prisma-guard 1.23.0 → 1.25.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.
- package/README.md +126 -39
- package/dist/generator/index.js +312 -257
- package/dist/generator/index.js.map +1 -1
- package/dist/runtime/index.cjs +766 -403
- package/dist/runtime/index.cjs.map +1 -1
- package/dist/runtime/index.d.cts +65 -25
- package/dist/runtime/index.d.ts +65 -25
- package/dist/runtime/index.js +766 -403
- package/dist/runtime/index.js.map +1 -1
- package/package.json +1 -1
package/dist/runtime/index.d.cts
CHANGED
|
@@ -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,
|
|
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,
|
|
79
|
+
cursor?: Record<string, unknown>;
|
|
80
80
|
take?: number | {
|
|
81
81
|
max: number;
|
|
82
82
|
default?: number;
|
|
@@ -84,11 +84,11 @@ interface NestedIncludeArgs {
|
|
|
84
84
|
skip?: true;
|
|
85
85
|
}
|
|
86
86
|
interface NestedSelectArgs {
|
|
87
|
-
select?: Record<string, true | NestedSelectArgs>;
|
|
88
|
-
include?: Record<string, true | NestedIncludeArgs>;
|
|
89
87
|
where?: Record<string, unknown>;
|
|
88
|
+
include?: Record<string, true | NestedIncludeArgs>;
|
|
89
|
+
select?: Record<string, true | NestedSelectArgs>;
|
|
90
90
|
orderBy?: Record<string, OrderByFieldConfig>;
|
|
91
|
-
cursor?: Record<string,
|
|
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
|
-
|
|
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';
|
|
@@ -148,9 +151,10 @@ interface GuardShape extends ShapeConfig {
|
|
|
148
151
|
type GuardShapeOrFn = GuardShape | ((ctx: any) => GuardShape);
|
|
149
152
|
type GuardInput = GuardShapeOrFn | Record<string, GuardShapeOrFn>;
|
|
150
153
|
type GuardableMethodName = QueryMethod | MutationMethod;
|
|
151
|
-
type
|
|
154
|
+
type AnyFn = (...args: any[]) => any;
|
|
155
|
+
type DelegateMethod<TDelegate, K extends PropertyKey> = K extends keyof TDelegate ? TDelegate[K] extends AnyFn ? TDelegate[K] : never : never;
|
|
152
156
|
type GuardedModel<TDelegate> = {
|
|
153
|
-
[K in GuardableMethodName as
|
|
157
|
+
[K in GuardableMethodName as DelegateMethod<TDelegate, K> extends never ? never : K]: DelegateMethod<TDelegate, K>;
|
|
154
158
|
};
|
|
155
159
|
|
|
156
160
|
declare function createGuard<TModels extends TypeMap = TypeMap, TRoots extends string = string, TModelExt = unknown>(config: GuardConfig & {
|
|
@@ -226,7 +230,12 @@ interface FieldMetaConst {
|
|
|
226
230
|
readonly isUnique?: boolean;
|
|
227
231
|
readonly isUnsupported?: boolean;
|
|
228
232
|
}
|
|
233
|
+
interface UniqueConstraintConst {
|
|
234
|
+
readonly selector: string;
|
|
235
|
+
readonly fields: readonly string[];
|
|
236
|
+
}
|
|
229
237
|
type TypeMapConst = Record<string, Record<string, FieldMetaConst>>;
|
|
238
|
+
type UniqueMapConst = Record<string, readonly UniqueConstraintConst[]>;
|
|
230
239
|
type ShapeDepth = 0 | 1 | 2 | 3;
|
|
231
240
|
type DecDepth<D extends ShapeDepth> = D extends 3 ? 2 : D extends 2 ? 1 : D extends 1 ? 0 : 0;
|
|
232
241
|
type AllFields<TM extends TypeMapConst, M extends keyof TM> = keyof TM[M] & string;
|
|
@@ -267,6 +276,31 @@ type LooseNestedArgs = {
|
|
|
267
276
|
skip?: true;
|
|
268
277
|
};
|
|
269
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>;
|
|
270
304
|
type TypedCountSelectInProjection<TM extends TypeMapConst, M extends keyof TM> = {
|
|
271
305
|
[K in ListRelationFields<TM, M>]?: true | {
|
|
272
306
|
where?: TypedWhere<TM, RelTarget<TM, M, K>>;
|
|
@@ -275,36 +309,36 @@ type TypedCountSelectInProjection<TM extends TypeMapConst, M extends keyof TM> =
|
|
|
275
309
|
type TypedProjectionCount<TM extends TypeMapConst, M extends keyof TM> = true | {
|
|
276
310
|
select: TypedCountSelectInProjection<TM, M>;
|
|
277
311
|
};
|
|
278
|
-
type TypedNestedRelArgs<TM extends TypeMapConst, T, D extends ShapeDepth> = T extends keyof TM ? D extends 0 ? LooseNestedArgs : {
|
|
279
|
-
select?: TypedProjection<TM, T, DecDepth<D
|
|
280
|
-
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>;
|
|
281
315
|
where?: TypedWhere<TM, T>;
|
|
282
316
|
orderBy?: true | Partial<Record<AllFields<TM, T>, unknown>>;
|
|
283
|
-
cursor?:
|
|
317
|
+
cursor?: TypedUniqueWhere<TM, T, UM>;
|
|
284
318
|
take?: number | {
|
|
285
319
|
max: number;
|
|
286
320
|
default?: number;
|
|
287
321
|
};
|
|
288
322
|
skip?: true;
|
|
289
323
|
} : LooseNestedArgs;
|
|
290
|
-
type TypedProjection<TM extends TypeMapConst, M extends keyof TM, D extends ShapeDepth> = {
|
|
291
|
-
[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;
|
|
292
326
|
} & {
|
|
293
327
|
_count?: TypedProjectionCount<TM, M>;
|
|
294
328
|
};
|
|
295
|
-
type TypedInclude<TM extends TypeMapConst, M extends keyof TM, D extends ShapeDepth> = {
|
|
296
|
-
[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>;
|
|
297
331
|
} & {
|
|
298
332
|
_count?: TypedProjectionCount<TM, M>;
|
|
299
333
|
};
|
|
300
334
|
type TypedCountSelect<TM extends TypeMapConst, M extends keyof TM> = Partial<Record<ScalarFields<TM, M> | '_all', true>>;
|
|
301
335
|
type TypedCountField<TM extends TypeMapConst, M extends keyof TM> = true | Partial<Record<ScalarFields<TM, M> | '_all', true>>;
|
|
302
|
-
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 = {}> = {
|
|
303
337
|
where: TypedWhere<TM, M>;
|
|
304
|
-
select: TypedProjection<TM, M, D>;
|
|
305
|
-
include: TypedInclude<TM, M, D>;
|
|
338
|
+
select: TypedProjection<TM, M, D, UM>;
|
|
339
|
+
include: TypedInclude<TM, M, D, UM>;
|
|
306
340
|
orderBy: true | Partial<Record<AllFields<TM, M>, unknown>>;
|
|
307
|
-
cursor:
|
|
341
|
+
cursor: TypedUniqueWhere<TM, M, UM>;
|
|
308
342
|
take: number | {
|
|
309
343
|
max: number;
|
|
310
344
|
default?: number;
|
|
@@ -322,17 +356,23 @@ type TypedShapeProps<TM extends TypeMapConst, M extends keyof TM, D extends Shap
|
|
|
322
356
|
create: Partial<Record<WritableFields<TM, M>, unknown>>;
|
|
323
357
|
update: Partial<Record<WritableFields<TM, M>, unknown>>;
|
|
324
358
|
};
|
|
325
|
-
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>>>>;
|
|
326
360
|
type RequireKeys<T, K extends keyof T> = Omit<T, K> & {
|
|
327
361
|
[P in K]-?: NonNullable<T[P]>;
|
|
328
362
|
};
|
|
329
|
-
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'> & {
|
|
330
364
|
select?: TypedCountSelect<TM, M>;
|
|
331
365
|
};
|
|
332
|
-
type
|
|
333
|
-
|
|
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>>;
|
|
334
374
|
type ShapeFn<S, TCtx> = (ctx: TCtx) => S;
|
|
335
375
|
type ShapeOrFn<S, TCtx> = S | ShapeFn<S, TCtx>;
|
|
336
376
|
type ShapeInput<S, TCtx = unknown> = ShapeOrFn<S, TCtx> | Record<string, ShapeOrFn<S, TCtx>>;
|
|
337
377
|
|
|
338
|
-
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 };
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -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,
|
|
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,
|
|
79
|
+
cursor?: Record<string, unknown>;
|
|
80
80
|
take?: number | {
|
|
81
81
|
max: number;
|
|
82
82
|
default?: number;
|
|
@@ -84,11 +84,11 @@ interface NestedIncludeArgs {
|
|
|
84
84
|
skip?: true;
|
|
85
85
|
}
|
|
86
86
|
interface NestedSelectArgs {
|
|
87
|
-
select?: Record<string, true | NestedSelectArgs>;
|
|
88
|
-
include?: Record<string, true | NestedIncludeArgs>;
|
|
89
87
|
where?: Record<string, unknown>;
|
|
88
|
+
include?: Record<string, true | NestedIncludeArgs>;
|
|
89
|
+
select?: Record<string, true | NestedSelectArgs>;
|
|
90
90
|
orderBy?: Record<string, OrderByFieldConfig>;
|
|
91
|
-
cursor?: Record<string,
|
|
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
|
-
|
|
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';
|
|
@@ -148,9 +151,10 @@ interface GuardShape extends ShapeConfig {
|
|
|
148
151
|
type GuardShapeOrFn = GuardShape | ((ctx: any) => GuardShape);
|
|
149
152
|
type GuardInput = GuardShapeOrFn | Record<string, GuardShapeOrFn>;
|
|
150
153
|
type GuardableMethodName = QueryMethod | MutationMethod;
|
|
151
|
-
type
|
|
154
|
+
type AnyFn = (...args: any[]) => any;
|
|
155
|
+
type DelegateMethod<TDelegate, K extends PropertyKey> = K extends keyof TDelegate ? TDelegate[K] extends AnyFn ? TDelegate[K] : never : never;
|
|
152
156
|
type GuardedModel<TDelegate> = {
|
|
153
|
-
[K in GuardableMethodName as
|
|
157
|
+
[K in GuardableMethodName as DelegateMethod<TDelegate, K> extends never ? never : K]: DelegateMethod<TDelegate, K>;
|
|
154
158
|
};
|
|
155
159
|
|
|
156
160
|
declare function createGuard<TModels extends TypeMap = TypeMap, TRoots extends string = string, TModelExt = unknown>(config: GuardConfig & {
|
|
@@ -226,7 +230,12 @@ interface FieldMetaConst {
|
|
|
226
230
|
readonly isUnique?: boolean;
|
|
227
231
|
readonly isUnsupported?: boolean;
|
|
228
232
|
}
|
|
233
|
+
interface UniqueConstraintConst {
|
|
234
|
+
readonly selector: string;
|
|
235
|
+
readonly fields: readonly string[];
|
|
236
|
+
}
|
|
229
237
|
type TypeMapConst = Record<string, Record<string, FieldMetaConst>>;
|
|
238
|
+
type UniqueMapConst = Record<string, readonly UniqueConstraintConst[]>;
|
|
230
239
|
type ShapeDepth = 0 | 1 | 2 | 3;
|
|
231
240
|
type DecDepth<D extends ShapeDepth> = D extends 3 ? 2 : D extends 2 ? 1 : D extends 1 ? 0 : 0;
|
|
232
241
|
type AllFields<TM extends TypeMapConst, M extends keyof TM> = keyof TM[M] & string;
|
|
@@ -267,6 +276,31 @@ type LooseNestedArgs = {
|
|
|
267
276
|
skip?: true;
|
|
268
277
|
};
|
|
269
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>;
|
|
270
304
|
type TypedCountSelectInProjection<TM extends TypeMapConst, M extends keyof TM> = {
|
|
271
305
|
[K in ListRelationFields<TM, M>]?: true | {
|
|
272
306
|
where?: TypedWhere<TM, RelTarget<TM, M, K>>;
|
|
@@ -275,36 +309,36 @@ type TypedCountSelectInProjection<TM extends TypeMapConst, M extends keyof TM> =
|
|
|
275
309
|
type TypedProjectionCount<TM extends TypeMapConst, M extends keyof TM> = true | {
|
|
276
310
|
select: TypedCountSelectInProjection<TM, M>;
|
|
277
311
|
};
|
|
278
|
-
type TypedNestedRelArgs<TM extends TypeMapConst, T, D extends ShapeDepth> = T extends keyof TM ? D extends 0 ? LooseNestedArgs : {
|
|
279
|
-
select?: TypedProjection<TM, T, DecDepth<D
|
|
280
|
-
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>;
|
|
281
315
|
where?: TypedWhere<TM, T>;
|
|
282
316
|
orderBy?: true | Partial<Record<AllFields<TM, T>, unknown>>;
|
|
283
|
-
cursor?:
|
|
317
|
+
cursor?: TypedUniqueWhere<TM, T, UM>;
|
|
284
318
|
take?: number | {
|
|
285
319
|
max: number;
|
|
286
320
|
default?: number;
|
|
287
321
|
};
|
|
288
322
|
skip?: true;
|
|
289
323
|
} : LooseNestedArgs;
|
|
290
|
-
type TypedProjection<TM extends TypeMapConst, M extends keyof TM, D extends ShapeDepth> = {
|
|
291
|
-
[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;
|
|
292
326
|
} & {
|
|
293
327
|
_count?: TypedProjectionCount<TM, M>;
|
|
294
328
|
};
|
|
295
|
-
type TypedInclude<TM extends TypeMapConst, M extends keyof TM, D extends ShapeDepth> = {
|
|
296
|
-
[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>;
|
|
297
331
|
} & {
|
|
298
332
|
_count?: TypedProjectionCount<TM, M>;
|
|
299
333
|
};
|
|
300
334
|
type TypedCountSelect<TM extends TypeMapConst, M extends keyof TM> = Partial<Record<ScalarFields<TM, M> | '_all', true>>;
|
|
301
335
|
type TypedCountField<TM extends TypeMapConst, M extends keyof TM> = true | Partial<Record<ScalarFields<TM, M> | '_all', true>>;
|
|
302
|
-
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 = {}> = {
|
|
303
337
|
where: TypedWhere<TM, M>;
|
|
304
|
-
select: TypedProjection<TM, M, D>;
|
|
305
|
-
include: TypedInclude<TM, M, D>;
|
|
338
|
+
select: TypedProjection<TM, M, D, UM>;
|
|
339
|
+
include: TypedInclude<TM, M, D, UM>;
|
|
306
340
|
orderBy: true | Partial<Record<AllFields<TM, M>, unknown>>;
|
|
307
|
-
cursor:
|
|
341
|
+
cursor: TypedUniqueWhere<TM, M, UM>;
|
|
308
342
|
take: number | {
|
|
309
343
|
max: number;
|
|
310
344
|
default?: number;
|
|
@@ -322,17 +356,23 @@ type TypedShapeProps<TM extends TypeMapConst, M extends keyof TM, D extends Shap
|
|
|
322
356
|
create: Partial<Record<WritableFields<TM, M>, unknown>>;
|
|
323
357
|
update: Partial<Record<WritableFields<TM, M>, unknown>>;
|
|
324
358
|
};
|
|
325
|
-
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>>>>;
|
|
326
360
|
type RequireKeys<T, K extends keyof T> = Omit<T, K> & {
|
|
327
361
|
[P in K]-?: NonNullable<T[P]>;
|
|
328
362
|
};
|
|
329
|
-
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'> & {
|
|
330
364
|
select?: TypedCountSelect<TM, M>;
|
|
331
365
|
};
|
|
332
|
-
type
|
|
333
|
-
|
|
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>>;
|
|
334
374
|
type ShapeFn<S, TCtx> = (ctx: TCtx) => S;
|
|
335
375
|
type ShapeOrFn<S, TCtx> = S | ShapeFn<S, TCtx>;
|
|
336
376
|
type ShapeInput<S, TCtx = unknown> = ShapeOrFn<S, TCtx> | Record<string, ShapeOrFn<S, TCtx>>;
|
|
337
377
|
|
|
338
|
-
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 };
|