webloom-framework 0.3.0 → 0.4.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/README.md +70 -42
- package/dist/advanced.d.ts +168 -0
- package/dist/advanced.js +441 -0
- package/dist/advanced.js.map +1 -0
- package/dist/chunk-4DSINPZD.js +158 -0
- package/dist/chunk-4DSINPZD.js.map +1 -0
- package/dist/chunk-ANA6GBEI.js +1737 -0
- package/dist/chunk-ANA6GBEI.js.map +1 -0
- package/dist/chunk-HJKPKWI7.js +4024 -0
- package/dist/chunk-HJKPKWI7.js.map +1 -0
- package/dist/chunk-SX46RHDI.js +433 -0
- package/dist/chunk-SX46RHDI.js.map +1 -0
- package/dist/index.d.ts +39 -259
- package/dist/index.js +38 -1359
- package/dist/index.js.map +1 -1
- package/dist/messageBus-CtrwkjrO.d.ts +5 -0
- package/dist/messagePortServiceTransport-BYprNvQY.d.ts +264 -0
- package/dist/react.d.ts +41 -28
- package/dist/react.js +79 -88
- package/dist/react.js.map +1 -1
- package/dist/runtimeTypes-DquUCHz-.d.ts +1640 -0
- package/dist/sharedWorkerHost-KI7TIGdX.d.ts +192 -0
- package/dist/testing.d.ts +18 -17
- package/dist/testing.js +23 -15
- package/dist/testing.js.map +1 -1
- package/dist/windowRuntime-BKkLPsAS.d.ts +23 -0
- package/docs/api.md +148 -111
- package/docs/proposals/webloom-v4/implementation-plan.md +443 -0
- package/docs/proposals/webloom-v4/requirements.md +555 -0
- package/docs/proposals/webloom-v4/verification.md +115 -0
- package/package.json +11 -2
- package/dist/chunk-76BGPI6M.js +0 -4261
- package/dist/chunk-76BGPI6M.js.map +0 -1
- package/dist/createPluginHost-BVsUCDKN.d.ts +0 -1318
- package/dist/resourceRegistry-BFnjmeGE.d.ts +0 -267
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
import { i as PluginSetup, aL as RuntimeUnitImplementationRegistry, R as RuntimeKind, ae as PluginStateKind, r as RemoteServiceReference, s as RemoteServiceMessageCodec, ah as PluginUnitState, au as RemoteServiceProxy, m as PluginHost, L as LifecycleDisposeResult, M as MessageBus, K as LifecycleScopeKind, o as LifecycleScopeIdentity, n as LifecycleScope, a9 as PluginIntentSnapshot, a7 as PluginIntentController, ax as RemoteServiceTransport, am as RemoteServiceBridge, ao as RemoteServiceCallContext, aC as ResourceRegistry, aA as ResourceDefinition } from './createPluginHost-BVsUCDKN.js';
|
|
2
|
-
|
|
3
|
-
interface RuntimeUnitImplementation {
|
|
4
|
-
/** 产品标识。 */
|
|
5
|
-
pluginId: string;
|
|
6
|
-
/** 稳定运行单元标识。 */
|
|
7
|
-
unitId: string;
|
|
8
|
-
/** 当前环境的可执行入口。 */
|
|
9
|
-
setup: PluginSetup;
|
|
10
|
-
}
|
|
11
|
-
/** 创建一个拒绝重复注册、按产品和单元查找实现的运行时注册表。 */
|
|
12
|
-
declare function createRuntimeUnitImplementationRegistry(implementations?: readonly RuntimeUnitImplementation[]): RuntimeUnitImplementationRegistry & {
|
|
13
|
-
register(implementation: RuntimeUnitImplementation): void;
|
|
14
|
-
unregister(pluginId: string, unitId: string): void;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
declare const RUNTIME_PROTOCOL_VERSION = "webloom.runtime.v2";
|
|
18
|
-
declare const RUNTIME_SNAPSHOT_TYPE = "webloom.runtime.snapshot";
|
|
19
|
-
declare const RUNTIME_ERROR_TYPE = "webloom.runtime.error";
|
|
20
|
-
interface RuntimeErrorMessage {
|
|
21
|
-
type: typeof RUNTIME_ERROR_TYPE;
|
|
22
|
-
protocolVersion: string;
|
|
23
|
-
code: "runtime_initialization_failed" | "protocol_mismatch" | "transport_unavailable";
|
|
24
|
-
message: string;
|
|
25
|
-
pluginId?: string;
|
|
26
|
-
unitId?: string;
|
|
27
|
-
phase?: "startup" | "snapshot";
|
|
28
|
-
}
|
|
29
|
-
interface RuntimeSnapshot {
|
|
30
|
-
type: typeof RUNTIME_SNAPSHOT_TYPE;
|
|
31
|
-
protocolVersion: string;
|
|
32
|
-
runtimeId: string;
|
|
33
|
-
runtimeKind: RuntimeKind;
|
|
34
|
-
runtimeInstanceId: string;
|
|
35
|
-
revision: number;
|
|
36
|
-
state: "starting" | "ready" | "stopping" | "failed" | "disposed";
|
|
37
|
-
units: readonly RuntimeSnapshotUnit[];
|
|
38
|
-
services: readonly RemoteServiceReference[];
|
|
39
|
-
}
|
|
40
|
-
interface RuntimeSnapshotUnit {
|
|
41
|
-
pluginId: string;
|
|
42
|
-
unitId: string;
|
|
43
|
-
runtime: RuntimeKind;
|
|
44
|
-
instanceId?: string;
|
|
45
|
-
state: PluginStateKind;
|
|
46
|
-
}
|
|
47
|
-
declare function createRuntimeMessageCodec(): RemoteServiceMessageCodec;
|
|
48
|
-
/** 只验证外层结构;协议版本接受由 RuntimeHandle 单独处理。 */
|
|
49
|
-
declare function isRuntimeSnapshot(input: unknown): input is RuntimeSnapshot;
|
|
50
|
-
declare function isRuntimeSnapshotProtocol(input: RuntimeSnapshot): boolean;
|
|
51
|
-
declare function isRuntimeError(input: unknown): input is RuntimeErrorMessage;
|
|
52
|
-
/** 将 Host 的 PluginUnitState 映射成不会泄露领域配置的运行时快照。 */
|
|
53
|
-
declare function unitSnapshotFromState(state: PluginUnitState, runtime: RuntimeKind): RuntimeSnapshotUnit;
|
|
54
|
-
|
|
55
|
-
type RuntimeAppState = "starting" | "ready" | "stopping" | "failed" | "disposed" | "disconnected";
|
|
56
|
-
interface RuntimeStatusSnapshot {
|
|
57
|
-
runtimeId: string;
|
|
58
|
-
runtimeKind: RuntimeKind;
|
|
59
|
-
runtimeInstanceId: string;
|
|
60
|
-
state: RuntimeAppState;
|
|
61
|
-
revision: number;
|
|
62
|
-
units: readonly RuntimeSnapshotUnit[];
|
|
63
|
-
services: readonly RemoteServiceReference[];
|
|
64
|
-
error?: string;
|
|
65
|
-
}
|
|
66
|
-
type RuntimeStatusListener = (snapshot: RuntimeStatusSnapshot) => void;
|
|
67
|
-
interface WindowApp {
|
|
68
|
-
readonly runtimeKind: "window-main";
|
|
69
|
-
readonly runtimeId: string;
|
|
70
|
-
readonly runtimeInstanceId: string;
|
|
71
|
-
/** 已由 createWindowApp 装配并注册完成的本地 Host。 */
|
|
72
|
-
readonly host: PluginHost;
|
|
73
|
-
state(): RuntimeStatusSnapshot;
|
|
74
|
-
/** 获取当前本地 capability;停止或销毁后同步抛错。 */
|
|
75
|
-
capability<T>(capabilityId: string): T;
|
|
76
|
-
subscribe(listener: RuntimeStatusListener): () => void;
|
|
77
|
-
dispose(reason?: string): Promise<LifecycleDisposeResult>;
|
|
78
|
-
}
|
|
79
|
-
interface RuntimeHandle {
|
|
80
|
-
readonly runtimeKind: "shared-worker";
|
|
81
|
-
readonly runtimeId: string;
|
|
82
|
-
/** 当前已观察到的 Worker 启动身份;首份快照前为 undefined。 */
|
|
83
|
-
readonly runtimeInstanceId?: string;
|
|
84
|
-
state(): RuntimeStatusSnapshot;
|
|
85
|
-
capability<T = unknown>(capabilityId: string, options?: {
|
|
86
|
-
contractVersion?: string;
|
|
87
|
-
}): RemoteServiceProxy & {
|
|
88
|
-
readonly serviceType?: T;
|
|
89
|
-
};
|
|
90
|
-
subscribe(listener: RuntimeStatusListener): () => void;
|
|
91
|
-
dispose(reason?: string): Promise<void>;
|
|
92
|
-
}
|
|
93
|
-
/** 跨 realm 初始化失败;不把 required 插件错误包装成成功状态。 */
|
|
94
|
-
interface RuntimeInitializationErrorDetails {
|
|
95
|
-
pluginId?: string;
|
|
96
|
-
unitId?: string;
|
|
97
|
-
phase: "validate" | "register" | "startup" | "snapshot";
|
|
98
|
-
error: string;
|
|
99
|
-
}
|
|
100
|
-
declare class RuntimeInitializationError extends Error {
|
|
101
|
-
readonly code: "runtime_initialization_failed";
|
|
102
|
-
readonly details: RuntimeInitializationErrorDetails;
|
|
103
|
-
constructor(details: RuntimeInitializationErrorDetails);
|
|
104
|
-
}
|
|
105
|
-
declare class RuntimeUnavailableError extends Error {
|
|
106
|
-
readonly code: "transport_unavailable";
|
|
107
|
-
constructor(message?: string);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
interface SharedWorkerLike {
|
|
111
|
-
readonly port: MessagePort;
|
|
112
|
-
onerror?: (event: Event) => void;
|
|
113
|
-
addEventListener?(type: "error", listener: (event: Event) => void): void;
|
|
114
|
-
removeEventListener?(type: "error", listener: (event: Event) => void): void;
|
|
115
|
-
}
|
|
116
|
-
type SharedWorkerFactory = (url: string | URL, options: {
|
|
117
|
-
type: "module";
|
|
118
|
-
name?: string;
|
|
119
|
-
credentials?: RequestCredentials;
|
|
120
|
-
}) => SharedWorkerLike;
|
|
121
|
-
/**
|
|
122
|
-
* 临时迁移接缝:下游 typed transfer API 完成前允许领域代码在同一
|
|
123
|
-
* 物理端口安装 listener。它不参与 Runtime 授权,也不传 connectionId。
|
|
124
|
-
*/
|
|
125
|
-
interface SharedWorkerConnectionContext {
|
|
126
|
-
readonly worker: SharedWorkerLike;
|
|
127
|
-
readonly port: MessagePort;
|
|
128
|
-
}
|
|
129
|
-
interface ConnectSharedWorkerOptions {
|
|
130
|
-
id: string;
|
|
131
|
-
url: string | URL;
|
|
132
|
-
name?: string;
|
|
133
|
-
credentials?: RequestCredentials;
|
|
134
|
-
defaultCallTimeoutMs?: number;
|
|
135
|
-
/** SWCF-009 完成前的临时同端口迁移接缝。 */
|
|
136
|
-
onConnection?: (context: SharedWorkerConnectionContext) => void;
|
|
137
|
-
}
|
|
138
|
-
/** 创建生产 RuntimeHandle;测试工厂不属于生产公共选项。 */
|
|
139
|
-
declare function connectSharedWorker(options: ConnectSharedWorkerOptions): RuntimeHandle;
|
|
140
|
-
/** 仅由 `webloom-framework/testing` 暴露的 SharedWorker 工厂注入入口。 */
|
|
141
|
-
declare function connectSharedWorkerForTesting(options: ConnectSharedWorkerOptions, workerFactory: SharedWorkerFactory): RuntimeHandle;
|
|
142
|
-
|
|
143
|
-
declare function createMessageBus(): MessageBus;
|
|
144
|
-
|
|
145
|
-
interface CreateResourceScopeOptions {
|
|
146
|
-
/** 可选固定作用域标识;生产代码通常省略,让实现生成不可复用 ID。 */
|
|
147
|
-
scopeId?: string;
|
|
148
|
-
/** 运行实例标识;省略时与 scopeId 同源生成。 */
|
|
149
|
-
instanceId?: string;
|
|
150
|
-
/** 作用域类型。 */
|
|
151
|
-
kind: LifecycleScopeKind;
|
|
152
|
-
/** 绑定插件和宿主只读属性。 */
|
|
153
|
-
metadata?: Omit<Partial<LifecycleScopeIdentity>, "scopeId" | "instanceId" | "kind">;
|
|
154
|
-
/** 测试或宿主诊断使用的状态变更回调。 */
|
|
155
|
-
onChange?: (scope: LifecycleScope) => void;
|
|
156
|
-
/** 子作用域生成最终清理结果后的内部通知;用于更新父级登记。 */
|
|
157
|
-
onDisposeResult?: (result: LifecycleDisposeResult) => void;
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* 创建一个可嵌套的生命周期作用域。
|
|
161
|
-
*
|
|
162
|
-
* `createResourceScope` 是 `createLifecycleScope` 的同义入口,方便不同
|
|
163
|
-
* 模块按“作用域”或“资源”语义调用;两者不代表两套实现。
|
|
164
|
-
*/
|
|
165
|
-
declare function createLifecycleScope(options: CreateResourceScopeOptions): LifecycleScope;
|
|
166
|
-
/** 语义别名:资源管理代码通常以 ResourceScope 称呼同一原语。 */
|
|
167
|
-
declare const createResourceScope: typeof createLifecycleScope;
|
|
168
|
-
type ResourceScopeOptions = CreateResourceScopeOptions;
|
|
169
|
-
|
|
170
|
-
interface CreatePluginIntentControllerOptions {
|
|
171
|
-
/** 当前控制面启动身份;Worker 重启时应传入新值。 */
|
|
172
|
-
authorityInstanceId?: string;
|
|
173
|
-
/** Worker 恢复后读取的平台意图。 */
|
|
174
|
-
initial?: Partial<PluginIntentSnapshot>;
|
|
175
|
-
/** 将候选快照原子写入平台存储;缺省表示内存控制面(测试用)。 */
|
|
176
|
-
persist?: (snapshot: PluginIntentSnapshot) => Promise<void>;
|
|
177
|
-
/** 有界去重记录数量,避免 commandId 永久增长。 */
|
|
178
|
-
maxCommandRecords?: number;
|
|
179
|
-
}
|
|
180
|
-
/** 创建单一控制面上的插件意图控制器。 */
|
|
181
|
-
declare function createPluginIntentController(options?: CreatePluginIntentControllerOptions): PluginIntentController;
|
|
182
|
-
|
|
183
|
-
interface CreateServiceBridgeOptions {
|
|
184
|
-
/** 要接受的精确服务协议版本。 */
|
|
185
|
-
protocolVersion: string;
|
|
186
|
-
/** 实际端口 RPC 传输;桥不负责重放请求。 */
|
|
187
|
-
transport: RemoteServiceTransport;
|
|
188
|
-
/** 默认总 deadline;必须有限且大于零。 */
|
|
189
|
-
defaultCallTimeoutMs?: number;
|
|
190
|
-
}
|
|
191
|
-
/** 创建一个无连接握手、无增量 revision 状态机的服务桥。 */
|
|
192
|
-
declare function createServiceBridge(options: CreateServiceBridgeOptions): RemoteServiceBridge;
|
|
193
|
-
|
|
194
|
-
interface RemoteServicePortCallMessage {
|
|
195
|
-
type: string;
|
|
196
|
-
protocolVersion: string;
|
|
197
|
-
callId: string;
|
|
198
|
-
capabilityId: string;
|
|
199
|
-
contractVersion: string;
|
|
200
|
-
serviceInstanceId: string;
|
|
201
|
-
operationId?: string;
|
|
202
|
-
grantId?: string;
|
|
203
|
-
request: unknown;
|
|
204
|
-
}
|
|
205
|
-
interface RemoteServicePortResultMessage {
|
|
206
|
-
type: string;
|
|
207
|
-
protocolVersion: string;
|
|
208
|
-
callId: string;
|
|
209
|
-
serviceInstanceId: string;
|
|
210
|
-
result: unknown;
|
|
211
|
-
}
|
|
212
|
-
interface RemoteServicePortErrorMessage {
|
|
213
|
-
type: string;
|
|
214
|
-
protocolVersion: string;
|
|
215
|
-
callId: string;
|
|
216
|
-
serviceInstanceId: string;
|
|
217
|
-
error: {
|
|
218
|
-
name?: string;
|
|
219
|
-
message: string;
|
|
220
|
-
code: string;
|
|
221
|
-
details?: Readonly<Record<string, unknown>>;
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
interface RemoteServicePortCancelMessage {
|
|
225
|
-
type: string;
|
|
226
|
-
protocolVersion: string;
|
|
227
|
-
callId: string;
|
|
228
|
-
serviceInstanceId: string;
|
|
229
|
-
}
|
|
230
|
-
type RemoteServicePortResponseMessage = RemoteServicePortResultMessage | RemoteServicePortErrorMessage;
|
|
231
|
-
interface CreateMessagePortServiceTransportOptions {
|
|
232
|
-
/** 已由实际 Worker / Window 连接产生的双工端口。 */
|
|
233
|
-
port: MessagePort;
|
|
234
|
-
/** 可选 transferable 提取器;默认只发送结构化克隆数据。 */
|
|
235
|
-
transferForRequest?: (request: unknown, context: RemoteServiceCallContext) => readonly Transferable[];
|
|
236
|
-
/** dispose 时是否关闭端口;默认不关闭,由端口所有者决定。 */
|
|
237
|
-
closeOnDispose?: boolean;
|
|
238
|
-
/** wire 消息 codec;默认 webloom.remote-service.v2。 */
|
|
239
|
-
codec?: RemoteServiceMessageCodec;
|
|
240
|
-
/** 直接使用 transport 时的默认总 deadline。 */
|
|
241
|
-
defaultCallTimeoutMs?: number;
|
|
242
|
-
}
|
|
243
|
-
/** 创建一条不携带连接身份、不会自动重放的 MessagePort transport。 */
|
|
244
|
-
declare function createMessagePortServiceTransport(options: CreateMessagePortServiceTransportOptions): RemoteServiceTransport & {
|
|
245
|
-
dispose(): void;
|
|
246
|
-
};
|
|
247
|
-
/** Provider 侧调用消息的结构化输入。 */
|
|
248
|
-
interface MessagePortServiceCallInput {
|
|
249
|
-
message: RemoteServicePortCallMessage;
|
|
250
|
-
/** Provider 的权威目录命中的服务引用。 */
|
|
251
|
-
reference: RemoteServiceReference;
|
|
252
|
-
signal: AbortSignal;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* 资源注册表实现
|
|
257
|
-
*
|
|
258
|
-
* 设计缘由:管理资源定义的注册和查询,支持 owner-aware 生命周期。
|
|
259
|
-
* 重复 id 抛错,disable 时可回收。
|
|
260
|
-
*/
|
|
261
|
-
|
|
262
|
-
/** 资源注册表实现 */
|
|
263
|
-
declare function createResourceRegistry(): ResourceRegistry;
|
|
264
|
-
/** Internal runtime hook; deliberately absent from ResourceRegistry's public type. */
|
|
265
|
-
declare function registerOwnedResource(registry: ResourceRegistry, ownerId: string, definition: ResourceDefinition<any, any>): void;
|
|
266
|
-
|
|
267
|
-
export { createMessageBus as A, createMessagePortServiceTransport as B, type ConnectSharedWorkerOptions as C, createPluginIntentController as D, createResourceRegistry as E, createResourceScope as F, createRuntimeMessageCodec as G, createRuntimeUnitImplementationRegistry as H, createServiceBridge as I, isRuntimeError as J, isRuntimeSnapshot as K, isRuntimeSnapshotProtocol as L, type MessagePortServiceCallInput as M, registerOwnedResource as N, unitSnapshotFromState as O, type SharedWorkerFactory as P, connectSharedWorkerForTesting as Q, type RuntimeHandle as R, type SharedWorkerConnectionContext as S, type WindowApp as W, type RuntimeStatusSnapshot as a, type RuntimeStatusListener as b, type CreateMessagePortServiceTransportOptions as c, type CreatePluginIntentControllerOptions as d, type CreateResourceScopeOptions as e, type CreateServiceBridgeOptions as f, RUNTIME_ERROR_TYPE as g, RUNTIME_PROTOCOL_VERSION as h, RUNTIME_SNAPSHOT_TYPE as i, type RemoteServicePortCallMessage as j, type RemoteServicePortCancelMessage as k, type RemoteServicePortErrorMessage as l, type RemoteServicePortResponseMessage as m, type RemoteServicePortResultMessage as n, type ResourceScopeOptions as o, type RuntimeAppState as p, type RuntimeErrorMessage as q, RuntimeInitializationError as r, type RuntimeInitializationErrorDetails as s, type RuntimeSnapshot as t, type RuntimeSnapshotUnit as u, RuntimeUnavailableError as v, type RuntimeUnitImplementation as w, type SharedWorkerLike as x, connectSharedWorker as y, createLifecycleScope as z };
|