@@ -39,45 +39,15 @@ import type {
3939 UpdateManyArgs ,
4040 UpsertArgs ,
4141} from './crud-types' ;
42- import type {
43- CoreCreateOperations ,
44- CoreCrudOperations ,
45- CoreDeleteOperations ,
46- CoreReadOperations ,
47- CoreUpdateOperations ,
48- } from './crud/operations/base' ;
4942import type { ClientOptions , QueryOptions } from './options' ;
5043import type { ExtClientMembersBase , ExtQueryArgsBase , RuntimePlugin } from './plugin' ;
5144import type { ZenStackPromise } from './promise' ;
5245import type { ToKysely } from './query-builder' ;
5346import type { GetSlicedModels , GetSlicedOperations , GetSlicedProcedures } from './type-utils' ;
47+ import type { ZodSchemaFactory } from './zod/factory' ;
5448
5549type TransactionUnsupportedMethods = ( typeof TRANSACTION_UNSUPPORTED_METHODS ) [ number ] ;
5650
57- /**
58- * Extracts extended query args for a specific operation.
59- */
60- type ExtractExtQueryArgs < ExtQueryArgs , Operation extends CoreCrudOperations > = ( Operation extends keyof ExtQueryArgs
61- ? ExtQueryArgs [ Operation ]
62- : { } ) &
63- ( '$create' extends keyof ExtQueryArgs
64- ? Operation extends CoreCreateOperations
65- ? ExtQueryArgs [ '$create' ]
66- : { }
67- : { } ) &
68- ( '$read' extends keyof ExtQueryArgs ? ( Operation extends CoreReadOperations ? ExtQueryArgs [ '$read' ] : { } ) : { } ) &
69- ( '$update' extends keyof ExtQueryArgs
70- ? Operation extends CoreUpdateOperations
71- ? ExtQueryArgs [ '$update' ]
72- : { }
73- : { } ) &
74- ( '$delete' extends keyof ExtQueryArgs
75- ? Operation extends CoreDeleteOperations
76- ? ExtQueryArgs [ '$delete' ]
77- : { }
78- : { } ) &
79- ( '$all' extends keyof ExtQueryArgs ? ExtQueryArgs [ '$all' ] : { } ) ;
80-
8151/**
8252 * Transaction isolation levels.
8353 */
@@ -232,6 +202,11 @@ export type ClientContract<
232202 */
233203 $disconnect ( ) : Promise < void > ;
234204
205+ /**
206+ * Factory for creating zod schemas to validate query args.
207+ */
208+ get $zod ( ) : ZodSchemaFactory < Schema , Options , ExtQueryArgs > ;
209+
235210 /**
236211 * Pushes the schema to the database. For testing purposes only.
237212 * @private
@@ -317,7 +292,7 @@ export type AllModelOperations<
317292 Schema extends SchemaDef ,
318293 Model extends GetModels < Schema > ,
319294 Options extends QueryOptions < Schema > ,
320- ExtQueryArgs ,
295+ ExtQueryArgs extends ExtQueryArgsBase ,
321296> = CommonModelOperations < Schema , Model , Options , ExtQueryArgs > &
322297 // provider-specific operations
323298 ( Schema [ 'provider' ] [ 'type' ] extends 'mysql'
@@ -341,15 +316,8 @@ export type AllModelOperations<
341316 * });
342317 * ```
343318 */
344- createManyAndReturn <
345- T extends CreateManyAndReturnArgs < Schema , Model , Options > &
346- ExtractExtQueryArgs < ExtQueryArgs , 'createManyAndReturn' > ,
347- > (
348- args ?: SelectSubset <
349- T ,
350- CreateManyAndReturnArgs < Schema , Model , Options > &
351- ExtractExtQueryArgs < ExtQueryArgs , 'createManyAndReturn' >
352- > ,
319+ createManyAndReturn < T extends CreateManyAndReturnArgs < Schema , Model , Options , ExtQueryArgs > > (
320+ args ?: SelectSubset < T , CreateManyAndReturnArgs < Schema , Model , Options , ExtQueryArgs > > ,
353321 ) : ZenStackPromise < Schema , SimplifiedPlainResult < Schema , Model , T , Options > [ ] > ;
354322
355323 /**
@@ -374,23 +342,16 @@ export type AllModelOperations<
374342 * });
375343 * ```
376344 */
377- updateManyAndReturn <
378- T extends UpdateManyAndReturnArgs < Schema , Model , Options > &
379- ExtractExtQueryArgs < ExtQueryArgs , 'updateManyAndReturn' > ,
380- > (
381- args : Subset <
382- T ,
383- UpdateManyAndReturnArgs < Schema , Model , Options > &
384- ExtractExtQueryArgs < ExtQueryArgs , 'updateManyAndReturn' >
385- > ,
345+ updateManyAndReturn < T extends UpdateManyAndReturnArgs < Schema , Model , Options , ExtQueryArgs > > (
346+ args : Subset < T , UpdateManyAndReturnArgs < Schema , Model , Options , ExtQueryArgs > > ,
386347 ) : ZenStackPromise < Schema , SimplifiedPlainResult < Schema , Model , T , Options > [ ] > ;
387348 } ) ;
388349
389350type CommonModelOperations <
390351 Schema extends SchemaDef ,
391352 Model extends GetModels < Schema > ,
392353 Options extends QueryOptions < Schema > ,
393- ExtQueryArgs ,
354+ ExtQueryArgs extends ExtQueryArgsBase ,
394355> = {
395356 /**
396357 * Returns a list of entities.
@@ -473,8 +434,8 @@ type CommonModelOperations<
473434 * }); // result: `{ _count: { posts: number } }`
474435 * ```
475436 */
476- findMany < T extends FindManyArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'findMany' > > (
477- args ?: SelectSubset < T , FindManyArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'findMany' > > ,
437+ findMany < T extends FindManyArgs < Schema , Model , Options , ExtQueryArgs > > (
438+ args ?: SelectSubset < T , FindManyArgs < Schema , Model , Options , ExtQueryArgs > > ,
478439 ) : ZenStackPromise < Schema , SimplifiedPlainResult < Schema , Model , T , Options > [ ] > ;
479440
480441 /**
@@ -483,8 +444,8 @@ type CommonModelOperations<
483444 * @returns a single entity or null if not found
484445 * @see {@link findMany }
485446 */
486- findUnique < T extends FindUniqueArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'findUnique' > > (
487- args : SelectSubset < T , FindUniqueArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'findUnique' > > ,
447+ findUnique < T extends FindUniqueArgs < Schema , Model , Options , ExtQueryArgs > > (
448+ args : SelectSubset < T , FindUniqueArgs < Schema , Model , Options , ExtQueryArgs > > ,
488449 ) : ZenStackPromise < Schema , SimplifiedPlainResult < Schema , Model , T , Options > | null > ;
489450
490451 /**
@@ -493,10 +454,8 @@ type CommonModelOperations<
493454 * @returns a single entity
494455 * @see {@link findMany }
495456 */
496- findUniqueOrThrow <
497- T extends FindUniqueArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'findUnique' > ,
498- > (
499- args : SelectSubset < T , FindUniqueArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'findUnique' > > ,
457+ findUniqueOrThrow < T extends FindUniqueArgs < Schema , Model , Options , ExtQueryArgs > > (
458+ args : SelectSubset < T , FindUniqueArgs < Schema , Model , Options , ExtQueryArgs > > ,
500459 ) : ZenStackPromise < Schema , SimplifiedPlainResult < Schema , Model , T , Options > > ;
501460
502461 /**
@@ -505,8 +464,8 @@ type CommonModelOperations<
505464 * @returns a single entity or null if not found
506465 * @see {@link findMany }
507466 */
508- findFirst < T extends FindFirstArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'findFirst' > > (
509- args ?: SelectSubset < T , FindFirstArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'findFirst' > > ,
467+ findFirst < T extends FindFirstArgs < Schema , Model , Options , ExtQueryArgs > > (
468+ args ?: SelectSubset < T , FindFirstArgs < Schema , Model , Options , ExtQueryArgs > > ,
510469 ) : ZenStackPromise < Schema , SimplifiedPlainResult < Schema , Model , T , Options > | null > ;
511470
512471 /**
@@ -515,8 +474,8 @@ type CommonModelOperations<
515474 * @returns a single entity
516475 * @see {@link findMany }
517476 */
518- findFirstOrThrow < T extends FindFirstArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'findFirst' > > (
519- args ?: SelectSubset < T , FindFirstArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'findFirst' > > ,
477+ findFirstOrThrow < T extends FindFirstArgs < Schema , Model , Options , ExtQueryArgs > > (
478+ args ?: SelectSubset < T , FindFirstArgs < Schema , Model , Options , ExtQueryArgs > > ,
520479 ) : ZenStackPromise < Schema , SimplifiedPlainResult < Schema , Model , T , Options > > ;
521480
522481 /**
@@ -571,8 +530,8 @@ type CommonModelOperations<
571530 * });
572531 * ```
573532 */
574- create < T extends CreateArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'create' > > (
575- args : SelectSubset < T , CreateArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'create' > > ,
533+ create < T extends CreateArgs < Schema , Model , Options , ExtQueryArgs > > (
534+ args : SelectSubset < T , CreateArgs < Schema , Model , Options , ExtQueryArgs > > ,
576535 ) : ZenStackPromise < Schema , SimplifiedPlainResult < Schema , Model , T , Options > > ;
577536
578537 /**
@@ -600,8 +559,8 @@ type CommonModelOperations<
600559 * });
601560 * ```
602561 */
603- createMany < T extends CreateManyArgs < Schema , Model > & ExtractExtQueryArgs < ExtQueryArgs , 'createMany' > > (
604- args ?: SelectSubset < T , CreateManyArgs < Schema , Model > & ExtractExtQueryArgs < ExtQueryArgs , 'createMany' > > ,
562+ createMany < T extends CreateManyArgs < Schema , Model , Options , ExtQueryArgs > > (
563+ args ?: SelectSubset < T , CreateManyArgs < Schema , Model , Options , ExtQueryArgs > > ,
605564 ) : ZenStackPromise < Schema , BatchResult > ;
606565
607566 /**
@@ -721,8 +680,8 @@ type CommonModelOperations<
721680 * });
722681 * ```
723682 */
724- update < T extends UpdateArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'update' > > (
725- args : SelectSubset < T , UpdateArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'update' > > ,
683+ update < T extends UpdateArgs < Schema , Model , Options , ExtQueryArgs > > (
684+ args : SelectSubset < T , UpdateArgs < Schema , Model , Options , ExtQueryArgs > > ,
726685 ) : ZenStackPromise < Schema , SimplifiedPlainResult < Schema , Model , T , Options > > ;
727686
728687 /**
@@ -745,8 +704,8 @@ type CommonModelOperations<
745704 * limit: 10
746705 * });
747706 */
748- updateMany < T extends UpdateManyArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'updateMany' > > (
749- args : Subset < T , UpdateManyArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'updateMany' > > ,
707+ updateMany < T extends UpdateManyArgs < Schema , Model , Options , ExtQueryArgs > > (
708+ args : Subset < T , UpdateManyArgs < Schema , Model , Options , ExtQueryArgs > > ,
750709 ) : ZenStackPromise < Schema , BatchResult > ;
751710
752711 /**
@@ -769,8 +728,8 @@ type CommonModelOperations<
769728 * });
770729 * ```
771730 */
772- upsert < T extends UpsertArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'upsert' > > (
773- args : SelectSubset < T , UpsertArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'upsert' > > ,
731+ upsert < T extends UpsertArgs < Schema , Model , Options , ExtQueryArgs > > (
732+ args : SelectSubset < T , UpsertArgs < Schema , Model , Options , ExtQueryArgs > > ,
774733 ) : ZenStackPromise < Schema , SimplifiedPlainResult < Schema , Model , T , Options > > ;
775734
776735 /**
@@ -792,8 +751,8 @@ type CommonModelOperations<
792751 * }); // result: `{ id: string; email: string }`
793752 * ```
794753 */
795- delete < T extends DeleteArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'delete' > > (
796- args : SelectSubset < T , DeleteArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'delete' > > ,
754+ delete < T extends DeleteArgs < Schema , Model , Options , ExtQueryArgs > > (
755+ args : SelectSubset < T , DeleteArgs < Schema , Model , Options , ExtQueryArgs > > ,
797756 ) : ZenStackPromise < Schema , SimplifiedPlainResult < Schema , Model , T , Options > > ;
798757
799758 /**
@@ -815,8 +774,8 @@ type CommonModelOperations<
815774 * });
816775 * ```
817776 */
818- deleteMany < T extends DeleteManyArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'deleteMany' > > (
819- args ?: Subset < T , DeleteManyArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'deleteMany' > > ,
777+ deleteMany < T extends DeleteManyArgs < Schema , Model , Options , ExtQueryArgs > > (
778+ args ?: Subset < T , DeleteManyArgs < Schema , Model , Options , ExtQueryArgs > > ,
820779 ) : ZenStackPromise < Schema , BatchResult > ;
821780
822781 /**
@@ -837,8 +796,8 @@ type CommonModelOperations<
837796 * select: { _all: true, email: true }
838797 * }); // result: `{ _all: number, email: number }`
839798 */
840- count < T extends CountArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'count' > > (
841- args ?: Subset < T , CountArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'count' > > ,
799+ count < T extends CountArgs < Schema , Model , Options , ExtQueryArgs > > (
800+ args ?: Subset < T , CountArgs < Schema , Model , Options , ExtQueryArgs > > ,
842801 ) : ZenStackPromise < Schema , Simplify < CountResult < Schema , Model , T > > > ;
843802
844803 /**
@@ -858,8 +817,8 @@ type CommonModelOperations<
858817 * _max: { age: true }
859818 * }); // result: `{ _count: number, _avg: { age: number }, ... }`
860819 */
861- aggregate < T extends AggregateArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'aggregate' > > (
862- args : Subset < T , AggregateArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'aggregate' > > ,
820+ aggregate < T extends AggregateArgs < Schema , Model , Options , ExtQueryArgs > > (
821+ args : Subset < T , AggregateArgs < Schema , Model , Options , ExtQueryArgs > > ,
863822 ) : ZenStackPromise < Schema , Simplify < AggregateResult < Schema , Model , T > > > ;
864823
865824 /**
@@ -895,8 +854,8 @@ type CommonModelOperations<
895854 * having: { country: 'US', age: { _avg: { gte: 18 } } }
896855 * });
897856 */
898- groupBy < T extends GroupByArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'groupBy' > > (
899- args : Subset < T , GroupByArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'groupBy' > > ,
857+ groupBy < T extends GroupByArgs < Schema , Model , Options , ExtQueryArgs > > (
858+ args : Subset < T , GroupByArgs < Schema , Model , Options , ExtQueryArgs > > ,
900859 ) : ZenStackPromise < Schema , Simplify < GroupByResult < Schema , Model , T > > > ;
901860
902861 /**
@@ -916,8 +875,8 @@ type CommonModelOperations<
916875 * where: { posts: { some: { published: true } } },
917876 * }); // result: `boolean`
918877 */
919- exists < T extends ExistsArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'exists' > > (
920- args ?: Subset < T , ExistsArgs < Schema , Model , Options > & ExtractExtQueryArgs < ExtQueryArgs , 'exists' > > ,
878+ exists < T extends ExistsArgs < Schema , Model , Options , ExtQueryArgs > > (
879+ args ?: Subset < T , ExistsArgs < Schema , Model , Options , ExtQueryArgs > > ,
921880 ) : ZenStackPromise < Schema , boolean > ;
922881} ;
923882
@@ -927,7 +886,7 @@ export type ModelOperations<
927886 Schema extends SchemaDef ,
928887 Model extends GetModels < Schema > ,
929888 Options extends ClientOptions < Schema > = ClientOptions < Schema > ,
930- ExtQueryArgs = { } ,
889+ ExtQueryArgs extends ExtQueryArgsBase = { } ,
931890> = SliceOperations < AllModelOperations < Schema , Model , Options , ExtQueryArgs > , Schema , Model , Options > ;
932891
933892//#endregion
0 commit comments