@zenstackhq/orm 3.6.0 → 3.6.2

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.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { t as __exportAll } from "./chunk-CfYAbeIz.mjs";
2
2
  import { clone, enumerate, invariant, isPlainObject, lowerCaseFirst, upperCaseFirst } from "@zenstackhq/common-helpers";
3
3
  import { AliasNode, AndNode, ColumnNode, ColumnUpdateNode, CompiledQuery, DefaultConnectionProvider, DefaultQueryExecutor, DeleteQueryNode, ExpressionWrapper, FromNode, IdentifierNode, InsertQueryNode, Kysely, Log, OperationNodeTransformer, OperationNodeVisitor, PrimitiveValueListNode, ReferenceNode, ReturningNode, SelectAllNode, SelectionNode, SingleConnectionProvider, TableNode, Transaction, UpdateQueryNode, ValueListNode, ValueNode, ValuesNode, WhereNode, createQueryId, expressionBuilder, sql } from "kysely";
4
- import z$1, { ZodObject, ZodType, z } from "zod";
4
+ import z, { ZodObject, ZodType, z as z$1 } from "zod";
5
5
  import { fromError } from "zod-validation-error/v4";
6
6
  import { P, match } from "ts-pattern";
7
7
  import { ExpressionUtils } from "@zenstackhq/schema";
@@ -1592,6 +1592,7 @@ var PostgresCrudDialect = class PostgresCrudDialect extends LateralJoinDialectBa
1592
1592
  return value;
1593
1593
  }
1594
1594
  });
1595
+ pg.types.setTypeParser(pg.types.builtins.DATE, (v) => /* @__PURE__ */ new Date(`${v}T00:00:00Z`));
1595
1596
  }).catch(() => {});
1596
1597
  }
1597
1598
  }
@@ -2074,7 +2075,7 @@ function createQuerySchemaFactory(clientOrSchema, options) {
2074
2075
  */
2075
2076
  var ZodSchemaFactory = class {
2076
2077
  schemaCache = /* @__PURE__ */ new Map();
2077
- schemaRegistry = z.registry();
2078
+ schemaRegistry = z$1.registry();
2078
2079
  allFilterKinds = [...new Set(Object.values(FILTER_PROPERTY_TO_KIND))];
2079
2080
  schema;
2080
2081
  options;
@@ -2166,7 +2167,7 @@ var ZodSchemaFactory = class {
2166
2167
  this.makeGroupBySchema(m);
2167
2168
  }
2168
2169
  for (const procName of Object.keys(this.schema.procedures ?? {})) if (this.isProcedureAllowed(procName)) this.makeProcedureArgsSchema(procName);
2169
- return z.toJSONSchema(this.schemaRegistry, { unrepresentable: "any" });
2170
+ return z$1.toJSONSchema(this.schemaRegistry, { unrepresentable: "any" });
2170
2171
  }
2171
2172
  get cacheStats() {
2172
2173
  return {
@@ -2195,13 +2196,13 @@ var ZodSchemaFactory = class {
2195
2196
  fields["omit"] = this.makeOmitSchema(model).optional().nullable();
2196
2197
  if (!unique) {
2197
2198
  fields["skip"] = this.makeSkipSchema().optional();
2198
- if (findOne) fields["take"] = z.literal(1).optional();
2199
+ if (findOne) fields["take"] = z$1.literal(1).optional();
2199
2200
  else fields["take"] = this.makeTakeSchema().optional();
2200
2201
  fields["orderBy"] = this.orArray(this.makeOrderBySchema(model, true, false, options), true).optional();
2201
2202
  fields["cursor"] = this.makeCursorSchema(model, options).optional();
2202
2203
  fields["distinct"] = this.makeDistinctSchema(model).optional();
2203
2204
  }
2204
- const baseSchema = z.strictObject(fields);
2205
+ const baseSchema = z$1.strictObject(fields);
2205
2206
  let result = this.mergePluginArgsSchema(baseSchema, operation);
2206
2207
  result = this.refineForSelectIncludeMutuallyExclusive(result);
2207
2208
  result = this.refineForSelectOmitMutuallyExclusive(result);
@@ -2211,7 +2212,7 @@ var ZodSchemaFactory = class {
2211
2212
  return result;
2212
2213
  }
2213
2214
  makeExistsSchema(model, options) {
2214
- const baseSchema = z.strictObject({ where: this.makeWhereSchema(model, false, false, false, options).optional() });
2215
+ const baseSchema = z$1.strictObject({ where: this.makeWhereSchema(model, false, false, false, options).optional() });
2215
2216
  const result = this.mergePluginArgsSchema(baseSchema, "exists").optional();
2216
2217
  this.registerSchema(`${model}ExistsArgs`, result);
2217
2218
  return result;
@@ -2219,31 +2220,31 @@ var ZodSchemaFactory = class {
2219
2220
  makeScalarSchema(type, attributes) {
2220
2221
  if (this.schema.typeDefs && type in this.schema.typeDefs) return this.makeTypeDefSchema(type);
2221
2222
  else if (this.schema.enums && type in this.schema.enums) return this.makeEnumSchema(type);
2222
- else return match(type).with("String", () => this.extraValidationsEnabled ? ZodUtils.addStringValidation(z.string(), attributes) : z.string()).with("Int", () => this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z.number().int(), attributes) : z.number().int()).with("Float", () => this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z.number(), attributes) : z.number()).with("Boolean", () => z.boolean()).with("BigInt", () => z.union([this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z.number().int(), attributes) : z.number().int(), this.extraValidationsEnabled ? ZodUtils.addBigIntValidation(z.bigint(), attributes) : z.bigint()])).with("Decimal", () => {
2223
- return z.union([
2224
- this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z.number(), attributes) : z.number(),
2225
- ZodUtils.addDecimalValidation(z.instanceof(Decimal), attributes, this.extraValidationsEnabled),
2226
- ZodUtils.addDecimalValidation(z.string(), attributes, this.extraValidationsEnabled)
2223
+ else return match(type).with("String", () => this.extraValidationsEnabled ? ZodUtils.addStringValidation(z$1.string(), attributes) : z$1.string()).with("Int", () => this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z$1.number().int(), attributes) : z$1.number().int()).with("Float", () => this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z$1.number(), attributes) : z$1.number()).with("Boolean", () => z$1.boolean()).with("BigInt", () => z$1.union([this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z$1.number().int(), attributes) : z$1.number().int(), this.extraValidationsEnabled ? ZodUtils.addBigIntValidation(z$1.bigint(), attributes) : z$1.bigint()])).with("Decimal", () => {
2224
+ return z$1.union([
2225
+ this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z$1.number(), attributes) : z$1.number(),
2226
+ ZodUtils.addDecimalValidation(z$1.instanceof(Decimal), attributes, this.extraValidationsEnabled),
2227
+ ZodUtils.addDecimalValidation(z$1.string(), attributes, this.extraValidationsEnabled)
2227
2228
  ]);
2228
- }).with("DateTime", () => this.makeDateTimeValueSchema()).with("Bytes", () => z.instanceof(Uint8Array)).with("Json", () => this.makeJsonValueSchema()).otherwise(() => z.unknown());
2229
+ }).with("DateTime", () => this.makeDateTimeValueSchema()).with("Bytes", () => z$1.instanceof(Uint8Array)).with("Json", () => this.makeJsonValueSchema()).otherwise(() => z$1.unknown());
2229
2230
  }
2230
2231
  makeEnumSchema(_enum) {
2231
2232
  const enumDef = getEnum(this.schema, _enum);
2232
2233
  invariant(enumDef, `Enum "${_enum}" not found in schema`);
2233
- const schema = z.enum(Object.keys(enumDef.values));
2234
+ const schema = z$1.enum(Object.keys(enumDef.values));
2234
2235
  this.registerSchema(_enum, schema);
2235
2236
  return schema;
2236
2237
  }
2237
2238
  makeTypeDefSchema(type) {
2238
2239
  const typeDef = getTypeDef(this.schema, type);
2239
2240
  invariant(typeDef, `Type definition "${type}" not found in schema`);
2240
- const schema = z.looseObject(Object.fromEntries(Object.entries(typeDef.fields).map(([field, def]) => {
2241
+ const schema = z$1.looseObject(Object.fromEntries(Object.entries(typeDef.fields).map(([field, def]) => {
2241
2242
  let fieldSchema = this.makeScalarSchema(def.type);
2242
2243
  if (def.array) fieldSchema = fieldSchema.array();
2243
2244
  if (def.optional) fieldSchema = fieldSchema.nullish();
2244
2245
  return [field, fieldSchema];
2245
2246
  })));
2246
- const finalSchema = z.any().superRefine((value, ctx) => {
2247
+ const finalSchema = z$1.any().superRefine((value, ctx) => {
2247
2248
  const parseResult = schema.safeParse(value);
2248
2249
  if (!parseResult.success) parseResult.error.issues.forEach((issue) => ctx.addIssue(issue));
2249
2250
  });
@@ -2259,17 +2260,17 @@ var ZodSchemaFactory = class {
2259
2260
  if (fieldDef.relation) {
2260
2261
  if (withoutRelationFields || !this.shouldIncludeRelations(options)) continue;
2261
2262
  const allowedFilterKinds = this.getEffectiveFilterKinds(model, field);
2262
- if (allowedFilterKinds && !allowedFilterKinds.includes("Relation")) fieldSchema = z.never();
2263
+ if (allowedFilterKinds && !allowedFilterKinds.includes("Relation")) fieldSchema = z$1.never();
2263
2264
  else {
2264
- fieldSchema = z.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts).optional());
2265
- if (fieldDef.array) fieldSchema = z.strictObject({
2265
+ fieldSchema = z$1.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts).optional());
2266
+ if (fieldDef.array) fieldSchema = z$1.strictObject({
2266
2267
  some: fieldSchema.optional(),
2267
2268
  every: fieldSchema.optional(),
2268
2269
  none: fieldSchema.optional()
2269
2270
  });
2270
2271
  else {
2271
2272
  fieldSchema = this.nullableIf(fieldSchema, !fieldDef.array && !!fieldDef.optional);
2272
- fieldSchema = z.union([fieldSchema, z.strictObject({
2273
+ fieldSchema = z$1.union([fieldSchema, z$1.strictObject({
2273
2274
  is: fieldSchema.optional(),
2274
2275
  isNot: fieldSchema.optional()
2275
2276
  })]);
@@ -2288,21 +2289,21 @@ var ZodSchemaFactory = class {
2288
2289
  }
2289
2290
  if (unique) {
2290
2291
  const uniqueFields = getUniqueFields(this.schema, model);
2291
- for (const uniqueField of uniqueFields) if ("defs" in uniqueField) fields[uniqueField.name] = z.object(Object.fromEntries(Object.entries(uniqueField.defs).map(([key, def]) => {
2292
+ for (const uniqueField of uniqueFields) if ("defs" in uniqueField) fields[uniqueField.name] = z$1.object(Object.fromEntries(Object.entries(uniqueField.defs).map(([key, def]) => {
2292
2293
  invariant(!def.relation, "unique field cannot be a relation");
2293
2294
  let fieldSchema;
2294
2295
  const enumDef = getEnum(this.schema, def.type);
2295
2296
  if (enumDef) if (Object.keys(enumDef.values).length > 0) fieldSchema = this.makeEnumFilterSchema(def.type, !!def.optional, !!def.array, false, void 0);
2296
- else fieldSchema = z.never();
2297
+ else fieldSchema = z$1.never();
2297
2298
  else fieldSchema = this.makePrimitiveFilterSchema(def.type, !!def.optional, false, void 0);
2298
2299
  return [key, fieldSchema];
2299
2300
  }))).optional();
2300
2301
  }
2301
- fields["$expr"] = z.custom((v) => typeof v === "function", { error: "\"$expr\" must be a function" }).optional();
2302
- fields["AND"] = this.orArray(z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
2303
- fields["OR"] = z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)).array().optional();
2304
- fields["NOT"] = this.orArray(z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
2305
- const baseWhere = z.strictObject(fields);
2302
+ fields["$expr"] = z$1.custom((v) => typeof v === "function", { error: "\"$expr\" must be a function" }).optional();
2303
+ fields["AND"] = this.orArray(z$1.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
2304
+ fields["OR"] = z$1.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)).array().optional();
2305
+ fields["NOT"] = this.orArray(z$1.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
2306
+ const baseWhere = z$1.strictObject(fields);
2306
2307
  let result = baseWhere;
2307
2308
  if (unique) {
2308
2309
  const uniqueFields = getUniqueFields(this.schema, model);
@@ -2328,26 +2329,26 @@ var ZodSchemaFactory = class {
2328
2329
  else if (getEnum(this.schema, fieldDef.type)) fieldSchemas[fieldName] = this.makeEnumFilterSchema(fieldDef.type, !!fieldDef.optional, !!fieldDef.array, false, void 0).optional();
2329
2330
  else if (fieldDef.array) fieldSchemas[fieldName] = this.makeArrayFilterSchema(fieldDef.type, void 0).optional();
2330
2331
  else fieldSchemas[fieldName] = this.makePrimitiveFilterSchema(fieldDef.type, !!fieldDef.optional, false, void 0).optional();
2331
- candidates.push(z.strictObject(fieldSchemas));
2332
+ candidates.push(z$1.strictObject(fieldSchemas));
2332
2333
  }
2333
- const recursiveSchema = z.lazy(() => this.makeTypedJsonFilterSchema(type, optional, false, allowedFilterKinds)).optional();
2334
- if (array) candidates.push(z.strictObject({
2334
+ const recursiveSchema = z$1.lazy(() => this.makeTypedJsonFilterSchema(type, optional, false, allowedFilterKinds)).optional();
2335
+ if (array) candidates.push(z$1.strictObject({
2335
2336
  some: recursiveSchema,
2336
2337
  every: recursiveSchema,
2337
2338
  none: recursiveSchema
2338
2339
  }));
2339
- else candidates.push(z.strictObject({
2340
+ else candidates.push(z$1.strictObject({
2340
2341
  is: recursiveSchema,
2341
2342
  isNot: recursiveSchema
2342
2343
  }));
2343
2344
  candidates.push(this.makeJsonFilterSchema(optional, allowedFilterKinds));
2344
2345
  if (optional) {
2345
- candidates.push(z.null());
2346
- candidates.push(z.instanceof(DbNullClass));
2347
- candidates.push(z.instanceof(JsonNullClass));
2348
- candidates.push(z.instanceof(AnyNullClass));
2346
+ candidates.push(z$1.null());
2347
+ candidates.push(z$1.instanceof(DbNullClass));
2348
+ candidates.push(z$1.instanceof(JsonNullClass));
2349
+ candidates.push(z$1.instanceof(AnyNullClass));
2349
2350
  }
2350
- const result = z.union(candidates);
2351
+ const result = z$1.union(candidates);
2351
2352
  this.registerSchema(`${type}Filter${this.filterSchemaSuffix({
2352
2353
  optional,
2353
2354
  array,
@@ -2356,7 +2357,7 @@ var ZodSchemaFactory = class {
2356
2357
  return result;
2357
2358
  }
2358
2359
  makeNullableTypedJsonMutationSchema(fieldSchema) {
2359
- return z.any().superRefine((value, ctx) => {
2360
+ return z$1.any().superRefine((value, ctx) => {
2360
2361
  if (value instanceof DbNullClass || value instanceof JsonNullClass || value === null || value === void 0) return;
2361
2362
  const parseResult = fieldSchema.safeParse(value);
2362
2363
  if (!parseResult.success) parseResult.error.issues.forEach((issue) => ctx.addIssue(issue));
@@ -2368,11 +2369,11 @@ var ZodSchemaFactory = class {
2368
2369
  makeEnumFilterSchema(enumName, optional, array, withAggregations, allowedFilterKinds) {
2369
2370
  const enumDef = getEnum(this.schema, enumName);
2370
2371
  invariant(enumDef, `Enum "${enumName}" not found in schema`);
2371
- const baseSchema = z.enum(Object.keys(enumDef.values));
2372
+ const baseSchema = z$1.enum(Object.keys(enumDef.values));
2372
2373
  let schema;
2373
2374
  if (array) schema = this.internalMakeArrayFilterSchema(baseSchema, allowedFilterKinds);
2374
2375
  else {
2375
- const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z.lazy(() => this.makeEnumFilterSchema(enumName, optional, array, withAggregations, allowedFilterKinds)), [
2376
+ const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z$1.lazy(() => this.makeEnumFilterSchema(enumName, optional, array, withAggregations, allowedFilterKinds)), [
2376
2377
  "equals",
2377
2378
  "in",
2378
2379
  "notIn",
@@ -2406,42 +2407,42 @@ var ZodSchemaFactory = class {
2406
2407
  has: elementSchema.optional(),
2407
2408
  hasEvery: elementSchema.array().optional(),
2408
2409
  hasSome: elementSchema.array().optional(),
2409
- isEmpty: z.boolean().optional()
2410
+ isEmpty: z$1.boolean().optional()
2410
2411
  };
2411
2412
  const filteredOperators = this.trimFilterOperators(operators, allowedFilterKinds);
2412
- return z.strictObject(filteredOperators);
2413
+ return z$1.strictObject(filteredOperators);
2413
2414
  }
2414
2415
  makePrimitiveFilterSchema(type, optional, withAggregations, allowedFilterKinds) {
2415
- return match(type).with("String", () => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds)).with(P.union("Int", "Float", "Decimal", "BigInt"), (type) => this.makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds)).with("Boolean", () => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)).with("DateTime", () => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)).with("Bytes", () => this.makeBytesFilterSchema(optional, withAggregations, allowedFilterKinds)).with("Json", () => this.makeJsonFilterSchema(optional, allowedFilterKinds)).with("Unsupported", () => z.never()).exhaustive();
2416
+ return match(type).with("String", () => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds)).with(P.union("Int", "Float", "Decimal", "BigInt"), (type) => this.makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds)).with("Boolean", () => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)).with("DateTime", () => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)).with("Bytes", () => this.makeBytesFilterSchema(optional, withAggregations, allowedFilterKinds)).with("Json", () => this.makeJsonFilterSchema(optional, allowedFilterKinds)).with("Unsupported", () => z$1.never()).exhaustive();
2416
2417
  }
2417
2418
  makeJsonValueSchema() {
2418
- const schema = z.union([
2419
- z.string(),
2420
- z.number(),
2421
- z.boolean(),
2422
- z.instanceof(JsonNullClass),
2423
- z.lazy(() => z.union([this.makeJsonValueSchema(), z.null()]).array()),
2424
- z.record(z.string(), z.lazy(() => z.union([this.makeJsonValueSchema(), z.null()])))
2419
+ const schema = z$1.union([
2420
+ z$1.string(),
2421
+ z$1.number(),
2422
+ z$1.boolean(),
2423
+ z$1.instanceof(JsonNullClass),
2424
+ z$1.lazy(() => z$1.union([this.makeJsonValueSchema(), z$1.null()]).array()),
2425
+ z$1.record(z$1.string(), z$1.lazy(() => z$1.union([this.makeJsonValueSchema(), z$1.null()])))
2425
2426
  ]);
2426
2427
  this.registerSchema("JsonValue", schema);
2427
2428
  return schema;
2428
2429
  }
2429
2430
  makeJsonFilterSchema(optional, allowedFilterKinds) {
2430
- if (allowedFilterKinds && !allowedFilterKinds.includes("Json")) return z.never();
2431
+ if (allowedFilterKinds && !allowedFilterKinds.includes("Json")) return z$1.never();
2431
2432
  const filterMembers = [
2432
2433
  this.makeJsonValueSchema(),
2433
- z.instanceof(DbNullClass),
2434
- z.instanceof(AnyNullClass)
2434
+ z$1.instanceof(DbNullClass),
2435
+ z$1.instanceof(AnyNullClass)
2435
2436
  ];
2436
- if (optional) filterMembers.push(z.null());
2437
- const filterValueSchema = z.union(filterMembers);
2438
- const schema = z.strictObject({
2439
- path: z.string().optional(),
2437
+ if (optional) filterMembers.push(z$1.null());
2438
+ const filterValueSchema = z$1.union(filterMembers);
2439
+ const schema = z$1.strictObject({
2440
+ path: z$1.string().optional(),
2440
2441
  equals: filterValueSchema.optional(),
2441
2442
  not: filterValueSchema.optional(),
2442
- string_contains: z.string().optional(),
2443
- string_starts_with: z.string().optional(),
2444
- string_ends_with: z.string().optional(),
2443
+ string_contains: z$1.string().optional(),
2444
+ string_starts_with: z$1.string().optional(),
2445
+ string_ends_with: z$1.string().optional(),
2445
2446
  mode: this.makeStringModeSchema().optional(),
2446
2447
  array_contains: filterValueSchema.optional(),
2447
2448
  array_starts_with: filterValueSchema.optional(),
@@ -2454,12 +2455,17 @@ var ZodSchemaFactory = class {
2454
2455
  return schema;
2455
2456
  }
2456
2457
  makeDateTimeValueSchema() {
2457
- const schema = z.union([z.iso.datetime(), z.date()]);
2458
+ const schema = z$1.union([
2459
+ z$1.iso.datetime(),
2460
+ z$1.iso.date(),
2461
+ z$1.date()
2462
+ ]);
2458
2463
  this.registerSchema("DateTime", schema);
2459
2464
  return schema;
2460
2465
  }
2461
2466
  makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds) {
2462
- const schema = this.makeCommonPrimitiveFilterSchema(this.makeDateTimeValueSchema(), optional, () => z.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)), withAggregations ? [
2467
+ const filterValueSchema = this.makeDateTimeValueSchema();
2468
+ const schema = this.makeCommonPrimitiveFilterSchema(filterValueSchema, optional, () => z$1.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)), withAggregations ? [
2463
2469
  "_count",
2464
2470
  "_min",
2465
2471
  "_max"
@@ -2472,12 +2478,12 @@ var ZodSchemaFactory = class {
2472
2478
  return schema;
2473
2479
  }
2474
2480
  makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds) {
2475
- const components = this.makeCommonPrimitiveFilterComponents(z.boolean(), optional, () => z.lazy(() => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)), ["equals", "not"], withAggregations ? [
2481
+ const components = this.makeCommonPrimitiveFilterComponents(z$1.boolean(), optional, () => z$1.lazy(() => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)), ["equals", "not"], withAggregations ? [
2476
2482
  "_count",
2477
2483
  "_min",
2478
2484
  "_max"
2479
2485
  ] : void 0, allowedFilterKinds);
2480
- const schema = this.createUnionFilterSchema(z.boolean(), optional, components, allowedFilterKinds);
2486
+ const schema = this.createUnionFilterSchema(z$1.boolean(), optional, components, allowedFilterKinds);
2481
2487
  this.registerSchema(`BooleanFilter${this.filterSchemaSuffix({
2482
2488
  optional,
2483
2489
  allowedFilterKinds,
@@ -2486,8 +2492,8 @@ var ZodSchemaFactory = class {
2486
2492
  return schema;
2487
2493
  }
2488
2494
  makeBytesFilterSchema(optional, withAggregations, allowedFilterKinds) {
2489
- const baseSchema = z.instanceof(Uint8Array);
2490
- const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z.instanceof(Uint8Array), [
2495
+ const baseSchema = z$1.instanceof(Uint8Array);
2496
+ const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z$1.instanceof(Uint8Array), [
2491
2497
  "equals",
2492
2498
  "in",
2493
2499
  "notIn",
@@ -2535,7 +2541,7 @@ var ZodSchemaFactory = class {
2535
2541
  return this.createUnionFilterSchema(baseSchema, optional, components, allowedFilterKinds);
2536
2542
  }
2537
2543
  makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds) {
2538
- const schema = this.makeCommonPrimitiveFilterSchema(this.makeScalarSchema(type), optional, () => z.lazy(() => this.makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds)), withAggregations ? [
2544
+ const schema = this.makeCommonPrimitiveFilterSchema(this.makeScalarSchema(type), optional, () => z$1.lazy(() => this.makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds)), withAggregations ? [
2539
2545
  "_count",
2540
2546
  "_avg",
2541
2547
  "_sum",
@@ -2550,15 +2556,15 @@ var ZodSchemaFactory = class {
2550
2556
  return schema;
2551
2557
  }
2552
2558
  makeStringFilterSchema(optional, withAggregations, allowedFilterKinds) {
2553
- const baseComponents = this.makeCommonPrimitiveFilterComponents(z.string(), optional, () => z.lazy(() => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds)), void 0, withAggregations ? [
2559
+ const baseComponents = this.makeCommonPrimitiveFilterComponents(z$1.string(), optional, () => z$1.lazy(() => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds)), void 0, withAggregations ? [
2554
2560
  "_count",
2555
2561
  "_min",
2556
2562
  "_max"
2557
2563
  ] : void 0, allowedFilterKinds);
2558
2564
  const stringSpecificOperators = {
2559
- startsWith: z.string().optional(),
2560
- endsWith: z.string().optional(),
2561
- contains: z.string().optional(),
2565
+ startsWith: z$1.string().optional(),
2566
+ endsWith: z$1.string().optional(),
2567
+ contains: z$1.string().optional(),
2562
2568
  ...this.providerSupportsCaseSensitivity ? { mode: this.makeStringModeSchema().optional() } : {}
2563
2569
  };
2564
2570
  const filteredStringOperators = this.trimFilterOperators(stringSpecificOperators, allowedFilterKinds);
@@ -2566,7 +2572,7 @@ var ZodSchemaFactory = class {
2566
2572
  ...baseComponents,
2567
2573
  ...filteredStringOperators
2568
2574
  };
2569
- const schema = this.createUnionFilterSchema(z.string(), optional, allComponents, allowedFilterKinds);
2575
+ const schema = this.createUnionFilterSchema(z$1.string(), optional, allComponents, allowedFilterKinds);
2570
2576
  this.registerSchema(`StringFilter${this.filterSchemaSuffix({
2571
2577
  optional,
2572
2578
  allowedFilterKinds,
@@ -2575,20 +2581,20 @@ var ZodSchemaFactory = class {
2575
2581
  return schema;
2576
2582
  }
2577
2583
  makeStringModeSchema() {
2578
- return z.union([z.literal("default"), z.literal("insensitive")]);
2584
+ return z$1.union([z$1.literal("default"), z$1.literal("insensitive")]);
2579
2585
  }
2580
2586
  makeSelectSchema(model, options) {
2581
2587
  const fields = {};
2582
2588
  for (const [field, fieldDef] of this.getModelFields(model)) if (fieldDef.relation) {
2583
2589
  if (!this.shouldIncludeRelations(options)) continue;
2584
2590
  if (this.isModelAllowed(fieldDef.type)) fields[field] = this.makeRelationSelectIncludeSchema(model, field, options).optional();
2585
- } else fields[field] = z.boolean().optional();
2591
+ } else fields[field] = z$1.boolean().optional();
2586
2592
  if (this.shouldIncludeRelations(options)) {
2587
2593
  const _countSchema = this.makeCountSelectionSchema(model, options);
2588
- if (!(_countSchema instanceof z.ZodNever)) fields["_count"] = _countSchema;
2594
+ if (!(_countSchema instanceof z$1.ZodNever)) fields["_count"] = _countSchema;
2589
2595
  }
2590
2596
  this.addExtResultFields(model, fields);
2591
- const result = z.strictObject(fields);
2597
+ const result = z$1.strictObject(fields);
2592
2598
  this.registerSchema(`${model}Select`, result);
2593
2599
  return result;
2594
2600
  }
@@ -2597,24 +2603,24 @@ var ZodSchemaFactory = class {
2597
2603
  const toManyRelations = Object.values(modelDef.fields).filter((def) => def.relation && def.array);
2598
2604
  if (toManyRelations.length > 0) {
2599
2605
  const nextOpts = this.nextOptions(options);
2600
- const schema = z.union([z.literal(true), z.strictObject({ select: z.strictObject(toManyRelations.reduce((acc, fieldDef) => ({
2606
+ const schema = z$1.union([z$1.literal(true), z$1.strictObject({ select: z$1.strictObject(toManyRelations.reduce((acc, fieldDef) => ({
2601
2607
  ...acc,
2602
- [fieldDef.name]: z.union([z.boolean(), z.strictObject({ where: this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts) })]).optional()
2608
+ [fieldDef.name]: z$1.union([z$1.boolean(), z$1.strictObject({ where: this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts) })]).optional()
2603
2609
  }), {})) })]).optional();
2604
2610
  this.registerSchema(`${model}CountSelection`, schema);
2605
2611
  return schema;
2606
- } else return z.never();
2612
+ } else return z$1.never();
2607
2613
  }
2608
2614
  makeRelationSelectIncludeSchema(model, field, options) {
2609
2615
  const fieldDef = requireField(this.schema, model, field);
2610
2616
  const nextOpts = this.nextOptions(options);
2611
- let objSchema = z.strictObject({
2612
- ...fieldDef.array || fieldDef.optional ? { where: z.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts)).optional() } : {},
2613
- select: z.lazy(() => this.makeSelectSchema(fieldDef.type, nextOpts)).optional().nullable(),
2614
- include: z.lazy(() => this.makeIncludeSchema(fieldDef.type, nextOpts)).optional().nullable(),
2615
- omit: z.lazy(() => this.makeOmitSchema(fieldDef.type)).optional().nullable(),
2617
+ let objSchema = z$1.strictObject({
2618
+ ...fieldDef.array || fieldDef.optional ? { where: z$1.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts)).optional() } : {},
2619
+ select: z$1.lazy(() => this.makeSelectSchema(fieldDef.type, nextOpts)).optional().nullable(),
2620
+ include: z$1.lazy(() => this.makeIncludeSchema(fieldDef.type, nextOpts)).optional().nullable(),
2621
+ omit: z$1.lazy(() => this.makeOmitSchema(fieldDef.type)).optional().nullable(),
2616
2622
  ...fieldDef.array ? {
2617
- orderBy: z.lazy(() => this.orArray(this.makeOrderBySchema(fieldDef.type, true, false, nextOpts), true)).optional(),
2623
+ orderBy: z$1.lazy(() => this.orArray(this.makeOrderBySchema(fieldDef.type, true, false, nextOpts), true)).optional(),
2618
2624
  skip: this.makeSkipSchema().optional(),
2619
2625
  take: this.makeTakeSchema().optional(),
2620
2626
  cursor: this.makeCursorSchema(fieldDef.type, nextOpts).optional(),
@@ -2624,16 +2630,16 @@ var ZodSchemaFactory = class {
2624
2630
  objSchema = this.refineForSelectIncludeMutuallyExclusive(objSchema);
2625
2631
  objSchema = this.refineForSelectOmitMutuallyExclusive(objSchema);
2626
2632
  objSchema = this.refineForSelectHasTruthyField(objSchema);
2627
- const result = z.union([z.boolean(), objSchema]);
2633
+ const result = z$1.union([z$1.boolean(), objSchema]);
2628
2634
  this.registerSchema(`${model}${upperCaseFirst(field)}RelationInput`, result);
2629
2635
  return result;
2630
2636
  }
2631
2637
  makeOmitSchema(model) {
2632
2638
  const fields = {};
2633
- for (const [field, fieldDef] of this.getModelFields(model)) if (!fieldDef.relation) if (this.options.allowQueryTimeOmitOverride !== false) fields[field] = z.boolean().optional();
2634
- else fields[field] = z.literal(true).optional();
2639
+ for (const [field, fieldDef] of this.getModelFields(model)) if (!fieldDef.relation) if (this.options.allowQueryTimeOmitOverride !== false) fields[field] = z$1.boolean().optional();
2640
+ else fields[field] = z$1.literal(true).optional();
2635
2641
  this.addExtResultFields(model, fields);
2636
- const result = z.strictObject(fields);
2642
+ const result = z$1.strictObject(fields);
2637
2643
  this.registerSchema(`${model}OmitInput`, result);
2638
2644
  return result;
2639
2645
  }
@@ -2642,7 +2648,7 @@ var ZodSchemaFactory = class {
2642
2648
  const resultConfig = plugin.result;
2643
2649
  if (resultConfig) {
2644
2650
  const modelConfig = resultConfig[lowerCaseFirst(model)];
2645
- if (modelConfig) for (const field of Object.keys(modelConfig)) fields[field] = z.boolean().optional();
2651
+ if (modelConfig) for (const field of Object.keys(modelConfig)) fields[field] = z$1.boolean().optional();
2646
2652
  }
2647
2653
  }
2648
2654
  }
@@ -2658,26 +2664,26 @@ var ZodSchemaFactory = class {
2658
2664
  }
2659
2665
  if (this.shouldIncludeRelations(options)) {
2660
2666
  const _countSchema = this.makeCountSelectionSchema(model, options);
2661
- if (!(_countSchema instanceof z.ZodNever)) fields["_count"] = _countSchema;
2667
+ if (!(_countSchema instanceof z$1.ZodNever)) fields["_count"] = _countSchema;
2662
2668
  }
2663
- const result = z.strictObject(fields);
2669
+ const result = z$1.strictObject(fields);
2664
2670
  this.registerSchema(`${model}Include`, result);
2665
2671
  return result;
2666
2672
  }
2667
2673
  makeOrderBySchema(model, withRelation, WithAggregation, options) {
2668
2674
  const fields = {};
2669
- const sort = z.union([z.literal("asc"), z.literal("desc")]);
2675
+ const sort = z$1.union([z$1.literal("asc"), z$1.literal("desc")]);
2670
2676
  const refineAtMostOneKey = (s) => s.refine((v) => Object.keys(v).length <= 1, { message: "Each orderBy element must have at most one key" });
2671
2677
  const nextOpts = this.nextOptions(options);
2672
2678
  for (const [field, fieldDef] of this.getModelFields(model)) if (fieldDef.relation) {
2673
- if (withRelation && this.shouldIncludeRelations(options)) fields[field] = z.lazy(() => {
2679
+ if (withRelation && this.shouldIncludeRelations(options)) fields[field] = z$1.lazy(() => {
2674
2680
  let relationOrderBy = this.makeOrderBySchema(fieldDef.type, withRelation, WithAggregation, nextOpts);
2675
2681
  if (fieldDef.array) relationOrderBy = refineAtMostOneKey(relationOrderBy.safeExtend({ _count: sort }));
2676
2682
  return relationOrderBy;
2677
2683
  }).optional();
2678
- } else if (fieldDef.optional) fields[field] = z.union([sort, z.strictObject({
2684
+ } else if (fieldDef.optional) fields[field] = z$1.union([sort, z$1.strictObject({
2679
2685
  sort,
2680
- nulls: z.union([z.literal("first"), z.literal("last")])
2686
+ nulls: z$1.union([z$1.literal("first"), z$1.literal("last")])
2681
2687
  })]).optional();
2682
2688
  else fields[field] = sort.optional();
2683
2689
  if (WithAggregation) for (const agg of [
@@ -2686,8 +2692,8 @@ var ZodSchemaFactory = class {
2686
2692
  "_sum",
2687
2693
  "_min",
2688
2694
  "_max"
2689
- ]) fields[agg] = z.lazy(() => this.makeOrderBySchema(model, true, false, options).optional());
2690
- const schema = refineAtMostOneKey(z.strictObject(fields));
2695
+ ]) fields[agg] = z$1.lazy(() => this.makeOrderBySchema(model, true, false, options).optional());
2696
+ const schema = refineAtMostOneKey(z$1.strictObject(fields));
2691
2697
  let schemaId = `${model}OrderBy`;
2692
2698
  if (withRelation) schemaId += "WithRelation";
2693
2699
  if (WithAggregation) schemaId += "WithAggregation";
@@ -2697,7 +2703,7 @@ var ZodSchemaFactory = class {
2697
2703
  }
2698
2704
  makeDistinctSchema(model) {
2699
2705
  const nonRelationFields = this.getModelFields(model).filter(([, def]) => !def.relation).map(([name]) => name);
2700
- const schema = nonRelationFields.length > 0 ? this.orArray(z.enum(nonRelationFields), true) : z.never();
2706
+ const schema = nonRelationFields.length > 0 ? this.orArray(z$1.enum(nonRelationFields), true) : z$1.never();
2701
2707
  this.registerSchema(`${model}DistinctInput`, schema);
2702
2708
  return schema;
2703
2709
  }
@@ -2708,7 +2714,7 @@ var ZodSchemaFactory = class {
2708
2714
  }
2709
2715
  makeCreateSchema(model, options) {
2710
2716
  const dataSchema = this.makeCreateDataSchema(model, false, [], false, options);
2711
- const baseSchema = z.strictObject({
2717
+ const baseSchema = z$1.strictObject({
2712
2718
  data: dataSchema,
2713
2719
  select: this.makeSelectSchema(model, options).optional().nullable(),
2714
2720
  include: this.makeIncludeSchema(model, options).optional().nullable(),
@@ -2757,7 +2763,7 @@ var ZodSchemaFactory = class {
2757
2763
  const oppositeFieldDef = requireField(this.schema, fieldDef.type, oppositeField);
2758
2764
  if (oppositeFieldDef.relation?.fields) excludeFields.push(...oppositeFieldDef.relation.fields);
2759
2765
  }
2760
- let fieldSchema = z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "create", nextOpts));
2766
+ let fieldSchema = z$1.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "create", nextOpts));
2761
2767
  if (fieldDef.optional || fieldDef.array) fieldSchema = fieldSchema.optional();
2762
2768
  else {
2763
2769
  let allFksOptional = false;
@@ -2774,23 +2780,23 @@ var ZodSchemaFactory = class {
2774
2780
  let fieldSchema = this.makeScalarSchema(fieldDef.type, fieldDef.attributes);
2775
2781
  if (fieldDef.array) {
2776
2782
  fieldSchema = ZodUtils.addListValidation(fieldSchema.array(), fieldDef.attributes);
2777
- fieldSchema = z.union([fieldSchema, z.strictObject({ set: fieldSchema })]).optional();
2783
+ fieldSchema = z$1.union([fieldSchema, z$1.strictObject({ set: fieldSchema })]).optional();
2778
2784
  }
2779
2785
  if (fieldDef.optional || fieldHasDefaultValue(fieldDef)) fieldSchema = fieldSchema.optional();
2780
- if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z.union([fieldSchema, z.instanceof(DbNullClass)]);
2786
+ if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z$1.union([fieldSchema, z$1.instanceof(DbNullClass)]);
2781
2787
  else if (this.isTypeDefType(fieldDef.type)) fieldSchema = this.makeNullableTypedJsonMutationSchema(fieldSchema);
2782
2788
  else fieldSchema = fieldSchema.nullable();
2783
2789
  uncheckedVariantFields[field] = fieldSchema;
2784
2790
  if (!fieldDef.foreignKeyFor) checkedVariantFields[field] = fieldSchema;
2785
2791
  }
2786
2792
  });
2787
- const uncheckedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(uncheckedVariantFields), modelDef.attributes) : z.strictObject(uncheckedVariantFields);
2788
- const checkedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(checkedVariantFields), modelDef.attributes) : z.strictObject(checkedVariantFields);
2789
- const result = !hasRelation ? this.orArray(uncheckedCreateSchema, canBeArray) : z.union([
2793
+ const uncheckedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z$1.strictObject(uncheckedVariantFields), modelDef.attributes) : z$1.strictObject(uncheckedVariantFields);
2794
+ const checkedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z$1.strictObject(checkedVariantFields), modelDef.attributes) : z$1.strictObject(checkedVariantFields);
2795
+ const result = !hasRelation ? this.orArray(uncheckedCreateSchema, canBeArray) : z$1.union([
2790
2796
  uncheckedCreateSchema,
2791
2797
  checkedCreateSchema,
2792
- ...canBeArray ? [z.array(uncheckedCreateSchema)] : [],
2793
- ...canBeArray ? [z.array(checkedCreateSchema)] : []
2798
+ ...canBeArray ? [z$1.array(uncheckedCreateSchema)] : [],
2799
+ ...canBeArray ? [z$1.array(checkedCreateSchema)] : []
2794
2800
  ]);
2795
2801
  const idParts = [`${model}CreateData`];
2796
2802
  if (canBeArray) idParts.push("Array");
@@ -2815,17 +2821,17 @@ var ZodSchemaFactory = class {
2815
2821
  fields["disconnect"] = this.makeDisconnectDataSchema(fieldType, array, options).optional();
2816
2822
  fields["delete"] = this.makeDeleteRelationDataSchema(fieldType, array, true, options).optional();
2817
2823
  }
2818
- fields["update"] = array ? this.orArray(z.strictObject({
2824
+ fields["update"] = array ? this.orArray(z$1.strictObject({
2819
2825
  where: this.makeWhereSchema(fieldType, true, false, false, options),
2820
2826
  data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
2821
- }), true).optional() : z.union([z.strictObject({
2827
+ }), true).optional() : z$1.union([z$1.strictObject({
2822
2828
  where: this.makeWhereSchema(fieldType, false, false, false, options).optional(),
2823
2829
  data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
2824
2830
  }), this.makeUpdateDataSchema(fieldType, withoutFields, false, options)]).optional();
2825
2831
  if (canCreateModel) {
2826
2832
  let upsertWhere = this.makeWhereSchema(fieldType, true, false, false, options);
2827
2833
  if (!fieldDef.array) upsertWhere = upsertWhere.optional();
2828
- fields["upsert"] = this.orArray(z.strictObject({
2834
+ fields["upsert"] = this.orArray(z$1.strictObject({
2829
2835
  where: upsertWhere,
2830
2836
  create: this.makeCreateDataSchema(fieldType, false, withoutFields, false, options),
2831
2837
  update: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
@@ -2833,14 +2839,14 @@ var ZodSchemaFactory = class {
2833
2839
  }
2834
2840
  if (array) {
2835
2841
  fields["set"] = this.makeSetDataSchema(fieldType, true, options).optional();
2836
- fields["updateMany"] = this.orArray(z.strictObject({
2842
+ fields["updateMany"] = this.orArray(z$1.strictObject({
2837
2843
  where: this.makeWhereSchema(fieldType, false, true, false, options),
2838
2844
  data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
2839
2845
  }), true).optional();
2840
2846
  fields["deleteMany"] = this.makeDeleteRelationDataSchema(fieldType, true, false, options).optional();
2841
2847
  }
2842
2848
  }
2843
- return z.strictObject(fields);
2849
+ return z$1.strictObject(fields);
2844
2850
  }
2845
2851
  makeSetDataSchema(model, canBeArray, options) {
2846
2852
  return this.orArray(this.makeWhereSchema(model, true, false, false, options), canBeArray);
@@ -2850,23 +2856,23 @@ var ZodSchemaFactory = class {
2850
2856
  }
2851
2857
  makeDisconnectDataSchema(model, canBeArray, options) {
2852
2858
  if (canBeArray) return this.orArray(this.makeWhereSchema(model, true, false, false, options), canBeArray);
2853
- else return z.union([z.boolean(), this.makeWhereSchema(model, false, false, false, options)]);
2859
+ else return z$1.union([z$1.boolean(), this.makeWhereSchema(model, false, false, false, options)]);
2854
2860
  }
2855
2861
  makeDeleteRelationDataSchema(model, toManyRelation, uniqueFilter, options) {
2856
- return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter, false, false, options), true) : z.union([z.boolean(), this.makeWhereSchema(model, uniqueFilter, false, false, options)]);
2862
+ return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter, false, false, options), true) : z$1.union([z$1.boolean(), this.makeWhereSchema(model, uniqueFilter, false, false, options)]);
2857
2863
  }
2858
2864
  makeConnectOrCreateDataSchema(model, canBeArray, withoutFields, options) {
2859
2865
  const whereSchema = this.makeWhereSchema(model, true, false, false, options);
2860
2866
  const createSchema = this.makeCreateDataSchema(model, false, withoutFields, false, options);
2861
- return this.orArray(z.strictObject({
2867
+ return this.orArray(z$1.strictObject({
2862
2868
  where: whereSchema,
2863
2869
  create: createSchema
2864
2870
  }), canBeArray);
2865
2871
  }
2866
2872
  makeCreateManyPayloadSchema(model, withoutFields, options) {
2867
- const schema = z.strictObject({
2873
+ const schema = z$1.strictObject({
2868
2874
  data: this.makeCreateDataSchema(model, true, withoutFields, true, options),
2869
- skipDuplicates: z.boolean().optional()
2875
+ skipDuplicates: z$1.boolean().optional()
2870
2876
  });
2871
2877
  const idParts = [`${model}CreateManyPayload`];
2872
2878
  if (withoutFields.length) idParts.push(`Without${withoutFields.slice().sort().join("")}`);
@@ -2874,7 +2880,7 @@ var ZodSchemaFactory = class {
2874
2880
  return schema;
2875
2881
  }
2876
2882
  makeUpdateSchema(model, options) {
2877
- const baseSchema = z.strictObject({
2883
+ const baseSchema = z$1.strictObject({
2878
2884
  where: this.makeWhereSchema(model, true, false, false, options),
2879
2885
  data: this.makeUpdateDataSchema(model, [], false, options),
2880
2886
  select: this.makeSelectSchema(model, options).optional().nullable(),
@@ -2889,10 +2895,10 @@ var ZodSchemaFactory = class {
2889
2895
  return schema;
2890
2896
  }
2891
2897
  makeUpdateManySchema(model, options) {
2892
- const result = this.mergePluginArgsSchema(z.strictObject({
2898
+ const result = this.mergePluginArgsSchema(z$1.strictObject({
2893
2899
  where: this.makeWhereSchema(model, false, false, false, options).optional(),
2894
2900
  data: this.makeUpdateDataSchema(model, [], true, options),
2895
- limit: z.number().int().nonnegative().optional()
2901
+ limit: z$1.number().int().nonnegative().optional()
2896
2902
  }), "updateMany");
2897
2903
  this.registerSchema(`${model}UpdateManyArgs`, result);
2898
2904
  return result;
@@ -2908,7 +2914,7 @@ var ZodSchemaFactory = class {
2908
2914
  return schema;
2909
2915
  }
2910
2916
  makeUpsertSchema(model, options) {
2911
- const baseSchema = z.strictObject({
2917
+ const baseSchema = z$1.strictObject({
2912
2918
  where: this.makeWhereSchema(model, true, false, false, options),
2913
2919
  create: this.makeCreateDataSchema(model, false, [], false, options),
2914
2920
  update: this.makeUpdateDataSchema(model, [], false, options),
@@ -2944,27 +2950,27 @@ var ZodSchemaFactory = class {
2944
2950
  const oppositeFieldDef = requireField(this.schema, fieldDef.type, oppositeField);
2945
2951
  if (oppositeFieldDef.relation?.fields) excludeFields.push(...oppositeFieldDef.relation.fields);
2946
2952
  }
2947
- let fieldSchema = z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "update", nextOpts)).optional();
2953
+ let fieldSchema = z$1.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "update", nextOpts)).optional();
2948
2954
  if (fieldDef.optional && !fieldDef.array) fieldSchema = fieldSchema.nullable();
2949
2955
  checkedVariantFields[field] = fieldSchema;
2950
2956
  if (fieldDef.array || !fieldDef.relation.references) uncheckedVariantFields[field] = fieldSchema;
2951
2957
  } else {
2952
2958
  let fieldSchema = this.makeScalarSchema(fieldDef.type, fieldDef.attributes);
2953
- if (this.isNumericField(fieldDef)) fieldSchema = z.union([fieldSchema, z.object({
2954
- set: this.nullableIf(z.number().optional(), !!fieldDef.optional).optional(),
2955
- increment: z.number().optional(),
2956
- decrement: z.number().optional(),
2957
- multiply: z.number().optional(),
2958
- divide: z.number().optional()
2959
+ if (this.isNumericField(fieldDef)) fieldSchema = z$1.union([fieldSchema, z$1.object({
2960
+ set: this.nullableIf(z$1.number().optional(), !!fieldDef.optional).optional(),
2961
+ increment: z$1.number().optional(),
2962
+ decrement: z$1.number().optional(),
2963
+ multiply: z$1.number().optional(),
2964
+ divide: z$1.number().optional()
2959
2965
  }).refine((v) => Object.keys(v).length === 1, "Only one of \"set\", \"increment\", \"decrement\", \"multiply\", or \"divide\" can be provided")]);
2960
2966
  if (fieldDef.array) {
2961
2967
  const arraySchema = ZodUtils.addListValidation(fieldSchema.array(), fieldDef.attributes);
2962
- fieldSchema = z.union([arraySchema, z.object({
2968
+ fieldSchema = z$1.union([arraySchema, z$1.object({
2963
2969
  set: arraySchema.optional(),
2964
- push: z.union([fieldSchema, fieldSchema.array()]).optional()
2970
+ push: z$1.union([fieldSchema, fieldSchema.array()]).optional()
2965
2971
  }).refine((v) => Object.keys(v).length === 1, "Only one of \"set\", \"push\" can be provided")]);
2966
2972
  }
2967
- if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z.union([fieldSchema, z.instanceof(DbNullClass)]);
2973
+ if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z$1.union([fieldSchema, z$1.instanceof(DbNullClass)]);
2968
2974
  else if (this.isTypeDefType(fieldDef.type)) fieldSchema = this.makeNullableTypedJsonMutationSchema(fieldSchema);
2969
2975
  else fieldSchema = fieldSchema.nullable();
2970
2976
  fieldSchema = fieldSchema.optional();
@@ -2972,9 +2978,9 @@ var ZodSchemaFactory = class {
2972
2978
  if (!fieldDef.foreignKeyFor) checkedVariantFields[field] = fieldSchema;
2973
2979
  }
2974
2980
  });
2975
- const uncheckedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(uncheckedVariantFields), modelDef.attributes) : z.strictObject(uncheckedVariantFields);
2976
- const checkedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(checkedVariantFields), modelDef.attributes) : z.strictObject(checkedVariantFields);
2977
- const result = !hasRelation ? uncheckedUpdateSchema : z.union([uncheckedUpdateSchema, checkedUpdateSchema]);
2981
+ const uncheckedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z$1.strictObject(uncheckedVariantFields), modelDef.attributes) : z$1.strictObject(uncheckedVariantFields);
2982
+ const checkedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z$1.strictObject(checkedVariantFields), modelDef.attributes) : z$1.strictObject(checkedVariantFields);
2983
+ const result = !hasRelation ? uncheckedUpdateSchema : z$1.union([uncheckedUpdateSchema, checkedUpdateSchema]);
2978
2984
  const idParts = [`${model}UpdateData`];
2979
2985
  if (withoutRelationFields) idParts.push("WithoutRelation");
2980
2986
  if (withoutFields.length) idParts.push(`Without${withoutFields.slice().sort().join("")}`);
@@ -2982,7 +2988,7 @@ var ZodSchemaFactory = class {
2982
2988
  return result;
2983
2989
  }
2984
2990
  makeDeleteSchema(model, options) {
2985
- const baseSchema = z.strictObject({
2991
+ const baseSchema = z$1.strictObject({
2986
2992
  where: this.makeWhereSchema(model, true, false, false, options),
2987
2993
  select: this.makeSelectSchema(model, options).optional().nullable(),
2988
2994
  include: this.makeIncludeSchema(model, options).optional().nullable(),
@@ -2996,15 +3002,15 @@ var ZodSchemaFactory = class {
2996
3002
  return schema;
2997
3003
  }
2998
3004
  makeDeleteManySchema(model, options) {
2999
- const result = this.mergePluginArgsSchema(z.strictObject({
3005
+ const result = this.mergePluginArgsSchema(z$1.strictObject({
3000
3006
  where: this.makeWhereSchema(model, false, false, false, options).optional(),
3001
- limit: z.number().int().nonnegative().optional()
3007
+ limit: z$1.number().int().nonnegative().optional()
3002
3008
  }), "deleteMany").optional();
3003
3009
  this.registerSchema(`${model}DeleteManyArgs`, result);
3004
3010
  return result;
3005
3011
  }
3006
3012
  makeCountSchema(model, options) {
3007
- const result = this.mergePluginArgsSchema(z.strictObject({
3013
+ const result = this.mergePluginArgsSchema(z$1.strictObject({
3008
3014
  where: this.makeWhereSchema(model, false, false, false, options).optional(),
3009
3015
  skip: this.makeSkipSchema().optional(),
3010
3016
  take: this.makeTakeSchema().optional(),
@@ -3015,10 +3021,10 @@ var ZodSchemaFactory = class {
3015
3021
  return result;
3016
3022
  }
3017
3023
  makeCountAggregateInputSchema(model) {
3018
- const schema = z.union([z.literal(true), z.strictObject({
3019
- _all: z.literal(true).optional(),
3024
+ const schema = z$1.union([z$1.literal(true), z$1.strictObject({
3025
+ _all: z$1.literal(true).optional(),
3020
3026
  ...this.getModelFields(model).reduce((acc, [field]) => {
3021
- acc[field] = z.literal(true).optional();
3027
+ acc[field] = z$1.literal(true).optional();
3022
3028
  return acc;
3023
3029
  }, {})
3024
3030
  })]);
@@ -3026,7 +3032,7 @@ var ZodSchemaFactory = class {
3026
3032
  return schema;
3027
3033
  }
3028
3034
  makeAggregateSchema(model, options) {
3029
- const result = this.mergePluginArgsSchema(z.strictObject({
3035
+ const result = this.mergePluginArgsSchema(z$1.strictObject({
3030
3036
  where: this.makeWhereSchema(model, false, false, false, options).optional(),
3031
3037
  skip: this.makeSkipSchema().optional(),
3032
3038
  take: this.makeTakeSchema().optional(),
@@ -3041,16 +3047,16 @@ var ZodSchemaFactory = class {
3041
3047
  return result;
3042
3048
  }
3043
3049
  makeSumAvgInputSchema(model) {
3044
- const schema = z.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
3045
- if (this.isNumericField(fieldDef)) acc[field] = z.literal(true).optional();
3050
+ const schema = z$1.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
3051
+ if (this.isNumericField(fieldDef)) acc[field] = z$1.literal(true).optional();
3046
3052
  return acc;
3047
3053
  }, {}));
3048
3054
  this.registerSchema(`${model}SumAvgAggregateInput`, schema);
3049
3055
  return schema;
3050
3056
  }
3051
3057
  makeMinMaxInputSchema(model) {
3052
- const schema = z.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
3053
- if (!fieldDef.relation && !fieldDef.array) acc[field] = z.literal(true).optional();
3058
+ const schema = z$1.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
3059
+ if (!fieldDef.relation && !fieldDef.array) acc[field] = z$1.literal(true).optional();
3054
3060
  return acc;
3055
3061
  }, {}));
3056
3062
  this.registerSchema(`${model}MinMaxAggregateInput`, schema);
@@ -3058,8 +3064,8 @@ var ZodSchemaFactory = class {
3058
3064
  }
3059
3065
  makeGroupBySchema(model, options) {
3060
3066
  const nonRelationFields = this.getModelFields(model).filter(([, def]) => !def.relation).map(([name]) => name);
3061
- const bySchema = nonRelationFields.length > 0 ? this.orArray(z.enum(nonRelationFields), true) : z.never();
3062
- const baseSchema = z.strictObject({
3067
+ const bySchema = nonRelationFields.length > 0 ? this.orArray(z$1.enum(nonRelationFields), true) : z$1.never();
3068
+ const baseSchema = z$1.strictObject({
3063
3069
  where: this.makeWhereSchema(model, false, false, false, options).optional(),
3064
3070
  orderBy: this.orArray(this.makeOrderBySchema(model, false, true, options), true).optional(),
3065
3071
  by: bySchema,
@@ -3111,7 +3117,7 @@ var ZodSchemaFactory = class {
3111
3117
  if (!procDef) throw createInternalError(`Procedure not found: ${procName}`);
3112
3118
  const shape = {};
3113
3119
  for (const param of Object.values(procDef.params ?? {})) shape[param.name] = this.makeProcedureParamSchema(param);
3114
- const schema = z.object(shape);
3120
+ const schema = z$1.object(shape);
3115
3121
  this.registerSchema(`${procName}ProcArgs`, schema);
3116
3122
  return schema;
3117
3123
  }
@@ -3119,10 +3125,10 @@ var ZodSchemaFactory = class {
3119
3125
  let schema;
3120
3126
  if (isTypeDef(this.schema, param.type)) schema = this.makeTypeDefSchema(param.type);
3121
3127
  else if (isEnum(this.schema, param.type)) schema = this.makeEnumSchema(param.type);
3122
- else if (param.type in (this.schema.models ?? {})) schema = z.record(z.string(), z.unknown());
3128
+ else if (param.type in (this.schema.models ?? {})) schema = z$1.record(z$1.string(), z$1.unknown());
3123
3129
  else {
3124
3130
  schema = this.makeScalarSchema(param.type);
3125
- if (schema instanceof z.ZodUnknown) throw createInternalError(`Unsupported procedure parameter type: ${param.type}`);
3131
+ if (schema instanceof z$1.ZodUnknown) throw createInternalError(`Unsupported procedure parameter type: ${param.type}`);
3126
3132
  }
3127
3133
  if (param.array) schema = schema.array();
3128
3134
  if (param.optional) schema = schema.optional();
@@ -3158,10 +3164,10 @@ var ZodSchemaFactory = class {
3158
3164
  return result;
3159
3165
  }
3160
3166
  makeSkipSchema() {
3161
- return z.number().int().nonnegative();
3167
+ return z$1.number().int().nonnegative();
3162
3168
  }
3163
3169
  makeTakeSchema() {
3164
- return z.number().int();
3170
+ return z$1.number().int();
3165
3171
  }
3166
3172
  refineForSelectIncludeMutuallyExclusive(schema) {
3167
3173
  return schema.refine((value) => !(value["select"] && value["include"]), "\"select\" and \"include\" cannot be used together");
@@ -3180,7 +3186,7 @@ var ZodSchemaFactory = class {
3180
3186
  return nullable ? schema.nullable() : schema;
3181
3187
  }
3182
3188
  orArray(schema, canBeArray) {
3183
- return canBeArray ? z.union([schema, z.array(schema)]) : schema;
3189
+ return canBeArray ? z$1.union([schema, z$1.array(schema)]) : schema;
3184
3190
  }
3185
3191
  isNumericField(fieldDef) {
3186
3192
  return NUMERIC_FIELD_TYPES.includes(fieldDef.type) && !fieldDef.array;
@@ -3236,10 +3242,10 @@ var ZodSchemaFactory = class {
3236
3242
  createUnionFilterSchema(valueSchema, optional, components, allowedFilterKinds) {
3237
3243
  if (Object.keys(components).length === 0) {
3238
3244
  if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return this.nullableIf(valueSchema, optional);
3239
- return z.never();
3245
+ return z$1.never();
3240
3246
  }
3241
- if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return z.union([this.nullableIf(valueSchema, optional), z.strictObject(components)]);
3242
- else return z.strictObject(components);
3247
+ if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return z$1.union([this.nullableIf(valueSchema, optional), z$1.strictObject(components)]);
3248
+ else return z$1.strictObject(components);
3243
3249
  }
3244
3250
  canCreateModel(model) {
3245
3251
  const modelDef = requireModel(this.schema, model);
@@ -5495,6 +5501,7 @@ var QueryNameMapper = class extends OperationNodeTransformer {
5495
5501
  modelToTableMap = /* @__PURE__ */ new Map();
5496
5502
  fieldToColumnMap = /* @__PURE__ */ new Map();
5497
5503
  enumTypeMap = /* @__PURE__ */ new Map();
5504
+ joinTableSchemaMap = /* @__PURE__ */ new Map();
5498
5505
  scopes = [];
5499
5506
  dialect;
5500
5507
  constructor(client) {
@@ -5513,6 +5520,13 @@ var QueryNameMapper = class extends OperationNodeTransformer {
5513
5520
  const mappedName = this.getMappedName(enumDef);
5514
5521
  if (mappedName) this.enumTypeMap.set(enumName, mappedName);
5515
5522
  }
5523
+ if (client.$schema.provider.type === "postgresql") for (const modelName of Object.keys(client.$schema.models)) for (const fieldDef of getModelFields(this.schema, modelName, { relations: true })) {
5524
+ const m2m = getManyToManyRelation(this.schema, modelName, fieldDef.name);
5525
+ if (m2m && !this.joinTableSchemaMap.has(m2m.joinTable)) {
5526
+ const owningModel = [modelName, m2m.otherModel].sort()[0];
5527
+ this.joinTableSchemaMap.set(m2m.joinTable, this.getTableSchema(owningModel) ?? "public");
5528
+ }
5529
+ }
5516
5530
  }
5517
5531
  get schema() {
5518
5532
  return this.client.$schema;
@@ -5776,8 +5790,9 @@ var QueryNameMapper = class extends OperationNodeTransformer {
5776
5790
  }
5777
5791
  getTableSchema(model) {
5778
5792
  if (this.schema.provider.type !== "postgresql") return;
5793
+ if (!this.schema.models[model]) return this.joinTableSchemaMap.get(model) ?? "public";
5779
5794
  let schema = this.schema.provider.defaultSchema ?? "public";
5780
- const schemaAttr = this.schema.models[model]?.attributes?.find((attr) => attr.name === "@@schema");
5795
+ const schemaAttr = this.schema.models[model].attributes?.find((attr) => attr.name === "@@schema");
5781
5796
  if (schemaAttr) {
5782
5797
  const mapArg = schemaAttr.args?.find((arg) => arg.name === "map");
5783
5798
  if (mapArg && mapArg.value.kind === "literal") schema = mapArg.value.value;
@@ -6834,9 +6849,9 @@ var ClientImpl = class ClientImpl {
6834
6849
  validateOptions(baseClient, options) {
6835
6850
  if (!baseClient && !options.skipValidationForComputedFields) this.validateComputedFieldsConfig(options);
6836
6851
  if (options.diagnostics) {
6837
- const parseResult = z$1.object({
6838
- slowQueryThresholdMs: z$1.number().nonnegative().optional(),
6839
- slowQueryMaxRecords: z$1.int().nonnegative().or(z$1.literal(Infinity)).optional()
6852
+ const parseResult = z.object({
6853
+ slowQueryThresholdMs: z.number().nonnegative().optional(),
6854
+ slowQueryMaxRecords: z.int().nonnegative().or(z.literal(Infinity)).optional()
6840
6855
  }).safeParse(options.diagnostics);
6841
6856
  if (!parseResult.success) throw createConfigError(`Invalid diagnostics configuration: ${formatError(parseResult.error)}`);
6842
6857
  }