@zenstackhq/orm 3.8.0-beta.2 → 3.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@ import { t as __exportAll } from "./chunk-CfYAbeIz.mjs";
2
2
  import { AnyNull, AnyNullClass, DbNull, DbNullClass, JsonNull, JsonNullClass } from "./common-types.mjs";
3
3
  import { clone, enumerate, invariant, isPlainObject, lowerCaseFirst, upperCaseFirst } from "@zenstackhq/common-helpers";
4
4
  import { AliasNode, AndNode, ColumnNode, ColumnUpdateNode, CompiledQuery, DefaultConnectionProvider, DefaultQueryExecutor, DeleteQueryNode, ExpressionWrapper, FromNode, IdentifierNode, InsertQueryNode, Kysely, Log, OperationNodeTransformer, OperationNodeVisitor, PrimitiveValueListNode, ReferenceNode, ReturningNode, SelectAllNode, SelectionNode, SingleConnectionProvider, TableNode, Transaction, UpdateQueryNode, ValueListNode, ValueNode, ValuesNode, WhereNode, createQueryId, expressionBuilder, sql } from "kysely";
5
- import z$1, { ZodObject, ZodType, z } from "zod";
5
+ import z, { ZodObject, ZodType, z as z$1 } from "zod";
6
6
  import { fromError } from "zod-validation-error/v4";
7
7
  import { P, match } from "ts-pattern";
8
8
  import { ExpressionUtils } from "@zenstackhq/schema";
@@ -1437,7 +1437,10 @@ var LateralJoinDialectBase = class extends BaseCrudDialect {
1437
1437
  return { [field]: fieldValue };
1438
1438
  }
1439
1439
  }));
1440
- if (typeof payload === "object" && payload.include && typeof payload.include === "object") Object.assign(objArgs, ...Object.entries(payload.include).filter(([, value]) => value).map(([field]) => ({ [field]: eb.ref(`${parentResultName}$${field}.$data`) })));
1440
+ if (typeof payload === "object" && payload.include && typeof payload.include === "object") Object.assign(objArgs, ...Object.entries(payload.include).filter(([, value]) => value).map(([field, value]) => {
1441
+ if (field === "_count") return { [field]: this.buildCountJson(relationModel, eb, relationModelAlias, value) };
1442
+ return { [field]: eb.ref(`${parentResultName}$${field}.$data`) };
1443
+ }));
1441
1444
  return objArgs;
1442
1445
  }
1443
1446
  buildRelationJoins(query, relationModel, relationModelAlias, payload, parentResultName) {
@@ -1832,7 +1835,7 @@ var PostgresCrudDialect = class PostgresCrudDialect extends LateralJoinDialectBa
1832
1835
  return this.eb.fn("trim", [expression, sql.lit("\"")]);
1833
1836
  }
1834
1837
  buildArrayLength(array) {
1835
- return this.eb.fn("array_length", [array]);
1838
+ return this.eb.fn("array_length", [array, sql.lit(1)]);
1836
1839
  }
1837
1840
  buildArrayValue(values, elemType) {
1838
1841
  const arr = sql`ARRAY[${sql.join(values, sql.raw(","))}]`;
@@ -2112,6 +2115,10 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
2112
2115
  } else return [sql.lit(field), this.fieldRef(relationModel, field, subQueryName, false)];
2113
2116
  }).flatMap((v) => v));
2114
2117
  if (typeof payload === "object" && payload.include && typeof payload.include === "object") objArgs.push(...Object.entries(payload.include).filter(([, value]) => value).map(([field, value]) => {
2118
+ if (field === "_count") {
2119
+ const subJson = this.buildCountJson(relationModel, eb, tmpAlias(`${parentAlias}$${relationField}`), value);
2120
+ return [sql.lit(field), subJson];
2121
+ }
2115
2122
  const subJson = this.buildRelationJSON(relationModel, eb, field, tmpAlias(`${parentAlias}$${relationField}`), value);
2116
2123
  return [sql.lit(field), subJson];
2117
2124
  }).flatMap((v) => v));
@@ -2287,7 +2294,7 @@ function createQuerySchemaFactory(clientOrSchema, options) {
2287
2294
  * @see https://github.com/zenstackhq/zenstack/issues/2631
2288
2295
  */
2289
2296
  function coercedDateTimeSchema() {
2290
- return z.preprocess((val) => {
2297
+ return z$1.preprocess((val) => {
2291
2298
  if (typeof val !== "string") return val;
2292
2299
  if (/^\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d\d(?::\d\d)?)?$/.test(val)) {
2293
2300
  const hasTz = val.endsWith("Z") || /[+-]\d\d(?::\d\d)?$/.test(val);
@@ -2296,10 +2303,10 @@ function coercedDateTimeSchema() {
2296
2303
  }
2297
2304
  const d = new Date(val);
2298
2305
  return isNaN(d.getTime()) ? val : d;
2299
- }, z.union([
2300
- z.iso.datetime(),
2301
- z.iso.date(),
2302
- z.date()
2306
+ }, z$1.union([
2307
+ z$1.iso.datetime(),
2308
+ z$1.iso.date(),
2309
+ z$1.date()
2303
2310
  ]));
2304
2311
  }
2305
2312
  /**
@@ -2307,7 +2314,7 @@ function coercedDateTimeSchema() {
2307
2314
  */
2308
2315
  var ZodSchemaFactory = class {
2309
2316
  schemaCache = /* @__PURE__ */ new Map();
2310
- schemaRegistry = z.registry();
2317
+ schemaRegistry = z$1.registry();
2311
2318
  allFilterKinds = [...new Set(Object.values(FILTER_PROPERTY_TO_KIND))];
2312
2319
  schema;
2313
2320
  options;
@@ -2399,7 +2406,7 @@ var ZodSchemaFactory = class {
2399
2406
  this.makeGroupBySchema(m);
2400
2407
  }
2401
2408
  for (const procName of Object.keys(this.schema.procedures ?? {})) if (this.isProcedureAllowed(procName)) this.makeProcedureArgsSchema(procName);
2402
- return z.toJSONSchema(this.schemaRegistry, { unrepresentable: "any" });
2409
+ return z$1.toJSONSchema(this.schemaRegistry, { unrepresentable: "any" });
2403
2410
  }
2404
2411
  get cacheStats() {
2405
2412
  return {
@@ -2428,13 +2435,13 @@ var ZodSchemaFactory = class {
2428
2435
  fields["omit"] = this.makeOmitSchema(model).optional().nullable();
2429
2436
  if (!unique) {
2430
2437
  fields["skip"] = this.makeSkipSchema().optional();
2431
- if (findOne) fields["take"] = z.literal(1).optional();
2438
+ if (findOne) fields["take"] = z$1.literal(1).optional();
2432
2439
  else fields["take"] = this.makeTakeSchema().optional();
2433
2440
  fields["orderBy"] = this.orArray(this.makeOrderBySchema(model, true, false, options), true).optional();
2434
2441
  fields["cursor"] = this.makeCursorSchema(model, options).optional();
2435
2442
  fields["distinct"] = this.makeDistinctSchema(model).optional();
2436
2443
  }
2437
- const baseSchema = z.strictObject(fields);
2444
+ const baseSchema = z$1.strictObject(fields);
2438
2445
  let result = this.mergePluginArgsSchema(baseSchema, operation);
2439
2446
  result = this.refineForSelectIncludeMutuallyExclusive(result);
2440
2447
  result = this.refineForSelectOmitMutuallyExclusive(result);
@@ -2444,7 +2451,7 @@ var ZodSchemaFactory = class {
2444
2451
  return result;
2445
2452
  }
2446
2453
  makeExistsSchema(model, options) {
2447
- const baseSchema = z.strictObject({ where: this.makeWhereSchema(model, false, false, false, options).optional() });
2454
+ const baseSchema = z$1.strictObject({ where: this.makeWhereSchema(model, false, false, false, options).optional() });
2448
2455
  const result = this.mergePluginArgsSchema(baseSchema, "exists").optional();
2449
2456
  this.registerSchema(`${model}ExistsArgs`, result);
2450
2457
  return result;
@@ -2452,31 +2459,31 @@ var ZodSchemaFactory = class {
2452
2459
  makeScalarSchema(type, attributes) {
2453
2460
  if (this.schema.typeDefs && type in this.schema.typeDefs) return this.makeTypeDefSchema(type);
2454
2461
  else if (this.schema.enums && type in this.schema.enums) return this.makeEnumSchema(type);
2455
- 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", () => {
2456
- return z.union([
2457
- this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z.number(), attributes) : z.number(),
2458
- ZodUtils.addDecimalValidation(z.instanceof(Decimal), attributes, this.extraValidationsEnabled),
2459
- ZodUtils.addDecimalValidation(z.string(), attributes, this.extraValidationsEnabled)
2462
+ 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", () => {
2463
+ return z$1.union([
2464
+ this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z$1.number(), attributes) : z$1.number(),
2465
+ ZodUtils.addDecimalValidation(z$1.instanceof(Decimal), attributes, this.extraValidationsEnabled),
2466
+ ZodUtils.addDecimalValidation(z$1.string(), attributes, this.extraValidationsEnabled)
2460
2467
  ]);
2461
- }).with("DateTime", () => this.makeDateTimeValueSchema()).with("Bytes", () => z.instanceof(Uint8Array)).with("Json", () => this.makeJsonValueSchema()).otherwise(() => z.unknown());
2468
+ }).with("DateTime", () => this.makeDateTimeValueSchema()).with("Bytes", () => z$1.instanceof(Uint8Array)).with("Json", () => this.makeJsonValueSchema()).otherwise(() => z$1.unknown());
2462
2469
  }
2463
2470
  makeEnumSchema(_enum) {
2464
2471
  const enumDef = getEnum(this.schema, _enum);
2465
2472
  invariant(enumDef, `Enum "${_enum}" not found in schema`);
2466
- const schema = z.enum(Object.keys(enumDef.values));
2473
+ const schema = z$1.enum(Object.keys(enumDef.values));
2467
2474
  this.registerSchema(_enum, schema);
2468
2475
  return schema;
2469
2476
  }
2470
2477
  makeTypeDefSchema(type) {
2471
2478
  const typeDef = getTypeDef(this.schema, type);
2472
2479
  invariant(typeDef, `Type definition "${type}" not found in schema`);
2473
- const schema = z.looseObject(Object.fromEntries(Object.entries(typeDef.fields).map(([field, def]) => {
2474
- let fieldSchema = isTypeDef(this.schema, def.type) ? z.lazy(() => this.makeTypeDefSchema(def.type)) : this.makeScalarSchema(def.type);
2480
+ const schema = z$1.looseObject(Object.fromEntries(Object.entries(typeDef.fields).map(([field, def]) => {
2481
+ let fieldSchema = isTypeDef(this.schema, def.type) ? z$1.lazy(() => this.makeTypeDefSchema(def.type)) : this.makeScalarSchema(def.type);
2475
2482
  if (def.array) fieldSchema = fieldSchema.array();
2476
2483
  if (def.optional) fieldSchema = fieldSchema.nullish();
2477
2484
  return [field, fieldSchema];
2478
2485
  })));
2479
- const finalSchema = z.any().superRefine((value, ctx) => {
2486
+ const finalSchema = z$1.any().superRefine((value, ctx) => {
2480
2487
  const parseResult = schema.safeParse(value);
2481
2488
  if (!parseResult.success) parseResult.error.issues.forEach((issue) => ctx.addIssue(issue));
2482
2489
  });
@@ -2492,17 +2499,17 @@ var ZodSchemaFactory = class {
2492
2499
  if (fieldDef.relation) {
2493
2500
  if (withoutRelationFields || !this.shouldIncludeRelations(options)) continue;
2494
2501
  const allowedFilterKinds = this.getEffectiveFilterKinds(model, field);
2495
- if (allowedFilterKinds && !allowedFilterKinds.includes("Relation")) fieldSchema = z.never();
2502
+ if (allowedFilterKinds && !allowedFilterKinds.includes("Relation")) fieldSchema = z$1.never();
2496
2503
  else {
2497
- fieldSchema = z.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts).optional());
2498
- if (fieldDef.array) fieldSchema = z.strictObject({
2504
+ fieldSchema = z$1.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts).optional());
2505
+ if (fieldDef.array) fieldSchema = z$1.strictObject({
2499
2506
  some: fieldSchema.optional(),
2500
2507
  every: fieldSchema.optional(),
2501
2508
  none: fieldSchema.optional()
2502
2509
  });
2503
2510
  else {
2504
2511
  fieldSchema = this.nullableIf(fieldSchema, !fieldDef.array && !!fieldDef.optional);
2505
- fieldSchema = z.union([fieldSchema, z.strictObject({
2512
+ fieldSchema = z$1.union([fieldSchema, z$1.strictObject({
2506
2513
  is: fieldSchema.optional(),
2507
2514
  isNot: fieldSchema.optional()
2508
2515
  })]);
@@ -2521,21 +2528,21 @@ var ZodSchemaFactory = class {
2521
2528
  }
2522
2529
  if (unique) {
2523
2530
  const uniqueFields = getUniqueFields(this.schema, model);
2524
- for (const uniqueField of uniqueFields) if ("defs" in uniqueField) fields[uniqueField.name] = z.object(Object.fromEntries(Object.entries(uniqueField.defs).map(([key, def]) => {
2531
+ for (const uniqueField of uniqueFields) if ("defs" in uniqueField) fields[uniqueField.name] = z$1.object(Object.fromEntries(Object.entries(uniqueField.defs).map(([key, def]) => {
2525
2532
  invariant(!def.relation, "unique field cannot be a relation");
2526
2533
  let fieldSchema;
2527
2534
  const enumDef = getEnum(this.schema, def.type);
2528
2535
  if (enumDef) if (Object.keys(enumDef.values).length > 0) fieldSchema = this.makeEnumFilterSchema(def.type, !!def.optional, !!def.array, false, void 0);
2529
- else fieldSchema = z.never();
2536
+ else fieldSchema = z$1.never();
2530
2537
  else fieldSchema = this.makePrimitiveFilterSchema(def.type, !!def.optional, false, void 0);
2531
2538
  return [key, fieldSchema];
2532
2539
  }))).optional();
2533
2540
  }
2534
- fields["$expr"] = z.custom((v) => typeof v === "function", { error: "\"$expr\" must be a function" }).optional();
2535
- fields["AND"] = this.orArray(z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
2536
- fields["OR"] = z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)).array().optional();
2537
- fields["NOT"] = this.orArray(z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
2538
- const baseWhere = z.strictObject(fields);
2541
+ fields["$expr"] = z$1.custom((v) => typeof v === "function", { error: "\"$expr\" must be a function" }).optional();
2542
+ fields["AND"] = this.orArray(z$1.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
2543
+ fields["OR"] = z$1.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)).array().optional();
2544
+ fields["NOT"] = this.orArray(z$1.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
2545
+ const baseWhere = z$1.strictObject(fields);
2539
2546
  let result = baseWhere;
2540
2547
  if (unique) {
2541
2548
  const uniqueFields = getUniqueFields(this.schema, model);
@@ -2561,26 +2568,26 @@ var ZodSchemaFactory = class {
2561
2568
  else if (getEnum(this.schema, fieldDef.type)) fieldSchemas[fieldName] = this.makeEnumFilterSchema(fieldDef.type, !!fieldDef.optional, !!fieldDef.array, false, void 0).optional();
2562
2569
  else if (fieldDef.array) fieldSchemas[fieldName] = this.makeArrayFilterSchema(fieldDef.type, void 0).optional();
2563
2570
  else fieldSchemas[fieldName] = this.makePrimitiveFilterSchema(fieldDef.type, !!fieldDef.optional, false, void 0).optional();
2564
- candidates.push(z.strictObject(fieldSchemas));
2571
+ candidates.push(z$1.strictObject(fieldSchemas));
2565
2572
  }
2566
- const recursiveSchema = z.lazy(() => this.makeTypedJsonFilterSchema(type, optional, false, allowedFilterKinds)).optional();
2567
- if (array) candidates.push(z.strictObject({
2573
+ const recursiveSchema = z$1.lazy(() => this.makeTypedJsonFilterSchema(type, optional, false, allowedFilterKinds)).optional();
2574
+ if (array) candidates.push(z$1.strictObject({
2568
2575
  some: recursiveSchema,
2569
2576
  every: recursiveSchema,
2570
2577
  none: recursiveSchema
2571
2578
  }));
2572
- else candidates.push(z.strictObject({
2579
+ else candidates.push(z$1.strictObject({
2573
2580
  is: recursiveSchema,
2574
2581
  isNot: recursiveSchema
2575
2582
  }));
2576
2583
  candidates.push(this.makeJsonFilterSchema(optional, allowedFilterKinds));
2577
2584
  if (optional) {
2578
- candidates.push(z.null());
2579
- candidates.push(z.instanceof(DbNullClass));
2580
- candidates.push(z.instanceof(JsonNullClass));
2581
- candidates.push(z.instanceof(AnyNullClass));
2585
+ candidates.push(z$1.null());
2586
+ candidates.push(z$1.instanceof(DbNullClass));
2587
+ candidates.push(z$1.instanceof(JsonNullClass));
2588
+ candidates.push(z$1.instanceof(AnyNullClass));
2582
2589
  }
2583
- const result = z.union(candidates);
2590
+ const result = z$1.union(candidates);
2584
2591
  this.registerSchema(`${type}Filter${this.filterSchemaSuffix({
2585
2592
  optional,
2586
2593
  array,
@@ -2589,7 +2596,7 @@ var ZodSchemaFactory = class {
2589
2596
  return result;
2590
2597
  }
2591
2598
  makeNullableTypedJsonMutationSchema(fieldSchema) {
2592
- return z.any().superRefine((value, ctx) => {
2599
+ return z$1.any().superRefine((value, ctx) => {
2593
2600
  if (value instanceof DbNullClass || value instanceof JsonNullClass || value === null || value === void 0) return;
2594
2601
  const parseResult = fieldSchema.safeParse(value);
2595
2602
  if (!parseResult.success) parseResult.error.issues.forEach((issue) => ctx.addIssue(issue));
@@ -2601,11 +2608,11 @@ var ZodSchemaFactory = class {
2601
2608
  makeEnumFilterSchema(enumName, optional, array, withAggregations, allowedFilterKinds) {
2602
2609
  const enumDef = getEnum(this.schema, enumName);
2603
2610
  invariant(enumDef, `Enum "${enumName}" not found in schema`);
2604
- const baseSchema = z.enum(Object.keys(enumDef.values));
2611
+ const baseSchema = z$1.enum(Object.keys(enumDef.values));
2605
2612
  let schema;
2606
2613
  if (array) schema = this.internalMakeArrayFilterSchema(baseSchema, allowedFilterKinds);
2607
2614
  else {
2608
- const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z.lazy(() => this.makeEnumFilterSchema(enumName, optional, array, withAggregations, allowedFilterKinds)), [
2615
+ const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z$1.lazy(() => this.makeEnumFilterSchema(enumName, optional, array, withAggregations, allowedFilterKinds)), [
2609
2616
  "equals",
2610
2617
  "in",
2611
2618
  "notIn",
@@ -2639,42 +2646,42 @@ var ZodSchemaFactory = class {
2639
2646
  has: elementSchema.optional(),
2640
2647
  hasEvery: elementSchema.array().optional(),
2641
2648
  hasSome: elementSchema.array().optional(),
2642
- isEmpty: z.boolean().optional()
2649
+ isEmpty: z$1.boolean().optional()
2643
2650
  };
2644
2651
  const filteredOperators = this.trimFilterOperators(operators, allowedFilterKinds);
2645
- return z.strictObject(filteredOperators);
2652
+ return z$1.strictObject(filteredOperators);
2646
2653
  }
2647
2654
  makePrimitiveFilterSchema(type, optional, withAggregations, allowedFilterKinds, withFuzzy = false, withFullText = false) {
2648
- return match(type).with("String", () => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy, withFullText)).with(P.union("Int", "Float", "Decimal", "BigInt"), (type) => this.makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds)).with("Boolean", () => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)).with("DateTime", () => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)).with("Bytes", () => this.makeBytesFilterSchema(optional, withAggregations, allowedFilterKinds)).with("Json", () => this.makeJsonFilterSchema(optional, allowedFilterKinds)).with("Unsupported", () => z.never()).exhaustive();
2655
+ return match(type).with("String", () => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy, withFullText)).with(P.union("Int", "Float", "Decimal", "BigInt"), (type) => this.makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds)).with("Boolean", () => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)).with("DateTime", () => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)).with("Bytes", () => this.makeBytesFilterSchema(optional, withAggregations, allowedFilterKinds)).with("Json", () => this.makeJsonFilterSchema(optional, allowedFilterKinds)).with("Unsupported", () => z$1.never()).exhaustive();
2649
2656
  }
2650
2657
  makeJsonValueSchema() {
2651
- const schema = z.union([
2652
- z.string(),
2653
- z.number(),
2654
- z.boolean(),
2655
- z.instanceof(JsonNullClass),
2656
- z.lazy(() => z.union([this.makeJsonValueSchema(), z.null()]).array()),
2657
- z.record(z.string(), z.lazy(() => z.union([this.makeJsonValueSchema(), z.null()])))
2658
+ const schema = z$1.union([
2659
+ z$1.string(),
2660
+ z$1.number(),
2661
+ z$1.boolean(),
2662
+ z$1.instanceof(JsonNullClass),
2663
+ z$1.lazy(() => z$1.union([this.makeJsonValueSchema(), z$1.null()]).array()),
2664
+ z$1.record(z$1.string(), z$1.lazy(() => z$1.union([this.makeJsonValueSchema(), z$1.null()])))
2658
2665
  ]);
2659
2666
  this.registerSchema("JsonValue", schema);
2660
2667
  return schema;
2661
2668
  }
2662
2669
  makeJsonFilterSchema(optional, allowedFilterKinds) {
2663
- if (allowedFilterKinds && !allowedFilterKinds.includes("Json")) return z.never();
2670
+ if (allowedFilterKinds && !allowedFilterKinds.includes("Json")) return z$1.never();
2664
2671
  const filterMembers = [
2665
2672
  this.makeJsonValueSchema(),
2666
- z.instanceof(DbNullClass),
2667
- z.instanceof(AnyNullClass)
2673
+ z$1.instanceof(DbNullClass),
2674
+ z$1.instanceof(AnyNullClass)
2668
2675
  ];
2669
- if (optional) filterMembers.push(z.null());
2670
- const filterValueSchema = z.union(filterMembers);
2671
- const schema = z.strictObject({
2672
- path: z.string().optional(),
2676
+ if (optional) filterMembers.push(z$1.null());
2677
+ const filterValueSchema = z$1.union(filterMembers);
2678
+ const schema = z$1.strictObject({
2679
+ path: z$1.string().optional(),
2673
2680
  equals: filterValueSchema.optional(),
2674
2681
  not: filterValueSchema.optional(),
2675
- string_contains: z.string().optional(),
2676
- string_starts_with: z.string().optional(),
2677
- string_ends_with: z.string().optional(),
2682
+ string_contains: z$1.string().optional(),
2683
+ string_starts_with: z$1.string().optional(),
2684
+ string_ends_with: z$1.string().optional(),
2678
2685
  mode: this.makeStringModeSchema().optional(),
2679
2686
  array_contains: filterValueSchema.optional(),
2680
2687
  array_starts_with: filterValueSchema.optional(),
@@ -2693,7 +2700,7 @@ var ZodSchemaFactory = class {
2693
2700
  }
2694
2701
  makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds) {
2695
2702
  const filterValueSchema = this.makeDateTimeValueSchema();
2696
- const schema = this.makeCommonPrimitiveFilterSchema(filterValueSchema, optional, () => z.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)), withAggregations ? [
2703
+ const schema = this.makeCommonPrimitiveFilterSchema(filterValueSchema, optional, () => z$1.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)), withAggregations ? [
2697
2704
  "_count",
2698
2705
  "_min",
2699
2706
  "_max"
@@ -2706,12 +2713,12 @@ var ZodSchemaFactory = class {
2706
2713
  return schema;
2707
2714
  }
2708
2715
  makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds) {
2709
- const components = this.makeCommonPrimitiveFilterComponents(z.boolean(), optional, () => z.lazy(() => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)), ["equals", "not"], withAggregations ? [
2716
+ const components = this.makeCommonPrimitiveFilterComponents(z$1.boolean(), optional, () => z$1.lazy(() => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)), ["equals", "not"], withAggregations ? [
2710
2717
  "_count",
2711
2718
  "_min",
2712
2719
  "_max"
2713
2720
  ] : void 0, allowedFilterKinds);
2714
- const schema = this.createUnionFilterSchema(z.boolean(), optional, components, allowedFilterKinds);
2721
+ const schema = this.createUnionFilterSchema(z$1.boolean(), optional, components, allowedFilterKinds);
2715
2722
  this.registerSchema(`BooleanFilter${this.filterSchemaSuffix({
2716
2723
  optional,
2717
2724
  allowedFilterKinds,
@@ -2720,8 +2727,8 @@ var ZodSchemaFactory = class {
2720
2727
  return schema;
2721
2728
  }
2722
2729
  makeBytesFilterSchema(optional, withAggregations, allowedFilterKinds) {
2723
- const baseSchema = z.instanceof(Uint8Array);
2724
- const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z.instanceof(Uint8Array), [
2730
+ const baseSchema = z$1.instanceof(Uint8Array);
2731
+ const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z$1.instanceof(Uint8Array), [
2725
2732
  "equals",
2726
2733
  "in",
2727
2734
  "notIn",
@@ -2769,7 +2776,7 @@ var ZodSchemaFactory = class {
2769
2776
  return this.createUnionFilterSchema(baseSchema, optional, components, allowedFilterKinds);
2770
2777
  }
2771
2778
  makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds) {
2772
- const schema = this.makeCommonPrimitiveFilterSchema(this.makeScalarSchema(type), optional, () => z.lazy(() => this.makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds)), withAggregations ? [
2779
+ const schema = this.makeCommonPrimitiveFilterSchema(this.makeScalarSchema(type), optional, () => z$1.lazy(() => this.makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds)), withAggregations ? [
2773
2780
  "_count",
2774
2781
  "_avg",
2775
2782
  "_sum",
@@ -2784,15 +2791,15 @@ var ZodSchemaFactory = class {
2784
2791
  return schema;
2785
2792
  }
2786
2793
  makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy = false, withFullText = false) {
2787
- const baseComponents = this.makeCommonPrimitiveFilterComponents(z.string(), optional, () => z.lazy(() => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy, withFullText)), void 0, withAggregations ? [
2794
+ const baseComponents = this.makeCommonPrimitiveFilterComponents(z$1.string(), optional, () => z$1.lazy(() => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy, withFullText)), void 0, withAggregations ? [
2788
2795
  "_count",
2789
2796
  "_min",
2790
2797
  "_max"
2791
2798
  ] : void 0, allowedFilterKinds);
2792
2799
  const stringSpecificOperators = {
2793
- startsWith: z.string().optional(),
2794
- endsWith: z.string().optional(),
2795
- contains: z.string().optional(),
2800
+ startsWith: z$1.string().optional(),
2801
+ endsWith: z$1.string().optional(),
2802
+ contains: z$1.string().optional(),
2796
2803
  ...withFuzzy && this.providerSupportsFuzzySearch ? { fuzzy: this.makeFuzzyFilterSchema().optional() } : {},
2797
2804
  ...withFullText && this.providerSupportsFullTextSearch ? { fts: this.makeFullTextFilterSchema().optional() } : {},
2798
2805
  ...this.providerSupportsCaseSensitivity ? { mode: this.makeStringModeSchema().optional() } : {}
@@ -2802,7 +2809,7 @@ var ZodSchemaFactory = class {
2802
2809
  ...baseComponents,
2803
2810
  ...filteredStringOperators
2804
2811
  };
2805
- const schema = this.createUnionFilterSchema(z.string(), optional, allComponents, allowedFilterKinds);
2812
+ const schema = this.createUnionFilterSchema(z$1.string(), optional, allComponents, allowedFilterKinds);
2806
2813
  const featureSuffix = `${withFuzzy ? "Fuzzy" : ""}${withFullText ? "FullText" : ""}`;
2807
2814
  this.registerSchema(`StringFilter${this.filterSchemaSuffix({
2808
2815
  optional,
@@ -2812,24 +2819,24 @@ var ZodSchemaFactory = class {
2812
2819
  return schema;
2813
2820
  }
2814
2821
  makeStringModeSchema() {
2815
- return z.union([z.literal("default"), z.literal("insensitive")]);
2822
+ return z$1.union([z$1.literal("default"), z$1.literal("insensitive")]);
2816
2823
  }
2817
2824
  makeFuzzyFilterSchema() {
2818
- return z.strictObject({
2819
- search: z.string().min(1),
2820
- mode: z.union([
2821
- z.literal("simple"),
2822
- z.literal("word"),
2823
- z.literal("strictWord")
2825
+ return z$1.strictObject({
2826
+ search: z$1.string().min(1),
2827
+ mode: z$1.union([
2828
+ z$1.literal("simple"),
2829
+ z$1.literal("word"),
2830
+ z$1.literal("strictWord")
2824
2831
  ]).default("simple"),
2825
- threshold: z.number().min(0).max(1).optional(),
2826
- unaccent: z.boolean().default(false)
2832
+ threshold: z$1.number().min(0).max(1).optional(),
2833
+ unaccent: z$1.boolean().default(false)
2827
2834
  });
2828
2835
  }
2829
2836
  makeFullTextFilterSchema() {
2830
- return z.strictObject({
2831
- search: z.string().min(1),
2832
- config: z.string().min(1).optional()
2837
+ return z$1.strictObject({
2838
+ search: z$1.string().min(1),
2839
+ config: z$1.string().min(1).optional()
2833
2840
  });
2834
2841
  }
2835
2842
  makeSelectSchema(model, options) {
@@ -2837,13 +2844,14 @@ var ZodSchemaFactory = class {
2837
2844
  for (const [field, fieldDef] of this.getModelFields(model)) if (fieldDef.relation) {
2838
2845
  if (!this.shouldIncludeRelations(options)) continue;
2839
2846
  if (this.isModelAllowed(fieldDef.type)) fields[field] = this.makeRelationSelectIncludeSchema(model, field, options).optional();
2840
- } else fields[field] = z.boolean().optional();
2847
+ } else if (this.options.allowQueryTimeOmitOverride === false && this.isFieldOmittedByConfig(model, field)) fields[field] = z$1.literal(false).optional();
2848
+ else fields[field] = z$1.boolean().optional();
2841
2849
  if (this.shouldIncludeRelations(options)) {
2842
2850
  const _countSchema = this.makeCountSelectionSchema(model, options);
2843
- if (!(_countSchema instanceof z.ZodNever)) fields["_count"] = _countSchema;
2851
+ if (!(_countSchema instanceof z$1.ZodNever)) fields["_count"] = _countSchema;
2844
2852
  }
2845
2853
  this.addExtResultFields(model, fields);
2846
- const result = z.strictObject(fields);
2854
+ const result = z$1.strictObject(fields);
2847
2855
  this.registerSchema(`${model}Select`, result);
2848
2856
  return result;
2849
2857
  }
@@ -2852,24 +2860,24 @@ var ZodSchemaFactory = class {
2852
2860
  const toManyRelations = Object.values(modelDef.fields).filter((def) => def.relation && def.array);
2853
2861
  if (toManyRelations.length > 0) {
2854
2862
  const nextOpts = this.nextOptions(options);
2855
- const schema = z.union([z.literal(true), z.strictObject({ select: z.strictObject(toManyRelations.reduce((acc, fieldDef) => ({
2863
+ const schema = z$1.union([z$1.literal(true), z$1.strictObject({ select: z$1.strictObject(toManyRelations.reduce((acc, fieldDef) => ({
2856
2864
  ...acc,
2857
- [fieldDef.name]: z.union([z.boolean(), z.strictObject({ where: this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts) })]).optional()
2865
+ [fieldDef.name]: z$1.union([z$1.boolean(), z$1.strictObject({ where: this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts) })]).optional()
2858
2866
  }), {})) })]).optional();
2859
2867
  this.registerSchema(`${model}CountSelection`, schema);
2860
2868
  return schema;
2861
- } else return z.never();
2869
+ } else return z$1.never();
2862
2870
  }
2863
2871
  makeRelationSelectIncludeSchema(model, field, options) {
2864
2872
  const fieldDef = requireField(this.schema, model, field);
2865
2873
  const nextOpts = this.nextOptions(options);
2866
- let objSchema = z.strictObject({
2867
- ...fieldDef.array || fieldDef.optional ? { where: z.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts)).optional() } : {},
2868
- select: z.lazy(() => this.makeSelectSchema(fieldDef.type, nextOpts)).optional().nullable(),
2869
- include: z.lazy(() => this.makeIncludeSchema(fieldDef.type, nextOpts)).optional().nullable(),
2870
- omit: z.lazy(() => this.makeOmitSchema(fieldDef.type)).optional().nullable(),
2874
+ let objSchema = z$1.strictObject({
2875
+ ...fieldDef.array || fieldDef.optional ? { where: z$1.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts)).optional() } : {},
2876
+ select: z$1.lazy(() => this.makeSelectSchema(fieldDef.type, nextOpts)).optional().nullable(),
2877
+ include: z$1.lazy(() => this.makeIncludeSchema(fieldDef.type, nextOpts)).optional().nullable(),
2878
+ omit: z$1.lazy(() => this.makeOmitSchema(fieldDef.type)).optional().nullable(),
2871
2879
  ...fieldDef.array ? {
2872
- orderBy: z.lazy(() => this.orArray(this.makeOrderBySchema(fieldDef.type, true, false, nextOpts), true)).optional(),
2880
+ orderBy: z$1.lazy(() => this.orArray(this.makeOrderBySchema(fieldDef.type, true, false, nextOpts), true)).optional(),
2873
2881
  skip: this.makeSkipSchema().optional(),
2874
2882
  take: this.makeTakeSchema().optional(),
2875
2883
  cursor: this.makeCursorSchema(fieldDef.type, nextOpts).optional(),
@@ -2879,16 +2887,25 @@ var ZodSchemaFactory = class {
2879
2887
  objSchema = this.refineForSelectIncludeMutuallyExclusive(objSchema);
2880
2888
  objSchema = this.refineForSelectOmitMutuallyExclusive(objSchema);
2881
2889
  objSchema = this.refineForSelectHasTruthyField(objSchema);
2882
- const result = z.union([z.boolean(), objSchema]);
2890
+ const result = z$1.union([z$1.boolean(), objSchema]);
2883
2891
  this.registerSchema(`${model}${upperCaseFirst(field)}RelationInput`, result);
2884
2892
  return result;
2885
2893
  }
2894
+ /**
2895
+ * Determines whether a field is configured to be omitted at the schema or client-options level
2896
+ * (query-level omit is excluded as it's mutually exclusive with `select`).
2897
+ */
2898
+ isFieldOmittedByConfig(model, field) {
2899
+ const omitConfig = this.options.omit?.[lowerCaseFirst(model)] ?? this.options.omit?.[model];
2900
+ if (omitConfig && typeof omitConfig[field] === "boolean") return omitConfig[field];
2901
+ return !!requireField(this.schema, model, field).omit;
2902
+ }
2886
2903
  makeOmitSchema(model) {
2887
2904
  const fields = {};
2888
- for (const [field, fieldDef] of this.getModelFields(model)) if (!fieldDef.relation) if (this.options.allowQueryTimeOmitOverride !== false) fields[field] = z.boolean().optional();
2889
- else fields[field] = z.literal(true).optional();
2905
+ for (const [field, fieldDef] of this.getModelFields(model)) if (!fieldDef.relation) if (this.options.allowQueryTimeOmitOverride !== false) fields[field] = z$1.boolean().optional();
2906
+ else fields[field] = z$1.literal(true).optional();
2890
2907
  this.addExtResultFields(model, fields);
2891
- const result = z.strictObject(fields);
2908
+ const result = z$1.strictObject(fields);
2892
2909
  this.registerSchema(`${model}OmitInput`, result);
2893
2910
  return result;
2894
2911
  }
@@ -2897,7 +2914,7 @@ var ZodSchemaFactory = class {
2897
2914
  const resultConfig = plugin.result;
2898
2915
  if (resultConfig) {
2899
2916
  const modelConfig = resultConfig[lowerCaseFirst(model)];
2900
- if (modelConfig) for (const field of Object.keys(modelConfig)) fields[field] = z.boolean().optional();
2917
+ if (modelConfig) for (const field of Object.keys(modelConfig)) fields[field] = z$1.boolean().optional();
2901
2918
  }
2902
2919
  }
2903
2920
  }
@@ -2913,26 +2930,26 @@ var ZodSchemaFactory = class {
2913
2930
  }
2914
2931
  if (this.shouldIncludeRelations(options)) {
2915
2932
  const _countSchema = this.makeCountSelectionSchema(model, options);
2916
- if (!(_countSchema instanceof z.ZodNever)) fields["_count"] = _countSchema;
2933
+ if (!(_countSchema instanceof z$1.ZodNever)) fields["_count"] = _countSchema;
2917
2934
  }
2918
- const result = z.strictObject(fields);
2935
+ const result = z$1.strictObject(fields);
2919
2936
  this.registerSchema(`${model}Include`, result);
2920
2937
  return result;
2921
2938
  }
2922
2939
  makeOrderBySchema(model, withRelation, WithAggregation, options) {
2923
2940
  const fields = {};
2924
- const sort = z.union([z.literal("asc"), z.literal("desc")]);
2941
+ const sort = z$1.union([z$1.literal("asc"), z$1.literal("desc")]);
2925
2942
  const refineAtMostOneKey = (s) => s.refine((v) => Object.keys(v).length <= 1, { message: "Each orderBy element must have at most one key" });
2926
2943
  const nextOpts = this.nextOptions(options);
2927
2944
  for (const [field, fieldDef] of this.getModelFields(model)) if (fieldDef.relation) {
2928
- if (withRelation && this.shouldIncludeRelations(options)) fields[field] = z.lazy(() => {
2945
+ if (withRelation && this.shouldIncludeRelations(options)) fields[field] = z$1.lazy(() => {
2929
2946
  let relationOrderBy = this.makeOrderBySchema(fieldDef.type, withRelation, WithAggregation, nextOpts);
2930
2947
  if (fieldDef.array) relationOrderBy = refineAtMostOneKey(relationOrderBy.safeExtend({ _count: sort }));
2931
2948
  return relationOrderBy;
2932
2949
  }).optional();
2933
- } else if (fieldDef.optional) fields[field] = z.union([sort, z.strictObject({
2950
+ } else if (fieldDef.optional) fields[field] = z$1.union([sort, z$1.strictObject({
2934
2951
  sort,
2935
- nulls: z.union([z.literal("first"), z.literal("last")]).optional()
2952
+ nulls: z$1.union([z$1.literal("first"), z$1.literal("last")]).optional()
2936
2953
  })]).optional();
2937
2954
  else fields[field] = sort.optional();
2938
2955
  if (WithAggregation) for (const agg of [
@@ -2941,31 +2958,31 @@ var ZodSchemaFactory = class {
2941
2958
  "_sum",
2942
2959
  "_min",
2943
2960
  "_max"
2944
- ]) fields[agg] = z.lazy(() => this.makeOrderBySchema(model, true, false, options).optional());
2961
+ ]) fields[agg] = z$1.lazy(() => this.makeOrderBySchema(model, true, false, options).optional());
2945
2962
  if (this.providerSupportsFuzzySearch) {
2946
2963
  const fuzzyFieldNames = this.getModelFields(model).filter(([, def]) => !def.relation && def.type === "String" && def.fuzzy === true).map(([name]) => name);
2947
- if (fuzzyFieldNames.length > 0) fields["_fuzzyRelevance"] = z.strictObject({
2948
- fields: z.array(z.enum(fuzzyFieldNames)).min(1),
2949
- search: z.string(),
2950
- mode: z.union([
2951
- z.literal("simple"),
2952
- z.literal("word"),
2953
- z.literal("strictWord")
2964
+ if (fuzzyFieldNames.length > 0) fields["_fuzzyRelevance"] = z$1.strictObject({
2965
+ fields: z$1.array(z$1.enum(fuzzyFieldNames)).min(1),
2966
+ search: z$1.string(),
2967
+ mode: z$1.union([
2968
+ z$1.literal("simple"),
2969
+ z$1.literal("word"),
2970
+ z$1.literal("strictWord")
2954
2971
  ]).default("simple"),
2955
- unaccent: z.boolean().default(false),
2972
+ unaccent: z$1.boolean().default(false),
2956
2973
  sort
2957
2974
  }).optional();
2958
2975
  }
2959
2976
  if (this.providerSupportsFullTextSearch) {
2960
2977
  const fullTextFieldNames = this.getModelFields(model).filter(([, def]) => !def.relation && def.type === "String" && def.fullText === true).map(([name]) => name);
2961
- if (fullTextFieldNames.length > 0) fields["_ftsRelevance"] = z.strictObject({
2962
- fields: z.array(z.enum(fullTextFieldNames)).min(1),
2963
- search: z.string().min(1),
2964
- config: z.string().min(1).optional(),
2978
+ if (fullTextFieldNames.length > 0) fields["_ftsRelevance"] = z$1.strictObject({
2979
+ fields: z$1.array(z$1.enum(fullTextFieldNames)).min(1),
2980
+ search: z$1.string().min(1),
2981
+ config: z$1.string().min(1).optional(),
2965
2982
  sort
2966
2983
  }).optional();
2967
2984
  }
2968
- const schema = refineAtMostOneKey(z.strictObject(fields));
2985
+ const schema = refineAtMostOneKey(z$1.strictObject(fields));
2969
2986
  let schemaId = `${model}OrderBy`;
2970
2987
  if (withRelation) schemaId += "WithRelation";
2971
2988
  if (WithAggregation) schemaId += "WithAggregation";
@@ -2975,7 +2992,7 @@ var ZodSchemaFactory = class {
2975
2992
  }
2976
2993
  makeDistinctSchema(model) {
2977
2994
  const nonRelationFields = this.getModelFields(model).filter(([, def]) => !def.relation).map(([name]) => name);
2978
- const schema = nonRelationFields.length > 0 ? this.orArray(z.enum(nonRelationFields), true) : z.never();
2995
+ const schema = nonRelationFields.length > 0 ? this.orArray(z$1.enum(nonRelationFields), true) : z$1.never();
2979
2996
  this.registerSchema(`${model}DistinctInput`, schema);
2980
2997
  return schema;
2981
2998
  }
@@ -2986,7 +3003,7 @@ var ZodSchemaFactory = class {
2986
3003
  }
2987
3004
  makeCreateSchema(model, options) {
2988
3005
  const dataSchema = this.makeCreateDataSchema(model, false, [], false, options);
2989
- const baseSchema = z.strictObject({
3006
+ const baseSchema = z$1.strictObject({
2990
3007
  data: dataSchema,
2991
3008
  select: this.makeSelectSchema(model, options).optional().nullable(),
2992
3009
  include: this.makeIncludeSchema(model, options).optional().nullable(),
@@ -3035,7 +3052,7 @@ var ZodSchemaFactory = class {
3035
3052
  const oppositeFieldDef = requireField(this.schema, fieldDef.type, oppositeField);
3036
3053
  if (oppositeFieldDef.relation?.fields) excludeFields.push(...oppositeFieldDef.relation.fields);
3037
3054
  }
3038
- let fieldSchema = z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "create", nextOpts));
3055
+ let fieldSchema = z$1.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "create", nextOpts));
3039
3056
  if (fieldDef.optional || fieldDef.array) fieldSchema = fieldSchema.optional();
3040
3057
  else {
3041
3058
  let allFksOptional = false;
@@ -3052,23 +3069,23 @@ var ZodSchemaFactory = class {
3052
3069
  let fieldSchema = this.makeScalarSchema(fieldDef.type, fieldDef.attributes);
3053
3070
  if (fieldDef.array) {
3054
3071
  fieldSchema = ZodUtils.addListValidation(fieldSchema.array(), fieldDef.attributes);
3055
- fieldSchema = z.union([fieldSchema, z.strictObject({ set: fieldSchema })]).optional();
3072
+ fieldSchema = z$1.union([fieldSchema, z$1.strictObject({ set: fieldSchema })]).optional();
3056
3073
  }
3057
3074
  if (fieldDef.optional || fieldHasDefaultValue(fieldDef)) fieldSchema = fieldSchema.optional();
3058
- if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z.union([fieldSchema, z.instanceof(DbNullClass)]);
3075
+ if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z$1.union([fieldSchema, z$1.instanceof(DbNullClass)]);
3059
3076
  else if (this.isTypeDefType(fieldDef.type)) fieldSchema = this.makeNullableTypedJsonMutationSchema(fieldSchema);
3060
3077
  else fieldSchema = fieldSchema.nullable();
3061
3078
  uncheckedVariantFields[field] = fieldSchema;
3062
3079
  if (!fieldDef.foreignKeyFor) checkedVariantFields[field] = fieldSchema;
3063
3080
  }
3064
3081
  });
3065
- const uncheckedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(uncheckedVariantFields), modelDef.attributes) : z.strictObject(uncheckedVariantFields);
3066
- const checkedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(checkedVariantFields), modelDef.attributes) : z.strictObject(checkedVariantFields);
3067
- const result = !hasRelation ? this.orArray(uncheckedCreateSchema, canBeArray) : z.union([
3082
+ const uncheckedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z$1.strictObject(uncheckedVariantFields), modelDef.attributes) : z$1.strictObject(uncheckedVariantFields);
3083
+ const checkedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z$1.strictObject(checkedVariantFields), modelDef.attributes) : z$1.strictObject(checkedVariantFields);
3084
+ const result = !hasRelation ? this.orArray(uncheckedCreateSchema, canBeArray) : z$1.union([
3068
3085
  uncheckedCreateSchema,
3069
3086
  checkedCreateSchema,
3070
- ...canBeArray ? [z.array(uncheckedCreateSchema)] : [],
3071
- ...canBeArray ? [z.array(checkedCreateSchema)] : []
3087
+ ...canBeArray ? [z$1.array(uncheckedCreateSchema)] : [],
3088
+ ...canBeArray ? [z$1.array(checkedCreateSchema)] : []
3072
3089
  ]);
3073
3090
  const idParts = [`${model}CreateData`];
3074
3091
  if (canBeArray) idParts.push("Array");
@@ -3093,17 +3110,17 @@ var ZodSchemaFactory = class {
3093
3110
  fields["disconnect"] = this.makeDisconnectDataSchema(fieldType, array, options).optional();
3094
3111
  fields["delete"] = this.makeDeleteRelationDataSchema(fieldType, array, true, options).optional();
3095
3112
  }
3096
- fields["update"] = array ? this.orArray(z.strictObject({
3113
+ fields["update"] = array ? this.orArray(z$1.strictObject({
3097
3114
  where: this.makeWhereSchema(fieldType, true, false, false, options),
3098
3115
  data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
3099
- }), true).optional() : z.union([z.strictObject({
3116
+ }), true).optional() : z$1.union([z$1.strictObject({
3100
3117
  where: this.makeWhereSchema(fieldType, false, false, false, options).optional(),
3101
3118
  data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
3102
3119
  }), this.makeUpdateDataSchema(fieldType, withoutFields, false, options)]).optional();
3103
3120
  if (canCreateModel) {
3104
3121
  let upsertWhere = this.makeWhereSchema(fieldType, true, false, false, options);
3105
3122
  if (!fieldDef.array) upsertWhere = upsertWhere.optional();
3106
- fields["upsert"] = this.orArray(z.strictObject({
3123
+ fields["upsert"] = this.orArray(z$1.strictObject({
3107
3124
  where: upsertWhere,
3108
3125
  create: this.makeCreateDataSchema(fieldType, false, withoutFields, false, options),
3109
3126
  update: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
@@ -3111,14 +3128,14 @@ var ZodSchemaFactory = class {
3111
3128
  }
3112
3129
  if (array) {
3113
3130
  fields["set"] = this.makeSetDataSchema(fieldType, true, options).optional();
3114
- fields["updateMany"] = this.orArray(z.strictObject({
3131
+ fields["updateMany"] = this.orArray(z$1.strictObject({
3115
3132
  where: this.makeWhereSchema(fieldType, false, true, false, options),
3116
3133
  data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
3117
3134
  }), true).optional();
3118
3135
  fields["deleteMany"] = this.makeDeleteRelationDataSchema(fieldType, true, false, options).optional();
3119
3136
  }
3120
3137
  }
3121
- return z.strictObject(fields);
3138
+ return z$1.strictObject(fields);
3122
3139
  }
3123
3140
  makeSetDataSchema(model, canBeArray, options) {
3124
3141
  return this.orArray(this.makeWhereSchema(model, true, false, false, options), canBeArray);
@@ -3128,23 +3145,23 @@ var ZodSchemaFactory = class {
3128
3145
  }
3129
3146
  makeDisconnectDataSchema(model, canBeArray, options) {
3130
3147
  if (canBeArray) return this.orArray(this.makeWhereSchema(model, true, false, false, options), canBeArray);
3131
- else return z.union([z.boolean(), this.makeWhereSchema(model, false, false, false, options)]);
3148
+ else return z$1.union([z$1.boolean(), this.makeWhereSchema(model, false, false, false, options)]);
3132
3149
  }
3133
3150
  makeDeleteRelationDataSchema(model, toManyRelation, uniqueFilter, options) {
3134
- return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter, false, false, options), true) : z.union([z.boolean(), this.makeWhereSchema(model, uniqueFilter, false, false, options)]);
3151
+ 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)]);
3135
3152
  }
3136
3153
  makeConnectOrCreateDataSchema(model, canBeArray, withoutFields, options) {
3137
3154
  const whereSchema = this.makeWhereSchema(model, true, false, false, options);
3138
3155
  const createSchema = this.makeCreateDataSchema(model, false, withoutFields, false, options);
3139
- return this.orArray(z.strictObject({
3156
+ return this.orArray(z$1.strictObject({
3140
3157
  where: whereSchema,
3141
3158
  create: createSchema
3142
3159
  }), canBeArray);
3143
3160
  }
3144
3161
  makeCreateManyPayloadSchema(model, withoutFields, options) {
3145
- const schema = z.strictObject({
3162
+ const schema = z$1.strictObject({
3146
3163
  data: this.makeCreateDataSchema(model, true, withoutFields, true, options),
3147
- skipDuplicates: z.boolean().optional()
3164
+ skipDuplicates: z$1.boolean().optional()
3148
3165
  });
3149
3166
  const idParts = [`${model}CreateManyPayload`];
3150
3167
  if (withoutFields.length) idParts.push(`Without${withoutFields.slice().sort().join("")}`);
@@ -3152,7 +3169,7 @@ var ZodSchemaFactory = class {
3152
3169
  return schema;
3153
3170
  }
3154
3171
  makeUpdateSchema(model, options) {
3155
- const baseSchema = z.strictObject({
3172
+ const baseSchema = z$1.strictObject({
3156
3173
  where: this.makeWhereSchema(model, true, false, false, options),
3157
3174
  data: this.makeUpdateDataSchema(model, [], false, options),
3158
3175
  select: this.makeSelectSchema(model, options).optional().nullable(),
@@ -3167,10 +3184,10 @@ var ZodSchemaFactory = class {
3167
3184
  return schema;
3168
3185
  }
3169
3186
  makeUpdateManySchema(model, options) {
3170
- const result = this.mergePluginArgsSchema(z.strictObject({
3187
+ const result = this.mergePluginArgsSchema(z$1.strictObject({
3171
3188
  where: this.makeWhereSchema(model, false, false, false, options).optional(),
3172
3189
  data: this.makeUpdateDataSchema(model, [], true, options),
3173
- limit: z.number().int().nonnegative().optional()
3190
+ limit: z$1.number().int().nonnegative().optional()
3174
3191
  }), "updateMany");
3175
3192
  this.registerSchema(`${model}UpdateManyArgs`, result);
3176
3193
  return result;
@@ -3186,7 +3203,7 @@ var ZodSchemaFactory = class {
3186
3203
  return schema;
3187
3204
  }
3188
3205
  makeUpsertSchema(model, options) {
3189
- const baseSchema = z.strictObject({
3206
+ const baseSchema = z$1.strictObject({
3190
3207
  where: this.makeWhereSchema(model, true, false, false, options),
3191
3208
  create: this.makeCreateDataSchema(model, false, [], false, options),
3192
3209
  update: this.makeUpdateDataSchema(model, [], false, options),
@@ -3222,27 +3239,27 @@ var ZodSchemaFactory = class {
3222
3239
  const oppositeFieldDef = requireField(this.schema, fieldDef.type, oppositeField);
3223
3240
  if (oppositeFieldDef.relation?.fields) excludeFields.push(...oppositeFieldDef.relation.fields);
3224
3241
  }
3225
- let fieldSchema = z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "update", nextOpts)).optional();
3242
+ let fieldSchema = z$1.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "update", nextOpts)).optional();
3226
3243
  if (fieldDef.optional && !fieldDef.array) fieldSchema = fieldSchema.nullable();
3227
3244
  checkedVariantFields[field] = fieldSchema;
3228
3245
  if (fieldDef.array || !fieldDef.relation.references) uncheckedVariantFields[field] = fieldSchema;
3229
3246
  } else {
3230
3247
  let fieldSchema = this.makeScalarSchema(fieldDef.type, fieldDef.attributes);
3231
- if (this.isNumericField(fieldDef)) fieldSchema = z.union([fieldSchema, z.object({
3232
- set: this.nullableIf(z.number().optional(), !!fieldDef.optional).optional(),
3233
- increment: z.number().optional(),
3234
- decrement: z.number().optional(),
3235
- multiply: z.number().optional(),
3236
- divide: z.number().optional()
3248
+ if (this.isNumericField(fieldDef)) fieldSchema = z$1.union([fieldSchema, z$1.object({
3249
+ set: this.nullableIf(z$1.number().optional(), !!fieldDef.optional).optional(),
3250
+ increment: z$1.number().optional(),
3251
+ decrement: z$1.number().optional(),
3252
+ multiply: z$1.number().optional(),
3253
+ divide: z$1.number().optional()
3237
3254
  }).refine((v) => Object.keys(v).length === 1, "Only one of \"set\", \"increment\", \"decrement\", \"multiply\", or \"divide\" can be provided")]);
3238
3255
  if (fieldDef.array) {
3239
3256
  const arraySchema = ZodUtils.addListValidation(fieldSchema.array(), fieldDef.attributes);
3240
- fieldSchema = z.union([arraySchema, z.object({
3257
+ fieldSchema = z$1.union([arraySchema, z$1.object({
3241
3258
  set: arraySchema.optional(),
3242
- push: z.union([fieldSchema, fieldSchema.array()]).optional()
3259
+ push: z$1.union([fieldSchema, fieldSchema.array()]).optional()
3243
3260
  }).refine((v) => Object.keys(v).length === 1, "Only one of \"set\", \"push\" can be provided")]);
3244
3261
  }
3245
- if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z.union([fieldSchema, z.instanceof(DbNullClass)]);
3262
+ if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z$1.union([fieldSchema, z$1.instanceof(DbNullClass)]);
3246
3263
  else if (this.isTypeDefType(fieldDef.type)) fieldSchema = this.makeNullableTypedJsonMutationSchema(fieldSchema);
3247
3264
  else fieldSchema = fieldSchema.nullable();
3248
3265
  fieldSchema = fieldSchema.optional();
@@ -3250,9 +3267,9 @@ var ZodSchemaFactory = class {
3250
3267
  if (!fieldDef.foreignKeyFor) checkedVariantFields[field] = fieldSchema;
3251
3268
  }
3252
3269
  });
3253
- const uncheckedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(uncheckedVariantFields), modelDef.attributes) : z.strictObject(uncheckedVariantFields);
3254
- const checkedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(checkedVariantFields), modelDef.attributes) : z.strictObject(checkedVariantFields);
3255
- const result = !hasRelation ? uncheckedUpdateSchema : z.union([uncheckedUpdateSchema, checkedUpdateSchema]);
3270
+ const uncheckedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z$1.strictObject(uncheckedVariantFields), modelDef.attributes) : z$1.strictObject(uncheckedVariantFields);
3271
+ const checkedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z$1.strictObject(checkedVariantFields), modelDef.attributes) : z$1.strictObject(checkedVariantFields);
3272
+ const result = !hasRelation ? uncheckedUpdateSchema : z$1.union([uncheckedUpdateSchema, checkedUpdateSchema]);
3256
3273
  const idParts = [`${model}UpdateData`];
3257
3274
  if (withoutRelationFields) idParts.push("WithoutRelation");
3258
3275
  if (withoutFields.length) idParts.push(`Without${withoutFields.slice().sort().join("")}`);
@@ -3260,7 +3277,7 @@ var ZodSchemaFactory = class {
3260
3277
  return result;
3261
3278
  }
3262
3279
  makeDeleteSchema(model, options) {
3263
- const baseSchema = z.strictObject({
3280
+ const baseSchema = z$1.strictObject({
3264
3281
  where: this.makeWhereSchema(model, true, false, false, options),
3265
3282
  select: this.makeSelectSchema(model, options).optional().nullable(),
3266
3283
  include: this.makeIncludeSchema(model, options).optional().nullable(),
@@ -3274,15 +3291,15 @@ var ZodSchemaFactory = class {
3274
3291
  return schema;
3275
3292
  }
3276
3293
  makeDeleteManySchema(model, options) {
3277
- const result = this.mergePluginArgsSchema(z.strictObject({
3294
+ const result = this.mergePluginArgsSchema(z$1.strictObject({
3278
3295
  where: this.makeWhereSchema(model, false, false, false, options).optional(),
3279
- limit: z.number().int().nonnegative().optional()
3296
+ limit: z$1.number().int().nonnegative().optional()
3280
3297
  }), "deleteMany").optional();
3281
3298
  this.registerSchema(`${model}DeleteManyArgs`, result);
3282
3299
  return result;
3283
3300
  }
3284
3301
  makeCountSchema(model, options) {
3285
- const result = this.mergePluginArgsSchema(z.strictObject({
3302
+ const result = this.mergePluginArgsSchema(z$1.strictObject({
3286
3303
  where: this.makeWhereSchema(model, false, false, false, options).optional(),
3287
3304
  skip: this.makeSkipSchema().optional(),
3288
3305
  take: this.makeTakeSchema().optional(),
@@ -3293,10 +3310,10 @@ var ZodSchemaFactory = class {
3293
3310
  return result;
3294
3311
  }
3295
3312
  makeCountAggregateInputSchema(model) {
3296
- const schema = z.union([z.literal(true), z.strictObject({
3297
- _all: z.literal(true).optional(),
3313
+ const schema = z$1.union([z$1.literal(true), z$1.strictObject({
3314
+ _all: z$1.literal(true).optional(),
3298
3315
  ...this.getModelFields(model).reduce((acc, [field]) => {
3299
- acc[field] = z.literal(true).optional();
3316
+ acc[field] = z$1.literal(true).optional();
3300
3317
  return acc;
3301
3318
  }, {})
3302
3319
  })]);
@@ -3304,7 +3321,7 @@ var ZodSchemaFactory = class {
3304
3321
  return schema;
3305
3322
  }
3306
3323
  makeAggregateSchema(model, options) {
3307
- const result = this.mergePluginArgsSchema(z.strictObject({
3324
+ const result = this.mergePluginArgsSchema(z$1.strictObject({
3308
3325
  where: this.makeWhereSchema(model, false, false, false, options).optional(),
3309
3326
  skip: this.makeSkipSchema().optional(),
3310
3327
  take: this.makeTakeSchema().optional(),
@@ -3319,16 +3336,16 @@ var ZodSchemaFactory = class {
3319
3336
  return result;
3320
3337
  }
3321
3338
  makeSumAvgInputSchema(model) {
3322
- const schema = z.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
3323
- if (this.isNumericField(fieldDef)) acc[field] = z.literal(true).optional();
3339
+ const schema = z$1.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
3340
+ if (this.isNumericField(fieldDef)) acc[field] = z$1.literal(true).optional();
3324
3341
  return acc;
3325
3342
  }, {}));
3326
3343
  this.registerSchema(`${model}SumAvgAggregateInput`, schema);
3327
3344
  return schema;
3328
3345
  }
3329
3346
  makeMinMaxInputSchema(model) {
3330
- const schema = z.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
3331
- if (!fieldDef.relation && !fieldDef.array) acc[field] = z.literal(true).optional();
3347
+ const schema = z$1.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
3348
+ if (!fieldDef.relation && !fieldDef.array) acc[field] = z$1.literal(true).optional();
3332
3349
  return acc;
3333
3350
  }, {}));
3334
3351
  this.registerSchema(`${model}MinMaxAggregateInput`, schema);
@@ -3336,8 +3353,8 @@ var ZodSchemaFactory = class {
3336
3353
  }
3337
3354
  makeGroupBySchema(model, options) {
3338
3355
  const nonRelationFields = this.getModelFields(model).filter(([, def]) => !def.relation).map(([name]) => name);
3339
- const bySchema = nonRelationFields.length > 0 ? this.orArray(z.enum(nonRelationFields), true) : z.never();
3340
- const baseSchema = z.strictObject({
3356
+ const bySchema = nonRelationFields.length > 0 ? this.orArray(z$1.enum(nonRelationFields), true) : z$1.never();
3357
+ const baseSchema = z$1.strictObject({
3341
3358
  where: this.makeWhereSchema(model, false, false, false, options).optional(),
3342
3359
  orderBy: this.orArray(this.makeOrderBySchema(model, false, true, options), true).optional(),
3343
3360
  by: bySchema,
@@ -3389,7 +3406,7 @@ var ZodSchemaFactory = class {
3389
3406
  if (!procDef) throw createInternalError(`Procedure not found: ${procName}`);
3390
3407
  const shape = {};
3391
3408
  for (const param of Object.values(procDef.params ?? {})) shape[param.name] = this.makeProcedureParamSchema(param);
3392
- const schema = z.object(shape);
3409
+ const schema = z$1.object(shape);
3393
3410
  this.registerSchema(`${procName}ProcArgs`, schema);
3394
3411
  return schema;
3395
3412
  }
@@ -3397,10 +3414,10 @@ var ZodSchemaFactory = class {
3397
3414
  let schema;
3398
3415
  if (isTypeDef(this.schema, param.type)) schema = this.makeTypeDefSchema(param.type);
3399
3416
  else if (isEnum(this.schema, param.type)) schema = this.makeEnumSchema(param.type);
3400
- else if (param.type in (this.schema.models ?? {})) schema = z.record(z.string(), z.unknown());
3417
+ else if (param.type in (this.schema.models ?? {})) schema = z$1.record(z$1.string(), z$1.unknown());
3401
3418
  else {
3402
3419
  schema = this.makeScalarSchema(param.type);
3403
- if (schema instanceof z.ZodUnknown) throw createInternalError(`Unsupported procedure parameter type: ${param.type}`);
3420
+ if (schema instanceof z$1.ZodUnknown) throw createInternalError(`Unsupported procedure parameter type: ${param.type}`);
3404
3421
  }
3405
3422
  if (param.array) schema = schema.array();
3406
3423
  if (param.optional) schema = schema.optional();
@@ -3436,10 +3453,10 @@ var ZodSchemaFactory = class {
3436
3453
  return result;
3437
3454
  }
3438
3455
  makeSkipSchema() {
3439
- return z.number().int().nonnegative();
3456
+ return z$1.number().int().nonnegative();
3440
3457
  }
3441
3458
  makeTakeSchema() {
3442
- return z.number().int();
3459
+ return z$1.number().int();
3443
3460
  }
3444
3461
  refineForSelectIncludeMutuallyExclusive(schema) {
3445
3462
  return schema.refine((value) => !(value["select"] && value["include"]), "\"select\" and \"include\" cannot be used together");
@@ -3458,7 +3475,7 @@ var ZodSchemaFactory = class {
3458
3475
  return nullable ? schema.nullable() : schema;
3459
3476
  }
3460
3477
  orArray(schema, canBeArray) {
3461
- return canBeArray ? z.union([schema, z.array(schema)]) : schema;
3478
+ return canBeArray ? z$1.union([schema, z$1.array(schema)]) : schema;
3462
3479
  }
3463
3480
  isNumericField(fieldDef) {
3464
3481
  return NUMERIC_FIELD_TYPES.includes(fieldDef.type) && !fieldDef.array;
@@ -3520,10 +3537,10 @@ var ZodSchemaFactory = class {
3520
3537
  createUnionFilterSchema(valueSchema, optional, components, allowedFilterKinds) {
3521
3538
  if (Object.keys(components).length === 0) {
3522
3539
  if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return this.nullableIf(valueSchema, optional);
3523
- return z.never();
3540
+ return z$1.never();
3524
3541
  }
3525
- if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return z.union([this.nullableIf(valueSchema, optional), z.strictObject(components)]);
3526
- else return z.strictObject(components);
3542
+ if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return z$1.union([this.nullableIf(valueSchema, optional), z$1.strictObject(components)]);
3543
+ else return z$1.strictObject(components);
3527
3544
  }
3528
3545
  canCreateModel(model) {
3529
3546
  const modelDef = requireModel(this.schema, model);
@@ -7131,9 +7148,9 @@ var ClientImpl = class ClientImpl {
7131
7148
  validateOptions(baseClient, options) {
7132
7149
  if (!baseClient && !options.skipValidationForComputedFields) this.validateComputedFieldsConfig(options);
7133
7150
  if (options.diagnostics) {
7134
- const parseResult = z$1.object({
7135
- slowQueryThresholdMs: z$1.number().nonnegative().optional(),
7136
- slowQueryMaxRecords: z$1.int().nonnegative().or(z$1.literal(Infinity)).optional()
7151
+ const parseResult = z.object({
7152
+ slowQueryThresholdMs: z.number().nonnegative().optional(),
7153
+ slowQueryMaxRecords: z.int().nonnegative().or(z.literal(Infinity)).optional()
7137
7154
  }).safeParse(options.diagnostics);
7138
7155
  if (!parseResult.success) throw createConfigError(`Invalid diagnostics configuration: ${formatError(parseResult.error)}`);
7139
7156
  }