@ecopages/core 0.2.0-rc.8 → 0.2.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 (216) hide show
  1. package/README.md +39 -38
  2. package/package.json +22 -152
  3. package/src/adapters/README.md +11 -3
  4. package/src/adapters/abstract/application-adapter.d.ts +32 -36
  5. package/src/adapters/abstract/application-adapter.js +61 -47
  6. package/src/adapters/abstract/server-adapter.d.ts +14 -0
  7. package/src/adapters/abstract/server-adapter.js +10 -0
  8. package/src/adapters/abstract/ws-pattern-matcher.d.ts +0 -5
  9. package/src/adapters/abstract/ws-pattern-matcher.js +0 -9
  10. package/src/adapters/bun/create-app.d.ts +12 -16
  11. package/src/adapters/bun/create-app.js +25 -55
  12. package/src/adapters/bun/hmr-manager.d.ts +0 -1
  13. package/src/adapters/bun/hmr-manager.js +2 -4
  14. package/src/adapters/bun/server-adapter.d.ts +15 -21
  15. package/src/adapters/bun/server-adapter.js +33 -67
  16. package/src/adapters/bun/static-preview-host.d.ts +1 -0
  17. package/src/adapters/bun/static-preview-host.js +1 -1
  18. package/src/adapters/create-app.d.ts +63 -8
  19. package/src/adapters/create-app.js +62 -5
  20. package/src/adapters/node/create-app.d.ts +8 -12
  21. package/src/adapters/node/create-app.js +22 -14
  22. package/src/adapters/node/runtime-host.d.ts +10 -10
  23. package/src/adapters/node/runtime-host.js +13 -8
  24. package/src/adapters/node/server-adapter-dependencies.d.ts +2 -10
  25. package/src/adapters/node/server-adapter-dependencies.js +8 -13
  26. package/src/adapters/node/server-adapter.d.ts +30 -32
  27. package/src/adapters/node/server-adapter.js +59 -65
  28. package/src/adapters/shared/hmr/shared-hmr-manager.d.ts +0 -4
  29. package/src/adapters/shared/hmr/shared-hmr-manager.js +0 -12
  30. package/src/adapters/shared/http/api-request-pipeline.d.ts +27 -1
  31. package/src/adapters/shared/http/api-request-pipeline.js +31 -16
  32. package/src/adapters/shared/http/explicit-static-route-matcher.js +5 -2
  33. package/src/adapters/shared/http/fs-server-response-factory.d.ts +2 -9
  34. package/src/adapters/shared/http/fs-server-response-factory.js +5 -33
  35. package/src/adapters/shared/http/fs-server-response-matcher.d.ts +24 -24
  36. package/src/adapters/shared/http/fs-server-response-matcher.js +59 -83
  37. package/src/adapters/shared/runtime/application-adapter.d.ts +1 -0
  38. package/src/adapters/shared/runtime/application-adapter.js +12 -0
  39. package/src/adapters/shared/runtime/bind-runtime-server.d.ts +17 -0
  40. package/src/adapters/shared/runtime/bind-runtime-server.js +50 -0
  41. package/src/adapters/shared/runtime/collect-dev-prewarm-plan.d.ts +1 -3
  42. package/src/adapters/shared/runtime/collect-dev-prewarm-plan.js +1 -4
  43. package/src/adapters/shared/runtime/port-manager-default-prompt.d.ts +6 -0
  44. package/src/adapters/shared/runtime/port-manager-default-prompt.js +41 -0
  45. package/src/adapters/shared/runtime/port-manager.d.ts +3 -3
  46. package/src/adapters/shared/runtime/port-manager.js +14 -45
  47. package/src/adapters/shared/runtime/runtime-app-bootstrap.d.ts +0 -10
  48. package/src/adapters/shared/runtime/runtime-app-bootstrap.js +0 -7
  49. package/src/adapters/shared/runtime/runtime-host.d.ts +5 -2
  50. package/src/adapters/shared/runtime/runtime-server-lifecycle.d.ts +1 -1
  51. package/src/adapters/shared/runtime/runtime-server-lifecycle.js +1 -1
  52. package/src/adapters/shared/runtime/server-adapter.d.ts +26 -5
  53. package/src/adapters/shared/runtime/server-adapter.js +35 -8
  54. package/src/adapters/shared/runtime/server-route-handler.js +11 -3
  55. package/src/adapters/shared/runtime/server-static-builder.d.ts +9 -3
  56. package/src/adapters/shared/runtime/server-static-builder.js +59 -37
  57. package/src/adapters/shared/ws/node-http-websocket-upgrades.d.ts +9 -1
  58. package/src/adapters/shared/ws/node-http-websocket-upgrades.js +8 -2
  59. package/src/build/README.md +12 -8
  60. package/src/build/cache/cache-constants.d.ts +0 -2
  61. package/src/build/cache/cache-constants.js +0 -2
  62. package/src/build/cache/cache-keys.d.ts +0 -2
  63. package/src/build/cache/cache-keys.js +0 -2
  64. package/src/build/cache/output-imports.d.ts +35 -0
  65. package/src/build/cache/output-imports.js +87 -0
  66. package/src/build/cache/pages-unified-graph-build.d.ts +15 -1
  67. package/src/build/cache/pages-unified-graph-build.js +73 -22
  68. package/src/build/cache/production-build-cache.d.ts +2 -2
  69. package/src/build/cache/production-build-cache.js +2 -2
  70. package/src/build/cache/server-entry-build-cache.d.ts +25 -3
  71. package/src/build/cache/server-entry-build-cache.js +129 -13
  72. package/src/build/contracts/build-contracts.d.ts +1 -13
  73. package/src/build/rolldown/runtime-build-output-normalizer.js +3 -6
  74. package/src/build/runtime/build-request-identity.d.ts +2 -6
  75. package/src/build/runtime/build-request-identity.js +2 -8
  76. package/src/build/runtime/build-request-policy.js +1 -1
  77. package/src/build/runtime/deduping-build-executor.d.ts +0 -1
  78. package/src/build/runtime/deduping-build-executor.js +0 -1
  79. package/src/build/server-bundle-publication.d.ts +14 -0
  80. package/src/build/server-bundle-publication.js +49 -0
  81. package/src/cache/index.d.ts +1 -1
  82. package/src/cache/index.js +1 -1
  83. package/src/cache/module-parse-cache.d.ts +2 -29
  84. package/src/cache/module-parse-cache.js +6 -39
  85. package/src/config/README.md +17 -2
  86. package/src/config/apply-user-config.d.ts +8 -0
  87. package/src/config/apply-user-config.js +68 -0
  88. package/src/config/config-builder.d.ts +11 -1
  89. package/src/config/config-builder.js +53 -12
  90. package/src/config/constants.d.ts +4 -4
  91. package/src/config/constants.js +4 -4
  92. package/src/config/define-config.d.ts +9 -0
  93. package/src/config/define-config.js +10 -0
  94. package/src/config/index.d.ts +5 -0
  95. package/src/config/index.js +4 -0
  96. package/src/config/is-finalized-app-config.d.ts +6 -0
  97. package/src/config/is-finalized-app-config.js +11 -0
  98. package/src/config/load-eco-config.d.ts +21 -0
  99. package/src/config/load-eco-config.js +107 -0
  100. package/src/config/resolve-eco-config-path.d.ts +32 -0
  101. package/src/config/resolve-eco-config-path.js +58 -0
  102. package/src/config/server-config-bundle.d.ts +25 -0
  103. package/src/config/server-config-bundle.js +148 -0
  104. package/src/config/user-config-types.d.ts +170 -0
  105. package/src/config/user-config-types.js +1 -0
  106. package/src/dev/README.md +4 -0
  107. package/src/dev/development-restart-watch-paths.d.ts +13 -0
  108. package/src/dev/development-restart-watch-paths.js +37 -0
  109. package/src/dev/development-restart.d.ts +13 -0
  110. package/src/dev/development-restart.js +21 -0
  111. package/src/dev/host-runtime.d.ts +0 -1
  112. package/src/dev/host-runtime.js +0 -3
  113. package/src/dev/sc-server.d.ts +4 -1
  114. package/src/dev/sc-server.js +11 -20
  115. package/src/dev/transform-server/dev-transform-import-rewriter.js +2 -2
  116. package/src/eco/eco.js +4 -0
  117. package/src/errors/http-error-page-contract.d.ts +77 -0
  118. package/src/errors/http-error-page-contract.js +106 -0
  119. package/src/hmr/hmr-file-change-prep.d.ts +0 -1
  120. package/src/hmr/hmr-file-change-prep.js +2 -5
  121. package/src/hmr/hmr-strategy.d.ts +3 -8
  122. package/src/hmr/hmr-strategy.js +3 -8
  123. package/src/index.browser.d.ts +1 -2
  124. package/src/index.browser.js +1 -2
  125. package/src/index.d.ts +5 -6
  126. package/src/index.js +5 -6
  127. package/src/islands/island-host.d.ts +0 -9
  128. package/src/islands/island-host.js +1 -13
  129. package/src/plugins/component-import-discovery.js +2 -2
  130. package/src/plugins/eco-component-meta-plugin.js +5 -5
  131. package/src/plugins/integration-plugin.d.ts +0 -1
  132. package/src/plugins/integration-plugin.js +0 -4
  133. package/src/plugins/processor.d.ts +6 -2
  134. package/src/route-renderer/README.md +4 -0
  135. package/src/{adapters/shared/http/explicit-static-render-preparation.d.ts → route-renderer/explicit-view-render-preparation.d.ts} +3 -3
  136. package/src/route-renderer/orchestration/custom-element-scripts/README.md +2 -2
  137. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.d.ts +14 -2
  138. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js +12 -5
  139. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.d.ts +8 -0
  140. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.js +19 -0
  141. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +1 -4
  142. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +25 -24
  143. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +18 -20
  144. package/src/route-renderer/orchestration/integration-renderer.d.ts +24 -7
  145. package/src/route-renderer/orchestration/integration-renderer.js +44 -33
  146. package/src/route-renderer/orchestration/integration-renderer.test-fixtures.js +1 -1
  147. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.d.ts +1 -1
  148. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.js +1 -1
  149. package/src/route-renderer/route-renderer.d.ts +9 -0
  150. package/src/route-renderer/route-renderer.js +18 -0
  151. package/src/services/README.md +2 -1
  152. package/src/services/assets/browser-bundle.service.d.ts +1 -6
  153. package/src/services/error-pages/README.md +9 -0
  154. package/src/services/error-pages/default-error-pages.d.ts +39 -0
  155. package/src/services/error-pages/default-error-pages.js +199 -0
  156. package/src/services/error-pages/error-page-renderer.d.ts +58 -0
  157. package/src/services/error-pages/error-page-renderer.js +146 -0
  158. package/src/services/error-pages/semantic-error-page-exporter.d.ts +23 -0
  159. package/src/services/error-pages/semantic-error-page-exporter.js +35 -0
  160. package/src/services/html/html-rewriter.d.ts +77 -0
  161. package/src/services/html/html-rewriter.js +751 -0
  162. package/src/services/html/html-rewriter.parity.test.bun.d.ts +1 -0
  163. package/src/services/html/html-rewriter.parity.test.bun.js +74 -0
  164. package/src/services/html/html-transformer.service.d.ts +29 -42
  165. package/src/services/html/html-transformer.service.js +85 -157
  166. package/src/services/invalidation/development-invalidation.service.d.ts +9 -20
  167. package/src/services/invalidation/development-invalidation.service.js +26 -39
  168. package/src/services/module-loading/README.md +20 -15
  169. package/src/services/module-loading/app-module-loader.service.d.ts +0 -2
  170. package/src/services/module-loading/app-server-module-transpiler.service.d.ts +1 -1
  171. package/src/services/module-loading/app-server-module-transpiler.service.js +2 -10
  172. package/src/services/module-loading/collection-server-module-build.service.d.ts +0 -1
  173. package/src/services/module-loading/collection-server-module-build.service.js +0 -3
  174. package/src/services/module-loading/host-module-loader-registry.d.ts +0 -1
  175. package/src/services/module-loading/host-module-loader-registry.js +0 -3
  176. package/src/services/module-loading/route-module-build-cache-registry.d.ts +0 -4
  177. package/src/services/module-loading/route-module-build-cache-registry.js +0 -4
  178. package/src/services/module-loading/route-module-build-cache.store.d.ts +8 -0
  179. package/src/services/module-loading/route-module-build-cache.store.js +25 -7
  180. package/src/services/module-loading/route-module-build-manifest.d.ts +12 -1
  181. package/src/services/module-loading/route-module-build-manifest.js +7 -3
  182. package/src/services/module-loading/route-module-dependency-hasher.d.ts +3 -2
  183. package/src/services/module-loading/route-module-dependency-hasher.js +13 -1
  184. package/src/services/module-loading/server-module-transpiler.service.d.ts +1 -15
  185. package/src/services/module-loading/server-module-transpiler.service.js +0 -24
  186. package/src/services/module-loading/view-module-loader.d.ts +10 -0
  187. package/src/services/module-loading/view-module-loader.js +46 -0
  188. package/src/services/runtime-state/entrypoint-dependency-graph.service.js +0 -12
  189. package/src/services/runtime-state/server-invalidation-state.service.d.ts +4 -2
  190. package/src/services/runtime-state/server-invalidation-state.service.js +7 -14
  191. package/src/static-site-generator/README.md +12 -8
  192. package/src/static-site-generator/static-site-generator.d.ts +3 -2
  193. package/src/static-site-generator/static-site-generator.js +17 -3
  194. package/src/types/internal-types.d.ts +1 -38
  195. package/src/types/public-types.d.ts +28 -130
  196. package/src/watchers/project-watcher.d.ts +9 -16
  197. package/src/watchers/project-watcher.js +35 -28
  198. package/src/watchers/project-watcher.test-helpers.d.ts +10 -1
  199. package/src/watchers/project-watcher.test-helpers.js +12 -0
  200. package/src/adapters/abstract/router-adapter.d.ts +0 -26
  201. package/src/adapters/abstract/router-adapter.js +0 -13
  202. package/src/adapters/bun/index.d.ts +0 -2
  203. package/src/adapters/bun/index.js +0 -2
  204. package/src/adapters/index.d.ts +0 -2
  205. package/src/adapters/index.js +0 -2
  206. package/src/eco/eco.utils.d.ts +0 -1
  207. package/src/eco/eco.utils.js +0 -1
  208. package/src/services/cache/index.d.ts +0 -9
  209. package/src/services/cache/index.js +0 -8
  210. package/src/services/html/html-rewriter-provider.service.d.ts +0 -40
  211. package/src/services/html/html-rewriter-provider.service.js +0 -68
  212. package/src/services/module-loading/route-module-build-cache.d.ts +0 -4
  213. package/src/services/module-loading/route-module-build-cache.js +0 -3
  214. package/src/services/runtime-state/dev-graph.service.d.ts +0 -118
  215. package/src/services/runtime-state/dev-graph.service.js +0 -170
  216. /package/src/{adapters/shared/http/explicit-static-render-preparation.js → route-renderer/explicit-view-render-preparation.js} +0 -0
@@ -2,6 +2,11 @@ import { createServer, type Server as NodeServerInstance } from 'node:http';
2
2
  import type { RuntimeHost, RuntimeHostStartOptions } from '../shared/runtime/runtime-host.js';
3
3
  import { NodeHttpRequestBridge } from './http-request-bridge.js';
4
4
  type NodeServerFactory = typeof createServer;
5
+ export type NodeRuntimeServeOptions = {
6
+ port?: number;
7
+ hostname?: string;
8
+ handleRequest(request: Request): Promise<Response>;
9
+ };
5
10
  /**
6
11
  * Node runtime host that binds the shared Web-request pipeline onto a concrete
7
12
  * Node HTTP server.
@@ -11,10 +16,7 @@ type NodeServerFactory = typeof createServer;
11
16
  * requests through `NodeHttpRequestBridge`, and handling socket-level failures.
12
17
  * Routing and rendering remain in the shared server adapter.
13
18
  */
14
- export declare class NodeRuntimeHost implements RuntimeHost<NodeServerInstance, {
15
- port?: number;
16
- hostname?: string;
17
- }> {
19
+ export declare class NodeRuntimeHost implements RuntimeHost<NodeServerInstance, NodeRuntimeServeOptions> {
18
20
  private readonly requestBridge;
19
21
  private readonly serverFactory;
20
22
  /**
@@ -27,13 +29,11 @@ export declare class NodeRuntimeHost implements RuntimeHost<NodeServerInstance,
27
29
  * request pipeline.
28
30
  *
29
31
  * @remarks
30
- * Client disconnects are treated as normal aborts and do not trigger adapter
31
- * error logging or the runtime host's `onError` callback.
32
+ * Client disconnects are treated as normal aborts and are not logged. Other
33
+ * failures here (the response write, or an uninitialised adapter) are logged
34
+ * with their stack and answered with 500.
32
35
  */
33
- start(options: RuntimeHostStartOptions<{
34
- port?: number;
35
- hostname?: string;
36
- }>): Promise<NodeServerInstance>;
36
+ start(options: RuntimeHostStartOptions<NodeRuntimeServeOptions>): Promise<NodeServerInstance>;
37
37
  /**
38
38
  * Stops the Node HTTP server and, by default, force-closes any remaining open
39
39
  * connections.
@@ -28,17 +28,19 @@ export class NodeRuntimeHost {
28
28
  * request pipeline.
29
29
  *
30
30
  * @remarks
31
- * Client disconnects are treated as normal aborts and do not trigger adapter
32
- * error logging or the runtime host's `onError` callback.
31
+ * Client disconnects are treated as normal aborts and are not logged. Other
32
+ * failures here (the response write, or an uninitialised adapter) are logged
33
+ * with their stack and answered with 500.
33
34
  */
34
35
  async start(options) {
35
36
  const hostname = String(options.serveOptions.hostname ?? DEFAULT_ECOPAGES_HOSTNAME);
36
37
  const port = Number(options.serveOptions.port ?? DEFAULT_ECOPAGES_PORT);
37
- const runtimeOrigin = resolveServeRuntimeOrigin({ hostname, port });
38
- const server = this.serverFactory(async (req, res) => {
38
+ let server;
39
+ server = this.serverFactory(async (req, res) => {
39
40
  try {
41
+ const runtimeOrigin = this.getOrigin(server, options.serveOptions);
40
42
  const webRequest = this.requestBridge.createWebRequest(req, runtimeOrigin);
41
- const response = await options.handleRequest(webRequest);
43
+ const response = await options.serveOptions.handleRequest(webRequest);
42
44
  await this.requestBridge.sendNodeResponse(res, response);
43
45
  }
44
46
  catch (error) {
@@ -48,11 +50,14 @@ export class NodeRuntimeHost {
48
50
  appLogger.error('Node server adapter request failed', error);
49
51
  res.statusCode = 500;
50
52
  res.end('Internal Server Error');
51
- await options.onError(error instanceof Error ? error : new Error(String(error)));
52
53
  }
53
54
  });
54
- await new Promise((resolve) => {
55
- server.listen(port, hostname, () => resolve());
55
+ await new Promise((resolve, reject) => {
56
+ server.once('error', reject);
57
+ server.listen(port, hostname, () => {
58
+ server.off('error', reject);
59
+ resolve();
60
+ });
56
61
  });
57
62
  return server;
58
63
  }
@@ -7,13 +7,5 @@ export interface NodeServerDevRuntime {
7
7
  bridge: NodeClientBridge;
8
8
  hmrManager: NodeHmrManager;
9
9
  }
10
- export interface NodeServerDevRuntimeFactory {
11
- create(options: {
12
- appConfig: EcoPagesAppConfig;
13
- }): NodeServerDevRuntime;
14
- }
15
- export declare class DefaultNodeServerDevRuntimeFactory implements NodeServerDevRuntimeFactory {
16
- create(options: {
17
- appConfig: EcoPagesAppConfig;
18
- }): NodeServerDevRuntime;
19
- }
10
+ /** Creates the dev WebSocket server, client bridge and HMR manager, and registers them for `appConfig`. */
11
+ export declare function createNodeServerDevRuntime(appConfig: EcoPagesAppConfig): NodeServerDevRuntime;
@@ -3,17 +3,12 @@ import { setAppDevClientBridge } from '../../dev/client-bridge-registry.js';
3
3
  import { setAppHmrManager } from '../../dev/hmr-manager-registry.js';
4
4
  import { NodeClientBridge } from './node-client-bridge.js';
5
5
  import { NodeHmrManager } from './node-hmr-manager.js';
6
- export class DefaultNodeServerDevRuntimeFactory {
7
- create(options) {
8
- const websocketServer = new WebSocketServer({ noServer: true });
9
- const bridge = new NodeClientBridge();
10
- const hmrManager = new NodeHmrManager({ appConfig: options.appConfig, bridge });
11
- setAppDevClientBridge(options.appConfig, bridge);
12
- setAppHmrManager(options.appConfig, hmrManager);
13
- return {
14
- websocketServer,
15
- bridge,
16
- hmrManager,
17
- };
18
- }
6
+ /** Creates the dev WebSocket server, client bridge and HMR manager, and registers them for `appConfig`. */
7
+ export function createNodeServerDevRuntime(appConfig) {
8
+ const websocketServer = new WebSocketServer({ noServer: true });
9
+ const bridge = new NodeClientBridge();
10
+ const hmrManager = new NodeHmrManager({ appConfig, bridge });
11
+ setAppDevClientBridge(appConfig, bridge);
12
+ setAppHmrManager(appConfig, hmrManager);
13
+ return { websocketServer, bridge, hmrManager };
19
14
  }
@@ -1,11 +1,10 @@
1
1
  import { type Server as NodeHttpServer } from 'node:http';
2
2
  import type { EcoPagesAppConfig } from '../../types/internal-types.js';
3
- import type { ApiHandler, ErrorHandler, StaticRoute, EcopagesWebSocketHandler } from '../../types/public-types.js';
3
+ import type { ApiHandler, ErrorHandler, StaticRoute, ErrorPageLoaders, EcopagesWebSocketHandler } from '../../types/public-types.js';
4
+ import { type WebSocketUpgradeOptions } from '../shared/ws/node-http-websocket-upgrades.js';
4
5
  import { SharedServerAdapter } from '../shared/runtime/server-adapter.js';
5
6
  import type { ServerAdapterResult } from '../abstract/server-adapter.js';
6
- import { NodeHttpRequestBridge } from './http-request-bridge.js';
7
7
  import type { StaticPreviewHost } from '../shared/runtime/static-preview-host.js';
8
- import { type NodeServerDevRuntimeFactory } from './server-adapter-dependencies.js';
9
8
  export type NodeServerInstance = NodeHttpServer;
10
9
  export type NodeServeAdapterServerOptions = {
11
10
  port?: number;
@@ -18,6 +17,7 @@ export interface NodeServerAdapterParams {
18
17
  serveOptions: NodeServeAdapterServerOptions;
19
18
  apiHandlers?: ApiHandler[];
20
19
  staticRoutes?: StaticRoute[];
20
+ errorPageLoaders?: ErrorPageLoaders;
21
21
  errorHandler?: ErrorHandler;
22
22
  websocketHandlers?: Map<string, EcopagesWebSocketHandler<any, any>>;
23
23
  hostOwnsDevClient?: boolean;
@@ -26,16 +26,13 @@ export interface NodeServerAdapterParams {
26
26
  };
27
27
  deferRuntimeAssetSetup?: boolean;
28
28
  allowPortFallback?: boolean;
29
+ onDevelopmentRestart?: (changedFile: string) => Promise<void>;
29
30
  previewHost?: StaticPreviewHost;
30
- requestBridge?: NodeHttpRequestBridge;
31
- devRuntimeFactory?: NodeServerDevRuntimeFactory;
32
31
  }
33
32
  export interface NodeServerAdapterResult extends ServerAdapterResult {
34
- completeInitialization: (server: NodeServerInstance) => Promise<void>;
33
+ completeInitialization: (server: NodeServerInstance, options?: WebSocketUpgradeOptions) => Promise<void>;
35
34
  handleRequest: (request: Request) => Promise<Response>;
36
- attachUserWebSocketUpgrades: (server: NodeServerInstance, options?: {
37
- passthroughUnmatched?: boolean;
38
- }) => void;
35
+ attachUserWebSocketUpgrades: (server: NodeServerInstance, options?: WebSocketUpgradeOptions) => void;
39
36
  dispose: () => Promise<void>;
40
37
  }
41
38
  /**
@@ -52,9 +49,10 @@ export interface NodeServerAdapterResult extends ServerAdapterResult {
52
49
  * Conditionally wires HMR, WebSocket upgrades, and the file watcher when
53
50
  * `options.watch` is `true`.
54
51
  * 3. `handleRequest(request)` — delegates to `handleSharedRequest` for routing;
55
- * intercepts `ClientAbortError` to return 499 instead of 500.
56
- * 4. `buildStatic()` — spins up an ephemeral runtime server, generates all static
57
- * pages against it, then tears it down.
52
+ * intercepts `ClientAbortError` to return 499 instead of 500 and sends every
53
+ * other escaped error through the shared `app.onError` boundary.
54
+ * 4. `buildStatic()` — generates static pages in-process through the shared
55
+ * static builder (no runtime server), then optionally starts the preview server.
58
56
  *
59
57
  * @see SharedServerAdapter for routing, caching and response handler logic.
60
58
  */
@@ -63,6 +61,7 @@ export declare class NodeServerAdapter extends SharedServerAdapter<NodeServerAda
63
61
  private initialized;
64
62
  private apiHandlers;
65
63
  private staticRoutes;
64
+ private errorPageLoaders;
66
65
  private errorHandler?;
67
66
  private bridge;
68
67
  private hmrManager;
@@ -70,9 +69,8 @@ export declare class NodeServerAdapter extends SharedServerAdapter<NodeServerAda
70
69
  private adapterDisposed;
71
70
  private readonly deferRuntimeAssetSetup;
72
71
  private readonly allowPortFallback;
72
+ private readonly onDevelopmentRestart?;
73
73
  private readonly previewHost;
74
- private readonly requestBridge;
75
- private readonly devRuntimeFactory;
76
74
  /**
77
75
  * Reference to the application-level WebSocket handlers map.
78
76
  *
@@ -88,23 +86,17 @@ export declare class NodeServerAdapter extends SharedServerAdapter<NodeServerAda
88
86
  * Host integrations such as the Vite plugin call this so `app.websocket()`
89
87
  * handlers work while HTTP is still served by the host dev server.
90
88
  */
91
- attachUserWebSocketUpgrades(server: NodeServerInstance, options?: {
92
- passthroughUnmatched?: boolean;
93
- }): void;
94
- private wireUserWebSocketUpgrades;
89
+ attachUserWebSocketUpgrades(server: NodeServerInstance, options?: WebSocketUpgradeOptions): void;
95
90
  /**
96
91
  * @remarks
97
- * `previewHost`, `requestBridge`, and `devRuntimeFactory` are optional on the
98
- * public {@link NodeServerAdapterParams} so factory callers can omit them, but
99
- * they are mandatory by the time the concrete adapter is constructed —
100
- * {@link createNodeServerAdapter} fills in Node-specific defaults first. The
101
- * constructor signature makes that invariant explicit instead of relying on
102
- * non-null assertions.
92
+ * `previewHost` is optional on the public {@link NodeServerAdapterParams} so
93
+ * factory callers can omit it, but it is mandatory by the time the concrete
94
+ * adapter is constructed — {@link createNodeServerAdapter} fills in the Node
95
+ * default first. The constructor signature makes that invariant explicit
96
+ * instead of relying on non-null assertions.
103
97
  */
104
98
  constructor(options: NodeServerAdapterParams & {
105
99
  previewHost: StaticPreviewHost;
106
- requestBridge: NodeHttpRequestBridge;
107
- devRuntimeFactory: NodeServerDevRuntimeFactory;
108
100
  });
109
101
  /**
110
102
  * Prepares the adapter for use.
@@ -144,12 +136,16 @@ export declare class NodeServerAdapter extends SharedServerAdapter<NodeServerAda
144
136
  * Handles a single incoming Web `Request` and returns a Web `Response`.
145
137
  *
146
138
  * Delegates to `handleSharedRequest` for all routing, caching, and response
147
- * handler logic. The only Node-specific concern here is translating a
148
- * `ClientAbortError` — which the body `ReadableStream` raises when the
149
- * underlying socket closes early — into a 499 response so it does not
150
- * incorrectly surface as a 500 in application logs.
139
+ * handler logic. Escaped errors go through the shared `app.onError`
140
+ * boundary, which answers client aborts (see {@link isClientAbortError}) with 499.
151
141
  */
152
142
  handleRequest(request: Request): Promise<Response>;
143
+ /**
144
+ * @remarks
145
+ * The request body stream raises `NodeClientAbortError` when the socket closes
146
+ * early (closed tab, network drop, programmatic abort).
147
+ */
148
+ protected isClientAbortError(error: unknown): boolean;
153
149
  /**
154
150
  * Called once the HTTP server is bound and listening.
155
151
  *
@@ -164,9 +160,11 @@ export declare class NodeServerAdapter extends SharedServerAdapter<NodeServerAda
164
160
  * refreshes the router and response handlers when pages are added or removed.
165
161
  *
166
162
  * WebSocket upgrade requests that do not match a known path are rejected with an
167
- * immediate socket destroy to prevent unhandled upgrade leaks.
163
+ * immediate socket destroy to prevent unhandled upgrade leaks, unless
164
+ * `passthroughUnmatched` is set because a host (for example Vite) shares the
165
+ * server and owns other upgrade paths.
168
166
  */
169
- completeInitialization(server: NodeServerInstance): Promise<void>;
167
+ completeInitialization(server: NodeServerInstance, options?: WebSocketUpgradeOptions): Promise<void>;
170
168
  }
171
169
  /**
172
170
  * Factory function that creates and fully initialises a `NodeServerAdapter`.
@@ -4,6 +4,7 @@ import { fileSystem } from '@ecopages/file-system';
4
4
  import { setupAppRuntimePlugins } from '../../build/build-adapter.js';
5
5
  import { installBuildRuntime } from '../../build/runtime/build-runtime.js';
6
6
  import { appLogger } from '../../global/app-logger.js';
7
+ import { entryWatcherOwnsConfig } from '../../dev/development-restart.js';
7
8
  import { NodeClientBridge } from './node-client-bridge.js';
8
9
  import { NodeHmrManager } from './node-hmr-manager.js';
9
10
  import { ProjectWatcher } from '../../watchers/project-watcher.js';
@@ -14,9 +15,9 @@ import { ServerStaticBuilder } from '../shared/runtime/server-static-builder.js'
14
15
  import { DEFAULT_ECOPAGES_HOSTNAME, DEFAULT_ECOPAGES_PORT } from '../../config/constants.js';
15
16
  import { attachHmrToIntegrations, disposeDevResources, prepareRuntimePublicDir, startDevWarmup, } from '../shared/runtime/runtime-server-lifecycle.js';
16
17
  import { resolveServeRuntimeOrigin } from '../shared/runtime/runtime-app-bootstrap.js';
17
- import { NodeClientAbortError, NodeHttpRequestBridge } from './http-request-bridge.js';
18
+ import { isNodeClientAbortError } from './http-request-bridge.js';
18
19
  import { NodeStaticPreviewHost } from './static-preview-host.js';
19
- import { DefaultNodeServerDevRuntimeFactory } from './server-adapter-dependencies.js';
20
+ import { createNodeServerDevRuntime } from './server-adapter-dependencies.js';
20
21
  /**
21
22
  * Node.js HTTP server adapter for the Ecopages runtime.
22
23
  *
@@ -31,9 +32,10 @@ import { DefaultNodeServerDevRuntimeFactory } from './server-adapter-dependencie
31
32
  * Conditionally wires HMR, WebSocket upgrades, and the file watcher when
32
33
  * `options.watch` is `true`.
33
34
  * 3. `handleRequest(request)` — delegates to `handleSharedRequest` for routing;
34
- * intercepts `ClientAbortError` to return 499 instead of 500.
35
- * 4. `buildStatic()` — spins up an ephemeral runtime server, generates all static
36
- * pages against it, then tears it down.
35
+ * intercepts `ClientAbortError` to return 499 instead of 500 and sends every
36
+ * other escaped error through the shared `app.onError` boundary.
37
+ * 4. `buildStatic()` — generates static pages in-process through the shared
38
+ * static builder (no runtime server), then optionally starts the preview server.
37
39
  *
38
40
  * @see SharedServerAdapter for routing, caching and response handler logic.
39
41
  */
@@ -42,6 +44,7 @@ export class NodeServerAdapter extends SharedServerAdapter {
42
44
  initialized = false;
43
45
  apiHandlers;
44
46
  staticRoutes;
47
+ errorPageLoaders;
45
48
  errorHandler;
46
49
  bridge = null;
47
50
  hmrManager = null;
@@ -49,9 +52,8 @@ export class NodeServerAdapter extends SharedServerAdapter {
49
52
  adapterDisposed = false;
50
53
  deferRuntimeAssetSetup;
51
54
  allowPortFallback;
55
+ onDevelopmentRestart;
52
56
  previewHost;
53
- requestBridge;
54
- devRuntimeFactory;
55
57
  /**
56
58
  * Reference to the application-level WebSocket handlers map.
57
59
  *
@@ -74,33 +76,24 @@ export class NodeServerAdapter extends SharedServerAdapter {
74
76
  passthroughUnmatched: options?.passthroughUnmatched,
75
77
  });
76
78
  }
77
- wireUserWebSocketUpgrades(server, preflight) {
78
- attachNodeHttpWebSocketUpgrades(server, {
79
- runtimeOrigin: this.runtimeOrigin,
80
- websocketHandlers: this.websocketHandlers,
81
- passthroughUnmatched: false,
82
- preflight,
83
- });
84
- }
85
79
  /**
86
80
  * @remarks
87
- * `previewHost`, `requestBridge`, and `devRuntimeFactory` are optional on the
88
- * public {@link NodeServerAdapterParams} so factory callers can omit them, but
89
- * they are mandatory by the time the concrete adapter is constructed —
90
- * {@link createNodeServerAdapter} fills in Node-specific defaults first. The
91
- * constructor signature makes that invariant explicit instead of relying on
92
- * non-null assertions.
81
+ * `previewHost` is optional on the public {@link NodeServerAdapterParams} so
82
+ * factory callers can omit it, but it is mandatory by the time the concrete
83
+ * adapter is constructed — {@link createNodeServerAdapter} fills in the Node
84
+ * default first. The constructor signature makes that invariant explicit
85
+ * instead of relying on non-null assertions.
93
86
  */
94
87
  constructor(options) {
95
88
  super(options);
96
89
  this.deferRuntimeAssetSetup = options.deferRuntimeAssetSetup === true;
97
90
  this.allowPortFallback = options.allowPortFallback !== false;
91
+ this.onDevelopmentRestart = options.onDevelopmentRestart;
98
92
  this.apiHandlers = options.apiHandlers || [];
99
93
  this.staticRoutes = options.staticRoutes || [];
94
+ this.errorPageLoaders = options.errorPageLoaders ?? {};
100
95
  this.errorHandler = options.errorHandler;
101
96
  this.previewHost = options.previewHost;
102
- this.requestBridge = options.requestBridge;
103
- this.devRuntimeFactory = options.devRuntimeFactory;
104
97
  if (options.websocketHandlers) {
105
98
  this.websocketHandlers = options.websocketHandlers;
106
99
  }
@@ -130,6 +123,7 @@ export class NodeServerAdapter extends SharedServerAdapter {
130
123
  }
131
124
  await this.initializeSharedRouteHandling({
132
125
  staticRoutes: this.staticRoutes,
126
+ errorPageLoaders: this.errorPageLoaders,
133
127
  hmrManager: this.hmrManager ?? undefined,
134
128
  });
135
129
  this.staticSiteGenerator = new StaticSiteGenerator({ appConfig: this.appConfig });
@@ -157,6 +151,7 @@ export class NodeServerAdapter extends SharedServerAdapter {
157
151
  router: this.router,
158
152
  routeRendererFactory: this.routeRendererFactory,
159
153
  staticRoutes: this.staticRoutes,
154
+ errorPageLoaders: this.errorPageLoaders,
160
155
  });
161
156
  if (!options?.preview) {
162
157
  return undefined;
@@ -199,6 +194,7 @@ export class NodeServerAdapter extends SharedServerAdapter {
199
194
  completeInitialization: this.completeInitialization.bind(this),
200
195
  handleRequest: this.handleRequest.bind(this),
201
196
  attachUserWebSocketUpgrades: this.attachUserWebSocketUpgrades.bind(this),
197
+ applyBoundPort: this.applyBoundPort.bind(this),
202
198
  listStaticGenerationRoutes: (input) => this.router.listStaticGenerationRoutes(input),
203
199
  dispose: this.dispose.bind(this),
204
200
  };
@@ -230,37 +226,34 @@ export class NodeServerAdapter extends SharedServerAdapter {
230
226
  * Handles a single incoming Web `Request` and returns a Web `Response`.
231
227
  *
232
228
  * Delegates to `handleSharedRequest` for all routing, caching, and response
233
- * handler logic. The only Node-specific concern here is translating a
234
- * `ClientAbortError` — which the body `ReadableStream` raises when the
235
- * underlying socket closes early — into a 499 response so it does not
236
- * incorrectly surface as a 500 in application logs.
229
+ * handler logic. Escaped errors go through the shared `app.onError`
230
+ * boundary, which answers client aborts (see {@link isClientAbortError}) with 499.
237
231
  */
238
232
  async handleRequest(request) {
239
233
  if (!this.initialized) {
240
234
  throw new Error('Node server adapter is not initialized. Call createAdapter() first.');
241
235
  }
236
+ const context = {
237
+ apiHandlers: this.apiHandlers,
238
+ errorHandler: this.errorHandler,
239
+ serverInstance: this.serverInstance,
240
+ hmrManager: this.hmrManager ?? undefined,
241
+ };
242
242
  try {
243
- const response = await this.handleSharedRequest(request, {
244
- apiHandlers: this.apiHandlers,
245
- errorHandler: this.errorHandler,
246
- serverInstance: this.serverInstance,
247
- hmrManager: this.hmrManager ?? undefined,
248
- });
249
- return response;
243
+ return await this.handleSharedRequest(request, context);
250
244
  }
251
245
  catch (error) {
252
- if (error instanceof NodeClientAbortError) {
253
- /**
254
- * The client disconnected before the response was sent (killed tab,
255
- * network drop, or programmatic abort). This is a normal browser behaviour,
256
- * not a server fault. Return 499 (Client Closed Request) silently so the
257
- * error does not surface in application logs as a 500.
258
- */
259
- return new Response(null, { status: 499 });
260
- }
261
- throw error;
246
+ return await this.handleUnexpectedRequestError(error, request, context);
262
247
  }
263
248
  }
249
+ /**
250
+ * @remarks
251
+ * The request body stream raises `NodeClientAbortError` when the socket closes
252
+ * early (closed tab, network drop, programmatic abort).
253
+ */
254
+ isClientAbortError(error) {
255
+ return isNodeClientAbortError(error);
256
+ }
264
257
  /**
265
258
  * Called once the HTTP server is bound and listening.
266
259
  *
@@ -275,13 +268,15 @@ export class NodeServerAdapter extends SharedServerAdapter {
275
268
  * refreshes the router and response handlers when pages are added or removed.
276
269
  *
277
270
  * WebSocket upgrade requests that do not match a known path are rejected with an
278
- * immediate socket destroy to prevent unhandled upgrade leaks.
271
+ * immediate socket destroy to prevent unhandled upgrade leaks, unless
272
+ * `passthroughUnmatched` is set because a host (for example Vite) shares the
273
+ * server and owns other upgrade paths.
279
274
  */
280
- async completeInitialization(server) {
275
+ async completeInitialization(server, options) {
281
276
  this.serverInstance = server;
282
- const hasUserWs = this.websocketHandlers.size > 0;
277
+ const passthroughUnmatched = options?.passthroughUnmatched;
283
278
  if (this.options?.watch) {
284
- const devRuntime = this.devRuntimeFactory.create({ appConfig: this.appConfig });
279
+ const devRuntime = createNodeServerDevRuntime(this.appConfig);
285
280
  const wss = devRuntime.websocketServer;
286
281
  this.bridge = devRuntime.bridge;
287
282
  this.hmrManager = devRuntime.hmrManager;
@@ -298,38 +293,41 @@ export class NodeServerAdapter extends SharedServerAdapter {
298
293
  });
299
294
  return true;
300
295
  };
301
- if (hasUserWs) {
302
- this.wireUserWebSocketUpgrades(server, hmrPreflight);
303
- }
304
- else {
305
- server.on('upgrade', (req, socket, head) => {
306
- if (!hmrPreflight(req, socket, head)) {
307
- socket.destroy();
308
- }
309
- });
310
- }
296
+ attachNodeHttpWebSocketUpgrades(server, {
297
+ runtimeOrigin: this.runtimeOrigin,
298
+ websocketHandlers: this.websocketHandlers,
299
+ passthroughUnmatched,
300
+ preflight: hmrPreflight,
301
+ });
311
302
  attachHmrToIntegrations(this.appConfig, this.hmrManager);
312
303
  startDevWarmup({
313
304
  appConfig: this.appConfig,
314
305
  runtimeOrigin: this.runtimeOrigin,
315
306
  });
316
- this.configureSharedResponseHandlers(this.staticRoutes, this.hmrManager);
307
+ this.configureSharedResponseHandlers({
308
+ staticRoutes: this.staticRoutes,
309
+ hmrManager: this.hmrManager,
310
+ errorPageLoaders: this.errorPageLoaders,
311
+ });
317
312
  await this.startDevStaticRoutePrewarmWhenReady();
318
313
  const watcher = new ProjectWatcher({
319
314
  config: this.appConfig,
320
315
  refreshRouterRoutesCallback: this.createSharedWatchRefreshCallback({
321
316
  staticRoutes: this.staticRoutes,
317
+ errorPageLoaders: this.errorPageLoaders,
322
318
  hmrManager: this.hmrManager ?? undefined,
323
319
  }),
324
320
  hmrManager: this.hmrManager ?? undefined,
325
321
  bridge: this.bridge,
326
322
  hostOwnsDevClient: this.hostOwnsDevClient,
323
+ onRestartRequest: this.onDevelopmentRestart,
324
+ entryWatcherOwnsConfig: entryWatcherOwnsConfig(),
327
325
  });
328
326
  this.projectWatcher = watcher;
329
327
  await watcher.createWatcherSubscription();
330
328
  }
331
- else if (hasUserWs) {
332
- this.wireUserWebSocketUpgrades(server);
329
+ else {
330
+ this.attachUserWebSocketUpgrades(server, { passthroughUnmatched });
333
331
  }
334
332
  appLogger.debug('Node server adapter initialization completed', {
335
333
  apiHandlers: this.apiHandlers.length,
@@ -349,14 +347,10 @@ export class NodeServerAdapter extends SharedServerAdapter {
349
347
  export async function createNodeServerAdapter(params) {
350
348
  const runtimeOrigin = params.runtimeOrigin ?? resolveServeRuntimeOrigin(params.serveOptions);
351
349
  const previewHost = params.previewHost ?? new NodeStaticPreviewHost();
352
- const requestBridge = params.requestBridge ?? new NodeHttpRequestBridge();
353
- const devRuntimeFactory = params.devRuntimeFactory ?? new DefaultNodeServerDevRuntimeFactory();
354
350
  const adapter = new NodeServerAdapter({
355
351
  ...params,
356
352
  runtimeOrigin,
357
353
  previewHost,
358
- requestBridge,
359
- devRuntimeFactory,
360
354
  });
361
355
  return adapter.createAdapter();
362
356
  }
@@ -1,4 +1,3 @@
1
- import fs from 'node:fs';
2
1
  import { type ResolvedHmrEntrypoint } from '../../../hmr/hmr-entrypoint-output.js';
3
2
  import type { DefaultHmrContext, EcoPagesAppConfig, IHmrManager, IClientBridge } from '../../../types/internal-types.js';
4
3
  import { type HmrStrategy } from '../../../hmr/hmr-strategy.js';
@@ -18,7 +17,6 @@ type SharedHmrManagerParams = {
18
17
  export declare abstract class SharedHmrManager implements IHmrManager {
19
18
  readonly appConfig: EcoPagesAppConfig;
20
19
  protected readonly bridge: IClientBridge;
21
- protected watchers: Map<string, fs.FSWatcher>;
22
20
  protected runtimeWorkDir: string;
23
21
  protected enabled: boolean;
24
22
  protected strategies: HmrStrategy[];
@@ -47,14 +45,12 @@ export declare abstract class SharedHmrManager implements IHmrManager {
47
45
  registerStrategy(strategy: HmrStrategy): void;
48
46
  setEnabled(enabled: boolean): void;
49
47
  isEnabled(): boolean;
50
- isRuntimeReady(): boolean;
51
48
  /**
52
49
  * Builds the browser HMR runtime once per manager session and reuses the in-flight build for concurrent callers.
53
50
  */
54
51
  ensureRuntimeReady(): Promise<boolean>;
55
52
  private ensureHmrRuntimeReady;
56
53
  private ensureDevToolbarRuntimeReady;
57
- buildRuntime(): Promise<void>;
58
54
  getRuntimePath(): string;
59
55
  private buildDevToolbarRuntimeInternal;
60
56
  getDevToolbarRuntimePath(): string;
@@ -1,4 +1,3 @@
1
- import fs from 'node:fs';
2
1
  import path from 'node:path';
3
2
  import { fileURLToPath } from 'node:url';
4
3
  import { HMR_RUNTIME_SCRIPT_URL, resolveHmrRuntimeWorkDir } from '../../../hmr/hmr-runtime-paths.js';
@@ -22,7 +21,6 @@ import { DevTransformServer } from '../../../dev/transform-server/dev-transform-
22
21
  export class SharedHmrManager {
23
22
  appConfig;
24
23
  bridge;
25
- watchers = new Map();
26
24
  runtimeWorkDir;
27
25
  enabled = false;
28
26
  strategies = [];
@@ -121,9 +119,6 @@ export class SharedHmrManager {
121
119
  isEnabled() {
122
120
  return this.enabled;
123
121
  }
124
- isRuntimeReady() {
125
- return this.runtimeReady && fileSystem.exists(this.getRuntimePath());
126
- }
127
122
  /**
128
123
  * Builds the browser HMR runtime once per manager session and reuses the in-flight build for concurrent callers.
129
124
  */
@@ -171,9 +166,6 @@ export class SharedHmrManager {
171
166
  this.devToolbarBuildPromise = null;
172
167
  }
173
168
  }
174
- async buildRuntime() {
175
- await this.ensureRuntimeReady();
176
- }
177
169
  getRuntimePath() {
178
170
  return path.join(this.runtimeWorkDir, path.basename(HMR_RUNTIME_SCRIPT_URL));
179
171
  }
@@ -409,10 +401,6 @@ export class SharedHmrManager {
409
401
  this.runtimeReady = false;
410
402
  this.entrypointRegistry.clearAll();
411
403
  this.devTransformServer.reset();
412
- for (const watcher of this.watchers.values()) {
413
- watcher.close();
414
- }
415
- this.watchers.clear();
416
404
  this.entrypointDependencyGraph.reset();
417
405
  }
418
406
  clearFailedEntrypointRegistration(entrypointPath) {
@@ -1,14 +1,24 @@
1
1
  import type { SchemaValidationService } from '../../../services/validation/schema-validation-service.js';
2
- import type { ApiHandler, CacheInvalidator, ErrorHandler, RenderContext } from '../../../types/public-types.js';
2
+ import type { ApiHandler, ApiHandlerContext, CacheInvalidator, ErrorHandler, RenderContext } from '../../../types/public-types.js';
3
3
  export type ApiRequestPipelineOptions = {
4
4
  schemaValidator: SchemaValidationService;
5
5
  getRenderContext: () => RenderContext;
6
6
  getCacheService: () => CacheInvalidator | null;
7
+ /**
8
+ * Recognises a client that disconnected mid-request.
9
+ *
10
+ * @remarks
11
+ * Such errors are a normal browser behaviour, not a server fault, so
12
+ * {@link ApiRequestPipeline.handleError} answers them with 499 without logging or
13
+ * calling `app.onError`. Only the Node adapter supplies it.
14
+ */
15
+ isClientAbort?: (error: unknown) => boolean;
7
16
  };
8
17
  export declare class ApiRequestPipeline<TRequest extends Request = Request, TServer = unknown> {
9
18
  private readonly schemaValidator;
10
19
  private readonly getRenderContext;
11
20
  private readonly getCacheService;
21
+ private readonly isClientAbort;
12
22
  constructor(options: ApiRequestPipelineOptions);
13
23
  match(request: TRequest, apiHandlers: ApiHandler<string, TRequest, TServer>[]): {
14
24
  routeConfig: ApiHandler<string, TRequest, TServer>;
@@ -16,6 +26,22 @@ export declare class ApiRequestPipeline<TRequest extends Request = Request, TSer
16
26
  } | null;
17
27
  tryHandle(request: TRequest, apiHandlers: ApiHandler<string, TRequest, TServer>[], serverInstance: TServer | undefined, errorHandler?: ErrorHandler<TRequest, TServer>): Promise<Response | null>;
18
28
  execute(request: TRequest, params: Record<string, string | string[]>, routeConfig: ApiHandler<string, TRequest, TServer>, serverInstance: TServer | undefined, errorHandler?: ErrorHandler<TRequest, TServer>): Promise<Response>;
29
+ /**
30
+ * Resolves an error that escaped a handler into a response.
31
+ *
32
+ * @remarks
33
+ * Precedence is a thrown `Response`, then a client abort (499), then the app
34
+ * `onError` handler, then `HttpError.toResponse()`, then a logged plain 500.
35
+ * Runtime adapters reuse this for errors that escape the whole request
36
+ * pipeline so `app.onError` behaves the same on Bun and Node.
37
+ */
38
+ handleError(error: unknown, options: {
39
+ request: TRequest;
40
+ params?: Record<string, string | string[]>;
41
+ serverInstance: TServer | undefined;
42
+ errorHandler?: ErrorHandler<TRequest, TServer>;
43
+ context?: ApiHandlerContext<TRequest, TServer>;
44
+ }): Promise<Response>;
19
45
  private createContext;
20
46
  private normalizeParams;
21
47
  private applyRequestSchema;