@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.js
CHANGED
|
@@ -199,23 +199,23 @@ function getRelationForeignKeyFieldPairs(schema, model, relationField) {
|
|
|
199
199
|
}
|
|
200
200
|
__name(getRelationForeignKeyFieldPairs, "getRelationForeignKeyFieldPairs");
|
|
201
201
|
function isScalarField(schema, model, field) {
|
|
202
|
-
const fieldDef =
|
|
203
|
-
return !fieldDef
|
|
202
|
+
const fieldDef = getField(schema, model, field);
|
|
203
|
+
return !fieldDef?.relation && !fieldDef?.foreignKeyFor;
|
|
204
204
|
}
|
|
205
205
|
__name(isScalarField, "isScalarField");
|
|
206
206
|
function isForeignKeyField(schema, model, field) {
|
|
207
|
-
const fieldDef =
|
|
208
|
-
return !!fieldDef
|
|
207
|
+
const fieldDef = getField(schema, model, field);
|
|
208
|
+
return !!fieldDef?.foreignKeyFor;
|
|
209
209
|
}
|
|
210
210
|
__name(isForeignKeyField, "isForeignKeyField");
|
|
211
211
|
function isRelationField(schema, model, field) {
|
|
212
|
-
const fieldDef =
|
|
213
|
-
return !!fieldDef
|
|
212
|
+
const fieldDef = getField(schema, model, field);
|
|
213
|
+
return !!fieldDef?.relation;
|
|
214
214
|
}
|
|
215
215
|
__name(isRelationField, "isRelationField");
|
|
216
216
|
function isInheritedField(schema, model, field) {
|
|
217
|
-
const fieldDef =
|
|
218
|
-
return !!fieldDef
|
|
217
|
+
const fieldDef = getField(schema, model, field);
|
|
218
|
+
return !!fieldDef?.originModel;
|
|
219
219
|
}
|
|
220
220
|
__name(isInheritedField, "isInheritedField");
|
|
221
221
|
function getUniqueFields(schema, model) {
|
|
@@ -696,7 +696,7 @@ var BaseCrudDialect = class {
|
|
|
696
696
|
buildLiteralFilter(eb, lhs, type, rhs) {
|
|
697
697
|
return eb(lhs, "=", rhs !== null && rhs !== void 0 ? this.transformPrimitive(rhs, type, false) : rhs);
|
|
698
698
|
}
|
|
699
|
-
buildStandardFilter(eb, type, payload, lhs, getRhs, recurse, throwIfInvalid = false, onlyForKeys = void 0) {
|
|
699
|
+
buildStandardFilter(eb, type, payload, lhs, getRhs, recurse, throwIfInvalid = false, onlyForKeys = void 0, excludeKeys = []) {
|
|
700
700
|
if (payload === null || !isPlainObject(payload)) {
|
|
701
701
|
return {
|
|
702
702
|
conditions: [
|
|
@@ -711,6 +711,9 @@ var BaseCrudDialect = class {
|
|
|
711
711
|
if (onlyForKeys && !onlyForKeys.includes(op)) {
|
|
712
712
|
continue;
|
|
713
713
|
}
|
|
714
|
+
if (excludeKeys.includes(op)) {
|
|
715
|
+
continue;
|
|
716
|
+
}
|
|
714
717
|
const rhs = Array.isArray(value) ? value.map(getRhs) : getRhs(value);
|
|
715
718
|
const condition = match(op).with("equals", () => rhs === null ? eb(lhs, "is", null) : eb(lhs, "=", rhs)).with("in", () => {
|
|
716
719
|
invariant(Array.isArray(rhs), "right hand side must be an array");
|
|
@@ -744,21 +747,20 @@ var BaseCrudDialect = class {
|
|
|
744
747
|
};
|
|
745
748
|
}
|
|
746
749
|
buildStringFilter(eb, fieldRef, payload) {
|
|
747
|
-
let
|
|
748
|
-
if (payload && typeof payload === "object" && "mode" in payload
|
|
749
|
-
|
|
750
|
-
fieldRef = eb.fn("lower", [
|
|
751
|
-
fieldRef
|
|
752
|
-
]);
|
|
750
|
+
let mode;
|
|
751
|
+
if (payload && typeof payload === "object" && "mode" in payload) {
|
|
752
|
+
mode = payload.mode;
|
|
753
753
|
}
|
|
754
|
-
const { conditions, consumedKeys } = this.buildStandardFilter(eb, "String", payload,
|
|
754
|
+
const { conditions, consumedKeys } = this.buildStandardFilter(eb, "String", payload, mode === "insensitive" ? eb.fn("lower", [
|
|
755
|
+
fieldRef
|
|
756
|
+
]) : fieldRef, (value) => this.prepStringCasing(eb, value, mode), (value) => this.buildStringFilter(eb, fieldRef, value));
|
|
755
757
|
if (payload && typeof payload === "object") {
|
|
756
758
|
for (const [key, value] of Object.entries(payload)) {
|
|
757
759
|
if (key === "mode" || consumedKeys.includes(key)) {
|
|
758
760
|
continue;
|
|
759
761
|
}
|
|
760
|
-
const condition = match(key).with("contains", () => insensitive ? eb(fieldRef, "ilike", sql.
|
|
761
|
-
throw new
|
|
762
|
+
const condition = match(key).with("contains", () => mode === "insensitive" ? eb(fieldRef, "ilike", sql.val(`%${value}%`)) : eb(fieldRef, "like", sql.val(`%${value}%`))).with("startsWith", () => mode === "insensitive" ? eb(fieldRef, "ilike", sql.val(`${value}%`)) : eb(fieldRef, "like", sql.val(`${value}%`))).with("endsWith", () => mode === "insensitive" ? eb(fieldRef, "ilike", sql.val(`%${value}`)) : eb(fieldRef, "like", sql.val(`%${value}`))).otherwise(() => {
|
|
763
|
+
throw new QueryError(`Invalid string filter key: ${key}`);
|
|
762
764
|
});
|
|
763
765
|
if (condition) {
|
|
764
766
|
conditions.push(condition);
|
|
@@ -767,15 +769,18 @@ var BaseCrudDialect = class {
|
|
|
767
769
|
}
|
|
768
770
|
return this.and(eb, ...conditions);
|
|
769
771
|
}
|
|
770
|
-
prepStringCasing(eb, value,
|
|
772
|
+
prepStringCasing(eb, value, mode) {
|
|
773
|
+
if (!mode || mode === "default") {
|
|
774
|
+
return value === null ? value : sql.val(value);
|
|
775
|
+
}
|
|
771
776
|
if (typeof value === "string") {
|
|
772
|
-
return
|
|
773
|
-
sql.
|
|
774
|
-
])
|
|
777
|
+
return eb.fn("lower", [
|
|
778
|
+
sql.val(value)
|
|
779
|
+
]);
|
|
775
780
|
} else if (Array.isArray(value)) {
|
|
776
|
-
return value.map((v) => this.prepStringCasing(eb, v,
|
|
781
|
+
return value.map((v) => this.prepStringCasing(eb, v, mode));
|
|
777
782
|
} else {
|
|
778
|
-
return value === null ? null : sql.
|
|
783
|
+
return value === null ? null : sql.val(value);
|
|
779
784
|
}
|
|
780
785
|
}
|
|
781
786
|
buildNumberFilter(eb, fieldRef, type, payload) {
|
|
@@ -937,6 +942,32 @@ var BaseCrudDialect = class {
|
|
|
937
942
|
});
|
|
938
943
|
return query;
|
|
939
944
|
}
|
|
945
|
+
buildCountJson(model, eb, parentAlias, payload) {
|
|
946
|
+
const modelDef = requireModel(this.schema, model);
|
|
947
|
+
const toManyRelations = Object.entries(modelDef.fields).filter(([, field]) => field.relation && field.array);
|
|
948
|
+
const selections = payload === true ? {
|
|
949
|
+
select: toManyRelations.reduce((acc, [field]) => {
|
|
950
|
+
acc[field] = true;
|
|
951
|
+
return acc;
|
|
952
|
+
}, {})
|
|
953
|
+
} : payload;
|
|
954
|
+
const jsonObject = {};
|
|
955
|
+
for (const [field, value] of Object.entries(selections.select)) {
|
|
956
|
+
const fieldDef = requireField(this.schema, model, field);
|
|
957
|
+
const fieldModel = fieldDef.type;
|
|
958
|
+
const joinPairs = buildJoinPairs(this.schema, model, parentAlias, field, fieldModel);
|
|
959
|
+
let fieldCountQuery = eb.selectFrom(fieldModel).select(eb.fn.countAll().as(`_count$${field}`));
|
|
960
|
+
for (const [left, right] of joinPairs) {
|
|
961
|
+
fieldCountQuery = fieldCountQuery.whereRef(left, "=", right);
|
|
962
|
+
}
|
|
963
|
+
if (value && typeof value === "object" && "where" in value && value.where && typeof value.where === "object") {
|
|
964
|
+
const filter = this.buildFilter(eb, fieldModel, fieldModel, value.where);
|
|
965
|
+
fieldCountQuery = fieldCountQuery.where(filter);
|
|
966
|
+
}
|
|
967
|
+
jsonObject[field] = fieldCountQuery;
|
|
968
|
+
}
|
|
969
|
+
return this.buildJsonObject(eb, jsonObject);
|
|
970
|
+
}
|
|
940
971
|
// #endregion
|
|
941
972
|
// #region utils
|
|
942
973
|
negateSort(sort, negated) {
|
|
@@ -1065,7 +1096,7 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
|
|
|
1065
1096
|
});
|
|
1066
1097
|
return qb;
|
|
1067
1098
|
}
|
|
1068
|
-
buildRelationObjectArgs(relationModel, relationField, eb, payload,
|
|
1099
|
+
buildRelationObjectArgs(relationModel, relationField, eb, payload, parentAlias) {
|
|
1069
1100
|
const relationModelDef = requireModel(this.schema, relationModel);
|
|
1070
1101
|
const objArgs = [];
|
|
1071
1102
|
const descendantModels = getDelegateDescendantModels(this.schema, relationModel);
|
|
@@ -1081,20 +1112,28 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
|
|
|
1081
1112
|
buildFieldRef(this.schema, relationModel, field, this.options, eb)
|
|
1082
1113
|
]).flatMap((v) => v));
|
|
1083
1114
|
} else if (payload.select) {
|
|
1084
|
-
objArgs.push(...Object.entries(payload.select).filter(([, value]) => value).map(([field]) => {
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1115
|
+
objArgs.push(...Object.entries(payload.select).filter(([, value]) => value).map(([field, value]) => {
|
|
1116
|
+
if (field === "_count") {
|
|
1117
|
+
const subJson = this.buildCountJson(relationModel, eb, `${parentAlias}$${relationField}`, value);
|
|
1118
|
+
return [
|
|
1119
|
+
sql2.lit(field),
|
|
1120
|
+
subJson
|
|
1121
|
+
];
|
|
1122
|
+
} else {
|
|
1123
|
+
const fieldDef = requireField(this.schema, relationModel, field);
|
|
1124
|
+
const fieldValue = fieldDef.relation ? eb.ref(`${parentAlias}$${relationField}$${field}.$j`) : buildFieldRef(this.schema, relationModel, field, this.options, eb);
|
|
1125
|
+
return [
|
|
1126
|
+
sql2.lit(field),
|
|
1127
|
+
fieldValue
|
|
1128
|
+
];
|
|
1129
|
+
}
|
|
1091
1130
|
}).flatMap((v) => v));
|
|
1092
1131
|
}
|
|
1093
1132
|
if (typeof payload === "object" && payload.include && typeof payload.include === "object") {
|
|
1094
1133
|
objArgs.push(...Object.entries(payload.include).filter(([, value]) => value).map(([field]) => [
|
|
1095
1134
|
sql2.lit(field),
|
|
1096
1135
|
// reference the synthesized JSON field
|
|
1097
|
-
eb.ref(`${
|
|
1136
|
+
eb.ref(`${parentAlias}$${relationField}$${field}.$j`)
|
|
1098
1137
|
]).flatMap((v) => v));
|
|
1099
1138
|
}
|
|
1100
1139
|
return objArgs;
|
|
@@ -1180,11 +1219,11 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
1180
1219
|
buildRelationSelection(query, model, relationField, parentAlias, payload) {
|
|
1181
1220
|
return query.select((eb) => this.buildRelationJSON(model, eb, relationField, parentAlias, payload).as(relationField));
|
|
1182
1221
|
}
|
|
1183
|
-
buildRelationJSON(model, eb, relationField,
|
|
1222
|
+
buildRelationJSON(model, eb, relationField, parentAlias, payload) {
|
|
1184
1223
|
const relationFieldDef = requireField(this.schema, model, relationField);
|
|
1185
1224
|
const relationModel = relationFieldDef.type;
|
|
1186
1225
|
const relationModelDef = requireModel(this.schema, relationModel);
|
|
1187
|
-
const subQueryName = `${
|
|
1226
|
+
const subQueryName = `${parentAlias}$${relationField}`;
|
|
1188
1227
|
let tbl = eb.selectFrom(() => {
|
|
1189
1228
|
let subQuery = this.buildSelectModel(eb, relationModel);
|
|
1190
1229
|
subQuery = this.buildSelectAllFields(relationModel, subQuery, typeof payload === "object" ? payload?.omit : void 0);
|
|
@@ -1208,14 +1247,14 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
1208
1247
|
const relationIds = getIdFields(this.schema, relationModel);
|
|
1209
1248
|
invariant3(parentIds.length === 1, "many-to-many relation must have exactly one id field");
|
|
1210
1249
|
invariant3(relationIds.length === 1, "many-to-many relation must have exactly one id field");
|
|
1211
|
-
subQuery = subQuery.where(eb(eb.ref(`${relationModel}.${relationIds[0]}`), "in", eb.selectFrom(m2m.joinTable).select(`${m2m.joinTable}.${m2m.otherFkName}`).whereRef(`${
|
|
1250
|
+
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}`)));
|
|
1212
1251
|
} else {
|
|
1213
1252
|
const { keyPairs, ownedByModel } = getRelationForeignKeyFieldPairs(this.schema, model, relationField);
|
|
1214
1253
|
keyPairs.forEach(({ fk, pk }) => {
|
|
1215
1254
|
if (ownedByModel) {
|
|
1216
|
-
subQuery = subQuery.whereRef(`${relationModel}.${pk}`, "=", `${
|
|
1255
|
+
subQuery = subQuery.whereRef(`${relationModel}.${pk}`, "=", `${parentAlias}.${fk}`);
|
|
1217
1256
|
} else {
|
|
1218
|
-
subQuery = subQuery.whereRef(`${relationModel}.${fk}`, "=", `${
|
|
1257
|
+
subQuery = subQuery.whereRef(`${relationModel}.${fk}`, "=", `${parentAlias}.${pk}`);
|
|
1219
1258
|
}
|
|
1220
1259
|
});
|
|
1221
1260
|
}
|
|
@@ -1237,24 +1276,32 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
1237
1276
|
]).flatMap((v) => v));
|
|
1238
1277
|
} else if (payload.select) {
|
|
1239
1278
|
objArgs.push(...Object.entries(payload.select).filter(([, value]) => value).map(([field, value]) => {
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
const subJson = this.buildRelationJSON(relationModel, eb, field, `${parentName}$${relationField}`, value);
|
|
1279
|
+
if (field === "_count") {
|
|
1280
|
+
const subJson = this.buildCountJson(relationModel, eb, `${parentAlias}$${relationField}`, value);
|
|
1243
1281
|
return [
|
|
1244
1282
|
sql3.lit(field),
|
|
1245
1283
|
subJson
|
|
1246
1284
|
];
|
|
1247
1285
|
} else {
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1286
|
+
const fieldDef = requireField(this.schema, relationModel, field);
|
|
1287
|
+
if (fieldDef.relation) {
|
|
1288
|
+
const subJson = this.buildRelationJSON(relationModel, eb, field, `${parentAlias}$${relationField}`, value);
|
|
1289
|
+
return [
|
|
1290
|
+
sql3.lit(field),
|
|
1291
|
+
subJson
|
|
1292
|
+
];
|
|
1293
|
+
} else {
|
|
1294
|
+
return [
|
|
1295
|
+
sql3.lit(field),
|
|
1296
|
+
buildFieldRef(this.schema, relationModel, field, this.options, eb)
|
|
1297
|
+
];
|
|
1298
|
+
}
|
|
1252
1299
|
}
|
|
1253
1300
|
}).flatMap((v) => v));
|
|
1254
1301
|
}
|
|
1255
1302
|
if (typeof payload === "object" && payload.include && typeof payload.include === "object") {
|
|
1256
1303
|
objArgs.push(...Object.entries(payload.include).filter(([, value]) => value).map(([field, value]) => {
|
|
1257
|
-
const subJson = this.buildRelationJSON(relationModel, eb, field, `${
|
|
1304
|
+
const subJson = this.buildRelationJSON(relationModel, eb, field, `${parentAlias}$${relationField}`, value);
|
|
1258
1305
|
return [
|
|
1259
1306
|
sql3.lit(field),
|
|
1260
1307
|
subJson
|
|
@@ -2666,6 +2713,7 @@ var BaseOperationHandler = class {
|
|
|
2666
2713
|
query = query.distinctOn(distinct.map((f) => sql4.ref(`${model}.${f}`)));
|
|
2667
2714
|
} else {
|
|
2668
2715
|
inMemoryDistinct = distinct;
|
|
2716
|
+
query = distinct.reduce((acc, field) => acc.select((eb) => buildFieldRef(this.schema, model, field, this.options, eb).as(`$distinct$${field}`)), query);
|
|
2669
2717
|
}
|
|
2670
2718
|
}
|
|
2671
2719
|
if (args && "select" in args && args.select) {
|
|
@@ -2703,13 +2751,16 @@ ${compiled.parameters.map((p) => inspect(p)).join("\n")}`;
|
|
|
2703
2751
|
const distinctResult = [];
|
|
2704
2752
|
const seen = /* @__PURE__ */ new Set();
|
|
2705
2753
|
for (const r of result) {
|
|
2706
|
-
const key = safeJSONStringify(inMemoryDistinct.map((f) => r[f]));
|
|
2754
|
+
const key = safeJSONStringify(inMemoryDistinct.map((f) => r[`$distinct$${f}`]));
|
|
2707
2755
|
if (!seen.has(key)) {
|
|
2708
2756
|
distinctResult.push(r);
|
|
2709
2757
|
seen.add(key);
|
|
2710
2758
|
}
|
|
2711
2759
|
}
|
|
2712
2760
|
result = distinctResult;
|
|
2761
|
+
for (const r of result) {
|
|
2762
|
+
Object.keys(r).filter((k) => k.startsWith("$distinct$")).forEach((k) => delete r[k]);
|
|
2763
|
+
}
|
|
2713
2764
|
}
|
|
2714
2765
|
return result;
|
|
2715
2766
|
}
|
|
@@ -2747,32 +2798,7 @@ ${compiled.parameters.map((p) => inspect(p)).join("\n")}`;
|
|
|
2747
2798
|
return result;
|
|
2748
2799
|
}
|
|
2749
2800
|
buildCountSelection(query, model, parentAlias, payload) {
|
|
2750
|
-
|
|
2751
|
-
const toManyRelations = Object.entries(modelDef.fields).filter(([, field]) => field.relation && field.array);
|
|
2752
|
-
const selections = payload === true ? {
|
|
2753
|
-
select: toManyRelations.reduce((acc, [field]) => {
|
|
2754
|
-
acc[field] = true;
|
|
2755
|
-
return acc;
|
|
2756
|
-
}, {})
|
|
2757
|
-
} : payload;
|
|
2758
|
-
const eb = expressionBuilder2();
|
|
2759
|
-
const jsonObject = {};
|
|
2760
|
-
for (const [field, value] of Object.entries(selections.select)) {
|
|
2761
|
-
const fieldDef = requireField(this.schema, model, field);
|
|
2762
|
-
const fieldModel = fieldDef.type;
|
|
2763
|
-
const joinPairs = buildJoinPairs(this.schema, model, parentAlias, field, fieldModel);
|
|
2764
|
-
let fieldCountQuery = eb.selectFrom(fieldModel).select(eb.fn.countAll().as(`_count$${field}`));
|
|
2765
|
-
for (const [left, right] of joinPairs) {
|
|
2766
|
-
fieldCountQuery = fieldCountQuery.whereRef(left, "=", right);
|
|
2767
|
-
}
|
|
2768
|
-
if (value && typeof value === "object" && "where" in value && value.where && typeof value.where === "object") {
|
|
2769
|
-
const filter = this.dialect.buildFilter(eb, fieldModel, fieldModel, value.where);
|
|
2770
|
-
fieldCountQuery = fieldCountQuery.where(filter);
|
|
2771
|
-
}
|
|
2772
|
-
jsonObject[field] = fieldCountQuery;
|
|
2773
|
-
}
|
|
2774
|
-
query = query.select((eb2) => this.dialect.buildJsonObject(eb2, jsonObject).as("_count"));
|
|
2775
|
-
return query;
|
|
2801
|
+
return query.select((eb) => this.dialect.buildCountJson(model, eb, parentAlias, payload).as("_count"));
|
|
2776
2802
|
}
|
|
2777
2803
|
buildCursorFilter(model, query, cursor, orderBy, negateOrderBy) {
|
|
2778
2804
|
if (!orderBy) {
|
|
@@ -4498,11 +4524,11 @@ var InputValidator = class {
|
|
|
4498
4524
|
fields["distinct"] = this.makeDistinctSchema(model).optional();
|
|
4499
4525
|
fields["cursor"] = this.makeCursorSchema(model).optional();
|
|
4500
4526
|
if (options.collection) {
|
|
4501
|
-
fields["skip"] =
|
|
4502
|
-
fields["take"] =
|
|
4527
|
+
fields["skip"] = this.makeSkipSchema().optional();
|
|
4528
|
+
fields["take"] = this.makeTakeSchema().optional();
|
|
4503
4529
|
fields["orderBy"] = this.orArray(this.makeOrderBySchema(model, true, false), true).optional();
|
|
4504
4530
|
}
|
|
4505
|
-
let result = z.
|
|
4531
|
+
let result = z.strictObject(fields);
|
|
4506
4532
|
result = this.refineForSelectIncludeMutuallyExclusive(result);
|
|
4507
4533
|
result = this.refineForSelectOmitMutuallyExclusive(result);
|
|
4508
4534
|
if (!options.unique) {
|
|
@@ -4569,7 +4595,7 @@ var InputValidator = class {
|
|
|
4569
4595
|
if (fieldDef.array) {
|
|
4570
4596
|
fieldSchema = z.union([
|
|
4571
4597
|
fieldSchema,
|
|
4572
|
-
z.
|
|
4598
|
+
z.strictObject({
|
|
4573
4599
|
some: fieldSchema.optional(),
|
|
4574
4600
|
every: fieldSchema.optional(),
|
|
4575
4601
|
none: fieldSchema.optional()
|
|
@@ -4578,7 +4604,7 @@ var InputValidator = class {
|
|
|
4578
4604
|
} else {
|
|
4579
4605
|
fieldSchema = z.union([
|
|
4580
4606
|
fieldSchema,
|
|
4581
|
-
z.
|
|
4607
|
+
z.strictObject({
|
|
4582
4608
|
is: fieldSchema.optional(),
|
|
4583
4609
|
isNot: fieldSchema.optional()
|
|
4584
4610
|
})
|
|
@@ -4629,7 +4655,7 @@ var InputValidator = class {
|
|
|
4629
4655
|
fields["AND"] = this.orArray(z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
|
|
4630
4656
|
fields["OR"] = z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)).array().optional();
|
|
4631
4657
|
fields["NOT"] = this.orArray(z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
|
|
4632
|
-
const baseWhere = z.
|
|
4658
|
+
const baseWhere = z.strictObject(fields);
|
|
4633
4659
|
let result = baseWhere;
|
|
4634
4660
|
if (unique) {
|
|
4635
4661
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
@@ -4653,7 +4679,7 @@ var InputValidator = class {
|
|
|
4653
4679
|
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z.lazy(() => this.makeEnumFilterSchema(enumDef, optional)));
|
|
4654
4680
|
return z.union([
|
|
4655
4681
|
this.nullableIf(baseSchema, optional),
|
|
4656
|
-
z.
|
|
4682
|
+
z.strictObject({
|
|
4657
4683
|
equals: components.equals,
|
|
4658
4684
|
in: components.in,
|
|
4659
4685
|
notIn: components.notIn,
|
|
@@ -4662,7 +4688,7 @@ var InputValidator = class {
|
|
|
4662
4688
|
]);
|
|
4663
4689
|
}
|
|
4664
4690
|
makeArrayFilterSchema(type) {
|
|
4665
|
-
return z.
|
|
4691
|
+
return z.strictObject({
|
|
4666
4692
|
equals: this.makePrimitiveSchema(type).array().optional(),
|
|
4667
4693
|
has: this.makePrimitiveSchema(type).optional(),
|
|
4668
4694
|
hasEvery: this.makePrimitiveSchema(type).array().optional(),
|
|
@@ -4688,7 +4714,7 @@ var InputValidator = class {
|
|
|
4688
4714
|
makeBooleanFilterSchema(optional) {
|
|
4689
4715
|
return z.union([
|
|
4690
4716
|
this.nullableIf(z.boolean(), optional),
|
|
4691
|
-
z.
|
|
4717
|
+
z.strictObject({
|
|
4692
4718
|
equals: this.nullableIf(z.boolean(), optional).optional(),
|
|
4693
4719
|
not: z.lazy(() => this.makeBooleanFilterSchema(optional)).optional()
|
|
4694
4720
|
})
|
|
@@ -4699,7 +4725,7 @@ var InputValidator = class {
|
|
|
4699
4725
|
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z.instanceof(Uint8Array));
|
|
4700
4726
|
return z.union([
|
|
4701
4727
|
this.nullableIf(baseSchema, optional),
|
|
4702
|
-
z.
|
|
4728
|
+
z.strictObject({
|
|
4703
4729
|
equals: components.equals,
|
|
4704
4730
|
in: components.in,
|
|
4705
4731
|
notIn: components.notIn,
|
|
@@ -4723,14 +4749,31 @@ var InputValidator = class {
|
|
|
4723
4749
|
makeCommonPrimitiveFilterSchema(baseSchema, optional, makeThis) {
|
|
4724
4750
|
return z.union([
|
|
4725
4751
|
this.nullableIf(baseSchema, optional),
|
|
4726
|
-
z.
|
|
4752
|
+
z.strictObject(this.makeCommonPrimitiveFilterComponents(baseSchema, optional, makeThis))
|
|
4727
4753
|
]);
|
|
4728
4754
|
}
|
|
4729
4755
|
makeNumberFilterSchema(baseSchema, optional) {
|
|
4730
4756
|
return this.makeCommonPrimitiveFilterSchema(baseSchema, optional, () => z.lazy(() => this.makeNumberFilterSchema(baseSchema, optional)));
|
|
4731
4757
|
}
|
|
4732
4758
|
makeStringFilterSchema(optional) {
|
|
4733
|
-
return
|
|
4759
|
+
return z.union([
|
|
4760
|
+
this.nullableIf(z.string(), optional),
|
|
4761
|
+
z.strictObject({
|
|
4762
|
+
...this.makeCommonPrimitiveFilterComponents(z.string(), optional, () => z.lazy(() => this.makeStringFilterSchema(optional))),
|
|
4763
|
+
startsWith: z.string().optional(),
|
|
4764
|
+
endsWith: z.string().optional(),
|
|
4765
|
+
contains: z.string().optional(),
|
|
4766
|
+
...this.providerSupportsCaseSensitivity ? {
|
|
4767
|
+
mode: this.makeStringModeSchema().optional()
|
|
4768
|
+
} : {}
|
|
4769
|
+
})
|
|
4770
|
+
]);
|
|
4771
|
+
}
|
|
4772
|
+
makeStringModeSchema() {
|
|
4773
|
+
return z.union([
|
|
4774
|
+
z.literal("default"),
|
|
4775
|
+
z.literal("insensitive")
|
|
4776
|
+
]);
|
|
4734
4777
|
}
|
|
4735
4778
|
makeSelectSchema(model) {
|
|
4736
4779
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -4740,7 +4783,7 @@ var InputValidator = class {
|
|
|
4740
4783
|
if (fieldDef.relation) {
|
|
4741
4784
|
fields[field] = z.union([
|
|
4742
4785
|
z.literal(true),
|
|
4743
|
-
z.
|
|
4786
|
+
z.strictObject({
|
|
4744
4787
|
select: z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional(),
|
|
4745
4788
|
include: z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional()
|
|
4746
4789
|
})
|
|
@@ -4749,22 +4792,24 @@ var InputValidator = class {
|
|
|
4749
4792
|
fields[field] = z.boolean().optional();
|
|
4750
4793
|
}
|
|
4751
4794
|
}
|
|
4752
|
-
const toManyRelations = Object.
|
|
4795
|
+
const toManyRelations = Object.values(modelDef.fields).filter((def) => def.relation && def.array);
|
|
4753
4796
|
if (toManyRelations.length > 0) {
|
|
4754
4797
|
fields["_count"] = z.union([
|
|
4755
4798
|
z.literal(true),
|
|
4756
|
-
z.
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
z.
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
|
|
4799
|
+
z.strictObject({
|
|
4800
|
+
select: z.strictObject(toManyRelations.reduce((acc, fieldDef) => ({
|
|
4801
|
+
...acc,
|
|
4802
|
+
[fieldDef.name]: z.union([
|
|
4803
|
+
z.boolean(),
|
|
4804
|
+
z.strictObject({
|
|
4805
|
+
where: this.makeWhereSchema(fieldDef.type, false, false)
|
|
4806
|
+
})
|
|
4807
|
+
]).optional()
|
|
4808
|
+
}), {}))
|
|
4809
|
+
})
|
|
4765
4810
|
]).optional();
|
|
4766
4811
|
}
|
|
4767
|
-
return z.
|
|
4812
|
+
return z.strictObject(fields);
|
|
4768
4813
|
}
|
|
4769
4814
|
makeOmitSchema(model) {
|
|
4770
4815
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -4775,7 +4820,7 @@ var InputValidator = class {
|
|
|
4775
4820
|
fields[field] = z.boolean().optional();
|
|
4776
4821
|
}
|
|
4777
4822
|
}
|
|
4778
|
-
return z.
|
|
4823
|
+
return z.strictObject(fields);
|
|
4779
4824
|
}
|
|
4780
4825
|
makeIncludeSchema(model) {
|
|
4781
4826
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -4785,15 +4830,20 @@ var InputValidator = class {
|
|
|
4785
4830
|
if (fieldDef.relation) {
|
|
4786
4831
|
fields[field] = z.union([
|
|
4787
4832
|
z.literal(true),
|
|
4788
|
-
z.
|
|
4833
|
+
z.strictObject({
|
|
4789
4834
|
select: z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional(),
|
|
4790
4835
|
include: z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional(),
|
|
4791
|
-
|
|
4836
|
+
omit: z.lazy(() => this.makeOmitSchema(fieldDef.type)).optional(),
|
|
4837
|
+
where: z.lazy(() => this.makeWhereSchema(fieldDef.type, false)).optional(),
|
|
4838
|
+
orderBy: z.lazy(() => this.makeOrderBySchema(fieldDef.type, true, false)).optional(),
|
|
4839
|
+
skip: this.makeSkipSchema().optional(),
|
|
4840
|
+
take: this.makeTakeSchema().optional(),
|
|
4841
|
+
distinct: this.makeDistinctSchema(fieldDef.type).optional()
|
|
4792
4842
|
})
|
|
4793
4843
|
]).optional();
|
|
4794
4844
|
}
|
|
4795
4845
|
}
|
|
4796
|
-
return z.
|
|
4846
|
+
return z.strictObject(fields);
|
|
4797
4847
|
}
|
|
4798
4848
|
makeOrderBySchema(model, withRelation, WithAggregation) {
|
|
4799
4849
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -4806,13 +4856,21 @@ var InputValidator = class {
|
|
|
4806
4856
|
const fieldDef = requireField(this.schema, model, field);
|
|
4807
4857
|
if (fieldDef.relation) {
|
|
4808
4858
|
if (withRelation) {
|
|
4809
|
-
fields[field] = z.lazy(() =>
|
|
4859
|
+
fields[field] = z.lazy(() => {
|
|
4860
|
+
let relationOrderBy = this.makeOrderBySchema(fieldDef.type, withRelation, WithAggregation);
|
|
4861
|
+
if (fieldDef.array) {
|
|
4862
|
+
relationOrderBy = relationOrderBy.extend({
|
|
4863
|
+
_count: sort
|
|
4864
|
+
});
|
|
4865
|
+
}
|
|
4866
|
+
return relationOrderBy.optional();
|
|
4867
|
+
});
|
|
4810
4868
|
}
|
|
4811
4869
|
} else {
|
|
4812
4870
|
if (fieldDef.optional) {
|
|
4813
4871
|
fields[field] = z.union([
|
|
4814
4872
|
sort,
|
|
4815
|
-
z.
|
|
4873
|
+
z.strictObject({
|
|
4816
4874
|
sort,
|
|
4817
4875
|
nulls: z.union([
|
|
4818
4876
|
z.literal("first"),
|
|
@@ -4837,7 +4895,7 @@ var InputValidator = class {
|
|
|
4837
4895
|
fields[agg] = z.lazy(() => this.makeOrderBySchema(model, true, false).optional());
|
|
4838
4896
|
}
|
|
4839
4897
|
}
|
|
4840
|
-
return z.
|
|
4898
|
+
return z.strictObject(fields);
|
|
4841
4899
|
}
|
|
4842
4900
|
makeDistinctSchema(model) {
|
|
4843
4901
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -4856,7 +4914,7 @@ var InputValidator = class {
|
|
|
4856
4914
|
select: this.makeSelectSchema(model).optional(),
|
|
4857
4915
|
include: this.makeIncludeSchema(model).optional(),
|
|
4858
4916
|
omit: this.makeOmitSchema(model).optional()
|
|
4859
|
-
})
|
|
4917
|
+
});
|
|
4860
4918
|
return this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
4861
4919
|
}
|
|
4862
4920
|
makeCreateManySchema(model) {
|
|
@@ -4864,7 +4922,7 @@ var InputValidator = class {
|
|
|
4864
4922
|
}
|
|
4865
4923
|
makeCreateManyAndReturnSchema(model) {
|
|
4866
4924
|
const base = this.makeCreateManyDataSchema(model, []);
|
|
4867
|
-
const result = base.merge(z.
|
|
4925
|
+
const result = base.merge(z.strictObject({
|
|
4868
4926
|
select: this.makeSelectSchema(model).optional(),
|
|
4869
4927
|
omit: this.makeOmitSchema(model).optional()
|
|
4870
4928
|
}));
|
|
@@ -4926,7 +4984,7 @@ var InputValidator = class {
|
|
|
4926
4984
|
if (fieldDef.array) {
|
|
4927
4985
|
fieldSchema = z.union([
|
|
4928
4986
|
z.array(fieldSchema),
|
|
4929
|
-
z.
|
|
4987
|
+
z.strictObject({
|
|
4930
4988
|
set: z.array(fieldSchema)
|
|
4931
4989
|
})
|
|
4932
4990
|
]).optional();
|
|
@@ -4944,16 +5002,16 @@ var InputValidator = class {
|
|
|
4944
5002
|
}
|
|
4945
5003
|
});
|
|
4946
5004
|
if (!hasRelation) {
|
|
4947
|
-
return this.orArray(z.
|
|
5005
|
+
return this.orArray(z.strictObject(uncheckedVariantFields), canBeArray);
|
|
4948
5006
|
} else {
|
|
4949
5007
|
return z.union([
|
|
4950
|
-
z.
|
|
4951
|
-
z.
|
|
5008
|
+
z.strictObject(uncheckedVariantFields),
|
|
5009
|
+
z.strictObject(checkedVariantFields),
|
|
4952
5010
|
...canBeArray ? [
|
|
4953
|
-
z.array(z.
|
|
5011
|
+
z.array(z.strictObject(uncheckedVariantFields))
|
|
4954
5012
|
] : [],
|
|
4955
5013
|
...canBeArray ? [
|
|
4956
|
-
z.array(z.
|
|
5014
|
+
z.array(z.strictObject(checkedVariantFields))
|
|
4957
5015
|
] : []
|
|
4958
5016
|
]);
|
|
4959
5017
|
}
|
|
@@ -4981,31 +5039,31 @@ var InputValidator = class {
|
|
|
4981
5039
|
fields["disconnect"] = this.makeDisconnectDataSchema(fieldType, array).optional();
|
|
4982
5040
|
fields["delete"] = this.makeDeleteRelationDataSchema(fieldType, array, true).optional();
|
|
4983
5041
|
}
|
|
4984
|
-
fields["update"] = array ? this.orArray(z.
|
|
5042
|
+
fields["update"] = array ? this.orArray(z.strictObject({
|
|
4985
5043
|
where: this.makeWhereSchema(fieldType, true),
|
|
4986
5044
|
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
4987
5045
|
}), true).optional() : z.union([
|
|
4988
|
-
z.
|
|
5046
|
+
z.strictObject({
|
|
4989
5047
|
where: this.makeWhereSchema(fieldType, true),
|
|
4990
5048
|
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
4991
5049
|
}),
|
|
4992
5050
|
this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
4993
5051
|
]).optional();
|
|
4994
|
-
fields["upsert"] = this.orArray(z.
|
|
5052
|
+
fields["upsert"] = this.orArray(z.strictObject({
|
|
4995
5053
|
where: this.makeWhereSchema(fieldType, true),
|
|
4996
5054
|
create: this.makeCreateDataSchema(fieldType, false, withoutFields),
|
|
4997
5055
|
update: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
4998
5056
|
}), true).optional();
|
|
4999
5057
|
if (array) {
|
|
5000
5058
|
fields["set"] = this.makeSetDataSchema(fieldType, true).optional();
|
|
5001
|
-
fields["updateMany"] = this.orArray(z.
|
|
5059
|
+
fields["updateMany"] = this.orArray(z.strictObject({
|
|
5002
5060
|
where: this.makeWhereSchema(fieldType, false, true),
|
|
5003
5061
|
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
5004
5062
|
}), true).optional();
|
|
5005
5063
|
fields["deleteMany"] = this.makeDeleteRelationDataSchema(fieldType, true, false).optional();
|
|
5006
5064
|
}
|
|
5007
5065
|
}
|
|
5008
|
-
return z.
|
|
5066
|
+
return z.strictObject(fields);
|
|
5009
5067
|
}
|
|
5010
5068
|
makeSetDataSchema(model, canBeArray) {
|
|
5011
5069
|
return this.orArray(this.makeWhereSchema(model, true), canBeArray);
|
|
@@ -5035,13 +5093,13 @@ var InputValidator = class {
|
|
|
5035
5093
|
return this.orArray(z.object({
|
|
5036
5094
|
where: whereSchema,
|
|
5037
5095
|
create: createSchema
|
|
5038
|
-
})
|
|
5096
|
+
}), canBeArray);
|
|
5039
5097
|
}
|
|
5040
5098
|
makeCreateManyDataSchema(model, withoutFields) {
|
|
5041
5099
|
return z.object({
|
|
5042
5100
|
data: this.makeCreateDataSchema(model, true, withoutFields, true),
|
|
5043
5101
|
skipDuplicates: z.boolean().optional()
|
|
5044
|
-
})
|
|
5102
|
+
});
|
|
5045
5103
|
}
|
|
5046
5104
|
// #endregion
|
|
5047
5105
|
// #region Update
|
|
@@ -5052,7 +5110,7 @@ var InputValidator = class {
|
|
|
5052
5110
|
select: this.makeSelectSchema(model).optional(),
|
|
5053
5111
|
include: this.makeIncludeSchema(model).optional(),
|
|
5054
5112
|
omit: this.makeOmitSchema(model).optional()
|
|
5055
|
-
})
|
|
5113
|
+
});
|
|
5056
5114
|
return this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
5057
5115
|
}
|
|
5058
5116
|
makeUpdateManySchema(model) {
|
|
@@ -5060,11 +5118,11 @@ var InputValidator = class {
|
|
|
5060
5118
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5061
5119
|
data: this.makeUpdateDataSchema(model, [], true),
|
|
5062
5120
|
limit: z.number().int().nonnegative().optional()
|
|
5063
|
-
})
|
|
5121
|
+
});
|
|
5064
5122
|
}
|
|
5065
5123
|
makeUpdateManyAndReturnSchema(model) {
|
|
5066
5124
|
const base = this.makeUpdateManySchema(model);
|
|
5067
|
-
const result = base.merge(z.
|
|
5125
|
+
const result = base.merge(z.strictObject({
|
|
5068
5126
|
select: this.makeSelectSchema(model).optional(),
|
|
5069
5127
|
omit: this.makeOmitSchema(model).optional()
|
|
5070
5128
|
}));
|
|
@@ -5078,7 +5136,7 @@ var InputValidator = class {
|
|
|
5078
5136
|
select: this.makeSelectSchema(model).optional(),
|
|
5079
5137
|
include: this.makeIncludeSchema(model).optional(),
|
|
5080
5138
|
omit: this.makeOmitSchema(model).optional()
|
|
5081
|
-
})
|
|
5139
|
+
});
|
|
5082
5140
|
return this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
5083
5141
|
}
|
|
5084
5142
|
makeUpdateDataSchema(model, withoutFields = [], withoutRelationFields = false) {
|
|
@@ -5145,11 +5203,11 @@ var InputValidator = class {
|
|
|
5145
5203
|
}
|
|
5146
5204
|
});
|
|
5147
5205
|
if (!hasRelation) {
|
|
5148
|
-
return z.
|
|
5206
|
+
return z.strictObject(uncheckedVariantFields);
|
|
5149
5207
|
} else {
|
|
5150
5208
|
return z.union([
|
|
5151
|
-
z.
|
|
5152
|
-
z.
|
|
5209
|
+
z.strictObject(uncheckedVariantFields),
|
|
5210
|
+
z.strictObject(checkedVariantFields)
|
|
5153
5211
|
]);
|
|
5154
5212
|
}
|
|
5155
5213
|
}
|
|
@@ -5160,25 +5218,25 @@ var InputValidator = class {
|
|
|
5160
5218
|
where: this.makeWhereSchema(model, true),
|
|
5161
5219
|
select: this.makeSelectSchema(model).optional(),
|
|
5162
5220
|
include: this.makeIncludeSchema(model).optional()
|
|
5163
|
-
})
|
|
5221
|
+
});
|
|
5164
5222
|
return this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
5165
5223
|
}
|
|
5166
5224
|
makeDeleteManySchema(model) {
|
|
5167
5225
|
return z.object({
|
|
5168
5226
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5169
5227
|
limit: z.number().int().nonnegative().optional()
|
|
5170
|
-
}).
|
|
5228
|
+
}).optional();
|
|
5171
5229
|
}
|
|
5172
5230
|
// #endregion
|
|
5173
5231
|
// #region Count
|
|
5174
5232
|
makeCountSchema(model) {
|
|
5175
5233
|
return z.object({
|
|
5176
5234
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5177
|
-
skip:
|
|
5178
|
-
take:
|
|
5235
|
+
skip: this.makeSkipSchema().optional(),
|
|
5236
|
+
take: this.makeTakeSchema().optional(),
|
|
5179
5237
|
orderBy: this.orArray(this.makeOrderBySchema(model, true, false), true).optional(),
|
|
5180
5238
|
select: this.makeCountAggregateInputSchema(model).optional()
|
|
5181
|
-
}).
|
|
5239
|
+
}).optional();
|
|
5182
5240
|
}
|
|
5183
5241
|
makeCountAggregateInputSchema(model) {
|
|
5184
5242
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -5190,7 +5248,7 @@ var InputValidator = class {
|
|
|
5190
5248
|
acc[field] = z.literal(true).optional();
|
|
5191
5249
|
return acc;
|
|
5192
5250
|
}, {})
|
|
5193
|
-
})
|
|
5251
|
+
})
|
|
5194
5252
|
]);
|
|
5195
5253
|
}
|
|
5196
5254
|
// #endregion
|
|
@@ -5198,19 +5256,19 @@ var InputValidator = class {
|
|
|
5198
5256
|
makeAggregateSchema(model) {
|
|
5199
5257
|
return z.object({
|
|
5200
5258
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5201
|
-
skip:
|
|
5202
|
-
take:
|
|
5259
|
+
skip: this.makeSkipSchema().optional(),
|
|
5260
|
+
take: this.makeTakeSchema().optional(),
|
|
5203
5261
|
orderBy: this.orArray(this.makeOrderBySchema(model, true, false), true).optional(),
|
|
5204
5262
|
_count: this.makeCountAggregateInputSchema(model).optional(),
|
|
5205
5263
|
_avg: this.makeSumAvgInputSchema(model).optional(),
|
|
5206
5264
|
_sum: this.makeSumAvgInputSchema(model).optional(),
|
|
5207
5265
|
_min: this.makeMinMaxInputSchema(model).optional(),
|
|
5208
5266
|
_max: this.makeMinMaxInputSchema(model).optional()
|
|
5209
|
-
}).
|
|
5267
|
+
}).optional();
|
|
5210
5268
|
}
|
|
5211
5269
|
makeSumAvgInputSchema(model) {
|
|
5212
5270
|
const modelDef = requireModel(this.schema, model);
|
|
5213
|
-
return z.
|
|
5271
|
+
return z.strictObject(Object.keys(modelDef.fields).reduce((acc, field) => {
|
|
5214
5272
|
const fieldDef = requireField(this.schema, model, field);
|
|
5215
5273
|
if (this.isNumericField(fieldDef)) {
|
|
5216
5274
|
acc[field] = z.literal(true).optional();
|
|
@@ -5220,7 +5278,7 @@ var InputValidator = class {
|
|
|
5220
5278
|
}
|
|
5221
5279
|
makeMinMaxInputSchema(model) {
|
|
5222
5280
|
const modelDef = requireModel(this.schema, model);
|
|
5223
|
-
return z.
|
|
5281
|
+
return z.strictObject(Object.keys(modelDef.fields).reduce((acc, field) => {
|
|
5224
5282
|
const fieldDef = requireField(this.schema, model, field);
|
|
5225
5283
|
if (!fieldDef.relation && !fieldDef.array) {
|
|
5226
5284
|
acc[field] = z.literal(true).optional();
|
|
@@ -5236,14 +5294,14 @@ var InputValidator = class {
|
|
|
5236
5294
|
orderBy: this.orArray(this.makeOrderBySchema(model, false, true), true).optional(),
|
|
5237
5295
|
by: this.orArray(z.enum(nonRelationFields), true),
|
|
5238
5296
|
having: this.makeWhereSchema(model, false, true).optional(),
|
|
5239
|
-
skip:
|
|
5240
|
-
take:
|
|
5297
|
+
skip: this.makeSkipSchema().optional(),
|
|
5298
|
+
take: this.makeTakeSchema().optional(),
|
|
5241
5299
|
_count: this.makeCountAggregateInputSchema(model).optional(),
|
|
5242
5300
|
_avg: this.makeSumAvgInputSchema(model).optional(),
|
|
5243
5301
|
_sum: this.makeSumAvgInputSchema(model).optional(),
|
|
5244
5302
|
_min: this.makeMinMaxInputSchema(model).optional(),
|
|
5245
5303
|
_max: this.makeMinMaxInputSchema(model).optional()
|
|
5246
|
-
})
|
|
5304
|
+
});
|
|
5247
5305
|
schema = schema.refine((value) => {
|
|
5248
5306
|
const bys = typeof value.by === "string" ? [
|
|
5249
5307
|
value.by
|
|
@@ -5268,6 +5326,12 @@ var InputValidator = class {
|
|
|
5268
5326
|
}
|
|
5269
5327
|
// #endregion
|
|
5270
5328
|
// #region Helpers
|
|
5329
|
+
makeSkipSchema() {
|
|
5330
|
+
return z.number().int().nonnegative();
|
|
5331
|
+
}
|
|
5332
|
+
makeTakeSchema() {
|
|
5333
|
+
return z.number().int();
|
|
5334
|
+
}
|
|
5271
5335
|
refineForSelectIncludeMutuallyExclusive(schema) {
|
|
5272
5336
|
return schema.refine((value) => !(value["select"] && value["include"]), '"select" and "include" cannot be used together');
|
|
5273
5337
|
}
|
|
@@ -5286,6 +5350,9 @@ var InputValidator = class {
|
|
|
5286
5350
|
isNumericField(fieldDef) {
|
|
5287
5351
|
return NUMERIC_FIELD_TYPES.includes(fieldDef.type) && !fieldDef.array;
|
|
5288
5352
|
}
|
|
5353
|
+
get providerSupportsCaseSensitivity() {
|
|
5354
|
+
return this.schema.provider.type === "postgresql";
|
|
5355
|
+
}
|
|
5289
5356
|
};
|
|
5290
5357
|
|
|
5291
5358
|
// src/client/executor/zenstack-driver.ts
|