prisma-extension-autozod 1.0.4 → 1.0.5

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 +58 -2
  2. package/package.json +9 -8
package/README.md CHANGED
@@ -13,11 +13,22 @@
13
13
 
14
14
  ---
15
15
 
16
+ ## Why prisma-extension-autozod?
17
+
18
+ | Feature | Manual Controller Validation | Schema Generators (zod-prisma) | prisma-extension-autozod |
19
+ | :--- | :--- | :--- | :--- |
20
+ | **Zero Controller Boilerplate** | No (Manual `.parse()`) | No (Manual `.parse()`) | Yes (Auto-intercepted) |
21
+ | **Prisma 8 Native Architecture** | No | No | Yes (`beforeCompile` / Contract) |
22
+ | **Compile-Time Typo Linter** | No | No | Yes (Immediate IDE feedback) |
23
+ | **Casing Normalization** | No | No | Yes (`first_name` <-> `firstName`) |
24
+
25
+ ---
26
+
16
27
  ## Requirements
17
28
 
18
- - **Node.js**: `>=22.0.0`
29
+ - **Node.js**: `>= 22.0.0`
19
30
  - **Prisma ORM**: `@prisma/orm-postgres >= 8.0.0`
20
- - **Zod**: `>=4.0.0`
31
+ - **Zod**: `^4.0.0`
21
32
 
22
33
  ---
23
34
 
@@ -148,6 +159,40 @@ await db.orm.public.User.where({ email: "alice@prisma.io" }).update({
148
159
 
149
160
  ---
150
161
 
162
+ ### 4. Column Normalization in Action
163
+
164
+ Incoming payloads from frontend forms or REST APIs often use `snake_case`. The middleware automatically remaps them to match your contract columns:
165
+
166
+ ```typescript
167
+ // Incoming frontend payload uses snake_case:
168
+ await db.orm.public.User.create({
169
+ first_name: "Alice", // Automatically remapped to `firstName` in Postgres
170
+ email: "alice@prisma.io",
171
+ });
172
+ ```
173
+
174
+ ---
175
+
176
+ ### 5. Error Handling DX
177
+
178
+ Because validation throws standard `ZodError` instances, you can easily catch and format errors for HTTP responses in Express, NestJS, Fastify, or Hono:
179
+
180
+ ```typescript
181
+ import { ZodError } from "zod";
182
+
183
+ try {
184
+ await db.orm.public.User.create(req.body);
185
+ } catch (error) {
186
+ if (error instanceof ZodError) {
187
+ // Clean flattened validation errors directly back to the client
188
+ return res.status(400).json({ errors: error.flatten().fieldErrors });
189
+ }
190
+ throw error;
191
+ }
192
+ ```
193
+
194
+ ---
195
+
151
196
  ## API Reference
152
197
 
153
198
  ### `createZodRegistry<TModels>()`
@@ -203,6 +248,17 @@ pnpm run build
203
248
 
204
249
  ---
205
250
 
251
+ ## Contributing
252
+
253
+ Contributions, bug reports, and feature requests are welcome!
254
+ Feel free to check the [issues page](https://github.com/abzr0o/prisma-extension-autozod/issues).
255
+
256
+ ## Support
257
+
258
+ If this library saves you time or prevents schema bugs in production, consider giving it a star on [GitHub](https://github.com/abzr0o/prisma-extension-autozod)!
259
+
260
+ ---
261
+
206
262
  ## License
207
263
 
208
264
  [MIT](LICENSE) (c) [Mohammed Thamer](https://github.com/abzr0o)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-extension-autozod",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
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",
@@ -19,6 +19,13 @@
19
19
  "engines": {
20
20
  "node": ">=22.0.0"
21
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"
28
+ },
22
29
  "keywords": [
23
30
  "prisma",
24
31
  "prisma8",
@@ -59,11 +66,5 @@
59
66
  },
60
67
  "dependencies": {
61
68
  "@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"
68
69
  }
69
- }
70
+ }