@zenstackhq/orm 3.4.0-beta.4 → 3.4.1
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 +756 -962
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +499 -448
- package/dist/index.d.ts +499 -448
- package/dist/index.js +848 -1055
- package/dist/index.js.map +1 -1
- package/package.json +7 -6
package/dist/index.cjs
CHANGED
|
@@ -58,6 +58,7 @@ __export(src_exports, {
|
|
|
58
58
|
SchemaUtils: () => schema_utils_exports,
|
|
59
59
|
TransactionIsolationLevel: () => TransactionIsolationLevel,
|
|
60
60
|
ZenStackClient: () => ZenStackClient,
|
|
61
|
+
createQuerySchemaFactory: () => createQuerySchemaFactory,
|
|
61
62
|
definePlugin: () => definePlugin,
|
|
62
63
|
getCrudDialect: () => getCrudDialect
|
|
63
64
|
});
|
|
@@ -65,7 +66,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
65
66
|
|
|
66
67
|
// src/client/client-impl.ts
|
|
67
68
|
var import_common_helpers14 = require("@zenstackhq/common-helpers");
|
|
68
|
-
var
|
|
69
|
+
var import_kysely12 = require("kysely");
|
|
69
70
|
|
|
70
71
|
// src/client/crud/operations/aggregate.ts
|
|
71
72
|
var import_ts_pattern8 = require("ts-pattern");
|
|
@@ -73,6 +74,7 @@ var import_ts_pattern8 = require("ts-pattern");
|
|
|
73
74
|
// src/client/query-utils.ts
|
|
74
75
|
var query_utils_exports = {};
|
|
75
76
|
__export(query_utils_exports, {
|
|
77
|
+
TEMP_ALIAS_PREFIX: () => TEMP_ALIAS_PREFIX,
|
|
76
78
|
aggregate: () => aggregate,
|
|
77
79
|
buildJoinPairs: () => buildJoinPairs,
|
|
78
80
|
ensureArray: () => ensureArray,
|
|
@@ -105,7 +107,8 @@ __export(query_utils_exports, {
|
|
|
105
107
|
requireIdFields: () => requireIdFields,
|
|
106
108
|
requireModel: () => requireModel,
|
|
107
109
|
requireTypeDef: () => requireTypeDef,
|
|
108
|
-
stripAlias: () => stripAlias
|
|
110
|
+
stripAlias: () => stripAlias,
|
|
111
|
+
tmpAlias: () => tmpAlias
|
|
109
112
|
});
|
|
110
113
|
var import_common_helpers = require("@zenstackhq/common-helpers");
|
|
111
114
|
var import_kysely = require("kysely");
|
|
@@ -620,6 +623,15 @@ function extractFieldName(node) {
|
|
|
620
623
|
}
|
|
621
624
|
}
|
|
622
625
|
__name(extractFieldName, "extractFieldName");
|
|
626
|
+
var TEMP_ALIAS_PREFIX = "$$_";
|
|
627
|
+
function tmpAlias(name) {
|
|
628
|
+
if (!name.startsWith(TEMP_ALIAS_PREFIX)) {
|
|
629
|
+
return `${TEMP_ALIAS_PREFIX}${name}`;
|
|
630
|
+
} else {
|
|
631
|
+
return name;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
__name(tmpAlias, "tmpAlias");
|
|
623
635
|
|
|
624
636
|
// src/client/crud/operations/base.ts
|
|
625
637
|
var import_cuid2 = require("@paralleldrive/cuid2");
|
|
@@ -896,7 +908,7 @@ var BaseCrudDialect = class {
|
|
|
896
908
|
});
|
|
897
909
|
}
|
|
898
910
|
}
|
|
899
|
-
const joinAlias = `${modelAlias}$${field}
|
|
911
|
+
const joinAlias = tmpAlias(`${modelAlias}$${field}`);
|
|
900
912
|
const joinPairs = buildJoinPairs(
|
|
901
913
|
this.schema,
|
|
902
914
|
model,
|
|
@@ -905,7 +917,7 @@ var BaseCrudDialect = class {
|
|
|
905
917
|
field,
|
|
906
918
|
joinAlias
|
|
907
919
|
);
|
|
908
|
-
const filterResultField = `${field}$
|
|
920
|
+
const filterResultField = tmpAlias(`${field}$flt`);
|
|
909
921
|
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));
|
|
910
922
|
const conditions = [];
|
|
911
923
|
if ("is" in payload || "isNot" in payload) {
|
|
@@ -938,7 +950,7 @@ var BaseCrudDialect = class {
|
|
|
938
950
|
return this.eb(this.eb.ref(`${modelAlias}.${field}`), "is", null);
|
|
939
951
|
}
|
|
940
952
|
const relationModel = fieldDef.type;
|
|
941
|
-
const relationFilterSelectAlias = `${modelAlias}$${field}$
|
|
953
|
+
const relationFilterSelectAlias = tmpAlias(`${modelAlias}$${field}$flt`);
|
|
942
954
|
const buildPkFkWhereRefs = /* @__PURE__ */ __name((eb) => {
|
|
943
955
|
const m2m = getManyToManyRelation(this.schema, model, field);
|
|
944
956
|
if (m2m) {
|
|
@@ -1402,7 +1414,7 @@ var BaseCrudDialect = class {
|
|
|
1402
1414
|
(0, import_common_helpers2.invariant)(value._count === "asc" || value._count === "desc", 'invalid orderBy value for field "_count"');
|
|
1403
1415
|
const sort = this.negateSort(value._count, negated);
|
|
1404
1416
|
result = result.orderBy((eb) => {
|
|
1405
|
-
const subQueryAlias = `${modelAlias}$
|
|
1417
|
+
const subQueryAlias = tmpAlias(`${modelAlias}$ob$${field}$ct`);
|
|
1406
1418
|
let subQuery = this.buildSelectModel(relationModel, subQueryAlias);
|
|
1407
1419
|
const joinPairs = buildJoinPairs(this.schema, model, modelAlias, field, subQueryAlias);
|
|
1408
1420
|
subQuery = subQuery.where(() => this.and(...joinPairs.map(([left, right]) => eb(this.eb.ref(left), "=", this.eb.ref(right)))));
|
|
@@ -1411,7 +1423,7 @@ var BaseCrudDialect = class {
|
|
|
1411
1423
|
}, sort);
|
|
1412
1424
|
}
|
|
1413
1425
|
} else {
|
|
1414
|
-
const joinAlias = `${modelAlias}$
|
|
1426
|
+
const joinAlias = tmpAlias(`${modelAlias}$ob$${index}`);
|
|
1415
1427
|
result = result.leftJoin(`${relationModel} as ${joinAlias}`, (join) => {
|
|
1416
1428
|
const joinPairs = buildJoinPairs(this.schema, model, modelAlias, field, joinAlias);
|
|
1417
1429
|
return join.on((eb) => this.and(...joinPairs.map(([left, right]) => eb(this.eb.ref(left), "=", this.eb.ref(right)))));
|
|
@@ -1604,7 +1616,7 @@ var LateralJoinDialectBase = class extends BaseCrudDialect {
|
|
|
1604
1616
|
__name(this, "LateralJoinDialectBase");
|
|
1605
1617
|
}
|
|
1606
1618
|
buildRelationSelection(query, model, relationField, parentAlias, payload) {
|
|
1607
|
-
const relationResultName = `${parentAlias}$${relationField}
|
|
1619
|
+
const relationResultName = tmpAlias(`${parentAlias}$${relationField}`);
|
|
1608
1620
|
const joinedQuery = this.buildRelationJSON(model, query, relationField, parentAlias, payload, relationResultName);
|
|
1609
1621
|
return joinedQuery.select(`${relationResultName}.$data as ${relationField}`);
|
|
1610
1622
|
}
|
|
@@ -1612,7 +1624,7 @@ var LateralJoinDialectBase = class extends BaseCrudDialect {
|
|
|
1612
1624
|
const relationFieldDef = requireField(this.schema, model, relationField);
|
|
1613
1625
|
const relationModel = relationFieldDef.type;
|
|
1614
1626
|
return qb.leftJoinLateral((eb) => {
|
|
1615
|
-
const relationSelectName = `${resultName}$sub
|
|
1627
|
+
const relationSelectName = tmpAlias(`${resultName}$sub`);
|
|
1616
1628
|
const relationModelDef = requireModel(this.schema, relationModel);
|
|
1617
1629
|
let tbl;
|
|
1618
1630
|
if (this.canJoinWithoutNestedSelect(relationModelDef, payload)) {
|
|
@@ -1899,7 +1911,7 @@ var MySqlCrudDialect = class extends LateralJoinDialectBase {
|
|
|
1899
1911
|
]), "=", this.transformInput(value, "Json", false))).with("array_ends_with", () => this.eb(import_kysely3.sql`JSON_EXTRACT(${lhs}, CONCAT('$[', JSON_LENGTH(${lhs}) - 1, ']'))`, "=", this.transformInput(value, "Json", false))).exhaustive();
|
|
1900
1912
|
}
|
|
1901
1913
|
buildJsonArrayExistsPredicate(receiver, buildFilter) {
|
|
1902
|
-
return this.eb.exists(this.eb.selectFrom(import_kysely3.sql`JSON_TABLE(${receiver}, '$[*]' COLUMNS(value JSON PATH '$'))`.as("$items")).select(this.eb.lit(1).as("
|
|
1914
|
+
return this.eb.exists(this.eb.selectFrom(import_kysely3.sql`JSON_TABLE(${receiver}, '$[*]' COLUMNS(value JSON PATH '$'))`.as("$items")).select(this.eb.lit(1).as("_")).where(buildFilter(this.eb.ref("$items.value"))));
|
|
1903
1915
|
}
|
|
1904
1916
|
getStringCasingBehavior() {
|
|
1905
1917
|
return {
|
|
@@ -2156,7 +2168,7 @@ var PostgresCrudDialect = class _PostgresCrudDialect extends LateralJoinDialectB
|
|
|
2156
2168
|
buildJsonArrayExistsPredicate(receiver, buildFilter) {
|
|
2157
2169
|
return this.eb.exists(this.eb.selectFrom(this.eb.fn("jsonb_array_elements", [
|
|
2158
2170
|
receiver
|
|
2159
|
-
]).as("$items")).select(this.eb.lit(1).as("
|
|
2171
|
+
]).as("$items")).select(this.eb.lit(1).as("_")).where(buildFilter(this.eb.ref("$items.value"))));
|
|
2160
2172
|
}
|
|
2161
2173
|
getSqlType(zmodelType) {
|
|
2162
2174
|
if (isEnum(this.schema, zmodelType)) {
|
|
@@ -2315,14 +2327,14 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
2315
2327
|
const relationFieldDef = requireField(this.schema, model, relationField);
|
|
2316
2328
|
const relationModel = relationFieldDef.type;
|
|
2317
2329
|
const relationModelDef = requireModel(this.schema, relationModel);
|
|
2318
|
-
const subQueryName = `${parentAlias}$${relationField}
|
|
2330
|
+
const subQueryName = tmpAlias(`${parentAlias}$${relationField}`);
|
|
2319
2331
|
let tbl;
|
|
2320
2332
|
if (this.canJoinWithoutNestedSelect(relationModelDef, payload)) {
|
|
2321
2333
|
tbl = this.buildModelSelect(relationModel, subQueryName, payload, false);
|
|
2322
2334
|
tbl = this.buildRelationJoinFilter(tbl, model, relationField, subQueryName, parentAlias);
|
|
2323
2335
|
} else {
|
|
2324
2336
|
tbl = eb.selectFrom(() => {
|
|
2325
|
-
const selectModelAlias = `${parentAlias}$${relationField}$sub
|
|
2337
|
+
const selectModelAlias = tmpAlias(`${parentAlias}$${relationField}$sub`);
|
|
2326
2338
|
let selectModelQuery = this.buildModelSelect(relationModel, selectModelAlias, payload, true);
|
|
2327
2339
|
selectModelQuery = this.buildRelationJoinFilter(selectModelQuery, model, relationField, selectModelAlias, parentAlias);
|
|
2328
2340
|
return selectModelQuery.as(subQueryName);
|
|
@@ -2346,7 +2358,7 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
2346
2358
|
} else if (payload.select) {
|
|
2347
2359
|
objArgs.push(...Object.entries(payload.select).filter(([, value]) => value).map(([field, value]) => {
|
|
2348
2360
|
if (field === "_count") {
|
|
2349
|
-
const subJson = this.buildCountJson(relationModel, eb, `${parentAlias}$${relationField}
|
|
2361
|
+
const subJson = this.buildCountJson(relationModel, eb, tmpAlias(`${parentAlias}$${relationField}`), value);
|
|
2350
2362
|
return [
|
|
2351
2363
|
import_kysely5.sql.lit(field),
|
|
2352
2364
|
subJson
|
|
@@ -2354,7 +2366,7 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
2354
2366
|
} else {
|
|
2355
2367
|
const fieldDef = requireField(this.schema, relationModel, field);
|
|
2356
2368
|
if (fieldDef.relation) {
|
|
2357
|
-
const subJson = this.buildRelationJSON(relationModel, eb, field, `${parentAlias}$${relationField}
|
|
2369
|
+
const subJson = this.buildRelationJSON(relationModel, eb, field, tmpAlias(`${parentAlias}$${relationField}`), value);
|
|
2358
2370
|
return [
|
|
2359
2371
|
import_kysely5.sql.lit(field),
|
|
2360
2372
|
subJson
|
|
@@ -2370,7 +2382,7 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
2370
2382
|
}
|
|
2371
2383
|
if (typeof payload === "object" && payload.include && typeof payload.include === "object") {
|
|
2372
2384
|
objArgs.push(...Object.entries(payload.include).filter(([, value]) => value).map(([field, value]) => {
|
|
2373
|
-
const subJson = this.buildRelationJSON(relationModel, eb, field, `${parentAlias}$${relationField}
|
|
2385
|
+
const subJson = this.buildRelationJSON(relationModel, eb, field, tmpAlias(`${parentAlias}$${relationField}`), value);
|
|
2374
2386
|
return [
|
|
2375
2387
|
import_kysely5.sql.lit(field),
|
|
2376
2388
|
subJson
|
|
@@ -2447,7 +2459,7 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
2447
2459
|
buildJsonArrayExistsPredicate(receiver, buildFilter) {
|
|
2448
2460
|
return this.eb.exists(this.eb.selectFrom(this.eb.fn("json_each", [
|
|
2449
2461
|
receiver
|
|
2450
|
-
]).as("$items")).select(this.eb.lit(1).as("
|
|
2462
|
+
]).as("$items")).select(this.eb.lit(1).as("_")).where(buildFilter(this.eb.ref("$items.value"))));
|
|
2451
2463
|
}
|
|
2452
2464
|
buildArrayLength(array) {
|
|
2453
2465
|
return this.eb.fn("json_array_length", [
|
|
@@ -2629,7 +2641,7 @@ var BaseOperationHandler = class {
|
|
|
2629
2641
|
});
|
|
2630
2642
|
}
|
|
2631
2643
|
async existsNonUnique(kysely, model, filter) {
|
|
2632
|
-
const query = kysely.selectNoFrom((eb) => eb.exists(this.dialect.buildSelectModel(model, model).select(import_kysely6.sql.lit(1).as("
|
|
2644
|
+
const query = kysely.selectNoFrom((eb) => eb.exists(this.dialect.buildSelectModel(model, model).select(import_kysely6.sql.lit(1).as("_")).where(() => this.dialect.buildFilter(model, model, filter))).as("$exists")).modifyEnd(this.makeContextComment({
|
|
2633
2645
|
model,
|
|
2634
2646
|
operation: "read"
|
|
2635
2647
|
}));
|
|
@@ -2641,7 +2653,7 @@ var BaseOperationHandler = class {
|
|
|
2641
2653
|
} catch (err) {
|
|
2642
2654
|
throw createDBQueryError(`Failed to execute query: ${err}`, err, compiled.sql, compiled.parameters);
|
|
2643
2655
|
}
|
|
2644
|
-
return !!result[0]
|
|
2656
|
+
return !!result[0]?.$exists;
|
|
2645
2657
|
}
|
|
2646
2658
|
async read(kysely, model, args) {
|
|
2647
2659
|
let query = this.dialect.buildSelectModel(model, model);
|
|
@@ -3238,7 +3250,7 @@ var BaseOperationHandler = class {
|
|
|
3238
3250
|
if (modelDef.baseModel) {
|
|
3239
3251
|
const baseUpdateResult = await this.processBaseModelUpdate(kysely, modelDef.baseModel, combinedWhere, finalData, throwIfNotFound);
|
|
3240
3252
|
finalData = baseUpdateResult.remainingFields;
|
|
3241
|
-
combinedWhere = baseUpdateResult.baseEntity;
|
|
3253
|
+
combinedWhere = baseUpdateResult.baseEntity ? getIdValues(this.schema, modelDef.baseModel, baseUpdateResult.baseEntity) : baseUpdateResult.baseEntity;
|
|
3242
3254
|
if (baseUpdateResult.baseEntity) {
|
|
3243
3255
|
for (const [key, value] of Object.entries(baseUpdateResult.baseEntity)) {
|
|
3244
3256
|
if (key in thisEntity) {
|
|
@@ -4635,11 +4647,9 @@ var UpdateOperationHandler = class extends BaseOperationHandler {
|
|
|
4635
4647
|
}
|
|
4636
4648
|
};
|
|
4637
4649
|
|
|
4638
|
-
// src/client/crud/validator/
|
|
4650
|
+
// src/client/crud/validator/validator.ts
|
|
4639
4651
|
var import_common_helpers9 = require("@zenstackhq/common-helpers");
|
|
4640
|
-
var import_decimal5 = __toESM(require("decimal.js"), 1);
|
|
4641
4652
|
var import_ts_pattern14 = require("ts-pattern");
|
|
4642
|
-
var import_zod2 = require("zod");
|
|
4643
4653
|
|
|
4644
4654
|
// src/utils/zod-utils.ts
|
|
4645
4655
|
var import_v4 = require("zod-validation-error/v4");
|
|
@@ -4648,7 +4658,14 @@ function formatError(error) {
|
|
|
4648
4658
|
}
|
|
4649
4659
|
__name(formatError, "formatError");
|
|
4650
4660
|
|
|
4651
|
-
// src/client/
|
|
4661
|
+
// src/client/zod/factory.ts
|
|
4662
|
+
var import_common_helpers8 = require("@zenstackhq/common-helpers");
|
|
4663
|
+
var import_zod = require("@zenstackhq/zod");
|
|
4664
|
+
var import_decimal4 = __toESM(require("decimal.js"), 1);
|
|
4665
|
+
var import_ts_pattern13 = require("ts-pattern");
|
|
4666
|
+
var import_zod2 = require("zod");
|
|
4667
|
+
|
|
4668
|
+
// src/client/zod/cache-decorator.ts
|
|
4652
4669
|
var import_json_stable_stringify = __toESM(require("json-stable-stringify"), 1);
|
|
4653
4670
|
function cache() {
|
|
4654
4671
|
return function(_target, propertyKey, descriptor) {
|
|
@@ -4680,371 +4697,7 @@ function cache() {
|
|
|
4680
4697
|
}
|
|
4681
4698
|
__name(cache, "cache");
|
|
4682
4699
|
|
|
4683
|
-
// src/client/
|
|
4684
|
-
var import_common_helpers8 = require("@zenstackhq/common-helpers");
|
|
4685
|
-
var import_decimal4 = __toESM(require("decimal.js"), 1);
|
|
4686
|
-
var import_ts_pattern13 = require("ts-pattern");
|
|
4687
|
-
var import_zod = require("zod");
|
|
4688
|
-
var import_v3 = require("zod/v3");
|
|
4689
|
-
function getArgValue(expr) {
|
|
4690
|
-
if (!expr || !schema_exports.ExpressionUtils.isLiteral(expr)) {
|
|
4691
|
-
return void 0;
|
|
4692
|
-
}
|
|
4693
|
-
return expr.value;
|
|
4694
|
-
}
|
|
4695
|
-
__name(getArgValue, "getArgValue");
|
|
4696
|
-
function addStringValidation(schema, attributes) {
|
|
4697
|
-
if (!attributes || attributes.length === 0) {
|
|
4698
|
-
return schema;
|
|
4699
|
-
}
|
|
4700
|
-
let result = schema;
|
|
4701
|
-
for (const attr of attributes) {
|
|
4702
|
-
(0, import_ts_pattern13.match)(attr.name).with("@length", () => {
|
|
4703
|
-
const min = getArgValue(attr.args?.[0]?.value);
|
|
4704
|
-
if (min !== void 0) {
|
|
4705
|
-
result = result.min(min);
|
|
4706
|
-
}
|
|
4707
|
-
const max = getArgValue(attr.args?.[1]?.value);
|
|
4708
|
-
if (max !== void 0) {
|
|
4709
|
-
result = result.max(max);
|
|
4710
|
-
}
|
|
4711
|
-
}).with("@startsWith", () => {
|
|
4712
|
-
const value = getArgValue(attr.args?.[0]?.value);
|
|
4713
|
-
if (value !== void 0) {
|
|
4714
|
-
result = result.startsWith(value);
|
|
4715
|
-
}
|
|
4716
|
-
}).with("@endsWith", () => {
|
|
4717
|
-
const value = getArgValue(attr.args?.[0]?.value);
|
|
4718
|
-
if (value !== void 0) {
|
|
4719
|
-
result = result.endsWith(value);
|
|
4720
|
-
}
|
|
4721
|
-
}).with("@contains", () => {
|
|
4722
|
-
const value = getArgValue(attr.args?.[0]?.value);
|
|
4723
|
-
if (value !== void 0) {
|
|
4724
|
-
result = result.includes(value);
|
|
4725
|
-
}
|
|
4726
|
-
}).with("@regex", () => {
|
|
4727
|
-
const pattern = getArgValue(attr.args?.[0]?.value);
|
|
4728
|
-
if (pattern !== void 0) {
|
|
4729
|
-
result = result.regex(new RegExp(pattern));
|
|
4730
|
-
}
|
|
4731
|
-
}).with("@email", () => {
|
|
4732
|
-
result = result.email();
|
|
4733
|
-
}).with("@datetime", () => {
|
|
4734
|
-
result = result.datetime();
|
|
4735
|
-
}).with("@url", () => {
|
|
4736
|
-
result = result.url();
|
|
4737
|
-
}).with("@trim", () => {
|
|
4738
|
-
result = result.trim();
|
|
4739
|
-
}).with("@lower", () => {
|
|
4740
|
-
result = result.toLowerCase();
|
|
4741
|
-
}).with("@upper", () => {
|
|
4742
|
-
result = result.toUpperCase();
|
|
4743
|
-
});
|
|
4744
|
-
}
|
|
4745
|
-
return result;
|
|
4746
|
-
}
|
|
4747
|
-
__name(addStringValidation, "addStringValidation");
|
|
4748
|
-
function addNumberValidation(schema, attributes) {
|
|
4749
|
-
if (!attributes || attributes.length === 0) {
|
|
4750
|
-
return schema;
|
|
4751
|
-
}
|
|
4752
|
-
let result = schema;
|
|
4753
|
-
for (const attr of attributes) {
|
|
4754
|
-
const val = getArgValue(attr.args?.[0]?.value);
|
|
4755
|
-
if (val === void 0) {
|
|
4756
|
-
continue;
|
|
4757
|
-
}
|
|
4758
|
-
(0, import_ts_pattern13.match)(attr.name).with("@gt", () => {
|
|
4759
|
-
result = result.gt(val);
|
|
4760
|
-
}).with("@gte", () => {
|
|
4761
|
-
result = result.gte(val);
|
|
4762
|
-
}).with("@lt", () => {
|
|
4763
|
-
result = result.lt(val);
|
|
4764
|
-
}).with("@lte", () => {
|
|
4765
|
-
result = result.lte(val);
|
|
4766
|
-
});
|
|
4767
|
-
}
|
|
4768
|
-
return result;
|
|
4769
|
-
}
|
|
4770
|
-
__name(addNumberValidation, "addNumberValidation");
|
|
4771
|
-
function addBigIntValidation(schema, attributes) {
|
|
4772
|
-
if (!attributes || attributes.length === 0) {
|
|
4773
|
-
return schema;
|
|
4774
|
-
}
|
|
4775
|
-
let result = schema;
|
|
4776
|
-
for (const attr of attributes) {
|
|
4777
|
-
const val = getArgValue(attr.args?.[0]?.value);
|
|
4778
|
-
if (val === void 0) {
|
|
4779
|
-
continue;
|
|
4780
|
-
}
|
|
4781
|
-
(0, import_ts_pattern13.match)(attr.name).with("@gt", () => {
|
|
4782
|
-
result = result.gt(BigInt(val));
|
|
4783
|
-
}).with("@gte", () => {
|
|
4784
|
-
result = result.gte(BigInt(val));
|
|
4785
|
-
}).with("@lt", () => {
|
|
4786
|
-
result = result.lt(BigInt(val));
|
|
4787
|
-
}).with("@lte", () => {
|
|
4788
|
-
result = result.lte(BigInt(val));
|
|
4789
|
-
});
|
|
4790
|
-
}
|
|
4791
|
-
return result;
|
|
4792
|
-
}
|
|
4793
|
-
__name(addBigIntValidation, "addBigIntValidation");
|
|
4794
|
-
function addDecimalValidation(schema, attributes, addExtraValidation) {
|
|
4795
|
-
let result = schema;
|
|
4796
|
-
if (schema instanceof import_zod.z.ZodString) {
|
|
4797
|
-
result = schema.superRefine((v, ctx) => {
|
|
4798
|
-
try {
|
|
4799
|
-
new import_decimal4.default(v);
|
|
4800
|
-
} catch (err) {
|
|
4801
|
-
ctx.addIssue({
|
|
4802
|
-
code: import_zod.z.ZodIssueCode.custom,
|
|
4803
|
-
message: `Invalid decimal: ${err}`
|
|
4804
|
-
});
|
|
4805
|
-
}
|
|
4806
|
-
}).transform((val) => new import_decimal4.default(val));
|
|
4807
|
-
}
|
|
4808
|
-
function refine(schema2, op, value) {
|
|
4809
|
-
return schema2.superRefine((v, ctx) => {
|
|
4810
|
-
const base = import_zod.z.number();
|
|
4811
|
-
const { error } = base[op](value).safeParse(v.toNumber());
|
|
4812
|
-
error?.issues.forEach((issue) => {
|
|
4813
|
-
if (op === "gt" || op === "gte") {
|
|
4814
|
-
ctx.addIssue({
|
|
4815
|
-
code: import_v3.ZodIssueCode.too_small,
|
|
4816
|
-
origin: "number",
|
|
4817
|
-
minimum: value,
|
|
4818
|
-
type: "decimal",
|
|
4819
|
-
inclusive: op === "gte",
|
|
4820
|
-
message: issue.message
|
|
4821
|
-
});
|
|
4822
|
-
} else {
|
|
4823
|
-
ctx.addIssue({
|
|
4824
|
-
code: import_v3.ZodIssueCode.too_big,
|
|
4825
|
-
origin: "number",
|
|
4826
|
-
maximum: value,
|
|
4827
|
-
type: "decimal",
|
|
4828
|
-
inclusive: op === "lte",
|
|
4829
|
-
message: issue.message
|
|
4830
|
-
});
|
|
4831
|
-
}
|
|
4832
|
-
});
|
|
4833
|
-
});
|
|
4834
|
-
}
|
|
4835
|
-
__name(refine, "refine");
|
|
4836
|
-
if (attributes && addExtraValidation) {
|
|
4837
|
-
for (const attr of attributes) {
|
|
4838
|
-
const val = getArgValue(attr.args?.[0]?.value);
|
|
4839
|
-
if (val === void 0) {
|
|
4840
|
-
continue;
|
|
4841
|
-
}
|
|
4842
|
-
(0, import_ts_pattern13.match)(attr.name).with("@gt", () => {
|
|
4843
|
-
result = refine(result, "gt", val);
|
|
4844
|
-
}).with("@gte", () => {
|
|
4845
|
-
result = refine(result, "gte", val);
|
|
4846
|
-
}).with("@lt", () => {
|
|
4847
|
-
result = refine(result, "lt", val);
|
|
4848
|
-
}).with("@lte", () => {
|
|
4849
|
-
result = refine(result, "lte", val);
|
|
4850
|
-
});
|
|
4851
|
-
}
|
|
4852
|
-
}
|
|
4853
|
-
return result;
|
|
4854
|
-
}
|
|
4855
|
-
__name(addDecimalValidation, "addDecimalValidation");
|
|
4856
|
-
function addListValidation(schema, attributes) {
|
|
4857
|
-
if (!attributes || attributes.length === 0) {
|
|
4858
|
-
return schema;
|
|
4859
|
-
}
|
|
4860
|
-
let result = schema;
|
|
4861
|
-
for (const attr of attributes) {
|
|
4862
|
-
(0, import_ts_pattern13.match)(attr.name).with("@length", () => {
|
|
4863
|
-
const min = getArgValue(attr.args?.[0]?.value);
|
|
4864
|
-
if (min !== void 0) {
|
|
4865
|
-
result = result.min(min);
|
|
4866
|
-
}
|
|
4867
|
-
const max = getArgValue(attr.args?.[1]?.value);
|
|
4868
|
-
if (max !== void 0) {
|
|
4869
|
-
result = result.max(max);
|
|
4870
|
-
}
|
|
4871
|
-
}).otherwise(() => {
|
|
4872
|
-
});
|
|
4873
|
-
}
|
|
4874
|
-
return result;
|
|
4875
|
-
}
|
|
4876
|
-
__name(addListValidation, "addListValidation");
|
|
4877
|
-
function addCustomValidation(schema, attributes) {
|
|
4878
|
-
const attrs = attributes?.filter((a) => a.name === "@@validate");
|
|
4879
|
-
if (!attrs || attrs.length === 0) {
|
|
4880
|
-
return schema;
|
|
4881
|
-
}
|
|
4882
|
-
let result = schema;
|
|
4883
|
-
for (const attr of attrs) {
|
|
4884
|
-
const expr = attr.args?.[0]?.value;
|
|
4885
|
-
if (!expr) {
|
|
4886
|
-
continue;
|
|
4887
|
-
}
|
|
4888
|
-
const message = getArgValue(attr.args?.[1]?.value);
|
|
4889
|
-
const pathExpr = attr.args?.[2]?.value;
|
|
4890
|
-
let path = void 0;
|
|
4891
|
-
if (pathExpr && schema_exports.ExpressionUtils.isArray(pathExpr)) {
|
|
4892
|
-
path = pathExpr.items.map((e) => schema_exports.ExpressionUtils.getLiteralValue(e));
|
|
4893
|
-
}
|
|
4894
|
-
result = applyValidation(result, expr, message, path);
|
|
4895
|
-
}
|
|
4896
|
-
return result;
|
|
4897
|
-
}
|
|
4898
|
-
__name(addCustomValidation, "addCustomValidation");
|
|
4899
|
-
function applyValidation(schema, expr, message, path) {
|
|
4900
|
-
const options = {};
|
|
4901
|
-
if (message) {
|
|
4902
|
-
options.error = message;
|
|
4903
|
-
}
|
|
4904
|
-
if (path) {
|
|
4905
|
-
options.path = path;
|
|
4906
|
-
}
|
|
4907
|
-
return schema.refine((data) => Boolean(evalExpression(data, expr)), options);
|
|
4908
|
-
}
|
|
4909
|
-
__name(applyValidation, "applyValidation");
|
|
4910
|
-
function evalExpression(data, expr) {
|
|
4911
|
-
return (0, import_ts_pattern13.match)(expr).with({
|
|
4912
|
-
kind: "literal"
|
|
4913
|
-
}, (e) => e.value).with({
|
|
4914
|
-
kind: "array"
|
|
4915
|
-
}, (e) => e.items.map((item) => evalExpression(data, item))).with({
|
|
4916
|
-
kind: "field"
|
|
4917
|
-
}, (e) => evalField(data, e)).with({
|
|
4918
|
-
kind: "member"
|
|
4919
|
-
}, (e) => evalMember(data, e)).with({
|
|
4920
|
-
kind: "unary"
|
|
4921
|
-
}, (e) => evalUnary(data, e)).with({
|
|
4922
|
-
kind: "binary"
|
|
4923
|
-
}, (e) => evalBinary(data, e)).with({
|
|
4924
|
-
kind: "call"
|
|
4925
|
-
}, (e) => evalCall(data, e)).with({
|
|
4926
|
-
kind: "this"
|
|
4927
|
-
}, () => data ?? null).with({
|
|
4928
|
-
kind: "null"
|
|
4929
|
-
}, () => null).with({
|
|
4930
|
-
kind: "binding"
|
|
4931
|
-
}, () => {
|
|
4932
|
-
throw new Error("Binding expression is not supported in validation expressions");
|
|
4933
|
-
}).exhaustive();
|
|
4934
|
-
}
|
|
4935
|
-
__name(evalExpression, "evalExpression");
|
|
4936
|
-
function evalField(data, e) {
|
|
4937
|
-
return data?.[e.field] ?? null;
|
|
4938
|
-
}
|
|
4939
|
-
__name(evalField, "evalField");
|
|
4940
|
-
function evalUnary(data, expr) {
|
|
4941
|
-
const operand = evalExpression(data, expr.operand);
|
|
4942
|
-
switch (expr.op) {
|
|
4943
|
-
case "!":
|
|
4944
|
-
return !operand;
|
|
4945
|
-
default:
|
|
4946
|
-
throw new Error(`Unsupported unary operator: ${expr.op}`);
|
|
4947
|
-
}
|
|
4948
|
-
}
|
|
4949
|
-
__name(evalUnary, "evalUnary");
|
|
4950
|
-
function evalBinary(data, expr) {
|
|
4951
|
-
const left = evalExpression(data, expr.left);
|
|
4952
|
-
const right = evalExpression(data, expr.right);
|
|
4953
|
-
return (0, import_ts_pattern13.match)(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("?", () => {
|
|
4954
|
-
if (!Array.isArray(left)) {
|
|
4955
|
-
return false;
|
|
4956
|
-
}
|
|
4957
|
-
return left.some((item) => item === right);
|
|
4958
|
-
}).with("!", () => {
|
|
4959
|
-
if (!Array.isArray(left)) {
|
|
4960
|
-
return false;
|
|
4961
|
-
}
|
|
4962
|
-
return left.every((item) => item === right);
|
|
4963
|
-
}).with("^", () => {
|
|
4964
|
-
if (!Array.isArray(left)) {
|
|
4965
|
-
return false;
|
|
4966
|
-
}
|
|
4967
|
-
return !left.some((item) => item === right);
|
|
4968
|
-
}).with("in", () => {
|
|
4969
|
-
if (!Array.isArray(right)) {
|
|
4970
|
-
return false;
|
|
4971
|
-
}
|
|
4972
|
-
return right.includes(left);
|
|
4973
|
-
}).exhaustive();
|
|
4974
|
-
}
|
|
4975
|
-
__name(evalBinary, "evalBinary");
|
|
4976
|
-
function evalMember(data, expr) {
|
|
4977
|
-
let result = evalExpression(data, expr.receiver);
|
|
4978
|
-
for (const member of expr.members) {
|
|
4979
|
-
if (!result || typeof result !== "object") {
|
|
4980
|
-
return void 0;
|
|
4981
|
-
}
|
|
4982
|
-
result = result[member];
|
|
4983
|
-
}
|
|
4984
|
-
return result ?? null;
|
|
4985
|
-
}
|
|
4986
|
-
__name(evalMember, "evalMember");
|
|
4987
|
-
function evalCall(data, expr) {
|
|
4988
|
-
const fieldArg = expr.args?.[0] ? evalExpression(data, expr.args[0]) : void 0;
|
|
4989
|
-
return (0, import_ts_pattern13.match)(expr.function).with("length", (f) => {
|
|
4990
|
-
if (fieldArg === void 0 || fieldArg === null) {
|
|
4991
|
-
return false;
|
|
4992
|
-
}
|
|
4993
|
-
(0, import_common_helpers8.invariant)(typeof fieldArg === "string" || Array.isArray(fieldArg), `"${f}" first argument must be a string or a list`);
|
|
4994
|
-
return fieldArg.length;
|
|
4995
|
-
}).with(import_ts_pattern13.P.union("startsWith", "endsWith", "contains"), (f) => {
|
|
4996
|
-
if (fieldArg === void 0 || fieldArg === null) {
|
|
4997
|
-
return false;
|
|
4998
|
-
}
|
|
4999
|
-
(0, import_common_helpers8.invariant)(typeof fieldArg === "string", `"${f}" first argument must be a string`);
|
|
5000
|
-
(0, import_common_helpers8.invariant)(expr.args?.[1], `"${f}" requires a search argument`);
|
|
5001
|
-
const search2 = getArgValue(expr.args?.[1]);
|
|
5002
|
-
const caseInsensitive = getArgValue(expr.args?.[2]) ?? false;
|
|
5003
|
-
const matcher = /* @__PURE__ */ __name((x, y) => (0, import_ts_pattern13.match)(f).with("startsWith", () => x.startsWith(y)).with("endsWith", () => x.endsWith(y)).with("contains", () => x.includes(y)).exhaustive(), "matcher");
|
|
5004
|
-
return caseInsensitive ? matcher(fieldArg.toLowerCase(), search2.toLowerCase()) : matcher(fieldArg, search2);
|
|
5005
|
-
}).with("regex", (f) => {
|
|
5006
|
-
if (fieldArg === void 0 || fieldArg === null) {
|
|
5007
|
-
return false;
|
|
5008
|
-
}
|
|
5009
|
-
(0, import_common_helpers8.invariant)(typeof fieldArg === "string", `"${f}" first argument must be a string`);
|
|
5010
|
-
const pattern = getArgValue(expr.args?.[1]);
|
|
5011
|
-
(0, import_common_helpers8.invariant)(pattern !== void 0, `"${f}" requires a pattern argument`);
|
|
5012
|
-
return new RegExp(pattern).test(fieldArg);
|
|
5013
|
-
}).with(import_ts_pattern13.P.union("isEmail", "isUrl", "isDateTime"), (f) => {
|
|
5014
|
-
if (fieldArg === void 0 || fieldArg === null) {
|
|
5015
|
-
return false;
|
|
5016
|
-
}
|
|
5017
|
-
(0, import_common_helpers8.invariant)(typeof fieldArg === "string", `"${f}" first argument must be a string`);
|
|
5018
|
-
const fn = (0, import_ts_pattern13.match)(f).with("isEmail", () => "email").with("isUrl", () => "url").with("isDateTime", () => "datetime").exhaustive();
|
|
5019
|
-
return import_zod.z.string()[fn]().safeParse(fieldArg).success;
|
|
5020
|
-
}).with(import_ts_pattern13.P.union("has", "hasEvery", "hasSome"), (f) => {
|
|
5021
|
-
(0, import_common_helpers8.invariant)(expr.args?.[1], `${f} requires a search argument`);
|
|
5022
|
-
if (fieldArg === void 0 || fieldArg === null) {
|
|
5023
|
-
return false;
|
|
5024
|
-
}
|
|
5025
|
-
(0, import_common_helpers8.invariant)(Array.isArray(fieldArg), `"${f}" first argument must be an array field`);
|
|
5026
|
-
const search2 = evalExpression(data, expr.args?.[1]);
|
|
5027
|
-
const matcher = /* @__PURE__ */ __name((x, y) => (0, import_ts_pattern13.match)(f).with("has", () => x.some((item) => item === y)).with("hasEvery", () => {
|
|
5028
|
-
(0, import_common_helpers8.invariant)(Array.isArray(y), "hasEvery second argument must be an array");
|
|
5029
|
-
return y.every((v) => x.some((item) => item === v));
|
|
5030
|
-
}).with("hasSome", () => {
|
|
5031
|
-
(0, import_common_helpers8.invariant)(Array.isArray(y), "hasSome second argument must be an array");
|
|
5032
|
-
return y.some((v) => x.some((item) => item === v));
|
|
5033
|
-
}).exhaustive(), "matcher");
|
|
5034
|
-
return matcher(fieldArg, search2);
|
|
5035
|
-
}).with("isEmpty", (f) => {
|
|
5036
|
-
if (fieldArg === void 0 || fieldArg === null) {
|
|
5037
|
-
return false;
|
|
5038
|
-
}
|
|
5039
|
-
(0, import_common_helpers8.invariant)(Array.isArray(fieldArg), `"${f}" first argument must be an array field`);
|
|
5040
|
-
return fieldArg.length === 0;
|
|
5041
|
-
}).otherwise(() => {
|
|
5042
|
-
throw createNotSupportedError(`Unsupported function "${expr.function}"`);
|
|
5043
|
-
});
|
|
5044
|
-
}
|
|
5045
|
-
__name(evalCall, "evalCall");
|
|
5046
|
-
|
|
5047
|
-
// src/client/crud/validator/index.ts
|
|
4700
|
+
// src/client/zod/factory.ts
|
|
5048
4701
|
function _ts_decorate(decorators, target, key, desc) {
|
|
5049
4702
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
5050
4703
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -5056,303 +4709,185 @@ function _ts_metadata(k, v) {
|
|
|
5056
4709
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
5057
4710
|
}
|
|
5058
4711
|
__name(_ts_metadata, "_ts_metadata");
|
|
5059
|
-
|
|
4712
|
+
function createQuerySchemaFactory(clientOrSchema, options) {
|
|
4713
|
+
return new ZodSchemaFactory(clientOrSchema, options);
|
|
4714
|
+
}
|
|
4715
|
+
__name(createQuerySchemaFactory, "createQuerySchemaFactory");
|
|
4716
|
+
var ZodSchemaFactory = class {
|
|
5060
4717
|
static {
|
|
5061
|
-
__name(this, "
|
|
4718
|
+
__name(this, "ZodSchemaFactory");
|
|
5062
4719
|
}
|
|
5063
|
-
client;
|
|
5064
4720
|
schemaCache = /* @__PURE__ */ new Map();
|
|
5065
4721
|
allFilterKinds = [
|
|
5066
4722
|
...new Set(Object.values(FILTER_PROPERTY_TO_KIND))
|
|
5067
4723
|
];
|
|
5068
|
-
|
|
5069
|
-
|
|
5070
|
-
|
|
5071
|
-
|
|
5072
|
-
|
|
4724
|
+
schema;
|
|
4725
|
+
options;
|
|
4726
|
+
constructor(clientOrSchema, options) {
|
|
4727
|
+
if ("$schema" in clientOrSchema) {
|
|
4728
|
+
this.schema = clientOrSchema.$schema;
|
|
4729
|
+
this.options = clientOrSchema.$options;
|
|
4730
|
+
} else {
|
|
4731
|
+
this.schema = clientOrSchema;
|
|
4732
|
+
this.options = options || {};
|
|
4733
|
+
}
|
|
5073
4734
|
}
|
|
5074
|
-
get
|
|
5075
|
-
return this.
|
|
4735
|
+
get plugins() {
|
|
4736
|
+
return this.options.plugins ?? [];
|
|
5076
4737
|
}
|
|
5077
4738
|
get extraValidationsEnabled() {
|
|
5078
|
-
return this.
|
|
5079
|
-
}
|
|
5080
|
-
// #region Entry points
|
|
5081
|
-
validateFindArgs(model, args, operation) {
|
|
5082
|
-
return this.validate(model, operation, (model2) => this.makeFindSchema(model2, operation), args);
|
|
5083
|
-
}
|
|
5084
|
-
validateExistsArgs(model, args) {
|
|
5085
|
-
return this.validate(model, "exists", (model2) => this.makeExistsSchema(model2), args);
|
|
4739
|
+
return this.options.validateInput !== false;
|
|
5086
4740
|
}
|
|
5087
|
-
|
|
5088
|
-
return
|
|
4741
|
+
shouldIncludeRelations(options) {
|
|
4742
|
+
return options?.relationDepth === void 0 || options.relationDepth > 0;
|
|
5089
4743
|
}
|
|
5090
|
-
|
|
5091
|
-
|
|
4744
|
+
nextOptions(options) {
|
|
4745
|
+
if (!options) return void 0;
|
|
4746
|
+
if (options.relationDepth === void 0) return options;
|
|
4747
|
+
return {
|
|
4748
|
+
...options,
|
|
4749
|
+
relationDepth: options.relationDepth - 1
|
|
4750
|
+
};
|
|
5092
4751
|
}
|
|
5093
|
-
|
|
5094
|
-
|
|
4752
|
+
// #region Cache Management
|
|
4753
|
+
// @ts-ignore
|
|
4754
|
+
getCache(cacheKey) {
|
|
4755
|
+
return this.schemaCache.get(cacheKey);
|
|
5095
4756
|
}
|
|
5096
|
-
|
|
5097
|
-
|
|
4757
|
+
// @ts-ignore
|
|
4758
|
+
setCache(cacheKey, schema) {
|
|
4759
|
+
return this.schemaCache.set(cacheKey, schema);
|
|
5098
4760
|
}
|
|
5099
|
-
|
|
5100
|
-
|
|
4761
|
+
// @ts-ignore
|
|
4762
|
+
printCacheStats(detailed = false) {
|
|
4763
|
+
console.log("Schema cache size:", this.schemaCache.size);
|
|
4764
|
+
if (detailed) {
|
|
4765
|
+
for (const key of this.schemaCache.keys()) {
|
|
4766
|
+
console.log(` ${key}`);
|
|
4767
|
+
}
|
|
4768
|
+
}
|
|
5101
4769
|
}
|
|
5102
|
-
|
|
5103
|
-
|
|
4770
|
+
// #endregion
|
|
4771
|
+
// #region Find
|
|
4772
|
+
makeFindUniqueSchema(model, options) {
|
|
4773
|
+
return this.makeFindSchema(model, "findUnique", options);
|
|
5104
4774
|
}
|
|
5105
|
-
|
|
5106
|
-
return this.
|
|
4775
|
+
makeFindFirstSchema(model, options) {
|
|
4776
|
+
return this.makeFindSchema(model, "findFirst", options);
|
|
5107
4777
|
}
|
|
5108
|
-
|
|
5109
|
-
return this.
|
|
4778
|
+
makeFindManySchema(model, options) {
|
|
4779
|
+
return this.makeFindSchema(model, "findMany", options);
|
|
5110
4780
|
}
|
|
5111
|
-
|
|
5112
|
-
|
|
4781
|
+
makeFindSchema(model, operation, options) {
|
|
4782
|
+
const fields = {};
|
|
4783
|
+
const unique = operation === "findUnique";
|
|
4784
|
+
const findOne = operation === "findUnique" || operation === "findFirst";
|
|
4785
|
+
const where = this.makeWhereSchema(model, unique, false, false, options);
|
|
4786
|
+
if (unique) {
|
|
4787
|
+
fields["where"] = where;
|
|
4788
|
+
} else {
|
|
4789
|
+
fields["where"] = where.optional();
|
|
4790
|
+
}
|
|
4791
|
+
fields["select"] = this.makeSelectSchema(model, options).optional().nullable();
|
|
4792
|
+
fields["include"] = this.makeIncludeSchema(model, options).optional().nullable();
|
|
4793
|
+
fields["omit"] = this.makeOmitSchema(model).optional().nullable();
|
|
4794
|
+
if (!unique) {
|
|
4795
|
+
fields["skip"] = this.makeSkipSchema().optional();
|
|
4796
|
+
if (findOne) {
|
|
4797
|
+
fields["take"] = import_zod2.z.literal(1).optional();
|
|
4798
|
+
} else {
|
|
4799
|
+
fields["take"] = this.makeTakeSchema().optional();
|
|
4800
|
+
}
|
|
4801
|
+
fields["orderBy"] = this.orArray(this.makeOrderBySchema(model, true, false, options), true).optional();
|
|
4802
|
+
fields["cursor"] = this.makeCursorSchema(model, options).optional();
|
|
4803
|
+
fields["distinct"] = this.makeDistinctSchema(model).optional();
|
|
4804
|
+
}
|
|
4805
|
+
const baseSchema = import_zod2.z.strictObject(fields);
|
|
4806
|
+
let result = this.mergePluginArgsSchema(baseSchema, operation);
|
|
4807
|
+
result = this.refineForSelectIncludeMutuallyExclusive(result);
|
|
4808
|
+
result = this.refineForSelectOmitMutuallyExclusive(result);
|
|
4809
|
+
result = this.refineForSelectHasTruthyField(result);
|
|
4810
|
+
if (!unique) {
|
|
4811
|
+
result = result.optional();
|
|
4812
|
+
}
|
|
4813
|
+
return result;
|
|
5113
4814
|
}
|
|
5114
|
-
|
|
5115
|
-
|
|
4815
|
+
makeExistsSchema(model, options) {
|
|
4816
|
+
const baseSchema = import_zod2.z.strictObject({
|
|
4817
|
+
where: this.makeWhereSchema(model, false, false, false, options).optional()
|
|
4818
|
+
});
|
|
4819
|
+
return this.mergePluginArgsSchema(baseSchema, "exists").optional();
|
|
5116
4820
|
}
|
|
5117
|
-
|
|
5118
|
-
|
|
4821
|
+
makeScalarSchema(type, attributes) {
|
|
4822
|
+
if (this.schema.typeDefs && type in this.schema.typeDefs) {
|
|
4823
|
+
return this.makeTypeDefSchema(type);
|
|
4824
|
+
} else if (this.schema.enums && type in this.schema.enums) {
|
|
4825
|
+
return this.makeEnumSchema(type);
|
|
4826
|
+
} else {
|
|
4827
|
+
return (0, import_ts_pattern13.match)(type).with("String", () => this.extraValidationsEnabled ? import_zod.ZodUtils.addStringValidation(import_zod2.z.string(), attributes) : import_zod2.z.string()).with("Int", () => this.extraValidationsEnabled ? import_zod.ZodUtils.addNumberValidation(import_zod2.z.number().int(), attributes) : import_zod2.z.number().int()).with("Float", () => this.extraValidationsEnabled ? import_zod.ZodUtils.addNumberValidation(import_zod2.z.number(), attributes) : import_zod2.z.number()).with("Boolean", () => import_zod2.z.boolean()).with("BigInt", () => import_zod2.z.union([
|
|
4828
|
+
this.extraValidationsEnabled ? import_zod.ZodUtils.addNumberValidation(import_zod2.z.number().int(), attributes) : import_zod2.z.number().int(),
|
|
4829
|
+
this.extraValidationsEnabled ? import_zod.ZodUtils.addBigIntValidation(import_zod2.z.bigint(), attributes) : import_zod2.z.bigint()
|
|
4830
|
+
])).with("Decimal", () => {
|
|
4831
|
+
return import_zod2.z.union([
|
|
4832
|
+
this.extraValidationsEnabled ? import_zod.ZodUtils.addNumberValidation(import_zod2.z.number(), attributes) : import_zod2.z.number(),
|
|
4833
|
+
import_zod.ZodUtils.addDecimalValidation(import_zod2.z.instanceof(import_decimal4.default), attributes, this.extraValidationsEnabled),
|
|
4834
|
+
import_zod.ZodUtils.addDecimalValidation(import_zod2.z.string(), attributes, this.extraValidationsEnabled)
|
|
4835
|
+
]);
|
|
4836
|
+
}).with("DateTime", () => import_zod2.z.union([
|
|
4837
|
+
import_zod2.z.date(),
|
|
4838
|
+
import_zod2.z.iso.datetime()
|
|
4839
|
+
])).with("Bytes", () => import_zod2.z.instanceof(Uint8Array)).with("Json", () => this.makeJsonValueSchema(false, false)).otherwise(() => import_zod2.z.unknown());
|
|
4840
|
+
}
|
|
5119
4841
|
}
|
|
5120
|
-
|
|
5121
|
-
|
|
4842
|
+
makeEnumSchema(_enum) {
|
|
4843
|
+
const enumDef = getEnum(this.schema, _enum);
|
|
4844
|
+
(0, import_common_helpers8.invariant)(enumDef, `Enum "${_enum}" not found in schema`);
|
|
4845
|
+
return import_zod2.z.enum(Object.keys(enumDef.values));
|
|
5122
4846
|
}
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5126
|
-
|
|
5127
|
-
|
|
5128
|
-
|
|
5129
|
-
|
|
5130
|
-
return void 0;
|
|
5131
|
-
}
|
|
5132
|
-
if (params.every((p) => p.optional)) {
|
|
5133
|
-
return void 0;
|
|
5134
|
-
}
|
|
5135
|
-
throw createInvalidInputError("Missing procedure arguments", `$procs.${proc}`);
|
|
5136
|
-
}
|
|
5137
|
-
if (typeof input !== "object" || input === null || Array.isArray(input)) {
|
|
5138
|
-
throw createInvalidInputError("Procedure input must be an object", `$procs.${proc}`);
|
|
5139
|
-
}
|
|
5140
|
-
const envelope = input;
|
|
5141
|
-
const argsPayload = Object.prototype.hasOwnProperty.call(envelope, "args") ? envelope.args : void 0;
|
|
5142
|
-
if (params.length === 0) {
|
|
5143
|
-
if (typeof argsPayload === "undefined") {
|
|
5144
|
-
return input;
|
|
5145
|
-
}
|
|
5146
|
-
if (!argsPayload || typeof argsPayload !== "object" || Array.isArray(argsPayload)) {
|
|
5147
|
-
throw createInvalidInputError("Procedure `args` must be an object", `$procs.${proc}`);
|
|
4847
|
+
makeTypeDefSchema(type) {
|
|
4848
|
+
const typeDef = getTypeDef(this.schema, type);
|
|
4849
|
+
(0, import_common_helpers8.invariant)(typeDef, `Type definition "${type}" not found in schema`);
|
|
4850
|
+
const schema = import_zod2.z.looseObject(Object.fromEntries(Object.entries(typeDef.fields).map(([field, def]) => {
|
|
4851
|
+
let fieldSchema = this.makeScalarSchema(def.type);
|
|
4852
|
+
if (def.array) {
|
|
4853
|
+
fieldSchema = fieldSchema.array();
|
|
5148
4854
|
}
|
|
5149
|
-
if (
|
|
5150
|
-
|
|
4855
|
+
if (def.optional) {
|
|
4856
|
+
fieldSchema = fieldSchema.nullish();
|
|
5151
4857
|
}
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
throw createInvalidInputError("Procedure `args` must be an object", `$procs.${proc}`);
|
|
5162
|
-
}
|
|
5163
|
-
const obj = argsPayload;
|
|
5164
|
-
for (const param of params) {
|
|
5165
|
-
const value = obj[param.name];
|
|
5166
|
-
if (!Object.prototype.hasOwnProperty.call(obj, param.name)) {
|
|
5167
|
-
if (param.optional) {
|
|
5168
|
-
continue;
|
|
5169
|
-
}
|
|
5170
|
-
throw createInvalidInputError(`Missing procedure argument: ${param.name}`, `$procs.${proc}`);
|
|
5171
|
-
}
|
|
5172
|
-
if (typeof value === "undefined") {
|
|
5173
|
-
if (param.optional) {
|
|
5174
|
-
continue;
|
|
5175
|
-
}
|
|
5176
|
-
throw createInvalidInputError(`Invalid procedure argument: ${param.name} is required`, `$procs.${proc}`);
|
|
5177
|
-
}
|
|
5178
|
-
const schema = this.makeProcedureParamSchema(param);
|
|
5179
|
-
const parsed = schema.safeParse(value);
|
|
5180
|
-
if (!parsed.success) {
|
|
5181
|
-
throw createInvalidInputError(`Invalid procedure argument: ${param.name}: ${formatError(parsed.error)}`, `$procs.${proc}`);
|
|
5182
|
-
}
|
|
5183
|
-
}
|
|
5184
|
-
return input;
|
|
5185
|
-
}
|
|
5186
|
-
// #endregion
|
|
5187
|
-
// #region Validation helpers
|
|
5188
|
-
validate(model, operation, getSchema, args) {
|
|
5189
|
-
const schema = getSchema(model);
|
|
5190
|
-
const { error, data } = schema.safeParse(args);
|
|
5191
|
-
if (error) {
|
|
5192
|
-
throw createInvalidInputError(`Invalid ${operation} args for model "${model}": ${formatError(error)}`, model, {
|
|
5193
|
-
cause: error
|
|
5194
|
-
});
|
|
5195
|
-
}
|
|
5196
|
-
return data;
|
|
5197
|
-
}
|
|
5198
|
-
mergePluginArgsSchema(schema, operation) {
|
|
5199
|
-
let result = schema;
|
|
5200
|
-
for (const plugin of this.options.plugins ?? []) {
|
|
5201
|
-
if (plugin.queryArgs) {
|
|
5202
|
-
const pluginSchema = this.getPluginExtQueryArgsSchema(plugin, operation);
|
|
5203
|
-
if (pluginSchema) {
|
|
5204
|
-
result = result.extend(pluginSchema.shape);
|
|
5205
|
-
}
|
|
5206
|
-
}
|
|
5207
|
-
}
|
|
5208
|
-
return result.strict();
|
|
5209
|
-
}
|
|
5210
|
-
getPluginExtQueryArgsSchema(plugin, operation) {
|
|
5211
|
-
if (!plugin.queryArgs) {
|
|
5212
|
-
return void 0;
|
|
5213
|
-
}
|
|
5214
|
-
let result;
|
|
5215
|
-
if (operation in plugin.queryArgs && plugin.queryArgs[operation]) {
|
|
5216
|
-
result = plugin.queryArgs[operation];
|
|
5217
|
-
} else if (operation === "upsert") {
|
|
5218
|
-
const createSchema = "$create" in plugin.queryArgs && plugin.queryArgs["$create"] ? plugin.queryArgs["$create"] : void 0;
|
|
5219
|
-
const updateSchema = "$update" in plugin.queryArgs && plugin.queryArgs["$update"] ? plugin.queryArgs["$update"] : void 0;
|
|
5220
|
-
if (createSchema && updateSchema) {
|
|
5221
|
-
(0, import_common_helpers9.invariant)(createSchema instanceof import_zod2.z.ZodObject, "Plugin extended query args schema must be a Zod object");
|
|
5222
|
-
(0, import_common_helpers9.invariant)(updateSchema instanceof import_zod2.z.ZodObject, "Plugin extended query args schema must be a Zod object");
|
|
5223
|
-
result = createSchema.extend(updateSchema.shape);
|
|
5224
|
-
} else if (createSchema) {
|
|
5225
|
-
result = createSchema;
|
|
5226
|
-
} else if (updateSchema) {
|
|
5227
|
-
result = updateSchema;
|
|
5228
|
-
}
|
|
5229
|
-
} else if (
|
|
5230
|
-
// then comes grouped operations: $create, $read, $update, $delete
|
|
5231
|
-
CoreCreateOperations.includes(operation) && "$create" in plugin.queryArgs && plugin.queryArgs["$create"]
|
|
5232
|
-
) {
|
|
5233
|
-
result = plugin.queryArgs["$create"];
|
|
5234
|
-
} else if (CoreReadOperations.includes(operation) && "$read" in plugin.queryArgs && plugin.queryArgs["$read"]) {
|
|
5235
|
-
result = plugin.queryArgs["$read"];
|
|
5236
|
-
} else if (CoreUpdateOperations.includes(operation) && "$update" in plugin.queryArgs && plugin.queryArgs["$update"]) {
|
|
5237
|
-
result = plugin.queryArgs["$update"];
|
|
5238
|
-
} else if (CoreDeleteOperations.includes(operation) && "$delete" in plugin.queryArgs && plugin.queryArgs["$delete"]) {
|
|
5239
|
-
result = plugin.queryArgs["$delete"];
|
|
5240
|
-
} else if ("$all" in plugin.queryArgs && plugin.queryArgs["$all"]) {
|
|
5241
|
-
result = plugin.queryArgs["$all"];
|
|
5242
|
-
}
|
|
5243
|
-
(0, import_common_helpers9.invariant)(result === void 0 || result instanceof import_zod2.z.ZodObject, "Plugin extended query args schema must be a Zod object");
|
|
5244
|
-
return result;
|
|
5245
|
-
}
|
|
5246
|
-
// #endregion
|
|
5247
|
-
// #region Find
|
|
5248
|
-
makeFindSchema(model, operation) {
|
|
5249
|
-
const fields = {};
|
|
5250
|
-
const unique = operation === "findUnique";
|
|
5251
|
-
const findOne = operation === "findUnique" || operation === "findFirst";
|
|
5252
|
-
const where = this.makeWhereSchema(model, unique);
|
|
5253
|
-
if (unique) {
|
|
5254
|
-
fields["where"] = where;
|
|
5255
|
-
} else {
|
|
5256
|
-
fields["where"] = where.optional();
|
|
5257
|
-
}
|
|
5258
|
-
fields["select"] = this.makeSelectSchema(model).optional().nullable();
|
|
5259
|
-
fields["include"] = this.makeIncludeSchema(model).optional().nullable();
|
|
5260
|
-
fields["omit"] = this.makeOmitSchema(model).optional().nullable();
|
|
5261
|
-
if (!unique) {
|
|
5262
|
-
fields["skip"] = this.makeSkipSchema().optional();
|
|
5263
|
-
if (findOne) {
|
|
5264
|
-
fields["take"] = import_zod2.z.literal(1).optional();
|
|
5265
|
-
} else {
|
|
5266
|
-
fields["take"] = this.makeTakeSchema().optional();
|
|
5267
|
-
}
|
|
5268
|
-
fields["orderBy"] = this.orArray(this.makeOrderBySchema(model, true, false), true).optional();
|
|
5269
|
-
fields["cursor"] = this.makeCursorSchema(model).optional();
|
|
5270
|
-
fields["distinct"] = this.makeDistinctSchema(model).optional();
|
|
5271
|
-
}
|
|
5272
|
-
const baseSchema = import_zod2.z.strictObject(fields);
|
|
5273
|
-
let result = this.mergePluginArgsSchema(baseSchema, operation);
|
|
5274
|
-
result = this.refineForSelectIncludeMutuallyExclusive(result);
|
|
5275
|
-
result = this.refineForSelectOmitMutuallyExclusive(result);
|
|
5276
|
-
if (!unique) {
|
|
5277
|
-
result = result.optional();
|
|
5278
|
-
}
|
|
5279
|
-
return result;
|
|
5280
|
-
}
|
|
5281
|
-
makeExistsSchema(model) {
|
|
5282
|
-
const baseSchema = import_zod2.z.strictObject({
|
|
5283
|
-
where: this.makeWhereSchema(model, false).optional()
|
|
5284
|
-
});
|
|
5285
|
-
return this.mergePluginArgsSchema(baseSchema, "exists").optional();
|
|
5286
|
-
}
|
|
5287
|
-
makeScalarSchema(type, attributes) {
|
|
5288
|
-
if (this.schema.typeDefs && type in this.schema.typeDefs) {
|
|
5289
|
-
return this.makeTypeDefSchema(type);
|
|
5290
|
-
} else if (this.schema.enums && type in this.schema.enums) {
|
|
5291
|
-
return this.makeEnumSchema(type);
|
|
5292
|
-
} else {
|
|
5293
|
-
return (0, import_ts_pattern14.match)(type).with("String", () => this.extraValidationsEnabled ? addStringValidation(import_zod2.z.string(), attributes) : import_zod2.z.string()).with("Int", () => this.extraValidationsEnabled ? addNumberValidation(import_zod2.z.number().int(), attributes) : import_zod2.z.number().int()).with("Float", () => this.extraValidationsEnabled ? addNumberValidation(import_zod2.z.number(), attributes) : import_zod2.z.number()).with("Boolean", () => import_zod2.z.boolean()).with("BigInt", () => import_zod2.z.union([
|
|
5294
|
-
this.extraValidationsEnabled ? addNumberValidation(import_zod2.z.number().int(), attributes) : import_zod2.z.number().int(),
|
|
5295
|
-
this.extraValidationsEnabled ? addBigIntValidation(import_zod2.z.bigint(), attributes) : import_zod2.z.bigint()
|
|
5296
|
-
])).with("Decimal", () => {
|
|
5297
|
-
return import_zod2.z.union([
|
|
5298
|
-
this.extraValidationsEnabled ? addNumberValidation(import_zod2.z.number(), attributes) : import_zod2.z.number(),
|
|
5299
|
-
addDecimalValidation(import_zod2.z.instanceof(import_decimal5.default), attributes, this.extraValidationsEnabled),
|
|
5300
|
-
addDecimalValidation(import_zod2.z.string(), attributes, this.extraValidationsEnabled)
|
|
5301
|
-
]);
|
|
5302
|
-
}).with("DateTime", () => import_zod2.z.union([
|
|
5303
|
-
import_zod2.z.date(),
|
|
5304
|
-
import_zod2.z.iso.datetime()
|
|
5305
|
-
])).with("Bytes", () => import_zod2.z.instanceof(Uint8Array)).with("Json", () => this.makeJsonValueSchema(false, false)).otherwise(() => import_zod2.z.unknown());
|
|
5306
|
-
}
|
|
5307
|
-
}
|
|
5308
|
-
makeEnumSchema(type) {
|
|
5309
|
-
const enumDef = getEnum(this.schema, type);
|
|
5310
|
-
(0, import_common_helpers9.invariant)(enumDef, `Enum "${type}" not found in schema`);
|
|
5311
|
-
return import_zod2.z.enum(Object.keys(enumDef.values));
|
|
5312
|
-
}
|
|
5313
|
-
makeTypeDefSchema(type) {
|
|
5314
|
-
const typeDef = getTypeDef(this.schema, type);
|
|
5315
|
-
(0, import_common_helpers9.invariant)(typeDef, `Type definition "${type}" not found in schema`);
|
|
5316
|
-
const schema = import_zod2.z.looseObject(Object.fromEntries(Object.entries(typeDef.fields).map(([field, def]) => {
|
|
5317
|
-
let fieldSchema = this.makeScalarSchema(def.type);
|
|
5318
|
-
if (def.array) {
|
|
5319
|
-
fieldSchema = fieldSchema.array();
|
|
5320
|
-
}
|
|
5321
|
-
if (def.optional) {
|
|
5322
|
-
fieldSchema = fieldSchema.nullish();
|
|
5323
|
-
}
|
|
5324
|
-
return [
|
|
5325
|
-
field,
|
|
5326
|
-
fieldSchema
|
|
5327
|
-
];
|
|
5328
|
-
})));
|
|
5329
|
-
const finalSchema = import_zod2.z.any().superRefine((value, ctx) => {
|
|
5330
|
-
const parseResult = schema.safeParse(value);
|
|
5331
|
-
if (!parseResult.success) {
|
|
5332
|
-
parseResult.error.issues.forEach((issue) => ctx.addIssue(issue));
|
|
4858
|
+
return [
|
|
4859
|
+
field,
|
|
4860
|
+
fieldSchema
|
|
4861
|
+
];
|
|
4862
|
+
})));
|
|
4863
|
+
const finalSchema = import_zod2.z.any().superRefine((value, ctx) => {
|
|
4864
|
+
const parseResult = schema.safeParse(value);
|
|
4865
|
+
if (!parseResult.success) {
|
|
4866
|
+
parseResult.error.issues.forEach((issue) => ctx.addIssue(issue));
|
|
5333
4867
|
}
|
|
5334
4868
|
});
|
|
5335
4869
|
return finalSchema;
|
|
5336
4870
|
}
|
|
5337
|
-
makeWhereSchema(model, unique, withoutRelationFields = false, withAggregations = false) {
|
|
4871
|
+
makeWhereSchema(model, unique, withoutRelationFields = false, withAggregations = false, options) {
|
|
5338
4872
|
const modelDef = requireModel(this.schema, model);
|
|
5339
4873
|
const uniqueFieldNames = unique ? getUniqueFields(this.schema, model).filter((uf) => (
|
|
5340
4874
|
// single-field unique
|
|
5341
4875
|
"def" in uf
|
|
5342
4876
|
)).map((uf) => uf.name) : void 0;
|
|
4877
|
+
const nextOpts = this.nextOptions(options);
|
|
5343
4878
|
const fields = {};
|
|
5344
4879
|
for (const field of Object.keys(modelDef.fields)) {
|
|
5345
4880
|
const fieldDef = requireField(this.schema, model, field);
|
|
5346
4881
|
let fieldSchema;
|
|
5347
4882
|
if (fieldDef.relation) {
|
|
5348
|
-
if (withoutRelationFields) {
|
|
4883
|
+
if (withoutRelationFields || !this.shouldIncludeRelations(options)) {
|
|
5349
4884
|
continue;
|
|
5350
4885
|
}
|
|
5351
4886
|
const allowedFilterKinds = this.getEffectiveFilterKinds(model, field);
|
|
5352
4887
|
if (allowedFilterKinds && !allowedFilterKinds.includes("Relation")) {
|
|
5353
4888
|
fieldSchema = import_zod2.z.never();
|
|
5354
4889
|
} else {
|
|
5355
|
-
fieldSchema = import_zod2.z.lazy(() => this.makeWhereSchema(fieldDef.type, false).optional());
|
|
4890
|
+
fieldSchema = import_zod2.z.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts).optional());
|
|
5356
4891
|
fieldSchema = this.nullableIf(fieldSchema, !fieldDef.array && !!fieldDef.optional);
|
|
5357
4892
|
if (fieldDef.array) {
|
|
5358
4893
|
fieldSchema = import_zod2.z.union([
|
|
@@ -5397,7 +4932,7 @@ var InputValidator = class {
|
|
|
5397
4932
|
for (const uniqueField of uniqueFields) {
|
|
5398
4933
|
if ("defs" in uniqueField) {
|
|
5399
4934
|
fields[uniqueField.name] = import_zod2.z.object(Object.fromEntries(Object.entries(uniqueField.defs).map(([key, def]) => {
|
|
5400
|
-
(0,
|
|
4935
|
+
(0, import_common_helpers8.invariant)(!def.relation, "unique field cannot be a relation");
|
|
5401
4936
|
let fieldSchema;
|
|
5402
4937
|
const enumDef = getEnum(this.schema, def.type);
|
|
5403
4938
|
if (enumDef) {
|
|
@@ -5420,9 +4955,9 @@ var InputValidator = class {
|
|
|
5420
4955
|
fields["$expr"] = import_zod2.z.custom((v) => typeof v === "function", {
|
|
5421
4956
|
error: '"$expr" must be a function'
|
|
5422
4957
|
}).optional();
|
|
5423
|
-
fields["AND"] = this.orArray(import_zod2.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
|
|
5424
|
-
fields["OR"] = import_zod2.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)).array().optional();
|
|
5425
|
-
fields["NOT"] = this.orArray(import_zod2.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
|
|
4958
|
+
fields["AND"] = this.orArray(import_zod2.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
|
|
4959
|
+
fields["OR"] = import_zod2.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)).array().optional();
|
|
4960
|
+
fields["NOT"] = this.orArray(import_zod2.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
|
|
5426
4961
|
const baseWhere = import_zod2.z.strictObject(fields);
|
|
5427
4962
|
let result = baseWhere;
|
|
5428
4963
|
if (unique) {
|
|
@@ -5448,7 +4983,7 @@ var InputValidator = class {
|
|
|
5448
4983
|
const optional = !!fieldInfo.optional;
|
|
5449
4984
|
const array = !!fieldInfo.array;
|
|
5450
4985
|
const typeDef = getTypeDef(this.schema, type);
|
|
5451
|
-
(0,
|
|
4986
|
+
(0, import_common_helpers8.invariant)(typeDef, `Type definition "${type}" not found in schema`);
|
|
5452
4987
|
const candidates = [];
|
|
5453
4988
|
if (!array) {
|
|
5454
4989
|
const fieldSchemas = {};
|
|
@@ -5500,7 +5035,7 @@ var InputValidator = class {
|
|
|
5500
5035
|
const optional = !!fieldInfo.optional;
|
|
5501
5036
|
const array = !!fieldInfo.array;
|
|
5502
5037
|
const enumDef = getEnum(this.schema, enumName);
|
|
5503
|
-
(0,
|
|
5038
|
+
(0, import_common_helpers8.invariant)(enumDef, `Enum "${enumName}" not found in schema`);
|
|
5504
5039
|
const baseSchema = import_zod2.z.enum(Object.keys(enumDef.values));
|
|
5505
5040
|
if (array) {
|
|
5506
5041
|
return this.internalMakeArrayFilterSchema(model, fieldInfo.name, baseSchema);
|
|
@@ -5537,7 +5072,7 @@ var InputValidator = class {
|
|
|
5537
5072
|
const allowedFilterKinds = ignoreSlicing ? void 0 : this.getEffectiveFilterKinds(contextModel, fieldInfo.name);
|
|
5538
5073
|
const type = fieldInfo.type;
|
|
5539
5074
|
const optional = !!fieldInfo.optional;
|
|
5540
|
-
return (0,
|
|
5075
|
+
return (0, import_ts_pattern13.match)(type).with("String", () => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds)).with(import_ts_pattern13.P.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", () => import_zod2.z.never()).exhaustive();
|
|
5541
5076
|
}
|
|
5542
5077
|
makeJsonValueSchema(nullable, forFilter) {
|
|
5543
5078
|
const options = [
|
|
@@ -5701,29 +5236,35 @@ var InputValidator = class {
|
|
|
5701
5236
|
import_zod2.z.literal("insensitive")
|
|
5702
5237
|
]);
|
|
5703
5238
|
}
|
|
5704
|
-
makeSelectSchema(model) {
|
|
5239
|
+
makeSelectSchema(model, options) {
|
|
5705
5240
|
const modelDef = requireModel(this.schema, model);
|
|
5706
5241
|
const fields = {};
|
|
5707
5242
|
for (const field of Object.keys(modelDef.fields)) {
|
|
5708
5243
|
const fieldDef = requireField(this.schema, model, field);
|
|
5709
5244
|
if (fieldDef.relation) {
|
|
5245
|
+
if (!this.shouldIncludeRelations(options)) {
|
|
5246
|
+
continue;
|
|
5247
|
+
}
|
|
5710
5248
|
if (this.isModelAllowed(fieldDef.type)) {
|
|
5711
|
-
fields[field] = this.makeRelationSelectIncludeSchema(model, field).optional();
|
|
5249
|
+
fields[field] = this.makeRelationSelectIncludeSchema(model, field, options).optional();
|
|
5712
5250
|
}
|
|
5713
5251
|
} else {
|
|
5714
5252
|
fields[field] = import_zod2.z.boolean().optional();
|
|
5715
5253
|
}
|
|
5716
5254
|
}
|
|
5717
|
-
|
|
5718
|
-
|
|
5719
|
-
|
|
5255
|
+
if (this.shouldIncludeRelations(options)) {
|
|
5256
|
+
const _countSchema = this.makeCountSelectionSchema(model, options);
|
|
5257
|
+
if (!(_countSchema instanceof import_zod2.z.ZodNever)) {
|
|
5258
|
+
fields["_count"] = _countSchema;
|
|
5259
|
+
}
|
|
5720
5260
|
}
|
|
5721
5261
|
return import_zod2.z.strictObject(fields);
|
|
5722
5262
|
}
|
|
5723
|
-
makeCountSelectionSchema(model) {
|
|
5263
|
+
makeCountSelectionSchema(model, options) {
|
|
5724
5264
|
const modelDef = requireModel(this.schema, model);
|
|
5725
5265
|
const toManyRelations = Object.values(modelDef.fields).filter((def) => def.relation && def.array);
|
|
5726
5266
|
if (toManyRelations.length > 0) {
|
|
5267
|
+
const nextOpts = this.nextOptions(options);
|
|
5727
5268
|
return import_zod2.z.union([
|
|
5728
5269
|
import_zod2.z.literal(true),
|
|
5729
5270
|
import_zod2.z.strictObject({
|
|
@@ -5732,7 +5273,7 @@ var InputValidator = class {
|
|
|
5732
5273
|
[fieldDef.name]: import_zod2.z.union([
|
|
5733
5274
|
import_zod2.z.boolean(),
|
|
5734
5275
|
import_zod2.z.strictObject({
|
|
5735
|
-
where: this.makeWhereSchema(fieldDef.type, false, false)
|
|
5276
|
+
where: this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts)
|
|
5736
5277
|
})
|
|
5737
5278
|
]).optional()
|
|
5738
5279
|
}), {}))
|
|
@@ -5742,27 +5283,29 @@ var InputValidator = class {
|
|
|
5742
5283
|
return import_zod2.z.never();
|
|
5743
5284
|
}
|
|
5744
5285
|
}
|
|
5745
|
-
makeRelationSelectIncludeSchema(model, field) {
|
|
5286
|
+
makeRelationSelectIncludeSchema(model, field, options) {
|
|
5746
5287
|
const fieldDef = requireField(this.schema, model, field);
|
|
5288
|
+
const nextOpts = this.nextOptions(options);
|
|
5747
5289
|
let objSchema = import_zod2.z.strictObject({
|
|
5748
5290
|
...fieldDef.array || fieldDef.optional ? {
|
|
5749
5291
|
// to-many relations and optional to-one relations are filterable
|
|
5750
|
-
where: import_zod2.z.lazy(() => this.makeWhereSchema(fieldDef.type, false)).optional()
|
|
5292
|
+
where: import_zod2.z.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts)).optional()
|
|
5751
5293
|
} : {},
|
|
5752
|
-
select: import_zod2.z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional().nullable(),
|
|
5753
|
-
include: import_zod2.z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional().nullable(),
|
|
5294
|
+
select: import_zod2.z.lazy(() => this.makeSelectSchema(fieldDef.type, nextOpts)).optional().nullable(),
|
|
5295
|
+
include: import_zod2.z.lazy(() => this.makeIncludeSchema(fieldDef.type, nextOpts)).optional().nullable(),
|
|
5754
5296
|
omit: import_zod2.z.lazy(() => this.makeOmitSchema(fieldDef.type)).optional().nullable(),
|
|
5755
5297
|
...fieldDef.array ? {
|
|
5756
5298
|
// to-many relations can be ordered, skipped, taken, and cursor-located
|
|
5757
|
-
orderBy: import_zod2.z.lazy(() => this.orArray(this.makeOrderBySchema(fieldDef.type, true, false), true)).optional(),
|
|
5299
|
+
orderBy: import_zod2.z.lazy(() => this.orArray(this.makeOrderBySchema(fieldDef.type, true, false, nextOpts), true)).optional(),
|
|
5758
5300
|
skip: this.makeSkipSchema().optional(),
|
|
5759
5301
|
take: this.makeTakeSchema().optional(),
|
|
5760
|
-
cursor: this.makeCursorSchema(fieldDef.type).optional(),
|
|
5302
|
+
cursor: this.makeCursorSchema(fieldDef.type, nextOpts).optional(),
|
|
5761
5303
|
distinct: this.makeDistinctSchema(fieldDef.type).optional()
|
|
5762
5304
|
} : {}
|
|
5763
5305
|
});
|
|
5764
5306
|
objSchema = this.refineForSelectIncludeMutuallyExclusive(objSchema);
|
|
5765
5307
|
objSchema = this.refineForSelectOmitMutuallyExclusive(objSchema);
|
|
5308
|
+
objSchema = this.refineForSelectHasTruthyField(objSchema);
|
|
5766
5309
|
return import_zod2.z.union([
|
|
5767
5310
|
import_zod2.z.boolean(),
|
|
5768
5311
|
objSchema
|
|
@@ -5783,36 +5326,42 @@ var InputValidator = class {
|
|
|
5783
5326
|
}
|
|
5784
5327
|
return import_zod2.z.strictObject(fields);
|
|
5785
5328
|
}
|
|
5786
|
-
makeIncludeSchema(model) {
|
|
5329
|
+
makeIncludeSchema(model, options) {
|
|
5787
5330
|
const modelDef = requireModel(this.schema, model);
|
|
5788
5331
|
const fields = {};
|
|
5789
5332
|
for (const field of Object.keys(modelDef.fields)) {
|
|
5790
5333
|
const fieldDef = requireField(this.schema, model, field);
|
|
5791
5334
|
if (fieldDef.relation) {
|
|
5335
|
+
if (!this.shouldIncludeRelations(options)) {
|
|
5336
|
+
continue;
|
|
5337
|
+
}
|
|
5792
5338
|
if (this.isModelAllowed(fieldDef.type)) {
|
|
5793
|
-
fields[field] = this.makeRelationSelectIncludeSchema(model, field).optional();
|
|
5339
|
+
fields[field] = this.makeRelationSelectIncludeSchema(model, field, options).optional();
|
|
5794
5340
|
}
|
|
5795
5341
|
}
|
|
5796
5342
|
}
|
|
5797
|
-
|
|
5798
|
-
|
|
5799
|
-
|
|
5343
|
+
if (this.shouldIncludeRelations(options)) {
|
|
5344
|
+
const _countSchema = this.makeCountSelectionSchema(model, options);
|
|
5345
|
+
if (!(_countSchema instanceof import_zod2.z.ZodNever)) {
|
|
5346
|
+
fields["_count"] = _countSchema;
|
|
5347
|
+
}
|
|
5800
5348
|
}
|
|
5801
5349
|
return import_zod2.z.strictObject(fields);
|
|
5802
5350
|
}
|
|
5803
|
-
makeOrderBySchema(model, withRelation, WithAggregation) {
|
|
5351
|
+
makeOrderBySchema(model, withRelation, WithAggregation, options) {
|
|
5804
5352
|
const modelDef = requireModel(this.schema, model);
|
|
5805
5353
|
const fields = {};
|
|
5806
5354
|
const sort = import_zod2.z.union([
|
|
5807
5355
|
import_zod2.z.literal("asc"),
|
|
5808
5356
|
import_zod2.z.literal("desc")
|
|
5809
5357
|
]);
|
|
5358
|
+
const nextOpts = this.nextOptions(options);
|
|
5810
5359
|
for (const field of Object.keys(modelDef.fields)) {
|
|
5811
5360
|
const fieldDef = requireField(this.schema, model, field);
|
|
5812
5361
|
if (fieldDef.relation) {
|
|
5813
|
-
if (withRelation) {
|
|
5362
|
+
if (withRelation && this.shouldIncludeRelations(options)) {
|
|
5814
5363
|
fields[field] = import_zod2.z.lazy(() => {
|
|
5815
|
-
let relationOrderBy = this.makeOrderBySchema(fieldDef.type, withRelation, WithAggregation);
|
|
5364
|
+
let relationOrderBy = this.makeOrderBySchema(fieldDef.type, withRelation, WithAggregation, nextOpts);
|
|
5816
5365
|
if (fieldDef.array) {
|
|
5817
5366
|
relationOrderBy = relationOrderBy.extend({
|
|
5818
5367
|
_count: sort
|
|
@@ -5847,7 +5396,7 @@ var InputValidator = class {
|
|
|
5847
5396
|
"_max"
|
|
5848
5397
|
];
|
|
5849
5398
|
for (const agg of aggregationFields) {
|
|
5850
|
-
fields[agg] = import_zod2.z.lazy(() => this.makeOrderBySchema(model, true, false).optional());
|
|
5399
|
+
fields[agg] = import_zod2.z.lazy(() => this.makeOrderBySchema(model, true, false, options).optional());
|
|
5851
5400
|
}
|
|
5852
5401
|
}
|
|
5853
5402
|
return import_zod2.z.strictObject(fields);
|
|
@@ -5855,56 +5404,56 @@ var InputValidator = class {
|
|
|
5855
5404
|
makeDistinctSchema(model) {
|
|
5856
5405
|
const modelDef = requireModel(this.schema, model);
|
|
5857
5406
|
const nonRelationFields = Object.keys(modelDef.fields).filter((field) => !modelDef.fields[field]?.relation);
|
|
5858
|
-
return this.orArray(import_zod2.z.enum(nonRelationFields), true);
|
|
5407
|
+
return nonRelationFields.length > 0 ? this.orArray(import_zod2.z.enum(nonRelationFields), true) : import_zod2.z.never();
|
|
5859
5408
|
}
|
|
5860
|
-
makeCursorSchema(model) {
|
|
5861
|
-
return this.makeWhereSchema(model, true, true).optional();
|
|
5409
|
+
makeCursorSchema(model, options) {
|
|
5410
|
+
return this.makeWhereSchema(model, true, true, false, options).optional();
|
|
5862
5411
|
}
|
|
5863
5412
|
// #endregion
|
|
5864
5413
|
// #region Create
|
|
5865
|
-
makeCreateSchema(model) {
|
|
5866
|
-
const dataSchema = this.makeCreateDataSchema(model, false);
|
|
5414
|
+
makeCreateSchema(model, options) {
|
|
5415
|
+
const dataSchema = this.makeCreateDataSchema(model, false, [], false, options);
|
|
5867
5416
|
const baseSchema = import_zod2.z.strictObject({
|
|
5868
5417
|
data: dataSchema,
|
|
5869
|
-
select: this.makeSelectSchema(model).optional().nullable(),
|
|
5870
|
-
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
5418
|
+
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
5419
|
+
include: this.makeIncludeSchema(model, options).optional().nullable(),
|
|
5871
5420
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
5872
5421
|
});
|
|
5873
5422
|
let schema = this.mergePluginArgsSchema(baseSchema, "create");
|
|
5874
5423
|
schema = this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
5875
5424
|
schema = this.refineForSelectOmitMutuallyExclusive(schema);
|
|
5425
|
+
schema = this.refineForSelectHasTruthyField(schema);
|
|
5876
5426
|
return schema;
|
|
5877
5427
|
}
|
|
5878
|
-
makeCreateManySchema(model) {
|
|
5879
|
-
return this.mergePluginArgsSchema(this.
|
|
5428
|
+
makeCreateManySchema(model, options) {
|
|
5429
|
+
return this.mergePluginArgsSchema(this.makeCreateManyPayloadSchema(model, [], options), "createMany");
|
|
5880
5430
|
}
|
|
5881
|
-
makeCreateManyAndReturnSchema(model) {
|
|
5882
|
-
const base = this.
|
|
5431
|
+
makeCreateManyAndReturnSchema(model, options) {
|
|
5432
|
+
const base = this.makeCreateManyPayloadSchema(model, [], options);
|
|
5883
5433
|
let result = base.extend({
|
|
5884
|
-
select: this.makeSelectSchema(model).optional().nullable(),
|
|
5434
|
+
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
5885
5435
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
5886
5436
|
});
|
|
5887
5437
|
result = this.mergePluginArgsSchema(result, "createManyAndReturn");
|
|
5888
|
-
return this.refineForSelectOmitMutuallyExclusive(result).optional();
|
|
5438
|
+
return this.refineForSelectHasTruthyField(this.refineForSelectOmitMutuallyExclusive(result)).optional();
|
|
5889
5439
|
}
|
|
5890
|
-
makeCreateDataSchema(model, canBeArray, withoutFields = [], withoutRelationFields = false) {
|
|
5440
|
+
makeCreateDataSchema(model, canBeArray, withoutFields = [], withoutRelationFields = false, options) {
|
|
5441
|
+
const skipRelations = withoutRelationFields || !this.shouldIncludeRelations(options);
|
|
5891
5442
|
const uncheckedVariantFields = {};
|
|
5892
5443
|
const checkedVariantFields = {};
|
|
5893
5444
|
const modelDef = requireModel(this.schema, model);
|
|
5894
|
-
const hasRelation = !
|
|
5445
|
+
const hasRelation = !skipRelations && Object.entries(modelDef.fields).some(([f, def]) => !withoutFields.includes(f) && def.relation);
|
|
5446
|
+
const nextOpts = this.nextOptions(options);
|
|
5895
5447
|
Object.keys(modelDef.fields).forEach((field) => {
|
|
5896
5448
|
if (withoutFields.includes(field)) {
|
|
5897
5449
|
return;
|
|
5898
5450
|
}
|
|
5899
5451
|
const fieldDef = requireField(this.schema, model, field);
|
|
5900
|
-
if (fieldDef.computed) {
|
|
5901
|
-
return;
|
|
5902
|
-
}
|
|
5903
|
-
if (this.isDelegateDiscriminator(fieldDef)) {
|
|
5452
|
+
if (fieldDef.computed || fieldDef.isDiscriminator) {
|
|
5904
5453
|
return;
|
|
5905
5454
|
}
|
|
5906
5455
|
if (fieldDef.relation) {
|
|
5907
|
-
if (
|
|
5456
|
+
if (skipRelations) {
|
|
5908
5457
|
return;
|
|
5909
5458
|
}
|
|
5910
5459
|
if (!this.isModelAllowed(fieldDef.type)) {
|
|
@@ -5919,7 +5468,7 @@ var InputValidator = class {
|
|
|
5919
5468
|
excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
5920
5469
|
}
|
|
5921
5470
|
}
|
|
5922
|
-
let fieldSchema = import_zod2.z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "create"));
|
|
5471
|
+
let fieldSchema = import_zod2.z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "create", nextOpts));
|
|
5923
5472
|
if (fieldDef.optional || fieldDef.array) {
|
|
5924
5473
|
fieldSchema = fieldSchema.optional();
|
|
5925
5474
|
} else {
|
|
@@ -5944,7 +5493,7 @@ var InputValidator = class {
|
|
|
5944
5493
|
} else {
|
|
5945
5494
|
let fieldSchema = this.makeScalarSchema(fieldDef.type, fieldDef.attributes);
|
|
5946
5495
|
if (fieldDef.array) {
|
|
5947
|
-
fieldSchema = addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
5496
|
+
fieldSchema = import_zod.ZodUtils.addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
5948
5497
|
fieldSchema = import_zod2.z.union([
|
|
5949
5498
|
fieldSchema,
|
|
5950
5499
|
import_zod2.z.strictObject({
|
|
@@ -5971,8 +5520,8 @@ var InputValidator = class {
|
|
|
5971
5520
|
}
|
|
5972
5521
|
}
|
|
5973
5522
|
});
|
|
5974
|
-
const uncheckedCreateSchema = this.extraValidationsEnabled ? addCustomValidation(import_zod2.z.strictObject(uncheckedVariantFields), modelDef.attributes) : import_zod2.z.strictObject(uncheckedVariantFields);
|
|
5975
|
-
const checkedCreateSchema = this.extraValidationsEnabled ? addCustomValidation(import_zod2.z.strictObject(checkedVariantFields), modelDef.attributes) : import_zod2.z.strictObject(checkedVariantFields);
|
|
5523
|
+
const uncheckedCreateSchema = this.extraValidationsEnabled ? import_zod.ZodUtils.addCustomValidation(import_zod2.z.strictObject(uncheckedVariantFields), modelDef.attributes) : import_zod2.z.strictObject(uncheckedVariantFields);
|
|
5524
|
+
const checkedCreateSchema = this.extraValidationsEnabled ? import_zod.ZodUtils.addCustomValidation(import_zod2.z.strictObject(checkedVariantFields), modelDef.attributes) : import_zod2.z.strictObject(checkedVariantFields);
|
|
5976
5525
|
if (!hasRelation) {
|
|
5977
5526
|
return this.orArray(uncheckedCreateSchema, canBeArray);
|
|
5978
5527
|
} else {
|
|
@@ -5988,153 +5537,154 @@ var InputValidator = class {
|
|
|
5988
5537
|
]);
|
|
5989
5538
|
}
|
|
5990
5539
|
}
|
|
5991
|
-
|
|
5992
|
-
if (!fieldDef.originModel) {
|
|
5993
|
-
return false;
|
|
5994
|
-
}
|
|
5995
|
-
const discriminatorField = getDiscriminatorField(this.schema, fieldDef.originModel);
|
|
5996
|
-
return discriminatorField === fieldDef.name;
|
|
5997
|
-
}
|
|
5998
|
-
makeRelationManipulationSchema(model, field, withoutFields, mode) {
|
|
5540
|
+
makeRelationManipulationSchema(model, field, withoutFields, mode, options) {
|
|
5999
5541
|
const fieldDef = requireField(this.schema, model, field);
|
|
6000
5542
|
const fieldType = fieldDef.type;
|
|
6001
5543
|
const array = !!fieldDef.array;
|
|
6002
5544
|
const fields = {
|
|
6003
|
-
create: this.makeCreateDataSchema(fieldDef.type, !!fieldDef.array, withoutFields).optional(),
|
|
6004
|
-
connect: this.makeConnectDataSchema(fieldType, array).optional(),
|
|
6005
|
-
connectOrCreate: this.makeConnectOrCreateDataSchema(fieldType, array, withoutFields).optional()
|
|
5545
|
+
create: this.makeCreateDataSchema(fieldDef.type, !!fieldDef.array, withoutFields, false, options).optional(),
|
|
5546
|
+
connect: this.makeConnectDataSchema(fieldType, array, options).optional(),
|
|
5547
|
+
connectOrCreate: this.makeConnectOrCreateDataSchema(fieldType, array, withoutFields, options).optional()
|
|
6006
5548
|
};
|
|
6007
5549
|
if (array) {
|
|
6008
|
-
fields["createMany"] = this.
|
|
5550
|
+
fields["createMany"] = this.makeCreateManyPayloadSchema(fieldType, withoutFields, options).optional();
|
|
6009
5551
|
}
|
|
6010
5552
|
if (mode === "update") {
|
|
6011
5553
|
if (fieldDef.optional || fieldDef.array) {
|
|
6012
|
-
fields["disconnect"] = this.makeDisconnectDataSchema(fieldType, array).optional();
|
|
6013
|
-
fields["delete"] = this.makeDeleteRelationDataSchema(fieldType, array, true).optional();
|
|
5554
|
+
fields["disconnect"] = this.makeDisconnectDataSchema(fieldType, array, options).optional();
|
|
5555
|
+
fields["delete"] = this.makeDeleteRelationDataSchema(fieldType, array, true, options).optional();
|
|
6014
5556
|
}
|
|
6015
5557
|
fields["update"] = array ? this.orArray(import_zod2.z.strictObject({
|
|
6016
|
-
where: this.makeWhereSchema(fieldType, true),
|
|
6017
|
-
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
5558
|
+
where: this.makeWhereSchema(fieldType, true, false, false, options),
|
|
5559
|
+
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
6018
5560
|
}), true).optional() : import_zod2.z.union([
|
|
6019
5561
|
import_zod2.z.strictObject({
|
|
6020
|
-
where: this.makeWhereSchema(fieldType, false).optional(),
|
|
6021
|
-
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
5562
|
+
where: this.makeWhereSchema(fieldType, false, false, false, options).optional(),
|
|
5563
|
+
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
6022
5564
|
}),
|
|
6023
|
-
this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
5565
|
+
this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
6024
5566
|
]).optional();
|
|
6025
|
-
let upsertWhere = this.makeWhereSchema(fieldType, true);
|
|
5567
|
+
let upsertWhere = this.makeWhereSchema(fieldType, true, false, false, options);
|
|
6026
5568
|
if (!fieldDef.array) {
|
|
6027
5569
|
upsertWhere = upsertWhere.optional();
|
|
6028
5570
|
}
|
|
6029
5571
|
fields["upsert"] = this.orArray(import_zod2.z.strictObject({
|
|
6030
5572
|
where: upsertWhere,
|
|
6031
|
-
create: this.makeCreateDataSchema(fieldType, false, withoutFields),
|
|
6032
|
-
update: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
5573
|
+
create: this.makeCreateDataSchema(fieldType, false, withoutFields, false, options),
|
|
5574
|
+
update: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
6033
5575
|
}), true).optional();
|
|
6034
5576
|
if (array) {
|
|
6035
|
-
fields["set"] = this.makeSetDataSchema(fieldType, true).optional();
|
|
5577
|
+
fields["set"] = this.makeSetDataSchema(fieldType, true, options).optional();
|
|
6036
5578
|
fields["updateMany"] = this.orArray(import_zod2.z.strictObject({
|
|
6037
|
-
where: this.makeWhereSchema(fieldType, false, true),
|
|
6038
|
-
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
5579
|
+
where: this.makeWhereSchema(fieldType, false, true, false, options),
|
|
5580
|
+
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
6039
5581
|
}), true).optional();
|
|
6040
|
-
fields["deleteMany"] = this.makeDeleteRelationDataSchema(fieldType, true, false).optional();
|
|
5582
|
+
fields["deleteMany"] = this.makeDeleteRelationDataSchema(fieldType, true, false, options).optional();
|
|
6041
5583
|
}
|
|
6042
5584
|
}
|
|
6043
5585
|
return import_zod2.z.strictObject(fields);
|
|
6044
5586
|
}
|
|
6045
|
-
makeSetDataSchema(model, canBeArray) {
|
|
6046
|
-
return this.orArray(this.makeWhereSchema(model, true), canBeArray);
|
|
5587
|
+
makeSetDataSchema(model, canBeArray, options) {
|
|
5588
|
+
return this.orArray(this.makeWhereSchema(model, true, false, false, options), canBeArray);
|
|
6047
5589
|
}
|
|
6048
|
-
makeConnectDataSchema(model, canBeArray) {
|
|
6049
|
-
return this.orArray(this.makeWhereSchema(model, true), canBeArray);
|
|
5590
|
+
makeConnectDataSchema(model, canBeArray, options) {
|
|
5591
|
+
return this.orArray(this.makeWhereSchema(model, true, false, false, options), canBeArray);
|
|
6050
5592
|
}
|
|
6051
|
-
makeDisconnectDataSchema(model, canBeArray) {
|
|
5593
|
+
makeDisconnectDataSchema(model, canBeArray, options) {
|
|
6052
5594
|
if (canBeArray) {
|
|
6053
|
-
return this.orArray(this.makeWhereSchema(model, true), canBeArray);
|
|
5595
|
+
return this.orArray(this.makeWhereSchema(model, true, false, false, options), canBeArray);
|
|
6054
5596
|
} else {
|
|
6055
5597
|
return import_zod2.z.union([
|
|
6056
5598
|
import_zod2.z.boolean(),
|
|
6057
|
-
this.makeWhereSchema(model, false)
|
|
5599
|
+
this.makeWhereSchema(model, false, false, false, options)
|
|
6058
5600
|
]);
|
|
6059
5601
|
}
|
|
6060
5602
|
}
|
|
6061
|
-
makeDeleteRelationDataSchema(model, toManyRelation, uniqueFilter) {
|
|
6062
|
-
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter), true) : import_zod2.z.union([
|
|
5603
|
+
makeDeleteRelationDataSchema(model, toManyRelation, uniqueFilter, options) {
|
|
5604
|
+
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter, false, false, options), true) : import_zod2.z.union([
|
|
6063
5605
|
import_zod2.z.boolean(),
|
|
6064
|
-
this.makeWhereSchema(model, uniqueFilter)
|
|
5606
|
+
this.makeWhereSchema(model, uniqueFilter, false, false, options)
|
|
6065
5607
|
]);
|
|
6066
5608
|
}
|
|
6067
|
-
makeConnectOrCreateDataSchema(model, canBeArray, withoutFields) {
|
|
6068
|
-
const whereSchema = this.makeWhereSchema(model, true);
|
|
6069
|
-
const createSchema = this.makeCreateDataSchema(model, false, withoutFields);
|
|
5609
|
+
makeConnectOrCreateDataSchema(model, canBeArray, withoutFields, options) {
|
|
5610
|
+
const whereSchema = this.makeWhereSchema(model, true, false, false, options);
|
|
5611
|
+
const createSchema = this.makeCreateDataSchema(model, false, withoutFields, false, options);
|
|
6070
5612
|
return this.orArray(import_zod2.z.strictObject({
|
|
6071
5613
|
where: whereSchema,
|
|
6072
5614
|
create: createSchema
|
|
6073
5615
|
}), canBeArray);
|
|
6074
5616
|
}
|
|
6075
|
-
|
|
5617
|
+
makeCreateManyPayloadSchema(model, withoutFields, options) {
|
|
6076
5618
|
return import_zod2.z.strictObject({
|
|
6077
|
-
data: this.makeCreateDataSchema(model, true, withoutFields, true),
|
|
5619
|
+
data: this.makeCreateDataSchema(model, true, withoutFields, true, options),
|
|
6078
5620
|
skipDuplicates: import_zod2.z.boolean().optional()
|
|
6079
5621
|
});
|
|
6080
5622
|
}
|
|
6081
5623
|
// #endregion
|
|
6082
5624
|
// #region Update
|
|
6083
|
-
makeUpdateSchema(model) {
|
|
5625
|
+
makeUpdateSchema(model, options) {
|
|
6084
5626
|
const baseSchema = import_zod2.z.strictObject({
|
|
6085
|
-
where: this.makeWhereSchema(model, true),
|
|
6086
|
-
data: this.makeUpdateDataSchema(model),
|
|
6087
|
-
select: this.makeSelectSchema(model).optional().nullable(),
|
|
6088
|
-
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
5627
|
+
where: this.makeWhereSchema(model, true, false, false, options),
|
|
5628
|
+
data: this.makeUpdateDataSchema(model, [], false, options),
|
|
5629
|
+
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
5630
|
+
include: this.makeIncludeSchema(model, options).optional().nullable(),
|
|
6089
5631
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
6090
5632
|
});
|
|
6091
5633
|
let schema = this.mergePluginArgsSchema(baseSchema, "update");
|
|
6092
5634
|
schema = this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
6093
5635
|
schema = this.refineForSelectOmitMutuallyExclusive(schema);
|
|
5636
|
+
schema = this.refineForSelectHasTruthyField(schema);
|
|
6094
5637
|
return schema;
|
|
6095
5638
|
}
|
|
6096
|
-
makeUpdateManySchema(model) {
|
|
5639
|
+
makeUpdateManySchema(model, options) {
|
|
6097
5640
|
return this.mergePluginArgsSchema(import_zod2.z.strictObject({
|
|
6098
|
-
where: this.makeWhereSchema(model, false).optional(),
|
|
6099
|
-
data: this.makeUpdateDataSchema(model, [], true),
|
|
5641
|
+
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
5642
|
+
data: this.makeUpdateDataSchema(model, [], true, options),
|
|
6100
5643
|
limit: import_zod2.z.number().int().nonnegative().optional()
|
|
6101
5644
|
}), "updateMany");
|
|
6102
5645
|
}
|
|
6103
|
-
makeUpdateManyAndReturnSchema(model) {
|
|
6104
|
-
const baseSchema = this.makeUpdateManySchema(model);
|
|
5646
|
+
makeUpdateManyAndReturnSchema(model, options) {
|
|
5647
|
+
const baseSchema = this.makeUpdateManySchema(model, options);
|
|
6105
5648
|
let schema = baseSchema.extend({
|
|
6106
|
-
select: this.makeSelectSchema(model).optional().nullable(),
|
|
5649
|
+
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
6107
5650
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
6108
5651
|
});
|
|
6109
5652
|
schema = this.refineForSelectOmitMutuallyExclusive(schema);
|
|
5653
|
+
schema = this.refineForSelectHasTruthyField(schema);
|
|
6110
5654
|
return schema;
|
|
6111
5655
|
}
|
|
6112
|
-
makeUpsertSchema(model) {
|
|
5656
|
+
makeUpsertSchema(model, options) {
|
|
6113
5657
|
const baseSchema = import_zod2.z.strictObject({
|
|
6114
|
-
where: this.makeWhereSchema(model, true),
|
|
6115
|
-
create: this.makeCreateDataSchema(model, false),
|
|
6116
|
-
update: this.makeUpdateDataSchema(model),
|
|
6117
|
-
select: this.makeSelectSchema(model).optional().nullable(),
|
|
6118
|
-
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
5658
|
+
where: this.makeWhereSchema(model, true, false, false, options),
|
|
5659
|
+
create: this.makeCreateDataSchema(model, false, [], false, options),
|
|
5660
|
+
update: this.makeUpdateDataSchema(model, [], false, options),
|
|
5661
|
+
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
5662
|
+
include: this.makeIncludeSchema(model, options).optional().nullable(),
|
|
6119
5663
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
6120
5664
|
});
|
|
6121
5665
|
let schema = this.mergePluginArgsSchema(baseSchema, "upsert");
|
|
6122
5666
|
schema = this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
6123
5667
|
schema = this.refineForSelectOmitMutuallyExclusive(schema);
|
|
5668
|
+
schema = this.refineForSelectHasTruthyField(schema);
|
|
6124
5669
|
return schema;
|
|
6125
5670
|
}
|
|
6126
|
-
makeUpdateDataSchema(model, withoutFields = [], withoutRelationFields = false) {
|
|
5671
|
+
makeUpdateDataSchema(model, withoutFields = [], withoutRelationFields = false, options) {
|
|
5672
|
+
const skipRelations = withoutRelationFields || !this.shouldIncludeRelations(options);
|
|
6127
5673
|
const uncheckedVariantFields = {};
|
|
6128
5674
|
const checkedVariantFields = {};
|
|
6129
5675
|
const modelDef = requireModel(this.schema, model);
|
|
6130
|
-
const hasRelation = Object.entries(modelDef.fields).some(([key, value]) => value.relation && !withoutFields.includes(key));
|
|
5676
|
+
const hasRelation = !skipRelations && Object.entries(modelDef.fields).some(([key, value]) => value.relation && !withoutFields.includes(key));
|
|
5677
|
+
const nextOpts = this.nextOptions(options);
|
|
6131
5678
|
Object.keys(modelDef.fields).forEach((field) => {
|
|
6132
5679
|
if (withoutFields.includes(field)) {
|
|
6133
5680
|
return;
|
|
6134
5681
|
}
|
|
6135
5682
|
const fieldDef = requireField(this.schema, model, field);
|
|
5683
|
+
if (fieldDef.computed || fieldDef.isDiscriminator) {
|
|
5684
|
+
return;
|
|
5685
|
+
}
|
|
6136
5686
|
if (fieldDef.relation) {
|
|
6137
|
-
if (
|
|
5687
|
+
if (skipRelations) {
|
|
6138
5688
|
return;
|
|
6139
5689
|
}
|
|
6140
5690
|
if (!this.isModelAllowed(fieldDef.type)) {
|
|
@@ -6149,7 +5699,7 @@ var InputValidator = class {
|
|
|
6149
5699
|
excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
6150
5700
|
}
|
|
6151
5701
|
}
|
|
6152
|
-
let fieldSchema = import_zod2.z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "update")).optional();
|
|
5702
|
+
let fieldSchema = import_zod2.z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "update", nextOpts)).optional();
|
|
6153
5703
|
if (fieldDef.optional && !fieldDef.array) {
|
|
6154
5704
|
fieldSchema = fieldSchema.nullable();
|
|
6155
5705
|
}
|
|
@@ -6163,6 +5713,7 @@ var InputValidator = class {
|
|
|
6163
5713
|
fieldSchema = import_zod2.z.union([
|
|
6164
5714
|
fieldSchema,
|
|
6165
5715
|
import_zod2.z.object({
|
|
5716
|
+
// TODO: use Decimal/BigInt for incremental updates
|
|
6166
5717
|
set: this.nullableIf(import_zod2.z.number().optional(), !!fieldDef.optional).optional(),
|
|
6167
5718
|
increment: import_zod2.z.number().optional(),
|
|
6168
5719
|
decrement: import_zod2.z.number().optional(),
|
|
@@ -6172,7 +5723,7 @@ var InputValidator = class {
|
|
|
6172
5723
|
]);
|
|
6173
5724
|
}
|
|
6174
5725
|
if (fieldDef.array) {
|
|
6175
|
-
const arraySchema = addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
5726
|
+
const arraySchema = import_zod.ZodUtils.addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
6176
5727
|
fieldSchema = import_zod2.z.union([
|
|
6177
5728
|
arraySchema,
|
|
6178
5729
|
import_zod2.z.object({
|
|
@@ -6201,8 +5752,8 @@ var InputValidator = class {
|
|
|
6201
5752
|
}
|
|
6202
5753
|
}
|
|
6203
5754
|
});
|
|
6204
|
-
const uncheckedUpdateSchema = this.extraValidationsEnabled ? addCustomValidation(import_zod2.z.strictObject(uncheckedVariantFields), modelDef.attributes) : import_zod2.z.strictObject(uncheckedVariantFields);
|
|
6205
|
-
const checkedUpdateSchema = this.extraValidationsEnabled ? addCustomValidation(import_zod2.z.strictObject(checkedVariantFields), modelDef.attributes) : import_zod2.z.strictObject(checkedVariantFields);
|
|
5755
|
+
const uncheckedUpdateSchema = this.extraValidationsEnabled ? import_zod.ZodUtils.addCustomValidation(import_zod2.z.strictObject(uncheckedVariantFields), modelDef.attributes) : import_zod2.z.strictObject(uncheckedVariantFields);
|
|
5756
|
+
const checkedUpdateSchema = this.extraValidationsEnabled ? import_zod.ZodUtils.addCustomValidation(import_zod2.z.strictObject(checkedVariantFields), modelDef.attributes) : import_zod2.z.strictObject(checkedVariantFields);
|
|
6206
5757
|
if (!hasRelation) {
|
|
6207
5758
|
return uncheckedUpdateSchema;
|
|
6208
5759
|
} else {
|
|
@@ -6214,32 +5765,33 @@ var InputValidator = class {
|
|
|
6214
5765
|
}
|
|
6215
5766
|
// #endregion
|
|
6216
5767
|
// #region Delete
|
|
6217
|
-
makeDeleteSchema(model) {
|
|
5768
|
+
makeDeleteSchema(model, options) {
|
|
6218
5769
|
const baseSchema = import_zod2.z.strictObject({
|
|
6219
|
-
where: this.makeWhereSchema(model, true),
|
|
6220
|
-
select: this.makeSelectSchema(model).optional().nullable(),
|
|
6221
|
-
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
5770
|
+
where: this.makeWhereSchema(model, true, false, false, options),
|
|
5771
|
+
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
5772
|
+
include: this.makeIncludeSchema(model, options).optional().nullable(),
|
|
6222
5773
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
6223
5774
|
});
|
|
6224
5775
|
let schema = this.mergePluginArgsSchema(baseSchema, "delete");
|
|
6225
5776
|
schema = this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
6226
5777
|
schema = this.refineForSelectOmitMutuallyExclusive(schema);
|
|
5778
|
+
schema = this.refineForSelectHasTruthyField(schema);
|
|
6227
5779
|
return schema;
|
|
6228
5780
|
}
|
|
6229
|
-
makeDeleteManySchema(model) {
|
|
5781
|
+
makeDeleteManySchema(model, options) {
|
|
6230
5782
|
return this.mergePluginArgsSchema(import_zod2.z.strictObject({
|
|
6231
|
-
where: this.makeWhereSchema(model, false).optional(),
|
|
5783
|
+
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
6232
5784
|
limit: import_zod2.z.number().int().nonnegative().optional()
|
|
6233
5785
|
}), "deleteMany").optional();
|
|
6234
5786
|
}
|
|
6235
5787
|
// #endregion
|
|
6236
5788
|
// #region Count
|
|
6237
|
-
makeCountSchema(model) {
|
|
5789
|
+
makeCountSchema(model, options) {
|
|
6238
5790
|
return this.mergePluginArgsSchema(import_zod2.z.strictObject({
|
|
6239
|
-
where: this.makeWhereSchema(model, false).optional(),
|
|
5791
|
+
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
6240
5792
|
skip: this.makeSkipSchema().optional(),
|
|
6241
5793
|
take: this.makeTakeSchema().optional(),
|
|
6242
|
-
orderBy: this.orArray(this.makeOrderBySchema(model, true, false), true).optional(),
|
|
5794
|
+
orderBy: this.orArray(this.makeOrderBySchema(model, true, false, options), true).optional(),
|
|
6243
5795
|
select: this.makeCountAggregateInputSchema(model).optional()
|
|
6244
5796
|
}), "count").optional();
|
|
6245
5797
|
}
|
|
@@ -6258,12 +5810,12 @@ var InputValidator = class {
|
|
|
6258
5810
|
}
|
|
6259
5811
|
// #endregion
|
|
6260
5812
|
// #region Aggregate
|
|
6261
|
-
makeAggregateSchema(model) {
|
|
5813
|
+
makeAggregateSchema(model, options) {
|
|
6262
5814
|
return this.mergePluginArgsSchema(import_zod2.z.strictObject({
|
|
6263
|
-
where: this.makeWhereSchema(model, false).optional(),
|
|
5815
|
+
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
6264
5816
|
skip: this.makeSkipSchema().optional(),
|
|
6265
5817
|
take: this.makeTakeSchema().optional(),
|
|
6266
|
-
orderBy: this.orArray(this.makeOrderBySchema(model, true, false), true).optional(),
|
|
5818
|
+
orderBy: this.orArray(this.makeOrderBySchema(model, true, false, options), true).optional(),
|
|
6267
5819
|
_count: this.makeCountAggregateInputSchema(model).optional(),
|
|
6268
5820
|
_avg: this.makeSumAvgInputSchema(model).optional(),
|
|
6269
5821
|
_sum: this.makeSumAvgInputSchema(model).optional(),
|
|
@@ -6291,15 +5843,17 @@ var InputValidator = class {
|
|
|
6291
5843
|
return acc;
|
|
6292
5844
|
}, {}));
|
|
6293
5845
|
}
|
|
6294
|
-
|
|
5846
|
+
// #endregion
|
|
5847
|
+
// #region Group By
|
|
5848
|
+
makeGroupBySchema(model, options) {
|
|
6295
5849
|
const modelDef = requireModel(this.schema, model);
|
|
6296
5850
|
const nonRelationFields = Object.keys(modelDef.fields).filter((field) => !modelDef.fields[field]?.relation);
|
|
6297
5851
|
const bySchema = nonRelationFields.length > 0 ? this.orArray(import_zod2.z.enum(nonRelationFields), true) : import_zod2.z.never();
|
|
6298
5852
|
const baseSchema = import_zod2.z.strictObject({
|
|
6299
|
-
where: this.makeWhereSchema(model, false).optional(),
|
|
6300
|
-
orderBy: this.orArray(this.makeOrderBySchema(model, false, true), true).optional(),
|
|
5853
|
+
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
5854
|
+
orderBy: this.orArray(this.makeOrderBySchema(model, false, true, options), true).optional(),
|
|
6301
5855
|
by: bySchema,
|
|
6302
|
-
having: this.makeHavingSchema(model).optional(),
|
|
5856
|
+
having: this.makeHavingSchema(model, options).optional(),
|
|
6303
5857
|
skip: this.makeSkipSchema().optional(),
|
|
6304
5858
|
take: this.makeTakeSchema().optional(),
|
|
6305
5859
|
_count: this.makeCountAggregateInputSchema(model).optional(),
|
|
@@ -6310,9 +5864,7 @@ var InputValidator = class {
|
|
|
6310
5864
|
});
|
|
6311
5865
|
let schema = this.mergePluginArgsSchema(baseSchema, "groupBy");
|
|
6312
5866
|
schema = schema.refine((value) => {
|
|
6313
|
-
const bys =
|
|
6314
|
-
value.by
|
|
6315
|
-
] : value.by;
|
|
5867
|
+
const bys = (0, import_common_helpers8.enumerate)(value.by);
|
|
6316
5868
|
if (value.having && typeof value.having === "object") {
|
|
6317
5869
|
for (const [key, val] of Object.entries(value.having)) {
|
|
6318
5870
|
if (AggregateOperators.includes(key)) {
|
|
@@ -6332,14 +5884,13 @@ var InputValidator = class {
|
|
|
6332
5884
|
return true;
|
|
6333
5885
|
}, 'fields in "having" must be in "by"');
|
|
6334
5886
|
schema = schema.refine((value) => {
|
|
6335
|
-
const bys =
|
|
6336
|
-
|
|
6337
|
-
|
|
6338
|
-
|
|
6339
|
-
|
|
6340
|
-
} else {
|
|
6341
|
-
return true;
|
|
5887
|
+
const bys = (0, import_common_helpers8.enumerate)(value.by);
|
|
5888
|
+
for (const orderBy of (0, import_common_helpers8.enumerate)(value.orderBy)) {
|
|
5889
|
+
if (orderBy && Object.keys(orderBy).filter((f) => !AggregateOperators.includes(f)).some((key) => !bys.includes(key))) {
|
|
5890
|
+
return false;
|
|
5891
|
+
}
|
|
6342
5892
|
}
|
|
5893
|
+
return true;
|
|
6343
5894
|
}, 'fields in "orderBy" must be in "by"');
|
|
6344
5895
|
return schema;
|
|
6345
5896
|
}
|
|
@@ -6349,7 +5900,7 @@ var InputValidator = class {
|
|
|
6349
5900
|
continue;
|
|
6350
5901
|
}
|
|
6351
5902
|
if (LOGICAL_COMBINATORS.includes(key)) {
|
|
6352
|
-
if ((0,
|
|
5903
|
+
if ((0, import_common_helpers8.enumerate)(value).every((v) => this.onlyAggregationFields(v))) {
|
|
6353
5904
|
continue;
|
|
6354
5905
|
}
|
|
6355
5906
|
}
|
|
@@ -6357,12 +5908,12 @@ var InputValidator = class {
|
|
|
6357
5908
|
}
|
|
6358
5909
|
return true;
|
|
6359
5910
|
}
|
|
6360
|
-
makeHavingSchema(model) {
|
|
6361
|
-
return this.makeWhereSchema(model, false, true, true);
|
|
5911
|
+
makeHavingSchema(model, options) {
|
|
5912
|
+
return this.makeWhereSchema(model, false, true, true, options);
|
|
6362
5913
|
}
|
|
6363
5914
|
// #endregion
|
|
6364
5915
|
// #region Procedures
|
|
6365
|
-
makeProcedureParamSchema(param) {
|
|
5916
|
+
makeProcedureParamSchema(param, _options) {
|
|
6366
5917
|
let schema;
|
|
6367
5918
|
if (isTypeDef(this.schema, param.type)) {
|
|
6368
5919
|
schema = this.makeTypeDefSchema(param.type);
|
|
@@ -6385,21 +5936,54 @@ var InputValidator = class {
|
|
|
6385
5936
|
return schema;
|
|
6386
5937
|
}
|
|
6387
5938
|
// #endregion
|
|
6388
|
-
// #region
|
|
6389
|
-
|
|
6390
|
-
|
|
6391
|
-
|
|
6392
|
-
|
|
6393
|
-
|
|
5939
|
+
// #region Plugin Args
|
|
5940
|
+
mergePluginArgsSchema(schema, operation) {
|
|
5941
|
+
let result = schema;
|
|
5942
|
+
for (const plugin of this.plugins ?? []) {
|
|
5943
|
+
if (plugin.queryArgs) {
|
|
5944
|
+
const pluginSchema = this.getPluginExtQueryArgsSchema(plugin, operation);
|
|
5945
|
+
if (pluginSchema) {
|
|
5946
|
+
result = result.extend(pluginSchema.shape);
|
|
5947
|
+
}
|
|
5948
|
+
}
|
|
5949
|
+
}
|
|
5950
|
+
return result.strict();
|
|
6394
5951
|
}
|
|
6395
|
-
|
|
6396
|
-
|
|
6397
|
-
|
|
6398
|
-
|
|
6399
|
-
|
|
6400
|
-
|
|
5952
|
+
getPluginExtQueryArgsSchema(plugin, operation) {
|
|
5953
|
+
if (!plugin.queryArgs) {
|
|
5954
|
+
return void 0;
|
|
5955
|
+
}
|
|
5956
|
+
let result;
|
|
5957
|
+
if (operation in plugin.queryArgs && plugin.queryArgs[operation]) {
|
|
5958
|
+
result = plugin.queryArgs[operation];
|
|
5959
|
+
} else if (operation === "upsert") {
|
|
5960
|
+
const createSchema = "$create" in plugin.queryArgs && plugin.queryArgs["$create"] ? plugin.queryArgs["$create"] : void 0;
|
|
5961
|
+
const updateSchema = "$update" in plugin.queryArgs && plugin.queryArgs["$update"] ? plugin.queryArgs["$update"] : void 0;
|
|
5962
|
+
if (createSchema && updateSchema) {
|
|
5963
|
+
(0, import_common_helpers8.invariant)(createSchema instanceof import_zod2.ZodObject, "Plugin extended query args schema must be a Zod object");
|
|
5964
|
+
(0, import_common_helpers8.invariant)(updateSchema instanceof import_zod2.ZodObject, "Plugin extended query args schema must be a Zod object");
|
|
5965
|
+
result = createSchema.extend(updateSchema.shape);
|
|
5966
|
+
} else if (createSchema) {
|
|
5967
|
+
result = createSchema;
|
|
5968
|
+
} else if (updateSchema) {
|
|
5969
|
+
result = updateSchema;
|
|
6401
5970
|
}
|
|
5971
|
+
} else if (
|
|
5972
|
+
// then comes grouped operations: $create, $read, $update, $delete
|
|
5973
|
+
CoreCreateOperations.includes(operation) && "$create" in plugin.queryArgs && plugin.queryArgs["$create"]
|
|
5974
|
+
) {
|
|
5975
|
+
result = plugin.queryArgs["$create"];
|
|
5976
|
+
} else if (CoreReadOperations.includes(operation) && "$read" in plugin.queryArgs && plugin.queryArgs["$read"]) {
|
|
5977
|
+
result = plugin.queryArgs["$read"];
|
|
5978
|
+
} else if (CoreUpdateOperations.includes(operation) && "$update" in plugin.queryArgs && plugin.queryArgs["$update"]) {
|
|
5979
|
+
result = plugin.queryArgs["$update"];
|
|
5980
|
+
} else if (CoreDeleteOperations.includes(operation) && "$delete" in plugin.queryArgs && plugin.queryArgs["$delete"]) {
|
|
5981
|
+
result = plugin.queryArgs["$delete"];
|
|
5982
|
+
} else if ("$all" in plugin.queryArgs && plugin.queryArgs["$all"]) {
|
|
5983
|
+
result = plugin.queryArgs["$all"];
|
|
6402
5984
|
}
|
|
5985
|
+
(0, import_common_helpers8.invariant)(result === void 0 || result instanceof import_zod2.ZodObject, "Plugin extended query args schema must be a Zod object");
|
|
5986
|
+
return result;
|
|
6403
5987
|
}
|
|
6404
5988
|
// #endregion
|
|
6405
5989
|
// #region Helpers
|
|
@@ -6415,6 +5999,15 @@ var InputValidator = class {
|
|
|
6415
5999
|
refineForSelectOmitMutuallyExclusive(schema) {
|
|
6416
6000
|
return schema.refine((value) => !(value["select"] && value["omit"]), '"select" and "omit" cannot be used together');
|
|
6417
6001
|
}
|
|
6002
|
+
refineForSelectHasTruthyField(schema) {
|
|
6003
|
+
return schema.refine((value) => {
|
|
6004
|
+
const select = value["select"];
|
|
6005
|
+
if (!select || typeof select !== "object") {
|
|
6006
|
+
return true;
|
|
6007
|
+
}
|
|
6008
|
+
return Object.values(select).some((v) => v);
|
|
6009
|
+
}, '"select" must have at least one truthy value');
|
|
6010
|
+
}
|
|
6418
6011
|
nullableIf(schema, nullable) {
|
|
6419
6012
|
return nullable ? schema.nullable() : schema;
|
|
6420
6013
|
}
|
|
@@ -6443,7 +6036,7 @@ var InputValidator = class {
|
|
|
6443
6036
|
return void 0;
|
|
6444
6037
|
}
|
|
6445
6038
|
const modelsRecord = slicing.models;
|
|
6446
|
-
const modelConfig = modelsRecord[(0,
|
|
6039
|
+
const modelConfig = modelsRecord[(0, import_common_helpers8.lowerCaseFirst)(model)];
|
|
6447
6040
|
if (modelConfig?.fields) {
|
|
6448
6041
|
const fieldConfig = modelConfig.fields[field];
|
|
6449
6042
|
if (fieldConfig) {
|
|
@@ -6544,18 +6137,20 @@ _ts_decorate([
|
|
|
6544
6137
|
_ts_metadata("design:type", Function),
|
|
6545
6138
|
_ts_metadata("design:paramtypes", [
|
|
6546
6139
|
String,
|
|
6547
|
-
typeof CoreCrudOperations === "undefined" ? Object : CoreCrudOperations
|
|
6140
|
+
typeof CoreCrudOperations === "undefined" ? Object : CoreCrudOperations,
|
|
6141
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6548
6142
|
]),
|
|
6549
6143
|
_ts_metadata("design:returntype", void 0)
|
|
6550
|
-
],
|
|
6144
|
+
], ZodSchemaFactory.prototype, "makeFindSchema", null);
|
|
6551
6145
|
_ts_decorate([
|
|
6552
6146
|
cache(),
|
|
6553
6147
|
_ts_metadata("design:type", Function),
|
|
6554
6148
|
_ts_metadata("design:paramtypes", [
|
|
6555
|
-
|
|
6149
|
+
typeof Model === "undefined" ? Object : Model,
|
|
6150
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6556
6151
|
]),
|
|
6557
|
-
_ts_metadata("design:returntype",
|
|
6558
|
-
],
|
|
6152
|
+
_ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
|
|
6153
|
+
], ZodSchemaFactory.prototype, "makeExistsSchema", null);
|
|
6559
6154
|
_ts_decorate([
|
|
6560
6155
|
cache(),
|
|
6561
6156
|
_ts_metadata("design:type", Function),
|
|
@@ -6563,15 +6158,15 @@ _ts_decorate([
|
|
|
6563
6158
|
String
|
|
6564
6159
|
]),
|
|
6565
6160
|
_ts_metadata("design:returntype", void 0)
|
|
6566
|
-
],
|
|
6161
|
+
], ZodSchemaFactory.prototype, "makeEnumSchema", null);
|
|
6567
6162
|
_ts_decorate([
|
|
6568
6163
|
cache(),
|
|
6569
6164
|
_ts_metadata("design:type", Function),
|
|
6570
6165
|
_ts_metadata("design:paramtypes", [
|
|
6571
6166
|
String
|
|
6572
6167
|
]),
|
|
6573
|
-
_ts_metadata("design:returntype", typeof import_zod2.
|
|
6574
|
-
],
|
|
6168
|
+
_ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
|
|
6169
|
+
], ZodSchemaFactory.prototype, "makeTypeDefSchema", null);
|
|
6575
6170
|
_ts_decorate([
|
|
6576
6171
|
cache(),
|
|
6577
6172
|
_ts_metadata("design:type", Function),
|
|
@@ -6579,10 +6174,11 @@ _ts_decorate([
|
|
|
6579
6174
|
String,
|
|
6580
6175
|
Boolean,
|
|
6581
6176
|
void 0,
|
|
6582
|
-
void 0
|
|
6177
|
+
void 0,
|
|
6178
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6583
6179
|
]),
|
|
6584
6180
|
_ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
|
|
6585
|
-
],
|
|
6181
|
+
], ZodSchemaFactory.prototype, "makeWhereSchema", null);
|
|
6586
6182
|
_ts_decorate([
|
|
6587
6183
|
cache(),
|
|
6588
6184
|
_ts_metadata("design:type", Function),
|
|
@@ -6591,7 +6187,7 @@ _ts_decorate([
|
|
|
6591
6187
|
typeof FieldInfo === "undefined" ? Object : FieldInfo
|
|
6592
6188
|
]),
|
|
6593
6189
|
_ts_metadata("design:returntype", void 0)
|
|
6594
|
-
],
|
|
6190
|
+
], ZodSchemaFactory.prototype, "makeTypedJsonFilterSchema", null);
|
|
6595
6191
|
_ts_decorate([
|
|
6596
6192
|
cache(),
|
|
6597
6193
|
_ts_metadata("design:type", Function),
|
|
@@ -6602,7 +6198,7 @@ _ts_decorate([
|
|
|
6602
6198
|
Boolean
|
|
6603
6199
|
]),
|
|
6604
6200
|
_ts_metadata("design:returntype", void 0)
|
|
6605
|
-
],
|
|
6201
|
+
], ZodSchemaFactory.prototype, "makeEnumFilterSchema", null);
|
|
6606
6202
|
_ts_decorate([
|
|
6607
6203
|
cache(),
|
|
6608
6204
|
_ts_metadata("design:type", Function),
|
|
@@ -6611,7 +6207,7 @@ _ts_decorate([
|
|
|
6611
6207
|
typeof FieldInfo === "undefined" ? Object : FieldInfo
|
|
6612
6208
|
]),
|
|
6613
6209
|
_ts_metadata("design:returntype", void 0)
|
|
6614
|
-
],
|
|
6210
|
+
], ZodSchemaFactory.prototype, "makeArrayFilterSchema", null);
|
|
6615
6211
|
_ts_decorate([
|
|
6616
6212
|
cache(),
|
|
6617
6213
|
_ts_metadata("design:type", Function),
|
|
@@ -6622,7 +6218,7 @@ _ts_decorate([
|
|
|
6622
6218
|
void 0
|
|
6623
6219
|
]),
|
|
6624
6220
|
_ts_metadata("design:returntype", void 0)
|
|
6625
|
-
],
|
|
6221
|
+
], ZodSchemaFactory.prototype, "makePrimitiveFilterSchema", null);
|
|
6626
6222
|
_ts_decorate([
|
|
6627
6223
|
cache(),
|
|
6628
6224
|
_ts_metadata("design:type", Function),
|
|
@@ -6632,7 +6228,7 @@ _ts_decorate([
|
|
|
6632
6228
|
Boolean
|
|
6633
6229
|
]),
|
|
6634
6230
|
_ts_metadata("design:returntype", void 0)
|
|
6635
|
-
],
|
|
6231
|
+
], ZodSchemaFactory.prototype, "makeJsonFilterSchema", null);
|
|
6636
6232
|
_ts_decorate([
|
|
6637
6233
|
cache(),
|
|
6638
6234
|
_ts_metadata("design:type", Function),
|
|
@@ -6642,7 +6238,7 @@ _ts_decorate([
|
|
|
6642
6238
|
Object
|
|
6643
6239
|
]),
|
|
6644
6240
|
_ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
|
|
6645
|
-
],
|
|
6241
|
+
], ZodSchemaFactory.prototype, "makeDateTimeFilterSchema", null);
|
|
6646
6242
|
_ts_decorate([
|
|
6647
6243
|
cache(),
|
|
6648
6244
|
_ts_metadata("design:type", Function),
|
|
@@ -6652,7 +6248,7 @@ _ts_decorate([
|
|
|
6652
6248
|
Object
|
|
6653
6249
|
]),
|
|
6654
6250
|
_ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
|
|
6655
|
-
],
|
|
6251
|
+
], ZodSchemaFactory.prototype, "makeBooleanFilterSchema", null);
|
|
6656
6252
|
_ts_decorate([
|
|
6657
6253
|
cache(),
|
|
6658
6254
|
_ts_metadata("design:type", Function),
|
|
@@ -6662,32 +6258,35 @@ _ts_decorate([
|
|
|
6662
6258
|
Object
|
|
6663
6259
|
]),
|
|
6664
6260
|
_ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
|
|
6665
|
-
],
|
|
6261
|
+
], ZodSchemaFactory.prototype, "makeBytesFilterSchema", null);
|
|
6666
6262
|
_ts_decorate([
|
|
6667
6263
|
cache(),
|
|
6668
6264
|
_ts_metadata("design:type", Function),
|
|
6669
6265
|
_ts_metadata("design:paramtypes", [
|
|
6670
|
-
String
|
|
6266
|
+
String,
|
|
6267
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6671
6268
|
]),
|
|
6672
6269
|
_ts_metadata("design:returntype", void 0)
|
|
6673
|
-
],
|
|
6270
|
+
], ZodSchemaFactory.prototype, "makeSelectSchema", null);
|
|
6674
6271
|
_ts_decorate([
|
|
6675
6272
|
cache(),
|
|
6676
6273
|
_ts_metadata("design:type", Function),
|
|
6677
6274
|
_ts_metadata("design:paramtypes", [
|
|
6678
|
-
String
|
|
6275
|
+
String,
|
|
6276
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6679
6277
|
]),
|
|
6680
6278
|
_ts_metadata("design:returntype", void 0)
|
|
6681
|
-
],
|
|
6279
|
+
], ZodSchemaFactory.prototype, "makeCountSelectionSchema", null);
|
|
6682
6280
|
_ts_decorate([
|
|
6683
6281
|
cache(),
|
|
6684
6282
|
_ts_metadata("design:type", Function),
|
|
6685
6283
|
_ts_metadata("design:paramtypes", [
|
|
6686
6284
|
String,
|
|
6687
|
-
String
|
|
6285
|
+
String,
|
|
6286
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6688
6287
|
]),
|
|
6689
6288
|
_ts_metadata("design:returntype", void 0)
|
|
6690
|
-
],
|
|
6289
|
+
], ZodSchemaFactory.prototype, "makeRelationSelectIncludeSchema", null);
|
|
6691
6290
|
_ts_decorate([
|
|
6692
6291
|
cache(),
|
|
6693
6292
|
_ts_metadata("design:type", Function),
|
|
@@ -6695,25 +6294,27 @@ _ts_decorate([
|
|
|
6695
6294
|
String
|
|
6696
6295
|
]),
|
|
6697
6296
|
_ts_metadata("design:returntype", void 0)
|
|
6698
|
-
],
|
|
6297
|
+
], ZodSchemaFactory.prototype, "makeOmitSchema", null);
|
|
6699
6298
|
_ts_decorate([
|
|
6700
6299
|
cache(),
|
|
6701
6300
|
_ts_metadata("design:type", Function),
|
|
6702
6301
|
_ts_metadata("design:paramtypes", [
|
|
6703
|
-
String
|
|
6302
|
+
String,
|
|
6303
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6704
6304
|
]),
|
|
6705
6305
|
_ts_metadata("design:returntype", void 0)
|
|
6706
|
-
],
|
|
6306
|
+
], ZodSchemaFactory.prototype, "makeIncludeSchema", null);
|
|
6707
6307
|
_ts_decorate([
|
|
6708
6308
|
cache(),
|
|
6709
6309
|
_ts_metadata("design:type", Function),
|
|
6710
6310
|
_ts_metadata("design:paramtypes", [
|
|
6711
6311
|
String,
|
|
6712
6312
|
Boolean,
|
|
6713
|
-
Boolean
|
|
6313
|
+
Boolean,
|
|
6314
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6714
6315
|
]),
|
|
6715
6316
|
_ts_metadata("design:returntype", void 0)
|
|
6716
|
-
],
|
|
6317
|
+
], ZodSchemaFactory.prototype, "makeOrderBySchema", null);
|
|
6717
6318
|
_ts_decorate([
|
|
6718
6319
|
cache(),
|
|
6719
6320
|
_ts_metadata("design:type", Function),
|
|
@@ -6721,31 +6322,34 @@ _ts_decorate([
|
|
|
6721
6322
|
String
|
|
6722
6323
|
]),
|
|
6723
6324
|
_ts_metadata("design:returntype", void 0)
|
|
6724
|
-
],
|
|
6325
|
+
], ZodSchemaFactory.prototype, "makeDistinctSchema", null);
|
|
6725
6326
|
_ts_decorate([
|
|
6726
6327
|
cache(),
|
|
6727
6328
|
_ts_metadata("design:type", Function),
|
|
6728
6329
|
_ts_metadata("design:paramtypes", [
|
|
6729
|
-
|
|
6330
|
+
typeof Model === "undefined" ? Object : Model,
|
|
6331
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6730
6332
|
]),
|
|
6731
|
-
_ts_metadata("design:returntype",
|
|
6732
|
-
],
|
|
6333
|
+
_ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
|
|
6334
|
+
], ZodSchemaFactory.prototype, "makeCreateSchema", null);
|
|
6733
6335
|
_ts_decorate([
|
|
6734
6336
|
cache(),
|
|
6735
6337
|
_ts_metadata("design:type", Function),
|
|
6736
6338
|
_ts_metadata("design:paramtypes", [
|
|
6737
|
-
|
|
6339
|
+
typeof Model === "undefined" ? Object : Model,
|
|
6340
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6738
6341
|
]),
|
|
6739
|
-
_ts_metadata("design:returntype",
|
|
6740
|
-
],
|
|
6342
|
+
_ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
|
|
6343
|
+
], ZodSchemaFactory.prototype, "makeCreateManySchema", null);
|
|
6741
6344
|
_ts_decorate([
|
|
6742
6345
|
cache(),
|
|
6743
6346
|
_ts_metadata("design:type", Function),
|
|
6744
6347
|
_ts_metadata("design:paramtypes", [
|
|
6745
|
-
|
|
6348
|
+
typeof Model === "undefined" ? Object : Model,
|
|
6349
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6746
6350
|
]),
|
|
6747
|
-
_ts_metadata("design:returntype",
|
|
6748
|
-
],
|
|
6351
|
+
_ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
|
|
6352
|
+
], ZodSchemaFactory.prototype, "makeCreateManyAndReturnSchema", null);
|
|
6749
6353
|
_ts_decorate([
|
|
6750
6354
|
cache(),
|
|
6751
6355
|
_ts_metadata("design:type", Function),
|
|
@@ -6753,10 +6357,11 @@ _ts_decorate([
|
|
|
6753
6357
|
String,
|
|
6754
6358
|
Boolean,
|
|
6755
6359
|
Array,
|
|
6756
|
-
void 0
|
|
6360
|
+
void 0,
|
|
6361
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6757
6362
|
]),
|
|
6758
6363
|
_ts_metadata("design:returntype", void 0)
|
|
6759
|
-
],
|
|
6364
|
+
], ZodSchemaFactory.prototype, "makeCreateDataSchema", null);
|
|
6760
6365
|
_ts_decorate([
|
|
6761
6366
|
cache(),
|
|
6762
6367
|
_ts_metadata("design:type", Function),
|
|
@@ -6764,132 +6369,147 @@ _ts_decorate([
|
|
|
6764
6369
|
String,
|
|
6765
6370
|
String,
|
|
6766
6371
|
Array,
|
|
6767
|
-
String
|
|
6372
|
+
String,
|
|
6373
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6768
6374
|
]),
|
|
6769
6375
|
_ts_metadata("design:returntype", void 0)
|
|
6770
|
-
],
|
|
6376
|
+
], ZodSchemaFactory.prototype, "makeRelationManipulationSchema", null);
|
|
6771
6377
|
_ts_decorate([
|
|
6772
6378
|
cache(),
|
|
6773
6379
|
_ts_metadata("design:type", Function),
|
|
6774
6380
|
_ts_metadata("design:paramtypes", [
|
|
6775
6381
|
String,
|
|
6776
|
-
Boolean
|
|
6382
|
+
Boolean,
|
|
6383
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6777
6384
|
]),
|
|
6778
6385
|
_ts_metadata("design:returntype", void 0)
|
|
6779
|
-
],
|
|
6386
|
+
], ZodSchemaFactory.prototype, "makeSetDataSchema", null);
|
|
6780
6387
|
_ts_decorate([
|
|
6781
6388
|
cache(),
|
|
6782
6389
|
_ts_metadata("design:type", Function),
|
|
6783
6390
|
_ts_metadata("design:paramtypes", [
|
|
6784
6391
|
String,
|
|
6785
|
-
Boolean
|
|
6392
|
+
Boolean,
|
|
6393
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6786
6394
|
]),
|
|
6787
6395
|
_ts_metadata("design:returntype", void 0)
|
|
6788
|
-
],
|
|
6396
|
+
], ZodSchemaFactory.prototype, "makeConnectDataSchema", null);
|
|
6789
6397
|
_ts_decorate([
|
|
6790
6398
|
cache(),
|
|
6791
6399
|
_ts_metadata("design:type", Function),
|
|
6792
6400
|
_ts_metadata("design:paramtypes", [
|
|
6793
6401
|
String,
|
|
6794
|
-
Boolean
|
|
6402
|
+
Boolean,
|
|
6403
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6795
6404
|
]),
|
|
6796
6405
|
_ts_metadata("design:returntype", void 0)
|
|
6797
|
-
],
|
|
6406
|
+
], ZodSchemaFactory.prototype, "makeDisconnectDataSchema", null);
|
|
6798
6407
|
_ts_decorate([
|
|
6799
6408
|
cache(),
|
|
6800
6409
|
_ts_metadata("design:type", Function),
|
|
6801
6410
|
_ts_metadata("design:paramtypes", [
|
|
6802
6411
|
String,
|
|
6803
6412
|
Boolean,
|
|
6804
|
-
Boolean
|
|
6413
|
+
Boolean,
|
|
6414
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6805
6415
|
]),
|
|
6806
6416
|
_ts_metadata("design:returntype", void 0)
|
|
6807
|
-
],
|
|
6417
|
+
], ZodSchemaFactory.prototype, "makeDeleteRelationDataSchema", null);
|
|
6808
6418
|
_ts_decorate([
|
|
6809
6419
|
cache(),
|
|
6810
6420
|
_ts_metadata("design:type", Function),
|
|
6811
6421
|
_ts_metadata("design:paramtypes", [
|
|
6812
6422
|
String,
|
|
6813
6423
|
Boolean,
|
|
6814
|
-
Array
|
|
6424
|
+
Array,
|
|
6425
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6815
6426
|
]),
|
|
6816
6427
|
_ts_metadata("design:returntype", void 0)
|
|
6817
|
-
],
|
|
6428
|
+
], ZodSchemaFactory.prototype, "makeConnectOrCreateDataSchema", null);
|
|
6818
6429
|
_ts_decorate([
|
|
6819
6430
|
cache(),
|
|
6820
6431
|
_ts_metadata("design:type", Function),
|
|
6821
6432
|
_ts_metadata("design:paramtypes", [
|
|
6822
6433
|
String,
|
|
6823
|
-
Array
|
|
6434
|
+
Array,
|
|
6435
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6824
6436
|
]),
|
|
6825
6437
|
_ts_metadata("design:returntype", void 0)
|
|
6826
|
-
],
|
|
6438
|
+
], ZodSchemaFactory.prototype, "makeCreateManyPayloadSchema", null);
|
|
6827
6439
|
_ts_decorate([
|
|
6828
6440
|
cache(),
|
|
6829
6441
|
_ts_metadata("design:type", Function),
|
|
6830
6442
|
_ts_metadata("design:paramtypes", [
|
|
6831
|
-
|
|
6443
|
+
typeof Model === "undefined" ? Object : Model,
|
|
6444
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6832
6445
|
]),
|
|
6833
|
-
_ts_metadata("design:returntype",
|
|
6834
|
-
],
|
|
6446
|
+
_ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
|
|
6447
|
+
], ZodSchemaFactory.prototype, "makeUpdateSchema", null);
|
|
6835
6448
|
_ts_decorate([
|
|
6836
6449
|
cache(),
|
|
6837
6450
|
_ts_metadata("design:type", Function),
|
|
6838
6451
|
_ts_metadata("design:paramtypes", [
|
|
6839
|
-
|
|
6452
|
+
typeof Model === "undefined" ? Object : Model,
|
|
6453
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6840
6454
|
]),
|
|
6841
|
-
_ts_metadata("design:returntype",
|
|
6842
|
-
],
|
|
6455
|
+
_ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
|
|
6456
|
+
], ZodSchemaFactory.prototype, "makeUpdateManySchema", null);
|
|
6843
6457
|
_ts_decorate([
|
|
6844
6458
|
cache(),
|
|
6845
6459
|
_ts_metadata("design:type", Function),
|
|
6846
6460
|
_ts_metadata("design:paramtypes", [
|
|
6847
|
-
|
|
6461
|
+
typeof Model === "undefined" ? Object : Model,
|
|
6462
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6848
6463
|
]),
|
|
6849
|
-
_ts_metadata("design:returntype",
|
|
6850
|
-
],
|
|
6464
|
+
_ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
|
|
6465
|
+
], ZodSchemaFactory.prototype, "makeUpdateManyAndReturnSchema", null);
|
|
6851
6466
|
_ts_decorate([
|
|
6852
6467
|
cache(),
|
|
6853
6468
|
_ts_metadata("design:type", Function),
|
|
6854
6469
|
_ts_metadata("design:paramtypes", [
|
|
6855
|
-
|
|
6470
|
+
typeof Model === "undefined" ? Object : Model,
|
|
6471
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6856
6472
|
]),
|
|
6857
|
-
_ts_metadata("design:returntype",
|
|
6858
|
-
],
|
|
6473
|
+
_ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
|
|
6474
|
+
], ZodSchemaFactory.prototype, "makeUpsertSchema", null);
|
|
6859
6475
|
_ts_decorate([
|
|
6860
6476
|
cache(),
|
|
6861
6477
|
_ts_metadata("design:type", Function),
|
|
6862
6478
|
_ts_metadata("design:paramtypes", [
|
|
6863
6479
|
String,
|
|
6864
6480
|
Array,
|
|
6865
|
-
void 0
|
|
6481
|
+
void 0,
|
|
6482
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6866
6483
|
]),
|
|
6867
6484
|
_ts_metadata("design:returntype", void 0)
|
|
6868
|
-
],
|
|
6485
|
+
], ZodSchemaFactory.prototype, "makeUpdateDataSchema", null);
|
|
6869
6486
|
_ts_decorate([
|
|
6870
6487
|
cache(),
|
|
6871
6488
|
_ts_metadata("design:type", Function),
|
|
6872
6489
|
_ts_metadata("design:paramtypes", [
|
|
6873
|
-
|
|
6490
|
+
typeof Model === "undefined" ? Object : Model,
|
|
6491
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6874
6492
|
]),
|
|
6875
|
-
_ts_metadata("design:returntype",
|
|
6876
|
-
],
|
|
6493
|
+
_ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
|
|
6494
|
+
], ZodSchemaFactory.prototype, "makeDeleteSchema", null);
|
|
6877
6495
|
_ts_decorate([
|
|
6878
6496
|
cache(),
|
|
6879
6497
|
_ts_metadata("design:type", Function),
|
|
6880
6498
|
_ts_metadata("design:paramtypes", [
|
|
6881
|
-
|
|
6499
|
+
typeof Model === "undefined" ? Object : Model,
|
|
6500
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6882
6501
|
]),
|
|
6883
|
-
_ts_metadata("design:returntype",
|
|
6884
|
-
],
|
|
6502
|
+
_ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
|
|
6503
|
+
], ZodSchemaFactory.prototype, "makeDeleteManySchema", null);
|
|
6885
6504
|
_ts_decorate([
|
|
6886
6505
|
cache(),
|
|
6887
6506
|
_ts_metadata("design:type", Function),
|
|
6888
6507
|
_ts_metadata("design:paramtypes", [
|
|
6889
|
-
|
|
6508
|
+
typeof Model === "undefined" ? Object : Model,
|
|
6509
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6890
6510
|
]),
|
|
6891
|
-
_ts_metadata("design:returntype",
|
|
6892
|
-
],
|
|
6511
|
+
_ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
|
|
6512
|
+
], ZodSchemaFactory.prototype, "makeCountSchema", null);
|
|
6893
6513
|
_ts_decorate([
|
|
6894
6514
|
cache(),
|
|
6895
6515
|
_ts_metadata("design:type", Function),
|
|
@@ -6897,15 +6517,16 @@ _ts_decorate([
|
|
|
6897
6517
|
String
|
|
6898
6518
|
]),
|
|
6899
6519
|
_ts_metadata("design:returntype", void 0)
|
|
6900
|
-
],
|
|
6520
|
+
], ZodSchemaFactory.prototype, "makeCountAggregateInputSchema", null);
|
|
6901
6521
|
_ts_decorate([
|
|
6902
6522
|
cache(),
|
|
6903
6523
|
_ts_metadata("design:type", Function),
|
|
6904
6524
|
_ts_metadata("design:paramtypes", [
|
|
6905
|
-
|
|
6525
|
+
typeof Model === "undefined" ? Object : Model,
|
|
6526
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6906
6527
|
]),
|
|
6907
|
-
_ts_metadata("design:returntype",
|
|
6908
|
-
],
|
|
6528
|
+
_ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
|
|
6529
|
+
], ZodSchemaFactory.prototype, "makeAggregateSchema", null);
|
|
6909
6530
|
_ts_decorate([
|
|
6910
6531
|
cache(),
|
|
6911
6532
|
_ts_metadata("design:type", Function),
|
|
@@ -6913,7 +6534,7 @@ _ts_decorate([
|
|
|
6913
6534
|
String
|
|
6914
6535
|
]),
|
|
6915
6536
|
_ts_metadata("design:returntype", void 0)
|
|
6916
|
-
],
|
|
6537
|
+
], ZodSchemaFactory.prototype, "makeSumAvgInputSchema", null);
|
|
6917
6538
|
_ts_decorate([
|
|
6918
6539
|
cache(),
|
|
6919
6540
|
_ts_metadata("design:type", Function),
|
|
@@ -6921,35 +6542,168 @@ _ts_decorate([
|
|
|
6921
6542
|
String
|
|
6922
6543
|
]),
|
|
6923
6544
|
_ts_metadata("design:returntype", void 0)
|
|
6924
|
-
],
|
|
6545
|
+
], ZodSchemaFactory.prototype, "makeMinMaxInputSchema", null);
|
|
6925
6546
|
_ts_decorate([
|
|
6926
6547
|
cache(),
|
|
6927
6548
|
_ts_metadata("design:type", Function),
|
|
6928
6549
|
_ts_metadata("design:paramtypes", [
|
|
6929
|
-
|
|
6550
|
+
typeof Model === "undefined" ? Object : Model,
|
|
6551
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6930
6552
|
]),
|
|
6931
|
-
_ts_metadata("design:returntype",
|
|
6932
|
-
],
|
|
6553
|
+
_ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
|
|
6554
|
+
], ZodSchemaFactory.prototype, "makeGroupBySchema", null);
|
|
6933
6555
|
_ts_decorate([
|
|
6934
6556
|
cache(),
|
|
6935
6557
|
_ts_metadata("design:type", Function),
|
|
6936
6558
|
_ts_metadata("design:paramtypes", [
|
|
6937
|
-
Object
|
|
6559
|
+
Object,
|
|
6560
|
+
typeof CreateSchemaOptions === "undefined" ? Object : CreateSchemaOptions
|
|
6938
6561
|
]),
|
|
6939
|
-
_ts_metadata("design:returntype", typeof import_zod2.
|
|
6940
|
-
],
|
|
6562
|
+
_ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
|
|
6563
|
+
], ZodSchemaFactory.prototype, "makeProcedureParamSchema", null);
|
|
6941
6564
|
_ts_decorate([
|
|
6942
6565
|
cache(),
|
|
6943
6566
|
_ts_metadata("design:type", Function),
|
|
6944
6567
|
_ts_metadata("design:paramtypes", []),
|
|
6945
6568
|
_ts_metadata("design:returntype", void 0)
|
|
6946
|
-
],
|
|
6569
|
+
], ZodSchemaFactory.prototype, "makeSkipSchema", null);
|
|
6947
6570
|
_ts_decorate([
|
|
6948
6571
|
cache(),
|
|
6949
6572
|
_ts_metadata("design:type", Function),
|
|
6950
6573
|
_ts_metadata("design:paramtypes", []),
|
|
6951
6574
|
_ts_metadata("design:returntype", void 0)
|
|
6952
|
-
],
|
|
6575
|
+
], ZodSchemaFactory.prototype, "makeTakeSchema", null);
|
|
6576
|
+
|
|
6577
|
+
// src/client/crud/validator/validator.ts
|
|
6578
|
+
var InputValidator = class {
|
|
6579
|
+
static {
|
|
6580
|
+
__name(this, "InputValidator");
|
|
6581
|
+
}
|
|
6582
|
+
client;
|
|
6583
|
+
zodFactory;
|
|
6584
|
+
constructor(client) {
|
|
6585
|
+
this.client = client;
|
|
6586
|
+
this.zodFactory = new ZodSchemaFactory(client);
|
|
6587
|
+
}
|
|
6588
|
+
// #region Entry points
|
|
6589
|
+
validateFindArgs(model, args, operation) {
|
|
6590
|
+
return this.validate(model, operation, (model2) => (0, import_ts_pattern14.match)(operation).with("findFirst", () => this.zodFactory.makeFindFirstSchema(model2)).with("findUnique", () => this.zodFactory.makeFindUniqueSchema(model2)).with("findMany", () => this.zodFactory.makeFindManySchema(model2)).exhaustive(), args);
|
|
6591
|
+
}
|
|
6592
|
+
validateExistsArgs(model, args) {
|
|
6593
|
+
return this.validate(model, "exists", (model2) => this.zodFactory.makeExistsSchema(model2), args);
|
|
6594
|
+
}
|
|
6595
|
+
validateCreateArgs(model, args) {
|
|
6596
|
+
return this.validate(model, "create", (model2) => this.zodFactory.makeCreateSchema(model2), args);
|
|
6597
|
+
}
|
|
6598
|
+
validateCreateManyArgs(model, args) {
|
|
6599
|
+
return this.validate(model, "createMany", (model2) => this.zodFactory.makeCreateManySchema(model2), args);
|
|
6600
|
+
}
|
|
6601
|
+
validateCreateManyAndReturnArgs(model, args) {
|
|
6602
|
+
return this.validate(model, "createManyAndReturn", (model2) => this.zodFactory.makeCreateManyAndReturnSchema(model2), args);
|
|
6603
|
+
}
|
|
6604
|
+
validateUpdateArgs(model, args) {
|
|
6605
|
+
return this.validate(model, "update", (model2) => this.zodFactory.makeUpdateSchema(model2), args);
|
|
6606
|
+
}
|
|
6607
|
+
validateUpdateManyArgs(model, args) {
|
|
6608
|
+
return this.validate(model, "updateMany", (model2) => this.zodFactory.makeUpdateManySchema(model2), args);
|
|
6609
|
+
}
|
|
6610
|
+
validateUpdateManyAndReturnArgs(model, args) {
|
|
6611
|
+
return this.validate(model, "updateManyAndReturn", (model2) => this.zodFactory.makeUpdateManyAndReturnSchema(model2), args);
|
|
6612
|
+
}
|
|
6613
|
+
validateUpsertArgs(model, args) {
|
|
6614
|
+
return this.validate(model, "upsert", (model2) => this.zodFactory.makeUpsertSchema(model2), args);
|
|
6615
|
+
}
|
|
6616
|
+
validateDeleteArgs(model, args) {
|
|
6617
|
+
return this.validate(model, "delete", (model2) => this.zodFactory.makeDeleteSchema(model2), args);
|
|
6618
|
+
}
|
|
6619
|
+
validateDeleteManyArgs(model, args) {
|
|
6620
|
+
return this.validate(model, "deleteMany", (model2) => this.zodFactory.makeDeleteManySchema(model2), args);
|
|
6621
|
+
}
|
|
6622
|
+
validateCountArgs(model, args) {
|
|
6623
|
+
return this.validate(model, "count", (model2) => this.zodFactory.makeCountSchema(model2), args);
|
|
6624
|
+
}
|
|
6625
|
+
validateAggregateArgs(model, args) {
|
|
6626
|
+
return this.validate(model, "aggregate", (model2) => this.zodFactory.makeAggregateSchema(model2), args);
|
|
6627
|
+
}
|
|
6628
|
+
validateGroupByArgs(model, args) {
|
|
6629
|
+
return this.validate(model, "groupBy", (model2) => this.zodFactory.makeGroupBySchema(model2), args);
|
|
6630
|
+
}
|
|
6631
|
+
// TODO: turn it into a Zod schema and cache
|
|
6632
|
+
validateProcedureInput(proc, input) {
|
|
6633
|
+
const procDef = (this.client.$schema.procedures ?? {})[proc];
|
|
6634
|
+
(0, import_common_helpers9.invariant)(procDef, `Procedure "${proc}" not found in schema`);
|
|
6635
|
+
const params = Object.values(procDef.params ?? {});
|
|
6636
|
+
if (typeof input === "undefined") {
|
|
6637
|
+
if (params.length === 0) {
|
|
6638
|
+
return void 0;
|
|
6639
|
+
}
|
|
6640
|
+
if (params.every((p) => p.optional)) {
|
|
6641
|
+
return void 0;
|
|
6642
|
+
}
|
|
6643
|
+
throw createInvalidInputError("Missing procedure arguments", `$procs.${proc}`);
|
|
6644
|
+
}
|
|
6645
|
+
if (typeof input !== "object" || input === null || Array.isArray(input)) {
|
|
6646
|
+
throw createInvalidInputError("Procedure input must be an object", `$procs.${proc}`);
|
|
6647
|
+
}
|
|
6648
|
+
const envelope = input;
|
|
6649
|
+
const argsPayload = Object.prototype.hasOwnProperty.call(envelope, "args") ? envelope.args : void 0;
|
|
6650
|
+
if (params.length === 0) {
|
|
6651
|
+
if (typeof argsPayload === "undefined") {
|
|
6652
|
+
return input;
|
|
6653
|
+
}
|
|
6654
|
+
if (!argsPayload || typeof argsPayload !== "object" || Array.isArray(argsPayload)) {
|
|
6655
|
+
throw createInvalidInputError("Procedure `args` must be an object", `$procs.${proc}`);
|
|
6656
|
+
}
|
|
6657
|
+
if (Object.keys(argsPayload).length === 0) {
|
|
6658
|
+
return input;
|
|
6659
|
+
}
|
|
6660
|
+
throw createInvalidInputError("Procedure does not accept arguments", `$procs.${proc}`);
|
|
6661
|
+
}
|
|
6662
|
+
if (typeof argsPayload === "undefined") {
|
|
6663
|
+
if (params.every((p) => p.optional)) {
|
|
6664
|
+
return input;
|
|
6665
|
+
}
|
|
6666
|
+
throw createInvalidInputError("Missing procedure arguments", `$procs.${proc}`);
|
|
6667
|
+
}
|
|
6668
|
+
if (!argsPayload || typeof argsPayload !== "object" || Array.isArray(argsPayload)) {
|
|
6669
|
+
throw createInvalidInputError("Procedure `args` must be an object", `$procs.${proc}`);
|
|
6670
|
+
}
|
|
6671
|
+
const obj = argsPayload;
|
|
6672
|
+
for (const param of params) {
|
|
6673
|
+
const value = obj[param.name];
|
|
6674
|
+
if (!Object.prototype.hasOwnProperty.call(obj, param.name)) {
|
|
6675
|
+
if (param.optional) {
|
|
6676
|
+
continue;
|
|
6677
|
+
}
|
|
6678
|
+
throw createInvalidInputError(`Missing procedure argument: ${param.name}`, `$procs.${proc}`);
|
|
6679
|
+
}
|
|
6680
|
+
if (typeof value === "undefined") {
|
|
6681
|
+
if (param.optional) {
|
|
6682
|
+
continue;
|
|
6683
|
+
}
|
|
6684
|
+
throw createInvalidInputError(`Invalid procedure argument: ${param.name} is required`, `$procs.${proc}`);
|
|
6685
|
+
}
|
|
6686
|
+
const schema = this.zodFactory.makeProcedureParamSchema(param);
|
|
6687
|
+
const parsed = schema.safeParse(value);
|
|
6688
|
+
if (!parsed.success) {
|
|
6689
|
+
throw createInvalidInputError(`Invalid procedure argument: ${param.name}: ${formatError(parsed.error)}`, `$procs.${proc}`);
|
|
6690
|
+
}
|
|
6691
|
+
}
|
|
6692
|
+
return input;
|
|
6693
|
+
}
|
|
6694
|
+
// #endregion
|
|
6695
|
+
// #region Validation helpers
|
|
6696
|
+
validate(model, operation, getSchema, args) {
|
|
6697
|
+
const schema = getSchema(model);
|
|
6698
|
+
const { error, data } = schema.safeParse(args);
|
|
6699
|
+
if (error) {
|
|
6700
|
+
throw createInvalidInputError(`Invalid ${operation} args for model "${model}": ${formatError(error)}`, model, {
|
|
6701
|
+
cause: error
|
|
6702
|
+
});
|
|
6703
|
+
}
|
|
6704
|
+
return data;
|
|
6705
|
+
}
|
|
6706
|
+
};
|
|
6953
6707
|
|
|
6954
6708
|
// src/client/executor/zenstack-driver.ts
|
|
6955
6709
|
var ZenStackDriver = class {
|
|
@@ -7136,7 +6890,7 @@ __name(performanceNow, "performanceNow");
|
|
|
7136
6890
|
|
|
7137
6891
|
// src/client/executor/zenstack-query-executor.ts
|
|
7138
6892
|
var import_common_helpers11 = require("@zenstackhq/common-helpers");
|
|
7139
|
-
var
|
|
6893
|
+
var import_kysely9 = require("kysely");
|
|
7140
6894
|
var import_ts_pattern15 = require("ts-pattern");
|
|
7141
6895
|
|
|
7142
6896
|
// src/client/executor/name-mapper.ts
|
|
@@ -7724,8 +7478,32 @@ var QueryNameMapper = class extends import_kysely7.OperationNodeTransformer {
|
|
|
7724
7478
|
}
|
|
7725
7479
|
};
|
|
7726
7480
|
|
|
7481
|
+
// src/client/executor/temp-alias-transformer.ts
|
|
7482
|
+
var import_kysely8 = require("kysely");
|
|
7483
|
+
var TempAliasTransformer = class extends import_kysely8.OperationNodeTransformer {
|
|
7484
|
+
static {
|
|
7485
|
+
__name(this, "TempAliasTransformer");
|
|
7486
|
+
}
|
|
7487
|
+
aliasMap = /* @__PURE__ */ new Map();
|
|
7488
|
+
run(node) {
|
|
7489
|
+
this.aliasMap.clear();
|
|
7490
|
+
return this.transformNode(node);
|
|
7491
|
+
}
|
|
7492
|
+
transformIdentifier(node, queryId) {
|
|
7493
|
+
if (node.name.startsWith(TEMP_ALIAS_PREFIX)) {
|
|
7494
|
+
let mapped = this.aliasMap.get(node.name);
|
|
7495
|
+
if (!mapped) {
|
|
7496
|
+
mapped = `$$t${this.aliasMap.size + 1}`;
|
|
7497
|
+
this.aliasMap.set(node.name, mapped);
|
|
7498
|
+
}
|
|
7499
|
+
return import_kysely8.IdentifierNode.create(mapped);
|
|
7500
|
+
}
|
|
7501
|
+
return super.transformIdentifier(node, queryId);
|
|
7502
|
+
}
|
|
7503
|
+
};
|
|
7504
|
+
|
|
7727
7505
|
// src/client/executor/zenstack-query-executor.ts
|
|
7728
|
-
var ZenStackQueryExecutor = class _ZenStackQueryExecutor extends
|
|
7506
|
+
var ZenStackQueryExecutor = class _ZenStackQueryExecutor extends import_kysely9.DefaultQueryExecutor {
|
|
7729
7507
|
static {
|
|
7730
7508
|
__name(this, "ZenStackQueryExecutor");
|
|
7731
7509
|
}
|
|
@@ -7827,17 +7605,17 @@ var ZenStackQueryExecutor = class _ZenStackQueryExecutor extends import_kysely8.
|
|
|
7827
7605
|
}
|
|
7828
7606
|
let preUpdateIds;
|
|
7829
7607
|
const mutationModel = this.getMutationModel(query);
|
|
7830
|
-
const needLoadAfterMutationEntities = (
|
|
7608
|
+
const needLoadAfterMutationEntities = (import_kysely9.InsertQueryNode.is(query) || import_kysely9.UpdateQueryNode.is(query)) && this.hasEntityMutationPluginsWithAfterMutationHooks;
|
|
7831
7609
|
if (needLoadAfterMutationEntities) {
|
|
7832
7610
|
if (this.dialect.supportsReturning) {
|
|
7833
7611
|
query = {
|
|
7834
7612
|
...query,
|
|
7835
|
-
returning:
|
|
7836
|
-
|
|
7613
|
+
returning: import_kysely9.ReturningNode.create([
|
|
7614
|
+
import_kysely9.SelectionNode.createSelectAll()
|
|
7837
7615
|
])
|
|
7838
7616
|
};
|
|
7839
7617
|
} else {
|
|
7840
|
-
if (
|
|
7618
|
+
if (import_kysely9.UpdateQueryNode.is(query)) {
|
|
7841
7619
|
preUpdateIds = await this.getPreUpdateIds(mutationModel, query, connection);
|
|
7842
7620
|
}
|
|
7843
7621
|
}
|
|
@@ -7847,7 +7625,7 @@ var ZenStackQueryExecutor = class _ZenStackQueryExecutor extends import_kysely8.
|
|
|
7847
7625
|
const mutationInfo = this.getMutationInfo(query);
|
|
7848
7626
|
let beforeMutationEntities;
|
|
7849
7627
|
const loadBeforeMutationEntities = /* @__PURE__ */ __name(async () => {
|
|
7850
|
-
if (beforeMutationEntities === void 0 && (
|
|
7628
|
+
if (beforeMutationEntities === void 0 && (import_kysely9.UpdateQueryNode.is(query) || import_kysely9.DeleteQueryNode.is(query))) {
|
|
7851
7629
|
beforeMutationEntities = await this.loadEntities(mutationInfo.model, mutationInfo.where, connection, void 0);
|
|
7852
7630
|
}
|
|
7853
7631
|
return beforeMutationEntities;
|
|
@@ -7951,10 +7729,10 @@ var ZenStackQueryExecutor = class _ZenStackQueryExecutor extends import_kysely8.
|
|
|
7951
7729
|
if (this.dialect.supportsReturning) {
|
|
7952
7730
|
return queryResult.rows;
|
|
7953
7731
|
} else {
|
|
7954
|
-
const mutatedIds =
|
|
7732
|
+
const mutatedIds = import_kysely9.InsertQueryNode.is(queryNode) ? this.getInsertIds(mutationInfo.model, queryNode, queryResult) : preUpdateIds;
|
|
7955
7733
|
if (mutatedIds) {
|
|
7956
7734
|
const idFields = requireIdFields(this.client.$schema, mutationInfo.model);
|
|
7957
|
-
const eb = (0,
|
|
7735
|
+
const eb = (0, import_kysely9.expressionBuilder)();
|
|
7958
7736
|
const filter = eb(
|
|
7959
7737
|
// @ts-ignore
|
|
7960
7738
|
eb.refTuple(...idFields),
|
|
@@ -7963,7 +7741,7 @@ var ZenStackQueryExecutor = class _ZenStackQueryExecutor extends import_kysely8.
|
|
|
7963
7741
|
...idFields.map((idField) => eb.val(idObj[idField]))
|
|
7964
7742
|
))
|
|
7965
7743
|
);
|
|
7966
|
-
const entities = await this.loadEntities(mutationInfo.model,
|
|
7744
|
+
const entities = await this.loadEntities(mutationInfo.model, import_kysely9.WhereNode.create(filter.toOperationNode()), connection, void 0);
|
|
7967
7745
|
return entities;
|
|
7968
7746
|
} else {
|
|
7969
7747
|
console.warn(`Unable to load after-mutation entities for hooks: model "${mutationInfo.model}", operation "${mutationInfo.action}".
|
|
@@ -7984,9 +7762,9 @@ In such cases, ZenStack cannot reliably determine the IDs of the mutated entitie
|
|
|
7984
7762
|
const idFields = requireIdFields(this.client.$schema, mutationModel);
|
|
7985
7763
|
if (query.updates) {
|
|
7986
7764
|
for (const update of query.updates) {
|
|
7987
|
-
if (
|
|
7765
|
+
if (import_kysely9.ColumnUpdateNode.is(update)) {
|
|
7988
7766
|
const columnNode = update.column;
|
|
7989
|
-
if (
|
|
7767
|
+
if (import_kysely9.ColumnNode.is(columnNode)) {
|
|
7990
7768
|
const columnName = columnNode.column.name;
|
|
7991
7769
|
if (idFields.includes(columnName)) {
|
|
7992
7770
|
return void 0;
|
|
@@ -7999,7 +7777,7 @@ In such cases, ZenStack cannot reliably determine the IDs of the mutated entitie
|
|
|
7999
7777
|
}
|
|
8000
7778
|
getInsertIds(mutationModel, query, queryResult) {
|
|
8001
7779
|
const idFields = requireIdFields(this.client.$schema, mutationModel);
|
|
8002
|
-
if (
|
|
7780
|
+
if (import_kysely9.InsertQueryNode.is(query) && queryResult.numAffectedRows === 1n && queryResult.insertId && idFields.length === 1) {
|
|
8003
7781
|
return [
|
|
8004
7782
|
{
|
|
8005
7783
|
[idFields[0]]: queryResult.insertId
|
|
@@ -8011,13 +7789,13 @@ In such cases, ZenStack cannot reliably determine the IDs of the mutated entitie
|
|
|
8011
7789
|
return void 0;
|
|
8012
7790
|
}
|
|
8013
7791
|
const values = query.values;
|
|
8014
|
-
if (!values || !
|
|
7792
|
+
if (!values || !import_kysely9.ValuesNode.is(values)) {
|
|
8015
7793
|
return void 0;
|
|
8016
7794
|
}
|
|
8017
7795
|
const allIds = [];
|
|
8018
7796
|
for (const valuesItem of values.values) {
|
|
8019
7797
|
const rowIds = {};
|
|
8020
|
-
if (
|
|
7798
|
+
if (import_kysely9.PrimitiveValueListNode.is(valuesItem)) {
|
|
8021
7799
|
(0, import_common_helpers11.invariant)(valuesItem.values.length === columns.length, "Values count must match columns count");
|
|
8022
7800
|
for (const idField of idFields) {
|
|
8023
7801
|
const colIndex = columns.findIndex((col) => col.column.name === idField);
|
|
@@ -8034,7 +7812,7 @@ In such cases, ZenStack cannot reliably determine the IDs of the mutated entitie
|
|
|
8034
7812
|
return void 0;
|
|
8035
7813
|
}
|
|
8036
7814
|
const valueNode = valuesItem.values[colIndex];
|
|
8037
|
-
if (!valueNode || !
|
|
7815
|
+
if (!valueNode || !import_kysely9.ValueNode.is(valueNode)) {
|
|
8038
7816
|
return void 0;
|
|
8039
7817
|
}
|
|
8040
7818
|
rowIds[idField] = valueNode.value;
|
|
@@ -8063,13 +7841,13 @@ In such cases, ZenStack cannot reliably determine the IDs of the mutated entitie
|
|
|
8063
7841
|
// #region utilities
|
|
8064
7842
|
getMutationInfo(queryNode) {
|
|
8065
7843
|
const model = this.getMutationModel(queryNode);
|
|
8066
|
-
const { action, where } = (0, import_ts_pattern15.match)(queryNode).when(
|
|
7844
|
+
const { action, where } = (0, import_ts_pattern15.match)(queryNode).when(import_kysely9.InsertQueryNode.is, () => ({
|
|
8067
7845
|
action: "create",
|
|
8068
7846
|
where: void 0
|
|
8069
|
-
})).when(
|
|
7847
|
+
})).when(import_kysely9.UpdateQueryNode.is, (node) => ({
|
|
8070
7848
|
action: "update",
|
|
8071
7849
|
where: node.where
|
|
8072
|
-
})).when(
|
|
7850
|
+
})).when(import_kysely9.DeleteQueryNode.is, (node) => ({
|
|
8073
7851
|
action: "delete",
|
|
8074
7852
|
where: node.where
|
|
8075
7853
|
})).exhaustive();
|
|
@@ -8080,31 +7858,43 @@ In such cases, ZenStack cannot reliably determine the IDs of the mutated entitie
|
|
|
8080
7858
|
};
|
|
8081
7859
|
}
|
|
8082
7860
|
isMutationNode(queryNode) {
|
|
8083
|
-
return
|
|
7861
|
+
return import_kysely9.InsertQueryNode.is(queryNode) || import_kysely9.UpdateQueryNode.is(queryNode) || import_kysely9.DeleteQueryNode.is(queryNode);
|
|
8084
7862
|
}
|
|
8085
7863
|
getMutationModel(queryNode) {
|
|
8086
|
-
return (0, import_ts_pattern15.match)(queryNode).when(
|
|
7864
|
+
return (0, import_ts_pattern15.match)(queryNode).when(import_kysely9.InsertQueryNode.is, (node) => {
|
|
8087
7865
|
(0, import_common_helpers11.invariant)(node.into, "InsertQueryNode must have an into clause");
|
|
8088
7866
|
return node.into.table.identifier.name;
|
|
8089
|
-
}).when(
|
|
7867
|
+
}).when(import_kysely9.UpdateQueryNode.is, (node) => {
|
|
8090
7868
|
(0, import_common_helpers11.invariant)(node.table, "UpdateQueryNode must have a table");
|
|
8091
7869
|
const { node: tableNode } = stripAlias(node.table);
|
|
8092
|
-
(0, import_common_helpers11.invariant)(
|
|
7870
|
+
(0, import_common_helpers11.invariant)(import_kysely9.TableNode.is(tableNode), "UpdateQueryNode must use a TableNode");
|
|
8093
7871
|
return tableNode.table.identifier.name;
|
|
8094
|
-
}).when(
|
|
7872
|
+
}).when(import_kysely9.DeleteQueryNode.is, (node) => {
|
|
8095
7873
|
(0, import_common_helpers11.invariant)(node.from.froms.length === 1, "Delete query must have exactly one from table");
|
|
8096
7874
|
const { node: tableNode } = stripAlias(node.from.froms[0]);
|
|
8097
|
-
(0, import_common_helpers11.invariant)(
|
|
7875
|
+
(0, import_common_helpers11.invariant)(import_kysely9.TableNode.is(tableNode), "DeleteQueryNode must use a TableNode");
|
|
8098
7876
|
return tableNode.table.identifier.name;
|
|
8099
7877
|
}).otherwise((node) => {
|
|
8100
7878
|
throw createInternalError(`Invalid query node: ${node}`);
|
|
8101
7879
|
});
|
|
8102
7880
|
}
|
|
7881
|
+
processQueryNode(query) {
|
|
7882
|
+
let result = query;
|
|
7883
|
+
result = this.processNameMapping(result);
|
|
7884
|
+
result = this.processTempAlias(result);
|
|
7885
|
+
return result;
|
|
7886
|
+
}
|
|
8103
7887
|
processNameMapping(query) {
|
|
8104
7888
|
return this.nameMapper?.transformNode(query) ?? query;
|
|
8105
7889
|
}
|
|
7890
|
+
processTempAlias(query) {
|
|
7891
|
+
if (this.options.useCompactAliasNames === false) {
|
|
7892
|
+
return query;
|
|
7893
|
+
}
|
|
7894
|
+
return new TempAliasTransformer().run(query);
|
|
7895
|
+
}
|
|
8106
7896
|
createClientForConnection(connection, inTx) {
|
|
8107
|
-
const innerExecutor = this.withConnectionProvider(new
|
|
7897
|
+
const innerExecutor = this.withConnectionProvider(new import_kysely9.SingleConnectionProvider(connection));
|
|
8108
7898
|
innerExecutor.suppressMutationHooks = true;
|
|
8109
7899
|
const innerClient = this.client.withExecutor(innerExecutor);
|
|
8110
7900
|
if (inTx) {
|
|
@@ -8114,16 +7904,16 @@ In such cases, ZenStack cannot reliably determine the IDs of the mutated entitie
|
|
|
8114
7904
|
}
|
|
8115
7905
|
andNodes(condition1, condition2) {
|
|
8116
7906
|
if (condition1 && condition2) {
|
|
8117
|
-
return
|
|
7907
|
+
return import_kysely9.WhereNode.create(import_kysely9.AndNode.create(condition1, condition2));
|
|
8118
7908
|
} else if (condition1) {
|
|
8119
|
-
return
|
|
7909
|
+
return import_kysely9.WhereNode.create(condition1);
|
|
8120
7910
|
} else {
|
|
8121
7911
|
return condition2;
|
|
8122
7912
|
}
|
|
8123
7913
|
}
|
|
8124
7914
|
async internalExecuteQuery(query, connection, queryId, parameters) {
|
|
8125
|
-
const finalQuery = this.
|
|
8126
|
-
let compiledQuery = this.compileQuery(finalQuery, queryId ?? (0,
|
|
7915
|
+
const finalQuery = this.processQueryNode(query);
|
|
7916
|
+
let compiledQuery = this.compileQuery(finalQuery, queryId ?? (0, import_kysely9.createQueryId)());
|
|
8127
7917
|
if (parameters) {
|
|
8128
7918
|
compiledQuery = {
|
|
8129
7919
|
...compiledQuery,
|
|
@@ -8193,7 +7983,7 @@ __export(functions_exports, {
|
|
|
8193
7983
|
startsWith: () => startsWith
|
|
8194
7984
|
});
|
|
8195
7985
|
var import_common_helpers12 = require("@zenstackhq/common-helpers");
|
|
8196
|
-
var
|
|
7986
|
+
var import_kysely10 = require("kysely");
|
|
8197
7987
|
var import_ts_pattern16 = require("ts-pattern");
|
|
8198
7988
|
var contains = /* @__PURE__ */ __name((eb, args, context) => textMatch(eb, args, context, "contains"), "contains");
|
|
8199
7989
|
var search = /* @__PURE__ */ __name((_eb, _args) => {
|
|
@@ -8231,20 +8021,20 @@ var textMatch = /* @__PURE__ */ __name((eb, args, { dialect }, method) => {
|
|
|
8231
8021
|
} else {
|
|
8232
8022
|
op = "like";
|
|
8233
8023
|
}
|
|
8234
|
-
searchExpr = eb.fn.coalesce(searchExpr,
|
|
8235
|
-
const escapedSearch =
|
|
8024
|
+
searchExpr = eb.fn.coalesce(searchExpr, import_kysely10.sql.lit(""));
|
|
8025
|
+
const escapedSearch = import_kysely10.sql`REPLACE(REPLACE(REPLACE(${dialect.castText(searchExpr)}, ${import_kysely10.sql.val("\\")}, ${import_kysely10.sql.val("\\\\")}), ${import_kysely10.sql.val("%")}, ${import_kysely10.sql.val("\\%")}), ${import_kysely10.sql.val("_")}, ${import_kysely10.sql.val("\\_")})`;
|
|
8236
8026
|
searchExpr = (0, import_ts_pattern16.match)(method).with("contains", () => eb.fn("CONCAT", [
|
|
8237
|
-
|
|
8027
|
+
import_kysely10.sql.lit("%"),
|
|
8238
8028
|
escapedSearch,
|
|
8239
|
-
|
|
8029
|
+
import_kysely10.sql.lit("%")
|
|
8240
8030
|
])).with("startsWith", () => eb.fn("CONCAT", [
|
|
8241
8031
|
escapedSearch,
|
|
8242
|
-
|
|
8032
|
+
import_kysely10.sql.lit("%")
|
|
8243
8033
|
])).with("endsWith", () => eb.fn("CONCAT", [
|
|
8244
|
-
|
|
8034
|
+
import_kysely10.sql.lit("%"),
|
|
8245
8035
|
escapedSearch
|
|
8246
8036
|
])).exhaustive();
|
|
8247
|
-
return
|
|
8037
|
+
return import_kysely10.sql`${fieldExpr} ${import_kysely10.sql.raw(op)} ${searchExpr} escape ${import_kysely10.sql.val("\\")}`;
|
|
8248
8038
|
}, "textMatch");
|
|
8249
8039
|
var has = /* @__PURE__ */ __name((_eb, args, context) => {
|
|
8250
8040
|
const [field, search2] = args;
|
|
@@ -8281,16 +8071,16 @@ var isEmpty = /* @__PURE__ */ __name((eb, args, { dialect }) => {
|
|
|
8281
8071
|
if (!field) {
|
|
8282
8072
|
throw new Error('"field" parameter is required');
|
|
8283
8073
|
}
|
|
8284
|
-
return eb(dialect.buildArrayLength(field), "=",
|
|
8074
|
+
return eb(dialect.buildArrayLength(field), "=", import_kysely10.sql.lit(0));
|
|
8285
8075
|
}, "isEmpty");
|
|
8286
|
-
var now = /* @__PURE__ */ __name(() =>
|
|
8076
|
+
var now = /* @__PURE__ */ __name(() => import_kysely10.sql.raw("CURRENT_TIMESTAMP"), "now");
|
|
8287
8077
|
var currentModel = /* @__PURE__ */ __name((_eb, args, { model }) => {
|
|
8288
8078
|
let result = model;
|
|
8289
8079
|
const [casing] = args;
|
|
8290
8080
|
if (casing) {
|
|
8291
8081
|
result = processCasing(casing, result, model);
|
|
8292
8082
|
}
|
|
8293
|
-
return
|
|
8083
|
+
return import_kysely10.sql.lit(result);
|
|
8294
8084
|
}, "currentModel");
|
|
8295
8085
|
var currentOperation = /* @__PURE__ */ __name((_eb, args, { operation }) => {
|
|
8296
8086
|
let result = operation;
|
|
@@ -8298,11 +8088,11 @@ var currentOperation = /* @__PURE__ */ __name((_eb, args, { operation }) => {
|
|
|
8298
8088
|
if (casing) {
|
|
8299
8089
|
result = processCasing(casing, result, operation);
|
|
8300
8090
|
}
|
|
8301
|
-
return
|
|
8091
|
+
return import_kysely10.sql.lit(result);
|
|
8302
8092
|
}, "currentOperation");
|
|
8303
8093
|
function processCasing(casing, result, model) {
|
|
8304
8094
|
const opNode = casing.toOperationNode();
|
|
8305
|
-
(0, import_common_helpers12.invariant)(
|
|
8095
|
+
(0, import_common_helpers12.invariant)(import_kysely10.ValueNode.is(opNode) && typeof opNode.value === "string", '"casting" parameter must be a string value');
|
|
8306
8096
|
result = (0, import_ts_pattern16.match)(opNode.value).with("original", () => model).with("upper", () => result.toUpperCase()).with("lower", () => result.toLowerCase()).with("capitalize", () => (0, import_common_helpers12.upperCaseFirst)(result)).with("uncapitalize", () => (0, import_common_helpers12.lowerCaseFirst)(result)).otherwise(() => {
|
|
8307
8097
|
throw new Error(`Invalid casing value: ${opNode.value}. Must be "original", "upper", "lower", "capitalize", or "uncapitalize".`);
|
|
8308
8098
|
});
|
|
@@ -8314,14 +8104,14 @@ function readBoolean(expr, defaultValue) {
|
|
|
8314
8104
|
return defaultValue;
|
|
8315
8105
|
}
|
|
8316
8106
|
const opNode = expr.toOperationNode();
|
|
8317
|
-
(0, import_common_helpers12.invariant)(
|
|
8107
|
+
(0, import_common_helpers12.invariant)(import_kysely10.ValueNode.is(opNode), "expression must be a literal value");
|
|
8318
8108
|
return !!opNode.value;
|
|
8319
8109
|
}
|
|
8320
8110
|
__name(readBoolean, "readBoolean");
|
|
8321
8111
|
|
|
8322
8112
|
// src/client/helpers/schema-db-pusher.ts
|
|
8323
8113
|
var import_common_helpers13 = require("@zenstackhq/common-helpers");
|
|
8324
|
-
var
|
|
8114
|
+
var import_kysely11 = require("kysely");
|
|
8325
8115
|
var import_toposort = __toESM(require("toposort"), 1);
|
|
8326
8116
|
var import_ts_pattern17 = require("ts-pattern");
|
|
8327
8117
|
var SchemaDbPusher = class {
|
|
@@ -8499,7 +8289,7 @@ var SchemaDbPusher = class {
|
|
|
8499
8289
|
if (fieldDef.default !== void 0 && this.isDefaultValueSupportedForType(fieldDef.type)) {
|
|
8500
8290
|
if (typeof fieldDef.default === "object" && "kind" in fieldDef.default) {
|
|
8501
8291
|
if (schema_exports.ExpressionUtils.isCall(fieldDef.default) && fieldDef.default.function === "now") {
|
|
8502
|
-
col = this.schema.provider.type === "mysql" ? col.defaultTo(
|
|
8292
|
+
col = this.schema.provider.type === "mysql" ? col.defaultTo(import_kysely11.sql`CURRENT_TIMESTAMP(3)`) : col.defaultTo(import_kysely11.sql`CURRENT_TIMESTAMP`);
|
|
8503
8293
|
}
|
|
8504
8294
|
} else {
|
|
8505
8295
|
if (this.schema.provider.type === "mysql" && fieldDef.type === "DateTime" && typeof fieldDef.default === "string") {
|
|
@@ -8531,7 +8321,7 @@ var SchemaDbPusher = class {
|
|
|
8531
8321
|
mapFieldType(fieldDef) {
|
|
8532
8322
|
if (this.schema.enums?.[fieldDef.type]) {
|
|
8533
8323
|
if (this.schema.provider.type === "postgresql") {
|
|
8534
|
-
return
|
|
8324
|
+
return import_kysely11.sql.ref(fieldDef.type);
|
|
8535
8325
|
} else if (this.schema.provider.type === "mysql") {
|
|
8536
8326
|
const enumDef = this.schema.enums[fieldDef.type];
|
|
8537
8327
|
let enumValues;
|
|
@@ -8549,7 +8339,7 @@ var SchemaDbPusher = class {
|
|
|
8549
8339
|
} else {
|
|
8550
8340
|
enumValues = Object.values(enumDef.values);
|
|
8551
8341
|
}
|
|
8552
|
-
return
|
|
8342
|
+
return import_kysely11.sql.raw(`enum(${enumValues.map((v) => `'${v}'`).join(", ")})`);
|
|
8553
8343
|
} else {
|
|
8554
8344
|
return "text";
|
|
8555
8345
|
}
|
|
@@ -8565,7 +8355,7 @@ var SchemaDbPusher = class {
|
|
|
8565
8355
|
throw new Error(`Unsupported field type: ${type}`);
|
|
8566
8356
|
});
|
|
8567
8357
|
if (fieldDef.array) {
|
|
8568
|
-
return
|
|
8358
|
+
return import_kysely11.sql.raw(`${result}[]`);
|
|
8569
8359
|
} else {
|
|
8570
8360
|
return result;
|
|
8571
8361
|
}
|
|
@@ -8611,25 +8401,25 @@ var SchemaDbPusher = class {
|
|
|
8611
8401
|
return (0, import_ts_pattern17.match)(this.schema.provider.type).with("postgresql", () => "bytea").with("mysql", () => "blob").otherwise(() => "blob");
|
|
8612
8402
|
}
|
|
8613
8403
|
get stringType() {
|
|
8614
|
-
return (0, import_ts_pattern17.match)(this.schema.provider.type).with("mysql", () =>
|
|
8404
|
+
return (0, import_ts_pattern17.match)(this.schema.provider.type).with("mysql", () => import_kysely11.sql.raw("varchar(255)")).otherwise(() => "text");
|
|
8615
8405
|
}
|
|
8616
8406
|
get booleanType() {
|
|
8617
|
-
return (0, import_ts_pattern17.match)(this.schema.provider.type).with("mysql", () =>
|
|
8407
|
+
return (0, import_ts_pattern17.match)(this.schema.provider.type).with("mysql", () => import_kysely11.sql.raw("tinyint(1)")).otherwise(() => "boolean");
|
|
8618
8408
|
}
|
|
8619
8409
|
get intType() {
|
|
8620
8410
|
return "integer";
|
|
8621
8411
|
}
|
|
8622
8412
|
get floatType() {
|
|
8623
|
-
return (0, import_ts_pattern17.match)(this.schema.provider.type).with("postgresql", () => "double precision").with("mysql", () =>
|
|
8413
|
+
return (0, import_ts_pattern17.match)(this.schema.provider.type).with("postgresql", () => "double precision").with("mysql", () => import_kysely11.sql.raw("double")).otherwise(() => "real");
|
|
8624
8414
|
}
|
|
8625
8415
|
get bigIntType() {
|
|
8626
8416
|
return "bigint";
|
|
8627
8417
|
}
|
|
8628
8418
|
get decimalType() {
|
|
8629
|
-
return (0, import_ts_pattern17.match)(this.schema.provider.type).with("mysql", () =>
|
|
8419
|
+
return (0, import_ts_pattern17.match)(this.schema.provider.type).with("mysql", () => import_kysely11.sql.raw("decimal(65, 30)")).otherwise(() => "decimal");
|
|
8630
8420
|
}
|
|
8631
8421
|
get dateTimeType() {
|
|
8632
|
-
return (0, import_ts_pattern17.match)(this.schema.provider.type).with("mysql", () =>
|
|
8422
|
+
return (0, import_ts_pattern17.match)(this.schema.provider.type).with("mysql", () => import_kysely11.sql.raw("datetime(3)")).otherwise(() => "timestamp");
|
|
8633
8423
|
}
|
|
8634
8424
|
columnSupportsAutoIncrement() {
|
|
8635
8425
|
return [
|
|
@@ -8820,15 +8610,15 @@ var ClientImpl = class _ClientImpl {
|
|
|
8820
8610
|
if (baseClient) {
|
|
8821
8611
|
this.kyselyProps = {
|
|
8822
8612
|
...baseClient.kyselyProps,
|
|
8823
|
-
executor: executor ?? new ZenStackQueryExecutor(this, baseClient.kyselyProps.driver, baseClient.kyselyProps.dialect.createQueryCompiler(), baseClient.kyselyProps.dialect.createAdapter(), new
|
|
8613
|
+
executor: executor ?? new ZenStackQueryExecutor(this, baseClient.kyselyProps.driver, baseClient.kyselyProps.dialect.createQueryCompiler(), baseClient.kyselyProps.dialect.createAdapter(), new import_kysely12.DefaultConnectionProvider(baseClient.kyselyProps.driver))
|
|
8824
8614
|
};
|
|
8825
8615
|
this.kyselyRaw = baseClient.kyselyRaw;
|
|
8826
8616
|
this.auth = baseClient.auth;
|
|
8827
8617
|
} else {
|
|
8828
|
-
const driver = new ZenStackDriver(options.dialect.createDriver(), new
|
|
8618
|
+
const driver = new ZenStackDriver(options.dialect.createDriver(), new import_kysely12.Log(this.$options.log ?? []));
|
|
8829
8619
|
const compiler = options.dialect.createQueryCompiler();
|
|
8830
8620
|
const adapter = options.dialect.createAdapter();
|
|
8831
|
-
const connectionProvider = new
|
|
8621
|
+
const connectionProvider = new import_kysely12.DefaultConnectionProvider(driver);
|
|
8832
8622
|
this.kyselyProps = {
|
|
8833
8623
|
config: {
|
|
8834
8624
|
dialect: options.dialect,
|
|
@@ -8838,12 +8628,12 @@ var ClientImpl = class _ClientImpl {
|
|
|
8838
8628
|
driver,
|
|
8839
8629
|
executor: executor ?? new ZenStackQueryExecutor(this, driver, compiler, adapter, connectionProvider)
|
|
8840
8630
|
};
|
|
8841
|
-
this.kyselyRaw = new
|
|
8631
|
+
this.kyselyRaw = new import_kysely12.Kysely({
|
|
8842
8632
|
...this.kyselyProps,
|
|
8843
|
-
executor: new
|
|
8633
|
+
executor: new import_kysely12.DefaultQueryExecutor(compiler, adapter, connectionProvider, [])
|
|
8844
8634
|
});
|
|
8845
8635
|
}
|
|
8846
|
-
this.kysely = new
|
|
8636
|
+
this.kysely = new import_kysely12.Kysely(this.kyselyProps);
|
|
8847
8637
|
this.inputValidator = baseClient?.inputValidator ?? new InputValidator(this);
|
|
8848
8638
|
return createClientProxy(this);
|
|
8849
8639
|
}
|
|
@@ -8853,6 +8643,9 @@ var ClientImpl = class _ClientImpl {
|
|
|
8853
8643
|
get $qbRaw() {
|
|
8854
8644
|
return this.kyselyRaw;
|
|
8855
8645
|
}
|
|
8646
|
+
get $zod() {
|
|
8647
|
+
return this.inputValidator.zodFactory;
|
|
8648
|
+
}
|
|
8856
8649
|
get isTransaction() {
|
|
8857
8650
|
return this.kysely.isTransaction;
|
|
8858
8651
|
}
|
|
@@ -8893,7 +8686,7 @@ var ClientImpl = class _ClientImpl {
|
|
|
8893
8686
|
}
|
|
8894
8687
|
forceTransaction() {
|
|
8895
8688
|
if (!this.kysely.isTransaction) {
|
|
8896
|
-
this.kysely = new
|
|
8689
|
+
this.kysely = new import_kysely12.Transaction(this.kyselyProps);
|
|
8897
8690
|
}
|
|
8898
8691
|
}
|
|
8899
8692
|
async interactiveTransaction(callback, options) {
|
|
@@ -8984,7 +8777,7 @@ var ClientImpl = class _ClientImpl {
|
|
|
8984
8777
|
}
|
|
8985
8778
|
async $connect() {
|
|
8986
8779
|
await this.kysely.connection().execute(async (conn) => {
|
|
8987
|
-
await conn.executeQuery(
|
|
8780
|
+
await conn.executeQuery(import_kysely12.sql`select 1`.compile(this.kysely));
|
|
8988
8781
|
});
|
|
8989
8782
|
}
|
|
8990
8783
|
async $disconnect() {
|
|
@@ -9055,7 +8848,7 @@ var ClientImpl = class _ClientImpl {
|
|
|
9055
8848
|
}
|
|
9056
8849
|
$executeRaw(query, ...values) {
|
|
9057
8850
|
return createZenStackPromise(async () => {
|
|
9058
|
-
const result = await (0,
|
|
8851
|
+
const result = await (0, import_kysely12.sql)(query, ...values).execute(this.kysely);
|
|
9059
8852
|
return Number(result.numAffectedRows ?? 0);
|
|
9060
8853
|
});
|
|
9061
8854
|
}
|
|
@@ -9068,7 +8861,7 @@ var ClientImpl = class _ClientImpl {
|
|
|
9068
8861
|
}
|
|
9069
8862
|
$queryRaw(query, ...values) {
|
|
9070
8863
|
return createZenStackPromise(async () => {
|
|
9071
|
-
const result = await (0,
|
|
8864
|
+
const result = await (0, import_kysely12.sql)(query, ...values).execute(this.kysely);
|
|
9072
8865
|
return result.rows;
|
|
9073
8866
|
});
|
|
9074
8867
|
}
|
|
@@ -9080,7 +8873,7 @@ var ClientImpl = class _ClientImpl {
|
|
|
9080
8873
|
});
|
|
9081
8874
|
}
|
|
9082
8875
|
createRawCompiledQuery(query, values) {
|
|
9083
|
-
const q =
|
|
8876
|
+
const q = import_kysely12.CompiledQuery.raw(query, values);
|
|
9084
8877
|
return {
|
|
9085
8878
|
...q,
|
|
9086
8879
|
$raw: true
|
|
@@ -9291,8 +9084,8 @@ var kysely_utils_exports = {};
|
|
|
9291
9084
|
__export(kysely_utils_exports, {
|
|
9292
9085
|
DefaultOperationNodeVisitor: () => DefaultOperationNodeVisitor
|
|
9293
9086
|
});
|
|
9294
|
-
var
|
|
9295
|
-
var DefaultOperationNodeVisitor = class extends
|
|
9087
|
+
var import_kysely13 = require("kysely");
|
|
9088
|
+
var DefaultOperationNodeVisitor = class extends import_kysely13.OperationNodeVisitor {
|
|
9296
9089
|
static {
|
|
9297
9090
|
__name(this, "DefaultOperationNodeVisitor");
|
|
9298
9091
|
}
|
|
@@ -9730,6 +9523,7 @@ var MatchingExpressionVisitor = class extends ExpressionVisitor {
|
|
|
9730
9523
|
SchemaUtils,
|
|
9731
9524
|
TransactionIsolationLevel,
|
|
9732
9525
|
ZenStackClient,
|
|
9526
|
+
createQuerySchemaFactory,
|
|
9733
9527
|
definePlugin,
|
|
9734
9528
|
getCrudDialect
|
|
9735
9529
|
});
|