@zenstackhq/orm 3.9.1 → 3.9.2
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 +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.mts +6 -5
- package/dist/index.mjs +199 -199
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { t as __exportAll } from "./chunk-CfYAbeIz.mjs";
|
|
|
2
2
|
import { AnyNull, AnyNullClass, DbNull, DbNullClass, JsonNull, JsonNullClass } from "./common-types.mjs";
|
|
3
3
|
import { clone, enumerate, invariant, isPlainObject, lowerCaseFirst, upperCaseFirst } from "@zenstackhq/common-helpers";
|
|
4
4
|
import { AliasNode, AndNode, ColumnNode, ColumnUpdateNode, CompiledQuery, DefaultConnectionProvider, DefaultQueryExecutor, DeleteQueryNode, ExpressionWrapper, FromNode, IdentifierNode, InsertQueryNode, Kysely, Log, OperationNodeTransformer, OperationNodeVisitor, PrimitiveValueListNode, ReferenceNode, ReturningNode, SelectAllNode, SelectionNode, SingleConnectionProvider, TableNode, Transaction, UpdateQueryNode, ValueListNode, ValueNode, ValuesNode, WhereNode, createQueryId, expressionBuilder, sql } from "kysely";
|
|
5
|
-
import z, { ZodObject, ZodType, z
|
|
5
|
+
import z$1, { ZodObject, ZodType, z } from "zod";
|
|
6
6
|
import { fromError } from "zod-validation-error/v4";
|
|
7
7
|
import { P, match } from "ts-pattern";
|
|
8
8
|
import { ExpressionUtils } from "@zenstackhq/schema";
|
|
@@ -2399,7 +2399,7 @@ function createQuerySchemaFactory(clientOrSchema, options) {
|
|
|
2399
2399
|
* @see https://github.com/zenstackhq/zenstack/issues/2631
|
|
2400
2400
|
*/
|
|
2401
2401
|
function coercedDateTimeSchema() {
|
|
2402
|
-
return z
|
|
2402
|
+
return z.preprocess((val) => {
|
|
2403
2403
|
if (typeof val !== "string") return val;
|
|
2404
2404
|
if (/^\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d\d(?::\d\d)?)?$/.test(val)) {
|
|
2405
2405
|
const hasTz = val.endsWith("Z") || /[+-]\d\d(?::\d\d)?$/.test(val);
|
|
@@ -2408,10 +2408,10 @@ function coercedDateTimeSchema() {
|
|
|
2408
2408
|
}
|
|
2409
2409
|
const d = new Date(val);
|
|
2410
2410
|
return isNaN(d.getTime()) ? val : d;
|
|
2411
|
-
}, z
|
|
2412
|
-
z
|
|
2413
|
-
z
|
|
2414
|
-
z
|
|
2411
|
+
}, z.union([
|
|
2412
|
+
z.iso.datetime(),
|
|
2413
|
+
z.iso.date(),
|
|
2414
|
+
z.date()
|
|
2415
2415
|
]));
|
|
2416
2416
|
}
|
|
2417
2417
|
/**
|
|
@@ -2419,7 +2419,7 @@ function coercedDateTimeSchema() {
|
|
|
2419
2419
|
*/
|
|
2420
2420
|
var ZodSchemaFactory = class {
|
|
2421
2421
|
schemaCache = /* @__PURE__ */ new Map();
|
|
2422
|
-
schemaRegistry = z
|
|
2422
|
+
schemaRegistry = z.registry();
|
|
2423
2423
|
allFilterKinds = [...new Set(Object.values(FILTER_PROPERTY_TO_KIND))];
|
|
2424
2424
|
schema;
|
|
2425
2425
|
options;
|
|
@@ -2511,7 +2511,7 @@ var ZodSchemaFactory = class {
|
|
|
2511
2511
|
this.makeGroupBySchema(m);
|
|
2512
2512
|
}
|
|
2513
2513
|
for (const procName of Object.keys(this.schema.procedures ?? {})) if (this.isProcedureAllowed(procName)) this.makeProcedureArgsSchema(procName);
|
|
2514
|
-
return z
|
|
2514
|
+
return z.toJSONSchema(this.schemaRegistry, { unrepresentable: "any" });
|
|
2515
2515
|
}
|
|
2516
2516
|
get cacheStats() {
|
|
2517
2517
|
return {
|
|
@@ -2540,13 +2540,13 @@ var ZodSchemaFactory = class {
|
|
|
2540
2540
|
fields["omit"] = this.makeOmitSchema(model).optional().nullable();
|
|
2541
2541
|
if (!unique) {
|
|
2542
2542
|
fields["skip"] = this.makeSkipSchema().optional();
|
|
2543
|
-
if (findOne) fields["take"] = z
|
|
2543
|
+
if (findOne) fields["take"] = z.literal(1).optional();
|
|
2544
2544
|
else fields["take"] = this.makeTakeSchema().optional();
|
|
2545
2545
|
fields["orderBy"] = this.orArray(this.makeOrderBySchema(model, true, false, options), true).optional();
|
|
2546
2546
|
fields["cursor"] = this.makeCursorSchema(model, options).optional();
|
|
2547
2547
|
fields["distinct"] = this.makeDistinctSchema(model).optional();
|
|
2548
2548
|
}
|
|
2549
|
-
const baseSchema = z
|
|
2549
|
+
const baseSchema = z.strictObject(fields);
|
|
2550
2550
|
let result = this.mergePluginArgsSchema(baseSchema, operation);
|
|
2551
2551
|
result = this.refineForSelectIncludeMutuallyExclusive(result);
|
|
2552
2552
|
result = this.refineForSelectOmitMutuallyExclusive(result);
|
|
@@ -2556,7 +2556,7 @@ var ZodSchemaFactory = class {
|
|
|
2556
2556
|
return result;
|
|
2557
2557
|
}
|
|
2558
2558
|
makeExistsSchema(model, options) {
|
|
2559
|
-
const baseSchema = z
|
|
2559
|
+
const baseSchema = z.strictObject({ where: this.makeWhereSchema(model, false, false, false, options).optional() });
|
|
2560
2560
|
const result = this.mergePluginArgsSchema(baseSchema, "exists").optional();
|
|
2561
2561
|
this.registerSchema(`${model}ExistsArgs`, result);
|
|
2562
2562
|
return result;
|
|
@@ -2564,19 +2564,19 @@ var ZodSchemaFactory = class {
|
|
|
2564
2564
|
makeScalarSchema(type, attributes) {
|
|
2565
2565
|
if (this.schema.typeDefs && type in this.schema.typeDefs) return this.makeTypeDefSchema(type);
|
|
2566
2566
|
else if (this.schema.enums && type in this.schema.enums) return this.makeEnumSchema(type);
|
|
2567
|
-
else return match(type).with("String", () => this.extraValidationsEnabled ? ZodUtils.addStringValidation(z
|
|
2568
|
-
return z
|
|
2569
|
-
this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z
|
|
2570
|
-
ZodUtils.addDecimalValidation(z
|
|
2571
|
-
ZodUtils.addDecimalValidation(z
|
|
2567
|
+
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", () => {
|
|
2568
|
+
return z.union([
|
|
2569
|
+
this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z.number(), attributes) : z.number(),
|
|
2570
|
+
ZodUtils.addDecimalValidation(z.instanceof(Decimal), attributes, this.extraValidationsEnabled),
|
|
2571
|
+
ZodUtils.addDecimalValidation(z.string(), attributes, this.extraValidationsEnabled)
|
|
2572
2572
|
]);
|
|
2573
|
-
}).with("DateTime", () => this.makeDateTimeValueSchema()).with("Bytes", () => z
|
|
2573
|
+
}).with("DateTime", () => this.makeDateTimeValueSchema()).with("Bytes", () => z.instanceof(Uint8Array)).with("Json", () => this.makeJsonValueSchema()).otherwise(() => z.unknown());
|
|
2574
2574
|
}
|
|
2575
2575
|
isParameterizedComputedField(fieldDef) {
|
|
2576
2576
|
return !!(fieldDef.computed && fieldDef.params);
|
|
2577
2577
|
}
|
|
2578
2578
|
makeFieldArgsSchema(params) {
|
|
2579
|
-
return z
|
|
2579
|
+
return z.strictObject(Object.fromEntries(Object.entries(params).map(([name, param]) => {
|
|
2580
2580
|
let paramSchema = this.makeScalarSchema(param.type);
|
|
2581
2581
|
if (param.array) paramSchema = paramSchema.array();
|
|
2582
2582
|
if (param.optional) paramSchema = paramSchema.optional();
|
|
@@ -2584,9 +2584,9 @@ var ZodSchemaFactory = class {
|
|
|
2584
2584
|
})));
|
|
2585
2585
|
}
|
|
2586
2586
|
addComputedArgsToFilter(filterSchema, params) {
|
|
2587
|
-
const objectMembers = (filterSchema instanceof z
|
|
2587
|
+
const objectMembers = (filterSchema instanceof z.ZodUnion ? filterSchema.options : [filterSchema]).filter((m) => m instanceof z.ZodObject);
|
|
2588
2588
|
const components = Object.assign({}, ...objectMembers.map((o) => o.shape));
|
|
2589
|
-
return z
|
|
2589
|
+
return z.strictObject({
|
|
2590
2590
|
args: this.makeFieldArgsSchema(params),
|
|
2591
2591
|
...components
|
|
2592
2592
|
});
|
|
@@ -2594,20 +2594,20 @@ var ZodSchemaFactory = class {
|
|
|
2594
2594
|
makeEnumSchema(_enum) {
|
|
2595
2595
|
const enumDef = getEnum(this.schema, _enum);
|
|
2596
2596
|
invariant(enumDef, `Enum "${_enum}" not found in schema`);
|
|
2597
|
-
const schema = z
|
|
2597
|
+
const schema = z.enum(Object.keys(enumDef.values));
|
|
2598
2598
|
this.registerSchema(_enum, schema);
|
|
2599
2599
|
return schema;
|
|
2600
2600
|
}
|
|
2601
2601
|
makeTypeDefSchema(type) {
|
|
2602
2602
|
const typeDef = getTypeDef(this.schema, type);
|
|
2603
2603
|
invariant(typeDef, `Type definition "${type}" not found in schema`);
|
|
2604
|
-
const schema = z
|
|
2605
|
-
let fieldSchema = isTypeDef(this.schema, def.type) ? z
|
|
2604
|
+
const schema = (typeDef.strict ? z.strictObject : z.looseObject)(Object.fromEntries(Object.entries(typeDef.fields).map(([field, def]) => {
|
|
2605
|
+
let fieldSchema = isTypeDef(this.schema, def.type) ? z.lazy(() => this.makeTypeDefSchema(def.type)) : this.makeScalarSchema(def.type);
|
|
2606
2606
|
if (def.array) fieldSchema = fieldSchema.array();
|
|
2607
2607
|
if (def.optional) fieldSchema = fieldSchema.nullish();
|
|
2608
2608
|
return [field, fieldSchema];
|
|
2609
2609
|
})));
|
|
2610
|
-
const finalSchema = z
|
|
2610
|
+
const finalSchema = z.any().superRefine((value, ctx) => {
|
|
2611
2611
|
const parseResult = schema.safeParse(value);
|
|
2612
2612
|
if (!parseResult.success) parseResult.error.issues.forEach((issue) => ctx.addIssue(issue));
|
|
2613
2613
|
});
|
|
@@ -2623,17 +2623,17 @@ var ZodSchemaFactory = class {
|
|
|
2623
2623
|
if (fieldDef.relation) {
|
|
2624
2624
|
if (withoutRelationFields || !this.shouldIncludeRelations(options)) continue;
|
|
2625
2625
|
const allowedFilterKinds = this.getEffectiveFilterKinds(model, field);
|
|
2626
|
-
if (allowedFilterKinds && !allowedFilterKinds.includes("Relation")) fieldSchema = z
|
|
2626
|
+
if (allowedFilterKinds && !allowedFilterKinds.includes("Relation")) fieldSchema = z.never();
|
|
2627
2627
|
else {
|
|
2628
|
-
fieldSchema = z
|
|
2629
|
-
if (fieldDef.array) fieldSchema = z
|
|
2628
|
+
fieldSchema = z.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts).optional());
|
|
2629
|
+
if (fieldDef.array) fieldSchema = z.strictObject({
|
|
2630
2630
|
some: fieldSchema.optional(),
|
|
2631
2631
|
every: fieldSchema.optional(),
|
|
2632
2632
|
none: fieldSchema.optional()
|
|
2633
2633
|
});
|
|
2634
2634
|
else {
|
|
2635
2635
|
fieldSchema = this.nullableIf(fieldSchema, !fieldDef.array && !!fieldDef.optional);
|
|
2636
|
-
fieldSchema = z
|
|
2636
|
+
fieldSchema = z.union([fieldSchema, z.strictObject({
|
|
2637
2637
|
is: fieldSchema.optional(),
|
|
2638
2638
|
isNot: fieldSchema.optional()
|
|
2639
2639
|
})]);
|
|
@@ -2653,21 +2653,21 @@ var ZodSchemaFactory = class {
|
|
|
2653
2653
|
}
|
|
2654
2654
|
if (unique) {
|
|
2655
2655
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
2656
|
-
for (const uniqueField of uniqueFields) if ("defs" in uniqueField) fields[uniqueField.name] = z
|
|
2656
|
+
for (const uniqueField of uniqueFields) if ("defs" in uniqueField) fields[uniqueField.name] = z.object(Object.fromEntries(Object.entries(uniqueField.defs).map(([key, def]) => {
|
|
2657
2657
|
invariant(!def.relation, "unique field cannot be a relation");
|
|
2658
2658
|
let fieldSchema;
|
|
2659
2659
|
const enumDef = getEnum(this.schema, def.type);
|
|
2660
2660
|
if (enumDef) if (Object.keys(enumDef.values).length > 0) fieldSchema = this.makeEnumFilterSchema(def.type, !!def.optional, !!def.array, false, void 0);
|
|
2661
|
-
else fieldSchema = z
|
|
2661
|
+
else fieldSchema = z.never();
|
|
2662
2662
|
else fieldSchema = this.makePrimitiveFilterSchema(def.type, !!def.optional, false, void 0);
|
|
2663
2663
|
return [key, fieldSchema];
|
|
2664
2664
|
}))).optional();
|
|
2665
2665
|
}
|
|
2666
|
-
fields["$expr"] = z
|
|
2667
|
-
fields["AND"] = this.orArray(z
|
|
2668
|
-
fields["OR"] = z
|
|
2669
|
-
fields["NOT"] = this.orArray(z
|
|
2670
|
-
const baseWhere = z
|
|
2666
|
+
fields["$expr"] = z.custom((v) => typeof v === "function", { error: "\"$expr\" must be a function" }).optional();
|
|
2667
|
+
fields["AND"] = this.orArray(z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
|
|
2668
|
+
fields["OR"] = z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)).array().optional();
|
|
2669
|
+
fields["NOT"] = this.orArray(z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
|
|
2670
|
+
const baseWhere = z.strictObject(fields);
|
|
2671
2671
|
let result = baseWhere;
|
|
2672
2672
|
if (unique) {
|
|
2673
2673
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
@@ -2693,26 +2693,26 @@ var ZodSchemaFactory = class {
|
|
|
2693
2693
|
else if (getEnum(this.schema, fieldDef.type)) fieldSchemas[fieldName] = this.makeEnumFilterSchema(fieldDef.type, !!fieldDef.optional, !!fieldDef.array, false, void 0).optional();
|
|
2694
2694
|
else if (fieldDef.array) fieldSchemas[fieldName] = this.makeArrayFilterSchema(fieldDef.type, void 0).optional();
|
|
2695
2695
|
else fieldSchemas[fieldName] = this.makePrimitiveFilterSchema(fieldDef.type, !!fieldDef.optional, false, void 0).optional();
|
|
2696
|
-
candidates.push(z
|
|
2696
|
+
candidates.push(z.strictObject(fieldSchemas));
|
|
2697
2697
|
}
|
|
2698
|
-
const recursiveSchema = z
|
|
2699
|
-
if (array) candidates.push(z
|
|
2698
|
+
const recursiveSchema = z.lazy(() => this.makeTypedJsonFilterSchema(type, optional, false, allowedFilterKinds)).optional();
|
|
2699
|
+
if (array) candidates.push(z.strictObject({
|
|
2700
2700
|
some: recursiveSchema,
|
|
2701
2701
|
every: recursiveSchema,
|
|
2702
2702
|
none: recursiveSchema
|
|
2703
2703
|
}));
|
|
2704
|
-
else candidates.push(z
|
|
2704
|
+
else candidates.push(z.strictObject({
|
|
2705
2705
|
is: recursiveSchema,
|
|
2706
2706
|
isNot: recursiveSchema
|
|
2707
2707
|
}));
|
|
2708
2708
|
candidates.push(this.makeJsonFilterSchema(optional, allowedFilterKinds));
|
|
2709
2709
|
if (optional) {
|
|
2710
|
-
candidates.push(z
|
|
2711
|
-
candidates.push(z
|
|
2712
|
-
candidates.push(z
|
|
2713
|
-
candidates.push(z
|
|
2710
|
+
candidates.push(z.null());
|
|
2711
|
+
candidates.push(z.instanceof(DbNullClass));
|
|
2712
|
+
candidates.push(z.instanceof(JsonNullClass));
|
|
2713
|
+
candidates.push(z.instanceof(AnyNullClass));
|
|
2714
2714
|
}
|
|
2715
|
-
const result = z
|
|
2715
|
+
const result = z.union(candidates);
|
|
2716
2716
|
this.registerSchema(`${type}Filter${this.filterSchemaSuffix({
|
|
2717
2717
|
optional,
|
|
2718
2718
|
array,
|
|
@@ -2721,7 +2721,7 @@ var ZodSchemaFactory = class {
|
|
|
2721
2721
|
return result;
|
|
2722
2722
|
}
|
|
2723
2723
|
makeNullableTypedJsonMutationSchema(fieldSchema) {
|
|
2724
|
-
return z
|
|
2724
|
+
return z.any().superRefine((value, ctx) => {
|
|
2725
2725
|
if (value instanceof DbNullClass || value instanceof JsonNullClass || value === null || value === void 0) return;
|
|
2726
2726
|
const parseResult = fieldSchema.safeParse(value);
|
|
2727
2727
|
if (!parseResult.success) parseResult.error.issues.forEach((issue) => ctx.addIssue(issue));
|
|
@@ -2733,11 +2733,11 @@ var ZodSchemaFactory = class {
|
|
|
2733
2733
|
makeEnumFilterSchema(enumName, optional, array, withAggregations, allowedFilterKinds) {
|
|
2734
2734
|
const enumDef = getEnum(this.schema, enumName);
|
|
2735
2735
|
invariant(enumDef, `Enum "${enumName}" not found in schema`);
|
|
2736
|
-
const baseSchema = z
|
|
2736
|
+
const baseSchema = z.enum(Object.keys(enumDef.values));
|
|
2737
2737
|
let schema;
|
|
2738
2738
|
if (array) schema = this.internalMakeArrayFilterSchema(baseSchema, allowedFilterKinds);
|
|
2739
2739
|
else {
|
|
2740
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z
|
|
2740
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z.lazy(() => this.makeEnumFilterSchema(enumName, optional, array, withAggregations, allowedFilterKinds)), [
|
|
2741
2741
|
"equals",
|
|
2742
2742
|
"in",
|
|
2743
2743
|
"notIn",
|
|
@@ -2771,42 +2771,42 @@ var ZodSchemaFactory = class {
|
|
|
2771
2771
|
has: elementSchema.optional(),
|
|
2772
2772
|
hasEvery: elementSchema.array().optional(),
|
|
2773
2773
|
hasSome: elementSchema.array().optional(),
|
|
2774
|
-
isEmpty: z
|
|
2774
|
+
isEmpty: z.boolean().optional()
|
|
2775
2775
|
};
|
|
2776
2776
|
const filteredOperators = this.trimFilterOperators(operators, allowedFilterKinds);
|
|
2777
|
-
return z
|
|
2777
|
+
return z.strictObject(filteredOperators);
|
|
2778
2778
|
}
|
|
2779
2779
|
makePrimitiveFilterSchema(type, optional, withAggregations, allowedFilterKinds, withFuzzy = false, withFullText = false) {
|
|
2780
|
-
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
|
|
2780
|
+
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();
|
|
2781
2781
|
}
|
|
2782
2782
|
makeJsonValueSchema() {
|
|
2783
|
-
const schema = z
|
|
2784
|
-
z
|
|
2785
|
-
z
|
|
2786
|
-
z
|
|
2787
|
-
z
|
|
2788
|
-
z
|
|
2789
|
-
z
|
|
2783
|
+
const schema = z.union([
|
|
2784
|
+
z.string(),
|
|
2785
|
+
z.number(),
|
|
2786
|
+
z.boolean(),
|
|
2787
|
+
z.instanceof(JsonNullClass),
|
|
2788
|
+
z.lazy(() => z.union([this.makeJsonValueSchema(), z.null()]).array()),
|
|
2789
|
+
z.record(z.string(), z.lazy(() => z.union([this.makeJsonValueSchema(), z.null()])))
|
|
2790
2790
|
]);
|
|
2791
2791
|
this.registerSchema("JsonValue", schema);
|
|
2792
2792
|
return schema;
|
|
2793
2793
|
}
|
|
2794
2794
|
makeJsonFilterSchema(optional, allowedFilterKinds) {
|
|
2795
|
-
if (allowedFilterKinds && !allowedFilterKinds.includes("Json")) return z
|
|
2795
|
+
if (allowedFilterKinds && !allowedFilterKinds.includes("Json")) return z.never();
|
|
2796
2796
|
const filterMembers = [
|
|
2797
2797
|
this.makeJsonValueSchema(),
|
|
2798
|
-
z
|
|
2799
|
-
z
|
|
2798
|
+
z.instanceof(DbNullClass),
|
|
2799
|
+
z.instanceof(AnyNullClass)
|
|
2800
2800
|
];
|
|
2801
|
-
if (optional) filterMembers.push(z
|
|
2802
|
-
const filterValueSchema = z
|
|
2803
|
-
const schema = z
|
|
2804
|
-
path: z
|
|
2801
|
+
if (optional) filterMembers.push(z.null());
|
|
2802
|
+
const filterValueSchema = z.union(filterMembers);
|
|
2803
|
+
const schema = z.strictObject({
|
|
2804
|
+
path: z.string().optional(),
|
|
2805
2805
|
equals: filterValueSchema.optional(),
|
|
2806
2806
|
not: filterValueSchema.optional(),
|
|
2807
|
-
string_contains: z
|
|
2808
|
-
string_starts_with: z
|
|
2809
|
-
string_ends_with: z
|
|
2807
|
+
string_contains: z.string().optional(),
|
|
2808
|
+
string_starts_with: z.string().optional(),
|
|
2809
|
+
string_ends_with: z.string().optional(),
|
|
2810
2810
|
mode: this.makeStringModeSchema().optional(),
|
|
2811
2811
|
array_contains: filterValueSchema.optional(),
|
|
2812
2812
|
array_starts_with: filterValueSchema.optional(),
|
|
@@ -2825,7 +2825,7 @@ var ZodSchemaFactory = class {
|
|
|
2825
2825
|
}
|
|
2826
2826
|
makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
2827
2827
|
const filterValueSchema = this.makeDateTimeValueSchema();
|
|
2828
|
-
const schema = this.makeCommonPrimitiveFilterSchema(filterValueSchema, optional, () => z
|
|
2828
|
+
const schema = this.makeCommonPrimitiveFilterSchema(filterValueSchema, optional, () => z.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)), withAggregations ? [
|
|
2829
2829
|
"_count",
|
|
2830
2830
|
"_min",
|
|
2831
2831
|
"_max"
|
|
@@ -2838,12 +2838,12 @@ var ZodSchemaFactory = class {
|
|
|
2838
2838
|
return schema;
|
|
2839
2839
|
}
|
|
2840
2840
|
makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
2841
|
-
const components = this.makeCommonPrimitiveFilterComponents(z
|
|
2841
|
+
const components = this.makeCommonPrimitiveFilterComponents(z.boolean(), optional, () => z.lazy(() => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)), ["equals", "not"], withAggregations ? [
|
|
2842
2842
|
"_count",
|
|
2843
2843
|
"_min",
|
|
2844
2844
|
"_max"
|
|
2845
2845
|
] : void 0, allowedFilterKinds);
|
|
2846
|
-
const schema = this.createUnionFilterSchema(z
|
|
2846
|
+
const schema = this.createUnionFilterSchema(z.boolean(), optional, components, allowedFilterKinds);
|
|
2847
2847
|
this.registerSchema(`BooleanFilter${this.filterSchemaSuffix({
|
|
2848
2848
|
optional,
|
|
2849
2849
|
allowedFilterKinds,
|
|
@@ -2852,8 +2852,8 @@ var ZodSchemaFactory = class {
|
|
|
2852
2852
|
return schema;
|
|
2853
2853
|
}
|
|
2854
2854
|
makeBytesFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
2855
|
-
const baseSchema = z
|
|
2856
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z
|
|
2855
|
+
const baseSchema = z.instanceof(Uint8Array);
|
|
2856
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z.instanceof(Uint8Array), [
|
|
2857
2857
|
"equals",
|
|
2858
2858
|
"in",
|
|
2859
2859
|
"notIn",
|
|
@@ -2901,7 +2901,7 @@ var ZodSchemaFactory = class {
|
|
|
2901
2901
|
return this.createUnionFilterSchema(baseSchema, optional, components, allowedFilterKinds);
|
|
2902
2902
|
}
|
|
2903
2903
|
makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds) {
|
|
2904
|
-
const schema = this.makeCommonPrimitiveFilterSchema(this.makeScalarSchema(type), optional, () => z
|
|
2904
|
+
const schema = this.makeCommonPrimitiveFilterSchema(this.makeScalarSchema(type), optional, () => z.lazy(() => this.makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds)), withAggregations ? [
|
|
2905
2905
|
"_count",
|
|
2906
2906
|
"_avg",
|
|
2907
2907
|
"_sum",
|
|
@@ -2916,15 +2916,15 @@ var ZodSchemaFactory = class {
|
|
|
2916
2916
|
return schema;
|
|
2917
2917
|
}
|
|
2918
2918
|
makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy = false, withFullText = false) {
|
|
2919
|
-
const baseComponents = this.makeCommonPrimitiveFilterComponents(z
|
|
2919
|
+
const baseComponents = this.makeCommonPrimitiveFilterComponents(z.string(), optional, () => z.lazy(() => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy, withFullText)), void 0, withAggregations ? [
|
|
2920
2920
|
"_count",
|
|
2921
2921
|
"_min",
|
|
2922
2922
|
"_max"
|
|
2923
2923
|
] : void 0, allowedFilterKinds);
|
|
2924
2924
|
const stringSpecificOperators = {
|
|
2925
|
-
startsWith: z
|
|
2926
|
-
endsWith: z
|
|
2927
|
-
contains: z
|
|
2925
|
+
startsWith: z.string().optional(),
|
|
2926
|
+
endsWith: z.string().optional(),
|
|
2927
|
+
contains: z.string().optional(),
|
|
2928
2928
|
...withFuzzy && this.providerSupportsFuzzySearch ? { fuzzy: this.makeFuzzyFilterSchema().optional() } : {},
|
|
2929
2929
|
...withFullText && this.providerSupportsFullTextSearch ? { fts: this.makeFullTextFilterSchema().optional() } : {},
|
|
2930
2930
|
...this.providerSupportsCaseSensitivity ? { mode: this.makeStringModeSchema().optional() } : {}
|
|
@@ -2934,7 +2934,7 @@ var ZodSchemaFactory = class {
|
|
|
2934
2934
|
...baseComponents,
|
|
2935
2935
|
...filteredStringOperators
|
|
2936
2936
|
};
|
|
2937
|
-
const schema = this.createUnionFilterSchema(z
|
|
2937
|
+
const schema = this.createUnionFilterSchema(z.string(), optional, allComponents, allowedFilterKinds);
|
|
2938
2938
|
const featureSuffix = `${withFuzzy ? "Fuzzy" : ""}${withFullText ? "FullText" : ""}`;
|
|
2939
2939
|
this.registerSchema(`StringFilter${this.filterSchemaSuffix({
|
|
2940
2940
|
optional,
|
|
@@ -2944,45 +2944,45 @@ var ZodSchemaFactory = class {
|
|
|
2944
2944
|
return schema;
|
|
2945
2945
|
}
|
|
2946
2946
|
makeStringModeSchema() {
|
|
2947
|
-
return z
|
|
2947
|
+
return z.union([z.literal("default"), z.literal("insensitive")]);
|
|
2948
2948
|
}
|
|
2949
2949
|
makeFuzzyFilterSchema() {
|
|
2950
|
-
return z
|
|
2951
|
-
search: z
|
|
2952
|
-
mode: z
|
|
2953
|
-
z
|
|
2954
|
-
z
|
|
2955
|
-
z
|
|
2950
|
+
return z.strictObject({
|
|
2951
|
+
search: z.string().min(1),
|
|
2952
|
+
mode: z.union([
|
|
2953
|
+
z.literal("simple"),
|
|
2954
|
+
z.literal("word"),
|
|
2955
|
+
z.literal("strictWord")
|
|
2956
2956
|
]).default("simple"),
|
|
2957
|
-
threshold: z
|
|
2958
|
-
unaccent: z
|
|
2957
|
+
threshold: z.number().min(0).max(1).optional(),
|
|
2958
|
+
unaccent: z.boolean().default(false)
|
|
2959
2959
|
});
|
|
2960
2960
|
}
|
|
2961
2961
|
makeFullTextFilterSchema() {
|
|
2962
|
-
return z
|
|
2963
|
-
search: z
|
|
2964
|
-
config: z
|
|
2962
|
+
return z.strictObject({
|
|
2963
|
+
search: z.string().min(1),
|
|
2964
|
+
config: z.string().min(1).optional()
|
|
2965
2965
|
});
|
|
2966
2966
|
}
|
|
2967
2967
|
makeSelectSchema(model, options) {
|
|
2968
2968
|
const fields = {};
|
|
2969
2969
|
for (const [field, fieldDef] of this.getModelFields(model)) {
|
|
2970
2970
|
if (this.isParameterizedComputedField(fieldDef)) {
|
|
2971
|
-
fields[field] = z
|
|
2971
|
+
fields[field] = z.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional();
|
|
2972
2972
|
continue;
|
|
2973
2973
|
}
|
|
2974
2974
|
if (fieldDef.relation) {
|
|
2975
2975
|
if (!this.shouldIncludeRelations(options)) continue;
|
|
2976
2976
|
if (this.isModelAllowed(fieldDef.type)) fields[field] = this.makeRelationSelectIncludeSchema(model, field, options).optional();
|
|
2977
|
-
} else if (this.options.allowQueryTimeOmitOverride === false && this.isFieldOmittedByConfig(model, field)) fields[field] = z
|
|
2978
|
-
else fields[field] = z
|
|
2977
|
+
} else if (this.options.allowQueryTimeOmitOverride === false && this.isFieldOmittedByConfig(model, field)) fields[field] = z.literal(false).optional();
|
|
2978
|
+
else fields[field] = z.boolean().optional();
|
|
2979
2979
|
}
|
|
2980
2980
|
if (this.shouldIncludeRelations(options)) {
|
|
2981
2981
|
const _countSchema = this.makeCountSelectionSchema(model, options);
|
|
2982
|
-
if (!(_countSchema instanceof z
|
|
2982
|
+
if (!(_countSchema instanceof z.ZodNever)) fields["_count"] = _countSchema;
|
|
2983
2983
|
}
|
|
2984
2984
|
this.addExtResultFields(model, fields);
|
|
2985
|
-
const result = z
|
|
2985
|
+
const result = z.strictObject(fields);
|
|
2986
2986
|
this.registerSchema(`${model}Select`, result);
|
|
2987
2987
|
return result;
|
|
2988
2988
|
}
|
|
@@ -2991,24 +2991,24 @@ var ZodSchemaFactory = class {
|
|
|
2991
2991
|
const toManyRelations = Object.values(modelDef.fields).filter((def) => def.relation && def.array);
|
|
2992
2992
|
if (toManyRelations.length > 0) {
|
|
2993
2993
|
const nextOpts = this.nextOptions(options);
|
|
2994
|
-
const schema = z
|
|
2994
|
+
const schema = z.union([z.literal(true), z.strictObject({ select: z.strictObject(toManyRelations.reduce((acc, fieldDef) => ({
|
|
2995
2995
|
...acc,
|
|
2996
|
-
[fieldDef.name]: z
|
|
2996
|
+
[fieldDef.name]: z.union([z.boolean(), z.strictObject({ where: this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts) })]).optional()
|
|
2997
2997
|
}), {})) })]).optional();
|
|
2998
2998
|
this.registerSchema(`${model}CountSelection`, schema);
|
|
2999
2999
|
return schema;
|
|
3000
|
-
} else return z
|
|
3000
|
+
} else return z.never();
|
|
3001
3001
|
}
|
|
3002
3002
|
makeRelationSelectIncludeSchema(model, field, options) {
|
|
3003
3003
|
const fieldDef = requireField(this.schema, model, field);
|
|
3004
3004
|
const nextOpts = this.nextOptions(options);
|
|
3005
|
-
let objSchema = z
|
|
3006
|
-
...fieldDef.array || fieldDef.optional ? { where: z
|
|
3007
|
-
select: z
|
|
3008
|
-
include: z
|
|
3009
|
-
omit: z
|
|
3005
|
+
let objSchema = z.strictObject({
|
|
3006
|
+
...fieldDef.array || fieldDef.optional ? { where: z.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts)).optional() } : {},
|
|
3007
|
+
select: z.lazy(() => this.makeSelectSchema(fieldDef.type, nextOpts)).optional().nullable(),
|
|
3008
|
+
include: z.lazy(() => this.makeIncludeSchema(fieldDef.type, nextOpts)).optional().nullable(),
|
|
3009
|
+
omit: z.lazy(() => this.makeOmitSchema(fieldDef.type)).optional().nullable(),
|
|
3010
3010
|
...fieldDef.array ? {
|
|
3011
|
-
orderBy: z
|
|
3011
|
+
orderBy: z.lazy(() => this.orArray(this.makeOrderBySchema(fieldDef.type, true, false, nextOpts), true)).optional(),
|
|
3012
3012
|
skip: this.makeSkipSchema().optional(),
|
|
3013
3013
|
take: this.makeTakeSchema().optional(),
|
|
3014
3014
|
cursor: this.makeCursorSchema(fieldDef.type, nextOpts).optional(),
|
|
@@ -3018,7 +3018,7 @@ var ZodSchemaFactory = class {
|
|
|
3018
3018
|
objSchema = this.refineForSelectIncludeMutuallyExclusive(objSchema);
|
|
3019
3019
|
objSchema = this.refineForSelectOmitMutuallyExclusive(objSchema);
|
|
3020
3020
|
objSchema = this.refineForSelectHasTruthyField(objSchema);
|
|
3021
|
-
const result = z
|
|
3021
|
+
const result = z.union([z.boolean(), objSchema]);
|
|
3022
3022
|
this.registerSchema(`${model}${upperCaseFirst(field)}RelationInput`, result);
|
|
3023
3023
|
return result;
|
|
3024
3024
|
}
|
|
@@ -3035,11 +3035,11 @@ var ZodSchemaFactory = class {
|
|
|
3035
3035
|
const fields = {};
|
|
3036
3036
|
for (const [field, fieldDef] of this.getModelFields(model)) {
|
|
3037
3037
|
if (this.isParameterizedComputedField(fieldDef)) continue;
|
|
3038
|
-
if (!fieldDef.relation) if (this.options.allowQueryTimeOmitOverride !== false) fields[field] = z
|
|
3039
|
-
else fields[field] = z
|
|
3038
|
+
if (!fieldDef.relation) if (this.options.allowQueryTimeOmitOverride !== false) fields[field] = z.boolean().optional();
|
|
3039
|
+
else fields[field] = z.literal(true).optional();
|
|
3040
3040
|
}
|
|
3041
3041
|
this.addExtResultFields(model, fields);
|
|
3042
|
-
const result = z
|
|
3042
|
+
const result = z.strictObject(fields);
|
|
3043
3043
|
this.registerSchema(`${model}OmitInput`, result);
|
|
3044
3044
|
return result;
|
|
3045
3045
|
}
|
|
@@ -3048,7 +3048,7 @@ var ZodSchemaFactory = class {
|
|
|
3048
3048
|
const resultConfig = plugin.result;
|
|
3049
3049
|
if (resultConfig) {
|
|
3050
3050
|
const modelConfig = resultConfig[lowerCaseFirst(model)];
|
|
3051
|
-
if (modelConfig) for (const field of Object.keys(modelConfig)) fields[field] = z
|
|
3051
|
+
if (modelConfig) for (const field of Object.keys(modelConfig)) fields[field] = z.boolean().optional();
|
|
3052
3052
|
}
|
|
3053
3053
|
}
|
|
3054
3054
|
}
|
|
@@ -3060,35 +3060,35 @@ var ZodSchemaFactory = class {
|
|
|
3060
3060
|
if (fieldDef.relation) {
|
|
3061
3061
|
if (!this.shouldIncludeRelations(options)) continue;
|
|
3062
3062
|
if (this.isModelAllowed(fieldDef.type)) fields[field] = this.makeRelationSelectIncludeSchema(model, field, options).optional();
|
|
3063
|
-
} else if (this.isParameterizedComputedField(fieldDef)) fields[field] = z
|
|
3063
|
+
} else if (this.isParameterizedComputedField(fieldDef)) fields[field] = z.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional();
|
|
3064
3064
|
}
|
|
3065
3065
|
if (this.shouldIncludeRelations(options)) {
|
|
3066
3066
|
const _countSchema = this.makeCountSelectionSchema(model, options);
|
|
3067
|
-
if (!(_countSchema instanceof z
|
|
3067
|
+
if (!(_countSchema instanceof z.ZodNever)) fields["_count"] = _countSchema;
|
|
3068
3068
|
}
|
|
3069
|
-
const result = z
|
|
3069
|
+
const result = z.strictObject(fields);
|
|
3070
3070
|
this.registerSchema(`${model}Include`, result);
|
|
3071
3071
|
return result;
|
|
3072
3072
|
}
|
|
3073
3073
|
makeOrderBySchema(model, withRelation, WithAggregation, options) {
|
|
3074
3074
|
const fields = {};
|
|
3075
|
-
const sort = z
|
|
3075
|
+
const sort = z.union([z.literal("asc"), z.literal("desc")]);
|
|
3076
3076
|
const refineAtMostOneKey = (s) => s.refine((v) => Object.keys(v).length <= 1, { message: "Each orderBy element must have at most one key" });
|
|
3077
3077
|
const nextOpts = this.nextOptions(options);
|
|
3078
3078
|
for (const [field, fieldDef] of this.getModelFields(model)) if (fieldDef.relation) {
|
|
3079
|
-
if (withRelation && this.shouldIncludeRelations(options)) fields[field] = z
|
|
3079
|
+
if (withRelation && this.shouldIncludeRelations(options)) fields[field] = z.lazy(() => {
|
|
3080
3080
|
let relationOrderBy = this.makeOrderBySchema(fieldDef.type, withRelation, WithAggregation, nextOpts);
|
|
3081
3081
|
if (fieldDef.array) relationOrderBy = refineAtMostOneKey(relationOrderBy.safeExtend({ _count: sort }));
|
|
3082
3082
|
return relationOrderBy;
|
|
3083
3083
|
}).optional();
|
|
3084
|
-
} else if (fieldDef.computed && fieldDef.params) fields[field] = z
|
|
3084
|
+
} else if (fieldDef.computed && fieldDef.params) fields[field] = z.strictObject({
|
|
3085
3085
|
args: this.makeFieldArgsSchema(fieldDef.params),
|
|
3086
3086
|
sort,
|
|
3087
|
-
nulls: z
|
|
3087
|
+
nulls: z.union([z.literal("first"), z.literal("last")]).optional()
|
|
3088
3088
|
}).optional();
|
|
3089
|
-
else if (fieldDef.optional) fields[field] = z
|
|
3089
|
+
else if (fieldDef.optional) fields[field] = z.union([sort, z.strictObject({
|
|
3090
3090
|
sort,
|
|
3091
|
-
nulls: z
|
|
3091
|
+
nulls: z.union([z.literal("first"), z.literal("last")]).optional()
|
|
3092
3092
|
})]).optional();
|
|
3093
3093
|
else fields[field] = sort.optional();
|
|
3094
3094
|
if (WithAggregation) for (const agg of [
|
|
@@ -3097,31 +3097,31 @@ var ZodSchemaFactory = class {
|
|
|
3097
3097
|
"_sum",
|
|
3098
3098
|
"_min",
|
|
3099
3099
|
"_max"
|
|
3100
|
-
]) fields[agg] = z
|
|
3100
|
+
]) fields[agg] = z.lazy(() => this.makeOrderBySchema(model, true, false, options).optional());
|
|
3101
3101
|
if (this.providerSupportsFuzzySearch) {
|
|
3102
3102
|
const fuzzyFieldNames = this.getModelFields(model).filter(([, def]) => !def.relation && def.type === "String" && def.fuzzy === true).map(([name]) => name);
|
|
3103
|
-
if (fuzzyFieldNames.length > 0) fields["_fuzzyRelevance"] = z
|
|
3104
|
-
fields: z
|
|
3105
|
-
search: z
|
|
3106
|
-
mode: z
|
|
3107
|
-
z
|
|
3108
|
-
z
|
|
3109
|
-
z
|
|
3103
|
+
if (fuzzyFieldNames.length > 0) fields["_fuzzyRelevance"] = z.strictObject({
|
|
3104
|
+
fields: z.array(z.enum(fuzzyFieldNames)).min(1),
|
|
3105
|
+
search: z.string(),
|
|
3106
|
+
mode: z.union([
|
|
3107
|
+
z.literal("simple"),
|
|
3108
|
+
z.literal("word"),
|
|
3109
|
+
z.literal("strictWord")
|
|
3110
3110
|
]).default("simple"),
|
|
3111
|
-
unaccent: z
|
|
3111
|
+
unaccent: z.boolean().default(false),
|
|
3112
3112
|
sort
|
|
3113
3113
|
}).optional();
|
|
3114
3114
|
}
|
|
3115
3115
|
if (this.providerSupportsFullTextSearch) {
|
|
3116
3116
|
const fullTextFieldNames = this.getModelFields(model).filter(([, def]) => !def.relation && def.type === "String" && def.fullText === true).map(([name]) => name);
|
|
3117
|
-
if (fullTextFieldNames.length > 0) fields["_ftsRelevance"] = z
|
|
3118
|
-
fields: z
|
|
3119
|
-
search: z
|
|
3120
|
-
config: z
|
|
3117
|
+
if (fullTextFieldNames.length > 0) fields["_ftsRelevance"] = z.strictObject({
|
|
3118
|
+
fields: z.array(z.enum(fullTextFieldNames)).min(1),
|
|
3119
|
+
search: z.string().min(1),
|
|
3120
|
+
config: z.string().min(1).optional(),
|
|
3121
3121
|
sort
|
|
3122
3122
|
}).optional();
|
|
3123
3123
|
}
|
|
3124
|
-
const schema = refineAtMostOneKey(z
|
|
3124
|
+
const schema = refineAtMostOneKey(z.strictObject(fields));
|
|
3125
3125
|
let schemaId = `${model}OrderBy`;
|
|
3126
3126
|
if (withRelation) schemaId += "WithRelation";
|
|
3127
3127
|
if (WithAggregation) schemaId += "WithAggregation";
|
|
@@ -3131,7 +3131,7 @@ var ZodSchemaFactory = class {
|
|
|
3131
3131
|
}
|
|
3132
3132
|
makeDistinctSchema(model) {
|
|
3133
3133
|
const nonRelationFields = this.getModelFields(model).filter(([, def]) => !def.relation && !this.isParameterizedComputedField(def)).map(([name]) => name);
|
|
3134
|
-
const schema = nonRelationFields.length > 0 ? this.orArray(z
|
|
3134
|
+
const schema = nonRelationFields.length > 0 ? this.orArray(z.enum(nonRelationFields), true) : z.never();
|
|
3135
3135
|
this.registerSchema(`${model}DistinctInput`, schema);
|
|
3136
3136
|
return schema;
|
|
3137
3137
|
}
|
|
@@ -3142,7 +3142,7 @@ var ZodSchemaFactory = class {
|
|
|
3142
3142
|
}
|
|
3143
3143
|
makeCreateSchema(model, options) {
|
|
3144
3144
|
const dataSchema = this.makeCreateDataSchema(model, false, [], false, options);
|
|
3145
|
-
const baseSchema = z
|
|
3145
|
+
const baseSchema = z.strictObject({
|
|
3146
3146
|
data: dataSchema,
|
|
3147
3147
|
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
3148
3148
|
include: this.makeIncludeSchema(model, options).optional().nullable(),
|
|
@@ -3191,7 +3191,7 @@ var ZodSchemaFactory = class {
|
|
|
3191
3191
|
const oppositeFieldDef = requireField(this.schema, fieldDef.type, oppositeField);
|
|
3192
3192
|
if (oppositeFieldDef.relation?.fields) excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
3193
3193
|
}
|
|
3194
|
-
let fieldSchema = z
|
|
3194
|
+
let fieldSchema = z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "create", nextOpts));
|
|
3195
3195
|
if (fieldDef.optional || fieldDef.array) fieldSchema = fieldSchema.optional();
|
|
3196
3196
|
else {
|
|
3197
3197
|
let allFksOptional = false;
|
|
@@ -3208,23 +3208,23 @@ var ZodSchemaFactory = class {
|
|
|
3208
3208
|
let fieldSchema = this.makeScalarSchema(fieldDef.type, fieldDef.attributes);
|
|
3209
3209
|
if (fieldDef.array) {
|
|
3210
3210
|
fieldSchema = ZodUtils.addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
3211
|
-
fieldSchema = z
|
|
3211
|
+
fieldSchema = z.union([fieldSchema, z.strictObject({ set: fieldSchema })]).optional();
|
|
3212
3212
|
}
|
|
3213
3213
|
if (fieldDef.optional || fieldHasDefaultValue(fieldDef)) fieldSchema = fieldSchema.optional();
|
|
3214
|
-
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z
|
|
3214
|
+
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z.union([fieldSchema, z.instanceof(DbNullClass)]);
|
|
3215
3215
|
else if (this.isTypeDefType(fieldDef.type)) fieldSchema = this.makeNullableTypedJsonMutationSchema(fieldSchema);
|
|
3216
3216
|
else fieldSchema = fieldSchema.nullable();
|
|
3217
3217
|
uncheckedVariantFields[field] = fieldSchema;
|
|
3218
3218
|
if (!fieldDef.foreignKeyFor) checkedVariantFields[field] = fieldSchema;
|
|
3219
3219
|
}
|
|
3220
3220
|
});
|
|
3221
|
-
const uncheckedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z
|
|
3222
|
-
const checkedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z
|
|
3223
|
-
const result = !hasRelation ? this.orArray(uncheckedCreateSchema, canBeArray) : z
|
|
3221
|
+
const uncheckedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(uncheckedVariantFields), modelDef.attributes) : z.strictObject(uncheckedVariantFields);
|
|
3222
|
+
const checkedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(checkedVariantFields), modelDef.attributes) : z.strictObject(checkedVariantFields);
|
|
3223
|
+
const result = !hasRelation ? this.orArray(uncheckedCreateSchema, canBeArray) : z.union([
|
|
3224
3224
|
uncheckedCreateSchema,
|
|
3225
3225
|
checkedCreateSchema,
|
|
3226
|
-
...canBeArray ? [z
|
|
3227
|
-
...canBeArray ? [z
|
|
3226
|
+
...canBeArray ? [z.array(uncheckedCreateSchema)] : [],
|
|
3227
|
+
...canBeArray ? [z.array(checkedCreateSchema)] : []
|
|
3228
3228
|
]);
|
|
3229
3229
|
const idParts = [`${model}CreateData`];
|
|
3230
3230
|
if (canBeArray) idParts.push("Array");
|
|
@@ -3249,17 +3249,17 @@ var ZodSchemaFactory = class {
|
|
|
3249
3249
|
fields["disconnect"] = this.makeDisconnectDataSchema(fieldType, array, options).optional();
|
|
3250
3250
|
fields["delete"] = this.makeDeleteRelationDataSchema(fieldType, array, true, options).optional();
|
|
3251
3251
|
}
|
|
3252
|
-
fields["update"] = array ? this.orArray(z
|
|
3252
|
+
fields["update"] = array ? this.orArray(z.strictObject({
|
|
3253
3253
|
where: this.makeWhereSchema(fieldType, true, false, false, options),
|
|
3254
3254
|
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
3255
|
-
}), true).optional() : z
|
|
3255
|
+
}), true).optional() : z.union([z.strictObject({
|
|
3256
3256
|
where: this.makeWhereSchema(fieldType, false, false, false, options).optional(),
|
|
3257
3257
|
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
3258
3258
|
}), this.makeUpdateDataSchema(fieldType, withoutFields, false, options)]).optional();
|
|
3259
3259
|
if (canCreateModel) {
|
|
3260
3260
|
let upsertWhere = this.makeWhereSchema(fieldType, true, false, false, options);
|
|
3261
3261
|
if (!fieldDef.array) upsertWhere = upsertWhere.optional();
|
|
3262
|
-
fields["upsert"] = this.orArray(z
|
|
3262
|
+
fields["upsert"] = this.orArray(z.strictObject({
|
|
3263
3263
|
where: upsertWhere,
|
|
3264
3264
|
create: this.makeCreateDataSchema(fieldType, false, withoutFields, false, options),
|
|
3265
3265
|
update: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
@@ -3267,14 +3267,14 @@ var ZodSchemaFactory = class {
|
|
|
3267
3267
|
}
|
|
3268
3268
|
if (array) {
|
|
3269
3269
|
fields["set"] = this.makeSetDataSchema(fieldType, true, options).optional();
|
|
3270
|
-
fields["updateMany"] = this.orArray(z
|
|
3270
|
+
fields["updateMany"] = this.orArray(z.strictObject({
|
|
3271
3271
|
where: this.makeWhereSchema(fieldType, false, true, false, options),
|
|
3272
3272
|
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
3273
3273
|
}), true).optional();
|
|
3274
3274
|
fields["deleteMany"] = this.makeDeleteRelationDataSchema(fieldType, true, false, options).optional();
|
|
3275
3275
|
}
|
|
3276
3276
|
}
|
|
3277
|
-
return z
|
|
3277
|
+
return z.strictObject(fields);
|
|
3278
3278
|
}
|
|
3279
3279
|
makeSetDataSchema(model, canBeArray, options) {
|
|
3280
3280
|
return this.orArray(this.makeWhereSchema(model, true, false, false, options), canBeArray);
|
|
@@ -3284,23 +3284,23 @@ var ZodSchemaFactory = class {
|
|
|
3284
3284
|
}
|
|
3285
3285
|
makeDisconnectDataSchema(model, canBeArray, options) {
|
|
3286
3286
|
if (canBeArray) return this.orArray(this.makeWhereSchema(model, true, false, false, options), canBeArray);
|
|
3287
|
-
else return z
|
|
3287
|
+
else return z.union([z.boolean(), this.makeWhereSchema(model, false, false, false, options)]);
|
|
3288
3288
|
}
|
|
3289
3289
|
makeDeleteRelationDataSchema(model, toManyRelation, uniqueFilter, options) {
|
|
3290
|
-
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter, false, false, options), true) : z
|
|
3290
|
+
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter, false, false, options), true) : z.union([z.boolean(), this.makeWhereSchema(model, uniqueFilter, false, false, options)]);
|
|
3291
3291
|
}
|
|
3292
3292
|
makeConnectOrCreateDataSchema(model, canBeArray, withoutFields, options) {
|
|
3293
3293
|
const whereSchema = this.makeWhereSchema(model, true, false, false, options);
|
|
3294
3294
|
const createSchema = this.makeCreateDataSchema(model, false, withoutFields, false, options);
|
|
3295
|
-
return this.orArray(z
|
|
3295
|
+
return this.orArray(z.strictObject({
|
|
3296
3296
|
where: whereSchema,
|
|
3297
3297
|
create: createSchema
|
|
3298
3298
|
}), canBeArray);
|
|
3299
3299
|
}
|
|
3300
3300
|
makeCreateManyPayloadSchema(model, withoutFields, options) {
|
|
3301
|
-
const schema = z
|
|
3301
|
+
const schema = z.strictObject({
|
|
3302
3302
|
data: this.makeCreateDataSchema(model, true, withoutFields, true, options),
|
|
3303
|
-
skipDuplicates: z
|
|
3303
|
+
skipDuplicates: z.boolean().optional()
|
|
3304
3304
|
});
|
|
3305
3305
|
const idParts = [`${model}CreateManyPayload`];
|
|
3306
3306
|
if (withoutFields.length) idParts.push(`Without${withoutFields.slice().sort().join("")}`);
|
|
@@ -3308,7 +3308,7 @@ var ZodSchemaFactory = class {
|
|
|
3308
3308
|
return schema;
|
|
3309
3309
|
}
|
|
3310
3310
|
makeUpdateSchema(model, options) {
|
|
3311
|
-
const baseSchema = z
|
|
3311
|
+
const baseSchema = z.strictObject({
|
|
3312
3312
|
where: this.makeWhereSchema(model, true, false, false, options),
|
|
3313
3313
|
data: this.makeUpdateDataSchema(model, [], false, options),
|
|
3314
3314
|
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
@@ -3323,10 +3323,10 @@ var ZodSchemaFactory = class {
|
|
|
3323
3323
|
return schema;
|
|
3324
3324
|
}
|
|
3325
3325
|
makeUpdateManySchema(model, options) {
|
|
3326
|
-
const result = this.mergePluginArgsSchema(z
|
|
3326
|
+
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3327
3327
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3328
3328
|
data: this.makeUpdateDataSchema(model, [], true, options),
|
|
3329
|
-
limit: z
|
|
3329
|
+
limit: z.number().int().nonnegative().optional()
|
|
3330
3330
|
}), "updateMany");
|
|
3331
3331
|
this.registerSchema(`${model}UpdateManyArgs`, result);
|
|
3332
3332
|
return result;
|
|
@@ -3342,7 +3342,7 @@ var ZodSchemaFactory = class {
|
|
|
3342
3342
|
return schema;
|
|
3343
3343
|
}
|
|
3344
3344
|
makeUpsertSchema(model, options) {
|
|
3345
|
-
const baseSchema = z
|
|
3345
|
+
const baseSchema = z.strictObject({
|
|
3346
3346
|
where: this.makeWhereSchema(model, true, false, false, options),
|
|
3347
3347
|
create: this.makeCreateDataSchema(model, false, [], false, options),
|
|
3348
3348
|
update: this.makeUpdateDataSchema(model, [], false, options),
|
|
@@ -3378,27 +3378,27 @@ var ZodSchemaFactory = class {
|
|
|
3378
3378
|
const oppositeFieldDef = requireField(this.schema, fieldDef.type, oppositeField);
|
|
3379
3379
|
if (oppositeFieldDef.relation?.fields) excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
3380
3380
|
}
|
|
3381
|
-
let fieldSchema = z
|
|
3381
|
+
let fieldSchema = z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "update", nextOpts)).optional();
|
|
3382
3382
|
if (fieldDef.optional && !fieldDef.array) fieldSchema = fieldSchema.nullable();
|
|
3383
3383
|
checkedVariantFields[field] = fieldSchema;
|
|
3384
3384
|
if (fieldDef.array || !fieldDef.relation.references) uncheckedVariantFields[field] = fieldSchema;
|
|
3385
3385
|
} else {
|
|
3386
3386
|
let fieldSchema = this.makeScalarSchema(fieldDef.type, fieldDef.attributes);
|
|
3387
|
-
if (this.isNumericField(fieldDef)) fieldSchema = z
|
|
3388
|
-
set: this.nullableIf(z
|
|
3389
|
-
increment: z
|
|
3390
|
-
decrement: z
|
|
3391
|
-
multiply: z
|
|
3392
|
-
divide: z
|
|
3387
|
+
if (this.isNumericField(fieldDef)) fieldSchema = z.union([fieldSchema, z.object({
|
|
3388
|
+
set: this.nullableIf(z.number().optional(), !!fieldDef.optional).optional(),
|
|
3389
|
+
increment: z.number().optional(),
|
|
3390
|
+
decrement: z.number().optional(),
|
|
3391
|
+
multiply: z.number().optional(),
|
|
3392
|
+
divide: z.number().optional()
|
|
3393
3393
|
}).refine((v) => Object.keys(v).length === 1, "Only one of \"set\", \"increment\", \"decrement\", \"multiply\", or \"divide\" can be provided")]);
|
|
3394
3394
|
if (fieldDef.array) {
|
|
3395
3395
|
const arraySchema = ZodUtils.addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
3396
|
-
fieldSchema = z
|
|
3396
|
+
fieldSchema = z.union([arraySchema, z.object({
|
|
3397
3397
|
set: arraySchema.optional(),
|
|
3398
|
-
push: z
|
|
3398
|
+
push: z.union([fieldSchema, fieldSchema.array()]).optional()
|
|
3399
3399
|
}).refine((v) => Object.keys(v).length === 1, "Only one of \"set\", \"push\" can be provided")]);
|
|
3400
3400
|
}
|
|
3401
|
-
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z
|
|
3401
|
+
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z.union([fieldSchema, z.instanceof(DbNullClass)]);
|
|
3402
3402
|
else if (this.isTypeDefType(fieldDef.type)) fieldSchema = this.makeNullableTypedJsonMutationSchema(fieldSchema);
|
|
3403
3403
|
else fieldSchema = fieldSchema.nullable();
|
|
3404
3404
|
fieldSchema = fieldSchema.optional();
|
|
@@ -3406,9 +3406,9 @@ var ZodSchemaFactory = class {
|
|
|
3406
3406
|
if (!fieldDef.foreignKeyFor) checkedVariantFields[field] = fieldSchema;
|
|
3407
3407
|
}
|
|
3408
3408
|
});
|
|
3409
|
-
const uncheckedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z
|
|
3410
|
-
const checkedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z
|
|
3411
|
-
const result = !hasRelation ? uncheckedUpdateSchema : z
|
|
3409
|
+
const uncheckedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(uncheckedVariantFields), modelDef.attributes) : z.strictObject(uncheckedVariantFields);
|
|
3410
|
+
const checkedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(checkedVariantFields), modelDef.attributes) : z.strictObject(checkedVariantFields);
|
|
3411
|
+
const result = !hasRelation ? uncheckedUpdateSchema : z.union([uncheckedUpdateSchema, checkedUpdateSchema]);
|
|
3412
3412
|
const idParts = [`${model}UpdateData`];
|
|
3413
3413
|
if (withoutRelationFields) idParts.push("WithoutRelation");
|
|
3414
3414
|
if (withoutFields.length) idParts.push(`Without${withoutFields.slice().sort().join("")}`);
|
|
@@ -3416,7 +3416,7 @@ var ZodSchemaFactory = class {
|
|
|
3416
3416
|
return result;
|
|
3417
3417
|
}
|
|
3418
3418
|
makeDeleteSchema(model, options) {
|
|
3419
|
-
const baseSchema = z
|
|
3419
|
+
const baseSchema = z.strictObject({
|
|
3420
3420
|
where: this.makeWhereSchema(model, true, false, false, options),
|
|
3421
3421
|
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
3422
3422
|
include: this.makeIncludeSchema(model, options).optional().nullable(),
|
|
@@ -3430,15 +3430,15 @@ var ZodSchemaFactory = class {
|
|
|
3430
3430
|
return schema;
|
|
3431
3431
|
}
|
|
3432
3432
|
makeDeleteManySchema(model, options) {
|
|
3433
|
-
const result = this.mergePluginArgsSchema(z
|
|
3433
|
+
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3434
3434
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3435
|
-
limit: z
|
|
3435
|
+
limit: z.number().int().nonnegative().optional()
|
|
3436
3436
|
}), "deleteMany").optional();
|
|
3437
3437
|
this.registerSchema(`${model}DeleteManyArgs`, result);
|
|
3438
3438
|
return result;
|
|
3439
3439
|
}
|
|
3440
3440
|
makeCountSchema(model, options) {
|
|
3441
|
-
const result = this.mergePluginArgsSchema(z
|
|
3441
|
+
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3442
3442
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3443
3443
|
skip: this.makeSkipSchema().optional(),
|
|
3444
3444
|
take: this.makeTakeSchema().optional(),
|
|
@@ -3449,10 +3449,10 @@ var ZodSchemaFactory = class {
|
|
|
3449
3449
|
return result;
|
|
3450
3450
|
}
|
|
3451
3451
|
makeCountAggregateInputSchema(model) {
|
|
3452
|
-
const schema = z
|
|
3453
|
-
_all: z
|
|
3452
|
+
const schema = z.union([z.literal(true), z.strictObject({
|
|
3453
|
+
_all: z.literal(true).optional(),
|
|
3454
3454
|
...this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
|
|
3455
|
-
acc[field] = this.isParameterizedComputedField(fieldDef) ? z
|
|
3455
|
+
acc[field] = this.isParameterizedComputedField(fieldDef) ? z.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional() : z.literal(true).optional();
|
|
3456
3456
|
return acc;
|
|
3457
3457
|
}, {})
|
|
3458
3458
|
})]);
|
|
@@ -3460,7 +3460,7 @@ var ZodSchemaFactory = class {
|
|
|
3460
3460
|
return schema;
|
|
3461
3461
|
}
|
|
3462
3462
|
makeAggregateSchema(model, options) {
|
|
3463
|
-
const result = this.mergePluginArgsSchema(z
|
|
3463
|
+
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3464
3464
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3465
3465
|
skip: this.makeSkipSchema().optional(),
|
|
3466
3466
|
take: this.makeTakeSchema().optional(),
|
|
@@ -3475,16 +3475,16 @@ var ZodSchemaFactory = class {
|
|
|
3475
3475
|
return result;
|
|
3476
3476
|
}
|
|
3477
3477
|
makeSumAvgInputSchema(model) {
|
|
3478
|
-
const schema = z
|
|
3479
|
-
if (this.isNumericField(fieldDef)) acc[field] = this.isParameterizedComputedField(fieldDef) ? z
|
|
3478
|
+
const schema = z.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
|
|
3479
|
+
if (this.isNumericField(fieldDef)) acc[field] = this.isParameterizedComputedField(fieldDef) ? z.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional() : z.literal(true).optional();
|
|
3480
3480
|
return acc;
|
|
3481
3481
|
}, {}));
|
|
3482
3482
|
this.registerSchema(`${model}SumAvgAggregateInput`, schema);
|
|
3483
3483
|
return schema;
|
|
3484
3484
|
}
|
|
3485
3485
|
makeMinMaxInputSchema(model) {
|
|
3486
|
-
const schema = z
|
|
3487
|
-
if (!fieldDef.relation && !fieldDef.array) acc[field] = this.isParameterizedComputedField(fieldDef) ? z
|
|
3486
|
+
const schema = z.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
|
|
3487
|
+
if (!fieldDef.relation && !fieldDef.array) acc[field] = this.isParameterizedComputedField(fieldDef) ? z.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional() : z.literal(true).optional();
|
|
3488
3488
|
return acc;
|
|
3489
3489
|
}, {}));
|
|
3490
3490
|
this.registerSchema(`${model}MinMaxAggregateInput`, schema);
|
|
@@ -3493,14 +3493,14 @@ var ZodSchemaFactory = class {
|
|
|
3493
3493
|
makeGroupBySchema(model, options) {
|
|
3494
3494
|
const nonRelationFields = this.getModelFields(model).filter(([, def]) => !def.relation && !this.isParameterizedComputedField(def)).map(([name]) => name);
|
|
3495
3495
|
const byMembers = [];
|
|
3496
|
-
if (nonRelationFields.length > 0) byMembers.push(z
|
|
3497
|
-
for (const [field, fieldDef] of this.getModelFields(model)) if (this.isParameterizedComputedField(fieldDef)) byMembers.push(z
|
|
3498
|
-
field: z
|
|
3496
|
+
if (nonRelationFields.length > 0) byMembers.push(z.enum(nonRelationFields));
|
|
3497
|
+
for (const [field, fieldDef] of this.getModelFields(model)) if (this.isParameterizedComputedField(fieldDef)) byMembers.push(z.strictObject({
|
|
3498
|
+
field: z.literal(field),
|
|
3499
3499
|
args: this.makeFieldArgsSchema(fieldDef.params)
|
|
3500
3500
|
}));
|
|
3501
|
-
const byElement = byMembers.length === 0 ? void 0 : byMembers.length === 1 ? byMembers[0] : z
|
|
3502
|
-
const bySchema = byElement ? this.orArray(byElement, true) : z
|
|
3503
|
-
const baseSchema = z
|
|
3501
|
+
const byElement = byMembers.length === 0 ? void 0 : byMembers.length === 1 ? byMembers[0] : z.union(byMembers);
|
|
3502
|
+
const bySchema = byElement ? this.orArray(byElement, true) : z.never();
|
|
3503
|
+
const baseSchema = z.strictObject({
|
|
3504
3504
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3505
3505
|
orderBy: this.orArray(this.makeOrderBySchema(model, false, true, options), true).optional(),
|
|
3506
3506
|
by: bySchema,
|
|
@@ -3552,7 +3552,7 @@ var ZodSchemaFactory = class {
|
|
|
3552
3552
|
if (!procDef) throw createInternalError(`Procedure not found: ${procName}`);
|
|
3553
3553
|
const shape = {};
|
|
3554
3554
|
for (const param of Object.values(procDef.params ?? {})) shape[param.name] = this.makeProcedureParamSchema(param);
|
|
3555
|
-
const schema = z
|
|
3555
|
+
const schema = z.object(shape);
|
|
3556
3556
|
this.registerSchema(`${procName}ProcArgs`, schema);
|
|
3557
3557
|
return schema;
|
|
3558
3558
|
}
|
|
@@ -3560,10 +3560,10 @@ var ZodSchemaFactory = class {
|
|
|
3560
3560
|
let schema;
|
|
3561
3561
|
if (isTypeDef(this.schema, param.type)) schema = this.makeTypeDefSchema(param.type);
|
|
3562
3562
|
else if (isEnum(this.schema, param.type)) schema = this.makeEnumSchema(param.type);
|
|
3563
|
-
else if (param.type in (this.schema.models ?? {})) schema = z
|
|
3563
|
+
else if (param.type in (this.schema.models ?? {})) schema = z.record(z.string(), z.unknown());
|
|
3564
3564
|
else {
|
|
3565
3565
|
schema = this.makeScalarSchema(param.type);
|
|
3566
|
-
if (schema instanceof z
|
|
3566
|
+
if (schema instanceof z.ZodUnknown) throw createInternalError(`Unsupported procedure parameter type: ${param.type}`);
|
|
3567
3567
|
}
|
|
3568
3568
|
if (param.array) schema = schema.array();
|
|
3569
3569
|
if (param.optional) schema = schema.optional();
|
|
@@ -3599,10 +3599,10 @@ var ZodSchemaFactory = class {
|
|
|
3599
3599
|
return result;
|
|
3600
3600
|
}
|
|
3601
3601
|
makeSkipSchema() {
|
|
3602
|
-
return z
|
|
3602
|
+
return z.number().int().nonnegative();
|
|
3603
3603
|
}
|
|
3604
3604
|
makeTakeSchema() {
|
|
3605
|
-
return z
|
|
3605
|
+
return z.number().int();
|
|
3606
3606
|
}
|
|
3607
3607
|
refineForSelectIncludeMutuallyExclusive(schema) {
|
|
3608
3608
|
return schema.refine((value) => !(value["select"] && value["include"]), "\"select\" and \"include\" cannot be used together");
|
|
@@ -3621,7 +3621,7 @@ var ZodSchemaFactory = class {
|
|
|
3621
3621
|
return nullable ? schema.nullable() : schema;
|
|
3622
3622
|
}
|
|
3623
3623
|
orArray(schema, canBeArray) {
|
|
3624
|
-
return canBeArray ? z
|
|
3624
|
+
return canBeArray ? z.union([schema, z.array(schema)]) : schema;
|
|
3625
3625
|
}
|
|
3626
3626
|
isNumericField(fieldDef) {
|
|
3627
3627
|
return NUMERIC_FIELD_TYPES.includes(fieldDef.type) && !fieldDef.array;
|
|
@@ -3683,10 +3683,10 @@ var ZodSchemaFactory = class {
|
|
|
3683
3683
|
createUnionFilterSchema(valueSchema, optional, components, allowedFilterKinds) {
|
|
3684
3684
|
if (Object.keys(components).length === 0) {
|
|
3685
3685
|
if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return this.nullableIf(valueSchema, optional);
|
|
3686
|
-
return z
|
|
3686
|
+
return z.never();
|
|
3687
3687
|
}
|
|
3688
|
-
if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return z
|
|
3689
|
-
else return z
|
|
3688
|
+
if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return z.union([this.nullableIf(valueSchema, optional), z.strictObject(components)]);
|
|
3689
|
+
else return z.strictObject(components);
|
|
3690
3690
|
}
|
|
3691
3691
|
canCreateModel(model) {
|
|
3692
3692
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -7324,9 +7324,9 @@ var ClientImpl = class ClientImpl {
|
|
|
7324
7324
|
validateOptions(baseClient, options) {
|
|
7325
7325
|
if (!baseClient && !options.skipValidationForComputedFields) this.validateComputedFieldsConfig(options);
|
|
7326
7326
|
if (options.diagnostics) {
|
|
7327
|
-
const parseResult = z.object({
|
|
7328
|
-
slowQueryThresholdMs: z.number().nonnegative().optional(),
|
|
7329
|
-
slowQueryMaxRecords: z.int().nonnegative().or(z.literal(Infinity)).optional()
|
|
7327
|
+
const parseResult = z$1.object({
|
|
7328
|
+
slowQueryThresholdMs: z$1.number().nonnegative().optional(),
|
|
7329
|
+
slowQueryMaxRecords: z$1.int().nonnegative().or(z$1.literal(Infinity)).optional()
|
|
7330
7330
|
}).safeParse(options.diagnostics);
|
|
7331
7331
|
if (!parseResult.success) throw createConfigError(`Invalid diagnostics configuration: ${formatError(parseResult.error)}`);
|
|
7332
7332
|
}
|