@zenstackhq/orm 3.9.6 → 3.9.7
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 +37 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -2
- package/dist/index.d.mts +13 -4
- package/dist/index.mjs +236 -202
- 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, RawNode, ReferenceNode, ReturningNode, SelectAllNode, SelectionNode, SingleConnectionProvider, TableNode, Transaction, UpdateQueryNode, ValueListNode, ValueNode, ValuesNode, WhereNode, createQueryId, expressionBuilder, sql } from "kysely";
|
|
5
|
-
import z
|
|
5
|
+
import z, { ZodObject, ZodType, z as z$1 } 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";
|
|
@@ -1265,13 +1265,14 @@ var BaseCrudDialect = class {
|
|
|
1265
1265
|
const fieldRefs = value.fields.map((f) => buildFieldRef(model, f, modelAlias));
|
|
1266
1266
|
return this.buildFtsRelevanceOrderBy(query, fieldRefs, value.search, config, this.negateSort(value.sort, negated));
|
|
1267
1267
|
}
|
|
1268
|
-
buildSelectAllFields(model, query, omit, modelAlias) {
|
|
1268
|
+
buildSelectAllFields(model, query, omit, modelAlias, options) {
|
|
1269
1269
|
let result = query;
|
|
1270
|
+
const applyOmit = options?.applyOmit ?? true;
|
|
1270
1271
|
for (const fieldDef of getModelFields(this.schema, model, {
|
|
1271
1272
|
inherited: true,
|
|
1272
1273
|
computed: true
|
|
1273
1274
|
})) {
|
|
1274
|
-
if (this.shouldOmitField(omit, model, fieldDef.name)) continue;
|
|
1275
|
+
if (applyOmit && this.shouldOmitField(omit, model, fieldDef.name)) continue;
|
|
1275
1276
|
if (fieldDef.computed && fieldDef.params) continue;
|
|
1276
1277
|
result = this.buildSelectField(result, model, modelAlias, fieldDef.name);
|
|
1277
1278
|
}
|
|
@@ -1299,7 +1300,7 @@ var BaseCrudDialect = class {
|
|
|
1299
1300
|
}
|
|
1300
1301
|
buildModelSelect(model, subQueryAlias, payload, selectAllFields) {
|
|
1301
1302
|
let subQuery = this.buildSelectModel(model, subQueryAlias);
|
|
1302
|
-
if (selectAllFields) subQuery = this.buildSelectAllFields(model, subQuery,
|
|
1303
|
+
if (selectAllFields) subQuery = this.buildSelectAllFields(model, subQuery, void 0, subQueryAlias, { applyOmit: false });
|
|
1303
1304
|
if (payload && typeof payload === "object") subQuery = this.buildFilterSortTake(model, payload, subQuery, subQueryAlias);
|
|
1304
1305
|
return subQuery;
|
|
1305
1306
|
}
|
|
@@ -1998,12 +1999,45 @@ var PostgresCrudDialect = class PostgresCrudDialect extends LateralJoinDialectBa
|
|
|
1998
1999
|
buildComparison(left, leftFieldDef, op, right, rightFieldDef) {
|
|
1999
2000
|
const leftResolved = this.resolveFieldSqlType(leftFieldDef);
|
|
2000
2001
|
const rightResolved = this.resolveFieldSqlType(rightFieldDef);
|
|
2002
|
+
const valueResult = this.tryBuildNativeTypeValueComparison(left, leftResolved, op, right, rightResolved);
|
|
2003
|
+
if (valueResult) return valueResult;
|
|
2001
2004
|
if (leftResolved.sqlType !== rightResolved.sqlType && (leftResolved.hasDbOverride || rightResolved.hasDbOverride)) {
|
|
2002
2005
|
if (leftResolved.hasDbOverride) left = this.eb.cast(left, sql.raw(this.getSqlType(leftFieldDef.type)));
|
|
2003
2006
|
if (rightResolved.hasDbOverride) right = this.eb.cast(right, sql.raw(this.getSqlType(rightFieldDef.type)));
|
|
2004
2007
|
}
|
|
2005
2008
|
return super.buildComparison(left, leftFieldDef, op, right, rightFieldDef);
|
|
2006
2009
|
}
|
|
2010
|
+
static textLikeSqlTypes = new Set([
|
|
2011
|
+
"text",
|
|
2012
|
+
"varchar",
|
|
2013
|
+
"bpchar",
|
|
2014
|
+
"citext"
|
|
2015
|
+
]);
|
|
2016
|
+
static uuidFormatRegex = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|[0-9a-f]{32})$/i;
|
|
2017
|
+
tryBuildNativeTypeValueComparison(left, leftResolved, op, right, rightResolved) {
|
|
2018
|
+
let valueNode;
|
|
2019
|
+
let columnResolved;
|
|
2020
|
+
const leftNode = left.toOperationNode();
|
|
2021
|
+
const rightNode = right.toOperationNode();
|
|
2022
|
+
if (ValueNode.is(rightNode) && !ValueNode.is(leftNode)) {
|
|
2023
|
+
valueNode = rightNode;
|
|
2024
|
+
columnResolved = leftResolved;
|
|
2025
|
+
} else if (ValueNode.is(leftNode) && !ValueNode.is(rightNode)) {
|
|
2026
|
+
valueNode = leftNode;
|
|
2027
|
+
columnResolved = rightResolved;
|
|
2028
|
+
} else return;
|
|
2029
|
+
if (!columnResolved.hasDbOverride || !columnResolved.sqlType) return;
|
|
2030
|
+
if (PostgresCrudDialect.textLikeSqlTypes.has(columnResolved.sqlType)) return this.eb(left, op, right);
|
|
2031
|
+
if (columnResolved.sqlType === "uuid" && (op === "=" || op === "!=")) {
|
|
2032
|
+
const value = valueNode.value;
|
|
2033
|
+
if (typeof value === "string" && PostgresCrudDialect.uuidFormatRegex.test(value)) return this.eb(left, op, right);
|
|
2034
|
+
else if (op === "=") return this.eb.lit(false);
|
|
2035
|
+
else {
|
|
2036
|
+
const column = valueNode === rightNode ? left : right;
|
|
2037
|
+
return this.eb(column, "is not", null);
|
|
2038
|
+
}
|
|
2039
|
+
}
|
|
2040
|
+
}
|
|
2007
2041
|
getStringCasingBehavior() {
|
|
2008
2042
|
return {
|
|
2009
2043
|
supportsILike: true,
|
|
@@ -2399,7 +2433,7 @@ function createQuerySchemaFactory(clientOrSchema, options) {
|
|
|
2399
2433
|
* @see https://github.com/zenstackhq/zenstack/issues/2631
|
|
2400
2434
|
*/
|
|
2401
2435
|
function coercedDateTimeSchema() {
|
|
2402
|
-
return z.preprocess((val) => {
|
|
2436
|
+
return z$1.preprocess((val) => {
|
|
2403
2437
|
if (typeof val !== "string") return val;
|
|
2404
2438
|
if (/^\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d\d(?::\d\d)?)?$/.test(val)) {
|
|
2405
2439
|
const hasTz = val.endsWith("Z") || /[+-]\d\d(?::\d\d)?$/.test(val);
|
|
@@ -2408,10 +2442,10 @@ function coercedDateTimeSchema() {
|
|
|
2408
2442
|
}
|
|
2409
2443
|
const d = new Date(val);
|
|
2410
2444
|
return isNaN(d.getTime()) ? val : d;
|
|
2411
|
-
}, z.union([
|
|
2412
|
-
z.iso.datetime(),
|
|
2413
|
-
z.iso.date(),
|
|
2414
|
-
z.date()
|
|
2445
|
+
}, z$1.union([
|
|
2446
|
+
z$1.iso.datetime(),
|
|
2447
|
+
z$1.iso.date(),
|
|
2448
|
+
z$1.date()
|
|
2415
2449
|
]));
|
|
2416
2450
|
}
|
|
2417
2451
|
/**
|
|
@@ -2419,7 +2453,7 @@ function coercedDateTimeSchema() {
|
|
|
2419
2453
|
*/
|
|
2420
2454
|
var ZodSchemaFactory = class {
|
|
2421
2455
|
schemaCache = /* @__PURE__ */ new Map();
|
|
2422
|
-
schemaRegistry = z.registry();
|
|
2456
|
+
schemaRegistry = z$1.registry();
|
|
2423
2457
|
allFilterKinds = [...new Set(Object.values(FILTER_PROPERTY_TO_KIND))];
|
|
2424
2458
|
schema;
|
|
2425
2459
|
options;
|
|
@@ -2511,7 +2545,7 @@ var ZodSchemaFactory = class {
|
|
|
2511
2545
|
this.makeGroupBySchema(m);
|
|
2512
2546
|
}
|
|
2513
2547
|
for (const procName of Object.keys(this.schema.procedures ?? {})) if (this.isProcedureAllowed(procName)) this.makeProcedureArgsSchema(procName);
|
|
2514
|
-
return z.toJSONSchema(this.schemaRegistry, { unrepresentable: "any" });
|
|
2548
|
+
return z$1.toJSONSchema(this.schemaRegistry, { unrepresentable: "any" });
|
|
2515
2549
|
}
|
|
2516
2550
|
get cacheStats() {
|
|
2517
2551
|
return {
|
|
@@ -2540,13 +2574,13 @@ var ZodSchemaFactory = class {
|
|
|
2540
2574
|
fields["omit"] = this.makeOmitSchema(model).optional().nullable();
|
|
2541
2575
|
if (!unique) {
|
|
2542
2576
|
fields["skip"] = this.makeSkipSchema().optional();
|
|
2543
|
-
if (findOne) fields["take"] = z.literal(1).optional();
|
|
2577
|
+
if (findOne) fields["take"] = z$1.literal(1).optional();
|
|
2544
2578
|
else fields["take"] = this.makeTakeSchema().optional();
|
|
2545
2579
|
fields["orderBy"] = this.orArray(this.makeOrderBySchema(model, true, false, options), true).optional();
|
|
2546
2580
|
fields["cursor"] = this.makeCursorSchema(model, options).optional();
|
|
2547
2581
|
fields["distinct"] = this.makeDistinctSchema(model).optional();
|
|
2548
2582
|
}
|
|
2549
|
-
const baseSchema = z.strictObject(fields);
|
|
2583
|
+
const baseSchema = z$1.strictObject(fields);
|
|
2550
2584
|
let result = this.mergePluginArgsSchema(baseSchema, operation);
|
|
2551
2585
|
result = this.refineForSelectIncludeMutuallyExclusive(result);
|
|
2552
2586
|
result = this.refineForSelectOmitMutuallyExclusive(result);
|
|
@@ -2556,7 +2590,7 @@ var ZodSchemaFactory = class {
|
|
|
2556
2590
|
return result;
|
|
2557
2591
|
}
|
|
2558
2592
|
makeExistsSchema(model, options) {
|
|
2559
|
-
const baseSchema = z.strictObject({ where: this.makeWhereSchema(model, false, false, false, options).optional() });
|
|
2593
|
+
const baseSchema = z$1.strictObject({ where: this.makeWhereSchema(model, false, false, false, options).optional() });
|
|
2560
2594
|
const result = this.mergePluginArgsSchema(baseSchema, "exists").optional();
|
|
2561
2595
|
this.registerSchema(`${model}ExistsArgs`, result);
|
|
2562
2596
|
return result;
|
|
@@ -2564,19 +2598,19 @@ var ZodSchemaFactory = class {
|
|
|
2564
2598
|
makeScalarSchema(type, attributes) {
|
|
2565
2599
|
if (this.schema.typeDefs && type in this.schema.typeDefs) return this.makeTypeDefSchema(type);
|
|
2566
2600
|
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.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)
|
|
2601
|
+
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", () => {
|
|
2602
|
+
return z$1.union([
|
|
2603
|
+
this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z$1.number(), attributes) : z$1.number(),
|
|
2604
|
+
ZodUtils.addDecimalValidation(z$1.instanceof(Decimal), attributes, this.extraValidationsEnabled),
|
|
2605
|
+
ZodUtils.addDecimalValidation(z$1.string(), attributes, this.extraValidationsEnabled)
|
|
2572
2606
|
]);
|
|
2573
|
-
}).with("DateTime", () => this.makeDateTimeValueSchema()).with("Bytes", () => z.instanceof(Uint8Array)).with("Json", () => this.makeJsonValueSchema()).otherwise(() => z.unknown());
|
|
2607
|
+
}).with("DateTime", () => this.makeDateTimeValueSchema()).with("Bytes", () => z$1.instanceof(Uint8Array)).with("Json", () => this.makeJsonValueSchema()).otherwise(() => z$1.unknown());
|
|
2574
2608
|
}
|
|
2575
2609
|
isParameterizedComputedField(fieldDef) {
|
|
2576
2610
|
return !!(fieldDef.computed && fieldDef.params);
|
|
2577
2611
|
}
|
|
2578
2612
|
makeFieldArgsSchema(params) {
|
|
2579
|
-
return z.strictObject(Object.fromEntries(Object.entries(params).map(([name, param]) => {
|
|
2613
|
+
return z$1.strictObject(Object.fromEntries(Object.entries(params).map(([name, param]) => {
|
|
2580
2614
|
let paramSchema = this.makeScalarSchema(param.type);
|
|
2581
2615
|
if (param.array) paramSchema = paramSchema.array();
|
|
2582
2616
|
if (param.optional) paramSchema = paramSchema.optional();
|
|
@@ -2584,9 +2618,9 @@ var ZodSchemaFactory = class {
|
|
|
2584
2618
|
})));
|
|
2585
2619
|
}
|
|
2586
2620
|
addComputedArgsToFilter(filterSchema, params) {
|
|
2587
|
-
const objectMembers = (filterSchema instanceof z.ZodUnion ? filterSchema.options : [filterSchema]).filter((m) => m instanceof z.ZodObject);
|
|
2621
|
+
const objectMembers = (filterSchema instanceof z$1.ZodUnion ? filterSchema.options : [filterSchema]).filter((m) => m instanceof z$1.ZodObject);
|
|
2588
2622
|
const components = Object.assign({}, ...objectMembers.map((o) => o.shape));
|
|
2589
|
-
return z.strictObject({
|
|
2623
|
+
return z$1.strictObject({
|
|
2590
2624
|
args: this.makeFieldArgsSchema(params),
|
|
2591
2625
|
...components
|
|
2592
2626
|
});
|
|
@@ -2594,20 +2628,20 @@ var ZodSchemaFactory = class {
|
|
|
2594
2628
|
makeEnumSchema(_enum) {
|
|
2595
2629
|
const enumDef = getEnum(this.schema, _enum);
|
|
2596
2630
|
invariant(enumDef, `Enum "${_enum}" not found in schema`);
|
|
2597
|
-
const schema = z.enum(Object.keys(enumDef.values));
|
|
2631
|
+
const schema = z$1.enum(Object.keys(enumDef.values));
|
|
2598
2632
|
this.registerSchema(_enum, schema);
|
|
2599
2633
|
return schema;
|
|
2600
2634
|
}
|
|
2601
2635
|
makeTypeDefSchema(type) {
|
|
2602
2636
|
const typeDef = getTypeDef(this.schema, type);
|
|
2603
2637
|
invariant(typeDef, `Type definition "${type}" not found in schema`);
|
|
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);
|
|
2638
|
+
const schema = (typeDef.strict ? z$1.strictObject : z$1.looseObject)(Object.fromEntries(Object.entries(typeDef.fields).map(([field, def]) => {
|
|
2639
|
+
let fieldSchema = isTypeDef(this.schema, def.type) ? z$1.lazy(() => this.makeTypeDefSchema(def.type)) : this.makeScalarSchema(def.type);
|
|
2606
2640
|
if (def.array) fieldSchema = fieldSchema.array();
|
|
2607
2641
|
if (def.optional) fieldSchema = fieldSchema.nullish();
|
|
2608
2642
|
return [field, fieldSchema];
|
|
2609
2643
|
})));
|
|
2610
|
-
const finalSchema = z.any().superRefine((value, ctx) => {
|
|
2644
|
+
const finalSchema = z$1.any().superRefine((value, ctx) => {
|
|
2611
2645
|
const parseResult = schema.safeParse(value);
|
|
2612
2646
|
if (!parseResult.success) parseResult.error.issues.forEach((issue) => ctx.addIssue(issue));
|
|
2613
2647
|
});
|
|
@@ -2623,17 +2657,17 @@ var ZodSchemaFactory = class {
|
|
|
2623
2657
|
if (fieldDef.relation) {
|
|
2624
2658
|
if (withoutRelationFields || !this.shouldIncludeRelations(options)) continue;
|
|
2625
2659
|
const allowedFilterKinds = this.getEffectiveFilterKinds(model, field);
|
|
2626
|
-
if (allowedFilterKinds && !allowedFilterKinds.includes("Relation")) fieldSchema = z.never();
|
|
2660
|
+
if (allowedFilterKinds && !allowedFilterKinds.includes("Relation")) fieldSchema = z$1.never();
|
|
2627
2661
|
else {
|
|
2628
|
-
fieldSchema = z.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts).optional());
|
|
2629
|
-
if (fieldDef.array) fieldSchema = z.strictObject({
|
|
2662
|
+
fieldSchema = z$1.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts).optional());
|
|
2663
|
+
if (fieldDef.array) fieldSchema = z$1.strictObject({
|
|
2630
2664
|
some: fieldSchema.optional(),
|
|
2631
2665
|
every: fieldSchema.optional(),
|
|
2632
2666
|
none: fieldSchema.optional()
|
|
2633
2667
|
});
|
|
2634
2668
|
else {
|
|
2635
2669
|
fieldSchema = this.nullableIf(fieldSchema, !fieldDef.array && !!fieldDef.optional);
|
|
2636
|
-
fieldSchema = z.union([fieldSchema, z.strictObject({
|
|
2670
|
+
fieldSchema = z$1.union([fieldSchema, z$1.strictObject({
|
|
2637
2671
|
is: fieldSchema.optional(),
|
|
2638
2672
|
isNot: fieldSchema.optional()
|
|
2639
2673
|
})]);
|
|
@@ -2653,21 +2687,21 @@ var ZodSchemaFactory = class {
|
|
|
2653
2687
|
}
|
|
2654
2688
|
if (unique) {
|
|
2655
2689
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
2656
|
-
for (const uniqueField of uniqueFields) if ("defs" in uniqueField) fields[uniqueField.name] = z.object(Object.fromEntries(Object.entries(uniqueField.defs).map(([key, def]) => {
|
|
2690
|
+
for (const uniqueField of uniqueFields) if ("defs" in uniqueField) fields[uniqueField.name] = z$1.object(Object.fromEntries(Object.entries(uniqueField.defs).map(([key, def]) => {
|
|
2657
2691
|
invariant(!def.relation, "unique field cannot be a relation");
|
|
2658
2692
|
let fieldSchema;
|
|
2659
2693
|
const enumDef = getEnum(this.schema, def.type);
|
|
2660
2694
|
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.never();
|
|
2695
|
+
else fieldSchema = z$1.never();
|
|
2662
2696
|
else fieldSchema = this.makePrimitiveFilterSchema(def.type, !!def.optional, false, void 0);
|
|
2663
2697
|
return [key, fieldSchema];
|
|
2664
2698
|
}))).optional();
|
|
2665
2699
|
}
|
|
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);
|
|
2700
|
+
fields["$expr"] = z$1.custom((v) => typeof v === "function", { error: "\"$expr\" must be a function" }).optional();
|
|
2701
|
+
fields["AND"] = this.orArray(z$1.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
|
|
2702
|
+
fields["OR"] = z$1.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)).array().optional();
|
|
2703
|
+
fields["NOT"] = this.orArray(z$1.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
|
|
2704
|
+
const baseWhere = z$1.strictObject(fields);
|
|
2671
2705
|
let result = baseWhere;
|
|
2672
2706
|
if (unique) {
|
|
2673
2707
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
@@ -2693,26 +2727,26 @@ var ZodSchemaFactory = class {
|
|
|
2693
2727
|
else if (getEnum(this.schema, fieldDef.type)) fieldSchemas[fieldName] = this.makeEnumFilterSchema(fieldDef.type, !!fieldDef.optional, !!fieldDef.array, false, void 0).optional();
|
|
2694
2728
|
else if (fieldDef.array) fieldSchemas[fieldName] = this.makeArrayFilterSchema(fieldDef.type, void 0).optional();
|
|
2695
2729
|
else fieldSchemas[fieldName] = this.makePrimitiveFilterSchema(fieldDef.type, !!fieldDef.optional, false, void 0).optional();
|
|
2696
|
-
candidates.push(z.strictObject(fieldSchemas));
|
|
2730
|
+
candidates.push(z$1.strictObject(fieldSchemas));
|
|
2697
2731
|
}
|
|
2698
|
-
const recursiveSchema = z.lazy(() => this.makeTypedJsonFilterSchema(type, optional, false, allowedFilterKinds)).optional();
|
|
2699
|
-
if (array) candidates.push(z.strictObject({
|
|
2732
|
+
const recursiveSchema = z$1.lazy(() => this.makeTypedJsonFilterSchema(type, optional, false, allowedFilterKinds)).optional();
|
|
2733
|
+
if (array) candidates.push(z$1.strictObject({
|
|
2700
2734
|
some: recursiveSchema,
|
|
2701
2735
|
every: recursiveSchema,
|
|
2702
2736
|
none: recursiveSchema
|
|
2703
2737
|
}));
|
|
2704
|
-
else candidates.push(z.strictObject({
|
|
2738
|
+
else candidates.push(z$1.strictObject({
|
|
2705
2739
|
is: recursiveSchema,
|
|
2706
2740
|
isNot: recursiveSchema
|
|
2707
2741
|
}));
|
|
2708
2742
|
candidates.push(this.makeJsonFilterSchema(optional, allowedFilterKinds));
|
|
2709
2743
|
if (optional) {
|
|
2710
|
-
candidates.push(z.null());
|
|
2711
|
-
candidates.push(z.instanceof(DbNullClass));
|
|
2712
|
-
candidates.push(z.instanceof(JsonNullClass));
|
|
2713
|
-
candidates.push(z.instanceof(AnyNullClass));
|
|
2744
|
+
candidates.push(z$1.null());
|
|
2745
|
+
candidates.push(z$1.instanceof(DbNullClass));
|
|
2746
|
+
candidates.push(z$1.instanceof(JsonNullClass));
|
|
2747
|
+
candidates.push(z$1.instanceof(AnyNullClass));
|
|
2714
2748
|
}
|
|
2715
|
-
const result = z.union(candidates);
|
|
2749
|
+
const result = z$1.union(candidates);
|
|
2716
2750
|
this.registerSchema(`${type}Filter${this.filterSchemaSuffix({
|
|
2717
2751
|
optional,
|
|
2718
2752
|
array,
|
|
@@ -2721,7 +2755,7 @@ var ZodSchemaFactory = class {
|
|
|
2721
2755
|
return result;
|
|
2722
2756
|
}
|
|
2723
2757
|
makeNullableTypedJsonMutationSchema(fieldSchema) {
|
|
2724
|
-
return z.any().superRefine((value, ctx) => {
|
|
2758
|
+
return z$1.any().superRefine((value, ctx) => {
|
|
2725
2759
|
if (value instanceof DbNullClass || value instanceof JsonNullClass || value === null || value === void 0) return;
|
|
2726
2760
|
const parseResult = fieldSchema.safeParse(value);
|
|
2727
2761
|
if (!parseResult.success) parseResult.error.issues.forEach((issue) => ctx.addIssue(issue));
|
|
@@ -2733,11 +2767,11 @@ var ZodSchemaFactory = class {
|
|
|
2733
2767
|
makeEnumFilterSchema(enumName, optional, array, withAggregations, allowedFilterKinds) {
|
|
2734
2768
|
const enumDef = getEnum(this.schema, enumName);
|
|
2735
2769
|
invariant(enumDef, `Enum "${enumName}" not found in schema`);
|
|
2736
|
-
const baseSchema = z.enum(Object.keys(enumDef.values));
|
|
2770
|
+
const baseSchema = z$1.enum(Object.keys(enumDef.values));
|
|
2737
2771
|
let schema;
|
|
2738
2772
|
if (array) schema = this.internalMakeArrayFilterSchema(baseSchema, allowedFilterKinds);
|
|
2739
2773
|
else {
|
|
2740
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z.lazy(() => this.makeEnumFilterSchema(enumName, optional, array, withAggregations, allowedFilterKinds)), [
|
|
2774
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z$1.lazy(() => this.makeEnumFilterSchema(enumName, optional, array, withAggregations, allowedFilterKinds)), [
|
|
2741
2775
|
"equals",
|
|
2742
2776
|
"in",
|
|
2743
2777
|
"notIn",
|
|
@@ -2771,42 +2805,42 @@ var ZodSchemaFactory = class {
|
|
|
2771
2805
|
has: elementSchema.optional(),
|
|
2772
2806
|
hasEvery: elementSchema.array().optional(),
|
|
2773
2807
|
hasSome: elementSchema.array().optional(),
|
|
2774
|
-
isEmpty: z.boolean().optional()
|
|
2808
|
+
isEmpty: z$1.boolean().optional()
|
|
2775
2809
|
};
|
|
2776
2810
|
const filteredOperators = this.trimFilterOperators(operators, allowedFilterKinds);
|
|
2777
|
-
return z.strictObject(filteredOperators);
|
|
2811
|
+
return z$1.strictObject(filteredOperators);
|
|
2778
2812
|
}
|
|
2779
2813
|
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.never()).exhaustive();
|
|
2814
|
+
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();
|
|
2781
2815
|
}
|
|
2782
2816
|
makeJsonValueSchema() {
|
|
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()])))
|
|
2817
|
+
const schema = z$1.union([
|
|
2818
|
+
z$1.string(),
|
|
2819
|
+
z$1.number(),
|
|
2820
|
+
z$1.boolean(),
|
|
2821
|
+
z$1.instanceof(JsonNullClass),
|
|
2822
|
+
z$1.lazy(() => z$1.union([this.makeJsonValueSchema(), z$1.null()]).array()),
|
|
2823
|
+
z$1.record(z$1.string(), z$1.lazy(() => z$1.union([this.makeJsonValueSchema(), z$1.null()])))
|
|
2790
2824
|
]);
|
|
2791
2825
|
this.registerSchema("JsonValue", schema);
|
|
2792
2826
|
return schema;
|
|
2793
2827
|
}
|
|
2794
2828
|
makeJsonFilterSchema(optional, allowedFilterKinds) {
|
|
2795
|
-
if (allowedFilterKinds && !allowedFilterKinds.includes("Json")) return z.never();
|
|
2829
|
+
if (allowedFilterKinds && !allowedFilterKinds.includes("Json")) return z$1.never();
|
|
2796
2830
|
const filterMembers = [
|
|
2797
2831
|
this.makeJsonValueSchema(),
|
|
2798
|
-
z.instanceof(DbNullClass),
|
|
2799
|
-
z.instanceof(AnyNullClass)
|
|
2832
|
+
z$1.instanceof(DbNullClass),
|
|
2833
|
+
z$1.instanceof(AnyNullClass)
|
|
2800
2834
|
];
|
|
2801
|
-
if (optional) filterMembers.push(z.null());
|
|
2802
|
-
const filterValueSchema = z.union(filterMembers);
|
|
2803
|
-
const schema = z.strictObject({
|
|
2804
|
-
path: z.string().optional(),
|
|
2835
|
+
if (optional) filterMembers.push(z$1.null());
|
|
2836
|
+
const filterValueSchema = z$1.union(filterMembers);
|
|
2837
|
+
const schema = z$1.strictObject({
|
|
2838
|
+
path: z$1.string().optional(),
|
|
2805
2839
|
equals: filterValueSchema.optional(),
|
|
2806
2840
|
not: filterValueSchema.optional(),
|
|
2807
|
-
string_contains: z.string().optional(),
|
|
2808
|
-
string_starts_with: z.string().optional(),
|
|
2809
|
-
string_ends_with: z.string().optional(),
|
|
2841
|
+
string_contains: z$1.string().optional(),
|
|
2842
|
+
string_starts_with: z$1.string().optional(),
|
|
2843
|
+
string_ends_with: z$1.string().optional(),
|
|
2810
2844
|
mode: this.makeStringModeSchema().optional(),
|
|
2811
2845
|
array_contains: filterValueSchema.optional(),
|
|
2812
2846
|
array_starts_with: filterValueSchema.optional(),
|
|
@@ -2825,7 +2859,7 @@ var ZodSchemaFactory = class {
|
|
|
2825
2859
|
}
|
|
2826
2860
|
makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
2827
2861
|
const filterValueSchema = this.makeDateTimeValueSchema();
|
|
2828
|
-
const schema = this.makeCommonPrimitiveFilterSchema(filterValueSchema, optional, () => z.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)), withAggregations ? [
|
|
2862
|
+
const schema = this.makeCommonPrimitiveFilterSchema(filterValueSchema, optional, () => z$1.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)), withAggregations ? [
|
|
2829
2863
|
"_count",
|
|
2830
2864
|
"_min",
|
|
2831
2865
|
"_max"
|
|
@@ -2838,12 +2872,12 @@ var ZodSchemaFactory = class {
|
|
|
2838
2872
|
return schema;
|
|
2839
2873
|
}
|
|
2840
2874
|
makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
2841
|
-
const components = this.makeCommonPrimitiveFilterComponents(z.boolean(), optional, () => z.lazy(() => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)), ["equals", "not"], withAggregations ? [
|
|
2875
|
+
const components = this.makeCommonPrimitiveFilterComponents(z$1.boolean(), optional, () => z$1.lazy(() => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)), ["equals", "not"], withAggregations ? [
|
|
2842
2876
|
"_count",
|
|
2843
2877
|
"_min",
|
|
2844
2878
|
"_max"
|
|
2845
2879
|
] : void 0, allowedFilterKinds);
|
|
2846
|
-
const schema = this.createUnionFilterSchema(z.boolean(), optional, components, allowedFilterKinds);
|
|
2880
|
+
const schema = this.createUnionFilterSchema(z$1.boolean(), optional, components, allowedFilterKinds);
|
|
2847
2881
|
this.registerSchema(`BooleanFilter${this.filterSchemaSuffix({
|
|
2848
2882
|
optional,
|
|
2849
2883
|
allowedFilterKinds,
|
|
@@ -2852,8 +2886,8 @@ var ZodSchemaFactory = class {
|
|
|
2852
2886
|
return schema;
|
|
2853
2887
|
}
|
|
2854
2888
|
makeBytesFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
2855
|
-
const baseSchema = z.instanceof(Uint8Array);
|
|
2856
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z.instanceof(Uint8Array), [
|
|
2889
|
+
const baseSchema = z$1.instanceof(Uint8Array);
|
|
2890
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z$1.instanceof(Uint8Array), [
|
|
2857
2891
|
"equals",
|
|
2858
2892
|
"in",
|
|
2859
2893
|
"notIn",
|
|
@@ -2901,7 +2935,7 @@ var ZodSchemaFactory = class {
|
|
|
2901
2935
|
return this.createUnionFilterSchema(baseSchema, optional, components, allowedFilterKinds);
|
|
2902
2936
|
}
|
|
2903
2937
|
makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds) {
|
|
2904
|
-
const schema = this.makeCommonPrimitiveFilterSchema(this.makeScalarSchema(type), optional, () => z.lazy(() => this.makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds)), withAggregations ? [
|
|
2938
|
+
const schema = this.makeCommonPrimitiveFilterSchema(this.makeScalarSchema(type), optional, () => z$1.lazy(() => this.makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds)), withAggregations ? [
|
|
2905
2939
|
"_count",
|
|
2906
2940
|
"_avg",
|
|
2907
2941
|
"_sum",
|
|
@@ -2916,15 +2950,15 @@ var ZodSchemaFactory = class {
|
|
|
2916
2950
|
return schema;
|
|
2917
2951
|
}
|
|
2918
2952
|
makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy = false, withFullText = false) {
|
|
2919
|
-
const baseComponents = this.makeCommonPrimitiveFilterComponents(z.string(), optional, () => z.lazy(() => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy, withFullText)), void 0, withAggregations ? [
|
|
2953
|
+
const baseComponents = this.makeCommonPrimitiveFilterComponents(z$1.string(), optional, () => z$1.lazy(() => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy, withFullText)), void 0, withAggregations ? [
|
|
2920
2954
|
"_count",
|
|
2921
2955
|
"_min",
|
|
2922
2956
|
"_max"
|
|
2923
2957
|
] : void 0, allowedFilterKinds);
|
|
2924
2958
|
const stringSpecificOperators = {
|
|
2925
|
-
startsWith: z.string().optional(),
|
|
2926
|
-
endsWith: z.string().optional(),
|
|
2927
|
-
contains: z.string().optional(),
|
|
2959
|
+
startsWith: z$1.string().optional(),
|
|
2960
|
+
endsWith: z$1.string().optional(),
|
|
2961
|
+
contains: z$1.string().optional(),
|
|
2928
2962
|
...withFuzzy && this.providerSupportsFuzzySearch ? { fuzzy: this.makeFuzzyFilterSchema().optional() } : {},
|
|
2929
2963
|
...withFullText && this.providerSupportsFullTextSearch ? { fts: this.makeFullTextFilterSchema().optional() } : {},
|
|
2930
2964
|
...this.providerSupportsCaseSensitivity ? { mode: this.makeStringModeSchema().optional() } : {}
|
|
@@ -2934,7 +2968,7 @@ var ZodSchemaFactory = class {
|
|
|
2934
2968
|
...baseComponents,
|
|
2935
2969
|
...filteredStringOperators
|
|
2936
2970
|
};
|
|
2937
|
-
const schema = this.createUnionFilterSchema(z.string(), optional, allComponents, allowedFilterKinds);
|
|
2971
|
+
const schema = this.createUnionFilterSchema(z$1.string(), optional, allComponents, allowedFilterKinds);
|
|
2938
2972
|
const featureSuffix = `${withFuzzy ? "Fuzzy" : ""}${withFullText ? "FullText" : ""}`;
|
|
2939
2973
|
this.registerSchema(`StringFilter${this.filterSchemaSuffix({
|
|
2940
2974
|
optional,
|
|
@@ -2944,45 +2978,45 @@ var ZodSchemaFactory = class {
|
|
|
2944
2978
|
return schema;
|
|
2945
2979
|
}
|
|
2946
2980
|
makeStringModeSchema() {
|
|
2947
|
-
return z.union([z.literal("default"), z.literal("insensitive")]);
|
|
2981
|
+
return z$1.union([z$1.literal("default"), z$1.literal("insensitive")]);
|
|
2948
2982
|
}
|
|
2949
2983
|
makeFuzzyFilterSchema() {
|
|
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")
|
|
2984
|
+
return z$1.strictObject({
|
|
2985
|
+
search: z$1.string().min(1),
|
|
2986
|
+
mode: z$1.union([
|
|
2987
|
+
z$1.literal("simple"),
|
|
2988
|
+
z$1.literal("word"),
|
|
2989
|
+
z$1.literal("strictWord")
|
|
2956
2990
|
]).default("simple"),
|
|
2957
|
-
threshold: z.number().min(0).max(1).optional(),
|
|
2958
|
-
unaccent: z.boolean().default(false)
|
|
2991
|
+
threshold: z$1.number().min(0).max(1).optional(),
|
|
2992
|
+
unaccent: z$1.boolean().default(false)
|
|
2959
2993
|
});
|
|
2960
2994
|
}
|
|
2961
2995
|
makeFullTextFilterSchema() {
|
|
2962
|
-
return z.strictObject({
|
|
2963
|
-
search: z.string().min(1),
|
|
2964
|
-
config: z.string().min(1).optional()
|
|
2996
|
+
return z$1.strictObject({
|
|
2997
|
+
search: z$1.string().min(1),
|
|
2998
|
+
config: z$1.string().min(1).optional()
|
|
2965
2999
|
});
|
|
2966
3000
|
}
|
|
2967
3001
|
makeSelectSchema(model, options) {
|
|
2968
3002
|
const fields = {};
|
|
2969
3003
|
for (const [field, fieldDef] of this.getModelFields(model)) {
|
|
2970
3004
|
if (this.isParameterizedComputedField(fieldDef)) {
|
|
2971
|
-
fields[field] = z.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional();
|
|
3005
|
+
fields[field] = z$1.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional();
|
|
2972
3006
|
continue;
|
|
2973
3007
|
}
|
|
2974
3008
|
if (fieldDef.relation) {
|
|
2975
3009
|
if (!this.shouldIncludeRelations(options)) continue;
|
|
2976
3010
|
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.literal(false).optional();
|
|
2978
|
-
else fields[field] = z.boolean().optional();
|
|
3011
|
+
} else if (this.options.allowQueryTimeOmitOverride === false && this.isFieldOmittedByConfig(model, field)) fields[field] = z$1.literal(false).optional();
|
|
3012
|
+
else fields[field] = z$1.boolean().optional();
|
|
2979
3013
|
}
|
|
2980
3014
|
if (this.shouldIncludeRelations(options)) {
|
|
2981
3015
|
const _countSchema = this.makeCountSelectionSchema(model, options);
|
|
2982
|
-
if (!(_countSchema instanceof z.ZodNever)) fields["_count"] = _countSchema;
|
|
3016
|
+
if (!(_countSchema instanceof z$1.ZodNever)) fields["_count"] = _countSchema;
|
|
2983
3017
|
}
|
|
2984
3018
|
this.addExtResultFields(model, fields);
|
|
2985
|
-
const result = z.strictObject(fields);
|
|
3019
|
+
const result = z$1.strictObject(fields);
|
|
2986
3020
|
this.registerSchema(`${model}Select`, result);
|
|
2987
3021
|
return result;
|
|
2988
3022
|
}
|
|
@@ -2991,24 +3025,24 @@ var ZodSchemaFactory = class {
|
|
|
2991
3025
|
const toManyRelations = Object.values(modelDef.fields).filter((def) => def.relation && def.array);
|
|
2992
3026
|
if (toManyRelations.length > 0) {
|
|
2993
3027
|
const nextOpts = this.nextOptions(options);
|
|
2994
|
-
const schema = z.union([z.literal(true), z.strictObject({ select: z.strictObject(toManyRelations.reduce((acc, fieldDef) => ({
|
|
3028
|
+
const schema = z$1.union([z$1.literal(true), z$1.strictObject({ select: z$1.strictObject(toManyRelations.reduce((acc, fieldDef) => ({
|
|
2995
3029
|
...acc,
|
|
2996
|
-
[fieldDef.name]: z.union([z.boolean(), z.strictObject({ where: this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts) })]).optional()
|
|
3030
|
+
[fieldDef.name]: z$1.union([z$1.boolean(), z$1.strictObject({ where: this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts) })]).optional()
|
|
2997
3031
|
}), {})) })]).optional();
|
|
2998
3032
|
this.registerSchema(`${model}CountSelection`, schema);
|
|
2999
3033
|
return schema;
|
|
3000
|
-
} else return z.never();
|
|
3034
|
+
} else return z$1.never();
|
|
3001
3035
|
}
|
|
3002
3036
|
makeRelationSelectIncludeSchema(model, field, options) {
|
|
3003
3037
|
const fieldDef = requireField(this.schema, model, field);
|
|
3004
3038
|
const nextOpts = this.nextOptions(options);
|
|
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(),
|
|
3039
|
+
let objSchema = z$1.strictObject({
|
|
3040
|
+
...fieldDef.array || fieldDef.optional ? { where: z$1.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts)).optional() } : {},
|
|
3041
|
+
select: z$1.lazy(() => this.makeSelectSchema(fieldDef.type, nextOpts)).optional().nullable(),
|
|
3042
|
+
include: z$1.lazy(() => this.makeIncludeSchema(fieldDef.type, nextOpts)).optional().nullable(),
|
|
3043
|
+
omit: z$1.lazy(() => this.makeOmitSchema(fieldDef.type)).optional().nullable(),
|
|
3010
3044
|
...fieldDef.array ? {
|
|
3011
|
-
orderBy: z.lazy(() => this.orArray(this.makeOrderBySchema(fieldDef.type, true, false, nextOpts), true)).optional(),
|
|
3045
|
+
orderBy: z$1.lazy(() => this.orArray(this.makeOrderBySchema(fieldDef.type, true, false, nextOpts), true)).optional(),
|
|
3012
3046
|
skip: this.makeSkipSchema().optional(),
|
|
3013
3047
|
take: this.makeTakeSchema().optional(),
|
|
3014
3048
|
cursor: this.makeCursorSchema(fieldDef.type, nextOpts).optional(),
|
|
@@ -3018,7 +3052,7 @@ var ZodSchemaFactory = class {
|
|
|
3018
3052
|
objSchema = this.refineForSelectIncludeMutuallyExclusive(objSchema);
|
|
3019
3053
|
objSchema = this.refineForSelectOmitMutuallyExclusive(objSchema);
|
|
3020
3054
|
objSchema = this.refineForSelectHasTruthyField(objSchema);
|
|
3021
|
-
const result = z.union([z.boolean(), objSchema]);
|
|
3055
|
+
const result = z$1.union([z$1.boolean(), objSchema]);
|
|
3022
3056
|
this.registerSchema(`${model}${upperCaseFirst(field)}RelationInput`, result);
|
|
3023
3057
|
return result;
|
|
3024
3058
|
}
|
|
@@ -3035,11 +3069,11 @@ var ZodSchemaFactory = class {
|
|
|
3035
3069
|
const fields = {};
|
|
3036
3070
|
for (const [field, fieldDef] of this.getModelFields(model)) {
|
|
3037
3071
|
if (this.isParameterizedComputedField(fieldDef)) continue;
|
|
3038
|
-
if (!fieldDef.relation) if (this.options.allowQueryTimeOmitOverride !== false) fields[field] = z.boolean().optional();
|
|
3039
|
-
else fields[field] = z.literal(true).optional();
|
|
3072
|
+
if (!fieldDef.relation) if (this.options.allowQueryTimeOmitOverride !== false) fields[field] = z$1.boolean().optional();
|
|
3073
|
+
else fields[field] = z$1.literal(true).optional();
|
|
3040
3074
|
}
|
|
3041
3075
|
this.addExtResultFields(model, fields);
|
|
3042
|
-
const result = z.strictObject(fields);
|
|
3076
|
+
const result = z$1.strictObject(fields);
|
|
3043
3077
|
this.registerSchema(`${model}OmitInput`, result);
|
|
3044
3078
|
return result;
|
|
3045
3079
|
}
|
|
@@ -3048,7 +3082,7 @@ var ZodSchemaFactory = class {
|
|
|
3048
3082
|
const resultConfig = plugin.result;
|
|
3049
3083
|
if (resultConfig) {
|
|
3050
3084
|
const modelConfig = resultConfig[lowerCaseFirst(model)];
|
|
3051
|
-
if (modelConfig) for (const field of Object.keys(modelConfig)) fields[field] = z.boolean().optional();
|
|
3085
|
+
if (modelConfig) for (const field of Object.keys(modelConfig)) fields[field] = z$1.boolean().optional();
|
|
3052
3086
|
}
|
|
3053
3087
|
}
|
|
3054
3088
|
}
|
|
@@ -3060,35 +3094,35 @@ var ZodSchemaFactory = class {
|
|
|
3060
3094
|
if (fieldDef.relation) {
|
|
3061
3095
|
if (!this.shouldIncludeRelations(options)) continue;
|
|
3062
3096
|
if (this.isModelAllowed(fieldDef.type)) fields[field] = this.makeRelationSelectIncludeSchema(model, field, options).optional();
|
|
3063
|
-
} else if (this.isParameterizedComputedField(fieldDef)) fields[field] = z.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional();
|
|
3097
|
+
} else if (this.isParameterizedComputedField(fieldDef)) fields[field] = z$1.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional();
|
|
3064
3098
|
}
|
|
3065
3099
|
if (this.shouldIncludeRelations(options)) {
|
|
3066
3100
|
const _countSchema = this.makeCountSelectionSchema(model, options);
|
|
3067
|
-
if (!(_countSchema instanceof z.ZodNever)) fields["_count"] = _countSchema;
|
|
3101
|
+
if (!(_countSchema instanceof z$1.ZodNever)) fields["_count"] = _countSchema;
|
|
3068
3102
|
}
|
|
3069
|
-
const result = z.strictObject(fields);
|
|
3103
|
+
const result = z$1.strictObject(fields);
|
|
3070
3104
|
this.registerSchema(`${model}Include`, result);
|
|
3071
3105
|
return result;
|
|
3072
3106
|
}
|
|
3073
3107
|
makeOrderBySchema(model, withRelation, WithAggregation, options) {
|
|
3074
3108
|
const fields = {};
|
|
3075
|
-
const sort = z.union([z.literal("asc"), z.literal("desc")]);
|
|
3109
|
+
const sort = z$1.union([z$1.literal("asc"), z$1.literal("desc")]);
|
|
3076
3110
|
const refineAtMostOneKey = (s) => s.refine((v) => Object.keys(v).length <= 1, { message: "Each orderBy element must have at most one key" });
|
|
3077
3111
|
const nextOpts = this.nextOptions(options);
|
|
3078
3112
|
for (const [field, fieldDef] of this.getModelFields(model)) if (fieldDef.relation) {
|
|
3079
|
-
if (withRelation && this.shouldIncludeRelations(options)) fields[field] = z.lazy(() => {
|
|
3113
|
+
if (withRelation && this.shouldIncludeRelations(options)) fields[field] = z$1.lazy(() => {
|
|
3080
3114
|
let relationOrderBy = this.makeOrderBySchema(fieldDef.type, withRelation, WithAggregation, nextOpts);
|
|
3081
3115
|
if (fieldDef.array) relationOrderBy = refineAtMostOneKey(relationOrderBy.safeExtend({ _count: sort }));
|
|
3082
3116
|
return relationOrderBy;
|
|
3083
3117
|
}).optional();
|
|
3084
|
-
} else if (fieldDef.computed && fieldDef.params) fields[field] = z.strictObject({
|
|
3118
|
+
} else if (fieldDef.computed && fieldDef.params) fields[field] = z$1.strictObject({
|
|
3085
3119
|
args: this.makeFieldArgsSchema(fieldDef.params),
|
|
3086
3120
|
sort,
|
|
3087
|
-
nulls: z.union([z.literal("first"), z.literal("last")]).optional()
|
|
3121
|
+
nulls: z$1.union([z$1.literal("first"), z$1.literal("last")]).optional()
|
|
3088
3122
|
}).optional();
|
|
3089
|
-
else if (fieldDef.optional) fields[field] = z.union([sort, z.strictObject({
|
|
3123
|
+
else if (fieldDef.optional) fields[field] = z$1.union([sort, z$1.strictObject({
|
|
3090
3124
|
sort,
|
|
3091
|
-
nulls: z.union([z.literal("first"), z.literal("last")]).optional()
|
|
3125
|
+
nulls: z$1.union([z$1.literal("first"), z$1.literal("last")]).optional()
|
|
3092
3126
|
})]).optional();
|
|
3093
3127
|
else fields[field] = sort.optional();
|
|
3094
3128
|
if (WithAggregation) for (const agg of [
|
|
@@ -3097,31 +3131,31 @@ var ZodSchemaFactory = class {
|
|
|
3097
3131
|
"_sum",
|
|
3098
3132
|
"_min",
|
|
3099
3133
|
"_max"
|
|
3100
|
-
]) fields[agg] = z.lazy(() => this.makeOrderBySchema(model, true, false, options).optional());
|
|
3134
|
+
]) fields[agg] = z$1.lazy(() => this.makeOrderBySchema(model, true, false, options).optional());
|
|
3101
3135
|
if (this.providerSupportsFuzzySearch) {
|
|
3102
3136
|
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.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")
|
|
3137
|
+
if (fuzzyFieldNames.length > 0) fields["_fuzzyRelevance"] = z$1.strictObject({
|
|
3138
|
+
fields: z$1.array(z$1.enum(fuzzyFieldNames)).min(1),
|
|
3139
|
+
search: z$1.string(),
|
|
3140
|
+
mode: z$1.union([
|
|
3141
|
+
z$1.literal("simple"),
|
|
3142
|
+
z$1.literal("word"),
|
|
3143
|
+
z$1.literal("strictWord")
|
|
3110
3144
|
]).default("simple"),
|
|
3111
|
-
unaccent: z.boolean().default(false),
|
|
3145
|
+
unaccent: z$1.boolean().default(false),
|
|
3112
3146
|
sort
|
|
3113
3147
|
}).optional();
|
|
3114
3148
|
}
|
|
3115
3149
|
if (this.providerSupportsFullTextSearch) {
|
|
3116
3150
|
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.strictObject({
|
|
3118
|
-
fields: z.array(z.enum(fullTextFieldNames)).min(1),
|
|
3119
|
-
search: z.string().min(1),
|
|
3120
|
-
config: z.string().min(1).optional(),
|
|
3151
|
+
if (fullTextFieldNames.length > 0) fields["_ftsRelevance"] = z$1.strictObject({
|
|
3152
|
+
fields: z$1.array(z$1.enum(fullTextFieldNames)).min(1),
|
|
3153
|
+
search: z$1.string().min(1),
|
|
3154
|
+
config: z$1.string().min(1).optional(),
|
|
3121
3155
|
sort
|
|
3122
3156
|
}).optional();
|
|
3123
3157
|
}
|
|
3124
|
-
const schema = refineAtMostOneKey(z.strictObject(fields));
|
|
3158
|
+
const schema = refineAtMostOneKey(z$1.strictObject(fields));
|
|
3125
3159
|
let schemaId = `${model}OrderBy`;
|
|
3126
3160
|
if (withRelation) schemaId += "WithRelation";
|
|
3127
3161
|
if (WithAggregation) schemaId += "WithAggregation";
|
|
@@ -3131,7 +3165,7 @@ var ZodSchemaFactory = class {
|
|
|
3131
3165
|
}
|
|
3132
3166
|
makeDistinctSchema(model) {
|
|
3133
3167
|
const nonRelationFields = this.getModelFields(model).filter(([, def]) => !def.relation && !this.isParameterizedComputedField(def)).map(([name]) => name);
|
|
3134
|
-
const schema = nonRelationFields.length > 0 ? this.orArray(z.enum(nonRelationFields), true) : z.never();
|
|
3168
|
+
const schema = nonRelationFields.length > 0 ? this.orArray(z$1.enum(nonRelationFields), true) : z$1.never();
|
|
3135
3169
|
this.registerSchema(`${model}DistinctInput`, schema);
|
|
3136
3170
|
return schema;
|
|
3137
3171
|
}
|
|
@@ -3142,7 +3176,7 @@ var ZodSchemaFactory = class {
|
|
|
3142
3176
|
}
|
|
3143
3177
|
makeCreateSchema(model, options) {
|
|
3144
3178
|
const dataSchema = this.makeCreateDataSchema(model, false, [], false, options);
|
|
3145
|
-
const baseSchema = z.strictObject({
|
|
3179
|
+
const baseSchema = z$1.strictObject({
|
|
3146
3180
|
data: dataSchema,
|
|
3147
3181
|
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
3148
3182
|
include: this.makeIncludeSchema(model, options).optional().nullable(),
|
|
@@ -3191,7 +3225,7 @@ var ZodSchemaFactory = class {
|
|
|
3191
3225
|
const oppositeFieldDef = requireField(this.schema, fieldDef.type, oppositeField);
|
|
3192
3226
|
if (oppositeFieldDef.relation?.fields) excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
3193
3227
|
}
|
|
3194
|
-
let fieldSchema = z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "create", nextOpts));
|
|
3228
|
+
let fieldSchema = z$1.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "create", nextOpts));
|
|
3195
3229
|
if (fieldDef.optional || fieldDef.array) fieldSchema = fieldSchema.optional();
|
|
3196
3230
|
else {
|
|
3197
3231
|
let allFksOptional = false;
|
|
@@ -3208,23 +3242,23 @@ var ZodSchemaFactory = class {
|
|
|
3208
3242
|
let fieldSchema = this.makeScalarSchema(fieldDef.type, fieldDef.attributes);
|
|
3209
3243
|
if (fieldDef.array) {
|
|
3210
3244
|
fieldSchema = ZodUtils.addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
3211
|
-
fieldSchema = z.union([fieldSchema, z.strictObject({ set: fieldSchema })]).optional();
|
|
3245
|
+
fieldSchema = z$1.union([fieldSchema, z$1.strictObject({ set: fieldSchema })]).optional();
|
|
3212
3246
|
}
|
|
3213
3247
|
if (fieldDef.optional || fieldHasDefaultValue(fieldDef)) fieldSchema = fieldSchema.optional();
|
|
3214
|
-
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z.union([fieldSchema, z.instanceof(DbNullClass)]);
|
|
3248
|
+
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z$1.union([fieldSchema, z$1.instanceof(DbNullClass)]);
|
|
3215
3249
|
else if (this.isTypeDefType(fieldDef.type)) fieldSchema = this.makeNullableTypedJsonMutationSchema(fieldSchema);
|
|
3216
3250
|
else fieldSchema = fieldSchema.nullable();
|
|
3217
3251
|
uncheckedVariantFields[field] = fieldSchema;
|
|
3218
3252
|
if (!fieldDef.foreignKeyFor) checkedVariantFields[field] = fieldSchema;
|
|
3219
3253
|
}
|
|
3220
3254
|
});
|
|
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([
|
|
3255
|
+
const uncheckedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z$1.strictObject(uncheckedVariantFields), modelDef.attributes) : z$1.strictObject(uncheckedVariantFields);
|
|
3256
|
+
const checkedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z$1.strictObject(checkedVariantFields), modelDef.attributes) : z$1.strictObject(checkedVariantFields);
|
|
3257
|
+
const result = !hasRelation ? this.orArray(uncheckedCreateSchema, canBeArray) : z$1.union([
|
|
3224
3258
|
uncheckedCreateSchema,
|
|
3225
3259
|
checkedCreateSchema,
|
|
3226
|
-
...canBeArray ? [z.array(uncheckedCreateSchema)] : [],
|
|
3227
|
-
...canBeArray ? [z.array(checkedCreateSchema)] : []
|
|
3260
|
+
...canBeArray ? [z$1.array(uncheckedCreateSchema)] : [],
|
|
3261
|
+
...canBeArray ? [z$1.array(checkedCreateSchema)] : []
|
|
3228
3262
|
]);
|
|
3229
3263
|
const idParts = [`${model}CreateData`];
|
|
3230
3264
|
if (canBeArray) idParts.push("Array");
|
|
@@ -3249,17 +3283,17 @@ var ZodSchemaFactory = class {
|
|
|
3249
3283
|
fields["disconnect"] = this.makeDisconnectDataSchema(fieldType, array, options).optional();
|
|
3250
3284
|
fields["delete"] = this.makeDeleteRelationDataSchema(fieldType, array, true, options).optional();
|
|
3251
3285
|
}
|
|
3252
|
-
fields["update"] = array ? this.orArray(z.strictObject({
|
|
3286
|
+
fields["update"] = array ? this.orArray(z$1.strictObject({
|
|
3253
3287
|
where: this.makeWhereSchema(fieldType, true, false, false, options),
|
|
3254
3288
|
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
3255
|
-
}), true).optional() : z.union([z.strictObject({
|
|
3289
|
+
}), true).optional() : z$1.union([z$1.strictObject({
|
|
3256
3290
|
where: this.makeWhereSchema(fieldType, false, false, false, options).optional(),
|
|
3257
3291
|
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
3258
3292
|
}), this.makeUpdateDataSchema(fieldType, withoutFields, false, options)]).optional();
|
|
3259
3293
|
if (canCreateModel) {
|
|
3260
3294
|
let upsertWhere = this.makeWhereSchema(fieldType, true, false, false, options);
|
|
3261
3295
|
if (!fieldDef.array) upsertWhere = upsertWhere.optional();
|
|
3262
|
-
fields["upsert"] = this.orArray(z.strictObject({
|
|
3296
|
+
fields["upsert"] = this.orArray(z$1.strictObject({
|
|
3263
3297
|
where: upsertWhere,
|
|
3264
3298
|
create: this.makeCreateDataSchema(fieldType, false, withoutFields, false, options),
|
|
3265
3299
|
update: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
@@ -3267,14 +3301,14 @@ var ZodSchemaFactory = class {
|
|
|
3267
3301
|
}
|
|
3268
3302
|
if (array) {
|
|
3269
3303
|
fields["set"] = this.makeSetDataSchema(fieldType, true, options).optional();
|
|
3270
|
-
fields["updateMany"] = this.orArray(z.strictObject({
|
|
3304
|
+
fields["updateMany"] = this.orArray(z$1.strictObject({
|
|
3271
3305
|
where: this.makeWhereSchema(fieldType, false, true, false, options),
|
|
3272
3306
|
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
3273
3307
|
}), true).optional();
|
|
3274
3308
|
fields["deleteMany"] = this.makeDeleteRelationDataSchema(fieldType, true, false, options).optional();
|
|
3275
3309
|
}
|
|
3276
3310
|
}
|
|
3277
|
-
return z.strictObject(fields);
|
|
3311
|
+
return z$1.strictObject(fields);
|
|
3278
3312
|
}
|
|
3279
3313
|
makeSetDataSchema(model, canBeArray, options) {
|
|
3280
3314
|
return this.orArray(this.makeWhereSchema(model, true, false, false, options), canBeArray);
|
|
@@ -3284,23 +3318,23 @@ var ZodSchemaFactory = class {
|
|
|
3284
3318
|
}
|
|
3285
3319
|
makeDisconnectDataSchema(model, canBeArray, options) {
|
|
3286
3320
|
if (canBeArray) return this.orArray(this.makeWhereSchema(model, true, false, false, options), canBeArray);
|
|
3287
|
-
else return z.union([z.boolean(), this.makeWhereSchema(model, false, false, false, options)]);
|
|
3321
|
+
else return z$1.union([z$1.boolean(), this.makeWhereSchema(model, false, false, false, options)]);
|
|
3288
3322
|
}
|
|
3289
3323
|
makeDeleteRelationDataSchema(model, toManyRelation, uniqueFilter, options) {
|
|
3290
|
-
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter, false, false, options), true) : z.union([z.boolean(), this.makeWhereSchema(model, uniqueFilter, false, false, options)]);
|
|
3324
|
+
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)]);
|
|
3291
3325
|
}
|
|
3292
3326
|
makeConnectOrCreateDataSchema(model, canBeArray, withoutFields, options) {
|
|
3293
3327
|
const whereSchema = this.makeWhereSchema(model, true, false, false, options);
|
|
3294
3328
|
const createSchema = this.makeCreateDataSchema(model, false, withoutFields, false, options);
|
|
3295
|
-
return this.orArray(z.strictObject({
|
|
3329
|
+
return this.orArray(z$1.strictObject({
|
|
3296
3330
|
where: whereSchema,
|
|
3297
3331
|
create: createSchema
|
|
3298
3332
|
}), canBeArray);
|
|
3299
3333
|
}
|
|
3300
3334
|
makeCreateManyPayloadSchema(model, withoutFields, options) {
|
|
3301
|
-
const schema = z.strictObject({
|
|
3335
|
+
const schema = z$1.strictObject({
|
|
3302
3336
|
data: this.makeCreateDataSchema(model, true, withoutFields, true, options),
|
|
3303
|
-
skipDuplicates: z.boolean().optional()
|
|
3337
|
+
skipDuplicates: z$1.boolean().optional()
|
|
3304
3338
|
});
|
|
3305
3339
|
const idParts = [`${model}CreateManyPayload`];
|
|
3306
3340
|
if (withoutFields.length) idParts.push(`Without${withoutFields.slice().sort().join("")}`);
|
|
@@ -3308,7 +3342,7 @@ var ZodSchemaFactory = class {
|
|
|
3308
3342
|
return schema;
|
|
3309
3343
|
}
|
|
3310
3344
|
makeUpdateSchema(model, options) {
|
|
3311
|
-
const baseSchema = z.strictObject({
|
|
3345
|
+
const baseSchema = z$1.strictObject({
|
|
3312
3346
|
where: this.makeWhereSchema(model, true, false, false, options),
|
|
3313
3347
|
data: this.makeUpdateDataSchema(model, [], false, options),
|
|
3314
3348
|
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
@@ -3323,10 +3357,10 @@ var ZodSchemaFactory = class {
|
|
|
3323
3357
|
return schema;
|
|
3324
3358
|
}
|
|
3325
3359
|
makeUpdateManySchema(model, options) {
|
|
3326
|
-
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3360
|
+
const result = this.mergePluginArgsSchema(z$1.strictObject({
|
|
3327
3361
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3328
3362
|
data: this.makeUpdateDataSchema(model, [], true, options),
|
|
3329
|
-
limit: z.number().int().nonnegative().optional()
|
|
3363
|
+
limit: z$1.number().int().nonnegative().optional()
|
|
3330
3364
|
}), "updateMany");
|
|
3331
3365
|
this.registerSchema(`${model}UpdateManyArgs`, result);
|
|
3332
3366
|
return result;
|
|
@@ -3342,7 +3376,7 @@ var ZodSchemaFactory = class {
|
|
|
3342
3376
|
return schema;
|
|
3343
3377
|
}
|
|
3344
3378
|
makeUpsertSchema(model, options) {
|
|
3345
|
-
const baseSchema = z.strictObject({
|
|
3379
|
+
const baseSchema = z$1.strictObject({
|
|
3346
3380
|
where: this.makeWhereSchema(model, true, false, false, options),
|
|
3347
3381
|
create: this.makeCreateDataSchema(model, false, [], false, options),
|
|
3348
3382
|
update: this.makeUpdateDataSchema(model, [], false, options),
|
|
@@ -3378,27 +3412,27 @@ var ZodSchemaFactory = class {
|
|
|
3378
3412
|
const oppositeFieldDef = requireField(this.schema, fieldDef.type, oppositeField);
|
|
3379
3413
|
if (oppositeFieldDef.relation?.fields) excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
3380
3414
|
}
|
|
3381
|
-
let fieldSchema = z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "update", nextOpts)).optional();
|
|
3415
|
+
let fieldSchema = z$1.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "update", nextOpts)).optional();
|
|
3382
3416
|
if (fieldDef.optional && !fieldDef.array) fieldSchema = fieldSchema.nullable();
|
|
3383
3417
|
checkedVariantFields[field] = fieldSchema;
|
|
3384
3418
|
if (fieldDef.array || !fieldDef.relation.references) uncheckedVariantFields[field] = fieldSchema;
|
|
3385
3419
|
} else {
|
|
3386
3420
|
let fieldSchema = this.makeScalarSchema(fieldDef.type, fieldDef.attributes);
|
|
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()
|
|
3421
|
+
if (this.isNumericField(fieldDef)) fieldSchema = z$1.union([fieldSchema, z$1.object({
|
|
3422
|
+
set: this.nullableIf(z$1.number().optional(), !!fieldDef.optional).optional(),
|
|
3423
|
+
increment: z$1.number().optional(),
|
|
3424
|
+
decrement: z$1.number().optional(),
|
|
3425
|
+
multiply: z$1.number().optional(),
|
|
3426
|
+
divide: z$1.number().optional()
|
|
3393
3427
|
}).refine((v) => Object.keys(v).length === 1, "Only one of \"set\", \"increment\", \"decrement\", \"multiply\", or \"divide\" can be provided")]);
|
|
3394
3428
|
if (fieldDef.array) {
|
|
3395
3429
|
const arraySchema = ZodUtils.addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
3396
|
-
fieldSchema = z.union([arraySchema, z.object({
|
|
3430
|
+
fieldSchema = z$1.union([arraySchema, z$1.object({
|
|
3397
3431
|
set: arraySchema.optional(),
|
|
3398
|
-
push: z.union([fieldSchema, fieldSchema.array()]).optional()
|
|
3432
|
+
push: z$1.union([fieldSchema, fieldSchema.array()]).optional()
|
|
3399
3433
|
}).refine((v) => Object.keys(v).length === 1, "Only one of \"set\", \"push\" can be provided")]);
|
|
3400
3434
|
}
|
|
3401
|
-
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z.union([fieldSchema, z.instanceof(DbNullClass)]);
|
|
3435
|
+
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z$1.union([fieldSchema, z$1.instanceof(DbNullClass)]);
|
|
3402
3436
|
else if (this.isTypeDefType(fieldDef.type)) fieldSchema = this.makeNullableTypedJsonMutationSchema(fieldSchema);
|
|
3403
3437
|
else fieldSchema = fieldSchema.nullable();
|
|
3404
3438
|
fieldSchema = fieldSchema.optional();
|
|
@@ -3406,9 +3440,9 @@ var ZodSchemaFactory = class {
|
|
|
3406
3440
|
if (!fieldDef.foreignKeyFor) checkedVariantFields[field] = fieldSchema;
|
|
3407
3441
|
}
|
|
3408
3442
|
});
|
|
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]);
|
|
3443
|
+
const uncheckedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z$1.strictObject(uncheckedVariantFields), modelDef.attributes) : z$1.strictObject(uncheckedVariantFields);
|
|
3444
|
+
const checkedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z$1.strictObject(checkedVariantFields), modelDef.attributes) : z$1.strictObject(checkedVariantFields);
|
|
3445
|
+
const result = !hasRelation ? uncheckedUpdateSchema : z$1.union([uncheckedUpdateSchema, checkedUpdateSchema]);
|
|
3412
3446
|
const idParts = [`${model}UpdateData`];
|
|
3413
3447
|
if (withoutRelationFields) idParts.push("WithoutRelation");
|
|
3414
3448
|
if (withoutFields.length) idParts.push(`Without${withoutFields.slice().sort().join("")}`);
|
|
@@ -3416,7 +3450,7 @@ var ZodSchemaFactory = class {
|
|
|
3416
3450
|
return result;
|
|
3417
3451
|
}
|
|
3418
3452
|
makeDeleteSchema(model, options) {
|
|
3419
|
-
const baseSchema = z.strictObject({
|
|
3453
|
+
const baseSchema = z$1.strictObject({
|
|
3420
3454
|
where: this.makeWhereSchema(model, true, false, false, options),
|
|
3421
3455
|
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
3422
3456
|
include: this.makeIncludeSchema(model, options).optional().nullable(),
|
|
@@ -3430,15 +3464,15 @@ var ZodSchemaFactory = class {
|
|
|
3430
3464
|
return schema;
|
|
3431
3465
|
}
|
|
3432
3466
|
makeDeleteManySchema(model, options) {
|
|
3433
|
-
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3467
|
+
const result = this.mergePluginArgsSchema(z$1.strictObject({
|
|
3434
3468
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3435
|
-
limit: z.number().int().nonnegative().optional()
|
|
3469
|
+
limit: z$1.number().int().nonnegative().optional()
|
|
3436
3470
|
}), "deleteMany").optional();
|
|
3437
3471
|
this.registerSchema(`${model}DeleteManyArgs`, result);
|
|
3438
3472
|
return result;
|
|
3439
3473
|
}
|
|
3440
3474
|
makeCountSchema(model, options) {
|
|
3441
|
-
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3475
|
+
const result = this.mergePluginArgsSchema(z$1.strictObject({
|
|
3442
3476
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3443
3477
|
skip: this.makeSkipSchema().optional(),
|
|
3444
3478
|
take: this.makeTakeSchema().optional(),
|
|
@@ -3449,10 +3483,10 @@ var ZodSchemaFactory = class {
|
|
|
3449
3483
|
return result;
|
|
3450
3484
|
}
|
|
3451
3485
|
makeCountAggregateInputSchema(model) {
|
|
3452
|
-
const schema = z.union([z.literal(true), z.strictObject({
|
|
3453
|
-
_all: z.literal(true).optional(),
|
|
3486
|
+
const schema = z$1.union([z$1.literal(true), z$1.strictObject({
|
|
3487
|
+
_all: z$1.literal(true).optional(),
|
|
3454
3488
|
...this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
|
|
3455
|
-
acc[field] = this.isParameterizedComputedField(fieldDef) ? z.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional() : z.literal(true).optional();
|
|
3489
|
+
acc[field] = this.isParameterizedComputedField(fieldDef) ? z$1.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional() : z$1.literal(true).optional();
|
|
3456
3490
|
return acc;
|
|
3457
3491
|
}, {})
|
|
3458
3492
|
})]);
|
|
@@ -3460,7 +3494,7 @@ var ZodSchemaFactory = class {
|
|
|
3460
3494
|
return schema;
|
|
3461
3495
|
}
|
|
3462
3496
|
makeAggregateSchema(model, options) {
|
|
3463
|
-
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3497
|
+
const result = this.mergePluginArgsSchema(z$1.strictObject({
|
|
3464
3498
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3465
3499
|
skip: this.makeSkipSchema().optional(),
|
|
3466
3500
|
take: this.makeTakeSchema().optional(),
|
|
@@ -3475,16 +3509,16 @@ var ZodSchemaFactory = class {
|
|
|
3475
3509
|
return result;
|
|
3476
3510
|
}
|
|
3477
3511
|
makeSumAvgInputSchema(model) {
|
|
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();
|
|
3512
|
+
const schema = z$1.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
|
|
3513
|
+
if (this.isNumericField(fieldDef)) acc[field] = this.isParameterizedComputedField(fieldDef) ? z$1.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional() : z$1.literal(true).optional();
|
|
3480
3514
|
return acc;
|
|
3481
3515
|
}, {}));
|
|
3482
3516
|
this.registerSchema(`${model}SumAvgAggregateInput`, schema);
|
|
3483
3517
|
return schema;
|
|
3484
3518
|
}
|
|
3485
3519
|
makeMinMaxInputSchema(model) {
|
|
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();
|
|
3520
|
+
const schema = z$1.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
|
|
3521
|
+
if (!fieldDef.relation && !fieldDef.array) acc[field] = this.isParameterizedComputedField(fieldDef) ? z$1.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional() : z$1.literal(true).optional();
|
|
3488
3522
|
return acc;
|
|
3489
3523
|
}, {}));
|
|
3490
3524
|
this.registerSchema(`${model}MinMaxAggregateInput`, schema);
|
|
@@ -3493,14 +3527,14 @@ var ZodSchemaFactory = class {
|
|
|
3493
3527
|
makeGroupBySchema(model, options) {
|
|
3494
3528
|
const nonRelationFields = this.getModelFields(model).filter(([, def]) => !def.relation && !this.isParameterizedComputedField(def)).map(([name]) => name);
|
|
3495
3529
|
const byMembers = [];
|
|
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),
|
|
3530
|
+
if (nonRelationFields.length > 0) byMembers.push(z$1.enum(nonRelationFields));
|
|
3531
|
+
for (const [field, fieldDef] of this.getModelFields(model)) if (this.isParameterizedComputedField(fieldDef)) byMembers.push(z$1.strictObject({
|
|
3532
|
+
field: z$1.literal(field),
|
|
3499
3533
|
args: this.makeFieldArgsSchema(fieldDef.params)
|
|
3500
3534
|
}));
|
|
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({
|
|
3535
|
+
const byElement = byMembers.length === 0 ? void 0 : byMembers.length === 1 ? byMembers[0] : z$1.union(byMembers);
|
|
3536
|
+
const bySchema = byElement ? this.orArray(byElement, true) : z$1.never();
|
|
3537
|
+
const baseSchema = z$1.strictObject({
|
|
3504
3538
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3505
3539
|
orderBy: this.orArray(this.makeOrderBySchema(model, false, true, options), true).optional(),
|
|
3506
3540
|
by: bySchema,
|
|
@@ -3552,7 +3586,7 @@ var ZodSchemaFactory = class {
|
|
|
3552
3586
|
if (!procDef) throw createInternalError(`Procedure not found: ${procName}`);
|
|
3553
3587
|
const shape = {};
|
|
3554
3588
|
for (const param of Object.values(procDef.params ?? {})) shape[param.name] = this.makeProcedureParamSchema(param);
|
|
3555
|
-
const schema = z.object(shape);
|
|
3589
|
+
const schema = z$1.object(shape);
|
|
3556
3590
|
this.registerSchema(`${procName}ProcArgs`, schema);
|
|
3557
3591
|
return schema;
|
|
3558
3592
|
}
|
|
@@ -3560,10 +3594,10 @@ var ZodSchemaFactory = class {
|
|
|
3560
3594
|
let schema;
|
|
3561
3595
|
if (isTypeDef(this.schema, param.type)) schema = this.makeTypeDefSchema(param.type);
|
|
3562
3596
|
else if (isEnum(this.schema, param.type)) schema = this.makeEnumSchema(param.type);
|
|
3563
|
-
else if (param.type in (this.schema.models ?? {})) schema = z.record(z.string(), z.unknown());
|
|
3597
|
+
else if (param.type in (this.schema.models ?? {})) schema = z$1.record(z$1.string(), z$1.unknown());
|
|
3564
3598
|
else {
|
|
3565
3599
|
schema = this.makeScalarSchema(param.type);
|
|
3566
|
-
if (schema instanceof z.ZodUnknown) throw createInternalError(`Unsupported procedure parameter type: ${param.type}`);
|
|
3600
|
+
if (schema instanceof z$1.ZodUnknown) throw createInternalError(`Unsupported procedure parameter type: ${param.type}`);
|
|
3567
3601
|
}
|
|
3568
3602
|
if (param.array) schema = schema.array();
|
|
3569
3603
|
if (param.optional) schema = schema.optional();
|
|
@@ -3599,10 +3633,10 @@ var ZodSchemaFactory = class {
|
|
|
3599
3633
|
return result;
|
|
3600
3634
|
}
|
|
3601
3635
|
makeSkipSchema() {
|
|
3602
|
-
return z.number().int().nonnegative();
|
|
3636
|
+
return z$1.number().int().nonnegative();
|
|
3603
3637
|
}
|
|
3604
3638
|
makeTakeSchema() {
|
|
3605
|
-
return z.number().int();
|
|
3639
|
+
return z$1.number().int();
|
|
3606
3640
|
}
|
|
3607
3641
|
refineForSelectIncludeMutuallyExclusive(schema) {
|
|
3608
3642
|
return schema.refine((value) => !(value["select"] && value["include"]), "\"select\" and \"include\" cannot be used together");
|
|
@@ -3621,7 +3655,7 @@ var ZodSchemaFactory = class {
|
|
|
3621
3655
|
return nullable ? schema.nullable() : schema;
|
|
3622
3656
|
}
|
|
3623
3657
|
orArray(schema, canBeArray) {
|
|
3624
|
-
return canBeArray ? z.union([schema, z.array(schema)]) : schema;
|
|
3658
|
+
return canBeArray ? z$1.union([schema, z$1.array(schema)]) : schema;
|
|
3625
3659
|
}
|
|
3626
3660
|
isNumericField(fieldDef) {
|
|
3627
3661
|
return NUMERIC_FIELD_TYPES.includes(fieldDef.type) && !fieldDef.array;
|
|
@@ -3683,10 +3717,10 @@ var ZodSchemaFactory = class {
|
|
|
3683
3717
|
createUnionFilterSchema(valueSchema, optional, components, allowedFilterKinds) {
|
|
3684
3718
|
if (Object.keys(components).length === 0) {
|
|
3685
3719
|
if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return this.nullableIf(valueSchema, optional);
|
|
3686
|
-
return z.never();
|
|
3720
|
+
return z$1.never();
|
|
3687
3721
|
}
|
|
3688
|
-
if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return z.union([this.nullableIf(valueSchema, optional), z.strictObject(components)]);
|
|
3689
|
-
else return z.strictObject(components);
|
|
3722
|
+
if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return z$1.union([this.nullableIf(valueSchema, optional), z$1.strictObject(components)]);
|
|
3723
|
+
else return z$1.strictObject(components);
|
|
3690
3724
|
}
|
|
3691
3725
|
canCreateModel(model) {
|
|
3692
3726
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -7392,9 +7426,9 @@ var ClientImpl = class ClientImpl {
|
|
|
7392
7426
|
validateOptions(baseClient, options) {
|
|
7393
7427
|
if (!baseClient && !options.skipValidationForComputedFields) this.validateComputedFieldsConfig(options);
|
|
7394
7428
|
if (options.diagnostics) {
|
|
7395
|
-
const parseResult = z
|
|
7396
|
-
slowQueryThresholdMs: z
|
|
7397
|
-
slowQueryMaxRecords: z
|
|
7429
|
+
const parseResult = z.object({
|
|
7430
|
+
slowQueryThresholdMs: z.number().nonnegative().optional(),
|
|
7431
|
+
slowQueryMaxRecords: z.int().nonnegative().or(z.literal(Infinity)).optional()
|
|
7398
7432
|
}).safeParse(options.diagnostics);
|
|
7399
7433
|
if (!parseResult.success) throw createConfigError(`Invalid diagnostics configuration: ${formatError(parseResult.error)}`);
|
|
7400
7434
|
}
|