threadforge 0.1.1 → 0.2.1

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 (358) hide show
  1. package/README.md +52 -20
  2. package/bin/forge.js +2 -1058
  3. package/bin/host-commands.d.ts +2 -0
  4. package/bin/host-commands.d.ts.map +1 -0
  5. package/bin/host-commands.js +7 -8
  6. package/bin/platform-commands.d.ts +2 -0
  7. package/bin/platform-commands.d.ts.map +1 -0
  8. package/bin/platform-commands.js +118 -36
  9. package/dist/cli/base-command.d.ts +12 -0
  10. package/dist/cli/base-command.d.ts.map +1 -0
  11. package/dist/cli/base-command.js +25 -0
  12. package/dist/cli/base-command.js.map +1 -0
  13. package/dist/cli/commands/build.d.ts +10 -0
  14. package/dist/cli/commands/build.d.ts.map +1 -0
  15. package/dist/cli/commands/build.js +110 -0
  16. package/dist/cli/commands/build.js.map +1 -0
  17. package/dist/cli/commands/deploy.d.ts +12 -0
  18. package/dist/cli/commands/deploy.d.ts.map +1 -0
  19. package/dist/cli/commands/deploy.js +143 -0
  20. package/dist/cli/commands/deploy.js.map +1 -0
  21. package/dist/cli/commands/dev.d.ts +10 -0
  22. package/dist/cli/commands/dev.d.ts.map +1 -0
  23. package/dist/cli/commands/dev.js +138 -0
  24. package/dist/cli/commands/dev.js.map +1 -0
  25. package/dist/cli/commands/generate.d.ts +10 -0
  26. package/dist/cli/commands/generate.d.ts.map +1 -0
  27. package/dist/cli/commands/generate.js +76 -0
  28. package/dist/cli/commands/generate.js.map +1 -0
  29. package/dist/cli/commands/host.d.ts +8 -0
  30. package/dist/cli/commands/host.d.ts.map +1 -0
  31. package/dist/cli/commands/host.js +20 -0
  32. package/dist/cli/commands/host.js.map +1 -0
  33. package/dist/cli/commands/init.d.ts +16 -0
  34. package/dist/cli/commands/init.d.ts.map +1 -0
  35. package/dist/cli/commands/init.js +246 -0
  36. package/dist/cli/commands/init.js.map +1 -0
  37. package/dist/cli/commands/platform.d.ts +8 -0
  38. package/dist/cli/commands/platform.d.ts.map +1 -0
  39. package/dist/cli/commands/platform.js +20 -0
  40. package/dist/cli/commands/platform.js.map +1 -0
  41. package/dist/cli/commands/restart.d.ts +8 -0
  42. package/dist/cli/commands/restart.d.ts.map +1 -0
  43. package/dist/cli/commands/restart.js +13 -0
  44. package/dist/cli/commands/restart.js.map +1 -0
  45. package/dist/cli/commands/scaffold/frontend.d.ts +10 -0
  46. package/dist/cli/commands/scaffold/frontend.d.ts.map +1 -0
  47. package/dist/cli/commands/scaffold/frontend.js +130 -0
  48. package/dist/cli/commands/scaffold/frontend.js.map +1 -0
  49. package/dist/cli/commands/scaffold/react.d.ts +7 -0
  50. package/dist/cli/commands/scaffold/react.d.ts.map +1 -0
  51. package/dist/cli/commands/scaffold/react.js +12 -0
  52. package/dist/cli/commands/scaffold/react.js.map +1 -0
  53. package/dist/cli/commands/scale.d.ts +8 -0
  54. package/dist/cli/commands/scale.d.ts.map +1 -0
  55. package/dist/cli/commands/scale.js +13 -0
  56. package/dist/cli/commands/scale.js.map +1 -0
  57. package/dist/cli/commands/start.d.ts +10 -0
  58. package/dist/cli/commands/start.d.ts.map +1 -0
  59. package/dist/cli/commands/start.js +71 -0
  60. package/dist/cli/commands/start.js.map +1 -0
  61. package/dist/cli/commands/status.d.ts +11 -0
  62. package/dist/cli/commands/status.d.ts.map +1 -0
  63. package/dist/cli/commands/status.js +60 -0
  64. package/dist/cli/commands/status.js.map +1 -0
  65. package/dist/cli/commands/stop.d.ts +10 -0
  66. package/dist/cli/commands/stop.d.ts.map +1 -0
  67. package/dist/cli/commands/stop.js +89 -0
  68. package/dist/cli/commands/stop.js.map +1 -0
  69. package/dist/cli/util/config-discovery.d.ts +8 -0
  70. package/dist/cli/util/config-discovery.d.ts.map +1 -0
  71. package/dist/cli/util/config-discovery.js +70 -0
  72. package/dist/cli/util/config-discovery.js.map +1 -0
  73. package/dist/cli/util/config-patcher.d.ts +17 -0
  74. package/dist/cli/util/config-patcher.d.ts.map +1 -0
  75. package/dist/cli/util/config-patcher.js +439 -0
  76. package/dist/cli/util/config-patcher.js.map +1 -0
  77. package/dist/cli/util/frontend-dev.d.ts +8 -0
  78. package/dist/cli/util/frontend-dev.d.ts.map +1 -0
  79. package/dist/cli/util/frontend-dev.js +117 -0
  80. package/dist/cli/util/frontend-dev.js.map +1 -0
  81. package/dist/cli/util/process.d.ts +5 -0
  82. package/dist/cli/util/process.d.ts.map +1 -0
  83. package/dist/cli/util/process.js +17 -0
  84. package/dist/cli/util/process.js.map +1 -0
  85. package/dist/cli/util/templates.d.ts +10 -0
  86. package/dist/cli/util/templates.d.ts.map +1 -0
  87. package/dist/cli/util/templates.js +157 -0
  88. package/dist/cli/util/templates.js.map +1 -0
  89. package/dist/core/AlertSink.d.ts +83 -0
  90. package/dist/core/AlertSink.d.ts.map +1 -0
  91. package/dist/core/AlertSink.js +126 -0
  92. package/dist/core/AlertSink.js.map +1 -0
  93. package/dist/core/DirectMessageBus.d.ts +88 -0
  94. package/dist/core/DirectMessageBus.d.ts.map +1 -0
  95. package/dist/core/DirectMessageBus.js +352 -0
  96. package/dist/core/DirectMessageBus.js.map +1 -0
  97. package/dist/core/EndpointResolver.d.ts +111 -0
  98. package/dist/core/EndpointResolver.d.ts.map +1 -0
  99. package/dist/core/EndpointResolver.js +336 -0
  100. package/dist/core/EndpointResolver.js.map +1 -0
  101. package/dist/core/ForgeContext.d.ts +221 -0
  102. package/dist/core/ForgeContext.d.ts.map +1 -0
  103. package/dist/core/ForgeContext.js +1169 -0
  104. package/dist/core/ForgeContext.js.map +1 -0
  105. package/dist/core/ForgeEndpoints.d.ts +71 -0
  106. package/dist/core/ForgeEndpoints.d.ts.map +1 -0
  107. package/dist/core/ForgeEndpoints.js +442 -0
  108. package/dist/core/ForgeEndpoints.js.map +1 -0
  109. package/dist/core/ForgeHost.d.ts +82 -0
  110. package/dist/core/ForgeHost.d.ts.map +1 -0
  111. package/dist/core/ForgeHost.js +107 -0
  112. package/dist/core/ForgeHost.js.map +1 -0
  113. package/dist/core/ForgePlatform.d.ts +96 -0
  114. package/dist/core/ForgePlatform.d.ts.map +1 -0
  115. package/dist/core/ForgePlatform.js +136 -0
  116. package/dist/core/ForgePlatform.js.map +1 -0
  117. package/dist/core/ForgeWebSocket.d.ts +56 -0
  118. package/dist/core/ForgeWebSocket.d.ts.map +1 -0
  119. package/dist/core/ForgeWebSocket.js +415 -0
  120. package/dist/core/ForgeWebSocket.js.map +1 -0
  121. package/dist/core/Ingress.d.ts +329 -0
  122. package/dist/core/Ingress.d.ts.map +1 -0
  123. package/dist/core/Ingress.js +694 -0
  124. package/dist/core/Ingress.js.map +1 -0
  125. package/dist/core/Interceptors.d.ts +134 -0
  126. package/dist/core/Interceptors.d.ts.map +1 -0
  127. package/dist/core/Interceptors.js +416 -0
  128. package/dist/core/Interceptors.js.map +1 -0
  129. package/dist/core/Logger.d.ts +20 -0
  130. package/dist/core/Logger.d.ts.map +1 -0
  131. package/dist/core/Logger.js +77 -0
  132. package/dist/core/Logger.js.map +1 -0
  133. package/dist/core/MessageBus.d.ts +15 -0
  134. package/dist/core/MessageBus.d.ts.map +1 -0
  135. package/dist/core/MessageBus.js +18 -0
  136. package/dist/core/MessageBus.js.map +1 -0
  137. package/dist/core/Prometheus.d.ts +80 -0
  138. package/dist/core/Prometheus.d.ts.map +1 -0
  139. package/dist/core/Prometheus.js +332 -0
  140. package/dist/core/Prometheus.js.map +1 -0
  141. package/dist/core/RequestContext.d.ts +214 -0
  142. package/dist/core/RequestContext.d.ts.map +1 -0
  143. package/dist/core/RequestContext.js +556 -0
  144. package/dist/core/RequestContext.js.map +1 -0
  145. package/dist/core/Router.d.ts +45 -0
  146. package/dist/core/Router.d.ts.map +1 -0
  147. package/dist/core/Router.js +285 -0
  148. package/dist/core/Router.js.map +1 -0
  149. package/dist/core/RoutingStrategy.d.ts +116 -0
  150. package/dist/core/RoutingStrategy.d.ts.map +1 -0
  151. package/dist/core/RoutingStrategy.js +306 -0
  152. package/dist/core/RoutingStrategy.js.map +1 -0
  153. package/dist/core/RpcConfig.d.ts +72 -0
  154. package/dist/core/RpcConfig.d.ts.map +1 -0
  155. package/dist/core/RpcConfig.js +127 -0
  156. package/dist/core/RpcConfig.js.map +1 -0
  157. package/dist/core/SignatureCache.d.ts +81 -0
  158. package/dist/core/SignatureCache.d.ts.map +1 -0
  159. package/dist/core/SignatureCache.js +172 -0
  160. package/dist/core/SignatureCache.js.map +1 -0
  161. package/dist/core/StaticFileServer.d.ts +34 -0
  162. package/dist/core/StaticFileServer.d.ts.map +1 -0
  163. package/dist/core/StaticFileServer.js +497 -0
  164. package/dist/core/StaticFileServer.js.map +1 -0
  165. package/dist/core/Supervisor.d.ts +198 -0
  166. package/dist/core/Supervisor.d.ts.map +1 -0
  167. package/dist/core/Supervisor.js +1418 -0
  168. package/dist/core/Supervisor.js.map +1 -0
  169. package/dist/core/ThreadAllocator.d.ts +52 -0
  170. package/dist/core/ThreadAllocator.d.ts.map +1 -0
  171. package/dist/core/ThreadAllocator.js +174 -0
  172. package/dist/core/ThreadAllocator.js.map +1 -0
  173. package/dist/core/WorkerChannelManager.d.ts +130 -0
  174. package/dist/core/WorkerChannelManager.d.ts.map +1 -0
  175. package/dist/core/WorkerChannelManager.js +956 -0
  176. package/dist/core/WorkerChannelManager.js.map +1 -0
  177. package/dist/core/config-enums.d.ts +41 -0
  178. package/dist/core/config-enums.d.ts.map +1 -0
  179. package/dist/core/config-enums.js +59 -0
  180. package/dist/core/config-enums.js.map +1 -0
  181. package/dist/core/config.d.ts +159 -0
  182. package/dist/core/config.d.ts.map +1 -0
  183. package/dist/core/config.js +694 -0
  184. package/dist/core/config.js.map +1 -0
  185. package/dist/core/host-config.d.ts +146 -0
  186. package/dist/core/host-config.d.ts.map +1 -0
  187. package/dist/core/host-config.js +312 -0
  188. package/dist/core/host-config.js.map +1 -0
  189. package/dist/core/ipc-errors.d.ts +27 -0
  190. package/dist/core/ipc-errors.d.ts.map +1 -0
  191. package/dist/core/ipc-errors.js +36 -0
  192. package/dist/core/ipc-errors.js.map +1 -0
  193. package/dist/core/network-utils.d.ts +35 -0
  194. package/dist/core/network-utils.d.ts.map +1 -0
  195. package/dist/core/network-utils.js +145 -0
  196. package/dist/core/network-utils.js.map +1 -0
  197. package/dist/core/platform-config.d.ts +142 -0
  198. package/dist/core/platform-config.d.ts.map +1 -0
  199. package/dist/core/platform-config.js +299 -0
  200. package/dist/core/platform-config.js.map +1 -0
  201. package/dist/decorators/ServiceProxy.d.ts +175 -0
  202. package/dist/decorators/ServiceProxy.d.ts.map +1 -0
  203. package/dist/decorators/ServiceProxy.js +969 -0
  204. package/dist/decorators/ServiceProxy.js.map +1 -0
  205. package/dist/decorators/index.d.ts +146 -0
  206. package/dist/decorators/index.d.ts.map +1 -0
  207. package/dist/decorators/index.js +545 -0
  208. package/dist/decorators/index.js.map +1 -0
  209. package/dist/deploy/NginxGenerator.d.ts +165 -0
  210. package/dist/deploy/NginxGenerator.d.ts.map +1 -0
  211. package/dist/deploy/NginxGenerator.js +781 -0
  212. package/dist/deploy/NginxGenerator.js.map +1 -0
  213. package/dist/deploy/PlatformManifestGenerator.d.ts +43 -0
  214. package/dist/deploy/PlatformManifestGenerator.d.ts.map +1 -0
  215. package/dist/deploy/PlatformManifestGenerator.js +80 -0
  216. package/dist/deploy/PlatformManifestGenerator.js.map +1 -0
  217. package/dist/deploy/RouteManifestGenerator.d.ts +42 -0
  218. package/dist/deploy/RouteManifestGenerator.d.ts.map +1 -0
  219. package/dist/deploy/RouteManifestGenerator.js +105 -0
  220. package/dist/deploy/RouteManifestGenerator.js.map +1 -0
  221. package/dist/deploy/index.d.ts +210 -0
  222. package/dist/deploy/index.d.ts.map +1 -0
  223. package/dist/deploy/index.js +918 -0
  224. package/dist/deploy/index.js.map +1 -0
  225. package/dist/frontend/FrontendDevLifecycle.d.ts +26 -0
  226. package/dist/frontend/FrontendDevLifecycle.d.ts.map +1 -0
  227. package/dist/frontend/FrontendDevLifecycle.js +60 -0
  228. package/dist/frontend/FrontendDevLifecycle.js.map +1 -0
  229. package/dist/frontend/FrontendPluginOrchestrator.d.ts +64 -0
  230. package/dist/frontend/FrontendPluginOrchestrator.d.ts.map +1 -0
  231. package/dist/frontend/FrontendPluginOrchestrator.js +167 -0
  232. package/dist/frontend/FrontendPluginOrchestrator.js.map +1 -0
  233. package/dist/frontend/SiteResolver.d.ts +33 -0
  234. package/dist/frontend/SiteResolver.d.ts.map +1 -0
  235. package/dist/frontend/SiteResolver.js +53 -0
  236. package/dist/frontend/SiteResolver.js.map +1 -0
  237. package/dist/frontend/StaticMountRegistry.d.ts +36 -0
  238. package/dist/frontend/StaticMountRegistry.d.ts.map +1 -0
  239. package/dist/frontend/StaticMountRegistry.js +94 -0
  240. package/dist/frontend/StaticMountRegistry.js.map +1 -0
  241. package/dist/frontend/index.d.ts +7 -0
  242. package/dist/frontend/index.d.ts.map +1 -0
  243. package/{src → dist}/frontend/index.js +4 -2
  244. package/dist/frontend/index.js.map +1 -0
  245. package/dist/frontend/pathUtils.d.ts +8 -0
  246. package/dist/frontend/pathUtils.d.ts.map +1 -0
  247. package/dist/frontend/pathUtils.js +17 -0
  248. package/dist/frontend/pathUtils.js.map +1 -0
  249. package/dist/frontend/plugins/index.d.ts +2 -0
  250. package/dist/frontend/plugins/index.d.ts.map +1 -0
  251. package/{src → dist}/frontend/plugins/index.js +1 -1
  252. package/dist/frontend/plugins/index.js.map +1 -0
  253. package/dist/frontend/plugins/viteFrontend.d.ts +51 -0
  254. package/dist/frontend/plugins/viteFrontend.d.ts.map +1 -0
  255. package/dist/frontend/plugins/viteFrontend.js +134 -0
  256. package/dist/frontend/plugins/viteFrontend.js.map +1 -0
  257. package/dist/frontend/types.d.ts +25 -0
  258. package/dist/frontend/types.d.ts.map +1 -0
  259. package/dist/frontend/types.js +2 -0
  260. package/dist/frontend/types.js.map +1 -0
  261. package/dist/index.d.ts +17 -0
  262. package/dist/index.d.ts.map +1 -0
  263. package/dist/index.js +32 -0
  264. package/dist/index.js.map +1 -0
  265. package/dist/internals.d.ts +21 -0
  266. package/dist/internals.d.ts.map +1 -0
  267. package/{src → dist}/internals.js +12 -14
  268. package/dist/internals.js.map +1 -0
  269. package/dist/plugins/PluginManager.d.ts +209 -0
  270. package/dist/plugins/PluginManager.d.ts.map +1 -0
  271. package/dist/plugins/PluginManager.js +365 -0
  272. package/dist/plugins/PluginManager.js.map +1 -0
  273. package/dist/plugins/ScopedPostgres.d.ts +78 -0
  274. package/dist/plugins/ScopedPostgres.d.ts.map +1 -0
  275. package/dist/plugins/ScopedPostgres.js +190 -0
  276. package/dist/plugins/ScopedPostgres.js.map +1 -0
  277. package/dist/plugins/ScopedRedis.d.ts +88 -0
  278. package/dist/plugins/ScopedRedis.d.ts.map +1 -0
  279. package/dist/plugins/ScopedRedis.js +169 -0
  280. package/dist/plugins/ScopedRedis.js.map +1 -0
  281. package/dist/plugins/index.d.ts +289 -0
  282. package/dist/plugins/index.d.ts.map +1 -0
  283. package/dist/plugins/index.js +1942 -0
  284. package/dist/plugins/index.js.map +1 -0
  285. package/dist/plugins/types.d.ts +59 -0
  286. package/dist/plugins/types.d.ts.map +1 -0
  287. package/dist/plugins/types.js +2 -0
  288. package/dist/plugins/types.js.map +1 -0
  289. package/dist/registry/ServiceRegistry.d.ts +305 -0
  290. package/dist/registry/ServiceRegistry.d.ts.map +1 -0
  291. package/dist/registry/ServiceRegistry.js +735 -0
  292. package/dist/registry/ServiceRegistry.js.map +1 -0
  293. package/dist/scaling/ScaleAdvisor.d.ts +214 -0
  294. package/dist/scaling/ScaleAdvisor.d.ts.map +1 -0
  295. package/dist/scaling/ScaleAdvisor.js +526 -0
  296. package/dist/scaling/ScaleAdvisor.js.map +1 -0
  297. package/dist/services/Service.d.ts +164 -0
  298. package/dist/services/Service.d.ts.map +1 -0
  299. package/dist/services/Service.js +106 -0
  300. package/dist/services/Service.js.map +1 -0
  301. package/dist/services/worker-bootstrap.d.ts +15 -0
  302. package/dist/services/worker-bootstrap.d.ts.map +1 -0
  303. package/dist/services/worker-bootstrap.js +744 -0
  304. package/dist/services/worker-bootstrap.js.map +1 -0
  305. package/dist/templates/auth-service.d.ts +42 -0
  306. package/dist/templates/auth-service.d.ts.map +1 -0
  307. package/dist/templates/auth-service.js +54 -0
  308. package/dist/templates/auth-service.js.map +1 -0
  309. package/dist/templates/identity-service.d.ts +50 -0
  310. package/dist/templates/identity-service.d.ts.map +1 -0
  311. package/dist/templates/identity-service.js +62 -0
  312. package/dist/templates/identity-service.js.map +1 -0
  313. package/dist/types/contract.d.ts +120 -0
  314. package/dist/types/contract.d.ts.map +1 -0
  315. package/dist/types/contract.js +69 -0
  316. package/dist/types/contract.js.map +1 -0
  317. package/package.json +78 -20
  318. package/src/core/DirectMessageBus.js +0 -364
  319. package/src/core/EndpointResolver.js +0 -259
  320. package/src/core/ForgeContext.js +0 -2236
  321. package/src/core/ForgeHost.js +0 -122
  322. package/src/core/ForgePlatform.js +0 -145
  323. package/src/core/Ingress.js +0 -768
  324. package/src/core/Interceptors.js +0 -420
  325. package/src/core/MessageBus.js +0 -321
  326. package/src/core/Prometheus.js +0 -305
  327. package/src/core/RequestContext.js +0 -413
  328. package/src/core/RoutingStrategy.js +0 -330
  329. package/src/core/Supervisor.js +0 -1349
  330. package/src/core/ThreadAllocator.js +0 -196
  331. package/src/core/WorkerChannelManager.js +0 -879
  332. package/src/core/config.js +0 -637
  333. package/src/core/host-config.js +0 -311
  334. package/src/core/network-utils.js +0 -166
  335. package/src/core/platform-config.js +0 -308
  336. package/src/decorators/ServiceProxy.js +0 -904
  337. package/src/decorators/index.js +0 -571
  338. package/src/deploy/NginxGenerator.js +0 -865
  339. package/src/deploy/PlatformManifestGenerator.js +0 -96
  340. package/src/deploy/RouteManifestGenerator.js +0 -112
  341. package/src/deploy/index.js +0 -984
  342. package/src/frontend/FrontendDevLifecycle.js +0 -65
  343. package/src/frontend/FrontendPluginOrchestrator.js +0 -187
  344. package/src/frontend/SiteResolver.js +0 -63
  345. package/src/frontend/StaticMountRegistry.js +0 -90
  346. package/src/frontend/plugins/viteFrontend.js +0 -79
  347. package/src/frontend/types.js +0 -35
  348. package/src/index.js +0 -58
  349. package/src/plugins/PluginManager.js +0 -537
  350. package/src/plugins/ScopedPostgres.js +0 -192
  351. package/src/plugins/ScopedRedis.js +0 -142
  352. package/src/plugins/index.js +0 -1756
  353. package/src/registry/ServiceRegistry.js +0 -797
  354. package/src/scaling/ScaleAdvisor.js +0 -442
  355. package/src/services/Service.js +0 -195
  356. package/src/services/worker-bootstrap.js +0 -679
  357. package/src/templates/auth-service.js +0 -65
  358. package/src/templates/identity-service.js +0 -75
@@ -1,65 +0,0 @@
1
- /**
2
- * Bind frontend dev cleanup to process lifecycle events.
3
- *
4
- * Ensures dev plugin child processes are cleaned on:
5
- * - SIGTERM / SIGINT
6
- * - graceful process drain (`beforeExit`)
7
- * - final process exit (`exit`, best-effort)
8
- */
9
- export function bindFrontendDevCleanup(cleanupFn, options = {}) {
10
- if (typeof cleanupFn !== "function") {
11
- return {
12
- runCleanup: async () => {},
13
- dispose: () => {},
14
- };
15
- }
16
-
17
- const proc = options.processRef ?? process;
18
- const logger = options.logger ?? console;
19
- let finished = false;
20
-
21
- const runCleanup = async () => {
22
- if (finished) return;
23
- finished = true;
24
- try {
25
- await cleanupFn();
26
- } catch (err) {
27
- logger.warn?.(` [dev] Frontend cleanup failed: ${err.message}`);
28
- }
29
- };
30
-
31
- const trigger = () => {
32
- void runCleanup();
33
- };
34
-
35
- const bindings = [
36
- ["SIGTERM", trigger],
37
- ["SIGINT", trigger],
38
- ["beforeExit", trigger],
39
- ["exit", trigger],
40
- ];
41
-
42
- for (const [event, handler] of bindings) {
43
- proc.once(event, handler);
44
- }
45
-
46
- const dispose = () => {
47
- for (const [event, handler] of bindings) {
48
- proc.removeListener(event, handler);
49
- }
50
- };
51
-
52
- return { runCleanup, dispose };
53
- }
54
-
55
- export function wrapShutdownWithCleanup(supervisor, runCleanup) {
56
- if (!supervisor || typeof supervisor.shutdown !== "function" || typeof runCleanup !== "function") {
57
- return;
58
- }
59
- const originalShutdown = supervisor.shutdown.bind(supervisor);
60
- supervisor.shutdown = async (...args) => {
61
- await runCleanup();
62
- return originalShutdown(...args);
63
- };
64
- }
65
-
@@ -1,187 +0,0 @@
1
- /**
2
- * Frontend Plugin Orchestrator
3
- *
4
- * Handles frontend/tooling plugin registration and lifecycle. This is
5
- * intentionally separate from the service runtime PluginManager.
6
- */
7
-
8
- export const FRONTEND_PLUGIN_CAPABILITIES = Object.freeze([
9
- "frontend-build",
10
- "static-serve",
11
- "frontend-dev",
12
- ]);
13
-
14
- const CAPABILITY_SET = new Set(FRONTEND_PLUGIN_CAPABILITIES);
15
- const REQUIRED_METHODS = Object.freeze({
16
- "frontend-build": "buildSite",
17
- "static-serve": "staticMounts",
18
- "frontend-dev": "devSite",
19
- });
20
-
21
- function ensureFunction(plugin, key) {
22
- if (plugin[key] !== undefined && typeof plugin[key] !== "function") {
23
- throw new Error(`Frontend plugin "${plugin.name}": "${key}" must be a function when provided`);
24
- }
25
- }
26
-
27
- function normalizePlugin(plugin) {
28
- if (!plugin || typeof plugin !== "object" || Array.isArray(plugin)) {
29
- throw new Error("Frontend plugin must be an object");
30
- }
31
-
32
- if (typeof plugin.name !== "string" || plugin.name.trim() === "") {
33
- throw new Error("Frontend plugin must have a non-empty name");
34
- }
35
-
36
- if (!Array.isArray(plugin.capabilities) || plugin.capabilities.length === 0) {
37
- throw new Error(`Frontend plugin "${plugin.name}" must declare a non-empty capabilities array`);
38
- }
39
-
40
- const dedupedCapabilities = [...new Set(plugin.capabilities)];
41
- for (const capability of dedupedCapabilities) {
42
- if (!CAPABILITY_SET.has(capability)) {
43
- throw new Error(
44
- `Frontend plugin "${plugin.name}" has invalid capability "${capability}". Valid capabilities: ${FRONTEND_PLUGIN_CAPABILITIES.join(", ")}`,
45
- );
46
- }
47
-
48
- const requiredMethod = REQUIRED_METHODS[capability];
49
- if (typeof plugin[requiredMethod] !== "function") {
50
- throw new Error(
51
- `Frontend plugin "${plugin.name}" declares capability "${capability}" but is missing required method "${requiredMethod}()"`,
52
- );
53
- }
54
- }
55
-
56
- ensureFunction(plugin, "validate");
57
- ensureFunction(plugin, "register");
58
- ensureFunction(plugin, "dispose");
59
-
60
- return {
61
- ...plugin,
62
- capabilities: dedupedCapabilities,
63
- };
64
- }
65
-
66
- export class FrontendPluginOrchestrator {
67
- constructor(options = {}) {
68
- /** @type {Map<string, any>} */
69
- this.plugins = new Map();
70
- this._logger = options.logger ?? {
71
- info: (...args) => console.log("[FrontendPluginOrchestrator]", ...args),
72
- warn: (...args) => console.warn("[FrontendPluginOrchestrator]", ...args),
73
- error: (...args) => console.error("[FrontendPluginOrchestrator]", ...args),
74
- };
75
- }
76
-
77
- register(plugins) {
78
- if (!plugins || !Array.isArray(plugins)) return;
79
-
80
- for (const rawPlugin of plugins) {
81
- const plugin = normalizePlugin(rawPlugin);
82
- if (this.plugins.has(plugin.name)) {
83
- throw new Error(`Duplicate frontend plugin: "${plugin.name}"`);
84
- }
85
- this.plugins.set(plugin.name, plugin);
86
- }
87
- }
88
-
89
- get(name) {
90
- return this.plugins.get(name) ?? null;
91
- }
92
-
93
- has(name) {
94
- return this.plugins.has(name);
95
- }
96
-
97
- list() {
98
- return [...this.plugins.values()];
99
- }
100
-
101
- pluginsForCapability(capability) {
102
- if (!CAPABILITY_SET.has(capability)) {
103
- throw new Error(
104
- `Invalid frontend capability "${capability}". Valid capabilities: ${FRONTEND_PLUGIN_CAPABILITIES.join(", ")}`,
105
- );
106
- }
107
- return [...this.plugins.values()].filter((plugin) => plugin.capabilities.includes(capability));
108
- }
109
-
110
- async validateAll(ctx = {}) {
111
- for (const [name, plugin] of this.plugins) {
112
- if (!plugin.validate) continue;
113
- try {
114
- await plugin.validate(ctx);
115
- } catch (err) {
116
- throw new Error(`Frontend plugin "${name}" validation failed: ${err.message}`);
117
- }
118
- }
119
- }
120
-
121
- async registerAll(ctx = {}) {
122
- for (const [name, plugin] of this.plugins) {
123
- if (!plugin.register) continue;
124
- try {
125
- await plugin.register(ctx);
126
- } catch (err) {
127
- throw new Error(`Frontend plugin "${name}" register hook failed: ${err.message}`);
128
- }
129
- }
130
- }
131
-
132
- async disposeAll(ctx = {}) {
133
- const errors = [];
134
- const plugins = [...this.plugins.values()].reverse();
135
-
136
- for (const plugin of plugins) {
137
- if (!plugin.dispose) continue;
138
- try {
139
- await plugin.dispose(ctx);
140
- } catch (err) {
141
- errors.push({ name: plugin.name, error: err.message });
142
- this._logger.warn?.(`Frontend plugin "${plugin.name}" dispose failed: ${err.message}`);
143
- }
144
- }
145
-
146
- return errors;
147
- }
148
-
149
- resolvePluginForSite(site) {
150
- const pluginName = site?.frontend?.plugin;
151
- if (!pluginName) return null;
152
-
153
- const plugin = this.get(pluginName);
154
- if (!plugin) {
155
- throw new Error(`Site "${site.siteId ?? "unknown"}" references unknown frontend plugin "${pluginName}"`);
156
- }
157
- return plugin;
158
- }
159
-
160
- async buildSite(site, ctx = {}) {
161
- if (!site?.frontend) return null;
162
- const plugin = this.resolvePluginForSite(site);
163
- if (!plugin.capabilities.includes("frontend-build")) {
164
- throw new Error(`Frontend plugin "${plugin.name}" does not support "frontend-build"`);
165
- }
166
- return plugin.buildSite(ctx, site);
167
- }
168
-
169
- async staticMounts(site, ctx = {}) {
170
- if (!site?.frontend) return [];
171
- const plugin = this.resolvePluginForSite(site);
172
- if (!plugin.capabilities.includes("static-serve")) {
173
- return [];
174
- }
175
- return plugin.staticMounts(ctx, site);
176
- }
177
-
178
- async devSite(site, ctx = {}) {
179
- if (!site?.frontend) return null;
180
- const plugin = this.resolvePluginForSite(site);
181
- if (!plugin.capabilities.includes("frontend-dev")) {
182
- throw new Error(`Frontend plugin "${plugin.name}" does not support "frontend-dev"`);
183
- }
184
- return plugin.devSite(ctx, site);
185
- }
186
- }
187
-
@@ -1,63 +0,0 @@
1
- function normalizeBasePath(basePath = "/") {
2
- if (!basePath || basePath === "/") return "/";
3
- let normalized = String(basePath).trim();
4
- if (!normalized.startsWith("/")) normalized = `/${normalized}`;
5
- if (normalized.length > 1 && normalized.endsWith("/")) normalized = normalized.slice(0, -1);
6
- return normalized;
7
- }
8
-
9
- export function resolveSitesMap(config) {
10
- if (!config || typeof config !== "object" || Array.isArray(config)) {
11
- return {};
12
- }
13
-
14
- const sites = config._sites ?? config.sites ?? null;
15
- if (sites && typeof sites === "object" && !Array.isArray(sites)) {
16
- return sites;
17
- }
18
-
19
- // Allow passing a raw site map directly.
20
- const values = Object.values(config);
21
- const isLikelySiteMap = values.length > 0 && values.every((value) =>
22
- value &&
23
- typeof value === "object" &&
24
- !Array.isArray(value) &&
25
- (
26
- Array.isArray(value.services) ||
27
- Array.isArray(value.domains) ||
28
- value.frontend !== undefined ||
29
- value.staticDir !== undefined
30
- )
31
- );
32
-
33
- return isLikelySiteMap ? config : {};
34
- }
35
-
36
- export function resolveFrontendSites(config) {
37
- return Object.values(resolveSitesMap(config)).filter((site) => site?.frontend);
38
- }
39
-
40
- export function resolveStaticMountsForService(serviceName, sitesConfig) {
41
- if (!serviceName || typeof serviceName !== "string") return [];
42
- const sites = resolveSitesMap(sitesConfig);
43
- const mounts = [];
44
-
45
- for (const site of Object.values(sites)) {
46
- if (!site?.services?.includes(serviceName)) continue;
47
-
48
- const frontend = site.frontend ?? null;
49
- const dir = frontend?.outDir ?? site.staticDir;
50
- if (!dir) continue;
51
-
52
- mounts.push({
53
- siteId: site.siteId ?? null,
54
- domains: Array.isArray(site.domains) ? site.domains : [],
55
- basePath: normalizeBasePath(frontend?.basePath ?? site.basePath ?? "/"),
56
- dir,
57
- spaFallback: frontend?.spaFallback ?? false,
58
- cachePolicy: "short",
59
- });
60
- }
61
-
62
- return mounts;
63
- }
@@ -1,90 +0,0 @@
1
- /**
2
- * Static Mount Registry
3
- *
4
- * Resolves incoming host/path tuples to static mount descriptors.
5
- */
6
-
7
- function normalizeBasePath(basePath) {
8
- if (!basePath || basePath === "/") return "/";
9
- let value = basePath.trim();
10
- if (!value.startsWith("/")) value = `/${value}`;
11
- if (value.length > 1 && value.endsWith("/")) value = value.slice(0, -1);
12
- return value;
13
- }
14
-
15
- function normalizeDomains(domains) {
16
- if (!Array.isArray(domains)) return [];
17
- return [...new Set(domains.filter((d) => typeof d === "string" && d.trim() !== "").map((d) => d.toLowerCase()))];
18
- }
19
-
20
- function matchBasePath(pathname, basePath) {
21
- if (basePath === "/") return true;
22
- return pathname === basePath || pathname.startsWith(`${basePath}/`);
23
- }
24
-
25
- function relativeFromBase(pathname, basePath) {
26
- if (basePath === "/") return pathname;
27
- const relative = pathname.slice(basePath.length);
28
- return relative === "" ? "/" : relative;
29
- }
30
-
31
- export class StaticMountRegistry {
32
- constructor(mounts = []) {
33
- this._mounts = [];
34
- this.setMounts(mounts);
35
- }
36
-
37
- setMounts(mounts = []) {
38
- if (!Array.isArray(mounts)) {
39
- throw new Error("Static mounts must be an array");
40
- }
41
-
42
- const normalized = mounts.map((mount) => {
43
- if (!mount || typeof mount !== "object" || Array.isArray(mount)) {
44
- throw new Error("Each static mount must be an object");
45
- }
46
- if (typeof mount.dir !== "string" || mount.dir.trim() === "") {
47
- throw new Error("Each static mount must have a non-empty dir");
48
- }
49
-
50
- return {
51
- siteId: mount.siteId ?? null,
52
- domains: normalizeDomains(mount.domains),
53
- basePath: normalizeBasePath(mount.basePath),
54
- dir: mount.dir,
55
- spaFallback: Boolean(mount.spaFallback),
56
- cachePolicy: mount.cachePolicy ?? "short",
57
- };
58
- });
59
-
60
- // Prefer exact-domain mounts over wildcard mounts, then longest base path.
61
- normalized.sort((a, b) => {
62
- const domainWeight = (b.domains.length > 0 ? 1 : 0) - (a.domains.length > 0 ? 1 : 0);
63
- if (domainWeight !== 0) return domainWeight;
64
- return b.basePath.length - a.basePath.length;
65
- });
66
-
67
- this._mounts = normalized;
68
- }
69
-
70
- list() {
71
- return this._mounts;
72
- }
73
-
74
- resolve(host, pathname) {
75
- const normalizedHost = typeof host === "string" ? host.toLowerCase() : "";
76
-
77
- for (const mount of this._mounts) {
78
- if (mount.domains.length > 0 && !mount.domains.includes(normalizedHost)) continue;
79
- if (!matchBasePath(pathname, mount.basePath)) continue;
80
-
81
- return {
82
- ...mount,
83
- relativePath: relativeFromBase(pathname, mount.basePath),
84
- };
85
- }
86
-
87
- return null;
88
- }
89
- }
90
-
@@ -1,79 +0,0 @@
1
- import path from "node:path";
2
- import { spawn } from "node:child_process";
3
-
4
- function defaultRunCommand(command, options = {}) {
5
- return new Promise((resolve, reject) => {
6
- const child = spawn(command, {
7
- cwd: options.cwd,
8
- env: options.env,
9
- shell: true,
10
- stdio: "inherit",
11
- });
12
-
13
- child.on("error", reject);
14
- child.on("close", (code) => {
15
- if (code === 0) {
16
- resolve();
17
- } else {
18
- reject(new Error(`Command failed (${code}): ${command}`));
19
- }
20
- });
21
- });
22
- }
23
-
24
- /**
25
- * Reference frontend plugin for Vite-based apps.
26
- *
27
- * It intentionally shells out to project scripts (build/dev) instead of
28
- * linking to Vite APIs directly, which keeps the core runtime dependency-free.
29
- */
30
- export function viteFrontend(options = {}) {
31
- const name = options.name ?? "vite";
32
- const buildCommand = options.buildCommand ?? "npm run build";
33
- const runCommand = options.runCommand ?? defaultRunCommand;
34
-
35
- return {
36
- name,
37
- capabilities: ["frontend-build", "static-serve"],
38
- validate() {
39
- if (typeof buildCommand !== "string" || buildCommand.trim() === "") {
40
- throw new Error(`Frontend plugin "${name}": buildCommand must be a non-empty string`);
41
- }
42
- if (typeof runCommand !== "function") {
43
- throw new Error(`Frontend plugin "${name}": runCommand must be a function`);
44
- }
45
- },
46
- async buildSite(_ctx, site) {
47
- if (!site?.frontend) {
48
- throw new Error(`Frontend plugin "${name}": buildSite requires a site.frontend config`);
49
- }
50
-
51
- const root = path.resolve(site.frontend.root);
52
- const outDir = path.resolve(site.frontend.outDir);
53
- const env = {
54
- ...process.env,
55
- ...site.frontend.env,
56
- };
57
-
58
- await runCommand(buildCommand, { cwd: root, env });
59
-
60
- return {
61
- siteId: site.siteId,
62
- outDir,
63
- };
64
- },
65
- async staticMounts(_ctx, site) {
66
- if (!site?.frontend) return [];
67
- return [
68
- {
69
- siteId: site.siteId,
70
- domains: site.domains ?? [],
71
- basePath: site.frontend.basePath ?? "/",
72
- dir: site.frontend.outDir,
73
- spaFallback: site.frontend.spaFallback ?? true,
74
- cachePolicy: "short",
75
- },
76
- ];
77
- },
78
- };
79
- }
@@ -1,35 +0,0 @@
1
- /**
2
- * @typedef {"frontend-build" | "static-serve" | "frontend-dev"} FrontendPluginCapability
3
- */
4
-
5
- /**
6
- * @typedef {Object} FrontendSiteDefinition
7
- * @property {string} siteId
8
- * @property {string[]} domains
9
- * @property {string} basePath
10
- * @property {string[]} services
11
- * @property {Object | null} [frontend]
12
- * @property {string | null} [staticDir]
13
- */
14
-
15
- /**
16
- * @typedef {Object} FrontendBuildResult
17
- * @property {string} siteId
18
- * @property {string} outDir
19
- * @property {string} [manifestPath]
20
- * @property {string} [assetsHash]
21
- * @property {string[]} [warnings]
22
- */
23
-
24
- /**
25
- * @typedef {Object} FrontendStaticMount
26
- * @property {string | null} siteId
27
- * @property {string[]} domains
28
- * @property {string} basePath
29
- * @property {string} dir
30
- * @property {boolean} [spaFallback]
31
- * @property {"immutable" | "short" | "none"} [cachePolicy]
32
- */
33
-
34
- export {};
35
-
package/src/index.js DELETED
@@ -1,58 +0,0 @@
1
- // ThreadForge - Multi-threaded Node.js Service Runtime
2
- // Public API
3
- //
4
- // D8: Core exports only. Internal plumbing is available via 'threadforge/internals'
5
- // (src/internals.js) for advanced use cases.
6
-
7
- // Core
8
- export { defineServices } from "./core/config.js";
9
- export { defineHost } from "./core/host-config.js";
10
- export { definePlatform } from "./core/platform-config.js";
11
- export { ForgeContext } from "./core/ForgeContext.js";
12
- export { RequestContext } from "./core/RequestContext.js";
13
-
14
- // Interceptors
15
- export {
16
- CircuitBreaker,
17
- deadlineInterceptor,
18
- isRetryable,
19
- loggingInterceptor,
20
- metricsInterceptor,
21
- retryInterceptor,
22
- runInterceptorChain,
23
- } from "./core/Interceptors.js";
24
-
25
- // Routing
26
- export {
27
- BroadcastStrategy,
28
- createStrategy,
29
- HashStrategy,
30
- LeastPendingStrategy,
31
- PrimaryStrategy,
32
- RoundRobinStrategy,
33
- } from "./core/RoutingStrategy.js";
34
-
35
- // Decorators
36
- export {
37
- Auth,
38
- Emit,
39
- Expose,
40
- getContract,
41
- Internal,
42
- On,
43
- Prefix,
44
- RateLimit,
45
- Route,
46
- Validate,
47
- } from "./decorators/index.js";
48
-
49
- // Plugins
50
- export { PluginManager } from "./plugins/PluginManager.js";
51
- export { cors, cron, postgres, realtime, redis, s3 } from "./plugins/index.js";
52
- export { viteFrontend } from "./frontend/plugins/viteFrontend.js";
53
-
54
- // Services
55
- export { Service } from "./services/Service.js";
56
-
57
- // Internal plumbing is available via 'threadforge/internals' for advanced use cases.
58
- // See src/internals.js for the full list of internal exports.