@zenstackhq/orm 3.4.0-beta.3 → 3.4.0
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 +768 -968
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +505 -454
- package/dist/index.d.ts +505 -454
- package/dist/index.js +864 -1065
- package/dist/index.js.map +1 -1
- package/package.json +7 -6
package/dist/index.js
CHANGED
|
@@ -18,7 +18,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
19
|
|
|
20
20
|
// src/client/client-impl.ts
|
|
21
|
-
import { invariant as invariant14 } from "@zenstackhq/common-helpers";
|
|
21
|
+
import { invariant as invariant14, lowerCaseFirst as lowerCaseFirst3 } from "@zenstackhq/common-helpers";
|
|
22
22
|
import { CompiledQuery, DefaultConnectionProvider, DefaultQueryExecutor as DefaultQueryExecutor2, Kysely, Log, sql as sql8, Transaction } from "kysely";
|
|
23
23
|
|
|
24
24
|
// src/client/crud/operations/aggregate.ts
|
|
@@ -27,6 +27,7 @@ import { match as match8 } from "ts-pattern";
|
|
|
27
27
|
// src/client/query-utils.ts
|
|
28
28
|
var query_utils_exports = {};
|
|
29
29
|
__export(query_utils_exports, {
|
|
30
|
+
TEMP_ALIAS_PREFIX: () => TEMP_ALIAS_PREFIX,
|
|
30
31
|
aggregate: () => aggregate,
|
|
31
32
|
buildJoinPairs: () => buildJoinPairs,
|
|
32
33
|
ensureArray: () => ensureArray,
|
|
@@ -59,7 +60,8 @@ __export(query_utils_exports, {
|
|
|
59
60
|
requireIdFields: () => requireIdFields,
|
|
60
61
|
requireModel: () => requireModel,
|
|
61
62
|
requireTypeDef: () => requireTypeDef,
|
|
62
|
-
stripAlias: () => stripAlias
|
|
63
|
+
stripAlias: () => stripAlias,
|
|
64
|
+
tmpAlias: () => tmpAlias
|
|
63
65
|
});
|
|
64
66
|
import { invariant } from "@zenstackhq/common-helpers";
|
|
65
67
|
import { AliasNode, ColumnNode, ReferenceNode, TableNode } from "kysely";
|
|
@@ -575,6 +577,15 @@ function extractFieldName(node) {
|
|
|
575
577
|
}
|
|
576
578
|
}
|
|
577
579
|
__name(extractFieldName, "extractFieldName");
|
|
580
|
+
var TEMP_ALIAS_PREFIX = "$$_";
|
|
581
|
+
function tmpAlias(name) {
|
|
582
|
+
if (!name.startsWith(TEMP_ALIAS_PREFIX)) {
|
|
583
|
+
return `${TEMP_ALIAS_PREFIX}${name}`;
|
|
584
|
+
} else {
|
|
585
|
+
return name;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
__name(tmpAlias, "tmpAlias");
|
|
578
589
|
|
|
579
590
|
// src/client/crud/operations/base.ts
|
|
580
591
|
import { createId as cuid2 } from "@paralleldrive/cuid2";
|
|
@@ -851,7 +862,7 @@ var BaseCrudDialect = class {
|
|
|
851
862
|
});
|
|
852
863
|
}
|
|
853
864
|
}
|
|
854
|
-
const joinAlias = `${modelAlias}$${field}
|
|
865
|
+
const joinAlias = tmpAlias(`${modelAlias}$${field}`);
|
|
855
866
|
const joinPairs = buildJoinPairs(
|
|
856
867
|
this.schema,
|
|
857
868
|
model,
|
|
@@ -860,7 +871,7 @@ var BaseCrudDialect = class {
|
|
|
860
871
|
field,
|
|
861
872
|
joinAlias
|
|
862
873
|
);
|
|
863
|
-
const filterResultField = `${field}$
|
|
874
|
+
const filterResultField = tmpAlias(`${field}$flt`);
|
|
864
875
|
const joinSelect = this.eb.selectFrom(`${fieldDef.type} as ${joinAlias}`).where(() => this.and(...joinPairs.map(([left, right]) => this.eb(this.eb.ref(left), "=", this.eb.ref(right))))).select(() => this.eb.fn.count(this.eb.lit(1)).as(filterResultField));
|
|
865
876
|
const conditions = [];
|
|
866
877
|
if ("is" in payload || "isNot" in payload) {
|
|
@@ -893,7 +904,7 @@ var BaseCrudDialect = class {
|
|
|
893
904
|
return this.eb(this.eb.ref(`${modelAlias}.${field}`), "is", null);
|
|
894
905
|
}
|
|
895
906
|
const relationModel = fieldDef.type;
|
|
896
|
-
const relationFilterSelectAlias = `${modelAlias}$${field}$
|
|
907
|
+
const relationFilterSelectAlias = tmpAlias(`${modelAlias}$${field}$flt`);
|
|
897
908
|
const buildPkFkWhereRefs = /* @__PURE__ */ __name((eb) => {
|
|
898
909
|
const m2m = getManyToManyRelation(this.schema, model, field);
|
|
899
910
|
if (m2m) {
|
|
@@ -1357,7 +1368,7 @@ var BaseCrudDialect = class {
|
|
|
1357
1368
|
invariant2(value._count === "asc" || value._count === "desc", 'invalid orderBy value for field "_count"');
|
|
1358
1369
|
const sort = this.negateSort(value._count, negated);
|
|
1359
1370
|
result = result.orderBy((eb) => {
|
|
1360
|
-
const subQueryAlias = `${modelAlias}$
|
|
1371
|
+
const subQueryAlias = tmpAlias(`${modelAlias}$ob$${field}$ct`);
|
|
1361
1372
|
let subQuery = this.buildSelectModel(relationModel, subQueryAlias);
|
|
1362
1373
|
const joinPairs = buildJoinPairs(this.schema, model, modelAlias, field, subQueryAlias);
|
|
1363
1374
|
subQuery = subQuery.where(() => this.and(...joinPairs.map(([left, right]) => eb(this.eb.ref(left), "=", this.eb.ref(right)))));
|
|
@@ -1366,7 +1377,7 @@ var BaseCrudDialect = class {
|
|
|
1366
1377
|
}, sort);
|
|
1367
1378
|
}
|
|
1368
1379
|
} else {
|
|
1369
|
-
const joinAlias = `${modelAlias}$
|
|
1380
|
+
const joinAlias = tmpAlias(`${modelAlias}$ob$${index}`);
|
|
1370
1381
|
result = result.leftJoin(`${relationModel} as ${joinAlias}`, (join) => {
|
|
1371
1382
|
const joinPairs = buildJoinPairs(this.schema, model, modelAlias, field, joinAlias);
|
|
1372
1383
|
return join.on((eb) => this.and(...joinPairs.map(([left, right]) => eb(this.eb.ref(left), "=", this.eb.ref(right)))));
|
|
@@ -1559,7 +1570,7 @@ var LateralJoinDialectBase = class extends BaseCrudDialect {
|
|
|
1559
1570
|
__name(this, "LateralJoinDialectBase");
|
|
1560
1571
|
}
|
|
1561
1572
|
buildRelationSelection(query, model, relationField, parentAlias, payload) {
|
|
1562
|
-
const relationResultName = `${parentAlias}$${relationField}
|
|
1573
|
+
const relationResultName = tmpAlias(`${parentAlias}$${relationField}`);
|
|
1563
1574
|
const joinedQuery = this.buildRelationJSON(model, query, relationField, parentAlias, payload, relationResultName);
|
|
1564
1575
|
return joinedQuery.select(`${relationResultName}.$data as ${relationField}`);
|
|
1565
1576
|
}
|
|
@@ -1567,7 +1578,7 @@ var LateralJoinDialectBase = class extends BaseCrudDialect {
|
|
|
1567
1578
|
const relationFieldDef = requireField(this.schema, model, relationField);
|
|
1568
1579
|
const relationModel = relationFieldDef.type;
|
|
1569
1580
|
return qb.leftJoinLateral((eb) => {
|
|
1570
|
-
const relationSelectName = `${resultName}$sub
|
|
1581
|
+
const relationSelectName = tmpAlias(`${resultName}$sub`);
|
|
1571
1582
|
const relationModelDef = requireModel(this.schema, relationModel);
|
|
1572
1583
|
let tbl;
|
|
1573
1584
|
if (this.canJoinWithoutNestedSelect(relationModelDef, payload)) {
|
|
@@ -1854,7 +1865,7 @@ var MySqlCrudDialect = class extends LateralJoinDialectBase {
|
|
|
1854
1865
|
]), "=", this.transformInput(value, "Json", false))).with("array_ends_with", () => this.eb(sql2`JSON_EXTRACT(${lhs}, CONCAT('$[', JSON_LENGTH(${lhs}) - 1, ']'))`, "=", this.transformInput(value, "Json", false))).exhaustive();
|
|
1855
1866
|
}
|
|
1856
1867
|
buildJsonArrayExistsPredicate(receiver, buildFilter) {
|
|
1857
|
-
return this.eb.exists(this.eb.selectFrom(sql2`JSON_TABLE(${receiver}, '$[*]' COLUMNS(value JSON PATH '$'))`.as("$items")).select(this.eb.lit(1).as("
|
|
1868
|
+
return this.eb.exists(this.eb.selectFrom(sql2`JSON_TABLE(${receiver}, '$[*]' COLUMNS(value JSON PATH '$'))`.as("$items")).select(this.eb.lit(1).as("_")).where(buildFilter(this.eb.ref("$items.value"))));
|
|
1858
1869
|
}
|
|
1859
1870
|
getStringCasingBehavior() {
|
|
1860
1871
|
return {
|
|
@@ -2111,7 +2122,7 @@ var PostgresCrudDialect = class _PostgresCrudDialect extends LateralJoinDialectB
|
|
|
2111
2122
|
buildJsonArrayExistsPredicate(receiver, buildFilter) {
|
|
2112
2123
|
return this.eb.exists(this.eb.selectFrom(this.eb.fn("jsonb_array_elements", [
|
|
2113
2124
|
receiver
|
|
2114
|
-
]).as("$items")).select(this.eb.lit(1).as("
|
|
2125
|
+
]).as("$items")).select(this.eb.lit(1).as("_")).where(buildFilter(this.eb.ref("$items.value"))));
|
|
2115
2126
|
}
|
|
2116
2127
|
getSqlType(zmodelType) {
|
|
2117
2128
|
if (isEnum(this.schema, zmodelType)) {
|
|
@@ -2270,14 +2281,14 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
2270
2281
|
const relationFieldDef = requireField(this.schema, model, relationField);
|
|
2271
2282
|
const relationModel = relationFieldDef.type;
|
|
2272
2283
|
const relationModelDef = requireModel(this.schema, relationModel);
|
|
2273
|
-
const subQueryName = `${parentAlias}$${relationField}
|
|
2284
|
+
const subQueryName = tmpAlias(`${parentAlias}$${relationField}`);
|
|
2274
2285
|
let tbl;
|
|
2275
2286
|
if (this.canJoinWithoutNestedSelect(relationModelDef, payload)) {
|
|
2276
2287
|
tbl = this.buildModelSelect(relationModel, subQueryName, payload, false);
|
|
2277
2288
|
tbl = this.buildRelationJoinFilter(tbl, model, relationField, subQueryName, parentAlias);
|
|
2278
2289
|
} else {
|
|
2279
2290
|
tbl = eb.selectFrom(() => {
|
|
2280
|
-
const selectModelAlias = `${parentAlias}$${relationField}$sub
|
|
2291
|
+
const selectModelAlias = tmpAlias(`${parentAlias}$${relationField}$sub`);
|
|
2281
2292
|
let selectModelQuery = this.buildModelSelect(relationModel, selectModelAlias, payload, true);
|
|
2282
2293
|
selectModelQuery = this.buildRelationJoinFilter(selectModelQuery, model, relationField, selectModelAlias, parentAlias);
|
|
2283
2294
|
return selectModelQuery.as(subQueryName);
|
|
@@ -2301,7 +2312,7 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
2301
2312
|
} else if (payload.select) {
|
|
2302
2313
|
objArgs.push(...Object.entries(payload.select).filter(([, value]) => value).map(([field, value]) => {
|
|
2303
2314
|
if (field === "_count") {
|
|
2304
|
-
const subJson = this.buildCountJson(relationModel, eb, `${parentAlias}$${relationField}
|
|
2315
|
+
const subJson = this.buildCountJson(relationModel, eb, tmpAlias(`${parentAlias}$${relationField}`), value);
|
|
2305
2316
|
return [
|
|
2306
2317
|
sql4.lit(field),
|
|
2307
2318
|
subJson
|
|
@@ -2309,7 +2320,7 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
2309
2320
|
} else {
|
|
2310
2321
|
const fieldDef = requireField(this.schema, relationModel, field);
|
|
2311
2322
|
if (fieldDef.relation) {
|
|
2312
|
-
const subJson = this.buildRelationJSON(relationModel, eb, field, `${parentAlias}$${relationField}
|
|
2323
|
+
const subJson = this.buildRelationJSON(relationModel, eb, field, tmpAlias(`${parentAlias}$${relationField}`), value);
|
|
2313
2324
|
return [
|
|
2314
2325
|
sql4.lit(field),
|
|
2315
2326
|
subJson
|
|
@@ -2325,7 +2336,7 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
2325
2336
|
}
|
|
2326
2337
|
if (typeof payload === "object" && payload.include && typeof payload.include === "object") {
|
|
2327
2338
|
objArgs.push(...Object.entries(payload.include).filter(([, value]) => value).map(([field, value]) => {
|
|
2328
|
-
const subJson = this.buildRelationJSON(relationModel, eb, field, `${parentAlias}$${relationField}
|
|
2339
|
+
const subJson = this.buildRelationJSON(relationModel, eb, field, tmpAlias(`${parentAlias}$${relationField}`), value);
|
|
2329
2340
|
return [
|
|
2330
2341
|
sql4.lit(field),
|
|
2331
2342
|
subJson
|
|
@@ -2402,7 +2413,7 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
2402
2413
|
buildJsonArrayExistsPredicate(receiver, buildFilter) {
|
|
2403
2414
|
return this.eb.exists(this.eb.selectFrom(this.eb.fn("json_each", [
|
|
2404
2415
|
receiver
|
|
2405
|
-
]).as("$items")).select(this.eb.lit(1).as("
|
|
2416
|
+
]).as("$items")).select(this.eb.lit(1).as("_")).where(buildFilter(this.eb.ref("$items.value"))));
|
|
2406
2417
|
}
|
|
2407
2418
|
buildArrayLength(array) {
|
|
2408
2419
|
return this.eb.fn("json_array_length", [
|
|
@@ -2584,7 +2595,7 @@ var BaseOperationHandler = class {
|
|
|
2584
2595
|
});
|
|
2585
2596
|
}
|
|
2586
2597
|
async existsNonUnique(kysely, model, filter) {
|
|
2587
|
-
const query = kysely.selectNoFrom((eb) => eb.exists(this.dialect.buildSelectModel(model, model).select(sql5.lit(1).as("
|
|
2598
|
+
const query = kysely.selectNoFrom((eb) => eb.exists(this.dialect.buildSelectModel(model, model).select(sql5.lit(1).as("_")).where(() => this.dialect.buildFilter(model, model, filter))).as("$exists")).modifyEnd(this.makeContextComment({
|
|
2588
2599
|
model,
|
|
2589
2600
|
operation: "read"
|
|
2590
2601
|
}));
|
|
@@ -2596,7 +2607,7 @@ var BaseOperationHandler = class {
|
|
|
2596
2607
|
} catch (err) {
|
|
2597
2608
|
throw createDBQueryError(`Failed to execute query: ${err}`, err, compiled.sql, compiled.parameters);
|
|
2598
2609
|
}
|
|
2599
|
-
return !!result[0]
|
|
2610
|
+
return !!result[0]?.$exists;
|
|
2600
2611
|
}
|
|
2601
2612
|
async read(kysely, model, args) {
|
|
2602
2613
|
let query = this.dialect.buildSelectModel(model, model);
|
|
@@ -3193,7 +3204,7 @@ var BaseOperationHandler = class {
|
|
|
3193
3204
|
if (modelDef.baseModel) {
|
|
3194
3205
|
const baseUpdateResult = await this.processBaseModelUpdate(kysely, modelDef.baseModel, combinedWhere, finalData, throwIfNotFound);
|
|
3195
3206
|
finalData = baseUpdateResult.remainingFields;
|
|
3196
|
-
combinedWhere = baseUpdateResult.baseEntity;
|
|
3207
|
+
combinedWhere = baseUpdateResult.baseEntity ? getIdValues(this.schema, modelDef.baseModel, baseUpdateResult.baseEntity) : baseUpdateResult.baseEntity;
|
|
3197
3208
|
if (baseUpdateResult.baseEntity) {
|
|
3198
3209
|
for (const [key, value] of Object.entries(baseUpdateResult.baseEntity)) {
|
|
3199
3210
|
if (key in thisEntity) {
|
|
@@ -4590,11 +4601,9 @@ var UpdateOperationHandler = class extends BaseOperationHandler {
|
|
|
4590
4601
|
}
|
|
4591
4602
|
};
|
|
4592
4603
|
|
|
4593
|
-
// src/client/crud/validator/
|
|
4594
|
-
import {
|
|
4595
|
-
import
|
|
4596
|
-
import { match as match14, P as P3 } from "ts-pattern";
|
|
4597
|
-
import { z as z2, ZodType } from "zod";
|
|
4604
|
+
// src/client/crud/validator/validator.ts
|
|
4605
|
+
import { invariant as invariant9 } from "@zenstackhq/common-helpers";
|
|
4606
|
+
import { match as match14 } from "ts-pattern";
|
|
4598
4607
|
|
|
4599
4608
|
// src/utils/zod-utils.ts
|
|
4600
4609
|
import { fromError } from "zod-validation-error/v4";
|
|
@@ -4603,7 +4612,14 @@ function formatError(error) {
|
|
|
4603
4612
|
}
|
|
4604
4613
|
__name(formatError, "formatError");
|
|
4605
4614
|
|
|
4606
|
-
// src/client/
|
|
4615
|
+
// src/client/zod/factory.ts
|
|
4616
|
+
import { enumerate as enumerate3, invariant as invariant8, lowerCaseFirst } from "@zenstackhq/common-helpers";
|
|
4617
|
+
import { ZodUtils } from "@zenstackhq/zod";
|
|
4618
|
+
import Decimal4 from "decimal.js";
|
|
4619
|
+
import { match as match13, P as P2 } from "ts-pattern";
|
|
4620
|
+
import { z, ZodObject, ZodType } from "zod";
|
|
4621
|
+
|
|
4622
|
+
// src/client/zod/cache-decorator.ts
|
|
4607
4623
|
import stableStringify from "json-stable-stringify";
|
|
4608
4624
|
function cache() {
|
|
4609
4625
|
return function(_target, propertyKey, descriptor) {
|
|
@@ -4635,371 +4651,7 @@ function cache() {
|
|
|
4635
4651
|
}
|
|
4636
4652
|
__name(cache, "cache");
|
|
4637
4653
|
|
|
4638
|
-
// src/client/
|
|
4639
|
-
import { invariant as invariant8 } from "@zenstackhq/common-helpers";
|
|
4640
|
-
import Decimal4 from "decimal.js";
|
|
4641
|
-
import { match as match13, P as P2 } from "ts-pattern";
|
|
4642
|
-
import { z } from "zod";
|
|
4643
|
-
import { ZodIssueCode } from "zod/v3";
|
|
4644
|
-
function getArgValue(expr) {
|
|
4645
|
-
if (!expr || !schema_exports.ExpressionUtils.isLiteral(expr)) {
|
|
4646
|
-
return void 0;
|
|
4647
|
-
}
|
|
4648
|
-
return expr.value;
|
|
4649
|
-
}
|
|
4650
|
-
__name(getArgValue, "getArgValue");
|
|
4651
|
-
function addStringValidation(schema, attributes) {
|
|
4652
|
-
if (!attributes || attributes.length === 0) {
|
|
4653
|
-
return schema;
|
|
4654
|
-
}
|
|
4655
|
-
let result = schema;
|
|
4656
|
-
for (const attr of attributes) {
|
|
4657
|
-
match13(attr.name).with("@length", () => {
|
|
4658
|
-
const min = getArgValue(attr.args?.[0]?.value);
|
|
4659
|
-
if (min !== void 0) {
|
|
4660
|
-
result = result.min(min);
|
|
4661
|
-
}
|
|
4662
|
-
const max = getArgValue(attr.args?.[1]?.value);
|
|
4663
|
-
if (max !== void 0) {
|
|
4664
|
-
result = result.max(max);
|
|
4665
|
-
}
|
|
4666
|
-
}).with("@startsWith", () => {
|
|
4667
|
-
const value = getArgValue(attr.args?.[0]?.value);
|
|
4668
|
-
if (value !== void 0) {
|
|
4669
|
-
result = result.startsWith(value);
|
|
4670
|
-
}
|
|
4671
|
-
}).with("@endsWith", () => {
|
|
4672
|
-
const value = getArgValue(attr.args?.[0]?.value);
|
|
4673
|
-
if (value !== void 0) {
|
|
4674
|
-
result = result.endsWith(value);
|
|
4675
|
-
}
|
|
4676
|
-
}).with("@contains", () => {
|
|
4677
|
-
const value = getArgValue(attr.args?.[0]?.value);
|
|
4678
|
-
if (value !== void 0) {
|
|
4679
|
-
result = result.includes(value);
|
|
4680
|
-
}
|
|
4681
|
-
}).with("@regex", () => {
|
|
4682
|
-
const pattern = getArgValue(attr.args?.[0]?.value);
|
|
4683
|
-
if (pattern !== void 0) {
|
|
4684
|
-
result = result.regex(new RegExp(pattern));
|
|
4685
|
-
}
|
|
4686
|
-
}).with("@email", () => {
|
|
4687
|
-
result = result.email();
|
|
4688
|
-
}).with("@datetime", () => {
|
|
4689
|
-
result = result.datetime();
|
|
4690
|
-
}).with("@url", () => {
|
|
4691
|
-
result = result.url();
|
|
4692
|
-
}).with("@trim", () => {
|
|
4693
|
-
result = result.trim();
|
|
4694
|
-
}).with("@lower", () => {
|
|
4695
|
-
result = result.toLowerCase();
|
|
4696
|
-
}).with("@upper", () => {
|
|
4697
|
-
result = result.toUpperCase();
|
|
4698
|
-
});
|
|
4699
|
-
}
|
|
4700
|
-
return result;
|
|
4701
|
-
}
|
|
4702
|
-
__name(addStringValidation, "addStringValidation");
|
|
4703
|
-
function addNumberValidation(schema, attributes) {
|
|
4704
|
-
if (!attributes || attributes.length === 0) {
|
|
4705
|
-
return schema;
|
|
4706
|
-
}
|
|
4707
|
-
let result = schema;
|
|
4708
|
-
for (const attr of attributes) {
|
|
4709
|
-
const val = getArgValue(attr.args?.[0]?.value);
|
|
4710
|
-
if (val === void 0) {
|
|
4711
|
-
continue;
|
|
4712
|
-
}
|
|
4713
|
-
match13(attr.name).with("@gt", () => {
|
|
4714
|
-
result = result.gt(val);
|
|
4715
|
-
}).with("@gte", () => {
|
|
4716
|
-
result = result.gte(val);
|
|
4717
|
-
}).with("@lt", () => {
|
|
4718
|
-
result = result.lt(val);
|
|
4719
|
-
}).with("@lte", () => {
|
|
4720
|
-
result = result.lte(val);
|
|
4721
|
-
});
|
|
4722
|
-
}
|
|
4723
|
-
return result;
|
|
4724
|
-
}
|
|
4725
|
-
__name(addNumberValidation, "addNumberValidation");
|
|
4726
|
-
function addBigIntValidation(schema, attributes) {
|
|
4727
|
-
if (!attributes || attributes.length === 0) {
|
|
4728
|
-
return schema;
|
|
4729
|
-
}
|
|
4730
|
-
let result = schema;
|
|
4731
|
-
for (const attr of attributes) {
|
|
4732
|
-
const val = getArgValue(attr.args?.[0]?.value);
|
|
4733
|
-
if (val === void 0) {
|
|
4734
|
-
continue;
|
|
4735
|
-
}
|
|
4736
|
-
match13(attr.name).with("@gt", () => {
|
|
4737
|
-
result = result.gt(BigInt(val));
|
|
4738
|
-
}).with("@gte", () => {
|
|
4739
|
-
result = result.gte(BigInt(val));
|
|
4740
|
-
}).with("@lt", () => {
|
|
4741
|
-
result = result.lt(BigInt(val));
|
|
4742
|
-
}).with("@lte", () => {
|
|
4743
|
-
result = result.lte(BigInt(val));
|
|
4744
|
-
});
|
|
4745
|
-
}
|
|
4746
|
-
return result;
|
|
4747
|
-
}
|
|
4748
|
-
__name(addBigIntValidation, "addBigIntValidation");
|
|
4749
|
-
function addDecimalValidation(schema, attributes, addExtraValidation) {
|
|
4750
|
-
let result = schema;
|
|
4751
|
-
if (schema instanceof z.ZodString) {
|
|
4752
|
-
result = schema.superRefine((v, ctx) => {
|
|
4753
|
-
try {
|
|
4754
|
-
new Decimal4(v);
|
|
4755
|
-
} catch (err) {
|
|
4756
|
-
ctx.addIssue({
|
|
4757
|
-
code: z.ZodIssueCode.custom,
|
|
4758
|
-
message: `Invalid decimal: ${err}`
|
|
4759
|
-
});
|
|
4760
|
-
}
|
|
4761
|
-
}).transform((val) => new Decimal4(val));
|
|
4762
|
-
}
|
|
4763
|
-
function refine(schema2, op, value) {
|
|
4764
|
-
return schema2.superRefine((v, ctx) => {
|
|
4765
|
-
const base = z.number();
|
|
4766
|
-
const { error } = base[op](value).safeParse(v.toNumber());
|
|
4767
|
-
error?.issues.forEach((issue) => {
|
|
4768
|
-
if (op === "gt" || op === "gte") {
|
|
4769
|
-
ctx.addIssue({
|
|
4770
|
-
code: ZodIssueCode.too_small,
|
|
4771
|
-
origin: "number",
|
|
4772
|
-
minimum: value,
|
|
4773
|
-
type: "decimal",
|
|
4774
|
-
inclusive: op === "gte",
|
|
4775
|
-
message: issue.message
|
|
4776
|
-
});
|
|
4777
|
-
} else {
|
|
4778
|
-
ctx.addIssue({
|
|
4779
|
-
code: ZodIssueCode.too_big,
|
|
4780
|
-
origin: "number",
|
|
4781
|
-
maximum: value,
|
|
4782
|
-
type: "decimal",
|
|
4783
|
-
inclusive: op === "lte",
|
|
4784
|
-
message: issue.message
|
|
4785
|
-
});
|
|
4786
|
-
}
|
|
4787
|
-
});
|
|
4788
|
-
});
|
|
4789
|
-
}
|
|
4790
|
-
__name(refine, "refine");
|
|
4791
|
-
if (attributes && addExtraValidation) {
|
|
4792
|
-
for (const attr of attributes) {
|
|
4793
|
-
const val = getArgValue(attr.args?.[0]?.value);
|
|
4794
|
-
if (val === void 0) {
|
|
4795
|
-
continue;
|
|
4796
|
-
}
|
|
4797
|
-
match13(attr.name).with("@gt", () => {
|
|
4798
|
-
result = refine(result, "gt", val);
|
|
4799
|
-
}).with("@gte", () => {
|
|
4800
|
-
result = refine(result, "gte", val);
|
|
4801
|
-
}).with("@lt", () => {
|
|
4802
|
-
result = refine(result, "lt", val);
|
|
4803
|
-
}).with("@lte", () => {
|
|
4804
|
-
result = refine(result, "lte", val);
|
|
4805
|
-
});
|
|
4806
|
-
}
|
|
4807
|
-
}
|
|
4808
|
-
return result;
|
|
4809
|
-
}
|
|
4810
|
-
__name(addDecimalValidation, "addDecimalValidation");
|
|
4811
|
-
function addListValidation(schema, attributes) {
|
|
4812
|
-
if (!attributes || attributes.length === 0) {
|
|
4813
|
-
return schema;
|
|
4814
|
-
}
|
|
4815
|
-
let result = schema;
|
|
4816
|
-
for (const attr of attributes) {
|
|
4817
|
-
match13(attr.name).with("@length", () => {
|
|
4818
|
-
const min = getArgValue(attr.args?.[0]?.value);
|
|
4819
|
-
if (min !== void 0) {
|
|
4820
|
-
result = result.min(min);
|
|
4821
|
-
}
|
|
4822
|
-
const max = getArgValue(attr.args?.[1]?.value);
|
|
4823
|
-
if (max !== void 0) {
|
|
4824
|
-
result = result.max(max);
|
|
4825
|
-
}
|
|
4826
|
-
}).otherwise(() => {
|
|
4827
|
-
});
|
|
4828
|
-
}
|
|
4829
|
-
return result;
|
|
4830
|
-
}
|
|
4831
|
-
__name(addListValidation, "addListValidation");
|
|
4832
|
-
function addCustomValidation(schema, attributes) {
|
|
4833
|
-
const attrs = attributes?.filter((a) => a.name === "@@validate");
|
|
4834
|
-
if (!attrs || attrs.length === 0) {
|
|
4835
|
-
return schema;
|
|
4836
|
-
}
|
|
4837
|
-
let result = schema;
|
|
4838
|
-
for (const attr of attrs) {
|
|
4839
|
-
const expr = attr.args?.[0]?.value;
|
|
4840
|
-
if (!expr) {
|
|
4841
|
-
continue;
|
|
4842
|
-
}
|
|
4843
|
-
const message = getArgValue(attr.args?.[1]?.value);
|
|
4844
|
-
const pathExpr = attr.args?.[2]?.value;
|
|
4845
|
-
let path = void 0;
|
|
4846
|
-
if (pathExpr && schema_exports.ExpressionUtils.isArray(pathExpr)) {
|
|
4847
|
-
path = pathExpr.items.map((e) => schema_exports.ExpressionUtils.getLiteralValue(e));
|
|
4848
|
-
}
|
|
4849
|
-
result = applyValidation(result, expr, message, path);
|
|
4850
|
-
}
|
|
4851
|
-
return result;
|
|
4852
|
-
}
|
|
4853
|
-
__name(addCustomValidation, "addCustomValidation");
|
|
4854
|
-
function applyValidation(schema, expr, message, path) {
|
|
4855
|
-
const options = {};
|
|
4856
|
-
if (message) {
|
|
4857
|
-
options.error = message;
|
|
4858
|
-
}
|
|
4859
|
-
if (path) {
|
|
4860
|
-
options.path = path;
|
|
4861
|
-
}
|
|
4862
|
-
return schema.refine((data) => Boolean(evalExpression(data, expr)), options);
|
|
4863
|
-
}
|
|
4864
|
-
__name(applyValidation, "applyValidation");
|
|
4865
|
-
function evalExpression(data, expr) {
|
|
4866
|
-
return match13(expr).with({
|
|
4867
|
-
kind: "literal"
|
|
4868
|
-
}, (e) => e.value).with({
|
|
4869
|
-
kind: "array"
|
|
4870
|
-
}, (e) => e.items.map((item) => evalExpression(data, item))).with({
|
|
4871
|
-
kind: "field"
|
|
4872
|
-
}, (e) => evalField(data, e)).with({
|
|
4873
|
-
kind: "member"
|
|
4874
|
-
}, (e) => evalMember(data, e)).with({
|
|
4875
|
-
kind: "unary"
|
|
4876
|
-
}, (e) => evalUnary(data, e)).with({
|
|
4877
|
-
kind: "binary"
|
|
4878
|
-
}, (e) => evalBinary(data, e)).with({
|
|
4879
|
-
kind: "call"
|
|
4880
|
-
}, (e) => evalCall(data, e)).with({
|
|
4881
|
-
kind: "this"
|
|
4882
|
-
}, () => data ?? null).with({
|
|
4883
|
-
kind: "null"
|
|
4884
|
-
}, () => null).with({
|
|
4885
|
-
kind: "binding"
|
|
4886
|
-
}, () => {
|
|
4887
|
-
throw new Error("Binding expression is not supported in validation expressions");
|
|
4888
|
-
}).exhaustive();
|
|
4889
|
-
}
|
|
4890
|
-
__name(evalExpression, "evalExpression");
|
|
4891
|
-
function evalField(data, e) {
|
|
4892
|
-
return data?.[e.field] ?? null;
|
|
4893
|
-
}
|
|
4894
|
-
__name(evalField, "evalField");
|
|
4895
|
-
function evalUnary(data, expr) {
|
|
4896
|
-
const operand = evalExpression(data, expr.operand);
|
|
4897
|
-
switch (expr.op) {
|
|
4898
|
-
case "!":
|
|
4899
|
-
return !operand;
|
|
4900
|
-
default:
|
|
4901
|
-
throw new Error(`Unsupported unary operator: ${expr.op}`);
|
|
4902
|
-
}
|
|
4903
|
-
}
|
|
4904
|
-
__name(evalUnary, "evalUnary");
|
|
4905
|
-
function evalBinary(data, expr) {
|
|
4906
|
-
const left = evalExpression(data, expr.left);
|
|
4907
|
-
const right = evalExpression(data, expr.right);
|
|
4908
|
-
return match13(expr.op).with("&&", () => Boolean(left) && Boolean(right)).with("||", () => Boolean(left) || Boolean(right)).with("==", () => left == right).with("!=", () => left != right).with("<", () => left < right).with("<=", () => left <= right).with(">", () => left > right).with(">=", () => left >= right).with("?", () => {
|
|
4909
|
-
if (!Array.isArray(left)) {
|
|
4910
|
-
return false;
|
|
4911
|
-
}
|
|
4912
|
-
return left.some((item) => item === right);
|
|
4913
|
-
}).with("!", () => {
|
|
4914
|
-
if (!Array.isArray(left)) {
|
|
4915
|
-
return false;
|
|
4916
|
-
}
|
|
4917
|
-
return left.every((item) => item === right);
|
|
4918
|
-
}).with("^", () => {
|
|
4919
|
-
if (!Array.isArray(left)) {
|
|
4920
|
-
return false;
|
|
4921
|
-
}
|
|
4922
|
-
return !left.some((item) => item === right);
|
|
4923
|
-
}).with("in", () => {
|
|
4924
|
-
if (!Array.isArray(right)) {
|
|
4925
|
-
return false;
|
|
4926
|
-
}
|
|
4927
|
-
return right.includes(left);
|
|
4928
|
-
}).exhaustive();
|
|
4929
|
-
}
|
|
4930
|
-
__name(evalBinary, "evalBinary");
|
|
4931
|
-
function evalMember(data, expr) {
|
|
4932
|
-
let result = evalExpression(data, expr.receiver);
|
|
4933
|
-
for (const member of expr.members) {
|
|
4934
|
-
if (!result || typeof result !== "object") {
|
|
4935
|
-
return void 0;
|
|
4936
|
-
}
|
|
4937
|
-
result = result[member];
|
|
4938
|
-
}
|
|
4939
|
-
return result ?? null;
|
|
4940
|
-
}
|
|
4941
|
-
__name(evalMember, "evalMember");
|
|
4942
|
-
function evalCall(data, expr) {
|
|
4943
|
-
const fieldArg = expr.args?.[0] ? evalExpression(data, expr.args[0]) : void 0;
|
|
4944
|
-
return match13(expr.function).with("length", (f) => {
|
|
4945
|
-
if (fieldArg === void 0 || fieldArg === null) {
|
|
4946
|
-
return false;
|
|
4947
|
-
}
|
|
4948
|
-
invariant8(typeof fieldArg === "string" || Array.isArray(fieldArg), `"${f}" first argument must be a string or a list`);
|
|
4949
|
-
return fieldArg.length;
|
|
4950
|
-
}).with(P2.union("startsWith", "endsWith", "contains"), (f) => {
|
|
4951
|
-
if (fieldArg === void 0 || fieldArg === null) {
|
|
4952
|
-
return false;
|
|
4953
|
-
}
|
|
4954
|
-
invariant8(typeof fieldArg === "string", `"${f}" first argument must be a string`);
|
|
4955
|
-
invariant8(expr.args?.[1], `"${f}" requires a search argument`);
|
|
4956
|
-
const search2 = getArgValue(expr.args?.[1]);
|
|
4957
|
-
const caseInsensitive = getArgValue(expr.args?.[2]) ?? false;
|
|
4958
|
-
const matcher = /* @__PURE__ */ __name((x, y) => match13(f).with("startsWith", () => x.startsWith(y)).with("endsWith", () => x.endsWith(y)).with("contains", () => x.includes(y)).exhaustive(), "matcher");
|
|
4959
|
-
return caseInsensitive ? matcher(fieldArg.toLowerCase(), search2.toLowerCase()) : matcher(fieldArg, search2);
|
|
4960
|
-
}).with("regex", (f) => {
|
|
4961
|
-
if (fieldArg === void 0 || fieldArg === null) {
|
|
4962
|
-
return false;
|
|
4963
|
-
}
|
|
4964
|
-
invariant8(typeof fieldArg === "string", `"${f}" first argument must be a string`);
|
|
4965
|
-
const pattern = getArgValue(expr.args?.[1]);
|
|
4966
|
-
invariant8(pattern !== void 0, `"${f}" requires a pattern argument`);
|
|
4967
|
-
return new RegExp(pattern).test(fieldArg);
|
|
4968
|
-
}).with(P2.union("isEmail", "isUrl", "isDateTime"), (f) => {
|
|
4969
|
-
if (fieldArg === void 0 || fieldArg === null) {
|
|
4970
|
-
return false;
|
|
4971
|
-
}
|
|
4972
|
-
invariant8(typeof fieldArg === "string", `"${f}" first argument must be a string`);
|
|
4973
|
-
const fn = match13(f).with("isEmail", () => "email").with("isUrl", () => "url").with("isDateTime", () => "datetime").exhaustive();
|
|
4974
|
-
return z.string()[fn]().safeParse(fieldArg).success;
|
|
4975
|
-
}).with(P2.union("has", "hasEvery", "hasSome"), (f) => {
|
|
4976
|
-
invariant8(expr.args?.[1], `${f} requires a search argument`);
|
|
4977
|
-
if (fieldArg === void 0 || fieldArg === null) {
|
|
4978
|
-
return false;
|
|
4979
|
-
}
|
|
4980
|
-
invariant8(Array.isArray(fieldArg), `"${f}" first argument must be an array field`);
|
|
4981
|
-
const search2 = evalExpression(data, expr.args?.[1]);
|
|
4982
|
-
const matcher = /* @__PURE__ */ __name((x, y) => match13(f).with("has", () => x.some((item) => item === y)).with("hasEvery", () => {
|
|
4983
|
-
invariant8(Array.isArray(y), "hasEvery second argument must be an array");
|
|
4984
|
-
return y.every((v) => x.some((item) => item === v));
|
|
4985
|
-
}).with("hasSome", () => {
|
|
4986
|
-
invariant8(Array.isArray(y), "hasSome second argument must be an array");
|
|
4987
|
-
return y.some((v) => x.some((item) => item === v));
|
|
4988
|
-
}).exhaustive(), "matcher");
|
|
4989
|
-
return matcher(fieldArg, search2);
|
|
4990
|
-
}).with("isEmpty", (f) => {
|
|
4991
|
-
if (fieldArg === void 0 || fieldArg === null) {
|
|
4992
|
-
return false;
|
|
4993
|
-
}
|
|
4994
|
-
invariant8(Array.isArray(fieldArg), `"${f}" first argument must be an array field`);
|
|
4995
|
-
return fieldArg.length === 0;
|
|
4996
|
-
}).otherwise(() => {
|
|
4997
|
-
throw createNotSupportedError(`Unsupported function "${expr.function}"`);
|
|
4998
|
-
});
|
|
4999
|
-
}
|
|
5000
|
-
__name(evalCall, "evalCall");
|
|
5001
|
-
|
|
5002
|
-
// src/client/crud/validator/index.ts
|
|
4654
|
+
// src/client/zod/factory.ts
|
|
5003
4655
|
function _ts_decorate(decorators, target, key, desc) {
|
|
5004
4656
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
5005
4657
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -5011,317 +4663,199 @@ function _ts_metadata(k, v) {
|
|
|
5011
4663
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
5012
4664
|
}
|
|
5013
4665
|
__name(_ts_metadata, "_ts_metadata");
|
|
5014
|
-
|
|
4666
|
+
function createQuerySchemaFactory(clientOrSchema, options) {
|
|
4667
|
+
return new ZodSchemaFactory(clientOrSchema, options);
|
|
4668
|
+
}
|
|
4669
|
+
__name(createQuerySchemaFactory, "createQuerySchemaFactory");
|
|
4670
|
+
var ZodSchemaFactory = class {
|
|
5015
4671
|
static {
|
|
5016
|
-
__name(this, "
|
|
4672
|
+
__name(this, "ZodSchemaFactory");
|
|
5017
4673
|
}
|
|
5018
|
-
client;
|
|
5019
4674
|
schemaCache = /* @__PURE__ */ new Map();
|
|
5020
4675
|
allFilterKinds = [
|
|
5021
4676
|
...new Set(Object.values(FILTER_PROPERTY_TO_KIND))
|
|
5022
4677
|
];
|
|
5023
|
-
|
|
5024
|
-
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
4678
|
+
schema;
|
|
4679
|
+
options;
|
|
4680
|
+
constructor(clientOrSchema, options) {
|
|
4681
|
+
if ("$schema" in clientOrSchema) {
|
|
4682
|
+
this.schema = clientOrSchema.$schema;
|
|
4683
|
+
this.options = clientOrSchema.$options;
|
|
4684
|
+
} else {
|
|
4685
|
+
this.schema = clientOrSchema;
|
|
4686
|
+
this.options = options || {};
|
|
4687
|
+
}
|
|
5028
4688
|
}
|
|
5029
|
-
get
|
|
5030
|
-
return this.
|
|
4689
|
+
get plugins() {
|
|
4690
|
+
return this.options.plugins ?? [];
|
|
5031
4691
|
}
|
|
5032
4692
|
get extraValidationsEnabled() {
|
|
5033
|
-
return this.
|
|
5034
|
-
}
|
|
5035
|
-
// #region Entry points
|
|
5036
|
-
validateFindArgs(model, args, operation) {
|
|
5037
|
-
return this.validate(model, operation, (model2) => this.makeFindSchema(model2, operation), args);
|
|
4693
|
+
return this.options.validateInput !== false;
|
|
5038
4694
|
}
|
|
5039
|
-
|
|
5040
|
-
return
|
|
5041
|
-
}
|
|
5042
|
-
validateCreateArgs(model, args) {
|
|
5043
|
-
return this.validate(model, "create", (model2) => this.makeCreateSchema(model2), args);
|
|
4695
|
+
shouldIncludeRelations(options) {
|
|
4696
|
+
return options?.relationDepth === void 0 || options.relationDepth > 0;
|
|
5044
4697
|
}
|
|
5045
|
-
|
|
5046
|
-
|
|
4698
|
+
nextOptions(options) {
|
|
4699
|
+
if (!options) return void 0;
|
|
4700
|
+
if (options.relationDepth === void 0) return options;
|
|
4701
|
+
return {
|
|
4702
|
+
...options,
|
|
4703
|
+
relationDepth: options.relationDepth - 1
|
|
4704
|
+
};
|
|
5047
4705
|
}
|
|
5048
|
-
|
|
5049
|
-
|
|
4706
|
+
// #region Cache Management
|
|
4707
|
+
// @ts-ignore
|
|
4708
|
+
getCache(cacheKey) {
|
|
4709
|
+
return this.schemaCache.get(cacheKey);
|
|
5050
4710
|
}
|
|
5051
|
-
|
|
5052
|
-
|
|
4711
|
+
// @ts-ignore
|
|
4712
|
+
setCache(cacheKey, schema) {
|
|
4713
|
+
return this.schemaCache.set(cacheKey, schema);
|
|
5053
4714
|
}
|
|
5054
|
-
|
|
5055
|
-
|
|
4715
|
+
// @ts-ignore
|
|
4716
|
+
printCacheStats(detailed = false) {
|
|
4717
|
+
console.log("Schema cache size:", this.schemaCache.size);
|
|
4718
|
+
if (detailed) {
|
|
4719
|
+
for (const key of this.schemaCache.keys()) {
|
|
4720
|
+
console.log(` ${key}`);
|
|
4721
|
+
}
|
|
4722
|
+
}
|
|
5056
4723
|
}
|
|
5057
|
-
|
|
5058
|
-
|
|
4724
|
+
// #endregion
|
|
4725
|
+
// #region Find
|
|
4726
|
+
makeFindUniqueSchema(model, options) {
|
|
4727
|
+
return this.makeFindSchema(model, "findUnique", options);
|
|
5059
4728
|
}
|
|
5060
|
-
|
|
5061
|
-
return this.
|
|
4729
|
+
makeFindFirstSchema(model, options) {
|
|
4730
|
+
return this.makeFindSchema(model, "findFirst", options);
|
|
5062
4731
|
}
|
|
5063
|
-
|
|
5064
|
-
return this.
|
|
4732
|
+
makeFindManySchema(model, options) {
|
|
4733
|
+
return this.makeFindSchema(model, "findMany", options);
|
|
5065
4734
|
}
|
|
5066
|
-
|
|
5067
|
-
|
|
4735
|
+
makeFindSchema(model, operation, options) {
|
|
4736
|
+
const fields = {};
|
|
4737
|
+
const unique = operation === "findUnique";
|
|
4738
|
+
const findOne = operation === "findUnique" || operation === "findFirst";
|
|
4739
|
+
const where = this.makeWhereSchema(model, unique, false, false, options);
|
|
4740
|
+
if (unique) {
|
|
4741
|
+
fields["where"] = where;
|
|
4742
|
+
} else {
|
|
4743
|
+
fields["where"] = where.optional();
|
|
4744
|
+
}
|
|
4745
|
+
fields["select"] = this.makeSelectSchema(model, options).optional().nullable();
|
|
4746
|
+
fields["include"] = this.makeIncludeSchema(model, options).optional().nullable();
|
|
4747
|
+
fields["omit"] = this.makeOmitSchema(model).optional().nullable();
|
|
4748
|
+
if (!unique) {
|
|
4749
|
+
fields["skip"] = this.makeSkipSchema().optional();
|
|
4750
|
+
if (findOne) {
|
|
4751
|
+
fields["take"] = z.literal(1).optional();
|
|
4752
|
+
} else {
|
|
4753
|
+
fields["take"] = this.makeTakeSchema().optional();
|
|
4754
|
+
}
|
|
4755
|
+
fields["orderBy"] = this.orArray(this.makeOrderBySchema(model, true, false, options), true).optional();
|
|
4756
|
+
fields["cursor"] = this.makeCursorSchema(model, options).optional();
|
|
4757
|
+
fields["distinct"] = this.makeDistinctSchema(model).optional();
|
|
4758
|
+
}
|
|
4759
|
+
const baseSchema = z.strictObject(fields);
|
|
4760
|
+
let result = this.mergePluginArgsSchema(baseSchema, operation);
|
|
4761
|
+
result = this.refineForSelectIncludeMutuallyExclusive(result);
|
|
4762
|
+
result = this.refineForSelectOmitMutuallyExclusive(result);
|
|
4763
|
+
result = this.refineForSelectHasTruthyField(result);
|
|
4764
|
+
if (!unique) {
|
|
4765
|
+
result = result.optional();
|
|
4766
|
+
}
|
|
4767
|
+
return result;
|
|
5068
4768
|
}
|
|
5069
|
-
|
|
5070
|
-
|
|
4769
|
+
makeExistsSchema(model, options) {
|
|
4770
|
+
const baseSchema = z.strictObject({
|
|
4771
|
+
where: this.makeWhereSchema(model, false, false, false, options).optional()
|
|
4772
|
+
});
|
|
4773
|
+
return this.mergePluginArgsSchema(baseSchema, "exists").optional();
|
|
5071
4774
|
}
|
|
5072
|
-
|
|
5073
|
-
|
|
4775
|
+
makeScalarSchema(type, attributes) {
|
|
4776
|
+
if (this.schema.typeDefs && type in this.schema.typeDefs) {
|
|
4777
|
+
return this.makeTypeDefSchema(type);
|
|
4778
|
+
} else if (this.schema.enums && type in this.schema.enums) {
|
|
4779
|
+
return this.makeEnumSchema(type);
|
|
4780
|
+
} else {
|
|
4781
|
+
return match13(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([
|
|
4782
|
+
this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z.number().int(), attributes) : z.number().int(),
|
|
4783
|
+
this.extraValidationsEnabled ? ZodUtils.addBigIntValidation(z.bigint(), attributes) : z.bigint()
|
|
4784
|
+
])).with("Decimal", () => {
|
|
4785
|
+
return z.union([
|
|
4786
|
+
this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z.number(), attributes) : z.number(),
|
|
4787
|
+
ZodUtils.addDecimalValidation(z.instanceof(Decimal4), attributes, this.extraValidationsEnabled),
|
|
4788
|
+
ZodUtils.addDecimalValidation(z.string(), attributes, this.extraValidationsEnabled)
|
|
4789
|
+
]);
|
|
4790
|
+
}).with("DateTime", () => z.union([
|
|
4791
|
+
z.date(),
|
|
4792
|
+
z.iso.datetime()
|
|
4793
|
+
])).with("Bytes", () => z.instanceof(Uint8Array)).with("Json", () => this.makeJsonValueSchema(false, false)).otherwise(() => z.unknown());
|
|
4794
|
+
}
|
|
5074
4795
|
}
|
|
5075
|
-
|
|
5076
|
-
|
|
4796
|
+
makeEnumSchema(_enum) {
|
|
4797
|
+
const enumDef = getEnum(this.schema, _enum);
|
|
4798
|
+
invariant8(enumDef, `Enum "${_enum}" not found in schema`);
|
|
4799
|
+
return z.enum(Object.keys(enumDef.values));
|
|
5077
4800
|
}
|
|
5078
|
-
|
|
5079
|
-
|
|
5080
|
-
|
|
5081
|
-
|
|
5082
|
-
|
|
5083
|
-
|
|
5084
|
-
|
|
5085
|
-
return void 0;
|
|
5086
|
-
}
|
|
5087
|
-
if (params.every((p) => p.optional)) {
|
|
5088
|
-
return void 0;
|
|
5089
|
-
}
|
|
5090
|
-
throw createInvalidInputError("Missing procedure arguments", `$procs.${proc}`);
|
|
5091
|
-
}
|
|
5092
|
-
if (typeof input !== "object" || input === null || Array.isArray(input)) {
|
|
5093
|
-
throw createInvalidInputError("Procedure input must be an object", `$procs.${proc}`);
|
|
5094
|
-
}
|
|
5095
|
-
const envelope = input;
|
|
5096
|
-
const argsPayload = Object.prototype.hasOwnProperty.call(envelope, "args") ? envelope.args : void 0;
|
|
5097
|
-
if (params.length === 0) {
|
|
5098
|
-
if (typeof argsPayload === "undefined") {
|
|
5099
|
-
return input;
|
|
5100
|
-
}
|
|
5101
|
-
if (!argsPayload || typeof argsPayload !== "object" || Array.isArray(argsPayload)) {
|
|
5102
|
-
throw createInvalidInputError("Procedure `args` must be an object", `$procs.${proc}`);
|
|
4801
|
+
makeTypeDefSchema(type) {
|
|
4802
|
+
const typeDef = getTypeDef(this.schema, type);
|
|
4803
|
+
invariant8(typeDef, `Type definition "${type}" not found in schema`);
|
|
4804
|
+
const schema = z.looseObject(Object.fromEntries(Object.entries(typeDef.fields).map(([field, def]) => {
|
|
4805
|
+
let fieldSchema = this.makeScalarSchema(def.type);
|
|
4806
|
+
if (def.array) {
|
|
4807
|
+
fieldSchema = fieldSchema.array();
|
|
5103
4808
|
}
|
|
5104
|
-
if (
|
|
5105
|
-
|
|
4809
|
+
if (def.optional) {
|
|
4810
|
+
fieldSchema = fieldSchema.nullish();
|
|
5106
4811
|
}
|
|
5107
|
-
|
|
5108
|
-
|
|
5109
|
-
|
|
5110
|
-
|
|
5111
|
-
|
|
4812
|
+
return [
|
|
4813
|
+
field,
|
|
4814
|
+
fieldSchema
|
|
4815
|
+
];
|
|
4816
|
+
})));
|
|
4817
|
+
const finalSchema = z.any().superRefine((value, ctx) => {
|
|
4818
|
+
const parseResult = schema.safeParse(value);
|
|
4819
|
+
if (!parseResult.success) {
|
|
4820
|
+
parseResult.error.issues.forEach((issue) => ctx.addIssue(issue));
|
|
5112
4821
|
}
|
|
5113
|
-
|
|
5114
|
-
|
|
5115
|
-
|
|
5116
|
-
|
|
5117
|
-
|
|
5118
|
-
const
|
|
5119
|
-
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5126
|
-
|
|
5127
|
-
if (
|
|
5128
|
-
if (
|
|
5129
|
-
continue;
|
|
5130
|
-
}
|
|
5131
|
-
throw createInvalidInputError(`Invalid procedure argument: ${param.name} is required`, `$procs.${proc}`);
|
|
5132
|
-
}
|
|
5133
|
-
const schema = this.makeProcedureParamSchema(param);
|
|
5134
|
-
const parsed = schema.safeParse(value);
|
|
5135
|
-
if (!parsed.success) {
|
|
5136
|
-
throw createInvalidInputError(`Invalid procedure argument: ${param.name}: ${formatError(parsed.error)}`, `$procs.${proc}`);
|
|
5137
|
-
}
|
|
5138
|
-
}
|
|
5139
|
-
return input;
|
|
5140
|
-
}
|
|
5141
|
-
// #endregion
|
|
5142
|
-
// #region Validation helpers
|
|
5143
|
-
validate(model, operation, getSchema, args) {
|
|
5144
|
-
const schema = getSchema(model);
|
|
5145
|
-
const { error, data } = schema.safeParse(args);
|
|
5146
|
-
if (error) {
|
|
5147
|
-
throw createInvalidInputError(`Invalid ${operation} args for model "${model}": ${formatError(error)}`, model, {
|
|
5148
|
-
cause: error
|
|
5149
|
-
});
|
|
5150
|
-
}
|
|
5151
|
-
return data;
|
|
5152
|
-
}
|
|
5153
|
-
mergePluginArgsSchema(schema, operation) {
|
|
5154
|
-
let result = schema;
|
|
5155
|
-
for (const plugin of this.options.plugins ?? []) {
|
|
5156
|
-
if (plugin.queryArgs) {
|
|
5157
|
-
const pluginSchema = this.getPluginExtQueryArgsSchema(plugin, operation);
|
|
5158
|
-
if (pluginSchema) {
|
|
5159
|
-
result = result.extend(pluginSchema.shape);
|
|
5160
|
-
}
|
|
5161
|
-
}
|
|
5162
|
-
}
|
|
5163
|
-
return result.strict();
|
|
5164
|
-
}
|
|
5165
|
-
getPluginExtQueryArgsSchema(plugin, operation) {
|
|
5166
|
-
if (!plugin.queryArgs) {
|
|
5167
|
-
return void 0;
|
|
5168
|
-
}
|
|
5169
|
-
let result;
|
|
5170
|
-
if (operation in plugin.queryArgs && plugin.queryArgs[operation]) {
|
|
5171
|
-
result = plugin.queryArgs[operation];
|
|
5172
|
-
} else if (operation === "upsert") {
|
|
5173
|
-
const createSchema = "$create" in plugin.queryArgs && plugin.queryArgs["$create"] ? plugin.queryArgs["$create"] : void 0;
|
|
5174
|
-
const updateSchema = "$update" in plugin.queryArgs && plugin.queryArgs["$update"] ? plugin.queryArgs["$update"] : void 0;
|
|
5175
|
-
if (createSchema && updateSchema) {
|
|
5176
|
-
invariant9(createSchema instanceof z2.ZodObject, "Plugin extended query args schema must be a Zod object");
|
|
5177
|
-
invariant9(updateSchema instanceof z2.ZodObject, "Plugin extended query args schema must be a Zod object");
|
|
5178
|
-
result = createSchema.extend(updateSchema.shape);
|
|
5179
|
-
} else if (createSchema) {
|
|
5180
|
-
result = createSchema;
|
|
5181
|
-
} else if (updateSchema) {
|
|
5182
|
-
result = updateSchema;
|
|
5183
|
-
}
|
|
5184
|
-
} else if (
|
|
5185
|
-
// then comes grouped operations: $create, $read, $update, $delete
|
|
5186
|
-
CoreCreateOperations.includes(operation) && "$create" in plugin.queryArgs && plugin.queryArgs["$create"]
|
|
5187
|
-
) {
|
|
5188
|
-
result = plugin.queryArgs["$create"];
|
|
5189
|
-
} else if (CoreReadOperations.includes(operation) && "$read" in plugin.queryArgs && plugin.queryArgs["$read"]) {
|
|
5190
|
-
result = plugin.queryArgs["$read"];
|
|
5191
|
-
} else if (CoreUpdateOperations.includes(operation) && "$update" in plugin.queryArgs && plugin.queryArgs["$update"]) {
|
|
5192
|
-
result = plugin.queryArgs["$update"];
|
|
5193
|
-
} else if (CoreDeleteOperations.includes(operation) && "$delete" in plugin.queryArgs && plugin.queryArgs["$delete"]) {
|
|
5194
|
-
result = plugin.queryArgs["$delete"];
|
|
5195
|
-
} else if ("$all" in plugin.queryArgs && plugin.queryArgs["$all"]) {
|
|
5196
|
-
result = plugin.queryArgs["$all"];
|
|
5197
|
-
}
|
|
5198
|
-
invariant9(result === void 0 || result instanceof z2.ZodObject, "Plugin extended query args schema must be a Zod object");
|
|
5199
|
-
return result;
|
|
5200
|
-
}
|
|
5201
|
-
// #endregion
|
|
5202
|
-
// #region Find
|
|
5203
|
-
makeFindSchema(model, operation) {
|
|
5204
|
-
const fields = {};
|
|
5205
|
-
const unique = operation === "findUnique";
|
|
5206
|
-
const findOne = operation === "findUnique" || operation === "findFirst";
|
|
5207
|
-
const where = this.makeWhereSchema(model, unique);
|
|
5208
|
-
if (unique) {
|
|
5209
|
-
fields["where"] = where;
|
|
5210
|
-
} else {
|
|
5211
|
-
fields["where"] = where.optional();
|
|
5212
|
-
}
|
|
5213
|
-
fields["select"] = this.makeSelectSchema(model).optional().nullable();
|
|
5214
|
-
fields["include"] = this.makeIncludeSchema(model).optional().nullable();
|
|
5215
|
-
fields["omit"] = this.makeOmitSchema(model).optional().nullable();
|
|
5216
|
-
if (!unique) {
|
|
5217
|
-
fields["skip"] = this.makeSkipSchema().optional();
|
|
5218
|
-
if (findOne) {
|
|
5219
|
-
fields["take"] = z2.literal(1).optional();
|
|
5220
|
-
} else {
|
|
5221
|
-
fields["take"] = this.makeTakeSchema().optional();
|
|
5222
|
-
}
|
|
5223
|
-
fields["orderBy"] = this.orArray(this.makeOrderBySchema(model, true, false), true).optional();
|
|
5224
|
-
fields["cursor"] = this.makeCursorSchema(model).optional();
|
|
5225
|
-
fields["distinct"] = this.makeDistinctSchema(model).optional();
|
|
5226
|
-
}
|
|
5227
|
-
const baseSchema = z2.strictObject(fields);
|
|
5228
|
-
let result = this.mergePluginArgsSchema(baseSchema, operation);
|
|
5229
|
-
result = this.refineForSelectIncludeMutuallyExclusive(result);
|
|
5230
|
-
result = this.refineForSelectOmitMutuallyExclusive(result);
|
|
5231
|
-
if (!unique) {
|
|
5232
|
-
result = result.optional();
|
|
5233
|
-
}
|
|
5234
|
-
return result;
|
|
5235
|
-
}
|
|
5236
|
-
makeExistsSchema(model) {
|
|
5237
|
-
const baseSchema = z2.strictObject({
|
|
5238
|
-
where: this.makeWhereSchema(model, false).optional()
|
|
5239
|
-
});
|
|
5240
|
-
return this.mergePluginArgsSchema(baseSchema, "exists").optional();
|
|
5241
|
-
}
|
|
5242
|
-
makeScalarSchema(type, attributes) {
|
|
5243
|
-
if (this.schema.typeDefs && type in this.schema.typeDefs) {
|
|
5244
|
-
return this.makeTypeDefSchema(type);
|
|
5245
|
-
} else if (this.schema.enums && type in this.schema.enums) {
|
|
5246
|
-
return this.makeEnumSchema(type);
|
|
5247
|
-
} else {
|
|
5248
|
-
return match14(type).with("String", () => this.extraValidationsEnabled ? addStringValidation(z2.string(), attributes) : z2.string()).with("Int", () => this.extraValidationsEnabled ? addNumberValidation(z2.number().int(), attributes) : z2.number().int()).with("Float", () => this.extraValidationsEnabled ? addNumberValidation(z2.number(), attributes) : z2.number()).with("Boolean", () => z2.boolean()).with("BigInt", () => z2.union([
|
|
5249
|
-
this.extraValidationsEnabled ? addNumberValidation(z2.number().int(), attributes) : z2.number().int(),
|
|
5250
|
-
this.extraValidationsEnabled ? addBigIntValidation(z2.bigint(), attributes) : z2.bigint()
|
|
5251
|
-
])).with("Decimal", () => {
|
|
5252
|
-
return z2.union([
|
|
5253
|
-
this.extraValidationsEnabled ? addNumberValidation(z2.number(), attributes) : z2.number(),
|
|
5254
|
-
addDecimalValidation(z2.instanceof(Decimal5), attributes, this.extraValidationsEnabled),
|
|
5255
|
-
addDecimalValidation(z2.string(), attributes, this.extraValidationsEnabled)
|
|
5256
|
-
]);
|
|
5257
|
-
}).with("DateTime", () => z2.union([
|
|
5258
|
-
z2.date(),
|
|
5259
|
-
z2.iso.datetime()
|
|
5260
|
-
])).with("Bytes", () => z2.instanceof(Uint8Array)).with("Json", () => this.makeJsonValueSchema(false, false)).otherwise(() => z2.unknown());
|
|
5261
|
-
}
|
|
5262
|
-
}
|
|
5263
|
-
makeEnumSchema(type) {
|
|
5264
|
-
const enumDef = getEnum(this.schema, type);
|
|
5265
|
-
invariant9(enumDef, `Enum "${type}" not found in schema`);
|
|
5266
|
-
return z2.enum(Object.keys(enumDef.values));
|
|
5267
|
-
}
|
|
5268
|
-
makeTypeDefSchema(type) {
|
|
5269
|
-
const typeDef = getTypeDef(this.schema, type);
|
|
5270
|
-
invariant9(typeDef, `Type definition "${type}" not found in schema`);
|
|
5271
|
-
const schema = z2.looseObject(Object.fromEntries(Object.entries(typeDef.fields).map(([field, def]) => {
|
|
5272
|
-
let fieldSchema = this.makeScalarSchema(def.type);
|
|
5273
|
-
if (def.array) {
|
|
5274
|
-
fieldSchema = fieldSchema.array();
|
|
5275
|
-
}
|
|
5276
|
-
if (def.optional) {
|
|
5277
|
-
fieldSchema = fieldSchema.nullish();
|
|
5278
|
-
}
|
|
5279
|
-
return [
|
|
5280
|
-
field,
|
|
5281
|
-
fieldSchema
|
|
5282
|
-
];
|
|
5283
|
-
})));
|
|
5284
|
-
const finalSchema = z2.any().superRefine((value, ctx) => {
|
|
5285
|
-
const parseResult = schema.safeParse(value);
|
|
5286
|
-
if (!parseResult.success) {
|
|
5287
|
-
parseResult.error.issues.forEach((issue) => ctx.addIssue(issue));
|
|
5288
|
-
}
|
|
5289
|
-
});
|
|
5290
|
-
return finalSchema;
|
|
5291
|
-
}
|
|
5292
|
-
makeWhereSchema(model, unique, withoutRelationFields = false, withAggregations = false) {
|
|
5293
|
-
const modelDef = requireModel(this.schema, model);
|
|
5294
|
-
const uniqueFieldNames = unique ? getUniqueFields(this.schema, model).filter((uf) => (
|
|
5295
|
-
// single-field unique
|
|
5296
|
-
"def" in uf
|
|
5297
|
-
)).map((uf) => uf.name) : void 0;
|
|
5298
|
-
const fields = {};
|
|
5299
|
-
for (const field of Object.keys(modelDef.fields)) {
|
|
5300
|
-
const fieldDef = requireField(this.schema, model, field);
|
|
5301
|
-
let fieldSchema;
|
|
5302
|
-
if (fieldDef.relation) {
|
|
5303
|
-
if (withoutRelationFields) {
|
|
4822
|
+
});
|
|
4823
|
+
return finalSchema;
|
|
4824
|
+
}
|
|
4825
|
+
makeWhereSchema(model, unique, withoutRelationFields = false, withAggregations = false, options) {
|
|
4826
|
+
const modelDef = requireModel(this.schema, model);
|
|
4827
|
+
const uniqueFieldNames = unique ? getUniqueFields(this.schema, model).filter((uf) => (
|
|
4828
|
+
// single-field unique
|
|
4829
|
+
"def" in uf
|
|
4830
|
+
)).map((uf) => uf.name) : void 0;
|
|
4831
|
+
const nextOpts = this.nextOptions(options);
|
|
4832
|
+
const fields = {};
|
|
4833
|
+
for (const field of Object.keys(modelDef.fields)) {
|
|
4834
|
+
const fieldDef = requireField(this.schema, model, field);
|
|
4835
|
+
let fieldSchema;
|
|
4836
|
+
if (fieldDef.relation) {
|
|
4837
|
+
if (withoutRelationFields || !this.shouldIncludeRelations(options)) {
|
|
5304
4838
|
continue;
|
|
5305
4839
|
}
|
|
5306
4840
|
const allowedFilterKinds = this.getEffectiveFilterKinds(model, field);
|
|
5307
4841
|
if (allowedFilterKinds && !allowedFilterKinds.includes("Relation")) {
|
|
5308
|
-
fieldSchema =
|
|
4842
|
+
fieldSchema = z.never();
|
|
5309
4843
|
} else {
|
|
5310
|
-
fieldSchema =
|
|
4844
|
+
fieldSchema = z.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts).optional());
|
|
5311
4845
|
fieldSchema = this.nullableIf(fieldSchema, !fieldDef.array && !!fieldDef.optional);
|
|
5312
4846
|
if (fieldDef.array) {
|
|
5313
|
-
fieldSchema =
|
|
4847
|
+
fieldSchema = z.union([
|
|
5314
4848
|
fieldSchema,
|
|
5315
|
-
|
|
4849
|
+
z.strictObject({
|
|
5316
4850
|
some: fieldSchema.optional(),
|
|
5317
4851
|
every: fieldSchema.optional(),
|
|
5318
4852
|
none: fieldSchema.optional()
|
|
5319
4853
|
})
|
|
5320
4854
|
]);
|
|
5321
4855
|
} else {
|
|
5322
|
-
fieldSchema =
|
|
4856
|
+
fieldSchema = z.union([
|
|
5323
4857
|
fieldSchema,
|
|
5324
|
-
|
|
4858
|
+
z.strictObject({
|
|
5325
4859
|
is: fieldSchema.optional(),
|
|
5326
4860
|
isNot: fieldSchema.optional()
|
|
5327
4861
|
})
|
|
@@ -5351,15 +4885,15 @@ var InputValidator = class {
|
|
|
5351
4885
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
5352
4886
|
for (const uniqueField of uniqueFields) {
|
|
5353
4887
|
if ("defs" in uniqueField) {
|
|
5354
|
-
fields[uniqueField.name] =
|
|
5355
|
-
|
|
4888
|
+
fields[uniqueField.name] = z.object(Object.fromEntries(Object.entries(uniqueField.defs).map(([key, def]) => {
|
|
4889
|
+
invariant8(!def.relation, "unique field cannot be a relation");
|
|
5356
4890
|
let fieldSchema;
|
|
5357
4891
|
const enumDef = getEnum(this.schema, def.type);
|
|
5358
4892
|
if (enumDef) {
|
|
5359
4893
|
if (Object.keys(enumDef.values).length > 0) {
|
|
5360
4894
|
fieldSchema = this.makeEnumFilterSchema(model, def, false, true);
|
|
5361
4895
|
} else {
|
|
5362
|
-
fieldSchema =
|
|
4896
|
+
fieldSchema = z.never();
|
|
5363
4897
|
}
|
|
5364
4898
|
} else {
|
|
5365
4899
|
fieldSchema = this.makePrimitiveFilterSchema(model, def, false, true);
|
|
@@ -5372,13 +4906,13 @@ var InputValidator = class {
|
|
|
5372
4906
|
}
|
|
5373
4907
|
}
|
|
5374
4908
|
}
|
|
5375
|
-
fields["$expr"] =
|
|
4909
|
+
fields["$expr"] = z.custom((v) => typeof v === "function", {
|
|
5376
4910
|
error: '"$expr" must be a function'
|
|
5377
4911
|
}).optional();
|
|
5378
|
-
fields["AND"] = this.orArray(
|
|
5379
|
-
fields["OR"] =
|
|
5380
|
-
fields["NOT"] = this.orArray(
|
|
5381
|
-
const baseWhere =
|
|
4912
|
+
fields["AND"] = this.orArray(z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
|
|
4913
|
+
fields["OR"] = z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)).array().optional();
|
|
4914
|
+
fields["NOT"] = this.orArray(z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
|
|
4915
|
+
const baseWhere = z.strictObject(fields);
|
|
5382
4916
|
let result = baseWhere;
|
|
5383
4917
|
if (unique) {
|
|
5384
4918
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
@@ -5403,7 +4937,7 @@ var InputValidator = class {
|
|
|
5403
4937
|
const optional = !!fieldInfo.optional;
|
|
5404
4938
|
const array = !!fieldInfo.array;
|
|
5405
4939
|
const typeDef = getTypeDef(this.schema, type);
|
|
5406
|
-
|
|
4940
|
+
invariant8(typeDef, `Type definition "${type}" not found in schema`);
|
|
5407
4941
|
const candidates = [];
|
|
5408
4942
|
if (!array) {
|
|
5409
4943
|
const fieldSchemas = {};
|
|
@@ -5421,31 +4955,31 @@ var InputValidator = class {
|
|
|
5421
4955
|
}
|
|
5422
4956
|
}
|
|
5423
4957
|
}
|
|
5424
|
-
candidates.push(
|
|
4958
|
+
candidates.push(z.strictObject(fieldSchemas));
|
|
5425
4959
|
}
|
|
5426
|
-
const recursiveSchema =
|
|
4960
|
+
const recursiveSchema = z.lazy(() => this.makeTypedJsonFilterSchema(contextModel, {
|
|
5427
4961
|
name: field,
|
|
5428
4962
|
type,
|
|
5429
4963
|
optional,
|
|
5430
4964
|
array: false
|
|
5431
4965
|
})).optional();
|
|
5432
4966
|
if (array) {
|
|
5433
|
-
candidates.push(
|
|
4967
|
+
candidates.push(z.strictObject({
|
|
5434
4968
|
some: recursiveSchema,
|
|
5435
4969
|
every: recursiveSchema,
|
|
5436
4970
|
none: recursiveSchema
|
|
5437
4971
|
}));
|
|
5438
4972
|
} else {
|
|
5439
|
-
candidates.push(
|
|
4973
|
+
candidates.push(z.strictObject({
|
|
5440
4974
|
is: recursiveSchema,
|
|
5441
4975
|
isNot: recursiveSchema
|
|
5442
4976
|
}));
|
|
5443
4977
|
}
|
|
5444
4978
|
candidates.push(this.makeJsonFilterSchema(contextModel, field, optional));
|
|
5445
4979
|
if (optional) {
|
|
5446
|
-
candidates.push(
|
|
4980
|
+
candidates.push(z.null());
|
|
5447
4981
|
}
|
|
5448
|
-
return
|
|
4982
|
+
return z.union(candidates);
|
|
5449
4983
|
}
|
|
5450
4984
|
isTypeDefType(type) {
|
|
5451
4985
|
return this.schema.typeDefs && type in this.schema.typeDefs;
|
|
@@ -5455,13 +4989,13 @@ var InputValidator = class {
|
|
|
5455
4989
|
const optional = !!fieldInfo.optional;
|
|
5456
4990
|
const array = !!fieldInfo.array;
|
|
5457
4991
|
const enumDef = getEnum(this.schema, enumName);
|
|
5458
|
-
|
|
5459
|
-
const baseSchema =
|
|
4992
|
+
invariant8(enumDef, `Enum "${enumName}" not found in schema`);
|
|
4993
|
+
const baseSchema = z.enum(Object.keys(enumDef.values));
|
|
5460
4994
|
if (array) {
|
|
5461
4995
|
return this.internalMakeArrayFilterSchema(model, fieldInfo.name, baseSchema);
|
|
5462
4996
|
}
|
|
5463
4997
|
const allowedFilterKinds = ignoreSlicing ? void 0 : this.getEffectiveFilterKinds(model, fieldInfo.name);
|
|
5464
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () =>
|
|
4998
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z.lazy(() => this.makeEnumFilterSchema(model, fieldInfo, withAggregations)), [
|
|
5465
4999
|
"equals",
|
|
5466
5000
|
"in",
|
|
5467
5001
|
"notIn",
|
|
@@ -5483,43 +5017,43 @@ var InputValidator = class {
|
|
|
5483
5017
|
has: elementSchema.optional(),
|
|
5484
5018
|
hasEvery: elementSchema.array().optional(),
|
|
5485
5019
|
hasSome: elementSchema.array().optional(),
|
|
5486
|
-
isEmpty:
|
|
5020
|
+
isEmpty: z.boolean().optional()
|
|
5487
5021
|
};
|
|
5488
5022
|
const filteredOperators = this.trimFilterOperators(operators, allowedFilterKinds);
|
|
5489
|
-
return
|
|
5023
|
+
return z.strictObject(filteredOperators);
|
|
5490
5024
|
}
|
|
5491
5025
|
makePrimitiveFilterSchema(contextModel, fieldInfo, withAggregations, ignoreSlicing = false) {
|
|
5492
5026
|
const allowedFilterKinds = ignoreSlicing ? void 0 : this.getEffectiveFilterKinds(contextModel, fieldInfo.name);
|
|
5493
5027
|
const type = fieldInfo.type;
|
|
5494
5028
|
const optional = !!fieldInfo.optional;
|
|
5495
|
-
return
|
|
5029
|
+
return match13(type).with("String", () => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds)).with(P2.union("Int", "Float", "Decimal", "BigInt"), (type2) => this.makeNumberFilterSchema(this.makeScalarSchema(type2), 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(contextModel, fieldInfo.name, optional)).with("Unsupported", () => z.never()).exhaustive();
|
|
5496
5030
|
}
|
|
5497
5031
|
makeJsonValueSchema(nullable, forFilter) {
|
|
5498
5032
|
const options = [
|
|
5499
|
-
|
|
5500
|
-
|
|
5501
|
-
|
|
5502
|
-
|
|
5033
|
+
z.string(),
|
|
5034
|
+
z.number(),
|
|
5035
|
+
z.boolean(),
|
|
5036
|
+
z.instanceof(JsonNullClass)
|
|
5503
5037
|
];
|
|
5504
5038
|
if (forFilter) {
|
|
5505
|
-
options.push(
|
|
5039
|
+
options.push(z.instanceof(DbNullClass));
|
|
5506
5040
|
} else {
|
|
5507
5041
|
if (nullable) {
|
|
5508
|
-
options.push(
|
|
5042
|
+
options.push(z.instanceof(DbNullClass));
|
|
5509
5043
|
}
|
|
5510
5044
|
}
|
|
5511
5045
|
if (forFilter) {
|
|
5512
|
-
options.push(
|
|
5046
|
+
options.push(z.instanceof(AnyNullClass));
|
|
5513
5047
|
}
|
|
5514
|
-
const schema =
|
|
5048
|
+
const schema = z.union([
|
|
5515
5049
|
...options,
|
|
5516
|
-
|
|
5050
|
+
z.lazy(() => z.union([
|
|
5517
5051
|
this.makeJsonValueSchema(false, false),
|
|
5518
|
-
|
|
5052
|
+
z.null()
|
|
5519
5053
|
]).array()),
|
|
5520
|
-
|
|
5054
|
+
z.record(z.string(), z.lazy(() => z.union([
|
|
5521
5055
|
this.makeJsonValueSchema(false, false),
|
|
5522
|
-
|
|
5056
|
+
z.null()
|
|
5523
5057
|
])))
|
|
5524
5058
|
]);
|
|
5525
5059
|
return this.nullableIf(schema, nullable);
|
|
@@ -5527,16 +5061,16 @@ var InputValidator = class {
|
|
|
5527
5061
|
makeJsonFilterSchema(contextModel, field, optional) {
|
|
5528
5062
|
const allowedFilterKinds = this.getEffectiveFilterKinds(contextModel, field);
|
|
5529
5063
|
if (allowedFilterKinds && !allowedFilterKinds.includes("Json")) {
|
|
5530
|
-
return
|
|
5064
|
+
return z.never();
|
|
5531
5065
|
}
|
|
5532
5066
|
const valueSchema = this.makeJsonValueSchema(optional, true);
|
|
5533
|
-
return
|
|
5534
|
-
path:
|
|
5067
|
+
return z.strictObject({
|
|
5068
|
+
path: z.string().optional(),
|
|
5535
5069
|
equals: valueSchema.optional(),
|
|
5536
5070
|
not: valueSchema.optional(),
|
|
5537
|
-
string_contains:
|
|
5538
|
-
string_starts_with:
|
|
5539
|
-
string_ends_with:
|
|
5071
|
+
string_contains: z.string().optional(),
|
|
5072
|
+
string_starts_with: z.string().optional(),
|
|
5073
|
+
string_ends_with: z.string().optional(),
|
|
5540
5074
|
mode: this.makeStringModeSchema().optional(),
|
|
5541
5075
|
array_contains: valueSchema.optional(),
|
|
5542
5076
|
array_starts_with: valueSchema.optional(),
|
|
@@ -5544,17 +5078,17 @@ var InputValidator = class {
|
|
|
5544
5078
|
});
|
|
5545
5079
|
}
|
|
5546
5080
|
makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
5547
|
-
return this.makeCommonPrimitiveFilterSchema(
|
|
5548
|
-
|
|
5549
|
-
|
|
5550
|
-
]), optional, () =>
|
|
5081
|
+
return this.makeCommonPrimitiveFilterSchema(z.union([
|
|
5082
|
+
z.iso.datetime(),
|
|
5083
|
+
z.date()
|
|
5084
|
+
]), optional, () => z.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)), withAggregations ? [
|
|
5551
5085
|
"_count",
|
|
5552
5086
|
"_min",
|
|
5553
5087
|
"_max"
|
|
5554
5088
|
] : void 0, allowedFilterKinds);
|
|
5555
5089
|
}
|
|
5556
5090
|
makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
5557
|
-
const components = this.makeCommonPrimitiveFilterComponents(
|
|
5091
|
+
const components = this.makeCommonPrimitiveFilterComponents(z.boolean(), optional, () => z.lazy(() => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)), [
|
|
5558
5092
|
"equals",
|
|
5559
5093
|
"not"
|
|
5560
5094
|
], withAggregations ? [
|
|
@@ -5562,11 +5096,11 @@ var InputValidator = class {
|
|
|
5562
5096
|
"_min",
|
|
5563
5097
|
"_max"
|
|
5564
5098
|
] : void 0, allowedFilterKinds);
|
|
5565
|
-
return this.createUnionFilterSchema(
|
|
5099
|
+
return this.createUnionFilterSchema(z.boolean(), optional, components, allowedFilterKinds);
|
|
5566
5100
|
}
|
|
5567
5101
|
makeBytesFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
5568
|
-
const baseSchema =
|
|
5569
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () =>
|
|
5102
|
+
const baseSchema = z.instanceof(Uint8Array);
|
|
5103
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z.instanceof(Uint8Array), [
|
|
5570
5104
|
"equals",
|
|
5571
5105
|
"in",
|
|
5572
5106
|
"notIn",
|
|
@@ -5591,7 +5125,7 @@ var InputValidator = class {
|
|
|
5591
5125
|
between: baseSchema.array().length(2).optional(),
|
|
5592
5126
|
not: makeThis().optional(),
|
|
5593
5127
|
...withAggregations?.includes("_count") ? {
|
|
5594
|
-
_count: this.makeNumberFilterSchema(
|
|
5128
|
+
_count: this.makeNumberFilterSchema(z.number().int(), false, false, void 0).optional()
|
|
5595
5129
|
} : {},
|
|
5596
5130
|
...withAggregations?.includes("_avg") ? {
|
|
5597
5131
|
_avg: commonAggSchema()
|
|
@@ -5621,7 +5155,7 @@ var InputValidator = class {
|
|
|
5621
5155
|
return this.createUnionFilterSchema(baseSchema, optional, components, allowedFilterKinds);
|
|
5622
5156
|
}
|
|
5623
5157
|
makeNumberFilterSchema(baseSchema, optional, withAggregations, allowedFilterKinds) {
|
|
5624
|
-
return this.makeCommonPrimitiveFilterSchema(baseSchema, optional, () =>
|
|
5158
|
+
return this.makeCommonPrimitiveFilterSchema(baseSchema, optional, () => z.lazy(() => this.makeNumberFilterSchema(baseSchema, optional, withAggregations, allowedFilterKinds)), withAggregations ? [
|
|
5625
5159
|
"_count",
|
|
5626
5160
|
"_avg",
|
|
5627
5161
|
"_sum",
|
|
@@ -5630,15 +5164,15 @@ var InputValidator = class {
|
|
|
5630
5164
|
] : void 0, allowedFilterKinds);
|
|
5631
5165
|
}
|
|
5632
5166
|
makeStringFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
5633
|
-
const baseComponents = this.makeCommonPrimitiveFilterComponents(
|
|
5167
|
+
const baseComponents = this.makeCommonPrimitiveFilterComponents(z.string(), optional, () => z.lazy(() => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds)), void 0, withAggregations ? [
|
|
5634
5168
|
"_count",
|
|
5635
5169
|
"_min",
|
|
5636
5170
|
"_max"
|
|
5637
5171
|
] : void 0, allowedFilterKinds);
|
|
5638
5172
|
const stringSpecificOperators = {
|
|
5639
|
-
startsWith:
|
|
5640
|
-
endsWith:
|
|
5641
|
-
contains:
|
|
5173
|
+
startsWith: z.string().optional(),
|
|
5174
|
+
endsWith: z.string().optional(),
|
|
5175
|
+
contains: z.string().optional(),
|
|
5642
5176
|
...this.providerSupportsCaseSensitivity ? {
|
|
5643
5177
|
mode: this.makeStringModeSchema().optional()
|
|
5644
5178
|
} : {}
|
|
@@ -5648,78 +5182,86 @@ var InputValidator = class {
|
|
|
5648
5182
|
...baseComponents,
|
|
5649
5183
|
...filteredStringOperators
|
|
5650
5184
|
};
|
|
5651
|
-
return this.createUnionFilterSchema(
|
|
5185
|
+
return this.createUnionFilterSchema(z.string(), optional, allComponents, allowedFilterKinds);
|
|
5652
5186
|
}
|
|
5653
5187
|
makeStringModeSchema() {
|
|
5654
|
-
return
|
|
5655
|
-
|
|
5656
|
-
|
|
5188
|
+
return z.union([
|
|
5189
|
+
z.literal("default"),
|
|
5190
|
+
z.literal("insensitive")
|
|
5657
5191
|
]);
|
|
5658
5192
|
}
|
|
5659
|
-
makeSelectSchema(model) {
|
|
5193
|
+
makeSelectSchema(model, options) {
|
|
5660
5194
|
const modelDef = requireModel(this.schema, model);
|
|
5661
5195
|
const fields = {};
|
|
5662
5196
|
for (const field of Object.keys(modelDef.fields)) {
|
|
5663
5197
|
const fieldDef = requireField(this.schema, model, field);
|
|
5664
5198
|
if (fieldDef.relation) {
|
|
5199
|
+
if (!this.shouldIncludeRelations(options)) {
|
|
5200
|
+
continue;
|
|
5201
|
+
}
|
|
5665
5202
|
if (this.isModelAllowed(fieldDef.type)) {
|
|
5666
|
-
fields[field] = this.makeRelationSelectIncludeSchema(model, field).optional();
|
|
5203
|
+
fields[field] = this.makeRelationSelectIncludeSchema(model, field, options).optional();
|
|
5667
5204
|
}
|
|
5668
5205
|
} else {
|
|
5669
|
-
fields[field] =
|
|
5206
|
+
fields[field] = z.boolean().optional();
|
|
5670
5207
|
}
|
|
5671
5208
|
}
|
|
5672
|
-
|
|
5673
|
-
|
|
5674
|
-
|
|
5209
|
+
if (this.shouldIncludeRelations(options)) {
|
|
5210
|
+
const _countSchema = this.makeCountSelectionSchema(model, options);
|
|
5211
|
+
if (!(_countSchema instanceof z.ZodNever)) {
|
|
5212
|
+
fields["_count"] = _countSchema;
|
|
5213
|
+
}
|
|
5675
5214
|
}
|
|
5676
|
-
return
|
|
5215
|
+
return z.strictObject(fields);
|
|
5677
5216
|
}
|
|
5678
|
-
makeCountSelectionSchema(model) {
|
|
5217
|
+
makeCountSelectionSchema(model, options) {
|
|
5679
5218
|
const modelDef = requireModel(this.schema, model);
|
|
5680
5219
|
const toManyRelations = Object.values(modelDef.fields).filter((def) => def.relation && def.array);
|
|
5681
5220
|
if (toManyRelations.length > 0) {
|
|
5682
|
-
|
|
5683
|
-
|
|
5684
|
-
|
|
5685
|
-
|
|
5221
|
+
const nextOpts = this.nextOptions(options);
|
|
5222
|
+
return z.union([
|
|
5223
|
+
z.literal(true),
|
|
5224
|
+
z.strictObject({
|
|
5225
|
+
select: z.strictObject(toManyRelations.reduce((acc, fieldDef) => ({
|
|
5686
5226
|
...acc,
|
|
5687
|
-
[fieldDef.name]:
|
|
5688
|
-
|
|
5689
|
-
|
|
5690
|
-
where: this.makeWhereSchema(fieldDef.type, false, false)
|
|
5227
|
+
[fieldDef.name]: z.union([
|
|
5228
|
+
z.boolean(),
|
|
5229
|
+
z.strictObject({
|
|
5230
|
+
where: this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts)
|
|
5691
5231
|
})
|
|
5692
5232
|
]).optional()
|
|
5693
5233
|
}), {}))
|
|
5694
5234
|
})
|
|
5695
5235
|
]).optional();
|
|
5696
5236
|
} else {
|
|
5697
|
-
return
|
|
5237
|
+
return z.never();
|
|
5698
5238
|
}
|
|
5699
5239
|
}
|
|
5700
|
-
makeRelationSelectIncludeSchema(model, field) {
|
|
5240
|
+
makeRelationSelectIncludeSchema(model, field, options) {
|
|
5701
5241
|
const fieldDef = requireField(this.schema, model, field);
|
|
5702
|
-
|
|
5242
|
+
const nextOpts = this.nextOptions(options);
|
|
5243
|
+
let objSchema = z.strictObject({
|
|
5703
5244
|
...fieldDef.array || fieldDef.optional ? {
|
|
5704
5245
|
// to-many relations and optional to-one relations are filterable
|
|
5705
|
-
where:
|
|
5246
|
+
where: z.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts)).optional()
|
|
5706
5247
|
} : {},
|
|
5707
|
-
select:
|
|
5708
|
-
include:
|
|
5709
|
-
omit:
|
|
5248
|
+
select: z.lazy(() => this.makeSelectSchema(fieldDef.type, nextOpts)).optional().nullable(),
|
|
5249
|
+
include: z.lazy(() => this.makeIncludeSchema(fieldDef.type, nextOpts)).optional().nullable(),
|
|
5250
|
+
omit: z.lazy(() => this.makeOmitSchema(fieldDef.type)).optional().nullable(),
|
|
5710
5251
|
...fieldDef.array ? {
|
|
5711
5252
|
// to-many relations can be ordered, skipped, taken, and cursor-located
|
|
5712
|
-
orderBy:
|
|
5253
|
+
orderBy: z.lazy(() => this.orArray(this.makeOrderBySchema(fieldDef.type, true, false, nextOpts), true)).optional(),
|
|
5713
5254
|
skip: this.makeSkipSchema().optional(),
|
|
5714
5255
|
take: this.makeTakeSchema().optional(),
|
|
5715
|
-
cursor: this.makeCursorSchema(fieldDef.type).optional(),
|
|
5256
|
+
cursor: this.makeCursorSchema(fieldDef.type, nextOpts).optional(),
|
|
5716
5257
|
distinct: this.makeDistinctSchema(fieldDef.type).optional()
|
|
5717
5258
|
} : {}
|
|
5718
5259
|
});
|
|
5719
5260
|
objSchema = this.refineForSelectIncludeMutuallyExclusive(objSchema);
|
|
5720
5261
|
objSchema = this.refineForSelectOmitMutuallyExclusive(objSchema);
|
|
5721
|
-
|
|
5722
|
-
|
|
5262
|
+
objSchema = this.refineForSelectHasTruthyField(objSchema);
|
|
5263
|
+
return z.union([
|
|
5264
|
+
z.boolean(),
|
|
5723
5265
|
objSchema
|
|
5724
5266
|
]);
|
|
5725
5267
|
}
|
|
@@ -5730,44 +5272,50 @@ var InputValidator = class {
|
|
|
5730
5272
|
const fieldDef = requireField(this.schema, model, field);
|
|
5731
5273
|
if (!fieldDef.relation) {
|
|
5732
5274
|
if (this.options.allowQueryTimeOmitOverride !== false) {
|
|
5733
|
-
fields[field] =
|
|
5275
|
+
fields[field] = z.boolean().optional();
|
|
5734
5276
|
} else {
|
|
5735
|
-
fields[field] =
|
|
5277
|
+
fields[field] = z.literal(true).optional();
|
|
5736
5278
|
}
|
|
5737
5279
|
}
|
|
5738
5280
|
}
|
|
5739
|
-
return
|
|
5281
|
+
return z.strictObject(fields);
|
|
5740
5282
|
}
|
|
5741
|
-
makeIncludeSchema(model) {
|
|
5283
|
+
makeIncludeSchema(model, options) {
|
|
5742
5284
|
const modelDef = requireModel(this.schema, model);
|
|
5743
5285
|
const fields = {};
|
|
5744
5286
|
for (const field of Object.keys(modelDef.fields)) {
|
|
5745
5287
|
const fieldDef = requireField(this.schema, model, field);
|
|
5746
5288
|
if (fieldDef.relation) {
|
|
5289
|
+
if (!this.shouldIncludeRelations(options)) {
|
|
5290
|
+
continue;
|
|
5291
|
+
}
|
|
5747
5292
|
if (this.isModelAllowed(fieldDef.type)) {
|
|
5748
|
-
fields[field] = this.makeRelationSelectIncludeSchema(model, field).optional();
|
|
5293
|
+
fields[field] = this.makeRelationSelectIncludeSchema(model, field, options).optional();
|
|
5749
5294
|
}
|
|
5750
5295
|
}
|
|
5751
5296
|
}
|
|
5752
|
-
|
|
5753
|
-
|
|
5754
|
-
|
|
5297
|
+
if (this.shouldIncludeRelations(options)) {
|
|
5298
|
+
const _countSchema = this.makeCountSelectionSchema(model, options);
|
|
5299
|
+
if (!(_countSchema instanceof z.ZodNever)) {
|
|
5300
|
+
fields["_count"] = _countSchema;
|
|
5301
|
+
}
|
|
5755
5302
|
}
|
|
5756
|
-
return
|
|
5303
|
+
return z.strictObject(fields);
|
|
5757
5304
|
}
|
|
5758
|
-
makeOrderBySchema(model, withRelation, WithAggregation) {
|
|
5305
|
+
makeOrderBySchema(model, withRelation, WithAggregation, options) {
|
|
5759
5306
|
const modelDef = requireModel(this.schema, model);
|
|
5760
5307
|
const fields = {};
|
|
5761
|
-
const sort =
|
|
5762
|
-
|
|
5763
|
-
|
|
5308
|
+
const sort = z.union([
|
|
5309
|
+
z.literal("asc"),
|
|
5310
|
+
z.literal("desc")
|
|
5764
5311
|
]);
|
|
5312
|
+
const nextOpts = this.nextOptions(options);
|
|
5765
5313
|
for (const field of Object.keys(modelDef.fields)) {
|
|
5766
5314
|
const fieldDef = requireField(this.schema, model, field);
|
|
5767
5315
|
if (fieldDef.relation) {
|
|
5768
|
-
if (withRelation) {
|
|
5769
|
-
fields[field] =
|
|
5770
|
-
let relationOrderBy = this.makeOrderBySchema(fieldDef.type, withRelation, WithAggregation);
|
|
5316
|
+
if (withRelation && this.shouldIncludeRelations(options)) {
|
|
5317
|
+
fields[field] = z.lazy(() => {
|
|
5318
|
+
let relationOrderBy = this.makeOrderBySchema(fieldDef.type, withRelation, WithAggregation, nextOpts);
|
|
5771
5319
|
if (fieldDef.array) {
|
|
5772
5320
|
relationOrderBy = relationOrderBy.extend({
|
|
5773
5321
|
_count: sort
|
|
@@ -5778,13 +5326,13 @@ var InputValidator = class {
|
|
|
5778
5326
|
}
|
|
5779
5327
|
} else {
|
|
5780
5328
|
if (fieldDef.optional) {
|
|
5781
|
-
fields[field] =
|
|
5329
|
+
fields[field] = z.union([
|
|
5782
5330
|
sort,
|
|
5783
|
-
|
|
5331
|
+
z.strictObject({
|
|
5784
5332
|
sort,
|
|
5785
|
-
nulls:
|
|
5786
|
-
|
|
5787
|
-
|
|
5333
|
+
nulls: z.union([
|
|
5334
|
+
z.literal("first"),
|
|
5335
|
+
z.literal("last")
|
|
5788
5336
|
])
|
|
5789
5337
|
})
|
|
5790
5338
|
]).optional();
|
|
@@ -5802,64 +5350,64 @@ var InputValidator = class {
|
|
|
5802
5350
|
"_max"
|
|
5803
5351
|
];
|
|
5804
5352
|
for (const agg of aggregationFields) {
|
|
5805
|
-
fields[agg] =
|
|
5353
|
+
fields[agg] = z.lazy(() => this.makeOrderBySchema(model, true, false, options).optional());
|
|
5806
5354
|
}
|
|
5807
5355
|
}
|
|
5808
|
-
return
|
|
5356
|
+
return z.strictObject(fields);
|
|
5809
5357
|
}
|
|
5810
5358
|
makeDistinctSchema(model) {
|
|
5811
5359
|
const modelDef = requireModel(this.schema, model);
|
|
5812
5360
|
const nonRelationFields = Object.keys(modelDef.fields).filter((field) => !modelDef.fields[field]?.relation);
|
|
5813
|
-
return this.orArray(
|
|
5361
|
+
return nonRelationFields.length > 0 ? this.orArray(z.enum(nonRelationFields), true) : z.never();
|
|
5814
5362
|
}
|
|
5815
|
-
makeCursorSchema(model) {
|
|
5816
|
-
return this.makeWhereSchema(model, true, true).optional();
|
|
5363
|
+
makeCursorSchema(model, options) {
|
|
5364
|
+
return this.makeWhereSchema(model, true, true, false, options).optional();
|
|
5817
5365
|
}
|
|
5818
5366
|
// #endregion
|
|
5819
5367
|
// #region Create
|
|
5820
|
-
makeCreateSchema(model) {
|
|
5821
|
-
const dataSchema = this.makeCreateDataSchema(model, false);
|
|
5822
|
-
const baseSchema =
|
|
5368
|
+
makeCreateSchema(model, options) {
|
|
5369
|
+
const dataSchema = this.makeCreateDataSchema(model, false, [], false, options);
|
|
5370
|
+
const baseSchema = z.strictObject({
|
|
5823
5371
|
data: dataSchema,
|
|
5824
|
-
select: this.makeSelectSchema(model).optional().nullable(),
|
|
5825
|
-
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
5372
|
+
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
5373
|
+
include: this.makeIncludeSchema(model, options).optional().nullable(),
|
|
5826
5374
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
5827
5375
|
});
|
|
5828
5376
|
let schema = this.mergePluginArgsSchema(baseSchema, "create");
|
|
5829
5377
|
schema = this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
5830
5378
|
schema = this.refineForSelectOmitMutuallyExclusive(schema);
|
|
5379
|
+
schema = this.refineForSelectHasTruthyField(schema);
|
|
5831
5380
|
return schema;
|
|
5832
5381
|
}
|
|
5833
|
-
makeCreateManySchema(model) {
|
|
5834
|
-
return this.mergePluginArgsSchema(this.
|
|
5382
|
+
makeCreateManySchema(model, options) {
|
|
5383
|
+
return this.mergePluginArgsSchema(this.makeCreateManyPayloadSchema(model, [], options), "createMany");
|
|
5835
5384
|
}
|
|
5836
|
-
makeCreateManyAndReturnSchema(model) {
|
|
5837
|
-
const base = this.
|
|
5385
|
+
makeCreateManyAndReturnSchema(model, options) {
|
|
5386
|
+
const base = this.makeCreateManyPayloadSchema(model, [], options);
|
|
5838
5387
|
let result = base.extend({
|
|
5839
|
-
select: this.makeSelectSchema(model).optional().nullable(),
|
|
5388
|
+
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
5840
5389
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
5841
5390
|
});
|
|
5842
5391
|
result = this.mergePluginArgsSchema(result, "createManyAndReturn");
|
|
5843
|
-
return this.refineForSelectOmitMutuallyExclusive(result).optional();
|
|
5392
|
+
return this.refineForSelectHasTruthyField(this.refineForSelectOmitMutuallyExclusive(result)).optional();
|
|
5844
5393
|
}
|
|
5845
|
-
makeCreateDataSchema(model, canBeArray, withoutFields = [], withoutRelationFields = false) {
|
|
5394
|
+
makeCreateDataSchema(model, canBeArray, withoutFields = [], withoutRelationFields = false, options) {
|
|
5395
|
+
const skipRelations = withoutRelationFields || !this.shouldIncludeRelations(options);
|
|
5846
5396
|
const uncheckedVariantFields = {};
|
|
5847
5397
|
const checkedVariantFields = {};
|
|
5848
5398
|
const modelDef = requireModel(this.schema, model);
|
|
5849
|
-
const hasRelation = !
|
|
5399
|
+
const hasRelation = !skipRelations && Object.entries(modelDef.fields).some(([f, def]) => !withoutFields.includes(f) && def.relation);
|
|
5400
|
+
const nextOpts = this.nextOptions(options);
|
|
5850
5401
|
Object.keys(modelDef.fields).forEach((field) => {
|
|
5851
5402
|
if (withoutFields.includes(field)) {
|
|
5852
5403
|
return;
|
|
5853
5404
|
}
|
|
5854
5405
|
const fieldDef = requireField(this.schema, model, field);
|
|
5855
|
-
if (fieldDef.computed) {
|
|
5856
|
-
return;
|
|
5857
|
-
}
|
|
5858
|
-
if (this.isDelegateDiscriminator(fieldDef)) {
|
|
5406
|
+
if (fieldDef.computed || fieldDef.isDiscriminator) {
|
|
5859
5407
|
return;
|
|
5860
5408
|
}
|
|
5861
5409
|
if (fieldDef.relation) {
|
|
5862
|
-
if (
|
|
5410
|
+
if (skipRelations) {
|
|
5863
5411
|
return;
|
|
5864
5412
|
}
|
|
5865
5413
|
if (!this.isModelAllowed(fieldDef.type)) {
|
|
@@ -5874,7 +5422,7 @@ var InputValidator = class {
|
|
|
5874
5422
|
excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
5875
5423
|
}
|
|
5876
5424
|
}
|
|
5877
|
-
let fieldSchema =
|
|
5425
|
+
let fieldSchema = z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "create", nextOpts));
|
|
5878
5426
|
if (fieldDef.optional || fieldDef.array) {
|
|
5879
5427
|
fieldSchema = fieldSchema.optional();
|
|
5880
5428
|
} else {
|
|
@@ -5899,10 +5447,10 @@ var InputValidator = class {
|
|
|
5899
5447
|
} else {
|
|
5900
5448
|
let fieldSchema = this.makeScalarSchema(fieldDef.type, fieldDef.attributes);
|
|
5901
5449
|
if (fieldDef.array) {
|
|
5902
|
-
fieldSchema = addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
5903
|
-
fieldSchema =
|
|
5450
|
+
fieldSchema = ZodUtils.addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
5451
|
+
fieldSchema = z.union([
|
|
5904
5452
|
fieldSchema,
|
|
5905
|
-
|
|
5453
|
+
z.strictObject({
|
|
5906
5454
|
set: fieldSchema
|
|
5907
5455
|
})
|
|
5908
5456
|
]).optional();
|
|
@@ -5912,9 +5460,9 @@ var InputValidator = class {
|
|
|
5912
5460
|
}
|
|
5913
5461
|
if (fieldDef.optional) {
|
|
5914
5462
|
if (fieldDef.type === "Json") {
|
|
5915
|
-
fieldSchema =
|
|
5463
|
+
fieldSchema = z.union([
|
|
5916
5464
|
fieldSchema,
|
|
5917
|
-
|
|
5465
|
+
z.instanceof(DbNullClass)
|
|
5918
5466
|
]);
|
|
5919
5467
|
} else {
|
|
5920
5468
|
fieldSchema = fieldSchema.nullable();
|
|
@@ -5926,170 +5474,171 @@ var InputValidator = class {
|
|
|
5926
5474
|
}
|
|
5927
5475
|
}
|
|
5928
5476
|
});
|
|
5929
|
-
const uncheckedCreateSchema = this.extraValidationsEnabled ? addCustomValidation(
|
|
5930
|
-
const checkedCreateSchema = this.extraValidationsEnabled ? addCustomValidation(
|
|
5477
|
+
const uncheckedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(uncheckedVariantFields), modelDef.attributes) : z.strictObject(uncheckedVariantFields);
|
|
5478
|
+
const checkedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(checkedVariantFields), modelDef.attributes) : z.strictObject(checkedVariantFields);
|
|
5931
5479
|
if (!hasRelation) {
|
|
5932
5480
|
return this.orArray(uncheckedCreateSchema, canBeArray);
|
|
5933
5481
|
} else {
|
|
5934
|
-
return
|
|
5482
|
+
return z.union([
|
|
5935
5483
|
uncheckedCreateSchema,
|
|
5936
5484
|
checkedCreateSchema,
|
|
5937
5485
|
...canBeArray ? [
|
|
5938
|
-
|
|
5486
|
+
z.array(uncheckedCreateSchema)
|
|
5939
5487
|
] : [],
|
|
5940
5488
|
...canBeArray ? [
|
|
5941
|
-
|
|
5489
|
+
z.array(checkedCreateSchema)
|
|
5942
5490
|
] : []
|
|
5943
5491
|
]);
|
|
5944
5492
|
}
|
|
5945
5493
|
}
|
|
5946
|
-
|
|
5947
|
-
if (!fieldDef.originModel) {
|
|
5948
|
-
return false;
|
|
5949
|
-
}
|
|
5950
|
-
const discriminatorField = getDiscriminatorField(this.schema, fieldDef.originModel);
|
|
5951
|
-
return discriminatorField === fieldDef.name;
|
|
5952
|
-
}
|
|
5953
|
-
makeRelationManipulationSchema(model, field, withoutFields, mode) {
|
|
5494
|
+
makeRelationManipulationSchema(model, field, withoutFields, mode, options) {
|
|
5954
5495
|
const fieldDef = requireField(this.schema, model, field);
|
|
5955
5496
|
const fieldType = fieldDef.type;
|
|
5956
5497
|
const array = !!fieldDef.array;
|
|
5957
5498
|
const fields = {
|
|
5958
|
-
create: this.makeCreateDataSchema(fieldDef.type, !!fieldDef.array, withoutFields).optional(),
|
|
5959
|
-
connect: this.makeConnectDataSchema(fieldType, array).optional(),
|
|
5960
|
-
connectOrCreate: this.makeConnectOrCreateDataSchema(fieldType, array, withoutFields).optional()
|
|
5499
|
+
create: this.makeCreateDataSchema(fieldDef.type, !!fieldDef.array, withoutFields, false, options).optional(),
|
|
5500
|
+
connect: this.makeConnectDataSchema(fieldType, array, options).optional(),
|
|
5501
|
+
connectOrCreate: this.makeConnectOrCreateDataSchema(fieldType, array, withoutFields, options).optional()
|
|
5961
5502
|
};
|
|
5962
5503
|
if (array) {
|
|
5963
|
-
fields["createMany"] = this.
|
|
5504
|
+
fields["createMany"] = this.makeCreateManyPayloadSchema(fieldType, withoutFields, options).optional();
|
|
5964
5505
|
}
|
|
5965
5506
|
if (mode === "update") {
|
|
5966
5507
|
if (fieldDef.optional || fieldDef.array) {
|
|
5967
|
-
fields["disconnect"] = this.makeDisconnectDataSchema(fieldType, array).optional();
|
|
5968
|
-
fields["delete"] = this.makeDeleteRelationDataSchema(fieldType, array, true).optional();
|
|
5969
|
-
}
|
|
5970
|
-
fields["update"] = array ? this.orArray(
|
|
5971
|
-
where: this.makeWhereSchema(fieldType, true),
|
|
5972
|
-
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
5973
|
-
}), true).optional() :
|
|
5974
|
-
|
|
5975
|
-
where: this.makeWhereSchema(fieldType, false).optional(),
|
|
5976
|
-
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
5508
|
+
fields["disconnect"] = this.makeDisconnectDataSchema(fieldType, array, options).optional();
|
|
5509
|
+
fields["delete"] = this.makeDeleteRelationDataSchema(fieldType, array, true, options).optional();
|
|
5510
|
+
}
|
|
5511
|
+
fields["update"] = array ? this.orArray(z.strictObject({
|
|
5512
|
+
where: this.makeWhereSchema(fieldType, true, false, false, options),
|
|
5513
|
+
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
5514
|
+
}), true).optional() : z.union([
|
|
5515
|
+
z.strictObject({
|
|
5516
|
+
where: this.makeWhereSchema(fieldType, false, false, false, options).optional(),
|
|
5517
|
+
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
5977
5518
|
}),
|
|
5978
|
-
this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
5519
|
+
this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
5979
5520
|
]).optional();
|
|
5980
|
-
let upsertWhere = this.makeWhereSchema(fieldType, true);
|
|
5521
|
+
let upsertWhere = this.makeWhereSchema(fieldType, true, false, false, options);
|
|
5981
5522
|
if (!fieldDef.array) {
|
|
5982
5523
|
upsertWhere = upsertWhere.optional();
|
|
5983
5524
|
}
|
|
5984
|
-
fields["upsert"] = this.orArray(
|
|
5525
|
+
fields["upsert"] = this.orArray(z.strictObject({
|
|
5985
5526
|
where: upsertWhere,
|
|
5986
|
-
create: this.makeCreateDataSchema(fieldType, false, withoutFields),
|
|
5987
|
-
update: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
5527
|
+
create: this.makeCreateDataSchema(fieldType, false, withoutFields, false, options),
|
|
5528
|
+
update: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
5988
5529
|
}), true).optional();
|
|
5989
5530
|
if (array) {
|
|
5990
|
-
fields["set"] = this.makeSetDataSchema(fieldType, true).optional();
|
|
5991
|
-
fields["updateMany"] = this.orArray(
|
|
5992
|
-
where: this.makeWhereSchema(fieldType, false, true),
|
|
5993
|
-
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
5531
|
+
fields["set"] = this.makeSetDataSchema(fieldType, true, options).optional();
|
|
5532
|
+
fields["updateMany"] = this.orArray(z.strictObject({
|
|
5533
|
+
where: this.makeWhereSchema(fieldType, false, true, false, options),
|
|
5534
|
+
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
5994
5535
|
}), true).optional();
|
|
5995
|
-
fields["deleteMany"] = this.makeDeleteRelationDataSchema(fieldType, true, false).optional();
|
|
5536
|
+
fields["deleteMany"] = this.makeDeleteRelationDataSchema(fieldType, true, false, options).optional();
|
|
5996
5537
|
}
|
|
5997
5538
|
}
|
|
5998
|
-
return
|
|
5539
|
+
return z.strictObject(fields);
|
|
5999
5540
|
}
|
|
6000
|
-
makeSetDataSchema(model, canBeArray) {
|
|
6001
|
-
return this.orArray(this.makeWhereSchema(model, true), canBeArray);
|
|
5541
|
+
makeSetDataSchema(model, canBeArray, options) {
|
|
5542
|
+
return this.orArray(this.makeWhereSchema(model, true, false, false, options), canBeArray);
|
|
6002
5543
|
}
|
|
6003
|
-
makeConnectDataSchema(model, canBeArray) {
|
|
6004
|
-
return this.orArray(this.makeWhereSchema(model, true), canBeArray);
|
|
5544
|
+
makeConnectDataSchema(model, canBeArray, options) {
|
|
5545
|
+
return this.orArray(this.makeWhereSchema(model, true, false, false, options), canBeArray);
|
|
6005
5546
|
}
|
|
6006
|
-
makeDisconnectDataSchema(model, canBeArray) {
|
|
5547
|
+
makeDisconnectDataSchema(model, canBeArray, options) {
|
|
6007
5548
|
if (canBeArray) {
|
|
6008
|
-
return this.orArray(this.makeWhereSchema(model, true), canBeArray);
|
|
5549
|
+
return this.orArray(this.makeWhereSchema(model, true, false, false, options), canBeArray);
|
|
6009
5550
|
} else {
|
|
6010
|
-
return
|
|
6011
|
-
|
|
6012
|
-
this.makeWhereSchema(model, false)
|
|
5551
|
+
return z.union([
|
|
5552
|
+
z.boolean(),
|
|
5553
|
+
this.makeWhereSchema(model, false, false, false, options)
|
|
6013
5554
|
]);
|
|
6014
5555
|
}
|
|
6015
5556
|
}
|
|
6016
|
-
makeDeleteRelationDataSchema(model, toManyRelation, uniqueFilter) {
|
|
6017
|
-
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter), true) :
|
|
6018
|
-
|
|
6019
|
-
this.makeWhereSchema(model, uniqueFilter)
|
|
5557
|
+
makeDeleteRelationDataSchema(model, toManyRelation, uniqueFilter, options) {
|
|
5558
|
+
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter, false, false, options), true) : z.union([
|
|
5559
|
+
z.boolean(),
|
|
5560
|
+
this.makeWhereSchema(model, uniqueFilter, false, false, options)
|
|
6020
5561
|
]);
|
|
6021
5562
|
}
|
|
6022
|
-
makeConnectOrCreateDataSchema(model, canBeArray, withoutFields) {
|
|
6023
|
-
const whereSchema = this.makeWhereSchema(model, true);
|
|
6024
|
-
const createSchema = this.makeCreateDataSchema(model, false, withoutFields);
|
|
6025
|
-
return this.orArray(
|
|
5563
|
+
makeConnectOrCreateDataSchema(model, canBeArray, withoutFields, options) {
|
|
5564
|
+
const whereSchema = this.makeWhereSchema(model, true, false, false, options);
|
|
5565
|
+
const createSchema = this.makeCreateDataSchema(model, false, withoutFields, false, options);
|
|
5566
|
+
return this.orArray(z.strictObject({
|
|
6026
5567
|
where: whereSchema,
|
|
6027
5568
|
create: createSchema
|
|
6028
5569
|
}), canBeArray);
|
|
6029
5570
|
}
|
|
6030
|
-
|
|
6031
|
-
return
|
|
6032
|
-
data: this.makeCreateDataSchema(model, true, withoutFields, true),
|
|
6033
|
-
skipDuplicates:
|
|
5571
|
+
makeCreateManyPayloadSchema(model, withoutFields, options) {
|
|
5572
|
+
return z.strictObject({
|
|
5573
|
+
data: this.makeCreateDataSchema(model, true, withoutFields, true, options),
|
|
5574
|
+
skipDuplicates: z.boolean().optional()
|
|
6034
5575
|
});
|
|
6035
5576
|
}
|
|
6036
5577
|
// #endregion
|
|
6037
5578
|
// #region Update
|
|
6038
|
-
makeUpdateSchema(model) {
|
|
6039
|
-
const baseSchema =
|
|
6040
|
-
where: this.makeWhereSchema(model, true),
|
|
6041
|
-
data: this.makeUpdateDataSchema(model),
|
|
6042
|
-
select: this.makeSelectSchema(model).optional().nullable(),
|
|
6043
|
-
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
5579
|
+
makeUpdateSchema(model, options) {
|
|
5580
|
+
const baseSchema = z.strictObject({
|
|
5581
|
+
where: this.makeWhereSchema(model, true, false, false, options),
|
|
5582
|
+
data: this.makeUpdateDataSchema(model, [], false, options),
|
|
5583
|
+
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
5584
|
+
include: this.makeIncludeSchema(model, options).optional().nullable(),
|
|
6044
5585
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
6045
5586
|
});
|
|
6046
5587
|
let schema = this.mergePluginArgsSchema(baseSchema, "update");
|
|
6047
5588
|
schema = this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
6048
5589
|
schema = this.refineForSelectOmitMutuallyExclusive(schema);
|
|
5590
|
+
schema = this.refineForSelectHasTruthyField(schema);
|
|
6049
5591
|
return schema;
|
|
6050
5592
|
}
|
|
6051
|
-
makeUpdateManySchema(model) {
|
|
6052
|
-
return this.mergePluginArgsSchema(
|
|
6053
|
-
where: this.makeWhereSchema(model, false).optional(),
|
|
6054
|
-
data: this.makeUpdateDataSchema(model, [], true),
|
|
6055
|
-
limit:
|
|
5593
|
+
makeUpdateManySchema(model, options) {
|
|
5594
|
+
return this.mergePluginArgsSchema(z.strictObject({
|
|
5595
|
+
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
5596
|
+
data: this.makeUpdateDataSchema(model, [], true, options),
|
|
5597
|
+
limit: z.number().int().nonnegative().optional()
|
|
6056
5598
|
}), "updateMany");
|
|
6057
5599
|
}
|
|
6058
|
-
makeUpdateManyAndReturnSchema(model) {
|
|
6059
|
-
const baseSchema = this.makeUpdateManySchema(model);
|
|
5600
|
+
makeUpdateManyAndReturnSchema(model, options) {
|
|
5601
|
+
const baseSchema = this.makeUpdateManySchema(model, options);
|
|
6060
5602
|
let schema = baseSchema.extend({
|
|
6061
|
-
select: this.makeSelectSchema(model).optional().nullable(),
|
|
5603
|
+
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
6062
5604
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
6063
5605
|
});
|
|
6064
5606
|
schema = this.refineForSelectOmitMutuallyExclusive(schema);
|
|
5607
|
+
schema = this.refineForSelectHasTruthyField(schema);
|
|
6065
5608
|
return schema;
|
|
6066
5609
|
}
|
|
6067
|
-
makeUpsertSchema(model) {
|
|
6068
|
-
const baseSchema =
|
|
6069
|
-
where: this.makeWhereSchema(model, true),
|
|
6070
|
-
create: this.makeCreateDataSchema(model, false),
|
|
6071
|
-
update: this.makeUpdateDataSchema(model),
|
|
6072
|
-
select: this.makeSelectSchema(model).optional().nullable(),
|
|
6073
|
-
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
5610
|
+
makeUpsertSchema(model, options) {
|
|
5611
|
+
const baseSchema = z.strictObject({
|
|
5612
|
+
where: this.makeWhereSchema(model, true, false, false, options),
|
|
5613
|
+
create: this.makeCreateDataSchema(model, false, [], false, options),
|
|
5614
|
+
update: this.makeUpdateDataSchema(model, [], false, options),
|
|
5615
|
+
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
5616
|
+
include: this.makeIncludeSchema(model, options).optional().nullable(),
|
|
6074
5617
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
6075
5618
|
});
|
|
6076
5619
|
let schema = this.mergePluginArgsSchema(baseSchema, "upsert");
|
|
6077
5620
|
schema = this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
6078
5621
|
schema = this.refineForSelectOmitMutuallyExclusive(schema);
|
|
5622
|
+
schema = this.refineForSelectHasTruthyField(schema);
|
|
6079
5623
|
return schema;
|
|
6080
5624
|
}
|
|
6081
|
-
makeUpdateDataSchema(model, withoutFields = [], withoutRelationFields = false) {
|
|
5625
|
+
makeUpdateDataSchema(model, withoutFields = [], withoutRelationFields = false, options) {
|
|
5626
|
+
const skipRelations = withoutRelationFields || !this.shouldIncludeRelations(options);
|
|
6082
5627
|
const uncheckedVariantFields = {};
|
|
6083
5628
|
const checkedVariantFields = {};
|
|
6084
5629
|
const modelDef = requireModel(this.schema, model);
|
|
6085
|
-
const hasRelation = Object.entries(modelDef.fields).some(([key, value]) => value.relation && !withoutFields.includes(key));
|
|
5630
|
+
const hasRelation = !skipRelations && Object.entries(modelDef.fields).some(([key, value]) => value.relation && !withoutFields.includes(key));
|
|
5631
|
+
const nextOpts = this.nextOptions(options);
|
|
6086
5632
|
Object.keys(modelDef.fields).forEach((field) => {
|
|
6087
5633
|
if (withoutFields.includes(field)) {
|
|
6088
5634
|
return;
|
|
6089
5635
|
}
|
|
6090
5636
|
const fieldDef = requireField(this.schema, model, field);
|
|
5637
|
+
if (fieldDef.computed || fieldDef.isDiscriminator) {
|
|
5638
|
+
return;
|
|
5639
|
+
}
|
|
6091
5640
|
if (fieldDef.relation) {
|
|
6092
|
-
if (
|
|
5641
|
+
if (skipRelations) {
|
|
6093
5642
|
return;
|
|
6094
5643
|
}
|
|
6095
5644
|
if (!this.isModelAllowed(fieldDef.type)) {
|
|
@@ -6104,7 +5653,7 @@ var InputValidator = class {
|
|
|
6104
5653
|
excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
6105
5654
|
}
|
|
6106
5655
|
}
|
|
6107
|
-
let fieldSchema =
|
|
5656
|
+
let fieldSchema = z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "update", nextOpts)).optional();
|
|
6108
5657
|
if (fieldDef.optional && !fieldDef.array) {
|
|
6109
5658
|
fieldSchema = fieldSchema.nullable();
|
|
6110
5659
|
}
|
|
@@ -6115,24 +5664,25 @@ var InputValidator = class {
|
|
|
6115
5664
|
} else {
|
|
6116
5665
|
let fieldSchema = this.makeScalarSchema(fieldDef.type, fieldDef.attributes);
|
|
6117
5666
|
if (this.isNumericField(fieldDef)) {
|
|
6118
|
-
fieldSchema =
|
|
5667
|
+
fieldSchema = z.union([
|
|
6119
5668
|
fieldSchema,
|
|
6120
|
-
|
|
6121
|
-
|
|
6122
|
-
|
|
6123
|
-
|
|
6124
|
-
|
|
6125
|
-
|
|
5669
|
+
z.object({
|
|
5670
|
+
// TODO: use Decimal/BigInt for incremental updates
|
|
5671
|
+
set: this.nullableIf(z.number().optional(), !!fieldDef.optional).optional(),
|
|
5672
|
+
increment: z.number().optional(),
|
|
5673
|
+
decrement: z.number().optional(),
|
|
5674
|
+
multiply: z.number().optional(),
|
|
5675
|
+
divide: z.number().optional()
|
|
6126
5676
|
}).refine((v) => Object.keys(v).length === 1, 'Only one of "set", "increment", "decrement", "multiply", or "divide" can be provided')
|
|
6127
5677
|
]);
|
|
6128
5678
|
}
|
|
6129
5679
|
if (fieldDef.array) {
|
|
6130
|
-
const arraySchema = addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
6131
|
-
fieldSchema =
|
|
5680
|
+
const arraySchema = ZodUtils.addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
5681
|
+
fieldSchema = z.union([
|
|
6132
5682
|
arraySchema,
|
|
6133
|
-
|
|
5683
|
+
z.object({
|
|
6134
5684
|
set: arraySchema.optional(),
|
|
6135
|
-
push:
|
|
5685
|
+
push: z.union([
|
|
6136
5686
|
fieldSchema,
|
|
6137
5687
|
fieldSchema.array()
|
|
6138
5688
|
]).optional()
|
|
@@ -6141,9 +5691,9 @@ var InputValidator = class {
|
|
|
6141
5691
|
}
|
|
6142
5692
|
if (fieldDef.optional) {
|
|
6143
5693
|
if (fieldDef.type === "Json") {
|
|
6144
|
-
fieldSchema =
|
|
5694
|
+
fieldSchema = z.union([
|
|
6145
5695
|
fieldSchema,
|
|
6146
|
-
|
|
5696
|
+
z.instanceof(DbNullClass)
|
|
6147
5697
|
]);
|
|
6148
5698
|
} else {
|
|
6149
5699
|
fieldSchema = fieldSchema.nullable();
|
|
@@ -6156,12 +5706,12 @@ var InputValidator = class {
|
|
|
6156
5706
|
}
|
|
6157
5707
|
}
|
|
6158
5708
|
});
|
|
6159
|
-
const uncheckedUpdateSchema = this.extraValidationsEnabled ? addCustomValidation(
|
|
6160
|
-
const checkedUpdateSchema = this.extraValidationsEnabled ? addCustomValidation(
|
|
5709
|
+
const uncheckedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(uncheckedVariantFields), modelDef.attributes) : z.strictObject(uncheckedVariantFields);
|
|
5710
|
+
const checkedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(checkedVariantFields), modelDef.attributes) : z.strictObject(checkedVariantFields);
|
|
6161
5711
|
if (!hasRelation) {
|
|
6162
5712
|
return uncheckedUpdateSchema;
|
|
6163
5713
|
} else {
|
|
6164
|
-
return
|
|
5714
|
+
return z.union([
|
|
6165
5715
|
uncheckedUpdateSchema,
|
|
6166
5716
|
checkedUpdateSchema
|
|
6167
5717
|
]);
|
|
@@ -6169,43 +5719,44 @@ var InputValidator = class {
|
|
|
6169
5719
|
}
|
|
6170
5720
|
// #endregion
|
|
6171
5721
|
// #region Delete
|
|
6172
|
-
makeDeleteSchema(model) {
|
|
6173
|
-
const baseSchema =
|
|
6174
|
-
where: this.makeWhereSchema(model, true),
|
|
6175
|
-
select: this.makeSelectSchema(model).optional().nullable(),
|
|
6176
|
-
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
5722
|
+
makeDeleteSchema(model, options) {
|
|
5723
|
+
const baseSchema = z.strictObject({
|
|
5724
|
+
where: this.makeWhereSchema(model, true, false, false, options),
|
|
5725
|
+
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
5726
|
+
include: this.makeIncludeSchema(model, options).optional().nullable(),
|
|
6177
5727
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
6178
5728
|
});
|
|
6179
5729
|
let schema = this.mergePluginArgsSchema(baseSchema, "delete");
|
|
6180
5730
|
schema = this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
6181
5731
|
schema = this.refineForSelectOmitMutuallyExclusive(schema);
|
|
5732
|
+
schema = this.refineForSelectHasTruthyField(schema);
|
|
6182
5733
|
return schema;
|
|
6183
5734
|
}
|
|
6184
|
-
makeDeleteManySchema(model) {
|
|
6185
|
-
return this.mergePluginArgsSchema(
|
|
6186
|
-
where: this.makeWhereSchema(model, false).optional(),
|
|
6187
|
-
limit:
|
|
5735
|
+
makeDeleteManySchema(model, options) {
|
|
5736
|
+
return this.mergePluginArgsSchema(z.strictObject({
|
|
5737
|
+
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
5738
|
+
limit: z.number().int().nonnegative().optional()
|
|
6188
5739
|
}), "deleteMany").optional();
|
|
6189
5740
|
}
|
|
6190
5741
|
// #endregion
|
|
6191
5742
|
// #region Count
|
|
6192
|
-
makeCountSchema(model) {
|
|
6193
|
-
return this.mergePluginArgsSchema(
|
|
6194
|
-
where: this.makeWhereSchema(model, false).optional(),
|
|
5743
|
+
makeCountSchema(model, options) {
|
|
5744
|
+
return this.mergePluginArgsSchema(z.strictObject({
|
|
5745
|
+
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
6195
5746
|
skip: this.makeSkipSchema().optional(),
|
|
6196
5747
|
take: this.makeTakeSchema().optional(),
|
|
6197
|
-
orderBy: this.orArray(this.makeOrderBySchema(model, true, false), true).optional(),
|
|
5748
|
+
orderBy: this.orArray(this.makeOrderBySchema(model, true, false, options), true).optional(),
|
|
6198
5749
|
select: this.makeCountAggregateInputSchema(model).optional()
|
|
6199
5750
|
}), "count").optional();
|
|
6200
5751
|
}
|
|
6201
5752
|
makeCountAggregateInputSchema(model) {
|
|
6202
5753
|
const modelDef = requireModel(this.schema, model);
|
|
6203
|
-
return
|
|
6204
|
-
|
|
6205
|
-
|
|
6206
|
-
_all:
|
|
5754
|
+
return z.union([
|
|
5755
|
+
z.literal(true),
|
|
5756
|
+
z.strictObject({
|
|
5757
|
+
_all: z.literal(true).optional(),
|
|
6207
5758
|
...Object.keys(modelDef.fields).reduce((acc, field) => {
|
|
6208
|
-
acc[field] =
|
|
5759
|
+
acc[field] = z.literal(true).optional();
|
|
6209
5760
|
return acc;
|
|
6210
5761
|
}, {})
|
|
6211
5762
|
})
|
|
@@ -6213,12 +5764,12 @@ var InputValidator = class {
|
|
|
6213
5764
|
}
|
|
6214
5765
|
// #endregion
|
|
6215
5766
|
// #region Aggregate
|
|
6216
|
-
makeAggregateSchema(model) {
|
|
6217
|
-
return this.mergePluginArgsSchema(
|
|
6218
|
-
where: this.makeWhereSchema(model, false).optional(),
|
|
5767
|
+
makeAggregateSchema(model, options) {
|
|
5768
|
+
return this.mergePluginArgsSchema(z.strictObject({
|
|
5769
|
+
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
6219
5770
|
skip: this.makeSkipSchema().optional(),
|
|
6220
5771
|
take: this.makeTakeSchema().optional(),
|
|
6221
|
-
orderBy: this.orArray(this.makeOrderBySchema(model, true, false), true).optional(),
|
|
5772
|
+
orderBy: this.orArray(this.makeOrderBySchema(model, true, false, options), true).optional(),
|
|
6222
5773
|
_count: this.makeCountAggregateInputSchema(model).optional(),
|
|
6223
5774
|
_avg: this.makeSumAvgInputSchema(model).optional(),
|
|
6224
5775
|
_sum: this.makeSumAvgInputSchema(model).optional(),
|
|
@@ -6228,33 +5779,35 @@ var InputValidator = class {
|
|
|
6228
5779
|
}
|
|
6229
5780
|
makeSumAvgInputSchema(model) {
|
|
6230
5781
|
const modelDef = requireModel(this.schema, model);
|
|
6231
|
-
return
|
|
5782
|
+
return z.strictObject(Object.keys(modelDef.fields).reduce((acc, field) => {
|
|
6232
5783
|
const fieldDef = requireField(this.schema, model, field);
|
|
6233
5784
|
if (this.isNumericField(fieldDef)) {
|
|
6234
|
-
acc[field] =
|
|
5785
|
+
acc[field] = z.literal(true).optional();
|
|
6235
5786
|
}
|
|
6236
5787
|
return acc;
|
|
6237
5788
|
}, {}));
|
|
6238
5789
|
}
|
|
6239
5790
|
makeMinMaxInputSchema(model) {
|
|
6240
5791
|
const modelDef = requireModel(this.schema, model);
|
|
6241
|
-
return
|
|
5792
|
+
return z.strictObject(Object.keys(modelDef.fields).reduce((acc, field) => {
|
|
6242
5793
|
const fieldDef = requireField(this.schema, model, field);
|
|
6243
5794
|
if (!fieldDef.relation && !fieldDef.array) {
|
|
6244
|
-
acc[field] =
|
|
5795
|
+
acc[field] = z.literal(true).optional();
|
|
6245
5796
|
}
|
|
6246
5797
|
return acc;
|
|
6247
5798
|
}, {}));
|
|
6248
5799
|
}
|
|
6249
|
-
|
|
5800
|
+
// #endregion
|
|
5801
|
+
// #region Group By
|
|
5802
|
+
makeGroupBySchema(model, options) {
|
|
6250
5803
|
const modelDef = requireModel(this.schema, model);
|
|
6251
5804
|
const nonRelationFields = Object.keys(modelDef.fields).filter((field) => !modelDef.fields[field]?.relation);
|
|
6252
|
-
const bySchema = nonRelationFields.length > 0 ? this.orArray(
|
|
6253
|
-
const baseSchema =
|
|
6254
|
-
where: this.makeWhereSchema(model, false).optional(),
|
|
6255
|
-
orderBy: this.orArray(this.makeOrderBySchema(model, false, true), true).optional(),
|
|
5805
|
+
const bySchema = nonRelationFields.length > 0 ? this.orArray(z.enum(nonRelationFields), true) : z.never();
|
|
5806
|
+
const baseSchema = z.strictObject({
|
|
5807
|
+
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
5808
|
+
orderBy: this.orArray(this.makeOrderBySchema(model, false, true, options), true).optional(),
|
|
6256
5809
|
by: bySchema,
|
|
6257
|
-
having: this.makeHavingSchema(model).optional(),
|
|
5810
|
+
having: this.makeHavingSchema(model, options).optional(),
|
|
6258
5811
|
skip: this.makeSkipSchema().optional(),
|
|
6259
5812
|
take: this.makeTakeSchema().optional(),
|
|
6260
5813
|
_count: this.makeCountAggregateInputSchema(model).optional(),
|
|
@@ -6265,9 +5818,7 @@ var InputValidator = class {
|
|
|
6265
5818
|
});
|
|
6266
5819
|
let schema = this.mergePluginArgsSchema(baseSchema, "groupBy");
|
|
6267
5820
|
schema = schema.refine((value) => {
|
|
6268
|
-
const bys =
|
|
6269
|
-
value.by
|
|
6270
|
-
] : value.by;
|
|
5821
|
+
const bys = enumerate3(value.by);
|
|
6271
5822
|
if (value.having && typeof value.having === "object") {
|
|
6272
5823
|
for (const [key, val] of Object.entries(value.having)) {
|
|
6273
5824
|
if (AggregateOperators.includes(key)) {
|
|
@@ -6287,14 +5838,13 @@ var InputValidator = class {
|
|
|
6287
5838
|
return true;
|
|
6288
5839
|
}, 'fields in "having" must be in "by"');
|
|
6289
5840
|
schema = schema.refine((value) => {
|
|
6290
|
-
const bys =
|
|
6291
|
-
|
|
6292
|
-
|
|
6293
|
-
|
|
6294
|
-
|
|
6295
|
-
} else {
|
|
6296
|
-
return true;
|
|
5841
|
+
const bys = enumerate3(value.by);
|
|
5842
|
+
for (const orderBy of enumerate3(value.orderBy)) {
|
|
5843
|
+
if (orderBy && Object.keys(orderBy).filter((f) => !AggregateOperators.includes(f)).some((key) => !bys.includes(key))) {
|
|
5844
|
+
return false;
|
|
5845
|
+
}
|
|
6297
5846
|
}
|
|
5847
|
+
return true;
|
|
6298
5848
|
}, 'fields in "orderBy" must be in "by"');
|
|
6299
5849
|
return schema;
|
|
6300
5850
|
}
|
|
@@ -6312,22 +5862,22 @@ var InputValidator = class {
|
|
|
6312
5862
|
}
|
|
6313
5863
|
return true;
|
|
6314
5864
|
}
|
|
6315
|
-
makeHavingSchema(model) {
|
|
6316
|
-
return this.makeWhereSchema(model, false, true, true);
|
|
5865
|
+
makeHavingSchema(model, options) {
|
|
5866
|
+
return this.makeWhereSchema(model, false, true, true, options);
|
|
6317
5867
|
}
|
|
6318
5868
|
// #endregion
|
|
6319
5869
|
// #region Procedures
|
|
6320
|
-
makeProcedureParamSchema(param) {
|
|
5870
|
+
makeProcedureParamSchema(param, _options) {
|
|
6321
5871
|
let schema;
|
|
6322
5872
|
if (isTypeDef(this.schema, param.type)) {
|
|
6323
5873
|
schema = this.makeTypeDefSchema(param.type);
|
|
6324
5874
|
} else if (isEnum(this.schema, param.type)) {
|
|
6325
5875
|
schema = this.makeEnumSchema(param.type);
|
|
6326
5876
|
} else if (param.type in (this.schema.models ?? {})) {
|
|
6327
|
-
schema =
|
|
5877
|
+
schema = z.record(z.string(), z.unknown());
|
|
6328
5878
|
} else {
|
|
6329
5879
|
schema = this.makeScalarSchema(param.type);
|
|
6330
|
-
if (schema instanceof
|
|
5880
|
+
if (schema instanceof z.ZodUnknown) {
|
|
6331
5881
|
throw createInternalError(`Unsupported procedure parameter type: ${param.type}`);
|
|
6332
5882
|
}
|
|
6333
5883
|
}
|
|
@@ -6340,29 +5890,62 @@ var InputValidator = class {
|
|
|
6340
5890
|
return schema;
|
|
6341
5891
|
}
|
|
6342
5892
|
// #endregion
|
|
6343
|
-
// #region
|
|
6344
|
-
|
|
6345
|
-
|
|
6346
|
-
|
|
6347
|
-
|
|
6348
|
-
|
|
5893
|
+
// #region Plugin Args
|
|
5894
|
+
mergePluginArgsSchema(schema, operation) {
|
|
5895
|
+
let result = schema;
|
|
5896
|
+
for (const plugin of this.plugins ?? []) {
|
|
5897
|
+
if (plugin.queryArgs) {
|
|
5898
|
+
const pluginSchema = this.getPluginExtQueryArgsSchema(plugin, operation);
|
|
5899
|
+
if (pluginSchema) {
|
|
5900
|
+
result = result.extend(pluginSchema.shape);
|
|
5901
|
+
}
|
|
5902
|
+
}
|
|
5903
|
+
}
|
|
5904
|
+
return result.strict();
|
|
6349
5905
|
}
|
|
6350
|
-
|
|
6351
|
-
|
|
6352
|
-
|
|
6353
|
-
|
|
6354
|
-
|
|
6355
|
-
|
|
5906
|
+
getPluginExtQueryArgsSchema(plugin, operation) {
|
|
5907
|
+
if (!plugin.queryArgs) {
|
|
5908
|
+
return void 0;
|
|
5909
|
+
}
|
|
5910
|
+
let result;
|
|
5911
|
+
if (operation in plugin.queryArgs && plugin.queryArgs[operation]) {
|
|
5912
|
+
result = plugin.queryArgs[operation];
|
|
5913
|
+
} else if (operation === "upsert") {
|
|
5914
|
+
const createSchema = "$create" in plugin.queryArgs && plugin.queryArgs["$create"] ? plugin.queryArgs["$create"] : void 0;
|
|
5915
|
+
const updateSchema = "$update" in plugin.queryArgs && plugin.queryArgs["$update"] ? plugin.queryArgs["$update"] : void 0;
|
|
5916
|
+
if (createSchema && updateSchema) {
|
|
5917
|
+
invariant8(createSchema instanceof ZodObject, "Plugin extended query args schema must be a Zod object");
|
|
5918
|
+
invariant8(updateSchema instanceof ZodObject, "Plugin extended query args schema must be a Zod object");
|
|
5919
|
+
result = createSchema.extend(updateSchema.shape);
|
|
5920
|
+
} else if (createSchema) {
|
|
5921
|
+
result = createSchema;
|
|
5922
|
+
} else if (updateSchema) {
|
|
5923
|
+
result = updateSchema;
|
|
6356
5924
|
}
|
|
5925
|
+
} else if (
|
|
5926
|
+
// then comes grouped operations: $create, $read, $update, $delete
|
|
5927
|
+
CoreCreateOperations.includes(operation) && "$create" in plugin.queryArgs && plugin.queryArgs["$create"]
|
|
5928
|
+
) {
|
|
5929
|
+
result = plugin.queryArgs["$create"];
|
|
5930
|
+
} else if (CoreReadOperations.includes(operation) && "$read" in plugin.queryArgs && plugin.queryArgs["$read"]) {
|
|
5931
|
+
result = plugin.queryArgs["$read"];
|
|
5932
|
+
} else if (CoreUpdateOperations.includes(operation) && "$update" in plugin.queryArgs && plugin.queryArgs["$update"]) {
|
|
5933
|
+
result = plugin.queryArgs["$update"];
|
|
5934
|
+
} else if (CoreDeleteOperations.includes(operation) && "$delete" in plugin.queryArgs && plugin.queryArgs["$delete"]) {
|
|
5935
|
+
result = plugin.queryArgs["$delete"];
|
|
5936
|
+
} else if ("$all" in plugin.queryArgs && plugin.queryArgs["$all"]) {
|
|
5937
|
+
result = plugin.queryArgs["$all"];
|
|
6357
5938
|
}
|
|
5939
|
+
invariant8(result === void 0 || result instanceof ZodObject, "Plugin extended query args schema must be a Zod object");
|
|
5940
|
+
return result;
|
|
6358
5941
|
}
|
|
6359
5942
|
// #endregion
|
|
6360
5943
|
// #region Helpers
|
|
6361
5944
|
makeSkipSchema() {
|
|
6362
|
-
return
|
|
5945
|
+
return z.number().int().nonnegative();
|
|
6363
5946
|
}
|
|
6364
5947
|
makeTakeSchema() {
|
|
6365
|
-
return
|
|
5948
|
+
return z.number().int();
|
|
6366
5949
|
}
|
|
6367
5950
|
refineForSelectIncludeMutuallyExclusive(schema) {
|
|
6368
5951
|
return schema.refine((value) => !(value["select"] && value["include"]), '"select" and "include" cannot be used together');
|
|
@@ -6370,13 +5953,22 @@ var InputValidator = class {
|
|
|
6370
5953
|
refineForSelectOmitMutuallyExclusive(schema) {
|
|
6371
5954
|
return schema.refine((value) => !(value["select"] && value["omit"]), '"select" and "omit" cannot be used together');
|
|
6372
5955
|
}
|
|
5956
|
+
refineForSelectHasTruthyField(schema) {
|
|
5957
|
+
return schema.refine((value) => {
|
|
5958
|
+
const select = value["select"];
|
|
5959
|
+
if (!select || typeof select !== "object") {
|
|
5960
|
+
return true;
|
|
5961
|
+
}
|
|
5962
|
+
return Object.values(select).some((v) => v);
|
|
5963
|
+
}, '"select" must have at least one truthy value');
|
|
5964
|
+
}
|
|
6373
5965
|
nullableIf(schema, nullable) {
|
|
6374
5966
|
return nullable ? schema.nullable() : schema;
|
|
6375
5967
|
}
|
|
6376
5968
|
orArray(schema, canBeArray) {
|
|
6377
|
-
return canBeArray ?
|
|
5969
|
+
return canBeArray ? z.union([
|
|
6378
5970
|
schema,
|
|
6379
|
-
|
|
5971
|
+
z.array(schema)
|
|
6380
5972
|
]) : schema;
|
|
6381
5973
|
}
|
|
6382
5974
|
isNumericField(fieldDef) {
|
|
@@ -6387,7 +5979,7 @@ var InputValidator = class {
|
|
|
6387
5979
|
}
|
|
6388
5980
|
/**
|
|
6389
5981
|
* Gets the effective set of allowed FilterKind values for a specific model and field.
|
|
6390
|
-
* Respects the precedence: field
|
|
5982
|
+
* Respects the precedence: model[field] > model.$all > $all[field] > $all.$all.
|
|
6391
5983
|
*/
|
|
6392
5984
|
getEffectiveFilterKinds(model, field) {
|
|
6393
5985
|
if (!model) {
|
|
@@ -6397,21 +5989,27 @@ var InputValidator = class {
|
|
|
6397
5989
|
if (!slicing?.models) {
|
|
6398
5990
|
return void 0;
|
|
6399
5991
|
}
|
|
6400
|
-
const
|
|
5992
|
+
const modelsRecord = slicing.models;
|
|
5993
|
+
const modelConfig = modelsRecord[lowerCaseFirst(model)];
|
|
6401
5994
|
if (modelConfig?.fields) {
|
|
6402
5995
|
const fieldConfig = modelConfig.fields[field];
|
|
6403
5996
|
if (fieldConfig) {
|
|
6404
5997
|
return this.computeFilterKinds(fieldConfig.includedFilterKinds, fieldConfig.excludedFilterKinds);
|
|
6405
5998
|
}
|
|
6406
|
-
const allFieldsConfig = modelConfig.fields
|
|
5999
|
+
const allFieldsConfig = modelConfig.fields["$all"];
|
|
6407
6000
|
if (allFieldsConfig) {
|
|
6408
6001
|
return this.computeFilterKinds(allFieldsConfig.includedFilterKinds, allFieldsConfig.excludedFilterKinds);
|
|
6409
6002
|
}
|
|
6410
6003
|
}
|
|
6411
|
-
const allModelsConfig =
|
|
6004
|
+
const allModelsConfig = modelsRecord["$all"];
|
|
6412
6005
|
if (allModelsConfig?.fields) {
|
|
6413
|
-
|
|
6414
|
-
|
|
6006
|
+
const allModelsFieldConfig = allModelsConfig.fields[field];
|
|
6007
|
+
if (allModelsFieldConfig) {
|
|
6008
|
+
return this.computeFilterKinds(allModelsFieldConfig.includedFilterKinds, allModelsFieldConfig.excludedFilterKinds);
|
|
6009
|
+
}
|
|
6010
|
+
const allModelsAllFieldsConfig = allModelsConfig.fields["$all"];
|
|
6011
|
+
if (allModelsAllFieldsConfig) {
|
|
6012
|
+
return this.computeFilterKinds(allModelsAllFieldsConfig.includedFilterKinds, allModelsAllFieldsConfig.excludedFilterKinds);
|
|
6415
6013
|
}
|
|
6416
6014
|
}
|
|
6417
6015
|
return void 0;
|
|
@@ -6454,15 +6052,15 @@ var InputValidator = class {
|
|
|
6454
6052
|
if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) {
|
|
6455
6053
|
return this.nullableIf(valueSchema, optional);
|
|
6456
6054
|
}
|
|
6457
|
-
return
|
|
6055
|
+
return z.never();
|
|
6458
6056
|
}
|
|
6459
6057
|
if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) {
|
|
6460
|
-
return
|
|
6058
|
+
return z.union([
|
|
6461
6059
|
this.nullableIf(valueSchema, optional),
|
|
6462
|
-
|
|
6060
|
+
z.strictObject(components)
|
|
6463
6061
|
]);
|
|
6464
6062
|
} else {
|
|
6465
|
-
return
|
|
6063
|
+
return z.strictObject(components);
|
|
6466
6064
|
}
|
|
6467
6065
|
}
|
|
6468
6066
|
/**
|
|
@@ -6493,18 +6091,20 @@ _ts_decorate([
|
|
|
6493
6091
|
_ts_metadata("design:type", Function),
|
|
6494
6092
|
_ts_metadata("design:paramtypes", [
|
|
6495
6093
|
String,
|
|
6496
|
-
typeof CoreCrudOperations === "undefined" ? Object : CoreCrudOperations
|
|
6094
|
+
typeof CoreCrudOperations === "undefined" ? Object : CoreCrudOperations,
|
|
6095
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6497
6096
|
]),
|
|
6498
6097
|
_ts_metadata("design:returntype", void 0)
|
|
6499
|
-
],
|
|
6098
|
+
], ZodSchemaFactory.prototype, "makeFindSchema", null);
|
|
6500
6099
|
_ts_decorate([
|
|
6501
6100
|
cache(),
|
|
6502
6101
|
_ts_metadata("design:type", Function),
|
|
6503
6102
|
_ts_metadata("design:paramtypes", [
|
|
6504
|
-
|
|
6103
|
+
typeof Model === "undefined" ? Object : Model,
|
|
6104
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6505
6105
|
]),
|
|
6506
|
-
_ts_metadata("design:returntype",
|
|
6507
|
-
],
|
|
6106
|
+
_ts_metadata("design:returntype", typeof ZodType === "undefined" ? Object : ZodType)
|
|
6107
|
+
], ZodSchemaFactory.prototype, "makeExistsSchema", null);
|
|
6508
6108
|
_ts_decorate([
|
|
6509
6109
|
cache(),
|
|
6510
6110
|
_ts_metadata("design:type", Function),
|
|
@@ -6512,15 +6112,15 @@ _ts_decorate([
|
|
|
6512
6112
|
String
|
|
6513
6113
|
]),
|
|
6514
6114
|
_ts_metadata("design:returntype", void 0)
|
|
6515
|
-
],
|
|
6115
|
+
], ZodSchemaFactory.prototype, "makeEnumSchema", null);
|
|
6516
6116
|
_ts_decorate([
|
|
6517
6117
|
cache(),
|
|
6518
6118
|
_ts_metadata("design:type", Function),
|
|
6519
6119
|
_ts_metadata("design:paramtypes", [
|
|
6520
6120
|
String
|
|
6521
6121
|
]),
|
|
6522
|
-
_ts_metadata("design:returntype", typeof
|
|
6523
|
-
],
|
|
6122
|
+
_ts_metadata("design:returntype", typeof ZodType === "undefined" ? Object : ZodType)
|
|
6123
|
+
], ZodSchemaFactory.prototype, "makeTypeDefSchema", null);
|
|
6524
6124
|
_ts_decorate([
|
|
6525
6125
|
cache(),
|
|
6526
6126
|
_ts_metadata("design:type", Function),
|
|
@@ -6528,10 +6128,11 @@ _ts_decorate([
|
|
|
6528
6128
|
String,
|
|
6529
6129
|
Boolean,
|
|
6530
6130
|
void 0,
|
|
6531
|
-
void 0
|
|
6131
|
+
void 0,
|
|
6132
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6532
6133
|
]),
|
|
6533
6134
|
_ts_metadata("design:returntype", typeof ZodType === "undefined" ? Object : ZodType)
|
|
6534
|
-
],
|
|
6135
|
+
], ZodSchemaFactory.prototype, "makeWhereSchema", null);
|
|
6535
6136
|
_ts_decorate([
|
|
6536
6137
|
cache(),
|
|
6537
6138
|
_ts_metadata("design:type", Function),
|
|
@@ -6540,7 +6141,7 @@ _ts_decorate([
|
|
|
6540
6141
|
typeof FieldInfo === "undefined" ? Object : FieldInfo
|
|
6541
6142
|
]),
|
|
6542
6143
|
_ts_metadata("design:returntype", void 0)
|
|
6543
|
-
],
|
|
6144
|
+
], ZodSchemaFactory.prototype, "makeTypedJsonFilterSchema", null);
|
|
6544
6145
|
_ts_decorate([
|
|
6545
6146
|
cache(),
|
|
6546
6147
|
_ts_metadata("design:type", Function),
|
|
@@ -6551,7 +6152,7 @@ _ts_decorate([
|
|
|
6551
6152
|
Boolean
|
|
6552
6153
|
]),
|
|
6553
6154
|
_ts_metadata("design:returntype", void 0)
|
|
6554
|
-
],
|
|
6155
|
+
], ZodSchemaFactory.prototype, "makeEnumFilterSchema", null);
|
|
6555
6156
|
_ts_decorate([
|
|
6556
6157
|
cache(),
|
|
6557
6158
|
_ts_metadata("design:type", Function),
|
|
@@ -6560,7 +6161,7 @@ _ts_decorate([
|
|
|
6560
6161
|
typeof FieldInfo === "undefined" ? Object : FieldInfo
|
|
6561
6162
|
]),
|
|
6562
6163
|
_ts_metadata("design:returntype", void 0)
|
|
6563
|
-
],
|
|
6164
|
+
], ZodSchemaFactory.prototype, "makeArrayFilterSchema", null);
|
|
6564
6165
|
_ts_decorate([
|
|
6565
6166
|
cache(),
|
|
6566
6167
|
_ts_metadata("design:type", Function),
|
|
@@ -6571,7 +6172,7 @@ _ts_decorate([
|
|
|
6571
6172
|
void 0
|
|
6572
6173
|
]),
|
|
6573
6174
|
_ts_metadata("design:returntype", void 0)
|
|
6574
|
-
],
|
|
6175
|
+
], ZodSchemaFactory.prototype, "makePrimitiveFilterSchema", null);
|
|
6575
6176
|
_ts_decorate([
|
|
6576
6177
|
cache(),
|
|
6577
6178
|
_ts_metadata("design:type", Function),
|
|
@@ -6581,7 +6182,7 @@ _ts_decorate([
|
|
|
6581
6182
|
Boolean
|
|
6582
6183
|
]),
|
|
6583
6184
|
_ts_metadata("design:returntype", void 0)
|
|
6584
|
-
],
|
|
6185
|
+
], ZodSchemaFactory.prototype, "makeJsonFilterSchema", null);
|
|
6585
6186
|
_ts_decorate([
|
|
6586
6187
|
cache(),
|
|
6587
6188
|
_ts_metadata("design:type", Function),
|
|
@@ -6591,7 +6192,7 @@ _ts_decorate([
|
|
|
6591
6192
|
Object
|
|
6592
6193
|
]),
|
|
6593
6194
|
_ts_metadata("design:returntype", typeof ZodType === "undefined" ? Object : ZodType)
|
|
6594
|
-
],
|
|
6195
|
+
], ZodSchemaFactory.prototype, "makeDateTimeFilterSchema", null);
|
|
6595
6196
|
_ts_decorate([
|
|
6596
6197
|
cache(),
|
|
6597
6198
|
_ts_metadata("design:type", Function),
|
|
@@ -6601,7 +6202,7 @@ _ts_decorate([
|
|
|
6601
6202
|
Object
|
|
6602
6203
|
]),
|
|
6603
6204
|
_ts_metadata("design:returntype", typeof ZodType === "undefined" ? Object : ZodType)
|
|
6604
|
-
],
|
|
6205
|
+
], ZodSchemaFactory.prototype, "makeBooleanFilterSchema", null);
|
|
6605
6206
|
_ts_decorate([
|
|
6606
6207
|
cache(),
|
|
6607
6208
|
_ts_metadata("design:type", Function),
|
|
@@ -6611,32 +6212,35 @@ _ts_decorate([
|
|
|
6611
6212
|
Object
|
|
6612
6213
|
]),
|
|
6613
6214
|
_ts_metadata("design:returntype", typeof ZodType === "undefined" ? Object : ZodType)
|
|
6614
|
-
],
|
|
6215
|
+
], ZodSchemaFactory.prototype, "makeBytesFilterSchema", null);
|
|
6615
6216
|
_ts_decorate([
|
|
6616
6217
|
cache(),
|
|
6617
6218
|
_ts_metadata("design:type", Function),
|
|
6618
6219
|
_ts_metadata("design:paramtypes", [
|
|
6619
|
-
String
|
|
6220
|
+
String,
|
|
6221
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6620
6222
|
]),
|
|
6621
6223
|
_ts_metadata("design:returntype", void 0)
|
|
6622
|
-
],
|
|
6224
|
+
], ZodSchemaFactory.prototype, "makeSelectSchema", null);
|
|
6623
6225
|
_ts_decorate([
|
|
6624
6226
|
cache(),
|
|
6625
6227
|
_ts_metadata("design:type", Function),
|
|
6626
6228
|
_ts_metadata("design:paramtypes", [
|
|
6627
|
-
String
|
|
6229
|
+
String,
|
|
6230
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6628
6231
|
]),
|
|
6629
6232
|
_ts_metadata("design:returntype", void 0)
|
|
6630
|
-
],
|
|
6233
|
+
], ZodSchemaFactory.prototype, "makeCountSelectionSchema", null);
|
|
6631
6234
|
_ts_decorate([
|
|
6632
6235
|
cache(),
|
|
6633
6236
|
_ts_metadata("design:type", Function),
|
|
6634
6237
|
_ts_metadata("design:paramtypes", [
|
|
6635
6238
|
String,
|
|
6636
|
-
String
|
|
6239
|
+
String,
|
|
6240
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6637
6241
|
]),
|
|
6638
6242
|
_ts_metadata("design:returntype", void 0)
|
|
6639
|
-
],
|
|
6243
|
+
], ZodSchemaFactory.prototype, "makeRelationSelectIncludeSchema", null);
|
|
6640
6244
|
_ts_decorate([
|
|
6641
6245
|
cache(),
|
|
6642
6246
|
_ts_metadata("design:type", Function),
|
|
@@ -6644,25 +6248,27 @@ _ts_decorate([
|
|
|
6644
6248
|
String
|
|
6645
6249
|
]),
|
|
6646
6250
|
_ts_metadata("design:returntype", void 0)
|
|
6647
|
-
],
|
|
6251
|
+
], ZodSchemaFactory.prototype, "makeOmitSchema", null);
|
|
6648
6252
|
_ts_decorate([
|
|
6649
6253
|
cache(),
|
|
6650
6254
|
_ts_metadata("design:type", Function),
|
|
6651
6255
|
_ts_metadata("design:paramtypes", [
|
|
6652
|
-
String
|
|
6256
|
+
String,
|
|
6257
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6653
6258
|
]),
|
|
6654
6259
|
_ts_metadata("design:returntype", void 0)
|
|
6655
|
-
],
|
|
6260
|
+
], ZodSchemaFactory.prototype, "makeIncludeSchema", null);
|
|
6656
6261
|
_ts_decorate([
|
|
6657
6262
|
cache(),
|
|
6658
6263
|
_ts_metadata("design:type", Function),
|
|
6659
6264
|
_ts_metadata("design:paramtypes", [
|
|
6660
6265
|
String,
|
|
6661
6266
|
Boolean,
|
|
6662
|
-
Boolean
|
|
6267
|
+
Boolean,
|
|
6268
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6663
6269
|
]),
|
|
6664
6270
|
_ts_metadata("design:returntype", void 0)
|
|
6665
|
-
],
|
|
6271
|
+
], ZodSchemaFactory.prototype, "makeOrderBySchema", null);
|
|
6666
6272
|
_ts_decorate([
|
|
6667
6273
|
cache(),
|
|
6668
6274
|
_ts_metadata("design:type", Function),
|
|
@@ -6670,31 +6276,34 @@ _ts_decorate([
|
|
|
6670
6276
|
String
|
|
6671
6277
|
]),
|
|
6672
6278
|
_ts_metadata("design:returntype", void 0)
|
|
6673
|
-
],
|
|
6279
|
+
], ZodSchemaFactory.prototype, "makeDistinctSchema", null);
|
|
6674
6280
|
_ts_decorate([
|
|
6675
6281
|
cache(),
|
|
6676
6282
|
_ts_metadata("design:type", Function),
|
|
6677
6283
|
_ts_metadata("design:paramtypes", [
|
|
6678
|
-
|
|
6284
|
+
typeof Model === "undefined" ? Object : Model,
|
|
6285
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6679
6286
|
]),
|
|
6680
|
-
_ts_metadata("design:returntype",
|
|
6681
|
-
],
|
|
6287
|
+
_ts_metadata("design:returntype", typeof ZodType === "undefined" ? Object : ZodType)
|
|
6288
|
+
], ZodSchemaFactory.prototype, "makeCreateSchema", null);
|
|
6682
6289
|
_ts_decorate([
|
|
6683
6290
|
cache(),
|
|
6684
6291
|
_ts_metadata("design:type", Function),
|
|
6685
6292
|
_ts_metadata("design:paramtypes", [
|
|
6686
|
-
|
|
6293
|
+
typeof Model === "undefined" ? Object : Model,
|
|
6294
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6687
6295
|
]),
|
|
6688
|
-
_ts_metadata("design:returntype",
|
|
6689
|
-
],
|
|
6296
|
+
_ts_metadata("design:returntype", typeof ZodType === "undefined" ? Object : ZodType)
|
|
6297
|
+
], ZodSchemaFactory.prototype, "makeCreateManySchema", null);
|
|
6690
6298
|
_ts_decorate([
|
|
6691
6299
|
cache(),
|
|
6692
6300
|
_ts_metadata("design:type", Function),
|
|
6693
6301
|
_ts_metadata("design:paramtypes", [
|
|
6694
|
-
|
|
6302
|
+
typeof Model === "undefined" ? Object : Model,
|
|
6303
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6695
6304
|
]),
|
|
6696
|
-
_ts_metadata("design:returntype",
|
|
6697
|
-
],
|
|
6305
|
+
_ts_metadata("design:returntype", typeof ZodType === "undefined" ? Object : ZodType)
|
|
6306
|
+
], ZodSchemaFactory.prototype, "makeCreateManyAndReturnSchema", null);
|
|
6698
6307
|
_ts_decorate([
|
|
6699
6308
|
cache(),
|
|
6700
6309
|
_ts_metadata("design:type", Function),
|
|
@@ -6702,10 +6311,11 @@ _ts_decorate([
|
|
|
6702
6311
|
String,
|
|
6703
6312
|
Boolean,
|
|
6704
6313
|
Array,
|
|
6705
|
-
void 0
|
|
6314
|
+
void 0,
|
|
6315
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6706
6316
|
]),
|
|
6707
6317
|
_ts_metadata("design:returntype", void 0)
|
|
6708
|
-
],
|
|
6318
|
+
], ZodSchemaFactory.prototype, "makeCreateDataSchema", null);
|
|
6709
6319
|
_ts_decorate([
|
|
6710
6320
|
cache(),
|
|
6711
6321
|
_ts_metadata("design:type", Function),
|
|
@@ -6713,132 +6323,147 @@ _ts_decorate([
|
|
|
6713
6323
|
String,
|
|
6714
6324
|
String,
|
|
6715
6325
|
Array,
|
|
6716
|
-
String
|
|
6326
|
+
String,
|
|
6327
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6717
6328
|
]),
|
|
6718
6329
|
_ts_metadata("design:returntype", void 0)
|
|
6719
|
-
],
|
|
6330
|
+
], ZodSchemaFactory.prototype, "makeRelationManipulationSchema", null);
|
|
6720
6331
|
_ts_decorate([
|
|
6721
6332
|
cache(),
|
|
6722
6333
|
_ts_metadata("design:type", Function),
|
|
6723
6334
|
_ts_metadata("design:paramtypes", [
|
|
6724
6335
|
String,
|
|
6725
|
-
Boolean
|
|
6336
|
+
Boolean,
|
|
6337
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6726
6338
|
]),
|
|
6727
6339
|
_ts_metadata("design:returntype", void 0)
|
|
6728
|
-
],
|
|
6340
|
+
], ZodSchemaFactory.prototype, "makeSetDataSchema", null);
|
|
6729
6341
|
_ts_decorate([
|
|
6730
6342
|
cache(),
|
|
6731
6343
|
_ts_metadata("design:type", Function),
|
|
6732
6344
|
_ts_metadata("design:paramtypes", [
|
|
6733
6345
|
String,
|
|
6734
|
-
Boolean
|
|
6346
|
+
Boolean,
|
|
6347
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6735
6348
|
]),
|
|
6736
6349
|
_ts_metadata("design:returntype", void 0)
|
|
6737
|
-
],
|
|
6350
|
+
], ZodSchemaFactory.prototype, "makeConnectDataSchema", null);
|
|
6738
6351
|
_ts_decorate([
|
|
6739
6352
|
cache(),
|
|
6740
6353
|
_ts_metadata("design:type", Function),
|
|
6741
6354
|
_ts_metadata("design:paramtypes", [
|
|
6742
6355
|
String,
|
|
6743
|
-
Boolean
|
|
6356
|
+
Boolean,
|
|
6357
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6744
6358
|
]),
|
|
6745
6359
|
_ts_metadata("design:returntype", void 0)
|
|
6746
|
-
],
|
|
6360
|
+
], ZodSchemaFactory.prototype, "makeDisconnectDataSchema", null);
|
|
6747
6361
|
_ts_decorate([
|
|
6748
6362
|
cache(),
|
|
6749
6363
|
_ts_metadata("design:type", Function),
|
|
6750
6364
|
_ts_metadata("design:paramtypes", [
|
|
6751
6365
|
String,
|
|
6752
6366
|
Boolean,
|
|
6753
|
-
Boolean
|
|
6367
|
+
Boolean,
|
|
6368
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6754
6369
|
]),
|
|
6755
6370
|
_ts_metadata("design:returntype", void 0)
|
|
6756
|
-
],
|
|
6371
|
+
], ZodSchemaFactory.prototype, "makeDeleteRelationDataSchema", null);
|
|
6757
6372
|
_ts_decorate([
|
|
6758
6373
|
cache(),
|
|
6759
6374
|
_ts_metadata("design:type", Function),
|
|
6760
6375
|
_ts_metadata("design:paramtypes", [
|
|
6761
6376
|
String,
|
|
6762
6377
|
Boolean,
|
|
6763
|
-
Array
|
|
6378
|
+
Array,
|
|
6379
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6764
6380
|
]),
|
|
6765
6381
|
_ts_metadata("design:returntype", void 0)
|
|
6766
|
-
],
|
|
6382
|
+
], ZodSchemaFactory.prototype, "makeConnectOrCreateDataSchema", null);
|
|
6767
6383
|
_ts_decorate([
|
|
6768
6384
|
cache(),
|
|
6769
6385
|
_ts_metadata("design:type", Function),
|
|
6770
6386
|
_ts_metadata("design:paramtypes", [
|
|
6771
6387
|
String,
|
|
6772
|
-
Array
|
|
6388
|
+
Array,
|
|
6389
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6773
6390
|
]),
|
|
6774
6391
|
_ts_metadata("design:returntype", void 0)
|
|
6775
|
-
],
|
|
6392
|
+
], ZodSchemaFactory.prototype, "makeCreateManyPayloadSchema", null);
|
|
6776
6393
|
_ts_decorate([
|
|
6777
6394
|
cache(),
|
|
6778
6395
|
_ts_metadata("design:type", Function),
|
|
6779
6396
|
_ts_metadata("design:paramtypes", [
|
|
6780
|
-
|
|
6397
|
+
typeof Model === "undefined" ? Object : Model,
|
|
6398
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6781
6399
|
]),
|
|
6782
|
-
_ts_metadata("design:returntype",
|
|
6783
|
-
],
|
|
6400
|
+
_ts_metadata("design:returntype", typeof ZodType === "undefined" ? Object : ZodType)
|
|
6401
|
+
], ZodSchemaFactory.prototype, "makeUpdateSchema", null);
|
|
6784
6402
|
_ts_decorate([
|
|
6785
6403
|
cache(),
|
|
6786
6404
|
_ts_metadata("design:type", Function),
|
|
6787
6405
|
_ts_metadata("design:paramtypes", [
|
|
6788
|
-
|
|
6406
|
+
typeof Model === "undefined" ? Object : Model,
|
|
6407
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6789
6408
|
]),
|
|
6790
|
-
_ts_metadata("design:returntype",
|
|
6791
|
-
],
|
|
6409
|
+
_ts_metadata("design:returntype", typeof ZodType === "undefined" ? Object : ZodType)
|
|
6410
|
+
], ZodSchemaFactory.prototype, "makeUpdateManySchema", null);
|
|
6792
6411
|
_ts_decorate([
|
|
6793
6412
|
cache(),
|
|
6794
6413
|
_ts_metadata("design:type", Function),
|
|
6795
6414
|
_ts_metadata("design:paramtypes", [
|
|
6796
|
-
|
|
6415
|
+
typeof Model === "undefined" ? Object : Model,
|
|
6416
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6797
6417
|
]),
|
|
6798
|
-
_ts_metadata("design:returntype",
|
|
6799
|
-
],
|
|
6418
|
+
_ts_metadata("design:returntype", typeof ZodType === "undefined" ? Object : ZodType)
|
|
6419
|
+
], ZodSchemaFactory.prototype, "makeUpdateManyAndReturnSchema", null);
|
|
6800
6420
|
_ts_decorate([
|
|
6801
6421
|
cache(),
|
|
6802
6422
|
_ts_metadata("design:type", Function),
|
|
6803
6423
|
_ts_metadata("design:paramtypes", [
|
|
6804
|
-
|
|
6424
|
+
typeof Model === "undefined" ? Object : Model,
|
|
6425
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6805
6426
|
]),
|
|
6806
|
-
_ts_metadata("design:returntype",
|
|
6807
|
-
],
|
|
6427
|
+
_ts_metadata("design:returntype", typeof ZodType === "undefined" ? Object : ZodType)
|
|
6428
|
+
], ZodSchemaFactory.prototype, "makeUpsertSchema", null);
|
|
6808
6429
|
_ts_decorate([
|
|
6809
6430
|
cache(),
|
|
6810
6431
|
_ts_metadata("design:type", Function),
|
|
6811
6432
|
_ts_metadata("design:paramtypes", [
|
|
6812
6433
|
String,
|
|
6813
6434
|
Array,
|
|
6814
|
-
void 0
|
|
6435
|
+
void 0,
|
|
6436
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6815
6437
|
]),
|
|
6816
6438
|
_ts_metadata("design:returntype", void 0)
|
|
6817
|
-
],
|
|
6439
|
+
], ZodSchemaFactory.prototype, "makeUpdateDataSchema", null);
|
|
6818
6440
|
_ts_decorate([
|
|
6819
6441
|
cache(),
|
|
6820
6442
|
_ts_metadata("design:type", Function),
|
|
6821
6443
|
_ts_metadata("design:paramtypes", [
|
|
6822
|
-
|
|
6444
|
+
typeof Model === "undefined" ? Object : Model,
|
|
6445
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6823
6446
|
]),
|
|
6824
|
-
_ts_metadata("design:returntype",
|
|
6825
|
-
],
|
|
6447
|
+
_ts_metadata("design:returntype", typeof ZodType === "undefined" ? Object : ZodType)
|
|
6448
|
+
], ZodSchemaFactory.prototype, "makeDeleteSchema", null);
|
|
6826
6449
|
_ts_decorate([
|
|
6827
6450
|
cache(),
|
|
6828
6451
|
_ts_metadata("design:type", Function),
|
|
6829
6452
|
_ts_metadata("design:paramtypes", [
|
|
6830
|
-
|
|
6453
|
+
typeof Model === "undefined" ? Object : Model,
|
|
6454
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6831
6455
|
]),
|
|
6832
|
-
_ts_metadata("design:returntype",
|
|
6833
|
-
],
|
|
6456
|
+
_ts_metadata("design:returntype", typeof ZodType === "undefined" ? Object : ZodType)
|
|
6457
|
+
], ZodSchemaFactory.prototype, "makeDeleteManySchema", null);
|
|
6834
6458
|
_ts_decorate([
|
|
6835
6459
|
cache(),
|
|
6836
6460
|
_ts_metadata("design:type", Function),
|
|
6837
6461
|
_ts_metadata("design:paramtypes", [
|
|
6838
|
-
|
|
6462
|
+
typeof Model === "undefined" ? Object : Model,
|
|
6463
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6839
6464
|
]),
|
|
6840
|
-
_ts_metadata("design:returntype",
|
|
6841
|
-
],
|
|
6465
|
+
_ts_metadata("design:returntype", typeof ZodType === "undefined" ? Object : ZodType)
|
|
6466
|
+
], ZodSchemaFactory.prototype, "makeCountSchema", null);
|
|
6842
6467
|
_ts_decorate([
|
|
6843
6468
|
cache(),
|
|
6844
6469
|
_ts_metadata("design:type", Function),
|
|
@@ -6846,15 +6471,16 @@ _ts_decorate([
|
|
|
6846
6471
|
String
|
|
6847
6472
|
]),
|
|
6848
6473
|
_ts_metadata("design:returntype", void 0)
|
|
6849
|
-
],
|
|
6474
|
+
], ZodSchemaFactory.prototype, "makeCountAggregateInputSchema", null);
|
|
6850
6475
|
_ts_decorate([
|
|
6851
6476
|
cache(),
|
|
6852
6477
|
_ts_metadata("design:type", Function),
|
|
6853
6478
|
_ts_metadata("design:paramtypes", [
|
|
6854
|
-
|
|
6479
|
+
typeof Model === "undefined" ? Object : Model,
|
|
6480
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6855
6481
|
]),
|
|
6856
|
-
_ts_metadata("design:returntype",
|
|
6857
|
-
],
|
|
6482
|
+
_ts_metadata("design:returntype", typeof ZodType === "undefined" ? Object : ZodType)
|
|
6483
|
+
], ZodSchemaFactory.prototype, "makeAggregateSchema", null);
|
|
6858
6484
|
_ts_decorate([
|
|
6859
6485
|
cache(),
|
|
6860
6486
|
_ts_metadata("design:type", Function),
|
|
@@ -6862,7 +6488,7 @@ _ts_decorate([
|
|
|
6862
6488
|
String
|
|
6863
6489
|
]),
|
|
6864
6490
|
_ts_metadata("design:returntype", void 0)
|
|
6865
|
-
],
|
|
6491
|
+
], ZodSchemaFactory.prototype, "makeSumAvgInputSchema", null);
|
|
6866
6492
|
_ts_decorate([
|
|
6867
6493
|
cache(),
|
|
6868
6494
|
_ts_metadata("design:type", Function),
|
|
@@ -6870,35 +6496,168 @@ _ts_decorate([
|
|
|
6870
6496
|
String
|
|
6871
6497
|
]),
|
|
6872
6498
|
_ts_metadata("design:returntype", void 0)
|
|
6873
|
-
],
|
|
6499
|
+
], ZodSchemaFactory.prototype, "makeMinMaxInputSchema", null);
|
|
6874
6500
|
_ts_decorate([
|
|
6875
6501
|
cache(),
|
|
6876
6502
|
_ts_metadata("design:type", Function),
|
|
6877
6503
|
_ts_metadata("design:paramtypes", [
|
|
6878
|
-
|
|
6504
|
+
typeof Model === "undefined" ? Object : Model,
|
|
6505
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6879
6506
|
]),
|
|
6880
|
-
_ts_metadata("design:returntype",
|
|
6881
|
-
],
|
|
6507
|
+
_ts_metadata("design:returntype", typeof ZodType === "undefined" ? Object : ZodType)
|
|
6508
|
+
], ZodSchemaFactory.prototype, "makeGroupBySchema", null);
|
|
6882
6509
|
_ts_decorate([
|
|
6883
6510
|
cache(),
|
|
6884
6511
|
_ts_metadata("design:type", Function),
|
|
6885
6512
|
_ts_metadata("design:paramtypes", [
|
|
6886
|
-
Object
|
|
6513
|
+
Object,
|
|
6514
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6887
6515
|
]),
|
|
6888
|
-
_ts_metadata("design:returntype", typeof
|
|
6889
|
-
],
|
|
6516
|
+
_ts_metadata("design:returntype", typeof ZodType === "undefined" ? Object : ZodType)
|
|
6517
|
+
], ZodSchemaFactory.prototype, "makeProcedureParamSchema", null);
|
|
6890
6518
|
_ts_decorate([
|
|
6891
6519
|
cache(),
|
|
6892
6520
|
_ts_metadata("design:type", Function),
|
|
6893
6521
|
_ts_metadata("design:paramtypes", []),
|
|
6894
6522
|
_ts_metadata("design:returntype", void 0)
|
|
6895
|
-
],
|
|
6523
|
+
], ZodSchemaFactory.prototype, "makeSkipSchema", null);
|
|
6896
6524
|
_ts_decorate([
|
|
6897
6525
|
cache(),
|
|
6898
6526
|
_ts_metadata("design:type", Function),
|
|
6899
6527
|
_ts_metadata("design:paramtypes", []),
|
|
6900
6528
|
_ts_metadata("design:returntype", void 0)
|
|
6901
|
-
],
|
|
6529
|
+
], ZodSchemaFactory.prototype, "makeTakeSchema", null);
|
|
6530
|
+
|
|
6531
|
+
// src/client/crud/validator/validator.ts
|
|
6532
|
+
var InputValidator = class {
|
|
6533
|
+
static {
|
|
6534
|
+
__name(this, "InputValidator");
|
|
6535
|
+
}
|
|
6536
|
+
client;
|
|
6537
|
+
zodFactory;
|
|
6538
|
+
constructor(client) {
|
|
6539
|
+
this.client = client;
|
|
6540
|
+
this.zodFactory = new ZodSchemaFactory(client);
|
|
6541
|
+
}
|
|
6542
|
+
// #region Entry points
|
|
6543
|
+
validateFindArgs(model, args, operation) {
|
|
6544
|
+
return this.validate(model, operation, (model2) => match14(operation).with("findFirst", () => this.zodFactory.makeFindFirstSchema(model2)).with("findUnique", () => this.zodFactory.makeFindUniqueSchema(model2)).with("findMany", () => this.zodFactory.makeFindManySchema(model2)).exhaustive(), args);
|
|
6545
|
+
}
|
|
6546
|
+
validateExistsArgs(model, args) {
|
|
6547
|
+
return this.validate(model, "exists", (model2) => this.zodFactory.makeExistsSchema(model2), args);
|
|
6548
|
+
}
|
|
6549
|
+
validateCreateArgs(model, args) {
|
|
6550
|
+
return this.validate(model, "create", (model2) => this.zodFactory.makeCreateSchema(model2), args);
|
|
6551
|
+
}
|
|
6552
|
+
validateCreateManyArgs(model, args) {
|
|
6553
|
+
return this.validate(model, "createMany", (model2) => this.zodFactory.makeCreateManySchema(model2), args);
|
|
6554
|
+
}
|
|
6555
|
+
validateCreateManyAndReturnArgs(model, args) {
|
|
6556
|
+
return this.validate(model, "createManyAndReturn", (model2) => this.zodFactory.makeCreateManyAndReturnSchema(model2), args);
|
|
6557
|
+
}
|
|
6558
|
+
validateUpdateArgs(model, args) {
|
|
6559
|
+
return this.validate(model, "update", (model2) => this.zodFactory.makeUpdateSchema(model2), args);
|
|
6560
|
+
}
|
|
6561
|
+
validateUpdateManyArgs(model, args) {
|
|
6562
|
+
return this.validate(model, "updateMany", (model2) => this.zodFactory.makeUpdateManySchema(model2), args);
|
|
6563
|
+
}
|
|
6564
|
+
validateUpdateManyAndReturnArgs(model, args) {
|
|
6565
|
+
return this.validate(model, "updateManyAndReturn", (model2) => this.zodFactory.makeUpdateManyAndReturnSchema(model2), args);
|
|
6566
|
+
}
|
|
6567
|
+
validateUpsertArgs(model, args) {
|
|
6568
|
+
return this.validate(model, "upsert", (model2) => this.zodFactory.makeUpsertSchema(model2), args);
|
|
6569
|
+
}
|
|
6570
|
+
validateDeleteArgs(model, args) {
|
|
6571
|
+
return this.validate(model, "delete", (model2) => this.zodFactory.makeDeleteSchema(model2), args);
|
|
6572
|
+
}
|
|
6573
|
+
validateDeleteManyArgs(model, args) {
|
|
6574
|
+
return this.validate(model, "deleteMany", (model2) => this.zodFactory.makeDeleteManySchema(model2), args);
|
|
6575
|
+
}
|
|
6576
|
+
validateCountArgs(model, args) {
|
|
6577
|
+
return this.validate(model, "count", (model2) => this.zodFactory.makeCountSchema(model2), args);
|
|
6578
|
+
}
|
|
6579
|
+
validateAggregateArgs(model, args) {
|
|
6580
|
+
return this.validate(model, "aggregate", (model2) => this.zodFactory.makeAggregateSchema(model2), args);
|
|
6581
|
+
}
|
|
6582
|
+
validateGroupByArgs(model, args) {
|
|
6583
|
+
return this.validate(model, "groupBy", (model2) => this.zodFactory.makeGroupBySchema(model2), args);
|
|
6584
|
+
}
|
|
6585
|
+
// TODO: turn it into a Zod schema and cache
|
|
6586
|
+
validateProcedureInput(proc, input) {
|
|
6587
|
+
const procDef = (this.client.$schema.procedures ?? {})[proc];
|
|
6588
|
+
invariant9(procDef, `Procedure "${proc}" not found in schema`);
|
|
6589
|
+
const params = Object.values(procDef.params ?? {});
|
|
6590
|
+
if (typeof input === "undefined") {
|
|
6591
|
+
if (params.length === 0) {
|
|
6592
|
+
return void 0;
|
|
6593
|
+
}
|
|
6594
|
+
if (params.every((p) => p.optional)) {
|
|
6595
|
+
return void 0;
|
|
6596
|
+
}
|
|
6597
|
+
throw createInvalidInputError("Missing procedure arguments", `$procs.${proc}`);
|
|
6598
|
+
}
|
|
6599
|
+
if (typeof input !== "object" || input === null || Array.isArray(input)) {
|
|
6600
|
+
throw createInvalidInputError("Procedure input must be an object", `$procs.${proc}`);
|
|
6601
|
+
}
|
|
6602
|
+
const envelope = input;
|
|
6603
|
+
const argsPayload = Object.prototype.hasOwnProperty.call(envelope, "args") ? envelope.args : void 0;
|
|
6604
|
+
if (params.length === 0) {
|
|
6605
|
+
if (typeof argsPayload === "undefined") {
|
|
6606
|
+
return input;
|
|
6607
|
+
}
|
|
6608
|
+
if (!argsPayload || typeof argsPayload !== "object" || Array.isArray(argsPayload)) {
|
|
6609
|
+
throw createInvalidInputError("Procedure `args` must be an object", `$procs.${proc}`);
|
|
6610
|
+
}
|
|
6611
|
+
if (Object.keys(argsPayload).length === 0) {
|
|
6612
|
+
return input;
|
|
6613
|
+
}
|
|
6614
|
+
throw createInvalidInputError("Procedure does not accept arguments", `$procs.${proc}`);
|
|
6615
|
+
}
|
|
6616
|
+
if (typeof argsPayload === "undefined") {
|
|
6617
|
+
if (params.every((p) => p.optional)) {
|
|
6618
|
+
return input;
|
|
6619
|
+
}
|
|
6620
|
+
throw createInvalidInputError("Missing procedure arguments", `$procs.${proc}`);
|
|
6621
|
+
}
|
|
6622
|
+
if (!argsPayload || typeof argsPayload !== "object" || Array.isArray(argsPayload)) {
|
|
6623
|
+
throw createInvalidInputError("Procedure `args` must be an object", `$procs.${proc}`);
|
|
6624
|
+
}
|
|
6625
|
+
const obj = argsPayload;
|
|
6626
|
+
for (const param of params) {
|
|
6627
|
+
const value = obj[param.name];
|
|
6628
|
+
if (!Object.prototype.hasOwnProperty.call(obj, param.name)) {
|
|
6629
|
+
if (param.optional) {
|
|
6630
|
+
continue;
|
|
6631
|
+
}
|
|
6632
|
+
throw createInvalidInputError(`Missing procedure argument: ${param.name}`, `$procs.${proc}`);
|
|
6633
|
+
}
|
|
6634
|
+
if (typeof value === "undefined") {
|
|
6635
|
+
if (param.optional) {
|
|
6636
|
+
continue;
|
|
6637
|
+
}
|
|
6638
|
+
throw createInvalidInputError(`Invalid procedure argument: ${param.name} is required`, `$procs.${proc}`);
|
|
6639
|
+
}
|
|
6640
|
+
const schema = this.zodFactory.makeProcedureParamSchema(param);
|
|
6641
|
+
const parsed = schema.safeParse(value);
|
|
6642
|
+
if (!parsed.success) {
|
|
6643
|
+
throw createInvalidInputError(`Invalid procedure argument: ${param.name}: ${formatError(parsed.error)}`, `$procs.${proc}`);
|
|
6644
|
+
}
|
|
6645
|
+
}
|
|
6646
|
+
return input;
|
|
6647
|
+
}
|
|
6648
|
+
// #endregion
|
|
6649
|
+
// #region Validation helpers
|
|
6650
|
+
validate(model, operation, getSchema, args) {
|
|
6651
|
+
const schema = getSchema(model);
|
|
6652
|
+
const { error, data } = schema.safeParse(args);
|
|
6653
|
+
if (error) {
|
|
6654
|
+
throw createInvalidInputError(`Invalid ${operation} args for model "${model}": ${formatError(error)}`, model, {
|
|
6655
|
+
cause: error
|
|
6656
|
+
});
|
|
6657
|
+
}
|
|
6658
|
+
return data;
|
|
6659
|
+
}
|
|
6660
|
+
};
|
|
6902
6661
|
|
|
6903
6662
|
// src/client/executor/zenstack-driver.ts
|
|
6904
6663
|
var ZenStackDriver = class {
|
|
@@ -7673,6 +7432,30 @@ var QueryNameMapper = class extends OperationNodeTransformer {
|
|
|
7673
7432
|
}
|
|
7674
7433
|
};
|
|
7675
7434
|
|
|
7435
|
+
// src/client/executor/temp-alias-transformer.ts
|
|
7436
|
+
import { IdentifierNode as IdentifierNode2, OperationNodeTransformer as OperationNodeTransformer2 } from "kysely";
|
|
7437
|
+
var TempAliasTransformer = class extends OperationNodeTransformer2 {
|
|
7438
|
+
static {
|
|
7439
|
+
__name(this, "TempAliasTransformer");
|
|
7440
|
+
}
|
|
7441
|
+
aliasMap = /* @__PURE__ */ new Map();
|
|
7442
|
+
run(node) {
|
|
7443
|
+
this.aliasMap.clear();
|
|
7444
|
+
return this.transformNode(node);
|
|
7445
|
+
}
|
|
7446
|
+
transformIdentifier(node, queryId) {
|
|
7447
|
+
if (node.name.startsWith(TEMP_ALIAS_PREFIX)) {
|
|
7448
|
+
let mapped = this.aliasMap.get(node.name);
|
|
7449
|
+
if (!mapped) {
|
|
7450
|
+
mapped = `$$t${this.aliasMap.size + 1}`;
|
|
7451
|
+
this.aliasMap.set(node.name, mapped);
|
|
7452
|
+
}
|
|
7453
|
+
return IdentifierNode2.create(mapped);
|
|
7454
|
+
}
|
|
7455
|
+
return super.transformIdentifier(node, queryId);
|
|
7456
|
+
}
|
|
7457
|
+
};
|
|
7458
|
+
|
|
7676
7459
|
// src/client/executor/zenstack-query-executor.ts
|
|
7677
7460
|
var ZenStackQueryExecutor = class _ZenStackQueryExecutor extends DefaultQueryExecutor {
|
|
7678
7461
|
static {
|
|
@@ -8049,9 +7832,21 @@ In such cases, ZenStack cannot reliably determine the IDs of the mutated entitie
|
|
|
8049
7832
|
throw createInternalError(`Invalid query node: ${node}`);
|
|
8050
7833
|
});
|
|
8051
7834
|
}
|
|
7835
|
+
processQueryNode(query) {
|
|
7836
|
+
let result = query;
|
|
7837
|
+
result = this.processNameMapping(result);
|
|
7838
|
+
result = this.processTempAlias(result);
|
|
7839
|
+
return result;
|
|
7840
|
+
}
|
|
8052
7841
|
processNameMapping(query) {
|
|
8053
7842
|
return this.nameMapper?.transformNode(query) ?? query;
|
|
8054
7843
|
}
|
|
7844
|
+
processTempAlias(query) {
|
|
7845
|
+
if (this.options.useCompactAliasNames === false) {
|
|
7846
|
+
return query;
|
|
7847
|
+
}
|
|
7848
|
+
return new TempAliasTransformer().run(query);
|
|
7849
|
+
}
|
|
8055
7850
|
createClientForConnection(connection, inTx) {
|
|
8056
7851
|
const innerExecutor = this.withConnectionProvider(new SingleConnectionProvider(connection));
|
|
8057
7852
|
innerExecutor.suppressMutationHooks = true;
|
|
@@ -8071,7 +7866,7 @@ In such cases, ZenStack cannot reliably determine the IDs of the mutated entitie
|
|
|
8071
7866
|
}
|
|
8072
7867
|
}
|
|
8073
7868
|
async internalExecuteQuery(query, connection, queryId, parameters) {
|
|
8074
|
-
const finalQuery = this.
|
|
7869
|
+
const finalQuery = this.processQueryNode(query);
|
|
8075
7870
|
let compiledQuery = this.compileQuery(finalQuery, queryId ?? createQueryId2());
|
|
8076
7871
|
if (parameters) {
|
|
8077
7872
|
compiledQuery = {
|
|
@@ -8141,7 +7936,7 @@ __export(functions_exports, {
|
|
|
8141
7936
|
search: () => search,
|
|
8142
7937
|
startsWith: () => startsWith
|
|
8143
7938
|
});
|
|
8144
|
-
import { invariant as invariant12, lowerCaseFirst, upperCaseFirst } from "@zenstackhq/common-helpers";
|
|
7939
|
+
import { invariant as invariant12, lowerCaseFirst as lowerCaseFirst2, upperCaseFirst } from "@zenstackhq/common-helpers";
|
|
8145
7940
|
import { sql as sql6, ValueNode as ValueNode3 } from "kysely";
|
|
8146
7941
|
import { match as match16 } from "ts-pattern";
|
|
8147
7942
|
var contains = /* @__PURE__ */ __name((eb, args, context) => textMatch(eb, args, context, "contains"), "contains");
|
|
@@ -8252,7 +8047,7 @@ var currentOperation = /* @__PURE__ */ __name((_eb, args, { operation }) => {
|
|
|
8252
8047
|
function processCasing(casing, result, model) {
|
|
8253
8048
|
const opNode = casing.toOperationNode();
|
|
8254
8049
|
invariant12(ValueNode3.is(opNode) && typeof opNode.value === "string", '"casting" parameter must be a string value');
|
|
8255
|
-
result = match16(opNode.value).with("original", () => model).with("upper", () => result.toUpperCase()).with("lower", () => result.toLowerCase()).with("capitalize", () => upperCaseFirst(result)).with("uncapitalize", () =>
|
|
8050
|
+
result = match16(opNode.value).with("original", () => model).with("upper", () => result.toUpperCase()).with("lower", () => result.toLowerCase()).with("capitalize", () => upperCaseFirst(result)).with("uncapitalize", () => lowerCaseFirst2(result)).otherwise(() => {
|
|
8256
8051
|
throw new Error(`Invalid casing value: ${opNode.value}. Must be "original", "upper", "lower", "capitalize", or "uncapitalize".`);
|
|
8257
8052
|
});
|
|
8258
8053
|
return result;
|
|
@@ -8802,6 +8597,9 @@ var ClientImpl = class _ClientImpl {
|
|
|
8802
8597
|
get $qbRaw() {
|
|
8803
8598
|
return this.kyselyRaw;
|
|
8804
8599
|
}
|
|
8600
|
+
get $zod() {
|
|
8601
|
+
return this.inputValidator.zodFactory;
|
|
8602
|
+
}
|
|
8805
8603
|
get isTransaction() {
|
|
8806
8604
|
return this.kysely.isTransaction;
|
|
8807
8605
|
}
|
|
@@ -9208,7 +9006,7 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
|
|
|
9208
9006
|
};
|
|
9209
9007
|
const slicing = client.$options.slicing;
|
|
9210
9008
|
if (slicing?.models) {
|
|
9211
|
-
const modelSlicing = slicing.models[model];
|
|
9009
|
+
const modelSlicing = slicing.models[lowerCaseFirst3(model)];
|
|
9212
9010
|
const allSlicing = slicing.models.$all;
|
|
9213
9011
|
const includedOperations = modelSlicing?.includedOperations ?? allSlicing?.includedOperations;
|
|
9214
9012
|
const excludedOperations = modelSlicing?.excludedOperations ?? allSlicing?.excludedOperations;
|
|
@@ -9678,6 +9476,7 @@ export {
|
|
|
9678
9476
|
schema_utils_exports as SchemaUtils,
|
|
9679
9477
|
TransactionIsolationLevel,
|
|
9680
9478
|
ZenStackClient,
|
|
9479
|
+
createQuerySchemaFactory,
|
|
9681
9480
|
definePlugin,
|
|
9682
9481
|
getCrudDialect
|
|
9683
9482
|
};
|