soma-core 1.4.0 → 1.4.1
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 +2041 -19
- package/core/build/component/component-graph.ts +208 -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 +265 -0
- package/core/client/base/SomaPageRootBase.ts +61 -0
- package/core/client/component/ai-catalog.ts +79 -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/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/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 +163 -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/path-algebra.ts +169 -0
- package/core/shared/predicates/index.ts +527 -0
- package/core/shared/types/component-contract.types.ts +128 -2
- 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 +4684 -349
- 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/SomaPageRootBase.d.ts +28 -0
- package/dist/types/client/component/ai-catalog.d.ts +24 -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/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 +32 -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/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 +112 -0
- 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 +2 -1
|
@@ -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();
|