@zenstackhq/orm 3.10.0 → 3.10.1
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/dist/index.cjs +39 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -2
- package/dist/index.d.mts +9 -4
- package/dist/index.mjs +236 -205
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { a as CoreCreateOperations, c as CoreReadOperations, d as DELEGATE_JOINE
|
|
|
3
3
|
import { AnyNull, AnyNullClass, DbNull, DbNullClass, JsonNull, JsonNullClass } from "./common-types.mjs";
|
|
4
4
|
import { clone, enumerate, invariant, isPlainObject, lowerCaseFirst, upperCaseFirst } from "@zenstackhq/common-helpers";
|
|
5
5
|
import { AliasNode, AndNode, ColumnNode, ColumnUpdateNode, CompiledQuery, DefaultConnectionProvider, DefaultQueryExecutor, DeleteQueryNode, ExpressionWrapper, FromNode, IdentifierNode, InsertQueryNode, Kysely, Log, OperationNodeTransformer, OperationNodeVisitor, PrimitiveValueListNode, RawNode, ReferenceNode, ReturningNode, SelectAllNode, SelectionNode, SingleConnectionProvider, TableNode, Transaction, UpdateQueryNode, ValueListNode, ValueNode, ValuesNode, WhereNode, createQueryId, expressionBuilder, sql } from "kysely";
|
|
6
|
-
import z
|
|
6
|
+
import z, { ZodObject, ZodType, z as z$1 } from "zod";
|
|
7
7
|
import { fromError } from "zod-validation-error/v4";
|
|
8
8
|
import { P, match } from "ts-pattern";
|
|
9
9
|
import { ExpressionUtils } from "@zenstackhq/schema";
|
|
@@ -2399,6 +2399,20 @@ function createQuerySchemaFactory(clientOrSchema, options) {
|
|
|
2399
2399
|
return new ZodSchemaFactory(clientOrSchema, options);
|
|
2400
2400
|
}
|
|
2401
2401
|
/**
|
|
2402
|
+
* Whether two client options produce the same query-args schemas, i.e. a `ZodSchemaFactory`
|
|
2403
|
+
* built for one can serve the other. Only `omit`, `slicing`, `allowQueryTimeOmitOverride` and
|
|
2404
|
+
* the plugins that extend query args or results shape the schemas; dialect, auth, hooks and
|
|
2405
|
+
* validation flags do not.
|
|
2406
|
+
*/
|
|
2407
|
+
function haveSameSchemaInputs(a, b) {
|
|
2408
|
+
if (a === b) return true;
|
|
2409
|
+
if (a.omit !== b.omit || a.slicing !== b.slicing || a.allowQueryTimeOmitOverride !== b.allowQueryTimeOmitOverride) return false;
|
|
2410
|
+
const shaping = (options) => (options.plugins ?? []).filter((plugin) => plugin.queryArgs || plugin.result);
|
|
2411
|
+
const pa = shaping(a);
|
|
2412
|
+
const pb = shaping(b);
|
|
2413
|
+
return pa.length === pb.length && pa.every((plugin, index) => plugin === pb[index]);
|
|
2414
|
+
}
|
|
2415
|
+
/**
|
|
2402
2416
|
* Builds a `DateTime` value schema that accepts a `Date` object or any string
|
|
2403
2417
|
* the JS `Date` constructor parses, and coerces it to a `Date`. ISO datetime,
|
|
2404
2418
|
* ISO date, and time-only strings (e.g. `"09:00:00"` for `@db.Time` fields,
|
|
@@ -2410,7 +2424,7 @@ function createQuerySchemaFactory(clientOrSchema, options) {
|
|
|
2410
2424
|
* @see https://github.com/zenstackhq/zenstack/issues/2631
|
|
2411
2425
|
*/
|
|
2412
2426
|
function coercedDateTimeSchema() {
|
|
2413
|
-
return z.preprocess((val) => {
|
|
2427
|
+
return z$1.preprocess((val) => {
|
|
2414
2428
|
if (typeof val !== "string") return val;
|
|
2415
2429
|
if (/^\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d\d(?::\d\d)?)?$/.test(val)) {
|
|
2416
2430
|
const hasTz = val.endsWith("Z") || /[+-]\d\d(?::\d\d)?$/.test(val);
|
|
@@ -2419,10 +2433,10 @@ function coercedDateTimeSchema() {
|
|
|
2419
2433
|
}
|
|
2420
2434
|
const d = new Date(val);
|
|
2421
2435
|
return isNaN(d.getTime()) ? val : d;
|
|
2422
|
-
}, z.union([
|
|
2423
|
-
z.iso.datetime(),
|
|
2424
|
-
z.iso.date(),
|
|
2425
|
-
z.date()
|
|
2436
|
+
}, z$1.union([
|
|
2437
|
+
z$1.iso.datetime(),
|
|
2438
|
+
z$1.iso.date(),
|
|
2439
|
+
z$1.date()
|
|
2426
2440
|
]));
|
|
2427
2441
|
}
|
|
2428
2442
|
/**
|
|
@@ -2430,7 +2444,7 @@ function coercedDateTimeSchema() {
|
|
|
2430
2444
|
*/
|
|
2431
2445
|
var ZodSchemaFactory = class {
|
|
2432
2446
|
schemaCache = /* @__PURE__ */ new Map();
|
|
2433
|
-
schemaRegistry = z.registry();
|
|
2447
|
+
schemaRegistry = z$1.registry();
|
|
2434
2448
|
allFilterKinds = [...new Set(Object.values(FILTER_PROPERTY_TO_KIND))];
|
|
2435
2449
|
schema;
|
|
2436
2450
|
options;
|
|
@@ -2522,7 +2536,7 @@ var ZodSchemaFactory = class {
|
|
|
2522
2536
|
this.makeGroupBySchema(m);
|
|
2523
2537
|
}
|
|
2524
2538
|
for (const procName of Object.keys(this.schema.procedures ?? {})) if (this.isProcedureAllowed(procName)) this.makeProcedureArgsSchema(procName);
|
|
2525
|
-
return z.toJSONSchema(this.schemaRegistry, { unrepresentable: "any" });
|
|
2539
|
+
return z$1.toJSONSchema(this.schemaRegistry, { unrepresentable: "any" });
|
|
2526
2540
|
}
|
|
2527
2541
|
get cacheStats() {
|
|
2528
2542
|
return {
|
|
@@ -2551,13 +2565,13 @@ var ZodSchemaFactory = class {
|
|
|
2551
2565
|
fields["omit"] = this.makeOmitSchema(model).optional().nullable();
|
|
2552
2566
|
if (!unique) {
|
|
2553
2567
|
fields["skip"] = this.makeSkipSchema().optional();
|
|
2554
|
-
if (findOne) fields["take"] = z.literal(1).optional();
|
|
2568
|
+
if (findOne) fields["take"] = z$1.literal(1).optional();
|
|
2555
2569
|
else fields["take"] = this.makeTakeSchema().optional();
|
|
2556
2570
|
fields["orderBy"] = this.orArray(this.makeOrderBySchema(model, true, false, options), true).optional();
|
|
2557
2571
|
fields["cursor"] = this.makeCursorSchema(model, options).optional();
|
|
2558
2572
|
fields["distinct"] = this.makeDistinctSchema(model).optional();
|
|
2559
2573
|
}
|
|
2560
|
-
const baseSchema = z.strictObject(fields);
|
|
2574
|
+
const baseSchema = z$1.strictObject(fields);
|
|
2561
2575
|
let result = this.mergePluginArgsSchema(baseSchema, operation);
|
|
2562
2576
|
result = this.refineForSelectIncludeMutuallyExclusive(result);
|
|
2563
2577
|
result = this.refineForSelectOmitMutuallyExclusive(result);
|
|
@@ -2567,7 +2581,7 @@ var ZodSchemaFactory = class {
|
|
|
2567
2581
|
return result;
|
|
2568
2582
|
}
|
|
2569
2583
|
makeExistsSchema(model, options) {
|
|
2570
|
-
const baseSchema = z.strictObject({ where: this.makeWhereSchema(model, false, false, false, options).optional() });
|
|
2584
|
+
const baseSchema = z$1.strictObject({ where: this.makeWhereSchema(model, false, false, false, options).optional() });
|
|
2571
2585
|
const result = this.mergePluginArgsSchema(baseSchema, "exists").optional();
|
|
2572
2586
|
this.registerSchema(`${model}ExistsArgs`, result);
|
|
2573
2587
|
return result;
|
|
@@ -2575,19 +2589,19 @@ var ZodSchemaFactory = class {
|
|
|
2575
2589
|
makeScalarSchema(type, attributes) {
|
|
2576
2590
|
if (this.schema.typeDefs && type in this.schema.typeDefs) return this.schema.typeDefs[type].base ? this.makeTypeDefSchema(type, attributes) : this.makeTypeDefSchema(type);
|
|
2577
2591
|
else if (this.schema.enums && type in this.schema.enums) return this.makeEnumSchema(type);
|
|
2578
|
-
else return match(type).with("String", () => this.extraValidationsEnabled ? ZodUtils.addStringValidation(z.string(), attributes) : z.string()).with("Int", () => this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z.number().int(), attributes) : z.number().int()).with("Float", () => this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z.number(), attributes) : z.number()).with("Boolean", () => z.boolean()).with("BigInt", () => z.union([this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z.number().int(), attributes) : z.number().int(), this.extraValidationsEnabled ? ZodUtils.addBigIntValidation(z.bigint(), attributes) : z.bigint()])).with("Decimal", () => {
|
|
2579
|
-
return z.union([
|
|
2580
|
-
this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z.number(), attributes) : z.number(),
|
|
2581
|
-
ZodUtils.addDecimalValidation(z.instanceof(Decimal), attributes, this.extraValidationsEnabled),
|
|
2582
|
-
ZodUtils.addDecimalValidation(z.string(), attributes, this.extraValidationsEnabled)
|
|
2592
|
+
else return match(type).with("String", () => this.extraValidationsEnabled ? ZodUtils.addStringValidation(z$1.string(), attributes) : z$1.string()).with("Int", () => this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z$1.number().int(), attributes) : z$1.number().int()).with("Float", () => this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z$1.number(), attributes) : z$1.number()).with("Boolean", () => z$1.boolean()).with("BigInt", () => z$1.union([this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z$1.number().int(), attributes) : z$1.number().int(), this.extraValidationsEnabled ? ZodUtils.addBigIntValidation(z$1.bigint(), attributes) : z$1.bigint()])).with("Decimal", () => {
|
|
2593
|
+
return z$1.union([
|
|
2594
|
+
this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z$1.number(), attributes) : z$1.number(),
|
|
2595
|
+
ZodUtils.addDecimalValidation(z$1.instanceof(Decimal), attributes, this.extraValidationsEnabled),
|
|
2596
|
+
ZodUtils.addDecimalValidation(z$1.string(), attributes, this.extraValidationsEnabled)
|
|
2583
2597
|
]);
|
|
2584
|
-
}).with("DateTime", () => this.makeDateTimeValueSchema()).with("Bytes", () => z.instanceof(Uint8Array)).with("Json", () => this.makeJsonValueSchema()).otherwise(() => z.unknown());
|
|
2598
|
+
}).with("DateTime", () => this.makeDateTimeValueSchema()).with("Bytes", () => z$1.instanceof(Uint8Array)).with("Json", () => this.makeJsonValueSchema()).otherwise(() => z$1.unknown());
|
|
2585
2599
|
}
|
|
2586
2600
|
isParameterizedComputedField(fieldDef) {
|
|
2587
2601
|
return !!(fieldDef.computed && fieldDef.params);
|
|
2588
2602
|
}
|
|
2589
2603
|
makeFieldArgsSchema(params) {
|
|
2590
|
-
return z.strictObject(Object.fromEntries(Object.entries(params).map(([name, param]) => {
|
|
2604
|
+
return z$1.strictObject(Object.fromEntries(Object.entries(params).map(([name, param]) => {
|
|
2591
2605
|
let paramSchema = this.makeScalarSchema(param.type);
|
|
2592
2606
|
if (param.array) paramSchema = paramSchema.array();
|
|
2593
2607
|
if (param.optional) paramSchema = paramSchema.optional();
|
|
@@ -2595,9 +2609,9 @@ var ZodSchemaFactory = class {
|
|
|
2595
2609
|
})));
|
|
2596
2610
|
}
|
|
2597
2611
|
addComputedArgsToFilter(filterSchema, params) {
|
|
2598
|
-
const objectMembers = (filterSchema instanceof z.ZodUnion ? filterSchema.options : [filterSchema]).filter((m) => m instanceof z.ZodObject);
|
|
2612
|
+
const objectMembers = (filterSchema instanceof z$1.ZodUnion ? filterSchema.options : [filterSchema]).filter((m) => m instanceof z$1.ZodObject);
|
|
2599
2613
|
const components = Object.assign({}, ...objectMembers.map((o) => o.shape));
|
|
2600
|
-
return z.strictObject({
|
|
2614
|
+
return z$1.strictObject({
|
|
2601
2615
|
args: this.makeFieldArgsSchema(params),
|
|
2602
2616
|
...components
|
|
2603
2617
|
});
|
|
@@ -2605,7 +2619,7 @@ var ZodSchemaFactory = class {
|
|
|
2605
2619
|
makeEnumSchema(_enum) {
|
|
2606
2620
|
const enumDef = getEnum(this.schema, _enum);
|
|
2607
2621
|
invariant(enumDef, `Enum "${_enum}" not found in schema`);
|
|
2608
|
-
const schema = z.enum(Object.keys(enumDef.values));
|
|
2622
|
+
const schema = z$1.enum(Object.keys(enumDef.values));
|
|
2609
2623
|
this.registerSchema(_enum, schema);
|
|
2610
2624
|
return schema;
|
|
2611
2625
|
}
|
|
@@ -2623,13 +2637,14 @@ var ZodSchemaFactory = class {
|
|
|
2623
2637
|
const schema = this.makeScalarSchema(typeDef.base, [...typeDef.fields["this"]?.attributes ?? [], ...fieldAttributes ?? []]);
|
|
2624
2638
|
return this.extraValidationsEnabled ? ZodUtils.addCustomValidation(schema, typeDef.attributes) : schema;
|
|
2625
2639
|
}
|
|
2626
|
-
const
|
|
2627
|
-
let fieldSchema = isTypeDef(this.schema, def.type) ? z.lazy(() => this.makeTypeDefSchema(def.type)) : this.makeScalarSchema(def.type);
|
|
2628
|
-
if (def.array) fieldSchema = fieldSchema.array();
|
|
2640
|
+
const objectSchema = (typeDef.strict ? z$1.strictObject : z$1.looseObject)(Object.fromEntries(Object.entries(typeDef.fields).map(([field, def]) => {
|
|
2641
|
+
let fieldSchema = isTypeDef(this.schema, def.type) && !isPrimitiveTypeDef(this.schema, def.type) ? z$1.lazy(() => this.makeTypeDefSchema(def.type)) : this.makeScalarSchema(def.type, this.getItemAttributes(def));
|
|
2642
|
+
if (def.array) fieldSchema = ZodUtils.addListValidation(fieldSchema.array(), def.attributes);
|
|
2629
2643
|
if (def.optional) fieldSchema = fieldSchema.nullish();
|
|
2630
2644
|
return [field, fieldSchema];
|
|
2631
2645
|
})));
|
|
2632
|
-
const
|
|
2646
|
+
const schema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(objectSchema, typeDef.attributes) : objectSchema;
|
|
2647
|
+
const finalSchema = z$1.any().superRefine((value, ctx) => {
|
|
2633
2648
|
const parseResult = schema.safeParse(value);
|
|
2634
2649
|
if (!parseResult.success) parseResult.error.issues.forEach((issue) => ctx.addIssue(issue));
|
|
2635
2650
|
});
|
|
@@ -2645,17 +2660,17 @@ var ZodSchemaFactory = class {
|
|
|
2645
2660
|
if (fieldDef.relation) {
|
|
2646
2661
|
if (withoutRelationFields || !this.shouldIncludeRelations(options)) continue;
|
|
2647
2662
|
const allowedFilterKinds = this.getEffectiveFilterKinds(model, field);
|
|
2648
|
-
if (allowedFilterKinds && !allowedFilterKinds.includes("Relation")) fieldSchema = z.never();
|
|
2663
|
+
if (allowedFilterKinds && !allowedFilterKinds.includes("Relation")) fieldSchema = z$1.never();
|
|
2649
2664
|
else {
|
|
2650
|
-
fieldSchema = z.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts).optional());
|
|
2651
|
-
if (fieldDef.array) fieldSchema = z.strictObject({
|
|
2665
|
+
fieldSchema = z$1.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts).optional());
|
|
2666
|
+
if (fieldDef.array) fieldSchema = z$1.strictObject({
|
|
2652
2667
|
some: fieldSchema.optional(),
|
|
2653
2668
|
every: fieldSchema.optional(),
|
|
2654
2669
|
none: fieldSchema.optional()
|
|
2655
2670
|
});
|
|
2656
2671
|
else {
|
|
2657
2672
|
fieldSchema = this.nullableIf(fieldSchema, !fieldDef.array && !!fieldDef.optional);
|
|
2658
|
-
fieldSchema = z.union([fieldSchema, z.strictObject({
|
|
2673
|
+
fieldSchema = z$1.union([fieldSchema, z$1.strictObject({
|
|
2659
2674
|
is: fieldSchema.optional(),
|
|
2660
2675
|
isNot: fieldSchema.optional()
|
|
2661
2676
|
})]);
|
|
@@ -2675,21 +2690,21 @@ var ZodSchemaFactory = class {
|
|
|
2675
2690
|
}
|
|
2676
2691
|
if (unique) {
|
|
2677
2692
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
2678
|
-
for (const uniqueField of uniqueFields) if ("defs" in uniqueField) fields[uniqueField.name] = z.object(Object.fromEntries(Object.entries(uniqueField.defs).map(([key, def]) => {
|
|
2693
|
+
for (const uniqueField of uniqueFields) if ("defs" in uniqueField) fields[uniqueField.name] = z$1.object(Object.fromEntries(Object.entries(uniqueField.defs).map(([key, def]) => {
|
|
2679
2694
|
invariant(!def.relation, "unique field cannot be a relation");
|
|
2680
2695
|
let fieldSchema;
|
|
2681
2696
|
const enumDef = getEnum(this.schema, def.type);
|
|
2682
2697
|
if (enumDef) if (Object.keys(enumDef.values).length > 0) fieldSchema = this.makeEnumFilterSchema(def.type, !!def.optional, !!def.array, false, void 0);
|
|
2683
|
-
else fieldSchema = z.never();
|
|
2698
|
+
else fieldSchema = z$1.never();
|
|
2684
2699
|
else fieldSchema = this.makePrimitiveFilterSchema(def.type, !!def.optional, false, void 0);
|
|
2685
2700
|
return [key, fieldSchema];
|
|
2686
2701
|
}))).optional();
|
|
2687
2702
|
}
|
|
2688
|
-
fields["$expr"] = z.custom((v) => typeof v === "function", { error: "\"$expr\" must be a function" }).optional();
|
|
2689
|
-
fields["AND"] = this.orArray(z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
|
|
2690
|
-
fields["OR"] = z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)).array().optional();
|
|
2691
|
-
fields["NOT"] = this.orArray(z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
|
|
2692
|
-
const baseWhere = z.strictObject(fields);
|
|
2703
|
+
fields["$expr"] = z$1.custom((v) => typeof v === "function", { error: "\"$expr\" must be a function" }).optional();
|
|
2704
|
+
fields["AND"] = this.orArray(z$1.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
|
|
2705
|
+
fields["OR"] = z$1.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)).array().optional();
|
|
2706
|
+
fields["NOT"] = this.orArray(z$1.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
|
|
2707
|
+
const baseWhere = z$1.strictObject(fields);
|
|
2693
2708
|
let result = baseWhere;
|
|
2694
2709
|
if (unique) {
|
|
2695
2710
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
@@ -2715,26 +2730,26 @@ var ZodSchemaFactory = class {
|
|
|
2715
2730
|
else if (getEnum(this.schema, fieldDef.type)) fieldSchemas[fieldName] = this.makeEnumFilterSchema(fieldDef.type, !!fieldDef.optional, !!fieldDef.array, false, void 0).optional();
|
|
2716
2731
|
else if (fieldDef.array) fieldSchemas[fieldName] = this.makeArrayFilterSchema(fieldDef.type, void 0).optional();
|
|
2717
2732
|
else fieldSchemas[fieldName] = this.makePrimitiveFilterSchema(this.getEffectiveFieldType(fieldDef.type), !!fieldDef.optional, false, void 0).optional();
|
|
2718
|
-
candidates.push(z.strictObject(fieldSchemas));
|
|
2733
|
+
candidates.push(z$1.strictObject(fieldSchemas));
|
|
2719
2734
|
}
|
|
2720
|
-
const recursiveSchema = z.lazy(() => this.makeTypedJsonFilterSchema(type, optional, false, allowedFilterKinds)).optional();
|
|
2721
|
-
if (array) candidates.push(z.strictObject({
|
|
2735
|
+
const recursiveSchema = z$1.lazy(() => this.makeTypedJsonFilterSchema(type, optional, false, allowedFilterKinds)).optional();
|
|
2736
|
+
if (array) candidates.push(z$1.strictObject({
|
|
2722
2737
|
some: recursiveSchema,
|
|
2723
2738
|
every: recursiveSchema,
|
|
2724
2739
|
none: recursiveSchema
|
|
2725
2740
|
}));
|
|
2726
|
-
else candidates.push(z.strictObject({
|
|
2741
|
+
else candidates.push(z$1.strictObject({
|
|
2727
2742
|
is: recursiveSchema,
|
|
2728
2743
|
isNot: recursiveSchema
|
|
2729
2744
|
}));
|
|
2730
2745
|
candidates.push(this.makeJsonFilterSchema(optional, allowedFilterKinds));
|
|
2731
2746
|
if (optional) {
|
|
2732
|
-
candidates.push(z.null());
|
|
2733
|
-
candidates.push(z.instanceof(DbNullClass));
|
|
2734
|
-
candidates.push(z.instanceof(JsonNullClass));
|
|
2735
|
-
candidates.push(z.instanceof(AnyNullClass));
|
|
2747
|
+
candidates.push(z$1.null());
|
|
2748
|
+
candidates.push(z$1.instanceof(DbNullClass));
|
|
2749
|
+
candidates.push(z$1.instanceof(JsonNullClass));
|
|
2750
|
+
candidates.push(z$1.instanceof(AnyNullClass));
|
|
2736
2751
|
}
|
|
2737
|
-
const result = z.union(candidates);
|
|
2752
|
+
const result = z$1.union(candidates);
|
|
2738
2753
|
this.registerSchema(`${type}Filter${this.filterSchemaSuffix({
|
|
2739
2754
|
optional,
|
|
2740
2755
|
array,
|
|
@@ -2743,7 +2758,7 @@ var ZodSchemaFactory = class {
|
|
|
2743
2758
|
return result;
|
|
2744
2759
|
}
|
|
2745
2760
|
makeNullableTypedJsonMutationSchema(fieldSchema) {
|
|
2746
|
-
return z.any().superRefine((value, ctx) => {
|
|
2761
|
+
return z$1.any().superRefine((value, ctx) => {
|
|
2747
2762
|
if (value instanceof DbNullClass || value instanceof JsonNullClass || value === null || value === void 0) return;
|
|
2748
2763
|
const parseResult = fieldSchema.safeParse(value);
|
|
2749
2764
|
if (!parseResult.success) parseResult.error.issues.forEach((issue) => ctx.addIssue(issue));
|
|
@@ -2759,11 +2774,11 @@ var ZodSchemaFactory = class {
|
|
|
2759
2774
|
makeEnumFilterSchema(enumName, optional, array, withAggregations, allowedFilterKinds) {
|
|
2760
2775
|
const enumDef = getEnum(this.schema, enumName);
|
|
2761
2776
|
invariant(enumDef, `Enum "${enumName}" not found in schema`);
|
|
2762
|
-
const baseSchema = z.enum(Object.keys(enumDef.values));
|
|
2777
|
+
const baseSchema = z$1.enum(Object.keys(enumDef.values));
|
|
2763
2778
|
let schema;
|
|
2764
2779
|
if (array) schema = this.internalMakeArrayFilterSchema(baseSchema, allowedFilterKinds);
|
|
2765
2780
|
else {
|
|
2766
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z.lazy(() => this.makeEnumFilterSchema(enumName, optional, array, withAggregations, allowedFilterKinds)), [
|
|
2781
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z$1.lazy(() => this.makeEnumFilterSchema(enumName, optional, array, withAggregations, allowedFilterKinds)), [
|
|
2767
2782
|
"equals",
|
|
2768
2783
|
"in",
|
|
2769
2784
|
"notIn",
|
|
@@ -2797,42 +2812,42 @@ var ZodSchemaFactory = class {
|
|
|
2797
2812
|
has: elementSchema.optional(),
|
|
2798
2813
|
hasEvery: elementSchema.array().optional(),
|
|
2799
2814
|
hasSome: elementSchema.array().optional(),
|
|
2800
|
-
isEmpty: z.boolean().optional()
|
|
2815
|
+
isEmpty: z$1.boolean().optional()
|
|
2801
2816
|
};
|
|
2802
2817
|
const filteredOperators = this.trimFilterOperators(operators, allowedFilterKinds);
|
|
2803
|
-
return z.strictObject(filteredOperators);
|
|
2818
|
+
return z$1.strictObject(filteredOperators);
|
|
2804
2819
|
}
|
|
2805
2820
|
makePrimitiveFilterSchema(type, optional, withAggregations, allowedFilterKinds, withFuzzy = false, withFullText = false) {
|
|
2806
|
-
return match(type).with("String", () => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy, withFullText)).with(P.union("Int", "Float", "Decimal", "BigInt"), (type) => this.makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds)).with("Boolean", () => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)).with("DateTime", () => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)).with("Bytes", () => this.makeBytesFilterSchema(optional, withAggregations, allowedFilterKinds)).with("Json", () => this.makeJsonFilterSchema(optional, allowedFilterKinds)).with("Unsupported", () => z.never()).exhaustive();
|
|
2821
|
+
return match(type).with("String", () => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy, withFullText)).with(P.union("Int", "Float", "Decimal", "BigInt"), (type) => this.makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds)).with("Boolean", () => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)).with("DateTime", () => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)).with("Bytes", () => this.makeBytesFilterSchema(optional, withAggregations, allowedFilterKinds)).with("Json", () => this.makeJsonFilterSchema(optional, allowedFilterKinds)).with("Unsupported", () => z$1.never()).exhaustive();
|
|
2807
2822
|
}
|
|
2808
2823
|
makeJsonValueSchema() {
|
|
2809
|
-
const schema = z.union([
|
|
2810
|
-
z.string(),
|
|
2811
|
-
z.number(),
|
|
2812
|
-
z.boolean(),
|
|
2813
|
-
z.instanceof(JsonNullClass),
|
|
2814
|
-
z.lazy(() => z.union([this.makeJsonValueSchema(), z.null()]).array()),
|
|
2815
|
-
z.record(z.string(), z.lazy(() => z.union([this.makeJsonValueSchema(), z.null()])))
|
|
2824
|
+
const schema = z$1.union([
|
|
2825
|
+
z$1.string(),
|
|
2826
|
+
z$1.number(),
|
|
2827
|
+
z$1.boolean(),
|
|
2828
|
+
z$1.instanceof(JsonNullClass),
|
|
2829
|
+
z$1.lazy(() => z$1.union([this.makeJsonValueSchema(), z$1.null()]).array()),
|
|
2830
|
+
z$1.record(z$1.string(), z$1.lazy(() => z$1.union([this.makeJsonValueSchema(), z$1.null()])))
|
|
2816
2831
|
]);
|
|
2817
2832
|
this.registerSchema("JsonValue", schema);
|
|
2818
2833
|
return schema;
|
|
2819
2834
|
}
|
|
2820
2835
|
makeJsonFilterSchema(optional, allowedFilterKinds) {
|
|
2821
|
-
if (allowedFilterKinds && !allowedFilterKinds.includes("Json")) return z.never();
|
|
2836
|
+
if (allowedFilterKinds && !allowedFilterKinds.includes("Json")) return z$1.never();
|
|
2822
2837
|
const filterMembers = [
|
|
2823
2838
|
this.makeJsonValueSchema(),
|
|
2824
|
-
z.instanceof(DbNullClass),
|
|
2825
|
-
z.instanceof(AnyNullClass)
|
|
2839
|
+
z$1.instanceof(DbNullClass),
|
|
2840
|
+
z$1.instanceof(AnyNullClass)
|
|
2826
2841
|
];
|
|
2827
|
-
if (optional) filterMembers.push(z.null());
|
|
2828
|
-
const filterValueSchema = z.union(filterMembers);
|
|
2829
|
-
const schema = z.strictObject({
|
|
2830
|
-
path: z.string().optional(),
|
|
2842
|
+
if (optional) filterMembers.push(z$1.null());
|
|
2843
|
+
const filterValueSchema = z$1.union(filterMembers);
|
|
2844
|
+
const schema = z$1.strictObject({
|
|
2845
|
+
path: z$1.string().optional(),
|
|
2831
2846
|
equals: filterValueSchema.optional(),
|
|
2832
2847
|
not: filterValueSchema.optional(),
|
|
2833
|
-
string_contains: z.string().optional(),
|
|
2834
|
-
string_starts_with: z.string().optional(),
|
|
2835
|
-
string_ends_with: z.string().optional(),
|
|
2848
|
+
string_contains: z$1.string().optional(),
|
|
2849
|
+
string_starts_with: z$1.string().optional(),
|
|
2850
|
+
string_ends_with: z$1.string().optional(),
|
|
2836
2851
|
mode: this.makeStringModeSchema().optional(),
|
|
2837
2852
|
array_contains: filterValueSchema.optional(),
|
|
2838
2853
|
array_starts_with: filterValueSchema.optional(),
|
|
@@ -2851,7 +2866,7 @@ var ZodSchemaFactory = class {
|
|
|
2851
2866
|
}
|
|
2852
2867
|
makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
2853
2868
|
const filterValueSchema = this.makeDateTimeValueSchema();
|
|
2854
|
-
const schema = this.makeCommonPrimitiveFilterSchema(filterValueSchema, optional, () => z.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)), withAggregations ? [
|
|
2869
|
+
const schema = this.makeCommonPrimitiveFilterSchema(filterValueSchema, optional, () => z$1.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)), withAggregations ? [
|
|
2855
2870
|
"_count",
|
|
2856
2871
|
"_min",
|
|
2857
2872
|
"_max"
|
|
@@ -2864,12 +2879,12 @@ var ZodSchemaFactory = class {
|
|
|
2864
2879
|
return schema;
|
|
2865
2880
|
}
|
|
2866
2881
|
makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
2867
|
-
const components = this.makeCommonPrimitiveFilterComponents(z.boolean(), optional, () => z.lazy(() => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)), ["equals", "not"], withAggregations ? [
|
|
2882
|
+
const components = this.makeCommonPrimitiveFilterComponents(z$1.boolean(), optional, () => z$1.lazy(() => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)), ["equals", "not"], withAggregations ? [
|
|
2868
2883
|
"_count",
|
|
2869
2884
|
"_min",
|
|
2870
2885
|
"_max"
|
|
2871
2886
|
] : void 0, allowedFilterKinds);
|
|
2872
|
-
const schema = this.createUnionFilterSchema(z.boolean(), optional, components, allowedFilterKinds);
|
|
2887
|
+
const schema = this.createUnionFilterSchema(z$1.boolean(), optional, components, allowedFilterKinds);
|
|
2873
2888
|
this.registerSchema(`BooleanFilter${this.filterSchemaSuffix({
|
|
2874
2889
|
optional,
|
|
2875
2890
|
allowedFilterKinds,
|
|
@@ -2878,8 +2893,8 @@ var ZodSchemaFactory = class {
|
|
|
2878
2893
|
return schema;
|
|
2879
2894
|
}
|
|
2880
2895
|
makeBytesFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
2881
|
-
const baseSchema = z.instanceof(Uint8Array);
|
|
2882
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z.instanceof(Uint8Array), [
|
|
2896
|
+
const baseSchema = z$1.instanceof(Uint8Array);
|
|
2897
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z$1.instanceof(Uint8Array), [
|
|
2883
2898
|
"equals",
|
|
2884
2899
|
"in",
|
|
2885
2900
|
"notIn",
|
|
@@ -2927,7 +2942,7 @@ var ZodSchemaFactory = class {
|
|
|
2927
2942
|
return this.createUnionFilterSchema(baseSchema, optional, components, allowedFilterKinds);
|
|
2928
2943
|
}
|
|
2929
2944
|
makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds) {
|
|
2930
|
-
const schema = this.makeCommonPrimitiveFilterSchema(this.makeScalarSchema(type), optional, () => z.lazy(() => this.makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds)), withAggregations ? [
|
|
2945
|
+
const schema = this.makeCommonPrimitiveFilterSchema(this.makeScalarSchema(type), optional, () => z$1.lazy(() => this.makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds)), withAggregations ? [
|
|
2931
2946
|
"_count",
|
|
2932
2947
|
"_avg",
|
|
2933
2948
|
"_sum",
|
|
@@ -2942,15 +2957,15 @@ var ZodSchemaFactory = class {
|
|
|
2942
2957
|
return schema;
|
|
2943
2958
|
}
|
|
2944
2959
|
makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy = false, withFullText = false) {
|
|
2945
|
-
const baseComponents = this.makeCommonPrimitiveFilterComponents(z.string(), optional, () => z.lazy(() => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy, withFullText)), void 0, withAggregations ? [
|
|
2960
|
+
const baseComponents = this.makeCommonPrimitiveFilterComponents(z$1.string(), optional, () => z$1.lazy(() => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy, withFullText)), void 0, withAggregations ? [
|
|
2946
2961
|
"_count",
|
|
2947
2962
|
"_min",
|
|
2948
2963
|
"_max"
|
|
2949
2964
|
] : void 0, allowedFilterKinds);
|
|
2950
2965
|
const stringSpecificOperators = {
|
|
2951
|
-
startsWith: z.string().optional(),
|
|
2952
|
-
endsWith: z.string().optional(),
|
|
2953
|
-
contains: z.string().optional(),
|
|
2966
|
+
startsWith: z$1.string().optional(),
|
|
2967
|
+
endsWith: z$1.string().optional(),
|
|
2968
|
+
contains: z$1.string().optional(),
|
|
2954
2969
|
...withFuzzy && this.providerSupportsFuzzySearch ? { fuzzy: this.makeFuzzyFilterSchema().optional() } : {},
|
|
2955
2970
|
...withFullText && this.providerSupportsFullTextSearch ? { fts: this.makeFullTextFilterSchema().optional() } : {},
|
|
2956
2971
|
...this.providerSupportsCaseSensitivity ? { mode: this.makeStringModeSchema().optional() } : {}
|
|
@@ -2960,7 +2975,7 @@ var ZodSchemaFactory = class {
|
|
|
2960
2975
|
...baseComponents,
|
|
2961
2976
|
...filteredStringOperators
|
|
2962
2977
|
};
|
|
2963
|
-
const schema = this.createUnionFilterSchema(z.string(), optional, allComponents, allowedFilterKinds);
|
|
2978
|
+
const schema = this.createUnionFilterSchema(z$1.string(), optional, allComponents, allowedFilterKinds);
|
|
2964
2979
|
const featureSuffix = `${withFuzzy ? "Fuzzy" : ""}${withFullText ? "FullText" : ""}`;
|
|
2965
2980
|
this.registerSchema(`StringFilter${this.filterSchemaSuffix({
|
|
2966
2981
|
optional,
|
|
@@ -2970,45 +2985,45 @@ var ZodSchemaFactory = class {
|
|
|
2970
2985
|
return schema;
|
|
2971
2986
|
}
|
|
2972
2987
|
makeStringModeSchema() {
|
|
2973
|
-
return z.union([z.literal("default"), z.literal("insensitive")]);
|
|
2988
|
+
return z$1.union([z$1.literal("default"), z$1.literal("insensitive")]);
|
|
2974
2989
|
}
|
|
2975
2990
|
makeFuzzyFilterSchema() {
|
|
2976
|
-
return z.strictObject({
|
|
2977
|
-
search: z.string().min(1),
|
|
2978
|
-
mode: z.union([
|
|
2979
|
-
z.literal("simple"),
|
|
2980
|
-
z.literal("word"),
|
|
2981
|
-
z.literal("strictWord")
|
|
2991
|
+
return z$1.strictObject({
|
|
2992
|
+
search: z$1.string().min(1),
|
|
2993
|
+
mode: z$1.union([
|
|
2994
|
+
z$1.literal("simple"),
|
|
2995
|
+
z$1.literal("word"),
|
|
2996
|
+
z$1.literal("strictWord")
|
|
2982
2997
|
]).default("simple"),
|
|
2983
|
-
threshold: z.number().min(0).max(1).optional(),
|
|
2984
|
-
unaccent: z.boolean().default(false)
|
|
2998
|
+
threshold: z$1.number().min(0).max(1).optional(),
|
|
2999
|
+
unaccent: z$1.boolean().default(false)
|
|
2985
3000
|
});
|
|
2986
3001
|
}
|
|
2987
3002
|
makeFullTextFilterSchema() {
|
|
2988
|
-
return z.strictObject({
|
|
2989
|
-
search: z.string().min(1),
|
|
2990
|
-
config: z.string().min(1).optional()
|
|
3003
|
+
return z$1.strictObject({
|
|
3004
|
+
search: z$1.string().min(1),
|
|
3005
|
+
config: z$1.string().min(1).optional()
|
|
2991
3006
|
});
|
|
2992
3007
|
}
|
|
2993
3008
|
makeSelectSchema(model, options) {
|
|
2994
3009
|
const fields = {};
|
|
2995
3010
|
for (const [field, fieldDef] of this.getModelFields(model)) {
|
|
2996
3011
|
if (this.isParameterizedComputedField(fieldDef)) {
|
|
2997
|
-
fields[field] = z.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional();
|
|
3012
|
+
fields[field] = z$1.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional();
|
|
2998
3013
|
continue;
|
|
2999
3014
|
}
|
|
3000
3015
|
if (fieldDef.relation) {
|
|
3001
3016
|
if (!this.shouldIncludeRelations(options)) continue;
|
|
3002
3017
|
if (this.isModelAllowed(fieldDef.type)) fields[field] = this.makeRelationSelectIncludeSchema(model, field, options).optional();
|
|
3003
|
-
} else if (this.options.allowQueryTimeOmitOverride === false && this.isFieldOmittedByConfig(model, field)) fields[field] = z.literal(false).optional();
|
|
3004
|
-
else fields[field] = z.boolean().optional();
|
|
3018
|
+
} else if (this.options.allowQueryTimeOmitOverride === false && this.isFieldOmittedByConfig(model, field)) fields[field] = z$1.literal(false).optional();
|
|
3019
|
+
else fields[field] = z$1.boolean().optional();
|
|
3005
3020
|
}
|
|
3006
3021
|
if (this.shouldIncludeRelations(options)) {
|
|
3007
3022
|
const _countSchema = this.makeCountSelectionSchema(model, options);
|
|
3008
|
-
if (!(_countSchema instanceof z.ZodNever)) fields["_count"] = _countSchema;
|
|
3023
|
+
if (!(_countSchema instanceof z$1.ZodNever)) fields["_count"] = _countSchema;
|
|
3009
3024
|
}
|
|
3010
3025
|
this.addExtResultFields(model, fields);
|
|
3011
|
-
const result = z.strictObject(fields);
|
|
3026
|
+
const result = z$1.strictObject(fields);
|
|
3012
3027
|
this.registerSchema(`${model}Select`, result);
|
|
3013
3028
|
return result;
|
|
3014
3029
|
}
|
|
@@ -3017,24 +3032,24 @@ var ZodSchemaFactory = class {
|
|
|
3017
3032
|
const toManyRelations = Object.values(modelDef.fields).filter((def) => def.relation && def.array);
|
|
3018
3033
|
if (toManyRelations.length > 0) {
|
|
3019
3034
|
const nextOpts = this.nextOptions(options);
|
|
3020
|
-
const schema = z.union([z.literal(true), z.strictObject({ select: z.strictObject(toManyRelations.reduce((acc, fieldDef) => ({
|
|
3035
|
+
const schema = z$1.union([z$1.literal(true), z$1.strictObject({ select: z$1.strictObject(toManyRelations.reduce((acc, fieldDef) => ({
|
|
3021
3036
|
...acc,
|
|
3022
|
-
[fieldDef.name]: z.union([z.boolean(), z.strictObject({ where: this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts) })]).optional()
|
|
3037
|
+
[fieldDef.name]: z$1.union([z$1.boolean(), z$1.strictObject({ where: this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts) })]).optional()
|
|
3023
3038
|
}), {})) })]).optional();
|
|
3024
3039
|
this.registerSchema(`${model}CountSelection`, schema);
|
|
3025
3040
|
return schema;
|
|
3026
|
-
} else return z.never();
|
|
3041
|
+
} else return z$1.never();
|
|
3027
3042
|
}
|
|
3028
3043
|
makeRelationSelectIncludeSchema(model, field, options) {
|
|
3029
3044
|
const fieldDef = requireField(this.schema, model, field);
|
|
3030
3045
|
const nextOpts = this.nextOptions(options);
|
|
3031
|
-
let objSchema = z.strictObject({
|
|
3032
|
-
...fieldDef.array || fieldDef.optional ? { where: z.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts)).optional() } : {},
|
|
3033
|
-
select: z.lazy(() => this.makeSelectSchema(fieldDef.type, nextOpts)).optional().nullable(),
|
|
3034
|
-
include: z.lazy(() => this.makeIncludeSchema(fieldDef.type, nextOpts)).optional().nullable(),
|
|
3035
|
-
omit: z.lazy(() => this.makeOmitSchema(fieldDef.type)).optional().nullable(),
|
|
3046
|
+
let objSchema = z$1.strictObject({
|
|
3047
|
+
...fieldDef.array || fieldDef.optional ? { where: z$1.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts)).optional() } : {},
|
|
3048
|
+
select: z$1.lazy(() => this.makeSelectSchema(fieldDef.type, nextOpts)).optional().nullable(),
|
|
3049
|
+
include: z$1.lazy(() => this.makeIncludeSchema(fieldDef.type, nextOpts)).optional().nullable(),
|
|
3050
|
+
omit: z$1.lazy(() => this.makeOmitSchema(fieldDef.type)).optional().nullable(),
|
|
3036
3051
|
...fieldDef.array ? {
|
|
3037
|
-
orderBy: z.lazy(() => this.orArray(this.makeOrderBySchema(fieldDef.type, true, false, nextOpts), true)).optional(),
|
|
3052
|
+
orderBy: z$1.lazy(() => this.orArray(this.makeOrderBySchema(fieldDef.type, true, false, nextOpts), true)).optional(),
|
|
3038
3053
|
skip: this.makeSkipSchema().optional(),
|
|
3039
3054
|
take: this.makeTakeSchema().optional(),
|
|
3040
3055
|
cursor: this.makeCursorSchema(fieldDef.type, nextOpts).optional(),
|
|
@@ -3044,7 +3059,7 @@ var ZodSchemaFactory = class {
|
|
|
3044
3059
|
objSchema = this.refineForSelectIncludeMutuallyExclusive(objSchema);
|
|
3045
3060
|
objSchema = this.refineForSelectOmitMutuallyExclusive(objSchema);
|
|
3046
3061
|
objSchema = this.refineForSelectHasTruthyField(objSchema);
|
|
3047
|
-
const result = z.union([z.boolean(), objSchema]);
|
|
3062
|
+
const result = z$1.union([z$1.boolean(), objSchema]);
|
|
3048
3063
|
this.registerSchema(`${model}${upperCaseFirst(field)}RelationInput`, result);
|
|
3049
3064
|
return result;
|
|
3050
3065
|
}
|
|
@@ -3061,11 +3076,11 @@ var ZodSchemaFactory = class {
|
|
|
3061
3076
|
const fields = {};
|
|
3062
3077
|
for (const [field, fieldDef] of this.getModelFields(model)) {
|
|
3063
3078
|
if (this.isParameterizedComputedField(fieldDef)) continue;
|
|
3064
|
-
if (!fieldDef.relation) if (this.options.allowQueryTimeOmitOverride !== false) fields[field] = z.boolean().optional();
|
|
3065
|
-
else fields[field] = z.literal(true).optional();
|
|
3079
|
+
if (!fieldDef.relation) if (this.options.allowQueryTimeOmitOverride !== false) fields[field] = z$1.boolean().optional();
|
|
3080
|
+
else fields[field] = z$1.literal(true).optional();
|
|
3066
3081
|
}
|
|
3067
3082
|
this.addExtResultFields(model, fields);
|
|
3068
|
-
const result = z.strictObject(fields);
|
|
3083
|
+
const result = z$1.strictObject(fields);
|
|
3069
3084
|
this.registerSchema(`${model}OmitInput`, result);
|
|
3070
3085
|
return result;
|
|
3071
3086
|
}
|
|
@@ -3074,7 +3089,7 @@ var ZodSchemaFactory = class {
|
|
|
3074
3089
|
const resultConfig = plugin.result;
|
|
3075
3090
|
if (resultConfig) {
|
|
3076
3091
|
const modelConfig = resultConfig[lowerCaseFirst(model)];
|
|
3077
|
-
if (modelConfig) for (const field of Object.keys(modelConfig)) fields[field] = z.boolean().optional();
|
|
3092
|
+
if (modelConfig) for (const field of Object.keys(modelConfig)) fields[field] = z$1.boolean().optional();
|
|
3078
3093
|
}
|
|
3079
3094
|
}
|
|
3080
3095
|
}
|
|
@@ -3086,35 +3101,35 @@ var ZodSchemaFactory = class {
|
|
|
3086
3101
|
if (fieldDef.relation) {
|
|
3087
3102
|
if (!this.shouldIncludeRelations(options)) continue;
|
|
3088
3103
|
if (this.isModelAllowed(fieldDef.type)) fields[field] = this.makeRelationSelectIncludeSchema(model, field, options).optional();
|
|
3089
|
-
} else if (this.isParameterizedComputedField(fieldDef)) fields[field] = z.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional();
|
|
3104
|
+
} else if (this.isParameterizedComputedField(fieldDef)) fields[field] = z$1.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional();
|
|
3090
3105
|
}
|
|
3091
3106
|
if (this.shouldIncludeRelations(options)) {
|
|
3092
3107
|
const _countSchema = this.makeCountSelectionSchema(model, options);
|
|
3093
|
-
if (!(_countSchema instanceof z.ZodNever)) fields["_count"] = _countSchema;
|
|
3108
|
+
if (!(_countSchema instanceof z$1.ZodNever)) fields["_count"] = _countSchema;
|
|
3094
3109
|
}
|
|
3095
|
-
const result = z.strictObject(fields);
|
|
3110
|
+
const result = z$1.strictObject(fields);
|
|
3096
3111
|
this.registerSchema(`${model}Include`, result);
|
|
3097
3112
|
return result;
|
|
3098
3113
|
}
|
|
3099
3114
|
makeOrderBySchema(model, withRelation, WithAggregation, options) {
|
|
3100
3115
|
const fields = {};
|
|
3101
|
-
const sort = z.union([z.literal("asc"), z.literal("desc")]);
|
|
3116
|
+
const sort = z$1.union([z$1.literal("asc"), z$1.literal("desc")]);
|
|
3102
3117
|
const refineAtMostOneKey = (s) => s.refine((v) => Object.keys(v).length <= 1, { message: "Each orderBy element must have at most one key" });
|
|
3103
3118
|
const nextOpts = this.nextOptions(options);
|
|
3104
3119
|
for (const [field, fieldDef] of this.getModelFields(model)) if (fieldDef.relation) {
|
|
3105
|
-
if (withRelation && this.shouldIncludeRelations(options)) fields[field] = z.lazy(() => {
|
|
3120
|
+
if (withRelation && this.shouldIncludeRelations(options)) fields[field] = z$1.lazy(() => {
|
|
3106
3121
|
let relationOrderBy = this.makeOrderBySchema(fieldDef.type, withRelation, WithAggregation, nextOpts);
|
|
3107
3122
|
if (fieldDef.array) relationOrderBy = refineAtMostOneKey(relationOrderBy.safeExtend({ _count: sort }));
|
|
3108
3123
|
return relationOrderBy;
|
|
3109
3124
|
}).optional();
|
|
3110
|
-
} else if (fieldDef.computed && fieldDef.params) fields[field] = z.strictObject({
|
|
3125
|
+
} else if (fieldDef.computed && fieldDef.params) fields[field] = z$1.strictObject({
|
|
3111
3126
|
args: this.makeFieldArgsSchema(fieldDef.params),
|
|
3112
3127
|
sort,
|
|
3113
|
-
nulls: z.union([z.literal("first"), z.literal("last")]).optional()
|
|
3128
|
+
nulls: z$1.union([z$1.literal("first"), z$1.literal("last")]).optional()
|
|
3114
3129
|
}).optional();
|
|
3115
|
-
else if (fieldDef.optional) fields[field] = z.union([sort, z.strictObject({
|
|
3130
|
+
else if (fieldDef.optional) fields[field] = z$1.union([sort, z$1.strictObject({
|
|
3116
3131
|
sort,
|
|
3117
|
-
nulls: z.union([z.literal("first"), z.literal("last")]).optional()
|
|
3132
|
+
nulls: z$1.union([z$1.literal("first"), z$1.literal("last")]).optional()
|
|
3118
3133
|
})]).optional();
|
|
3119
3134
|
else fields[field] = sort.optional();
|
|
3120
3135
|
if (WithAggregation) for (const agg of [
|
|
@@ -3123,31 +3138,31 @@ var ZodSchemaFactory = class {
|
|
|
3123
3138
|
"_sum",
|
|
3124
3139
|
"_min",
|
|
3125
3140
|
"_max"
|
|
3126
|
-
]) fields[agg] = z.lazy(() => this.makeOrderBySchema(model, true, false, options).optional());
|
|
3141
|
+
]) fields[agg] = z$1.lazy(() => this.makeOrderBySchema(model, true, false, options).optional());
|
|
3127
3142
|
if (this.providerSupportsFuzzySearch) {
|
|
3128
3143
|
const fuzzyFieldNames = this.getModelFields(model).filter(([, def]) => !def.relation && def.type === "String" && def.fuzzy === true).map(([name]) => name);
|
|
3129
|
-
if (fuzzyFieldNames.length > 0) fields["_fuzzyRelevance"] = z.strictObject({
|
|
3130
|
-
fields: z.array(z.enum(fuzzyFieldNames)).min(1),
|
|
3131
|
-
search: z.string(),
|
|
3132
|
-
mode: z.union([
|
|
3133
|
-
z.literal("simple"),
|
|
3134
|
-
z.literal("word"),
|
|
3135
|
-
z.literal("strictWord")
|
|
3144
|
+
if (fuzzyFieldNames.length > 0) fields["_fuzzyRelevance"] = z$1.strictObject({
|
|
3145
|
+
fields: z$1.array(z$1.enum(fuzzyFieldNames)).min(1),
|
|
3146
|
+
search: z$1.string(),
|
|
3147
|
+
mode: z$1.union([
|
|
3148
|
+
z$1.literal("simple"),
|
|
3149
|
+
z$1.literal("word"),
|
|
3150
|
+
z$1.literal("strictWord")
|
|
3136
3151
|
]).default("simple"),
|
|
3137
|
-
unaccent: z.boolean().default(false),
|
|
3152
|
+
unaccent: z$1.boolean().default(false),
|
|
3138
3153
|
sort
|
|
3139
3154
|
}).optional();
|
|
3140
3155
|
}
|
|
3141
3156
|
if (this.providerSupportsFullTextSearch) {
|
|
3142
3157
|
const fullTextFieldNames = this.getModelFields(model).filter(([, def]) => !def.relation && def.type === "String" && def.fullText === true).map(([name]) => name);
|
|
3143
|
-
if (fullTextFieldNames.length > 0) fields["_ftsRelevance"] = z.strictObject({
|
|
3144
|
-
fields: z.array(z.enum(fullTextFieldNames)).min(1),
|
|
3145
|
-
search: z.string().min(1),
|
|
3146
|
-
config: z.string().min(1).optional(),
|
|
3158
|
+
if (fullTextFieldNames.length > 0) fields["_ftsRelevance"] = z$1.strictObject({
|
|
3159
|
+
fields: z$1.array(z$1.enum(fullTextFieldNames)).min(1),
|
|
3160
|
+
search: z$1.string().min(1),
|
|
3161
|
+
config: z$1.string().min(1).optional(),
|
|
3147
3162
|
sort
|
|
3148
3163
|
}).optional();
|
|
3149
3164
|
}
|
|
3150
|
-
const schema = refineAtMostOneKey(z.strictObject(fields));
|
|
3165
|
+
const schema = refineAtMostOneKey(z$1.strictObject(fields));
|
|
3151
3166
|
let schemaId = `${model}OrderBy`;
|
|
3152
3167
|
if (withRelation) schemaId += "WithRelation";
|
|
3153
3168
|
if (WithAggregation) schemaId += "WithAggregation";
|
|
@@ -3157,7 +3172,7 @@ var ZodSchemaFactory = class {
|
|
|
3157
3172
|
}
|
|
3158
3173
|
makeDistinctSchema(model) {
|
|
3159
3174
|
const nonRelationFields = this.getModelFields(model).filter(([, def]) => !def.relation && !this.isParameterizedComputedField(def)).map(([name]) => name);
|
|
3160
|
-
const schema = nonRelationFields.length > 0 ? this.orArray(z.enum(nonRelationFields), true) : z.never();
|
|
3175
|
+
const schema = nonRelationFields.length > 0 ? this.orArray(z$1.enum(nonRelationFields), true) : z$1.never();
|
|
3161
3176
|
this.registerSchema(`${model}DistinctInput`, schema);
|
|
3162
3177
|
return schema;
|
|
3163
3178
|
}
|
|
@@ -3168,7 +3183,7 @@ var ZodSchemaFactory = class {
|
|
|
3168
3183
|
}
|
|
3169
3184
|
makeCreateSchema(model, options) {
|
|
3170
3185
|
const dataSchema = this.makeCreateDataSchema(model, false, [], false, options);
|
|
3171
|
-
const baseSchema = z.strictObject({
|
|
3186
|
+
const baseSchema = z$1.strictObject({
|
|
3172
3187
|
data: dataSchema,
|
|
3173
3188
|
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
3174
3189
|
include: this.makeIncludeSchema(model, options).optional().nullable(),
|
|
@@ -3217,7 +3232,7 @@ var ZodSchemaFactory = class {
|
|
|
3217
3232
|
const oppositeFieldDef = requireField(this.schema, fieldDef.type, oppositeField);
|
|
3218
3233
|
if (oppositeFieldDef.relation?.fields) excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
3219
3234
|
}
|
|
3220
|
-
let fieldSchema = z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "create", nextOpts));
|
|
3235
|
+
let fieldSchema = z$1.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "create", nextOpts));
|
|
3221
3236
|
if (fieldDef.optional || fieldDef.array) fieldSchema = fieldSchema.optional();
|
|
3222
3237
|
else {
|
|
3223
3238
|
let allFksOptional = false;
|
|
@@ -3234,23 +3249,23 @@ var ZodSchemaFactory = class {
|
|
|
3234
3249
|
let fieldSchema = this.makeScalarSchema(fieldDef.type, this.getItemAttributes(fieldDef));
|
|
3235
3250
|
if (fieldDef.array) {
|
|
3236
3251
|
fieldSchema = ZodUtils.addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
3237
|
-
fieldSchema = z.union([fieldSchema, z.strictObject({ set: fieldSchema })]).optional();
|
|
3252
|
+
fieldSchema = z$1.union([fieldSchema, z$1.strictObject({ set: fieldSchema })]).optional();
|
|
3238
3253
|
}
|
|
3239
3254
|
if (fieldDef.optional || fieldHasDefaultValue(fieldDef)) fieldSchema = fieldSchema.optional();
|
|
3240
|
-
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z.union([fieldSchema, z.instanceof(DbNullClass)]);
|
|
3255
|
+
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z$1.union([fieldSchema, z$1.instanceof(DbNullClass)]);
|
|
3241
3256
|
else if (this.isTypeDefType(fieldDef.type)) fieldSchema = this.makeNullableTypedJsonMutationSchema(fieldSchema);
|
|
3242
3257
|
else fieldSchema = fieldSchema.nullable();
|
|
3243
3258
|
uncheckedVariantFields[field] = fieldSchema;
|
|
3244
3259
|
if (!fieldDef.foreignKeyFor) checkedVariantFields[field] = fieldSchema;
|
|
3245
3260
|
}
|
|
3246
3261
|
});
|
|
3247
|
-
const uncheckedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(uncheckedVariantFields), modelDef.attributes) : z.strictObject(uncheckedVariantFields);
|
|
3248
|
-
const checkedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(checkedVariantFields), modelDef.attributes) : z.strictObject(checkedVariantFields);
|
|
3249
|
-
const result = !hasRelation ? this.orArray(uncheckedCreateSchema, canBeArray) : z.union([
|
|
3262
|
+
const uncheckedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z$1.strictObject(uncheckedVariantFields), modelDef.attributes) : z$1.strictObject(uncheckedVariantFields);
|
|
3263
|
+
const checkedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z$1.strictObject(checkedVariantFields), modelDef.attributes) : z$1.strictObject(checkedVariantFields);
|
|
3264
|
+
const result = !hasRelation ? this.orArray(uncheckedCreateSchema, canBeArray) : z$1.union([
|
|
3250
3265
|
uncheckedCreateSchema,
|
|
3251
3266
|
checkedCreateSchema,
|
|
3252
|
-
...canBeArray ? [z.array(uncheckedCreateSchema)] : [],
|
|
3253
|
-
...canBeArray ? [z.array(checkedCreateSchema)] : []
|
|
3267
|
+
...canBeArray ? [z$1.array(uncheckedCreateSchema)] : [],
|
|
3268
|
+
...canBeArray ? [z$1.array(checkedCreateSchema)] : []
|
|
3254
3269
|
]);
|
|
3255
3270
|
const idParts = [`${model}CreateData`];
|
|
3256
3271
|
if (canBeArray) idParts.push("Array");
|
|
@@ -3275,17 +3290,17 @@ var ZodSchemaFactory = class {
|
|
|
3275
3290
|
fields["disconnect"] = this.makeDisconnectDataSchema(fieldType, array, options).optional();
|
|
3276
3291
|
fields["delete"] = this.makeDeleteRelationDataSchema(fieldType, array, true, options).optional();
|
|
3277
3292
|
}
|
|
3278
|
-
fields["update"] = array ? this.orArray(z.strictObject({
|
|
3293
|
+
fields["update"] = array ? this.orArray(z$1.strictObject({
|
|
3279
3294
|
where: this.makeWhereSchema(fieldType, true, false, false, options),
|
|
3280
3295
|
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
3281
|
-
}), true).optional() : z.union([z.strictObject({
|
|
3296
|
+
}), true).optional() : z$1.union([z$1.strictObject({
|
|
3282
3297
|
where: this.makeWhereSchema(fieldType, false, false, false, options).optional(),
|
|
3283
3298
|
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
3284
3299
|
}), this.makeUpdateDataSchema(fieldType, withoutFields, false, options)]).optional();
|
|
3285
3300
|
if (canCreateModel) {
|
|
3286
3301
|
let upsertWhere = this.makeWhereSchema(fieldType, true, false, false, options);
|
|
3287
3302
|
if (!fieldDef.array) upsertWhere = upsertWhere.optional();
|
|
3288
|
-
fields["upsert"] = this.orArray(z.strictObject({
|
|
3303
|
+
fields["upsert"] = this.orArray(z$1.strictObject({
|
|
3289
3304
|
where: upsertWhere,
|
|
3290
3305
|
create: this.makeCreateDataSchema(fieldType, false, withoutFields, false, options),
|
|
3291
3306
|
update: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
@@ -3293,14 +3308,14 @@ var ZodSchemaFactory = class {
|
|
|
3293
3308
|
}
|
|
3294
3309
|
if (array) {
|
|
3295
3310
|
fields["set"] = this.makeSetDataSchema(fieldType, true, options).optional();
|
|
3296
|
-
fields["updateMany"] = this.orArray(z.strictObject({
|
|
3311
|
+
fields["updateMany"] = this.orArray(z$1.strictObject({
|
|
3297
3312
|
where: this.makeWhereSchema(fieldType, false, true, false, options),
|
|
3298
3313
|
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
3299
3314
|
}), true).optional();
|
|
3300
3315
|
fields["deleteMany"] = this.makeDeleteRelationDataSchema(fieldType, true, false, options).optional();
|
|
3301
3316
|
}
|
|
3302
3317
|
}
|
|
3303
|
-
return z.strictObject(fields);
|
|
3318
|
+
return z$1.strictObject(fields);
|
|
3304
3319
|
}
|
|
3305
3320
|
makeSetDataSchema(model, canBeArray, options) {
|
|
3306
3321
|
return this.orArray(this.makeWhereSchema(model, true, false, false, options), canBeArray);
|
|
@@ -3310,23 +3325,23 @@ var ZodSchemaFactory = class {
|
|
|
3310
3325
|
}
|
|
3311
3326
|
makeDisconnectDataSchema(model, canBeArray, options) {
|
|
3312
3327
|
if (canBeArray) return this.orArray(this.makeWhereSchema(model, true, false, false, options), canBeArray);
|
|
3313
|
-
else return z.union([z.boolean(), this.makeWhereSchema(model, false, false, false, options)]);
|
|
3328
|
+
else return z$1.union([z$1.boolean(), this.makeWhereSchema(model, false, false, false, options)]);
|
|
3314
3329
|
}
|
|
3315
3330
|
makeDeleteRelationDataSchema(model, toManyRelation, uniqueFilter, options) {
|
|
3316
|
-
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter, false, false, options), true) : z.union([z.boolean(), this.makeWhereSchema(model, uniqueFilter, false, false, options)]);
|
|
3331
|
+
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter, false, false, options), true) : z$1.union([z$1.boolean(), this.makeWhereSchema(model, uniqueFilter, false, false, options)]);
|
|
3317
3332
|
}
|
|
3318
3333
|
makeConnectOrCreateDataSchema(model, canBeArray, withoutFields, options) {
|
|
3319
3334
|
const whereSchema = this.makeWhereSchema(model, true, false, false, options);
|
|
3320
3335
|
const createSchema = this.makeCreateDataSchema(model, false, withoutFields, false, options);
|
|
3321
|
-
return this.orArray(z.strictObject({
|
|
3336
|
+
return this.orArray(z$1.strictObject({
|
|
3322
3337
|
where: whereSchema,
|
|
3323
3338
|
create: createSchema
|
|
3324
3339
|
}), canBeArray);
|
|
3325
3340
|
}
|
|
3326
3341
|
makeCreateManyPayloadSchema(model, withoutFields, options) {
|
|
3327
|
-
const schema = z.strictObject({
|
|
3342
|
+
const schema = z$1.strictObject({
|
|
3328
3343
|
data: this.makeCreateDataSchema(model, true, withoutFields, true, options),
|
|
3329
|
-
skipDuplicates: z.boolean().optional()
|
|
3344
|
+
skipDuplicates: z$1.boolean().optional()
|
|
3330
3345
|
});
|
|
3331
3346
|
const idParts = [`${model}CreateManyPayload`];
|
|
3332
3347
|
if (withoutFields.length) idParts.push(`Without${withoutFields.slice().sort().join("")}`);
|
|
@@ -3334,7 +3349,7 @@ var ZodSchemaFactory = class {
|
|
|
3334
3349
|
return schema;
|
|
3335
3350
|
}
|
|
3336
3351
|
makeUpdateSchema(model, options) {
|
|
3337
|
-
const baseSchema = z.strictObject({
|
|
3352
|
+
const baseSchema = z$1.strictObject({
|
|
3338
3353
|
where: this.makeWhereSchema(model, true, false, false, options),
|
|
3339
3354
|
data: this.makeUpdateDataSchema(model, [], false, options),
|
|
3340
3355
|
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
@@ -3349,10 +3364,10 @@ var ZodSchemaFactory = class {
|
|
|
3349
3364
|
return schema;
|
|
3350
3365
|
}
|
|
3351
3366
|
makeUpdateManySchema(model, options) {
|
|
3352
|
-
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3367
|
+
const result = this.mergePluginArgsSchema(z$1.strictObject({
|
|
3353
3368
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3354
3369
|
data: this.makeUpdateDataSchema(model, [], true, options),
|
|
3355
|
-
limit: z.number().int().nonnegative().optional()
|
|
3370
|
+
limit: z$1.number().int().nonnegative().optional()
|
|
3356
3371
|
}), "updateMany");
|
|
3357
3372
|
this.registerSchema(`${model}UpdateManyArgs`, result);
|
|
3358
3373
|
return result;
|
|
@@ -3368,7 +3383,7 @@ var ZodSchemaFactory = class {
|
|
|
3368
3383
|
return schema;
|
|
3369
3384
|
}
|
|
3370
3385
|
makeUpsertSchema(model, options) {
|
|
3371
|
-
const baseSchema = z.strictObject({
|
|
3386
|
+
const baseSchema = z$1.strictObject({
|
|
3372
3387
|
where: this.makeWhereSchema(model, true, false, false, options),
|
|
3373
3388
|
create: this.makeCreateDataSchema(model, false, [], false, options),
|
|
3374
3389
|
update: this.makeUpdateDataSchema(model, [], false, options),
|
|
@@ -3404,27 +3419,27 @@ var ZodSchemaFactory = class {
|
|
|
3404
3419
|
const oppositeFieldDef = requireField(this.schema, fieldDef.type, oppositeField);
|
|
3405
3420
|
if (oppositeFieldDef.relation?.fields) excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
3406
3421
|
}
|
|
3407
|
-
let fieldSchema = z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "update", nextOpts)).optional();
|
|
3422
|
+
let fieldSchema = z$1.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "update", nextOpts)).optional();
|
|
3408
3423
|
if (fieldDef.optional && !fieldDef.array) fieldSchema = fieldSchema.nullable();
|
|
3409
3424
|
checkedVariantFields[field] = fieldSchema;
|
|
3410
3425
|
if (fieldDef.array || !fieldDef.relation.references) uncheckedVariantFields[field] = fieldSchema;
|
|
3411
3426
|
} else {
|
|
3412
3427
|
let fieldSchema = this.makeScalarSchema(fieldDef.type, this.getItemAttributes(fieldDef));
|
|
3413
|
-
if (this.isNumericField(fieldDef)) fieldSchema = z.union([fieldSchema, z.object({
|
|
3414
|
-
set: this.nullableIf(z.number().optional(), !!fieldDef.optional).optional(),
|
|
3415
|
-
increment: z.number().optional(),
|
|
3416
|
-
decrement: z.number().optional(),
|
|
3417
|
-
multiply: z.number().optional(),
|
|
3418
|
-
divide: z.number().optional()
|
|
3428
|
+
if (this.isNumericField(fieldDef)) fieldSchema = z$1.union([fieldSchema, z$1.object({
|
|
3429
|
+
set: this.nullableIf(z$1.number().optional(), !!fieldDef.optional).optional(),
|
|
3430
|
+
increment: z$1.number().optional(),
|
|
3431
|
+
decrement: z$1.number().optional(),
|
|
3432
|
+
multiply: z$1.number().optional(),
|
|
3433
|
+
divide: z$1.number().optional()
|
|
3419
3434
|
}).refine((v) => Object.keys(v).length === 1, "Only one of \"set\", \"increment\", \"decrement\", \"multiply\", or \"divide\" can be provided")]);
|
|
3420
3435
|
if (fieldDef.array) {
|
|
3421
3436
|
const arraySchema = ZodUtils.addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
3422
|
-
fieldSchema = z.union([arraySchema, z.object({
|
|
3437
|
+
fieldSchema = z$1.union([arraySchema, z$1.object({
|
|
3423
3438
|
set: arraySchema.optional(),
|
|
3424
|
-
push: z.union([fieldSchema, fieldSchema.array()]).optional()
|
|
3439
|
+
push: z$1.union([fieldSchema, fieldSchema.array()]).optional()
|
|
3425
3440
|
}).refine((v) => Object.keys(v).length === 1, "Only one of \"set\", \"push\" can be provided")]);
|
|
3426
3441
|
}
|
|
3427
|
-
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z.union([fieldSchema, z.instanceof(DbNullClass)]);
|
|
3442
|
+
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z$1.union([fieldSchema, z$1.instanceof(DbNullClass)]);
|
|
3428
3443
|
else if (this.isTypeDefType(fieldDef.type)) fieldSchema = this.makeNullableTypedJsonMutationSchema(fieldSchema);
|
|
3429
3444
|
else fieldSchema = fieldSchema.nullable();
|
|
3430
3445
|
fieldSchema = fieldSchema.optional();
|
|
@@ -3432,9 +3447,9 @@ var ZodSchemaFactory = class {
|
|
|
3432
3447
|
if (!fieldDef.foreignKeyFor) checkedVariantFields[field] = fieldSchema;
|
|
3433
3448
|
}
|
|
3434
3449
|
});
|
|
3435
|
-
const uncheckedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(uncheckedVariantFields), modelDef.attributes) : z.strictObject(uncheckedVariantFields);
|
|
3436
|
-
const checkedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(checkedVariantFields), modelDef.attributes) : z.strictObject(checkedVariantFields);
|
|
3437
|
-
const result = !hasRelation ? uncheckedUpdateSchema : z.union([uncheckedUpdateSchema, checkedUpdateSchema]);
|
|
3450
|
+
const uncheckedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z$1.strictObject(uncheckedVariantFields), modelDef.attributes) : z$1.strictObject(uncheckedVariantFields);
|
|
3451
|
+
const checkedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z$1.strictObject(checkedVariantFields), modelDef.attributes) : z$1.strictObject(checkedVariantFields);
|
|
3452
|
+
const result = !hasRelation ? uncheckedUpdateSchema : z$1.union([uncheckedUpdateSchema, checkedUpdateSchema]);
|
|
3438
3453
|
const idParts = [`${model}UpdateData`];
|
|
3439
3454
|
if (withoutRelationFields) idParts.push("WithoutRelation");
|
|
3440
3455
|
if (withoutFields.length) idParts.push(`Without${withoutFields.slice().sort().join("")}`);
|
|
@@ -3442,7 +3457,7 @@ var ZodSchemaFactory = class {
|
|
|
3442
3457
|
return result;
|
|
3443
3458
|
}
|
|
3444
3459
|
makeDeleteSchema(model, options) {
|
|
3445
|
-
const baseSchema = z.strictObject({
|
|
3460
|
+
const baseSchema = z$1.strictObject({
|
|
3446
3461
|
where: this.makeWhereSchema(model, true, false, false, options),
|
|
3447
3462
|
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
3448
3463
|
include: this.makeIncludeSchema(model, options).optional().nullable(),
|
|
@@ -3456,15 +3471,15 @@ var ZodSchemaFactory = class {
|
|
|
3456
3471
|
return schema;
|
|
3457
3472
|
}
|
|
3458
3473
|
makeDeleteManySchema(model, options) {
|
|
3459
|
-
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3474
|
+
const result = this.mergePluginArgsSchema(z$1.strictObject({
|
|
3460
3475
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3461
|
-
limit: z.number().int().nonnegative().optional()
|
|
3476
|
+
limit: z$1.number().int().nonnegative().optional()
|
|
3462
3477
|
}), "deleteMany").optional();
|
|
3463
3478
|
this.registerSchema(`${model}DeleteManyArgs`, result);
|
|
3464
3479
|
return result;
|
|
3465
3480
|
}
|
|
3466
3481
|
makeCountSchema(model, options) {
|
|
3467
|
-
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3482
|
+
const result = this.mergePluginArgsSchema(z$1.strictObject({
|
|
3468
3483
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3469
3484
|
skip: this.makeSkipSchema().optional(),
|
|
3470
3485
|
take: this.makeTakeSchema().optional(),
|
|
@@ -3475,10 +3490,10 @@ var ZodSchemaFactory = class {
|
|
|
3475
3490
|
return result;
|
|
3476
3491
|
}
|
|
3477
3492
|
makeCountAggregateInputSchema(model) {
|
|
3478
|
-
const schema = z.union([z.literal(true), z.strictObject({
|
|
3479
|
-
_all: z.literal(true).optional(),
|
|
3493
|
+
const schema = z$1.union([z$1.literal(true), z$1.strictObject({
|
|
3494
|
+
_all: z$1.literal(true).optional(),
|
|
3480
3495
|
...this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
|
|
3481
|
-
acc[field] = this.isParameterizedComputedField(fieldDef) ? z.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional() : z.literal(true).optional();
|
|
3496
|
+
acc[field] = this.isParameterizedComputedField(fieldDef) ? z$1.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional() : z$1.literal(true).optional();
|
|
3482
3497
|
return acc;
|
|
3483
3498
|
}, {})
|
|
3484
3499
|
})]);
|
|
@@ -3486,7 +3501,7 @@ var ZodSchemaFactory = class {
|
|
|
3486
3501
|
return schema;
|
|
3487
3502
|
}
|
|
3488
3503
|
makeAggregateSchema(model, options) {
|
|
3489
|
-
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3504
|
+
const result = this.mergePluginArgsSchema(z$1.strictObject({
|
|
3490
3505
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3491
3506
|
skip: this.makeSkipSchema().optional(),
|
|
3492
3507
|
take: this.makeTakeSchema().optional(),
|
|
@@ -3501,16 +3516,16 @@ var ZodSchemaFactory = class {
|
|
|
3501
3516
|
return result;
|
|
3502
3517
|
}
|
|
3503
3518
|
makeSumAvgInputSchema(model) {
|
|
3504
|
-
const schema = z.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
|
|
3505
|
-
if (this.isNumericField(fieldDef)) acc[field] = this.isParameterizedComputedField(fieldDef) ? z.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional() : z.literal(true).optional();
|
|
3519
|
+
const schema = z$1.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
|
|
3520
|
+
if (this.isNumericField(fieldDef)) acc[field] = this.isParameterizedComputedField(fieldDef) ? z$1.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional() : z$1.literal(true).optional();
|
|
3506
3521
|
return acc;
|
|
3507
3522
|
}, {}));
|
|
3508
3523
|
this.registerSchema(`${model}SumAvgAggregateInput`, schema);
|
|
3509
3524
|
return schema;
|
|
3510
3525
|
}
|
|
3511
3526
|
makeMinMaxInputSchema(model) {
|
|
3512
|
-
const schema = z.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
|
|
3513
|
-
if (!fieldDef.relation && !fieldDef.array) acc[field] = this.isParameterizedComputedField(fieldDef) ? z.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional() : z.literal(true).optional();
|
|
3527
|
+
const schema = z$1.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
|
|
3528
|
+
if (!fieldDef.relation && !fieldDef.array) acc[field] = this.isParameterizedComputedField(fieldDef) ? z$1.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional() : z$1.literal(true).optional();
|
|
3514
3529
|
return acc;
|
|
3515
3530
|
}, {}));
|
|
3516
3531
|
this.registerSchema(`${model}MinMaxAggregateInput`, schema);
|
|
@@ -3519,14 +3534,14 @@ var ZodSchemaFactory = class {
|
|
|
3519
3534
|
makeGroupBySchema(model, options) {
|
|
3520
3535
|
const nonRelationFields = this.getModelFields(model).filter(([, def]) => !def.relation && !this.isParameterizedComputedField(def)).map(([name]) => name);
|
|
3521
3536
|
const byMembers = [];
|
|
3522
|
-
if (nonRelationFields.length > 0) byMembers.push(z.enum(nonRelationFields));
|
|
3523
|
-
for (const [field, fieldDef] of this.getModelFields(model)) if (this.isParameterizedComputedField(fieldDef)) byMembers.push(z.strictObject({
|
|
3524
|
-
field: z.literal(field),
|
|
3537
|
+
if (nonRelationFields.length > 0) byMembers.push(z$1.enum(nonRelationFields));
|
|
3538
|
+
for (const [field, fieldDef] of this.getModelFields(model)) if (this.isParameterizedComputedField(fieldDef)) byMembers.push(z$1.strictObject({
|
|
3539
|
+
field: z$1.literal(field),
|
|
3525
3540
|
args: this.makeFieldArgsSchema(fieldDef.params)
|
|
3526
3541
|
}));
|
|
3527
|
-
const byElement = byMembers.length === 0 ? void 0 : byMembers.length === 1 ? byMembers[0] : z.union(byMembers);
|
|
3528
|
-
const bySchema = byElement ? this.orArray(byElement, true) : z.never();
|
|
3529
|
-
const baseSchema = z.strictObject({
|
|
3542
|
+
const byElement = byMembers.length === 0 ? void 0 : byMembers.length === 1 ? byMembers[0] : z$1.union(byMembers);
|
|
3543
|
+
const bySchema = byElement ? this.orArray(byElement, true) : z$1.never();
|
|
3544
|
+
const baseSchema = z$1.strictObject({
|
|
3530
3545
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3531
3546
|
orderBy: this.orArray(this.makeOrderBySchema(model, false, true, options), true).optional(),
|
|
3532
3547
|
by: bySchema,
|
|
@@ -3578,7 +3593,7 @@ var ZodSchemaFactory = class {
|
|
|
3578
3593
|
if (!procDef) throw createInternalError(`Procedure not found: ${procName}`);
|
|
3579
3594
|
const shape = {};
|
|
3580
3595
|
for (const param of Object.values(procDef.params ?? {})) shape[param.name] = this.makeProcedureParamSchema(param);
|
|
3581
|
-
const schema = z.object(shape);
|
|
3596
|
+
const schema = z$1.object(shape);
|
|
3582
3597
|
this.registerSchema(`${procName}ProcArgs`, schema);
|
|
3583
3598
|
return schema;
|
|
3584
3599
|
}
|
|
@@ -3586,10 +3601,10 @@ var ZodSchemaFactory = class {
|
|
|
3586
3601
|
let schema;
|
|
3587
3602
|
if (isTypeDef(this.schema, param.type)) schema = this.makeTypeDefSchema(param.type);
|
|
3588
3603
|
else if (isEnum(this.schema, param.type)) schema = this.makeEnumSchema(param.type);
|
|
3589
|
-
else if (param.type in (this.schema.models ?? {})) schema = z.record(z.string(), z.unknown());
|
|
3604
|
+
else if (param.type in (this.schema.models ?? {})) schema = z$1.record(z$1.string(), z$1.unknown());
|
|
3590
3605
|
else {
|
|
3591
3606
|
schema = this.makeScalarSchema(param.type);
|
|
3592
|
-
if (schema instanceof z.ZodUnknown) throw createInternalError(`Unsupported procedure parameter type: ${param.type}`);
|
|
3607
|
+
if (schema instanceof z$1.ZodUnknown) throw createInternalError(`Unsupported procedure parameter type: ${param.type}`);
|
|
3593
3608
|
}
|
|
3594
3609
|
if (param.array) schema = schema.array();
|
|
3595
3610
|
if (param.optional) schema = schema.optional();
|
|
@@ -3625,10 +3640,10 @@ var ZodSchemaFactory = class {
|
|
|
3625
3640
|
return result;
|
|
3626
3641
|
}
|
|
3627
3642
|
makeSkipSchema() {
|
|
3628
|
-
return z.number().int().nonnegative();
|
|
3643
|
+
return z$1.number().int().nonnegative();
|
|
3629
3644
|
}
|
|
3630
3645
|
makeTakeSchema() {
|
|
3631
|
-
return z.number().int();
|
|
3646
|
+
return z$1.number().int();
|
|
3632
3647
|
}
|
|
3633
3648
|
refineForSelectIncludeMutuallyExclusive(schema) {
|
|
3634
3649
|
return schema.refine((value) => !(value["select"] && value["include"]), "\"select\" and \"include\" cannot be used together");
|
|
@@ -3647,7 +3662,7 @@ var ZodSchemaFactory = class {
|
|
|
3647
3662
|
return nullable ? schema.nullable() : schema;
|
|
3648
3663
|
}
|
|
3649
3664
|
orArray(schema, canBeArray) {
|
|
3650
|
-
return canBeArray ? z.union([schema, z.array(schema)]) : schema;
|
|
3665
|
+
return canBeArray ? z$1.union([schema, z$1.array(schema)]) : schema;
|
|
3651
3666
|
}
|
|
3652
3667
|
isNumericField(fieldDef) {
|
|
3653
3668
|
return NUMERIC_FIELD_TYPES.includes(this.getEffectiveFieldType(fieldDef.type)) && !fieldDef.array;
|
|
@@ -3709,10 +3724,10 @@ var ZodSchemaFactory = class {
|
|
|
3709
3724
|
createUnionFilterSchema(valueSchema, optional, components, allowedFilterKinds) {
|
|
3710
3725
|
if (Object.keys(components).length === 0) {
|
|
3711
3726
|
if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return this.nullableIf(valueSchema, optional);
|
|
3712
|
-
return z.never();
|
|
3727
|
+
return z$1.never();
|
|
3713
3728
|
}
|
|
3714
|
-
if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return z.union([this.nullableIf(valueSchema, optional), z.strictObject(components)]);
|
|
3715
|
-
else return z.strictObject(components);
|
|
3729
|
+
if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return z$1.union([this.nullableIf(valueSchema, optional), z$1.strictObject(components)]);
|
|
3730
|
+
else return z$1.strictObject(components);
|
|
3716
3731
|
}
|
|
3717
3732
|
canCreateModel(model) {
|
|
3718
3733
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -4180,7 +4195,7 @@ var InputValidator = class {
|
|
|
4180
4195
|
enabled;
|
|
4181
4196
|
constructor(client, options) {
|
|
4182
4197
|
this.client = client;
|
|
4183
|
-
this.zodFactory = new ZodSchemaFactory(client);
|
|
4198
|
+
this.zodFactory = options?.zodFactory ?? new ZodSchemaFactory(client);
|
|
4184
4199
|
this.enabled = options?.enabled !== false;
|
|
4185
4200
|
}
|
|
4186
4201
|
validateFindArgs(model, args, operation) {
|
|
@@ -4333,6 +4348,7 @@ var BaseOperationHandler = class {
|
|
|
4333
4348
|
try {
|
|
4334
4349
|
result = (await kysely.getExecutor().executeQuery(compiled)).rows;
|
|
4335
4350
|
} catch (err) {
|
|
4351
|
+
if (err instanceof ORMError) throw err;
|
|
4336
4352
|
throw createDBQueryError(`Failed to execute query: ${err}`, err, compiled.sql, compiled.parameters);
|
|
4337
4353
|
}
|
|
4338
4354
|
return !!result[0]?.$exists;
|
|
@@ -4352,6 +4368,7 @@ var BaseOperationHandler = class {
|
|
|
4352
4368
|
try {
|
|
4353
4369
|
result = (await kysely.getExecutor().executeQuery(compiled)).rows;
|
|
4354
4370
|
} catch (err) {
|
|
4371
|
+
if (err instanceof ORMError) throw err;
|
|
4355
4372
|
throw createDBQueryError(`Failed to execute query: ${err}`, err, compiled.sql, compiled.parameters);
|
|
4356
4373
|
}
|
|
4357
4374
|
return result;
|
|
@@ -6763,6 +6780,7 @@ var ZenStackQueryExecutor = class ZenStackQueryExecutor extends DefaultQueryExec
|
|
|
6763
6780
|
if (this.dialect.supportsReturning) return queryResult.rows.map((row) => ({ ...row }));
|
|
6764
6781
|
else {
|
|
6765
6782
|
const mutatedIds = InsertQueryNode.is(queryNode) ? this.getInsertIds(mutationInfo.model, queryNode, queryResult) : preUpdateIds;
|
|
6783
|
+
if (mutatedIds && mutatedIds.length === 0) return [];
|
|
6766
6784
|
if (mutatedIds) {
|
|
6767
6785
|
const idFields = requireIdFields(this.client.$schema, mutationInfo.model);
|
|
6768
6786
|
const eb = expressionBuilder();
|
|
@@ -7542,9 +7560,9 @@ var ClientImpl = class ClientImpl {
|
|
|
7542
7560
|
validateOptions(baseClient, options) {
|
|
7543
7561
|
if (!baseClient && !options.skipValidationForComputedFields) this.validateComputedFieldsConfig(options);
|
|
7544
7562
|
if (options.diagnostics) {
|
|
7545
|
-
const parseResult = z
|
|
7546
|
-
slowQueryThresholdMs: z
|
|
7547
|
-
slowQueryMaxRecords: z
|
|
7563
|
+
const parseResult = z.object({
|
|
7564
|
+
slowQueryThresholdMs: z.number().nonnegative().optional(),
|
|
7565
|
+
slowQueryMaxRecords: z.int().nonnegative().or(z.literal(Infinity)).optional()
|
|
7548
7566
|
}).safeParse(options.diagnostics);
|
|
7549
7567
|
if (!parseResult.success) throw createConfigError(`Invalid diagnostics configuration: ${formatError(parseResult.error)}`);
|
|
7550
7568
|
}
|
|
@@ -7681,7 +7699,7 @@ var ClientImpl = class ClientImpl {
|
|
|
7681
7699
|
plugins: newPlugins
|
|
7682
7700
|
};
|
|
7683
7701
|
const newClient = new ClientImpl(this.schema, newOptions, this);
|
|
7684
|
-
newClient.inputValidator =
|
|
7702
|
+
newClient.inputValidator = this.deriveInputValidator(newClient);
|
|
7685
7703
|
return newClient;
|
|
7686
7704
|
}
|
|
7687
7705
|
$unuse(pluginId) {
|
|
@@ -7692,7 +7710,7 @@ var ClientImpl = class ClientImpl {
|
|
|
7692
7710
|
plugins: newPlugins
|
|
7693
7711
|
};
|
|
7694
7712
|
const newClient = new ClientImpl(this.schema, newOptions, this);
|
|
7695
|
-
newClient.inputValidator =
|
|
7713
|
+
newClient.inputValidator = this.deriveInputValidator(newClient);
|
|
7696
7714
|
return newClient;
|
|
7697
7715
|
}
|
|
7698
7716
|
$unuseAll() {
|
|
@@ -7701,9 +7719,22 @@ var ClientImpl = class ClientImpl {
|
|
|
7701
7719
|
plugins: []
|
|
7702
7720
|
};
|
|
7703
7721
|
const newClient = new ClientImpl(this.schema, newOptions, this);
|
|
7704
|
-
newClient.inputValidator =
|
|
7722
|
+
newClient.inputValidator = this.deriveInputValidator(newClient);
|
|
7705
7723
|
return newClient;
|
|
7706
7724
|
}
|
|
7725
|
+
/**
|
|
7726
|
+
* Validator for a client derived from this one. The derived client reuses this client's Zod
|
|
7727
|
+
* schema factory, and so its schema cache, whenever its options shape the same query-args
|
|
7728
|
+
* schemas; it only gets a fresh factory when a plugin that extends query args or results was
|
|
7729
|
+
* added or removed, or `omit`/`slicing` changed. The validator itself is always new because
|
|
7730
|
+
* `validateInput` may differ.
|
|
7731
|
+
*/
|
|
7732
|
+
deriveInputValidator(newClient) {
|
|
7733
|
+
return new InputValidator(newClient, {
|
|
7734
|
+
enabled: newClient.$options.validateInput !== false,
|
|
7735
|
+
zodFactory: haveSameSchemaInputs(this.$options, newClient.$options) ? this.inputValidator.zodFactory : void 0
|
|
7736
|
+
});
|
|
7737
|
+
}
|
|
7707
7738
|
$setAuth(auth) {
|
|
7708
7739
|
if (auth !== void 0 && (typeof auth !== "object" || auth === null || Array.isArray(auth))) throw new Error("Invalid auth object");
|
|
7709
7740
|
const newClient = new ClientImpl(this.schema, this.$options, this);
|
|
@@ -7725,7 +7756,7 @@ var ClientImpl = class ClientImpl {
|
|
|
7725
7756
|
}
|
|
7726
7757
|
$setOptions(options) {
|
|
7727
7758
|
const newClient = new ClientImpl(this.schema, options, this);
|
|
7728
|
-
newClient.inputValidator =
|
|
7759
|
+
newClient.inputValidator = this.deriveInputValidator(newClient);
|
|
7729
7760
|
return newClient;
|
|
7730
7761
|
}
|
|
7731
7762
|
$setInputValidation(enable) {
|