express-file-cluster 0.9.6 → 0.10.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.
- package/dist/auth/index.cjs +5 -5
- package/dist/auth/index.d.cts +1 -1
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.js +4 -4
- package/dist/{chunk-QL6EWT4B.cjs → chunk-4DOHQU6I.cjs} +9 -7
- package/dist/chunk-4DOHQU6I.cjs.map +1 -0
- package/dist/{chunk-2SETEVMO.js → chunk-7KC2H76D.js} +42 -2
- package/dist/chunk-7KC2H76D.js.map +1 -0
- package/dist/{chunk-6KHBJOLB.cjs → chunk-7KO4DJRJ.cjs} +7 -7
- package/dist/{chunk-6KHBJOLB.cjs.map → chunk-7KO4DJRJ.cjs.map} +1 -1
- package/dist/{chunk-45BWAR6P.js → chunk-ATVD2HGC.js} +3 -3
- package/dist/{chunk-BBSZLGZW.js → chunk-EGSSZUVO.js} +8 -6
- package/dist/chunk-EGSSZUVO.js.map +1 -0
- package/dist/{chunk-TI24L4XE.cjs → chunk-GBI77W5T.cjs} +6 -2
- package/dist/chunk-GBI77W5T.cjs.map +1 -0
- package/dist/{chunk-VWSUQKCJ.cjs → chunk-HBCY7ILD.cjs} +274 -107
- package/dist/chunk-HBCY7ILD.cjs.map +1 -0
- package/dist/{chunk-RGT4ZVHL.cjs → chunk-KFVFP2Q7.cjs} +45 -5
- package/dist/chunk-KFVFP2Q7.cjs.map +1 -0
- package/dist/{chunk-TYCYYLLM.cjs → chunk-NKLOE4AK.cjs} +1 -1
- package/dist/chunk-NKLOE4AK.cjs.map +1 -0
- package/dist/{chunk-OFA7OGN5.js → chunk-PGJQK36V.js} +171 -4
- package/dist/chunk-PGJQK36V.js.map +1 -0
- package/dist/{chunk-ULWNHN6P.js → chunk-QDEDOHP7.js} +1 -1
- package/dist/chunk-QDEDOHP7.js.map +1 -0
- package/dist/{chunk-7ZESZG3J.js → chunk-R4XO4SVM.js} +3 -3
- package/dist/chunk-R52CUEGT.js +74 -0
- package/dist/chunk-R52CUEGT.js.map +1 -0
- package/dist/{chunk-HBYSKULC.js → chunk-RAB44UGX.js} +5 -1
- package/dist/chunk-RAB44UGX.js.map +1 -0
- package/dist/{chunk-7YEX4MQV.cjs → chunk-WBLUGOAG.cjs} +42 -6
- package/dist/chunk-WBLUGOAG.cjs.map +1 -0
- package/dist/{chunk-FMA76PRH.cjs → chunk-YK4ZM3CA.cjs} +8 -8
- package/dist/{chunk-FMA76PRH.cjs.map → chunk-YK4ZM3CA.cjs.map} +1 -1
- package/dist/cli/db-runner.cjs +2010 -116
- package/dist/cli/db-runner.cjs.map +1 -1
- package/dist/cli/db-runner.js +1987 -93
- package/dist/cli/db-runner.js.map +1 -1
- package/dist/cli/index.cjs +36 -13
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +33 -10
- package/dist/cli/index.js.map +1 -1
- package/dist/docs/api-reference/collection.md +44 -1
- package/dist/docs/api-reference/ignite.md +9 -0
- package/dist/docs/api-reference/types.md +99 -0
- package/dist/docs/cli/add.md +1 -1
- package/dist/docs/cli/db.md +2 -2
- package/dist/docs/core-concepts/background-tasks.md +6 -3
- package/dist/docs/getting-started/index.md +2 -1
- package/dist/docs/guides/caching.md +32 -1
- package/dist/docs/guides/database.md +2 -0
- package/dist/docs/guides/feature-matrix.md +58 -0
- package/dist/docs/guides/migrations.md +23 -2
- package/dist/docs/guides/which-api.md +2 -2
- package/dist/docs/index.md +3 -1
- package/dist/docs/skills/SKILL.md +1 -1
- package/dist/docs/skills/api-surface.md +5 -0
- package/dist/docs/skills/tasks-internals.md +4 -3
- package/dist/docs/skills/what-not-to-invent.md +4 -3
- package/dist/index.cjs +99 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +204 -3
- package/dist/index.d.ts +204 -3
- package/dist/index.js +76 -7
- package/dist/index.js.map +1 -1
- package/dist/pgboss-backend-FW42SBSM.js +14 -0
- package/dist/pgboss-backend-RVHUBJTU.cjs +14 -0
- package/dist/{pgboss-backend-DSO3QTNK.cjs.map → pgboss-backend-RVHUBJTU.cjs.map} +1 -1
- package/dist/registry/index.json +13 -1
- package/dist/registry/js-mongo/auth.json +1 -1
- package/dist/registry/js-mongo/forgot-password.json +1 -1
- package/dist/registry/js-mongo-collection/_base.json +1 -0
- package/dist/registry/js-mongo-collection/account-security.json +1 -0
- package/dist/registry/js-mongo-collection/account-settings.json +1 -0
- package/dist/registry/js-mongo-collection/admin-admins.json +1 -0
- package/dist/registry/js-mongo-collection/admin-analytics.json +1 -0
- package/dist/registry/js-mongo-collection/admin-billing.json +1 -0
- package/dist/registry/js-mongo-collection/admin-content.json +1 -0
- package/dist/registry/js-mongo-collection/admin-logs.json +1 -0
- package/dist/registry/js-mongo-collection/admin-support.json +1 -0
- package/dist/registry/js-mongo-collection/admin-system.json +1 -0
- package/dist/registry/js-mongo-collection/admin-users.json +1 -0
- package/dist/registry/js-mongo-collection/admin.json +1 -0
- package/dist/registry/js-mongo-collection/auth.json +1 -0
- package/dist/registry/js-mongo-collection/auth@apple.json +1 -0
- package/dist/registry/js-mongo-collection/auth@google.json +1 -0
- package/dist/registry/js-mongo-collection/billing.json +1 -0
- package/dist/registry/js-mongo-collection/email-client.json +1 -0
- package/dist/registry/js-mongo-collection/email-verification.json +1 -0
- package/dist/registry/js-mongo-collection/files.json +1 -0
- package/dist/registry/js-mongo-collection/forgot-password.json +1 -0
- package/dist/registry/js-mongo-collection/notifications.json +1 -0
- package/dist/registry/js-mongo-collection/support.json +1 -0
- package/dist/registry/js-mongo-collection/user-profile.json +1 -0
- package/dist/registry/js-pg-model/auth.json +1 -1
- package/dist/registry/js-pg-model/forgot-password.json +1 -1
- package/dist/registry/js-pg-table/auth.json +1 -1
- package/dist/registry/js-pg-table/forgot-password.json +1 -1
- package/dist/registry/ts-mongo/auth.json +1 -1
- package/dist/registry/ts-mongo/forgot-password.json +1 -1
- package/dist/registry/ts-mongo-collection/_base.json +1 -0
- package/dist/registry/ts-mongo-collection/account-security.json +1 -0
- package/dist/registry/ts-mongo-collection/account-settings.json +1 -0
- package/dist/registry/ts-mongo-collection/admin-admins.json +1 -0
- package/dist/registry/ts-mongo-collection/admin-analytics.json +1 -0
- package/dist/registry/ts-mongo-collection/admin-billing.json +1 -0
- package/dist/registry/ts-mongo-collection/admin-content.json +1 -0
- package/dist/registry/ts-mongo-collection/admin-logs.json +1 -0
- package/dist/registry/ts-mongo-collection/admin-support.json +1 -0
- package/dist/registry/ts-mongo-collection/admin-system.json +1 -0
- package/dist/registry/ts-mongo-collection/admin-users.json +1 -0
- package/dist/registry/ts-mongo-collection/admin.json +1 -0
- package/dist/registry/ts-mongo-collection/auth.json +1 -0
- package/dist/registry/ts-mongo-collection/auth@apple.json +1 -0
- package/dist/registry/ts-mongo-collection/auth@google.json +1 -0
- package/dist/registry/ts-mongo-collection/billing.json +1 -0
- package/dist/registry/ts-mongo-collection/email-client.json +1 -0
- package/dist/registry/ts-mongo-collection/email-verification.json +1 -0
- package/dist/registry/ts-mongo-collection/files.json +1 -0
- package/dist/registry/ts-mongo-collection/forgot-password.json +1 -0
- package/dist/registry/ts-mongo-collection/notifications.json +1 -0
- package/dist/registry/ts-mongo-collection/support.json +1 -0
- package/dist/registry/ts-mongo-collection/user-profile.json +1 -0
- package/dist/registry/ts-pg-model/auth.json +1 -1
- package/dist/registry/ts-pg-model/forgot-password.json +1 -1
- package/dist/registry/ts-pg-table/auth.json +1 -1
- package/dist/registry/ts-pg-table/forgot-password.json +1 -1
- package/dist/tasks/index.cjs +4 -2
- package/dist/tasks/index.cjs.map +1 -1
- package/dist/tasks/index.d.cts +4 -2
- package/dist/tasks/index.d.ts +4 -2
- package/dist/tasks/index.js +3 -1
- package/dist/thread-runner.cjs +8 -0
- package/dist/thread-runner.cjs.map +1 -0
- package/dist/thread-runner.d.cts +3 -0
- package/dist/thread-runner.d.ts +3 -0
- package/dist/thread-runner.js +8 -0
- package/dist/thread-runner.js.map +1 -0
- package/dist/{types-DAsBKVM-.d.cts → types-Bnxvj3l0.d.cts} +7 -1
- package/dist/{types-DAsBKVM-.d.ts → types-Bnxvj3l0.d.ts} +7 -1
- package/package.json +1 -1
- package/dist/chunk-2SETEVMO.js.map +0 -1
- package/dist/chunk-7YEX4MQV.cjs.map +0 -1
- package/dist/chunk-BBSZLGZW.js.map +0 -1
- package/dist/chunk-HBYSKULC.js.map +0 -1
- package/dist/chunk-LJNSJFOL.js +0 -38
- package/dist/chunk-LJNSJFOL.js.map +0 -1
- package/dist/chunk-OFA7OGN5.js.map +0 -1
- package/dist/chunk-QL6EWT4B.cjs.map +0 -1
- package/dist/chunk-RGT4ZVHL.cjs.map +0 -1
- package/dist/chunk-TI24L4XE.cjs.map +0 -1
- package/dist/chunk-TYCYYLLM.cjs.map +0 -1
- package/dist/chunk-ULWNHN6P.js.map +0 -1
- package/dist/chunk-VWSUQKCJ.cjs.map +0 -1
- package/dist/pgboss-backend-DSO3QTNK.cjs +0 -14
- package/dist/pgboss-backend-I6DFUNRM.js +0 -14
- /package/dist/{chunk-45BWAR6P.js.map → chunk-ATVD2HGC.js.map} +0 -0
- /package/dist/{chunk-7ZESZG3J.js.map → chunk-R4XO4SVM.js.map} +0 -0
- /package/dist/{pgboss-backend-I6DFUNRM.js.map → pgboss-backend-FW42SBSM.js.map} +0 -0
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
var
|
|
21
|
+
var _chunkNKLOE4AKcjs = require('./chunk-NKLOE4AK.cjs');
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
|
|
@@ -86,7 +86,7 @@ function rules(node, mg) {
|
|
|
86
86
|
if (d.unique !== void 0) entry["unique"] = d.unique;
|
|
87
87
|
if (d.index !== void 0) entry["index"] = d.index;
|
|
88
88
|
if (d.default !== void 0)
|
|
89
|
-
entry["default"] =
|
|
89
|
+
entry["default"] = _chunkNKLOE4AKcjs.resolveDefault.call(void 0, d.default, () => new mg.Types.ObjectId());
|
|
90
90
|
if (d.enum !== void 0) entry["enum"] = d.enum;
|
|
91
91
|
if (d.min !== void 0) entry["min"] = d.min;
|
|
92
92
|
if (d.max !== void 0) entry["max"] = d.max;
|
|
@@ -160,7 +160,7 @@ function normalise(value) {
|
|
|
160
160
|
function translateError(model, err) {
|
|
161
161
|
const e = err;
|
|
162
162
|
if (_optionalChain([e, 'optionalAccess', _ => _.name]) === "ValidationError" && e.errors) {
|
|
163
|
-
throw new (0,
|
|
163
|
+
throw new (0, _chunkNKLOE4AKcjs.ModelValidationError)(
|
|
164
164
|
model,
|
|
165
165
|
Object.entries(e.errors).map(([path, v]) => ({
|
|
166
166
|
path,
|
|
@@ -172,13 +172,13 @@ function translateError(model, err) {
|
|
|
172
172
|
);
|
|
173
173
|
}
|
|
174
174
|
if (_optionalChain([e, 'optionalAccess', _2 => _2.name]) === "CastError") {
|
|
175
|
-
throw new (0,
|
|
175
|
+
throw new (0, _chunkNKLOE4AKcjs.ModelValidationError)(model, [
|
|
176
176
|
{ path: _nullishCoalesce(e.path, () => ( "")), message: _nullishCoalesce(e.message, () => ( "invalid value")) }
|
|
177
177
|
]);
|
|
178
178
|
}
|
|
179
179
|
if (_optionalChain([e, 'optionalAccess', _3 => _3.code]) === 11e3) {
|
|
180
180
|
const field = _nullishCoalesce(Object.keys(_nullishCoalesce(e.keyValue, () => ( {})))[0], () => ( "field"));
|
|
181
|
-
throw new (0,
|
|
181
|
+
throw new (0, _chunkNKLOE4AKcjs.HttpError)(409, `${model} with this ${field} already exists`);
|
|
182
182
|
}
|
|
183
183
|
throw err;
|
|
184
184
|
}
|
|
@@ -210,8 +210,8 @@ function mongoModel(name, tree, options) {
|
|
|
210
210
|
const schema = new mg.Schema(buildTree(tree, mg), {
|
|
211
211
|
timestamps: _nullishCoalesce(options.timestamps, () => ( true)),
|
|
212
212
|
// autoSync: false hands collection and index creation to migrations, on MongoDB too.
|
|
213
|
-
autoIndex:
|
|
214
|
-
autoCreate:
|
|
213
|
+
autoIndex: _chunkNKLOE4AKcjs.isAutoSync.call(void 0, ),
|
|
214
|
+
autoCreate: _chunkNKLOE4AKcjs.isAutoSync.call(void 0, ),
|
|
215
215
|
...options.collection !== void 0 && { collection: options.collection }
|
|
216
216
|
});
|
|
217
217
|
for (const idx of _nullishCoalesce(options.indexes, () => ( []))) {
|
|
@@ -226,7 +226,7 @@ function mongoModel(name, tree, options) {
|
|
|
226
226
|
}
|
|
227
227
|
});
|
|
228
228
|
}
|
|
229
|
-
const sequences =
|
|
229
|
+
const sequences = _chunkNKLOE4AKcjs.sequenceFields.call(void 0, name, tree);
|
|
230
230
|
if (sequences.length > 0) {
|
|
231
231
|
schema.pre("validate", async function() {
|
|
232
232
|
if (!this.isNew) return;
|
|
@@ -236,7 +236,7 @@ function mongoModel(name, tree, options) {
|
|
|
236
236
|
});
|
|
237
237
|
}
|
|
238
238
|
const M = mg.model(name, schema);
|
|
239
|
-
if (
|
|
239
|
+
if (_chunkNKLOE4AKcjs.isAutoSync.call(void 0, )) {
|
|
240
240
|
await M.init().catch((err) => {
|
|
241
241
|
_chunkDUADUR6Rcjs.getLogger.call(void 0, ).warn(
|
|
242
242
|
{ model: name, err: err.message },
|
|
@@ -248,7 +248,7 @@ function mongoModel(name, tree, options) {
|
|
|
248
248
|
})
|
|
249
249
|
);
|
|
250
250
|
const session = () => {
|
|
251
|
-
const tx =
|
|
251
|
+
const tx = _chunkNKLOE4AKcjs.currentTx.call(void 0, );
|
|
252
252
|
return _optionalChain([tx, 'optionalAccess', _5 => _5.engine]) === "mongodb" ? { session: tx.session } : {};
|
|
253
253
|
};
|
|
254
254
|
const applyQueryOptions = (q2, opts) => {
|
|
@@ -382,7 +382,7 @@ function mongoModel(name, tree, options) {
|
|
|
382
382
|
}),
|
|
383
383
|
raw: () => model(),
|
|
384
384
|
async sync(opts) {
|
|
385
|
-
if (
|
|
385
|
+
if (_chunkNKLOE4AKcjs.isSyncSuppressed.call(void 0, )) return [];
|
|
386
386
|
const M = await model();
|
|
387
387
|
const changes = [];
|
|
388
388
|
const exists = (await M.db.db.listCollections({ name: M.collection.collectionName }).toArray()).length > 0;
|
|
@@ -506,7 +506,7 @@ function explainMongoError(err, url) {
|
|
|
506
506
|
|
|
507
507
|
// src/db/pg-model.ts
|
|
508
508
|
function pgModel(name, tree, options) {
|
|
509
|
-
const tbl =
|
|
509
|
+
const tbl = _chunkNKLOE4AKcjs.pgTable.call(void 0, name, tree, options, { native: false, api: "defineModel" });
|
|
510
510
|
const { columns, ts, refs, ready, compile, client, columnFor, toDb, fromRow, validate, guard } = tbl;
|
|
511
511
|
const kindOf = (field) => _optionalChain([columns, 'access', _15 => _15.get, 'call', _16 => _16(field), 'optionalAccess', _17 => _17.kind]);
|
|
512
512
|
function missingField(sql, cond) {
|
|
@@ -606,7 +606,7 @@ function pgModel(name, tree, options) {
|
|
|
606
606
|
break;
|
|
607
607
|
}
|
|
608
608
|
default:
|
|
609
|
-
throw new (0,
|
|
609
|
+
throw new (0, _chunkNKLOE4AKcjs.ModelValidationError)(name, [
|
|
610
610
|
{ path, message: `operator ${op} is not supported on PostgreSQL` }
|
|
611
611
|
]);
|
|
612
612
|
}
|
|
@@ -637,8 +637,8 @@ function pgModel(name, tree, options) {
|
|
|
637
637
|
for (const path of Array.isArray(paths) ? paths : [paths]) {
|
|
638
638
|
const ref = refs.get(path);
|
|
639
639
|
if (!ref)
|
|
640
|
-
throw new (0,
|
|
641
|
-
const target =
|
|
640
|
+
throw new (0, _chunkNKLOE4AKcjs.ModelValidationError)(name, [{ path, message: "is not a populatable ref field" }]);
|
|
641
|
+
const target = _chunkNKLOE4AKcjs.getRegisteredModel.call(void 0, ref.model);
|
|
642
642
|
if (!target) throw new Error(`[EFC] populate: model "${ref.model}" is not defined`);
|
|
643
643
|
const ids = [
|
|
644
644
|
...new Set(
|
|
@@ -681,7 +681,7 @@ function pgModel(name, tree, options) {
|
|
|
681
681
|
return populate(rows, _optionalChain([opts, 'optionalAccess', _22 => _22.populate]));
|
|
682
682
|
}
|
|
683
683
|
const strictUpdate = (update) => {
|
|
684
|
-
const declared = (path) => columns.has(path.split(".")[0]) && (!path.includes(".") ||
|
|
684
|
+
const declared = (path) => columns.has(path.split(".")[0]) && (!path.includes(".") || _chunkNKLOE4AKcjs.nodeAt.call(void 0, tree, path.split(".")) !== void 0);
|
|
685
685
|
const out = {};
|
|
686
686
|
for (const [k, v] of Object.entries(update)) {
|
|
687
687
|
if (k.startsWith("$") && v !== null && typeof v === "object") {
|
|
@@ -696,7 +696,7 @@ function pgModel(name, tree, options) {
|
|
|
696
696
|
const ops = update;
|
|
697
697
|
for (const op of Object.keys(update).filter((k) => k.startsWith("$"))) {
|
|
698
698
|
if (!["$set", "$unset", "$inc", "$push", "$pull"].includes(op)) {
|
|
699
|
-
throw new (0,
|
|
699
|
+
throw new (0, _chunkNKLOE4AKcjs.ModelValidationError)(name, [
|
|
700
700
|
{ path: op, message: "update operator is not supported on PostgreSQL" }
|
|
701
701
|
]);
|
|
702
702
|
}
|
|
@@ -709,25 +709,25 @@ function pgModel(name, tree, options) {
|
|
|
709
709
|
for (const [k, v] of Object.entries($set)) if (!k.includes(".")) topLevel[k] = v;
|
|
710
710
|
for (const k of Object.keys(_nullishCoalesce(ops["$unset"], () => ( {})))) if (!k.includes(".")) topLevel[k] = null;
|
|
711
711
|
for (const [k, v] of Object.entries($set))
|
|
712
|
-
if (k.includes(".")) await
|
|
712
|
+
if (k.includes(".")) await _chunkNKLOE4AKcjs.validateAtPath.call(void 0, tree, k, v, issues);
|
|
713
713
|
for (const k of Object.keys(_nullishCoalesce(ops["$unset"], () => ( {})))) {
|
|
714
|
-
if (k.includes(".")) await
|
|
714
|
+
if (k.includes(".")) await _chunkNKLOE4AKcjs.validateAtPath.call(void 0, tree, k, null, issues);
|
|
715
715
|
}
|
|
716
716
|
for (const [k, by] of Object.entries(_nullishCoalesce(ops["$inc"], () => ( {})))) {
|
|
717
717
|
if (typeof by !== "number") issues.push({ path: k, message: "$inc needs a number" });
|
|
718
|
-
const node = k.includes(".") ?
|
|
718
|
+
const node = k.includes(".") ? _chunkNKLOE4AKcjs.nodeAt.call(void 0, tree, k.split(".")) : tree[k];
|
|
719
719
|
if (node && !(node.kind === "scalar" && node.type === "number") && node.kind !== "json") {
|
|
720
720
|
issues.push({ path: k, message: "$inc only applies to number fields" });
|
|
721
721
|
}
|
|
722
722
|
}
|
|
723
|
-
if (issues.length) throw new (0,
|
|
723
|
+
if (issues.length) throw new (0, _chunkNKLOE4AKcjs.ModelValidationError)(name, issues);
|
|
724
724
|
await validate(topLevel, true);
|
|
725
725
|
const set = {};
|
|
726
726
|
const nested = /* @__PURE__ */ new Map();
|
|
727
727
|
const touchedTop = /* @__PURE__ */ new Set();
|
|
728
728
|
const acc = (field) => _nullishCoalesce(nested.get(field), () => ( columnFor(t, field)));
|
|
729
729
|
const conflict = (path) => {
|
|
730
|
-
throw new (0,
|
|
730
|
+
throw new (0, _chunkNKLOE4AKcjs.ModelValidationError)(name, [{ path, message: "conflicting update paths" }]);
|
|
731
731
|
};
|
|
732
732
|
const top = (field, value) => {
|
|
733
733
|
if (touchedTop.has(field) || nested.has(field)) conflict(field);
|
|
@@ -898,7 +898,7 @@ function defineModel(name, schema, options) {
|
|
|
898
898
|
return createModel(name, schema, _nullishCoalesce(options, () => ( {})));
|
|
899
899
|
}
|
|
900
900
|
function distinctFields(tree, options) {
|
|
901
|
-
const ts =
|
|
901
|
+
const ts = _chunkNKLOE4AKcjs.timestampFields.call(void 0, options);
|
|
902
902
|
const fields = /* @__PURE__ */ new Set(["id", ...Object.values(ts)]);
|
|
903
903
|
for (const [key, node] of Object.entries(tree)) if (node.kind === "scalar") fields.add(key);
|
|
904
904
|
return fields;
|
|
@@ -923,11 +923,11 @@ var MODEL_OPS = [
|
|
|
923
923
|
];
|
|
924
924
|
var sortKey = (v) => v instanceof Date ? v.getTime() : v;
|
|
925
925
|
function createModel(name, schema, options, native) {
|
|
926
|
-
const tree =
|
|
926
|
+
const tree = _chunkNKLOE4AKcjs.normalizeSchema.call(void 0, schema, "model", name);
|
|
927
927
|
let engineModel;
|
|
928
928
|
const impl = () => {
|
|
929
929
|
if (engineModel) return engineModel;
|
|
930
|
-
const engine =
|
|
930
|
+
const engine = _chunkNKLOE4AKcjs.getDbEngine.call(void 0, );
|
|
931
931
|
if (native && native.engine !== engine) {
|
|
932
932
|
throw new Error(
|
|
933
933
|
`[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`
|
|
@@ -969,7 +969,7 @@ function createModel(name, schema, options, native) {
|
|
|
969
969
|
try {
|
|
970
970
|
return await m.create(create);
|
|
971
971
|
} catch (err) {
|
|
972
|
-
if (
|
|
972
|
+
if (_chunkNKLOE4AKcjs.isHttpError.call(void 0, err) && err.statusCode === 409 && !_chunkNKLOE4AKcjs.currentTx.call(void 0, )) {
|
|
973
973
|
const retried = await m.updateOne(filter, update);
|
|
974
974
|
if (retried) return retried;
|
|
975
975
|
}
|
|
@@ -986,25 +986,31 @@ function createModel(name, schema, options, native) {
|
|
|
986
986
|
drop: () => call((m) => m.drop())
|
|
987
987
|
};
|
|
988
988
|
_chunkDUADUR6Rcjs.traceOps.call(void 0, name, model, MODEL_OPS);
|
|
989
|
-
|
|
989
|
+
_chunkNKLOE4AKcjs.registerModel.call(void 0, {
|
|
990
990
|
name,
|
|
991
991
|
sync: model.sync,
|
|
992
992
|
plan: (opts) => call((m) => m.plan(opts)),
|
|
993
993
|
drop: model.drop,
|
|
994
994
|
findByIds: (ids) => model.find({ id: { $in: ids } }),
|
|
995
|
-
pgTarget: () => ({ table: _nullishCoalesce(options.collection, () => (
|
|
995
|
+
pgTarget: () => ({ table: _nullishCoalesce(options.collection, () => ( _chunkNKLOE4AKcjs.tableNameFor.call(void 0, name))), idKind: "uuid" }),
|
|
996
|
+
studio: {
|
|
997
|
+
storage: async () => _chunkNKLOE4AKcjs.getDbEngine.call(void 0, ) === "mongodb" ? (await model.raw()).collection.collectionName : _nullishCoalesce(options.collection, () => ( _chunkNKLOE4AKcjs.tableNameFor.call(void 0, name))),
|
|
998
|
+
create: (data) => model.create(data),
|
|
999
|
+
update: (id, data) => model.update(id, data),
|
|
1000
|
+
delete: (id) => model.delete(id)
|
|
1001
|
+
}
|
|
996
1002
|
});
|
|
997
1003
|
return model;
|
|
998
1004
|
}
|
|
999
1005
|
|
|
1000
1006
|
// src/db/transaction.ts
|
|
1001
1007
|
async function transaction(fn) {
|
|
1002
|
-
if (
|
|
1003
|
-
if (
|
|
1008
|
+
if (_chunkNKLOE4AKcjs.currentTx.call(void 0, )) return fn();
|
|
1009
|
+
if (_chunkNKLOE4AKcjs.getDbEngine.call(void 0, ) === "postgresql") {
|
|
1004
1010
|
let result;
|
|
1005
1011
|
const afterCommit = [];
|
|
1006
1012
|
await _chunkDUADUR6Rcjs.getOrm.call(void 0, ).transaction(async (tx) => {
|
|
1007
|
-
result = await
|
|
1013
|
+
result = await _chunkNKLOE4AKcjs.runInTx.call(void 0, { engine: "postgresql", tx, afterCommit }, fn);
|
|
1008
1014
|
});
|
|
1009
1015
|
for (const run of afterCommit) run();
|
|
1010
1016
|
return result;
|
|
@@ -1014,7 +1020,7 @@ async function transaction(fn) {
|
|
|
1014
1020
|
try {
|
|
1015
1021
|
let result;
|
|
1016
1022
|
await session.withTransaction(async () => {
|
|
1017
|
-
result = await
|
|
1023
|
+
result = await _chunkNKLOE4AKcjs.runInTx.call(void 0, { engine: "mongodb", session }, fn);
|
|
1018
1024
|
});
|
|
1019
1025
|
return result;
|
|
1020
1026
|
} finally {
|
|
@@ -1060,8 +1066,8 @@ var TableRuntime = (_class = class {
|
|
|
1060
1066
|
constructor(name, schema, options) {;_class.prototype.__init.call(this);
|
|
1061
1067
|
this.name = name;
|
|
1062
1068
|
this.options = options;
|
|
1063
|
-
const tree =
|
|
1064
|
-
this.tbl =
|
|
1069
|
+
const tree = _chunkNKLOE4AKcjs.normalizeSchema.call(void 0, schema, "table", name);
|
|
1070
|
+
this.tbl = _chunkNKLOE4AKcjs.pgTable.call(void 0, name, tree, options, { native: true, api: "defineTable" });
|
|
1065
1071
|
this.uniqueSets = [["id"]];
|
|
1066
1072
|
for (const spec of this.tbl.columns.values()) {
|
|
1067
1073
|
if (_optionalChain([spec, 'access', _25 => _25.node, 'optionalAccess', _26 => _26.def, 'access', _27 => _27.unique])) this.uniqueSets.push([spec.field]);
|
|
@@ -1088,7 +1094,7 @@ var TableRuntime = (_class = class {
|
|
|
1088
1094
|
/** Many-to-many fields as list columns, so filters and projections treat them alike. */
|
|
1089
1095
|
__init() {this.joinSpecs = /* @__PURE__ */ new Map()}
|
|
1090
1096
|
fail(path, message) {
|
|
1091
|
-
throw new (0,
|
|
1097
|
+
throw new (0, _chunkNKLOE4AKcjs.ModelValidationError)(this.name, [{ path, message }]);
|
|
1092
1098
|
}
|
|
1093
1099
|
spec(field) {
|
|
1094
1100
|
return _nullishCoalesce(this.tbl.columns.get(field), () => ( this.joinSpecs.get(field)));
|
|
@@ -1099,18 +1105,18 @@ var TableRuntime = (_class = class {
|
|
|
1099
1105
|
/** A many-to-many field's ids, in order, for the row `owner` (a table name or alias). */
|
|
1100
1106
|
joinExpr(sql, join, owner) {
|
|
1101
1107
|
return sql.raw(
|
|
1102
|
-
`coalesce((select array_agg(efc_j.ref_id order by efc_j.position) from ${
|
|
1108
|
+
`coalesce((select array_agg(efc_j.ref_id order by efc_j.position) from ${_chunkNKLOE4AKcjs.q.call(void 0, join.table)} efc_j where efc_j.owner_id = ${owner}.${_chunkNKLOE4AKcjs.q.call(void 0, "id")}), '{}'::${join.ddl})`
|
|
1103
1109
|
);
|
|
1104
1110
|
}
|
|
1105
1111
|
col(sql, field, alias) {
|
|
1106
1112
|
const join = this.join(field);
|
|
1107
|
-
if (join) return this.joinExpr(sql, join, _nullishCoalesce(alias, () => (
|
|
1113
|
+
if (join) return this.joinExpr(sql, join, _nullishCoalesce(alias, () => ( _chunkNKLOE4AKcjs.q.call(void 0, this.tbl.table))));
|
|
1108
1114
|
const spec = this.spec(field);
|
|
1109
|
-
return sql.raw(alias ? `${alias}.${
|
|
1115
|
+
return sql.raw(alias ? `${alias}.${_chunkNKLOE4AKcjs.q.call(void 0, spec.column)}` : _chunkNKLOE4AKcjs.q.call(void 0, spec.column));
|
|
1110
1116
|
}
|
|
1111
1117
|
/** SELECT items for the many-to-many fields among `fields`, as text arrays. */
|
|
1112
1118
|
joinColumns(sql, fields, owner) {
|
|
1113
|
-
return fields.filter((f) => this.join(f)).map((f) => sql`${this.col(sql, f, owner)}::text[] as ${sql.raw(
|
|
1119
|
+
return fields.filter((f) => this.join(f)).map((f) => sql`${this.col(sql, f, owner)}::text[] as ${sql.raw(_chunkNKLOE4AKcjs.q.call(void 0, relAlias(f)))}`);
|
|
1114
1120
|
}
|
|
1115
1121
|
/** `col` for SELECT lists: many-to-many fields come back as text arrays under an alias. */
|
|
1116
1122
|
selectCols(sql, fields, owner) {
|
|
@@ -1402,7 +1408,7 @@ var TableRuntime = (_class = class {
|
|
|
1402
1408
|
if (args["cursor"]) {
|
|
1403
1409
|
this.uniqueKey(args["cursor"], "cursor");
|
|
1404
1410
|
const cw = this.where(sql, t, args["cursor"]);
|
|
1405
|
-
const at = (field) => sql`(select ${this.col(sql, field)} from ${sql.raw(
|
|
1411
|
+
const at = (field) => sql`(select ${this.col(sql, field)} from ${sql.raw(_chunkNKLOE4AKcjs.q.call(void 0, this.tbl.table))} where ${cw})`;
|
|
1406
1412
|
const ors = [];
|
|
1407
1413
|
const same = (o) => sql`${this.col(sql, o.field)} is not distinct from ${at(o.field)}`;
|
|
1408
1414
|
for (let i = 0; i < order.length; i++) {
|
|
@@ -1415,7 +1421,7 @@ var TableRuntime = (_class = class {
|
|
|
1415
1421
|
ors.push(eqs.length ? sql`(${sql.join([...eqs, after], sql` and `)})` : after);
|
|
1416
1422
|
}
|
|
1417
1423
|
ors.push(sql`(${sql.join(order.map(same), sql` and `)})`);
|
|
1418
|
-
parts.push(sql`exists (select 1 from ${sql.raw(
|
|
1424
|
+
parts.push(sql`exists (select 1 from ${sql.raw(_chunkNKLOE4AKcjs.q.call(void 0, this.tbl.table))} where ${cw})`);
|
|
1419
1425
|
parts.push(sql`(${sql.join(ors, sql` or `)})`);
|
|
1420
1426
|
}
|
|
1421
1427
|
return parts.length ? sql.join(parts, sql` and `) : sql`true`;
|
|
@@ -1440,7 +1446,7 @@ var TableRuntime = (_class = class {
|
|
|
1440
1446
|
const offset = args["skip"] ? sql` offset ${sql.param(args["skip"])}` : sql``;
|
|
1441
1447
|
const orderBy = order.length ? sql` order by ${this.orderSql(sql, order)}` : sql``;
|
|
1442
1448
|
const where = this.readWhere(sql, t, args, order);
|
|
1443
|
-
const from = sql.raw(
|
|
1449
|
+
const from = sql.raw(_chunkNKLOE4AKcjs.q.call(void 0, this.tbl.table));
|
|
1444
1450
|
const distinct = _optionalChain([args, 'access', _29 => _29["distinct"], 'optionalAccess', _30 => _30.filter, 'call', _31 => _31((f) => this.spec(f))]);
|
|
1445
1451
|
if (_optionalChain([distinct, 'optionalAccess', _32 => _32.length])) {
|
|
1446
1452
|
const dcols = sql.join(
|
|
@@ -1470,7 +1476,7 @@ var TableRuntime = (_class = class {
|
|
|
1470
1476
|
distinct ? "efc_distinct" : void 0
|
|
1471
1477
|
);
|
|
1472
1478
|
const include = this.includeArg(args);
|
|
1473
|
-
const included = include ? await this.includeColumns(sql, include, distinct ? "efc_distinct" :
|
|
1479
|
+
const included = include ? await this.includeColumns(sql, include, distinct ? "efc_distinct" : _chunkNKLOE4AKcjs.q.call(void 0, this.tbl.table), 1) : [];
|
|
1474
1480
|
const { query, reversed } = this.readQuery(
|
|
1475
1481
|
sql,
|
|
1476
1482
|
t,
|
|
@@ -1545,7 +1551,7 @@ var TableRuntime = (_class = class {
|
|
|
1545
1551
|
for (const [name, arg] of Object.entries(include)) {
|
|
1546
1552
|
if (!arg) continue;
|
|
1547
1553
|
const expr = await this.relationExpr(sql, this.relation(name), relArgs(arg), owner, depth);
|
|
1548
|
-
out.push(sql`${expr} as ${sql.raw(
|
|
1554
|
+
out.push(sql`${expr} as ${sql.raw(_chunkNKLOE4AKcjs.q.call(void 0, incAlias(name)))}`);
|
|
1549
1555
|
}
|
|
1550
1556
|
return out;
|
|
1551
1557
|
}
|
|
@@ -1579,21 +1585,21 @@ var TableRuntime = (_class = class {
|
|
|
1579
1585
|
*/
|
|
1580
1586
|
relationSource(rel, owner, a, j) {
|
|
1581
1587
|
const T = runtimeOf(rel.target, `${this.name}.${rel.name}`);
|
|
1582
|
-
const target = `${
|
|
1583
|
-
const ownerId = `${owner}.${
|
|
1588
|
+
const target = `${_chunkNKLOE4AKcjs.q.call(void 0, T.tbl.table)} ${a}`;
|
|
1589
|
+
const ownerId = `${owner}.${_chunkNKLOE4AKcjs.q.call(void 0, "id")}`;
|
|
1584
1590
|
if (rel.via === "fk") {
|
|
1585
1591
|
return {
|
|
1586
1592
|
T,
|
|
1587
1593
|
from: target,
|
|
1588
|
-
cond: `${a}.${
|
|
1589
|
-
defaultOrder: `${a}.${
|
|
1594
|
+
cond: `${a}.${_chunkNKLOE4AKcjs.q.call(void 0, "id")} = ${owner}.${_chunkNKLOE4AKcjs.q.call(void 0, rel.column)}`,
|
|
1595
|
+
defaultOrder: `${a}.${_chunkNKLOE4AKcjs.q.call(void 0, "id")}`
|
|
1590
1596
|
};
|
|
1591
1597
|
}
|
|
1592
1598
|
let from;
|
|
1593
1599
|
let cond;
|
|
1594
1600
|
let defaultOrder;
|
|
1595
1601
|
if (rel.via === "join") {
|
|
1596
|
-
from = `${
|
|
1602
|
+
from = `${_chunkNKLOE4AKcjs.q.call(void 0, rel.join.table)} ${j} join ${target} on ${a}.${_chunkNKLOE4AKcjs.q.call(void 0, "id")} = ${j}.ref_id`;
|
|
1597
1603
|
cond = `${j}.owner_id = ${ownerId}`;
|
|
1598
1604
|
defaultOrder = `${j}.position`;
|
|
1599
1605
|
} else {
|
|
@@ -1611,7 +1617,7 @@ var TableRuntime = (_class = class {
|
|
|
1611
1617
|
`[EFC] ${this.name}.${rel.name}: ${rel.target}.${rel.foreignKey} is many-to-many \u2014 use hasMany`
|
|
1612
1618
|
);
|
|
1613
1619
|
}
|
|
1614
|
-
from = `${
|
|
1620
|
+
from = `${_chunkNKLOE4AKcjs.q.call(void 0, join.table)} ${j} join ${target} on ${a}.${_chunkNKLOE4AKcjs.q.call(void 0, "id")} = ${j}.owner_id`;
|
|
1615
1621
|
cond = `${j}.ref_id = ${ownerId}`;
|
|
1616
1622
|
} else {
|
|
1617
1623
|
if (rel.kind === "one" && !column.node.def.unique) {
|
|
@@ -1620,9 +1626,9 @@ var TableRuntime = (_class = class {
|
|
|
1620
1626
|
);
|
|
1621
1627
|
}
|
|
1622
1628
|
from = target;
|
|
1623
|
-
cond = `${a}.${
|
|
1629
|
+
cond = `${a}.${_chunkNKLOE4AKcjs.q.call(void 0, column.column)} = ${ownerId}`;
|
|
1624
1630
|
}
|
|
1625
|
-
defaultOrder = `${a}.${
|
|
1631
|
+
defaultOrder = `${a}.${_chunkNKLOE4AKcjs.q.call(void 0, "id")}`;
|
|
1626
1632
|
}
|
|
1627
1633
|
return { T, from, cond, defaultOrder };
|
|
1628
1634
|
}
|
|
@@ -1647,7 +1653,7 @@ var TableRuntime = (_class = class {
|
|
|
1647
1653
|
const where = isPlainObject(w) ? w : { id: w };
|
|
1648
1654
|
const found = await T.findUnique({ where, select: { id: true } });
|
|
1649
1655
|
if (!found) {
|
|
1650
|
-
throw new (0,
|
|
1656
|
+
throw new (0, _chunkNKLOE4AKcjs.ModelValidationError)(this.name, [
|
|
1651
1657
|
{ path, message: `no ${rel.target} matches ${JSON.stringify(where, idJson)}` }
|
|
1652
1658
|
]);
|
|
1653
1659
|
}
|
|
@@ -1739,8 +1745,8 @@ var TableRuntime = (_class = class {
|
|
|
1739
1745
|
try {
|
|
1740
1746
|
await T.updateNested({ where: whereOf(w), data: { [fk]: owner } });
|
|
1741
1747
|
} catch (err) {
|
|
1742
|
-
if (
|
|
1743
|
-
throw new (0,
|
|
1748
|
+
if (_chunkNKLOE4AKcjs.isHttpError.call(void 0, err) && err.statusCode === 404) {
|
|
1749
|
+
throw new (0, _chunkNKLOE4AKcjs.ModelValidationError)(this.name, [
|
|
1744
1750
|
{
|
|
1745
1751
|
path: key,
|
|
1746
1752
|
message: `no ${rel.target} matches ${JSON.stringify(whereOf(w), idJson)}`
|
|
@@ -1891,7 +1897,7 @@ var TableRuntime = (_class = class {
|
|
|
1891
1897
|
const a = `efc_f${++aliasSeq}`;
|
|
1892
1898
|
const { T, from, cond } = this.relationSource(
|
|
1893
1899
|
rel,
|
|
1894
|
-
_nullishCoalesce(owner, () => (
|
|
1900
|
+
_nullishCoalesce(owner, () => ( _chunkNKLOE4AKcjs.q.call(void 0, this.tbl.table))),
|
|
1895
1901
|
a,
|
|
1896
1902
|
`efc_fj${aliasSeq}`
|
|
1897
1903
|
);
|
|
@@ -2032,7 +2038,7 @@ var TableRuntime = (_class = class {
|
|
|
2032
2038
|
}
|
|
2033
2039
|
async orThrow(p) {
|
|
2034
2040
|
const r = await p;
|
|
2035
|
-
if (r === null) throw new (0,
|
|
2041
|
+
if (r === null) throw new (0, _chunkNKLOE4AKcjs.HttpError)(404, `${this.name} not found`);
|
|
2036
2042
|
return r;
|
|
2037
2043
|
}
|
|
2038
2044
|
async count(args = {}) {
|
|
@@ -2042,7 +2048,7 @@ var TableRuntime = (_class = class {
|
|
|
2042
2048
|
const counted = select ? Object.entries(select).filter(([f, on]) => on && (f === "_all" || this.spec(f))) : [["_all", true]];
|
|
2043
2049
|
const exprs = sql.join(
|
|
2044
2050
|
counted.map(
|
|
2045
|
-
([f]) => f === "_all" ? sql`count(*)::int as ${sql.raw(
|
|
2051
|
+
([f]) => f === "_all" ? sql`count(*)::int as ${sql.raw(_chunkNKLOE4AKcjs.q.call(void 0, "_all"))}` : sql`count(${this.col(sql, f, "efc_rows")})::int as ${sql.raw(_chunkNKLOE4AKcjs.q.call(void 0, f))}`
|
|
2046
2052
|
),
|
|
2047
2053
|
sql`, `
|
|
2048
2054
|
);
|
|
@@ -2117,7 +2123,7 @@ var TableRuntime = (_class = class {
|
|
|
2117
2123
|
const specs = this.aggregateSpec(args);
|
|
2118
2124
|
if (specs.length === 0) return {};
|
|
2119
2125
|
const exprs = sql.join(
|
|
2120
|
-
specs.map((s) => sql`${this.aggregateExpr(sql, s.agg, s.field)} as ${sql.raw(
|
|
2126
|
+
specs.map((s) => sql`${this.aggregateExpr(sql, s.agg, s.field)} as ${sql.raw(_chunkNKLOE4AKcjs.q.call(void 0, s.alias))}`),
|
|
2121
2127
|
sql`, `
|
|
2122
2128
|
);
|
|
2123
2129
|
const { query } = this.readQuery(sql, t, { ...args, select: void 0 }, sql`*`);
|
|
@@ -2175,7 +2181,7 @@ var TableRuntime = (_class = class {
|
|
|
2175
2181
|
[
|
|
2176
2182
|
...by.map((f) => this.col(sql, f)),
|
|
2177
2183
|
...specs.map(
|
|
2178
|
-
(s) => sql`${this.aggregateExpr(sql, s.agg, s.field)} as ${sql.raw(
|
|
2184
|
+
(s) => sql`${this.aggregateExpr(sql, s.agg, s.field)} as ${sql.raw(_chunkNKLOE4AKcjs.q.call(void 0, s.alias))}`
|
|
2179
2185
|
)
|
|
2180
2186
|
],
|
|
2181
2187
|
sql`, `
|
|
@@ -2199,7 +2205,7 @@ var TableRuntime = (_class = class {
|
|
|
2199
2205
|
}
|
|
2200
2206
|
}
|
|
2201
2207
|
}
|
|
2202
|
-
const query = sql`select ${select} from ${sql.raw(
|
|
2208
|
+
const query = sql`select ${select} from ${sql.raw(_chunkNKLOE4AKcjs.q.call(void 0, this.tbl.table))}${where ? sql` where ${where}` : sql``} group by ${sql.join(
|
|
2203
2209
|
by.map((f) => this.col(sql, f)),
|
|
2204
2210
|
sql`, `
|
|
2205
2211
|
)}${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``}`;
|
|
@@ -2277,7 +2283,7 @@ var TableRuntime = (_class = class {
|
|
|
2277
2283
|
}
|
|
2278
2284
|
}
|
|
2279
2285
|
}
|
|
2280
|
-
if (issues.length) throw new (0,
|
|
2286
|
+
if (issues.length) throw new (0, _chunkNKLOE4AKcjs.ModelValidationError)(this.name, issues);
|
|
2281
2287
|
await this.tbl.validate(plain, true);
|
|
2282
2288
|
for (const [field, v] of Object.entries(plain)) {
|
|
2283
2289
|
sets.push(
|
|
@@ -2319,7 +2325,7 @@ var TableRuntime = (_class = class {
|
|
|
2319
2325
|
}
|
|
2320
2326
|
for (const [field, entries] of byField) {
|
|
2321
2327
|
const join = this.join(field);
|
|
2322
|
-
const jt = sql.raw(
|
|
2328
|
+
const jt = sql.raw(_chunkNKLOE4AKcjs.q.call(void 0, join.table));
|
|
2323
2329
|
const sets = entries.filter((e) => e.op.mode === "set");
|
|
2324
2330
|
if (sets.length) {
|
|
2325
2331
|
const owners2 = sets.map((e) => idText(e.id));
|
|
@@ -2366,7 +2372,7 @@ var TableRuntime = (_class = class {
|
|
|
2366
2372
|
const idDdl = this.tbl.columns.get("id").ddl;
|
|
2367
2373
|
const owners = sql`${sql.param(ids.map(idText))}::${sql.raw(idDdl)}[]`;
|
|
2368
2374
|
const parts = joins.map(
|
|
2369
|
-
(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(
|
|
2375
|
+
(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(_chunkNKLOE4AKcjs.q.call(void 0, j.table))} where owner_id = any(${owners}) group by owner_id`
|
|
2370
2376
|
);
|
|
2371
2377
|
const { rows } = await this.exec(sql.join(parts, sql` union all `));
|
|
2372
2378
|
for (const j of joins) out.set(j.field, /* @__PURE__ */ new Map());
|
|
@@ -2388,7 +2394,7 @@ var TableRuntime = (_class = class {
|
|
|
2388
2394
|
}
|
|
2389
2395
|
insertSql(sql, t, rows) {
|
|
2390
2396
|
const fields = [...new Set(rows.flatMap((r) => Object.keys(r)))];
|
|
2391
|
-
const head = sql`insert into ${sql.raw(
|
|
2397
|
+
const head = sql`insert into ${sql.raw(_chunkNKLOE4AKcjs.q.call(void 0, this.tbl.table))} (${sql.join(
|
|
2392
2398
|
fields.map((f) => this.col(sql, f)),
|
|
2393
2399
|
sql`, `
|
|
2394
2400
|
)})`;
|
|
@@ -2485,7 +2491,7 @@ var TableRuntime = (_class = class {
|
|
|
2485
2491
|
return;
|
|
2486
2492
|
}
|
|
2487
2493
|
const { rows: ids } = await this.exec(
|
|
2488
|
-
sql`select nextval(pg_get_serial_sequence(${sql.param(
|
|
2494
|
+
sql`select nextval(pg_get_serial_sequence(${sql.param(_chunkNKLOE4AKcjs.q.call(void 0, this.tbl.table))}, 'id'))::text as id from generate_series(1, ${sql.param(missing.length)})`
|
|
2489
2495
|
);
|
|
2490
2496
|
missing.forEach((r, i) => {
|
|
2491
2497
|
const id = ids[i]["id"];
|
|
@@ -2514,9 +2520,9 @@ var TableRuntime = (_class = class {
|
|
|
2514
2520
|
const where = this.where(sql, t, args["where"]);
|
|
2515
2521
|
const links = this.joinColumns(sql, [...this.tbl.joins.keys()]);
|
|
2516
2522
|
const extra = links.length ? sql`, ${sql.join(links, sql`, `)}` : sql``;
|
|
2517
|
-
const query = sets.length ? sql`update ${sql.raw(
|
|
2523
|
+
const query = sets.length ? sql`update ${sql.raw(_chunkNKLOE4AKcjs.q.call(void 0, this.tbl.table))} set ${sql.join(sets, sql`, `)} where ${where} returning *${extra}` : sql`select *${extra} from ${sql.raw(_chunkNKLOE4AKcjs.q.call(void 0, this.tbl.table))} where ${where} limit 1`;
|
|
2518
2524
|
const [row] = (await this.exec(query)).rows;
|
|
2519
|
-
if (!row) throw new (0,
|
|
2525
|
+
if (!row) throw new (0, _chunkNKLOE4AKcjs.HttpError)(404, `${this.name} not found`);
|
|
2520
2526
|
const record = this.fromRaw(t, row);
|
|
2521
2527
|
await this.applyJoins(sql, [{ id: record["id"], ops: joinOps }]);
|
|
2522
2528
|
await this.refreshJoins(sql, [record], joinOps);
|
|
@@ -2537,7 +2543,7 @@ var TableRuntime = (_class = class {
|
|
|
2537
2543
|
const links = returning ? this.joinColumns(sql, [...this.tbl.joins.keys()]) : [];
|
|
2538
2544
|
const list = returning ? sql` returning *${links.length ? sql`, ${sql.join(links, sql`, `)}` : sql``}` : joinOps.length ? sql` returning ${this.col(sql, "id")}` : sql``;
|
|
2539
2545
|
const result = await this.exec(
|
|
2540
|
-
sets.length ? sql`update ${sql.raw(
|
|
2546
|
+
sets.length ? sql`update ${sql.raw(_chunkNKLOE4AKcjs.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(_chunkNKLOE4AKcjs.q.call(void 0, this.tbl.table))} where ${where}`
|
|
2541
2547
|
);
|
|
2542
2548
|
const records = result.rows.map((r) => returning ? this.fromRaw(t, r) : r);
|
|
2543
2549
|
await this.applyJoins(
|
|
@@ -2561,7 +2567,7 @@ var TableRuntime = (_class = class {
|
|
|
2561
2567
|
if (row[f] === void 0) row[f] = this.tbl.toDb(f, args["where"][f]);
|
|
2562
2568
|
}
|
|
2563
2569
|
const { head, values } = this.insertSql(sql, t, [row]);
|
|
2564
|
-
const table =
|
|
2570
|
+
const table = _chunkNKLOE4AKcjs.q.call(void 0, this.tbl.table);
|
|
2565
2571
|
const update = await this.setList(sql, t, _nullishCoalesce(args["update"], () => ( {})), table);
|
|
2566
2572
|
const { joinOps } = update;
|
|
2567
2573
|
let { sets } = update;
|
|
@@ -2582,7 +2588,7 @@ var TableRuntime = (_class = class {
|
|
|
2582
2588
|
const [out] = (await this.exec(
|
|
2583
2589
|
sql`${head} values ${values} on conflict (${target}) do update set ${sql.join(sets, sql`, `)}${cond}${returning}`
|
|
2584
2590
|
)).rows;
|
|
2585
|
-
if (!out) throw new (0,
|
|
2591
|
+
if (!out) throw new (0, _chunkNKLOE4AKcjs.HttpError)(404, `${this.name} not found`);
|
|
2586
2592
|
const record = this.fromRaw(t, out);
|
|
2587
2593
|
if (linked) {
|
|
2588
2594
|
const ops = out["efc_inserted"] ? createOps.filter((o) => o.items.length) : joinOps;
|
|
@@ -2601,9 +2607,9 @@ var TableRuntime = (_class = class {
|
|
|
2601
2607
|
const where = this.where(sql, t, args["where"]);
|
|
2602
2608
|
const links = this.joinColumns(sql, [...this.tbl.joins.keys()]);
|
|
2603
2609
|
const [row] = (await this.exec(
|
|
2604
|
-
sql`delete from ${sql.raw(
|
|
2610
|
+
sql`delete from ${sql.raw(_chunkNKLOE4AKcjs.q.call(void 0, this.tbl.table))} where ${where} returning *${links.length ? sql`, ${sql.join(links, sql`, `)}` : sql``}`
|
|
2605
2611
|
)).rows;
|
|
2606
|
-
if (!row) throw new (0,
|
|
2612
|
+
if (!row) throw new (0, _chunkNKLOE4AKcjs.HttpError)(404, `${this.name} not found`);
|
|
2607
2613
|
return this.project(this.fromRaw(t, row), this.projection(args));
|
|
2608
2614
|
});
|
|
2609
2615
|
}
|
|
@@ -2611,7 +2617,7 @@ var TableRuntime = (_class = class {
|
|
|
2611
2617
|
const { t, sql } = await this.ready(args["where"]);
|
|
2612
2618
|
return this.tbl.guard(async () => {
|
|
2613
2619
|
const where = _nullishCoalesce(this.where(sql, t, args["where"]), () => ( sql`true`));
|
|
2614
|
-
const result = await this.tbl.client().execute(sql`delete from ${sql.raw(
|
|
2620
|
+
const result = await this.tbl.client().execute(sql`delete from ${sql.raw(_chunkNKLOE4AKcjs.q.call(void 0, this.tbl.table))} where ${where}`);
|
|
2615
2621
|
return { count: _nullishCoalesce(result.rowCount, () => ( 0)) };
|
|
2616
2622
|
});
|
|
2617
2623
|
}
|
|
@@ -2620,10 +2626,10 @@ function relArgs(arg) {
|
|
|
2620
2626
|
return isPlainObject(arg) ? arg : {};
|
|
2621
2627
|
}
|
|
2622
2628
|
function runtimeOf(name, from) {
|
|
2623
|
-
const runtime = _optionalChain([
|
|
2629
|
+
const runtime = _optionalChain([_chunkNKLOE4AKcjs.getRegisteredModel.call(void 0, name), 'optionalAccess', _65 => _65.tableRuntime, 'optionalCall', _66 => _66()]);
|
|
2624
2630
|
if (!runtime) {
|
|
2625
2631
|
throw new Error(
|
|
2626
|
-
|
|
2632
|
+
_chunkNKLOE4AKcjs.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`
|
|
2627
2633
|
);
|
|
2628
2634
|
}
|
|
2629
2635
|
return runtime;
|
|
@@ -2643,7 +2649,7 @@ var JSON_OPS = /* @__PURE__ */ new Set([
|
|
|
2643
2649
|
"mode"
|
|
2644
2650
|
]);
|
|
2645
2651
|
function createTable(name, schema, options = {}) {
|
|
2646
|
-
|
|
2652
|
+
_chunkNKLOE4AKcjs.normalizeSchema.call(void 0, schema, "table", name);
|
|
2647
2653
|
for (const [rel, def] of Object.entries(_nullishCoalesce(options.relations, () => ( {})))) {
|
|
2648
2654
|
const where = `[EFC] ${name}.relations.${rel}`;
|
|
2649
2655
|
if (rel in schema) throw new Error(`${where}: a field already has this name`);
|
|
@@ -2658,7 +2664,7 @@ function createTable(name, schema, options = {}) {
|
|
|
2658
2664
|
}
|
|
2659
2665
|
let runtime;
|
|
2660
2666
|
const rt = () => {
|
|
2661
|
-
const engine =
|
|
2667
|
+
const engine = _chunkNKLOE4AKcjs.getDbEngine.call(void 0, );
|
|
2662
2668
|
if (engine !== "postgresql") {
|
|
2663
2669
|
throw new Error(
|
|
2664
2670
|
`[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`
|
|
@@ -2695,14 +2701,23 @@ function createTable(name, schema, options = {}) {
|
|
|
2695
2701
|
model,
|
|
2696
2702
|
Object.keys(model).filter((op) => !["name", "raw", "sync", "drop"].includes(op))
|
|
2697
2703
|
);
|
|
2698
|
-
|
|
2704
|
+
_chunkNKLOE4AKcjs.registerModel.call(void 0, {
|
|
2699
2705
|
name,
|
|
2700
2706
|
sync: model.sync,
|
|
2701
2707
|
plan: (opts) => call((r) => r.tbl.plan(opts)),
|
|
2702
2708
|
drop: model.drop,
|
|
2703
2709
|
findByIds: (ids) => model.findMany({ where: { id: { in: ids } } }),
|
|
2704
2710
|
pgTarget: () => ({ table: rt().tbl.table, idKind: rt().tbl.idKind }),
|
|
2705
|
-
tableRuntime: () => rt()
|
|
2711
|
+
tableRuntime: () => rt(),
|
|
2712
|
+
studio: /* @__PURE__ */ (() => {
|
|
2713
|
+
const idOf = (id) => rt().tbl.idKind === "serial" ? Number(id) : rt().tbl.idKind === "bigserial" ? BigInt(id) : id;
|
|
2714
|
+
return {
|
|
2715
|
+
storage: async () => rt().tbl.table,
|
|
2716
|
+
create: (data) => model.create({ data }),
|
|
2717
|
+
update: (id, data) => model.update({ where: { id: idOf(id) }, data }),
|
|
2718
|
+
delete: (id) => model.delete({ where: { id: idOf(id) } })
|
|
2719
|
+
};
|
|
2720
|
+
})()
|
|
2706
2721
|
});
|
|
2707
2722
|
return model;
|
|
2708
2723
|
}
|
|
@@ -2710,6 +2725,129 @@ function defineTable(name, schema, options) {
|
|
|
2710
2725
|
return createTable(name, schema, _nullishCoalesce(options, () => ( {})));
|
|
2711
2726
|
}
|
|
2712
2727
|
|
|
2728
|
+
// src/db/pipeline.ts
|
|
2729
|
+
var Pipeline = class _Pipeline {
|
|
2730
|
+
/** @internal */
|
|
2731
|
+
constructor(run, stages = []) {
|
|
2732
|
+
this.run = run;
|
|
2733
|
+
this.stages = stages;
|
|
2734
|
+
}
|
|
2735
|
+
|
|
2736
|
+
|
|
2737
|
+
next(...stage) {
|
|
2738
|
+
return new _Pipeline(this.run, [...this.stages, ...stage]);
|
|
2739
|
+
}
|
|
2740
|
+
/** `$match` — same filter vocabulary as `find`. */
|
|
2741
|
+
match(filter) {
|
|
2742
|
+
return this.next({ $match: filter });
|
|
2743
|
+
}
|
|
2744
|
+
sort(spec) {
|
|
2745
|
+
return this.next({ $sort: spec });
|
|
2746
|
+
}
|
|
2747
|
+
skip(n) {
|
|
2748
|
+
return this.next({ $skip: n });
|
|
2749
|
+
}
|
|
2750
|
+
limit(n) {
|
|
2751
|
+
return this.next({ $limit: n });
|
|
2752
|
+
}
|
|
2753
|
+
/** `$sample` — `n` random records. */
|
|
2754
|
+
sample(n) {
|
|
2755
|
+
return this.next({ $sample: { size: n } });
|
|
2756
|
+
}
|
|
2757
|
+
/** `$project` with an inclusion spec: the result has only those fields (and `id`). */
|
|
2758
|
+
project(spec) {
|
|
2759
|
+
return this.next({ $project: spec });
|
|
2760
|
+
}
|
|
2761
|
+
/**
|
|
2762
|
+
* `$unwind` an array field: one result per element, the field holding that element.
|
|
2763
|
+
* `preserveNullAndEmptyArrays` keeps records without elements (the field is then null).
|
|
2764
|
+
*/
|
|
2765
|
+
unwind(path, options) {
|
|
2766
|
+
return this.next(
|
|
2767
|
+
_optionalChain([options, 'optionalAccess', _72 => _72.preserveNullAndEmptyArrays]) ? { $unwind: { path, preserveNullAndEmptyArrays: true } } : { $unwind: path }
|
|
2768
|
+
);
|
|
2769
|
+
}
|
|
2770
|
+
/** `$group` — `_id` is `'$field'`, `null` or `{ key: '$field' }`; accumulators are typed. */
|
|
2771
|
+
group(spec) {
|
|
2772
|
+
return this.next({ $group: spec });
|
|
2773
|
+
}
|
|
2774
|
+
/** `$count` — a single `{ [field]: n }` (no result at all when nothing matched). */
|
|
2775
|
+
count(field) {
|
|
2776
|
+
return this.next({ $count: field });
|
|
2777
|
+
}
|
|
2778
|
+
/** `$addFields` / `$set` — say what the new fields are: `addFields<{ total: number }>({ … })`. */
|
|
2779
|
+
addFields(spec) {
|
|
2780
|
+
return this.next({ $addFields: spec });
|
|
2781
|
+
}
|
|
2782
|
+
lookup(a, b) {
|
|
2783
|
+
const idField = (f) => f === "id" ? "_id" : f;
|
|
2784
|
+
if (typeof a === "string") {
|
|
2785
|
+
const field = a;
|
|
2786
|
+
const target2 = b;
|
|
2787
|
+
const isArray = `__efc_isarr_${field.replace(/\./g, "_")}`;
|
|
2788
|
+
return this.next(async () => [
|
|
2789
|
+
{ $set: { [isArray]: { $isArray: `$${field}` } } },
|
|
2790
|
+
{
|
|
2791
|
+
$lookup: {
|
|
2792
|
+
from: await collectionOf(target2),
|
|
2793
|
+
localField: field,
|
|
2794
|
+
foreignField: "_id",
|
|
2795
|
+
as: field
|
|
2796
|
+
}
|
|
2797
|
+
},
|
|
2798
|
+
{
|
|
2799
|
+
$set: {
|
|
2800
|
+
[field]: {
|
|
2801
|
+
$cond: [
|
|
2802
|
+
`$${isArray}`,
|
|
2803
|
+
`$${field}`,
|
|
2804
|
+
{ $ifNull: [{ $arrayElemAt: [`$${field}`, 0] }, null] }
|
|
2805
|
+
]
|
|
2806
|
+
}
|
|
2807
|
+
}
|
|
2808
|
+
},
|
|
2809
|
+
{ $unset: isArray }
|
|
2810
|
+
]);
|
|
2811
|
+
}
|
|
2812
|
+
const { from: target, localField, foreignField, as } = a;
|
|
2813
|
+
return this.next(async () => [
|
|
2814
|
+
{
|
|
2815
|
+
$lookup: {
|
|
2816
|
+
from: await collectionOf(target),
|
|
2817
|
+
localField: idField(localField),
|
|
2818
|
+
foreignField: idField(foreignField),
|
|
2819
|
+
as
|
|
2820
|
+
}
|
|
2821
|
+
}
|
|
2822
|
+
]);
|
|
2823
|
+
}
|
|
2824
|
+
/** Any other stage, with its output type spelled out: `stage<{ … }>({ $facet: … })`. */
|
|
2825
|
+
stage(stage) {
|
|
2826
|
+
return this.next(stage);
|
|
2827
|
+
}
|
|
2828
|
+
/** The stages as plain objects (lookups resolved to collection names). */
|
|
2829
|
+
async toArray() {
|
|
2830
|
+
const out = [];
|
|
2831
|
+
for (const s of this.stages) {
|
|
2832
|
+
if (typeof s === "function") out.push(...await s());
|
|
2833
|
+
else out.push(s);
|
|
2834
|
+
}
|
|
2835
|
+
return out;
|
|
2836
|
+
}
|
|
2837
|
+
async exec() {
|
|
2838
|
+
return await this.run(await this.toArray());
|
|
2839
|
+
}
|
|
2840
|
+
then(onfulfilled, onrejected) {
|
|
2841
|
+
return this.exec().then(onfulfilled, onrejected);
|
|
2842
|
+
}
|
|
2843
|
+
};
|
|
2844
|
+
async function collectionOf(target) {
|
|
2845
|
+
const model = await target.raw();
|
|
2846
|
+
const name = _nullishCoalesce(_optionalChain([model, 'access', _73 => _73.collection, 'optionalAccess', _74 => _74.collectionName]), () => ( _optionalChain([model, 'access', _75 => _75.collection, 'optionalAccess', _76 => _76.name])));
|
|
2847
|
+
if (!name) throw new Error(`[EFC] lookup: can't find the collection behind ${target.name}`);
|
|
2848
|
+
return name;
|
|
2849
|
+
}
|
|
2850
|
+
|
|
2713
2851
|
// src/db/collection-model.ts
|
|
2714
2852
|
function fromBson(value) {
|
|
2715
2853
|
if (Array.isArray(value)) return value.map(fromBson);
|
|
@@ -2769,7 +2907,7 @@ function mapBulkOp(op) {
|
|
|
2769
2907
|
return { [kind]: b };
|
|
2770
2908
|
}
|
|
2771
2909
|
function createCollection(name, schema, options) {
|
|
2772
|
-
const tree =
|
|
2910
|
+
const tree = _chunkNKLOE4AKcjs.normalizeSchema.call(void 0, schema, "collection", name);
|
|
2773
2911
|
const base = mongoModel(name, tree, options);
|
|
2774
2912
|
const longs = hasLong(tree);
|
|
2775
2913
|
const toRecord = (doc) => {
|
|
@@ -2778,7 +2916,7 @@ function createCollection(name, schema, options) {
|
|
|
2778
2916
|
return longs ? castTree(rec, tree) : rec;
|
|
2779
2917
|
};
|
|
2780
2918
|
const model = async () => {
|
|
2781
|
-
const engine =
|
|
2919
|
+
const engine = _chunkNKLOE4AKcjs.getDbEngine.call(void 0, );
|
|
2782
2920
|
if (engine !== "mongodb") {
|
|
2783
2921
|
throw new Error(
|
|
2784
2922
|
`[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`
|
|
@@ -2787,13 +2925,33 @@ function createCollection(name, schema, options) {
|
|
|
2787
2925
|
return await base.raw();
|
|
2788
2926
|
};
|
|
2789
2927
|
const session = () => {
|
|
2790
|
-
const tx =
|
|
2791
|
-
return _optionalChain([tx, 'optionalAccess',
|
|
2928
|
+
const tx = _chunkNKLOE4AKcjs.currentTx.call(void 0, );
|
|
2929
|
+
return _optionalChain([tx, 'optionalAccess', _77 => _77.engine]) === "mongodb" ? tx.session : null;
|
|
2792
2930
|
};
|
|
2793
2931
|
const sess = () => {
|
|
2794
2932
|
const s = session();
|
|
2795
2933
|
return s ? { session: s } : {};
|
|
2796
2934
|
};
|
|
2935
|
+
const runPipeline = (stages) => guard(async (M) => {
|
|
2936
|
+
let sourceShape = true;
|
|
2937
|
+
const prepared = stages.map((stage) => {
|
|
2938
|
+
const [op] = Object.keys(stage);
|
|
2939
|
+
if (!sourceShape) return stage;
|
|
2940
|
+
if (op === "$match") {
|
|
2941
|
+
const filter = mapFilter(stage["$match"]);
|
|
2942
|
+
return { $match: M.find().cast(M, filter) };
|
|
2943
|
+
}
|
|
2944
|
+
if (op === "$sort") return { $sort: mapSort(stage["$sort"]) };
|
|
2945
|
+
if (op !== "$skip" && op !== "$limit" && op !== "$sample") sourceShape = false;
|
|
2946
|
+
return stage;
|
|
2947
|
+
});
|
|
2948
|
+
const agg = M.aggregate(prepared);
|
|
2949
|
+
const s = session();
|
|
2950
|
+
if (s) agg.session(s);
|
|
2951
|
+
if (options.collation)
|
|
2952
|
+
agg.collation(options.collation);
|
|
2953
|
+
return (await agg).map(toRecord);
|
|
2954
|
+
});
|
|
2797
2955
|
const guard = async (fn) => {
|
|
2798
2956
|
const M = await model();
|
|
2799
2957
|
try {
|
|
@@ -2803,22 +2961,22 @@ function createCollection(name, schema, options) {
|
|
|
2803
2961
|
}
|
|
2804
2962
|
};
|
|
2805
2963
|
const findOpts = (q2, opts) => {
|
|
2806
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
2807
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
2964
|
+
if (_optionalChain([opts, 'optionalAccess', _78 => _78.projection])) q2.select(opts.projection);
|
|
2965
|
+
if (_optionalChain([opts, 'optionalAccess', _79 => _79.sort])) {
|
|
2808
2966
|
const meta = Object.values(opts.sort).some((v) => typeof v === "object");
|
|
2809
2967
|
q2.sort(meta ? opts.sort : mapSort(opts.sort));
|
|
2810
2968
|
}
|
|
2811
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
2812
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
2813
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
2814
|
-
const collation = _nullishCoalesce(_optionalChain([opts, 'optionalAccess',
|
|
2969
|
+
if (_optionalChain([opts, 'optionalAccess', _80 => _80.skip]) !== void 0) q2.skip(opts.skip);
|
|
2970
|
+
if (_optionalChain([opts, 'optionalAccess', _81 => _81.limit]) !== void 0) q2.limit(opts.limit);
|
|
2971
|
+
if (_optionalChain([opts, 'optionalAccess', _82 => _82.populate])) q2.populate(opts.populate);
|
|
2972
|
+
const collation = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _83 => _83.collation]), () => ( options.collation));
|
|
2815
2973
|
if (collation) q2.collation(collation);
|
|
2816
2974
|
q2.session(session());
|
|
2817
2975
|
return q2;
|
|
2818
2976
|
};
|
|
2819
2977
|
const isBadId = (err) => {
|
|
2820
2978
|
const e = err;
|
|
2821
|
-
return _optionalChain([e, 'optionalAccess',
|
|
2979
|
+
return _optionalChain([e, 'optionalAccess', _84 => _84.name]) === "CastError" && e.path === "_id";
|
|
2822
2980
|
};
|
|
2823
2981
|
const model$ = {
|
|
2824
2982
|
name,
|
|
@@ -2859,7 +3017,7 @@ function createCollection(name, schema, options) {
|
|
|
2859
3017
|
async (M) => writeResult(
|
|
2860
3018
|
await M.updateOne(mapFilter(filter), update, {
|
|
2861
3019
|
runValidators: true,
|
|
2862
|
-
upsert: _nullishCoalesce(_optionalChain([opts, 'optionalAccess',
|
|
3020
|
+
upsert: _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _85 => _85.upsert]), () => ( false)),
|
|
2863
3021
|
...sess()
|
|
2864
3022
|
})
|
|
2865
3023
|
)
|
|
@@ -2868,7 +3026,7 @@ function createCollection(name, schema, options) {
|
|
|
2868
3026
|
async (M) => writeResult(
|
|
2869
3027
|
await M.updateMany(mapFilter(filter), update, {
|
|
2870
3028
|
runValidators: true,
|
|
2871
|
-
upsert: _nullishCoalesce(_optionalChain([opts, 'optionalAccess',
|
|
3029
|
+
upsert: _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _86 => _86.upsert]), () => ( false)),
|
|
2872
3030
|
...sess()
|
|
2873
3031
|
})
|
|
2874
3032
|
)
|
|
@@ -2877,7 +3035,7 @@ function createCollection(name, schema, options) {
|
|
|
2877
3035
|
async (M) => writeResult(
|
|
2878
3036
|
await M.replaceOne(mapFilter(filter), replacement, {
|
|
2879
3037
|
runValidators: true,
|
|
2880
|
-
upsert: _nullishCoalesce(_optionalChain([opts, 'optionalAccess',
|
|
3038
|
+
upsert: _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _87 => _87.upsert]), () => ( false)),
|
|
2881
3039
|
...sess()
|
|
2882
3040
|
})
|
|
2883
3041
|
)
|
|
@@ -2886,10 +3044,10 @@ function createCollection(name, schema, options) {
|
|
|
2886
3044
|
async (M) => toRecord(
|
|
2887
3045
|
await M.findOneAndUpdate(mapFilter(filter), update, {
|
|
2888
3046
|
runValidators: true,
|
|
2889
|
-
upsert: _nullishCoalesce(_optionalChain([opts, 'optionalAccess',
|
|
2890
|
-
returnDocument: _nullishCoalesce(_optionalChain([opts, 'optionalAccess',
|
|
2891
|
-
..._optionalChain([opts, 'optionalAccess',
|
|
2892
|
-
..._optionalChain([opts, 'optionalAccess',
|
|
3047
|
+
upsert: _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _88 => _88.upsert]), () => ( false)),
|
|
3048
|
+
returnDocument: _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _89 => _89.returnDocument]), () => ( "before")),
|
|
3049
|
+
..._optionalChain([opts, 'optionalAccess', _90 => _90.projection]) && { projection: opts.projection },
|
|
3050
|
+
..._optionalChain([opts, 'optionalAccess', _91 => _91.sort]) && { sort: opts.sort },
|
|
2893
3051
|
...sess()
|
|
2894
3052
|
}).lean()
|
|
2895
3053
|
)
|
|
@@ -2899,7 +3057,7 @@ function createCollection(name, schema, options) {
|
|
|
2899
3057
|
return toRecord(
|
|
2900
3058
|
await M.findByIdAndUpdate(id, update, {
|
|
2901
3059
|
runValidators: true,
|
|
2902
|
-
returnDocument: _nullishCoalesce(_optionalChain([opts, 'optionalAccess',
|
|
3060
|
+
returnDocument: _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _92 => _92.returnDocument]), () => ( "before")),
|
|
2903
3061
|
...sess()
|
|
2904
3062
|
}).lean()
|
|
2905
3063
|
);
|
|
@@ -2911,7 +3069,7 @@ function createCollection(name, schema, options) {
|
|
|
2911
3069
|
findOneAndDelete: (filter, opts) => guard(
|
|
2912
3070
|
async (M) => toRecord(
|
|
2913
3071
|
await M.findOneAndDelete(mapFilter(filter), {
|
|
2914
|
-
..._optionalChain([opts, 'optionalAccess',
|
|
3072
|
+
..._optionalChain([opts, 'optionalAccess', _93 => _93.sort]) && { sort: opts.sort },
|
|
2915
3073
|
...sess()
|
|
2916
3074
|
}).lean()
|
|
2917
3075
|
)
|
|
@@ -2938,6 +3096,8 @@ function createCollection(name, schema, options) {
|
|
|
2938
3096
|
agg.collation(options.collation);
|
|
2939
3097
|
return (await agg).map(toRecord);
|
|
2940
3098
|
}),
|
|
3099
|
+
pipeline: () => new Pipeline(runPipeline),
|
|
3100
|
+
lookup: (field, target, filter) => new Pipeline(runPipeline).match(_nullishCoalesce(filter, () => ( {}))).lookup(field, target).exec(),
|
|
2941
3101
|
bulkWrite: (ops, opts) => guard(async (M) => {
|
|
2942
3102
|
if (ops.length === 0) {
|
|
2943
3103
|
return {
|
|
@@ -2951,7 +3111,7 @@ function createCollection(name, schema, options) {
|
|
|
2951
3111
|
const r = await M.bulkWrite(
|
|
2952
3112
|
ops.map(mapBulkOp),
|
|
2953
3113
|
{
|
|
2954
|
-
ordered: _nullishCoalesce(_optionalChain([opts, 'optionalAccess',
|
|
3114
|
+
ordered: _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _94 => _94.ordered]), () => ( true)),
|
|
2955
3115
|
runValidators: true,
|
|
2956
3116
|
...sess()
|
|
2957
3117
|
}
|
|
@@ -2970,13 +3130,13 @@ function createCollection(name, schema, options) {
|
|
|
2970
3130
|
const open = async () => {
|
|
2971
3131
|
const M = await model();
|
|
2972
3132
|
stream ??= M.watch(pipeline, {
|
|
2973
|
-
..._optionalChain([opts, 'optionalAccess',
|
|
3133
|
+
..._optionalChain([opts, 'optionalAccess', _95 => _95.fullDocument]) && { fullDocument: opts.fullDocument }
|
|
2974
3134
|
});
|
|
2975
3135
|
return stream;
|
|
2976
3136
|
};
|
|
2977
3137
|
const close = async () => {
|
|
2978
3138
|
closed = true;
|
|
2979
|
-
await _optionalChain([stream, 'optionalAccess',
|
|
3139
|
+
await _optionalChain([stream, 'optionalAccess', _96 => _96.close, 'call', _97 => _97()]);
|
|
2980
3140
|
};
|
|
2981
3141
|
return {
|
|
2982
3142
|
close,
|
|
@@ -2992,7 +3152,7 @@ function createCollection(name, schema, options) {
|
|
|
2992
3152
|
const key = change["documentKey"];
|
|
2993
3153
|
yield {
|
|
2994
3154
|
operationType: String(change["operationType"]),
|
|
2995
|
-
id: _optionalChain([key, 'optionalAccess',
|
|
3155
|
+
id: _optionalChain([key, 'optionalAccess', _98 => _98._id]) == null ? void 0 : String(key._id),
|
|
2996
3156
|
...change["fullDocument"] != null && {
|
|
2997
3157
|
fullDocument: toRecord(change["fullDocument"])
|
|
2998
3158
|
},
|
|
@@ -3017,7 +3177,7 @@ function createCollection(name, schema, options) {
|
|
|
3017
3177
|
model$,
|
|
3018
3178
|
Object.keys(model$).filter((op) => !["name", "raw", "sync", "drop", "watch"].includes(op))
|
|
3019
3179
|
);
|
|
3020
|
-
|
|
3180
|
+
_chunkNKLOE4AKcjs.registerModel.call(void 0, {
|
|
3021
3181
|
name,
|
|
3022
3182
|
sync: model$.sync,
|
|
3023
3183
|
plan: (opts) => model().then(() => base.plan(opts)),
|
|
@@ -3025,6 +3185,12 @@ function createCollection(name, schema, options) {
|
|
|
3025
3185
|
findByIds: (ids) => model$.find({ _id: { $in: ids } }),
|
|
3026
3186
|
pgTarget: () => {
|
|
3027
3187
|
throw new Error(`[EFC] ${name} is a MongoDB collection (defineCollection)`);
|
|
3188
|
+
},
|
|
3189
|
+
studio: {
|
|
3190
|
+
storage: async () => (await model()).collection.collectionName,
|
|
3191
|
+
create: (data) => model$.create(data),
|
|
3192
|
+
update: (id, data) => model$.findByIdAndUpdate(id, data, { returnDocument: "after" }),
|
|
3193
|
+
delete: (id) => model$.findByIdAndDelete(id)
|
|
3028
3194
|
}
|
|
3029
3195
|
});
|
|
3030
3196
|
return model$;
|
|
@@ -3065,5 +3231,6 @@ var db = new Proxy({}, {
|
|
|
3065
3231
|
|
|
3066
3232
|
|
|
3067
3233
|
|
|
3068
|
-
|
|
3069
|
-
|
|
3234
|
+
|
|
3235
|
+
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;
|
|
3236
|
+
//# sourceMappingURL=chunk-HBCY7ILD.cjs.map
|