soma-core 1.4.2 → 1.5.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/bin/component.cjs +240 -0
- package/bin/eject.cjs +174 -0
- package/bin/migrate.cjs +362 -0
- package/core/build/blocks/block-compile.ts +143 -17
- package/core/build/blocks/migrate-flat.ts +118 -25
- package/core/build/compiler/page-declaration-compiler.ts +149 -5
- package/core/build/compiler/route-builder.ts +0 -4
- package/core/build/compiler/soma-precompile.js +431 -26
- package/core/build/component/component-graph.ts +28 -105
- package/core/build/component/package-loader.ts +18 -4
- package/core/build/eject/component-eject.ts +8 -2
- package/core/build/layout/constraint-solver.ts +131 -16
- package/core/build/layout/css-emitter.ts +29 -10
- package/core/build/ooui/artifact/artifact.types.ts +275 -0
- package/core/build/ooui/artifact/emit-artifact.ts +269 -0
- package/core/build/ooui/artifact/emit-html.ts +204 -0
- package/core/build/ooui/artifact/index.ts +53 -0
- package/core/build/ooui/artifact/spatial-tree.ts +268 -0
- package/core/build/ooui/artifact/utility-class.ts +83 -0
- package/core/build/ooui/composition/candidate.types.ts +323 -0
- package/core/build/ooui/composition/control-model.ts +114 -0
- package/core/build/ooui/composition/registry.ts +520 -0
- package/core/build/ooui/composition/select.ts +232 -0
- package/core/build/ooui/diagnostics/codes.ts +230 -0
- package/core/build/ooui/diagnostics/error.ts +235 -0
- package/core/build/ooui/diagnostics/format.ts +106 -0
- package/core/build/ooui/diagnostics/index.ts +62 -0
- package/core/build/ooui/diagnostics/issue.types.ts +112 -0
- package/core/build/ooui/engine-slot.ts +184 -0
- package/core/build/ooui/index.ts +1427 -0
- package/core/build/ooui/intent/derive-intent.ts +450 -0
- package/core/build/ooui/intent/field-rules.ts +330 -0
- package/core/build/ooui/intent/intent.types.ts +476 -0
- package/core/build/ooui/intent/verb-events.ts +285 -0
- package/core/build/ooui/page/budget.ts +503 -0
- package/core/build/ooui/page/compose-page.ts +736 -0
- package/core/build/ooui/page/index.ts +66 -0
- package/core/build/ooui/page/page.types.ts +402 -0
- package/core/build/ooui/page/region-row.ts +241 -0
- package/core/build/ooui/semantic/expand-page-surface.ts +180 -0
- package/core/build/ooui/semantic/kernel.types.ts +187 -0
- package/core/build/ooui/semantic/normalize.ts +784 -0
- package/core/build/ooui/semantic/origin.types.ts +211 -0
- package/core/build/ooui/semantic/role-alias.ts +154 -0
- package/core/build/ooui/semantic/shorthand.ts +233 -0
- package/core/build/ooui/semantic/surface.types.ts +78 -0
- package/core/build/ooui/semantic/validate-request.ts +267 -0
- package/core/build/ooui/spatial/emit-utility.ts +480 -0
- package/core/build/ooui/spatial/ir.types.ts +443 -0
- package/core/build/ooui/spatial/registry.ts +565 -0
- package/core/build/ooui/spatial/solve.ts +769 -0
- package/core/build/ooui/spatial/utility.types.ts +242 -0
- package/core/build/ooui/trace/index.ts +40 -0
- package/core/build/ooui/trace/render.ts +190 -0
- package/core/build/ooui/trace/source.types.ts +69 -0
- package/core/build/ooui/trace/trace.types.ts +326 -0
- package/core/client/component/component-expander.ts +18 -3
- package/core/client/component/component-manager.ts +4 -0
- package/core/client/component/example-blocks.ts +1 -7
- package/core/client/component/theme-component-tokens.ts +12 -15
- package/core/client/component/verify-pack.ts +43 -0
- package/core/client/data/data-object-resolver.ts +27 -8
- package/core/client/diagnostics/telemetry-context.ts +0 -4
- package/core/client/engine/asset-resolver.ts +0 -1
- package/core/client/engine/event-engine.ts +7 -3
- package/core/client/engine/soma-bootstrap.ts +292 -34
- package/core/client/engine/style-binder.ts +0 -1
- package/core/client/infra/http/IHttpClient.ts +0 -6
- package/core/client/infra/http/SomaHttpService.ts +4 -1
- package/core/client/infra/notify/DomNotifyService.ts +1 -1
- package/core/client/infra/router/router-path.ts +0 -6
- package/core/client/parser/annotation-extractor.ts +1 -1
- package/core/client/parser/blocks/namespace.ts +30 -5
- package/core/client/parser/blocks/page-parser.ts +44 -1
- package/core/client/parser/blocks/use-parser.ts +266 -46
- package/core/client/parser/data-config-parser.ts +71 -3
- package/core/client/parser/layout-parser.ts +4 -3
- package/core/client/parser/reaction-parser.ts +0 -1
- package/core/client/parser/ui-config-parser.ts +212 -74
- package/core/client/theme/scene-tokens.ts +9 -3
- package/core/client/theme/theme-axes.ts +74 -16
- package/core/client/theme/theme-engine.ts +341 -70
- package/core/client/theme/tone-solver.ts +9 -8
- package/core/index.ts +24 -5
- package/core/server/api/load-host-service.ts +8 -2
- package/core/server/declaration-safety.ts +11 -0
- package/core/server/host/page-response-request.ts +0 -2
- package/core/server/host/published-page-artifact-cache.ts +244 -0
- package/core/server/host/published-page-assets.ts +44 -5
- package/core/server/mock/node/cli.mjs +0 -1
- package/core/server/mock/node/schema-generator.mjs +0 -1
- package/core/server/ooui.ts +34 -0
- package/core/server/page-assets.ts +8 -0
- package/core/server/page-declaration.ts +18 -0
- package/core/server/registry/asset-store.ts +327 -0
- package/core/server/registry/declaration-precompiler.ts +49 -6
- package/core/server/registry/index.ts +47 -1
- package/core/server/registry/page-registry-repository.ts +6 -2
- package/core/server/registry/page-registry-store.ts +133 -19
- package/core/server/registry/publish-asset-pin.ts +557 -0
- package/core/server/registry/services/pages/List.ts +15 -3
- package/core/server/registry/validation/compile-gate.ts +180 -8
- package/core/server/registry/validation/declaration-safety-scan.ts +113 -23
- package/core/shared/component/derive-sample.ts +201 -16
- package/core/shared/component/field-lines.ts +98 -8
- package/core/shared/container-breakpoints.ts +46 -0
- package/core/shared/object-semantics.ts +240 -0
- package/core/shared/ooui-declaration.ts +235 -0
- package/core/shared/types/component-contract.types.ts +7 -6
- package/core/shared/types/data-config.types.ts +95 -0
- package/core/shared/types/domain.types.ts +0 -24
- package/core/shared/types/engine.types.ts +0 -5
- package/core/shared/types/layout-constraint.types.ts +16 -0
- package/core/shared/types/ui-config.types.ts +163 -13
- package/dist/cli/soma.js +24 -11
- package/dist/core/index.cjs +1829 -1028
- package/dist/types/build/blocks/block-compile.d.ts +16 -1
- package/dist/types/build/blocks/migrate-flat.d.ts +17 -0
- package/dist/types/build/compiler/page-declaration-compiler.d.ts +46 -0
- package/dist/types/build/compiler/route-builder.d.ts +0 -1
- package/dist/types/build/component/component-graph.d.ts +17 -53
- package/dist/types/build/component/package-loader.d.ts +8 -1
- package/dist/types/build/layout/constraint-solver.d.ts +46 -4
- package/dist/types/build/ooui/artifact/artifact.types.d.ts +180 -0
- package/dist/types/build/ooui/artifact/emit-artifact.d.ts +58 -0
- package/dist/types/build/ooui/artifact/emit-html.d.ts +53 -0
- package/dist/types/build/ooui/artifact/index.d.ts +5 -0
- package/dist/types/build/ooui/artifact/spatial-tree.d.ts +48 -0
- package/dist/types/build/ooui/artifact/utility-class.d.ts +46 -0
- package/dist/types/build/ooui/composition/candidate.types.d.ts +206 -0
- package/dist/types/build/ooui/composition/control-model.d.ts +37 -0
- package/dist/types/build/ooui/composition/registry.d.ts +66 -0
- package/dist/types/build/ooui/composition/select.d.ts +63 -0
- package/dist/types/build/ooui/diagnostics/codes.d.ts +28 -0
- package/dist/types/build/ooui/diagnostics/error.d.ts +135 -0
- package/dist/types/build/ooui/diagnostics/format.d.ts +51 -0
- package/dist/types/build/ooui/diagnostics/index.d.ts +25 -0
- package/dist/types/build/ooui/diagnostics/issue.types.d.ts +56 -0
- package/dist/types/build/ooui/engine-slot.d.ts +41 -0
- package/dist/types/build/ooui/index.d.ts +286 -0
- package/dist/types/build/ooui/intent/derive-intent.d.ts +32 -0
- package/dist/types/build/ooui/intent/field-rules.d.ts +99 -0
- package/dist/types/build/ooui/intent/intent.types.d.ts +318 -0
- package/dist/types/build/ooui/intent/verb-events.d.ts +70 -0
- package/dist/types/build/ooui/page/budget.d.ts +28 -0
- package/dist/types/build/ooui/page/compose-page.d.ts +41 -0
- package/dist/types/build/ooui/page/index.d.ts +4 -0
- package/dist/types/build/ooui/page/page.types.d.ts +264 -0
- package/dist/types/build/ooui/page/region-row.d.ts +16 -0
- package/dist/types/build/ooui/semantic/expand-page-surface.d.ts +33 -0
- package/dist/types/build/ooui/semantic/kernel.types.d.ts +125 -0
- package/dist/types/build/ooui/semantic/normalize.d.ts +45 -0
- package/dist/types/build/ooui/semantic/origin.types.d.ts +95 -0
- package/dist/types/build/ooui/semantic/role-alias.d.ts +35 -0
- package/dist/types/build/ooui/semantic/shorthand.d.ts +60 -0
- package/dist/types/build/ooui/semantic/surface.types.d.ts +16 -0
- package/dist/types/build/ooui/semantic/validate-request.d.ts +19 -0
- package/dist/types/build/ooui/spatial/emit-utility.d.ts +43 -0
- package/dist/types/build/ooui/spatial/ir.types.d.ts +280 -0
- package/dist/types/build/ooui/spatial/registry.d.ts +110 -0
- package/dist/types/build/ooui/spatial/solve.d.ts +42 -0
- package/dist/types/build/ooui/spatial/utility.types.d.ts +191 -0
- package/dist/types/build/ooui/trace/index.d.ts +3 -0
- package/dist/types/build/ooui/trace/render.d.ts +42 -0
- package/dist/types/build/ooui/trace/source.types.d.ts +25 -0
- package/dist/types/build/ooui/trace/trace.types.d.ts +143 -0
- package/dist/types/client/component/component-expander.d.ts +1 -0
- package/dist/types/client/component/example-blocks.d.ts +0 -2
- package/dist/types/client/component/theme-component-tokens.d.ts +8 -5
- package/dist/types/client/data/data-object-resolver.d.ts +10 -2
- package/dist/types/client/diagnostics/telemetry-context.d.ts +0 -1
- package/dist/types/client/engine/soma-bootstrap.d.ts +123 -10
- package/dist/types/client/infra/http/IHttpClient.d.ts +0 -5
- package/dist/types/client/infra/http/SomaHttpService.d.ts +1 -1
- package/dist/types/client/infra/router/router-path.d.ts +0 -2
- package/dist/types/client/parser/blocks/namespace.d.ts +20 -0
- package/dist/types/client/parser/blocks/page-parser.d.ts +9 -0
- package/dist/types/client/parser/blocks/use-parser.d.ts +38 -4
- package/dist/types/client/parser/data-config-parser.d.ts +13 -0
- package/dist/types/client/parser/ui-config-parser.d.ts +1 -11
- package/dist/types/client/theme/scene-tokens.d.ts +9 -3
- package/dist/types/client/theme/theme-axes.d.ts +64 -1
- package/dist/types/client/theme/theme-engine.d.ts +13 -8
- package/dist/types/client/theme/tone-solver.d.ts +9 -5
- package/dist/types/index.d.ts +4 -6
- package/dist/types/server/declaration-safety.d.ts +7 -0
- package/dist/types/server/host/page-response-request.d.ts +0 -1
- package/dist/types/server/host/published-page-artifact-cache.d.ts +64 -0
- package/dist/types/server/ooui.d.ts +18 -0
- package/dist/types/server/page-assets.d.ts +7 -0
- package/dist/types/server/page-declaration.d.ts +14 -0
- package/dist/types/server/registry/asset-store.d.ts +112 -0
- package/dist/types/server/registry/declaration-precompiler.d.ts +23 -3
- package/dist/types/server/registry/index.d.ts +3 -1
- package/dist/types/server/registry/page-registry-store.d.ts +57 -4
- package/dist/types/server/registry/publish-asset-pin.d.ts +166 -0
- package/dist/types/server/registry/services/pages/List.d.ts +9 -3
- package/dist/types/server/registry/validation/compile-gate.d.ts +63 -0
- package/dist/types/shared/component/derive-sample.d.ts +14 -0
- package/dist/types/shared/container-breakpoints.d.ts +42 -0
- package/dist/types/shared/object-semantics.d.ts +42 -0
- package/dist/types/shared/ooui-declaration.d.ts +135 -0
- package/dist/types/shared/types/component-contract.types.d.ts +7 -6
- package/dist/types/shared/types/data-config.types.d.ts +86 -0
- package/dist/types/shared/types/domain.types.d.ts +0 -21
- package/dist/types/shared/types/engine.types.d.ts +0 -4
- package/dist/types/shared/types/layout-constraint.types.d.ts +1 -0
- package/dist/types/shared/types/ui-config.types.d.ts +157 -12
- package/next.config.js +106 -13
- package/package.json +29 -2
- package/core/client/host-bridge/index.ts +0 -27
- package/core/client/parser/yaml-loader.ts +0 -36
- package/core/shared/manifest/manifest-contract.ts +0 -12
- package/dist/types/client/host-bridge/index.d.ts +0 -9
- package/dist/types/client/parser/yaml-loader.d.ts +0 -21
- package/dist/types/shared/manifest/manifest-contract.d.ts +0 -4
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
// 意图层 ② · 字段级意图规则表。§31 实测的那 30 条,按维度分派而非按组合枚举。
|
|
2
|
+
//
|
|
3
|
+
// ── 为什么这一层的失败模式是静默的 ─────────────────────────────────
|
|
4
|
+
// ① **同序并列时取第一条**。`rules.filter(match).sort(order)[0]` 是最自然的写法,
|
|
5
|
+
// 而它把"两条规则都说了话"这件事**吃掉**:结果取决于书写顺序,
|
|
6
|
+
// 书写顺序会在任何一次"把相关规则挪到一起"的整理里改变。
|
|
7
|
+
// 表现是同一类字段今天渲染成标签、明天渲染成纯文本——**两种都是合法呈现**,
|
|
8
|
+
// 没有一条测试会红,没有一个用户会报。§3.2 因此明令冲突要报错。
|
|
9
|
+
//
|
|
10
|
+
// ② **规则从"按维度分派"滑成"按组合枚举"**。滑的那一刻不报错,
|
|
11
|
+
// 只是规则表从 30 条长到 300 条,而每一条单看都合理。
|
|
12
|
+
// §31.2 的实测结论是规则数应当是各维度基数之**和**(17 型 + 7 角色 + 3 信号),
|
|
13
|
+
// 不是之积。本文件用两个形状把它焊死:
|
|
14
|
+
// 主分派是纯数据描述符(谓词写不进来,见 `intent.types.ts` 的 `SomaFieldDispatch`),
|
|
15
|
+
// 基数/可变性/重要度是**规则内部的参数**,不产生新规则。
|
|
16
|
+
// §36.1 裁定 1 落地时当场验证了这条:`w-enum-few` 与 `w-enum-many`
|
|
17
|
+
// 合并成一条,因为它们的差别(分段 vs 下拉)恰恰是被裁定移出意图层的那件事,
|
|
18
|
+
// 而"少候选还是多候选"落进 `cardinality` 参数——**表反而变短了**。
|
|
19
|
+
//
|
|
20
|
+
// ③ **信号正则互相交叠**。`owner_id` 同时像人名(`owner`)又像编号(`_id$`)。
|
|
21
|
+
// 原型在 1244 个真实字段上跑出 0.00% 冲突,但那是**样本没撞上**,不是不会撞。
|
|
22
|
+
// 对策不是等它撞,是把三个信号的 order 拉开成一次性裁决(见 SIGNAL_ORDER 注释)。
|
|
23
|
+
//
|
|
24
|
+
// ④ **信号匹配错对象**。信号要匹配字段**键**(`fields` 的键名),
|
|
25
|
+
// 不是 `SomaField.name`——后者是业务名称(「订单号」)。
|
|
26
|
+
// 拿中文标签去撞英文正则永远撞不上,表现是所有字段都走兜底呈现,不报错。
|
|
27
|
+
|
|
28
|
+
import type {
|
|
29
|
+
SomaDataFieldType,
|
|
30
|
+
} from '../../../shared/types/data-config.types';
|
|
31
|
+
import {
|
|
32
|
+
SOMA_DATA_FIELD_TYPE_ALIASES,
|
|
33
|
+
} from '../../../shared/types/data-config.types';
|
|
34
|
+
import type { SomaObjectRoles } from '../semantic/kernel.types';
|
|
35
|
+
import type {
|
|
36
|
+
SomaFieldNameSignal,
|
|
37
|
+
SomaIntentFieldRule,
|
|
38
|
+
} from './intent.types';
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 字段的分派视图:规则匹配只看这几样,**全是字段自身的性质**。
|
|
42
|
+
*
|
|
43
|
+
* 刻意不含对象、不含动词、不含谓词求值结果:
|
|
44
|
+
* 一旦匹配函数能看见对象,就有人会写"这个对象叫 order 时特殊处理",
|
|
45
|
+
* 而那条规则在别的对象上永远不命中,也永远不会有人发现它是死规则。
|
|
46
|
+
*/
|
|
47
|
+
export interface SomaFieldView {
|
|
48
|
+
/** 字段**键**(`fields` 的键名),信号匹配的对象 */
|
|
49
|
+
key: string;
|
|
50
|
+
/** 归一后的字段类型(别名已展开;缺省 `text`) */
|
|
51
|
+
type: SomaDataFieldType;
|
|
52
|
+
/** 这次交互里它可不可写(= 写动词 && `permission: w` && 非派生) */
|
|
53
|
+
mutable: boolean;
|
|
54
|
+
/** 承担的语义位 */
|
|
55
|
+
role?: keyof SomaObjectRoles;
|
|
56
|
+
/** 修饰哪个字段;有值即"不独立成格" */
|
|
57
|
+
modifierOf?: string;
|
|
58
|
+
/** 枚举候选数;未声明候选(含 `options: { from }` 动态换源)为 `undefined` */
|
|
59
|
+
optionCount?: number;
|
|
60
|
+
/** 有没有 `required` 规则(决定重要度,不参与匹配) */
|
|
61
|
+
required: boolean;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 三个字段名信号的正则。**在这里集中一份**,规则表里只写信号名。
|
|
66
|
+
*
|
|
67
|
+
* 来源是 §31 原型 `field-rules.mjs` 实测过的三条,逐字保留:
|
|
68
|
+
* 换掉其中任何一条都会让 §31 那组数字(30 条 / 0 冲突 / 15 种呈现)失去可比性。
|
|
69
|
+
*/
|
|
70
|
+
const SIGNAL_PATTERNS: Readonly<Record<SomaFieldNameSignal, RegExp>> = {
|
|
71
|
+
'code-like': /_no$|_code$|_id$|^id$|hash|sku/,
|
|
72
|
+
person: /assignee|owner|requester|buyer|author|user|contact|by$/,
|
|
73
|
+
'long-text': /summary|description|reason|note|remark|comment/,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 三个信号的 order **各不相同**,这是一次性裁决,不是随手排的。
|
|
78
|
+
*
|
|
79
|
+
* 判据是"信号的格式确定性":
|
|
80
|
+
* · `code-like` 最强——`_no` / `_code` / `sku` 是**格式**约定,字段真的是等宽编号;
|
|
81
|
+
* · `person` 次之——`owner` / `by` 是**语义**约定,多数时候确实是人;
|
|
82
|
+
* · `long-text` 最弱——`note` / `comment` 只说明**话题**,字段本身可能很短。
|
|
83
|
+
* 拉开之后 `owner_id`(两条都像)落到 `code-like`,是确定的答案而不是冲突;
|
|
84
|
+
* 同序并列的话它每次都会红,而它是个完全正常的字段名。
|
|
85
|
+
*/
|
|
86
|
+
const SIGNAL_ORDER: Readonly<Record<SomaFieldNameSignal, number>> = {
|
|
87
|
+
'code-like': 43,
|
|
88
|
+
person: 44,
|
|
89
|
+
'long-text': 45,
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 内置字段级意图规则表:**30 条**。
|
|
94
|
+
*
|
|
95
|
+
* 结构(§31.2 的分派而非枚举):
|
|
96
|
+
* ```
|
|
97
|
+
* 角色特例 4 条(status / title / amount / id,只在只读侧)
|
|
98
|
+
* 修饰并入 1 条
|
|
99
|
+
* 可写路径 9 条(按 type 分派)
|
|
100
|
+
* 只读路径 15 条(12 条按 type + 3 条按信号)
|
|
101
|
+
* 兜底 1 条
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* 与原型 `field-rules.mjs` 的四处差别,每一处都有出处:
|
|
105
|
+
* 1. `w-enum-few` / `w-enum-many` 合并成 `w-enum`——§36.1 裁定 1
|
|
106
|
+
* (`picker` 不进封闭集;少候选还是多候选落进 `cardinality` 参数);
|
|
107
|
+
* 2. `w-tree` 从 `picker` 改成 `single-choice`——同上;
|
|
108
|
+
* 树选还是级联选是控件形态,构件层从 `object.fields[key].type` 自己看得见;
|
|
109
|
+
* 3. **删掉 `calc-readonly` 规则**——派生恒只读这件事由 `mutable` 的计算承担
|
|
110
|
+
* (见 `derive-intent.ts` 的 `fieldMutable`)。留着它反而更坏:
|
|
111
|
+
* 它把 `calc` 的金额字段压成 `display/plain`,丢掉 `amount` 呈现;
|
|
112
|
+
* 4. 四条角色规则补 `mutable: false`——原型给全部字段硬写 `w: false`
|
|
113
|
+
* (§34.2 记在案的那处),所以"可写的状态字段该长什么样"一次都没被问到。
|
|
114
|
+
* 不补的话,`verb: edit` 下一个 `permission: w` 的状态字段会被压成只读标签,
|
|
115
|
+
* 表单上那一格点不动,而它看起来像"设计如此"。
|
|
116
|
+
* 新增 `r-file` / `r-tree` 两条只读规则同理:原型的只读路径漏了这两型,
|
|
117
|
+
* 它们会掉进兜底 `display/plain`,附件列表渲染成一行文件名字符串。
|
|
118
|
+
*/
|
|
119
|
+
export const SOMA_INTENT_FIELD_RULES: readonly SomaIntentFieldRule[] = [
|
|
120
|
+
// ── 角色特例:角色覆盖类型,但**不覆盖可变性**(可写的状态字段仍要能改) ──
|
|
121
|
+
{ name: 'role-status', order: 10, on: { role: 'status', mutable: false }, outcome: { kind: 'form', form: 'display', variant: 'status' } },
|
|
122
|
+
{ name: 'role-title', order: 10, on: { role: 'title', mutable: false }, outcome: { kind: 'form', form: 'display', variant: 'title' } },
|
|
123
|
+
{ name: 'role-amount', order: 10, on: { role: 'amount', mutable: false }, outcome: { kind: 'form', form: 'display', variant: 'amount' } },
|
|
124
|
+
{ name: 'role-id', order: 10, on: { role: 'id', mutable: false }, outcome: { kind: 'form', form: 'display', variant: 'mono' } },
|
|
125
|
+
|
|
126
|
+
// ── 修饰字段:并入被修饰者,不独立成形态(§15.3 缺口 1) ──
|
|
127
|
+
{ name: 'modifier', order: 15, on: { modifier: true }, outcome: { kind: 'merge' } },
|
|
128
|
+
|
|
129
|
+
// ── 可写路径:按 type 分派 ──
|
|
130
|
+
{ name: 'w-bool', order: 30, on: { mutable: true, type: ['bool'] }, outcome: { kind: 'form', form: 'toggle' } },
|
|
131
|
+
{ name: 'w-enum', order: 30, on: { mutable: true, type: ['enum'] }, outcome: { kind: 'form', form: 'single-choice' } },
|
|
132
|
+
{ name: 'w-tree', order: 30, on: { mutable: true, type: ['tree', 'cascade'] }, outcome: { kind: 'form', form: 'single-choice' } },
|
|
133
|
+
{ name: 'w-tags', order: 30, on: { mutable: true, type: ['tags'] }, outcome: { kind: 'form', form: 'multi-choice' } },
|
|
134
|
+
{ name: 'w-temporal', order: 30, on: { mutable: true, type: ['date', 'datetime'] }, outcome: { kind: 'form', form: 'temporal-entry' } },
|
|
135
|
+
{ name: 'w-number', order: 30, on: { mutable: true, type: ['int', 'float', 'money', 'percent', 'progress'] }, outcome: { kind: 'form', form: 'numeric-entry' } },
|
|
136
|
+
{ name: 'w-rich', order: 30, on: { mutable: true, type: ['richtext'] }, outcome: { kind: 'form', form: 'rich-entry' } },
|
|
137
|
+
{ name: 'w-file', order: 30, on: { mutable: true, type: ['file', 'image'] }, outcome: { kind: 'form', form: 'file-entry' } },
|
|
138
|
+
{ name: 'w-text', order: 39, on: { mutable: true }, outcome: { kind: 'form', form: 'text-entry' } },
|
|
139
|
+
|
|
140
|
+
// ── 只读路径:先按 type,再按信号 ──
|
|
141
|
+
{ name: 'r-bool', order: 40, on: { type: ['bool'] }, outcome: { kind: 'form', form: 'display', variant: 'boolean' } },
|
|
142
|
+
{ name: 'r-enum', order: 40, on: { type: ['enum'] }, outcome: { kind: 'form', form: 'display', variant: 'tag' } },
|
|
143
|
+
{ name: 'r-money', order: 40, on: { type: ['money'] }, outcome: { kind: 'form', form: 'display', variant: 'amount' } },
|
|
144
|
+
{ name: 'r-meter', order: 40, on: { type: ['percent', 'progress'] }, outcome: { kind: 'form', form: 'display', variant: 'meter' } },
|
|
145
|
+
{ name: 'r-temporal', order: 40, on: { type: ['date', 'datetime'] }, outcome: { kind: 'form', form: 'display', variant: 'time' } },
|
|
146
|
+
{ name: 'r-image', order: 40, on: { type: ['image'] }, outcome: { kind: 'form', form: 'display', variant: 'media' } },
|
|
147
|
+
{ name: 'r-file', order: 40, on: { type: ['file'] }, outcome: { kind: 'form', form: 'display', variant: 'media' } },
|
|
148
|
+
{ name: 'r-url', order: 40, on: { type: ['url'] }, outcome: { kind: 'form', form: 'display', variant: 'link' } },
|
|
149
|
+
{ name: 'r-number', order: 40, on: { type: ['int', 'float'] }, outcome: { kind: 'form', form: 'display', variant: 'number' } },
|
|
150
|
+
{ name: 'r-rich', order: 40, on: { type: ['richtext'] }, outcome: { kind: 'form', form: 'display', variant: 'prose' } },
|
|
151
|
+
{ name: 'r-tags', order: 40, on: { type: ['tags'] }, outcome: { kind: 'form', form: 'display', variant: 'tags' } },
|
|
152
|
+
{ name: 'r-tree', order: 40, on: { type: ['tree', 'cascade'] }, outcome: { kind: 'form', form: 'display', variant: 'path' } },
|
|
153
|
+
{ name: 'r-code-like', order: SIGNAL_ORDER['code-like'], on: { signal: 'code-like' }, outcome: { kind: 'form', form: 'display', variant: 'mono' } },
|
|
154
|
+
{ name: 'r-person', order: SIGNAL_ORDER.person, on: { signal: 'person' }, outcome: { kind: 'form', form: 'display', variant: 'person' } },
|
|
155
|
+
{ name: 'r-long-text', order: SIGNAL_ORDER['long-text'], on: { signal: 'long-text' }, outcome: { kind: 'form', form: 'display', variant: 'prose' } },
|
|
156
|
+
|
|
157
|
+
// ── 兜底:**唯一**一条空描述符的规则,且必须是 order 最大的那条(注册期自检) ──
|
|
158
|
+
{ name: 'r-fallback', order: 99, on: {}, outcome: { kind: 'form', form: 'display', variant: 'plain' } },
|
|
159
|
+
];
|
|
160
|
+
|
|
161
|
+
/** 把字段类型归一到唯一真源的词汇(`number` → `float`;缺省 `text`) */
|
|
162
|
+
export function normalizeFieldType(raw: string | undefined): SomaDataFieldType {
|
|
163
|
+
if (!raw) return 'text';
|
|
164
|
+
return SOMA_DATA_FIELD_TYPE_ALIASES[raw] ?? (raw as SomaDataFieldType);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** 一条规则的主分派匹不匹配。**纯数据比较**,没有函数可执行 */
|
|
168
|
+
function dispatchMatches(rule: SomaIntentFieldRule, view: SomaFieldView): boolean {
|
|
169
|
+
const on = rule.on;
|
|
170
|
+
if (on.role !== undefined && on.role !== view.role) return false;
|
|
171
|
+
if (on.type !== undefined && !on.type.includes(view.type)) return false;
|
|
172
|
+
if (on.mutable !== undefined && on.mutable !== view.mutable) return false;
|
|
173
|
+
if (on.modifier !== undefined && on.modifier !== (view.modifierOf !== undefined)) return false;
|
|
174
|
+
if (on.signal !== undefined && SIGNAL_PATTERNS[on.signal].test(view.key) === false) return false;
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** 规则裁决结果:命中一条 / 同序并列(错误)/ 一条都没命中(错误) */
|
|
179
|
+
export type SomaRuleVerdict =
|
|
180
|
+
| { kind: 'hit'; rule: SomaIntentFieldRule }
|
|
181
|
+
| { kind: 'conflict'; order: number; rules: readonly string[] }
|
|
182
|
+
| { kind: 'none' };
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* 挑出这个字段该走哪条规则。
|
|
186
|
+
*
|
|
187
|
+
* **同序并列一律判冲突,不取第一条**(§3.2 失败模式)——
|
|
188
|
+
* 哪怕两条规则给出的形态恰好相同也判冲突:形态相同只是今天相同,
|
|
189
|
+
* 而"两条规则都认领了同一类字段"这件事本身就是表写坏了,
|
|
190
|
+
* 等到有人改其中一条的 outcome 时,坏法会变成静默的呈现漂移。
|
|
191
|
+
*
|
|
192
|
+
* `predicates` 是对象**已声明**的命名谓词名集合。规则的 `when` 只查声明存在性,
|
|
193
|
+
* **不求值**——谓词的真假要数据,编译期求值等于把一个动态判断当成静态事实。
|
|
194
|
+
*/
|
|
195
|
+
export function resolveFieldRule(
|
|
196
|
+
view: SomaFieldView,
|
|
197
|
+
rules: readonly SomaIntentFieldRule[],
|
|
198
|
+
predicates: ReadonlySet<string>,
|
|
199
|
+
): SomaRuleVerdict {
|
|
200
|
+
const applicable = rules.filter((rule) => {
|
|
201
|
+
if (rule.when !== undefined && !predicates.has(rule.when.ref)) return false;
|
|
202
|
+
return dispatchMatches(rule, view);
|
|
203
|
+
});
|
|
204
|
+
if (applicable.length === 0) return { kind: 'none' };
|
|
205
|
+
|
|
206
|
+
let best = applicable[0].order;
|
|
207
|
+
for (const rule of applicable) if (rule.order < best) best = rule.order;
|
|
208
|
+
const top = applicable.filter((rule) => rule.order === best);
|
|
209
|
+
if (top.length > 1) {
|
|
210
|
+
return { kind: 'conflict', order: best, rules: top.map((rule) => rule.name) };
|
|
211
|
+
}
|
|
212
|
+
return { kind: 'hit', rule: top[0] };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// ── 规则表自检(新增闸门三件套的"判据自检"与"扫描面非空自检") ──────
|
|
216
|
+
|
|
217
|
+
/** 自检扫过的维度矩阵规模,随 issues 一起返回,防止"零条也算通过" */
|
|
218
|
+
export interface SomaIntentRuleAudit {
|
|
219
|
+
issues: string[];
|
|
220
|
+
/** 规则条数 */
|
|
221
|
+
rules: number;
|
|
222
|
+
/** 扫描面:合成的字段视图数 */
|
|
223
|
+
swept: number;
|
|
224
|
+
/** 扫描面里命中兜底的比例(诊断用,**不是**判据——§31.3 那次指标设计错误) */
|
|
225
|
+
fallbackHits: number;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const ALL_TYPES: readonly SomaDataFieldType[] = [
|
|
229
|
+
'text', 'int', 'float', 'money', 'bool', 'enum', 'date', 'datetime',
|
|
230
|
+
'image', 'url', 'richtext', 'percent', 'progress', 'tags', 'file', 'tree', 'cascade',
|
|
231
|
+
];
|
|
232
|
+
const ALL_ROLES: readonly (keyof SomaObjectRoles | undefined)[] = [
|
|
233
|
+
undefined, 'id', 'title', 'subtitle', 'status', 'timestamp', 'amount', 'baseline',
|
|
234
|
+
];
|
|
235
|
+
/** 合成键:三个信号各一个代表 + 一个都不像的 + 一个**两个信号都像**的对撞样本 */
|
|
236
|
+
const PROBE_KEYS: readonly string[] = ['plain_field', 'order_no', 'owner', 'note', 'owner_id'];
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* 规则表自检:**表本身对不对**,与扫到什么无关。
|
|
240
|
+
*
|
|
241
|
+
* 三件套在这里的落点:
|
|
242
|
+
* · 扫描面非空自检——规则为空、或合成矩阵为空,直接判红(否则"0 冲突"是空转出来的);
|
|
243
|
+
* · 判据自检——用合成的全维度矩阵跑一遍裁决,同序冲突与无规则命中都当场报出;
|
|
244
|
+
* · 只减不增——`SOMA_INTENT_FIELD_RULES` 的条数与结构由测试钉住,
|
|
245
|
+
* 加规则要改测试里的期望,是一次会被看见的改动。
|
|
246
|
+
*/
|
|
247
|
+
export function verifyIntentRules(
|
|
248
|
+
rules: readonly SomaIntentFieldRule[] = SOMA_INTENT_FIELD_RULES,
|
|
249
|
+
): SomaIntentRuleAudit {
|
|
250
|
+
const issues: string[] = [];
|
|
251
|
+
|
|
252
|
+
if (rules.length === 0) {
|
|
253
|
+
issues.push('规则表为空:没有任何规则时"零冲突/全覆盖"都是空转出来的结论。');
|
|
254
|
+
return { issues, rules: 0, swept: 0, fallbackHits: 0 };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// 结构约束
|
|
258
|
+
const seen = new Set<string>();
|
|
259
|
+
const emptyDispatch: SomaIntentFieldRule[] = [];
|
|
260
|
+
const maxOrder = Math.max(...rules.map((rule) => rule.order));
|
|
261
|
+
for (const rule of rules) {
|
|
262
|
+
if (seen.has(rule.name)) issues.push(`规则名重复:${rule.name}(错误消息里指名道姓的那个名字必须唯一)`);
|
|
263
|
+
seen.add(rule.name);
|
|
264
|
+
|
|
265
|
+
const on = rule.on;
|
|
266
|
+
const dims = [on.role, on.type, on.mutable, on.signal, on.modifier].filter((v) => v !== undefined).length;
|
|
267
|
+
if (dims === 0) emptyDispatch.push(rule);
|
|
268
|
+
if (dims === 0 && rule.order !== maxOrder) {
|
|
269
|
+
issues.push(`规则 ${rule.name} 的主分派为空却不是 order 最大的那条:空描述符匹配一切,排在前面会把它后面的规则全部屏蔽。`);
|
|
270
|
+
}
|
|
271
|
+
if (rule.when !== undefined && dims === 0) {
|
|
272
|
+
issues.push(
|
|
273
|
+
`规则 ${rule.name} 只有 when 没有 on:谓词成了主分派。`
|
|
274
|
+
+ '§31.4 立的规矩是谓词只能作为前置——只按谓词分派会让规则表按业务组合枚举,'
|
|
275
|
+
+ '规模从各维度基数之和变成之积。',
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
if (rule.outcome.kind === 'form') {
|
|
279
|
+
const { form, variant } = rule.outcome;
|
|
280
|
+
if (form === 'display' && variant === undefined) {
|
|
281
|
+
issues.push(
|
|
282
|
+
`规则 ${rule.name} 产出无 variant 的 display:§36.1 裁定 2 不补通用 Text 原子件,`
|
|
283
|
+
+ 'display 必须带 variant 才有真实组件接得住,否则那一格会静默渲染成空。',
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
if (form !== 'display' && variant !== undefined) {
|
|
287
|
+
issues.push(`规则 ${rule.name} 给非 display 形态带了 variant:variant 是 display 的呈现细分,别处没有消费方。`);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
if (emptyDispatch.length > 1) {
|
|
292
|
+
issues.push(`有 ${emptyDispatch.length} 条空描述符规则(${emptyDispatch.map((r) => r.name).join('、')}):兜底只能有一条,多于一条必然同序或互相屏蔽。`);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// 判据自检:合成全维度矩阵,跑一遍真实裁决
|
|
296
|
+
let swept = 0;
|
|
297
|
+
let fallbackHits = 0;
|
|
298
|
+
const conflicts: string[] = [];
|
|
299
|
+
const uncovered: string[] = [];
|
|
300
|
+
for (const type of ALL_TYPES) {
|
|
301
|
+
for (const role of ALL_ROLES) {
|
|
302
|
+
for (const mutable of [false, true]) {
|
|
303
|
+
for (const key of PROBE_KEYS) {
|
|
304
|
+
swept += 1;
|
|
305
|
+
const view: SomaFieldView = { key, type, mutable, role, required: false };
|
|
306
|
+
const verdict = resolveFieldRule(view, rules, new Set());
|
|
307
|
+
if (verdict.kind === 'conflict') {
|
|
308
|
+
const line = `${key}/${type}/${mutable ? 'w' : 'r'}/${role ?? '-'} → ${verdict.rules.join(' vs ')}(order ${verdict.order})`;
|
|
309
|
+
if (conflicts.length < 5) conflicts.push(line);
|
|
310
|
+
} else if (verdict.kind === 'none') {
|
|
311
|
+
if (uncovered.length < 5) uncovered.push(`${key}/${type}/${mutable ? 'w' : 'r'}/${role ?? '-'}`);
|
|
312
|
+
} else if (verdict.rule.outcome.kind === 'form' && verdict.rule.name === 'r-fallback') {
|
|
313
|
+
fallbackHits += 1;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (swept === 0) {
|
|
320
|
+
issues.push('自检矩阵为空:ALL_TYPES / ALL_ROLES / PROBE_KEYS 里有一处成了空数组,本次自检什么都没查。');
|
|
321
|
+
}
|
|
322
|
+
if (conflicts.length) {
|
|
323
|
+
issues.push(`同序并列命中 ${conflicts.length}${conflicts.length >= 5 ? '+' : ''} 处,样本:${conflicts.join(' | ')}`);
|
|
324
|
+
}
|
|
325
|
+
if (uncovered.length) {
|
|
326
|
+
issues.push(`有字段视图一条规则都不命中,样本:${uncovered.join(' | ')}(兜底规则应当覆盖一切)`);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
return { issues, rules: rules.length, swept, fallbackHits };
|
|
330
|
+
}
|