webloom-framework 0.4.0 → 0.4.2

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.
@@ -1,264 +0,0 @@
1
- import { T as PluginSetup, K as Capability, bj as RuntimeUnitImplementationRegistry, aH as PluginIntentSnapshot, aF as PluginIntentController, a$ as ResourceRegistry, aZ as ResourceDefinition, bd as RuntimeSnapshot, R as RuntimeKind, aN as PluginStateKind, Y as CapabilityBridge } from './runtimeTypes-DquUCHz-.js';
2
- import { R as ReceivePortLedger, a as RuntimeLimitsInput, b as RuntimeBudget } from './sharedWorkerHost-Cb2a1_KD.js';
3
-
4
- interface RuntimeUnitImplementation {
5
- /** 产品标识。 */
6
- pluginId: string;
7
- /** 稳定运行单元标识。 */
8
- unitId: string;
9
- /** 当前环境的可执行入口。 */
10
- setup: PluginSetup;
11
- /** 当前 realm 的 typed capability 定义。 */
12
- capabilities?: readonly Capability[];
13
- }
14
- /** 创建一个拒绝重复注册、按产品和单元查找实现的运行时注册表。 */
15
- declare function createRuntimeUnitImplementationRegistry(implementations?: readonly RuntimeUnitImplementation[]): RuntimeUnitImplementationRegistry & {
16
- register(implementation: RuntimeUnitImplementation): void;
17
- unregister(pluginId: string, unitId: string): void;
18
- };
19
-
20
- interface CreatePluginIntentControllerOptions {
21
- /** 当前控制面启动身份;Worker 重启时应传入新值。 */
22
- authorityInstanceId?: string;
23
- /** Worker 恢复后读取的平台意图。 */
24
- initial?: Partial<PluginIntentSnapshot>;
25
- /** 将候选快照原子写入平台存储;缺省表示内存控制面(测试用)。 */
26
- persist?: (snapshot: PluginIntentSnapshot) => Promise<void>;
27
- /** 有界去重记录数量,避免 commandId 永久增长。 */
28
- maxCommandRecords?: number;
29
- }
30
- /** 创建单一控制面上的插件意图控制器。 */
31
- declare function createPluginIntentController(options?: CreatePluginIntentControllerOptions): PluginIntentController;
32
-
33
- /**
34
- * 资源注册表实现
35
- *
36
- * 设计缘由:管理资源定义的注册和查询,支持 owner-aware 生命周期。
37
- * 重复 id 抛错,disable 时可回收。
38
- */
39
-
40
- /** 资源注册表实现 */
41
- declare function createResourceRegistry(): ResourceRegistry;
42
- /** Internal runtime hook; deliberately absent from ResourceRegistry's public type. */
43
- declare function registerOwnedResource(registry: ResourceRegistry, ownerId: string, definition: ResourceDefinition<any, any>): void;
44
-
45
- declare const RUNTIME_PROTOCOL_VERSION: "webloom.runtime.v1";
46
- declare const RUNTIME_SNAPSHOT_TYPE: "webloom.runtime.v1.snapshot";
47
- declare const RUNTIME_ERROR_TYPE: "webloom.runtime.v1.runtime-error";
48
- declare const RUNTIME_CALL_TYPE: "webloom.runtime.v1.call";
49
- declare const RUNTIME_RESULT_TYPE: "webloom.runtime.v1.result";
50
- declare const RUNTIME_ERROR_MESSAGE_TYPE: "webloom.runtime.v1.error";
51
- declare const RUNTIME_CANCEL_TYPE: "webloom.runtime.v1.cancel";
52
- declare const RUNTIME_NEXT_TYPE: "webloom.runtime.v1.next";
53
- declare const RUNTIME_CREDIT_TYPE: "webloom.runtime.v1.credit";
54
- interface RuntimeSnapshotUnit {
55
- /** 插件标识。 */
56
- readonly pluginId: string;
57
- /** 单元标识。 */
58
- readonly unitId: string;
59
- /** Runtime。 */
60
- readonly runtime: RuntimeKind;
61
- /** 实例标识。 */
62
- readonly instanceId?: string;
63
- /** 状态。 */
64
- readonly state: PluginStateKind;
65
- }
66
- type RuntimeSnapshotMessage = RuntimeSnapshot & {
67
- readonly type: typeof RUNTIME_SNAPSHOT_TYPE;
68
- };
69
- interface RuntimeErrorMessage {
70
- /** 消息类型。 */
71
- readonly type: typeof RUNTIME_ERROR_TYPE;
72
- /** 协议版本。 */
73
- readonly protocolVersion: typeof RUNTIME_PROTOCOL_VERSION;
74
- /** 结构化错误码。 */
75
- readonly code: string;
76
- /** 脱敏消息。 */
77
- readonly message: string;
78
- /** 失败阶段。 */
79
- readonly phase: "validate" | "wait" | "dispatch" | "execute" | "receive" | "dispose";
80
- /** 可选插件标识。 */
81
- readonly pluginId?: string;
82
- /** 可选单元标识。 */
83
- readonly unitId?: string;
84
- }
85
- interface RuntimeCallMessage {
86
- /** 消息类型。 */
87
- readonly type: typeof RUNTIME_CALL_TYPE;
88
- /** 协议版本。 */
89
- readonly protocolVersion: typeof RUNTIME_PROTOCOL_VERSION;
90
- /** 方向内唯一 call id。 */
91
- readonly callId: string;
92
- /** capability 标识。 */
93
- readonly capabilityId: string;
94
- /** 契约版本。 */
95
- readonly contractVersion: string;
96
- /** exposure 身份。 */
97
- readonly serviceInstanceId: string;
98
- /** 调用模式。 */
99
- readonly mode: "unary" | "stream";
100
- /** 本次派发的剩余预算。 */
101
- readonly timeoutMs: number;
102
- /** 已 parser 验证的请求。 */
103
- readonly request: unknown;
104
- /** 产品操作标识。 */
105
- readonly operationId?: string;
106
- /** 领域授权标识。 */
107
- readonly grantId?: string;
108
- /** stream 初始 credit。 */
109
- readonly initialCredit?: number;
110
- }
111
- interface RuntimeUnaryResultMessage {
112
- /** 消息类型。 */
113
- readonly type: typeof RUNTIME_RESULT_TYPE;
114
- /** 协议版本。 */
115
- readonly protocolVersion: typeof RUNTIME_PROTOCOL_VERSION;
116
- /** call id。 */
117
- readonly callId: string;
118
- /** exposure 身份。 */
119
- readonly serviceInstanceId: string;
120
- /** unary 结果。 */
121
- readonly result: unknown;
122
- }
123
- interface RuntimeStreamReadyMessage {
124
- /** 消息类型。 */
125
- readonly type: typeof RUNTIME_RESULT_TYPE;
126
- /** 协议版本。 */
127
- readonly protocolVersion: typeof RUNTIME_PROTOCOL_VERSION;
128
- /** call id。 */
129
- readonly callId: string;
130
- /** exposure 身份。 */
131
- readonly serviceInstanceId: string;
132
- /** stream 建立确认。 */
133
- readonly streamReady: true;
134
- }
135
- interface RuntimeStreamDoneMessage {
136
- /** 消息类型。 */
137
- readonly type: typeof RUNTIME_RESULT_TYPE;
138
- /** 协议版本。 */
139
- readonly protocolVersion: typeof RUNTIME_PROTOCOL_VERSION;
140
- /** call id。 */
141
- readonly callId: string;
142
- /** exposure 身份。 */
143
- readonly serviceInstanceId: string;
144
- /** stream 正常结束。 */
145
- readonly done: true;
146
- }
147
- type RuntimeResultMessage = RuntimeUnaryResultMessage | RuntimeStreamReadyMessage | RuntimeStreamDoneMessage;
148
- interface RuntimeErrorResponseMessage {
149
- /** 消息类型。 */
150
- readonly type: typeof RUNTIME_ERROR_MESSAGE_TYPE;
151
- /** 协议版本。 */
152
- readonly protocolVersion: typeof RUNTIME_PROTOCOL_VERSION;
153
- /** call id。 */
154
- readonly callId: string;
155
- /** exposure 身份。 */
156
- readonly serviceInstanceId: string;
157
- /** 结构化错误。 */
158
- readonly error: {
159
- readonly code: string;
160
- readonly message: string;
161
- readonly phase: RuntimeErrorMessage["phase"];
162
- readonly details?: Readonly<Record<string, unknown>>;
163
- };
164
- }
165
- interface RuntimeCancelMessage {
166
- /** 消息类型。 */
167
- readonly type: typeof RUNTIME_CANCEL_TYPE;
168
- /** 协议版本。 */
169
- readonly protocolVersion: typeof RUNTIME_PROTOCOL_VERSION;
170
- /** call id。 */
171
- readonly callId: string;
172
- /** exposure 身份。 */
173
- readonly serviceInstanceId: string;
174
- }
175
- interface RuntimeNextMessage {
176
- /** 消息类型。 */
177
- readonly type: typeof RUNTIME_NEXT_TYPE;
178
- /** 协议版本。 */
179
- readonly protocolVersion: typeof RUNTIME_PROTOCOL_VERSION;
180
- /** call id。 */
181
- readonly callId: string;
182
- /** exposure 身份。 */
183
- readonly serviceInstanceId: string;
184
- /** 连续序号。 */
185
- readonly sequence: number;
186
- /** parser 验证的 item。 */
187
- readonly item: unknown;
188
- }
189
- interface RuntimeCreditMessage {
190
- /** 消息类型。 */
191
- readonly type: typeof RUNTIME_CREDIT_TYPE;
192
- /** 协议版本。 */
193
- readonly protocolVersion: typeof RUNTIME_PROTOCOL_VERSION;
194
- /** call id。 */
195
- readonly callId: string;
196
- /** exposure 身份。 */
197
- readonly serviceInstanceId: string;
198
- /** 新增 credit。 */
199
- readonly count: number;
200
- }
201
- type RuntimeWireMessage = RuntimeSnapshotMessage | RuntimeErrorMessage | RuntimeCallMessage | RuntimeResultMessage | RuntimeErrorResponseMessage | RuntimeCancelMessage | RuntimeNextMessage | RuntimeCreditMessage;
202
- interface RuntimeMessageCodec {
203
- /** 严格验证并冻结 v4 message。 */
204
- encode(message: RuntimeWireMessage): RuntimeWireMessage;
205
- /** 严格解析 v4 message;旧协议直接拒绝。 */
206
- decode(value: unknown): RuntimeWireMessage;
207
- }
208
- declare function createRuntimeMessageCodec(): RuntimeMessageCodec;
209
- declare function isRuntimeSnapshot(value: RuntimeWireMessage): value is RuntimeSnapshotMessage;
210
-
211
- interface RuntimeReceiveMetadata {
212
- /** 本次 MessageEvent 实际携带的业务 MessagePort;仅 transport 本地使用。 */
213
- readonly ports?: readonly MessagePort[];
214
- /** 由物理 endpoint transport 创建的一次性接收资源账本。 */
215
- readonly ledger?: ReceivePortLedger;
216
- /** 物理 endpoint 已完成一次 codec decode。 */
217
- readonly decoded?: boolean;
218
- }
219
- interface RuntimeTransport {
220
- /** 发送已验证 v4 message;transfer 由契约 extractor 提供。 */
221
- send(message: RuntimeWireMessage, transfer?: readonly Transferable[]): void;
222
- /** 订阅接收 message 及本次事件的本地 transfer 元数据。 */
223
- subscribe(listener: (message: RuntimeWireMessage, metadata?: RuntimeReceiveMetadata) => void): () => void;
224
- /** 关闭本端传输。 */
225
- close?(): void;
226
- /** 物理 endpoint 对 decode/接收账本错误的统一通知。 */
227
- subscribeError?(listener: (error: unknown, metadata?: RuntimeReceiveMetadata) => void): () => void;
228
- }
229
- interface CreateCapabilityBridgeOptions {
230
- /** 底层双向 transport。 */
231
- readonly transport: RuntimeTransport;
232
- /** 预期的对端 Runtime 类型。 */
233
- readonly remoteRuntimeKind?: RuntimeKind;
234
- /** 预期的对端逻辑 Runtime id。 */
235
- readonly remoteRuntimeId?: string;
236
- /** 默认调用预算。 */
237
- readonly defaultCallTimeoutMs?: number;
238
- /** 可信 Runtime/advanced 装配提供的预算;只能收紧 v4 默认值。 */
239
- readonly limits?: RuntimeLimitsInput;
240
- /** 可选的 Runtime 方向共享计数器。 */
241
- readonly budget?: RuntimeBudget;
242
- }
243
- /** 创建按 peer 绑定、可撤销且支持 typed stream 的 bridge。 */
244
- declare function createCapabilityBridge(options: CreateCapabilityBridgeOptions): CapabilityBridge & {
245
- readonly pendingCallCount: number;
246
- readonly activeStreamCount: number;
247
- readonly retainedPayloadBytes: number;
248
- };
249
- /** 内部 typed transfer 校验 helper;不接受 call 级临时 transfer 数组。 */
250
- declare function validateTransferables(value: unknown, transfer: readonly Transferable[] | undefined, limits?: RuntimeLimitsInput): readonly Transferable[];
251
-
252
- interface MessagePortLike {
253
- addEventListener(type: "message" | "messageerror", listener: (event: MessageEvent) => void): void;
254
- removeEventListener(type: "message" | "messageerror", listener: (event: MessageEvent) => void): void;
255
- postMessage(message: unknown, transfer?: readonly Transferable[]): void;
256
- start?(): void;
257
- close?(): void;
258
- }
259
- /** 将一个真实 MessagePort 绑定为双向 v4 transport。 */
260
- declare function createMessagePortRuntimeTransport(port: MessagePortLike, options?: {
261
- readonly limits?: RuntimeLimitsInput;
262
- }): RuntimeTransport;
263
-
264
- export { createCapabilityBridge as A, createMessagePortRuntimeTransport as B, type CreateCapabilityBridgeOptions as C, createPluginIntentController as D, createResourceRegistry as E, createRuntimeMessageCodec as F, createRuntimeUnitImplementationRegistry as G, isRuntimeSnapshot as H, registerOwnedResource as I, validateTransferables as J, type MessagePortLike as M, type RuntimeCallMessage as R, type RuntimeTransport as a, type CreatePluginIntentControllerOptions as b, RUNTIME_CALL_TYPE as c, RUNTIME_CANCEL_TYPE as d, RUNTIME_CREDIT_TYPE as e, RUNTIME_ERROR_MESSAGE_TYPE as f, RUNTIME_ERROR_TYPE as g, RUNTIME_NEXT_TYPE as h, RUNTIME_PROTOCOL_VERSION as i, RUNTIME_RESULT_TYPE as j, RUNTIME_SNAPSHOT_TYPE as k, type RuntimeCancelMessage as l, type RuntimeCreditMessage as m, type RuntimeErrorMessage as n, type RuntimeErrorResponseMessage as o, type RuntimeMessageCodec as p, type RuntimeNextMessage as q, type RuntimeReceiveMetadata as r, type RuntimeResultMessage as s, type RuntimeSnapshotMessage as t, type RuntimeSnapshotUnit as u, type RuntimeStreamDoneMessage as v, type RuntimeStreamReadyMessage as w, type RuntimeUnaryResultMessage as x, type RuntimeUnitImplementation as y, type RuntimeWireMessage as z };