@zenstackhq/orm 3.0.0-beta.25 → 3.0.0-beta.27
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 +247 -175
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +635 -584
- package/dist/index.d.ts +635 -584
- package/dist/index.js +247 -175
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -632,6 +632,7 @@ var import_common_helpers3 = require("@zenstackhq/common-helpers");
|
|
|
632
632
|
var import_decimal = __toESM(require("decimal.js"), 1);
|
|
633
633
|
var import_kysely3 = require("kysely");
|
|
634
634
|
var import_ts_pattern3 = require("ts-pattern");
|
|
635
|
+
var import_zod = __toESM(require("zod"), 1);
|
|
635
636
|
|
|
636
637
|
// src/client/crud/dialects/base-dialect.ts
|
|
637
638
|
var import_common_helpers2 = require("@zenstackhq/common-helpers");
|
|
@@ -1128,7 +1129,7 @@ var BaseCrudDialect = class {
|
|
|
1128
1129
|
if (isRelationField(this.schema, model, field)) {
|
|
1129
1130
|
continue;
|
|
1130
1131
|
}
|
|
1131
|
-
if (omit
|
|
1132
|
+
if (this.shouldOmitField(omit, model, field)) {
|
|
1132
1133
|
continue;
|
|
1133
1134
|
}
|
|
1134
1135
|
result = this.buildSelectField(result, model, modelAlias, field);
|
|
@@ -1149,6 +1150,16 @@ var BaseCrudDialect = class {
|
|
|
1149
1150
|
}
|
|
1150
1151
|
return result;
|
|
1151
1152
|
}
|
|
1153
|
+
shouldOmitField(omit, model, field) {
|
|
1154
|
+
if (omit && typeof omit === "object" && typeof omit[field] === "boolean") {
|
|
1155
|
+
return omit[field];
|
|
1156
|
+
}
|
|
1157
|
+
if (this.options.omit?.[model] && typeof this.options.omit[model] === "object" && typeof this.options.omit[model][field] === "boolean") {
|
|
1158
|
+
return this.options.omit[model][field];
|
|
1159
|
+
}
|
|
1160
|
+
const fieldDef = requireField(this.schema, model, field);
|
|
1161
|
+
return !!fieldDef.omit;
|
|
1162
|
+
}
|
|
1152
1163
|
buildModelSelect(model, subQueryAlias, payload, selectAllFields) {
|
|
1153
1164
|
let subQuery = this.buildSelectModel(model, subQueryAlias);
|
|
1154
1165
|
if (selectAllFields) {
|
|
@@ -1291,6 +1302,10 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
|
|
|
1291
1302
|
static {
|
|
1292
1303
|
__name(this, "PostgresCrudDialect");
|
|
1293
1304
|
}
|
|
1305
|
+
isoDateSchema = import_zod.default.iso.datetime({
|
|
1306
|
+
local: true,
|
|
1307
|
+
offset: true
|
|
1308
|
+
});
|
|
1294
1309
|
constructor(schema, options) {
|
|
1295
1310
|
super(schema, options);
|
|
1296
1311
|
}
|
|
@@ -1339,7 +1354,12 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
|
|
|
1339
1354
|
}
|
|
1340
1355
|
transformOutputDate(value) {
|
|
1341
1356
|
if (typeof value === "string") {
|
|
1342
|
-
|
|
1357
|
+
if (this.isoDateSchema.safeParse(value).success) {
|
|
1358
|
+
const hasOffset = value.endsWith("Z") || /[+-]\d{2}:\d{2}$/.test(value);
|
|
1359
|
+
return new Date(hasOffset ? value : `${value}Z`);
|
|
1360
|
+
} else {
|
|
1361
|
+
return value;
|
|
1362
|
+
}
|
|
1343
1363
|
} else if (value instanceof Date && this.options.fixPostgresTimezone !== false) {
|
|
1344
1364
|
return new Date(value.getTime() - value.getTimezoneOffset() * 60 * 1e3);
|
|
1345
1365
|
} else {
|
|
@@ -1412,7 +1432,8 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
|
|
|
1412
1432
|
]).flatMap((v) => v));
|
|
1413
1433
|
}
|
|
1414
1434
|
if (payload === true || !payload.select) {
|
|
1415
|
-
|
|
1435
|
+
const omit = typeof payload === "object" ? payload.omit : void 0;
|
|
1436
|
+
objArgs.push(...Object.entries(relationModelDef.fields).filter(([, value]) => !value.relation).filter(([name]) => !this.shouldOmitField(omit, relationModel, name)).map(([field]) => [
|
|
1416
1437
|
import_kysely3.sql.lit(field),
|
|
1417
1438
|
this.fieldRef(relationModel, field, relationModelAlias, false)
|
|
1418
1439
|
]).flatMap((v) => v));
|
|
@@ -1623,7 +1644,8 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
1623
1644
|
]).flatMap((v) => v));
|
|
1624
1645
|
}
|
|
1625
1646
|
if (payload === true || !payload.select) {
|
|
1626
|
-
|
|
1647
|
+
const omit = typeof payload === "object" ? payload.omit : void 0;
|
|
1648
|
+
objArgs.push(...Object.entries(relationModelDef.fields).filter(([, value]) => !value.relation).filter(([name]) => !this.shouldOmitField(omit, relationModel, name)).map(([field]) => [
|
|
1627
1649
|
import_kysely4.sql.lit(field),
|
|
1628
1650
|
this.fieldRef(relationModel, field, subQueryName, false)
|
|
1629
1651
|
]).flatMap((v) => v));
|
|
@@ -3099,12 +3121,11 @@ var BaseOperationHandler = class {
|
|
|
3099
3121
|
const allFields = Object.keys(modelDef.fields);
|
|
3100
3122
|
const relationFields = Object.values(modelDef.fields).filter((f) => f.relation).map((f) => f.name);
|
|
3101
3123
|
const computedFields = Object.values(modelDef.fields).filter((f) => f.computed).map((f) => f.name);
|
|
3102
|
-
const omit = Object.entries(args.omit ?? {}).filter(([, v]) => v).map(([k]) => k);
|
|
3103
3124
|
const allFieldsSelected = [];
|
|
3104
3125
|
if (!args.select || typeof args.select !== "object") {
|
|
3105
|
-
allFieldsSelected.push(...allFields.filter((f) => !relationFields.includes(f) && !
|
|
3126
|
+
allFieldsSelected.push(...allFields.filter((f) => !relationFields.includes(f) && !this.dialect.shouldOmitField(args.omit, model, f)));
|
|
3106
3127
|
} else {
|
|
3107
|
-
allFieldsSelected.push(...Object.entries(args.select).filter(([k, v]) => v && !
|
|
3128
|
+
allFieldsSelected.push(...Object.entries(args.select).filter(([k, v]) => v && !this.dialect.shouldOmitField(args.omit, model, k)).map(([k]) => k));
|
|
3108
3129
|
}
|
|
3109
3130
|
if (allFieldsSelected.some((f) => relationFields.includes(f) || computedFields.includes(f))) {
|
|
3110
3131
|
return {
|
|
@@ -3620,7 +3641,7 @@ var import_common_helpers7 = require("@zenstackhq/common-helpers");
|
|
|
3620
3641
|
var import_decimal4 = __toESM(require("decimal.js"), 1);
|
|
3621
3642
|
var import_json_stable_stringify = __toESM(require("json-stable-stringify"), 1);
|
|
3622
3643
|
var import_ts_pattern13 = require("ts-pattern");
|
|
3623
|
-
var
|
|
3644
|
+
var import_zod3 = require("zod");
|
|
3624
3645
|
|
|
3625
3646
|
// src/utils/zod-utils.ts
|
|
3626
3647
|
var import_v4 = require("zod-validation-error/v4");
|
|
@@ -3633,7 +3654,7 @@ __name(formatError, "formatError");
|
|
|
3633
3654
|
var import_common_helpers6 = require("@zenstackhq/common-helpers");
|
|
3634
3655
|
var import_decimal3 = __toESM(require("decimal.js"), 1);
|
|
3635
3656
|
var import_ts_pattern12 = require("ts-pattern");
|
|
3636
|
-
var
|
|
3657
|
+
var import_zod2 = require("zod");
|
|
3637
3658
|
var import_v3 = require("zod/v3");
|
|
3638
3659
|
function getArgValue(expr) {
|
|
3639
3660
|
if (!expr || !schema_exports.ExpressionUtils.isLiteral(expr)) {
|
|
@@ -3742,13 +3763,13 @@ function addBigIntValidation(schema, attributes) {
|
|
|
3742
3763
|
__name(addBigIntValidation, "addBigIntValidation");
|
|
3743
3764
|
function addDecimalValidation(schema, attributes, addExtraValidation) {
|
|
3744
3765
|
let result = schema;
|
|
3745
|
-
if (schema instanceof
|
|
3766
|
+
if (schema instanceof import_zod2.z.ZodString) {
|
|
3746
3767
|
result = schema.superRefine((v, ctx) => {
|
|
3747
3768
|
try {
|
|
3748
3769
|
new import_decimal3.default(v);
|
|
3749
3770
|
} catch (err) {
|
|
3750
3771
|
ctx.addIssue({
|
|
3751
|
-
code:
|
|
3772
|
+
code: import_zod2.z.ZodIssueCode.custom,
|
|
3752
3773
|
message: `Invalid decimal: ${err}`
|
|
3753
3774
|
});
|
|
3754
3775
|
}
|
|
@@ -3756,7 +3777,7 @@ function addDecimalValidation(schema, attributes, addExtraValidation) {
|
|
|
3756
3777
|
}
|
|
3757
3778
|
function refine(schema2, op, value) {
|
|
3758
3779
|
return schema2.superRefine((v, ctx) => {
|
|
3759
|
-
const base =
|
|
3780
|
+
const base = import_zod2.z.number();
|
|
3760
3781
|
const { error } = base[op](value).safeParse(v.toNumber());
|
|
3761
3782
|
error?.issues.forEach((issue) => {
|
|
3762
3783
|
if (op === "gt" || op === "gte") {
|
|
@@ -3961,7 +3982,7 @@ function evalCall(data, expr) {
|
|
|
3961
3982
|
}
|
|
3962
3983
|
(0, import_common_helpers6.invariant)(typeof fieldArg === "string", `"${f}" first argument must be a string`);
|
|
3963
3984
|
const fn = (0, import_ts_pattern12.match)(f).with("isEmail", () => "email").with("isUrl", () => "url").with("isDateTime", () => "datetime").exhaustive();
|
|
3964
|
-
return
|
|
3985
|
+
return import_zod2.z.string()[fn]().safeParse(fieldArg).success;
|
|
3965
3986
|
}).with(import_ts_pattern12.P.union("has", "hasEvery", "hasSome"), (f) => {
|
|
3966
3987
|
(0, import_common_helpers6.invariant)(expr.args?.[1], `${f} requires a search argument`);
|
|
3967
3988
|
if (fieldArg === void 0 || fieldArg === null) {
|
|
@@ -4002,6 +4023,9 @@ var InputValidator = class {
|
|
|
4002
4023
|
get schema() {
|
|
4003
4024
|
return this.client.$schema;
|
|
4004
4025
|
}
|
|
4026
|
+
get options() {
|
|
4027
|
+
return this.client.$options;
|
|
4028
|
+
}
|
|
4005
4029
|
get extraValidationsEnabled() {
|
|
4006
4030
|
return this.client.$options.validateInput !== false;
|
|
4007
4031
|
}
|
|
@@ -4096,7 +4120,7 @@ var InputValidator = class {
|
|
|
4096
4120
|
if (!options.unique) {
|
|
4097
4121
|
fields["skip"] = this.makeSkipSchema().optional();
|
|
4098
4122
|
if (options.findOne) {
|
|
4099
|
-
fields["take"] =
|
|
4123
|
+
fields["take"] = import_zod3.z.literal(1).optional();
|
|
4100
4124
|
} else {
|
|
4101
4125
|
fields["take"] = this.makeTakeSchema().optional();
|
|
4102
4126
|
}
|
|
@@ -4104,7 +4128,7 @@ var InputValidator = class {
|
|
|
4104
4128
|
fields["cursor"] = this.makeCursorSchema(model).optional();
|
|
4105
4129
|
fields["distinct"] = this.makeDistinctSchema(model).optional();
|
|
4106
4130
|
}
|
|
4107
|
-
let result =
|
|
4131
|
+
let result = import_zod3.z.strictObject(fields);
|
|
4108
4132
|
result = this.refineForSelectIncludeMutuallyExclusive(result);
|
|
4109
4133
|
result = this.refineForSelectOmitMutuallyExclusive(result);
|
|
4110
4134
|
if (!options.unique) {
|
|
@@ -4118,19 +4142,19 @@ var InputValidator = class {
|
|
|
4118
4142
|
} else if (this.schema.enums && type in this.schema.enums) {
|
|
4119
4143
|
return this.makeEnumSchema(type);
|
|
4120
4144
|
} else {
|
|
4121
|
-
return (0, import_ts_pattern13.match)(type).with("String", () => this.extraValidationsEnabled ? addStringValidation(
|
|
4122
|
-
this.extraValidationsEnabled ? addNumberValidation(
|
|
4123
|
-
this.extraValidationsEnabled ? addBigIntValidation(
|
|
4145
|
+
return (0, import_ts_pattern13.match)(type).with("String", () => this.extraValidationsEnabled ? addStringValidation(import_zod3.z.string(), attributes) : import_zod3.z.string()).with("Int", () => this.extraValidationsEnabled ? addNumberValidation(import_zod3.z.number().int(), attributes) : import_zod3.z.number().int()).with("Float", () => this.extraValidationsEnabled ? addNumberValidation(import_zod3.z.number(), attributes) : import_zod3.z.number()).with("Boolean", () => import_zod3.z.boolean()).with("BigInt", () => import_zod3.z.union([
|
|
4146
|
+
this.extraValidationsEnabled ? addNumberValidation(import_zod3.z.number().int(), attributes) : import_zod3.z.number().int(),
|
|
4147
|
+
this.extraValidationsEnabled ? addBigIntValidation(import_zod3.z.bigint(), attributes) : import_zod3.z.bigint()
|
|
4124
4148
|
])).with("Decimal", () => {
|
|
4125
|
-
return
|
|
4126
|
-
this.extraValidationsEnabled ? addNumberValidation(
|
|
4127
|
-
addDecimalValidation(
|
|
4128
|
-
addDecimalValidation(
|
|
4149
|
+
return import_zod3.z.union([
|
|
4150
|
+
this.extraValidationsEnabled ? addNumberValidation(import_zod3.z.number(), attributes) : import_zod3.z.number(),
|
|
4151
|
+
addDecimalValidation(import_zod3.z.instanceof(import_decimal4.default), attributes, this.extraValidationsEnabled),
|
|
4152
|
+
addDecimalValidation(import_zod3.z.string(), attributes, this.extraValidationsEnabled)
|
|
4129
4153
|
]);
|
|
4130
|
-
}).with("DateTime", () =>
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
])).with("Bytes", () =>
|
|
4154
|
+
}).with("DateTime", () => import_zod3.z.union([
|
|
4155
|
+
import_zod3.z.date(),
|
|
4156
|
+
import_zod3.z.string().datetime()
|
|
4157
|
+
])).with("Bytes", () => import_zod3.z.instanceof(Uint8Array)).otherwise(() => import_zod3.z.unknown());
|
|
4134
4158
|
}
|
|
4135
4159
|
}
|
|
4136
4160
|
makeEnumSchema(type) {
|
|
@@ -4144,7 +4168,7 @@ var InputValidator = class {
|
|
|
4144
4168
|
}
|
|
4145
4169
|
const enumDef = getEnum(this.schema, type);
|
|
4146
4170
|
(0, import_common_helpers7.invariant)(enumDef, `Enum "${type}" not found in schema`);
|
|
4147
|
-
schema =
|
|
4171
|
+
schema = import_zod3.z.enum(Object.keys(enumDef.values));
|
|
4148
4172
|
this.setSchemaCache(key, schema);
|
|
4149
4173
|
return schema;
|
|
4150
4174
|
}
|
|
@@ -4160,7 +4184,7 @@ var InputValidator = class {
|
|
|
4160
4184
|
}
|
|
4161
4185
|
const typeDef = getTypeDef(this.schema, type);
|
|
4162
4186
|
(0, import_common_helpers7.invariant)(typeDef, `Type definition "${type}" not found in schema`);
|
|
4163
|
-
schema =
|
|
4187
|
+
schema = import_zod3.z.looseObject(Object.fromEntries(Object.entries(typeDef.fields).map(([field, def]) => {
|
|
4164
4188
|
let fieldSchema = this.makePrimitiveSchema(def.type);
|
|
4165
4189
|
if (def.array) {
|
|
4166
4190
|
fieldSchema = fieldSchema.array();
|
|
@@ -4186,21 +4210,21 @@ var InputValidator = class {
|
|
|
4186
4210
|
if (withoutRelationFields) {
|
|
4187
4211
|
continue;
|
|
4188
4212
|
}
|
|
4189
|
-
fieldSchema =
|
|
4213
|
+
fieldSchema = import_zod3.z.lazy(() => this.makeWhereSchema(fieldDef.type, false).optional());
|
|
4190
4214
|
fieldSchema = this.nullableIf(fieldSchema, !fieldDef.array && !!fieldDef.optional);
|
|
4191
4215
|
if (fieldDef.array) {
|
|
4192
|
-
fieldSchema =
|
|
4216
|
+
fieldSchema = import_zod3.z.union([
|
|
4193
4217
|
fieldSchema,
|
|
4194
|
-
|
|
4218
|
+
import_zod3.z.strictObject({
|
|
4195
4219
|
some: fieldSchema.optional(),
|
|
4196
4220
|
every: fieldSchema.optional(),
|
|
4197
4221
|
none: fieldSchema.optional()
|
|
4198
4222
|
})
|
|
4199
4223
|
]);
|
|
4200
4224
|
} else {
|
|
4201
|
-
fieldSchema =
|
|
4225
|
+
fieldSchema = import_zod3.z.union([
|
|
4202
4226
|
fieldSchema,
|
|
4203
|
-
|
|
4227
|
+
import_zod3.z.strictObject({
|
|
4204
4228
|
is: fieldSchema.optional(),
|
|
4205
4229
|
isNot: fieldSchema.optional()
|
|
4206
4230
|
})
|
|
@@ -4226,7 +4250,7 @@ var InputValidator = class {
|
|
|
4226
4250
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
4227
4251
|
for (const uniqueField of uniqueFields) {
|
|
4228
4252
|
if ("defs" in uniqueField) {
|
|
4229
|
-
fields[uniqueField.name] =
|
|
4253
|
+
fields[uniqueField.name] = import_zod3.z.object(Object.fromEntries(Object.entries(uniqueField.defs).map(([key, def]) => {
|
|
4230
4254
|
(0, import_common_helpers7.invariant)(!def.relation, "unique field cannot be a relation");
|
|
4231
4255
|
let fieldSchema;
|
|
4232
4256
|
const enumDef = getEnum(this.schema, def.type);
|
|
@@ -4234,7 +4258,7 @@ var InputValidator = class {
|
|
|
4234
4258
|
if (Object.keys(enumDef.values).length > 0) {
|
|
4235
4259
|
fieldSchema = this.makeEnumFilterSchema(enumDef, !!def.optional, false);
|
|
4236
4260
|
} else {
|
|
4237
|
-
fieldSchema =
|
|
4261
|
+
fieldSchema = import_zod3.z.never();
|
|
4238
4262
|
}
|
|
4239
4263
|
} else {
|
|
4240
4264
|
fieldSchema = this.makePrimitiveFilterSchema(def.type, !!def.optional, false);
|
|
@@ -4247,11 +4271,11 @@ var InputValidator = class {
|
|
|
4247
4271
|
}
|
|
4248
4272
|
}
|
|
4249
4273
|
}
|
|
4250
|
-
fields["$expr"] =
|
|
4251
|
-
fields["AND"] = this.orArray(
|
|
4252
|
-
fields["OR"] =
|
|
4253
|
-
fields["NOT"] = this.orArray(
|
|
4254
|
-
const baseWhere =
|
|
4274
|
+
fields["$expr"] = import_zod3.z.custom((v) => typeof v === "function").optional();
|
|
4275
|
+
fields["AND"] = this.orArray(import_zod3.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
|
|
4276
|
+
fields["OR"] = import_zod3.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)).array().optional();
|
|
4277
|
+
fields["NOT"] = this.orArray(import_zod3.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
|
|
4278
|
+
const baseWhere = import_zod3.z.strictObject(fields);
|
|
4255
4279
|
let result = baseWhere;
|
|
4256
4280
|
if (unique) {
|
|
4257
4281
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
@@ -4271,8 +4295,8 @@ var InputValidator = class {
|
|
|
4271
4295
|
return result;
|
|
4272
4296
|
}
|
|
4273
4297
|
makeEnumFilterSchema(enumDef, optional, withAggregations) {
|
|
4274
|
-
const baseSchema =
|
|
4275
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () =>
|
|
4298
|
+
const baseSchema = import_zod3.z.enum(Object.keys(enumDef.values));
|
|
4299
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => import_zod3.z.lazy(() => this.makeEnumFilterSchema(enumDef, optional, withAggregations)), [
|
|
4276
4300
|
"equals",
|
|
4277
4301
|
"in",
|
|
4278
4302
|
"notIn",
|
|
@@ -4282,41 +4306,41 @@ var InputValidator = class {
|
|
|
4282
4306
|
"_min",
|
|
4283
4307
|
"_max"
|
|
4284
4308
|
] : void 0);
|
|
4285
|
-
return
|
|
4309
|
+
return import_zod3.z.union([
|
|
4286
4310
|
this.nullableIf(baseSchema, optional),
|
|
4287
|
-
|
|
4311
|
+
import_zod3.z.strictObject(components)
|
|
4288
4312
|
]);
|
|
4289
4313
|
}
|
|
4290
4314
|
makeArrayFilterSchema(type) {
|
|
4291
|
-
return
|
|
4315
|
+
return import_zod3.z.strictObject({
|
|
4292
4316
|
equals: this.makePrimitiveSchema(type).array().optional(),
|
|
4293
4317
|
has: this.makePrimitiveSchema(type).optional(),
|
|
4294
4318
|
hasEvery: this.makePrimitiveSchema(type).array().optional(),
|
|
4295
4319
|
hasSome: this.makePrimitiveSchema(type).array().optional(),
|
|
4296
|
-
isEmpty:
|
|
4320
|
+
isEmpty: import_zod3.z.boolean().optional()
|
|
4297
4321
|
});
|
|
4298
4322
|
}
|
|
4299
4323
|
makePrimitiveFilterSchema(type, optional, withAggregations) {
|
|
4300
4324
|
if (this.schema.typeDefs && type in this.schema.typeDefs) {
|
|
4301
4325
|
return this.makeTypeDefFilterSchema(type, optional);
|
|
4302
4326
|
}
|
|
4303
|
-
return (0, import_ts_pattern13.match)(type).with("String", () => this.makeStringFilterSchema(optional, withAggregations)).with(import_ts_pattern13.P.union("Int", "Float", "Decimal", "BigInt"), (type2) => this.makeNumberFilterSchema(this.makePrimitiveSchema(type2), optional, withAggregations)).with("Boolean", () => this.makeBooleanFilterSchema(optional, withAggregations)).with("DateTime", () => this.makeDateTimeFilterSchema(optional, withAggregations)).with("Bytes", () => this.makeBytesFilterSchema(optional, withAggregations)).with("Json", () =>
|
|
4327
|
+
return (0, import_ts_pattern13.match)(type).with("String", () => this.makeStringFilterSchema(optional, withAggregations)).with(import_ts_pattern13.P.union("Int", "Float", "Decimal", "BigInt"), (type2) => this.makeNumberFilterSchema(this.makePrimitiveSchema(type2), optional, withAggregations)).with("Boolean", () => this.makeBooleanFilterSchema(optional, withAggregations)).with("DateTime", () => this.makeDateTimeFilterSchema(optional, withAggregations)).with("Bytes", () => this.makeBytesFilterSchema(optional, withAggregations)).with("Json", () => import_zod3.z.any()).with("Unsupported", () => import_zod3.z.never()).exhaustive();
|
|
4304
4328
|
}
|
|
4305
4329
|
makeTypeDefFilterSchema(_type, _optional) {
|
|
4306
|
-
return
|
|
4330
|
+
return import_zod3.z.never();
|
|
4307
4331
|
}
|
|
4308
4332
|
makeDateTimeFilterSchema(optional, withAggregations) {
|
|
4309
|
-
return this.makeCommonPrimitiveFilterSchema(
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
]), optional, () =>
|
|
4333
|
+
return this.makeCommonPrimitiveFilterSchema(import_zod3.z.union([
|
|
4334
|
+
import_zod3.z.string().datetime(),
|
|
4335
|
+
import_zod3.z.date()
|
|
4336
|
+
]), optional, () => import_zod3.z.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations)), withAggregations ? [
|
|
4313
4337
|
"_count",
|
|
4314
4338
|
"_min",
|
|
4315
4339
|
"_max"
|
|
4316
4340
|
] : void 0);
|
|
4317
4341
|
}
|
|
4318
4342
|
makeBooleanFilterSchema(optional, withAggregations) {
|
|
4319
|
-
const components = this.makeCommonPrimitiveFilterComponents(
|
|
4343
|
+
const components = this.makeCommonPrimitiveFilterComponents(import_zod3.z.boolean(), optional, () => import_zod3.z.lazy(() => this.makeBooleanFilterSchema(optional, withAggregations)), [
|
|
4320
4344
|
"equals",
|
|
4321
4345
|
"not"
|
|
4322
4346
|
], withAggregations ? [
|
|
@@ -4324,14 +4348,14 @@ var InputValidator = class {
|
|
|
4324
4348
|
"_min",
|
|
4325
4349
|
"_max"
|
|
4326
4350
|
] : void 0);
|
|
4327
|
-
return
|
|
4328
|
-
this.nullableIf(
|
|
4329
|
-
|
|
4351
|
+
return import_zod3.z.union([
|
|
4352
|
+
this.nullableIf(import_zod3.z.boolean(), optional),
|
|
4353
|
+
import_zod3.z.strictObject(components)
|
|
4330
4354
|
]);
|
|
4331
4355
|
}
|
|
4332
4356
|
makeBytesFilterSchema(optional, withAggregations) {
|
|
4333
|
-
const baseSchema =
|
|
4334
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () =>
|
|
4357
|
+
const baseSchema = import_zod3.z.instanceof(Uint8Array);
|
|
4358
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => import_zod3.z.instanceof(Uint8Array), [
|
|
4335
4359
|
"equals",
|
|
4336
4360
|
"in",
|
|
4337
4361
|
"notIn",
|
|
@@ -4341,9 +4365,9 @@ var InputValidator = class {
|
|
|
4341
4365
|
"_min",
|
|
4342
4366
|
"_max"
|
|
4343
4367
|
] : void 0);
|
|
4344
|
-
return
|
|
4368
|
+
return import_zod3.z.union([
|
|
4345
4369
|
this.nullableIf(baseSchema, optional),
|
|
4346
|
-
|
|
4370
|
+
import_zod3.z.strictObject(components)
|
|
4347
4371
|
]);
|
|
4348
4372
|
}
|
|
4349
4373
|
makeCommonPrimitiveFilterComponents(baseSchema, optional, makeThis, supportedOperators = void 0, withAggregations = void 0) {
|
|
@@ -4359,7 +4383,7 @@ var InputValidator = class {
|
|
|
4359
4383
|
gte: baseSchema.optional(),
|
|
4360
4384
|
not: makeThis().optional(),
|
|
4361
4385
|
...withAggregations?.includes("_count") ? {
|
|
4362
|
-
_count: this.makeNumberFilterSchema(
|
|
4386
|
+
_count: this.makeNumberFilterSchema(import_zod3.z.number().int(), false, false).optional()
|
|
4363
4387
|
} : {},
|
|
4364
4388
|
...withAggregations?.includes("_avg") ? {
|
|
4365
4389
|
_avg: commonAggSchema()
|
|
@@ -4384,13 +4408,13 @@ var InputValidator = class {
|
|
|
4384
4408
|
return result;
|
|
4385
4409
|
}
|
|
4386
4410
|
makeCommonPrimitiveFilterSchema(baseSchema, optional, makeThis, withAggregations = void 0) {
|
|
4387
|
-
return
|
|
4411
|
+
return import_zod3.z.union([
|
|
4388
4412
|
this.nullableIf(baseSchema, optional),
|
|
4389
|
-
|
|
4413
|
+
import_zod3.z.strictObject(this.makeCommonPrimitiveFilterComponents(baseSchema, optional, makeThis, void 0, withAggregations))
|
|
4390
4414
|
]);
|
|
4391
4415
|
}
|
|
4392
4416
|
makeNumberFilterSchema(baseSchema, optional, withAggregations) {
|
|
4393
|
-
return this.makeCommonPrimitiveFilterSchema(baseSchema, optional, () =>
|
|
4417
|
+
return this.makeCommonPrimitiveFilterSchema(baseSchema, optional, () => import_zod3.z.lazy(() => this.makeNumberFilterSchema(baseSchema, optional, withAggregations)), withAggregations ? [
|
|
4394
4418
|
"_count",
|
|
4395
4419
|
"_avg",
|
|
4396
4420
|
"_sum",
|
|
@@ -4399,17 +4423,17 @@ var InputValidator = class {
|
|
|
4399
4423
|
] : void 0);
|
|
4400
4424
|
}
|
|
4401
4425
|
makeStringFilterSchema(optional, withAggregations) {
|
|
4402
|
-
return
|
|
4403
|
-
this.nullableIf(
|
|
4404
|
-
|
|
4405
|
-
...this.makeCommonPrimitiveFilterComponents(
|
|
4426
|
+
return import_zod3.z.union([
|
|
4427
|
+
this.nullableIf(import_zod3.z.string(), optional),
|
|
4428
|
+
import_zod3.z.strictObject({
|
|
4429
|
+
...this.makeCommonPrimitiveFilterComponents(import_zod3.z.string(), optional, () => import_zod3.z.lazy(() => this.makeStringFilterSchema(optional, withAggregations)), void 0, withAggregations ? [
|
|
4406
4430
|
"_count",
|
|
4407
4431
|
"_min",
|
|
4408
4432
|
"_max"
|
|
4409
4433
|
] : void 0),
|
|
4410
|
-
startsWith:
|
|
4411
|
-
endsWith:
|
|
4412
|
-
contains:
|
|
4434
|
+
startsWith: import_zod3.z.string().optional(),
|
|
4435
|
+
endsWith: import_zod3.z.string().optional(),
|
|
4436
|
+
contains: import_zod3.z.string().optional(),
|
|
4413
4437
|
...this.providerSupportsCaseSensitivity ? {
|
|
4414
4438
|
mode: this.makeStringModeSchema().optional()
|
|
4415
4439
|
} : {}
|
|
@@ -4417,9 +4441,9 @@ var InputValidator = class {
|
|
|
4417
4441
|
]);
|
|
4418
4442
|
}
|
|
4419
4443
|
makeStringModeSchema() {
|
|
4420
|
-
return
|
|
4421
|
-
|
|
4422
|
-
|
|
4444
|
+
return import_zod3.z.union([
|
|
4445
|
+
import_zod3.z.literal("default"),
|
|
4446
|
+
import_zod3.z.literal("insensitive")
|
|
4423
4447
|
]);
|
|
4424
4448
|
}
|
|
4425
4449
|
makeSelectSchema(model) {
|
|
@@ -4430,26 +4454,26 @@ var InputValidator = class {
|
|
|
4430
4454
|
if (fieldDef.relation) {
|
|
4431
4455
|
fields[field] = this.makeRelationSelectIncludeSchema(fieldDef).optional();
|
|
4432
4456
|
} else {
|
|
4433
|
-
fields[field] =
|
|
4457
|
+
fields[field] = import_zod3.z.boolean().optional();
|
|
4434
4458
|
}
|
|
4435
4459
|
}
|
|
4436
4460
|
const _countSchema = this.makeCountSelectionSchema(modelDef);
|
|
4437
4461
|
if (_countSchema) {
|
|
4438
4462
|
fields["_count"] = _countSchema;
|
|
4439
4463
|
}
|
|
4440
|
-
return
|
|
4464
|
+
return import_zod3.z.strictObject(fields);
|
|
4441
4465
|
}
|
|
4442
4466
|
makeCountSelectionSchema(modelDef) {
|
|
4443
4467
|
const toManyRelations = Object.values(modelDef.fields).filter((def) => def.relation && def.array);
|
|
4444
4468
|
if (toManyRelations.length > 0) {
|
|
4445
|
-
return
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
select:
|
|
4469
|
+
return import_zod3.z.union([
|
|
4470
|
+
import_zod3.z.literal(true),
|
|
4471
|
+
import_zod3.z.strictObject({
|
|
4472
|
+
select: import_zod3.z.strictObject(toManyRelations.reduce((acc, fieldDef) => ({
|
|
4449
4473
|
...acc,
|
|
4450
|
-
[fieldDef.name]:
|
|
4451
|
-
|
|
4452
|
-
|
|
4474
|
+
[fieldDef.name]: import_zod3.z.union([
|
|
4475
|
+
import_zod3.z.boolean(),
|
|
4476
|
+
import_zod3.z.strictObject({
|
|
4453
4477
|
where: this.makeWhereSchema(fieldDef.type, false, false)
|
|
4454
4478
|
})
|
|
4455
4479
|
]).optional()
|
|
@@ -4461,17 +4485,17 @@ var InputValidator = class {
|
|
|
4461
4485
|
}
|
|
4462
4486
|
}
|
|
4463
4487
|
makeRelationSelectIncludeSchema(fieldDef) {
|
|
4464
|
-
let objSchema =
|
|
4488
|
+
let objSchema = import_zod3.z.strictObject({
|
|
4465
4489
|
...fieldDef.array || fieldDef.optional ? {
|
|
4466
4490
|
// to-many relations and optional to-one relations are filterable
|
|
4467
|
-
where:
|
|
4491
|
+
where: import_zod3.z.lazy(() => this.makeWhereSchema(fieldDef.type, false)).optional()
|
|
4468
4492
|
} : {},
|
|
4469
|
-
select:
|
|
4470
|
-
include:
|
|
4471
|
-
omit:
|
|
4493
|
+
select: import_zod3.z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional().nullable(),
|
|
4494
|
+
include: import_zod3.z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional().nullable(),
|
|
4495
|
+
omit: import_zod3.z.lazy(() => this.makeOmitSchema(fieldDef.type)).optional().nullable(),
|
|
4472
4496
|
...fieldDef.array ? {
|
|
4473
4497
|
// to-many relations can be ordered, skipped, taken, and cursor-located
|
|
4474
|
-
orderBy:
|
|
4498
|
+
orderBy: import_zod3.z.lazy(() => this.orArray(this.makeOrderBySchema(fieldDef.type, true, false), true)).optional(),
|
|
4475
4499
|
skip: this.makeSkipSchema().optional(),
|
|
4476
4500
|
take: this.makeTakeSchema().optional(),
|
|
4477
4501
|
cursor: this.makeCursorSchema(fieldDef.type).optional(),
|
|
@@ -4480,8 +4504,8 @@ var InputValidator = class {
|
|
|
4480
4504
|
});
|
|
4481
4505
|
objSchema = this.refineForSelectIncludeMutuallyExclusive(objSchema);
|
|
4482
4506
|
objSchema = this.refineForSelectOmitMutuallyExclusive(objSchema);
|
|
4483
|
-
return
|
|
4484
|
-
|
|
4507
|
+
return import_zod3.z.union([
|
|
4508
|
+
import_zod3.z.boolean(),
|
|
4485
4509
|
objSchema
|
|
4486
4510
|
]);
|
|
4487
4511
|
}
|
|
@@ -4491,10 +4515,14 @@ var InputValidator = class {
|
|
|
4491
4515
|
for (const field of Object.keys(modelDef.fields)) {
|
|
4492
4516
|
const fieldDef = requireField(this.schema, model, field);
|
|
4493
4517
|
if (!fieldDef.relation) {
|
|
4494
|
-
|
|
4518
|
+
if (this.options.allowQueryTimeOmitOverride !== false) {
|
|
4519
|
+
fields[field] = import_zod3.z.boolean().optional();
|
|
4520
|
+
} else {
|
|
4521
|
+
fields[field] = import_zod3.z.literal(true).optional();
|
|
4522
|
+
}
|
|
4495
4523
|
}
|
|
4496
4524
|
}
|
|
4497
|
-
return
|
|
4525
|
+
return import_zod3.z.strictObject(fields);
|
|
4498
4526
|
}
|
|
4499
4527
|
makeIncludeSchema(model) {
|
|
4500
4528
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -4509,20 +4537,20 @@ var InputValidator = class {
|
|
|
4509
4537
|
if (_countSchema) {
|
|
4510
4538
|
fields["_count"] = _countSchema;
|
|
4511
4539
|
}
|
|
4512
|
-
return
|
|
4540
|
+
return import_zod3.z.strictObject(fields);
|
|
4513
4541
|
}
|
|
4514
4542
|
makeOrderBySchema(model, withRelation, WithAggregation) {
|
|
4515
4543
|
const modelDef = requireModel(this.schema, model);
|
|
4516
4544
|
const fields = {};
|
|
4517
|
-
const sort =
|
|
4518
|
-
|
|
4519
|
-
|
|
4545
|
+
const sort = import_zod3.z.union([
|
|
4546
|
+
import_zod3.z.literal("asc"),
|
|
4547
|
+
import_zod3.z.literal("desc")
|
|
4520
4548
|
]);
|
|
4521
4549
|
for (const field of Object.keys(modelDef.fields)) {
|
|
4522
4550
|
const fieldDef = requireField(this.schema, model, field);
|
|
4523
4551
|
if (fieldDef.relation) {
|
|
4524
4552
|
if (withRelation) {
|
|
4525
|
-
fields[field] =
|
|
4553
|
+
fields[field] = import_zod3.z.lazy(() => {
|
|
4526
4554
|
let relationOrderBy = this.makeOrderBySchema(fieldDef.type, withRelation, WithAggregation);
|
|
4527
4555
|
if (fieldDef.array) {
|
|
4528
4556
|
relationOrderBy = relationOrderBy.extend({
|
|
@@ -4534,13 +4562,13 @@ var InputValidator = class {
|
|
|
4534
4562
|
}
|
|
4535
4563
|
} else {
|
|
4536
4564
|
if (fieldDef.optional) {
|
|
4537
|
-
fields[field] =
|
|
4565
|
+
fields[field] = import_zod3.z.union([
|
|
4538
4566
|
sort,
|
|
4539
|
-
|
|
4567
|
+
import_zod3.z.strictObject({
|
|
4540
4568
|
sort,
|
|
4541
|
-
nulls:
|
|
4542
|
-
|
|
4543
|
-
|
|
4569
|
+
nulls: import_zod3.z.union([
|
|
4570
|
+
import_zod3.z.literal("first"),
|
|
4571
|
+
import_zod3.z.literal("last")
|
|
4544
4572
|
])
|
|
4545
4573
|
})
|
|
4546
4574
|
]).optional();
|
|
@@ -4558,15 +4586,15 @@ var InputValidator = class {
|
|
|
4558
4586
|
"_max"
|
|
4559
4587
|
];
|
|
4560
4588
|
for (const agg of aggregationFields) {
|
|
4561
|
-
fields[agg] =
|
|
4589
|
+
fields[agg] = import_zod3.z.lazy(() => this.makeOrderBySchema(model, true, false).optional());
|
|
4562
4590
|
}
|
|
4563
4591
|
}
|
|
4564
|
-
return
|
|
4592
|
+
return import_zod3.z.strictObject(fields);
|
|
4565
4593
|
}
|
|
4566
4594
|
makeDistinctSchema(model) {
|
|
4567
4595
|
const modelDef = requireModel(this.schema, model);
|
|
4568
4596
|
const nonRelationFields = Object.keys(modelDef.fields).filter((field) => !modelDef.fields[field]?.relation);
|
|
4569
|
-
return this.orArray(
|
|
4597
|
+
return this.orArray(import_zod3.z.enum(nonRelationFields), true);
|
|
4570
4598
|
}
|
|
4571
4599
|
makeCursorSchema(model) {
|
|
4572
4600
|
return this.makeWhereSchema(model, true, true).optional();
|
|
@@ -4575,7 +4603,7 @@ var InputValidator = class {
|
|
|
4575
4603
|
// #region Create
|
|
4576
4604
|
makeCreateSchema(model) {
|
|
4577
4605
|
const dataSchema = this.makeCreateDataSchema(model, false);
|
|
4578
|
-
let schema =
|
|
4606
|
+
let schema = import_zod3.z.strictObject({
|
|
4579
4607
|
data: dataSchema,
|
|
4580
4608
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
4581
4609
|
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
@@ -4625,7 +4653,7 @@ var InputValidator = class {
|
|
|
4625
4653
|
excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
4626
4654
|
}
|
|
4627
4655
|
}
|
|
4628
|
-
let fieldSchema =
|
|
4656
|
+
let fieldSchema = import_zod3.z.lazy(() => this.makeRelationManipulationSchema(fieldDef, excludeFields, "create"));
|
|
4629
4657
|
if (fieldDef.optional || fieldDef.array) {
|
|
4630
4658
|
fieldSchema = fieldSchema.optional();
|
|
4631
4659
|
} else {
|
|
@@ -4651,9 +4679,9 @@ var InputValidator = class {
|
|
|
4651
4679
|
let fieldSchema = this.makePrimitiveSchema(fieldDef.type, fieldDef.attributes);
|
|
4652
4680
|
if (fieldDef.array) {
|
|
4653
4681
|
fieldSchema = addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
4654
|
-
fieldSchema =
|
|
4682
|
+
fieldSchema = import_zod3.z.union([
|
|
4655
4683
|
fieldSchema,
|
|
4656
|
-
|
|
4684
|
+
import_zod3.z.strictObject({
|
|
4657
4685
|
set: fieldSchema
|
|
4658
4686
|
})
|
|
4659
4687
|
]).optional();
|
|
@@ -4670,19 +4698,19 @@ var InputValidator = class {
|
|
|
4670
4698
|
}
|
|
4671
4699
|
}
|
|
4672
4700
|
});
|
|
4673
|
-
const uncheckedCreateSchema = this.extraValidationsEnabled ? addCustomValidation(
|
|
4674
|
-
const checkedCreateSchema = this.extraValidationsEnabled ? addCustomValidation(
|
|
4701
|
+
const uncheckedCreateSchema = this.extraValidationsEnabled ? addCustomValidation(import_zod3.z.strictObject(uncheckedVariantFields), modelDef.attributes) : import_zod3.z.strictObject(uncheckedVariantFields);
|
|
4702
|
+
const checkedCreateSchema = this.extraValidationsEnabled ? addCustomValidation(import_zod3.z.strictObject(checkedVariantFields), modelDef.attributes) : import_zod3.z.strictObject(checkedVariantFields);
|
|
4675
4703
|
if (!hasRelation) {
|
|
4676
4704
|
return this.orArray(uncheckedCreateSchema, canBeArray);
|
|
4677
4705
|
} else {
|
|
4678
|
-
return
|
|
4706
|
+
return import_zod3.z.union([
|
|
4679
4707
|
uncheckedCreateSchema,
|
|
4680
4708
|
checkedCreateSchema,
|
|
4681
4709
|
...canBeArray ? [
|
|
4682
|
-
|
|
4710
|
+
import_zod3.z.array(uncheckedCreateSchema)
|
|
4683
4711
|
] : [],
|
|
4684
4712
|
...canBeArray ? [
|
|
4685
|
-
|
|
4713
|
+
import_zod3.z.array(checkedCreateSchema)
|
|
4686
4714
|
] : []
|
|
4687
4715
|
]);
|
|
4688
4716
|
}
|
|
@@ -4710,11 +4738,11 @@ var InputValidator = class {
|
|
|
4710
4738
|
fields["disconnect"] = this.makeDisconnectDataSchema(fieldType, array).optional();
|
|
4711
4739
|
fields["delete"] = this.makeDeleteRelationDataSchema(fieldType, array, true).optional();
|
|
4712
4740
|
}
|
|
4713
|
-
fields["update"] = array ? this.orArray(
|
|
4741
|
+
fields["update"] = array ? this.orArray(import_zod3.z.strictObject({
|
|
4714
4742
|
where: this.makeWhereSchema(fieldType, true).optional(),
|
|
4715
4743
|
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
4716
|
-
}), true).optional() :
|
|
4717
|
-
|
|
4744
|
+
}), true).optional() : import_zod3.z.union([
|
|
4745
|
+
import_zod3.z.strictObject({
|
|
4718
4746
|
where: this.makeWhereSchema(fieldType, true).optional(),
|
|
4719
4747
|
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
4720
4748
|
}),
|
|
@@ -4724,21 +4752,21 @@ var InputValidator = class {
|
|
|
4724
4752
|
if (!fieldDef.array) {
|
|
4725
4753
|
upsertWhere = upsertWhere.optional();
|
|
4726
4754
|
}
|
|
4727
|
-
fields["upsert"] = this.orArray(
|
|
4755
|
+
fields["upsert"] = this.orArray(import_zod3.z.strictObject({
|
|
4728
4756
|
where: upsertWhere,
|
|
4729
4757
|
create: this.makeCreateDataSchema(fieldType, false, withoutFields),
|
|
4730
4758
|
update: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
4731
4759
|
}), true).optional();
|
|
4732
4760
|
if (array) {
|
|
4733
4761
|
fields["set"] = this.makeSetDataSchema(fieldType, true).optional();
|
|
4734
|
-
fields["updateMany"] = this.orArray(
|
|
4762
|
+
fields["updateMany"] = this.orArray(import_zod3.z.strictObject({
|
|
4735
4763
|
where: this.makeWhereSchema(fieldType, false, true),
|
|
4736
4764
|
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
4737
4765
|
}), true).optional();
|
|
4738
4766
|
fields["deleteMany"] = this.makeDeleteRelationDataSchema(fieldType, true, false).optional();
|
|
4739
4767
|
}
|
|
4740
4768
|
}
|
|
4741
|
-
return
|
|
4769
|
+
return import_zod3.z.strictObject(fields);
|
|
4742
4770
|
}
|
|
4743
4771
|
makeSetDataSchema(model, canBeArray) {
|
|
4744
4772
|
return this.orArray(this.makeWhereSchema(model, true), canBeArray);
|
|
@@ -4750,36 +4778,36 @@ var InputValidator = class {
|
|
|
4750
4778
|
if (canBeArray) {
|
|
4751
4779
|
return this.orArray(this.makeWhereSchema(model, true), canBeArray);
|
|
4752
4780
|
} else {
|
|
4753
|
-
return
|
|
4754
|
-
|
|
4781
|
+
return import_zod3.z.union([
|
|
4782
|
+
import_zod3.z.boolean(),
|
|
4755
4783
|
this.makeWhereSchema(model, false)
|
|
4756
4784
|
]);
|
|
4757
4785
|
}
|
|
4758
4786
|
}
|
|
4759
4787
|
makeDeleteRelationDataSchema(model, toManyRelation, uniqueFilter) {
|
|
4760
|
-
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter), true) :
|
|
4761
|
-
|
|
4788
|
+
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter), true) : import_zod3.z.union([
|
|
4789
|
+
import_zod3.z.boolean(),
|
|
4762
4790
|
this.makeWhereSchema(model, uniqueFilter)
|
|
4763
4791
|
]);
|
|
4764
4792
|
}
|
|
4765
4793
|
makeConnectOrCreateDataSchema(model, canBeArray, withoutFields) {
|
|
4766
4794
|
const whereSchema = this.makeWhereSchema(model, true);
|
|
4767
4795
|
const createSchema = this.makeCreateDataSchema(model, false, withoutFields);
|
|
4768
|
-
return this.orArray(
|
|
4796
|
+
return this.orArray(import_zod3.z.strictObject({
|
|
4769
4797
|
where: whereSchema,
|
|
4770
4798
|
create: createSchema
|
|
4771
4799
|
}), canBeArray);
|
|
4772
4800
|
}
|
|
4773
4801
|
makeCreateManyDataSchema(model, withoutFields) {
|
|
4774
|
-
return
|
|
4802
|
+
return import_zod3.z.strictObject({
|
|
4775
4803
|
data: this.makeCreateDataSchema(model, true, withoutFields, true),
|
|
4776
|
-
skipDuplicates:
|
|
4804
|
+
skipDuplicates: import_zod3.z.boolean().optional()
|
|
4777
4805
|
});
|
|
4778
4806
|
}
|
|
4779
4807
|
// #endregion
|
|
4780
4808
|
// #region Update
|
|
4781
4809
|
makeUpdateSchema(model) {
|
|
4782
|
-
let schema =
|
|
4810
|
+
let schema = import_zod3.z.strictObject({
|
|
4783
4811
|
where: this.makeWhereSchema(model, true),
|
|
4784
4812
|
data: this.makeUpdateDataSchema(model),
|
|
4785
4813
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
@@ -4791,10 +4819,10 @@ var InputValidator = class {
|
|
|
4791
4819
|
return schema;
|
|
4792
4820
|
}
|
|
4793
4821
|
makeUpdateManySchema(model) {
|
|
4794
|
-
return
|
|
4822
|
+
return import_zod3.z.strictObject({
|
|
4795
4823
|
where: this.makeWhereSchema(model, false).optional(),
|
|
4796
4824
|
data: this.makeUpdateDataSchema(model, [], true),
|
|
4797
|
-
limit:
|
|
4825
|
+
limit: import_zod3.z.number().int().nonnegative().optional()
|
|
4798
4826
|
});
|
|
4799
4827
|
}
|
|
4800
4828
|
makeUpdateManyAndReturnSchema(model) {
|
|
@@ -4807,7 +4835,7 @@ var InputValidator = class {
|
|
|
4807
4835
|
return schema;
|
|
4808
4836
|
}
|
|
4809
4837
|
makeUpsertSchema(model) {
|
|
4810
|
-
let schema =
|
|
4838
|
+
let schema = import_zod3.z.strictObject({
|
|
4811
4839
|
where: this.makeWhereSchema(model, true),
|
|
4812
4840
|
create: this.makeCreateDataSchema(model, false),
|
|
4813
4841
|
update: this.makeUpdateDataSchema(model),
|
|
@@ -4842,7 +4870,7 @@ var InputValidator = class {
|
|
|
4842
4870
|
excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
4843
4871
|
}
|
|
4844
4872
|
}
|
|
4845
|
-
let fieldSchema =
|
|
4873
|
+
let fieldSchema = import_zod3.z.lazy(() => this.makeRelationManipulationSchema(fieldDef, excludeFields, "update")).optional();
|
|
4846
4874
|
if (fieldDef.optional && !fieldDef.array) {
|
|
4847
4875
|
fieldSchema = fieldSchema.nullable();
|
|
4848
4876
|
}
|
|
@@ -4853,24 +4881,24 @@ var InputValidator = class {
|
|
|
4853
4881
|
} else {
|
|
4854
4882
|
let fieldSchema = this.makePrimitiveSchema(fieldDef.type, fieldDef.attributes);
|
|
4855
4883
|
if (this.isNumericField(fieldDef)) {
|
|
4856
|
-
fieldSchema =
|
|
4884
|
+
fieldSchema = import_zod3.z.union([
|
|
4857
4885
|
fieldSchema,
|
|
4858
|
-
|
|
4859
|
-
set: this.nullableIf(
|
|
4860
|
-
increment:
|
|
4861
|
-
decrement:
|
|
4862
|
-
multiply:
|
|
4863
|
-
divide:
|
|
4886
|
+
import_zod3.z.object({
|
|
4887
|
+
set: this.nullableIf(import_zod3.z.number().optional(), !!fieldDef.optional).optional(),
|
|
4888
|
+
increment: import_zod3.z.number().optional(),
|
|
4889
|
+
decrement: import_zod3.z.number().optional(),
|
|
4890
|
+
multiply: import_zod3.z.number().optional(),
|
|
4891
|
+
divide: import_zod3.z.number().optional()
|
|
4864
4892
|
}).refine((v) => Object.keys(v).length === 1, 'Only one of "set", "increment", "decrement", "multiply", or "divide" can be provided')
|
|
4865
4893
|
]);
|
|
4866
4894
|
}
|
|
4867
4895
|
if (fieldDef.array) {
|
|
4868
4896
|
const arraySchema = addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
4869
|
-
fieldSchema =
|
|
4897
|
+
fieldSchema = import_zod3.z.union([
|
|
4870
4898
|
arraySchema,
|
|
4871
|
-
|
|
4899
|
+
import_zod3.z.object({
|
|
4872
4900
|
set: arraySchema.optional(),
|
|
4873
|
-
push:
|
|
4901
|
+
push: import_zod3.z.union([
|
|
4874
4902
|
fieldSchema,
|
|
4875
4903
|
fieldSchema.array()
|
|
4876
4904
|
]).optional()
|
|
@@ -4887,12 +4915,12 @@ var InputValidator = class {
|
|
|
4887
4915
|
}
|
|
4888
4916
|
}
|
|
4889
4917
|
});
|
|
4890
|
-
const uncheckedUpdateSchema = this.extraValidationsEnabled ? addCustomValidation(
|
|
4891
|
-
const checkedUpdateSchema = this.extraValidationsEnabled ? addCustomValidation(
|
|
4918
|
+
const uncheckedUpdateSchema = this.extraValidationsEnabled ? addCustomValidation(import_zod3.z.strictObject(uncheckedVariantFields), modelDef.attributes) : import_zod3.z.strictObject(uncheckedVariantFields);
|
|
4919
|
+
const checkedUpdateSchema = this.extraValidationsEnabled ? addCustomValidation(import_zod3.z.strictObject(checkedVariantFields), modelDef.attributes) : import_zod3.z.strictObject(checkedVariantFields);
|
|
4892
4920
|
if (!hasRelation) {
|
|
4893
4921
|
return uncheckedUpdateSchema;
|
|
4894
4922
|
} else {
|
|
4895
|
-
return
|
|
4923
|
+
return import_zod3.z.union([
|
|
4896
4924
|
uncheckedUpdateSchema,
|
|
4897
4925
|
checkedUpdateSchema
|
|
4898
4926
|
]);
|
|
@@ -4901,25 +4929,26 @@ var InputValidator = class {
|
|
|
4901
4929
|
// #endregion
|
|
4902
4930
|
// #region Delete
|
|
4903
4931
|
makeDeleteSchema(model) {
|
|
4904
|
-
let schema =
|
|
4932
|
+
let schema = import_zod3.z.strictObject({
|
|
4905
4933
|
where: this.makeWhereSchema(model, true),
|
|
4906
4934
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
4907
|
-
include: this.makeIncludeSchema(model).optional().nullable()
|
|
4935
|
+
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
4936
|
+
omit: this.makeOmitSchema(model).optional().nullable()
|
|
4908
4937
|
});
|
|
4909
4938
|
schema = this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
4910
4939
|
schema = this.refineForSelectOmitMutuallyExclusive(schema);
|
|
4911
4940
|
return schema;
|
|
4912
4941
|
}
|
|
4913
4942
|
makeDeleteManySchema(model) {
|
|
4914
|
-
return
|
|
4943
|
+
return import_zod3.z.object({
|
|
4915
4944
|
where: this.makeWhereSchema(model, false).optional(),
|
|
4916
|
-
limit:
|
|
4945
|
+
limit: import_zod3.z.number().int().nonnegative().optional()
|
|
4917
4946
|
}).optional();
|
|
4918
4947
|
}
|
|
4919
4948
|
// #endregion
|
|
4920
4949
|
// #region Count
|
|
4921
4950
|
makeCountSchema(model) {
|
|
4922
|
-
return
|
|
4951
|
+
return import_zod3.z.object({
|
|
4923
4952
|
where: this.makeWhereSchema(model, false).optional(),
|
|
4924
4953
|
skip: this.makeSkipSchema().optional(),
|
|
4925
4954
|
take: this.makeTakeSchema().optional(),
|
|
@@ -4929,12 +4958,12 @@ var InputValidator = class {
|
|
|
4929
4958
|
}
|
|
4930
4959
|
makeCountAggregateInputSchema(model) {
|
|
4931
4960
|
const modelDef = requireModel(this.schema, model);
|
|
4932
|
-
return
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
_all:
|
|
4961
|
+
return import_zod3.z.union([
|
|
4962
|
+
import_zod3.z.literal(true),
|
|
4963
|
+
import_zod3.z.strictObject({
|
|
4964
|
+
_all: import_zod3.z.literal(true).optional(),
|
|
4936
4965
|
...Object.keys(modelDef.fields).reduce((acc, field) => {
|
|
4937
|
-
acc[field] =
|
|
4966
|
+
acc[field] = import_zod3.z.literal(true).optional();
|
|
4938
4967
|
return acc;
|
|
4939
4968
|
}, {})
|
|
4940
4969
|
})
|
|
@@ -4943,7 +4972,7 @@ var InputValidator = class {
|
|
|
4943
4972
|
// #endregion
|
|
4944
4973
|
// #region Aggregate
|
|
4945
4974
|
makeAggregateSchema(model) {
|
|
4946
|
-
return
|
|
4975
|
+
return import_zod3.z.object({
|
|
4947
4976
|
where: this.makeWhereSchema(model, false).optional(),
|
|
4948
4977
|
skip: this.makeSkipSchema().optional(),
|
|
4949
4978
|
take: this.makeTakeSchema().optional(),
|
|
@@ -4957,20 +4986,20 @@ var InputValidator = class {
|
|
|
4957
4986
|
}
|
|
4958
4987
|
makeSumAvgInputSchema(model) {
|
|
4959
4988
|
const modelDef = requireModel(this.schema, model);
|
|
4960
|
-
return
|
|
4989
|
+
return import_zod3.z.strictObject(Object.keys(modelDef.fields).reduce((acc, field) => {
|
|
4961
4990
|
const fieldDef = requireField(this.schema, model, field);
|
|
4962
4991
|
if (this.isNumericField(fieldDef)) {
|
|
4963
|
-
acc[field] =
|
|
4992
|
+
acc[field] = import_zod3.z.literal(true).optional();
|
|
4964
4993
|
}
|
|
4965
4994
|
return acc;
|
|
4966
4995
|
}, {}));
|
|
4967
4996
|
}
|
|
4968
4997
|
makeMinMaxInputSchema(model) {
|
|
4969
4998
|
const modelDef = requireModel(this.schema, model);
|
|
4970
|
-
return
|
|
4999
|
+
return import_zod3.z.strictObject(Object.keys(modelDef.fields).reduce((acc, field) => {
|
|
4971
5000
|
const fieldDef = requireField(this.schema, model, field);
|
|
4972
5001
|
if (!fieldDef.relation && !fieldDef.array) {
|
|
4973
|
-
acc[field] =
|
|
5002
|
+
acc[field] = import_zod3.z.literal(true).optional();
|
|
4974
5003
|
}
|
|
4975
5004
|
return acc;
|
|
4976
5005
|
}, {}));
|
|
@@ -4978,8 +5007,8 @@ var InputValidator = class {
|
|
|
4978
5007
|
makeGroupBySchema(model) {
|
|
4979
5008
|
const modelDef = requireModel(this.schema, model);
|
|
4980
5009
|
const nonRelationFields = Object.keys(modelDef.fields).filter((field) => !modelDef.fields[field]?.relation);
|
|
4981
|
-
const bySchema = nonRelationFields.length > 0 ? this.orArray(
|
|
4982
|
-
let schema =
|
|
5010
|
+
const bySchema = nonRelationFields.length > 0 ? this.orArray(import_zod3.z.enum(nonRelationFields), true) : import_zod3.z.never();
|
|
5011
|
+
let schema = import_zod3.z.strictObject({
|
|
4983
5012
|
where: this.makeWhereSchema(model, false).optional(),
|
|
4984
5013
|
orderBy: this.orArray(this.makeOrderBySchema(model, false, true), true).optional(),
|
|
4985
5014
|
by: bySchema,
|
|
@@ -5046,10 +5075,10 @@ var InputValidator = class {
|
|
|
5046
5075
|
// #endregion
|
|
5047
5076
|
// #region Helpers
|
|
5048
5077
|
makeSkipSchema() {
|
|
5049
|
-
return
|
|
5078
|
+
return import_zod3.z.number().int().nonnegative();
|
|
5050
5079
|
}
|
|
5051
5080
|
makeTakeSchema() {
|
|
5052
|
-
return
|
|
5081
|
+
return import_zod3.z.number().int();
|
|
5053
5082
|
}
|
|
5054
5083
|
refineForSelectIncludeMutuallyExclusive(schema) {
|
|
5055
5084
|
return schema.refine((value) => !(value["select"] && value["include"]), '"select" and "include" cannot be used together');
|
|
@@ -5061,9 +5090,9 @@ var InputValidator = class {
|
|
|
5061
5090
|
return nullable ? schema.nullable() : schema;
|
|
5062
5091
|
}
|
|
5063
5092
|
orArray(schema, canBeArray) {
|
|
5064
|
-
return canBeArray ?
|
|
5093
|
+
return canBeArray ? import_zod3.z.union([
|
|
5065
5094
|
schema,
|
|
5066
|
-
|
|
5095
|
+
import_zod3.z.array(schema)
|
|
5067
5096
|
]) : schema;
|
|
5068
5097
|
}
|
|
5069
5098
|
isNumericField(fieldDef) {
|
|
@@ -6826,6 +6855,9 @@ var ClientImpl = class _ClientImpl {
|
|
|
6826
6855
|
get $auth() {
|
|
6827
6856
|
return this.auth;
|
|
6828
6857
|
}
|
|
6858
|
+
$setOptions(options) {
|
|
6859
|
+
return new _ClientImpl(this.schema, options, this);
|
|
6860
|
+
}
|
|
6829
6861
|
$setInputValidation(enable) {
|
|
6830
6862
|
const newOptions = {
|
|
6831
6863
|
...this.options,
|
|
@@ -7305,7 +7337,8 @@ var DefaultOperationNodeVisitor = class extends import_kysely11.OperationNodeVis
|
|
|
7305
7337
|
// src/utils/schema-utils.ts
|
|
7306
7338
|
var schema_utils_exports = {};
|
|
7307
7339
|
__export(schema_utils_exports, {
|
|
7308
|
-
ExpressionVisitor: () => ExpressionVisitor
|
|
7340
|
+
ExpressionVisitor: () => ExpressionVisitor,
|
|
7341
|
+
MatchingExpressionVisitor: () => MatchingExpressionVisitor
|
|
7309
7342
|
});
|
|
7310
7343
|
var import_ts_pattern17 = require("ts-pattern");
|
|
7311
7344
|
var ExpressionVisitor = class {
|
|
@@ -7313,7 +7346,7 @@ var ExpressionVisitor = class {
|
|
|
7313
7346
|
__name(this, "ExpressionVisitor");
|
|
7314
7347
|
}
|
|
7315
7348
|
visit(expr) {
|
|
7316
|
-
(0, import_ts_pattern17.match)(expr).with({
|
|
7349
|
+
return (0, import_ts_pattern17.match)(expr).with({
|
|
7317
7350
|
kind: "literal"
|
|
7318
7351
|
}, (e) => this.visitLiteral(e)).with({
|
|
7319
7352
|
kind: "array"
|
|
@@ -7336,28 +7369,67 @@ var ExpressionVisitor = class {
|
|
|
7336
7369
|
visitLiteral(_e) {
|
|
7337
7370
|
}
|
|
7338
7371
|
visitArray(e) {
|
|
7339
|
-
|
|
7372
|
+
for (const item of e.items) {
|
|
7373
|
+
const result = this.visit(item);
|
|
7374
|
+
if (result?.abort) {
|
|
7375
|
+
return result;
|
|
7376
|
+
}
|
|
7377
|
+
}
|
|
7340
7378
|
}
|
|
7341
7379
|
visitField(_e) {
|
|
7342
7380
|
}
|
|
7343
7381
|
visitMember(e) {
|
|
7344
|
-
this.visit(e.receiver);
|
|
7382
|
+
return this.visit(e.receiver);
|
|
7345
7383
|
}
|
|
7346
7384
|
visitBinary(e) {
|
|
7347
|
-
this.visit(e.left);
|
|
7348
|
-
|
|
7385
|
+
const l = this.visit(e.left);
|
|
7386
|
+
if (l?.abort) {
|
|
7387
|
+
return l;
|
|
7388
|
+
} else {
|
|
7389
|
+
return this.visit(e.right);
|
|
7390
|
+
}
|
|
7349
7391
|
}
|
|
7350
7392
|
visitUnary(e) {
|
|
7351
|
-
this.visit(e.operand);
|
|
7393
|
+
return this.visit(e.operand);
|
|
7352
7394
|
}
|
|
7353
7395
|
visitCall(e) {
|
|
7354
|
-
e.args
|
|
7396
|
+
for (const arg of e.args ?? []) {
|
|
7397
|
+
const r = this.visit(arg);
|
|
7398
|
+
if (r?.abort) {
|
|
7399
|
+
return r;
|
|
7400
|
+
}
|
|
7401
|
+
}
|
|
7355
7402
|
}
|
|
7356
7403
|
visitThis(_e) {
|
|
7357
7404
|
}
|
|
7358
7405
|
visitNull(_e) {
|
|
7359
7406
|
}
|
|
7360
7407
|
};
|
|
7408
|
+
var MatchingExpressionVisitor = class extends ExpressionVisitor {
|
|
7409
|
+
static {
|
|
7410
|
+
__name(this, "MatchingExpressionVisitor");
|
|
7411
|
+
}
|
|
7412
|
+
predicate;
|
|
7413
|
+
found = false;
|
|
7414
|
+
constructor(predicate) {
|
|
7415
|
+
super(), this.predicate = predicate;
|
|
7416
|
+
}
|
|
7417
|
+
find(expr) {
|
|
7418
|
+
this.found = false;
|
|
7419
|
+
this.visit(expr);
|
|
7420
|
+
return this.found;
|
|
7421
|
+
}
|
|
7422
|
+
visit(expr) {
|
|
7423
|
+
if (this.predicate(expr)) {
|
|
7424
|
+
this.found = true;
|
|
7425
|
+
return {
|
|
7426
|
+
abort: true
|
|
7427
|
+
};
|
|
7428
|
+
} else {
|
|
7429
|
+
return super.visit(expr);
|
|
7430
|
+
}
|
|
7431
|
+
}
|
|
7432
|
+
};
|
|
7361
7433
|
// Annotate the CommonJS export names for ESM import in node:
|
|
7362
7434
|
0 && (module.exports = {
|
|
7363
7435
|
BaseCrudDialect,
|