@ecopages/core 0.2.0-alpha.7 → 0.2.0-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/package.json +212 -92
- package/src/adapters/abstract/application-adapter.d.ts +168 -0
- package/src/adapters/abstract/application-adapter.js +109 -0
- package/src/adapters/abstract/router-adapter.d.ts +26 -0
- package/src/adapters/abstract/router-adapter.js +5 -0
- package/src/adapters/abstract/server-adapter.d.ts +69 -0
- package/src/adapters/abstract/server-adapter.js +15 -0
- package/src/adapters/bun/client-bridge.d.ts +34 -0
- package/src/adapters/bun/client-bridge.js +48 -0
- package/src/adapters/bun/create-app.d.ts +60 -0
- package/src/adapters/bun/create-app.js +117 -0
- package/src/adapters/bun/hmr-manager.d.ts +143 -0
- package/src/adapters/bun/hmr-manager.js +334 -0
- package/src/adapters/bun/index.d.ts +2 -0
- package/src/adapters/bun/index.js +8 -0
- package/src/adapters/bun/server-adapter.d.ts +155 -0
- package/src/adapters/bun/server-adapter.js +373 -0
- package/src/adapters/bun/server-lifecycle.d.ts +63 -0
- package/src/adapters/bun/server-lifecycle.js +92 -0
- package/src/adapters/index.d.ts +6 -0
- package/src/adapters/index.js +14 -0
- package/src/adapters/node/bootstrap-dependency-resolver.d.ts +44 -0
- package/src/adapters/node/bootstrap-dependency-resolver.js +172 -0
- package/src/adapters/node/create-app.d.ts +21 -0
- package/src/adapters/node/create-app.js +143 -0
- package/src/adapters/node/index.d.ts +6 -0
- package/src/adapters/node/index.js +11 -0
- package/src/adapters/node/node-client-bridge.d.ts +26 -0
- package/src/adapters/node/node-client-bridge.js +66 -0
- package/src/adapters/node/node-hmr-manager.d.ts +133 -0
- package/src/adapters/node/node-hmr-manager.js +312 -0
- package/src/adapters/node/runtime-adapter.d.ts +46 -0
- package/src/adapters/node/runtime-adapter.js +306 -0
- package/src/adapters/node/server-adapter.d.ts +161 -0
- package/src/adapters/node/server-adapter.js +358 -0
- package/src/adapters/node/static-content-server.d.ts +60 -0
- package/src/adapters/node/static-content-server.js +194 -0
- package/src/adapters/node/write-runtime-manifest.d.ts +26 -0
- package/src/adapters/node/write-runtime-manifest.js +12 -0
- package/src/adapters/shared/api-response.d.ts +52 -0
- package/src/adapters/shared/api-response.js +96 -0
- package/src/adapters/shared/application-adapter.d.ts +18 -0
- package/src/adapters/shared/application-adapter.js +90 -0
- package/src/adapters/shared/define-api-handler.d.ts +25 -0
- package/src/adapters/shared/define-api-handler.js +15 -0
- package/src/adapters/shared/explicit-static-route-matcher.d.ts +38 -0
- package/src/adapters/shared/explicit-static-route-matcher.js +103 -0
- package/src/adapters/shared/file-route-middleware-pipeline.d.ts +65 -0
- package/src/adapters/shared/file-route-middleware-pipeline.js +99 -0
- package/src/adapters/shared/fs-server-response-factory.d.ts +19 -0
- package/src/adapters/shared/fs-server-response-factory.js +97 -0
- package/src/adapters/shared/fs-server-response-matcher.d.ts +75 -0
- package/src/adapters/shared/fs-server-response-matcher.js +160 -0
- package/src/adapters/shared/hmr-entrypoint-registrar.d.ts +55 -0
- package/src/adapters/shared/hmr-entrypoint-registrar.js +87 -0
- package/src/adapters/shared/hmr-html-response.d.ts +22 -0
- package/src/adapters/shared/hmr-html-response.js +32 -0
- package/src/adapters/shared/render-context.d.ts +14 -0
- package/src/adapters/shared/render-context.js +70 -0
- package/src/adapters/shared/runtime-bootstrap.d.ts +38 -0
- package/src/adapters/shared/runtime-bootstrap.js +43 -0
- package/src/adapters/shared/server-adapter.d.ts +97 -0
- package/src/adapters/shared/server-adapter.js +386 -0
- package/src/adapters/shared/server-route-handler.d.ts +89 -0
- package/src/adapters/shared/server-route-handler.js +111 -0
- package/src/adapters/shared/server-static-builder.d.ts +70 -0
- package/src/adapters/shared/server-static-builder.js +99 -0
- package/src/build/build-adapter.d.ts +186 -0
- package/src/build/build-adapter.js +168 -0
- package/src/build/build-manifest.d.ts +27 -0
- package/src/build/build-manifest.js +30 -0
- package/src/build/build-types.d.ts +57 -0
- package/src/build/build-types.js +0 -0
- package/src/build/dev-build-coordinator.d.ts +74 -0
- package/src/build/dev-build-coordinator.js +161 -0
- package/src/build/esbuild-build-adapter.d.ts +72 -0
- package/src/build/esbuild-build-adapter.js +422 -0
- package/src/build/runtime-build-executor.d.ts +13 -0
- package/src/build/runtime-build-executor.js +20 -0
- package/src/build/runtime-specifier-alias-plugin.d.ts +15 -0
- package/src/build/runtime-specifier-alias-plugin.js +31 -0
- package/src/config/config-builder.d.ts +238 -0
- package/src/config/config-builder.js +565 -0
- package/src/constants.d.ts +45 -0
- package/src/constants.js +25 -0
- package/src/create-app.d.ts +17 -0
- package/src/create-app.js +66 -0
- package/src/dev/sc-server.d.ts +30 -0
- package/src/dev/sc-server.js +111 -0
- package/src/eco/component-render-context.d.ts +105 -0
- package/src/eco/component-render-context.js +87 -0
- package/src/eco/eco.d.ts +9 -0
- package/src/eco/eco.js +114 -0
- package/src/eco/eco.types.d.ts +178 -0
- package/src/eco/eco.types.js +0 -0
- package/src/eco/eco.utils.d.ts +40 -0
- package/src/eco/eco.utils.js +40 -0
- package/src/eco/global-injector-map.d.ts +16 -0
- package/src/eco/global-injector-map.js +80 -0
- package/src/eco/lazy-injector-map.d.ts +8 -0
- package/src/eco/lazy-injector-map.js +70 -0
- package/src/eco/module-dependencies.d.ts +18 -0
- package/src/eco/module-dependencies.js +49 -0
- package/src/errors/http-error.d.ts +31 -0
- package/src/errors/http-error.js +50 -0
- package/src/errors/index.d.ts +2 -0
- package/src/errors/index.js +4 -0
- package/src/errors/locals-access-error.d.ts +4 -0
- package/src/errors/locals-access-error.js +9 -0
- package/src/global/app-logger.d.ts +2 -0
- package/src/global/app-logger.js +6 -0
- package/src/hmr/client/hmr-runtime.d.ts +5 -0
- package/src/hmr/client/hmr-runtime.js +109 -0
- package/src/hmr/hmr-strategy.d.ts +159 -0
- package/src/hmr/hmr-strategy.js +29 -0
- package/src/hmr/hmr.postcss.test.e2e.d.ts +1 -0
- package/src/hmr/hmr.postcss.test.e2e.js +31 -0
- package/src/hmr/hmr.test.e2e.d.ts +1 -0
- package/src/hmr/hmr.test.e2e.js +43 -0
- package/src/hmr/strategies/default-hmr-strategy.d.ts +43 -0
- package/src/hmr/strategies/default-hmr-strategy.js +34 -0
- package/src/hmr/strategies/js-hmr-strategy.d.ts +139 -0
- package/src/hmr/strategies/js-hmr-strategy.js +178 -0
- package/src/index.browser.d.ts +3 -0
- package/src/index.browser.js +4 -0
- package/src/index.d.ts +5 -0
- package/src/index.js +10 -0
- package/src/integrations/ghtml/ghtml-renderer.d.ts +15 -0
- package/src/integrations/ghtml/ghtml-renderer.js +62 -0
- package/src/integrations/ghtml/ghtml.plugin.d.ts +20 -0
- package/src/integrations/ghtml/ghtml.plugin.js +21 -0
- package/src/internal-types.d.ts +221 -0
- package/src/internal-types.js +0 -0
- package/src/plugins/alias-resolver-plugin.d.ts +2 -0
- package/src/plugins/alias-resolver-plugin.js +53 -0
- package/src/plugins/eco-component-meta-plugin.d.ts +97 -0
- package/src/plugins/eco-component-meta-plugin.js +157 -0
- package/src/plugins/integration-plugin.d.ts +136 -0
- package/src/plugins/integration-plugin.js +133 -0
- package/src/plugins/processor.d.ts +95 -0
- package/src/plugins/processor.js +136 -0
- package/src/plugins/runtime-capability.d.ts +9 -0
- package/src/plugins/runtime-capability.js +0 -0
- package/src/public-types.d.ts +1149 -0
- package/src/public-types.js +0 -0
- package/src/route-renderer/component-graph/component-graph-executor.d.ts +32 -0
- package/src/route-renderer/component-graph/component-graph-executor.js +31 -0
- package/src/route-renderer/component-graph/component-graph.d.ts +42 -0
- package/src/route-renderer/component-graph/component-graph.js +72 -0
- package/src/route-renderer/component-graph/component-marker.d.ts +52 -0
- package/src/route-renderer/component-graph/component-marker.js +46 -0
- package/src/route-renderer/component-graph/component-reference.d.ts +10 -0
- package/src/route-renderer/component-graph/component-reference.js +19 -0
- package/src/route-renderer/component-graph/marker-graph-resolver.d.ts +77 -0
- package/src/route-renderer/component-graph/marker-graph-resolver.js +95 -0
- package/src/route-renderer/orchestration/integration-renderer.d.ts +372 -0
- package/src/route-renderer/orchestration/integration-renderer.js +589 -0
- package/src/route-renderer/orchestration/render-execution.service.d.ts +103 -0
- package/src/route-renderer/orchestration/render-execution.service.js +121 -0
- package/src/route-renderer/orchestration/render-preparation.service.d.ts +121 -0
- package/src/route-renderer/orchestration/render-preparation.service.js +332 -0
- package/src/route-renderer/page-loading/dependency-resolver.d.ts +35 -0
- package/src/route-renderer/page-loading/dependency-resolver.js +442 -0
- package/src/route-renderer/page-loading/page-module-loader.d.ts +87 -0
- package/src/route-renderer/page-loading/page-module-loader.js +124 -0
- package/src/route-renderer/route-renderer.d.ts +61 -0
- package/src/route-renderer/route-renderer.js +87 -0
- package/src/router/client/link-intent.js +34 -0
- package/src/router/client/link-intent.test.browser.d.ts +1 -0
- package/src/router/client/link-intent.test.browser.js +43 -0
- package/src/router/client/navigation-coordinator.d.ts +149 -0
- package/src/router/client/navigation-coordinator.js +215 -0
- package/src/router/server/fs-router-scanner.d.ts +41 -0
- package/src/router/server/fs-router-scanner.js +156 -0
- package/src/router/server/fs-router.d.ts +26 -0
- package/src/router/server/fs-router.js +100 -0
- package/src/services/assets/asset-processing-service/asset-processing.service.d.ts +120 -0
- package/src/services/assets/asset-processing-service/asset-processing.service.js +331 -0
- package/src/services/assets/asset-processing-service/asset.factory.d.ts +17 -0
- package/src/services/assets/asset-processing-service/asset.factory.js +82 -0
- package/src/services/assets/asset-processing-service/assets.types.d.ts +89 -0
- package/src/services/assets/asset-processing-service/assets.types.js +0 -0
- package/src/services/assets/asset-processing-service/browser-runtime-asset.factory.d.ts +55 -0
- package/src/services/assets/asset-processing-service/browser-runtime-asset.factory.js +48 -0
- package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.d.ts +20 -0
- package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.js +41 -0
- package/src/services/assets/asset-processing-service/index.d.ts +5 -0
- package/src/services/assets/asset-processing-service/index.js +5 -0
- package/src/services/assets/asset-processing-service/processor.interface.d.ts +22 -0
- package/src/services/assets/asset-processing-service/processor.interface.js +6 -0
- package/src/services/assets/asset-processing-service/processor.registry.d.ts +8 -0
- package/src/services/assets/asset-processing-service/processor.registry.js +15 -0
- package/src/services/assets/asset-processing-service/processors/base/base-processor.d.ts +24 -0
- package/src/services/assets/asset-processing-service/processors/base/base-processor.js +64 -0
- package/src/services/assets/asset-processing-service/processors/base/base-script-processor.d.ts +17 -0
- package/src/services/assets/asset-processing-service/processors/base/base-script-processor.js +72 -0
- package/src/services/assets/asset-processing-service/processors/index.d.ts +5 -0
- package/src/services/assets/asset-processing-service/processors/index.js +5 -0
- package/src/services/assets/asset-processing-service/processors/script/content-script.processor.d.ts +5 -0
- package/src/services/assets/asset-processing-service/processors/script/content-script.processor.js +57 -0
- package/src/services/assets/asset-processing-service/processors/script/file-script.processor.d.ts +8 -0
- package/src/services/assets/asset-processing-service/processors/script/file-script.processor.js +76 -0
- package/src/services/assets/asset-processing-service/processors/script/node-module-script.processor.d.ts +7 -0
- package/src/services/assets/asset-processing-service/processors/script/node-module-script.processor.js +75 -0
- package/src/services/assets/asset-processing-service/processors/stylesheet/content-stylesheet.processor.d.ts +5 -0
- package/src/services/assets/asset-processing-service/processors/stylesheet/content-stylesheet.processor.js +25 -0
- package/src/services/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.d.ts +9 -0
- package/src/services/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.js +66 -0
- package/src/services/assets/browser-bundle.service.d.ts +32 -0
- package/src/services/assets/browser-bundle.service.js +33 -0
- package/src/services/cache/cache.types.d.ts +107 -0
- package/src/services/cache/cache.types.js +0 -0
- package/src/services/cache/index.d.ts +7 -0
- package/src/services/cache/index.js +7 -0
- package/src/services/cache/memory-cache-store.d.ts +42 -0
- package/src/services/cache/memory-cache-store.js +98 -0
- package/src/services/cache/page-cache-service.d.ts +70 -0
- package/src/services/cache/page-cache-service.js +152 -0
- package/src/services/cache/page-request-cache-coordinator.service.d.ts +75 -0
- package/src/services/cache/page-request-cache-coordinator.service.js +109 -0
- package/src/services/html/html-rewriter-provider.service.d.ts +37 -0
- package/src/services/html/html-rewriter-provider.service.js +65 -0
- package/src/services/html/html-transformer.service.d.ts +77 -0
- package/src/services/html/html-transformer.service.js +221 -0
- package/src/services/invalidation/development-invalidation.service.d.ts +74 -0
- package/src/services/invalidation/development-invalidation.service.js +189 -0
- package/src/services/module-loading/app-server-module-transpiler.service.d.ts +16 -0
- package/src/services/module-loading/app-server-module-transpiler.service.js +34 -0
- package/src/services/module-loading/page-module-import.service.d.ts +71 -0
- package/src/services/module-loading/page-module-import.service.js +132 -0
- package/src/services/module-loading/server-loader.service.d.ts +96 -0
- package/src/services/module-loading/server-loader.service.js +32 -0
- package/src/services/module-loading/server-module-transpiler.service.d.ts +69 -0
- package/src/services/module-loading/server-module-transpiler.service.js +61 -0
- package/src/services/runtime-manifest/node-runtime-manifest.service.d.ts +35 -0
- package/src/services/runtime-manifest/node-runtime-manifest.service.js +60 -0
- package/src/services/runtime-state/dev-graph.service.d.ts +118 -0
- package/src/services/runtime-state/dev-graph.service.js +162 -0
- package/src/services/runtime-state/entrypoint-dependency-graph.service.d.ts +41 -0
- package/src/services/runtime-state/entrypoint-dependency-graph.service.js +85 -0
- package/src/services/runtime-state/runtime-specifier-registry.service.d.ts +69 -0
- package/src/services/runtime-state/runtime-specifier-registry.service.js +37 -0
- package/src/services/runtime-state/server-invalidation-state.service.d.ts +26 -0
- package/src/services/runtime-state/server-invalidation-state.service.js +35 -0
- package/src/services/validation/schema-validation-service.d.ts +122 -0
- package/src/services/validation/schema-validation-service.js +101 -0
- package/src/services/validation/standard-schema.types.d.ts +65 -0
- package/src/services/validation/standard-schema.types.js +0 -0
- package/src/static-site-generator/static-site-generator.d.ts +109 -0
- package/src/static-site-generator/static-site-generator.js +353 -0
- package/src/utils/css.d.ts +1 -0
- package/src/utils/css.js +7 -0
- package/src/utils/deep-merge.d.ts +14 -0
- package/src/utils/deep-merge.js +32 -0
- package/src/utils/hash.d.ts +1 -0
- package/src/utils/hash.js +7 -0
- package/src/utils/html.d.ts +1 -0
- package/src/utils/html.js +4 -0
- package/src/utils/invariant.d.ts +5 -0
- package/src/utils/invariant.js +11 -0
- package/src/utils/locals-utils.d.ts +15 -0
- package/src/utils/locals-utils.js +24 -0
- package/src/utils/parse-cli-args.d.ts +24 -0
- package/src/utils/parse-cli-args.js +47 -0
- package/src/utils/path-utils.module.d.ts +5 -0
- package/src/utils/path-utils.module.js +14 -0
- package/src/utils/resolve-work-dir.d.ts +11 -0
- package/src/utils/resolve-work-dir.js +31 -0
- package/src/utils/runtime.d.ts +11 -0
- package/src/utils/runtime.js +40 -0
- package/src/utils/server-utils.module.d.ts +19 -0
- package/src/utils/server-utils.module.js +56 -0
- package/src/watchers/project-watcher.d.ts +136 -0
- package/src/watchers/project-watcher.js +281 -0
- package/src/watchers/project-watcher.test-helpers.d.ts +4 -0
- package/src/watchers/project-watcher.test-helpers.js +52 -0
- package/src/adapters/bun/hmr-manager.test.ts +0 -267
- package/src/adapters/node/bootstrap-dependency-resolver.test.ts +0 -282
- package/src/adapters/node/node-client-bridge.test.ts +0 -198
- package/src/adapters/node/node-hmr-manager.test.ts +0 -322
- package/src/adapters/node/runtime-adapter.test.ts +0 -868
- package/src/adapters/node/static-content-server.test.ts +0 -60
- package/src/adapters/shared/api-response.test.ts +0 -97
- package/src/adapters/shared/explicit-static-route-matcher.test.ts +0 -381
- package/src/adapters/shared/file-route-middleware-pipeline.test.ts +0 -90
- package/src/adapters/shared/fs-server-response-factory.test.ts +0 -187
- package/src/adapters/shared/fs-server-response-matcher.test.ts +0 -286
- package/src/adapters/shared/hmr-manager.contract.test.ts +0 -196
- package/src/adapters/shared/hmr-manager.dispatch.test.ts +0 -220
- package/src/adapters/shared/render-context.test.ts +0 -146
- package/src/adapters/shared/server-adapter.test.ts +0 -77
- package/src/adapters/shared/server-route-handler.test.ts +0 -110
- package/src/adapters/shared/server-static-builder.test.ts +0 -316
- package/src/build/build-adapter-serialization.test.ts +0 -268
- package/src/build/build-adapter.test.ts +0 -815
- package/src/build/runtime-specifier-alias-plugin.test.ts +0 -43
- package/src/config/config-builder.test.ts +0 -410
- package/src/eco/eco.test.ts +0 -678
- package/src/eco/eco.utils.test.ts +0 -124
- package/src/eco/global-injector-map.test.ts +0 -42
- package/src/eco/lazy-injector-map.test.ts +0 -66
- package/src/eco/module-dependencies.test.ts +0 -30
- package/src/errors/http-error.test.ts +0 -134
- package/src/global/utils.test.ts +0 -12
- package/src/hmr/client/__screenshots__/hmr-runtime.test.browser.ts/HMR-Runtime-HMR-Server-Integration-should-have-HMR-script-injected-in-page-1.png +0 -0
- package/src/hmr/client/__screenshots__/hmr-runtime.test.browser.ts/HMR-Runtime-HMR-Server-Integration-should-load-fixture-app-page-1.png +0 -0
- package/src/hmr/client/__screenshots__/hmr-runtime.test.browser.ts/HMR-Runtime-WebSocket-Connection-should-connect-to-correct-HMR-endpoint-1.png +0 -0
- package/src/hmr/hmr-strategy.test.ts +0 -124
- package/src/hmr/strategies/js-hmr-strategy.test.ts +0 -335
- package/src/integrations/ghtml/ghtml-renderer.test.ts +0 -63
- package/src/plugins/alias-resolver-plugin.test.ts +0 -41
- package/src/plugins/eco-component-meta-plugin.test.ts +0 -380
- package/src/plugins/integration-plugin.test.ts +0 -111
- package/src/plugins/processor.test.ts +0 -148
- package/src/route-renderer/component-graph/component-graph-executor.test.ts +0 -41
- package/src/route-renderer/component-graph/component-graph.test.ts +0 -63
- package/src/route-renderer/component-graph/component-marker.test.ts +0 -73
- package/src/route-renderer/component-graph/marker-graph-resolver.test.ts +0 -135
- package/src/route-renderer/orchestration/integration-renderer.test.ts +0 -936
- package/src/route-renderer/orchestration/render-execution.service.test.ts +0 -97
- package/src/route-renderer/orchestration/render-preparation.service.test.ts +0 -235
- package/src/route-renderer/page-loading/dependency-resolver.test.ts +0 -345
- package/src/route-renderer/page-loading/page-module-loader.test.ts +0 -96
- package/src/router/client/navigation-coordinator.test.ts +0 -237
- package/src/router/server/fs-router-scanner.test.ts +0 -83
- package/src/router/server/fs-router.test.ts +0 -214
- package/src/services/assets/asset-processing-service/asset-processing.service.test.ts +0 -385
- package/src/services/assets/asset-processing-service/asset.factory.test.ts +0 -63
- package/src/services/assets/asset-processing-service/browser-runtime-asset.factory.test.ts +0 -72
- package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.test.ts +0 -67
- package/src/services/assets/asset-processing-service/processors/base/base-processor.test.ts +0 -59
- package/src/services/assets/asset-processing-service/processors/script/file-script.processor.test.ts +0 -286
- package/src/services/assets/asset-processing-service/processors/script/node-module-script.processor.test.ts +0 -227
- package/src/services/assets/asset-processing-service/processors/stylesheet/content-stylesheet.processor.test.ts +0 -199
- package/src/services/assets/browser-bundle.service.test.ts +0 -36
- package/src/services/cache/memory-cache-store.test.ts +0 -225
- package/src/services/cache/page-cache-service.test.ts +0 -175
- package/src/services/cache/page-request-cache-coordinator.service.test.ts +0 -79
- package/src/services/html/html-rewriter-provider.service.test.ts +0 -183
- package/src/services/html/html-transformer.service.test.ts +0 -378
- package/src/services/invalidation/development-invalidation.service.test.ts +0 -77
- package/src/services/module-loading/page-module-import.service.test.ts +0 -253
- package/src/services/module-loading/server-loader.service.test.ts +0 -161
- package/src/services/module-loading/server-module-transpiler.service.test.ts +0 -115
- package/src/services/runtime-manifest/node-runtime-manifest.service.test.ts +0 -95
- package/src/services/validation/schema-validation-service.test.ts +0 -223
- package/src/static-site-generator/static-site-generator.test.ts +0 -307
- package/src/utils/deep-merge.test.ts +0 -114
- package/src/utils/invariant.test.ts +0 -22
- package/src/utils/path-utils.test.ts +0 -15
- package/src/utils/server-utils.test.ts +0 -38
- package/src/watchers/project-watcher.integration.test.ts +0 -337
- package/src/watchers/project-watcher.test.ts +0 -678
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const HMR_RUNTIME_IMPORT = "import '/_hmr_runtime.js'";
|
|
2
|
+
const HMR_RUNTIME_SCRIPT = `<script type="module">${HMR_RUNTIME_IMPORT};<\/script>`;
|
|
3
|
+
function isHtmlResponse(response) {
|
|
4
|
+
const contentType = response.headers.get("Content-Type");
|
|
5
|
+
return contentType !== null && contentType.startsWith("text/html");
|
|
6
|
+
}
|
|
7
|
+
function shouldInjectHmrHtmlResponse(watch, hmrManager) {
|
|
8
|
+
return watch && hmrManager?.isEnabled() === true;
|
|
9
|
+
}
|
|
10
|
+
async function injectHmrRuntimeIntoHtmlResponse(response) {
|
|
11
|
+
const html = await response.text();
|
|
12
|
+
if (html.includes(HMR_RUNTIME_IMPORT)) {
|
|
13
|
+
return new Response(html, {
|
|
14
|
+
status: response.status,
|
|
15
|
+
statusText: response.statusText,
|
|
16
|
+
headers: response.headers
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const updatedHtml = html.replace(/<\/html>/i, `${HMR_RUNTIME_SCRIPT}</html>`);
|
|
20
|
+
const headers = new Headers(response.headers);
|
|
21
|
+
headers.delete("Content-Length");
|
|
22
|
+
return new Response(updatedHtml, {
|
|
23
|
+
status: response.status,
|
|
24
|
+
statusText: response.statusText,
|
|
25
|
+
headers
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
injectHmrRuntimeIntoHtmlResponse,
|
|
30
|
+
isHtmlResponse,
|
|
31
|
+
shouldInjectHmrHtmlResponse
|
|
32
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { RenderContext } from '../../public-types.js';
|
|
2
|
+
import type { IntegrationPlugin } from '../../plugins/integration-plugin.js';
|
|
3
|
+
export interface CreateRenderContextOptions {
|
|
4
|
+
integrations: IntegrationPlugin[];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Creates a render context for route handlers.
|
|
8
|
+
* Provides render(), renderPartial(), json(), and html() methods that can be used
|
|
9
|
+
* within route handlers to generate responses.
|
|
10
|
+
*
|
|
11
|
+
* @param options - Configuration options including available integrations
|
|
12
|
+
* @returns A RenderContext object with methods for rendering views and creating responses
|
|
13
|
+
*/
|
|
14
|
+
export declare function createRenderContext(options: CreateRenderContextOptions): RenderContext;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { invariant } from "../../utils/invariant.js";
|
|
2
|
+
function mergePropsWithLocals(props, locals) {
|
|
3
|
+
if (!locals || typeof props !== "object" || props === null) {
|
|
4
|
+
return props;
|
|
5
|
+
}
|
|
6
|
+
return { ...props, locals };
|
|
7
|
+
}
|
|
8
|
+
function createRenderContext(options) {
|
|
9
|
+
const { integrations } = options;
|
|
10
|
+
const getRendererForView = (view) => {
|
|
11
|
+
const integrationName = view.config?.integration ?? view.config?.__eco?.integration;
|
|
12
|
+
invariant(
|
|
13
|
+
!!integrationName,
|
|
14
|
+
"Cannot determine integration for view. Set view.config.integration explicitly or ensure the view is defined with eco.page() in a file with a recognized extension."
|
|
15
|
+
);
|
|
16
|
+
const integration = integrations.find((i) => i.name === integrationName);
|
|
17
|
+
invariant(!!integration, `No integration found for: ${integrationName}`);
|
|
18
|
+
return integration.initializeRenderer();
|
|
19
|
+
};
|
|
20
|
+
const renderContext = {
|
|
21
|
+
async render(view, props, renderOptions) {
|
|
22
|
+
const locals = this?.locals;
|
|
23
|
+
const mergedProps = mergePropsWithLocals(props ?? {}, locals);
|
|
24
|
+
const renderer = getRendererForView(view);
|
|
25
|
+
const ctx = {
|
|
26
|
+
partial: false,
|
|
27
|
+
status: renderOptions?.status,
|
|
28
|
+
headers: renderOptions?.headers
|
|
29
|
+
};
|
|
30
|
+
return renderer.renderToResponse(view, mergedProps, ctx);
|
|
31
|
+
},
|
|
32
|
+
async renderPartial(view, props, renderOptions) {
|
|
33
|
+
const locals = this?.locals;
|
|
34
|
+
const mergedProps = mergePropsWithLocals(props, locals);
|
|
35
|
+
const renderer = getRendererForView(view);
|
|
36
|
+
const ctx = {
|
|
37
|
+
partial: true,
|
|
38
|
+
status: renderOptions?.status,
|
|
39
|
+
headers: renderOptions?.headers
|
|
40
|
+
};
|
|
41
|
+
return renderer.renderToResponse(view, mergedProps, ctx);
|
|
42
|
+
},
|
|
43
|
+
json(data, responseOptions) {
|
|
44
|
+
const headers = new Headers({ "Content-Type": "application/json; charset=utf-8" });
|
|
45
|
+
if (responseOptions?.headers) {
|
|
46
|
+
const incomingHeaders = new Headers(responseOptions.headers);
|
|
47
|
+
incomingHeaders.forEach((value, key) => headers.set(key, value));
|
|
48
|
+
}
|
|
49
|
+
return new Response(JSON.stringify(data), {
|
|
50
|
+
status: responseOptions?.status ?? 200,
|
|
51
|
+
headers
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
html(content, responseOptions) {
|
|
55
|
+
const headers = new Headers({ "Content-Type": "text/html; charset=utf-8" });
|
|
56
|
+
if (responseOptions?.headers) {
|
|
57
|
+
const incomingHeaders = new Headers(responseOptions.headers);
|
|
58
|
+
incomingHeaders.forEach((value, key) => headers.set(key, value));
|
|
59
|
+
}
|
|
60
|
+
return new Response(content, {
|
|
61
|
+
status: responseOptions?.status ?? 200,
|
|
62
|
+
headers
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
return renderContext;
|
|
67
|
+
}
|
|
68
|
+
export {
|
|
69
|
+
createRenderContext
|
|
70
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type BuildExecutor } from '../../build/build-adapter.js';
|
|
2
|
+
import type { EcoBuildPlugin } from '../../build/build-types.js';
|
|
3
|
+
import type { EcoPagesAppConfig, IClientBridge, IHmrManager } from '../../internal-types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Installs and returns the app-owned runtime build executor used by adapter
|
|
6
|
+
* startup and follow-up runtime work.
|
|
7
|
+
*/
|
|
8
|
+
export declare function installSharedRuntimeBuildExecutor(appConfig: EcoPagesAppConfig, options: {
|
|
9
|
+
development: boolean;
|
|
10
|
+
}): BuildExecutor;
|
|
11
|
+
/**
|
|
12
|
+
* Copies app public assets into dist and ensures the resolved assets directory
|
|
13
|
+
* exists before request handling begins.
|
|
14
|
+
*/
|
|
15
|
+
export declare function prepareSharedRuntimePublicDir(appConfig: EcoPagesAppConfig): void;
|
|
16
|
+
/**
|
|
17
|
+
* Runs runtime plugin setup against app-owned config/runtime state and optional
|
|
18
|
+
* host plugin registration hooks.
|
|
19
|
+
*/
|
|
20
|
+
export declare function initializeSharedRuntimePlugins(options: {
|
|
21
|
+
appConfig: EcoPagesAppConfig;
|
|
22
|
+
runtimeOrigin: string;
|
|
23
|
+
hmrManager?: IHmrManager;
|
|
24
|
+
onRuntimePlugin?: (plugin: unknown) => void;
|
|
25
|
+
}): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Starts shared project watching for runtime adapters.
|
|
28
|
+
*/
|
|
29
|
+
export declare function startSharedProjectWatching(options: {
|
|
30
|
+
appConfig: EcoPagesAppConfig;
|
|
31
|
+
refreshRouterRoutesCallback: () => Promise<void>;
|
|
32
|
+
hmrManager: IHmrManager;
|
|
33
|
+
bridge: IClientBridge;
|
|
34
|
+
}): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Binds a runtime HMR manager to app-owned plugin and integration state.
|
|
37
|
+
*/
|
|
38
|
+
export declare function bindSharedRuntimeHmrManager(appConfig: EcoPagesAppConfig, hmrManager: IHmrManager): EcoBuildPlugin[];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileSystem } from "@ecopages/file-system";
|
|
3
|
+
import { getAppBrowserBuildPlugins, setupAppRuntimePlugins } from "../../build/build-adapter.js";
|
|
4
|
+
import { installAppRuntimeBuildExecutor } from "../../build/runtime-build-executor.js";
|
|
5
|
+
import { RESOLVED_ASSETS_DIR } from "../../constants.js";
|
|
6
|
+
import { ProjectWatcher } from "../../watchers/project-watcher.js";
|
|
7
|
+
function installSharedRuntimeBuildExecutor(appConfig, options) {
|
|
8
|
+
return installAppRuntimeBuildExecutor(appConfig, options);
|
|
9
|
+
}
|
|
10
|
+
function prepareSharedRuntimePublicDir(appConfig) {
|
|
11
|
+
const srcPublicDir = path.join(appConfig.rootDir, appConfig.srcDir, appConfig.publicDir);
|
|
12
|
+
if (fileSystem.exists(srcPublicDir)) {
|
|
13
|
+
fileSystem.copyDir(srcPublicDir, path.join(appConfig.rootDir, appConfig.distDir));
|
|
14
|
+
}
|
|
15
|
+
fileSystem.ensureDir(path.join(appConfig.absolutePaths.distDir, RESOLVED_ASSETS_DIR));
|
|
16
|
+
}
|
|
17
|
+
async function initializeSharedRuntimePlugins(options) {
|
|
18
|
+
await setupAppRuntimePlugins(options);
|
|
19
|
+
}
|
|
20
|
+
async function startSharedProjectWatching(options) {
|
|
21
|
+
const watcher = new ProjectWatcher({
|
|
22
|
+
config: options.appConfig,
|
|
23
|
+
refreshRouterRoutesCallback: options.refreshRouterRoutesCallback,
|
|
24
|
+
hmrManager: options.hmrManager,
|
|
25
|
+
bridge: options.bridge
|
|
26
|
+
});
|
|
27
|
+
await watcher.createWatcherSubscription();
|
|
28
|
+
}
|
|
29
|
+
function bindSharedRuntimeHmrManager(appConfig, hmrManager) {
|
|
30
|
+
const browserBuildPlugins = getAppBrowserBuildPlugins(appConfig);
|
|
31
|
+
hmrManager.setPlugins(browserBuildPlugins);
|
|
32
|
+
for (const integration of appConfig.integrations) {
|
|
33
|
+
integration.setHmrManager(hmrManager);
|
|
34
|
+
}
|
|
35
|
+
return browserBuildPlugins;
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
bindSharedRuntimeHmrManager,
|
|
39
|
+
initializeSharedRuntimePlugins,
|
|
40
|
+
installSharedRuntimeBuildExecutor,
|
|
41
|
+
prepareSharedRuntimePublicDir,
|
|
42
|
+
startSharedProjectWatching
|
|
43
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { AbstractServerAdapter } from '../abstract/server-adapter.js';
|
|
2
|
+
import type { ServerAdapterOptions, ServerAdapterResult } from '../abstract/server-adapter.js';
|
|
3
|
+
import { RouteRendererFactory } from '../../route-renderer/route-renderer.js';
|
|
4
|
+
import { FSRouter } from '../../router/server/fs-router.js';
|
|
5
|
+
import { SchemaValidationService } from '../../services/validation/schema-validation-service.js';
|
|
6
|
+
import { StaticSiteGenerator } from '../../static-site-generator/static-site-generator.js';
|
|
7
|
+
import { ServerStaticBuilder } from './server-static-builder.js';
|
|
8
|
+
import { FileSystemResponseMatcher } from './fs-server-response-matcher.js';
|
|
9
|
+
import { ServerRouteHandler } from './server-route-handler.js';
|
|
10
|
+
import type { ApiHandler, CacheInvalidator, ErrorHandler, RenderContext, StaticRoute } from '../../public-types.js';
|
|
11
|
+
export declare abstract class SharedServerAdapter<TOptions extends ServerAdapterOptions, TResult extends ServerAdapterResult> extends AbstractServerAdapter<TOptions, TResult> {
|
|
12
|
+
protected router: FSRouter;
|
|
13
|
+
protected fileSystemResponseMatcher: FileSystemResponseMatcher;
|
|
14
|
+
protected routeRendererFactory: RouteRendererFactory;
|
|
15
|
+
protected routeHandler: ServerRouteHandler;
|
|
16
|
+
protected staticSiteGenerator: StaticSiteGenerator;
|
|
17
|
+
protected staticBuilder: ServerStaticBuilder;
|
|
18
|
+
protected readonly schemaValidator: SchemaValidationService;
|
|
19
|
+
protected initializeSharedRouteHandling(options: {
|
|
20
|
+
staticRoutes: StaticRoute[];
|
|
21
|
+
hmrManager?: any;
|
|
22
|
+
}): Promise<void>;
|
|
23
|
+
protected createSharedWatchRefreshCallback(options: {
|
|
24
|
+
staticRoutes: StaticRoute[];
|
|
25
|
+
hmrManager?: any;
|
|
26
|
+
onRoutesReady?: () => Promise<void> | void;
|
|
27
|
+
onError?: (error: Error) => Promise<void> | void;
|
|
28
|
+
}): () => Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Scans the filesystem and dynamically constructs the universal router map.
|
|
31
|
+
*
|
|
32
|
+
* This process runs identically across both Bun and Node wrappers. It analyzes the configured pages
|
|
33
|
+
* directory, building a map of all available UI routes and API endpoints.
|
|
34
|
+
* The resulting `FSRouter` instance becomes the central nervous system for mapping WinterCG incoming
|
|
35
|
+
* Web Requests (`Request`) to their corresponding internal execution paths.
|
|
36
|
+
*/
|
|
37
|
+
protected initSharedRouter(): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Sets up the unified rendering pipeline and response matching chain.
|
|
40
|
+
*
|
|
41
|
+
* It bridges several sub-systems together so that when an incoming request is received, the adapter knows:
|
|
42
|
+
* 1. How to render React/Lit pages via `RouteRendererFactory`
|
|
43
|
+
* 2. How to match logical routes to physical filesystem artifacts via `FileSystemResponseMatcher`
|
|
44
|
+
* 3. Whether to serve the response from the embedded `PageCacheService` or generate it fresh on the fly.
|
|
45
|
+
*
|
|
46
|
+
* Because `HmrManager` implementations rely heavily on runtime-specific WebSocket APIs (e.g. Bun.serve Websockets vs Node WS),
|
|
47
|
+
* we leave it untyped (`any`) here at the common denominator core.
|
|
48
|
+
*
|
|
49
|
+
* @param staticRoutes - A map of explicitly served static assets.
|
|
50
|
+
* @param hmrManager - The runtime-specific Hot Module Replacement orchestrator (if watching).
|
|
51
|
+
*/
|
|
52
|
+
protected configureSharedResponseHandlers(staticRoutes: StaticRoute[], hmrManager?: any): void;
|
|
53
|
+
protected getCacheService(): CacheInvalidator | null;
|
|
54
|
+
protected getRenderContext(): RenderContext;
|
|
55
|
+
/**
|
|
56
|
+
* Executes an Application Programming Interface (API) handler in an environment-agnostic manner.
|
|
57
|
+
*
|
|
58
|
+
* API routes in Ecopages are universally written using standard WinterCG `Request` and `Response` objects.
|
|
59
|
+
* This execution pipeline takes the raw `Request`, extracts its dynamic segments, runs our high-speed JSON schema
|
|
60
|
+
* validator against the body/query/headers, and triggers the developer's middleware chain sequentially.
|
|
61
|
+
*
|
|
62
|
+
* If the execution throws an error, it is gracefully caught, logged, and mutated into a standardized Http error payload,
|
|
63
|
+
* ensuring the consuming client receives a parsable response even upon internal catastrophic failure.
|
|
64
|
+
*
|
|
65
|
+
* @param request - The incoming Web standard `Request`.
|
|
66
|
+
* @param params - The extracted dynamic URL parameters (e.g., `{ id: '123' }`).
|
|
67
|
+
* @param routeConfig - The user-defined API handler object containing their business logic (`handler`) and `middleware`.
|
|
68
|
+
* @param serverInstance - Untyped reference to the underlying native server instance (BunServer/NodeServer) for potential escape hatches.
|
|
69
|
+
* @param errorHandler - Optional global error trap defined in project configuration.
|
|
70
|
+
* @returns The resulting Web standard `Response` constructed by the user's handler.
|
|
71
|
+
*/
|
|
72
|
+
protected executeApiHandler(request: Request, params: Record<string, string | string[]>, routeConfig: ApiHandler, serverInstance: any, errorHandler?: ErrorHandler): Promise<Response>;
|
|
73
|
+
private normalizePath;
|
|
74
|
+
private matchApiPath;
|
|
75
|
+
private getApiPathScore;
|
|
76
|
+
protected matchApiHandler(request: Request, apiHandlers: ApiHandler[]): {
|
|
77
|
+
routeConfig: ApiHandler;
|
|
78
|
+
params: Record<string, string | string[]>;
|
|
79
|
+
} | null;
|
|
80
|
+
/**
|
|
81
|
+
* Universally processes an incoming WinterCG Web standard Request.
|
|
82
|
+
*
|
|
83
|
+
* 1. Resolves static Hot Module Replacement runtime blobs if development.
|
|
84
|
+
* 2. Checks if the incoming request matches any parsed API route schemas.
|
|
85
|
+
* - Routes through `executeApiHandler` which performs strict validation.
|
|
86
|
+
* 3. Falls through to standard `ServerRouteHandler` for React/Lit filesystem pages.
|
|
87
|
+
*
|
|
88
|
+
* Both Bun and Node bindings fall back to this exact function once they have mapped their
|
|
89
|
+
* native HTTP objects into Web Standard Requests.
|
|
90
|
+
*/
|
|
91
|
+
handleSharedRequest(request: Request, context: {
|
|
92
|
+
apiHandlers: ApiHandler[];
|
|
93
|
+
errorHandler?: ErrorHandler;
|
|
94
|
+
serverInstance?: any;
|
|
95
|
+
hmrManager?: any;
|
|
96
|
+
}): Promise<Response>;
|
|
97
|
+
}
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { AbstractServerAdapter } from "../abstract/server-adapter.js";
|
|
3
|
+
import { RouteRendererFactory } from "../../route-renderer/route-renderer.js";
|
|
4
|
+
import { FSRouter } from "../../router/server/fs-router.js";
|
|
5
|
+
import { FSRouterScanner } from "../../router/server/fs-router-scanner.js";
|
|
6
|
+
import { MemoryCacheStore } from "../../services/cache/memory-cache-store.js";
|
|
7
|
+
import { PageCacheService } from "../../services/cache/page-cache-service.js";
|
|
8
|
+
import { SchemaValidationService } from "../../services/validation/schema-validation-service.js";
|
|
9
|
+
import { StaticSiteGenerator } from "../../static-site-generator/static-site-generator.js";
|
|
10
|
+
import { ServerStaticBuilder } from "./server-static-builder.js";
|
|
11
|
+
import { ExplicitStaticRouteMatcher } from "./explicit-static-route-matcher.js";
|
|
12
|
+
import { FileSystemServerResponseFactory } from "./fs-server-response-factory.js";
|
|
13
|
+
import { FileSystemResponseMatcher } from "./fs-server-response-matcher.js";
|
|
14
|
+
import { ServerRouteHandler } from "./server-route-handler.js";
|
|
15
|
+
import { createRenderContext } from "./render-context.js";
|
|
16
|
+
import { createRequire } from "../../utils/locals-utils.js";
|
|
17
|
+
import { HttpError } from "../../errors/http-error.js";
|
|
18
|
+
import { ApiResponseBuilder } from "./api-response.js";
|
|
19
|
+
import { appLogger } from "../../global/app-logger.js";
|
|
20
|
+
import { fileSystem } from "@ecopages/file-system";
|
|
21
|
+
class SharedServerAdapter extends AbstractServerAdapter {
|
|
22
|
+
router;
|
|
23
|
+
fileSystemResponseMatcher;
|
|
24
|
+
routeRendererFactory;
|
|
25
|
+
routeHandler;
|
|
26
|
+
staticSiteGenerator;
|
|
27
|
+
staticBuilder;
|
|
28
|
+
schemaValidator = new SchemaValidationService();
|
|
29
|
+
async initializeSharedRouteHandling(options) {
|
|
30
|
+
await this.initSharedRouter();
|
|
31
|
+
this.configureSharedResponseHandlers(options.staticRoutes, options.hmrManager);
|
|
32
|
+
}
|
|
33
|
+
createSharedWatchRefreshCallback(options) {
|
|
34
|
+
return async () => {
|
|
35
|
+
try {
|
|
36
|
+
await this.initializeSharedRouteHandling({
|
|
37
|
+
staticRoutes: options.staticRoutes,
|
|
38
|
+
hmrManager: options.hmrManager
|
|
39
|
+
});
|
|
40
|
+
if (options.onRoutesReady) {
|
|
41
|
+
await options.onRoutesReady();
|
|
42
|
+
}
|
|
43
|
+
} catch (error) {
|
|
44
|
+
if (options.onError) {
|
|
45
|
+
await options.onError(error instanceof Error ? error : new Error(String(error)));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Scans the filesystem and dynamically constructs the universal router map.
|
|
54
|
+
*
|
|
55
|
+
* This process runs identically across both Bun and Node wrappers. It analyzes the configured pages
|
|
56
|
+
* directory, building a map of all available UI routes and API endpoints.
|
|
57
|
+
* The resulting `FSRouter` instance becomes the central nervous system for mapping WinterCG incoming
|
|
58
|
+
* Web Requests (`Request`) to their corresponding internal execution paths.
|
|
59
|
+
*/
|
|
60
|
+
async initSharedRouter() {
|
|
61
|
+
const scanner = new FSRouterScanner({
|
|
62
|
+
dir: path.join(this.appConfig.rootDir, this.appConfig.srcDir, this.appConfig.pagesDir),
|
|
63
|
+
appConfig: this.appConfig,
|
|
64
|
+
origin: this.runtimeOrigin,
|
|
65
|
+
templatesExt: this.appConfig.templatesExt,
|
|
66
|
+
options: {
|
|
67
|
+
buildMode: !this.options?.watch
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
this.router = new FSRouter({
|
|
71
|
+
origin: this.runtimeOrigin,
|
|
72
|
+
assetPrefix: path.join(this.appConfig.rootDir, this.appConfig.distDir),
|
|
73
|
+
scanner
|
|
74
|
+
});
|
|
75
|
+
await this.router.init();
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Sets up the unified rendering pipeline and response matching chain.
|
|
79
|
+
*
|
|
80
|
+
* It bridges several sub-systems together so that when an incoming request is received, the adapter knows:
|
|
81
|
+
* 1. How to render React/Lit pages via `RouteRendererFactory`
|
|
82
|
+
* 2. How to match logical routes to physical filesystem artifacts via `FileSystemResponseMatcher`
|
|
83
|
+
* 3. Whether to serve the response from the embedded `PageCacheService` or generate it fresh on the fly.
|
|
84
|
+
*
|
|
85
|
+
* Because `HmrManager` implementations rely heavily on runtime-specific WebSocket APIs (e.g. Bun.serve Websockets vs Node WS),
|
|
86
|
+
* we leave it untyped (`any`) here at the common denominator core.
|
|
87
|
+
*
|
|
88
|
+
* @param staticRoutes - A map of explicitly served static assets.
|
|
89
|
+
* @param hmrManager - The runtime-specific Hot Module Replacement orchestrator (if watching).
|
|
90
|
+
*/
|
|
91
|
+
configureSharedResponseHandlers(staticRoutes, hmrManager) {
|
|
92
|
+
this.routeRendererFactory = new RouteRendererFactory({
|
|
93
|
+
appConfig: this.appConfig,
|
|
94
|
+
runtimeOrigin: this.runtimeOrigin
|
|
95
|
+
});
|
|
96
|
+
const fileSystemResponseFactory = new FileSystemServerResponseFactory({
|
|
97
|
+
appConfig: this.appConfig,
|
|
98
|
+
routeRendererFactory: this.routeRendererFactory,
|
|
99
|
+
options: {
|
|
100
|
+
watchMode: !!this.options?.watch
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
const cacheConfig = this.appConfig.cache;
|
|
104
|
+
const isCacheEnabled = cacheConfig?.enabled ?? !this.options?.watch;
|
|
105
|
+
let cacheService = null;
|
|
106
|
+
if (isCacheEnabled) {
|
|
107
|
+
const store = cacheConfig?.store === "memory" || !cacheConfig?.store ? new MemoryCacheStore({ maxEntries: cacheConfig?.maxEntries }) : cacheConfig.store;
|
|
108
|
+
cacheService = new PageCacheService({ store, enabled: true });
|
|
109
|
+
}
|
|
110
|
+
this.fileSystemResponseMatcher = new FileSystemResponseMatcher({
|
|
111
|
+
appConfig: this.appConfig,
|
|
112
|
+
router: this.router,
|
|
113
|
+
routeRendererFactory: this.routeRendererFactory,
|
|
114
|
+
fileSystemResponseFactory,
|
|
115
|
+
cacheService,
|
|
116
|
+
defaultCacheStrategy: cacheConfig?.defaultStrategy ?? "static"
|
|
117
|
+
});
|
|
118
|
+
const explicitStaticRouteMatcher = staticRoutes.length > 0 ? new ExplicitStaticRouteMatcher({
|
|
119
|
+
appConfig: this.appConfig,
|
|
120
|
+
routeRendererFactory: this.routeRendererFactory,
|
|
121
|
+
staticRoutes
|
|
122
|
+
}) : void 0;
|
|
123
|
+
this.routeHandler = new ServerRouteHandler({
|
|
124
|
+
router: this.router,
|
|
125
|
+
fileSystemResponseMatcher: this.fileSystemResponseMatcher,
|
|
126
|
+
explicitStaticRouteMatcher,
|
|
127
|
+
watch: !!this.options?.watch,
|
|
128
|
+
hmrManager
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
getCacheService() {
|
|
132
|
+
return this.fileSystemResponseMatcher?.getCacheService() ?? null;
|
|
133
|
+
}
|
|
134
|
+
getRenderContext() {
|
|
135
|
+
return createRenderContext({ integrations: this.appConfig.integrations });
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Executes an Application Programming Interface (API) handler in an environment-agnostic manner.
|
|
139
|
+
*
|
|
140
|
+
* API routes in Ecopages are universally written using standard WinterCG `Request` and `Response` objects.
|
|
141
|
+
* This execution pipeline takes the raw `Request`, extracts its dynamic segments, runs our high-speed JSON schema
|
|
142
|
+
* validator against the body/query/headers, and triggers the developer's middleware chain sequentially.
|
|
143
|
+
*
|
|
144
|
+
* If the execution throws an error, it is gracefully caught, logged, and mutated into a standardized Http error payload,
|
|
145
|
+
* ensuring the consuming client receives a parsable response even upon internal catastrophic failure.
|
|
146
|
+
*
|
|
147
|
+
* @param request - The incoming Web standard `Request`.
|
|
148
|
+
* @param params - The extracted dynamic URL parameters (e.g., `{ id: '123' }`).
|
|
149
|
+
* @param routeConfig - The user-defined API handler object containing their business logic (`handler`) and `middleware`.
|
|
150
|
+
* @param serverInstance - Untyped reference to the underlying native server instance (BunServer/NodeServer) for potential escape hatches.
|
|
151
|
+
* @param errorHandler - Optional global error trap defined in project configuration.
|
|
152
|
+
* @returns The resulting Web standard `Response` constructed by the user's handler.
|
|
153
|
+
*/
|
|
154
|
+
async executeApiHandler(request, params, routeConfig, serverInstance, errorHandler) {
|
|
155
|
+
let context;
|
|
156
|
+
try {
|
|
157
|
+
const middleware = routeConfig.middleware || [];
|
|
158
|
+
const schema = routeConfig.schema;
|
|
159
|
+
const locals = {};
|
|
160
|
+
const normalizedParams = Object.fromEntries(
|
|
161
|
+
Object.entries(params).map(([key, value]) => [key, Array.isArray(value) ? value.join("/") : value])
|
|
162
|
+
);
|
|
163
|
+
context = {
|
|
164
|
+
request,
|
|
165
|
+
params: normalizedParams,
|
|
166
|
+
response: new ApiResponseBuilder(),
|
|
167
|
+
server: serverInstance,
|
|
168
|
+
locals,
|
|
169
|
+
require: createRequire(() => locals),
|
|
170
|
+
services: {
|
|
171
|
+
cache: this.getCacheService()
|
|
172
|
+
},
|
|
173
|
+
...this.getRenderContext()
|
|
174
|
+
};
|
|
175
|
+
if (schema) {
|
|
176
|
+
const url = new URL(request.url);
|
|
177
|
+
const queryParams = Object.fromEntries(url.searchParams);
|
|
178
|
+
const headers = Object.fromEntries(request.headers);
|
|
179
|
+
let body;
|
|
180
|
+
if (schema.body) {
|
|
181
|
+
try {
|
|
182
|
+
const contentType = request.headers.get("Content-Type") || "";
|
|
183
|
+
if (contentType.includes("application/json")) body = await request.clone().json();
|
|
184
|
+
else if (contentType.includes("text/plain")) body = await request.clone().text();
|
|
185
|
+
} catch {
|
|
186
|
+
return context.response.status(400).json({ error: "Invalid request body" });
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const validationResult = await this.schemaValidator.validateRequest(
|
|
190
|
+
{ body, query: queryParams, headers, params: normalizedParams },
|
|
191
|
+
schema
|
|
192
|
+
);
|
|
193
|
+
if (!validationResult.success) {
|
|
194
|
+
return context.response.status(400).json({
|
|
195
|
+
error: "Validation failed",
|
|
196
|
+
issues: validationResult.errors
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
const validated = validationResult.data;
|
|
200
|
+
if (validated.body !== void 0) context.body = validated.body;
|
|
201
|
+
if (validated.query !== void 0) context.query = validated.query;
|
|
202
|
+
if (validated.headers !== void 0) context.headers = validated.headers;
|
|
203
|
+
if (validated.params !== void 0) context.params = validated.params;
|
|
204
|
+
}
|
|
205
|
+
if (middleware.length === 0) {
|
|
206
|
+
return await routeConfig.handler(context);
|
|
207
|
+
}
|
|
208
|
+
let index = 0;
|
|
209
|
+
const executeNext = async () => {
|
|
210
|
+
if (index < middleware.length) {
|
|
211
|
+
const currentMiddleware = middleware[index++];
|
|
212
|
+
return await currentMiddleware(context, executeNext);
|
|
213
|
+
}
|
|
214
|
+
return await routeConfig.handler(context);
|
|
215
|
+
};
|
|
216
|
+
return await executeNext();
|
|
217
|
+
} catch (error) {
|
|
218
|
+
if (error instanceof Response) return error;
|
|
219
|
+
if (errorHandler) {
|
|
220
|
+
try {
|
|
221
|
+
if (!context) {
|
|
222
|
+
const locals = {};
|
|
223
|
+
context = {
|
|
224
|
+
request,
|
|
225
|
+
params: Object.fromEntries(
|
|
226
|
+
Object.entries(params).map(([key, value]) => [
|
|
227
|
+
key,
|
|
228
|
+
Array.isArray(value) ? value.join("/") : value
|
|
229
|
+
])
|
|
230
|
+
),
|
|
231
|
+
response: new ApiResponseBuilder(),
|
|
232
|
+
server: serverInstance,
|
|
233
|
+
locals,
|
|
234
|
+
require: createRequire(() => locals),
|
|
235
|
+
services: { cache: this.getCacheService() },
|
|
236
|
+
...this.getRenderContext()
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
return await errorHandler(error, context);
|
|
240
|
+
} catch (handlerError) {
|
|
241
|
+
appLogger.error(`[ecopages] Error in custom error handler: ${handlerError}`);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (error instanceof HttpError) return error.toResponse();
|
|
245
|
+
appLogger.error(`[ecopages] Error handling API request: ${error}`);
|
|
246
|
+
return new Response("Internal Server Error", { status: 500 });
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
normalizePath(pathname) {
|
|
250
|
+
if (pathname.length > 1 && pathname.endsWith("/")) {
|
|
251
|
+
return pathname.slice(0, -1);
|
|
252
|
+
}
|
|
253
|
+
return pathname;
|
|
254
|
+
}
|
|
255
|
+
matchApiPath(pattern, pathname) {
|
|
256
|
+
const normalizedPattern = this.normalizePath(pattern);
|
|
257
|
+
const normalizedPathname = this.normalizePath(pathname);
|
|
258
|
+
const patternSegments = normalizedPattern.split("/").filter(Boolean);
|
|
259
|
+
const pathSegments = normalizedPathname.split("/").filter(Boolean);
|
|
260
|
+
const params = {};
|
|
261
|
+
let patternIndex = 0;
|
|
262
|
+
let pathIndex = 0;
|
|
263
|
+
while (patternIndex < patternSegments.length && pathIndex < pathSegments.length) {
|
|
264
|
+
const patternSegment = patternSegments[patternIndex];
|
|
265
|
+
const pathSegment = pathSegments[pathIndex];
|
|
266
|
+
if (patternSegment === "*") {
|
|
267
|
+
return params;
|
|
268
|
+
}
|
|
269
|
+
if (patternSegment.startsWith("[...") && patternSegment.endsWith("]")) {
|
|
270
|
+
const paramName = patternSegment.slice(4, -1);
|
|
271
|
+
params[paramName] = pathSegments.slice(pathIndex);
|
|
272
|
+
return params;
|
|
273
|
+
}
|
|
274
|
+
if (patternSegment.startsWith(":")) {
|
|
275
|
+
params[patternSegment.slice(1)] = pathSegment;
|
|
276
|
+
patternIndex++;
|
|
277
|
+
pathIndex++;
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
if (patternSegment.startsWith("[") && patternSegment.endsWith("]")) {
|
|
281
|
+
params[patternSegment.slice(1, -1)] = pathSegment;
|
|
282
|
+
patternIndex++;
|
|
283
|
+
pathIndex++;
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
if (patternSegment !== pathSegment) {
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
289
|
+
patternIndex++;
|
|
290
|
+
pathIndex++;
|
|
291
|
+
}
|
|
292
|
+
if (patternIndex < patternSegments.length) {
|
|
293
|
+
const remaining = patternSegments.slice(patternIndex);
|
|
294
|
+
const catchAll = remaining[0];
|
|
295
|
+
if (remaining.length === 1 && (catchAll === "*" || catchAll.startsWith("[...") && catchAll.endsWith("]"))) {
|
|
296
|
+
if (catchAll.startsWith("[...")) {
|
|
297
|
+
const paramName = catchAll.slice(4, -1);
|
|
298
|
+
params[paramName] = [];
|
|
299
|
+
}
|
|
300
|
+
return params;
|
|
301
|
+
}
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
if (pathIndex < pathSegments.length) {
|
|
305
|
+
return null;
|
|
306
|
+
}
|
|
307
|
+
return params;
|
|
308
|
+
}
|
|
309
|
+
getApiPathScore(pattern) {
|
|
310
|
+
const segments = this.normalizePath(pattern).split("/").filter(Boolean);
|
|
311
|
+
let score = 0;
|
|
312
|
+
for (const segment of segments) {
|
|
313
|
+
if (segment === "*" || segment.startsWith("[...") && segment.endsWith("]")) {
|
|
314
|
+
score += 10;
|
|
315
|
+
} else if (segment.startsWith(":") || segment.startsWith("[") && segment.endsWith("]")) {
|
|
316
|
+
score += 50;
|
|
317
|
+
} else {
|
|
318
|
+
score += 100;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return score;
|
|
322
|
+
}
|
|
323
|
+
matchApiHandler(request, apiHandlers) {
|
|
324
|
+
const pathname = new URL(request.url).pathname;
|
|
325
|
+
const method = request.method.toUpperCase();
|
|
326
|
+
const sortedHandlers = [...apiHandlers].sort((a, b) => {
|
|
327
|
+
return this.getApiPathScore(b.path) - this.getApiPathScore(a.path);
|
|
328
|
+
});
|
|
329
|
+
for (const routeConfig of sortedHandlers) {
|
|
330
|
+
const routeMethod = (routeConfig.method || "GET").toUpperCase();
|
|
331
|
+
if (routeMethod !== method) {
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
const params = this.matchApiPath(routeConfig.path, pathname);
|
|
335
|
+
if (params) {
|
|
336
|
+
return { routeConfig, params };
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return null;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Universally processes an incoming WinterCG Web standard Request.
|
|
343
|
+
*
|
|
344
|
+
* 1. Resolves static Hot Module Replacement runtime blobs if development.
|
|
345
|
+
* 2. Checks if the incoming request matches any parsed API route schemas.
|
|
346
|
+
* - Routes through `executeApiHandler` which performs strict validation.
|
|
347
|
+
* 3. Falls through to standard `ServerRouteHandler` for React/Lit filesystem pages.
|
|
348
|
+
*
|
|
349
|
+
* Both Bun and Node bindings fall back to this exact function once they have mapped their
|
|
350
|
+
* native HTTP objects into Web Standard Requests.
|
|
351
|
+
*/
|
|
352
|
+
async handleSharedRequest(request, context) {
|
|
353
|
+
const url = new URL(request.url);
|
|
354
|
+
if (url.pathname === "/_hmr_runtime.js" && context.hmrManager) {
|
|
355
|
+
const runtimePath = context.hmrManager.getRuntimePath();
|
|
356
|
+
if (fileSystem.exists(runtimePath)) {
|
|
357
|
+
return new Response(fileSystem.readFileAsBuffer(runtimePath), {
|
|
358
|
+
headers: { "Content-Type": "application/javascript" }
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
if (url.pathname.startsWith("/assets/_hmr/") && context.hmrManager) {
|
|
363
|
+
const relativePath = url.pathname.slice("/assets/_hmr/".length);
|
|
364
|
+
const assetPath = path.join(context.hmrManager.getDistDir(), relativePath);
|
|
365
|
+
if (fileSystem.exists(assetPath)) {
|
|
366
|
+
return new Response(fileSystem.readFileAsBuffer(assetPath), {
|
|
367
|
+
headers: { "Content-Type": "application/javascript" }
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
const apiMatch = this.matchApiHandler(request, context.apiHandlers);
|
|
372
|
+
if (apiMatch) {
|
|
373
|
+
return this.executeApiHandler(
|
|
374
|
+
request,
|
|
375
|
+
apiMatch.params,
|
|
376
|
+
apiMatch.routeConfig,
|
|
377
|
+
context.serverInstance,
|
|
378
|
+
context.errorHandler
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
return this.routeHandler.handleResponse(request);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
export {
|
|
385
|
+
SharedServerAdapter
|
|
386
|
+
};
|