@zenstackhq/orm 3.8.0 → 3.8.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 +50 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -1
- package/dist/index.d.mts +19 -3
- package/dist/index.mjs +238 -189
- 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";
|
|
@@ -195,6 +195,7 @@ var query_utils_exports = /* @__PURE__ */ __exportAll({
|
|
|
195
195
|
getField: () => getField,
|
|
196
196
|
getIdFields: () => getIdFields,
|
|
197
197
|
getIdValues: () => getIdValues,
|
|
198
|
+
getManyToManyJoinTable: () => getManyToManyJoinTable,
|
|
198
199
|
getManyToManyRelation: () => getManyToManyRelation,
|
|
199
200
|
getModel: () => getModel,
|
|
200
201
|
getModelFields: () => getModelFields,
|
|
@@ -220,8 +221,25 @@ var query_utils_exports = /* @__PURE__ */ __exportAll({
|
|
|
220
221
|
function hasModel(schema, model) {
|
|
221
222
|
return Object.keys(schema.models).map((k) => k.toLowerCase()).includes(model.toLowerCase());
|
|
222
223
|
}
|
|
224
|
+
const schemaLookupCache = /* @__PURE__ */ new WeakMap();
|
|
225
|
+
function getSchemaLookupCache(schema) {
|
|
226
|
+
let cache = schemaLookupCache.get(schema);
|
|
227
|
+
if (!cache) {
|
|
228
|
+
cache = {
|
|
229
|
+
model: /* @__PURE__ */ new Map(),
|
|
230
|
+
m2mRelation: /* @__PURE__ */ new Map()
|
|
231
|
+
};
|
|
232
|
+
schemaLookupCache.set(schema, cache);
|
|
233
|
+
}
|
|
234
|
+
return cache;
|
|
235
|
+
}
|
|
223
236
|
function getModel(schema, model) {
|
|
224
|
-
|
|
237
|
+
const cache = getSchemaLookupCache(schema);
|
|
238
|
+
const key = model.toLowerCase();
|
|
239
|
+
if (cache.model.has(key)) return cache.model.get(key);
|
|
240
|
+
const result = Object.values(schema.models).find((m) => m.name.toLowerCase() === key);
|
|
241
|
+
cache.model.set(key, result);
|
|
242
|
+
return result;
|
|
225
243
|
}
|
|
226
244
|
function getTypeDef(schema, type) {
|
|
227
245
|
return schema.typeDefs?.[type];
|
|
@@ -362,6 +380,37 @@ function makeDefaultOrderBy(schema, model) {
|
|
|
362
380
|
return requireIdFields(schema, model).map((f) => ({ [f]: "asc" }));
|
|
363
381
|
}
|
|
364
382
|
function getManyToManyRelation(schema, model, field) {
|
|
383
|
+
const cache = getSchemaLookupCache(schema);
|
|
384
|
+
const key = `${model} ${field}`;
|
|
385
|
+
if (cache.m2mRelation.has(key)) return cache.m2mRelation.get(key);
|
|
386
|
+
const result = computeManyToManyRelation(schema, model, field);
|
|
387
|
+
cache.m2mRelation.set(key, result);
|
|
388
|
+
return result;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Resolve the relation endpoints for an implicit many-to-many join table by its table
|
|
392
|
+
* name, or `undefined` if the table is not an implicit m2m join table. The join-table
|
|
393
|
+
* index is built once per schema (single pass) and reused, making this an O(1) lookup.
|
|
394
|
+
* See issue #2715.
|
|
395
|
+
*/
|
|
396
|
+
function getManyToManyJoinTable(schema, joinTableName) {
|
|
397
|
+
const cache = getSchemaLookupCache(schema);
|
|
398
|
+
if (!cache.m2mJoinTable) {
|
|
399
|
+
const map = /* @__PURE__ */ new Map();
|
|
400
|
+
for (const model of Object.values(schema.models)) for (const field of Object.values(model.fields)) {
|
|
401
|
+
const m2m = getManyToManyRelation(schema, model.name, field.name);
|
|
402
|
+
if (m2m?.joinTable && !map.has(m2m.joinTable)) map.set(m2m.joinTable, {
|
|
403
|
+
model: model.name,
|
|
404
|
+
field: field.name,
|
|
405
|
+
otherModel: m2m.otherModel,
|
|
406
|
+
otherField: m2m.otherField
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
cache.m2mJoinTable = map;
|
|
410
|
+
}
|
|
411
|
+
return cache.m2mJoinTable.get(joinTableName);
|
|
412
|
+
}
|
|
413
|
+
function computeManyToManyRelation(schema, model, field) {
|
|
365
414
|
const fieldDef = requireField(schema, model, field);
|
|
366
415
|
if (!fieldDef.array || !fieldDef.relation?.opposite) return;
|
|
367
416
|
const realModel = fieldDef.originModel ?? model;
|
|
@@ -2294,7 +2343,7 @@ function createQuerySchemaFactory(clientOrSchema, options) {
|
|
|
2294
2343
|
* @see https://github.com/zenstackhq/zenstack/issues/2631
|
|
2295
2344
|
*/
|
|
2296
2345
|
function coercedDateTimeSchema() {
|
|
2297
|
-
return z
|
|
2346
|
+
return z.preprocess((val) => {
|
|
2298
2347
|
if (typeof val !== "string") return val;
|
|
2299
2348
|
if (/^\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d\d(?::\d\d)?)?$/.test(val)) {
|
|
2300
2349
|
const hasTz = val.endsWith("Z") || /[+-]\d\d(?::\d\d)?$/.test(val);
|
|
@@ -2303,10 +2352,10 @@ function coercedDateTimeSchema() {
|
|
|
2303
2352
|
}
|
|
2304
2353
|
const d = new Date(val);
|
|
2305
2354
|
return isNaN(d.getTime()) ? val : d;
|
|
2306
|
-
}, z
|
|
2307
|
-
z
|
|
2308
|
-
z
|
|
2309
|
-
z
|
|
2355
|
+
}, z.union([
|
|
2356
|
+
z.iso.datetime(),
|
|
2357
|
+
z.iso.date(),
|
|
2358
|
+
z.date()
|
|
2310
2359
|
]));
|
|
2311
2360
|
}
|
|
2312
2361
|
/**
|
|
@@ -2314,7 +2363,7 @@ function coercedDateTimeSchema() {
|
|
|
2314
2363
|
*/
|
|
2315
2364
|
var ZodSchemaFactory = class {
|
|
2316
2365
|
schemaCache = /* @__PURE__ */ new Map();
|
|
2317
|
-
schemaRegistry = z
|
|
2366
|
+
schemaRegistry = z.registry();
|
|
2318
2367
|
allFilterKinds = [...new Set(Object.values(FILTER_PROPERTY_TO_KIND))];
|
|
2319
2368
|
schema;
|
|
2320
2369
|
options;
|
|
@@ -2406,7 +2455,7 @@ var ZodSchemaFactory = class {
|
|
|
2406
2455
|
this.makeGroupBySchema(m);
|
|
2407
2456
|
}
|
|
2408
2457
|
for (const procName of Object.keys(this.schema.procedures ?? {})) if (this.isProcedureAllowed(procName)) this.makeProcedureArgsSchema(procName);
|
|
2409
|
-
return z
|
|
2458
|
+
return z.toJSONSchema(this.schemaRegistry, { unrepresentable: "any" });
|
|
2410
2459
|
}
|
|
2411
2460
|
get cacheStats() {
|
|
2412
2461
|
return {
|
|
@@ -2435,13 +2484,13 @@ var ZodSchemaFactory = class {
|
|
|
2435
2484
|
fields["omit"] = this.makeOmitSchema(model).optional().nullable();
|
|
2436
2485
|
if (!unique) {
|
|
2437
2486
|
fields["skip"] = this.makeSkipSchema().optional();
|
|
2438
|
-
if (findOne) fields["take"] = z
|
|
2487
|
+
if (findOne) fields["take"] = z.literal(1).optional();
|
|
2439
2488
|
else fields["take"] = this.makeTakeSchema().optional();
|
|
2440
2489
|
fields["orderBy"] = this.orArray(this.makeOrderBySchema(model, true, false, options), true).optional();
|
|
2441
2490
|
fields["cursor"] = this.makeCursorSchema(model, options).optional();
|
|
2442
2491
|
fields["distinct"] = this.makeDistinctSchema(model).optional();
|
|
2443
2492
|
}
|
|
2444
|
-
const baseSchema = z
|
|
2493
|
+
const baseSchema = z.strictObject(fields);
|
|
2445
2494
|
let result = this.mergePluginArgsSchema(baseSchema, operation);
|
|
2446
2495
|
result = this.refineForSelectIncludeMutuallyExclusive(result);
|
|
2447
2496
|
result = this.refineForSelectOmitMutuallyExclusive(result);
|
|
@@ -2451,7 +2500,7 @@ var ZodSchemaFactory = class {
|
|
|
2451
2500
|
return result;
|
|
2452
2501
|
}
|
|
2453
2502
|
makeExistsSchema(model, options) {
|
|
2454
|
-
const baseSchema = z
|
|
2503
|
+
const baseSchema = z.strictObject({ where: this.makeWhereSchema(model, false, false, false, options).optional() });
|
|
2455
2504
|
const result = this.mergePluginArgsSchema(baseSchema, "exists").optional();
|
|
2456
2505
|
this.registerSchema(`${model}ExistsArgs`, result);
|
|
2457
2506
|
return result;
|
|
@@ -2459,31 +2508,31 @@ var ZodSchemaFactory = class {
|
|
|
2459
2508
|
makeScalarSchema(type, attributes) {
|
|
2460
2509
|
if (this.schema.typeDefs && type in this.schema.typeDefs) return this.makeTypeDefSchema(type);
|
|
2461
2510
|
else if (this.schema.enums && type in this.schema.enums) return this.makeEnumSchema(type);
|
|
2462
|
-
else return match(type).with("String", () => this.extraValidationsEnabled ? ZodUtils.addStringValidation(z
|
|
2463
|
-
return z
|
|
2464
|
-
this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z
|
|
2465
|
-
ZodUtils.addDecimalValidation(z
|
|
2466
|
-
ZodUtils.addDecimalValidation(z
|
|
2511
|
+
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", () => {
|
|
2512
|
+
return z.union([
|
|
2513
|
+
this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z.number(), attributes) : z.number(),
|
|
2514
|
+
ZodUtils.addDecimalValidation(z.instanceof(Decimal), attributes, this.extraValidationsEnabled),
|
|
2515
|
+
ZodUtils.addDecimalValidation(z.string(), attributes, this.extraValidationsEnabled)
|
|
2467
2516
|
]);
|
|
2468
|
-
}).with("DateTime", () => this.makeDateTimeValueSchema()).with("Bytes", () => z
|
|
2517
|
+
}).with("DateTime", () => this.makeDateTimeValueSchema()).with("Bytes", () => z.instanceof(Uint8Array)).with("Json", () => this.makeJsonValueSchema()).otherwise(() => z.unknown());
|
|
2469
2518
|
}
|
|
2470
2519
|
makeEnumSchema(_enum) {
|
|
2471
2520
|
const enumDef = getEnum(this.schema, _enum);
|
|
2472
2521
|
invariant(enumDef, `Enum "${_enum}" not found in schema`);
|
|
2473
|
-
const schema = z
|
|
2522
|
+
const schema = z.enum(Object.keys(enumDef.values));
|
|
2474
2523
|
this.registerSchema(_enum, schema);
|
|
2475
2524
|
return schema;
|
|
2476
2525
|
}
|
|
2477
2526
|
makeTypeDefSchema(type) {
|
|
2478
2527
|
const typeDef = getTypeDef(this.schema, type);
|
|
2479
2528
|
invariant(typeDef, `Type definition "${type}" not found in schema`);
|
|
2480
|
-
const schema = z
|
|
2481
|
-
let fieldSchema = isTypeDef(this.schema, def.type) ? z
|
|
2529
|
+
const schema = z.looseObject(Object.fromEntries(Object.entries(typeDef.fields).map(([field, def]) => {
|
|
2530
|
+
let fieldSchema = isTypeDef(this.schema, def.type) ? z.lazy(() => this.makeTypeDefSchema(def.type)) : this.makeScalarSchema(def.type);
|
|
2482
2531
|
if (def.array) fieldSchema = fieldSchema.array();
|
|
2483
2532
|
if (def.optional) fieldSchema = fieldSchema.nullish();
|
|
2484
2533
|
return [field, fieldSchema];
|
|
2485
2534
|
})));
|
|
2486
|
-
const finalSchema = z
|
|
2535
|
+
const finalSchema = z.any().superRefine((value, ctx) => {
|
|
2487
2536
|
const parseResult = schema.safeParse(value);
|
|
2488
2537
|
if (!parseResult.success) parseResult.error.issues.forEach((issue) => ctx.addIssue(issue));
|
|
2489
2538
|
});
|
|
@@ -2499,17 +2548,17 @@ var ZodSchemaFactory = class {
|
|
|
2499
2548
|
if (fieldDef.relation) {
|
|
2500
2549
|
if (withoutRelationFields || !this.shouldIncludeRelations(options)) continue;
|
|
2501
2550
|
const allowedFilterKinds = this.getEffectiveFilterKinds(model, field);
|
|
2502
|
-
if (allowedFilterKinds && !allowedFilterKinds.includes("Relation")) fieldSchema = z
|
|
2551
|
+
if (allowedFilterKinds && !allowedFilterKinds.includes("Relation")) fieldSchema = z.never();
|
|
2503
2552
|
else {
|
|
2504
|
-
fieldSchema = z
|
|
2505
|
-
if (fieldDef.array) fieldSchema = z
|
|
2553
|
+
fieldSchema = z.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts).optional());
|
|
2554
|
+
if (fieldDef.array) fieldSchema = z.strictObject({
|
|
2506
2555
|
some: fieldSchema.optional(),
|
|
2507
2556
|
every: fieldSchema.optional(),
|
|
2508
2557
|
none: fieldSchema.optional()
|
|
2509
2558
|
});
|
|
2510
2559
|
else {
|
|
2511
2560
|
fieldSchema = this.nullableIf(fieldSchema, !fieldDef.array && !!fieldDef.optional);
|
|
2512
|
-
fieldSchema = z
|
|
2561
|
+
fieldSchema = z.union([fieldSchema, z.strictObject({
|
|
2513
2562
|
is: fieldSchema.optional(),
|
|
2514
2563
|
isNot: fieldSchema.optional()
|
|
2515
2564
|
})]);
|
|
@@ -2528,21 +2577,21 @@ var ZodSchemaFactory = class {
|
|
|
2528
2577
|
}
|
|
2529
2578
|
if (unique) {
|
|
2530
2579
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
2531
|
-
for (const uniqueField of uniqueFields) if ("defs" in uniqueField) fields[uniqueField.name] = z
|
|
2580
|
+
for (const uniqueField of uniqueFields) if ("defs" in uniqueField) fields[uniqueField.name] = z.object(Object.fromEntries(Object.entries(uniqueField.defs).map(([key, def]) => {
|
|
2532
2581
|
invariant(!def.relation, "unique field cannot be a relation");
|
|
2533
2582
|
let fieldSchema;
|
|
2534
2583
|
const enumDef = getEnum(this.schema, def.type);
|
|
2535
2584
|
if (enumDef) if (Object.keys(enumDef.values).length > 0) fieldSchema = this.makeEnumFilterSchema(def.type, !!def.optional, !!def.array, false, void 0);
|
|
2536
|
-
else fieldSchema = z
|
|
2585
|
+
else fieldSchema = z.never();
|
|
2537
2586
|
else fieldSchema = this.makePrimitiveFilterSchema(def.type, !!def.optional, false, void 0);
|
|
2538
2587
|
return [key, fieldSchema];
|
|
2539
2588
|
}))).optional();
|
|
2540
2589
|
}
|
|
2541
|
-
fields["$expr"] = z
|
|
2542
|
-
fields["AND"] = this.orArray(z
|
|
2543
|
-
fields["OR"] = z
|
|
2544
|
-
fields["NOT"] = this.orArray(z
|
|
2545
|
-
const baseWhere = z
|
|
2590
|
+
fields["$expr"] = z.custom((v) => typeof v === "function", { error: "\"$expr\" must be a function" }).optional();
|
|
2591
|
+
fields["AND"] = this.orArray(z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
|
|
2592
|
+
fields["OR"] = z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)).array().optional();
|
|
2593
|
+
fields["NOT"] = this.orArray(z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
|
|
2594
|
+
const baseWhere = z.strictObject(fields);
|
|
2546
2595
|
let result = baseWhere;
|
|
2547
2596
|
if (unique) {
|
|
2548
2597
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
@@ -2568,26 +2617,26 @@ var ZodSchemaFactory = class {
|
|
|
2568
2617
|
else if (getEnum(this.schema, fieldDef.type)) fieldSchemas[fieldName] = this.makeEnumFilterSchema(fieldDef.type, !!fieldDef.optional, !!fieldDef.array, false, void 0).optional();
|
|
2569
2618
|
else if (fieldDef.array) fieldSchemas[fieldName] = this.makeArrayFilterSchema(fieldDef.type, void 0).optional();
|
|
2570
2619
|
else fieldSchemas[fieldName] = this.makePrimitiveFilterSchema(fieldDef.type, !!fieldDef.optional, false, void 0).optional();
|
|
2571
|
-
candidates.push(z
|
|
2620
|
+
candidates.push(z.strictObject(fieldSchemas));
|
|
2572
2621
|
}
|
|
2573
|
-
const recursiveSchema = z
|
|
2574
|
-
if (array) candidates.push(z
|
|
2622
|
+
const recursiveSchema = z.lazy(() => this.makeTypedJsonFilterSchema(type, optional, false, allowedFilterKinds)).optional();
|
|
2623
|
+
if (array) candidates.push(z.strictObject({
|
|
2575
2624
|
some: recursiveSchema,
|
|
2576
2625
|
every: recursiveSchema,
|
|
2577
2626
|
none: recursiveSchema
|
|
2578
2627
|
}));
|
|
2579
|
-
else candidates.push(z
|
|
2628
|
+
else candidates.push(z.strictObject({
|
|
2580
2629
|
is: recursiveSchema,
|
|
2581
2630
|
isNot: recursiveSchema
|
|
2582
2631
|
}));
|
|
2583
2632
|
candidates.push(this.makeJsonFilterSchema(optional, allowedFilterKinds));
|
|
2584
2633
|
if (optional) {
|
|
2585
|
-
candidates.push(z
|
|
2586
|
-
candidates.push(z
|
|
2587
|
-
candidates.push(z
|
|
2588
|
-
candidates.push(z
|
|
2634
|
+
candidates.push(z.null());
|
|
2635
|
+
candidates.push(z.instanceof(DbNullClass));
|
|
2636
|
+
candidates.push(z.instanceof(JsonNullClass));
|
|
2637
|
+
candidates.push(z.instanceof(AnyNullClass));
|
|
2589
2638
|
}
|
|
2590
|
-
const result = z
|
|
2639
|
+
const result = z.union(candidates);
|
|
2591
2640
|
this.registerSchema(`${type}Filter${this.filterSchemaSuffix({
|
|
2592
2641
|
optional,
|
|
2593
2642
|
array,
|
|
@@ -2596,7 +2645,7 @@ var ZodSchemaFactory = class {
|
|
|
2596
2645
|
return result;
|
|
2597
2646
|
}
|
|
2598
2647
|
makeNullableTypedJsonMutationSchema(fieldSchema) {
|
|
2599
|
-
return z
|
|
2648
|
+
return z.any().superRefine((value, ctx) => {
|
|
2600
2649
|
if (value instanceof DbNullClass || value instanceof JsonNullClass || value === null || value === void 0) return;
|
|
2601
2650
|
const parseResult = fieldSchema.safeParse(value);
|
|
2602
2651
|
if (!parseResult.success) parseResult.error.issues.forEach((issue) => ctx.addIssue(issue));
|
|
@@ -2608,11 +2657,11 @@ var ZodSchemaFactory = class {
|
|
|
2608
2657
|
makeEnumFilterSchema(enumName, optional, array, withAggregations, allowedFilterKinds) {
|
|
2609
2658
|
const enumDef = getEnum(this.schema, enumName);
|
|
2610
2659
|
invariant(enumDef, `Enum "${enumName}" not found in schema`);
|
|
2611
|
-
const baseSchema = z
|
|
2660
|
+
const baseSchema = z.enum(Object.keys(enumDef.values));
|
|
2612
2661
|
let schema;
|
|
2613
2662
|
if (array) schema = this.internalMakeArrayFilterSchema(baseSchema, allowedFilterKinds);
|
|
2614
2663
|
else {
|
|
2615
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z
|
|
2664
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z.lazy(() => this.makeEnumFilterSchema(enumName, optional, array, withAggregations, allowedFilterKinds)), [
|
|
2616
2665
|
"equals",
|
|
2617
2666
|
"in",
|
|
2618
2667
|
"notIn",
|
|
@@ -2646,42 +2695,42 @@ var ZodSchemaFactory = class {
|
|
|
2646
2695
|
has: elementSchema.optional(),
|
|
2647
2696
|
hasEvery: elementSchema.array().optional(),
|
|
2648
2697
|
hasSome: elementSchema.array().optional(),
|
|
2649
|
-
isEmpty: z
|
|
2698
|
+
isEmpty: z.boolean().optional()
|
|
2650
2699
|
};
|
|
2651
2700
|
const filteredOperators = this.trimFilterOperators(operators, allowedFilterKinds);
|
|
2652
|
-
return z
|
|
2701
|
+
return z.strictObject(filteredOperators);
|
|
2653
2702
|
}
|
|
2654
2703
|
makePrimitiveFilterSchema(type, optional, withAggregations, allowedFilterKinds, withFuzzy = false, withFullText = false) {
|
|
2655
|
-
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
|
|
2704
|
+
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();
|
|
2656
2705
|
}
|
|
2657
2706
|
makeJsonValueSchema() {
|
|
2658
|
-
const schema = z
|
|
2659
|
-
z
|
|
2660
|
-
z
|
|
2661
|
-
z
|
|
2662
|
-
z
|
|
2663
|
-
z
|
|
2664
|
-
z
|
|
2707
|
+
const schema = z.union([
|
|
2708
|
+
z.string(),
|
|
2709
|
+
z.number(),
|
|
2710
|
+
z.boolean(),
|
|
2711
|
+
z.instanceof(JsonNullClass),
|
|
2712
|
+
z.lazy(() => z.union([this.makeJsonValueSchema(), z.null()]).array()),
|
|
2713
|
+
z.record(z.string(), z.lazy(() => z.union([this.makeJsonValueSchema(), z.null()])))
|
|
2665
2714
|
]);
|
|
2666
2715
|
this.registerSchema("JsonValue", schema);
|
|
2667
2716
|
return schema;
|
|
2668
2717
|
}
|
|
2669
2718
|
makeJsonFilterSchema(optional, allowedFilterKinds) {
|
|
2670
|
-
if (allowedFilterKinds && !allowedFilterKinds.includes("Json")) return z
|
|
2719
|
+
if (allowedFilterKinds && !allowedFilterKinds.includes("Json")) return z.never();
|
|
2671
2720
|
const filterMembers = [
|
|
2672
2721
|
this.makeJsonValueSchema(),
|
|
2673
|
-
z
|
|
2674
|
-
z
|
|
2722
|
+
z.instanceof(DbNullClass),
|
|
2723
|
+
z.instanceof(AnyNullClass)
|
|
2675
2724
|
];
|
|
2676
|
-
if (optional) filterMembers.push(z
|
|
2677
|
-
const filterValueSchema = z
|
|
2678
|
-
const schema = z
|
|
2679
|
-
path: z
|
|
2725
|
+
if (optional) filterMembers.push(z.null());
|
|
2726
|
+
const filterValueSchema = z.union(filterMembers);
|
|
2727
|
+
const schema = z.strictObject({
|
|
2728
|
+
path: z.string().optional(),
|
|
2680
2729
|
equals: filterValueSchema.optional(),
|
|
2681
2730
|
not: filterValueSchema.optional(),
|
|
2682
|
-
string_contains: z
|
|
2683
|
-
string_starts_with: z
|
|
2684
|
-
string_ends_with: z
|
|
2731
|
+
string_contains: z.string().optional(),
|
|
2732
|
+
string_starts_with: z.string().optional(),
|
|
2733
|
+
string_ends_with: z.string().optional(),
|
|
2685
2734
|
mode: this.makeStringModeSchema().optional(),
|
|
2686
2735
|
array_contains: filterValueSchema.optional(),
|
|
2687
2736
|
array_starts_with: filterValueSchema.optional(),
|
|
@@ -2700,7 +2749,7 @@ var ZodSchemaFactory = class {
|
|
|
2700
2749
|
}
|
|
2701
2750
|
makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
2702
2751
|
const filterValueSchema = this.makeDateTimeValueSchema();
|
|
2703
|
-
const schema = this.makeCommonPrimitiveFilterSchema(filterValueSchema, optional, () => z
|
|
2752
|
+
const schema = this.makeCommonPrimitiveFilterSchema(filterValueSchema, optional, () => z.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)), withAggregations ? [
|
|
2704
2753
|
"_count",
|
|
2705
2754
|
"_min",
|
|
2706
2755
|
"_max"
|
|
@@ -2713,12 +2762,12 @@ var ZodSchemaFactory = class {
|
|
|
2713
2762
|
return schema;
|
|
2714
2763
|
}
|
|
2715
2764
|
makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
2716
|
-
const components = this.makeCommonPrimitiveFilterComponents(z
|
|
2765
|
+
const components = this.makeCommonPrimitiveFilterComponents(z.boolean(), optional, () => z.lazy(() => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)), ["equals", "not"], withAggregations ? [
|
|
2717
2766
|
"_count",
|
|
2718
2767
|
"_min",
|
|
2719
2768
|
"_max"
|
|
2720
2769
|
] : void 0, allowedFilterKinds);
|
|
2721
|
-
const schema = this.createUnionFilterSchema(z
|
|
2770
|
+
const schema = this.createUnionFilterSchema(z.boolean(), optional, components, allowedFilterKinds);
|
|
2722
2771
|
this.registerSchema(`BooleanFilter${this.filterSchemaSuffix({
|
|
2723
2772
|
optional,
|
|
2724
2773
|
allowedFilterKinds,
|
|
@@ -2727,8 +2776,8 @@ var ZodSchemaFactory = class {
|
|
|
2727
2776
|
return schema;
|
|
2728
2777
|
}
|
|
2729
2778
|
makeBytesFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
2730
|
-
const baseSchema = z
|
|
2731
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z
|
|
2779
|
+
const baseSchema = z.instanceof(Uint8Array);
|
|
2780
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z.instanceof(Uint8Array), [
|
|
2732
2781
|
"equals",
|
|
2733
2782
|
"in",
|
|
2734
2783
|
"notIn",
|
|
@@ -2776,7 +2825,7 @@ var ZodSchemaFactory = class {
|
|
|
2776
2825
|
return this.createUnionFilterSchema(baseSchema, optional, components, allowedFilterKinds);
|
|
2777
2826
|
}
|
|
2778
2827
|
makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds) {
|
|
2779
|
-
const schema = this.makeCommonPrimitiveFilterSchema(this.makeScalarSchema(type), optional, () => z
|
|
2828
|
+
const schema = this.makeCommonPrimitiveFilterSchema(this.makeScalarSchema(type), optional, () => z.lazy(() => this.makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds)), withAggregations ? [
|
|
2780
2829
|
"_count",
|
|
2781
2830
|
"_avg",
|
|
2782
2831
|
"_sum",
|
|
@@ -2791,15 +2840,15 @@ var ZodSchemaFactory = class {
|
|
|
2791
2840
|
return schema;
|
|
2792
2841
|
}
|
|
2793
2842
|
makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy = false, withFullText = false) {
|
|
2794
|
-
const baseComponents = this.makeCommonPrimitiveFilterComponents(z
|
|
2843
|
+
const baseComponents = this.makeCommonPrimitiveFilterComponents(z.string(), optional, () => z.lazy(() => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy, withFullText)), void 0, withAggregations ? [
|
|
2795
2844
|
"_count",
|
|
2796
2845
|
"_min",
|
|
2797
2846
|
"_max"
|
|
2798
2847
|
] : void 0, allowedFilterKinds);
|
|
2799
2848
|
const stringSpecificOperators = {
|
|
2800
|
-
startsWith: z
|
|
2801
|
-
endsWith: z
|
|
2802
|
-
contains: z
|
|
2849
|
+
startsWith: z.string().optional(),
|
|
2850
|
+
endsWith: z.string().optional(),
|
|
2851
|
+
contains: z.string().optional(),
|
|
2803
2852
|
...withFuzzy && this.providerSupportsFuzzySearch ? { fuzzy: this.makeFuzzyFilterSchema().optional() } : {},
|
|
2804
2853
|
...withFullText && this.providerSupportsFullTextSearch ? { fts: this.makeFullTextFilterSchema().optional() } : {},
|
|
2805
2854
|
...this.providerSupportsCaseSensitivity ? { mode: this.makeStringModeSchema().optional() } : {}
|
|
@@ -2809,7 +2858,7 @@ var ZodSchemaFactory = class {
|
|
|
2809
2858
|
...baseComponents,
|
|
2810
2859
|
...filteredStringOperators
|
|
2811
2860
|
};
|
|
2812
|
-
const schema = this.createUnionFilterSchema(z
|
|
2861
|
+
const schema = this.createUnionFilterSchema(z.string(), optional, allComponents, allowedFilterKinds);
|
|
2813
2862
|
const featureSuffix = `${withFuzzy ? "Fuzzy" : ""}${withFullText ? "FullText" : ""}`;
|
|
2814
2863
|
this.registerSchema(`StringFilter${this.filterSchemaSuffix({
|
|
2815
2864
|
optional,
|
|
@@ -2819,24 +2868,24 @@ var ZodSchemaFactory = class {
|
|
|
2819
2868
|
return schema;
|
|
2820
2869
|
}
|
|
2821
2870
|
makeStringModeSchema() {
|
|
2822
|
-
return z
|
|
2871
|
+
return z.union([z.literal("default"), z.literal("insensitive")]);
|
|
2823
2872
|
}
|
|
2824
2873
|
makeFuzzyFilterSchema() {
|
|
2825
|
-
return z
|
|
2826
|
-
search: z
|
|
2827
|
-
mode: z
|
|
2828
|
-
z
|
|
2829
|
-
z
|
|
2830
|
-
z
|
|
2874
|
+
return z.strictObject({
|
|
2875
|
+
search: z.string().min(1),
|
|
2876
|
+
mode: z.union([
|
|
2877
|
+
z.literal("simple"),
|
|
2878
|
+
z.literal("word"),
|
|
2879
|
+
z.literal("strictWord")
|
|
2831
2880
|
]).default("simple"),
|
|
2832
|
-
threshold: z
|
|
2833
|
-
unaccent: z
|
|
2881
|
+
threshold: z.number().min(0).max(1).optional(),
|
|
2882
|
+
unaccent: z.boolean().default(false)
|
|
2834
2883
|
});
|
|
2835
2884
|
}
|
|
2836
2885
|
makeFullTextFilterSchema() {
|
|
2837
|
-
return z
|
|
2838
|
-
search: z
|
|
2839
|
-
config: z
|
|
2886
|
+
return z.strictObject({
|
|
2887
|
+
search: z.string().min(1),
|
|
2888
|
+
config: z.string().min(1).optional()
|
|
2840
2889
|
});
|
|
2841
2890
|
}
|
|
2842
2891
|
makeSelectSchema(model, options) {
|
|
@@ -2844,14 +2893,14 @@ var ZodSchemaFactory = class {
|
|
|
2844
2893
|
for (const [field, fieldDef] of this.getModelFields(model)) if (fieldDef.relation) {
|
|
2845
2894
|
if (!this.shouldIncludeRelations(options)) continue;
|
|
2846
2895
|
if (this.isModelAllowed(fieldDef.type)) fields[field] = this.makeRelationSelectIncludeSchema(model, field, options).optional();
|
|
2847
|
-
} else if (this.options.allowQueryTimeOmitOverride === false && this.isFieldOmittedByConfig(model, field)) fields[field] = z
|
|
2848
|
-
else fields[field] = z
|
|
2896
|
+
} else if (this.options.allowQueryTimeOmitOverride === false && this.isFieldOmittedByConfig(model, field)) fields[field] = z.literal(false).optional();
|
|
2897
|
+
else fields[field] = z.boolean().optional();
|
|
2849
2898
|
if (this.shouldIncludeRelations(options)) {
|
|
2850
2899
|
const _countSchema = this.makeCountSelectionSchema(model, options);
|
|
2851
|
-
if (!(_countSchema instanceof z
|
|
2900
|
+
if (!(_countSchema instanceof z.ZodNever)) fields["_count"] = _countSchema;
|
|
2852
2901
|
}
|
|
2853
2902
|
this.addExtResultFields(model, fields);
|
|
2854
|
-
const result = z
|
|
2903
|
+
const result = z.strictObject(fields);
|
|
2855
2904
|
this.registerSchema(`${model}Select`, result);
|
|
2856
2905
|
return result;
|
|
2857
2906
|
}
|
|
@@ -2860,24 +2909,24 @@ var ZodSchemaFactory = class {
|
|
|
2860
2909
|
const toManyRelations = Object.values(modelDef.fields).filter((def) => def.relation && def.array);
|
|
2861
2910
|
if (toManyRelations.length > 0) {
|
|
2862
2911
|
const nextOpts = this.nextOptions(options);
|
|
2863
|
-
const schema = z
|
|
2912
|
+
const schema = z.union([z.literal(true), z.strictObject({ select: z.strictObject(toManyRelations.reduce((acc, fieldDef) => ({
|
|
2864
2913
|
...acc,
|
|
2865
|
-
[fieldDef.name]: z
|
|
2914
|
+
[fieldDef.name]: z.union([z.boolean(), z.strictObject({ where: this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts) })]).optional()
|
|
2866
2915
|
}), {})) })]).optional();
|
|
2867
2916
|
this.registerSchema(`${model}CountSelection`, schema);
|
|
2868
2917
|
return schema;
|
|
2869
|
-
} else return z
|
|
2918
|
+
} else return z.never();
|
|
2870
2919
|
}
|
|
2871
2920
|
makeRelationSelectIncludeSchema(model, field, options) {
|
|
2872
2921
|
const fieldDef = requireField(this.schema, model, field);
|
|
2873
2922
|
const nextOpts = this.nextOptions(options);
|
|
2874
|
-
let objSchema = z
|
|
2875
|
-
...fieldDef.array || fieldDef.optional ? { where: z
|
|
2876
|
-
select: z
|
|
2877
|
-
include: z
|
|
2878
|
-
omit: z
|
|
2923
|
+
let objSchema = z.strictObject({
|
|
2924
|
+
...fieldDef.array || fieldDef.optional ? { where: z.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts)).optional() } : {},
|
|
2925
|
+
select: z.lazy(() => this.makeSelectSchema(fieldDef.type, nextOpts)).optional().nullable(),
|
|
2926
|
+
include: z.lazy(() => this.makeIncludeSchema(fieldDef.type, nextOpts)).optional().nullable(),
|
|
2927
|
+
omit: z.lazy(() => this.makeOmitSchema(fieldDef.type)).optional().nullable(),
|
|
2879
2928
|
...fieldDef.array ? {
|
|
2880
|
-
orderBy: z
|
|
2929
|
+
orderBy: z.lazy(() => this.orArray(this.makeOrderBySchema(fieldDef.type, true, false, nextOpts), true)).optional(),
|
|
2881
2930
|
skip: this.makeSkipSchema().optional(),
|
|
2882
2931
|
take: this.makeTakeSchema().optional(),
|
|
2883
2932
|
cursor: this.makeCursorSchema(fieldDef.type, nextOpts).optional(),
|
|
@@ -2887,7 +2936,7 @@ var ZodSchemaFactory = class {
|
|
|
2887
2936
|
objSchema = this.refineForSelectIncludeMutuallyExclusive(objSchema);
|
|
2888
2937
|
objSchema = this.refineForSelectOmitMutuallyExclusive(objSchema);
|
|
2889
2938
|
objSchema = this.refineForSelectHasTruthyField(objSchema);
|
|
2890
|
-
const result = z
|
|
2939
|
+
const result = z.union([z.boolean(), objSchema]);
|
|
2891
2940
|
this.registerSchema(`${model}${upperCaseFirst(field)}RelationInput`, result);
|
|
2892
2941
|
return result;
|
|
2893
2942
|
}
|
|
@@ -2902,10 +2951,10 @@ var ZodSchemaFactory = class {
|
|
|
2902
2951
|
}
|
|
2903
2952
|
makeOmitSchema(model) {
|
|
2904
2953
|
const fields = {};
|
|
2905
|
-
for (const [field, fieldDef] of this.getModelFields(model)) if (!fieldDef.relation) if (this.options.allowQueryTimeOmitOverride !== false) fields[field] = z
|
|
2906
|
-
else fields[field] = z
|
|
2954
|
+
for (const [field, fieldDef] of this.getModelFields(model)) if (!fieldDef.relation) if (this.options.allowQueryTimeOmitOverride !== false) fields[field] = z.boolean().optional();
|
|
2955
|
+
else fields[field] = z.literal(true).optional();
|
|
2907
2956
|
this.addExtResultFields(model, fields);
|
|
2908
|
-
const result = z
|
|
2957
|
+
const result = z.strictObject(fields);
|
|
2909
2958
|
this.registerSchema(`${model}OmitInput`, result);
|
|
2910
2959
|
return result;
|
|
2911
2960
|
}
|
|
@@ -2914,7 +2963,7 @@ var ZodSchemaFactory = class {
|
|
|
2914
2963
|
const resultConfig = plugin.result;
|
|
2915
2964
|
if (resultConfig) {
|
|
2916
2965
|
const modelConfig = resultConfig[lowerCaseFirst(model)];
|
|
2917
|
-
if (modelConfig) for (const field of Object.keys(modelConfig)) fields[field] = z
|
|
2966
|
+
if (modelConfig) for (const field of Object.keys(modelConfig)) fields[field] = z.boolean().optional();
|
|
2918
2967
|
}
|
|
2919
2968
|
}
|
|
2920
2969
|
}
|
|
@@ -2930,26 +2979,26 @@ var ZodSchemaFactory = class {
|
|
|
2930
2979
|
}
|
|
2931
2980
|
if (this.shouldIncludeRelations(options)) {
|
|
2932
2981
|
const _countSchema = this.makeCountSelectionSchema(model, options);
|
|
2933
|
-
if (!(_countSchema instanceof z
|
|
2982
|
+
if (!(_countSchema instanceof z.ZodNever)) fields["_count"] = _countSchema;
|
|
2934
2983
|
}
|
|
2935
|
-
const result = z
|
|
2984
|
+
const result = z.strictObject(fields);
|
|
2936
2985
|
this.registerSchema(`${model}Include`, result);
|
|
2937
2986
|
return result;
|
|
2938
2987
|
}
|
|
2939
2988
|
makeOrderBySchema(model, withRelation, WithAggregation, options) {
|
|
2940
2989
|
const fields = {};
|
|
2941
|
-
const sort = z
|
|
2990
|
+
const sort = z.union([z.literal("asc"), z.literal("desc")]);
|
|
2942
2991
|
const refineAtMostOneKey = (s) => s.refine((v) => Object.keys(v).length <= 1, { message: "Each orderBy element must have at most one key" });
|
|
2943
2992
|
const nextOpts = this.nextOptions(options);
|
|
2944
2993
|
for (const [field, fieldDef] of this.getModelFields(model)) if (fieldDef.relation) {
|
|
2945
|
-
if (withRelation && this.shouldIncludeRelations(options)) fields[field] = z
|
|
2994
|
+
if (withRelation && this.shouldIncludeRelations(options)) fields[field] = z.lazy(() => {
|
|
2946
2995
|
let relationOrderBy = this.makeOrderBySchema(fieldDef.type, withRelation, WithAggregation, nextOpts);
|
|
2947
2996
|
if (fieldDef.array) relationOrderBy = refineAtMostOneKey(relationOrderBy.safeExtend({ _count: sort }));
|
|
2948
2997
|
return relationOrderBy;
|
|
2949
2998
|
}).optional();
|
|
2950
|
-
} else if (fieldDef.optional) fields[field] = z
|
|
2999
|
+
} else if (fieldDef.optional) fields[field] = z.union([sort, z.strictObject({
|
|
2951
3000
|
sort,
|
|
2952
|
-
nulls: z
|
|
3001
|
+
nulls: z.union([z.literal("first"), z.literal("last")]).optional()
|
|
2953
3002
|
})]).optional();
|
|
2954
3003
|
else fields[field] = sort.optional();
|
|
2955
3004
|
if (WithAggregation) for (const agg of [
|
|
@@ -2958,31 +3007,31 @@ var ZodSchemaFactory = class {
|
|
|
2958
3007
|
"_sum",
|
|
2959
3008
|
"_min",
|
|
2960
3009
|
"_max"
|
|
2961
|
-
]) fields[agg] = z
|
|
3010
|
+
]) fields[agg] = z.lazy(() => this.makeOrderBySchema(model, true, false, options).optional());
|
|
2962
3011
|
if (this.providerSupportsFuzzySearch) {
|
|
2963
3012
|
const fuzzyFieldNames = this.getModelFields(model).filter(([, def]) => !def.relation && def.type === "String" && def.fuzzy === true).map(([name]) => name);
|
|
2964
|
-
if (fuzzyFieldNames.length > 0) fields["_fuzzyRelevance"] = z
|
|
2965
|
-
fields: z
|
|
2966
|
-
search: z
|
|
2967
|
-
mode: z
|
|
2968
|
-
z
|
|
2969
|
-
z
|
|
2970
|
-
z
|
|
3013
|
+
if (fuzzyFieldNames.length > 0) fields["_fuzzyRelevance"] = z.strictObject({
|
|
3014
|
+
fields: z.array(z.enum(fuzzyFieldNames)).min(1),
|
|
3015
|
+
search: z.string(),
|
|
3016
|
+
mode: z.union([
|
|
3017
|
+
z.literal("simple"),
|
|
3018
|
+
z.literal("word"),
|
|
3019
|
+
z.literal("strictWord")
|
|
2971
3020
|
]).default("simple"),
|
|
2972
|
-
unaccent: z
|
|
3021
|
+
unaccent: z.boolean().default(false),
|
|
2973
3022
|
sort
|
|
2974
3023
|
}).optional();
|
|
2975
3024
|
}
|
|
2976
3025
|
if (this.providerSupportsFullTextSearch) {
|
|
2977
3026
|
const fullTextFieldNames = this.getModelFields(model).filter(([, def]) => !def.relation && def.type === "String" && def.fullText === true).map(([name]) => name);
|
|
2978
|
-
if (fullTextFieldNames.length > 0) fields["_ftsRelevance"] = z
|
|
2979
|
-
fields: z
|
|
2980
|
-
search: z
|
|
2981
|
-
config: z
|
|
3027
|
+
if (fullTextFieldNames.length > 0) fields["_ftsRelevance"] = z.strictObject({
|
|
3028
|
+
fields: z.array(z.enum(fullTextFieldNames)).min(1),
|
|
3029
|
+
search: z.string().min(1),
|
|
3030
|
+
config: z.string().min(1).optional(),
|
|
2982
3031
|
sort
|
|
2983
3032
|
}).optional();
|
|
2984
3033
|
}
|
|
2985
|
-
const schema = refineAtMostOneKey(z
|
|
3034
|
+
const schema = refineAtMostOneKey(z.strictObject(fields));
|
|
2986
3035
|
let schemaId = `${model}OrderBy`;
|
|
2987
3036
|
if (withRelation) schemaId += "WithRelation";
|
|
2988
3037
|
if (WithAggregation) schemaId += "WithAggregation";
|
|
@@ -2992,7 +3041,7 @@ var ZodSchemaFactory = class {
|
|
|
2992
3041
|
}
|
|
2993
3042
|
makeDistinctSchema(model) {
|
|
2994
3043
|
const nonRelationFields = this.getModelFields(model).filter(([, def]) => !def.relation).map(([name]) => name);
|
|
2995
|
-
const schema = nonRelationFields.length > 0 ? this.orArray(z
|
|
3044
|
+
const schema = nonRelationFields.length > 0 ? this.orArray(z.enum(nonRelationFields), true) : z.never();
|
|
2996
3045
|
this.registerSchema(`${model}DistinctInput`, schema);
|
|
2997
3046
|
return schema;
|
|
2998
3047
|
}
|
|
@@ -3003,7 +3052,7 @@ var ZodSchemaFactory = class {
|
|
|
3003
3052
|
}
|
|
3004
3053
|
makeCreateSchema(model, options) {
|
|
3005
3054
|
const dataSchema = this.makeCreateDataSchema(model, false, [], false, options);
|
|
3006
|
-
const baseSchema = z
|
|
3055
|
+
const baseSchema = z.strictObject({
|
|
3007
3056
|
data: dataSchema,
|
|
3008
3057
|
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
3009
3058
|
include: this.makeIncludeSchema(model, options).optional().nullable(),
|
|
@@ -3052,7 +3101,7 @@ var ZodSchemaFactory = class {
|
|
|
3052
3101
|
const oppositeFieldDef = requireField(this.schema, fieldDef.type, oppositeField);
|
|
3053
3102
|
if (oppositeFieldDef.relation?.fields) excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
3054
3103
|
}
|
|
3055
|
-
let fieldSchema = z
|
|
3104
|
+
let fieldSchema = z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "create", nextOpts));
|
|
3056
3105
|
if (fieldDef.optional || fieldDef.array) fieldSchema = fieldSchema.optional();
|
|
3057
3106
|
else {
|
|
3058
3107
|
let allFksOptional = false;
|
|
@@ -3069,23 +3118,23 @@ var ZodSchemaFactory = class {
|
|
|
3069
3118
|
let fieldSchema = this.makeScalarSchema(fieldDef.type, fieldDef.attributes);
|
|
3070
3119
|
if (fieldDef.array) {
|
|
3071
3120
|
fieldSchema = ZodUtils.addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
3072
|
-
fieldSchema = z
|
|
3121
|
+
fieldSchema = z.union([fieldSchema, z.strictObject({ set: fieldSchema })]).optional();
|
|
3073
3122
|
}
|
|
3074
3123
|
if (fieldDef.optional || fieldHasDefaultValue(fieldDef)) fieldSchema = fieldSchema.optional();
|
|
3075
|
-
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z
|
|
3124
|
+
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z.union([fieldSchema, z.instanceof(DbNullClass)]);
|
|
3076
3125
|
else if (this.isTypeDefType(fieldDef.type)) fieldSchema = this.makeNullableTypedJsonMutationSchema(fieldSchema);
|
|
3077
3126
|
else fieldSchema = fieldSchema.nullable();
|
|
3078
3127
|
uncheckedVariantFields[field] = fieldSchema;
|
|
3079
3128
|
if (!fieldDef.foreignKeyFor) checkedVariantFields[field] = fieldSchema;
|
|
3080
3129
|
}
|
|
3081
3130
|
});
|
|
3082
|
-
const uncheckedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z
|
|
3083
|
-
const checkedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z
|
|
3084
|
-
const result = !hasRelation ? this.orArray(uncheckedCreateSchema, canBeArray) : z
|
|
3131
|
+
const uncheckedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(uncheckedVariantFields), modelDef.attributes) : z.strictObject(uncheckedVariantFields);
|
|
3132
|
+
const checkedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(checkedVariantFields), modelDef.attributes) : z.strictObject(checkedVariantFields);
|
|
3133
|
+
const result = !hasRelation ? this.orArray(uncheckedCreateSchema, canBeArray) : z.union([
|
|
3085
3134
|
uncheckedCreateSchema,
|
|
3086
3135
|
checkedCreateSchema,
|
|
3087
|
-
...canBeArray ? [z
|
|
3088
|
-
...canBeArray ? [z
|
|
3136
|
+
...canBeArray ? [z.array(uncheckedCreateSchema)] : [],
|
|
3137
|
+
...canBeArray ? [z.array(checkedCreateSchema)] : []
|
|
3089
3138
|
]);
|
|
3090
3139
|
const idParts = [`${model}CreateData`];
|
|
3091
3140
|
if (canBeArray) idParts.push("Array");
|
|
@@ -3110,17 +3159,17 @@ var ZodSchemaFactory = class {
|
|
|
3110
3159
|
fields["disconnect"] = this.makeDisconnectDataSchema(fieldType, array, options).optional();
|
|
3111
3160
|
fields["delete"] = this.makeDeleteRelationDataSchema(fieldType, array, true, options).optional();
|
|
3112
3161
|
}
|
|
3113
|
-
fields["update"] = array ? this.orArray(z
|
|
3162
|
+
fields["update"] = array ? this.orArray(z.strictObject({
|
|
3114
3163
|
where: this.makeWhereSchema(fieldType, true, false, false, options),
|
|
3115
3164
|
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
3116
|
-
}), true).optional() : z
|
|
3165
|
+
}), true).optional() : z.union([z.strictObject({
|
|
3117
3166
|
where: this.makeWhereSchema(fieldType, false, false, false, options).optional(),
|
|
3118
3167
|
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
3119
3168
|
}), this.makeUpdateDataSchema(fieldType, withoutFields, false, options)]).optional();
|
|
3120
3169
|
if (canCreateModel) {
|
|
3121
3170
|
let upsertWhere = this.makeWhereSchema(fieldType, true, false, false, options);
|
|
3122
3171
|
if (!fieldDef.array) upsertWhere = upsertWhere.optional();
|
|
3123
|
-
fields["upsert"] = this.orArray(z
|
|
3172
|
+
fields["upsert"] = this.orArray(z.strictObject({
|
|
3124
3173
|
where: upsertWhere,
|
|
3125
3174
|
create: this.makeCreateDataSchema(fieldType, false, withoutFields, false, options),
|
|
3126
3175
|
update: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
@@ -3128,14 +3177,14 @@ var ZodSchemaFactory = class {
|
|
|
3128
3177
|
}
|
|
3129
3178
|
if (array) {
|
|
3130
3179
|
fields["set"] = this.makeSetDataSchema(fieldType, true, options).optional();
|
|
3131
|
-
fields["updateMany"] = this.orArray(z
|
|
3180
|
+
fields["updateMany"] = this.orArray(z.strictObject({
|
|
3132
3181
|
where: this.makeWhereSchema(fieldType, false, true, false, options),
|
|
3133
3182
|
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
3134
3183
|
}), true).optional();
|
|
3135
3184
|
fields["deleteMany"] = this.makeDeleteRelationDataSchema(fieldType, true, false, options).optional();
|
|
3136
3185
|
}
|
|
3137
3186
|
}
|
|
3138
|
-
return z
|
|
3187
|
+
return z.strictObject(fields);
|
|
3139
3188
|
}
|
|
3140
3189
|
makeSetDataSchema(model, canBeArray, options) {
|
|
3141
3190
|
return this.orArray(this.makeWhereSchema(model, true, false, false, options), canBeArray);
|
|
@@ -3145,23 +3194,23 @@ var ZodSchemaFactory = class {
|
|
|
3145
3194
|
}
|
|
3146
3195
|
makeDisconnectDataSchema(model, canBeArray, options) {
|
|
3147
3196
|
if (canBeArray) return this.orArray(this.makeWhereSchema(model, true, false, false, options), canBeArray);
|
|
3148
|
-
else return z
|
|
3197
|
+
else return z.union([z.boolean(), this.makeWhereSchema(model, false, false, false, options)]);
|
|
3149
3198
|
}
|
|
3150
3199
|
makeDeleteRelationDataSchema(model, toManyRelation, uniqueFilter, options) {
|
|
3151
|
-
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter, false, false, options), true) : z
|
|
3200
|
+
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter, false, false, options), true) : z.union([z.boolean(), this.makeWhereSchema(model, uniqueFilter, false, false, options)]);
|
|
3152
3201
|
}
|
|
3153
3202
|
makeConnectOrCreateDataSchema(model, canBeArray, withoutFields, options) {
|
|
3154
3203
|
const whereSchema = this.makeWhereSchema(model, true, false, false, options);
|
|
3155
3204
|
const createSchema = this.makeCreateDataSchema(model, false, withoutFields, false, options);
|
|
3156
|
-
return this.orArray(z
|
|
3205
|
+
return this.orArray(z.strictObject({
|
|
3157
3206
|
where: whereSchema,
|
|
3158
3207
|
create: createSchema
|
|
3159
3208
|
}), canBeArray);
|
|
3160
3209
|
}
|
|
3161
3210
|
makeCreateManyPayloadSchema(model, withoutFields, options) {
|
|
3162
|
-
const schema = z
|
|
3211
|
+
const schema = z.strictObject({
|
|
3163
3212
|
data: this.makeCreateDataSchema(model, true, withoutFields, true, options),
|
|
3164
|
-
skipDuplicates: z
|
|
3213
|
+
skipDuplicates: z.boolean().optional()
|
|
3165
3214
|
});
|
|
3166
3215
|
const idParts = [`${model}CreateManyPayload`];
|
|
3167
3216
|
if (withoutFields.length) idParts.push(`Without${withoutFields.slice().sort().join("")}`);
|
|
@@ -3169,7 +3218,7 @@ var ZodSchemaFactory = class {
|
|
|
3169
3218
|
return schema;
|
|
3170
3219
|
}
|
|
3171
3220
|
makeUpdateSchema(model, options) {
|
|
3172
|
-
const baseSchema = z
|
|
3221
|
+
const baseSchema = z.strictObject({
|
|
3173
3222
|
where: this.makeWhereSchema(model, true, false, false, options),
|
|
3174
3223
|
data: this.makeUpdateDataSchema(model, [], false, options),
|
|
3175
3224
|
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
@@ -3184,10 +3233,10 @@ var ZodSchemaFactory = class {
|
|
|
3184
3233
|
return schema;
|
|
3185
3234
|
}
|
|
3186
3235
|
makeUpdateManySchema(model, options) {
|
|
3187
|
-
const result = this.mergePluginArgsSchema(z
|
|
3236
|
+
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3188
3237
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3189
3238
|
data: this.makeUpdateDataSchema(model, [], true, options),
|
|
3190
|
-
limit: z
|
|
3239
|
+
limit: z.number().int().nonnegative().optional()
|
|
3191
3240
|
}), "updateMany");
|
|
3192
3241
|
this.registerSchema(`${model}UpdateManyArgs`, result);
|
|
3193
3242
|
return result;
|
|
@@ -3203,7 +3252,7 @@ var ZodSchemaFactory = class {
|
|
|
3203
3252
|
return schema;
|
|
3204
3253
|
}
|
|
3205
3254
|
makeUpsertSchema(model, options) {
|
|
3206
|
-
const baseSchema = z
|
|
3255
|
+
const baseSchema = z.strictObject({
|
|
3207
3256
|
where: this.makeWhereSchema(model, true, false, false, options),
|
|
3208
3257
|
create: this.makeCreateDataSchema(model, false, [], false, options),
|
|
3209
3258
|
update: this.makeUpdateDataSchema(model, [], false, options),
|
|
@@ -3239,27 +3288,27 @@ var ZodSchemaFactory = class {
|
|
|
3239
3288
|
const oppositeFieldDef = requireField(this.schema, fieldDef.type, oppositeField);
|
|
3240
3289
|
if (oppositeFieldDef.relation?.fields) excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
3241
3290
|
}
|
|
3242
|
-
let fieldSchema = z
|
|
3291
|
+
let fieldSchema = z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "update", nextOpts)).optional();
|
|
3243
3292
|
if (fieldDef.optional && !fieldDef.array) fieldSchema = fieldSchema.nullable();
|
|
3244
3293
|
checkedVariantFields[field] = fieldSchema;
|
|
3245
3294
|
if (fieldDef.array || !fieldDef.relation.references) uncheckedVariantFields[field] = fieldSchema;
|
|
3246
3295
|
} else {
|
|
3247
3296
|
let fieldSchema = this.makeScalarSchema(fieldDef.type, fieldDef.attributes);
|
|
3248
|
-
if (this.isNumericField(fieldDef)) fieldSchema = z
|
|
3249
|
-
set: this.nullableIf(z
|
|
3250
|
-
increment: z
|
|
3251
|
-
decrement: z
|
|
3252
|
-
multiply: z
|
|
3253
|
-
divide: z
|
|
3297
|
+
if (this.isNumericField(fieldDef)) fieldSchema = z.union([fieldSchema, z.object({
|
|
3298
|
+
set: this.nullableIf(z.number().optional(), !!fieldDef.optional).optional(),
|
|
3299
|
+
increment: z.number().optional(),
|
|
3300
|
+
decrement: z.number().optional(),
|
|
3301
|
+
multiply: z.number().optional(),
|
|
3302
|
+
divide: z.number().optional()
|
|
3254
3303
|
}).refine((v) => Object.keys(v).length === 1, "Only one of \"set\", \"increment\", \"decrement\", \"multiply\", or \"divide\" can be provided")]);
|
|
3255
3304
|
if (fieldDef.array) {
|
|
3256
3305
|
const arraySchema = ZodUtils.addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
3257
|
-
fieldSchema = z
|
|
3306
|
+
fieldSchema = z.union([arraySchema, z.object({
|
|
3258
3307
|
set: arraySchema.optional(),
|
|
3259
|
-
push: z
|
|
3308
|
+
push: z.union([fieldSchema, fieldSchema.array()]).optional()
|
|
3260
3309
|
}).refine((v) => Object.keys(v).length === 1, "Only one of \"set\", \"push\" can be provided")]);
|
|
3261
3310
|
}
|
|
3262
|
-
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z
|
|
3311
|
+
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z.union([fieldSchema, z.instanceof(DbNullClass)]);
|
|
3263
3312
|
else if (this.isTypeDefType(fieldDef.type)) fieldSchema = this.makeNullableTypedJsonMutationSchema(fieldSchema);
|
|
3264
3313
|
else fieldSchema = fieldSchema.nullable();
|
|
3265
3314
|
fieldSchema = fieldSchema.optional();
|
|
@@ -3267,9 +3316,9 @@ var ZodSchemaFactory = class {
|
|
|
3267
3316
|
if (!fieldDef.foreignKeyFor) checkedVariantFields[field] = fieldSchema;
|
|
3268
3317
|
}
|
|
3269
3318
|
});
|
|
3270
|
-
const uncheckedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z
|
|
3271
|
-
const checkedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z
|
|
3272
|
-
const result = !hasRelation ? uncheckedUpdateSchema : z
|
|
3319
|
+
const uncheckedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(uncheckedVariantFields), modelDef.attributes) : z.strictObject(uncheckedVariantFields);
|
|
3320
|
+
const checkedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(checkedVariantFields), modelDef.attributes) : z.strictObject(checkedVariantFields);
|
|
3321
|
+
const result = !hasRelation ? uncheckedUpdateSchema : z.union([uncheckedUpdateSchema, checkedUpdateSchema]);
|
|
3273
3322
|
const idParts = [`${model}UpdateData`];
|
|
3274
3323
|
if (withoutRelationFields) idParts.push("WithoutRelation");
|
|
3275
3324
|
if (withoutFields.length) idParts.push(`Without${withoutFields.slice().sort().join("")}`);
|
|
@@ -3277,7 +3326,7 @@ var ZodSchemaFactory = class {
|
|
|
3277
3326
|
return result;
|
|
3278
3327
|
}
|
|
3279
3328
|
makeDeleteSchema(model, options) {
|
|
3280
|
-
const baseSchema = z
|
|
3329
|
+
const baseSchema = z.strictObject({
|
|
3281
3330
|
where: this.makeWhereSchema(model, true, false, false, options),
|
|
3282
3331
|
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
3283
3332
|
include: this.makeIncludeSchema(model, options).optional().nullable(),
|
|
@@ -3291,15 +3340,15 @@ var ZodSchemaFactory = class {
|
|
|
3291
3340
|
return schema;
|
|
3292
3341
|
}
|
|
3293
3342
|
makeDeleteManySchema(model, options) {
|
|
3294
|
-
const result = this.mergePluginArgsSchema(z
|
|
3343
|
+
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3295
3344
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3296
|
-
limit: z
|
|
3345
|
+
limit: z.number().int().nonnegative().optional()
|
|
3297
3346
|
}), "deleteMany").optional();
|
|
3298
3347
|
this.registerSchema(`${model}DeleteManyArgs`, result);
|
|
3299
3348
|
return result;
|
|
3300
3349
|
}
|
|
3301
3350
|
makeCountSchema(model, options) {
|
|
3302
|
-
const result = this.mergePluginArgsSchema(z
|
|
3351
|
+
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3303
3352
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3304
3353
|
skip: this.makeSkipSchema().optional(),
|
|
3305
3354
|
take: this.makeTakeSchema().optional(),
|
|
@@ -3310,10 +3359,10 @@ var ZodSchemaFactory = class {
|
|
|
3310
3359
|
return result;
|
|
3311
3360
|
}
|
|
3312
3361
|
makeCountAggregateInputSchema(model) {
|
|
3313
|
-
const schema = z
|
|
3314
|
-
_all: z
|
|
3362
|
+
const schema = z.union([z.literal(true), z.strictObject({
|
|
3363
|
+
_all: z.literal(true).optional(),
|
|
3315
3364
|
...this.getModelFields(model).reduce((acc, [field]) => {
|
|
3316
|
-
acc[field] = z
|
|
3365
|
+
acc[field] = z.literal(true).optional();
|
|
3317
3366
|
return acc;
|
|
3318
3367
|
}, {})
|
|
3319
3368
|
})]);
|
|
@@ -3321,7 +3370,7 @@ var ZodSchemaFactory = class {
|
|
|
3321
3370
|
return schema;
|
|
3322
3371
|
}
|
|
3323
3372
|
makeAggregateSchema(model, options) {
|
|
3324
|
-
const result = this.mergePluginArgsSchema(z
|
|
3373
|
+
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3325
3374
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3326
3375
|
skip: this.makeSkipSchema().optional(),
|
|
3327
3376
|
take: this.makeTakeSchema().optional(),
|
|
@@ -3336,16 +3385,16 @@ var ZodSchemaFactory = class {
|
|
|
3336
3385
|
return result;
|
|
3337
3386
|
}
|
|
3338
3387
|
makeSumAvgInputSchema(model) {
|
|
3339
|
-
const schema = z
|
|
3340
|
-
if (this.isNumericField(fieldDef)) acc[field] = z
|
|
3388
|
+
const schema = z.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
|
|
3389
|
+
if (this.isNumericField(fieldDef)) acc[field] = z.literal(true).optional();
|
|
3341
3390
|
return acc;
|
|
3342
3391
|
}, {}));
|
|
3343
3392
|
this.registerSchema(`${model}SumAvgAggregateInput`, schema);
|
|
3344
3393
|
return schema;
|
|
3345
3394
|
}
|
|
3346
3395
|
makeMinMaxInputSchema(model) {
|
|
3347
|
-
const schema = z
|
|
3348
|
-
if (!fieldDef.relation && !fieldDef.array) acc[field] = z
|
|
3396
|
+
const schema = z.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
|
|
3397
|
+
if (!fieldDef.relation && !fieldDef.array) acc[field] = z.literal(true).optional();
|
|
3349
3398
|
return acc;
|
|
3350
3399
|
}, {}));
|
|
3351
3400
|
this.registerSchema(`${model}MinMaxAggregateInput`, schema);
|
|
@@ -3353,8 +3402,8 @@ var ZodSchemaFactory = class {
|
|
|
3353
3402
|
}
|
|
3354
3403
|
makeGroupBySchema(model, options) {
|
|
3355
3404
|
const nonRelationFields = this.getModelFields(model).filter(([, def]) => !def.relation).map(([name]) => name);
|
|
3356
|
-
const bySchema = nonRelationFields.length > 0 ? this.orArray(z
|
|
3357
|
-
const baseSchema = z
|
|
3405
|
+
const bySchema = nonRelationFields.length > 0 ? this.orArray(z.enum(nonRelationFields), true) : z.never();
|
|
3406
|
+
const baseSchema = z.strictObject({
|
|
3358
3407
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3359
3408
|
orderBy: this.orArray(this.makeOrderBySchema(model, false, true, options), true).optional(),
|
|
3360
3409
|
by: bySchema,
|
|
@@ -3406,7 +3455,7 @@ var ZodSchemaFactory = class {
|
|
|
3406
3455
|
if (!procDef) throw createInternalError(`Procedure not found: ${procName}`);
|
|
3407
3456
|
const shape = {};
|
|
3408
3457
|
for (const param of Object.values(procDef.params ?? {})) shape[param.name] = this.makeProcedureParamSchema(param);
|
|
3409
|
-
const schema = z
|
|
3458
|
+
const schema = z.object(shape);
|
|
3410
3459
|
this.registerSchema(`${procName}ProcArgs`, schema);
|
|
3411
3460
|
return schema;
|
|
3412
3461
|
}
|
|
@@ -3414,10 +3463,10 @@ var ZodSchemaFactory = class {
|
|
|
3414
3463
|
let schema;
|
|
3415
3464
|
if (isTypeDef(this.schema, param.type)) schema = this.makeTypeDefSchema(param.type);
|
|
3416
3465
|
else if (isEnum(this.schema, param.type)) schema = this.makeEnumSchema(param.type);
|
|
3417
|
-
else if (param.type in (this.schema.models ?? {})) schema = z
|
|
3466
|
+
else if (param.type in (this.schema.models ?? {})) schema = z.record(z.string(), z.unknown());
|
|
3418
3467
|
else {
|
|
3419
3468
|
schema = this.makeScalarSchema(param.type);
|
|
3420
|
-
if (schema instanceof z
|
|
3469
|
+
if (schema instanceof z.ZodUnknown) throw createInternalError(`Unsupported procedure parameter type: ${param.type}`);
|
|
3421
3470
|
}
|
|
3422
3471
|
if (param.array) schema = schema.array();
|
|
3423
3472
|
if (param.optional) schema = schema.optional();
|
|
@@ -3453,10 +3502,10 @@ var ZodSchemaFactory = class {
|
|
|
3453
3502
|
return result;
|
|
3454
3503
|
}
|
|
3455
3504
|
makeSkipSchema() {
|
|
3456
|
-
return z
|
|
3505
|
+
return z.number().int().nonnegative();
|
|
3457
3506
|
}
|
|
3458
3507
|
makeTakeSchema() {
|
|
3459
|
-
return z
|
|
3508
|
+
return z.number().int();
|
|
3460
3509
|
}
|
|
3461
3510
|
refineForSelectIncludeMutuallyExclusive(schema) {
|
|
3462
3511
|
return schema.refine((value) => !(value["select"] && value["include"]), "\"select\" and \"include\" cannot be used together");
|
|
@@ -3475,7 +3524,7 @@ var ZodSchemaFactory = class {
|
|
|
3475
3524
|
return nullable ? schema.nullable() : schema;
|
|
3476
3525
|
}
|
|
3477
3526
|
orArray(schema, canBeArray) {
|
|
3478
|
-
return canBeArray ? z
|
|
3527
|
+
return canBeArray ? z.union([schema, z.array(schema)]) : schema;
|
|
3479
3528
|
}
|
|
3480
3529
|
isNumericField(fieldDef) {
|
|
3481
3530
|
return NUMERIC_FIELD_TYPES.includes(fieldDef.type) && !fieldDef.array;
|
|
@@ -3537,10 +3586,10 @@ var ZodSchemaFactory = class {
|
|
|
3537
3586
|
createUnionFilterSchema(valueSchema, optional, components, allowedFilterKinds) {
|
|
3538
3587
|
if (Object.keys(components).length === 0) {
|
|
3539
3588
|
if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return this.nullableIf(valueSchema, optional);
|
|
3540
|
-
return z
|
|
3589
|
+
return z.never();
|
|
3541
3590
|
}
|
|
3542
|
-
if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return z
|
|
3543
|
-
else return z
|
|
3591
|
+
if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return z.union([this.nullableIf(valueSchema, optional), z.strictObject(components)]);
|
|
3592
|
+
else return z.strictObject(components);
|
|
3544
3593
|
}
|
|
3545
3594
|
canCreateModel(model) {
|
|
3546
3595
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -7148,9 +7197,9 @@ var ClientImpl = class ClientImpl {
|
|
|
7148
7197
|
validateOptions(baseClient, options) {
|
|
7149
7198
|
if (!baseClient && !options.skipValidationForComputedFields) this.validateComputedFieldsConfig(options);
|
|
7150
7199
|
if (options.diagnostics) {
|
|
7151
|
-
const parseResult = z.object({
|
|
7152
|
-
slowQueryThresholdMs: z.number().nonnegative().optional(),
|
|
7153
|
-
slowQueryMaxRecords: z.int().nonnegative().or(z.literal(Infinity)).optional()
|
|
7200
|
+
const parseResult = z$1.object({
|
|
7201
|
+
slowQueryThresholdMs: z$1.number().nonnegative().optional(),
|
|
7202
|
+
slowQueryMaxRecords: z$1.int().nonnegative().or(z$1.literal(Infinity)).optional()
|
|
7154
7203
|
}).safeParse(options.diagnostics);
|
|
7155
7204
|
if (!parseResult.success) throw createConfigError(`Invalid diagnostics configuration: ${formatError(parseResult.error)}`);
|
|
7156
7205
|
}
|