@zenstackhq/orm 3.2.1 → 3.3.0-beta.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.js CHANGED
@@ -1122,7 +1122,15 @@ var BaseCrudDialect = class {
1122
1122
  } else {
1123
1123
  return this.eb.not(this.eb(lhs, "in", rhs));
1124
1124
  }
1125
- }).with("lt", () => this.eb(lhs, "<", rhs)).with("lte", () => this.eb(lhs, "<=", rhs)).with("gt", () => this.eb(lhs, ">", rhs)).with("gte", () => this.eb(lhs, ">=", rhs)).with("not", () => this.eb.not(recurse(value))).with(P.union(...AGGREGATE_OPERATORS), (op2) => {
1125
+ }).with("lt", () => this.eb(lhs, "<", rhs)).with("lte", () => this.eb(lhs, "<=", rhs)).with("gt", () => this.eb(lhs, ">", rhs)).with("gte", () => this.eb(lhs, ">=", rhs)).with("between", () => {
1126
+ invariant2(Array.isArray(rhs), "right hand side must be an array");
1127
+ invariant2(rhs.length === 2, "right hand side must have a length of 2");
1128
+ const [start, end] = rhs;
1129
+ return this.eb.and([
1130
+ this.eb(lhs, ">=", start),
1131
+ this.eb(lhs, "<=", end)
1132
+ ]);
1133
+ }).with("not", () => this.eb.not(recurse(value))).with(P.union(...AGGREGATE_OPERATORS), (op2) => {
1126
1134
  const innerResult = this.buildStandardFilter(type, value, aggregate(this.eb, lhs, op2), getRhs, recurse, throwIfInvalid);
1127
1135
  consumedKeys.push(...innerResult.consumedKeys);
1128
1136
  return this.and(...innerResult.conditions);
@@ -2070,6 +2078,70 @@ function getCrudDialect(schema, options) {
2070
2078
  __name(getCrudDialect, "getCrudDialect");
2071
2079
 
2072
2080
  // src/client/crud/operations/base.ts
2081
+ var CoreCrudOperations = [
2082
+ "findMany",
2083
+ "findUnique",
2084
+ "findFirst",
2085
+ "create",
2086
+ "createMany",
2087
+ "createManyAndReturn",
2088
+ "update",
2089
+ "updateMany",
2090
+ "updateManyAndReturn",
2091
+ "upsert",
2092
+ "delete",
2093
+ "deleteMany",
2094
+ "count",
2095
+ "aggregate",
2096
+ "groupBy",
2097
+ "exists"
2098
+ ];
2099
+ var CoreReadOperations = [
2100
+ "findMany",
2101
+ "findUnique",
2102
+ "findFirst",
2103
+ "count",
2104
+ "aggregate",
2105
+ "groupBy",
2106
+ "exists"
2107
+ ];
2108
+ var CoreWriteOperations = [
2109
+ "create",
2110
+ "createMany",
2111
+ "createManyAndReturn",
2112
+ "update",
2113
+ "updateMany",
2114
+ "updateManyAndReturn",
2115
+ "upsert",
2116
+ "delete",
2117
+ "deleteMany"
2118
+ ];
2119
+ var CoreCreateOperations = [
2120
+ "create",
2121
+ "createMany",
2122
+ "createManyAndReturn",
2123
+ "upsert"
2124
+ ];
2125
+ var CoreUpdateOperations = [
2126
+ "update",
2127
+ "updateMany",
2128
+ "updateManyAndReturn",
2129
+ "upsert"
2130
+ ];
2131
+ var CoreDeleteOperations = [
2132
+ "delete",
2133
+ "deleteMany"
2134
+ ];
2135
+ var AllCrudOperations = [
2136
+ ...CoreCrudOperations,
2137
+ "findUniqueOrThrow",
2138
+ "findFirstOrThrow"
2139
+ ];
2140
+ var AllReadOperations = [
2141
+ ...CoreReadOperations,
2142
+ "findUniqueOrThrow",
2143
+ "findFirstOrThrow"
2144
+ ];
2073
2145
  var BaseOperationHandler = class {
2074
2146
  static {
2075
2147
  __name(this, "BaseOperationHandler");
@@ -3722,6 +3794,18 @@ var DeleteOperationHandler = class extends BaseOperationHandler {
3722
3794
  }
3723
3795
  };
3724
3796
 
3797
+ // src/client/crud/operations/exists.ts
3798
+ var ExistsOperationHandler = class extends BaseOperationHandler {
3799
+ static {
3800
+ __name(this, "ExistsOperationHandler");
3801
+ }
3802
+ async handle(_operation, args) {
3803
+ const normalizedArgs = this.normalizeArgs(args);
3804
+ const parsedArgs = this.inputValidator.validateExistsArgs(this.model, normalizedArgs);
3805
+ return await this.existsNonUnique(this.client.$qb, this.model, parsedArgs?.where);
3806
+ }
3807
+ };
3808
+
3725
3809
  // src/client/crud/operations/find.ts
3726
3810
  var FindOperationHandler = class extends BaseOperationHandler {
3727
3811
  static {
@@ -3730,10 +3814,7 @@ var FindOperationHandler = class extends BaseOperationHandler {
3730
3814
  async handle(operation, args, validateArgs = true) {
3731
3815
  const normalizedArgs = this.normalizeArgs(args);
3732
3816
  const findOne = operation === "findFirst" || operation === "findUnique";
3733
- let parsedArgs = validateArgs ? this.inputValidator.validateFindArgs(this.model, normalizedArgs, {
3734
- unique: operation === "findUnique",
3735
- findOne
3736
- }) : normalizedArgs;
3817
+ let parsedArgs = validateArgs ? this.inputValidator.validateFindArgs(this.model, normalizedArgs, operation) : normalizedArgs;
3737
3818
  if (findOne) {
3738
3819
  parsedArgs = parsedArgs ?? {};
3739
3820
  parsedArgs.take = 1;
@@ -3744,18 +3825,6 @@ var FindOperationHandler = class extends BaseOperationHandler {
3744
3825
  }
3745
3826
  };
3746
3827
 
3747
- // src/client/crud/operations/exists.ts
3748
- var ExistsOperationHandler = class extends BaseOperationHandler {
3749
- static {
3750
- __name(this, "ExistsOperationHandler");
3751
- }
3752
- async handle(_operation, args) {
3753
- const normalizedArgs = this.normalizeArgs(args);
3754
- const parsedArgs = this.inputValidator.validateExistsArgs(this.model, normalizedArgs);
3755
- return await this.existsNonUnique(this.client.$qb, this.model, parsedArgs?.where);
3756
- }
3757
- };
3758
-
3759
3828
  // src/client/crud/operations/group-by.ts
3760
3829
  import { match as match10 } from "ts-pattern";
3761
3830
  var GroupByOperationHandler = class extends BaseOperationHandler {
@@ -4354,12 +4423,12 @@ function evalCall(data, expr) {
4354
4423
  __name(evalCall, "evalCall");
4355
4424
 
4356
4425
  // src/client/crud/validator/index.ts
4357
- var schemaCache = /* @__PURE__ */ new WeakMap();
4358
4426
  var InputValidator = class {
4359
4427
  static {
4360
4428
  __name(this, "InputValidator");
4361
4429
  }
4362
4430
  client;
4431
+ schemaCache = /* @__PURE__ */ new Map();
4363
4432
  constructor(client) {
4364
4433
  this.client = client;
4365
4434
  }
@@ -4456,75 +4525,64 @@ var InputValidator = class {
4456
4525
  }
4457
4526
  return schema;
4458
4527
  }
4459
- validateFindArgs(model, args, options) {
4460
- return this.validate(model, "find", options, (model2, options2) => this.makeFindSchema(model2, options2), args);
4528
+ validateFindArgs(model, args, operation) {
4529
+ return this.validate(model, operation, (model2) => this.makeFindSchema(model2, operation), args);
4461
4530
  }
4462
4531
  validateExistsArgs(model, args) {
4463
- return this.validate(model, "exists", void 0, (model2) => this.makeExistsSchema(model2), args);
4532
+ return this.validate(model, "exists", (model2) => this.makeExistsSchema(model2), args);
4464
4533
  }
4465
4534
  validateCreateArgs(model, args) {
4466
- return this.validate(model, "create", void 0, (model2) => this.makeCreateSchema(model2), args);
4535
+ return this.validate(model, "create", (model2) => this.makeCreateSchema(model2), args);
4467
4536
  }
4468
4537
  validateCreateManyArgs(model, args) {
4469
- return this.validate(model, "createMany", void 0, (model2) => this.makeCreateManySchema(model2), args);
4538
+ return this.validate(model, "createMany", (model2) => this.makeCreateManySchema(model2), args);
4470
4539
  }
4471
4540
  validateCreateManyAndReturnArgs(model, args) {
4472
- return this.validate(model, "createManyAndReturn", void 0, (model2) => this.makeCreateManyAndReturnSchema(model2), args);
4541
+ return this.validate(model, "createManyAndReturn", (model2) => this.makeCreateManyAndReturnSchema(model2), args);
4473
4542
  }
4474
4543
  validateUpdateArgs(model, args) {
4475
- return this.validate(model, "update", void 0, (model2) => this.makeUpdateSchema(model2), args);
4544
+ return this.validate(model, "update", (model2) => this.makeUpdateSchema(model2), args);
4476
4545
  }
4477
4546
  validateUpdateManyArgs(model, args) {
4478
- return this.validate(model, "updateMany", void 0, (model2) => this.makeUpdateManySchema(model2), args);
4547
+ return this.validate(model, "updateMany", (model2) => this.makeUpdateManySchema(model2), args);
4479
4548
  }
4480
4549
  validateUpdateManyAndReturnArgs(model, args) {
4481
- return this.validate(model, "updateManyAndReturn", void 0, (model2) => this.makeUpdateManyAndReturnSchema(model2), args);
4550
+ return this.validate(model, "updateManyAndReturn", (model2) => this.makeUpdateManyAndReturnSchema(model2), args);
4482
4551
  }
4483
4552
  validateUpsertArgs(model, args) {
4484
- return this.validate(model, "upsert", void 0, (model2) => this.makeUpsertSchema(model2), args);
4553
+ return this.validate(model, "upsert", (model2) => this.makeUpsertSchema(model2), args);
4485
4554
  }
4486
4555
  validateDeleteArgs(model, args) {
4487
- return this.validate(model, "delete", void 0, (model2) => this.makeDeleteSchema(model2), args);
4556
+ return this.validate(model, "delete", (model2) => this.makeDeleteSchema(model2), args);
4488
4557
  }
4489
4558
  validateDeleteManyArgs(model, args) {
4490
- return this.validate(model, "deleteMany", void 0, (model2) => this.makeDeleteManySchema(model2), args);
4559
+ return this.validate(model, "deleteMany", (model2) => this.makeDeleteManySchema(model2), args);
4491
4560
  }
4492
4561
  validateCountArgs(model, args) {
4493
- return this.validate(model, "count", void 0, (model2) => this.makeCountSchema(model2), args);
4562
+ return this.validate(model, "count", (model2) => this.makeCountSchema(model2), args);
4494
4563
  }
4495
4564
  validateAggregateArgs(model, args) {
4496
- return this.validate(model, "aggregate", void 0, (model2) => this.makeAggregateSchema(model2), args);
4565
+ return this.validate(model, "aggregate", (model2) => this.makeAggregateSchema(model2), args);
4497
4566
  }
4498
4567
  validateGroupByArgs(model, args) {
4499
- return this.validate(model, "groupBy", void 0, (model2) => this.makeGroupBySchema(model2), args);
4568
+ return this.validate(model, "groupBy", (model2) => this.makeGroupBySchema(model2), args);
4500
4569
  }
4501
4570
  getSchemaCache(cacheKey) {
4502
- let thisCache = schemaCache.get(this.schema);
4503
- if (!thisCache) {
4504
- thisCache = /* @__PURE__ */ new Map();
4505
- schemaCache.set(this.schema, thisCache);
4506
- }
4507
- return thisCache.get(cacheKey);
4571
+ return this.schemaCache.get(cacheKey);
4508
4572
  }
4509
4573
  setSchemaCache(cacheKey, schema) {
4510
- let thisCache = schemaCache.get(this.schema);
4511
- if (!thisCache) {
4512
- thisCache = /* @__PURE__ */ new Map();
4513
- schemaCache.set(this.schema, thisCache);
4514
- }
4515
- return thisCache.set(cacheKey, schema);
4574
+ return this.schemaCache.set(cacheKey, schema);
4516
4575
  }
4517
- validate(model, operation, options, getSchema, args) {
4576
+ validate(model, operation, getSchema, args) {
4518
4577
  const cacheKey = stableStringify({
4519
4578
  type: "model",
4520
4579
  model,
4521
4580
  operation,
4522
- options,
4523
4581
  extraValidationsEnabled: this.extraValidationsEnabled
4524
4582
  });
4525
4583
  let schema = this.getSchemaCache(cacheKey);
4526
4584
  if (!schema) {
4527
- schema = getSchema(model, options);
4585
+ schema = getSchema(model);
4528
4586
  this.setSchemaCache(cacheKey, schema);
4529
4587
  }
4530
4588
  const { error, data } = schema.safeParse(args);
@@ -4535,11 +4593,61 @@ var InputValidator = class {
4535
4593
  }
4536
4594
  return data;
4537
4595
  }
4596
+ mergePluginArgsSchema(schema, operation) {
4597
+ let result = schema;
4598
+ for (const plugin of this.options.plugins ?? []) {
4599
+ if (plugin.queryArgs) {
4600
+ const pluginSchema = this.getPluginExtQueryArgsSchema(plugin, operation);
4601
+ if (pluginSchema) {
4602
+ result = result.extend(pluginSchema.shape);
4603
+ }
4604
+ }
4605
+ }
4606
+ return result.strict();
4607
+ }
4608
+ getPluginExtQueryArgsSchema(plugin, operation) {
4609
+ if (!plugin.queryArgs) {
4610
+ return void 0;
4611
+ }
4612
+ let result;
4613
+ if (operation in plugin.queryArgs && plugin.queryArgs[operation]) {
4614
+ result = plugin.queryArgs[operation];
4615
+ } else if (operation === "upsert") {
4616
+ const createSchema = "$create" in plugin.queryArgs && plugin.queryArgs["$create"] ? plugin.queryArgs["$create"] : void 0;
4617
+ const updateSchema = "$update" in plugin.queryArgs && plugin.queryArgs["$update"] ? plugin.queryArgs["$update"] : void 0;
4618
+ if (createSchema && updateSchema) {
4619
+ invariant7(createSchema instanceof z3.ZodObject, "Plugin extended query args schema must be a Zod object");
4620
+ invariant7(updateSchema instanceof z3.ZodObject, "Plugin extended query args schema must be a Zod object");
4621
+ result = createSchema.extend(updateSchema.shape);
4622
+ } else if (createSchema) {
4623
+ result = createSchema;
4624
+ } else if (updateSchema) {
4625
+ result = updateSchema;
4626
+ }
4627
+ } else if (
4628
+ // then comes grouped operations: $create, $read, $update, $delete
4629
+ CoreCreateOperations.includes(operation) && "$create" in plugin.queryArgs && plugin.queryArgs["$create"]
4630
+ ) {
4631
+ result = plugin.queryArgs["$create"];
4632
+ } else if (CoreReadOperations.includes(operation) && "$read" in plugin.queryArgs && plugin.queryArgs["$read"]) {
4633
+ result = plugin.queryArgs["$read"];
4634
+ } else if (CoreUpdateOperations.includes(operation) && "$update" in plugin.queryArgs && plugin.queryArgs["$update"]) {
4635
+ result = plugin.queryArgs["$update"];
4636
+ } else if (CoreDeleteOperations.includes(operation) && "$delete" in plugin.queryArgs && plugin.queryArgs["$delete"]) {
4637
+ result = plugin.queryArgs["$delete"];
4638
+ } else if ("$all" in plugin.queryArgs && plugin.queryArgs["$all"]) {
4639
+ result = plugin.queryArgs["$all"];
4640
+ }
4641
+ invariant7(result === void 0 || result instanceof z3.ZodObject, "Plugin extended query args schema must be a Zod object");
4642
+ return result;
4643
+ }
4538
4644
  // #region Find
4539
- makeFindSchema(model, options) {
4645
+ makeFindSchema(model, operation) {
4540
4646
  const fields = {};
4541
- const where = this.makeWhereSchema(model, options.unique);
4542
- if (options.unique) {
4647
+ const unique = operation === "findUnique";
4648
+ const findOne = operation === "findUnique" || operation === "findFirst";
4649
+ const where = this.makeWhereSchema(model, unique);
4650
+ if (unique) {
4543
4651
  fields["where"] = where;
4544
4652
  } else {
4545
4653
  fields["where"] = where.optional();
@@ -4547,9 +4655,9 @@ var InputValidator = class {
4547
4655
  fields["select"] = this.makeSelectSchema(model).optional().nullable();
4548
4656
  fields["include"] = this.makeIncludeSchema(model).optional().nullable();
4549
4657
  fields["omit"] = this.makeOmitSchema(model).optional().nullable();
4550
- if (!options.unique) {
4658
+ if (!unique) {
4551
4659
  fields["skip"] = this.makeSkipSchema().optional();
4552
- if (options.findOne) {
4660
+ if (findOne) {
4553
4661
  fields["take"] = z3.literal(1).optional();
4554
4662
  } else {
4555
4663
  fields["take"] = this.makeTakeSchema().optional();
@@ -4558,18 +4666,20 @@ var InputValidator = class {
4558
4666
  fields["cursor"] = this.makeCursorSchema(model).optional();
4559
4667
  fields["distinct"] = this.makeDistinctSchema(model).optional();
4560
4668
  }
4561
- let result = z3.strictObject(fields);
4669
+ const baseSchema = z3.strictObject(fields);
4670
+ let result = this.mergePluginArgsSchema(baseSchema, operation);
4562
4671
  result = this.refineForSelectIncludeMutuallyExclusive(result);
4563
4672
  result = this.refineForSelectOmitMutuallyExclusive(result);
4564
- if (!options.unique) {
4673
+ if (!unique) {
4565
4674
  result = result.optional();
4566
4675
  }
4567
4676
  return result;
4568
4677
  }
4569
4678
  makeExistsSchema(model) {
4570
- return z3.strictObject({
4679
+ const baseSchema = z3.strictObject({
4571
4680
  where: this.makeWhereSchema(model, false).optional()
4572
- }).optional();
4681
+ });
4682
+ return this.mergePluginArgsSchema(baseSchema, "exists").optional();
4573
4683
  }
4574
4684
  makeScalarSchema(type, attributes) {
4575
4685
  if (this.schema.typeDefs && type in this.schema.typeDefs) {
@@ -4915,6 +5025,7 @@ var InputValidator = class {
4915
5025
  lte: baseSchema.optional(),
4916
5026
  gt: baseSchema.optional(),
4917
5027
  gte: baseSchema.optional(),
5028
+ between: baseSchema.array().length(2).optional(),
4918
5029
  not: makeThis().optional(),
4919
5030
  ...withAggregations?.includes("_count") ? {
4920
5031
  _count: this.makeNumberFilterSchema(z3.number().int(), false, false).optional()
@@ -5137,25 +5248,27 @@ var InputValidator = class {
5137
5248
  // #region Create
5138
5249
  makeCreateSchema(model) {
5139
5250
  const dataSchema = this.makeCreateDataSchema(model, false);
5140
- let schema = z3.strictObject({
5251
+ const baseSchema = z3.strictObject({
5141
5252
  data: dataSchema,
5142
5253
  select: this.makeSelectSchema(model).optional().nullable(),
5143
5254
  include: this.makeIncludeSchema(model).optional().nullable(),
5144
5255
  omit: this.makeOmitSchema(model).optional().nullable()
5145
5256
  });
5257
+ let schema = this.mergePluginArgsSchema(baseSchema, "create");
5146
5258
  schema = this.refineForSelectIncludeMutuallyExclusive(schema);
5147
5259
  schema = this.refineForSelectOmitMutuallyExclusive(schema);
5148
5260
  return schema;
5149
5261
  }
5150
5262
  makeCreateManySchema(model) {
5151
- return this.makeCreateManyDataSchema(model, []).optional();
5263
+ return this.mergePluginArgsSchema(this.makeCreateManyDataSchema(model, []), "createMany").optional();
5152
5264
  }
5153
5265
  makeCreateManyAndReturnSchema(model) {
5154
5266
  const base = this.makeCreateManyDataSchema(model, []);
5155
- const result = base.extend({
5267
+ let result = base.extend({
5156
5268
  select: this.makeSelectSchema(model).optional().nullable(),
5157
5269
  omit: this.makeOmitSchema(model).optional().nullable()
5158
5270
  });
5271
+ result = this.mergePluginArgsSchema(result, "createManyAndReturn");
5159
5272
  return this.refineForSelectOmitMutuallyExclusive(result).optional();
5160
5273
  }
5161
5274
  makeCreateDataSchema(model, canBeArray, withoutFields = [], withoutRelationFields = false) {
@@ -5348,27 +5461,28 @@ var InputValidator = class {
5348
5461
  // #endregion
5349
5462
  // #region Update
5350
5463
  makeUpdateSchema(model) {
5351
- let schema = z3.strictObject({
5464
+ const baseSchema = z3.strictObject({
5352
5465
  where: this.makeWhereSchema(model, true),
5353
5466
  data: this.makeUpdateDataSchema(model),
5354
5467
  select: this.makeSelectSchema(model).optional().nullable(),
5355
5468
  include: this.makeIncludeSchema(model).optional().nullable(),
5356
5469
  omit: this.makeOmitSchema(model).optional().nullable()
5357
5470
  });
5471
+ let schema = this.mergePluginArgsSchema(baseSchema, "update");
5358
5472
  schema = this.refineForSelectIncludeMutuallyExclusive(schema);
5359
5473
  schema = this.refineForSelectOmitMutuallyExclusive(schema);
5360
5474
  return schema;
5361
5475
  }
5362
5476
  makeUpdateManySchema(model) {
5363
- return z3.strictObject({
5477
+ return this.mergePluginArgsSchema(z3.strictObject({
5364
5478
  where: this.makeWhereSchema(model, false).optional(),
5365
5479
  data: this.makeUpdateDataSchema(model, [], true),
5366
5480
  limit: z3.number().int().nonnegative().optional()
5367
- });
5481
+ }), "updateMany");
5368
5482
  }
5369
5483
  makeUpdateManyAndReturnSchema(model) {
5370
- const base = this.makeUpdateManySchema(model);
5371
- let schema = base.extend({
5484
+ const baseSchema = this.makeUpdateManySchema(model);
5485
+ let schema = baseSchema.extend({
5372
5486
  select: this.makeSelectSchema(model).optional().nullable(),
5373
5487
  omit: this.makeOmitSchema(model).optional().nullable()
5374
5488
  });
@@ -5376,7 +5490,7 @@ var InputValidator = class {
5376
5490
  return schema;
5377
5491
  }
5378
5492
  makeUpsertSchema(model) {
5379
- let schema = z3.strictObject({
5493
+ const baseSchema = z3.strictObject({
5380
5494
  where: this.makeWhereSchema(model, true),
5381
5495
  create: this.makeCreateDataSchema(model, false),
5382
5496
  update: this.makeUpdateDataSchema(model),
@@ -5384,6 +5498,7 @@ var InputValidator = class {
5384
5498
  include: this.makeIncludeSchema(model).optional().nullable(),
5385
5499
  omit: this.makeOmitSchema(model).optional().nullable()
5386
5500
  });
5501
+ let schema = this.mergePluginArgsSchema(baseSchema, "upsert");
5387
5502
  schema = this.refineForSelectIncludeMutuallyExclusive(schema);
5388
5503
  schema = this.refineForSelectOmitMutuallyExclusive(schema);
5389
5504
  return schema;
@@ -5477,32 +5592,33 @@ var InputValidator = class {
5477
5592
  // #endregion
5478
5593
  // #region Delete
5479
5594
  makeDeleteSchema(model) {
5480
- let schema = z3.strictObject({
5595
+ const baseSchema = z3.strictObject({
5481
5596
  where: this.makeWhereSchema(model, true),
5482
5597
  select: this.makeSelectSchema(model).optional().nullable(),
5483
5598
  include: this.makeIncludeSchema(model).optional().nullable(),
5484
5599
  omit: this.makeOmitSchema(model).optional().nullable()
5485
5600
  });
5601
+ let schema = this.mergePluginArgsSchema(baseSchema, "delete");
5486
5602
  schema = this.refineForSelectIncludeMutuallyExclusive(schema);
5487
5603
  schema = this.refineForSelectOmitMutuallyExclusive(schema);
5488
5604
  return schema;
5489
5605
  }
5490
5606
  makeDeleteManySchema(model) {
5491
- return z3.object({
5607
+ return this.mergePluginArgsSchema(z3.strictObject({
5492
5608
  where: this.makeWhereSchema(model, false).optional(),
5493
5609
  limit: z3.number().int().nonnegative().optional()
5494
- }).optional();
5610
+ }), "deleteMany").optional();
5495
5611
  }
5496
5612
  // #endregion
5497
5613
  // #region Count
5498
5614
  makeCountSchema(model) {
5499
- return z3.object({
5615
+ return this.mergePluginArgsSchema(z3.strictObject({
5500
5616
  where: this.makeWhereSchema(model, false).optional(),
5501
5617
  skip: this.makeSkipSchema().optional(),
5502
5618
  take: this.makeTakeSchema().optional(),
5503
5619
  orderBy: this.orArray(this.makeOrderBySchema(model, true, false), true).optional(),
5504
5620
  select: this.makeCountAggregateInputSchema(model).optional()
5505
- }).optional();
5621
+ }), "count").optional();
5506
5622
  }
5507
5623
  makeCountAggregateInputSchema(model) {
5508
5624
  const modelDef = requireModel(this.schema, model);
@@ -5520,7 +5636,7 @@ var InputValidator = class {
5520
5636
  // #endregion
5521
5637
  // #region Aggregate
5522
5638
  makeAggregateSchema(model) {
5523
- return z3.object({
5639
+ return this.mergePluginArgsSchema(z3.strictObject({
5524
5640
  where: this.makeWhereSchema(model, false).optional(),
5525
5641
  skip: this.makeSkipSchema().optional(),
5526
5642
  take: this.makeTakeSchema().optional(),
@@ -5530,7 +5646,7 @@ var InputValidator = class {
5530
5646
  _sum: this.makeSumAvgInputSchema(model).optional(),
5531
5647
  _min: this.makeMinMaxInputSchema(model).optional(),
5532
5648
  _max: this.makeMinMaxInputSchema(model).optional()
5533
- }).optional();
5649
+ }), "aggregate").optional();
5534
5650
  }
5535
5651
  makeSumAvgInputSchema(model) {
5536
5652
  const modelDef = requireModel(this.schema, model);
@@ -5556,7 +5672,7 @@ var InputValidator = class {
5556
5672
  const modelDef = requireModel(this.schema, model);
5557
5673
  const nonRelationFields = Object.keys(modelDef.fields).filter((field) => !modelDef.fields[field]?.relation);
5558
5674
  const bySchema = nonRelationFields.length > 0 ? this.orArray(z3.enum(nonRelationFields), true) : z3.never();
5559
- let schema = z3.strictObject({
5675
+ const baseSchema = z3.strictObject({
5560
5676
  where: this.makeWhereSchema(model, false).optional(),
5561
5677
  orderBy: this.orArray(this.makeOrderBySchema(model, false, true), true).optional(),
5562
5678
  by: bySchema,
@@ -5569,6 +5685,7 @@ var InputValidator = class {
5569
5685
  _min: this.makeMinMaxInputSchema(model).optional(),
5570
5686
  _max: this.makeMinMaxInputSchema(model).optional()
5571
5687
  });
5688
+ let schema = this.mergePluginArgsSchema(baseSchema, "groupBy");
5572
5689
  schema = schema.refine((value) => {
5573
5690
  const bys = typeof value.by === "string" ? [
5574
5691
  value.by
@@ -7259,6 +7376,7 @@ var ClientImpl = class _ClientImpl {
7259
7376
  $schema;
7260
7377
  kyselyProps;
7261
7378
  auth;
7379
+ inputValidator;
7262
7380
  constructor(schema, options, baseClient, executor) {
7263
7381
  this.schema = schema;
7264
7382
  this.options = options;
@@ -7295,6 +7413,7 @@ var ClientImpl = class _ClientImpl {
7295
7413
  });
7296
7414
  }
7297
7415
  this.kysely = new Kysely(this.kyselyProps);
7416
+ this.inputValidator = baseClient?.inputValidator ?? new InputValidator(this);
7298
7417
  return createClientProxy(this);
7299
7418
  }
7300
7419
  get $qb() {
@@ -7379,8 +7498,7 @@ var ClientImpl = class _ClientImpl {
7379
7498
  if (!procOptions[name] || typeof procOptions[name] !== "function") {
7380
7499
  throw createConfigError(`Procedure "${name}" does not have a handler configured.`);
7381
7500
  }
7382
- const inputValidator = new InputValidator(this);
7383
- const validatedInput = inputValidator.validateProcedureInput(name, input);
7501
+ const validatedInput = this.inputValidator.validateProcedureInput(name, input);
7384
7502
  const handler = procOptions[name];
7385
7503
  const invokeWithClient = /* @__PURE__ */ __name(async (client, _input) => {
7386
7504
  let proceed = /* @__PURE__ */ __name(async (nextInput) => {
@@ -7430,7 +7548,9 @@ var ClientImpl = class _ClientImpl {
7430
7548
  ...this.options,
7431
7549
  plugins: newPlugins
7432
7550
  };
7433
- return new _ClientImpl(this.schema, newOptions, this);
7551
+ const newClient = new _ClientImpl(this.schema, newOptions, this);
7552
+ newClient.inputValidator = new InputValidator(newClient);
7553
+ return newClient;
7434
7554
  }
7435
7555
  $unuse(pluginId) {
7436
7556
  const newPlugins = [];
@@ -7443,14 +7563,18 @@ var ClientImpl = class _ClientImpl {
7443
7563
  ...this.options,
7444
7564
  plugins: newPlugins
7445
7565
  };
7446
- return new _ClientImpl(this.schema, newOptions, this);
7566
+ const newClient = new _ClientImpl(this.schema, newOptions, this);
7567
+ newClient.inputValidator = new InputValidator(newClient);
7568
+ return newClient;
7447
7569
  }
7448
7570
  $unuseAll() {
7449
7571
  const newOptions = {
7450
7572
  ...this.options,
7451
7573
  plugins: []
7452
7574
  };
7453
- return new _ClientImpl(this.schema, newOptions, this);
7575
+ const newClient = new _ClientImpl(this.schema, newOptions, this);
7576
+ newClient.inputValidator = new InputValidator(newClient);
7577
+ return newClient;
7454
7578
  }
7455
7579
  $setAuth(auth) {
7456
7580
  if (auth !== void 0 && typeof auth !== "object") {
@@ -7464,14 +7588,16 @@ var ClientImpl = class _ClientImpl {
7464
7588
  return this.auth;
7465
7589
  }
7466
7590
  $setOptions(options) {
7467
- return new _ClientImpl(this.schema, options, this);
7591
+ const newClient = new _ClientImpl(this.schema, options, this);
7592
+ newClient.inputValidator = new InputValidator(newClient);
7593
+ return newClient;
7468
7594
  }
7469
7595
  $setInputValidation(enable) {
7470
7596
  const newOptions = {
7471
7597
  ...this.options,
7472
7598
  validateInput: enable
7473
7599
  };
7474
- return new _ClientImpl(this.schema, newOptions, this);
7600
+ return this.$setOptions(newOptions);
7475
7601
  }
7476
7602
  $executeRaw(query, ...values) {
7477
7603
  return createZenStackPromise(async () => {
@@ -7508,17 +7634,24 @@ var ClientImpl = class _ClientImpl {
7508
7634
  }
7509
7635
  };
7510
7636
  function createClientProxy(client) {
7511
- const inputValidator = new InputValidator(client);
7512
7637
  const resultProcessor = new ResultProcessor(client.$schema, client.$options);
7513
7638
  return new Proxy(client, {
7514
7639
  get: /* @__PURE__ */ __name((target, prop, receiver) => {
7515
7640
  if (typeof prop === "string" && prop.startsWith("$")) {
7641
+ const plugins = target.$options.plugins ?? [];
7642
+ for (let i = plugins.length - 1; i >= 0; i--) {
7643
+ const plugin = plugins[i];
7644
+ const clientMembers = plugin?.client;
7645
+ if (clientMembers && prop in clientMembers) {
7646
+ return clientMembers[prop];
7647
+ }
7648
+ }
7516
7649
  return Reflect.get(target, prop, receiver);
7517
7650
  }
7518
7651
  if (typeof prop === "string") {
7519
7652
  const model = Object.keys(client.$schema.models).find((m) => m.toLowerCase() === prop.toLowerCase());
7520
7653
  if (model) {
7521
- return createModelCrudHandler(client, model, inputValidator, resultProcessor);
7654
+ return createModelCrudHandler(client, model, client.inputValidator, resultProcessor);
7522
7655
  }
7523
7656
  }
7524
7657
  return Reflect.get(target, prop, receiver);
@@ -7550,15 +7683,18 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
7550
7683
  const onQuery = plugin.onQuery;
7551
7684
  if (onQuery) {
7552
7685
  const _proceed = proceed;
7553
- proceed = /* @__PURE__ */ __name((_args) => onQuery({
7554
- client,
7555
- model,
7556
- operation: nominalOperation,
7557
- // reflect the latest override if provided
7558
- args: _args,
7559
- // ensure inner overrides are propagated to the previous proceed
7560
- proceed: /* @__PURE__ */ __name((nextArgs) => _proceed(nextArgs), "proceed")
7561
- }), "proceed");
7686
+ proceed = /* @__PURE__ */ __name((_args) => {
7687
+ const ctx = {
7688
+ client,
7689
+ model,
7690
+ operation: nominalOperation,
7691
+ // reflect the latest override if provided
7692
+ args: _args,
7693
+ // ensure inner overrides are propagated to the previous proceed
7694
+ proceed: /* @__PURE__ */ __name((nextArgs) => _proceed(nextArgs), "proceed")
7695
+ };
7696
+ return onQuery(ctx);
7697
+ }, "proceed");
7562
7698
  }
7563
7699
  }
7564
7700
  return proceed(args);
@@ -7578,7 +7714,7 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
7578
7714
  return createPromise("findFirst", "findFirstOrThrow", args, new FindOperationHandler(client, model, inputValidator), true, true);
7579
7715
  }, "findFirstOrThrow"),
7580
7716
  findMany: /* @__PURE__ */ __name((args) => {
7581
- return createPromise("findMany", "findMany", args, new FindOperationHandler(client, model, inputValidator), true);
7717
+ return createPromise("findMany", "findMany", args, new FindOperationHandler(client, model, inputValidator), true, false);
7582
7718
  }, "findMany"),
7583
7719
  create: /* @__PURE__ */ __name((args) => {
7584
7720
  return createPromise("create", "create", args, new CreateOperationHandler(client, model, inputValidator), true);
@@ -8042,11 +8178,19 @@ var MatchingExpressionVisitor = class extends ExpressionVisitor {
8042
8178
  }
8043
8179
  };
8044
8180
  export {
8181
+ AllCrudOperations,
8182
+ AllReadOperations,
8045
8183
  AnyNull,
8046
8184
  AnyNullClass,
8047
8185
  BaseCrudDialect,
8048
8186
  CRUD,
8049
8187
  CRUD_EXT,
8188
+ CoreCreateOperations,
8189
+ CoreCrudOperations,
8190
+ CoreDeleteOperations,
8191
+ CoreReadOperations,
8192
+ CoreUpdateOperations,
8193
+ CoreWriteOperations,
8050
8194
  DbNull,
8051
8195
  DbNullClass,
8052
8196
  InputValidator,