express-file-cluster 0.10.2 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/dist/auth/index.cjs +4 -4
  2. package/dist/auth/index.d.cts +3 -1
  3. package/dist/auth/index.d.ts +3 -1
  4. package/dist/auth/index.js +3 -3
  5. package/dist/{chunk-V73R76I4.js → chunk-2IDRC7RK.js} +2 -1
  6. package/dist/{chunk-RETV3GKE.js → chunk-336IU55W.js} +2 -2
  7. package/dist/{chunk-7BC3AN7R.cjs → chunk-6WTMRZS7.cjs} +8 -8
  8. package/dist/{chunk-7BC3AN7R.cjs.map → chunk-6WTMRZS7.cjs.map} +1 -1
  9. package/dist/chunk-DGYPIIJE.cjs +845 -0
  10. package/dist/chunk-DGYPIIJE.cjs.map +1 -0
  11. package/dist/{chunk-TBIVIR6L.cjs → chunk-DTMDJGRW.cjs} +8 -8
  12. package/dist/{chunk-TBIVIR6L.cjs.map → chunk-DTMDJGRW.cjs.map} +1 -1
  13. package/dist/{chunk-MUVO7MGS.js → chunk-EJDZZ4KX.js} +2 -2
  14. package/dist/{chunk-IUZ6A7PB.cjs → chunk-GWMW6XY7.cjs} +13 -13
  15. package/dist/{chunk-IUZ6A7PB.cjs.map → chunk-GWMW6XY7.cjs.map} +1 -1
  16. package/dist/{chunk-Y4NKIXUL.cjs → chunk-IEF6AEK3.cjs} +13 -13
  17. package/dist/{chunk-Y4NKIXUL.cjs.map → chunk-IEF6AEK3.cjs.map} +1 -1
  18. package/dist/{chunk-BG4A7Z32.js → chunk-JBOMTZT5.js} +3 -3
  19. package/dist/chunk-LECHRAU3.js +845 -0
  20. package/dist/chunk-LECHRAU3.js.map +1 -0
  21. package/dist/{chunk-5LPRKZPB.js → chunk-O2E7H2XA.js} +2 -2
  22. package/dist/{chunk-C2FOZ7ME.js → chunk-OM2XJJWX.js} +2 -2
  23. package/dist/{chunk-JP36TLL4.cjs → chunk-QSIP7YLW.cjs} +3 -2
  24. package/dist/chunk-QSIP7YLW.cjs.map +1 -0
  25. package/dist/{chunk-Y75V5FCU.js → chunk-R6GPQZLI.js} +3 -3
  26. package/dist/{chunk-R2K7AFIB.cjs → chunk-SOU3PBJC.cjs} +89 -89
  27. package/dist/{chunk-R2K7AFIB.cjs.map → chunk-SOU3PBJC.cjs.map} +1 -1
  28. package/dist/{chunk-4GHK27JA.cjs → chunk-WHBSVYUY.cjs} +3 -3
  29. package/dist/{chunk-4GHK27JA.cjs.map → chunk-WHBSVYUY.cjs.map} +1 -1
  30. package/dist/cli/db-runner.cjs +24 -24
  31. package/dist/cli/db-runner.js +3 -3
  32. package/dist/cli/index.cjs +8 -8
  33. package/dist/cli/index.js +5 -5
  34. package/dist/docs/api-reference/ignite.md +4 -0
  35. package/dist/docs/api-reference/openapi.md +36 -0
  36. package/dist/docs/api-reference/testing.md +2 -0
  37. package/dist/docs/api-reference/websockets.md +23 -0
  38. package/dist/docs/cli/add.md +1 -1
  39. package/dist/docs/core-concepts/clustering.md +2 -0
  40. package/dist/docs/core-concepts/file-based-routing.md +2 -0
  41. package/dist/docs/guides/feature-matrix.md +9 -0
  42. package/dist/docs/guides/openapi.md +57 -0
  43. package/dist/docs/guides/validation.md +2 -0
  44. package/dist/docs/guides/websockets.md +60 -0
  45. package/dist/docs/index.md +3 -1
  46. package/dist/docs/skills/SKILL.md +4 -2
  47. package/dist/docs/skills/api-surface.md +10 -0
  48. package/dist/docs/skills/pre-flight.md +2 -0
  49. package/dist/docs/skills/routing-rules.md +4 -0
  50. package/dist/docs/skills/what-not-to-invent.md +2 -0
  51. package/dist/index.cjs +75 -53
  52. package/dist/index.cjs.map +1 -1
  53. package/dist/index.d.cts +3 -2
  54. package/dist/index.d.ts +3 -2
  55. package/dist/index.js +32 -11
  56. package/dist/index.js.map +1 -1
  57. package/dist/openapi-cjs.cjs +5 -0
  58. package/dist/{pgboss-backend-4X2YT4RB.js → pgboss-backend-PQW6I3VF.js} +3 -3
  59. package/dist/pgboss-backend-QVXISTLP.cjs +15 -0
  60. package/dist/{pgboss-backend-UXQ3O2WT.cjs.map → pgboss-backend-QVXISTLP.cjs.map} +1 -1
  61. package/dist/registry/index.json +1 -1
  62. package/dist/tasks/index.d.cts +3 -1
  63. package/dist/tasks/index.d.ts +3 -1
  64. package/dist/testing.cjs +16 -10
  65. package/dist/testing.cjs.map +1 -1
  66. package/dist/testing.d.cts +4 -1
  67. package/dist/testing.d.ts +4 -1
  68. package/dist/testing.js +12 -6
  69. package/dist/testing.js.map +1 -1
  70. package/dist/{types-CPMFTVXm.d.cts → types-D3QmZgeX.d.cts} +80 -2
  71. package/dist/{types-CPMFTVXm.d.ts → types-D3QmZgeX.d.ts} +80 -2
  72. package/package.json +6 -4
  73. package/dist/chunk-74BSJXWD.cjs +0 -220
  74. package/dist/chunk-74BSJXWD.cjs.map +0 -1
  75. package/dist/chunk-JP36TLL4.cjs.map +0 -1
  76. package/dist/chunk-KLWL7XSC.js +0 -220
  77. package/dist/chunk-KLWL7XSC.js.map +0 -1
  78. package/dist/pgboss-backend-UXQ3O2WT.cjs +0 -15
  79. /package/dist/{chunk-V73R76I4.js.map → chunk-2IDRC7RK.js.map} +0 -0
  80. /package/dist/{chunk-RETV3GKE.js.map → chunk-336IU55W.js.map} +0 -0
  81. /package/dist/{chunk-MUVO7MGS.js.map → chunk-EJDZZ4KX.js.map} +0 -0
  82. /package/dist/{chunk-BG4A7Z32.js.map → chunk-JBOMTZT5.js.map} +0 -0
  83. /package/dist/{chunk-5LPRKZPB.js.map → chunk-O2E7H2XA.js.map} +0 -0
  84. /package/dist/{chunk-C2FOZ7ME.js.map → chunk-OM2XJJWX.js.map} +0 -0
  85. /package/dist/{chunk-Y75V5FCU.js.map → chunk-R6GPQZLI.js.map} +0 -0
  86. /package/dist/{pgboss-backend-4X2YT4RB.js.map → pgboss-backend-PQW6I3VF.js.map} +0 -0
@@ -16,7 +16,7 @@
16
16
 
17
17
 
18
18
 
19
- var _chunkIUZ6A7PBcjs = require('./chunk-IUZ6A7PB.cjs');
19
+ var _chunkGWMW6XY7cjs = require('./chunk-GWMW6XY7.cjs');
20
20
 
21
21
 
22
22
 
@@ -29,17 +29,17 @@ var _chunkAGOYTFROcjs = require('./chunk-AGOYTFRO.cjs');
29
29
 
30
30
 
31
31
 
32
- var _chunkJP36TLL4cjs = require('./chunk-JP36TLL4.cjs');
32
+ var _chunkQSIP7YLWcjs = require('./chunk-QSIP7YLW.cjs');
33
33
 
34
34
  // src/db/mongo-model.ts
35
35
  var mongoosePromise;
36
36
  function loadMongoose() {
37
37
  mongoosePromise ??= Promise.resolve().then(() => _interopRequireWildcard(require("mongoose"))).then((mod) => _nullishCoalesce(mod.default, () => ( mod))).then((mg) => {
38
- _chunkJP36TLL4cjs.whenQueryTracking.call(void 0, () => mg.set("debug", _chunkJP36TLL4cjs.countStatement));
38
+ _chunkQSIP7YLWcjs.whenQueryTracking.call(void 0, () => mg.set("debug", _chunkQSIP7YLWcjs.countStatement));
39
39
  return mg;
40
40
  }).catch((err) => {
41
41
  mongoosePromise = void 0;
42
- throw _chunkJP36TLL4cjs.notInstalled.call(void 0, err, "mongoose", "npm install mongoose");
42
+ throw _chunkQSIP7YLWcjs.notInstalled.call(void 0, err, "mongoose", "npm install mongoose");
43
43
  });
44
44
  return mongoosePromise;
45
45
  }
@@ -88,7 +88,7 @@ function rules(node, mg) {
88
88
  if (d.unique !== void 0) entry["unique"] = d.unique;
89
89
  if (d.index !== void 0) entry["index"] = d.index;
90
90
  if (d.default !== void 0)
91
- entry["default"] = _chunkIUZ6A7PBcjs.resolveDefault.call(void 0, d.default, () => new mg.Types.ObjectId());
91
+ entry["default"] = _chunkGWMW6XY7cjs.resolveDefault.call(void 0, d.default, () => new mg.Types.ObjectId());
92
92
  if (d.enum !== void 0) entry["enum"] = d.enum;
93
93
  if (d.min !== void 0) entry["min"] = d.min;
94
94
  if (d.max !== void 0) entry["max"] = d.max;
@@ -162,7 +162,7 @@ function normalise(value) {
162
162
  function translateError(model, err) {
163
163
  const e = err;
164
164
  if (_optionalChain([e, 'optionalAccess', _ => _.name]) === "ValidationError" && e.errors) {
165
- throw new (0, _chunkIUZ6A7PBcjs.ModelValidationError)(
165
+ throw new (0, _chunkGWMW6XY7cjs.ModelValidationError)(
166
166
  model,
167
167
  Object.entries(e.errors).map(([path, v]) => ({
168
168
  path,
@@ -174,7 +174,7 @@ function translateError(model, err) {
174
174
  );
175
175
  }
176
176
  if (_optionalChain([e, 'optionalAccess', _2 => _2.name]) === "CastError") {
177
- throw new (0, _chunkIUZ6A7PBcjs.ModelValidationError)(model, [
177
+ throw new (0, _chunkGWMW6XY7cjs.ModelValidationError)(model, [
178
178
  { path: _nullishCoalesce(e.path, () => ( "")), message: _nullishCoalesce(e.message, () => ( "invalid value")) }
179
179
  ]);
180
180
  }
@@ -206,14 +206,14 @@ function mapSort(sort) {
206
206
  }
207
207
  function mongoModel(name, tree, options) {
208
208
  let compiled;
209
- const model = () => compiled ??= _chunkJP36TLL4cjs.untracked.call(void 0,
209
+ const model = () => compiled ??= _chunkQSIP7YLWcjs.untracked.call(void 0,
210
210
  () => loadMongoose().then(async (mg) => {
211
211
  if (mg.models[name]) return mg.models[name];
212
212
  const schema = new mg.Schema(buildTree(tree, mg), {
213
213
  timestamps: _nullishCoalesce(options.timestamps, () => ( true)),
214
214
  // autoSync: false hands collection and index creation to migrations, on MongoDB too.
215
- autoIndex: _chunkIUZ6A7PBcjs.isAutoSync.call(void 0, ),
216
- autoCreate: _chunkIUZ6A7PBcjs.isAutoSync.call(void 0, ),
215
+ autoIndex: _chunkGWMW6XY7cjs.isAutoSync.call(void 0, ),
216
+ autoCreate: _chunkGWMW6XY7cjs.isAutoSync.call(void 0, ),
217
217
  ...options.collection !== void 0 && { collection: options.collection }
218
218
  });
219
219
  for (const idx of _nullishCoalesce(options.indexes, () => ( []))) {
@@ -228,7 +228,7 @@ function mongoModel(name, tree, options) {
228
228
  }
229
229
  });
230
230
  }
231
- const sequences = _chunkIUZ6A7PBcjs.sequenceFields.call(void 0, name, tree);
231
+ const sequences = _chunkGWMW6XY7cjs.sequenceFields.call(void 0, name, tree);
232
232
  if (sequences.length > 0) {
233
233
  schema.pre("validate", async function() {
234
234
  if (!this.isNew) return;
@@ -238,9 +238,9 @@ function mongoModel(name, tree, options) {
238
238
  });
239
239
  }
240
240
  const M = mg.model(name, schema);
241
- if (_chunkIUZ6A7PBcjs.isAutoSync.call(void 0, )) {
241
+ if (_chunkGWMW6XY7cjs.isAutoSync.call(void 0, )) {
242
242
  await M.init().catch((err) => {
243
- _chunkJP36TLL4cjs.getLogger.call(void 0, ).warn(
243
+ _chunkQSIP7YLWcjs.getLogger.call(void 0, ).warn(
244
244
  { model: name, err: err.message },
245
245
  `${name}: could not build its indexes \u2014 fix the data, then run efc db sync`
246
246
  );
@@ -250,7 +250,7 @@ function mongoModel(name, tree, options) {
250
250
  })
251
251
  );
252
252
  const session = () => {
253
- const tx = _chunkIUZ6A7PBcjs.currentTx.call(void 0, );
253
+ const tx = _chunkGWMW6XY7cjs.currentTx.call(void 0, );
254
254
  return _optionalChain([tx, 'optionalAccess', _5 => _5.engine]) === "mongodb" ? { session: tx.session } : {};
255
255
  };
256
256
  const applyQueryOptions = (q2, opts) => {
@@ -384,7 +384,7 @@ function mongoModel(name, tree, options) {
384
384
  }),
385
385
  raw: () => model(),
386
386
  async sync(opts) {
387
- if (_chunkIUZ6A7PBcjs.isSyncSuppressed.call(void 0, )) return [];
387
+ if (_chunkGWMW6XY7cjs.isSyncSuppressed.call(void 0, )) return [];
388
388
  const M = await model();
389
389
  const changes = [];
390
390
  const exists = (await M.db.db.listCollections({ name: M.collection.collectionName }).toArray()).length > 0;
@@ -482,7 +482,7 @@ async function connectMongo(url, pool = {}) {
482
482
  }).catch((err) => {
483
483
  throw explainMongoError(err, url);
484
484
  });
485
- _chunkJP36TLL4cjs.getLogger.call(void 0, ).info("MongoDB connected");
485
+ _chunkQSIP7YLWcjs.getLogger.call(void 0, ).info("MongoDB connected");
486
486
  return mg.connection;
487
487
  }
488
488
  function explainMongoError(err, url) {
@@ -508,7 +508,7 @@ function explainMongoError(err, url) {
508
508
 
509
509
  // src/db/pg-model.ts
510
510
  function pgModel(name, tree, options) {
511
- const tbl = _chunkIUZ6A7PBcjs.pgTable.call(void 0, name, tree, options, { native: false, api: "defineModel" });
511
+ const tbl = _chunkGWMW6XY7cjs.pgTable.call(void 0, name, tree, options, { native: false, api: "defineModel" });
512
512
  const { columns, ts, refs, ready, compile, client, columnFor, toDb, fromRow, validate, guard } = tbl;
513
513
  const kindOf = (field) => _optionalChain([columns, 'access', _15 => _15.get, 'call', _16 => _16(field), 'optionalAccess', _17 => _17.kind]);
514
514
  function missingField(sql, cond) {
@@ -608,7 +608,7 @@ function pgModel(name, tree, options) {
608
608
  break;
609
609
  }
610
610
  default:
611
- throw new (0, _chunkIUZ6A7PBcjs.ModelValidationError)(name, [
611
+ throw new (0, _chunkGWMW6XY7cjs.ModelValidationError)(name, [
612
612
  { path, message: `operator ${op} is not supported on PostgreSQL` }
613
613
  ]);
614
614
  }
@@ -639,8 +639,8 @@ function pgModel(name, tree, options) {
639
639
  for (const path of Array.isArray(paths) ? paths : [paths]) {
640
640
  const ref = refs.get(path);
641
641
  if (!ref)
642
- throw new (0, _chunkIUZ6A7PBcjs.ModelValidationError)(name, [{ path, message: "is not a populatable ref field" }]);
643
- const target = _chunkIUZ6A7PBcjs.getRegisteredModel.call(void 0, ref.model);
642
+ throw new (0, _chunkGWMW6XY7cjs.ModelValidationError)(name, [{ path, message: "is not a populatable ref field" }]);
643
+ const target = _chunkGWMW6XY7cjs.getRegisteredModel.call(void 0, ref.model);
644
644
  if (!target) throw new Error(`[EFC] populate: model "${ref.model}" is not defined`);
645
645
  const ids = [
646
646
  ...new Set(
@@ -683,7 +683,7 @@ function pgModel(name, tree, options) {
683
683
  return populate(rows, _optionalChain([opts, 'optionalAccess', _22 => _22.populate]));
684
684
  }
685
685
  const strictUpdate = (update) => {
686
- const declared = (path) => columns.has(path.split(".")[0]) && (!path.includes(".") || _chunkIUZ6A7PBcjs.nodeAt.call(void 0, tree, path.split(".")) !== void 0);
686
+ const declared = (path) => columns.has(path.split(".")[0]) && (!path.includes(".") || _chunkGWMW6XY7cjs.nodeAt.call(void 0, tree, path.split(".")) !== void 0);
687
687
  const out = {};
688
688
  for (const [k, v] of Object.entries(update)) {
689
689
  if (k.startsWith("$") && v !== null && typeof v === "object") {
@@ -698,7 +698,7 @@ function pgModel(name, tree, options) {
698
698
  const ops = update;
699
699
  for (const op of Object.keys(update).filter((k) => k.startsWith("$"))) {
700
700
  if (!["$set", "$unset", "$inc", "$push", "$pull"].includes(op)) {
701
- throw new (0, _chunkIUZ6A7PBcjs.ModelValidationError)(name, [
701
+ throw new (0, _chunkGWMW6XY7cjs.ModelValidationError)(name, [
702
702
  { path: op, message: "update operator is not supported on PostgreSQL" }
703
703
  ]);
704
704
  }
@@ -711,25 +711,25 @@ function pgModel(name, tree, options) {
711
711
  for (const [k, v] of Object.entries($set)) if (!k.includes(".")) topLevel[k] = v;
712
712
  for (const k of Object.keys(_nullishCoalesce(ops["$unset"], () => ( {})))) if (!k.includes(".")) topLevel[k] = null;
713
713
  for (const [k, v] of Object.entries($set))
714
- if (k.includes(".")) await _chunkIUZ6A7PBcjs.validateAtPath.call(void 0, tree, k, v, issues);
714
+ if (k.includes(".")) await _chunkGWMW6XY7cjs.validateAtPath.call(void 0, tree, k, v, issues);
715
715
  for (const k of Object.keys(_nullishCoalesce(ops["$unset"], () => ( {})))) {
716
- if (k.includes(".")) await _chunkIUZ6A7PBcjs.validateAtPath.call(void 0, tree, k, null, issues);
716
+ if (k.includes(".")) await _chunkGWMW6XY7cjs.validateAtPath.call(void 0, tree, k, null, issues);
717
717
  }
718
718
  for (const [k, by] of Object.entries(_nullishCoalesce(ops["$inc"], () => ( {})))) {
719
719
  if (typeof by !== "number") issues.push({ path: k, message: "$inc needs a number" });
720
- const node = k.includes(".") ? _chunkIUZ6A7PBcjs.nodeAt.call(void 0, tree, k.split(".")) : tree[k];
720
+ const node = k.includes(".") ? _chunkGWMW6XY7cjs.nodeAt.call(void 0, tree, k.split(".")) : tree[k];
721
721
  if (node && !(node.kind === "scalar" && node.type === "number") && node.kind !== "json") {
722
722
  issues.push({ path: k, message: "$inc only applies to number fields" });
723
723
  }
724
724
  }
725
- if (issues.length) throw new (0, _chunkIUZ6A7PBcjs.ModelValidationError)(name, issues);
725
+ if (issues.length) throw new (0, _chunkGWMW6XY7cjs.ModelValidationError)(name, issues);
726
726
  await validate(topLevel, true);
727
727
  const set = {};
728
728
  const nested = /* @__PURE__ */ new Map();
729
729
  const touchedTop = /* @__PURE__ */ new Set();
730
730
  const acc = (field) => _nullishCoalesce(nested.get(field), () => ( columnFor(t, field)));
731
731
  const conflict = (path) => {
732
- throw new (0, _chunkIUZ6A7PBcjs.ModelValidationError)(name, [{ path, message: "conflicting update paths" }]);
732
+ throw new (0, _chunkGWMW6XY7cjs.ModelValidationError)(name, [{ path, message: "conflicting update paths" }]);
733
733
  };
734
734
  const top = (field, value) => {
735
735
  if (touchedTop.has(field) || nested.has(field)) conflict(field);
@@ -900,7 +900,7 @@ function defineModel(name, schema, options) {
900
900
  return createModel(name, schema, _nullishCoalesce(options, () => ( {})));
901
901
  }
902
902
  function distinctFields(tree, options) {
903
- const ts = _chunkIUZ6A7PBcjs.timestampFields.call(void 0, options);
903
+ const ts = _chunkGWMW6XY7cjs.timestampFields.call(void 0, options);
904
904
  const fields = /* @__PURE__ */ new Set(["id", ...Object.values(ts)]);
905
905
  for (const [key, node] of Object.entries(tree)) if (node.kind === "scalar") fields.add(key);
906
906
  return fields;
@@ -925,11 +925,11 @@ var MODEL_OPS = [
925
925
  ];
926
926
  var sortKey = (v) => v instanceof Date ? v.getTime() : v;
927
927
  function createModel(name, schema, options, native) {
928
- const tree = _chunkIUZ6A7PBcjs.normalizeSchema.call(void 0, schema, "model", name);
928
+ const tree = _chunkGWMW6XY7cjs.normalizeSchema.call(void 0, schema, "model", name);
929
929
  let engineModel;
930
930
  const impl = () => {
931
931
  if (engineModel) return engineModel;
932
- const engine = _chunkIUZ6A7PBcjs.getDbEngine.call(void 0, );
932
+ const engine = _chunkGWMW6XY7cjs.getDbEngine.call(void 0, );
933
933
  if (native && native.engine !== engine) {
934
934
  throw new Error(
935
935
  `[EFC] ${name} is a ${ENGINE_LABEL[native.engine]} ${native.kind} (${native.api}) but the app is connected to ${ENGINE_LABEL[engine]} \u2014 check DATABASE_URL / config.database, or use defineModel for a model that runs on both`
@@ -971,7 +971,7 @@ function createModel(name, schema, options, native) {
971
971
  try {
972
972
  return await m.create(create);
973
973
  } catch (err) {
974
- if (_chunkAGOYTFROcjs.isHttpError.call(void 0, err) && err.statusCode === 409 && !_chunkIUZ6A7PBcjs.currentTx.call(void 0, )) {
974
+ if (_chunkAGOYTFROcjs.isHttpError.call(void 0, err) && err.statusCode === 409 && !_chunkGWMW6XY7cjs.currentTx.call(void 0, )) {
975
975
  const retried = await m.updateOne(filter, update);
976
976
  if (retried) return retried;
977
977
  }
@@ -987,16 +987,16 @@ function createModel(name, schema, options, native) {
987
987
  sync: (opts) => call((m) => m.sync(opts)),
988
988
  drop: () => call((m) => m.drop())
989
989
  };
990
- _chunkJP36TLL4cjs.traceOps.call(void 0, name, model, MODEL_OPS);
991
- _chunkIUZ6A7PBcjs.registerModel.call(void 0, {
990
+ _chunkQSIP7YLWcjs.traceOps.call(void 0, name, model, MODEL_OPS);
991
+ _chunkGWMW6XY7cjs.registerModel.call(void 0, {
992
992
  name,
993
993
  sync: model.sync,
994
994
  plan: (opts) => call((m) => m.plan(opts)),
995
995
  drop: model.drop,
996
996
  findByIds: (ids) => model.find({ id: { $in: ids } }),
997
- pgTarget: () => ({ table: _nullishCoalesce(options.collection, () => ( _chunkIUZ6A7PBcjs.tableNameFor.call(void 0, name))), idKind: "uuid" }),
997
+ pgTarget: () => ({ table: _nullishCoalesce(options.collection, () => ( _chunkGWMW6XY7cjs.tableNameFor.call(void 0, name))), idKind: "uuid" }),
998
998
  studio: {
999
- storage: async () => _chunkIUZ6A7PBcjs.getDbEngine.call(void 0, ) === "mongodb" ? (await model.raw()).collection.collectionName : _nullishCoalesce(options.collection, () => ( _chunkIUZ6A7PBcjs.tableNameFor.call(void 0, name))),
999
+ storage: async () => _chunkGWMW6XY7cjs.getDbEngine.call(void 0, ) === "mongodb" ? (await model.raw()).collection.collectionName : _nullishCoalesce(options.collection, () => ( _chunkGWMW6XY7cjs.tableNameFor.call(void 0, name))),
1000
1000
  create: (data) => model.create(data),
1001
1001
  update: (id, data) => model.update(id, data),
1002
1002
  delete: (id) => model.delete(id)
@@ -1007,12 +1007,12 @@ function createModel(name, schema, options, native) {
1007
1007
 
1008
1008
  // src/db/transaction.ts
1009
1009
  async function transaction(fn) {
1010
- if (_chunkIUZ6A7PBcjs.currentTx.call(void 0, )) return fn();
1011
- if (_chunkIUZ6A7PBcjs.getDbEngine.call(void 0, ) === "postgresql") {
1010
+ if (_chunkGWMW6XY7cjs.currentTx.call(void 0, )) return fn();
1011
+ if (_chunkGWMW6XY7cjs.getDbEngine.call(void 0, ) === "postgresql") {
1012
1012
  let result;
1013
1013
  const afterCommit = [];
1014
- await _chunkJP36TLL4cjs.getOrm.call(void 0, ).transaction(async (tx) => {
1015
- result = await _chunkIUZ6A7PBcjs.runInTx.call(void 0, { engine: "postgresql", tx, afterCommit }, fn);
1014
+ await _chunkQSIP7YLWcjs.getOrm.call(void 0, ).transaction(async (tx) => {
1015
+ result = await _chunkGWMW6XY7cjs.runInTx.call(void 0, { engine: "postgresql", tx, afterCommit }, fn);
1016
1016
  });
1017
1017
  for (const run of afterCommit) run();
1018
1018
  return result;
@@ -1022,7 +1022,7 @@ async function transaction(fn) {
1022
1022
  try {
1023
1023
  let result;
1024
1024
  await session.withTransaction(async () => {
1025
- result = await _chunkIUZ6A7PBcjs.runInTx.call(void 0, { engine: "mongodb", session }, fn);
1025
+ result = await _chunkGWMW6XY7cjs.runInTx.call(void 0, { engine: "mongodb", session }, fn);
1026
1026
  });
1027
1027
  return result;
1028
1028
  } finally {
@@ -1068,8 +1068,8 @@ var TableRuntime = (_class = class {
1068
1068
  constructor(name, schema, options) {;_class.prototype.__init.call(this);
1069
1069
  this.name = name;
1070
1070
  this.options = options;
1071
- const tree = _chunkIUZ6A7PBcjs.normalizeSchema.call(void 0, schema, "table", name);
1072
- this.tbl = _chunkIUZ6A7PBcjs.pgTable.call(void 0, name, tree, options, { native: true, api: "defineTable" });
1071
+ const tree = _chunkGWMW6XY7cjs.normalizeSchema.call(void 0, schema, "table", name);
1072
+ this.tbl = _chunkGWMW6XY7cjs.pgTable.call(void 0, name, tree, options, { native: true, api: "defineTable" });
1073
1073
  this.uniqueSets = [["id"]];
1074
1074
  for (const spec of this.tbl.columns.values()) {
1075
1075
  if (_optionalChain([spec, 'access', _25 => _25.node, 'optionalAccess', _26 => _26.def, 'access', _27 => _27.unique])) this.uniqueSets.push([spec.field]);
@@ -1096,7 +1096,7 @@ var TableRuntime = (_class = class {
1096
1096
  /** Many-to-many fields as list columns, so filters and projections treat them alike. */
1097
1097
  __init() {this.joinSpecs = /* @__PURE__ */ new Map()}
1098
1098
  fail(path, message) {
1099
- throw new (0, _chunkIUZ6A7PBcjs.ModelValidationError)(this.name, [{ path, message }]);
1099
+ throw new (0, _chunkGWMW6XY7cjs.ModelValidationError)(this.name, [{ path, message }]);
1100
1100
  }
1101
1101
  spec(field) {
1102
1102
  return _nullishCoalesce(this.tbl.columns.get(field), () => ( this.joinSpecs.get(field)));
@@ -1107,18 +1107,18 @@ var TableRuntime = (_class = class {
1107
1107
  /** A many-to-many field's ids, in order, for the row `owner` (a table name or alias). */
1108
1108
  joinExpr(sql, join, owner) {
1109
1109
  return sql.raw(
1110
- `coalesce((select array_agg(efc_j.ref_id order by efc_j.position) from ${_chunkIUZ6A7PBcjs.q.call(void 0, join.table)} efc_j where efc_j.owner_id = ${owner}.${_chunkIUZ6A7PBcjs.q.call(void 0, "id")}), '{}'::${join.ddl})`
1110
+ `coalesce((select array_agg(efc_j.ref_id order by efc_j.position) from ${_chunkGWMW6XY7cjs.q.call(void 0, join.table)} efc_j where efc_j.owner_id = ${owner}.${_chunkGWMW6XY7cjs.q.call(void 0, "id")}), '{}'::${join.ddl})`
1111
1111
  );
1112
1112
  }
1113
1113
  col(sql, field, alias) {
1114
1114
  const join = this.join(field);
1115
- if (join) return this.joinExpr(sql, join, _nullishCoalesce(alias, () => ( _chunkIUZ6A7PBcjs.q.call(void 0, this.tbl.table))));
1115
+ if (join) return this.joinExpr(sql, join, _nullishCoalesce(alias, () => ( _chunkGWMW6XY7cjs.q.call(void 0, this.tbl.table))));
1116
1116
  const spec = this.spec(field);
1117
- return sql.raw(alias ? `${alias}.${_chunkIUZ6A7PBcjs.q.call(void 0, spec.column)}` : _chunkIUZ6A7PBcjs.q.call(void 0, spec.column));
1117
+ return sql.raw(alias ? `${alias}.${_chunkGWMW6XY7cjs.q.call(void 0, spec.column)}` : _chunkGWMW6XY7cjs.q.call(void 0, spec.column));
1118
1118
  }
1119
1119
  /** SELECT items for the many-to-many fields among `fields`, as text arrays. */
1120
1120
  joinColumns(sql, fields, owner) {
1121
- return fields.filter((f) => this.join(f)).map((f) => sql`${this.col(sql, f, owner)}::text[] as ${sql.raw(_chunkIUZ6A7PBcjs.q.call(void 0, relAlias(f)))}`);
1121
+ return fields.filter((f) => this.join(f)).map((f) => sql`${this.col(sql, f, owner)}::text[] as ${sql.raw(_chunkGWMW6XY7cjs.q.call(void 0, relAlias(f)))}`);
1122
1122
  }
1123
1123
  /** `col` for SELECT lists: many-to-many fields come back as text arrays under an alias. */
1124
1124
  selectCols(sql, fields, owner) {
@@ -1410,7 +1410,7 @@ var TableRuntime = (_class = class {
1410
1410
  if (args["cursor"]) {
1411
1411
  this.uniqueKey(args["cursor"], "cursor");
1412
1412
  const cw = this.where(sql, t, args["cursor"]);
1413
- const at = (field) => sql`(select ${this.col(sql, field)} from ${sql.raw(_chunkIUZ6A7PBcjs.q.call(void 0, this.tbl.table))} where ${cw})`;
1413
+ const at = (field) => sql`(select ${this.col(sql, field)} from ${sql.raw(_chunkGWMW6XY7cjs.q.call(void 0, this.tbl.table))} where ${cw})`;
1414
1414
  const ors = [];
1415
1415
  const same = (o) => sql`${this.col(sql, o.field)} is not distinct from ${at(o.field)}`;
1416
1416
  for (let i = 0; i < order.length; i++) {
@@ -1423,7 +1423,7 @@ var TableRuntime = (_class = class {
1423
1423
  ors.push(eqs.length ? sql`(${sql.join([...eqs, after], sql` and `)})` : after);
1424
1424
  }
1425
1425
  ors.push(sql`(${sql.join(order.map(same), sql` and `)})`);
1426
- parts.push(sql`exists (select 1 from ${sql.raw(_chunkIUZ6A7PBcjs.q.call(void 0, this.tbl.table))} where ${cw})`);
1426
+ parts.push(sql`exists (select 1 from ${sql.raw(_chunkGWMW6XY7cjs.q.call(void 0, this.tbl.table))} where ${cw})`);
1427
1427
  parts.push(sql`(${sql.join(ors, sql` or `)})`);
1428
1428
  }
1429
1429
  return parts.length ? sql.join(parts, sql` and `) : sql`true`;
@@ -1448,7 +1448,7 @@ var TableRuntime = (_class = class {
1448
1448
  const offset = args["skip"] ? sql` offset ${sql.param(args["skip"])}` : sql``;
1449
1449
  const orderBy = order.length ? sql` order by ${this.orderSql(sql, order)}` : sql``;
1450
1450
  const where = this.readWhere(sql, t, args, order);
1451
- const from = sql.raw(_chunkIUZ6A7PBcjs.q.call(void 0, this.tbl.table));
1451
+ const from = sql.raw(_chunkGWMW6XY7cjs.q.call(void 0, this.tbl.table));
1452
1452
  const distinct = _optionalChain([args, 'access', _29 => _29["distinct"], 'optionalAccess', _30 => _30.filter, 'call', _31 => _31((f) => this.spec(f))]);
1453
1453
  if (_optionalChain([distinct, 'optionalAccess', _32 => _32.length])) {
1454
1454
  const dcols = sql.join(
@@ -1478,7 +1478,7 @@ var TableRuntime = (_class = class {
1478
1478
  distinct ? "efc_distinct" : void 0
1479
1479
  );
1480
1480
  const include = this.includeArg(args);
1481
- const included = include ? await this.includeColumns(sql, include, distinct ? "efc_distinct" : _chunkIUZ6A7PBcjs.q.call(void 0, this.tbl.table), 1) : [];
1481
+ const included = include ? await this.includeColumns(sql, include, distinct ? "efc_distinct" : _chunkGWMW6XY7cjs.q.call(void 0, this.tbl.table), 1) : [];
1482
1482
  const { query, reversed } = this.readQuery(
1483
1483
  sql,
1484
1484
  t,
@@ -1553,7 +1553,7 @@ var TableRuntime = (_class = class {
1553
1553
  for (const [name, arg] of Object.entries(include)) {
1554
1554
  if (!arg) continue;
1555
1555
  const expr = await this.relationExpr(sql, this.relation(name), relArgs(arg), owner, depth);
1556
- out.push(sql`${expr} as ${sql.raw(_chunkIUZ6A7PBcjs.q.call(void 0, incAlias(name)))}`);
1556
+ out.push(sql`${expr} as ${sql.raw(_chunkGWMW6XY7cjs.q.call(void 0, incAlias(name)))}`);
1557
1557
  }
1558
1558
  return out;
1559
1559
  }
@@ -1587,21 +1587,21 @@ var TableRuntime = (_class = class {
1587
1587
  */
1588
1588
  relationSource(rel, owner, a, j) {
1589
1589
  const T = runtimeOf(rel.target, `${this.name}.${rel.name}`);
1590
- const target = `${_chunkIUZ6A7PBcjs.q.call(void 0, T.tbl.table)} ${a}`;
1591
- const ownerId = `${owner}.${_chunkIUZ6A7PBcjs.q.call(void 0, "id")}`;
1590
+ const target = `${_chunkGWMW6XY7cjs.q.call(void 0, T.tbl.table)} ${a}`;
1591
+ const ownerId = `${owner}.${_chunkGWMW6XY7cjs.q.call(void 0, "id")}`;
1592
1592
  if (rel.via === "fk") {
1593
1593
  return {
1594
1594
  T,
1595
1595
  from: target,
1596
- cond: `${a}.${_chunkIUZ6A7PBcjs.q.call(void 0, "id")} = ${owner}.${_chunkIUZ6A7PBcjs.q.call(void 0, rel.column)}`,
1597
- defaultOrder: `${a}.${_chunkIUZ6A7PBcjs.q.call(void 0, "id")}`
1596
+ cond: `${a}.${_chunkGWMW6XY7cjs.q.call(void 0, "id")} = ${owner}.${_chunkGWMW6XY7cjs.q.call(void 0, rel.column)}`,
1597
+ defaultOrder: `${a}.${_chunkGWMW6XY7cjs.q.call(void 0, "id")}`
1598
1598
  };
1599
1599
  }
1600
1600
  let from;
1601
1601
  let cond;
1602
1602
  let defaultOrder;
1603
1603
  if (rel.via === "join") {
1604
- from = `${_chunkIUZ6A7PBcjs.q.call(void 0, rel.join.table)} ${j} join ${target} on ${a}.${_chunkIUZ6A7PBcjs.q.call(void 0, "id")} = ${j}.ref_id`;
1604
+ from = `${_chunkGWMW6XY7cjs.q.call(void 0, rel.join.table)} ${j} join ${target} on ${a}.${_chunkGWMW6XY7cjs.q.call(void 0, "id")} = ${j}.ref_id`;
1605
1605
  cond = `${j}.owner_id = ${ownerId}`;
1606
1606
  defaultOrder = `${j}.position`;
1607
1607
  } else {
@@ -1619,7 +1619,7 @@ var TableRuntime = (_class = class {
1619
1619
  `[EFC] ${this.name}.${rel.name}: ${rel.target}.${rel.foreignKey} is many-to-many \u2014 use hasMany`
1620
1620
  );
1621
1621
  }
1622
- from = `${_chunkIUZ6A7PBcjs.q.call(void 0, join.table)} ${j} join ${target} on ${a}.${_chunkIUZ6A7PBcjs.q.call(void 0, "id")} = ${j}.owner_id`;
1622
+ from = `${_chunkGWMW6XY7cjs.q.call(void 0, join.table)} ${j} join ${target} on ${a}.${_chunkGWMW6XY7cjs.q.call(void 0, "id")} = ${j}.owner_id`;
1623
1623
  cond = `${j}.ref_id = ${ownerId}`;
1624
1624
  } else {
1625
1625
  if (rel.kind === "one" && !column.node.def.unique) {
@@ -1628,9 +1628,9 @@ var TableRuntime = (_class = class {
1628
1628
  );
1629
1629
  }
1630
1630
  from = target;
1631
- cond = `${a}.${_chunkIUZ6A7PBcjs.q.call(void 0, column.column)} = ${ownerId}`;
1631
+ cond = `${a}.${_chunkGWMW6XY7cjs.q.call(void 0, column.column)} = ${ownerId}`;
1632
1632
  }
1633
- defaultOrder = `${a}.${_chunkIUZ6A7PBcjs.q.call(void 0, "id")}`;
1633
+ defaultOrder = `${a}.${_chunkGWMW6XY7cjs.q.call(void 0, "id")}`;
1634
1634
  }
1635
1635
  return { T, from, cond, defaultOrder };
1636
1636
  }
@@ -1655,7 +1655,7 @@ var TableRuntime = (_class = class {
1655
1655
  const where = isPlainObject(w) ? w : { id: w };
1656
1656
  const found = await T.findUnique({ where, select: { id: true } });
1657
1657
  if (!found) {
1658
- throw new (0, _chunkIUZ6A7PBcjs.ModelValidationError)(this.name, [
1658
+ throw new (0, _chunkGWMW6XY7cjs.ModelValidationError)(this.name, [
1659
1659
  { path, message: `no ${rel.target} matches ${JSON.stringify(where, idJson)}` }
1660
1660
  ]);
1661
1661
  }
@@ -1748,7 +1748,7 @@ var TableRuntime = (_class = class {
1748
1748
  await T.updateNested({ where: whereOf(w), data: { [fk]: owner } });
1749
1749
  } catch (err) {
1750
1750
  if (_chunkAGOYTFROcjs.isHttpError.call(void 0, err) && err.statusCode === 404) {
1751
- throw new (0, _chunkIUZ6A7PBcjs.ModelValidationError)(this.name, [
1751
+ throw new (0, _chunkGWMW6XY7cjs.ModelValidationError)(this.name, [
1752
1752
  {
1753
1753
  path: key,
1754
1754
  message: `no ${rel.target} matches ${JSON.stringify(whereOf(w), idJson)}`
@@ -1899,7 +1899,7 @@ var TableRuntime = (_class = class {
1899
1899
  const a = `efc_f${++aliasSeq}`;
1900
1900
  const { T, from, cond } = this.relationSource(
1901
1901
  rel,
1902
- _nullishCoalesce(owner, () => ( _chunkIUZ6A7PBcjs.q.call(void 0, this.tbl.table))),
1902
+ _nullishCoalesce(owner, () => ( _chunkGWMW6XY7cjs.q.call(void 0, this.tbl.table))),
1903
1903
  a,
1904
1904
  `efc_fj${aliasSeq}`
1905
1905
  );
@@ -2050,7 +2050,7 @@ var TableRuntime = (_class = class {
2050
2050
  const counted = select ? Object.entries(select).filter(([f, on]) => on && (f === "_all" || this.spec(f))) : [["_all", true]];
2051
2051
  const exprs = sql.join(
2052
2052
  counted.map(
2053
- ([f]) => f === "_all" ? sql`count(*)::int as ${sql.raw(_chunkIUZ6A7PBcjs.q.call(void 0, "_all"))}` : sql`count(${this.col(sql, f, "efc_rows")})::int as ${sql.raw(_chunkIUZ6A7PBcjs.q.call(void 0, f))}`
2053
+ ([f]) => f === "_all" ? sql`count(*)::int as ${sql.raw(_chunkGWMW6XY7cjs.q.call(void 0, "_all"))}` : sql`count(${this.col(sql, f, "efc_rows")})::int as ${sql.raw(_chunkGWMW6XY7cjs.q.call(void 0, f))}`
2054
2054
  ),
2055
2055
  sql`, `
2056
2056
  );
@@ -2125,7 +2125,7 @@ var TableRuntime = (_class = class {
2125
2125
  const specs = this.aggregateSpec(args);
2126
2126
  if (specs.length === 0) return {};
2127
2127
  const exprs = sql.join(
2128
- specs.map((s) => sql`${this.aggregateExpr(sql, s.agg, s.field)} as ${sql.raw(_chunkIUZ6A7PBcjs.q.call(void 0, s.alias))}`),
2128
+ specs.map((s) => sql`${this.aggregateExpr(sql, s.agg, s.field)} as ${sql.raw(_chunkGWMW6XY7cjs.q.call(void 0, s.alias))}`),
2129
2129
  sql`, `
2130
2130
  );
2131
2131
  const { query } = this.readQuery(sql, t, { ...args, select: void 0 }, sql`*`);
@@ -2183,7 +2183,7 @@ var TableRuntime = (_class = class {
2183
2183
  [
2184
2184
  ...by.map((f) => this.col(sql, f)),
2185
2185
  ...specs.map(
2186
- (s) => sql`${this.aggregateExpr(sql, s.agg, s.field)} as ${sql.raw(_chunkIUZ6A7PBcjs.q.call(void 0, s.alias))}`
2186
+ (s) => sql`${this.aggregateExpr(sql, s.agg, s.field)} as ${sql.raw(_chunkGWMW6XY7cjs.q.call(void 0, s.alias))}`
2187
2187
  )
2188
2188
  ],
2189
2189
  sql`, `
@@ -2207,7 +2207,7 @@ var TableRuntime = (_class = class {
2207
2207
  }
2208
2208
  }
2209
2209
  }
2210
- const query = sql`select ${select} from ${sql.raw(_chunkIUZ6A7PBcjs.q.call(void 0, this.tbl.table))}${where ? sql` where ${where}` : sql``} group by ${sql.join(
2210
+ const query = sql`select ${select} from ${sql.raw(_chunkGWMW6XY7cjs.q.call(void 0, this.tbl.table))}${where ? sql` where ${where}` : sql``} group by ${sql.join(
2211
2211
  by.map((f) => this.col(sql, f)),
2212
2212
  sql`, `
2213
2213
  )}${having ? sql` having ${having}` : sql``}${orders.length ? sql` order by ${sql.join(orders, sql`, `)}` : sql``}${args["take"] !== void 0 ? sql` limit ${sql.param(args["take"])}` : sql``}${args["skip"] ? sql` offset ${sql.param(args["skip"])}` : sql``}`;
@@ -2285,7 +2285,7 @@ var TableRuntime = (_class = class {
2285
2285
  }
2286
2286
  }
2287
2287
  }
2288
- if (issues.length) throw new (0, _chunkIUZ6A7PBcjs.ModelValidationError)(this.name, issues);
2288
+ if (issues.length) throw new (0, _chunkGWMW6XY7cjs.ModelValidationError)(this.name, issues);
2289
2289
  await this.tbl.validate(plain, true);
2290
2290
  for (const [field, v] of Object.entries(plain)) {
2291
2291
  sets.push(
@@ -2327,7 +2327,7 @@ var TableRuntime = (_class = class {
2327
2327
  }
2328
2328
  for (const [field, entries] of byField) {
2329
2329
  const join = this.join(field);
2330
- const jt = sql.raw(_chunkIUZ6A7PBcjs.q.call(void 0, join.table));
2330
+ const jt = sql.raw(_chunkGWMW6XY7cjs.q.call(void 0, join.table));
2331
2331
  const sets = entries.filter((e) => e.op.mode === "set");
2332
2332
  if (sets.length) {
2333
2333
  const owners2 = sets.map((e) => idText(e.id));
@@ -2374,7 +2374,7 @@ var TableRuntime = (_class = class {
2374
2374
  const idDdl = this.tbl.columns.get("id").ddl;
2375
2375
  const owners = sql`${sql.param(ids.map(idText))}::${sql.raw(idDdl)}[]`;
2376
2376
  const parts = joins.map(
2377
- (j) => sql`select ${sql.param(j.field)}::text as f, owner_id::text as o, array_agg(ref_id::text order by position) as ids from ${sql.raw(_chunkIUZ6A7PBcjs.q.call(void 0, j.table))} where owner_id = any(${owners}) group by owner_id`
2377
+ (j) => sql`select ${sql.param(j.field)}::text as f, owner_id::text as o, array_agg(ref_id::text order by position) as ids from ${sql.raw(_chunkGWMW6XY7cjs.q.call(void 0, j.table))} where owner_id = any(${owners}) group by owner_id`
2378
2378
  );
2379
2379
  const { rows } = await this.exec(sql.join(parts, sql` union all `));
2380
2380
  for (const j of joins) out.set(j.field, /* @__PURE__ */ new Map());
@@ -2396,7 +2396,7 @@ var TableRuntime = (_class = class {
2396
2396
  }
2397
2397
  insertSql(sql, t, rows) {
2398
2398
  const fields = [...new Set(rows.flatMap((r) => Object.keys(r)))];
2399
- const head = sql`insert into ${sql.raw(_chunkIUZ6A7PBcjs.q.call(void 0, this.tbl.table))} (${sql.join(
2399
+ const head = sql`insert into ${sql.raw(_chunkGWMW6XY7cjs.q.call(void 0, this.tbl.table))} (${sql.join(
2400
2400
  fields.map((f) => this.col(sql, f)),
2401
2401
  sql`, `
2402
2402
  )})`;
@@ -2493,7 +2493,7 @@ var TableRuntime = (_class = class {
2493
2493
  return;
2494
2494
  }
2495
2495
  const { rows: ids } = await this.exec(
2496
- sql`select nextval(pg_get_serial_sequence(${sql.param(_chunkIUZ6A7PBcjs.q.call(void 0, this.tbl.table))}, 'id'))::text as id from generate_series(1, ${sql.param(missing.length)})`
2496
+ sql`select nextval(pg_get_serial_sequence(${sql.param(_chunkGWMW6XY7cjs.q.call(void 0, this.tbl.table))}, 'id'))::text as id from generate_series(1, ${sql.param(missing.length)})`
2497
2497
  );
2498
2498
  missing.forEach((r, i) => {
2499
2499
  const id = ids[i]["id"];
@@ -2522,7 +2522,7 @@ var TableRuntime = (_class = class {
2522
2522
  const where = this.where(sql, t, args["where"]);
2523
2523
  const links = this.joinColumns(sql, [...this.tbl.joins.keys()]);
2524
2524
  const extra = links.length ? sql`, ${sql.join(links, sql`, `)}` : sql``;
2525
- const query = sets.length ? sql`update ${sql.raw(_chunkIUZ6A7PBcjs.q.call(void 0, this.tbl.table))} set ${sql.join(sets, sql`, `)} where ${where} returning *${extra}` : sql`select *${extra} from ${sql.raw(_chunkIUZ6A7PBcjs.q.call(void 0, this.tbl.table))} where ${where} limit 1`;
2525
+ const query = sets.length ? sql`update ${sql.raw(_chunkGWMW6XY7cjs.q.call(void 0, this.tbl.table))} set ${sql.join(sets, sql`, `)} where ${where} returning *${extra}` : sql`select *${extra} from ${sql.raw(_chunkGWMW6XY7cjs.q.call(void 0, this.tbl.table))} where ${where} limit 1`;
2526
2526
  const [row] = (await this.exec(query)).rows;
2527
2527
  if (!row) throw new (0, _chunkAGOYTFROcjs.HttpError)(404, `${this.name} not found`);
2528
2528
  const record = this.fromRaw(t, row);
@@ -2545,7 +2545,7 @@ var TableRuntime = (_class = class {
2545
2545
  const links = returning ? this.joinColumns(sql, [...this.tbl.joins.keys()]) : [];
2546
2546
  const list = returning ? sql` returning *${links.length ? sql`, ${sql.join(links, sql`, `)}` : sql``}` : joinOps.length ? sql` returning ${this.col(sql, "id")}` : sql``;
2547
2547
  const result = await this.exec(
2548
- sets.length ? sql`update ${sql.raw(_chunkIUZ6A7PBcjs.q.call(void 0, this.tbl.table))} set ${sql.join(sets, sql`, `)} where ${where}${list}` : sql`select ${returning ? sql`*${links.length ? sql`, ${sql.join(links, sql`, `)}` : sql``}` : this.col(sql, "id")} from ${sql.raw(_chunkIUZ6A7PBcjs.q.call(void 0, this.tbl.table))} where ${where}`
2548
+ sets.length ? sql`update ${sql.raw(_chunkGWMW6XY7cjs.q.call(void 0, this.tbl.table))} set ${sql.join(sets, sql`, `)} where ${where}${list}` : sql`select ${returning ? sql`*${links.length ? sql`, ${sql.join(links, sql`, `)}` : sql``}` : this.col(sql, "id")} from ${sql.raw(_chunkGWMW6XY7cjs.q.call(void 0, this.tbl.table))} where ${where}`
2549
2549
  );
2550
2550
  const records = result.rows.map((r) => returning ? this.fromRaw(t, r) : r);
2551
2551
  await this.applyJoins(
@@ -2569,7 +2569,7 @@ var TableRuntime = (_class = class {
2569
2569
  if (row[f] === void 0) row[f] = this.tbl.toDb(f, args["where"][f]);
2570
2570
  }
2571
2571
  const { head, values } = this.insertSql(sql, t, [row]);
2572
- const table = _chunkIUZ6A7PBcjs.q.call(void 0, this.tbl.table);
2572
+ const table = _chunkGWMW6XY7cjs.q.call(void 0, this.tbl.table);
2573
2573
  const update = await this.setList(sql, t, _nullishCoalesce(args["update"], () => ( {})), table);
2574
2574
  const { joinOps } = update;
2575
2575
  let { sets } = update;
@@ -2609,7 +2609,7 @@ var TableRuntime = (_class = class {
2609
2609
  const where = this.where(sql, t, args["where"]);
2610
2610
  const links = this.joinColumns(sql, [...this.tbl.joins.keys()]);
2611
2611
  const [row] = (await this.exec(
2612
- sql`delete from ${sql.raw(_chunkIUZ6A7PBcjs.q.call(void 0, this.tbl.table))} where ${where} returning *${links.length ? sql`, ${sql.join(links, sql`, `)}` : sql``}`
2612
+ sql`delete from ${sql.raw(_chunkGWMW6XY7cjs.q.call(void 0, this.tbl.table))} where ${where} returning *${links.length ? sql`, ${sql.join(links, sql`, `)}` : sql``}`
2613
2613
  )).rows;
2614
2614
  if (!row) throw new (0, _chunkAGOYTFROcjs.HttpError)(404, `${this.name} not found`);
2615
2615
  return this.project(this.fromRaw(t, row), this.projection(args));
@@ -2619,7 +2619,7 @@ var TableRuntime = (_class = class {
2619
2619
  const { t, sql } = await this.ready(args["where"]);
2620
2620
  return this.tbl.guard(async () => {
2621
2621
  const where = _nullishCoalesce(this.where(sql, t, args["where"]), () => ( sql`true`));
2622
- const result = await this.tbl.client().execute(sql`delete from ${sql.raw(_chunkIUZ6A7PBcjs.q.call(void 0, this.tbl.table))} where ${where}`);
2622
+ const result = await this.tbl.client().execute(sql`delete from ${sql.raw(_chunkGWMW6XY7cjs.q.call(void 0, this.tbl.table))} where ${where}`);
2623
2623
  return { count: _nullishCoalesce(result.rowCount, () => ( 0)) };
2624
2624
  });
2625
2625
  }
@@ -2628,10 +2628,10 @@ function relArgs(arg) {
2628
2628
  return isPlainObject(arg) ? arg : {};
2629
2629
  }
2630
2630
  function runtimeOf(name, from) {
2631
- const runtime = _optionalChain([_chunkIUZ6A7PBcjs.getRegisteredModel.call(void 0, name), 'optionalAccess', _65 => _65.tableRuntime, 'optionalCall', _66 => _66()]);
2631
+ const runtime = _optionalChain([_chunkGWMW6XY7cjs.getRegisteredModel.call(void 0, name), 'optionalAccess', _65 => _65.tableRuntime, 'optionalCall', _66 => _66()]);
2632
2632
  if (!runtime) {
2633
2633
  throw new Error(
2634
- _chunkIUZ6A7PBcjs.getRegisteredModel.call(void 0, name) ? `[EFC] ${from}: include needs ${name} to be a defineTable model` : `[EFC] ${from}: "${name}" is not defined \u2014 import that model before including it`
2634
+ _chunkGWMW6XY7cjs.getRegisteredModel.call(void 0, name) ? `[EFC] ${from}: include needs ${name} to be a defineTable model` : `[EFC] ${from}: "${name}" is not defined \u2014 import that model before including it`
2635
2635
  );
2636
2636
  }
2637
2637
  return runtime;
@@ -2651,7 +2651,7 @@ var JSON_OPS = /* @__PURE__ */ new Set([
2651
2651
  "mode"
2652
2652
  ]);
2653
2653
  function createTable(name, schema, options = {}) {
2654
- _chunkIUZ6A7PBcjs.normalizeSchema.call(void 0, schema, "table", name);
2654
+ _chunkGWMW6XY7cjs.normalizeSchema.call(void 0, schema, "table", name);
2655
2655
  for (const [rel, def] of Object.entries(_nullishCoalesce(options.relations, () => ( {})))) {
2656
2656
  const where = `[EFC] ${name}.relations.${rel}`;
2657
2657
  if (rel in schema) throw new Error(`${where}: a field already has this name`);
@@ -2666,7 +2666,7 @@ function createTable(name, schema, options = {}) {
2666
2666
  }
2667
2667
  let runtime;
2668
2668
  const rt = () => {
2669
- const engine = _chunkIUZ6A7PBcjs.getDbEngine.call(void 0, );
2669
+ const engine = _chunkGWMW6XY7cjs.getDbEngine.call(void 0, );
2670
2670
  if (engine !== "postgresql") {
2671
2671
  throw new Error(
2672
2672
  `[EFC] ${name} is a PostgreSQL table (defineTable) but the app is connected to MongoDB \u2014 check DATABASE_URL / config.database, or use defineModel for a model that runs on both`
@@ -2698,12 +2698,12 @@ function createTable(name, schema, options = {}) {
2698
2698
  sync: (opts) => call((r) => r.tbl.reconcile(_nullishCoalesce(_optionalChain([opts, 'optionalAccess', _71 => _71.dryRun]), () => ( false)))),
2699
2699
  drop: () => call((r) => r.tbl.drop())
2700
2700
  };
2701
- _chunkJP36TLL4cjs.traceOps.call(void 0,
2701
+ _chunkQSIP7YLWcjs.traceOps.call(void 0,
2702
2702
  name,
2703
2703
  model,
2704
2704
  Object.keys(model).filter((op) => !["name", "raw", "sync", "drop"].includes(op))
2705
2705
  );
2706
- _chunkIUZ6A7PBcjs.registerModel.call(void 0, {
2706
+ _chunkGWMW6XY7cjs.registerModel.call(void 0, {
2707
2707
  name,
2708
2708
  sync: model.sync,
2709
2709
  plan: (opts) => call((r) => r.tbl.plan(opts)),
@@ -2909,7 +2909,7 @@ function mapBulkOp(op) {
2909
2909
  return { [kind]: b };
2910
2910
  }
2911
2911
  function createCollection(name, schema, options) {
2912
- const tree = _chunkIUZ6A7PBcjs.normalizeSchema.call(void 0, schema, "collection", name);
2912
+ const tree = _chunkGWMW6XY7cjs.normalizeSchema.call(void 0, schema, "collection", name);
2913
2913
  const base = mongoModel(name, tree, options);
2914
2914
  const longs = hasLong(tree);
2915
2915
  const toRecord = (doc) => {
@@ -2918,7 +2918,7 @@ function createCollection(name, schema, options) {
2918
2918
  return longs ? castTree(rec, tree) : rec;
2919
2919
  };
2920
2920
  const model = async () => {
2921
- const engine = _chunkIUZ6A7PBcjs.getDbEngine.call(void 0, );
2921
+ const engine = _chunkGWMW6XY7cjs.getDbEngine.call(void 0, );
2922
2922
  if (engine !== "mongodb") {
2923
2923
  throw new Error(
2924
2924
  `[EFC] ${name} is a MongoDB collection (defineCollection) but the app is connected to PostgreSQL \u2014 check DATABASE_URL / config.database, or use defineModel for a model that runs on both`
@@ -2927,7 +2927,7 @@ function createCollection(name, schema, options) {
2927
2927
  return await base.raw();
2928
2928
  };
2929
2929
  const session = () => {
2930
- const tx = _chunkIUZ6A7PBcjs.currentTx.call(void 0, );
2930
+ const tx = _chunkGWMW6XY7cjs.currentTx.call(void 0, );
2931
2931
  return _optionalChain([tx, 'optionalAccess', _77 => _77.engine]) === "mongodb" ? tx.session : null;
2932
2932
  };
2933
2933
  const sess = () => {
@@ -3174,12 +3174,12 @@ function createCollection(name, schema, options) {
3174
3174
  sync: (opts) => model().then(() => base.sync(opts)),
3175
3175
  drop: () => model().then(() => base.drop())
3176
3176
  };
3177
- _chunkJP36TLL4cjs.traceOps.call(void 0,
3177
+ _chunkQSIP7YLWcjs.traceOps.call(void 0,
3178
3178
  name,
3179
3179
  model$,
3180
3180
  Object.keys(model$).filter((op) => !["name", "raw", "sync", "drop", "watch"].includes(op))
3181
3181
  );
3182
- _chunkIUZ6A7PBcjs.registerModel.call(void 0, {
3182
+ _chunkGWMW6XY7cjs.registerModel.call(void 0, {
3183
3183
  name,
3184
3184
  sync: model$.sync,
3185
3185
  plan: (opts) => model().then(() => base.plan(opts)),
@@ -3235,4 +3235,4 @@ var db = new Proxy({}, {
3235
3235
 
3236
3236
 
3237
3237
  exports.loadMongoose = loadMongoose; exports.connectMongo = connectMongo; exports.defineModel = defineModel; exports.transaction = transaction; exports.defineTable = defineTable; exports.defineCollection = defineCollection; exports.setDbClient = setDbClient; exports.getDbClient = getDbClient; exports.db = db;
3238
- //# sourceMappingURL=chunk-R2K7AFIB.cjs.map
3238
+ //# sourceMappingURL=chunk-SOU3PBJC.cjs.map