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