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.
Files changed (121) hide show
  1. package/README.md +1 -1
  2. package/core/build/blocks/block-compile.ts +31 -2
  3. package/core/build/blocks/block-container.ts +2 -11
  4. package/core/build/compiler/page-declaration-compiler.ts +30 -2
  5. package/core/build/compiler/soma-precompile.js +2041 -19
  6. package/core/build/component/component-graph.ts +208 -0
  7. package/core/build/eject/component-eject.ts +473 -0
  8. package/core/build/eject/component-upgrade.ts +359 -0
  9. package/core/build/layout/constraint-solver.ts +235 -0
  10. package/core/build/layout/css-emitter.ts +116 -0
  11. package/core/build/layout/page-layout.ts +85 -0
  12. package/core/build/pack/pack-init.ts +265 -0
  13. package/core/client/base/SomaPageRootBase.ts +61 -0
  14. package/core/client/component/ai-catalog.ts +79 -4
  15. package/core/client/component/component-defaults.ts +100 -0
  16. package/core/client/component/component-definition.types.ts +39 -0
  17. package/core/client/component/component-manager.ts +79 -4
  18. package/core/client/component/component-pack.ts +126 -2
  19. package/core/client/component/keyboard-matrix.ts +144 -0
  20. package/core/client/component/pack-styles.ts +59 -1
  21. package/core/client/component/style-features.ts +131 -0
  22. package/core/client/component/theme-component-tokens.ts +83 -0
  23. package/core/client/data/data-object-resolver.ts +407 -4
  24. package/core/client/data/reaction-engine.ts +176 -0
  25. package/core/client/data/window-engine.ts +477 -0
  26. package/core/client/engine/event-engine.ts +98 -0
  27. package/core/client/engine/soma-bootstrap.ts +265 -5
  28. package/core/client/engine/step-runner.ts +134 -0
  29. package/core/client/parser/blocks/page-parser.ts +15 -1
  30. package/core/client/parser/blocks/use-parser.ts +5 -12
  31. package/core/client/parser/data-config-parser.ts +316 -8
  32. package/core/client/parser/duration.ts +16 -0
  33. package/core/client/parser/layout-parser.ts +157 -0
  34. package/core/client/parser/page-state-parser.ts +166 -0
  35. package/core/client/parser/pipeline-parser.ts +76 -1
  36. package/core/client/parser/reaction-parser.ts +459 -0
  37. package/core/client/parser/reaction-sugar.ts +47 -0
  38. package/core/client/parser/step-parser.ts +359 -0
  39. package/core/client/parser/ui-config-parser.ts +59 -0
  40. package/core/client/parser/window-parser.ts +294 -0
  41. package/core/client/theme/theme-engine.ts +102 -2
  42. package/core/index.ts +163 -0
  43. package/core/shared/block-errors.ts +11 -0
  44. package/core/shared/calc/coerce.ts +29 -0
  45. package/core/shared/calc/errors.ts +43 -0
  46. package/core/shared/calc/evaluator.ts +101 -0
  47. package/core/shared/calc/index.ts +12 -0
  48. package/core/shared/calc/lexer.ts +194 -0
  49. package/core/shared/calc/parser.ts +204 -0
  50. package/core/shared/calc/typer.ts +184 -0
  51. package/core/shared/path-algebra.ts +169 -0
  52. package/core/shared/predicates/index.ts +527 -0
  53. package/core/shared/types/component-contract.types.ts +128 -2
  54. package/core/shared/types/data-config.types.ts +120 -1
  55. package/core/shared/types/domain.types.ts +13 -0
  56. package/core/shared/types/event.types.ts +22 -2
  57. package/core/shared/types/layout-constraint.types.ts +73 -0
  58. package/core/shared/types/page-state.types.ts +60 -0
  59. package/core/shared/types/reaction.types.ts +144 -0
  60. package/core/shared/types/step.types.ts +91 -0
  61. package/core/shared/types/ui-config.types.ts +18 -0
  62. package/core/shared/types/window.types.ts +177 -0
  63. package/dist/cli/soma.js +13 -1
  64. package/dist/core/index.cjs +4684 -349
  65. package/dist/types/build/blocks/block-container.d.ts +1 -6
  66. package/dist/types/build/compiler/page-declaration-compiler.d.ts +2 -0
  67. package/dist/types/build/component/component-graph.d.ts +85 -0
  68. package/dist/types/build/eject/component-eject.d.ts +121 -0
  69. package/dist/types/build/eject/component-upgrade.d.ts +43 -0
  70. package/dist/types/build/layout/constraint-solver.d.ts +36 -0
  71. package/dist/types/build/layout/css-emitter.d.ts +18 -0
  72. package/dist/types/build/layout/page-layout.d.ts +24 -0
  73. package/dist/types/build/pack/pack-init.d.ts +8 -0
  74. package/dist/types/client/base/SomaPageRootBase.d.ts +28 -0
  75. package/dist/types/client/component/ai-catalog.d.ts +24 -1
  76. package/dist/types/client/component/component-defaults.d.ts +15 -0
  77. package/dist/types/client/component/component-definition.types.d.ts +38 -0
  78. package/dist/types/client/component/component-manager.d.ts +36 -0
  79. package/dist/types/client/component/component-pack.d.ts +32 -2
  80. package/dist/types/client/component/keyboard-matrix.d.ts +24 -0
  81. package/dist/types/client/component/pack-styles.d.ts +21 -0
  82. package/dist/types/client/component/style-features.d.ts +26 -0
  83. package/dist/types/client/component/theme-component-tokens.d.ts +14 -0
  84. package/dist/types/client/data/data-object-resolver.d.ts +106 -1
  85. package/dist/types/client/data/reaction-engine.d.ts +21 -0
  86. package/dist/types/client/data/window-engine.d.ts +27 -0
  87. package/dist/types/client/engine/event-engine.d.ts +15 -0
  88. package/dist/types/client/engine/soma-bootstrap.d.ts +70 -0
  89. package/dist/types/client/engine/step-runner.d.ts +24 -0
  90. package/dist/types/client/parser/blocks/use-parser.d.ts +2 -2
  91. package/dist/types/client/parser/duration.d.ts +1 -0
  92. package/dist/types/client/parser/layout-parser.d.ts +9 -0
  93. package/dist/types/client/parser/page-state-parser.d.ts +32 -0
  94. package/dist/types/client/parser/reaction-parser.d.ts +16 -0
  95. package/dist/types/client/parser/reaction-sugar.d.ts +13 -0
  96. package/dist/types/client/parser/step-parser.d.ts +23 -0
  97. package/dist/types/client/parser/ui-config-parser.d.ts +5 -0
  98. package/dist/types/client/parser/window-parser.d.ts +25 -0
  99. package/dist/types/client/theme/theme-engine.d.ts +26 -0
  100. package/dist/types/index.d.ts +32 -2
  101. package/dist/types/shared/block-errors.d.ts +5 -0
  102. package/dist/types/shared/calc/coerce.d.ts +4 -0
  103. package/dist/types/shared/calc/errors.d.ts +14 -0
  104. package/dist/types/shared/calc/evaluator.d.ts +2 -0
  105. package/dist/types/shared/calc/index.d.ts +6 -0
  106. package/dist/types/shared/calc/lexer.d.ts +20 -0
  107. package/dist/types/shared/calc/parser.d.ts +49 -0
  108. package/dist/types/shared/calc/typer.d.ts +16 -0
  109. package/dist/types/shared/path-algebra.d.ts +56 -0
  110. package/dist/types/shared/predicates/index.d.ts +79 -0
  111. package/dist/types/shared/types/component-contract.types.d.ts +112 -0
  112. package/dist/types/shared/types/data-config.types.d.ts +115 -1
  113. package/dist/types/shared/types/domain.types.d.ts +12 -0
  114. package/dist/types/shared/types/event.types.d.ts +8 -2
  115. package/dist/types/shared/types/layout-constraint.types.d.ts +52 -0
  116. package/dist/types/shared/types/page-state.types.d.ts +49 -0
  117. package/dist/types/shared/types/reaction.types.d.ts +115 -0
  118. package/dist/types/shared/types/step.types.d.ts +76 -0
  119. package/dist/types/shared/types/ui-config.types.d.ts +18 -0
  120. package/dist/types/shared/types/window.types.d.ts +171 -0
  121. package/package.json +2 -1
@@ -0,0 +1,184 @@
1
+ // calc 类型推导(REQ-010 S1a)——本层是 calc 存在的最大理由。
2
+ //
3
+ // JsonLogic 的 `var` 路径是自由字符串、Formily 的表达式在 `new Function` 里跑、
4
+ // amis 的 `${}` 沿运行时数据链求值——三家都**无法在声明期知道一个表达式算出来是什么类型**,
5
+ // 于是 `[amount] - [note]`(金额减备注)这种错只会在页面上显示成 `NaN`,
6
+ // 而且显示 NaN 的那一刻离写错的地方已经隔了很远。
7
+ //
8
+ // SOMA 的字段类型是字典里的封闭枚举,所以这件事可以在解析期做完:
9
+ // 每个节点推出类型,与字段声明的 `type` 对账,不配就当场点名到列号。
10
+ //
11
+ // ── 一条刻意的收紧 ────────────────────────────────────────────────────
12
+ // `date - date → number`(毫秒差)是有用的(算时长),但 `date + date` 无意义,
13
+ // `date * 2` 更无意义——所以日期的算术只开了「差」与「加减一个数」两扇门。
14
+
15
+ import { SomaCalcTypeError } from './errors';
16
+ import type { CalcAst } from './parser';
17
+
18
+ export type CalcType = 'number' | 'text' | 'bool' | 'date';
19
+
20
+ /**
21
+ * 字段类型 → calc 类型。
22
+ *
23
+ * 表里没有的字段类型**不可被引用**:`richtext` 引用进算式没有意义(它是一段 HTML),
24
+ * `image / file` 是资源标识,`tags / tree / cascade` 是集合或路径。
25
+ * 与其让它们悄悄按 text 参与拼接,不如直接拒绝并让作者换个字段。
26
+ */
27
+ const FIELD_TO_CALC: Readonly<Record<string, CalcType>> = {
28
+ int: 'number', float: 'number', money: 'number', percent: 'number', progress: 'number',
29
+ text: 'text', url: 'text', enum: 'text',
30
+ bool: 'bool',
31
+ date: 'date', datetime: 'date',
32
+ };
33
+
34
+ /** calc 类型 → 允许声明的字段类型(用于结果与 `type` 对账) */
35
+ const CALC_TO_FIELD: Readonly<Record<CalcType, readonly string[]>> = {
36
+ number: ['int', 'float', 'money', 'percent', 'progress'],
37
+ text: ['text', 'url', 'enum'],
38
+ bool: ['bool'],
39
+ date: ['date', 'datetime'],
40
+ };
41
+
42
+ export interface CalcTypeContext {
43
+ /** 字段名 → 字典里的 `type`(缺省视为 text,与字典本身的缺省一致) */
44
+ fieldTypes: Readonly<Record<string, string | undefined>>;
45
+ /** 原始表达式串,仅用于错误定位 */
46
+ source: string;
47
+ }
48
+
49
+ export function inferCalcType(ast: CalcAst, ctx: CalcTypeContext): CalcType {
50
+ return infer(ast, ctx);
51
+ }
52
+
53
+ function infer(node: CalcAst, ctx: CalcTypeContext): CalcType {
54
+ const bad: (message: string, expected: string, actual: string) => never = (message, expected, actual) => {
55
+ throw new SomaCalcTypeError(message, ctx.source, node.pos, expected, actual);
56
+ };
57
+
58
+ switch (node.k) {
59
+ case 'num': return 'number';
60
+ case 'str': return 'text';
61
+ case 'bool': return 'bool';
62
+ case 'date': return 'date';
63
+
64
+ case 'ref': {
65
+ const declared = ctx.fieldTypes[node.name];
66
+ if (declared === undefined && !(node.name in ctx.fieldTypes)) {
67
+ bad(`引用了不存在的字段 "${node.name}"`, '字典里的字段', '未声明');
68
+ }
69
+ const kind = FIELD_TO_CALC[declared ?? 'text'];
70
+ if (!kind) {
71
+ bad(
72
+ `字段 "${node.name}" 是 ${declared} 类型,不能参与计算`
73
+ + `(可引用的类型:${Object.keys(FIELD_TO_CALC).join(' / ')})`,
74
+ '可计算的字段类型', String(declared),
75
+ );
76
+ }
77
+ return kind;
78
+ }
79
+
80
+ case 'un': {
81
+ const inner = infer(node.arg, ctx);
82
+ if (inner !== 'number') bad('取负只能作用在数值上', 'number', inner);
83
+ return 'number';
84
+ }
85
+
86
+ case 'bin': {
87
+ const left = infer(node.left, ctx);
88
+ const right = infer(node.right, ctx);
89
+ switch (node.op) {
90
+ case '+': case '-': {
91
+ if (left === 'number' && right === 'number') return 'number';
92
+ if (node.op === '-' && left === 'date' && right === 'date') return 'number'; // 毫秒差
93
+ if (left === 'date' && right === 'number') return 'date'; // 日期 ± 天数(毫秒)
94
+ if (node.op === '+' && left === 'number' && right === 'date') return 'date';
95
+ // 建议要对得上运算符:对减法说「请用 CONCAT」是句错话,
96
+ // 作者照做只会得到第二个错误。只有 + 才可能是「想拼接」写错了。
97
+ if (node.op === '+' && (left === 'text' || right === 'text')) {
98
+ bad('文本不能用 + 拼接——请用 CONCAT(a, b)', 'number 或 date', `${left} 与 ${right}`);
99
+ }
100
+ return bad(`${node.op} 不能作用在 ${left} 与 ${right} 上`, 'number', `${left} 与 ${right}`);
101
+ }
102
+ case '*': case '/': {
103
+ if (left === 'number' && right === 'number') return 'number';
104
+ return bad(`${node.op} 只能作用在数值上`, 'number', `${left} 与 ${right}`);
105
+ }
106
+ case '>': case '>=': case '<': case '<=': {
107
+ if (left === right && (left === 'number' || left === 'date')) return 'bool';
108
+ return bad('比较大小只能在两个数值之间或两个日期之间', '同为 number 或同为 date', `${left} 与 ${right}`);
109
+ }
110
+ case '==': case '!=': {
111
+ if (left === right) return 'bool';
112
+ return bad('相等比较的两侧必须同型', left, right);
113
+ }
114
+ }
115
+ }
116
+
117
+ case 'call': {
118
+ switch (node.fn) {
119
+ case 'IF': {
120
+ const cond = infer(node.args[0], ctx);
121
+ if (cond !== 'bool') bad('IF 的第一个参数必须是判断(比较或布尔字段)', 'bool', cond);
122
+ const a = infer(node.args[1], ctx);
123
+ const b = infer(node.args[2], ctx);
124
+ if (a !== b) bad('IF 的两个分支必须同型', a, b);
125
+ return a;
126
+ }
127
+ case 'MIN': case 'MAX': {
128
+ const kinds = node.args.map((arg) => infer(arg, ctx));
129
+ const first = kinds[0];
130
+ if (first !== 'number' && first !== 'date') {
131
+ bad(`${node.fn} 只能作用在数值或日期上`, 'number 或 date', first);
132
+ }
133
+ const off = kinds.find((kind) => kind !== first);
134
+ if (off) bad(`${node.fn} 的参数必须同型`, first, off);
135
+ return first;
136
+ }
137
+ case 'ROUND': {
138
+ const value = infer(node.args[0], ctx);
139
+ if (value !== 'number') bad('ROUND 只能作用在数值上', 'number', value);
140
+ return 'number';
141
+ }
142
+ case 'ABS': {
143
+ const value = infer(node.args[0], ctx);
144
+ if (value !== 'number') bad('ABS 只能作用在数值上', 'number', value);
145
+ return 'number';
146
+ }
147
+ case 'CONCAT': {
148
+ node.args.forEach((arg) => infer(arg, ctx)); // 任意型,逐个求值即可(错在里面照样点名)
149
+ return 'text';
150
+ }
151
+ }
152
+ }
153
+ }
154
+ }
155
+
156
+ /**
157
+ * 与字段声明的 `type` 对账。
158
+ *
159
+ * 单独一个函数而不是塞进 `infer`:解析器可能被用在「只想知道类型」的场合
160
+ * (如 DW 的派生列预览),那时还没有目标字段。
161
+ */
162
+ export function assertCalcResultType(
163
+ result: CalcType,
164
+ declaredFieldType: string | undefined,
165
+ ctx: CalcTypeContext,
166
+ ast: CalcAst,
167
+ ): void {
168
+ const declared = declaredFieldType ?? 'text';
169
+ const allowed = CALC_TO_FIELD[result];
170
+ if (!allowed.includes(declared)) {
171
+ throw new SomaCalcTypeError(
172
+ `表达式算出来是 ${result},但字段声明的是 ${declared}`
173
+ + `(${result} 可以声明为:${allowed.join(' / ')})`,
174
+ ctx.source, ast.pos, allowed.join('|'), declared,
175
+ );
176
+ }
177
+ if (result === 'bool') {
178
+ throw new SomaCalcTypeError(
179
+ '派生列不能是判断结果——字段类型里没有「显示 true」这种业务语义;'
180
+ + '想按条件出不同文案请用 IF(条件, "A", "B")',
181
+ ctx.source, ast.pos, 'number|text|date', 'bool',
182
+ );
183
+ }
184
+ }
@@ -0,0 +1,169 @@
1
+ // 列表路径代数(REQ-010 F-11)——让一条反应作用在「每一项」上。
2
+ //
3
+ // ── 要解决的问题 ──────────────────────────────────────────────────────
4
+ // 明细行里的联动(「这一行选了折扣,这一行的折扣率就必填」)今天写不出来:
5
+ // 反应图的字段是**顶层**字段名,而明细行的字段住在 `items[3].discount` 这种位置上。
6
+ // 结果是列表内的联动只能回到组件里手写,而那正是反应图要消灭的东西。
7
+ //
8
+ // 三种形态,闭集:
9
+ //
10
+ // | 写法 | 意思 | 展开成 |
11
+ // |---|---|---|
12
+ // | `items[*].x` | 每一项的 x | 逐项一条,项数由运行期值决定 |
13
+ // | `items[..].x` | 同一项内的 x(在项作用域里写反应时用) | 当前项的 x |
14
+ // | `items[+1].x` | 下一项的 x(比如"结束日不能早于下一段的开始日") | 第 i+1 项 |
15
+ //
16
+ // 刻意**不做**的:分组(`items[status=paid].x`)、排除(`items[!0].x`)、
17
+ // 前缀匹配。它们都要求在展开期知道运行期的值,那等于把求值搬进编译期——
18
+ // 一旦开这个口,「这条反应会牵动谁」就重新变成一个运行期才有答案的问题,
19
+ // 而静态可回溯正是反应图存在的理由。
20
+
21
+ /** 三种形态的判别式 */
22
+ export type SomaPathSelector =
23
+ | { kind: 'each' } // [*]
24
+ | { kind: 'self' } // [..]
25
+ | { kind: 'offset'; delta: number }; // [+1] / [-1]
26
+
27
+ export interface SomaListPath {
28
+ /** 列表字段名(`items`) */
29
+ list: string;
30
+ selector: SomaPathSelector;
31
+ /** 项内字段名(`discount`);支持多级 `a.b` */
32
+ field: string;
33
+ /** 原样保留,报错时回指作者写的那串 */
34
+ source: string;
35
+ }
36
+
37
+ const PATH_PATTERN = /^([a-z][a-z0-9_]*)\[(\*|\.\.|[+-]\d+)\]\.([a-z][a-z0-9_.]*)$/i;
38
+
39
+ /** 一个引用是不是列表路径(不是的话按普通顶层字段处理) */
40
+ export function isListPath(reference: string): boolean {
41
+ return PATH_PATTERN.test(reference);
42
+ }
43
+
44
+ export class SomaPathError extends Error {
45
+ constructor(message: string) {
46
+ super(`[SOMA Path] ${message}`);
47
+ this.name = 'SomaPathError';
48
+ }
49
+ }
50
+
51
+ export function parseListPath(reference: string): SomaListPath {
52
+ const match = PATH_PATTERN.exec(reference);
53
+ if (!match) {
54
+ throw new SomaPathError(
55
+ `"${reference}" 不是合法的列表路径。三种形态:`
56
+ + '`items[*].x`(每一项)/ `items[..].x`(同一项)/ `items[+1].x`(下一项)。'
57
+ + '不支持分组、排除与前缀匹配——那些要在展开期知道运行期的值,'
58
+ + '等于把求值搬进编译期,而静态可回溯正是反应图存在的理由。',
59
+ );
60
+ }
61
+ const [, list, selectorRaw, field] = match;
62
+ let selector: SomaPathSelector;
63
+ if (selectorRaw === '*') selector = { kind: 'each' };
64
+ else if (selectorRaw === '..') selector = { kind: 'self' };
65
+ else {
66
+ const delta = Number(selectorRaw);
67
+ if (delta === 0) {
68
+ // `[+0]` 与 `[..]` 是同一件事,但写成两种会让读的人以为有区别
69
+ throw new SomaPathError(`"${reference}" 的偏移是 0——同一项请写 \`${list}[..].${field}\``);
70
+ }
71
+ selector = { kind: 'offset', delta };
72
+ }
73
+ return { list, selector, field, source: reference };
74
+ }
75
+
76
+ /**
77
+ * 展开成逐项的具体路径。
78
+ *
79
+ * `count` 是运行期的项数——展开发生在**每次求值前**而不是解析期:
80
+ * 项数会变(用户增删行),而解析期展开出来的模板会立刻过期。
81
+ * 解析期做的是**校验**(列表字段在不在字典里、项内字段在不在 `item_fields` 里),
82
+ * 那部分才是静态的。
83
+ *
84
+ * 越界的偏移(最后一项的 `[+1]`)产出 `null` 而不是抛:
85
+ * 「最后一段没有下一段」是正常的数据形态,不是错误。调用方按"读不到值"处理。
86
+ */
87
+ export function expandListPath(
88
+ path: SomaListPath,
89
+ count: number,
90
+ currentIndex?: number,
91
+ ): Array<{ index: number; path: string } | null> {
92
+ if (path.selector.kind === 'each') {
93
+ return Array.from({ length: Math.max(0, count) }, (_unused, index) => ({
94
+ index,
95
+ path: `${path.list}[${index}].${path.field}`,
96
+ }));
97
+ }
98
+ if (currentIndex === undefined) {
99
+ throw new SomaPathError(
100
+ `"${path.source}" 用了 ${path.selector.kind === 'self' ? '[..]' : '偏移'} 形态,`
101
+ + '但求值时没有"当前项"——这两种形态只能出现在项作用域里的反应上',
102
+ );
103
+ }
104
+ const target = path.selector.kind === 'self'
105
+ ? currentIndex
106
+ : currentIndex + path.selector.delta;
107
+ if (target < 0 || target >= count) return [null];
108
+ return [{ index: target, path: `${path.list}[${target}].${path.field}` }];
109
+ }
110
+
111
+ /**
112
+ * 从一份值里读列表路径指向的值。
113
+ *
114
+ * 读不到一律 `null`(不抛、不返回 undefined):反应图的求值面对的是**半填的表单**,
115
+ * 缺值是常态。抛的话,一个还没填到的明细行会炸掉整张表的联动。
116
+ */
117
+ export function readListPath(
118
+ values: Record<string, unknown>,
119
+ path: SomaListPath,
120
+ index: number,
121
+ ): unknown {
122
+ const list = values[path.list];
123
+ if (!Array.isArray(list)) return null;
124
+ const item = list[index];
125
+ if (item === null || typeof item !== 'object') return null;
126
+ let current: unknown = item;
127
+ for (const segment of path.field.split('.')) {
128
+ if (current === null || typeof current !== 'object') return null;
129
+ current = (current as Record<string, unknown>)[segment];
130
+ }
131
+ return current === undefined ? null : current;
132
+ }
133
+
134
+ /**
135
+ * 声明期校验:列表字段在不在字典里、它是不是 list、项内字段在不在 `item_fields` 里。
136
+ *
137
+ * 这三条是静态的,所以必须在声明期查完——留到运行期的话,一个拼错的项内字段名
138
+ * 只会让那条联动**永远不成立**,而"永远不成立"和"条件确实没满足"看不出区别。
139
+ */
140
+ export function validateListPath(
141
+ path: SomaListPath,
142
+ fields: Record<string, { type?: string; item_fields?: unknown }>,
143
+ ): string[] {
144
+ const issues: string[] = [];
145
+ const list = fields[path.list];
146
+ if (!list) {
147
+ issues.push(
148
+ `"${path.source}" 引用了不存在的字段 "${path.list}"`
149
+ + `(本对象字典:${Object.keys(fields).join(' / ') || '空'})`,
150
+ );
151
+ return issues;
152
+ }
153
+ if (String(list.type ?? '') !== 'list') {
154
+ issues.push(`"${path.source}" 的 "${path.list}" 不是 list 类型(是 ${list.type ?? '未声明'})`);
155
+ return issues;
156
+ }
157
+ const items = Array.isArray(list.item_fields) ? list.item_fields : [];
158
+ const known = items
159
+ .map((entry) => (entry !== null && typeof entry === 'object' ? String((entry as { key?: unknown }).key ?? '') : ''))
160
+ .filter((key) => key !== '');
161
+ const root = path.field.split('.')[0];
162
+ if (known.length > 0 && !known.includes(root)) {
163
+ issues.push(
164
+ `"${path.source}" 的项内字段 "${root}" 不在 ${path.list}.item_fields 里`
165
+ + `(可选:${known.join(' / ')})`,
166
+ );
167
+ }
168
+ return issues;
169
+ }