soma-core 1.4.0 → 1.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.
- package/README.md +1 -1
- package/core/build/blocks/block-compile.ts +31 -2
- package/core/build/blocks/block-container.ts +2 -11
- package/core/build/compiler/page-declaration-compiler.ts +30 -2
- package/core/build/compiler/soma-precompile.js +2053 -23
- package/core/build/component/component-graph.ts +208 -0
- package/core/build/component/package-loader.ts +32 -0
- package/core/build/eject/component-eject.ts +473 -0
- package/core/build/eject/component-upgrade.ts +359 -0
- package/core/build/layout/constraint-solver.ts +235 -0
- package/core/build/layout/css-emitter.ts +116 -0
- package/core/build/layout/page-layout.ts +85 -0
- package/core/build/pack/pack-init.ts +270 -0
- package/core/client/base/SomaHttpClient.ts +34 -1
- package/core/client/base/SomaPageRootBase.ts +61 -0
- package/core/client/component/ai-catalog.ts +121 -4
- package/core/client/component/component-defaults.ts +100 -0
- package/core/client/component/component-definition.types.ts +39 -0
- package/core/client/component/component-manager.ts +79 -4
- package/core/client/component/component-pack.ts +126 -2
- package/core/client/component/keyboard-matrix.ts +144 -0
- package/core/client/component/pack-styles.ts +59 -1
- package/core/client/component/style-features.ts +131 -0
- package/core/client/component/theme-component-tokens.ts +83 -0
- package/core/client/component/verify-pack.ts +120 -1
- package/core/client/container/SomaContainerAdapter.ts +6 -2
- package/core/client/data/data-object-resolver.ts +407 -4
- package/core/client/data/reaction-engine.ts +176 -0
- package/core/client/data/window-engine.ts +477 -0
- package/core/client/engine/event-engine.ts +98 -0
- package/core/client/engine/soma-bootstrap.ts +265 -5
- package/core/client/engine/step-runner.ts +134 -0
- package/core/client/infra/http/SomaHttpService.ts +2 -2
- package/core/client/parser/blocks/page-parser.ts +15 -1
- package/core/client/parser/blocks/use-parser.ts +5 -12
- package/core/client/parser/data-config-parser.ts +316 -8
- package/core/client/parser/duration.ts +16 -0
- package/core/client/parser/layout-parser.ts +157 -0
- package/core/client/parser/page-state-parser.ts +166 -0
- package/core/client/parser/pipeline-parser.ts +76 -1
- package/core/client/parser/reaction-parser.ts +459 -0
- package/core/client/parser/reaction-sugar.ts +47 -0
- package/core/client/parser/step-parser.ts +359 -0
- package/core/client/parser/ui-config-parser.ts +59 -0
- package/core/client/parser/window-parser.ts +294 -0
- package/core/client/theme/theme-engine.ts +102 -2
- package/core/index.ts +184 -0
- package/core/shared/block-errors.ts +11 -0
- package/core/shared/calc/coerce.ts +29 -0
- package/core/shared/calc/errors.ts +43 -0
- package/core/shared/calc/evaluator.ts +101 -0
- package/core/shared/calc/index.ts +12 -0
- package/core/shared/calc/lexer.ts +194 -0
- package/core/shared/calc/parser.ts +204 -0
- package/core/shared/calc/typer.ts +184 -0
- package/core/shared/component/derive-sample.ts +105 -0
- package/core/shared/component/field-lines.ts +473 -0
- package/core/shared/path-algebra.ts +169 -0
- package/core/shared/predicates/index.ts +527 -0
- package/core/shared/types/component-contract.types.ts +151 -9
- package/core/shared/types/data-config.types.ts +120 -1
- package/core/shared/types/domain.types.ts +13 -0
- package/core/shared/types/event.types.ts +22 -2
- package/core/shared/types/layout-constraint.types.ts +73 -0
- package/core/shared/types/page-state.types.ts +60 -0
- package/core/shared/types/reaction.types.ts +144 -0
- package/core/shared/types/step.types.ts +91 -0
- package/core/shared/types/ui-config.types.ts +18 -0
- package/core/shared/types/window.types.ts +177 -0
- package/dist/cli/soma.js +13 -1
- package/dist/core/index.cjs +5529 -631
- package/dist/types/build/blocks/block-container.d.ts +1 -6
- package/dist/types/build/compiler/page-declaration-compiler.d.ts +2 -0
- package/dist/types/build/component/component-graph.d.ts +85 -0
- package/dist/types/build/eject/component-eject.d.ts +121 -0
- package/dist/types/build/eject/component-upgrade.d.ts +43 -0
- package/dist/types/build/layout/constraint-solver.d.ts +36 -0
- package/dist/types/build/layout/css-emitter.d.ts +18 -0
- package/dist/types/build/layout/page-layout.d.ts +24 -0
- package/dist/types/build/pack/pack-init.d.ts +8 -0
- package/dist/types/client/base/SomaHttpClient.d.ts +8 -0
- package/dist/types/client/base/SomaPageRootBase.d.ts +28 -0
- package/dist/types/client/component/ai-catalog.d.ts +33 -1
- package/dist/types/client/component/component-defaults.d.ts +15 -0
- package/dist/types/client/component/component-definition.types.d.ts +38 -0
- package/dist/types/client/component/component-manager.d.ts +36 -0
- package/dist/types/client/component/component-pack.d.ts +32 -2
- package/dist/types/client/component/keyboard-matrix.d.ts +24 -0
- package/dist/types/client/component/pack-styles.d.ts +21 -0
- package/dist/types/client/component/style-features.d.ts +26 -0
- package/dist/types/client/component/theme-component-tokens.d.ts +14 -0
- package/dist/types/client/component/verify-pack.d.ts +10 -0
- package/dist/types/client/data/data-object-resolver.d.ts +106 -1
- package/dist/types/client/data/reaction-engine.d.ts +21 -0
- package/dist/types/client/data/window-engine.d.ts +27 -0
- package/dist/types/client/engine/event-engine.d.ts +15 -0
- package/dist/types/client/engine/soma-bootstrap.d.ts +70 -0
- package/dist/types/client/engine/step-runner.d.ts +24 -0
- package/dist/types/client/parser/blocks/use-parser.d.ts +2 -2
- package/dist/types/client/parser/duration.d.ts +1 -0
- package/dist/types/client/parser/layout-parser.d.ts +9 -0
- package/dist/types/client/parser/page-state-parser.d.ts +32 -0
- package/dist/types/client/parser/reaction-parser.d.ts +16 -0
- package/dist/types/client/parser/reaction-sugar.d.ts +13 -0
- package/dist/types/client/parser/step-parser.d.ts +23 -0
- package/dist/types/client/parser/ui-config-parser.d.ts +5 -0
- package/dist/types/client/parser/window-parser.d.ts +25 -0
- package/dist/types/client/theme/theme-engine.d.ts +26 -0
- package/dist/types/index.d.ts +35 -2
- package/dist/types/shared/block-errors.d.ts +5 -0
- package/dist/types/shared/calc/coerce.d.ts +4 -0
- package/dist/types/shared/calc/errors.d.ts +14 -0
- package/dist/types/shared/calc/evaluator.d.ts +2 -0
- package/dist/types/shared/calc/index.d.ts +6 -0
- package/dist/types/shared/calc/lexer.d.ts +20 -0
- package/dist/types/shared/calc/parser.d.ts +49 -0
- package/dist/types/shared/calc/typer.d.ts +16 -0
- package/dist/types/shared/component/derive-sample.d.ts +23 -0
- package/dist/types/shared/component/field-lines.d.ts +19 -0
- package/dist/types/shared/path-algebra.d.ts +56 -0
- package/dist/types/shared/predicates/index.d.ts +79 -0
- package/dist/types/shared/types/component-contract.types.d.ts +134 -6
- package/dist/types/shared/types/data-config.types.d.ts +115 -1
- package/dist/types/shared/types/domain.types.d.ts +12 -0
- package/dist/types/shared/types/event.types.d.ts +8 -2
- package/dist/types/shared/types/layout-constraint.types.d.ts +52 -0
- package/dist/types/shared/types/page-state.types.d.ts +49 -0
- package/dist/types/shared/types/reaction.types.d.ts +115 -0
- package/dist/types/shared/types/step.types.d.ts +76 -0
- package/dist/types/shared/types/ui-config.types.d.ts +18 -0
- package/dist/types/shared/types/window.types.d.ts +171 -0
- package/package.json +3 -2
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// 反应图类型(REQ-010 S1b)——「字段之间怎么互相影响」的声明式表达。
|
|
2
|
+
//
|
|
3
|
+
// 要解决的问题:表单里第三类逻辑——不是「值合不合法」(rules),不是「该不该出现」
|
|
4
|
+
// (谓词图已覆盖),而是**「A 变了,B 要跟着变成什么」**:选了公司就必须填税号、
|
|
5
|
+
// 金额减折扣自动算出实付、校验失败就锁住提交。
|
|
6
|
+
//
|
|
7
|
+
// ── 为什么必须是「图」而不是一串回调 ──────────────────────────────────
|
|
8
|
+
// 上游三家(Formily 的 x-reactions、amis 的 onEvent、antd 的 dependencies)都能表达联动,
|
|
9
|
+
// 但它们的依赖是**运行时收集**的:Formily 的编译器是 `new Function('$root','with($root){…}')`
|
|
10
|
+
// 加 MobX 式的 Tracker,amis 是 `${}` 沿运行时数据链向上找。后果是编译期什么都不知道——
|
|
11
|
+
// 建不了图、检不了环、说不清一个字段的值最终来自哪个接口,CSP 也去不掉 unsafe-eval。
|
|
12
|
+
//
|
|
13
|
+
// SOMA 的字段是字典里的封闭枚举、算子是闭集、calc 是受限文法,所以**依赖可以在声明期
|
|
14
|
+
// 静态提取**:`when` 的字段(collectPredicateFields)∪ `depends` ∪ `calc` 的引用
|
|
15
|
+
// (collectCalcRefs)就是这条反应的全部入边。有了入边就能建 DAG、能拓扑排序、能检环、
|
|
16
|
+
// 能回答「改这个字段会牵动谁」和「这个字段的值是怎么来的」。
|
|
17
|
+
// 这是本需求里对方结构上做不到的三件事之一。
|
|
18
|
+
|
|
19
|
+
import type { SomaFieldPredicate } from '../predicates';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 触发时机——闭集十一档(对齐 Formily 的 effect hooks,但作为 DSL 枚举而非自由字符串)。
|
|
23
|
+
* 时机进类型系统之后,「什么时候触发」不再是拼写正确才生效的字符串。
|
|
24
|
+
*/
|
|
25
|
+
export const SOMA_REACTION_PHASES = [
|
|
26
|
+
'field_init', 'field_mount', 'field_unmount',
|
|
27
|
+
'field_value_change', 'field_input_change',
|
|
28
|
+
'field_validate_start', 'field_validate_end',
|
|
29
|
+
'field_validate_failed', 'field_validate_success',
|
|
30
|
+
'form_submit_start', 'form_submit_end',
|
|
31
|
+
] as const;
|
|
32
|
+
|
|
33
|
+
export type SomaReactionPhase = typeof SOMA_REACTION_PHASES[number];
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 显示三态(Formily `display` 的对位物)。
|
|
37
|
+
*
|
|
38
|
+
* `hidden` 与 `none` 的差别在**提交载荷**上:前者字段还在 values 里(只是不给看),
|
|
39
|
+
* 后者连数据一起摘除。用一个布尔 `visible` 表达不了这件事,而后端收到一份
|
|
40
|
+
* 「隐藏了但仍然提交」的脏数据时,前端这边一点迹象都没有。
|
|
41
|
+
*/
|
|
42
|
+
export const SOMA_FIELD_DISPLAYS = ['visible', 'hidden', 'none'] as const;
|
|
43
|
+
export type SomaFieldDisplay = typeof SOMA_FIELD_DISPLAYS[number];
|
|
44
|
+
|
|
45
|
+
/** 可编辑四态(Formily `pattern` 的对位物),与显示三态**正交** */
|
|
46
|
+
export const SOMA_FIELD_PATTERNS = ['editable', 'disabled', 'read_only', 'read_pretty'] as const;
|
|
47
|
+
export type SomaFieldPattern = typeof SOMA_FIELD_PATTERNS[number];
|
|
48
|
+
|
|
49
|
+
/** 值 patch:清空 / 复制另一个字段 / 走 calc 算 —— 三种,没有第四种(没有 `run`) */
|
|
50
|
+
export type SomaFieldValuePatch = 'clear' | { from: string } | { calc: string };
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 封闭 patch 集。
|
|
54
|
+
*
|
|
55
|
+
* 这里是 Formily `fulfill.state` 的对位物,**刻意删掉了 `run`**——那是它的逃生舱,
|
|
56
|
+
* 也是它必须带 eval 的原因。八个键各自一句话说得清,且每个都能在解析期与字段类型配对。
|
|
57
|
+
*/
|
|
58
|
+
export interface SomaFieldStatePatch {
|
|
59
|
+
/** 语法糖:true → visible,false → hidden(要摘数据请显式写 display: none) */
|
|
60
|
+
visible?: boolean;
|
|
61
|
+
display?: SomaFieldDisplay;
|
|
62
|
+
pattern?: SomaFieldPattern;
|
|
63
|
+
required?: boolean;
|
|
64
|
+
value?: SomaFieldValuePatch;
|
|
65
|
+
/** 枚举源切换:'<对象>.<字段>' */
|
|
66
|
+
options?: { from: string };
|
|
67
|
+
/** 覆盖该字段的提示文案 */
|
|
68
|
+
message?: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 表单级 patch(不挂在任何字段上) */
|
|
72
|
+
export interface SomaFormStatePatch {
|
|
73
|
+
submit?: { disabled?: boolean };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface SomaReactionConfig {
|
|
77
|
+
/** 条件;与 `depends` 至少给一个(否则这条反应永远不知道何时该跑) */
|
|
78
|
+
when?: SomaFieldPredicate;
|
|
79
|
+
/** 显式依赖:`when` 之外还要盯着的字段(`calc` 的引用会自动并入,不必重复写) */
|
|
80
|
+
depends?: string[];
|
|
81
|
+
/** 缺省 `field_value_change` */
|
|
82
|
+
on?: SomaReactionPhase;
|
|
83
|
+
/** 仅 `field_validate_*` 时有意义:盯着哪个字段的校验结果 */
|
|
84
|
+
target?: string;
|
|
85
|
+
fulfill?: Record<string, SomaFieldStatePatch | SomaFormStatePatch>;
|
|
86
|
+
otherwise?: Record<string, SomaFieldStatePatch | SomaFormStatePatch>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** 表单级 patch 在 fulfill/otherwise 里用的保留键 */
|
|
90
|
+
export const SOMA_REACTION_FORM_KEY = 'submit';
|
|
91
|
+
|
|
92
|
+
/** 编译后的单条反应 */
|
|
93
|
+
export interface SomaCompiledReaction {
|
|
94
|
+
/** 拓扑序下标 */
|
|
95
|
+
index: number;
|
|
96
|
+
/** 声明序(错误信息用:作者看的是自己写的顺序,不是拓扑序) */
|
|
97
|
+
declaredAt: number;
|
|
98
|
+
/** 入边:`when` 字段 ∪ `depends` ∪ `calc` 引用(去重) */
|
|
99
|
+
reads: readonly string[];
|
|
100
|
+
/** 出边:`fulfill` / `otherwise` 的字段键(不含 submit) */
|
|
101
|
+
writes: readonly string[];
|
|
102
|
+
phase: SomaReactionPhase;
|
|
103
|
+
config: SomaReactionConfig;
|
|
104
|
+
/** 预解析的 calc AST(避免每次求值重新解析):`<字段>` → AST */
|
|
105
|
+
calcAsts: Readonly<Record<string, unknown>>;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 字段回溯:这个字段的状态是谁写的、依据什么、数据从哪来。
|
|
110
|
+
*
|
|
111
|
+
* amis 的 `${x}` 只能沿运行时链向上找,给不出这张表;这是「可静态回溯」的落点。
|
|
112
|
+
*/
|
|
113
|
+
export interface SomaFieldProvenance {
|
|
114
|
+
/** 写它的反应(声明序下标) */
|
|
115
|
+
writtenBy: readonly number[];
|
|
116
|
+
/** 传递闭包内的全部上游字段 */
|
|
117
|
+
readsFrom: readonly string[];
|
|
118
|
+
/** 该字段来自读通道的哪个接口(`from[].api`);派生字段为 undefined */
|
|
119
|
+
sourceApi?: string;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** 编译产物 */
|
|
123
|
+
export interface SomaReactionGraph {
|
|
124
|
+
/** 已按拓扑序排列 */
|
|
125
|
+
reactions: readonly SomaCompiledReaction[];
|
|
126
|
+
/** 字段 → 读它的反应在 `reactions` 里的下标(受影响子图的入口) */
|
|
127
|
+
byField: Readonly<Record<string, readonly number[]>>;
|
|
128
|
+
/** 字段 → 回溯信息 */
|
|
129
|
+
provenance: Readonly<Record<string, SomaFieldProvenance>>;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** 一次求值的产物 */
|
|
133
|
+
export interface SomaReactionResult {
|
|
134
|
+
/** 字段 → 合并后的 patch(后写的赢,与声明序一致) */
|
|
135
|
+
patches: Readonly<Record<string, SomaFieldStatePatch>>;
|
|
136
|
+
/** 表单级 patch */
|
|
137
|
+
form: SomaFormStatePatch;
|
|
138
|
+
/** 应用 value patch 之后的值(新对象,不改入参) */
|
|
139
|
+
values: Record<string, unknown>;
|
|
140
|
+
/** 被 `display: none` 摘除的字段(写通道据此剔除请求体) */
|
|
141
|
+
detached: readonly string[];
|
|
142
|
+
/** 传播步数——图无环时必然有界,作为 RG-5 的断言面 */
|
|
143
|
+
steps: number;
|
|
144
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// 动作编排类型(REQ-010 S4)——「一个交互要按顺序做好几件事」的声明式表达。
|
|
2
|
+
//
|
|
3
|
+
// ── 它替掉的是什么 ────────────────────────────────────────────────────
|
|
4
|
+
// 今天一个事件只能挂一条管道。要「先导出、成功了跳转、失败了弹错、顺带刷统计」,
|
|
5
|
+
// 只能在 Domain 里写一个 handler 把四件事串起来——于是编排逻辑回到了代码里,
|
|
6
|
+
// 声明层看不见它,AI 也生成不了它。
|
|
7
|
+
//
|
|
8
|
+
// amis 的 `onEvent` 能表达编排,代价是它带 `custom(script)` 逃生舱;
|
|
9
|
+
// XState 能表达状态机,但它的 actions 是函数。两边的共同点:**编排图不是数据**,
|
|
10
|
+
// 所以画不出来、diff 不了、也没法在编译期回答「这条链会不会不终止」。
|
|
11
|
+
//
|
|
12
|
+
// SOMA 的每一步都是既有的四动词管道 + 闭集控制流,所以编排图是**纯数据**:
|
|
13
|
+
// 可画、可 diff、可静态判定可终止性。逃生舱换成**具名动作注册表**——
|
|
14
|
+
// 实现仍在 Host 代码里,但它有名字、要注册、可审计,声明层零脚本。
|
|
15
|
+
|
|
16
|
+
import type { SomaFieldPredicate } from '../predicates';
|
|
17
|
+
import type { ParsedEvent } from './event.types';
|
|
18
|
+
|
|
19
|
+
/** 出错之后怎么走:停 / 继续 / 跳到第 n 步(只许向后,见 AO-1) */
|
|
20
|
+
export type SomaStepOnError = 'stop' | 'continue' | `goto:${number}`;
|
|
21
|
+
|
|
22
|
+
/** 单步:一条管道 + 可选的条件、输出槽与错误去向 */
|
|
23
|
+
export interface SomaDoStep {
|
|
24
|
+
when?: SomaFieldPredicate;
|
|
25
|
+
do: string;
|
|
26
|
+
output?: string;
|
|
27
|
+
on_error?: SomaStepOnError;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** 分支:取第一个成立的 `when`;`otherwise` 可选且只能有一个、且必须在末尾 */
|
|
31
|
+
export interface SomaSwitchStep {
|
|
32
|
+
when?: SomaFieldPredicate;
|
|
33
|
+
switch: Array<{ when?: SomaFieldPredicate; otherwise?: true; do: string; output?: string }>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** 并行:分支之间**不许互引输出槽**(互引就意味着有顺序,那它就不是并行) */
|
|
37
|
+
export interface SomaParallelStep {
|
|
38
|
+
parallel: SomaStep[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** 遍历:`over` 必须是有界的(数组型输出槽或事件载荷里的数组) */
|
|
42
|
+
export interface SomaForEachStep {
|
|
43
|
+
for_each: { over: string; as: string; steps: SomaStep[] };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type SomaStep = SomaDoStep | SomaSwitchStep | SomaParallelStep | SomaForEachStep;
|
|
47
|
+
|
|
48
|
+
/** 输出槽:本次事件内的具名中间结果 */
|
|
49
|
+
export interface SomaStepSlot {
|
|
50
|
+
/** 声明它的步骤序号(引用只许向后,见 AO-2) */
|
|
51
|
+
declaredAt: number;
|
|
52
|
+
/** 产出它的动作类型,用于「这个槽是不是数组」这类判断 */
|
|
53
|
+
producedBy: string;
|
|
54
|
+
/** 是否已知为数组(`for_each.over` 只认这种) */
|
|
55
|
+
bounded: boolean;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** 编译后的一步:管道已解析,条件已校验 */
|
|
59
|
+
export interface SomaCompiledStep {
|
|
60
|
+
index: number;
|
|
61
|
+
kind: 'do' | 'switch' | 'parallel' | 'for_each';
|
|
62
|
+
when?: SomaFieldPredicate;
|
|
63
|
+
/** kind='do' */
|
|
64
|
+
pipeline?: Omit<ParsedEvent, 'somaId' | 'domEvent'>;
|
|
65
|
+
output?: string;
|
|
66
|
+
onError: SomaStepOnError;
|
|
67
|
+
/** kind='switch' */
|
|
68
|
+
branches?: Array<{
|
|
69
|
+
when?: SomaFieldPredicate;
|
|
70
|
+
otherwise: boolean;
|
|
71
|
+
pipeline: Omit<ParsedEvent, 'somaId' | 'domEvent'>;
|
|
72
|
+
output?: string;
|
|
73
|
+
}>;
|
|
74
|
+
/** kind='parallel' / 'for_each' */
|
|
75
|
+
children?: SomaCompiledStep[];
|
|
76
|
+
/** kind='for_each' */
|
|
77
|
+
over?: string;
|
|
78
|
+
as?: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 编译产物:纯数据,可画、可 diff、可进目录快照(AO-4)。
|
|
83
|
+
*
|
|
84
|
+
* `edges` 是顺序边与 `goto` 边的并集——它存在的唯一理由是**能被画出来**:
|
|
85
|
+
* 一张编排图如果只能靠读 YAML 想象,那它和写在代码里的 handler 没有区别。
|
|
86
|
+
*/
|
|
87
|
+
export interface SomaStepGraph {
|
|
88
|
+
steps: SomaCompiledStep[];
|
|
89
|
+
slots: Record<string, SomaStepSlot>;
|
|
90
|
+
edges: Array<[number, number]>;
|
|
91
|
+
}
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
import type { OnChangeRule } from './watcher.types';
|
|
5
5
|
import type { SomaAdaptiveConfig } from './adaptive.types';
|
|
6
|
+
import type { SomaPageStateConfig } from './page-state.types';
|
|
7
|
+
import type { SomaLayoutConstraint } from './layout-constraint.types';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* 作用域声明
|
|
@@ -102,6 +104,22 @@ export interface UiConfig {
|
|
|
102
104
|
* 所以此键必须保持可选,且缺席时不得在下游产生任何默认值。
|
|
103
105
|
*/
|
|
104
106
|
adaptive?: SomaAdaptiveConfig;
|
|
107
|
+
/**
|
|
108
|
+
* 页面态切片声明(REQ-010 F-37,保留键,可选)。
|
|
109
|
+
* 与 `adaptive` 同一条纪律:未声明时编译产物与迁移前字节级一致。
|
|
110
|
+
*/
|
|
111
|
+
state?: SomaPageStateConfig;
|
|
112
|
+
/**
|
|
113
|
+
* 约束布局声明(REQ-010 S3 / REQ-011 接线,保留键,可选):锚点 id → 一行的约束。
|
|
114
|
+
*
|
|
115
|
+
* 这是**声明**;它的产物是 `layoutCss`。求解只在构建期(`compilePageDeclaration`)发生,
|
|
116
|
+
* 运行时收到的是已经解好的 CSS(`layout_css`),浏览器一行 JS 都不用算。
|
|
117
|
+
* 运行时若收到的是 `layout` 而不是 `layout_css`,说明页面没走构建期编译——
|
|
118
|
+
* 引擎只告警、不求解(CL-4:求解器不进 client)。
|
|
119
|
+
*/
|
|
120
|
+
layout?: Record<string, SomaLayoutConstraint>;
|
|
121
|
+
/** 构建期求解产物:只含容器查询 + flex 的 CSS(CL-2),运行时按页注入一次 */
|
|
122
|
+
layoutCss?: string;
|
|
105
123
|
}
|
|
106
124
|
|
|
107
125
|
/**
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// 数据窗口类型(REQ-010 S2)——「一屏一屏地从服务端取数」这件事的声明式表达。
|
|
2
|
+
//
|
|
3
|
+
// ── 为什么窗口必须是引擎的东西,不是组件的东西 ────────────────────────────
|
|
4
|
+
// 今天每个列表类组件各自持 `page / page_size / sort_key / filters`,各自拼请求、各自
|
|
5
|
+
// 处理竞态。三个后果:① 同一页上两个组件对「第几页」的理解可以不一致;② 换排序该不该
|
|
6
|
+
// 回第一页这种裁决被复制了 N 份,改一处漏一处;③ 前端的取数意图对后端是不可校验的
|
|
7
|
+
// —— 后端收到 `sort=amount` 只能照做,它没有办法判断 `amount` 在前端那边到底是什么类型。
|
|
8
|
+
//
|
|
9
|
+
// AG Grid 的 SSRM 把请求形状定下来了(start/end/sortModel/filterModel/rowGroupCols/valueCols),
|
|
10
|
+
// 这是对的;但它的列是函数(`valueGetter`),所以「这个排序字段合不合法」只能靠人。
|
|
11
|
+
// SOMA 的字段是字典里的封闭枚举,于是同一个请求形状可以**带上字典哈希**下发:
|
|
12
|
+
// 后端按同一份字典校验前端的意图,而不只是执行它。这是本层唯一的结构性超越点。
|
|
13
|
+
|
|
14
|
+
import type { SomaFieldPredicateOp } from '../predicates';
|
|
15
|
+
import type { SomaDataSubmitResult } from './data-config.types';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 过滤 AST:递归的 `join + conditions`,叶子复用谓词图的算子闭集。
|
|
19
|
+
*
|
|
20
|
+
* 复用而不是另立一套算子,是因为同一个「状态在已付/已发货里」的判断,在字段显隐
|
|
21
|
+
* (RG 的 `when`)与列表过滤(这里)上必须是同一个意思。两套算子表迟早会有一套先长出
|
|
22
|
+
* 第 13 个算子。
|
|
23
|
+
*/
|
|
24
|
+
export type SomaFilterNode =
|
|
25
|
+
| { join: 'and' | 'or'; conditions: SomaFilterNode[] }
|
|
26
|
+
| { field: string; op: SomaFieldPredicateOp; value?: unknown };
|
|
27
|
+
|
|
28
|
+
/** 排序意图:多列,声明序即优先级 */
|
|
29
|
+
export interface SomaWindowSort {
|
|
30
|
+
field: string;
|
|
31
|
+
order: 'asc' | 'desc';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** 聚合函数闭集;`count` 之外都只对数值型字段(声明期配对) */
|
|
35
|
+
export const SOMA_AGGREGATE_FNS = ['sum', 'avg', 'min', 'max', 'count'] as const;
|
|
36
|
+
export type SomaAggregateFn = typeof SOMA_AGGREGATE_FNS[number];
|
|
37
|
+
|
|
38
|
+
export interface SomaWindowAggregate {
|
|
39
|
+
field: string;
|
|
40
|
+
fn: SomaAggregateFn;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 全选语义三档。
|
|
45
|
+
*
|
|
46
|
+
* `all` 与 `filtered` 的差别只在后端:前者是「库里所有行」,后者是「当前过滤条件命中的行」。
|
|
47
|
+
* 前端表现一样(都是 `base: 'all'`),但一个批量删除操作在这两档之间的差别是灾难性的,
|
|
48
|
+
* 所以它必须是显式声明,不能靠"当时有没有过滤条件"猜。
|
|
49
|
+
*/
|
|
50
|
+
export const SOMA_SELECT_ALL_MODES = ['all', 'filtered', 'current_page'] as const;
|
|
51
|
+
export type SomaSelectAllMode = typeof SOMA_SELECT_ALL_MODES[number];
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 选择态:基线 + 反选集。
|
|
55
|
+
*
|
|
56
|
+
* 十万行里「全选后取消三行」,朴素做法要传九万九千九百九十七个 id。
|
|
57
|
+
* 记成 `{ base: 'all', toggled: [3 个] }` 之后载荷是 O(反选数) —— 这也是
|
|
58
|
+
* 后端唯一能高效解释的形状(它自己知道 `all` 是哪些行)。
|
|
59
|
+
*/
|
|
60
|
+
export interface SomaWindowSelection {
|
|
61
|
+
base: 'none' | 'all';
|
|
62
|
+
toggled: string[];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface SomaWindowBlockConfig {
|
|
66
|
+
/** 一块多少行(SSRM cacheBlockSize 等价) */
|
|
67
|
+
size: number;
|
|
68
|
+
/** 最多缓存几块,超出按 LRU 淘汰;当前视口覆盖的块永不淘汰 */
|
|
69
|
+
max_blocks: number;
|
|
70
|
+
/** 合并快速滚动期间的中间块请求(毫秒) */
|
|
71
|
+
debounce_ms: number;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** 解析产物:声明期已把所有缺省补齐、所有引用对着字典校验过 */
|
|
75
|
+
export interface SomaWindowConfig {
|
|
76
|
+
/** 只有服务端窗口。客户端窗口与「业务逻辑归后端」冲突,不做 */
|
|
77
|
+
mode: 'server';
|
|
78
|
+
block: SomaWindowBlockConfig;
|
|
79
|
+
sort: SomaWindowSort[];
|
|
80
|
+
filter: SomaFilterNode | null;
|
|
81
|
+
group: { by: string[]; keys: string[] } | null;
|
|
82
|
+
aggregate: SomaWindowAggregate[];
|
|
83
|
+
selection: SomaWindowSelection;
|
|
84
|
+
select_all: SomaSelectAllMode;
|
|
85
|
+
cache: { ttl_ms: number | null; keep_previous: boolean };
|
|
86
|
+
revalidate_ms: number | null;
|
|
87
|
+
/**
|
|
88
|
+
* 字段字典的稳定哈希(字段名 + 类型 + 权限)。
|
|
89
|
+
* 随请求下发,后端据此拒收「按一份它不认识的字典发来的意图」。
|
|
90
|
+
*/
|
|
91
|
+
dict_hash: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 请求体:**纯 JSON**(DW-2)。
|
|
96
|
+
*
|
|
97
|
+
* 这里不许出现函数、Set、Map、DOM 引用——它要能 `JSON.stringify` 往返相等,
|
|
98
|
+
* 因为它同时是网络载荷、缓存键和排障时贴进工单的那段文本。
|
|
99
|
+
*/
|
|
100
|
+
export interface SomaWindowRequest {
|
|
101
|
+
start: number;
|
|
102
|
+
end: number;
|
|
103
|
+
sort: SomaWindowSort[];
|
|
104
|
+
filter: SomaFilterNode | null;
|
|
105
|
+
group: { by: string[]; keys: string[] } | null;
|
|
106
|
+
aggregate: SomaWindowAggregate[];
|
|
107
|
+
dict_hash: string;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface SomaWindowResponse {
|
|
111
|
+
rows: unknown[];
|
|
112
|
+
/** 后端不知道总数时可省略:滚动条按「至少还有一块」的语义给初值 */
|
|
113
|
+
total?: number;
|
|
114
|
+
group_info?: Record<string, unknown>;
|
|
115
|
+
grand_total?: Record<string, unknown>;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* 写通道事务体(对齐 AG Grid ServerSideTransaction)。
|
|
120
|
+
* 一次提交是一个 patch 集,不是一个对象——批量编辑的天然形状。
|
|
121
|
+
*/
|
|
122
|
+
export interface SomaTransaction {
|
|
123
|
+
/** 分组路径:改的是哪一层的行 */
|
|
124
|
+
route?: string[];
|
|
125
|
+
add?: Array<Record<string, unknown>>;
|
|
126
|
+
remove?: Array<Record<string, unknown>>;
|
|
127
|
+
update?: Array<Record<string, unknown>>;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** 组件消费面:自治组件与受控组件都只认这一个把手 */
|
|
131
|
+
export interface SomaWindowHandle {
|
|
132
|
+
readonly spec: SomaWindowConfig;
|
|
133
|
+
/** 展示值:已提交值 ⊕ 未提交编辑(pending) */
|
|
134
|
+
readonly rows: readonly unknown[];
|
|
135
|
+
readonly total: number | undefined;
|
|
136
|
+
readonly selection: SomaWindowSelection;
|
|
137
|
+
readonly loading: boolean;
|
|
138
|
+
readonly error: string;
|
|
139
|
+
/** 当前缓存块数(DW-6 的观测面) */
|
|
140
|
+
readonly blockCount: number;
|
|
141
|
+
/** 当前视口 [start, end):`rows` 就是这一段;受控组件按 `start` 还原真实行号 */
|
|
142
|
+
readonly start: number;
|
|
143
|
+
readonly end: number;
|
|
144
|
+
/** 当前生效的排序 / 过滤意图(声明起步,之后随 request(patch) 改写) */
|
|
145
|
+
readonly sort: SomaWindowSort[];
|
|
146
|
+
readonly filter: SomaFilterNode | null;
|
|
147
|
+
/** 改意图或挪视口;改 sort/filter/group/aggregate 任一项都会清空缓存并回到第 0 行 */
|
|
148
|
+
request(patch: SomaWindowRequestPatch): Promise<void>;
|
|
149
|
+
/** 翻转选择:`toggle` 逐个翻,`base` 换基线并清空反选集 */
|
|
150
|
+
select(patch: { toggle?: string[]; base?: 'none' | 'all' }): void;
|
|
151
|
+
isSelected(id: string): boolean;
|
|
152
|
+
/** 未提交的单元格编辑(受控编辑:组件只发意图,不写数据) */
|
|
153
|
+
edit(id: string, field: string, value: unknown): void;
|
|
154
|
+
readonly pendingCount: number;
|
|
155
|
+
commit(tx?: SomaTransaction): Promise<SomaDataSubmitResult>;
|
|
156
|
+
savepoint(): number;
|
|
157
|
+
revertTo(id: number): void;
|
|
158
|
+
/**
|
|
159
|
+
* 分组下钻(F-33):展开到 `keys` 这一层,拿它自己的窗口。
|
|
160
|
+
* 没声明 `group:` 段、或路径比分组层数还深时返回 null。
|
|
161
|
+
* 子窗口继承父的排序与过滤,**不继承**选择态。
|
|
162
|
+
*/
|
|
163
|
+
drillDown(keys: readonly string[]): SomaWindowHandle | null;
|
|
164
|
+
/** 已展开的子窗口路径(诊断用) */
|
|
165
|
+
readonly childPaths: string[];
|
|
166
|
+
/** 对象级 reload 时销毁(连同子分组窗口) */
|
|
167
|
+
destroy(): void;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export interface SomaWindowRequestPatch {
|
|
171
|
+
start?: number;
|
|
172
|
+
end?: number;
|
|
173
|
+
sort?: SomaWindowSort[];
|
|
174
|
+
filter?: SomaFilterNode | null;
|
|
175
|
+
group?: { by: string[]; keys: string[] } | null;
|
|
176
|
+
aggregate?: SomaWindowAggregate[];
|
|
177
|
+
}
|
package/dist/cli/soma.js
CHANGED
|
@@ -11,6 +11,18 @@ const args = process.argv.slice(2);
|
|
|
11
11
|
const command = args[0] || 'dev';
|
|
12
12
|
const delegated = ['doctor', 'sync', 'lsp', 'codegen', 'init', 'package-vscode', 'eject'];
|
|
13
13
|
const packageRoot = node_path_1.default.resolve(__dirname, '../..');
|
|
14
|
+
// REQ-009 EC-1/2/3:组件 eject / diff 与组件包脚手架。
|
|
15
|
+
// 与 `db` 同样走独立进程:它们只读写文件,不需要 Next 工作区那一整套装配。
|
|
16
|
+
if (command === 'component' || command === 'pack') {
|
|
17
|
+
const child = (0, node_child_process_1.spawnSync)(process.execPath, [node_path_1.default.join(packageRoot, 'bin', 'component.cjs'), ...args], { cwd: process.cwd(), stdio: 'inherit', env: process.env });
|
|
18
|
+
process.exit(child.status === null ? 1 : child.status);
|
|
19
|
+
}
|
|
20
|
+
// `soma component eject|diff` 与 `soma pack init`(REQ-009 EC-1/2/3)。
|
|
21
|
+
// 与 db 同一分派方式:它们有自己的 bin,不走 soma-inline 的页面固化那条线。
|
|
22
|
+
if (command === 'component' || command === 'pack') {
|
|
23
|
+
const child = (0, node_child_process_1.spawnSync)(process.execPath, [node_path_1.default.join(packageRoot, 'bin', 'component.cjs'), command, ...args.slice(1)], { cwd: process.cwd(), stdio: 'inherit', env: process.env });
|
|
24
|
+
process.exit(child.status === null ? 1 : child.status);
|
|
25
|
+
}
|
|
14
26
|
if (command === 'db') {
|
|
15
27
|
const child = (0, node_child_process_1.spawnSync)(process.execPath, [node_path_1.default.join(packageRoot, 'bin', 'soma-db.cjs'), ...args.slice(1)], { cwd: process.cwd(), stdio: 'inherit', env: process.env });
|
|
16
28
|
process.exit(child.status === null ? 1 : child.status);
|
|
@@ -436,7 +448,7 @@ if (delegated.includes(command)) {
|
|
|
436
448
|
process.exit(child.status === null ? 1 : child.status);
|
|
437
449
|
}
|
|
438
450
|
if (!['dev', 'build', 'start'].includes(command)) {
|
|
439
|
-
console.error(`Usage: soma <dev|build|start|db|${delegated.join('|')}> [...args]`);
|
|
451
|
+
console.error(`Usage: soma <dev|build|start|db|component|pack|${delegated.join('|')}> [...args]`);
|
|
440
452
|
process.exit(1);
|
|
441
453
|
}
|
|
442
454
|
const nextBin = resolveNextBin();
|