@zenstackhq/runtime 3.0.0-alpha.17 → 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-C6xcEG6Q.d.cts → contract-CxX20JtH.d.cts} +74 -64
- package/dist/{contract-C6xcEG6Q.d.ts → contract-CxX20JtH.d.ts} +74 -64
- package/dist/index.cjs +236 -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 +236 -140
- package/dist/index.js.map +1 -1
- package/dist/plugins/policy/index.cjs +104 -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 +104 -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;
|
|
@@ -1182,6 +1221,9 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
|
|
|
1182
1221
|
return `ARRAY[${values.map((v) => typeof v === "string" ? `'${v}'` : v)}]`;
|
|
1183
1222
|
}
|
|
1184
1223
|
}
|
|
1224
|
+
get supportInsertWithDefault() {
|
|
1225
|
+
return true;
|
|
1226
|
+
}
|
|
1185
1227
|
};
|
|
1186
1228
|
|
|
1187
1229
|
// src/client/crud/dialects/sqlite.ts
|
|
@@ -1212,11 +1254,11 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
1212
1254
|
buildRelationSelection(query, model, relationField, parentAlias, payload) {
|
|
1213
1255
|
return query.select((eb) => this.buildRelationJSON(model, eb, relationField, parentAlias, payload).as(relationField));
|
|
1214
1256
|
}
|
|
1215
|
-
buildRelationJSON(model, eb, relationField,
|
|
1257
|
+
buildRelationJSON(model, eb, relationField, parentAlias, payload) {
|
|
1216
1258
|
const relationFieldDef = requireField(this.schema, model, relationField);
|
|
1217
1259
|
const relationModel = relationFieldDef.type;
|
|
1218
1260
|
const relationModelDef = requireModel(this.schema, relationModel);
|
|
1219
|
-
const subQueryName = `${
|
|
1261
|
+
const subQueryName = `${parentAlias}$${relationField}`;
|
|
1220
1262
|
let tbl = eb.selectFrom(() => {
|
|
1221
1263
|
let subQuery = this.buildSelectModel(eb, relationModel);
|
|
1222
1264
|
subQuery = this.buildSelectAllFields(relationModel, subQuery, typeof payload === "object" ? payload?.omit : void 0);
|
|
@@ -1240,14 +1282,14 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
1240
1282
|
const relationIds = getIdFields(this.schema, relationModel);
|
|
1241
1283
|
(0, import_common_helpers3.invariant)(parentIds.length === 1, "many-to-many relation must have exactly one id field");
|
|
1242
1284
|
(0, import_common_helpers3.invariant)(relationIds.length === 1, "many-to-many relation must have exactly one id field");
|
|
1243
|
-
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}`)));
|
|
1244
1286
|
} else {
|
|
1245
1287
|
const { keyPairs, ownedByModel } = getRelationForeignKeyFieldPairs(this.schema, model, relationField);
|
|
1246
1288
|
keyPairs.forEach(({ fk, pk }) => {
|
|
1247
1289
|
if (ownedByModel) {
|
|
1248
|
-
subQuery = subQuery.whereRef(`${relationModel}.${pk}`, "=", `${
|
|
1290
|
+
subQuery = subQuery.whereRef(`${relationModel}.${pk}`, "=", `${parentAlias}.${fk}`);
|
|
1249
1291
|
} else {
|
|
1250
|
-
subQuery = subQuery.whereRef(`${relationModel}.${fk}`, "=", `${
|
|
1292
|
+
subQuery = subQuery.whereRef(`${relationModel}.${fk}`, "=", `${parentAlias}.${pk}`);
|
|
1251
1293
|
}
|
|
1252
1294
|
});
|
|
1253
1295
|
}
|
|
@@ -1269,24 +1311,32 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
1269
1311
|
]).flatMap((v) => v));
|
|
1270
1312
|
} else if (payload.select) {
|
|
1271
1313
|
objArgs.push(...Object.entries(payload.select).filter(([, value]) => value).map(([field, value]) => {
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
const subJson = this.buildRelationJSON(relationModel, eb, field, `${parentName}$${relationField}`, value);
|
|
1314
|
+
if (field === "_count") {
|
|
1315
|
+
const subJson = this.buildCountJson(relationModel, eb, `${parentAlias}$${relationField}`, value);
|
|
1275
1316
|
return [
|
|
1276
1317
|
import_kysely3.sql.lit(field),
|
|
1277
1318
|
subJson
|
|
1278
1319
|
];
|
|
1279
1320
|
} else {
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
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
|
+
}
|
|
1284
1334
|
}
|
|
1285
1335
|
}).flatMap((v) => v));
|
|
1286
1336
|
}
|
|
1287
1337
|
if (typeof payload === "object" && payload.include && typeof payload.include === "object") {
|
|
1288
1338
|
objArgs.push(...Object.entries(payload.include).filter(([, value]) => value).map(([field, value]) => {
|
|
1289
|
-
const subJson = this.buildRelationJSON(relationModel, eb, field, `${
|
|
1339
|
+
const subJson = this.buildRelationJSON(relationModel, eb, field, `${parentAlias}$${relationField}`, value);
|
|
1290
1340
|
return [
|
|
1291
1341
|
import_kysely3.sql.lit(field),
|
|
1292
1342
|
subJson
|
|
@@ -1336,6 +1386,9 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
1336
1386
|
buildArrayLiteralSQL(_values) {
|
|
1337
1387
|
throw new Error("SQLite does not support array literals");
|
|
1338
1388
|
}
|
|
1389
|
+
get supportInsertWithDefault() {
|
|
1390
|
+
return false;
|
|
1391
|
+
}
|
|
1339
1392
|
};
|
|
1340
1393
|
|
|
1341
1394
|
// src/client/crud/dialects/index.ts
|
|
@@ -2695,6 +2748,7 @@ var BaseOperationHandler = class {
|
|
|
2695
2748
|
query = query.distinctOn(distinct.map((f) => import_kysely8.sql.ref(`${model}.${f}`)));
|
|
2696
2749
|
} else {
|
|
2697
2750
|
inMemoryDistinct = distinct;
|
|
2751
|
+
query = distinct.reduce((acc, field) => acc.select((eb) => buildFieldRef(this.schema, model, field, this.options, eb).as(`$distinct$${field}`)), query);
|
|
2698
2752
|
}
|
|
2699
2753
|
}
|
|
2700
2754
|
if (args && "select" in args && args.select) {
|
|
@@ -2732,13 +2786,16 @@ ${compiled.parameters.map((p) => (0, import_node_util.inspect)(p)).join("\n")}`;
|
|
|
2732
2786
|
const distinctResult = [];
|
|
2733
2787
|
const seen = /* @__PURE__ */ new Set();
|
|
2734
2788
|
for (const r of result) {
|
|
2735
|
-
const key = safeJSONStringify(inMemoryDistinct.map((f) => r[f]));
|
|
2789
|
+
const key = safeJSONStringify(inMemoryDistinct.map((f) => r[`$distinct$${f}`]));
|
|
2736
2790
|
if (!seen.has(key)) {
|
|
2737
2791
|
distinctResult.push(r);
|
|
2738
2792
|
seen.add(key);
|
|
2739
2793
|
}
|
|
2740
2794
|
}
|
|
2741
2795
|
result = distinctResult;
|
|
2796
|
+
for (const r of result) {
|
|
2797
|
+
Object.keys(r).filter((k) => k.startsWith("$distinct$")).forEach((k) => delete r[k]);
|
|
2798
|
+
}
|
|
2742
2799
|
}
|
|
2743
2800
|
return result;
|
|
2744
2801
|
}
|
|
@@ -2776,32 +2833,7 @@ ${compiled.parameters.map((p) => (0, import_node_util.inspect)(p)).join("\n")}`;
|
|
|
2776
2833
|
return result;
|
|
2777
2834
|
}
|
|
2778
2835
|
buildCountSelection(query, model, parentAlias, payload) {
|
|
2779
|
-
|
|
2780
|
-
const toManyRelations = Object.entries(modelDef.fields).filter(([, field]) => field.relation && field.array);
|
|
2781
|
-
const selections = payload === true ? {
|
|
2782
|
-
select: toManyRelations.reduce((acc, [field]) => {
|
|
2783
|
-
acc[field] = true;
|
|
2784
|
-
return acc;
|
|
2785
|
-
}, {})
|
|
2786
|
-
} : payload;
|
|
2787
|
-
const eb = (0, import_kysely8.expressionBuilder)();
|
|
2788
|
-
const jsonObject = {};
|
|
2789
|
-
for (const [field, value] of Object.entries(selections.select)) {
|
|
2790
|
-
const fieldDef = requireField(this.schema, model, field);
|
|
2791
|
-
const fieldModel = fieldDef.type;
|
|
2792
|
-
const joinPairs = buildJoinPairs(this.schema, model, parentAlias, field, fieldModel);
|
|
2793
|
-
let fieldCountQuery = eb.selectFrom(fieldModel).select(eb.fn.countAll().as(`_count$${field}`));
|
|
2794
|
-
for (const [left, right] of joinPairs) {
|
|
2795
|
-
fieldCountQuery = fieldCountQuery.whereRef(left, "=", right);
|
|
2796
|
-
}
|
|
2797
|
-
if (value && typeof value === "object" && "where" in value && value.where && typeof value.where === "object") {
|
|
2798
|
-
const filter = this.dialect.buildFilter(eb, fieldModel, fieldModel, value.where);
|
|
2799
|
-
fieldCountQuery = fieldCountQuery.where(filter);
|
|
2800
|
-
}
|
|
2801
|
-
jsonObject[field] = fieldCountQuery;
|
|
2802
|
-
}
|
|
2803
|
-
query = query.select((eb2) => this.dialect.buildJsonObject(eb2, jsonObject).as("_count"));
|
|
2804
|
-
return query;
|
|
2836
|
+
return query.select((eb) => this.dialect.buildCountJson(model, eb, parentAlias, payload).as("_count"));
|
|
2805
2837
|
}
|
|
2806
2838
|
buildCursorFilter(model, query, cursor, orderBy, negateOrderBy) {
|
|
2807
2839
|
if (!orderBy) {
|
|
@@ -3108,6 +3140,29 @@ ${compiled.parameters.map((p) => (0, import_node_util.inspect)(p)).join("\n")}`;
|
|
|
3108
3140
|
}
|
|
3109
3141
|
return this.fillGeneratedValues(modelDef, newItem);
|
|
3110
3142
|
});
|
|
3143
|
+
if (!this.dialect.supportInsertWithDefault) {
|
|
3144
|
+
const allPassedFields = createData.reduce((acc, item) => {
|
|
3145
|
+
Object.keys(item).forEach((field) => {
|
|
3146
|
+
if (!acc.includes(field)) {
|
|
3147
|
+
acc.push(field);
|
|
3148
|
+
}
|
|
3149
|
+
});
|
|
3150
|
+
return acc;
|
|
3151
|
+
}, []);
|
|
3152
|
+
for (const item of createData) {
|
|
3153
|
+
if (Object.keys(item).length === allPassedFields.length) {
|
|
3154
|
+
continue;
|
|
3155
|
+
}
|
|
3156
|
+
for (const field of allPassedFields) {
|
|
3157
|
+
if (!(field in item)) {
|
|
3158
|
+
const fieldDef = this.requireField(model, field);
|
|
3159
|
+
if (fieldDef.default !== void 0 && fieldDef.default !== null && typeof fieldDef.default !== "object") {
|
|
3160
|
+
item[field] = this.dialect.transformPrimitive(fieldDef.default, fieldDef.type, !!fieldDef.array);
|
|
3161
|
+
}
|
|
3162
|
+
}
|
|
3163
|
+
}
|
|
3164
|
+
}
|
|
3165
|
+
}
|
|
3111
3166
|
if (modelDef.baseModel) {
|
|
3112
3167
|
if (input.skipDuplicates) {
|
|
3113
3168
|
throw new QueryError('"skipDuplicates" options is not supported for polymorphic models');
|
|
@@ -4504,11 +4559,11 @@ var InputValidator = class {
|
|
|
4504
4559
|
fields["distinct"] = this.makeDistinctSchema(model).optional();
|
|
4505
4560
|
fields["cursor"] = this.makeCursorSchema(model).optional();
|
|
4506
4561
|
if (options.collection) {
|
|
4507
|
-
fields["skip"] =
|
|
4508
|
-
fields["take"] =
|
|
4562
|
+
fields["skip"] = this.makeSkipSchema().optional();
|
|
4563
|
+
fields["take"] = this.makeTakeSchema().optional();
|
|
4509
4564
|
fields["orderBy"] = this.orArray(this.makeOrderBySchema(model, true, false), true).optional();
|
|
4510
4565
|
}
|
|
4511
|
-
let result = import_zod.z.
|
|
4566
|
+
let result = import_zod.z.strictObject(fields);
|
|
4512
4567
|
result = this.refineForSelectIncludeMutuallyExclusive(result);
|
|
4513
4568
|
result = this.refineForSelectOmitMutuallyExclusive(result);
|
|
4514
4569
|
if (!options.unique) {
|
|
@@ -4575,7 +4630,7 @@ var InputValidator = class {
|
|
|
4575
4630
|
if (fieldDef.array) {
|
|
4576
4631
|
fieldSchema = import_zod.z.union([
|
|
4577
4632
|
fieldSchema,
|
|
4578
|
-
import_zod.z.
|
|
4633
|
+
import_zod.z.strictObject({
|
|
4579
4634
|
some: fieldSchema.optional(),
|
|
4580
4635
|
every: fieldSchema.optional(),
|
|
4581
4636
|
none: fieldSchema.optional()
|
|
@@ -4584,7 +4639,7 @@ var InputValidator = class {
|
|
|
4584
4639
|
} else {
|
|
4585
4640
|
fieldSchema = import_zod.z.union([
|
|
4586
4641
|
fieldSchema,
|
|
4587
|
-
import_zod.z.
|
|
4642
|
+
import_zod.z.strictObject({
|
|
4588
4643
|
is: fieldSchema.optional(),
|
|
4589
4644
|
isNot: fieldSchema.optional()
|
|
4590
4645
|
})
|
|
@@ -4635,7 +4690,7 @@ var InputValidator = class {
|
|
|
4635
4690
|
fields["AND"] = this.orArray(import_zod.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
|
|
4636
4691
|
fields["OR"] = import_zod.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)).array().optional();
|
|
4637
4692
|
fields["NOT"] = this.orArray(import_zod.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
|
|
4638
|
-
const baseWhere = import_zod.z.
|
|
4693
|
+
const baseWhere = import_zod.z.strictObject(fields);
|
|
4639
4694
|
let result = baseWhere;
|
|
4640
4695
|
if (unique) {
|
|
4641
4696
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
@@ -4659,7 +4714,7 @@ var InputValidator = class {
|
|
|
4659
4714
|
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => import_zod.z.lazy(() => this.makeEnumFilterSchema(enumDef, optional)));
|
|
4660
4715
|
return import_zod.z.union([
|
|
4661
4716
|
this.nullableIf(baseSchema, optional),
|
|
4662
|
-
import_zod.z.
|
|
4717
|
+
import_zod.z.strictObject({
|
|
4663
4718
|
equals: components.equals,
|
|
4664
4719
|
in: components.in,
|
|
4665
4720
|
notIn: components.notIn,
|
|
@@ -4668,7 +4723,7 @@ var InputValidator = class {
|
|
|
4668
4723
|
]);
|
|
4669
4724
|
}
|
|
4670
4725
|
makeArrayFilterSchema(type) {
|
|
4671
|
-
return import_zod.z.
|
|
4726
|
+
return import_zod.z.strictObject({
|
|
4672
4727
|
equals: this.makePrimitiveSchema(type).array().optional(),
|
|
4673
4728
|
has: this.makePrimitiveSchema(type).optional(),
|
|
4674
4729
|
hasEvery: this.makePrimitiveSchema(type).array().optional(),
|
|
@@ -4694,7 +4749,7 @@ var InputValidator = class {
|
|
|
4694
4749
|
makeBooleanFilterSchema(optional) {
|
|
4695
4750
|
return import_zod.z.union([
|
|
4696
4751
|
this.nullableIf(import_zod.z.boolean(), optional),
|
|
4697
|
-
import_zod.z.
|
|
4752
|
+
import_zod.z.strictObject({
|
|
4698
4753
|
equals: this.nullableIf(import_zod.z.boolean(), optional).optional(),
|
|
4699
4754
|
not: import_zod.z.lazy(() => this.makeBooleanFilterSchema(optional)).optional()
|
|
4700
4755
|
})
|
|
@@ -4705,7 +4760,7 @@ var InputValidator = class {
|
|
|
4705
4760
|
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => import_zod.z.instanceof(Uint8Array));
|
|
4706
4761
|
return import_zod.z.union([
|
|
4707
4762
|
this.nullableIf(baseSchema, optional),
|
|
4708
|
-
import_zod.z.
|
|
4763
|
+
import_zod.z.strictObject({
|
|
4709
4764
|
equals: components.equals,
|
|
4710
4765
|
in: components.in,
|
|
4711
4766
|
notIn: components.notIn,
|
|
@@ -4729,14 +4784,31 @@ var InputValidator = class {
|
|
|
4729
4784
|
makeCommonPrimitiveFilterSchema(baseSchema, optional, makeThis) {
|
|
4730
4785
|
return import_zod.z.union([
|
|
4731
4786
|
this.nullableIf(baseSchema, optional),
|
|
4732
|
-
import_zod.z.
|
|
4787
|
+
import_zod.z.strictObject(this.makeCommonPrimitiveFilterComponents(baseSchema, optional, makeThis))
|
|
4733
4788
|
]);
|
|
4734
4789
|
}
|
|
4735
4790
|
makeNumberFilterSchema(baseSchema, optional) {
|
|
4736
4791
|
return this.makeCommonPrimitiveFilterSchema(baseSchema, optional, () => import_zod.z.lazy(() => this.makeNumberFilterSchema(baseSchema, optional)));
|
|
4737
4792
|
}
|
|
4738
4793
|
makeStringFilterSchema(optional) {
|
|
4739
|
-
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
|
+
]);
|
|
4740
4812
|
}
|
|
4741
4813
|
makeSelectSchema(model) {
|
|
4742
4814
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -4746,7 +4818,7 @@ var InputValidator = class {
|
|
|
4746
4818
|
if (fieldDef.relation) {
|
|
4747
4819
|
fields[field] = import_zod.z.union([
|
|
4748
4820
|
import_zod.z.literal(true),
|
|
4749
|
-
import_zod.z.
|
|
4821
|
+
import_zod.z.strictObject({
|
|
4750
4822
|
select: import_zod.z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional(),
|
|
4751
4823
|
include: import_zod.z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional()
|
|
4752
4824
|
})
|
|
@@ -4755,22 +4827,24 @@ var InputValidator = class {
|
|
|
4755
4827
|
fields[field] = import_zod.z.boolean().optional();
|
|
4756
4828
|
}
|
|
4757
4829
|
}
|
|
4758
|
-
const toManyRelations = Object.
|
|
4830
|
+
const toManyRelations = Object.values(modelDef.fields).filter((def) => def.relation && def.array);
|
|
4759
4831
|
if (toManyRelations.length > 0) {
|
|
4760
4832
|
fields["_count"] = import_zod.z.union([
|
|
4761
4833
|
import_zod.z.literal(true),
|
|
4762
|
-
import_zod.z.
|
|
4763
|
-
|
|
4764
|
-
|
|
4765
|
-
import_zod.z.
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
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
|
+
})
|
|
4771
4845
|
]).optional();
|
|
4772
4846
|
}
|
|
4773
|
-
return import_zod.z.
|
|
4847
|
+
return import_zod.z.strictObject(fields);
|
|
4774
4848
|
}
|
|
4775
4849
|
makeOmitSchema(model) {
|
|
4776
4850
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -4781,7 +4855,7 @@ var InputValidator = class {
|
|
|
4781
4855
|
fields[field] = import_zod.z.boolean().optional();
|
|
4782
4856
|
}
|
|
4783
4857
|
}
|
|
4784
|
-
return import_zod.z.
|
|
4858
|
+
return import_zod.z.strictObject(fields);
|
|
4785
4859
|
}
|
|
4786
4860
|
makeIncludeSchema(model) {
|
|
4787
4861
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -4791,15 +4865,20 @@ var InputValidator = class {
|
|
|
4791
4865
|
if (fieldDef.relation) {
|
|
4792
4866
|
fields[field] = import_zod.z.union([
|
|
4793
4867
|
import_zod.z.literal(true),
|
|
4794
|
-
import_zod.z.
|
|
4868
|
+
import_zod.z.strictObject({
|
|
4795
4869
|
select: import_zod.z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional(),
|
|
4796
4870
|
include: import_zod.z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional(),
|
|
4797
|
-
|
|
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()
|
|
4798
4877
|
})
|
|
4799
4878
|
]).optional();
|
|
4800
4879
|
}
|
|
4801
4880
|
}
|
|
4802
|
-
return import_zod.z.
|
|
4881
|
+
return import_zod.z.strictObject(fields);
|
|
4803
4882
|
}
|
|
4804
4883
|
makeOrderBySchema(model, withRelation, WithAggregation) {
|
|
4805
4884
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -4812,13 +4891,21 @@ var InputValidator = class {
|
|
|
4812
4891
|
const fieldDef = requireField(this.schema, model, field);
|
|
4813
4892
|
if (fieldDef.relation) {
|
|
4814
4893
|
if (withRelation) {
|
|
4815
|
-
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
|
+
});
|
|
4816
4903
|
}
|
|
4817
4904
|
} else {
|
|
4818
4905
|
if (fieldDef.optional) {
|
|
4819
4906
|
fields[field] = import_zod.z.union([
|
|
4820
4907
|
sort,
|
|
4821
|
-
import_zod.z.
|
|
4908
|
+
import_zod.z.strictObject({
|
|
4822
4909
|
sort,
|
|
4823
4910
|
nulls: import_zod.z.union([
|
|
4824
4911
|
import_zod.z.literal("first"),
|
|
@@ -4843,7 +4930,7 @@ var InputValidator = class {
|
|
|
4843
4930
|
fields[agg] = import_zod.z.lazy(() => this.makeOrderBySchema(model, true, false).optional());
|
|
4844
4931
|
}
|
|
4845
4932
|
}
|
|
4846
|
-
return import_zod.z.
|
|
4933
|
+
return import_zod.z.strictObject(fields);
|
|
4847
4934
|
}
|
|
4848
4935
|
makeDistinctSchema(model) {
|
|
4849
4936
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -4862,7 +4949,7 @@ var InputValidator = class {
|
|
|
4862
4949
|
select: this.makeSelectSchema(model).optional(),
|
|
4863
4950
|
include: this.makeIncludeSchema(model).optional(),
|
|
4864
4951
|
omit: this.makeOmitSchema(model).optional()
|
|
4865
|
-
})
|
|
4952
|
+
});
|
|
4866
4953
|
return this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
4867
4954
|
}
|
|
4868
4955
|
makeCreateManySchema(model) {
|
|
@@ -4870,7 +4957,7 @@ var InputValidator = class {
|
|
|
4870
4957
|
}
|
|
4871
4958
|
makeCreateManyAndReturnSchema(model) {
|
|
4872
4959
|
const base = this.makeCreateManyDataSchema(model, []);
|
|
4873
|
-
const result = base.merge(import_zod.z.
|
|
4960
|
+
const result = base.merge(import_zod.z.strictObject({
|
|
4874
4961
|
select: this.makeSelectSchema(model).optional(),
|
|
4875
4962
|
omit: this.makeOmitSchema(model).optional()
|
|
4876
4963
|
}));
|
|
@@ -4932,7 +5019,7 @@ var InputValidator = class {
|
|
|
4932
5019
|
if (fieldDef.array) {
|
|
4933
5020
|
fieldSchema = import_zod.z.union([
|
|
4934
5021
|
import_zod.z.array(fieldSchema),
|
|
4935
|
-
import_zod.z.
|
|
5022
|
+
import_zod.z.strictObject({
|
|
4936
5023
|
set: import_zod.z.array(fieldSchema)
|
|
4937
5024
|
})
|
|
4938
5025
|
]).optional();
|
|
@@ -4950,16 +5037,16 @@ var InputValidator = class {
|
|
|
4950
5037
|
}
|
|
4951
5038
|
});
|
|
4952
5039
|
if (!hasRelation) {
|
|
4953
|
-
return this.orArray(import_zod.z.
|
|
5040
|
+
return this.orArray(import_zod.z.strictObject(uncheckedVariantFields), canBeArray);
|
|
4954
5041
|
} else {
|
|
4955
5042
|
return import_zod.z.union([
|
|
4956
|
-
import_zod.z.
|
|
4957
|
-
import_zod.z.
|
|
5043
|
+
import_zod.z.strictObject(uncheckedVariantFields),
|
|
5044
|
+
import_zod.z.strictObject(checkedVariantFields),
|
|
4958
5045
|
...canBeArray ? [
|
|
4959
|
-
import_zod.z.array(import_zod.z.
|
|
5046
|
+
import_zod.z.array(import_zod.z.strictObject(uncheckedVariantFields))
|
|
4960
5047
|
] : [],
|
|
4961
5048
|
...canBeArray ? [
|
|
4962
|
-
import_zod.z.array(import_zod.z.
|
|
5049
|
+
import_zod.z.array(import_zod.z.strictObject(checkedVariantFields))
|
|
4963
5050
|
] : []
|
|
4964
5051
|
]);
|
|
4965
5052
|
}
|
|
@@ -4987,31 +5074,31 @@ var InputValidator = class {
|
|
|
4987
5074
|
fields["disconnect"] = this.makeDisconnectDataSchema(fieldType, array).optional();
|
|
4988
5075
|
fields["delete"] = this.makeDeleteRelationDataSchema(fieldType, array, true).optional();
|
|
4989
5076
|
}
|
|
4990
|
-
fields["update"] = array ? this.orArray(import_zod.z.
|
|
5077
|
+
fields["update"] = array ? this.orArray(import_zod.z.strictObject({
|
|
4991
5078
|
where: this.makeWhereSchema(fieldType, true),
|
|
4992
5079
|
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
4993
5080
|
}), true).optional() : import_zod.z.union([
|
|
4994
|
-
import_zod.z.
|
|
5081
|
+
import_zod.z.strictObject({
|
|
4995
5082
|
where: this.makeWhereSchema(fieldType, true),
|
|
4996
5083
|
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
4997
5084
|
}),
|
|
4998
5085
|
this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
4999
5086
|
]).optional();
|
|
5000
|
-
fields["upsert"] = this.orArray(import_zod.z.
|
|
5087
|
+
fields["upsert"] = this.orArray(import_zod.z.strictObject({
|
|
5001
5088
|
where: this.makeWhereSchema(fieldType, true),
|
|
5002
5089
|
create: this.makeCreateDataSchema(fieldType, false, withoutFields),
|
|
5003
5090
|
update: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
5004
5091
|
}), true).optional();
|
|
5005
5092
|
if (array) {
|
|
5006
5093
|
fields["set"] = this.makeSetDataSchema(fieldType, true).optional();
|
|
5007
|
-
fields["updateMany"] = this.orArray(import_zod.z.
|
|
5094
|
+
fields["updateMany"] = this.orArray(import_zod.z.strictObject({
|
|
5008
5095
|
where: this.makeWhereSchema(fieldType, false, true),
|
|
5009
5096
|
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
5010
5097
|
}), true).optional();
|
|
5011
5098
|
fields["deleteMany"] = this.makeDeleteRelationDataSchema(fieldType, true, false).optional();
|
|
5012
5099
|
}
|
|
5013
5100
|
}
|
|
5014
|
-
return import_zod.z.
|
|
5101
|
+
return import_zod.z.strictObject(fields);
|
|
5015
5102
|
}
|
|
5016
5103
|
makeSetDataSchema(model, canBeArray) {
|
|
5017
5104
|
return this.orArray(this.makeWhereSchema(model, true), canBeArray);
|
|
@@ -5041,13 +5128,13 @@ var InputValidator = class {
|
|
|
5041
5128
|
return this.orArray(import_zod.z.object({
|
|
5042
5129
|
where: whereSchema,
|
|
5043
5130
|
create: createSchema
|
|
5044
|
-
})
|
|
5131
|
+
}), canBeArray);
|
|
5045
5132
|
}
|
|
5046
5133
|
makeCreateManyDataSchema(model, withoutFields) {
|
|
5047
5134
|
return import_zod.z.object({
|
|
5048
5135
|
data: this.makeCreateDataSchema(model, true, withoutFields, true),
|
|
5049
5136
|
skipDuplicates: import_zod.z.boolean().optional()
|
|
5050
|
-
})
|
|
5137
|
+
});
|
|
5051
5138
|
}
|
|
5052
5139
|
// #endregion
|
|
5053
5140
|
// #region Update
|
|
@@ -5058,7 +5145,7 @@ var InputValidator = class {
|
|
|
5058
5145
|
select: this.makeSelectSchema(model).optional(),
|
|
5059
5146
|
include: this.makeIncludeSchema(model).optional(),
|
|
5060
5147
|
omit: this.makeOmitSchema(model).optional()
|
|
5061
|
-
})
|
|
5148
|
+
});
|
|
5062
5149
|
return this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
5063
5150
|
}
|
|
5064
5151
|
makeUpdateManySchema(model) {
|
|
@@ -5066,11 +5153,11 @@ var InputValidator = class {
|
|
|
5066
5153
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5067
5154
|
data: this.makeUpdateDataSchema(model, [], true),
|
|
5068
5155
|
limit: import_zod.z.number().int().nonnegative().optional()
|
|
5069
|
-
})
|
|
5156
|
+
});
|
|
5070
5157
|
}
|
|
5071
5158
|
makeUpdateManyAndReturnSchema(model) {
|
|
5072
5159
|
const base = this.makeUpdateManySchema(model);
|
|
5073
|
-
const result = base.merge(import_zod.z.
|
|
5160
|
+
const result = base.merge(import_zod.z.strictObject({
|
|
5074
5161
|
select: this.makeSelectSchema(model).optional(),
|
|
5075
5162
|
omit: this.makeOmitSchema(model).optional()
|
|
5076
5163
|
}));
|
|
@@ -5084,7 +5171,7 @@ var InputValidator = class {
|
|
|
5084
5171
|
select: this.makeSelectSchema(model).optional(),
|
|
5085
5172
|
include: this.makeIncludeSchema(model).optional(),
|
|
5086
5173
|
omit: this.makeOmitSchema(model).optional()
|
|
5087
|
-
})
|
|
5174
|
+
});
|
|
5088
5175
|
return this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
5089
5176
|
}
|
|
5090
5177
|
makeUpdateDataSchema(model, withoutFields = [], withoutRelationFields = false) {
|
|
@@ -5151,11 +5238,11 @@ var InputValidator = class {
|
|
|
5151
5238
|
}
|
|
5152
5239
|
});
|
|
5153
5240
|
if (!hasRelation) {
|
|
5154
|
-
return import_zod.z.
|
|
5241
|
+
return import_zod.z.strictObject(uncheckedVariantFields);
|
|
5155
5242
|
} else {
|
|
5156
5243
|
return import_zod.z.union([
|
|
5157
|
-
import_zod.z.
|
|
5158
|
-
import_zod.z.
|
|
5244
|
+
import_zod.z.strictObject(uncheckedVariantFields),
|
|
5245
|
+
import_zod.z.strictObject(checkedVariantFields)
|
|
5159
5246
|
]);
|
|
5160
5247
|
}
|
|
5161
5248
|
}
|
|
@@ -5166,25 +5253,25 @@ var InputValidator = class {
|
|
|
5166
5253
|
where: this.makeWhereSchema(model, true),
|
|
5167
5254
|
select: this.makeSelectSchema(model).optional(),
|
|
5168
5255
|
include: this.makeIncludeSchema(model).optional()
|
|
5169
|
-
})
|
|
5256
|
+
});
|
|
5170
5257
|
return this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
5171
5258
|
}
|
|
5172
5259
|
makeDeleteManySchema(model) {
|
|
5173
5260
|
return import_zod.z.object({
|
|
5174
5261
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5175
5262
|
limit: import_zod.z.number().int().nonnegative().optional()
|
|
5176
|
-
}).
|
|
5263
|
+
}).optional();
|
|
5177
5264
|
}
|
|
5178
5265
|
// #endregion
|
|
5179
5266
|
// #region Count
|
|
5180
5267
|
makeCountSchema(model) {
|
|
5181
5268
|
return import_zod.z.object({
|
|
5182
5269
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5183
|
-
skip:
|
|
5184
|
-
take:
|
|
5270
|
+
skip: this.makeSkipSchema().optional(),
|
|
5271
|
+
take: this.makeTakeSchema().optional(),
|
|
5185
5272
|
orderBy: this.orArray(this.makeOrderBySchema(model, true, false), true).optional(),
|
|
5186
5273
|
select: this.makeCountAggregateInputSchema(model).optional()
|
|
5187
|
-
}).
|
|
5274
|
+
}).optional();
|
|
5188
5275
|
}
|
|
5189
5276
|
makeCountAggregateInputSchema(model) {
|
|
5190
5277
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -5196,7 +5283,7 @@ var InputValidator = class {
|
|
|
5196
5283
|
acc[field] = import_zod.z.literal(true).optional();
|
|
5197
5284
|
return acc;
|
|
5198
5285
|
}, {})
|
|
5199
|
-
})
|
|
5286
|
+
})
|
|
5200
5287
|
]);
|
|
5201
5288
|
}
|
|
5202
5289
|
// #endregion
|
|
@@ -5204,19 +5291,19 @@ var InputValidator = class {
|
|
|
5204
5291
|
makeAggregateSchema(model) {
|
|
5205
5292
|
return import_zod.z.object({
|
|
5206
5293
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5207
|
-
skip:
|
|
5208
|
-
take:
|
|
5294
|
+
skip: this.makeSkipSchema().optional(),
|
|
5295
|
+
take: this.makeTakeSchema().optional(),
|
|
5209
5296
|
orderBy: this.orArray(this.makeOrderBySchema(model, true, false), true).optional(),
|
|
5210
5297
|
_count: this.makeCountAggregateInputSchema(model).optional(),
|
|
5211
5298
|
_avg: this.makeSumAvgInputSchema(model).optional(),
|
|
5212
5299
|
_sum: this.makeSumAvgInputSchema(model).optional(),
|
|
5213
5300
|
_min: this.makeMinMaxInputSchema(model).optional(),
|
|
5214
5301
|
_max: this.makeMinMaxInputSchema(model).optional()
|
|
5215
|
-
}).
|
|
5302
|
+
}).optional();
|
|
5216
5303
|
}
|
|
5217
5304
|
makeSumAvgInputSchema(model) {
|
|
5218
5305
|
const modelDef = requireModel(this.schema, model);
|
|
5219
|
-
return import_zod.z.
|
|
5306
|
+
return import_zod.z.strictObject(Object.keys(modelDef.fields).reduce((acc, field) => {
|
|
5220
5307
|
const fieldDef = requireField(this.schema, model, field);
|
|
5221
5308
|
if (this.isNumericField(fieldDef)) {
|
|
5222
5309
|
acc[field] = import_zod.z.literal(true).optional();
|
|
@@ -5226,7 +5313,7 @@ var InputValidator = class {
|
|
|
5226
5313
|
}
|
|
5227
5314
|
makeMinMaxInputSchema(model) {
|
|
5228
5315
|
const modelDef = requireModel(this.schema, model);
|
|
5229
|
-
return import_zod.z.
|
|
5316
|
+
return import_zod.z.strictObject(Object.keys(modelDef.fields).reduce((acc, field) => {
|
|
5230
5317
|
const fieldDef = requireField(this.schema, model, field);
|
|
5231
5318
|
if (!fieldDef.relation && !fieldDef.array) {
|
|
5232
5319
|
acc[field] = import_zod.z.literal(true).optional();
|
|
@@ -5242,14 +5329,14 @@ var InputValidator = class {
|
|
|
5242
5329
|
orderBy: this.orArray(this.makeOrderBySchema(model, false, true), true).optional(),
|
|
5243
5330
|
by: this.orArray(import_zod.z.enum(nonRelationFields), true),
|
|
5244
5331
|
having: this.makeWhereSchema(model, false, true).optional(),
|
|
5245
|
-
skip:
|
|
5246
|
-
take:
|
|
5332
|
+
skip: this.makeSkipSchema().optional(),
|
|
5333
|
+
take: this.makeTakeSchema().optional(),
|
|
5247
5334
|
_count: this.makeCountAggregateInputSchema(model).optional(),
|
|
5248
5335
|
_avg: this.makeSumAvgInputSchema(model).optional(),
|
|
5249
5336
|
_sum: this.makeSumAvgInputSchema(model).optional(),
|
|
5250
5337
|
_min: this.makeMinMaxInputSchema(model).optional(),
|
|
5251
5338
|
_max: this.makeMinMaxInputSchema(model).optional()
|
|
5252
|
-
})
|
|
5339
|
+
});
|
|
5253
5340
|
schema = schema.refine((value) => {
|
|
5254
5341
|
const bys = typeof value.by === "string" ? [
|
|
5255
5342
|
value.by
|
|
@@ -5274,6 +5361,12 @@ var InputValidator = class {
|
|
|
5274
5361
|
}
|
|
5275
5362
|
// #endregion
|
|
5276
5363
|
// #region Helpers
|
|
5364
|
+
makeSkipSchema() {
|
|
5365
|
+
return import_zod.z.number().int().nonnegative();
|
|
5366
|
+
}
|
|
5367
|
+
makeTakeSchema() {
|
|
5368
|
+
return import_zod.z.number().int();
|
|
5369
|
+
}
|
|
5277
5370
|
refineForSelectIncludeMutuallyExclusive(schema) {
|
|
5278
5371
|
return schema.refine((value) => !(value["select"] && value["include"]), '"select" and "include" cannot be used together');
|
|
5279
5372
|
}
|
|
@@ -5292,6 +5385,9 @@ var InputValidator = class {
|
|
|
5292
5385
|
isNumericField(fieldDef) {
|
|
5293
5386
|
return NUMERIC_FIELD_TYPES.includes(fieldDef.type) && !fieldDef.array;
|
|
5294
5387
|
}
|
|
5388
|
+
get providerSupportsCaseSensitivity() {
|
|
5389
|
+
return this.schema.provider.type === "postgresql";
|
|
5390
|
+
}
|
|
5295
5391
|
};
|
|
5296
5392
|
|
|
5297
5393
|
// src/client/executor/zenstack-driver.ts
|