@ecopages/core 0.2.0-alpha.26 → 0.2.0-alpha.28
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 +25 -0
- package/README.md +63 -7
- package/package.json +8 -94
- package/src/adapters/bun/create-app.d.ts +1 -0
- package/src/adapters/bun/create-app.js +39 -2
- package/src/adapters/bun/hmr-manager.d.ts +1 -13
- package/src/adapters/bun/hmr-manager.js +1 -22
- package/src/adapters/bun/server-adapter.js +23 -4
- package/src/adapters/node/node-hmr-manager.d.ts +2 -14
- package/src/adapters/node/node-hmr-manager.js +2 -23
- package/src/adapters/shared/explicit-static-render-preparation.d.ts +25 -0
- package/src/adapters/shared/explicit-static-render-preparation.js +26 -0
- package/src/adapters/shared/explicit-static-route-matcher.d.ts +5 -2
- package/src/adapters/shared/explicit-static-route-matcher.js +14 -16
- package/src/adapters/shared/file-route-middleware-pipeline.d.ts +7 -10
- package/src/adapters/shared/file-route-middleware-pipeline.js +2 -11
- package/src/adapters/shared/fs-server-response-factory.d.ts +13 -9
- package/src/adapters/shared/fs-server-response-factory.js +10 -26
- package/src/adapters/shared/fs-server-response-matcher.d.ts +14 -6
- package/src/adapters/shared/fs-server-response-matcher.js +67 -28
- package/src/adapters/shared/render-context.d.ts +2 -2
- package/src/adapters/shared/server-adapter.d.ts +21 -10
- package/src/adapters/shared/server-adapter.js +171 -132
- package/src/adapters/shared/server-route-handler.d.ts +2 -2
- package/src/adapters/shared/server-route-handler.js +1 -1
- package/src/adapters/shared/server-static-builder.d.ts +4 -4
- package/src/config/README.md +1 -1
- package/src/config/config-builder.d.ts +2 -2
- package/src/config/config-builder.js +0 -5
- package/src/dev/host-runtime.d.ts +10 -0
- package/src/dev/host-runtime.js +24 -0
- package/src/eco/eco.js +7 -7
- package/src/eco/eco.types.d.ts +3 -3
- package/src/errors/index.d.ts +1 -0
- package/src/errors/index.js +3 -1
- package/src/hmr/strategies/js-hmr-strategy.d.ts +0 -5
- package/src/integrations/ghtml/ghtml-renderer.d.ts +0 -4
- package/src/integrations/ghtml/ghtml-renderer.js +1 -7
- package/src/plugins/eco-component-meta-plugin.js +0 -1
- package/src/plugins/integration-plugin.d.ts +14 -18
- package/src/plugins/integration-plugin.js +14 -21
- package/src/plugins/processor.d.ts +2 -0
- package/src/plugins/processor.js +6 -1
- package/src/route-renderer/GRAPH.md +81 -289
- package/src/route-renderer/README.md +67 -105
- package/src/route-renderer/orchestration/component-render-context.d.ts +24 -18
- package/src/route-renderer/orchestration/component-render-context.js +14 -14
- package/src/route-renderer/orchestration/declared-ownership-graph.d.ts +18 -0
- package/src/route-renderer/orchestration/declared-ownership-graph.js +34 -0
- package/src/route-renderer/orchestration/foreign-subtree-execution.service.d.ts +108 -0
- package/src/route-renderer/orchestration/foreign-subtree-execution.service.js +206 -0
- package/src/route-renderer/orchestration/integration-renderer.d.ts +96 -136
- package/src/route-renderer/orchestration/integration-renderer.js +280 -303
- package/src/route-renderer/orchestration/ownership-planning.service.d.ts +24 -0
- package/src/route-renderer/orchestration/ownership-planning.service.js +63 -0
- package/src/route-renderer/orchestration/ownership-validation.service.d.ts +29 -0
- package/src/route-renderer/orchestration/ownership-validation.service.js +53 -0
- package/src/route-renderer/orchestration/queued-foreign-subtree-resolution.service.d.ts +90 -0
- package/src/route-renderer/orchestration/{queued-boundary-runtime.service.js → queued-foreign-subtree-resolution.service.js} +28 -25
- package/src/route-renderer/orchestration/render-output.utils.d.ts +3 -3
- package/src/route-renderer/orchestration/render-output.utils.js +6 -6
- package/src/route-renderer/orchestration/route-render-orchestrator.d.ts +120 -0
- package/src/route-renderer/orchestration/{render-preparation.service.js → route-render-orchestrator.js} +132 -108
- package/src/route-renderer/page-loading/component-dependency-collection.js +8 -1
- package/src/route-renderer/page-loading/dependency-resolver.js +5 -7
- package/src/route-renderer/page-loading/page-dependency-bundling.d.ts +1 -1
- package/src/route-renderer/page-loading/page-dependency-bundling.js +41 -19
- package/src/route-renderer/route-renderer.d.ts +28 -26
- package/src/route-renderer/route-renderer.js +4 -27
- package/src/router/README.md +16 -19
- package/src/router/server/route-registry.d.ts +78 -0
- package/src/router/server/route-registry.js +262 -0
- package/src/services/README.md +1 -2
- package/src/services/assets/asset-processing-service/assets.types.d.ts +3 -0
- package/src/services/assets/asset-processing-service/index.d.ts +1 -0
- package/src/services/assets/asset-processing-service/index.js +1 -0
- package/src/services/assets/asset-processing-service/page-package.d.ts +3 -0
- package/src/services/assets/asset-processing-service/page-package.js +74 -0
- package/src/services/assets/asset-processing-service/processors/base/base-script-processor.js +4 -4
- package/src/services/assets/asset-processing-service/processors/script/content-script.processor.js +6 -3
- package/src/services/assets/asset-processing-service/processors/script/file-script.processor.js +9 -3
- package/src/services/assets/asset-processing-service/processors/script/node-module-script.processor.js +4 -2
- package/src/services/assets/asset-processing-service/processors/stylesheet/content-stylesheet.processor.js +2 -1
- package/src/services/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.js +3 -1
- package/src/services/module-loading/node-bootstrap-plugin.js +15 -3
- package/src/static-site-generator/static-site-generator.d.ts +20 -21
- package/src/static-site-generator/static-site-generator.js +107 -140
- package/src/types/internal-types.d.ts +13 -12
- package/src/types/public-types.d.ts +46 -36
- package/src/watchers/project-watcher.test-helpers.js +5 -5
- package/src/route-renderer/orchestration/boundary-planning.service.d.ts +0 -25
- package/src/route-renderer/orchestration/boundary-planning.service.js +0 -97
- package/src/route-renderer/orchestration/page-packaging.service.d.ts +0 -16
- package/src/route-renderer/orchestration/page-packaging.service.js +0 -66
- package/src/route-renderer/orchestration/queued-boundary-runtime.service.d.ts +0 -89
- package/src/route-renderer/orchestration/render-execution.service.d.ts +0 -43
- package/src/route-renderer/orchestration/render-execution.service.js +0 -106
- package/src/route-renderer/orchestration/render-preparation.service.d.ts +0 -120
- package/src/route-renderer/orchestration/route-shell-composer.service.d.ts +0 -50
- package/src/route-renderer/orchestration/route-shell-composer.service.js +0 -81
- package/src/router/server/fs-router-scanner.d.ts +0 -41
- package/src/router/server/fs-router-scanner.js +0 -161
- package/src/router/server/fs-router.d.ts +0 -26
- package/src/router/server/fs-router.js +0 -100
- package/src/services/runtime-state/runtime-specifier-registry.service.d.ts +0 -69
- package/src/services/runtime-state/runtime-specifier-registry.service.js +0 -37
|
@@ -6,151 +6,113 @@ This folder contains the core rendering orchestration for Ecopages.
|
|
|
6
6
|
|
|
7
7
|
The route renderer layer is responsible for:
|
|
8
8
|
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
9
|
+
- selecting the correct integration renderer for a route
|
|
10
|
+
- loading page modules and resolving static data or metadata
|
|
11
|
+
- resolving component dependencies and page browser assets
|
|
12
|
+
- coordinating mixed-integration rendering
|
|
13
|
+
- emitting final HTML plus cache strategy
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## Core Concepts
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
The architecture is organized around three distinct concepts:
|
|
18
18
|
|
|
19
|
-
- `
|
|
20
|
-
- `
|
|
19
|
+
- `ownership`: preparation-time metadata that describes which integration owns each declared component edge
|
|
20
|
+
- `foreign child`: a component encountered during render whose owning integration differs from the current integration
|
|
21
|
+
- `foreign subtree`: the resolved HTML, assets, and root-attachment metadata returned by the owning renderer for that foreign child
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
These concepts intentionally live in different places:
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
- `ownership-planning.service.ts` builds `ownershipPlan`
|
|
26
|
+
- `ownership-validation.service.ts` validates declared foreign ownership up front
|
|
27
|
+
- `component-render-context.ts` intercepts foreign children during active component render
|
|
28
|
+
- `queued-foreign-subtree-resolution.service.ts` resolves queued foreign subtrees for renderers that cannot hand them off inline
|
|
29
|
+
- `integration-renderer.ts` owns renderer-to-renderer delegation and shared shell composition
|
|
30
|
+
- `route-render-flow.ts` owns route preparation, final response capture, and unresolved artifact enforcement
|
|
25
31
|
|
|
26
|
-
|
|
27
|
-
- `render-preparation.service.ts`: page module/data/dependency preparation before render.
|
|
28
|
-
- `render-execution.service.ts`: render capture, unresolved boundary artifact enforcement, and finalization.
|
|
29
|
-
- `route-shell-composer.service.ts`: shared page/view/layout/html-template shell composition used by multiple integrations.
|
|
30
|
-
- `queued-boundary-runtime.service.ts`: shared queued foreign-boundary runtime used directly by renderer-owned helpers, including string-first renderers.
|
|
32
|
+
## Main Files
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
### `route-renderer.ts`
|
|
33
35
|
|
|
34
|
-
- `
|
|
35
|
-
- `
|
|
36
|
-
- deferred boundary resolution for nested cross-integration component boundaries.
|
|
36
|
+
- `RouteRendererFactory` chooses integration renderers from route files
|
|
37
|
+
- `RouteRenderer` delegates execution to the selected renderer
|
|
37
38
|
|
|
38
|
-
###
|
|
39
|
+
### `orchestration/`
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
- `route-render-flow.ts`: one route render from page-module loading through final HTML output
|
|
42
|
+
- `integration-renderer.ts`: abstract base class for route rendering, explicit view rendering, and foreign-child delegation
|
|
43
|
+
- `ownership-planning.service.ts`: declared ownership graph construction
|
|
44
|
+
- `ownership-validation.service.ts`: up-front ownership validation for route roots and declared descendants
|
|
45
|
+
- `component-render-context.ts`: active render context used by `eco.component()` to intercept foreign children
|
|
46
|
+
- `queued-foreign-subtree-resolution.service.ts`: queue resolution for renderers that need token-based foreign-subtree handoff
|
|
47
|
+
- `render-output.utils.ts`: unresolved artifact normalization and marker inspection
|
|
41
48
|
|
|
42
49
|
### `page-loading/`
|
|
43
50
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
- `importPageFile()` runtime-aware loading.
|
|
47
|
-
- `resolvePageModule()` normalizes exports and statics.
|
|
48
|
-
- `resolvePageData()` resolves static props then metadata.
|
|
49
|
-
|
|
50
|
-
Builds processed assets from component dependency declarations:
|
|
51
|
+
- `page-module-loader.ts`: imports page modules and normalizes page exports
|
|
52
|
+
- `dependency-resolver.ts`: resolves component dependencies and browser-facing assets
|
|
51
53
|
|
|
52
|
-
|
|
53
|
-
- Lazy dependency grouping and trigger derivation.
|
|
54
|
-
- Default global injector behavior with optional legacy scripts-injector compatibility.
|
|
54
|
+
## Render Flow
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
The route-render contract is:
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
The current mixed-renderer contract has four phases:
|
|
66
|
-
|
|
67
|
-
1. `render-preparation.service.ts` builds the route inputs and a conservative `boundaryPlan` from declared component dependencies.
|
|
68
|
-
2. The selected integration renderer owns page, layout, document-shell, and explicit-view composition for that route.
|
|
69
|
-
3. `route-shell-composer.service.ts` applies the shared page/view/layout/html-template composition flow while calling back into the owning renderer for each boundary render.
|
|
70
|
-
4. Renderer-owned boundary runtimes resolve foreign nested components through the owning renderer and exchange a compatibility `renderBoundary()` payload with explicit attachment-policy semantics.
|
|
71
|
-
5. `render-execution.service.ts` finalizes the response and fails if unresolved boundary artifact HTML survives the renderer-owned resolution pass.
|
|
58
|
+
1. `RouteRendererFactory` selects the owning integration renderer.
|
|
59
|
+
2. `IntegrationRenderer.execute()` delegates preparation and finalization to `RouteRenderFlow`.
|
|
60
|
+
3. `RouteRenderFlow.prepareRenderOptions()` loads the page module, validates ownership, builds `ownershipPlan`, resolves page data, resolves dependencies, and builds the page browser graph.
|
|
61
|
+
4. The integration renderer performs page, layout, and document-shell rendering. When it encounters a foreign child, it delegates that child back to the owning renderer.
|
|
62
|
+
5. If a renderer needs queued handoff, it emits internal foreign-subtree tokens and resolves them before returning final HTML.
|
|
63
|
+
6. `RouteRenderFlow.execute()` captures the final body, rejects unresolved `<eco-marker>` artifacts, stamps root or document attributes when needed, and runs the HTML transformer.
|
|
72
64
|
|
|
73
65
|
Important:
|
|
74
66
|
|
|
75
|
-
-
|
|
76
|
-
-
|
|
77
|
-
-
|
|
67
|
+
- route-level fallback resolution is gone; unresolved artifacts are now a hard failure
|
|
68
|
+
- ownership is declared from component metadata, not inferred from final HTML
|
|
69
|
+
- same-integration children stay renderer-local and do not need to pass through a universal transport
|
|
78
70
|
|
|
79
71
|
## Declared Foreign Child Contract
|
|
80
72
|
|
|
81
|
-
Mixed-integration component configs must declare every possible foreign child in `config.dependencies.components`.
|
|
82
|
-
|
|
83
|
-
Current behavior:
|
|
73
|
+
Mixed-integration component configs must declare every possible foreign child in `config.dependencies.components`.
|
|
84
74
|
|
|
85
|
-
|
|
86
|
-
- Renderer-owned runtime discovery still resolves actual foreign descendants during render.
|
|
87
|
-
- If unresolved boundary artifact HTML reaches route finalization, Ecopages throws instead of attempting a route-level recovery pass.
|
|
75
|
+
That declaration is used for two things:
|
|
88
76
|
|
|
89
|
-
|
|
77
|
+
- `OwnershipValidationService` surfaces missing metadata or unknown integrations before render execution
|
|
78
|
+
- `OwnershipPlanningService` records the expected ownership shape in `ownershipPlan`
|
|
90
79
|
|
|
91
|
-
|
|
92
|
-
- On `eco:after-swap`, it prunes stale `ecopages/global-injector-map` scripts and calls `refresh()` so newly swapped `data-eco-trigger` elements can bind their lazy rules.
|
|
93
|
-
- It must not call injector `cleanup()` on every swap, because that permanently disables future refresh work for the current runtime instance.
|
|
80
|
+
At runtime, renderers still discover actual foreign children through the active component render context.
|
|
94
81
|
|
|
95
|
-
##
|
|
82
|
+
## Foreign Subtree Contract
|
|
96
83
|
|
|
97
|
-
|
|
84
|
+
`renderForeignSubtree()` is the compatibility contract for renderer-to-renderer handoff. It returns:
|
|
98
85
|
|
|
99
86
|
- `html`
|
|
100
87
|
- `assets`
|
|
101
88
|
- `rootTag`
|
|
102
|
-
- `integrationName`
|
|
103
89
|
- optional `rootAttributes`
|
|
104
90
|
- `attachmentPolicy`
|
|
105
|
-
|
|
106
|
-
`renderComponent()` still returns `ComponentRenderResult` internally, including `canAttachAttributes`, because renderer-local implementations have not been collapsed into one universal boundary primitive.
|
|
107
|
-
|
|
108
|
-
Base orchestration uses the compatibility payload to:
|
|
109
|
-
|
|
110
|
-
- keep queued foreign-boundary resolution renderer-owned
|
|
111
|
-
- apply root attributes only when `attachmentPolicy.kind === 'first-element'`
|
|
112
|
-
- preserve asset bubbling through the normal dependency pipeline
|
|
113
|
-
|
|
114
|
-
The lower-level `ComponentRenderResult` currently includes:
|
|
115
|
-
|
|
116
|
-
- `html`
|
|
117
|
-
- `canAttachAttributes`
|
|
118
|
-
- `rootTag`
|
|
119
91
|
- `integrationName`
|
|
120
|
-
- optional `rootAttributes`
|
|
121
|
-
- optional `assets`
|
|
122
|
-
|
|
123
|
-
When rendered output still contains unresolved boundary artifact HTML:
|
|
124
92
|
|
|
125
|
-
|
|
126
|
-
- renderer-owned boundary runtimes are responsible for resolving foreign nested components before final route HTML is returned.
|
|
93
|
+
`renderComponentWithForeignChildren()` is the higher-level renderer entrypoint. It is responsible for:
|
|
127
94
|
|
|
128
|
-
|
|
95
|
+
- reusing the execution-scoped owning-renderer cache
|
|
96
|
+
- deciding whether the current component can stay local
|
|
97
|
+
- creating a foreign-child runtime when nested foreign ownership must be resolved
|
|
98
|
+
- normalizing unresolved artifact HTML before the render leaves the renderer
|
|
129
99
|
|
|
130
|
-
##
|
|
100
|
+
## Queue Model
|
|
131
101
|
|
|
132
|
-
|
|
133
|
-
- The React integration attaches `data-eco-component-id` on the component's own SSR root element when a single root is available.
|
|
134
|
-
- Island client bootstrap mounts with `createRoot()` into that root boundary.
|
|
135
|
-
- The emitted hydration bootstrap also listens for `eco:after-swap` so islands hydrate correctly when their SSR markup appears after client-side navigation.
|
|
136
|
-
- React hydration bootstraps are emitted with `data-eco-rerun` and stable `data-eco-script-id` metadata so head-script reconciliation can safely re-execute them when needed.
|
|
137
|
-
- This keeps authored DOM shape stable for global layout/style selectors while preserving per-island runtime isolation.
|
|
102
|
+
Not every integration needs queue-based handoff.
|
|
138
103
|
|
|
139
|
-
|
|
104
|
+
- If a renderer can resolve a foreign child inline, it returns resolved output immediately.
|
|
105
|
+
- If it cannot, it may emit internal foreign-subtree tokens and resolve them before returning final HTML.
|
|
106
|
+
- The queue service is only for renderer-owned transport inside one render pass. It is not a general route-level fallback mechanism.
|
|
140
107
|
|
|
141
|
-
|
|
142
|
-
2. Integration renderer prepares render options.
|
|
143
|
-
3. Dependencies are resolved and processed.
|
|
144
|
-
4. Orchestration assets/artifacts are merged.
|
|
145
|
-
5. Integration renderer generates HTML body.
|
|
146
|
-
6. HTML transformer injects head/body dependencies.
|
|
147
|
-
7. Route result returns body + metadata + cache strategy.
|
|
108
|
+
## React Island Notes
|
|
148
109
|
|
|
149
|
-
|
|
110
|
+
- React islands are emitted without synthetic wrapper elements.
|
|
111
|
+
- The React integration attaches `data-eco-component-id` to the SSR root when a single root exists.
|
|
112
|
+
- The island bootstrap mounts with `createRoot()` into that SSR root.
|
|
113
|
+
- Hydration bootstraps listen for `eco:after-swap` so islands hydrate after client-side navigation.
|
|
150
114
|
|
|
151
|
-
|
|
115
|
+
## Current Limits
|
|
152
116
|
|
|
153
|
-
-
|
|
154
|
-
-
|
|
155
|
-
- `boundaryPlan` is currently preparation-time metadata and diagnostics. It does not yet drive a full route-composer execution model.
|
|
156
|
-
- A narrow `RouteShellComposer` now owns shared shell composition, but a broader route composer that absorbs boundary ownership or execution flow is still deferred.
|
|
117
|
+
- `ownershipPlan` is still diagnostic and preparatory metadata; it does not yet drive a full route-composer execution model.
|
|
118
|
+
- Different integrations still own different foreign-child runtime strategies, which is intentional where child transport or hydration behavior differs.
|
|
@@ -1,50 +1,56 @@
|
|
|
1
1
|
import type { EcoComponent } from '../../types/public-types.js';
|
|
2
2
|
/**
|
|
3
|
-
* Result returned by a renderer-owned
|
|
3
|
+
* Result returned by a renderer-owned foreign-child runtime.
|
|
4
4
|
*
|
|
5
5
|
* `inline` keeps rendering inside the current integration. `resolved` returns a
|
|
6
6
|
* renderer-owned value immediately, which can be final HTML or a renderer-local
|
|
7
7
|
* transport token for later queue resolution.
|
|
8
8
|
*/
|
|
9
|
-
export type
|
|
9
|
+
export type ForeignChildInterceptionResult = {
|
|
10
10
|
kind: 'inline';
|
|
11
11
|
} | {
|
|
12
12
|
kind: 'resolved';
|
|
13
13
|
value: unknown;
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* Foreign-child metadata passed into the active renderer-owned runtime.
|
|
17
17
|
*/
|
|
18
|
-
export type
|
|
18
|
+
export type ForeignChildInterceptionInput = {
|
|
19
19
|
currentIntegration: string;
|
|
20
20
|
targetIntegration?: string;
|
|
21
21
|
component: EcoComponent;
|
|
22
22
|
props: Record<string, unknown>;
|
|
23
23
|
};
|
|
24
24
|
/**
|
|
25
|
-
* Narrow renderer-owned
|
|
25
|
+
* Narrow renderer-owned foreign-child runtime injected into one active render
|
|
26
26
|
* context.
|
|
27
27
|
*
|
|
28
|
-
* Integrations implement this contract when foreign
|
|
28
|
+
* Integrations implement this contract when foreign children must be handed
|
|
29
29
|
* off inside the renderer instead of being left for route-level reconciliation.
|
|
30
30
|
*/
|
|
31
|
-
export interface
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
export interface ForeignChildRuntime {
|
|
32
|
+
/**
|
|
33
|
+
* Intercepts one foreign child during an active render.
|
|
34
|
+
*
|
|
35
|
+
* This runtime is typically installed by the Foreign Subtree execution module,
|
|
36
|
+
* which decides whether the child stays inline or leaves the current renderer.
|
|
37
|
+
*/
|
|
38
|
+
interceptForeignChild?(input: ForeignChildInterceptionInput): ForeignChildInterceptionResult | Promise<ForeignChildInterceptionResult>;
|
|
39
|
+
interceptForeignChildSync?(input: ForeignChildInterceptionInput): ForeignChildInterceptionResult;
|
|
34
40
|
}
|
|
35
|
-
type
|
|
41
|
+
type ForeignChildRenderInput = {
|
|
36
42
|
component: EcoComponent;
|
|
37
43
|
props: Record<string, unknown>;
|
|
38
44
|
targetIntegration?: string;
|
|
39
45
|
};
|
|
40
46
|
/**
|
|
41
|
-
* Per-render mutable state used while applying
|
|
47
|
+
* Per-render mutable state used while applying foreign-child interception and lazy
|
|
42
48
|
* output wrapping.
|
|
43
49
|
*/
|
|
44
50
|
export type ComponentRenderContext = {
|
|
45
51
|
currentIntegration: string;
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
foreignChildRuntime?: ForeignChildRuntime;
|
|
53
|
+
interceptForeignChild(input: ForeignChildRenderInput): Promise<unknown | undefined> | unknown | undefined;
|
|
48
54
|
finalizeComponentRender<T>(component: EcoComponent, content: T): T;
|
|
49
55
|
};
|
|
50
56
|
/**
|
|
@@ -54,11 +60,11 @@ export type ComponentRenderContext = {
|
|
|
54
60
|
*/
|
|
55
61
|
export declare function getComponentRenderContext(): ComponentRenderContext | undefined;
|
|
56
62
|
/**
|
|
57
|
-
* Runs
|
|
63
|
+
* Runs foreign-child interception for one component render step.
|
|
58
64
|
*
|
|
59
|
-
* The active runtime may resolve the
|
|
65
|
+
* The active runtime may resolve the foreign child immediately or keep it inline.
|
|
60
66
|
*/
|
|
61
|
-
export declare function
|
|
67
|
+
export declare function interceptForeignChild(input: ForeignChildRenderInput): Promise<unknown | undefined> | unknown | undefined;
|
|
62
68
|
/**
|
|
63
69
|
* Applies lazy trigger or injector wrapping to completed component output.
|
|
64
70
|
*
|
|
@@ -70,13 +76,13 @@ export declare function finalizeComponentRender<T>(component: EcoComponent, cont
|
|
|
70
76
|
* Runs render work under a fresh component render context and returns the
|
|
71
77
|
* resulting value.
|
|
72
78
|
*
|
|
73
|
-
* @param input Execution metadata for current integration and
|
|
79
|
+
* @param input Execution metadata for current integration and foreign-child policy.
|
|
74
80
|
* @param render Async render function to execute inside the context.
|
|
75
81
|
* @returns Render result value.
|
|
76
82
|
*/
|
|
77
83
|
export declare function runWithComponentRenderContext<T>(input: {
|
|
78
84
|
currentIntegration: string;
|
|
79
|
-
|
|
85
|
+
foreignChildRuntime?: ForeignChildRuntime;
|
|
80
86
|
}, render: () => Promise<T>): Promise<{
|
|
81
87
|
value: T;
|
|
82
88
|
}>;
|
|
@@ -30,36 +30,36 @@ class ContextualComponentRenderRuntime extends ComponentRenderOutputRuntime {
|
|
|
30
30
|
super();
|
|
31
31
|
this.context = context;
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
applyForeignChildInterceptionResult(result) {
|
|
34
34
|
if (result.kind === "resolved") {
|
|
35
35
|
return result.value;
|
|
36
36
|
}
|
|
37
37
|
return void 0;
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
|
-
* Resolves one
|
|
40
|
+
* Resolves one foreign-child interception through the active runtime.
|
|
41
41
|
*
|
|
42
42
|
* The runtime may choose inline rendering or immediate resolved output.
|
|
43
43
|
*/
|
|
44
|
-
|
|
45
|
-
const
|
|
44
|
+
interceptForeignChild(input) {
|
|
45
|
+
const foreignChildRuntimeInput = {
|
|
46
46
|
currentIntegration: this.context.currentIntegration,
|
|
47
47
|
targetIntegration: input.targetIntegration,
|
|
48
48
|
component: input.component,
|
|
49
49
|
props: input.props
|
|
50
50
|
};
|
|
51
|
-
const asyncInterception = this.context.
|
|
51
|
+
const asyncInterception = this.context.foreignChildRuntime?.interceptForeignChild?.(foreignChildRuntimeInput);
|
|
52
52
|
if (asyncInterception !== void 0) {
|
|
53
53
|
if (isThenable(asyncInterception)) {
|
|
54
|
-
return asyncInterception.then((result) => this.
|
|
54
|
+
return asyncInterception.then((result) => this.applyForeignChildInterceptionResult(result));
|
|
55
55
|
}
|
|
56
|
-
return this.
|
|
56
|
+
return this.applyForeignChildInterceptionResult(asyncInterception);
|
|
57
57
|
}
|
|
58
|
-
const syncInterception = this.context.
|
|
58
|
+
const syncInterception = this.context.foreignChildRuntime?.interceptForeignChildSync?.(foreignChildRuntimeInput);
|
|
59
59
|
if (syncInterception === void 0) {
|
|
60
60
|
return void 0;
|
|
61
61
|
}
|
|
62
|
-
return this.
|
|
62
|
+
return this.applyForeignChildInterceptionResult(syncInterception);
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
const GLOBAL_COMPONENT_RENDER_CONTEXT_STATE_KEY = "__ECOPAGES_COMPONENT_RENDER_CONTEXT_STATE__";
|
|
@@ -107,8 +107,8 @@ function getComponentRenderContext() {
|
|
|
107
107
|
return state.nodeContextStorage?.getStore() ?? state.contextStack[state.contextStack.length - 1];
|
|
108
108
|
}
|
|
109
109
|
const componentRenderOutputRuntime = new ComponentRenderOutputRuntime();
|
|
110
|
-
function
|
|
111
|
-
return getComponentRenderContext()?.
|
|
110
|
+
function interceptForeignChild(input) {
|
|
111
|
+
return getComponentRenderContext()?.interceptForeignChild(input);
|
|
112
112
|
}
|
|
113
113
|
function finalizeComponentRender(component, content) {
|
|
114
114
|
const renderContext = getComponentRenderContext();
|
|
@@ -117,10 +117,10 @@ function finalizeComponentRender(component, content) {
|
|
|
117
117
|
async function runWithComponentRenderContext(input, render) {
|
|
118
118
|
const context = {
|
|
119
119
|
currentIntegration: input.currentIntegration,
|
|
120
|
-
|
|
120
|
+
foreignChildRuntime: input.foreignChildRuntime
|
|
121
121
|
};
|
|
122
122
|
const runtime = new ContextualComponentRenderRuntime(context);
|
|
123
|
-
context.
|
|
123
|
+
context.interceptForeignChild = (deferredInput) => runtime.interceptForeignChild(deferredInput);
|
|
124
124
|
context.finalizeComponentRender = (component, content) => runtime.finalizeComponentRender(component, content);
|
|
125
125
|
const storage = await getContextStorage();
|
|
126
126
|
let value;
|
|
@@ -142,6 +142,6 @@ async function runWithComponentRenderContext(input, render) {
|
|
|
142
142
|
export {
|
|
143
143
|
finalizeComponentRender,
|
|
144
144
|
getComponentRenderContext,
|
|
145
|
-
|
|
145
|
+
interceptForeignChild,
|
|
146
146
|
runWithComponentRenderContext
|
|
147
147
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { EcoComponent, OwnershipPlanNodeSource } from '../../types/public-types.js';
|
|
2
|
+
export type DeclaredOwnershipRoot = {
|
|
3
|
+
component: EcoComponent;
|
|
4
|
+
source: Extract<OwnershipPlanNodeSource, 'page' | 'layout' | 'html-template'>;
|
|
5
|
+
};
|
|
6
|
+
export type DeclaredOwnershipNodeInput = {
|
|
7
|
+
component: EcoComponent;
|
|
8
|
+
source: Exclude<OwnershipPlanNodeSource, 'route'>;
|
|
9
|
+
parentIntegrationName: string;
|
|
10
|
+
integrationName: string;
|
|
11
|
+
componentId: string;
|
|
12
|
+
isForeignToParent: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare function mapDeclaredOwnershipGraph<T>(input: {
|
|
15
|
+
roots: DeclaredOwnershipRoot[];
|
|
16
|
+
currentIntegrationName: string;
|
|
17
|
+
mapNode: (node: DeclaredOwnershipNodeInput, children: T[]) => T;
|
|
18
|
+
}): T[];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
function mapDeclaredOwnershipGraph(input) {
|
|
2
|
+
let nextSyntheticId = 0;
|
|
3
|
+
const mapComponent = (component, source, parentIntegrationName, lineage) => {
|
|
4
|
+
const integrationName = component.config?.integration ?? component.config?.__eco?.integration ?? parentIntegrationName;
|
|
5
|
+
const componentMeta = component.config?.__eco;
|
|
6
|
+
const isForeignToParent = integrationName !== parentIntegrationName;
|
|
7
|
+
const componentId = componentMeta?.id ?? componentMeta?.file ?? `${source}:${nextSyntheticId += 1}`;
|
|
8
|
+
const nextLineage = new Set(lineage);
|
|
9
|
+
nextLineage.add(component);
|
|
10
|
+
const children = (component.config?.dependencies?.components ?? []).flatMap((child) => {
|
|
11
|
+
if (!child || nextLineage.has(child)) {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
return [mapComponent(child, "dependency", integrationName, nextLineage)];
|
|
15
|
+
});
|
|
16
|
+
return input.mapNode(
|
|
17
|
+
{
|
|
18
|
+
component,
|
|
19
|
+
source,
|
|
20
|
+
parentIntegrationName,
|
|
21
|
+
integrationName,
|
|
22
|
+
componentId,
|
|
23
|
+
isForeignToParent
|
|
24
|
+
},
|
|
25
|
+
children
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
return input.roots.map(
|
|
29
|
+
({ component, source }) => mapComponent(component, source, input.currentIntegrationName, /* @__PURE__ */ new Set())
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
mapDeclaredOwnershipGraph
|
|
34
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { ProcessedAsset } from '../../services/assets/asset-processing-service/index.js';
|
|
2
|
+
import type { BaseIntegrationContext, ComponentRenderInput, ComponentRenderResult, EcoComponent, ForeignSubtreeRenderPayload } from '../../types/public-types.js';
|
|
3
|
+
import { type ForeignChildRuntime } from './component-render-context.js';
|
|
4
|
+
import { QueuedForeignSubtreeResolutionService, type QueuedForeignSubtreeResolution, type QueuedForeignSubtreeResolutionContext } from './queued-foreign-subtree-resolution.service.js';
|
|
5
|
+
export interface ForeignSubtreeExecutionOwningRenderer {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
renderComponentWithForeignChildren(input: ComponentRenderInput): Promise<ComponentRenderResult>;
|
|
8
|
+
renderForeignSubtree(input: ComponentRenderInput): Promise<ForeignSubtreeRenderPayload>;
|
|
9
|
+
}
|
|
10
|
+
export interface ForeignSubtreeExecutionDecisionInput {
|
|
11
|
+
currentIntegration: string;
|
|
12
|
+
targetIntegration?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface ForeignSubtreeExecutionRenderOptions {
|
|
15
|
+
currentIntegrationName: string;
|
|
16
|
+
input: ComponentRenderInput;
|
|
17
|
+
renderComponent(input: ComponentRenderInput): Promise<ComponentRenderResult>;
|
|
18
|
+
normalizeComponentRenderOutput(result: ComponentRenderResult): ComponentRenderResult;
|
|
19
|
+
hasForeignChildDescendants(component: EcoComponent): boolean;
|
|
20
|
+
createForeignChildRuntime(options: {
|
|
21
|
+
renderInput: ComponentRenderInput;
|
|
22
|
+
rendererCache: Map<string, ForeignSubtreeExecutionOwningRenderer>;
|
|
23
|
+
}): ForeignChildRuntime;
|
|
24
|
+
getOwningRenderer(integrationName: string, rendererCache: Map<string, ForeignSubtreeExecutionOwningRenderer>): ForeignSubtreeExecutionOwningRenderer;
|
|
25
|
+
}
|
|
26
|
+
export interface ForeignSubtreeQueuedRuntimeOptions<TContext extends QueuedForeignSubtreeResolutionContext> {
|
|
27
|
+
renderInput: ComponentRenderInput;
|
|
28
|
+
rendererCache: Map<string, ForeignSubtreeExecutionOwningRenderer>;
|
|
29
|
+
runtimeContextKey: string;
|
|
30
|
+
tokenPrefix: string;
|
|
31
|
+
createRuntimeContext?: (integrationContext: BaseIntegrationContext & Record<string, unknown>, rendererCache: Map<string, unknown>) => TContext;
|
|
32
|
+
}
|
|
33
|
+
export interface ForeignSubtreeStringQueuedHtmlOptions {
|
|
34
|
+
currentIntegrationName: string;
|
|
35
|
+
renderInput: ComponentRenderInput;
|
|
36
|
+
html: string;
|
|
37
|
+
runtimeContextKey: string;
|
|
38
|
+
queueLabel: string;
|
|
39
|
+
getOwningRenderer(integrationName: string, rendererCache: Map<string, ForeignSubtreeExecutionOwningRenderer>): ForeignSubtreeExecutionOwningRenderer;
|
|
40
|
+
applyAttributesToFirstElement(html: string, attributes: Record<string, string>): string;
|
|
41
|
+
dedupeProcessedAssets(assets: ProcessedAsset[]): ProcessedAsset[];
|
|
42
|
+
}
|
|
43
|
+
export interface ForeignSubtreeQueuedHtmlOptions<TContext extends QueuedForeignSubtreeResolutionContext> {
|
|
44
|
+
currentIntegrationName: string;
|
|
45
|
+
html: string;
|
|
46
|
+
runtimeContext?: TContext;
|
|
47
|
+
queueLabel: string;
|
|
48
|
+
renderQueuedChildren(children: unknown, runtimeContext: TContext, queuedResolutionsByToken: Map<string, QueuedForeignSubtreeResolution>, resolveToken: (token: string) => Promise<string>): Promise<{
|
|
49
|
+
assets: ProcessedAsset[];
|
|
50
|
+
html?: string;
|
|
51
|
+
}>;
|
|
52
|
+
getOwningRenderer(integrationName: string, rendererCache: Map<string, ForeignSubtreeExecutionOwningRenderer>): ForeignSubtreeExecutionOwningRenderer;
|
|
53
|
+
applyAttributesToFirstElement(html: string, attributes: Record<string, string>): string;
|
|
54
|
+
dedupeProcessedAssets(assets: ProcessedAsset[]): ProcessedAsset[];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Executes one component render tree under Foreign Child support.
|
|
58
|
+
*
|
|
59
|
+
* This service owns the execution policy for mixed-integration component trees:
|
|
60
|
+
* it decides when a child stays inline, when it must delegate to an owning
|
|
61
|
+
* renderer, how one render-pass renderer cache is reused, and how queued
|
|
62
|
+
* Foreign Subtree tokens resolve back into final HTML.
|
|
63
|
+
*/
|
|
64
|
+
export declare class ForeignSubtreeExecutionService {
|
|
65
|
+
private readonly queuedForeignSubtreeResolutionService;
|
|
66
|
+
constructor(queuedForeignSubtreeResolutionService?: QueuedForeignSubtreeResolutionService);
|
|
67
|
+
/**
|
|
68
|
+
* Returns whether the current render pass must hand the child off to a foreign owner.
|
|
69
|
+
*/
|
|
70
|
+
shouldDelegateForeignChild(input: ForeignSubtreeExecutionDecisionInput): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Creates the base runtime used when a renderer has not supplied its own queueing runtime.
|
|
73
|
+
*
|
|
74
|
+
* The runtime allows same-integration children to continue inline and fails fast
|
|
75
|
+
* when execution crosses into a foreign owner without a renderer-owned handoff.
|
|
76
|
+
*/
|
|
77
|
+
createFailFastRuntime(rendererName: string): ForeignChildRuntime;
|
|
78
|
+
getQueuedRuntimeContext<TContext extends QueuedForeignSubtreeResolutionContext>(input: ComponentRenderInput, runtimeContextKey: string): TContext | undefined;
|
|
79
|
+
createQueuedRuntime<TContext extends QueuedForeignSubtreeResolutionContext>(options: ForeignSubtreeQueuedRuntimeOptions<TContext>): ForeignChildRuntime;
|
|
80
|
+
/**
|
|
81
|
+
* Resolves a string-first renderer HTML fragment that may contain queued Foreign Subtree tokens.
|
|
82
|
+
*/
|
|
83
|
+
resolveStringQueuedHtml<TContext extends QueuedForeignSubtreeResolutionContext>(options: ForeignSubtreeStringQueuedHtmlOptions): Promise<{
|
|
84
|
+
assets: ProcessedAsset[];
|
|
85
|
+
html: string;
|
|
86
|
+
}>;
|
|
87
|
+
resolveQueuedHtml<TContext extends QueuedForeignSubtreeResolutionContext>(options: ForeignSubtreeQueuedHtmlOptions<TContext>): Promise<{
|
|
88
|
+
assets: ProcessedAsset[];
|
|
89
|
+
html: string;
|
|
90
|
+
}>;
|
|
91
|
+
/**
|
|
92
|
+
* Executes one component render with Foreign Child support under the current integration.
|
|
93
|
+
*/
|
|
94
|
+
executeComponentRender(options: ForeignSubtreeExecutionRenderOptions): Promise<ComponentRenderResult>;
|
|
95
|
+
private getRendererCache;
|
|
96
|
+
private withRendererCache;
|
|
97
|
+
/**
|
|
98
|
+
* Returns the delegatable owning renderer integration for one component.
|
|
99
|
+
*
|
|
100
|
+
* The pseudo `html` integration marks document-shell ownership only and does
|
|
101
|
+
* not participate in component-level foreign subtree execution.
|
|
102
|
+
*/
|
|
103
|
+
private getForeignOwnerIntegrationName;
|
|
104
|
+
private resolveForeignChildInOwningRenderer;
|
|
105
|
+
private resolveForeignSubtreeInOwningRenderer;
|
|
106
|
+
private runInForeignOwningRenderer;
|
|
107
|
+
resolveQueuedTokens(html: string, queuedResolutionsByToken: Map<string, QueuedForeignSubtreeResolution>, resolveToken: (token: string) => Promise<string>): Promise<string>;
|
|
108
|
+
}
|