@pactor-app/runtime 0.1.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/LICENSE +21 -0
- package/README.md +54 -0
- package/dist/index.cjs +938 -0
- package/dist/index.d.cts +447 -0
- package/dist/index.d.ts +447 -0
- package/dist/index.js +909 -0
- package/package.json +69 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
import { PermissionConfig, Registry, ActionConfig, DataSourceConfig, PageMeta, I18nContext, DslNode, PageDsl, LifecycleEventName } from '@pactor-app/core';
|
|
2
|
+
import { ExpressionScope } from '@pactor-app/expression';
|
|
3
|
+
import * as react from 'react';
|
|
4
|
+
import { ComponentType, ReactNode } from 'react';
|
|
5
|
+
import { DslValidationError } from '@pactor-app/schema';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 适配接口(设计文档第 15、17 节,决策 D2):
|
|
9
|
+
*
|
|
10
|
+
* 动作能力边界 —— `navigate` / 权限判定 / HTTP 传输依赖上层模块
|
|
11
|
+
* (@pactor-app/router / @pactor-app/permission / 宿主应用),本包只定义接口与
|
|
12
|
+
* 默认实现,真实现经 `createRuntimeContext` 注入。
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* 权限适配接口:检查权限配置(string / string[] 任一命中即放行 /
|
|
16
|
+
* `{ code, denied }` 对象形式)。三种形态均只判定"有没有权限"——
|
|
17
|
+
* 对象形式只检查 `code`,denied 策略由 Renderer / Guard 解释。
|
|
18
|
+
*/
|
|
19
|
+
interface PermissionAdapter {
|
|
20
|
+
check(permission: PermissionConfig): boolean;
|
|
21
|
+
}
|
|
22
|
+
/** 路由适配接口 */
|
|
23
|
+
interface RouterAdapter {
|
|
24
|
+
navigate(to: string): void;
|
|
25
|
+
}
|
|
26
|
+
/** HTTP 请求描述(与 DataSourceConfig.request 结构对齐) */
|
|
27
|
+
interface HttpRequestConfig {
|
|
28
|
+
method?: string;
|
|
29
|
+
url: string;
|
|
30
|
+
params?: Record<string, unknown>;
|
|
31
|
+
headers?: Record<string, string>;
|
|
32
|
+
body?: unknown;
|
|
33
|
+
}
|
|
34
|
+
/** HTTP 适配接口:统一出口,便于测试替换与统一认证 */
|
|
35
|
+
interface HttpAdapter {
|
|
36
|
+
request(config: HttpRequestConfig): Promise<unknown>;
|
|
37
|
+
}
|
|
38
|
+
/** 默认权限适配器:全部放行(真实权限由 @pactor-app/permission 提供) */
|
|
39
|
+
declare function createDefaultPermissionAdapter(): PermissionAdapter;
|
|
40
|
+
/** 默认路由适配器:no-op 并告警(真实导航由 @pactor-app/router 提供) */
|
|
41
|
+
declare function createDefaultRouterAdapter(): RouterAdapter;
|
|
42
|
+
/**
|
|
43
|
+
* 默认 HTTP 适配器:基于全局 fetch。
|
|
44
|
+
* GET/HEAD 请求把 params 拼到 query string;body 统一 JSON 编码;
|
|
45
|
+
* 非 2xx 响应抛错;响应优先按 JSON 解析,失败则返回原文本。
|
|
46
|
+
*/
|
|
47
|
+
declare function createFetchHttpAdapter(): HttpAdapter;
|
|
48
|
+
|
|
49
|
+
/** 动作执行结果:全程受控,不向 UI 层抛未捕获异常 */
|
|
50
|
+
interface ActionResult {
|
|
51
|
+
ok: boolean;
|
|
52
|
+
data?: unknown;
|
|
53
|
+
error?: Error;
|
|
54
|
+
/** condition 求值为 false 时跳过执行 */
|
|
55
|
+
skipped?: boolean;
|
|
56
|
+
}
|
|
57
|
+
/** handler 可见的执行上下文 */
|
|
58
|
+
interface ActionContext {
|
|
59
|
+
/** 完整 RuntimeContext(state / data / services / http 等) */
|
|
60
|
+
context: RuntimeContext;
|
|
61
|
+
/** 本次执行的求值作用域(含事件等局部作用域) */
|
|
62
|
+
scope: ExpressionScope;
|
|
63
|
+
/** 以当前局部作用域执行子动作(编排动作用) */
|
|
64
|
+
execute(action: ActionConfig): Promise<ActionResult>;
|
|
65
|
+
}
|
|
66
|
+
type ActionHandler = (action: ActionConfig, ctx: ActionContext) => ActionResult | Promise<ActionResult>;
|
|
67
|
+
/** Action Registry:动作名 → handler(设计文档第 17 节) */
|
|
68
|
+
type ActionRegistry = Registry<ActionHandler>;
|
|
69
|
+
/**
|
|
70
|
+
* Action 引擎(设计文档第 17 节,决策 D4)。
|
|
71
|
+
*
|
|
72
|
+
* 执行管线:求值 `condition`(false 则跳过,返回 `{ ok: true, skipped: true }`)
|
|
73
|
+
* → 检查 `permission`(拒绝返回 `{ ok: false }`)→ 查 ActionRegistry 执行。
|
|
74
|
+
* 未注册动作返回受控失败;任何异常收敛为 `{ ok: false, error }`。
|
|
75
|
+
*
|
|
76
|
+
* 命名动作结果(设计文档第 48 节,决策 D2):动作声明 `id` 时,
|
|
77
|
+
* 执行完成(含 skipped / 失败)后把结果写入 context 级 `actionResults`
|
|
78
|
+
* ——成功时为 `result.data`,失败时为 `{ ok: false, error }`;
|
|
79
|
+
* 经 buildScope 的 `actions` 键供后续动作引用(`${actions.<id>}`)。
|
|
80
|
+
* 未命名动作行为不变。
|
|
81
|
+
*/
|
|
82
|
+
declare class ActionEngine {
|
|
83
|
+
private readonly context;
|
|
84
|
+
constructor(context: RuntimeContext);
|
|
85
|
+
execute(action: ActionConfig, localScope?: ExpressionScope): Promise<ActionResult>;
|
|
86
|
+
/** 命名动作结果落盘:成功 → data;失败 → `{ ok: false, error }` */
|
|
87
|
+
private recordNamedResult;
|
|
88
|
+
/** 事件动作数组按声明顺序串行执行 */
|
|
89
|
+
executeAll(actions: ActionConfig | ActionConfig[], localScope?: ExpressionScope): Promise<ActionResult[]>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** 单个数据源的运行时状态 */
|
|
93
|
+
interface DataSourceStatus {
|
|
94
|
+
loading: boolean;
|
|
95
|
+
error?: Error;
|
|
96
|
+
data?: unknown;
|
|
97
|
+
}
|
|
98
|
+
interface DataStoreDeps {
|
|
99
|
+
dataSources: Record<string, DataSourceConfig>;
|
|
100
|
+
services: ServiceRegistry;
|
|
101
|
+
http: HttpAdapter;
|
|
102
|
+
/** 加载前取当前表达式作用域(params / request 求值用) */
|
|
103
|
+
getScope: () => ExpressionScope;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* DataStore:DataSource 运行时(设计文档第 19 节,决策 D3)。
|
|
107
|
+
*
|
|
108
|
+
* 按数据源名维护 `{ loading, error, data }`;按类型分派加载
|
|
109
|
+
* (static / service / http;computed / resource 留待后续迭代)。
|
|
110
|
+
* 错误一律写入 `error` 状态,绝不抛到渲染层。
|
|
111
|
+
*/
|
|
112
|
+
declare class DataStore {
|
|
113
|
+
private readonly configs;
|
|
114
|
+
private readonly services;
|
|
115
|
+
private readonly http;
|
|
116
|
+
private readonly getScope;
|
|
117
|
+
private readonly statuses;
|
|
118
|
+
private readonly listeners;
|
|
119
|
+
private version;
|
|
120
|
+
constructor(deps: DataStoreDeps);
|
|
121
|
+
/** 状态快照(未知名返回空状态,不抛错) */
|
|
122
|
+
get(name: string): DataSourceStatus;
|
|
123
|
+
/** 同 `get(name)`,语义化别名 */
|
|
124
|
+
getStatus(name: string): DataSourceStatus;
|
|
125
|
+
getData(name: string): unknown;
|
|
126
|
+
/** 各数据源当前数据,供表达式作用域的 `data` 键使用 */
|
|
127
|
+
getAllData(): Record<string, unknown>;
|
|
128
|
+
subscribe(listener: () => void): () => void;
|
|
129
|
+
/** 版本号,供 `useSyncExternalStore` 的 getSnapshot 使用 */
|
|
130
|
+
getVersion(): number;
|
|
131
|
+
/** 触发所有 `autoLoad: true` 的数据源(PageRuntime 初始化阶段调用) */
|
|
132
|
+
init(): Promise<void[]>;
|
|
133
|
+
/**
|
|
134
|
+
* 加载指定数据源。状态流转:开始置 loading 并清空 error;
|
|
135
|
+
* 成功写入 data;失败写入 error(保留旧 data)。MUST NOT 抛出。
|
|
136
|
+
*/
|
|
137
|
+
load(name: string): Promise<void>;
|
|
138
|
+
/** 重新加载指定数据源(语义同 `load`,供模板与 Action 调用) */
|
|
139
|
+
refresh(name: string): Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* reload 语义:指定名称时刷新该数据源;
|
|
142
|
+
* 缺省时刷新全部 autoLoad 数据源(供 Action 引擎 `reload` 动作调用)。
|
|
143
|
+
*/
|
|
144
|
+
reload(name?: string): Promise<void | void[]>;
|
|
145
|
+
private autoLoadNames;
|
|
146
|
+
private loadByType;
|
|
147
|
+
private update;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* StateStore:框架无关的最小状态容器(设计文档第 15 节,决策 D1)。
|
|
152
|
+
*
|
|
153
|
+
* 手写约百行、零依赖,不引入 Zustand;React 侧经 `useSyncExternalStore`
|
|
154
|
+
* 订阅(见 renderer/)。所有写入均为不可变更新,`reset()` 因此可以安全地
|
|
155
|
+
* 恢复到创建时的初始值。
|
|
156
|
+
*/
|
|
157
|
+
declare class StateStore {
|
|
158
|
+
private state;
|
|
159
|
+
private readonly initialState;
|
|
160
|
+
private readonly listeners;
|
|
161
|
+
private version;
|
|
162
|
+
constructor(initialState?: Record<string, unknown>);
|
|
163
|
+
/** 当前完整 state 对象 */
|
|
164
|
+
getState(): Record<string, unknown>;
|
|
165
|
+
/** 按点路径读取,如 `get('user.name')`;路径不存在时返回 undefined */
|
|
166
|
+
get(path: string): unknown;
|
|
167
|
+
/** 对象合并:`set({ b: 3 })` */
|
|
168
|
+
set(patch: Record<string, unknown>): void;
|
|
169
|
+
/** 路径写入:`set('user.name', 'Bob')` */
|
|
170
|
+
set(path: string, value: unknown): void;
|
|
171
|
+
/** 恢复为创建时的初始值 */
|
|
172
|
+
reset(): void;
|
|
173
|
+
/** 订阅变化,返回退订函数 */
|
|
174
|
+
subscribe(listener: () => void): () => void;
|
|
175
|
+
/**
|
|
176
|
+
* 单调递增的版本号,供 `useSyncExternalStore` 的 getSnapshot 使用
|
|
177
|
+
* (V1 简化策略:任一变化重渲染整棵 DSL 树)。
|
|
178
|
+
*/
|
|
179
|
+
getVersion(): number;
|
|
180
|
+
private notify;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** 业务服务函数:以求值后的 params 调用(如 `customer.list`) */
|
|
184
|
+
type ServiceHandler = (params: Record<string, unknown>) => unknown | Promise<unknown>;
|
|
185
|
+
/** Service Registry:服务名 → 服务函数(设计文档第 18 节) */
|
|
186
|
+
type ServiceRegistry = Registry<ServiceHandler>;
|
|
187
|
+
/**
|
|
188
|
+
* Component Registry:组件类型名 → 组件条目。
|
|
189
|
+
*
|
|
190
|
+
* 条目在 renderer/ 中被作为 React 组件使用(可为组件或
|
|
191
|
+
* `{ component, withScope }` 包装);本层为保持零 React 依赖,
|
|
192
|
+
* 类型放宽为 unknown,由注册方保证。
|
|
193
|
+
*/
|
|
194
|
+
type ComponentRegistry = Registry<unknown>;
|
|
195
|
+
/** Capability Registry(设计文档第 37 节预留) */
|
|
196
|
+
type CapabilityRegistry = Registry<unknown>;
|
|
197
|
+
/**
|
|
198
|
+
* Form 句柄(表单联动桥,决策同 UiBridge):
|
|
199
|
+
* Form 组件挂载时注册、卸载注销;`form.setValues` 动作经它写入字段值。
|
|
200
|
+
* setValues 不触发校验与 onValuesChange(避免联动循环)。
|
|
201
|
+
*/
|
|
202
|
+
interface FormHandle {
|
|
203
|
+
setValues(values: Record<string, unknown>): void;
|
|
204
|
+
}
|
|
205
|
+
/** Form Registry:表单名 → 句柄(缺省名 'default') */
|
|
206
|
+
type FormRegistry = Registry<FormHandle>;
|
|
207
|
+
/** 路由上下文:参数 + 导航能力(navigate 委托给 RouterAdapter) */
|
|
208
|
+
interface RouteContext {
|
|
209
|
+
params: Record<string, unknown>;
|
|
210
|
+
query: Record<string, unknown>;
|
|
211
|
+
navigate(to: string): void;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* RuntimeContext(设计文档第 15 节,决策 D2):
|
|
215
|
+
* 普通 TS 对象,非 React 代码直接持有;Renderer 经 React Context 透传。
|
|
216
|
+
*/
|
|
217
|
+
interface RuntimeContext {
|
|
218
|
+
app: Record<string, unknown>;
|
|
219
|
+
page: Partial<PageMeta>;
|
|
220
|
+
state: StateStore;
|
|
221
|
+
data: DataStore;
|
|
222
|
+
route: RouteContext;
|
|
223
|
+
user: Record<string, unknown>;
|
|
224
|
+
services: ServiceRegistry;
|
|
225
|
+
components: ComponentRegistry;
|
|
226
|
+
actions: ActionRegistry;
|
|
227
|
+
/** 表单句柄注册表:Form 组件挂载注册,`form.setValues` 动作寻址 */
|
|
228
|
+
forms: FormRegistry;
|
|
229
|
+
/**
|
|
230
|
+
* 命名动作结果记录(设计文档第 48 节,决策 D2):
|
|
231
|
+
* 带 `id` 的动作执行完成后写入——成功时为结果数据,失败时为
|
|
232
|
+
* `{ ok: false, error }`;经 `buildScope` 以 `actions` 键暴露给
|
|
233
|
+
* 表达式(`${actions.<id>.success}`)。页面级共享:同一
|
|
234
|
+
* RuntimeContext 的所有事件分发读写同一记录,PageRuntime
|
|
235
|
+
* destroy 时清理。
|
|
236
|
+
*/
|
|
237
|
+
actionResults: Record<string, unknown>;
|
|
238
|
+
permission: PermissionAdapter;
|
|
239
|
+
capabilities: CapabilityRegistry;
|
|
240
|
+
/** HTTP 出口适配器(DataSource / request 动作共用) */
|
|
241
|
+
http: HttpAdapter;
|
|
242
|
+
/** 当前语言代码(如 'zh-CN') */
|
|
243
|
+
locale: string;
|
|
244
|
+
/** i18n 上下文:提供 `t(key, params?)` 翻译函数 */
|
|
245
|
+
i18n: I18nContext;
|
|
246
|
+
}
|
|
247
|
+
interface CreateRuntimeContextOptions {
|
|
248
|
+
app?: Record<string, unknown>;
|
|
249
|
+
page?: Partial<PageMeta>;
|
|
250
|
+
/** 页面初始 state */
|
|
251
|
+
state?: Record<string, unknown>;
|
|
252
|
+
dataSources?: Record<string, DataSourceConfig>;
|
|
253
|
+
route?: {
|
|
254
|
+
params?: Record<string, unknown>;
|
|
255
|
+
query?: Record<string, unknown>;
|
|
256
|
+
};
|
|
257
|
+
user?: Record<string, unknown>;
|
|
258
|
+
services?: ServiceRegistry;
|
|
259
|
+
components?: ComponentRegistry;
|
|
260
|
+
actions?: ActionRegistry;
|
|
261
|
+
forms?: FormRegistry;
|
|
262
|
+
permission?: PermissionAdapter;
|
|
263
|
+
router?: RouterAdapter;
|
|
264
|
+
http?: HttpAdapter;
|
|
265
|
+
capabilities?: CapabilityRegistry;
|
|
266
|
+
/** 当前语言代码(缺省 'zh-CN') */
|
|
267
|
+
locale?: string;
|
|
268
|
+
/** 回退语言代码(缺省 'zh-CN') */
|
|
269
|
+
defaultLocale?: string;
|
|
270
|
+
/** 翻译消息表 */
|
|
271
|
+
messages?: Record<string, string | Record<string, string>>;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* 组装 RuntimeContext。默认情形下 registries 为空 Registry 实例、
|
|
275
|
+
* adapters 为默认空实现(permission 放行、navigate no-op、http 走 fetch)。
|
|
276
|
+
*
|
|
277
|
+
* 注意:本工厂不注册内置动作;`createPageRuntime` 会自动注册,
|
|
278
|
+
* 独立使用上下文时可调用 `registerBuiltinActions(context.actions)`。
|
|
279
|
+
*/
|
|
280
|
+
declare function createRuntimeContext(options?: CreateRuntimeContextOptions): RuntimeContext;
|
|
281
|
+
/** 表达式局部作用域(row / rowIndex / event / item 等) */
|
|
282
|
+
type LocalScope = ExpressionScope;
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* 组装表达式求值作用域(设计文档第 15、16 节,决策 D2):
|
|
286
|
+
*
|
|
287
|
+
* - `state` / `data` 取 Store 当前值快照
|
|
288
|
+
* - `form` 为 state 的 `form` 路径别名(Form 提交写入 `state.form`,
|
|
289
|
+
* 使 `${form.<field>}` 可用,设计文档第 15 节 form 作用域层级)
|
|
290
|
+
* - 另含 `app` / `page` / `route` / `user` / `params`(route.params 的别名)
|
|
291
|
+
* - `actions` 为命名动作结果记录(`ActionConfig.id` 执行结果,
|
|
292
|
+
* 设计文档第 48 节),引用同一可变记录,后写入的结果立即可见
|
|
293
|
+
* - 局部作用域(`row` / `rowIndex` / `event` / `item` 等)覆盖同名全局键
|
|
294
|
+
*/
|
|
295
|
+
declare function buildScope(context: RuntimeContext, local?: ExpressionScope): ExpressionScope;
|
|
296
|
+
|
|
297
|
+
declare const I18nContextProvider: react.Provider<I18nContext | null>;
|
|
298
|
+
/** 在 React 组件内获取 i18n 上下文;未包裹 I18nContextProvider 时返回缺省上下文 */
|
|
299
|
+
declare function useI18n(): I18nContext;
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* 内置 UI 无关标准动作(设计文档第 17 节,决策 D4)。
|
|
303
|
+
*
|
|
304
|
+
* `navigate` / `message` / `confirm` / `overlay.*` 依赖上层模块,
|
|
305
|
+
* 不在此处实现,由 @pactor-app/router / @pactor-app/ui 的 interaction 层注册。
|
|
306
|
+
* 已注册的同名动作不会被覆盖。
|
|
307
|
+
*/
|
|
308
|
+
declare function registerBuiltinActions(registry: ActionRegistry): void;
|
|
309
|
+
|
|
310
|
+
type AnyComponent = ComponentType<any>;
|
|
311
|
+
/**
|
|
312
|
+
* 组件注册条目:直接注册组件,或以 `{ component, withScope: true }`
|
|
313
|
+
* 声明组件自行渲染 children(经 `useRenderer().renderChildren`
|
|
314
|
+
* 注入行 / 项等局部作用域,此时原始 DSL children 以 `dslChildren` prop 传入)。
|
|
315
|
+
*/
|
|
316
|
+
interface ScopedComponentEntry {
|
|
317
|
+
component: AnyComponent;
|
|
318
|
+
withScope?: boolean;
|
|
319
|
+
}
|
|
320
|
+
type ComponentEntry = AnyComponent | ScopedComponentEntry;
|
|
321
|
+
interface DslRendererProps {
|
|
322
|
+
context: RuntimeContext;
|
|
323
|
+
node?: DslNode;
|
|
324
|
+
engine?: ActionEngine;
|
|
325
|
+
/**
|
|
326
|
+
* 附加子树(最小补充):渲染在 RendererContextProvider 之内、
|
|
327
|
+
* DSL 根节点之后,供 OverlayHost 等宿主把扩展 UI 挂进
|
|
328
|
+
* Renderer 上下文(children 内可 `useRenderer()`)。
|
|
329
|
+
*/
|
|
330
|
+
children?: ReactNode;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* React Renderer(设计文档第 21 节,决策 D5)。
|
|
334
|
+
*
|
|
335
|
+
* 函数式递归渲染:组件一律经 ComponentRegistry 解析(禁止按类型名
|
|
336
|
+
* 硬编码分支);props 深度表达式解析;`when` 条件渲染;`events`
|
|
337
|
+
* 绑定到 Action 引擎;`permission` 经 PermissionAdapter 检查,
|
|
338
|
+
* 无权限时按 denied 策略处理(hidden 不渲染 / 注入 disabled /
|
|
339
|
+
* 注入 readOnly)。V1 简化策略:根节点订阅整个 StateStore /
|
|
340
|
+
* DataStore,任一变化重渲染整棵 DSL 树。
|
|
341
|
+
*/
|
|
342
|
+
declare function DslRenderer({ context, node, engine, children }: DslRendererProps): react.JSX.Element;
|
|
343
|
+
|
|
344
|
+
/** Renderer 经 React Context 透传给被渲染组件的能力 */
|
|
345
|
+
interface RendererContextValue {
|
|
346
|
+
context: RuntimeContext;
|
|
347
|
+
engine: ActionEngine;
|
|
348
|
+
/** 当前局部作用域(row / rowIndex / event / item 等) */
|
|
349
|
+
scope: ExpressionScope;
|
|
350
|
+
/**
|
|
351
|
+
* 渲染 DSL 子节点;`extraScope` 注入的局部作用域覆盖同名全局键,
|
|
352
|
+
* 且仅作用于该子树(Table 行、Repeat 项等场景,设计文档第 21 节)。
|
|
353
|
+
*/
|
|
354
|
+
renderChildren(children: DslNode[] | undefined, extraScope?: ExpressionScope): ReactNode;
|
|
355
|
+
}
|
|
356
|
+
/** 在被渲染组件内获取 Renderer 能力(renderChildren / engine / context) */
|
|
357
|
+
declare function useRenderer(): RendererContextValue;
|
|
358
|
+
/**
|
|
359
|
+
* 订阅 StateStore(决策 D5)。`path` 为点路径;缺省返回整个 state。
|
|
360
|
+
* 基于 `useSyncExternalStore`,state 变化时组件重渲染。
|
|
361
|
+
*/
|
|
362
|
+
declare function useRuntimeState<T = unknown>(path?: string): T;
|
|
363
|
+
/** 订阅指定数据源的 `{ loading, error, data }` 状态 */
|
|
364
|
+
declare function useDataSource(name: string): DataSourceStatus;
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* 未注册组件的占位渲染(决策 D5):展示类型名,dev 友好,
|
|
368
|
+
* 不抛错也不渲染空白。
|
|
369
|
+
*/
|
|
370
|
+
declare function UnsupportedComponent({ type }: {
|
|
371
|
+
type: string;
|
|
372
|
+
}): react.JSX.Element;
|
|
373
|
+
|
|
374
|
+
/** Page DSL 校验失败错误:内含结构化错误列表 */
|
|
375
|
+
declare class PageRuntimeError extends Error {
|
|
376
|
+
readonly errors: DslValidationError[];
|
|
377
|
+
constructor(errors: DslValidationError[]);
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* PageRuntime(设计文档第 20、89 节,决策 D6):
|
|
381
|
+
* PageDsl → 校验 → RuntimeContext → 初始化 state / dataSources(autoLoad)
|
|
382
|
+
* → 生命周期 → 渲染 body 的完整链路。
|
|
383
|
+
*/
|
|
384
|
+
interface PageRuntime {
|
|
385
|
+
readonly pageDsl: PageDsl;
|
|
386
|
+
readonly context: RuntimeContext;
|
|
387
|
+
readonly engine: ActionEngine;
|
|
388
|
+
/** 初始化完成的 Promise(autoLoad 触发 + onInit + onLoad 执行完毕) */
|
|
389
|
+
readonly initialized: Promise<void>;
|
|
390
|
+
/** 是否已销毁 */
|
|
391
|
+
readonly destroyed: boolean;
|
|
392
|
+
/** 渲染 body 子树;未配置 body 时渲染空内容 */
|
|
393
|
+
render(): ReactNode;
|
|
394
|
+
/** 宿主(Router)触发生命周期:onReady */
|
|
395
|
+
ready(): Promise<void>;
|
|
396
|
+
/** 宿主(Router)触发生命周期:onShow */
|
|
397
|
+
show(): Promise<void>;
|
|
398
|
+
/** 宿主(Router)触发生命周期:onHide */
|
|
399
|
+
hide(): Promise<void>;
|
|
400
|
+
/** 触发 onDestroy 并清理订阅 */
|
|
401
|
+
destroy(): Promise<void>;
|
|
402
|
+
/** 订阅生命周期事件,返回退订函数 */
|
|
403
|
+
onLifecycle(listener: (event: LifecycleEventName) => void): () => void;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* 创建 PageRuntime:
|
|
407
|
+
* 1. `validatePageDsl` 校验,失败抛 `PageRuntimeError`(含结构化错误列表)
|
|
408
|
+
* 2. `createRuntimeContext`(page meta + 初始 state + registries / adapters)
|
|
409
|
+
* 3. 注册 8 个 UI 无关内置动作
|
|
410
|
+
* 4. 初始化 DataSources,触发 autoLoad
|
|
411
|
+
* 5. 生命周期:onInit(创建后)→ onLoad(首次加载完成)自动执行;
|
|
412
|
+
* onReady / onShow / onHide / onDestroy 由宿主经方法触发
|
|
413
|
+
*/
|
|
414
|
+
declare function createPageRuntime(pageDsl: PageDsl, options?: CreateRuntimeContextOptions): PageRuntime;
|
|
415
|
+
/**
|
|
416
|
+
* React 组件形式的渲染入口。
|
|
417
|
+
*
|
|
418
|
+
* `children`(最小补充,供 OverlayHost 等宿主扩展使用)渲染在
|
|
419
|
+
* DslRenderer 的 React Context 之内——即页面 body 渲染完成后、
|
|
420
|
+
* 同一 Renderer 上下文下,因此 children 内的组件可使用
|
|
421
|
+
* `useRenderer()` 等 Renderer 能力。未传 children 时行为与此前一致。
|
|
422
|
+
*/
|
|
423
|
+
declare function PageRuntimeView({ runtime, children, }: {
|
|
424
|
+
runtime: PageRuntime;
|
|
425
|
+
children?: ReactNode;
|
|
426
|
+
}): react.JSX.Element;
|
|
427
|
+
|
|
428
|
+
interface ResolveDeepOptions {
|
|
429
|
+
/**
|
|
430
|
+
* 返回 true 时该对象(及其子树)不求值、原样保留。
|
|
431
|
+
* Action 引擎用它跳过 params 中内嵌的子动作配置
|
|
432
|
+
* (`sequence` / `parallel` / `if` 的子动作须在各自执行时
|
|
433
|
+
* 按当时的 state 求值,不能随父动作提前求值)。
|
|
434
|
+
*/
|
|
435
|
+
isOpaque?: (value: Record<string, unknown>) => boolean;
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* 深度表达式求值(设计文档第 21 节,D5):
|
|
439
|
+
*
|
|
440
|
+
* - 字符串经 @pactor-app/expression `resolveTemplate` 求值
|
|
441
|
+
* (整体单表达式保留原始类型,无 `${` 快速返回)
|
|
442
|
+
* - 数组 / 普通对象递归处理
|
|
443
|
+
* - 其余类型原样保留
|
|
444
|
+
*/
|
|
445
|
+
declare function resolveDeep(value: unknown, scope: ExpressionScope, options?: ResolveDeepOptions): unknown;
|
|
446
|
+
|
|
447
|
+
export { type ActionContext, ActionEngine, type ActionHandler, type ActionRegistry, type ActionResult, type CapabilityRegistry, type ComponentEntry, type ComponentRegistry, type CreateRuntimeContextOptions, type DataSourceStatus, DataStore, type DataStoreDeps, DslRenderer, type DslRendererProps, type FormHandle, type FormRegistry, type HttpAdapter, type HttpRequestConfig, I18nContextProvider, type LocalScope, type PageRuntime, PageRuntimeError, PageRuntimeView, type PermissionAdapter, type RendererContextValue, type RouteContext, type RouterAdapter, type RuntimeContext, type ScopedComponentEntry, type ServiceHandler, type ServiceRegistry, StateStore, UnsupportedComponent, buildScope, createDefaultPermissionAdapter, createDefaultRouterAdapter, createFetchHttpAdapter, createPageRuntime, createRuntimeContext, registerBuiltinActions, resolveDeep, useDataSource, useI18n, useRenderer, useRuntimeState };
|