prisma-extension-autozod 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +32 -13
  2. package/package.json +14 -15
package/README.md CHANGED
@@ -7,6 +7,7 @@
7
7
  > Contract-aware compile-time linting and runtime Zod validation for the new Prisma ORM (@prisma/orm-postgres).
8
8
 
9
9
  `prisma-extension-autozod` connects **Zod 4** and **Prisma ORM 8**. It provides two layers of safety:
10
+
10
11
  1. **Compile-time Linting**: TypeScript flags any field in your Zod schema that does not exist in your Prisma data contract.
11
12
  2. **Runtime Middleware**: Automatically intercepts write operations (`create`, `update`, `insert`) via Prisma 8's `beforeCompile` hook, validates payloads, normalizes column naming conventions, and blocks invalid mutations before SQL reaches your database.
12
13
 
@@ -14,9 +15,9 @@
14
15
 
15
16
  ## Requirements
16
17
 
17
- - **Node.js**: `>= 24.0.0`
18
+ - **Node.js**: `>=22.0.0`
18
19
  - **Prisma ORM**: `@prisma/orm-postgres >= 8.0.0`
19
- - **Zod**: `^4.0.0`
20
+ - **Zod**: `>=4.0.0`
20
21
 
21
22
  ---
22
23
 
@@ -64,18 +65,30 @@ export const userValidator = defineModel(
64
65
  "User",
65
66
  z.object({
66
67
  email: z.string().email("Invalid email address"),
67
- username: z.string().min(2, "Username must be at least 2 characters").nullable().optional(),
68
- name: z.string().min(2, "Name must be at least 2 characters").nullable().optional(),
69
- })
68
+ username: z
69
+ .string()
70
+ .min(2, "Username must be at least 2 characters")
71
+ .nullable()
72
+ .optional(),
73
+ name: z
74
+ .string()
75
+ .min(2, "Name must be at least 2 characters")
76
+ .nullable()
77
+ .optional(),
78
+ }),
70
79
  );
71
80
  ```
72
81
 
73
82
  > **Compile-Time Safety in Action:**
74
83
  > If you add a field that does not exist in the contract:
84
+ >
75
85
  > ```typescript
76
- > defineModel("User", z.object({
77
- > nonExistentColumn: z.string() // Error: Field 'nonExistentColumn' does not exist in table contract
78
- > }));
86
+ > defineModel(
87
+ > "User",
88
+ > z.object({
89
+ > nonExistentColumn: z.string(), // Error: Field 'nonExistentColumn' does not exist in table contract
90
+ > }),
91
+ > );
79
92
  > ```
80
93
 
81
94
  ---
@@ -128,11 +141,9 @@ await db.orm.public.User.create({
128
141
  });
129
142
 
130
143
  // Update: Only supplied fields are validated
131
- await db.orm.public.User
132
- .where({ email: "alice@prisma.io" })
133
- .update({
134
- name: "Alice Wonder", // Valid; other fields are not required on updates
135
- });
144
+ await db.orm.public.User.where({ email: "alice@prisma.io" }).update({
145
+ name: "Alice Wonder", // Valid; other fields are not required on updates
146
+ });
136
147
  ```
137
148
 
138
149
  ---
@@ -140,28 +151,36 @@ await db.orm.public.User
140
151
  ## API Reference
141
152
 
142
153
  ### `createZodRegistry<TModels>()`
154
+
143
155
  Creates a model validator factory bound to your contract models. Validates that all fields in the schema exist in the contract table, allowing omission of auto-generated or optional fields.
156
+
144
157
  ```typescript
145
158
  const defineModel = createZodRegistry<typeof models.public>();
146
159
  const userValidator = defineModel("User", zodSchema);
147
160
  ```
148
161
 
149
162
  ### `createStrictZodRegistry<TModels>()`
163
+
150
164
  Creates a strict validator factory that requires all columns in the contract table to be declared in the schema, while also rejecting unknown fields.
165
+
151
166
  ```typescript
152
167
  const defineStrict = createStrictZodRegistry<typeof models.public>();
153
168
  const userValidator = defineStrict("User", zodSchema);
154
169
  ```
155
170
 
156
171
  ### `autoZodPrisma8(options)` (alias: `autoZod`)
172
+
157
173
  Prisma ORM 8 middleware factory:
174
+
158
175
  - `options.contract`: The raw `contract.json` object.
159
176
  - `options.validators`: Array of validator entries returned by `createZodRegistry` or `createStrictZodRegistry`.
160
177
 
161
178
  ### `extractColumns(contractJson)`
179
+
162
180
  Helper function that inspects storage namespaces inside `contract.json` and returns a normalized dictionary of table column names.
163
181
 
164
182
  ### `normalizeKey(key: string)`
183
+
165
184
  Normalizes strings to lowercase alphanumeric format for reliable case- and separator-insensitive mapping.
166
185
 
167
186
  ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-extension-autozod",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Contract-aware compile-time linting and runtime Zod validation for Prisma ORM 8 (@prisma/orm-postgres)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -17,14 +17,7 @@
17
17
  "dist"
18
18
  ],
19
19
  "engines": {
20
- "node": ">=24.0.0"
21
- },
22
- "scripts": {
23
- "build": "tsup src/index.ts --format cjs,esm --dts --clean",
24
- "test": "vitest run",
25
- "test:watch": "vitest",
26
- "typecheck": "tsc --noEmit",
27
- "prepublishOnly": "npm run typecheck && npm run test && npm run build"
20
+ "node": ">=22.0.0"
28
21
  },
29
22
  "keywords": [
30
23
  "prisma",
@@ -54,17 +47,23 @@
54
47
  },
55
48
  "homepage": "https://github.com/abzr0o/prisma-extension-autozod#readme",
56
49
  "peerDependencies": {
57
- "@prisma/orm-postgres": "^8.0.0",
58
- "zod": "^4.0.0"
50
+ "@prisma/orm-postgres": ">=8.0.0-rc.0 <9.0.0",
51
+ "zod": ">=4.0.0"
59
52
  },
60
53
  "devDependencies": {
61
54
  "@prisma/orm-postgres": "8.0.0-rc.22",
62
55
  "tsup": "^9.0.0",
63
56
  "typescript": "5.8.2",
64
- "vitest": "^5.1.0"
57
+ "vitest": "^5.1.0",
58
+ "zod": "^4.6.7"
65
59
  },
66
60
  "dependencies": {
67
- "@prisma/orm-family-sql": "8.0.0-rc.22",
68
- "zod": "^4.6.7"
61
+ "@prisma/orm-family-sql": "8.0.0-rc.22"
62
+ },
63
+ "scripts": {
64
+ "build": "tsup src/index.ts --format cjs,esm --dts --clean",
65
+ "test": "vitest run",
66
+ "test:watch": "vitest",
67
+ "typecheck": "tsc --noEmit"
69
68
  }
70
- }
69
+ }