@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,109 @@
|
|
|
1
|
+
import { getCacheControlHeader } from "./page-cache-service.js";
|
|
2
|
+
class PageRequestCacheCoordinator {
|
|
3
|
+
cacheService;
|
|
4
|
+
defaultCacheStrategy;
|
|
5
|
+
constructor(cacheService, defaultCacheStrategy) {
|
|
6
|
+
this.cacheService = cacheService;
|
|
7
|
+
this.defaultCacheStrategy = defaultCacheStrategy;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Builds the cache key used for page lookups.
|
|
11
|
+
*
|
|
12
|
+
* Query parameters are part of the key so two requests that hit the same
|
|
13
|
+
* pathname but differ by search params do not share the same rendered entry.
|
|
14
|
+
*
|
|
15
|
+
* @param input Pathname plus optional query record.
|
|
16
|
+
* @returns Stable cache key for the request.
|
|
17
|
+
*/
|
|
18
|
+
buildCacheKey(input) {
|
|
19
|
+
let key = input.pathname;
|
|
20
|
+
if (input.query && Object.keys(input.query).length > 0) {
|
|
21
|
+
const queryString = new URLSearchParams(input.query).toString();
|
|
22
|
+
key += `?${queryString}`;
|
|
23
|
+
}
|
|
24
|
+
return key;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Resolves a render request through the configured cache policy.
|
|
28
|
+
*
|
|
29
|
+
* Pages using `dynamic` rendering, or applications without a cache service,
|
|
30
|
+
* bypass cache lookup entirely and still receive the same response header
|
|
31
|
+
* contract as cached pages.
|
|
32
|
+
*
|
|
33
|
+
* @param options Cache coordination inputs for one page request.
|
|
34
|
+
* @returns HTTP response with cache headers applied.
|
|
35
|
+
*/
|
|
36
|
+
async render(options) {
|
|
37
|
+
if (!this.cacheService || options.pageCacheStrategy === "dynamic") {
|
|
38
|
+
const { html, strategy } = await options.renderFn();
|
|
39
|
+
return this.createCachedResponse(html, strategy, "disabled");
|
|
40
|
+
}
|
|
41
|
+
const result = await this.cacheService.getOrCreate(
|
|
42
|
+
options.cacheKey,
|
|
43
|
+
options.pageCacheStrategy,
|
|
44
|
+
options.renderFn
|
|
45
|
+
);
|
|
46
|
+
return this.createCachedResponse(result.html, result.strategy, result.status);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Exposes the underlying cache service for invalidation and adapter plumbing.
|
|
50
|
+
*
|
|
51
|
+
* @returns Configured cache service or `null` when caching is disabled.
|
|
52
|
+
*/
|
|
53
|
+
getCacheService() {
|
|
54
|
+
return this.cacheService;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Returns the default render strategy used when a page does not declare one.
|
|
58
|
+
*
|
|
59
|
+
* @returns Application-level fallback cache strategy.
|
|
60
|
+
*/
|
|
61
|
+
getDefaultCacheStrategy() {
|
|
62
|
+
return this.defaultCacheStrategy;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Normalizes various route render body shapes into a cacheable string.
|
|
66
|
+
*
|
|
67
|
+
* Page rendering may produce strings, buffers, byte arrays, or streams. The
|
|
68
|
+
* matcher needs a single representation before passing HTML through the cache
|
|
69
|
+
* layer, so this method centralizes the conversion rules.
|
|
70
|
+
*
|
|
71
|
+
* @param body Render output body in any supported form.
|
|
72
|
+
* @returns HTML string representation.
|
|
73
|
+
*/
|
|
74
|
+
async bodyToString(body) {
|
|
75
|
+
if (typeof body === "string") {
|
|
76
|
+
return body;
|
|
77
|
+
}
|
|
78
|
+
if (Buffer.isBuffer(body)) {
|
|
79
|
+
return body.toString("utf-8");
|
|
80
|
+
}
|
|
81
|
+
if (body instanceof ReadableStream) {
|
|
82
|
+
return new Response(body).text();
|
|
83
|
+
}
|
|
84
|
+
if (body instanceof Uint8Array) {
|
|
85
|
+
return new TextDecoder().decode(body);
|
|
86
|
+
}
|
|
87
|
+
return String(body);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Creates the final HTML response with the current cache semantics encoded in
|
|
91
|
+
* response headers.
|
|
92
|
+
*
|
|
93
|
+
* @param html Rendered page HTML.
|
|
94
|
+
* @param strategy Effective cache strategy for the response.
|
|
95
|
+
* @param cacheStatus Status used for `X-Cache` and `Cache-Control` generation.
|
|
96
|
+
* @returns HTTP response ready to send to the client.
|
|
97
|
+
*/
|
|
98
|
+
createCachedResponse(html, strategy, cacheStatus) {
|
|
99
|
+
const headers = {
|
|
100
|
+
"Content-Type": "text/html",
|
|
101
|
+
"Cache-Control": getCacheControlHeader(cacheStatus === "disabled" ? "disabled" : strategy),
|
|
102
|
+
"X-Cache": cacheStatus.toUpperCase()
|
|
103
|
+
};
|
|
104
|
+
return new Response(html, { headers });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export {
|
|
108
|
+
PageRequestCacheCoordinator
|
|
109
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export type HtmlRewriterElement = {
|
|
2
|
+
append(content: string, options?: {
|
|
3
|
+
html?: boolean;
|
|
4
|
+
}): void;
|
|
5
|
+
};
|
|
6
|
+
export type HtmlRewriterRuntime = {
|
|
7
|
+
on(selector: 'head' | 'body', handler: {
|
|
8
|
+
element: (element: HtmlRewriterElement) => void;
|
|
9
|
+
}): HtmlRewriterRuntime;
|
|
10
|
+
transform(response: Response): Response;
|
|
11
|
+
};
|
|
12
|
+
export type HtmlRewriterConstructor = new () => HtmlRewriterRuntime;
|
|
13
|
+
export type HtmlRewriterMode = 'auto' | 'native' | 'worker-tools' | 'fallback';
|
|
14
|
+
export interface HtmlRewriterProvider {
|
|
15
|
+
createHtmlRewriter(): Promise<HtmlRewriterRuntime | null>;
|
|
16
|
+
setMode(mode: HtmlRewriterMode): void;
|
|
17
|
+
}
|
|
18
|
+
export interface HtmlRewriterLogger {
|
|
19
|
+
warn(message: string): void;
|
|
20
|
+
}
|
|
21
|
+
export interface DefaultHtmlRewriterProviderOptions {
|
|
22
|
+
mode?: HtmlRewriterMode;
|
|
23
|
+
logger?: HtmlRewriterLogger;
|
|
24
|
+
getNativeHtmlRewriter?: () => HtmlRewriterConstructor | undefined;
|
|
25
|
+
loadWorkerToolsHtmlRewriter?: () => Promise<HtmlRewriterConstructor | null>;
|
|
26
|
+
}
|
|
27
|
+
export declare class DefaultHtmlRewriterProvider implements HtmlRewriterProvider {
|
|
28
|
+
private htmlRewriterConstructorPromise?;
|
|
29
|
+
private htmlRewriterMode;
|
|
30
|
+
private logger;
|
|
31
|
+
private getNativeHtmlRewriter;
|
|
32
|
+
private loadWorkerToolsHtmlRewriter;
|
|
33
|
+
constructor(options?: DefaultHtmlRewriterProviderOptions);
|
|
34
|
+
setMode(mode: HtmlRewriterMode): void;
|
|
35
|
+
createHtmlRewriter(): Promise<HtmlRewriterRuntime | null>;
|
|
36
|
+
private resolveHtmlRewriterConstructor;
|
|
37
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { appLogger } from "../../global/app-logger.js";
|
|
2
|
+
class DefaultHtmlRewriterProvider {
|
|
3
|
+
htmlRewriterConstructorPromise;
|
|
4
|
+
htmlRewriterMode;
|
|
5
|
+
logger;
|
|
6
|
+
getNativeHtmlRewriter;
|
|
7
|
+
loadWorkerToolsHtmlRewriter;
|
|
8
|
+
constructor(options = {}) {
|
|
9
|
+
this.htmlRewriterMode = options.mode ?? "auto";
|
|
10
|
+
this.logger = options.logger ?? appLogger;
|
|
11
|
+
this.getNativeHtmlRewriter = options.getNativeHtmlRewriter ?? (() => globalThis.HTMLRewriter);
|
|
12
|
+
this.loadWorkerToolsHtmlRewriter = options.loadWorkerToolsHtmlRewriter ?? loadWorkerToolsHtmlRewriter;
|
|
13
|
+
}
|
|
14
|
+
setMode(mode) {
|
|
15
|
+
this.htmlRewriterMode = mode;
|
|
16
|
+
this.htmlRewriterConstructorPromise = void 0;
|
|
17
|
+
}
|
|
18
|
+
async createHtmlRewriter() {
|
|
19
|
+
const RuntimeHtmlRewriter = await this.resolveHtmlRewriterConstructor();
|
|
20
|
+
return RuntimeHtmlRewriter ? new RuntimeHtmlRewriter() : null;
|
|
21
|
+
}
|
|
22
|
+
async resolveHtmlRewriterConstructor() {
|
|
23
|
+
if (!this.htmlRewriterConstructorPromise) {
|
|
24
|
+
const mode = this.htmlRewriterMode;
|
|
25
|
+
const RuntimeHtmlRewriter = this.getNativeHtmlRewriter();
|
|
26
|
+
if (mode === "fallback") {
|
|
27
|
+
this.htmlRewriterConstructorPromise = Promise.resolve(null);
|
|
28
|
+
} else if (mode === "native") {
|
|
29
|
+
if (RuntimeHtmlRewriter) {
|
|
30
|
+
this.htmlRewriterConstructorPromise = Promise.resolve(RuntimeHtmlRewriter);
|
|
31
|
+
} else {
|
|
32
|
+
this.logger.warn(
|
|
33
|
+
"[HtmlTransformerService] Native HTMLRewriter was forced but is unavailable, falling back to string injection."
|
|
34
|
+
);
|
|
35
|
+
this.htmlRewriterConstructorPromise = Promise.resolve(null);
|
|
36
|
+
}
|
|
37
|
+
} else if (mode === "auto" && RuntimeHtmlRewriter) {
|
|
38
|
+
this.htmlRewriterConstructorPromise = Promise.resolve(RuntimeHtmlRewriter);
|
|
39
|
+
} else {
|
|
40
|
+
this.htmlRewriterConstructorPromise = this.loadWorkerToolsHtmlRewriter();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return this.htmlRewriterConstructorPromise;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async function loadWorkerToolsHtmlRewriter() {
|
|
47
|
+
try {
|
|
48
|
+
const module = await import("@worker-tools/html-rewriter/base64");
|
|
49
|
+
return module.HTMLRewriter;
|
|
50
|
+
} catch (primaryError) {
|
|
51
|
+
try {
|
|
52
|
+
const runtimeLocalModule = await import(new URL("../node_modules/@worker-tools/html-rewriter/base64.js", import.meta.url).href);
|
|
53
|
+
return runtimeLocalModule.HTMLRewriter;
|
|
54
|
+
} catch {
|
|
55
|
+
const message = primaryError instanceof Error ? primaryError.message : String(primaryError);
|
|
56
|
+
appLogger.warn(
|
|
57
|
+
`[HtmlTransformerService] Failed to load @worker-tools/html-rewriter/base64, falling back to string injection: ${message}`
|
|
58
|
+
);
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export {
|
|
64
|
+
DefaultHtmlRewriterProvider
|
|
65
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { ProcessedAsset } from '../assets/asset-processing-service/assets.types';
|
|
2
|
+
import { type HtmlRewriterMode, type HtmlRewriterProvider } from './html-rewriter-provider.service';
|
|
3
|
+
export interface HtmlTransformerServiceOptions {
|
|
4
|
+
htmlRewriterMode?: HtmlRewriterMode;
|
|
5
|
+
htmlRewriterProvider?: HtmlRewriterProvider;
|
|
6
|
+
}
|
|
7
|
+
export declare class HtmlTransformerService {
|
|
8
|
+
private processedDependencies;
|
|
9
|
+
private htmlRewriterProvider;
|
|
10
|
+
constructor(options?: HtmlTransformerServiceOptions);
|
|
11
|
+
/**
|
|
12
|
+
* Overrides the HTML rewriter runtime selection.
|
|
13
|
+
*
|
|
14
|
+
* This is intended for internal/runtime tests that need deterministic
|
|
15
|
+
* selection between native, worker-tools, and string fallback behavior.
|
|
16
|
+
*
|
|
17
|
+
* @param mode Requested runtime selection strategy.
|
|
18
|
+
*/
|
|
19
|
+
setHtmlRewriterMode(mode: HtmlRewriterMode): void;
|
|
20
|
+
private formatAttributes;
|
|
21
|
+
private generateScriptTag;
|
|
22
|
+
private generateStylesheetTag;
|
|
23
|
+
private appendDependencies;
|
|
24
|
+
private buildDependencyTags;
|
|
25
|
+
/**
|
|
26
|
+
* Injects generated markup immediately before the closing HTML tag when it is
|
|
27
|
+
* present, or appends/prepends a fallback insertion otherwise.
|
|
28
|
+
*/
|
|
29
|
+
private injectBeforeClosingTag;
|
|
30
|
+
/**
|
|
31
|
+
* Replaces the current processed dependency set used during HTML finalization.
|
|
32
|
+
*/
|
|
33
|
+
setProcessedDependencies(processedDependencies: ProcessedAsset[]): void;
|
|
34
|
+
/**
|
|
35
|
+
* Returns the processed dependencies queued for the next transform pass.
|
|
36
|
+
*/
|
|
37
|
+
getProcessedDependencies(): ProcessedAsset[];
|
|
38
|
+
/**
|
|
39
|
+
* Applies attributes to the opening `<html>` tag when present.
|
|
40
|
+
*/
|
|
41
|
+
applyAttributesToHtmlElement(html: string, attributes: Record<string, string>): string;
|
|
42
|
+
/**
|
|
43
|
+
* Applies attributes to the first element nested directly under `<body>`.
|
|
44
|
+
*/
|
|
45
|
+
applyAttributesToFirstBodyElement(html: string, attributes: Record<string, string>): string;
|
|
46
|
+
/**
|
|
47
|
+
* Applies attributes to the first element in a fragment or full-document HTML
|
|
48
|
+
* string.
|
|
49
|
+
*/
|
|
50
|
+
applyAttributesToFirstElement(html: string, attributes: Record<string, string>): string;
|
|
51
|
+
/**
|
|
52
|
+
* Removes duplicate processed assets while preserving first-seen order.
|
|
53
|
+
*
|
|
54
|
+
* @remarks
|
|
55
|
+
* Dedupe keys include structural asset fields and HTML attributes so repeated
|
|
56
|
+
* orchestration passes can merge assets safely without collapsing distinct tag
|
|
57
|
+
* variants.
|
|
58
|
+
*/
|
|
59
|
+
dedupeProcessedAssets(assets: ProcessedAsset[]): ProcessedAsset[];
|
|
60
|
+
/**
|
|
61
|
+
* Injects the currently processed dependencies into an HTML response.
|
|
62
|
+
*
|
|
63
|
+
* @remarks
|
|
64
|
+
* Native or worker-tools HTML rewriter support is preferred when available. A
|
|
65
|
+
* string-based fallback remains in place for runtimes that cannot provide one
|
|
66
|
+
* of those rewriter implementations.
|
|
67
|
+
*/
|
|
68
|
+
transform(res: Response): Promise<Response>;
|
|
69
|
+
/**
|
|
70
|
+
* Splits processed assets into head and body injection groups.
|
|
71
|
+
*/
|
|
72
|
+
private groupDependenciesByPosition;
|
|
73
|
+
/**
|
|
74
|
+
* Builds a serialized HTML attribute string from an attribute object.
|
|
75
|
+
*/
|
|
76
|
+
private buildAttributeString;
|
|
77
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DefaultHtmlRewriterProvider
|
|
3
|
+
} from "./html-rewriter-provider.service";
|
|
4
|
+
class HtmlTransformerService {
|
|
5
|
+
processedDependencies = [];
|
|
6
|
+
htmlRewriterProvider;
|
|
7
|
+
constructor(options = {}) {
|
|
8
|
+
this.htmlRewriterProvider = options.htmlRewriterProvider ?? new DefaultHtmlRewriterProvider();
|
|
9
|
+
if (options.htmlRewriterMode) {
|
|
10
|
+
this.htmlRewriterProvider.setMode(options.htmlRewriterMode);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Overrides the HTML rewriter runtime selection.
|
|
15
|
+
*
|
|
16
|
+
* This is intended for internal/runtime tests that need deterministic
|
|
17
|
+
* selection between native, worker-tools, and string fallback behavior.
|
|
18
|
+
*
|
|
19
|
+
* @param mode Requested runtime selection strategy.
|
|
20
|
+
*/
|
|
21
|
+
setHtmlRewriterMode(mode) {
|
|
22
|
+
this.htmlRewriterProvider.setMode(mode);
|
|
23
|
+
}
|
|
24
|
+
formatAttributes(attrs) {
|
|
25
|
+
if (!attrs) return "";
|
|
26
|
+
return ` ${Object.entries(attrs).map(([key, value]) => `${key}="${value}"`).join(" ")}`;
|
|
27
|
+
}
|
|
28
|
+
generateScriptTag(dep) {
|
|
29
|
+
return dep.inline ? `<script${this.formatAttributes(dep.attributes)}>${dep.content}<\/script>` : `<script src="${dep.srcUrl}"${this.formatAttributes(dep.attributes)}><\/script>`;
|
|
30
|
+
}
|
|
31
|
+
generateStylesheetTag(dep) {
|
|
32
|
+
return dep.inline ? `<style${this.formatAttributes(dep.attributes)}>${dep.content}</style>` : `<link rel="stylesheet" href="${dep.srcUrl}"${this.formatAttributes(dep.attributes)}>`;
|
|
33
|
+
}
|
|
34
|
+
appendDependencies(element, dependencies) {
|
|
35
|
+
for (const dep of dependencies) {
|
|
36
|
+
const tag = dep.kind === "script" ? this.generateScriptTag(dep) : this.generateStylesheetTag(dep);
|
|
37
|
+
element.append(tag, { html: true });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
buildDependencyTags(dependencies) {
|
|
41
|
+
return dependencies.map(
|
|
42
|
+
(dep) => dep.kind === "script" ? this.generateScriptTag(dep) : this.generateStylesheetTag(dep)
|
|
43
|
+
).join("");
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Injects generated markup immediately before the closing HTML tag when it is
|
|
47
|
+
* present, or appends/prepends a fallback insertion otherwise.
|
|
48
|
+
*/
|
|
49
|
+
injectBeforeClosingTag(html, tag, content) {
|
|
50
|
+
if (!content) {
|
|
51
|
+
return html;
|
|
52
|
+
}
|
|
53
|
+
const closingTag = `</${tag}>`;
|
|
54
|
+
const lowerHtml = html.toLowerCase();
|
|
55
|
+
const closingTagIndex = lowerHtml.lastIndexOf(closingTag);
|
|
56
|
+
if (closingTagIndex !== -1) {
|
|
57
|
+
return `${html.slice(0, closingTagIndex)}${content}${html.slice(closingTagIndex)}`;
|
|
58
|
+
}
|
|
59
|
+
if (tag === "head") {
|
|
60
|
+
return `${content}${html}`;
|
|
61
|
+
}
|
|
62
|
+
return `${html}${content}`;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Replaces the current processed dependency set used during HTML finalization.
|
|
66
|
+
*/
|
|
67
|
+
setProcessedDependencies(processedDependencies) {
|
|
68
|
+
this.processedDependencies = processedDependencies;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Returns the processed dependencies queued for the next transform pass.
|
|
72
|
+
*/
|
|
73
|
+
getProcessedDependencies() {
|
|
74
|
+
return this.processedDependencies;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Applies attributes to the opening `<html>` tag when present.
|
|
78
|
+
*/
|
|
79
|
+
applyAttributesToHtmlElement(html, attributes) {
|
|
80
|
+
const htmlTagMatch = html.match(/<html\b[^>]*>/i);
|
|
81
|
+
if (!htmlTagMatch || htmlTagMatch.index === void 0) {
|
|
82
|
+
return html;
|
|
83
|
+
}
|
|
84
|
+
const attrs = this.buildAttributeString(attributes);
|
|
85
|
+
if (attrs.length === 0) {
|
|
86
|
+
return html;
|
|
87
|
+
}
|
|
88
|
+
const injectionOffset = htmlTagMatch.index + htmlTagMatch[0].length - 1;
|
|
89
|
+
return `${html.slice(0, injectionOffset)}${attrs}${html.slice(injectionOffset)}`;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Applies attributes to the first element nested directly under `<body>`.
|
|
93
|
+
*/
|
|
94
|
+
applyAttributesToFirstBodyElement(html, attributes) {
|
|
95
|
+
const bodyMatch = html.match(/<body\b[^>]*>/i);
|
|
96
|
+
if (!bodyMatch || bodyMatch.index === void 0) {
|
|
97
|
+
return html;
|
|
98
|
+
}
|
|
99
|
+
const bodyOpenEnd = bodyMatch.index + bodyMatch[0].length;
|
|
100
|
+
const afterBody = html.slice(bodyOpenEnd);
|
|
101
|
+
const firstTagMatch = afterBody.match(/^(\s*<)([a-zA-Z][a-zA-Z0-9:-]*)(\b[^>]*>)/);
|
|
102
|
+
if (!firstTagMatch || firstTagMatch.index === void 0) {
|
|
103
|
+
return html;
|
|
104
|
+
}
|
|
105
|
+
const attrs = this.buildAttributeString(attributes);
|
|
106
|
+
if (attrs.length === 0) {
|
|
107
|
+
return html;
|
|
108
|
+
}
|
|
109
|
+
const injectionOffset = bodyOpenEnd + firstTagMatch[1].length + firstTagMatch[2].length;
|
|
110
|
+
return `${html.slice(0, injectionOffset)}${attrs}${html.slice(injectionOffset)}`;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Applies attributes to the first element in a fragment or full-document HTML
|
|
114
|
+
* string.
|
|
115
|
+
*/
|
|
116
|
+
applyAttributesToFirstElement(html, attributes) {
|
|
117
|
+
const firstTagMatch = html.match(/^(\s*<)([a-zA-Z][a-zA-Z0-9:-]*)(\b[^>]*>)/);
|
|
118
|
+
if (!firstTagMatch || firstTagMatch.index === void 0) {
|
|
119
|
+
return html;
|
|
120
|
+
}
|
|
121
|
+
const attrs = this.buildAttributeString(attributes);
|
|
122
|
+
if (attrs.length === 0) {
|
|
123
|
+
return html;
|
|
124
|
+
}
|
|
125
|
+
const injectionOffset = firstTagMatch[1].length + firstTagMatch[2].length;
|
|
126
|
+
return `${html.slice(0, injectionOffset)}${attrs}${html.slice(injectionOffset)}`;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Removes duplicate processed assets while preserving first-seen order.
|
|
130
|
+
*
|
|
131
|
+
* @remarks
|
|
132
|
+
* Dedupe keys include structural asset fields and HTML attributes so repeated
|
|
133
|
+
* orchestration passes can merge assets safely without collapsing distinct tag
|
|
134
|
+
* variants.
|
|
135
|
+
*/
|
|
136
|
+
dedupeProcessedAssets(assets) {
|
|
137
|
+
const unique = /* @__PURE__ */ new Map();
|
|
138
|
+
for (const asset of assets) {
|
|
139
|
+
const key = [
|
|
140
|
+
asset.kind,
|
|
141
|
+
asset.position ?? "",
|
|
142
|
+
asset.srcUrl ?? "",
|
|
143
|
+
asset.filepath ?? "",
|
|
144
|
+
asset.content ?? "",
|
|
145
|
+
asset.inline ? "inline" : "external",
|
|
146
|
+
asset.excludeFromHtml ? "excluded" : "included",
|
|
147
|
+
JSON.stringify(asset.attributes ?? {})
|
|
148
|
+
].join("|");
|
|
149
|
+
if (!unique.has(key)) {
|
|
150
|
+
unique.set(key, asset);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return [...unique.values()];
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Injects the currently processed dependencies into an HTML response.
|
|
157
|
+
*
|
|
158
|
+
* @remarks
|
|
159
|
+
* Native or worker-tools HTML rewriter support is preferred when available. A
|
|
160
|
+
* string-based fallback remains in place for runtimes that cannot provide one
|
|
161
|
+
* of those rewriter implementations.
|
|
162
|
+
*/
|
|
163
|
+
async transform(res) {
|
|
164
|
+
const { head, body } = this.groupDependenciesByPosition();
|
|
165
|
+
const htmlRewriter = await this.htmlRewriterProvider.createHtmlRewriter();
|
|
166
|
+
const html = await res.text();
|
|
167
|
+
const headers = new Headers(res.headers);
|
|
168
|
+
if (htmlRewriter) {
|
|
169
|
+
htmlRewriter.on("head", {
|
|
170
|
+
element: (element) => this.appendDependencies(element, head)
|
|
171
|
+
}).on("body", {
|
|
172
|
+
element: (element) => this.appendDependencies(element, body)
|
|
173
|
+
});
|
|
174
|
+
return htmlRewriter.transform(
|
|
175
|
+
new Response(html, {
|
|
176
|
+
headers,
|
|
177
|
+
status: res.status,
|
|
178
|
+
statusText: res.statusText
|
|
179
|
+
})
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
const withHeadDependencies = this.injectBeforeClosingTag(html, "head", this.buildDependencyTags(head));
|
|
183
|
+
const transformedHtml = this.injectBeforeClosingTag(
|
|
184
|
+
withHeadDependencies,
|
|
185
|
+
"body",
|
|
186
|
+
this.buildDependencyTags(body)
|
|
187
|
+
);
|
|
188
|
+
return new Response(transformedHtml, {
|
|
189
|
+
headers,
|
|
190
|
+
status: res.status,
|
|
191
|
+
statusText: res.statusText
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Splits processed assets into head and body injection groups.
|
|
196
|
+
*/
|
|
197
|
+
groupDependenciesByPosition() {
|
|
198
|
+
return this.processedDependencies.reduce(
|
|
199
|
+
(acc, dep) => {
|
|
200
|
+
if (dep.kind === "script") {
|
|
201
|
+
if (dep.excludeFromHtml) return acc;
|
|
202
|
+
const position = dep.position || "body";
|
|
203
|
+
acc[position].push(dep);
|
|
204
|
+
} else if (dep.kind === "stylesheet") {
|
|
205
|
+
acc.head.push(dep);
|
|
206
|
+
}
|
|
207
|
+
return acc;
|
|
208
|
+
},
|
|
209
|
+
{ head: [], body: [] }
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Builds a serialized HTML attribute string from an attribute object.
|
|
214
|
+
*/
|
|
215
|
+
buildAttributeString(attributes) {
|
|
216
|
+
return Object.entries(attributes).filter(([key, value]) => key.length > 0 && value.length > 0).map(([key, value]) => ` ${key}="${value}"`).join("");
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
export {
|
|
220
|
+
HtmlTransformerService
|
|
221
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { EcoPagesAppConfig } from '../../internal-types.js';
|
|
2
|
+
export type DevelopmentInvalidationCategory = 'public-asset' | 'additional-watch' | 'include-source' | 'route-source' | 'processor-owned-asset' | 'server-source' | 'other';
|
|
3
|
+
/**
|
|
4
|
+
* Framework-owned invalidation plan for one changed file.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* This is the explicit invalidation matrix Workstream 4 needs. Watchers and
|
|
8
|
+
* runtime adapters consume this plan instead of encoding file-category rules in
|
|
9
|
+
* host-specific control flow.
|
|
10
|
+
*/
|
|
11
|
+
export interface DevelopmentInvalidationPlan {
|
|
12
|
+
category: DevelopmentInvalidationCategory;
|
|
13
|
+
invalidateServerModules: boolean;
|
|
14
|
+
refreshRoutes: boolean;
|
|
15
|
+
reloadBrowser: boolean;
|
|
16
|
+
delegateToHmr: boolean;
|
|
17
|
+
processorHandledAsset: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Framework-owned development invalidation service.
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* This service centralizes two responsibilities:
|
|
24
|
+
* - file-change classification for watcher behavior
|
|
25
|
+
* - app-owned server-module invalidation versioning backed by the dev graph
|
|
26
|
+
*
|
|
27
|
+
* Hosts and watchers should ask this service what a file change means instead
|
|
28
|
+
* of deciding invalidation semantics inline.
|
|
29
|
+
*/
|
|
30
|
+
export declare class DevelopmentInvalidationService {
|
|
31
|
+
private readonly appConfig;
|
|
32
|
+
constructor(appConfig: EcoPagesAppConfig);
|
|
33
|
+
/**
|
|
34
|
+
* Returns the current app-owned server-module invalidation version.
|
|
35
|
+
*/
|
|
36
|
+
getServerModuleInvalidationVersion(): number;
|
|
37
|
+
/**
|
|
38
|
+
* Invalidates the app-owned server-module graph.
|
|
39
|
+
*/
|
|
40
|
+
invalidateServerModules(changedFiles?: string[]): void;
|
|
41
|
+
/**
|
|
42
|
+
* Resets runtime-owned graph state and invalidates server modules.
|
|
43
|
+
*/
|
|
44
|
+
resetRuntimeState(changedFiles?: string[]): void;
|
|
45
|
+
/**
|
|
46
|
+
* Classifies one changed file into an explicit framework invalidation plan.
|
|
47
|
+
*/
|
|
48
|
+
planFileChange(filePath: string): DevelopmentInvalidationPlan;
|
|
49
|
+
/**
|
|
50
|
+
* Returns whether the file lives under the public directory.
|
|
51
|
+
*/
|
|
52
|
+
isPublicDirFile(filePath: string): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Returns whether the file matches `additionalWatchPaths`.
|
|
55
|
+
*/
|
|
56
|
+
matchesAdditionalWatchPaths(filePath: string): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Returns whether the file is a route source file.
|
|
59
|
+
*/
|
|
60
|
+
isRouteSourceFile(filePath: string): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Returns whether the file is an include/template source file.
|
|
63
|
+
*/
|
|
64
|
+
isIncludeSourceFile(filePath: string): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Returns whether the file is a server-executed source module outside the
|
|
67
|
+
* special route/include buckets.
|
|
68
|
+
*/
|
|
69
|
+
isServerModuleSourceFile(filePath: string): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Returns whether a processor owns the changed file as an asset input.
|
|
72
|
+
*/
|
|
73
|
+
isProcessorOwnedAsset(filePath: string): boolean;
|
|
74
|
+
}
|