express-file-cluster 0.9.3 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (220) hide show
  1. package/dist/auth/index.cjs +6 -7
  2. package/dist/auth/index.cjs.map +1 -1
  3. package/dist/auth/index.d.cts +7 -2
  4. package/dist/auth/index.d.ts +7 -2
  5. package/dist/auth/index.js +5 -6
  6. package/dist/{chunk-QL6EWT4B.cjs → chunk-4DOHQU6I.cjs} +9 -7
  7. package/dist/chunk-4DOHQU6I.cjs.map +1 -0
  8. package/dist/chunk-73XJUT2S.js +366 -0
  9. package/dist/chunk-73XJUT2S.js.map +1 -0
  10. package/dist/{chunk-ATL4GYFU.js → chunk-7KC2H76D.js} +50 -8
  11. package/dist/chunk-7KC2H76D.js.map +1 -0
  12. package/dist/{chunk-TYR2GZZE.cjs → chunk-7KO4DJRJ.cjs} +19 -14
  13. package/dist/chunk-7KO4DJRJ.cjs.map +1 -0
  14. package/dist/{chunk-UBQYQPBU.js → chunk-ATVD2HGC.js} +4 -4
  15. package/dist/{chunk-R34R7QPD.cjs → chunk-DCJOWFVD.cjs} +3 -3
  16. package/dist/{chunk-R34R7QPD.cjs.map → chunk-DCJOWFVD.cjs.map} +1 -1
  17. package/dist/chunk-DUADUR6R.cjs +366 -0
  18. package/dist/chunk-DUADUR6R.cjs.map +1 -0
  19. package/dist/{chunk-BBSZLGZW.js → chunk-EGSSZUVO.js} +8 -6
  20. package/dist/chunk-EGSSZUVO.js.map +1 -0
  21. package/dist/{chunk-TI24L4XE.cjs → chunk-GBI77W5T.cjs} +6 -2
  22. package/dist/chunk-GBI77W5T.cjs.map +1 -0
  23. package/dist/{chunk-RTF7PHS2.cjs → chunk-HBCY7ILD.cjs} +306 -119
  24. package/dist/chunk-HBCY7ILD.cjs.map +1 -0
  25. package/dist/{chunk-ANUSWEAP.cjs → chunk-KFVFP2Q7.cjs} +59 -17
  26. package/dist/chunk-KFVFP2Q7.cjs.map +1 -0
  27. package/dist/{chunk-RS4MXCPW.js → chunk-NI2BNGGV.js} +2 -2
  28. package/dist/{chunk-X2US4RAM.cjs → chunk-NKLOE4AK.cjs} +11 -13
  29. package/dist/chunk-NKLOE4AK.cjs.map +1 -0
  30. package/dist/{chunk-RRQ2RK5M.js → chunk-PGJQK36V.js} +195 -8
  31. package/dist/chunk-PGJQK36V.js.map +1 -0
  32. package/dist/{chunk-QKQZF573.js → chunk-QDEDOHP7.js} +4 -6
  33. package/dist/chunk-QDEDOHP7.js.map +1 -0
  34. package/dist/{chunk-UTM4PEVG.js → chunk-R4XO4SVM.js} +10 -5
  35. package/dist/chunk-R4XO4SVM.js.map +1 -0
  36. package/dist/chunk-R52CUEGT.js +74 -0
  37. package/dist/chunk-R52CUEGT.js.map +1 -0
  38. package/dist/{chunk-HBYSKULC.js → chunk-RAB44UGX.js} +5 -1
  39. package/dist/chunk-RAB44UGX.js.map +1 -0
  40. package/dist/{chunk-7YEX4MQV.cjs → chunk-WBLUGOAG.cjs} +42 -6
  41. package/dist/chunk-WBLUGOAG.cjs.map +1 -0
  42. package/dist/{chunk-T4OHFU5T.cjs → chunk-YK4ZM3CA.cjs} +15 -15
  43. package/dist/{chunk-T4OHFU5T.cjs.map → chunk-YK4ZM3CA.cjs.map} +1 -1
  44. package/dist/cli/db-runner.cjs +2012 -120
  45. package/dist/cli/db-runner.cjs.map +1 -1
  46. package/dist/cli/db-runner.js +1989 -97
  47. package/dist/cli/db-runner.js.map +1 -1
  48. package/dist/cli/index.cjs +101 -43
  49. package/dist/cli/index.cjs.map +1 -1
  50. package/dist/cli/index.js +80 -22
  51. package/dist/cli/index.js.map +1 -1
  52. package/dist/docs/api-reference/auth.md +10 -8
  53. package/dist/docs/api-reference/collection.md +44 -1
  54. package/dist/docs/api-reference/ignite.md +22 -3
  55. package/dist/docs/api-reference/types.md +99 -0
  56. package/dist/docs/cli/add.md +1 -1
  57. package/dist/docs/cli/db.md +2 -2
  58. package/dist/docs/contributing/index.md +1 -1
  59. package/dist/docs/core-concepts/background-tasks.md +6 -3
  60. package/dist/docs/getting-started/index.md +3 -2
  61. package/dist/docs/guides/authentication.md +34 -24
  62. package/dist/docs/guides/caching.md +32 -1
  63. package/dist/docs/guides/database.md +14 -0
  64. package/dist/docs/guides/feature-matrix.md +58 -0
  65. package/dist/docs/guides/migrations.md +23 -2
  66. package/dist/docs/guides/oauth.md +15 -1
  67. package/dist/docs/guides/which-api.md +2 -2
  68. package/dist/docs/index.md +4 -1
  69. package/dist/docs/skills/SKILL.md +2 -2
  70. package/dist/docs/skills/api-surface.md +10 -4
  71. package/dist/docs/skills/auth-internals.md +3 -3
  72. package/dist/docs/skills/tasks-internals.md +4 -3
  73. package/dist/docs/skills/what-not-to-invent.md +4 -3
  74. package/dist/docs/versioning.md +42 -0
  75. package/dist/index.cjs +144 -51
  76. package/dist/index.cjs.map +1 -1
  77. package/dist/index.d.cts +204 -3
  78. package/dist/index.d.ts +204 -3
  79. package/dist/index.js +107 -14
  80. package/dist/index.js.map +1 -1
  81. package/dist/pgboss-backend-FW42SBSM.js +14 -0
  82. package/dist/pgboss-backend-RVHUBJTU.cjs +14 -0
  83. package/dist/{pgboss-backend-TCHI7CHM.cjs.map → pgboss-backend-RVHUBJTU.cjs.map} +1 -1
  84. package/dist/registry/index.json +34 -3
  85. package/dist/registry/js-mongo/account-security.json +1 -1
  86. package/dist/registry/js-mongo/admin-users.json +1 -1
  87. package/dist/registry/js-mongo/auth.json +1 -1
  88. package/dist/registry/js-mongo/auth@apple.json +1 -1
  89. package/dist/registry/js-mongo/auth@google.json +1 -1
  90. package/dist/registry/js-mongo/email-verification.json +1 -1
  91. package/dist/registry/js-mongo/forgot-password.json +1 -1
  92. package/dist/registry/js-mongo/user-profile.json +1 -1
  93. package/dist/registry/js-mongo-collection/_base.json +1 -0
  94. package/dist/registry/js-mongo-collection/account-security.json +1 -0
  95. package/dist/registry/js-mongo-collection/account-settings.json +1 -0
  96. package/dist/registry/js-mongo-collection/admin-admins.json +1 -0
  97. package/dist/registry/js-mongo-collection/admin-analytics.json +1 -0
  98. package/dist/registry/js-mongo-collection/admin-billing.json +1 -0
  99. package/dist/registry/js-mongo-collection/admin-content.json +1 -0
  100. package/dist/registry/js-mongo-collection/admin-logs.json +1 -0
  101. package/dist/registry/js-mongo-collection/admin-support.json +1 -0
  102. package/dist/registry/js-mongo-collection/admin-system.json +1 -0
  103. package/dist/registry/js-mongo-collection/admin-users.json +1 -0
  104. package/dist/registry/js-mongo-collection/admin.json +1 -0
  105. package/dist/registry/js-mongo-collection/auth.json +1 -0
  106. package/dist/registry/js-mongo-collection/auth@apple.json +1 -0
  107. package/dist/registry/js-mongo-collection/auth@google.json +1 -0
  108. package/dist/registry/js-mongo-collection/billing.json +1 -0
  109. package/dist/registry/js-mongo-collection/email-client.json +1 -0
  110. package/dist/registry/js-mongo-collection/email-verification.json +1 -0
  111. package/dist/registry/js-mongo-collection/files.json +1 -0
  112. package/dist/registry/js-mongo-collection/forgot-password.json +1 -0
  113. package/dist/registry/js-mongo-collection/notifications.json +1 -0
  114. package/dist/registry/js-mongo-collection/support.json +1 -0
  115. package/dist/registry/js-mongo-collection/user-profile.json +1 -0
  116. package/dist/registry/js-pg-model/account-security.json +1 -1
  117. package/dist/registry/js-pg-model/admin-users.json +1 -1
  118. package/dist/registry/js-pg-model/auth.json +1 -1
  119. package/dist/registry/js-pg-model/auth@apple.json +1 -1
  120. package/dist/registry/js-pg-model/auth@google.json +1 -1
  121. package/dist/registry/js-pg-model/email-verification.json +1 -1
  122. package/dist/registry/js-pg-model/forgot-password.json +1 -1
  123. package/dist/registry/js-pg-model/user-profile.json +1 -1
  124. package/dist/registry/js-pg-table/account-security.json +1 -1
  125. package/dist/registry/js-pg-table/admin-users.json +1 -1
  126. package/dist/registry/js-pg-table/auth.json +1 -1
  127. package/dist/registry/js-pg-table/auth@apple.json +1 -1
  128. package/dist/registry/js-pg-table/auth@google.json +1 -1
  129. package/dist/registry/js-pg-table/email-verification.json +1 -1
  130. package/dist/registry/js-pg-table/forgot-password.json +1 -1
  131. package/dist/registry/js-pg-table/user-profile.json +1 -1
  132. package/dist/registry/ts-mongo/account-security.json +1 -1
  133. package/dist/registry/ts-mongo/admin-users.json +1 -1
  134. package/dist/registry/ts-mongo/auth.json +1 -1
  135. package/dist/registry/ts-mongo/auth@apple.json +1 -1
  136. package/dist/registry/ts-mongo/auth@google.json +1 -1
  137. package/dist/registry/ts-mongo/email-verification.json +1 -1
  138. package/dist/registry/ts-mongo/forgot-password.json +1 -1
  139. package/dist/registry/ts-mongo/user-profile.json +1 -1
  140. package/dist/registry/ts-mongo-collection/_base.json +1 -0
  141. package/dist/registry/ts-mongo-collection/account-security.json +1 -0
  142. package/dist/registry/ts-mongo-collection/account-settings.json +1 -0
  143. package/dist/registry/ts-mongo-collection/admin-admins.json +1 -0
  144. package/dist/registry/ts-mongo-collection/admin-analytics.json +1 -0
  145. package/dist/registry/ts-mongo-collection/admin-billing.json +1 -0
  146. package/dist/registry/ts-mongo-collection/admin-content.json +1 -0
  147. package/dist/registry/ts-mongo-collection/admin-logs.json +1 -0
  148. package/dist/registry/ts-mongo-collection/admin-support.json +1 -0
  149. package/dist/registry/ts-mongo-collection/admin-system.json +1 -0
  150. package/dist/registry/ts-mongo-collection/admin-users.json +1 -0
  151. package/dist/registry/ts-mongo-collection/admin.json +1 -0
  152. package/dist/registry/ts-mongo-collection/auth.json +1 -0
  153. package/dist/registry/ts-mongo-collection/auth@apple.json +1 -0
  154. package/dist/registry/ts-mongo-collection/auth@google.json +1 -0
  155. package/dist/registry/ts-mongo-collection/billing.json +1 -0
  156. package/dist/registry/ts-mongo-collection/email-client.json +1 -0
  157. package/dist/registry/ts-mongo-collection/email-verification.json +1 -0
  158. package/dist/registry/ts-mongo-collection/files.json +1 -0
  159. package/dist/registry/ts-mongo-collection/forgot-password.json +1 -0
  160. package/dist/registry/ts-mongo-collection/notifications.json +1 -0
  161. package/dist/registry/ts-mongo-collection/support.json +1 -0
  162. package/dist/registry/ts-mongo-collection/user-profile.json +1 -0
  163. package/dist/registry/ts-pg-model/account-security.json +1 -1
  164. package/dist/registry/ts-pg-model/admin-users.json +1 -1
  165. package/dist/registry/ts-pg-model/auth.json +1 -1
  166. package/dist/registry/ts-pg-model/auth@apple.json +1 -1
  167. package/dist/registry/ts-pg-model/auth@google.json +1 -1
  168. package/dist/registry/ts-pg-model/email-verification.json +1 -1
  169. package/dist/registry/ts-pg-model/forgot-password.json +1 -1
  170. package/dist/registry/ts-pg-model/user-profile.json +1 -1
  171. package/dist/registry/ts-pg-table/account-security.json +1 -1
  172. package/dist/registry/ts-pg-table/admin-users.json +1 -1
  173. package/dist/registry/ts-pg-table/auth.json +1 -1
  174. package/dist/registry/ts-pg-table/auth@apple.json +1 -1
  175. package/dist/registry/ts-pg-table/auth@google.json +1 -1
  176. package/dist/registry/ts-pg-table/email-verification.json +1 -1
  177. package/dist/registry/ts-pg-table/forgot-password.json +1 -1
  178. package/dist/registry/ts-pg-table/user-profile.json +1 -1
  179. package/dist/tasks/index.cjs +4 -2
  180. package/dist/tasks/index.cjs.map +1 -1
  181. package/dist/tasks/index.d.cts +4 -2
  182. package/dist/tasks/index.d.ts +4 -2
  183. package/dist/tasks/index.js +3 -1
  184. package/dist/thread-runner.cjs +8 -0
  185. package/dist/thread-runner.cjs.map +1 -0
  186. package/dist/thread-runner.d.cts +3 -0
  187. package/dist/thread-runner.d.ts +3 -0
  188. package/dist/thread-runner.js +8 -0
  189. package/dist/thread-runner.js.map +1 -0
  190. package/dist/{types-BY-ObnZH.d.ts → types-Bnxvj3l0.d.cts} +14 -2
  191. package/dist/{types-BY-ObnZH.d.cts → types-Bnxvj3l0.d.ts} +14 -2
  192. package/package.json +1 -1
  193. package/dist/chunk-277BSYVH.js +0 -127
  194. package/dist/chunk-277BSYVH.js.map +0 -1
  195. package/dist/chunk-7YEX4MQV.cjs.map +0 -1
  196. package/dist/chunk-ANUSWEAP.cjs.map +0 -1
  197. package/dist/chunk-ATL4GYFU.js.map +0 -1
  198. package/dist/chunk-BBSZLGZW.js.map +0 -1
  199. package/dist/chunk-HBYSKULC.js.map +0 -1
  200. package/dist/chunk-HXV543HZ.js +0 -177
  201. package/dist/chunk-HXV543HZ.js.map +0 -1
  202. package/dist/chunk-LJNSJFOL.js +0 -38
  203. package/dist/chunk-LJNSJFOL.js.map +0 -1
  204. package/dist/chunk-QKQZF573.js.map +0 -1
  205. package/dist/chunk-QL6EWT4B.cjs.map +0 -1
  206. package/dist/chunk-RRQ2RK5M.js.map +0 -1
  207. package/dist/chunk-RTF7PHS2.cjs.map +0 -1
  208. package/dist/chunk-TI24L4XE.cjs.map +0 -1
  209. package/dist/chunk-TYR2GZZE.cjs.map +0 -1
  210. package/dist/chunk-UTM4PEVG.js.map +0 -1
  211. package/dist/chunk-VQSWSYK6.cjs +0 -177
  212. package/dist/chunk-VQSWSYK6.cjs.map +0 -1
  213. package/dist/chunk-X2US4RAM.cjs.map +0 -1
  214. package/dist/chunk-YL37D6KM.cjs +0 -127
  215. package/dist/chunk-YL37D6KM.cjs.map +0 -1
  216. package/dist/pgboss-backend-QKBXVJ6B.js +0 -14
  217. package/dist/pgboss-backend-TCHI7CHM.cjs +0 -14
  218. /package/dist/{chunk-UBQYQPBU.js.map → chunk-ATVD2HGC.js.map} +0 -0
  219. /package/dist/{chunk-RS4MXCPW.js.map → chunk-NI2BNGGV.js.map} +0 -0
  220. /package/dist/{pgboss-backend-QKBXVJ6B.js.map → pgboss-backend-FW42SBSM.js.map} +0 -0
package/dist/index.cjs CHANGED
@@ -4,16 +4,16 @@
4
4
 
5
5
 
6
6
 
7
- var _chunkANUSWEAPcjs = require('./chunk-ANUSWEAP.cjs');
8
7
 
9
8
 
10
- var _chunkR34R7QPDcjs = require('./chunk-R34R7QPD.cjs');
9
+ var _chunkKFVFP2Q7cjs = require('./chunk-KFVFP2Q7.cjs');
11
10
 
12
11
 
12
+ var _chunkDCJOWFVDcjs = require('./chunk-DCJOWFVD.cjs');
13
13
 
14
- var _chunkT4OHFU5Tcjs = require('./chunk-T4OHFU5T.cjs');
15
14
 
16
15
 
16
+ var _chunkYK4ZM3CAcjs = require('./chunk-YK4ZM3CA.cjs');
17
17
 
18
18
 
19
19
 
@@ -21,27 +21,26 @@ var _chunkT4OHFU5Tcjs = require('./chunk-T4OHFU5T.cjs');
21
21
 
22
22
 
23
23
 
24
- var _chunkRTF7PHS2cjs = require('./chunk-RTF7PHS2.cjs');
25
24
 
26
25
 
26
+ var _chunkHBCY7ILDcjs = require('./chunk-HBCY7ILD.cjs');
27
27
 
28
28
 
29
29
 
30
30
 
31
- var _chunkX2US4RAMcjs = require('./chunk-X2US4RAM.cjs');
32
31
 
33
32
 
33
+ var _chunkNKLOE4AKcjs = require('./chunk-NKLOE4AK.cjs');
34
34
 
35
- var _chunkVQSWSYK6cjs = require('./chunk-VQSWSYK6.cjs');
36
35
 
37
36
 
37
+ var _chunk7KO4DJRJcjs = require('./chunk-7KO4DJRJ.cjs');
38
+ require('./chunk-WBLUGOAG.cjs');
38
39
 
39
- var _chunkTYR2GZZEcjs = require('./chunk-TYR2GZZE.cjs');
40
- require('./chunk-7YEX4MQV.cjs');
41
40
 
42
41
 
42
+ var _chunkGBI77W5Tcjs = require('./chunk-GBI77W5T.cjs');
43
43
 
44
- var _chunkTI24L4XEcjs = require('./chunk-TI24L4XE.cjs');
45
44
 
46
45
 
47
46
 
@@ -49,7 +48,9 @@ var _chunkTI24L4XEcjs = require('./chunk-TI24L4XE.cjs');
49
48
 
50
49
 
51
50
 
52
- var _chunkYL37D6KMcjs = require('./chunk-YL37D6KM.cjs');
51
+
52
+
53
+ var _chunkDUADUR6Rcjs = require('./chunk-DUADUR6R.cjs');
53
54
 
54
55
  // src/index.ts
55
56
  var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
@@ -201,7 +202,7 @@ function workerCount() {
201
202
  }
202
203
  function shutdownMaster() {
203
204
  isShuttingDown = true;
204
- _chunkYL37D6KMcjs.getLogger.call(void 0, ).info(`Cluster primary (pid=${process.pid}) shutting down, waiting for workers\u2026`);
205
+ _chunkDUADUR6Rcjs.getLogger.call(void 0, ).info(`Cluster primary (pid=${process.pid}) shutting down, waiting for workers\u2026`);
205
206
  if (workerCount() === 0) process.exit(0);
206
207
  for (const worker of Object.values(_nullishCoalesce(_cluster2.default.workers, () => ( {})))) {
207
208
  _optionalChain([worker, 'optionalAccess', _3 => _3.process, 'access', _4 => _4.kill, 'call', _5 => _5("SIGTERM")]);
@@ -209,7 +210,7 @@ function shutdownMaster() {
209
210
  }
210
211
  function runMaster(options = {}) {
211
212
  const count = _nullishCoalesce(options.workers, () => ( 1));
212
- _chunkYL37D6KMcjs.getLogger.call(void 0, ).info(`Primary ${process.pid} starting ${count} workers`);
213
+ _chunkDUADUR6Rcjs.getLogger.call(void 0, ).info(`Primary ${process.pid} starting ${count} workers`);
213
214
  for (let i = 0; i < count; i++) {
214
215
  _cluster2.default.fork();
215
216
  }
@@ -219,14 +220,14 @@ function runMaster(options = {}) {
219
220
  _cluster2.default.on("exit", (worker, code, signal) => {
220
221
  const exitCode = _nullishCoalesce(code, () => ( (signal ? -1 : 0)));
221
222
  if (isShuttingDown) {
222
- _chunkYL37D6KMcjs.getLogger.call(void 0, ).info(`Worker ${worker.id} gracefully exited`);
223
+ _chunkDUADUR6Rcjs.getLogger.call(void 0, ).info(`Worker ${worker.id} gracefully exited`);
223
224
  if (workerCount() === 0) {
224
- _chunkYL37D6KMcjs.getLogger.call(void 0, ).info("All workers exited. Primary exiting.");
225
+ _chunkDUADUR6Rcjs.getLogger.call(void 0, ).info("All workers exited. Primary exiting.");
225
226
  process.exit(0);
226
227
  }
227
228
  return;
228
229
  }
229
- _chunkYL37D6KMcjs.getLogger.call(void 0, ).warn(`Worker ${worker.id} exited (code=${exitCode}), respawning\u2026`);
230
+ _chunkDUADUR6Rcjs.getLogger.call(void 0, ).warn(`Worker ${worker.id} exited (code=${exitCode}), respawning\u2026`);
230
231
  _optionalChain([options, 'access', _8 => _8.onWorkerCrash, 'optionalCall', _9 => _9(worker.id, exitCode)]);
231
232
  _cluster2.default.fork();
232
233
  });
@@ -245,13 +246,13 @@ async function scanTasks(tasksDir) {
245
246
  const mod = await Promise.resolve().then(() => _interopRequireWildcard(require(filePath)));
246
247
  const def = mod["default"];
247
248
  if (!def || typeof def.handler !== "function") {
248
- _chunkYL37D6KMcjs.getLogger.call(void 0, ).warn(`Task file ${file} has no valid default export \u2014 skipping`);
249
+ _chunkDUADUR6Rcjs.getLogger.call(void 0, ).warn(`Task file ${file} has no valid default export \u2014 skipping`);
249
250
  continue;
250
251
  }
251
- _chunkTI24L4XEcjs.registerTask.call(void 0, taskName, { ...def, filePath });
252
- _chunkYL37D6KMcjs.getLogger.call(void 0, ).debug(`Registered task: ${taskName}`);
252
+ _chunkGBI77W5Tcjs.registerTask.call(void 0, taskName, { ...def, filePath });
253
+ _chunkDUADUR6Rcjs.getLogger.call(void 0, ).debug(`Registered task: ${taskName}`);
253
254
  } catch (err) {
254
- _chunkYL37D6KMcjs.getLogger.call(void 0, ).warn({ err }, `Failed to load task ${file}`);
255
+ _chunkDUADUR6Rcjs.getLogger.call(void 0, ).warn({ err }, `Failed to load task ${file}`);
255
256
  }
256
257
  }
257
258
  }
@@ -854,6 +855,71 @@ function generateDashboard(routes, basePath, port, projectName, projectVersion)
854
855
  </html>`;
855
856
  }
856
857
 
858
+ // src/rate-limit.ts
859
+ var UNITS = { s: 1, m: 60, h: 3600, d: 86400 };
860
+ function parseWindow(window) {
861
+ if (typeof window === "number") {
862
+ if (window > 0) return window;
863
+ } else {
864
+ const m = /^(\d+(?:\.\d+)?)\s*(s|m|h|d)$/.exec(window.trim());
865
+ if (m) return Number(m[1]) * UNITS[m[2]];
866
+ }
867
+ throw new Error(`[EFC] rateLimit: window must be seconds or like '15m' \u2014 got ${String(window)}`);
868
+ }
869
+ var lastCacheError = 0;
870
+ function rateLimit(options) {
871
+ const windowSeconds = parseWindow(options.window);
872
+ if (!Number.isInteger(options.max) || options.max < 1) {
873
+ throw new Error("[EFC] rateLimit: max must be a positive integer");
874
+ }
875
+ const keyOf = _nullishCoalesce(options.key, () => ( ((req) => _nullishCoalesce(req.ip, () => ( req.socket.remoteAddress)))));
876
+ const message = _nullishCoalesce(options.message, () => ( "Too many requests, try again later"));
877
+ const headers = _nullishCoalesce(options.headers, () => ( true));
878
+ return (req, res, next) => {
879
+ void (async () => {
880
+ const who = keyOf(req);
881
+ if (who === void 0) return next();
882
+ if (!_chunkKFVFP2Q7cjs.isCacheConfigured.call(void 0, )) {
883
+ throw new Error("[EFC] rateLimit needs a cache \u2014 pass cache: { backend } to ignite()");
884
+ }
885
+ const bucket = _nullishCoalesce(options.name, () => ( req.baseUrl + (_nullishCoalesce(_optionalChain([req, 'access', _10 => _10.route, 'optionalAccess', _11 => _11.path]), () => ( req.path)))));
886
+ const windowMs = windowSeconds * 1e3;
887
+ const now = Date.now();
888
+ const slot = Math.floor(now / windowMs);
889
+ const resetMs = (slot + 1) * windowMs - now;
890
+ let count;
891
+ try {
892
+ count = (await _chunkKFVFP2Q7cjs.rawIncr.call(void 0, `rl:${bucket}:${who}:${slot}`, Math.ceil(resetMs / 1e3) + 1)).value;
893
+ } catch (err) {
894
+ if (Date.now() - lastCacheError > 3e4) {
895
+ lastCacheError = Date.now();
896
+ _chunkDUADUR6Rcjs.getLogger.call(void 0, ).error(
897
+ { err },
898
+ `rateLimit: cache unavailable \u2014 ${options.onCacheError === "reject" ? "rejecting with 503" : "allowing requests"}`
899
+ );
900
+ }
901
+ if (options.onCacheError === "reject") {
902
+ res.status(503).json({ error: "Service Unavailable", statusCode: 503 });
903
+ return;
904
+ }
905
+ return next();
906
+ }
907
+ const resetSeconds = Math.max(1, Math.ceil(resetMs / 1e3));
908
+ if (headers) {
909
+ res.setHeader("RateLimit-Limit", String(options.max));
910
+ res.setHeader("RateLimit-Remaining", String(Math.max(0, options.max - count)));
911
+ res.setHeader("RateLimit-Reset", String(resetSeconds));
912
+ }
913
+ if (count > options.max) {
914
+ if (headers) res.setHeader("Retry-After", String(resetSeconds));
915
+ res.status(429).json({ error: message, statusCode: 429 });
916
+ return;
917
+ }
918
+ next();
919
+ })().catch(next);
920
+ };
921
+ }
922
+
857
923
  // src/cache/response.ts
858
924
  var RESPONSE_PREFIX = "res:";
859
925
  function cacheResponse(options) {
@@ -862,14 +928,14 @@ function cacheResponse(options) {
862
928
  if (req.method !== "GET" && req.method !== "HEAD") return next();
863
929
  let scope = "";
864
930
  if (opts.perUser) {
865
- const user = _chunkYL37D6KMcjs.getCurrentUser.call(void 0, );
866
- const id = _nullishCoalesce(_optionalChain([user, 'optionalAccess', _10 => _10["sub"]]), () => ( _optionalChain([user, 'optionalAccess', _11 => _11["id"]])));
931
+ const user = _chunkDUADUR6Rcjs.getCurrentUser.call(void 0, );
932
+ const id = _nullishCoalesce(_optionalChain([user, 'optionalAccess', _12 => _12["sub"]]), () => ( _optionalChain([user, 'optionalAccess', _13 => _13["id"]])));
867
933
  if (id === void 0) return next();
868
934
  scope = `u:${String(id)}:`;
869
935
  }
870
936
  const key = RESPONSE_PREFIX + scope + (opts.key ? opts.key(req) : req.originalUrl);
871
937
  void (async () => {
872
- const hit = await _chunkANUSWEAPcjs.cache.get(key);
938
+ const hit = await _chunkKFVFP2Q7cjs.cache.get(key);
873
939
  if (hit) {
874
940
  res.setHeader("X-Cache", "HIT");
875
941
  res.status(hit.status).json(hit.body);
@@ -878,7 +944,7 @@ function cacheResponse(options) {
878
944
  res.setHeader("X-Cache", "MISS");
879
945
  const json = res.json.bind(res);
880
946
  res.json = (body) => {
881
- if (res.statusCode === 200) void _chunkANUSWEAPcjs.cache.set(key, { status: 200, body }, { ttl: opts.ttl });
947
+ if (res.statusCode === 200) void _chunkKFVFP2Q7cjs.cache.set(key, { status: 200, body }, { ttl: opts.ttl });
882
948
  return json(body);
883
949
  };
884
950
  next();
@@ -952,11 +1018,21 @@ async function ignite(config) {
952
1018
  const jwtSecret = config.jwtSecret;
953
1019
  const authStrategy = _nullishCoalesce(config.authStrategy, () => ( "http-only"));
954
1020
  const clusterEnabled = _nullishCoalesce(config.cluster, () => ( process.env["NODE_ENV"] === "production"));
955
- _chunkYL37D6KMcjs.configureLogger.call(void 0, config.logging);
956
- _chunkVQSWSYK6cjs.configureQueryLog.call(void 0, config.logging);
1021
+ _chunkDUADUR6Rcjs.configureLogger.call(void 0, config.logging);
1022
+ if (!["http-only", "bearer", "localStorage"].includes(authStrategy) && (!clusterEnabled || _cluster2.default.isPrimary)) {
1023
+ _chunkDUADUR6Rcjs.getLogger.call(void 0, ).warn(
1024
+ `[EFC] Unknown authStrategy "${String(authStrategy)}" \u2014 treated as 'bearer'. Use 'http-only' or 'bearer'; this will be an error in 1.0.`
1025
+ );
1026
+ }
1027
+ if (jwtSecret && Buffer.byteLength(jwtSecret) < 32 && process.env["NODE_ENV"] === "production" && (!clusterEnabled || _cluster2.default.isPrimary)) {
1028
+ _chunkDUADUR6Rcjs.getLogger.call(void 0, ).warn(
1029
+ `[EFC] jwtSecret is ${Buffer.byteLength(jwtSecret)} bytes \u2014 use at least 32 random bytes in production (openssl rand -hex 64).`
1030
+ );
1031
+ }
1032
+ _chunkDUADUR6Rcjs.configureQueryLog.call(void 0, config.logging);
957
1033
  if (clusterEnabled && _cluster2.default.isPrimary) {
958
1034
  if (config.cache && config.cache.backend === "memory") {
959
- _chunkANUSWEAPcjs.servePrimaryCache.call(void 0, _nullishCoalesce(config.cache.maxEntries, () => ( 1e4)));
1035
+ _chunkKFVFP2Q7cjs.servePrimaryCache.call(void 0, _nullishCoalesce(config.cache.maxEntries, () => ( 1e4)));
960
1036
  }
961
1037
  runMaster({
962
1038
  workers: _nullishCoalesce(workers, () => ( _os2.default.cpus().length)),
@@ -966,14 +1042,15 @@ async function ignite(config) {
966
1042
  return;
967
1043
  }
968
1044
  const app = _express2.default.call(void 0, );
1045
+ if (config.trustProxy !== void 0) app.set("trust proxy", config.trustProxy);
969
1046
  app.set(
970
1047
  "json replacer",
971
1048
  (_key, value) => typeof value === "bigint" ? value.toString() : value
972
1049
  );
973
1050
  app.use((_req, _res, next) => {
974
- _chunkYL37D6KMcjs.runWithContext.call(void 0, {}, next);
1051
+ _chunkDUADUR6Rcjs.runWithContext.call(void 0, {}, next);
975
1052
  });
976
- app.use(_chunkYL37D6KMcjs.requestLogger.call(void 0, ));
1053
+ app.use(_chunkDUADUR6Rcjs.requestLogger.call(void 0, ));
977
1054
  if (config.requestTimeout) {
978
1055
  const ms = config.requestTimeout;
979
1056
  app.use((_req, res, next) => {
@@ -998,20 +1075,34 @@ async function ignite(config) {
998
1075
  for (const mw of globalMiddlewares) {
999
1076
  app.use(mw);
1000
1077
  }
1001
- if (database) _chunkX2US4RAMcjs.setDbEngine.call(void 0, database);
1002
- _chunkX2US4RAMcjs.setAutoSync.call(void 0, _nullishCoalesce(config.autoSync, () => ( true)));
1078
+ if (database) _chunkNKLOE4AKcjs.setDbEngine.call(void 0, database);
1079
+ _chunkNKLOE4AKcjs.setAutoSync.call(void 0, _nullishCoalesce(config.autoSync, () => ( true)));
1080
+ const poolWorkers = clusterEnabled ? _nullishCoalesce(workers, () => ( _os2.default.cpus().length)) : 1;
1081
+ const reportsPools = !clusterEnabled || _optionalChain([_cluster2.default, 'access', _14 => _14.worker, 'optionalAccess', _15 => _15.id]) === 1;
1003
1082
  if (database === "mongodb" && databaseUrl) {
1004
- const conn = await _chunkRTF7PHS2cjs.connectMongo.call(void 0, databaseUrl, config.databasePool);
1005
- _chunkRTF7PHS2cjs.setDbClient.call(void 0, conn);
1083
+ const conn = await _chunkHBCY7ILDcjs.connectMongo.call(void 0, databaseUrl, config.databasePool);
1084
+ _chunkHBCY7ILDcjs.setDbClient.call(void 0, conn);
1085
+ if (reportsPools) {
1086
+ const max = _nullishCoalesce(_optionalChain([config, 'access', _16 => _16.databasePool, 'optionalAccess', _17 => _17.max]), () => ( 100));
1087
+ _chunkDUADUR6Rcjs.getLogger.call(void 0, ).info(
1088
+ `MongoDB connections: up to ${poolWorkers * max} from this machine (${poolWorkers} worker(s) \xD7 maxPoolSize ${max})`
1089
+ );
1090
+ }
1006
1091
  } else if (database === "postgresql" && databaseUrl) {
1007
- const pool = await _chunkVQSWSYK6cjs.connectPostgres.call(void 0, databaseUrl, config.databasePool);
1008
- _chunkRTF7PHS2cjs.setDbClient.call(void 0, pool);
1092
+ const pool = await _chunkDUADUR6Rcjs.connectPostgres.call(void 0, databaseUrl, config.databasePool);
1093
+ _chunkHBCY7ILDcjs.setDbClient.call(void 0, pool);
1094
+ if (reportsPools) {
1095
+ const max = _nullishCoalesce(_optionalChain([config, 'access', _18 => _18.databasePool, 'optionalAccess', _19 => _19.max]), () => ( 10));
1096
+ const boss = config.tasks && config.tasks.backend === "pg-boss" && !config.tasks.connectionString ? 10 : 0;
1097
+ const breakdown = `${poolWorkers} worker(s) \xD7 (pool ${max}${boss ? ` + pg-boss ${boss}` : ""})`;
1098
+ await _chunkDUADUR6Rcjs.checkConnectionBudget.call(void 0, poolWorkers * (max + boss), breakdown);
1099
+ }
1009
1100
  }
1010
1101
  if (config.cache) {
1011
- await _chunkANUSWEAPcjs.configureCache.call(void 0, config.cache);
1102
+ await _chunkKFVFP2Q7cjs.configureCache.call(void 0, config.cache);
1012
1103
  }
1013
1104
  if (jwtSecret) {
1014
- _chunkANUSWEAPcjs.configureAuth.call(void 0, {
1105
+ _chunkKFVFP2Q7cjs.configureAuth.call(void 0, {
1015
1106
  secret: jwtSecret,
1016
1107
  strategy: authStrategy,
1017
1108
  expiresIn: _nullishCoalesce(config.jwtExpiresIn, () => ( "7d")),
@@ -1023,7 +1114,7 @@ async function ignite(config) {
1023
1114
  }
1024
1115
  if (config.tasks) {
1025
1116
  if (config.tasks.backend === "bullmq") {
1026
- await _chunkT4OHFU5Tcjs.initBullMQ.call(void 0, {
1117
+ await _chunkYK4ZM3CAcjs.initBullMQ.call(void 0, {
1027
1118
  redisUrl: _nullishCoalesce(config.tasks.redisUrl, () => ( "redis://localhost:6379")),
1028
1119
  concurrency: _nullishCoalesce(config.tasks.concurrency, () => ( 5)),
1029
1120
  enqueueTimeout: _nullishCoalesce(config.tasks.enqueueTimeout, () => ( 5e3)),
@@ -1036,7 +1127,7 @@ async function ignite(config) {
1036
1127
  '[EFC] tasks.backend "pg-boss" needs tasks.connectionString or databaseUrl'
1037
1128
  );
1038
1129
  }
1039
- await _chunkTYR2GZZEcjs.initPgBoss.call(void 0, {
1130
+ await _chunk7KO4DJRJcjs.initPgBoss.call(void 0, {
1040
1131
  connectionString,
1041
1132
  concurrency: _nullishCoalesce(config.tasks.concurrency, () => ( 5)),
1042
1133
  enqueueTimeout: _nullishCoalesce(config.tasks.enqueueTimeout, () => ( 5e3)),
@@ -1045,7 +1136,7 @@ async function ignite(config) {
1045
1136
  });
1046
1137
  }
1047
1138
  }
1048
- const routes = _chunkR34R7QPDcjs.scanDir.call(void 0, apiDir);
1139
+ const routes = _chunkDCJOWFVDcjs.scanDir.call(void 0, apiDir);
1049
1140
  const apiRouter = _express2.default.Router();
1050
1141
  const mounted = await mountRoutes(apiRouter, routes);
1051
1142
  app.use(basePath, apiRouter);
@@ -1062,11 +1153,12 @@ async function ignite(config) {
1062
1153
  app.use(
1063
1154
  (err, _req, res, _next) => {
1064
1155
  if (res.headersSent) {
1065
- _chunkYL37D6KMcjs.getLogger.call(void 0, ).warn({ err }, "Error after the response was sent");
1156
+ _chunkDUADUR6Rcjs.getLogger.call(void 0, ).warn({ err }, "Error after the response was sent");
1066
1157
  return;
1067
1158
  }
1068
- const duckTyped = err instanceof Error && typeof err.statusCode === "number" ? err : null;
1069
- if (_chunkX2US4RAMcjs.isHttpError.call(void 0, err)) {
1159
+ const status = _optionalChain([err, 'optionalAccess', _20 => _20.statusCode]);
1160
+ const duckTyped = err instanceof Error && typeof status === "number" && status >= 400 && status < 500 ? err : null;
1161
+ if (_chunkNKLOE4AKcjs.isHttpError.call(void 0, err)) {
1070
1162
  const issues = err.issues;
1071
1163
  res.status(err.statusCode).json({
1072
1164
  error: err.message,
@@ -1076,7 +1168,7 @@ async function ignite(config) {
1076
1168
  } else if (duckTyped) {
1077
1169
  res.status(duckTyped.statusCode).json({ error: duckTyped.message, statusCode: duckTyped.statusCode });
1078
1170
  } else {
1079
- _chunkYL37D6KMcjs.getLogger.call(void 0, ).error({ err }, "Unhandled error");
1171
+ _chunkDUADUR6Rcjs.getLogger.call(void 0, ).error({ err }, "Unhandled error");
1080
1172
  res.status(500).json({ error: "Internal Server Error", statusCode: 500 });
1081
1173
  }
1082
1174
  }
@@ -1085,9 +1177,9 @@ async function ignite(config) {
1085
1177
  return new Promise((resolve, reject) => {
1086
1178
  const server = app.listen(port);
1087
1179
  server.once("listening", () => {
1088
- const wid = _nullishCoalesce(_optionalChain([_cluster2.default, 'access', _12 => _12.worker, 'optionalAccess', _13 => _13.id]), () => ( "primary"));
1180
+ const wid = _nullishCoalesce(_optionalChain([_cluster2.default, 'access', _21 => _21.worker, 'optionalAccess', _22 => _22.id]), () => ( "primary"));
1089
1181
  const addr = server.address();
1090
- _chunkYL37D6KMcjs.getLogger.call(void 0, ).info(`Worker ${wid} listening on :${_nullishCoalesce(_optionalChain([addr, 'optionalAccess', _14 => _14.port]), () => ( port))}`);
1182
+ _chunkDUADUR6Rcjs.getLogger.call(void 0, ).info(`Worker ${wid} listening on :${_nullishCoalesce(_optionalChain([addr, 'optionalAccess', _23 => _23.port]), () => ( port))}`);
1091
1183
  resolve(server);
1092
1184
  });
1093
1185
  server.once("error", reject);
@@ -1098,21 +1190,21 @@ function gracefulShutdown(server, timeoutMs = 1e4) {
1098
1190
  const shutdown = (signal) => {
1099
1191
  if (shuttingDown) return;
1100
1192
  shuttingDown = true;
1101
- _chunkYL37D6KMcjs.getLogger.call(void 0, ).info(`${signal} received \u2014 closing server gracefully\u2026`);
1193
+ _chunkDUADUR6Rcjs.getLogger.call(void 0, ).info(`${signal} received \u2014 closing server gracefully\u2026`);
1102
1194
  if (server) {
1103
1195
  server.closeIdleConnections();
1104
1196
  server.close(() => {
1105
- _chunkYL37D6KMcjs.getLogger.call(void 0, ).info("Server closed");
1106
- Promise.all([_chunkT4OHFU5Tcjs.closeBullMQ.call(void 0, ), _chunkTYR2GZZEcjs.closePgBoss.call(void 0, ), _chunkANUSWEAPcjs.closeCache.call(void 0, )]).catch((err) => _chunkYL37D6KMcjs.getLogger.call(void 0, ).error({ err }, "Task backend close failed")).finally(() => process.exit(0));
1197
+ _chunkDUADUR6Rcjs.getLogger.call(void 0, ).info("Server closed");
1198
+ Promise.all([_chunkYK4ZM3CAcjs.closeBullMQ.call(void 0, ), _chunk7KO4DJRJcjs.closePgBoss.call(void 0, ), _chunkKFVFP2Q7cjs.closeCache.call(void 0, )]).catch((err) => _chunkDUADUR6Rcjs.getLogger.call(void 0, ).error({ err }, "Task backend close failed")).finally(() => process.exit(0));
1107
1199
  });
1108
1200
  setTimeout(() => {
1109
- _chunkYL37D6KMcjs.getLogger.call(void 0, ).error("Forced exit after timeout");
1201
+ _chunkDUADUR6Rcjs.getLogger.call(void 0, ).error("Forced exit after timeout");
1110
1202
  process.exit(1);
1111
1203
  }, timeoutMs).unref();
1112
1204
  } else {
1113
1205
  shutdownMaster();
1114
1206
  setTimeout(() => {
1115
- _chunkYL37D6KMcjs.getLogger.call(void 0, ).error("Workers did not exit in time \u2014 forcing primary exit");
1207
+ _chunkDUADUR6Rcjs.getLogger.call(void 0, ).error("Workers did not exit in time \u2014 forcing primary exit");
1116
1208
  process.exit(1);
1117
1209
  }, timeoutMs + 2e3).unref();
1118
1210
  }
@@ -1141,5 +1233,6 @@ function gracefulShutdown(server, timeoutMs = 1e4) {
1141
1233
 
1142
1234
 
1143
1235
 
1144
- exports.HttpError = _chunkX2US4RAMcjs.HttpError; exports.ModelValidationError = _chunkX2US4RAMcjs.ModelValidationError; exports.cache = _chunkANUSWEAPcjs.cache; exports.cacheResponse = cacheResponse; exports.compose = compose; exports.db = _chunkRTF7PHS2cjs.db; exports.defineCollection = _chunkRTF7PHS2cjs.defineCollection; exports.defineModel = _chunkRTF7PHS2cjs.defineModel; exports.defineTable = _chunkRTF7PHS2cjs.defineTable; exports.getDbClient = _chunkRTF7PHS2cjs.getDbClient; exports.getLogger = _chunkYL37D6KMcjs.getLogger; exports.gracefulShutdown = gracefulShutdown; exports.ignite = ignite; exports.isHttpError = _chunkX2US4RAMcjs.isHttpError; exports.listTasks = _chunkTI24L4XEcjs.listTasks; exports.logger = _chunkYL37D6KMcjs.logger; exports.scanDir = _chunkR34R7QPDcjs.scanDir; exports.setDbClient = _chunkRTF7PHS2cjs.setDbClient; exports.transaction = _chunkRTF7PHS2cjs.transaction; exports.workerCount = workerCount;
1236
+
1237
+ exports.HttpError = _chunkNKLOE4AKcjs.HttpError; exports.ModelValidationError = _chunkNKLOE4AKcjs.ModelValidationError; exports.cache = _chunkKFVFP2Q7cjs.cache; exports.cacheResponse = cacheResponse; exports.compose = compose; exports.db = _chunkHBCY7ILDcjs.db; exports.defineCollection = _chunkHBCY7ILDcjs.defineCollection; exports.defineModel = _chunkHBCY7ILDcjs.defineModel; exports.defineTable = _chunkHBCY7ILDcjs.defineTable; exports.getDbClient = _chunkHBCY7ILDcjs.getDbClient; exports.getLogger = _chunkDUADUR6Rcjs.getLogger; exports.gracefulShutdown = gracefulShutdown; exports.ignite = ignite; exports.isHttpError = _chunkNKLOE4AKcjs.isHttpError; exports.listTasks = _chunkGBI77W5Tcjs.listTasks; exports.logger = _chunkDUADUR6Rcjs.logger; exports.rateLimit = rateLimit; exports.scanDir = _chunkDCJOWFVDcjs.scanDir; exports.setDbClient = _chunkHBCY7ILDcjs.setDbClient; exports.transaction = _chunkHBCY7ILDcjs.transaction; exports.workerCount = workerCount;
1145
1238
  //# sourceMappingURL=index.cjs.map