@zenstackhq/orm 3.9.7 → 3.9.8
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/constants-BQEq4CBi.mjs +161 -0
- package/dist/constants-BQEq4CBi.mjs.map +1 -0
- package/dist/constants-CcJSpq4B.cjs +244 -0
- package/dist/constants-CcJSpq4B.cjs.map +1 -0
- package/dist/constants-RUWhnVl4.d.mts +129 -0
- package/dist/constants-lRwcp6Hv.d.cts +129 -0
- package/dist/constants.cjs +11 -0
- package/dist/constants.d.cts +2 -0
- package/dist/constants.d.mts +2 -0
- package/dist/constants.mjs +2 -0
- package/dist/index.cjs +142 -204
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -129
- package/dist/index.d.mts +3 -131
- package/dist/index.mjs +312 -374
- package/dist/index.mjs.map +1 -1
- package/package.json +18 -8
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { t as __exportAll } from "./chunk-CfYAbeIz.mjs";
|
|
2
|
+
import { a as CoreCreateOperations, c as CoreReadOperations, d as DELEGATE_JOINED_FIELD_PREFIX, f as FILTER_PROPERTY_TO_KIND, i as AllWriteOperations, l as CoreUpdateOperations, m as NUMERIC_FIELD_TYPES, n as AllCrudOperations, o as CoreCrudOperations, p as LOGICAL_COMBINATORS, r as AllReadOperations, s as CoreDeleteOperations, t as AggregateOperators, u as CoreWriteOperations } from "./constants-BQEq4CBi.mjs";
|
|
2
3
|
import { AnyNull, AnyNullClass, DbNull, DbNullClass, JsonNull, JsonNullClass } from "./common-types.mjs";
|
|
3
4
|
import { clone, enumerate, invariant, isPlainObject, lowerCaseFirst, upperCaseFirst } from "@zenstackhq/common-helpers";
|
|
4
5
|
import { AliasNode, AndNode, ColumnNode, ColumnUpdateNode, CompiledQuery, DefaultConnectionProvider, DefaultQueryExecutor, DeleteQueryNode, ExpressionWrapper, FromNode, IdentifierNode, InsertQueryNode, Kysely, Log, OperationNodeTransformer, OperationNodeVisitor, PrimitiveValueListNode, RawNode, ReferenceNode, ReturningNode, SelectAllNode, SelectionNode, SingleConnectionProvider, TableNode, Transaction, UpdateQueryNode, ValueListNode, ValueNode, ValuesNode, WhereNode, createQueryId, expressionBuilder, sql } from "kysely";
|
|
5
|
-
import z, { ZodObject, ZodType, z
|
|
6
|
+
import z$1, { ZodObject, ZodType, z } from "zod";
|
|
6
7
|
import { fromError } from "zod-validation-error/v4";
|
|
7
8
|
import { P, match } from "ts-pattern";
|
|
8
9
|
import { ExpressionUtils } from "@zenstackhq/schema";
|
|
@@ -541,75 +542,6 @@ function tmpAlias(name) {
|
|
|
541
542
|
else return name;
|
|
542
543
|
}
|
|
543
544
|
//#endregion
|
|
544
|
-
//#region src/client/constants.ts
|
|
545
|
-
/**
|
|
546
|
-
* The types of fields that are numeric.
|
|
547
|
-
*/
|
|
548
|
-
const NUMERIC_FIELD_TYPES = [
|
|
549
|
-
"Int",
|
|
550
|
-
"Float",
|
|
551
|
-
"BigInt",
|
|
552
|
-
"Decimal"
|
|
553
|
-
];
|
|
554
|
-
/**
|
|
555
|
-
* Prefix for JSON field used to store joined delegate rows.
|
|
556
|
-
*/
|
|
557
|
-
const DELEGATE_JOINED_FIELD_PREFIX = "$delegate$";
|
|
558
|
-
/**
|
|
559
|
-
* Logical combinators used in filters.
|
|
560
|
-
*/
|
|
561
|
-
const LOGICAL_COMBINATORS = [
|
|
562
|
-
"AND",
|
|
563
|
-
"OR",
|
|
564
|
-
"NOT"
|
|
565
|
-
];
|
|
566
|
-
/**
|
|
567
|
-
* Aggregation operators.
|
|
568
|
-
*/
|
|
569
|
-
const AggregateOperators = [
|
|
570
|
-
"_count",
|
|
571
|
-
"_sum",
|
|
572
|
-
"_avg",
|
|
573
|
-
"_min",
|
|
574
|
-
"_max"
|
|
575
|
-
];
|
|
576
|
-
/**
|
|
577
|
-
* Mapping of filter operators to their corresponding filter kind categories.
|
|
578
|
-
*/
|
|
579
|
-
const FILTER_PROPERTY_TO_KIND = {
|
|
580
|
-
equals: "Equality",
|
|
581
|
-
not: "Equality",
|
|
582
|
-
in: "Equality",
|
|
583
|
-
notIn: "Equality",
|
|
584
|
-
lt: "Range",
|
|
585
|
-
lte: "Range",
|
|
586
|
-
gt: "Range",
|
|
587
|
-
gte: "Range",
|
|
588
|
-
between: "Range",
|
|
589
|
-
contains: "Like",
|
|
590
|
-
startsWith: "Like",
|
|
591
|
-
endsWith: "Like",
|
|
592
|
-
mode: "Like",
|
|
593
|
-
is: "Relation",
|
|
594
|
-
isNot: "Relation",
|
|
595
|
-
some: "Relation",
|
|
596
|
-
every: "Relation",
|
|
597
|
-
none: "Relation",
|
|
598
|
-
path: "Json",
|
|
599
|
-
string_contains: "Json",
|
|
600
|
-
string_starts_with: "Json",
|
|
601
|
-
string_ends_with: "Json",
|
|
602
|
-
array_contains: "Json",
|
|
603
|
-
array_starts_with: "Json",
|
|
604
|
-
array_ends_with: "Json",
|
|
605
|
-
fuzzy: "Fuzzy",
|
|
606
|
-
fts: "FullText",
|
|
607
|
-
has: "List",
|
|
608
|
-
hasEvery: "List",
|
|
609
|
-
hasSome: "List",
|
|
610
|
-
isEmpty: "List"
|
|
611
|
-
};
|
|
612
|
-
//#endregion
|
|
613
545
|
//#region src/client/contract.ts
|
|
614
546
|
/**
|
|
615
547
|
* Transaction isolation levels.
|
|
@@ -2433,7 +2365,7 @@ function createQuerySchemaFactory(clientOrSchema, options) {
|
|
|
2433
2365
|
* @see https://github.com/zenstackhq/zenstack/issues/2631
|
|
2434
2366
|
*/
|
|
2435
2367
|
function coercedDateTimeSchema() {
|
|
2436
|
-
return z
|
|
2368
|
+
return z.preprocess((val) => {
|
|
2437
2369
|
if (typeof val !== "string") return val;
|
|
2438
2370
|
if (/^\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d\d(?::\d\d)?)?$/.test(val)) {
|
|
2439
2371
|
const hasTz = val.endsWith("Z") || /[+-]\d\d(?::\d\d)?$/.test(val);
|
|
@@ -2442,10 +2374,10 @@ function coercedDateTimeSchema() {
|
|
|
2442
2374
|
}
|
|
2443
2375
|
const d = new Date(val);
|
|
2444
2376
|
return isNaN(d.getTime()) ? val : d;
|
|
2445
|
-
}, z
|
|
2446
|
-
z
|
|
2447
|
-
z
|
|
2448
|
-
z
|
|
2377
|
+
}, z.union([
|
|
2378
|
+
z.iso.datetime(),
|
|
2379
|
+
z.iso.date(),
|
|
2380
|
+
z.date()
|
|
2449
2381
|
]));
|
|
2450
2382
|
}
|
|
2451
2383
|
/**
|
|
@@ -2453,7 +2385,7 @@ function coercedDateTimeSchema() {
|
|
|
2453
2385
|
*/
|
|
2454
2386
|
var ZodSchemaFactory = class {
|
|
2455
2387
|
schemaCache = /* @__PURE__ */ new Map();
|
|
2456
|
-
schemaRegistry = z
|
|
2388
|
+
schemaRegistry = z.registry();
|
|
2457
2389
|
allFilterKinds = [...new Set(Object.values(FILTER_PROPERTY_TO_KIND))];
|
|
2458
2390
|
schema;
|
|
2459
2391
|
options;
|
|
@@ -2545,7 +2477,7 @@ var ZodSchemaFactory = class {
|
|
|
2545
2477
|
this.makeGroupBySchema(m);
|
|
2546
2478
|
}
|
|
2547
2479
|
for (const procName of Object.keys(this.schema.procedures ?? {})) if (this.isProcedureAllowed(procName)) this.makeProcedureArgsSchema(procName);
|
|
2548
|
-
return z
|
|
2480
|
+
return z.toJSONSchema(this.schemaRegistry, { unrepresentable: "any" });
|
|
2549
2481
|
}
|
|
2550
2482
|
get cacheStats() {
|
|
2551
2483
|
return {
|
|
@@ -2574,13 +2506,13 @@ var ZodSchemaFactory = class {
|
|
|
2574
2506
|
fields["omit"] = this.makeOmitSchema(model).optional().nullable();
|
|
2575
2507
|
if (!unique) {
|
|
2576
2508
|
fields["skip"] = this.makeSkipSchema().optional();
|
|
2577
|
-
if (findOne) fields["take"] = z
|
|
2509
|
+
if (findOne) fields["take"] = z.literal(1).optional();
|
|
2578
2510
|
else fields["take"] = this.makeTakeSchema().optional();
|
|
2579
2511
|
fields["orderBy"] = this.orArray(this.makeOrderBySchema(model, true, false, options), true).optional();
|
|
2580
2512
|
fields["cursor"] = this.makeCursorSchema(model, options).optional();
|
|
2581
2513
|
fields["distinct"] = this.makeDistinctSchema(model).optional();
|
|
2582
2514
|
}
|
|
2583
|
-
const baseSchema = z
|
|
2515
|
+
const baseSchema = z.strictObject(fields);
|
|
2584
2516
|
let result = this.mergePluginArgsSchema(baseSchema, operation);
|
|
2585
2517
|
result = this.refineForSelectIncludeMutuallyExclusive(result);
|
|
2586
2518
|
result = this.refineForSelectOmitMutuallyExclusive(result);
|
|
@@ -2590,7 +2522,7 @@ var ZodSchemaFactory = class {
|
|
|
2590
2522
|
return result;
|
|
2591
2523
|
}
|
|
2592
2524
|
makeExistsSchema(model, options) {
|
|
2593
|
-
const baseSchema = z
|
|
2525
|
+
const baseSchema = z.strictObject({ where: this.makeWhereSchema(model, false, false, false, options).optional() });
|
|
2594
2526
|
const result = this.mergePluginArgsSchema(baseSchema, "exists").optional();
|
|
2595
2527
|
this.registerSchema(`${model}ExistsArgs`, result);
|
|
2596
2528
|
return result;
|
|
@@ -2598,19 +2530,19 @@ var ZodSchemaFactory = class {
|
|
|
2598
2530
|
makeScalarSchema(type, attributes) {
|
|
2599
2531
|
if (this.schema.typeDefs && type in this.schema.typeDefs) return this.makeTypeDefSchema(type);
|
|
2600
2532
|
else if (this.schema.enums && type in this.schema.enums) return this.makeEnumSchema(type);
|
|
2601
|
-
else return match(type).with("String", () => this.extraValidationsEnabled ? ZodUtils.addStringValidation(z
|
|
2602
|
-
return z
|
|
2603
|
-
this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z
|
|
2604
|
-
ZodUtils.addDecimalValidation(z
|
|
2605
|
-
ZodUtils.addDecimalValidation(z
|
|
2533
|
+
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", () => {
|
|
2534
|
+
return z.union([
|
|
2535
|
+
this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z.number(), attributes) : z.number(),
|
|
2536
|
+
ZodUtils.addDecimalValidation(z.instanceof(Decimal), attributes, this.extraValidationsEnabled),
|
|
2537
|
+
ZodUtils.addDecimalValidation(z.string(), attributes, this.extraValidationsEnabled)
|
|
2606
2538
|
]);
|
|
2607
|
-
}).with("DateTime", () => this.makeDateTimeValueSchema()).with("Bytes", () => z
|
|
2539
|
+
}).with("DateTime", () => this.makeDateTimeValueSchema()).with("Bytes", () => z.instanceof(Uint8Array)).with("Json", () => this.makeJsonValueSchema()).otherwise(() => z.unknown());
|
|
2608
2540
|
}
|
|
2609
2541
|
isParameterizedComputedField(fieldDef) {
|
|
2610
2542
|
return !!(fieldDef.computed && fieldDef.params);
|
|
2611
2543
|
}
|
|
2612
2544
|
makeFieldArgsSchema(params) {
|
|
2613
|
-
return z
|
|
2545
|
+
return z.strictObject(Object.fromEntries(Object.entries(params).map(([name, param]) => {
|
|
2614
2546
|
let paramSchema = this.makeScalarSchema(param.type);
|
|
2615
2547
|
if (param.array) paramSchema = paramSchema.array();
|
|
2616
2548
|
if (param.optional) paramSchema = paramSchema.optional();
|
|
@@ -2618,9 +2550,9 @@ var ZodSchemaFactory = class {
|
|
|
2618
2550
|
})));
|
|
2619
2551
|
}
|
|
2620
2552
|
addComputedArgsToFilter(filterSchema, params) {
|
|
2621
|
-
const objectMembers = (filterSchema instanceof z
|
|
2553
|
+
const objectMembers = (filterSchema instanceof z.ZodUnion ? filterSchema.options : [filterSchema]).filter((m) => m instanceof z.ZodObject);
|
|
2622
2554
|
const components = Object.assign({}, ...objectMembers.map((o) => o.shape));
|
|
2623
|
-
return z
|
|
2555
|
+
return z.strictObject({
|
|
2624
2556
|
args: this.makeFieldArgsSchema(params),
|
|
2625
2557
|
...components
|
|
2626
2558
|
});
|
|
@@ -2628,20 +2560,20 @@ var ZodSchemaFactory = class {
|
|
|
2628
2560
|
makeEnumSchema(_enum) {
|
|
2629
2561
|
const enumDef = getEnum(this.schema, _enum);
|
|
2630
2562
|
invariant(enumDef, `Enum "${_enum}" not found in schema`);
|
|
2631
|
-
const schema = z
|
|
2563
|
+
const schema = z.enum(Object.keys(enumDef.values));
|
|
2632
2564
|
this.registerSchema(_enum, schema);
|
|
2633
2565
|
return schema;
|
|
2634
2566
|
}
|
|
2635
2567
|
makeTypeDefSchema(type) {
|
|
2636
2568
|
const typeDef = getTypeDef(this.schema, type);
|
|
2637
2569
|
invariant(typeDef, `Type definition "${type}" not found in schema`);
|
|
2638
|
-
const schema = (typeDef.strict ? z
|
|
2639
|
-
let fieldSchema = isTypeDef(this.schema, def.type) ? z
|
|
2570
|
+
const schema = (typeDef.strict ? z.strictObject : z.looseObject)(Object.fromEntries(Object.entries(typeDef.fields).map(([field, def]) => {
|
|
2571
|
+
let fieldSchema = isTypeDef(this.schema, def.type) ? z.lazy(() => this.makeTypeDefSchema(def.type)) : this.makeScalarSchema(def.type);
|
|
2640
2572
|
if (def.array) fieldSchema = fieldSchema.array();
|
|
2641
2573
|
if (def.optional) fieldSchema = fieldSchema.nullish();
|
|
2642
2574
|
return [field, fieldSchema];
|
|
2643
2575
|
})));
|
|
2644
|
-
const finalSchema = z
|
|
2576
|
+
const finalSchema = z.any().superRefine((value, ctx) => {
|
|
2645
2577
|
const parseResult = schema.safeParse(value);
|
|
2646
2578
|
if (!parseResult.success) parseResult.error.issues.forEach((issue) => ctx.addIssue(issue));
|
|
2647
2579
|
});
|
|
@@ -2657,17 +2589,17 @@ var ZodSchemaFactory = class {
|
|
|
2657
2589
|
if (fieldDef.relation) {
|
|
2658
2590
|
if (withoutRelationFields || !this.shouldIncludeRelations(options)) continue;
|
|
2659
2591
|
const allowedFilterKinds = this.getEffectiveFilterKinds(model, field);
|
|
2660
|
-
if (allowedFilterKinds && !allowedFilterKinds.includes("Relation")) fieldSchema = z
|
|
2592
|
+
if (allowedFilterKinds && !allowedFilterKinds.includes("Relation")) fieldSchema = z.never();
|
|
2661
2593
|
else {
|
|
2662
|
-
fieldSchema = z
|
|
2663
|
-
if (fieldDef.array) fieldSchema = z
|
|
2594
|
+
fieldSchema = z.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts).optional());
|
|
2595
|
+
if (fieldDef.array) fieldSchema = z.strictObject({
|
|
2664
2596
|
some: fieldSchema.optional(),
|
|
2665
2597
|
every: fieldSchema.optional(),
|
|
2666
2598
|
none: fieldSchema.optional()
|
|
2667
2599
|
});
|
|
2668
2600
|
else {
|
|
2669
2601
|
fieldSchema = this.nullableIf(fieldSchema, !fieldDef.array && !!fieldDef.optional);
|
|
2670
|
-
fieldSchema = z
|
|
2602
|
+
fieldSchema = z.union([fieldSchema, z.strictObject({
|
|
2671
2603
|
is: fieldSchema.optional(),
|
|
2672
2604
|
isNot: fieldSchema.optional()
|
|
2673
2605
|
})]);
|
|
@@ -2687,21 +2619,21 @@ var ZodSchemaFactory = class {
|
|
|
2687
2619
|
}
|
|
2688
2620
|
if (unique) {
|
|
2689
2621
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
2690
|
-
for (const uniqueField of uniqueFields) if ("defs" in uniqueField) fields[uniqueField.name] = z
|
|
2622
|
+
for (const uniqueField of uniqueFields) if ("defs" in uniqueField) fields[uniqueField.name] = z.object(Object.fromEntries(Object.entries(uniqueField.defs).map(([key, def]) => {
|
|
2691
2623
|
invariant(!def.relation, "unique field cannot be a relation");
|
|
2692
2624
|
let fieldSchema;
|
|
2693
2625
|
const enumDef = getEnum(this.schema, def.type);
|
|
2694
2626
|
if (enumDef) if (Object.keys(enumDef.values).length > 0) fieldSchema = this.makeEnumFilterSchema(def.type, !!def.optional, !!def.array, false, void 0);
|
|
2695
|
-
else fieldSchema = z
|
|
2627
|
+
else fieldSchema = z.never();
|
|
2696
2628
|
else fieldSchema = this.makePrimitiveFilterSchema(def.type, !!def.optional, false, void 0);
|
|
2697
2629
|
return [key, fieldSchema];
|
|
2698
2630
|
}))).optional();
|
|
2699
2631
|
}
|
|
2700
|
-
fields["$expr"] = z
|
|
2701
|
-
fields["AND"] = this.orArray(z
|
|
2702
|
-
fields["OR"] = z
|
|
2703
|
-
fields["NOT"] = this.orArray(z
|
|
2704
|
-
const baseWhere = z
|
|
2632
|
+
fields["$expr"] = z.custom((v) => typeof v === "function", { error: "\"$expr\" must be a function" }).optional();
|
|
2633
|
+
fields["AND"] = this.orArray(z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
|
|
2634
|
+
fields["OR"] = z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)).array().optional();
|
|
2635
|
+
fields["NOT"] = this.orArray(z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
|
|
2636
|
+
const baseWhere = z.strictObject(fields);
|
|
2705
2637
|
let result = baseWhere;
|
|
2706
2638
|
if (unique) {
|
|
2707
2639
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
@@ -2727,26 +2659,26 @@ var ZodSchemaFactory = class {
|
|
|
2727
2659
|
else if (getEnum(this.schema, fieldDef.type)) fieldSchemas[fieldName] = this.makeEnumFilterSchema(fieldDef.type, !!fieldDef.optional, !!fieldDef.array, false, void 0).optional();
|
|
2728
2660
|
else if (fieldDef.array) fieldSchemas[fieldName] = this.makeArrayFilterSchema(fieldDef.type, void 0).optional();
|
|
2729
2661
|
else fieldSchemas[fieldName] = this.makePrimitiveFilterSchema(fieldDef.type, !!fieldDef.optional, false, void 0).optional();
|
|
2730
|
-
candidates.push(z
|
|
2662
|
+
candidates.push(z.strictObject(fieldSchemas));
|
|
2731
2663
|
}
|
|
2732
|
-
const recursiveSchema = z
|
|
2733
|
-
if (array) candidates.push(z
|
|
2664
|
+
const recursiveSchema = z.lazy(() => this.makeTypedJsonFilterSchema(type, optional, false, allowedFilterKinds)).optional();
|
|
2665
|
+
if (array) candidates.push(z.strictObject({
|
|
2734
2666
|
some: recursiveSchema,
|
|
2735
2667
|
every: recursiveSchema,
|
|
2736
2668
|
none: recursiveSchema
|
|
2737
2669
|
}));
|
|
2738
|
-
else candidates.push(z
|
|
2670
|
+
else candidates.push(z.strictObject({
|
|
2739
2671
|
is: recursiveSchema,
|
|
2740
2672
|
isNot: recursiveSchema
|
|
2741
2673
|
}));
|
|
2742
2674
|
candidates.push(this.makeJsonFilterSchema(optional, allowedFilterKinds));
|
|
2743
2675
|
if (optional) {
|
|
2744
|
-
candidates.push(z
|
|
2745
|
-
candidates.push(z
|
|
2746
|
-
candidates.push(z
|
|
2747
|
-
candidates.push(z
|
|
2676
|
+
candidates.push(z.null());
|
|
2677
|
+
candidates.push(z.instanceof(DbNullClass));
|
|
2678
|
+
candidates.push(z.instanceof(JsonNullClass));
|
|
2679
|
+
candidates.push(z.instanceof(AnyNullClass));
|
|
2748
2680
|
}
|
|
2749
|
-
const result = z
|
|
2681
|
+
const result = z.union(candidates);
|
|
2750
2682
|
this.registerSchema(`${type}Filter${this.filterSchemaSuffix({
|
|
2751
2683
|
optional,
|
|
2752
2684
|
array,
|
|
@@ -2755,7 +2687,7 @@ var ZodSchemaFactory = class {
|
|
|
2755
2687
|
return result;
|
|
2756
2688
|
}
|
|
2757
2689
|
makeNullableTypedJsonMutationSchema(fieldSchema) {
|
|
2758
|
-
return z
|
|
2690
|
+
return z.any().superRefine((value, ctx) => {
|
|
2759
2691
|
if (value instanceof DbNullClass || value instanceof JsonNullClass || value === null || value === void 0) return;
|
|
2760
2692
|
const parseResult = fieldSchema.safeParse(value);
|
|
2761
2693
|
if (!parseResult.success) parseResult.error.issues.forEach((issue) => ctx.addIssue(issue));
|
|
@@ -2767,11 +2699,11 @@ var ZodSchemaFactory = class {
|
|
|
2767
2699
|
makeEnumFilterSchema(enumName, optional, array, withAggregations, allowedFilterKinds) {
|
|
2768
2700
|
const enumDef = getEnum(this.schema, enumName);
|
|
2769
2701
|
invariant(enumDef, `Enum "${enumName}" not found in schema`);
|
|
2770
|
-
const baseSchema = z
|
|
2702
|
+
const baseSchema = z.enum(Object.keys(enumDef.values));
|
|
2771
2703
|
let schema;
|
|
2772
2704
|
if (array) schema = this.internalMakeArrayFilterSchema(baseSchema, allowedFilterKinds);
|
|
2773
2705
|
else {
|
|
2774
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z
|
|
2706
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z.lazy(() => this.makeEnumFilterSchema(enumName, optional, array, withAggregations, allowedFilterKinds)), [
|
|
2775
2707
|
"equals",
|
|
2776
2708
|
"in",
|
|
2777
2709
|
"notIn",
|
|
@@ -2805,42 +2737,42 @@ var ZodSchemaFactory = class {
|
|
|
2805
2737
|
has: elementSchema.optional(),
|
|
2806
2738
|
hasEvery: elementSchema.array().optional(),
|
|
2807
2739
|
hasSome: elementSchema.array().optional(),
|
|
2808
|
-
isEmpty: z
|
|
2740
|
+
isEmpty: z.boolean().optional()
|
|
2809
2741
|
};
|
|
2810
2742
|
const filteredOperators = this.trimFilterOperators(operators, allowedFilterKinds);
|
|
2811
|
-
return z
|
|
2743
|
+
return z.strictObject(filteredOperators);
|
|
2812
2744
|
}
|
|
2813
2745
|
makePrimitiveFilterSchema(type, optional, withAggregations, allowedFilterKinds, withFuzzy = false, withFullText = false) {
|
|
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
|
|
2746
|
+
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();
|
|
2815
2747
|
}
|
|
2816
2748
|
makeJsonValueSchema() {
|
|
2817
|
-
const schema = z
|
|
2818
|
-
z
|
|
2819
|
-
z
|
|
2820
|
-
z
|
|
2821
|
-
z
|
|
2822
|
-
z
|
|
2823
|
-
z
|
|
2749
|
+
const schema = z.union([
|
|
2750
|
+
z.string(),
|
|
2751
|
+
z.number(),
|
|
2752
|
+
z.boolean(),
|
|
2753
|
+
z.instanceof(JsonNullClass),
|
|
2754
|
+
z.lazy(() => z.union([this.makeJsonValueSchema(), z.null()]).array()),
|
|
2755
|
+
z.record(z.string(), z.lazy(() => z.union([this.makeJsonValueSchema(), z.null()])))
|
|
2824
2756
|
]);
|
|
2825
2757
|
this.registerSchema("JsonValue", schema);
|
|
2826
2758
|
return schema;
|
|
2827
2759
|
}
|
|
2828
2760
|
makeJsonFilterSchema(optional, allowedFilterKinds) {
|
|
2829
|
-
if (allowedFilterKinds && !allowedFilterKinds.includes("Json")) return z
|
|
2761
|
+
if (allowedFilterKinds && !allowedFilterKinds.includes("Json")) return z.never();
|
|
2830
2762
|
const filterMembers = [
|
|
2831
2763
|
this.makeJsonValueSchema(),
|
|
2832
|
-
z
|
|
2833
|
-
z
|
|
2764
|
+
z.instanceof(DbNullClass),
|
|
2765
|
+
z.instanceof(AnyNullClass)
|
|
2834
2766
|
];
|
|
2835
|
-
if (optional) filterMembers.push(z
|
|
2836
|
-
const filterValueSchema = z
|
|
2837
|
-
const schema = z
|
|
2838
|
-
path: z
|
|
2767
|
+
if (optional) filterMembers.push(z.null());
|
|
2768
|
+
const filterValueSchema = z.union(filterMembers);
|
|
2769
|
+
const schema = z.strictObject({
|
|
2770
|
+
path: z.string().optional(),
|
|
2839
2771
|
equals: filterValueSchema.optional(),
|
|
2840
2772
|
not: filterValueSchema.optional(),
|
|
2841
|
-
string_contains: z
|
|
2842
|
-
string_starts_with: z
|
|
2843
|
-
string_ends_with: z
|
|
2773
|
+
string_contains: z.string().optional(),
|
|
2774
|
+
string_starts_with: z.string().optional(),
|
|
2775
|
+
string_ends_with: z.string().optional(),
|
|
2844
2776
|
mode: this.makeStringModeSchema().optional(),
|
|
2845
2777
|
array_contains: filterValueSchema.optional(),
|
|
2846
2778
|
array_starts_with: filterValueSchema.optional(),
|
|
@@ -2859,7 +2791,7 @@ var ZodSchemaFactory = class {
|
|
|
2859
2791
|
}
|
|
2860
2792
|
makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
2861
2793
|
const filterValueSchema = this.makeDateTimeValueSchema();
|
|
2862
|
-
const schema = this.makeCommonPrimitiveFilterSchema(filterValueSchema, optional, () => z
|
|
2794
|
+
const schema = this.makeCommonPrimitiveFilterSchema(filterValueSchema, optional, () => z.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)), withAggregations ? [
|
|
2863
2795
|
"_count",
|
|
2864
2796
|
"_min",
|
|
2865
2797
|
"_max"
|
|
@@ -2872,12 +2804,12 @@ var ZodSchemaFactory = class {
|
|
|
2872
2804
|
return schema;
|
|
2873
2805
|
}
|
|
2874
2806
|
makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
2875
|
-
const components = this.makeCommonPrimitiveFilterComponents(z
|
|
2807
|
+
const components = this.makeCommonPrimitiveFilterComponents(z.boolean(), optional, () => z.lazy(() => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)), ["equals", "not"], withAggregations ? [
|
|
2876
2808
|
"_count",
|
|
2877
2809
|
"_min",
|
|
2878
2810
|
"_max"
|
|
2879
2811
|
] : void 0, allowedFilterKinds);
|
|
2880
|
-
const schema = this.createUnionFilterSchema(z
|
|
2812
|
+
const schema = this.createUnionFilterSchema(z.boolean(), optional, components, allowedFilterKinds);
|
|
2881
2813
|
this.registerSchema(`BooleanFilter${this.filterSchemaSuffix({
|
|
2882
2814
|
optional,
|
|
2883
2815
|
allowedFilterKinds,
|
|
@@ -2886,8 +2818,8 @@ var ZodSchemaFactory = class {
|
|
|
2886
2818
|
return schema;
|
|
2887
2819
|
}
|
|
2888
2820
|
makeBytesFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
2889
|
-
const baseSchema = z
|
|
2890
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z
|
|
2821
|
+
const baseSchema = z.instanceof(Uint8Array);
|
|
2822
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z.instanceof(Uint8Array), [
|
|
2891
2823
|
"equals",
|
|
2892
2824
|
"in",
|
|
2893
2825
|
"notIn",
|
|
@@ -2935,7 +2867,7 @@ var ZodSchemaFactory = class {
|
|
|
2935
2867
|
return this.createUnionFilterSchema(baseSchema, optional, components, allowedFilterKinds);
|
|
2936
2868
|
}
|
|
2937
2869
|
makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds) {
|
|
2938
|
-
const schema = this.makeCommonPrimitiveFilterSchema(this.makeScalarSchema(type), optional, () => z
|
|
2870
|
+
const schema = this.makeCommonPrimitiveFilterSchema(this.makeScalarSchema(type), optional, () => z.lazy(() => this.makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds)), withAggregations ? [
|
|
2939
2871
|
"_count",
|
|
2940
2872
|
"_avg",
|
|
2941
2873
|
"_sum",
|
|
@@ -2950,15 +2882,15 @@ var ZodSchemaFactory = class {
|
|
|
2950
2882
|
return schema;
|
|
2951
2883
|
}
|
|
2952
2884
|
makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy = false, withFullText = false) {
|
|
2953
|
-
const baseComponents = this.makeCommonPrimitiveFilterComponents(z
|
|
2885
|
+
const baseComponents = this.makeCommonPrimitiveFilterComponents(z.string(), optional, () => z.lazy(() => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy, withFullText)), void 0, withAggregations ? [
|
|
2954
2886
|
"_count",
|
|
2955
2887
|
"_min",
|
|
2956
2888
|
"_max"
|
|
2957
2889
|
] : void 0, allowedFilterKinds);
|
|
2958
2890
|
const stringSpecificOperators = {
|
|
2959
|
-
startsWith: z
|
|
2960
|
-
endsWith: z
|
|
2961
|
-
contains: z
|
|
2891
|
+
startsWith: z.string().optional(),
|
|
2892
|
+
endsWith: z.string().optional(),
|
|
2893
|
+
contains: z.string().optional(),
|
|
2962
2894
|
...withFuzzy && this.providerSupportsFuzzySearch ? { fuzzy: this.makeFuzzyFilterSchema().optional() } : {},
|
|
2963
2895
|
...withFullText && this.providerSupportsFullTextSearch ? { fts: this.makeFullTextFilterSchema().optional() } : {},
|
|
2964
2896
|
...this.providerSupportsCaseSensitivity ? { mode: this.makeStringModeSchema().optional() } : {}
|
|
@@ -2968,7 +2900,7 @@ var ZodSchemaFactory = class {
|
|
|
2968
2900
|
...baseComponents,
|
|
2969
2901
|
...filteredStringOperators
|
|
2970
2902
|
};
|
|
2971
|
-
const schema = this.createUnionFilterSchema(z
|
|
2903
|
+
const schema = this.createUnionFilterSchema(z.string(), optional, allComponents, allowedFilterKinds);
|
|
2972
2904
|
const featureSuffix = `${withFuzzy ? "Fuzzy" : ""}${withFullText ? "FullText" : ""}`;
|
|
2973
2905
|
this.registerSchema(`StringFilter${this.filterSchemaSuffix({
|
|
2974
2906
|
optional,
|
|
@@ -2978,45 +2910,45 @@ var ZodSchemaFactory = class {
|
|
|
2978
2910
|
return schema;
|
|
2979
2911
|
}
|
|
2980
2912
|
makeStringModeSchema() {
|
|
2981
|
-
return z
|
|
2913
|
+
return z.union([z.literal("default"), z.literal("insensitive")]);
|
|
2982
2914
|
}
|
|
2983
2915
|
makeFuzzyFilterSchema() {
|
|
2984
|
-
return z
|
|
2985
|
-
search: z
|
|
2986
|
-
mode: z
|
|
2987
|
-
z
|
|
2988
|
-
z
|
|
2989
|
-
z
|
|
2916
|
+
return z.strictObject({
|
|
2917
|
+
search: z.string().min(1),
|
|
2918
|
+
mode: z.union([
|
|
2919
|
+
z.literal("simple"),
|
|
2920
|
+
z.literal("word"),
|
|
2921
|
+
z.literal("strictWord")
|
|
2990
2922
|
]).default("simple"),
|
|
2991
|
-
threshold: z
|
|
2992
|
-
unaccent: z
|
|
2923
|
+
threshold: z.number().min(0).max(1).optional(),
|
|
2924
|
+
unaccent: z.boolean().default(false)
|
|
2993
2925
|
});
|
|
2994
2926
|
}
|
|
2995
2927
|
makeFullTextFilterSchema() {
|
|
2996
|
-
return z
|
|
2997
|
-
search: z
|
|
2998
|
-
config: z
|
|
2928
|
+
return z.strictObject({
|
|
2929
|
+
search: z.string().min(1),
|
|
2930
|
+
config: z.string().min(1).optional()
|
|
2999
2931
|
});
|
|
3000
2932
|
}
|
|
3001
2933
|
makeSelectSchema(model, options) {
|
|
3002
2934
|
const fields = {};
|
|
3003
2935
|
for (const [field, fieldDef] of this.getModelFields(model)) {
|
|
3004
2936
|
if (this.isParameterizedComputedField(fieldDef)) {
|
|
3005
|
-
fields[field] = z
|
|
2937
|
+
fields[field] = z.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional();
|
|
3006
2938
|
continue;
|
|
3007
2939
|
}
|
|
3008
2940
|
if (fieldDef.relation) {
|
|
3009
2941
|
if (!this.shouldIncludeRelations(options)) continue;
|
|
3010
2942
|
if (this.isModelAllowed(fieldDef.type)) fields[field] = this.makeRelationSelectIncludeSchema(model, field, options).optional();
|
|
3011
|
-
} else if (this.options.allowQueryTimeOmitOverride === false && this.isFieldOmittedByConfig(model, field)) fields[field] = z
|
|
3012
|
-
else fields[field] = z
|
|
2943
|
+
} else if (this.options.allowQueryTimeOmitOverride === false && this.isFieldOmittedByConfig(model, field)) fields[field] = z.literal(false).optional();
|
|
2944
|
+
else fields[field] = z.boolean().optional();
|
|
3013
2945
|
}
|
|
3014
2946
|
if (this.shouldIncludeRelations(options)) {
|
|
3015
2947
|
const _countSchema = this.makeCountSelectionSchema(model, options);
|
|
3016
|
-
if (!(_countSchema instanceof z
|
|
2948
|
+
if (!(_countSchema instanceof z.ZodNever)) fields["_count"] = _countSchema;
|
|
3017
2949
|
}
|
|
3018
2950
|
this.addExtResultFields(model, fields);
|
|
3019
|
-
const result = z
|
|
2951
|
+
const result = z.strictObject(fields);
|
|
3020
2952
|
this.registerSchema(`${model}Select`, result);
|
|
3021
2953
|
return result;
|
|
3022
2954
|
}
|
|
@@ -3025,24 +2957,24 @@ var ZodSchemaFactory = class {
|
|
|
3025
2957
|
const toManyRelations = Object.values(modelDef.fields).filter((def) => def.relation && def.array);
|
|
3026
2958
|
if (toManyRelations.length > 0) {
|
|
3027
2959
|
const nextOpts = this.nextOptions(options);
|
|
3028
|
-
const schema = z
|
|
2960
|
+
const schema = z.union([z.literal(true), z.strictObject({ select: z.strictObject(toManyRelations.reduce((acc, fieldDef) => ({
|
|
3029
2961
|
...acc,
|
|
3030
|
-
[fieldDef.name]: z
|
|
2962
|
+
[fieldDef.name]: z.union([z.boolean(), z.strictObject({ where: this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts) })]).optional()
|
|
3031
2963
|
}), {})) })]).optional();
|
|
3032
2964
|
this.registerSchema(`${model}CountSelection`, schema);
|
|
3033
2965
|
return schema;
|
|
3034
|
-
} else return z
|
|
2966
|
+
} else return z.never();
|
|
3035
2967
|
}
|
|
3036
2968
|
makeRelationSelectIncludeSchema(model, field, options) {
|
|
3037
2969
|
const fieldDef = requireField(this.schema, model, field);
|
|
3038
2970
|
const nextOpts = this.nextOptions(options);
|
|
3039
|
-
let objSchema = z
|
|
3040
|
-
...fieldDef.array || fieldDef.optional ? { where: z
|
|
3041
|
-
select: z
|
|
3042
|
-
include: z
|
|
3043
|
-
omit: z
|
|
2971
|
+
let objSchema = z.strictObject({
|
|
2972
|
+
...fieldDef.array || fieldDef.optional ? { where: z.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts)).optional() } : {},
|
|
2973
|
+
select: z.lazy(() => this.makeSelectSchema(fieldDef.type, nextOpts)).optional().nullable(),
|
|
2974
|
+
include: z.lazy(() => this.makeIncludeSchema(fieldDef.type, nextOpts)).optional().nullable(),
|
|
2975
|
+
omit: z.lazy(() => this.makeOmitSchema(fieldDef.type)).optional().nullable(),
|
|
3044
2976
|
...fieldDef.array ? {
|
|
3045
|
-
orderBy: z
|
|
2977
|
+
orderBy: z.lazy(() => this.orArray(this.makeOrderBySchema(fieldDef.type, true, false, nextOpts), true)).optional(),
|
|
3046
2978
|
skip: this.makeSkipSchema().optional(),
|
|
3047
2979
|
take: this.makeTakeSchema().optional(),
|
|
3048
2980
|
cursor: this.makeCursorSchema(fieldDef.type, nextOpts).optional(),
|
|
@@ -3052,7 +2984,7 @@ var ZodSchemaFactory = class {
|
|
|
3052
2984
|
objSchema = this.refineForSelectIncludeMutuallyExclusive(objSchema);
|
|
3053
2985
|
objSchema = this.refineForSelectOmitMutuallyExclusive(objSchema);
|
|
3054
2986
|
objSchema = this.refineForSelectHasTruthyField(objSchema);
|
|
3055
|
-
const result = z
|
|
2987
|
+
const result = z.union([z.boolean(), objSchema]);
|
|
3056
2988
|
this.registerSchema(`${model}${upperCaseFirst(field)}RelationInput`, result);
|
|
3057
2989
|
return result;
|
|
3058
2990
|
}
|
|
@@ -3069,11 +3001,11 @@ var ZodSchemaFactory = class {
|
|
|
3069
3001
|
const fields = {};
|
|
3070
3002
|
for (const [field, fieldDef] of this.getModelFields(model)) {
|
|
3071
3003
|
if (this.isParameterizedComputedField(fieldDef)) continue;
|
|
3072
|
-
if (!fieldDef.relation) if (this.options.allowQueryTimeOmitOverride !== false) fields[field] = z
|
|
3073
|
-
else fields[field] = z
|
|
3004
|
+
if (!fieldDef.relation) if (this.options.allowQueryTimeOmitOverride !== false) fields[field] = z.boolean().optional();
|
|
3005
|
+
else fields[field] = z.literal(true).optional();
|
|
3074
3006
|
}
|
|
3075
3007
|
this.addExtResultFields(model, fields);
|
|
3076
|
-
const result = z
|
|
3008
|
+
const result = z.strictObject(fields);
|
|
3077
3009
|
this.registerSchema(`${model}OmitInput`, result);
|
|
3078
3010
|
return result;
|
|
3079
3011
|
}
|
|
@@ -3082,7 +3014,7 @@ var ZodSchemaFactory = class {
|
|
|
3082
3014
|
const resultConfig = plugin.result;
|
|
3083
3015
|
if (resultConfig) {
|
|
3084
3016
|
const modelConfig = resultConfig[lowerCaseFirst(model)];
|
|
3085
|
-
if (modelConfig) for (const field of Object.keys(modelConfig)) fields[field] = z
|
|
3017
|
+
if (modelConfig) for (const field of Object.keys(modelConfig)) fields[field] = z.boolean().optional();
|
|
3086
3018
|
}
|
|
3087
3019
|
}
|
|
3088
3020
|
}
|
|
@@ -3094,35 +3026,35 @@ var ZodSchemaFactory = class {
|
|
|
3094
3026
|
if (fieldDef.relation) {
|
|
3095
3027
|
if (!this.shouldIncludeRelations(options)) continue;
|
|
3096
3028
|
if (this.isModelAllowed(fieldDef.type)) fields[field] = this.makeRelationSelectIncludeSchema(model, field, options).optional();
|
|
3097
|
-
} else if (this.isParameterizedComputedField(fieldDef)) fields[field] = z
|
|
3029
|
+
} else if (this.isParameterizedComputedField(fieldDef)) fields[field] = z.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional();
|
|
3098
3030
|
}
|
|
3099
3031
|
if (this.shouldIncludeRelations(options)) {
|
|
3100
3032
|
const _countSchema = this.makeCountSelectionSchema(model, options);
|
|
3101
|
-
if (!(_countSchema instanceof z
|
|
3033
|
+
if (!(_countSchema instanceof z.ZodNever)) fields["_count"] = _countSchema;
|
|
3102
3034
|
}
|
|
3103
|
-
const result = z
|
|
3035
|
+
const result = z.strictObject(fields);
|
|
3104
3036
|
this.registerSchema(`${model}Include`, result);
|
|
3105
3037
|
return result;
|
|
3106
3038
|
}
|
|
3107
3039
|
makeOrderBySchema(model, withRelation, WithAggregation, options) {
|
|
3108
3040
|
const fields = {};
|
|
3109
|
-
const sort = z
|
|
3041
|
+
const sort = z.union([z.literal("asc"), z.literal("desc")]);
|
|
3110
3042
|
const refineAtMostOneKey = (s) => s.refine((v) => Object.keys(v).length <= 1, { message: "Each orderBy element must have at most one key" });
|
|
3111
3043
|
const nextOpts = this.nextOptions(options);
|
|
3112
3044
|
for (const [field, fieldDef] of this.getModelFields(model)) if (fieldDef.relation) {
|
|
3113
|
-
if (withRelation && this.shouldIncludeRelations(options)) fields[field] = z
|
|
3045
|
+
if (withRelation && this.shouldIncludeRelations(options)) fields[field] = z.lazy(() => {
|
|
3114
3046
|
let relationOrderBy = this.makeOrderBySchema(fieldDef.type, withRelation, WithAggregation, nextOpts);
|
|
3115
3047
|
if (fieldDef.array) relationOrderBy = refineAtMostOneKey(relationOrderBy.safeExtend({ _count: sort }));
|
|
3116
3048
|
return relationOrderBy;
|
|
3117
3049
|
}).optional();
|
|
3118
|
-
} else if (fieldDef.computed && fieldDef.params) fields[field] = z
|
|
3050
|
+
} else if (fieldDef.computed && fieldDef.params) fields[field] = z.strictObject({
|
|
3119
3051
|
args: this.makeFieldArgsSchema(fieldDef.params),
|
|
3120
3052
|
sort,
|
|
3121
|
-
nulls: z
|
|
3053
|
+
nulls: z.union([z.literal("first"), z.literal("last")]).optional()
|
|
3122
3054
|
}).optional();
|
|
3123
|
-
else if (fieldDef.optional) fields[field] = z
|
|
3055
|
+
else if (fieldDef.optional) fields[field] = z.union([sort, z.strictObject({
|
|
3124
3056
|
sort,
|
|
3125
|
-
nulls: z
|
|
3057
|
+
nulls: z.union([z.literal("first"), z.literal("last")]).optional()
|
|
3126
3058
|
})]).optional();
|
|
3127
3059
|
else fields[field] = sort.optional();
|
|
3128
3060
|
if (WithAggregation) for (const agg of [
|
|
@@ -3131,31 +3063,31 @@ var ZodSchemaFactory = class {
|
|
|
3131
3063
|
"_sum",
|
|
3132
3064
|
"_min",
|
|
3133
3065
|
"_max"
|
|
3134
|
-
]) fields[agg] = z
|
|
3066
|
+
]) fields[agg] = z.lazy(() => this.makeOrderBySchema(model, true, false, options).optional());
|
|
3135
3067
|
if (this.providerSupportsFuzzySearch) {
|
|
3136
3068
|
const fuzzyFieldNames = this.getModelFields(model).filter(([, def]) => !def.relation && def.type === "String" && def.fuzzy === true).map(([name]) => name);
|
|
3137
|
-
if (fuzzyFieldNames.length > 0) fields["_fuzzyRelevance"] = z
|
|
3138
|
-
fields: z
|
|
3139
|
-
search: z
|
|
3140
|
-
mode: z
|
|
3141
|
-
z
|
|
3142
|
-
z
|
|
3143
|
-
z
|
|
3069
|
+
if (fuzzyFieldNames.length > 0) fields["_fuzzyRelevance"] = z.strictObject({
|
|
3070
|
+
fields: z.array(z.enum(fuzzyFieldNames)).min(1),
|
|
3071
|
+
search: z.string(),
|
|
3072
|
+
mode: z.union([
|
|
3073
|
+
z.literal("simple"),
|
|
3074
|
+
z.literal("word"),
|
|
3075
|
+
z.literal("strictWord")
|
|
3144
3076
|
]).default("simple"),
|
|
3145
|
-
unaccent: z
|
|
3077
|
+
unaccent: z.boolean().default(false),
|
|
3146
3078
|
sort
|
|
3147
3079
|
}).optional();
|
|
3148
3080
|
}
|
|
3149
3081
|
if (this.providerSupportsFullTextSearch) {
|
|
3150
3082
|
const fullTextFieldNames = this.getModelFields(model).filter(([, def]) => !def.relation && def.type === "String" && def.fullText === true).map(([name]) => name);
|
|
3151
|
-
if (fullTextFieldNames.length > 0) fields["_ftsRelevance"] = z
|
|
3152
|
-
fields: z
|
|
3153
|
-
search: z
|
|
3154
|
-
config: z
|
|
3083
|
+
if (fullTextFieldNames.length > 0) fields["_ftsRelevance"] = z.strictObject({
|
|
3084
|
+
fields: z.array(z.enum(fullTextFieldNames)).min(1),
|
|
3085
|
+
search: z.string().min(1),
|
|
3086
|
+
config: z.string().min(1).optional(),
|
|
3155
3087
|
sort
|
|
3156
3088
|
}).optional();
|
|
3157
3089
|
}
|
|
3158
|
-
const schema = refineAtMostOneKey(z
|
|
3090
|
+
const schema = refineAtMostOneKey(z.strictObject(fields));
|
|
3159
3091
|
let schemaId = `${model}OrderBy`;
|
|
3160
3092
|
if (withRelation) schemaId += "WithRelation";
|
|
3161
3093
|
if (WithAggregation) schemaId += "WithAggregation";
|
|
@@ -3165,7 +3097,7 @@ var ZodSchemaFactory = class {
|
|
|
3165
3097
|
}
|
|
3166
3098
|
makeDistinctSchema(model) {
|
|
3167
3099
|
const nonRelationFields = this.getModelFields(model).filter(([, def]) => !def.relation && !this.isParameterizedComputedField(def)).map(([name]) => name);
|
|
3168
|
-
const schema = nonRelationFields.length > 0 ? this.orArray(z
|
|
3100
|
+
const schema = nonRelationFields.length > 0 ? this.orArray(z.enum(nonRelationFields), true) : z.never();
|
|
3169
3101
|
this.registerSchema(`${model}DistinctInput`, schema);
|
|
3170
3102
|
return schema;
|
|
3171
3103
|
}
|
|
@@ -3176,7 +3108,7 @@ var ZodSchemaFactory = class {
|
|
|
3176
3108
|
}
|
|
3177
3109
|
makeCreateSchema(model, options) {
|
|
3178
3110
|
const dataSchema = this.makeCreateDataSchema(model, false, [], false, options);
|
|
3179
|
-
const baseSchema = z
|
|
3111
|
+
const baseSchema = z.strictObject({
|
|
3180
3112
|
data: dataSchema,
|
|
3181
3113
|
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
3182
3114
|
include: this.makeIncludeSchema(model, options).optional().nullable(),
|
|
@@ -3225,7 +3157,7 @@ var ZodSchemaFactory = class {
|
|
|
3225
3157
|
const oppositeFieldDef = requireField(this.schema, fieldDef.type, oppositeField);
|
|
3226
3158
|
if (oppositeFieldDef.relation?.fields) excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
3227
3159
|
}
|
|
3228
|
-
let fieldSchema = z
|
|
3160
|
+
let fieldSchema = z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "create", nextOpts));
|
|
3229
3161
|
if (fieldDef.optional || fieldDef.array) fieldSchema = fieldSchema.optional();
|
|
3230
3162
|
else {
|
|
3231
3163
|
let allFksOptional = false;
|
|
@@ -3242,23 +3174,23 @@ var ZodSchemaFactory = class {
|
|
|
3242
3174
|
let fieldSchema = this.makeScalarSchema(fieldDef.type, fieldDef.attributes);
|
|
3243
3175
|
if (fieldDef.array) {
|
|
3244
3176
|
fieldSchema = ZodUtils.addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
3245
|
-
fieldSchema = z
|
|
3177
|
+
fieldSchema = z.union([fieldSchema, z.strictObject({ set: fieldSchema })]).optional();
|
|
3246
3178
|
}
|
|
3247
3179
|
if (fieldDef.optional || fieldHasDefaultValue(fieldDef)) fieldSchema = fieldSchema.optional();
|
|
3248
|
-
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z
|
|
3180
|
+
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z.union([fieldSchema, z.instanceof(DbNullClass)]);
|
|
3249
3181
|
else if (this.isTypeDefType(fieldDef.type)) fieldSchema = this.makeNullableTypedJsonMutationSchema(fieldSchema);
|
|
3250
3182
|
else fieldSchema = fieldSchema.nullable();
|
|
3251
3183
|
uncheckedVariantFields[field] = fieldSchema;
|
|
3252
3184
|
if (!fieldDef.foreignKeyFor) checkedVariantFields[field] = fieldSchema;
|
|
3253
3185
|
}
|
|
3254
3186
|
});
|
|
3255
|
-
const uncheckedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z
|
|
3256
|
-
const checkedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z
|
|
3257
|
-
const result = !hasRelation ? this.orArray(uncheckedCreateSchema, canBeArray) : z
|
|
3187
|
+
const uncheckedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(uncheckedVariantFields), modelDef.attributes) : z.strictObject(uncheckedVariantFields);
|
|
3188
|
+
const checkedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(checkedVariantFields), modelDef.attributes) : z.strictObject(checkedVariantFields);
|
|
3189
|
+
const result = !hasRelation ? this.orArray(uncheckedCreateSchema, canBeArray) : z.union([
|
|
3258
3190
|
uncheckedCreateSchema,
|
|
3259
3191
|
checkedCreateSchema,
|
|
3260
|
-
...canBeArray ? [z
|
|
3261
|
-
...canBeArray ? [z
|
|
3192
|
+
...canBeArray ? [z.array(uncheckedCreateSchema)] : [],
|
|
3193
|
+
...canBeArray ? [z.array(checkedCreateSchema)] : []
|
|
3262
3194
|
]);
|
|
3263
3195
|
const idParts = [`${model}CreateData`];
|
|
3264
3196
|
if (canBeArray) idParts.push("Array");
|
|
@@ -3283,17 +3215,17 @@ var ZodSchemaFactory = class {
|
|
|
3283
3215
|
fields["disconnect"] = this.makeDisconnectDataSchema(fieldType, array, options).optional();
|
|
3284
3216
|
fields["delete"] = this.makeDeleteRelationDataSchema(fieldType, array, true, options).optional();
|
|
3285
3217
|
}
|
|
3286
|
-
fields["update"] = array ? this.orArray(z
|
|
3218
|
+
fields["update"] = array ? this.orArray(z.strictObject({
|
|
3287
3219
|
where: this.makeWhereSchema(fieldType, true, false, false, options),
|
|
3288
3220
|
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
3289
|
-
}), true).optional() : z
|
|
3221
|
+
}), true).optional() : z.union([z.strictObject({
|
|
3290
3222
|
where: this.makeWhereSchema(fieldType, false, false, false, options).optional(),
|
|
3291
3223
|
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
3292
3224
|
}), this.makeUpdateDataSchema(fieldType, withoutFields, false, options)]).optional();
|
|
3293
3225
|
if (canCreateModel) {
|
|
3294
3226
|
let upsertWhere = this.makeWhereSchema(fieldType, true, false, false, options);
|
|
3295
3227
|
if (!fieldDef.array) upsertWhere = upsertWhere.optional();
|
|
3296
|
-
fields["upsert"] = this.orArray(z
|
|
3228
|
+
fields["upsert"] = this.orArray(z.strictObject({
|
|
3297
3229
|
where: upsertWhere,
|
|
3298
3230
|
create: this.makeCreateDataSchema(fieldType, false, withoutFields, false, options),
|
|
3299
3231
|
update: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
@@ -3301,14 +3233,14 @@ var ZodSchemaFactory = class {
|
|
|
3301
3233
|
}
|
|
3302
3234
|
if (array) {
|
|
3303
3235
|
fields["set"] = this.makeSetDataSchema(fieldType, true, options).optional();
|
|
3304
|
-
fields["updateMany"] = this.orArray(z
|
|
3236
|
+
fields["updateMany"] = this.orArray(z.strictObject({
|
|
3305
3237
|
where: this.makeWhereSchema(fieldType, false, true, false, options),
|
|
3306
3238
|
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
3307
3239
|
}), true).optional();
|
|
3308
3240
|
fields["deleteMany"] = this.makeDeleteRelationDataSchema(fieldType, true, false, options).optional();
|
|
3309
3241
|
}
|
|
3310
3242
|
}
|
|
3311
|
-
return z
|
|
3243
|
+
return z.strictObject(fields);
|
|
3312
3244
|
}
|
|
3313
3245
|
makeSetDataSchema(model, canBeArray, options) {
|
|
3314
3246
|
return this.orArray(this.makeWhereSchema(model, true, false, false, options), canBeArray);
|
|
@@ -3318,23 +3250,23 @@ var ZodSchemaFactory = class {
|
|
|
3318
3250
|
}
|
|
3319
3251
|
makeDisconnectDataSchema(model, canBeArray, options) {
|
|
3320
3252
|
if (canBeArray) return this.orArray(this.makeWhereSchema(model, true, false, false, options), canBeArray);
|
|
3321
|
-
else return z
|
|
3253
|
+
else return z.union([z.boolean(), this.makeWhereSchema(model, false, false, false, options)]);
|
|
3322
3254
|
}
|
|
3323
3255
|
makeDeleteRelationDataSchema(model, toManyRelation, uniqueFilter, options) {
|
|
3324
|
-
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter, false, false, options), true) : z
|
|
3256
|
+
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter, false, false, options), true) : z.union([z.boolean(), this.makeWhereSchema(model, uniqueFilter, false, false, options)]);
|
|
3325
3257
|
}
|
|
3326
3258
|
makeConnectOrCreateDataSchema(model, canBeArray, withoutFields, options) {
|
|
3327
3259
|
const whereSchema = this.makeWhereSchema(model, true, false, false, options);
|
|
3328
3260
|
const createSchema = this.makeCreateDataSchema(model, false, withoutFields, false, options);
|
|
3329
|
-
return this.orArray(z
|
|
3261
|
+
return this.orArray(z.strictObject({
|
|
3330
3262
|
where: whereSchema,
|
|
3331
3263
|
create: createSchema
|
|
3332
3264
|
}), canBeArray);
|
|
3333
3265
|
}
|
|
3334
3266
|
makeCreateManyPayloadSchema(model, withoutFields, options) {
|
|
3335
|
-
const schema = z
|
|
3267
|
+
const schema = z.strictObject({
|
|
3336
3268
|
data: this.makeCreateDataSchema(model, true, withoutFields, true, options),
|
|
3337
|
-
skipDuplicates: z
|
|
3269
|
+
skipDuplicates: z.boolean().optional()
|
|
3338
3270
|
});
|
|
3339
3271
|
const idParts = [`${model}CreateManyPayload`];
|
|
3340
3272
|
if (withoutFields.length) idParts.push(`Without${withoutFields.slice().sort().join("")}`);
|
|
@@ -3342,7 +3274,7 @@ var ZodSchemaFactory = class {
|
|
|
3342
3274
|
return schema;
|
|
3343
3275
|
}
|
|
3344
3276
|
makeUpdateSchema(model, options) {
|
|
3345
|
-
const baseSchema = z
|
|
3277
|
+
const baseSchema = z.strictObject({
|
|
3346
3278
|
where: this.makeWhereSchema(model, true, false, false, options),
|
|
3347
3279
|
data: this.makeUpdateDataSchema(model, [], false, options),
|
|
3348
3280
|
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
@@ -3357,10 +3289,10 @@ var ZodSchemaFactory = class {
|
|
|
3357
3289
|
return schema;
|
|
3358
3290
|
}
|
|
3359
3291
|
makeUpdateManySchema(model, options) {
|
|
3360
|
-
const result = this.mergePluginArgsSchema(z
|
|
3292
|
+
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3361
3293
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3362
3294
|
data: this.makeUpdateDataSchema(model, [], true, options),
|
|
3363
|
-
limit: z
|
|
3295
|
+
limit: z.number().int().nonnegative().optional()
|
|
3364
3296
|
}), "updateMany");
|
|
3365
3297
|
this.registerSchema(`${model}UpdateManyArgs`, result);
|
|
3366
3298
|
return result;
|
|
@@ -3376,7 +3308,7 @@ var ZodSchemaFactory = class {
|
|
|
3376
3308
|
return schema;
|
|
3377
3309
|
}
|
|
3378
3310
|
makeUpsertSchema(model, options) {
|
|
3379
|
-
const baseSchema = z
|
|
3311
|
+
const baseSchema = z.strictObject({
|
|
3380
3312
|
where: this.makeWhereSchema(model, true, false, false, options),
|
|
3381
3313
|
create: this.makeCreateDataSchema(model, false, [], false, options),
|
|
3382
3314
|
update: this.makeUpdateDataSchema(model, [], false, options),
|
|
@@ -3412,27 +3344,27 @@ var ZodSchemaFactory = class {
|
|
|
3412
3344
|
const oppositeFieldDef = requireField(this.schema, fieldDef.type, oppositeField);
|
|
3413
3345
|
if (oppositeFieldDef.relation?.fields) excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
3414
3346
|
}
|
|
3415
|
-
let fieldSchema = z
|
|
3347
|
+
let fieldSchema = z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "update", nextOpts)).optional();
|
|
3416
3348
|
if (fieldDef.optional && !fieldDef.array) fieldSchema = fieldSchema.nullable();
|
|
3417
3349
|
checkedVariantFields[field] = fieldSchema;
|
|
3418
3350
|
if (fieldDef.array || !fieldDef.relation.references) uncheckedVariantFields[field] = fieldSchema;
|
|
3419
3351
|
} else {
|
|
3420
3352
|
let fieldSchema = this.makeScalarSchema(fieldDef.type, fieldDef.attributes);
|
|
3421
|
-
if (this.isNumericField(fieldDef)) fieldSchema = z
|
|
3422
|
-
set: this.nullableIf(z
|
|
3423
|
-
increment: z
|
|
3424
|
-
decrement: z
|
|
3425
|
-
multiply: z
|
|
3426
|
-
divide: z
|
|
3353
|
+
if (this.isNumericField(fieldDef)) fieldSchema = z.union([fieldSchema, z.object({
|
|
3354
|
+
set: this.nullableIf(z.number().optional(), !!fieldDef.optional).optional(),
|
|
3355
|
+
increment: z.number().optional(),
|
|
3356
|
+
decrement: z.number().optional(),
|
|
3357
|
+
multiply: z.number().optional(),
|
|
3358
|
+
divide: z.number().optional()
|
|
3427
3359
|
}).refine((v) => Object.keys(v).length === 1, "Only one of \"set\", \"increment\", \"decrement\", \"multiply\", or \"divide\" can be provided")]);
|
|
3428
3360
|
if (fieldDef.array) {
|
|
3429
3361
|
const arraySchema = ZodUtils.addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
3430
|
-
fieldSchema = z
|
|
3362
|
+
fieldSchema = z.union([arraySchema, z.object({
|
|
3431
3363
|
set: arraySchema.optional(),
|
|
3432
|
-
push: z
|
|
3364
|
+
push: z.union([fieldSchema, fieldSchema.array()]).optional()
|
|
3433
3365
|
}).refine((v) => Object.keys(v).length === 1, "Only one of \"set\", \"push\" can be provided")]);
|
|
3434
3366
|
}
|
|
3435
|
-
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z
|
|
3367
|
+
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z.union([fieldSchema, z.instanceof(DbNullClass)]);
|
|
3436
3368
|
else if (this.isTypeDefType(fieldDef.type)) fieldSchema = this.makeNullableTypedJsonMutationSchema(fieldSchema);
|
|
3437
3369
|
else fieldSchema = fieldSchema.nullable();
|
|
3438
3370
|
fieldSchema = fieldSchema.optional();
|
|
@@ -3440,9 +3372,9 @@ var ZodSchemaFactory = class {
|
|
|
3440
3372
|
if (!fieldDef.foreignKeyFor) checkedVariantFields[field] = fieldSchema;
|
|
3441
3373
|
}
|
|
3442
3374
|
});
|
|
3443
|
-
const uncheckedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z
|
|
3444
|
-
const checkedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z
|
|
3445
|
-
const result = !hasRelation ? uncheckedUpdateSchema : z
|
|
3375
|
+
const uncheckedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(uncheckedVariantFields), modelDef.attributes) : z.strictObject(uncheckedVariantFields);
|
|
3376
|
+
const checkedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(checkedVariantFields), modelDef.attributes) : z.strictObject(checkedVariantFields);
|
|
3377
|
+
const result = !hasRelation ? uncheckedUpdateSchema : z.union([uncheckedUpdateSchema, checkedUpdateSchema]);
|
|
3446
3378
|
const idParts = [`${model}UpdateData`];
|
|
3447
3379
|
if (withoutRelationFields) idParts.push("WithoutRelation");
|
|
3448
3380
|
if (withoutFields.length) idParts.push(`Without${withoutFields.slice().sort().join("")}`);
|
|
@@ -3450,7 +3382,7 @@ var ZodSchemaFactory = class {
|
|
|
3450
3382
|
return result;
|
|
3451
3383
|
}
|
|
3452
3384
|
makeDeleteSchema(model, options) {
|
|
3453
|
-
const baseSchema = z
|
|
3385
|
+
const baseSchema = z.strictObject({
|
|
3454
3386
|
where: this.makeWhereSchema(model, true, false, false, options),
|
|
3455
3387
|
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
3456
3388
|
include: this.makeIncludeSchema(model, options).optional().nullable(),
|
|
@@ -3464,15 +3396,15 @@ var ZodSchemaFactory = class {
|
|
|
3464
3396
|
return schema;
|
|
3465
3397
|
}
|
|
3466
3398
|
makeDeleteManySchema(model, options) {
|
|
3467
|
-
const result = this.mergePluginArgsSchema(z
|
|
3399
|
+
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3468
3400
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3469
|
-
limit: z
|
|
3401
|
+
limit: z.number().int().nonnegative().optional()
|
|
3470
3402
|
}), "deleteMany").optional();
|
|
3471
3403
|
this.registerSchema(`${model}DeleteManyArgs`, result);
|
|
3472
3404
|
return result;
|
|
3473
3405
|
}
|
|
3474
3406
|
makeCountSchema(model, options) {
|
|
3475
|
-
const result = this.mergePluginArgsSchema(z
|
|
3407
|
+
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3476
3408
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3477
3409
|
skip: this.makeSkipSchema().optional(),
|
|
3478
3410
|
take: this.makeTakeSchema().optional(),
|
|
@@ -3483,10 +3415,10 @@ var ZodSchemaFactory = class {
|
|
|
3483
3415
|
return result;
|
|
3484
3416
|
}
|
|
3485
3417
|
makeCountAggregateInputSchema(model) {
|
|
3486
|
-
const schema = z
|
|
3487
|
-
_all: z
|
|
3418
|
+
const schema = z.union([z.literal(true), z.strictObject({
|
|
3419
|
+
_all: z.literal(true).optional(),
|
|
3488
3420
|
...this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
|
|
3489
|
-
acc[field] = this.isParameterizedComputedField(fieldDef) ? z
|
|
3421
|
+
acc[field] = this.isParameterizedComputedField(fieldDef) ? z.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional() : z.literal(true).optional();
|
|
3490
3422
|
return acc;
|
|
3491
3423
|
}, {})
|
|
3492
3424
|
})]);
|
|
@@ -3494,7 +3426,7 @@ var ZodSchemaFactory = class {
|
|
|
3494
3426
|
return schema;
|
|
3495
3427
|
}
|
|
3496
3428
|
makeAggregateSchema(model, options) {
|
|
3497
|
-
const result = this.mergePluginArgsSchema(z
|
|
3429
|
+
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3498
3430
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3499
3431
|
skip: this.makeSkipSchema().optional(),
|
|
3500
3432
|
take: this.makeTakeSchema().optional(),
|
|
@@ -3509,16 +3441,16 @@ var ZodSchemaFactory = class {
|
|
|
3509
3441
|
return result;
|
|
3510
3442
|
}
|
|
3511
3443
|
makeSumAvgInputSchema(model) {
|
|
3512
|
-
const schema = z
|
|
3513
|
-
if (this.isNumericField(fieldDef)) acc[field] = this.isParameterizedComputedField(fieldDef) ? z
|
|
3444
|
+
const schema = z.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
|
|
3445
|
+
if (this.isNumericField(fieldDef)) acc[field] = this.isParameterizedComputedField(fieldDef) ? z.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional() : z.literal(true).optional();
|
|
3514
3446
|
return acc;
|
|
3515
3447
|
}, {}));
|
|
3516
3448
|
this.registerSchema(`${model}SumAvgAggregateInput`, schema);
|
|
3517
3449
|
return schema;
|
|
3518
3450
|
}
|
|
3519
3451
|
makeMinMaxInputSchema(model) {
|
|
3520
|
-
const schema = z
|
|
3521
|
-
if (!fieldDef.relation && !fieldDef.array) acc[field] = this.isParameterizedComputedField(fieldDef) ? z
|
|
3452
|
+
const schema = z.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
|
|
3453
|
+
if (!fieldDef.relation && !fieldDef.array) acc[field] = this.isParameterizedComputedField(fieldDef) ? z.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional() : z.literal(true).optional();
|
|
3522
3454
|
return acc;
|
|
3523
3455
|
}, {}));
|
|
3524
3456
|
this.registerSchema(`${model}MinMaxAggregateInput`, schema);
|
|
@@ -3527,14 +3459,14 @@ var ZodSchemaFactory = class {
|
|
|
3527
3459
|
makeGroupBySchema(model, options) {
|
|
3528
3460
|
const nonRelationFields = this.getModelFields(model).filter(([, def]) => !def.relation && !this.isParameterizedComputedField(def)).map(([name]) => name);
|
|
3529
3461
|
const byMembers = [];
|
|
3530
|
-
if (nonRelationFields.length > 0) byMembers.push(z
|
|
3531
|
-
for (const [field, fieldDef] of this.getModelFields(model)) if (this.isParameterizedComputedField(fieldDef)) byMembers.push(z
|
|
3532
|
-
field: z
|
|
3462
|
+
if (nonRelationFields.length > 0) byMembers.push(z.enum(nonRelationFields));
|
|
3463
|
+
for (const [field, fieldDef] of this.getModelFields(model)) if (this.isParameterizedComputedField(fieldDef)) byMembers.push(z.strictObject({
|
|
3464
|
+
field: z.literal(field),
|
|
3533
3465
|
args: this.makeFieldArgsSchema(fieldDef.params)
|
|
3534
3466
|
}));
|
|
3535
|
-
const byElement = byMembers.length === 0 ? void 0 : byMembers.length === 1 ? byMembers[0] : z
|
|
3536
|
-
const bySchema = byElement ? this.orArray(byElement, true) : z
|
|
3537
|
-
const baseSchema = z
|
|
3467
|
+
const byElement = byMembers.length === 0 ? void 0 : byMembers.length === 1 ? byMembers[0] : z.union(byMembers);
|
|
3468
|
+
const bySchema = byElement ? this.orArray(byElement, true) : z.never();
|
|
3469
|
+
const baseSchema = z.strictObject({
|
|
3538
3470
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3539
3471
|
orderBy: this.orArray(this.makeOrderBySchema(model, false, true, options), true).optional(),
|
|
3540
3472
|
by: bySchema,
|
|
@@ -3586,7 +3518,7 @@ var ZodSchemaFactory = class {
|
|
|
3586
3518
|
if (!procDef) throw createInternalError(`Procedure not found: ${procName}`);
|
|
3587
3519
|
const shape = {};
|
|
3588
3520
|
for (const param of Object.values(procDef.params ?? {})) shape[param.name] = this.makeProcedureParamSchema(param);
|
|
3589
|
-
const schema = z
|
|
3521
|
+
const schema = z.object(shape);
|
|
3590
3522
|
this.registerSchema(`${procName}ProcArgs`, schema);
|
|
3591
3523
|
return schema;
|
|
3592
3524
|
}
|
|
@@ -3594,10 +3526,10 @@ var ZodSchemaFactory = class {
|
|
|
3594
3526
|
let schema;
|
|
3595
3527
|
if (isTypeDef(this.schema, param.type)) schema = this.makeTypeDefSchema(param.type);
|
|
3596
3528
|
else if (isEnum(this.schema, param.type)) schema = this.makeEnumSchema(param.type);
|
|
3597
|
-
else if (param.type in (this.schema.models ?? {})) schema = z
|
|
3529
|
+
else if (param.type in (this.schema.models ?? {})) schema = z.record(z.string(), z.unknown());
|
|
3598
3530
|
else {
|
|
3599
3531
|
schema = this.makeScalarSchema(param.type);
|
|
3600
|
-
if (schema instanceof z
|
|
3532
|
+
if (schema instanceof z.ZodUnknown) throw createInternalError(`Unsupported procedure parameter type: ${param.type}`);
|
|
3601
3533
|
}
|
|
3602
3534
|
if (param.array) schema = schema.array();
|
|
3603
3535
|
if (param.optional) schema = schema.optional();
|
|
@@ -3633,10 +3565,10 @@ var ZodSchemaFactory = class {
|
|
|
3633
3565
|
return result;
|
|
3634
3566
|
}
|
|
3635
3567
|
makeSkipSchema() {
|
|
3636
|
-
return z
|
|
3568
|
+
return z.number().int().nonnegative();
|
|
3637
3569
|
}
|
|
3638
3570
|
makeTakeSchema() {
|
|
3639
|
-
return z
|
|
3571
|
+
return z.number().int();
|
|
3640
3572
|
}
|
|
3641
3573
|
refineForSelectIncludeMutuallyExclusive(schema) {
|
|
3642
3574
|
return schema.refine((value) => !(value["select"] && value["include"]), "\"select\" and \"include\" cannot be used together");
|
|
@@ -3655,7 +3587,7 @@ var ZodSchemaFactory = class {
|
|
|
3655
3587
|
return nullable ? schema.nullable() : schema;
|
|
3656
3588
|
}
|
|
3657
3589
|
orArray(schema, canBeArray) {
|
|
3658
|
-
return canBeArray ? z
|
|
3590
|
+
return canBeArray ? z.union([schema, z.array(schema)]) : schema;
|
|
3659
3591
|
}
|
|
3660
3592
|
isNumericField(fieldDef) {
|
|
3661
3593
|
return NUMERIC_FIELD_TYPES.includes(fieldDef.type) && !fieldDef.array;
|
|
@@ -3717,10 +3649,10 @@ var ZodSchemaFactory = class {
|
|
|
3717
3649
|
createUnionFilterSchema(valueSchema, optional, components, allowedFilterKinds) {
|
|
3718
3650
|
if (Object.keys(components).length === 0) {
|
|
3719
3651
|
if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return this.nullableIf(valueSchema, optional);
|
|
3720
|
-
return z
|
|
3652
|
+
return z.never();
|
|
3721
3653
|
}
|
|
3722
|
-
if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return z
|
|
3723
|
-
else return z
|
|
3654
|
+
if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return z.union([this.nullableIf(valueSchema, optional), z.strictObject(components)]);
|
|
3655
|
+
else return z.strictObject(components);
|
|
3724
3656
|
}
|
|
3725
3657
|
canCreateModel(model) {
|
|
3726
3658
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -4283,94 +4215,13 @@ var InputValidator = class {
|
|
|
4283
4215
|
//#endregion
|
|
4284
4216
|
//#region src/client/crud/operations/base.ts
|
|
4285
4217
|
/**
|
|
4286
|
-
*
|
|
4287
|
-
*/
|
|
4288
|
-
const CoreCrudOperations = [
|
|
4289
|
-
"findMany",
|
|
4290
|
-
"findUnique",
|
|
4291
|
-
"findFirst",
|
|
4292
|
-
"create",
|
|
4293
|
-
"createMany",
|
|
4294
|
-
"createManyAndReturn",
|
|
4295
|
-
"update",
|
|
4296
|
-
"updateMany",
|
|
4297
|
-
"updateManyAndReturn",
|
|
4298
|
-
"upsert",
|
|
4299
|
-
"delete",
|
|
4300
|
-
"deleteMany",
|
|
4301
|
-
"count",
|
|
4302
|
-
"aggregate",
|
|
4303
|
-
"groupBy",
|
|
4304
|
-
"exists"
|
|
4305
|
-
];
|
|
4306
|
-
/**
|
|
4307
|
-
* List of core read operations. It excludes the 'orThrow' variants.
|
|
4308
|
-
*/
|
|
4309
|
-
const CoreReadOperations = [
|
|
4310
|
-
"findMany",
|
|
4311
|
-
"findUnique",
|
|
4312
|
-
"findFirst",
|
|
4313
|
-
"count",
|
|
4314
|
-
"aggregate",
|
|
4315
|
-
"groupBy",
|
|
4316
|
-
"exists"
|
|
4317
|
-
];
|
|
4318
|
-
/**
|
|
4319
|
-
* List of core write operations.
|
|
4320
|
-
*/
|
|
4321
|
-
const CoreWriteOperations = [
|
|
4322
|
-
"create",
|
|
4323
|
-
"createMany",
|
|
4324
|
-
"createManyAndReturn",
|
|
4325
|
-
"update",
|
|
4326
|
-
"updateMany",
|
|
4327
|
-
"updateManyAndReturn",
|
|
4328
|
-
"upsert",
|
|
4329
|
-
"delete",
|
|
4330
|
-
"deleteMany"
|
|
4331
|
-
];
|
|
4332
|
-
/**
|
|
4333
|
-
* List of core create operations.
|
|
4334
|
-
*/
|
|
4335
|
-
const CoreCreateOperations = [
|
|
4336
|
-
"create",
|
|
4337
|
-
"createMany",
|
|
4338
|
-
"createManyAndReturn",
|
|
4339
|
-
"upsert"
|
|
4340
|
-
];
|
|
4341
|
-
/**
|
|
4342
|
-
* List of core update operations.
|
|
4343
|
-
*/
|
|
4344
|
-
const CoreUpdateOperations = [
|
|
4345
|
-
"update",
|
|
4346
|
-
"updateMany",
|
|
4347
|
-
"updateManyAndReturn",
|
|
4348
|
-
"upsert"
|
|
4349
|
-
];
|
|
4350
|
-
/**
|
|
4351
|
-
* List of core delete operations.
|
|
4352
|
-
*/
|
|
4353
|
-
const CoreDeleteOperations = ["delete", "deleteMany"];
|
|
4354
|
-
/**
|
|
4355
|
-
* List of all CRUD operations, including 'orThrow' variants.
|
|
4356
|
-
*/
|
|
4357
|
-
const AllCrudOperations = [
|
|
4358
|
-
...CoreCrudOperations,
|
|
4359
|
-
"findUniqueOrThrow",
|
|
4360
|
-
"findFirstOrThrow"
|
|
4361
|
-
];
|
|
4362
|
-
/**
|
|
4363
|
-
* List of all read operations, including 'orThrow' variants.
|
|
4218
|
+
* Maximum number of rows identified by id in a single statement during cascade delete simulation.
|
|
4364
4219
|
*/
|
|
4365
|
-
const
|
|
4366
|
-
...CoreReadOperations,
|
|
4367
|
-
"findUniqueOrThrow",
|
|
4368
|
-
"findFirstOrThrow"
|
|
4369
|
-
];
|
|
4220
|
+
const DELETE_ID_BATCH_SIZE = 1e3;
|
|
4370
4221
|
/**
|
|
4371
|
-
*
|
|
4222
|
+
* Same as `DELETE_ID_BATCH_SIZE`, for compound ids, which are matched with one `OR` branch per row.
|
|
4372
4223
|
*/
|
|
4373
|
-
const
|
|
4224
|
+
const DELETE_COMPOUND_ID_BATCH_SIZE = 100;
|
|
4374
4225
|
var BaseOperationHandler = class {
|
|
4375
4226
|
dialect;
|
|
4376
4227
|
constructor(client, model, inputValidator) {
|
|
@@ -5305,37 +5156,130 @@ var BaseOperationHandler = class {
|
|
|
5305
5156
|
normalizeRelationManipulationInput(model, data) {
|
|
5306
5157
|
return enumerate(data).map((item) => flattenCompoundUniqueFilters(this.schema, model, item));
|
|
5307
5158
|
}
|
|
5308
|
-
async delete(kysely, model, where, limit, filterModel, fieldsToReturn) {
|
|
5159
|
+
async delete(kysely, model, where, limit, filterModel, fieldsToReturn, visited) {
|
|
5309
5160
|
filterModel ??= model;
|
|
5161
|
+
visited ??= /* @__PURE__ */ new Set();
|
|
5310
5162
|
const modelDef = this.requireModel(model);
|
|
5311
5163
|
if (modelDef.baseModel) {
|
|
5312
5164
|
if (limit !== void 0) throw createNotSupportedError("Deleting with a limit is not supported for polymorphic models");
|
|
5313
|
-
return this.processBaseModelDelete(kysely, modelDef.baseModel, where, limit, filterModel);
|
|
5165
|
+
return this.processBaseModelDelete(kysely, modelDef.baseModel, where, limit, filterModel, visited);
|
|
5314
5166
|
}
|
|
5167
|
+
const cascadeRelations = this.getDelegateCascadeRelations(model, filterModel);
|
|
5168
|
+
if (cascadeRelations.length === 0) return this.executeDelete(kysely, model, where, limit, filterModel, fieldsToReturn);
|
|
5169
|
+
if (!modelDef.isDelegate) {
|
|
5170
|
+
if (limit !== void 0) throw createNotSupportedError("Deleting with a limit is not supported for polymorphic models");
|
|
5171
|
+
for (const { fieldDef } of cascadeRelations) await this.delete(kysely, fieldDef.type, { [fieldDef.relation.opposite]: where }, void 0, void 0, void 0, visited);
|
|
5172
|
+
return this.executeDelete(kysely, model, where, limit, filterModel, fieldsToReturn);
|
|
5173
|
+
}
|
|
5174
|
+
const discriminator = getDiscriminatorField(this.schema, model);
|
|
5175
|
+
const deletedRows = await this.read(kysely, filterModel, {
|
|
5176
|
+
where,
|
|
5177
|
+
select: {
|
|
5178
|
+
...this.makeIdSelect(filterModel),
|
|
5179
|
+
[discriminator]: true
|
|
5180
|
+
},
|
|
5181
|
+
...limit !== void 0 ? { take: limit } : {}
|
|
5182
|
+
});
|
|
5183
|
+
deletedRows.forEach((row) => visited.add(this.makeVisitedKey(model, row)));
|
|
5184
|
+
for (const { fieldDef, discriminatorValue } of cascadeRelations) {
|
|
5185
|
+
const parentRows = discriminatorValue === void 0 ? deletedRows : deletedRows.filter((row) => row[discriminator] === discriminatorValue);
|
|
5186
|
+
for (const batch of this.batchRows(model, parentRows)) {
|
|
5187
|
+
const childModel = fieldDef.type;
|
|
5188
|
+
const pendingRows = (await this.read(kysely, childModel, {
|
|
5189
|
+
where: this.makeChildFilter(model, fieldDef, batch),
|
|
5190
|
+
select: this.makeIdSelect(childModel)
|
|
5191
|
+
})).filter((row) => {
|
|
5192
|
+
const key = this.makeVisitedKey(childModel, row);
|
|
5193
|
+
if (visited.has(key)) return false;
|
|
5194
|
+
visited.add(key);
|
|
5195
|
+
return true;
|
|
5196
|
+
});
|
|
5197
|
+
for (const childBatch of this.batchRows(childModel, pendingRows)) await this.delete(kysely, childModel, this.makeIdsFilter(childModel, childBatch), void 0, void 0, void 0, visited);
|
|
5198
|
+
}
|
|
5199
|
+
}
|
|
5200
|
+
let numAffectedRows = 0n;
|
|
5201
|
+
const rows = [];
|
|
5202
|
+
for (const batch of this.batchRows(model, deletedRows)) {
|
|
5203
|
+
const result = await this.executeDelete(kysely, model, this.makeIdsFilter(model, batch), void 0, model, fieldsToReturn);
|
|
5204
|
+
numAffectedRows += result.numAffectedRows ?? 0n;
|
|
5205
|
+
rows.push(...result.rows);
|
|
5206
|
+
}
|
|
5207
|
+
return {
|
|
5208
|
+
numAffectedRows,
|
|
5209
|
+
rows
|
|
5210
|
+
};
|
|
5211
|
+
}
|
|
5212
|
+
async executeDelete(kysely, model, where, limit, filterModel, fieldsToReturn) {
|
|
5213
|
+
const modelDef = this.requireModel(model);
|
|
5315
5214
|
fieldsToReturn = fieldsToReturn ?? requireIdFields(this.schema, model);
|
|
5316
5215
|
let needIdFilter = false;
|
|
5317
5216
|
if (limit !== void 0 && !this.dialect.supportsDeleteWithLimit) needIdFilter = true;
|
|
5318
5217
|
if (modelDef.isDelegate || modelDef.baseModel) needIdFilter = true;
|
|
5319
5218
|
const deleteFilter = needIdFilter ? (eb) => eb(eb.refTuple(...this.buildIdFieldRefs(kysely, model)), "in", eb.selectFrom(this.dialect.buildSelectModel(filterModel, filterModel).where(() => this.dialect.buildFilter(filterModel, filterModel, where)).select(this.buildIdFieldRefs(kysely, filterModel)).$if(limit !== void 0, (qb) => qb.limit(limit)).as("$sub")).selectAll()) : () => this.dialect.buildFilter(model, model, where);
|
|
5320
|
-
await this.processDelegateRelationDelete(kysely, modelDef, where, limit);
|
|
5321
5219
|
const query = kysely.deleteFrom(model).where(deleteFilter).$if(this.dialect.supportsReturning, (qb) => qb.returning(fieldsToReturn)).$if(limit !== void 0 && this.dialect.supportsDeleteWithLimit, (qb) => qb.limit(limit)).modifyEnd(this.makeContextComment({
|
|
5322
5220
|
model,
|
|
5323
5221
|
operation: "delete"
|
|
5324
5222
|
}));
|
|
5325
5223
|
return this.executeQuery(kysely, query, "delete");
|
|
5326
5224
|
}
|
|
5327
|
-
|
|
5328
|
-
|
|
5225
|
+
/**
|
|
5226
|
+
* Gets the relations whose deletion must be simulated when deleting from the given model: relations
|
|
5227
|
+
* pointing to a model that extends a delegate model, with cascade delete on the opposite side. For a
|
|
5228
|
+
* delegate model, this includes relations declared on its sub models, because deleting a base row
|
|
5229
|
+
* cascades to the sub model rows in the database. `discriminatorValue` is set for a sub model relation:
|
|
5230
|
+
* it is the base model's discriminator value of the rows the relation can belong to.
|
|
5231
|
+
*/
|
|
5232
|
+
getDelegateCascadeRelations(model, filterModel = model) {
|
|
5233
|
+
const modelDef = this.requireModel(model);
|
|
5234
|
+
const filterDiscriminatorValue = filterModel === model ? void 0 : this.getDiscriminatorValueBelow(model, filterModel);
|
|
5235
|
+
const candidates = Object.values(modelDef.fields).map((fieldDef) => ({
|
|
5236
|
+
fieldDef,
|
|
5237
|
+
discriminatorValue: void 0
|
|
5238
|
+
}));
|
|
5239
|
+
if (modelDef.isDelegate) for (const subModel of getDelegateDescendantModels(this.schema, model)) {
|
|
5240
|
+
const discriminatorValue = this.getDiscriminatorValueBelow(model, subModel.name);
|
|
5241
|
+
if (filterDiscriminatorValue !== void 0 && discriminatorValue !== filterDiscriminatorValue) continue;
|
|
5242
|
+
for (const fieldDef of Object.values(subModel.fields)) if (!fieldDef.originModel) candidates.push({
|
|
5243
|
+
fieldDef,
|
|
5244
|
+
discriminatorValue
|
|
5245
|
+
});
|
|
5246
|
+
}
|
|
5247
|
+
return candidates.filter(({ fieldDef }) => {
|
|
5248
|
+
if (!fieldDef.relation?.opposite) return false;
|
|
5329
5249
|
const oppositeModelDef = this.requireModel(fieldDef.type);
|
|
5330
5250
|
const oppositeRelation = this.requireField(fieldDef.type, fieldDef.relation.opposite);
|
|
5331
|
-
|
|
5332
|
-
|
|
5333
|
-
|
|
5334
|
-
|
|
5335
|
-
|
|
5251
|
+
return !!oppositeModelDef.baseModel && oppositeRelation.relation?.onDelete === "Cascade";
|
|
5252
|
+
});
|
|
5253
|
+
}
|
|
5254
|
+
getDiscriminatorValueBelow(model, subModel) {
|
|
5255
|
+
let ancestor = this.requireModel(subModel);
|
|
5256
|
+
while (ancestor.baseModel !== model) ancestor = this.requireModel(ancestor.baseModel);
|
|
5257
|
+
return getDelegateDiscriminatorValue(this.schema, ancestor.name);
|
|
5336
5258
|
}
|
|
5337
|
-
|
|
5338
|
-
|
|
5259
|
+
makeVisitedKey(model, row) {
|
|
5260
|
+
let root = model;
|
|
5261
|
+
for (let base = this.requireModel(root).baseModel; base; base = this.requireModel(root).baseModel) root = base;
|
|
5262
|
+
return JSON.stringify([root, ...this.requireModel(model).idFields.map((f) => row[f])]);
|
|
5263
|
+
}
|
|
5264
|
+
makeChildFilter(model, fieldDef, parentRows) {
|
|
5265
|
+
const opposite = fieldDef.relation.opposite;
|
|
5266
|
+
const { fields, references } = this.requireField(fieldDef.type, opposite).relation ?? {};
|
|
5267
|
+
const idFields = this.requireModel(model).idFields;
|
|
5268
|
+
if (!fields || !references || !references.every((f) => idFields.includes(f))) return { [opposite]: this.makeIdsFilter(model, parentRows) };
|
|
5269
|
+
if (fields.length === 1) return { [fields[0]]: { in: parentRows.map((row) => row[references[0]]) } };
|
|
5270
|
+
return { OR: parentRows.map((row) => Object.fromEntries(fields.map((f, i) => [f, row[references[i]]]))) };
|
|
5271
|
+
}
|
|
5272
|
+
makeIdsFilter(model, rows) {
|
|
5273
|
+
const idFields = this.requireModel(model).idFields;
|
|
5274
|
+
if (idFields.length === 1) return { [idFields[0]]: { in: rows.map((row) => row[idFields[0]]) } };
|
|
5275
|
+
return { OR: rows.map((row) => Object.fromEntries(idFields.map((f) => [f, row[f]]))) };
|
|
5276
|
+
}
|
|
5277
|
+
*batchRows(model, rows) {
|
|
5278
|
+
const size = this.requireModel(model).idFields.length === 1 ? DELETE_ID_BATCH_SIZE : DELETE_COMPOUND_ID_BATCH_SIZE;
|
|
5279
|
+
for (let i = 0; i < rows.length; i += size) yield rows.slice(i, i + size);
|
|
5280
|
+
}
|
|
5281
|
+
async processBaseModelDelete(kysely, model, where, limit, filterModel, visited) {
|
|
5282
|
+
return this.delete(kysely, model, where, limit, filterModel, void 0, visited);
|
|
5339
5283
|
}
|
|
5340
5284
|
makeIdSelect(model) {
|
|
5341
5285
|
return this.requireModel(model).idFields.reduce((acc, f) => {
|
|
@@ -5638,14 +5582,8 @@ var DeleteOperationHandler = class extends BaseOperationHandler {
|
|
|
5638
5582
|
});
|
|
5639
5583
|
}
|
|
5640
5584
|
needsNestedDelete() {
|
|
5641
|
-
|
|
5642
|
-
|
|
5643
|
-
for (const fieldDef of Object.values(modelDef.fields)) if (fieldDef.relation?.opposite) {
|
|
5644
|
-
const oppositeModelDef = this.requireModel(fieldDef.type);
|
|
5645
|
-
const oppositeRelation = this.requireField(fieldDef.type, fieldDef.relation.opposite);
|
|
5646
|
-
if (oppositeModelDef.baseModel && oppositeRelation.relation?.onDelete === "Cascade") return true;
|
|
5647
|
-
}
|
|
5648
|
-
return false;
|
|
5585
|
+
if (this.requireModel(this.model).baseModel) return true;
|
|
5586
|
+
return this.getDelegateCascadeRelations(this.model).length > 0;
|
|
5649
5587
|
}
|
|
5650
5588
|
};
|
|
5651
5589
|
//#endregion
|
|
@@ -7304,7 +7242,7 @@ var ResultProcessor = class {
|
|
|
7304
7242
|
else if (key.startsWith("$delegate$")) {
|
|
7305
7243
|
if (value) {
|
|
7306
7244
|
const subRow = this.dialect.transformOutput(value, "Json", false);
|
|
7307
|
-
const subModel = key.slice(
|
|
7245
|
+
const subModel = key.slice(DELEGATE_JOINED_FIELD_PREFIX.length);
|
|
7308
7246
|
const idValues = getIdValues(this.schema, subModel, subRow);
|
|
7309
7247
|
if (Object.values(idValues).some((v) => v === null || v === void 0)) {
|
|
7310
7248
|
delete data[key];
|
|
@@ -7426,9 +7364,9 @@ var ClientImpl = class ClientImpl {
|
|
|
7426
7364
|
validateOptions(baseClient, options) {
|
|
7427
7365
|
if (!baseClient && !options.skipValidationForComputedFields) this.validateComputedFieldsConfig(options);
|
|
7428
7366
|
if (options.diagnostics) {
|
|
7429
|
-
const parseResult = z.object({
|
|
7430
|
-
slowQueryThresholdMs: z.number().nonnegative().optional(),
|
|
7431
|
-
slowQueryMaxRecords: z.int().nonnegative().or(z.literal(Infinity)).optional()
|
|
7367
|
+
const parseResult = z$1.object({
|
|
7368
|
+
slowQueryThresholdMs: z$1.number().nonnegative().optional(),
|
|
7369
|
+
slowQueryMaxRecords: z$1.int().nonnegative().or(z$1.literal(Infinity)).optional()
|
|
7432
7370
|
}).safeParse(options.diagnostics);
|
|
7433
7371
|
if (!parseResult.success) throw createConfigError(`Invalid diagnostics configuration: ${formatError(parseResult.error)}`);
|
|
7434
7372
|
}
|