@zenstackhq/orm 3.5.3 → 3.5.4

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
@@ -65,7 +65,7 @@ __export(src_exports, {
65
65
  module.exports = __toCommonJS(src_exports);
66
66
 
67
67
  // src/client/client-impl.ts
68
- var import_common_helpers14 = require("@zenstackhq/common-helpers");
68
+ var import_common_helpers15 = require("@zenstackhq/common-helpers");
69
69
  var import_kysely12 = require("kysely");
70
70
  var import_zod3 = __toESM(require("zod"), 1);
71
71
 
@@ -119,7 +119,7 @@ __export(query_utils_exports, {
119
119
  stripAlias: () => stripAlias,
120
120
  tmpAlias: () => tmpAlias
121
121
  });
122
- var import_common_helpers = require("@zenstackhq/common-helpers");
122
+ var import_common_helpers2 = require("@zenstackhq/common-helpers");
123
123
  var import_kysely = require("kysely");
124
124
  var import_ts_pattern = require("ts-pattern");
125
125
 
@@ -128,6 +128,7 @@ var schema_exports = {};
128
128
  __reExport(schema_exports, require("@zenstackhq/schema"));
129
129
 
130
130
  // src/utils/object-utils.ts
131
+ var import_common_helpers = require("@zenstackhq/common-helpers");
131
132
  function extractFields(obj, fields) {
132
133
  return Object.fromEntries(Object.entries(obj).filter(([key]) => fields.includes(key)));
133
134
  }
@@ -139,6 +140,10 @@ function fieldsToSelectObject(fields) {
139
140
  ]));
140
141
  }
141
142
  __name(fieldsToSelectObject, "fieldsToSelectObject");
143
+ function isEmptyObject(x) {
144
+ return (0, import_common_helpers.isPlainObject)(x) && Object.keys(x).length === 0;
145
+ }
146
+ __name(isEmptyObject, "isEmptyObject");
142
147
 
143
148
  // src/client/executor/error-processor.ts
144
149
  function getDbErrorCode(error) {
@@ -507,9 +512,9 @@ function getManyToManyRelation(schema, model, field) {
507
512
  ];
508
513
  }
509
514
  const modelIdFields = requireIdFields(schema, realModel);
510
- (0, import_common_helpers.invariant)(modelIdFields.length === 1, "Only single-field ID is supported for many-to-many relation");
515
+ (0, import_common_helpers2.invariant)(modelIdFields.length === 1, "Only single-field ID is supported for many-to-many relation");
511
516
  const otherIdFields = requireIdFields(schema, fieldDef.type);
512
- (0, import_common_helpers.invariant)(otherIdFields.length === 1, "Only single-field ID is supported for many-to-many relation");
517
+ (0, import_common_helpers2.invariant)(otherIdFields.length === 1, "Only single-field ID is supported for many-to-many relation");
513
518
  return {
514
519
  parentFkName: orderedFK[0],
515
520
  parentPKName: modelIdFields[0],
@@ -651,7 +656,7 @@ __name(tmpAlias, "tmpAlias");
651
656
 
652
657
  // src/client/crud/operations/base.ts
653
658
  var import_cuid2 = require("@paralleldrive/cuid2");
654
- var import_common_helpers7 = require("@zenstackhq/common-helpers");
659
+ var import_common_helpers8 = require("@zenstackhq/common-helpers");
655
660
  var import_cuid = __toESM(require("cuid"), 1);
656
661
  var import_kysely6 = require("kysely");
657
662
  var import_nanoid = require("nanoid");
@@ -741,7 +746,7 @@ var CRUD_EXT = [
741
746
  var import_ts_pattern3 = require("ts-pattern");
742
747
 
743
748
  // src/client/crud/dialects/mysql.ts
744
- var import_common_helpers4 = require("@zenstackhq/common-helpers");
749
+ var import_common_helpers5 = require("@zenstackhq/common-helpers");
745
750
  var import_decimal = __toESM(require("decimal.js"), 1);
746
751
  var import_kysely3 = require("kysely");
747
752
 
@@ -772,10 +777,10 @@ var AnyNullClass = class {
772
777
  var AnyNull = new AnyNullClass();
773
778
 
774
779
  // src/client/crud/dialects/lateral-join-dialect-base.ts
775
- var import_common_helpers3 = require("@zenstackhq/common-helpers");
780
+ var import_common_helpers4 = require("@zenstackhq/common-helpers");
776
781
 
777
782
  // src/client/crud/dialects/base-dialect.ts
778
- var import_common_helpers2 = require("@zenstackhq/common-helpers");
783
+ var import_common_helpers3 = require("@zenstackhq/common-helpers");
779
784
  var import_kysely2 = require("kysely");
780
785
  var import_ts_pattern2 = require("ts-pattern");
781
786
  var BaseCrudDialect = class {
@@ -903,7 +908,31 @@ var BaseCrudDialect = class {
903
908
  return LOGICAL_COMBINATORS.includes(key);
904
909
  }
905
910
  buildCompositeFilter(model, modelAlias, key, payload) {
906
- return (0, import_ts_pattern2.match)(key).with("AND", () => this.and(...(0, import_common_helpers2.enumerate)(payload).map((subPayload) => this.buildFilter(model, modelAlias, subPayload)))).with("OR", () => this.or(...(0, import_common_helpers2.enumerate)(payload).map((subPayload) => this.buildFilter(model, modelAlias, subPayload)))).with("NOT", () => this.eb.not(this.buildCompositeFilter(model, modelAlias, "AND", payload))).exhaustive();
911
+ const normalizedPayload = (0, import_common_helpers3.enumerate)(payload).filter((el) => {
912
+ if (typeof el === "object" && el !== null && !Array.isArray(el)) {
913
+ const entries = Object.entries(el);
914
+ return entries.some(([, v]) => v !== void 0);
915
+ } else {
916
+ return true;
917
+ }
918
+ });
919
+ const normalizedFilters = normalizedPayload.map((el) => this.buildFilter(model, modelAlias, el));
920
+ return (0, import_ts_pattern2.match)(key).with("AND", () => {
921
+ if (normalizedFilters.length === 0) {
922
+ return this.true();
923
+ }
924
+ return this.and(...normalizedFilters);
925
+ }).with("OR", () => {
926
+ if (normalizedFilters.length === 0) {
927
+ return this.false();
928
+ }
929
+ return this.or(...normalizedFilters);
930
+ }).with("NOT", () => {
931
+ if (normalizedFilters.length === 0) {
932
+ return this.true();
933
+ }
934
+ return this.not(...normalizedFilters);
935
+ }).exhaustive();
907
936
  }
908
937
  buildRelationFilter(model, modelAlias, field, fieldDef, payload) {
909
938
  if (!fieldDef.array) {
@@ -970,9 +999,9 @@ var BaseCrudDialect = class {
970
999
  const m2m = getManyToManyRelation(this.schema, model, field);
971
1000
  if (m2m) {
972
1001
  const modelIdFields = requireIdFields(this.schema, model);
973
- (0, import_common_helpers2.invariant)(modelIdFields.length === 1, "many-to-many relation must have exactly one id field");
1002
+ (0, import_common_helpers3.invariant)(modelIdFields.length === 1, "many-to-many relation must have exactly one id field");
974
1003
  const relationIdFields = requireIdFields(this.schema, relationModel);
975
- (0, import_common_helpers2.invariant)(relationIdFields.length === 1, "many-to-many relation must have exactly one id field");
1004
+ (0, import_common_helpers3.invariant)(relationIdFields.length === 1, "many-to-many relation must have exactly one id field");
976
1005
  return eb(this.eb.ref(`${relationFilterSelectAlias}.${relationIdFields[0]}`), "in", eb.selectFrom(m2m.joinTable).select(`${m2m.joinTable}.${m2m.otherFkName}`).whereRef(this.eb.ref(`${m2m.joinTable}.${m2m.parentFkName}`), "=", this.eb.ref(`${modelAlias}.${modelIdFields[0]}`)));
977
1006
  } else {
978
1007
  const relationKeyPairs = getRelationForeignKeyFieldPairs(this.schema, model, field);
@@ -1021,14 +1050,14 @@ var BaseCrudDialect = class {
1021
1050
  if (_value === void 0) {
1022
1051
  continue;
1023
1052
  }
1024
- (0, import_common_helpers2.invariant)(fieldDef.array, "Field must be an array type to build array filter");
1053
+ (0, import_common_helpers3.invariant)(fieldDef.array, "Field must be an array type to build array filter");
1025
1054
  const value = this.transformInput(_value, fieldType, true);
1026
1055
  let receiver = fieldRef;
1027
1056
  if (isEnum(this.schema, fieldType)) {
1028
1057
  receiver = this.eb.cast(fieldRef, import_kysely2.sql.raw("text[]"));
1029
1058
  }
1030
1059
  const buildArray = /* @__PURE__ */ __name((value2) => {
1031
- (0, import_common_helpers2.invariant)(Array.isArray(value2), "Array filter value must be an array");
1060
+ (0, import_common_helpers3.invariant)(Array.isArray(value2), "Array filter value must be an array");
1032
1061
  return this.buildArrayValue(value2.map((v) => this.eb.val(v)), fieldType);
1033
1062
  }, "buildArray");
1034
1063
  switch (key) {
@@ -1074,7 +1103,7 @@ var BaseCrudDialect = class {
1074
1103
  }).exhaustive();
1075
1104
  }
1076
1105
  buildJsonFilter(receiver, filter, fieldDef) {
1077
- (0, import_common_helpers2.invariant)(filter && typeof filter === "object", "Json filter payload must be an object");
1106
+ (0, import_common_helpers3.invariant)(filter && typeof filter === "object", "Json filter payload must be an object");
1078
1107
  if ([
1079
1108
  "path",
1080
1109
  "equals",
@@ -1099,7 +1128,7 @@ var BaseCrudDialect = class {
1099
1128
  const jsonReceiver = this.buildJsonPathSelection(receiver, path);
1100
1129
  const stringReceiver = this.castText(jsonReceiver);
1101
1130
  const mode = filter.mode ?? "default";
1102
- (0, import_common_helpers2.invariant)(mode === "default" || mode === "insensitive", "Invalid JSON filter mode");
1131
+ (0, import_common_helpers3.invariant)(mode === "default" || mode === "insensitive", "Invalid JSON filter mode");
1103
1132
  for (const [key, value] of Object.entries(filter)) {
1104
1133
  switch (key) {
1105
1134
  case "equals": {
@@ -1111,17 +1140,17 @@ var BaseCrudDialect = class {
1111
1140
  break;
1112
1141
  }
1113
1142
  case "string_contains": {
1114
- (0, import_common_helpers2.invariant)(typeof value === "string", "string_contains value must be a string");
1143
+ (0, import_common_helpers3.invariant)(typeof value === "string", "string_contains value must be a string");
1115
1144
  clauses.push(this.buildJsonStringFilter(stringReceiver, key, value, mode));
1116
1145
  break;
1117
1146
  }
1118
1147
  case "string_starts_with": {
1119
- (0, import_common_helpers2.invariant)(typeof value === "string", "string_starts_with value must be a string");
1148
+ (0, import_common_helpers3.invariant)(typeof value === "string", "string_starts_with value must be a string");
1120
1149
  clauses.push(this.buildJsonStringFilter(stringReceiver, key, value, mode));
1121
1150
  break;
1122
1151
  }
1123
1152
  case "string_ends_with": {
1124
- (0, import_common_helpers2.invariant)(typeof value === "string", "string_ends_with value must be a string");
1153
+ (0, import_common_helpers3.invariant)(typeof value === "string", "string_ends_with value must be a string");
1125
1154
  clauses.push(this.buildJsonStringFilter(stringReceiver, key, value, mode));
1126
1155
  break;
1127
1156
  }
@@ -1154,7 +1183,7 @@ var BaseCrudDialect = class {
1154
1183
  }
1155
1184
  }
1156
1185
  buildTypedJsonArrayFilter(receiver, filter, typeDefName) {
1157
- (0, import_common_helpers2.invariant)(filter && typeof filter === "object", "Typed JSON array filter payload must be an object");
1186
+ (0, import_common_helpers3.invariant)(filter && typeof filter === "object", "Typed JSON array filter payload must be an object");
1158
1187
  const makeExistsPred = /* @__PURE__ */ __name((filter2) => this.buildJsonArrayExistsPredicate(receiver, (elem) => this.buildTypedJsonFilter(elem, filter2, typeDefName, false)), "makeExistsPred");
1159
1188
  const makeExistsNegatedPred = /* @__PURE__ */ __name((filter2) => this.buildJsonArrayExistsPredicate(receiver, (elem) => this.eb.not(this.buildTypedJsonFilter(elem, filter2, typeDefName, false))), "makeExistsNegatedPred");
1160
1189
  const clauses = [];
@@ -1173,7 +1202,7 @@ var BaseCrudDialect = class {
1173
1202
  clauses.push(this.eb.not(makeExistsNegatedPred(value)));
1174
1203
  break;
1175
1204
  default:
1176
- (0, import_common_helpers2.invariant)(false, `Invalid typed JSON array filter key: ${key}`);
1205
+ (0, import_common_helpers3.invariant)(false, `Invalid typed JSON array filter key: ${key}`);
1177
1206
  }
1178
1207
  }
1179
1208
  return this.and(...clauses);
@@ -1183,7 +1212,7 @@ var BaseCrudDialect = class {
1183
1212
  if (filter === null) {
1184
1213
  return this.eb(receiver, "=", this.transformInput(null, "Json", false));
1185
1214
  }
1186
- (0, import_common_helpers2.invariant)(filter && typeof filter === "object", "Typed JSON filter payload must be an object");
1215
+ (0, import_common_helpers3.invariant)(filter && typeof filter === "object", "Typed JSON filter payload must be an object");
1187
1216
  if ("is" in filter || "isNot" in filter) {
1188
1217
  if ("is" in filter && filter.is && typeof filter.is === "object") {
1189
1218
  clauses.push(this.buildTypedJsonFilter(receiver, filter.is, typeDefName, false));
@@ -1195,7 +1224,7 @@ var BaseCrudDialect = class {
1195
1224
  const typeDef = requireTypeDef(this.schema, typeDefName);
1196
1225
  for (const [key, value] of Object.entries(filter)) {
1197
1226
  const fieldDef = typeDef.fields[key];
1198
- (0, import_common_helpers2.invariant)(fieldDef, `Field "${key}" not found in type definition "${typeDefName}"`);
1227
+ (0, import_common_helpers3.invariant)(fieldDef, `Field "${key}" not found in type definition "${typeDefName}"`);
1199
1228
  const fieldReceiver = this.buildJsonPathSelection(receiver, `$.${key}`);
1200
1229
  if (isTypeDef(this.schema, fieldDef.type)) {
1201
1230
  clauses.push(this.buildTypedJsonFilter(fieldReceiver, value, fieldDef.type, !!fieldDef.array));
@@ -1244,7 +1273,7 @@ var BaseCrudDialect = class {
1244
1273
  return this.eb(lhs, "=", this.transformInput(rhs, type, false));
1245
1274
  }
1246
1275
  buildStandardFilter(type, payload, lhs, getRhs, recurse, throwIfInvalid = false, onlyForKeys = void 0, excludeKeys = []) {
1247
- if (payload === null || !(0, import_common_helpers2.isPlainObject)(payload)) {
1276
+ if (payload === null || !(0, import_common_helpers3.isPlainObject)(payload)) {
1248
1277
  return {
1249
1278
  conditions: [
1250
1279
  this.buildValueFilter(lhs, type, payload)
@@ -1261,24 +1290,27 @@ var BaseCrudDialect = class {
1261
1290
  if (excludeKeys.includes(op)) {
1262
1291
  continue;
1263
1292
  }
1293
+ if (value === void 0) {
1294
+ continue;
1295
+ }
1264
1296
  const rhs = Array.isArray(value) ? value.map(getRhs) : getRhs(value);
1265
1297
  const condition = (0, import_ts_pattern2.match)(op).with("equals", () => rhs === null ? this.eb(lhs, "is", null) : this.eb(lhs, "=", rhs)).with("in", () => {
1266
- (0, import_common_helpers2.invariant)(Array.isArray(rhs), "right hand side must be an array");
1298
+ (0, import_common_helpers3.invariant)(Array.isArray(rhs), "right hand side must be an array");
1267
1299
  if (rhs.length === 0) {
1268
1300
  return this.false();
1269
1301
  } else {
1270
1302
  return this.eb(lhs, "in", rhs);
1271
1303
  }
1272
1304
  }).with("notIn", () => {
1273
- (0, import_common_helpers2.invariant)(Array.isArray(rhs), "right hand side must be an array");
1305
+ (0, import_common_helpers3.invariant)(Array.isArray(rhs), "right hand side must be an array");
1274
1306
  if (rhs.length === 0) {
1275
1307
  return this.true();
1276
1308
  } else {
1277
1309
  return this.eb.not(this.eb(lhs, "in", rhs));
1278
1310
  }
1279
1311
  }).with("lt", () => this.eb(lhs, "<", rhs)).with("lte", () => this.eb(lhs, "<=", rhs)).with("gt", () => this.eb(lhs, ">", rhs)).with("gte", () => this.eb(lhs, ">=", rhs)).with("between", () => {
1280
- (0, import_common_helpers2.invariant)(Array.isArray(rhs), "right hand side must be an array");
1281
- (0, import_common_helpers2.invariant)(rhs.length === 2, "right hand side must have a length of 2");
1312
+ (0, import_common_helpers3.invariant)(Array.isArray(rhs), "right hand side must be an array");
1313
+ (0, import_common_helpers3.invariant)(rhs.length === 2, "right hand side must have a length of 2");
1282
1314
  const [start, end] = rhs;
1283
1315
  return this.eb.and([
1284
1316
  this.eb(lhs, ">=", start),
@@ -1318,7 +1350,10 @@ var BaseCrudDialect = class {
1318
1350
  if (key === "mode" || consumedKeys.includes(key)) {
1319
1351
  continue;
1320
1352
  }
1321
- (0, import_common_helpers2.invariant)(typeof value === "string", `${key} value must be a string`);
1353
+ if (value === void 0) {
1354
+ continue;
1355
+ }
1356
+ (0, import_common_helpers3.invariant)(typeof value === "string", `${key} value must be a string`);
1322
1357
  const escapedValue = this.escapeLikePattern(value);
1323
1358
  const condition = (0, import_ts_pattern2.match)(key).with("contains", () => this.buildStringLike(fieldRef, `%${escapedValue}%`, mode === "insensitive")).with("startsWith", () => this.buildStringLike(fieldRef, `${escapedValue}%`, mode === "insensitive")).with("endsWith", () => this.buildStringLike(fieldRef, `%${escapedValue}`, mode === "insensitive")).otherwise(() => {
1324
1359
  throw createInvalidInputError(`Invalid string filter key: ${key}`);
@@ -1399,7 +1434,7 @@ var BaseCrudDialect = class {
1399
1434
  const fieldDef = requireField(this.schema, model2, field);
1400
1435
  return fieldDef.originModel ? this.fieldRef(fieldDef.originModel, field, fieldDef.originModel) : this.fieldRef(model2, field, modelAlias2);
1401
1436
  }, "buildFieldRef");
1402
- (0, import_common_helpers2.enumerate)(orderBy).forEach((orderBy2, index) => {
1437
+ (0, import_common_helpers3.enumerate)(orderBy).forEach((orderBy2, index) => {
1403
1438
  for (const [field, value] of Object.entries(orderBy2)) {
1404
1439
  if (!value) {
1405
1440
  continue;
@@ -1411,9 +1446,9 @@ var BaseCrudDialect = class {
1411
1446
  "_min",
1412
1447
  "_max"
1413
1448
  ].includes(field)) {
1414
- (0, import_common_helpers2.invariant)(typeof value === "object", `invalid orderBy value for field "${field}"`);
1449
+ (0, import_common_helpers3.invariant)(typeof value === "object", `invalid orderBy value for field "${field}"`);
1415
1450
  for (const [k, v] of Object.entries(value)) {
1416
- (0, import_common_helpers2.invariant)(v === "asc" || v === "desc", `invalid orderBy value for field "${field}"`);
1451
+ (0, import_common_helpers3.invariant)(v === "asc" || v === "desc", `invalid orderBy value for field "${field}"`);
1417
1452
  result = result.orderBy((eb) => aggregate(eb, buildFieldRef(model, k, modelAlias), field), this.negateSort(v, negated));
1418
1453
  }
1419
1454
  continue;
@@ -1433,7 +1468,7 @@ var BaseCrudDialect = class {
1433
1468
  throw createInvalidInputError(`invalid orderBy value for field "${field}"`);
1434
1469
  }
1435
1470
  if ("_count" in value) {
1436
- (0, import_common_helpers2.invariant)(value._count === "asc" || value._count === "desc", 'invalid orderBy value for field "_count"');
1471
+ (0, import_common_helpers3.invariant)(value._count === "asc" || value._count === "desc", 'invalid orderBy value for field "_count"');
1437
1472
  const sort = this.negateSort(value._count, negated);
1438
1473
  result = result.orderBy((eb) => {
1439
1474
  const subQueryAlias = tmpAlias(`${modelAlias}$ob$${field}$ct`);
@@ -1490,7 +1525,7 @@ var BaseCrudDialect = class {
1490
1525
  if (omit && typeof omit === "object" && typeof omit[field] === "boolean") {
1491
1526
  return omit[field];
1492
1527
  }
1493
- const uncapModel = (0, import_common_helpers2.lowerCaseFirst)(model);
1528
+ const uncapModel = (0, import_common_helpers3.lowerCaseFirst)(model);
1494
1529
  const omitConfig = this.options.omit?.[uncapModel] ?? this.options.omit?.[model];
1495
1530
  if (omitConfig && typeof omitConfig === "object" && typeof omitConfig[field] === "boolean") {
1496
1531
  return omitConfig[field];
@@ -1612,7 +1647,7 @@ var BaseCrudDialect = class {
1612
1647
  if ("computedFields" in this.options) {
1613
1648
  const computedFields = this.options.computedFields;
1614
1649
  const computedModel = fieldDef.originModel ?? model;
1615
- computer = computedFields?.[(0, import_common_helpers2.lowerCaseFirst)(computedModel)]?.[field] ?? computedFields?.[computedModel]?.[field];
1650
+ computer = computedFields?.[(0, import_common_helpers3.lowerCaseFirst)(computedModel)]?.[field] ?? computedFields?.[computedModel]?.[field];
1616
1651
  }
1617
1652
  if (!computer) {
1618
1653
  throw createConfigError(`Computed field "${field}" implementation not provided for model "${model}"`);
@@ -1691,8 +1726,8 @@ var LateralJoinDialectBase = class extends BaseCrudDialect {
1691
1726
  if (m2m) {
1692
1727
  const parentIds = requireIdFields(this.schema, model);
1693
1728
  const relationIds = requireIdFields(this.schema, relationModel);
1694
- (0, import_common_helpers3.invariant)(parentIds.length === 1, "many-to-many relation must have exactly one id field");
1695
- (0, import_common_helpers3.invariant)(relationIds.length === 1, "many-to-many relation must have exactly one id field");
1729
+ (0, import_common_helpers4.invariant)(parentIds.length === 1, "many-to-many relation must have exactly one id field");
1730
+ (0, import_common_helpers4.invariant)(relationIds.length === 1, "many-to-many relation must have exactly one id field");
1696
1731
  query = query.where((eb) => eb(eb.ref(`${relationModelAlias}.${relationIds[0]}`), "in", eb.selectFrom(m2m.joinTable).select(`${m2m.joinTable}.${m2m.otherFkName}`).whereRef(`${parentAlias}.${parentIds[0]}`, "=", `${m2m.joinTable}.${m2m.parentFkName}`)));
1697
1732
  } else {
1698
1733
  const joinPairs = buildJoinPairs(this.schema, model, parentAlias, relationField, relationModelAlias);
@@ -1846,7 +1881,7 @@ var MySqlCrudDialect = class extends LateralJoinDialectBase {
1846
1881
  } else if (value instanceof DbNullClass) {
1847
1882
  return null;
1848
1883
  } else if (value instanceof AnyNullClass) {
1849
- (0, import_common_helpers4.invariant)(false, "should not reach here: AnyNull is not a valid input value");
1884
+ (0, import_common_helpers5.invariant)(false, "should not reach here: AnyNull is not a valid input value");
1850
1885
  }
1851
1886
  if (isTypeDef(this.schema, type)) {
1852
1887
  if (typeof value !== "string") {
@@ -1909,14 +1944,14 @@ var MySqlCrudDialect = class extends LateralJoinDialectBase {
1909
1944
  if (typeof value === "bigint") {
1910
1945
  return value;
1911
1946
  }
1912
- (0, import_common_helpers4.invariant)(typeof value === "string" || typeof value === "number", `Expected string or number, got ${typeof value}`);
1947
+ (0, import_common_helpers5.invariant)(typeof value === "string" || typeof value === "number", `Expected string or number, got ${typeof value}`);
1913
1948
  return BigInt(value);
1914
1949
  }
1915
1950
  transformDecimal(value) {
1916
1951
  if (value instanceof import_decimal.default) {
1917
1952
  return value;
1918
1953
  }
1919
- (0, import_common_helpers4.invariant)(typeof value === "string" || typeof value === "number" || value instanceof import_decimal.default, `Expected string, number or Decimal, got ${typeof value}`);
1954
+ (0, import_common_helpers5.invariant)(typeof value === "string" || typeof value === "number" || value instanceof import_decimal.default, `Expected string, number or Decimal, got ${typeof value}`);
1920
1955
  return new import_decimal.default(value);
1921
1956
  }
1922
1957
  transformOutputDate(value) {
@@ -2063,7 +2098,7 @@ var MySqlCrudDialect = class extends LateralJoinDialectBase {
2063
2098
  };
2064
2099
 
2065
2100
  // src/client/crud/dialects/postgresql.ts
2066
- var import_common_helpers5 = require("@zenstackhq/common-helpers");
2101
+ var import_common_helpers6 = require("@zenstackhq/common-helpers");
2067
2102
  var import_decimal2 = __toESM(require("decimal.js"), 1);
2068
2103
  var import_kysely4 = require("kysely");
2069
2104
  var import_postgres_array = require("postgres-array");
@@ -2183,7 +2218,7 @@ var PostgresCrudDialect = class _PostgresCrudDialect extends LateralJoinDialectB
2183
2218
  } else if (value instanceof DbNullClass) {
2184
2219
  return null;
2185
2220
  } else if (value instanceof AnyNullClass) {
2186
- (0, import_common_helpers5.invariant)(false, "should not reach here: AnyNull is not a valid input value");
2221
+ (0, import_common_helpers6.invariant)(false, "should not reach here: AnyNull is not a valid input value");
2187
2222
  }
2188
2223
  if (isTypeDef(this.schema, type)) {
2189
2224
  if (typeof value !== "string") {
@@ -2239,14 +2274,14 @@ var PostgresCrudDialect = class _PostgresCrudDialect extends LateralJoinDialectB
2239
2274
  if (typeof value === "bigint") {
2240
2275
  return value;
2241
2276
  }
2242
- (0, import_common_helpers5.invariant)(typeof value === "string" || typeof value === "number", `Expected string or number, got ${typeof value}`);
2277
+ (0, import_common_helpers6.invariant)(typeof value === "string" || typeof value === "number", `Expected string or number, got ${typeof value}`);
2243
2278
  return BigInt(value);
2244
2279
  }
2245
2280
  transformDecimal(value) {
2246
2281
  if (value instanceof import_decimal2.default) {
2247
2282
  return value;
2248
2283
  }
2249
- (0, import_common_helpers5.invariant)(typeof value === "string" || typeof value === "number" || value instanceof import_decimal2.default, `Expected string, number or Decimal, got ${typeof value}`);
2284
+ (0, import_common_helpers6.invariant)(typeof value === "string" || typeof value === "number" || value instanceof import_decimal2.default, `Expected string, number or Decimal, got ${typeof value}`);
2250
2285
  return new import_decimal2.default(value);
2251
2286
  }
2252
2287
  transformOutputDate(value) {
@@ -2459,7 +2494,7 @@ var PostgresCrudDialect = class _PostgresCrudDialect extends LateralJoinDialectB
2459
2494
  };
2460
2495
 
2461
2496
  // src/client/crud/dialects/sqlite.ts
2462
- var import_common_helpers6 = require("@zenstackhq/common-helpers");
2497
+ var import_common_helpers7 = require("@zenstackhq/common-helpers");
2463
2498
  var import_decimal3 = __toESM(require("decimal.js"), 1);
2464
2499
  var import_kysely5 = require("kysely");
2465
2500
  var SqliteCrudDialect = class extends BaseCrudDialect {
@@ -2502,7 +2537,7 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
2502
2537
  } else if (value instanceof DbNullClass) {
2503
2538
  return null;
2504
2539
  } else if (value instanceof AnyNullClass) {
2505
- (0, import_common_helpers6.invariant)(false, "should not reach here: AnyNull is not a valid input value");
2540
+ (0, import_common_helpers7.invariant)(false, "should not reach here: AnyNull is not a valid input value");
2506
2541
  }
2507
2542
  if (type === "Json" || this.schema.typeDefs && type in this.schema.typeDefs) {
2508
2543
  return JSON.stringify(value);
@@ -2552,14 +2587,14 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
2552
2587
  if (value instanceof import_decimal3.default) {
2553
2588
  return value;
2554
2589
  }
2555
- (0, import_common_helpers6.invariant)(typeof value === "string" || typeof value === "number" || value instanceof import_decimal3.default, `Expected string, number or Decimal, got ${typeof value}`);
2590
+ (0, import_common_helpers7.invariant)(typeof value === "string" || typeof value === "number" || value instanceof import_decimal3.default, `Expected string, number or Decimal, got ${typeof value}`);
2556
2591
  return new import_decimal3.default(value);
2557
2592
  }
2558
2593
  transformOutputBigInt(value) {
2559
2594
  if (typeof value === "bigint") {
2560
2595
  return value;
2561
2596
  }
2562
- (0, import_common_helpers6.invariant)(typeof value === "string" || typeof value === "number", `Expected string or number, got ${typeof value}`);
2597
+ (0, import_common_helpers7.invariant)(typeof value === "string" || typeof value === "number", `Expected string or number, got ${typeof value}`);
2563
2598
  return BigInt(value);
2564
2599
  }
2565
2600
  transformOutputBoolean(value) {
@@ -2675,8 +2710,8 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
2675
2710
  if (m2m) {
2676
2711
  const parentIds = requireIdFields(this.schema, model);
2677
2712
  const relationIds = requireIdFields(this.schema, relationModel);
2678
- (0, import_common_helpers6.invariant)(parentIds.length === 1, "many-to-many relation must have exactly one id field");
2679
- (0, import_common_helpers6.invariant)(relationIds.length === 1, "many-to-many relation must have exactly one id field");
2713
+ (0, import_common_helpers7.invariant)(parentIds.length === 1, "many-to-many relation must have exactly one id field");
2714
+ (0, import_common_helpers7.invariant)(relationIds.length === 1, "many-to-many relation must have exactly one id field");
2680
2715
  selectModelQuery = selectModelQuery.where((eb) => eb(eb.ref(`${relationModelAlias}.${relationIds[0]}`), "in", eb.selectFrom(m2m.joinTable).select(`${m2m.joinTable}.${m2m.otherFkName}`).whereRef(`${parentAlias}.${parentIds[0]}`, "=", `${m2m.joinTable}.${m2m.parentFkName}`)));
2681
2716
  } else {
2682
2717
  const { keyPairs, ownedByModel } = getRelationForeignKeyFieldPairs(this.schema, model, relationField);
@@ -3109,7 +3144,7 @@ var BaseOperationHandler = class {
3109
3144
  }
3110
3145
  });
3111
3146
  const discriminatorField = getDiscriminatorField(this.schema, model);
3112
- (0, import_common_helpers7.invariant)(discriminatorField, `Base model "${model}" must have a discriminator field`);
3147
+ (0, import_common_helpers8.invariant)(discriminatorField, `Base model "${model}" must have a discriminator field`);
3113
3148
  thisCreateFields[discriminatorField] = forModel;
3114
3149
  const baseEntity = await this.create(kysely, model, thisCreateFields, void 0, true);
3115
3150
  const idValues = extractIdFields(baseEntity, this.schema, model);
@@ -3121,8 +3156,8 @@ var BaseOperationHandler = class {
3121
3156
  }
3122
3157
  async buildFkAssignments(kysely, model, relationField, entity) {
3123
3158
  const parentFkFields = {};
3124
- (0, import_common_helpers7.invariant)(relationField, "parentField must be defined if parentModel is defined");
3125
- (0, import_common_helpers7.invariant)(entity, "parentEntity must be defined if parentModel is defined");
3159
+ (0, import_common_helpers8.invariant)(relationField, "parentField must be defined if parentModel is defined");
3160
+ (0, import_common_helpers8.invariant)(entity, "parentEntity must be defined if parentModel is defined");
3126
3161
  const { keyPairs } = getRelationForeignKeyFieldPairs(this.schema, model, relationField);
3127
3162
  for (const pair of keyPairs) {
3128
3163
  if (!(pair.pk in entity)) {
@@ -3151,8 +3186,8 @@ var BaseOperationHandler = class {
3151
3186
  const leftFirst = leftModel !== rightModel ? leftModel.localeCompare(rightModel) <= 0 : leftField.localeCompare(rightField) <= 0;
3152
3187
  const leftIdField = requireIdFields(this.schema, leftModel);
3153
3188
  const rightIdField = requireIdFields(this.schema, rightModel);
3154
- (0, import_common_helpers7.invariant)(leftIdField.length === 1, "many-to-many relation must have exactly one id field");
3155
- (0, import_common_helpers7.invariant)(rightIdField.length === 1, "many-to-many relation must have exactly one id field");
3189
+ (0, import_common_helpers8.invariant)(leftIdField.length === 1, "many-to-many relation must have exactly one id field");
3190
+ (0, import_common_helpers8.invariant)(rightIdField.length === 1, "many-to-many relation must have exactly one id field");
3156
3191
  const leftIdValue = leftEntity[leftIdField[0]];
3157
3192
  const rightIdValues = rightEntities.map((e) => e[rightIdField[0]]);
3158
3193
  if (action === "connect") {
@@ -3177,10 +3212,10 @@ var BaseOperationHandler = class {
3177
3212
  }
3178
3213
  }
3179
3214
  resetManyToManyRelation(kysely, model, field, parentIds) {
3180
- (0, import_common_helpers7.invariant)(Object.keys(parentIds).length === 1, "parentIds must have exactly one field");
3215
+ (0, import_common_helpers8.invariant)(Object.keys(parentIds).length === 1, "parentIds must have exactly one field");
3181
3216
  const parentId = Object.values(parentIds)[0];
3182
3217
  const m2m = getManyToManyRelation(this.schema, model, field);
3183
- (0, import_common_helpers7.invariant)(m2m, "not a many-to-many relation");
3218
+ (0, import_common_helpers8.invariant)(m2m, "not a many-to-many relation");
3184
3219
  const eb = (0, import_kysely6.expressionBuilder)();
3185
3220
  return kysely.deleteFrom(m2m.joinTable).where(eb(`${m2m.joinTable}.${m2m.parentFkName}`, "=", parentId)).execute();
3186
3221
  }
@@ -3202,7 +3237,7 @@ var BaseOperationHandler = class {
3202
3237
  }
3203
3238
  case "connect": {
3204
3239
  const referencedPkFields = relationField.relation.references;
3205
- (0, import_common_helpers7.invariant)(referencedPkFields, "relation must have fields info");
3240
+ (0, import_common_helpers8.invariant)(referencedPkFields, "relation must have fields info");
3206
3241
  const extractedFks = extractFields(subPayload, referencedPkFields);
3207
3242
  if (Object.keys(extractedFks).length === referencedPkFields.length) {
3208
3243
  result = extractedFks;
@@ -3249,13 +3284,13 @@ var BaseOperationHandler = class {
3249
3284
  }
3250
3285
  switch (action) {
3251
3286
  case "create": {
3252
- for (const item of (0, import_common_helpers7.enumerate)(subPayload)) {
3287
+ for (const item of (0, import_common_helpers8.enumerate)(subPayload)) {
3253
3288
  await this.create(kysely, relationModel, item, fromRelationContext);
3254
3289
  }
3255
3290
  break;
3256
3291
  }
3257
3292
  case "createMany": {
3258
- (0, import_common_helpers7.invariant)(relationFieldDef.array, "relation must be an array for createMany");
3293
+ (0, import_common_helpers8.invariant)(relationFieldDef.array, "relation must be an array for createMany");
3259
3294
  await this.createMany(kysely, relationModel, subPayload, false, fromRelationContext);
3260
3295
  break;
3261
3296
  }
@@ -3264,7 +3299,7 @@ var BaseOperationHandler = class {
3264
3299
  break;
3265
3300
  }
3266
3301
  case "connectOrCreate": {
3267
- for (const item of (0, import_common_helpers7.enumerate)(subPayload)) {
3302
+ for (const item of (0, import_common_helpers8.enumerate)(subPayload)) {
3268
3303
  const found = await this.exists(kysely, relationModel, item.where);
3269
3304
  if (!found) {
3270
3305
  await this.create(kysely, relationModel, item.create, fromRelationContext);
@@ -3294,11 +3329,11 @@ var BaseOperationHandler = class {
3294
3329
  }
3295
3330
  relationKeyPairs.push(...keyPairs);
3296
3331
  }
3297
- let createData = (0, import_common_helpers7.enumerate)(input.data).map((item) => {
3332
+ let createData = (0, import_common_helpers8.enumerate)(input.data).map((item) => {
3298
3333
  const newItem = {};
3299
3334
  for (const [name, value] of Object.entries(item)) {
3300
3335
  const fieldDef = this.requireField(model, name);
3301
- (0, import_common_helpers7.invariant)(!fieldDef.relation, "createMany does not support relations");
3336
+ (0, import_common_helpers8.invariant)(!fieldDef.relation, "createMany does not support relations");
3302
3337
  newItem[name] = this.dialect.transformInput(value, fieldDef.type, !!fieldDef.array);
3303
3338
  }
3304
3339
  if (fromRelation) {
@@ -3361,7 +3396,7 @@ var BaseOperationHandler = class {
3361
3396
  const thisCreateRows = [];
3362
3397
  const remainingFieldRows = [];
3363
3398
  const discriminatorField = getDiscriminatorField(this.schema, model);
3364
- (0, import_common_helpers7.invariant)(discriminatorField, `Base model "${model}" must have a discriminator field`);
3399
+ (0, import_common_helpers8.invariant)(discriminatorField, `Base model "${model}" must have a discriminator field`);
3365
3400
  for (const createFields of createRows) {
3366
3401
  const thisCreateFields = {};
3367
3402
  const remainingFields = {};
@@ -3400,7 +3435,7 @@ var BaseOperationHandler = class {
3400
3435
  }
3401
3436
  fillGeneratedAndDefaultValues(modelDef, data) {
3402
3437
  const fields = modelDef.fields;
3403
- const values = (0, import_common_helpers7.clone)(data);
3438
+ const values = (0, import_common_helpers8.clone)(data);
3404
3439
  for (const [field, fieldDef] of Object.entries(fields)) {
3405
3440
  if (fieldDef.originModel) {
3406
3441
  continue;
@@ -3472,7 +3507,7 @@ var BaseOperationHandler = class {
3472
3507
  throw createInvalidInputError("data must be an object");
3473
3508
  }
3474
3509
  const parentWhere = await this.buildUpdateParentRelationFilter(kysely, fromRelation);
3475
- let combinedWhere = where ?? {};
3510
+ let combinedWhere = where ?? true;
3476
3511
  if (Object.keys(parentWhere).length > 0) {
3477
3512
  combinedWhere = Object.keys(combinedWhere).length > 0 ? {
3478
3513
  AND: [
@@ -3491,7 +3526,7 @@ var BaseOperationHandler = class {
3491
3526
  const hasNonIgnoredFields = Object.keys(data).some((field) => (isScalarField(this.schema, modelDef.name, field) || isForeignKeyField(this.schema, modelDef.name, field)) && !ignoredFields.has(field));
3492
3527
  if (hasNonIgnoredFields) {
3493
3528
  if (finalData === data) {
3494
- finalData = (0, import_common_helpers7.clone)(data);
3529
+ finalData = (0, import_common_helpers8.clone)(data);
3495
3530
  }
3496
3531
  finalData[fieldName] = this.dialect.transformInput(/* @__PURE__ */ new Date(), "DateTime", false);
3497
3532
  autoUpdatedFields.push(fieldName);
@@ -3594,7 +3629,7 @@ var BaseOperationHandler = class {
3594
3629
  const updatingIdFields = idFields.some((idField) => idField in updateFields);
3595
3630
  if (updatingIdFields) {
3596
3631
  const origIdValues = await loadThisEntity();
3597
- (0, import_common_helpers7.invariant)(origIdValues, "Original entity should have been loaded for update without RETURNING");
3632
+ (0, import_common_helpers8.invariant)(origIdValues, "Original entity should have been loaded for update without RETURNING");
3598
3633
  readFilter = {
3599
3634
  ...origIdValues
3600
3635
  };
@@ -3653,7 +3688,7 @@ var BaseOperationHandler = class {
3653
3688
  }
3654
3689
  } else {
3655
3690
  const fromRelationFieldDef = this.requireField(fromRelation.model, fromRelation.field);
3656
- (0, import_common_helpers7.invariant)(fromRelationFieldDef.relation?.opposite);
3691
+ (0, import_common_helpers8.invariant)(fromRelationFieldDef.relation?.opposite);
3657
3692
  parentWhere[fromRelationFieldDef.relation.opposite] = {
3658
3693
  some: fromRelation.ids
3659
3694
  };
@@ -3704,7 +3739,7 @@ var BaseOperationHandler = class {
3704
3739
  };
3705
3740
  }
3706
3741
  transformIncrementalUpdate(model, field, fieldDef, payload) {
3707
- (0, import_common_helpers7.invariant)(Object.keys(payload).length === 1, 'Only one of "set", "increment", "decrement", "multiply", or "divide" can be provided');
3742
+ (0, import_common_helpers8.invariant)(Object.keys(payload).length === 1, 'Only one of "set", "increment", "decrement", "multiply", or "divide" can be provided');
3708
3743
  const key = Object.keys(payload)[0];
3709
3744
  const value = this.dialect.transformInput(payload[key], fieldDef.type, false);
3710
3745
  const eb = (0, import_kysely6.expressionBuilder)();
@@ -3714,7 +3749,7 @@ var BaseOperationHandler = class {
3714
3749
  });
3715
3750
  }
3716
3751
  transformScalarListUpdate(model, field, fieldDef, payload) {
3717
- (0, import_common_helpers7.invariant)(Object.keys(payload).length === 1, 'Only one of "set", "push" can be provided');
3752
+ (0, import_common_helpers8.invariant)(Object.keys(payload).length === 1, 'Only one of "set", "push" can be provided');
3718
3753
  const key = Object.keys(payload)[0];
3719
3754
  const value = this.dialect.transformInput(payload[key], fieldDef.type, true);
3720
3755
  const eb = (0, import_kysely6.expressionBuilder)();
@@ -3745,7 +3780,7 @@ var BaseOperationHandler = class {
3745
3780
  throw createNotSupportedError("Updating with a limit is not supported for polymorphic models");
3746
3781
  }
3747
3782
  const parentWhere = await this.buildUpdateParentRelationFilter(kysely, fromRelation);
3748
- let combinedWhere = where ?? {};
3783
+ let combinedWhere = where ?? true;
3749
3784
  if (Object.keys(parentWhere).length > 0) {
3750
3785
  combinedWhere = Object.keys(combinedWhere).length > 0 ? {
3751
3786
  AND: [
@@ -3874,14 +3909,14 @@ var BaseOperationHandler = class {
3874
3909
  for (const [key, value] of Object.entries(args)) {
3875
3910
  switch (key) {
3876
3911
  case "create": {
3877
- (0, import_common_helpers7.invariant)(!Array.isArray(value) || fieldDef.array, "relation must be an array if create is an array");
3878
- for (const item of (0, import_common_helpers7.enumerate)(value)) {
3912
+ (0, import_common_helpers8.invariant)(!Array.isArray(value) || fieldDef.array, "relation must be an array if create is an array");
3913
+ for (const item of (0, import_common_helpers8.enumerate)(value)) {
3879
3914
  await this.create(kysely, fieldModel, item, fromRelationContext);
3880
3915
  }
3881
3916
  break;
3882
3917
  }
3883
3918
  case "createMany": {
3884
- (0, import_common_helpers7.invariant)(fieldDef.array, "relation must be an array for createMany");
3919
+ (0, import_common_helpers8.invariant)(fieldDef.array, "relation must be an array for createMany");
3885
3920
  await this.createMany(kysely, fieldModel, value, false, fromRelationContext);
3886
3921
  break;
3887
3922
  }
@@ -3898,12 +3933,12 @@ var BaseOperationHandler = class {
3898
3933
  break;
3899
3934
  }
3900
3935
  case "set": {
3901
- (0, import_common_helpers7.invariant)(fieldDef.array, "relation must be an array");
3936
+ (0, import_common_helpers8.invariant)(fieldDef.array, "relation must be an array");
3902
3937
  await this.setRelation(kysely, fieldModel, value, fromRelationContext);
3903
3938
  break;
3904
3939
  }
3905
3940
  case "update": {
3906
- for (const _item of (0, import_common_helpers7.enumerate)(value)) {
3941
+ for (const _item of (0, import_common_helpers8.enumerate)(value)) {
3907
3942
  const item = _item;
3908
3943
  let where;
3909
3944
  let data;
@@ -3920,7 +3955,7 @@ var BaseOperationHandler = class {
3920
3955
  break;
3921
3956
  }
3922
3957
  case "upsert": {
3923
- for (const _item of (0, import_common_helpers7.enumerate)(value)) {
3958
+ for (const _item of (0, import_common_helpers8.enumerate)(value)) {
3924
3959
  const item = _item;
3925
3960
  const updated = await this.update(kysely, fieldModel, item.where, item.update, fromRelationContext, true, false);
3926
3961
  if (!updated) {
@@ -3930,18 +3965,18 @@ var BaseOperationHandler = class {
3930
3965
  break;
3931
3966
  }
3932
3967
  case "updateMany": {
3933
- for (const _item of (0, import_common_helpers7.enumerate)(value)) {
3968
+ for (const _item of (0, import_common_helpers8.enumerate)(value)) {
3934
3969
  const item = _item;
3935
3970
  await this.updateMany(kysely, fieldModel, item.where, item.data, item.limit, false, fieldModel, fromRelationContext);
3936
3971
  }
3937
3972
  break;
3938
3973
  }
3939
3974
  case "delete": {
3940
- await this.deleteRelation(kysely, fieldModel, value, fromRelationContext, true);
3975
+ await this.deleteRelation(kysely, fieldModel, value, fromRelationContext, true, true);
3941
3976
  break;
3942
3977
  }
3943
3978
  case "deleteMany": {
3944
- await this.deleteRelation(kysely, fieldModel, value, fromRelationContext, false);
3979
+ await this.deleteRelation(kysely, fieldModel, value, fromRelationContext, false, false);
3945
3980
  break;
3946
3981
  }
3947
3982
  default: {
@@ -3967,7 +4002,7 @@ var BaseOperationHandler = class {
3967
4002
  } else {
3968
4003
  const { ownedByModel, keyPairs } = getRelationForeignKeyFieldPairs(this.schema, fromRelation.model, fromRelation.field);
3969
4004
  if (ownedByModel) {
3970
- (0, import_common_helpers7.invariant)(_data.length === 1, "only one entity can be connected");
4005
+ (0, import_common_helpers8.invariant)(_data.length === 1, "only one entity can be connected");
3971
4006
  const target = await this.readUnique(kysely, model, {
3972
4007
  where: _data[0]
3973
4008
  });
@@ -4004,7 +4039,7 @@ var BaseOperationHandler = class {
4004
4039
  }
4005
4040
  }
4006
4041
  async connectOrCreateRelation(kysely, model, data, fromRelation) {
4007
- const _data = (0, import_common_helpers7.enumerate)(data);
4042
+ const _data = (0, import_common_helpers8.enumerate)(data);
4008
4043
  if (_data.length === 0) {
4009
4044
  return;
4010
4045
  }
@@ -4029,6 +4064,10 @@ var BaseOperationHandler = class {
4029
4064
  true
4030
4065
  ];
4031
4066
  }
4067
+ } else if (isEmptyObject(data)) {
4068
+ disconnectConditions = [
4069
+ true
4070
+ ];
4032
4071
  } else {
4033
4072
  disconnectConditions = this.normalizeRelationManipulationInput(model, data);
4034
4073
  if (disconnectConditions.length === 0) {
@@ -4048,7 +4087,7 @@ var BaseOperationHandler = class {
4048
4087
  const { ownedByModel, keyPairs } = getRelationForeignKeyFieldPairs(this.schema, fromRelation.model, fromRelation.field);
4049
4088
  const eb = (0, import_kysely6.expressionBuilder)();
4050
4089
  if (ownedByModel) {
4051
- (0, import_common_helpers7.invariant)(disconnectConditions.length === 1, "only one entity can be disconnected");
4090
+ (0, import_common_helpers8.invariant)(disconnectConditions.length === 1, "only one entity can be disconnected");
4052
4091
  const condition = disconnectConditions[0];
4053
4092
  if (condition === true) {
4054
4093
  for (const { fk } of keyPairs) {
@@ -4151,9 +4190,9 @@ var BaseOperationHandler = class {
4151
4190
  }
4152
4191
  }
4153
4192
  }
4154
- async deleteRelation(kysely, model, data, fromRelation, throwForNotFound) {
4193
+ async deleteRelation(kysely, model, data, fromRelation, uniqueDelete, throwForNotFound) {
4155
4194
  let deleteConditions = [];
4156
- let expectedDeleteCount;
4195
+ let expectedDeleteCount = -1;
4157
4196
  if (typeof data === "boolean") {
4158
4197
  if (data === false) {
4159
4198
  return;
@@ -4161,6 +4200,15 @@ var BaseOperationHandler = class {
4161
4200
  deleteConditions = [
4162
4201
  true
4163
4202
  ];
4203
+ if (uniqueDelete) {
4204
+ expectedDeleteCount = 1;
4205
+ }
4206
+ }
4207
+ } else if (isEmptyObject(data)) {
4208
+ deleteConditions = [
4209
+ true
4210
+ ];
4211
+ if (uniqueDelete) {
4164
4212
  expectedDeleteCount = 1;
4165
4213
  }
4166
4214
  } else {
@@ -4168,7 +4216,9 @@ var BaseOperationHandler = class {
4168
4216
  if (deleteConditions.length === 0) {
4169
4217
  return;
4170
4218
  }
4171
- expectedDeleteCount = deleteConditions.length;
4219
+ if (uniqueDelete) {
4220
+ expectedDeleteCount = deleteConditions.length;
4221
+ }
4172
4222
  }
4173
4223
  let deleteResult;
4174
4224
  let deleteFromModel;
@@ -4176,7 +4226,7 @@ var BaseOperationHandler = class {
4176
4226
  if (m2m) {
4177
4227
  deleteFromModel = model;
4178
4228
  const fieldDef = this.requireField(fromRelation.model, fromRelation.field);
4179
- (0, import_common_helpers7.invariant)(fieldDef.relation?.opposite);
4229
+ (0, import_common_helpers8.invariant)(fieldDef.relation?.opposite);
4180
4230
  deleteResult = await this.delete(kysely, model, {
4181
4231
  AND: [
4182
4232
  {
@@ -4200,7 +4250,7 @@ var BaseOperationHandler = class {
4200
4250
  throw createNotFoundError(fromRelation.model);
4201
4251
  }
4202
4252
  const fieldDef = this.requireField(fromRelation.model, fromRelation.field);
4203
- (0, import_common_helpers7.invariant)(fieldDef.relation?.opposite);
4253
+ (0, import_common_helpers8.invariant)(fieldDef.relation?.opposite);
4204
4254
  deleteResult = await this.delete(kysely, model, {
4205
4255
  AND: [
4206
4256
  // filter for parent
@@ -4228,12 +4278,12 @@ var BaseOperationHandler = class {
4228
4278
  });
4229
4279
  }
4230
4280
  }
4231
- if (throwForNotFound && expectedDeleteCount > (deleteResult.numAffectedRows ?? 0)) {
4281
+ if (throwForNotFound && expectedDeleteCount >= 0 && expectedDeleteCount > (deleteResult.numAffectedRows ?? 0)) {
4232
4282
  throw createNotFoundError(deleteFromModel);
4233
4283
  }
4234
4284
  }
4235
4285
  normalizeRelationManipulationInput(model, data) {
4236
- return (0, import_common_helpers7.enumerate)(data).map((item) => flattenCompoundUniqueFilters(this.schema, model, item));
4286
+ return (0, import_common_helpers8.enumerate)(data).map((item) => flattenCompoundUniqueFilters(this.schema, model, item));
4237
4287
  }
4238
4288
  // #endregion
4239
4289
  async delete(kysely, model, where, limit, filterModel, fieldsToReturn) {
@@ -4354,7 +4404,7 @@ var BaseOperationHandler = class {
4354
4404
  if (!args) {
4355
4405
  return;
4356
4406
  }
4357
- const newArgs = (0, import_common_helpers7.clone)(args);
4407
+ const newArgs = (0, import_common_helpers8.clone)(args);
4358
4408
  this.doNormalizeArgs(newArgs);
4359
4409
  return newArgs;
4360
4410
  }
@@ -4363,7 +4413,7 @@ var BaseOperationHandler = class {
4363
4413
  for (const [key, value] of Object.entries(args)) {
4364
4414
  if (value === void 0) {
4365
4415
  delete args[key];
4366
- } else if (value && (0, import_common_helpers7.isPlainObject)(value)) {
4416
+ } else if (value && (0, import_common_helpers8.isPlainObject)(value)) {
4367
4417
  this.doNormalizeArgs(value);
4368
4418
  }
4369
4419
  }
@@ -4997,11 +5047,11 @@ var UpdateOperationHandler = class extends BaseOperationHandler {
4997
5047
  };
4998
5048
 
4999
5049
  // src/client/crud/validator/validator.ts
5000
- var import_common_helpers9 = require("@zenstackhq/common-helpers");
5050
+ var import_common_helpers10 = require("@zenstackhq/common-helpers");
5001
5051
  var import_ts_pattern11 = require("ts-pattern");
5002
5052
 
5003
5053
  // src/client/zod/factory.ts
5004
- var import_common_helpers8 = require("@zenstackhq/common-helpers");
5054
+ var import_common_helpers9 = require("@zenstackhq/common-helpers");
5005
5055
  var import_zod = require("@zenstackhq/zod");
5006
5056
  var import_decimal4 = __toESM(require("decimal.js"), 1);
5007
5057
  var import_ts_pattern10 = require("ts-pattern");
@@ -5196,12 +5246,12 @@ var ZodSchemaFactory = class {
5196
5246
  }
5197
5247
  makeEnumSchema(_enum) {
5198
5248
  const enumDef = getEnum(this.schema, _enum);
5199
- (0, import_common_helpers8.invariant)(enumDef, `Enum "${_enum}" not found in schema`);
5249
+ (0, import_common_helpers9.invariant)(enumDef, `Enum "${_enum}" not found in schema`);
5200
5250
  return import_zod2.z.enum(Object.keys(enumDef.values));
5201
5251
  }
5202
5252
  makeTypeDefSchema(type) {
5203
5253
  const typeDef = getTypeDef(this.schema, type);
5204
- (0, import_common_helpers8.invariant)(typeDef, `Type definition "${type}" not found in schema`);
5254
+ (0, import_common_helpers9.invariant)(typeDef, `Type definition "${type}" not found in schema`);
5205
5255
  const schema = import_zod2.z.looseObject(Object.fromEntries(Object.entries(typeDef.fields).map(([field, def]) => {
5206
5256
  let fieldSchema = this.makeScalarSchema(def.type);
5207
5257
  if (def.array) {
@@ -5285,7 +5335,7 @@ var ZodSchemaFactory = class {
5285
5335
  for (const uniqueField of uniqueFields) {
5286
5336
  if ("defs" in uniqueField) {
5287
5337
  fields[uniqueField.name] = import_zod2.z.object(Object.fromEntries(Object.entries(uniqueField.defs).map(([key, def]) => {
5288
- (0, import_common_helpers8.invariant)(!def.relation, "unique field cannot be a relation");
5338
+ (0, import_common_helpers9.invariant)(!def.relation, "unique field cannot be a relation");
5289
5339
  let fieldSchema;
5290
5340
  const enumDef = getEnum(this.schema, def.type);
5291
5341
  if (enumDef) {
@@ -5336,7 +5386,7 @@ var ZodSchemaFactory = class {
5336
5386
  const optional = !!fieldInfo.optional;
5337
5387
  const array = !!fieldInfo.array;
5338
5388
  const typeDef = getTypeDef(this.schema, type);
5339
- (0, import_common_helpers8.invariant)(typeDef, `Type definition "${type}" not found in schema`);
5389
+ (0, import_common_helpers9.invariant)(typeDef, `Type definition "${type}" not found in schema`);
5340
5390
  const candidates = [];
5341
5391
  if (!array) {
5342
5392
  const fieldSchemas = {};
@@ -5388,7 +5438,7 @@ var ZodSchemaFactory = class {
5388
5438
  const optional = !!fieldInfo.optional;
5389
5439
  const array = !!fieldInfo.array;
5390
5440
  const enumDef = getEnum(this.schema, enumName);
5391
- (0, import_common_helpers8.invariant)(enumDef, `Enum "${enumName}" not found in schema`);
5441
+ (0, import_common_helpers9.invariant)(enumDef, `Enum "${enumName}" not found in schema`);
5392
5442
  const baseSchema = import_zod2.z.enum(Object.keys(enumDef.values));
5393
5443
  if (array) {
5394
5444
  return this.internalMakeArrayFilterSchema(model, fieldInfo.name, baseSchema);
@@ -5681,7 +5731,7 @@ var ZodSchemaFactory = class {
5681
5731
  for (const plugin of this.plugins) {
5682
5732
  const resultConfig = plugin.result;
5683
5733
  if (resultConfig) {
5684
- const modelConfig = resultConfig[(0, import_common_helpers8.lowerCaseFirst)(model)];
5734
+ const modelConfig = resultConfig[(0, import_common_helpers9.lowerCaseFirst)(model)];
5685
5735
  if (modelConfig) {
5686
5736
  for (const field of Object.keys(modelConfig)) {
5687
5737
  fields[field] = import_zod2.z.boolean().optional();
@@ -6224,7 +6274,7 @@ var ZodSchemaFactory = class {
6224
6274
  });
6225
6275
  let schema = this.mergePluginArgsSchema(baseSchema, "groupBy");
6226
6276
  schema = schema.refine((value) => {
6227
- const bys = (0, import_common_helpers8.enumerate)(value.by);
6277
+ const bys = (0, import_common_helpers9.enumerate)(value.by);
6228
6278
  if (value.having && typeof value.having === "object") {
6229
6279
  for (const [key, val] of Object.entries(value.having)) {
6230
6280
  if (AggregateOperators.includes(key)) {
@@ -6244,8 +6294,8 @@ var ZodSchemaFactory = class {
6244
6294
  return true;
6245
6295
  }, 'fields in "having" must be in "by"');
6246
6296
  schema = schema.refine((value) => {
6247
- const bys = (0, import_common_helpers8.enumerate)(value.by);
6248
- for (const orderBy of (0, import_common_helpers8.enumerate)(value.orderBy)) {
6297
+ const bys = (0, import_common_helpers9.enumerate)(value.by);
6298
+ for (const orderBy of (0, import_common_helpers9.enumerate)(value.orderBy)) {
6249
6299
  if (orderBy && Object.keys(orderBy).filter((f) => !AggregateOperators.includes(f)).some((key) => !bys.includes(key))) {
6250
6300
  return false;
6251
6301
  }
@@ -6260,7 +6310,7 @@ var ZodSchemaFactory = class {
6260
6310
  continue;
6261
6311
  }
6262
6312
  if (LOGICAL_COMBINATORS.includes(key)) {
6263
- if ((0, import_common_helpers8.enumerate)(value).every((v) => this.onlyAggregationFields(v))) {
6313
+ if ((0, import_common_helpers9.enumerate)(value).every((v) => this.onlyAggregationFields(v))) {
6264
6314
  continue;
6265
6315
  }
6266
6316
  }
@@ -6320,8 +6370,8 @@ var ZodSchemaFactory = class {
6320
6370
  const createSchema = "$create" in plugin.queryArgs && plugin.queryArgs["$create"] ? plugin.queryArgs["$create"] : void 0;
6321
6371
  const updateSchema = "$update" in plugin.queryArgs && plugin.queryArgs["$update"] ? plugin.queryArgs["$update"] : void 0;
6322
6372
  if (createSchema && updateSchema) {
6323
- (0, import_common_helpers8.invariant)(createSchema instanceof import_zod2.ZodObject, "Plugin extended query args schema must be a Zod object");
6324
- (0, import_common_helpers8.invariant)(updateSchema instanceof import_zod2.ZodObject, "Plugin extended query args schema must be a Zod object");
6373
+ (0, import_common_helpers9.invariant)(createSchema instanceof import_zod2.ZodObject, "Plugin extended query args schema must be a Zod object");
6374
+ (0, import_common_helpers9.invariant)(updateSchema instanceof import_zod2.ZodObject, "Plugin extended query args schema must be a Zod object");
6325
6375
  result = createSchema.extend(updateSchema.shape);
6326
6376
  } else if (createSchema) {
6327
6377
  result = createSchema;
@@ -6342,7 +6392,7 @@ var ZodSchemaFactory = class {
6342
6392
  } else if ("$all" in plugin.queryArgs && plugin.queryArgs["$all"]) {
6343
6393
  result = plugin.queryArgs["$all"];
6344
6394
  }
6345
- (0, import_common_helpers8.invariant)(result === void 0 || result instanceof import_zod2.ZodObject, "Plugin extended query args schema must be a Zod object");
6395
+ (0, import_common_helpers9.invariant)(result === void 0 || result instanceof import_zod2.ZodObject, "Plugin extended query args schema must be a Zod object");
6346
6396
  return result;
6347
6397
  }
6348
6398
  // #endregion
@@ -6396,7 +6446,7 @@ var ZodSchemaFactory = class {
6396
6446
  return void 0;
6397
6447
  }
6398
6448
  const modelsRecord = slicing.models;
6399
- const modelConfig = modelsRecord[(0, import_common_helpers8.lowerCaseFirst)(model)];
6449
+ const modelConfig = modelsRecord[(0, import_common_helpers9.lowerCaseFirst)(model)];
6400
6450
  if (modelConfig?.fields) {
6401
6451
  const fieldConfig = modelConfig.fields[field];
6402
6452
  if (fieldConfig) {
@@ -7003,7 +7053,7 @@ var InputValidator = class {
7003
7053
  return input;
7004
7054
  }
7005
7055
  const procDef = (this.client.$schema.procedures ?? {})[proc];
7006
- (0, import_common_helpers9.invariant)(procDef, `Procedure "${proc}" not found in schema`);
7056
+ (0, import_common_helpers10.invariant)(procDef, `Procedure "${proc}" not found in schema`);
7007
7057
  const params = Object.values(procDef.params ?? {});
7008
7058
  if (typeof input === "undefined") {
7009
7059
  if (params.length === 0) {
@@ -7264,12 +7314,12 @@ function performanceNow() {
7264
7314
  __name(performanceNow, "performanceNow");
7265
7315
 
7266
7316
  // src/client/executor/zenstack-query-executor.ts
7267
- var import_common_helpers11 = require("@zenstackhq/common-helpers");
7317
+ var import_common_helpers12 = require("@zenstackhq/common-helpers");
7268
7318
  var import_kysely9 = require("kysely");
7269
7319
  var import_ts_pattern12 = require("ts-pattern");
7270
7320
 
7271
7321
  // src/client/executor/name-mapper.ts
7272
- var import_common_helpers10 = require("@zenstackhq/common-helpers");
7322
+ var import_common_helpers11 = require("@zenstackhq/common-helpers");
7273
7323
  var import_kysely7 = require("kysely");
7274
7324
  var QueryNameMapper = class extends import_kysely7.OperationNodeTransformer {
7275
7325
  static {
@@ -7342,7 +7392,7 @@ var QueryNameMapper = class extends import_kysely7.OperationNodeTransformer {
7342
7392
  return super.transformInsertQuery(node, queryId);
7343
7393
  }
7344
7394
  const model = extractModelName(node.into);
7345
- (0, import_common_helpers10.invariant)(model, 'InsertQueryNode must have a model name in the "into" clause');
7395
+ (0, import_common_helpers11.invariant)(model, 'InsertQueryNode must have a model name in the "into" clause');
7346
7396
  return this.withScope({
7347
7397
  model
7348
7398
  }, () => {
@@ -7425,7 +7475,7 @@ var QueryNameMapper = class extends import_kysely7.OperationNodeTransformer {
7425
7475
  return super.transformUpdateQuery(node);
7426
7476
  }
7427
7477
  const model = extractModelName(innerTable);
7428
- (0, import_common_helpers10.invariant)(model, 'UpdateQueryNode must have a model name in the "table" clause');
7478
+ (0, import_common_helpers11.invariant)(model, 'UpdateQueryNode must have a model name in the "table" clause');
7429
7479
  return this.withScope({
7430
7480
  model,
7431
7481
  alias
@@ -7729,7 +7779,7 @@ var QueryNameMapper = class extends import_kysely7.OperationNodeTransformer {
7729
7779
  }
7730
7780
  requireCurrentScope() {
7731
7781
  const scope = this.scopes[this.scopes.length - 1];
7732
- (0, import_common_helpers10.invariant)(scope, "No scope available");
7782
+ (0, import_common_helpers11.invariant)(scope, "No scope available");
7733
7783
  return scope;
7734
7784
  }
7735
7785
  // #endregion
@@ -8196,7 +8246,7 @@ In such cases, ZenStack cannot reliably determine the IDs of the mutated entitie
8196
8246
  for (const valuesItem of values.values) {
8197
8247
  const rowIds = {};
8198
8248
  if (import_kysely9.PrimitiveValueListNode.is(valuesItem)) {
8199
- (0, import_common_helpers11.invariant)(valuesItem.values.length === columns.length, "Values count must match columns count");
8249
+ (0, import_common_helpers12.invariant)(valuesItem.values.length === columns.length, "Values count must match columns count");
8200
8250
  for (const idField of idFields) {
8201
8251
  const colIndex = columns.findIndex((col) => col.column.name === idField);
8202
8252
  if (colIndex === -1) {
@@ -8205,7 +8255,7 @@ In such cases, ZenStack cannot reliably determine the IDs of the mutated entitie
8205
8255
  rowIds[idField] = valuesItem.values[colIndex];
8206
8256
  }
8207
8257
  } else {
8208
- (0, import_common_helpers11.invariant)(valuesItem.values.length === columns.length, "Values count must match columns count");
8258
+ (0, import_common_helpers12.invariant)(valuesItem.values.length === columns.length, "Values count must match columns count");
8209
8259
  for (const idField of idFields) {
8210
8260
  const colIndex = columns.findIndex((col) => col.column.name === idField);
8211
8261
  if (colIndex === -1) {
@@ -8262,17 +8312,17 @@ In such cases, ZenStack cannot reliably determine the IDs of the mutated entitie
8262
8312
  }
8263
8313
  getMutationModel(queryNode) {
8264
8314
  return (0, import_ts_pattern12.match)(queryNode).when(import_kysely9.InsertQueryNode.is, (node) => {
8265
- (0, import_common_helpers11.invariant)(node.into, "InsertQueryNode must have an into clause");
8315
+ (0, import_common_helpers12.invariant)(node.into, "InsertQueryNode must have an into clause");
8266
8316
  return node.into.table.identifier.name;
8267
8317
  }).when(import_kysely9.UpdateQueryNode.is, (node) => {
8268
- (0, import_common_helpers11.invariant)(node.table, "UpdateQueryNode must have a table");
8318
+ (0, import_common_helpers12.invariant)(node.table, "UpdateQueryNode must have a table");
8269
8319
  const { node: tableNode } = stripAlias(node.table);
8270
- (0, import_common_helpers11.invariant)(import_kysely9.TableNode.is(tableNode), "UpdateQueryNode must use a TableNode");
8320
+ (0, import_common_helpers12.invariant)(import_kysely9.TableNode.is(tableNode), "UpdateQueryNode must use a TableNode");
8271
8321
  return tableNode.table.identifier.name;
8272
8322
  }).when(import_kysely9.DeleteQueryNode.is, (node) => {
8273
- (0, import_common_helpers11.invariant)(node.from.froms.length === 1, "Delete query must have exactly one from table");
8323
+ (0, import_common_helpers12.invariant)(node.from.froms.length === 1, "Delete query must have exactly one from table");
8274
8324
  const { node: tableNode } = stripAlias(node.from.froms[0]);
8275
- (0, import_common_helpers11.invariant)(import_kysely9.TableNode.is(tableNode), "DeleteQueryNode must use a TableNode");
8325
+ (0, import_common_helpers12.invariant)(import_kysely9.TableNode.is(tableNode), "DeleteQueryNode must use a TableNode");
8276
8326
  return tableNode.table.identifier.name;
8277
8327
  }).otherwise((node) => {
8278
8328
  throw createInternalError(`Invalid query node: ${node}`);
@@ -8417,7 +8467,7 @@ __export(functions_exports, {
8417
8467
  search: () => search,
8418
8468
  startsWith: () => startsWith
8419
8469
  });
8420
- var import_common_helpers12 = require("@zenstackhq/common-helpers");
8470
+ var import_common_helpers13 = require("@zenstackhq/common-helpers");
8421
8471
  var import_kysely10 = require("kysely");
8422
8472
  var import_ts_pattern13 = require("ts-pattern");
8423
8473
  var contains = /* @__PURE__ */ __name((eb, args, context) => textMatch(eb, args, context, "contains"), "contains");
@@ -8527,8 +8577,8 @@ var currentOperation = /* @__PURE__ */ __name((_eb, args, { operation }) => {
8527
8577
  }, "currentOperation");
8528
8578
  function processCasing(casing, result, model) {
8529
8579
  const opNode = casing.toOperationNode();
8530
- (0, import_common_helpers12.invariant)(import_kysely10.ValueNode.is(opNode) && typeof opNode.value === "string", '"casting" parameter must be a string value');
8531
- result = (0, import_ts_pattern13.match)(opNode.value).with("original", () => model).with("upper", () => result.toUpperCase()).with("lower", () => result.toLowerCase()).with("capitalize", () => (0, import_common_helpers12.upperCaseFirst)(result)).with("uncapitalize", () => (0, import_common_helpers12.lowerCaseFirst)(result)).otherwise(() => {
8580
+ (0, import_common_helpers13.invariant)(import_kysely10.ValueNode.is(opNode) && typeof opNode.value === "string", '"casting" parameter must be a string value');
8581
+ result = (0, import_ts_pattern13.match)(opNode.value).with("original", () => model).with("upper", () => result.toUpperCase()).with("lower", () => result.toLowerCase()).with("capitalize", () => (0, import_common_helpers13.upperCaseFirst)(result)).with("uncapitalize", () => (0, import_common_helpers13.lowerCaseFirst)(result)).otherwise(() => {
8532
8582
  throw new Error(`Invalid casing value: ${opNode.value}. Must be "original", "upper", "lower", "capitalize", or "uncapitalize".`);
8533
8583
  });
8534
8584
  return result;
@@ -8539,13 +8589,13 @@ function readBoolean(expr, defaultValue) {
8539
8589
  return defaultValue;
8540
8590
  }
8541
8591
  const opNode = expr.toOperationNode();
8542
- (0, import_common_helpers12.invariant)(import_kysely10.ValueNode.is(opNode), "expression must be a literal value");
8592
+ (0, import_common_helpers13.invariant)(import_kysely10.ValueNode.is(opNode), "expression must be a literal value");
8543
8593
  return !!opNode.value;
8544
8594
  }
8545
8595
  __name(readBoolean, "readBoolean");
8546
8596
 
8547
8597
  // src/client/helpers/schema-db-pusher.ts
8548
- var import_common_helpers13 = require("@zenstackhq/common-helpers");
8598
+ var import_common_helpers14 = require("@zenstackhq/common-helpers");
8549
8599
  var import_kysely11 = require("kysely");
8550
8600
  var import_toposort = __toESM(require("toposort"), 1);
8551
8601
  var import_ts_pattern14 = require("ts-pattern");
@@ -8571,7 +8621,7 @@ var SchemaDbPusher = class {
8571
8621
  return f.name;
8572
8622
  } else {
8573
8623
  const mappedName = schema_exports.ExpressionUtils.getLiteralValue(mapAttr.args[0].value);
8574
- (0, import_common_helpers13.invariant)(mappedName && typeof mappedName === "string", `Invalid @map attribute for enum field ${f.name}`);
8624
+ (0, import_common_helpers14.invariant)(mappedName && typeof mappedName === "string", `Invalid @map attribute for enum field ${f.name}`);
8575
8625
  return mappedName;
8576
8626
  }
8577
8627
  });
@@ -8698,7 +8748,7 @@ var SchemaDbPusher = class {
8698
8748
  }
8699
8749
  addUniqueConstraint(table, modelDef) {
8700
8750
  for (const [key, value] of Object.entries(modelDef.uniqueFields)) {
8701
- (0, import_common_helpers13.invariant)(typeof value === "object", "expecting an object");
8751
+ (0, import_common_helpers14.invariant)(typeof value === "object", "expecting an object");
8702
8752
  if ("type" in value) {
8703
8753
  const fieldDef = modelDef.fields[key];
8704
8754
  if (fieldDef.unique) {
@@ -8773,7 +8823,7 @@ var SchemaDbPusher = class {
8773
8823
  return f.name;
8774
8824
  } else {
8775
8825
  const mappedName = schema_exports.ExpressionUtils.getLiteralValue(mapAttr.args[0].value);
8776
- (0, import_common_helpers13.invariant)(mappedName && typeof mappedName === "string", `Invalid @map attribute for enum field ${f.name}`);
8826
+ (0, import_common_helpers14.invariant)(mappedName && typeof mappedName === "string", `Invalid @map attribute for enum field ${f.name}`);
8777
8827
  return mappedName;
8778
8828
  }
8779
8829
  });
@@ -8808,7 +8858,7 @@ var SchemaDbPusher = class {
8808
8858
  return fieldDef.default && schema_exports.ExpressionUtils.isCall(fieldDef.default) && fieldDef.default.function === "autoincrement";
8809
8859
  }
8810
8860
  addForeignKeyConstraint(table, model, fieldName, fieldDef) {
8811
- (0, import_common_helpers13.invariant)(fieldDef.relation, "field must be a relation");
8861
+ (0, import_common_helpers14.invariant)(fieldDef.relation, "field must be a relation");
8812
8862
  if (!fieldDef.relation.fields || !fieldDef.relation.references) {
8813
8863
  return table;
8814
8864
  }
@@ -9129,7 +9179,7 @@ var ClientImpl = class _ClientImpl {
9129
9179
  for (const [modelName, modelDef] of Object.entries(this.$schema.models)) {
9130
9180
  if (modelDef.computedFields) {
9131
9181
  for (const fieldName of Object.keys(modelDef.computedFields)) {
9132
- const modelConfig = computedFieldsConfig?.[(0, import_common_helpers14.lowerCaseFirst)(modelName)] ?? computedFieldsConfig?.[modelName];
9182
+ const modelConfig = computedFieldsConfig?.[(0, import_common_helpers15.lowerCaseFirst)(modelName)] ?? computedFieldsConfig?.[modelName];
9133
9183
  const fieldConfig = modelConfig?.[fieldName];
9134
9184
  if (fieldConfig === null || fieldConfig === void 0) {
9135
9185
  throw createConfigError(`Computed field "${fieldName}" in model "${modelName}" does not have a configuration. Please provide an implementation in the computedFields option.`);
@@ -9161,7 +9211,7 @@ var ClientImpl = class _ClientImpl {
9161
9211
  }
9162
9212
  // implementation
9163
9213
  async $transaction(input, options) {
9164
- (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");
9214
+ (0, import_common_helpers15.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");
9165
9215
  if (typeof input === "function") {
9166
9216
  return this.interactiveTransaction(input, options);
9167
9217
  } else {
@@ -9560,7 +9610,7 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
9560
9610
  };
9561
9611
  const slicing = client.$options.slicing;
9562
9612
  if (slicing?.models) {
9563
- const modelSlicing = slicing.models[(0, import_common_helpers14.lowerCaseFirst)(model)];
9613
+ const modelSlicing = slicing.models[(0, import_common_helpers15.lowerCaseFirst)(model)];
9564
9614
  const allSlicing = slicing.models.$all;
9565
9615
  const includedOperations = modelSlicing?.includedOperations ?? allSlicing?.includedOperations;
9566
9616
  const excludedOperations = modelSlicing?.excludedOperations ?? allSlicing?.excludedOperations;
@@ -9611,7 +9661,7 @@ function collectExtResultFieldDefs(model, schema, plugins) {
9611
9661
  for (const plugin of plugins) {
9612
9662
  const resultConfig = plugin.result;
9613
9663
  if (resultConfig) {
9614
- const modelConfig = resultConfig[(0, import_common_helpers14.lowerCaseFirst)(model)];
9664
+ const modelConfig = resultConfig[(0, import_common_helpers15.lowerCaseFirst)(model)];
9615
9665
  if (modelConfig) {
9616
9666
  for (const [fieldName, fieldDef] of Object.entries(modelConfig)) {
9617
9667
  if (getField(schema, model, fieldName)) {