@zenstackhq/orm 3.9.8 → 3.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +354 -145
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +87 -15
- package/dist/index.d.mts +89 -17
- package/dist/index.mjs +482 -273
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { a as CoreCreateOperations, c as CoreReadOperations, d as DELEGATE_JOINE
|
|
|
3
3
|
import { AnyNull, AnyNullClass, DbNull, DbNullClass, JsonNull, JsonNullClass } from "./common-types.mjs";
|
|
4
4
|
import { clone, enumerate, invariant, isPlainObject, lowerCaseFirst, upperCaseFirst } from "@zenstackhq/common-helpers";
|
|
5
5
|
import { AliasNode, AndNode, ColumnNode, ColumnUpdateNode, CompiledQuery, DefaultConnectionProvider, DefaultQueryExecutor, DeleteQueryNode, ExpressionWrapper, FromNode, IdentifierNode, InsertQueryNode, Kysely, Log, OperationNodeTransformer, OperationNodeVisitor, PrimitiveValueListNode, RawNode, ReferenceNode, ReturningNode, SelectAllNode, SelectionNode, SingleConnectionProvider, TableNode, Transaction, UpdateQueryNode, ValueListNode, ValueNode, ValuesNode, WhereNode, createQueryId, expressionBuilder, sql } from "kysely";
|
|
6
|
-
import z
|
|
6
|
+
import z, { ZodObject, ZodType, z as z$1 } from "zod";
|
|
7
7
|
import { fromError } from "zod-validation-error/v4";
|
|
8
8
|
import { P, match } from "ts-pattern";
|
|
9
9
|
import { ExpressionUtils } from "@zenstackhq/schema";
|
|
@@ -207,6 +207,7 @@ var query_utils_exports = /* @__PURE__ */ __exportAll({
|
|
|
207
207
|
isEnum: () => isEnum,
|
|
208
208
|
isForeignKeyField: () => isForeignKeyField,
|
|
209
209
|
isInheritedField: () => isInheritedField,
|
|
210
|
+
isPrimitiveTypeDef: () => isPrimitiveTypeDef,
|
|
210
211
|
isRelationField: () => isRelationField,
|
|
211
212
|
isScalarField: () => isScalarField,
|
|
212
213
|
isTypeDef: () => isTypeDef,
|
|
@@ -387,6 +388,9 @@ function getEnum(schema, type) {
|
|
|
387
388
|
function isTypeDef(schema, type) {
|
|
388
389
|
return !!schema.typeDefs?.[type];
|
|
389
390
|
}
|
|
391
|
+
function isPrimitiveTypeDef(schema, type) {
|
|
392
|
+
return !!schema.typeDefs?.[type]?.base;
|
|
393
|
+
}
|
|
390
394
|
function buildJoinPairs(schema, model, modelAlias, relationField, relationModelAlias) {
|
|
391
395
|
const { keyPairs, ownedByModel } = getRelationForeignKeyFieldPairs(schema, model, relationField);
|
|
392
396
|
return keyPairs.map(({ fk, pk }) => {
|
|
@@ -690,12 +694,12 @@ var BaseCrudDialect = class {
|
|
|
690
694
|
const { args: _args, ...rest } = payload;
|
|
691
695
|
filterPayload = rest;
|
|
692
696
|
}
|
|
693
|
-
const fieldRef = this.fieldRef(fieldDef.originModel ?? model, key,
|
|
697
|
+
const fieldRef = this.fieldRef(fieldDef.originModel ?? model, key, this.delegateFieldAlias(model, modelAlias, fieldDef), true, computedArgs);
|
|
694
698
|
if (fieldDef.array) result = this.and(result, this.buildArrayFilter(fieldRef, fieldDef, filterPayload));
|
|
695
699
|
else result = this.and(result, this.buildPrimitiveFilter(fieldRef, fieldDef, filterPayload));
|
|
696
700
|
}
|
|
697
701
|
}
|
|
698
|
-
if ("$expr" in _where && typeof _where["$expr"] === "function") result = this.and(result, _where["$expr"](this.eb));
|
|
702
|
+
if ("$expr" in _where && typeof _where["$expr"] === "function") result = this.and(result, _where["$expr"](this.eb, { modelAlias }));
|
|
699
703
|
return result;
|
|
700
704
|
}
|
|
701
705
|
buildCursorFilter(model, query, cursor, orderBy, negateOrderBy, modelAlias) {
|
|
@@ -710,8 +714,8 @@ var BaseCrudDialect = class {
|
|
|
710
714
|
const [field, order] = orderByItems[j];
|
|
711
715
|
const op = j === i ? (negateOrderBy ? order === "asc" ? "desc" : "asc" : order) === "asc" ? ">=" : "<=" : "=";
|
|
712
716
|
const fieldDef = requireField(this.schema, model, field);
|
|
713
|
-
const outerAlias =
|
|
714
|
-
const subSelectAlias =
|
|
717
|
+
const outerAlias = this.delegateFieldAlias(model, modelAlias, fieldDef);
|
|
718
|
+
const subSelectAlias = this.delegateFieldAlias(model, subQueryAlias, fieldDef);
|
|
715
719
|
andFilters.push(this.eb(this.eb.ref(`${outerAlias}.${field}`), op, this.buildSelectModel(model, subQueryAlias).select(`${subSelectAlias}.${field}`).where(cursorFilter)));
|
|
716
720
|
}
|
|
717
721
|
filters.push(this.eb.and(andFilters));
|
|
@@ -749,7 +753,7 @@ var BaseCrudDialect = class {
|
|
|
749
753
|
else return this.buildToOneRelationFilter(model, modelAlias, field, fieldDef, { is: null });
|
|
750
754
|
}
|
|
751
755
|
const joinAlias = tmpAlias(`${modelAlias}$${field}`);
|
|
752
|
-
const joinPairs = buildJoinPairs(this.schema, model,
|
|
756
|
+
const joinPairs = buildJoinPairs(this.schema, model, this.delegateFieldAlias(model, modelAlias, fieldDef), field, joinAlias);
|
|
753
757
|
const baseJoin = this.buildSelectModel(fieldDef.type, joinAlias).select(this.eb.lit(1).as("_")).where(() => this.and(...joinPairs.map(([left, right]) => this.eb(this.eb.ref(left), "=", this.eb.ref(right)))));
|
|
754
758
|
const existsSelect = (extraFilter) => {
|
|
755
759
|
const q = extraFilter ? baseJoin.where(extraFilter) : baseJoin;
|
|
@@ -843,11 +847,13 @@ var BaseCrudDialect = class {
|
|
|
843
847
|
buildPrimitiveFilter(fieldRef, fieldDef, payload) {
|
|
844
848
|
if (payload === null) return this.eb(fieldRef, "is", null);
|
|
845
849
|
if (isEnum(this.schema, fieldDef.type)) return this.buildEnumFilter(fieldRef, fieldDef, payload);
|
|
846
|
-
|
|
850
|
+
let type = fieldDef.type;
|
|
851
|
+
if (isTypeDef(this.schema, fieldDef.type)) if (isPrimitiveTypeDef(this.schema, fieldDef.type)) type = this.schema["typeDefs"][fieldDef.type]["base"];
|
|
852
|
+
else {
|
|
847
853
|
if (payload instanceof DbNullClass || payload instanceof JsonNullClass || payload instanceof AnyNullClass) return this.buildJsonValueFilterClause(fieldRef, payload);
|
|
848
854
|
return this.buildJsonFilter(fieldRef, payload, fieldDef);
|
|
849
855
|
}
|
|
850
|
-
return match(
|
|
856
|
+
return match(type).with("String", () => this.buildStringFilter(fieldRef, payload, fieldDef)).with(P.union("Int", "Float", "Decimal", "BigInt"), (type) => this.buildNumberFilter(fieldRef, type, payload)).with("Boolean", () => this.buildBooleanFilter(fieldRef, payload)).with("DateTime", () => this.buildDateTimeFilter(fieldRef, payload)).with("Bytes", () => this.buildBytesFilter(fieldRef, payload)).with("Json", () => this.buildJsonFilter(fieldRef, payload, fieldDef)).with("Unsupported", () => {
|
|
851
857
|
throw createInvalidInputError(`Unsupported field cannot be used in filters`);
|
|
852
858
|
}).exhaustive();
|
|
853
859
|
}
|
|
@@ -947,11 +953,12 @@ var BaseCrudDialect = class {
|
|
|
947
953
|
const fieldDef = typeDef.fields[key];
|
|
948
954
|
invariant(fieldDef, `Field "${key}" not found in type definition "${typeDefName}"`);
|
|
949
955
|
const fieldReceiver = this.buildJsonPathSelection(receiver, `$.${key}`);
|
|
950
|
-
if (isTypeDef(this.schema, fieldDef.type)) clauses.push(this.buildTypedJsonFilter(fieldReceiver, value, fieldDef.type, !!fieldDef.array));
|
|
956
|
+
if (isTypeDef(this.schema, fieldDef.type) && !isPrimitiveTypeDef(this.schema, fieldDef.type)) clauses.push(this.buildTypedJsonFilter(fieldReceiver, value, fieldDef.type, !!fieldDef.array));
|
|
951
957
|
else if (fieldDef.array) clauses.push(this.buildArrayFilter(fieldReceiver, fieldDef, value));
|
|
952
958
|
else {
|
|
959
|
+
const effectiveType = isPrimitiveTypeDef(this.schema, fieldDef.type) ? this.schema.typeDefs[fieldDef.type].base : fieldDef.type;
|
|
953
960
|
let _receiver = fieldReceiver;
|
|
954
|
-
if (
|
|
961
|
+
if (effectiveType === "String" || isEnum(this.schema, effectiveType)) _receiver = this.trimTextQuotes(this.castText(fieldReceiver));
|
|
955
962
|
clauses.push(this.buildPrimitiveFilter(_receiver, fieldDef, value));
|
|
956
963
|
}
|
|
957
964
|
}
|
|
@@ -1095,7 +1102,7 @@ var BaseCrudDialect = class {
|
|
|
1095
1102
|
let result = query;
|
|
1096
1103
|
const buildFieldRef = (model, field, modelAlias, computedArgs) => {
|
|
1097
1104
|
const fieldDef = requireField(this.schema, model, field);
|
|
1098
|
-
return fieldDef.originModel ? this.fieldRef(fieldDef.originModel, field, fieldDef.originModel, true, computedArgs) : this.fieldRef(model, field, modelAlias, true, computedArgs);
|
|
1105
|
+
return fieldDef.originModel ? this.fieldRef(fieldDef.originModel, field, this.delegateJoinAlias(model, modelAlias, fieldDef.originModel), true, computedArgs) : this.fieldRef(model, field, modelAlias, true, computedArgs);
|
|
1099
1106
|
};
|
|
1100
1107
|
enumerate(orderBy).forEach((orderBy, index) => {
|
|
1101
1108
|
for (const [field, value] of Object.entries(orderBy)) {
|
|
@@ -1144,10 +1151,15 @@ var BaseCrudDialect = class {
|
|
|
1144
1151
|
return query;
|
|
1145
1152
|
}
|
|
1146
1153
|
const joinAlias = tmpAlias(`${modelAlias}$ob$${index}`);
|
|
1147
|
-
|
|
1148
|
-
const joinPairs = buildJoinPairs(this.schema, model, modelAlias, field, joinAlias);
|
|
1154
|
+
let joined = query.leftJoin(`${relationModel} as ${joinAlias}`, (join) => {
|
|
1155
|
+
const joinPairs = buildJoinPairs(this.schema, model, this.delegateFieldAlias(model, modelAlias, fieldDef), field, joinAlias);
|
|
1149
1156
|
return join.on((eb) => this.and(...joinPairs.map(([left, right]) => eb(this.eb.ref(left), "=", this.eb.ref(right)))));
|
|
1150
1157
|
});
|
|
1158
|
+
let joinBase = requireModel(this.schema, relationModel).baseModel;
|
|
1159
|
+
while (joinBase) {
|
|
1160
|
+
joined = this.buildDelegateJoin(relationModel, joinAlias, joinBase, joined);
|
|
1161
|
+
joinBase = requireModel(this.schema, joinBase).baseModel;
|
|
1162
|
+
}
|
|
1151
1163
|
return this.buildOrderBy(joined, relationModel, joinAlias, value, negated, take);
|
|
1152
1164
|
}
|
|
1153
1165
|
applyScalarOrderBy(query, model, modelAlias, field, value, negated, buildFieldRef) {
|
|
@@ -1211,12 +1223,13 @@ var BaseCrudDialect = class {
|
|
|
1211
1223
|
const descendants = getDelegateDescendantModels(this.schema, model);
|
|
1212
1224
|
for (const subModel of descendants) {
|
|
1213
1225
|
result = this.buildDelegateJoin(model, modelAlias, subModel.name, result);
|
|
1226
|
+
const subModelAlias = this.delegateJoinAlias(model, modelAlias, subModel.name);
|
|
1214
1227
|
result = result.select(() => {
|
|
1215
1228
|
const jsonObject = {};
|
|
1216
1229
|
for (const fieldDef of getModelFields(this.schema, subModel.name, { computed: true })) {
|
|
1217
1230
|
if (this.shouldOmitField(omit, subModel.name, fieldDef.name)) continue;
|
|
1218
1231
|
if (fieldDef.computed && fieldDef.params) continue;
|
|
1219
|
-
jsonObject[fieldDef.name] = this.fieldRef(subModel.name, fieldDef.name,
|
|
1232
|
+
jsonObject[fieldDef.name] = this.fieldRef(subModel.name, fieldDef.name, subModelAlias);
|
|
1220
1233
|
}
|
|
1221
1234
|
return this.buildJsonObject(jsonObject).as(`${DELEGATE_JOINED_FIELD_PREFIX}${subModel.name}`);
|
|
1222
1235
|
});
|
|
@@ -1239,17 +1252,35 @@ var BaseCrudDialect = class {
|
|
|
1239
1252
|
buildSelectField(query, model, modelAlias, field, computedArgs) {
|
|
1240
1253
|
const fieldDef = requireField(this.schema, model, field);
|
|
1241
1254
|
const fieldModel = fieldDef.originModel ?? model;
|
|
1242
|
-
const alias =
|
|
1255
|
+
const alias = this.delegateFieldAlias(model, modelAlias, fieldDef);
|
|
1243
1256
|
return query.select(() => this.fieldRef(fieldModel, field, alias, true, computedArgs).as(field));
|
|
1244
1257
|
}
|
|
1245
|
-
buildDelegateJoin(thisModel, thisModelAlias,
|
|
1258
|
+
buildDelegateJoin(thisModel, thisModelAlias, otherModel, query) {
|
|
1246
1259
|
const idFields = requireIdFields(this.schema, thisModel);
|
|
1247
|
-
|
|
1260
|
+
const otherModelAlias = this.delegateJoinAlias(thisModel, thisModelAlias, otherModel);
|
|
1261
|
+
const table = otherModelAlias === otherModel ? otherModel : `${otherModel} as ${otherModelAlias}`;
|
|
1262
|
+
query = query.leftJoin(table, (qb) => {
|
|
1248
1263
|
for (const idField of idFields) qb = qb.onRef(`${thisModelAlias}.${idField}`, "=", `${otherModelAlias}.${idField}`);
|
|
1249
1264
|
return qb;
|
|
1250
1265
|
});
|
|
1251
1266
|
return query;
|
|
1252
1267
|
}
|
|
1268
|
+
/**
|
|
1269
|
+
* Gets the alias under which a delegate base or sub model is joined to a model selected as `modelAlias`.
|
|
1270
|
+
* A model selected under its own name (a top-level query) has them joined under their own model names.
|
|
1271
|
+
* A model selected under another alias (a relation subquery) has them joined under aliases derived from
|
|
1272
|
+
* it, so they never shadow a table of an enclosing query in the same delegate hierarchy.
|
|
1273
|
+
*/
|
|
1274
|
+
delegateJoinAlias(model, modelAlias, joinedModel) {
|
|
1275
|
+
return modelAlias === model ? joinedModel : tmpAlias(`${modelAlias}$${joinedModel}`);
|
|
1276
|
+
}
|
|
1277
|
+
/**
|
|
1278
|
+
* Gets the alias of the table holding a field of a model selected as `modelAlias`: the joined base
|
|
1279
|
+
* table for a field inherited from a delegate base, otherwise the model's own table.
|
|
1280
|
+
*/
|
|
1281
|
+
delegateFieldAlias(model, modelAlias, fieldDef) {
|
|
1282
|
+
return fieldDef.originModel ? this.delegateJoinAlias(model, modelAlias, fieldDef.originModel) : modelAlias;
|
|
1283
|
+
}
|
|
1253
1284
|
buildCountJson(model, eb, parentAlias, payload) {
|
|
1254
1285
|
const modelDef = requireModel(this.schema, model);
|
|
1255
1286
|
const toManyRelations = Object.entries(modelDef.fields).filter(([, field]) => field.relation && field.array);
|
|
@@ -1521,9 +1552,10 @@ var MySqlCrudDialect = class extends LateralJoinDialectBase {
|
|
|
1521
1552
|
if (value instanceof JsonNullClass) return this.eb.cast(sql.lit("null"), "json");
|
|
1522
1553
|
else if (value instanceof DbNullClass) return null;
|
|
1523
1554
|
else if (value instanceof AnyNullClass) invariant(false, "should not reach here: AnyNull is not a valid input value");
|
|
1524
|
-
if (isTypeDef(this.schema, type)) if (
|
|
1555
|
+
if (isTypeDef(this.schema, type)) if (isPrimitiveTypeDef(this.schema, type)) type = this.schema["typeDefs"][type]["base"];
|
|
1556
|
+
else if (typeof value !== "string") return this.transformInput(value, "Json", forArrayField);
|
|
1525
1557
|
else return value;
|
|
1526
|
-
|
|
1558
|
+
if (Array.isArray(value)) if (type === "Json") return JSON.stringify(value);
|
|
1527
1559
|
else throw createNotSupportedError(`MySQL does not support array literals`);
|
|
1528
1560
|
else switch (type) {
|
|
1529
1561
|
case "Boolean": return value ? 1 : 0;
|
|
@@ -1538,6 +1570,7 @@ var MySqlCrudDialect = class extends LateralJoinDialectBase {
|
|
|
1538
1570
|
}
|
|
1539
1571
|
transformOutput(value, type, array) {
|
|
1540
1572
|
if (value === null || value === void 0) return value;
|
|
1573
|
+
if (isPrimitiveTypeDef(this.schema, type)) return this.transformOutput(value, this.schema.typeDefs[type].base, array);
|
|
1541
1574
|
switch (type) {
|
|
1542
1575
|
case "Boolean": return this.transformOutputBoolean(value);
|
|
1543
1576
|
case "DateTime": return this.transformOutputDate(value);
|
|
@@ -1566,7 +1599,12 @@ var MySqlCrudDialect = class extends LateralJoinDialectBase {
|
|
|
1566
1599
|
return new Date(!anchored.endsWith("Z") ? anchored + "Z" : anchored);
|
|
1567
1600
|
}
|
|
1568
1601
|
transformOutputBytes(value) {
|
|
1569
|
-
|
|
1602
|
+
if (Buffer.isBuffer(value)) return Uint8Array.from(value);
|
|
1603
|
+
if (typeof value === "string") {
|
|
1604
|
+
const match = /^base64:type\d+:(.*)$/s.exec(value);
|
|
1605
|
+
if (match) return Uint8Array.from(Buffer.from(match[1], "base64"));
|
|
1606
|
+
}
|
|
1607
|
+
return value;
|
|
1570
1608
|
}
|
|
1571
1609
|
buildExistsExpression(innerQuery) {
|
|
1572
1610
|
return this.eb.exists(this.eb.selectFrom(innerQuery.as("$exists_sub")).select(this.eb.lit(1).as("_")));
|
|
@@ -1778,9 +1816,10 @@ var PostgresCrudDialect = class PostgresCrudDialect extends LateralJoinDialectBa
|
|
|
1778
1816
|
if (value instanceof JsonNullClass) return "null";
|
|
1779
1817
|
else if (value instanceof DbNullClass) return null;
|
|
1780
1818
|
else if (value instanceof AnyNullClass) invariant(false, "should not reach here: AnyNull is not a valid input value");
|
|
1781
|
-
if (isTypeDef(this.schema, type)) if (
|
|
1819
|
+
if (isTypeDef(this.schema, type)) if (isPrimitiveTypeDef(this.schema, type)) type = this.schema["typeDefs"][type]["base"];
|
|
1820
|
+
else if (typeof value !== "string") return JSON.stringify(value);
|
|
1782
1821
|
else return value;
|
|
1783
|
-
|
|
1822
|
+
if (Array.isArray(value)) if (type === "Json" && !forArrayField) return JSON.stringify(value);
|
|
1784
1823
|
else return value.map((v) => this.transformInput(v, type, false, fieldDef));
|
|
1785
1824
|
else switch (type) {
|
|
1786
1825
|
case "DateTime": {
|
|
@@ -1798,6 +1837,7 @@ var PostgresCrudDialect = class PostgresCrudDialect extends LateralJoinDialectBa
|
|
|
1798
1837
|
}
|
|
1799
1838
|
transformOutput(value, type, array) {
|
|
1800
1839
|
if (value === null || value === void 0) return value;
|
|
1840
|
+
if (isPrimitiveTypeDef(this.schema, type)) return this.transformOutput(value, this.schema.typeDefs[type].base, array);
|
|
1801
1841
|
switch (type) {
|
|
1802
1842
|
case "DateTime": return this.transformOutputDate(value);
|
|
1803
1843
|
case "Bytes": return this.transformOutputBytes(value);
|
|
@@ -1910,6 +1950,7 @@ var PostgresCrudDialect = class PostgresCrudDialect extends LateralJoinDialectBa
|
|
|
1910
1950
|
const mapped = PostgresCrudDialect.dbAttributeToSqlTypeMap[attr.name];
|
|
1911
1951
|
if (mapped) return mapped;
|
|
1912
1952
|
}
|
|
1953
|
+
if (isPrimitiveTypeDef(this.schema, zmodelType)) zmodelType = this.schema.typeDefs[zmodelType].base;
|
|
1913
1954
|
if (isEnum(this.schema, zmodelType)) return "text";
|
|
1914
1955
|
else return this.zmodelToSqlTypeMap[zmodelType] ?? "text";
|
|
1915
1956
|
}
|
|
@@ -2093,7 +2134,9 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
2093
2134
|
if (value instanceof JsonNullClass) return "null";
|
|
2094
2135
|
else if (value instanceof DbNullClass) return null;
|
|
2095
2136
|
else if (value instanceof AnyNullClass) invariant(false, "should not reach here: AnyNull is not a valid input value");
|
|
2096
|
-
if (type
|
|
2137
|
+
if (isTypeDef(this.schema, type)) if (isPrimitiveTypeDef(this.schema, type)) type = this.schema.typeDefs[type].base;
|
|
2138
|
+
else return JSON.stringify(value);
|
|
2139
|
+
if (type === "Json") return JSON.stringify(value);
|
|
2097
2140
|
if (Array.isArray(value)) return value.map((v) => this.transformInput(v, type, false));
|
|
2098
2141
|
else switch (type) {
|
|
2099
2142
|
case "Boolean": return value ? 1 : 0;
|
|
@@ -2105,8 +2148,10 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
2105
2148
|
}
|
|
2106
2149
|
transformOutput(value, type, array) {
|
|
2107
2150
|
if (value === null || value === void 0) return value;
|
|
2108
|
-
else if (this.schema.typeDefs && type in this.schema.typeDefs)
|
|
2109
|
-
|
|
2151
|
+
else if (this.schema.typeDefs && type in this.schema.typeDefs) {
|
|
2152
|
+
if (isPrimitiveTypeDef(this.schema, type)) return this.transformOutput(value, this.schema.typeDefs[type].base, array);
|
|
2153
|
+
return this.transformOutputJson(value);
|
|
2154
|
+
} else switch (type) {
|
|
2110
2155
|
case "Boolean": return this.transformOutputBoolean(value);
|
|
2111
2156
|
case "DateTime": return this.transformOutputDate(value);
|
|
2112
2157
|
case "Bytes": return this.transformOutputBytes(value);
|
|
@@ -2354,6 +2399,20 @@ function createQuerySchemaFactory(clientOrSchema, options) {
|
|
|
2354
2399
|
return new ZodSchemaFactory(clientOrSchema, options);
|
|
2355
2400
|
}
|
|
2356
2401
|
/**
|
|
2402
|
+
* Whether two client options produce the same query-args schemas, i.e. a `ZodSchemaFactory`
|
|
2403
|
+
* built for one can serve the other. Only `omit`, `slicing`, `allowQueryTimeOmitOverride` and
|
|
2404
|
+
* the plugins that extend query args or results shape the schemas; dialect, auth, hooks and
|
|
2405
|
+
* validation flags do not.
|
|
2406
|
+
*/
|
|
2407
|
+
function haveSameSchemaInputs(a, b) {
|
|
2408
|
+
if (a === b) return true;
|
|
2409
|
+
if (a.omit !== b.omit || a.slicing !== b.slicing || a.allowQueryTimeOmitOverride !== b.allowQueryTimeOmitOverride) return false;
|
|
2410
|
+
const shaping = (options) => (options.plugins ?? []).filter((plugin) => plugin.queryArgs || plugin.result);
|
|
2411
|
+
const pa = shaping(a);
|
|
2412
|
+
const pb = shaping(b);
|
|
2413
|
+
return pa.length === pb.length && pa.every((plugin, index) => plugin === pb[index]);
|
|
2414
|
+
}
|
|
2415
|
+
/**
|
|
2357
2416
|
* Builds a `DateTime` value schema that accepts a `Date` object or any string
|
|
2358
2417
|
* the JS `Date` constructor parses, and coerces it to a `Date`. ISO datetime,
|
|
2359
2418
|
* ISO date, and time-only strings (e.g. `"09:00:00"` for `@db.Time` fields,
|
|
@@ -2365,7 +2424,7 @@ function createQuerySchemaFactory(clientOrSchema, options) {
|
|
|
2365
2424
|
* @see https://github.com/zenstackhq/zenstack/issues/2631
|
|
2366
2425
|
*/
|
|
2367
2426
|
function coercedDateTimeSchema() {
|
|
2368
|
-
return z.preprocess((val) => {
|
|
2427
|
+
return z$1.preprocess((val) => {
|
|
2369
2428
|
if (typeof val !== "string") return val;
|
|
2370
2429
|
if (/^\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d\d(?::\d\d)?)?$/.test(val)) {
|
|
2371
2430
|
const hasTz = val.endsWith("Z") || /[+-]\d\d(?::\d\d)?$/.test(val);
|
|
@@ -2374,10 +2433,10 @@ function coercedDateTimeSchema() {
|
|
|
2374
2433
|
}
|
|
2375
2434
|
const d = new Date(val);
|
|
2376
2435
|
return isNaN(d.getTime()) ? val : d;
|
|
2377
|
-
}, z.union([
|
|
2378
|
-
z.iso.datetime(),
|
|
2379
|
-
z.iso.date(),
|
|
2380
|
-
z.date()
|
|
2436
|
+
}, z$1.union([
|
|
2437
|
+
z$1.iso.datetime(),
|
|
2438
|
+
z$1.iso.date(),
|
|
2439
|
+
z$1.date()
|
|
2381
2440
|
]));
|
|
2382
2441
|
}
|
|
2383
2442
|
/**
|
|
@@ -2385,7 +2444,7 @@ function coercedDateTimeSchema() {
|
|
|
2385
2444
|
*/
|
|
2386
2445
|
var ZodSchemaFactory = class {
|
|
2387
2446
|
schemaCache = /* @__PURE__ */ new Map();
|
|
2388
|
-
schemaRegistry = z.registry();
|
|
2447
|
+
schemaRegistry = z$1.registry();
|
|
2389
2448
|
allFilterKinds = [...new Set(Object.values(FILTER_PROPERTY_TO_KIND))];
|
|
2390
2449
|
schema;
|
|
2391
2450
|
options;
|
|
@@ -2477,7 +2536,7 @@ var ZodSchemaFactory = class {
|
|
|
2477
2536
|
this.makeGroupBySchema(m);
|
|
2478
2537
|
}
|
|
2479
2538
|
for (const procName of Object.keys(this.schema.procedures ?? {})) if (this.isProcedureAllowed(procName)) this.makeProcedureArgsSchema(procName);
|
|
2480
|
-
return z.toJSONSchema(this.schemaRegistry, { unrepresentable: "any" });
|
|
2539
|
+
return z$1.toJSONSchema(this.schemaRegistry, { unrepresentable: "any" });
|
|
2481
2540
|
}
|
|
2482
2541
|
get cacheStats() {
|
|
2483
2542
|
return {
|
|
@@ -2506,13 +2565,13 @@ var ZodSchemaFactory = class {
|
|
|
2506
2565
|
fields["omit"] = this.makeOmitSchema(model).optional().nullable();
|
|
2507
2566
|
if (!unique) {
|
|
2508
2567
|
fields["skip"] = this.makeSkipSchema().optional();
|
|
2509
|
-
if (findOne) fields["take"] = z.literal(1).optional();
|
|
2568
|
+
if (findOne) fields["take"] = z$1.literal(1).optional();
|
|
2510
2569
|
else fields["take"] = this.makeTakeSchema().optional();
|
|
2511
2570
|
fields["orderBy"] = this.orArray(this.makeOrderBySchema(model, true, false, options), true).optional();
|
|
2512
2571
|
fields["cursor"] = this.makeCursorSchema(model, options).optional();
|
|
2513
2572
|
fields["distinct"] = this.makeDistinctSchema(model).optional();
|
|
2514
2573
|
}
|
|
2515
|
-
const baseSchema = z.strictObject(fields);
|
|
2574
|
+
const baseSchema = z$1.strictObject(fields);
|
|
2516
2575
|
let result = this.mergePluginArgsSchema(baseSchema, operation);
|
|
2517
2576
|
result = this.refineForSelectIncludeMutuallyExclusive(result);
|
|
2518
2577
|
result = this.refineForSelectOmitMutuallyExclusive(result);
|
|
@@ -2522,27 +2581,27 @@ var ZodSchemaFactory = class {
|
|
|
2522
2581
|
return result;
|
|
2523
2582
|
}
|
|
2524
2583
|
makeExistsSchema(model, options) {
|
|
2525
|
-
const baseSchema = z.strictObject({ where: this.makeWhereSchema(model, false, false, false, options).optional() });
|
|
2584
|
+
const baseSchema = z$1.strictObject({ where: this.makeWhereSchema(model, false, false, false, options).optional() });
|
|
2526
2585
|
const result = this.mergePluginArgsSchema(baseSchema, "exists").optional();
|
|
2527
2586
|
this.registerSchema(`${model}ExistsArgs`, result);
|
|
2528
2587
|
return result;
|
|
2529
2588
|
}
|
|
2530
2589
|
makeScalarSchema(type, attributes) {
|
|
2531
|
-
if (this.schema.typeDefs && type in this.schema.typeDefs) return this.makeTypeDefSchema(type);
|
|
2590
|
+
if (this.schema.typeDefs && type in this.schema.typeDefs) return this.schema.typeDefs[type].base ? this.makeTypeDefSchema(type, attributes) : this.makeTypeDefSchema(type);
|
|
2532
2591
|
else if (this.schema.enums && type in this.schema.enums) return this.makeEnumSchema(type);
|
|
2533
|
-
else return match(type).with("String", () => this.extraValidationsEnabled ? ZodUtils.addStringValidation(z.string(), attributes) : z.string()).with("Int", () => this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z.number().int(), attributes) : z.number().int()).with("Float", () => this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z.number(), attributes) : z.number()).with("Boolean", () => z.boolean()).with("BigInt", () => z.union([this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z.number().int(), attributes) : z.number().int(), this.extraValidationsEnabled ? ZodUtils.addBigIntValidation(z.bigint(), attributes) : z.bigint()])).with("Decimal", () => {
|
|
2534
|
-
return z.union([
|
|
2535
|
-
this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z.number(), attributes) : z.number(),
|
|
2536
|
-
ZodUtils.addDecimalValidation(z.instanceof(Decimal), attributes, this.extraValidationsEnabled),
|
|
2537
|
-
ZodUtils.addDecimalValidation(z.string(), attributes, this.extraValidationsEnabled)
|
|
2592
|
+
else return match(type).with("String", () => this.extraValidationsEnabled ? ZodUtils.addStringValidation(z$1.string(), attributes) : z$1.string()).with("Int", () => this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z$1.number().int(), attributes) : z$1.number().int()).with("Float", () => this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z$1.number(), attributes) : z$1.number()).with("Boolean", () => z$1.boolean()).with("BigInt", () => z$1.union([this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z$1.number().int(), attributes) : z$1.number().int(), this.extraValidationsEnabled ? ZodUtils.addBigIntValidation(z$1.bigint(), attributes) : z$1.bigint()])).with("Decimal", () => {
|
|
2593
|
+
return z$1.union([
|
|
2594
|
+
this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z$1.number(), attributes) : z$1.number(),
|
|
2595
|
+
ZodUtils.addDecimalValidation(z$1.instanceof(Decimal), attributes, this.extraValidationsEnabled),
|
|
2596
|
+
ZodUtils.addDecimalValidation(z$1.string(), attributes, this.extraValidationsEnabled)
|
|
2538
2597
|
]);
|
|
2539
|
-
}).with("DateTime", () => this.makeDateTimeValueSchema()).with("Bytes", () => z.instanceof(Uint8Array)).with("Json", () => this.makeJsonValueSchema()).otherwise(() => z.unknown());
|
|
2598
|
+
}).with("DateTime", () => this.makeDateTimeValueSchema()).with("Bytes", () => z$1.instanceof(Uint8Array)).with("Json", () => this.makeJsonValueSchema()).otherwise(() => z$1.unknown());
|
|
2540
2599
|
}
|
|
2541
2600
|
isParameterizedComputedField(fieldDef) {
|
|
2542
2601
|
return !!(fieldDef.computed && fieldDef.params);
|
|
2543
2602
|
}
|
|
2544
2603
|
makeFieldArgsSchema(params) {
|
|
2545
|
-
return z.strictObject(Object.fromEntries(Object.entries(params).map(([name, param]) => {
|
|
2604
|
+
return z$1.strictObject(Object.fromEntries(Object.entries(params).map(([name, param]) => {
|
|
2546
2605
|
let paramSchema = this.makeScalarSchema(param.type);
|
|
2547
2606
|
if (param.array) paramSchema = paramSchema.array();
|
|
2548
2607
|
if (param.optional) paramSchema = paramSchema.optional();
|
|
@@ -2550,9 +2609,9 @@ var ZodSchemaFactory = class {
|
|
|
2550
2609
|
})));
|
|
2551
2610
|
}
|
|
2552
2611
|
addComputedArgsToFilter(filterSchema, params) {
|
|
2553
|
-
const objectMembers = (filterSchema instanceof z.ZodUnion ? filterSchema.options : [filterSchema]).filter((m) => m instanceof z.ZodObject);
|
|
2612
|
+
const objectMembers = (filterSchema instanceof z$1.ZodUnion ? filterSchema.options : [filterSchema]).filter((m) => m instanceof z$1.ZodObject);
|
|
2554
2613
|
const components = Object.assign({}, ...objectMembers.map((o) => o.shape));
|
|
2555
|
-
return z.strictObject({
|
|
2614
|
+
return z$1.strictObject({
|
|
2556
2615
|
args: this.makeFieldArgsSchema(params),
|
|
2557
2616
|
...components
|
|
2558
2617
|
});
|
|
@@ -2560,20 +2619,32 @@ var ZodSchemaFactory = class {
|
|
|
2560
2619
|
makeEnumSchema(_enum) {
|
|
2561
2620
|
const enumDef = getEnum(this.schema, _enum);
|
|
2562
2621
|
invariant(enumDef, `Enum "${_enum}" not found in schema`);
|
|
2563
|
-
const schema = z.enum(Object.keys(enumDef.values));
|
|
2622
|
+
const schema = z$1.enum(Object.keys(enumDef.values));
|
|
2564
2623
|
this.registerSchema(_enum, schema);
|
|
2565
2624
|
return schema;
|
|
2566
2625
|
}
|
|
2567
|
-
|
|
2626
|
+
/**
|
|
2627
|
+
* Attributes to validate each value of a scalar field against. For typedef list fields, the
|
|
2628
|
+
* field's own attributes (e.g. `@length`) validate the list rather than its items.
|
|
2629
|
+
*/
|
|
2630
|
+
getItemAttributes(fieldDef) {
|
|
2631
|
+
return fieldDef.array && isTypeDef(this.schema, fieldDef.type) ? void 0 : fieldDef.attributes;
|
|
2632
|
+
}
|
|
2633
|
+
makeTypeDefSchema(type, fieldAttributes) {
|
|
2568
2634
|
const typeDef = getTypeDef(this.schema, type);
|
|
2569
2635
|
invariant(typeDef, `Type definition "${type}" not found in schema`);
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2636
|
+
if (typeDef.base) {
|
|
2637
|
+
const schema = this.makeScalarSchema(typeDef.base, [...typeDef.fields["this"]?.attributes ?? [], ...fieldAttributes ?? []]);
|
|
2638
|
+
return this.extraValidationsEnabled ? ZodUtils.addCustomValidation(schema, typeDef.attributes) : schema;
|
|
2639
|
+
}
|
|
2640
|
+
const objectSchema = (typeDef.strict ? z$1.strictObject : z$1.looseObject)(Object.fromEntries(Object.entries(typeDef.fields).map(([field, def]) => {
|
|
2641
|
+
let fieldSchema = isTypeDef(this.schema, def.type) && !isPrimitiveTypeDef(this.schema, def.type) ? z$1.lazy(() => this.makeTypeDefSchema(def.type)) : this.makeScalarSchema(def.type, this.getItemAttributes(def));
|
|
2642
|
+
if (def.array) fieldSchema = ZodUtils.addListValidation(fieldSchema.array(), def.attributes);
|
|
2573
2643
|
if (def.optional) fieldSchema = fieldSchema.nullish();
|
|
2574
2644
|
return [field, fieldSchema];
|
|
2575
2645
|
})));
|
|
2576
|
-
const
|
|
2646
|
+
const schema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(objectSchema, typeDef.attributes) : objectSchema;
|
|
2647
|
+
const finalSchema = z$1.any().superRefine((value, ctx) => {
|
|
2577
2648
|
const parseResult = schema.safeParse(value);
|
|
2578
2649
|
if (!parseResult.success) parseResult.error.issues.forEach((issue) => ctx.addIssue(issue));
|
|
2579
2650
|
});
|
|
@@ -2589,17 +2660,17 @@ var ZodSchemaFactory = class {
|
|
|
2589
2660
|
if (fieldDef.relation) {
|
|
2590
2661
|
if (withoutRelationFields || !this.shouldIncludeRelations(options)) continue;
|
|
2591
2662
|
const allowedFilterKinds = this.getEffectiveFilterKinds(model, field);
|
|
2592
|
-
if (allowedFilterKinds && !allowedFilterKinds.includes("Relation")) fieldSchema = z.never();
|
|
2663
|
+
if (allowedFilterKinds && !allowedFilterKinds.includes("Relation")) fieldSchema = z$1.never();
|
|
2593
2664
|
else {
|
|
2594
|
-
fieldSchema = z.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts).optional());
|
|
2595
|
-
if (fieldDef.array) fieldSchema = z.strictObject({
|
|
2665
|
+
fieldSchema = z$1.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts).optional());
|
|
2666
|
+
if (fieldDef.array) fieldSchema = z$1.strictObject({
|
|
2596
2667
|
some: fieldSchema.optional(),
|
|
2597
2668
|
every: fieldSchema.optional(),
|
|
2598
2669
|
none: fieldSchema.optional()
|
|
2599
2670
|
});
|
|
2600
2671
|
else {
|
|
2601
2672
|
fieldSchema = this.nullableIf(fieldSchema, !fieldDef.array && !!fieldDef.optional);
|
|
2602
|
-
fieldSchema = z.union([fieldSchema, z.strictObject({
|
|
2673
|
+
fieldSchema = z$1.union([fieldSchema, z$1.strictObject({
|
|
2603
2674
|
is: fieldSchema.optional(),
|
|
2604
2675
|
isNot: fieldSchema.optional()
|
|
2605
2676
|
})]);
|
|
@@ -2611,29 +2682,29 @@ var ZodSchemaFactory = class {
|
|
|
2611
2682
|
if (enumDef) {
|
|
2612
2683
|
if (Object.keys(enumDef.values).length > 0) fieldSchema = this.makeEnumFilterSchema(fieldDef.type, !!fieldDef.optional, !!fieldDef.array, withAggregations, allowedFilterKinds);
|
|
2613
2684
|
} else if (fieldDef.array) fieldSchema = this.makeArrayFilterSchema(fieldDef.type, allowedFilterKinds);
|
|
2614
|
-
else if (this.isTypeDefType(fieldDef.type)) fieldSchema = this.makeTypedJsonFilterSchema(fieldDef.type, !!fieldDef.optional, !!fieldDef.array, allowedFilterKinds);
|
|
2615
|
-
else fieldSchema = this.makePrimitiveFilterSchema(fieldDef.type, !!fieldDef.optional, withAggregations, allowedFilterKinds, !!fieldDef.fuzzy, !!fieldDef.fullText);
|
|
2685
|
+
else if (this.isTypeDefType(fieldDef.type) && !isPrimitiveTypeDef(this.schema, fieldDef.type)) fieldSchema = this.makeTypedJsonFilterSchema(fieldDef.type, !!fieldDef.optional, !!fieldDef.array, allowedFilterKinds);
|
|
2686
|
+
else fieldSchema = this.makePrimitiveFilterSchema(this.getEffectiveFieldType(fieldDef.type), !!fieldDef.optional, withAggregations, allowedFilterKinds, !!fieldDef.fuzzy, !!fieldDef.fullText);
|
|
2616
2687
|
}
|
|
2617
2688
|
if (fieldSchema && this.isParameterizedComputedField(fieldDef)) fieldSchema = this.addComputedArgsToFilter(fieldSchema, fieldDef.params);
|
|
2618
2689
|
if (fieldSchema) fields[field] = fieldSchema.optional();
|
|
2619
2690
|
}
|
|
2620
2691
|
if (unique) {
|
|
2621
2692
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
2622
|
-
for (const uniqueField of uniqueFields) if ("defs" in uniqueField) fields[uniqueField.name] = z.object(Object.fromEntries(Object.entries(uniqueField.defs).map(([key, def]) => {
|
|
2693
|
+
for (const uniqueField of uniqueFields) if ("defs" in uniqueField) fields[uniqueField.name] = z$1.object(Object.fromEntries(Object.entries(uniqueField.defs).map(([key, def]) => {
|
|
2623
2694
|
invariant(!def.relation, "unique field cannot be a relation");
|
|
2624
2695
|
let fieldSchema;
|
|
2625
2696
|
const enumDef = getEnum(this.schema, def.type);
|
|
2626
2697
|
if (enumDef) if (Object.keys(enumDef.values).length > 0) fieldSchema = this.makeEnumFilterSchema(def.type, !!def.optional, !!def.array, false, void 0);
|
|
2627
|
-
else fieldSchema = z.never();
|
|
2698
|
+
else fieldSchema = z$1.never();
|
|
2628
2699
|
else fieldSchema = this.makePrimitiveFilterSchema(def.type, !!def.optional, false, void 0);
|
|
2629
2700
|
return [key, fieldSchema];
|
|
2630
2701
|
}))).optional();
|
|
2631
2702
|
}
|
|
2632
|
-
fields["$expr"] = z.custom((v) => typeof v === "function", { error: "\"$expr\" must be a function" }).optional();
|
|
2633
|
-
fields["AND"] = this.orArray(z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
|
|
2634
|
-
fields["OR"] = z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)).array().optional();
|
|
2635
|
-
fields["NOT"] = this.orArray(z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
|
|
2636
|
-
const baseWhere = z.strictObject(fields);
|
|
2703
|
+
fields["$expr"] = z$1.custom((v) => typeof v === "function", { error: "\"$expr\" must be a function" }).optional();
|
|
2704
|
+
fields["AND"] = this.orArray(z$1.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
|
|
2705
|
+
fields["OR"] = z$1.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)).array().optional();
|
|
2706
|
+
fields["NOT"] = this.orArray(z$1.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
|
|
2707
|
+
const baseWhere = z$1.strictObject(fields);
|
|
2637
2708
|
let result = baseWhere;
|
|
2638
2709
|
if (unique) {
|
|
2639
2710
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
@@ -2655,30 +2726,30 @@ var ZodSchemaFactory = class {
|
|
|
2655
2726
|
const candidates = [];
|
|
2656
2727
|
if (!array) {
|
|
2657
2728
|
const fieldSchemas = {};
|
|
2658
|
-
for (const [fieldName, fieldDef] of Object.entries(typeDef.fields)) if (this.isTypeDefType(fieldDef.type)) fieldSchemas[fieldName] = this.makeTypedJsonFilterSchema(fieldDef.type, !!fieldDef.optional, !!fieldDef.array, void 0).optional();
|
|
2729
|
+
for (const [fieldName, fieldDef] of Object.entries(typeDef.fields)) if (this.isTypeDefType(fieldDef.type) && !isPrimitiveTypeDef(this.schema, fieldDef.type)) fieldSchemas[fieldName] = this.makeTypedJsonFilterSchema(fieldDef.type, !!fieldDef.optional, !!fieldDef.array, void 0).optional();
|
|
2659
2730
|
else if (getEnum(this.schema, fieldDef.type)) fieldSchemas[fieldName] = this.makeEnumFilterSchema(fieldDef.type, !!fieldDef.optional, !!fieldDef.array, false, void 0).optional();
|
|
2660
2731
|
else if (fieldDef.array) fieldSchemas[fieldName] = this.makeArrayFilterSchema(fieldDef.type, void 0).optional();
|
|
2661
|
-
else fieldSchemas[fieldName] = this.makePrimitiveFilterSchema(fieldDef.type, !!fieldDef.optional, false, void 0).optional();
|
|
2662
|
-
candidates.push(z.strictObject(fieldSchemas));
|
|
2732
|
+
else fieldSchemas[fieldName] = this.makePrimitiveFilterSchema(this.getEffectiveFieldType(fieldDef.type), !!fieldDef.optional, false, void 0).optional();
|
|
2733
|
+
candidates.push(z$1.strictObject(fieldSchemas));
|
|
2663
2734
|
}
|
|
2664
|
-
const recursiveSchema = z.lazy(() => this.makeTypedJsonFilterSchema(type, optional, false, allowedFilterKinds)).optional();
|
|
2665
|
-
if (array) candidates.push(z.strictObject({
|
|
2735
|
+
const recursiveSchema = z$1.lazy(() => this.makeTypedJsonFilterSchema(type, optional, false, allowedFilterKinds)).optional();
|
|
2736
|
+
if (array) candidates.push(z$1.strictObject({
|
|
2666
2737
|
some: recursiveSchema,
|
|
2667
2738
|
every: recursiveSchema,
|
|
2668
2739
|
none: recursiveSchema
|
|
2669
2740
|
}));
|
|
2670
|
-
else candidates.push(z.strictObject({
|
|
2741
|
+
else candidates.push(z$1.strictObject({
|
|
2671
2742
|
is: recursiveSchema,
|
|
2672
2743
|
isNot: recursiveSchema
|
|
2673
2744
|
}));
|
|
2674
2745
|
candidates.push(this.makeJsonFilterSchema(optional, allowedFilterKinds));
|
|
2675
2746
|
if (optional) {
|
|
2676
|
-
candidates.push(z.null());
|
|
2677
|
-
candidates.push(z.instanceof(DbNullClass));
|
|
2678
|
-
candidates.push(z.instanceof(JsonNullClass));
|
|
2679
|
-
candidates.push(z.instanceof(AnyNullClass));
|
|
2747
|
+
candidates.push(z$1.null());
|
|
2748
|
+
candidates.push(z$1.instanceof(DbNullClass));
|
|
2749
|
+
candidates.push(z$1.instanceof(JsonNullClass));
|
|
2750
|
+
candidates.push(z$1.instanceof(AnyNullClass));
|
|
2680
2751
|
}
|
|
2681
|
-
const result = z.union(candidates);
|
|
2752
|
+
const result = z$1.union(candidates);
|
|
2682
2753
|
this.registerSchema(`${type}Filter${this.filterSchemaSuffix({
|
|
2683
2754
|
optional,
|
|
2684
2755
|
array,
|
|
@@ -2687,7 +2758,7 @@ var ZodSchemaFactory = class {
|
|
|
2687
2758
|
return result;
|
|
2688
2759
|
}
|
|
2689
2760
|
makeNullableTypedJsonMutationSchema(fieldSchema) {
|
|
2690
|
-
return z.any().superRefine((value, ctx) => {
|
|
2761
|
+
return z$1.any().superRefine((value, ctx) => {
|
|
2691
2762
|
if (value instanceof DbNullClass || value instanceof JsonNullClass || value === null || value === void 0) return;
|
|
2692
2763
|
const parseResult = fieldSchema.safeParse(value);
|
|
2693
2764
|
if (!parseResult.success) parseResult.error.issues.forEach((issue) => ctx.addIssue(issue));
|
|
@@ -2696,14 +2767,18 @@ var ZodSchemaFactory = class {
|
|
|
2696
2767
|
isTypeDefType(type) {
|
|
2697
2768
|
return this.schema.typeDefs && type in this.schema.typeDefs;
|
|
2698
2769
|
}
|
|
2770
|
+
getEffectiveFieldType(type) {
|
|
2771
|
+
if (isPrimitiveTypeDef(this.schema, type)) return this.schema.typeDefs[type].base;
|
|
2772
|
+
return type;
|
|
2773
|
+
}
|
|
2699
2774
|
makeEnumFilterSchema(enumName, optional, array, withAggregations, allowedFilterKinds) {
|
|
2700
2775
|
const enumDef = getEnum(this.schema, enumName);
|
|
2701
2776
|
invariant(enumDef, `Enum "${enumName}" not found in schema`);
|
|
2702
|
-
const baseSchema = z.enum(Object.keys(enumDef.values));
|
|
2777
|
+
const baseSchema = z$1.enum(Object.keys(enumDef.values));
|
|
2703
2778
|
let schema;
|
|
2704
2779
|
if (array) schema = this.internalMakeArrayFilterSchema(baseSchema, allowedFilterKinds);
|
|
2705
2780
|
else {
|
|
2706
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z.lazy(() => this.makeEnumFilterSchema(enumName, optional, array, withAggregations, allowedFilterKinds)), [
|
|
2781
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z$1.lazy(() => this.makeEnumFilterSchema(enumName, optional, array, withAggregations, allowedFilterKinds)), [
|
|
2707
2782
|
"equals",
|
|
2708
2783
|
"in",
|
|
2709
2784
|
"notIn",
|
|
@@ -2737,42 +2812,42 @@ var ZodSchemaFactory = class {
|
|
|
2737
2812
|
has: elementSchema.optional(),
|
|
2738
2813
|
hasEvery: elementSchema.array().optional(),
|
|
2739
2814
|
hasSome: elementSchema.array().optional(),
|
|
2740
|
-
isEmpty: z.boolean().optional()
|
|
2815
|
+
isEmpty: z$1.boolean().optional()
|
|
2741
2816
|
};
|
|
2742
2817
|
const filteredOperators = this.trimFilterOperators(operators, allowedFilterKinds);
|
|
2743
|
-
return z.strictObject(filteredOperators);
|
|
2818
|
+
return z$1.strictObject(filteredOperators);
|
|
2744
2819
|
}
|
|
2745
2820
|
makePrimitiveFilterSchema(type, optional, withAggregations, allowedFilterKinds, withFuzzy = false, withFullText = false) {
|
|
2746
|
-
return match(type).with("String", () => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy, withFullText)).with(P.union("Int", "Float", "Decimal", "BigInt"), (type) => this.makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds)).with("Boolean", () => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)).with("DateTime", () => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)).with("Bytes", () => this.makeBytesFilterSchema(optional, withAggregations, allowedFilterKinds)).with("Json", () => this.makeJsonFilterSchema(optional, allowedFilterKinds)).with("Unsupported", () => z.never()).exhaustive();
|
|
2821
|
+
return match(type).with("String", () => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy, withFullText)).with(P.union("Int", "Float", "Decimal", "BigInt"), (type) => this.makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds)).with("Boolean", () => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)).with("DateTime", () => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)).with("Bytes", () => this.makeBytesFilterSchema(optional, withAggregations, allowedFilterKinds)).with("Json", () => this.makeJsonFilterSchema(optional, allowedFilterKinds)).with("Unsupported", () => z$1.never()).exhaustive();
|
|
2747
2822
|
}
|
|
2748
2823
|
makeJsonValueSchema() {
|
|
2749
|
-
const schema = z.union([
|
|
2750
|
-
z.string(),
|
|
2751
|
-
z.number(),
|
|
2752
|
-
z.boolean(),
|
|
2753
|
-
z.instanceof(JsonNullClass),
|
|
2754
|
-
z.lazy(() => z.union([this.makeJsonValueSchema(), z.null()]).array()),
|
|
2755
|
-
z.record(z.string(), z.lazy(() => z.union([this.makeJsonValueSchema(), z.null()])))
|
|
2824
|
+
const schema = z$1.union([
|
|
2825
|
+
z$1.string(),
|
|
2826
|
+
z$1.number(),
|
|
2827
|
+
z$1.boolean(),
|
|
2828
|
+
z$1.instanceof(JsonNullClass),
|
|
2829
|
+
z$1.lazy(() => z$1.union([this.makeJsonValueSchema(), z$1.null()]).array()),
|
|
2830
|
+
z$1.record(z$1.string(), z$1.lazy(() => z$1.union([this.makeJsonValueSchema(), z$1.null()])))
|
|
2756
2831
|
]);
|
|
2757
2832
|
this.registerSchema("JsonValue", schema);
|
|
2758
2833
|
return schema;
|
|
2759
2834
|
}
|
|
2760
2835
|
makeJsonFilterSchema(optional, allowedFilterKinds) {
|
|
2761
|
-
if (allowedFilterKinds && !allowedFilterKinds.includes("Json")) return z.never();
|
|
2836
|
+
if (allowedFilterKinds && !allowedFilterKinds.includes("Json")) return z$1.never();
|
|
2762
2837
|
const filterMembers = [
|
|
2763
2838
|
this.makeJsonValueSchema(),
|
|
2764
|
-
z.instanceof(DbNullClass),
|
|
2765
|
-
z.instanceof(AnyNullClass)
|
|
2839
|
+
z$1.instanceof(DbNullClass),
|
|
2840
|
+
z$1.instanceof(AnyNullClass)
|
|
2766
2841
|
];
|
|
2767
|
-
if (optional) filterMembers.push(z.null());
|
|
2768
|
-
const filterValueSchema = z.union(filterMembers);
|
|
2769
|
-
const schema = z.strictObject({
|
|
2770
|
-
path: z.string().optional(),
|
|
2842
|
+
if (optional) filterMembers.push(z$1.null());
|
|
2843
|
+
const filterValueSchema = z$1.union(filterMembers);
|
|
2844
|
+
const schema = z$1.strictObject({
|
|
2845
|
+
path: z$1.string().optional(),
|
|
2771
2846
|
equals: filterValueSchema.optional(),
|
|
2772
2847
|
not: filterValueSchema.optional(),
|
|
2773
|
-
string_contains: z.string().optional(),
|
|
2774
|
-
string_starts_with: z.string().optional(),
|
|
2775
|
-
string_ends_with: z.string().optional(),
|
|
2848
|
+
string_contains: z$1.string().optional(),
|
|
2849
|
+
string_starts_with: z$1.string().optional(),
|
|
2850
|
+
string_ends_with: z$1.string().optional(),
|
|
2776
2851
|
mode: this.makeStringModeSchema().optional(),
|
|
2777
2852
|
array_contains: filterValueSchema.optional(),
|
|
2778
2853
|
array_starts_with: filterValueSchema.optional(),
|
|
@@ -2791,7 +2866,7 @@ var ZodSchemaFactory = class {
|
|
|
2791
2866
|
}
|
|
2792
2867
|
makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
2793
2868
|
const filterValueSchema = this.makeDateTimeValueSchema();
|
|
2794
|
-
const schema = this.makeCommonPrimitiveFilterSchema(filterValueSchema, optional, () => z.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)), withAggregations ? [
|
|
2869
|
+
const schema = this.makeCommonPrimitiveFilterSchema(filterValueSchema, optional, () => z$1.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)), withAggregations ? [
|
|
2795
2870
|
"_count",
|
|
2796
2871
|
"_min",
|
|
2797
2872
|
"_max"
|
|
@@ -2804,12 +2879,12 @@ var ZodSchemaFactory = class {
|
|
|
2804
2879
|
return schema;
|
|
2805
2880
|
}
|
|
2806
2881
|
makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
2807
|
-
const components = this.makeCommonPrimitiveFilterComponents(z.boolean(), optional, () => z.lazy(() => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)), ["equals", "not"], withAggregations ? [
|
|
2882
|
+
const components = this.makeCommonPrimitiveFilterComponents(z$1.boolean(), optional, () => z$1.lazy(() => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)), ["equals", "not"], withAggregations ? [
|
|
2808
2883
|
"_count",
|
|
2809
2884
|
"_min",
|
|
2810
2885
|
"_max"
|
|
2811
2886
|
] : void 0, allowedFilterKinds);
|
|
2812
|
-
const schema = this.createUnionFilterSchema(z.boolean(), optional, components, allowedFilterKinds);
|
|
2887
|
+
const schema = this.createUnionFilterSchema(z$1.boolean(), optional, components, allowedFilterKinds);
|
|
2813
2888
|
this.registerSchema(`BooleanFilter${this.filterSchemaSuffix({
|
|
2814
2889
|
optional,
|
|
2815
2890
|
allowedFilterKinds,
|
|
@@ -2818,8 +2893,8 @@ var ZodSchemaFactory = class {
|
|
|
2818
2893
|
return schema;
|
|
2819
2894
|
}
|
|
2820
2895
|
makeBytesFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
2821
|
-
const baseSchema = z.instanceof(Uint8Array);
|
|
2822
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z.instanceof(Uint8Array), [
|
|
2896
|
+
const baseSchema = z$1.instanceof(Uint8Array);
|
|
2897
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z$1.instanceof(Uint8Array), [
|
|
2823
2898
|
"equals",
|
|
2824
2899
|
"in",
|
|
2825
2900
|
"notIn",
|
|
@@ -2867,7 +2942,7 @@ var ZodSchemaFactory = class {
|
|
|
2867
2942
|
return this.createUnionFilterSchema(baseSchema, optional, components, allowedFilterKinds);
|
|
2868
2943
|
}
|
|
2869
2944
|
makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds) {
|
|
2870
|
-
const schema = this.makeCommonPrimitiveFilterSchema(this.makeScalarSchema(type), optional, () => z.lazy(() => this.makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds)), withAggregations ? [
|
|
2945
|
+
const schema = this.makeCommonPrimitiveFilterSchema(this.makeScalarSchema(type), optional, () => z$1.lazy(() => this.makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds)), withAggregations ? [
|
|
2871
2946
|
"_count",
|
|
2872
2947
|
"_avg",
|
|
2873
2948
|
"_sum",
|
|
@@ -2882,15 +2957,15 @@ var ZodSchemaFactory = class {
|
|
|
2882
2957
|
return schema;
|
|
2883
2958
|
}
|
|
2884
2959
|
makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy = false, withFullText = false) {
|
|
2885
|
-
const baseComponents = this.makeCommonPrimitiveFilterComponents(z.string(), optional, () => z.lazy(() => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy, withFullText)), void 0, withAggregations ? [
|
|
2960
|
+
const baseComponents = this.makeCommonPrimitiveFilterComponents(z$1.string(), optional, () => z$1.lazy(() => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy, withFullText)), void 0, withAggregations ? [
|
|
2886
2961
|
"_count",
|
|
2887
2962
|
"_min",
|
|
2888
2963
|
"_max"
|
|
2889
2964
|
] : void 0, allowedFilterKinds);
|
|
2890
2965
|
const stringSpecificOperators = {
|
|
2891
|
-
startsWith: z.string().optional(),
|
|
2892
|
-
endsWith: z.string().optional(),
|
|
2893
|
-
contains: z.string().optional(),
|
|
2966
|
+
startsWith: z$1.string().optional(),
|
|
2967
|
+
endsWith: z$1.string().optional(),
|
|
2968
|
+
contains: z$1.string().optional(),
|
|
2894
2969
|
...withFuzzy && this.providerSupportsFuzzySearch ? { fuzzy: this.makeFuzzyFilterSchema().optional() } : {},
|
|
2895
2970
|
...withFullText && this.providerSupportsFullTextSearch ? { fts: this.makeFullTextFilterSchema().optional() } : {},
|
|
2896
2971
|
...this.providerSupportsCaseSensitivity ? { mode: this.makeStringModeSchema().optional() } : {}
|
|
@@ -2900,7 +2975,7 @@ var ZodSchemaFactory = class {
|
|
|
2900
2975
|
...baseComponents,
|
|
2901
2976
|
...filteredStringOperators
|
|
2902
2977
|
};
|
|
2903
|
-
const schema = this.createUnionFilterSchema(z.string(), optional, allComponents, allowedFilterKinds);
|
|
2978
|
+
const schema = this.createUnionFilterSchema(z$1.string(), optional, allComponents, allowedFilterKinds);
|
|
2904
2979
|
const featureSuffix = `${withFuzzy ? "Fuzzy" : ""}${withFullText ? "FullText" : ""}`;
|
|
2905
2980
|
this.registerSchema(`StringFilter${this.filterSchemaSuffix({
|
|
2906
2981
|
optional,
|
|
@@ -2910,45 +2985,45 @@ var ZodSchemaFactory = class {
|
|
|
2910
2985
|
return schema;
|
|
2911
2986
|
}
|
|
2912
2987
|
makeStringModeSchema() {
|
|
2913
|
-
return z.union([z.literal("default"), z.literal("insensitive")]);
|
|
2988
|
+
return z$1.union([z$1.literal("default"), z$1.literal("insensitive")]);
|
|
2914
2989
|
}
|
|
2915
2990
|
makeFuzzyFilterSchema() {
|
|
2916
|
-
return z.strictObject({
|
|
2917
|
-
search: z.string().min(1),
|
|
2918
|
-
mode: z.union([
|
|
2919
|
-
z.literal("simple"),
|
|
2920
|
-
z.literal("word"),
|
|
2921
|
-
z.literal("strictWord")
|
|
2991
|
+
return z$1.strictObject({
|
|
2992
|
+
search: z$1.string().min(1),
|
|
2993
|
+
mode: z$1.union([
|
|
2994
|
+
z$1.literal("simple"),
|
|
2995
|
+
z$1.literal("word"),
|
|
2996
|
+
z$1.literal("strictWord")
|
|
2922
2997
|
]).default("simple"),
|
|
2923
|
-
threshold: z.number().min(0).max(1).optional(),
|
|
2924
|
-
unaccent: z.boolean().default(false)
|
|
2998
|
+
threshold: z$1.number().min(0).max(1).optional(),
|
|
2999
|
+
unaccent: z$1.boolean().default(false)
|
|
2925
3000
|
});
|
|
2926
3001
|
}
|
|
2927
3002
|
makeFullTextFilterSchema() {
|
|
2928
|
-
return z.strictObject({
|
|
2929
|
-
search: z.string().min(1),
|
|
2930
|
-
config: z.string().min(1).optional()
|
|
3003
|
+
return z$1.strictObject({
|
|
3004
|
+
search: z$1.string().min(1),
|
|
3005
|
+
config: z$1.string().min(1).optional()
|
|
2931
3006
|
});
|
|
2932
3007
|
}
|
|
2933
3008
|
makeSelectSchema(model, options) {
|
|
2934
3009
|
const fields = {};
|
|
2935
3010
|
for (const [field, fieldDef] of this.getModelFields(model)) {
|
|
2936
3011
|
if (this.isParameterizedComputedField(fieldDef)) {
|
|
2937
|
-
fields[field] = z.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional();
|
|
3012
|
+
fields[field] = z$1.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional();
|
|
2938
3013
|
continue;
|
|
2939
3014
|
}
|
|
2940
3015
|
if (fieldDef.relation) {
|
|
2941
3016
|
if (!this.shouldIncludeRelations(options)) continue;
|
|
2942
3017
|
if (this.isModelAllowed(fieldDef.type)) fields[field] = this.makeRelationSelectIncludeSchema(model, field, options).optional();
|
|
2943
|
-
} else if (this.options.allowQueryTimeOmitOverride === false && this.isFieldOmittedByConfig(model, field)) fields[field] = z.literal(false).optional();
|
|
2944
|
-
else fields[field] = z.boolean().optional();
|
|
3018
|
+
} else if (this.options.allowQueryTimeOmitOverride === false && this.isFieldOmittedByConfig(model, field)) fields[field] = z$1.literal(false).optional();
|
|
3019
|
+
else fields[field] = z$1.boolean().optional();
|
|
2945
3020
|
}
|
|
2946
3021
|
if (this.shouldIncludeRelations(options)) {
|
|
2947
3022
|
const _countSchema = this.makeCountSelectionSchema(model, options);
|
|
2948
|
-
if (!(_countSchema instanceof z.ZodNever)) fields["_count"] = _countSchema;
|
|
3023
|
+
if (!(_countSchema instanceof z$1.ZodNever)) fields["_count"] = _countSchema;
|
|
2949
3024
|
}
|
|
2950
3025
|
this.addExtResultFields(model, fields);
|
|
2951
|
-
const result = z.strictObject(fields);
|
|
3026
|
+
const result = z$1.strictObject(fields);
|
|
2952
3027
|
this.registerSchema(`${model}Select`, result);
|
|
2953
3028
|
return result;
|
|
2954
3029
|
}
|
|
@@ -2957,24 +3032,24 @@ var ZodSchemaFactory = class {
|
|
|
2957
3032
|
const toManyRelations = Object.values(modelDef.fields).filter((def) => def.relation && def.array);
|
|
2958
3033
|
if (toManyRelations.length > 0) {
|
|
2959
3034
|
const nextOpts = this.nextOptions(options);
|
|
2960
|
-
const schema = z.union([z.literal(true), z.strictObject({ select: z.strictObject(toManyRelations.reduce((acc, fieldDef) => ({
|
|
3035
|
+
const schema = z$1.union([z$1.literal(true), z$1.strictObject({ select: z$1.strictObject(toManyRelations.reduce((acc, fieldDef) => ({
|
|
2961
3036
|
...acc,
|
|
2962
|
-
[fieldDef.name]: z.union([z.boolean(), z.strictObject({ where: this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts) })]).optional()
|
|
3037
|
+
[fieldDef.name]: z$1.union([z$1.boolean(), z$1.strictObject({ where: this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts) })]).optional()
|
|
2963
3038
|
}), {})) })]).optional();
|
|
2964
3039
|
this.registerSchema(`${model}CountSelection`, schema);
|
|
2965
3040
|
return schema;
|
|
2966
|
-
} else return z.never();
|
|
3041
|
+
} else return z$1.never();
|
|
2967
3042
|
}
|
|
2968
3043
|
makeRelationSelectIncludeSchema(model, field, options) {
|
|
2969
3044
|
const fieldDef = requireField(this.schema, model, field);
|
|
2970
3045
|
const nextOpts = this.nextOptions(options);
|
|
2971
|
-
let objSchema = z.strictObject({
|
|
2972
|
-
...fieldDef.array || fieldDef.optional ? { where: z.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts)).optional() } : {},
|
|
2973
|
-
select: z.lazy(() => this.makeSelectSchema(fieldDef.type, nextOpts)).optional().nullable(),
|
|
2974
|
-
include: z.lazy(() => this.makeIncludeSchema(fieldDef.type, nextOpts)).optional().nullable(),
|
|
2975
|
-
omit: z.lazy(() => this.makeOmitSchema(fieldDef.type)).optional().nullable(),
|
|
3046
|
+
let objSchema = z$1.strictObject({
|
|
3047
|
+
...fieldDef.array || fieldDef.optional ? { where: z$1.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts)).optional() } : {},
|
|
3048
|
+
select: z$1.lazy(() => this.makeSelectSchema(fieldDef.type, nextOpts)).optional().nullable(),
|
|
3049
|
+
include: z$1.lazy(() => this.makeIncludeSchema(fieldDef.type, nextOpts)).optional().nullable(),
|
|
3050
|
+
omit: z$1.lazy(() => this.makeOmitSchema(fieldDef.type)).optional().nullable(),
|
|
2976
3051
|
...fieldDef.array ? {
|
|
2977
|
-
orderBy: z.lazy(() => this.orArray(this.makeOrderBySchema(fieldDef.type, true, false, nextOpts), true)).optional(),
|
|
3052
|
+
orderBy: z$1.lazy(() => this.orArray(this.makeOrderBySchema(fieldDef.type, true, false, nextOpts), true)).optional(),
|
|
2978
3053
|
skip: this.makeSkipSchema().optional(),
|
|
2979
3054
|
take: this.makeTakeSchema().optional(),
|
|
2980
3055
|
cursor: this.makeCursorSchema(fieldDef.type, nextOpts).optional(),
|
|
@@ -2984,7 +3059,7 @@ var ZodSchemaFactory = class {
|
|
|
2984
3059
|
objSchema = this.refineForSelectIncludeMutuallyExclusive(objSchema);
|
|
2985
3060
|
objSchema = this.refineForSelectOmitMutuallyExclusive(objSchema);
|
|
2986
3061
|
objSchema = this.refineForSelectHasTruthyField(objSchema);
|
|
2987
|
-
const result = z.union([z.boolean(), objSchema]);
|
|
3062
|
+
const result = z$1.union([z$1.boolean(), objSchema]);
|
|
2988
3063
|
this.registerSchema(`${model}${upperCaseFirst(field)}RelationInput`, result);
|
|
2989
3064
|
return result;
|
|
2990
3065
|
}
|
|
@@ -3001,11 +3076,11 @@ var ZodSchemaFactory = class {
|
|
|
3001
3076
|
const fields = {};
|
|
3002
3077
|
for (const [field, fieldDef] of this.getModelFields(model)) {
|
|
3003
3078
|
if (this.isParameterizedComputedField(fieldDef)) continue;
|
|
3004
|
-
if (!fieldDef.relation) if (this.options.allowQueryTimeOmitOverride !== false) fields[field] = z.boolean().optional();
|
|
3005
|
-
else fields[field] = z.literal(true).optional();
|
|
3079
|
+
if (!fieldDef.relation) if (this.options.allowQueryTimeOmitOverride !== false) fields[field] = z$1.boolean().optional();
|
|
3080
|
+
else fields[field] = z$1.literal(true).optional();
|
|
3006
3081
|
}
|
|
3007
3082
|
this.addExtResultFields(model, fields);
|
|
3008
|
-
const result = z.strictObject(fields);
|
|
3083
|
+
const result = z$1.strictObject(fields);
|
|
3009
3084
|
this.registerSchema(`${model}OmitInput`, result);
|
|
3010
3085
|
return result;
|
|
3011
3086
|
}
|
|
@@ -3014,7 +3089,7 @@ var ZodSchemaFactory = class {
|
|
|
3014
3089
|
const resultConfig = plugin.result;
|
|
3015
3090
|
if (resultConfig) {
|
|
3016
3091
|
const modelConfig = resultConfig[lowerCaseFirst(model)];
|
|
3017
|
-
if (modelConfig) for (const field of Object.keys(modelConfig)) fields[field] = z.boolean().optional();
|
|
3092
|
+
if (modelConfig) for (const field of Object.keys(modelConfig)) fields[field] = z$1.boolean().optional();
|
|
3018
3093
|
}
|
|
3019
3094
|
}
|
|
3020
3095
|
}
|
|
@@ -3026,35 +3101,35 @@ var ZodSchemaFactory = class {
|
|
|
3026
3101
|
if (fieldDef.relation) {
|
|
3027
3102
|
if (!this.shouldIncludeRelations(options)) continue;
|
|
3028
3103
|
if (this.isModelAllowed(fieldDef.type)) fields[field] = this.makeRelationSelectIncludeSchema(model, field, options).optional();
|
|
3029
|
-
} else if (this.isParameterizedComputedField(fieldDef)) fields[field] = z.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional();
|
|
3104
|
+
} else if (this.isParameterizedComputedField(fieldDef)) fields[field] = z$1.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional();
|
|
3030
3105
|
}
|
|
3031
3106
|
if (this.shouldIncludeRelations(options)) {
|
|
3032
3107
|
const _countSchema = this.makeCountSelectionSchema(model, options);
|
|
3033
|
-
if (!(_countSchema instanceof z.ZodNever)) fields["_count"] = _countSchema;
|
|
3108
|
+
if (!(_countSchema instanceof z$1.ZodNever)) fields["_count"] = _countSchema;
|
|
3034
3109
|
}
|
|
3035
|
-
const result = z.strictObject(fields);
|
|
3110
|
+
const result = z$1.strictObject(fields);
|
|
3036
3111
|
this.registerSchema(`${model}Include`, result);
|
|
3037
3112
|
return result;
|
|
3038
3113
|
}
|
|
3039
3114
|
makeOrderBySchema(model, withRelation, WithAggregation, options) {
|
|
3040
3115
|
const fields = {};
|
|
3041
|
-
const sort = z.union([z.literal("asc"), z.literal("desc")]);
|
|
3116
|
+
const sort = z$1.union([z$1.literal("asc"), z$1.literal("desc")]);
|
|
3042
3117
|
const refineAtMostOneKey = (s) => s.refine((v) => Object.keys(v).length <= 1, { message: "Each orderBy element must have at most one key" });
|
|
3043
3118
|
const nextOpts = this.nextOptions(options);
|
|
3044
3119
|
for (const [field, fieldDef] of this.getModelFields(model)) if (fieldDef.relation) {
|
|
3045
|
-
if (withRelation && this.shouldIncludeRelations(options)) fields[field] = z.lazy(() => {
|
|
3120
|
+
if (withRelation && this.shouldIncludeRelations(options)) fields[field] = z$1.lazy(() => {
|
|
3046
3121
|
let relationOrderBy = this.makeOrderBySchema(fieldDef.type, withRelation, WithAggregation, nextOpts);
|
|
3047
3122
|
if (fieldDef.array) relationOrderBy = refineAtMostOneKey(relationOrderBy.safeExtend({ _count: sort }));
|
|
3048
3123
|
return relationOrderBy;
|
|
3049
3124
|
}).optional();
|
|
3050
|
-
} else if (fieldDef.computed && fieldDef.params) fields[field] = z.strictObject({
|
|
3125
|
+
} else if (fieldDef.computed && fieldDef.params) fields[field] = z$1.strictObject({
|
|
3051
3126
|
args: this.makeFieldArgsSchema(fieldDef.params),
|
|
3052
3127
|
sort,
|
|
3053
|
-
nulls: z.union([z.literal("first"), z.literal("last")]).optional()
|
|
3128
|
+
nulls: z$1.union([z$1.literal("first"), z$1.literal("last")]).optional()
|
|
3054
3129
|
}).optional();
|
|
3055
|
-
else if (fieldDef.optional) fields[field] = z.union([sort, z.strictObject({
|
|
3130
|
+
else if (fieldDef.optional) fields[field] = z$1.union([sort, z$1.strictObject({
|
|
3056
3131
|
sort,
|
|
3057
|
-
nulls: z.union([z.literal("first"), z.literal("last")]).optional()
|
|
3132
|
+
nulls: z$1.union([z$1.literal("first"), z$1.literal("last")]).optional()
|
|
3058
3133
|
})]).optional();
|
|
3059
3134
|
else fields[field] = sort.optional();
|
|
3060
3135
|
if (WithAggregation) for (const agg of [
|
|
@@ -3063,31 +3138,31 @@ var ZodSchemaFactory = class {
|
|
|
3063
3138
|
"_sum",
|
|
3064
3139
|
"_min",
|
|
3065
3140
|
"_max"
|
|
3066
|
-
]) fields[agg] = z.lazy(() => this.makeOrderBySchema(model, true, false, options).optional());
|
|
3141
|
+
]) fields[agg] = z$1.lazy(() => this.makeOrderBySchema(model, true, false, options).optional());
|
|
3067
3142
|
if (this.providerSupportsFuzzySearch) {
|
|
3068
3143
|
const fuzzyFieldNames = this.getModelFields(model).filter(([, def]) => !def.relation && def.type === "String" && def.fuzzy === true).map(([name]) => name);
|
|
3069
|
-
if (fuzzyFieldNames.length > 0) fields["_fuzzyRelevance"] = z.strictObject({
|
|
3070
|
-
fields: z.array(z.enum(fuzzyFieldNames)).min(1),
|
|
3071
|
-
search: z.string(),
|
|
3072
|
-
mode: z.union([
|
|
3073
|
-
z.literal("simple"),
|
|
3074
|
-
z.literal("word"),
|
|
3075
|
-
z.literal("strictWord")
|
|
3144
|
+
if (fuzzyFieldNames.length > 0) fields["_fuzzyRelevance"] = z$1.strictObject({
|
|
3145
|
+
fields: z$1.array(z$1.enum(fuzzyFieldNames)).min(1),
|
|
3146
|
+
search: z$1.string(),
|
|
3147
|
+
mode: z$1.union([
|
|
3148
|
+
z$1.literal("simple"),
|
|
3149
|
+
z$1.literal("word"),
|
|
3150
|
+
z$1.literal("strictWord")
|
|
3076
3151
|
]).default("simple"),
|
|
3077
|
-
unaccent: z.boolean().default(false),
|
|
3152
|
+
unaccent: z$1.boolean().default(false),
|
|
3078
3153
|
sort
|
|
3079
3154
|
}).optional();
|
|
3080
3155
|
}
|
|
3081
3156
|
if (this.providerSupportsFullTextSearch) {
|
|
3082
3157
|
const fullTextFieldNames = this.getModelFields(model).filter(([, def]) => !def.relation && def.type === "String" && def.fullText === true).map(([name]) => name);
|
|
3083
|
-
if (fullTextFieldNames.length > 0) fields["_ftsRelevance"] = z.strictObject({
|
|
3084
|
-
fields: z.array(z.enum(fullTextFieldNames)).min(1),
|
|
3085
|
-
search: z.string().min(1),
|
|
3086
|
-
config: z.string().min(1).optional(),
|
|
3158
|
+
if (fullTextFieldNames.length > 0) fields["_ftsRelevance"] = z$1.strictObject({
|
|
3159
|
+
fields: z$1.array(z$1.enum(fullTextFieldNames)).min(1),
|
|
3160
|
+
search: z$1.string().min(1),
|
|
3161
|
+
config: z$1.string().min(1).optional(),
|
|
3087
3162
|
sort
|
|
3088
3163
|
}).optional();
|
|
3089
3164
|
}
|
|
3090
|
-
const schema = refineAtMostOneKey(z.strictObject(fields));
|
|
3165
|
+
const schema = refineAtMostOneKey(z$1.strictObject(fields));
|
|
3091
3166
|
let schemaId = `${model}OrderBy`;
|
|
3092
3167
|
if (withRelation) schemaId += "WithRelation";
|
|
3093
3168
|
if (WithAggregation) schemaId += "WithAggregation";
|
|
@@ -3097,7 +3172,7 @@ var ZodSchemaFactory = class {
|
|
|
3097
3172
|
}
|
|
3098
3173
|
makeDistinctSchema(model) {
|
|
3099
3174
|
const nonRelationFields = this.getModelFields(model).filter(([, def]) => !def.relation && !this.isParameterizedComputedField(def)).map(([name]) => name);
|
|
3100
|
-
const schema = nonRelationFields.length > 0 ? this.orArray(z.enum(nonRelationFields), true) : z.never();
|
|
3175
|
+
const schema = nonRelationFields.length > 0 ? this.orArray(z$1.enum(nonRelationFields), true) : z$1.never();
|
|
3101
3176
|
this.registerSchema(`${model}DistinctInput`, schema);
|
|
3102
3177
|
return schema;
|
|
3103
3178
|
}
|
|
@@ -3108,7 +3183,7 @@ var ZodSchemaFactory = class {
|
|
|
3108
3183
|
}
|
|
3109
3184
|
makeCreateSchema(model, options) {
|
|
3110
3185
|
const dataSchema = this.makeCreateDataSchema(model, false, [], false, options);
|
|
3111
|
-
const baseSchema = z.strictObject({
|
|
3186
|
+
const baseSchema = z$1.strictObject({
|
|
3112
3187
|
data: dataSchema,
|
|
3113
3188
|
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
3114
3189
|
include: this.makeIncludeSchema(model, options).optional().nullable(),
|
|
@@ -3157,7 +3232,7 @@ var ZodSchemaFactory = class {
|
|
|
3157
3232
|
const oppositeFieldDef = requireField(this.schema, fieldDef.type, oppositeField);
|
|
3158
3233
|
if (oppositeFieldDef.relation?.fields) excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
3159
3234
|
}
|
|
3160
|
-
let fieldSchema = z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "create", nextOpts));
|
|
3235
|
+
let fieldSchema = z$1.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "create", nextOpts));
|
|
3161
3236
|
if (fieldDef.optional || fieldDef.array) fieldSchema = fieldSchema.optional();
|
|
3162
3237
|
else {
|
|
3163
3238
|
let allFksOptional = false;
|
|
@@ -3171,26 +3246,26 @@ var ZodSchemaFactory = class {
|
|
|
3171
3246
|
checkedVariantFields[field] = fieldSchema;
|
|
3172
3247
|
if (fieldDef.array || !fieldDef.relation.references) uncheckedVariantFields[field] = fieldSchema;
|
|
3173
3248
|
} else {
|
|
3174
|
-
let fieldSchema = this.makeScalarSchema(fieldDef.type, fieldDef
|
|
3249
|
+
let fieldSchema = this.makeScalarSchema(fieldDef.type, this.getItemAttributes(fieldDef));
|
|
3175
3250
|
if (fieldDef.array) {
|
|
3176
3251
|
fieldSchema = ZodUtils.addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
3177
|
-
fieldSchema = z.union([fieldSchema, z.strictObject({ set: fieldSchema })]).optional();
|
|
3252
|
+
fieldSchema = z$1.union([fieldSchema, z$1.strictObject({ set: fieldSchema })]).optional();
|
|
3178
3253
|
}
|
|
3179
3254
|
if (fieldDef.optional || fieldHasDefaultValue(fieldDef)) fieldSchema = fieldSchema.optional();
|
|
3180
|
-
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z.union([fieldSchema, z.instanceof(DbNullClass)]);
|
|
3255
|
+
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z$1.union([fieldSchema, z$1.instanceof(DbNullClass)]);
|
|
3181
3256
|
else if (this.isTypeDefType(fieldDef.type)) fieldSchema = this.makeNullableTypedJsonMutationSchema(fieldSchema);
|
|
3182
3257
|
else fieldSchema = fieldSchema.nullable();
|
|
3183
3258
|
uncheckedVariantFields[field] = fieldSchema;
|
|
3184
3259
|
if (!fieldDef.foreignKeyFor) checkedVariantFields[field] = fieldSchema;
|
|
3185
3260
|
}
|
|
3186
3261
|
});
|
|
3187
|
-
const uncheckedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(uncheckedVariantFields), modelDef.attributes) : z.strictObject(uncheckedVariantFields);
|
|
3188
|
-
const checkedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(checkedVariantFields), modelDef.attributes) : z.strictObject(checkedVariantFields);
|
|
3189
|
-
const result = !hasRelation ? this.orArray(uncheckedCreateSchema, canBeArray) : z.union([
|
|
3262
|
+
const uncheckedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z$1.strictObject(uncheckedVariantFields), modelDef.attributes) : z$1.strictObject(uncheckedVariantFields);
|
|
3263
|
+
const checkedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z$1.strictObject(checkedVariantFields), modelDef.attributes) : z$1.strictObject(checkedVariantFields);
|
|
3264
|
+
const result = !hasRelation ? this.orArray(uncheckedCreateSchema, canBeArray) : z$1.union([
|
|
3190
3265
|
uncheckedCreateSchema,
|
|
3191
3266
|
checkedCreateSchema,
|
|
3192
|
-
...canBeArray ? [z.array(uncheckedCreateSchema)] : [],
|
|
3193
|
-
...canBeArray ? [z.array(checkedCreateSchema)] : []
|
|
3267
|
+
...canBeArray ? [z$1.array(uncheckedCreateSchema)] : [],
|
|
3268
|
+
...canBeArray ? [z$1.array(checkedCreateSchema)] : []
|
|
3194
3269
|
]);
|
|
3195
3270
|
const idParts = [`${model}CreateData`];
|
|
3196
3271
|
if (canBeArray) idParts.push("Array");
|
|
@@ -3215,17 +3290,17 @@ var ZodSchemaFactory = class {
|
|
|
3215
3290
|
fields["disconnect"] = this.makeDisconnectDataSchema(fieldType, array, options).optional();
|
|
3216
3291
|
fields["delete"] = this.makeDeleteRelationDataSchema(fieldType, array, true, options).optional();
|
|
3217
3292
|
}
|
|
3218
|
-
fields["update"] = array ? this.orArray(z.strictObject({
|
|
3293
|
+
fields["update"] = array ? this.orArray(z$1.strictObject({
|
|
3219
3294
|
where: this.makeWhereSchema(fieldType, true, false, false, options),
|
|
3220
3295
|
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
3221
|
-
}), true).optional() : z.union([z.strictObject({
|
|
3296
|
+
}), true).optional() : z$1.union([z$1.strictObject({
|
|
3222
3297
|
where: this.makeWhereSchema(fieldType, false, false, false, options).optional(),
|
|
3223
3298
|
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
3224
3299
|
}), this.makeUpdateDataSchema(fieldType, withoutFields, false, options)]).optional();
|
|
3225
3300
|
if (canCreateModel) {
|
|
3226
3301
|
let upsertWhere = this.makeWhereSchema(fieldType, true, false, false, options);
|
|
3227
3302
|
if (!fieldDef.array) upsertWhere = upsertWhere.optional();
|
|
3228
|
-
fields["upsert"] = this.orArray(z.strictObject({
|
|
3303
|
+
fields["upsert"] = this.orArray(z$1.strictObject({
|
|
3229
3304
|
where: upsertWhere,
|
|
3230
3305
|
create: this.makeCreateDataSchema(fieldType, false, withoutFields, false, options),
|
|
3231
3306
|
update: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
@@ -3233,14 +3308,14 @@ var ZodSchemaFactory = class {
|
|
|
3233
3308
|
}
|
|
3234
3309
|
if (array) {
|
|
3235
3310
|
fields["set"] = this.makeSetDataSchema(fieldType, true, options).optional();
|
|
3236
|
-
fields["updateMany"] = this.orArray(z.strictObject({
|
|
3311
|
+
fields["updateMany"] = this.orArray(z$1.strictObject({
|
|
3237
3312
|
where: this.makeWhereSchema(fieldType, false, true, false, options),
|
|
3238
3313
|
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
3239
3314
|
}), true).optional();
|
|
3240
3315
|
fields["deleteMany"] = this.makeDeleteRelationDataSchema(fieldType, true, false, options).optional();
|
|
3241
3316
|
}
|
|
3242
3317
|
}
|
|
3243
|
-
return z.strictObject(fields);
|
|
3318
|
+
return z$1.strictObject(fields);
|
|
3244
3319
|
}
|
|
3245
3320
|
makeSetDataSchema(model, canBeArray, options) {
|
|
3246
3321
|
return this.orArray(this.makeWhereSchema(model, true, false, false, options), canBeArray);
|
|
@@ -3250,23 +3325,23 @@ var ZodSchemaFactory = class {
|
|
|
3250
3325
|
}
|
|
3251
3326
|
makeDisconnectDataSchema(model, canBeArray, options) {
|
|
3252
3327
|
if (canBeArray) return this.orArray(this.makeWhereSchema(model, true, false, false, options), canBeArray);
|
|
3253
|
-
else return z.union([z.boolean(), this.makeWhereSchema(model, false, false, false, options)]);
|
|
3328
|
+
else return z$1.union([z$1.boolean(), this.makeWhereSchema(model, false, false, false, options)]);
|
|
3254
3329
|
}
|
|
3255
3330
|
makeDeleteRelationDataSchema(model, toManyRelation, uniqueFilter, options) {
|
|
3256
|
-
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter, false, false, options), true) : z.union([z.boolean(), this.makeWhereSchema(model, uniqueFilter, false, false, options)]);
|
|
3331
|
+
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter, false, false, options), true) : z$1.union([z$1.boolean(), this.makeWhereSchema(model, uniqueFilter, false, false, options)]);
|
|
3257
3332
|
}
|
|
3258
3333
|
makeConnectOrCreateDataSchema(model, canBeArray, withoutFields, options) {
|
|
3259
3334
|
const whereSchema = this.makeWhereSchema(model, true, false, false, options);
|
|
3260
3335
|
const createSchema = this.makeCreateDataSchema(model, false, withoutFields, false, options);
|
|
3261
|
-
return this.orArray(z.strictObject({
|
|
3336
|
+
return this.orArray(z$1.strictObject({
|
|
3262
3337
|
where: whereSchema,
|
|
3263
3338
|
create: createSchema
|
|
3264
3339
|
}), canBeArray);
|
|
3265
3340
|
}
|
|
3266
3341
|
makeCreateManyPayloadSchema(model, withoutFields, options) {
|
|
3267
|
-
const schema = z.strictObject({
|
|
3342
|
+
const schema = z$1.strictObject({
|
|
3268
3343
|
data: this.makeCreateDataSchema(model, true, withoutFields, true, options),
|
|
3269
|
-
skipDuplicates: z.boolean().optional()
|
|
3344
|
+
skipDuplicates: z$1.boolean().optional()
|
|
3270
3345
|
});
|
|
3271
3346
|
const idParts = [`${model}CreateManyPayload`];
|
|
3272
3347
|
if (withoutFields.length) idParts.push(`Without${withoutFields.slice().sort().join("")}`);
|
|
@@ -3274,7 +3349,7 @@ var ZodSchemaFactory = class {
|
|
|
3274
3349
|
return schema;
|
|
3275
3350
|
}
|
|
3276
3351
|
makeUpdateSchema(model, options) {
|
|
3277
|
-
const baseSchema = z.strictObject({
|
|
3352
|
+
const baseSchema = z$1.strictObject({
|
|
3278
3353
|
where: this.makeWhereSchema(model, true, false, false, options),
|
|
3279
3354
|
data: this.makeUpdateDataSchema(model, [], false, options),
|
|
3280
3355
|
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
@@ -3289,10 +3364,10 @@ var ZodSchemaFactory = class {
|
|
|
3289
3364
|
return schema;
|
|
3290
3365
|
}
|
|
3291
3366
|
makeUpdateManySchema(model, options) {
|
|
3292
|
-
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3367
|
+
const result = this.mergePluginArgsSchema(z$1.strictObject({
|
|
3293
3368
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3294
3369
|
data: this.makeUpdateDataSchema(model, [], true, options),
|
|
3295
|
-
limit: z.number().int().nonnegative().optional()
|
|
3370
|
+
limit: z$1.number().int().nonnegative().optional()
|
|
3296
3371
|
}), "updateMany");
|
|
3297
3372
|
this.registerSchema(`${model}UpdateManyArgs`, result);
|
|
3298
3373
|
return result;
|
|
@@ -3308,7 +3383,7 @@ var ZodSchemaFactory = class {
|
|
|
3308
3383
|
return schema;
|
|
3309
3384
|
}
|
|
3310
3385
|
makeUpsertSchema(model, options) {
|
|
3311
|
-
const baseSchema = z.strictObject({
|
|
3386
|
+
const baseSchema = z$1.strictObject({
|
|
3312
3387
|
where: this.makeWhereSchema(model, true, false, false, options),
|
|
3313
3388
|
create: this.makeCreateDataSchema(model, false, [], false, options),
|
|
3314
3389
|
update: this.makeUpdateDataSchema(model, [], false, options),
|
|
@@ -3344,27 +3419,27 @@ var ZodSchemaFactory = class {
|
|
|
3344
3419
|
const oppositeFieldDef = requireField(this.schema, fieldDef.type, oppositeField);
|
|
3345
3420
|
if (oppositeFieldDef.relation?.fields) excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
3346
3421
|
}
|
|
3347
|
-
let fieldSchema = z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "update", nextOpts)).optional();
|
|
3422
|
+
let fieldSchema = z$1.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "update", nextOpts)).optional();
|
|
3348
3423
|
if (fieldDef.optional && !fieldDef.array) fieldSchema = fieldSchema.nullable();
|
|
3349
3424
|
checkedVariantFields[field] = fieldSchema;
|
|
3350
3425
|
if (fieldDef.array || !fieldDef.relation.references) uncheckedVariantFields[field] = fieldSchema;
|
|
3351
3426
|
} else {
|
|
3352
|
-
let fieldSchema = this.makeScalarSchema(fieldDef.type, fieldDef
|
|
3353
|
-
if (this.isNumericField(fieldDef)) fieldSchema = z.union([fieldSchema, z.object({
|
|
3354
|
-
set: this.nullableIf(z.number().optional(), !!fieldDef.optional).optional(),
|
|
3355
|
-
increment: z.number().optional(),
|
|
3356
|
-
decrement: z.number().optional(),
|
|
3357
|
-
multiply: z.number().optional(),
|
|
3358
|
-
divide: z.number().optional()
|
|
3427
|
+
let fieldSchema = this.makeScalarSchema(fieldDef.type, this.getItemAttributes(fieldDef));
|
|
3428
|
+
if (this.isNumericField(fieldDef)) fieldSchema = z$1.union([fieldSchema, z$1.object({
|
|
3429
|
+
set: this.nullableIf(z$1.number().optional(), !!fieldDef.optional).optional(),
|
|
3430
|
+
increment: z$1.number().optional(),
|
|
3431
|
+
decrement: z$1.number().optional(),
|
|
3432
|
+
multiply: z$1.number().optional(),
|
|
3433
|
+
divide: z$1.number().optional()
|
|
3359
3434
|
}).refine((v) => Object.keys(v).length === 1, "Only one of \"set\", \"increment\", \"decrement\", \"multiply\", or \"divide\" can be provided")]);
|
|
3360
3435
|
if (fieldDef.array) {
|
|
3361
3436
|
const arraySchema = ZodUtils.addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
3362
|
-
fieldSchema = z.union([arraySchema, z.object({
|
|
3437
|
+
fieldSchema = z$1.union([arraySchema, z$1.object({
|
|
3363
3438
|
set: arraySchema.optional(),
|
|
3364
|
-
push: z.union([fieldSchema, fieldSchema.array()]).optional()
|
|
3439
|
+
push: z$1.union([fieldSchema, fieldSchema.array()]).optional()
|
|
3365
3440
|
}).refine((v) => Object.keys(v).length === 1, "Only one of \"set\", \"push\" can be provided")]);
|
|
3366
3441
|
}
|
|
3367
|
-
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z.union([fieldSchema, z.instanceof(DbNullClass)]);
|
|
3442
|
+
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z$1.union([fieldSchema, z$1.instanceof(DbNullClass)]);
|
|
3368
3443
|
else if (this.isTypeDefType(fieldDef.type)) fieldSchema = this.makeNullableTypedJsonMutationSchema(fieldSchema);
|
|
3369
3444
|
else fieldSchema = fieldSchema.nullable();
|
|
3370
3445
|
fieldSchema = fieldSchema.optional();
|
|
@@ -3372,9 +3447,9 @@ var ZodSchemaFactory = class {
|
|
|
3372
3447
|
if (!fieldDef.foreignKeyFor) checkedVariantFields[field] = fieldSchema;
|
|
3373
3448
|
}
|
|
3374
3449
|
});
|
|
3375
|
-
const uncheckedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(uncheckedVariantFields), modelDef.attributes) : z.strictObject(uncheckedVariantFields);
|
|
3376
|
-
const checkedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(checkedVariantFields), modelDef.attributes) : z.strictObject(checkedVariantFields);
|
|
3377
|
-
const result = !hasRelation ? uncheckedUpdateSchema : z.union([uncheckedUpdateSchema, checkedUpdateSchema]);
|
|
3450
|
+
const uncheckedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z$1.strictObject(uncheckedVariantFields), modelDef.attributes) : z$1.strictObject(uncheckedVariantFields);
|
|
3451
|
+
const checkedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z$1.strictObject(checkedVariantFields), modelDef.attributes) : z$1.strictObject(checkedVariantFields);
|
|
3452
|
+
const result = !hasRelation ? uncheckedUpdateSchema : z$1.union([uncheckedUpdateSchema, checkedUpdateSchema]);
|
|
3378
3453
|
const idParts = [`${model}UpdateData`];
|
|
3379
3454
|
if (withoutRelationFields) idParts.push("WithoutRelation");
|
|
3380
3455
|
if (withoutFields.length) idParts.push(`Without${withoutFields.slice().sort().join("")}`);
|
|
@@ -3382,7 +3457,7 @@ var ZodSchemaFactory = class {
|
|
|
3382
3457
|
return result;
|
|
3383
3458
|
}
|
|
3384
3459
|
makeDeleteSchema(model, options) {
|
|
3385
|
-
const baseSchema = z.strictObject({
|
|
3460
|
+
const baseSchema = z$1.strictObject({
|
|
3386
3461
|
where: this.makeWhereSchema(model, true, false, false, options),
|
|
3387
3462
|
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
3388
3463
|
include: this.makeIncludeSchema(model, options).optional().nullable(),
|
|
@@ -3396,15 +3471,15 @@ var ZodSchemaFactory = class {
|
|
|
3396
3471
|
return schema;
|
|
3397
3472
|
}
|
|
3398
3473
|
makeDeleteManySchema(model, options) {
|
|
3399
|
-
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3474
|
+
const result = this.mergePluginArgsSchema(z$1.strictObject({
|
|
3400
3475
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3401
|
-
limit: z.number().int().nonnegative().optional()
|
|
3476
|
+
limit: z$1.number().int().nonnegative().optional()
|
|
3402
3477
|
}), "deleteMany").optional();
|
|
3403
3478
|
this.registerSchema(`${model}DeleteManyArgs`, result);
|
|
3404
3479
|
return result;
|
|
3405
3480
|
}
|
|
3406
3481
|
makeCountSchema(model, options) {
|
|
3407
|
-
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3482
|
+
const result = this.mergePluginArgsSchema(z$1.strictObject({
|
|
3408
3483
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3409
3484
|
skip: this.makeSkipSchema().optional(),
|
|
3410
3485
|
take: this.makeTakeSchema().optional(),
|
|
@@ -3415,10 +3490,10 @@ var ZodSchemaFactory = class {
|
|
|
3415
3490
|
return result;
|
|
3416
3491
|
}
|
|
3417
3492
|
makeCountAggregateInputSchema(model) {
|
|
3418
|
-
const schema = z.union([z.literal(true), z.strictObject({
|
|
3419
|
-
_all: z.literal(true).optional(),
|
|
3493
|
+
const schema = z$1.union([z$1.literal(true), z$1.strictObject({
|
|
3494
|
+
_all: z$1.literal(true).optional(),
|
|
3420
3495
|
...this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
|
|
3421
|
-
acc[field] = this.isParameterizedComputedField(fieldDef) ? z.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional() : z.literal(true).optional();
|
|
3496
|
+
acc[field] = this.isParameterizedComputedField(fieldDef) ? z$1.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional() : z$1.literal(true).optional();
|
|
3422
3497
|
return acc;
|
|
3423
3498
|
}, {})
|
|
3424
3499
|
})]);
|
|
@@ -3426,7 +3501,7 @@ var ZodSchemaFactory = class {
|
|
|
3426
3501
|
return schema;
|
|
3427
3502
|
}
|
|
3428
3503
|
makeAggregateSchema(model, options) {
|
|
3429
|
-
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3504
|
+
const result = this.mergePluginArgsSchema(z$1.strictObject({
|
|
3430
3505
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3431
3506
|
skip: this.makeSkipSchema().optional(),
|
|
3432
3507
|
take: this.makeTakeSchema().optional(),
|
|
@@ -3441,16 +3516,16 @@ var ZodSchemaFactory = class {
|
|
|
3441
3516
|
return result;
|
|
3442
3517
|
}
|
|
3443
3518
|
makeSumAvgInputSchema(model) {
|
|
3444
|
-
const schema = z.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
|
|
3445
|
-
if (this.isNumericField(fieldDef)) acc[field] = this.isParameterizedComputedField(fieldDef) ? z.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional() : z.literal(true).optional();
|
|
3519
|
+
const schema = z$1.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
|
|
3520
|
+
if (this.isNumericField(fieldDef)) acc[field] = this.isParameterizedComputedField(fieldDef) ? z$1.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional() : z$1.literal(true).optional();
|
|
3446
3521
|
return acc;
|
|
3447
3522
|
}, {}));
|
|
3448
3523
|
this.registerSchema(`${model}SumAvgAggregateInput`, schema);
|
|
3449
3524
|
return schema;
|
|
3450
3525
|
}
|
|
3451
3526
|
makeMinMaxInputSchema(model) {
|
|
3452
|
-
const schema = z.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
|
|
3453
|
-
if (!fieldDef.relation && !fieldDef.array) acc[field] = this.isParameterizedComputedField(fieldDef) ? z.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional() : z.literal(true).optional();
|
|
3527
|
+
const schema = z$1.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
|
|
3528
|
+
if (!fieldDef.relation && !fieldDef.array) acc[field] = this.isParameterizedComputedField(fieldDef) ? z$1.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional() : z$1.literal(true).optional();
|
|
3454
3529
|
return acc;
|
|
3455
3530
|
}, {}));
|
|
3456
3531
|
this.registerSchema(`${model}MinMaxAggregateInput`, schema);
|
|
@@ -3459,14 +3534,14 @@ var ZodSchemaFactory = class {
|
|
|
3459
3534
|
makeGroupBySchema(model, options) {
|
|
3460
3535
|
const nonRelationFields = this.getModelFields(model).filter(([, def]) => !def.relation && !this.isParameterizedComputedField(def)).map(([name]) => name);
|
|
3461
3536
|
const byMembers = [];
|
|
3462
|
-
if (nonRelationFields.length > 0) byMembers.push(z.enum(nonRelationFields));
|
|
3463
|
-
for (const [field, fieldDef] of this.getModelFields(model)) if (this.isParameterizedComputedField(fieldDef)) byMembers.push(z.strictObject({
|
|
3464
|
-
field: z.literal(field),
|
|
3537
|
+
if (nonRelationFields.length > 0) byMembers.push(z$1.enum(nonRelationFields));
|
|
3538
|
+
for (const [field, fieldDef] of this.getModelFields(model)) if (this.isParameterizedComputedField(fieldDef)) byMembers.push(z$1.strictObject({
|
|
3539
|
+
field: z$1.literal(field),
|
|
3465
3540
|
args: this.makeFieldArgsSchema(fieldDef.params)
|
|
3466
3541
|
}));
|
|
3467
|
-
const byElement = byMembers.length === 0 ? void 0 : byMembers.length === 1 ? byMembers[0] : z.union(byMembers);
|
|
3468
|
-
const bySchema = byElement ? this.orArray(byElement, true) : z.never();
|
|
3469
|
-
const baseSchema = z.strictObject({
|
|
3542
|
+
const byElement = byMembers.length === 0 ? void 0 : byMembers.length === 1 ? byMembers[0] : z$1.union(byMembers);
|
|
3543
|
+
const bySchema = byElement ? this.orArray(byElement, true) : z$1.never();
|
|
3544
|
+
const baseSchema = z$1.strictObject({
|
|
3470
3545
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3471
3546
|
orderBy: this.orArray(this.makeOrderBySchema(model, false, true, options), true).optional(),
|
|
3472
3547
|
by: bySchema,
|
|
@@ -3518,7 +3593,7 @@ var ZodSchemaFactory = class {
|
|
|
3518
3593
|
if (!procDef) throw createInternalError(`Procedure not found: ${procName}`);
|
|
3519
3594
|
const shape = {};
|
|
3520
3595
|
for (const param of Object.values(procDef.params ?? {})) shape[param.name] = this.makeProcedureParamSchema(param);
|
|
3521
|
-
const schema = z.object(shape);
|
|
3596
|
+
const schema = z$1.object(shape);
|
|
3522
3597
|
this.registerSchema(`${procName}ProcArgs`, schema);
|
|
3523
3598
|
return schema;
|
|
3524
3599
|
}
|
|
@@ -3526,10 +3601,10 @@ var ZodSchemaFactory = class {
|
|
|
3526
3601
|
let schema;
|
|
3527
3602
|
if (isTypeDef(this.schema, param.type)) schema = this.makeTypeDefSchema(param.type);
|
|
3528
3603
|
else if (isEnum(this.schema, param.type)) schema = this.makeEnumSchema(param.type);
|
|
3529
|
-
else if (param.type in (this.schema.models ?? {})) schema = z.record(z.string(), z.unknown());
|
|
3604
|
+
else if (param.type in (this.schema.models ?? {})) schema = z$1.record(z$1.string(), z$1.unknown());
|
|
3530
3605
|
else {
|
|
3531
3606
|
schema = this.makeScalarSchema(param.type);
|
|
3532
|
-
if (schema instanceof z.ZodUnknown) throw createInternalError(`Unsupported procedure parameter type: ${param.type}`);
|
|
3607
|
+
if (schema instanceof z$1.ZodUnknown) throw createInternalError(`Unsupported procedure parameter type: ${param.type}`);
|
|
3533
3608
|
}
|
|
3534
3609
|
if (param.array) schema = schema.array();
|
|
3535
3610
|
if (param.optional) schema = schema.optional();
|
|
@@ -3565,10 +3640,10 @@ var ZodSchemaFactory = class {
|
|
|
3565
3640
|
return result;
|
|
3566
3641
|
}
|
|
3567
3642
|
makeSkipSchema() {
|
|
3568
|
-
return z.number().int().nonnegative();
|
|
3643
|
+
return z$1.number().int().nonnegative();
|
|
3569
3644
|
}
|
|
3570
3645
|
makeTakeSchema() {
|
|
3571
|
-
return z.number().int();
|
|
3646
|
+
return z$1.number().int();
|
|
3572
3647
|
}
|
|
3573
3648
|
refineForSelectIncludeMutuallyExclusive(schema) {
|
|
3574
3649
|
return schema.refine((value) => !(value["select"] && value["include"]), "\"select\" and \"include\" cannot be used together");
|
|
@@ -3587,10 +3662,10 @@ var ZodSchemaFactory = class {
|
|
|
3587
3662
|
return nullable ? schema.nullable() : schema;
|
|
3588
3663
|
}
|
|
3589
3664
|
orArray(schema, canBeArray) {
|
|
3590
|
-
return canBeArray ? z.union([schema, z.array(schema)]) : schema;
|
|
3665
|
+
return canBeArray ? z$1.union([schema, z$1.array(schema)]) : schema;
|
|
3591
3666
|
}
|
|
3592
3667
|
isNumericField(fieldDef) {
|
|
3593
|
-
return NUMERIC_FIELD_TYPES.includes(fieldDef.type) && !fieldDef.array;
|
|
3668
|
+
return NUMERIC_FIELD_TYPES.includes(this.getEffectiveFieldType(fieldDef.type)) && !fieldDef.array;
|
|
3594
3669
|
}
|
|
3595
3670
|
get providerSupportsCaseSensitivity() {
|
|
3596
3671
|
return this.schema.provider.type === "postgresql";
|
|
@@ -3649,10 +3724,10 @@ var ZodSchemaFactory = class {
|
|
|
3649
3724
|
createUnionFilterSchema(valueSchema, optional, components, allowedFilterKinds) {
|
|
3650
3725
|
if (Object.keys(components).length === 0) {
|
|
3651
3726
|
if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return this.nullableIf(valueSchema, optional);
|
|
3652
|
-
return z.never();
|
|
3727
|
+
return z$1.never();
|
|
3653
3728
|
}
|
|
3654
|
-
if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return z.union([this.nullableIf(valueSchema, optional), z.strictObject(components)]);
|
|
3655
|
-
else return z.strictObject(components);
|
|
3729
|
+
if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return z$1.union([this.nullableIf(valueSchema, optional), z$1.strictObject(components)]);
|
|
3730
|
+
else return z$1.strictObject(components);
|
|
3656
3731
|
}
|
|
3657
3732
|
canCreateModel(model) {
|
|
3658
3733
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -3710,7 +3785,7 @@ __decorate([
|
|
|
3710
3785
|
__decorate([
|
|
3711
3786
|
cache(),
|
|
3712
3787
|
__decorateMetadata("design:type", Function),
|
|
3713
|
-
__decorateMetadata("design:paramtypes", [String]),
|
|
3788
|
+
__decorateMetadata("design:paramtypes", [String, Array]),
|
|
3714
3789
|
__decorateMetadata("design:returntype", typeof (_ref2 = typeof ZodType !== "undefined" && ZodType) === "function" ? _ref2 : Object)
|
|
3715
3790
|
], ZodSchemaFactory.prototype, "makeTypeDefSchema", null);
|
|
3716
3791
|
__decorate([
|
|
@@ -4120,7 +4195,7 @@ var InputValidator = class {
|
|
|
4120
4195
|
enabled;
|
|
4121
4196
|
constructor(client, options) {
|
|
4122
4197
|
this.client = client;
|
|
4123
|
-
this.zodFactory = new ZodSchemaFactory(client);
|
|
4198
|
+
this.zodFactory = options?.zodFactory ?? new ZodSchemaFactory(client);
|
|
4124
4199
|
this.enabled = options?.enabled !== false;
|
|
4125
4200
|
}
|
|
4126
4201
|
validateFindArgs(model, args, operation) {
|
|
@@ -4273,6 +4348,7 @@ var BaseOperationHandler = class {
|
|
|
4273
4348
|
try {
|
|
4274
4349
|
result = (await kysely.getExecutor().executeQuery(compiled)).rows;
|
|
4275
4350
|
} catch (err) {
|
|
4351
|
+
if (err instanceof ORMError) throw err;
|
|
4276
4352
|
throw createDBQueryError(`Failed to execute query: ${err}`, err, compiled.sql, compiled.parameters);
|
|
4277
4353
|
}
|
|
4278
4354
|
return !!result[0]?.$exists;
|
|
@@ -4292,6 +4368,7 @@ var BaseOperationHandler = class {
|
|
|
4292
4368
|
try {
|
|
4293
4369
|
result = (await kysely.getExecutor().executeQuery(compiled)).rows;
|
|
4294
4370
|
} catch (err) {
|
|
4371
|
+
if (err instanceof ORMError) throw err;
|
|
4295
4372
|
throw createDBQueryError(`Failed to execute query: ${err}`, err, compiled.sql, compiled.parameters);
|
|
4296
4373
|
}
|
|
4297
4374
|
return result;
|
|
@@ -4316,7 +4393,7 @@ var BaseOperationHandler = class {
|
|
|
4316
4393
|
result = this.dialect.buildSelectField(result, model, parentAlias, field, computedArgs);
|
|
4317
4394
|
} else {
|
|
4318
4395
|
if (!fieldDef.array && !fieldDef.optional && payload.where) throw createInternalError(`Field "${field}" does not support filtering`, model);
|
|
4319
|
-
if (fieldDef.originModel) result = this.dialect.buildRelationSelection(result, fieldDef.originModel, field, fieldDef.originModel, payload);
|
|
4396
|
+
if (fieldDef.originModel) result = this.dialect.buildRelationSelection(result, fieldDef.originModel, field, this.dialect.delegateJoinAlias(model, parentAlias, fieldDef.originModel), payload);
|
|
4320
4397
|
else result = this.dialect.buildRelationSelection(result, model, field, parentAlias, payload);
|
|
4321
4398
|
}
|
|
4322
4399
|
}
|
|
@@ -4678,16 +4755,9 @@ var BaseOperationHandler = class {
|
|
|
4678
4755
|
if (Object.keys(parentWhere).length > 0) combinedWhere = Object.keys(combinedWhere).length > 0 ? { AND: [parentWhere, combinedWhere] } : parentWhere;
|
|
4679
4756
|
const origWhere = combinedWhere;
|
|
4680
4757
|
const modelDef = this.requireModel(model);
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
const ignoredFields = new Set(typeof fieldDef.updatedAt === "boolean" ? [] : fieldDef.updatedAt.ignore);
|
|
4685
|
-
if (Object.keys(data).some((field) => (isScalarField(this.schema, modelDef.name, field) || isForeignKeyField(this.schema, modelDef.name, field)) && !ignoredFields.has(field))) {
|
|
4686
|
-
if (finalData === data) finalData = clone(data);
|
|
4687
|
-
finalData[fieldName] = this.dialect.transformInput(/* @__PURE__ */ new Date(), "DateTime", false, fieldDef);
|
|
4688
|
-
autoUpdatedFields.push(fieldName);
|
|
4689
|
-
}
|
|
4690
|
-
}
|
|
4758
|
+
const filled = this.fillUpdatedAtFields(modelDef, data);
|
|
4759
|
+
let finalData = filled.data;
|
|
4760
|
+
const autoUpdatedFields = filled.autoUpdatedFields;
|
|
4691
4761
|
let thisEntity;
|
|
4692
4762
|
const loadThisEntity = async () => {
|
|
4693
4763
|
if (thisEntity === void 0) {
|
|
@@ -4836,7 +4906,8 @@ var BaseOperationHandler = class {
|
|
|
4836
4906
|
});
|
|
4837
4907
|
}
|
|
4838
4908
|
isNumericField(fieldDef) {
|
|
4839
|
-
|
|
4909
|
+
const type = isPrimitiveTypeDef(this.schema, fieldDef.type) ? this.schema.typeDefs[fieldDef.type].base : fieldDef.type;
|
|
4910
|
+
return NUMERIC_FIELD_TYPES.includes(type) && !fieldDef.array;
|
|
4840
4911
|
}
|
|
4841
4912
|
makeContextComment(_context) {
|
|
4842
4913
|
return sql``;
|
|
@@ -4849,11 +4920,13 @@ var BaseOperationHandler = class {
|
|
|
4849
4920
|
const parentWhere = await this.buildUpdateParentRelationFilter(kysely, fromRelation);
|
|
4850
4921
|
let combinedWhere = where ?? true;
|
|
4851
4922
|
if (Object.keys(parentWhere).length > 0) combinedWhere = Object.keys(combinedWhere).length > 0 ? { AND: [parentWhere, combinedWhere] } : parentWhere;
|
|
4923
|
+
const { data: finalData } = this.fillUpdatedAtFields(modelDef, data);
|
|
4924
|
+
if (modelDef.baseModel && filterModel === void 0) return this.updateManyByIds(kysely, model, combinedWhere, finalData, returnData, fieldsToReturn);
|
|
4852
4925
|
filterModel ??= model;
|
|
4853
4926
|
let updateFields = {};
|
|
4854
|
-
for (const field in
|
|
4927
|
+
for (const field in finalData) {
|
|
4855
4928
|
if (isRelationField(this.schema, model, field)) continue;
|
|
4856
|
-
updateFields[field] = this.processScalarFieldUpdateData(model, field,
|
|
4929
|
+
updateFields[field] = this.processScalarFieldUpdateData(model, field, finalData);
|
|
4857
4930
|
}
|
|
4858
4931
|
let resultFromBaseModel = void 0;
|
|
4859
4932
|
if (modelDef.baseModel) {
|
|
@@ -4904,6 +4977,50 @@ var BaseOperationHandler = class {
|
|
|
4904
4977
|
}
|
|
4905
4978
|
}
|
|
4906
4979
|
}
|
|
4980
|
+
/**
|
|
4981
|
+
* Runs `updateMany` on a delegate sub model by id. Reads the ids of the rows that match
|
|
4982
|
+
* `where`, then updates them in batches with an id filter. Callers run this inside a
|
|
4983
|
+
* transaction (`needsNestedUpdate` is true for every model with a base model).
|
|
4984
|
+
*/
|
|
4985
|
+
async updateManyByIds(kysely, model, where, data, returnData, fieldsToReturn) {
|
|
4986
|
+
const idFields = requireIdFields(this.schema, model);
|
|
4987
|
+
const rows = await this.read(kysely, model, {
|
|
4988
|
+
where,
|
|
4989
|
+
select: Object.fromEntries(idFields.map((f) => [f, true]))
|
|
4990
|
+
});
|
|
4991
|
+
const batchSize = idFields.length === 1 ? 1e3 : 100;
|
|
4992
|
+
let count = 0;
|
|
4993
|
+
const returned = [];
|
|
4994
|
+
for (let i = 0; i < rows.length; i += batchSize) {
|
|
4995
|
+
const batch = rows.slice(i, i + batchSize);
|
|
4996
|
+
const idWhere = idFields.length === 1 ? { [idFields[0]]: { in: batch.map((row) => row[idFields[0]]) } } : { OR: batch.map((row) => Object.fromEntries(idFields.map((f) => [f, row[f]]))) };
|
|
4997
|
+
const result = await this.updateMany(kysely, model, idWhere, data, void 0, returnData, model, void 0, fieldsToReturn);
|
|
4998
|
+
if (returnData) returned.push(...result);
|
|
4999
|
+
else count += result.count;
|
|
5000
|
+
}
|
|
5001
|
+
return returnData ? returned : { count };
|
|
5002
|
+
}
|
|
5003
|
+
/**
|
|
5004
|
+
* Sets `@updatedAt` fields to the current time when `data` changes a scalar or foreign key
|
|
5005
|
+
* field that is not in the field's `ignore` list. A value given explicitly in `data` is kept.
|
|
5006
|
+
* Returns the original `data` object when nothing is filled in, otherwise a clone.
|
|
5007
|
+
*/
|
|
5008
|
+
fillUpdatedAtFields(modelDef, data) {
|
|
5009
|
+
let result = data;
|
|
5010
|
+
const autoUpdatedFields = [];
|
|
5011
|
+
for (const [fieldName, fieldDef] of Object.entries(modelDef.fields)) if (fieldDef.updatedAt && result[fieldName] === void 0) {
|
|
5012
|
+
const ignoredFields = new Set(typeof fieldDef.updatedAt === "boolean" ? [] : fieldDef.updatedAt.ignore);
|
|
5013
|
+
if (Object.keys(data).some((field) => (isScalarField(this.schema, modelDef.name, field) || isForeignKeyField(this.schema, modelDef.name, field)) && !ignoredFields.has(field))) {
|
|
5014
|
+
if (result === data) result = clone(data);
|
|
5015
|
+
result[fieldName] = this.dialect.transformInput(/* @__PURE__ */ new Date(), "DateTime", false, fieldDef);
|
|
5016
|
+
autoUpdatedFields.push(fieldName);
|
|
5017
|
+
}
|
|
5018
|
+
}
|
|
5019
|
+
return {
|
|
5020
|
+
data: result,
|
|
5021
|
+
autoUpdatedFields
|
|
5022
|
+
};
|
|
5023
|
+
}
|
|
4907
5024
|
async processBaseModelUpdateMany(kysely, model, where, updateFields, filterModel) {
|
|
4908
5025
|
const thisUpdateFields = {};
|
|
4909
5026
|
const remainingFields = {};
|
|
@@ -4974,7 +5091,7 @@ var BaseOperationHandler = class {
|
|
|
4974
5091
|
case "updateMany":
|
|
4975
5092
|
for (const _item of enumerate(value)) {
|
|
4976
5093
|
const item = _item;
|
|
4977
|
-
await this.updateMany(kysely, fieldModel, item.where, item.data, item.limit, false,
|
|
5094
|
+
await this.updateMany(kysely, fieldModel, item.where, item.data, item.limit, false, void 0, fromRelationContext);
|
|
4978
5095
|
}
|
|
4979
5096
|
break;
|
|
4980
5097
|
case "delete":
|
|
@@ -5166,17 +5283,12 @@ var BaseOperationHandler = class {
|
|
|
5166
5283
|
}
|
|
5167
5284
|
const cascadeRelations = this.getDelegateCascadeRelations(model, filterModel);
|
|
5168
5285
|
if (cascadeRelations.length === 0) return this.executeDelete(kysely, model, where, limit, filterModel, fieldsToReturn);
|
|
5169
|
-
if (!modelDef.isDelegate) {
|
|
5170
|
-
if (limit !== void 0) throw createNotSupportedError("Deleting with a limit is not supported for polymorphic models");
|
|
5171
|
-
for (const { fieldDef } of cascadeRelations) await this.delete(kysely, fieldDef.type, { [fieldDef.relation.opposite]: where }, void 0, void 0, void 0, visited);
|
|
5172
|
-
return this.executeDelete(kysely, model, where, limit, filterModel, fieldsToReturn);
|
|
5173
|
-
}
|
|
5174
5286
|
const discriminator = getDiscriminatorField(this.schema, model);
|
|
5175
5287
|
const deletedRows = await this.read(kysely, filterModel, {
|
|
5176
5288
|
where,
|
|
5177
5289
|
select: {
|
|
5178
5290
|
...this.makeIdSelect(filterModel),
|
|
5179
|
-
[discriminator]: true
|
|
5291
|
+
...discriminator ? { [discriminator]: true } : {}
|
|
5180
5292
|
},
|
|
5181
5293
|
...limit !== void 0 ? { take: limit } : {}
|
|
5182
5294
|
});
|
|
@@ -5455,7 +5567,7 @@ var AggregateOperationHandler = class extends BaseOperationHandler {
|
|
|
5455
5567
|
if (typeof value === "string") {
|
|
5456
5568
|
const fieldDef = getField(this.schema, this.model, field);
|
|
5457
5569
|
if (fieldDef) {
|
|
5458
|
-
const type = fieldDef.type;
|
|
5570
|
+
const type = isPrimitiveTypeDef(this.schema, fieldDef.type) ? this.schema.typeDefs[fieldDef.type].base : fieldDef.type;
|
|
5459
5571
|
if (op === "_avg") val = parseFloat(val);
|
|
5460
5572
|
else if (op === "_sum" || op === "_min" || op === "_max") val = match(type).with("Int", () => parseInt(value, 10)).with("BigInt", () => BigInt(value)).with("Float", () => parseFloat(value)).with("Decimal", () => parseFloat(value)).otherwise(() => value);
|
|
5461
5573
|
}
|
|
@@ -5678,7 +5790,7 @@ var GroupByOperationHandler = class extends BaseOperationHandler {
|
|
|
5678
5790
|
if (typeof value === "string") {
|
|
5679
5791
|
const fieldDef = getField(this.schema, this.model, field);
|
|
5680
5792
|
if (fieldDef) {
|
|
5681
|
-
const type = fieldDef.type;
|
|
5793
|
+
const type = isPrimitiveTypeDef(this.schema, fieldDef.type) ? this.schema.typeDefs[fieldDef.type].base : fieldDef.type;
|
|
5682
5794
|
if (op === "_avg") val = parseFloat(val);
|
|
5683
5795
|
else if (op === "_sum" || op === "_min" || op === "_max") val = match(type).with("Int", () => parseInt(value, 10)).with("BigInt", () => BigInt(value)).with("Float", () => parseFloat(value)).with("Decimal", () => parseFloat(value)).otherwise(() => value);
|
|
5684
5796
|
}
|
|
@@ -6098,7 +6210,7 @@ var QueryNameMapper = class extends OperationNodeTransformer {
|
|
|
6098
6210
|
return ColumnNode.create(mappedName);
|
|
6099
6211
|
}
|
|
6100
6212
|
transformBinaryOperation(node, queryId) {
|
|
6101
|
-
if (ReferenceNode.is(node.leftOperand) && ColumnNode.is(node.leftOperand.column) && (ValueNode.is(node.rightOperand) || PrimitiveValueListNode.is(node.rightOperand))) {
|
|
6213
|
+
if (ReferenceNode.is(node.leftOperand) && ColumnNode.is(node.leftOperand.column) && (ValueNode.is(node.rightOperand) || PrimitiveValueListNode.is(node.rightOperand) || ValueListNode.is(node.rightOperand))) {
|
|
6102
6214
|
const columnNode = node.leftOperand.column;
|
|
6103
6215
|
const resolvedScope = this.resolveFieldFromScopes(columnNode.column.name, node.leftOperand.table?.table.identifier.name);
|
|
6104
6216
|
if (resolvedScope?.model) {
|
|
@@ -6106,6 +6218,7 @@ var QueryNameMapper = class extends OperationNodeTransformer {
|
|
|
6106
6218
|
let resultValue = valueNode;
|
|
6107
6219
|
if (ValueNode.is(valueNode)) resultValue = this.processEnumMappingForValue(resolvedScope.model, columnNode, valueNode);
|
|
6108
6220
|
else if (PrimitiveValueListNode.is(valueNode)) resultValue = PrimitiveValueListNode.create(this.processEnumMappingForValues(resolvedScope.model, valueNode.values.map(() => columnNode), valueNode.values));
|
|
6221
|
+
else if (ValueListNode.is(valueNode)) resultValue = ValueListNode.create(valueNode.values.map((v) => ValueNode.is(v) ? this.processEnumMappingForValue(resolvedScope.model, columnNode, v) : v));
|
|
6109
6222
|
return super.transformBinaryOperation({
|
|
6110
6223
|
...node,
|
|
6111
6224
|
rightOperand: resultValue
|
|
@@ -6506,7 +6619,11 @@ var ZenStackQueryExecutor = class ZenStackQueryExecutor extends DefaultQueryExec
|
|
|
6506
6619
|
return (this.client.$options.plugins ?? []).some((plugin) => plugin.onEntityMutation);
|
|
6507
6620
|
}
|
|
6508
6621
|
get hasEntityMutationPluginsWithAfterMutationHooks() {
|
|
6509
|
-
return (this.client.$options.plugins ?? []).some((plugin) =>
|
|
6622
|
+
return (this.client.$options.plugins ?? []).some((plugin) => {
|
|
6623
|
+
if (!plugin.onEntityMutation) return false;
|
|
6624
|
+
if (plugin.onEntityMutation["$all"]?.afterEntityMutation) return true;
|
|
6625
|
+
return Object.keys(this.client.$schema.models).some((model) => plugin.onEntityMutation?.[model]?.afterEntityMutation);
|
|
6626
|
+
});
|
|
6510
6627
|
}
|
|
6511
6628
|
get hasOnKyselyHooks() {
|
|
6512
6629
|
return (this.client.$options.plugins ?? []).some((plugin) => plugin.onKyselyQuery);
|
|
@@ -6611,8 +6728,17 @@ var ZenStackQueryExecutor = class ZenStackQueryExecutor extends DefaultQueryExec
|
|
|
6611
6728
|
const { queryNode, mutationInfo, loadBeforeMutationEntities, client, queryId } = args;
|
|
6612
6729
|
if (this.options.plugins) for (const plugin of this.options.plugins) {
|
|
6613
6730
|
const onEntityMutation = plugin.onEntityMutation;
|
|
6614
|
-
if (!onEntityMutation
|
|
6615
|
-
await onEntityMutation.beforeEntityMutation({
|
|
6731
|
+
if (!onEntityMutation) continue;
|
|
6732
|
+
if (onEntityMutation["$all"]?.beforeEntityMutation) await onEntityMutation["$all"].beforeEntityMutation({
|
|
6733
|
+
model: mutationInfo.model,
|
|
6734
|
+
action: mutationInfo.action,
|
|
6735
|
+
queryNode,
|
|
6736
|
+
loadBeforeMutationEntities,
|
|
6737
|
+
client,
|
|
6738
|
+
queryId
|
|
6739
|
+
});
|
|
6740
|
+
const modelHooks = onEntityMutation[mutationInfo.model];
|
|
6741
|
+
if (modelHooks?.beforeEntityMutation) await modelHooks.beforeEntityMutation({
|
|
6616
6742
|
model: mutationInfo.model,
|
|
6617
6743
|
action: mutationInfo.action,
|
|
6618
6744
|
queryNode,
|
|
@@ -6627,10 +6753,16 @@ var ZenStackQueryExecutor = class ZenStackQueryExecutor extends DefaultQueryExec
|
|
|
6627
6753
|
const hooks = [];
|
|
6628
6754
|
for (const plugin of this.options.plugins ?? []) {
|
|
6629
6755
|
const onEntityMutation = plugin.onEntityMutation;
|
|
6630
|
-
if (!onEntityMutation
|
|
6631
|
-
if (
|
|
6632
|
-
|
|
6633
|
-
|
|
6756
|
+
if (!onEntityMutation) continue;
|
|
6757
|
+
if (onEntityMutation["$all"]?.afterEntityMutation) {
|
|
6758
|
+
const runInTx = onEntityMutation["$all"].runAfterMutationWithinTransaction ?? false;
|
|
6759
|
+
if (filterFor === "all" || filterFor === "inTx" && runInTx || filterFor === "outTx" && !runInTx) hooks.push(onEntityMutation["$all"].afterEntityMutation.bind(plugin));
|
|
6760
|
+
}
|
|
6761
|
+
const modelHooks = onEntityMutation[mutationInfo.model];
|
|
6762
|
+
if (modelHooks?.afterEntityMutation) {
|
|
6763
|
+
const runInTx = modelHooks.runAfterMutationWithinTransaction ?? false;
|
|
6764
|
+
if (filterFor === "all" || filterFor === "inTx" && runInTx || filterFor === "outTx" && !runInTx) hooks.push(modelHooks.afterEntityMutation.bind(plugin));
|
|
6765
|
+
}
|
|
6634
6766
|
}
|
|
6635
6767
|
if (hooks.length === 0) return;
|
|
6636
6768
|
for (const hook of hooks) await hook({
|
|
@@ -6645,9 +6777,10 @@ var ZenStackQueryExecutor = class ZenStackQueryExecutor extends DefaultQueryExec
|
|
|
6645
6777
|
}
|
|
6646
6778
|
async loadAfterMutationEntities(mutationInfo, queryNode, queryResult, connection, preUpdateIds) {
|
|
6647
6779
|
if (mutationInfo.action === "delete") return;
|
|
6648
|
-
if (this.dialect.supportsReturning) return queryResult.rows;
|
|
6780
|
+
if (this.dialect.supportsReturning) return queryResult.rows.map((row) => ({ ...row }));
|
|
6649
6781
|
else {
|
|
6650
6782
|
const mutatedIds = InsertQueryNode.is(queryNode) ? this.getInsertIds(mutationInfo.model, queryNode, queryResult) : preUpdateIds;
|
|
6783
|
+
if (mutatedIds && mutatedIds.length === 0) return [];
|
|
6651
6784
|
if (mutatedIds) {
|
|
6652
6785
|
const idFields = requireIdFields(this.client.$schema, mutationInfo.model);
|
|
6653
6786
|
const eb = expressionBuilder();
|
|
@@ -7105,8 +7238,12 @@ var SchemaDbPusher = class {
|
|
|
7105
7238
|
return sql.raw(`enum(${enumValues.map((v) => `'${v}'`).join(", ")})`);
|
|
7106
7239
|
} else return "text";
|
|
7107
7240
|
if (this.isAutoIncrement(fieldDef) && this.schema.provider.type === "postgresql") return "serial";
|
|
7108
|
-
|
|
7109
|
-
|
|
7241
|
+
let type = fieldDef.type;
|
|
7242
|
+
if (this.isCustomType(type)) {
|
|
7243
|
+
const typeDef = Object.values(this.schema.typeDefs).find((def) => def.name === type);
|
|
7244
|
+
if (typeDef.base) type = typeDef.base;
|
|
7245
|
+
else return this.jsonType;
|
|
7246
|
+
}
|
|
7110
7247
|
const result = match(type).with("String", () => this.stringType).with("Boolean", () => this.booleanType).with("Int", () => this.intType).with("Float", () => this.floatType).with("BigInt", () => this.bigIntType).with("Decimal", () => this.decimalType).with("DateTime", () => this.dateTimeType).with("Bytes", () => this.bytesType).with("Json", () => this.jsonType).otherwise(() => {
|
|
7111
7248
|
throw new Error(`Unsupported field type: ${type}`);
|
|
7112
7249
|
});
|
|
@@ -7298,6 +7435,7 @@ var ResultProcessor = class {
|
|
|
7298
7435
|
};
|
|
7299
7436
|
//#endregion
|
|
7300
7437
|
//#region src/client/client-impl.ts
|
|
7438
|
+
const warnedPlugins = /* @__PURE__ */ new WeakSet();
|
|
7301
7439
|
/**
|
|
7302
7440
|
* Returns the name mapper held by a ZenStack executor, or undefined for a plain kysely one.
|
|
7303
7441
|
*/
|
|
@@ -7328,6 +7466,7 @@ var ClientImpl = class ClientImpl {
|
|
|
7328
7466
|
...functions_exports,
|
|
7329
7467
|
...this.$options.functions
|
|
7330
7468
|
};
|
|
7469
|
+
if (this.$options.plugins) this.$options.plugins = this.normalizePlugins(this.$options.plugins);
|
|
7331
7470
|
this.validateOptions(baseClient, options);
|
|
7332
7471
|
if (baseClient) {
|
|
7333
7472
|
this.kyselyProps = {
|
|
@@ -7361,12 +7500,69 @@ var ClientImpl = class ClientImpl {
|
|
|
7361
7500
|
this.inputValidator = baseClient?.inputValidator ?? new InputValidator(this, { enabled: this.$options.validateInput !== false });
|
|
7362
7501
|
return createClientProxy(this);
|
|
7363
7502
|
}
|
|
7503
|
+
/**
|
|
7504
|
+
* Normalizes plugin definitions for backward compatibility and validates
|
|
7505
|
+
* `onEntityMutation` keys. Legacy plugins that define hooks directly under
|
|
7506
|
+
* `onEntityMutation` (instead of under `$all`) are converted to the new shape
|
|
7507
|
+
* with a one-time warning.
|
|
7508
|
+
*/
|
|
7509
|
+
normalizePlugins(plugins) {
|
|
7510
|
+
let changed = false;
|
|
7511
|
+
const result = plugins.map((plugin) => {
|
|
7512
|
+
const normalized = this.normalizeEntityMutationHooks(plugin);
|
|
7513
|
+
if (normalized !== plugin) changed = true;
|
|
7514
|
+
return normalized;
|
|
7515
|
+
});
|
|
7516
|
+
return changed ? result : plugins;
|
|
7517
|
+
}
|
|
7518
|
+
normalizeEntityMutationHooks(plugin) {
|
|
7519
|
+
const hooks = plugin.onEntityMutation;
|
|
7520
|
+
if (!hooks || typeof hooks !== "object") return plugin;
|
|
7521
|
+
const legacyKeys = [
|
|
7522
|
+
"beforeEntityMutation",
|
|
7523
|
+
"afterEntityMutation",
|
|
7524
|
+
"runAfterMutationWithinTransaction"
|
|
7525
|
+
];
|
|
7526
|
+
const presentLegacyKeys = legacyKeys.filter((key) => key in hooks);
|
|
7527
|
+
const unknownKeys = Object.keys(hooks).filter((key) => key !== "$all" && !legacyKeys.includes(key) && !(key in this.$schema.models));
|
|
7528
|
+
const warnOnce = (message) => {
|
|
7529
|
+
if (!warnedPlugins.has(hooks)) console.warn(message);
|
|
7530
|
+
};
|
|
7531
|
+
if (unknownKeys.length > 0) warnOnce(`Plugin "${plugin.id}" defines "onEntityMutation" hooks for unknown keys: ${unknownKeys.map((k) => `"${k}"`).join(", ")}. Valid keys are "$all" and model names. These hooks will never be invoked.`);
|
|
7532
|
+
if (presentLegacyKeys.length === 0) {
|
|
7533
|
+
warnedPlugins.add(hooks);
|
|
7534
|
+
return plugin;
|
|
7535
|
+
}
|
|
7536
|
+
warnOnce(`Plugin "${plugin.id}" defines "onEntityMutation" hooks in a deprecated shape. Hooks that apply to all models should be nested under "$all": { onEntityMutation: { $all: { beforeEntityMutation, afterEntityMutation, runAfterMutationWithinTransaction } } }. The legacy shape is still supported but will be removed in a future release.`);
|
|
7537
|
+
warnedPlugins.add(hooks);
|
|
7538
|
+
const legacy = {};
|
|
7539
|
+
const rest = {};
|
|
7540
|
+
for (const [key, value] of Object.entries(hooks)) if (legacyKeys.includes(key)) legacy[key] = value;
|
|
7541
|
+
else rest[key] = value;
|
|
7542
|
+
for (const key of ["beforeEntityMutation", "afterEntityMutation"]) if (typeof legacy[key] === "function") legacy[key] = legacy[key].bind(plugin);
|
|
7543
|
+
const normalizedHooks = {
|
|
7544
|
+
...rest,
|
|
7545
|
+
$all: {
|
|
7546
|
+
...legacy,
|
|
7547
|
+
...rest["$all"]
|
|
7548
|
+
}
|
|
7549
|
+
};
|
|
7550
|
+
warnedPlugins.add(normalizedHooks);
|
|
7551
|
+
const copy = Object.create(Object.getPrototypeOf(plugin), Object.getOwnPropertyDescriptors(plugin));
|
|
7552
|
+
Object.defineProperty(copy, "onEntityMutation", {
|
|
7553
|
+
value: normalizedHooks,
|
|
7554
|
+
enumerable: true,
|
|
7555
|
+
configurable: true,
|
|
7556
|
+
writable: true
|
|
7557
|
+
});
|
|
7558
|
+
return copy;
|
|
7559
|
+
}
|
|
7364
7560
|
validateOptions(baseClient, options) {
|
|
7365
7561
|
if (!baseClient && !options.skipValidationForComputedFields) this.validateComputedFieldsConfig(options);
|
|
7366
7562
|
if (options.diagnostics) {
|
|
7367
|
-
const parseResult = z
|
|
7368
|
-
slowQueryThresholdMs: z
|
|
7369
|
-
slowQueryMaxRecords: z
|
|
7563
|
+
const parseResult = z.object({
|
|
7564
|
+
slowQueryThresholdMs: z.number().nonnegative().optional(),
|
|
7565
|
+
slowQueryMaxRecords: z.int().nonnegative().or(z.literal(Infinity)).optional()
|
|
7370
7566
|
}).safeParse(options.diagnostics);
|
|
7371
7567
|
if (!parseResult.success) throw createConfigError(`Invalid diagnostics configuration: ${formatError(parseResult.error)}`);
|
|
7372
7568
|
}
|
|
@@ -7503,7 +7699,7 @@ var ClientImpl = class ClientImpl {
|
|
|
7503
7699
|
plugins: newPlugins
|
|
7504
7700
|
};
|
|
7505
7701
|
const newClient = new ClientImpl(this.schema, newOptions, this);
|
|
7506
|
-
newClient.inputValidator =
|
|
7702
|
+
newClient.inputValidator = this.deriveInputValidator(newClient);
|
|
7507
7703
|
return newClient;
|
|
7508
7704
|
}
|
|
7509
7705
|
$unuse(pluginId) {
|
|
@@ -7514,7 +7710,7 @@ var ClientImpl = class ClientImpl {
|
|
|
7514
7710
|
plugins: newPlugins
|
|
7515
7711
|
};
|
|
7516
7712
|
const newClient = new ClientImpl(this.schema, newOptions, this);
|
|
7517
|
-
newClient.inputValidator =
|
|
7713
|
+
newClient.inputValidator = this.deriveInputValidator(newClient);
|
|
7518
7714
|
return newClient;
|
|
7519
7715
|
}
|
|
7520
7716
|
$unuseAll() {
|
|
@@ -7523,9 +7719,22 @@ var ClientImpl = class ClientImpl {
|
|
|
7523
7719
|
plugins: []
|
|
7524
7720
|
};
|
|
7525
7721
|
const newClient = new ClientImpl(this.schema, newOptions, this);
|
|
7526
|
-
newClient.inputValidator =
|
|
7722
|
+
newClient.inputValidator = this.deriveInputValidator(newClient);
|
|
7527
7723
|
return newClient;
|
|
7528
7724
|
}
|
|
7725
|
+
/**
|
|
7726
|
+
* Validator for a client derived from this one. The derived client reuses this client's Zod
|
|
7727
|
+
* schema factory, and so its schema cache, whenever its options shape the same query-args
|
|
7728
|
+
* schemas; it only gets a fresh factory when a plugin that extends query args or results was
|
|
7729
|
+
* added or removed, or `omit`/`slicing` changed. The validator itself is always new because
|
|
7730
|
+
* `validateInput` may differ.
|
|
7731
|
+
*/
|
|
7732
|
+
deriveInputValidator(newClient) {
|
|
7733
|
+
return new InputValidator(newClient, {
|
|
7734
|
+
enabled: newClient.$options.validateInput !== false,
|
|
7735
|
+
zodFactory: haveSameSchemaInputs(this.$options, newClient.$options) ? this.inputValidator.zodFactory : void 0
|
|
7736
|
+
});
|
|
7737
|
+
}
|
|
7529
7738
|
$setAuth(auth) {
|
|
7530
7739
|
if (auth !== void 0 && (typeof auth !== "object" || auth === null || Array.isArray(auth))) throw new Error("Invalid auth object");
|
|
7531
7740
|
const newClient = new ClientImpl(this.schema, this.$options, this);
|
|
@@ -7547,7 +7756,7 @@ var ClientImpl = class ClientImpl {
|
|
|
7547
7756
|
}
|
|
7548
7757
|
$setOptions(options) {
|
|
7549
7758
|
const newClient = new ClientImpl(this.schema, options, this);
|
|
7550
|
-
newClient.inputValidator =
|
|
7759
|
+
newClient.inputValidator = this.deriveInputValidator(newClient);
|
|
7551
7760
|
return newClient;
|
|
7552
7761
|
}
|
|
7553
7762
|
$setInputValidation(enable) {
|