Configuration
Prisma Guard supports three formats for local configuration: a .js / .mjs file using a defineConfig helper, standard JSDoc exports, or a simple .json file. The configuration file must be named prisma-guard.config.(js|mjs|json).
Configuration Formats
1. defineConfig (Recommended)
This format provides full TypeScript IntelliSense and inline type check documentation:
// prisma-guard.config.js
import { defineConfig } from "@explita/prisma-guard";
export default defineConfig({
schemaDir: "./prisma",
outputDir: "./generated",
omitIds: true,
omitDates: true,
autoTrim: true,
});
2. JSDoc Type Hints
If you prefer not to import the defineConfig helper:
// prisma-guard.config.js
/** @type {import('@explita/prisma-guard').PrismaGuardConfig} */
export default {
schemaDir: "./prisma",
outputDir: "./generated",
};
3. JSON Configuration
A simple static JSON file prisma-guard.config.json:
{
"schemaDir": "./prisma",
"outputDir": "./generated",
"omitIds": true,
"omitDates": true,
"autoTrim": true
}
Config Property Reference
| Property | Type | Default | Description |
|---|---|---|---|
schemaDir | string | "./prisma" | Path to the directory containing your .prisma schema files. |
outputDir | string | "node_modules/.prisma-guard" | Target directory where generated Zod schemas are written. If you need to import schemas in your code, set this to a committed directory (e.g., ./src/generated). Note that internal runtime guard JSON metadata files are ALWAYS written to node_modules/.prisma-guard to keep your custom schema directory clean. |
generateZod | boolean | true | Set to false to skip generating Zod schemas, producing only runtime guard metadata. |
omitIds | boolean | false | When true, removes all @id primary key fields from public Zod schemas. |
omitDates | boolean | false | When true, removes auto-generated dates (e.g. createdAt, updatedAt) from public schemas. |
zodOmit | string[] | [] | Global list of field names to exclude from all generated Zod schemas (e.g. ["password"]). |
autoTrim | boolean | true | Automatically appends .trim() to all inferred z.string() validations. |
schemaSuffix | string | "Schema" | Suffix appended to generated model Zod schemas (e.g., UserSchema). |
enumSuffix | string | "Enum" | Suffix appended to generated enum Zod schemas (e.g., RoleEnum). |
useJsDoc | boolean | false | Uses standard JSDoc comments (/** */) instead of Zod's .describe() calls. |
skipScalar | boolean | false | When true, skips generating intermediate database scalar schemas, producing only public API validation schemas. |
defaultsOnOverride | boolean | false | When true, preserves Prisma @default() boundaries when using explicit @zod.z overrides. |
prettier | boolean | true | Automatically runs Prettier formatting on all generated typescript code. |
skipGitignore | boolean | false | Prevents automatically updating your .gitignore with the generated Zod directory. |
debug | boolean | false | Enables verbose console logging output during schema building processes. |
importSuffix | string | "" | Appends a custom string suffix to relative import calls inside generated schemas (e.g. ".js" for ESM). |
typeMap | Record<string, string> | — | Custom Zod type mapping overrides (see below). |
decorators | Record<string, any> | — | Reusable named preset validation decorators (see Decorators guide). |
Default Type Mappings
Prisma Guard maps Prisma schema scalars to Zod schemas using these default translations:
| Prisma Type | Default Zod Translation |
|---|---|
String | z.string().trim() |
Int | z.number() |
BigInt | z.string().trim() |
Float | z.number() |
Decimal | z.union([z.number(), z.string()]) |
Boolean | z.boolean() |
DateTime | z.coerce.date() |
Json | z.unknown() |
Bytes | z.instanceof(Buffer) |
Overriding Default Mappings
You can override type translations globally inside the typeMap option of your config file:
export default defineConfig({
typeMap: {
// Map DateTime to ISO string validation instead of Date instances
DateTime: "z.string().datetime()",
},
});