@ecopages/core 0.2.0-alpha.12 → 0.2.0-alpha.13
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 +7 -28
- package/README.md +5 -4
- package/package.json +2 -2
- package/src/adapters/bun/hmr-manager.js +2 -2
- package/src/adapters/node/node-hmr-manager.js +2 -2
- package/src/adapters/node/server-adapter.d.ts +2 -2
- package/src/adapters/node/server-adapter.js +5 -5
- package/src/build/build-adapter.d.ts +7 -6
- package/src/build/build-adapter.js +6 -7
- package/src/eco/eco.js +15 -6
- package/src/eco/eco.utils.d.ts +1 -1
- package/src/eco/eco.utils.js +5 -1
- package/src/hmr/hmr-strategy.d.ts +2 -2
- package/src/integrations/ghtml/ghtml-renderer.d.ts +6 -1
- package/src/integrations/ghtml/ghtml-renderer.js +29 -28
- package/src/plugins/integration-plugin.d.ts +1 -24
- package/src/plugins/integration-plugin.js +0 -14
- package/src/route-renderer/GRAPH.md +54 -84
- package/src/route-renderer/README.md +11 -22
- package/src/route-renderer/orchestration/component-render-context.d.ts +33 -84
- package/src/route-renderer/orchestration/component-render-context.js +30 -108
- package/src/route-renderer/orchestration/integration-renderer.d.ts +219 -96
- package/src/route-renderer/orchestration/integration-renderer.js +416 -236
- package/src/route-renderer/orchestration/queued-boundary-runtime.service.d.ts +93 -0
- package/src/route-renderer/orchestration/queued-boundary-runtime.service.js +155 -0
- package/src/route-renderer/orchestration/render-execution.service.d.ts +8 -71
- package/src/route-renderer/orchestration/render-execution.service.js +28 -115
- package/src/route-renderer/orchestration/render-output.utils.d.ts +6 -0
- package/src/route-renderer/orchestration/render-output.utils.js +25 -0
- package/src/route-renderer/orchestration/render-preparation.service.d.ts +0 -9
- package/src/route-renderer/orchestration/render-preparation.service.js +3 -34
- package/src/route-renderer/page-loading/dependency-resolver.js +6 -1
- package/src/route-renderer/page-loading/page-module-loader.d.ts +1 -2
- package/src/route-renderer/page-loading/page-module-loader.js +0 -2
- package/src/router/client/navigation-coordinator.js +2 -2
- package/src/router/server/fs-router-scanner.js +6 -1
- package/src/services/runtime-state/dev-graph.service.d.ts +5 -5
- package/src/services/runtime-state/dev-graph.service.js +10 -10
- package/src/types/public-types.d.ts +2 -5
- package/src/eco/component-render-context.d.ts +0 -2
- package/src/eco/component-render-context.js +0 -12
- package/src/route-renderer/component-graph/component-graph-executor.d.ts +0 -33
- package/src/route-renderer/component-graph/component-graph-executor.js +0 -30
- package/src/route-renderer/component-graph/component-graph.d.ts +0 -53
- package/src/route-renderer/component-graph/component-graph.js +0 -94
- package/src/route-renderer/component-graph/component-marker.d.ts +0 -52
- package/src/route-renderer/component-graph/component-marker.js +0 -44
- package/src/route-renderer/component-graph/component-reference.d.ts +0 -10
- package/src/route-renderer/component-graph/component-reference.js +0 -34
- package/src/route-renderer/component-graph/marker-graph-resolver.d.ts +0 -79
- package/src/route-renderer/component-graph/marker-graph-resolver.js +0 -117
|
@@ -5,9 +5,6 @@ import {
|
|
|
5
5
|
AssetFactory
|
|
6
6
|
} from "../../services/assets/asset-processing-service/index.js";
|
|
7
7
|
import { buildGlobalInjectorBootstrapContent, buildGlobalInjectorMapScript } from "../../eco/global-injector-map.js";
|
|
8
|
-
import {
|
|
9
|
-
runWithComponentRenderContext
|
|
10
|
-
} from "./component-render-context.js";
|
|
11
8
|
class RenderPreparationService {
|
|
12
9
|
appConfig;
|
|
13
10
|
assetProcessingService;
|
|
@@ -38,7 +35,7 @@ class RenderPreparationService {
|
|
|
38
35
|
*/
|
|
39
36
|
async prepare(routeOptions, currentIntegrationName, callbacks) {
|
|
40
37
|
const pageModule = await callbacks.resolvePageModule(routeOptions.file);
|
|
41
|
-
const { Page, integrationSpecificProps
|
|
38
|
+
const { Page, integrationSpecificProps } = pageModule;
|
|
42
39
|
const HtmlTemplate = await callbacks.getHtmlTemplate();
|
|
43
40
|
const { props, metadata } = await callbacks.resolvePageData(pageModule, routeOptions);
|
|
44
41
|
const Layout = Page.config?.layout;
|
|
@@ -51,20 +48,14 @@ class RenderPreparationService {
|
|
|
51
48
|
const pageDeps = await callbacks.buildRouteRenderAssets(routeOptions.file) || [];
|
|
52
49
|
const allDependencies = [...resolvedDependencies, ...usedIntegrationDependencies, ...pageDeps];
|
|
53
50
|
let componentRender;
|
|
54
|
-
let componentGraphContext = explicitComponentGraphContext;
|
|
55
51
|
if (callbacks.shouldRenderPageComponent({ Page, Layout, options: routeOptions })) {
|
|
56
52
|
const pageRootRender = await this.renderPageRoot({
|
|
57
|
-
currentIntegrationName,
|
|
58
53
|
Page,
|
|
59
54
|
props,
|
|
60
55
|
routeOptions,
|
|
61
56
|
callbacks
|
|
62
57
|
});
|
|
63
58
|
componentRender = pageRootRender.componentRender;
|
|
64
|
-
componentGraphContext = this.mergeGraphContext(
|
|
65
|
-
pageRootRender.componentGraphContext,
|
|
66
|
-
explicitComponentGraphContext
|
|
67
|
-
);
|
|
68
59
|
if (componentRender.assets?.length) {
|
|
69
60
|
allDependencies.push(...componentRender.assets);
|
|
70
61
|
}
|
|
@@ -94,7 +85,6 @@ class RenderPreparationService {
|
|
|
94
85
|
...routeOptions,
|
|
95
86
|
resolvedDependencies,
|
|
96
87
|
componentRender,
|
|
97
|
-
componentGraphContext,
|
|
98
88
|
HtmlTemplate,
|
|
99
89
|
Layout,
|
|
100
90
|
props,
|
|
@@ -112,18 +102,6 @@ class RenderPreparationService {
|
|
|
112
102
|
...preparedOptions
|
|
113
103
|
};
|
|
114
104
|
}
|
|
115
|
-
mergeGraphContext(capturedGraphContext, explicitGraphContext) {
|
|
116
|
-
return {
|
|
117
|
-
propsByRef: {
|
|
118
|
-
...capturedGraphContext.propsByRef ?? {},
|
|
119
|
-
...explicitGraphContext?.propsByRef ?? {}
|
|
120
|
-
},
|
|
121
|
-
slotChildrenByRef: {
|
|
122
|
-
...capturedGraphContext.slotChildrenByRef ?? {},
|
|
123
|
-
...explicitGraphContext?.slotChildrenByRef ?? {}
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
105
|
/**
|
|
128
106
|
* Collects resolved lazy trigger metadata from the component tree.
|
|
129
107
|
*
|
|
@@ -215,13 +193,8 @@ class RenderPreparationService {
|
|
|
215
193
|
* @returns Structured component render result.
|
|
216
194
|
*/
|
|
217
195
|
async renderPageRoot(input) {
|
|
218
|
-
|
|
219
|
-
{
|
|
220
|
-
currentIntegration: input.currentIntegrationName,
|
|
221
|
-
boundaryContext: input.callbacks.getComponentRenderBoundaryContext(),
|
|
222
|
-
serializeDeferredValue: input.callbacks.serializeDeferredValue
|
|
223
|
-
},
|
|
224
|
-
async () => input.callbacks.renderPageComponent({
|
|
196
|
+
return {
|
|
197
|
+
componentRender: await input.callbacks.renderPageComponent({
|
|
225
198
|
component: input.Page,
|
|
226
199
|
props: {
|
|
227
200
|
...input.props,
|
|
@@ -229,10 +202,6 @@ class RenderPreparationService {
|
|
|
229
202
|
query: input.routeOptions.query || {}
|
|
230
203
|
}
|
|
231
204
|
})
|
|
232
|
-
);
|
|
233
|
-
return {
|
|
234
|
-
componentRender: execution.value,
|
|
235
|
-
componentGraphContext: execution.graphContext
|
|
236
205
|
};
|
|
237
206
|
}
|
|
238
207
|
/**
|
|
@@ -34,7 +34,12 @@ function extractEcopagesVirtualImports(file) {
|
|
|
34
34
|
const namedImports = [];
|
|
35
35
|
for (const spec of node.specifiers ?? []) {
|
|
36
36
|
if (spec.type === "ImportSpecifier") {
|
|
37
|
-
|
|
37
|
+
let importedName = spec.local?.name;
|
|
38
|
+
if (spec.imported?.type === "Identifier") {
|
|
39
|
+
importedName = spec.imported.name;
|
|
40
|
+
} else if (spec.imported?.type === "Literal") {
|
|
41
|
+
importedName = spec.imported.value;
|
|
42
|
+
}
|
|
38
43
|
namedImports.push(importedName);
|
|
39
44
|
}
|
|
40
45
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { EcoPageFile, GetMetadata, GetMetadataContext, GetStaticProps, PageMetadataProps, RouteRendererOptions, EcoPageComponent } from '../../types/public-types.js';
|
|
2
2
|
import type { EcoPagesAppConfig } from '../../types/internal-types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Loads route page modules and normalizes their data hooks for rendering.
|
|
@@ -66,7 +66,6 @@ export declare class PageModuleLoaderService {
|
|
|
66
66
|
Page: EcoPageFile['default'] | EcoPageComponent<any>;
|
|
67
67
|
getStaticProps?: GetStaticProps<Record<string, unknown>>;
|
|
68
68
|
getMetadata?: GetMetadata;
|
|
69
|
-
componentGraphContext?: ComponentGraphContext;
|
|
70
69
|
integrationSpecificProps: Record<string, unknown>;
|
|
71
70
|
}>;
|
|
72
71
|
/**
|
|
@@ -88,14 +88,12 @@ class PageModuleLoaderService {
|
|
|
88
88
|
default: Page,
|
|
89
89
|
getStaticProps: moduleGetStaticProps,
|
|
90
90
|
getMetadata: moduleGetMetadata,
|
|
91
|
-
componentGraphContext,
|
|
92
91
|
...integrationSpecificProps
|
|
93
92
|
} = module;
|
|
94
93
|
return {
|
|
95
94
|
Page,
|
|
96
95
|
getStaticProps: Page.staticProps ?? moduleGetStaticProps,
|
|
97
96
|
getMetadata: Page.metadata ?? moduleGetMetadata,
|
|
98
|
-
componentGraphContext,
|
|
99
97
|
integrationSpecificProps
|
|
100
98
|
};
|
|
101
99
|
}
|
|
@@ -16,7 +16,7 @@ function getCandidateOwners(currentOwner, registrations, excludedOwner) {
|
|
|
16
16
|
}
|
|
17
17
|
return owners;
|
|
18
18
|
}
|
|
19
|
-
function createEcoNavigationRuntime(
|
|
19
|
+
function createEcoNavigationRuntime() {
|
|
20
20
|
const registrations = /* @__PURE__ */ new Map();
|
|
21
21
|
const listeners = /* @__PURE__ */ new Set();
|
|
22
22
|
let owner = "none";
|
|
@@ -204,7 +204,7 @@ function getEcoNavigationRuntime(windowObject = window) {
|
|
|
204
204
|
const runtimeWindow = windowObject;
|
|
205
205
|
runtimeWindow.__ECO_PAGES__ = runtimeWindow.__ECO_PAGES__ || {};
|
|
206
206
|
if (!runtimeWindow.__ECO_PAGES__.navigation) {
|
|
207
|
-
runtimeWindow.__ECO_PAGES__.navigation = createEcoNavigationRuntime(
|
|
207
|
+
runtimeWindow.__ECO_PAGES__.navigation = createEcoNavigationRuntime();
|
|
208
208
|
}
|
|
209
209
|
return runtimeWindow.__ECO_PAGES__.navigation;
|
|
210
210
|
}
|
|
@@ -113,7 +113,12 @@ class FSRouterScanner {
|
|
|
113
113
|
const filePath = path.join(this.dir, file);
|
|
114
114
|
const isCatchAll = filePath.includes("[...");
|
|
115
115
|
const isDynamic = !isCatchAll && filePath.includes("[") && filePath.includes("]");
|
|
116
|
-
|
|
116
|
+
let kind = "exact";
|
|
117
|
+
if (isCatchAll) {
|
|
118
|
+
kind = "catch-all";
|
|
119
|
+
} else if (isDynamic) {
|
|
120
|
+
kind = "dynamic";
|
|
121
|
+
}
|
|
117
122
|
return { route, routePath, filePath, kind };
|
|
118
123
|
}
|
|
119
124
|
async scan() {
|
|
@@ -32,7 +32,7 @@ export declare class NoopDevGraphService implements DevGraphService {
|
|
|
32
32
|
/**
|
|
33
33
|
* Invalidates all server-side module state by incrementing the shared version.
|
|
34
34
|
*/
|
|
35
|
-
invalidateServerModules(
|
|
35
|
+
invalidateServerModules(changedFiles?: string[]): void;
|
|
36
36
|
/**
|
|
37
37
|
* Indicates that this graph cannot target invalidation to one entrypoint set.
|
|
38
38
|
*/
|
|
@@ -41,19 +41,19 @@ export declare class NoopDevGraphService implements DevGraphService {
|
|
|
41
41
|
* Returns an empty entrypoint set because this implementation stores no
|
|
42
42
|
* dependency graph metadata.
|
|
43
43
|
*/
|
|
44
|
-
getDependencyEntrypoints(
|
|
44
|
+
getDependencyEntrypoints(filePath: string): Set<string>;
|
|
45
45
|
/**
|
|
46
46
|
* Accepts dependency updates to preserve interface compatibility, but stores no
|
|
47
47
|
* graph state in the noop implementation.
|
|
48
48
|
*/
|
|
49
|
-
setEntrypointDependencies(
|
|
49
|
+
setEntrypointDependencies(entrypointPath: string, dependencies: string[]): void;
|
|
50
50
|
/**
|
|
51
51
|
* Clears one entrypoint from the graph.
|
|
52
52
|
*
|
|
53
53
|
* @remarks
|
|
54
54
|
* There is no stored graph state in this implementation, so this is a no-op.
|
|
55
55
|
*/
|
|
56
|
-
clearEntrypointDependencies(
|
|
56
|
+
clearEntrypointDependencies(entrypointPath: string): void;
|
|
57
57
|
/**
|
|
58
58
|
* Resets graph-owned state for a fresh runtime cycle.
|
|
59
59
|
*/
|
|
@@ -82,7 +82,7 @@ export declare class InMemoryDevGraphService implements DevGraphService {
|
|
|
82
82
|
* modules. Selective dependency lookups are used by callers that need to limit
|
|
83
83
|
* browser rebuild work.
|
|
84
84
|
*/
|
|
85
|
-
invalidateServerModules(
|
|
85
|
+
invalidateServerModules(changedFiles?: string[]): void;
|
|
86
86
|
/**
|
|
87
87
|
* Indicates that this graph can answer dependency-to-entrypoint lookups.
|
|
88
88
|
*/
|
|
@@ -21,8 +21,8 @@ class NoopDevGraphService {
|
|
|
21
21
|
/**
|
|
22
22
|
* Invalidates all server-side module state by incrementing the shared version.
|
|
23
23
|
*/
|
|
24
|
-
invalidateServerModules(
|
|
25
|
-
this.invalidationState.invalidateServerModules(
|
|
24
|
+
invalidateServerModules(changedFiles) {
|
|
25
|
+
this.invalidationState.invalidateServerModules(changedFiles);
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* Indicates that this graph cannot target invalidation to one entrypoint set.
|
|
@@ -34,15 +34,15 @@ class NoopDevGraphService {
|
|
|
34
34
|
* Returns an empty entrypoint set because this implementation stores no
|
|
35
35
|
* dependency graph metadata.
|
|
36
36
|
*/
|
|
37
|
-
getDependencyEntrypoints(
|
|
38
|
-
return this.dependencyGraph.getDependencyEntrypoints(
|
|
37
|
+
getDependencyEntrypoints(filePath) {
|
|
38
|
+
return this.dependencyGraph.getDependencyEntrypoints(filePath);
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
41
|
* Accepts dependency updates to preserve interface compatibility, but stores no
|
|
42
42
|
* graph state in the noop implementation.
|
|
43
43
|
*/
|
|
44
|
-
setEntrypointDependencies(
|
|
45
|
-
this.dependencyGraph.setEntrypointDependencies(
|
|
44
|
+
setEntrypointDependencies(entrypointPath, dependencies) {
|
|
45
|
+
this.dependencyGraph.setEntrypointDependencies(entrypointPath, dependencies);
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* Clears one entrypoint from the graph.
|
|
@@ -50,8 +50,8 @@ class NoopDevGraphService {
|
|
|
50
50
|
* @remarks
|
|
51
51
|
* There is no stored graph state in this implementation, so this is a no-op.
|
|
52
52
|
*/
|
|
53
|
-
clearEntrypointDependencies(
|
|
54
|
-
this.dependencyGraph.clearEntrypointDependencies(
|
|
53
|
+
clearEntrypointDependencies(entrypointPath) {
|
|
54
|
+
this.dependencyGraph.clearEntrypointDependencies(entrypointPath);
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
57
|
* Resets graph-owned state for a fresh runtime cycle.
|
|
@@ -78,8 +78,8 @@ class InMemoryDevGraphService {
|
|
|
78
78
|
* modules. Selective dependency lookups are used by callers that need to limit
|
|
79
79
|
* browser rebuild work.
|
|
80
80
|
*/
|
|
81
|
-
invalidateServerModules(
|
|
82
|
-
this.invalidationState.invalidateServerModules(
|
|
81
|
+
invalidateServerModules(changedFiles) {
|
|
82
|
+
this.invalidationState.invalidateServerModules(changedFiles);
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
85
|
* Indicates that this graph can answer dependency-to-entrypoint lookups.
|
|
@@ -2,7 +2,7 @@ import type { Readable } from 'node:stream';
|
|
|
2
2
|
import type { ApiResponseBuilder } from '../adapters/shared/api-response.js';
|
|
3
3
|
import type { BuildExecutor } from '../build/build-adapter.js';
|
|
4
4
|
import type { EcoBuildPlugin } from '../build/build-types.js';
|
|
5
|
-
import type {
|
|
5
|
+
import type { ComponentBoundaryRuntime } from '../route-renderer/orchestration/component-render-context.js';
|
|
6
6
|
import type { EcoPageComponent } from '../eco/eco.types.js';
|
|
7
7
|
import type { EcoPagesAppConfig } from './internal-types.js';
|
|
8
8
|
import type { HmrStrategy } from '../hmr/hmr-strategy.js';
|
|
@@ -12,10 +12,9 @@ import type { CacheStats, CacheStrategy } from '../services/cache/cache.types.js
|
|
|
12
12
|
import type { InteractionEventsString as ScriptsInjectorInteractionEventsString } from '@ecopages/scripts-injector/types';
|
|
13
13
|
export type { EcoPagesAppConfig } from './internal-types.js';
|
|
14
14
|
export type { EcoPageComponent } from '../eco/eco.types.js';
|
|
15
|
-
export type { MarkerGraphContext } from '../route-renderer/component-graph/marker-graph-resolver.js';
|
|
16
15
|
export type { ProcessedAsset } from '../services/assets/asset-processing-service/assets.types.js';
|
|
17
16
|
import type { StandardSchema, StandardSchemaResult, StandardSchemaSuccessResult, StandardSchemaFailureResult, StandardSchemaIssue, InferOutput } from '../services/validation/standard-schema.types.js';
|
|
18
|
-
export type { StandardSchema, StandardSchemaResult, StandardSchemaSuccessResult, StandardSchemaFailureResult, StandardSchemaIssue, InferOutput,
|
|
17
|
+
export type { StandardSchema, StandardSchemaResult, StandardSchemaSuccessResult, StandardSchemaFailureResult, StandardSchemaIssue, InferOutput, ComponentBoundaryRuntime, };
|
|
19
18
|
export type InteractionEventsString = ScriptsInjectorInteractionEventsString;
|
|
20
19
|
export type DependencyLazyTrigger = {
|
|
21
20
|
'on:idle': true;
|
|
@@ -573,7 +572,6 @@ export type EcoPageFile<T = unknown> = T & {
|
|
|
573
572
|
getStaticPaths?: GetStaticPaths;
|
|
574
573
|
getStaticProps?: GetStaticProps<Record<string, unknown>>;
|
|
575
574
|
getMetadata?: GetMetadata;
|
|
576
|
-
componentGraphContext?: ComponentGraphContext;
|
|
577
575
|
cache?: CacheStrategy;
|
|
578
576
|
};
|
|
579
577
|
/**
|
|
@@ -677,7 +675,6 @@ export type IntegrationRendererRenderOptions<C = EcoPagesElement> = RouteRendere
|
|
|
677
675
|
dependencies?: EcoComponentDependencies;
|
|
678
676
|
resolvedDependencies: ProcessedAsset[];
|
|
679
677
|
componentRender?: ComponentRenderResult;
|
|
680
|
-
componentGraphContext?: ComponentGraphContext;
|
|
681
678
|
pageProps?: Record<string, unknown>;
|
|
682
679
|
cacheStrategy?: CacheStrategy;
|
|
683
680
|
pageLocals?: RequestLocals;
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
export { finalizeComponentRender, getComponentRenderContext, runWithComponentRenderContext, tryRenderDeferredBoundary, } from '../route-renderer/orchestration/component-render-context.js';
|
|
2
|
-
export type { BoundaryRenderDecisionInput, BoundaryRenderMode, ComponentGraphContext, ComponentRenderBoundaryContext, ComponentRenderContext, } from '../route-renderer/orchestration/component-render-context.js';
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
finalizeComponentRender,
|
|
3
|
-
getComponentRenderContext,
|
|
4
|
-
runWithComponentRenderContext,
|
|
5
|
-
tryRenderDeferredBoundary
|
|
6
|
-
} from "../route-renderer/orchestration/component-render-context.js";
|
|
7
|
-
export {
|
|
8
|
-
finalizeComponentRender,
|
|
9
|
-
getComponentRenderContext,
|
|
10
|
-
runWithComponentRenderContext,
|
|
11
|
-
tryRenderDeferredBoundary
|
|
12
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { ComponentMarker } from './component-marker.js';
|
|
2
|
-
import type { ComponentGraph } from './component-graph.js';
|
|
3
|
-
/**
|
|
4
|
-
* Render result returned by a graph node resolver.
|
|
5
|
-
*
|
|
6
|
-
* `html` is inserted in place of the corresponding marker token.
|
|
7
|
-
*/
|
|
8
|
-
export type GraphNodeRenderResult = {
|
|
9
|
-
html: string;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Callback used to render one marker node during graph execution.
|
|
13
|
-
*
|
|
14
|
-
* Resolver implementations may call integration-specific `renderComponent`
|
|
15
|
-
* and can use closure state to wire child output into parent render calls.
|
|
16
|
-
*/
|
|
17
|
-
export type GraphNodeResolver = (marker: ComponentMarker) => Promise<GraphNodeRenderResult>;
|
|
18
|
-
/**
|
|
19
|
-
* Resolves all markers in bottom-up order based on computed graph levels.
|
|
20
|
-
*
|
|
21
|
-
* Child nodes are resolved first so parent slot content can consume already
|
|
22
|
-
* resolved child HTML in subsequent resolver invocations.
|
|
23
|
-
*
|
|
24
|
-
* Nodes discovered from serialized props may not exist as literal marker tokens in
|
|
25
|
-
* `inputHtml`. They still resolve so parent nodes can consume their resolved child
|
|
26
|
-
* HTML, while replacement in the outer HTML buffer remains a no-op.
|
|
27
|
-
*
|
|
28
|
-
* @param inputHtml HTML containing marker tokens.
|
|
29
|
-
* @param graph Precomputed marker graph with topological levels.
|
|
30
|
-
* @param resolver Async callback that renders each marker node.
|
|
31
|
-
* @returns HTML with resolved markers replaced.
|
|
32
|
-
*/
|
|
33
|
-
export declare function resolveComponentGraph(inputHtml: string, graph: ComponentGraph, resolver: GraphNodeResolver): Promise<string>;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
function escapeRegex(value) {
|
|
2
|
-
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3
|
-
}
|
|
4
|
-
function replaceMarkerByNodeId(html, nodeId, replacement) {
|
|
5
|
-
const pattern = `<eco-marker[^>]*data-eco-node-id="${escapeRegex(nodeId)}"[^>]*><\\/eco-marker>`;
|
|
6
|
-
const markerRegex = new RegExp(pattern);
|
|
7
|
-
return html.replace(markerRegex, replacement);
|
|
8
|
-
}
|
|
9
|
-
async function resolveComponentGraph(inputHtml, graph, resolver) {
|
|
10
|
-
let html = inputHtml;
|
|
11
|
-
const markersById = /* @__PURE__ */ new Map();
|
|
12
|
-
for (const node of graph.nodes.values()) {
|
|
13
|
-
markersById.set(node.nodeId, node);
|
|
14
|
-
}
|
|
15
|
-
const levels = [...graph.levels].reverse();
|
|
16
|
-
for (const level of levels) {
|
|
17
|
-
for (const nodeId of level) {
|
|
18
|
-
const marker = markersById.get(nodeId);
|
|
19
|
-
if (!marker) {
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
const result = await resolver(marker);
|
|
23
|
-
html = replaceMarkerByNodeId(html, nodeId, result.html);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return html;
|
|
27
|
-
}
|
|
28
|
-
export {
|
|
29
|
-
resolveComponentGraph
|
|
30
|
-
};
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type { ComponentMarker, MarkerNodeId } from './component-marker.js';
|
|
2
|
-
/**
|
|
3
|
-
* Maps a parent slot reference to child marker node ids discovered in that slot.
|
|
4
|
-
*
|
|
5
|
-
* Keys are `slotRef` values emitted in marker payloads.
|
|
6
|
-
*/
|
|
7
|
-
export type SlotChildrenRegistry = Record<string, MarkerNodeId[]>;
|
|
8
|
-
/**
|
|
9
|
-
* Serializable props captured for deferred marker nodes.
|
|
10
|
-
*
|
|
11
|
-
* The graph builder reads this registry to discover child markers that were not
|
|
12
|
-
* emitted into the outer HTML stream because they were captured inside a
|
|
13
|
-
* deferred parent's serialized `children` prop.
|
|
14
|
-
*/
|
|
15
|
-
export type PropsRegistry = Record<string, Record<string, unknown>>;
|
|
16
|
-
/**
|
|
17
|
-
* Graph node enriched with source-order information for deterministic traversal.
|
|
18
|
-
*/
|
|
19
|
-
export type ComponentGraphNode = ComponentMarker & {
|
|
20
|
-
order: number;
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Directed acyclic graph representation for component marker orchestration.
|
|
24
|
-
*
|
|
25
|
-
* `levels` are topological layers from roots to leaves.
|
|
26
|
-
*/
|
|
27
|
-
export type ComponentGraph = {
|
|
28
|
-
nodes: Map<MarkerNodeId, ComponentGraphNode>;
|
|
29
|
-
edges: Map<MarkerNodeId, Set<MarkerNodeId>>;
|
|
30
|
-
reverseEdges: Map<MarkerNodeId, Set<MarkerNodeId>>;
|
|
31
|
-
levels: MarkerNodeId[][];
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* Extracts marker graph metadata from rendered HTML and slot linkage data.
|
|
35
|
-
*
|
|
36
|
-
* This is the canonical graph builder used by marker execution.
|
|
37
|
-
*
|
|
38
|
-
* Algorithm summary:
|
|
39
|
-
* 1. Parse markers from HTML in source order.
|
|
40
|
-
* 2. Discover nested child markers captured inside serialized `children` props.
|
|
41
|
-
* 3. Create nodes and derive edges from `slotChildrenRegistry`.
|
|
42
|
-
* 3. Compute deterministic topological levels.
|
|
43
|
-
*
|
|
44
|
-
* Unknown child node ids in `slotChildrenRegistry` are ignored to keep the
|
|
45
|
-
* extractor tolerant to stale references.
|
|
46
|
-
*
|
|
47
|
-
* @param html Rendered HTML containing `eco-marker` tokens.
|
|
48
|
-
* @param slotChildrenRegistry Optional slot -> child linkage map.
|
|
49
|
-
* @param propsRegistry Optional props registry used to discover nested markers
|
|
50
|
-
* captured inside deferred parent `children` props.
|
|
51
|
-
* @returns Component graph structure with levels ready for execution.
|
|
52
|
-
*/
|
|
53
|
-
export declare function extractComponentGraph(html: string, slotChildrenRegistry?: SlotChildrenRegistry, propsRegistry?: PropsRegistry): ComponentGraph;
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { parseComponentMarkers } from "./component-marker.js";
|
|
2
|
-
function readNestedChildMarkers(marker, propsRegistry) {
|
|
3
|
-
const children = propsRegistry[marker.propsRef]?.children;
|
|
4
|
-
if (typeof children !== "string" || !children.includes("<eco-marker")) {
|
|
5
|
-
return [];
|
|
6
|
-
}
|
|
7
|
-
return parseComponentMarkers(children);
|
|
8
|
-
}
|
|
9
|
-
function ensureEdgeMaps(edges, reverseEdges, from, to) {
|
|
10
|
-
if (!edges.has(from)) {
|
|
11
|
-
edges.set(from, /* @__PURE__ */ new Set());
|
|
12
|
-
}
|
|
13
|
-
if (!reverseEdges.has(to)) {
|
|
14
|
-
reverseEdges.set(to, /* @__PURE__ */ new Set());
|
|
15
|
-
}
|
|
16
|
-
edges.get(from)?.add(to);
|
|
17
|
-
reverseEdges.get(to)?.add(from);
|
|
18
|
-
}
|
|
19
|
-
function computeLevels(nodes, edges, reverseEdges) {
|
|
20
|
-
const indegree = /* @__PURE__ */ new Map();
|
|
21
|
-
for (const nodeId of nodes.keys()) {
|
|
22
|
-
indegree.set(nodeId, reverseEdges.get(nodeId)?.size ?? 0);
|
|
23
|
-
}
|
|
24
|
-
const levels = [];
|
|
25
|
-
let frontier = [...nodes.values()].filter((node) => (indegree.get(node.nodeId) ?? 0) === 0).sort((a, b) => a.order - b.order).map((node) => node.nodeId);
|
|
26
|
-
const visited = /* @__PURE__ */ new Set();
|
|
27
|
-
while (frontier.length > 0) {
|
|
28
|
-
levels.push(frontier);
|
|
29
|
-
const next = [];
|
|
30
|
-
for (const current of frontier) {
|
|
31
|
-
visited.add(current);
|
|
32
|
-
for (const child of edges.get(current) ?? []) {
|
|
33
|
-
const nextInDegree = (indegree.get(child) ?? 0) - 1;
|
|
34
|
-
indegree.set(child, nextInDegree);
|
|
35
|
-
if (nextInDegree === 0) {
|
|
36
|
-
next.push(child);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
frontier = next.filter((nodeId, index) => next.indexOf(nodeId) === index).sort((a, b) => {
|
|
41
|
-
const orderA = nodes.get(a)?.order ?? 0;
|
|
42
|
-
const orderB = nodes.get(b)?.order ?? 0;
|
|
43
|
-
return orderA - orderB;
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
if (visited.size !== nodes.size) {
|
|
47
|
-
throw new Error("[ecopages] Component marker graph contains a cycle or unresolved dependency links.");
|
|
48
|
-
}
|
|
49
|
-
return levels;
|
|
50
|
-
}
|
|
51
|
-
function extractComponentGraph(html, slotChildrenRegistry = {}, propsRegistry = {}) {
|
|
52
|
-
const markers = parseComponentMarkers(html);
|
|
53
|
-
const nodes = /* @__PURE__ */ new Map();
|
|
54
|
-
const edges = /* @__PURE__ */ new Map();
|
|
55
|
-
const reverseEdges = /* @__PURE__ */ new Map();
|
|
56
|
-
const discoveredMarkers = [];
|
|
57
|
-
const registerMarker = (marker) => {
|
|
58
|
-
if (nodes.has(marker.nodeId)) {
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
discoveredMarkers.push(marker);
|
|
62
|
-
nodes.set(marker.nodeId, {
|
|
63
|
-
...marker,
|
|
64
|
-
order: discoveredMarkers.length - 1
|
|
65
|
-
});
|
|
66
|
-
return true;
|
|
67
|
-
};
|
|
68
|
-
for (const marker of markers) {
|
|
69
|
-
registerMarker(marker);
|
|
70
|
-
}
|
|
71
|
-
for (let index = 0; index < discoveredMarkers.length; index += 1) {
|
|
72
|
-
const marker = discoveredMarkers[index];
|
|
73
|
-
for (const nestedMarker of readNestedChildMarkers(marker, propsRegistry)) {
|
|
74
|
-
registerMarker(nestedMarker);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
for (const marker of discoveredMarkers) {
|
|
78
|
-
if (!marker.slotRef) {
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
const linkedChildren = slotChildrenRegistry[marker.slotRef] ?? [];
|
|
82
|
-
for (const childNodeId of linkedChildren) {
|
|
83
|
-
if (!nodes.has(childNodeId)) {
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
ensureEdgeMaps(edges, reverseEdges, marker.nodeId, childNodeId);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
const levels = computeLevels(nodes, edges, reverseEdges);
|
|
90
|
-
return { nodes, edges, reverseEdges, levels };
|
|
91
|
-
}
|
|
92
|
-
export {
|
|
93
|
-
extractComponentGraph
|
|
94
|
-
};
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Stable marker node identifier used during one render graph resolution pass.
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* `n_12`
|
|
6
|
-
*/
|
|
7
|
-
export type MarkerNodeId = `n_${string}`;
|
|
8
|
-
/**
|
|
9
|
-
* Marker payload used by graph extraction and execution.
|
|
10
|
-
*
|
|
11
|
-
* Each marker references:
|
|
12
|
-
* - the owning integration renderer (`integration`)
|
|
13
|
-
* - a component definition key (`componentRef`)
|
|
14
|
-
* - a serialized props key (`propsRef`)
|
|
15
|
-
* - optional child-slot linkage (`slotRef`)
|
|
16
|
-
*/
|
|
17
|
-
export type ComponentMarker = {
|
|
18
|
-
nodeId: MarkerNodeId;
|
|
19
|
-
integration: string;
|
|
20
|
-
componentRef: string;
|
|
21
|
-
propsRef: string;
|
|
22
|
-
slotRef?: string;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Input contract for marker emission.
|
|
26
|
-
*
|
|
27
|
-
* This shape is intentionally close to `ComponentMarker` to keep emission and
|
|
28
|
-
* parsing symmetric.
|
|
29
|
-
*/
|
|
30
|
-
export type MarkerRenderInput = {
|
|
31
|
-
nodeId: MarkerNodeId;
|
|
32
|
-
integration: string;
|
|
33
|
-
componentRef: string;
|
|
34
|
-
propsRef: string;
|
|
35
|
-
slotRef?: string;
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Creates the canonical `<eco-marker>` token used for deferred component rendering.
|
|
39
|
-
*
|
|
40
|
-
* @param input Marker payload fields.
|
|
41
|
-
* @returns Serialized marker HTML token.
|
|
42
|
-
*/
|
|
43
|
-
export declare function createComponentMarker(input: MarkerRenderInput): string;
|
|
44
|
-
/**
|
|
45
|
-
* Parses all valid `<eco-marker>` tokens from HTML output.
|
|
46
|
-
*
|
|
47
|
-
* Invalid markers (missing required attributes) are ignored by design.
|
|
48
|
-
*
|
|
49
|
-
* @param html Rendered HTML fragment or document.
|
|
50
|
-
* @returns Parsed marker payloads in source order.
|
|
51
|
-
*/
|
|
52
|
-
export declare function parseComponentMarkers(html: string): ComponentMarker[];
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { escapeHtmlAttribute } from "../../utils/html-escaping.js";
|
|
2
|
-
function readAttribute(tag, name) {
|
|
3
|
-
const match = tag.match(new RegExp(`${name}="([^"]*)"`));
|
|
4
|
-
return match?.[1];
|
|
5
|
-
}
|
|
6
|
-
function createComponentMarker(input) {
|
|
7
|
-
const attributes = [
|
|
8
|
-
`data-eco-node-id="${escapeHtmlAttribute(input.nodeId)}"`,
|
|
9
|
-
`data-eco-integration="${escapeHtmlAttribute(input.integration)}"`,
|
|
10
|
-
`data-eco-component-ref="${escapeHtmlAttribute(input.componentRef)}"`,
|
|
11
|
-
`data-eco-props-ref="${escapeHtmlAttribute(input.propsRef)}"`
|
|
12
|
-
];
|
|
13
|
-
if (input.slotRef) {
|
|
14
|
-
attributes.push(`data-eco-slot-ref="${escapeHtmlAttribute(input.slotRef)}"`);
|
|
15
|
-
}
|
|
16
|
-
return `<eco-marker ${attributes.join(" ")}></eco-marker>`;
|
|
17
|
-
}
|
|
18
|
-
function parseComponentMarkers(html) {
|
|
19
|
-
const markerRegex = /<eco-marker\b[^>]*><\/eco-marker>/g;
|
|
20
|
-
const results = [];
|
|
21
|
-
for (let match = markerRegex.exec(html); match; match = markerRegex.exec(html)) {
|
|
22
|
-
const tag = match[0];
|
|
23
|
-
const nodeId = readAttribute(tag, "data-eco-node-id");
|
|
24
|
-
const integration = readAttribute(tag, "data-eco-integration");
|
|
25
|
-
const componentRef = readAttribute(tag, "data-eco-component-ref");
|
|
26
|
-
const propsRef = readAttribute(tag, "data-eco-props-ref");
|
|
27
|
-
const slotRef = readAttribute(tag, "data-eco-slot-ref");
|
|
28
|
-
if (!nodeId || !integration || !componentRef || !propsRef) {
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
results.push({
|
|
32
|
-
nodeId,
|
|
33
|
-
integration,
|
|
34
|
-
componentRef,
|
|
35
|
-
propsRef,
|
|
36
|
-
slotRef
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
return results;
|
|
40
|
-
}
|
|
41
|
-
export {
|
|
42
|
-
createComponentMarker,
|
|
43
|
-
parseComponentMarkers
|
|
44
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { EcoComponent } from '../../types/public-types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Resolves a stable component reference for marker emission and lookup.
|
|
4
|
-
*
|
|
5
|
-
* Build-time metadata remains the preferred source. When a component is
|
|
6
|
-
* imported directly from source on the server and metadata has not been
|
|
7
|
-
* injected, fall back to a process-local stable runtime reference so explicit
|
|
8
|
-
* request-time rendering can still resolve deferred boundaries.
|
|
9
|
-
*/
|
|
10
|
-
export declare function getComponentReference(component: EcoComponent): string;
|