soma-core 1.4.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +443 -30
- package/core/build/component/component-graph.ts +28 -105
- package/core/build/component/package-loader.ts +50 -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 +15 -9
- 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/build/pack/pack-init.ts +19 -14
- package/core/client/base/SomaHttpClient.ts +34 -1
- package/core/client/component/ai-catalog.ts +42 -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 +120 -1
- package/core/client/container/SomaContainerAdapter.ts +6 -2
- 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 +5 -2
- 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 +280 -69
- package/core/client/theme/tone-solver.ts +9 -8
- package/core/index.ts +38 -3
- 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 +290 -0
- package/core/shared/component/field-lines.ts +563 -0
- 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 +30 -13
- 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 +2424 -1098
- 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/base/SomaHttpClient.d.ts +8 -0
- package/dist/types/client/component/ai-catalog.d.ts +9 -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/component/verify-pack.d.ts +10 -0
- 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 +6 -4
- 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 +37 -0
- package/dist/types/shared/component/field-lines.d.ts +19 -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 +29 -12
- 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 +28 -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,240 @@
|
|
|
1
|
+
// core/shared/object-semantics.ts — 对象级语义(roles / relations / modifies)的**唯一**校验实现。
|
|
2
|
+
//
|
|
3
|
+
// ── 为什么这三样的失败模式是静默的 ─────────────────────────────────
|
|
4
|
+
// 这三样都不影响取数、不影响渲染、不抛异常,坏掉的只是"这一页看起来对不对":
|
|
5
|
+
//
|
|
6
|
+
// · `roles.title` 指向一个不存在的字段 → 标题栏空白。页面照常出来,
|
|
7
|
+
// 接口照常返回 200,控制台干净。表现是"这页没标题",而这句话在验收时
|
|
8
|
+
// 多半被当成"设计就这样"。
|
|
9
|
+
// · `relations.to` 指向一个没声明的对象 → `navigate` / `compare` 拿不到
|
|
10
|
+
// 目标对象的字典,演绎出来的是一张**空的**关联区,而不是一条报错。
|
|
11
|
+
// · `modifies` 指向不存在的字段(或自己指自己) → 修饰字段没有被并入,
|
|
12
|
+
// 于是它自己占一格,页面上多出一排空的 `status_tone: —`(§15.3 缺口 1)。
|
|
13
|
+
//
|
|
14
|
+
// 三条的共同点是**都在"能跑"的那一侧**。所以它们必须在声明期被拦住,
|
|
15
|
+
// 而不是留到"有人觉得这页怪怪的"那天。
|
|
16
|
+
//
|
|
17
|
+
// ── 为什么这份校验住在 shared,而不是各写一遍 ──────────────────────
|
|
18
|
+
// SOMA 有两条书写路径:块声明(`core/client/parser/blocks/use-parser.ts`)
|
|
19
|
+
// 与平铺 `_data.yaml`(`core/client/parser/data-config-parser.ts`)。
|
|
20
|
+
// 两条路径各写一遍同一个判据,是本仓库已经付过学费的错法——
|
|
21
|
+
// 字段类型表曾经被手抄成四份,结果 `type: url` 在一条路上合法、在另一条路上被拒收,
|
|
22
|
+
// 且"哪一条对"没有答案(见 `types/data-config.types.ts` 头注释)。
|
|
23
|
+
// 判据只准有一份,两个解析器各自把自己的错误类套在返回的 issue 上。
|
|
24
|
+
//
|
|
25
|
+
// 返回 `string[]` 而不是抛:照 `validateNamedPredicates` 的先例——
|
|
26
|
+
// 让调用方决定措辞、定位路径与错误类(`SomaDataConfigError` vs `SomaBlockParseError`)。
|
|
27
|
+
|
|
28
|
+
import {
|
|
29
|
+
SOMA_DATA_OBJECT_ROLES,
|
|
30
|
+
SOMA_DATA_RELATION_CARDINALITIES,
|
|
31
|
+
type SomaDataObjectRelation,
|
|
32
|
+
type SomaDataObjectRoles,
|
|
33
|
+
} from './types/data-config.types';
|
|
34
|
+
|
|
35
|
+
/** 对象名 / 关系名 / 字段名的合法标识符(与 data-config-parser 同一条) */
|
|
36
|
+
const IDENTIFIER = /^[a-zA-Z_]\w*$/;
|
|
37
|
+
|
|
38
|
+
/** relations 条目的封闭键集 */
|
|
39
|
+
const RELATION_KEYS: readonly string[] = ['name', 'to', 'cardinality', 'via'];
|
|
40
|
+
|
|
41
|
+
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
42
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function fieldList(fieldKeys: readonly string[]): string {
|
|
46
|
+
return fieldKeys.length > 0 ? fieldKeys.join(' / ') : '(空)';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 校验 `roles:` 段。返回空数组即合法。
|
|
51
|
+
*
|
|
52
|
+
* `fieldKeys` 是本对象字段字典的键。**字典为空时直接拒收整段**:
|
|
53
|
+
* 角色的值就是字段名,没有字典就没有任何东西能对账,
|
|
54
|
+
* 放行等于把"指错字段"这类错推迟到渲染期,而渲染期它只会表现为一处空白。
|
|
55
|
+
*/
|
|
56
|
+
export function validateObjectRoles(
|
|
57
|
+
raw: unknown,
|
|
58
|
+
fieldKeys: readonly string[],
|
|
59
|
+
): string[] {
|
|
60
|
+
if (raw === undefined || raw === null) return [];
|
|
61
|
+
if (!isPlainObject(raw)) {
|
|
62
|
+
return ['roles 必须是映射(角色名 → 字段名),如 `roles: { title: no, status: state }`'];
|
|
63
|
+
}
|
|
64
|
+
const entries = Object.entries(raw);
|
|
65
|
+
if (entries.length === 0) {
|
|
66
|
+
return ['roles 是空映射——不声明与声明成空是两回事,删掉整段或至少给一个角色'];
|
|
67
|
+
}
|
|
68
|
+
if (fieldKeys.length === 0) {
|
|
69
|
+
return [
|
|
70
|
+
'roles 的值是字段名,但本对象没有声明 fields,任何角色都无从对账'
|
|
71
|
+
+ '——请先补 `fields:` 字段字典,再声明 roles',
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const issues: string[] = [];
|
|
76
|
+
const known = SOMA_DATA_OBJECT_ROLES as readonly string[];
|
|
77
|
+
for (const [role, target] of entries) {
|
|
78
|
+
if (!known.includes(role)) {
|
|
79
|
+
issues.push(
|
|
80
|
+
`未知的角色 "${role}"(封闭集:${known.join(' / ')})`
|
|
81
|
+
+ '——角色表是封闭集,加一个角色是一次体系决策,不在声明里临时扩',
|
|
82
|
+
);
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (typeof target !== 'string' || target.trim() === '') {
|
|
86
|
+
issues.push(`角色 "${role}" 的值必须是非空字段名,当前值: ${JSON.stringify(target)}`);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (!fieldKeys.includes(target)) {
|
|
90
|
+
issues.push(
|
|
91
|
+
`角色 "${role}" 指向字段 "${target}",但字典里没有它(本对象字典:${fieldList(fieldKeys)})`
|
|
92
|
+
+ '——指错的后果是那一位静默留空,页面照常渲染',
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return issues;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** `validateObjectRelations` 的上下文 */
|
|
100
|
+
export interface ObjectRelationsContext {
|
|
101
|
+
/** 本对象字段字典的键(校验 `via`) */
|
|
102
|
+
fieldKeys: readonly string[];
|
|
103
|
+
/**
|
|
104
|
+
* 本次声明里全部已知的对象名(校验 `to`)。
|
|
105
|
+
*
|
|
106
|
+
* 传 `undefined` 表示**调用方拿不到这份名单**(块声明路径就是如此:块内私有对象
|
|
107
|
+
* 的全局身份要等 block-compile 合并之后才成形)。这时跳过 `to` 的存在性检查,
|
|
108
|
+
* 但**仍校验它是不是合法标识符**——放行未知名字与放行乱码是两件事。
|
|
109
|
+
*/
|
|
110
|
+
objectNames?: readonly string[];
|
|
111
|
+
/** 本对象名(`to` 指向自己是合法的:树形自关联) */
|
|
112
|
+
selfName?: string;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* 校验 `relations:` 段。返回空数组即合法。
|
|
117
|
+
*/
|
|
118
|
+
export function validateObjectRelations(
|
|
119
|
+
raw: unknown,
|
|
120
|
+
ctx: ObjectRelationsContext,
|
|
121
|
+
): string[] {
|
|
122
|
+
if (raw === undefined || raw === null) return [];
|
|
123
|
+
if (!Array.isArray(raw)) {
|
|
124
|
+
return [
|
|
125
|
+
'relations 必须是数组,如 '
|
|
126
|
+
+ '`relations: [{ name: items, to: order_item, cardinality: many, via: order_no }]`',
|
|
127
|
+
];
|
|
128
|
+
}
|
|
129
|
+
if (raw.length === 0) {
|
|
130
|
+
return ['relations 是空数组——不声明与声明成空是两回事,删掉整段或至少给一条关系'];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const issues: string[] = [];
|
|
134
|
+
const seen = new Set<string>();
|
|
135
|
+
const cardinalities = SOMA_DATA_RELATION_CARDINALITIES as readonly string[];
|
|
136
|
+
|
|
137
|
+
raw.forEach((entry, index) => {
|
|
138
|
+
const at = `relations[${index}]`;
|
|
139
|
+
if (!isPlainObject(entry)) {
|
|
140
|
+
issues.push(`${at} 必须是对象(name / to / cardinality / via)`);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
for (const key of Object.keys(entry)) {
|
|
144
|
+
if (!RELATION_KEYS.includes(key)) {
|
|
145
|
+
issues.push(`${at} 不支持键 "${key}"(可用:${RELATION_KEYS.join(' / ')})`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const { name, to, cardinality, via } = entry as Partial<SomaDataObjectRelation>;
|
|
150
|
+
|
|
151
|
+
if (typeof name !== 'string' || !IDENTIFIER.test(name)) {
|
|
152
|
+
issues.push(`${at}.name 必须是标识符(字母/下划线开头),当前值: ${JSON.stringify(name)}`);
|
|
153
|
+
} else if (seen.has(name)) {
|
|
154
|
+
issues.push(
|
|
155
|
+
`${at}.name "${name}" 与前面的关系重名`
|
|
156
|
+
+ '——`through` 按名字引用关系,重名等于让它指向两个地方',
|
|
157
|
+
);
|
|
158
|
+
} else {
|
|
159
|
+
seen.add(name);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (typeof to !== 'string' || !IDENTIFIER.test(to)) {
|
|
163
|
+
issues.push(`${at}.to 必须是数据对象名(标识符),当前值: ${JSON.stringify(to)}`);
|
|
164
|
+
} else if (ctx.objectNames !== undefined && !ctx.objectNames.includes(to)) {
|
|
165
|
+
issues.push(
|
|
166
|
+
`${at}.to 指向未声明的数据对象 "${to}"`
|
|
167
|
+
+ `(本次声明里有:${ctx.objectNames.length > 0 ? ctx.objectNames.join(' / ') : '(空)'})`
|
|
168
|
+
+ '——把目标对象也声明进 data,或删掉这条关系;'
|
|
169
|
+
+ '留着它会让 navigate / compare 取不到目标字典,演绎出一片空白而不是报错',
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (typeof cardinality !== 'string' || !cardinalities.includes(cardinality)) {
|
|
174
|
+
issues.push(
|
|
175
|
+
`${at}.cardinality 必须是 ${cardinalities.join(' / ')},当前值: ${JSON.stringify(cardinality)}`
|
|
176
|
+
+ '——基数决定的是"演绎成一格还是一列",猜不得',
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (via !== undefined) {
|
|
181
|
+
if (typeof via !== 'string' || via.trim() === '') {
|
|
182
|
+
issues.push(`${at}.via 必须是非空字段名,当前值: ${JSON.stringify(via)}`);
|
|
183
|
+
} else if (!ctx.fieldKeys.includes(via)) {
|
|
184
|
+
issues.push(
|
|
185
|
+
`${at}.via 指向字段 "${via}",但字典里没有它(本对象字典:${fieldList(ctx.fieldKeys)})`,
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
return issues;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* 校验字段字典里的 `modifies:` 修饰关系。返回空数组即合法。
|
|
196
|
+
*
|
|
197
|
+
* 三条判据,都拦"能跑但看着不对"的错法:
|
|
198
|
+
* ① 目标必须在同一本字典里——指错则修饰字段并不进被修饰者,自己占一格;
|
|
199
|
+
* ② 不能指自己——自指的语义是"我修饰我",没有可执行含义;
|
|
200
|
+
* ③ 目标自己不能再带 `modifies`——**修饰不可级联**。级联时"谁是被呈现的那个"
|
|
201
|
+
* 没有唯一答案,而这种歧义只会表现为"少显示了一格"。
|
|
202
|
+
*/
|
|
203
|
+
export function validateFieldModifies(
|
|
204
|
+
fields: Readonly<Record<string, { modifies?: string }>>,
|
|
205
|
+
): string[] {
|
|
206
|
+
const issues: string[] = [];
|
|
207
|
+
const keys = Object.keys(fields);
|
|
208
|
+
for (const key of keys) {
|
|
209
|
+
const target = fields[key]?.modifies;
|
|
210
|
+
if (target === undefined) continue;
|
|
211
|
+
if (typeof target !== 'string' || target.trim() === '') {
|
|
212
|
+
issues.push(`字段 "${key}" 的 modifies 必须是非空字段名,当前值: ${JSON.stringify(target)}`);
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
if (target === key) {
|
|
216
|
+
issues.push(
|
|
217
|
+
`字段 "${key}" 的 modifies 指向它自己`
|
|
218
|
+
+ '——修饰关系说的是"我是别人的语气/单位/图标",自指没有可执行含义',
|
|
219
|
+
);
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
if (!(target in fields)) {
|
|
223
|
+
issues.push(
|
|
224
|
+
`字段 "${key}" 的 modifies 指向 "${target}",但字典里没有它(本对象字典:${fieldList(keys)})`
|
|
225
|
+
+ '——指错则本字段不会被并入被修饰者,而是自己占一格,页面上多出一行空值',
|
|
226
|
+
);
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
if (fields[target].modifies !== undefined) {
|
|
230
|
+
issues.push(
|
|
231
|
+
`字段 "${key}" 修饰 "${target}",而 "${target}" 自己也带 modifies——修饰不可级联`
|
|
232
|
+
+ `(请让 "${key}" 直接指向最终被修饰的那个字段)`,
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return issues;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** 供解析器复用的类型别名出口,避免消费方再从两处 import */
|
|
240
|
+
export type { SomaDataObjectRelation, SomaDataObjectRoles };
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OOUI 声明与产物的共享字面量:全体系唯一真源(REQ-014)。
|
|
3
|
+
*
|
|
4
|
+
* ── 为什么单独一个模块 ─────────────────────────────────────────────
|
|
5
|
+
* 这里的每一样东西都被**隔着依赖闸门的几方**同时消费:
|
|
6
|
+
*
|
|
7
|
+
* · 运行时解析器 `client/parser/ui-config-parser.ts`——client 不许 import `core/build`
|
|
8
|
+
* (`verify:client-dep-graph`);
|
|
9
|
+
* · 构建期引擎 `build/ooui/**` 的编排层、页面组合层、空间层与产物层——
|
|
10
|
+
* 层与层之间只许单向看(`verify-ooui-dep-graph`),产物层够不着构件层,
|
|
11
|
+
* 空间层与产物层谁都够不着页面组合层。
|
|
12
|
+
*
|
|
13
|
+
* 此前的结果是同一件事在各处各抄一份,且抄本宽严不一:锚点文法抄成三份
|
|
14
|
+
* (`1list` 过得了页面组合、到产物层才红;`_list` 过得了解析器、到页面组合才红),
|
|
15
|
+
* 演绎请求的键闭集抄成两份(解析器那份收下 `bound_to` / `layout` 却不搬进声明),
|
|
16
|
+
* `'#text'` 在构件层是常量、在产物层是两处字面量。每一份单看都对,
|
|
17
|
+
* 只是报错总落在比写错那一行晚一两层的地方——或者干脆不报。
|
|
18
|
+
*
|
|
19
|
+
* `core/shared/**` 是唯一几方都 import 得到的位置(与 `container-breakpoints.ts` 同一形态):
|
|
20
|
+
* 纯字面量与纯函数,除同在 `core/shared` 的纯字面量闭集(`SOMA_LAYOUT_SIZINGS`)外只 import 类型,
|
|
21
|
+
* 不牵连任何运行时模块。
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import {
|
|
25
|
+
SOMA_LAYOUT_SIZINGS,
|
|
26
|
+
type SomaLayoutNodeConstraint,
|
|
27
|
+
type SomaSizing,
|
|
28
|
+
} from './types/layout-constraint.types';
|
|
29
|
+
import type { SomaOouiRequestDeclaration } from './types/ui-config.types';
|
|
30
|
+
|
|
31
|
+
// ─────────────────────────────────────────────────────────────
|
|
32
|
+
// 锚点文法
|
|
33
|
+
// ─────────────────────────────────────────────────────────────
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* `ooui:` 的锚点名 = 页面组合的区域名 = 空间 IR 的节点 id。**三处是同一个名字,所以是同一条文法。**
|
|
37
|
+
*
|
|
38
|
+
* 锚点名就是区域名(`compilePageOoui` 拿锚点当区域名),区域名就是 IR 叶子的 id
|
|
39
|
+
* (`solvePageBudget` 原样放进去),产物层再按它派生 `<锚点>-shell` / `<锚点>-root`。
|
|
40
|
+
* 它会原样进 DOM 属性与 CSS 属性选择器:放开引号、括号、空格等于给选择器注入留门,
|
|
41
|
+
* 而注入成功的表现是页面照常渲染。
|
|
42
|
+
*
|
|
43
|
+
* 取「字母或下划线开头」:与运行时解析器一直收的、`layout:` 段锚点键用的是同一条
|
|
44
|
+
* (SOMA 标识符的通行写法);数字开头不收——`data-soma-id="1"` 是合法 HTML,
|
|
45
|
+
* 但读不出它指的是什么。
|
|
46
|
+
*/
|
|
47
|
+
export const SOMA_OOUI_ANCHOR_PATTERN = /^[A-Za-z_][A-Za-z0-9_-]*$/;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 同一条文法的人话版本。错误消息只引用它,不各写一句——
|
|
51
|
+
* 此前三份消息分别写着「字母开头」「字母或数字开头」,与各自的正则一起漂开。
|
|
52
|
+
*/
|
|
53
|
+
export const SOMA_OOUI_ANCHOR_GRAMMAR = '字母或下划线开头,其余可含字母、数字、- 与 _';
|
|
54
|
+
|
|
55
|
+
// ─────────────────────────────────────────────────────────────
|
|
56
|
+
// 演绎请求(`ooui:` 段的一条)的形状
|
|
57
|
+
// ─────────────────────────────────────────────────────────────
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 键闭集。以 `SomaOouiRequestDeclaration` 为准做**编译期对账**(`satisfies`):
|
|
61
|
+
* 声明类型加了字段而这里没跟上,typecheck 当场红——不会再出现"类型里有、闭集里没有"
|
|
62
|
+
* 或反过来"闭集收下了、没人搬"的那一种。
|
|
63
|
+
*/
|
|
64
|
+
const REQUEST_KEY_SET = {
|
|
65
|
+
object: true,
|
|
66
|
+
verb: true,
|
|
67
|
+
focus: true,
|
|
68
|
+
through: true,
|
|
69
|
+
form: true,
|
|
70
|
+
bound_to: true,
|
|
71
|
+
layout: true,
|
|
72
|
+
} as const satisfies Record<keyof SomaOouiRequestDeclaration, true>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 一条演绎请求允许的键——闭集,写错一个字母必须当场红。
|
|
76
|
+
*
|
|
77
|
+
* 运行时解析器与构建期编译器各校一次形状(前者服务直接喂源 YAML 的路径,
|
|
78
|
+
* 后者是发布主路径),两处用的**是这一份**。顺序即书写顺序,错误消息按它列出可用键。
|
|
79
|
+
*/
|
|
80
|
+
export const SOMA_OOUI_REQUEST_KEYS = Object.keys(REQUEST_KEY_SET) as readonly (keyof SomaOouiRequestDeclaration)[];
|
|
81
|
+
|
|
82
|
+
/** 声明里 `layout` 的形状(区域的空间约束逃生门) */
|
|
83
|
+
export type SomaOouiLayoutDeclaration = NonNullable<SomaOouiRequestDeclaration['layout']>;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* `layout` 的键 → 值的原始类型。键集同时对着声明类型与空间层的节点约束对账:
|
|
87
|
+
* 两边任一加了键,这里不跟上就是 typecheck 红。
|
|
88
|
+
*/
|
|
89
|
+
const LAYOUT_VALUE_TYPES = {
|
|
90
|
+
sizing: 'string',
|
|
91
|
+
width: 'string',
|
|
92
|
+
min: 'string',
|
|
93
|
+
max: 'string',
|
|
94
|
+
priority: 'number',
|
|
95
|
+
} as const satisfies Record<keyof SomaOouiLayoutDeclaration, 'string' | 'number'>
|
|
96
|
+
& Record<keyof SomaLayoutNodeConstraint, 'string' | 'number'>;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* `layout` 允许的键——**白名单**。
|
|
100
|
+
*
|
|
101
|
+
* 为什么必须是白名单而不是"原样摊进去":区域的约束会被摊进空间 IR 的叶子节点,
|
|
102
|
+
* 而叶子节点上还有 `id` / `kind` / `anchor` / `classes` 这些**结构键**。
|
|
103
|
+
* 放行一个 `layout: { id: x }`,叶子就被改了名,求解结果里再也找不到这个区域——
|
|
104
|
+
* 此前那里读成 0rem,于是这个区域静默降到最窄的候选,页面照常渲染。
|
|
105
|
+
*/
|
|
106
|
+
export const SOMA_OOUI_LAYOUT_KEYS = Object.keys(LAYOUT_VALUE_TYPES) as readonly (keyof SomaOouiLayoutDeclaration)[];
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 尺寸意图三档(`fixed` 就这么宽 / `hug` 内容多宽我多宽 / `fill` 剩下的给我)。顺序即文档书写序。
|
|
110
|
+
*
|
|
111
|
+
* 此前没有任何一层核 `ooui:` 区域的 sizing——解析器、编译器、页面组合层都只核"是不是字符串",
|
|
112
|
+
* 空间层求解器拿到什么就摊进约束。写成 `sizing: fil` 的区域既不是 fixed 也不是 fill,
|
|
113
|
+
* 求解器按"从 min 起步、不参与分余量"处理,于是它**静默缩到下界**(没写 min 就是 0rem),
|
|
114
|
+
* 一路喂进构件选型——这一块降到最窄的候选,页面照常渲染。
|
|
115
|
+
*
|
|
116
|
+
* 三方都要用它:运行时解析器(client 不许 import `core/build`)、编译器与页面组合层
|
|
117
|
+
* (声明期就指着写错的那一行报)、空间层求解器(IR 树的最后一道)。
|
|
118
|
+
* **它不是一份抄本,是 `SOMA_LAYOUT_SIZINGS` 本身**(`shared/types/layout-constraint.types.ts`,
|
|
119
|
+
* 在那里以 `SomaSizing` 做 `satisfies` 对账):`layout:` 段的解析器认的也是那一份。
|
|
120
|
+
* 此前这里自持一份、解析器又自持一份,两份逐字相同,漂开的那天没有断言会红。
|
|
121
|
+
*/
|
|
122
|
+
export const SOMA_OOUI_SIZINGS: readonly SomaSizing[] = SOMA_LAYOUT_SIZINGS;
|
|
123
|
+
|
|
124
|
+
/** 值是不是三档之一。非字符串一律不是——`sizing: 1` 不该被 `String()` 顶成 `'1'` 再比 */
|
|
125
|
+
export function isOouiSizing(value: unknown): value is SomaSizing {
|
|
126
|
+
return typeof value === 'string' && (SOMA_OOUI_SIZINGS as readonly string[]).includes(value);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** `layout` 里第一处不合形状的键:闭集之外的键、值的原始类型不对,或 sizing 不在三档里 */
|
|
130
|
+
export interface SomaOouiLayoutProblem {
|
|
131
|
+
readonly key: string;
|
|
132
|
+
readonly kind: 'unknown-key' | 'value-type' | 'sizing-unknown';
|
|
133
|
+
/** `value-type` 时:这个键要的原始类型 */
|
|
134
|
+
readonly expected?: 'string' | 'number';
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** 映射(非 null、非数组的对象)。YAML 里 `~` / 列表 / 标量都不是 */
|
|
138
|
+
export function isOouiMap(value: unknown): value is Record<string, unknown> {
|
|
139
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** 非空白字符串:`object` / `verb` / `through` / `form` 与 `bound_to` 两项的形状判据 */
|
|
143
|
+
export function isOouiText(value: unknown): value is string {
|
|
144
|
+
return typeof value === 'string' && value.trim() !== '';
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* `focus`:非空、且每一项都是非空白字段名。
|
|
149
|
+
*
|
|
150
|
+
* 空数组单独拦:`focus: []` 读起来像"不限",实际演绎出一个没有字段的界面——
|
|
151
|
+
* 框架在、标题在、空白在,是最像成功的失败。"全部字段"的写法是省略 focus。
|
|
152
|
+
*/
|
|
153
|
+
export function isOouiFocus(value: unknown): value is string[] {
|
|
154
|
+
return Array.isArray(value) && value.length > 0 && value.every((item) => isOouiText(item));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** 声明里 `bound_to` 的形状(区域间联动的来源) */
|
|
158
|
+
export type SomaOouiBindingDeclaration = NonNullable<SomaOouiRequestDeclaration['bound_to']>;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* `bound_to` 的键闭集。以声明类型做**编译期对账**(`satisfies`),理由同 `REQUEST_KEY_SET`。
|
|
162
|
+
*
|
|
163
|
+
* 此前解析器与编译器都只取 `region` / `as` 两项、其余键**静默丢弃**:写成
|
|
164
|
+
* `bound_to: { region: list, as: select, event: row_click }` 的作者以为自己把组件的 emit 也钉住了,
|
|
165
|
+
* 实际那一项从解析那一刻起就不存在——"写了没生效"与"这个能力不存在"分不开。
|
|
166
|
+
*/
|
|
167
|
+
const BINDING_KEY_SET = {
|
|
168
|
+
region: true,
|
|
169
|
+
as: true,
|
|
170
|
+
} as const satisfies Record<keyof SomaOouiBindingDeclaration, true>;
|
|
171
|
+
|
|
172
|
+
/** `bound_to` 允许的键。解析器与编译器的"未知键"错误都按它列出可用键 */
|
|
173
|
+
export const SOMA_OOUI_BINDING_KEYS = Object.keys(BINDING_KEY_SET) as readonly (keyof SomaOouiBindingDeclaration)[];
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* `bound_to` 里第一个闭集之外的键(按书写序);没有则 undefined。
|
|
177
|
+
*
|
|
178
|
+
* 收 `object` 而不是映射类型:页面组合层拿到的是已经带类型的 `SomaRegionBinding`,
|
|
179
|
+
* 那里多出来的键同样要报,而接口类型不能直接当 `Record<string, unknown>` 用。
|
|
180
|
+
*/
|
|
181
|
+
export function findOouiBindingUnknownKey(binding: object): string | undefined {
|
|
182
|
+
return Object.keys(binding).find((key) => !(SOMA_OOUI_BINDING_KEYS as readonly string[]).includes(key));
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* `bound_to`:恰好 `{ region, as }` 两项、且都是非空白字符串的映射。
|
|
187
|
+
*
|
|
188
|
+
* 多一个键也不算合形状——判据若只看两项齐不齐,多出来的键就会一路被当成"合法、只是没用上"。
|
|
189
|
+
* 调用方要报**哪个键**多了时先调 `findOouiBindingUnknownKey`(与 `findOouiLayoutProblem` 同一形态)。
|
|
190
|
+
*/
|
|
191
|
+
export function isOouiBinding(value: unknown): value is SomaOouiBindingDeclaration {
|
|
192
|
+
return isOouiMap(value)
|
|
193
|
+
&& findOouiBindingUnknownKey(value) === undefined
|
|
194
|
+
&& isOouiText(value.region)
|
|
195
|
+
&& isOouiText(value.as);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* 找 `layout` 里第一处不合形状的键。合形状返回 undefined。
|
|
200
|
+
*
|
|
201
|
+
* 核三件:**键**在白名单里、**值的原始类型**对、**sizing 在三档里**。
|
|
202
|
+
* priority 的四档与长度单位仍由空间层的求解器核(长度要拿到容器宽才折算得出来)。
|
|
203
|
+
*
|
|
204
|
+
* sizing 的闭集此前刻意不在这里核("闭集归空间层"),结果是**哪一层都没核**:
|
|
205
|
+
* 空间层求解器也只是把它摊进约束。现在它是 `SOMA_OOUI_SIZINGS` 这一份——类型的运行时镜像;
|
|
206
|
+
* 解析器、编译器、页面组合层都经本函数判,空间层求解器按同一份常量兜 IR 树的最后一道。
|
|
207
|
+
*/
|
|
208
|
+
export function findOouiLayoutProblem(layout: Readonly<Record<string, unknown>>): SomaOouiLayoutProblem | undefined {
|
|
209
|
+
for (const [key, value] of Object.entries(layout)) {
|
|
210
|
+
if (!(SOMA_OOUI_LAYOUT_KEYS as readonly string[]).includes(key)) return { key, kind: 'unknown-key' };
|
|
211
|
+
const expected = LAYOUT_VALUE_TYPES[key as keyof typeof LAYOUT_VALUE_TYPES];
|
|
212
|
+
if (typeof value !== expected) return { key, kind: 'value-type', expected };
|
|
213
|
+
if (key === 'sizing' && !isOouiSizing(value)) return { key, kind: 'sizing-unknown' };
|
|
214
|
+
}
|
|
215
|
+
return undefined;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** `layout` 合形状:映射、键全在白名单里、值的原始类型对、sizing 在三档里 */
|
|
219
|
+
export function isOouiLayout(value: unknown): value is SomaOouiLayoutDeclaration {
|
|
220
|
+
return isOouiMap(value) && findOouiLayoutProblem(value) === undefined;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// ─────────────────────────────────────────────────────────────
|
|
224
|
+
// 产物节点
|
|
225
|
+
// ─────────────────────────────────────────────────────────────
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* 纯文本节点的组件名占位:**不是组件**(`SomaOouiNode.component` 的一个取值)。
|
|
229
|
+
*
|
|
230
|
+
* 构件层选型时产出它,产物层发射时按它分支(落成 `<span>`、不写 `data-soma-component`)。
|
|
231
|
+
* 两层之间隔着依赖闸门(产物层回看构件层判 `SKIP-BACK`),所以常量住在两边都够得着的这里。
|
|
232
|
+
* 各写一个 `'#text'` 字面量的话,改名那天只改了一边,另一边的判断静默失配——
|
|
233
|
+
* 纯文本字段被当成一个叫 `#text` 的组件去挂载,查不到契约就跳过,那一格永远空着。
|
|
234
|
+
*/
|
|
235
|
+
export const SOMA_TEXT_NODE = '#text';
|
|
@@ -30,15 +30,34 @@ export type SomaContractPropType =
|
|
|
30
30
|
| 'object'
|
|
31
31
|
| 'array';
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
/**
|
|
34
|
+
* 字段(REQ-012)。
|
|
35
|
+
*
|
|
36
|
+
* prop、对象里的字段、数组元素、事件载荷是同一种东西,所以只有这一个形状,递归到底:
|
|
37
|
+
* `type: object` 用 `fields` 继续描述,`type: array` 用 `items` 描述元素。
|
|
38
|
+
*
|
|
39
|
+
* 为什么要 `example` 而不是靠 `default`:规则 C4 要求可选 prop 有默认值,而默认值按
|
|
40
|
+
* C4a 必须是空串 / 空数组这类浅结构——拿它渲染出来的永远是空态。展示页、视觉矩阵与
|
|
41
|
+
* AI 需要的是「这个字段真实长什么样」,那是另一个值,必须另有一处写。
|
|
42
|
+
*/
|
|
43
|
+
export interface SomaContractField {
|
|
34
44
|
type: SomaContractPropType;
|
|
45
|
+
desc?: string;
|
|
35
46
|
required?: boolean;
|
|
36
47
|
/** 非 required 的 prop 必须有默认值(契约规则 C4:零 props 可渲染) */
|
|
37
48
|
default?: unknown;
|
|
38
|
-
|
|
49
|
+
/** 示例值(REQ-012):样张与展示页的数据来源;不参与运行时,只被派生与目录消费 */
|
|
50
|
+
example?: unknown;
|
|
39
51
|
/** type === 'enum' 时的取值集合 */
|
|
40
52
|
values?: (string | number)[];
|
|
41
|
-
/**
|
|
53
|
+
/** type === 'object' 时的子字段(REQ-012) */
|
|
54
|
+
fields?: Record<string, SomaContractField>;
|
|
55
|
+
/** type === 'array' 时的元素形状(REQ-012) */
|
|
56
|
+
items?: SomaContractField;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface SomaContractProp extends SomaContractField {
|
|
60
|
+
/** 绑定模式:oneway(默认)| model(双向,一个组件最多一个)。只在 prop 一层有意义 */
|
|
42
61
|
mode?: 'oneway' | 'model';
|
|
43
62
|
}
|
|
44
63
|
|
|
@@ -67,10 +86,7 @@ export function findNestedMutableContractDefault(value: unknown): string | null
|
|
|
67
86
|
return null;
|
|
68
87
|
}
|
|
69
88
|
|
|
70
|
-
export interface SomaContractEmitPayloadField {
|
|
71
|
-
type: SomaContractPropType;
|
|
72
|
-
desc?: string;
|
|
73
|
-
}
|
|
89
|
+
export interface SomaContractEmitPayloadField extends SomaContractField {}
|
|
74
90
|
|
|
75
91
|
export interface SomaContractEmit {
|
|
76
92
|
payload?: Record<string, SomaContractEmitPayloadField>;
|
|
@@ -143,12 +159,13 @@ export interface SomaComponentContract {
|
|
|
143
159
|
* 依赖的其它组件(REQ-010 F-46):PascalCase 契约名数组。
|
|
144
160
|
*
|
|
145
161
|
* 两件事靠它:
|
|
146
|
-
* ①
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
162
|
+
* ① **eject 说得出副本还需要谁**——`soma component eject` 一个 TreeSelect 时列出它还要 Tree
|
|
163
|
+
* (仍从 soma-ui 取,要在宿主注册表里可解析),而不是等页面渲染出一堆没样式的节点才发现
|
|
164
|
+
* (这条曾真实发生过:`COMPONENT_CSS_DEPS` 少写一条 `TreeSelect: ['Tree']`,
|
|
165
|
+
* 页面上是无样式的折叠箭头);
|
|
166
|
+
* ② **与 CSS 依赖表对账**——`build/component/component-graph.ts` 按它建图,
|
|
167
|
+
* soma-ui 的 `component-css-deps` 测试拿图与 `COMPONENT_CSS_DEPS` 逐项对账,
|
|
168
|
+
* 漏登记的那一条当场红。
|
|
152
169
|
*
|
|
153
170
|
* 只登记**契约级**依赖(模板里真的嵌了那个组件、或 CSS 分片依赖它),
|
|
154
171
|
* 不登记共享资产(`shared/*` 由构建图自然带上,写进来只会重复一份且会漂)。
|
|
@@ -114,6 +114,91 @@ export interface SomaDataFieldConfig {
|
|
|
114
114
|
* 而"写了没反应"是最难查的一类。
|
|
115
115
|
*/
|
|
116
116
|
calc?: string;
|
|
117
|
+
/**
|
|
118
|
+
* 修饰关系(REQ-014 §15.3 原型实测补入):本字段是**另一个字段的修饰**,
|
|
119
|
+
* 不独立呈现。典型是 `status_tone` 修饰 `status_text`——语气、单位、币种、
|
|
120
|
+
* 图标、趋势方向都属此类。
|
|
121
|
+
*
|
|
122
|
+
* 不声明的后果是静默的:修饰字段会被当成一个普通只读字段各占一格,
|
|
123
|
+
* 页面上出现一排空的 `status_tone: —` `priority_tone: —`。它不报错、
|
|
124
|
+
* 不影响功能,只是"这页看着有点乱"——而这句话没人会当成 bug 报上来。
|
|
125
|
+
* 原型跑出来第一眼看到的就是这个(§15.3 缺口 1)。
|
|
126
|
+
*
|
|
127
|
+
* 约束(解析期强制):目标必须是同一本字典里的**另一个**字段,且目标自己
|
|
128
|
+
* 不能再带 `modifies`——修饰不可级联。级联的话"谁是被呈现的那个"就没有唯一答案,
|
|
129
|
+
* 而这种歧义在渲染期只会表现为"少显示了一格"。
|
|
130
|
+
*/
|
|
131
|
+
modifies?: string;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* 对象级角色(REQ-014 §3.1.2):哪个字段承担什么**语义位**。
|
|
136
|
+
*
|
|
137
|
+
* 它要替换掉的是"靠字段名猜"。今天 `pickField` 一类的做法用别名表匹配
|
|
138
|
+
* (`title` / `name` / `label` …)去猜标题字段,猜错了表现为"标题栏显示订单备注",
|
|
139
|
+
* 而这条猜测既不出现在声明里也不出现在日志里,**没有任何地方可查**。
|
|
140
|
+
* 声明了 `roles` 之后,"谁是标题"是作者写的事实,不是系统的运气。
|
|
141
|
+
*
|
|
142
|
+
* 全部可选、值都是**本对象字段字典里的字段名**(解析期对账,指错当场红)。
|
|
143
|
+
*/
|
|
144
|
+
export interface SomaDataObjectRoles {
|
|
145
|
+
/** 身份:这一行/这个对象的唯一键 */
|
|
146
|
+
id?: string;
|
|
147
|
+
/** 展示这个对象时拿什么当标题 */
|
|
148
|
+
title?: string;
|
|
149
|
+
/** 副标题 */
|
|
150
|
+
subtitle?: string;
|
|
151
|
+
/** 生命周期状态,驱动状态位与语气 */
|
|
152
|
+
status?: string;
|
|
153
|
+
/** 时间轴默认依据 */
|
|
154
|
+
timestamp?: string;
|
|
155
|
+
/** 金额,决定右对齐与货币格式 */
|
|
156
|
+
amount?: string;
|
|
157
|
+
/**
|
|
158
|
+
* 对比基准(§27.3 盲测补入):指向标记基准项的字段(如 `is_control`)。
|
|
159
|
+
*
|
|
160
|
+
* 缺它则对比无锚点——"+12%" 不知道是相对谁。而"相对谁"错了的界面
|
|
161
|
+
* 看起来完全正常:数字在、箭头在、颜色也在,只是符号反了。
|
|
162
|
+
*/
|
|
163
|
+
baseline?: string;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* 全部合法角色名(封闭集),供两条书写路径的解析器共用。
|
|
168
|
+
*
|
|
169
|
+
* **不要在解析器里再手抄一份**——字段类型表已经因为手抄漂成过四份
|
|
170
|
+
* (见本文件 `SomaDataFieldType` 的头注释),角色表没有理由重走一遍。
|
|
171
|
+
*/
|
|
172
|
+
export const SOMA_DATA_OBJECT_ROLES: readonly (keyof SomaDataObjectRoles)[] = [
|
|
173
|
+
'id', 'title', 'subtitle', 'status', 'timestamp', 'amount', 'baseline',
|
|
174
|
+
];
|
|
175
|
+
|
|
176
|
+
/** 关系基数:一对一 / 一对多。封闭集 */
|
|
177
|
+
export type SomaDataRelationCardinality = 'one' | 'many';
|
|
178
|
+
|
|
179
|
+
/** 全部合法基数(封闭集),解析器共用 */
|
|
180
|
+
export const SOMA_DATA_RELATION_CARDINALITIES: readonly SomaDataRelationCardinality[] = [
|
|
181
|
+
'one', 'many',
|
|
182
|
+
];
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* 对象间关系(REQ-014 §3.1.2)。
|
|
186
|
+
*
|
|
187
|
+
* 为什么必须显式声明:`compare` 与 `navigate` 两个动词的作用对象**往往不是主对象**
|
|
188
|
+
* (§27.2 盲测)——要比的是"一个实验内部的多个变体",要导航的必然是关系的另一端。
|
|
189
|
+
* 没有关系声明,这两个动词(占八动词封闭集的 25%)表达不出来;
|
|
190
|
+
* 靠字段名后缀猜关系(`xxx_id` → `xxx`)猜错时表现为"点进去是另一个对象的详情",
|
|
191
|
+
* 而页面本身渲染得好好的。
|
|
192
|
+
*/
|
|
193
|
+
export interface SomaDataObjectRelation {
|
|
194
|
+
/** 关系名(对象内唯一),`through` 按它引用 */
|
|
195
|
+
name: string;
|
|
196
|
+
/** 目标对象名(必须是同一份声明里已声明的数据对象) */
|
|
197
|
+
to: string;
|
|
198
|
+
/** 基数 */
|
|
199
|
+
cardinality: SomaDataRelationCardinality;
|
|
200
|
+
/** 本对象上的外键字段(可选;给了就必须在本对象字典里) */
|
|
201
|
+
via?: string;
|
|
117
202
|
}
|
|
118
203
|
|
|
119
204
|
/**
|
|
@@ -185,6 +270,16 @@ export interface SomaDataObjectConfig {
|
|
|
185
270
|
fields?: Record<string, SomaDataFieldConfig>;
|
|
186
271
|
/** mock 样本:SOMA_MOCK_ENABLED / 接口失败兜底 / 无接口预览 */
|
|
187
272
|
mock?: unknown;
|
|
273
|
+
/**
|
|
274
|
+
* 对象级角色(REQ-014 §3.1.2):哪个字段承担什么语义位。
|
|
275
|
+
* 声明它等于把"谁是标题/状态/金额/基准"从系统的猜测变成作者的事实。
|
|
276
|
+
*/
|
|
277
|
+
roles?: SomaDataObjectRoles;
|
|
278
|
+
/**
|
|
279
|
+
* 与其他对象的关系(REQ-014 §3.1.2)。
|
|
280
|
+
* `SomaSemanticRequest.through` 按 `name` 引用它,`compare` / `navigate` 靠它成立。
|
|
281
|
+
*/
|
|
282
|
+
relations?: SomaDataObjectRelation[];
|
|
188
283
|
/** 写通道声明(§8);不给 = 该对象只读 */
|
|
189
284
|
write?: SomaDataWriteConfig;
|
|
190
285
|
/**
|