@@ -253,10 +253,9 @@ export default class Transformer {
253
253
if ( isAggregateInputType ( name ) ) {
254
254
name = `${ name } Type` ;
255
255
}
256
- const end = `export const ${ this . name } ObjectSchema = Schema` ;
257
- return `const Schema: z.ZodType<Omit<Prisma.${ name } , ${ AUXILIARY_FIELDS . map ( ( f ) => "'" + f + "'" ) . join (
258
- '|'
259
- ) } >> = ${ schema } ;\n\n ${ end } `;
256
+ return `export const ${ this . name } ObjectSchema: z.ZodType<Omit<Prisma.${ name } , ${ AUXILIARY_FIELDS . map (
257
+ ( f ) => "'" + f + "'"
258
+ ) . join ( '|' ) } >> = ${ schema } ;`;
260
259
}
261
260
262
261
addFinalWrappers ( { zodStringFields } : { zodStringFields : string [ ] } ) {
@@ -390,14 +389,21 @@ export default class Transformer {
390
389
const { selectImport, includeImport, selectZodSchemaLineLazy, includeZodSchemaLineLazy } =
391
390
this . resolveSelectIncludeImportAndZodSchemaLine ( model ) ;
392
391
393
- let imports = [ `import { z } from 'zod'` , selectImport , includeImport ] ;
392
+ let imports = [
393
+ `import { z } from 'zod'` ,
394
+ this . generateImportPrismaStatement ( ) ,
395
+ selectImport ,
396
+ includeImport ,
397
+ ] ;
394
398
let codeBody = '' ;
399
+ const operations : [ string , string ] [ ] = [ ] ;
395
400
396
401
if ( findUnique ) {
397
402
imports . push (
398
403
`import { ${ modelName } WhereUniqueInputObjectSchema } from '../objects/${ modelName } WhereUniqueInput.schema'`
399
404
) ;
400
405
codeBody += `findUnique: z.object({ ${ selectZodSchemaLineLazy } ${ includeZodSchemaLineLazy } where: ${ modelName } WhereUniqueInputObjectSchema }),` ;
406
+ operations . push ( [ 'findUnique' , modelName ] ) ;
401
407
}
402
408
403
409
if ( findFirst ) {
@@ -412,6 +418,7 @@ export default class Transformer {
412
418
codeBody += `findFirst: z.object({ ${ selectZodSchemaLineLazy } ${ includeZodSchemaLineLazy } where: ${ modelName } WhereInputObjectSchema.optional(), orderBy: z.union([${ modelName } OrderByWithRelationInputObjectSchema, ${ modelName } OrderByWithRelationInputObjectSchema.array()]).optional(), cursor: ${ modelName } WhereUniqueInputObjectSchema.optional(), take: z.number().optional(), skip: z.number().optional(), distinct: z.array(${ upperCaseFirst (
413
419
modelName
414
420
) } ScalarFieldEnumSchema).optional() }),`;
421
+ operations . push ( [ 'findFirst' , modelName ] ) ;
415
422
}
416
423
417
424
if ( findMany ) {
@@ -426,6 +433,7 @@ export default class Transformer {
426
433
codeBody += `findMany: z.object({ ${ selectZodSchemaLineLazy } ${ includeZodSchemaLineLazy } where: ${ modelName } WhereInputObjectSchema.optional(), orderBy: z.union([${ modelName } OrderByWithRelationInputObjectSchema, ${ modelName } OrderByWithRelationInputObjectSchema.array()]).optional(), cursor: ${ modelName } WhereUniqueInputObjectSchema.optional(), take: z.number().optional(), skip: z.number().optional(), distinct: z.array(${ upperCaseFirst (
427
434
modelName
428
435
) } ScalarFieldEnumSchema).optional() }),`;
436
+ operations . push ( [ 'findMany' , modelName ] ) ;
429
437
}
430
438
431
439
if ( createOne ) {
@@ -434,27 +442,31 @@ export default class Transformer {
434
442
`import { ${ modelName } UncheckedCreateInputObjectSchema } from '../objects/${ modelName } UncheckedCreateInput.schema'`
435
443
) ;
436
444
codeBody += `create: z.object({ ${ selectZodSchemaLineLazy } ${ includeZodSchemaLineLazy } data: z.union([${ modelName } CreateInputObjectSchema, ${ modelName } UncheckedCreateInputObjectSchema]) }),` ;
445
+ operations . push ( [ 'create' , modelName ] ) ;
437
446
}
438
447
439
448
if ( createMany ) {
440
449
imports . push (
441
450
`import { ${ modelName } CreateManyInputObjectSchema } from '../objects/${ modelName } CreateManyInput.schema'`
442
451
) ;
443
452
codeBody += `createMany: z.object({ data: z.union([${ modelName } CreateManyInputObjectSchema, z.array(${ modelName } CreateManyInputObjectSchema)]) }),` ;
453
+ operations . push ( [ 'createMany' , modelName ] ) ;
444
454
}
445
455
446
456
if ( deleteOne ) {
447
457
imports . push (
448
458
`import { ${ modelName } WhereUniqueInputObjectSchema } from '../objects/${ modelName } WhereUniqueInput.schema'`
449
459
) ;
450
460
codeBody += `'delete': z.object({ ${ selectZodSchemaLineLazy } ${ includeZodSchemaLineLazy } where: ${ modelName } WhereUniqueInputObjectSchema }),` ;
461
+ operations . push ( [ 'delete' , modelName ] ) ;
451
462
}
452
463
453
464
if ( deleteMany ) {
454
465
imports . push (
455
466
`import { ${ modelName } WhereInputObjectSchema } from '../objects/${ modelName } WhereInput.schema'`
456
467
) ;
457
468
codeBody += `deleteMany: z.object({ where: ${ modelName } WhereInputObjectSchema.optional() }),` ;
469
+ operations . push ( [ 'deleteMany' , modelName ] ) ;
458
470
}
459
471
460
472
if ( updateOne ) {
@@ -464,6 +476,7 @@ export default class Transformer {
464
476
`import { ${ modelName } WhereUniqueInputObjectSchema } from '../objects/${ modelName } WhereUniqueInput.schema'`
465
477
) ;
466
478
codeBody += `update: z.object({ ${ selectZodSchemaLineLazy } ${ includeZodSchemaLineLazy } data: z.union([${ modelName } UpdateInputObjectSchema, ${ modelName } UncheckedUpdateInputObjectSchema]), where: ${ modelName } WhereUniqueInputObjectSchema }),` ;
479
+ operations . push ( [ 'update' , modelName ] ) ;
467
480
}
468
481
469
482
if ( updateMany ) {
@@ -473,6 +486,7 @@ export default class Transformer {
473
486
`import { ${ modelName } WhereInputObjectSchema } from '../objects/${ modelName } WhereInput.schema'`
474
487
) ;
475
488
codeBody += `updateMany: z.object({ data: z.union([${ modelName } UpdateManyMutationInputObjectSchema, ${ modelName } UncheckedUpdateManyInputObjectSchema]), where: ${ modelName } WhereInputObjectSchema.optional() }),` ;
489
+ operations . push ( [ 'updateMany' , modelName ] ) ;
476
490
}
477
491
478
492
if ( upsertOne ) {
@@ -484,6 +498,7 @@ export default class Transformer {
484
498
`import { ${ modelName } UncheckedUpdateInputObjectSchema } from '../objects/${ modelName } UncheckedUpdateInput.schema'`
485
499
) ;
486
500
codeBody += `upsert: z.object({ ${ selectZodSchemaLineLazy } ${ includeZodSchemaLineLazy } where: ${ modelName } WhereUniqueInputObjectSchema, create: z.union([${ modelName } CreateInputObjectSchema, ${ modelName } UncheckedCreateInputObjectSchema]), update: z.union([${ modelName } UpdateInputObjectSchema, ${ modelName } UncheckedUpdateInputObjectSchema]) }),` ;
501
+ operations . push ( [ 'upsert' , modelName ] ) ;
487
502
}
488
503
489
504
const aggregateOperations = [ ] ;
@@ -532,6 +547,7 @@ export default class Transformer {
532
547
codeBody += `aggregate: z.object({ where: ${ modelName } WhereInputObjectSchema.optional(), orderBy: z.union([${ modelName } OrderByWithRelationInputObjectSchema, ${ modelName } OrderByWithRelationInputObjectSchema.array()]).optional(), cursor: ${ modelName } WhereUniqueInputObjectSchema.optional(), take: z.number().optional(), skip: z.number().optional(), ${ aggregateOperations . join (
533
548
', '
534
549
) } }),`;
550
+ operations . push ( [ 'aggregate' , modelNameVar ] ) ;
535
551
}
536
552
537
553
if ( groupBy ) {
@@ -546,6 +562,7 @@ export default class Transformer {
546
562
codeBody += `groupBy: z.object({ where: ${ modelName } WhereInputObjectSchema.optional(), orderBy: z.union([${ modelName } OrderByWithAggregationInputObjectSchema, ${ modelName } OrderByWithAggregationInputObjectSchema.array()]).optional(), having: ${ modelName } ScalarWhereWithAggregatesInputObjectSchema.optional(), take: z.number().optional(), skip: z.number().optional(), by: z.array(${ upperCaseFirst (
547
563
modelName
548
564
) } ScalarFieldEnumSchema), ${ aggregateOperations . join ( ', ' ) } }),`;
565
+ operations . push ( [ 'groupBy' , modelNameVar ] ) ;
549
566
}
550
567
551
568
imports = [ ...new Set ( imports ) ] ;
@@ -555,7 +572,13 @@ export default class Transformer {
555
572
/* eslint-disable */
556
573
${ imports . join ( ';\n' ) }
557
574
558
- export const ${ modelName } InputSchema = {
575
+ type ${ modelName } InputSchemaType = {
576
+ ${ operations
577
+ . map ( ( op ) => indentString ( `${ op [ 0 ] } : z.ZodType<Prisma.${ op [ 1 ] } ${ upperCaseFirst ( op [ 0 ] ) } Args>` , 4 ) )
578
+ . join ( ',\n' ) }
579
+ }
580
+
581
+ export const ${ modelName } InputSchema: ${ modelName } InputSchemaType = {
559
582
${ indentString ( codeBody , 4 ) }
560
583
};
561
584
` ;
0 commit comments