express-file-cluster 0.9.2 → 0.9.6
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 +4 -5
- package/dist/auth/index.cjs.map +1 -1
- package/dist/auth/index.d.cts +7 -2
- package/dist/auth/index.d.ts +7 -2
- package/dist/auth/index.js +3 -4
- package/dist/{chunk-ATL4GYFU.js → chunk-2SETEVMO.js} +10 -8
- package/dist/{chunk-ATL4GYFU.js.map → chunk-2SETEVMO.js.map} +1 -1
- package/dist/{chunk-UBQYQPBU.js → chunk-45BWAR6P.js} +2 -2
- package/dist/{chunk-TYR2GZZE.cjs → chunk-6KHBJOLB.cjs} +13 -8
- package/dist/chunk-6KHBJOLB.cjs.map +1 -0
- package/dist/chunk-73XJUT2S.js +366 -0
- package/dist/chunk-73XJUT2S.js.map +1 -0
- package/dist/{chunk-UTM4PEVG.js → chunk-7ZESZG3J.js} +8 -3
- package/dist/chunk-7ZESZG3J.js.map +1 -0
- package/dist/{chunk-R34R7QPD.cjs → chunk-DCJOWFVD.cjs} +3 -3
- package/dist/{chunk-R34R7QPD.cjs.map → chunk-DCJOWFVD.cjs.map} +1 -1
- package/dist/chunk-DUADUR6R.cjs +366 -0
- package/dist/chunk-DUADUR6R.cjs.map +1 -0
- package/dist/{chunk-T4OHFU5T.cjs → chunk-FMA76PRH.cjs} +8 -8
- package/dist/{chunk-T4OHFU5T.cjs.map → chunk-FMA76PRH.cjs.map} +1 -1
- package/dist/{chunk-RS4MXCPW.js → chunk-NI2BNGGV.js} +2 -2
- package/dist/{chunk-RRQ2RK5M.js → chunk-OFA7OGN5.js} +26 -6
- package/dist/chunk-OFA7OGN5.js.map +1 -0
- package/dist/{chunk-ANUSWEAP.cjs → chunk-RGT4ZVHL.cjs} +17 -15
- package/dist/chunk-RGT4ZVHL.cjs.map +1 -0
- package/dist/{chunk-X2US4RAM.cjs → chunk-TYCYYLLM.cjs} +11 -13
- package/dist/chunk-TYCYYLLM.cjs.map +1 -0
- package/dist/{chunk-QKQZF573.js → chunk-ULWNHN6P.js} +4 -6
- package/dist/{chunk-QKQZF573.js.map → chunk-ULWNHN6P.js.map} +1 -1
- package/dist/{chunk-RTF7PHS2.cjs → chunk-VWSUQKCJ.cjs} +116 -96
- package/dist/chunk-VWSUQKCJ.cjs.map +1 -0
- package/dist/cli/db-runner.cjs +20 -22
- package/dist/cli/db-runner.cjs.map +1 -1
- package/dist/cli/db-runner.js +4 -6
- package/dist/cli/db-runner.js.map +1 -1
- package/dist/cli/index.cjs +95 -58
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +126 -89
- package/dist/cli/index.js.map +1 -1
- package/dist/docs/api-reference/auth.md +10 -8
- package/dist/docs/api-reference/ignite.md +13 -3
- package/dist/docs/cli/add.md +1 -1
- package/dist/docs/cli/start.md +1 -1
- package/dist/docs/contributing/index.md +1 -1
- package/dist/docs/getting-started/index.md +1 -1
- package/dist/docs/guides/authentication.md +34 -24
- package/dist/docs/guides/database.md +12 -0
- package/dist/docs/guides/deployment.md +1 -1
- package/dist/docs/guides/environment-variables.md +1 -1
- package/dist/docs/guides/oauth.md +15 -1
- package/dist/docs/index.md +2 -1
- package/dist/docs/skills/SKILL.md +2 -2
- package/dist/docs/skills/api-surface.md +5 -4
- package/dist/docs/skills/auth-internals.md +3 -3
- package/dist/docs/versioning.md +42 -0
- package/dist/index.cjs +73 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +36 -12
- package/dist/index.js.map +1 -1
- package/dist/pgboss-backend-DSO3QTNK.cjs +14 -0
- package/dist/{pgboss-backend-TCHI7CHM.cjs.map → pgboss-backend-DSO3QTNK.cjs.map} +1 -1
- package/dist/{pgboss-backend-QKBXVJ6B.js → pgboss-backend-I6DFUNRM.js} +3 -3
- package/dist/registry/index.json +22 -3
- package/dist/registry/js-mongo/account-security.json +1 -1
- package/dist/registry/js-mongo/admin-users.json +1 -1
- package/dist/registry/js-mongo/auth.json +1 -1
- package/dist/registry/js-mongo/auth@apple.json +1 -1
- package/dist/registry/js-mongo/auth@google.json +1 -1
- package/dist/registry/js-mongo/email-verification.json +1 -1
- package/dist/registry/js-mongo/forgot-password.json +1 -1
- package/dist/registry/js-mongo/user-profile.json +1 -1
- package/dist/registry/js-pg-model/account-security.json +1 -1
- package/dist/registry/js-pg-model/admin-users.json +1 -1
- package/dist/registry/js-pg-model/auth.json +1 -1
- package/dist/registry/js-pg-model/auth@apple.json +1 -1
- package/dist/registry/js-pg-model/auth@google.json +1 -1
- package/dist/registry/js-pg-model/email-verification.json +1 -1
- package/dist/registry/js-pg-model/forgot-password.json +1 -1
- package/dist/registry/js-pg-model/user-profile.json +1 -1
- package/dist/registry/js-pg-table/account-security.json +1 -1
- package/dist/registry/js-pg-table/admin-users.json +1 -1
- package/dist/registry/js-pg-table/auth.json +1 -1
- package/dist/registry/js-pg-table/auth@apple.json +1 -1
- package/dist/registry/js-pg-table/auth@google.json +1 -1
- package/dist/registry/js-pg-table/email-verification.json +1 -1
- package/dist/registry/js-pg-table/forgot-password.json +1 -1
- package/dist/registry/js-pg-table/user-profile.json +1 -1
- package/dist/registry/ts-mongo/account-security.json +1 -1
- package/dist/registry/ts-mongo/admin-users.json +1 -1
- package/dist/registry/ts-mongo/auth.json +1 -1
- package/dist/registry/ts-mongo/auth@apple.json +1 -1
- package/dist/registry/ts-mongo/auth@google.json +1 -1
- package/dist/registry/ts-mongo/email-verification.json +1 -1
- package/dist/registry/ts-mongo/forgot-password.json +1 -1
- package/dist/registry/ts-mongo/user-profile.json +1 -1
- package/dist/registry/ts-pg-model/account-security.json +1 -1
- package/dist/registry/ts-pg-model/admin-users.json +1 -1
- package/dist/registry/ts-pg-model/auth.json +1 -1
- package/dist/registry/ts-pg-model/auth@apple.json +1 -1
- package/dist/registry/ts-pg-model/auth@google.json +1 -1
- package/dist/registry/ts-pg-model/email-verification.json +1 -1
- package/dist/registry/ts-pg-model/forgot-password.json +1 -1
- package/dist/registry/ts-pg-model/user-profile.json +1 -1
- package/dist/registry/ts-pg-table/account-security.json +1 -1
- package/dist/registry/ts-pg-table/admin-users.json +1 -1
- package/dist/registry/ts-pg-table/auth.json +1 -1
- package/dist/registry/ts-pg-table/auth@apple.json +1 -1
- package/dist/registry/ts-pg-table/auth@google.json +1 -1
- package/dist/registry/ts-pg-table/email-verification.json +1 -1
- package/dist/registry/ts-pg-table/forgot-password.json +1 -1
- package/dist/registry/ts-pg-table/user-profile.json +1 -1
- package/dist/tasks/index.d.cts +1 -1
- package/dist/tasks/index.d.ts +1 -1
- package/dist/{types-BY-ObnZH.d.cts → types-DAsBKVM-.d.cts} +7 -1
- package/dist/{types-BY-ObnZH.d.ts → types-DAsBKVM-.d.ts} +7 -1
- package/package.json +1 -1
- package/dist/chunk-277BSYVH.js +0 -127
- package/dist/chunk-277BSYVH.js.map +0 -1
- package/dist/chunk-ANUSWEAP.cjs.map +0 -1
- package/dist/chunk-HXV543HZ.js +0 -177
- package/dist/chunk-HXV543HZ.js.map +0 -1
- package/dist/chunk-RRQ2RK5M.js.map +0 -1
- package/dist/chunk-RTF7PHS2.cjs.map +0 -1
- package/dist/chunk-TYR2GZZE.cjs.map +0 -1
- package/dist/chunk-UTM4PEVG.js.map +0 -1
- package/dist/chunk-VQSWSYK6.cjs +0 -177
- package/dist/chunk-VQSWSYK6.cjs.map +0 -1
- package/dist/chunk-X2US4RAM.cjs.map +0 -1
- package/dist/chunk-YL37D6KM.cjs +0 -127
- package/dist/chunk-YL37D6KM.cjs.map +0 -1
- package/dist/pgboss-backend-TCHI7CHM.cjs +0 -14
- /package/dist/{chunk-UBQYQPBU.js.map → chunk-45BWAR6P.js.map} +0 -0
- /package/dist/{chunk-RS4MXCPW.js.map → chunk-NI2BNGGV.js.map} +0 -0
- /package/dist/{pgboss-backend-QKBXVJ6B.js.map → pgboss-backend-I6DFUNRM.js.map} +0 -0
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
var
|
|
21
|
+
var _chunkTYCYYLLMcjs = require('./chunk-TYCYYLLM.cjs');
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
|
|
@@ -26,20 +26,18 @@ var _chunkX2US4RAMcjs = require('./chunk-X2US4RAM.cjs');
|
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
var _chunkVQSWSYK6cjs = require('./chunk-VQSWSYK6.cjs');
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
var _chunkYL37D6KMcjs = require('./chunk-YL37D6KM.cjs');
|
|
30
|
+
var _chunkDUADUR6Rcjs = require('./chunk-DUADUR6R.cjs');
|
|
33
31
|
|
|
34
32
|
// src/db/mongo-model.ts
|
|
35
33
|
var mongoosePromise;
|
|
36
34
|
function loadMongoose() {
|
|
37
35
|
mongoosePromise ??= Promise.resolve().then(() => _interopRequireWildcard(require("mongoose"))).then((mod) => _nullishCoalesce(mod.default, () => ( mod))).then((mg) => {
|
|
38
|
-
|
|
36
|
+
_chunkDUADUR6Rcjs.whenQueryTracking.call(void 0, () => mg.set("debug", _chunkDUADUR6Rcjs.countStatement));
|
|
39
37
|
return mg;
|
|
40
38
|
}).catch((err) => {
|
|
41
39
|
mongoosePromise = void 0;
|
|
42
|
-
throw
|
|
40
|
+
throw _chunkDUADUR6Rcjs.notInstalled.call(void 0, err, "mongoose", "npm install mongoose");
|
|
43
41
|
});
|
|
44
42
|
return mongoosePromise;
|
|
45
43
|
}
|
|
@@ -88,7 +86,7 @@ function rules(node, mg) {
|
|
|
88
86
|
if (d.unique !== void 0) entry["unique"] = d.unique;
|
|
89
87
|
if (d.index !== void 0) entry["index"] = d.index;
|
|
90
88
|
if (d.default !== void 0)
|
|
91
|
-
entry["default"] =
|
|
89
|
+
entry["default"] = _chunkTYCYYLLMcjs.resolveDefault.call(void 0, d.default, () => new mg.Types.ObjectId());
|
|
92
90
|
if (d.enum !== void 0) entry["enum"] = d.enum;
|
|
93
91
|
if (d.min !== void 0) entry["min"] = d.min;
|
|
94
92
|
if (d.max !== void 0) entry["max"] = d.max;
|
|
@@ -162,7 +160,7 @@ function normalise(value) {
|
|
|
162
160
|
function translateError(model, err) {
|
|
163
161
|
const e = err;
|
|
164
162
|
if (_optionalChain([e, 'optionalAccess', _ => _.name]) === "ValidationError" && e.errors) {
|
|
165
|
-
throw new (0,
|
|
163
|
+
throw new (0, _chunkTYCYYLLMcjs.ModelValidationError)(
|
|
166
164
|
model,
|
|
167
165
|
Object.entries(e.errors).map(([path, v]) => ({
|
|
168
166
|
path,
|
|
@@ -174,13 +172,13 @@ function translateError(model, err) {
|
|
|
174
172
|
);
|
|
175
173
|
}
|
|
176
174
|
if (_optionalChain([e, 'optionalAccess', _2 => _2.name]) === "CastError") {
|
|
177
|
-
throw new (0,
|
|
175
|
+
throw new (0, _chunkTYCYYLLMcjs.ModelValidationError)(model, [
|
|
178
176
|
{ path: _nullishCoalesce(e.path, () => ( "")), message: _nullishCoalesce(e.message, () => ( "invalid value")) }
|
|
179
177
|
]);
|
|
180
178
|
}
|
|
181
179
|
if (_optionalChain([e, 'optionalAccess', _3 => _3.code]) === 11e3) {
|
|
182
180
|
const field = _nullishCoalesce(Object.keys(_nullishCoalesce(e.keyValue, () => ( {})))[0], () => ( "field"));
|
|
183
|
-
throw new (0,
|
|
181
|
+
throw new (0, _chunkTYCYYLLMcjs.HttpError)(409, `${model} with this ${field} already exists`);
|
|
184
182
|
}
|
|
185
183
|
throw err;
|
|
186
184
|
}
|
|
@@ -206,14 +204,14 @@ function mapSort(sort) {
|
|
|
206
204
|
}
|
|
207
205
|
function mongoModel(name, tree, options) {
|
|
208
206
|
let compiled;
|
|
209
|
-
const model = () => compiled ??=
|
|
207
|
+
const model = () => compiled ??= _chunkDUADUR6Rcjs.untracked.call(void 0,
|
|
210
208
|
() => loadMongoose().then(async (mg) => {
|
|
211
209
|
if (mg.models[name]) return mg.models[name];
|
|
212
210
|
const schema = new mg.Schema(buildTree(tree, mg), {
|
|
213
211
|
timestamps: _nullishCoalesce(options.timestamps, () => ( true)),
|
|
214
212
|
// autoSync: false hands collection and index creation to migrations, on MongoDB too.
|
|
215
|
-
autoIndex:
|
|
216
|
-
autoCreate:
|
|
213
|
+
autoIndex: _chunkTYCYYLLMcjs.isAutoSync.call(void 0, ),
|
|
214
|
+
autoCreate: _chunkTYCYYLLMcjs.isAutoSync.call(void 0, ),
|
|
217
215
|
...options.collection !== void 0 && { collection: options.collection }
|
|
218
216
|
});
|
|
219
217
|
for (const idx of _nullishCoalesce(options.indexes, () => ( []))) {
|
|
@@ -228,7 +226,7 @@ function mongoModel(name, tree, options) {
|
|
|
228
226
|
}
|
|
229
227
|
});
|
|
230
228
|
}
|
|
231
|
-
const sequences =
|
|
229
|
+
const sequences = _chunkTYCYYLLMcjs.sequenceFields.call(void 0, name, tree);
|
|
232
230
|
if (sequences.length > 0) {
|
|
233
231
|
schema.pre("validate", async function() {
|
|
234
232
|
if (!this.isNew) return;
|
|
@@ -238,9 +236,9 @@ function mongoModel(name, tree, options) {
|
|
|
238
236
|
});
|
|
239
237
|
}
|
|
240
238
|
const M = mg.model(name, schema);
|
|
241
|
-
if (
|
|
239
|
+
if (_chunkTYCYYLLMcjs.isAutoSync.call(void 0, )) {
|
|
242
240
|
await M.init().catch((err) => {
|
|
243
|
-
|
|
241
|
+
_chunkDUADUR6Rcjs.getLogger.call(void 0, ).warn(
|
|
244
242
|
{ model: name, err: err.message },
|
|
245
243
|
`${name}: could not build its indexes \u2014 fix the data, then run efc db sync`
|
|
246
244
|
);
|
|
@@ -250,7 +248,7 @@ function mongoModel(name, tree, options) {
|
|
|
250
248
|
})
|
|
251
249
|
);
|
|
252
250
|
const session = () => {
|
|
253
|
-
const tx =
|
|
251
|
+
const tx = _chunkTYCYYLLMcjs.currentTx.call(void 0, );
|
|
254
252
|
return _optionalChain([tx, 'optionalAccess', _5 => _5.engine]) === "mongodb" ? { session: tx.session } : {};
|
|
255
253
|
};
|
|
256
254
|
const applyQueryOptions = (q2, opts) => {
|
|
@@ -384,7 +382,7 @@ function mongoModel(name, tree, options) {
|
|
|
384
382
|
}),
|
|
385
383
|
raw: () => model(),
|
|
386
384
|
async sync(opts) {
|
|
387
|
-
if (
|
|
385
|
+
if (_chunkTYCYYLLMcjs.isSyncSuppressed.call(void 0, )) return [];
|
|
388
386
|
const M = await model();
|
|
389
387
|
const changes = [];
|
|
390
388
|
const exists = (await M.db.db.listCollections({ name: M.collection.collectionName }).toArray()).length > 0;
|
|
@@ -479,14 +477,36 @@ async function connectMongo(url, pool = {}) {
|
|
|
479
477
|
serverSelectionTimeoutMS: pool.connectionTimeoutMs,
|
|
480
478
|
waitQueueTimeoutMS: pool.connectionTimeoutMs
|
|
481
479
|
}
|
|
480
|
+
}).catch((err) => {
|
|
481
|
+
throw explainMongoError(err, url);
|
|
482
482
|
});
|
|
483
|
-
|
|
483
|
+
_chunkDUADUR6Rcjs.getLogger.call(void 0, ).info("MongoDB connected");
|
|
484
484
|
return mg.connection;
|
|
485
485
|
}
|
|
486
|
+
function explainMongoError(err, url) {
|
|
487
|
+
const e = err;
|
|
488
|
+
let where = "(unparsable DATABASE_URL)";
|
|
489
|
+
let user = "(none)";
|
|
490
|
+
try {
|
|
491
|
+
const u = new URL(url);
|
|
492
|
+
where = u.host || "localhost";
|
|
493
|
+
user = decodeURIComponent(u.username) || "(none)";
|
|
494
|
+
} catch (e2) {
|
|
495
|
+
}
|
|
496
|
+
let text;
|
|
497
|
+
if (e.code === 18 || e.codeName === "AuthenticationFailed") {
|
|
498
|
+
text = `MongoDB rejected the login for user "${user}" at ${where}. Check the username and password in DATABASE_URL (special characters must be URL-encoded), and authSource if the user lives in another database.`;
|
|
499
|
+
} else if (e.name === "MongooseServerSelectionError" || e.name === "MongoServerSelectionError") {
|
|
500
|
+
text = `Could not reach MongoDB at ${where}. Is it running? On Atlas, add this machine's IP under Network Access.`;
|
|
501
|
+
} else if (e.name === "MongoParseError") {
|
|
502
|
+
text = `DATABASE_URL isn't a valid MongoDB connection string: ${_nullishCoalesce(e.message, () => ( ""))}`;
|
|
503
|
+
}
|
|
504
|
+
return text ? new Error(`[EFC] ${text}`, { cause: err }) : err;
|
|
505
|
+
}
|
|
486
506
|
|
|
487
507
|
// src/db/pg-model.ts
|
|
488
508
|
function pgModel(name, tree, options) {
|
|
489
|
-
const tbl =
|
|
509
|
+
const tbl = _chunkTYCYYLLMcjs.pgTable.call(void 0, name, tree, options, { native: false, api: "defineModel" });
|
|
490
510
|
const { columns, ts, refs, ready, compile, client, columnFor, toDb, fromRow, validate, guard } = tbl;
|
|
491
511
|
const kindOf = (field) => _optionalChain([columns, 'access', _15 => _15.get, 'call', _16 => _16(field), 'optionalAccess', _17 => _17.kind]);
|
|
492
512
|
function missingField(sql, cond) {
|
|
@@ -586,7 +606,7 @@ function pgModel(name, tree, options) {
|
|
|
586
606
|
break;
|
|
587
607
|
}
|
|
588
608
|
default:
|
|
589
|
-
throw new (0,
|
|
609
|
+
throw new (0, _chunkTYCYYLLMcjs.ModelValidationError)(name, [
|
|
590
610
|
{ path, message: `operator ${op} is not supported on PostgreSQL` }
|
|
591
611
|
]);
|
|
592
612
|
}
|
|
@@ -617,8 +637,8 @@ function pgModel(name, tree, options) {
|
|
|
617
637
|
for (const path of Array.isArray(paths) ? paths : [paths]) {
|
|
618
638
|
const ref = refs.get(path);
|
|
619
639
|
if (!ref)
|
|
620
|
-
throw new (0,
|
|
621
|
-
const target =
|
|
640
|
+
throw new (0, _chunkTYCYYLLMcjs.ModelValidationError)(name, [{ path, message: "is not a populatable ref field" }]);
|
|
641
|
+
const target = _chunkTYCYYLLMcjs.getRegisteredModel.call(void 0, ref.model);
|
|
622
642
|
if (!target) throw new Error(`[EFC] populate: model "${ref.model}" is not defined`);
|
|
623
643
|
const ids = [
|
|
624
644
|
...new Set(
|
|
@@ -661,7 +681,7 @@ function pgModel(name, tree, options) {
|
|
|
661
681
|
return populate(rows, _optionalChain([opts, 'optionalAccess', _22 => _22.populate]));
|
|
662
682
|
}
|
|
663
683
|
const strictUpdate = (update) => {
|
|
664
|
-
const declared = (path) => columns.has(path.split(".")[0]) && (!path.includes(".") ||
|
|
684
|
+
const declared = (path) => columns.has(path.split(".")[0]) && (!path.includes(".") || _chunkTYCYYLLMcjs.nodeAt.call(void 0, tree, path.split(".")) !== void 0);
|
|
665
685
|
const out = {};
|
|
666
686
|
for (const [k, v] of Object.entries(update)) {
|
|
667
687
|
if (k.startsWith("$") && v !== null && typeof v === "object") {
|
|
@@ -676,7 +696,7 @@ function pgModel(name, tree, options) {
|
|
|
676
696
|
const ops = update;
|
|
677
697
|
for (const op of Object.keys(update).filter((k) => k.startsWith("$"))) {
|
|
678
698
|
if (!["$set", "$unset", "$inc", "$push", "$pull"].includes(op)) {
|
|
679
|
-
throw new (0,
|
|
699
|
+
throw new (0, _chunkTYCYYLLMcjs.ModelValidationError)(name, [
|
|
680
700
|
{ path: op, message: "update operator is not supported on PostgreSQL" }
|
|
681
701
|
]);
|
|
682
702
|
}
|
|
@@ -689,25 +709,25 @@ function pgModel(name, tree, options) {
|
|
|
689
709
|
for (const [k, v] of Object.entries($set)) if (!k.includes(".")) topLevel[k] = v;
|
|
690
710
|
for (const k of Object.keys(_nullishCoalesce(ops["$unset"], () => ( {})))) if (!k.includes(".")) topLevel[k] = null;
|
|
691
711
|
for (const [k, v] of Object.entries($set))
|
|
692
|
-
if (k.includes(".")) await
|
|
712
|
+
if (k.includes(".")) await _chunkTYCYYLLMcjs.validateAtPath.call(void 0, tree, k, v, issues);
|
|
693
713
|
for (const k of Object.keys(_nullishCoalesce(ops["$unset"], () => ( {})))) {
|
|
694
|
-
if (k.includes(".")) await
|
|
714
|
+
if (k.includes(".")) await _chunkTYCYYLLMcjs.validateAtPath.call(void 0, tree, k, null, issues);
|
|
695
715
|
}
|
|
696
716
|
for (const [k, by] of Object.entries(_nullishCoalesce(ops["$inc"], () => ( {})))) {
|
|
697
717
|
if (typeof by !== "number") issues.push({ path: k, message: "$inc needs a number" });
|
|
698
|
-
const node = k.includes(".") ?
|
|
718
|
+
const node = k.includes(".") ? _chunkTYCYYLLMcjs.nodeAt.call(void 0, tree, k.split(".")) : tree[k];
|
|
699
719
|
if (node && !(node.kind === "scalar" && node.type === "number") && node.kind !== "json") {
|
|
700
720
|
issues.push({ path: k, message: "$inc only applies to number fields" });
|
|
701
721
|
}
|
|
702
722
|
}
|
|
703
|
-
if (issues.length) throw new (0,
|
|
723
|
+
if (issues.length) throw new (0, _chunkTYCYYLLMcjs.ModelValidationError)(name, issues);
|
|
704
724
|
await validate(topLevel, true);
|
|
705
725
|
const set = {};
|
|
706
726
|
const nested = /* @__PURE__ */ new Map();
|
|
707
727
|
const touchedTop = /* @__PURE__ */ new Set();
|
|
708
728
|
const acc = (field) => _nullishCoalesce(nested.get(field), () => ( columnFor(t, field)));
|
|
709
729
|
const conflict = (path) => {
|
|
710
|
-
throw new (0,
|
|
730
|
+
throw new (0, _chunkTYCYYLLMcjs.ModelValidationError)(name, [{ path, message: "conflicting update paths" }]);
|
|
711
731
|
};
|
|
712
732
|
const top = (field, value) => {
|
|
713
733
|
if (touchedTop.has(field) || nested.has(field)) conflict(field);
|
|
@@ -878,7 +898,7 @@ function defineModel(name, schema, options) {
|
|
|
878
898
|
return createModel(name, schema, _nullishCoalesce(options, () => ( {})));
|
|
879
899
|
}
|
|
880
900
|
function distinctFields(tree, options) {
|
|
881
|
-
const ts =
|
|
901
|
+
const ts = _chunkTYCYYLLMcjs.timestampFields.call(void 0, options);
|
|
882
902
|
const fields = /* @__PURE__ */ new Set(["id", ...Object.values(ts)]);
|
|
883
903
|
for (const [key, node] of Object.entries(tree)) if (node.kind === "scalar") fields.add(key);
|
|
884
904
|
return fields;
|
|
@@ -903,11 +923,11 @@ var MODEL_OPS = [
|
|
|
903
923
|
];
|
|
904
924
|
var sortKey = (v) => v instanceof Date ? v.getTime() : v;
|
|
905
925
|
function createModel(name, schema, options, native) {
|
|
906
|
-
const tree =
|
|
926
|
+
const tree = _chunkTYCYYLLMcjs.normalizeSchema.call(void 0, schema, "model", name);
|
|
907
927
|
let engineModel;
|
|
908
928
|
const impl = () => {
|
|
909
929
|
if (engineModel) return engineModel;
|
|
910
|
-
const engine =
|
|
930
|
+
const engine = _chunkTYCYYLLMcjs.getDbEngine.call(void 0, );
|
|
911
931
|
if (native && native.engine !== engine) {
|
|
912
932
|
throw new Error(
|
|
913
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`
|
|
@@ -949,7 +969,7 @@ function createModel(name, schema, options, native) {
|
|
|
949
969
|
try {
|
|
950
970
|
return await m.create(create);
|
|
951
971
|
} catch (err) {
|
|
952
|
-
if (
|
|
972
|
+
if (_chunkTYCYYLLMcjs.isHttpError.call(void 0, err) && err.statusCode === 409 && !_chunkTYCYYLLMcjs.currentTx.call(void 0, )) {
|
|
953
973
|
const retried = await m.updateOne(filter, update);
|
|
954
974
|
if (retried) return retried;
|
|
955
975
|
}
|
|
@@ -965,26 +985,26 @@ function createModel(name, schema, options, native) {
|
|
|
965
985
|
sync: (opts) => call((m) => m.sync(opts)),
|
|
966
986
|
drop: () => call((m) => m.drop())
|
|
967
987
|
};
|
|
968
|
-
|
|
969
|
-
|
|
988
|
+
_chunkDUADUR6Rcjs.traceOps.call(void 0, name, model, MODEL_OPS);
|
|
989
|
+
_chunkTYCYYLLMcjs.registerModel.call(void 0, {
|
|
970
990
|
name,
|
|
971
991
|
sync: model.sync,
|
|
972
992
|
plan: (opts) => call((m) => m.plan(opts)),
|
|
973
993
|
drop: model.drop,
|
|
974
994
|
findByIds: (ids) => model.find({ id: { $in: ids } }),
|
|
975
|
-
pgTarget: () => ({ table: _nullishCoalesce(options.collection, () => (
|
|
995
|
+
pgTarget: () => ({ table: _nullishCoalesce(options.collection, () => ( _chunkTYCYYLLMcjs.tableNameFor.call(void 0, name))), idKind: "uuid" })
|
|
976
996
|
});
|
|
977
997
|
return model;
|
|
978
998
|
}
|
|
979
999
|
|
|
980
1000
|
// src/db/transaction.ts
|
|
981
1001
|
async function transaction(fn) {
|
|
982
|
-
if (
|
|
983
|
-
if (
|
|
1002
|
+
if (_chunkTYCYYLLMcjs.currentTx.call(void 0, )) return fn();
|
|
1003
|
+
if (_chunkTYCYYLLMcjs.getDbEngine.call(void 0, ) === "postgresql") {
|
|
984
1004
|
let result;
|
|
985
1005
|
const afterCommit = [];
|
|
986
|
-
await
|
|
987
|
-
result = await
|
|
1006
|
+
await _chunkDUADUR6Rcjs.getOrm.call(void 0, ).transaction(async (tx) => {
|
|
1007
|
+
result = await _chunkTYCYYLLMcjs.runInTx.call(void 0, { engine: "postgresql", tx, afterCommit }, fn);
|
|
988
1008
|
});
|
|
989
1009
|
for (const run of afterCommit) run();
|
|
990
1010
|
return result;
|
|
@@ -994,7 +1014,7 @@ async function transaction(fn) {
|
|
|
994
1014
|
try {
|
|
995
1015
|
let result;
|
|
996
1016
|
await session.withTransaction(async () => {
|
|
997
|
-
result = await
|
|
1017
|
+
result = await _chunkTYCYYLLMcjs.runInTx.call(void 0, { engine: "mongodb", session }, fn);
|
|
998
1018
|
});
|
|
999
1019
|
return result;
|
|
1000
1020
|
} finally {
|
|
@@ -1040,8 +1060,8 @@ var TableRuntime = (_class = class {
|
|
|
1040
1060
|
constructor(name, schema, options) {;_class.prototype.__init.call(this);
|
|
1041
1061
|
this.name = name;
|
|
1042
1062
|
this.options = options;
|
|
1043
|
-
const tree =
|
|
1044
|
-
this.tbl =
|
|
1063
|
+
const tree = _chunkTYCYYLLMcjs.normalizeSchema.call(void 0, schema, "table", name);
|
|
1064
|
+
this.tbl = _chunkTYCYYLLMcjs.pgTable.call(void 0, name, tree, options, { native: true, api: "defineTable" });
|
|
1045
1065
|
this.uniqueSets = [["id"]];
|
|
1046
1066
|
for (const spec of this.tbl.columns.values()) {
|
|
1047
1067
|
if (_optionalChain([spec, 'access', _25 => _25.node, 'optionalAccess', _26 => _26.def, 'access', _27 => _27.unique])) this.uniqueSets.push([spec.field]);
|
|
@@ -1068,7 +1088,7 @@ var TableRuntime = (_class = class {
|
|
|
1068
1088
|
/** Many-to-many fields as list columns, so filters and projections treat them alike. */
|
|
1069
1089
|
__init() {this.joinSpecs = /* @__PURE__ */ new Map()}
|
|
1070
1090
|
fail(path, message) {
|
|
1071
|
-
throw new (0,
|
|
1091
|
+
throw new (0, _chunkTYCYYLLMcjs.ModelValidationError)(this.name, [{ path, message }]);
|
|
1072
1092
|
}
|
|
1073
1093
|
spec(field) {
|
|
1074
1094
|
return _nullishCoalesce(this.tbl.columns.get(field), () => ( this.joinSpecs.get(field)));
|
|
@@ -1079,18 +1099,18 @@ var TableRuntime = (_class = class {
|
|
|
1079
1099
|
/** A many-to-many field's ids, in order, for the row `owner` (a table name or alias). */
|
|
1080
1100
|
joinExpr(sql, join, owner) {
|
|
1081
1101
|
return sql.raw(
|
|
1082
|
-
`coalesce((select array_agg(efc_j.ref_id order by efc_j.position) from ${
|
|
1102
|
+
`coalesce((select array_agg(efc_j.ref_id order by efc_j.position) from ${_chunkTYCYYLLMcjs.q.call(void 0, join.table)} efc_j where efc_j.owner_id = ${owner}.${_chunkTYCYYLLMcjs.q.call(void 0, "id")}), '{}'::${join.ddl})`
|
|
1083
1103
|
);
|
|
1084
1104
|
}
|
|
1085
1105
|
col(sql, field, alias) {
|
|
1086
1106
|
const join = this.join(field);
|
|
1087
|
-
if (join) return this.joinExpr(sql, join, _nullishCoalesce(alias, () => (
|
|
1107
|
+
if (join) return this.joinExpr(sql, join, _nullishCoalesce(alias, () => ( _chunkTYCYYLLMcjs.q.call(void 0, this.tbl.table))));
|
|
1088
1108
|
const spec = this.spec(field);
|
|
1089
|
-
return sql.raw(alias ? `${alias}.${
|
|
1109
|
+
return sql.raw(alias ? `${alias}.${_chunkTYCYYLLMcjs.q.call(void 0, spec.column)}` : _chunkTYCYYLLMcjs.q.call(void 0, spec.column));
|
|
1090
1110
|
}
|
|
1091
1111
|
/** SELECT items for the many-to-many fields among `fields`, as text arrays. */
|
|
1092
1112
|
joinColumns(sql, fields, owner) {
|
|
1093
|
-
return fields.filter((f) => this.join(f)).map((f) => sql`${this.col(sql, f, owner)}::text[] as ${sql.raw(
|
|
1113
|
+
return fields.filter((f) => this.join(f)).map((f) => sql`${this.col(sql, f, owner)}::text[] as ${sql.raw(_chunkTYCYYLLMcjs.q.call(void 0, relAlias(f)))}`);
|
|
1094
1114
|
}
|
|
1095
1115
|
/** `col` for SELECT lists: many-to-many fields come back as text arrays under an alias. */
|
|
1096
1116
|
selectCols(sql, fields, owner) {
|
|
@@ -1382,7 +1402,7 @@ var TableRuntime = (_class = class {
|
|
|
1382
1402
|
if (args["cursor"]) {
|
|
1383
1403
|
this.uniqueKey(args["cursor"], "cursor");
|
|
1384
1404
|
const cw = this.where(sql, t, args["cursor"]);
|
|
1385
|
-
const at = (field) => sql`(select ${this.col(sql, field)} from ${sql.raw(
|
|
1405
|
+
const at = (field) => sql`(select ${this.col(sql, field)} from ${sql.raw(_chunkTYCYYLLMcjs.q.call(void 0, this.tbl.table))} where ${cw})`;
|
|
1386
1406
|
const ors = [];
|
|
1387
1407
|
const same = (o) => sql`${this.col(sql, o.field)} is not distinct from ${at(o.field)}`;
|
|
1388
1408
|
for (let i = 0; i < order.length; i++) {
|
|
@@ -1395,7 +1415,7 @@ var TableRuntime = (_class = class {
|
|
|
1395
1415
|
ors.push(eqs.length ? sql`(${sql.join([...eqs, after], sql` and `)})` : after);
|
|
1396
1416
|
}
|
|
1397
1417
|
ors.push(sql`(${sql.join(order.map(same), sql` and `)})`);
|
|
1398
|
-
parts.push(sql`exists (select 1 from ${sql.raw(
|
|
1418
|
+
parts.push(sql`exists (select 1 from ${sql.raw(_chunkTYCYYLLMcjs.q.call(void 0, this.tbl.table))} where ${cw})`);
|
|
1399
1419
|
parts.push(sql`(${sql.join(ors, sql` or `)})`);
|
|
1400
1420
|
}
|
|
1401
1421
|
return parts.length ? sql.join(parts, sql` and `) : sql`true`;
|
|
@@ -1420,7 +1440,7 @@ var TableRuntime = (_class = class {
|
|
|
1420
1440
|
const offset = args["skip"] ? sql` offset ${sql.param(args["skip"])}` : sql``;
|
|
1421
1441
|
const orderBy = order.length ? sql` order by ${this.orderSql(sql, order)}` : sql``;
|
|
1422
1442
|
const where = this.readWhere(sql, t, args, order);
|
|
1423
|
-
const from = sql.raw(
|
|
1443
|
+
const from = sql.raw(_chunkTYCYYLLMcjs.q.call(void 0, this.tbl.table));
|
|
1424
1444
|
const distinct = _optionalChain([args, 'access', _29 => _29["distinct"], 'optionalAccess', _30 => _30.filter, 'call', _31 => _31((f) => this.spec(f))]);
|
|
1425
1445
|
if (_optionalChain([distinct, 'optionalAccess', _32 => _32.length])) {
|
|
1426
1446
|
const dcols = sql.join(
|
|
@@ -1450,7 +1470,7 @@ var TableRuntime = (_class = class {
|
|
|
1450
1470
|
distinct ? "efc_distinct" : void 0
|
|
1451
1471
|
);
|
|
1452
1472
|
const include = this.includeArg(args);
|
|
1453
|
-
const included = include ? await this.includeColumns(sql, include, distinct ? "efc_distinct" :
|
|
1473
|
+
const included = include ? await this.includeColumns(sql, include, distinct ? "efc_distinct" : _chunkTYCYYLLMcjs.q.call(void 0, this.tbl.table), 1) : [];
|
|
1454
1474
|
const { query, reversed } = this.readQuery(
|
|
1455
1475
|
sql,
|
|
1456
1476
|
t,
|
|
@@ -1525,7 +1545,7 @@ var TableRuntime = (_class = class {
|
|
|
1525
1545
|
for (const [name, arg] of Object.entries(include)) {
|
|
1526
1546
|
if (!arg) continue;
|
|
1527
1547
|
const expr = await this.relationExpr(sql, this.relation(name), relArgs(arg), owner, depth);
|
|
1528
|
-
out.push(sql`${expr} as ${sql.raw(
|
|
1548
|
+
out.push(sql`${expr} as ${sql.raw(_chunkTYCYYLLMcjs.q.call(void 0, incAlias(name)))}`);
|
|
1529
1549
|
}
|
|
1530
1550
|
return out;
|
|
1531
1551
|
}
|
|
@@ -1559,21 +1579,21 @@ var TableRuntime = (_class = class {
|
|
|
1559
1579
|
*/
|
|
1560
1580
|
relationSource(rel, owner, a, j) {
|
|
1561
1581
|
const T = runtimeOf(rel.target, `${this.name}.${rel.name}`);
|
|
1562
|
-
const target = `${
|
|
1563
|
-
const ownerId = `${owner}.${
|
|
1582
|
+
const target = `${_chunkTYCYYLLMcjs.q.call(void 0, T.tbl.table)} ${a}`;
|
|
1583
|
+
const ownerId = `${owner}.${_chunkTYCYYLLMcjs.q.call(void 0, "id")}`;
|
|
1564
1584
|
if (rel.via === "fk") {
|
|
1565
1585
|
return {
|
|
1566
1586
|
T,
|
|
1567
1587
|
from: target,
|
|
1568
|
-
cond: `${a}.${
|
|
1569
|
-
defaultOrder: `${a}.${
|
|
1588
|
+
cond: `${a}.${_chunkTYCYYLLMcjs.q.call(void 0, "id")} = ${owner}.${_chunkTYCYYLLMcjs.q.call(void 0, rel.column)}`,
|
|
1589
|
+
defaultOrder: `${a}.${_chunkTYCYYLLMcjs.q.call(void 0, "id")}`
|
|
1570
1590
|
};
|
|
1571
1591
|
}
|
|
1572
1592
|
let from;
|
|
1573
1593
|
let cond;
|
|
1574
1594
|
let defaultOrder;
|
|
1575
1595
|
if (rel.via === "join") {
|
|
1576
|
-
from = `${
|
|
1596
|
+
from = `${_chunkTYCYYLLMcjs.q.call(void 0, rel.join.table)} ${j} join ${target} on ${a}.${_chunkTYCYYLLMcjs.q.call(void 0, "id")} = ${j}.ref_id`;
|
|
1577
1597
|
cond = `${j}.owner_id = ${ownerId}`;
|
|
1578
1598
|
defaultOrder = `${j}.position`;
|
|
1579
1599
|
} else {
|
|
@@ -1591,7 +1611,7 @@ var TableRuntime = (_class = class {
|
|
|
1591
1611
|
`[EFC] ${this.name}.${rel.name}: ${rel.target}.${rel.foreignKey} is many-to-many \u2014 use hasMany`
|
|
1592
1612
|
);
|
|
1593
1613
|
}
|
|
1594
|
-
from = `${
|
|
1614
|
+
from = `${_chunkTYCYYLLMcjs.q.call(void 0, join.table)} ${j} join ${target} on ${a}.${_chunkTYCYYLLMcjs.q.call(void 0, "id")} = ${j}.owner_id`;
|
|
1595
1615
|
cond = `${j}.ref_id = ${ownerId}`;
|
|
1596
1616
|
} else {
|
|
1597
1617
|
if (rel.kind === "one" && !column.node.def.unique) {
|
|
@@ -1600,9 +1620,9 @@ var TableRuntime = (_class = class {
|
|
|
1600
1620
|
);
|
|
1601
1621
|
}
|
|
1602
1622
|
from = target;
|
|
1603
|
-
cond = `${a}.${
|
|
1623
|
+
cond = `${a}.${_chunkTYCYYLLMcjs.q.call(void 0, column.column)} = ${ownerId}`;
|
|
1604
1624
|
}
|
|
1605
|
-
defaultOrder = `${a}.${
|
|
1625
|
+
defaultOrder = `${a}.${_chunkTYCYYLLMcjs.q.call(void 0, "id")}`;
|
|
1606
1626
|
}
|
|
1607
1627
|
return { T, from, cond, defaultOrder };
|
|
1608
1628
|
}
|
|
@@ -1627,7 +1647,7 @@ var TableRuntime = (_class = class {
|
|
|
1627
1647
|
const where = isPlainObject(w) ? w : { id: w };
|
|
1628
1648
|
const found = await T.findUnique({ where, select: { id: true } });
|
|
1629
1649
|
if (!found) {
|
|
1630
|
-
throw new (0,
|
|
1650
|
+
throw new (0, _chunkTYCYYLLMcjs.ModelValidationError)(this.name, [
|
|
1631
1651
|
{ path, message: `no ${rel.target} matches ${JSON.stringify(where, idJson)}` }
|
|
1632
1652
|
]);
|
|
1633
1653
|
}
|
|
@@ -1719,8 +1739,8 @@ var TableRuntime = (_class = class {
|
|
|
1719
1739
|
try {
|
|
1720
1740
|
await T.updateNested({ where: whereOf(w), data: { [fk]: owner } });
|
|
1721
1741
|
} catch (err) {
|
|
1722
|
-
if (
|
|
1723
|
-
throw new (0,
|
|
1742
|
+
if (_chunkTYCYYLLMcjs.isHttpError.call(void 0, err) && err.statusCode === 404) {
|
|
1743
|
+
throw new (0, _chunkTYCYYLLMcjs.ModelValidationError)(this.name, [
|
|
1724
1744
|
{
|
|
1725
1745
|
path: key,
|
|
1726
1746
|
message: `no ${rel.target} matches ${JSON.stringify(whereOf(w), idJson)}`
|
|
@@ -1871,7 +1891,7 @@ var TableRuntime = (_class = class {
|
|
|
1871
1891
|
const a = `efc_f${++aliasSeq}`;
|
|
1872
1892
|
const { T, from, cond } = this.relationSource(
|
|
1873
1893
|
rel,
|
|
1874
|
-
_nullishCoalesce(owner, () => (
|
|
1894
|
+
_nullishCoalesce(owner, () => ( _chunkTYCYYLLMcjs.q.call(void 0, this.tbl.table))),
|
|
1875
1895
|
a,
|
|
1876
1896
|
`efc_fj${aliasSeq}`
|
|
1877
1897
|
);
|
|
@@ -2012,7 +2032,7 @@ var TableRuntime = (_class = class {
|
|
|
2012
2032
|
}
|
|
2013
2033
|
async orThrow(p) {
|
|
2014
2034
|
const r = await p;
|
|
2015
|
-
if (r === null) throw new (0,
|
|
2035
|
+
if (r === null) throw new (0, _chunkTYCYYLLMcjs.HttpError)(404, `${this.name} not found`);
|
|
2016
2036
|
return r;
|
|
2017
2037
|
}
|
|
2018
2038
|
async count(args = {}) {
|
|
@@ -2022,7 +2042,7 @@ var TableRuntime = (_class = class {
|
|
|
2022
2042
|
const counted = select ? Object.entries(select).filter(([f, on]) => on && (f === "_all" || this.spec(f))) : [["_all", true]];
|
|
2023
2043
|
const exprs = sql.join(
|
|
2024
2044
|
counted.map(
|
|
2025
|
-
([f]) => f === "_all" ? sql`count(*)::int as ${sql.raw(
|
|
2045
|
+
([f]) => f === "_all" ? sql`count(*)::int as ${sql.raw(_chunkTYCYYLLMcjs.q.call(void 0, "_all"))}` : sql`count(${this.col(sql, f, "efc_rows")})::int as ${sql.raw(_chunkTYCYYLLMcjs.q.call(void 0, f))}`
|
|
2026
2046
|
),
|
|
2027
2047
|
sql`, `
|
|
2028
2048
|
);
|
|
@@ -2097,7 +2117,7 @@ var TableRuntime = (_class = class {
|
|
|
2097
2117
|
const specs = this.aggregateSpec(args);
|
|
2098
2118
|
if (specs.length === 0) return {};
|
|
2099
2119
|
const exprs = sql.join(
|
|
2100
|
-
specs.map((s) => sql`${this.aggregateExpr(sql, s.agg, s.field)} as ${sql.raw(
|
|
2120
|
+
specs.map((s) => sql`${this.aggregateExpr(sql, s.agg, s.field)} as ${sql.raw(_chunkTYCYYLLMcjs.q.call(void 0, s.alias))}`),
|
|
2101
2121
|
sql`, `
|
|
2102
2122
|
);
|
|
2103
2123
|
const { query } = this.readQuery(sql, t, { ...args, select: void 0 }, sql`*`);
|
|
@@ -2155,7 +2175,7 @@ var TableRuntime = (_class = class {
|
|
|
2155
2175
|
[
|
|
2156
2176
|
...by.map((f) => this.col(sql, f)),
|
|
2157
2177
|
...specs.map(
|
|
2158
|
-
(s) => sql`${this.aggregateExpr(sql, s.agg, s.field)} as ${sql.raw(
|
|
2178
|
+
(s) => sql`${this.aggregateExpr(sql, s.agg, s.field)} as ${sql.raw(_chunkTYCYYLLMcjs.q.call(void 0, s.alias))}`
|
|
2159
2179
|
)
|
|
2160
2180
|
],
|
|
2161
2181
|
sql`, `
|
|
@@ -2179,7 +2199,7 @@ var TableRuntime = (_class = class {
|
|
|
2179
2199
|
}
|
|
2180
2200
|
}
|
|
2181
2201
|
}
|
|
2182
|
-
const query = sql`select ${select} from ${sql.raw(
|
|
2202
|
+
const query = sql`select ${select} from ${sql.raw(_chunkTYCYYLLMcjs.q.call(void 0, this.tbl.table))}${where ? sql` where ${where}` : sql``} group by ${sql.join(
|
|
2183
2203
|
by.map((f) => this.col(sql, f)),
|
|
2184
2204
|
sql`, `
|
|
2185
2205
|
)}${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``}`;
|
|
@@ -2257,7 +2277,7 @@ var TableRuntime = (_class = class {
|
|
|
2257
2277
|
}
|
|
2258
2278
|
}
|
|
2259
2279
|
}
|
|
2260
|
-
if (issues.length) throw new (0,
|
|
2280
|
+
if (issues.length) throw new (0, _chunkTYCYYLLMcjs.ModelValidationError)(this.name, issues);
|
|
2261
2281
|
await this.tbl.validate(plain, true);
|
|
2262
2282
|
for (const [field, v] of Object.entries(plain)) {
|
|
2263
2283
|
sets.push(
|
|
@@ -2299,7 +2319,7 @@ var TableRuntime = (_class = class {
|
|
|
2299
2319
|
}
|
|
2300
2320
|
for (const [field, entries] of byField) {
|
|
2301
2321
|
const join = this.join(field);
|
|
2302
|
-
const jt = sql.raw(
|
|
2322
|
+
const jt = sql.raw(_chunkTYCYYLLMcjs.q.call(void 0, join.table));
|
|
2303
2323
|
const sets = entries.filter((e) => e.op.mode === "set");
|
|
2304
2324
|
if (sets.length) {
|
|
2305
2325
|
const owners2 = sets.map((e) => idText(e.id));
|
|
@@ -2346,7 +2366,7 @@ var TableRuntime = (_class = class {
|
|
|
2346
2366
|
const idDdl = this.tbl.columns.get("id").ddl;
|
|
2347
2367
|
const owners = sql`${sql.param(ids.map(idText))}::${sql.raw(idDdl)}[]`;
|
|
2348
2368
|
const parts = joins.map(
|
|
2349
|
-
(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(
|
|
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(_chunkTYCYYLLMcjs.q.call(void 0, j.table))} where owner_id = any(${owners}) group by owner_id`
|
|
2350
2370
|
);
|
|
2351
2371
|
const { rows } = await this.exec(sql.join(parts, sql` union all `));
|
|
2352
2372
|
for (const j of joins) out.set(j.field, /* @__PURE__ */ new Map());
|
|
@@ -2368,7 +2388,7 @@ var TableRuntime = (_class = class {
|
|
|
2368
2388
|
}
|
|
2369
2389
|
insertSql(sql, t, rows) {
|
|
2370
2390
|
const fields = [...new Set(rows.flatMap((r) => Object.keys(r)))];
|
|
2371
|
-
const head = sql`insert into ${sql.raw(
|
|
2391
|
+
const head = sql`insert into ${sql.raw(_chunkTYCYYLLMcjs.q.call(void 0, this.tbl.table))} (${sql.join(
|
|
2372
2392
|
fields.map((f) => this.col(sql, f)),
|
|
2373
2393
|
sql`, `
|
|
2374
2394
|
)})`;
|
|
@@ -2465,7 +2485,7 @@ var TableRuntime = (_class = class {
|
|
|
2465
2485
|
return;
|
|
2466
2486
|
}
|
|
2467
2487
|
const { rows: ids } = await this.exec(
|
|
2468
|
-
sql`select nextval(pg_get_serial_sequence(${sql.param(
|
|
2488
|
+
sql`select nextval(pg_get_serial_sequence(${sql.param(_chunkTYCYYLLMcjs.q.call(void 0, this.tbl.table))}, 'id'))::text as id from generate_series(1, ${sql.param(missing.length)})`
|
|
2469
2489
|
);
|
|
2470
2490
|
missing.forEach((r, i) => {
|
|
2471
2491
|
const id = ids[i]["id"];
|
|
@@ -2494,9 +2514,9 @@ var TableRuntime = (_class = class {
|
|
|
2494
2514
|
const where = this.where(sql, t, args["where"]);
|
|
2495
2515
|
const links = this.joinColumns(sql, [...this.tbl.joins.keys()]);
|
|
2496
2516
|
const extra = links.length ? sql`, ${sql.join(links, sql`, `)}` : sql``;
|
|
2497
|
-
const query = sets.length ? sql`update ${sql.raw(
|
|
2517
|
+
const query = sets.length ? sql`update ${sql.raw(_chunkTYCYYLLMcjs.q.call(void 0, this.tbl.table))} set ${sql.join(sets, sql`, `)} where ${where} returning *${extra}` : sql`select *${extra} from ${sql.raw(_chunkTYCYYLLMcjs.q.call(void 0, this.tbl.table))} where ${where} limit 1`;
|
|
2498
2518
|
const [row] = (await this.exec(query)).rows;
|
|
2499
|
-
if (!row) throw new (0,
|
|
2519
|
+
if (!row) throw new (0, _chunkTYCYYLLMcjs.HttpError)(404, `${this.name} not found`);
|
|
2500
2520
|
const record = this.fromRaw(t, row);
|
|
2501
2521
|
await this.applyJoins(sql, [{ id: record["id"], ops: joinOps }]);
|
|
2502
2522
|
await this.refreshJoins(sql, [record], joinOps);
|
|
@@ -2517,7 +2537,7 @@ var TableRuntime = (_class = class {
|
|
|
2517
2537
|
const links = returning ? this.joinColumns(sql, [...this.tbl.joins.keys()]) : [];
|
|
2518
2538
|
const list = returning ? sql` returning *${links.length ? sql`, ${sql.join(links, sql`, `)}` : sql``}` : joinOps.length ? sql` returning ${this.col(sql, "id")}` : sql``;
|
|
2519
2539
|
const result = await this.exec(
|
|
2520
|
-
sets.length ? sql`update ${sql.raw(
|
|
2540
|
+
sets.length ? sql`update ${sql.raw(_chunkTYCYYLLMcjs.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(_chunkTYCYYLLMcjs.q.call(void 0, this.tbl.table))} where ${where}`
|
|
2521
2541
|
);
|
|
2522
2542
|
const records = result.rows.map((r) => returning ? this.fromRaw(t, r) : r);
|
|
2523
2543
|
await this.applyJoins(
|
|
@@ -2541,7 +2561,7 @@ var TableRuntime = (_class = class {
|
|
|
2541
2561
|
if (row[f] === void 0) row[f] = this.tbl.toDb(f, args["where"][f]);
|
|
2542
2562
|
}
|
|
2543
2563
|
const { head, values } = this.insertSql(sql, t, [row]);
|
|
2544
|
-
const table =
|
|
2564
|
+
const table = _chunkTYCYYLLMcjs.q.call(void 0, this.tbl.table);
|
|
2545
2565
|
const update = await this.setList(sql, t, _nullishCoalesce(args["update"], () => ( {})), table);
|
|
2546
2566
|
const { joinOps } = update;
|
|
2547
2567
|
let { sets } = update;
|
|
@@ -2562,7 +2582,7 @@ var TableRuntime = (_class = class {
|
|
|
2562
2582
|
const [out] = (await this.exec(
|
|
2563
2583
|
sql`${head} values ${values} on conflict (${target}) do update set ${sql.join(sets, sql`, `)}${cond}${returning}`
|
|
2564
2584
|
)).rows;
|
|
2565
|
-
if (!out) throw new (0,
|
|
2585
|
+
if (!out) throw new (0, _chunkTYCYYLLMcjs.HttpError)(404, `${this.name} not found`);
|
|
2566
2586
|
const record = this.fromRaw(t, out);
|
|
2567
2587
|
if (linked) {
|
|
2568
2588
|
const ops = out["efc_inserted"] ? createOps.filter((o) => o.items.length) : joinOps;
|
|
@@ -2581,9 +2601,9 @@ var TableRuntime = (_class = class {
|
|
|
2581
2601
|
const where = this.where(sql, t, args["where"]);
|
|
2582
2602
|
const links = this.joinColumns(sql, [...this.tbl.joins.keys()]);
|
|
2583
2603
|
const [row] = (await this.exec(
|
|
2584
|
-
sql`delete from ${sql.raw(
|
|
2604
|
+
sql`delete from ${sql.raw(_chunkTYCYYLLMcjs.q.call(void 0, this.tbl.table))} where ${where} returning *${links.length ? sql`, ${sql.join(links, sql`, `)}` : sql``}`
|
|
2585
2605
|
)).rows;
|
|
2586
|
-
if (!row) throw new (0,
|
|
2606
|
+
if (!row) throw new (0, _chunkTYCYYLLMcjs.HttpError)(404, `${this.name} not found`);
|
|
2587
2607
|
return this.project(this.fromRaw(t, row), this.projection(args));
|
|
2588
2608
|
});
|
|
2589
2609
|
}
|
|
@@ -2591,7 +2611,7 @@ var TableRuntime = (_class = class {
|
|
|
2591
2611
|
const { t, sql } = await this.ready(args["where"]);
|
|
2592
2612
|
return this.tbl.guard(async () => {
|
|
2593
2613
|
const where = _nullishCoalesce(this.where(sql, t, args["where"]), () => ( sql`true`));
|
|
2594
|
-
const result = await this.tbl.client().execute(sql`delete from ${sql.raw(
|
|
2614
|
+
const result = await this.tbl.client().execute(sql`delete from ${sql.raw(_chunkTYCYYLLMcjs.q.call(void 0, this.tbl.table))} where ${where}`);
|
|
2595
2615
|
return { count: _nullishCoalesce(result.rowCount, () => ( 0)) };
|
|
2596
2616
|
});
|
|
2597
2617
|
}
|
|
@@ -2600,10 +2620,10 @@ function relArgs(arg) {
|
|
|
2600
2620
|
return isPlainObject(arg) ? arg : {};
|
|
2601
2621
|
}
|
|
2602
2622
|
function runtimeOf(name, from) {
|
|
2603
|
-
const runtime = _optionalChain([
|
|
2623
|
+
const runtime = _optionalChain([_chunkTYCYYLLMcjs.getRegisteredModel.call(void 0, name), 'optionalAccess', _65 => _65.tableRuntime, 'optionalCall', _66 => _66()]);
|
|
2604
2624
|
if (!runtime) {
|
|
2605
2625
|
throw new Error(
|
|
2606
|
-
|
|
2626
|
+
_chunkTYCYYLLMcjs.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`
|
|
2607
2627
|
);
|
|
2608
2628
|
}
|
|
2609
2629
|
return runtime;
|
|
@@ -2623,7 +2643,7 @@ var JSON_OPS = /* @__PURE__ */ new Set([
|
|
|
2623
2643
|
"mode"
|
|
2624
2644
|
]);
|
|
2625
2645
|
function createTable(name, schema, options = {}) {
|
|
2626
|
-
|
|
2646
|
+
_chunkTYCYYLLMcjs.normalizeSchema.call(void 0, schema, "table", name);
|
|
2627
2647
|
for (const [rel, def] of Object.entries(_nullishCoalesce(options.relations, () => ( {})))) {
|
|
2628
2648
|
const where = `[EFC] ${name}.relations.${rel}`;
|
|
2629
2649
|
if (rel in schema) throw new Error(`${where}: a field already has this name`);
|
|
@@ -2638,7 +2658,7 @@ function createTable(name, schema, options = {}) {
|
|
|
2638
2658
|
}
|
|
2639
2659
|
let runtime;
|
|
2640
2660
|
const rt = () => {
|
|
2641
|
-
const engine =
|
|
2661
|
+
const engine = _chunkTYCYYLLMcjs.getDbEngine.call(void 0, );
|
|
2642
2662
|
if (engine !== "postgresql") {
|
|
2643
2663
|
throw new Error(
|
|
2644
2664
|
`[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`
|
|
@@ -2670,12 +2690,12 @@ function createTable(name, schema, options = {}) {
|
|
|
2670
2690
|
sync: (opts) => call((r) => r.tbl.reconcile(_nullishCoalesce(_optionalChain([opts, 'optionalAccess', _71 => _71.dryRun]), () => ( false)))),
|
|
2671
2691
|
drop: () => call((r) => r.tbl.drop())
|
|
2672
2692
|
};
|
|
2673
|
-
|
|
2693
|
+
_chunkDUADUR6Rcjs.traceOps.call(void 0,
|
|
2674
2694
|
name,
|
|
2675
2695
|
model,
|
|
2676
2696
|
Object.keys(model).filter((op) => !["name", "raw", "sync", "drop"].includes(op))
|
|
2677
2697
|
);
|
|
2678
|
-
|
|
2698
|
+
_chunkTYCYYLLMcjs.registerModel.call(void 0, {
|
|
2679
2699
|
name,
|
|
2680
2700
|
sync: model.sync,
|
|
2681
2701
|
plan: (opts) => call((r) => r.tbl.plan(opts)),
|
|
@@ -2749,7 +2769,7 @@ function mapBulkOp(op) {
|
|
|
2749
2769
|
return { [kind]: b };
|
|
2750
2770
|
}
|
|
2751
2771
|
function createCollection(name, schema, options) {
|
|
2752
|
-
const tree =
|
|
2772
|
+
const tree = _chunkTYCYYLLMcjs.normalizeSchema.call(void 0, schema, "collection", name);
|
|
2753
2773
|
const base = mongoModel(name, tree, options);
|
|
2754
2774
|
const longs = hasLong(tree);
|
|
2755
2775
|
const toRecord = (doc) => {
|
|
@@ -2758,7 +2778,7 @@ function createCollection(name, schema, options) {
|
|
|
2758
2778
|
return longs ? castTree(rec, tree) : rec;
|
|
2759
2779
|
};
|
|
2760
2780
|
const model = async () => {
|
|
2761
|
-
const engine =
|
|
2781
|
+
const engine = _chunkTYCYYLLMcjs.getDbEngine.call(void 0, );
|
|
2762
2782
|
if (engine !== "mongodb") {
|
|
2763
2783
|
throw new Error(
|
|
2764
2784
|
`[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`
|
|
@@ -2767,7 +2787,7 @@ function createCollection(name, schema, options) {
|
|
|
2767
2787
|
return await base.raw();
|
|
2768
2788
|
};
|
|
2769
2789
|
const session = () => {
|
|
2770
|
-
const tx =
|
|
2790
|
+
const tx = _chunkTYCYYLLMcjs.currentTx.call(void 0, );
|
|
2771
2791
|
return _optionalChain([tx, 'optionalAccess', _72 => _72.engine]) === "mongodb" ? tx.session : null;
|
|
2772
2792
|
};
|
|
2773
2793
|
const sess = () => {
|
|
@@ -2992,12 +3012,12 @@ function createCollection(name, schema, options) {
|
|
|
2992
3012
|
sync: (opts) => model().then(() => base.sync(opts)),
|
|
2993
3013
|
drop: () => model().then(() => base.drop())
|
|
2994
3014
|
};
|
|
2995
|
-
|
|
3015
|
+
_chunkDUADUR6Rcjs.traceOps.call(void 0,
|
|
2996
3016
|
name,
|
|
2997
3017
|
model$,
|
|
2998
3018
|
Object.keys(model$).filter((op) => !["name", "raw", "sync", "drop", "watch"].includes(op))
|
|
2999
3019
|
);
|
|
3000
|
-
|
|
3020
|
+
_chunkTYCYYLLMcjs.registerModel.call(void 0, {
|
|
3001
3021
|
name,
|
|
3002
3022
|
sync: model$.sync,
|
|
3003
3023
|
plan: (opts) => model().then(() => base.plan(opts)),
|
|
@@ -3046,4 +3066,4 @@ var db = new Proxy({}, {
|
|
|
3046
3066
|
|
|
3047
3067
|
|
|
3048
3068
|
exports.connectMongo = connectMongo; exports.defineModel = defineModel; exports.transaction = transaction; exports.defineTable = defineTable; exports.defineCollection = defineCollection; exports.setDbClient = setDbClient; exports.getDbClient = getDbClient; exports.db = db;
|
|
3049
|
-
//# sourceMappingURL=chunk-
|
|
3069
|
+
//# sourceMappingURL=chunk-VWSUQKCJ.cjs.map
|