express-file-cluster 0.10.2 → 0.12.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 (142) hide show
  1. package/dist/auth/index.cjs +8 -7
  2. package/dist/auth/index.cjs.map +1 -1
  3. package/dist/auth/index.d.cts +3 -1
  4. package/dist/auth/index.d.ts +3 -1
  5. package/dist/auth/index.js +7 -5
  6. package/dist/{chunk-BG4A7Z32.js → chunk-3JQWQF2M.js} +3 -3
  7. package/dist/{chunk-4GHK27JA.cjs → chunk-4FQP6QX3.cjs} +3 -3
  8. package/dist/{chunk-4GHK27JA.cjs.map → chunk-4FQP6QX3.cjs.map} +1 -1
  9. package/dist/chunk-546TNO2V.js +226 -0
  10. package/dist/chunk-546TNO2V.js.map +1 -0
  11. package/dist/{chunk-MUVO7MGS.js → chunk-74R37C4I.js} +48 -21
  12. package/dist/chunk-74R37C4I.js.map +1 -0
  13. package/dist/{chunk-H2PVWCWC.cjs → chunk-A2QGDWCG.cjs} +15 -8
  14. package/dist/chunk-A2QGDWCG.cjs.map +1 -0
  15. package/dist/{chunk-5LPRKZPB.js → chunk-BCSJOPYH.js} +2 -2
  16. package/dist/chunk-BJR42CN3.cjs +872 -0
  17. package/dist/chunk-BJR42CN3.cjs.map +1 -0
  18. package/dist/{chunk-C2FOZ7ME.js → chunk-EBJELA7T.js} +30 -25
  19. package/dist/chunk-EBJELA7T.js.map +1 -0
  20. package/dist/{chunk-Y4NKIXUL.cjs → chunk-H6MHRHUP.cjs} +104 -50
  21. package/dist/chunk-H6MHRHUP.cjs.map +1 -0
  22. package/dist/{chunk-7BC3AN7R.cjs → chunk-IG3V2IOK.cjs} +57 -30
  23. package/dist/chunk-IG3V2IOK.cjs.map +1 -0
  24. package/dist/chunk-JAPZYQVJ.cjs +143 -0
  25. package/dist/chunk-JAPZYQVJ.cjs.map +1 -0
  26. package/dist/{chunk-JP36TLL4.cjs → chunk-JHCXIYJH.cjs} +25 -47
  27. package/dist/chunk-JHCXIYJH.cjs.map +1 -0
  28. package/dist/{chunk-IUZ6A7PB.cjs → chunk-JVB5NLEM.cjs} +15 -13
  29. package/dist/chunk-JVB5NLEM.cjs.map +1 -0
  30. package/dist/chunk-LIAGVWFQ.js +872 -0
  31. package/dist/chunk-LIAGVWFQ.js.map +1 -0
  32. package/dist/chunk-PUM5ZDAH.js +140 -0
  33. package/dist/chunk-PUM5ZDAH.js.map +1 -0
  34. package/dist/{chunk-CGY7JU4Y.cjs → chunk-PUYBKDYD.cjs} +11 -2
  35. package/dist/chunk-PUYBKDYD.cjs.map +1 -0
  36. package/dist/{chunk-RETV3GKE.js → chunk-QLM3JEER.js} +5 -3
  37. package/dist/{chunk-RETV3GKE.js.map → chunk-QLM3JEER.js.map} +1 -1
  38. package/dist/{chunk-R2K7AFIB.cjs → chunk-SV4C4HWP.cjs} +89 -89
  39. package/dist/{chunk-R2K7AFIB.cjs.map → chunk-SV4C4HWP.cjs.map} +1 -1
  40. package/dist/{chunk-V73R76I4.js → chunk-UJ2ISRLP.js} +11 -33
  41. package/dist/chunk-UJ2ISRLP.js.map +1 -0
  42. package/dist/chunk-URKE3OXN.cjs +226 -0
  43. package/dist/chunk-URKE3OXN.cjs.map +1 -0
  44. package/dist/{chunk-TBIVIR6L.cjs → chunk-VLGN3XUM.cjs} +40 -35
  45. package/dist/chunk-VLGN3XUM.cjs.map +1 -0
  46. package/dist/{chunk-Y75V5FCU.js → chunk-X2B7WBKH.js} +88 -34
  47. package/dist/chunk-X2B7WBKH.js.map +1 -0
  48. package/dist/chunk-Y7I2633P.js +12 -0
  49. package/dist/chunk-Y7I2633P.js.map +1 -0
  50. package/dist/{chunk-B6MB6HEG.js → chunk-ZBQUYFI3.js} +14 -7
  51. package/dist/chunk-ZBQUYFI3.js.map +1 -0
  52. package/dist/cli/db-runner.cjs +26 -25
  53. package/dist/cli/db-runner.cjs.map +1 -1
  54. package/dist/cli/db-runner.js +5 -3
  55. package/dist/cli/db-runner.js.map +1 -1
  56. package/dist/cli/index.cjs +16 -15
  57. package/dist/cli/index.cjs.map +1 -1
  58. package/dist/cli/index.js +9 -7
  59. package/dist/cli/index.js.map +1 -1
  60. package/dist/docs/api-reference/auth.md +2 -0
  61. package/dist/docs/api-reference/ignite.md +6 -0
  62. package/dist/docs/api-reference/openapi.md +36 -0
  63. package/dist/docs/api-reference/tasks.md +5 -1
  64. package/dist/docs/api-reference/testing.md +4 -0
  65. package/dist/docs/api-reference/tracing.md +18 -0
  66. package/dist/docs/api-reference/websockets.md +23 -0
  67. package/dist/docs/cli/add.md +1 -1
  68. package/dist/docs/core-concepts/background-tasks.md +5 -1
  69. package/dist/docs/core-concepts/clustering.md +2 -0
  70. package/dist/docs/core-concepts/file-based-routing.md +4 -0
  71. package/dist/docs/core-concepts/middleware.md +2 -0
  72. package/dist/docs/guides/caching.md +12 -0
  73. package/dist/docs/guides/error-handling.md +2 -0
  74. package/dist/docs/guides/feature-matrix.md +16 -0
  75. package/dist/docs/guides/logging.md +2 -0
  76. package/dist/docs/guides/openapi.md +57 -0
  77. package/dist/docs/guides/tracing.md +64 -0
  78. package/dist/docs/guides/validation.md +2 -0
  79. package/dist/docs/guides/websockets.md +60 -0
  80. package/dist/docs/index.md +4 -1
  81. package/dist/docs/skills/SKILL.md +7 -3
  82. package/dist/docs/skills/api-surface.md +18 -0
  83. package/dist/docs/skills/auth-internals.md +4 -2
  84. package/dist/docs/skills/pre-flight.md +6 -0
  85. package/dist/docs/skills/routing-rules.md +6 -0
  86. package/dist/docs/skills/tasks-internals.md +10 -2
  87. package/dist/docs/skills/what-not-to-invent.md +4 -0
  88. package/dist/index.cjs +185 -70
  89. package/dist/index.cjs.map +1 -1
  90. package/dist/index.d.cts +6 -14
  91. package/dist/index.d.ts +6 -14
  92. package/dist/index.js +143 -28
  93. package/dist/index.js.map +1 -1
  94. package/dist/openapi-cjs.cjs +5 -0
  95. package/dist/pgboss-backend-5DXF4G22.js +16 -0
  96. package/dist/pgboss-backend-KRTFHRNZ.cjs +16 -0
  97. package/dist/pgboss-backend-KRTFHRNZ.cjs.map +1 -0
  98. package/dist/registry/index.json +1 -1
  99. package/dist/tasks/index.cjs +3 -3
  100. package/dist/tasks/index.d.cts +4 -2
  101. package/dist/tasks/index.d.ts +4 -2
  102. package/dist/tasks/index.js +2 -1
  103. package/dist/testing.cjs +21 -13
  104. package/dist/testing.cjs.map +1 -1
  105. package/dist/testing.d.cts +5 -1
  106. package/dist/testing.d.ts +5 -1
  107. package/dist/testing.js +17 -8
  108. package/dist/testing.js.map +1 -1
  109. package/dist/thread-runner.cjs +5 -4
  110. package/dist/thread-runner.cjs.map +1 -1
  111. package/dist/thread-runner.d.cts +1 -1
  112. package/dist/thread-runner.d.ts +1 -1
  113. package/dist/thread-runner.js +4 -2
  114. package/dist/{types-CPMFTVXm.d.ts → types-Bgeqpm-n.d.cts} +91 -2
  115. package/dist/{types-CPMFTVXm.d.cts → types-Bgeqpm-n.d.ts} +91 -2
  116. package/package.json +11 -5
  117. package/dist/chunk-3SWI46YK.js +0 -74
  118. package/dist/chunk-3SWI46YK.js.map +0 -1
  119. package/dist/chunk-74BSJXWD.cjs +0 -220
  120. package/dist/chunk-74BSJXWD.cjs.map +0 -1
  121. package/dist/chunk-7BC3AN7R.cjs.map +0 -1
  122. package/dist/chunk-B6MB6HEG.js.map +0 -1
  123. package/dist/chunk-C2FOZ7ME.js.map +0 -1
  124. package/dist/chunk-CGY7JU4Y.cjs.map +0 -1
  125. package/dist/chunk-H2PVWCWC.cjs.map +0 -1
  126. package/dist/chunk-IUZ6A7PB.cjs.map +0 -1
  127. package/dist/chunk-JP36TLL4.cjs.map +0 -1
  128. package/dist/chunk-KLWL7XSC.js +0 -220
  129. package/dist/chunk-KLWL7XSC.js.map +0 -1
  130. package/dist/chunk-MUVO7MGS.js.map +0 -1
  131. package/dist/chunk-RPL2IFWK.cjs +0 -77
  132. package/dist/chunk-RPL2IFWK.cjs.map +0 -1
  133. package/dist/chunk-TBIVIR6L.cjs.map +0 -1
  134. package/dist/chunk-V73R76I4.js.map +0 -1
  135. package/dist/chunk-Y4NKIXUL.cjs.map +0 -1
  136. package/dist/chunk-Y75V5FCU.js.map +0 -1
  137. package/dist/pgboss-backend-4X2YT4RB.js +0 -14
  138. package/dist/pgboss-backend-UXQ3O2WT.cjs +0 -15
  139. package/dist/pgboss-backend-UXQ3O2WT.cjs.map +0 -1
  140. /package/dist/{chunk-BG4A7Z32.js.map → chunk-3JQWQF2M.js.map} +0 -0
  141. /package/dist/{chunk-5LPRKZPB.js.map → chunk-BCSJOPYH.js.map} +0 -0
  142. /package/dist/{pgboss-backend-4X2YT4RB.js.map → pgboss-backend-5DXF4G22.js.map} +0 -0
package/dist/testing.js CHANGED
@@ -1,21 +1,24 @@
1
1
  import {
2
2
  createHttpApp,
3
3
  mountErrorHandler,
4
+ mountOpenAPI,
4
5
  mountRoutes
5
- } from "./chunk-KLWL7XSC.js";
6
+ } from "./chunk-LIAGVWFQ.js";
6
7
  import {
7
8
  configureAuth
8
- } from "./chunk-Y75V5FCU.js";
9
+ } from "./chunk-X2B7WBKH.js";
9
10
  import {
10
11
  scanDir
11
- } from "./chunk-5LPRKZPB.js";
12
- import "./chunk-C2FOZ7ME.js";
12
+ } from "./chunk-BCSJOPYH.js";
13
+ import "./chunk-EBJELA7T.js";
13
14
  import "./chunk-XPY5TQDK.js";
14
- import "./chunk-3SWI46YK.js";
15
- import "./chunk-B6MB6HEG.js";
15
+ import "./chunk-PUM5ZDAH.js";
16
+ import "./chunk-ZBQUYFI3.js";
16
17
  import {
17
18
  configureLogger
18
- } from "./chunk-V73R76I4.js";
19
+ } from "./chunk-UJ2ISRLP.js";
20
+ import "./chunk-546TNO2V.js";
21
+ import "./chunk-Y7I2633P.js";
19
22
 
20
23
  // src/testing.ts
21
24
  import path from "path";
@@ -40,6 +43,7 @@ async function createTestApp(options) {
40
43
  }
41
44
  const app = createHttpApp({
42
45
  cors: false,
46
+ ...options.tracing !== void 0 && { tracing: options.tracing },
43
47
  ...options.globalMiddlewares !== void 0 && {
44
48
  globalMiddlewares: options.globalMiddlewares
45
49
  },
@@ -47,7 +51,12 @@ async function createTestApp(options) {
47
51
  ...options.trustProxy !== void 0 && { trustProxy: options.trustProxy }
48
52
  });
49
53
  const router = express.Router();
50
- await mountRoutes(router, scanDir(apiDir));
54
+ const mounted = await mountRoutes(router, scanDir(apiDir));
55
+ if (options.openapi)
56
+ await mountOpenAPI(app, mounted, {
57
+ ...options.openapi === true ? {} : options.openapi,
58
+ basePath: options.basePath ?? "/v1/api"
59
+ });
51
60
  app.use(options.basePath ?? "/v1/api", router);
52
61
  mountErrorHandler(app, options.onError);
53
62
  return app;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/testing.ts"],"sourcesContent":["import path from 'node:path';\nimport fs from 'node:fs';\nimport express from 'express';\nimport type { AuthStrategy, EFCConfig } from './types.js';\nimport { configureAuth } from './auth/index.js';\nimport { configureLogger } from './logger.js';\nimport { createHttpApp, mountErrorHandler } from './http-app.js';\nimport { scanDir } from './router/scan.js';\nimport { mountRoutes } from './router/mount.js';\n\nexport interface TestAppOptions {\n /** Explicit fixtures/app API directory. Does not change cwd or ignite() conventions. */\n apiDir: string;\n basePath?: string;\n globalMiddlewares?: express.RequestHandler[];\n requestTimeout?: number;\n trustProxy?: EFCConfig['trustProxy'];\n onError?: express.ErrorRequestHandler;\n /** Auth is process-wide, as in ignite(); use one configuration per test process. */\n auth?: {\n secret: string;\n strategy?: AuthStrategy;\n expiresIn?: string;\n cookieDomain?: string;\n };\n}\n\n/**\n * Mounts real file-based routes on an Express app for supertest (or another HTTP\n * harness). Does not listen, fork workers, start services, or install signal handlers.\n * Models and task queues need separately configured integration fixtures.\n */\nexport async function createTestApp(options: TestAppOptions): Promise<express.Express> {\n if (typeof options.apiDir !== 'string' || !options.apiDir.trim()) {\n throw new Error('[EFC] createTestApp requires a nonempty apiDir');\n }\n const apiDir = path.resolve(options.apiDir);\n if (!fs.existsSync(apiDir) || !fs.statSync(apiDir).isDirectory()) {\n throw new Error(`[EFC] createTestApp apiDir is not a directory: ${apiDir}`);\n }\n configureLogger(false);\n if (options.auth) {\n configureAuth({\n secret: options.auth.secret,\n strategy: options.auth.strategy ?? 'http-only',\n expiresIn: options.auth.expiresIn ?? '1h',\n ...(options.auth.cookieDomain !== undefined && { cookieDomain: options.auth.cookieDomain }),\n });\n }\n const app = createHttpApp({\n cors: false,\n ...(options.globalMiddlewares !== undefined && {\n globalMiddlewares: options.globalMiddlewares,\n }),\n ...(options.requestTimeout !== undefined && { requestTimeout: options.requestTimeout }),\n ...(options.trustProxy !== undefined && { trustProxy: options.trustProxy }),\n });\n const router = express.Router();\n await mountRoutes(router, scanDir(apiDir));\n app.use(options.basePath ?? '/v1/api', router);\n mountErrorHandler(app, options.onError);\n return app;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,OAAO,UAAU;AACjB,OAAO,QAAQ;AACf,OAAO,aAAa;AA8BpB,eAAsB,cAAc,SAAmD;AACrF,MAAI,OAAO,QAAQ,WAAW,YAAY,CAAC,QAAQ,OAAO,KAAK,GAAG;AAChE,UAAM,IAAI,MAAM,gDAAgD;AAAA,EAClE;AACA,QAAM,SAAS,KAAK,QAAQ,QAAQ,MAAM;AAC1C,MAAI,CAAC,GAAG,WAAW,MAAM,KAAK,CAAC,GAAG,SAAS,MAAM,EAAE,YAAY,GAAG;AAChE,UAAM,IAAI,MAAM,kDAAkD,MAAM,EAAE;AAAA,EAC5E;AACA,kBAAgB,KAAK;AACrB,MAAI,QAAQ,MAAM;AAChB,kBAAc;AAAA,MACZ,QAAQ,QAAQ,KAAK;AAAA,MACrB,UAAU,QAAQ,KAAK,YAAY;AAAA,MACnC,WAAW,QAAQ,KAAK,aAAa;AAAA,MACrC,GAAI,QAAQ,KAAK,iBAAiB,UAAa,EAAE,cAAc,QAAQ,KAAK,aAAa;AAAA,IAC3F,CAAC;AAAA,EACH;AACA,QAAM,MAAM,cAAc;AAAA,IACxB,MAAM;AAAA,IACN,GAAI,QAAQ,sBAAsB,UAAa;AAAA,MAC7C,mBAAmB,QAAQ;AAAA,IAC7B;AAAA,IACA,GAAI,QAAQ,mBAAmB,UAAa,EAAE,gBAAgB,QAAQ,eAAe;AAAA,IACrF,GAAI,QAAQ,eAAe,UAAa,EAAE,YAAY,QAAQ,WAAW;AAAA,EAC3E,CAAC;AACD,QAAM,SAAS,QAAQ,OAAO;AAC9B,QAAM,YAAY,QAAQ,QAAQ,MAAM,CAAC;AACzC,MAAI,IAAI,QAAQ,YAAY,WAAW,MAAM;AAC7C,oBAAkB,KAAK,QAAQ,OAAO;AACtC,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/testing.ts"],"sourcesContent":["import path from 'node:path';\nimport fs from 'node:fs';\nimport express from 'express';\nimport type { AuthStrategy, EFCConfig } from './types.js';\nimport { configureAuth } from './auth/index.js';\nimport { configureLogger } from './logger.js';\nimport { createHttpApp, mountErrorHandler } from './http-app.js';\nimport { scanDir } from './router/scan.js';\nimport { mountRoutes } from './router/mount.js';\nimport { mountOpenAPI } from './openapi.js';\n\nexport interface TestAppOptions {\n tracing?: EFCConfig['tracing'];\n openapi?: EFCConfig['openapi'];\n /** Explicit fixtures/app API directory. Does not change cwd or ignite() conventions. */\n apiDir: string;\n basePath?: string;\n globalMiddlewares?: express.RequestHandler[];\n requestTimeout?: number;\n trustProxy?: EFCConfig['trustProxy'];\n onError?: express.ErrorRequestHandler;\n /** Auth is process-wide, as in ignite(); use one configuration per test process. */\n auth?: {\n secret: string;\n strategy?: AuthStrategy;\n expiresIn?: string;\n cookieDomain?: string;\n };\n}\n\n/**\n * Mounts real file-based routes on an Express app for supertest (or another HTTP\n * harness). Does not listen, fork workers, start services, or install signal handlers.\n * Models and task queues need separately configured integration fixtures.\n */\nexport async function createTestApp(options: TestAppOptions): Promise<express.Express> {\n if (typeof options.apiDir !== 'string' || !options.apiDir.trim()) {\n throw new Error('[EFC] createTestApp requires a nonempty apiDir');\n }\n const apiDir = path.resolve(options.apiDir);\n if (!fs.existsSync(apiDir) || !fs.statSync(apiDir).isDirectory()) {\n throw new Error(`[EFC] createTestApp apiDir is not a directory: ${apiDir}`);\n }\n configureLogger(false);\n if (options.auth) {\n configureAuth({\n secret: options.auth.secret,\n strategy: options.auth.strategy ?? 'http-only',\n expiresIn: options.auth.expiresIn ?? '1h',\n ...(options.auth.cookieDomain !== undefined && { cookieDomain: options.auth.cookieDomain }),\n });\n }\n const app = createHttpApp({\n cors: false,\n ...(options.tracing !== undefined && { tracing: options.tracing }),\n ...(options.globalMiddlewares !== undefined && {\n globalMiddlewares: options.globalMiddlewares,\n }),\n ...(options.requestTimeout !== undefined && { requestTimeout: options.requestTimeout }),\n ...(options.trustProxy !== undefined && { trustProxy: options.trustProxy }),\n });\n const router = express.Router();\n const mounted = await mountRoutes(router, scanDir(apiDir));\n if (options.openapi)\n await mountOpenAPI(app, mounted, {\n ...(options.openapi === true ? {} : options.openapi),\n basePath: options.basePath ?? '/v1/api',\n });\n app.use(options.basePath ?? '/v1/api', router);\n mountErrorHandler(app, options.onError);\n return app;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,UAAU;AACjB,OAAO,QAAQ;AACf,OAAO,aAAa;AAiCpB,eAAsB,cAAc,SAAmD;AACrF,MAAI,OAAO,QAAQ,WAAW,YAAY,CAAC,QAAQ,OAAO,KAAK,GAAG;AAChE,UAAM,IAAI,MAAM,gDAAgD;AAAA,EAClE;AACA,QAAM,SAAS,KAAK,QAAQ,QAAQ,MAAM;AAC1C,MAAI,CAAC,GAAG,WAAW,MAAM,KAAK,CAAC,GAAG,SAAS,MAAM,EAAE,YAAY,GAAG;AAChE,UAAM,IAAI,MAAM,kDAAkD,MAAM,EAAE;AAAA,EAC5E;AACA,kBAAgB,KAAK;AACrB,MAAI,QAAQ,MAAM;AAChB,kBAAc;AAAA,MACZ,QAAQ,QAAQ,KAAK;AAAA,MACrB,UAAU,QAAQ,KAAK,YAAY;AAAA,MACnC,WAAW,QAAQ,KAAK,aAAa;AAAA,MACrC,GAAI,QAAQ,KAAK,iBAAiB,UAAa,EAAE,cAAc,QAAQ,KAAK,aAAa;AAAA,IAC3F,CAAC;AAAA,EACH;AACA,QAAM,MAAM,cAAc;AAAA,IACxB,MAAM;AAAA,IACN,GAAI,QAAQ,YAAY,UAAa,EAAE,SAAS,QAAQ,QAAQ;AAAA,IAChE,GAAI,QAAQ,sBAAsB,UAAa;AAAA,MAC7C,mBAAmB,QAAQ;AAAA,IAC7B;AAAA,IACA,GAAI,QAAQ,mBAAmB,UAAa,EAAE,gBAAgB,QAAQ,eAAe;AAAA,IACrF,GAAI,QAAQ,eAAe,UAAa,EAAE,YAAY,QAAQ,WAAW;AAAA,EAC3E,CAAC;AACD,QAAM,SAAS,QAAQ,OAAO;AAC9B,QAAM,UAAU,MAAM,YAAY,QAAQ,QAAQ,MAAM,CAAC;AACzD,MAAI,QAAQ;AACV,UAAM,aAAa,KAAK,SAAS;AAAA,MAC/B,GAAI,QAAQ,YAAY,OAAO,CAAC,IAAI,QAAQ;AAAA,MAC5C,UAAU,QAAQ,YAAY;AAAA,IAChC,CAAC;AACH,MAAI,IAAI,QAAQ,YAAY,WAAW,MAAM;AAC7C,oBAAkB,KAAK,QAAQ,OAAO;AACtC,SAAO;AACT;","names":[]}
@@ -1,9 +1,10 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkRPL2IFWKcjs = require('./chunk-RPL2IFWK.cjs');
4
- require('./chunk-H2PVWCWC.cjs');
5
- require('./chunk-CGY7JU4Y.cjs');
3
+ var _chunkJAPZYQVJcjs = require('./chunk-JAPZYQVJ.cjs');
4
+ require('./chunk-A2QGDWCG.cjs');
5
+ require('./chunk-URKE3OXN.cjs');
6
+ require('./chunk-PUYBKDYD.cjs');
6
7
 
7
8
 
8
- exports.runInThread = _chunkRPL2IFWKcjs.runInThread;
9
+ exports.runInThread = _chunkJAPZYQVJcjs.runInThread;
9
10
  //# sourceMappingURL=thread-runner.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/express-file-cluster/express-file-cluster/packages/core/dist/thread-runner.cjs"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B,gCAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACF,oDAAC","file":"/home/runner/work/express-file-cluster/express-file-cluster/packages/core/dist/thread-runner.cjs"}
1
+ {"version":3,"sources":["/home/runner/work/express-file-cluster/express-file-cluster/packages/core/dist/thread-runner.cjs"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B,gCAA6B;AAC7B,gCAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACF,oDAAC","file":"/home/runner/work/express-file-cluster/express-file-cluster/packages/core/dist/thread-runner.cjs"}
@@ -1,3 +1,3 @@
1
- declare function runInThread(handlerPath: string, payload: unknown): Promise<void>;
1
+ declare function runInThread(handlerPath: string, payload: unknown, tracing?: boolean): Promise<void>;
2
2
 
3
3
  export { runInThread };
@@ -1,3 +1,3 @@
1
- declare function runInThread(handlerPath: string, payload: unknown): Promise<void>;
1
+ declare function runInThread(handlerPath: string, payload: unknown, tracing?: boolean): Promise<void>;
2
2
 
3
3
  export { runInThread };
@@ -1,7 +1,9 @@
1
1
  import {
2
2
  runInThread
3
- } from "./chunk-3SWI46YK.js";
4
- import "./chunk-B6MB6HEG.js";
3
+ } from "./chunk-PUM5ZDAH.js";
4
+ import "./chunk-ZBQUYFI3.js";
5
+ import "./chunk-546TNO2V.js";
6
+ import "./chunk-Y7I2633P.js";
5
7
  export {
6
8
  runInThread
7
9
  };
@@ -1,4 +1,69 @@
1
- import { RequestHandler, ErrorRequestHandler } from 'express';
1
+ import { Request, Express, RequestHandler, ErrorRequestHandler } from 'express';
2
+ import http from 'node:http';
3
+ import { WebSocket, WebSocketServer } from 'ws';
4
+
5
+ type JSONSchema = boolean | Record<string, unknown>;
6
+ interface OpenAPIOptions {
7
+ /** Absolute static URL for the document. Default /openapi.json. */
8
+ path?: string;
9
+ info?: {
10
+ title: string;
11
+ version: string;
12
+ description?: string;
13
+ };
14
+ servers?: Array<{
15
+ url: string;
16
+ description?: string;
17
+ }>;
18
+ components?: Record<string, unknown>;
19
+ /** Adapter for validators without Standard JSON Schema support. */
20
+ schemaToJSONSchema?: (validator: Validator) => JSONSchema | Promise<JSONSchema>;
21
+ }
22
+ interface OpenAPIDocument {
23
+ openapi: '3.1.0';
24
+ info: {
25
+ title: string;
26
+ version: string;
27
+ description?: string;
28
+ };
29
+ paths: Record<string, Record<string, unknown>>;
30
+ components: Record<string, unknown> & {
31
+ schemas: Record<string, JSONSchema>;
32
+ };
33
+ servers?: Array<{
34
+ url: string;
35
+ description?: string;
36
+ }>;
37
+ }
38
+ /** Generate a document from the same mounted route exports used by the HTTP router. */
39
+ declare function generateOpenAPI(input: MountedRoute[] | string, options?: OpenAPIOptions & {
40
+ basePath?: string;
41
+ }): Promise<OpenAPIDocument>;
42
+
43
+ interface TracingOptions {
44
+ /** Instrument HTTP, including upgrade handshakes. Default true. */
45
+ http?: boolean;
46
+ /** Instrument the queue backends and propagate context to tasks. Default true. */
47
+ tasks?: boolean;
48
+ /** App-owned SDK shutdown/flush, called after HTTP and tasks drain. */
49
+ shutdown?: () => Promise<void>;
50
+ }
51
+
52
+ type WebSocketHandler = (socket: WebSocket, request: Request) => void | Promise<void>;
53
+ interface WebSocketOptions {
54
+ /** Default 1 MiB. Compression is disabled. */
55
+ maxPayload?: number;
56
+ /** Browser origins; default is same-origin. Clients without Origin are allowed. */
57
+ origins?: string[];
58
+ /** Default 30 seconds; 0 disables heartbeat. */
59
+ heartbeatIntervalMs?: number;
60
+ /** Default 10 seconds to finish upgrade middleware. */
61
+ handshakeTimeoutMs?: number;
62
+ }
63
+ /** Attach upgrade handling to an EFC HTTP app/server (also useful with createTestApp). */
64
+ declare function attachWebSockets(server: http.Server, app: Express, options?: WebSocketOptions): WebSocketServer;
65
+ /** Close upgraded sockets with 1001, then terminate peers that do not acknowledge. */
66
+ declare function closeWebSockets(server: http.Server, timeoutMs?: number): Promise<void>;
2
67
 
3
68
  type DatabaseEngine = 'mongodb' | 'postgresql';
4
69
  /**
@@ -102,6 +167,12 @@ interface DatabasePoolConfig {
102
167
  connectionTimeoutMs?: number;
103
168
  }
104
169
  interface EFCConfig {
170
+ /** Opt-in OpenTelemetry instrumentation; the app owns its SDK/exporter. */
171
+ tracing?: boolean | TracingOptions;
172
+ /** Opt-in OpenAPI 3.1 document; default URL /openapi.json. */
173
+ openapi?: boolean | OpenAPIOptions;
174
+ /** WS exports enable WebSockets by default; false disables upgrades. */
175
+ websocket?: false | WebSocketOptions;
105
176
  port?: number;
106
177
  /**
107
178
  * Express's `trust proxy`: set it when the app runs behind a proxy or load balancer
@@ -155,6 +226,13 @@ interface RouteEntry {
155
226
  pattern?: RegExp;
156
227
  }
157
228
  interface RouteMethodMeta {
229
+ summary?: string;
230
+ tags?: string[];
231
+ operationId?: string;
232
+ /** Explicit OpenAPI operation fields. hidden omits this operation from docs. */
233
+ openapi?: Record<string, unknown> & {
234
+ hidden?: boolean;
235
+ };
158
236
  description?: string;
159
237
  request?: {
160
238
  headers?: Record<string, string>;
@@ -179,6 +257,11 @@ type RouteMeta = Partial<Record<string, RouteMethodMeta>>;
179
257
  type Validator = {
180
258
  readonly '~standard': {
181
259
  validate: (value: unknown) => unknown;
260
+ jsonSchema?: {
261
+ input: (options: {
262
+ target: 'draft-2020-12';
263
+ }) => unknown;
264
+ };
182
265
  };
183
266
  } | {
184
267
  safeParse: (value: unknown) => unknown;
@@ -200,6 +283,12 @@ interface ValidationIssue {
200
283
  path: string;
201
284
  message: string;
202
285
  }
286
+ interface MountedRoute extends RouteEntry {
287
+ methods: string[];
288
+ schema?: RouteSchema;
289
+ websocket?: boolean;
290
+ meta?: RouteMeta;
291
+ }
203
292
  interface TaskOptions {
204
293
  thread?: boolean;
205
294
  retries?: number;
@@ -651,4 +740,4 @@ interface MigrationContext {
651
740
  engine: DatabaseEngine;
652
741
  }
653
742
 
654
- export type { AuthStrategy as A, ScalarKeys as B, CollectionSchema as C, DatabaseEngine as D, EFCConfig as E, FieldDefinition as F, GeoPoint as G, SchemaField as H, InferSchema as I, TableFieldDefinition as J, TableRelation as K, LoggingConfig as L, ModelSchema as M, TableSchemaField as N, Validator as O, QueryLogConfig as Q, RouteEntry as R, Simplify as S, TaskOptions as T, Update as U, ValidationIssue as V, TaskDefinition as a, InferCreateInput as b, ModelOptions as c, InferredModel as d, TableSchema as e, TableOptions as f, SortDirection as g, InferRecord as h, CacheConfig as i, CollectionFieldDefinition as j, CorsConfig as k, DatabasePoolConfig as l, DefaultOperator as m, Filter as n, FilterOperators as o, FindOptions as p, IndexDefinition as q, InferCreate as r, MigrationContext as s, ModelCRUD as t, ModelQueryOptions as u, ModelRecord as v, RequestSchema as w, RouteMeta as x, RouteMethodMeta as y, RouteSchema as z };
743
+ export { attachWebSockets as $, type AuthStrategy as A, type RouteSchema as B, type CollectionSchema as C, type DatabaseEngine as D, type EFCConfig as E, type FieldDefinition as F, type GeoPoint as G, type ScalarKeys as H, type InferSchema as I, type JSONSchema as J, type SchemaField as K, type LoggingConfig as L, type ModelSchema as M, type TableFieldDefinition as N, type OpenAPIDocument as O, type TableRelation as P, type QueryLogConfig as Q, type RouteEntry as R, type Simplify as S, type TaskOptions as T, type TableSchemaField as U, type TracingOptions as V, type Update as W, type ValidationIssue as X, type Validator as Y, type WebSocketHandler as Z, type WebSocketOptions as _, type TaskDefinition as a, closeWebSockets as a0, generateOpenAPI as a1, type InferCreateInput as b, type ModelOptions as c, type InferredModel as d, type TableSchema as e, type TableOptions as f, type SortDirection as g, type InferRecord as h, type CacheConfig as i, type CollectionFieldDefinition as j, type CorsConfig as k, type DatabasePoolConfig as l, type DefaultOperator as m, type Filter as n, type FilterOperators as o, type FindOptions as p, type IndexDefinition as q, type InferCreate as r, type MigrationContext as s, type ModelCRUD as t, type ModelQueryOptions as u, type ModelRecord as v, type OpenAPIOptions as w, type RequestSchema as x, type RouteMeta as y, type RouteMethodMeta as z };
@@ -1,4 +1,69 @@
1
- import { RequestHandler, ErrorRequestHandler } from 'express';
1
+ import { Request, Express, RequestHandler, ErrorRequestHandler } from 'express';
2
+ import http from 'node:http';
3
+ import { WebSocket, WebSocketServer } from 'ws';
4
+
5
+ type JSONSchema = boolean | Record<string, unknown>;
6
+ interface OpenAPIOptions {
7
+ /** Absolute static URL for the document. Default /openapi.json. */
8
+ path?: string;
9
+ info?: {
10
+ title: string;
11
+ version: string;
12
+ description?: string;
13
+ };
14
+ servers?: Array<{
15
+ url: string;
16
+ description?: string;
17
+ }>;
18
+ components?: Record<string, unknown>;
19
+ /** Adapter for validators without Standard JSON Schema support. */
20
+ schemaToJSONSchema?: (validator: Validator) => JSONSchema | Promise<JSONSchema>;
21
+ }
22
+ interface OpenAPIDocument {
23
+ openapi: '3.1.0';
24
+ info: {
25
+ title: string;
26
+ version: string;
27
+ description?: string;
28
+ };
29
+ paths: Record<string, Record<string, unknown>>;
30
+ components: Record<string, unknown> & {
31
+ schemas: Record<string, JSONSchema>;
32
+ };
33
+ servers?: Array<{
34
+ url: string;
35
+ description?: string;
36
+ }>;
37
+ }
38
+ /** Generate a document from the same mounted route exports used by the HTTP router. */
39
+ declare function generateOpenAPI(input: MountedRoute[] | string, options?: OpenAPIOptions & {
40
+ basePath?: string;
41
+ }): Promise<OpenAPIDocument>;
42
+
43
+ interface TracingOptions {
44
+ /** Instrument HTTP, including upgrade handshakes. Default true. */
45
+ http?: boolean;
46
+ /** Instrument the queue backends and propagate context to tasks. Default true. */
47
+ tasks?: boolean;
48
+ /** App-owned SDK shutdown/flush, called after HTTP and tasks drain. */
49
+ shutdown?: () => Promise<void>;
50
+ }
51
+
52
+ type WebSocketHandler = (socket: WebSocket, request: Request) => void | Promise<void>;
53
+ interface WebSocketOptions {
54
+ /** Default 1 MiB. Compression is disabled. */
55
+ maxPayload?: number;
56
+ /** Browser origins; default is same-origin. Clients without Origin are allowed. */
57
+ origins?: string[];
58
+ /** Default 30 seconds; 0 disables heartbeat. */
59
+ heartbeatIntervalMs?: number;
60
+ /** Default 10 seconds to finish upgrade middleware. */
61
+ handshakeTimeoutMs?: number;
62
+ }
63
+ /** Attach upgrade handling to an EFC HTTP app/server (also useful with createTestApp). */
64
+ declare function attachWebSockets(server: http.Server, app: Express, options?: WebSocketOptions): WebSocketServer;
65
+ /** Close upgraded sockets with 1001, then terminate peers that do not acknowledge. */
66
+ declare function closeWebSockets(server: http.Server, timeoutMs?: number): Promise<void>;
2
67
 
3
68
  type DatabaseEngine = 'mongodb' | 'postgresql';
4
69
  /**
@@ -102,6 +167,12 @@ interface DatabasePoolConfig {
102
167
  connectionTimeoutMs?: number;
103
168
  }
104
169
  interface EFCConfig {
170
+ /** Opt-in OpenTelemetry instrumentation; the app owns its SDK/exporter. */
171
+ tracing?: boolean | TracingOptions;
172
+ /** Opt-in OpenAPI 3.1 document; default URL /openapi.json. */
173
+ openapi?: boolean | OpenAPIOptions;
174
+ /** WS exports enable WebSockets by default; false disables upgrades. */
175
+ websocket?: false | WebSocketOptions;
105
176
  port?: number;
106
177
  /**
107
178
  * Express's `trust proxy`: set it when the app runs behind a proxy or load balancer
@@ -155,6 +226,13 @@ interface RouteEntry {
155
226
  pattern?: RegExp;
156
227
  }
157
228
  interface RouteMethodMeta {
229
+ summary?: string;
230
+ tags?: string[];
231
+ operationId?: string;
232
+ /** Explicit OpenAPI operation fields. hidden omits this operation from docs. */
233
+ openapi?: Record<string, unknown> & {
234
+ hidden?: boolean;
235
+ };
158
236
  description?: string;
159
237
  request?: {
160
238
  headers?: Record<string, string>;
@@ -179,6 +257,11 @@ type RouteMeta = Partial<Record<string, RouteMethodMeta>>;
179
257
  type Validator = {
180
258
  readonly '~standard': {
181
259
  validate: (value: unknown) => unknown;
260
+ jsonSchema?: {
261
+ input: (options: {
262
+ target: 'draft-2020-12';
263
+ }) => unknown;
264
+ };
182
265
  };
183
266
  } | {
184
267
  safeParse: (value: unknown) => unknown;
@@ -200,6 +283,12 @@ interface ValidationIssue {
200
283
  path: string;
201
284
  message: string;
202
285
  }
286
+ interface MountedRoute extends RouteEntry {
287
+ methods: string[];
288
+ schema?: RouteSchema;
289
+ websocket?: boolean;
290
+ meta?: RouteMeta;
291
+ }
203
292
  interface TaskOptions {
204
293
  thread?: boolean;
205
294
  retries?: number;
@@ -651,4 +740,4 @@ interface MigrationContext {
651
740
  engine: DatabaseEngine;
652
741
  }
653
742
 
654
- export type { AuthStrategy as A, ScalarKeys as B, CollectionSchema as C, DatabaseEngine as D, EFCConfig as E, FieldDefinition as F, GeoPoint as G, SchemaField as H, InferSchema as I, TableFieldDefinition as J, TableRelation as K, LoggingConfig as L, ModelSchema as M, TableSchemaField as N, Validator as O, QueryLogConfig as Q, RouteEntry as R, Simplify as S, TaskOptions as T, Update as U, ValidationIssue as V, TaskDefinition as a, InferCreateInput as b, ModelOptions as c, InferredModel as d, TableSchema as e, TableOptions as f, SortDirection as g, InferRecord as h, CacheConfig as i, CollectionFieldDefinition as j, CorsConfig as k, DatabasePoolConfig as l, DefaultOperator as m, Filter as n, FilterOperators as o, FindOptions as p, IndexDefinition as q, InferCreate as r, MigrationContext as s, ModelCRUD as t, ModelQueryOptions as u, ModelRecord as v, RequestSchema as w, RouteMeta as x, RouteMethodMeta as y, RouteSchema as z };
743
+ export { attachWebSockets as $, type AuthStrategy as A, type RouteSchema as B, type CollectionSchema as C, type DatabaseEngine as D, type EFCConfig as E, type FieldDefinition as F, type GeoPoint as G, type ScalarKeys as H, type InferSchema as I, type JSONSchema as J, type SchemaField as K, type LoggingConfig as L, type ModelSchema as M, type TableFieldDefinition as N, type OpenAPIDocument as O, type TableRelation as P, type QueryLogConfig as Q, type RouteEntry as R, type Simplify as S, type TaskOptions as T, type TableSchemaField as U, type TracingOptions as V, type Update as W, type ValidationIssue as X, type Validator as Y, type WebSocketHandler as Z, type WebSocketOptions as _, type TaskDefinition as a, closeWebSockets as a0, generateOpenAPI as a1, type InferCreateInput as b, type ModelOptions as c, type InferredModel as d, type TableSchema as e, type TableOptions as f, type SortDirection as g, type InferRecord as h, type CacheConfig as i, type CollectionFieldDefinition as j, type CorsConfig as k, type DatabasePoolConfig as l, type DefaultOperator as m, type Filter as n, type FilterOperators as o, type FindOptions as p, type IndexDefinition as q, type InferCreate as r, type MigrationContext as s, type ModelCRUD as t, type ModelQueryOptions as u, type ModelRecord as v, type OpenAPIOptions as w, type RequestSchema as x, type RouteMeta as y, type RouteMethodMeta as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-file-cluster",
3
- "version": "0.10.2",
3
+ "version": "0.12.0",
4
4
  "description": "Enterprise-grade, zero-boilerplate backend framework with file-based routing and multi-core clustering",
5
5
  "homepage": "https://efc.prashantadhikari7.com.np/",
6
6
  "repository": {
@@ -50,15 +50,21 @@
50
50
  "typecheck": "tsc --noEmit"
51
51
  },
52
52
  "dependencies": {
53
+ "@opentelemetry/api": "~1.9.0",
54
+ "@opentelemetry/core": "^2.12.0",
55
+ "@types/ws": "^8.18.2",
53
56
  "chokidar": "^4.0.0",
54
57
  "commander": "^12.0.0",
55
58
  "cookie-parser": "^1.4.6",
56
59
  "cors": "^2.8.6",
57
60
  "jose": "^6.2.3",
58
61
  "picocolors": "^1.1.1",
59
- "pino": "^10.4.0"
62
+ "pino": "^10.4.0",
63
+ "ws": "^8.22.0"
60
64
  },
61
65
  "devDependencies": {
66
+ "@opentelemetry/context-async-hooks": "^2.12.0",
67
+ "@opentelemetry/sdk-trace": "^2.12.0",
62
68
  "@types/cookie-parser": "^1.4.7",
63
69
  "@types/cors": "^2.8.19",
64
70
  "@types/express": "^4.17.21",
@@ -78,13 +84,13 @@
78
84
  "zod": "^4.6.7"
79
85
  },
80
86
  "peerDependencies": {
81
- "bullmq": ">=5.0.0",
87
+ "bullmq": ">=5.79.1",
82
88
  "drizzle-orm": ">=0.40.0",
83
89
  "express": "^4.19.0",
90
+ "ioredis": "^5.0.0",
84
91
  "mongoose": "^8.0.0 || ^9.0.0",
85
92
  "pg": "^8.11.0",
86
- "pg-boss": ">=12.0.0",
87
- "ioredis": "^5.0.0"
93
+ "pg-boss": ">=12.38.0"
88
94
  },
89
95
  "peerDependenciesMeta": {
90
96
  "bullmq": {
@@ -1,74 +0,0 @@
1
- import {
2
- ENQUEUE_BRIDGE,
3
- enqueue
4
- } from "./chunk-B6MB6HEG.js";
5
-
6
- // src/tasks/thread-runner.ts
7
- import { Worker, workerData, parentPort, isMainThread } from "worker_threads";
8
- if (!isMainThread && parentPort && workerData?.efcTask) {
9
- const port = parentPort;
10
- const { handlerPath, payload } = workerData;
11
- const waiting = /* @__PURE__ */ new Map();
12
- let seq = 0;
13
- port.unref();
14
- port.on("message", (msg) => {
15
- if (msg?.type !== "enqueued") return;
16
- const w = waiting.get(msg.id);
17
- if (!w) return;
18
- waiting.delete(msg.id);
19
- if (waiting.size === 0) port.unref();
20
- if (msg.error === void 0) w.resolve();
21
- else w.reject(new Error(msg.error));
22
- });
23
- globalThis[ENQUEUE_BRIDGE] = (name, payload2) => new Promise((resolve, reject) => {
24
- const id = ++seq;
25
- waiting.set(id, { resolve, reject });
26
- port.ref();
27
- port.postMessage({ type: "enqueue", id, name, payload: payload2 });
28
- });
29
- (async () => {
30
- try {
31
- const mod = await import(handlerPath);
32
- const def = mod["default"];
33
- if (!def || typeof def.handler !== "function") {
34
- throw new Error(`[EFC] Thread runner: no valid task export in ${handlerPath}`);
35
- }
36
- await def.handler(payload);
37
- port.postMessage({ type: "done", ok: true });
38
- } catch (err) {
39
- port.postMessage({ type: "done", ok: false, error: String(err) });
40
- }
41
- })();
42
- }
43
- function runInThread(handlerPath, payload) {
44
- return new Promise((resolve, reject) => {
45
- const worker = new Worker(new URL("./thread-runner.js", import.meta.url), {
46
- workerData: { efcTask: true, handlerPath, payload }
47
- });
48
- worker.on("message", (msg) => {
49
- if (msg.type === "enqueue") {
50
- const reply = (error) => worker.postMessage({
51
- type: "enqueued",
52
- id: msg.id,
53
- ...error !== void 0 && { error }
54
- });
55
- enqueue(msg.name, msg.payload).then(
56
- () => reply(),
57
- (err) => reply(err instanceof Error ? err.message : String(err))
58
- );
59
- return;
60
- }
61
- if (msg.ok) resolve();
62
- else reject(new Error(msg.error ?? "Thread task failed"));
63
- });
64
- worker.on("error", reject);
65
- worker.on("exit", (code) => {
66
- if (code !== 0) reject(new Error(`Thread worker exited with code ${code}`));
67
- });
68
- });
69
- }
70
-
71
- export {
72
- runInThread
73
- };
74
- //# sourceMappingURL=chunk-3SWI46YK.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/tasks/thread-runner.ts"],"sourcesContent":["import { Worker, workerData, parentPort, isMainThread } from 'node:worker_threads';\nimport type { TaskDefinition } from '../types.js';\nimport { enqueue, ENQUEUE_BRIDGE } from './index.js';\n\n// `{ thread: true }` tasks run here, in a worker_thread. The task queue lives on the main\n// thread, so `enqueue()` inside the thread is bridged: the thread posts the call, the main\n// thread runs the real enqueue() and posts back the outcome.\n\ntype FromThread =\n | { type: 'done'; ok: true }\n | { type: 'done'; ok: false; error: string }\n | { type: 'enqueue'; id: number; name: string; payload: unknown };\ntype ToThread = { type: 'enqueued'; id: number; error?: string };\n\n// ── Worker-thread side ────────────────────────────────────────────────────────\nif (!isMainThread && parentPort && (workerData as { efcTask?: boolean })?.efcTask) {\n const port = parentPort;\n const { handlerPath, payload } = workerData as { handlerPath: string; payload: unknown };\n const waiting = new Map<number, { resolve: () => void; reject: (e: Error) => void }>();\n let seq = 0;\n // The port only keeps the thread alive while an enqueue waits for its answer, so a\n // finished task's thread still exits.\n port.unref();\n port.on('message', (msg: ToThread) => {\n if (msg?.type !== 'enqueued') return;\n const w = waiting.get(msg.id);\n if (!w) return;\n waiting.delete(msg.id);\n if (waiting.size === 0) port.unref();\n if (msg.error === undefined) w.resolve();\n else w.reject(new Error(msg.error));\n });\n // On globalThis, so the task's own copy of express-file-cluster/tasks (ESM or CJS)\n // finds it too.\n (globalThis as Record<symbol, unknown>)[ENQUEUE_BRIDGE] = (name: string, payload: unknown) =>\n new Promise<void>((resolve, reject) => {\n const id = ++seq;\n waiting.set(id, { resolve, reject });\n port.ref();\n port.postMessage({ type: 'enqueue', id, name, payload } satisfies FromThread);\n });\n\n (async () => {\n try {\n const mod = (await import(handlerPath)) as Record<string, unknown>;\n const def = mod['default'] as TaskDefinition | undefined;\n if (!def || typeof def.handler !== 'function') {\n throw new Error(`[EFC] Thread runner: no valid task export in ${handlerPath}`);\n }\n await def.handler(payload);\n port.postMessage({ type: 'done', ok: true } satisfies FromThread);\n } catch (err) {\n port.postMessage({ type: 'done', ok: false, error: String(err) } satisfies FromThread);\n }\n })();\n}\n\n// ── Main-thread side ──────────────────────────────────────────────────────────\nexport function runInThread(handlerPath: string, payload: unknown): Promise<void> {\n return new Promise((resolve, reject) => {\n const worker = new Worker(new URL('./thread-runner.js', import.meta.url), {\n workerData: { efcTask: true, handlerPath, payload },\n });\n\n worker.on('message', (msg: FromThread) => {\n if (msg.type === 'enqueue') {\n const reply = (error?: string) =>\n worker.postMessage({\n type: 'enqueued',\n id: msg.id,\n ...(error !== undefined && { error }),\n } satisfies ToThread);\n enqueue(msg.name, msg.payload).then(\n () => reply(),\n (err: unknown) => reply(err instanceof Error ? err.message : String(err)),\n );\n return;\n }\n if (msg.ok) resolve();\n else reject(new Error(msg.error ?? 'Thread task failed'));\n });\n\n worker.on('error', reject);\n worker.on('exit', (code) => {\n if (code !== 0) reject(new Error(`Thread worker exited with code ${code}`));\n });\n });\n}\n"],"mappings":";;;;;;AAAA,SAAS,QAAQ,YAAY,YAAY,oBAAoB;AAe7D,IAAI,CAAC,gBAAgB,cAAe,YAAsC,SAAS;AACjF,QAAM,OAAO;AACb,QAAM,EAAE,aAAa,QAAQ,IAAI;AACjC,QAAM,UAAU,oBAAI,IAAiE;AACrF,MAAI,MAAM;AAGV,OAAK,MAAM;AACX,OAAK,GAAG,WAAW,CAAC,QAAkB;AACpC,QAAI,KAAK,SAAS,WAAY;AAC9B,UAAM,IAAI,QAAQ,IAAI,IAAI,EAAE;AAC5B,QAAI,CAAC,EAAG;AACR,YAAQ,OAAO,IAAI,EAAE;AACrB,QAAI,QAAQ,SAAS,EAAG,MAAK,MAAM;AACnC,QAAI,IAAI,UAAU,OAAW,GAAE,QAAQ;AAAA,QAClC,GAAE,OAAO,IAAI,MAAM,IAAI,KAAK,CAAC;AAAA,EACpC,CAAC;AAGD,EAAC,WAAuC,cAAc,IAAI,CAAC,MAAcA,aACvE,IAAI,QAAc,CAAC,SAAS,WAAW;AACrC,UAAM,KAAK,EAAE;AACb,YAAQ,IAAI,IAAI,EAAE,SAAS,OAAO,CAAC;AACnC,SAAK,IAAI;AACT,SAAK,YAAY,EAAE,MAAM,WAAW,IAAI,MAAM,SAAAA,SAAQ,CAAsB;AAAA,EAC9E,CAAC;AAEH,GAAC,YAAY;AACX,QAAI;AACF,YAAM,MAAO,MAAM,OAAO;AAC1B,YAAM,MAAM,IAAI,SAAS;AACzB,UAAI,CAAC,OAAO,OAAO,IAAI,YAAY,YAAY;AAC7C,cAAM,IAAI,MAAM,gDAAgD,WAAW,EAAE;AAAA,MAC/E;AACA,YAAM,IAAI,QAAQ,OAAO;AACzB,WAAK,YAAY,EAAE,MAAM,QAAQ,IAAI,KAAK,CAAsB;AAAA,IAClE,SAAS,KAAK;AACZ,WAAK,YAAY,EAAE,MAAM,QAAQ,IAAI,OAAO,OAAO,OAAO,GAAG,EAAE,CAAsB;AAAA,IACvF;AAAA,EACF,GAAG;AACL;AAGO,SAAS,YAAY,aAAqB,SAAiC;AAChF,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,UAAM,SAAS,IAAI,OAAO,IAAI,IAAI,sBAAsB,YAAY,GAAG,GAAG;AAAA,MACxE,YAAY,EAAE,SAAS,MAAM,aAAa,QAAQ;AAAA,IACpD,CAAC;AAED,WAAO,GAAG,WAAW,CAAC,QAAoB;AACxC,UAAI,IAAI,SAAS,WAAW;AAC1B,cAAM,QAAQ,CAAC,UACb,OAAO,YAAY;AAAA,UACjB,MAAM;AAAA,UACN,IAAI,IAAI;AAAA,UACR,GAAI,UAAU,UAAa,EAAE,MAAM;AAAA,QACrC,CAAoB;AACtB,gBAAQ,IAAI,MAAM,IAAI,OAAO,EAAE;AAAA,UAC7B,MAAM,MAAM;AAAA,UACZ,CAAC,QAAiB,MAAM,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,CAAC;AAAA,QAC1E;AACA;AAAA,MACF;AACA,UAAI,IAAI,GAAI,SAAQ;AAAA,UACf,QAAO,IAAI,MAAM,IAAI,SAAS,oBAAoB,CAAC;AAAA,IAC1D,CAAC;AAED,WAAO,GAAG,SAAS,MAAM;AACzB,WAAO,GAAG,QAAQ,CAAC,SAAS;AAC1B,UAAI,SAAS,EAAG,QAAO,IAAI,MAAM,kCAAkC,IAAI,EAAE,CAAC;AAAA,IAC5E,CAAC;AAAA,EACH,CAAC;AACH;","names":["payload"]}