prisma-guard 1.24.0 → 1.26.0

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.
@@ -56,7 +56,7 @@ interface ShapeConfig {
56
56
  include?: Record<string, true | NestedIncludeArgs>;
57
57
  select?: Record<string, true | NestedSelectArgs>;
58
58
  orderBy?: true | Record<string, OrderByFieldConfig>;
59
- cursor?: Record<string, true>;
59
+ cursor?: Record<string, unknown>;
60
60
  take?: number | {
61
61
  max: number;
62
62
  default?: number;
@@ -76,7 +76,7 @@ interface NestedIncludeArgs {
76
76
  include?: Record<string, true | NestedIncludeArgs>;
77
77
  select?: Record<string, true | NestedSelectArgs>;
78
78
  orderBy?: Record<string, OrderByFieldConfig>;
79
- cursor?: Record<string, true>;
79
+ cursor?: Record<string, unknown>;
80
80
  take?: number | {
81
81
  max: number;
82
82
  default?: number;
@@ -88,7 +88,7 @@ interface NestedSelectArgs {
88
88
  include?: Record<string, true | NestedIncludeArgs>;
89
89
  select?: Record<string, true | NestedSelectArgs>;
90
90
  orderBy?: Record<string, OrderByFieldConfig>;
91
- cursor?: Record<string, true>;
91
+ cursor?: Record<string, unknown>;
92
92
  take?: number | {
93
93
  max: number;
94
94
  default?: number;
@@ -106,7 +106,10 @@ type TypeMap = Record<string, Record<string, FieldMeta>>;
106
106
  type EnumMap = Record<string, readonly string[]>;
107
107
  type ZodChains = Record<string, Record<string, (base: any) => z.ZodTypeAny>>;
108
108
  type ZodDefaults = Record<string, readonly string[]>;
109
- type UniqueConstraint = readonly string[];
109
+ interface UniqueConstraint {
110
+ readonly selector: string;
111
+ readonly fields: readonly string[];
112
+ }
110
113
  type UniqueMap = Record<string, readonly UniqueConstraint[]>;
111
114
  type MissingScopeContextMode = 'error' | 'warn' | 'ignore';
112
115
  type FindUniqueMode = 'verify' | 'reject';
@@ -227,7 +230,12 @@ interface FieldMetaConst {
227
230
  readonly isUnique?: boolean;
228
231
  readonly isUnsupported?: boolean;
229
232
  }
233
+ interface UniqueConstraintConst {
234
+ readonly selector: string;
235
+ readonly fields: readonly string[];
236
+ }
230
237
  type TypeMapConst = Record<string, Record<string, FieldMetaConst>>;
238
+ type UniqueMapConst = Record<string, readonly UniqueConstraintConst[]>;
231
239
  type ShapeDepth = 0 | 1 | 2 | 3;
232
240
  type DecDepth<D extends ShapeDepth> = D extends 3 ? 2 : D extends 2 ? 1 : D extends 1 ? 0 : 0;
233
241
  type AllFields<TM extends TypeMapConst, M extends keyof TM> = keyof TM[M] & string;
@@ -268,6 +276,31 @@ type LooseNestedArgs = {
268
276
  skip?: true;
269
277
  };
270
278
  type TypedWhere<TM extends TypeMapConst, M extends keyof TM> = Partial<Record<AllFields<TM, M> | 'AND' | 'OR' | 'NOT', unknown>>;
279
+ type ForcedShapeValue<T> = {
280
+ value: T;
281
+ };
282
+ type UniqueScalarValue<F extends FieldMetaConst> = F['isEnum'] extends true ? string : F['type'] extends 'String' ? string : F['type'] extends 'Int' ? number : F['type'] extends 'BigInt' ? bigint | number | string : F['type'] extends 'Float' ? number : F['type'] extends 'Decimal' ? number | string : F['type'] extends 'Boolean' ? boolean : F['type'] extends 'DateTime' ? Date | string : F['type'] extends 'Bytes' ? Uint8Array | string : string | number | bigint | boolean | Date | Uint8Array;
283
+ type TypedUniqueWhereValue<F extends FieldMetaConst> = true | UniqueScalarValue<F> | ForcedShapeValue<UniqueScalarValue<F>>;
284
+ type SingleFieldUniqueWhere<TM extends TypeMapConst, M extends keyof TM> = Partial<{
285
+ [K in UniqueFields<TM, M>]: TypedUniqueWhereValue<TM[M][K]>;
286
+ }>;
287
+ type ModelUniqueConstraints<TM extends TypeMapConst, M extends keyof TM, UM extends UniqueMapConst> = M extends keyof UM ? UM[M][number] : never;
288
+ type UniqueSelectorNames<TM extends TypeMapConst, M extends keyof TM, UM extends UniqueMapConst> = ModelUniqueConstraints<TM, M, UM> extends infer C ? C extends UniqueConstraintConst ? C['selector'] & string : never : never;
289
+ type UniqueConstraintBySelector<TM extends TypeMapConst, M extends keyof TM, UM extends UniqueMapConst, S extends string> = Extract<ModelUniqueConstraints<TM, M, UM>, {
290
+ readonly selector: S;
291
+ }>;
292
+ type UniqueFieldName<TM extends TypeMapConst, M extends keyof TM, F> = Extract<F, keyof TM[M] & string>;
293
+ type TypedCompoundUniqueSelector<TM extends TypeMapConst, M extends keyof TM, C extends UniqueConstraintConst> = {
294
+ [K in UniqueFieldName<TM, M, C['fields'][number]>]: TypedUniqueWhereValue<TM[M][K]>;
295
+ };
296
+ type TypedCompoundUniqueForcedValue<TM extends TypeMapConst, M extends keyof TM, C extends UniqueConstraintConst> = {
297
+ [K in UniqueFieldName<TM, M, C['fields'][number]>]: UniqueScalarValue<TM[M][K]>;
298
+ };
299
+ type TypedUniqueSelectorValue<TM extends TypeMapConst, M extends keyof TM, C extends UniqueConstraintConst> = C['fields'] extends readonly [infer F] ? TypedUniqueWhereValue<TM[M][UniqueFieldName<TM, M, F>]> : TypedCompoundUniqueSelector<TM, M, C> | ForcedShapeValue<TypedCompoundUniqueForcedValue<TM, M, C>>;
300
+ type GeneratedUniqueWhere<TM extends TypeMapConst, M extends keyof TM, UM extends UniqueMapConst> = Partial<{
301
+ [S in UniqueSelectorNames<TM, M, UM>]: TypedUniqueSelectorValue<TM, M, UniqueConstraintBySelector<TM, M, UM, S>>;
302
+ }>;
303
+ type TypedUniqueWhere<TM extends TypeMapConst, M extends keyof TM, UM extends UniqueMapConst = {}> = SingleFieldUniqueWhere<TM, M> & GeneratedUniqueWhere<TM, M, UM>;
271
304
  type TypedCountSelectInProjection<TM extends TypeMapConst, M extends keyof TM> = {
272
305
  [K in ListRelationFields<TM, M>]?: true | {
273
306
  where?: TypedWhere<TM, RelTarget<TM, M, K>>;
@@ -276,36 +309,36 @@ type TypedCountSelectInProjection<TM extends TypeMapConst, M extends keyof TM> =
276
309
  type TypedProjectionCount<TM extends TypeMapConst, M extends keyof TM> = true | {
277
310
  select: TypedCountSelectInProjection<TM, M>;
278
311
  };
279
- type TypedNestedRelArgs<TM extends TypeMapConst, T, D extends ShapeDepth> = T extends keyof TM ? D extends 0 ? LooseNestedArgs : {
280
- select?: TypedProjection<TM, T, DecDepth<D>>;
281
- include?: TypedInclude<TM, T, DecDepth<D>>;
312
+ type TypedNestedRelArgs<TM extends TypeMapConst, T, D extends ShapeDepth, UM extends UniqueMapConst = {}> = T extends keyof TM ? D extends 0 ? LooseNestedArgs : {
313
+ select?: TypedProjection<TM, T, DecDepth<D>, UM>;
314
+ include?: TypedInclude<TM, T, DecDepth<D>, UM>;
282
315
  where?: TypedWhere<TM, T>;
283
316
  orderBy?: true | Partial<Record<AllFields<TM, T>, unknown>>;
284
- cursor?: Partial<Record<UniqueFields<TM, T>, true>>;
317
+ cursor?: TypedUniqueWhere<TM, T, UM>;
285
318
  take?: number | {
286
319
  max: number;
287
320
  default?: number;
288
321
  };
289
322
  skip?: true;
290
323
  } : LooseNestedArgs;
291
- type TypedProjection<TM extends TypeMapConst, M extends keyof TM, D extends ShapeDepth> = {
292
- [K in AllFields<TM, M>]?: K extends RelationFields<TM, M> ? true | TypedNestedRelArgs<TM, RelTarget<TM, M, K>, D> : true;
324
+ type TypedProjection<TM extends TypeMapConst, M extends keyof TM, D extends ShapeDepth, UM extends UniqueMapConst = {}> = {
325
+ [K in AllFields<TM, M>]?: K extends RelationFields<TM, M> ? true | TypedNestedRelArgs<TM, RelTarget<TM, M, K>, D, UM> : true;
293
326
  } & {
294
327
  _count?: TypedProjectionCount<TM, M>;
295
328
  };
296
- type TypedInclude<TM extends TypeMapConst, M extends keyof TM, D extends ShapeDepth> = {
297
- [K in RelationFields<TM, M>]?: true | TypedNestedRelArgs<TM, RelTarget<TM, M, K>, D>;
329
+ type TypedInclude<TM extends TypeMapConst, M extends keyof TM, D extends ShapeDepth, UM extends UniqueMapConst = {}> = {
330
+ [K in RelationFields<TM, M>]?: true | TypedNestedRelArgs<TM, RelTarget<TM, M, K>, D, UM>;
298
331
  } & {
299
332
  _count?: TypedProjectionCount<TM, M>;
300
333
  };
301
334
  type TypedCountSelect<TM extends TypeMapConst, M extends keyof TM> = Partial<Record<ScalarFields<TM, M> | '_all', true>>;
302
335
  type TypedCountField<TM extends TypeMapConst, M extends keyof TM> = true | Partial<Record<ScalarFields<TM, M> | '_all', true>>;
303
- type TypedShapeProps<TM extends TypeMapConst, M extends keyof TM, D extends ShapeDepth> = {
336
+ type TypedShapeProps<TM extends TypeMapConst, M extends keyof TM, D extends ShapeDepth, UM extends UniqueMapConst = {}> = {
304
337
  where: TypedWhere<TM, M>;
305
- select: TypedProjection<TM, M, D>;
306
- include: TypedInclude<TM, M, D>;
338
+ select: TypedProjection<TM, M, D, UM>;
339
+ include: TypedInclude<TM, M, D, UM>;
307
340
  orderBy: true | Partial<Record<AllFields<TM, M>, unknown>>;
308
- cursor: Partial<Record<UniqueFields<TM, M>, true>>;
341
+ cursor: TypedUniqueWhere<TM, M, UM>;
309
342
  take: number | {
310
343
  max: number;
311
344
  default?: number;
@@ -323,17 +356,23 @@ type TypedShapeProps<TM extends TypeMapConst, M extends keyof TM, D extends Shap
323
356
  create: Partial<Record<WritableFields<TM, M>, unknown>>;
324
357
  update: Partial<Record<WritableFields<TM, M>, unknown>>;
325
358
  };
326
- type BaseOperationShape<TM extends TypeMapConst, M extends keyof TM, O extends OperationName, D extends ShapeDepth> = Partial<Pick<TypedShapeProps<TM, M, D>, Extract<OperationShapeKey<O>, keyof TypedShapeProps<TM, M, D>>>>;
359
+ type BaseOperationShape<TM extends TypeMapConst, M extends keyof TM, O extends OperationName, D extends ShapeDepth, UM extends UniqueMapConst> = Partial<Pick<TypedShapeProps<TM, M, D, UM>, Extract<OperationShapeKey<O>, keyof TypedShapeProps<TM, M, D, UM>>>>;
327
360
  type RequireKeys<T, K extends keyof T> = Omit<T, K> & {
328
361
  [P in K]-?: NonNullable<T[P]>;
329
362
  };
330
- type CountShape<TM extends TypeMapConst, M extends keyof TM, D extends ShapeDepth> = Omit<BaseOperationShape<TM, M, 'count', D>, 'select'> & {
363
+ type CountShape<TM extends TypeMapConst, M extends keyof TM, D extends ShapeDepth, UM extends UniqueMapConst> = Omit<BaseOperationShape<TM, M, 'count', D, UM>, 'select'> & {
331
364
  select?: TypedCountSelect<TM, M>;
332
365
  };
333
- type OperationShape<TM extends TypeMapConst, M extends keyof TM, O extends OperationName, D extends ShapeDepth = 1> = O extends 'findUnique' ? RequireKeys<BaseOperationShape<TM, M, 'findUnique', D>, 'where'> : O extends 'findUniqueOrThrow' ? RequireKeys<BaseOperationShape<TM, M, 'findUniqueOrThrow', D>, 'where'> : O extends 'groupBy' ? RequireKeys<BaseOperationShape<TM, M, 'groupBy', D>, 'by'> : O extends 'count' ? CountShape<TM, M, D> : BaseOperationShape<TM, M, O, D>;
334
- type TypedGuardShape<TM extends TypeMapConst, M extends keyof TM, D extends ShapeDepth = 1> = Partial<TypedShapeProps<TM, M, D>>;
366
+ type UniqueWhereShape<TM extends TypeMapConst, M extends keyof TM, O extends OperationName, D extends ShapeDepth, UM extends UniqueMapConst> = Omit<BaseOperationShape<TM, M, O, D, UM>, 'where'> & {
367
+ where?: TypedUniqueWhere<TM, M, UM>;
368
+ };
369
+ type RequiredUniqueWhereShape<TM extends TypeMapConst, M extends keyof TM, O extends OperationName, D extends ShapeDepth, UM extends UniqueMapConst> = Omit<BaseOperationShape<TM, M, O, D, UM>, 'where'> & {
370
+ where: TypedUniqueWhere<TM, M, UM>;
371
+ };
372
+ type OperationShape<TM extends TypeMapConst, M extends keyof TM, O extends OperationName, D extends ShapeDepth = 1, UM extends UniqueMapConst = {}> = O extends 'findUnique' ? RequiredUniqueWhereShape<TM, M, 'findUnique', D, UM> : O extends 'findUniqueOrThrow' ? RequiredUniqueWhereShape<TM, M, 'findUniqueOrThrow', D, UM> : O extends 'update' ? UniqueWhereShape<TM, M, 'update', D, UM> : O extends 'delete' ? UniqueWhereShape<TM, M, 'delete', D, UM> : O extends 'upsert' ? UniqueWhereShape<TM, M, 'upsert', D, UM> : O extends 'groupBy' ? RequireKeys<BaseOperationShape<TM, M, 'groupBy', D, UM>, 'by'> : O extends 'count' ? CountShape<TM, M, D, UM> : BaseOperationShape<TM, M, O, D, UM>;
373
+ type TypedGuardShape<TM extends TypeMapConst, M extends keyof TM, D extends ShapeDepth = 1, UM extends UniqueMapConst = {}> = Partial<TypedShapeProps<TM, M, D, UM>>;
335
374
  type ShapeFn<S, TCtx> = (ctx: TCtx) => S;
336
375
  type ShapeOrFn<S, TCtx> = S | ShapeFn<S, TCtx>;
337
376
  type ShapeInput<S, TCtx = unknown> = ShapeOrFn<S, TCtx> | Record<string, ShapeOrFn<S, TCtx>>;
338
377
 
339
- export { CallerError, type ComparableFields, type EnumMap, type FieldMeta, type FieldMetaConst, type GuardConfig, type GuardGeneratedConfig, type GuardInput, type GuardLogger, type GuardShape, type GuardShapeOrFn, type GuardedModel, type InputOpts, type InputSchema, type MissingScopeContextMode, type ModelOpts, type MutationMethod, type NestedIncludeArgs, type NestedSelectArgs, type NumericFields, type OperationName, type OperationShape, PolicyError, type QueryMethod, type QuerySchema, type ScopeEntry, type ScopeMap, type ShapeConfig, type ShapeDepth, ShapeError, type ShapeInput, type ShapeOrFn$1 as ShapeOrFn, type TypeMap, type TypeMapConst, type TypedCountSelect, type TypedGuardShape, type TypedInclude, type TypedProjection, type TypedShapeProps, type TypedWhere, type UniqueConstraint, type UniqueMap, type ZodChains, type ZodDefaults, createGuard, force, unsupported };
378
+ export { CallerError, type ComparableFields, type EnumMap, type FieldMeta, type FieldMetaConst, type GuardConfig, type GuardGeneratedConfig, type GuardInput, type GuardLogger, type GuardShape, type GuardShapeOrFn, type GuardedModel, type InputOpts, type InputSchema, type MissingScopeContextMode, type ModelOpts, type MutationMethod, type NestedIncludeArgs, type NestedSelectArgs, type NumericFields, type OperationName, type OperationShape, PolicyError, type QueryMethod, type QuerySchema, type ScopeEntry, type ScopeMap, type ShapeConfig, type ShapeDepth, ShapeError, type ShapeInput, type ShapeOrFn$1 as ShapeOrFn, type TypeMap, type TypeMapConst, type TypedCountSelect, type TypedGuardShape, type TypedInclude, type TypedProjection, type TypedShapeProps, type TypedUniqueWhere, type TypedWhere, type UniqueConstraint, type UniqueConstraintConst, type UniqueMap, type UniqueMapConst, type ZodChains, type ZodDefaults, createGuard, force, unsupported };
@@ -56,7 +56,7 @@ interface ShapeConfig {
56
56
  include?: Record<string, true | NestedIncludeArgs>;
57
57
  select?: Record<string, true | NestedSelectArgs>;
58
58
  orderBy?: true | Record<string, OrderByFieldConfig>;
59
- cursor?: Record<string, true>;
59
+ cursor?: Record<string, unknown>;
60
60
  take?: number | {
61
61
  max: number;
62
62
  default?: number;
@@ -76,7 +76,7 @@ interface NestedIncludeArgs {
76
76
  include?: Record<string, true | NestedIncludeArgs>;
77
77
  select?: Record<string, true | NestedSelectArgs>;
78
78
  orderBy?: Record<string, OrderByFieldConfig>;
79
- cursor?: Record<string, true>;
79
+ cursor?: Record<string, unknown>;
80
80
  take?: number | {
81
81
  max: number;
82
82
  default?: number;
@@ -88,7 +88,7 @@ interface NestedSelectArgs {
88
88
  include?: Record<string, true | NestedIncludeArgs>;
89
89
  select?: Record<string, true | NestedSelectArgs>;
90
90
  orderBy?: Record<string, OrderByFieldConfig>;
91
- cursor?: Record<string, true>;
91
+ cursor?: Record<string, unknown>;
92
92
  take?: number | {
93
93
  max: number;
94
94
  default?: number;
@@ -106,7 +106,10 @@ type TypeMap = Record<string, Record<string, FieldMeta>>;
106
106
  type EnumMap = Record<string, readonly string[]>;
107
107
  type ZodChains = Record<string, Record<string, (base: any) => z.ZodTypeAny>>;
108
108
  type ZodDefaults = Record<string, readonly string[]>;
109
- type UniqueConstraint = readonly string[];
109
+ interface UniqueConstraint {
110
+ readonly selector: string;
111
+ readonly fields: readonly string[];
112
+ }
110
113
  type UniqueMap = Record<string, readonly UniqueConstraint[]>;
111
114
  type MissingScopeContextMode = 'error' | 'warn' | 'ignore';
112
115
  type FindUniqueMode = 'verify' | 'reject';
@@ -227,7 +230,12 @@ interface FieldMetaConst {
227
230
  readonly isUnique?: boolean;
228
231
  readonly isUnsupported?: boolean;
229
232
  }
233
+ interface UniqueConstraintConst {
234
+ readonly selector: string;
235
+ readonly fields: readonly string[];
236
+ }
230
237
  type TypeMapConst = Record<string, Record<string, FieldMetaConst>>;
238
+ type UniqueMapConst = Record<string, readonly UniqueConstraintConst[]>;
231
239
  type ShapeDepth = 0 | 1 | 2 | 3;
232
240
  type DecDepth<D extends ShapeDepth> = D extends 3 ? 2 : D extends 2 ? 1 : D extends 1 ? 0 : 0;
233
241
  type AllFields<TM extends TypeMapConst, M extends keyof TM> = keyof TM[M] & string;
@@ -268,6 +276,31 @@ type LooseNestedArgs = {
268
276
  skip?: true;
269
277
  };
270
278
  type TypedWhere<TM extends TypeMapConst, M extends keyof TM> = Partial<Record<AllFields<TM, M> | 'AND' | 'OR' | 'NOT', unknown>>;
279
+ type ForcedShapeValue<T> = {
280
+ value: T;
281
+ };
282
+ type UniqueScalarValue<F extends FieldMetaConst> = F['isEnum'] extends true ? string : F['type'] extends 'String' ? string : F['type'] extends 'Int' ? number : F['type'] extends 'BigInt' ? bigint | number | string : F['type'] extends 'Float' ? number : F['type'] extends 'Decimal' ? number | string : F['type'] extends 'Boolean' ? boolean : F['type'] extends 'DateTime' ? Date | string : F['type'] extends 'Bytes' ? Uint8Array | string : string | number | bigint | boolean | Date | Uint8Array;
283
+ type TypedUniqueWhereValue<F extends FieldMetaConst> = true | UniqueScalarValue<F> | ForcedShapeValue<UniqueScalarValue<F>>;
284
+ type SingleFieldUniqueWhere<TM extends TypeMapConst, M extends keyof TM> = Partial<{
285
+ [K in UniqueFields<TM, M>]: TypedUniqueWhereValue<TM[M][K]>;
286
+ }>;
287
+ type ModelUniqueConstraints<TM extends TypeMapConst, M extends keyof TM, UM extends UniqueMapConst> = M extends keyof UM ? UM[M][number] : never;
288
+ type UniqueSelectorNames<TM extends TypeMapConst, M extends keyof TM, UM extends UniqueMapConst> = ModelUniqueConstraints<TM, M, UM> extends infer C ? C extends UniqueConstraintConst ? C['selector'] & string : never : never;
289
+ type UniqueConstraintBySelector<TM extends TypeMapConst, M extends keyof TM, UM extends UniqueMapConst, S extends string> = Extract<ModelUniqueConstraints<TM, M, UM>, {
290
+ readonly selector: S;
291
+ }>;
292
+ type UniqueFieldName<TM extends TypeMapConst, M extends keyof TM, F> = Extract<F, keyof TM[M] & string>;
293
+ type TypedCompoundUniqueSelector<TM extends TypeMapConst, M extends keyof TM, C extends UniqueConstraintConst> = {
294
+ [K in UniqueFieldName<TM, M, C['fields'][number]>]: TypedUniqueWhereValue<TM[M][K]>;
295
+ };
296
+ type TypedCompoundUniqueForcedValue<TM extends TypeMapConst, M extends keyof TM, C extends UniqueConstraintConst> = {
297
+ [K in UniqueFieldName<TM, M, C['fields'][number]>]: UniqueScalarValue<TM[M][K]>;
298
+ };
299
+ type TypedUniqueSelectorValue<TM extends TypeMapConst, M extends keyof TM, C extends UniqueConstraintConst> = C['fields'] extends readonly [infer F] ? TypedUniqueWhereValue<TM[M][UniqueFieldName<TM, M, F>]> : TypedCompoundUniqueSelector<TM, M, C> | ForcedShapeValue<TypedCompoundUniqueForcedValue<TM, M, C>>;
300
+ type GeneratedUniqueWhere<TM extends TypeMapConst, M extends keyof TM, UM extends UniqueMapConst> = Partial<{
301
+ [S in UniqueSelectorNames<TM, M, UM>]: TypedUniqueSelectorValue<TM, M, UniqueConstraintBySelector<TM, M, UM, S>>;
302
+ }>;
303
+ type TypedUniqueWhere<TM extends TypeMapConst, M extends keyof TM, UM extends UniqueMapConst = {}> = SingleFieldUniqueWhere<TM, M> & GeneratedUniqueWhere<TM, M, UM>;
271
304
  type TypedCountSelectInProjection<TM extends TypeMapConst, M extends keyof TM> = {
272
305
  [K in ListRelationFields<TM, M>]?: true | {
273
306
  where?: TypedWhere<TM, RelTarget<TM, M, K>>;
@@ -276,36 +309,36 @@ type TypedCountSelectInProjection<TM extends TypeMapConst, M extends keyof TM> =
276
309
  type TypedProjectionCount<TM extends TypeMapConst, M extends keyof TM> = true | {
277
310
  select: TypedCountSelectInProjection<TM, M>;
278
311
  };
279
- type TypedNestedRelArgs<TM extends TypeMapConst, T, D extends ShapeDepth> = T extends keyof TM ? D extends 0 ? LooseNestedArgs : {
280
- select?: TypedProjection<TM, T, DecDepth<D>>;
281
- include?: TypedInclude<TM, T, DecDepth<D>>;
312
+ type TypedNestedRelArgs<TM extends TypeMapConst, T, D extends ShapeDepth, UM extends UniqueMapConst = {}> = T extends keyof TM ? D extends 0 ? LooseNestedArgs : {
313
+ select?: TypedProjection<TM, T, DecDepth<D>, UM>;
314
+ include?: TypedInclude<TM, T, DecDepth<D>, UM>;
282
315
  where?: TypedWhere<TM, T>;
283
316
  orderBy?: true | Partial<Record<AllFields<TM, T>, unknown>>;
284
- cursor?: Partial<Record<UniqueFields<TM, T>, true>>;
317
+ cursor?: TypedUniqueWhere<TM, T, UM>;
285
318
  take?: number | {
286
319
  max: number;
287
320
  default?: number;
288
321
  };
289
322
  skip?: true;
290
323
  } : LooseNestedArgs;
291
- type TypedProjection<TM extends TypeMapConst, M extends keyof TM, D extends ShapeDepth> = {
292
- [K in AllFields<TM, M>]?: K extends RelationFields<TM, M> ? true | TypedNestedRelArgs<TM, RelTarget<TM, M, K>, D> : true;
324
+ type TypedProjection<TM extends TypeMapConst, M extends keyof TM, D extends ShapeDepth, UM extends UniqueMapConst = {}> = {
325
+ [K in AllFields<TM, M>]?: K extends RelationFields<TM, M> ? true | TypedNestedRelArgs<TM, RelTarget<TM, M, K>, D, UM> : true;
293
326
  } & {
294
327
  _count?: TypedProjectionCount<TM, M>;
295
328
  };
296
- type TypedInclude<TM extends TypeMapConst, M extends keyof TM, D extends ShapeDepth> = {
297
- [K in RelationFields<TM, M>]?: true | TypedNestedRelArgs<TM, RelTarget<TM, M, K>, D>;
329
+ type TypedInclude<TM extends TypeMapConst, M extends keyof TM, D extends ShapeDepth, UM extends UniqueMapConst = {}> = {
330
+ [K in RelationFields<TM, M>]?: true | TypedNestedRelArgs<TM, RelTarget<TM, M, K>, D, UM>;
298
331
  } & {
299
332
  _count?: TypedProjectionCount<TM, M>;
300
333
  };
301
334
  type TypedCountSelect<TM extends TypeMapConst, M extends keyof TM> = Partial<Record<ScalarFields<TM, M> | '_all', true>>;
302
335
  type TypedCountField<TM extends TypeMapConst, M extends keyof TM> = true | Partial<Record<ScalarFields<TM, M> | '_all', true>>;
303
- type TypedShapeProps<TM extends TypeMapConst, M extends keyof TM, D extends ShapeDepth> = {
336
+ type TypedShapeProps<TM extends TypeMapConst, M extends keyof TM, D extends ShapeDepth, UM extends UniqueMapConst = {}> = {
304
337
  where: TypedWhere<TM, M>;
305
- select: TypedProjection<TM, M, D>;
306
- include: TypedInclude<TM, M, D>;
338
+ select: TypedProjection<TM, M, D, UM>;
339
+ include: TypedInclude<TM, M, D, UM>;
307
340
  orderBy: true | Partial<Record<AllFields<TM, M>, unknown>>;
308
- cursor: Partial<Record<UniqueFields<TM, M>, true>>;
341
+ cursor: TypedUniqueWhere<TM, M, UM>;
309
342
  take: number | {
310
343
  max: number;
311
344
  default?: number;
@@ -323,17 +356,23 @@ type TypedShapeProps<TM extends TypeMapConst, M extends keyof TM, D extends Shap
323
356
  create: Partial<Record<WritableFields<TM, M>, unknown>>;
324
357
  update: Partial<Record<WritableFields<TM, M>, unknown>>;
325
358
  };
326
- type BaseOperationShape<TM extends TypeMapConst, M extends keyof TM, O extends OperationName, D extends ShapeDepth> = Partial<Pick<TypedShapeProps<TM, M, D>, Extract<OperationShapeKey<O>, keyof TypedShapeProps<TM, M, D>>>>;
359
+ type BaseOperationShape<TM extends TypeMapConst, M extends keyof TM, O extends OperationName, D extends ShapeDepth, UM extends UniqueMapConst> = Partial<Pick<TypedShapeProps<TM, M, D, UM>, Extract<OperationShapeKey<O>, keyof TypedShapeProps<TM, M, D, UM>>>>;
327
360
  type RequireKeys<T, K extends keyof T> = Omit<T, K> & {
328
361
  [P in K]-?: NonNullable<T[P]>;
329
362
  };
330
- type CountShape<TM extends TypeMapConst, M extends keyof TM, D extends ShapeDepth> = Omit<BaseOperationShape<TM, M, 'count', D>, 'select'> & {
363
+ type CountShape<TM extends TypeMapConst, M extends keyof TM, D extends ShapeDepth, UM extends UniqueMapConst> = Omit<BaseOperationShape<TM, M, 'count', D, UM>, 'select'> & {
331
364
  select?: TypedCountSelect<TM, M>;
332
365
  };
333
- type OperationShape<TM extends TypeMapConst, M extends keyof TM, O extends OperationName, D extends ShapeDepth = 1> = O extends 'findUnique' ? RequireKeys<BaseOperationShape<TM, M, 'findUnique', D>, 'where'> : O extends 'findUniqueOrThrow' ? RequireKeys<BaseOperationShape<TM, M, 'findUniqueOrThrow', D>, 'where'> : O extends 'groupBy' ? RequireKeys<BaseOperationShape<TM, M, 'groupBy', D>, 'by'> : O extends 'count' ? CountShape<TM, M, D> : BaseOperationShape<TM, M, O, D>;
334
- type TypedGuardShape<TM extends TypeMapConst, M extends keyof TM, D extends ShapeDepth = 1> = Partial<TypedShapeProps<TM, M, D>>;
366
+ type UniqueWhereShape<TM extends TypeMapConst, M extends keyof TM, O extends OperationName, D extends ShapeDepth, UM extends UniqueMapConst> = Omit<BaseOperationShape<TM, M, O, D, UM>, 'where'> & {
367
+ where?: TypedUniqueWhere<TM, M, UM>;
368
+ };
369
+ type RequiredUniqueWhereShape<TM extends TypeMapConst, M extends keyof TM, O extends OperationName, D extends ShapeDepth, UM extends UniqueMapConst> = Omit<BaseOperationShape<TM, M, O, D, UM>, 'where'> & {
370
+ where: TypedUniqueWhere<TM, M, UM>;
371
+ };
372
+ type OperationShape<TM extends TypeMapConst, M extends keyof TM, O extends OperationName, D extends ShapeDepth = 1, UM extends UniqueMapConst = {}> = O extends 'findUnique' ? RequiredUniqueWhereShape<TM, M, 'findUnique', D, UM> : O extends 'findUniqueOrThrow' ? RequiredUniqueWhereShape<TM, M, 'findUniqueOrThrow', D, UM> : O extends 'update' ? UniqueWhereShape<TM, M, 'update', D, UM> : O extends 'delete' ? UniqueWhereShape<TM, M, 'delete', D, UM> : O extends 'upsert' ? UniqueWhereShape<TM, M, 'upsert', D, UM> : O extends 'groupBy' ? RequireKeys<BaseOperationShape<TM, M, 'groupBy', D, UM>, 'by'> : O extends 'count' ? CountShape<TM, M, D, UM> : BaseOperationShape<TM, M, O, D, UM>;
373
+ type TypedGuardShape<TM extends TypeMapConst, M extends keyof TM, D extends ShapeDepth = 1, UM extends UniqueMapConst = {}> = Partial<TypedShapeProps<TM, M, D, UM>>;
335
374
  type ShapeFn<S, TCtx> = (ctx: TCtx) => S;
336
375
  type ShapeOrFn<S, TCtx> = S | ShapeFn<S, TCtx>;
337
376
  type ShapeInput<S, TCtx = unknown> = ShapeOrFn<S, TCtx> | Record<string, ShapeOrFn<S, TCtx>>;
338
377
 
339
- export { CallerError, type ComparableFields, type EnumMap, type FieldMeta, type FieldMetaConst, type GuardConfig, type GuardGeneratedConfig, type GuardInput, type GuardLogger, type GuardShape, type GuardShapeOrFn, type GuardedModel, type InputOpts, type InputSchema, type MissingScopeContextMode, type ModelOpts, type MutationMethod, type NestedIncludeArgs, type NestedSelectArgs, type NumericFields, type OperationName, type OperationShape, PolicyError, type QueryMethod, type QuerySchema, type ScopeEntry, type ScopeMap, type ShapeConfig, type ShapeDepth, ShapeError, type ShapeInput, type ShapeOrFn$1 as ShapeOrFn, type TypeMap, type TypeMapConst, type TypedCountSelect, type TypedGuardShape, type TypedInclude, type TypedProjection, type TypedShapeProps, type TypedWhere, type UniqueConstraint, type UniqueMap, type ZodChains, type ZodDefaults, createGuard, force, unsupported };
378
+ export { CallerError, type ComparableFields, type EnumMap, type FieldMeta, type FieldMetaConst, type GuardConfig, type GuardGeneratedConfig, type GuardInput, type GuardLogger, type GuardShape, type GuardShapeOrFn, type GuardedModel, type InputOpts, type InputSchema, type MissingScopeContextMode, type ModelOpts, type MutationMethod, type NestedIncludeArgs, type NestedSelectArgs, type NumericFields, type OperationName, type OperationShape, PolicyError, type QueryMethod, type QuerySchema, type ScopeEntry, type ScopeMap, type ShapeConfig, type ShapeDepth, ShapeError, type ShapeInput, type ShapeOrFn$1 as ShapeOrFn, type TypeMap, type TypeMapConst, type TypedCountSelect, type TypedGuardShape, type TypedInclude, type TypedProjection, type TypedShapeProps, type TypedUniqueWhere, type TypedWhere, type UniqueConstraint, type UniqueConstraintConst, type UniqueMap, type UniqueMapConst, type ZodChains, type ZodDefaults, createGuard, force, unsupported };