@deviltea/widget-core 0.0.1
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/LICENSE +21 -0
- package/README.md +327 -0
- package/dist/dep-DKQpJwdW.d.mts +1110 -0
- package/dist/index.d.mts +149 -0
- package/dist/index.mjs +3891 -0
- package/dist/inspection/index.d.mts +190 -0
- package/dist/inspection/index.mjs +296 -0
- package/dist/internals-DXFEmv8H.mjs +27 -0
- package/package.json +62 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { Bn as ExecutionResult, Jt as WidgetSystemRuntime, Kt as WidgetSystemBlueprint, T as BlueprintDependencyReference, Tt as ResolvedBlueprintWidgetNode, bt as BlueprintWidgetNode, in as AnyWidgetPluginTuple, lt as RuntimePropertyDiagnostic, qn as WidgetMemberKey, zt as UnresolvedBlueprintWidgetNode } from "../dep-DKQpJwdW.mjs";
|
|
2
|
+
//#region src/inspection/types.d.ts
|
|
3
|
+
declare const inspectionNodeIdBrand: unique symbol;
|
|
4
|
+
/**
|
|
5
|
+
* Snapshot-local diagnostic identity only: unique per recovered source node (resolved and unresolved
|
|
6
|
+
* alike) within one Blueprint inspection snapshot. Not persisted/domain identity, no stability guarantee
|
|
7
|
+
* across `recompile()` or separately-created Blueprint snapshots, and equality across snapshots has no
|
|
8
|
+
* semantic meaning. Consumers must not manufacture values or use it as a dependency target or
|
|
9
|
+
* application/widget identifier. Allocation strategy is not public.
|
|
10
|
+
*/
|
|
11
|
+
type InspectionNodeId = number & {
|
|
12
|
+
readonly [inspectionNodeIdBrand]: true;
|
|
13
|
+
};
|
|
14
|
+
interface BlueprintInspectionCapabilities {
|
|
15
|
+
readonly config: boolean;
|
|
16
|
+
readonly slots: boolean;
|
|
17
|
+
readonly state: boolean;
|
|
18
|
+
readonly properties: boolean;
|
|
19
|
+
readonly methods: boolean;
|
|
20
|
+
}
|
|
21
|
+
interface BlueprintInspectionSourceSlot {
|
|
22
|
+
readonly name: string;
|
|
23
|
+
readonly placement: 'slot' | 'raw-slot';
|
|
24
|
+
readonly children: readonly InspectionNodeId[];
|
|
25
|
+
}
|
|
26
|
+
interface BlueprintInspectionSemanticSlot {
|
|
27
|
+
readonly name: WidgetMemberKey;
|
|
28
|
+
readonly children: readonly InspectionNodeId[];
|
|
29
|
+
}
|
|
30
|
+
interface BlueprintInspectionMemberRef {
|
|
31
|
+
readonly nodeId: InspectionNodeId;
|
|
32
|
+
readonly member: {
|
|
33
|
+
readonly type: 'state';
|
|
34
|
+
readonly name: WidgetMemberKey;
|
|
35
|
+
} | {
|
|
36
|
+
readonly type: 'property';
|
|
37
|
+
readonly name: WidgetMemberKey;
|
|
38
|
+
} | {
|
|
39
|
+
readonly type: 'method';
|
|
40
|
+
readonly name: WidgetMemberKey;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
interface BlueprintInspectionDependencyBase {
|
|
44
|
+
/**
|
|
45
|
+
* Path from the `registerDeps()` return root to this leaf, e.g. `[]` / `['pricing']` /
|
|
46
|
+
* `['pricing', 'base']` / `['items', 0]`. Object keys stay strings verbatim (`'__proto__'`, `'a.b'`,
|
|
47
|
+
* `'0'`); array/tuple indices are numbers. Never stringified to dot syntax.
|
|
48
|
+
*/
|
|
49
|
+
readonly path: readonly (string | number)[];
|
|
50
|
+
/** Existing stable public declaration reference. */
|
|
51
|
+
readonly reference: BlueprintDependencyReference;
|
|
52
|
+
}
|
|
53
|
+
interface ResolvedBlueprintInspectionDependency extends BlueprintInspectionDependencyBase {
|
|
54
|
+
readonly status: 'resolved';
|
|
55
|
+
/** Actual semantically-resolved endpoint. */
|
|
56
|
+
readonly target: BlueprintInspectionMemberRef;
|
|
57
|
+
}
|
|
58
|
+
interface AbsentBlueprintInspectionDependency extends BlueprintInspectionDependencyBase {
|
|
59
|
+
readonly status: 'absent';
|
|
60
|
+
}
|
|
61
|
+
interface InvalidBlueprintInspectionDependency extends BlueprintInspectionDependencyBase {
|
|
62
|
+
readonly status: 'invalid';
|
|
63
|
+
/**
|
|
64
|
+
* Present only when target cardinality resolved to exactly one recovered source node before
|
|
65
|
+
* semantic target/capability/member resolution failed.
|
|
66
|
+
*/
|
|
67
|
+
readonly targetNodeId?: InspectionNodeId;
|
|
68
|
+
}
|
|
69
|
+
type BlueprintInspectionDependency = ResolvedBlueprintInspectionDependency | AbsentBlueprintInspectionDependency | InvalidBlueprintInspectionDependency;
|
|
70
|
+
interface BlueprintInspectionStateMember {
|
|
71
|
+
readonly type: 'state';
|
|
72
|
+
readonly name: WidgetMemberKey;
|
|
73
|
+
}
|
|
74
|
+
interface BlueprintInspectionPropertyMember {
|
|
75
|
+
readonly type: 'property';
|
|
76
|
+
readonly name: WidgetMemberKey;
|
|
77
|
+
readonly dependencies: readonly BlueprintInspectionDependency[];
|
|
78
|
+
}
|
|
79
|
+
interface BlueprintInspectionMethodMember {
|
|
80
|
+
readonly type: 'method';
|
|
81
|
+
readonly name: WidgetMemberKey;
|
|
82
|
+
/** Compiler-authoritative transitive write-effect fact. */
|
|
83
|
+
readonly transitivelyWrites: boolean;
|
|
84
|
+
readonly dependencies: readonly BlueprintInspectionDependency[];
|
|
85
|
+
}
|
|
86
|
+
interface BlueprintInspectionNodeBase<Plugins extends AnyWidgetPluginTuple = AnyWidgetPluginTuple> {
|
|
87
|
+
readonly nodeId: InspectionNodeId;
|
|
88
|
+
/**
|
|
89
|
+
* The existing public Blueprint node object (`source`, `diagnostics`, and — when resolved —
|
|
90
|
+
* id/type/config/slots semantics). Inspection does not duplicate those semantics into a second DTO.
|
|
91
|
+
*/
|
|
92
|
+
readonly node: BlueprintWidgetNode<Plugins>;
|
|
93
|
+
/** Best-effort recovered source topology (not a raw `slots` mirror). */
|
|
94
|
+
readonly sourceSlots: readonly BlueprintInspectionSourceSlot[];
|
|
95
|
+
}
|
|
96
|
+
interface UnresolvedBlueprintInspectionNode<Plugins extends AnyWidgetPluginTuple = AnyWidgetPluginTuple> extends BlueprintInspectionNodeBase<Plugins> {
|
|
97
|
+
readonly resolved: false;
|
|
98
|
+
readonly node: UnresolvedBlueprintWidgetNode<Plugins>;
|
|
99
|
+
}
|
|
100
|
+
interface ResolvedBlueprintInspectionNode<Plugins extends AnyWidgetPluginTuple = AnyWidgetPluginTuple> extends BlueprintInspectionNodeBase<Plugins> {
|
|
101
|
+
readonly resolved: true;
|
|
102
|
+
readonly node: ResolvedBlueprintWidgetNode<Plugins>;
|
|
103
|
+
/** Authoritative capability presence (absent vs explicitly declared empty). */
|
|
104
|
+
readonly capabilities: BlueprintInspectionCapabilities;
|
|
105
|
+
readonly semanticSlots: readonly BlueprintInspectionSemanticSlot[];
|
|
106
|
+
readonly state: readonly BlueprintInspectionStateMember[];
|
|
107
|
+
readonly properties: readonly BlueprintInspectionPropertyMember[];
|
|
108
|
+
readonly methods: readonly BlueprintInspectionMethodMember[];
|
|
109
|
+
}
|
|
110
|
+
type BlueprintInspectionNode<Plugins extends AnyWidgetPluginTuple = AnyWidgetPluginTuple> = UnresolvedBlueprintInspectionNode<Plugins> | ResolvedBlueprintInspectionNode<Plugins>;
|
|
111
|
+
interface BlueprintInspectionEvaluationMemberRef {
|
|
112
|
+
readonly nodeId: InspectionNodeId;
|
|
113
|
+
readonly member: {
|
|
114
|
+
readonly type: 'property';
|
|
115
|
+
readonly name: WidgetMemberKey;
|
|
116
|
+
} | {
|
|
117
|
+
readonly type: 'method';
|
|
118
|
+
readonly name: WidgetMemberKey;
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
interface BlueprintInspectionInvalidCycle {
|
|
122
|
+
/** The SCC member set in deterministic semantic member order — not an ordered cycle path. */
|
|
123
|
+
readonly members: readonly BlueprintInspectionEvaluationMemberRef[];
|
|
124
|
+
}
|
|
125
|
+
interface BlueprintInspection<Plugins extends AnyWidgetPluginTuple = AnyWidgetPluginTuple> {
|
|
126
|
+
readonly rootNodeId: InspectionNodeId;
|
|
127
|
+
/** Every recovered source node, including unresolved nodes. */
|
|
128
|
+
readonly nodes: readonly BlueprintInspectionNode<Plugins>[];
|
|
129
|
+
/**
|
|
130
|
+
* Property-containing invalid evaluation SCCs produced by core graph analysis. Method-only SCCs
|
|
131
|
+
* never appear.
|
|
132
|
+
*/
|
|
133
|
+
readonly invalidCycles: readonly BlueprintInspectionInvalidCycle[];
|
|
134
|
+
getNode: (nodeId: InspectionNodeId) => BlueprintInspectionNode<Plugins> | null;
|
|
135
|
+
getNodeId: (node: BlueprintWidgetNode<Plugins>) => InspectionNodeId | null;
|
|
136
|
+
}
|
|
137
|
+
interface InspectionObservable<Snapshot> {
|
|
138
|
+
getSnapshot: () => Snapshot;
|
|
139
|
+
subscribe: (listener: (snapshot: Snapshot) => void) => () => void;
|
|
140
|
+
}
|
|
141
|
+
interface RuntimeStateInspectionSnapshot<T> {
|
|
142
|
+
readonly value: T | null;
|
|
143
|
+
}
|
|
144
|
+
interface RuntimeStateInspection<T> extends InspectionObservable<RuntimeStateInspectionSnapshot<T>> {}
|
|
145
|
+
type RuntimePropertyInspectionSnapshot<T> = {
|
|
146
|
+
readonly status: 'never-evaluated';
|
|
147
|
+
} | {
|
|
148
|
+
readonly status: 'completed';
|
|
149
|
+
readonly result: ExecutionResult<T | null, RuntimePropertyDiagnostic>;
|
|
150
|
+
};
|
|
151
|
+
interface RuntimePropertyInspection<T> extends InspectionObservable<RuntimePropertyInspectionSnapshot<T>> {}
|
|
152
|
+
interface RuntimeWidgetInspection<Plugins extends AnyWidgetPluginTuple = AnyWidgetPluginTuple> {
|
|
153
|
+
readonly nodeId: InspectionNodeId;
|
|
154
|
+
readonly blueprintNode: ResolvedBlueprintInspectionNode<Plugins>;
|
|
155
|
+
/** `null` when the state member/capability does not exist. Dynamic `unknown` typing. */
|
|
156
|
+
getState: (key: WidgetMemberKey) => RuntimeStateInspection<unknown> | null;
|
|
157
|
+
/** `null` when the property member/capability does not exist. Dynamic `unknown` typing. */
|
|
158
|
+
getProperty: (name: WidgetMemberKey) => RuntimePropertyInspection<unknown> | null;
|
|
159
|
+
}
|
|
160
|
+
interface RuntimeInspection<Plugins extends AnyWidgetPluginTuple = AnyWidgetPluginTuple> {
|
|
161
|
+
/** Identity-stable with `inspectBlueprint(runtime.blueprint)`. */
|
|
162
|
+
readonly blueprint: BlueprintInspection<Plugins>;
|
|
163
|
+
/**
|
|
164
|
+
* For every `InspectionNodeId` obtained from this `RuntimeInspection`'s `blueprint`, returns its
|
|
165
|
+
* corresponding `RuntimeWidgetInspection`. `null` when the supplied value does not designate a node
|
|
166
|
+
* in this snapshot (forged/out-of-domain values). An `InspectionNodeId` minted by a *different*
|
|
167
|
+
* snapshot is outside this identifier's defined domain — no cross-snapshot rejection is promised, and
|
|
168
|
+
* the implementation is not required to detect a value that happens to collide numerically with a
|
|
169
|
+
* node in this snapshot. Never throws for an ordinary lookup miss.
|
|
170
|
+
*/
|
|
171
|
+
getWidget: (nodeId: InspectionNodeId) => RuntimeWidgetInspection<Plugins> | null;
|
|
172
|
+
}
|
|
173
|
+
//#endregion
|
|
174
|
+
//#region src/inspection/blueprint.d.ts
|
|
175
|
+
/**
|
|
176
|
+
* Returns the frozen, first-use eagerly-materialized Blueprint inspection snapshot for `blueprint`,
|
|
177
|
+
* cached (weak, no global strong retention) so `inspectBlueprint(blueprint) === inspectBlueprint(blueprint)`.
|
|
178
|
+
*/
|
|
179
|
+
declare function inspectBlueprint<Plugins extends AnyWidgetPluginTuple = AnyWidgetPluginTuple>(blueprint: WidgetSystemBlueprint<Plugins>): BlueprintInspection<Plugins>;
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region src/inspection/runtime.d.ts
|
|
182
|
+
/**
|
|
183
|
+
* Returns the readonly Runtime inspection facade for `runtime`, cached (weak, no global strong
|
|
184
|
+
* retention) so `inspectRuntime(runtime) === inspectRuntime(runtime)`. Explicitly allowed — and returns
|
|
185
|
+
* the facade over already-retained facts — even when called for the first time after `runtime.dispose()`
|
|
186
|
+
* (post-mortem inspection).
|
|
187
|
+
*/
|
|
188
|
+
declare function inspectRuntime<Plugins extends AnyWidgetPluginTuple = AnyWidgetPluginTuple>(runtime: WidgetSystemRuntime<Plugins>): RuntimeInspection<Plugins>;
|
|
189
|
+
//#endregion
|
|
190
|
+
export { type AbsentBlueprintInspectionDependency, type BlueprintInspection, type BlueprintInspectionCapabilities, type BlueprintInspectionDependency, type BlueprintInspectionDependencyBase, type BlueprintInspectionEvaluationMemberRef, type BlueprintInspectionInvalidCycle, type BlueprintInspectionMemberRef, type BlueprintInspectionMethodMember, type BlueprintInspectionNode, type BlueprintInspectionNodeBase, type BlueprintInspectionPropertyMember, type BlueprintInspectionSemanticSlot, type BlueprintInspectionSourceSlot, type BlueprintInspectionStateMember, type InspectionNodeId, type InspectionObservable, type InvalidBlueprintInspectionDependency, type ResolvedBlueprintInspectionDependency, type ResolvedBlueprintInspectionNode, type RuntimeInspection, type RuntimePropertyInspection, type RuntimePropertyInspectionSnapshot, type RuntimeStateInspection, type RuntimeStateInspectionSnapshot, type RuntimeWidgetInspection, type UnresolvedBlueprintInspectionNode, inspectBlueprint, inspectRuntime };
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { a as isCompiledDependency, o as readCompiledBlueprint, t as readRuntimeInternals } from "../internals-DXFEmv8H.mjs";
|
|
2
|
+
//#region src/inspection/blueprint.ts
|
|
3
|
+
/**
|
|
4
|
+
* Projects a compiler-owned `BlueprintDependencyReference` into an independent, deep-frozen structural
|
|
5
|
+
* clone (`target`/`operation` included).
|
|
6
|
+
*
|
|
7
|
+
* The compiler's own `reference` object (and its nested `target`/`operation` wrappers) is not guaranteed
|
|
8
|
+
* frozen for resolved/absent leaves — only diagnostic finalization freezes it, and resolved/absent leaves
|
|
9
|
+
* never produce an Diagnostic of their own. Runtime dependency-callable closures (`../runtime/deps.ts`)
|
|
10
|
+
* capture that *same* object; aliasing it directly into the public inspection snapshot would let a
|
|
11
|
+
* consumer mutate `dependency.reference.operation`/`.target` through `as any` and corrupt later Runtime
|
|
12
|
+
* lookups/diagnostics — a live inspection-to-semantics channel the readonly contract must not allow.
|
|
13
|
+
*/
|
|
14
|
+
function freezeClonedReference(reference) {
|
|
15
|
+
const target = Object.freeze({ ...reference.target });
|
|
16
|
+
const operation = Object.freeze({ ...reference.operation });
|
|
17
|
+
return Object.freeze({
|
|
18
|
+
target,
|
|
19
|
+
operation
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function buildMemberRef(nodeId, operation) {
|
|
23
|
+
const member = operation.type === "state-get" || operation.type === "state-set" ? {
|
|
24
|
+
type: "state",
|
|
25
|
+
name: operation.key
|
|
26
|
+
} : operation.type === "property-get" ? {
|
|
27
|
+
type: "property",
|
|
28
|
+
name: operation.name
|
|
29
|
+
} : {
|
|
30
|
+
type: "method",
|
|
31
|
+
name: operation.name
|
|
32
|
+
};
|
|
33
|
+
return Object.freeze({
|
|
34
|
+
nodeId,
|
|
35
|
+
member: Object.freeze(member)
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function projectDependency(leaf, path) {
|
|
39
|
+
const frozenPath = Object.freeze(path);
|
|
40
|
+
const reference = freezeClonedReference(leaf.reference);
|
|
41
|
+
if (leaf.status === "resolved") return Object.freeze({
|
|
42
|
+
status: "resolved",
|
|
43
|
+
path: frozenPath,
|
|
44
|
+
reference,
|
|
45
|
+
target: buildMemberRef(leaf.targetNodeId, leaf.reference.operation)
|
|
46
|
+
});
|
|
47
|
+
if (leaf.status === "absent") return Object.freeze({
|
|
48
|
+
status: "absent",
|
|
49
|
+
path: frozenPath,
|
|
50
|
+
reference
|
|
51
|
+
});
|
|
52
|
+
return Object.freeze({
|
|
53
|
+
status: "invalid",
|
|
54
|
+
path: frozenPath,
|
|
55
|
+
reference,
|
|
56
|
+
...leaf.targetNodeId === void 0 ? {} : { targetNodeId: leaf.targetNodeId }
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Recursive dependency-container leaf traversal, in the same order `../blueprint/deps.ts`'s `walkDeps`
|
|
61
|
+
* built the tree (array index order; object key order — `Object.keys()` of a `registerDeps()`-authored
|
|
62
|
+
* container preserves the plugin's own insertion order, including special names like `__proto__`).
|
|
63
|
+
*/
|
|
64
|
+
function flattenDependencies(tree) {
|
|
65
|
+
const result = [];
|
|
66
|
+
function walk(node, path) {
|
|
67
|
+
if (isCompiledDependency(node)) {
|
|
68
|
+
result.push(projectDependency(node, path));
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (Array.isArray(node)) {
|
|
72
|
+
node.forEach((item, index) => walk(item, [...path, index]));
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
for (const key of Object.keys(node)) walk(node[key], [...path, key]);
|
|
76
|
+
}
|
|
77
|
+
walk(tree, []);
|
|
78
|
+
return Object.freeze(result);
|
|
79
|
+
}
|
|
80
|
+
function buildSourceSlots(compiledNode) {
|
|
81
|
+
const semanticSlots = compiledNode.resolved ? compiledNode.semanticSlots : null;
|
|
82
|
+
return Object.freeze(compiledNode.rawSlots.map((rawSlot) => Object.freeze({
|
|
83
|
+
name: rawSlot.slot,
|
|
84
|
+
placement: semanticSlots !== null && semanticSlots.has(rawSlot.slot) ? "slot" : "raw-slot",
|
|
85
|
+
children: Object.freeze(rawSlot.childNodeIds.map((id) => id))
|
|
86
|
+
})));
|
|
87
|
+
}
|
|
88
|
+
function buildSemanticSlots(compiledNode) {
|
|
89
|
+
const result = [];
|
|
90
|
+
for (const [name, childIds] of compiledNode.semanticSlots) result.push(Object.freeze({
|
|
91
|
+
name,
|
|
92
|
+
children: Object.freeze(childIds.map((id) => id))
|
|
93
|
+
}));
|
|
94
|
+
return Object.freeze(result);
|
|
95
|
+
}
|
|
96
|
+
function buildStateMembers(compiledNode) {
|
|
97
|
+
const result = [];
|
|
98
|
+
for (const name of compiledNode.state.keys()) result.push(Object.freeze({
|
|
99
|
+
type: "state",
|
|
100
|
+
name
|
|
101
|
+
}));
|
|
102
|
+
return Object.freeze(result);
|
|
103
|
+
}
|
|
104
|
+
function buildPropertyMembers(compiledNode) {
|
|
105
|
+
const result = [];
|
|
106
|
+
for (const [name, member] of compiledNode.properties) result.push(Object.freeze({
|
|
107
|
+
type: "property",
|
|
108
|
+
name,
|
|
109
|
+
dependencies: flattenDependencies(member.deps)
|
|
110
|
+
}));
|
|
111
|
+
return Object.freeze(result);
|
|
112
|
+
}
|
|
113
|
+
function buildMethodMembers(compiledNode) {
|
|
114
|
+
const result = [];
|
|
115
|
+
for (const [name, member] of compiledNode.methods) result.push(Object.freeze({
|
|
116
|
+
type: "method",
|
|
117
|
+
name,
|
|
118
|
+
transitivelyWrites: member.transitivelyWrites,
|
|
119
|
+
dependencies: flattenDependencies(member.deps)
|
|
120
|
+
}));
|
|
121
|
+
return Object.freeze(result);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Reuses the plugin's own public `capabilities` fact object (diagnostic #10 amendment "declaration-presence
|
|
125
|
+
* semantics and public `WidgetPlugin.capabilities`") rather than re-deriving presence from the erased
|
|
126
|
+
* definition: `plugin.capabilities` is already the compiler/builder-authoritative declaration-presence
|
|
127
|
+
* source, and `BlueprintInspectionCapabilities` is intentionally the same shape. No object-identity
|
|
128
|
+
* relationship between the two is part of either contract — reusing the reference here is an internal
|
|
129
|
+
* implementation choice, not something callers may rely on.
|
|
130
|
+
*/
|
|
131
|
+
function buildCapabilities(compiledNode) {
|
|
132
|
+
return compiledNode.plugin.capabilities;
|
|
133
|
+
}
|
|
134
|
+
function buildNode(compiledNode, nodeId) {
|
|
135
|
+
const sourceSlots = buildSourceSlots(compiledNode);
|
|
136
|
+
if (!compiledNode.resolved) return Object.freeze({
|
|
137
|
+
nodeId,
|
|
138
|
+
node: compiledNode.publicNode,
|
|
139
|
+
sourceSlots,
|
|
140
|
+
resolved: false
|
|
141
|
+
});
|
|
142
|
+
return Object.freeze({
|
|
143
|
+
nodeId,
|
|
144
|
+
node: compiledNode.publicNode,
|
|
145
|
+
sourceSlots,
|
|
146
|
+
resolved: true,
|
|
147
|
+
capabilities: buildCapabilities(compiledNode),
|
|
148
|
+
semanticSlots: buildSemanticSlots(compiledNode),
|
|
149
|
+
state: buildStateMembers(compiledNode),
|
|
150
|
+
properties: buildPropertyMembers(compiledNode),
|
|
151
|
+
methods: buildMethodMembers(compiledNode)
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Recovered-source topology pre-order: root first, then recursively each node's recovered children in
|
|
156
|
+
* `rawSlots` enumeration order, each with its children in source index order. Deliberately distinct from
|
|
157
|
+
* the compiler's own `semanticOrder` (which prioritizes declared slots over raw-only ones for diagnostic
|
|
158
|
+
* aggregation) — inspection's `nodes` ordering contract is topology-only, not semantic priority.
|
|
159
|
+
*/
|
|
160
|
+
function computePreOrder(nodes, rootNodeId) {
|
|
161
|
+
const order = [];
|
|
162
|
+
function visit(nodeId) {
|
|
163
|
+
order.push(nodeId);
|
|
164
|
+
const node = nodes[nodeId];
|
|
165
|
+
for (const rawSlot of node.rawSlots) for (const childId of rawSlot.childNodeIds) visit(childId);
|
|
166
|
+
}
|
|
167
|
+
visit(rootNodeId);
|
|
168
|
+
return order;
|
|
169
|
+
}
|
|
170
|
+
function buildInvalidCycles(compiled) {
|
|
171
|
+
return Object.freeze(compiled.analysis.invalidCycles.map((cycle) => Object.freeze({ members: Object.freeze(cycle.map((ref) => Object.freeze({
|
|
172
|
+
nodeId: ref.nodeId,
|
|
173
|
+
member: Object.freeze({ ...ref.member })
|
|
174
|
+
}))) })));
|
|
175
|
+
}
|
|
176
|
+
function buildBlueprintInspection(blueprint) {
|
|
177
|
+
const compiled = readCompiledBlueprint(blueprint);
|
|
178
|
+
const nodesByInternalId = compiled.nodes.map((compiledNode, nodeId) => buildNode(compiledNode, nodeId));
|
|
179
|
+
const preOrder = computePreOrder(compiled.nodes, compiled.rootNodeId);
|
|
180
|
+
const nodes = Object.freeze(preOrder.map((nodeId) => nodesByInternalId[nodeId]));
|
|
181
|
+
const invalidCycles = buildInvalidCycles(compiled);
|
|
182
|
+
function getNode(nodeId) {
|
|
183
|
+
return nodesByInternalId[nodeId] ?? null;
|
|
184
|
+
}
|
|
185
|
+
function getNodeId(node) {
|
|
186
|
+
const id = compiled.nodeIdByPublicNode.get(node);
|
|
187
|
+
return id === void 0 ? null : id;
|
|
188
|
+
}
|
|
189
|
+
return Object.freeze({
|
|
190
|
+
rootNodeId: compiled.rootNodeId,
|
|
191
|
+
nodes,
|
|
192
|
+
invalidCycles,
|
|
193
|
+
getNode,
|
|
194
|
+
getNodeId
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
const blueprintInspectionCache = /* @__PURE__ */ new WeakMap();
|
|
198
|
+
/**
|
|
199
|
+
* Returns the frozen, first-use eagerly-materialized Blueprint inspection snapshot for `blueprint`,
|
|
200
|
+
* cached (weak, no global strong retention) so `inspectBlueprint(blueprint) === inspectBlueprint(blueprint)`.
|
|
201
|
+
*/
|
|
202
|
+
function inspectBlueprint(blueprint) {
|
|
203
|
+
const cached = blueprintInspectionCache.get(blueprint);
|
|
204
|
+
if (cached !== void 0) return cached;
|
|
205
|
+
const built = buildBlueprintInspection(blueprint);
|
|
206
|
+
blueprintInspectionCache.set(blueprint, built);
|
|
207
|
+
return built;
|
|
208
|
+
}
|
|
209
|
+
//#endregion
|
|
210
|
+
//#region src/inspection/runtime.ts
|
|
211
|
+
function buildStateInspection(context, primitive) {
|
|
212
|
+
return Object.freeze({
|
|
213
|
+
getSnapshot: () => primitive.internal.inspection.getSnapshot(),
|
|
214
|
+
subscribe: (listener) => {
|
|
215
|
+
context.assertActive();
|
|
216
|
+
const rawUnsubscribe = primitive.internal.inspection.subscribe(listener);
|
|
217
|
+
return context.registerSubscription(rawUnsubscribe);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
function buildPropertyInspection(context, primitive) {
|
|
222
|
+
return Object.freeze({
|
|
223
|
+
getSnapshot: () => primitive.internal.inspection.getSnapshot(),
|
|
224
|
+
subscribe: (listener) => {
|
|
225
|
+
context.assertActive();
|
|
226
|
+
const rawUnsubscribe = primitive.internal.inspection.subscribe(listener);
|
|
227
|
+
return context.registerSubscription(rawUnsubscribe);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
function buildRuntimeWidgetInspection(context, nodeId, blueprintNode, entry) {
|
|
232
|
+
const stateFacades = /* @__PURE__ */ new Map();
|
|
233
|
+
const propertyFacades = /* @__PURE__ */ new Map();
|
|
234
|
+
function getState(key) {
|
|
235
|
+
const primitive = entry.state.get(key);
|
|
236
|
+
if (primitive === void 0) return null;
|
|
237
|
+
let facade = stateFacades.get(key);
|
|
238
|
+
if (facade === void 0) {
|
|
239
|
+
facade = buildStateInspection(context, primitive);
|
|
240
|
+
stateFacades.set(key, facade);
|
|
241
|
+
}
|
|
242
|
+
return facade;
|
|
243
|
+
}
|
|
244
|
+
function getProperty(name) {
|
|
245
|
+
const primitive = entry.properties.get(name);
|
|
246
|
+
if (primitive === void 0) return null;
|
|
247
|
+
let facade = propertyFacades.get(name);
|
|
248
|
+
if (facade === void 0) {
|
|
249
|
+
facade = buildPropertyInspection(context, primitive);
|
|
250
|
+
propertyFacades.set(name, facade);
|
|
251
|
+
}
|
|
252
|
+
return facade;
|
|
253
|
+
}
|
|
254
|
+
return Object.freeze({
|
|
255
|
+
nodeId,
|
|
256
|
+
blueprintNode,
|
|
257
|
+
getState,
|
|
258
|
+
getProperty
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
function buildRuntimeInspection(runtime) {
|
|
262
|
+
const { context, registry } = readRuntimeInternals(runtime);
|
|
263
|
+
const blueprintInspection = inspectBlueprint(runtime.blueprint);
|
|
264
|
+
const widgetInspections = /* @__PURE__ */ new Map();
|
|
265
|
+
function getWidget(nodeId) {
|
|
266
|
+
const cached = widgetInspections.get(nodeId);
|
|
267
|
+
if (cached !== void 0) return cached;
|
|
268
|
+
const blueprintNode = blueprintInspection.getNode(nodeId);
|
|
269
|
+
if (blueprintNode === null || !blueprintNode.resolved) return null;
|
|
270
|
+
const entry = registry.get(nodeId);
|
|
271
|
+
if (entry === void 0) return null;
|
|
272
|
+
const built = buildRuntimeWidgetInspection(context, nodeId, blueprintNode, entry);
|
|
273
|
+
widgetInspections.set(nodeId, built);
|
|
274
|
+
return built;
|
|
275
|
+
}
|
|
276
|
+
return Object.freeze({
|
|
277
|
+
blueprint: blueprintInspection,
|
|
278
|
+
getWidget
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
const runtimeInspectionCache = /* @__PURE__ */ new WeakMap();
|
|
282
|
+
/**
|
|
283
|
+
* Returns the readonly Runtime inspection facade for `runtime`, cached (weak, no global strong
|
|
284
|
+
* retention) so `inspectRuntime(runtime) === inspectRuntime(runtime)`. Explicitly allowed — and returns
|
|
285
|
+
* the facade over already-retained facts — even when called for the first time after `runtime.dispose()`
|
|
286
|
+
* (post-mortem inspection).
|
|
287
|
+
*/
|
|
288
|
+
function inspectRuntime(runtime) {
|
|
289
|
+
const cached = runtimeInspectionCache.get(runtime);
|
|
290
|
+
if (cached !== void 0) return cached;
|
|
291
|
+
const built = buildRuntimeInspection(runtime);
|
|
292
|
+
runtimeInspectionCache.set(runtime, built);
|
|
293
|
+
return built;
|
|
294
|
+
}
|
|
295
|
+
//#endregion
|
|
296
|
+
export { inspectBlueprint, inspectRuntime };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/internal/contract.ts
|
|
2
|
+
const compiledDependencyBrand = Symbol("@deviltea/widget-core:compiled-dependency");
|
|
3
|
+
function isCompiledDependency(value) {
|
|
4
|
+
return typeof value === "object" && value !== null && compiledDependencyBrand in value;
|
|
5
|
+
}
|
|
6
|
+
const blueprintInternals = Symbol("@deviltea/widget-core:blueprint-internals");
|
|
7
|
+
/**
|
|
8
|
+
* Reads the compiled snapshot carried by a Blueprint.
|
|
9
|
+
*/
|
|
10
|
+
function readCompiledBlueprint(blueprint) {
|
|
11
|
+
const compiled = blueprint[blueprintInternals];
|
|
12
|
+
if (compiled === void 0) throw new Error("The blueprint was not produced by this widget core build.");
|
|
13
|
+
return compiled;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/runtime/internals.ts
|
|
17
|
+
const runtimeInternals = Symbol("@deviltea/widget-core:runtime-internals");
|
|
18
|
+
/**
|
|
19
|
+
* Reads the internals carried by a Runtime produced by `createWidgetSystemRuntime`.
|
|
20
|
+
*/
|
|
21
|
+
function readRuntimeInternals(runtime) {
|
|
22
|
+
const internals = runtime[runtimeInternals];
|
|
23
|
+
if (internals === void 0) throw new Error("The runtime was not produced by this widget core build.");
|
|
24
|
+
return internals;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { isCompiledDependency as a, compiledDependencyBrand as i, runtimeInternals as n, readCompiledBlueprint as o, blueprintInternals as r, readRuntimeInternals as t };
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@deviltea/widget-core",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"version": "0.0.1",
|
|
8
|
+
"author": "DevilTea <ch19980814@gmail.com>",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"homepage": "https://github.com/DevilTea/deviltea-labs/tree/main/packages/widget/core#readme",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/DevilTea/deviltea-labs.git",
|
|
14
|
+
"directory": "packages/widget/core"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/DevilTea/deviltea-labs/issues"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"widget",
|
|
21
|
+
"composition",
|
|
22
|
+
"plugin",
|
|
23
|
+
"blueprint",
|
|
24
|
+
"runtime",
|
|
25
|
+
"signals"
|
|
26
|
+
],
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.mts",
|
|
30
|
+
"import": "./dist/index.mjs"
|
|
31
|
+
},
|
|
32
|
+
"./inspection": {
|
|
33
|
+
"types": "./dist/inspection/index.d.mts",
|
|
34
|
+
"import": "./dist/inspection/index.mjs"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"main": "dist/index.mjs",
|
|
38
|
+
"module": "dist/index.mjs",
|
|
39
|
+
"types": "dist/index.d.mts",
|
|
40
|
+
"files": [
|
|
41
|
+
"dist"
|
|
42
|
+
],
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": "^22.14.0 || ^24.0.0"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"alien-signals": "3.2.1"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"tsdown": "^0.22.3",
|
|
51
|
+
"vitest": "^4.1.9"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "tsdown",
|
|
55
|
+
"build:pack": "pnpm build && pnpm pack",
|
|
56
|
+
"dev": "tsdown --watch",
|
|
57
|
+
"test": "vitest run --config vitest.config.ts",
|
|
58
|
+
"typecheck": "pnpm typecheck:package && pnpm typecheck:test",
|
|
59
|
+
"typecheck:package": "tsc --project ./tsconfig.package.json --noEmit",
|
|
60
|
+
"typecheck:test": "tsc --project ./tsconfig.tests.json --noEmit"
|
|
61
|
+
}
|
|
62
|
+
}
|