@zenstackhq/orm 3.3.0-beta.3 → 3.3.0-beta.4

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 CHANGED
@@ -956,24 +956,31 @@ var BaseCrudDialect = class {
956
956
  if (_value === void 0) {
957
957
  continue;
958
958
  }
959
- const value = this.transformInput(_value, fieldType, !!fieldDef.array);
959
+ (0, import_common_helpers2.invariant)(fieldDef.array, "Field must be an array type to build array filter");
960
+ const value = this.transformInput(_value, fieldType, true);
961
+ let receiver = fieldRef;
962
+ if (isEnum(this.schema, fieldType)) {
963
+ receiver = this.eb.cast(fieldRef, import_kysely2.sql.raw("text[]"));
964
+ }
965
+ const buildArray = /* @__PURE__ */ __name((value2) => {
966
+ (0, import_common_helpers2.invariant)(Array.isArray(value2), "Array filter value must be an array");
967
+ return this.buildArrayValue(value2.map((v) => this.eb.val(v)), fieldType);
968
+ }, "buildArray");
960
969
  switch (key) {
961
970
  case "equals": {
962
- clauses.push(this.buildLiteralFilter(fieldRef, fieldType, this.eb.val(value)));
971
+ clauses.push(this.eb(receiver, "=", buildArray(value)));
963
972
  break;
964
973
  }
965
974
  case "has": {
966
- clauses.push(this.eb(fieldRef, "@>", this.eb.val([
967
- value
968
- ])));
975
+ clauses.push(this.buildArrayContains(receiver, this.eb.val(value)));
969
976
  break;
970
977
  }
971
978
  case "hasEvery": {
972
- clauses.push(this.eb(fieldRef, "@>", this.eb.val(value)));
979
+ clauses.push(this.buildArrayHasEvery(receiver, buildArray(value)));
973
980
  break;
974
981
  }
975
982
  case "hasSome": {
976
- clauses.push(this.eb(fieldRef, "&&", this.eb.val(value)));
983
+ clauses.push(this.buildArrayHasSome(receiver, buildArray(value)));
977
984
  break;
978
985
  }
979
986
  case "isEmpty": {
@@ -1809,8 +1816,17 @@ var MySqlCrudDialect = class extends LateralJoinDialectBase {
1809
1816
  array
1810
1817
  ]);
1811
1818
  }
1812
- buildArrayLiteralSQL(_values) {
1813
- throw new Error("MySQL does not support array literals");
1819
+ buildArrayValue(values, _elemType) {
1820
+ return new import_kysely3.ExpressionWrapper(import_kysely3.ValueListNode.create(values.map((v) => v.toOperationNode())));
1821
+ }
1822
+ buildArrayContains(_field, _value) {
1823
+ throw createNotSupportedError("MySQL does not support native array operations");
1824
+ }
1825
+ buildArrayHasEvery(_field, _values) {
1826
+ throw createNotSupportedError("MySQL does not support native array operations");
1827
+ }
1828
+ buildArrayHasSome(_field, _values) {
1829
+ throw createNotSupportedError("MySQL does not support native array operations");
1814
1830
  }
1815
1831
  buildJsonEqualityFilter(lhs, rhs) {
1816
1832
  return this.eb.and([
@@ -1848,21 +1864,6 @@ var MySqlCrudDialect = class extends LateralJoinDialectBase {
1848
1864
  buildJsonArrayExistsPredicate(receiver, buildFilter) {
1849
1865
  return this.eb.exists(this.eb.selectFrom(import_kysely3.sql`JSON_TABLE(${receiver}, '$[*]' COLUMNS(value JSON PATH '$'))`.as("$items")).select(this.eb.lit(1).as("$t")).where(buildFilter(this.eb.ref("$items.value"))));
1850
1866
  }
1851
- getFieldSqlType(fieldDef) {
1852
- if (fieldDef.relation) {
1853
- throw createInternalError("Cannot get SQL type of a relation field");
1854
- }
1855
- let result;
1856
- if (this.schema.enums?.[fieldDef.type]) {
1857
- result = "varchar(255)";
1858
- } else {
1859
- result = (0, import_ts_pattern3.match)(fieldDef.type).with("String", () => "varchar(255)").with("Boolean", () => "tinyint(1)").with("Int", () => "int").with("BigInt", () => "bigint").with("Float", () => "double").with("Decimal", () => "decimal").with("DateTime", () => "datetime").with("Bytes", () => "blob").with("Json", () => "json").otherwise(() => "text");
1860
- }
1861
- if (fieldDef.array) {
1862
- result = "json";
1863
- }
1864
- return result;
1865
- }
1866
1867
  getStringCasingBehavior() {
1867
1868
  return {
1868
1869
  supportsILike: false,
@@ -1902,21 +1903,36 @@ var import_decimal2 = __toESM(require("decimal.js"), 1);
1902
1903
  var import_kysely4 = require("kysely");
1903
1904
  var import_postgres_array = require("postgres-array");
1904
1905
  var import_ts_pattern4 = require("ts-pattern");
1905
- var import_zod = __toESM(require("zod"), 1);
1906
- var PostgresCrudDialect = class extends LateralJoinDialectBase {
1906
+ var PostgresCrudDialect = class _PostgresCrudDialect extends LateralJoinDialectBase {
1907
1907
  static {
1908
1908
  __name(this, "PostgresCrudDialect");
1909
1909
  }
1910
- isoDateSchema = import_zod.default.iso.datetime({
1911
- local: true,
1912
- offset: true
1913
- });
1910
+ static typeParserOverrideApplied = false;
1914
1911
  constructor(schema, options) {
1915
1912
  super(schema, options);
1913
+ this.overrideTypeParsers();
1916
1914
  }
1917
1915
  get provider() {
1918
1916
  return "postgresql";
1919
1917
  }
1918
+ overrideTypeParsers() {
1919
+ if (this.options.fixPostgresTimezone !== false && !_PostgresCrudDialect.typeParserOverrideApplied) {
1920
+ _PostgresCrudDialect.typeParserOverrideApplied = true;
1921
+ import("pg").then((pg) => {
1922
+ pg.types.setTypeParser(pg.types.builtins.TIMESTAMP, (value) => {
1923
+ if (typeof value !== "string") {
1924
+ return value;
1925
+ }
1926
+ if (!this.hasTimezoneOffset(value)) {
1927
+ value += "Z";
1928
+ }
1929
+ const result = new Date(value);
1930
+ return isNaN(result.getTime()) ? value : result;
1931
+ });
1932
+ }).catch(() => {
1933
+ });
1934
+ }
1935
+ }
1920
1936
  // #region capabilities
1921
1937
  get supportsUpdateWithLimit() {
1922
1938
  return false;
@@ -1961,9 +1977,6 @@ var PostgresCrudDialect = class extends LateralJoinDialectBase {
1961
1977
  } else if (Array.isArray(value)) {
1962
1978
  if (type === "Json" && !forArrayField) {
1963
1979
  return JSON.stringify(value);
1964
- }
1965
- if (isEnum(this.schema, type)) {
1966
- return this.eb.cast(import_kysely4.sql`ARRAY[${import_kysely4.sql.join(value.map((v) => this.transformInput(v, type, false)), import_kysely4.sql.raw(","))}]`, this.createSchemaQualifiedEnumType(type, true));
1967
1980
  } else {
1968
1981
  return value.map((v) => this.transformInput(v, type, false));
1969
1982
  }
@@ -1977,24 +1990,6 @@ var PostgresCrudDialect = class extends LateralJoinDialectBase {
1977
1990
  }).otherwise(() => value);
1978
1991
  }
1979
1992
  }
1980
- createSchemaQualifiedEnumType(type, array) {
1981
- let qualified = type;
1982
- const enumDef = getEnum(this.schema, type);
1983
- if (enumDef) {
1984
- const schemaAttr = enumDef.attributes?.find((attr) => attr.name === "@@schema");
1985
- if (schemaAttr) {
1986
- const mapArg = schemaAttr.args?.find((arg) => arg.name === "map");
1987
- if (mapArg && mapArg.value.kind === "literal") {
1988
- const schemaName = mapArg.value.value;
1989
- qualified = `"${schemaName}"."${type}"`;
1990
- }
1991
- } else {
1992
- const defaultSchema = this.schema.provider.defaultSchema ?? "public";
1993
- qualified = `"${defaultSchema}"."${type}"`;
1994
- }
1995
- }
1996
- return array ? import_kysely4.sql.raw(`${qualified}[]`) : import_kysely4.sql.raw(qualified);
1997
- }
1998
1993
  transformOutput(value, type, array) {
1999
1994
  if (value === null || value === void 0) {
2000
1995
  return value;
@@ -2017,18 +2012,16 @@ var PostgresCrudDialect = class extends LateralJoinDialectBase {
2017
2012
  }
2018
2013
  transformOutputDate(value) {
2019
2014
  if (typeof value === "string") {
2020
- if (this.isoDateSchema.safeParse(value).success) {
2021
- const hasOffset = value.endsWith("Z") || /[+-]\d{2}:\d{2}$/.test(value);
2022
- return new Date(hasOffset ? value : `${value}Z`);
2023
- } else {
2024
- return value;
2025
- }
2026
- } else if (value instanceof Date && this.options.fixPostgresTimezone !== false) {
2027
- return new Date(value.getTime() - value.getTimezoneOffset() * 60 * 1e3);
2015
+ const normalized = this.hasTimezoneOffset(value) ? value : `${value}Z`;
2016
+ const parsed = new Date(normalized);
2017
+ return Number.isNaN(parsed.getTime()) ? value : parsed;
2028
2018
  } else {
2029
2019
  return value;
2030
2020
  }
2031
2021
  }
2022
+ hasTimezoneOffset(value) {
2023
+ return value.endsWith("Z") || /[+-]\d{2}:\d{2}$/.test(value);
2024
+ }
2032
2025
  transformOutputBytes(value) {
2033
2026
  return Buffer.isBuffer(value) ? Uint8Array.from(value) : typeof value === "string" && value.startsWith("\\x") ? Uint8Array.from(Buffer.from(value.slice(2), "hex")) : value;
2034
2027
  }
@@ -2078,12 +2071,19 @@ var PostgresCrudDialect = class extends LateralJoinDialectBase {
2078
2071
  array
2079
2072
  ]);
2080
2073
  }
2081
- buildArrayLiteralSQL(values) {
2082
- if (values.length === 0) {
2083
- return import_kysely4.sql`{}`;
2084
- } else {
2085
- return import_kysely4.sql`ARRAY[${import_kysely4.sql.join(values.map((v) => import_kysely4.sql.val(v)), import_kysely4.sql.raw(","))}]`;
2086
- }
2074
+ buildArrayValue(values, elemType) {
2075
+ const arr = import_kysely4.sql`ARRAY[${import_kysely4.sql.join(values, import_kysely4.sql.raw(","))}]`;
2076
+ const mappedType = this.getSqlType(elemType);
2077
+ return this.eb.cast(arr, import_kysely4.sql`${import_kysely4.sql.raw(mappedType)}[]`);
2078
+ }
2079
+ buildArrayContains(field, value) {
2080
+ return this.eb(field, "@>", import_kysely4.sql`ARRAY[${value}]`);
2081
+ }
2082
+ buildArrayHasEvery(field, values) {
2083
+ return this.eb(field, "@>", values);
2084
+ }
2085
+ buildArrayHasSome(field, values) {
2086
+ return this.eb(field, "&&", values);
2087
2087
  }
2088
2088
  buildJsonPathSelection(receiver, path) {
2089
2089
  if (path) {
@@ -2114,20 +2114,12 @@ var PostgresCrudDialect = class extends LateralJoinDialectBase {
2114
2114
  receiver
2115
2115
  ]).as("$items")).select(this.eb.lit(1).as("$t")).where(buildFilter(this.eb.ref("$items.value"))));
2116
2116
  }
2117
- getFieldSqlType(fieldDef) {
2118
- if (fieldDef.relation) {
2119
- throw createInternalError("Cannot get SQL type of a relation field");
2120
- }
2121
- let result;
2122
- if (this.schema.enums?.[fieldDef.type]) {
2123
- result = "text";
2117
+ getSqlType(zmodelType) {
2118
+ if (isEnum(this.schema, zmodelType)) {
2119
+ return "text";
2124
2120
  } else {
2125
- result = (0, import_ts_pattern4.match)(fieldDef.type).with("String", () => "text").with("Boolean", () => "boolean").with("Int", () => "integer").with("BigInt", () => "bigint").with("Float", () => "double precision").with("Decimal", () => "decimal").with("DateTime", () => "timestamp").with("Bytes", () => "bytea").with("Json", () => "jsonb").otherwise(() => "text");
2121
+ return (0, import_ts_pattern4.match)(zmodelType).with("String", () => "text").with("Boolean", () => "boolean").with("Int", () => "integer").with("BigInt", () => "bigint").with("Float", () => "double precision").with("Decimal", () => "decimal").with("DateTime", () => "timestamp").with("Bytes", () => "bytea").with("Json", () => "jsonb").otherwise(() => "text");
2126
2122
  }
2127
- if (fieldDef.array) {
2128
- result += "[]";
2129
- }
2130
- return result;
2131
2123
  }
2132
2124
  getStringCasingBehavior() {
2133
2125
  return {
@@ -2149,7 +2141,11 @@ var PostgresCrudDialect = class extends LateralJoinDialectBase {
2149
2141
  }
2150
2142
  }
2151
2143
  const eb = (0, import_kysely4.expressionBuilder)();
2152
- return eb.selectFrom(import_kysely4.sql`(VALUES ${import_kysely4.sql.join(rows.map((row) => import_kysely4.sql`(${import_kysely4.sql.join(row.map((v) => import_kysely4.sql.val(v)))})`), import_kysely4.sql.raw(", "))})`.as("$values")).select(fields.map((f, i) => import_kysely4.sql`CAST(${import_kysely4.sql.ref(`$values.column${i + 1}`)} AS ${import_kysely4.sql.raw(this.getFieldSqlType(f))})`.as(f.name)));
2144
+ return eb.selectFrom(import_kysely4.sql`(VALUES ${import_kysely4.sql.join(rows.map((row) => import_kysely4.sql`(${import_kysely4.sql.join(row.map((v) => import_kysely4.sql.val(v)))})`), import_kysely4.sql.raw(", "))})`.as("$values")).select(fields.map((f, i) => {
2145
+ const mappedType = this.getSqlType(f.type);
2146
+ const castType = f.array ? import_kysely4.sql`${import_kysely4.sql.raw(mappedType)}[]` : import_kysely4.sql.raw(mappedType);
2147
+ return this.eb.cast(import_kysely4.sql.ref(`$values.column${i + 1}`), castType).as(f.name);
2148
+ }));
2153
2149
  }
2154
2150
  buildOrderByField(query, field, sort, nulls) {
2155
2151
  return query.orderBy(field, (ob) => {
@@ -2414,8 +2410,17 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
2414
2410
  array
2415
2411
  ]);
2416
2412
  }
2417
- buildArrayLiteralSQL(_values) {
2418
- throw new Error("SQLite does not support array literals");
2413
+ buildArrayValue(values, _elemType) {
2414
+ return new import_kysely5.ExpressionWrapper(import_kysely5.ValueListNode.create(values.map((v) => v.toOperationNode())));
2415
+ }
2416
+ buildArrayContains(_field, _value) {
2417
+ throw createNotSupportedError("SQLite does not support native array operations");
2418
+ }
2419
+ buildArrayHasEvery(_field, _values) {
2420
+ throw createNotSupportedError("SQLite does not support native array operations");
2421
+ }
2422
+ buildArrayHasSome(_field, _values) {
2423
+ throw createNotSupportedError("SQLite does not support native array operations");
2419
2424
  }
2420
2425
  castInt(expression) {
2421
2426
  return expression;
@@ -2429,18 +2434,6 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
2429
2434
  import_kysely5.sql.lit('"')
2430
2435
  ]);
2431
2436
  }
2432
- getFieldSqlType(fieldDef) {
2433
- if (fieldDef.relation) {
2434
- throw createInternalError("Cannot get SQL type of a relation field");
2435
- }
2436
- if (fieldDef.array) {
2437
- throw createInternalError("SQLite does not support scalar list type");
2438
- }
2439
- if (this.schema.enums?.[fieldDef.type]) {
2440
- return "text";
2441
- }
2442
- return (0, import_ts_pattern5.match)(fieldDef.type).with("String", () => "text").with("Boolean", () => "integer").with("Int", () => "integer").with("BigInt", () => "integer").with("Float", () => "real").with("Decimal", () => "decimal").with("DateTime", () => "numeric").with("Bytes", () => "blob").with("Json", () => "jsonb").otherwise(() => "text");
2443
- }
2444
2437
  getStringCasingBehavior() {
2445
2438
  return {
2446
2439
  supportsILike: false,
@@ -4598,7 +4591,7 @@ var UpdateOperationHandler = class extends BaseOperationHandler {
4598
4591
  var import_common_helpers9 = require("@zenstackhq/common-helpers");
4599
4592
  var import_decimal5 = __toESM(require("decimal.js"), 1);
4600
4593
  var import_ts_pattern14 = require("ts-pattern");
4601
- var import_zod3 = require("zod");
4594
+ var import_zod2 = require("zod");
4602
4595
 
4603
4596
  // src/utils/zod-utils.ts
4604
4597
  var import_v4 = require("zod-validation-error/v4");
@@ -4643,7 +4636,7 @@ __name(cache, "cache");
4643
4636
  var import_common_helpers8 = require("@zenstackhq/common-helpers");
4644
4637
  var import_decimal4 = __toESM(require("decimal.js"), 1);
4645
4638
  var import_ts_pattern13 = require("ts-pattern");
4646
- var import_zod2 = require("zod");
4639
+ var import_zod = require("zod");
4647
4640
  var import_v3 = require("zod/v3");
4648
4641
  function getArgValue(expr) {
4649
4642
  if (!expr || !schema_exports.ExpressionUtils.isLiteral(expr)) {
@@ -4752,13 +4745,13 @@ function addBigIntValidation(schema, attributes) {
4752
4745
  __name(addBigIntValidation, "addBigIntValidation");
4753
4746
  function addDecimalValidation(schema, attributes, addExtraValidation) {
4754
4747
  let result = schema;
4755
- if (schema instanceof import_zod2.z.ZodString) {
4748
+ if (schema instanceof import_zod.z.ZodString) {
4756
4749
  result = schema.superRefine((v, ctx) => {
4757
4750
  try {
4758
4751
  new import_decimal4.default(v);
4759
4752
  } catch (err) {
4760
4753
  ctx.addIssue({
4761
- code: import_zod2.z.ZodIssueCode.custom,
4754
+ code: import_zod.z.ZodIssueCode.custom,
4762
4755
  message: `Invalid decimal: ${err}`
4763
4756
  });
4764
4757
  }
@@ -4766,7 +4759,7 @@ function addDecimalValidation(schema, attributes, addExtraValidation) {
4766
4759
  }
4767
4760
  function refine(schema2, op, value) {
4768
4761
  return schema2.superRefine((v, ctx) => {
4769
- const base = import_zod2.z.number();
4762
+ const base = import_zod.z.number();
4770
4763
  const { error } = base[op](value).safeParse(v.toNumber());
4771
4764
  error?.issues.forEach((issue) => {
4772
4765
  if (op === "gt" || op === "gte") {
@@ -4975,7 +4968,7 @@ function evalCall(data, expr) {
4975
4968
  }
4976
4969
  (0, import_common_helpers8.invariant)(typeof fieldArg === "string", `"${f}" first argument must be a string`);
4977
4970
  const fn = (0, import_ts_pattern13.match)(f).with("isEmail", () => "email").with("isUrl", () => "url").with("isDateTime", () => "datetime").exhaustive();
4978
- return import_zod2.z.string()[fn]().safeParse(fieldArg).success;
4971
+ return import_zod.z.string()[fn]().safeParse(fieldArg).success;
4979
4972
  }).with(import_ts_pattern13.P.union("has", "hasEvery", "hasSome"), (f) => {
4980
4973
  (0, import_common_helpers8.invariant)(expr.args?.[1], `${f} requires a search argument`);
4981
4974
  if (fieldArg === void 0 || fieldArg === null) {
@@ -5174,8 +5167,8 @@ var InputValidator = class {
5174
5167
  const createSchema = "$create" in plugin.queryArgs && plugin.queryArgs["$create"] ? plugin.queryArgs["$create"] : void 0;
5175
5168
  const updateSchema = "$update" in plugin.queryArgs && plugin.queryArgs["$update"] ? plugin.queryArgs["$update"] : void 0;
5176
5169
  if (createSchema && updateSchema) {
5177
- (0, import_common_helpers9.invariant)(createSchema instanceof import_zod3.z.ZodObject, "Plugin extended query args schema must be a Zod object");
5178
- (0, import_common_helpers9.invariant)(updateSchema instanceof import_zod3.z.ZodObject, "Plugin extended query args schema must be a Zod object");
5170
+ (0, import_common_helpers9.invariant)(createSchema instanceof import_zod2.z.ZodObject, "Plugin extended query args schema must be a Zod object");
5171
+ (0, import_common_helpers9.invariant)(updateSchema instanceof import_zod2.z.ZodObject, "Plugin extended query args schema must be a Zod object");
5179
5172
  result = createSchema.extend(updateSchema.shape);
5180
5173
  } else if (createSchema) {
5181
5174
  result = createSchema;
@@ -5196,7 +5189,7 @@ var InputValidator = class {
5196
5189
  } else if ("$all" in plugin.queryArgs && plugin.queryArgs["$all"]) {
5197
5190
  result = plugin.queryArgs["$all"];
5198
5191
  }
5199
- (0, import_common_helpers9.invariant)(result === void 0 || result instanceof import_zod3.z.ZodObject, "Plugin extended query args schema must be a Zod object");
5192
+ (0, import_common_helpers9.invariant)(result === void 0 || result instanceof import_zod2.z.ZodObject, "Plugin extended query args schema must be a Zod object");
5200
5193
  return result;
5201
5194
  }
5202
5195
  // #endregion
@@ -5217,7 +5210,7 @@ var InputValidator = class {
5217
5210
  if (!unique) {
5218
5211
  fields["skip"] = this.makeSkipSchema().optional();
5219
5212
  if (findOne) {
5220
- fields["take"] = import_zod3.z.literal(1).optional();
5213
+ fields["take"] = import_zod2.z.literal(1).optional();
5221
5214
  } else {
5222
5215
  fields["take"] = this.makeTakeSchema().optional();
5223
5216
  }
@@ -5225,7 +5218,7 @@ var InputValidator = class {
5225
5218
  fields["cursor"] = this.makeCursorSchema(model).optional();
5226
5219
  fields["distinct"] = this.makeDistinctSchema(model).optional();
5227
5220
  }
5228
- const baseSchema = import_zod3.z.strictObject(fields);
5221
+ const baseSchema = import_zod2.z.strictObject(fields);
5229
5222
  let result = this.mergePluginArgsSchema(baseSchema, operation);
5230
5223
  result = this.refineForSelectIncludeMutuallyExclusive(result);
5231
5224
  result = this.refineForSelectOmitMutuallyExclusive(result);
@@ -5235,7 +5228,7 @@ var InputValidator = class {
5235
5228
  return result;
5236
5229
  }
5237
5230
  makeExistsSchema(model) {
5238
- const baseSchema = import_zod3.z.strictObject({
5231
+ const baseSchema = import_zod2.z.strictObject({
5239
5232
  where: this.makeWhereSchema(model, false).optional()
5240
5233
  });
5241
5234
  return this.mergePluginArgsSchema(baseSchema, "exists").optional();
@@ -5246,30 +5239,30 @@ var InputValidator = class {
5246
5239
  } else if (this.schema.enums && type in this.schema.enums) {
5247
5240
  return this.makeEnumSchema(type);
5248
5241
  } else {
5249
- return (0, import_ts_pattern14.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([
5250
- this.extraValidationsEnabled ? addNumberValidation(import_zod3.z.number().int(), attributes) : import_zod3.z.number().int(),
5251
- this.extraValidationsEnabled ? addBigIntValidation(import_zod3.z.bigint(), attributes) : import_zod3.z.bigint()
5242
+ return (0, import_ts_pattern14.match)(type).with("String", () => this.extraValidationsEnabled ? addStringValidation(import_zod2.z.string(), attributes) : import_zod2.z.string()).with("Int", () => this.extraValidationsEnabled ? addNumberValidation(import_zod2.z.number().int(), attributes) : import_zod2.z.number().int()).with("Float", () => this.extraValidationsEnabled ? addNumberValidation(import_zod2.z.number(), attributes) : import_zod2.z.number()).with("Boolean", () => import_zod2.z.boolean()).with("BigInt", () => import_zod2.z.union([
5243
+ this.extraValidationsEnabled ? addNumberValidation(import_zod2.z.number().int(), attributes) : import_zod2.z.number().int(),
5244
+ this.extraValidationsEnabled ? addBigIntValidation(import_zod2.z.bigint(), attributes) : import_zod2.z.bigint()
5252
5245
  ])).with("Decimal", () => {
5253
- return import_zod3.z.union([
5254
- this.extraValidationsEnabled ? addNumberValidation(import_zod3.z.number(), attributes) : import_zod3.z.number(),
5255
- addDecimalValidation(import_zod3.z.instanceof(import_decimal5.default), attributes, this.extraValidationsEnabled),
5256
- addDecimalValidation(import_zod3.z.string(), attributes, this.extraValidationsEnabled)
5246
+ return import_zod2.z.union([
5247
+ this.extraValidationsEnabled ? addNumberValidation(import_zod2.z.number(), attributes) : import_zod2.z.number(),
5248
+ addDecimalValidation(import_zod2.z.instanceof(import_decimal5.default), attributes, this.extraValidationsEnabled),
5249
+ addDecimalValidation(import_zod2.z.string(), attributes, this.extraValidationsEnabled)
5257
5250
  ]);
5258
- }).with("DateTime", () => import_zod3.z.union([
5259
- import_zod3.z.date(),
5260
- import_zod3.z.iso.datetime()
5261
- ])).with("Bytes", () => import_zod3.z.instanceof(Uint8Array)).with("Json", () => this.makeJsonValueSchema(false, false)).otherwise(() => import_zod3.z.unknown());
5251
+ }).with("DateTime", () => import_zod2.z.union([
5252
+ import_zod2.z.date(),
5253
+ import_zod2.z.iso.datetime()
5254
+ ])).with("Bytes", () => import_zod2.z.instanceof(Uint8Array)).with("Json", () => this.makeJsonValueSchema(false, false)).otherwise(() => import_zod2.z.unknown());
5262
5255
  }
5263
5256
  }
5264
5257
  makeEnumSchema(type) {
5265
5258
  const enumDef = getEnum(this.schema, type);
5266
5259
  (0, import_common_helpers9.invariant)(enumDef, `Enum "${type}" not found in schema`);
5267
- return import_zod3.z.enum(Object.keys(enumDef.values));
5260
+ return import_zod2.z.enum(Object.keys(enumDef.values));
5268
5261
  }
5269
5262
  makeTypeDefSchema(type) {
5270
5263
  const typeDef = getTypeDef(this.schema, type);
5271
5264
  (0, import_common_helpers9.invariant)(typeDef, `Type definition "${type}" not found in schema`);
5272
- const schema = import_zod3.z.looseObject(Object.fromEntries(Object.entries(typeDef.fields).map(([field, def]) => {
5265
+ const schema = import_zod2.z.looseObject(Object.fromEntries(Object.entries(typeDef.fields).map(([field, def]) => {
5273
5266
  let fieldSchema = this.makeScalarSchema(def.type);
5274
5267
  if (def.array) {
5275
5268
  fieldSchema = fieldSchema.array();
@@ -5282,7 +5275,7 @@ var InputValidator = class {
5282
5275
  fieldSchema
5283
5276
  ];
5284
5277
  })));
5285
- const finalSchema = import_zod3.z.any().superRefine((value, ctx) => {
5278
+ const finalSchema = import_zod2.z.any().superRefine((value, ctx) => {
5286
5279
  const parseResult = schema.safeParse(value);
5287
5280
  if (!parseResult.success) {
5288
5281
  parseResult.error.issues.forEach((issue) => ctx.addIssue(issue));
@@ -5300,21 +5293,21 @@ var InputValidator = class {
5300
5293
  if (withoutRelationFields) {
5301
5294
  continue;
5302
5295
  }
5303
- fieldSchema = import_zod3.z.lazy(() => this.makeWhereSchema(fieldDef.type, false).optional());
5296
+ fieldSchema = import_zod2.z.lazy(() => this.makeWhereSchema(fieldDef.type, false).optional());
5304
5297
  fieldSchema = this.nullableIf(fieldSchema, !fieldDef.array && !!fieldDef.optional);
5305
5298
  if (fieldDef.array) {
5306
- fieldSchema = import_zod3.z.union([
5299
+ fieldSchema = import_zod2.z.union([
5307
5300
  fieldSchema,
5308
- import_zod3.z.strictObject({
5301
+ import_zod2.z.strictObject({
5309
5302
  some: fieldSchema.optional(),
5310
5303
  every: fieldSchema.optional(),
5311
5304
  none: fieldSchema.optional()
5312
5305
  })
5313
5306
  ]);
5314
5307
  } else {
5315
- fieldSchema = import_zod3.z.union([
5308
+ fieldSchema = import_zod2.z.union([
5316
5309
  fieldSchema,
5317
- import_zod3.z.strictObject({
5310
+ import_zod2.z.strictObject({
5318
5311
  is: fieldSchema.optional(),
5319
5312
  isNot: fieldSchema.optional()
5320
5313
  })
@@ -5342,7 +5335,7 @@ var InputValidator = class {
5342
5335
  const uniqueFields = getUniqueFields(this.schema, model);
5343
5336
  for (const uniqueField of uniqueFields) {
5344
5337
  if ("defs" in uniqueField) {
5345
- fields[uniqueField.name] = import_zod3.z.object(Object.fromEntries(Object.entries(uniqueField.defs).map(([key, def]) => {
5338
+ fields[uniqueField.name] = import_zod2.z.object(Object.fromEntries(Object.entries(uniqueField.defs).map(([key, def]) => {
5346
5339
  (0, import_common_helpers9.invariant)(!def.relation, "unique field cannot be a relation");
5347
5340
  let fieldSchema;
5348
5341
  const enumDef = getEnum(this.schema, def.type);
@@ -5350,7 +5343,7 @@ var InputValidator = class {
5350
5343
  if (Object.keys(enumDef.values).length > 0) {
5351
5344
  fieldSchema = this.makeEnumFilterSchema(def.type, !!def.optional, false, false);
5352
5345
  } else {
5353
- fieldSchema = import_zod3.z.never();
5346
+ fieldSchema = import_zod2.z.never();
5354
5347
  }
5355
5348
  } else {
5356
5349
  fieldSchema = this.makePrimitiveFilterSchema(def.type, !!def.optional, false);
@@ -5363,13 +5356,13 @@ var InputValidator = class {
5363
5356
  }
5364
5357
  }
5365
5358
  }
5366
- fields["$expr"] = import_zod3.z.custom((v) => typeof v === "function", {
5359
+ fields["$expr"] = import_zod2.z.custom((v) => typeof v === "function", {
5367
5360
  error: '"$expr" must be a function'
5368
5361
  }).optional();
5369
- fields["AND"] = this.orArray(import_zod3.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
5370
- fields["OR"] = import_zod3.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)).array().optional();
5371
- fields["NOT"] = this.orArray(import_zod3.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
5372
- const baseWhere = import_zod3.z.strictObject(fields);
5362
+ fields["AND"] = this.orArray(import_zod2.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
5363
+ fields["OR"] = import_zod2.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)).array().optional();
5364
+ fields["NOT"] = this.orArray(import_zod2.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
5365
+ const baseWhere = import_zod2.z.strictObject(fields);
5373
5366
  let result = baseWhere;
5374
5367
  if (unique) {
5375
5368
  const uniqueFields = getUniqueFields(this.schema, model);
@@ -5408,26 +5401,26 @@ var InputValidator = class {
5408
5401
  }
5409
5402
  }
5410
5403
  }
5411
- candidates.push(import_zod3.z.strictObject(fieldSchemas));
5404
+ candidates.push(import_zod2.z.strictObject(fieldSchemas));
5412
5405
  }
5413
- const recursiveSchema = import_zod3.z.lazy(() => this.makeTypedJsonFilterSchema(type, optional, false)).optional();
5406
+ const recursiveSchema = import_zod2.z.lazy(() => this.makeTypedJsonFilterSchema(type, optional, false)).optional();
5414
5407
  if (array) {
5415
- candidates.push(import_zod3.z.strictObject({
5408
+ candidates.push(import_zod2.z.strictObject({
5416
5409
  some: recursiveSchema,
5417
5410
  every: recursiveSchema,
5418
5411
  none: recursiveSchema
5419
5412
  }));
5420
5413
  } else {
5421
- candidates.push(import_zod3.z.strictObject({
5414
+ candidates.push(import_zod2.z.strictObject({
5422
5415
  is: recursiveSchema,
5423
5416
  isNot: recursiveSchema
5424
5417
  }));
5425
5418
  }
5426
5419
  candidates.push(this.makeJsonFilterSchema(optional));
5427
5420
  if (optional) {
5428
- candidates.push(import_zod3.z.null());
5421
+ candidates.push(import_zod2.z.null());
5429
5422
  }
5430
- return import_zod3.z.union(candidates);
5423
+ return import_zod2.z.union(candidates);
5431
5424
  }
5432
5425
  isTypeDefType(type) {
5433
5426
  return this.schema.typeDefs && type in this.schema.typeDefs;
@@ -5435,11 +5428,11 @@ var InputValidator = class {
5435
5428
  makeEnumFilterSchema(enumName, optional, withAggregations, array) {
5436
5429
  const enumDef = getEnum(this.schema, enumName);
5437
5430
  (0, import_common_helpers9.invariant)(enumDef, `Enum "${enumName}" not found in schema`);
5438
- const baseSchema = import_zod3.z.enum(Object.keys(enumDef.values));
5431
+ const baseSchema = import_zod2.z.enum(Object.keys(enumDef.values));
5439
5432
  if (array) {
5440
5433
  return this.internalMakeArrayFilterSchema(baseSchema);
5441
5434
  }
5442
- const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => import_zod3.z.lazy(() => this.makeEnumFilterSchema(enumName, optional, withAggregations, array)), [
5435
+ const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => import_zod2.z.lazy(() => this.makeEnumFilterSchema(enumName, optional, withAggregations, array)), [
5443
5436
  "equals",
5444
5437
  "in",
5445
5438
  "notIn",
@@ -5449,65 +5442,65 @@ var InputValidator = class {
5449
5442
  "_min",
5450
5443
  "_max"
5451
5444
  ] : void 0);
5452
- return import_zod3.z.union([
5445
+ return import_zod2.z.union([
5453
5446
  this.nullableIf(baseSchema, optional),
5454
- import_zod3.z.strictObject(components)
5447
+ import_zod2.z.strictObject(components)
5455
5448
  ]);
5456
5449
  }
5457
5450
  makeArrayFilterSchema(type) {
5458
5451
  return this.internalMakeArrayFilterSchema(this.makeScalarSchema(type));
5459
5452
  }
5460
5453
  internalMakeArrayFilterSchema(elementSchema) {
5461
- return import_zod3.z.strictObject({
5454
+ return import_zod2.z.strictObject({
5462
5455
  equals: elementSchema.array().optional(),
5463
5456
  has: elementSchema.optional(),
5464
5457
  hasEvery: elementSchema.array().optional(),
5465
5458
  hasSome: elementSchema.array().optional(),
5466
- isEmpty: import_zod3.z.boolean().optional()
5459
+ isEmpty: import_zod2.z.boolean().optional()
5467
5460
  });
5468
5461
  }
5469
5462
  makePrimitiveFilterSchema(type, optional, withAggregations) {
5470
- return (0, import_ts_pattern14.match)(type).with("String", () => this.makeStringFilterSchema(optional, withAggregations)).with(import_ts_pattern14.P.union("Int", "Float", "Decimal", "BigInt"), (type2) => this.makeNumberFilterSchema(this.makeScalarSchema(type2), optional, withAggregations)).with("Boolean", () => this.makeBooleanFilterSchema(optional, withAggregations)).with("DateTime", () => this.makeDateTimeFilterSchema(optional, withAggregations)).with("Bytes", () => this.makeBytesFilterSchema(optional, withAggregations)).with("Json", () => this.makeJsonFilterSchema(optional)).with("Unsupported", () => import_zod3.z.never()).exhaustive();
5463
+ return (0, import_ts_pattern14.match)(type).with("String", () => this.makeStringFilterSchema(optional, withAggregations)).with(import_ts_pattern14.P.union("Int", "Float", "Decimal", "BigInt"), (type2) => this.makeNumberFilterSchema(this.makeScalarSchema(type2), optional, withAggregations)).with("Boolean", () => this.makeBooleanFilterSchema(optional, withAggregations)).with("DateTime", () => this.makeDateTimeFilterSchema(optional, withAggregations)).with("Bytes", () => this.makeBytesFilterSchema(optional, withAggregations)).with("Json", () => this.makeJsonFilterSchema(optional)).with("Unsupported", () => import_zod2.z.never()).exhaustive();
5471
5464
  }
5472
5465
  makeJsonValueSchema(nullable, forFilter) {
5473
5466
  const options = [
5474
- import_zod3.z.string(),
5475
- import_zod3.z.number(),
5476
- import_zod3.z.boolean(),
5477
- import_zod3.z.instanceof(JsonNullClass)
5467
+ import_zod2.z.string(),
5468
+ import_zod2.z.number(),
5469
+ import_zod2.z.boolean(),
5470
+ import_zod2.z.instanceof(JsonNullClass)
5478
5471
  ];
5479
5472
  if (forFilter) {
5480
- options.push(import_zod3.z.instanceof(DbNullClass));
5473
+ options.push(import_zod2.z.instanceof(DbNullClass));
5481
5474
  } else {
5482
5475
  if (nullable) {
5483
- options.push(import_zod3.z.instanceof(DbNullClass));
5476
+ options.push(import_zod2.z.instanceof(DbNullClass));
5484
5477
  }
5485
5478
  }
5486
5479
  if (forFilter) {
5487
- options.push(import_zod3.z.instanceof(AnyNullClass));
5480
+ options.push(import_zod2.z.instanceof(AnyNullClass));
5488
5481
  }
5489
- const schema = import_zod3.z.union([
5482
+ const schema = import_zod2.z.union([
5490
5483
  ...options,
5491
- import_zod3.z.lazy(() => import_zod3.z.union([
5484
+ import_zod2.z.lazy(() => import_zod2.z.union([
5492
5485
  this.makeJsonValueSchema(false, false),
5493
- import_zod3.z.null()
5486
+ import_zod2.z.null()
5494
5487
  ]).array()),
5495
- import_zod3.z.record(import_zod3.z.string(), import_zod3.z.lazy(() => import_zod3.z.union([
5488
+ import_zod2.z.record(import_zod2.z.string(), import_zod2.z.lazy(() => import_zod2.z.union([
5496
5489
  this.makeJsonValueSchema(false, false),
5497
- import_zod3.z.null()
5490
+ import_zod2.z.null()
5498
5491
  ])))
5499
5492
  ]);
5500
5493
  return this.nullableIf(schema, nullable);
5501
5494
  }
5502
5495
  makeJsonFilterSchema(optional) {
5503
5496
  const valueSchema = this.makeJsonValueSchema(optional, true);
5504
- return import_zod3.z.strictObject({
5505
- path: import_zod3.z.string().optional(),
5497
+ return import_zod2.z.strictObject({
5498
+ path: import_zod2.z.string().optional(),
5506
5499
  equals: valueSchema.optional(),
5507
5500
  not: valueSchema.optional(),
5508
- string_contains: import_zod3.z.string().optional(),
5509
- string_starts_with: import_zod3.z.string().optional(),
5510
- string_ends_with: import_zod3.z.string().optional(),
5501
+ string_contains: import_zod2.z.string().optional(),
5502
+ string_starts_with: import_zod2.z.string().optional(),
5503
+ string_ends_with: import_zod2.z.string().optional(),
5511
5504
  mode: this.makeStringModeSchema().optional(),
5512
5505
  array_contains: valueSchema.optional(),
5513
5506
  array_starts_with: valueSchema.optional(),
@@ -5515,17 +5508,17 @@ var InputValidator = class {
5515
5508
  });
5516
5509
  }
5517
5510
  makeDateTimeFilterSchema(optional, withAggregations) {
5518
- return this.makeCommonPrimitiveFilterSchema(import_zod3.z.union([
5519
- import_zod3.z.iso.datetime(),
5520
- import_zod3.z.date()
5521
- ]), optional, () => import_zod3.z.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations)), withAggregations ? [
5511
+ return this.makeCommonPrimitiveFilterSchema(import_zod2.z.union([
5512
+ import_zod2.z.iso.datetime(),
5513
+ import_zod2.z.date()
5514
+ ]), optional, () => import_zod2.z.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations)), withAggregations ? [
5522
5515
  "_count",
5523
5516
  "_min",
5524
5517
  "_max"
5525
5518
  ] : void 0);
5526
5519
  }
5527
5520
  makeBooleanFilterSchema(optional, withAggregations) {
5528
- const components = this.makeCommonPrimitiveFilterComponents(import_zod3.z.boolean(), optional, () => import_zod3.z.lazy(() => this.makeBooleanFilterSchema(optional, withAggregations)), [
5521
+ const components = this.makeCommonPrimitiveFilterComponents(import_zod2.z.boolean(), optional, () => import_zod2.z.lazy(() => this.makeBooleanFilterSchema(optional, withAggregations)), [
5529
5522
  "equals",
5530
5523
  "not"
5531
5524
  ], withAggregations ? [
@@ -5533,14 +5526,14 @@ var InputValidator = class {
5533
5526
  "_min",
5534
5527
  "_max"
5535
5528
  ] : void 0);
5536
- return import_zod3.z.union([
5537
- this.nullableIf(import_zod3.z.boolean(), optional),
5538
- import_zod3.z.strictObject(components)
5529
+ return import_zod2.z.union([
5530
+ this.nullableIf(import_zod2.z.boolean(), optional),
5531
+ import_zod2.z.strictObject(components)
5539
5532
  ]);
5540
5533
  }
5541
5534
  makeBytesFilterSchema(optional, withAggregations) {
5542
- const baseSchema = import_zod3.z.instanceof(Uint8Array);
5543
- const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => import_zod3.z.instanceof(Uint8Array), [
5535
+ const baseSchema = import_zod2.z.instanceof(Uint8Array);
5536
+ const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => import_zod2.z.instanceof(Uint8Array), [
5544
5537
  "equals",
5545
5538
  "in",
5546
5539
  "notIn",
@@ -5550,9 +5543,9 @@ var InputValidator = class {
5550
5543
  "_min",
5551
5544
  "_max"
5552
5545
  ] : void 0);
5553
- return import_zod3.z.union([
5546
+ return import_zod2.z.union([
5554
5547
  this.nullableIf(baseSchema, optional),
5555
- import_zod3.z.strictObject(components)
5548
+ import_zod2.z.strictObject(components)
5556
5549
  ]);
5557
5550
  }
5558
5551
  makeCommonPrimitiveFilterComponents(baseSchema, optional, makeThis, supportedOperators = void 0, withAggregations = void 0) {
@@ -5569,7 +5562,7 @@ var InputValidator = class {
5569
5562
  between: baseSchema.array().length(2).optional(),
5570
5563
  not: makeThis().optional(),
5571
5564
  ...withAggregations?.includes("_count") ? {
5572
- _count: this.makeNumberFilterSchema(import_zod3.z.number().int(), false, false).optional()
5565
+ _count: this.makeNumberFilterSchema(import_zod2.z.number().int(), false, false).optional()
5573
5566
  } : {},
5574
5567
  ...withAggregations?.includes("_avg") ? {
5575
5568
  _avg: commonAggSchema()
@@ -5594,13 +5587,13 @@ var InputValidator = class {
5594
5587
  return result;
5595
5588
  }
5596
5589
  makeCommonPrimitiveFilterSchema(baseSchema, optional, makeThis, withAggregations = void 0) {
5597
- return import_zod3.z.union([
5590
+ return import_zod2.z.union([
5598
5591
  this.nullableIf(baseSchema, optional),
5599
- import_zod3.z.strictObject(this.makeCommonPrimitiveFilterComponents(baseSchema, optional, makeThis, void 0, withAggregations))
5592
+ import_zod2.z.strictObject(this.makeCommonPrimitiveFilterComponents(baseSchema, optional, makeThis, void 0, withAggregations))
5600
5593
  ]);
5601
5594
  }
5602
5595
  makeNumberFilterSchema(baseSchema, optional, withAggregations) {
5603
- return this.makeCommonPrimitiveFilterSchema(baseSchema, optional, () => import_zod3.z.lazy(() => this.makeNumberFilterSchema(baseSchema, optional, withAggregations)), withAggregations ? [
5596
+ return this.makeCommonPrimitiveFilterSchema(baseSchema, optional, () => import_zod2.z.lazy(() => this.makeNumberFilterSchema(baseSchema, optional, withAggregations)), withAggregations ? [
5604
5597
  "_count",
5605
5598
  "_avg",
5606
5599
  "_sum",
@@ -5609,17 +5602,17 @@ var InputValidator = class {
5609
5602
  ] : void 0);
5610
5603
  }
5611
5604
  makeStringFilterSchema(optional, withAggregations) {
5612
- return import_zod3.z.union([
5613
- this.nullableIf(import_zod3.z.string(), optional),
5614
- import_zod3.z.strictObject({
5615
- ...this.makeCommonPrimitiveFilterComponents(import_zod3.z.string(), optional, () => import_zod3.z.lazy(() => this.makeStringFilterSchema(optional, withAggregations)), void 0, withAggregations ? [
5605
+ return import_zod2.z.union([
5606
+ this.nullableIf(import_zod2.z.string(), optional),
5607
+ import_zod2.z.strictObject({
5608
+ ...this.makeCommonPrimitiveFilterComponents(import_zod2.z.string(), optional, () => import_zod2.z.lazy(() => this.makeStringFilterSchema(optional, withAggregations)), void 0, withAggregations ? [
5616
5609
  "_count",
5617
5610
  "_min",
5618
5611
  "_max"
5619
5612
  ] : void 0),
5620
- startsWith: import_zod3.z.string().optional(),
5621
- endsWith: import_zod3.z.string().optional(),
5622
- contains: import_zod3.z.string().optional(),
5613
+ startsWith: import_zod2.z.string().optional(),
5614
+ endsWith: import_zod2.z.string().optional(),
5615
+ contains: import_zod2.z.string().optional(),
5623
5616
  ...this.providerSupportsCaseSensitivity ? {
5624
5617
  mode: this.makeStringModeSchema().optional()
5625
5618
  } : {}
@@ -5627,9 +5620,9 @@ var InputValidator = class {
5627
5620
  ]);
5628
5621
  }
5629
5622
  makeStringModeSchema() {
5630
- return import_zod3.z.union([
5631
- import_zod3.z.literal("default"),
5632
- import_zod3.z.literal("insensitive")
5623
+ return import_zod2.z.union([
5624
+ import_zod2.z.literal("default"),
5625
+ import_zod2.z.literal("insensitive")
5633
5626
  ]);
5634
5627
  }
5635
5628
  makeSelectSchema(model) {
@@ -5640,27 +5633,27 @@ var InputValidator = class {
5640
5633
  if (fieldDef.relation) {
5641
5634
  fields[field] = this.makeRelationSelectIncludeSchema(model, field).optional();
5642
5635
  } else {
5643
- fields[field] = import_zod3.z.boolean().optional();
5636
+ fields[field] = import_zod2.z.boolean().optional();
5644
5637
  }
5645
5638
  }
5646
5639
  const _countSchema = this.makeCountSelectionSchema(model);
5647
- if (!(_countSchema instanceof import_zod3.z.ZodNever)) {
5640
+ if (!(_countSchema instanceof import_zod2.z.ZodNever)) {
5648
5641
  fields["_count"] = _countSchema;
5649
5642
  }
5650
- return import_zod3.z.strictObject(fields);
5643
+ return import_zod2.z.strictObject(fields);
5651
5644
  }
5652
5645
  makeCountSelectionSchema(model) {
5653
5646
  const modelDef = requireModel(this.schema, model);
5654
5647
  const toManyRelations = Object.values(modelDef.fields).filter((def) => def.relation && def.array);
5655
5648
  if (toManyRelations.length > 0) {
5656
- return import_zod3.z.union([
5657
- import_zod3.z.literal(true),
5658
- import_zod3.z.strictObject({
5659
- select: import_zod3.z.strictObject(toManyRelations.reduce((acc, fieldDef) => ({
5649
+ return import_zod2.z.union([
5650
+ import_zod2.z.literal(true),
5651
+ import_zod2.z.strictObject({
5652
+ select: import_zod2.z.strictObject(toManyRelations.reduce((acc, fieldDef) => ({
5660
5653
  ...acc,
5661
- [fieldDef.name]: import_zod3.z.union([
5662
- import_zod3.z.boolean(),
5663
- import_zod3.z.strictObject({
5654
+ [fieldDef.name]: import_zod2.z.union([
5655
+ import_zod2.z.boolean(),
5656
+ import_zod2.z.strictObject({
5664
5657
  where: this.makeWhereSchema(fieldDef.type, false, false)
5665
5658
  })
5666
5659
  ]).optional()
@@ -5668,22 +5661,22 @@ var InputValidator = class {
5668
5661
  })
5669
5662
  ]).optional();
5670
5663
  } else {
5671
- return import_zod3.z.never();
5664
+ return import_zod2.z.never();
5672
5665
  }
5673
5666
  }
5674
5667
  makeRelationSelectIncludeSchema(model, field) {
5675
5668
  const fieldDef = requireField(this.schema, model, field);
5676
- let objSchema = import_zod3.z.strictObject({
5669
+ let objSchema = import_zod2.z.strictObject({
5677
5670
  ...fieldDef.array || fieldDef.optional ? {
5678
5671
  // to-many relations and optional to-one relations are filterable
5679
- where: import_zod3.z.lazy(() => this.makeWhereSchema(fieldDef.type, false)).optional()
5672
+ where: import_zod2.z.lazy(() => this.makeWhereSchema(fieldDef.type, false)).optional()
5680
5673
  } : {},
5681
- select: import_zod3.z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional().nullable(),
5682
- include: import_zod3.z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional().nullable(),
5683
- omit: import_zod3.z.lazy(() => this.makeOmitSchema(fieldDef.type)).optional().nullable(),
5674
+ select: import_zod2.z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional().nullable(),
5675
+ include: import_zod2.z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional().nullable(),
5676
+ omit: import_zod2.z.lazy(() => this.makeOmitSchema(fieldDef.type)).optional().nullable(),
5684
5677
  ...fieldDef.array ? {
5685
5678
  // to-many relations can be ordered, skipped, taken, and cursor-located
5686
- orderBy: import_zod3.z.lazy(() => this.orArray(this.makeOrderBySchema(fieldDef.type, true, false), true)).optional(),
5679
+ orderBy: import_zod2.z.lazy(() => this.orArray(this.makeOrderBySchema(fieldDef.type, true, false), true)).optional(),
5687
5680
  skip: this.makeSkipSchema().optional(),
5688
5681
  take: this.makeTakeSchema().optional(),
5689
5682
  cursor: this.makeCursorSchema(fieldDef.type).optional(),
@@ -5692,8 +5685,8 @@ var InputValidator = class {
5692
5685
  });
5693
5686
  objSchema = this.refineForSelectIncludeMutuallyExclusive(objSchema);
5694
5687
  objSchema = this.refineForSelectOmitMutuallyExclusive(objSchema);
5695
- return import_zod3.z.union([
5696
- import_zod3.z.boolean(),
5688
+ return import_zod2.z.union([
5689
+ import_zod2.z.boolean(),
5697
5690
  objSchema
5698
5691
  ]);
5699
5692
  }
@@ -5704,13 +5697,13 @@ var InputValidator = class {
5704
5697
  const fieldDef = requireField(this.schema, model, field);
5705
5698
  if (!fieldDef.relation) {
5706
5699
  if (this.options.allowQueryTimeOmitOverride !== false) {
5707
- fields[field] = import_zod3.z.boolean().optional();
5700
+ fields[field] = import_zod2.z.boolean().optional();
5708
5701
  } else {
5709
- fields[field] = import_zod3.z.literal(true).optional();
5702
+ fields[field] = import_zod2.z.literal(true).optional();
5710
5703
  }
5711
5704
  }
5712
5705
  }
5713
- return import_zod3.z.strictObject(fields);
5706
+ return import_zod2.z.strictObject(fields);
5714
5707
  }
5715
5708
  makeIncludeSchema(model) {
5716
5709
  const modelDef = requireModel(this.schema, model);
@@ -5722,23 +5715,23 @@ var InputValidator = class {
5722
5715
  }
5723
5716
  }
5724
5717
  const _countSchema = this.makeCountSelectionSchema(model);
5725
- if (!(_countSchema instanceof import_zod3.z.ZodNever)) {
5718
+ if (!(_countSchema instanceof import_zod2.z.ZodNever)) {
5726
5719
  fields["_count"] = _countSchema;
5727
5720
  }
5728
- return import_zod3.z.strictObject(fields);
5721
+ return import_zod2.z.strictObject(fields);
5729
5722
  }
5730
5723
  makeOrderBySchema(model, withRelation, WithAggregation) {
5731
5724
  const modelDef = requireModel(this.schema, model);
5732
5725
  const fields = {};
5733
- const sort = import_zod3.z.union([
5734
- import_zod3.z.literal("asc"),
5735
- import_zod3.z.literal("desc")
5726
+ const sort = import_zod2.z.union([
5727
+ import_zod2.z.literal("asc"),
5728
+ import_zod2.z.literal("desc")
5736
5729
  ]);
5737
5730
  for (const field of Object.keys(modelDef.fields)) {
5738
5731
  const fieldDef = requireField(this.schema, model, field);
5739
5732
  if (fieldDef.relation) {
5740
5733
  if (withRelation) {
5741
- fields[field] = import_zod3.z.lazy(() => {
5734
+ fields[field] = import_zod2.z.lazy(() => {
5742
5735
  let relationOrderBy = this.makeOrderBySchema(fieldDef.type, withRelation, WithAggregation);
5743
5736
  if (fieldDef.array) {
5744
5737
  relationOrderBy = relationOrderBy.extend({
@@ -5750,13 +5743,13 @@ var InputValidator = class {
5750
5743
  }
5751
5744
  } else {
5752
5745
  if (fieldDef.optional) {
5753
- fields[field] = import_zod3.z.union([
5746
+ fields[field] = import_zod2.z.union([
5754
5747
  sort,
5755
- import_zod3.z.strictObject({
5748
+ import_zod2.z.strictObject({
5756
5749
  sort,
5757
- nulls: import_zod3.z.union([
5758
- import_zod3.z.literal("first"),
5759
- import_zod3.z.literal("last")
5750
+ nulls: import_zod2.z.union([
5751
+ import_zod2.z.literal("first"),
5752
+ import_zod2.z.literal("last")
5760
5753
  ])
5761
5754
  })
5762
5755
  ]).optional();
@@ -5774,15 +5767,15 @@ var InputValidator = class {
5774
5767
  "_max"
5775
5768
  ];
5776
5769
  for (const agg of aggregationFields) {
5777
- fields[agg] = import_zod3.z.lazy(() => this.makeOrderBySchema(model, true, false).optional());
5770
+ fields[agg] = import_zod2.z.lazy(() => this.makeOrderBySchema(model, true, false).optional());
5778
5771
  }
5779
5772
  }
5780
- return import_zod3.z.strictObject(fields);
5773
+ return import_zod2.z.strictObject(fields);
5781
5774
  }
5782
5775
  makeDistinctSchema(model) {
5783
5776
  const modelDef = requireModel(this.schema, model);
5784
5777
  const nonRelationFields = Object.keys(modelDef.fields).filter((field) => !modelDef.fields[field]?.relation);
5785
- return this.orArray(import_zod3.z.enum(nonRelationFields), true);
5778
+ return this.orArray(import_zod2.z.enum(nonRelationFields), true);
5786
5779
  }
5787
5780
  makeCursorSchema(model) {
5788
5781
  return this.makeWhereSchema(model, true, true).optional();
@@ -5791,7 +5784,7 @@ var InputValidator = class {
5791
5784
  // #region Create
5792
5785
  makeCreateSchema(model) {
5793
5786
  const dataSchema = this.makeCreateDataSchema(model, false);
5794
- const baseSchema = import_zod3.z.strictObject({
5787
+ const baseSchema = import_zod2.z.strictObject({
5795
5788
  data: dataSchema,
5796
5789
  select: this.makeSelectSchema(model).optional().nullable(),
5797
5790
  include: this.makeIncludeSchema(model).optional().nullable(),
@@ -5843,7 +5836,7 @@ var InputValidator = class {
5843
5836
  excludeFields.push(...oppositeFieldDef.relation.fields);
5844
5837
  }
5845
5838
  }
5846
- let fieldSchema = import_zod3.z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "create"));
5839
+ let fieldSchema = import_zod2.z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "create"));
5847
5840
  if (fieldDef.optional || fieldDef.array) {
5848
5841
  fieldSchema = fieldSchema.optional();
5849
5842
  } else {
@@ -5869,9 +5862,9 @@ var InputValidator = class {
5869
5862
  let fieldSchema = this.makeScalarSchema(fieldDef.type, fieldDef.attributes);
5870
5863
  if (fieldDef.array) {
5871
5864
  fieldSchema = addListValidation(fieldSchema.array(), fieldDef.attributes);
5872
- fieldSchema = import_zod3.z.union([
5865
+ fieldSchema = import_zod2.z.union([
5873
5866
  fieldSchema,
5874
- import_zod3.z.strictObject({
5867
+ import_zod2.z.strictObject({
5875
5868
  set: fieldSchema
5876
5869
  })
5877
5870
  ]).optional();
@@ -5881,9 +5874,9 @@ var InputValidator = class {
5881
5874
  }
5882
5875
  if (fieldDef.optional) {
5883
5876
  if (fieldDef.type === "Json") {
5884
- fieldSchema = import_zod3.z.union([
5877
+ fieldSchema = import_zod2.z.union([
5885
5878
  fieldSchema,
5886
- import_zod3.z.instanceof(DbNullClass)
5879
+ import_zod2.z.instanceof(DbNullClass)
5887
5880
  ]);
5888
5881
  } else {
5889
5882
  fieldSchema = fieldSchema.nullable();
@@ -5895,19 +5888,19 @@ var InputValidator = class {
5895
5888
  }
5896
5889
  }
5897
5890
  });
5898
- const uncheckedCreateSchema = this.extraValidationsEnabled ? addCustomValidation(import_zod3.z.strictObject(uncheckedVariantFields), modelDef.attributes) : import_zod3.z.strictObject(uncheckedVariantFields);
5899
- const checkedCreateSchema = this.extraValidationsEnabled ? addCustomValidation(import_zod3.z.strictObject(checkedVariantFields), modelDef.attributes) : import_zod3.z.strictObject(checkedVariantFields);
5891
+ const uncheckedCreateSchema = this.extraValidationsEnabled ? addCustomValidation(import_zod2.z.strictObject(uncheckedVariantFields), modelDef.attributes) : import_zod2.z.strictObject(uncheckedVariantFields);
5892
+ const checkedCreateSchema = this.extraValidationsEnabled ? addCustomValidation(import_zod2.z.strictObject(checkedVariantFields), modelDef.attributes) : import_zod2.z.strictObject(checkedVariantFields);
5900
5893
  if (!hasRelation) {
5901
5894
  return this.orArray(uncheckedCreateSchema, canBeArray);
5902
5895
  } else {
5903
- return import_zod3.z.union([
5896
+ return import_zod2.z.union([
5904
5897
  uncheckedCreateSchema,
5905
5898
  checkedCreateSchema,
5906
5899
  ...canBeArray ? [
5907
- import_zod3.z.array(uncheckedCreateSchema)
5900
+ import_zod2.z.array(uncheckedCreateSchema)
5908
5901
  ] : [],
5909
5902
  ...canBeArray ? [
5910
- import_zod3.z.array(checkedCreateSchema)
5903
+ import_zod2.z.array(checkedCreateSchema)
5911
5904
  ] : []
5912
5905
  ]);
5913
5906
  }
@@ -5936,11 +5929,11 @@ var InputValidator = class {
5936
5929
  fields["disconnect"] = this.makeDisconnectDataSchema(fieldType, array).optional();
5937
5930
  fields["delete"] = this.makeDeleteRelationDataSchema(fieldType, array, true).optional();
5938
5931
  }
5939
- fields["update"] = array ? this.orArray(import_zod3.z.strictObject({
5932
+ fields["update"] = array ? this.orArray(import_zod2.z.strictObject({
5940
5933
  where: this.makeWhereSchema(fieldType, true),
5941
5934
  data: this.makeUpdateDataSchema(fieldType, withoutFields)
5942
- }), true).optional() : import_zod3.z.union([
5943
- import_zod3.z.strictObject({
5935
+ }), true).optional() : import_zod2.z.union([
5936
+ import_zod2.z.strictObject({
5944
5937
  where: this.makeWhereSchema(fieldType, false).optional(),
5945
5938
  data: this.makeUpdateDataSchema(fieldType, withoutFields)
5946
5939
  }),
@@ -5950,21 +5943,21 @@ var InputValidator = class {
5950
5943
  if (!fieldDef.array) {
5951
5944
  upsertWhere = upsertWhere.optional();
5952
5945
  }
5953
- fields["upsert"] = this.orArray(import_zod3.z.strictObject({
5946
+ fields["upsert"] = this.orArray(import_zod2.z.strictObject({
5954
5947
  where: upsertWhere,
5955
5948
  create: this.makeCreateDataSchema(fieldType, false, withoutFields),
5956
5949
  update: this.makeUpdateDataSchema(fieldType, withoutFields)
5957
5950
  }), true).optional();
5958
5951
  if (array) {
5959
5952
  fields["set"] = this.makeSetDataSchema(fieldType, true).optional();
5960
- fields["updateMany"] = this.orArray(import_zod3.z.strictObject({
5953
+ fields["updateMany"] = this.orArray(import_zod2.z.strictObject({
5961
5954
  where: this.makeWhereSchema(fieldType, false, true),
5962
5955
  data: this.makeUpdateDataSchema(fieldType, withoutFields)
5963
5956
  }), true).optional();
5964
5957
  fields["deleteMany"] = this.makeDeleteRelationDataSchema(fieldType, true, false).optional();
5965
5958
  }
5966
5959
  }
5967
- return import_zod3.z.strictObject(fields);
5960
+ return import_zod2.z.strictObject(fields);
5968
5961
  }
5969
5962
  makeSetDataSchema(model, canBeArray) {
5970
5963
  return this.orArray(this.makeWhereSchema(model, true), canBeArray);
@@ -5976,36 +5969,36 @@ var InputValidator = class {
5976
5969
  if (canBeArray) {
5977
5970
  return this.orArray(this.makeWhereSchema(model, true), canBeArray);
5978
5971
  } else {
5979
- return import_zod3.z.union([
5980
- import_zod3.z.boolean(),
5972
+ return import_zod2.z.union([
5973
+ import_zod2.z.boolean(),
5981
5974
  this.makeWhereSchema(model, false)
5982
5975
  ]);
5983
5976
  }
5984
5977
  }
5985
5978
  makeDeleteRelationDataSchema(model, toManyRelation, uniqueFilter) {
5986
- return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter), true) : import_zod3.z.union([
5987
- import_zod3.z.boolean(),
5979
+ return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter), true) : import_zod2.z.union([
5980
+ import_zod2.z.boolean(),
5988
5981
  this.makeWhereSchema(model, uniqueFilter)
5989
5982
  ]);
5990
5983
  }
5991
5984
  makeConnectOrCreateDataSchema(model, canBeArray, withoutFields) {
5992
5985
  const whereSchema = this.makeWhereSchema(model, true);
5993
5986
  const createSchema = this.makeCreateDataSchema(model, false, withoutFields);
5994
- return this.orArray(import_zod3.z.strictObject({
5987
+ return this.orArray(import_zod2.z.strictObject({
5995
5988
  where: whereSchema,
5996
5989
  create: createSchema
5997
5990
  }), canBeArray);
5998
5991
  }
5999
5992
  makeCreateManyDataSchema(model, withoutFields) {
6000
- return import_zod3.z.strictObject({
5993
+ return import_zod2.z.strictObject({
6001
5994
  data: this.makeCreateDataSchema(model, true, withoutFields, true),
6002
- skipDuplicates: import_zod3.z.boolean().optional()
5995
+ skipDuplicates: import_zod2.z.boolean().optional()
6003
5996
  });
6004
5997
  }
6005
5998
  // #endregion
6006
5999
  // #region Update
6007
6000
  makeUpdateSchema(model) {
6008
- const baseSchema = import_zod3.z.strictObject({
6001
+ const baseSchema = import_zod2.z.strictObject({
6009
6002
  where: this.makeWhereSchema(model, true),
6010
6003
  data: this.makeUpdateDataSchema(model),
6011
6004
  select: this.makeSelectSchema(model).optional().nullable(),
@@ -6018,10 +6011,10 @@ var InputValidator = class {
6018
6011
  return schema;
6019
6012
  }
6020
6013
  makeUpdateManySchema(model) {
6021
- return this.mergePluginArgsSchema(import_zod3.z.strictObject({
6014
+ return this.mergePluginArgsSchema(import_zod2.z.strictObject({
6022
6015
  where: this.makeWhereSchema(model, false).optional(),
6023
6016
  data: this.makeUpdateDataSchema(model, [], true),
6024
- limit: import_zod3.z.number().int().nonnegative().optional()
6017
+ limit: import_zod2.z.number().int().nonnegative().optional()
6025
6018
  }), "updateMany");
6026
6019
  }
6027
6020
  makeUpdateManyAndReturnSchema(model) {
@@ -6034,7 +6027,7 @@ var InputValidator = class {
6034
6027
  return schema;
6035
6028
  }
6036
6029
  makeUpsertSchema(model) {
6037
- const baseSchema = import_zod3.z.strictObject({
6030
+ const baseSchema = import_zod2.z.strictObject({
6038
6031
  where: this.makeWhereSchema(model, true),
6039
6032
  create: this.makeCreateDataSchema(model, false),
6040
6033
  update: this.makeUpdateDataSchema(model),
@@ -6070,7 +6063,7 @@ var InputValidator = class {
6070
6063
  excludeFields.push(...oppositeFieldDef.relation.fields);
6071
6064
  }
6072
6065
  }
6073
- let fieldSchema = import_zod3.z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "update")).optional();
6066
+ let fieldSchema = import_zod2.z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "update")).optional();
6074
6067
  if (fieldDef.optional && !fieldDef.array) {
6075
6068
  fieldSchema = fieldSchema.nullable();
6076
6069
  }
@@ -6081,24 +6074,24 @@ var InputValidator = class {
6081
6074
  } else {
6082
6075
  let fieldSchema = this.makeScalarSchema(fieldDef.type, fieldDef.attributes);
6083
6076
  if (this.isNumericField(fieldDef)) {
6084
- fieldSchema = import_zod3.z.union([
6077
+ fieldSchema = import_zod2.z.union([
6085
6078
  fieldSchema,
6086
- import_zod3.z.object({
6087
- set: this.nullableIf(import_zod3.z.number().optional(), !!fieldDef.optional).optional(),
6088
- increment: import_zod3.z.number().optional(),
6089
- decrement: import_zod3.z.number().optional(),
6090
- multiply: import_zod3.z.number().optional(),
6091
- divide: import_zod3.z.number().optional()
6079
+ import_zod2.z.object({
6080
+ set: this.nullableIf(import_zod2.z.number().optional(), !!fieldDef.optional).optional(),
6081
+ increment: import_zod2.z.number().optional(),
6082
+ decrement: import_zod2.z.number().optional(),
6083
+ multiply: import_zod2.z.number().optional(),
6084
+ divide: import_zod2.z.number().optional()
6092
6085
  }).refine((v) => Object.keys(v).length === 1, 'Only one of "set", "increment", "decrement", "multiply", or "divide" can be provided')
6093
6086
  ]);
6094
6087
  }
6095
6088
  if (fieldDef.array) {
6096
6089
  const arraySchema = addListValidation(fieldSchema.array(), fieldDef.attributes);
6097
- fieldSchema = import_zod3.z.union([
6090
+ fieldSchema = import_zod2.z.union([
6098
6091
  arraySchema,
6099
- import_zod3.z.object({
6092
+ import_zod2.z.object({
6100
6093
  set: arraySchema.optional(),
6101
- push: import_zod3.z.union([
6094
+ push: import_zod2.z.union([
6102
6095
  fieldSchema,
6103
6096
  fieldSchema.array()
6104
6097
  ]).optional()
@@ -6107,9 +6100,9 @@ var InputValidator = class {
6107
6100
  }
6108
6101
  if (fieldDef.optional) {
6109
6102
  if (fieldDef.type === "Json") {
6110
- fieldSchema = import_zod3.z.union([
6103
+ fieldSchema = import_zod2.z.union([
6111
6104
  fieldSchema,
6112
- import_zod3.z.instanceof(DbNullClass)
6105
+ import_zod2.z.instanceof(DbNullClass)
6113
6106
  ]);
6114
6107
  } else {
6115
6108
  fieldSchema = fieldSchema.nullable();
@@ -6122,12 +6115,12 @@ var InputValidator = class {
6122
6115
  }
6123
6116
  }
6124
6117
  });
6125
- const uncheckedUpdateSchema = this.extraValidationsEnabled ? addCustomValidation(import_zod3.z.strictObject(uncheckedVariantFields), modelDef.attributes) : import_zod3.z.strictObject(uncheckedVariantFields);
6126
- const checkedUpdateSchema = this.extraValidationsEnabled ? addCustomValidation(import_zod3.z.strictObject(checkedVariantFields), modelDef.attributes) : import_zod3.z.strictObject(checkedVariantFields);
6118
+ const uncheckedUpdateSchema = this.extraValidationsEnabled ? addCustomValidation(import_zod2.z.strictObject(uncheckedVariantFields), modelDef.attributes) : import_zod2.z.strictObject(uncheckedVariantFields);
6119
+ const checkedUpdateSchema = this.extraValidationsEnabled ? addCustomValidation(import_zod2.z.strictObject(checkedVariantFields), modelDef.attributes) : import_zod2.z.strictObject(checkedVariantFields);
6127
6120
  if (!hasRelation) {
6128
6121
  return uncheckedUpdateSchema;
6129
6122
  } else {
6130
- return import_zod3.z.union([
6123
+ return import_zod2.z.union([
6131
6124
  uncheckedUpdateSchema,
6132
6125
  checkedUpdateSchema
6133
6126
  ]);
@@ -6136,7 +6129,7 @@ var InputValidator = class {
6136
6129
  // #endregion
6137
6130
  // #region Delete
6138
6131
  makeDeleteSchema(model) {
6139
- const baseSchema = import_zod3.z.strictObject({
6132
+ const baseSchema = import_zod2.z.strictObject({
6140
6133
  where: this.makeWhereSchema(model, true),
6141
6134
  select: this.makeSelectSchema(model).optional().nullable(),
6142
6135
  include: this.makeIncludeSchema(model).optional().nullable(),
@@ -6148,15 +6141,15 @@ var InputValidator = class {
6148
6141
  return schema;
6149
6142
  }
6150
6143
  makeDeleteManySchema(model) {
6151
- return this.mergePluginArgsSchema(import_zod3.z.strictObject({
6144
+ return this.mergePluginArgsSchema(import_zod2.z.strictObject({
6152
6145
  where: this.makeWhereSchema(model, false).optional(),
6153
- limit: import_zod3.z.number().int().nonnegative().optional()
6146
+ limit: import_zod2.z.number().int().nonnegative().optional()
6154
6147
  }), "deleteMany").optional();
6155
6148
  }
6156
6149
  // #endregion
6157
6150
  // #region Count
6158
6151
  makeCountSchema(model) {
6159
- return this.mergePluginArgsSchema(import_zod3.z.strictObject({
6152
+ return this.mergePluginArgsSchema(import_zod2.z.strictObject({
6160
6153
  where: this.makeWhereSchema(model, false).optional(),
6161
6154
  skip: this.makeSkipSchema().optional(),
6162
6155
  take: this.makeTakeSchema().optional(),
@@ -6166,12 +6159,12 @@ var InputValidator = class {
6166
6159
  }
6167
6160
  makeCountAggregateInputSchema(model) {
6168
6161
  const modelDef = requireModel(this.schema, model);
6169
- return import_zod3.z.union([
6170
- import_zod3.z.literal(true),
6171
- import_zod3.z.strictObject({
6172
- _all: import_zod3.z.literal(true).optional(),
6162
+ return import_zod2.z.union([
6163
+ import_zod2.z.literal(true),
6164
+ import_zod2.z.strictObject({
6165
+ _all: import_zod2.z.literal(true).optional(),
6173
6166
  ...Object.keys(modelDef.fields).reduce((acc, field) => {
6174
- acc[field] = import_zod3.z.literal(true).optional();
6167
+ acc[field] = import_zod2.z.literal(true).optional();
6175
6168
  return acc;
6176
6169
  }, {})
6177
6170
  })
@@ -6180,7 +6173,7 @@ var InputValidator = class {
6180
6173
  // #endregion
6181
6174
  // #region Aggregate
6182
6175
  makeAggregateSchema(model) {
6183
- return this.mergePluginArgsSchema(import_zod3.z.strictObject({
6176
+ return this.mergePluginArgsSchema(import_zod2.z.strictObject({
6184
6177
  where: this.makeWhereSchema(model, false).optional(),
6185
6178
  skip: this.makeSkipSchema().optional(),
6186
6179
  take: this.makeTakeSchema().optional(),
@@ -6194,20 +6187,20 @@ var InputValidator = class {
6194
6187
  }
6195
6188
  makeSumAvgInputSchema(model) {
6196
6189
  const modelDef = requireModel(this.schema, model);
6197
- return import_zod3.z.strictObject(Object.keys(modelDef.fields).reduce((acc, field) => {
6190
+ return import_zod2.z.strictObject(Object.keys(modelDef.fields).reduce((acc, field) => {
6198
6191
  const fieldDef = requireField(this.schema, model, field);
6199
6192
  if (this.isNumericField(fieldDef)) {
6200
- acc[field] = import_zod3.z.literal(true).optional();
6193
+ acc[field] = import_zod2.z.literal(true).optional();
6201
6194
  }
6202
6195
  return acc;
6203
6196
  }, {}));
6204
6197
  }
6205
6198
  makeMinMaxInputSchema(model) {
6206
6199
  const modelDef = requireModel(this.schema, model);
6207
- return import_zod3.z.strictObject(Object.keys(modelDef.fields).reduce((acc, field) => {
6200
+ return import_zod2.z.strictObject(Object.keys(modelDef.fields).reduce((acc, field) => {
6208
6201
  const fieldDef = requireField(this.schema, model, field);
6209
6202
  if (!fieldDef.relation && !fieldDef.array) {
6210
- acc[field] = import_zod3.z.literal(true).optional();
6203
+ acc[field] = import_zod2.z.literal(true).optional();
6211
6204
  }
6212
6205
  return acc;
6213
6206
  }, {}));
@@ -6215,8 +6208,8 @@ var InputValidator = class {
6215
6208
  makeGroupBySchema(model) {
6216
6209
  const modelDef = requireModel(this.schema, model);
6217
6210
  const nonRelationFields = Object.keys(modelDef.fields).filter((field) => !modelDef.fields[field]?.relation);
6218
- const bySchema = nonRelationFields.length > 0 ? this.orArray(import_zod3.z.enum(nonRelationFields), true) : import_zod3.z.never();
6219
- const baseSchema = import_zod3.z.strictObject({
6211
+ const bySchema = nonRelationFields.length > 0 ? this.orArray(import_zod2.z.enum(nonRelationFields), true) : import_zod2.z.never();
6212
+ const baseSchema = import_zod2.z.strictObject({
6220
6213
  where: this.makeWhereSchema(model, false).optional(),
6221
6214
  orderBy: this.orArray(this.makeOrderBySchema(model, false, true), true).optional(),
6222
6215
  by: bySchema,
@@ -6290,10 +6283,10 @@ var InputValidator = class {
6290
6283
  } else if (isEnum(this.schema, param.type)) {
6291
6284
  schema = this.makeEnumSchema(param.type);
6292
6285
  } else if (param.type in (this.schema.models ?? {})) {
6293
- schema = import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown());
6286
+ schema = import_zod2.z.record(import_zod2.z.string(), import_zod2.z.unknown());
6294
6287
  } else {
6295
6288
  schema = this.makeScalarSchema(param.type);
6296
- if (schema instanceof import_zod3.z.ZodUnknown) {
6289
+ if (schema instanceof import_zod2.z.ZodUnknown) {
6297
6290
  throw createInternalError(`Unsupported procedure parameter type: ${param.type}`);
6298
6291
  }
6299
6292
  }
@@ -6325,10 +6318,10 @@ var InputValidator = class {
6325
6318
  // #endregion
6326
6319
  // #region Helpers
6327
6320
  makeSkipSchema() {
6328
- return import_zod3.z.number().int().nonnegative();
6321
+ return import_zod2.z.number().int().nonnegative();
6329
6322
  }
6330
6323
  makeTakeSchema() {
6331
- return import_zod3.z.number().int();
6324
+ return import_zod2.z.number().int();
6332
6325
  }
6333
6326
  refineForSelectIncludeMutuallyExclusive(schema) {
6334
6327
  return schema.refine((value) => !(value["select"] && value["include"]), '"select" and "include" cannot be used together');
@@ -6340,9 +6333,9 @@ var InputValidator = class {
6340
6333
  return nullable ? schema.nullable() : schema;
6341
6334
  }
6342
6335
  orArray(schema, canBeArray) {
6343
- return canBeArray ? import_zod3.z.union([
6336
+ return canBeArray ? import_zod2.z.union([
6344
6337
  schema,
6345
- import_zod3.z.array(schema)
6338
+ import_zod2.z.array(schema)
6346
6339
  ]) : schema;
6347
6340
  }
6348
6341
  isNumericField(fieldDef) {
@@ -6383,7 +6376,7 @@ _ts_decorate([
6383
6376
  _ts_metadata("design:paramtypes", [
6384
6377
  String
6385
6378
  ]),
6386
- _ts_metadata("design:returntype", typeof import_zod3.z === "undefined" || typeof import_zod3.z.ZodType === "undefined" ? Object : import_zod3.z.ZodType)
6379
+ _ts_metadata("design:returntype", typeof import_zod2.z === "undefined" || typeof import_zod2.z.ZodType === "undefined" ? Object : import_zod2.z.ZodType)
6387
6380
  ], InputValidator.prototype, "makeTypeDefSchema", null);
6388
6381
  _ts_decorate([
6389
6382
  cache(),
@@ -6394,7 +6387,7 @@ _ts_decorate([
6394
6387
  void 0,
6395
6388
  void 0
6396
6389
  ]),
6397
- _ts_metadata("design:returntype", typeof import_zod3.ZodType === "undefined" ? Object : import_zod3.ZodType)
6390
+ _ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
6398
6391
  ], InputValidator.prototype, "makeWhereSchema", null);
6399
6392
  _ts_decorate([
6400
6393
  cache(),
@@ -6450,7 +6443,7 @@ _ts_decorate([
6450
6443
  Boolean,
6451
6444
  Boolean
6452
6445
  ]),
6453
- _ts_metadata("design:returntype", typeof import_zod3.ZodType === "undefined" ? Object : import_zod3.ZodType)
6446
+ _ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
6454
6447
  ], InputValidator.prototype, "makeDateTimeFilterSchema", null);
6455
6448
  _ts_decorate([
6456
6449
  cache(),
@@ -6459,7 +6452,7 @@ _ts_decorate([
6459
6452
  Boolean,
6460
6453
  Boolean
6461
6454
  ]),
6462
- _ts_metadata("design:returntype", typeof import_zod3.ZodType === "undefined" ? Object : import_zod3.ZodType)
6455
+ _ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
6463
6456
  ], InputValidator.prototype, "makeBooleanFilterSchema", null);
6464
6457
  _ts_decorate([
6465
6458
  cache(),
@@ -6468,7 +6461,7 @@ _ts_decorate([
6468
6461
  Boolean,
6469
6462
  Boolean
6470
6463
  ]),
6471
- _ts_metadata("design:returntype", typeof import_zod3.ZodType === "undefined" ? Object : import_zod3.ZodType)
6464
+ _ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
6472
6465
  ], InputValidator.prototype, "makeBytesFilterSchema", null);
6473
6466
  _ts_decorate([
6474
6467
  cache(),
@@ -6743,7 +6736,7 @@ _ts_decorate([
6743
6736
  _ts_metadata("design:paramtypes", [
6744
6737
  Object
6745
6738
  ]),
6746
- _ts_metadata("design:returntype", typeof import_zod3.z === "undefined" || typeof import_zod3.z.ZodType === "undefined" ? Object : import_zod3.z.ZodType)
6739
+ _ts_metadata("design:returntype", typeof import_zod2.z === "undefined" || typeof import_zod2.z.ZodType === "undefined" ? Object : import_zod2.z.ZodType)
6747
6740
  ], InputValidator.prototype, "makeProcedureParamSchema", null);
6748
6741
  _ts_decorate([
6749
6742
  cache(),
@@ -6956,6 +6949,7 @@ var QueryNameMapper = class extends import_kysely7.OperationNodeTransformer {
6956
6949
  client;
6957
6950
  modelToTableMap = /* @__PURE__ */ new Map();
6958
6951
  fieldToColumnMap = /* @__PURE__ */ new Map();
6952
+ enumTypeMap = /* @__PURE__ */ new Map();
6959
6953
  scopes = [];
6960
6954
  dialect;
6961
6955
  constructor(client) {
@@ -6973,14 +6967,20 @@ var QueryNameMapper = class extends import_kysely7.OperationNodeTransformer {
6973
6967
  }
6974
6968
  }
6975
6969
  }
6970
+ for (const [enumName, enumDef] of Object.entries(client.$schema.enums ?? {})) {
6971
+ const mappedName = this.getMappedName(enumDef);
6972
+ if (mappedName) {
6973
+ this.enumTypeMap.set(enumName, mappedName);
6974
+ }
6975
+ }
6976
6976
  }
6977
6977
  get schema() {
6978
6978
  return this.client.$schema;
6979
6979
  }
6980
6980
  // #region overrides
6981
- transformSelectQuery(node) {
6981
+ transformSelectQuery(node, queryId) {
6982
6982
  if (!node.from?.froms) {
6983
- return super.transformSelectQuery(node);
6983
+ return super.transformSelectQuery(node, queryId);
6984
6984
  }
6985
6985
  const processedFroms = node.from.froms.map((from) => this.processSelectTable(from));
6986
6986
  const processedJoins = [];
@@ -6999,7 +6999,7 @@ var QueryNameMapper = class extends import_kysely7.OperationNodeTransformer {
6999
6999
  on: this.transformNode(join.on)
7000
7000
  })) : void 0;
7001
7001
  const selections = this.processSelectQuerySelections(node);
7002
- const baseResult = super.transformSelectQuery(node);
7002
+ const baseResult = super.transformSelectQuery(node, queryId);
7003
7003
  return {
7004
7004
  ...baseResult,
7005
7005
  from: import_kysely7.FromNode.create(processedFroms.map((f) => f.node)),
@@ -7008,16 +7008,16 @@ var QueryNameMapper = class extends import_kysely7.OperationNodeTransformer {
7008
7008
  };
7009
7009
  });
7010
7010
  }
7011
- transformInsertQuery(node) {
7011
+ transformInsertQuery(node, queryId) {
7012
7012
  if (!node.into) {
7013
- return super.transformInsertQuery(node);
7013
+ return super.transformInsertQuery(node, queryId);
7014
7014
  }
7015
7015
  const model = extractModelName(node.into);
7016
7016
  (0, import_common_helpers10.invariant)(model, 'InsertQueryNode must have a model name in the "into" clause');
7017
7017
  return this.withScope({
7018
7018
  model
7019
7019
  }, () => {
7020
- const baseResult = super.transformInsertQuery(node);
7020
+ const baseResult = super.transformInsertQuery(node, queryId);
7021
7021
  let values = baseResult.values;
7022
7022
  if (node.columns && values) {
7023
7023
  values = this.processEnumMappingForColumns(model, node.columns, values);
@@ -7040,9 +7040,9 @@ var QueryNameMapper = class extends import_kysely7.OperationNodeTransformer {
7040
7040
  selections: this.processSelections(node.selections)
7041
7041
  };
7042
7042
  }
7043
- transformReference(node) {
7043
+ transformReference(node, queryId) {
7044
7044
  if (!import_kysely7.ColumnNode.is(node.column)) {
7045
- return super.transformReference(node);
7045
+ return super.transformReference(node, queryId);
7046
7046
  }
7047
7047
  const scope = this.resolveFieldFromScopes(node.column.column.name, node.table?.table.identifier.name);
7048
7048
  if (scope && !scope.namesMapped && scope.model) {
@@ -7059,15 +7059,15 @@ var QueryNameMapper = class extends import_kysely7.OperationNodeTransformer {
7059
7059
  return node;
7060
7060
  }
7061
7061
  }
7062
- transformColumn(node) {
7062
+ transformColumn(node, queryId) {
7063
7063
  const scope = this.resolveFieldFromScopes(node.column.name);
7064
7064
  if (!scope || scope.namesMapped || !scope.model) {
7065
- return super.transformColumn(node);
7065
+ return super.transformColumn(node, queryId);
7066
7066
  }
7067
7067
  const mappedName = this.mapFieldName(scope.model, node.column.name);
7068
7068
  return import_kysely7.ColumnNode.create(mappedName);
7069
7069
  }
7070
- transformBinaryOperation(node) {
7070
+ transformBinaryOperation(node, queryId) {
7071
7071
  if (import_kysely7.ReferenceNode.is(node.leftOperand) && import_kysely7.ColumnNode.is(node.leftOperand.column) && (import_kysely7.ValueNode.is(node.rightOperand) || import_kysely7.PrimitiveValueListNode.is(node.rightOperand))) {
7072
7072
  const columnNode = node.leftOperand.column;
7073
7073
  const resolvedScope = this.resolveFieldFromScopes(columnNode.column.name, node.leftOperand.table?.table.identifier.name);
@@ -7082,14 +7082,14 @@ var QueryNameMapper = class extends import_kysely7.OperationNodeTransformer {
7082
7082
  return super.transformBinaryOperation({
7083
7083
  ...node,
7084
7084
  rightOperand: resultValue
7085
- });
7085
+ }, queryId);
7086
7086
  }
7087
7087
  }
7088
- return super.transformBinaryOperation(node);
7088
+ return super.transformBinaryOperation(node, queryId);
7089
7089
  }
7090
- transformUpdateQuery(node) {
7090
+ transformUpdateQuery(node, queryId) {
7091
7091
  if (!node.table) {
7092
- return super.transformUpdateQuery(node);
7092
+ return super.transformUpdateQuery(node, queryId);
7093
7093
  }
7094
7094
  const { alias, node: innerTable } = stripAlias(node.table);
7095
7095
  if (!innerTable || !import_kysely7.TableNode.is(innerTable)) {
@@ -7101,7 +7101,7 @@ var QueryNameMapper = class extends import_kysely7.OperationNodeTransformer {
7101
7101
  model,
7102
7102
  alias
7103
7103
  }, () => {
7104
- const baseResult = super.transformUpdateQuery(node);
7104
+ const baseResult = super.transformUpdateQuery(node, queryId);
7105
7105
  const updates = baseResult.updates?.map((update, i) => {
7106
7106
  if (import_kysely7.ColumnNode.is(update.column)) {
7107
7107
  const origColumn = node.updates[i].column;
@@ -7118,7 +7118,7 @@ var QueryNameMapper = class extends import_kysely7.OperationNodeTransformer {
7118
7118
  };
7119
7119
  });
7120
7120
  }
7121
- transformDeleteQuery(node) {
7121
+ transformDeleteQuery(node, queryId) {
7122
7122
  const scopes = node.from.froms.map((node2) => {
7123
7123
  const { alias, node: innerNode } = stripAlias(node2);
7124
7124
  return {
@@ -7132,12 +7132,12 @@ var QueryNameMapper = class extends import_kysely7.OperationNodeTransformer {
7132
7132
  if (import_kysely7.TableNode.is(innerNode)) {
7133
7133
  return this.wrapAlias(this.processTableRef(innerNode), alias);
7134
7134
  } else {
7135
- return super.transformNode(from);
7135
+ return super.transformNode(from, queryId);
7136
7136
  }
7137
7137
  });
7138
7138
  return this.withScopes(scopes, () => {
7139
7139
  return {
7140
- ...super.transformDeleteQuery(node),
7140
+ ...super.transformDeleteQuery(node, queryId),
7141
7141
  from: import_kysely7.FromNode.create(froms)
7142
7142
  };
7143
7143
  });
@@ -8046,7 +8046,7 @@ var textMatch = /* @__PURE__ */ __name((eb, args, { dialect }, method) => {
8046
8046
  ])).exhaustive();
8047
8047
  return import_kysely9.sql`${fieldExpr} ${import_kysely9.sql.raw(op)} ${searchExpr} escape ${import_kysely9.sql.val("\\")}`;
8048
8048
  }, "textMatch");
8049
- var has = /* @__PURE__ */ __name((eb, args) => {
8049
+ var has = /* @__PURE__ */ __name((_eb, args, context) => {
8050
8050
  const [field, search2] = args;
8051
8051
  if (!field) {
8052
8052
  throw new Error('"field" parameter is required');
@@ -8054,11 +8054,9 @@ var has = /* @__PURE__ */ __name((eb, args) => {
8054
8054
  if (!search2) {
8055
8055
  throw new Error('"search" parameter is required');
8056
8056
  }
8057
- return eb(field, "@>", [
8058
- search2
8059
- ]);
8057
+ return context.dialect.buildArrayContains(field, search2);
8060
8058
  }, "has");
8061
- var hasEvery = /* @__PURE__ */ __name((eb, args) => {
8059
+ var hasEvery = /* @__PURE__ */ __name((_eb, args, { dialect }) => {
8062
8060
  const [field, search2] = args;
8063
8061
  if (!field) {
8064
8062
  throw new Error('"field" parameter is required');
@@ -8066,9 +8064,9 @@ var hasEvery = /* @__PURE__ */ __name((eb, args) => {
8066
8064
  if (!search2) {
8067
8065
  throw new Error('"search" parameter is required');
8068
8066
  }
8069
- return eb(field, "@>", search2);
8067
+ return dialect.buildArrayHasEvery(field, search2);
8070
8068
  }, "hasEvery");
8071
- var hasSome = /* @__PURE__ */ __name((eb, args) => {
8069
+ var hasSome = /* @__PURE__ */ __name((_eb, args, { dialect }) => {
8072
8070
  const [field, search2] = args;
8073
8071
  if (!field) {
8074
8072
  throw new Error('"field" parameter is required');
@@ -8076,7 +8074,7 @@ var hasSome = /* @__PURE__ */ __name((eb, args) => {
8076
8074
  if (!search2) {
8077
8075
  throw new Error('"search" parameter is required');
8078
8076
  }
8079
- return eb(field, "&&", search2);
8077
+ return dialect.buildArrayHasSome(field, search2);
8080
8078
  }, "hasSome");
8081
8079
  var isEmpty = /* @__PURE__ */ __name((eb, args, { dialect }) => {
8082
8080
  const [field] = args;
@@ -8139,7 +8137,7 @@ var SchemaDbPusher = class {
8139
8137
  async push() {
8140
8138
  await this.kysely.transaction().execute(async (tx) => {
8141
8139
  if (this.schema.enums && this.providerSupportsNativeEnum) {
8142
- for (const [name, enumDef] of Object.entries(this.schema.enums)) {
8140
+ for (const enumDef of Object.values(this.schema.enums)) {
8143
8141
  let enumValues;
8144
8142
  if (enumDef.fields) {
8145
8143
  enumValues = Object.values(enumDef.fields).map((f) => {
@@ -8155,7 +8153,7 @@ var SchemaDbPusher = class {
8155
8153
  } else {
8156
8154
  enumValues = Object.values(enumDef.values);
8157
8155
  }
8158
- const createEnum = tx.schema.createType(name).asEnum(enumValues);
8156
+ const createEnum = tx.schema.createType(this.getEnumName(enumDef)).asEnum(enumValues);
8159
8157
  await createEnum.execute();
8160
8158
  }
8161
8159
  }
@@ -8233,6 +8231,16 @@ var SchemaDbPusher = class {
8233
8231
  }
8234
8232
  return modelDef.name;
8235
8233
  }
8234
+ getEnumName(enumDef) {
8235
+ const mapAttr = enumDef.attributes?.find((a) => a.name === "@@map");
8236
+ if (mapAttr && mapAttr.args?.[0]) {
8237
+ const mappedName = schema_exports.ExpressionUtils.getLiteralValue(mapAttr.args[0].value);
8238
+ if (mappedName) {
8239
+ return mappedName;
8240
+ }
8241
+ }
8242
+ return enumDef.name;
8243
+ }
8236
8244
  getColumnName(fieldDef) {
8237
8245
  const mapAttr = fieldDef.attributes?.find((a) => a.name === "@map");
8238
8246
  if (mapAttr && mapAttr.args?.[0]) {