@zenstackhq/runtime 3.0.0-alpha.4 → 3.0.0-alpha.7

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
@@ -36,6 +36,7 @@ __export(src_exports, {
36
36
  module.exports = __toCommonJS(src_exports);
37
37
 
38
38
  // src/client/client-impl.ts
39
+ var import_common_helpers12 = require("@zenstackhq/common-helpers");
39
40
  var import_kysely16 = require("kysely");
40
41
  var import_ts_pattern19 = require("ts-pattern");
41
42
 
@@ -310,9 +311,9 @@ __name(safeJSONStringify, "safeJSONStringify");
310
311
 
311
312
  // src/client/crud/operations/base.ts
312
313
  var import_cuid2 = require("@paralleldrive/cuid2");
314
+ var import_common_helpers8 = require("@zenstackhq/common-helpers");
313
315
  var import_kysely8 = require("kysely");
314
316
  var import_nanoid = require("nanoid");
315
- var import_tiny_invariant7 = __toESM(require("tiny-invariant"), 1);
316
317
  var import_ts_pattern8 = require("ts-pattern");
317
318
  var import_ulid = require("ulid");
318
319
  var uuid = __toESM(require("uuid"), 1);
@@ -330,21 +331,21 @@ var RejectedByPolicyError = class extends Error {
330
331
  };
331
332
 
332
333
  // src/plugins/policy/policy-handler.ts
334
+ var import_common_helpers6 = require("@zenstackhq/common-helpers");
333
335
  var import_kysely7 = require("kysely");
334
- var import_tiny_invariant6 = __toESM(require("tiny-invariant"), 1);
335
336
  var import_ts_pattern7 = require("ts-pattern");
336
337
 
337
338
  // src/client/crud/dialects/index.ts
338
339
  var import_ts_pattern4 = require("ts-pattern");
339
340
 
340
341
  // src/client/crud/dialects/postgresql.ts
342
+ var import_common_helpers2 = require("@zenstackhq/common-helpers");
341
343
  var import_kysely2 = require("kysely");
342
- var import_tiny_invariant2 = __toESM(require("tiny-invariant"), 1);
343
344
  var import_ts_pattern2 = require("ts-pattern");
344
345
 
345
346
  // src/client/crud/dialects/base.ts
347
+ var import_common_helpers = require("@zenstackhq/common-helpers");
346
348
  var import_kysely = require("kysely");
347
- var import_tiny_invariant = __toESM(require("tiny-invariant"), 1);
348
349
  var import_ts_pattern = require("ts-pattern");
349
350
 
350
351
  // src/utils/enumerate.ts
@@ -362,7 +363,6 @@ function enumerate(x) {
362
363
  __name(enumerate, "enumerate");
363
364
 
364
365
  // src/client/crud/dialects/base.ts
365
- var import_is_plain_object = require("is-plain-object");
366
366
  var BaseCrudDialect = class {
367
367
  static {
368
368
  __name(this, "BaseCrudDialect");
@@ -560,7 +560,7 @@ var BaseCrudDialect = class {
560
560
  return eb(lhs, "=", rhs !== null && rhs !== void 0 ? this.transformPrimitive(rhs, type) : rhs);
561
561
  }
562
562
  buildStandardFilter(eb, type, payload, lhs, getRhs, recurse, throwIfInvalid = false, onlyForKeys = void 0) {
563
- if (payload === null || !(0, import_is_plain_object.isPlainObject)(payload)) {
563
+ if (payload === null || !(0, import_common_helpers.isPlainObject)(payload)) {
564
564
  return {
565
565
  conditions: [
566
566
  this.buildLiteralFilter(eb, lhs, type, payload)
@@ -576,14 +576,14 @@ var BaseCrudDialect = class {
576
576
  }
577
577
  const rhs = Array.isArray(value) ? value.map(getRhs) : getRhs(value);
578
578
  const condition = (0, import_ts_pattern.match)(op).with("equals", () => rhs === null ? eb(lhs, "is", null) : eb(lhs, "=", rhs)).with("in", () => {
579
- (0, import_tiny_invariant.default)(Array.isArray(rhs), "right hand side must be an array");
579
+ (0, import_common_helpers.invariant)(Array.isArray(rhs), "right hand side must be an array");
580
580
  if (rhs.length === 0) {
581
581
  return this.false(eb);
582
582
  } else {
583
583
  return eb(lhs, "in", rhs);
584
584
  }
585
585
  }).with("notIn", () => {
586
- (0, import_tiny_invariant.default)(Array.isArray(rhs), "right hand side must be an array");
586
+ (0, import_common_helpers.invariant)(Array.isArray(rhs), "right hand side must be an array");
587
587
  if (rhs.length === 0) {
588
588
  return this.true(eb);
589
589
  } else {
@@ -697,9 +697,9 @@ var BaseCrudDialect = class {
697
697
  "_min",
698
698
  "_max"
699
699
  ].includes(field)) {
700
- (0, import_tiny_invariant.default)(value && typeof value === "object", `invalid orderBy value for field "${field}"`);
700
+ (0, import_common_helpers.invariant)(value && typeof value === "object", `invalid orderBy value for field "${field}"`);
701
701
  for (const [k, v] of Object.entries(value)) {
702
- (0, import_tiny_invariant.default)(v === "asc" || v === "desc", `invalid orderBy value for field "${field}"`);
702
+ (0, import_common_helpers.invariant)(v === "asc" || v === "desc", `invalid orderBy value for field "${field}"`);
703
703
  result = result.orderBy((eb) => eb.fn(field.slice(1), [
704
704
  import_kysely.sql.ref(k)
705
705
  ]), import_kysely.sql.raw(this.negateSort(v, negated)));
@@ -708,9 +708,9 @@ var BaseCrudDialect = class {
708
708
  }
709
709
  switch (field) {
710
710
  case "_count": {
711
- (0, import_tiny_invariant.default)(value && typeof value === "object", 'invalid orderBy value for field "_count"');
711
+ (0, import_common_helpers.invariant)(value && typeof value === "object", 'invalid orderBy value for field "_count"');
712
712
  for (const [k, v] of Object.entries(value)) {
713
- (0, import_tiny_invariant.default)(v === "asc" || v === "desc", `invalid orderBy value for field "${field}"`);
713
+ (0, import_common_helpers.invariant)(v === "asc" || v === "desc", `invalid orderBy value for field "${field}"`);
714
714
  result = result.orderBy((eb) => eb.fn.count(import_kysely.sql.ref(k)), import_kysely.sql.raw(this.negateSort(v, negated)));
715
715
  }
716
716
  continue;
@@ -732,7 +732,7 @@ var BaseCrudDialect = class {
732
732
  throw new QueryError(`invalid orderBy value for field "${field}"`);
733
733
  }
734
734
  if ("_count" in value) {
735
- (0, import_tiny_invariant.default)(value._count === "asc" || value._count === "desc", 'invalid orderBy value for field "_count"');
735
+ (0, import_common_helpers.invariant)(value._count === "asc" || value._count === "desc", 'invalid orderBy value for field "_count"');
736
736
  const sort = this.negateSort(value._count, negated);
737
737
  result = result.orderBy((eb) => {
738
738
  let subQuery = eb.selectFrom(relationModel);
@@ -850,8 +850,8 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
850
850
  if (m2m) {
851
851
  const parentIds = getIdFields(this.schema, model);
852
852
  const relationIds = getIdFields(this.schema, relationModel);
853
- (0, import_tiny_invariant2.default)(parentIds.length === 1, "many-to-many relation must have exactly one id field");
854
- (0, import_tiny_invariant2.default)(relationIds.length === 1, "many-to-many relation must have exactly one id field");
853
+ (0, import_common_helpers2.invariant)(parentIds.length === 1, "many-to-many relation must have exactly one id field");
854
+ (0, import_common_helpers2.invariant)(relationIds.length === 1, "many-to-many relation must have exactly one id field");
855
855
  subQuery = subQuery.where(eb(eb.ref(`${relationModel}.${relationIds[0]}`), "in", eb.selectFrom(m2m.joinTable).select(`${m2m.joinTable}.${m2m.otherFkName}`).whereRef(`${parentName}.${parentIds[0]}`, "=", `${m2m.joinTable}.${m2m.parentFkName}`)));
856
856
  } else {
857
857
  const joinPairs = buildJoinPairs(this.schema, model, parentName, relationField, relationModel);
@@ -945,8 +945,8 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
945
945
  };
946
946
 
947
947
  // src/client/crud/dialects/sqlite.ts
948
+ var import_common_helpers3 = require("@zenstackhq/common-helpers");
948
949
  var import_kysely3 = require("kysely");
949
- var import_tiny_invariant3 = __toESM(require("tiny-invariant"), 1);
950
950
  var import_ts_pattern3 = require("ts-pattern");
951
951
  var SqliteCrudDialect = class extends BaseCrudDialect {
952
952
  static {
@@ -993,8 +993,8 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
993
993
  if (m2m) {
994
994
  const parentIds = getIdFields(this.schema, model);
995
995
  const relationIds = getIdFields(this.schema, relationModel);
996
- (0, import_tiny_invariant3.default)(parentIds.length === 1, "many-to-many relation must have exactly one id field");
997
- (0, import_tiny_invariant3.default)(relationIds.length === 1, "many-to-many relation must have exactly one id field");
996
+ (0, import_common_helpers3.invariant)(parentIds.length === 1, "many-to-many relation must have exactly one id field");
997
+ (0, import_common_helpers3.invariant)(relationIds.length === 1, "many-to-many relation must have exactly one id field");
998
998
  subQuery = subQuery.where(eb(eb.ref(`${relationModel}.${relationIds[0]}`), "in", eb.selectFrom(m2m.joinTable).select(`${m2m.joinTable}.${m2m.otherFkName}`).whereRef(`${parentName}.${parentIds[0]}`, "=", `${m2m.joinTable}.${m2m.parentFkName}`)));
999
999
  } else {
1000
1000
  const { keyPairs, ownedByModel } = getRelationForeignKeyFieldPairs(this.schema, model, relationField);
@@ -1490,12 +1490,12 @@ var ColumnCollector = class extends DefaultOperationNodeVisitor {
1490
1490
  };
1491
1491
 
1492
1492
  // src/plugins/policy/expression-transformer.ts
1493
+ var import_common_helpers5 = require("@zenstackhq/common-helpers");
1493
1494
  var import_kysely6 = require("kysely");
1494
- var import_tiny_invariant5 = __toESM(require("tiny-invariant"), 1);
1495
1495
  var import_ts_pattern6 = require("ts-pattern");
1496
1496
 
1497
1497
  // src/plugins/policy/expression-evaluator.ts
1498
- var import_tiny_invariant4 = __toESM(require("tiny-invariant"), 1);
1498
+ var import_common_helpers4 = require("@zenstackhq/common-helpers");
1499
1499
  var import_ts_pattern5 = require("ts-pattern");
1500
1500
  var ExpressionEvaluator = class {
1501
1501
  static {
@@ -1539,18 +1539,18 @@ var ExpressionEvaluator = class {
1539
1539
  const right = this.evaluate(expr2.right, context);
1540
1540
  return (0, import_ts_pattern5.match)(expr2.op).with("==", () => left === right).with("!=", () => left !== right).with(">", () => left > right).with(">=", () => left >= right).with("<", () => left < right).with("<=", () => left <= right).with("&&", () => left && right).with("||", () => left || right).with("in", () => {
1541
1541
  const _right = right ?? [];
1542
- (0, import_tiny_invariant4.default)(Array.isArray(_right), 'expected array for "in" operator');
1542
+ (0, import_common_helpers4.invariant)(Array.isArray(_right), 'expected array for "in" operator');
1543
1543
  return _right.includes(left);
1544
1544
  }).exhaustive();
1545
1545
  }
1546
1546
  evaluateCollectionPredicate(expr2, context) {
1547
1547
  const op = expr2.op;
1548
- (0, import_tiny_invariant4.default)(op === "?" || op === "!" || op === "^", 'expected "?" or "!" or "^" operator');
1548
+ (0, import_common_helpers4.invariant)(op === "?" || op === "!" || op === "^", 'expected "?" or "!" or "^" operator');
1549
1549
  const left = this.evaluate(expr2.left, context);
1550
1550
  if (!left) {
1551
1551
  return false;
1552
1552
  }
1553
- (0, import_tiny_invariant4.default)(Array.isArray(left), "expected array");
1553
+ (0, import_common_helpers4.invariant)(Array.isArray(left), "expected array");
1554
1554
  return (0, import_ts_pattern5.match)(op).with("?", () => left.some((item) => this.evaluate(expr2.right, {
1555
1555
  ...context,
1556
1556
  thisValue: item
@@ -1772,20 +1772,20 @@ var ExpressionTransformer = class {
1772
1772
  return import_kysely6.BinaryOperationNode.create(left, this.transformOperator(op), right);
1773
1773
  }
1774
1774
  transformCollectionPredicate(expr2, context) {
1775
- (0, import_tiny_invariant5.default)(expr2.op === "?" || expr2.op === "!" || expr2.op === "^", 'expected "?" or "!" or "^" operator');
1775
+ (0, import_common_helpers5.invariant)(expr2.op === "?" || expr2.op === "!" || expr2.op === "^", 'expected "?" or "!" or "^" operator');
1776
1776
  if (this.isAuthCall(expr2.left) || this.isAuthMember(expr2.left)) {
1777
1777
  const value = new ExpressionEvaluator().evaluate(expr2, {
1778
1778
  auth: this.auth
1779
1779
  });
1780
1780
  return this.transformValue(value, "Boolean");
1781
1781
  }
1782
- (0, import_tiny_invariant5.default)(ExpressionUtils.isField(expr2.left) || ExpressionUtils.isMember(expr2.left), "left operand must be field or member access");
1782
+ (0, import_common_helpers5.invariant)(ExpressionUtils.isField(expr2.left) || ExpressionUtils.isMember(expr2.left), "left operand must be field or member access");
1783
1783
  let newContextModel;
1784
1784
  if (ExpressionUtils.isField(expr2.left)) {
1785
1785
  const fieldDef = requireField(this.schema, context.model, expr2.left.field);
1786
1786
  newContextModel = fieldDef.type;
1787
1787
  } else {
1788
- (0, import_tiny_invariant5.default)(ExpressionUtils.isField(expr2.left.receiver));
1788
+ (0, import_common_helpers5.invariant)(ExpressionUtils.isField(expr2.left.receiver));
1789
1789
  const fieldDef = requireField(this.schema, context.model, expr2.left.receiver.field);
1790
1790
  newContextModel = fieldDef.type;
1791
1791
  for (const member of expr2.left.members) {
@@ -1832,7 +1832,7 @@ var ExpressionTransformer = class {
1832
1832
  return import_kysely6.ValueNode.create(this.dialect.transformPrimitive(value, type) ?? null);
1833
1833
  }
1834
1834
  _unary(expr2, context) {
1835
- (0, import_tiny_invariant5.default)(expr2.op === "!", 'only "!" operator is supported');
1835
+ (0, import_common_helpers5.invariant)(expr2.op === "!", 'only "!" operator is supported');
1836
1836
  return import_kysely6.BinaryOperationNode.create(this.transform(expr2.operand, context), this.transformOperator("!="), trueNode(this.dialect));
1837
1837
  }
1838
1838
  transformOperator(op) {
@@ -1875,10 +1875,10 @@ var ExpressionTransformer = class {
1875
1875
  if (this.isAuthCall(expr2.receiver)) {
1876
1876
  return this.valueMemberAccess(this.auth, expr2, this.authType);
1877
1877
  }
1878
- (0, import_tiny_invariant5.default)(ExpressionUtils.isField(expr2.receiver), "expect receiver to be field expression");
1878
+ (0, import_common_helpers5.invariant)(ExpressionUtils.isField(expr2.receiver), "expect receiver to be field expression");
1879
1879
  const { memberFilter, memberSelect, ...restContext } = context;
1880
1880
  const receiver = this.transform(expr2.receiver, restContext);
1881
- (0, import_tiny_invariant5.default)(import_kysely6.SelectQueryNode.is(receiver), "expected receiver to be select query");
1881
+ (0, import_common_helpers5.invariant)(import_kysely6.SelectQueryNode.is(receiver), "expected receiver to be select query");
1882
1882
  const receiverField = requireField(this.schema, context.model, expr2.receiver.field);
1883
1883
  const memberFields = [];
1884
1884
  let currType = receiverField.type;
@@ -1902,7 +1902,7 @@ var ExpressionTransformer = class {
1902
1902
  thisEntity: void 0
1903
1903
  });
1904
1904
  if (currNode) {
1905
- (0, import_tiny_invariant5.default)(import_kysely6.SelectQueryNode.is(currNode), "expected select query node");
1905
+ (0, import_common_helpers5.invariant)(import_kysely6.SelectQueryNode.is(currNode), "expected select query node");
1906
1906
  currNode = {
1907
1907
  ...relation,
1908
1908
  selections: [
@@ -1919,8 +1919,8 @@ var ExpressionTransformer = class {
1919
1919
  };
1920
1920
  }
1921
1921
  } else {
1922
- (0, import_tiny_invariant5.default)(i === expr2.members.length - 1, "plain field access must be the last segment");
1923
- (0, import_tiny_invariant5.default)(!currNode, "plain field access must be the last segment");
1922
+ (0, import_common_helpers5.invariant)(i === expr2.members.length - 1, "plain field access must be the last segment");
1923
+ (0, import_common_helpers5.invariant)(!currNode, "plain field access must be the last segment");
1924
1924
  currNode = import_kysely6.ColumnNode.create(member);
1925
1925
  }
1926
1926
  }
@@ -2165,13 +2165,13 @@ var PolicyHandler = class extends import_kysely7.OperationNodeTransformer {
2165
2165
  }
2166
2166
  }
2167
2167
  unwrapCreateValueRow(data, model, fields) {
2168
- (0, import_tiny_invariant6.default)(data.length === fields.length, "data length must match fields length");
2168
+ (0, import_common_helpers6.invariant)(data.length === fields.length, "data length must match fields length");
2169
2169
  const result = [];
2170
2170
  for (let i = 0; i < data.length; i++) {
2171
2171
  const item = data[i];
2172
2172
  const fieldDef = requireField(this.client.$schema, model, fields[i]);
2173
2173
  if (typeof item === "object" && item && "kind" in item) {
2174
- (0, import_tiny_invariant6.default)(item.kind === "ValueNode", "expecting a ValueNode");
2174
+ (0, import_common_helpers6.invariant)(item.kind === "ValueNode", "expecting a ValueNode");
2175
2175
  result.push({
2176
2176
  node: import_kysely7.ValueNode.create(this.dialect.transformPrimitive(item.value, fieldDef.type)),
2177
2177
  raw: item.value
@@ -2379,8 +2379,8 @@ var PolicyHandler = class extends import_kysely7.OperationNodeTransformer {
2379
2379
  const modelDef = requireModel(this.client.$schema, modelName);
2380
2380
  const result = [];
2381
2381
  const extractOperations = /* @__PURE__ */ __name((expr2) => {
2382
- (0, import_tiny_invariant6.default)(ExpressionUtils.isLiteral(expr2), "expecting a literal");
2383
- (0, import_tiny_invariant6.default)(typeof expr2.value === "string", "expecting a string literal");
2382
+ (0, import_common_helpers6.invariant)(ExpressionUtils.isLiteral(expr2), "expecting a literal");
2383
+ (0, import_common_helpers6.invariant)(typeof expr2.value === "string", "expecting a string literal");
2384
2384
  return expr2.value.split(",").filter((v) => !!v).map((v) => v.trim());
2385
2385
  }, "extractOperations");
2386
2386
  if (modelDef.attributes) {
@@ -2415,13 +2415,13 @@ var PolicyPlugin = class {
2415
2415
  };
2416
2416
 
2417
2417
  // src/utils/clone.ts
2418
- var import_is_plain_object2 = require("is-plain-object");
2418
+ var import_common_helpers7 = require("@zenstackhq/common-helpers");
2419
2419
  function clone(value) {
2420
2420
  if (Array.isArray(value)) {
2421
2421
  return value.map((v) => clone(v));
2422
2422
  }
2423
2423
  if (typeof value === "object") {
2424
- if (!value || !(0, import_is_plain_object2.isPlainObject)(value)) {
2424
+ if (!value || !(0, import_common_helpers7.isPlainObject)(value)) {
2425
2425
  return value;
2426
2426
  }
2427
2427
  const result = {};
@@ -2741,8 +2741,8 @@ var BaseOperationHandler = class {
2741
2741
  }
2742
2742
  buildFkAssignments(model, relationField, entity) {
2743
2743
  const parentFkFields = {};
2744
- (0, import_tiny_invariant7.default)(relationField, "parentField must be defined if parentModel is defined");
2745
- (0, import_tiny_invariant7.default)(entity, "parentEntity must be defined if parentModel is defined");
2744
+ (0, import_common_helpers8.invariant)(relationField, "parentField must be defined if parentModel is defined");
2745
+ (0, import_common_helpers8.invariant)(entity, "parentEntity must be defined if parentModel is defined");
2746
2746
  const { keyPairs } = getRelationForeignKeyFieldPairs(this.schema, model, relationField);
2747
2747
  for (const pair of keyPairs) {
2748
2748
  if (!(pair.pk in entity)) {
@@ -2769,8 +2769,8 @@ var BaseOperationHandler = class {
2769
2769
  ].sort((a, b) => a.model.localeCompare(b.model));
2770
2770
  const firstIds = getIdFields(this.schema, sortedRecords[0].model);
2771
2771
  const secondIds = getIdFields(this.schema, sortedRecords[1].model);
2772
- (0, import_tiny_invariant7.default)(firstIds.length === 1, "many-to-many relation must have exactly one id field");
2773
- (0, import_tiny_invariant7.default)(secondIds.length === 1, "many-to-many relation must have exactly one id field");
2772
+ (0, import_common_helpers8.invariant)(firstIds.length === 1, "many-to-many relation must have exactly one id field");
2773
+ (0, import_common_helpers8.invariant)(secondIds.length === 1, "many-to-many relation must have exactly one id field");
2774
2774
  if (action === "connect") {
2775
2775
  const result = await kysely.insertInto(joinTable).values({
2776
2776
  A: sortedRecords[0].entity[firstIds[0]],
@@ -2787,10 +2787,10 @@ var BaseOperationHandler = class {
2787
2787
  }
2788
2788
  }
2789
2789
  resetManyToManyRelation(kysely, model, field, parentIds) {
2790
- (0, import_tiny_invariant7.default)(Object.keys(parentIds).length === 1, "parentIds must have exactly one field");
2790
+ (0, import_common_helpers8.invariant)(Object.keys(parentIds).length === 1, "parentIds must have exactly one field");
2791
2791
  const parentId = Object.values(parentIds)[0];
2792
2792
  const m2m = getManyToManyRelation(this.schema, model, field);
2793
- (0, import_tiny_invariant7.default)(m2m, "not a many-to-many relation");
2793
+ (0, import_common_helpers8.invariant)(m2m, "not a many-to-many relation");
2794
2794
  const eb = (0, import_kysely8.expressionBuilder)();
2795
2795
  return kysely.deleteFrom(m2m.joinTable).where(eb(`${m2m.joinTable}.${m2m.parentFkName}`, "=", parentId)).execute();
2796
2796
  }
@@ -2812,7 +2812,7 @@ var BaseOperationHandler = class {
2812
2812
  }
2813
2813
  case "connect": {
2814
2814
  const referencedPkFields = relationField.relation.references;
2815
- (0, import_tiny_invariant7.default)(referencedPkFields, "relation must have fields info");
2815
+ (0, import_common_helpers8.invariant)(referencedPkFields, "relation must have fields info");
2816
2816
  const extractedFks = extractFields(subPayload, referencedPkFields);
2817
2817
  if (Object.keys(extractedFks).length === referencedPkFields.length) {
2818
2818
  result = extractedFks;
@@ -2901,7 +2901,7 @@ var BaseOperationHandler = class {
2901
2901
  const newItem = {};
2902
2902
  for (const [name, value] of Object.entries(item)) {
2903
2903
  const fieldDef = this.requireField(model, name);
2904
- (0, import_tiny_invariant7.default)(!fieldDef.relation, "createMany does not support relations");
2904
+ (0, import_common_helpers8.invariant)(!fieldDef.relation, "createMany does not support relations");
2905
2905
  newItem[name] = this.dialect.transformPrimitive(value, fieldDef.type);
2906
2906
  }
2907
2907
  if (fromRelation) {
@@ -2980,7 +2980,7 @@ var BaseOperationHandler = class {
2980
2980
  }
2981
2981
  } else {
2982
2982
  const fromRelationFieldDef = this.requireField(fromRelation.model, fromRelation.field);
2983
- (0, import_tiny_invariant7.default)(fromRelationFieldDef.relation?.opposite);
2983
+ (0, import_common_helpers8.invariant)(fromRelationFieldDef.relation?.opposite);
2984
2984
  parentWhere[fromRelationFieldDef.relation.opposite] = {
2985
2985
  some: fromRelation.ids
2986
2986
  };
@@ -3070,7 +3070,7 @@ var BaseOperationHandler = class {
3070
3070
  }
3071
3071
  }
3072
3072
  transformIncrementalUpdate(model, field, fieldDef, payload) {
3073
- (0, import_tiny_invariant7.default)(Object.keys(payload).length === 1, 'Only one of "set", "increment", "decrement", "multiply", or "divide" can be provided');
3073
+ (0, import_common_helpers8.invariant)(Object.keys(payload).length === 1, 'Only one of "set", "increment", "decrement", "multiply", or "divide" can be provided');
3074
3074
  const key = Object.keys(payload)[0];
3075
3075
  const value = this.dialect.transformPrimitive(payload[key], fieldDef.type);
3076
3076
  const eb = (0, import_kysely8.expressionBuilder)();
@@ -3080,7 +3080,7 @@ var BaseOperationHandler = class {
3080
3080
  });
3081
3081
  }
3082
3082
  transformScalarListUpdate(model, field, fieldDef, payload) {
3083
- (0, import_tiny_invariant7.default)(Object.keys(payload).length === 1, 'Only one of "set", "push" can be provided');
3083
+ (0, import_common_helpers8.invariant)(Object.keys(payload).length === 1, 'Only one of "set", "push" can be provided');
3084
3084
  const key = Object.keys(payload)[0];
3085
3085
  const value = this.dialect.transformPrimitive(payload[key], fieldDef.type);
3086
3086
  const eb = (0, import_kysely8.expressionBuilder)();
@@ -3161,12 +3161,12 @@ var BaseOperationHandler = class {
3161
3161
  for (const [key, value] of Object.entries(args)) {
3162
3162
  switch (key) {
3163
3163
  case "create": {
3164
- (0, import_tiny_invariant7.default)(!Array.isArray(value) || fieldDef.array, "relation must be an array if create is an array");
3164
+ (0, import_common_helpers8.invariant)(!Array.isArray(value) || fieldDef.array, "relation must be an array if create is an array");
3165
3165
  tasks.push(...enumerate(value).map((item) => this.create(kysely, fieldModel, item, fromRelationContext)));
3166
3166
  break;
3167
3167
  }
3168
3168
  case "createMany": {
3169
- (0, import_tiny_invariant7.default)(fieldDef.array, "relation must be an array for createMany");
3169
+ (0, import_common_helpers8.invariant)(fieldDef.array, "relation must be an array for createMany");
3170
3170
  tasks.push(this.createMany(kysely, fieldModel, value, false, fromRelationContext));
3171
3171
  break;
3172
3172
  }
@@ -3183,7 +3183,7 @@ var BaseOperationHandler = class {
3183
3183
  break;
3184
3184
  }
3185
3185
  case "set": {
3186
- (0, import_tiny_invariant7.default)(fieldDef.array, "relation must be an array");
3186
+ (0, import_common_helpers8.invariant)(fieldDef.array, "relation must be an array");
3187
3187
  tasks.push(this.setRelation(kysely, fieldModel, value, fromRelationContext));
3188
3188
  break;
3189
3189
  }
@@ -3252,7 +3252,7 @@ var BaseOperationHandler = class {
3252
3252
  const { ownedByModel, keyPairs } = getRelationForeignKeyFieldPairs(this.schema, fromRelation.model, fromRelation.field);
3253
3253
  let updateResult;
3254
3254
  if (ownedByModel) {
3255
- (0, import_tiny_invariant7.default)(_data.length === 1, "only one entity can be connected");
3255
+ (0, import_common_helpers8.invariant)(_data.length === 1, "only one entity can be connected");
3256
3256
  const target = await this.readUnique(kysely, model, {
3257
3257
  where: _data[0]
3258
3258
  });
@@ -3342,7 +3342,7 @@ var BaseOperationHandler = class {
3342
3342
  const { ownedByModel, keyPairs } = getRelationForeignKeyFieldPairs(this.schema, fromRelation.model, fromRelation.field);
3343
3343
  const eb = (0, import_kysely8.expressionBuilder)();
3344
3344
  if (ownedByModel) {
3345
- (0, import_tiny_invariant7.default)(disconnectConditions.length === 1, "only one entity can be disconnected");
3345
+ (0, import_common_helpers8.invariant)(disconnectConditions.length === 1, "only one entity can be disconnected");
3346
3346
  const condition = disconnectConditions[0];
3347
3347
  const query = kysely.updateTable(fromRelation.model).where(eb.and(fromRelation.ids)).$if(condition !== true, (qb) => qb.where(eb(
3348
3348
  // @ts-ignore
@@ -3450,7 +3450,7 @@ var BaseOperationHandler = class {
3450
3450
  const m2m = getManyToManyRelation(this.schema, fromRelation.model, fromRelation.field);
3451
3451
  if (m2m) {
3452
3452
  const fieldDef = this.requireField(fromRelation.model, fromRelation.field);
3453
- (0, import_tiny_invariant7.default)(fieldDef.relation?.opposite);
3453
+ (0, import_common_helpers8.invariant)(fieldDef.relation?.opposite);
3454
3454
  deleteResult = await this.delete(kysely, model, {
3455
3455
  AND: [
3456
3456
  {
@@ -3473,7 +3473,7 @@ var BaseOperationHandler = class {
3473
3473
  throw new NotFoundError(model);
3474
3474
  }
3475
3475
  const fieldDef = this.requireField(fromRelation.model, fromRelation.field);
3476
- (0, import_tiny_invariant7.default)(fieldDef.relation?.opposite);
3476
+ (0, import_common_helpers8.invariant)(fieldDef.relation?.opposite);
3477
3477
  deleteResult = await this.delete(kysely, model, {
3478
3478
  AND: [
3479
3479
  // filter for parent
@@ -3978,16 +3978,15 @@ var UpdateOperationHandler = class extends BaseOperationHandler {
3978
3978
  var import_decimal = __toESM(require("decimal.js"), 1);
3979
3979
  var import_json_stable_stringify = __toESM(require("json-stable-stringify"), 1);
3980
3980
  var import_ts_pattern14 = require("ts-pattern");
3981
- var import_zod = require("zod");
3981
+ var import_v4 = require("zod/v4");
3982
3982
  var InputValidator = class {
3983
3983
  static {
3984
3984
  __name(this, "InputValidator");
3985
3985
  }
3986
3986
  schema;
3987
- schemaCache;
3987
+ schemaCache = /* @__PURE__ */ new Map();
3988
3988
  constructor(schema) {
3989
3989
  this.schema = schema;
3990
- this.schemaCache = /* @__PURE__ */ new Map();
3991
3990
  }
3992
3991
  validateFindArgs(model, unique, args) {
3993
3992
  return this.validate(model, "find", {
@@ -4063,11 +4062,11 @@ var InputValidator = class {
4063
4062
  fields["distinct"] = this.makeDistinctSchema(model).optional();
4064
4063
  fields["cursor"] = this.makeCursorSchema(model).optional();
4065
4064
  if (options.collection) {
4066
- fields["skip"] = import_zod.z.number().int().nonnegative().optional();
4067
- fields["take"] = import_zod.z.number().int().optional();
4065
+ fields["skip"] = import_v4.z.number().int().nonnegative().optional();
4066
+ fields["take"] = import_v4.z.number().int().optional();
4068
4067
  fields["orderBy"] = this.orArray(this.makeOrderBySchema(model, true, false), true).optional();
4069
4068
  }
4070
- let result = import_zod.z.object(fields).strict();
4069
+ let result = import_v4.z.object(fields).strict();
4071
4070
  result = this.refineForSelectIncludeMutuallyExclusive(result);
4072
4071
  result = this.refineForSelectOmitMutuallyExclusive(result);
4073
4072
  if (!options.unique) {
@@ -4076,17 +4075,17 @@ var InputValidator = class {
4076
4075
  return result;
4077
4076
  }
4078
4077
  makePrimitiveSchema(type) {
4079
- return (0, import_ts_pattern14.match)(type).with("String", () => import_zod.z.string()).with("Int", () => import_zod.z.number()).with("Float", () => import_zod.z.number()).with("Boolean", () => import_zod.z.boolean()).with("BigInt", () => import_zod.z.union([
4080
- import_zod.z.number(),
4081
- import_zod.z.bigint()
4082
- ])).with("Decimal", () => import_zod.z.union([
4083
- import_zod.z.number(),
4084
- import_zod.z.instanceof(import_decimal.default),
4085
- import_zod.z.string()
4086
- ])).with("DateTime", () => import_zod.z.union([
4087
- import_zod.z.date(),
4088
- import_zod.z.string().datetime()
4089
- ])).with("Bytes", () => import_zod.z.instanceof(Uint8Array)).otherwise(() => import_zod.z.unknown());
4078
+ return (0, import_ts_pattern14.match)(type).with("String", () => import_v4.z.string()).with("Int", () => import_v4.z.number()).with("Float", () => import_v4.z.number()).with("Boolean", () => import_v4.z.boolean()).with("BigInt", () => import_v4.z.union([
4079
+ import_v4.z.number(),
4080
+ import_v4.z.bigint()
4081
+ ])).with("Decimal", () => import_v4.z.union([
4082
+ import_v4.z.number(),
4083
+ import_v4.z.instanceof(import_decimal.default),
4084
+ import_v4.z.string()
4085
+ ])).with("DateTime", () => import_v4.z.union([
4086
+ import_v4.z.date(),
4087
+ import_v4.z.string().datetime()
4088
+ ])).with("Bytes", () => import_v4.z.instanceof(Uint8Array)).otherwise(() => import_v4.z.unknown());
4090
4089
  }
4091
4090
  makeWhereSchema(model, unique, withoutRelationFields = false) {
4092
4091
  const modelDef = getModel(this.schema, model);
@@ -4101,21 +4100,21 @@ var InputValidator = class {
4101
4100
  if (withoutRelationFields) {
4102
4101
  continue;
4103
4102
  }
4104
- fieldSchema = import_zod.z.lazy(() => this.makeWhereSchema(fieldDef.type, false).optional());
4103
+ fieldSchema = import_v4.z.lazy(() => this.makeWhereSchema(fieldDef.type, false).optional());
4105
4104
  fieldSchema = this.nullableIf(fieldSchema, !fieldDef.array && !!fieldDef.optional);
4106
4105
  if (fieldDef.array) {
4107
- fieldSchema = import_zod.z.union([
4106
+ fieldSchema = import_v4.z.union([
4108
4107
  fieldSchema,
4109
- import_zod.z.object({
4108
+ import_v4.z.object({
4110
4109
  some: fieldSchema.optional(),
4111
4110
  every: fieldSchema.optional(),
4112
4111
  none: fieldSchema.optional()
4113
4112
  })
4114
4113
  ]);
4115
4114
  } else {
4116
- fieldSchema = import_zod.z.union([
4115
+ fieldSchema = import_v4.z.union([
4117
4116
  fieldSchema,
4118
- import_zod.z.object({
4117
+ import_v4.z.object({
4119
4118
  is: fieldSchema.optional(),
4120
4119
  isNot: fieldSchema.optional()
4121
4120
  })
@@ -4141,18 +4140,18 @@ var InputValidator = class {
4141
4140
  const uniqueFields = getUniqueFields(this.schema, model);
4142
4141
  for (const uniqueField of uniqueFields) {
4143
4142
  if ("defs" in uniqueField) {
4144
- fields[uniqueField.name] = import_zod.z.object(Object.fromEntries(Object.entries(uniqueField.defs).map(([key, def]) => [
4143
+ fields[uniqueField.name] = import_v4.z.object(Object.fromEntries(Object.entries(uniqueField.defs).map(([key, def]) => [
4145
4144
  key,
4146
4145
  this.makePrimitiveFilterSchema(def.type, !!def.optional)
4147
4146
  ]))).optional();
4148
4147
  }
4149
4148
  }
4150
4149
  }
4151
- fields["$expr"] = import_zod.z.function().optional();
4152
- fields["AND"] = this.orArray(import_zod.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
4153
- fields["OR"] = import_zod.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)).array().optional();
4154
- fields["NOT"] = this.orArray(import_zod.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
4155
- const baseWhere = import_zod.z.object(fields).strict();
4150
+ fields["$expr"] = import_v4.z.custom((v) => typeof v === "function").optional();
4151
+ fields["AND"] = this.orArray(import_v4.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
4152
+ fields["OR"] = import_v4.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)).array().optional();
4153
+ fields["NOT"] = this.orArray(import_v4.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
4154
+ const baseWhere = import_v4.z.object(fields).strict();
4156
4155
  let result = baseWhere;
4157
4156
  if (unique) {
4158
4157
  const uniqueFields = getUniqueFields(this.schema, model);
@@ -4172,11 +4171,11 @@ var InputValidator = class {
4172
4171
  return result;
4173
4172
  }
4174
4173
  makeEnumFilterSchema(enumDef, optional) {
4175
- const baseSchema = import_zod.z.enum(Object.keys(enumDef));
4176
- const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => import_zod.z.lazy(() => this.makeEnumFilterSchema(enumDef, optional)));
4177
- return import_zod.z.union([
4174
+ const baseSchema = import_v4.z.enum(Object.keys(enumDef));
4175
+ const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => import_v4.z.lazy(() => this.makeEnumFilterSchema(enumDef, optional)));
4176
+ return import_v4.z.union([
4178
4177
  this.nullableIf(baseSchema, optional),
4179
- import_zod.z.object({
4178
+ import_v4.z.object({
4180
4179
  equals: components.equals,
4181
4180
  in: components.in,
4182
4181
  notIn: components.notIn,
@@ -4185,38 +4184,38 @@ var InputValidator = class {
4185
4184
  ]);
4186
4185
  }
4187
4186
  makeArrayFilterSchema(type) {
4188
- return import_zod.z.object({
4187
+ return import_v4.z.object({
4189
4188
  equals: this.makePrimitiveSchema(type).array().optional(),
4190
4189
  has: this.makePrimitiveSchema(type).optional(),
4191
4190
  hasEvery: this.makePrimitiveSchema(type).array().optional(),
4192
4191
  hasSome: this.makePrimitiveSchema(type).array().optional(),
4193
- isEmpty: import_zod.z.boolean().optional()
4192
+ isEmpty: import_v4.z.boolean().optional()
4194
4193
  });
4195
4194
  }
4196
4195
  makePrimitiveFilterSchema(type, optional) {
4197
4196
  return (0, import_ts_pattern14.match)(type).with("String", () => this.makeStringFilterSchema(optional)).with(import_ts_pattern14.P.union("Int", "Float", "Decimal", "BigInt"), (type2) => this.makeNumberFilterSchema(this.makePrimitiveSchema(type2), optional)).with("Boolean", () => this.makeBooleanFilterSchema(optional)).with("DateTime", () => this.makeDateTimeFilterSchema(optional)).with("Bytes", () => this.makeBytesFilterSchema(optional)).exhaustive();
4198
4197
  }
4199
4198
  makeDateTimeFilterSchema(optional) {
4200
- return this.makeCommonPrimitiveFilterSchema(import_zod.z.union([
4201
- import_zod.z.string().datetime(),
4202
- import_zod.z.date()
4203
- ]), optional, () => import_zod.z.lazy(() => this.makeDateTimeFilterSchema(optional)));
4199
+ return this.makeCommonPrimitiveFilterSchema(import_v4.z.union([
4200
+ import_v4.z.string().datetime(),
4201
+ import_v4.z.date()
4202
+ ]), optional, () => import_v4.z.lazy(() => this.makeDateTimeFilterSchema(optional)));
4204
4203
  }
4205
4204
  makeBooleanFilterSchema(optional) {
4206
- return import_zod.z.union([
4207
- this.nullableIf(import_zod.z.boolean(), optional),
4208
- import_zod.z.object({
4209
- equals: this.nullableIf(import_zod.z.boolean(), optional).optional(),
4210
- not: import_zod.z.lazy(() => this.makeBooleanFilterSchema(optional)).optional()
4205
+ return import_v4.z.union([
4206
+ this.nullableIf(import_v4.z.boolean(), optional),
4207
+ import_v4.z.object({
4208
+ equals: this.nullableIf(import_v4.z.boolean(), optional).optional(),
4209
+ not: import_v4.z.lazy(() => this.makeBooleanFilterSchema(optional)).optional()
4211
4210
  })
4212
4211
  ]);
4213
4212
  }
4214
4213
  makeBytesFilterSchema(optional) {
4215
- const baseSchema = import_zod.z.instanceof(Uint8Array);
4216
- const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => import_zod.z.instanceof(Uint8Array));
4217
- return import_zod.z.union([
4214
+ const baseSchema = import_v4.z.instanceof(Uint8Array);
4215
+ const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => import_v4.z.instanceof(Uint8Array));
4216
+ return import_v4.z.union([
4218
4217
  this.nullableIf(baseSchema, optional),
4219
- import_zod.z.object({
4218
+ import_v4.z.object({
4220
4219
  equals: components.equals,
4221
4220
  in: components.in,
4222
4221
  notIn: components.notIn,
@@ -4238,16 +4237,16 @@ var InputValidator = class {
4238
4237
  };
4239
4238
  }
4240
4239
  makeCommonPrimitiveFilterSchema(baseSchema, optional, makeThis) {
4241
- return import_zod.z.union([
4240
+ return import_v4.z.union([
4242
4241
  this.nullableIf(baseSchema, optional),
4243
- import_zod.z.object(this.makeCommonPrimitiveFilterComponents(baseSchema, optional, makeThis))
4242
+ import_v4.z.object(this.makeCommonPrimitiveFilterComponents(baseSchema, optional, makeThis))
4244
4243
  ]);
4245
4244
  }
4246
4245
  makeNumberFilterSchema(baseSchema, optional) {
4247
- return this.makeCommonPrimitiveFilterSchema(baseSchema, optional, () => import_zod.z.lazy(() => this.makeNumberFilterSchema(baseSchema, optional)));
4246
+ return this.makeCommonPrimitiveFilterSchema(baseSchema, optional, () => import_v4.z.lazy(() => this.makeNumberFilterSchema(baseSchema, optional)));
4248
4247
  }
4249
4248
  makeStringFilterSchema(optional) {
4250
- return this.makeCommonPrimitiveFilterSchema(import_zod.z.string(), optional, () => import_zod.z.lazy(() => this.makeStringFilterSchema(optional)));
4249
+ return this.makeCommonPrimitiveFilterSchema(import_v4.z.string(), optional, () => import_v4.z.lazy(() => this.makeStringFilterSchema(optional)));
4251
4250
  }
4252
4251
  makeSelectSchema(model) {
4253
4252
  const modelDef = requireModel(this.schema, model);
@@ -4255,33 +4254,33 @@ var InputValidator = class {
4255
4254
  for (const field of Object.keys(modelDef.fields)) {
4256
4255
  const fieldDef = requireField(this.schema, model, field);
4257
4256
  if (fieldDef.relation) {
4258
- fields[field] = import_zod.z.union([
4259
- import_zod.z.literal(true),
4260
- import_zod.z.object({
4261
- select: import_zod.z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional(),
4262
- include: import_zod.z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional()
4257
+ fields[field] = import_v4.z.union([
4258
+ import_v4.z.literal(true),
4259
+ import_v4.z.object({
4260
+ select: import_v4.z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional(),
4261
+ include: import_v4.z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional()
4263
4262
  })
4264
4263
  ]).optional();
4265
4264
  } else {
4266
- fields[field] = import_zod.z.boolean().optional();
4265
+ fields[field] = import_v4.z.boolean().optional();
4267
4266
  }
4268
4267
  }
4269
4268
  const toManyRelations = Object.entries(modelDef.fields).filter(([, value]) => value.relation && value.array);
4270
4269
  if (toManyRelations.length > 0) {
4271
- fields["_count"] = import_zod.z.union([
4272
- import_zod.z.literal(true),
4273
- import_zod.z.object(toManyRelations.reduce((acc, [name, fieldDef]) => ({
4270
+ fields["_count"] = import_v4.z.union([
4271
+ import_v4.z.literal(true),
4272
+ import_v4.z.object(toManyRelations.reduce((acc, [name, fieldDef]) => ({
4274
4273
  ...acc,
4275
- [name]: import_zod.z.union([
4276
- import_zod.z.boolean(),
4277
- import_zod.z.object({
4274
+ [name]: import_v4.z.union([
4275
+ import_v4.z.boolean(),
4276
+ import_v4.z.object({
4278
4277
  where: this.makeWhereSchema(fieldDef.type, false, false)
4279
4278
  })
4280
4279
  ]).optional()
4281
4280
  }), {}))
4282
4281
  ]).optional();
4283
4282
  }
4284
- return import_zod.z.object(fields).strict();
4283
+ return import_v4.z.object(fields).strict();
4285
4284
  }
4286
4285
  makeOmitSchema(model) {
4287
4286
  const modelDef = requireModel(this.schema, model);
@@ -4289,10 +4288,10 @@ var InputValidator = class {
4289
4288
  for (const field of Object.keys(modelDef.fields)) {
4290
4289
  const fieldDef = requireField(this.schema, model, field);
4291
4290
  if (!fieldDef.relation) {
4292
- fields[field] = import_zod.z.boolean().optional();
4291
+ fields[field] = import_v4.z.boolean().optional();
4293
4292
  }
4294
4293
  }
4295
- return import_zod.z.object(fields).strict();
4294
+ return import_v4.z.object(fields).strict();
4296
4295
  }
4297
4296
  makeIncludeSchema(model) {
4298
4297
  const modelDef = requireModel(this.schema, model);
@@ -4300,40 +4299,40 @@ var InputValidator = class {
4300
4299
  for (const field of Object.keys(modelDef.fields)) {
4301
4300
  const fieldDef = requireField(this.schema, model, field);
4302
4301
  if (fieldDef.relation) {
4303
- fields[field] = import_zod.z.union([
4304
- import_zod.z.literal(true),
4305
- import_zod.z.object({
4306
- select: import_zod.z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional(),
4307
- include: import_zod.z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional(),
4308
- where: import_zod.z.lazy(() => this.makeWhereSchema(fieldDef.type, false)).optional()
4302
+ fields[field] = import_v4.z.union([
4303
+ import_v4.z.literal(true),
4304
+ import_v4.z.object({
4305
+ select: import_v4.z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional(),
4306
+ include: import_v4.z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional(),
4307
+ where: import_v4.z.lazy(() => this.makeWhereSchema(fieldDef.type, false)).optional()
4309
4308
  })
4310
4309
  ]).optional();
4311
4310
  }
4312
4311
  }
4313
- return import_zod.z.object(fields).strict();
4312
+ return import_v4.z.object(fields).strict();
4314
4313
  }
4315
4314
  makeOrderBySchema(model, withRelation, WithAggregation) {
4316
4315
  const modelDef = requireModel(this.schema, model);
4317
4316
  const fields = {};
4318
- const sort = import_zod.z.union([
4319
- import_zod.z.literal("asc"),
4320
- import_zod.z.literal("desc")
4317
+ const sort = import_v4.z.union([
4318
+ import_v4.z.literal("asc"),
4319
+ import_v4.z.literal("desc")
4321
4320
  ]);
4322
4321
  for (const field of Object.keys(modelDef.fields)) {
4323
4322
  const fieldDef = requireField(this.schema, model, field);
4324
4323
  if (fieldDef.relation) {
4325
4324
  if (withRelation) {
4326
- fields[field] = import_zod.z.lazy(() => this.makeOrderBySchema(fieldDef.type, withRelation, WithAggregation).optional());
4325
+ fields[field] = import_v4.z.lazy(() => this.makeOrderBySchema(fieldDef.type, withRelation, WithAggregation).optional());
4327
4326
  }
4328
4327
  } else {
4329
4328
  if (fieldDef.optional) {
4330
- fields[field] = import_zod.z.union([
4329
+ fields[field] = import_v4.z.union([
4331
4330
  sort,
4332
- import_zod.z.object({
4331
+ import_v4.z.object({
4333
4332
  sort,
4334
- nulls: import_zod.z.union([
4335
- import_zod.z.literal("first"),
4336
- import_zod.z.literal("last")
4333
+ nulls: import_v4.z.union([
4334
+ import_v4.z.literal("first"),
4335
+ import_v4.z.literal("last")
4337
4336
  ])
4338
4337
  })
4339
4338
  ]).optional();
@@ -4351,15 +4350,15 @@ var InputValidator = class {
4351
4350
  "_max"
4352
4351
  ];
4353
4352
  for (const agg of aggregationFields) {
4354
- fields[agg] = import_zod.z.lazy(() => this.makeOrderBySchema(model, true, false).optional());
4353
+ fields[agg] = import_v4.z.lazy(() => this.makeOrderBySchema(model, true, false).optional());
4355
4354
  }
4356
4355
  }
4357
- return import_zod.z.object(fields);
4356
+ return import_v4.z.object(fields);
4358
4357
  }
4359
4358
  makeDistinctSchema(model) {
4360
4359
  const modelDef = requireModel(this.schema, model);
4361
4360
  const nonRelationFields = Object.keys(modelDef.fields).filter((field) => !modelDef.fields[field]?.relation);
4362
- return this.orArray(import_zod.z.enum(nonRelationFields), true);
4361
+ return this.orArray(import_v4.z.enum(nonRelationFields), true);
4363
4362
  }
4364
4363
  makeCursorSchema(model) {
4365
4364
  return this.makeWhereSchema(model, true, true).optional();
@@ -4368,7 +4367,7 @@ var InputValidator = class {
4368
4367
  // #region Create
4369
4368
  makeCreateSchema(model) {
4370
4369
  const dataSchema = this.makeCreateDataSchema(model, false);
4371
- const schema = import_zod.z.object({
4370
+ const schema = import_v4.z.object({
4372
4371
  data: dataSchema,
4373
4372
  select: this.makeSelectSchema(model).optional(),
4374
4373
  include: this.makeIncludeSchema(model).optional(),
@@ -4381,7 +4380,7 @@ var InputValidator = class {
4381
4380
  }
4382
4381
  makeCreateManyAndReturnSchema(model) {
4383
4382
  const base = this.makeCreateManyDataSchema(model, []);
4384
- const result = base.merge(import_zod.z.object({
4383
+ const result = base.merge(import_v4.z.object({
4385
4384
  select: this.makeSelectSchema(model).optional(),
4386
4385
  omit: this.makeOmitSchema(model).optional()
4387
4386
  }));
@@ -4413,7 +4412,7 @@ var InputValidator = class {
4413
4412
  excludeFields.push(...oppositeFieldDef.relation.fields);
4414
4413
  }
4415
4414
  }
4416
- let fieldSchema = import_zod.z.lazy(() => this.makeRelationManipulationSchema(fieldDef, excludeFields, "create"));
4415
+ let fieldSchema = import_v4.z.lazy(() => this.makeRelationManipulationSchema(fieldDef, excludeFields, "create"));
4417
4416
  if (fieldDef.optional || fieldDef.array) {
4418
4417
  fieldSchema = fieldSchema.optional();
4419
4418
  } else {
@@ -4435,10 +4434,10 @@ var InputValidator = class {
4435
4434
  } else {
4436
4435
  let fieldSchema = this.makePrimitiveSchema(fieldDef.type);
4437
4436
  if (fieldDef.array) {
4438
- fieldSchema = import_zod.z.union([
4439
- import_zod.z.array(fieldSchema),
4440
- import_zod.z.object({
4441
- set: import_zod.z.array(fieldSchema)
4437
+ fieldSchema = import_v4.z.union([
4438
+ import_v4.z.array(fieldSchema),
4439
+ import_v4.z.object({
4440
+ set: import_v4.z.array(fieldSchema)
4442
4441
  })
4443
4442
  ]).optional();
4444
4443
  }
@@ -4455,16 +4454,16 @@ var InputValidator = class {
4455
4454
  }
4456
4455
  });
4457
4456
  if (!hasRelation) {
4458
- return this.orArray(import_zod.z.object(regularAndFkFields).strict(), canBeArray);
4457
+ return this.orArray(import_v4.z.object(regularAndFkFields).strict(), canBeArray);
4459
4458
  } else {
4460
- return import_zod.z.union([
4461
- import_zod.z.object(regularAndFkFields).strict(),
4462
- import_zod.z.object(regularAndRelationFields).strict(),
4459
+ return import_v4.z.union([
4460
+ import_v4.z.object(regularAndFkFields).strict(),
4461
+ import_v4.z.object(regularAndRelationFields).strict(),
4463
4462
  ...canBeArray ? [
4464
- import_zod.z.array(import_zod.z.object(regularAndFkFields).strict())
4463
+ import_v4.z.array(import_v4.z.object(regularAndFkFields).strict())
4465
4464
  ] : [],
4466
4465
  ...canBeArray ? [
4467
- import_zod.z.array(import_zod.z.object(regularAndRelationFields).strict())
4466
+ import_v4.z.array(import_v4.z.object(regularAndRelationFields).strict())
4468
4467
  ] : []
4469
4468
  ]);
4470
4469
  }
@@ -4485,31 +4484,31 @@ var InputValidator = class {
4485
4484
  fields["disconnect"] = this.makeDisconnectDataSchema(fieldType, array).optional();
4486
4485
  fields["delete"] = this.makeDeleteRelationDataSchema(fieldType, array, true).optional();
4487
4486
  }
4488
- fields["update"] = array ? this.orArray(import_zod.z.object({
4487
+ fields["update"] = array ? this.orArray(import_v4.z.object({
4489
4488
  where: this.makeWhereSchema(fieldType, true),
4490
4489
  data: this.makeUpdateDataSchema(fieldType, withoutFields)
4491
- }), true).optional() : import_zod.z.union([
4492
- import_zod.z.object({
4490
+ }), true).optional() : import_v4.z.union([
4491
+ import_v4.z.object({
4493
4492
  where: this.makeWhereSchema(fieldType, true),
4494
4493
  data: this.makeUpdateDataSchema(fieldType, withoutFields)
4495
4494
  }),
4496
4495
  this.makeUpdateDataSchema(fieldType, withoutFields)
4497
4496
  ]).optional();
4498
- fields["upsert"] = this.orArray(import_zod.z.object({
4497
+ fields["upsert"] = this.orArray(import_v4.z.object({
4499
4498
  where: this.makeWhereSchema(fieldType, true),
4500
4499
  create: this.makeCreateDataSchema(fieldType, false, withoutFields),
4501
4500
  update: this.makeUpdateDataSchema(fieldType, withoutFields)
4502
4501
  }), true).optional();
4503
4502
  if (array) {
4504
4503
  fields["set"] = this.makeSetDataSchema(fieldType, true).optional();
4505
- fields["updateMany"] = this.orArray(import_zod.z.object({
4504
+ fields["updateMany"] = this.orArray(import_v4.z.object({
4506
4505
  where: this.makeWhereSchema(fieldType, false, true),
4507
4506
  data: this.makeUpdateDataSchema(fieldType, withoutFields)
4508
4507
  }), true).optional();
4509
4508
  fields["deleteMany"] = this.makeDeleteRelationDataSchema(fieldType, true, false).optional();
4510
4509
  }
4511
4510
  }
4512
- return import_zod.z.object(fields).strict().refine((v) => Object.keys(v).length > 0, "At least one action is required");
4511
+ return import_v4.z.object(fields).strict().refine((v) => Object.keys(v).length > 0, "At least one action is required");
4513
4512
  }
4514
4513
  makeSetDataSchema(model, canBeArray) {
4515
4514
  return this.orArray(this.makeWhereSchema(model, true), canBeArray);
@@ -4521,36 +4520,36 @@ var InputValidator = class {
4521
4520
  if (canBeArray) {
4522
4521
  return this.orArray(this.makeWhereSchema(model, true), canBeArray);
4523
4522
  } else {
4524
- return import_zod.z.union([
4525
- import_zod.z.boolean(),
4523
+ return import_v4.z.union([
4524
+ import_v4.z.boolean(),
4526
4525
  this.makeWhereSchema(model, false)
4527
4526
  ]);
4528
4527
  }
4529
4528
  }
4530
4529
  makeDeleteRelationDataSchema(model, toManyRelation, uniqueFilter) {
4531
- return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter), true) : import_zod.z.union([
4532
- import_zod.z.boolean(),
4530
+ return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter), true) : import_v4.z.union([
4531
+ import_v4.z.boolean(),
4533
4532
  this.makeWhereSchema(model, uniqueFilter)
4534
4533
  ]);
4535
4534
  }
4536
4535
  makeConnectOrCreateDataSchema(model, canBeArray, withoutFields) {
4537
4536
  const whereSchema = this.makeWhereSchema(model, true);
4538
4537
  const createSchema = this.makeCreateDataSchema(model, false, withoutFields);
4539
- return this.orArray(import_zod.z.object({
4538
+ return this.orArray(import_v4.z.object({
4540
4539
  where: whereSchema,
4541
4540
  create: createSchema
4542
4541
  }).strict(), canBeArray);
4543
4542
  }
4544
4543
  makeCreateManyDataSchema(model, withoutFields) {
4545
- return import_zod.z.object({
4544
+ return import_v4.z.object({
4546
4545
  data: this.makeCreateDataSchema(model, true, withoutFields, true),
4547
- skipDuplicates: import_zod.z.boolean().optional()
4546
+ skipDuplicates: import_v4.z.boolean().optional()
4548
4547
  }).strict();
4549
4548
  }
4550
4549
  // #endregion
4551
4550
  // #region Update
4552
4551
  makeUpdateSchema(model) {
4553
- const schema = import_zod.z.object({
4552
+ const schema = import_v4.z.object({
4554
4553
  where: this.makeWhereSchema(model, true),
4555
4554
  data: this.makeUpdateDataSchema(model),
4556
4555
  select: this.makeSelectSchema(model).optional(),
@@ -4560,22 +4559,22 @@ var InputValidator = class {
4560
4559
  return this.refineForSelectIncludeMutuallyExclusive(schema);
4561
4560
  }
4562
4561
  makeUpdateManySchema(model) {
4563
- return import_zod.z.object({
4562
+ return import_v4.z.object({
4564
4563
  where: this.makeWhereSchema(model, false).optional(),
4565
4564
  data: this.makeUpdateDataSchema(model, [], true),
4566
- limit: import_zod.z.number().int().nonnegative().optional()
4565
+ limit: import_v4.z.number().int().nonnegative().optional()
4567
4566
  }).strict();
4568
4567
  }
4569
4568
  makeUpdateManyAndReturnSchema(model) {
4570
4569
  const base = this.makeUpdateManySchema(model);
4571
- const result = base.merge(import_zod.z.object({
4570
+ const result = base.merge(import_v4.z.object({
4572
4571
  select: this.makeSelectSchema(model).optional(),
4573
4572
  omit: this.makeOmitSchema(model).optional()
4574
4573
  }));
4575
4574
  return this.refineForSelectOmitMutuallyExclusive(result);
4576
4575
  }
4577
4576
  makeUpsertSchema(model) {
4578
- const schema = import_zod.z.object({
4577
+ const schema = import_v4.z.object({
4579
4578
  where: this.makeWhereSchema(model, true),
4580
4579
  create: this.makeCreateDataSchema(model, false),
4581
4580
  update: this.makeUpdateDataSchema(model),
@@ -4608,7 +4607,7 @@ var InputValidator = class {
4608
4607
  excludeFields.push(...oppositeFieldDef.relation.fields);
4609
4608
  }
4610
4609
  }
4611
- let fieldSchema = import_zod.z.lazy(() => this.makeRelationManipulationSchema(fieldDef, excludeFields, "update")).optional();
4610
+ let fieldSchema = import_v4.z.lazy(() => this.makeRelationManipulationSchema(fieldDef, excludeFields, "update")).optional();
4612
4611
  if (fieldDef.optional && !fieldDef.array) {
4613
4612
  fieldSchema = fieldSchema.nullable();
4614
4613
  }
@@ -4616,22 +4615,22 @@ var InputValidator = class {
4616
4615
  } else {
4617
4616
  let fieldSchema = this.makePrimitiveSchema(fieldDef.type).optional();
4618
4617
  if (this.isNumericField(fieldDef)) {
4619
- fieldSchema = import_zod.z.union([
4618
+ fieldSchema = import_v4.z.union([
4620
4619
  fieldSchema,
4621
- import_zod.z.object({
4622
- set: this.nullableIf(import_zod.z.number().optional(), !!fieldDef.optional),
4623
- increment: import_zod.z.number().optional(),
4624
- decrement: import_zod.z.number().optional(),
4625
- multiply: import_zod.z.number().optional(),
4626
- divide: import_zod.z.number().optional()
4620
+ import_v4.z.object({
4621
+ set: this.nullableIf(import_v4.z.number().optional(), !!fieldDef.optional),
4622
+ increment: import_v4.z.number().optional(),
4623
+ decrement: import_v4.z.number().optional(),
4624
+ multiply: import_v4.z.number().optional(),
4625
+ divide: import_v4.z.number().optional()
4627
4626
  }).refine((v) => Object.keys(v).length === 1, 'Only one of "set", "increment", "decrement", "multiply", or "divide" can be provided')
4628
4627
  ]);
4629
4628
  }
4630
4629
  if (fieldDef.array) {
4631
- fieldSchema = import_zod.z.union([
4630
+ fieldSchema = import_v4.z.union([
4632
4631
  fieldSchema.array(),
4633
- import_zod.z.object({
4634
- set: import_zod.z.array(fieldSchema).optional(),
4632
+ import_v4.z.object({
4633
+ set: import_v4.z.array(fieldSchema).optional(),
4635
4634
  push: this.orArray(fieldSchema, true).optional()
4636
4635
  }).refine((v) => Object.keys(v).length === 1, 'Only one of "set", "push" can be provided')
4637
4636
  ]).optional();
@@ -4646,18 +4645,18 @@ var InputValidator = class {
4646
4645
  }
4647
4646
  });
4648
4647
  if (!hasRelation) {
4649
- return import_zod.z.object(regularAndFkFields).strict();
4648
+ return import_v4.z.object(regularAndFkFields).strict();
4650
4649
  } else {
4651
- return import_zod.z.union([
4652
- import_zod.z.object(regularAndFkFields).strict(),
4653
- import_zod.z.object(regularAndRelationFields).strict()
4650
+ return import_v4.z.union([
4651
+ import_v4.z.object(regularAndFkFields).strict(),
4652
+ import_v4.z.object(regularAndRelationFields).strict()
4654
4653
  ]);
4655
4654
  }
4656
4655
  }
4657
4656
  // #endregion
4658
4657
  // #region Delete
4659
4658
  makeDeleteSchema(model) {
4660
- const schema = import_zod.z.object({
4659
+ const schema = import_v4.z.object({
4661
4660
  where: this.makeWhereSchema(model, true),
4662
4661
  select: this.makeSelectSchema(model).optional(),
4663
4662
  include: this.makeIncludeSchema(model).optional()
@@ -4665,30 +4664,30 @@ var InputValidator = class {
4665
4664
  return this.refineForSelectIncludeMutuallyExclusive(schema);
4666
4665
  }
4667
4666
  makeDeleteManySchema(model) {
4668
- return import_zod.z.object({
4667
+ return import_v4.z.object({
4669
4668
  where: this.makeWhereSchema(model, false).optional(),
4670
- limit: import_zod.z.number().int().nonnegative().optional()
4669
+ limit: import_v4.z.number().int().nonnegative().optional()
4671
4670
  }).strict().optional();
4672
4671
  }
4673
4672
  // #endregion
4674
4673
  // #region Count
4675
4674
  makeCountSchema(model) {
4676
- return import_zod.z.object({
4675
+ return import_v4.z.object({
4677
4676
  where: this.makeWhereSchema(model, false).optional(),
4678
- skip: import_zod.z.number().int().nonnegative().optional(),
4679
- take: import_zod.z.number().int().optional(),
4677
+ skip: import_v4.z.number().int().nonnegative().optional(),
4678
+ take: import_v4.z.number().int().optional(),
4680
4679
  orderBy: this.orArray(this.makeOrderBySchema(model, true, false), true).optional(),
4681
4680
  select: this.makeCountAggregateInputSchema(model).optional()
4682
4681
  }).strict().optional();
4683
4682
  }
4684
4683
  makeCountAggregateInputSchema(model) {
4685
4684
  const modelDef = requireModel(this.schema, model);
4686
- return import_zod.z.union([
4687
- import_zod.z.literal(true),
4688
- import_zod.z.object({
4689
- _all: import_zod.z.literal(true).optional(),
4685
+ return import_v4.z.union([
4686
+ import_v4.z.literal(true),
4687
+ import_v4.z.object({
4688
+ _all: import_v4.z.literal(true).optional(),
4690
4689
  ...Object.keys(modelDef.fields).reduce((acc, field) => {
4691
- acc[field] = import_zod.z.literal(true).optional();
4690
+ acc[field] = import_v4.z.literal(true).optional();
4692
4691
  return acc;
4693
4692
  }, {})
4694
4693
  }).strict()
@@ -4697,10 +4696,10 @@ var InputValidator = class {
4697
4696
  // #endregion
4698
4697
  // #region Aggregate
4699
4698
  makeAggregateSchema(model) {
4700
- return import_zod.z.object({
4699
+ return import_v4.z.object({
4701
4700
  where: this.makeWhereSchema(model, false).optional(),
4702
- skip: import_zod.z.number().int().nonnegative().optional(),
4703
- take: import_zod.z.number().int().optional(),
4701
+ skip: import_v4.z.number().int().nonnegative().optional(),
4702
+ take: import_v4.z.number().int().optional(),
4704
4703
  orderBy: this.orArray(this.makeOrderBySchema(model, true, false), true).optional(),
4705
4704
  _count: this.makeCountAggregateInputSchema(model).optional(),
4706
4705
  _avg: this.makeSumAvgInputSchema(model).optional(),
@@ -4711,20 +4710,20 @@ var InputValidator = class {
4711
4710
  }
4712
4711
  makeSumAvgInputSchema(model) {
4713
4712
  const modelDef = requireModel(this.schema, model);
4714
- return import_zod.z.object(Object.keys(modelDef.fields).reduce((acc, field) => {
4713
+ return import_v4.z.object(Object.keys(modelDef.fields).reduce((acc, field) => {
4715
4714
  const fieldDef = requireField(this.schema, model, field);
4716
4715
  if (this.isNumericField(fieldDef)) {
4717
- acc[field] = import_zod.z.literal(true).optional();
4716
+ acc[field] = import_v4.z.literal(true).optional();
4718
4717
  }
4719
4718
  return acc;
4720
4719
  }, {}));
4721
4720
  }
4722
4721
  makeMinMaxInputSchema(model) {
4723
4722
  const modelDef = requireModel(this.schema, model);
4724
- return import_zod.z.object(Object.keys(modelDef.fields).reduce((acc, field) => {
4723
+ return import_v4.z.object(Object.keys(modelDef.fields).reduce((acc, field) => {
4725
4724
  const fieldDef = requireField(this.schema, model, field);
4726
4725
  if (!fieldDef.relation && !fieldDef.array) {
4727
- acc[field] = import_zod.z.literal(true).optional();
4726
+ acc[field] = import_v4.z.literal(true).optional();
4728
4727
  }
4729
4728
  return acc;
4730
4729
  }, {}));
@@ -4732,13 +4731,13 @@ var InputValidator = class {
4732
4731
  makeGroupBySchema(model) {
4733
4732
  const modelDef = requireModel(this.schema, model);
4734
4733
  const nonRelationFields = Object.keys(modelDef.fields).filter((field) => !modelDef.fields[field]?.relation);
4735
- let schema = import_zod.z.object({
4734
+ let schema = import_v4.z.object({
4736
4735
  where: this.makeWhereSchema(model, false).optional(),
4737
4736
  orderBy: this.orArray(this.makeOrderBySchema(model, false, true), true).optional(),
4738
- by: this.orArray(import_zod.z.enum(nonRelationFields), true),
4737
+ by: this.orArray(import_v4.z.enum(nonRelationFields), true),
4739
4738
  having: this.makeWhereSchema(model, false, true).optional(),
4740
- skip: import_zod.z.number().int().nonnegative().optional(),
4741
- take: import_zod.z.number().int().optional(),
4739
+ skip: import_v4.z.number().int().nonnegative().optional(),
4740
+ take: import_v4.z.number().int().optional(),
4742
4741
  _count: this.makeCountAggregateInputSchema(model).optional(),
4743
4742
  _avg: this.makeSumAvgInputSchema(model).optional(),
4744
4743
  _sum: this.makeSumAvgInputSchema(model).optional(),
@@ -4779,9 +4778,9 @@ var InputValidator = class {
4779
4778
  return nullable ? schema.nullable() : schema;
4780
4779
  }
4781
4780
  orArray(schema, canBeArray) {
4782
- return canBeArray ? import_zod.z.union([
4781
+ return canBeArray ? import_v4.z.union([
4783
4782
  schema,
4784
- import_zod.z.array(schema)
4783
+ import_v4.z.array(schema)
4785
4784
  ]) : schema;
4786
4785
  }
4787
4786
  isNumericField(fieldDef) {
@@ -4955,11 +4954,11 @@ var QueryNameMapper = class extends import_kysely12.OperationNodeTransformer {
4955
4954
  __name(this, "QueryNameMapper");
4956
4955
  }
4957
4956
  schema;
4958
- modelToTableMap;
4959
- fieldToColumnMap;
4960
- modelStack;
4957
+ modelToTableMap = /* @__PURE__ */ new Map();
4958
+ fieldToColumnMap = /* @__PURE__ */ new Map();
4959
+ modelStack = [];
4961
4960
  constructor(schema) {
4962
- super(), this.schema = schema, this.modelToTableMap = /* @__PURE__ */ new Map(), this.fieldToColumnMap = /* @__PURE__ */ new Map(), this.modelStack = [];
4961
+ super(), this.schema = schema;
4963
4962
  for (const [modelName, modelDef] of Object.entries(schema.models)) {
4964
4963
  const mappedName = this.getMappedName(modelDef);
4965
4964
  if (mappedName) {
@@ -5416,8 +5415,8 @@ __export(functions_exports, {
5416
5415
  search: () => search,
5417
5416
  startsWith: () => startsWith
5418
5417
  });
5418
+ var import_common_helpers9 = require("@zenstackhq/common-helpers");
5419
5419
  var import_kysely14 = require("kysely");
5420
- var import_tiny_invariant8 = __toESM(require("tiny-invariant"), 1);
5421
5420
  var import_ts_pattern16 = require("ts-pattern");
5422
5421
  var contains = /* @__PURE__ */ __name((eb, args) => {
5423
5422
  const [field, search2, caseInsensitive = false] = args;
@@ -5523,8 +5522,8 @@ var currentOperation = /* @__PURE__ */ __name((_eb, args, { operation }) => {
5523
5522
  }, "currentOperation");
5524
5523
  function processCasing(casing, result, model) {
5525
5524
  const opNode = casing.toOperationNode();
5526
- (0, import_tiny_invariant8.default)(import_kysely14.ValueNode.is(opNode) && typeof opNode.value === "string", '"casting" parameter must be a string value');
5527
- result = (0, import_ts_pattern16.match)(opNode.value).with("original", () => model).with("upper", () => result.toUpperCase()).with("lower", () => result.toLowerCase()).with("capitalize", () => `${result.charAt(0).toUpperCase() + result.slice(1)}`).with("uncapitalize", () => `${result.charAt(0).toLowerCase() + result.slice(1)}`).otherwise(() => {
5525
+ (0, import_common_helpers9.invariant)(import_kysely14.ValueNode.is(opNode) && typeof opNode.value === "string", '"casting" parameter must be a string value');
5526
+ result = (0, import_ts_pattern16.match)(opNode.value).with("original", () => model).with("upper", () => result.toUpperCase()).with("lower", () => result.toLowerCase()).with("capitalize", () => (0, import_common_helpers9.upperCaseFirst)(result)).with("uncapitalize", () => (0, import_common_helpers9.lowerCaseFirst)(result)).otherwise(() => {
5528
5527
  throw new Error(`Invalid casing value: ${opNode.value}. Must be "original", "upper", "lower", "capitalize", or "uncapitalize".`);
5529
5528
  });
5530
5529
  return result;
@@ -5532,8 +5531,8 @@ function processCasing(casing, result, model) {
5532
5531
  __name(processCasing, "processCasing");
5533
5532
 
5534
5533
  // src/client/helpers/schema-db-pusher.ts
5534
+ var import_common_helpers10 = require("@zenstackhq/common-helpers");
5535
5535
  var import_kysely15 = require("kysely");
5536
- var import_tiny_invariant9 = __toESM(require("tiny-invariant"), 1);
5537
5536
  var import_ts_pattern17 = require("ts-pattern");
5538
5537
  var SchemaDbPusher = class {
5539
5538
  static {
@@ -5565,7 +5564,7 @@ var SchemaDbPusher = class {
5565
5564
  for (const [fieldName, fieldDef] of Object.entries(modelDef.fields)) {
5566
5565
  if (fieldDef.relation) {
5567
5566
  table = this.addForeignKeyConstraint(table, model, fieldName, fieldDef);
5568
- } else {
5567
+ } else if (!this.isComputedField(fieldDef)) {
5569
5568
  table = this.createModelField(table, fieldName, fieldDef, modelDef);
5570
5569
  }
5571
5570
  }
@@ -5573,6 +5572,9 @@ var SchemaDbPusher = class {
5573
5572
  table = this.addUniqueConstraint(table, modelDef);
5574
5573
  return table;
5575
5574
  }
5575
+ isComputedField(fieldDef) {
5576
+ return fieldDef.attributes?.some((a) => a.name === "@computed");
5577
+ }
5576
5578
  addPrimaryKeyConstraint(table, model, modelDef) {
5577
5579
  if (modelDef.idFields.length === 1) {
5578
5580
  if (Object.values(modelDef.fields).some((f) => f.id)) {
@@ -5586,7 +5588,7 @@ var SchemaDbPusher = class {
5586
5588
  }
5587
5589
  addUniqueConstraint(table, modelDef) {
5588
5590
  for (const [key, value] of Object.entries(modelDef.uniqueFields)) {
5589
- (0, import_tiny_invariant9.default)(typeof value === "object", "expecting an object");
5591
+ (0, import_common_helpers10.invariant)(typeof value === "object", "expecting an object");
5590
5592
  if ("type" in value) {
5591
5593
  const fieldDef = modelDef.fields[key];
5592
5594
  if (fieldDef.unique) {
@@ -5645,7 +5647,7 @@ var SchemaDbPusher = class {
5645
5647
  return fieldDef.default && ExpressionUtils.isCall(fieldDef.default) && fieldDef.default.function === "autoincrement";
5646
5648
  }
5647
5649
  addForeignKeyConstraint(table, model, fieldName, fieldDef) {
5648
- (0, import_tiny_invariant9.default)(fieldDef.relation, "field must be a relation");
5650
+ (0, import_common_helpers10.invariant)(fieldDef.relation, "field must be a relation");
5649
5651
  if (!fieldDef.relation.fields || !fieldDef.relation.references) {
5650
5652
  return table;
5651
5653
  }
@@ -5699,8 +5701,8 @@ function valueToPromise(thing) {
5699
5701
  __name(valueToPromise, "valueToPromise");
5700
5702
 
5701
5703
  // src/client/result-processor.ts
5704
+ var import_common_helpers11 = require("@zenstackhq/common-helpers");
5702
5705
  var import_decimal2 = __toESM(require("decimal.js"), 1);
5703
- var import_tiny_invariant10 = __toESM(require("tiny-invariant"), 1);
5704
5706
  var import_ts_pattern18 = require("ts-pattern");
5705
5707
  var ResultProcessor = class {
5706
5708
  static {
@@ -5780,14 +5782,14 @@ var ResultProcessor = class {
5780
5782
  if (value instanceof import_decimal2.default) {
5781
5783
  return value;
5782
5784
  }
5783
- (0, import_tiny_invariant10.default)(typeof value === "string" || typeof value === "number" || value instanceof import_decimal2.default, `Expected string, number or Decimal, got ${typeof value}`);
5785
+ (0, import_common_helpers11.invariant)(typeof value === "string" || typeof value === "number" || value instanceof import_decimal2.default, `Expected string, number or Decimal, got ${typeof value}`);
5784
5786
  return new import_decimal2.default(value);
5785
5787
  }
5786
5788
  transformBigInt(value) {
5787
5789
  if (typeof value === "bigint") {
5788
5790
  return value;
5789
5791
  }
5790
- (0, import_tiny_invariant10.default)(typeof value === "string" || typeof value === "number", `Expected string or number, got ${typeof value}`);
5792
+ (0, import_common_helpers11.invariant)(typeof value === "string" || typeof value === "number", `Expected string or number, got ${typeof value}`);
5791
5793
  return BigInt(value);
5792
5794
  }
5793
5795
  transformBoolean(value) {
@@ -5934,12 +5936,19 @@ var ClientImpl = class _ClientImpl {
5934
5936
  const newOptions = {
5935
5937
  ...this.options,
5936
5938
  plugins: [
5937
- ...this.options?.plugins ?? [],
5939
+ ...this.options.plugins ?? [],
5938
5940
  plugin
5939
5941
  ]
5940
5942
  };
5941
5943
  return new _ClientImpl(this.schema, newOptions, this);
5942
5944
  }
5945
+ $unuse(pluginId) {
5946
+ const newOptions = {
5947
+ ...this.options,
5948
+ plugins: this.options.plugins?.filter((p) => p.id !== pluginId)
5949
+ };
5950
+ return new _ClientImpl(this.schema, newOptions, this);
5951
+ }
5943
5952
  $unuseAll() {
5944
5953
  const newOptions = {
5945
5954
  ...this.options,
@@ -5995,22 +6004,31 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
5995
6004
  }
5996
6005
  return result;
5997
6006
  }, "proceed");
5998
- const context = {
5999
- client,
6000
- model,
6001
- operation,
6002
- queryArgs: args
6003
- };
6004
6007
  const plugins = [
6005
6008
  ...client.$options.plugins ?? []
6006
6009
  ];
6007
6010
  for (const plugin of plugins) {
6008
- if (plugin.onQuery) {
6009
- const _proceed = proceed;
6010
- proceed = /* @__PURE__ */ __name(() => plugin.onQuery({
6011
- ...context,
6012
- proceed: _proceed
6013
- }), "proceed");
6011
+ if (plugin.onQuery && typeof plugin.onQuery === "object") {
6012
+ for (const [_model, modelHooks] of Object.entries(plugin.onQuery)) {
6013
+ if (_model === (0, import_common_helpers12.lowerCaseFirst)(model) || _model === "$allModels") {
6014
+ if (modelHooks && typeof modelHooks === "object") {
6015
+ for (const [op, opHooks] of Object.entries(modelHooks)) {
6016
+ if (op === operation || op === "$allOperations") {
6017
+ if (typeof opHooks === "function") {
6018
+ const _proceed = proceed;
6019
+ proceed = /* @__PURE__ */ __name(() => opHooks({
6020
+ client,
6021
+ model,
6022
+ operation,
6023
+ args,
6024
+ query: _proceed
6025
+ }), "proceed");
6026
+ }
6027
+ }
6028
+ }
6029
+ }
6030
+ }
6031
+ }
6014
6032
  }
6015
6033
  }
6016
6034
  return proceed(args);