@pactor-app/core 0.1.0 → 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 CHANGED
@@ -22,10 +22,32 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  RUNTIME_SCOPES: () => RUNTIME_SCOPES,
24
24
  Registry: () => Registry,
25
- createI18nContext: () => createI18nContext
25
+ createI18nContext: () => createI18nContext,
26
+ isDslSourceRef: () => isDslSourceRef,
27
+ resolveRootNodes: () => resolveRootNodes
26
28
  });
27
29
  module.exports = __toCommonJS(index_exports);
28
30
 
31
+ // src/node.ts
32
+ function isDslSourceRef(value) {
33
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
34
+ return false;
35
+ }
36
+ const source = value.source;
37
+ return typeof source === "object" && source !== null && (source.type === "service" || source.type === "http");
38
+ }
39
+
40
+ // src/document.ts
41
+ function resolveRootNodes(pageDsl) {
42
+ if (pageDsl.body) {
43
+ return [pageDsl.body];
44
+ }
45
+ if (Array.isArray(pageDsl.children)) {
46
+ return pageDsl.children;
47
+ }
48
+ return [];
49
+ }
50
+
29
51
  // src/scope.ts
30
52
  var RUNTIME_SCOPES = [
31
53
  "global",
@@ -123,5 +145,7 @@ function createI18nContext(options = {}) {
123
145
  0 && (module.exports = {
124
146
  RUNTIME_SCOPES,
125
147
  Registry,
126
- createI18nContext
148
+ createI18nContext,
149
+ isDslSourceRef,
150
+ resolveRootNodes
127
151
  });
package/dist/index.d.cts CHANGED
@@ -38,18 +38,60 @@ interface ActionConfig {
38
38
  }
39
39
  /** 事件映射:事件名 → 单个或多个动作 */
40
40
  type EventMap = Record<string, ActionConfig | ActionConfig[]>;
41
- /** UI DSL 树基础节点 */
42
- interface DslNode {
41
+ /**
42
+ * 动态 DSL 引用(设计文档:DSL 各位置支持远端加载):
43
+ * `source` 为二选一形态——`service`(经 ServiceRegistry 调用)或
44
+ * `http`(经 HttpAdapter 请求),返回 DSL 内容(PageDsl / DslNode / DslNode[]);
45
+ * `params` 值可含表达式字符串,按**首次解析时**的作用域求值一次(不做联动重载)。
46
+ * `placeholder` 为解析期间渲染的占位子树(缺省渲染空)。
47
+ */
48
+ interface DslSourceRef {
49
+ source: {
50
+ type: 'service';
51
+ service: string;
52
+ params?: Record<string, unknown>;
53
+ } | {
54
+ type: 'http';
55
+ request: {
56
+ method?: string;
57
+ url: string;
58
+ params?: Record<string, unknown>;
59
+ headers?: Record<string, string>;
60
+ };
61
+ };
62
+ placeholder?: DslNode;
63
+ }
64
+ /** DslSourceRef 类型守卫 */
65
+ declare function isDslSourceRef(value: unknown): value is DslSourceRef;
66
+ /** 子树元素:内联节点或动态引用(children 数组中可混排) */
67
+ type DslChildrenItem = DslNode | DslSourceRef;
68
+ /** 子树声明:内联数组(元素可为节点或动态引用混排),或整体远端动态引用 */
69
+ type DslChildren = DslChildrenItem[] | DslSourceRef;
70
+ /** UI DSL 树基础节点共有字段 */
71
+ interface DslNodeBase {
43
72
  id?: string;
44
- /** 组件类型,对应 Component Registry 中的注册名 */
45
- type: string;
46
73
  props?: Record<string, unknown>;
47
- children?: DslNode[];
74
+ children?: DslChildren;
48
75
  events?: EventMap;
49
76
  permission?: PermissionConfig;
50
77
  /** 条件渲染 */
51
78
  when?: ConditionConfig;
52
79
  }
80
+ /** 组件节点:`type` 对应 Component Registry 中的注册名 */
81
+ interface DslComponentNode extends DslNodeBase {
82
+ type: string;
83
+ component?: undefined;
84
+ }
85
+ /**
86
+ * 引用节点:`component` 引用页面级命名组件(PageDsl.components)的 key,
87
+ * 渲染该子树;引用处的 props / events 覆盖定义处同名字段
88
+ */
89
+ interface DslReferenceNode extends DslNodeBase {
90
+ component: string;
91
+ type?: undefined;
92
+ }
93
+ /** UI DSL 树节点:组件节点(type)与引用节点(component)二选一 */
94
+ type DslNode = DslComponentNode | DslReferenceNode;
53
95
 
54
96
  /**
55
97
  * DSL 文档结构(设计文档第 9、10、37 节)。
@@ -67,6 +109,10 @@ interface RequiresConfig {
67
109
  interface PageMeta {
68
110
  id: string;
69
111
  title?: string;
112
+ /** 页面名称(标识用途,区别于展示的 title) */
113
+ name?: string;
114
+ /** 页面描述 */
115
+ description?: string;
70
116
  /** 页面类型 / Page Pattern,如 "list"、"detail"、"form" */
71
117
  type?: string;
72
118
  permission?: PermissionConfig;
@@ -81,6 +127,15 @@ interface DataSourceConfig {
81
127
  autoLoad?: boolean;
82
128
  /** 调用参数,值可含表达式字符串 */
83
129
  params?: Record<string, unknown>;
130
+ /**
131
+ * 选项字段映射(该数据源用作选项源时声明):加载结果为数组时,
132
+ * 每项归一化出 `{ label, value, disabled }` 键(原字段保留),
133
+ * 供 Select 等组件经 `${data.x}` 直接绑定
134
+ */
135
+ valueField?: string;
136
+ labelField?: string;
137
+ /** 选项禁用标记字段:数组项中该字段为真值时选项禁用 */
138
+ disabledField?: string;
84
139
  /** type 为 http 时的请求描述 */
85
140
  request?: {
86
141
  method?: string;
@@ -107,13 +162,47 @@ interface PageDsl {
107
162
  dsl: DslVersion;
108
163
  requires?: RequiresConfig;
109
164
  page: PageMeta;
165
+ /** 页面扩展元数据(自由键值,如 version / author / 业务自定义标记),Runtime 不消费,仅供宿主与工具链读取 */
166
+ meta?: Record<string, unknown>;
110
167
  /** 页面初始状态 */
111
168
  state?: Record<string, unknown>;
112
169
  dataSources?: Record<string, DataSourceConfig>;
170
+ /**
171
+ * 页面级命名动作定义:动作名 → 单个动作或动作数组,
172
+ * 供事件中的 `call` 动作按名引用复用(以调用方作用域执行,
173
+ * `${row}` / `${event}` 等局部作用域原样可用)
174
+ */
175
+ actions?: Record<string, ActionConfig | ActionConfig[]>;
176
+ /**
177
+ * 页面级命名组件定义(设计文档第 50 节 Fragment 的页面局部形态):
178
+ * 组件名 → DslNode 子树(或 DslSourceRef 动态引用,引用处渲染时惰性解析),
179
+ * body 中以 `{ component: '名称' }` 引用节点复用,防止 DSL 嵌套过深;
180
+ * 以引用处作用域渲染
181
+ */
182
+ components?: Record<string, DslNode | DslSourceRef>;
113
183
  lifecycle?: LifecycleConfig;
114
- /** UI 树根 */
184
+ /**
185
+ * UI 树根(单个 DslNode)。
186
+ * 与根级 `children` 为两种等价声明形态:`body` 存在时优先使用 `body`;
187
+ * `body` 缺失且 `children` 存在时以根级 `children` 作为 UI 树
188
+ * (隐式片段根,无需 Page 等包装节点,DSL 可描述页面局部);
189
+ * 两者均缺失时按空树处理。读取入口见 `resolveRootNodes`
190
+ */
115
191
  body?: DslNode;
192
+ /**
193
+ * UI 树根(`body` 缺失时生效):数组形态(元素可为 DslNode 或
194
+ * DslSourceRef 混排)或整体动态引用
195
+ */
196
+ children?: DslChildren;
116
197
  }
198
+ /**
199
+ * 读取 Page DSL 的 UI 树根元素列表(官方入口):
200
+ * `body` 存在 → `[body]`;根级 `children` 为数组 → 原样返回
201
+ * (元素可为 DslNode 或 DslSourceRef);根级 `children` 为整体
202
+ * DslSourceRef 或缺失 → 空数组(整体引用形态由渲染入口经
203
+ * DslSourceBoundary 异步解析)
204
+ */
205
+ declare function resolveRootNodes(pageDsl: PageDsl): DslChildrenItem[];
117
206
  /** Fragment DSL(第 50 节):可复用的 UI 片段 */
118
207
  interface FragmentDsl {
119
208
  dsl: DslVersion;
@@ -214,4 +303,4 @@ interface CreateI18nOptions {
214
303
  */
215
304
  declare function createI18nContext(options?: CreateI18nOptions): I18nContext;
216
305
 
217
- export { type ActionConfig, type ApplicationDsl, type ConditionConfig, type CreateI18nOptions, type DataSourceConfig, type DataSourceType, type DslNode, type DslVersion, type EventMap, type ExpressionString, type FragmentDsl, type I18nContext, type I18nMessages, type I18nParams, type LifecycleConfig, type LifecycleEventName, type Locale, type PageDsl, type PageMeta, type PermissionConfig, type PermissionDeniedStrategy, RUNTIME_SCOPES, Registry, type RequiresConfig, type RuntimeScope, createI18nContext };
306
+ export { type ActionConfig, type ApplicationDsl, type ConditionConfig, type CreateI18nOptions, type DataSourceConfig, type DataSourceType, type DslChildren, type DslChildrenItem, type DslComponentNode, type DslNode, type DslNodeBase, type DslReferenceNode, type DslSourceRef, type DslVersion, type EventMap, type ExpressionString, type FragmentDsl, type I18nContext, type I18nMessages, type I18nParams, type LifecycleConfig, type LifecycleEventName, type Locale, type PageDsl, type PageMeta, type PermissionConfig, type PermissionDeniedStrategy, RUNTIME_SCOPES, Registry, type RequiresConfig, type RuntimeScope, createI18nContext, isDslSourceRef, resolveRootNodes };
package/dist/index.d.ts CHANGED
@@ -38,18 +38,60 @@ interface ActionConfig {
38
38
  }
39
39
  /** 事件映射:事件名 → 单个或多个动作 */
40
40
  type EventMap = Record<string, ActionConfig | ActionConfig[]>;
41
- /** UI DSL 树基础节点 */
42
- interface DslNode {
41
+ /**
42
+ * 动态 DSL 引用(设计文档:DSL 各位置支持远端加载):
43
+ * `source` 为二选一形态——`service`(经 ServiceRegistry 调用)或
44
+ * `http`(经 HttpAdapter 请求),返回 DSL 内容(PageDsl / DslNode / DslNode[]);
45
+ * `params` 值可含表达式字符串,按**首次解析时**的作用域求值一次(不做联动重载)。
46
+ * `placeholder` 为解析期间渲染的占位子树(缺省渲染空)。
47
+ */
48
+ interface DslSourceRef {
49
+ source: {
50
+ type: 'service';
51
+ service: string;
52
+ params?: Record<string, unknown>;
53
+ } | {
54
+ type: 'http';
55
+ request: {
56
+ method?: string;
57
+ url: string;
58
+ params?: Record<string, unknown>;
59
+ headers?: Record<string, string>;
60
+ };
61
+ };
62
+ placeholder?: DslNode;
63
+ }
64
+ /** DslSourceRef 类型守卫 */
65
+ declare function isDslSourceRef(value: unknown): value is DslSourceRef;
66
+ /** 子树元素:内联节点或动态引用(children 数组中可混排) */
67
+ type DslChildrenItem = DslNode | DslSourceRef;
68
+ /** 子树声明:内联数组(元素可为节点或动态引用混排),或整体远端动态引用 */
69
+ type DslChildren = DslChildrenItem[] | DslSourceRef;
70
+ /** UI DSL 树基础节点共有字段 */
71
+ interface DslNodeBase {
43
72
  id?: string;
44
- /** 组件类型,对应 Component Registry 中的注册名 */
45
- type: string;
46
73
  props?: Record<string, unknown>;
47
- children?: DslNode[];
74
+ children?: DslChildren;
48
75
  events?: EventMap;
49
76
  permission?: PermissionConfig;
50
77
  /** 条件渲染 */
51
78
  when?: ConditionConfig;
52
79
  }
80
+ /** 组件节点:`type` 对应 Component Registry 中的注册名 */
81
+ interface DslComponentNode extends DslNodeBase {
82
+ type: string;
83
+ component?: undefined;
84
+ }
85
+ /**
86
+ * 引用节点:`component` 引用页面级命名组件(PageDsl.components)的 key,
87
+ * 渲染该子树;引用处的 props / events 覆盖定义处同名字段
88
+ */
89
+ interface DslReferenceNode extends DslNodeBase {
90
+ component: string;
91
+ type?: undefined;
92
+ }
93
+ /** UI DSL 树节点:组件节点(type)与引用节点(component)二选一 */
94
+ type DslNode = DslComponentNode | DslReferenceNode;
53
95
 
54
96
  /**
55
97
  * DSL 文档结构(设计文档第 9、10、37 节)。
@@ -67,6 +109,10 @@ interface RequiresConfig {
67
109
  interface PageMeta {
68
110
  id: string;
69
111
  title?: string;
112
+ /** 页面名称(标识用途,区别于展示的 title) */
113
+ name?: string;
114
+ /** 页面描述 */
115
+ description?: string;
70
116
  /** 页面类型 / Page Pattern,如 "list"、"detail"、"form" */
71
117
  type?: string;
72
118
  permission?: PermissionConfig;
@@ -81,6 +127,15 @@ interface DataSourceConfig {
81
127
  autoLoad?: boolean;
82
128
  /** 调用参数,值可含表达式字符串 */
83
129
  params?: Record<string, unknown>;
130
+ /**
131
+ * 选项字段映射(该数据源用作选项源时声明):加载结果为数组时,
132
+ * 每项归一化出 `{ label, value, disabled }` 键(原字段保留),
133
+ * 供 Select 等组件经 `${data.x}` 直接绑定
134
+ */
135
+ valueField?: string;
136
+ labelField?: string;
137
+ /** 选项禁用标记字段:数组项中该字段为真值时选项禁用 */
138
+ disabledField?: string;
84
139
  /** type 为 http 时的请求描述 */
85
140
  request?: {
86
141
  method?: string;
@@ -107,13 +162,47 @@ interface PageDsl {
107
162
  dsl: DslVersion;
108
163
  requires?: RequiresConfig;
109
164
  page: PageMeta;
165
+ /** 页面扩展元数据(自由键值,如 version / author / 业务自定义标记),Runtime 不消费,仅供宿主与工具链读取 */
166
+ meta?: Record<string, unknown>;
110
167
  /** 页面初始状态 */
111
168
  state?: Record<string, unknown>;
112
169
  dataSources?: Record<string, DataSourceConfig>;
170
+ /**
171
+ * 页面级命名动作定义:动作名 → 单个动作或动作数组,
172
+ * 供事件中的 `call` 动作按名引用复用(以调用方作用域执行,
173
+ * `${row}` / `${event}` 等局部作用域原样可用)
174
+ */
175
+ actions?: Record<string, ActionConfig | ActionConfig[]>;
176
+ /**
177
+ * 页面级命名组件定义(设计文档第 50 节 Fragment 的页面局部形态):
178
+ * 组件名 → DslNode 子树(或 DslSourceRef 动态引用,引用处渲染时惰性解析),
179
+ * body 中以 `{ component: '名称' }` 引用节点复用,防止 DSL 嵌套过深;
180
+ * 以引用处作用域渲染
181
+ */
182
+ components?: Record<string, DslNode | DslSourceRef>;
113
183
  lifecycle?: LifecycleConfig;
114
- /** UI 树根 */
184
+ /**
185
+ * UI 树根(单个 DslNode)。
186
+ * 与根级 `children` 为两种等价声明形态:`body` 存在时优先使用 `body`;
187
+ * `body` 缺失且 `children` 存在时以根级 `children` 作为 UI 树
188
+ * (隐式片段根,无需 Page 等包装节点,DSL 可描述页面局部);
189
+ * 两者均缺失时按空树处理。读取入口见 `resolveRootNodes`
190
+ */
115
191
  body?: DslNode;
192
+ /**
193
+ * UI 树根(`body` 缺失时生效):数组形态(元素可为 DslNode 或
194
+ * DslSourceRef 混排)或整体动态引用
195
+ */
196
+ children?: DslChildren;
116
197
  }
198
+ /**
199
+ * 读取 Page DSL 的 UI 树根元素列表(官方入口):
200
+ * `body` 存在 → `[body]`;根级 `children` 为数组 → 原样返回
201
+ * (元素可为 DslNode 或 DslSourceRef);根级 `children` 为整体
202
+ * DslSourceRef 或缺失 → 空数组(整体引用形态由渲染入口经
203
+ * DslSourceBoundary 异步解析)
204
+ */
205
+ declare function resolveRootNodes(pageDsl: PageDsl): DslChildrenItem[];
117
206
  /** Fragment DSL(第 50 节):可复用的 UI 片段 */
118
207
  interface FragmentDsl {
119
208
  dsl: DslVersion;
@@ -214,4 +303,4 @@ interface CreateI18nOptions {
214
303
  */
215
304
  declare function createI18nContext(options?: CreateI18nOptions): I18nContext;
216
305
 
217
- export { type ActionConfig, type ApplicationDsl, type ConditionConfig, type CreateI18nOptions, type DataSourceConfig, type DataSourceType, type DslNode, type DslVersion, type EventMap, type ExpressionString, type FragmentDsl, type I18nContext, type I18nMessages, type I18nParams, type LifecycleConfig, type LifecycleEventName, type Locale, type PageDsl, type PageMeta, type PermissionConfig, type PermissionDeniedStrategy, RUNTIME_SCOPES, Registry, type RequiresConfig, type RuntimeScope, createI18nContext };
306
+ export { type ActionConfig, type ApplicationDsl, type ConditionConfig, type CreateI18nOptions, type DataSourceConfig, type DataSourceType, type DslChildren, type DslChildrenItem, type DslComponentNode, type DslNode, type DslNodeBase, type DslReferenceNode, type DslSourceRef, type DslVersion, type EventMap, type ExpressionString, type FragmentDsl, type I18nContext, type I18nMessages, type I18nParams, type LifecycleConfig, type LifecycleEventName, type Locale, type PageDsl, type PageMeta, type PermissionConfig, type PermissionDeniedStrategy, RUNTIME_SCOPES, Registry, type RequiresConfig, type RuntimeScope, createI18nContext, isDslSourceRef, resolveRootNodes };
package/dist/index.js CHANGED
@@ -1,3 +1,23 @@
1
+ // src/node.ts
2
+ function isDslSourceRef(value) {
3
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
4
+ return false;
5
+ }
6
+ const source = value.source;
7
+ return typeof source === "object" && source !== null && (source.type === "service" || source.type === "http");
8
+ }
9
+
10
+ // src/document.ts
11
+ function resolveRootNodes(pageDsl) {
12
+ if (pageDsl.body) {
13
+ return [pageDsl.body];
14
+ }
15
+ if (Array.isArray(pageDsl.children)) {
16
+ return pageDsl.children;
17
+ }
18
+ return [];
19
+ }
20
+
1
21
  // src/scope.ts
2
22
  var RUNTIME_SCOPES = [
3
23
  "global",
@@ -94,5 +114,7 @@ function createI18nContext(options = {}) {
94
114
  export {
95
115
  RUNTIME_SCOPES,
96
116
  Registry,
97
- createI18nContext
117
+ createI18nContext,
118
+ isDslSourceRef,
119
+ resolveRootNodes
98
120
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pactor-app/core",
3
- "version": "0.1.0",
3
+ "version": "1.0.0",
4
4
  "description": "Pactor core: DSL protocol types and generic Registry (React-free, zero dependencies)",
5
5
  "keywords": [
6
6
  "pactor",