@zenstackhq/orm 3.0.0-beta.26 → 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 +171 -161
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +171 -161
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -602,6 +602,7 @@ import { invariant as invariant3 } from "@zenstackhq/common-helpers";
|
|
|
602
602
|
import Decimal from "decimal.js";
|
|
603
603
|
import { sql as sql2 } from "kysely";
|
|
604
604
|
import { match as match3 } from "ts-pattern";
|
|
605
|
+
import z from "zod";
|
|
605
606
|
|
|
606
607
|
// src/client/crud/dialects/base-dialect.ts
|
|
607
608
|
import { enumerate, invariant as invariant2, isPlainObject } from "@zenstackhq/common-helpers";
|
|
@@ -1271,6 +1272,10 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
|
|
|
1271
1272
|
static {
|
|
1272
1273
|
__name(this, "PostgresCrudDialect");
|
|
1273
1274
|
}
|
|
1275
|
+
isoDateSchema = z.iso.datetime({
|
|
1276
|
+
local: true,
|
|
1277
|
+
offset: true
|
|
1278
|
+
});
|
|
1274
1279
|
constructor(schema, options) {
|
|
1275
1280
|
super(schema, options);
|
|
1276
1281
|
}
|
|
@@ -1319,7 +1324,12 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
|
|
|
1319
1324
|
}
|
|
1320
1325
|
transformOutputDate(value) {
|
|
1321
1326
|
if (typeof value === "string") {
|
|
1322
|
-
|
|
1327
|
+
if (this.isoDateSchema.safeParse(value).success) {
|
|
1328
|
+
const hasOffset = value.endsWith("Z") || /[+-]\d{2}:\d{2}$/.test(value);
|
|
1329
|
+
return new Date(hasOffset ? value : `${value}Z`);
|
|
1330
|
+
} else {
|
|
1331
|
+
return value;
|
|
1332
|
+
}
|
|
1323
1333
|
} else if (value instanceof Date && this.options.fixPostgresTimezone !== false) {
|
|
1324
1334
|
return new Date(value.getTime() - value.getTimezoneOffset() * 60 * 1e3);
|
|
1325
1335
|
} else {
|
|
@@ -3601,7 +3611,7 @@ import { enumerate as enumerate3, invariant as invariant7 } from "@zenstackhq/co
|
|
|
3601
3611
|
import Decimal4 from "decimal.js";
|
|
3602
3612
|
import stableStringify from "json-stable-stringify";
|
|
3603
3613
|
import { match as match13, P as P3 } from "ts-pattern";
|
|
3604
|
-
import { z as
|
|
3614
|
+
import { z as z3 } from "zod";
|
|
3605
3615
|
|
|
3606
3616
|
// src/utils/zod-utils.ts
|
|
3607
3617
|
import { fromError } from "zod-validation-error/v4";
|
|
@@ -3614,7 +3624,7 @@ __name(formatError, "formatError");
|
|
|
3614
3624
|
import { invariant as invariant6 } from "@zenstackhq/common-helpers";
|
|
3615
3625
|
import Decimal3 from "decimal.js";
|
|
3616
3626
|
import { match as match12, P as P2 } from "ts-pattern";
|
|
3617
|
-
import { z } from "zod";
|
|
3627
|
+
import { z as z2 } from "zod";
|
|
3618
3628
|
import { ZodIssueCode } from "zod/v3";
|
|
3619
3629
|
function getArgValue(expr) {
|
|
3620
3630
|
if (!expr || !schema_exports.ExpressionUtils.isLiteral(expr)) {
|
|
@@ -3723,13 +3733,13 @@ function addBigIntValidation(schema, attributes) {
|
|
|
3723
3733
|
__name(addBigIntValidation, "addBigIntValidation");
|
|
3724
3734
|
function addDecimalValidation(schema, attributes, addExtraValidation) {
|
|
3725
3735
|
let result = schema;
|
|
3726
|
-
if (schema instanceof
|
|
3736
|
+
if (schema instanceof z2.ZodString) {
|
|
3727
3737
|
result = schema.superRefine((v, ctx) => {
|
|
3728
3738
|
try {
|
|
3729
3739
|
new Decimal3(v);
|
|
3730
3740
|
} catch (err) {
|
|
3731
3741
|
ctx.addIssue({
|
|
3732
|
-
code:
|
|
3742
|
+
code: z2.ZodIssueCode.custom,
|
|
3733
3743
|
message: `Invalid decimal: ${err}`
|
|
3734
3744
|
});
|
|
3735
3745
|
}
|
|
@@ -3737,7 +3747,7 @@ function addDecimalValidation(schema, attributes, addExtraValidation) {
|
|
|
3737
3747
|
}
|
|
3738
3748
|
function refine(schema2, op, value) {
|
|
3739
3749
|
return schema2.superRefine((v, ctx) => {
|
|
3740
|
-
const base =
|
|
3750
|
+
const base = z2.number();
|
|
3741
3751
|
const { error } = base[op](value).safeParse(v.toNumber());
|
|
3742
3752
|
error?.issues.forEach((issue) => {
|
|
3743
3753
|
if (op === "gt" || op === "gte") {
|
|
@@ -3942,7 +3952,7 @@ function evalCall(data, expr) {
|
|
|
3942
3952
|
}
|
|
3943
3953
|
invariant6(typeof fieldArg === "string", `"${f}" first argument must be a string`);
|
|
3944
3954
|
const fn = match12(f).with("isEmail", () => "email").with("isUrl", () => "url").with("isDateTime", () => "datetime").exhaustive();
|
|
3945
|
-
return
|
|
3955
|
+
return z2.string()[fn]().safeParse(fieldArg).success;
|
|
3946
3956
|
}).with(P2.union("has", "hasEvery", "hasSome"), (f) => {
|
|
3947
3957
|
invariant6(expr.args?.[1], `${f} requires a search argument`);
|
|
3948
3958
|
if (fieldArg === void 0 || fieldArg === null) {
|
|
@@ -4080,7 +4090,7 @@ var InputValidator = class {
|
|
|
4080
4090
|
if (!options.unique) {
|
|
4081
4091
|
fields["skip"] = this.makeSkipSchema().optional();
|
|
4082
4092
|
if (options.findOne) {
|
|
4083
|
-
fields["take"] =
|
|
4093
|
+
fields["take"] = z3.literal(1).optional();
|
|
4084
4094
|
} else {
|
|
4085
4095
|
fields["take"] = this.makeTakeSchema().optional();
|
|
4086
4096
|
}
|
|
@@ -4088,7 +4098,7 @@ var InputValidator = class {
|
|
|
4088
4098
|
fields["cursor"] = this.makeCursorSchema(model).optional();
|
|
4089
4099
|
fields["distinct"] = this.makeDistinctSchema(model).optional();
|
|
4090
4100
|
}
|
|
4091
|
-
let result =
|
|
4101
|
+
let result = z3.strictObject(fields);
|
|
4092
4102
|
result = this.refineForSelectIncludeMutuallyExclusive(result);
|
|
4093
4103
|
result = this.refineForSelectOmitMutuallyExclusive(result);
|
|
4094
4104
|
if (!options.unique) {
|
|
@@ -4102,19 +4112,19 @@ var InputValidator = class {
|
|
|
4102
4112
|
} else if (this.schema.enums && type in this.schema.enums) {
|
|
4103
4113
|
return this.makeEnumSchema(type);
|
|
4104
4114
|
} else {
|
|
4105
|
-
return match13(type).with("String", () => this.extraValidationsEnabled ? addStringValidation(
|
|
4106
|
-
this.extraValidationsEnabled ? addNumberValidation(
|
|
4107
|
-
this.extraValidationsEnabled ? addBigIntValidation(
|
|
4115
|
+
return match13(type).with("String", () => this.extraValidationsEnabled ? addStringValidation(z3.string(), attributes) : z3.string()).with("Int", () => this.extraValidationsEnabled ? addNumberValidation(z3.number().int(), attributes) : z3.number().int()).with("Float", () => this.extraValidationsEnabled ? addNumberValidation(z3.number(), attributes) : z3.number()).with("Boolean", () => z3.boolean()).with("BigInt", () => z3.union([
|
|
4116
|
+
this.extraValidationsEnabled ? addNumberValidation(z3.number().int(), attributes) : z3.number().int(),
|
|
4117
|
+
this.extraValidationsEnabled ? addBigIntValidation(z3.bigint(), attributes) : z3.bigint()
|
|
4108
4118
|
])).with("Decimal", () => {
|
|
4109
|
-
return
|
|
4110
|
-
this.extraValidationsEnabled ? addNumberValidation(
|
|
4111
|
-
addDecimalValidation(
|
|
4112
|
-
addDecimalValidation(
|
|
4119
|
+
return z3.union([
|
|
4120
|
+
this.extraValidationsEnabled ? addNumberValidation(z3.number(), attributes) : z3.number(),
|
|
4121
|
+
addDecimalValidation(z3.instanceof(Decimal4), attributes, this.extraValidationsEnabled),
|
|
4122
|
+
addDecimalValidation(z3.string(), attributes, this.extraValidationsEnabled)
|
|
4113
4123
|
]);
|
|
4114
|
-
}).with("DateTime", () =>
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
])).with("Bytes", () =>
|
|
4124
|
+
}).with("DateTime", () => z3.union([
|
|
4125
|
+
z3.date(),
|
|
4126
|
+
z3.string().datetime()
|
|
4127
|
+
])).with("Bytes", () => z3.instanceof(Uint8Array)).otherwise(() => z3.unknown());
|
|
4118
4128
|
}
|
|
4119
4129
|
}
|
|
4120
4130
|
makeEnumSchema(type) {
|
|
@@ -4128,7 +4138,7 @@ var InputValidator = class {
|
|
|
4128
4138
|
}
|
|
4129
4139
|
const enumDef = getEnum(this.schema, type);
|
|
4130
4140
|
invariant7(enumDef, `Enum "${type}" not found in schema`);
|
|
4131
|
-
schema =
|
|
4141
|
+
schema = z3.enum(Object.keys(enumDef.values));
|
|
4132
4142
|
this.setSchemaCache(key, schema);
|
|
4133
4143
|
return schema;
|
|
4134
4144
|
}
|
|
@@ -4144,7 +4154,7 @@ var InputValidator = class {
|
|
|
4144
4154
|
}
|
|
4145
4155
|
const typeDef = getTypeDef(this.schema, type);
|
|
4146
4156
|
invariant7(typeDef, `Type definition "${type}" not found in schema`);
|
|
4147
|
-
schema =
|
|
4157
|
+
schema = z3.looseObject(Object.fromEntries(Object.entries(typeDef.fields).map(([field, def]) => {
|
|
4148
4158
|
let fieldSchema = this.makePrimitiveSchema(def.type);
|
|
4149
4159
|
if (def.array) {
|
|
4150
4160
|
fieldSchema = fieldSchema.array();
|
|
@@ -4170,21 +4180,21 @@ var InputValidator = class {
|
|
|
4170
4180
|
if (withoutRelationFields) {
|
|
4171
4181
|
continue;
|
|
4172
4182
|
}
|
|
4173
|
-
fieldSchema =
|
|
4183
|
+
fieldSchema = z3.lazy(() => this.makeWhereSchema(fieldDef.type, false).optional());
|
|
4174
4184
|
fieldSchema = this.nullableIf(fieldSchema, !fieldDef.array && !!fieldDef.optional);
|
|
4175
4185
|
if (fieldDef.array) {
|
|
4176
|
-
fieldSchema =
|
|
4186
|
+
fieldSchema = z3.union([
|
|
4177
4187
|
fieldSchema,
|
|
4178
|
-
|
|
4188
|
+
z3.strictObject({
|
|
4179
4189
|
some: fieldSchema.optional(),
|
|
4180
4190
|
every: fieldSchema.optional(),
|
|
4181
4191
|
none: fieldSchema.optional()
|
|
4182
4192
|
})
|
|
4183
4193
|
]);
|
|
4184
4194
|
} else {
|
|
4185
|
-
fieldSchema =
|
|
4195
|
+
fieldSchema = z3.union([
|
|
4186
4196
|
fieldSchema,
|
|
4187
|
-
|
|
4197
|
+
z3.strictObject({
|
|
4188
4198
|
is: fieldSchema.optional(),
|
|
4189
4199
|
isNot: fieldSchema.optional()
|
|
4190
4200
|
})
|
|
@@ -4210,7 +4220,7 @@ var InputValidator = class {
|
|
|
4210
4220
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
4211
4221
|
for (const uniqueField of uniqueFields) {
|
|
4212
4222
|
if ("defs" in uniqueField) {
|
|
4213
|
-
fields[uniqueField.name] =
|
|
4223
|
+
fields[uniqueField.name] = z3.object(Object.fromEntries(Object.entries(uniqueField.defs).map(([key, def]) => {
|
|
4214
4224
|
invariant7(!def.relation, "unique field cannot be a relation");
|
|
4215
4225
|
let fieldSchema;
|
|
4216
4226
|
const enumDef = getEnum(this.schema, def.type);
|
|
@@ -4218,7 +4228,7 @@ var InputValidator = class {
|
|
|
4218
4228
|
if (Object.keys(enumDef.values).length > 0) {
|
|
4219
4229
|
fieldSchema = this.makeEnumFilterSchema(enumDef, !!def.optional, false);
|
|
4220
4230
|
} else {
|
|
4221
|
-
fieldSchema =
|
|
4231
|
+
fieldSchema = z3.never();
|
|
4222
4232
|
}
|
|
4223
4233
|
} else {
|
|
4224
4234
|
fieldSchema = this.makePrimitiveFilterSchema(def.type, !!def.optional, false);
|
|
@@ -4231,11 +4241,11 @@ var InputValidator = class {
|
|
|
4231
4241
|
}
|
|
4232
4242
|
}
|
|
4233
4243
|
}
|
|
4234
|
-
fields["$expr"] =
|
|
4235
|
-
fields["AND"] = this.orArray(
|
|
4236
|
-
fields["OR"] =
|
|
4237
|
-
fields["NOT"] = this.orArray(
|
|
4238
|
-
const baseWhere =
|
|
4244
|
+
fields["$expr"] = z3.custom((v) => typeof v === "function").optional();
|
|
4245
|
+
fields["AND"] = this.orArray(z3.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
|
|
4246
|
+
fields["OR"] = z3.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)).array().optional();
|
|
4247
|
+
fields["NOT"] = this.orArray(z3.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
|
|
4248
|
+
const baseWhere = z3.strictObject(fields);
|
|
4239
4249
|
let result = baseWhere;
|
|
4240
4250
|
if (unique) {
|
|
4241
4251
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
@@ -4255,8 +4265,8 @@ var InputValidator = class {
|
|
|
4255
4265
|
return result;
|
|
4256
4266
|
}
|
|
4257
4267
|
makeEnumFilterSchema(enumDef, optional, withAggregations) {
|
|
4258
|
-
const baseSchema =
|
|
4259
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () =>
|
|
4268
|
+
const baseSchema = z3.enum(Object.keys(enumDef.values));
|
|
4269
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z3.lazy(() => this.makeEnumFilterSchema(enumDef, optional, withAggregations)), [
|
|
4260
4270
|
"equals",
|
|
4261
4271
|
"in",
|
|
4262
4272
|
"notIn",
|
|
@@ -4266,41 +4276,41 @@ var InputValidator = class {
|
|
|
4266
4276
|
"_min",
|
|
4267
4277
|
"_max"
|
|
4268
4278
|
] : void 0);
|
|
4269
|
-
return
|
|
4279
|
+
return z3.union([
|
|
4270
4280
|
this.nullableIf(baseSchema, optional),
|
|
4271
|
-
|
|
4281
|
+
z3.strictObject(components)
|
|
4272
4282
|
]);
|
|
4273
4283
|
}
|
|
4274
4284
|
makeArrayFilterSchema(type) {
|
|
4275
|
-
return
|
|
4285
|
+
return z3.strictObject({
|
|
4276
4286
|
equals: this.makePrimitiveSchema(type).array().optional(),
|
|
4277
4287
|
has: this.makePrimitiveSchema(type).optional(),
|
|
4278
4288
|
hasEvery: this.makePrimitiveSchema(type).array().optional(),
|
|
4279
4289
|
hasSome: this.makePrimitiveSchema(type).array().optional(),
|
|
4280
|
-
isEmpty:
|
|
4290
|
+
isEmpty: z3.boolean().optional()
|
|
4281
4291
|
});
|
|
4282
4292
|
}
|
|
4283
4293
|
makePrimitiveFilterSchema(type, optional, withAggregations) {
|
|
4284
4294
|
if (this.schema.typeDefs && type in this.schema.typeDefs) {
|
|
4285
4295
|
return this.makeTypeDefFilterSchema(type, optional);
|
|
4286
4296
|
}
|
|
4287
|
-
return match13(type).with("String", () => this.makeStringFilterSchema(optional, withAggregations)).with(P3.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", () =>
|
|
4297
|
+
return match13(type).with("String", () => this.makeStringFilterSchema(optional, withAggregations)).with(P3.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", () => z3.any()).with("Unsupported", () => z3.never()).exhaustive();
|
|
4288
4298
|
}
|
|
4289
4299
|
makeTypeDefFilterSchema(_type, _optional) {
|
|
4290
|
-
return
|
|
4300
|
+
return z3.never();
|
|
4291
4301
|
}
|
|
4292
4302
|
makeDateTimeFilterSchema(optional, withAggregations) {
|
|
4293
|
-
return this.makeCommonPrimitiveFilterSchema(
|
|
4294
|
-
|
|
4295
|
-
|
|
4296
|
-
]), optional, () =>
|
|
4303
|
+
return this.makeCommonPrimitiveFilterSchema(z3.union([
|
|
4304
|
+
z3.string().datetime(),
|
|
4305
|
+
z3.date()
|
|
4306
|
+
]), optional, () => z3.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations)), withAggregations ? [
|
|
4297
4307
|
"_count",
|
|
4298
4308
|
"_min",
|
|
4299
4309
|
"_max"
|
|
4300
4310
|
] : void 0);
|
|
4301
4311
|
}
|
|
4302
4312
|
makeBooleanFilterSchema(optional, withAggregations) {
|
|
4303
|
-
const components = this.makeCommonPrimitiveFilterComponents(
|
|
4313
|
+
const components = this.makeCommonPrimitiveFilterComponents(z3.boolean(), optional, () => z3.lazy(() => this.makeBooleanFilterSchema(optional, withAggregations)), [
|
|
4304
4314
|
"equals",
|
|
4305
4315
|
"not"
|
|
4306
4316
|
], withAggregations ? [
|
|
@@ -4308,14 +4318,14 @@ var InputValidator = class {
|
|
|
4308
4318
|
"_min",
|
|
4309
4319
|
"_max"
|
|
4310
4320
|
] : void 0);
|
|
4311
|
-
return
|
|
4312
|
-
this.nullableIf(
|
|
4313
|
-
|
|
4321
|
+
return z3.union([
|
|
4322
|
+
this.nullableIf(z3.boolean(), optional),
|
|
4323
|
+
z3.strictObject(components)
|
|
4314
4324
|
]);
|
|
4315
4325
|
}
|
|
4316
4326
|
makeBytesFilterSchema(optional, withAggregations) {
|
|
4317
|
-
const baseSchema =
|
|
4318
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () =>
|
|
4327
|
+
const baseSchema = z3.instanceof(Uint8Array);
|
|
4328
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z3.instanceof(Uint8Array), [
|
|
4319
4329
|
"equals",
|
|
4320
4330
|
"in",
|
|
4321
4331
|
"notIn",
|
|
@@ -4325,9 +4335,9 @@ var InputValidator = class {
|
|
|
4325
4335
|
"_min",
|
|
4326
4336
|
"_max"
|
|
4327
4337
|
] : void 0);
|
|
4328
|
-
return
|
|
4338
|
+
return z3.union([
|
|
4329
4339
|
this.nullableIf(baseSchema, optional),
|
|
4330
|
-
|
|
4340
|
+
z3.strictObject(components)
|
|
4331
4341
|
]);
|
|
4332
4342
|
}
|
|
4333
4343
|
makeCommonPrimitiveFilterComponents(baseSchema, optional, makeThis, supportedOperators = void 0, withAggregations = void 0) {
|
|
@@ -4343,7 +4353,7 @@ var InputValidator = class {
|
|
|
4343
4353
|
gte: baseSchema.optional(),
|
|
4344
4354
|
not: makeThis().optional(),
|
|
4345
4355
|
...withAggregations?.includes("_count") ? {
|
|
4346
|
-
_count: this.makeNumberFilterSchema(
|
|
4356
|
+
_count: this.makeNumberFilterSchema(z3.number().int(), false, false).optional()
|
|
4347
4357
|
} : {},
|
|
4348
4358
|
...withAggregations?.includes("_avg") ? {
|
|
4349
4359
|
_avg: commonAggSchema()
|
|
@@ -4368,13 +4378,13 @@ var InputValidator = class {
|
|
|
4368
4378
|
return result;
|
|
4369
4379
|
}
|
|
4370
4380
|
makeCommonPrimitiveFilterSchema(baseSchema, optional, makeThis, withAggregations = void 0) {
|
|
4371
|
-
return
|
|
4381
|
+
return z3.union([
|
|
4372
4382
|
this.nullableIf(baseSchema, optional),
|
|
4373
|
-
|
|
4383
|
+
z3.strictObject(this.makeCommonPrimitiveFilterComponents(baseSchema, optional, makeThis, void 0, withAggregations))
|
|
4374
4384
|
]);
|
|
4375
4385
|
}
|
|
4376
4386
|
makeNumberFilterSchema(baseSchema, optional, withAggregations) {
|
|
4377
|
-
return this.makeCommonPrimitiveFilterSchema(baseSchema, optional, () =>
|
|
4387
|
+
return this.makeCommonPrimitiveFilterSchema(baseSchema, optional, () => z3.lazy(() => this.makeNumberFilterSchema(baseSchema, optional, withAggregations)), withAggregations ? [
|
|
4378
4388
|
"_count",
|
|
4379
4389
|
"_avg",
|
|
4380
4390
|
"_sum",
|
|
@@ -4383,17 +4393,17 @@ var InputValidator = class {
|
|
|
4383
4393
|
] : void 0);
|
|
4384
4394
|
}
|
|
4385
4395
|
makeStringFilterSchema(optional, withAggregations) {
|
|
4386
|
-
return
|
|
4387
|
-
this.nullableIf(
|
|
4388
|
-
|
|
4389
|
-
...this.makeCommonPrimitiveFilterComponents(
|
|
4396
|
+
return z3.union([
|
|
4397
|
+
this.nullableIf(z3.string(), optional),
|
|
4398
|
+
z3.strictObject({
|
|
4399
|
+
...this.makeCommonPrimitiveFilterComponents(z3.string(), optional, () => z3.lazy(() => this.makeStringFilterSchema(optional, withAggregations)), void 0, withAggregations ? [
|
|
4390
4400
|
"_count",
|
|
4391
4401
|
"_min",
|
|
4392
4402
|
"_max"
|
|
4393
4403
|
] : void 0),
|
|
4394
|
-
startsWith:
|
|
4395
|
-
endsWith:
|
|
4396
|
-
contains:
|
|
4404
|
+
startsWith: z3.string().optional(),
|
|
4405
|
+
endsWith: z3.string().optional(),
|
|
4406
|
+
contains: z3.string().optional(),
|
|
4397
4407
|
...this.providerSupportsCaseSensitivity ? {
|
|
4398
4408
|
mode: this.makeStringModeSchema().optional()
|
|
4399
4409
|
} : {}
|
|
@@ -4401,9 +4411,9 @@ var InputValidator = class {
|
|
|
4401
4411
|
]);
|
|
4402
4412
|
}
|
|
4403
4413
|
makeStringModeSchema() {
|
|
4404
|
-
return
|
|
4405
|
-
|
|
4406
|
-
|
|
4414
|
+
return z3.union([
|
|
4415
|
+
z3.literal("default"),
|
|
4416
|
+
z3.literal("insensitive")
|
|
4407
4417
|
]);
|
|
4408
4418
|
}
|
|
4409
4419
|
makeSelectSchema(model) {
|
|
@@ -4414,26 +4424,26 @@ var InputValidator = class {
|
|
|
4414
4424
|
if (fieldDef.relation) {
|
|
4415
4425
|
fields[field] = this.makeRelationSelectIncludeSchema(fieldDef).optional();
|
|
4416
4426
|
} else {
|
|
4417
|
-
fields[field] =
|
|
4427
|
+
fields[field] = z3.boolean().optional();
|
|
4418
4428
|
}
|
|
4419
4429
|
}
|
|
4420
4430
|
const _countSchema = this.makeCountSelectionSchema(modelDef);
|
|
4421
4431
|
if (_countSchema) {
|
|
4422
4432
|
fields["_count"] = _countSchema;
|
|
4423
4433
|
}
|
|
4424
|
-
return
|
|
4434
|
+
return z3.strictObject(fields);
|
|
4425
4435
|
}
|
|
4426
4436
|
makeCountSelectionSchema(modelDef) {
|
|
4427
4437
|
const toManyRelations = Object.values(modelDef.fields).filter((def) => def.relation && def.array);
|
|
4428
4438
|
if (toManyRelations.length > 0) {
|
|
4429
|
-
return
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
select:
|
|
4439
|
+
return z3.union([
|
|
4440
|
+
z3.literal(true),
|
|
4441
|
+
z3.strictObject({
|
|
4442
|
+
select: z3.strictObject(toManyRelations.reduce((acc, fieldDef) => ({
|
|
4433
4443
|
...acc,
|
|
4434
|
-
[fieldDef.name]:
|
|
4435
|
-
|
|
4436
|
-
|
|
4444
|
+
[fieldDef.name]: z3.union([
|
|
4445
|
+
z3.boolean(),
|
|
4446
|
+
z3.strictObject({
|
|
4437
4447
|
where: this.makeWhereSchema(fieldDef.type, false, false)
|
|
4438
4448
|
})
|
|
4439
4449
|
]).optional()
|
|
@@ -4445,17 +4455,17 @@ var InputValidator = class {
|
|
|
4445
4455
|
}
|
|
4446
4456
|
}
|
|
4447
4457
|
makeRelationSelectIncludeSchema(fieldDef) {
|
|
4448
|
-
let objSchema =
|
|
4458
|
+
let objSchema = z3.strictObject({
|
|
4449
4459
|
...fieldDef.array || fieldDef.optional ? {
|
|
4450
4460
|
// to-many relations and optional to-one relations are filterable
|
|
4451
|
-
where:
|
|
4461
|
+
where: z3.lazy(() => this.makeWhereSchema(fieldDef.type, false)).optional()
|
|
4452
4462
|
} : {},
|
|
4453
|
-
select:
|
|
4454
|
-
include:
|
|
4455
|
-
omit:
|
|
4463
|
+
select: z3.lazy(() => this.makeSelectSchema(fieldDef.type)).optional().nullable(),
|
|
4464
|
+
include: z3.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional().nullable(),
|
|
4465
|
+
omit: z3.lazy(() => this.makeOmitSchema(fieldDef.type)).optional().nullable(),
|
|
4456
4466
|
...fieldDef.array ? {
|
|
4457
4467
|
// to-many relations can be ordered, skipped, taken, and cursor-located
|
|
4458
|
-
orderBy:
|
|
4468
|
+
orderBy: z3.lazy(() => this.orArray(this.makeOrderBySchema(fieldDef.type, true, false), true)).optional(),
|
|
4459
4469
|
skip: this.makeSkipSchema().optional(),
|
|
4460
4470
|
take: this.makeTakeSchema().optional(),
|
|
4461
4471
|
cursor: this.makeCursorSchema(fieldDef.type).optional(),
|
|
@@ -4464,8 +4474,8 @@ var InputValidator = class {
|
|
|
4464
4474
|
});
|
|
4465
4475
|
objSchema = this.refineForSelectIncludeMutuallyExclusive(objSchema);
|
|
4466
4476
|
objSchema = this.refineForSelectOmitMutuallyExclusive(objSchema);
|
|
4467
|
-
return
|
|
4468
|
-
|
|
4477
|
+
return z3.union([
|
|
4478
|
+
z3.boolean(),
|
|
4469
4479
|
objSchema
|
|
4470
4480
|
]);
|
|
4471
4481
|
}
|
|
@@ -4476,13 +4486,13 @@ var InputValidator = class {
|
|
|
4476
4486
|
const fieldDef = requireField(this.schema, model, field);
|
|
4477
4487
|
if (!fieldDef.relation) {
|
|
4478
4488
|
if (this.options.allowQueryTimeOmitOverride !== false) {
|
|
4479
|
-
fields[field] =
|
|
4489
|
+
fields[field] = z3.boolean().optional();
|
|
4480
4490
|
} else {
|
|
4481
|
-
fields[field] =
|
|
4491
|
+
fields[field] = z3.literal(true).optional();
|
|
4482
4492
|
}
|
|
4483
4493
|
}
|
|
4484
4494
|
}
|
|
4485
|
-
return
|
|
4495
|
+
return z3.strictObject(fields);
|
|
4486
4496
|
}
|
|
4487
4497
|
makeIncludeSchema(model) {
|
|
4488
4498
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -4497,20 +4507,20 @@ var InputValidator = class {
|
|
|
4497
4507
|
if (_countSchema) {
|
|
4498
4508
|
fields["_count"] = _countSchema;
|
|
4499
4509
|
}
|
|
4500
|
-
return
|
|
4510
|
+
return z3.strictObject(fields);
|
|
4501
4511
|
}
|
|
4502
4512
|
makeOrderBySchema(model, withRelation, WithAggregation) {
|
|
4503
4513
|
const modelDef = requireModel(this.schema, model);
|
|
4504
4514
|
const fields = {};
|
|
4505
|
-
const sort =
|
|
4506
|
-
|
|
4507
|
-
|
|
4515
|
+
const sort = z3.union([
|
|
4516
|
+
z3.literal("asc"),
|
|
4517
|
+
z3.literal("desc")
|
|
4508
4518
|
]);
|
|
4509
4519
|
for (const field of Object.keys(modelDef.fields)) {
|
|
4510
4520
|
const fieldDef = requireField(this.schema, model, field);
|
|
4511
4521
|
if (fieldDef.relation) {
|
|
4512
4522
|
if (withRelation) {
|
|
4513
|
-
fields[field] =
|
|
4523
|
+
fields[field] = z3.lazy(() => {
|
|
4514
4524
|
let relationOrderBy = this.makeOrderBySchema(fieldDef.type, withRelation, WithAggregation);
|
|
4515
4525
|
if (fieldDef.array) {
|
|
4516
4526
|
relationOrderBy = relationOrderBy.extend({
|
|
@@ -4522,13 +4532,13 @@ var InputValidator = class {
|
|
|
4522
4532
|
}
|
|
4523
4533
|
} else {
|
|
4524
4534
|
if (fieldDef.optional) {
|
|
4525
|
-
fields[field] =
|
|
4535
|
+
fields[field] = z3.union([
|
|
4526
4536
|
sort,
|
|
4527
|
-
|
|
4537
|
+
z3.strictObject({
|
|
4528
4538
|
sort,
|
|
4529
|
-
nulls:
|
|
4530
|
-
|
|
4531
|
-
|
|
4539
|
+
nulls: z3.union([
|
|
4540
|
+
z3.literal("first"),
|
|
4541
|
+
z3.literal("last")
|
|
4532
4542
|
])
|
|
4533
4543
|
})
|
|
4534
4544
|
]).optional();
|
|
@@ -4546,15 +4556,15 @@ var InputValidator = class {
|
|
|
4546
4556
|
"_max"
|
|
4547
4557
|
];
|
|
4548
4558
|
for (const agg of aggregationFields) {
|
|
4549
|
-
fields[agg] =
|
|
4559
|
+
fields[agg] = z3.lazy(() => this.makeOrderBySchema(model, true, false).optional());
|
|
4550
4560
|
}
|
|
4551
4561
|
}
|
|
4552
|
-
return
|
|
4562
|
+
return z3.strictObject(fields);
|
|
4553
4563
|
}
|
|
4554
4564
|
makeDistinctSchema(model) {
|
|
4555
4565
|
const modelDef = requireModel(this.schema, model);
|
|
4556
4566
|
const nonRelationFields = Object.keys(modelDef.fields).filter((field) => !modelDef.fields[field]?.relation);
|
|
4557
|
-
return this.orArray(
|
|
4567
|
+
return this.orArray(z3.enum(nonRelationFields), true);
|
|
4558
4568
|
}
|
|
4559
4569
|
makeCursorSchema(model) {
|
|
4560
4570
|
return this.makeWhereSchema(model, true, true).optional();
|
|
@@ -4563,7 +4573,7 @@ var InputValidator = class {
|
|
|
4563
4573
|
// #region Create
|
|
4564
4574
|
makeCreateSchema(model) {
|
|
4565
4575
|
const dataSchema = this.makeCreateDataSchema(model, false);
|
|
4566
|
-
let schema =
|
|
4576
|
+
let schema = z3.strictObject({
|
|
4567
4577
|
data: dataSchema,
|
|
4568
4578
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
4569
4579
|
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
@@ -4613,7 +4623,7 @@ var InputValidator = class {
|
|
|
4613
4623
|
excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
4614
4624
|
}
|
|
4615
4625
|
}
|
|
4616
|
-
let fieldSchema =
|
|
4626
|
+
let fieldSchema = z3.lazy(() => this.makeRelationManipulationSchema(fieldDef, excludeFields, "create"));
|
|
4617
4627
|
if (fieldDef.optional || fieldDef.array) {
|
|
4618
4628
|
fieldSchema = fieldSchema.optional();
|
|
4619
4629
|
} else {
|
|
@@ -4639,9 +4649,9 @@ var InputValidator = class {
|
|
|
4639
4649
|
let fieldSchema = this.makePrimitiveSchema(fieldDef.type, fieldDef.attributes);
|
|
4640
4650
|
if (fieldDef.array) {
|
|
4641
4651
|
fieldSchema = addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
4642
|
-
fieldSchema =
|
|
4652
|
+
fieldSchema = z3.union([
|
|
4643
4653
|
fieldSchema,
|
|
4644
|
-
|
|
4654
|
+
z3.strictObject({
|
|
4645
4655
|
set: fieldSchema
|
|
4646
4656
|
})
|
|
4647
4657
|
]).optional();
|
|
@@ -4658,19 +4668,19 @@ var InputValidator = class {
|
|
|
4658
4668
|
}
|
|
4659
4669
|
}
|
|
4660
4670
|
});
|
|
4661
|
-
const uncheckedCreateSchema = this.extraValidationsEnabled ? addCustomValidation(
|
|
4662
|
-
const checkedCreateSchema = this.extraValidationsEnabled ? addCustomValidation(
|
|
4671
|
+
const uncheckedCreateSchema = this.extraValidationsEnabled ? addCustomValidation(z3.strictObject(uncheckedVariantFields), modelDef.attributes) : z3.strictObject(uncheckedVariantFields);
|
|
4672
|
+
const checkedCreateSchema = this.extraValidationsEnabled ? addCustomValidation(z3.strictObject(checkedVariantFields), modelDef.attributes) : z3.strictObject(checkedVariantFields);
|
|
4663
4673
|
if (!hasRelation) {
|
|
4664
4674
|
return this.orArray(uncheckedCreateSchema, canBeArray);
|
|
4665
4675
|
} else {
|
|
4666
|
-
return
|
|
4676
|
+
return z3.union([
|
|
4667
4677
|
uncheckedCreateSchema,
|
|
4668
4678
|
checkedCreateSchema,
|
|
4669
4679
|
...canBeArray ? [
|
|
4670
|
-
|
|
4680
|
+
z3.array(uncheckedCreateSchema)
|
|
4671
4681
|
] : [],
|
|
4672
4682
|
...canBeArray ? [
|
|
4673
|
-
|
|
4683
|
+
z3.array(checkedCreateSchema)
|
|
4674
4684
|
] : []
|
|
4675
4685
|
]);
|
|
4676
4686
|
}
|
|
@@ -4698,11 +4708,11 @@ var InputValidator = class {
|
|
|
4698
4708
|
fields["disconnect"] = this.makeDisconnectDataSchema(fieldType, array).optional();
|
|
4699
4709
|
fields["delete"] = this.makeDeleteRelationDataSchema(fieldType, array, true).optional();
|
|
4700
4710
|
}
|
|
4701
|
-
fields["update"] = array ? this.orArray(
|
|
4711
|
+
fields["update"] = array ? this.orArray(z3.strictObject({
|
|
4702
4712
|
where: this.makeWhereSchema(fieldType, true).optional(),
|
|
4703
4713
|
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
4704
|
-
}), true).optional() :
|
|
4705
|
-
|
|
4714
|
+
}), true).optional() : z3.union([
|
|
4715
|
+
z3.strictObject({
|
|
4706
4716
|
where: this.makeWhereSchema(fieldType, true).optional(),
|
|
4707
4717
|
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
4708
4718
|
}),
|
|
@@ -4712,21 +4722,21 @@ var InputValidator = class {
|
|
|
4712
4722
|
if (!fieldDef.array) {
|
|
4713
4723
|
upsertWhere = upsertWhere.optional();
|
|
4714
4724
|
}
|
|
4715
|
-
fields["upsert"] = this.orArray(
|
|
4725
|
+
fields["upsert"] = this.orArray(z3.strictObject({
|
|
4716
4726
|
where: upsertWhere,
|
|
4717
4727
|
create: this.makeCreateDataSchema(fieldType, false, withoutFields),
|
|
4718
4728
|
update: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
4719
4729
|
}), true).optional();
|
|
4720
4730
|
if (array) {
|
|
4721
4731
|
fields["set"] = this.makeSetDataSchema(fieldType, true).optional();
|
|
4722
|
-
fields["updateMany"] = this.orArray(
|
|
4732
|
+
fields["updateMany"] = this.orArray(z3.strictObject({
|
|
4723
4733
|
where: this.makeWhereSchema(fieldType, false, true),
|
|
4724
4734
|
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
4725
4735
|
}), true).optional();
|
|
4726
4736
|
fields["deleteMany"] = this.makeDeleteRelationDataSchema(fieldType, true, false).optional();
|
|
4727
4737
|
}
|
|
4728
4738
|
}
|
|
4729
|
-
return
|
|
4739
|
+
return z3.strictObject(fields);
|
|
4730
4740
|
}
|
|
4731
4741
|
makeSetDataSchema(model, canBeArray) {
|
|
4732
4742
|
return this.orArray(this.makeWhereSchema(model, true), canBeArray);
|
|
@@ -4738,36 +4748,36 @@ var InputValidator = class {
|
|
|
4738
4748
|
if (canBeArray) {
|
|
4739
4749
|
return this.orArray(this.makeWhereSchema(model, true), canBeArray);
|
|
4740
4750
|
} else {
|
|
4741
|
-
return
|
|
4742
|
-
|
|
4751
|
+
return z3.union([
|
|
4752
|
+
z3.boolean(),
|
|
4743
4753
|
this.makeWhereSchema(model, false)
|
|
4744
4754
|
]);
|
|
4745
4755
|
}
|
|
4746
4756
|
}
|
|
4747
4757
|
makeDeleteRelationDataSchema(model, toManyRelation, uniqueFilter) {
|
|
4748
|
-
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter), true) :
|
|
4749
|
-
|
|
4758
|
+
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter), true) : z3.union([
|
|
4759
|
+
z3.boolean(),
|
|
4750
4760
|
this.makeWhereSchema(model, uniqueFilter)
|
|
4751
4761
|
]);
|
|
4752
4762
|
}
|
|
4753
4763
|
makeConnectOrCreateDataSchema(model, canBeArray, withoutFields) {
|
|
4754
4764
|
const whereSchema = this.makeWhereSchema(model, true);
|
|
4755
4765
|
const createSchema = this.makeCreateDataSchema(model, false, withoutFields);
|
|
4756
|
-
return this.orArray(
|
|
4766
|
+
return this.orArray(z3.strictObject({
|
|
4757
4767
|
where: whereSchema,
|
|
4758
4768
|
create: createSchema
|
|
4759
4769
|
}), canBeArray);
|
|
4760
4770
|
}
|
|
4761
4771
|
makeCreateManyDataSchema(model, withoutFields) {
|
|
4762
|
-
return
|
|
4772
|
+
return z3.strictObject({
|
|
4763
4773
|
data: this.makeCreateDataSchema(model, true, withoutFields, true),
|
|
4764
|
-
skipDuplicates:
|
|
4774
|
+
skipDuplicates: z3.boolean().optional()
|
|
4765
4775
|
});
|
|
4766
4776
|
}
|
|
4767
4777
|
// #endregion
|
|
4768
4778
|
// #region Update
|
|
4769
4779
|
makeUpdateSchema(model) {
|
|
4770
|
-
let schema =
|
|
4780
|
+
let schema = z3.strictObject({
|
|
4771
4781
|
where: this.makeWhereSchema(model, true),
|
|
4772
4782
|
data: this.makeUpdateDataSchema(model),
|
|
4773
4783
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
@@ -4779,10 +4789,10 @@ var InputValidator = class {
|
|
|
4779
4789
|
return schema;
|
|
4780
4790
|
}
|
|
4781
4791
|
makeUpdateManySchema(model) {
|
|
4782
|
-
return
|
|
4792
|
+
return z3.strictObject({
|
|
4783
4793
|
where: this.makeWhereSchema(model, false).optional(),
|
|
4784
4794
|
data: this.makeUpdateDataSchema(model, [], true),
|
|
4785
|
-
limit:
|
|
4795
|
+
limit: z3.number().int().nonnegative().optional()
|
|
4786
4796
|
});
|
|
4787
4797
|
}
|
|
4788
4798
|
makeUpdateManyAndReturnSchema(model) {
|
|
@@ -4795,7 +4805,7 @@ var InputValidator = class {
|
|
|
4795
4805
|
return schema;
|
|
4796
4806
|
}
|
|
4797
4807
|
makeUpsertSchema(model) {
|
|
4798
|
-
let schema =
|
|
4808
|
+
let schema = z3.strictObject({
|
|
4799
4809
|
where: this.makeWhereSchema(model, true),
|
|
4800
4810
|
create: this.makeCreateDataSchema(model, false),
|
|
4801
4811
|
update: this.makeUpdateDataSchema(model),
|
|
@@ -4830,7 +4840,7 @@ var InputValidator = class {
|
|
|
4830
4840
|
excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
4831
4841
|
}
|
|
4832
4842
|
}
|
|
4833
|
-
let fieldSchema =
|
|
4843
|
+
let fieldSchema = z3.lazy(() => this.makeRelationManipulationSchema(fieldDef, excludeFields, "update")).optional();
|
|
4834
4844
|
if (fieldDef.optional && !fieldDef.array) {
|
|
4835
4845
|
fieldSchema = fieldSchema.nullable();
|
|
4836
4846
|
}
|
|
@@ -4841,24 +4851,24 @@ var InputValidator = class {
|
|
|
4841
4851
|
} else {
|
|
4842
4852
|
let fieldSchema = this.makePrimitiveSchema(fieldDef.type, fieldDef.attributes);
|
|
4843
4853
|
if (this.isNumericField(fieldDef)) {
|
|
4844
|
-
fieldSchema =
|
|
4854
|
+
fieldSchema = z3.union([
|
|
4845
4855
|
fieldSchema,
|
|
4846
|
-
|
|
4847
|
-
set: this.nullableIf(
|
|
4848
|
-
increment:
|
|
4849
|
-
decrement:
|
|
4850
|
-
multiply:
|
|
4851
|
-
divide:
|
|
4856
|
+
z3.object({
|
|
4857
|
+
set: this.nullableIf(z3.number().optional(), !!fieldDef.optional).optional(),
|
|
4858
|
+
increment: z3.number().optional(),
|
|
4859
|
+
decrement: z3.number().optional(),
|
|
4860
|
+
multiply: z3.number().optional(),
|
|
4861
|
+
divide: z3.number().optional()
|
|
4852
4862
|
}).refine((v) => Object.keys(v).length === 1, 'Only one of "set", "increment", "decrement", "multiply", or "divide" can be provided')
|
|
4853
4863
|
]);
|
|
4854
4864
|
}
|
|
4855
4865
|
if (fieldDef.array) {
|
|
4856
4866
|
const arraySchema = addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
4857
|
-
fieldSchema =
|
|
4867
|
+
fieldSchema = z3.union([
|
|
4858
4868
|
arraySchema,
|
|
4859
|
-
|
|
4869
|
+
z3.object({
|
|
4860
4870
|
set: arraySchema.optional(),
|
|
4861
|
-
push:
|
|
4871
|
+
push: z3.union([
|
|
4862
4872
|
fieldSchema,
|
|
4863
4873
|
fieldSchema.array()
|
|
4864
4874
|
]).optional()
|
|
@@ -4875,12 +4885,12 @@ var InputValidator = class {
|
|
|
4875
4885
|
}
|
|
4876
4886
|
}
|
|
4877
4887
|
});
|
|
4878
|
-
const uncheckedUpdateSchema = this.extraValidationsEnabled ? addCustomValidation(
|
|
4879
|
-
const checkedUpdateSchema = this.extraValidationsEnabled ? addCustomValidation(
|
|
4888
|
+
const uncheckedUpdateSchema = this.extraValidationsEnabled ? addCustomValidation(z3.strictObject(uncheckedVariantFields), modelDef.attributes) : z3.strictObject(uncheckedVariantFields);
|
|
4889
|
+
const checkedUpdateSchema = this.extraValidationsEnabled ? addCustomValidation(z3.strictObject(checkedVariantFields), modelDef.attributes) : z3.strictObject(checkedVariantFields);
|
|
4880
4890
|
if (!hasRelation) {
|
|
4881
4891
|
return uncheckedUpdateSchema;
|
|
4882
4892
|
} else {
|
|
4883
|
-
return
|
|
4893
|
+
return z3.union([
|
|
4884
4894
|
uncheckedUpdateSchema,
|
|
4885
4895
|
checkedUpdateSchema
|
|
4886
4896
|
]);
|
|
@@ -4889,7 +4899,7 @@ var InputValidator = class {
|
|
|
4889
4899
|
// #endregion
|
|
4890
4900
|
// #region Delete
|
|
4891
4901
|
makeDeleteSchema(model) {
|
|
4892
|
-
let schema =
|
|
4902
|
+
let schema = z3.strictObject({
|
|
4893
4903
|
where: this.makeWhereSchema(model, true),
|
|
4894
4904
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
4895
4905
|
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
@@ -4900,15 +4910,15 @@ var InputValidator = class {
|
|
|
4900
4910
|
return schema;
|
|
4901
4911
|
}
|
|
4902
4912
|
makeDeleteManySchema(model) {
|
|
4903
|
-
return
|
|
4913
|
+
return z3.object({
|
|
4904
4914
|
where: this.makeWhereSchema(model, false).optional(),
|
|
4905
|
-
limit:
|
|
4915
|
+
limit: z3.number().int().nonnegative().optional()
|
|
4906
4916
|
}).optional();
|
|
4907
4917
|
}
|
|
4908
4918
|
// #endregion
|
|
4909
4919
|
// #region Count
|
|
4910
4920
|
makeCountSchema(model) {
|
|
4911
|
-
return
|
|
4921
|
+
return z3.object({
|
|
4912
4922
|
where: this.makeWhereSchema(model, false).optional(),
|
|
4913
4923
|
skip: this.makeSkipSchema().optional(),
|
|
4914
4924
|
take: this.makeTakeSchema().optional(),
|
|
@@ -4918,12 +4928,12 @@ var InputValidator = class {
|
|
|
4918
4928
|
}
|
|
4919
4929
|
makeCountAggregateInputSchema(model) {
|
|
4920
4930
|
const modelDef = requireModel(this.schema, model);
|
|
4921
|
-
return
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
_all:
|
|
4931
|
+
return z3.union([
|
|
4932
|
+
z3.literal(true),
|
|
4933
|
+
z3.strictObject({
|
|
4934
|
+
_all: z3.literal(true).optional(),
|
|
4925
4935
|
...Object.keys(modelDef.fields).reduce((acc, field) => {
|
|
4926
|
-
acc[field] =
|
|
4936
|
+
acc[field] = z3.literal(true).optional();
|
|
4927
4937
|
return acc;
|
|
4928
4938
|
}, {})
|
|
4929
4939
|
})
|
|
@@ -4932,7 +4942,7 @@ var InputValidator = class {
|
|
|
4932
4942
|
// #endregion
|
|
4933
4943
|
// #region Aggregate
|
|
4934
4944
|
makeAggregateSchema(model) {
|
|
4935
|
-
return
|
|
4945
|
+
return z3.object({
|
|
4936
4946
|
where: this.makeWhereSchema(model, false).optional(),
|
|
4937
4947
|
skip: this.makeSkipSchema().optional(),
|
|
4938
4948
|
take: this.makeTakeSchema().optional(),
|
|
@@ -4946,20 +4956,20 @@ var InputValidator = class {
|
|
|
4946
4956
|
}
|
|
4947
4957
|
makeSumAvgInputSchema(model) {
|
|
4948
4958
|
const modelDef = requireModel(this.schema, model);
|
|
4949
|
-
return
|
|
4959
|
+
return z3.strictObject(Object.keys(modelDef.fields).reduce((acc, field) => {
|
|
4950
4960
|
const fieldDef = requireField(this.schema, model, field);
|
|
4951
4961
|
if (this.isNumericField(fieldDef)) {
|
|
4952
|
-
acc[field] =
|
|
4962
|
+
acc[field] = z3.literal(true).optional();
|
|
4953
4963
|
}
|
|
4954
4964
|
return acc;
|
|
4955
4965
|
}, {}));
|
|
4956
4966
|
}
|
|
4957
4967
|
makeMinMaxInputSchema(model) {
|
|
4958
4968
|
const modelDef = requireModel(this.schema, model);
|
|
4959
|
-
return
|
|
4969
|
+
return z3.strictObject(Object.keys(modelDef.fields).reduce((acc, field) => {
|
|
4960
4970
|
const fieldDef = requireField(this.schema, model, field);
|
|
4961
4971
|
if (!fieldDef.relation && !fieldDef.array) {
|
|
4962
|
-
acc[field] =
|
|
4972
|
+
acc[field] = z3.literal(true).optional();
|
|
4963
4973
|
}
|
|
4964
4974
|
return acc;
|
|
4965
4975
|
}, {}));
|
|
@@ -4967,8 +4977,8 @@ var InputValidator = class {
|
|
|
4967
4977
|
makeGroupBySchema(model) {
|
|
4968
4978
|
const modelDef = requireModel(this.schema, model);
|
|
4969
4979
|
const nonRelationFields = Object.keys(modelDef.fields).filter((field) => !modelDef.fields[field]?.relation);
|
|
4970
|
-
const bySchema = nonRelationFields.length > 0 ? this.orArray(
|
|
4971
|
-
let schema =
|
|
4980
|
+
const bySchema = nonRelationFields.length > 0 ? this.orArray(z3.enum(nonRelationFields), true) : z3.never();
|
|
4981
|
+
let schema = z3.strictObject({
|
|
4972
4982
|
where: this.makeWhereSchema(model, false).optional(),
|
|
4973
4983
|
orderBy: this.orArray(this.makeOrderBySchema(model, false, true), true).optional(),
|
|
4974
4984
|
by: bySchema,
|
|
@@ -5035,10 +5045,10 @@ var InputValidator = class {
|
|
|
5035
5045
|
// #endregion
|
|
5036
5046
|
// #region Helpers
|
|
5037
5047
|
makeSkipSchema() {
|
|
5038
|
-
return
|
|
5048
|
+
return z3.number().int().nonnegative();
|
|
5039
5049
|
}
|
|
5040
5050
|
makeTakeSchema() {
|
|
5041
|
-
return
|
|
5051
|
+
return z3.number().int();
|
|
5042
5052
|
}
|
|
5043
5053
|
refineForSelectIncludeMutuallyExclusive(schema) {
|
|
5044
5054
|
return schema.refine((value) => !(value["select"] && value["include"]), '"select" and "include" cannot be used together');
|
|
@@ -5050,9 +5060,9 @@ var InputValidator = class {
|
|
|
5050
5060
|
return nullable ? schema.nullable() : schema;
|
|
5051
5061
|
}
|
|
5052
5062
|
orArray(schema, canBeArray) {
|
|
5053
|
-
return canBeArray ?
|
|
5063
|
+
return canBeArray ? z3.union([
|
|
5054
5064
|
schema,
|
|
5055
|
-
|
|
5065
|
+
z3.array(schema)
|
|
5056
5066
|
]) : schema;
|
|
5057
5067
|
}
|
|
5058
5068
|
isNumericField(fieldDef) {
|