@zenstackhq/orm 3.8.3 → 3.9.0
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 +165 -76
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +116 -36
- package/dist/index.d.mts +118 -38
- package/dist/index.mjs +344 -255
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { t as __exportAll } from "./chunk-CfYAbeIz.mjs";
|
|
|
2
2
|
import { AnyNull, AnyNullClass, DbNull, DbNullClass, JsonNull, JsonNullClass } from "./common-types.mjs";
|
|
3
3
|
import { clone, enumerate, invariant, isPlainObject, lowerCaseFirst, upperCaseFirst } from "@zenstackhq/common-helpers";
|
|
4
4
|
import { AliasNode, AndNode, ColumnNode, ColumnUpdateNode, CompiledQuery, DefaultConnectionProvider, DefaultQueryExecutor, DeleteQueryNode, ExpressionWrapper, FromNode, IdentifierNode, InsertQueryNode, Kysely, Log, OperationNodeTransformer, OperationNodeVisitor, PrimitiveValueListNode, ReferenceNode, ReturningNode, SelectAllNode, SelectionNode, SingleConnectionProvider, TableNode, Transaction, UpdateQueryNode, ValueListNode, ValueNode, ValuesNode, WhereNode, createQueryId, expressionBuilder, sql } from "kysely";
|
|
5
|
-
import z
|
|
5
|
+
import z, { ZodObject, ZodType, z as z$1 } from "zod";
|
|
6
6
|
import { fromError } from "zod-validation-error/v4";
|
|
7
7
|
import { P, match } from "ts-pattern";
|
|
8
8
|
import { ExpressionUtils } from "@zenstackhq/schema";
|
|
@@ -24,26 +24,6 @@ function formatError(error) {
|
|
|
24
24
|
return fromError(error).toString();
|
|
25
25
|
}
|
|
26
26
|
//#endregion
|
|
27
|
-
//#region src/utils/object-utils.ts
|
|
28
|
-
/**
|
|
29
|
-
* Extract fields from an object.
|
|
30
|
-
*/
|
|
31
|
-
function extractFields(obj, fields) {
|
|
32
|
-
return Object.fromEntries(Object.entries(obj).filter(([key]) => fields.includes(key)));
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Create an object with fields as keys and true values.
|
|
36
|
-
*/
|
|
37
|
-
function fieldsToSelectObject(fields) {
|
|
38
|
-
return Object.fromEntries(fields.map((f) => [f, true]));
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Checks if the given value is an empty plain object.
|
|
42
|
-
*/
|
|
43
|
-
function isEmptyObject(x) {
|
|
44
|
-
return isPlainObject(x) && Object.keys(x).length === 0;
|
|
45
|
-
}
|
|
46
|
-
//#endregion
|
|
47
27
|
//#region src/client/executor/error-processor.ts
|
|
48
28
|
/**
|
|
49
29
|
* Extracts database error code from an error thrown by the database driver.
|
|
@@ -177,6 +157,26 @@ function createInternalError(message, model, options) {
|
|
|
177
157
|
return error;
|
|
178
158
|
}
|
|
179
159
|
//#endregion
|
|
160
|
+
//#region src/utils/object-utils.ts
|
|
161
|
+
/**
|
|
162
|
+
* Extract fields from an object.
|
|
163
|
+
*/
|
|
164
|
+
function extractFields(obj, fields) {
|
|
165
|
+
return Object.fromEntries(Object.entries(obj).filter(([key]) => fields.includes(key)));
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Create an object with fields as keys and true values.
|
|
169
|
+
*/
|
|
170
|
+
function fieldsToSelectObject(fields) {
|
|
171
|
+
return Object.fromEntries(fields.map((f) => [f, true]));
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Checks if the given value is an empty plain object.
|
|
175
|
+
*/
|
|
176
|
+
function isEmptyObject(x) {
|
|
177
|
+
return isPlainObject(x) && Object.keys(x).length === 0;
|
|
178
|
+
}
|
|
179
|
+
//#endregion
|
|
180
180
|
//#region src/client/query-utils.ts
|
|
181
181
|
var query_utils_exports = /* @__PURE__ */ __exportAll({
|
|
182
182
|
TEMP_ALIAS_PREFIX: () => "$$_",
|
|
@@ -696,6 +696,8 @@ var BaseCrudDialect = class {
|
|
|
696
696
|
if (typeof ob !== "object" || ob === null) return void 0;
|
|
697
697
|
if ("_fuzzyRelevance" in ob) return "_fuzzyRelevance";
|
|
698
698
|
if ("_ftsRelevance" in ob) return "_ftsRelevance";
|
|
699
|
+
const argsEntry = Object.entries(ob).find(([, v]) => v !== null && typeof v === "object" && "args" in v);
|
|
700
|
+
if (argsEntry) return argsEntry[0];
|
|
699
701
|
}).find((k) => k !== void 0);
|
|
700
702
|
if (offendingKey) throw createNotSupportedError(`cursor pagination cannot be combined with "${offendingKey}" ordering`);
|
|
701
703
|
}
|
|
@@ -718,9 +720,16 @@ var BaseCrudDialect = class {
|
|
|
718
720
|
const fieldDef = requireField(this.schema, model, key);
|
|
719
721
|
if (fieldDef.relation) result = this.and(result, this.buildRelationFilter(model, modelAlias, key, fieldDef, payload));
|
|
720
722
|
else {
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
723
|
+
let computedArgs;
|
|
724
|
+
let filterPayload = payload;
|
|
725
|
+
if (fieldDef.computed && fieldDef.params && payload && typeof payload === "object" && "args" in payload) {
|
|
726
|
+
computedArgs = payload.args;
|
|
727
|
+
const { args: _args, ...rest } = payload;
|
|
728
|
+
filterPayload = rest;
|
|
729
|
+
}
|
|
730
|
+
const fieldRef = this.fieldRef(fieldDef.originModel ?? model, key, fieldDef.originModel ?? modelAlias, true, computedArgs);
|
|
731
|
+
if (fieldDef.array) result = this.and(result, this.buildArrayFilter(fieldRef, fieldDef, filterPayload));
|
|
732
|
+
else result = this.and(result, this.buildPrimitiveFilter(fieldRef, fieldDef, filterPayload));
|
|
724
733
|
}
|
|
725
734
|
}
|
|
726
735
|
if ("$expr" in _where && typeof _where["$expr"] === "function") result = this.and(result, _where["$expr"](this.eb));
|
|
@@ -778,7 +787,7 @@ var BaseCrudDialect = class {
|
|
|
778
787
|
}
|
|
779
788
|
const joinAlias = tmpAlias(`${modelAlias}$${field}`);
|
|
780
789
|
const joinPairs = buildJoinPairs(this.schema, model, fieldDef.originModel ?? modelAlias, field, joinAlias);
|
|
781
|
-
const baseJoin = this.
|
|
790
|
+
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)))));
|
|
782
791
|
const existsSelect = (extraFilter) => {
|
|
783
792
|
const q = extraFilter ? baseJoin.where(extraFilter) : baseJoin;
|
|
784
793
|
return this.buildExistsExpression(q);
|
|
@@ -979,7 +988,7 @@ var BaseCrudDialect = class {
|
|
|
979
988
|
else if (fieldDef.array) clauses.push(this.buildArrayFilter(fieldReceiver, fieldDef, value));
|
|
980
989
|
else {
|
|
981
990
|
let _receiver = fieldReceiver;
|
|
982
|
-
if (fieldDef.type === "String") _receiver = this.trimTextQuotes(this.castText(fieldReceiver));
|
|
991
|
+
if (fieldDef.type === "String" || isEnum(this.schema, fieldDef.type)) _receiver = this.trimTextQuotes(this.castText(fieldReceiver));
|
|
983
992
|
clauses.push(this.buildPrimitiveFilter(_receiver, fieldDef, value));
|
|
984
993
|
}
|
|
985
994
|
}
|
|
@@ -1121,9 +1130,9 @@ var BaseCrudDialect = class {
|
|
|
1121
1130
|
buildOrderBy(query, model, modelAlias, orderBy, negated, take) {
|
|
1122
1131
|
if (!orderBy) return query;
|
|
1123
1132
|
let result = query;
|
|
1124
|
-
const buildFieldRef = (model, field, modelAlias) => {
|
|
1133
|
+
const buildFieldRef = (model, field, modelAlias, computedArgs) => {
|
|
1125
1134
|
const fieldDef = requireField(this.schema, model, field);
|
|
1126
|
-
return fieldDef.originModel ? this.fieldRef(fieldDef.originModel, field, fieldDef.originModel) : this.fieldRef(model, field, modelAlias);
|
|
1135
|
+
return fieldDef.originModel ? this.fieldRef(fieldDef.originModel, field, fieldDef.originModel, true, computedArgs) : this.fieldRef(model, field, modelAlias, true, computedArgs);
|
|
1127
1136
|
};
|
|
1128
1137
|
enumerate(orderBy).forEach((orderBy, index) => {
|
|
1129
1138
|
for (const [field, value] of Object.entries(orderBy)) {
|
|
@@ -1179,7 +1188,7 @@ var BaseCrudDialect = class {
|
|
|
1179
1188
|
return this.buildOrderBy(joined, relationModel, joinAlias, value, negated, take);
|
|
1180
1189
|
}
|
|
1181
1190
|
applyScalarOrderBy(query, model, modelAlias, field, value, negated, buildFieldRef) {
|
|
1182
|
-
const fieldRef = buildFieldRef(model, field, modelAlias);
|
|
1191
|
+
const fieldRef = buildFieldRef(model, field, modelAlias, value && typeof value === "object" && "args" in value ? value.args : void 0);
|
|
1183
1192
|
if (value === "asc" || value === "desc") return query.orderBy(fieldRef, this.negateSort(value, negated));
|
|
1184
1193
|
if (typeof value === "object" && "sort" in value && (value.sort === "asc" || value.sort === "desc")) {
|
|
1185
1194
|
const sort = this.negateSort(value.sort, negated);
|
|
@@ -1189,11 +1198,15 @@ var BaseCrudDialect = class {
|
|
|
1189
1198
|
return query;
|
|
1190
1199
|
}
|
|
1191
1200
|
applyAggregationOrderBy(query, model, modelAlias, field, value, negated, buildFieldRef) {
|
|
1192
|
-
|
|
1201
|
+
if (!isPlainObject(value)) throw createInvalidInputError(`invalid orderBy value for field "${field}"`);
|
|
1193
1202
|
let result = query;
|
|
1194
1203
|
for (const [k, v] of Object.entries(value)) {
|
|
1195
|
-
|
|
1196
|
-
|
|
1204
|
+
const sort = isPlainObject(v) ? v["sort"] : v;
|
|
1205
|
+
if (sort !== "asc" && sort !== "desc") throw createInvalidInputError(`invalid orderBy value for field "${field}"`);
|
|
1206
|
+
const computedArgs = isPlainObject(v) && "args" in v ? v["args"] : void 0;
|
|
1207
|
+
const aggExpr = aggregate(this.eb, buildFieldRef(model, k, modelAlias, computedArgs), field);
|
|
1208
|
+
const nulls = isPlainObject(v) ? v["nulls"] : void 0;
|
|
1209
|
+
result = nulls === "first" || nulls === "last" ? this.buildOrderByField(result, aggExpr, this.negateSort(sort, negated), nulls) : result.orderBy(aggExpr, this.negateSort(sort, negated));
|
|
1197
1210
|
}
|
|
1198
1211
|
return result;
|
|
1199
1212
|
}
|
|
@@ -1228,6 +1241,7 @@ var BaseCrudDialect = class {
|
|
|
1228
1241
|
computed: true
|
|
1229
1242
|
})) {
|
|
1230
1243
|
if (this.shouldOmitField(omit, model, fieldDef.name)) continue;
|
|
1244
|
+
if (fieldDef.computed && fieldDef.params) continue;
|
|
1231
1245
|
result = this.buildSelectField(result, model, modelAlias, fieldDef.name);
|
|
1232
1246
|
}
|
|
1233
1247
|
const descendants = getDelegateDescendantModels(this.schema, model);
|
|
@@ -1237,6 +1251,7 @@ var BaseCrudDialect = class {
|
|
|
1237
1251
|
const jsonObject = {};
|
|
1238
1252
|
for (const fieldDef of getModelFields(this.schema, subModel.name, { computed: true })) {
|
|
1239
1253
|
if (this.shouldOmitField(omit, subModel.name, fieldDef.name)) continue;
|
|
1254
|
+
if (fieldDef.computed && fieldDef.params) continue;
|
|
1240
1255
|
jsonObject[fieldDef.name] = this.fieldRef(subModel.name, fieldDef.name, subModel.name);
|
|
1241
1256
|
}
|
|
1242
1257
|
return this.buildJsonObject(jsonObject).as(`${DELEGATE_JOINED_FIELD_PREFIX}${subModel.name}`);
|
|
@@ -1257,11 +1272,11 @@ var BaseCrudDialect = class {
|
|
|
1257
1272
|
if (payload && typeof payload === "object") subQuery = this.buildFilterSortTake(model, payload, subQuery, subQueryAlias);
|
|
1258
1273
|
return subQuery;
|
|
1259
1274
|
}
|
|
1260
|
-
buildSelectField(query, model, modelAlias, field) {
|
|
1275
|
+
buildSelectField(query, model, modelAlias, field, computedArgs) {
|
|
1261
1276
|
const fieldDef = requireField(this.schema, model, field);
|
|
1262
1277
|
const fieldModel = fieldDef.originModel ?? model;
|
|
1263
1278
|
const alias = fieldDef.originModel ?? modelAlias;
|
|
1264
|
-
return query.select(() => this.fieldRef(fieldModel, field, alias).as(field));
|
|
1279
|
+
return query.select(() => this.fieldRef(fieldModel, field, alias, true, computedArgs).as(field));
|
|
1265
1280
|
}
|
|
1266
1281
|
buildDelegateJoin(thisModel, thisModelAlias, otherModelAlias, query) {
|
|
1267
1282
|
const idFields = requireIdFields(this.schema, thisModel);
|
|
@@ -1328,7 +1343,7 @@ var BaseCrudDialect = class {
|
|
|
1328
1343
|
not(...args) {
|
|
1329
1344
|
return this.eb.not(this.and(...args));
|
|
1330
1345
|
}
|
|
1331
|
-
fieldRef(model, field, modelAlias, inlineComputedField = true) {
|
|
1346
|
+
fieldRef(model, field, modelAlias, inlineComputedField = true, computedArgs) {
|
|
1332
1347
|
const fieldDef = requireField(this.schema, model, field);
|
|
1333
1348
|
if (!fieldDef.computed) return this.eb.ref(modelAlias ? `${modelAlias}.${field}` : field);
|
|
1334
1349
|
else {
|
|
@@ -1340,7 +1355,7 @@ var BaseCrudDialect = class {
|
|
|
1340
1355
|
computer = computedFields?.[lowerCaseFirst(computedModel)]?.[field] ?? computedFields?.[computedModel]?.[field];
|
|
1341
1356
|
}
|
|
1342
1357
|
if (!computer) throw createConfigError(`Computed field "${field}" implementation not provided for model "${model}"`);
|
|
1343
|
-
return computer(this.eb, { modelAlias });
|
|
1358
|
+
return computer(this.eb, { modelAlias }, computedArgs);
|
|
1344
1359
|
}
|
|
1345
1360
|
}
|
|
1346
1361
|
canJoinWithoutNestedSelect(modelDef, payload) {
|
|
@@ -1476,18 +1491,21 @@ var LateralJoinDialectBase = class extends BaseCrudDialect {
|
|
|
1476
1491
|
if (descendantModels.length > 0) Object.assign(objArgs, ...descendantModels.map((subModel) => ({ [`${DELEGATE_JOINED_FIELD_PREFIX}${subModel.name}`]: eb.ref(`${DELEGATE_JOINED_FIELD_PREFIX}${subModel.name}`) })));
|
|
1477
1492
|
if (payload === true || !payload.select) {
|
|
1478
1493
|
const omit = typeof payload === "object" ? payload.omit : void 0;
|
|
1479
|
-
Object.assign(objArgs, ...Object.entries(relationModelDef.fields).filter(([, value]) => !value.relation).filter(([name]) => !this.shouldOmitField(omit, relationModel, name)).map(([field]) => ({ [field]: this.fieldRef(relationModel, field, relationModelAlias, false) })));
|
|
1494
|
+
Object.assign(objArgs, ...Object.entries(relationModelDef.fields).filter(([, value]) => !value.relation).filter(([, value]) => !(value.computed && value.params)).filter(([name]) => !this.shouldOmitField(omit, relationModel, name)).map(([field]) => ({ [field]: this.fieldRef(relationModel, field, relationModelAlias, false) })));
|
|
1480
1495
|
} else if (payload.select) Object.assign(objArgs, ...Object.entries(payload.select).filter(([, value]) => value).map(([field, value]) => {
|
|
1481
1496
|
if (field === "_count") {
|
|
1482
1497
|
const subJson = this.buildCountJson(relationModel, eb, relationModelAlias, value);
|
|
1483
1498
|
return { [field]: subJson };
|
|
1484
1499
|
} else {
|
|
1485
|
-
const
|
|
1500
|
+
const fieldDef = requireField(this.schema, relationModel, field);
|
|
1501
|
+
const fieldValue = fieldDef.relation ? eb.ref(`${parentResultName}$${field}.$data`) : fieldDef.computed && fieldDef.params ? this.fieldRef(relationModel, field, relationModelAlias, true, value.args) : this.fieldRef(relationModel, field, relationModelAlias, false);
|
|
1486
1502
|
return { [field]: fieldValue };
|
|
1487
1503
|
}
|
|
1488
1504
|
}));
|
|
1489
1505
|
if (typeof payload === "object" && payload.include && typeof payload.include === "object") Object.assign(objArgs, ...Object.entries(payload.include).filter(([, value]) => value).map(([field, value]) => {
|
|
1490
1506
|
if (field === "_count") return { [field]: this.buildCountJson(relationModel, eb, relationModelAlias, value) };
|
|
1507
|
+
const fieldDef = requireField(this.schema, relationModel, field);
|
|
1508
|
+
if (fieldDef.computed && fieldDef.params) return { [field]: this.fieldRef(relationModel, field, relationModelAlias, true, value.args) };
|
|
1491
1509
|
return { [field]: eb.ref(`${parentResultName}$${field}.$data`) };
|
|
1492
1510
|
}));
|
|
1493
1511
|
return objArgs;
|
|
@@ -2153,21 +2171,27 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
2153
2171
|
if (descendantModels.length > 0) objArgs.push(...descendantModels.map((subModel) => [sql.lit(`${DELEGATE_JOINED_FIELD_PREFIX}${subModel.name}`), eb.ref(`${DELEGATE_JOINED_FIELD_PREFIX}${subModel.name}`)]).flatMap((v) => v));
|
|
2154
2172
|
if (payload === true || !payload.select) {
|
|
2155
2173
|
const omit = typeof payload === "object" ? payload.omit : void 0;
|
|
2156
|
-
objArgs.push(...Object.entries(relationModelDef.fields).filter(([, value]) => !value.relation).filter(([name]) => !this.shouldOmitField(omit, relationModel, name)).map(([field]) => [sql.lit(field), this.fieldRef(relationModel, field, subQueryName, false)]).flatMap((v) => v));
|
|
2174
|
+
objArgs.push(...Object.entries(relationModelDef.fields).filter(([, value]) => !value.relation).filter(([, value]) => !(value.computed && value.params)).filter(([name]) => !this.shouldOmitField(omit, relationModel, name)).map(([field]) => [sql.lit(field), this.fieldRef(relationModel, field, subQueryName, false)]).flatMap((v) => v));
|
|
2157
2175
|
} else if (payload.select) objArgs.push(...Object.entries(payload.select).filter(([, value]) => value).map(([field, value]) => {
|
|
2158
2176
|
if (field === "_count") {
|
|
2159
2177
|
const subJson = this.buildCountJson(relationModel, eb, tmpAlias(`${parentAlias}$${relationField}`), value);
|
|
2160
2178
|
return [sql.lit(field), subJson];
|
|
2161
|
-
} else
|
|
2162
|
-
const
|
|
2163
|
-
|
|
2164
|
-
|
|
2179
|
+
} else {
|
|
2180
|
+
const fieldDef = requireField(this.schema, relationModel, field);
|
|
2181
|
+
if (fieldDef.relation) {
|
|
2182
|
+
const subJson = this.buildRelationJSON(relationModel, eb, field, tmpAlias(`${parentAlias}$${relationField}`), value);
|
|
2183
|
+
return [sql.lit(field), subJson];
|
|
2184
|
+
} else if (fieldDef.computed && fieldDef.params) return [sql.lit(field), this.fieldRef(relationModel, field, subQueryName, true, value.args)];
|
|
2185
|
+
else return [sql.lit(field), this.fieldRef(relationModel, field, subQueryName, false)];
|
|
2186
|
+
}
|
|
2165
2187
|
}).flatMap((v) => v));
|
|
2166
2188
|
if (typeof payload === "object" && payload.include && typeof payload.include === "object") objArgs.push(...Object.entries(payload.include).filter(([, value]) => value).map(([field, value]) => {
|
|
2167
2189
|
if (field === "_count") {
|
|
2168
2190
|
const subJson = this.buildCountJson(relationModel, eb, tmpAlias(`${parentAlias}$${relationField}`), value);
|
|
2169
2191
|
return [sql.lit(field), subJson];
|
|
2170
2192
|
}
|
|
2193
|
+
const fieldDef = requireField(this.schema, relationModel, field);
|
|
2194
|
+
if (fieldDef.computed && fieldDef.params) return [sql.lit(field), this.fieldRef(relationModel, field, subQueryName, true, value.args)];
|
|
2171
2195
|
const subJson = this.buildRelationJSON(relationModel, eb, field, tmpAlias(`${parentAlias}$${relationField}`), value);
|
|
2172
2196
|
return [sql.lit(field), subJson];
|
|
2173
2197
|
}).flatMap((v) => v));
|
|
@@ -2343,7 +2367,7 @@ function createQuerySchemaFactory(clientOrSchema, options) {
|
|
|
2343
2367
|
* @see https://github.com/zenstackhq/zenstack/issues/2631
|
|
2344
2368
|
*/
|
|
2345
2369
|
function coercedDateTimeSchema() {
|
|
2346
|
-
return z.preprocess((val) => {
|
|
2370
|
+
return z$1.preprocess((val) => {
|
|
2347
2371
|
if (typeof val !== "string") return val;
|
|
2348
2372
|
if (/^\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d\d(?::\d\d)?)?$/.test(val)) {
|
|
2349
2373
|
const hasTz = val.endsWith("Z") || /[+-]\d\d(?::\d\d)?$/.test(val);
|
|
@@ -2352,10 +2376,10 @@ function coercedDateTimeSchema() {
|
|
|
2352
2376
|
}
|
|
2353
2377
|
const d = new Date(val);
|
|
2354
2378
|
return isNaN(d.getTime()) ? val : d;
|
|
2355
|
-
}, z.union([
|
|
2356
|
-
z.iso.datetime(),
|
|
2357
|
-
z.iso.date(),
|
|
2358
|
-
z.date()
|
|
2379
|
+
}, z$1.union([
|
|
2380
|
+
z$1.iso.datetime(),
|
|
2381
|
+
z$1.iso.date(),
|
|
2382
|
+
z$1.date()
|
|
2359
2383
|
]));
|
|
2360
2384
|
}
|
|
2361
2385
|
/**
|
|
@@ -2363,7 +2387,7 @@ function coercedDateTimeSchema() {
|
|
|
2363
2387
|
*/
|
|
2364
2388
|
var ZodSchemaFactory = class {
|
|
2365
2389
|
schemaCache = /* @__PURE__ */ new Map();
|
|
2366
|
-
schemaRegistry = z.registry();
|
|
2390
|
+
schemaRegistry = z$1.registry();
|
|
2367
2391
|
allFilterKinds = [...new Set(Object.values(FILTER_PROPERTY_TO_KIND))];
|
|
2368
2392
|
schema;
|
|
2369
2393
|
options;
|
|
@@ -2455,7 +2479,7 @@ var ZodSchemaFactory = class {
|
|
|
2455
2479
|
this.makeGroupBySchema(m);
|
|
2456
2480
|
}
|
|
2457
2481
|
for (const procName of Object.keys(this.schema.procedures ?? {})) if (this.isProcedureAllowed(procName)) this.makeProcedureArgsSchema(procName);
|
|
2458
|
-
return z.toJSONSchema(this.schemaRegistry, { unrepresentable: "any" });
|
|
2482
|
+
return z$1.toJSONSchema(this.schemaRegistry, { unrepresentable: "any" });
|
|
2459
2483
|
}
|
|
2460
2484
|
get cacheStats() {
|
|
2461
2485
|
return {
|
|
@@ -2484,13 +2508,13 @@ var ZodSchemaFactory = class {
|
|
|
2484
2508
|
fields["omit"] = this.makeOmitSchema(model).optional().nullable();
|
|
2485
2509
|
if (!unique) {
|
|
2486
2510
|
fields["skip"] = this.makeSkipSchema().optional();
|
|
2487
|
-
if (findOne) fields["take"] = z.literal(1).optional();
|
|
2511
|
+
if (findOne) fields["take"] = z$1.literal(1).optional();
|
|
2488
2512
|
else fields["take"] = this.makeTakeSchema().optional();
|
|
2489
2513
|
fields["orderBy"] = this.orArray(this.makeOrderBySchema(model, true, false, options), true).optional();
|
|
2490
2514
|
fields["cursor"] = this.makeCursorSchema(model, options).optional();
|
|
2491
2515
|
fields["distinct"] = this.makeDistinctSchema(model).optional();
|
|
2492
2516
|
}
|
|
2493
|
-
const baseSchema = z.strictObject(fields);
|
|
2517
|
+
const baseSchema = z$1.strictObject(fields);
|
|
2494
2518
|
let result = this.mergePluginArgsSchema(baseSchema, operation);
|
|
2495
2519
|
result = this.refineForSelectIncludeMutuallyExclusive(result);
|
|
2496
2520
|
result = this.refineForSelectOmitMutuallyExclusive(result);
|
|
@@ -2500,7 +2524,7 @@ var ZodSchemaFactory = class {
|
|
|
2500
2524
|
return result;
|
|
2501
2525
|
}
|
|
2502
2526
|
makeExistsSchema(model, options) {
|
|
2503
|
-
const baseSchema = z.strictObject({ where: this.makeWhereSchema(model, false, false, false, options).optional() });
|
|
2527
|
+
const baseSchema = z$1.strictObject({ where: this.makeWhereSchema(model, false, false, false, options).optional() });
|
|
2504
2528
|
const result = this.mergePluginArgsSchema(baseSchema, "exists").optional();
|
|
2505
2529
|
this.registerSchema(`${model}ExistsArgs`, result);
|
|
2506
2530
|
return result;
|
|
@@ -2508,31 +2532,50 @@ var ZodSchemaFactory = class {
|
|
|
2508
2532
|
makeScalarSchema(type, attributes) {
|
|
2509
2533
|
if (this.schema.typeDefs && type in this.schema.typeDefs) return this.makeTypeDefSchema(type);
|
|
2510
2534
|
else if (this.schema.enums && type in this.schema.enums) return this.makeEnumSchema(type);
|
|
2511
|
-
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", () => {
|
|
2512
|
-
return z.union([
|
|
2513
|
-
this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z.number(), attributes) : z.number(),
|
|
2514
|
-
ZodUtils.addDecimalValidation(z.instanceof(Decimal), attributes, this.extraValidationsEnabled),
|
|
2515
|
-
ZodUtils.addDecimalValidation(z.string(), attributes, this.extraValidationsEnabled)
|
|
2535
|
+
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", () => {
|
|
2536
|
+
return z$1.union([
|
|
2537
|
+
this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z$1.number(), attributes) : z$1.number(),
|
|
2538
|
+
ZodUtils.addDecimalValidation(z$1.instanceof(Decimal), attributes, this.extraValidationsEnabled),
|
|
2539
|
+
ZodUtils.addDecimalValidation(z$1.string(), attributes, this.extraValidationsEnabled)
|
|
2516
2540
|
]);
|
|
2517
|
-
}).with("DateTime", () => this.makeDateTimeValueSchema()).with("Bytes", () => z.instanceof(Uint8Array)).with("Json", () => this.makeJsonValueSchema()).otherwise(() => z.unknown());
|
|
2541
|
+
}).with("DateTime", () => this.makeDateTimeValueSchema()).with("Bytes", () => z$1.instanceof(Uint8Array)).with("Json", () => this.makeJsonValueSchema()).otherwise(() => z$1.unknown());
|
|
2542
|
+
}
|
|
2543
|
+
isParameterizedComputedField(fieldDef) {
|
|
2544
|
+
return !!(fieldDef.computed && fieldDef.params);
|
|
2545
|
+
}
|
|
2546
|
+
makeFieldArgsSchema(params) {
|
|
2547
|
+
return z$1.strictObject(Object.fromEntries(Object.entries(params).map(([name, param]) => {
|
|
2548
|
+
let paramSchema = this.makeScalarSchema(param.type);
|
|
2549
|
+
if (param.array) paramSchema = paramSchema.array();
|
|
2550
|
+
if (param.optional) paramSchema = paramSchema.optional();
|
|
2551
|
+
return [name, paramSchema];
|
|
2552
|
+
})));
|
|
2553
|
+
}
|
|
2554
|
+
addComputedArgsToFilter(filterSchema, params) {
|
|
2555
|
+
const objectMembers = (filterSchema instanceof z$1.ZodUnion ? filterSchema.options : [filterSchema]).filter((m) => m instanceof z$1.ZodObject);
|
|
2556
|
+
const components = Object.assign({}, ...objectMembers.map((o) => o.shape));
|
|
2557
|
+
return z$1.strictObject({
|
|
2558
|
+
args: this.makeFieldArgsSchema(params),
|
|
2559
|
+
...components
|
|
2560
|
+
});
|
|
2518
2561
|
}
|
|
2519
2562
|
makeEnumSchema(_enum) {
|
|
2520
2563
|
const enumDef = getEnum(this.schema, _enum);
|
|
2521
2564
|
invariant(enumDef, `Enum "${_enum}" not found in schema`);
|
|
2522
|
-
const schema = z.enum(Object.keys(enumDef.values));
|
|
2565
|
+
const schema = z$1.enum(Object.keys(enumDef.values));
|
|
2523
2566
|
this.registerSchema(_enum, schema);
|
|
2524
2567
|
return schema;
|
|
2525
2568
|
}
|
|
2526
2569
|
makeTypeDefSchema(type) {
|
|
2527
2570
|
const typeDef = getTypeDef(this.schema, type);
|
|
2528
2571
|
invariant(typeDef, `Type definition "${type}" not found in schema`);
|
|
2529
|
-
const schema = z.looseObject(Object.fromEntries(Object.entries(typeDef.fields).map(([field, def]) => {
|
|
2530
|
-
let fieldSchema = isTypeDef(this.schema, def.type) ? z.lazy(() => this.makeTypeDefSchema(def.type)) : this.makeScalarSchema(def.type);
|
|
2572
|
+
const schema = z$1.looseObject(Object.fromEntries(Object.entries(typeDef.fields).map(([field, def]) => {
|
|
2573
|
+
let fieldSchema = isTypeDef(this.schema, def.type) ? z$1.lazy(() => this.makeTypeDefSchema(def.type)) : this.makeScalarSchema(def.type);
|
|
2531
2574
|
if (def.array) fieldSchema = fieldSchema.array();
|
|
2532
2575
|
if (def.optional) fieldSchema = fieldSchema.nullish();
|
|
2533
2576
|
return [field, fieldSchema];
|
|
2534
2577
|
})));
|
|
2535
|
-
const finalSchema = z.any().superRefine((value, ctx) => {
|
|
2578
|
+
const finalSchema = z$1.any().superRefine((value, ctx) => {
|
|
2536
2579
|
const parseResult = schema.safeParse(value);
|
|
2537
2580
|
if (!parseResult.success) parseResult.error.issues.forEach((issue) => ctx.addIssue(issue));
|
|
2538
2581
|
});
|
|
@@ -2548,17 +2591,17 @@ var ZodSchemaFactory = class {
|
|
|
2548
2591
|
if (fieldDef.relation) {
|
|
2549
2592
|
if (withoutRelationFields || !this.shouldIncludeRelations(options)) continue;
|
|
2550
2593
|
const allowedFilterKinds = this.getEffectiveFilterKinds(model, field);
|
|
2551
|
-
if (allowedFilterKinds && !allowedFilterKinds.includes("Relation")) fieldSchema = z.never();
|
|
2594
|
+
if (allowedFilterKinds && !allowedFilterKinds.includes("Relation")) fieldSchema = z$1.never();
|
|
2552
2595
|
else {
|
|
2553
|
-
fieldSchema = z.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts).optional());
|
|
2554
|
-
if (fieldDef.array) fieldSchema = z.strictObject({
|
|
2596
|
+
fieldSchema = z$1.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts).optional());
|
|
2597
|
+
if (fieldDef.array) fieldSchema = z$1.strictObject({
|
|
2555
2598
|
some: fieldSchema.optional(),
|
|
2556
2599
|
every: fieldSchema.optional(),
|
|
2557
2600
|
none: fieldSchema.optional()
|
|
2558
2601
|
});
|
|
2559
2602
|
else {
|
|
2560
2603
|
fieldSchema = this.nullableIf(fieldSchema, !fieldDef.array && !!fieldDef.optional);
|
|
2561
|
-
fieldSchema = z.union([fieldSchema, z.strictObject({
|
|
2604
|
+
fieldSchema = z$1.union([fieldSchema, z$1.strictObject({
|
|
2562
2605
|
is: fieldSchema.optional(),
|
|
2563
2606
|
isNot: fieldSchema.optional()
|
|
2564
2607
|
})]);
|
|
@@ -2573,25 +2616,26 @@ var ZodSchemaFactory = class {
|
|
|
2573
2616
|
else if (this.isTypeDefType(fieldDef.type)) fieldSchema = this.makeTypedJsonFilterSchema(fieldDef.type, !!fieldDef.optional, !!fieldDef.array, allowedFilterKinds);
|
|
2574
2617
|
else fieldSchema = this.makePrimitiveFilterSchema(fieldDef.type, !!fieldDef.optional, withAggregations, allowedFilterKinds, !!fieldDef.fuzzy, !!fieldDef.fullText);
|
|
2575
2618
|
}
|
|
2619
|
+
if (fieldSchema && this.isParameterizedComputedField(fieldDef)) fieldSchema = this.addComputedArgsToFilter(fieldSchema, fieldDef.params);
|
|
2576
2620
|
if (fieldSchema) fields[field] = fieldSchema.optional();
|
|
2577
2621
|
}
|
|
2578
2622
|
if (unique) {
|
|
2579
2623
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
2580
|
-
for (const uniqueField of uniqueFields) if ("defs" in uniqueField) fields[uniqueField.name] = z.object(Object.fromEntries(Object.entries(uniqueField.defs).map(([key, def]) => {
|
|
2624
|
+
for (const uniqueField of uniqueFields) if ("defs" in uniqueField) fields[uniqueField.name] = z$1.object(Object.fromEntries(Object.entries(uniqueField.defs).map(([key, def]) => {
|
|
2581
2625
|
invariant(!def.relation, "unique field cannot be a relation");
|
|
2582
2626
|
let fieldSchema;
|
|
2583
2627
|
const enumDef = getEnum(this.schema, def.type);
|
|
2584
2628
|
if (enumDef) if (Object.keys(enumDef.values).length > 0) fieldSchema = this.makeEnumFilterSchema(def.type, !!def.optional, !!def.array, false, void 0);
|
|
2585
|
-
else fieldSchema = z.never();
|
|
2629
|
+
else fieldSchema = z$1.never();
|
|
2586
2630
|
else fieldSchema = this.makePrimitiveFilterSchema(def.type, !!def.optional, false, void 0);
|
|
2587
2631
|
return [key, fieldSchema];
|
|
2588
2632
|
}))).optional();
|
|
2589
2633
|
}
|
|
2590
|
-
fields["$expr"] = z.custom((v) => typeof v === "function", { error: "\"$expr\" must be a function" }).optional();
|
|
2591
|
-
fields["AND"] = this.orArray(z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
|
|
2592
|
-
fields["OR"] = z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)).array().optional();
|
|
2593
|
-
fields["NOT"] = this.orArray(z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
|
|
2594
|
-
const baseWhere = z.strictObject(fields);
|
|
2634
|
+
fields["$expr"] = z$1.custom((v) => typeof v === "function", { error: "\"$expr\" must be a function" }).optional();
|
|
2635
|
+
fields["AND"] = this.orArray(z$1.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
|
|
2636
|
+
fields["OR"] = z$1.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)).array().optional();
|
|
2637
|
+
fields["NOT"] = this.orArray(z$1.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
|
|
2638
|
+
const baseWhere = z$1.strictObject(fields);
|
|
2595
2639
|
let result = baseWhere;
|
|
2596
2640
|
if (unique) {
|
|
2597
2641
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
@@ -2617,26 +2661,26 @@ var ZodSchemaFactory = class {
|
|
|
2617
2661
|
else if (getEnum(this.schema, fieldDef.type)) fieldSchemas[fieldName] = this.makeEnumFilterSchema(fieldDef.type, !!fieldDef.optional, !!fieldDef.array, false, void 0).optional();
|
|
2618
2662
|
else if (fieldDef.array) fieldSchemas[fieldName] = this.makeArrayFilterSchema(fieldDef.type, void 0).optional();
|
|
2619
2663
|
else fieldSchemas[fieldName] = this.makePrimitiveFilterSchema(fieldDef.type, !!fieldDef.optional, false, void 0).optional();
|
|
2620
|
-
candidates.push(z.strictObject(fieldSchemas));
|
|
2664
|
+
candidates.push(z$1.strictObject(fieldSchemas));
|
|
2621
2665
|
}
|
|
2622
|
-
const recursiveSchema = z.lazy(() => this.makeTypedJsonFilterSchema(type, optional, false, allowedFilterKinds)).optional();
|
|
2623
|
-
if (array) candidates.push(z.strictObject({
|
|
2666
|
+
const recursiveSchema = z$1.lazy(() => this.makeTypedJsonFilterSchema(type, optional, false, allowedFilterKinds)).optional();
|
|
2667
|
+
if (array) candidates.push(z$1.strictObject({
|
|
2624
2668
|
some: recursiveSchema,
|
|
2625
2669
|
every: recursiveSchema,
|
|
2626
2670
|
none: recursiveSchema
|
|
2627
2671
|
}));
|
|
2628
|
-
else candidates.push(z.strictObject({
|
|
2672
|
+
else candidates.push(z$1.strictObject({
|
|
2629
2673
|
is: recursiveSchema,
|
|
2630
2674
|
isNot: recursiveSchema
|
|
2631
2675
|
}));
|
|
2632
2676
|
candidates.push(this.makeJsonFilterSchema(optional, allowedFilterKinds));
|
|
2633
2677
|
if (optional) {
|
|
2634
|
-
candidates.push(z.null());
|
|
2635
|
-
candidates.push(z.instanceof(DbNullClass));
|
|
2636
|
-
candidates.push(z.instanceof(JsonNullClass));
|
|
2637
|
-
candidates.push(z.instanceof(AnyNullClass));
|
|
2678
|
+
candidates.push(z$1.null());
|
|
2679
|
+
candidates.push(z$1.instanceof(DbNullClass));
|
|
2680
|
+
candidates.push(z$1.instanceof(JsonNullClass));
|
|
2681
|
+
candidates.push(z$1.instanceof(AnyNullClass));
|
|
2638
2682
|
}
|
|
2639
|
-
const result = z.union(candidates);
|
|
2683
|
+
const result = z$1.union(candidates);
|
|
2640
2684
|
this.registerSchema(`${type}Filter${this.filterSchemaSuffix({
|
|
2641
2685
|
optional,
|
|
2642
2686
|
array,
|
|
@@ -2645,7 +2689,7 @@ var ZodSchemaFactory = class {
|
|
|
2645
2689
|
return result;
|
|
2646
2690
|
}
|
|
2647
2691
|
makeNullableTypedJsonMutationSchema(fieldSchema) {
|
|
2648
|
-
return z.any().superRefine((value, ctx) => {
|
|
2692
|
+
return z$1.any().superRefine((value, ctx) => {
|
|
2649
2693
|
if (value instanceof DbNullClass || value instanceof JsonNullClass || value === null || value === void 0) return;
|
|
2650
2694
|
const parseResult = fieldSchema.safeParse(value);
|
|
2651
2695
|
if (!parseResult.success) parseResult.error.issues.forEach((issue) => ctx.addIssue(issue));
|
|
@@ -2657,11 +2701,11 @@ var ZodSchemaFactory = class {
|
|
|
2657
2701
|
makeEnumFilterSchema(enumName, optional, array, withAggregations, allowedFilterKinds) {
|
|
2658
2702
|
const enumDef = getEnum(this.schema, enumName);
|
|
2659
2703
|
invariant(enumDef, `Enum "${enumName}" not found in schema`);
|
|
2660
|
-
const baseSchema = z.enum(Object.keys(enumDef.values));
|
|
2704
|
+
const baseSchema = z$1.enum(Object.keys(enumDef.values));
|
|
2661
2705
|
let schema;
|
|
2662
2706
|
if (array) schema = this.internalMakeArrayFilterSchema(baseSchema, allowedFilterKinds);
|
|
2663
2707
|
else {
|
|
2664
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z.lazy(() => this.makeEnumFilterSchema(enumName, optional, array, withAggregations, allowedFilterKinds)), [
|
|
2708
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z$1.lazy(() => this.makeEnumFilterSchema(enumName, optional, array, withAggregations, allowedFilterKinds)), [
|
|
2665
2709
|
"equals",
|
|
2666
2710
|
"in",
|
|
2667
2711
|
"notIn",
|
|
@@ -2695,42 +2739,42 @@ var ZodSchemaFactory = class {
|
|
|
2695
2739
|
has: elementSchema.optional(),
|
|
2696
2740
|
hasEvery: elementSchema.array().optional(),
|
|
2697
2741
|
hasSome: elementSchema.array().optional(),
|
|
2698
|
-
isEmpty: z.boolean().optional()
|
|
2742
|
+
isEmpty: z$1.boolean().optional()
|
|
2699
2743
|
};
|
|
2700
2744
|
const filteredOperators = this.trimFilterOperators(operators, allowedFilterKinds);
|
|
2701
|
-
return z.strictObject(filteredOperators);
|
|
2745
|
+
return z$1.strictObject(filteredOperators);
|
|
2702
2746
|
}
|
|
2703
2747
|
makePrimitiveFilterSchema(type, optional, withAggregations, allowedFilterKinds, withFuzzy = false, withFullText = false) {
|
|
2704
|
-
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();
|
|
2748
|
+
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();
|
|
2705
2749
|
}
|
|
2706
2750
|
makeJsonValueSchema() {
|
|
2707
|
-
const schema = z.union([
|
|
2708
|
-
z.string(),
|
|
2709
|
-
z.number(),
|
|
2710
|
-
z.boolean(),
|
|
2711
|
-
z.instanceof(JsonNullClass),
|
|
2712
|
-
z.lazy(() => z.union([this.makeJsonValueSchema(), z.null()]).array()),
|
|
2713
|
-
z.record(z.string(), z.lazy(() => z.union([this.makeJsonValueSchema(), z.null()])))
|
|
2751
|
+
const schema = z$1.union([
|
|
2752
|
+
z$1.string(),
|
|
2753
|
+
z$1.number(),
|
|
2754
|
+
z$1.boolean(),
|
|
2755
|
+
z$1.instanceof(JsonNullClass),
|
|
2756
|
+
z$1.lazy(() => z$1.union([this.makeJsonValueSchema(), z$1.null()]).array()),
|
|
2757
|
+
z$1.record(z$1.string(), z$1.lazy(() => z$1.union([this.makeJsonValueSchema(), z$1.null()])))
|
|
2714
2758
|
]);
|
|
2715
2759
|
this.registerSchema("JsonValue", schema);
|
|
2716
2760
|
return schema;
|
|
2717
2761
|
}
|
|
2718
2762
|
makeJsonFilterSchema(optional, allowedFilterKinds) {
|
|
2719
|
-
if (allowedFilterKinds && !allowedFilterKinds.includes("Json")) return z.never();
|
|
2763
|
+
if (allowedFilterKinds && !allowedFilterKinds.includes("Json")) return z$1.never();
|
|
2720
2764
|
const filterMembers = [
|
|
2721
2765
|
this.makeJsonValueSchema(),
|
|
2722
|
-
z.instanceof(DbNullClass),
|
|
2723
|
-
z.instanceof(AnyNullClass)
|
|
2766
|
+
z$1.instanceof(DbNullClass),
|
|
2767
|
+
z$1.instanceof(AnyNullClass)
|
|
2724
2768
|
];
|
|
2725
|
-
if (optional) filterMembers.push(z.null());
|
|
2726
|
-
const filterValueSchema = z.union(filterMembers);
|
|
2727
|
-
const schema = z.strictObject({
|
|
2728
|
-
path: z.string().optional(),
|
|
2769
|
+
if (optional) filterMembers.push(z$1.null());
|
|
2770
|
+
const filterValueSchema = z$1.union(filterMembers);
|
|
2771
|
+
const schema = z$1.strictObject({
|
|
2772
|
+
path: z$1.string().optional(),
|
|
2729
2773
|
equals: filterValueSchema.optional(),
|
|
2730
2774
|
not: filterValueSchema.optional(),
|
|
2731
|
-
string_contains: z.string().optional(),
|
|
2732
|
-
string_starts_with: z.string().optional(),
|
|
2733
|
-
string_ends_with: z.string().optional(),
|
|
2775
|
+
string_contains: z$1.string().optional(),
|
|
2776
|
+
string_starts_with: z$1.string().optional(),
|
|
2777
|
+
string_ends_with: z$1.string().optional(),
|
|
2734
2778
|
mode: this.makeStringModeSchema().optional(),
|
|
2735
2779
|
array_contains: filterValueSchema.optional(),
|
|
2736
2780
|
array_starts_with: filterValueSchema.optional(),
|
|
@@ -2749,7 +2793,7 @@ var ZodSchemaFactory = class {
|
|
|
2749
2793
|
}
|
|
2750
2794
|
makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
2751
2795
|
const filterValueSchema = this.makeDateTimeValueSchema();
|
|
2752
|
-
const schema = this.makeCommonPrimitiveFilterSchema(filterValueSchema, optional, () => z.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)), withAggregations ? [
|
|
2796
|
+
const schema = this.makeCommonPrimitiveFilterSchema(filterValueSchema, optional, () => z$1.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)), withAggregations ? [
|
|
2753
2797
|
"_count",
|
|
2754
2798
|
"_min",
|
|
2755
2799
|
"_max"
|
|
@@ -2762,12 +2806,12 @@ var ZodSchemaFactory = class {
|
|
|
2762
2806
|
return schema;
|
|
2763
2807
|
}
|
|
2764
2808
|
makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
2765
|
-
const components = this.makeCommonPrimitiveFilterComponents(z.boolean(), optional, () => z.lazy(() => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)), ["equals", "not"], withAggregations ? [
|
|
2809
|
+
const components = this.makeCommonPrimitiveFilterComponents(z$1.boolean(), optional, () => z$1.lazy(() => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)), ["equals", "not"], withAggregations ? [
|
|
2766
2810
|
"_count",
|
|
2767
2811
|
"_min",
|
|
2768
2812
|
"_max"
|
|
2769
2813
|
] : void 0, allowedFilterKinds);
|
|
2770
|
-
const schema = this.createUnionFilterSchema(z.boolean(), optional, components, allowedFilterKinds);
|
|
2814
|
+
const schema = this.createUnionFilterSchema(z$1.boolean(), optional, components, allowedFilterKinds);
|
|
2771
2815
|
this.registerSchema(`BooleanFilter${this.filterSchemaSuffix({
|
|
2772
2816
|
optional,
|
|
2773
2817
|
allowedFilterKinds,
|
|
@@ -2776,8 +2820,8 @@ var ZodSchemaFactory = class {
|
|
|
2776
2820
|
return schema;
|
|
2777
2821
|
}
|
|
2778
2822
|
makeBytesFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
2779
|
-
const baseSchema = z.instanceof(Uint8Array);
|
|
2780
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z.instanceof(Uint8Array), [
|
|
2823
|
+
const baseSchema = z$1.instanceof(Uint8Array);
|
|
2824
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z$1.instanceof(Uint8Array), [
|
|
2781
2825
|
"equals",
|
|
2782
2826
|
"in",
|
|
2783
2827
|
"notIn",
|
|
@@ -2825,7 +2869,7 @@ var ZodSchemaFactory = class {
|
|
|
2825
2869
|
return this.createUnionFilterSchema(baseSchema, optional, components, allowedFilterKinds);
|
|
2826
2870
|
}
|
|
2827
2871
|
makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds) {
|
|
2828
|
-
const schema = this.makeCommonPrimitiveFilterSchema(this.makeScalarSchema(type), optional, () => z.lazy(() => this.makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds)), withAggregations ? [
|
|
2872
|
+
const schema = this.makeCommonPrimitiveFilterSchema(this.makeScalarSchema(type), optional, () => z$1.lazy(() => this.makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds)), withAggregations ? [
|
|
2829
2873
|
"_count",
|
|
2830
2874
|
"_avg",
|
|
2831
2875
|
"_sum",
|
|
@@ -2840,15 +2884,15 @@ var ZodSchemaFactory = class {
|
|
|
2840
2884
|
return schema;
|
|
2841
2885
|
}
|
|
2842
2886
|
makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy = false, withFullText = false) {
|
|
2843
|
-
const baseComponents = this.makeCommonPrimitiveFilterComponents(z.string(), optional, () => z.lazy(() => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy, withFullText)), void 0, withAggregations ? [
|
|
2887
|
+
const baseComponents = this.makeCommonPrimitiveFilterComponents(z$1.string(), optional, () => z$1.lazy(() => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy, withFullText)), void 0, withAggregations ? [
|
|
2844
2888
|
"_count",
|
|
2845
2889
|
"_min",
|
|
2846
2890
|
"_max"
|
|
2847
2891
|
] : void 0, allowedFilterKinds);
|
|
2848
2892
|
const stringSpecificOperators = {
|
|
2849
|
-
startsWith: z.string().optional(),
|
|
2850
|
-
endsWith: z.string().optional(),
|
|
2851
|
-
contains: z.string().optional(),
|
|
2893
|
+
startsWith: z$1.string().optional(),
|
|
2894
|
+
endsWith: z$1.string().optional(),
|
|
2895
|
+
contains: z$1.string().optional(),
|
|
2852
2896
|
...withFuzzy && this.providerSupportsFuzzySearch ? { fuzzy: this.makeFuzzyFilterSchema().optional() } : {},
|
|
2853
2897
|
...withFullText && this.providerSupportsFullTextSearch ? { fts: this.makeFullTextFilterSchema().optional() } : {},
|
|
2854
2898
|
...this.providerSupportsCaseSensitivity ? { mode: this.makeStringModeSchema().optional() } : {}
|
|
@@ -2858,7 +2902,7 @@ var ZodSchemaFactory = class {
|
|
|
2858
2902
|
...baseComponents,
|
|
2859
2903
|
...filteredStringOperators
|
|
2860
2904
|
};
|
|
2861
|
-
const schema = this.createUnionFilterSchema(z.string(), optional, allComponents, allowedFilterKinds);
|
|
2905
|
+
const schema = this.createUnionFilterSchema(z$1.string(), optional, allComponents, allowedFilterKinds);
|
|
2862
2906
|
const featureSuffix = `${withFuzzy ? "Fuzzy" : ""}${withFullText ? "FullText" : ""}`;
|
|
2863
2907
|
this.registerSchema(`StringFilter${this.filterSchemaSuffix({
|
|
2864
2908
|
optional,
|
|
@@ -2868,39 +2912,45 @@ var ZodSchemaFactory = class {
|
|
|
2868
2912
|
return schema;
|
|
2869
2913
|
}
|
|
2870
2914
|
makeStringModeSchema() {
|
|
2871
|
-
return z.union([z.literal("default"), z.literal("insensitive")]);
|
|
2915
|
+
return z$1.union([z$1.literal("default"), z$1.literal("insensitive")]);
|
|
2872
2916
|
}
|
|
2873
2917
|
makeFuzzyFilterSchema() {
|
|
2874
|
-
return z.strictObject({
|
|
2875
|
-
search: z.string().min(1),
|
|
2876
|
-
mode: z.union([
|
|
2877
|
-
z.literal("simple"),
|
|
2878
|
-
z.literal("word"),
|
|
2879
|
-
z.literal("strictWord")
|
|
2918
|
+
return z$1.strictObject({
|
|
2919
|
+
search: z$1.string().min(1),
|
|
2920
|
+
mode: z$1.union([
|
|
2921
|
+
z$1.literal("simple"),
|
|
2922
|
+
z$1.literal("word"),
|
|
2923
|
+
z$1.literal("strictWord")
|
|
2880
2924
|
]).default("simple"),
|
|
2881
|
-
threshold: z.number().min(0).max(1).optional(),
|
|
2882
|
-
unaccent: z.boolean().default(false)
|
|
2925
|
+
threshold: z$1.number().min(0).max(1).optional(),
|
|
2926
|
+
unaccent: z$1.boolean().default(false)
|
|
2883
2927
|
});
|
|
2884
2928
|
}
|
|
2885
2929
|
makeFullTextFilterSchema() {
|
|
2886
|
-
return z.strictObject({
|
|
2887
|
-
search: z.string().min(1),
|
|
2888
|
-
config: z.string().min(1).optional()
|
|
2930
|
+
return z$1.strictObject({
|
|
2931
|
+
search: z$1.string().min(1),
|
|
2932
|
+
config: z$1.string().min(1).optional()
|
|
2889
2933
|
});
|
|
2890
2934
|
}
|
|
2891
2935
|
makeSelectSchema(model, options) {
|
|
2892
2936
|
const fields = {};
|
|
2893
|
-
for (const [field, fieldDef] of this.getModelFields(model))
|
|
2894
|
-
if (
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2937
|
+
for (const [field, fieldDef] of this.getModelFields(model)) {
|
|
2938
|
+
if (this.isParameterizedComputedField(fieldDef)) {
|
|
2939
|
+
fields[field] = z$1.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional();
|
|
2940
|
+
continue;
|
|
2941
|
+
}
|
|
2942
|
+
if (fieldDef.relation) {
|
|
2943
|
+
if (!this.shouldIncludeRelations(options)) continue;
|
|
2944
|
+
if (this.isModelAllowed(fieldDef.type)) fields[field] = this.makeRelationSelectIncludeSchema(model, field, options).optional();
|
|
2945
|
+
} else if (this.options.allowQueryTimeOmitOverride === false && this.isFieldOmittedByConfig(model, field)) fields[field] = z$1.literal(false).optional();
|
|
2946
|
+
else fields[field] = z$1.boolean().optional();
|
|
2947
|
+
}
|
|
2898
2948
|
if (this.shouldIncludeRelations(options)) {
|
|
2899
2949
|
const _countSchema = this.makeCountSelectionSchema(model, options);
|
|
2900
|
-
if (!(_countSchema instanceof z.ZodNever)) fields["_count"] = _countSchema;
|
|
2950
|
+
if (!(_countSchema instanceof z$1.ZodNever)) fields["_count"] = _countSchema;
|
|
2901
2951
|
}
|
|
2902
2952
|
this.addExtResultFields(model, fields);
|
|
2903
|
-
const result = z.strictObject(fields);
|
|
2953
|
+
const result = z$1.strictObject(fields);
|
|
2904
2954
|
this.registerSchema(`${model}Select`, result);
|
|
2905
2955
|
return result;
|
|
2906
2956
|
}
|
|
@@ -2909,24 +2959,24 @@ var ZodSchemaFactory = class {
|
|
|
2909
2959
|
const toManyRelations = Object.values(modelDef.fields).filter((def) => def.relation && def.array);
|
|
2910
2960
|
if (toManyRelations.length > 0) {
|
|
2911
2961
|
const nextOpts = this.nextOptions(options);
|
|
2912
|
-
const schema = z.union([z.literal(true), z.strictObject({ select: z.strictObject(toManyRelations.reduce((acc, fieldDef) => ({
|
|
2962
|
+
const schema = z$1.union([z$1.literal(true), z$1.strictObject({ select: z$1.strictObject(toManyRelations.reduce((acc, fieldDef) => ({
|
|
2913
2963
|
...acc,
|
|
2914
|
-
[fieldDef.name]: z.union([z.boolean(), z.strictObject({ where: this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts) })]).optional()
|
|
2964
|
+
[fieldDef.name]: z$1.union([z$1.boolean(), z$1.strictObject({ where: this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts) })]).optional()
|
|
2915
2965
|
}), {})) })]).optional();
|
|
2916
2966
|
this.registerSchema(`${model}CountSelection`, schema);
|
|
2917
2967
|
return schema;
|
|
2918
|
-
} else return z.never();
|
|
2968
|
+
} else return z$1.never();
|
|
2919
2969
|
}
|
|
2920
2970
|
makeRelationSelectIncludeSchema(model, field, options) {
|
|
2921
2971
|
const fieldDef = requireField(this.schema, model, field);
|
|
2922
2972
|
const nextOpts = this.nextOptions(options);
|
|
2923
|
-
let objSchema = z.strictObject({
|
|
2924
|
-
...fieldDef.array || fieldDef.optional ? { where: z.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts)).optional() } : {},
|
|
2925
|
-
select: z.lazy(() => this.makeSelectSchema(fieldDef.type, nextOpts)).optional().nullable(),
|
|
2926
|
-
include: z.lazy(() => this.makeIncludeSchema(fieldDef.type, nextOpts)).optional().nullable(),
|
|
2927
|
-
omit: z.lazy(() => this.makeOmitSchema(fieldDef.type)).optional().nullable(),
|
|
2973
|
+
let objSchema = z$1.strictObject({
|
|
2974
|
+
...fieldDef.array || fieldDef.optional ? { where: z$1.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts)).optional() } : {},
|
|
2975
|
+
select: z$1.lazy(() => this.makeSelectSchema(fieldDef.type, nextOpts)).optional().nullable(),
|
|
2976
|
+
include: z$1.lazy(() => this.makeIncludeSchema(fieldDef.type, nextOpts)).optional().nullable(),
|
|
2977
|
+
omit: z$1.lazy(() => this.makeOmitSchema(fieldDef.type)).optional().nullable(),
|
|
2928
2978
|
...fieldDef.array ? {
|
|
2929
|
-
orderBy: z.lazy(() => this.orArray(this.makeOrderBySchema(fieldDef.type, true, false, nextOpts), true)).optional(),
|
|
2979
|
+
orderBy: z$1.lazy(() => this.orArray(this.makeOrderBySchema(fieldDef.type, true, false, nextOpts), true)).optional(),
|
|
2930
2980
|
skip: this.makeSkipSchema().optional(),
|
|
2931
2981
|
take: this.makeTakeSchema().optional(),
|
|
2932
2982
|
cursor: this.makeCursorSchema(fieldDef.type, nextOpts).optional(),
|
|
@@ -2936,7 +2986,7 @@ var ZodSchemaFactory = class {
|
|
|
2936
2986
|
objSchema = this.refineForSelectIncludeMutuallyExclusive(objSchema);
|
|
2937
2987
|
objSchema = this.refineForSelectOmitMutuallyExclusive(objSchema);
|
|
2938
2988
|
objSchema = this.refineForSelectHasTruthyField(objSchema);
|
|
2939
|
-
const result = z.union([z.boolean(), objSchema]);
|
|
2989
|
+
const result = z$1.union([z$1.boolean(), objSchema]);
|
|
2940
2990
|
this.registerSchema(`${model}${upperCaseFirst(field)}RelationInput`, result);
|
|
2941
2991
|
return result;
|
|
2942
2992
|
}
|
|
@@ -2951,10 +3001,13 @@ var ZodSchemaFactory = class {
|
|
|
2951
3001
|
}
|
|
2952
3002
|
makeOmitSchema(model) {
|
|
2953
3003
|
const fields = {};
|
|
2954
|
-
for (const [field, fieldDef] of this.getModelFields(model))
|
|
2955
|
-
|
|
3004
|
+
for (const [field, fieldDef] of this.getModelFields(model)) {
|
|
3005
|
+
if (this.isParameterizedComputedField(fieldDef)) continue;
|
|
3006
|
+
if (!fieldDef.relation) if (this.options.allowQueryTimeOmitOverride !== false) fields[field] = z$1.boolean().optional();
|
|
3007
|
+
else fields[field] = z$1.literal(true).optional();
|
|
3008
|
+
}
|
|
2956
3009
|
this.addExtResultFields(model, fields);
|
|
2957
|
-
const result = z.strictObject(fields);
|
|
3010
|
+
const result = z$1.strictObject(fields);
|
|
2958
3011
|
this.registerSchema(`${model}OmitInput`, result);
|
|
2959
3012
|
return result;
|
|
2960
3013
|
}
|
|
@@ -2963,7 +3016,7 @@ var ZodSchemaFactory = class {
|
|
|
2963
3016
|
const resultConfig = plugin.result;
|
|
2964
3017
|
if (resultConfig) {
|
|
2965
3018
|
const modelConfig = resultConfig[lowerCaseFirst(model)];
|
|
2966
|
-
if (modelConfig) for (const field of Object.keys(modelConfig)) fields[field] = z.boolean().optional();
|
|
3019
|
+
if (modelConfig) for (const field of Object.keys(modelConfig)) fields[field] = z$1.boolean().optional();
|
|
2967
3020
|
}
|
|
2968
3021
|
}
|
|
2969
3022
|
}
|
|
@@ -2975,30 +3028,35 @@ var ZodSchemaFactory = class {
|
|
|
2975
3028
|
if (fieldDef.relation) {
|
|
2976
3029
|
if (!this.shouldIncludeRelations(options)) continue;
|
|
2977
3030
|
if (this.isModelAllowed(fieldDef.type)) fields[field] = this.makeRelationSelectIncludeSchema(model, field, options).optional();
|
|
2978
|
-
}
|
|
3031
|
+
} else if (this.isParameterizedComputedField(fieldDef)) fields[field] = z$1.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional();
|
|
2979
3032
|
}
|
|
2980
3033
|
if (this.shouldIncludeRelations(options)) {
|
|
2981
3034
|
const _countSchema = this.makeCountSelectionSchema(model, options);
|
|
2982
|
-
if (!(_countSchema instanceof z.ZodNever)) fields["_count"] = _countSchema;
|
|
3035
|
+
if (!(_countSchema instanceof z$1.ZodNever)) fields["_count"] = _countSchema;
|
|
2983
3036
|
}
|
|
2984
|
-
const result = z.strictObject(fields);
|
|
3037
|
+
const result = z$1.strictObject(fields);
|
|
2985
3038
|
this.registerSchema(`${model}Include`, result);
|
|
2986
3039
|
return result;
|
|
2987
3040
|
}
|
|
2988
3041
|
makeOrderBySchema(model, withRelation, WithAggregation, options) {
|
|
2989
3042
|
const fields = {};
|
|
2990
|
-
const sort = z.union([z.literal("asc"), z.literal("desc")]);
|
|
3043
|
+
const sort = z$1.union([z$1.literal("asc"), z$1.literal("desc")]);
|
|
2991
3044
|
const refineAtMostOneKey = (s) => s.refine((v) => Object.keys(v).length <= 1, { message: "Each orderBy element must have at most one key" });
|
|
2992
3045
|
const nextOpts = this.nextOptions(options);
|
|
2993
3046
|
for (const [field, fieldDef] of this.getModelFields(model)) if (fieldDef.relation) {
|
|
2994
|
-
if (withRelation && this.shouldIncludeRelations(options)) fields[field] = z.lazy(() => {
|
|
3047
|
+
if (withRelation && this.shouldIncludeRelations(options)) fields[field] = z$1.lazy(() => {
|
|
2995
3048
|
let relationOrderBy = this.makeOrderBySchema(fieldDef.type, withRelation, WithAggregation, nextOpts);
|
|
2996
3049
|
if (fieldDef.array) relationOrderBy = refineAtMostOneKey(relationOrderBy.safeExtend({ _count: sort }));
|
|
2997
3050
|
return relationOrderBy;
|
|
2998
3051
|
}).optional();
|
|
2999
|
-
} else if (fieldDef.
|
|
3052
|
+
} else if (fieldDef.computed && fieldDef.params) fields[field] = z$1.strictObject({
|
|
3053
|
+
args: this.makeFieldArgsSchema(fieldDef.params),
|
|
3054
|
+
sort,
|
|
3055
|
+
nulls: z$1.union([z$1.literal("first"), z$1.literal("last")]).optional()
|
|
3056
|
+
}).optional();
|
|
3057
|
+
else if (fieldDef.optional) fields[field] = z$1.union([sort, z$1.strictObject({
|
|
3000
3058
|
sort,
|
|
3001
|
-
nulls: z.union([z.literal("first"), z.literal("last")]).optional()
|
|
3059
|
+
nulls: z$1.union([z$1.literal("first"), z$1.literal("last")]).optional()
|
|
3002
3060
|
})]).optional();
|
|
3003
3061
|
else fields[field] = sort.optional();
|
|
3004
3062
|
if (WithAggregation) for (const agg of [
|
|
@@ -3007,31 +3065,31 @@ var ZodSchemaFactory = class {
|
|
|
3007
3065
|
"_sum",
|
|
3008
3066
|
"_min",
|
|
3009
3067
|
"_max"
|
|
3010
|
-
]) fields[agg] = z.lazy(() => this.makeOrderBySchema(model, true, false, options).optional());
|
|
3068
|
+
]) fields[agg] = z$1.lazy(() => this.makeOrderBySchema(model, true, false, options).optional());
|
|
3011
3069
|
if (this.providerSupportsFuzzySearch) {
|
|
3012
3070
|
const fuzzyFieldNames = this.getModelFields(model).filter(([, def]) => !def.relation && def.type === "String" && def.fuzzy === true).map(([name]) => name);
|
|
3013
|
-
if (fuzzyFieldNames.length > 0) fields["_fuzzyRelevance"] = z.strictObject({
|
|
3014
|
-
fields: z.array(z.enum(fuzzyFieldNames)).min(1),
|
|
3015
|
-
search: z.string(),
|
|
3016
|
-
mode: z.union([
|
|
3017
|
-
z.literal("simple"),
|
|
3018
|
-
z.literal("word"),
|
|
3019
|
-
z.literal("strictWord")
|
|
3071
|
+
if (fuzzyFieldNames.length > 0) fields["_fuzzyRelevance"] = z$1.strictObject({
|
|
3072
|
+
fields: z$1.array(z$1.enum(fuzzyFieldNames)).min(1),
|
|
3073
|
+
search: z$1.string(),
|
|
3074
|
+
mode: z$1.union([
|
|
3075
|
+
z$1.literal("simple"),
|
|
3076
|
+
z$1.literal("word"),
|
|
3077
|
+
z$1.literal("strictWord")
|
|
3020
3078
|
]).default("simple"),
|
|
3021
|
-
unaccent: z.boolean().default(false),
|
|
3079
|
+
unaccent: z$1.boolean().default(false),
|
|
3022
3080
|
sort
|
|
3023
3081
|
}).optional();
|
|
3024
3082
|
}
|
|
3025
3083
|
if (this.providerSupportsFullTextSearch) {
|
|
3026
3084
|
const fullTextFieldNames = this.getModelFields(model).filter(([, def]) => !def.relation && def.type === "String" && def.fullText === true).map(([name]) => name);
|
|
3027
|
-
if (fullTextFieldNames.length > 0) fields["_ftsRelevance"] = z.strictObject({
|
|
3028
|
-
fields: z.array(z.enum(fullTextFieldNames)).min(1),
|
|
3029
|
-
search: z.string().min(1),
|
|
3030
|
-
config: z.string().min(1).optional(),
|
|
3085
|
+
if (fullTextFieldNames.length > 0) fields["_ftsRelevance"] = z$1.strictObject({
|
|
3086
|
+
fields: z$1.array(z$1.enum(fullTextFieldNames)).min(1),
|
|
3087
|
+
search: z$1.string().min(1),
|
|
3088
|
+
config: z$1.string().min(1).optional(),
|
|
3031
3089
|
sort
|
|
3032
3090
|
}).optional();
|
|
3033
3091
|
}
|
|
3034
|
-
const schema = refineAtMostOneKey(z.strictObject(fields));
|
|
3092
|
+
const schema = refineAtMostOneKey(z$1.strictObject(fields));
|
|
3035
3093
|
let schemaId = `${model}OrderBy`;
|
|
3036
3094
|
if (withRelation) schemaId += "WithRelation";
|
|
3037
3095
|
if (WithAggregation) schemaId += "WithAggregation";
|
|
@@ -3040,8 +3098,8 @@ var ZodSchemaFactory = class {
|
|
|
3040
3098
|
return schema;
|
|
3041
3099
|
}
|
|
3042
3100
|
makeDistinctSchema(model) {
|
|
3043
|
-
const nonRelationFields = this.getModelFields(model).filter(([, def]) => !def.relation).map(([name]) => name);
|
|
3044
|
-
const schema = nonRelationFields.length > 0 ? this.orArray(z.enum(nonRelationFields), true) : z.never();
|
|
3101
|
+
const nonRelationFields = this.getModelFields(model).filter(([, def]) => !def.relation && !this.isParameterizedComputedField(def)).map(([name]) => name);
|
|
3102
|
+
const schema = nonRelationFields.length > 0 ? this.orArray(z$1.enum(nonRelationFields), true) : z$1.never();
|
|
3045
3103
|
this.registerSchema(`${model}DistinctInput`, schema);
|
|
3046
3104
|
return schema;
|
|
3047
3105
|
}
|
|
@@ -3052,7 +3110,7 @@ var ZodSchemaFactory = class {
|
|
|
3052
3110
|
}
|
|
3053
3111
|
makeCreateSchema(model, options) {
|
|
3054
3112
|
const dataSchema = this.makeCreateDataSchema(model, false, [], false, options);
|
|
3055
|
-
const baseSchema = z.strictObject({
|
|
3113
|
+
const baseSchema = z$1.strictObject({
|
|
3056
3114
|
data: dataSchema,
|
|
3057
3115
|
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
3058
3116
|
include: this.makeIncludeSchema(model, options).optional().nullable(),
|
|
@@ -3101,7 +3159,7 @@ var ZodSchemaFactory = class {
|
|
|
3101
3159
|
const oppositeFieldDef = requireField(this.schema, fieldDef.type, oppositeField);
|
|
3102
3160
|
if (oppositeFieldDef.relation?.fields) excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
3103
3161
|
}
|
|
3104
|
-
let fieldSchema = z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "create", nextOpts));
|
|
3162
|
+
let fieldSchema = z$1.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "create", nextOpts));
|
|
3105
3163
|
if (fieldDef.optional || fieldDef.array) fieldSchema = fieldSchema.optional();
|
|
3106
3164
|
else {
|
|
3107
3165
|
let allFksOptional = false;
|
|
@@ -3118,23 +3176,23 @@ var ZodSchemaFactory = class {
|
|
|
3118
3176
|
let fieldSchema = this.makeScalarSchema(fieldDef.type, fieldDef.attributes);
|
|
3119
3177
|
if (fieldDef.array) {
|
|
3120
3178
|
fieldSchema = ZodUtils.addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
3121
|
-
fieldSchema = z.union([fieldSchema, z.strictObject({ set: fieldSchema })]).optional();
|
|
3179
|
+
fieldSchema = z$1.union([fieldSchema, z$1.strictObject({ set: fieldSchema })]).optional();
|
|
3122
3180
|
}
|
|
3123
3181
|
if (fieldDef.optional || fieldHasDefaultValue(fieldDef)) fieldSchema = fieldSchema.optional();
|
|
3124
|
-
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z.union([fieldSchema, z.instanceof(DbNullClass)]);
|
|
3182
|
+
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z$1.union([fieldSchema, z$1.instanceof(DbNullClass)]);
|
|
3125
3183
|
else if (this.isTypeDefType(fieldDef.type)) fieldSchema = this.makeNullableTypedJsonMutationSchema(fieldSchema);
|
|
3126
3184
|
else fieldSchema = fieldSchema.nullable();
|
|
3127
3185
|
uncheckedVariantFields[field] = fieldSchema;
|
|
3128
3186
|
if (!fieldDef.foreignKeyFor) checkedVariantFields[field] = fieldSchema;
|
|
3129
3187
|
}
|
|
3130
3188
|
});
|
|
3131
|
-
const uncheckedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(uncheckedVariantFields), modelDef.attributes) : z.strictObject(uncheckedVariantFields);
|
|
3132
|
-
const checkedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(checkedVariantFields), modelDef.attributes) : z.strictObject(checkedVariantFields);
|
|
3133
|
-
const result = !hasRelation ? this.orArray(uncheckedCreateSchema, canBeArray) : z.union([
|
|
3189
|
+
const uncheckedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z$1.strictObject(uncheckedVariantFields), modelDef.attributes) : z$1.strictObject(uncheckedVariantFields);
|
|
3190
|
+
const checkedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z$1.strictObject(checkedVariantFields), modelDef.attributes) : z$1.strictObject(checkedVariantFields);
|
|
3191
|
+
const result = !hasRelation ? this.orArray(uncheckedCreateSchema, canBeArray) : z$1.union([
|
|
3134
3192
|
uncheckedCreateSchema,
|
|
3135
3193
|
checkedCreateSchema,
|
|
3136
|
-
...canBeArray ? [z.array(uncheckedCreateSchema)] : [],
|
|
3137
|
-
...canBeArray ? [z.array(checkedCreateSchema)] : []
|
|
3194
|
+
...canBeArray ? [z$1.array(uncheckedCreateSchema)] : [],
|
|
3195
|
+
...canBeArray ? [z$1.array(checkedCreateSchema)] : []
|
|
3138
3196
|
]);
|
|
3139
3197
|
const idParts = [`${model}CreateData`];
|
|
3140
3198
|
if (canBeArray) idParts.push("Array");
|
|
@@ -3159,17 +3217,17 @@ var ZodSchemaFactory = class {
|
|
|
3159
3217
|
fields["disconnect"] = this.makeDisconnectDataSchema(fieldType, array, options).optional();
|
|
3160
3218
|
fields["delete"] = this.makeDeleteRelationDataSchema(fieldType, array, true, options).optional();
|
|
3161
3219
|
}
|
|
3162
|
-
fields["update"] = array ? this.orArray(z.strictObject({
|
|
3220
|
+
fields["update"] = array ? this.orArray(z$1.strictObject({
|
|
3163
3221
|
where: this.makeWhereSchema(fieldType, true, false, false, options),
|
|
3164
3222
|
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
3165
|
-
}), true).optional() : z.union([z.strictObject({
|
|
3223
|
+
}), true).optional() : z$1.union([z$1.strictObject({
|
|
3166
3224
|
where: this.makeWhereSchema(fieldType, false, false, false, options).optional(),
|
|
3167
3225
|
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
3168
3226
|
}), this.makeUpdateDataSchema(fieldType, withoutFields, false, options)]).optional();
|
|
3169
3227
|
if (canCreateModel) {
|
|
3170
3228
|
let upsertWhere = this.makeWhereSchema(fieldType, true, false, false, options);
|
|
3171
3229
|
if (!fieldDef.array) upsertWhere = upsertWhere.optional();
|
|
3172
|
-
fields["upsert"] = this.orArray(z.strictObject({
|
|
3230
|
+
fields["upsert"] = this.orArray(z$1.strictObject({
|
|
3173
3231
|
where: upsertWhere,
|
|
3174
3232
|
create: this.makeCreateDataSchema(fieldType, false, withoutFields, false, options),
|
|
3175
3233
|
update: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
@@ -3177,14 +3235,14 @@ var ZodSchemaFactory = class {
|
|
|
3177
3235
|
}
|
|
3178
3236
|
if (array) {
|
|
3179
3237
|
fields["set"] = this.makeSetDataSchema(fieldType, true, options).optional();
|
|
3180
|
-
fields["updateMany"] = this.orArray(z.strictObject({
|
|
3238
|
+
fields["updateMany"] = this.orArray(z$1.strictObject({
|
|
3181
3239
|
where: this.makeWhereSchema(fieldType, false, true, false, options),
|
|
3182
3240
|
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
3183
3241
|
}), true).optional();
|
|
3184
3242
|
fields["deleteMany"] = this.makeDeleteRelationDataSchema(fieldType, true, false, options).optional();
|
|
3185
3243
|
}
|
|
3186
3244
|
}
|
|
3187
|
-
return z.strictObject(fields);
|
|
3245
|
+
return z$1.strictObject(fields);
|
|
3188
3246
|
}
|
|
3189
3247
|
makeSetDataSchema(model, canBeArray, options) {
|
|
3190
3248
|
return this.orArray(this.makeWhereSchema(model, true, false, false, options), canBeArray);
|
|
@@ -3194,23 +3252,23 @@ var ZodSchemaFactory = class {
|
|
|
3194
3252
|
}
|
|
3195
3253
|
makeDisconnectDataSchema(model, canBeArray, options) {
|
|
3196
3254
|
if (canBeArray) return this.orArray(this.makeWhereSchema(model, true, false, false, options), canBeArray);
|
|
3197
|
-
else return z.union([z.boolean(), this.makeWhereSchema(model, false, false, false, options)]);
|
|
3255
|
+
else return z$1.union([z$1.boolean(), this.makeWhereSchema(model, false, false, false, options)]);
|
|
3198
3256
|
}
|
|
3199
3257
|
makeDeleteRelationDataSchema(model, toManyRelation, uniqueFilter, options) {
|
|
3200
|
-
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter, false, false, options), true) : z.union([z.boolean(), this.makeWhereSchema(model, uniqueFilter, false, false, options)]);
|
|
3258
|
+
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)]);
|
|
3201
3259
|
}
|
|
3202
3260
|
makeConnectOrCreateDataSchema(model, canBeArray, withoutFields, options) {
|
|
3203
3261
|
const whereSchema = this.makeWhereSchema(model, true, false, false, options);
|
|
3204
3262
|
const createSchema = this.makeCreateDataSchema(model, false, withoutFields, false, options);
|
|
3205
|
-
return this.orArray(z.strictObject({
|
|
3263
|
+
return this.orArray(z$1.strictObject({
|
|
3206
3264
|
where: whereSchema,
|
|
3207
3265
|
create: createSchema
|
|
3208
3266
|
}), canBeArray);
|
|
3209
3267
|
}
|
|
3210
3268
|
makeCreateManyPayloadSchema(model, withoutFields, options) {
|
|
3211
|
-
const schema = z.strictObject({
|
|
3269
|
+
const schema = z$1.strictObject({
|
|
3212
3270
|
data: this.makeCreateDataSchema(model, true, withoutFields, true, options),
|
|
3213
|
-
skipDuplicates: z.boolean().optional()
|
|
3271
|
+
skipDuplicates: z$1.boolean().optional()
|
|
3214
3272
|
});
|
|
3215
3273
|
const idParts = [`${model}CreateManyPayload`];
|
|
3216
3274
|
if (withoutFields.length) idParts.push(`Without${withoutFields.slice().sort().join("")}`);
|
|
@@ -3218,7 +3276,7 @@ var ZodSchemaFactory = class {
|
|
|
3218
3276
|
return schema;
|
|
3219
3277
|
}
|
|
3220
3278
|
makeUpdateSchema(model, options) {
|
|
3221
|
-
const baseSchema = z.strictObject({
|
|
3279
|
+
const baseSchema = z$1.strictObject({
|
|
3222
3280
|
where: this.makeWhereSchema(model, true, false, false, options),
|
|
3223
3281
|
data: this.makeUpdateDataSchema(model, [], false, options),
|
|
3224
3282
|
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
@@ -3233,10 +3291,10 @@ var ZodSchemaFactory = class {
|
|
|
3233
3291
|
return schema;
|
|
3234
3292
|
}
|
|
3235
3293
|
makeUpdateManySchema(model, options) {
|
|
3236
|
-
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3294
|
+
const result = this.mergePluginArgsSchema(z$1.strictObject({
|
|
3237
3295
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3238
3296
|
data: this.makeUpdateDataSchema(model, [], true, options),
|
|
3239
|
-
limit: z.number().int().nonnegative().optional()
|
|
3297
|
+
limit: z$1.number().int().nonnegative().optional()
|
|
3240
3298
|
}), "updateMany");
|
|
3241
3299
|
this.registerSchema(`${model}UpdateManyArgs`, result);
|
|
3242
3300
|
return result;
|
|
@@ -3252,7 +3310,7 @@ var ZodSchemaFactory = class {
|
|
|
3252
3310
|
return schema;
|
|
3253
3311
|
}
|
|
3254
3312
|
makeUpsertSchema(model, options) {
|
|
3255
|
-
const baseSchema = z.strictObject({
|
|
3313
|
+
const baseSchema = z$1.strictObject({
|
|
3256
3314
|
where: this.makeWhereSchema(model, true, false, false, options),
|
|
3257
3315
|
create: this.makeCreateDataSchema(model, false, [], false, options),
|
|
3258
3316
|
update: this.makeUpdateDataSchema(model, [], false, options),
|
|
@@ -3288,27 +3346,27 @@ var ZodSchemaFactory = class {
|
|
|
3288
3346
|
const oppositeFieldDef = requireField(this.schema, fieldDef.type, oppositeField);
|
|
3289
3347
|
if (oppositeFieldDef.relation?.fields) excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
3290
3348
|
}
|
|
3291
|
-
let fieldSchema = z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "update", nextOpts)).optional();
|
|
3349
|
+
let fieldSchema = z$1.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "update", nextOpts)).optional();
|
|
3292
3350
|
if (fieldDef.optional && !fieldDef.array) fieldSchema = fieldSchema.nullable();
|
|
3293
3351
|
checkedVariantFields[field] = fieldSchema;
|
|
3294
3352
|
if (fieldDef.array || !fieldDef.relation.references) uncheckedVariantFields[field] = fieldSchema;
|
|
3295
3353
|
} else {
|
|
3296
3354
|
let fieldSchema = this.makeScalarSchema(fieldDef.type, fieldDef.attributes);
|
|
3297
|
-
if (this.isNumericField(fieldDef)) fieldSchema = z.union([fieldSchema, z.object({
|
|
3298
|
-
set: this.nullableIf(z.number().optional(), !!fieldDef.optional).optional(),
|
|
3299
|
-
increment: z.number().optional(),
|
|
3300
|
-
decrement: z.number().optional(),
|
|
3301
|
-
multiply: z.number().optional(),
|
|
3302
|
-
divide: z.number().optional()
|
|
3355
|
+
if (this.isNumericField(fieldDef)) fieldSchema = z$1.union([fieldSchema, z$1.object({
|
|
3356
|
+
set: this.nullableIf(z$1.number().optional(), !!fieldDef.optional).optional(),
|
|
3357
|
+
increment: z$1.number().optional(),
|
|
3358
|
+
decrement: z$1.number().optional(),
|
|
3359
|
+
multiply: z$1.number().optional(),
|
|
3360
|
+
divide: z$1.number().optional()
|
|
3303
3361
|
}).refine((v) => Object.keys(v).length === 1, "Only one of \"set\", \"increment\", \"decrement\", \"multiply\", or \"divide\" can be provided")]);
|
|
3304
3362
|
if (fieldDef.array) {
|
|
3305
3363
|
const arraySchema = ZodUtils.addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
3306
|
-
fieldSchema = z.union([arraySchema, z.object({
|
|
3364
|
+
fieldSchema = z$1.union([arraySchema, z$1.object({
|
|
3307
3365
|
set: arraySchema.optional(),
|
|
3308
|
-
push: z.union([fieldSchema, fieldSchema.array()]).optional()
|
|
3366
|
+
push: z$1.union([fieldSchema, fieldSchema.array()]).optional()
|
|
3309
3367
|
}).refine((v) => Object.keys(v).length === 1, "Only one of \"set\", \"push\" can be provided")]);
|
|
3310
3368
|
}
|
|
3311
|
-
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z.union([fieldSchema, z.instanceof(DbNullClass)]);
|
|
3369
|
+
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z$1.union([fieldSchema, z$1.instanceof(DbNullClass)]);
|
|
3312
3370
|
else if (this.isTypeDefType(fieldDef.type)) fieldSchema = this.makeNullableTypedJsonMutationSchema(fieldSchema);
|
|
3313
3371
|
else fieldSchema = fieldSchema.nullable();
|
|
3314
3372
|
fieldSchema = fieldSchema.optional();
|
|
@@ -3316,9 +3374,9 @@ var ZodSchemaFactory = class {
|
|
|
3316
3374
|
if (!fieldDef.foreignKeyFor) checkedVariantFields[field] = fieldSchema;
|
|
3317
3375
|
}
|
|
3318
3376
|
});
|
|
3319
|
-
const uncheckedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(uncheckedVariantFields), modelDef.attributes) : z.strictObject(uncheckedVariantFields);
|
|
3320
|
-
const checkedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(checkedVariantFields), modelDef.attributes) : z.strictObject(checkedVariantFields);
|
|
3321
|
-
const result = !hasRelation ? uncheckedUpdateSchema : z.union([uncheckedUpdateSchema, checkedUpdateSchema]);
|
|
3377
|
+
const uncheckedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z$1.strictObject(uncheckedVariantFields), modelDef.attributes) : z$1.strictObject(uncheckedVariantFields);
|
|
3378
|
+
const checkedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z$1.strictObject(checkedVariantFields), modelDef.attributes) : z$1.strictObject(checkedVariantFields);
|
|
3379
|
+
const result = !hasRelation ? uncheckedUpdateSchema : z$1.union([uncheckedUpdateSchema, checkedUpdateSchema]);
|
|
3322
3380
|
const idParts = [`${model}UpdateData`];
|
|
3323
3381
|
if (withoutRelationFields) idParts.push("WithoutRelation");
|
|
3324
3382
|
if (withoutFields.length) idParts.push(`Without${withoutFields.slice().sort().join("")}`);
|
|
@@ -3326,7 +3384,7 @@ var ZodSchemaFactory = class {
|
|
|
3326
3384
|
return result;
|
|
3327
3385
|
}
|
|
3328
3386
|
makeDeleteSchema(model, options) {
|
|
3329
|
-
const baseSchema = z.strictObject({
|
|
3387
|
+
const baseSchema = z$1.strictObject({
|
|
3330
3388
|
where: this.makeWhereSchema(model, true, false, false, options),
|
|
3331
3389
|
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
3332
3390
|
include: this.makeIncludeSchema(model, options).optional().nullable(),
|
|
@@ -3340,15 +3398,15 @@ var ZodSchemaFactory = class {
|
|
|
3340
3398
|
return schema;
|
|
3341
3399
|
}
|
|
3342
3400
|
makeDeleteManySchema(model, options) {
|
|
3343
|
-
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3401
|
+
const result = this.mergePluginArgsSchema(z$1.strictObject({
|
|
3344
3402
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3345
|
-
limit: z.number().int().nonnegative().optional()
|
|
3403
|
+
limit: z$1.number().int().nonnegative().optional()
|
|
3346
3404
|
}), "deleteMany").optional();
|
|
3347
3405
|
this.registerSchema(`${model}DeleteManyArgs`, result);
|
|
3348
3406
|
return result;
|
|
3349
3407
|
}
|
|
3350
3408
|
makeCountSchema(model, options) {
|
|
3351
|
-
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3409
|
+
const result = this.mergePluginArgsSchema(z$1.strictObject({
|
|
3352
3410
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3353
3411
|
skip: this.makeSkipSchema().optional(),
|
|
3354
3412
|
take: this.makeTakeSchema().optional(),
|
|
@@ -3359,10 +3417,10 @@ var ZodSchemaFactory = class {
|
|
|
3359
3417
|
return result;
|
|
3360
3418
|
}
|
|
3361
3419
|
makeCountAggregateInputSchema(model) {
|
|
3362
|
-
const schema = z.union([z.literal(true), z.strictObject({
|
|
3363
|
-
_all: z.literal(true).optional(),
|
|
3364
|
-
...this.getModelFields(model).reduce((acc, [field]) => {
|
|
3365
|
-
acc[field] = z.literal(true).optional();
|
|
3420
|
+
const schema = z$1.union([z$1.literal(true), z$1.strictObject({
|
|
3421
|
+
_all: z$1.literal(true).optional(),
|
|
3422
|
+
...this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
|
|
3423
|
+
acc[field] = this.isParameterizedComputedField(fieldDef) ? z$1.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional() : z$1.literal(true).optional();
|
|
3366
3424
|
return acc;
|
|
3367
3425
|
}, {})
|
|
3368
3426
|
})]);
|
|
@@ -3370,7 +3428,7 @@ var ZodSchemaFactory = class {
|
|
|
3370
3428
|
return schema;
|
|
3371
3429
|
}
|
|
3372
3430
|
makeAggregateSchema(model, options) {
|
|
3373
|
-
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3431
|
+
const result = this.mergePluginArgsSchema(z$1.strictObject({
|
|
3374
3432
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3375
3433
|
skip: this.makeSkipSchema().optional(),
|
|
3376
3434
|
take: this.makeTakeSchema().optional(),
|
|
@@ -3385,25 +3443,32 @@ var ZodSchemaFactory = class {
|
|
|
3385
3443
|
return result;
|
|
3386
3444
|
}
|
|
3387
3445
|
makeSumAvgInputSchema(model) {
|
|
3388
|
-
const schema = z.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
|
|
3389
|
-
if (this.isNumericField(fieldDef)) acc[field] = z.literal(true).optional();
|
|
3446
|
+
const schema = z$1.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
|
|
3447
|
+
if (this.isNumericField(fieldDef)) acc[field] = this.isParameterizedComputedField(fieldDef) ? z$1.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional() : z$1.literal(true).optional();
|
|
3390
3448
|
return acc;
|
|
3391
3449
|
}, {}));
|
|
3392
3450
|
this.registerSchema(`${model}SumAvgAggregateInput`, schema);
|
|
3393
3451
|
return schema;
|
|
3394
3452
|
}
|
|
3395
3453
|
makeMinMaxInputSchema(model) {
|
|
3396
|
-
const schema = z.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
|
|
3397
|
-
if (!fieldDef.relation && !fieldDef.array) acc[field] = z.literal(true).optional();
|
|
3454
|
+
const schema = z$1.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
|
|
3455
|
+
if (!fieldDef.relation && !fieldDef.array) acc[field] = this.isParameterizedComputedField(fieldDef) ? z$1.strictObject({ args: this.makeFieldArgsSchema(fieldDef.params) }).optional() : z$1.literal(true).optional();
|
|
3398
3456
|
return acc;
|
|
3399
3457
|
}, {}));
|
|
3400
3458
|
this.registerSchema(`${model}MinMaxAggregateInput`, schema);
|
|
3401
3459
|
return schema;
|
|
3402
3460
|
}
|
|
3403
3461
|
makeGroupBySchema(model, options) {
|
|
3404
|
-
const nonRelationFields = this.getModelFields(model).filter(([, def]) => !def.relation).map(([name]) => name);
|
|
3405
|
-
const
|
|
3406
|
-
|
|
3462
|
+
const nonRelationFields = this.getModelFields(model).filter(([, def]) => !def.relation && !this.isParameterizedComputedField(def)).map(([name]) => name);
|
|
3463
|
+
const byMembers = [];
|
|
3464
|
+
if (nonRelationFields.length > 0) byMembers.push(z$1.enum(nonRelationFields));
|
|
3465
|
+
for (const [field, fieldDef] of this.getModelFields(model)) if (this.isParameterizedComputedField(fieldDef)) byMembers.push(z$1.strictObject({
|
|
3466
|
+
field: z$1.literal(field),
|
|
3467
|
+
args: this.makeFieldArgsSchema(fieldDef.params)
|
|
3468
|
+
}));
|
|
3469
|
+
const byElement = byMembers.length === 0 ? void 0 : byMembers.length === 1 ? byMembers[0] : z$1.union(byMembers);
|
|
3470
|
+
const bySchema = byElement ? this.orArray(byElement, true) : z$1.never();
|
|
3471
|
+
const baseSchema = z$1.strictObject({
|
|
3407
3472
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3408
3473
|
orderBy: this.orArray(this.makeOrderBySchema(model, false, true, options), true).optional(),
|
|
3409
3474
|
by: bySchema,
|
|
@@ -3418,7 +3483,7 @@ var ZodSchemaFactory = class {
|
|
|
3418
3483
|
});
|
|
3419
3484
|
let schema = this.mergePluginArgsSchema(baseSchema, "groupBy");
|
|
3420
3485
|
schema = schema.refine((value) => {
|
|
3421
|
-
const bys = enumerate(value.by);
|
|
3486
|
+
const bys = enumerate(value.by).map((b) => typeof b === "string" ? b : b?.field);
|
|
3422
3487
|
if (value.having && typeof value.having === "object") for (const [key, val] of Object.entries(value.having)) {
|
|
3423
3488
|
if (AggregateOperators.includes(key)) continue;
|
|
3424
3489
|
if (bys.includes(key)) continue;
|
|
@@ -3428,7 +3493,7 @@ var ZodSchemaFactory = class {
|
|
|
3428
3493
|
return true;
|
|
3429
3494
|
}, "fields in \"having\" must be in \"by\"");
|
|
3430
3495
|
schema = schema.refine((value) => {
|
|
3431
|
-
const bys = enumerate(value.by);
|
|
3496
|
+
const bys = enumerate(value.by).map((b) => typeof b === "string" ? b : b?.field);
|
|
3432
3497
|
for (const orderBy of enumerate(value.orderBy)) if (orderBy && Object.keys(orderBy).filter((f) => !AggregateOperators.includes(f)).some((key) => !bys.includes(key))) return false;
|
|
3433
3498
|
return true;
|
|
3434
3499
|
}, "fields in \"orderBy\" must be in \"by\"");
|
|
@@ -3455,7 +3520,7 @@ var ZodSchemaFactory = class {
|
|
|
3455
3520
|
if (!procDef) throw createInternalError(`Procedure not found: ${procName}`);
|
|
3456
3521
|
const shape = {};
|
|
3457
3522
|
for (const param of Object.values(procDef.params ?? {})) shape[param.name] = this.makeProcedureParamSchema(param);
|
|
3458
|
-
const schema = z.object(shape);
|
|
3523
|
+
const schema = z$1.object(shape);
|
|
3459
3524
|
this.registerSchema(`${procName}ProcArgs`, schema);
|
|
3460
3525
|
return schema;
|
|
3461
3526
|
}
|
|
@@ -3463,10 +3528,10 @@ var ZodSchemaFactory = class {
|
|
|
3463
3528
|
let schema;
|
|
3464
3529
|
if (isTypeDef(this.schema, param.type)) schema = this.makeTypeDefSchema(param.type);
|
|
3465
3530
|
else if (isEnum(this.schema, param.type)) schema = this.makeEnumSchema(param.type);
|
|
3466
|
-
else if (param.type in (this.schema.models ?? {})) schema = z.record(z.string(), z.unknown());
|
|
3531
|
+
else if (param.type in (this.schema.models ?? {})) schema = z$1.record(z$1.string(), z$1.unknown());
|
|
3467
3532
|
else {
|
|
3468
3533
|
schema = this.makeScalarSchema(param.type);
|
|
3469
|
-
if (schema instanceof z.ZodUnknown) throw createInternalError(`Unsupported procedure parameter type: ${param.type}`);
|
|
3534
|
+
if (schema instanceof z$1.ZodUnknown) throw createInternalError(`Unsupported procedure parameter type: ${param.type}`);
|
|
3470
3535
|
}
|
|
3471
3536
|
if (param.array) schema = schema.array();
|
|
3472
3537
|
if (param.optional) schema = schema.optional();
|
|
@@ -3502,10 +3567,10 @@ var ZodSchemaFactory = class {
|
|
|
3502
3567
|
return result;
|
|
3503
3568
|
}
|
|
3504
3569
|
makeSkipSchema() {
|
|
3505
|
-
return z.number().int().nonnegative();
|
|
3570
|
+
return z$1.number().int().nonnegative();
|
|
3506
3571
|
}
|
|
3507
3572
|
makeTakeSchema() {
|
|
3508
|
-
return z.number().int();
|
|
3573
|
+
return z$1.number().int();
|
|
3509
3574
|
}
|
|
3510
3575
|
refineForSelectIncludeMutuallyExclusive(schema) {
|
|
3511
3576
|
return schema.refine((value) => !(value["select"] && value["include"]), "\"select\" and \"include\" cannot be used together");
|
|
@@ -3524,7 +3589,7 @@ var ZodSchemaFactory = class {
|
|
|
3524
3589
|
return nullable ? schema.nullable() : schema;
|
|
3525
3590
|
}
|
|
3526
3591
|
orArray(schema, canBeArray) {
|
|
3527
|
-
return canBeArray ? z.union([schema, z.array(schema)]) : schema;
|
|
3592
|
+
return canBeArray ? z$1.union([schema, z$1.array(schema)]) : schema;
|
|
3528
3593
|
}
|
|
3529
3594
|
isNumericField(fieldDef) {
|
|
3530
3595
|
return NUMERIC_FIELD_TYPES.includes(fieldDef.type) && !fieldDef.array;
|
|
@@ -3586,10 +3651,10 @@ var ZodSchemaFactory = class {
|
|
|
3586
3651
|
createUnionFilterSchema(valueSchema, optional, components, allowedFilterKinds) {
|
|
3587
3652
|
if (Object.keys(components).length === 0) {
|
|
3588
3653
|
if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return this.nullableIf(valueSchema, optional);
|
|
3589
|
-
return z.never();
|
|
3654
|
+
return z$1.never();
|
|
3590
3655
|
}
|
|
3591
|
-
if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return z.union([this.nullableIf(valueSchema, optional), z.strictObject(components)]);
|
|
3592
|
-
else return z.strictObject(components);
|
|
3656
|
+
if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return z$1.union([this.nullableIf(valueSchema, optional), z$1.strictObject(components)]);
|
|
3657
|
+
else return z$1.strictObject(components);
|
|
3593
3658
|
}
|
|
3594
3659
|
canCreateModel(model) {
|
|
3595
3660
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -4329,8 +4394,10 @@ var BaseOperationHandler = class {
|
|
|
4329
4394
|
continue;
|
|
4330
4395
|
}
|
|
4331
4396
|
const fieldDef = this.requireField(model, field);
|
|
4332
|
-
if (!fieldDef.relation)
|
|
4333
|
-
|
|
4397
|
+
if (!fieldDef.relation) {
|
|
4398
|
+
const computedArgs = fieldDef.computed && fieldDef.params && typeof payload === "object" && "args" in payload ? payload.args : void 0;
|
|
4399
|
+
result = this.dialect.buildSelectField(result, model, parentAlias, field, computedArgs);
|
|
4400
|
+
} else {
|
|
4334
4401
|
if (!fieldDef.array && !fieldDef.optional && payload.where) throw createInternalError(`Field "${field}" does not support filtering`, model);
|
|
4335
4402
|
if (fieldDef.originModel) result = this.dialect.buildRelationSelection(result, fieldDef.originModel, field, fieldDef.originModel, payload);
|
|
4336
4403
|
else result = this.dialect.buildRelationSelection(result, model, field, parentAlias, payload);
|
|
@@ -5312,6 +5379,7 @@ var BaseOperationHandler = class {
|
|
|
5312
5379
|
};
|
|
5313
5380
|
//#endregion
|
|
5314
5381
|
//#region src/client/crud/operations/aggregate.ts
|
|
5382
|
+
const argsKey = (v) => JSON.stringify(v, (_k, val) => typeof val === "bigint" ? `${val}n` : val);
|
|
5315
5383
|
var AggregateOperationHandler = class extends BaseOperationHandler {
|
|
5316
5384
|
async handle(_operation, args) {
|
|
5317
5385
|
const normalizedArgs = this.normalizeArgs(args);
|
|
@@ -5319,10 +5387,18 @@ var AggregateOperationHandler = class extends BaseOperationHandler {
|
|
|
5319
5387
|
let query = this.kysely.selectFrom((eb) => {
|
|
5320
5388
|
let subQuery = this.dialect.buildSelectModel(this.model, this.model).where(() => this.dialect.buildFilter(this.model, this.model, parsedArgs?.where));
|
|
5321
5389
|
const selectedFields = [];
|
|
5322
|
-
|
|
5390
|
+
const computedArgsByField = {};
|
|
5391
|
+
for (const [key, value] of Object.entries(parsedArgs)) if (key.startsWith("_") && value && typeof value === "object") Object.entries(value).filter(([field]) => field !== "_all").forEach(([field, val]) => {
|
|
5392
|
+
const args = val && typeof val === "object" && "args" in val ? val.args : void 0;
|
|
5393
|
+
if (val !== true && args === void 0) return;
|
|
5323
5394
|
if (!selectedFields.includes(field)) selectedFields.push(field);
|
|
5395
|
+
if (args !== void 0) {
|
|
5396
|
+
const prev = computedArgsByField[field];
|
|
5397
|
+
if (prev !== void 0 && argsKey(prev) !== argsKey(args)) throw createInvalidInputError(`computed field "${field}" is aggregated with conflicting "args"; the same field can only be aggregated with one set of arguments per query`);
|
|
5398
|
+
computedArgsByField[field] = args;
|
|
5399
|
+
}
|
|
5324
5400
|
});
|
|
5325
|
-
if (selectedFields.length > 0) for (const field of selectedFields) subQuery = this.dialect.buildSelectField(subQuery, this.model, this.model, field);
|
|
5401
|
+
if (selectedFields.length > 0) for (const field of selectedFields) subQuery = this.dialect.buildSelectField(subQuery, this.model, this.model, field, computedArgsByField[field]);
|
|
5326
5402
|
else subQuery = subQuery.select(() => eb.lit(1).as("_all"));
|
|
5327
5403
|
const skip = parsedArgs?.skip;
|
|
5328
5404
|
let take = parsedArgs?.take;
|
|
@@ -5339,7 +5415,7 @@ var AggregateOperationHandler = class extends BaseOperationHandler {
|
|
|
5339
5415
|
case "_count":
|
|
5340
5416
|
if (value === true) query = query.select((eb) => this.dialect.castInt(eb.fn.countAll()).as("_count"));
|
|
5341
5417
|
else Object.entries(value).forEach(([field, val]) => {
|
|
5342
|
-
if (val === true) if (field === "_all") query = query.select((eb) => this.dialect.castInt(eb.fn.countAll()).as(`_count._all`));
|
|
5418
|
+
if (val === true || val && typeof val === "object" && "args" in val) if (field === "_all") query = query.select((eb) => this.dialect.castInt(eb.fn.countAll()).as(`_count._all`));
|
|
5343
5419
|
else query = query.select((eb) => this.dialect.castInt(eb.fn.count(eb.ref(`$sub.${field}`))).as(`${key}.${field}`));
|
|
5344
5420
|
});
|
|
5345
5421
|
break;
|
|
@@ -5348,7 +5424,7 @@ var AggregateOperationHandler = class extends BaseOperationHandler {
|
|
|
5348
5424
|
case "_max":
|
|
5349
5425
|
case "_min":
|
|
5350
5426
|
Object.entries(value).forEach(([field, val]) => {
|
|
5351
|
-
if (val === true) query = query.select((eb) => {
|
|
5427
|
+
if (val === true || val && typeof val === "object" && "args" in val) query = query.select((eb) => {
|
|
5352
5428
|
return match(key).with("_sum", () => eb.fn.sum).with("_avg", () => eb.fn.avg).with("_max", () => eb.fn.max).with("_min", () => eb.fn.min).exhaustive()(eb.ref(`$sub.${field}`)).as(`${key}.${field}`);
|
|
5353
5429
|
});
|
|
5354
5430
|
});
|
|
@@ -5391,9 +5467,12 @@ var CountOperationHandler = class extends BaseOperationHandler {
|
|
|
5391
5467
|
const subQueryName = "$sub";
|
|
5392
5468
|
let query = this.kysely.selectFrom((eb) => {
|
|
5393
5469
|
let subQuery = this.dialect.buildSelectModel(this.model, this.model).where(() => this.dialect.buildFilter(this.model, this.model, parsedArgs?.where));
|
|
5394
|
-
if (parsedArgs?.select && typeof parsedArgs.select === "object") {
|
|
5395
|
-
|
|
5396
|
-
|
|
5470
|
+
if (parsedArgs?.select && typeof parsedArgs.select === "object") for (const [key, value] of Object.entries(parsedArgs.select)) {
|
|
5471
|
+
if (key === "_all") continue;
|
|
5472
|
+
if (value === true) subQuery = this.dialect.buildSelectField(subQuery, this.model, this.model, key);
|
|
5473
|
+
else if (value && typeof value === "object" && "args" in value) subQuery = this.dialect.buildSelectField(subQuery, this.model, this.model, key, value.args);
|
|
5474
|
+
}
|
|
5475
|
+
else subQuery = subQuery.select(() => eb.lit(1).as("_all"));
|
|
5397
5476
|
subQuery = this.dialect.buildSkipTake(subQuery, parsedArgs?.skip, parsedArgs?.take);
|
|
5398
5477
|
return subQuery.as(subQueryName);
|
|
5399
5478
|
});
|
|
@@ -5534,9 +5613,17 @@ var GroupByOperationHandler = class extends BaseOperationHandler {
|
|
|
5534
5613
|
const normalizedArgs = this.normalizeArgs(args);
|
|
5535
5614
|
const parsedArgs = this.inputValidator.validateGroupByArgs(this.model, normalizedArgs);
|
|
5536
5615
|
let query = this.kysely.selectFrom(this.model).where(() => this.dialect.buildFilter(this.model, this.model, parsedArgs?.where));
|
|
5537
|
-
const fieldRef = (field) => this.dialect.fieldRef(this.model, field);
|
|
5538
|
-
const
|
|
5539
|
-
|
|
5616
|
+
const fieldRef = (field, computedArgs) => this.dialect.fieldRef(this.model, field, this.model, true, computedArgs);
|
|
5617
|
+
const byEntries = (Array.isArray(parsedArgs.by) ? parsedArgs.by : [parsedArgs.by]).map((by) => typeof by === "string" ? {
|
|
5618
|
+
field: by,
|
|
5619
|
+
args: void 0
|
|
5620
|
+
} : {
|
|
5621
|
+
field: by.field,
|
|
5622
|
+
args: by.args
|
|
5623
|
+
});
|
|
5624
|
+
query = query.groupBy(byEntries.map((e) => {
|
|
5625
|
+
return getField(this.schema, this.model, e.field)?.computed ? sql.ref(e.field) : fieldRef(e.field);
|
|
5626
|
+
}));
|
|
5540
5627
|
const skip = parsedArgs?.skip;
|
|
5541
5628
|
let take = parsedArgs?.take;
|
|
5542
5629
|
let negateOrderBy = false;
|
|
@@ -5547,13 +5634,14 @@ var GroupByOperationHandler = class extends BaseOperationHandler {
|
|
|
5547
5634
|
query = this.dialect.buildSkipTake(query, skip, take);
|
|
5548
5635
|
query = this.dialect.buildOrderBy(query, this.model, this.model, parsedArgs.orderBy, negateOrderBy, take);
|
|
5549
5636
|
if (parsedArgs.having) query = query.having(() => this.dialect.buildFilter(this.model, this.model, parsedArgs.having));
|
|
5550
|
-
for (const
|
|
5637
|
+
for (const e of byEntries) query = query.select(() => fieldRef(e.field, e.args).as(e.field));
|
|
5551
5638
|
for (const [key, value] of Object.entries(parsedArgs)) switch (key) {
|
|
5552
5639
|
case "_count":
|
|
5553
5640
|
if (value === true) query = query.select((eb) => this.dialect.castInt(eb.fn.countAll()).as("_count"));
|
|
5554
5641
|
else Object.entries(value).forEach(([field, val]) => {
|
|
5555
|
-
|
|
5556
|
-
|
|
5642
|
+
const args = val && typeof val === "object" && "args" in val ? val.args : void 0;
|
|
5643
|
+
if (val === true || args !== void 0) if (field === "_all") query = query.select((eb) => this.dialect.castInt(eb.fn.countAll()).as(`_count._all`));
|
|
5644
|
+
else query = query.select((eb) => this.dialect.castInt(eb.fn.count(fieldRef(field, args))).as(`${key}.${field}`));
|
|
5557
5645
|
});
|
|
5558
5646
|
break;
|
|
5559
5647
|
case "_sum":
|
|
@@ -5561,7 +5649,8 @@ var GroupByOperationHandler = class extends BaseOperationHandler {
|
|
|
5561
5649
|
case "_max":
|
|
5562
5650
|
case "_min":
|
|
5563
5651
|
Object.entries(value).forEach(([field, val]) => {
|
|
5564
|
-
|
|
5652
|
+
const args = val && typeof val === "object" && "args" in val ? val.args : void 0;
|
|
5653
|
+
if (val === true || args !== void 0) query = query.select((eb) => aggregate(eb, fieldRef(field, args), key).as(`${key}.${field}`));
|
|
5565
5654
|
});
|
|
5566
5655
|
break;
|
|
5567
5656
|
}
|
|
@@ -7197,9 +7286,9 @@ var ClientImpl = class ClientImpl {
|
|
|
7197
7286
|
validateOptions(baseClient, options) {
|
|
7198
7287
|
if (!baseClient && !options.skipValidationForComputedFields) this.validateComputedFieldsConfig(options);
|
|
7199
7288
|
if (options.diagnostics) {
|
|
7200
|
-
const parseResult = z
|
|
7201
|
-
slowQueryThresholdMs: z
|
|
7202
|
-
slowQueryMaxRecords: z
|
|
7289
|
+
const parseResult = z.object({
|
|
7290
|
+
slowQueryThresholdMs: z.number().nonnegative().optional(),
|
|
7291
|
+
slowQueryMaxRecords: z.int().nonnegative().or(z.literal(Infinity)).optional()
|
|
7203
7292
|
}).safeParse(options.diagnostics);
|
|
7204
7293
|
if (!parseResult.success) throw createConfigError(`Invalid diagnostics configuration: ${formatError(parseResult.error)}`);
|
|
7205
7294
|
}
|