@deviltea/widget-core 0.0.1 → 0.0.3
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/README.md +73 -12
- package/dist/{internals-DXFEmv8H.mjs → contract-CRpMqCY2.mjs} +8 -12
- package/dist/{dep-DKQpJwdW.d.mts → dep-DAoSoLhi.d.mts} +156 -26
- package/dist/event-BMif_vRJ.mjs +192 -0
- package/dist/index.d.mts +11 -2
- package/dist/index.mjs +149 -360
- package/dist/inspection/index.d.mts +79 -2
- package/dist/inspection/index.mjs +112 -10
- package/dist/integration/index.d.mts +12 -0
- package/dist/integration/index.mjs +26 -0
- package/dist/internals-L391flXY.mjs +199 -0
- package/package.json +12 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Jt as WidgetSystemBlueprint, T as BlueprintDependencyReference, Tn as WidgetPluginConfigMetadata, Tt as ResolvedBlueprintWidgetNode, Vt as UnresolvedBlueprintWidgetNode, Xt as WidgetSystemRuntime, bt as BlueprintWidgetNode, cn as AnyWidgetPluginTuple, dr as WidgetMemberKey, lt as RuntimePropertyDiagnostic, sn as AnyWidgetPlugin, tr as ExecutionResult } from "../dep-DAoSoLhi.mjs";
|
|
2
2
|
//#region src/inspection/types.d.ts
|
|
3
3
|
declare const inspectionNodeIdBrand: unique symbol;
|
|
4
4
|
/**
|
|
@@ -11,12 +11,36 @@ declare const inspectionNodeIdBrand: unique symbol;
|
|
|
11
11
|
type InspectionNodeId = number & {
|
|
12
12
|
readonly [inspectionNodeIdBrand]: true;
|
|
13
13
|
};
|
|
14
|
+
interface PluginInspectionStateMember {
|
|
15
|
+
readonly type: 'state';
|
|
16
|
+
readonly name: WidgetMemberKey;
|
|
17
|
+
readonly authorWritable: boolean;
|
|
18
|
+
}
|
|
19
|
+
interface PluginInspectionPropertyMember {
|
|
20
|
+
readonly type: 'property';
|
|
21
|
+
readonly name: WidgetMemberKey;
|
|
22
|
+
readonly valueContractId: string | null;
|
|
23
|
+
}
|
|
24
|
+
interface PluginInspectionEventMember {
|
|
25
|
+
readonly type: 'event';
|
|
26
|
+
readonly name: WidgetMemberKey;
|
|
27
|
+
readonly description: string;
|
|
28
|
+
}
|
|
29
|
+
interface PluginInspection {
|
|
30
|
+
/** Null means the State capability was not declared; an empty map means explicitly declared empty. */
|
|
31
|
+
readonly state: ReadonlyMap<WidgetMemberKey, PluginInspectionStateMember> | null;
|
|
32
|
+
/** Null means the Properties capability was not declared; an empty map means explicitly declared empty. */
|
|
33
|
+
readonly properties: ReadonlyMap<WidgetMemberKey, PluginInspectionPropertyMember> | null;
|
|
34
|
+
/** Null means the Events capability was not declared; an empty map means explicitly declared empty. */
|
|
35
|
+
readonly events: ReadonlyMap<WidgetMemberKey, PluginInspectionEventMember> | null;
|
|
36
|
+
}
|
|
14
37
|
interface BlueprintInspectionCapabilities {
|
|
15
38
|
readonly config: boolean;
|
|
16
39
|
readonly slots: boolean;
|
|
17
40
|
readonly state: boolean;
|
|
18
41
|
readonly properties: boolean;
|
|
19
42
|
readonly methods: boolean;
|
|
43
|
+
readonly events: boolean;
|
|
20
44
|
}
|
|
21
45
|
interface BlueprintInspectionSourceSlot {
|
|
22
46
|
readonly name: string;
|
|
@@ -70,12 +94,19 @@ type BlueprintInspectionDependency = ResolvedBlueprintInspectionDependency | Abs
|
|
|
70
94
|
interface BlueprintInspectionStateMember {
|
|
71
95
|
readonly type: 'state';
|
|
72
96
|
readonly name: WidgetMemberKey;
|
|
97
|
+
readonly authorWritable: boolean;
|
|
73
98
|
}
|
|
74
99
|
interface BlueprintInspectionPropertyMember {
|
|
75
100
|
readonly type: 'property';
|
|
76
101
|
readonly name: WidgetMemberKey;
|
|
102
|
+
readonly valueContractId: string | null;
|
|
77
103
|
readonly dependencies: readonly BlueprintInspectionDependency[];
|
|
78
104
|
}
|
|
105
|
+
interface BlueprintInspectionEventMember {
|
|
106
|
+
readonly type: 'event';
|
|
107
|
+
readonly name: WidgetMemberKey;
|
|
108
|
+
readonly description: string;
|
|
109
|
+
}
|
|
79
110
|
interface BlueprintInspectionMethodMember {
|
|
80
111
|
readonly type: 'method';
|
|
81
112
|
readonly name: WidgetMemberKey;
|
|
@@ -102,10 +133,13 @@ interface ResolvedBlueprintInspectionNode<Plugins extends AnyWidgetPluginTuple =
|
|
|
102
133
|
readonly node: ResolvedBlueprintWidgetNode<Plugins>;
|
|
103
134
|
/** Authoritative capability presence (absent vs explicitly declared empty). */
|
|
104
135
|
readonly capabilities: BlueprintInspectionCapabilities;
|
|
136
|
+
/** Passive config authoring metadata. Null means no config capability. */
|
|
137
|
+
readonly config: WidgetPluginConfigMetadata | null;
|
|
105
138
|
readonly semanticSlots: readonly BlueprintInspectionSemanticSlot[];
|
|
106
139
|
readonly state: readonly BlueprintInspectionStateMember[];
|
|
107
140
|
readonly properties: readonly BlueprintInspectionPropertyMember[];
|
|
108
141
|
readonly methods: readonly BlueprintInspectionMethodMember[];
|
|
142
|
+
readonly events: readonly BlueprintInspectionEventMember[];
|
|
109
143
|
}
|
|
110
144
|
type BlueprintInspectionNode<Plugins extends AnyWidgetPluginTuple = AnyWidgetPluginTuple> = UnresolvedBlueprintInspectionNode<Plugins> | ResolvedBlueprintInspectionNode<Plugins>;
|
|
111
145
|
interface BlueprintInspectionEvaluationMemberRef {
|
|
@@ -149,6 +183,25 @@ type RuntimePropertyInspectionSnapshot<T> = {
|
|
|
149
183
|
readonly result: ExecutionResult<T | null, RuntimePropertyDiagnostic>;
|
|
150
184
|
};
|
|
151
185
|
interface RuntimePropertyInspection<T> extends InspectionObservable<RuntimePropertyInspectionSnapshot<T>> {}
|
|
186
|
+
/**
|
|
187
|
+
* Passive, readonly observation of one Event member's occurrences. It grants no emit authority and never
|
|
188
|
+
* changes emission, public listener membership or order, or any exception the emitter sees.
|
|
189
|
+
*
|
|
190
|
+
* For one emit, every inspection listener runs **before** any public listener; the public audience is
|
|
191
|
+
* fixed before inspection listeners run, so an inspection callback cannot join the current public
|
|
192
|
+
* delivery. The inspection audience is snapshotted per occurrence. A throwing listener is isolated (it
|
|
193
|
+
* reaches neither the emitter, peer inspection listeners nor public listeners) and is reported outside
|
|
194
|
+
* the emit call; the reporting mechanism is not normative. Each occurrence passes one shallow-frozen
|
|
195
|
+
* args array shared by that occurrence's listeners; elements are the emitted references and are not
|
|
196
|
+
* cloned or deep-frozen. Only future occurrences are delivered (no replay or history). After
|
|
197
|
+
* `runtime.dispose()`, a new `subscribe()` throws `WidgetSystemRuntimeDisposedError`, earlier
|
|
198
|
+
* subscriptions receive nothing further, and unsubscribe stays idempotent. What a listener does by
|
|
199
|
+
* synchronously writing State or invoking Methods is not guaranteed beyond ordinary Runtime rules;
|
|
200
|
+
* defer such work, for example to a microtask.
|
|
201
|
+
*/
|
|
202
|
+
interface RuntimeEventInspection {
|
|
203
|
+
subscribe: (listener: (args: readonly unknown[]) => void) => () => void;
|
|
204
|
+
}
|
|
152
205
|
interface RuntimeWidgetInspection<Plugins extends AnyWidgetPluginTuple = AnyWidgetPluginTuple> {
|
|
153
206
|
readonly nodeId: InspectionNodeId;
|
|
154
207
|
readonly blueprintNode: ResolvedBlueprintInspectionNode<Plugins>;
|
|
@@ -156,6 +209,8 @@ interface RuntimeWidgetInspection<Plugins extends AnyWidgetPluginTuple = AnyWidg
|
|
|
156
209
|
getState: (key: WidgetMemberKey) => RuntimeStateInspection<unknown> | null;
|
|
157
210
|
/** `null` when the property member/capability does not exist. Dynamic `unknown` typing. */
|
|
158
211
|
getProperty: (name: WidgetMemberKey) => RuntimePropertyInspection<unknown> | null;
|
|
212
|
+
/** `null` when the event member/capability does not exist. Readonly occurrence observation only. */
|
|
213
|
+
getEvent: (name: WidgetMemberKey) => RuntimeEventInspection | null;
|
|
159
214
|
}
|
|
160
215
|
interface RuntimeInspection<Plugins extends AnyWidgetPluginTuple = AnyWidgetPluginTuple> {
|
|
161
216
|
/** Identity-stable with `inspectBlueprint(runtime.blueprint)`. */
|
|
@@ -178,6 +233,28 @@ interface RuntimeInspection<Plugins extends AnyWidgetPluginTuple = AnyWidgetPlug
|
|
|
178
233
|
*/
|
|
179
234
|
declare function inspectBlueprint<Plugins extends AnyWidgetPluginTuple = AnyWidgetPluginTuple>(blueprint: WidgetSystemBlueprint<Plugins>): BlueprintInspection<Plugins>;
|
|
180
235
|
//#endregion
|
|
236
|
+
//#region src/inspection/errors.d.ts
|
|
237
|
+
/**
|
|
238
|
+
* Coded exception for foreign inputs to the inspection entries.
|
|
239
|
+
*/
|
|
240
|
+
type WidgetInspectionErrorCode = 'foreign-plugin' | 'foreign-blueprint' | 'foreign-runtime';
|
|
241
|
+
/**
|
|
242
|
+
* Thrown by `inspectPlugin` / `inspectBlueprint` / `inspectRuntime` when the argument was not produced
|
|
243
|
+
* by this loaded `@deviltea/widget-core` module instance (another module instance or a structural
|
|
244
|
+
* look-alike). Discriminate by class and `code`; `message` is not protocol.
|
|
245
|
+
*/
|
|
246
|
+
declare class WidgetInspectionError extends Error {
|
|
247
|
+
readonly code: WidgetInspectionErrorCode;
|
|
248
|
+
readonly name = "WidgetInspectionError";
|
|
249
|
+
constructor(code: WidgetInspectionErrorCode, message?: string);
|
|
250
|
+
}
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/inspection/plugin.d.ts
|
|
253
|
+
/**
|
|
254
|
+
* Returns an identity-stable, readonly/passive projection for the exact completed Plugin object.
|
|
255
|
+
*/
|
|
256
|
+
declare function inspectPlugin(plugin: AnyWidgetPlugin): PluginInspection;
|
|
257
|
+
//#endregion
|
|
181
258
|
//#region src/inspection/runtime.d.ts
|
|
182
259
|
/**
|
|
183
260
|
* Returns the readonly Runtime inspection facade for `runtime`, cached (weak, no global strong
|
|
@@ -187,4 +264,4 @@ declare function inspectBlueprint<Plugins extends AnyWidgetPluginTuple = AnyWidg
|
|
|
187
264
|
*/
|
|
188
265
|
declare function inspectRuntime<Plugins extends AnyWidgetPluginTuple = AnyWidgetPluginTuple>(runtime: WidgetSystemRuntime<Plugins>): RuntimeInspection<Plugins>;
|
|
189
266
|
//#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 };
|
|
267
|
+
export { type AbsentBlueprintInspectionDependency, type BlueprintInspection, type BlueprintInspectionCapabilities, type BlueprintInspectionDependency, type BlueprintInspectionDependencyBase, type BlueprintInspectionEvaluationMemberRef, type BlueprintInspectionEventMember, 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 PluginInspection, type PluginInspectionEventMember, type PluginInspectionPropertyMember, type PluginInspectionStateMember, type ResolvedBlueprintInspectionDependency, type ResolvedBlueprintInspectionNode, type RuntimeEventInspection, type RuntimeInspection, type RuntimePropertyInspection, type RuntimePropertyInspectionSnapshot, type RuntimeStateInspection, type RuntimeStateInspectionSnapshot, type RuntimeWidgetInspection, type UnresolvedBlueprintInspectionNode, WidgetInspectionError, type WidgetInspectionErrorCode, inspectBlueprint, inspectPlugin, inspectRuntime };
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as readWidgetPluginDefinition, l as createReadonlyMap, n as readRuntimeInternals, s as isCoreWidgetPlugin, t as isCoreRuntime } from "../internals-L391flXY.mjs";
|
|
2
|
+
import { a as readCompiledBlueprint, i as isCoreBlueprint, r as isCompiledDependency } from "../contract-CRpMqCY2.mjs";
|
|
3
|
+
//#region src/inspection/errors.ts
|
|
4
|
+
/**
|
|
5
|
+
* Thrown by `inspectPlugin` / `inspectBlueprint` / `inspectRuntime` when the argument was not produced
|
|
6
|
+
* by this loaded `@deviltea/widget-core` module instance (another module instance or a structural
|
|
7
|
+
* look-alike). Discriminate by class and `code`; `message` is not protocol.
|
|
8
|
+
*/
|
|
9
|
+
var WidgetInspectionError = class extends Error {
|
|
10
|
+
code;
|
|
11
|
+
name = "WidgetInspectionError";
|
|
12
|
+
constructor(code, message = `The ${code.slice(8)} was not produced by this widget core instance.`) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.code = code;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
2
18
|
//#region src/inspection/blueprint.ts
|
|
3
19
|
/**
|
|
4
20
|
* Projects a compiler-owned `BlueprintDependencyReference` into an independent, deep-frozen structural
|
|
@@ -93,23 +109,36 @@ function buildSemanticSlots(compiledNode) {
|
|
|
93
109
|
}));
|
|
94
110
|
return Object.freeze(result);
|
|
95
111
|
}
|
|
96
|
-
function buildStateMembers(compiledNode) {
|
|
112
|
+
function buildStateMembers$1(compiledNode) {
|
|
97
113
|
const result = [];
|
|
98
|
-
for (const name of compiledNode.state
|
|
114
|
+
for (const [name, member] of compiledNode.state) result.push(Object.freeze({
|
|
99
115
|
type: "state",
|
|
100
|
-
name
|
|
116
|
+
name,
|
|
117
|
+
authorWritable: member.definition.authorWritable === true
|
|
101
118
|
}));
|
|
102
119
|
return Object.freeze(result);
|
|
103
120
|
}
|
|
104
|
-
function buildPropertyMembers(compiledNode) {
|
|
121
|
+
function buildPropertyMembers$1(compiledNode) {
|
|
105
122
|
const result = [];
|
|
106
123
|
for (const [name, member] of compiledNode.properties) result.push(Object.freeze({
|
|
107
124
|
type: "property",
|
|
108
125
|
name,
|
|
126
|
+
valueContractId: member.definition.valueContract?.id ?? null,
|
|
109
127
|
dependencies: flattenDependencies(member.deps)
|
|
110
128
|
}));
|
|
111
129
|
return Object.freeze(result);
|
|
112
130
|
}
|
|
131
|
+
function buildEventMembers$1(compiledNode) {
|
|
132
|
+
const definitions = readWidgetPluginDefinition(compiledNode.plugin).events;
|
|
133
|
+
if (definitions === null) return Object.freeze([]);
|
|
134
|
+
const result = [];
|
|
135
|
+
for (const [name, definition] of definitions) result.push(Object.freeze({
|
|
136
|
+
type: "event",
|
|
137
|
+
name,
|
|
138
|
+
description: definition.description
|
|
139
|
+
}));
|
|
140
|
+
return Object.freeze(result);
|
|
141
|
+
}
|
|
113
142
|
function buildMethodMembers(compiledNode) {
|
|
114
143
|
const result = [];
|
|
115
144
|
for (const [name, member] of compiledNode.methods) result.push(Object.freeze({
|
|
@@ -145,10 +174,12 @@ function buildNode(compiledNode, nodeId) {
|
|
|
145
174
|
sourceSlots,
|
|
146
175
|
resolved: true,
|
|
147
176
|
capabilities: buildCapabilities(compiledNode),
|
|
177
|
+
config: compiledNode.plugin.config,
|
|
148
178
|
semanticSlots: buildSemanticSlots(compiledNode),
|
|
149
|
-
state: buildStateMembers(compiledNode),
|
|
150
|
-
properties: buildPropertyMembers(compiledNode),
|
|
151
|
-
methods: buildMethodMembers(compiledNode)
|
|
179
|
+
state: buildStateMembers$1(compiledNode),
|
|
180
|
+
properties: buildPropertyMembers$1(compiledNode),
|
|
181
|
+
methods: buildMethodMembers(compiledNode),
|
|
182
|
+
events: buildEventMembers$1(compiledNode)
|
|
152
183
|
});
|
|
153
184
|
}
|
|
154
185
|
/**
|
|
@@ -200,6 +231,7 @@ const blueprintInspectionCache = /* @__PURE__ */ new WeakMap();
|
|
|
200
231
|
* cached (weak, no global strong retention) so `inspectBlueprint(blueprint) === inspectBlueprint(blueprint)`.
|
|
201
232
|
*/
|
|
202
233
|
function inspectBlueprint(blueprint) {
|
|
234
|
+
if (!isCoreBlueprint(blueprint)) throw new WidgetInspectionError("foreign-blueprint");
|
|
203
235
|
const cached = blueprintInspectionCache.get(blueprint);
|
|
204
236
|
if (cached !== void 0) return cached;
|
|
205
237
|
const built = buildBlueprintInspection(blueprint);
|
|
@@ -207,6 +239,57 @@ function inspectBlueprint(blueprint) {
|
|
|
207
239
|
return built;
|
|
208
240
|
}
|
|
209
241
|
//#endregion
|
|
242
|
+
//#region src/inspection/plugin.ts
|
|
243
|
+
const inspectionCache = /* @__PURE__ */ new WeakMap();
|
|
244
|
+
function buildStateMembers(plugin) {
|
|
245
|
+
const definitions = readWidgetPluginDefinition(plugin).state;
|
|
246
|
+
if (definitions === null) return null;
|
|
247
|
+
const members = [];
|
|
248
|
+
for (const [name, definition] of definitions) members.push([name, Object.freeze({
|
|
249
|
+
type: "state",
|
|
250
|
+
name,
|
|
251
|
+
authorWritable: definition.authorWritable === true
|
|
252
|
+
})]);
|
|
253
|
+
return createReadonlyMap(members);
|
|
254
|
+
}
|
|
255
|
+
function buildPropertyMembers(plugin) {
|
|
256
|
+
const definitions = readWidgetPluginDefinition(plugin).properties;
|
|
257
|
+
if (definitions === null) return null;
|
|
258
|
+
const members = [];
|
|
259
|
+
for (const [name, definition] of definitions) members.push([name, Object.freeze({
|
|
260
|
+
type: "property",
|
|
261
|
+
name,
|
|
262
|
+
valueContractId: definition.valueContract?.id ?? null
|
|
263
|
+
})]);
|
|
264
|
+
return createReadonlyMap(members);
|
|
265
|
+
}
|
|
266
|
+
function buildEventMembers(plugin) {
|
|
267
|
+
const definitions = readWidgetPluginDefinition(plugin).events;
|
|
268
|
+
if (definitions === null) return null;
|
|
269
|
+
const members = [];
|
|
270
|
+
for (const [name, definition] of definitions) members.push([name, Object.freeze({
|
|
271
|
+
type: "event",
|
|
272
|
+
name,
|
|
273
|
+
description: definition.description
|
|
274
|
+
})]);
|
|
275
|
+
return createReadonlyMap(members);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Returns an identity-stable, readonly/passive projection for the exact completed Plugin object.
|
|
279
|
+
*/
|
|
280
|
+
function inspectPlugin(plugin) {
|
|
281
|
+
if (!isCoreWidgetPlugin(plugin)) throw new WidgetInspectionError("foreign-plugin");
|
|
282
|
+
const existing = inspectionCache.get(plugin);
|
|
283
|
+
if (existing !== void 0) return existing;
|
|
284
|
+
const inspection = Object.freeze({
|
|
285
|
+
state: buildStateMembers(plugin),
|
|
286
|
+
properties: buildPropertyMembers(plugin),
|
|
287
|
+
events: buildEventMembers(plugin)
|
|
288
|
+
});
|
|
289
|
+
inspectionCache.set(plugin, inspection);
|
|
290
|
+
return inspection;
|
|
291
|
+
}
|
|
292
|
+
//#endregion
|
|
210
293
|
//#region src/inspection/runtime.ts
|
|
211
294
|
function buildStateInspection(context, primitive) {
|
|
212
295
|
return Object.freeze({
|
|
@@ -228,9 +311,16 @@ function buildPropertyInspection(context, primitive) {
|
|
|
228
311
|
}
|
|
229
312
|
});
|
|
230
313
|
}
|
|
314
|
+
function buildEventInspection(context, primitive) {
|
|
315
|
+
return Object.freeze({ subscribe(listener) {
|
|
316
|
+
context.assertActive();
|
|
317
|
+
return context.registerSubscription(primitive.inspection.subscribe(listener));
|
|
318
|
+
} });
|
|
319
|
+
}
|
|
231
320
|
function buildRuntimeWidgetInspection(context, nodeId, blueprintNode, entry) {
|
|
232
321
|
const stateFacades = /* @__PURE__ */ new Map();
|
|
233
322
|
const propertyFacades = /* @__PURE__ */ new Map();
|
|
323
|
+
const eventFacades = /* @__PURE__ */ new Map();
|
|
234
324
|
function getState(key) {
|
|
235
325
|
const primitive = entry.state.get(key);
|
|
236
326
|
if (primitive === void 0) return null;
|
|
@@ -241,6 +331,16 @@ function buildRuntimeWidgetInspection(context, nodeId, blueprintNode, entry) {
|
|
|
241
331
|
}
|
|
242
332
|
return facade;
|
|
243
333
|
}
|
|
334
|
+
function getEvent(name) {
|
|
335
|
+
const primitive = entry.events.get(name);
|
|
336
|
+
if (primitive === void 0) return null;
|
|
337
|
+
let facade = eventFacades.get(name);
|
|
338
|
+
if (facade === void 0) {
|
|
339
|
+
facade = buildEventInspection(context, primitive);
|
|
340
|
+
eventFacades.set(name, facade);
|
|
341
|
+
}
|
|
342
|
+
return facade;
|
|
343
|
+
}
|
|
244
344
|
function getProperty(name) {
|
|
245
345
|
const primitive = entry.properties.get(name);
|
|
246
346
|
if (primitive === void 0) return null;
|
|
@@ -255,7 +355,8 @@ function buildRuntimeWidgetInspection(context, nodeId, blueprintNode, entry) {
|
|
|
255
355
|
nodeId,
|
|
256
356
|
blueprintNode,
|
|
257
357
|
getState,
|
|
258
|
-
getProperty
|
|
358
|
+
getProperty,
|
|
359
|
+
getEvent
|
|
259
360
|
});
|
|
260
361
|
}
|
|
261
362
|
function buildRuntimeInspection(runtime) {
|
|
@@ -286,6 +387,7 @@ const runtimeInspectionCache = /* @__PURE__ */ new WeakMap();
|
|
|
286
387
|
* (post-mortem inspection).
|
|
287
388
|
*/
|
|
288
389
|
function inspectRuntime(runtime) {
|
|
390
|
+
if (!isCoreRuntime(runtime)) throw new WidgetInspectionError("foreign-runtime");
|
|
289
391
|
const cached = runtimeInspectionCache.get(runtime);
|
|
290
392
|
if (cached !== void 0) return cached;
|
|
291
393
|
const built = buildRuntimeInspection(runtime);
|
|
@@ -293,4 +395,4 @@ function inspectRuntime(runtime) {
|
|
|
293
395
|
return built;
|
|
294
396
|
}
|
|
295
397
|
//#endregion
|
|
296
|
-
export { inspectBlueprint, inspectRuntime };
|
|
398
|
+
export { WidgetInspectionError, inspectBlueprint, inspectPlugin, inspectRuntime };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Lt as RuntimeWidget, Xt as WidgetSystemRuntime, cn as AnyWidgetPluginTuple, dr as WidgetMemberKey } from "../dep-DAoSoLhi.mjs";
|
|
2
|
+
//#region src/integration/index.d.ts
|
|
3
|
+
type WidgetIntegrationErrorCode = 'runtime-widget-mismatch' | 'foreign-runtime';
|
|
4
|
+
declare class WidgetIntegrationError extends Error {
|
|
5
|
+
readonly code: WidgetIntegrationErrorCode;
|
|
6
|
+
readonly name = "WidgetIntegrationError";
|
|
7
|
+
constructor(code: WidgetIntegrationErrorCode, message?: string);
|
|
8
|
+
}
|
|
9
|
+
type WidgetIntegrationEventEmitter = Readonly<Record<WidgetMemberKey, (...args: readonly unknown[]) => void>>;
|
|
10
|
+
declare function getWidgetEventEmitter<Plugins extends AnyWidgetPluginTuple>(runtime: WidgetSystemRuntime<Plugins>, widget: RuntimeWidget<Plugins>): WidgetIntegrationEventEmitter | null;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { WidgetIntegrationError, WidgetIntegrationErrorCode, WidgetIntegrationEventEmitter, getWidgetEventEmitter };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { t as buildEventEmitter } from "../event-BMif_vRJ.mjs";
|
|
2
|
+
import { c as readWidgetPluginDefinition, n as readRuntimeInternals, t as isCoreRuntime } from "../internals-L391flXY.mjs";
|
|
3
|
+
//#region src/integration/index.ts
|
|
4
|
+
var WidgetIntegrationError = class extends Error {
|
|
5
|
+
code;
|
|
6
|
+
name = "WidgetIntegrationError";
|
|
7
|
+
constructor(code, message = code === "foreign-runtime" ? "The supplied WidgetSystemRuntime was not produced by this widget core instance." : "The RuntimeWidget does not belong to the supplied WidgetSystemRuntime instance.") {
|
|
8
|
+
super(message);
|
|
9
|
+
this.code = code;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
function getWidgetEventEmitter(runtime, widget) {
|
|
13
|
+
if (!isCoreRuntime(runtime)) throw new WidgetIntegrationError("foreign-runtime");
|
|
14
|
+
const internals = readRuntimeInternals(runtime);
|
|
15
|
+
internals.context.assertActive();
|
|
16
|
+
const nodeId = typeof widget === "object" && widget !== null ? internals.nodeIdByRuntimeWidget.get(widget) : void 0;
|
|
17
|
+
if (nodeId === void 0) throw new WidgetIntegrationError("runtime-widget-mismatch");
|
|
18
|
+
const node = internals.compiled.nodes[nodeId];
|
|
19
|
+
if (node === void 0 || !node.resolved) throw new Error("The RuntimeWidget is not backed by a resolved Runtime node.");
|
|
20
|
+
if (readWidgetPluginDefinition(node.plugin).events === null) return null;
|
|
21
|
+
const entry = internals.registry.get(nodeId);
|
|
22
|
+
if (entry === void 0) throw new Error("The RuntimeWidget event implementation was not found in the supplied Runtime.");
|
|
23
|
+
return buildEventEmitter(entry.events);
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { WidgetIntegrationError, getWidgetEventEmitter };
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
//#region src/readonly-map.ts
|
|
2
|
+
/** Creates a map-shaped, runtime immutable projection without exposing mutating Map methods. */
|
|
3
|
+
function createReadonlyMap(entries) {
|
|
4
|
+
const map = new Map(entries);
|
|
5
|
+
const result = {
|
|
6
|
+
get size() {
|
|
7
|
+
return map.size;
|
|
8
|
+
},
|
|
9
|
+
get(key) {
|
|
10
|
+
return map.get(key);
|
|
11
|
+
},
|
|
12
|
+
has(key) {
|
|
13
|
+
return map.has(key);
|
|
14
|
+
},
|
|
15
|
+
keys() {
|
|
16
|
+
return map.keys();
|
|
17
|
+
},
|
|
18
|
+
values() {
|
|
19
|
+
return map.values();
|
|
20
|
+
},
|
|
21
|
+
entries() {
|
|
22
|
+
return map.entries();
|
|
23
|
+
},
|
|
24
|
+
forEach(callbackfn, thisArg) {
|
|
25
|
+
map.forEach((value, key) => callbackfn.call(thisArg, value, key, result));
|
|
26
|
+
},
|
|
27
|
+
[Symbol.iterator]() {
|
|
28
|
+
return map[Symbol.iterator]();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
return Object.freeze(result);
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/plugin.ts
|
|
35
|
+
/**
|
|
36
|
+
* Framework-private brand carrying the plugin's phantom interfaces and its erased definition record.
|
|
37
|
+
*/
|
|
38
|
+
const widgetPluginBrand = Symbol("@deviltea/widget-core:widget-plugin");
|
|
39
|
+
/**
|
|
40
|
+
* Declares a stable semantic value-contract id while retaining the associated TypeScript value type for
|
|
41
|
+
* Plugin-author checking. Core does not interpret, register, validate, or schema-check contract ids.
|
|
42
|
+
*/
|
|
43
|
+
function createWidgetValueContract(id) {
|
|
44
|
+
return Object.freeze({ id });
|
|
45
|
+
}
|
|
46
|
+
const WIDGET_CONFIG_JSON_SCHEMA_DIALECT = "https://json-schema.org/draft/2020-12/schema";
|
|
47
|
+
/**
|
|
48
|
+
* Provenance probe: true only for plugins completed by this loaded module instance. A plugin from
|
|
49
|
+
* another module instance (its brand is a different Symbol) or a structural look-alike is foreign.
|
|
50
|
+
* Capability separation, not a security sandbox.
|
|
51
|
+
*/
|
|
52
|
+
function isCoreWidgetPlugin(value) {
|
|
53
|
+
if (typeof value !== "object" || value === null) return false;
|
|
54
|
+
const brand = value[widgetPluginBrand];
|
|
55
|
+
return typeof brand === "object" && brand !== null && typeof brand.definition === "object" && brand.definition !== null;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Reads the erased definition record of a plugin.
|
|
59
|
+
*/
|
|
60
|
+
function readWidgetPluginDefinition(plugin) {
|
|
61
|
+
return plugin[widgetPluginBrand].definition;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Builds the section keyed-chain object.
|
|
65
|
+
*
|
|
66
|
+
* Declared member keys exist only at the type level, so every string member access resolves to a
|
|
67
|
+
* consuming function; the returned chain object is the same object by identity.
|
|
68
|
+
*/
|
|
69
|
+
function createSection(sink) {
|
|
70
|
+
const section = new Proxy({}, { get(_target, key) {
|
|
71
|
+
if (typeof key !== "string") return void 0;
|
|
72
|
+
return (definition) => {
|
|
73
|
+
sink.set(key, definition);
|
|
74
|
+
return section;
|
|
75
|
+
};
|
|
76
|
+
} });
|
|
77
|
+
return section;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Starts the plugin builder for one plugin `type`.
|
|
81
|
+
*
|
|
82
|
+
* Phase order is `description -> interfaces -> config? -> slots? -> state? -> properties? -> methods? -> events? -> done()`;
|
|
83
|
+
* a phase exists only when its capability is declared. Calling a declared phase out of order (or
|
|
84
|
+
* repeating it) fails type-checking with an order-specific diagnostic; the runtime builder itself is
|
|
85
|
+
* order-agnostic.
|
|
86
|
+
*/
|
|
87
|
+
function createWidgetPlugin(type) {
|
|
88
|
+
const draft = {
|
|
89
|
+
description: "",
|
|
90
|
+
config: null,
|
|
91
|
+
slots: null,
|
|
92
|
+
validateStructure: null,
|
|
93
|
+
state: null,
|
|
94
|
+
properties: null,
|
|
95
|
+
methods: null,
|
|
96
|
+
events: null
|
|
97
|
+
};
|
|
98
|
+
const builder = {
|
|
99
|
+
description(description) {
|
|
100
|
+
draft.description = description;
|
|
101
|
+
return builder;
|
|
102
|
+
},
|
|
103
|
+
interfaces: () => builder,
|
|
104
|
+
config(definition) {
|
|
105
|
+
draft.config = Object.freeze({
|
|
106
|
+
...definition,
|
|
107
|
+
schema: definition.schema ?? null
|
|
108
|
+
});
|
|
109
|
+
return builder;
|
|
110
|
+
},
|
|
111
|
+
slots(definitions, validateStructure) {
|
|
112
|
+
draft.slots = new Map(Object.entries(definitions));
|
|
113
|
+
draft.validateStructure = validateStructure ?? null;
|
|
114
|
+
return builder;
|
|
115
|
+
},
|
|
116
|
+
state(build) {
|
|
117
|
+
const members = /* @__PURE__ */ new Map();
|
|
118
|
+
draft.state = members;
|
|
119
|
+
build(createSection(members));
|
|
120
|
+
return builder;
|
|
121
|
+
},
|
|
122
|
+
properties(build) {
|
|
123
|
+
const members = /* @__PURE__ */ new Map();
|
|
124
|
+
draft.properties = members;
|
|
125
|
+
build(createSection(members));
|
|
126
|
+
return builder;
|
|
127
|
+
},
|
|
128
|
+
methods(build) {
|
|
129
|
+
const members = /* @__PURE__ */ new Map();
|
|
130
|
+
draft.methods = members;
|
|
131
|
+
build(createSection(members));
|
|
132
|
+
return builder;
|
|
133
|
+
},
|
|
134
|
+
events(build) {
|
|
135
|
+
const members = /* @__PURE__ */ new Map();
|
|
136
|
+
draft.events = members;
|
|
137
|
+
build(createSection(members));
|
|
138
|
+
return builder;
|
|
139
|
+
},
|
|
140
|
+
done() {
|
|
141
|
+
const definition = Object.freeze({
|
|
142
|
+
type,
|
|
143
|
+
description: draft.description,
|
|
144
|
+
config: draft.config,
|
|
145
|
+
slots: draft.slots,
|
|
146
|
+
validateStructure: draft.validateStructure,
|
|
147
|
+
state: draft.state,
|
|
148
|
+
properties: draft.properties,
|
|
149
|
+
methods: draft.methods,
|
|
150
|
+
events: draft.events
|
|
151
|
+
});
|
|
152
|
+
const capabilities = Object.freeze({
|
|
153
|
+
config: definition.config !== null,
|
|
154
|
+
slots: definition.slots !== null,
|
|
155
|
+
state: definition.state !== null,
|
|
156
|
+
properties: definition.properties !== null,
|
|
157
|
+
methods: definition.methods !== null,
|
|
158
|
+
events: definition.events !== null
|
|
159
|
+
});
|
|
160
|
+
const config = definition.config === null ? null : Object.freeze({
|
|
161
|
+
description: definition.config.description,
|
|
162
|
+
schema: definition.config.schema
|
|
163
|
+
});
|
|
164
|
+
const descriptions = Object.freeze({
|
|
165
|
+
config: config?.description ?? null,
|
|
166
|
+
slots: definition.slots === null ? null : createReadonlyMap([...definition.slots].map(([key, slot]) => [key, slot.description]))
|
|
167
|
+
});
|
|
168
|
+
return Object.freeze({
|
|
169
|
+
type,
|
|
170
|
+
description: draft.description,
|
|
171
|
+
capabilities,
|
|
172
|
+
config,
|
|
173
|
+
descriptions,
|
|
174
|
+
[widgetPluginBrand]: Object.freeze({ definition })
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
return builder;
|
|
179
|
+
}
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region src/runtime/internals.ts
|
|
182
|
+
const runtimeInternals = Symbol("@deviltea/widget-core:runtime-internals");
|
|
183
|
+
/**
|
|
184
|
+
* Provenance probe: true only for Runtimes produced by this loaded module instance.
|
|
185
|
+
*/
|
|
186
|
+
function isCoreRuntime(value) {
|
|
187
|
+
if (typeof value !== "object" || value === null) return false;
|
|
188
|
+
return value[runtimeInternals] !== void 0;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Reads the internals carried by a Runtime produced by `createWidgetSystemRuntime`.
|
|
192
|
+
*/
|
|
193
|
+
function readRuntimeInternals(runtime) {
|
|
194
|
+
const internals = runtime[runtimeInternals];
|
|
195
|
+
if (internals === void 0) throw new Error("The runtime was not produced by this widget core build.");
|
|
196
|
+
return internals;
|
|
197
|
+
}
|
|
198
|
+
//#endregion
|
|
199
|
+
export { createWidgetPlugin as a, readWidgetPluginDefinition as c, WIDGET_CONFIG_JSON_SCHEMA_DIALECT as i, createReadonlyMap as l, readRuntimeInternals as n, createWidgetValueContract as o, runtimeInternals as r, isCoreWidgetPlugin as s, isCoreRuntime as t };
|
package/package.json
CHANGED
|
@@ -4,17 +4,17 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.0.
|
|
7
|
+
"version": "0.0.3",
|
|
8
8
|
"author": "DevilTea <ch19980814@gmail.com>",
|
|
9
9
|
"license": "MIT",
|
|
10
|
-
"homepage": "https://github.com/DevilTea/
|
|
10
|
+
"homepage": "https://github.com/DevilTea/widget/tree/main/packages/core#readme",
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/DevilTea/
|
|
14
|
-
"directory": "packages/
|
|
13
|
+
"url": "git+https://github.com/DevilTea/widget.git",
|
|
14
|
+
"directory": "packages/core"
|
|
15
15
|
},
|
|
16
16
|
"bugs": {
|
|
17
|
-
"url": "https://github.com/DevilTea/
|
|
17
|
+
"url": "https://github.com/DevilTea/widget/issues"
|
|
18
18
|
},
|
|
19
19
|
"keywords": [
|
|
20
20
|
"widget",
|
|
@@ -32,6 +32,10 @@
|
|
|
32
32
|
"./inspection": {
|
|
33
33
|
"types": "./dist/inspection/index.d.mts",
|
|
34
34
|
"import": "./dist/inspection/index.mjs"
|
|
35
|
+
},
|
|
36
|
+
"./integration": {
|
|
37
|
+
"types": "./dist/integration/index.d.mts",
|
|
38
|
+
"import": "./dist/integration/index.mjs"
|
|
35
39
|
}
|
|
36
40
|
},
|
|
37
41
|
"main": "dist/index.mjs",
|
|
@@ -44,9 +48,11 @@
|
|
|
44
48
|
"node": "^22.14.0 || ^24.0.0"
|
|
45
49
|
},
|
|
46
50
|
"dependencies": {
|
|
47
|
-
"alien-signals": "3.2.1"
|
|
51
|
+
"alien-signals": "3.2.1",
|
|
52
|
+
"json-schema-typed": "^8.0.2"
|
|
48
53
|
},
|
|
49
54
|
"devDependencies": {
|
|
55
|
+
"@deviltea/tsconfig": "1.0.0",
|
|
50
56
|
"tsdown": "^0.22.3",
|
|
51
57
|
"vitest": "^4.1.9"
|
|
52
58
|
},
|