express-file-cluster 0.9.6 → 0.10.2
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 +1 -1
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.js +5 -5
- package/dist/chunk-3SWI46YK.js +74 -0
- package/dist/chunk-3SWI46YK.js.map +1 -0
- package/dist/{chunk-DCJOWFVD.cjs → chunk-4GHK27JA.cjs} +3 -3
- package/dist/{chunk-DCJOWFVD.cjs.map → chunk-4GHK27JA.cjs.map} +1 -1
- package/dist/{chunk-NI2BNGGV.js → chunk-5LPRKZPB.js} +2 -2
- package/dist/chunk-74BSJXWD.cjs +220 -0
- package/dist/chunk-74BSJXWD.cjs.map +1 -0
- package/dist/{chunk-6KHBJOLB.cjs → chunk-7BC3AN7R.cjs} +14 -14
- package/dist/{chunk-6KHBJOLB.cjs.map → chunk-7BC3AN7R.cjs.map} +1 -1
- package/dist/chunk-AGOYTFRO.cjs +42 -0
- package/dist/chunk-AGOYTFRO.cjs.map +1 -0
- package/dist/{chunk-HBYSKULC.js → chunk-B6MB6HEG.js} +5 -1
- package/dist/chunk-B6MB6HEG.js.map +1 -0
- package/dist/{chunk-OFA7OGN5.js → chunk-BG4A7Z32.js} +176 -7
- package/dist/chunk-BG4A7Z32.js.map +1 -0
- package/dist/{chunk-45BWAR6P.js → chunk-C2FOZ7ME.js} +4 -4
- package/dist/chunk-CGY7JU4Y.cjs +8 -0
- package/dist/chunk-CGY7JU4Y.cjs.map +1 -0
- package/dist/{chunk-BBSZLGZW.js → chunk-DN4TCGYB.js} +43 -14
- package/dist/chunk-DN4TCGYB.js.map +1 -0
- package/dist/{chunk-TI24L4XE.cjs → chunk-H2PVWCWC.cjs} +6 -2
- package/dist/chunk-H2PVWCWC.cjs.map +1 -0
- package/dist/{chunk-TYCYYLLM.cjs → chunk-IUZ6A7PB.cjs} +20 -53
- package/dist/chunk-IUZ6A7PB.cjs.map +1 -0
- package/dist/{chunk-DUADUR6R.cjs → chunk-JP36TLL4.cjs} +171 -14
- package/dist/chunk-JP36TLL4.cjs.map +1 -0
- package/dist/chunk-KLWL7XSC.js +220 -0
- package/dist/chunk-KLWL7XSC.js.map +1 -0
- package/dist/{chunk-QL6EWT4B.cjs → chunk-M53GODCX.cjs} +44 -15
- package/dist/chunk-M53GODCX.cjs.map +1 -0
- package/dist/{chunk-7ZESZG3J.js → chunk-MUVO7MGS.js} +4 -4
- package/dist/{chunk-VWSUQKCJ.cjs → chunk-R2K7AFIB.cjs} +286 -117
- package/dist/chunk-R2K7AFIB.cjs.map +1 -0
- package/dist/{chunk-ULWNHN6P.js → chunk-RETV3GKE.js} +9 -42
- package/dist/chunk-RETV3GKE.js.map +1 -0
- package/dist/{chunk-7YEX4MQV.cjs → chunk-RPL2IFWK.cjs} +46 -7
- package/dist/chunk-RPL2IFWK.cjs.map +1 -0
- package/dist/{chunk-FMA76PRH.cjs → chunk-TBIVIR6L.cjs} +15 -15
- package/dist/{chunk-FMA76PRH.cjs.map → chunk-TBIVIR6L.cjs.map} +1 -1
- package/dist/{chunk-73XJUT2S.js → chunk-V73R76I4.js} +162 -5
- package/dist/chunk-V73R76I4.js.map +1 -0
- package/dist/chunk-XPY5TQDK.js +42 -0
- package/dist/chunk-XPY5TQDK.js.map +1 -0
- package/dist/{chunk-RGT4ZVHL.cjs → chunk-Y4NKIXUL.cjs} +110 -55
- package/dist/chunk-Y4NKIXUL.cjs.map +1 -0
- package/dist/{chunk-2SETEVMO.js → chunk-Y75V5FCU.js} +100 -45
- package/dist/chunk-Y75V5FCU.js.map +1 -0
- package/dist/cli/db-runner.cjs +2059 -126
- package/dist/cli/db-runner.cjs.map +1 -1
- package/dist/cli/db-runner.js +2034 -102
- package/dist/cli/db-runner.js.map +1 -1
- package/dist/cli/index.cjs +50 -29
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +39 -21
- package/dist/cli/index.js.map +1 -1
- package/dist/docs/api-reference/auth.md +23 -0
- package/dist/docs/api-reference/collection.md +44 -1
- 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 +13 -1
- package/dist/docs/api-reference/testing.md +26 -0
- package/dist/docs/api-reference/types.md +99 -0
- package/dist/docs/cli/add.md +2 -2
- package/dist/docs/cli/db.md +2 -2
- package/dist/docs/core-concepts/background-tasks.md +6 -3
- package/dist/docs/core-concepts/file-based-routing.md +2 -0
- package/dist/docs/core-concepts/middleware.md +2 -2
- package/dist/docs/getting-started/index.md +6 -1
- package/dist/docs/guides/authentication.md +33 -0
- package/dist/docs/guides/caching.md +34 -1
- package/dist/docs/guides/database.md +17 -0
- package/dist/docs/guides/environment-variables.md +6 -0
- package/dist/docs/guides/feature-matrix.md +58 -0
- package/dist/docs/guides/generated-portals.md +3 -1
- package/dist/docs/guides/logging.md +17 -0
- package/dist/docs/guides/migrations.md +26 -3
- package/dist/docs/guides/testing.md +31 -0
- package/dist/docs/guides/which-api.md +2 -2
- package/dist/docs/index.md +4 -1
- package/dist/docs/skills/SKILL.md +5 -1
- package/dist/docs/skills/api-surface.md +25 -4
- package/dist/docs/skills/auth-internals.md +14 -1
- package/dist/docs/skills/pre-flight.md +6 -0
- package/dist/docs/skills/routing-rules.md +1 -1
- package/dist/docs/skills/tasks-internals.md +4 -3
- package/dist/docs/skills/what-not-to-invent.md +13 -4
- package/dist/docs/versioning.md +1 -1
- package/dist/index.cjs +135 -255
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +228 -3
- package/dist/index.d.ts +228 -3
- package/dist/index.js +96 -217
- package/dist/index.js.map +1 -1
- package/dist/pgboss-backend-4X2YT4RB.js +14 -0
- package/dist/pgboss-backend-UXQ3O2WT.cjs +15 -0
- package/dist/pgboss-backend-UXQ3O2WT.cjs.map +1 -0
- package/dist/registry/index.json +39 -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/_base.json +1 -0
- package/dist/registry/js-mongo-collection/account-security.json +1 -0
- package/dist/registry/js-mongo-collection/account-settings.json +1 -0
- package/dist/registry/js-mongo-collection/admin-admins.json +1 -0
- package/dist/registry/js-mongo-collection/admin-analytics.json +1 -0
- package/dist/registry/js-mongo-collection/admin-billing.json +1 -0
- package/dist/registry/js-mongo-collection/admin-content.json +1 -0
- package/dist/registry/js-mongo-collection/admin-logs.json +1 -0
- package/dist/registry/js-mongo-collection/admin-support.json +1 -0
- package/dist/registry/js-mongo-collection/admin-system.json +1 -0
- package/dist/registry/js-mongo-collection/admin-users.json +1 -0
- package/dist/registry/js-mongo-collection/admin.json +1 -0
- package/dist/registry/js-mongo-collection/auth.json +1 -0
- package/dist/registry/js-mongo-collection/auth@apple.json +1 -0
- package/dist/registry/js-mongo-collection/auth@google.json +1 -0
- package/dist/registry/js-mongo-collection/billing.json +1 -0
- package/dist/registry/js-mongo-collection/email-client.json +1 -0
- package/dist/registry/js-mongo-collection/email-verification.json +1 -0
- package/dist/registry/js-mongo-collection/files.json +1 -0
- package/dist/registry/js-mongo-collection/forgot-password.json +1 -0
- package/dist/registry/js-mongo-collection/notifications.json +1 -0
- package/dist/registry/js-mongo-collection/support.json +1 -0
- package/dist/registry/js-mongo-collection/user-profile.json +1 -0
- package/dist/registry/js-pg-model/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/_base.json +1 -0
- package/dist/registry/ts-mongo-collection/account-security.json +1 -0
- package/dist/registry/ts-mongo-collection/account-settings.json +1 -0
- package/dist/registry/ts-mongo-collection/admin-admins.json +1 -0
- package/dist/registry/ts-mongo-collection/admin-analytics.json +1 -0
- package/dist/registry/ts-mongo-collection/admin-billing.json +1 -0
- package/dist/registry/ts-mongo-collection/admin-content.json +1 -0
- package/dist/registry/ts-mongo-collection/admin-logs.json +1 -0
- package/dist/registry/ts-mongo-collection/admin-support.json +1 -0
- package/dist/registry/ts-mongo-collection/admin-system.json +1 -0
- package/dist/registry/ts-mongo-collection/admin-users.json +1 -0
- package/dist/registry/ts-mongo-collection/admin.json +1 -0
- package/dist/registry/ts-mongo-collection/auth.json +1 -0
- package/dist/registry/ts-mongo-collection/auth@apple.json +1 -0
- package/dist/registry/ts-mongo-collection/auth@google.json +1 -0
- package/dist/registry/ts-mongo-collection/billing.json +1 -0
- package/dist/registry/ts-mongo-collection/email-client.json +1 -0
- package/dist/registry/ts-mongo-collection/email-verification.json +1 -0
- package/dist/registry/ts-mongo-collection/files.json +1 -0
- package/dist/registry/ts-mongo-collection/forgot-password.json +1 -0
- package/dist/registry/ts-mongo-collection/notifications.json +1 -0
- package/dist/registry/ts-mongo-collection/support.json +1 -0
- package/dist/registry/ts-mongo-collection/user-profile.json +1 -0
- package/dist/registry/ts-pg-model/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 +5 -2
- package/dist/tasks/index.cjs.map +1 -1
- package/dist/tasks/index.d.cts +4 -2
- package/dist/tasks/index.d.ts +4 -2
- package/dist/tasks/index.js +3 -1
- package/dist/testing-cjs.cjs +5 -0
- package/dist/testing.cjs +59 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +27 -0
- package/dist/testing.d.ts +27 -0
- package/dist/testing.js +58 -0
- package/dist/testing.js.map +1 -0
- package/dist/thread-runner.cjs +9 -0
- package/dist/thread-runner.cjs.map +1 -0
- package/dist/thread-runner.d.cts +3 -0
- package/dist/thread-runner.d.ts +3 -0
- package/dist/thread-runner.js +8 -0
- package/dist/thread-runner.js.map +1 -0
- package/dist/{types-DAsBKVM-.d.ts → types-CPMFTVXm.d.cts} +15 -1
- package/dist/{types-DAsBKVM-.d.cts → types-CPMFTVXm.d.ts} +15 -1
- package/package.json +6 -1
- package/dist/chunk-2SETEVMO.js.map +0 -1
- package/dist/chunk-73XJUT2S.js.map +0 -1
- package/dist/chunk-7YEX4MQV.cjs.map +0 -1
- package/dist/chunk-BBSZLGZW.js.map +0 -1
- package/dist/chunk-DUADUR6R.cjs.map +0 -1
- package/dist/chunk-HBYSKULC.js.map +0 -1
- package/dist/chunk-LJNSJFOL.js +0 -38
- package/dist/chunk-LJNSJFOL.js.map +0 -1
- package/dist/chunk-OFA7OGN5.js.map +0 -1
- package/dist/chunk-QL6EWT4B.cjs.map +0 -1
- package/dist/chunk-RGT4ZVHL.cjs.map +0 -1
- package/dist/chunk-TI24L4XE.cjs.map +0 -1
- package/dist/chunk-TYCYYLLM.cjs.map +0 -1
- package/dist/chunk-ULWNHN6P.js.map +0 -1
- package/dist/chunk-VWSUQKCJ.cjs.map +0 -1
- package/dist/pgboss-backend-DSO3QTNK.cjs +0 -14
- package/dist/pgboss-backend-DSO3QTNK.cjs.map +0 -1
- package/dist/pgboss-backend-I6DFUNRM.js +0 -14
- /package/dist/{chunk-NI2BNGGV.js.map → chunk-5LPRKZPB.js.map} +0 -0
- /package/dist/{chunk-45BWAR6P.js.map → chunk-C2FOZ7ME.js.map} +0 -0
- /package/dist/{chunk-7ZESZG3J.js.map → chunk-MUVO7MGS.js.map} +0 -0
- /package/dist/{pgboss-backend-I6DFUNRM.js.map → pgboss-backend-4X2YT4RB.js.map} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -2,196 +2,71 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
+
var _chunk74BSJXWDcjs = require('./chunk-74BSJXWD.cjs');
|
|
5
6
|
|
|
6
7
|
|
|
7
|
-
var _chunkRGT4ZVHLcjs = require('./chunk-RGT4ZVHL.cjs');
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var _chunkDCJOWFVDcjs = require('./chunk-DCJOWFVD.cjs');
|
|
11
10
|
|
|
12
11
|
|
|
13
12
|
|
|
14
|
-
var _chunkFMA76PRHcjs = require('./chunk-FMA76PRH.cjs');
|
|
15
13
|
|
|
14
|
+
var _chunkY4NKIXULcjs = require('./chunk-Y4NKIXUL.cjs');
|
|
16
15
|
|
|
17
16
|
|
|
17
|
+
var _chunk4GHK27JAcjs = require('./chunk-4GHK27JA.cjs');
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
|
|
21
|
+
var _chunkTBIVIR6Lcjs = require('./chunk-TBIVIR6L.cjs');
|
|
21
22
|
|
|
22
23
|
|
|
23
24
|
|
|
24
|
-
var _chunkVWSUQKCJcjs = require('./chunk-VWSUQKCJ.cjs');
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
|
|
31
|
-
var
|
|
31
|
+
var _chunkR2K7AFIBcjs = require('./chunk-R2K7AFIB.cjs');
|
|
32
32
|
|
|
33
33
|
|
|
34
34
|
|
|
35
|
-
var _chunk6KHBJOLBcjs = require('./chunk-6KHBJOLB.cjs');
|
|
36
|
-
require('./chunk-7YEX4MQV.cjs');
|
|
37
35
|
|
|
36
|
+
var _chunkIUZ6A7PBcjs = require('./chunk-IUZ6A7PB.cjs');
|
|
38
37
|
|
|
39
38
|
|
|
40
|
-
var _chunkTI24L4XEcjs = require('./chunk-TI24L4XE.cjs');
|
|
41
39
|
|
|
40
|
+
var _chunkAGOYTFROcjs = require('./chunk-AGOYTFRO.cjs');
|
|
42
41
|
|
|
43
42
|
|
|
44
43
|
|
|
44
|
+
var _chunk7BC3AN7Rcjs = require('./chunk-7BC3AN7R.cjs');
|
|
45
|
+
require('./chunk-RPL2IFWK.cjs');
|
|
45
46
|
|
|
46
47
|
|
|
47
48
|
|
|
49
|
+
var _chunkH2PVWCWCcjs = require('./chunk-H2PVWCWC.cjs');
|
|
48
50
|
|
|
49
51
|
|
|
50
52
|
|
|
51
|
-
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
var _chunkJP36TLL4cjs = require('./chunk-JP36TLL4.cjs');
|
|
61
|
+
require('./chunk-CGY7JU4Y.cjs');
|
|
52
62
|
|
|
53
63
|
// src/index.ts
|
|
54
64
|
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
|
|
55
65
|
var _express = require('express'); var _express2 = _interopRequireDefault(_express);
|
|
56
|
-
var _cors = require('cors'); var _cors2 = _interopRequireDefault(_cors);
|
|
57
|
-
var _cookieparser = require('cookie-parser'); var _cookieparser2 = _interopRequireDefault(_cookieparser);
|
|
58
66
|
var _cluster = require('cluster'); var _cluster2 = _interopRequireDefault(_cluster);
|
|
59
67
|
var _os = require('os'); var _os2 = _interopRequireDefault(_os);
|
|
60
68
|
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
61
69
|
|
|
62
|
-
// src/router/validate.ts
|
|
63
|
-
var LOCATIONS = ["params", "query", "body"];
|
|
64
|
-
function isRequestSchema(value) {
|
|
65
|
-
return value != null && typeof value === "object" && LOCATIONS.some((loc) => loc in value);
|
|
66
|
-
}
|
|
67
|
-
function schemaFor(schema, method) {
|
|
68
|
-
if (!schema) return void 0;
|
|
69
|
-
const byMethod = schema[method];
|
|
70
|
-
if (isRequestSchema(byMethod)) return byMethod;
|
|
71
|
-
return isRequestSchema(schema) ? schema : void 0;
|
|
72
|
-
}
|
|
73
|
-
function pathToString(path3) {
|
|
74
|
-
if (!path3) return "";
|
|
75
|
-
return path3.map((p) => typeof p === "object" && p !== null && "key" in p ? p.key : p).map(String).join(".");
|
|
76
|
-
}
|
|
77
|
-
async function run(validator, input) {
|
|
78
|
-
const std = validator["~standard"];
|
|
79
|
-
if (std && typeof std.validate === "function") {
|
|
80
|
-
return await std.validate(input);
|
|
81
|
-
}
|
|
82
|
-
const v = validator;
|
|
83
|
-
const parse = _nullishCoalesce(v.safeParseAsync, () => ( v.safeParse));
|
|
84
|
-
if (typeof parse !== "function") {
|
|
85
|
-
throw new Error("[EFC] Route schema entries must be Standard Schema validators (e.g. zod)");
|
|
86
|
-
}
|
|
87
|
-
const r = await parse.call(validator, input);
|
|
88
|
-
return r.success ? { value: r.data } : { issues: _nullishCoalesce(_optionalChain([r, 'access', _ => _.error, 'optionalAccess', _2 => _2.issues]), () => ( [{ message: "Invalid" }])) };
|
|
89
|
-
}
|
|
90
|
-
function validateRequest(schema) {
|
|
91
|
-
return (req, res, next) => {
|
|
92
|
-
void (async () => {
|
|
93
|
-
const issues = [];
|
|
94
|
-
const parsed = {};
|
|
95
|
-
for (const location of LOCATIONS) {
|
|
96
|
-
const validator = schema[location];
|
|
97
|
-
if (!validator) continue;
|
|
98
|
-
const result = await run(validator, req[location]);
|
|
99
|
-
if (result.issues) {
|
|
100
|
-
for (const issue of result.issues) {
|
|
101
|
-
issues.push({ location, path: pathToString(issue.path), message: issue.message });
|
|
102
|
-
}
|
|
103
|
-
} else {
|
|
104
|
-
parsed[location] = result.value;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
if (issues.length > 0) {
|
|
108
|
-
res.status(400).json({ error: "Validation failed", statusCode: 400, issues });
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
for (const location of LOCATIONS) {
|
|
112
|
-
if (location in parsed) {
|
|
113
|
-
Object.defineProperty(req, location, {
|
|
114
|
-
value: parsed[location],
|
|
115
|
-
writable: true,
|
|
116
|
-
configurable: true,
|
|
117
|
-
enumerable: true
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
next();
|
|
122
|
-
})().catch(next);
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// src/router/mount.ts
|
|
127
|
-
var HTTP_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"];
|
|
128
|
-
function asyncWrap(handler) {
|
|
129
|
-
return (req, res, next) => {
|
|
130
|
-
Promise.resolve(handler(req, res, next)).catch(next);
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
function namedParams(route) {
|
|
134
|
-
const catchAlls = new Set([...route.urlPath.matchAll(/:([A-Za-z0-9_$]+)\*/g)].map((m) => m[1]));
|
|
135
|
-
return (req, _res, next) => {
|
|
136
|
-
const positional = req.params;
|
|
137
|
-
const named = {};
|
|
138
|
-
route.params.forEach((name, i) => {
|
|
139
|
-
const value = positional[String(i)];
|
|
140
|
-
if (value === void 0 || value === "") {
|
|
141
|
-
named[name] = catchAlls.has(name) ? [] : void 0;
|
|
142
|
-
} else if (catchAlls.has(name)) {
|
|
143
|
-
named[name] = value.split("/").filter(Boolean).map(decodeURIComponent);
|
|
144
|
-
} else {
|
|
145
|
-
named[name] = decodeURIComponent(value);
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
req.params = named;
|
|
149
|
-
next();
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
async function mountRoutes(app, routes) {
|
|
153
|
-
const mounted = [];
|
|
154
|
-
for (const route of routes) {
|
|
155
|
-
const mod = await Promise.resolve().then(() => _interopRequireWildcard(require(route.filePath)));
|
|
156
|
-
const routeMiddlewares = Array.isArray(mod["middlewares"]) ? mod["middlewares"] : [];
|
|
157
|
-
const raw = mod["meta"];
|
|
158
|
-
const meta = raw != null && typeof raw === "object" && !Array.isArray(raw) ? raw : void 0;
|
|
159
|
-
const schema = mod["schema"] != null && typeof mod["schema"] === "object" ? mod["schema"] : void 0;
|
|
160
|
-
const routePath = _nullishCoalesce(route.pattern, () => ( route.urlPath));
|
|
161
|
-
const paramMapper = route.pattern ? [namedParams(route)] : [];
|
|
162
|
-
const implemented = [];
|
|
163
|
-
const unimplemented = [];
|
|
164
|
-
for (const method of HTTP_METHODS) {
|
|
165
|
-
if (typeof mod[method] === "function") {
|
|
166
|
-
implemented.push(method);
|
|
167
|
-
const methodSchema = schemaFor(schema, method);
|
|
168
|
-
const validation = methodSchema ? [validateRequest(methodSchema)] : [];
|
|
169
|
-
app[method.toLowerCase()](
|
|
170
|
-
routePath,
|
|
171
|
-
...paramMapper,
|
|
172
|
-
...routeMiddlewares,
|
|
173
|
-
...validation,
|
|
174
|
-
asyncWrap(mod[method])
|
|
175
|
-
);
|
|
176
|
-
} else {
|
|
177
|
-
unimplemented.push(method);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
if (implemented.length > 0 && unimplemented.length > 0) {
|
|
181
|
-
const allowHeader = implemented.join(", ");
|
|
182
|
-
app.all(routePath, (req, res, next) => {
|
|
183
|
-
if (unimplemented.includes(req.method)) {
|
|
184
|
-
res.set("Allow", allowHeader).status(405).json({ error: "Method Not Allowed" });
|
|
185
|
-
} else {
|
|
186
|
-
next();
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
mounted.push({ ...route, methods: implemented, ...meta !== void 0 && { meta } });
|
|
191
|
-
}
|
|
192
|
-
return mounted;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
70
|
// src/cluster/index.ts
|
|
196
71
|
|
|
197
72
|
var isShuttingDown = false;
|
|
@@ -200,33 +75,33 @@ function workerCount() {
|
|
|
200
75
|
}
|
|
201
76
|
function shutdownMaster() {
|
|
202
77
|
isShuttingDown = true;
|
|
203
|
-
|
|
78
|
+
_chunkJP36TLL4cjs.getLogger.call(void 0, ).info(`Cluster primary (pid=${process.pid}) shutting down, waiting for workers\u2026`);
|
|
204
79
|
if (workerCount() === 0) process.exit(0);
|
|
205
80
|
for (const worker of Object.values(_nullishCoalesce(_cluster2.default.workers, () => ( {})))) {
|
|
206
|
-
_optionalChain([worker, 'optionalAccess',
|
|
81
|
+
_optionalChain([worker, 'optionalAccess', _ => _.process, 'access', _2 => _2.kill, 'call', _3 => _3("SIGTERM")]);
|
|
207
82
|
}
|
|
208
83
|
}
|
|
209
84
|
function runMaster(options = {}) {
|
|
210
85
|
const count = _nullishCoalesce(options.workers, () => ( 1));
|
|
211
|
-
|
|
86
|
+
_chunkJP36TLL4cjs.getLogger.call(void 0, ).info(`Primary ${process.pid} starting ${count} workers`);
|
|
212
87
|
for (let i = 0; i < count; i++) {
|
|
213
88
|
_cluster2.default.fork();
|
|
214
89
|
}
|
|
215
90
|
_cluster2.default.on("online", (worker) => {
|
|
216
|
-
_optionalChain([options, 'access',
|
|
91
|
+
_optionalChain([options, 'access', _4 => _4.onWorkerReady, 'optionalCall', _5 => _5(worker.id)]);
|
|
217
92
|
});
|
|
218
93
|
_cluster2.default.on("exit", (worker, code, signal) => {
|
|
219
94
|
const exitCode = _nullishCoalesce(code, () => ( (signal ? -1 : 0)));
|
|
220
95
|
if (isShuttingDown) {
|
|
221
|
-
|
|
96
|
+
_chunkJP36TLL4cjs.getLogger.call(void 0, ).info(`Worker ${worker.id} gracefully exited`);
|
|
222
97
|
if (workerCount() === 0) {
|
|
223
|
-
|
|
98
|
+
_chunkJP36TLL4cjs.getLogger.call(void 0, ).info("All workers exited. Primary exiting.");
|
|
224
99
|
process.exit(0);
|
|
225
100
|
}
|
|
226
101
|
return;
|
|
227
102
|
}
|
|
228
|
-
|
|
229
|
-
_optionalChain([options, 'access',
|
|
103
|
+
_chunkJP36TLL4cjs.getLogger.call(void 0, ).warn(`Worker ${worker.id} exited (code=${exitCode}), respawning\u2026`);
|
|
104
|
+
_optionalChain([options, 'access', _6 => _6.onWorkerCrash, 'optionalCall', _7 => _7(worker.id, exitCode)]);
|
|
230
105
|
_cluster2.default.fork();
|
|
231
106
|
});
|
|
232
107
|
}
|
|
@@ -244,13 +119,13 @@ async function scanTasks(tasksDir) {
|
|
|
244
119
|
const mod = await Promise.resolve().then(() => _interopRequireWildcard(require(filePath)));
|
|
245
120
|
const def = mod["default"];
|
|
246
121
|
if (!def || typeof def.handler !== "function") {
|
|
247
|
-
|
|
122
|
+
_chunkJP36TLL4cjs.getLogger.call(void 0, ).warn(`Task file ${file} has no valid default export \u2014 skipping`);
|
|
248
123
|
continue;
|
|
249
124
|
}
|
|
250
|
-
|
|
251
|
-
|
|
125
|
+
_chunkH2PVWCWCcjs.registerTask.call(void 0, taskName, { ...def, filePath });
|
|
126
|
+
_chunkJP36TLL4cjs.getLogger.call(void 0, ).debug(`Registered task: ${taskName}`);
|
|
252
127
|
} catch (err) {
|
|
253
|
-
|
|
128
|
+
_chunkJP36TLL4cjs.getLogger.call(void 0, ).warn({ err }, `Failed to load task ${file}`);
|
|
254
129
|
}
|
|
255
130
|
}
|
|
256
131
|
}
|
|
@@ -853,6 +728,71 @@ function generateDashboard(routes, basePath, port, projectName, projectVersion)
|
|
|
853
728
|
</html>`;
|
|
854
729
|
}
|
|
855
730
|
|
|
731
|
+
// src/rate-limit.ts
|
|
732
|
+
var UNITS = { s: 1, m: 60, h: 3600, d: 86400 };
|
|
733
|
+
function parseWindow(window) {
|
|
734
|
+
if (typeof window === "number") {
|
|
735
|
+
if (window > 0) return window;
|
|
736
|
+
} else {
|
|
737
|
+
const m = /^(\d+(?:\.\d+)?)\s*(s|m|h|d)$/.exec(window.trim());
|
|
738
|
+
if (m) return Number(m[1]) * UNITS[m[2]];
|
|
739
|
+
}
|
|
740
|
+
throw new Error(`[EFC] rateLimit: window must be seconds or like '15m' \u2014 got ${String(window)}`);
|
|
741
|
+
}
|
|
742
|
+
var lastCacheError = 0;
|
|
743
|
+
function rateLimit(options) {
|
|
744
|
+
const windowSeconds = parseWindow(options.window);
|
|
745
|
+
if (!Number.isInteger(options.max) || options.max < 1) {
|
|
746
|
+
throw new Error("[EFC] rateLimit: max must be a positive integer");
|
|
747
|
+
}
|
|
748
|
+
const keyOf = _nullishCoalesce(options.key, () => ( ((req) => _nullishCoalesce(req.ip, () => ( req.socket.remoteAddress)))));
|
|
749
|
+
const message = _nullishCoalesce(options.message, () => ( "Too many requests, try again later"));
|
|
750
|
+
const headers = _nullishCoalesce(options.headers, () => ( true));
|
|
751
|
+
return (req, res, next) => {
|
|
752
|
+
void (async () => {
|
|
753
|
+
const who = keyOf(req);
|
|
754
|
+
if (who === void 0) return next();
|
|
755
|
+
if (!_chunkY4NKIXULcjs.isCacheConfigured.call(void 0, )) {
|
|
756
|
+
throw new Error("[EFC] rateLimit needs a cache \u2014 pass cache: { backend } to ignite()");
|
|
757
|
+
}
|
|
758
|
+
const bucket = _nullishCoalesce(options.name, () => ( req.baseUrl + (_nullishCoalesce(_optionalChain([req, 'access', _8 => _8.route, 'optionalAccess', _9 => _9.path]), () => ( req.path)))));
|
|
759
|
+
const windowMs = windowSeconds * 1e3;
|
|
760
|
+
const now = Date.now();
|
|
761
|
+
const slot = Math.floor(now / windowMs);
|
|
762
|
+
const resetMs = (slot + 1) * windowMs - now;
|
|
763
|
+
let count;
|
|
764
|
+
try {
|
|
765
|
+
count = (await _chunkY4NKIXULcjs.rawIncr.call(void 0, `rl:${bucket}:${who}:${slot}`, Math.ceil(resetMs / 1e3) + 1)).value;
|
|
766
|
+
} catch (err) {
|
|
767
|
+
if (Date.now() - lastCacheError > 3e4) {
|
|
768
|
+
lastCacheError = Date.now();
|
|
769
|
+
_chunkJP36TLL4cjs.getLogger.call(void 0, ).error(
|
|
770
|
+
{ err },
|
|
771
|
+
`rateLimit: cache unavailable \u2014 ${options.onCacheError === "reject" ? "rejecting with 503" : "allowing requests"}`
|
|
772
|
+
);
|
|
773
|
+
}
|
|
774
|
+
if (options.onCacheError === "reject") {
|
|
775
|
+
res.status(503).json({ error: "Service Unavailable", statusCode: 503 });
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
778
|
+
return next();
|
|
779
|
+
}
|
|
780
|
+
const resetSeconds = Math.max(1, Math.ceil(resetMs / 1e3));
|
|
781
|
+
if (headers) {
|
|
782
|
+
res.setHeader("RateLimit-Limit", String(options.max));
|
|
783
|
+
res.setHeader("RateLimit-Remaining", String(Math.max(0, options.max - count)));
|
|
784
|
+
res.setHeader("RateLimit-Reset", String(resetSeconds));
|
|
785
|
+
}
|
|
786
|
+
if (count > options.max) {
|
|
787
|
+
if (headers) res.setHeader("Retry-After", String(resetSeconds));
|
|
788
|
+
res.status(429).json({ error: message, statusCode: 429 });
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
next();
|
|
792
|
+
})().catch(next);
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
|
|
856
796
|
// src/cache/response.ts
|
|
857
797
|
var RESPONSE_PREFIX = "res:";
|
|
858
798
|
function cacheResponse(options) {
|
|
@@ -861,14 +801,14 @@ function cacheResponse(options) {
|
|
|
861
801
|
if (req.method !== "GET" && req.method !== "HEAD") return next();
|
|
862
802
|
let scope = "";
|
|
863
803
|
if (opts.perUser) {
|
|
864
|
-
const user =
|
|
804
|
+
const user = _chunkJP36TLL4cjs.getCurrentUser.call(void 0, );
|
|
865
805
|
const id = _nullishCoalesce(_optionalChain([user, 'optionalAccess', _10 => _10["sub"]]), () => ( _optionalChain([user, 'optionalAccess', _11 => _11["id"]])));
|
|
866
806
|
if (id === void 0) return next();
|
|
867
807
|
scope = `u:${String(id)}:`;
|
|
868
808
|
}
|
|
869
809
|
const key = RESPONSE_PREFIX + scope + (opts.key ? opts.key(req) : req.originalUrl);
|
|
870
810
|
void (async () => {
|
|
871
|
-
const hit = await
|
|
811
|
+
const hit = await _chunkY4NKIXULcjs.cache.get(key);
|
|
872
812
|
if (hit) {
|
|
873
813
|
res.setHeader("X-Cache", "HIT");
|
|
874
814
|
res.status(hit.status).json(hit.body);
|
|
@@ -877,7 +817,7 @@ function cacheResponse(options) {
|
|
|
877
817
|
res.setHeader("X-Cache", "MISS");
|
|
878
818
|
const json = res.json.bind(res);
|
|
879
819
|
res.json = (body) => {
|
|
880
|
-
if (res.statusCode === 200) void
|
|
820
|
+
if (res.statusCode === 200) void _chunkY4NKIXULcjs.cache.set(key, { status: 200, body }, { ttl: opts.ttl });
|
|
881
821
|
return json(body);
|
|
882
822
|
};
|
|
883
823
|
next();
|
|
@@ -899,7 +839,9 @@ function compose(...handlers) {
|
|
|
899
839
|
return;
|
|
900
840
|
}
|
|
901
841
|
try {
|
|
902
|
-
Promise.resolve(
|
|
842
|
+
Promise.resolve(
|
|
843
|
+
handler(req, res, (err) => err ? next(err) : dispatch(i + 1))
|
|
844
|
+
).catch(next);
|
|
903
845
|
} catch (err) {
|
|
904
846
|
next(err);
|
|
905
847
|
}
|
|
@@ -916,14 +858,7 @@ function detectDatabase(url) {
|
|
|
916
858
|
return void 0;
|
|
917
859
|
}
|
|
918
860
|
async function ignite(config) {
|
|
919
|
-
const {
|
|
920
|
-
port: _port,
|
|
921
|
-
workers,
|
|
922
|
-
globalMiddlewares = [],
|
|
923
|
-
onWorkerReady,
|
|
924
|
-
onWorkerCrash,
|
|
925
|
-
onError
|
|
926
|
-
} = config;
|
|
861
|
+
const { port: _port, workers, onWorkerReady, onWorkerCrash, onError } = config;
|
|
927
862
|
function resolveConventionDir(name) {
|
|
928
863
|
const candidates = [
|
|
929
864
|
...process.argv[1] ? [_path2.default.join(_path2.default.dirname(process.argv[1]), name)] : [],
|
|
@@ -951,21 +886,21 @@ async function ignite(config) {
|
|
|
951
886
|
const jwtSecret = config.jwtSecret;
|
|
952
887
|
const authStrategy = _nullishCoalesce(config.authStrategy, () => ( "http-only"));
|
|
953
888
|
const clusterEnabled = _nullishCoalesce(config.cluster, () => ( process.env["NODE_ENV"] === "production"));
|
|
954
|
-
|
|
889
|
+
_chunkJP36TLL4cjs.configureLogger.call(void 0, config.logging);
|
|
955
890
|
if (!["http-only", "bearer", "localStorage"].includes(authStrategy) && (!clusterEnabled || _cluster2.default.isPrimary)) {
|
|
956
|
-
|
|
891
|
+
_chunkJP36TLL4cjs.getLogger.call(void 0, ).warn(
|
|
957
892
|
`[EFC] Unknown authStrategy "${String(authStrategy)}" \u2014 treated as 'bearer'. Use 'http-only' or 'bearer'; this will be an error in 1.0.`
|
|
958
893
|
);
|
|
959
894
|
}
|
|
960
895
|
if (jwtSecret && Buffer.byteLength(jwtSecret) < 32 && process.env["NODE_ENV"] === "production" && (!clusterEnabled || _cluster2.default.isPrimary)) {
|
|
961
|
-
|
|
896
|
+
_chunkJP36TLL4cjs.getLogger.call(void 0, ).warn(
|
|
962
897
|
`[EFC] jwtSecret is ${Buffer.byteLength(jwtSecret)} bytes \u2014 use at least 32 random bytes in production (openssl rand -hex 64).`
|
|
963
898
|
);
|
|
964
899
|
}
|
|
965
|
-
|
|
900
|
+
_chunkJP36TLL4cjs.configureQueryLog.call(void 0, config.logging);
|
|
966
901
|
if (clusterEnabled && _cluster2.default.isPrimary) {
|
|
967
902
|
if (config.cache && config.cache.backend === "memory") {
|
|
968
|
-
|
|
903
|
+
_chunkY4NKIXULcjs.servePrimaryCache.call(void 0, _nullishCoalesce(config.cache.maxEntries, () => ( 1e4)));
|
|
969
904
|
}
|
|
970
905
|
runMaster({
|
|
971
906
|
workers: _nullishCoalesce(workers, () => ( _os2.default.cpus().length)),
|
|
@@ -974,67 +909,35 @@ async function ignite(config) {
|
|
|
974
909
|
});
|
|
975
910
|
return;
|
|
976
911
|
}
|
|
977
|
-
const app =
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
(_key, value) => typeof value === "bigint" ? value.toString() : value
|
|
981
|
-
);
|
|
982
|
-
app.use((_req, _res, next) => {
|
|
983
|
-
_chunkDUADUR6Rcjs.runWithContext.call(void 0, {}, next);
|
|
984
|
-
});
|
|
985
|
-
app.use(_chunkDUADUR6Rcjs.requestLogger.call(void 0, ));
|
|
986
|
-
if (config.requestTimeout) {
|
|
987
|
-
const ms = config.requestTimeout;
|
|
988
|
-
app.use((_req, res, next) => {
|
|
989
|
-
const timer = setTimeout(() => {
|
|
990
|
-
if (!res.headersSent) res.status(408).json({ error: "Request Timeout", statusCode: 408 });
|
|
991
|
-
}, ms);
|
|
992
|
-
const clear = () => clearTimeout(timer);
|
|
993
|
-
res.once("finish", clear);
|
|
994
|
-
res.once("close", clear);
|
|
995
|
-
next();
|
|
996
|
-
});
|
|
997
|
-
}
|
|
998
|
-
const corsOption = _nullishCoalesce(config.cors, () => ( true));
|
|
999
|
-
if (corsOption !== false) {
|
|
1000
|
-
const origin = typeof corsOption === "object" && corsOption.origin !== void 0 ? corsOption.origin : true;
|
|
1001
|
-
const corsOpts = typeof corsOption === "object" ? { ...corsOption, origin } : { origin };
|
|
1002
|
-
app.use(_cors2.default.call(void 0, corsOpts));
|
|
1003
|
-
}
|
|
1004
|
-
app.use(_express2.default.json());
|
|
1005
|
-
app.use(_express2.default.urlencoded({ extended: true }));
|
|
1006
|
-
app.use(_cookieparser2.default.call(void 0, ));
|
|
1007
|
-
for (const mw of globalMiddlewares) {
|
|
1008
|
-
app.use(mw);
|
|
1009
|
-
}
|
|
1010
|
-
if (database) _chunkTYCYYLLMcjs.setDbEngine.call(void 0, database);
|
|
1011
|
-
_chunkTYCYYLLMcjs.setAutoSync.call(void 0, _nullishCoalesce(config.autoSync, () => ( true)));
|
|
912
|
+
const app = _chunk74BSJXWDcjs.createHttpApp.call(void 0, config);
|
|
913
|
+
if (database) _chunkIUZ6A7PBcjs.setDbEngine.call(void 0, database);
|
|
914
|
+
_chunkIUZ6A7PBcjs.setAutoSync.call(void 0, _nullishCoalesce(config.autoSync, () => ( true)));
|
|
1012
915
|
const poolWorkers = clusterEnabled ? _nullishCoalesce(workers, () => ( _os2.default.cpus().length)) : 1;
|
|
1013
916
|
const reportsPools = !clusterEnabled || _optionalChain([_cluster2.default, 'access', _12 => _12.worker, 'optionalAccess', _13 => _13.id]) === 1;
|
|
1014
917
|
if (database === "mongodb" && databaseUrl) {
|
|
1015
|
-
const conn = await
|
|
1016
|
-
|
|
918
|
+
const conn = await _chunkR2K7AFIBcjs.connectMongo.call(void 0, databaseUrl, config.databasePool);
|
|
919
|
+
_chunkR2K7AFIBcjs.setDbClient.call(void 0, conn);
|
|
1017
920
|
if (reportsPools) {
|
|
1018
921
|
const max = _nullishCoalesce(_optionalChain([config, 'access', _14 => _14.databasePool, 'optionalAccess', _15 => _15.max]), () => ( 100));
|
|
1019
|
-
|
|
922
|
+
_chunkJP36TLL4cjs.getLogger.call(void 0, ).info(
|
|
1020
923
|
`MongoDB connections: up to ${poolWorkers * max} from this machine (${poolWorkers} worker(s) \xD7 maxPoolSize ${max})`
|
|
1021
924
|
);
|
|
1022
925
|
}
|
|
1023
926
|
} else if (database === "postgresql" && databaseUrl) {
|
|
1024
|
-
const pool = await
|
|
1025
|
-
|
|
927
|
+
const pool = await _chunkJP36TLL4cjs.connectPostgres.call(void 0, databaseUrl, config.databasePool);
|
|
928
|
+
_chunkR2K7AFIBcjs.setDbClient.call(void 0, pool);
|
|
1026
929
|
if (reportsPools) {
|
|
1027
930
|
const max = _nullishCoalesce(_optionalChain([config, 'access', _16 => _16.databasePool, 'optionalAccess', _17 => _17.max]), () => ( 10));
|
|
1028
931
|
const boss = config.tasks && config.tasks.backend === "pg-boss" && !config.tasks.connectionString ? 10 : 0;
|
|
1029
932
|
const breakdown = `${poolWorkers} worker(s) \xD7 (pool ${max}${boss ? ` + pg-boss ${boss}` : ""})`;
|
|
1030
|
-
await
|
|
933
|
+
await _chunkJP36TLL4cjs.checkConnectionBudget.call(void 0, poolWorkers * (max + boss), breakdown);
|
|
1031
934
|
}
|
|
1032
935
|
}
|
|
1033
936
|
if (config.cache) {
|
|
1034
|
-
await
|
|
937
|
+
await _chunkY4NKIXULcjs.configureCache.call(void 0, config.cache);
|
|
1035
938
|
}
|
|
1036
939
|
if (jwtSecret) {
|
|
1037
|
-
|
|
940
|
+
_chunkY4NKIXULcjs.configureAuth.call(void 0, {
|
|
1038
941
|
secret: jwtSecret,
|
|
1039
942
|
strategy: authStrategy,
|
|
1040
943
|
expiresIn: _nullishCoalesce(config.jwtExpiresIn, () => ( "7d")),
|
|
@@ -1046,7 +949,7 @@ async function ignite(config) {
|
|
|
1046
949
|
}
|
|
1047
950
|
if (config.tasks) {
|
|
1048
951
|
if (config.tasks.backend === "bullmq") {
|
|
1049
|
-
await
|
|
952
|
+
await _chunkTBIVIR6Lcjs.initBullMQ.call(void 0, {
|
|
1050
953
|
redisUrl: _nullishCoalesce(config.tasks.redisUrl, () => ( "redis://localhost:6379")),
|
|
1051
954
|
concurrency: _nullishCoalesce(config.tasks.concurrency, () => ( 5)),
|
|
1052
955
|
enqueueTimeout: _nullishCoalesce(config.tasks.enqueueTimeout, () => ( 5e3)),
|
|
@@ -1059,7 +962,7 @@ async function ignite(config) {
|
|
|
1059
962
|
'[EFC] tasks.backend "pg-boss" needs tasks.connectionString or databaseUrl'
|
|
1060
963
|
);
|
|
1061
964
|
}
|
|
1062
|
-
await
|
|
965
|
+
await _chunk7BC3AN7Rcjs.initPgBoss.call(void 0, {
|
|
1063
966
|
connectionString,
|
|
1064
967
|
concurrency: _nullishCoalesce(config.tasks.concurrency, () => ( 5)),
|
|
1065
968
|
enqueueTimeout: _nullishCoalesce(config.tasks.enqueueTimeout, () => ( 5e3)),
|
|
@@ -1068,9 +971,9 @@ async function ignite(config) {
|
|
|
1068
971
|
});
|
|
1069
972
|
}
|
|
1070
973
|
}
|
|
1071
|
-
const routes =
|
|
974
|
+
const routes = _chunk4GHK27JAcjs.scanDir.call(void 0, apiDir);
|
|
1072
975
|
const apiRouter = _express2.default.Router();
|
|
1073
|
-
const mounted = await mountRoutes(apiRouter, routes);
|
|
976
|
+
const mounted = await _chunk74BSJXWDcjs.mountRoutes.call(void 0, apiRouter, routes);
|
|
1074
977
|
app.use(basePath, apiRouter);
|
|
1075
978
|
if (config.dashboard !== false && process.env["NODE_ENV"] === "development") {
|
|
1076
979
|
app.get("/", (_req, res) => {
|
|
@@ -1079,39 +982,13 @@ async function ignite(config) {
|
|
|
1079
982
|
res.send(generateDashboard(mounted, basePath, port, name, version));
|
|
1080
983
|
});
|
|
1081
984
|
}
|
|
1082
|
-
|
|
1083
|
-
app.use(onError);
|
|
1084
|
-
} else {
|
|
1085
|
-
app.use(
|
|
1086
|
-
(err, _req, res, _next) => {
|
|
1087
|
-
if (res.headersSent) {
|
|
1088
|
-
_chunkDUADUR6Rcjs.getLogger.call(void 0, ).warn({ err }, "Error after the response was sent");
|
|
1089
|
-
return;
|
|
1090
|
-
}
|
|
1091
|
-
const status = _optionalChain([err, 'optionalAccess', _18 => _18.statusCode]);
|
|
1092
|
-
const duckTyped = err instanceof Error && typeof status === "number" && status >= 400 && status < 500 ? err : null;
|
|
1093
|
-
if (_chunkTYCYYLLMcjs.isHttpError.call(void 0, err)) {
|
|
1094
|
-
const issues = err.issues;
|
|
1095
|
-
res.status(err.statusCode).json({
|
|
1096
|
-
error: err.message,
|
|
1097
|
-
statusCode: err.statusCode,
|
|
1098
|
-
...issues !== void 0 && { issues }
|
|
1099
|
-
});
|
|
1100
|
-
} else if (duckTyped) {
|
|
1101
|
-
res.status(duckTyped.statusCode).json({ error: duckTyped.message, statusCode: duckTyped.statusCode });
|
|
1102
|
-
} else {
|
|
1103
|
-
_chunkDUADUR6Rcjs.getLogger.call(void 0, ).error({ err }, "Unhandled error");
|
|
1104
|
-
res.status(500).json({ error: "Internal Server Error", statusCode: 500 });
|
|
1105
|
-
}
|
|
1106
|
-
}
|
|
1107
|
-
);
|
|
1108
|
-
}
|
|
985
|
+
_chunk74BSJXWDcjs.mountErrorHandler.call(void 0, app, onError);
|
|
1109
986
|
return new Promise((resolve, reject) => {
|
|
1110
987
|
const server = app.listen(port);
|
|
1111
988
|
server.once("listening", () => {
|
|
1112
|
-
const wid = _nullishCoalesce(_optionalChain([_cluster2.default, 'access',
|
|
989
|
+
const wid = _nullishCoalesce(_optionalChain([_cluster2.default, 'access', _18 => _18.worker, 'optionalAccess', _19 => _19.id]), () => ( "primary"));
|
|
1113
990
|
const addr = server.address();
|
|
1114
|
-
|
|
991
|
+
_chunkJP36TLL4cjs.getLogger.call(void 0, ).info(`Worker ${wid} listening on :${_nullishCoalesce(_optionalChain([addr, 'optionalAccess', _20 => _20.port]), () => ( port))}`);
|
|
1115
992
|
resolve(server);
|
|
1116
993
|
});
|
|
1117
994
|
server.once("error", reject);
|
|
@@ -1122,21 +999,21 @@ function gracefulShutdown(server, timeoutMs = 1e4) {
|
|
|
1122
999
|
const shutdown = (signal) => {
|
|
1123
1000
|
if (shuttingDown) return;
|
|
1124
1001
|
shuttingDown = true;
|
|
1125
|
-
|
|
1002
|
+
_chunkJP36TLL4cjs.getLogger.call(void 0, ).info(`${signal} received \u2014 closing server gracefully\u2026`);
|
|
1126
1003
|
if (server) {
|
|
1127
1004
|
server.closeIdleConnections();
|
|
1128
1005
|
server.close(() => {
|
|
1129
|
-
|
|
1130
|
-
Promise.all([
|
|
1006
|
+
_chunkJP36TLL4cjs.getLogger.call(void 0, ).info("Server closed");
|
|
1007
|
+
Promise.all([_chunkTBIVIR6Lcjs.closeBullMQ.call(void 0, ), _chunk7BC3AN7Rcjs.closePgBoss.call(void 0, ), _chunkY4NKIXULcjs.closeCache.call(void 0, )]).catch((err) => _chunkJP36TLL4cjs.getLogger.call(void 0, ).error({ err }, "Task backend close failed")).finally(() => process.exit(0));
|
|
1131
1008
|
});
|
|
1132
1009
|
setTimeout(() => {
|
|
1133
|
-
|
|
1010
|
+
_chunkJP36TLL4cjs.getLogger.call(void 0, ).error("Forced exit after timeout");
|
|
1134
1011
|
process.exit(1);
|
|
1135
1012
|
}, timeoutMs).unref();
|
|
1136
1013
|
} else {
|
|
1137
1014
|
shutdownMaster();
|
|
1138
1015
|
setTimeout(() => {
|
|
1139
|
-
|
|
1016
|
+
_chunkJP36TLL4cjs.getLogger.call(void 0, ).error("Workers did not exit in time \u2014 forcing primary exit");
|
|
1140
1017
|
process.exit(1);
|
|
1141
1018
|
}, timeoutMs + 2e3).unref();
|
|
1142
1019
|
}
|
|
@@ -1165,5 +1042,8 @@ function gracefulShutdown(server, timeoutMs = 1e4) {
|
|
|
1165
1042
|
|
|
1166
1043
|
|
|
1167
1044
|
|
|
1168
|
-
|
|
1045
|
+
|
|
1046
|
+
|
|
1047
|
+
|
|
1048
|
+
exports.HttpError = _chunkAGOYTFROcjs.HttpError; exports.ModelValidationError = _chunkIUZ6A7PBcjs.ModelValidationError; exports.cache = _chunkY4NKIXULcjs.cache; exports.cacheResponse = cacheResponse; exports.compose = compose; exports.db = _chunkR2K7AFIBcjs.db; exports.defineCollection = _chunkR2K7AFIBcjs.defineCollection; exports.defineModel = _chunkR2K7AFIBcjs.defineModel; exports.defineTable = _chunkR2K7AFIBcjs.defineTable; exports.getDbClient = _chunkR2K7AFIBcjs.getDbClient; exports.getLogger = _chunkJP36TLL4cjs.getLogger; exports.getQueryMetrics = _chunkJP36TLL4cjs.getQueryMetrics; exports.gracefulShutdown = gracefulShutdown; exports.ignite = ignite; exports.isHttpError = _chunkAGOYTFROcjs.isHttpError; exports.listTasks = _chunkH2PVWCWCcjs.listTasks; exports.logger = _chunkJP36TLL4cjs.logger; exports.rateLimit = rateLimit; exports.resetQueryMetrics = _chunkJP36TLL4cjs.resetQueryMetrics; exports.scanDir = _chunk4GHK27JAcjs.scanDir; exports.setDbClient = _chunkR2K7AFIBcjs.setDbClient; exports.transaction = _chunkR2K7AFIBcjs.transaction; exports.workerCount = workerCount;
|
|
1169
1049
|
//# sourceMappingURL=index.cjs.map
|