@zenstackhq/orm 3.3.3 → 3.4.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.cjs CHANGED
@@ -644,13 +644,50 @@ var LOGICAL_COMBINATORS = [
644
644
  "OR",
645
645
  "NOT"
646
646
  ];
647
- var AGGREGATE_OPERATORS = [
647
+ var AggregateOperators = [
648
648
  "_count",
649
649
  "_sum",
650
650
  "_avg",
651
651
  "_min",
652
652
  "_max"
653
653
  ];
654
+ var FILTER_PROPERTY_TO_KIND = {
655
+ // Equality operators
656
+ equals: "Equality",
657
+ not: "Equality",
658
+ in: "Equality",
659
+ notIn: "Equality",
660
+ // Range operators
661
+ lt: "Range",
662
+ lte: "Range",
663
+ gt: "Range",
664
+ gte: "Range",
665
+ between: "Range",
666
+ // Like operators
667
+ contains: "Like",
668
+ startsWith: "Like",
669
+ endsWith: "Like",
670
+ mode: "Like",
671
+ // Relation operators
672
+ is: "Relation",
673
+ isNot: "Relation",
674
+ some: "Relation",
675
+ every: "Relation",
676
+ none: "Relation",
677
+ // Json operators
678
+ path: "Json",
679
+ string_contains: "Json",
680
+ string_starts_with: "Json",
681
+ string_ends_with: "Json",
682
+ array_contains: "Json",
683
+ array_starts_with: "Json",
684
+ array_ends_with: "Json",
685
+ // List operators
686
+ has: "List",
687
+ hasEvery: "List",
688
+ hasSome: "List",
689
+ isEmpty: "List"
690
+ };
654
691
 
655
692
  // src/client/contract.ts
656
693
  var TransactionIsolationLevel = /* @__PURE__ */ function(TransactionIsolationLevel2) {
@@ -1213,7 +1250,7 @@ var BaseCrudDialect = class {
1213
1250
  this.eb(lhs, ">=", start),
1214
1251
  this.eb(lhs, "<=", end)
1215
1252
  ]);
1216
- }).with("not", () => this.eb.not(recurse(value))).with(import_ts_pattern2.P.union(...AGGREGATE_OPERATORS), (op2) => {
1253
+ }).with("not", () => this.eb.not(recurse(value))).with(import_ts_pattern2.P.union(...AggregateOperators), (op2) => {
1217
1254
  const innerResult = this.buildStandardFilter(type, value, aggregate(this.eb, lhs, op2), getRhs, recurse, throwIfInvalid);
1218
1255
  consumedKeys.push(...innerResult.consumedKeys);
1219
1256
  return this.and(...innerResult.conditions);
@@ -5296,6 +5333,10 @@ var InputValidator = class {
5296
5333
  }
5297
5334
  makeWhereSchema(model, unique, withoutRelationFields = false, withAggregations = false) {
5298
5335
  const modelDef = requireModel(this.schema, model);
5336
+ const uniqueFieldNames = unique ? getUniqueFields(this.schema, model).filter((uf) => (
5337
+ // single-field unique
5338
+ "def" in uf
5339
+ )).map((uf) => uf.name) : void 0;
5299
5340
  const fields = {};
5300
5341
  for (const field of Object.keys(modelDef.fields)) {
5301
5342
  const fieldDef = requireField(this.schema, model, field);
@@ -5304,38 +5345,44 @@ var InputValidator = class {
5304
5345
  if (withoutRelationFields) {
5305
5346
  continue;
5306
5347
  }
5307
- fieldSchema = import_zod2.z.lazy(() => this.makeWhereSchema(fieldDef.type, false).optional());
5308
- fieldSchema = this.nullableIf(fieldSchema, !fieldDef.array && !!fieldDef.optional);
5309
- if (fieldDef.array) {
5310
- fieldSchema = import_zod2.z.union([
5311
- fieldSchema,
5312
- import_zod2.z.strictObject({
5313
- some: fieldSchema.optional(),
5314
- every: fieldSchema.optional(),
5315
- none: fieldSchema.optional()
5316
- })
5317
- ]);
5348
+ const allowedFilterKinds = this.getEffectiveFilterKinds(model, field);
5349
+ if (allowedFilterKinds && !allowedFilterKinds.has("Relation")) {
5350
+ fieldSchema = import_zod2.z.never();
5318
5351
  } else {
5319
- fieldSchema = import_zod2.z.union([
5320
- fieldSchema,
5321
- import_zod2.z.strictObject({
5322
- is: fieldSchema.optional(),
5323
- isNot: fieldSchema.optional()
5324
- })
5325
- ]);
5352
+ fieldSchema = import_zod2.z.lazy(() => this.makeWhereSchema(fieldDef.type, false).optional());
5353
+ fieldSchema = this.nullableIf(fieldSchema, !fieldDef.array && !!fieldDef.optional);
5354
+ if (fieldDef.array) {
5355
+ fieldSchema = import_zod2.z.union([
5356
+ fieldSchema,
5357
+ import_zod2.z.strictObject({
5358
+ some: fieldSchema.optional(),
5359
+ every: fieldSchema.optional(),
5360
+ none: fieldSchema.optional()
5361
+ })
5362
+ ]);
5363
+ } else {
5364
+ fieldSchema = import_zod2.z.union([
5365
+ fieldSchema,
5366
+ import_zod2.z.strictObject({
5367
+ is: fieldSchema.optional(),
5368
+ isNot: fieldSchema.optional()
5369
+ })
5370
+ ]);
5371
+ }
5326
5372
  }
5327
5373
  } else {
5374
+ const ignoreSlicing = !!uniqueFieldNames?.includes(field);
5328
5375
  const enumDef = getEnum(this.schema, fieldDef.type);
5329
5376
  if (enumDef) {
5330
5377
  if (Object.keys(enumDef.values).length > 0) {
5331
- fieldSchema = this.makeEnumFilterSchema(fieldDef.type, !!fieldDef.optional, withAggregations, !!fieldDef.array);
5378
+ fieldSchema = this.makeEnumFilterSchema(model, fieldDef, withAggregations, ignoreSlicing);
5332
5379
  }
5333
5380
  } else if (fieldDef.array) {
5334
- fieldSchema = this.makeArrayFilterSchema(fieldDef.type);
5381
+ fieldSchema = this.makeArrayFilterSchema(model, fieldDef);
5335
5382
  } else if (this.isTypeDefType(fieldDef.type)) {
5336
- fieldSchema = this.makeTypedJsonFilterSchema(fieldDef.type, !!fieldDef.optional, !!fieldDef.array);
5383
+ fieldSchema = this.makeTypedJsonFilterSchema(model, fieldDef);
5337
5384
  } else {
5338
- fieldSchema = this.makePrimitiveFilterSchema(fieldDef.type, !!fieldDef.optional, withAggregations);
5385
+ fieldSchema = this.makePrimitiveFilterSchema(model, fieldDef, withAggregations, ignoreSlicing);
5339
5386
  }
5340
5387
  }
5341
5388
  if (fieldSchema) {
@@ -5352,12 +5399,12 @@ var InputValidator = class {
5352
5399
  const enumDef = getEnum(this.schema, def.type);
5353
5400
  if (enumDef) {
5354
5401
  if (Object.keys(enumDef.values).length > 0) {
5355
- fieldSchema = this.makeEnumFilterSchema(def.type, !!def.optional, false, false);
5402
+ fieldSchema = this.makeEnumFilterSchema(model, def, false, true);
5356
5403
  } else {
5357
5404
  fieldSchema = import_zod2.z.never();
5358
5405
  }
5359
5406
  } else {
5360
- fieldSchema = this.makePrimitiveFilterSchema(def.type, !!def.optional, false);
5407
+ fieldSchema = this.makePrimitiveFilterSchema(model, def, false, true);
5361
5408
  }
5362
5409
  return [
5363
5410
  key,
@@ -5392,7 +5439,11 @@ var InputValidator = class {
5392
5439
  }
5393
5440
  return result;
5394
5441
  }
5395
- makeTypedJsonFilterSchema(type, optional, array) {
5442
+ makeTypedJsonFilterSchema(contextModel, fieldInfo) {
5443
+ const field = fieldInfo.name;
5444
+ const type = fieldInfo.type;
5445
+ const optional = !!fieldInfo.optional;
5446
+ const array = !!fieldInfo.array;
5396
5447
  const typeDef = getTypeDef(this.schema, type);
5397
5448
  (0, import_common_helpers9.invariant)(typeDef, `Type definition "${type}" not found in schema`);
5398
5449
  const candidates = [];
@@ -5400,21 +5451,26 @@ var InputValidator = class {
5400
5451
  const fieldSchemas = {};
5401
5452
  for (const [fieldName, fieldDef] of Object.entries(typeDef.fields)) {
5402
5453
  if (this.isTypeDefType(fieldDef.type)) {
5403
- fieldSchemas[fieldName] = this.makeTypedJsonFilterSchema(fieldDef.type, !!fieldDef.optional, !!fieldDef.array).optional();
5454
+ fieldSchemas[fieldName] = this.makeTypedJsonFilterSchema(contextModel, fieldDef).optional();
5404
5455
  } else {
5405
5456
  const enumDef = getEnum(this.schema, fieldDef.type);
5406
5457
  if (enumDef) {
5407
- fieldSchemas[fieldName] = this.makeEnumFilterSchema(fieldDef.type, !!fieldDef.optional, false, !!fieldDef.array).optional();
5458
+ fieldSchemas[fieldName] = this.makeEnumFilterSchema(contextModel, fieldDef, false).optional();
5408
5459
  } else if (fieldDef.array) {
5409
- fieldSchemas[fieldName] = this.makeArrayFilterSchema(fieldDef.type).optional();
5460
+ fieldSchemas[fieldName] = this.makeArrayFilterSchema(contextModel, fieldDef).optional();
5410
5461
  } else {
5411
- fieldSchemas[fieldName] = this.makePrimitiveFilterSchema(fieldDef.type, !!fieldDef.optional, false).optional();
5462
+ fieldSchemas[fieldName] = this.makePrimitiveFilterSchema(contextModel, fieldDef, false).optional();
5412
5463
  }
5413
5464
  }
5414
5465
  }
5415
5466
  candidates.push(import_zod2.z.strictObject(fieldSchemas));
5416
5467
  }
5417
- const recursiveSchema = import_zod2.z.lazy(() => this.makeTypedJsonFilterSchema(type, optional, false)).optional();
5468
+ const recursiveSchema = import_zod2.z.lazy(() => this.makeTypedJsonFilterSchema(contextModel, {
5469
+ name: field,
5470
+ type,
5471
+ optional,
5472
+ array: false
5473
+ })).optional();
5418
5474
  if (array) {
5419
5475
  candidates.push(import_zod2.z.strictObject({
5420
5476
  some: recursiveSchema,
@@ -5427,7 +5483,7 @@ var InputValidator = class {
5427
5483
  isNot: recursiveSchema
5428
5484
  }));
5429
5485
  }
5430
- candidates.push(this.makeJsonFilterSchema(optional));
5486
+ candidates.push(this.makeJsonFilterSchema(contextModel, field, optional));
5431
5487
  if (optional) {
5432
5488
  candidates.push(import_zod2.z.null());
5433
5489
  }
@@ -5436,14 +5492,18 @@ var InputValidator = class {
5436
5492
  isTypeDefType(type) {
5437
5493
  return this.schema.typeDefs && type in this.schema.typeDefs;
5438
5494
  }
5439
- makeEnumFilterSchema(enumName, optional, withAggregations, array) {
5495
+ makeEnumFilterSchema(model, fieldInfo, withAggregations, ignoreSlicing = false) {
5496
+ const enumName = fieldInfo.type;
5497
+ const optional = !!fieldInfo.optional;
5498
+ const array = !!fieldInfo.array;
5440
5499
  const enumDef = getEnum(this.schema, enumName);
5441
5500
  (0, import_common_helpers9.invariant)(enumDef, `Enum "${enumName}" not found in schema`);
5442
5501
  const baseSchema = import_zod2.z.enum(Object.keys(enumDef.values));
5443
5502
  if (array) {
5444
- return this.internalMakeArrayFilterSchema(baseSchema);
5503
+ return this.internalMakeArrayFilterSchema(model, fieldInfo.name, baseSchema);
5445
5504
  }
5446
- const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => import_zod2.z.lazy(() => this.makeEnumFilterSchema(enumName, optional, withAggregations, array)), [
5505
+ const allowedFilterKinds = ignoreSlicing ? void 0 : this.getEffectiveFilterKinds(model, fieldInfo.name);
5506
+ const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => import_zod2.z.lazy(() => this.makeEnumFilterSchema(model, fieldInfo, withAggregations)), [
5447
5507
  "equals",
5448
5508
  "in",
5449
5509
  "notIn",
@@ -5452,26 +5512,29 @@ var InputValidator = class {
5452
5512
  "_count",
5453
5513
  "_min",
5454
5514
  "_max"
5455
- ] : void 0);
5456
- return import_zod2.z.union([
5457
- this.nullableIf(baseSchema, optional),
5458
- import_zod2.z.strictObject(components)
5459
- ]);
5515
+ ] : void 0, allowedFilterKinds);
5516
+ return this.createUnionFilterSchema(baseSchema, optional, components, allowedFilterKinds);
5460
5517
  }
5461
- makeArrayFilterSchema(type) {
5462
- return this.internalMakeArrayFilterSchema(this.makeScalarSchema(type));
5518
+ makeArrayFilterSchema(model, fieldInfo) {
5519
+ return this.internalMakeArrayFilterSchema(model, fieldInfo.name, this.makeScalarSchema(fieldInfo.type));
5463
5520
  }
5464
- internalMakeArrayFilterSchema(elementSchema) {
5465
- return import_zod2.z.strictObject({
5521
+ internalMakeArrayFilterSchema(contextModel, field, elementSchema) {
5522
+ const allowedFilterKinds = this.getEffectiveFilterKinds(contextModel, field);
5523
+ const operators = {
5466
5524
  equals: elementSchema.array().optional(),
5467
5525
  has: elementSchema.optional(),
5468
5526
  hasEvery: elementSchema.array().optional(),
5469
5527
  hasSome: elementSchema.array().optional(),
5470
5528
  isEmpty: import_zod2.z.boolean().optional()
5471
- });
5529
+ };
5530
+ const filteredOperators = this.trimFilterOperators(operators, allowedFilterKinds);
5531
+ return import_zod2.z.strictObject(filteredOperators);
5472
5532
  }
5473
- makePrimitiveFilterSchema(type, optional, withAggregations) {
5474
- return (0, import_ts_pattern14.match)(type).with("String", () => this.makeStringFilterSchema(optional, withAggregations)).with(import_ts_pattern14.P.union("Int", "Float", "Decimal", "BigInt"), (type2) => this.makeNumberFilterSchema(this.makeScalarSchema(type2), optional, withAggregations)).with("Boolean", () => this.makeBooleanFilterSchema(optional, withAggregations)).with("DateTime", () => this.makeDateTimeFilterSchema(optional, withAggregations)).with("Bytes", () => this.makeBytesFilterSchema(optional, withAggregations)).with("Json", () => this.makeJsonFilterSchema(optional)).with("Unsupported", () => import_zod2.z.never()).exhaustive();
5533
+ makePrimitiveFilterSchema(contextModel, fieldInfo, withAggregations, ignoreSlicing = false) {
5534
+ const allowedFilterKinds = ignoreSlicing ? void 0 : this.getEffectiveFilterKinds(contextModel, fieldInfo.name);
5535
+ const type = fieldInfo.type;
5536
+ const optional = !!fieldInfo.optional;
5537
+ return (0, import_ts_pattern14.match)(type).with("String", () => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds)).with(import_ts_pattern14.P.union("Int", "Float", "Decimal", "BigInt"), (type2) => this.makeNumberFilterSchema(this.makeScalarSchema(type2), 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(contextModel, fieldInfo.name, optional)).with("Unsupported", () => import_zod2.z.never()).exhaustive();
5475
5538
  }
5476
5539
  makeJsonValueSchema(nullable, forFilter) {
5477
5540
  const options = [
@@ -5503,7 +5566,11 @@ var InputValidator = class {
5503
5566
  ]);
5504
5567
  return this.nullableIf(schema, nullable);
5505
5568
  }
5506
- makeJsonFilterSchema(optional) {
5569
+ makeJsonFilterSchema(contextModel, field, optional) {
5570
+ const allowedFilterKinds = this.getEffectiveFilterKinds(contextModel, field);
5571
+ if (allowedFilterKinds && !allowedFilterKinds.has("Json")) {
5572
+ return import_zod2.z.never();
5573
+ }
5507
5574
  const valueSchema = this.makeJsonValueSchema(optional, true);
5508
5575
  return import_zod2.z.strictObject({
5509
5576
  path: import_zod2.z.string().optional(),
@@ -5518,31 +5585,28 @@ var InputValidator = class {
5518
5585
  array_ends_with: valueSchema.optional()
5519
5586
  });
5520
5587
  }
5521
- makeDateTimeFilterSchema(optional, withAggregations) {
5588
+ makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds) {
5522
5589
  return this.makeCommonPrimitiveFilterSchema(import_zod2.z.union([
5523
5590
  import_zod2.z.iso.datetime(),
5524
5591
  import_zod2.z.date()
5525
- ]), optional, () => import_zod2.z.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations)), withAggregations ? [
5592
+ ]), optional, () => import_zod2.z.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)), withAggregations ? [
5526
5593
  "_count",
5527
5594
  "_min",
5528
5595
  "_max"
5529
- ] : void 0);
5596
+ ] : void 0, allowedFilterKinds);
5530
5597
  }
5531
- makeBooleanFilterSchema(optional, withAggregations) {
5532
- const components = this.makeCommonPrimitiveFilterComponents(import_zod2.z.boolean(), optional, () => import_zod2.z.lazy(() => this.makeBooleanFilterSchema(optional, withAggregations)), [
5598
+ makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds) {
5599
+ const components = this.makeCommonPrimitiveFilterComponents(import_zod2.z.boolean(), optional, () => import_zod2.z.lazy(() => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)), [
5533
5600
  "equals",
5534
5601
  "not"
5535
5602
  ], withAggregations ? [
5536
5603
  "_count",
5537
5604
  "_min",
5538
5605
  "_max"
5539
- ] : void 0);
5540
- return import_zod2.z.union([
5541
- this.nullableIf(import_zod2.z.boolean(), optional),
5542
- import_zod2.z.strictObject(components)
5543
- ]);
5606
+ ] : void 0, allowedFilterKinds);
5607
+ return this.createUnionFilterSchema(import_zod2.z.boolean(), optional, components, allowedFilterKinds);
5544
5608
  }
5545
- makeBytesFilterSchema(optional, withAggregations) {
5609
+ makeBytesFilterSchema(optional, withAggregations, allowedFilterKinds) {
5546
5610
  const baseSchema = import_zod2.z.instanceof(Uint8Array);
5547
5611
  const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => import_zod2.z.instanceof(Uint8Array), [
5548
5612
  "equals",
@@ -5553,17 +5617,13 @@ var InputValidator = class {
5553
5617
  "_count",
5554
5618
  "_min",
5555
5619
  "_max"
5556
- ] : void 0);
5557
- return import_zod2.z.union([
5558
- this.nullableIf(baseSchema, optional),
5559
- import_zod2.z.strictObject(components)
5560
- ]);
5620
+ ] : void 0, allowedFilterKinds);
5621
+ return this.createUnionFilterSchema(baseSchema, optional, components, allowedFilterKinds);
5561
5622
  }
5562
- makeCommonPrimitiveFilterComponents(baseSchema, optional, makeThis, supportedOperators = void 0, withAggregations = void 0) {
5563
- const commonAggSchema = /* @__PURE__ */ __name(() => this.makeCommonPrimitiveFilterSchema(baseSchema, false, makeThis, void 0).optional(), "commonAggSchema");
5623
+ makeCommonPrimitiveFilterComponents(baseSchema, optional, makeThis, supportedOperators = void 0, withAggregations = void 0, allowedFilterKinds = void 0) {
5624
+ const commonAggSchema = /* @__PURE__ */ __name(() => this.makeCommonPrimitiveFilterSchema(baseSchema, false, makeThis, void 0, allowedFilterKinds).optional(), "commonAggSchema");
5564
5625
  let result = {
5565
5626
  equals: this.nullableIf(baseSchema.optional(), optional),
5566
- notEquals: this.nullableIf(baseSchema.optional(), optional),
5567
5627
  in: baseSchema.array().optional(),
5568
5628
  notIn: baseSchema.array().optional(),
5569
5629
  lt: baseSchema.optional(),
@@ -5573,7 +5633,7 @@ var InputValidator = class {
5573
5633
  between: baseSchema.array().length(2).optional(),
5574
5634
  not: makeThis().optional(),
5575
5635
  ...withAggregations?.includes("_count") ? {
5576
- _count: this.makeNumberFilterSchema(import_zod2.z.number().int(), false, false).optional()
5636
+ _count: this.makeNumberFilterSchema(import_zod2.z.number().int(), false, false, void 0).optional()
5577
5637
  } : {},
5578
5638
  ...withAggregations?.includes("_avg") ? {
5579
5639
  _avg: commonAggSchema()
@@ -5595,40 +5655,42 @@ var InputValidator = class {
5595
5655
  ];
5596
5656
  result = extractFields(result, keys);
5597
5657
  }
5658
+ result = this.trimFilterOperators(result, allowedFilterKinds);
5598
5659
  return result;
5599
5660
  }
5600
- makeCommonPrimitiveFilterSchema(baseSchema, optional, makeThis, withAggregations = void 0) {
5601
- return import_zod2.z.union([
5602
- this.nullableIf(baseSchema, optional),
5603
- import_zod2.z.strictObject(this.makeCommonPrimitiveFilterComponents(baseSchema, optional, makeThis, void 0, withAggregations))
5604
- ]);
5661
+ makeCommonPrimitiveFilterSchema(baseSchema, optional, makeThis, withAggregations = void 0, allowedFilterKinds = void 0) {
5662
+ const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, makeThis, void 0, withAggregations, allowedFilterKinds);
5663
+ return this.createUnionFilterSchema(baseSchema, optional, components, allowedFilterKinds);
5605
5664
  }
5606
- makeNumberFilterSchema(baseSchema, optional, withAggregations) {
5607
- return this.makeCommonPrimitiveFilterSchema(baseSchema, optional, () => import_zod2.z.lazy(() => this.makeNumberFilterSchema(baseSchema, optional, withAggregations)), withAggregations ? [
5665
+ makeNumberFilterSchema(baseSchema, optional, withAggregations, allowedFilterKinds) {
5666
+ return this.makeCommonPrimitiveFilterSchema(baseSchema, optional, () => import_zod2.z.lazy(() => this.makeNumberFilterSchema(baseSchema, optional, withAggregations, allowedFilterKinds)), withAggregations ? [
5608
5667
  "_count",
5609
5668
  "_avg",
5610
5669
  "_sum",
5611
5670
  "_min",
5612
5671
  "_max"
5613
- ] : void 0);
5672
+ ] : void 0, allowedFilterKinds);
5614
5673
  }
5615
- makeStringFilterSchema(optional, withAggregations) {
5616
- return import_zod2.z.union([
5617
- this.nullableIf(import_zod2.z.string(), optional),
5618
- import_zod2.z.strictObject({
5619
- ...this.makeCommonPrimitiveFilterComponents(import_zod2.z.string(), optional, () => import_zod2.z.lazy(() => this.makeStringFilterSchema(optional, withAggregations)), void 0, withAggregations ? [
5620
- "_count",
5621
- "_min",
5622
- "_max"
5623
- ] : void 0),
5624
- startsWith: import_zod2.z.string().optional(),
5625
- endsWith: import_zod2.z.string().optional(),
5626
- contains: import_zod2.z.string().optional(),
5627
- ...this.providerSupportsCaseSensitivity ? {
5628
- mode: this.makeStringModeSchema().optional()
5629
- } : {}
5630
- })
5631
- ]);
5674
+ makeStringFilterSchema(optional, withAggregations, allowedFilterKinds) {
5675
+ const baseComponents = this.makeCommonPrimitiveFilterComponents(import_zod2.z.string(), optional, () => import_zod2.z.lazy(() => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds)), void 0, withAggregations ? [
5676
+ "_count",
5677
+ "_min",
5678
+ "_max"
5679
+ ] : void 0, allowedFilterKinds);
5680
+ const stringSpecificOperators = {
5681
+ startsWith: import_zod2.z.string().optional(),
5682
+ endsWith: import_zod2.z.string().optional(),
5683
+ contains: import_zod2.z.string().optional(),
5684
+ ...this.providerSupportsCaseSensitivity ? {
5685
+ mode: this.makeStringModeSchema().optional()
5686
+ } : {}
5687
+ };
5688
+ const filteredStringOperators = this.trimFilterOperators(stringSpecificOperators, allowedFilterKinds);
5689
+ const allComponents = {
5690
+ ...baseComponents,
5691
+ ...filteredStringOperators
5692
+ };
5693
+ return this.createUnionFilterSchema(import_zod2.z.string(), optional, allComponents, allowedFilterKinds);
5632
5694
  }
5633
5695
  makeStringModeSchema() {
5634
5696
  return import_zod2.z.union([
@@ -5642,7 +5704,9 @@ var InputValidator = class {
5642
5704
  for (const field of Object.keys(modelDef.fields)) {
5643
5705
  const fieldDef = requireField(this.schema, model, field);
5644
5706
  if (fieldDef.relation) {
5645
- fields[field] = this.makeRelationSelectIncludeSchema(model, field).optional();
5707
+ if (this.isModelAllowed(fieldDef.type)) {
5708
+ fields[field] = this.makeRelationSelectIncludeSchema(model, field).optional();
5709
+ }
5646
5710
  } else {
5647
5711
  fields[field] = import_zod2.z.boolean().optional();
5648
5712
  }
@@ -5722,7 +5786,9 @@ var InputValidator = class {
5722
5786
  for (const field of Object.keys(modelDef.fields)) {
5723
5787
  const fieldDef = requireField(this.schema, model, field);
5724
5788
  if (fieldDef.relation) {
5725
- fields[field] = this.makeRelationSelectIncludeSchema(model, field).optional();
5789
+ if (this.isModelAllowed(fieldDef.type)) {
5790
+ fields[field] = this.makeRelationSelectIncludeSchema(model, field).optional();
5791
+ }
5726
5792
  }
5727
5793
  }
5728
5794
  const _countSchema = this.makeCountSelectionSchema(model);
@@ -5838,6 +5904,9 @@ var InputValidator = class {
5838
5904
  if (withoutRelationFields) {
5839
5905
  return;
5840
5906
  }
5907
+ if (!this.isModelAllowed(fieldDef.type)) {
5908
+ return;
5909
+ }
5841
5910
  const excludeFields = [];
5842
5911
  const oppositeField = fieldDef.relation.opposite;
5843
5912
  if (oppositeField) {
@@ -6065,6 +6134,9 @@ var InputValidator = class {
6065
6134
  if (withoutRelationFields) {
6066
6135
  return;
6067
6136
  }
6137
+ if (!this.isModelAllowed(fieldDef.type)) {
6138
+ return;
6139
+ }
6068
6140
  const excludeFields = [];
6069
6141
  const oppositeField = fieldDef.relation.opposite;
6070
6142
  if (oppositeField) {
@@ -6240,7 +6312,7 @@ var InputValidator = class {
6240
6312
  ] : value.by;
6241
6313
  if (value.having && typeof value.having === "object") {
6242
6314
  for (const [key, val] of Object.entries(value.having)) {
6243
- if (AGGREGATE_OPERATORS.includes(key)) {
6315
+ if (AggregateOperators.includes(key)) {
6244
6316
  continue;
6245
6317
  }
6246
6318
  if (bys.includes(key)) {
@@ -6260,7 +6332,7 @@ var InputValidator = class {
6260
6332
  const bys = typeof value.by === "string" ? [
6261
6333
  value.by
6262
6334
  ] : value.by;
6263
- if (value.orderBy && Object.keys(value.orderBy).filter((f) => !AGGREGATE_OPERATORS.includes(f)).some((key) => !bys.includes(key))) {
6335
+ if (value.orderBy && Object.keys(value.orderBy).filter((f) => !AggregateOperators.includes(f)).some((key) => !bys.includes(key))) {
6264
6336
  return false;
6265
6337
  } else {
6266
6338
  return true;
@@ -6270,7 +6342,7 @@ var InputValidator = class {
6270
6342
  }
6271
6343
  onlyAggregationFields(val) {
6272
6344
  for (const [key, value] of Object.entries(val)) {
6273
- if (AGGREGATE_OPERATORS.includes(key)) {
6345
+ if (AggregateOperators.includes(key)) {
6274
6346
  continue;
6275
6347
  }
6276
6348
  if (LOGICAL_COMBINATORS.includes(key)) {
@@ -6355,6 +6427,111 @@ var InputValidator = class {
6355
6427
  get providerSupportsCaseSensitivity() {
6356
6428
  return this.schema.provider.type === "postgresql";
6357
6429
  }
6430
+ /**
6431
+ * Gets the effective set of allowed FilterKind values for a specific model and field.
6432
+ * Respects the precedence: field-level > model-level $all > global $all.
6433
+ */
6434
+ getEffectiveFilterKinds(model, field) {
6435
+ if (!model) {
6436
+ return void 0;
6437
+ }
6438
+ const slicing = this.options.slicing;
6439
+ if (!slicing?.models) {
6440
+ return void 0;
6441
+ }
6442
+ const modelConfig = slicing.models[model];
6443
+ if (modelConfig?.fields) {
6444
+ const fieldConfig = modelConfig.fields[field];
6445
+ if (fieldConfig) {
6446
+ return this.computeFilterKinds(fieldConfig.includedFilterKinds, fieldConfig.excludedFilterKinds);
6447
+ }
6448
+ const allFieldsConfig = modelConfig.fields.$all;
6449
+ if (allFieldsConfig) {
6450
+ return this.computeFilterKinds(allFieldsConfig.includedFilterKinds, allFieldsConfig.excludedFilterKinds);
6451
+ }
6452
+ }
6453
+ const allModelsConfig = slicing.models.$all;
6454
+ if (allModelsConfig?.fields) {
6455
+ if (allModelsConfig.fields.$all) {
6456
+ return this.computeFilterKinds(allModelsConfig.fields.$all.includedFilterKinds, allModelsConfig.fields.$all.excludedFilterKinds);
6457
+ }
6458
+ }
6459
+ return void 0;
6460
+ }
6461
+ /**
6462
+ * Computes the effective set of filter kinds based on inclusion and exclusion lists.
6463
+ */
6464
+ computeFilterKinds(included, excluded) {
6465
+ let result;
6466
+ if (included !== void 0) {
6467
+ result = new Set(included);
6468
+ }
6469
+ if (excluded !== void 0) {
6470
+ if (!result) {
6471
+ result = /* @__PURE__ */ new Set([
6472
+ "Equality",
6473
+ "Range",
6474
+ "Like",
6475
+ "Json",
6476
+ "List",
6477
+ "Relation"
6478
+ ]);
6479
+ }
6480
+ for (const kind of excluded) {
6481
+ result.delete(kind);
6482
+ }
6483
+ }
6484
+ return result;
6485
+ }
6486
+ /**
6487
+ * Filters operators based on allowed filter kinds.
6488
+ */
6489
+ trimFilterOperators(operators, allowedKinds) {
6490
+ if (!allowedKinds) {
6491
+ return operators;
6492
+ }
6493
+ return Object.fromEntries(Object.entries(operators).filter(([key, _]) => {
6494
+ return !(key in FILTER_PROPERTY_TO_KIND) || allowedKinds.has(FILTER_PROPERTY_TO_KIND[key]);
6495
+ }));
6496
+ }
6497
+ createUnionFilterSchema(valueSchema, optional, components, allowedFilterKinds) {
6498
+ if (Object.keys(components).length === 0) {
6499
+ if (!allowedFilterKinds || allowedFilterKinds.has("Equality")) {
6500
+ return this.nullableIf(valueSchema, optional);
6501
+ }
6502
+ return import_zod2.z.never();
6503
+ }
6504
+ if (!allowedFilterKinds || allowedFilterKinds.has("Equality")) {
6505
+ return import_zod2.z.union([
6506
+ this.nullableIf(valueSchema, optional),
6507
+ import_zod2.z.strictObject(components)
6508
+ ]);
6509
+ } else {
6510
+ return import_zod2.z.strictObject(components);
6511
+ }
6512
+ }
6513
+ /**
6514
+ * Checks if a model is included in the slicing configuration.
6515
+ * Returns true if the model is allowed, false if it's excluded.
6516
+ */
6517
+ isModelAllowed(targetModel) {
6518
+ const slicing = this.options.slicing;
6519
+ if (!slicing) {
6520
+ return true;
6521
+ }
6522
+ const { includedModels, excludedModels } = slicing;
6523
+ if (includedModels !== void 0) {
6524
+ if (!includedModels.includes(targetModel)) {
6525
+ return false;
6526
+ }
6527
+ }
6528
+ if (excludedModels !== void 0) {
6529
+ if (excludedModels.includes(targetModel)) {
6530
+ return false;
6531
+ }
6532
+ }
6533
+ return true;
6534
+ }
6358
6535
  };
6359
6536
  _ts_decorate([
6360
6537
  cache(),
@@ -6404,9 +6581,8 @@ _ts_decorate([
6404
6581
  cache(),
6405
6582
  _ts_metadata("design:type", Function),
6406
6583
  _ts_metadata("design:paramtypes", [
6407
- String,
6408
- Boolean,
6409
- Boolean
6584
+ Object,
6585
+ typeof FieldInfo === "undefined" ? Object : FieldInfo
6410
6586
  ]),
6411
6587
  _ts_metadata("design:returntype", void 0)
6412
6588
  ], InputValidator.prototype, "makeTypedJsonFilterSchema", null);
@@ -6414,8 +6590,8 @@ _ts_decorate([
6414
6590
  cache(),
6415
6591
  _ts_metadata("design:type", Function),
6416
6592
  _ts_metadata("design:paramtypes", [
6417
- String,
6418
- Boolean,
6593
+ Object,
6594
+ typeof FieldInfo === "undefined" ? Object : FieldInfo,
6419
6595
  Boolean,
6420
6596
  Boolean
6421
6597
  ]),
@@ -6425,7 +6601,8 @@ _ts_decorate([
6425
6601
  cache(),
6426
6602
  _ts_metadata("design:type", Function),
6427
6603
  _ts_metadata("design:paramtypes", [
6428
- typeof BuiltinType === "undefined" ? Object : BuiltinType
6604
+ Object,
6605
+ typeof FieldInfo === "undefined" ? Object : FieldInfo
6429
6606
  ]),
6430
6607
  _ts_metadata("design:returntype", void 0)
6431
6608
  ], InputValidator.prototype, "makeArrayFilterSchema", null);
@@ -6433,9 +6610,10 @@ _ts_decorate([
6433
6610
  cache(),
6434
6611
  _ts_metadata("design:type", Function),
6435
6612
  _ts_metadata("design:paramtypes", [
6436
- typeof BuiltinType === "undefined" ? Object : BuiltinType,
6613
+ Object,
6614
+ typeof FieldInfo === "undefined" ? Object : FieldInfo,
6437
6615
  Boolean,
6438
- Boolean
6616
+ void 0
6439
6617
  ]),
6440
6618
  _ts_metadata("design:returntype", void 0)
6441
6619
  ], InputValidator.prototype, "makePrimitiveFilterSchema", null);
@@ -6443,6 +6621,8 @@ _ts_decorate([
6443
6621
  cache(),
6444
6622
  _ts_metadata("design:type", Function),
6445
6623
  _ts_metadata("design:paramtypes", [
6624
+ Object,
6625
+ String,
6446
6626
  Boolean
6447
6627
  ]),
6448
6628
  _ts_metadata("design:returntype", void 0)
@@ -6452,7 +6632,8 @@ _ts_decorate([
6452
6632
  _ts_metadata("design:type", Function),
6453
6633
  _ts_metadata("design:paramtypes", [
6454
6634
  Boolean,
6455
- Boolean
6635
+ Boolean,
6636
+ Object
6456
6637
  ]),
6457
6638
  _ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
6458
6639
  ], InputValidator.prototype, "makeDateTimeFilterSchema", null);
@@ -6461,7 +6642,8 @@ _ts_decorate([
6461
6642
  _ts_metadata("design:type", Function),
6462
6643
  _ts_metadata("design:paramtypes", [
6463
6644
  Boolean,
6464
- Boolean
6645
+ Boolean,
6646
+ Object
6465
6647
  ]),
6466
6648
  _ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
6467
6649
  ], InputValidator.prototype, "makeBooleanFilterSchema", null);
@@ -6470,7 +6652,8 @@ _ts_decorate([
6470
6652
  _ts_metadata("design:type", Function),
6471
6653
  _ts_metadata("design:paramtypes", [
6472
6654
  Boolean,
6473
- Boolean
6655
+ Boolean,
6656
+ Object
6474
6657
  ]),
6475
6658
  _ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
6476
6659
  ], InputValidator.prototype, "makeBytesFilterSchema", null);
@@ -8625,6 +8808,9 @@ var ClientImpl = class _ClientImpl {
8625
8808
  ...functions_exports,
8626
8809
  ...this.$options.functions
8627
8810
  };
8811
+ if (!baseClient) {
8812
+ this.validateComputedFieldsConfig();
8813
+ }
8628
8814
  if (baseClient) {
8629
8815
  this.kyselyProps = {
8630
8816
  ...baseClient.kyselyProps,
@@ -8670,6 +8856,26 @@ var ClientImpl = class _ClientImpl {
8670
8856
  withExecutor(executor) {
8671
8857
  return new _ClientImpl(this.schema, this.$options, this, executor);
8672
8858
  }
8859
+ /**
8860
+ * Validates that all computed fields in the schema have corresponding configurations.
8861
+ */
8862
+ validateComputedFieldsConfig() {
8863
+ const computedFieldsConfig = "computedFields" in this.$options ? this.$options.computedFields : void 0;
8864
+ for (const [modelName, modelDef] of Object.entries(this.$schema.models)) {
8865
+ if (modelDef.computedFields) {
8866
+ for (const fieldName of Object.keys(modelDef.computedFields)) {
8867
+ const modelConfig = computedFieldsConfig?.[modelName];
8868
+ const fieldConfig = modelConfig?.[fieldName];
8869
+ if (fieldConfig === null || fieldConfig === void 0) {
8870
+ throw createConfigError(`Computed field "${fieldName}" in model "${modelName}" does not have a configuration. Please provide an implementation in the computedFields option.`);
8871
+ }
8872
+ if (typeof fieldConfig !== "function") {
8873
+ throw createConfigError(`Computed field "${fieldName}" in model "${modelName}" has an invalid configuration: expected a function but received ${typeof fieldConfig}.`);
8874
+ }
8875
+ }
8876
+ }
8877
+ }
8878
+ }
8673
8879
  // implementation
8674
8880
  async $transaction(input, options) {
8675
8881
  (0, import_common_helpers14.invariant)(typeof input === "function" || Array.isArray(input) && input.every((p) => p.then && p.cb), "Invalid transaction input, expected a function or an array of ZenStackPromise");
@@ -8721,6 +8927,9 @@ var ClientImpl = class _ClientImpl {
8721
8927
  }
8722
8928
  get $procs() {
8723
8929
  return Object.keys(this.$schema.procedures ?? {}).reduce((acc, name) => {
8930
+ if (!isProcedureIncluded(this.$options, name)) {
8931
+ return acc;
8932
+ }
8724
8933
  acc[name] = (input) => this.handleProc(name, input);
8725
8934
  return acc;
8726
8935
  }, {});
@@ -8890,6 +9099,9 @@ function createClientProxy(client) {
8890
9099
  if (typeof prop === "string") {
8891
9100
  const model = Object.keys(client.$schema.models).find((m) => m.toLowerCase() === prop.toLowerCase());
8892
9101
  if (model) {
9102
+ if (!isModelIncluded(client.$options, model)) {
9103
+ return void 0;
9104
+ }
8893
9105
  return createModelCrudHandler(client, model, client.inputValidator, resultProcessor);
8894
9106
  }
8895
9107
  }
@@ -8898,6 +9110,44 @@ function createClientProxy(client) {
8898
9110
  });
8899
9111
  }
8900
9112
  __name(createClientProxy, "createClientProxy");
9113
+ function isModelIncluded(options, model) {
9114
+ const slicing = options.slicing;
9115
+ if (!slicing) {
9116
+ return true;
9117
+ }
9118
+ const { includedModels, excludedModels } = slicing;
9119
+ if (includedModels !== void 0) {
9120
+ if (!includedModels.includes(model)) {
9121
+ return false;
9122
+ }
9123
+ }
9124
+ if (excludedModels && excludedModels.length > 0) {
9125
+ if (excludedModels.includes(model)) {
9126
+ return false;
9127
+ }
9128
+ }
9129
+ return true;
9130
+ }
9131
+ __name(isModelIncluded, "isModelIncluded");
9132
+ function isProcedureIncluded(options, procedureName) {
9133
+ const slicing = options.slicing;
9134
+ if (!slicing) {
9135
+ return true;
9136
+ }
9137
+ const { includedProcedures, excludedProcedures } = slicing;
9138
+ if (includedProcedures !== void 0) {
9139
+ if (!includedProcedures.includes(procedureName)) {
9140
+ return false;
9141
+ }
9142
+ }
9143
+ if (excludedProcedures && excludedProcedures.length > 0) {
9144
+ if (excludedProcedures.includes(procedureName)) {
9145
+ return false;
9146
+ }
9147
+ }
9148
+ return true;
9149
+ }
9150
+ __name(isProcedureIncluded, "isProcedureIncluded");
8901
9151
  function createModelCrudHandler(client, model, inputValidator, resultProcessor) {
8902
9152
  const createPromise = /* @__PURE__ */ __name((operation, nominalOperation, args, handler, postProcess = false, throwIfNoResult = false) => {
8903
9153
  return createZenStackPromise(async (txClient) => {
@@ -8939,7 +9189,7 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
8939
9189
  return proceed(args);
8940
9190
  });
8941
9191
  }, "createPromise");
8942
- return {
9192
+ const operations = {
8943
9193
  findUnique: /* @__PURE__ */ __name((args) => {
8944
9194
  return createPromise("findUnique", "findUnique", args, new FindOperationHandler(client, model, inputValidator), true);
8945
9195
  }, "findUnique"),
@@ -9001,6 +9251,26 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
9001
9251
  return createPromise("exists", "exists", args, new ExistsOperationHandler(client, model, inputValidator), false);
9002
9252
  }, "exists")
9003
9253
  };
9254
+ const slicing = client.$options.slicing;
9255
+ if (slicing?.models) {
9256
+ const modelSlicing = slicing.models[model];
9257
+ const allSlicing = slicing.models.$all;
9258
+ const includedOperations = modelSlicing?.includedOperations ?? allSlicing?.includedOperations;
9259
+ const excludedOperations = modelSlicing?.excludedOperations ?? allSlicing?.excludedOperations;
9260
+ if (includedOperations !== void 0) {
9261
+ for (const key of Object.keys(operations)) {
9262
+ if (!includedOperations.includes(key)) {
9263
+ delete operations[key];
9264
+ }
9265
+ }
9266
+ }
9267
+ if (excludedOperations && excludedOperations.length > 0) {
9268
+ for (const operation of excludedOperations) {
9269
+ delete operations[operation];
9270
+ }
9271
+ }
9272
+ }
9273
+ return operations;
9004
9274
  }
9005
9275
  __name(createModelCrudHandler, "createModelCrudHandler");
9006
9276