@zenstackhq/orm 3.0.0-beta.26 → 3.0.0-beta.28
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 +624 -209
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +573 -33
- package/dist/index.d.ts +573 -33
- package/dist/index.js +618 -209
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -32,9 +32,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
32
32
|
// src/index.ts
|
|
33
33
|
var src_exports = {};
|
|
34
34
|
__export(src_exports, {
|
|
35
|
+
AnyNull: () => AnyNull,
|
|
36
|
+
AnyNullClass: () => AnyNullClass,
|
|
35
37
|
BaseCrudDialect: () => BaseCrudDialect,
|
|
36
38
|
CRUD: () => CRUD,
|
|
37
39
|
CRUD_EXT: () => CRUD_EXT,
|
|
40
|
+
DbNull: () => DbNull,
|
|
41
|
+
DbNullClass: () => DbNullClass,
|
|
42
|
+
JsonNull: () => JsonNull,
|
|
43
|
+
JsonNullClass: () => JsonNullClass,
|
|
38
44
|
KyselyUtils: () => kysely_utils_exports,
|
|
39
45
|
ORMError: () => ORMError,
|
|
40
46
|
ORMErrorReason: () => ORMErrorReason,
|
|
@@ -83,10 +89,12 @@ __export(query_utils_exports, {
|
|
|
83
89
|
isInheritedField: () => isInheritedField,
|
|
84
90
|
isRelationField: () => isRelationField,
|
|
85
91
|
isScalarField: () => isScalarField,
|
|
92
|
+
isTypeDef: () => isTypeDef,
|
|
86
93
|
makeDefaultOrderBy: () => makeDefaultOrderBy,
|
|
87
94
|
requireField: () => requireField,
|
|
88
95
|
requireIdFields: () => requireIdFields,
|
|
89
96
|
requireModel: () => requireModel,
|
|
97
|
+
requireTypeDef: () => requireTypeDef,
|
|
90
98
|
stripAlias: () => stripAlias
|
|
91
99
|
});
|
|
92
100
|
var import_common_helpers = require("@zenstackhq/common-helpers");
|
|
@@ -236,6 +244,14 @@ function requireModel(schema, model) {
|
|
|
236
244
|
return modelDef;
|
|
237
245
|
}
|
|
238
246
|
__name(requireModel, "requireModel");
|
|
247
|
+
function requireTypeDef(schema, type) {
|
|
248
|
+
const typeDef = getTypeDef(schema, type);
|
|
249
|
+
if (!typeDef) {
|
|
250
|
+
throw createInternalError(`Type "${type}" not found in schema`, type);
|
|
251
|
+
}
|
|
252
|
+
return typeDef;
|
|
253
|
+
}
|
|
254
|
+
__name(requireTypeDef, "requireTypeDef");
|
|
239
255
|
function getField(schema, model, field) {
|
|
240
256
|
const modelDef = getModel(schema, model);
|
|
241
257
|
return modelDef?.fields[field];
|
|
@@ -383,6 +399,10 @@ function getEnum(schema, type) {
|
|
|
383
399
|
return schema.enums?.[type];
|
|
384
400
|
}
|
|
385
401
|
__name(getEnum, "getEnum");
|
|
402
|
+
function isTypeDef(schema, type) {
|
|
403
|
+
return !!schema.typeDefs?.[type];
|
|
404
|
+
}
|
|
405
|
+
__name(isTypeDef, "isTypeDef");
|
|
386
406
|
function buildJoinPairs(schema, model, modelAlias, relationField, relationModelAlias) {
|
|
387
407
|
const { keyPairs, ownedByModel } = getRelationForeignKeyFieldPairs(schema, model, relationField);
|
|
388
408
|
return keyPairs.map(({ fk, pk }) => {
|
|
@@ -632,6 +652,33 @@ var import_common_helpers3 = require("@zenstackhq/common-helpers");
|
|
|
632
652
|
var import_decimal = __toESM(require("decimal.js"), 1);
|
|
633
653
|
var import_kysely3 = require("kysely");
|
|
634
654
|
var import_ts_pattern3 = require("ts-pattern");
|
|
655
|
+
var import_zod = __toESM(require("zod"), 1);
|
|
656
|
+
|
|
657
|
+
// src/common-types.ts
|
|
658
|
+
var DbNullClass = class {
|
|
659
|
+
static {
|
|
660
|
+
__name(this, "DbNullClass");
|
|
661
|
+
}
|
|
662
|
+
// @ts-ignore
|
|
663
|
+
__brand = "DbNull";
|
|
664
|
+
};
|
|
665
|
+
var DbNull = new DbNullClass();
|
|
666
|
+
var JsonNullClass = class {
|
|
667
|
+
static {
|
|
668
|
+
__name(this, "JsonNullClass");
|
|
669
|
+
}
|
|
670
|
+
// @ts-ignore
|
|
671
|
+
__brand = "JsonNull";
|
|
672
|
+
};
|
|
673
|
+
var JsonNull = new JsonNullClass();
|
|
674
|
+
var AnyNullClass = class {
|
|
675
|
+
static {
|
|
676
|
+
__name(this, "AnyNullClass");
|
|
677
|
+
}
|
|
678
|
+
// @ts-ignore
|
|
679
|
+
__brand = "AnyNull";
|
|
680
|
+
};
|
|
681
|
+
var AnyNull = new AnyNullClass();
|
|
635
682
|
|
|
636
683
|
// src/client/crud/dialects/base-dialect.ts
|
|
637
684
|
var import_common_helpers2 = require("@zenstackhq/common-helpers");
|
|
@@ -904,12 +951,174 @@ var BaseCrudDialect = class {
|
|
|
904
951
|
if (isEnum(this.schema, fieldDef.type)) {
|
|
905
952
|
return this.buildEnumFilter(fieldRef, fieldDef, payload);
|
|
906
953
|
}
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
}
|
|
954
|
+
if (isTypeDef(this.schema, fieldDef.type)) {
|
|
955
|
+
return this.buildJsonFilter(fieldRef, payload, fieldDef);
|
|
956
|
+
}
|
|
957
|
+
return (0, import_ts_pattern2.match)(fieldDef.type).with("String", () => this.buildStringFilter(fieldRef, payload)).with(import_ts_pattern2.P.union("Int", "Float", "Decimal", "BigInt"), (type) => this.buildNumberFilter(fieldRef, type, payload)).with("Boolean", () => this.buildBooleanFilter(fieldRef, payload)).with("DateTime", () => this.buildDateTimeFilter(fieldRef, payload)).with("Bytes", () => this.buildBytesFilter(fieldRef, payload)).with("Json", () => this.buildJsonFilter(fieldRef, payload, fieldDef)).with("Unsupported", () => {
|
|
910
958
|
throw createInvalidInputError(`Unsupported field cannot be used in filters`);
|
|
911
959
|
}).exhaustive();
|
|
912
960
|
}
|
|
961
|
+
buildJsonFilter(receiver, filter, fieldDef) {
|
|
962
|
+
(0, import_common_helpers2.invariant)(filter && typeof filter === "object", "Json filter payload must be an object");
|
|
963
|
+
if ([
|
|
964
|
+
"path",
|
|
965
|
+
"equals",
|
|
966
|
+
"not",
|
|
967
|
+
"string_contains",
|
|
968
|
+
"string_starts_with",
|
|
969
|
+
"string_ends_with",
|
|
970
|
+
"array_contains",
|
|
971
|
+
"array_starts_with",
|
|
972
|
+
"array_ends_with"
|
|
973
|
+
].some((k) => k in filter)) {
|
|
974
|
+
return this.buildPlainJsonFilter(receiver, filter);
|
|
975
|
+
} else if (isTypeDef(this.schema, fieldDef.type)) {
|
|
976
|
+
return this.buildTypedJsonFilter(receiver, filter, fieldDef.type, !!fieldDef.array);
|
|
977
|
+
} else {
|
|
978
|
+
throw createInvalidInputError(`Invalid JSON filter payload`);
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
buildPlainJsonFilter(receiver, filter) {
|
|
982
|
+
const clauses = [];
|
|
983
|
+
const path = filter.path;
|
|
984
|
+
const jsonReceiver = this.buildJsonPathSelection(receiver, path);
|
|
985
|
+
const stringReceiver = this.eb.cast(jsonReceiver, "text");
|
|
986
|
+
const mode = filter.mode ?? "default";
|
|
987
|
+
(0, import_common_helpers2.invariant)(mode === "default" || mode === "insensitive", "Invalid JSON filter mode");
|
|
988
|
+
for (const [key, value] of Object.entries(filter)) {
|
|
989
|
+
switch (key) {
|
|
990
|
+
case "equals": {
|
|
991
|
+
clauses.push(this.buildJsonValueFilterClause(jsonReceiver, value));
|
|
992
|
+
break;
|
|
993
|
+
}
|
|
994
|
+
case "not": {
|
|
995
|
+
clauses.push(this.eb.not(this.buildJsonValueFilterClause(jsonReceiver, value)));
|
|
996
|
+
break;
|
|
997
|
+
}
|
|
998
|
+
case "string_contains": {
|
|
999
|
+
(0, import_common_helpers2.invariant)(typeof value === "string", "string_contains value must be a string");
|
|
1000
|
+
clauses.push(this.buildJsonStringFilter(stringReceiver, key, value, mode));
|
|
1001
|
+
break;
|
|
1002
|
+
}
|
|
1003
|
+
case "string_starts_with": {
|
|
1004
|
+
(0, import_common_helpers2.invariant)(typeof value === "string", "string_starts_with value must be a string");
|
|
1005
|
+
clauses.push(this.buildJsonStringFilter(stringReceiver, key, value, mode));
|
|
1006
|
+
break;
|
|
1007
|
+
}
|
|
1008
|
+
case "string_ends_with": {
|
|
1009
|
+
(0, import_common_helpers2.invariant)(typeof value === "string", "string_ends_with value must be a string");
|
|
1010
|
+
clauses.push(this.buildJsonStringFilter(stringReceiver, key, value, mode));
|
|
1011
|
+
break;
|
|
1012
|
+
}
|
|
1013
|
+
case "array_contains": {
|
|
1014
|
+
clauses.push(this.buildJsonArrayFilter(jsonReceiver, key, value));
|
|
1015
|
+
break;
|
|
1016
|
+
}
|
|
1017
|
+
case "array_starts_with": {
|
|
1018
|
+
clauses.push(this.buildJsonArrayFilter(jsonReceiver, key, value));
|
|
1019
|
+
break;
|
|
1020
|
+
}
|
|
1021
|
+
case "array_ends_with": {
|
|
1022
|
+
clauses.push(this.buildJsonArrayFilter(jsonReceiver, key, value));
|
|
1023
|
+
break;
|
|
1024
|
+
}
|
|
1025
|
+
case "path":
|
|
1026
|
+
case "mode":
|
|
1027
|
+
break;
|
|
1028
|
+
default:
|
|
1029
|
+
throw createInvalidInputError(`Invalid JSON filter key: ${key}`);
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
return this.and(...clauses);
|
|
1033
|
+
}
|
|
1034
|
+
buildTypedJsonFilter(receiver, filter, typeDefName, array) {
|
|
1035
|
+
if (array) {
|
|
1036
|
+
return this.buildTypedJsonArrayFilter(receiver, filter, typeDefName);
|
|
1037
|
+
} else {
|
|
1038
|
+
return this.buildTypeJsonNonArrayFilter(receiver, filter, typeDefName);
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
buildTypedJsonArrayFilter(receiver, filter, typeDefName) {
|
|
1042
|
+
(0, import_common_helpers2.invariant)(filter && typeof filter === "object", "Typed JSON array filter payload must be an object");
|
|
1043
|
+
const makeExistsPred = /* @__PURE__ */ __name((filter2) => this.buildJsonArrayExistsPredicate(receiver, (elem) => this.buildTypedJsonFilter(elem, filter2, typeDefName, false)), "makeExistsPred");
|
|
1044
|
+
const makeExistsNegatedPred = /* @__PURE__ */ __name((filter2) => this.buildJsonArrayExistsPredicate(receiver, (elem) => this.eb.not(this.buildTypedJsonFilter(elem, filter2, typeDefName, false))), "makeExistsNegatedPred");
|
|
1045
|
+
const clauses = [];
|
|
1046
|
+
for (const [key, value] of Object.entries(filter)) {
|
|
1047
|
+
if (!value || typeof value !== "object") {
|
|
1048
|
+
continue;
|
|
1049
|
+
}
|
|
1050
|
+
switch (key) {
|
|
1051
|
+
case "some":
|
|
1052
|
+
clauses.push(makeExistsPred(value));
|
|
1053
|
+
break;
|
|
1054
|
+
case "none":
|
|
1055
|
+
clauses.push(this.eb.not(makeExistsPred(value)));
|
|
1056
|
+
break;
|
|
1057
|
+
case "every":
|
|
1058
|
+
clauses.push(this.eb.not(makeExistsNegatedPred(value)));
|
|
1059
|
+
break;
|
|
1060
|
+
default:
|
|
1061
|
+
(0, import_common_helpers2.invariant)(false, `Invalid typed JSON array filter key: ${key}`);
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
return this.and(...clauses);
|
|
1065
|
+
}
|
|
1066
|
+
buildTypeJsonNonArrayFilter(receiver, filter, typeDefName) {
|
|
1067
|
+
const clauses = [];
|
|
1068
|
+
if (filter === null) {
|
|
1069
|
+
return this.eb(receiver, "=", "null");
|
|
1070
|
+
}
|
|
1071
|
+
(0, import_common_helpers2.invariant)(filter && typeof filter === "object", "Typed JSON filter payload must be an object");
|
|
1072
|
+
if ("is" in filter || "isNot" in filter) {
|
|
1073
|
+
if ("is" in filter && filter.is && typeof filter.is === "object") {
|
|
1074
|
+
clauses.push(this.buildTypedJsonFilter(receiver, filter.is, typeDefName, false));
|
|
1075
|
+
}
|
|
1076
|
+
if ("isNot" in filter && filter.isNot && typeof filter.isNot === "object") {
|
|
1077
|
+
clauses.push(this.eb.not(this.buildTypedJsonFilter(receiver, filter.isNot, typeDefName, false)));
|
|
1078
|
+
}
|
|
1079
|
+
} else {
|
|
1080
|
+
const typeDef = requireTypeDef(this.schema, typeDefName);
|
|
1081
|
+
for (const [key, value] of Object.entries(filter)) {
|
|
1082
|
+
const fieldDef = typeDef.fields[key];
|
|
1083
|
+
(0, import_common_helpers2.invariant)(fieldDef, `Field "${key}" not found in type definition "${typeDefName}"`);
|
|
1084
|
+
const fieldReceiver = this.buildJsonPathSelection(receiver, `$.${key}`);
|
|
1085
|
+
if (isTypeDef(this.schema, fieldDef.type)) {
|
|
1086
|
+
clauses.push(this.buildTypedJsonFilter(fieldReceiver, value, fieldDef.type, !!fieldDef.array));
|
|
1087
|
+
} else {
|
|
1088
|
+
if (fieldDef.array) {
|
|
1089
|
+
clauses.push(this.buildArrayFilter(fieldReceiver, fieldDef, value));
|
|
1090
|
+
} else {
|
|
1091
|
+
let _receiver = fieldReceiver;
|
|
1092
|
+
if (fieldDef.type === "String") {
|
|
1093
|
+
_receiver = this.eb.fn("trim", [
|
|
1094
|
+
this.eb.cast(fieldReceiver, "text"),
|
|
1095
|
+
import_kysely2.sql.lit('"')
|
|
1096
|
+
]);
|
|
1097
|
+
}
|
|
1098
|
+
clauses.push(this.buildPrimitiveFilter(_receiver, fieldDef, value));
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
return this.and(...clauses);
|
|
1104
|
+
}
|
|
1105
|
+
buildJsonValueFilterClause(lhs, value) {
|
|
1106
|
+
if (value instanceof DbNullClass) {
|
|
1107
|
+
return this.eb(lhs, "is", null);
|
|
1108
|
+
} else if (value instanceof JsonNullClass) {
|
|
1109
|
+
return this.eb.and([
|
|
1110
|
+
this.eb(lhs, "=", "null"),
|
|
1111
|
+
this.eb(lhs, "is not", null)
|
|
1112
|
+
]);
|
|
1113
|
+
} else if (value instanceof AnyNullClass) {
|
|
1114
|
+
return this.eb.or([
|
|
1115
|
+
this.eb(lhs, "is", null),
|
|
1116
|
+
this.eb(lhs, "=", "null")
|
|
1117
|
+
]);
|
|
1118
|
+
} else {
|
|
1119
|
+
return this.buildLiteralFilter(lhs, "Json", value);
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
913
1122
|
buildLiteralFilter(lhs, type, rhs) {
|
|
914
1123
|
return this.eb(lhs, "=", rhs !== null && rhs !== void 0 ? this.transformPrimitive(rhs, type, false) : rhs);
|
|
915
1124
|
}
|
|
@@ -980,7 +1189,9 @@ var BaseCrudDialect = class {
|
|
|
980
1189
|
if (key === "mode" || consumedKeys.includes(key)) {
|
|
981
1190
|
continue;
|
|
982
1191
|
}
|
|
983
|
-
|
|
1192
|
+
(0, import_common_helpers2.invariant)(typeof value === "string", `${key} value must be a string`);
|
|
1193
|
+
const escapedValue = this.escapeLikePattern(value);
|
|
1194
|
+
const condition = (0, import_ts_pattern2.match)(key).with("contains", () => this.buildStringLike(fieldRef, `%${escapedValue}%`, mode === "insensitive")).with("startsWith", () => this.buildStringLike(fieldRef, `${escapedValue}%`, mode === "insensitive")).with("endsWith", () => this.buildStringLike(fieldRef, `%${escapedValue}`, mode === "insensitive")).otherwise(() => {
|
|
984
1195
|
throw createInvalidInputError(`Invalid string filter key: ${key}`);
|
|
985
1196
|
});
|
|
986
1197
|
if (condition) {
|
|
@@ -990,6 +1201,19 @@ var BaseCrudDialect = class {
|
|
|
990
1201
|
}
|
|
991
1202
|
return this.and(...conditions);
|
|
992
1203
|
}
|
|
1204
|
+
buildJsonStringFilter(receiver, operation, value, mode) {
|
|
1205
|
+
const escapedValue = this.escapeLikePattern(value);
|
|
1206
|
+
const pattern = (0, import_ts_pattern2.match)(operation).with("string_contains", () => `"%${escapedValue}%"`).with("string_starts_with", () => `"${escapedValue}%"`).with("string_ends_with", () => `"%${escapedValue}"`).exhaustive();
|
|
1207
|
+
return this.buildStringLike(receiver, pattern, mode === "insensitive");
|
|
1208
|
+
}
|
|
1209
|
+
escapeLikePattern(pattern) {
|
|
1210
|
+
return pattern.replace(/\\/g, "\\\\").replace(/%/g, "\\%").replace(/_/g, "\\_");
|
|
1211
|
+
}
|
|
1212
|
+
buildStringLike(receiver, pattern, insensitive) {
|
|
1213
|
+
const { supportsILike } = this.getStringCasingBehavior();
|
|
1214
|
+
const op = insensitive && supportsILike ? "ilike" : "like";
|
|
1215
|
+
return import_kysely2.sql`${receiver} ${import_kysely2.sql.raw(op)} ${import_kysely2.sql.val(pattern)} escape '\\'`;
|
|
1216
|
+
}
|
|
993
1217
|
prepStringCasing(eb, value, mode) {
|
|
994
1218
|
if (!mode || mode === "default") {
|
|
995
1219
|
return value === null ? value : import_kysely2.sql.val(value);
|
|
@@ -1301,6 +1525,10 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
|
|
|
1301
1525
|
static {
|
|
1302
1526
|
__name(this, "PostgresCrudDialect");
|
|
1303
1527
|
}
|
|
1528
|
+
isoDateSchema = import_zod.default.iso.datetime({
|
|
1529
|
+
local: true,
|
|
1530
|
+
offset: true
|
|
1531
|
+
});
|
|
1304
1532
|
constructor(schema, options) {
|
|
1305
1533
|
super(schema, options);
|
|
1306
1534
|
}
|
|
@@ -1311,6 +1539,13 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
|
|
|
1311
1539
|
if (value === void 0) {
|
|
1312
1540
|
return value;
|
|
1313
1541
|
}
|
|
1542
|
+
if (value instanceof JsonNullClass) {
|
|
1543
|
+
return "null";
|
|
1544
|
+
} else if (value instanceof DbNullClass) {
|
|
1545
|
+
return null;
|
|
1546
|
+
} else if (value instanceof AnyNullClass) {
|
|
1547
|
+
(0, import_common_helpers3.invariant)(false, "should not reach here: AnyNull is not a valid input value");
|
|
1548
|
+
}
|
|
1314
1549
|
if (Array.isArray(value)) {
|
|
1315
1550
|
if (type === "Json" && !forArrayField) {
|
|
1316
1551
|
return JSON.stringify(value);
|
|
@@ -1349,7 +1584,12 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
|
|
|
1349
1584
|
}
|
|
1350
1585
|
transformOutputDate(value) {
|
|
1351
1586
|
if (typeof value === "string") {
|
|
1352
|
-
|
|
1587
|
+
if (this.isoDateSchema.safeParse(value).success) {
|
|
1588
|
+
const hasOffset = value.endsWith("Z") || /[+-]\d{2}:\d{2}$/.test(value);
|
|
1589
|
+
return new Date(hasOffset ? value : `${value}Z`);
|
|
1590
|
+
} else {
|
|
1591
|
+
return value;
|
|
1592
|
+
}
|
|
1353
1593
|
} else if (value instanceof Date && this.options.fixPostgresTimezone !== false) {
|
|
1354
1594
|
return new Date(value.getTime() - value.getTimezoneOffset() * 60 * 1e3);
|
|
1355
1595
|
} else {
|
|
@@ -1502,6 +1742,35 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
|
|
|
1502
1742
|
return `ARRAY[${values.map((v) => typeof v === "string" ? `'${v}'` : v)}]`;
|
|
1503
1743
|
}
|
|
1504
1744
|
}
|
|
1745
|
+
buildJsonPathSelection(receiver, path) {
|
|
1746
|
+
if (path) {
|
|
1747
|
+
return this.eb.fn("jsonb_path_query_first", [
|
|
1748
|
+
receiver,
|
|
1749
|
+
this.eb.val(path)
|
|
1750
|
+
]);
|
|
1751
|
+
} else {
|
|
1752
|
+
return receiver;
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
buildJsonArrayFilter(lhs, operation, value) {
|
|
1756
|
+
return (0, import_ts_pattern3.match)(operation).with("array_contains", () => {
|
|
1757
|
+
const v = Array.isArray(value) ? value : [
|
|
1758
|
+
value
|
|
1759
|
+
];
|
|
1760
|
+
return import_kysely3.sql`${lhs} @> ${import_kysely3.sql.val(JSON.stringify(v))}::jsonb`;
|
|
1761
|
+
}).with("array_starts_with", () => this.eb(this.eb.fn("jsonb_extract_path", [
|
|
1762
|
+
lhs,
|
|
1763
|
+
this.eb.val("0")
|
|
1764
|
+
]), "=", this.transformPrimitive(value, "Json", false))).with("array_ends_with", () => this.eb(this.eb.fn("jsonb_extract_path", [
|
|
1765
|
+
lhs,
|
|
1766
|
+
import_kysely3.sql`(jsonb_array_length(${lhs}) - 1)::text`
|
|
1767
|
+
]), "=", this.transformPrimitive(value, "Json", false))).exhaustive();
|
|
1768
|
+
}
|
|
1769
|
+
buildJsonArrayExistsPredicate(receiver, buildFilter) {
|
|
1770
|
+
return this.eb.exists(this.eb.selectFrom(this.eb.fn("jsonb_array_elements", [
|
|
1771
|
+
receiver
|
|
1772
|
+
]).as("$items")).select(this.eb.lit(1).as("$t")).where(buildFilter(this.eb.ref("$items.value"))));
|
|
1773
|
+
}
|
|
1505
1774
|
get supportInsertWithDefault() {
|
|
1506
1775
|
return true;
|
|
1507
1776
|
}
|
|
@@ -1544,14 +1813,20 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
1544
1813
|
if (value === void 0) {
|
|
1545
1814
|
return value;
|
|
1546
1815
|
}
|
|
1816
|
+
if (value instanceof JsonNullClass) {
|
|
1817
|
+
return "null";
|
|
1818
|
+
} else if (value instanceof DbNullClass) {
|
|
1819
|
+
return null;
|
|
1820
|
+
} else if (value instanceof AnyNullClass) {
|
|
1821
|
+
(0, import_common_helpers4.invariant)(false, "should not reach here: AnyNull is not a valid input value");
|
|
1822
|
+
}
|
|
1823
|
+
if (type === "Json" || this.schema.typeDefs && type in this.schema.typeDefs) {
|
|
1824
|
+
return JSON.stringify(value);
|
|
1825
|
+
}
|
|
1547
1826
|
if (Array.isArray(value)) {
|
|
1548
1827
|
return value.map((v) => this.transformPrimitive(v, type, false));
|
|
1549
1828
|
} else {
|
|
1550
|
-
|
|
1551
|
-
return JSON.stringify(value);
|
|
1552
|
-
} else {
|
|
1553
|
-
return (0, import_ts_pattern4.match)(type).with("Boolean", () => value ? 1 : 0).with("DateTime", () => value instanceof Date ? value.toISOString() : typeof value === "string" ? new Date(value).toISOString() : value).with("Decimal", () => value.toString()).with("Bytes", () => Buffer.from(value)).with("Json", () => JSON.stringify(value)).otherwise(() => value);
|
|
1554
|
-
}
|
|
1829
|
+
return (0, import_ts_pattern4.match)(type).with("Boolean", () => value ? 1 : 0).with("DateTime", () => value instanceof Date ? value.toISOString() : typeof value === "string" ? new Date(value).toISOString() : value).with("Decimal", () => value.toString()).with("Bytes", () => Buffer.from(value)).otherwise(() => value);
|
|
1555
1830
|
}
|
|
1556
1831
|
}
|
|
1557
1832
|
transformOutput(value, type) {
|
|
@@ -1721,6 +1996,30 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
1721
1996
|
value2
|
|
1722
1997
|
]));
|
|
1723
1998
|
}
|
|
1999
|
+
buildJsonPathSelection(receiver, path) {
|
|
2000
|
+
if (!path) {
|
|
2001
|
+
return receiver;
|
|
2002
|
+
} else {
|
|
2003
|
+
return import_kysely4.sql`${receiver} -> ${this.eb.val(path)}`;
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
buildJsonArrayFilter(lhs, operation, value) {
|
|
2007
|
+
return (0, import_ts_pattern4.match)(operation).with("array_contains", () => {
|
|
2008
|
+
if (Array.isArray(value)) {
|
|
2009
|
+
throw createNotSupportedError('SQLite "array_contains" only supports checking for a single value, not an array of values');
|
|
2010
|
+
} else {
|
|
2011
|
+
return import_kysely4.sql`EXISTS (SELECT 1 FROM jsonb_each(${lhs}) WHERE value = ${value})`;
|
|
2012
|
+
}
|
|
2013
|
+
}).with("array_starts_with", () => this.eb(this.eb.fn("json_extract", [
|
|
2014
|
+
lhs,
|
|
2015
|
+
this.eb.val("$[0]")
|
|
2016
|
+
]), "=", value)).with("array_ends_with", () => this.eb(import_kysely4.sql`json_extract(${lhs}, '$[' || (json_array_length(${lhs}) - 1) || ']')`, "=", value)).exhaustive();
|
|
2017
|
+
}
|
|
2018
|
+
buildJsonArrayExistsPredicate(receiver, buildFilter) {
|
|
2019
|
+
return this.eb.exists(this.eb.selectFrom(this.eb.fn("jsonb_each", [
|
|
2020
|
+
receiver
|
|
2021
|
+
]).as("$items")).select(this.eb.lit(1).as("$t")).where(buildFilter(this.eb.ref("$items.value"))));
|
|
2022
|
+
}
|
|
1724
2023
|
get supportsUpdateWithLimit() {
|
|
1725
2024
|
return false;
|
|
1726
2025
|
}
|
|
@@ -2339,8 +2638,16 @@ var BaseOperationHandler = class {
|
|
|
2339
2638
|
autoUpdatedFields.push(fieldName);
|
|
2340
2639
|
}
|
|
2341
2640
|
}
|
|
2641
|
+
const thisEntity = await this.getEntityIds(kysely, model, combinedWhere);
|
|
2642
|
+
if (!thisEntity) {
|
|
2643
|
+
if (throwIfNotFound) {
|
|
2644
|
+
throw createNotFoundError(model);
|
|
2645
|
+
} else {
|
|
2646
|
+
return null;
|
|
2647
|
+
}
|
|
2648
|
+
}
|
|
2342
2649
|
if (Object.keys(finalData).length === 0) {
|
|
2343
|
-
return
|
|
2650
|
+
return thisEntity;
|
|
2344
2651
|
}
|
|
2345
2652
|
let needIdRead = false;
|
|
2346
2653
|
if (modelDef.baseModel && !this.isIdFilter(model, combinedWhere)) {
|
|
@@ -2360,9 +2667,15 @@ var BaseOperationHandler = class {
|
|
|
2360
2667
|
const baseUpdateResult = await this.processBaseModelUpdate(kysely, modelDef.baseModel, combinedWhere, finalData, throwIfNotFound);
|
|
2361
2668
|
finalData = baseUpdateResult.remainingFields;
|
|
2362
2669
|
combinedWhere = baseUpdateResult.baseEntity;
|
|
2670
|
+
if (baseUpdateResult.baseEntity) {
|
|
2671
|
+
for (const [key, value] of Object.entries(baseUpdateResult.baseEntity)) {
|
|
2672
|
+
if (key in thisEntity) {
|
|
2673
|
+
thisEntity[key] = value;
|
|
2674
|
+
}
|
|
2675
|
+
}
|
|
2676
|
+
}
|
|
2363
2677
|
}
|
|
2364
2678
|
const updateFields = {};
|
|
2365
|
-
let thisEntity = void 0;
|
|
2366
2679
|
for (const field in finalData) {
|
|
2367
2680
|
const fieldDef = this.requireField(model, field);
|
|
2368
2681
|
if (isScalarField(this.schema, model, field) || isForeignKeyField(this.schema, model, field)) {
|
|
@@ -2371,17 +2684,7 @@ var BaseOperationHandler = class {
|
|
|
2371
2684
|
if (!allowRelationUpdate) {
|
|
2372
2685
|
throw createNotSupportedError(`Relation update not allowed for field "${field}"`);
|
|
2373
2686
|
}
|
|
2374
|
-
|
|
2375
|
-
thisEntity = await this.getEntityIds(kysely, model, combinedWhere);
|
|
2376
|
-
if (!thisEntity) {
|
|
2377
|
-
if (throwIfNotFound) {
|
|
2378
|
-
throw createNotFoundError(model);
|
|
2379
|
-
} else {
|
|
2380
|
-
return null;
|
|
2381
|
-
}
|
|
2382
|
-
}
|
|
2383
|
-
}
|
|
2384
|
-
const parentUpdates = await this.processRelationUpdates(kysely, model, field, fieldDef, thisEntity, finalData[field], throwIfNotFound);
|
|
2687
|
+
const parentUpdates = await this.processRelationUpdates(kysely, model, field, fieldDef, thisEntity, finalData[field]);
|
|
2385
2688
|
if (Object.keys(parentUpdates).length > 0) {
|
|
2386
2689
|
Object.assign(updateFields, parentUpdates);
|
|
2387
2690
|
}
|
|
@@ -2392,7 +2695,7 @@ var BaseOperationHandler = class {
|
|
|
2392
2695
|
hasFieldUpdate = Object.keys(updateFields).some((f) => !autoUpdatedFields.includes(f));
|
|
2393
2696
|
}
|
|
2394
2697
|
if (!hasFieldUpdate) {
|
|
2395
|
-
return
|
|
2698
|
+
return thisEntity;
|
|
2396
2699
|
} else {
|
|
2397
2700
|
fieldsToReturn = fieldsToReturn ?? requireIdFields(this.schema, model);
|
|
2398
2701
|
const query = kysely.updateTable(model).where(() => this.dialect.buildFilter(model, model, combinedWhere)).set(updateFields).returning(fieldsToReturn).modifyEnd(this.makeContextComment({
|
|
@@ -2571,7 +2874,7 @@ var BaseOperationHandler = class {
|
|
|
2571
2874
|
const idFields = requireIdFields(this.schema, model);
|
|
2572
2875
|
return idFields.map((f) => kysely.dynamic.ref(`${model}.${f}`));
|
|
2573
2876
|
}
|
|
2574
|
-
async processRelationUpdates(kysely, model, field, fieldDef, parentIds, args
|
|
2877
|
+
async processRelationUpdates(kysely, model, field, fieldDef, parentIds, args) {
|
|
2575
2878
|
const fieldModel = fieldDef.type;
|
|
2576
2879
|
const fromRelationContext = {
|
|
2577
2880
|
model,
|
|
@@ -2622,6 +2925,7 @@ var BaseOperationHandler = class {
|
|
|
2622
2925
|
where = void 0;
|
|
2623
2926
|
data = item;
|
|
2624
2927
|
}
|
|
2928
|
+
const throwIfNotFound = !fieldDef.array || !!where;
|
|
2625
2929
|
await this.update(kysely, fieldModel, where, data, fromRelationContext, true, throwIfNotFound);
|
|
2626
2930
|
}
|
|
2627
2931
|
break;
|
|
@@ -3631,7 +3935,7 @@ var import_common_helpers7 = require("@zenstackhq/common-helpers");
|
|
|
3631
3935
|
var import_decimal4 = __toESM(require("decimal.js"), 1);
|
|
3632
3936
|
var import_json_stable_stringify = __toESM(require("json-stable-stringify"), 1);
|
|
3633
3937
|
var import_ts_pattern13 = require("ts-pattern");
|
|
3634
|
-
var
|
|
3938
|
+
var import_zod3 = require("zod");
|
|
3635
3939
|
|
|
3636
3940
|
// src/utils/zod-utils.ts
|
|
3637
3941
|
var import_v4 = require("zod-validation-error/v4");
|
|
@@ -3644,7 +3948,7 @@ __name(formatError, "formatError");
|
|
|
3644
3948
|
var import_common_helpers6 = require("@zenstackhq/common-helpers");
|
|
3645
3949
|
var import_decimal3 = __toESM(require("decimal.js"), 1);
|
|
3646
3950
|
var import_ts_pattern12 = require("ts-pattern");
|
|
3647
|
-
var
|
|
3951
|
+
var import_zod2 = require("zod");
|
|
3648
3952
|
var import_v3 = require("zod/v3");
|
|
3649
3953
|
function getArgValue(expr) {
|
|
3650
3954
|
if (!expr || !schema_exports.ExpressionUtils.isLiteral(expr)) {
|
|
@@ -3753,13 +4057,13 @@ function addBigIntValidation(schema, attributes) {
|
|
|
3753
4057
|
__name(addBigIntValidation, "addBigIntValidation");
|
|
3754
4058
|
function addDecimalValidation(schema, attributes, addExtraValidation) {
|
|
3755
4059
|
let result = schema;
|
|
3756
|
-
if (schema instanceof
|
|
4060
|
+
if (schema instanceof import_zod2.z.ZodString) {
|
|
3757
4061
|
result = schema.superRefine((v, ctx) => {
|
|
3758
4062
|
try {
|
|
3759
4063
|
new import_decimal3.default(v);
|
|
3760
4064
|
} catch (err) {
|
|
3761
4065
|
ctx.addIssue({
|
|
3762
|
-
code:
|
|
4066
|
+
code: import_zod2.z.ZodIssueCode.custom,
|
|
3763
4067
|
message: `Invalid decimal: ${err}`
|
|
3764
4068
|
});
|
|
3765
4069
|
}
|
|
@@ -3767,7 +4071,7 @@ function addDecimalValidation(schema, attributes, addExtraValidation) {
|
|
|
3767
4071
|
}
|
|
3768
4072
|
function refine(schema2, op, value) {
|
|
3769
4073
|
return schema2.superRefine((v, ctx) => {
|
|
3770
|
-
const base =
|
|
4074
|
+
const base = import_zod2.z.number();
|
|
3771
4075
|
const { error } = base[op](value).safeParse(v.toNumber());
|
|
3772
4076
|
error?.issues.forEach((issue) => {
|
|
3773
4077
|
if (op === "gt" || op === "gte") {
|
|
@@ -3972,7 +4276,7 @@ function evalCall(data, expr) {
|
|
|
3972
4276
|
}
|
|
3973
4277
|
(0, import_common_helpers6.invariant)(typeof fieldArg === "string", `"${f}" first argument must be a string`);
|
|
3974
4278
|
const fn = (0, import_ts_pattern12.match)(f).with("isEmail", () => "email").with("isUrl", () => "url").with("isDateTime", () => "datetime").exhaustive();
|
|
3975
|
-
return
|
|
4279
|
+
return import_zod2.z.string()[fn]().safeParse(fieldArg).success;
|
|
3976
4280
|
}).with(import_ts_pattern12.P.union("has", "hasEvery", "hasSome"), (f) => {
|
|
3977
4281
|
(0, import_common_helpers6.invariant)(expr.args?.[1], `${f} requires a search argument`);
|
|
3978
4282
|
if (fieldArg === void 0 || fieldArg === null) {
|
|
@@ -4110,7 +4414,7 @@ var InputValidator = class {
|
|
|
4110
4414
|
if (!options.unique) {
|
|
4111
4415
|
fields["skip"] = this.makeSkipSchema().optional();
|
|
4112
4416
|
if (options.findOne) {
|
|
4113
|
-
fields["take"] =
|
|
4417
|
+
fields["take"] = import_zod3.z.literal(1).optional();
|
|
4114
4418
|
} else {
|
|
4115
4419
|
fields["take"] = this.makeTakeSchema().optional();
|
|
4116
4420
|
}
|
|
@@ -4118,7 +4422,7 @@ var InputValidator = class {
|
|
|
4118
4422
|
fields["cursor"] = this.makeCursorSchema(model).optional();
|
|
4119
4423
|
fields["distinct"] = this.makeDistinctSchema(model).optional();
|
|
4120
4424
|
}
|
|
4121
|
-
let result =
|
|
4425
|
+
let result = import_zod3.z.strictObject(fields);
|
|
4122
4426
|
result = this.refineForSelectIncludeMutuallyExclusive(result);
|
|
4123
4427
|
result = this.refineForSelectOmitMutuallyExclusive(result);
|
|
4124
4428
|
if (!options.unique) {
|
|
@@ -4126,25 +4430,25 @@ var InputValidator = class {
|
|
|
4126
4430
|
}
|
|
4127
4431
|
return result;
|
|
4128
4432
|
}
|
|
4129
|
-
|
|
4433
|
+
makeScalarSchema(type, attributes) {
|
|
4130
4434
|
if (this.schema.typeDefs && type in this.schema.typeDefs) {
|
|
4131
4435
|
return this.makeTypeDefSchema(type);
|
|
4132
4436
|
} else if (this.schema.enums && type in this.schema.enums) {
|
|
4133
4437
|
return this.makeEnumSchema(type);
|
|
4134
4438
|
} else {
|
|
4135
|
-
return (0, import_ts_pattern13.match)(type).with("String", () => this.extraValidationsEnabled ? addStringValidation(
|
|
4136
|
-
this.extraValidationsEnabled ? addNumberValidation(
|
|
4137
|
-
this.extraValidationsEnabled ? addBigIntValidation(
|
|
4439
|
+
return (0, import_ts_pattern13.match)(type).with("String", () => this.extraValidationsEnabled ? addStringValidation(import_zod3.z.string(), attributes) : import_zod3.z.string()).with("Int", () => this.extraValidationsEnabled ? addNumberValidation(import_zod3.z.number().int(), attributes) : import_zod3.z.number().int()).with("Float", () => this.extraValidationsEnabled ? addNumberValidation(import_zod3.z.number(), attributes) : import_zod3.z.number()).with("Boolean", () => import_zod3.z.boolean()).with("BigInt", () => import_zod3.z.union([
|
|
4440
|
+
this.extraValidationsEnabled ? addNumberValidation(import_zod3.z.number().int(), attributes) : import_zod3.z.number().int(),
|
|
4441
|
+
this.extraValidationsEnabled ? addBigIntValidation(import_zod3.z.bigint(), attributes) : import_zod3.z.bigint()
|
|
4138
4442
|
])).with("Decimal", () => {
|
|
4139
|
-
return
|
|
4140
|
-
this.extraValidationsEnabled ? addNumberValidation(
|
|
4141
|
-
addDecimalValidation(
|
|
4142
|
-
addDecimalValidation(
|
|
4443
|
+
return import_zod3.z.union([
|
|
4444
|
+
this.extraValidationsEnabled ? addNumberValidation(import_zod3.z.number(), attributes) : import_zod3.z.number(),
|
|
4445
|
+
addDecimalValidation(import_zod3.z.instanceof(import_decimal4.default), attributes, this.extraValidationsEnabled),
|
|
4446
|
+
addDecimalValidation(import_zod3.z.string(), attributes, this.extraValidationsEnabled)
|
|
4143
4447
|
]);
|
|
4144
|
-
}).with("DateTime", () =>
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
])).with("Bytes", () =>
|
|
4448
|
+
}).with("DateTime", () => import_zod3.z.union([
|
|
4449
|
+
import_zod3.z.date(),
|
|
4450
|
+
import_zod3.z.iso.datetime()
|
|
4451
|
+
])).with("Bytes", () => import_zod3.z.instanceof(Uint8Array)).with("Json", () => this.makeJsonValueSchema(false, false)).otherwise(() => import_zod3.z.unknown());
|
|
4148
4452
|
}
|
|
4149
4453
|
}
|
|
4150
4454
|
makeEnumSchema(type) {
|
|
@@ -4158,7 +4462,7 @@ var InputValidator = class {
|
|
|
4158
4462
|
}
|
|
4159
4463
|
const enumDef = getEnum(this.schema, type);
|
|
4160
4464
|
(0, import_common_helpers7.invariant)(enumDef, `Enum "${type}" not found in schema`);
|
|
4161
|
-
schema =
|
|
4465
|
+
schema = import_zod3.z.enum(Object.keys(enumDef.values));
|
|
4162
4466
|
this.setSchemaCache(key, schema);
|
|
4163
4467
|
return schema;
|
|
4164
4468
|
}
|
|
@@ -4174,21 +4478,24 @@ var InputValidator = class {
|
|
|
4174
4478
|
}
|
|
4175
4479
|
const typeDef = getTypeDef(this.schema, type);
|
|
4176
4480
|
(0, import_common_helpers7.invariant)(typeDef, `Type definition "${type}" not found in schema`);
|
|
4177
|
-
schema =
|
|
4178
|
-
let fieldSchema = this.
|
|
4481
|
+
schema = import_zod3.z.looseObject(Object.fromEntries(Object.entries(typeDef.fields).map(([field, def]) => {
|
|
4482
|
+
let fieldSchema = this.makeScalarSchema(def.type);
|
|
4179
4483
|
if (def.array) {
|
|
4180
4484
|
fieldSchema = fieldSchema.array();
|
|
4181
4485
|
}
|
|
4182
4486
|
if (def.optional) {
|
|
4183
|
-
fieldSchema = fieldSchema.
|
|
4487
|
+
fieldSchema = fieldSchema.nullish();
|
|
4184
4488
|
}
|
|
4185
4489
|
return [
|
|
4186
4490
|
field,
|
|
4187
4491
|
fieldSchema
|
|
4188
4492
|
];
|
|
4189
4493
|
})));
|
|
4190
|
-
|
|
4191
|
-
|
|
4494
|
+
const finalSchema = import_zod3.z.custom((v) => {
|
|
4495
|
+
return schema.safeParse(v).success;
|
|
4496
|
+
});
|
|
4497
|
+
this.setSchemaCache(key, finalSchema);
|
|
4498
|
+
return finalSchema;
|
|
4192
4499
|
}
|
|
4193
4500
|
makeWhereSchema(model, unique, withoutRelationFields = false, withAggregations = false) {
|
|
4194
4501
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -4200,21 +4507,21 @@ var InputValidator = class {
|
|
|
4200
4507
|
if (withoutRelationFields) {
|
|
4201
4508
|
continue;
|
|
4202
4509
|
}
|
|
4203
|
-
fieldSchema =
|
|
4510
|
+
fieldSchema = import_zod3.z.lazy(() => this.makeWhereSchema(fieldDef.type, false).optional());
|
|
4204
4511
|
fieldSchema = this.nullableIf(fieldSchema, !fieldDef.array && !!fieldDef.optional);
|
|
4205
4512
|
if (fieldDef.array) {
|
|
4206
|
-
fieldSchema =
|
|
4513
|
+
fieldSchema = import_zod3.z.union([
|
|
4207
4514
|
fieldSchema,
|
|
4208
|
-
|
|
4515
|
+
import_zod3.z.strictObject({
|
|
4209
4516
|
some: fieldSchema.optional(),
|
|
4210
4517
|
every: fieldSchema.optional(),
|
|
4211
4518
|
none: fieldSchema.optional()
|
|
4212
4519
|
})
|
|
4213
4520
|
]);
|
|
4214
4521
|
} else {
|
|
4215
|
-
fieldSchema =
|
|
4522
|
+
fieldSchema = import_zod3.z.union([
|
|
4216
4523
|
fieldSchema,
|
|
4217
|
-
|
|
4524
|
+
import_zod3.z.strictObject({
|
|
4218
4525
|
is: fieldSchema.optional(),
|
|
4219
4526
|
isNot: fieldSchema.optional()
|
|
4220
4527
|
})
|
|
@@ -4228,6 +4535,8 @@ var InputValidator = class {
|
|
|
4228
4535
|
}
|
|
4229
4536
|
} else if (fieldDef.array) {
|
|
4230
4537
|
fieldSchema = this.makeArrayFilterSchema(fieldDef.type);
|
|
4538
|
+
} else if (this.isTypeDefType(fieldDef.type)) {
|
|
4539
|
+
fieldSchema = this.makeTypedJsonFilterSchema(fieldDef.type, !!fieldDef.optional, !!fieldDef.array);
|
|
4231
4540
|
} else {
|
|
4232
4541
|
fieldSchema = this.makePrimitiveFilterSchema(fieldDef.type, !!fieldDef.optional, withAggregations);
|
|
4233
4542
|
}
|
|
@@ -4240,7 +4549,7 @@ var InputValidator = class {
|
|
|
4240
4549
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
4241
4550
|
for (const uniqueField of uniqueFields) {
|
|
4242
4551
|
if ("defs" in uniqueField) {
|
|
4243
|
-
fields[uniqueField.name] =
|
|
4552
|
+
fields[uniqueField.name] = import_zod3.z.object(Object.fromEntries(Object.entries(uniqueField.defs).map(([key, def]) => {
|
|
4244
4553
|
(0, import_common_helpers7.invariant)(!def.relation, "unique field cannot be a relation");
|
|
4245
4554
|
let fieldSchema;
|
|
4246
4555
|
const enumDef = getEnum(this.schema, def.type);
|
|
@@ -4248,7 +4557,7 @@ var InputValidator = class {
|
|
|
4248
4557
|
if (Object.keys(enumDef.values).length > 0) {
|
|
4249
4558
|
fieldSchema = this.makeEnumFilterSchema(enumDef, !!def.optional, false);
|
|
4250
4559
|
} else {
|
|
4251
|
-
fieldSchema =
|
|
4560
|
+
fieldSchema = import_zod3.z.never();
|
|
4252
4561
|
}
|
|
4253
4562
|
} else {
|
|
4254
4563
|
fieldSchema = this.makePrimitiveFilterSchema(def.type, !!def.optional, false);
|
|
@@ -4261,11 +4570,11 @@ var InputValidator = class {
|
|
|
4261
4570
|
}
|
|
4262
4571
|
}
|
|
4263
4572
|
}
|
|
4264
|
-
fields["$expr"] =
|
|
4265
|
-
fields["AND"] = this.orArray(
|
|
4266
|
-
fields["OR"] =
|
|
4267
|
-
fields["NOT"] = this.orArray(
|
|
4268
|
-
const baseWhere =
|
|
4573
|
+
fields["$expr"] = import_zod3.z.custom((v) => typeof v === "function").optional();
|
|
4574
|
+
fields["AND"] = this.orArray(import_zod3.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
|
|
4575
|
+
fields["OR"] = import_zod3.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)).array().optional();
|
|
4576
|
+
fields["NOT"] = this.orArray(import_zod3.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
|
|
4577
|
+
const baseWhere = import_zod3.z.strictObject(fields);
|
|
4269
4578
|
let result = baseWhere;
|
|
4270
4579
|
if (unique) {
|
|
4271
4580
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
@@ -4284,9 +4593,55 @@ var InputValidator = class {
|
|
|
4284
4593
|
}
|
|
4285
4594
|
return result;
|
|
4286
4595
|
}
|
|
4596
|
+
makeTypedJsonFilterSchema(type, optional, array) {
|
|
4597
|
+
const typeDef = getTypeDef(this.schema, type);
|
|
4598
|
+
(0, import_common_helpers7.invariant)(typeDef, `Type definition "${type}" not found in schema`);
|
|
4599
|
+
const candidates = [];
|
|
4600
|
+
if (!array) {
|
|
4601
|
+
const fieldSchemas = {};
|
|
4602
|
+
for (const [fieldName, fieldDef] of Object.entries(typeDef.fields)) {
|
|
4603
|
+
if (this.isTypeDefType(fieldDef.type)) {
|
|
4604
|
+
fieldSchemas[fieldName] = this.makeTypedJsonFilterSchema(fieldDef.type, !!fieldDef.optional, !!fieldDef.array).optional();
|
|
4605
|
+
} else {
|
|
4606
|
+
if (fieldDef.array) {
|
|
4607
|
+
fieldSchemas[fieldName] = this.makeArrayFilterSchema(fieldDef.type).optional();
|
|
4608
|
+
} else {
|
|
4609
|
+
const enumDef = getEnum(this.schema, fieldDef.type);
|
|
4610
|
+
if (enumDef) {
|
|
4611
|
+
fieldSchemas[fieldName] = this.makeEnumFilterSchema(enumDef, !!fieldDef.optional, false).optional();
|
|
4612
|
+
} else {
|
|
4613
|
+
fieldSchemas[fieldName] = this.makePrimitiveFilterSchema(fieldDef.type, !!fieldDef.optional, false).optional();
|
|
4614
|
+
}
|
|
4615
|
+
}
|
|
4616
|
+
}
|
|
4617
|
+
}
|
|
4618
|
+
candidates.push(import_zod3.z.strictObject(fieldSchemas));
|
|
4619
|
+
}
|
|
4620
|
+
const recursiveSchema = import_zod3.z.lazy(() => this.makeTypedJsonFilterSchema(type, optional, false)).optional();
|
|
4621
|
+
if (array) {
|
|
4622
|
+
candidates.push(import_zod3.z.strictObject({
|
|
4623
|
+
some: recursiveSchema,
|
|
4624
|
+
every: recursiveSchema,
|
|
4625
|
+
none: recursiveSchema
|
|
4626
|
+
}));
|
|
4627
|
+
} else {
|
|
4628
|
+
candidates.push(import_zod3.z.strictObject({
|
|
4629
|
+
is: recursiveSchema,
|
|
4630
|
+
isNot: recursiveSchema
|
|
4631
|
+
}));
|
|
4632
|
+
}
|
|
4633
|
+
candidates.push(this.makeJsonFilterSchema(optional));
|
|
4634
|
+
if (optional) {
|
|
4635
|
+
candidates.push(import_zod3.z.null());
|
|
4636
|
+
}
|
|
4637
|
+
return import_zod3.z.union(candidates);
|
|
4638
|
+
}
|
|
4639
|
+
isTypeDefType(type) {
|
|
4640
|
+
return this.schema.typeDefs && type in this.schema.typeDefs;
|
|
4641
|
+
}
|
|
4287
4642
|
makeEnumFilterSchema(enumDef, optional, withAggregations) {
|
|
4288
|
-
const baseSchema =
|
|
4289
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () =>
|
|
4643
|
+
const baseSchema = import_zod3.z.enum(Object.keys(enumDef.values));
|
|
4644
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => import_zod3.z.lazy(() => this.makeEnumFilterSchema(enumDef, optional, withAggregations)), [
|
|
4290
4645
|
"equals",
|
|
4291
4646
|
"in",
|
|
4292
4647
|
"notIn",
|
|
@@ -4296,41 +4651,80 @@ var InputValidator = class {
|
|
|
4296
4651
|
"_min",
|
|
4297
4652
|
"_max"
|
|
4298
4653
|
] : void 0);
|
|
4299
|
-
return
|
|
4654
|
+
return import_zod3.z.union([
|
|
4300
4655
|
this.nullableIf(baseSchema, optional),
|
|
4301
|
-
|
|
4656
|
+
import_zod3.z.strictObject(components)
|
|
4302
4657
|
]);
|
|
4303
4658
|
}
|
|
4304
4659
|
makeArrayFilterSchema(type) {
|
|
4305
|
-
return
|
|
4306
|
-
equals: this.
|
|
4307
|
-
has: this.
|
|
4308
|
-
hasEvery: this.
|
|
4309
|
-
hasSome: this.
|
|
4310
|
-
isEmpty:
|
|
4660
|
+
return import_zod3.z.strictObject({
|
|
4661
|
+
equals: this.makeScalarSchema(type).array().optional(),
|
|
4662
|
+
has: this.makeScalarSchema(type).optional(),
|
|
4663
|
+
hasEvery: this.makeScalarSchema(type).array().optional(),
|
|
4664
|
+
hasSome: this.makeScalarSchema(type).array().optional(),
|
|
4665
|
+
isEmpty: import_zod3.z.boolean().optional()
|
|
4311
4666
|
});
|
|
4312
4667
|
}
|
|
4313
4668
|
makePrimitiveFilterSchema(type, optional, withAggregations) {
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
|
|
4669
|
+
return (0, import_ts_pattern13.match)(type).with("String", () => this.makeStringFilterSchema(optional, withAggregations)).with(import_ts_pattern13.P.union("Int", "Float", "Decimal", "BigInt"), (type2) => this.makeNumberFilterSchema(this.makeScalarSchema(type2), optional, withAggregations)).with("Boolean", () => this.makeBooleanFilterSchema(optional, withAggregations)).with("DateTime", () => this.makeDateTimeFilterSchema(optional, withAggregations)).with("Bytes", () => this.makeBytesFilterSchema(optional, withAggregations)).with("Json", () => this.makeJsonFilterSchema(optional)).with("Unsupported", () => import_zod3.z.never()).exhaustive();
|
|
4670
|
+
}
|
|
4671
|
+
makeJsonValueSchema(nullable, forFilter) {
|
|
4672
|
+
const options = [
|
|
4673
|
+
import_zod3.z.string(),
|
|
4674
|
+
import_zod3.z.number(),
|
|
4675
|
+
import_zod3.z.boolean(),
|
|
4676
|
+
import_zod3.z.instanceof(JsonNullClass)
|
|
4677
|
+
];
|
|
4678
|
+
if (forFilter) {
|
|
4679
|
+
options.push(import_zod3.z.instanceof(DbNullClass));
|
|
4680
|
+
} else {
|
|
4681
|
+
if (nullable) {
|
|
4682
|
+
options.push(import_zod3.z.instanceof(DbNullClass));
|
|
4683
|
+
}
|
|
4684
|
+
}
|
|
4685
|
+
if (forFilter) {
|
|
4686
|
+
options.push(import_zod3.z.instanceof(AnyNullClass));
|
|
4687
|
+
}
|
|
4688
|
+
const schema = import_zod3.z.union([
|
|
4689
|
+
...options,
|
|
4690
|
+
import_zod3.z.lazy(() => import_zod3.z.union([
|
|
4691
|
+
this.makeJsonValueSchema(false, false),
|
|
4692
|
+
import_zod3.z.null()
|
|
4693
|
+
]).array()),
|
|
4694
|
+
import_zod3.z.record(import_zod3.z.string(), import_zod3.z.lazy(() => import_zod3.z.union([
|
|
4695
|
+
this.makeJsonValueSchema(false, false),
|
|
4696
|
+
import_zod3.z.null()
|
|
4697
|
+
])))
|
|
4698
|
+
]);
|
|
4699
|
+
return this.nullableIf(schema, nullable);
|
|
4700
|
+
}
|
|
4701
|
+
makeJsonFilterSchema(optional) {
|
|
4702
|
+
const valueSchema = this.makeJsonValueSchema(optional, true);
|
|
4703
|
+
return import_zod3.z.strictObject({
|
|
4704
|
+
path: import_zod3.z.string().optional(),
|
|
4705
|
+
equals: valueSchema.optional(),
|
|
4706
|
+
not: valueSchema.optional(),
|
|
4707
|
+
string_contains: import_zod3.z.string().optional(),
|
|
4708
|
+
string_starts_with: import_zod3.z.string().optional(),
|
|
4709
|
+
string_ends_with: import_zod3.z.string().optional(),
|
|
4710
|
+
mode: this.makeStringModeSchema().optional(),
|
|
4711
|
+
array_contains: valueSchema.optional(),
|
|
4712
|
+
array_starts_with: valueSchema.optional(),
|
|
4713
|
+
array_ends_with: valueSchema.optional()
|
|
4714
|
+
});
|
|
4321
4715
|
}
|
|
4322
4716
|
makeDateTimeFilterSchema(optional, withAggregations) {
|
|
4323
|
-
return this.makeCommonPrimitiveFilterSchema(
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
]), optional, () =>
|
|
4717
|
+
return this.makeCommonPrimitiveFilterSchema(import_zod3.z.union([
|
|
4718
|
+
import_zod3.z.iso.datetime(),
|
|
4719
|
+
import_zod3.z.date()
|
|
4720
|
+
]), optional, () => import_zod3.z.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations)), withAggregations ? [
|
|
4327
4721
|
"_count",
|
|
4328
4722
|
"_min",
|
|
4329
4723
|
"_max"
|
|
4330
4724
|
] : void 0);
|
|
4331
4725
|
}
|
|
4332
4726
|
makeBooleanFilterSchema(optional, withAggregations) {
|
|
4333
|
-
const components = this.makeCommonPrimitiveFilterComponents(
|
|
4727
|
+
const components = this.makeCommonPrimitiveFilterComponents(import_zod3.z.boolean(), optional, () => import_zod3.z.lazy(() => this.makeBooleanFilterSchema(optional, withAggregations)), [
|
|
4334
4728
|
"equals",
|
|
4335
4729
|
"not"
|
|
4336
4730
|
], withAggregations ? [
|
|
@@ -4338,14 +4732,14 @@ var InputValidator = class {
|
|
|
4338
4732
|
"_min",
|
|
4339
4733
|
"_max"
|
|
4340
4734
|
] : void 0);
|
|
4341
|
-
return
|
|
4342
|
-
this.nullableIf(
|
|
4343
|
-
|
|
4735
|
+
return import_zod3.z.union([
|
|
4736
|
+
this.nullableIf(import_zod3.z.boolean(), optional),
|
|
4737
|
+
import_zod3.z.strictObject(components)
|
|
4344
4738
|
]);
|
|
4345
4739
|
}
|
|
4346
4740
|
makeBytesFilterSchema(optional, withAggregations) {
|
|
4347
|
-
const baseSchema =
|
|
4348
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () =>
|
|
4741
|
+
const baseSchema = import_zod3.z.instanceof(Uint8Array);
|
|
4742
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => import_zod3.z.instanceof(Uint8Array), [
|
|
4349
4743
|
"equals",
|
|
4350
4744
|
"in",
|
|
4351
4745
|
"notIn",
|
|
@@ -4355,9 +4749,9 @@ var InputValidator = class {
|
|
|
4355
4749
|
"_min",
|
|
4356
4750
|
"_max"
|
|
4357
4751
|
] : void 0);
|
|
4358
|
-
return
|
|
4752
|
+
return import_zod3.z.union([
|
|
4359
4753
|
this.nullableIf(baseSchema, optional),
|
|
4360
|
-
|
|
4754
|
+
import_zod3.z.strictObject(components)
|
|
4361
4755
|
]);
|
|
4362
4756
|
}
|
|
4363
4757
|
makeCommonPrimitiveFilterComponents(baseSchema, optional, makeThis, supportedOperators = void 0, withAggregations = void 0) {
|
|
@@ -4373,7 +4767,7 @@ var InputValidator = class {
|
|
|
4373
4767
|
gte: baseSchema.optional(),
|
|
4374
4768
|
not: makeThis().optional(),
|
|
4375
4769
|
...withAggregations?.includes("_count") ? {
|
|
4376
|
-
_count: this.makeNumberFilterSchema(
|
|
4770
|
+
_count: this.makeNumberFilterSchema(import_zod3.z.number().int(), false, false).optional()
|
|
4377
4771
|
} : {},
|
|
4378
4772
|
...withAggregations?.includes("_avg") ? {
|
|
4379
4773
|
_avg: commonAggSchema()
|
|
@@ -4398,13 +4792,13 @@ var InputValidator = class {
|
|
|
4398
4792
|
return result;
|
|
4399
4793
|
}
|
|
4400
4794
|
makeCommonPrimitiveFilterSchema(baseSchema, optional, makeThis, withAggregations = void 0) {
|
|
4401
|
-
return
|
|
4795
|
+
return import_zod3.z.union([
|
|
4402
4796
|
this.nullableIf(baseSchema, optional),
|
|
4403
|
-
|
|
4797
|
+
import_zod3.z.strictObject(this.makeCommonPrimitiveFilterComponents(baseSchema, optional, makeThis, void 0, withAggregations))
|
|
4404
4798
|
]);
|
|
4405
4799
|
}
|
|
4406
4800
|
makeNumberFilterSchema(baseSchema, optional, withAggregations) {
|
|
4407
|
-
return this.makeCommonPrimitiveFilterSchema(baseSchema, optional, () =>
|
|
4801
|
+
return this.makeCommonPrimitiveFilterSchema(baseSchema, optional, () => import_zod3.z.lazy(() => this.makeNumberFilterSchema(baseSchema, optional, withAggregations)), withAggregations ? [
|
|
4408
4802
|
"_count",
|
|
4409
4803
|
"_avg",
|
|
4410
4804
|
"_sum",
|
|
@@ -4413,17 +4807,17 @@ var InputValidator = class {
|
|
|
4413
4807
|
] : void 0);
|
|
4414
4808
|
}
|
|
4415
4809
|
makeStringFilterSchema(optional, withAggregations) {
|
|
4416
|
-
return
|
|
4417
|
-
this.nullableIf(
|
|
4418
|
-
|
|
4419
|
-
...this.makeCommonPrimitiveFilterComponents(
|
|
4810
|
+
return import_zod3.z.union([
|
|
4811
|
+
this.nullableIf(import_zod3.z.string(), optional),
|
|
4812
|
+
import_zod3.z.strictObject({
|
|
4813
|
+
...this.makeCommonPrimitiveFilterComponents(import_zod3.z.string(), optional, () => import_zod3.z.lazy(() => this.makeStringFilterSchema(optional, withAggregations)), void 0, withAggregations ? [
|
|
4420
4814
|
"_count",
|
|
4421
4815
|
"_min",
|
|
4422
4816
|
"_max"
|
|
4423
4817
|
] : void 0),
|
|
4424
|
-
startsWith:
|
|
4425
|
-
endsWith:
|
|
4426
|
-
contains:
|
|
4818
|
+
startsWith: import_zod3.z.string().optional(),
|
|
4819
|
+
endsWith: import_zod3.z.string().optional(),
|
|
4820
|
+
contains: import_zod3.z.string().optional(),
|
|
4427
4821
|
...this.providerSupportsCaseSensitivity ? {
|
|
4428
4822
|
mode: this.makeStringModeSchema().optional()
|
|
4429
4823
|
} : {}
|
|
@@ -4431,9 +4825,9 @@ var InputValidator = class {
|
|
|
4431
4825
|
]);
|
|
4432
4826
|
}
|
|
4433
4827
|
makeStringModeSchema() {
|
|
4434
|
-
return
|
|
4435
|
-
|
|
4436
|
-
|
|
4828
|
+
return import_zod3.z.union([
|
|
4829
|
+
import_zod3.z.literal("default"),
|
|
4830
|
+
import_zod3.z.literal("insensitive")
|
|
4437
4831
|
]);
|
|
4438
4832
|
}
|
|
4439
4833
|
makeSelectSchema(model) {
|
|
@@ -4444,26 +4838,26 @@ var InputValidator = class {
|
|
|
4444
4838
|
if (fieldDef.relation) {
|
|
4445
4839
|
fields[field] = this.makeRelationSelectIncludeSchema(fieldDef).optional();
|
|
4446
4840
|
} else {
|
|
4447
|
-
fields[field] =
|
|
4841
|
+
fields[field] = import_zod3.z.boolean().optional();
|
|
4448
4842
|
}
|
|
4449
4843
|
}
|
|
4450
4844
|
const _countSchema = this.makeCountSelectionSchema(modelDef);
|
|
4451
4845
|
if (_countSchema) {
|
|
4452
4846
|
fields["_count"] = _countSchema;
|
|
4453
4847
|
}
|
|
4454
|
-
return
|
|
4848
|
+
return import_zod3.z.strictObject(fields);
|
|
4455
4849
|
}
|
|
4456
4850
|
makeCountSelectionSchema(modelDef) {
|
|
4457
4851
|
const toManyRelations = Object.values(modelDef.fields).filter((def) => def.relation && def.array);
|
|
4458
4852
|
if (toManyRelations.length > 0) {
|
|
4459
|
-
return
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
select:
|
|
4853
|
+
return import_zod3.z.union([
|
|
4854
|
+
import_zod3.z.literal(true),
|
|
4855
|
+
import_zod3.z.strictObject({
|
|
4856
|
+
select: import_zod3.z.strictObject(toManyRelations.reduce((acc, fieldDef) => ({
|
|
4463
4857
|
...acc,
|
|
4464
|
-
[fieldDef.name]:
|
|
4465
|
-
|
|
4466
|
-
|
|
4858
|
+
[fieldDef.name]: import_zod3.z.union([
|
|
4859
|
+
import_zod3.z.boolean(),
|
|
4860
|
+
import_zod3.z.strictObject({
|
|
4467
4861
|
where: this.makeWhereSchema(fieldDef.type, false, false)
|
|
4468
4862
|
})
|
|
4469
4863
|
]).optional()
|
|
@@ -4475,17 +4869,17 @@ var InputValidator = class {
|
|
|
4475
4869
|
}
|
|
4476
4870
|
}
|
|
4477
4871
|
makeRelationSelectIncludeSchema(fieldDef) {
|
|
4478
|
-
let objSchema =
|
|
4872
|
+
let objSchema = import_zod3.z.strictObject({
|
|
4479
4873
|
...fieldDef.array || fieldDef.optional ? {
|
|
4480
4874
|
// to-many relations and optional to-one relations are filterable
|
|
4481
|
-
where:
|
|
4875
|
+
where: import_zod3.z.lazy(() => this.makeWhereSchema(fieldDef.type, false)).optional()
|
|
4482
4876
|
} : {},
|
|
4483
|
-
select:
|
|
4484
|
-
include:
|
|
4485
|
-
omit:
|
|
4877
|
+
select: import_zod3.z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional().nullable(),
|
|
4878
|
+
include: import_zod3.z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional().nullable(),
|
|
4879
|
+
omit: import_zod3.z.lazy(() => this.makeOmitSchema(fieldDef.type)).optional().nullable(),
|
|
4486
4880
|
...fieldDef.array ? {
|
|
4487
4881
|
// to-many relations can be ordered, skipped, taken, and cursor-located
|
|
4488
|
-
orderBy:
|
|
4882
|
+
orderBy: import_zod3.z.lazy(() => this.orArray(this.makeOrderBySchema(fieldDef.type, true, false), true)).optional(),
|
|
4489
4883
|
skip: this.makeSkipSchema().optional(),
|
|
4490
4884
|
take: this.makeTakeSchema().optional(),
|
|
4491
4885
|
cursor: this.makeCursorSchema(fieldDef.type).optional(),
|
|
@@ -4494,8 +4888,8 @@ var InputValidator = class {
|
|
|
4494
4888
|
});
|
|
4495
4889
|
objSchema = this.refineForSelectIncludeMutuallyExclusive(objSchema);
|
|
4496
4890
|
objSchema = this.refineForSelectOmitMutuallyExclusive(objSchema);
|
|
4497
|
-
return
|
|
4498
|
-
|
|
4891
|
+
return import_zod3.z.union([
|
|
4892
|
+
import_zod3.z.boolean(),
|
|
4499
4893
|
objSchema
|
|
4500
4894
|
]);
|
|
4501
4895
|
}
|
|
@@ -4506,13 +4900,13 @@ var InputValidator = class {
|
|
|
4506
4900
|
const fieldDef = requireField(this.schema, model, field);
|
|
4507
4901
|
if (!fieldDef.relation) {
|
|
4508
4902
|
if (this.options.allowQueryTimeOmitOverride !== false) {
|
|
4509
|
-
fields[field] =
|
|
4903
|
+
fields[field] = import_zod3.z.boolean().optional();
|
|
4510
4904
|
} else {
|
|
4511
|
-
fields[field] =
|
|
4905
|
+
fields[field] = import_zod3.z.literal(true).optional();
|
|
4512
4906
|
}
|
|
4513
4907
|
}
|
|
4514
4908
|
}
|
|
4515
|
-
return
|
|
4909
|
+
return import_zod3.z.strictObject(fields);
|
|
4516
4910
|
}
|
|
4517
4911
|
makeIncludeSchema(model) {
|
|
4518
4912
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -4527,20 +4921,20 @@ var InputValidator = class {
|
|
|
4527
4921
|
if (_countSchema) {
|
|
4528
4922
|
fields["_count"] = _countSchema;
|
|
4529
4923
|
}
|
|
4530
|
-
return
|
|
4924
|
+
return import_zod3.z.strictObject(fields);
|
|
4531
4925
|
}
|
|
4532
4926
|
makeOrderBySchema(model, withRelation, WithAggregation) {
|
|
4533
4927
|
const modelDef = requireModel(this.schema, model);
|
|
4534
4928
|
const fields = {};
|
|
4535
|
-
const sort =
|
|
4536
|
-
|
|
4537
|
-
|
|
4929
|
+
const sort = import_zod3.z.union([
|
|
4930
|
+
import_zod3.z.literal("asc"),
|
|
4931
|
+
import_zod3.z.literal("desc")
|
|
4538
4932
|
]);
|
|
4539
4933
|
for (const field of Object.keys(modelDef.fields)) {
|
|
4540
4934
|
const fieldDef = requireField(this.schema, model, field);
|
|
4541
4935
|
if (fieldDef.relation) {
|
|
4542
4936
|
if (withRelation) {
|
|
4543
|
-
fields[field] =
|
|
4937
|
+
fields[field] = import_zod3.z.lazy(() => {
|
|
4544
4938
|
let relationOrderBy = this.makeOrderBySchema(fieldDef.type, withRelation, WithAggregation);
|
|
4545
4939
|
if (fieldDef.array) {
|
|
4546
4940
|
relationOrderBy = relationOrderBy.extend({
|
|
@@ -4552,13 +4946,13 @@ var InputValidator = class {
|
|
|
4552
4946
|
}
|
|
4553
4947
|
} else {
|
|
4554
4948
|
if (fieldDef.optional) {
|
|
4555
|
-
fields[field] =
|
|
4949
|
+
fields[field] = import_zod3.z.union([
|
|
4556
4950
|
sort,
|
|
4557
|
-
|
|
4951
|
+
import_zod3.z.strictObject({
|
|
4558
4952
|
sort,
|
|
4559
|
-
nulls:
|
|
4560
|
-
|
|
4561
|
-
|
|
4953
|
+
nulls: import_zod3.z.union([
|
|
4954
|
+
import_zod3.z.literal("first"),
|
|
4955
|
+
import_zod3.z.literal("last")
|
|
4562
4956
|
])
|
|
4563
4957
|
})
|
|
4564
4958
|
]).optional();
|
|
@@ -4576,15 +4970,15 @@ var InputValidator = class {
|
|
|
4576
4970
|
"_max"
|
|
4577
4971
|
];
|
|
4578
4972
|
for (const agg of aggregationFields) {
|
|
4579
|
-
fields[agg] =
|
|
4973
|
+
fields[agg] = import_zod3.z.lazy(() => this.makeOrderBySchema(model, true, false).optional());
|
|
4580
4974
|
}
|
|
4581
4975
|
}
|
|
4582
|
-
return
|
|
4976
|
+
return import_zod3.z.strictObject(fields);
|
|
4583
4977
|
}
|
|
4584
4978
|
makeDistinctSchema(model) {
|
|
4585
4979
|
const modelDef = requireModel(this.schema, model);
|
|
4586
4980
|
const nonRelationFields = Object.keys(modelDef.fields).filter((field) => !modelDef.fields[field]?.relation);
|
|
4587
|
-
return this.orArray(
|
|
4981
|
+
return this.orArray(import_zod3.z.enum(nonRelationFields), true);
|
|
4588
4982
|
}
|
|
4589
4983
|
makeCursorSchema(model) {
|
|
4590
4984
|
return this.makeWhereSchema(model, true, true).optional();
|
|
@@ -4593,7 +4987,7 @@ var InputValidator = class {
|
|
|
4593
4987
|
// #region Create
|
|
4594
4988
|
makeCreateSchema(model) {
|
|
4595
4989
|
const dataSchema = this.makeCreateDataSchema(model, false);
|
|
4596
|
-
let schema =
|
|
4990
|
+
let schema = import_zod3.z.strictObject({
|
|
4597
4991
|
data: dataSchema,
|
|
4598
4992
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
4599
4993
|
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
@@ -4643,7 +5037,7 @@ var InputValidator = class {
|
|
|
4643
5037
|
excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
4644
5038
|
}
|
|
4645
5039
|
}
|
|
4646
|
-
let fieldSchema =
|
|
5040
|
+
let fieldSchema = import_zod3.z.lazy(() => this.makeRelationManipulationSchema(fieldDef, excludeFields, "create"));
|
|
4647
5041
|
if (fieldDef.optional || fieldDef.array) {
|
|
4648
5042
|
fieldSchema = fieldSchema.optional();
|
|
4649
5043
|
} else {
|
|
@@ -4666,12 +5060,12 @@ var InputValidator = class {
|
|
|
4666
5060
|
uncheckedVariantFields[field] = fieldSchema;
|
|
4667
5061
|
}
|
|
4668
5062
|
} else {
|
|
4669
|
-
let fieldSchema = this.
|
|
5063
|
+
let fieldSchema = this.makeScalarSchema(fieldDef.type, fieldDef.attributes);
|
|
4670
5064
|
if (fieldDef.array) {
|
|
4671
5065
|
fieldSchema = addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
4672
|
-
fieldSchema =
|
|
5066
|
+
fieldSchema = import_zod3.z.union([
|
|
4673
5067
|
fieldSchema,
|
|
4674
|
-
|
|
5068
|
+
import_zod3.z.strictObject({
|
|
4675
5069
|
set: fieldSchema
|
|
4676
5070
|
})
|
|
4677
5071
|
]).optional();
|
|
@@ -4680,7 +5074,14 @@ var InputValidator = class {
|
|
|
4680
5074
|
fieldSchema = fieldSchema.optional();
|
|
4681
5075
|
}
|
|
4682
5076
|
if (fieldDef.optional) {
|
|
4683
|
-
|
|
5077
|
+
if (fieldDef.type === "Json") {
|
|
5078
|
+
fieldSchema = import_zod3.z.union([
|
|
5079
|
+
fieldSchema,
|
|
5080
|
+
import_zod3.z.instanceof(DbNullClass)
|
|
5081
|
+
]);
|
|
5082
|
+
} else {
|
|
5083
|
+
fieldSchema = fieldSchema.nullable();
|
|
5084
|
+
}
|
|
4684
5085
|
}
|
|
4685
5086
|
uncheckedVariantFields[field] = fieldSchema;
|
|
4686
5087
|
if (!fieldDef.foreignKeyFor) {
|
|
@@ -4688,19 +5089,19 @@ var InputValidator = class {
|
|
|
4688
5089
|
}
|
|
4689
5090
|
}
|
|
4690
5091
|
});
|
|
4691
|
-
const uncheckedCreateSchema = this.extraValidationsEnabled ? addCustomValidation(
|
|
4692
|
-
const checkedCreateSchema = this.extraValidationsEnabled ? addCustomValidation(
|
|
5092
|
+
const uncheckedCreateSchema = this.extraValidationsEnabled ? addCustomValidation(import_zod3.z.strictObject(uncheckedVariantFields), modelDef.attributes) : import_zod3.z.strictObject(uncheckedVariantFields);
|
|
5093
|
+
const checkedCreateSchema = this.extraValidationsEnabled ? addCustomValidation(import_zod3.z.strictObject(checkedVariantFields), modelDef.attributes) : import_zod3.z.strictObject(checkedVariantFields);
|
|
4693
5094
|
if (!hasRelation) {
|
|
4694
5095
|
return this.orArray(uncheckedCreateSchema, canBeArray);
|
|
4695
5096
|
} else {
|
|
4696
|
-
return
|
|
5097
|
+
return import_zod3.z.union([
|
|
4697
5098
|
uncheckedCreateSchema,
|
|
4698
5099
|
checkedCreateSchema,
|
|
4699
5100
|
...canBeArray ? [
|
|
4700
|
-
|
|
5101
|
+
import_zod3.z.array(uncheckedCreateSchema)
|
|
4701
5102
|
] : [],
|
|
4702
5103
|
...canBeArray ? [
|
|
4703
|
-
|
|
5104
|
+
import_zod3.z.array(checkedCreateSchema)
|
|
4704
5105
|
] : []
|
|
4705
5106
|
]);
|
|
4706
5107
|
}
|
|
@@ -4728,12 +5129,12 @@ var InputValidator = class {
|
|
|
4728
5129
|
fields["disconnect"] = this.makeDisconnectDataSchema(fieldType, array).optional();
|
|
4729
5130
|
fields["delete"] = this.makeDeleteRelationDataSchema(fieldType, array, true).optional();
|
|
4730
5131
|
}
|
|
4731
|
-
fields["update"] = array ? this.orArray(
|
|
4732
|
-
where: this.makeWhereSchema(fieldType, true)
|
|
5132
|
+
fields["update"] = array ? this.orArray(import_zod3.z.strictObject({
|
|
5133
|
+
where: this.makeWhereSchema(fieldType, true),
|
|
4733
5134
|
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
4734
|
-
}), true).optional() :
|
|
4735
|
-
|
|
4736
|
-
where: this.makeWhereSchema(fieldType,
|
|
5135
|
+
}), true).optional() : import_zod3.z.union([
|
|
5136
|
+
import_zod3.z.strictObject({
|
|
5137
|
+
where: this.makeWhereSchema(fieldType, false).optional(),
|
|
4737
5138
|
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
4738
5139
|
}),
|
|
4739
5140
|
this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
@@ -4742,21 +5143,21 @@ var InputValidator = class {
|
|
|
4742
5143
|
if (!fieldDef.array) {
|
|
4743
5144
|
upsertWhere = upsertWhere.optional();
|
|
4744
5145
|
}
|
|
4745
|
-
fields["upsert"] = this.orArray(
|
|
5146
|
+
fields["upsert"] = this.orArray(import_zod3.z.strictObject({
|
|
4746
5147
|
where: upsertWhere,
|
|
4747
5148
|
create: this.makeCreateDataSchema(fieldType, false, withoutFields),
|
|
4748
5149
|
update: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
4749
5150
|
}), true).optional();
|
|
4750
5151
|
if (array) {
|
|
4751
5152
|
fields["set"] = this.makeSetDataSchema(fieldType, true).optional();
|
|
4752
|
-
fields["updateMany"] = this.orArray(
|
|
5153
|
+
fields["updateMany"] = this.orArray(import_zod3.z.strictObject({
|
|
4753
5154
|
where: this.makeWhereSchema(fieldType, false, true),
|
|
4754
5155
|
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
4755
5156
|
}), true).optional();
|
|
4756
5157
|
fields["deleteMany"] = this.makeDeleteRelationDataSchema(fieldType, true, false).optional();
|
|
4757
5158
|
}
|
|
4758
5159
|
}
|
|
4759
|
-
return
|
|
5160
|
+
return import_zod3.z.strictObject(fields);
|
|
4760
5161
|
}
|
|
4761
5162
|
makeSetDataSchema(model, canBeArray) {
|
|
4762
5163
|
return this.orArray(this.makeWhereSchema(model, true), canBeArray);
|
|
@@ -4768,36 +5169,36 @@ var InputValidator = class {
|
|
|
4768
5169
|
if (canBeArray) {
|
|
4769
5170
|
return this.orArray(this.makeWhereSchema(model, true), canBeArray);
|
|
4770
5171
|
} else {
|
|
4771
|
-
return
|
|
4772
|
-
|
|
5172
|
+
return import_zod3.z.union([
|
|
5173
|
+
import_zod3.z.boolean(),
|
|
4773
5174
|
this.makeWhereSchema(model, false)
|
|
4774
5175
|
]);
|
|
4775
5176
|
}
|
|
4776
5177
|
}
|
|
4777
5178
|
makeDeleteRelationDataSchema(model, toManyRelation, uniqueFilter) {
|
|
4778
|
-
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter), true) :
|
|
4779
|
-
|
|
5179
|
+
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter), true) : import_zod3.z.union([
|
|
5180
|
+
import_zod3.z.boolean(),
|
|
4780
5181
|
this.makeWhereSchema(model, uniqueFilter)
|
|
4781
5182
|
]);
|
|
4782
5183
|
}
|
|
4783
5184
|
makeConnectOrCreateDataSchema(model, canBeArray, withoutFields) {
|
|
4784
5185
|
const whereSchema = this.makeWhereSchema(model, true);
|
|
4785
5186
|
const createSchema = this.makeCreateDataSchema(model, false, withoutFields);
|
|
4786
|
-
return this.orArray(
|
|
5187
|
+
return this.orArray(import_zod3.z.strictObject({
|
|
4787
5188
|
where: whereSchema,
|
|
4788
5189
|
create: createSchema
|
|
4789
5190
|
}), canBeArray);
|
|
4790
5191
|
}
|
|
4791
5192
|
makeCreateManyDataSchema(model, withoutFields) {
|
|
4792
|
-
return
|
|
5193
|
+
return import_zod3.z.strictObject({
|
|
4793
5194
|
data: this.makeCreateDataSchema(model, true, withoutFields, true),
|
|
4794
|
-
skipDuplicates:
|
|
5195
|
+
skipDuplicates: import_zod3.z.boolean().optional()
|
|
4795
5196
|
});
|
|
4796
5197
|
}
|
|
4797
5198
|
// #endregion
|
|
4798
5199
|
// #region Update
|
|
4799
5200
|
makeUpdateSchema(model) {
|
|
4800
|
-
let schema =
|
|
5201
|
+
let schema = import_zod3.z.strictObject({
|
|
4801
5202
|
where: this.makeWhereSchema(model, true),
|
|
4802
5203
|
data: this.makeUpdateDataSchema(model),
|
|
4803
5204
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
@@ -4809,10 +5210,10 @@ var InputValidator = class {
|
|
|
4809
5210
|
return schema;
|
|
4810
5211
|
}
|
|
4811
5212
|
makeUpdateManySchema(model) {
|
|
4812
|
-
return
|
|
5213
|
+
return import_zod3.z.strictObject({
|
|
4813
5214
|
where: this.makeWhereSchema(model, false).optional(),
|
|
4814
5215
|
data: this.makeUpdateDataSchema(model, [], true),
|
|
4815
|
-
limit:
|
|
5216
|
+
limit: import_zod3.z.number().int().nonnegative().optional()
|
|
4816
5217
|
});
|
|
4817
5218
|
}
|
|
4818
5219
|
makeUpdateManyAndReturnSchema(model) {
|
|
@@ -4825,7 +5226,7 @@ var InputValidator = class {
|
|
|
4825
5226
|
return schema;
|
|
4826
5227
|
}
|
|
4827
5228
|
makeUpsertSchema(model) {
|
|
4828
|
-
let schema =
|
|
5229
|
+
let schema = import_zod3.z.strictObject({
|
|
4829
5230
|
where: this.makeWhereSchema(model, true),
|
|
4830
5231
|
create: this.makeCreateDataSchema(model, false),
|
|
4831
5232
|
update: this.makeUpdateDataSchema(model),
|
|
@@ -4860,7 +5261,7 @@ var InputValidator = class {
|
|
|
4860
5261
|
excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
4861
5262
|
}
|
|
4862
5263
|
}
|
|
4863
|
-
let fieldSchema =
|
|
5264
|
+
let fieldSchema = import_zod3.z.lazy(() => this.makeRelationManipulationSchema(fieldDef, excludeFields, "update")).optional();
|
|
4864
5265
|
if (fieldDef.optional && !fieldDef.array) {
|
|
4865
5266
|
fieldSchema = fieldSchema.nullable();
|
|
4866
5267
|
}
|
|
@@ -4869,26 +5270,26 @@ var InputValidator = class {
|
|
|
4869
5270
|
uncheckedVariantFields[field] = fieldSchema;
|
|
4870
5271
|
}
|
|
4871
5272
|
} else {
|
|
4872
|
-
let fieldSchema = this.
|
|
5273
|
+
let fieldSchema = this.makeScalarSchema(fieldDef.type, fieldDef.attributes);
|
|
4873
5274
|
if (this.isNumericField(fieldDef)) {
|
|
4874
|
-
fieldSchema =
|
|
5275
|
+
fieldSchema = import_zod3.z.union([
|
|
4875
5276
|
fieldSchema,
|
|
4876
|
-
|
|
4877
|
-
set: this.nullableIf(
|
|
4878
|
-
increment:
|
|
4879
|
-
decrement:
|
|
4880
|
-
multiply:
|
|
4881
|
-
divide:
|
|
5277
|
+
import_zod3.z.object({
|
|
5278
|
+
set: this.nullableIf(import_zod3.z.number().optional(), !!fieldDef.optional).optional(),
|
|
5279
|
+
increment: import_zod3.z.number().optional(),
|
|
5280
|
+
decrement: import_zod3.z.number().optional(),
|
|
5281
|
+
multiply: import_zod3.z.number().optional(),
|
|
5282
|
+
divide: import_zod3.z.number().optional()
|
|
4882
5283
|
}).refine((v) => Object.keys(v).length === 1, 'Only one of "set", "increment", "decrement", "multiply", or "divide" can be provided')
|
|
4883
5284
|
]);
|
|
4884
5285
|
}
|
|
4885
5286
|
if (fieldDef.array) {
|
|
4886
5287
|
const arraySchema = addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
4887
|
-
fieldSchema =
|
|
5288
|
+
fieldSchema = import_zod3.z.union([
|
|
4888
5289
|
arraySchema,
|
|
4889
|
-
|
|
5290
|
+
import_zod3.z.object({
|
|
4890
5291
|
set: arraySchema.optional(),
|
|
4891
|
-
push:
|
|
5292
|
+
push: import_zod3.z.union([
|
|
4892
5293
|
fieldSchema,
|
|
4893
5294
|
fieldSchema.array()
|
|
4894
5295
|
]).optional()
|
|
@@ -4896,7 +5297,14 @@ var InputValidator = class {
|
|
|
4896
5297
|
]);
|
|
4897
5298
|
}
|
|
4898
5299
|
if (fieldDef.optional) {
|
|
4899
|
-
|
|
5300
|
+
if (fieldDef.type === "Json") {
|
|
5301
|
+
fieldSchema = import_zod3.z.union([
|
|
5302
|
+
fieldSchema,
|
|
5303
|
+
import_zod3.z.instanceof(DbNullClass)
|
|
5304
|
+
]);
|
|
5305
|
+
} else {
|
|
5306
|
+
fieldSchema = fieldSchema.nullable();
|
|
5307
|
+
}
|
|
4900
5308
|
}
|
|
4901
5309
|
fieldSchema = fieldSchema.optional();
|
|
4902
5310
|
uncheckedVariantFields[field] = fieldSchema;
|
|
@@ -4905,12 +5313,12 @@ var InputValidator = class {
|
|
|
4905
5313
|
}
|
|
4906
5314
|
}
|
|
4907
5315
|
});
|
|
4908
|
-
const uncheckedUpdateSchema = this.extraValidationsEnabled ? addCustomValidation(
|
|
4909
|
-
const checkedUpdateSchema = this.extraValidationsEnabled ? addCustomValidation(
|
|
5316
|
+
const uncheckedUpdateSchema = this.extraValidationsEnabled ? addCustomValidation(import_zod3.z.strictObject(uncheckedVariantFields), modelDef.attributes) : import_zod3.z.strictObject(uncheckedVariantFields);
|
|
5317
|
+
const checkedUpdateSchema = this.extraValidationsEnabled ? addCustomValidation(import_zod3.z.strictObject(checkedVariantFields), modelDef.attributes) : import_zod3.z.strictObject(checkedVariantFields);
|
|
4910
5318
|
if (!hasRelation) {
|
|
4911
5319
|
return uncheckedUpdateSchema;
|
|
4912
5320
|
} else {
|
|
4913
|
-
return
|
|
5321
|
+
return import_zod3.z.union([
|
|
4914
5322
|
uncheckedUpdateSchema,
|
|
4915
5323
|
checkedUpdateSchema
|
|
4916
5324
|
]);
|
|
@@ -4919,7 +5327,7 @@ var InputValidator = class {
|
|
|
4919
5327
|
// #endregion
|
|
4920
5328
|
// #region Delete
|
|
4921
5329
|
makeDeleteSchema(model) {
|
|
4922
|
-
let schema =
|
|
5330
|
+
let schema = import_zod3.z.strictObject({
|
|
4923
5331
|
where: this.makeWhereSchema(model, true),
|
|
4924
5332
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
4925
5333
|
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
@@ -4930,15 +5338,15 @@ var InputValidator = class {
|
|
|
4930
5338
|
return schema;
|
|
4931
5339
|
}
|
|
4932
5340
|
makeDeleteManySchema(model) {
|
|
4933
|
-
return
|
|
5341
|
+
return import_zod3.z.object({
|
|
4934
5342
|
where: this.makeWhereSchema(model, false).optional(),
|
|
4935
|
-
limit:
|
|
5343
|
+
limit: import_zod3.z.number().int().nonnegative().optional()
|
|
4936
5344
|
}).optional();
|
|
4937
5345
|
}
|
|
4938
5346
|
// #endregion
|
|
4939
5347
|
// #region Count
|
|
4940
5348
|
makeCountSchema(model) {
|
|
4941
|
-
return
|
|
5349
|
+
return import_zod3.z.object({
|
|
4942
5350
|
where: this.makeWhereSchema(model, false).optional(),
|
|
4943
5351
|
skip: this.makeSkipSchema().optional(),
|
|
4944
5352
|
take: this.makeTakeSchema().optional(),
|
|
@@ -4948,12 +5356,12 @@ var InputValidator = class {
|
|
|
4948
5356
|
}
|
|
4949
5357
|
makeCountAggregateInputSchema(model) {
|
|
4950
5358
|
const modelDef = requireModel(this.schema, model);
|
|
4951
|
-
return
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
|
-
_all:
|
|
5359
|
+
return import_zod3.z.union([
|
|
5360
|
+
import_zod3.z.literal(true),
|
|
5361
|
+
import_zod3.z.strictObject({
|
|
5362
|
+
_all: import_zod3.z.literal(true).optional(),
|
|
4955
5363
|
...Object.keys(modelDef.fields).reduce((acc, field) => {
|
|
4956
|
-
acc[field] =
|
|
5364
|
+
acc[field] = import_zod3.z.literal(true).optional();
|
|
4957
5365
|
return acc;
|
|
4958
5366
|
}, {})
|
|
4959
5367
|
})
|
|
@@ -4962,7 +5370,7 @@ var InputValidator = class {
|
|
|
4962
5370
|
// #endregion
|
|
4963
5371
|
// #region Aggregate
|
|
4964
5372
|
makeAggregateSchema(model) {
|
|
4965
|
-
return
|
|
5373
|
+
return import_zod3.z.object({
|
|
4966
5374
|
where: this.makeWhereSchema(model, false).optional(),
|
|
4967
5375
|
skip: this.makeSkipSchema().optional(),
|
|
4968
5376
|
take: this.makeTakeSchema().optional(),
|
|
@@ -4976,20 +5384,20 @@ var InputValidator = class {
|
|
|
4976
5384
|
}
|
|
4977
5385
|
makeSumAvgInputSchema(model) {
|
|
4978
5386
|
const modelDef = requireModel(this.schema, model);
|
|
4979
|
-
return
|
|
5387
|
+
return import_zod3.z.strictObject(Object.keys(modelDef.fields).reduce((acc, field) => {
|
|
4980
5388
|
const fieldDef = requireField(this.schema, model, field);
|
|
4981
5389
|
if (this.isNumericField(fieldDef)) {
|
|
4982
|
-
acc[field] =
|
|
5390
|
+
acc[field] = import_zod3.z.literal(true).optional();
|
|
4983
5391
|
}
|
|
4984
5392
|
return acc;
|
|
4985
5393
|
}, {}));
|
|
4986
5394
|
}
|
|
4987
5395
|
makeMinMaxInputSchema(model) {
|
|
4988
5396
|
const modelDef = requireModel(this.schema, model);
|
|
4989
|
-
return
|
|
5397
|
+
return import_zod3.z.strictObject(Object.keys(modelDef.fields).reduce((acc, field) => {
|
|
4990
5398
|
const fieldDef = requireField(this.schema, model, field);
|
|
4991
5399
|
if (!fieldDef.relation && !fieldDef.array) {
|
|
4992
|
-
acc[field] =
|
|
5400
|
+
acc[field] = import_zod3.z.literal(true).optional();
|
|
4993
5401
|
}
|
|
4994
5402
|
return acc;
|
|
4995
5403
|
}, {}));
|
|
@@ -4997,8 +5405,8 @@ var InputValidator = class {
|
|
|
4997
5405
|
makeGroupBySchema(model) {
|
|
4998
5406
|
const modelDef = requireModel(this.schema, model);
|
|
4999
5407
|
const nonRelationFields = Object.keys(modelDef.fields).filter((field) => !modelDef.fields[field]?.relation);
|
|
5000
|
-
const bySchema = nonRelationFields.length > 0 ? this.orArray(
|
|
5001
|
-
let schema =
|
|
5408
|
+
const bySchema = nonRelationFields.length > 0 ? this.orArray(import_zod3.z.enum(nonRelationFields), true) : import_zod3.z.never();
|
|
5409
|
+
let schema = import_zod3.z.strictObject({
|
|
5002
5410
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5003
5411
|
orderBy: this.orArray(this.makeOrderBySchema(model, false, true), true).optional(),
|
|
5004
5412
|
by: bySchema,
|
|
@@ -5065,10 +5473,10 @@ var InputValidator = class {
|
|
|
5065
5473
|
// #endregion
|
|
5066
5474
|
// #region Helpers
|
|
5067
5475
|
makeSkipSchema() {
|
|
5068
|
-
return
|
|
5476
|
+
return import_zod3.z.number().int().nonnegative();
|
|
5069
5477
|
}
|
|
5070
5478
|
makeTakeSchema() {
|
|
5071
|
-
return
|
|
5479
|
+
return import_zod3.z.number().int();
|
|
5072
5480
|
}
|
|
5073
5481
|
refineForSelectIncludeMutuallyExclusive(schema) {
|
|
5074
5482
|
return schema.refine((value) => !(value["select"] && value["include"]), '"select" and "include" cannot be used together');
|
|
@@ -5080,9 +5488,9 @@ var InputValidator = class {
|
|
|
5080
5488
|
return nullable ? schema.nullable() : schema;
|
|
5081
5489
|
}
|
|
5082
5490
|
orArray(schema, canBeArray) {
|
|
5083
|
-
return canBeArray ?
|
|
5491
|
+
return canBeArray ? import_zod3.z.union([
|
|
5084
5492
|
schema,
|
|
5085
|
-
|
|
5493
|
+
import_zod3.z.array(schema)
|
|
5086
5494
|
]) : schema;
|
|
5087
5495
|
}
|
|
5088
5496
|
isNumericField(fieldDef) {
|
|
@@ -6180,18 +6588,19 @@ var textMatch = /* @__PURE__ */ __name((eb, args, { dialect }, method) => {
|
|
|
6180
6588
|
} else {
|
|
6181
6589
|
op = "like";
|
|
6182
6590
|
}
|
|
6591
|
+
const escapedSearch = import_kysely8.sql`REPLACE(REPLACE(REPLACE(CAST(${searchExpr} as text), '\\', '\\\\'), '%', '\\%'), '_', '\\_')`;
|
|
6183
6592
|
searchExpr = (0, import_ts_pattern15.match)(method).with("contains", () => eb.fn("CONCAT", [
|
|
6184
6593
|
import_kysely8.sql.lit("%"),
|
|
6185
|
-
|
|
6594
|
+
escapedSearch,
|
|
6186
6595
|
import_kysely8.sql.lit("%")
|
|
6187
6596
|
])).with("startsWith", () => eb.fn("CONCAT", [
|
|
6188
|
-
|
|
6597
|
+
escapedSearch,
|
|
6189
6598
|
import_kysely8.sql.lit("%")
|
|
6190
6599
|
])).with("endsWith", () => eb.fn("CONCAT", [
|
|
6191
6600
|
import_kysely8.sql.lit("%"),
|
|
6192
|
-
|
|
6601
|
+
escapedSearch
|
|
6193
6602
|
])).exhaustive();
|
|
6194
|
-
return
|
|
6603
|
+
return import_kysely8.sql`${fieldExpr} ${import_kysely8.sql.raw(op)} ${searchExpr} escape '\\'`;
|
|
6195
6604
|
}, "textMatch");
|
|
6196
6605
|
var has = /* @__PURE__ */ __name((eb, args) => {
|
|
6197
6606
|
const [field, search2] = args;
|
|
@@ -7422,9 +7831,15 @@ var MatchingExpressionVisitor = class extends ExpressionVisitor {
|
|
|
7422
7831
|
};
|
|
7423
7832
|
// Annotate the CommonJS export names for ESM import in node:
|
|
7424
7833
|
0 && (module.exports = {
|
|
7834
|
+
AnyNull,
|
|
7835
|
+
AnyNullClass,
|
|
7425
7836
|
BaseCrudDialect,
|
|
7426
7837
|
CRUD,
|
|
7427
7838
|
CRUD_EXT,
|
|
7839
|
+
DbNull,
|
|
7840
|
+
DbNullClass,
|
|
7841
|
+
JsonNull,
|
|
7842
|
+
JsonNullClass,
|
|
7428
7843
|
KyselyUtils,
|
|
7429
7844
|
ORMError,
|
|
7430
7845
|
ORMErrorReason,
|