@zenstackhq/runtime 3.0.0-alpha.18 → 3.0.0-alpha.19
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/{contract-Cn4sSxg8.d.cts → contract-CxX20JtH.d.cts} +16 -10
- package/dist/{contract-Cn4sSxg8.d.ts → contract-CxX20JtH.d.ts} +16 -10
- package/dist/index.cjs +207 -140
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +207 -140
- package/dist/index.js.map +1 -1
- package/dist/plugins/policy/index.cjs +98 -42
- package/dist/plugins/policy/index.cjs.map +1 -1
- package/dist/plugins/policy/index.d.cts +1 -1
- package/dist/plugins/policy/index.d.ts +1 -1
- package/dist/plugins/policy/index.js +98 -42
- package/dist/plugins/policy/index.js.map +1 -1
- package/package.json +9 -9
package/dist/index.cjs
CHANGED
|
@@ -234,23 +234,23 @@ function getRelationForeignKeyFieldPairs(schema, model, relationField) {
|
|
|
234
234
|
}
|
|
235
235
|
__name(getRelationForeignKeyFieldPairs, "getRelationForeignKeyFieldPairs");
|
|
236
236
|
function isScalarField(schema, model, field) {
|
|
237
|
-
const fieldDef =
|
|
238
|
-
return !fieldDef
|
|
237
|
+
const fieldDef = getField(schema, model, field);
|
|
238
|
+
return !fieldDef?.relation && !fieldDef?.foreignKeyFor;
|
|
239
239
|
}
|
|
240
240
|
__name(isScalarField, "isScalarField");
|
|
241
241
|
function isForeignKeyField(schema, model, field) {
|
|
242
|
-
const fieldDef =
|
|
243
|
-
return !!fieldDef
|
|
242
|
+
const fieldDef = getField(schema, model, field);
|
|
243
|
+
return !!fieldDef?.foreignKeyFor;
|
|
244
244
|
}
|
|
245
245
|
__name(isForeignKeyField, "isForeignKeyField");
|
|
246
246
|
function isRelationField(schema, model, field) {
|
|
247
|
-
const fieldDef =
|
|
248
|
-
return !!fieldDef
|
|
247
|
+
const fieldDef = getField(schema, model, field);
|
|
248
|
+
return !!fieldDef?.relation;
|
|
249
249
|
}
|
|
250
250
|
__name(isRelationField, "isRelationField");
|
|
251
251
|
function isInheritedField(schema, model, field) {
|
|
252
|
-
const fieldDef =
|
|
253
|
-
return !!fieldDef
|
|
252
|
+
const fieldDef = getField(schema, model, field);
|
|
253
|
+
return !!fieldDef?.originModel;
|
|
254
254
|
}
|
|
255
255
|
__name(isInheritedField, "isInheritedField");
|
|
256
256
|
function getUniqueFields(schema, model) {
|
|
@@ -731,7 +731,7 @@ var BaseCrudDialect = class {
|
|
|
731
731
|
buildLiteralFilter(eb, lhs, type, rhs) {
|
|
732
732
|
return eb(lhs, "=", rhs !== null && rhs !== void 0 ? this.transformPrimitive(rhs, type, false) : rhs);
|
|
733
733
|
}
|
|
734
|
-
buildStandardFilter(eb, type, payload, lhs, getRhs, recurse, throwIfInvalid = false, onlyForKeys = void 0) {
|
|
734
|
+
buildStandardFilter(eb, type, payload, lhs, getRhs, recurse, throwIfInvalid = false, onlyForKeys = void 0, excludeKeys = []) {
|
|
735
735
|
if (payload === null || !(0, import_common_helpers.isPlainObject)(payload)) {
|
|
736
736
|
return {
|
|
737
737
|
conditions: [
|
|
@@ -746,6 +746,9 @@ var BaseCrudDialect = class {
|
|
|
746
746
|
if (onlyForKeys && !onlyForKeys.includes(op)) {
|
|
747
747
|
continue;
|
|
748
748
|
}
|
|
749
|
+
if (excludeKeys.includes(op)) {
|
|
750
|
+
continue;
|
|
751
|
+
}
|
|
749
752
|
const rhs = Array.isArray(value) ? value.map(getRhs) : getRhs(value);
|
|
750
753
|
const condition = (0, import_ts_pattern.match)(op).with("equals", () => rhs === null ? eb(lhs, "is", null) : eb(lhs, "=", rhs)).with("in", () => {
|
|
751
754
|
(0, import_common_helpers.invariant)(Array.isArray(rhs), "right hand side must be an array");
|
|
@@ -779,21 +782,20 @@ var BaseCrudDialect = class {
|
|
|
779
782
|
};
|
|
780
783
|
}
|
|
781
784
|
buildStringFilter(eb, fieldRef, payload) {
|
|
782
|
-
let
|
|
783
|
-
if (payload && typeof payload === "object" && "mode" in payload
|
|
784
|
-
|
|
785
|
-
fieldRef = eb.fn("lower", [
|
|
786
|
-
fieldRef
|
|
787
|
-
]);
|
|
785
|
+
let mode;
|
|
786
|
+
if (payload && typeof payload === "object" && "mode" in payload) {
|
|
787
|
+
mode = payload.mode;
|
|
788
788
|
}
|
|
789
|
-
const { conditions, consumedKeys } = this.buildStandardFilter(eb, "String", payload,
|
|
789
|
+
const { conditions, consumedKeys } = this.buildStandardFilter(eb, "String", payload, mode === "insensitive" ? eb.fn("lower", [
|
|
790
|
+
fieldRef
|
|
791
|
+
]) : fieldRef, (value) => this.prepStringCasing(eb, value, mode), (value) => this.buildStringFilter(eb, fieldRef, value));
|
|
790
792
|
if (payload && typeof payload === "object") {
|
|
791
793
|
for (const [key, value] of Object.entries(payload)) {
|
|
792
794
|
if (key === "mode" || consumedKeys.includes(key)) {
|
|
793
795
|
continue;
|
|
794
796
|
}
|
|
795
|
-
const condition = (0, import_ts_pattern.match)(key).with("contains", () => insensitive ? eb(fieldRef, "ilike", import_kysely.sql.
|
|
796
|
-
throw new
|
|
797
|
+
const condition = (0, import_ts_pattern.match)(key).with("contains", () => mode === "insensitive" ? eb(fieldRef, "ilike", import_kysely.sql.val(`%${value}%`)) : eb(fieldRef, "like", import_kysely.sql.val(`%${value}%`))).with("startsWith", () => mode === "insensitive" ? eb(fieldRef, "ilike", import_kysely.sql.val(`${value}%`)) : eb(fieldRef, "like", import_kysely.sql.val(`${value}%`))).with("endsWith", () => mode === "insensitive" ? eb(fieldRef, "ilike", import_kysely.sql.val(`%${value}`)) : eb(fieldRef, "like", import_kysely.sql.val(`%${value}`))).otherwise(() => {
|
|
798
|
+
throw new QueryError(`Invalid string filter key: ${key}`);
|
|
797
799
|
});
|
|
798
800
|
if (condition) {
|
|
799
801
|
conditions.push(condition);
|
|
@@ -802,15 +804,18 @@ var BaseCrudDialect = class {
|
|
|
802
804
|
}
|
|
803
805
|
return this.and(eb, ...conditions);
|
|
804
806
|
}
|
|
805
|
-
prepStringCasing(eb, value,
|
|
807
|
+
prepStringCasing(eb, value, mode) {
|
|
808
|
+
if (!mode || mode === "default") {
|
|
809
|
+
return value === null ? value : import_kysely.sql.val(value);
|
|
810
|
+
}
|
|
806
811
|
if (typeof value === "string") {
|
|
807
|
-
return
|
|
808
|
-
import_kysely.sql.
|
|
809
|
-
])
|
|
812
|
+
return eb.fn("lower", [
|
|
813
|
+
import_kysely.sql.val(value)
|
|
814
|
+
]);
|
|
810
815
|
} else if (Array.isArray(value)) {
|
|
811
|
-
return value.map((v) => this.prepStringCasing(eb, v,
|
|
816
|
+
return value.map((v) => this.prepStringCasing(eb, v, mode));
|
|
812
817
|
} else {
|
|
813
|
-
return value === null ? null : import_kysely.sql.
|
|
818
|
+
return value === null ? null : import_kysely.sql.val(value);
|
|
814
819
|
}
|
|
815
820
|
}
|
|
816
821
|
buildNumberFilter(eb, fieldRef, type, payload) {
|
|
@@ -972,6 +977,32 @@ var BaseCrudDialect = class {
|
|
|
972
977
|
});
|
|
973
978
|
return query;
|
|
974
979
|
}
|
|
980
|
+
buildCountJson(model, eb, parentAlias, payload) {
|
|
981
|
+
const modelDef = requireModel(this.schema, model);
|
|
982
|
+
const toManyRelations = Object.entries(modelDef.fields).filter(([, field]) => field.relation && field.array);
|
|
983
|
+
const selections = payload === true ? {
|
|
984
|
+
select: toManyRelations.reduce((acc, [field]) => {
|
|
985
|
+
acc[field] = true;
|
|
986
|
+
return acc;
|
|
987
|
+
}, {})
|
|
988
|
+
} : payload;
|
|
989
|
+
const jsonObject = {};
|
|
990
|
+
for (const [field, value] of Object.entries(selections.select)) {
|
|
991
|
+
const fieldDef = requireField(this.schema, model, field);
|
|
992
|
+
const fieldModel = fieldDef.type;
|
|
993
|
+
const joinPairs = buildJoinPairs(this.schema, model, parentAlias, field, fieldModel);
|
|
994
|
+
let fieldCountQuery = eb.selectFrom(fieldModel).select(eb.fn.countAll().as(`_count$${field}`));
|
|
995
|
+
for (const [left, right] of joinPairs) {
|
|
996
|
+
fieldCountQuery = fieldCountQuery.whereRef(left, "=", right);
|
|
997
|
+
}
|
|
998
|
+
if (value && typeof value === "object" && "where" in value && value.where && typeof value.where === "object") {
|
|
999
|
+
const filter = this.buildFilter(eb, fieldModel, fieldModel, value.where);
|
|
1000
|
+
fieldCountQuery = fieldCountQuery.where(filter);
|
|
1001
|
+
}
|
|
1002
|
+
jsonObject[field] = fieldCountQuery;
|
|
1003
|
+
}
|
|
1004
|
+
return this.buildJsonObject(eb, jsonObject);
|
|
1005
|
+
}
|
|
975
1006
|
// #endregion
|
|
976
1007
|
// #region utils
|
|
977
1008
|
negateSort(sort, negated) {
|
|
@@ -1100,7 +1131,7 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
|
|
|
1100
1131
|
});
|
|
1101
1132
|
return qb;
|
|
1102
1133
|
}
|
|
1103
|
-
buildRelationObjectArgs(relationModel, relationField, eb, payload,
|
|
1134
|
+
buildRelationObjectArgs(relationModel, relationField, eb, payload, parentAlias) {
|
|
1104
1135
|
const relationModelDef = requireModel(this.schema, relationModel);
|
|
1105
1136
|
const objArgs = [];
|
|
1106
1137
|
const descendantModels = getDelegateDescendantModels(this.schema, relationModel);
|
|
@@ -1116,20 +1147,28 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
|
|
|
1116
1147
|
buildFieldRef(this.schema, relationModel, field, this.options, eb)
|
|
1117
1148
|
]).flatMap((v) => v));
|
|
1118
1149
|
} else if (payload.select) {
|
|
1119
|
-
objArgs.push(...Object.entries(payload.select).filter(([, value]) => value).map(([field]) => {
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1150
|
+
objArgs.push(...Object.entries(payload.select).filter(([, value]) => value).map(([field, value]) => {
|
|
1151
|
+
if (field === "_count") {
|
|
1152
|
+
const subJson = this.buildCountJson(relationModel, eb, `${parentAlias}$${relationField}`, value);
|
|
1153
|
+
return [
|
|
1154
|
+
import_kysely2.sql.lit(field),
|
|
1155
|
+
subJson
|
|
1156
|
+
];
|
|
1157
|
+
} else {
|
|
1158
|
+
const fieldDef = requireField(this.schema, relationModel, field);
|
|
1159
|
+
const fieldValue = fieldDef.relation ? eb.ref(`${parentAlias}$${relationField}$${field}.$j`) : buildFieldRef(this.schema, relationModel, field, this.options, eb);
|
|
1160
|
+
return [
|
|
1161
|
+
import_kysely2.sql.lit(field),
|
|
1162
|
+
fieldValue
|
|
1163
|
+
];
|
|
1164
|
+
}
|
|
1126
1165
|
}).flatMap((v) => v));
|
|
1127
1166
|
}
|
|
1128
1167
|
if (typeof payload === "object" && payload.include && typeof payload.include === "object") {
|
|
1129
1168
|
objArgs.push(...Object.entries(payload.include).filter(([, value]) => value).map(([field]) => [
|
|
1130
1169
|
import_kysely2.sql.lit(field),
|
|
1131
1170
|
// reference the synthesized JSON field
|
|
1132
|
-
eb.ref(`${
|
|
1171
|
+
eb.ref(`${parentAlias}$${relationField}$${field}.$j`)
|
|
1133
1172
|
]).flatMap((v) => v));
|
|
1134
1173
|
}
|
|
1135
1174
|
return objArgs;
|
|
@@ -1215,11 +1254,11 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
1215
1254
|
buildRelationSelection(query, model, relationField, parentAlias, payload) {
|
|
1216
1255
|
return query.select((eb) => this.buildRelationJSON(model, eb, relationField, parentAlias, payload).as(relationField));
|
|
1217
1256
|
}
|
|
1218
|
-
buildRelationJSON(model, eb, relationField,
|
|
1257
|
+
buildRelationJSON(model, eb, relationField, parentAlias, payload) {
|
|
1219
1258
|
const relationFieldDef = requireField(this.schema, model, relationField);
|
|
1220
1259
|
const relationModel = relationFieldDef.type;
|
|
1221
1260
|
const relationModelDef = requireModel(this.schema, relationModel);
|
|
1222
|
-
const subQueryName = `${
|
|
1261
|
+
const subQueryName = `${parentAlias}$${relationField}`;
|
|
1223
1262
|
let tbl = eb.selectFrom(() => {
|
|
1224
1263
|
let subQuery = this.buildSelectModel(eb, relationModel);
|
|
1225
1264
|
subQuery = this.buildSelectAllFields(relationModel, subQuery, typeof payload === "object" ? payload?.omit : void 0);
|
|
@@ -1243,14 +1282,14 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
1243
1282
|
const relationIds = getIdFields(this.schema, relationModel);
|
|
1244
1283
|
(0, import_common_helpers3.invariant)(parentIds.length === 1, "many-to-many relation must have exactly one id field");
|
|
1245
1284
|
(0, import_common_helpers3.invariant)(relationIds.length === 1, "many-to-many relation must have exactly one id field");
|
|
1246
|
-
subQuery = subQuery.where(eb(eb.ref(`${relationModel}.${relationIds[0]}`), "in", eb.selectFrom(m2m.joinTable).select(`${m2m.joinTable}.${m2m.otherFkName}`).whereRef(`${
|
|
1285
|
+
subQuery = subQuery.where(eb(eb.ref(`${relationModel}.${relationIds[0]}`), "in", eb.selectFrom(m2m.joinTable).select(`${m2m.joinTable}.${m2m.otherFkName}`).whereRef(`${parentAlias}.${parentIds[0]}`, "=", `${m2m.joinTable}.${m2m.parentFkName}`)));
|
|
1247
1286
|
} else {
|
|
1248
1287
|
const { keyPairs, ownedByModel } = getRelationForeignKeyFieldPairs(this.schema, model, relationField);
|
|
1249
1288
|
keyPairs.forEach(({ fk, pk }) => {
|
|
1250
1289
|
if (ownedByModel) {
|
|
1251
|
-
subQuery = subQuery.whereRef(`${relationModel}.${pk}`, "=", `${
|
|
1290
|
+
subQuery = subQuery.whereRef(`${relationModel}.${pk}`, "=", `${parentAlias}.${fk}`);
|
|
1252
1291
|
} else {
|
|
1253
|
-
subQuery = subQuery.whereRef(`${relationModel}.${fk}`, "=", `${
|
|
1292
|
+
subQuery = subQuery.whereRef(`${relationModel}.${fk}`, "=", `${parentAlias}.${pk}`);
|
|
1254
1293
|
}
|
|
1255
1294
|
});
|
|
1256
1295
|
}
|
|
@@ -1272,24 +1311,32 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
1272
1311
|
]).flatMap((v) => v));
|
|
1273
1312
|
} else if (payload.select) {
|
|
1274
1313
|
objArgs.push(...Object.entries(payload.select).filter(([, value]) => value).map(([field, value]) => {
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
const subJson = this.buildRelationJSON(relationModel, eb, field, `${parentName}$${relationField}`, value);
|
|
1314
|
+
if (field === "_count") {
|
|
1315
|
+
const subJson = this.buildCountJson(relationModel, eb, `${parentAlias}$${relationField}`, value);
|
|
1278
1316
|
return [
|
|
1279
1317
|
import_kysely3.sql.lit(field),
|
|
1280
1318
|
subJson
|
|
1281
1319
|
];
|
|
1282
1320
|
} else {
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1321
|
+
const fieldDef = requireField(this.schema, relationModel, field);
|
|
1322
|
+
if (fieldDef.relation) {
|
|
1323
|
+
const subJson = this.buildRelationJSON(relationModel, eb, field, `${parentAlias}$${relationField}`, value);
|
|
1324
|
+
return [
|
|
1325
|
+
import_kysely3.sql.lit(field),
|
|
1326
|
+
subJson
|
|
1327
|
+
];
|
|
1328
|
+
} else {
|
|
1329
|
+
return [
|
|
1330
|
+
import_kysely3.sql.lit(field),
|
|
1331
|
+
buildFieldRef(this.schema, relationModel, field, this.options, eb)
|
|
1332
|
+
];
|
|
1333
|
+
}
|
|
1287
1334
|
}
|
|
1288
1335
|
}).flatMap((v) => v));
|
|
1289
1336
|
}
|
|
1290
1337
|
if (typeof payload === "object" && payload.include && typeof payload.include === "object") {
|
|
1291
1338
|
objArgs.push(...Object.entries(payload.include).filter(([, value]) => value).map(([field, value]) => {
|
|
1292
|
-
const subJson = this.buildRelationJSON(relationModel, eb, field, `${
|
|
1339
|
+
const subJson = this.buildRelationJSON(relationModel, eb, field, `${parentAlias}$${relationField}`, value);
|
|
1293
1340
|
return [
|
|
1294
1341
|
import_kysely3.sql.lit(field),
|
|
1295
1342
|
subJson
|
|
@@ -2701,6 +2748,7 @@ var BaseOperationHandler = class {
|
|
|
2701
2748
|
query = query.distinctOn(distinct.map((f) => import_kysely8.sql.ref(`${model}.${f}`)));
|
|
2702
2749
|
} else {
|
|
2703
2750
|
inMemoryDistinct = distinct;
|
|
2751
|
+
query = distinct.reduce((acc, field) => acc.select((eb) => buildFieldRef(this.schema, model, field, this.options, eb).as(`$distinct$${field}`)), query);
|
|
2704
2752
|
}
|
|
2705
2753
|
}
|
|
2706
2754
|
if (args && "select" in args && args.select) {
|
|
@@ -2738,13 +2786,16 @@ ${compiled.parameters.map((p) => (0, import_node_util.inspect)(p)).join("\n")}`;
|
|
|
2738
2786
|
const distinctResult = [];
|
|
2739
2787
|
const seen = /* @__PURE__ */ new Set();
|
|
2740
2788
|
for (const r of result) {
|
|
2741
|
-
const key = safeJSONStringify(inMemoryDistinct.map((f) => r[f]));
|
|
2789
|
+
const key = safeJSONStringify(inMemoryDistinct.map((f) => r[`$distinct$${f}`]));
|
|
2742
2790
|
if (!seen.has(key)) {
|
|
2743
2791
|
distinctResult.push(r);
|
|
2744
2792
|
seen.add(key);
|
|
2745
2793
|
}
|
|
2746
2794
|
}
|
|
2747
2795
|
result = distinctResult;
|
|
2796
|
+
for (const r of result) {
|
|
2797
|
+
Object.keys(r).filter((k) => k.startsWith("$distinct$")).forEach((k) => delete r[k]);
|
|
2798
|
+
}
|
|
2748
2799
|
}
|
|
2749
2800
|
return result;
|
|
2750
2801
|
}
|
|
@@ -2782,32 +2833,7 @@ ${compiled.parameters.map((p) => (0, import_node_util.inspect)(p)).join("\n")}`;
|
|
|
2782
2833
|
return result;
|
|
2783
2834
|
}
|
|
2784
2835
|
buildCountSelection(query, model, parentAlias, payload) {
|
|
2785
|
-
|
|
2786
|
-
const toManyRelations = Object.entries(modelDef.fields).filter(([, field]) => field.relation && field.array);
|
|
2787
|
-
const selections = payload === true ? {
|
|
2788
|
-
select: toManyRelations.reduce((acc, [field]) => {
|
|
2789
|
-
acc[field] = true;
|
|
2790
|
-
return acc;
|
|
2791
|
-
}, {})
|
|
2792
|
-
} : payload;
|
|
2793
|
-
const eb = (0, import_kysely8.expressionBuilder)();
|
|
2794
|
-
const jsonObject = {};
|
|
2795
|
-
for (const [field, value] of Object.entries(selections.select)) {
|
|
2796
|
-
const fieldDef = requireField(this.schema, model, field);
|
|
2797
|
-
const fieldModel = fieldDef.type;
|
|
2798
|
-
const joinPairs = buildJoinPairs(this.schema, model, parentAlias, field, fieldModel);
|
|
2799
|
-
let fieldCountQuery = eb.selectFrom(fieldModel).select(eb.fn.countAll().as(`_count$${field}`));
|
|
2800
|
-
for (const [left, right] of joinPairs) {
|
|
2801
|
-
fieldCountQuery = fieldCountQuery.whereRef(left, "=", right);
|
|
2802
|
-
}
|
|
2803
|
-
if (value && typeof value === "object" && "where" in value && value.where && typeof value.where === "object") {
|
|
2804
|
-
const filter = this.dialect.buildFilter(eb, fieldModel, fieldModel, value.where);
|
|
2805
|
-
fieldCountQuery = fieldCountQuery.where(filter);
|
|
2806
|
-
}
|
|
2807
|
-
jsonObject[field] = fieldCountQuery;
|
|
2808
|
-
}
|
|
2809
|
-
query = query.select((eb2) => this.dialect.buildJsonObject(eb2, jsonObject).as("_count"));
|
|
2810
|
-
return query;
|
|
2836
|
+
return query.select((eb) => this.dialect.buildCountJson(model, eb, parentAlias, payload).as("_count"));
|
|
2811
2837
|
}
|
|
2812
2838
|
buildCursorFilter(model, query, cursor, orderBy, negateOrderBy) {
|
|
2813
2839
|
if (!orderBy) {
|
|
@@ -4533,11 +4559,11 @@ var InputValidator = class {
|
|
|
4533
4559
|
fields["distinct"] = this.makeDistinctSchema(model).optional();
|
|
4534
4560
|
fields["cursor"] = this.makeCursorSchema(model).optional();
|
|
4535
4561
|
if (options.collection) {
|
|
4536
|
-
fields["skip"] =
|
|
4537
|
-
fields["take"] =
|
|
4562
|
+
fields["skip"] = this.makeSkipSchema().optional();
|
|
4563
|
+
fields["take"] = this.makeTakeSchema().optional();
|
|
4538
4564
|
fields["orderBy"] = this.orArray(this.makeOrderBySchema(model, true, false), true).optional();
|
|
4539
4565
|
}
|
|
4540
|
-
let result = import_zod.z.
|
|
4566
|
+
let result = import_zod.z.strictObject(fields);
|
|
4541
4567
|
result = this.refineForSelectIncludeMutuallyExclusive(result);
|
|
4542
4568
|
result = this.refineForSelectOmitMutuallyExclusive(result);
|
|
4543
4569
|
if (!options.unique) {
|
|
@@ -4604,7 +4630,7 @@ var InputValidator = class {
|
|
|
4604
4630
|
if (fieldDef.array) {
|
|
4605
4631
|
fieldSchema = import_zod.z.union([
|
|
4606
4632
|
fieldSchema,
|
|
4607
|
-
import_zod.z.
|
|
4633
|
+
import_zod.z.strictObject({
|
|
4608
4634
|
some: fieldSchema.optional(),
|
|
4609
4635
|
every: fieldSchema.optional(),
|
|
4610
4636
|
none: fieldSchema.optional()
|
|
@@ -4613,7 +4639,7 @@ var InputValidator = class {
|
|
|
4613
4639
|
} else {
|
|
4614
4640
|
fieldSchema = import_zod.z.union([
|
|
4615
4641
|
fieldSchema,
|
|
4616
|
-
import_zod.z.
|
|
4642
|
+
import_zod.z.strictObject({
|
|
4617
4643
|
is: fieldSchema.optional(),
|
|
4618
4644
|
isNot: fieldSchema.optional()
|
|
4619
4645
|
})
|
|
@@ -4664,7 +4690,7 @@ var InputValidator = class {
|
|
|
4664
4690
|
fields["AND"] = this.orArray(import_zod.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
|
|
4665
4691
|
fields["OR"] = import_zod.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)).array().optional();
|
|
4666
4692
|
fields["NOT"] = this.orArray(import_zod.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
|
|
4667
|
-
const baseWhere = import_zod.z.
|
|
4693
|
+
const baseWhere = import_zod.z.strictObject(fields);
|
|
4668
4694
|
let result = baseWhere;
|
|
4669
4695
|
if (unique) {
|
|
4670
4696
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
@@ -4688,7 +4714,7 @@ var InputValidator = class {
|
|
|
4688
4714
|
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => import_zod.z.lazy(() => this.makeEnumFilterSchema(enumDef, optional)));
|
|
4689
4715
|
return import_zod.z.union([
|
|
4690
4716
|
this.nullableIf(baseSchema, optional),
|
|
4691
|
-
import_zod.z.
|
|
4717
|
+
import_zod.z.strictObject({
|
|
4692
4718
|
equals: components.equals,
|
|
4693
4719
|
in: components.in,
|
|
4694
4720
|
notIn: components.notIn,
|
|
@@ -4697,7 +4723,7 @@ var InputValidator = class {
|
|
|
4697
4723
|
]);
|
|
4698
4724
|
}
|
|
4699
4725
|
makeArrayFilterSchema(type) {
|
|
4700
|
-
return import_zod.z.
|
|
4726
|
+
return import_zod.z.strictObject({
|
|
4701
4727
|
equals: this.makePrimitiveSchema(type).array().optional(),
|
|
4702
4728
|
has: this.makePrimitiveSchema(type).optional(),
|
|
4703
4729
|
hasEvery: this.makePrimitiveSchema(type).array().optional(),
|
|
@@ -4723,7 +4749,7 @@ var InputValidator = class {
|
|
|
4723
4749
|
makeBooleanFilterSchema(optional) {
|
|
4724
4750
|
return import_zod.z.union([
|
|
4725
4751
|
this.nullableIf(import_zod.z.boolean(), optional),
|
|
4726
|
-
import_zod.z.
|
|
4752
|
+
import_zod.z.strictObject({
|
|
4727
4753
|
equals: this.nullableIf(import_zod.z.boolean(), optional).optional(),
|
|
4728
4754
|
not: import_zod.z.lazy(() => this.makeBooleanFilterSchema(optional)).optional()
|
|
4729
4755
|
})
|
|
@@ -4734,7 +4760,7 @@ var InputValidator = class {
|
|
|
4734
4760
|
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => import_zod.z.instanceof(Uint8Array));
|
|
4735
4761
|
return import_zod.z.union([
|
|
4736
4762
|
this.nullableIf(baseSchema, optional),
|
|
4737
|
-
import_zod.z.
|
|
4763
|
+
import_zod.z.strictObject({
|
|
4738
4764
|
equals: components.equals,
|
|
4739
4765
|
in: components.in,
|
|
4740
4766
|
notIn: components.notIn,
|
|
@@ -4758,14 +4784,31 @@ var InputValidator = class {
|
|
|
4758
4784
|
makeCommonPrimitiveFilterSchema(baseSchema, optional, makeThis) {
|
|
4759
4785
|
return import_zod.z.union([
|
|
4760
4786
|
this.nullableIf(baseSchema, optional),
|
|
4761
|
-
import_zod.z.
|
|
4787
|
+
import_zod.z.strictObject(this.makeCommonPrimitiveFilterComponents(baseSchema, optional, makeThis))
|
|
4762
4788
|
]);
|
|
4763
4789
|
}
|
|
4764
4790
|
makeNumberFilterSchema(baseSchema, optional) {
|
|
4765
4791
|
return this.makeCommonPrimitiveFilterSchema(baseSchema, optional, () => import_zod.z.lazy(() => this.makeNumberFilterSchema(baseSchema, optional)));
|
|
4766
4792
|
}
|
|
4767
4793
|
makeStringFilterSchema(optional) {
|
|
4768
|
-
return
|
|
4794
|
+
return import_zod.z.union([
|
|
4795
|
+
this.nullableIf(import_zod.z.string(), optional),
|
|
4796
|
+
import_zod.z.strictObject({
|
|
4797
|
+
...this.makeCommonPrimitiveFilterComponents(import_zod.z.string(), optional, () => import_zod.z.lazy(() => this.makeStringFilterSchema(optional))),
|
|
4798
|
+
startsWith: import_zod.z.string().optional(),
|
|
4799
|
+
endsWith: import_zod.z.string().optional(),
|
|
4800
|
+
contains: import_zod.z.string().optional(),
|
|
4801
|
+
...this.providerSupportsCaseSensitivity ? {
|
|
4802
|
+
mode: this.makeStringModeSchema().optional()
|
|
4803
|
+
} : {}
|
|
4804
|
+
})
|
|
4805
|
+
]);
|
|
4806
|
+
}
|
|
4807
|
+
makeStringModeSchema() {
|
|
4808
|
+
return import_zod.z.union([
|
|
4809
|
+
import_zod.z.literal("default"),
|
|
4810
|
+
import_zod.z.literal("insensitive")
|
|
4811
|
+
]);
|
|
4769
4812
|
}
|
|
4770
4813
|
makeSelectSchema(model) {
|
|
4771
4814
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -4775,7 +4818,7 @@ var InputValidator = class {
|
|
|
4775
4818
|
if (fieldDef.relation) {
|
|
4776
4819
|
fields[field] = import_zod.z.union([
|
|
4777
4820
|
import_zod.z.literal(true),
|
|
4778
|
-
import_zod.z.
|
|
4821
|
+
import_zod.z.strictObject({
|
|
4779
4822
|
select: import_zod.z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional(),
|
|
4780
4823
|
include: import_zod.z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional()
|
|
4781
4824
|
})
|
|
@@ -4784,22 +4827,24 @@ var InputValidator = class {
|
|
|
4784
4827
|
fields[field] = import_zod.z.boolean().optional();
|
|
4785
4828
|
}
|
|
4786
4829
|
}
|
|
4787
|
-
const toManyRelations = Object.
|
|
4830
|
+
const toManyRelations = Object.values(modelDef.fields).filter((def) => def.relation && def.array);
|
|
4788
4831
|
if (toManyRelations.length > 0) {
|
|
4789
4832
|
fields["_count"] = import_zod.z.union([
|
|
4790
4833
|
import_zod.z.literal(true),
|
|
4791
|
-
import_zod.z.
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
import_zod.z.
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4834
|
+
import_zod.z.strictObject({
|
|
4835
|
+
select: import_zod.z.strictObject(toManyRelations.reduce((acc, fieldDef) => ({
|
|
4836
|
+
...acc,
|
|
4837
|
+
[fieldDef.name]: import_zod.z.union([
|
|
4838
|
+
import_zod.z.boolean(),
|
|
4839
|
+
import_zod.z.strictObject({
|
|
4840
|
+
where: this.makeWhereSchema(fieldDef.type, false, false)
|
|
4841
|
+
})
|
|
4842
|
+
]).optional()
|
|
4843
|
+
}), {}))
|
|
4844
|
+
})
|
|
4800
4845
|
]).optional();
|
|
4801
4846
|
}
|
|
4802
|
-
return import_zod.z.
|
|
4847
|
+
return import_zod.z.strictObject(fields);
|
|
4803
4848
|
}
|
|
4804
4849
|
makeOmitSchema(model) {
|
|
4805
4850
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -4810,7 +4855,7 @@ var InputValidator = class {
|
|
|
4810
4855
|
fields[field] = import_zod.z.boolean().optional();
|
|
4811
4856
|
}
|
|
4812
4857
|
}
|
|
4813
|
-
return import_zod.z.
|
|
4858
|
+
return import_zod.z.strictObject(fields);
|
|
4814
4859
|
}
|
|
4815
4860
|
makeIncludeSchema(model) {
|
|
4816
4861
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -4820,15 +4865,20 @@ var InputValidator = class {
|
|
|
4820
4865
|
if (fieldDef.relation) {
|
|
4821
4866
|
fields[field] = import_zod.z.union([
|
|
4822
4867
|
import_zod.z.literal(true),
|
|
4823
|
-
import_zod.z.
|
|
4868
|
+
import_zod.z.strictObject({
|
|
4824
4869
|
select: import_zod.z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional(),
|
|
4825
4870
|
include: import_zod.z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional(),
|
|
4826
|
-
|
|
4871
|
+
omit: import_zod.z.lazy(() => this.makeOmitSchema(fieldDef.type)).optional(),
|
|
4872
|
+
where: import_zod.z.lazy(() => this.makeWhereSchema(fieldDef.type, false)).optional(),
|
|
4873
|
+
orderBy: import_zod.z.lazy(() => this.makeOrderBySchema(fieldDef.type, true, false)).optional(),
|
|
4874
|
+
skip: this.makeSkipSchema().optional(),
|
|
4875
|
+
take: this.makeTakeSchema().optional(),
|
|
4876
|
+
distinct: this.makeDistinctSchema(fieldDef.type).optional()
|
|
4827
4877
|
})
|
|
4828
4878
|
]).optional();
|
|
4829
4879
|
}
|
|
4830
4880
|
}
|
|
4831
|
-
return import_zod.z.
|
|
4881
|
+
return import_zod.z.strictObject(fields);
|
|
4832
4882
|
}
|
|
4833
4883
|
makeOrderBySchema(model, withRelation, WithAggregation) {
|
|
4834
4884
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -4841,13 +4891,21 @@ var InputValidator = class {
|
|
|
4841
4891
|
const fieldDef = requireField(this.schema, model, field);
|
|
4842
4892
|
if (fieldDef.relation) {
|
|
4843
4893
|
if (withRelation) {
|
|
4844
|
-
fields[field] = import_zod.z.lazy(() =>
|
|
4894
|
+
fields[field] = import_zod.z.lazy(() => {
|
|
4895
|
+
let relationOrderBy = this.makeOrderBySchema(fieldDef.type, withRelation, WithAggregation);
|
|
4896
|
+
if (fieldDef.array) {
|
|
4897
|
+
relationOrderBy = relationOrderBy.extend({
|
|
4898
|
+
_count: sort
|
|
4899
|
+
});
|
|
4900
|
+
}
|
|
4901
|
+
return relationOrderBy.optional();
|
|
4902
|
+
});
|
|
4845
4903
|
}
|
|
4846
4904
|
} else {
|
|
4847
4905
|
if (fieldDef.optional) {
|
|
4848
4906
|
fields[field] = import_zod.z.union([
|
|
4849
4907
|
sort,
|
|
4850
|
-
import_zod.z.
|
|
4908
|
+
import_zod.z.strictObject({
|
|
4851
4909
|
sort,
|
|
4852
4910
|
nulls: import_zod.z.union([
|
|
4853
4911
|
import_zod.z.literal("first"),
|
|
@@ -4872,7 +4930,7 @@ var InputValidator = class {
|
|
|
4872
4930
|
fields[agg] = import_zod.z.lazy(() => this.makeOrderBySchema(model, true, false).optional());
|
|
4873
4931
|
}
|
|
4874
4932
|
}
|
|
4875
|
-
return import_zod.z.
|
|
4933
|
+
return import_zod.z.strictObject(fields);
|
|
4876
4934
|
}
|
|
4877
4935
|
makeDistinctSchema(model) {
|
|
4878
4936
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -4891,7 +4949,7 @@ var InputValidator = class {
|
|
|
4891
4949
|
select: this.makeSelectSchema(model).optional(),
|
|
4892
4950
|
include: this.makeIncludeSchema(model).optional(),
|
|
4893
4951
|
omit: this.makeOmitSchema(model).optional()
|
|
4894
|
-
})
|
|
4952
|
+
});
|
|
4895
4953
|
return this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
4896
4954
|
}
|
|
4897
4955
|
makeCreateManySchema(model) {
|
|
@@ -4899,7 +4957,7 @@ var InputValidator = class {
|
|
|
4899
4957
|
}
|
|
4900
4958
|
makeCreateManyAndReturnSchema(model) {
|
|
4901
4959
|
const base = this.makeCreateManyDataSchema(model, []);
|
|
4902
|
-
const result = base.merge(import_zod.z.
|
|
4960
|
+
const result = base.merge(import_zod.z.strictObject({
|
|
4903
4961
|
select: this.makeSelectSchema(model).optional(),
|
|
4904
4962
|
omit: this.makeOmitSchema(model).optional()
|
|
4905
4963
|
}));
|
|
@@ -4961,7 +5019,7 @@ var InputValidator = class {
|
|
|
4961
5019
|
if (fieldDef.array) {
|
|
4962
5020
|
fieldSchema = import_zod.z.union([
|
|
4963
5021
|
import_zod.z.array(fieldSchema),
|
|
4964
|
-
import_zod.z.
|
|
5022
|
+
import_zod.z.strictObject({
|
|
4965
5023
|
set: import_zod.z.array(fieldSchema)
|
|
4966
5024
|
})
|
|
4967
5025
|
]).optional();
|
|
@@ -4979,16 +5037,16 @@ var InputValidator = class {
|
|
|
4979
5037
|
}
|
|
4980
5038
|
});
|
|
4981
5039
|
if (!hasRelation) {
|
|
4982
|
-
return this.orArray(import_zod.z.
|
|
5040
|
+
return this.orArray(import_zod.z.strictObject(uncheckedVariantFields), canBeArray);
|
|
4983
5041
|
} else {
|
|
4984
5042
|
return import_zod.z.union([
|
|
4985
|
-
import_zod.z.
|
|
4986
|
-
import_zod.z.
|
|
5043
|
+
import_zod.z.strictObject(uncheckedVariantFields),
|
|
5044
|
+
import_zod.z.strictObject(checkedVariantFields),
|
|
4987
5045
|
...canBeArray ? [
|
|
4988
|
-
import_zod.z.array(import_zod.z.
|
|
5046
|
+
import_zod.z.array(import_zod.z.strictObject(uncheckedVariantFields))
|
|
4989
5047
|
] : [],
|
|
4990
5048
|
...canBeArray ? [
|
|
4991
|
-
import_zod.z.array(import_zod.z.
|
|
5049
|
+
import_zod.z.array(import_zod.z.strictObject(checkedVariantFields))
|
|
4992
5050
|
] : []
|
|
4993
5051
|
]);
|
|
4994
5052
|
}
|
|
@@ -5016,31 +5074,31 @@ var InputValidator = class {
|
|
|
5016
5074
|
fields["disconnect"] = this.makeDisconnectDataSchema(fieldType, array).optional();
|
|
5017
5075
|
fields["delete"] = this.makeDeleteRelationDataSchema(fieldType, array, true).optional();
|
|
5018
5076
|
}
|
|
5019
|
-
fields["update"] = array ? this.orArray(import_zod.z.
|
|
5077
|
+
fields["update"] = array ? this.orArray(import_zod.z.strictObject({
|
|
5020
5078
|
where: this.makeWhereSchema(fieldType, true),
|
|
5021
5079
|
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
5022
5080
|
}), true).optional() : import_zod.z.union([
|
|
5023
|
-
import_zod.z.
|
|
5081
|
+
import_zod.z.strictObject({
|
|
5024
5082
|
where: this.makeWhereSchema(fieldType, true),
|
|
5025
5083
|
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
5026
5084
|
}),
|
|
5027
5085
|
this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
5028
5086
|
]).optional();
|
|
5029
|
-
fields["upsert"] = this.orArray(import_zod.z.
|
|
5087
|
+
fields["upsert"] = this.orArray(import_zod.z.strictObject({
|
|
5030
5088
|
where: this.makeWhereSchema(fieldType, true),
|
|
5031
5089
|
create: this.makeCreateDataSchema(fieldType, false, withoutFields),
|
|
5032
5090
|
update: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
5033
5091
|
}), true).optional();
|
|
5034
5092
|
if (array) {
|
|
5035
5093
|
fields["set"] = this.makeSetDataSchema(fieldType, true).optional();
|
|
5036
|
-
fields["updateMany"] = this.orArray(import_zod.z.
|
|
5094
|
+
fields["updateMany"] = this.orArray(import_zod.z.strictObject({
|
|
5037
5095
|
where: this.makeWhereSchema(fieldType, false, true),
|
|
5038
5096
|
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
5039
5097
|
}), true).optional();
|
|
5040
5098
|
fields["deleteMany"] = this.makeDeleteRelationDataSchema(fieldType, true, false).optional();
|
|
5041
5099
|
}
|
|
5042
5100
|
}
|
|
5043
|
-
return import_zod.z.
|
|
5101
|
+
return import_zod.z.strictObject(fields);
|
|
5044
5102
|
}
|
|
5045
5103
|
makeSetDataSchema(model, canBeArray) {
|
|
5046
5104
|
return this.orArray(this.makeWhereSchema(model, true), canBeArray);
|
|
@@ -5070,13 +5128,13 @@ var InputValidator = class {
|
|
|
5070
5128
|
return this.orArray(import_zod.z.object({
|
|
5071
5129
|
where: whereSchema,
|
|
5072
5130
|
create: createSchema
|
|
5073
|
-
})
|
|
5131
|
+
}), canBeArray);
|
|
5074
5132
|
}
|
|
5075
5133
|
makeCreateManyDataSchema(model, withoutFields) {
|
|
5076
5134
|
return import_zod.z.object({
|
|
5077
5135
|
data: this.makeCreateDataSchema(model, true, withoutFields, true),
|
|
5078
5136
|
skipDuplicates: import_zod.z.boolean().optional()
|
|
5079
|
-
})
|
|
5137
|
+
});
|
|
5080
5138
|
}
|
|
5081
5139
|
// #endregion
|
|
5082
5140
|
// #region Update
|
|
@@ -5087,7 +5145,7 @@ var InputValidator = class {
|
|
|
5087
5145
|
select: this.makeSelectSchema(model).optional(),
|
|
5088
5146
|
include: this.makeIncludeSchema(model).optional(),
|
|
5089
5147
|
omit: this.makeOmitSchema(model).optional()
|
|
5090
|
-
})
|
|
5148
|
+
});
|
|
5091
5149
|
return this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
5092
5150
|
}
|
|
5093
5151
|
makeUpdateManySchema(model) {
|
|
@@ -5095,11 +5153,11 @@ var InputValidator = class {
|
|
|
5095
5153
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5096
5154
|
data: this.makeUpdateDataSchema(model, [], true),
|
|
5097
5155
|
limit: import_zod.z.number().int().nonnegative().optional()
|
|
5098
|
-
})
|
|
5156
|
+
});
|
|
5099
5157
|
}
|
|
5100
5158
|
makeUpdateManyAndReturnSchema(model) {
|
|
5101
5159
|
const base = this.makeUpdateManySchema(model);
|
|
5102
|
-
const result = base.merge(import_zod.z.
|
|
5160
|
+
const result = base.merge(import_zod.z.strictObject({
|
|
5103
5161
|
select: this.makeSelectSchema(model).optional(),
|
|
5104
5162
|
omit: this.makeOmitSchema(model).optional()
|
|
5105
5163
|
}));
|
|
@@ -5113,7 +5171,7 @@ var InputValidator = class {
|
|
|
5113
5171
|
select: this.makeSelectSchema(model).optional(),
|
|
5114
5172
|
include: this.makeIncludeSchema(model).optional(),
|
|
5115
5173
|
omit: this.makeOmitSchema(model).optional()
|
|
5116
|
-
})
|
|
5174
|
+
});
|
|
5117
5175
|
return this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
5118
5176
|
}
|
|
5119
5177
|
makeUpdateDataSchema(model, withoutFields = [], withoutRelationFields = false) {
|
|
@@ -5180,11 +5238,11 @@ var InputValidator = class {
|
|
|
5180
5238
|
}
|
|
5181
5239
|
});
|
|
5182
5240
|
if (!hasRelation) {
|
|
5183
|
-
return import_zod.z.
|
|
5241
|
+
return import_zod.z.strictObject(uncheckedVariantFields);
|
|
5184
5242
|
} else {
|
|
5185
5243
|
return import_zod.z.union([
|
|
5186
|
-
import_zod.z.
|
|
5187
|
-
import_zod.z.
|
|
5244
|
+
import_zod.z.strictObject(uncheckedVariantFields),
|
|
5245
|
+
import_zod.z.strictObject(checkedVariantFields)
|
|
5188
5246
|
]);
|
|
5189
5247
|
}
|
|
5190
5248
|
}
|
|
@@ -5195,25 +5253,25 @@ var InputValidator = class {
|
|
|
5195
5253
|
where: this.makeWhereSchema(model, true),
|
|
5196
5254
|
select: this.makeSelectSchema(model).optional(),
|
|
5197
5255
|
include: this.makeIncludeSchema(model).optional()
|
|
5198
|
-
})
|
|
5256
|
+
});
|
|
5199
5257
|
return this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
5200
5258
|
}
|
|
5201
5259
|
makeDeleteManySchema(model) {
|
|
5202
5260
|
return import_zod.z.object({
|
|
5203
5261
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5204
5262
|
limit: import_zod.z.number().int().nonnegative().optional()
|
|
5205
|
-
}).
|
|
5263
|
+
}).optional();
|
|
5206
5264
|
}
|
|
5207
5265
|
// #endregion
|
|
5208
5266
|
// #region Count
|
|
5209
5267
|
makeCountSchema(model) {
|
|
5210
5268
|
return import_zod.z.object({
|
|
5211
5269
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5212
|
-
skip:
|
|
5213
|
-
take:
|
|
5270
|
+
skip: this.makeSkipSchema().optional(),
|
|
5271
|
+
take: this.makeTakeSchema().optional(),
|
|
5214
5272
|
orderBy: this.orArray(this.makeOrderBySchema(model, true, false), true).optional(),
|
|
5215
5273
|
select: this.makeCountAggregateInputSchema(model).optional()
|
|
5216
|
-
}).
|
|
5274
|
+
}).optional();
|
|
5217
5275
|
}
|
|
5218
5276
|
makeCountAggregateInputSchema(model) {
|
|
5219
5277
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -5225,7 +5283,7 @@ var InputValidator = class {
|
|
|
5225
5283
|
acc[field] = import_zod.z.literal(true).optional();
|
|
5226
5284
|
return acc;
|
|
5227
5285
|
}, {})
|
|
5228
|
-
})
|
|
5286
|
+
})
|
|
5229
5287
|
]);
|
|
5230
5288
|
}
|
|
5231
5289
|
// #endregion
|
|
@@ -5233,19 +5291,19 @@ var InputValidator = class {
|
|
|
5233
5291
|
makeAggregateSchema(model) {
|
|
5234
5292
|
return import_zod.z.object({
|
|
5235
5293
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5236
|
-
skip:
|
|
5237
|
-
take:
|
|
5294
|
+
skip: this.makeSkipSchema().optional(),
|
|
5295
|
+
take: this.makeTakeSchema().optional(),
|
|
5238
5296
|
orderBy: this.orArray(this.makeOrderBySchema(model, true, false), true).optional(),
|
|
5239
5297
|
_count: this.makeCountAggregateInputSchema(model).optional(),
|
|
5240
5298
|
_avg: this.makeSumAvgInputSchema(model).optional(),
|
|
5241
5299
|
_sum: this.makeSumAvgInputSchema(model).optional(),
|
|
5242
5300
|
_min: this.makeMinMaxInputSchema(model).optional(),
|
|
5243
5301
|
_max: this.makeMinMaxInputSchema(model).optional()
|
|
5244
|
-
}).
|
|
5302
|
+
}).optional();
|
|
5245
5303
|
}
|
|
5246
5304
|
makeSumAvgInputSchema(model) {
|
|
5247
5305
|
const modelDef = requireModel(this.schema, model);
|
|
5248
|
-
return import_zod.z.
|
|
5306
|
+
return import_zod.z.strictObject(Object.keys(modelDef.fields).reduce((acc, field) => {
|
|
5249
5307
|
const fieldDef = requireField(this.schema, model, field);
|
|
5250
5308
|
if (this.isNumericField(fieldDef)) {
|
|
5251
5309
|
acc[field] = import_zod.z.literal(true).optional();
|
|
@@ -5255,7 +5313,7 @@ var InputValidator = class {
|
|
|
5255
5313
|
}
|
|
5256
5314
|
makeMinMaxInputSchema(model) {
|
|
5257
5315
|
const modelDef = requireModel(this.schema, model);
|
|
5258
|
-
return import_zod.z.
|
|
5316
|
+
return import_zod.z.strictObject(Object.keys(modelDef.fields).reduce((acc, field) => {
|
|
5259
5317
|
const fieldDef = requireField(this.schema, model, field);
|
|
5260
5318
|
if (!fieldDef.relation && !fieldDef.array) {
|
|
5261
5319
|
acc[field] = import_zod.z.literal(true).optional();
|
|
@@ -5271,14 +5329,14 @@ var InputValidator = class {
|
|
|
5271
5329
|
orderBy: this.orArray(this.makeOrderBySchema(model, false, true), true).optional(),
|
|
5272
5330
|
by: this.orArray(import_zod.z.enum(nonRelationFields), true),
|
|
5273
5331
|
having: this.makeWhereSchema(model, false, true).optional(),
|
|
5274
|
-
skip:
|
|
5275
|
-
take:
|
|
5332
|
+
skip: this.makeSkipSchema().optional(),
|
|
5333
|
+
take: this.makeTakeSchema().optional(),
|
|
5276
5334
|
_count: this.makeCountAggregateInputSchema(model).optional(),
|
|
5277
5335
|
_avg: this.makeSumAvgInputSchema(model).optional(),
|
|
5278
5336
|
_sum: this.makeSumAvgInputSchema(model).optional(),
|
|
5279
5337
|
_min: this.makeMinMaxInputSchema(model).optional(),
|
|
5280
5338
|
_max: this.makeMinMaxInputSchema(model).optional()
|
|
5281
|
-
})
|
|
5339
|
+
});
|
|
5282
5340
|
schema = schema.refine((value) => {
|
|
5283
5341
|
const bys = typeof value.by === "string" ? [
|
|
5284
5342
|
value.by
|
|
@@ -5303,6 +5361,12 @@ var InputValidator = class {
|
|
|
5303
5361
|
}
|
|
5304
5362
|
// #endregion
|
|
5305
5363
|
// #region Helpers
|
|
5364
|
+
makeSkipSchema() {
|
|
5365
|
+
return import_zod.z.number().int().nonnegative();
|
|
5366
|
+
}
|
|
5367
|
+
makeTakeSchema() {
|
|
5368
|
+
return import_zod.z.number().int();
|
|
5369
|
+
}
|
|
5306
5370
|
refineForSelectIncludeMutuallyExclusive(schema) {
|
|
5307
5371
|
return schema.refine((value) => !(value["select"] && value["include"]), '"select" and "include" cannot be used together');
|
|
5308
5372
|
}
|
|
@@ -5321,6 +5385,9 @@ var InputValidator = class {
|
|
|
5321
5385
|
isNumericField(fieldDef) {
|
|
5322
5386
|
return NUMERIC_FIELD_TYPES.includes(fieldDef.type) && !fieldDef.array;
|
|
5323
5387
|
}
|
|
5388
|
+
get providerSupportsCaseSensitivity() {
|
|
5389
|
+
return this.schema.provider.type === "postgresql";
|
|
5390
|
+
}
|
|
5324
5391
|
};
|
|
5325
5392
|
|
|
5326
5393
|
// src/client/executor/zenstack-driver.ts
|