prisma-zod-generator 0.8.13 → 0.8.15

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 (39) hide show
  1. package/README.md +700 -67
  2. package/lib/generator.d.ts +1 -1
  3. package/lib/helpers/aggregate-helpers.js +3 -3
  4. package/lib/helpers/aggregate-helpers.js.map +1 -1
  5. package/lib/helpers/comments-helpers.js +3 -4
  6. package/lib/helpers/comments-helpers.js.map +1 -1
  7. package/lib/helpers/helpers.d.ts +2 -2
  8. package/lib/helpers/helpers.js +18 -3
  9. package/lib/helpers/helpers.js.map +1 -1
  10. package/lib/helpers/include-helpers.js +1 -2
  11. package/lib/helpers/include-helpers.js.map +1 -1
  12. package/lib/helpers/index.d.ts +1 -1
  13. package/lib/helpers/model-helpers.d.ts +12 -2
  14. package/lib/helpers/model-helpers.js +5 -6
  15. package/lib/helpers/model-helpers.js.map +1 -1
  16. package/lib/helpers/modelArgs-helpers.js +1 -2
  17. package/lib/helpers/modelArgs-helpers.js.map +1 -1
  18. package/lib/helpers/mongodb-helpers.js +2 -2
  19. package/lib/helpers/mongodb-helpers.js.map +1 -1
  20. package/lib/helpers/select-helpers.js +2 -3
  21. package/lib/helpers/select-helpers.js.map +1 -1
  22. package/lib/helpers/whereUniqueInput-helpers.js +4 -6
  23. package/lib/helpers/whereUniqueInput-helpers.js.map +1 -1
  24. package/lib/index.js +0 -1
  25. package/lib/index.js.map +1 -1
  26. package/lib/prisma-generator.js +31 -13
  27. package/lib/prisma-generator.js.map +1 -1
  28. package/lib/transformer.d.ts +9 -2
  29. package/lib/transformer.js +78 -29
  30. package/lib/transformer.js.map +1 -1
  31. package/lib/types.d.ts +1 -1
  32. package/lib/utils/formatFile.js.map +1 -1
  33. package/lib/utils/removeDir.js +1 -1
  34. package/lib/utils/removeDir.js.map +1 -1
  35. package/lib/utils/writeFileSafely.d.ts +1 -1
  36. package/lib/utils/writeFileSafely.js.map +1 -1
  37. package/lib/utils/writeIndexFile.js +3 -4
  38. package/lib/utils/writeIndexFile.js.map +1 -1
  39. package/package.json +67 -13
package/README.md CHANGED
@@ -1,74 +1,320 @@
1
- # Prisma Zod Generator
2
-
3
- [![npm version](https://badge.fury.io/js/prisma-zod-generator.svg)](https://badge.fury.io/js/prisma-zod-generator)
4
- [![npm](https://img.shields.io/npm/dt/prisma-zod-generator.svg)](https://www.npmjs.com/package/prisma-zod-generator)
5
- [![HitCount](https://hits.dwyl.com/omar-dulaimi/prisma-zod-generator.svg?style=flat)](http://hits.dwyl.com/omar-dulaimi/prisma-zod-generator)
6
- [![npm](https://img.shields.io/npm/l/prisma-zod-generator.svg)](LICENSE)
7
-
8
- Automatically generate [Zod](https://github.com/colinhacks/zod) schemas from your [Prisma](https://github.com/prisma/prisma) Schema, and use them to validate your API endpoints or any other use you have. Updates every time `npx prisma generate` runs.
9
-
10
- <p align="center">
11
- <a href="https://www.buymeacoffee.com/omardulaimi">
12
- <img src="https://cdn.buymeacoffee.com/buttons/default-black.png" alt="Buy Me A Coffee" height="41" width="174">
1
+ <div align="center">
2
+
3
+ # ⚡ Prisma Zod Generator
4
+
5
+ ### 🚀 **Automatically generate Zod schemas from your Prisma schema**
6
+
7
+ <p>
8
+ <a href="https://www.npmjs.com/package/prisma-zod-generator">
9
+ <img src="https://img.shields.io/npm/v/prisma-zod-generator/latest.svg?style=for-the-badge&logo=npm&color=blue" alt="Stable Version">
10
+ </a>
11
+ <a href="https://www.npmjs.com/package/prisma-zod-generator">
12
+ <img src="https://img.shields.io/npm/v/prisma-zod-generator/beta.svg?style=for-the-badge&logo=npm&label=beta&color=orange" alt="Beta Version">
13
+ </a>
14
+ </p>
15
+
16
+ <p>
17
+ <a href="https://www.npmjs.com/package/prisma-zod-generator">
18
+ <img src="https://img.shields.io/npm/dt/prisma-zod-generator.svg?style=for-the-badge&logo=npm&color=green" alt="Downloads">
19
+ </a>
20
+ <a href="https://github.com/omar-dulaimi/prisma-zod-generator/actions">
21
+ <img src="https://img.shields.io/github/actions/workflow/status/omar-dulaimi/prisma-zod-generator/ci.yml?style=for-the-badge&logo=github" alt="CI Status">
22
+ </a>
23
+ <a href="LICENSE">
24
+ <img src="https://img.shields.io/npm/l/prisma-zod-generator.svg?style=for-the-badge&color=purple" alt="License">
25
+ </a>
26
+ </p>
27
+
28
+ <p>
29
+ <strong>🎯 Zero-config • 🛡️ Type-safe • ⚡ Fast • 🔧 Customizable</strong>
30
+ </p>
31
+
32
+ </div>
33
+
34
+ ---
35
+
36
+ <br>
37
+
38
+ <div align="center">
39
+ <h3>💡 Transform your Prisma schema into type-safe validation schemas</h3>
40
+ <p><em>Automatically generates Zod schemas for all Prisma operations with full TypeScript support</em></p>
41
+ </div>
42
+
43
+ <div align="center">
44
+
45
+ ## 💖 **Support This Project**
46
+
47
+ <p><em>If this tool accelerates your development, consider supporting its growth</em></p>
48
+
49
+ <a href="https://github.com/sponsors/omar-dulaimi">
50
+ <img src="https://img.shields.io/badge/💝_Sponsor_on_GitHub-ea4aaa?style=for-the-badge&logo=github&logoColor=white" alt="GitHub Sponsors" height="45">
13
51
  </a>
14
- </p>
52
+
53
+ <p><strong>✨ Your sponsorship drives innovation and keeps this project thriving ✨</strong></p>
54
+
55
+ </div>
56
+
57
+ <div align="center">
58
+
59
+ ## 🚀 **Latest Stable Release** - Now with Schema Compilation Fixes!
60
+
61
+ <table>
62
+ <tr>
63
+ <td align="center">
64
+ <img src="https://img.shields.io/badge/🎉_STABLE_RELEASE-green?style=for-the-badge&logo=checkmark" alt="Stable Release">
65
+ </td>
66
+ </tr>
67
+ <tr>
68
+ <td align="center">
69
+ <strong>🎉 Production Ready with New Prisma Client Generator Support!</strong>
70
+ </td>
71
+ </tr>
72
+ </table>
73
+
74
+ </div>
75
+
76
+ ### ✨ **Latest Features**
77
+
78
+ 🐛 **Schema Compilation Fixes** - Resolved critical schema compilation errors:
79
+ - **SortOrderInput schemas** now use direct enum references instead of unnecessary lazy loading
80
+ - **Args schemas** (UserArgs, ProfileArgs, etc.) no longer cause TypeScript compilation errors
81
+ - **All generated schemas** now compile cleanly without type constraint issues
82
+
83
+ 🔧 **Test Infrastructure** - Enhanced test reliability with improved CI/CD pipeline
84
+
85
+ ### ✨ **Core Features**
86
+
87
+ <div align="center">
88
+
89
+ | 🚀 **Feature** | 📦 **Version** | 🎯 **Benefit** |
90
+ |----------------|----------------|------------------|
91
+ | **New Prisma Client** | `6.12.0+` | 🆕 ESM-compatible generator support |
92
+ | **Prisma** | `6.12.0+` | 🏃‍♂️ Latest features & performance |
93
+ | **Zod** | `4.0.5+` | 🛡️ Enhanced validation & type safety |
94
+ | **TypeScript** | `5.8+` | ⚡ Cutting-edge language features |
95
+ | **Testing** | `Vitest 3` | 🧪 Comprehensive coverage |
96
+ | **Tooling** | `ESLint 9` | 🔧 Modern dev experience |
97
+ | **Multi-DB** | `All Providers` | 🗄️ PostgreSQL, MySQL, MongoDB, SQLite+ |
98
+
99
+ </div>
100
+
101
+ <div align="center">
102
+
103
+ ### 📦 **Installation**
104
+
105
+ </div>
15
106
 
16
- ## Table of Contents
107
+ ```bash
108
+ # 🚀 Install the latest stable release (recommended)
109
+ npm install prisma-zod-generator
17
110
 
18
- - [Supported Prisma Versions](#supported-prisma-versions)
19
- - [Installation](#installation)
20
- - [Usage](#usage)
21
- - [Customizations](#customizations)
22
- - [Additional Options](#additional-options)
111
+ # or explicitly specify latest
112
+ npm install prisma-zod-generator@latest
23
113
 
24
- # Supported Prisma Versions
114
+ # 🧪 Install beta versions (for testing latest features)
115
+ npm install prisma-zod-generator@beta
116
+ ```
25
117
 
26
- ### Prisma 4
118
+ ### 🔄 Upgrading
27
119
 
28
- - 0.3.0 and higher
120
+ The latest stable version maintains full API compatibility. Requirements:
121
+ - **Node.js 18+**
122
+ - **Prisma 6.12.0+**
123
+ - **Zod 4.0.5+**
29
124
 
30
- ### Prisma 2/3
125
+ Simply update your dependencies and re-run `npx prisma generate` - no code changes needed!
31
126
 
32
- - 0.2.0 and lower
127
+ ```bash
128
+ npm update prisma-zod-generator
129
+ npx prisma generate
130
+ ```
33
131
 
34
- # Installation
132
+ ### 📝 Beta Feedback
133
+
134
+ Please test thoroughly and [report any issues](https://github.com/omar-dulaimi/prisma-zod-generator/issues). Your feedback helps us deliver a stable release!
135
+
136
+ <div align="center">
137
+
138
+ ## 📚 **Navigation**
139
+
140
+ <table>
141
+ <tr>
142
+ <td><a href="#-features">✨ Features</a></td>
143
+ <td><a href="#-quick-start">🚀 Quick Start</a></td>
144
+ <td><a href="#-generated-output">📋 Output</a></td>
145
+ <td><a href="#️-configuration-options">⚙️ Config</a></td>
146
+ </tr>
147
+ <tr>
148
+ <td><a href="#-advanced-usage">🔧 Advanced</a></td>
149
+ <td><a href="#-examples">📚 Examples</a></td>
150
+ <td><a href="#-troubleshooting">🔍 Troubleshooting</a></td>
151
+ <td><a href="#-contributing">🤝 Contributing</a></td>
152
+ </tr>
153
+ </table>
154
+
155
+ </div>
156
+
157
+ <div align="center">
158
+
159
+ ## ✨ **Why Choose Prisma Zod Generator?**
160
+
161
+ </div>
162
+
163
+ <table>
164
+ <tr>
165
+ <td align="center" width="25%">
166
+ <img src="https://img.shields.io/badge/🚀-Zero_Config-blue?style=for-the-badge" alt="Zero Config">
167
+ <br><strong>Works instantly</strong><br><em>Sensible defaults included</em>
168
+ </td>
169
+ <td align="center" width="25%">
170
+ <img src="https://img.shields.io/badge/🔄-Auto_Generated-green?style=for-the-badge" alt="Auto Generated">
171
+ <br><strong>Always in sync</strong><br><em>Updates with schema changes</em>
172
+ </td>
173
+ <td align="center" width="25%">
174
+ <img src="https://img.shields.io/badge/🛡️-Type_Safe-purple?style=for-the-badge" alt="Type Safe">
175
+ <br><strong>100% TypeScript</strong><br><em>Catch errors at compile time</em>
176
+ </td>
177
+ <td align="center" width="25%">
178
+ <img src="https://img.shields.io/badge/🎯-Comprehensive-orange?style=for-the-badge" alt="Comprehensive">
179
+ <br><strong>Full CRUD coverage</strong><br><em>All Prisma operations included</em>
180
+ </td>
181
+ </tr>
182
+ <tr>
183
+ <td align="center">
184
+ <img src="https://img.shields.io/badge/⚙️-Configurable-red?style=for-the-badge" alt="Configurable">
185
+ <br><strong>Highly customizable</strong><br><em>Adapt to your needs</em>
186
+ </td>
187
+ <td align="center">
188
+ <img src="https://img.shields.io/badge/📦-Lightweight-yellow?style=for-the-badge" alt="Lightweight">
189
+ <br><strong>Minimal footprint</strong><br><em>Fast generation & runtime</em>
190
+ </td>
191
+ <td align="center">
192
+ <img src="https://img.shields.io/badge/🗄️-Multi_DB-cyan?style=for-the-badge" alt="Multi Database">
193
+ <br><strong>All databases</strong><br><em>PostgreSQL, MySQL, MongoDB+</em>
194
+ </td>
195
+ <td align="center">
196
+ <img src="https://img.shields.io/badge/🎨-Flexible-pink?style=for-the-badge" alt="Flexible">
197
+ <br><strong>Your way</strong><br><em>Custom paths & options</em>
198
+ </td>
199
+ </tr>
200
+ </table>
201
+
202
+ ## 🚀 Quick Start
203
+
204
+ ### Installation
205
+
206
+ #### Beta Version (Recommended - Latest Features)
207
+ ```bash
208
+ # NPM
209
+ npm install prisma-zod-generator@beta
35
210
 
36
- Using npm:
211
+ # Yarn
212
+ yarn add prisma-zod-generator@beta
37
213
 
38
- ```bash
39
- npm install prisma-zod-generator
214
+ # PNPM
215
+ pnpm add prisma-zod-generator@beta
40
216
  ```
41
217
 
42
- Using yarn:
43
-
218
+ #### Stable Version (Latest)
44
219
  ```bash
45
- yarn add prisma-zod-generator
220
+ # NPM
221
+ npm install prisma-zod-generator@latest
222
+
223
+ # Yarn
224
+ yarn add prisma-zod-generator@latest
225
+
226
+ # PNPM
227
+ pnpm add prisma-zod-generator@latest
46
228
  ```
47
229
 
48
- # Usage
230
+ ### Setup
49
231
 
50
- 1- Star this repo 😉
232
+ 1. **Star this repo** 😉
51
233
 
52
- 2- Add the generator to your Prisma schema
234
+ 2. **Add the generator to your Prisma schema:**
53
235
 
54
236
  ```prisma
55
237
  generator zod {
56
- provider = "prisma-zod-generator"
238
+ provider = "prisma-zod-generator"
239
+ output = "./generated/schemas"
240
+ isGenerateSelect = true
241
+ isGenerateInclude = true
57
242
  }
58
243
  ```
59
244
 
60
- 3- Enable strict mode in `tsconfig` as it is required by Zod, and considered a Typescript best practice
245
+ 3. **Enable strict mode in `tsconfig.json`** (required by Zod):
61
246
 
62
- ```ts
247
+ ```json
63
248
  {
64
249
  "compilerOptions": {
65
- "strict": true
250
+ "strict": true,
251
+ "exactOptionalPropertyTypes": true
66
252
  }
67
253
  }
254
+ ```
255
+
256
+ 4. **Generate your Zod schemas:**
68
257
 
258
+ ```bash
259
+ npx prisma generate
69
260
  ```
70
261
 
71
- 4- Running `npx prisma generate` for the following schema.prisma
262
+ ## 🆕 Prisma Client Generator Support
263
+
264
+ The latest stable version includes full support for both the legacy and new ESM-compatible `prisma-client` generator introduced in Prisma 6.12.0, plus important schema compilation fixes!
265
+
266
+ ### Generator Compatibility
267
+
268
+ The Zod generator now supports both Prisma client generators:
269
+
270
+ #### Legacy Generator (Existing Projects)
271
+ ```prisma
272
+ generator client {
273
+ provider = "prisma-client-js"
274
+ }
275
+
276
+ generator zod {
277
+ provider = "prisma-zod-generator"
278
+ output = "./generated/schemas"
279
+ }
280
+ ```
281
+
282
+ #### New ESM-Compatible Generator (Prisma 6.12.0+)
283
+ ```prisma
284
+ generator client {
285
+ provider = "prisma-client"
286
+ output = "./src/generated/client"
287
+ runtime = "nodejs"
288
+ moduleFormat = "esm"
289
+ generatedFileExtension = "ts"
290
+ importFileExtension = "ts"
291
+ }
292
+
293
+ generator zod {
294
+ provider = "prisma-zod-generator"
295
+ output = "./generated/schemas"
296
+ }
297
+ ```
298
+
299
+ ### Key Benefits of the New Generator
300
+
301
+ - **🔗 ESM Compatibility** - Full ES Module support
302
+ - **📂 Custom Output Location** - Generate client outside `node_modules`
303
+ - **🔧 Runtime Flexibility** - Support for Bun, Deno, Cloudflare Workers
304
+ - **⚡ Better Performance** - Optimized code generation
305
+ - **🔮 Future-Ready** - Will become the default in Prisma v7
306
+
307
+ ### Migration Guide
308
+
309
+ **Existing Projects**: No changes needed - continue using `prisma-client-js`
310
+
311
+ **New Projects**: Consider using the new `prisma-client` generator for modern features
312
+
313
+ **Gradual Migration**: Both generators are supported simultaneously during the transition
314
+
315
+ ## 📋 Generated Output
316
+
317
+ For the following schema:
72
318
 
73
319
  ```prisma
74
320
  model User {
@@ -92,49 +338,436 @@ model Post {
92
338
  }
93
339
  ```
94
340
 
95
- will generate the following files
341
+ The generator creates:
96
342
 
97
- ![Zod Schemas](https://raw.githubusercontent.com/omar-dulaimi/prisma-zod-generator/master/zodSchemas.png)
343
+ ```
344
+ 📁 generated/schemas/
345
+ ├── 📁 enums/ # Enum validation schemas
346
+ ├── 📁 objects/ # Input type schemas
347
+ ├── 📄 findManyUser.schema.ts
348
+ ├── 📄 findUniqueUser.schema.ts
349
+ ├── 📄 createOneUser.schema.ts
350
+ ├── 📄 updateOneUser.schema.ts
351
+ ├── 📄 deleteOneUser.schema.ts
352
+ ├── 📄 findManyPost.schema.ts
353
+ ├── 📄 createOnePost.schema.ts
354
+ └── 📄 index.ts # Barrel exports
355
+ ```
98
356
 
99
- 5- Use generated schemas somewhere in your API logic, like middleware or decorator
357
+ ### Version Compatibility
100
358
 
101
- ```ts
102
- import { PostCreateOneSchema } from './prisma/generated/schemas/createOnePost.schema';
359
+ | Version | Prisma | Zod | TypeScript | Node.js | Status |
360
+ |---------|--------|-----|------------|---------|--------|
361
+ | **Latest** | 6.12.0+ | 4.0.5+ | 5.8+ | 18+ | ✅ **Stable** - Full Features + Schema Fixes |
362
+ | **Beta** | 6.12.0+ | 4.0.5+ | 5.8+ | 18+ | 🧪 **Testing** - Experimental Features |
363
+ | **Legacy** | 4.8.0+ | 3.20+ | 4.9+ | 16+ | 📦 **Deprecated** - Limited Support |
103
364
 
104
- app.post('/blog', async (req, res, next) => {
105
- const { body } = req;
106
- await PostCreateOneSchema.parse(body);
107
- });
365
+ > **Recommendation**: Use `npm install prisma-zod-generator` for the latest stable release with full features and important bug fixes.
366
+
367
+ ## ⚙️ Configuration Options
368
+
369
+ | Option | Description | Type | Default |
370
+ |--------|-------------|------|---------|
371
+ | `output` | Output directory for generated files | `string` | `"./generated"` |
372
+ | `isGenerateSelect` | Generate Select-related schemas | `boolean` | `false` |
373
+ | `isGenerateInclude` | Generate Include-related schemas | `boolean` | `false` |
374
+
375
+ ### Example Configuration
376
+
377
+ ```prisma
378
+ generator zod {
379
+ provider = "prisma-zod-generator"
380
+ output = "./src/schemas"
381
+ isGenerateSelect = true
382
+ isGenerateInclude = true
383
+ }
108
384
  ```
109
385
 
110
- # Customizations
386
+ ## 🔧 Advanced Usage
111
387
 
112
- ## Skipping entire models
388
+ ### Model Customizations
389
+
390
+ Hide specific models from generation:
113
391
 
114
392
  ```prisma
115
393
  /// @@Gen.model(hide: true)
116
- model User {
117
- id Int @id @default(autoincrement())
118
- email String @unique
119
- name String?
394
+ model InternalLog {
395
+ id Int @id @default(autoincrement())
396
+ message String
397
+ createdAt DateTime @default(now())
120
398
  }
121
399
  ```
122
400
 
123
- # Additional Options
401
+ ### Database Provider Support
124
402
 
125
- | Option | Description | Type | Default |
126
- | ------------------- | -------------------------------------------------------------------------- | --------- | ------------- |
127
- | `output` | Output directory for the generated zod schemas | `string` | `./generated` |
128
- | `isGenerateSelect` | Enables the generation of Select related schemas and the select property | `boolean` | `false` |
129
- | `isGenerateInclude` | Enables the generation of Include related schemas and the include property | `boolean` | `false` |
403
+ The generator supports all Prisma database providers:
130
404
 
131
- Use additional options in the `schema.prisma`
405
+ - **PostgreSQL** - Complete support including advanced types
406
+ - **MySQL** - Full compatibility with all MySQL features
407
+ - **MongoDB** - Native MongoDB schema generation
408
+ - **SQLite** - Perfect for development and testing
409
+ - **SQL Server** - Enterprise-grade support
410
+ - **CockroachDB** - Distributed database support
132
411
 
133
- ```prisma
134
- generator zod {
135
- provider = "prisma-zod-generator"
136
- output = "./generated-zod-schemas"
137
- isGenerateSelect = true
138
- isGenerateInclude = true
412
+ ## 📚 Examples
413
+
414
+ ### Express.js API Validation
415
+
416
+ ```typescript
417
+ import express from 'express';
418
+ import { PostCreateOneSchema, UserFindManySchema } from './generated/schemas';
419
+
420
+ const app = express();
421
+
422
+ // Create post with validation
423
+ app.post('/posts', async (req, res) => {
424
+ try {
425
+ const data = PostCreateOneSchema.parse(req.body);
426
+ const post = await prisma.post.create(data);
427
+ res.json(post);
428
+ } catch (error) {
429
+ if (error instanceof z.ZodError) {
430
+ return res.status(400).json({ errors: error.errors });
431
+ }
432
+ res.status(500).json({ error: 'Internal server error' });
433
+ }
434
+ });
435
+
436
+ // Query with validation
437
+ app.get('/users', async (req, res) => {
438
+ const query = UserFindManySchema.parse(req.query);
439
+ const users = await prisma.user.findMany(query);
440
+ res.json(users);
441
+ });
442
+ ```
443
+
444
+ ### Next.js API Routes
445
+
446
+ ```typescript
447
+ // pages/api/users.ts
448
+ import type { NextApiRequest, NextApiResponse } from 'next';
449
+ import { UserCreateOneSchema } from '../../generated/schemas';
450
+
451
+ export default async function handler(req: NextApiRequest, res: NextApiResponse) {
452
+ if (req.method === 'POST') {
453
+ try {
454
+ const userData = UserCreateOneSchema.parse(req.body);
455
+ const user = await prisma.user.create(userData);
456
+ res.status(201).json(user);
457
+ } catch (error) {
458
+ res.status(400).json({ error: error.message });
459
+ }
460
+ }
139
461
  }
140
462
  ```
463
+
464
+ ### tRPC Integration
465
+
466
+ ```typescript
467
+ import { z } from 'zod';
468
+ import { PostCreateOneSchema, PostFindManySchema } from './generated/schemas';
469
+
470
+ export const postRouter = router({
471
+ create: publicProcedure
472
+ .input(PostCreateOneSchema)
473
+ .mutation(({ input }) => {
474
+ return prisma.post.create(input);
475
+ }),
476
+
477
+ list: publicProcedure
478
+ .input(PostFindManySchema)
479
+ .query(({ input }) => {
480
+ return prisma.post.findMany(input);
481
+ }),
482
+ });
483
+ ```
484
+
485
+ ### React Hook Form Integration
486
+
487
+ ```typescript
488
+ import { useForm } from 'react-hook-form';
489
+ import { zodResolver } from '@hookform/resolvers/zod';
490
+ import { UserCreateInputObjectSchema } from './generated/schemas';
491
+
492
+ function CreateUserForm() {
493
+ const { register, handleSubmit, formState: { errors } } = useForm({
494
+ resolver: zodResolver(UserCreateInputObjectSchema)
495
+ });
496
+
497
+ const onSubmit = async (data) => {
498
+ const response = await fetch('/api/users', {
499
+ method: 'POST',
500
+ headers: { 'Content-Type': 'application/json' },
501
+ body: JSON.stringify({ data })
502
+ });
503
+ };
504
+
505
+ return (
506
+ <form onSubmit={handleSubmit(onSubmit)}>
507
+ <input {...register('email')} type="email" />
508
+ {errors.email && <span>{errors.email.message}</span>}
509
+
510
+ <input {...register('name')} />
511
+ {errors.name && <span>{errors.name.message}</span>}
512
+
513
+ <button type="submit">Create User</button>
514
+ </form>
515
+ );
516
+ }
517
+ ```
518
+
519
+ ## 🔧 API Reference
520
+
521
+ ### Generated Schema Types
522
+
523
+ The generator creates the following types of schemas:
524
+
525
+ #### Operation Schemas
526
+ - **Create Operations**: `ModelCreateOneSchema`, `ModelCreateManySchema`
527
+ - **Read Operations**: `ModelFindManySchema`, `ModelFindUniqueSchema`, `ModelFindFirstSchema`
528
+ - **Update Operations**: `ModelUpdateOneSchema`, `ModelUpdateManySchema`, `ModelUpsertSchema`
529
+ - **Delete Operations**: `ModelDeleteOneSchema`, `ModelDeleteManySchema`
530
+ - **Aggregate Operations**: `ModelAggregateSchema`, `ModelGroupBySchema`
531
+
532
+ #### Input Object Schemas
533
+ - **Create Inputs**: `ModelCreateInputObjectSchema`, `ModelCreateNestedInputObjectSchema`
534
+ - **Update Inputs**: `ModelUpdateInputObjectSchema`, `ModelUpdateNestedInputObjectSchema`
535
+ - **Where Inputs**: `ModelWhereInputObjectSchema`, `ModelWhereUniqueInputObjectSchema`
536
+ - **Order Inputs**: `ModelOrderByInputObjectSchema`
537
+
538
+ #### Select & Include Schemas (Optional)
539
+ When enabled with `isGenerateSelect: true` and `isGenerateInclude: true`:
540
+ - **Select Schemas**: `ModelSelectObjectSchema`
541
+ - **Include Schemas**: `ModelIncludeObjectSchema`
542
+
543
+ ### Schema Naming Convention
544
+
545
+ All generated schemas follow a consistent naming pattern:
546
+ ```
547
+ {ModelName}{Operation}{Type}Schema
548
+ ```
549
+
550
+ Examples:
551
+ - `UserCreateOneSchema` - Schema for creating a single user
552
+ - `PostFindManyArgsSchema` - Schema for finding multiple posts with arguments
553
+ - `UserWhereInputObjectSchema` - Schema for user where conditions
554
+
555
+ ## 🔍 Troubleshooting
556
+
557
+ ### Latest Version Information
558
+
559
+ **Recent Schema Compilation Fixes**
560
+ - **SortOrderInput schemas**: Fixed unnecessary lazy loading that caused validation issues
561
+ - **Args schemas**: Resolved TypeScript compilation errors for UserArgs, ProfileArgs, etc.
562
+ - **All schemas**: Now compile cleanly without type constraint issues
563
+ - **Full backward compatibility**: No code changes needed when upgrading
564
+
565
+ **Generator Support**
566
+ - Both `prisma-client-js` and `prisma-client` generators are fully supported
567
+ - If using the new generator, ensure Prisma 6.12.0+ is installed
568
+ - Clear error messages guide you if no compatible generator is found
569
+
570
+ **Current Requirements**
571
+ - Requires Node.js 18+
572
+ - Requires Prisma 6.12.0+ and Zod 4.0.5+
573
+ - All peer dependencies must be compatible
574
+
575
+ **Upgrading to Latest Version**
576
+ - Backup your project before upgrading
577
+ - Update all related dependencies (Prisma, Zod, TypeScript)
578
+ - Re-run `npx prisma generate` after upgrading
579
+ - Test thoroughly in development environment
580
+
581
+ ### Common Issues
582
+
583
+ **Generator compatibility errors**
584
+ - Ensure you have either `prisma-client-js` or `prisma-client` generator in your schema
585
+ - The Zod generator provides clear error messages with examples if no compatible generator is found
586
+ - Both legacy and new generators are supported simultaneously
587
+
588
+ **Error: Cannot find module './generated/schemas'**
589
+ - Ensure you've run `npx prisma generate` after adding the generator
590
+ - Check that your output path is correct
591
+
592
+ **TypeScript errors in generated schemas**
593
+ - Make sure all dependencies are installed and up to date
594
+ - Ensure `strict: true` is enabled in `tsconfig.json`
595
+ - Verify exactOptionalPropertyTypes is enabled
596
+
597
+ **Generated schemas not updating**
598
+ - Run `npx prisma generate` after modifying your schema
599
+ - Check that the generator is properly configured in `schema.prisma`
600
+ - Clear your build cache and regenerate
601
+
602
+ **Zod validation errors (v0.8.14-beta)**
603
+ - Ensure you have Zod 4.0.5+ installed for beta compatibility
604
+ - Check that your input schemas match your Prisma model types
605
+
606
+ **Generator fails to run**
607
+ - Ensure you have the correct version installed
608
+ - Check that your `schema.prisma` syntax is valid
609
+ - Verify Node.js version compatibility (18+)
610
+ - Clear node_modules and reinstall dependencies
611
+
612
+ ### Performance Considerations
613
+
614
+ #### Large Schemas
615
+ For projects with many models (50+), consider:
616
+ - Using selective generation with model hiding
617
+ - Splitting schemas into multiple files
618
+ - Implementing lazy loading for schemas
619
+
620
+ #### Build Times
621
+ To optimize build performance:
622
+ - Add generated files to `.gitignore`
623
+ - Use parallel builds where possible
624
+ - Consider caching in CI/CD pipelines
625
+
626
+ ### FAQ
627
+
628
+ **Q: Can I customize the generated schema validation rules?**
629
+ A: The schemas are generated based on your Prisma schema constraints. Modify your Prisma model definitions to change validation rules.
630
+
631
+ **Q: Does this work with Prisma Edge Runtime?**
632
+ A: Yes, the generated schemas are compatible with Prisma Edge Runtime.
633
+
634
+ **Q: Can I use this with databases other than the officially supported ones?**
635
+ A: The generator supports all Prisma-compatible databases. Custom databases should work if Prisma supports them.
636
+
637
+ **Q: How do I handle enum validation?**
638
+ A: Enums are automatically converted to Zod enum schemas and placed in the `enums/` directory.
639
+
640
+ **Q: Can I exclude certain fields from validation?**
641
+ A: Use Prisma's `@ignore` directive or model-level hiding with `@@Gen.model(hide: true)`.
642
+
643
+ ### Getting Help
644
+
645
+ - 🐛 **Bug Reports**: [Create a bug report](https://github.com/omar-dulaimi/prisma-zod-generator/issues/new)
646
+ - 💡 **Feature Requests**: [Request a feature](https://github.com/omar-dulaimi/prisma-zod-generator/issues/new)
647
+ - 💬 **Discussions**: [Join the discussion](https://github.com/omar-dulaimi/prisma-zod-generator/discussions)
648
+
649
+ ## 🤝 Contributing
650
+
651
+ Contributions are welcome! Here's how you can help:
652
+
653
+ ### Development Setup
654
+
655
+ 1. **Fork and clone the repository**
656
+ ```bash
657
+ git clone https://github.com/your-username/prisma-zod-generator.git
658
+ cd prisma-zod-generator
659
+ ```
660
+
661
+ 2. **Install dependencies**
662
+ ```bash
663
+ npm install
664
+ ```
665
+
666
+ 3. **Run the development build**
667
+ ```bash
668
+ npm run gen-example
669
+ ```
670
+
671
+ 4. **Run tests**
672
+ ```bash
673
+ npm test
674
+ ```
675
+
676
+ ### Testing
677
+
678
+ We have comprehensive tests covering:
679
+ - **Unit Tests**: Core transformation logic
680
+ - **Integration Tests**: End-to-end schema generation
681
+ - **Multi-Provider Tests**: All database providers
682
+ - **Performance Tests**: Large schema handling
683
+
684
+ Run specific test suites:
685
+ ```bash
686
+ npm run test:basic # Basic functionality
687
+ npm run test:multi # Multi-provider testing
688
+ npm run test:coverage # Coverage reports
689
+ npm run test:comprehensive # Full test suite
690
+ ```
691
+
692
+ ### Contribution Guidelines
693
+
694
+ 1. **Create an issue** for bugs or feature requests
695
+ 2. **Follow the existing code style** (ESLint + Prettier)
696
+ 3. **Add tests** for new functionality
697
+ 4. **Update documentation** as needed
698
+ 5. **Submit a pull request** with a clear description
699
+
700
+ ### Code Style
701
+
702
+ We use ESLint and Prettier for consistent code formatting:
703
+ ```bash
704
+ npm run lint # Check and fix linting issues
705
+ npm run format # Format code with Prettier
706
+ ```
707
+
708
+ ### Release Process
709
+
710
+ This project uses semantic versioning and automated releases:
711
+ - **Patch**: Bug fixes and small improvements
712
+ - **Minor**: New features and enhancements
713
+ - **Major**: Breaking changes
714
+
715
+ ## 📄 License
716
+
717
+ This project is licensed under the [MIT License](LICENSE).
718
+
719
+ ## 🔗 Related Projects
720
+
721
+ - [prisma-trpc-generator](https://github.com/omar-dulaimi/prisma-trpc-generator) - Generate tRPC routers from Prisma schema
722
+ - [Prisma](https://github.com/prisma/prisma) - Database toolkit and ORM
723
+ - [Zod](https://github.com/colinhacks/zod) - TypeScript-first schema validation
724
+
725
+ ## 🙏 Acknowledgments
726
+
727
+ - [Prisma](https://github.com/prisma/prisma) - Modern database toolkit
728
+ - [Zod](https://github.com/colinhacks/zod) - TypeScript-first schema validation
729
+ - All our [contributors](https://github.com/omar-dulaimi/prisma-zod-generator/graphs/contributors)
730
+
731
+ ---
732
+
733
+ <br>
734
+
735
+ ---
736
+
737
+ <div align="center">
738
+
739
+ <h3>🌟 **Show Your Support** 🌟</h3>
740
+
741
+ <a href="https://github.com/omar-dulaimi/prisma-zod-generator">
742
+ <img src="https://img.shields.io/github/stars/omar-dulaimi/prisma-zod-generator?style=for-the-badge&logo=github&color=yellow" alt="GitHub Stars">
743
+ </a>
744
+
745
+ <br><br>
746
+
747
+ <table>
748
+ <tr>
749
+ <td align="center">
750
+ <img src="https://img.shields.io/badge/💎-Latest_Stable-success?style=for-the-badge&logo=npm" alt="Stable">
751
+ <br>
752
+ <code>v1.0.0</code>
753
+ </td>
754
+ <td align="center">
755
+ <img src="https://img.shields.io/badge/📦-Legacy_Version-lightgrey?style=for-the-badge&logo=archive" alt="Legacy">
756
+ <br>
757
+ <code>v0.8.13</code>
758
+ </td>
759
+ </tr>
760
+ </table>
761
+
762
+ <br>
763
+
764
+ <p>
765
+ <strong>Made with ❤️ by</strong>
766
+ <a href="https://github.com/omar-dulaimi">
767
+ <img src="https://img.shields.io/badge/Omar_Dulaimi-100000?style=for-the-badge&logo=github&logoColor=white" alt="Omar Dulaimi">
768
+ </a>
769
+ </p>
770
+
771
+ <p><em>⚡ Accelerating Prisma development, one schema at a time</em></p>
772
+
773
+ </div>