@djvlc/runtime-core 1.0.0
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/dist/index.cjs +3368 -0
- package/dist/index.d.cts +1228 -0
- package/dist/index.d.ts +1228 -0
- package/dist/index.js +3314 -0
- package/package.json +56 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,1228 @@
|
|
|
1
|
+
import { RuntimeError, RuntimeEvent, PerformanceMetric, PageResolveResult, ComponentLoadResult, PageSchema, HostAPI, ErrorCode, ManifestItem, PageManifest, EventBus as EventBus$1, RuntimeEventType, ComponentEvent, ExpressionNode, ExpressionContext, ExpressionValidationResult, RuntimeContext, DataQueryResponse, ActionExecuteResponse, NavigateOptions, DialogOptions, ToastOptions, TrackEvent, ClipboardResult, StorageOptions, BlockedComponent } from '@djvlc/contracts-types';
|
|
2
|
+
export { ActionExecuteResponse, ComponentInstance, ComponentLoadResult, ComponentLoadStatus, DataQueryResponse, ExpressionContext, HostAPI, ManifestItem, PageManifest, PageResolveResult, PageSchema, PerformanceMetric, RuntimeConfig, RuntimeError, RuntimeEvent, RuntimeEventType } from '@djvlc/contracts-types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Runtime 类型定义
|
|
6
|
+
* 基于 @djvlc/contracts-types 扩展的运行时特有类型
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 运行时初始化选项
|
|
11
|
+
*/
|
|
12
|
+
interface RuntimeOptions {
|
|
13
|
+
/** 容器元素或选择器 */
|
|
14
|
+
container: string | HTMLElement;
|
|
15
|
+
/** 页面 UID */
|
|
16
|
+
pageUid: string;
|
|
17
|
+
/** API 基础 URL */
|
|
18
|
+
apiBaseUrl: string;
|
|
19
|
+
/** CDN 基础 URL */
|
|
20
|
+
cdnBaseUrl: string;
|
|
21
|
+
/** 渠道 */
|
|
22
|
+
channel?: 'preview' | 'prod' | 'gray';
|
|
23
|
+
/** 用户 ID */
|
|
24
|
+
userId?: string;
|
|
25
|
+
/** 设备 ID */
|
|
26
|
+
deviceId?: string;
|
|
27
|
+
/** 认证 Token */
|
|
28
|
+
authToken?: string;
|
|
29
|
+
/** 预览 Token */
|
|
30
|
+
previewToken?: string;
|
|
31
|
+
/** 调试模式 */
|
|
32
|
+
debug?: boolean;
|
|
33
|
+
/** 是否启用 SRI 校验 */
|
|
34
|
+
enableSRI?: boolean;
|
|
35
|
+
/** 自定义请求头 */
|
|
36
|
+
headers?: Record<string, string>;
|
|
37
|
+
/** 错误回调 */
|
|
38
|
+
onError?: (error: RuntimeError) => void;
|
|
39
|
+
/** 事件回调 */
|
|
40
|
+
onEvent?: (event: RuntimeEvent) => void;
|
|
41
|
+
/** 性能指标回调 */
|
|
42
|
+
onMetric?: (metric: PerformanceMetric) => void;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 运行时阶段
|
|
46
|
+
*/
|
|
47
|
+
type RuntimePhase = 'idle' | 'resolving' | 'loading' | 'rendering' | 'ready' | 'error';
|
|
48
|
+
/**
|
|
49
|
+
* 运行时状态
|
|
50
|
+
*/
|
|
51
|
+
interface RuntimeState {
|
|
52
|
+
/** 当前阶段 */
|
|
53
|
+
phase: RuntimePhase;
|
|
54
|
+
/** 页面数据 */
|
|
55
|
+
page: PageResolveResult | null;
|
|
56
|
+
/** 页面状态(可变) */
|
|
57
|
+
variables: Record<string, unknown>;
|
|
58
|
+
/** 查询结果缓存 */
|
|
59
|
+
queries: Record<string, unknown>;
|
|
60
|
+
/** 组件加载状态 */
|
|
61
|
+
components: Map<string, ComponentLoadResult>;
|
|
62
|
+
/** 错误信息 */
|
|
63
|
+
error: RuntimeError | null;
|
|
64
|
+
/** 是否已销毁 */
|
|
65
|
+
destroyed: boolean;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* 已加载的组件模块
|
|
69
|
+
*/
|
|
70
|
+
interface LoadedComponent {
|
|
71
|
+
/** 组件名称 */
|
|
72
|
+
name: string;
|
|
73
|
+
/** 组件版本 */
|
|
74
|
+
version: string;
|
|
75
|
+
/** 组件类/构造函数 */
|
|
76
|
+
Component: CustomElementConstructor | unknown;
|
|
77
|
+
/** 加载耗时 */
|
|
78
|
+
loadTime: number;
|
|
79
|
+
/** 元数据 */
|
|
80
|
+
meta?: Record<string, unknown>;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 渲染器接口(框架无关)
|
|
84
|
+
*/
|
|
85
|
+
interface Renderer {
|
|
86
|
+
/** 初始化 */
|
|
87
|
+
init(): void;
|
|
88
|
+
/** 渲染页面 */
|
|
89
|
+
render(schema: PageSchema, container: HTMLElement): void;
|
|
90
|
+
/** 更新组件 */
|
|
91
|
+
updateComponent(componentId: string, props: Record<string, unknown>): void;
|
|
92
|
+
/** 销毁 */
|
|
93
|
+
destroy(): void;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* 事件处理器
|
|
97
|
+
*/
|
|
98
|
+
type EventHandler<T = unknown> = (event: RuntimeEvent<T>) => void;
|
|
99
|
+
/**
|
|
100
|
+
* 事件订阅取消函数
|
|
101
|
+
*/
|
|
102
|
+
type Unsubscribe = () => void;
|
|
103
|
+
/**
|
|
104
|
+
* 日志级别
|
|
105
|
+
*/
|
|
106
|
+
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
107
|
+
/**
|
|
108
|
+
* 日志器接口
|
|
109
|
+
*/
|
|
110
|
+
interface Logger {
|
|
111
|
+
debug(message: string, ...args: unknown[]): void;
|
|
112
|
+
info(message: string, ...args: unknown[]): void;
|
|
113
|
+
warn(message: string, ...args: unknown[]): void;
|
|
114
|
+
error(message: string, ...args: unknown[]): void;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 主运行时类
|
|
119
|
+
* 统一管理整个运行时生命周期
|
|
120
|
+
*/
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 创建运行时实例
|
|
124
|
+
*/
|
|
125
|
+
declare function createRuntime(options: RuntimeOptions): DjvlcRuntime;
|
|
126
|
+
/**
|
|
127
|
+
* DJVLC 运行时
|
|
128
|
+
*/
|
|
129
|
+
declare class DjvlcRuntime {
|
|
130
|
+
private options;
|
|
131
|
+
private container;
|
|
132
|
+
private pageLoader;
|
|
133
|
+
private componentLoader;
|
|
134
|
+
private assetLoader;
|
|
135
|
+
private stateManager;
|
|
136
|
+
private eventBus;
|
|
137
|
+
private expressionEngine;
|
|
138
|
+
private securityManager;
|
|
139
|
+
private telemetryManager;
|
|
140
|
+
private renderer;
|
|
141
|
+
private hostApi;
|
|
142
|
+
private logger;
|
|
143
|
+
constructor(options: RuntimeOptions);
|
|
144
|
+
/**
|
|
145
|
+
* 初始化运行时
|
|
146
|
+
*/
|
|
147
|
+
init(): Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* 加载页面
|
|
150
|
+
*/
|
|
151
|
+
load(): Promise<PageResolveResult>;
|
|
152
|
+
/**
|
|
153
|
+
* 渲染页面
|
|
154
|
+
*/
|
|
155
|
+
render(): Promise<void>;
|
|
156
|
+
/**
|
|
157
|
+
* 获取 Host API
|
|
158
|
+
*/
|
|
159
|
+
getHostApi(): HostAPI;
|
|
160
|
+
/**
|
|
161
|
+
* 获取当前状态
|
|
162
|
+
*/
|
|
163
|
+
getState(): RuntimeState;
|
|
164
|
+
/**
|
|
165
|
+
* 订阅状态变更
|
|
166
|
+
*/
|
|
167
|
+
onStateChange(listener: (state: RuntimeState) => void): () => void;
|
|
168
|
+
/**
|
|
169
|
+
* 订阅事件
|
|
170
|
+
*/
|
|
171
|
+
on<T>(type: RuntimeEvent<T>['type'], handler: (event: RuntimeEvent<T>) => void): () => void;
|
|
172
|
+
/**
|
|
173
|
+
* 更新组件
|
|
174
|
+
*/
|
|
175
|
+
updateComponent(componentId: string, props: Record<string, unknown>): void;
|
|
176
|
+
/**
|
|
177
|
+
* 设置变量
|
|
178
|
+
*/
|
|
179
|
+
setVariable(key: string, value: unknown): void;
|
|
180
|
+
/**
|
|
181
|
+
* 刷新数据
|
|
182
|
+
*/
|
|
183
|
+
refreshData(queryId: string): Promise<void>;
|
|
184
|
+
/**
|
|
185
|
+
* 销毁运行时
|
|
186
|
+
*/
|
|
187
|
+
destroy(): void;
|
|
188
|
+
private resolveContainer;
|
|
189
|
+
private initHostApi;
|
|
190
|
+
private initRenderer;
|
|
191
|
+
private handleError;
|
|
192
|
+
private emitEvent;
|
|
193
|
+
private createLogger;
|
|
194
|
+
private log;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* 运行时错误类型定义
|
|
199
|
+
*/
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* 运行时错误基类
|
|
203
|
+
*/
|
|
204
|
+
declare class DjvlcRuntimeError extends Error {
|
|
205
|
+
readonly code: ErrorCode;
|
|
206
|
+
readonly details?: Record<string, unknown>;
|
|
207
|
+
readonly traceId?: string;
|
|
208
|
+
readonly timestamp: number;
|
|
209
|
+
constructor(code: ErrorCode, message?: string, details?: Record<string, unknown>, traceId?: string);
|
|
210
|
+
toJSON(): {
|
|
211
|
+
name: string;
|
|
212
|
+
code: ErrorCode;
|
|
213
|
+
message: string;
|
|
214
|
+
details: Record<string, unknown> | undefined;
|
|
215
|
+
traceId: string | undefined;
|
|
216
|
+
timestamp: number;
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* 页面加载错误
|
|
221
|
+
*/
|
|
222
|
+
declare class PageLoadError extends DjvlcRuntimeError {
|
|
223
|
+
constructor(message: string, details?: Record<string, unknown>, traceId?: string);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* 组件加载错误
|
|
227
|
+
*/
|
|
228
|
+
declare class ComponentLoadError extends DjvlcRuntimeError {
|
|
229
|
+
readonly componentName: string;
|
|
230
|
+
readonly componentVersion: string;
|
|
231
|
+
constructor(componentName: string, componentVersion: string, message: string, code?: ErrorCode, details?: Record<string, unknown>);
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* 组件完整性校验错误
|
|
235
|
+
*/
|
|
236
|
+
declare class IntegrityError extends DjvlcRuntimeError {
|
|
237
|
+
readonly componentName: string;
|
|
238
|
+
readonly componentVersion: string;
|
|
239
|
+
readonly expectedHash: string;
|
|
240
|
+
readonly actualHash: string;
|
|
241
|
+
constructor(componentName: string, componentVersion: string, expectedHash: string, actualHash: string);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* 组件阻断错误
|
|
245
|
+
*/
|
|
246
|
+
declare class ComponentBlockedError extends DjvlcRuntimeError {
|
|
247
|
+
readonly componentName: string;
|
|
248
|
+
readonly componentVersion: string;
|
|
249
|
+
readonly reason: string;
|
|
250
|
+
constructor(componentName: string, componentVersion: string, reason: string);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* 表达式求值错误
|
|
254
|
+
*/
|
|
255
|
+
declare class ExpressionError extends DjvlcRuntimeError {
|
|
256
|
+
readonly expression: string;
|
|
257
|
+
readonly position?: {
|
|
258
|
+
start: number;
|
|
259
|
+
end: number;
|
|
260
|
+
};
|
|
261
|
+
constructor(expression: string, message: string, position?: {
|
|
262
|
+
start: number;
|
|
263
|
+
end: number;
|
|
264
|
+
}, details?: Record<string, unknown>);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* 动作执行错误
|
|
268
|
+
*/
|
|
269
|
+
declare class ActionError extends DjvlcRuntimeError {
|
|
270
|
+
readonly actionType: string;
|
|
271
|
+
readonly actionId?: string;
|
|
272
|
+
constructor(actionType: string, message: string, code?: ErrorCode, actionId?: string, details?: Record<string, unknown>);
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* 数据查询错误
|
|
276
|
+
*/
|
|
277
|
+
declare class QueryError extends DjvlcRuntimeError {
|
|
278
|
+
readonly queryId: string;
|
|
279
|
+
constructor(queryId: string, message: string, code?: ErrorCode, details?: Record<string, unknown>);
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* 渲染错误
|
|
283
|
+
*/
|
|
284
|
+
declare class RenderError extends DjvlcRuntimeError {
|
|
285
|
+
readonly componentId: string;
|
|
286
|
+
readonly componentType: string;
|
|
287
|
+
constructor(componentId: string, componentType: string, message: string, details?: Record<string, unknown>);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* 页面加载器
|
|
292
|
+
* 负责从 API 解析页面配置
|
|
293
|
+
*/
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* 页面加载器配置
|
|
297
|
+
*/
|
|
298
|
+
interface PageLoaderOptions {
|
|
299
|
+
/** API 基础 URL */
|
|
300
|
+
apiBaseUrl: string;
|
|
301
|
+
/** 渠道 */
|
|
302
|
+
channel?: 'preview' | 'prod' | 'gray';
|
|
303
|
+
/** 认证 Token */
|
|
304
|
+
authToken?: string;
|
|
305
|
+
/** 预览 Token */
|
|
306
|
+
previewToken?: string;
|
|
307
|
+
/** 请求头 */
|
|
308
|
+
headers?: Record<string, string>;
|
|
309
|
+
/** 缓存配置 */
|
|
310
|
+
cache?: {
|
|
311
|
+
enabled: boolean;
|
|
312
|
+
maxAge?: number;
|
|
313
|
+
};
|
|
314
|
+
/** 日志器 */
|
|
315
|
+
logger?: Logger;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* 页面加载器
|
|
319
|
+
* 负责调用 /page/resolve 接口获取页面数据
|
|
320
|
+
*/
|
|
321
|
+
declare class PageLoader {
|
|
322
|
+
private options;
|
|
323
|
+
private cache;
|
|
324
|
+
constructor(options: PageLoaderOptions);
|
|
325
|
+
/**
|
|
326
|
+
* 解析页面
|
|
327
|
+
* @param pageUid 页面 UID
|
|
328
|
+
* @param params 额外参数
|
|
329
|
+
*/
|
|
330
|
+
resolve(pageUid: string, params?: {
|
|
331
|
+
uid?: string;
|
|
332
|
+
deviceId?: string;
|
|
333
|
+
}): Promise<PageResolveResult>;
|
|
334
|
+
/**
|
|
335
|
+
* 预连接 API 服务器
|
|
336
|
+
*/
|
|
337
|
+
preconnect(): void;
|
|
338
|
+
/**
|
|
339
|
+
* 清除缓存
|
|
340
|
+
*/
|
|
341
|
+
clearCache(pageUid?: string): void;
|
|
342
|
+
private buildResolveUrl;
|
|
343
|
+
private buildHeaders;
|
|
344
|
+
private getCacheKey;
|
|
345
|
+
private isCacheValid;
|
|
346
|
+
private isValidPageResolveResult;
|
|
347
|
+
private log;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* 组件加载器
|
|
352
|
+
* 负责从 CDN 加载组件资源
|
|
353
|
+
*/
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* 组件加载器配置
|
|
357
|
+
*/
|
|
358
|
+
interface ComponentLoaderOptions {
|
|
359
|
+
/** CDN 基础 URL */
|
|
360
|
+
cdnBaseUrl: string;
|
|
361
|
+
/** 是否启用 SRI 校验 */
|
|
362
|
+
enableSRI?: boolean;
|
|
363
|
+
/** 被阻断的组件列表 */
|
|
364
|
+
blockedComponents?: string[];
|
|
365
|
+
/** 并行加载数量 */
|
|
366
|
+
concurrency?: number;
|
|
367
|
+
/** 超时时间(毫秒) */
|
|
368
|
+
timeout?: number;
|
|
369
|
+
/** 日志器 */
|
|
370
|
+
logger?: Logger;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* 组件加载器
|
|
374
|
+
* 负责加载 Web Components
|
|
375
|
+
*/
|
|
376
|
+
declare class ComponentLoader {
|
|
377
|
+
private options;
|
|
378
|
+
private loadedComponents;
|
|
379
|
+
private loadingPromises;
|
|
380
|
+
private blockedSet;
|
|
381
|
+
constructor(options: ComponentLoaderOptions);
|
|
382
|
+
/**
|
|
383
|
+
* 加载单个组件
|
|
384
|
+
*/
|
|
385
|
+
load(item: ManifestItem): Promise<LoadedComponent>;
|
|
386
|
+
/**
|
|
387
|
+
* 加载 Manifest 中的所有组件
|
|
388
|
+
*/
|
|
389
|
+
loadAll(manifest: PageManifest): Promise<Map<string, ComponentLoadResult>>;
|
|
390
|
+
/**
|
|
391
|
+
* 预加载组件
|
|
392
|
+
*/
|
|
393
|
+
preload(items: ManifestItem[]): void;
|
|
394
|
+
/**
|
|
395
|
+
* 检查组件是否已加载
|
|
396
|
+
*/
|
|
397
|
+
isLoaded(name: string, version: string): boolean;
|
|
398
|
+
/**
|
|
399
|
+
* 获取已加载的组件
|
|
400
|
+
*/
|
|
401
|
+
get(name: string, version: string): LoadedComponent | undefined;
|
|
402
|
+
/**
|
|
403
|
+
* 检查组件是否被阻断
|
|
404
|
+
*/
|
|
405
|
+
isBlocked(name: string, version: string): boolean;
|
|
406
|
+
/**
|
|
407
|
+
* 更新阻断列表
|
|
408
|
+
*/
|
|
409
|
+
updateBlockedList(blocked: string[]): void;
|
|
410
|
+
private loadComponent;
|
|
411
|
+
private fetchWithTimeout;
|
|
412
|
+
private validateIntegrity;
|
|
413
|
+
private executeScript;
|
|
414
|
+
private resolveUrl;
|
|
415
|
+
private getComponentKey;
|
|
416
|
+
private log;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* 资源加载器
|
|
421
|
+
* 负责预连接、预加载等资源优化
|
|
422
|
+
*/
|
|
423
|
+
/**
|
|
424
|
+
* 资源加载器配置
|
|
425
|
+
*/
|
|
426
|
+
interface AssetLoaderOptions {
|
|
427
|
+
/** CDN 域名列表 */
|
|
428
|
+
cdnHosts: string[];
|
|
429
|
+
/** API 域名列表 */
|
|
430
|
+
apiHosts: string[];
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* 资源加载器
|
|
434
|
+
* 负责资源预连接、预加载等优化
|
|
435
|
+
*/
|
|
436
|
+
declare class AssetLoader {
|
|
437
|
+
private options;
|
|
438
|
+
private preconnectedHosts;
|
|
439
|
+
private preloadedAssets;
|
|
440
|
+
constructor(options: AssetLoaderOptions);
|
|
441
|
+
/**
|
|
442
|
+
* 预连接所有域名
|
|
443
|
+
*/
|
|
444
|
+
preconnectAll(): void;
|
|
445
|
+
/**
|
|
446
|
+
* 预连接单个域名
|
|
447
|
+
*/
|
|
448
|
+
preconnect(host: string): void;
|
|
449
|
+
/**
|
|
450
|
+
* DNS 预解析
|
|
451
|
+
*/
|
|
452
|
+
dnsPrefetch(host: string): void;
|
|
453
|
+
/**
|
|
454
|
+
* 预加载脚本
|
|
455
|
+
*/
|
|
456
|
+
preloadScript(url: string, integrity?: string): void;
|
|
457
|
+
/**
|
|
458
|
+
* 预加载样式
|
|
459
|
+
*/
|
|
460
|
+
preloadStyle(url: string, integrity?: string): void;
|
|
461
|
+
/**
|
|
462
|
+
* 预加载图片
|
|
463
|
+
*/
|
|
464
|
+
preloadImage(url: string): void;
|
|
465
|
+
/**
|
|
466
|
+
* 预获取资源(低优先级)
|
|
467
|
+
*/
|
|
468
|
+
prefetch(url: string, as?: 'script' | 'style' | 'image' | 'document'): void;
|
|
469
|
+
/**
|
|
470
|
+
* 加载样式表
|
|
471
|
+
*/
|
|
472
|
+
loadStylesheet(url: string, integrity?: string): Promise<void>;
|
|
473
|
+
/**
|
|
474
|
+
* 加载脚本
|
|
475
|
+
*/
|
|
476
|
+
loadScript(url: string, integrity?: string): Promise<void>;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* 状态管理器
|
|
481
|
+
* 管理页面运行时状态
|
|
482
|
+
*/
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* 状态变更监听器
|
|
486
|
+
*/
|
|
487
|
+
type StateListener = (state: RuntimeState) => void;
|
|
488
|
+
/**
|
|
489
|
+
* 状态管理器
|
|
490
|
+
*/
|
|
491
|
+
declare class StateManager {
|
|
492
|
+
private state;
|
|
493
|
+
private listeners;
|
|
494
|
+
constructor();
|
|
495
|
+
/**
|
|
496
|
+
* 获取当前状态
|
|
497
|
+
*/
|
|
498
|
+
getState(): RuntimeState;
|
|
499
|
+
/**
|
|
500
|
+
* 获取当前阶段
|
|
501
|
+
*/
|
|
502
|
+
getPhase(): RuntimePhase;
|
|
503
|
+
/**
|
|
504
|
+
* 设置阶段
|
|
505
|
+
*/
|
|
506
|
+
setPhase(phase: RuntimePhase): void;
|
|
507
|
+
/**
|
|
508
|
+
* 设置页面数据
|
|
509
|
+
*/
|
|
510
|
+
setPage(page: PageResolveResult): void;
|
|
511
|
+
/**
|
|
512
|
+
* 设置错误
|
|
513
|
+
*/
|
|
514
|
+
setError(error: RuntimeError): void;
|
|
515
|
+
/**
|
|
516
|
+
* 获取变量值
|
|
517
|
+
*/
|
|
518
|
+
getVariable<T = unknown>(key: string): T | undefined;
|
|
519
|
+
/**
|
|
520
|
+
* 设置变量值
|
|
521
|
+
*/
|
|
522
|
+
setVariable(key: string, value: unknown): void;
|
|
523
|
+
/**
|
|
524
|
+
* 批量设置变量
|
|
525
|
+
*/
|
|
526
|
+
setVariables(variables: Record<string, unknown>): void;
|
|
527
|
+
/**
|
|
528
|
+
* 获取查询结果
|
|
529
|
+
*/
|
|
530
|
+
getQuery<T = unknown>(queryId: string): T | undefined;
|
|
531
|
+
/**
|
|
532
|
+
* 设置查询结果
|
|
533
|
+
*/
|
|
534
|
+
setQuery(queryId: string, data: unknown): void;
|
|
535
|
+
/**
|
|
536
|
+
* 更新组件加载状态
|
|
537
|
+
*/
|
|
538
|
+
setComponentStatus(key: string, result: ComponentLoadResult): void;
|
|
539
|
+
/**
|
|
540
|
+
* 标记为已销毁
|
|
541
|
+
*/
|
|
542
|
+
setDestroyed(): void;
|
|
543
|
+
/**
|
|
544
|
+
* 订阅状态变更
|
|
545
|
+
*/
|
|
546
|
+
subscribe(listener: StateListener): () => void;
|
|
547
|
+
/**
|
|
548
|
+
* 重置状态
|
|
549
|
+
*/
|
|
550
|
+
reset(): void;
|
|
551
|
+
private setState;
|
|
552
|
+
private notifyListeners;
|
|
553
|
+
private createInitialState;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* 事件总线
|
|
558
|
+
* 运行时事件系统
|
|
559
|
+
*/
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* 事件总线配置
|
|
563
|
+
*/
|
|
564
|
+
interface EventBusOptions {
|
|
565
|
+
/** 是否开启调试 */
|
|
566
|
+
debug?: boolean;
|
|
567
|
+
/** 日志器 */
|
|
568
|
+
logger?: Logger;
|
|
569
|
+
/** 最大监听器数量 */
|
|
570
|
+
maxListeners?: number;
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* 事件总线实现
|
|
574
|
+
*/
|
|
575
|
+
declare class EventBus implements EventBus$1 {
|
|
576
|
+
private handlers;
|
|
577
|
+
private options;
|
|
578
|
+
constructor(options?: EventBusOptions);
|
|
579
|
+
/**
|
|
580
|
+
* 发送事件
|
|
581
|
+
*/
|
|
582
|
+
emit<T>(event: RuntimeEvent<T>): void;
|
|
583
|
+
/**
|
|
584
|
+
* 订阅事件
|
|
585
|
+
*/
|
|
586
|
+
on<T>(type: RuntimeEventType, handler: EventHandler<T>): Unsubscribe;
|
|
587
|
+
/**
|
|
588
|
+
* 取消订阅
|
|
589
|
+
*/
|
|
590
|
+
off<T>(type: RuntimeEventType, handler: EventHandler<T>): void;
|
|
591
|
+
/**
|
|
592
|
+
* 一次性订阅
|
|
593
|
+
*/
|
|
594
|
+
once<T>(type: RuntimeEventType, handler: EventHandler<T>): Unsubscribe;
|
|
595
|
+
/**
|
|
596
|
+
* 清除所有监听器
|
|
597
|
+
*/
|
|
598
|
+
clear(type?: RuntimeEventType): void;
|
|
599
|
+
/**
|
|
600
|
+
* 获取监听器数量
|
|
601
|
+
*/
|
|
602
|
+
listenerCount(type: RuntimeEventType): number;
|
|
603
|
+
/**
|
|
604
|
+
* 创建事件
|
|
605
|
+
*/
|
|
606
|
+
static createEvent<T>(type: RuntimeEventType, data: T, traceId?: string): RuntimeEvent<T>;
|
|
607
|
+
private log;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
* 动作桥接器
|
|
612
|
+
* 处理组件事件到动作的映射
|
|
613
|
+
*/
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* 动作执行器
|
|
617
|
+
*/
|
|
618
|
+
interface ActionExecutor {
|
|
619
|
+
execute(actionType: string, params: Record<string, unknown>): Promise<unknown>;
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* 动作桥接器配置
|
|
623
|
+
*/
|
|
624
|
+
interface ActionBridgeOptions {
|
|
625
|
+
/** 动作执行器 */
|
|
626
|
+
executor: ActionExecutor;
|
|
627
|
+
/** 调试模式 */
|
|
628
|
+
debug?: boolean;
|
|
629
|
+
/** 日志器 */
|
|
630
|
+
logger?: Logger;
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* 动作桥接器
|
|
634
|
+
* 将组件事件转换为动作执行
|
|
635
|
+
*/
|
|
636
|
+
declare class ActionBridge {
|
|
637
|
+
private options;
|
|
638
|
+
private debounceTimers;
|
|
639
|
+
private throttleTimers;
|
|
640
|
+
constructor(options: ActionBridgeOptions);
|
|
641
|
+
/**
|
|
642
|
+
* 处理组件事件
|
|
643
|
+
*/
|
|
644
|
+
handleEvent(event: ComponentEvent, eventData: Record<string, unknown>, context: Record<string, unknown>): Promise<void>;
|
|
645
|
+
/**
|
|
646
|
+
* 销毁
|
|
647
|
+
*/
|
|
648
|
+
destroy(): void;
|
|
649
|
+
private executeAction;
|
|
650
|
+
private resolveParams;
|
|
651
|
+
private debounce;
|
|
652
|
+
private throttle;
|
|
653
|
+
private delay;
|
|
654
|
+
private log;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
/**
|
|
658
|
+
* 表达式词法分析器
|
|
659
|
+
* 将表达式字符串分解为 Token
|
|
660
|
+
*/
|
|
661
|
+
/**
|
|
662
|
+
* Token 类型
|
|
663
|
+
*/
|
|
664
|
+
type TokenType = 'NUMBER' | 'STRING' | 'BOOLEAN' | 'NULL' | 'IDENTIFIER' | 'OPERATOR' | 'DOT' | 'LBRACKET' | 'RBRACKET' | 'LPAREN' | 'RPAREN' | 'COMMA' | 'QUESTION' | 'COLON' | 'EOF';
|
|
665
|
+
/**
|
|
666
|
+
* Token
|
|
667
|
+
*/
|
|
668
|
+
interface Token {
|
|
669
|
+
type: TokenType;
|
|
670
|
+
value: string | number | boolean | null;
|
|
671
|
+
start: number;
|
|
672
|
+
end: number;
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* 词法分析器
|
|
676
|
+
*/
|
|
677
|
+
declare class Lexer {
|
|
678
|
+
private input;
|
|
679
|
+
private pos;
|
|
680
|
+
private tokens;
|
|
681
|
+
constructor(input: string);
|
|
682
|
+
/**
|
|
683
|
+
* 分析表达式,返回 Token 列表
|
|
684
|
+
*/
|
|
685
|
+
tokenize(): Token[];
|
|
686
|
+
private readToken;
|
|
687
|
+
private readNumber;
|
|
688
|
+
private readString;
|
|
689
|
+
private readIdentifier;
|
|
690
|
+
private readOperator;
|
|
691
|
+
private skipWhitespace;
|
|
692
|
+
private isDigit;
|
|
693
|
+
private isIdentifierStart;
|
|
694
|
+
private isIdentifierChar;
|
|
695
|
+
private peek;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* 表达式解析器
|
|
700
|
+
* 将 Token 列表解析为 AST
|
|
701
|
+
*/
|
|
702
|
+
|
|
703
|
+
/**
|
|
704
|
+
* AST 节点类型
|
|
705
|
+
*/
|
|
706
|
+
interface LiteralASTNode extends ExpressionNode {
|
|
707
|
+
type: 'literal';
|
|
708
|
+
value: string | number | boolean | null;
|
|
709
|
+
}
|
|
710
|
+
interface IdentifierASTNode extends ExpressionNode {
|
|
711
|
+
type: 'identifier';
|
|
712
|
+
name: string;
|
|
713
|
+
}
|
|
714
|
+
interface MemberASTNode extends ExpressionNode {
|
|
715
|
+
type: 'member';
|
|
716
|
+
object: ASTNode;
|
|
717
|
+
property: string | ASTNode;
|
|
718
|
+
computed: boolean;
|
|
719
|
+
}
|
|
720
|
+
interface CallASTNode extends ExpressionNode {
|
|
721
|
+
type: 'call';
|
|
722
|
+
callee: string;
|
|
723
|
+
arguments: ASTNode[];
|
|
724
|
+
}
|
|
725
|
+
interface BinaryASTNode extends ExpressionNode {
|
|
726
|
+
type: 'binary';
|
|
727
|
+
operator: string;
|
|
728
|
+
left: ASTNode;
|
|
729
|
+
right: ASTNode;
|
|
730
|
+
}
|
|
731
|
+
interface UnaryASTNode extends ExpressionNode {
|
|
732
|
+
type: 'unary';
|
|
733
|
+
operator: string;
|
|
734
|
+
argument: ASTNode;
|
|
735
|
+
}
|
|
736
|
+
interface ConditionalASTNode extends ExpressionNode {
|
|
737
|
+
type: 'conditional';
|
|
738
|
+
test: ASTNode;
|
|
739
|
+
consequent: ASTNode;
|
|
740
|
+
alternate: ASTNode;
|
|
741
|
+
}
|
|
742
|
+
interface ArrayASTNode extends ExpressionNode {
|
|
743
|
+
type: 'array';
|
|
744
|
+
elements: ASTNode[];
|
|
745
|
+
}
|
|
746
|
+
type ASTNode = LiteralASTNode | IdentifierASTNode | MemberASTNode | CallASTNode | BinaryASTNode | UnaryASTNode | ConditionalASTNode | ArrayASTNode;
|
|
747
|
+
/**
|
|
748
|
+
* 表达式解析器
|
|
749
|
+
*/
|
|
750
|
+
declare class Parser {
|
|
751
|
+
private tokens;
|
|
752
|
+
private pos;
|
|
753
|
+
constructor(tokens: Token[]);
|
|
754
|
+
/**
|
|
755
|
+
* 解析表达式
|
|
756
|
+
*/
|
|
757
|
+
parse(): ASTNode;
|
|
758
|
+
private parseExpression;
|
|
759
|
+
private parseTernary;
|
|
760
|
+
private parseBinary;
|
|
761
|
+
private parseUnary;
|
|
762
|
+
private parsePostfix;
|
|
763
|
+
private parsePrimary;
|
|
764
|
+
private parseArray;
|
|
765
|
+
private parseArguments;
|
|
766
|
+
private current;
|
|
767
|
+
private advance;
|
|
768
|
+
private expect;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
/**
|
|
772
|
+
* 表达式求值器
|
|
773
|
+
* 安全地执行 AST,无 eval
|
|
774
|
+
*/
|
|
775
|
+
|
|
776
|
+
/**
|
|
777
|
+
* 求值结果
|
|
778
|
+
*/
|
|
779
|
+
interface EvaluationResult {
|
|
780
|
+
value: unknown;
|
|
781
|
+
error?: Error;
|
|
782
|
+
}
|
|
783
|
+
/**
|
|
784
|
+
* 求值器配置
|
|
785
|
+
*/
|
|
786
|
+
interface EvaluatorOptions {
|
|
787
|
+
/** 最大递归深度 */
|
|
788
|
+
maxDepth?: number;
|
|
789
|
+
/** 最大执行时间(毫秒) */
|
|
790
|
+
timeout?: number;
|
|
791
|
+
/** 调试模式 */
|
|
792
|
+
debug?: boolean;
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* 表达式求值器
|
|
796
|
+
*/
|
|
797
|
+
declare class Evaluator {
|
|
798
|
+
private options;
|
|
799
|
+
private depth;
|
|
800
|
+
private startTime;
|
|
801
|
+
constructor(options?: EvaluatorOptions);
|
|
802
|
+
/**
|
|
803
|
+
* 求值表达式
|
|
804
|
+
*/
|
|
805
|
+
evaluate(ast: ASTNode, context: ExpressionContext): EvaluationResult;
|
|
806
|
+
private evaluateNode;
|
|
807
|
+
private evaluateLiteral;
|
|
808
|
+
private evaluateIdentifier;
|
|
809
|
+
private evaluateMember;
|
|
810
|
+
private evaluateCall;
|
|
811
|
+
private evaluateBinary;
|
|
812
|
+
private evaluateUnary;
|
|
813
|
+
private evaluateConditional;
|
|
814
|
+
private evaluateArray;
|
|
815
|
+
private checkLimits;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
/**
|
|
819
|
+
* 表达式引擎
|
|
820
|
+
* 统一的表达式解析和求值入口
|
|
821
|
+
*/
|
|
822
|
+
|
|
823
|
+
/**
|
|
824
|
+
* 表达式引擎配置
|
|
825
|
+
*/
|
|
826
|
+
interface ExpressionEngineOptions extends EvaluatorOptions {
|
|
827
|
+
/** 是否缓存 AST */
|
|
828
|
+
cacheAST?: boolean;
|
|
829
|
+
/** 最大缓存大小 */
|
|
830
|
+
maxCacheSize?: number;
|
|
831
|
+
/** 日志器 */
|
|
832
|
+
logger?: Logger;
|
|
833
|
+
}
|
|
834
|
+
/**
|
|
835
|
+
* 表达式引擎
|
|
836
|
+
* 安全的表达式解析和求值,无 eval/new Function
|
|
837
|
+
*/
|
|
838
|
+
declare class ExpressionEngine {
|
|
839
|
+
private options;
|
|
840
|
+
private evaluator;
|
|
841
|
+
private astCache;
|
|
842
|
+
constructor(options?: ExpressionEngineOptions);
|
|
843
|
+
/**
|
|
844
|
+
* 求值表达式
|
|
845
|
+
*/
|
|
846
|
+
evaluate(expression: string, context: ExpressionContext): EvaluationResult;
|
|
847
|
+
/**
|
|
848
|
+
* 求值表达式并返回值
|
|
849
|
+
* 出错时返回 fallback 值
|
|
850
|
+
*/
|
|
851
|
+
evaluateWithFallback<T>(expression: string, context: ExpressionContext, fallback: T): T;
|
|
852
|
+
/**
|
|
853
|
+
* 求值模板字符串
|
|
854
|
+
* 支持 ${expression} 语法
|
|
855
|
+
*/
|
|
856
|
+
evaluateTemplate(template: string, context: ExpressionContext): string;
|
|
857
|
+
/**
|
|
858
|
+
* 解析表达式为 AST
|
|
859
|
+
*/
|
|
860
|
+
parse(expression: string): ASTNode;
|
|
861
|
+
/**
|
|
862
|
+
* 校验表达式
|
|
863
|
+
*/
|
|
864
|
+
validate(expression: string): ExpressionValidationResult;
|
|
865
|
+
/**
|
|
866
|
+
* 清除 AST 缓存
|
|
867
|
+
*/
|
|
868
|
+
clearCache(): void;
|
|
869
|
+
private collectReferences;
|
|
870
|
+
private buildMemberPath;
|
|
871
|
+
private log;
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
/**
|
|
875
|
+
* 内置函数实现
|
|
876
|
+
* 表达式中可调用的白名单函数
|
|
877
|
+
*/
|
|
878
|
+
type BuiltinFn = (...args: unknown[]) => unknown;
|
|
879
|
+
/**
|
|
880
|
+
* 内置函数映射
|
|
881
|
+
*/
|
|
882
|
+
declare const builtinFunctions: Record<string, BuiltinFn>;
|
|
883
|
+
|
|
884
|
+
/**
|
|
885
|
+
* Host API 实现
|
|
886
|
+
* 提供给组件的安全 API
|
|
887
|
+
*/
|
|
888
|
+
|
|
889
|
+
/**
|
|
890
|
+
* Host API 配置
|
|
891
|
+
*/
|
|
892
|
+
interface HostAPIOptions {
|
|
893
|
+
/** API 基础 URL */
|
|
894
|
+
apiBaseUrl: string;
|
|
895
|
+
/** 认证 Token */
|
|
896
|
+
authToken?: string;
|
|
897
|
+
/** 请求头 */
|
|
898
|
+
headers?: Record<string, string>;
|
|
899
|
+
/** 状态管理器 */
|
|
900
|
+
stateManager: StateManager;
|
|
901
|
+
/** 事件总线 */
|
|
902
|
+
eventBus: EventBus;
|
|
903
|
+
/** 表达式引擎 */
|
|
904
|
+
expressionEngine: ExpressionEngine;
|
|
905
|
+
/** 运行时上下文 */
|
|
906
|
+
context: RuntimeContext;
|
|
907
|
+
/** 调试模式 */
|
|
908
|
+
debug?: boolean;
|
|
909
|
+
/** 日志器 */
|
|
910
|
+
logger?: Logger;
|
|
911
|
+
}
|
|
912
|
+
/**
|
|
913
|
+
* Host API 实现
|
|
914
|
+
*/
|
|
915
|
+
declare class HostAPIImpl implements HostAPI {
|
|
916
|
+
private options;
|
|
917
|
+
private storageNamespace;
|
|
918
|
+
constructor(options: HostAPIOptions);
|
|
919
|
+
requestData<T = unknown>(queryId: string, params?: Record<string, unknown>): Promise<DataQueryResponse<T>>;
|
|
920
|
+
executeAction<T = unknown>(actionType: string, params?: Record<string, unknown>): Promise<ActionExecuteResponse<T>>;
|
|
921
|
+
navigate(options: NavigateOptions): void;
|
|
922
|
+
goBack(): void;
|
|
923
|
+
refresh(): void;
|
|
924
|
+
openDialog(options: DialogOptions): Promise<boolean | string>;
|
|
925
|
+
closeDialog(): void;
|
|
926
|
+
showToast(options: ToastOptions): void;
|
|
927
|
+
track(event: TrackEvent): void;
|
|
928
|
+
copyToClipboard(text: string): Promise<ClipboardResult>;
|
|
929
|
+
readFromClipboard(): Promise<ClipboardResult>;
|
|
930
|
+
getState<T = unknown>(key: string): T | undefined;
|
|
931
|
+
setState(key: string, value: unknown): void;
|
|
932
|
+
getVariable<T = unknown>(name: string): T | undefined;
|
|
933
|
+
postMessage(componentId: string, message: unknown): void;
|
|
934
|
+
broadcast(channel: string, message: unknown): void;
|
|
935
|
+
storage: {
|
|
936
|
+
get: <T = unknown>(key: string, options?: StorageOptions) => T | undefined;
|
|
937
|
+
set: (key: string, value: unknown, options?: StorageOptions) => void;
|
|
938
|
+
remove: (key: string, options?: StorageOptions) => void;
|
|
939
|
+
};
|
|
940
|
+
getContext(): RuntimeContext;
|
|
941
|
+
private buildHeaders;
|
|
942
|
+
private getStorageKey;
|
|
943
|
+
private generateIdempotencyKey;
|
|
944
|
+
private simpleHash;
|
|
945
|
+
private log;
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
/**
|
|
949
|
+
* 安全管理器
|
|
950
|
+
* SRI 校验、域名白名单、组件阻止等
|
|
951
|
+
*/
|
|
952
|
+
|
|
953
|
+
/**
|
|
954
|
+
* 安全管理器配置
|
|
955
|
+
*/
|
|
956
|
+
interface SecurityManagerOptions {
|
|
957
|
+
/** 是否启用 SRI 校验 */
|
|
958
|
+
enableSRI?: boolean;
|
|
959
|
+
/** CDN 域名白名单 */
|
|
960
|
+
cdnDomains?: string[];
|
|
961
|
+
/** API 域名白名单 */
|
|
962
|
+
apiDomains?: string[];
|
|
963
|
+
/** 被阻断的组件列表 */
|
|
964
|
+
blockedComponents?: BlockedComponent[];
|
|
965
|
+
/** 被阻断的动作类型 */
|
|
966
|
+
blockedActions?: string[];
|
|
967
|
+
/** 日志器 */
|
|
968
|
+
logger?: Logger;
|
|
969
|
+
}
|
|
970
|
+
/**
|
|
971
|
+
* 安全管理器
|
|
972
|
+
*/
|
|
973
|
+
declare class SecurityManager {
|
|
974
|
+
private options;
|
|
975
|
+
private blockedComponentsMap;
|
|
976
|
+
private blockedActionsSet;
|
|
977
|
+
constructor(options?: SecurityManagerOptions);
|
|
978
|
+
/**
|
|
979
|
+
* 更新阻断列表
|
|
980
|
+
*/
|
|
981
|
+
updateBlockedList(components: BlockedComponent[], actions: string[]): void;
|
|
982
|
+
/**
|
|
983
|
+
* 检查组件是否被阻断
|
|
984
|
+
*/
|
|
985
|
+
isComponentBlocked(name: string, version: string): boolean;
|
|
986
|
+
/**
|
|
987
|
+
* 获取组件阻断信息
|
|
988
|
+
*/
|
|
989
|
+
getBlockedInfo(name: string, version: string): BlockedComponent | undefined;
|
|
990
|
+
/**
|
|
991
|
+
* 检查动作是否被阻断
|
|
992
|
+
*/
|
|
993
|
+
isActionBlocked(actionType: string): boolean;
|
|
994
|
+
/**
|
|
995
|
+
* 验证组件完整性
|
|
996
|
+
*/
|
|
997
|
+
validateComponent(name: string, version: string, content: string, expectedIntegrity: string): Promise<void>;
|
|
998
|
+
/**
|
|
999
|
+
* 验证 URL 是否在白名单内
|
|
1000
|
+
*/
|
|
1001
|
+
isAllowedUrl(url: string, type: 'cdn' | 'api'): boolean;
|
|
1002
|
+
/**
|
|
1003
|
+
* 生成 CSP 策略
|
|
1004
|
+
*/
|
|
1005
|
+
generateCSPPolicy(): string;
|
|
1006
|
+
/**
|
|
1007
|
+
* 应用 CSP 策略
|
|
1008
|
+
*/
|
|
1009
|
+
applyCSP(): void;
|
|
1010
|
+
/**
|
|
1011
|
+
* 确保组件未被阻断
|
|
1012
|
+
*/
|
|
1013
|
+
assertNotBlocked(name: string, version: string): void;
|
|
1014
|
+
/**
|
|
1015
|
+
* 计算哈希值
|
|
1016
|
+
*/
|
|
1017
|
+
private computeHash;
|
|
1018
|
+
private _log;
|
|
1019
|
+
protected get log(): (level: "debug" | "info" | "warn" | "error", message: string) => void;
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
/**
|
|
1023
|
+
* 基础渲染器
|
|
1024
|
+
* 框架无关的渲染核心
|
|
1025
|
+
*/
|
|
1026
|
+
|
|
1027
|
+
/**
|
|
1028
|
+
* 渲染器配置
|
|
1029
|
+
*/
|
|
1030
|
+
interface BaseRendererOptions {
|
|
1031
|
+
/** 表达式引擎 */
|
|
1032
|
+
expressionEngine: ExpressionEngine;
|
|
1033
|
+
/** 组件映射 */
|
|
1034
|
+
components: Map<string, LoadedComponent>;
|
|
1035
|
+
/** Host API 注入函数 */
|
|
1036
|
+
injectHostApi: (element: HTMLElement, componentId: string) => void;
|
|
1037
|
+
/** 调试模式 */
|
|
1038
|
+
debug?: boolean;
|
|
1039
|
+
/** 日志器 */
|
|
1040
|
+
logger?: Logger;
|
|
1041
|
+
/** 错误边界处理 */
|
|
1042
|
+
onRenderError?: (componentId: string, error: Error) => HTMLElement | null;
|
|
1043
|
+
}
|
|
1044
|
+
/**
|
|
1045
|
+
* 基础渲染器
|
|
1046
|
+
* 将 PageSchema 渲染为 DOM
|
|
1047
|
+
*/
|
|
1048
|
+
declare class BaseRenderer implements Renderer {
|
|
1049
|
+
private options;
|
|
1050
|
+
private container;
|
|
1051
|
+
private renderedElements;
|
|
1052
|
+
private expressionContext;
|
|
1053
|
+
constructor(options: BaseRendererOptions);
|
|
1054
|
+
/**
|
|
1055
|
+
* 初始化渲染器
|
|
1056
|
+
*/
|
|
1057
|
+
init(): void;
|
|
1058
|
+
/**
|
|
1059
|
+
* 渲染页面
|
|
1060
|
+
*/
|
|
1061
|
+
render(schema: PageSchema, container: HTMLElement): void;
|
|
1062
|
+
/**
|
|
1063
|
+
* 更新组件属性
|
|
1064
|
+
*/
|
|
1065
|
+
updateComponent(componentId: string, props: Record<string, unknown>): void;
|
|
1066
|
+
/**
|
|
1067
|
+
* 更新表达式上下文
|
|
1068
|
+
*/
|
|
1069
|
+
updateContext(context: Partial<ExpressionContext>): void;
|
|
1070
|
+
/**
|
|
1071
|
+
* 销毁渲染器
|
|
1072
|
+
*/
|
|
1073
|
+
destroy(): void;
|
|
1074
|
+
/**
|
|
1075
|
+
* 渲染单个组件
|
|
1076
|
+
*/
|
|
1077
|
+
private renderComponent;
|
|
1078
|
+
/**
|
|
1079
|
+
* 解析 props 中的表达式
|
|
1080
|
+
*/
|
|
1081
|
+
private resolveProps;
|
|
1082
|
+
/**
|
|
1083
|
+
* 应用 props 到元素
|
|
1084
|
+
*/
|
|
1085
|
+
private applyProps;
|
|
1086
|
+
/**
|
|
1087
|
+
* 应用样式到元素
|
|
1088
|
+
*/
|
|
1089
|
+
private applyStyles;
|
|
1090
|
+
/**
|
|
1091
|
+
* 应用页面样式
|
|
1092
|
+
*/
|
|
1093
|
+
private applyPageStyles;
|
|
1094
|
+
private log;
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
/**
|
|
1098
|
+
* Fallback 组件
|
|
1099
|
+
* 组件加载失败或渲染错误时的降级显示
|
|
1100
|
+
*/
|
|
1101
|
+
/**
|
|
1102
|
+
* 注册 fallback 组件
|
|
1103
|
+
*/
|
|
1104
|
+
declare function registerFallbackComponents(): void;
|
|
1105
|
+
/**
|
|
1106
|
+
* 创建 fallback 元素
|
|
1107
|
+
*/
|
|
1108
|
+
declare function createFallbackElement(type: 'fallback' | 'blocked' | 'error', message?: string, componentName?: string): HTMLElement;
|
|
1109
|
+
|
|
1110
|
+
/**
|
|
1111
|
+
* 遥测管理器
|
|
1112
|
+
* 链路追踪、性能监控、错误上报
|
|
1113
|
+
*/
|
|
1114
|
+
|
|
1115
|
+
/**
|
|
1116
|
+
* Span 信息
|
|
1117
|
+
*/
|
|
1118
|
+
interface Span {
|
|
1119
|
+
spanId: string;
|
|
1120
|
+
traceId: string;
|
|
1121
|
+
parentSpanId?: string;
|
|
1122
|
+
name: string;
|
|
1123
|
+
startTime: number;
|
|
1124
|
+
endTime?: number;
|
|
1125
|
+
status?: 'ok' | 'error';
|
|
1126
|
+
attributes?: Record<string, unknown>;
|
|
1127
|
+
}
|
|
1128
|
+
/**
|
|
1129
|
+
* 遥测管理器配置
|
|
1130
|
+
*/
|
|
1131
|
+
interface TelemetryManagerOptions {
|
|
1132
|
+
/** 是否启用 */
|
|
1133
|
+
enabled?: boolean;
|
|
1134
|
+
/** 页面版本 ID */
|
|
1135
|
+
pageVersionId: string;
|
|
1136
|
+
/** 应用 ID */
|
|
1137
|
+
appId?: string;
|
|
1138
|
+
/** 采样率 (0-1) */
|
|
1139
|
+
sampleRate?: number;
|
|
1140
|
+
/** 上报 URL */
|
|
1141
|
+
endpoint?: string;
|
|
1142
|
+
/** 日志器 */
|
|
1143
|
+
logger?: Logger;
|
|
1144
|
+
/** 调试模式 */
|
|
1145
|
+
debug?: boolean;
|
|
1146
|
+
}
|
|
1147
|
+
/**
|
|
1148
|
+
* 遥测管理器
|
|
1149
|
+
*/
|
|
1150
|
+
declare class TelemetryManager {
|
|
1151
|
+
private options;
|
|
1152
|
+
private traceId;
|
|
1153
|
+
private spans;
|
|
1154
|
+
private metrics;
|
|
1155
|
+
private errors;
|
|
1156
|
+
private shouldSample;
|
|
1157
|
+
constructor(options: TelemetryManagerOptions);
|
|
1158
|
+
/**
|
|
1159
|
+
* 获取 Trace ID
|
|
1160
|
+
*/
|
|
1161
|
+
getTraceId(): string;
|
|
1162
|
+
/**
|
|
1163
|
+
* 获取 W3C Trace Context 格式的 traceparent
|
|
1164
|
+
*/
|
|
1165
|
+
getTraceparent(): string;
|
|
1166
|
+
/**
|
|
1167
|
+
* 开始一个 Span
|
|
1168
|
+
*/
|
|
1169
|
+
startSpan(name: string, parentSpanId?: string, attributes?: Record<string, unknown>): Span;
|
|
1170
|
+
/**
|
|
1171
|
+
* 结束一个 Span
|
|
1172
|
+
*/
|
|
1173
|
+
endSpan(spanId: string, status?: 'ok' | 'error'): void;
|
|
1174
|
+
/**
|
|
1175
|
+
* 记录性能指标
|
|
1176
|
+
*/
|
|
1177
|
+
recordMetric(type: PerformanceMetric['type'], name: string, duration: number, extra?: Record<string, unknown>): void;
|
|
1178
|
+
/**
|
|
1179
|
+
* 记录错误
|
|
1180
|
+
*/
|
|
1181
|
+
recordError(error: Error | RuntimeError, context?: Record<string, unknown>): void;
|
|
1182
|
+
/**
|
|
1183
|
+
* 记录页面加载时间
|
|
1184
|
+
*/
|
|
1185
|
+
recordPageLoad(duration: number, extra?: Record<string, unknown>): void;
|
|
1186
|
+
/**
|
|
1187
|
+
* 记录组件加载时间
|
|
1188
|
+
*/
|
|
1189
|
+
recordComponentLoad(name: string, version: string, duration: number, success: boolean): void;
|
|
1190
|
+
/**
|
|
1191
|
+
* 记录首次渲染时间
|
|
1192
|
+
*/
|
|
1193
|
+
recordFirstRender(duration: number): void;
|
|
1194
|
+
/**
|
|
1195
|
+
* 记录动作执行时间
|
|
1196
|
+
*/
|
|
1197
|
+
recordActionExecute(actionType: string, duration: number, success: boolean): void;
|
|
1198
|
+
/**
|
|
1199
|
+
* 记录查询执行时间
|
|
1200
|
+
*/
|
|
1201
|
+
recordQueryExecute(queryId: string, duration: number, success: boolean, fromCache: boolean): void;
|
|
1202
|
+
/**
|
|
1203
|
+
* 获取所有指标
|
|
1204
|
+
*/
|
|
1205
|
+
getMetrics(): PerformanceMetric[];
|
|
1206
|
+
/**
|
|
1207
|
+
* 获取所有 Span
|
|
1208
|
+
*/
|
|
1209
|
+
getSpans(): Span[];
|
|
1210
|
+
/**
|
|
1211
|
+
* 清理数据
|
|
1212
|
+
*/
|
|
1213
|
+
clear(): void;
|
|
1214
|
+
/**
|
|
1215
|
+
* 刷新上报
|
|
1216
|
+
*/
|
|
1217
|
+
flush(): Promise<void>;
|
|
1218
|
+
private reportError;
|
|
1219
|
+
private generateId;
|
|
1220
|
+
private log;
|
|
1221
|
+
}
|
|
1222
|
+
declare module './telemetry-manager' {
|
|
1223
|
+
interface TelemetryManagerOptions {
|
|
1224
|
+
onMetric?: (metric: PerformanceMetric) => void;
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
export { type ASTNode, ActionBridge, type ActionBridgeOptions, ActionError, type ActionExecutor, AssetLoader, type AssetLoaderOptions, BaseRenderer, type BaseRendererOptions, ComponentBlockedError, ComponentLoadError, ComponentLoader, type ComponentLoaderOptions, DjvlcRuntime, DjvlcRuntimeError, type EvaluationResult, Evaluator, type EvaluatorOptions, EventBus, type EventBusOptions, type EventHandler, ExpressionEngine, type ExpressionEngineOptions, ExpressionError, HostAPIImpl, type HostAPIOptions, IntegrityError, Lexer, type LoadedComponent, type LogLevel, type Logger, PageLoadError, PageLoader, type PageLoaderOptions, Parser, QueryError, RenderError, type Renderer, type RuntimeOptions, type RuntimePhase, type RuntimeState, SecurityManager, type SecurityManagerOptions, type Span, type StateListener, StateManager, TelemetryManager, type TelemetryManagerOptions, type Token, type TokenType, type Unsubscribe, builtinFunctions, createFallbackElement, createRuntime, registerFallbackComponents };
|