soma-core 1.4.2 → 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 +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 +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/client/component/example-blocks.ts +1 -7
- package/core/client/component/theme-component-tokens.ts +12 -15
- 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 +280 -69
- package/core/client/theme/tone-solver.ts +9 -8
- package/core/index.ts +18 -4
- 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 +1563 -800
- 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/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 -5
- 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 +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,557 @@
|
|
|
1
|
+
// 发布单元的资产钉子:一个页面版本"是对着哪一份组件 CSS 发布的"。
|
|
2
|
+
//
|
|
3
|
+
// ── 这个失败模式为什么是静默的 ─────────────────────────────────────────
|
|
4
|
+
// 页面版本记录里有声明、有编译产物、有版本号,唯独没有**样式的身份**。
|
|
5
|
+
// 组件 CSS 随 npm 包走、随实例化注入(`core/client/component/pack-styles.ts`),
|
|
6
|
+
// 所以回滚到 v3 拿到的是 v3 的 DOM 配今天的样式表。三件事同时成立:
|
|
7
|
+
// 回滚回执完整、页面能开、每个组件都渲染出来——只有间距、字号、断点不是那天的样子。
|
|
8
|
+
// 没有任何东西会红,因为没有任何东西在比对:库里既没有 v3 那天的字节,
|
|
9
|
+
// 也没有一句"v3 当时用的是哪一份"。**钉子就是那句话**,它让"不一样"第一次可判定。
|
|
10
|
+
//
|
|
11
|
+
// ── 三条纪律,第一条最重要 ───────────────────────────────────────────
|
|
12
|
+
// 1. **钉子宁可缺席,不可说谎**。资产字节没能落库(库满、无权限、宿主没接供货)
|
|
13
|
+
// 就整份不钉,并且告警——一个指向不存在字节的摘要比没有摘要更坏:
|
|
14
|
+
// 它让对账显示"已钉住",而恢复时才发现字节不在。
|
|
15
|
+
// 2. **钉子是真理,不是缓存,所以它是 `compiled` 的兄弟而不是儿子**。
|
|
16
|
+
// `CompiledDeclaration` 那份纪律写着"编译失败不阻断发布"——失败即 null。
|
|
17
|
+
// 把钉子塞进去,一次编译失败就把钉子一起丢了,而丢掉之后对账会说"未钉住"(通过),
|
|
18
|
+
// 正是要防的静默。所以钉子挂在 `PageVersionRecord.assets`,与 `compiled` 平级。
|
|
19
|
+
// 3. **宿主没供货就不判**(与 `validation/component-existence.ts` 同一条):
|
|
20
|
+
// 组件 CSS 住在组件库(soma-ui / 业务包),core 不许 import 它们
|
|
21
|
+
// (`verify-ooui-dep-graph` 的 `CORE-IMPORTS-UI`),只能由宿主反向注册进来。
|
|
22
|
+
// core 宁可不钉,也不能拿一份自己臆想的样式表去冒充"发布时的字节"。
|
|
23
|
+
//
|
|
24
|
+
// ── 落法的裁定:组件 CSS 独立落库,页面级产物 CSS 搭便车 ───────────────
|
|
25
|
+
// 判据是**跨页共用面**,不是"哪个更省事":
|
|
26
|
+
//
|
|
27
|
+
// | 资产 | 实测体量 | 跨页共用 | 落法 |
|
|
28
|
+
// |-------------------------------------|---------------------------|---------|------|
|
|
29
|
+
// | 组件包 CSS(soma-ui 325 分片) | 全库 1,351,112B; | 极高 | 独立落库 |
|
|
30
|
+
// | | 单页闭包 14,465~40,785B | | (内容寻址) |
|
|
31
|
+
// | `layout_css` / `ooui_artifact.css` | 百字节~数 KB,单页独有 | 无 | 搭 uiConfig 便车 |
|
|
32
|
+
//
|
|
33
|
+
// 独立落库的四个理由:
|
|
34
|
+
// ① **版本只增不减,rollback 也是追加**。单页 CSS 闭包实测是声明本体的 10~28 倍
|
|
35
|
+
// (soma-web 五页:html 481~1,423 字节,对应组件 CSS 14,465~40,785 字节)。
|
|
36
|
+
// 搭便车 = 每个版本各复制一份;一个页面改 20 次就是 20 份近乎相同的 40KB。
|
|
37
|
+
// 内容寻址后这 20 个版本共用一份字节,而且跨页面也共用。
|
|
38
|
+
// ② **全库 1,351,112 字节是声明体积闸门(131,072)的 10.3 倍**。任何"塞进声明/产物"
|
|
39
|
+
// 的方案要么撞闸门、要么迫使把闸门抬高十倍——而抬高会同时放开声明本身,
|
|
40
|
+
// 那正是 128KiB 要防的东西(把明细表、base64 塞进 html)。闸门不为搭车让路。
|
|
41
|
+
// ③ 组件 CSS 是**不可变、可长缓存**的资源(哈希即身份);声明是每次取页都要重拉的
|
|
42
|
+
// 可变资源。混在一份 JSON 里 = 让不可变资源随可变资源一起重传。
|
|
43
|
+
// ④ `layout_css` 恰好相反:百字节、单页独有、零共用面。为它单独开一次资产读写
|
|
44
|
+
// 只是多一次 IO 和多一处可失败的接线。所以两者取不同落法**不是不一致,
|
|
45
|
+
// 是共用面不同**。
|
|
46
|
+
//
|
|
47
|
+
// ── 回滚时钉子取今天的,不取被回滚版本的 ─────────────────────────────
|
|
48
|
+
// `rollback(v3)` 产出的是**新版本 v5**(声明复制自 v3)。v5 的钉子按**今天**的供货钉。
|
|
49
|
+
// 不把 v3 的钉子抄给 v5,是因为取页路径现在仍从 npm 包注入 CSS(见本批 findings):
|
|
50
|
+
// 抄过来的钉子会声称 v5 用的是 v3 的字节,而实际不是——那是**说谎的钉子**,
|
|
51
|
+
// 比没有钉子坏得多。差异由 `reconcilePinnedAssets(v3 记录)` 说出来:
|
|
52
|
+
// 它拿 v3 的钉子对今天的供货,答"今天与 v3 发布时是否一致、不一致还能不能恢复"。
|
|
53
|
+
|
|
54
|
+
import {
|
|
55
|
+
assetIntakeIssues,
|
|
56
|
+
getRegistryAssetStore,
|
|
57
|
+
isSomaAssetDigest,
|
|
58
|
+
somaAssetDigest,
|
|
59
|
+
type RegistryAssetStore,
|
|
60
|
+
type SomaAssetKind,
|
|
61
|
+
} from './asset-store';
|
|
62
|
+
import { collectReferencedComponents } from './validation/component-existence';
|
|
63
|
+
import type { SomaOouiNode, SomaPageOouiArtifact } from '../../shared/types/ui-config.types';
|
|
64
|
+
|
|
65
|
+
/** 钉子格式版本。读到不认识的版本整份当"未钉住",不猜字段。 */
|
|
66
|
+
export const ASSET_PIN_VERSION = 1;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 供货方交出来的样式表分片。字段名与 `ComposedComponentPacks.styles`
|
|
70
|
+
* (`core/client/component/component-pack.ts`)一一对应,宿主接线是把已有的
|
|
71
|
+
* 合成结果原样递进来,不必再造一份形状。
|
|
72
|
+
*/
|
|
73
|
+
export interface PublishedAssetSupply {
|
|
74
|
+
/** 组件名 → 该组件的 CSS 分片(`styles.components`) */
|
|
75
|
+
components: Readonly<Record<string, string>>;
|
|
76
|
+
/** 共享资产名 → 分片(`styles.shared`) */
|
|
77
|
+
shared?: Readonly<Record<string, string>>;
|
|
78
|
+
/** 组件名 → 依赖的共享资产名(`styles.deps`) */
|
|
79
|
+
dependencies?: Readonly<Record<string, readonly string[]>>;
|
|
80
|
+
/** 包级基座分片(`styles.base`)。**次序即身份**——注入键是 `base:<下标>`,这里不重排 */
|
|
81
|
+
base?: readonly string[];
|
|
82
|
+
/** 组件名 → 令牌规则(`renderComponentTokenRule` 的产出;core 不代算,见下) */
|
|
83
|
+
tokens?: Readonly<Record<string, string>>;
|
|
84
|
+
/** 组件补丁(`composed.patches`) */
|
|
85
|
+
patches?: readonly { target: string; patchedBy: string; css: string }[];
|
|
86
|
+
/**
|
|
87
|
+
* 供货包名 → 版本(如 `{ 'soma-ui': '1.4.2' }`)。
|
|
88
|
+
* 这是**词表版本**那一维的载体,也是 `isCompiledUsable` 第三道闸的判据来源
|
|
89
|
+
* (见 `currentAssetSupplyKey`)。参照 SDUI 的能力协商:各方把自己"是哪个版本"
|
|
90
|
+
* 报上来,而不是让对面去猜。不给就那道闸不判。
|
|
91
|
+
*/
|
|
92
|
+
packs?: Readonly<Record<string, string>>;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** 供货来源;返回 null / undefined 表示"宿主没告诉我",此时不钉、不判 */
|
|
96
|
+
export type PublishedAssetSource = () => PublishedAssetSupply | null | undefined;
|
|
97
|
+
|
|
98
|
+
let source: PublishedAssetSource | null = null;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* 注入样式供货来源(宿主服务端接线;传 null 复位为"不钉")。
|
|
102
|
+
* 与组件清单同款:**每次都重新问一次,不缓存**——供货可随宿主热更新,
|
|
103
|
+
* 缓存住的表现是"换了组件库版本,钉子还钉着旧摘要"。
|
|
104
|
+
*/
|
|
105
|
+
export function setPublishedAssetSource(next: PublishedAssetSource | null): void {
|
|
106
|
+
source = next;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** 当前供货(没有则 undefined)。对账与钉住共用同一个入口,不各问一次。 */
|
|
110
|
+
export function currentAssetSupply(): PublishedAssetSupply | undefined {
|
|
111
|
+
const supply = source?.();
|
|
112
|
+
if (!supply || typeof supply !== 'object') return undefined;
|
|
113
|
+
if (!supply.components || typeof supply.components !== 'object') return undefined;
|
|
114
|
+
return supply;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 供货指纹:`packs` 的 `名字@版本` 逐行摘要。缺 `packs` 返回 undefined(不判)。
|
|
119
|
+
*
|
|
120
|
+
* 为什么不去哈希 1.3MB 的全库字节:这个键会挂在**每次取页**都要过的
|
|
121
|
+
* `isCompiledUsable` 上。哈希全库每次约数毫秒,而"每次取页多几毫秒"是这条路径上
|
|
122
|
+
* 最典型的静默退化(功能全对、监控全绿,只有耗时在涨——`published-page-assets.ts`
|
|
123
|
+
* 的文件头就是为同一件事写的)。版本号是**声明出来的**能力协商,微秒级。
|
|
124
|
+
* 代价是宿主必须如实报版本;不报就不判,而不是拿一个猜的键去判。
|
|
125
|
+
*/
|
|
126
|
+
export function currentAssetSupplyKey(): string | undefined {
|
|
127
|
+
const lines = packLines(currentAssetSupply()?.packs);
|
|
128
|
+
return lines ? somaAssetDigest(lines.join('\n')) : undefined;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* 供货包版本表里的有效条目名(版本是非空字符串),升序。
|
|
133
|
+
*
|
|
134
|
+
* 供货指纹、钉子里的 `packs`、漂移告示三处共用这一份筛选与排序:
|
|
135
|
+
* 各写一遍的话,哪天一处多收了一种条目(比如空版本),同一份供货就会在
|
|
136
|
+
* 指纹里与钉子里是两个样子,对账天天报假漂移。
|
|
137
|
+
*/
|
|
138
|
+
function validPackNames(packs: Readonly<Record<string, string>> | undefined): string[] | undefined {
|
|
139
|
+
if (!packs || typeof packs !== 'object') return undefined;
|
|
140
|
+
const names = Object.keys(packs)
|
|
141
|
+
.filter((name) => typeof packs[name] === 'string' && packs[name] !== '')
|
|
142
|
+
.sort();
|
|
143
|
+
return names.length > 0 ? names : undefined;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** `名字@版本` 逐行(升序);没有有效条目返回 undefined */
|
|
147
|
+
function packLines(packs: Readonly<Record<string, string>> | undefined): string[] | undefined {
|
|
148
|
+
return validPackNames(packs)?.map((name) => `${name}@${packs![name]}`);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** 钉住的一份资产 */
|
|
152
|
+
export interface SomaPinnedAsset {
|
|
153
|
+
kind: SomaAssetKind;
|
|
154
|
+
/** `sha256-<64 hex>` */
|
|
155
|
+
digest: string;
|
|
156
|
+
bytes: number;
|
|
157
|
+
/** 参与这份资产的构件名(升序)。对账要按同一份名单重算,"少了谁"才看得见 */
|
|
158
|
+
members: string[];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** 一个页面版本的资产钉子 */
|
|
162
|
+
export interface SomaAssetPin {
|
|
163
|
+
pinVersion: typeof ASSET_PIN_VERSION;
|
|
164
|
+
/** 与 `compiled` 同一道版本闸(`DECLARATION_COMPILER_VERSION`) */
|
|
165
|
+
compilerVersion: string;
|
|
166
|
+
/** 供货包版本(词表版本那一维;供货方没报就缺席) */
|
|
167
|
+
packs?: Record<string, string>;
|
|
168
|
+
/** 资产清单(按 kind 升序) */
|
|
169
|
+
assets: SomaPinnedAsset[];
|
|
170
|
+
/**
|
|
171
|
+
* 本次**没能覆盖到**的东西。空则整个键不写。
|
|
172
|
+
* 它是"钉子宁可缺席不可说谎"的第二层:钉住了一部分,就必须写清哪一部分没钉住。
|
|
173
|
+
*/
|
|
174
|
+
caveats?: string[];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** 钉住资产时需要的最小声明形状(只用 html;不引 page-registry-store 免得成环) */
|
|
178
|
+
export interface PinnableDeclaration {
|
|
179
|
+
html: string;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export interface PinPublishedAssetsOptions {
|
|
183
|
+
/** 演绎产物。演绎选出的组件不在 `html` 里,不带上就会漏钉恰好是演绎选中的那些 */
|
|
184
|
+
artifact?: SomaPageOouiArtifact | undefined;
|
|
185
|
+
/** 资产库(缺省取进程共享库) */
|
|
186
|
+
store?: RegistryAssetStore;
|
|
187
|
+
/** 编译器版本。由调用方传入,与 `compiled.compilerVersion` 同一个值 */
|
|
188
|
+
compilerVersion: string;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* 收集这一版真正会用到的构件名(升序去重)。
|
|
193
|
+
*
|
|
194
|
+
* 两个来源都要:
|
|
195
|
+
* - `html` 里的 `data-soma-component`(手写编排);
|
|
196
|
+
* - 演绎产物每个区域的构件树(REQ-014)。**漏掉后者的表现最阴**:
|
|
197
|
+
* 页面开出来,手写那部分有样式,演绎出来那一块光秃秃,而两者都"渲染成功"。
|
|
198
|
+
*/
|
|
199
|
+
export function pinnedAssetMembers(
|
|
200
|
+
html: string,
|
|
201
|
+
artifact?: SomaPageOouiArtifact | undefined,
|
|
202
|
+
): string[] {
|
|
203
|
+
const names = new Set<string>(collectReferencedComponents(html ?? ''));
|
|
204
|
+
for (const region of artifact?.regions ?? []) {
|
|
205
|
+
collectNodeComponents(region.root, names);
|
|
206
|
+
}
|
|
207
|
+
return [...names].sort();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function collectNodeComponents(node: SomaOouiNode | undefined, into: Set<string>): void {
|
|
211
|
+
if (!node || typeof node !== 'object') return;
|
|
212
|
+
if (typeof node.component === 'string' && node.component !== '' && node.component !== '#text') {
|
|
213
|
+
into.add(node.component);
|
|
214
|
+
}
|
|
215
|
+
for (const child of node.children ?? []) {
|
|
216
|
+
collectNodeComponents(child, into);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** 拼装结果:规范次序的样式表 + 没找到分片的构件名 */
|
|
221
|
+
export interface AssembledComponentCss {
|
|
222
|
+
css: string;
|
|
223
|
+
missing: string[];
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* 按**规范次序**拼一份组件 CSS 闭包。幂等的全部要求都在这个函数里:
|
|
228
|
+
* 同一份构件名单 + 同一份供货 ⇒ 逐字节相同的字符串。
|
|
229
|
+
*
|
|
230
|
+
* 次序 = 基座 → 共享 → 令牌 → 组件 → 补丁,与 `pack-styles.ts` 的注入次序同层同序。
|
|
231
|
+
* 差别只有一处,写在这里免得下一个人以为是随手拉平的:运行时是**逐组件**注入
|
|
232
|
+
* (组件 A 的共享 → A 的令牌 → A 的分片 → 组件 B 的共享 → …),这里拉平成分层。
|
|
233
|
+
* 两者只在"某个组件分片去改共享类"时级联结果不同——而那本身违反分片纪律
|
|
234
|
+
* (分片只该碰自己的 `.soma-<组件>`)。钉子不为它兜底,但也不假装两者永远等价。
|
|
235
|
+
*
|
|
236
|
+
* `tokens` 由供货方交,core 不代算:令牌规则要读组件契约(`contract.tokens`),
|
|
237
|
+
* 契约住在组件库,core 自己算就等于在 core 里养第二份派生实现——两份必然漂,
|
|
238
|
+
* 而漂掉的表现是"钉子的字节与真实注入的字节差一条规则",对账天天报假漂移。
|
|
239
|
+
*/
|
|
240
|
+
export function assembleComponentCss(
|
|
241
|
+
supply: PublishedAssetSupply,
|
|
242
|
+
members: readonly string[],
|
|
243
|
+
): AssembledComponentCss {
|
|
244
|
+
const segments: string[] = [];
|
|
245
|
+
const missing: string[] = [];
|
|
246
|
+
|
|
247
|
+
for (const css of supply.base ?? []) {
|
|
248
|
+
if (typeof css === 'string' && css !== '') segments.push(css);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const sharedNames = new Set<string>();
|
|
252
|
+
for (const name of members) {
|
|
253
|
+
for (const dep of supply.dependencies?.[name] ?? []) {
|
|
254
|
+
if (typeof dep === 'string' && dep !== '') sharedNames.add(dep);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
for (const dep of [...sharedNames].sort()) {
|
|
258
|
+
const css = supply.shared?.[dep];
|
|
259
|
+
if (typeof css === 'string' && css !== '') segments.push(css);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
for (const name of members) {
|
|
263
|
+
const rule = supply.tokens?.[name];
|
|
264
|
+
if (typeof rule === 'string' && rule !== '') segments.push(rule);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
for (const name of members) {
|
|
268
|
+
const css = supply.components[name];
|
|
269
|
+
if (typeof css === 'string') {
|
|
270
|
+
if (css !== '') segments.push(css);
|
|
271
|
+
} else {
|
|
272
|
+
missing.push(name);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const patches = [...(supply.patches ?? [])]
|
|
277
|
+
.filter((patch) => patch && typeof patch.css === 'string' && patch.css !== ''
|
|
278
|
+
&& members.includes(patch.target))
|
|
279
|
+
.sort((left, right) => (
|
|
280
|
+
`${left.target} ${left.patchedBy}`.localeCompare(`${right.target} ${right.patchedBy}`)
|
|
281
|
+
));
|
|
282
|
+
for (const patch of patches) segments.push(patch.css);
|
|
283
|
+
|
|
284
|
+
return { css: segments.join('\n'), missing };
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* 钉住这一版的资产。返回 null = 这一版没有可钉的资产(宿主没供货 / 页面没引用构件 /
|
|
289
|
+
* 供货里这些构件一片 CSS 都没有 / 字节没能落库)。**返回 null 不阻断发布**。
|
|
290
|
+
*/
|
|
291
|
+
export function pinPublishedAssets(
|
|
292
|
+
declaration: PinnableDeclaration,
|
|
293
|
+
options: PinPublishedAssetsOptions,
|
|
294
|
+
): SomaAssetPin | null {
|
|
295
|
+
const supply = currentAssetSupply();
|
|
296
|
+
if (!supply) return null;
|
|
297
|
+
|
|
298
|
+
const members = pinnedAssetMembers(declaration?.html ?? '', options.artifact);
|
|
299
|
+
if (members.length === 0) return null;
|
|
300
|
+
|
|
301
|
+
const assembled = assembleComponentCss(supply, members);
|
|
302
|
+
const intake = assetIntakeIssues(assembled.css);
|
|
303
|
+
if (intake.length > 0) {
|
|
304
|
+
// 空是正常的(这些构件确实没有 CSS),超限不是:超限要响,否则一份异常供货
|
|
305
|
+
// 会让此后每一版都静默地没有钉子。
|
|
306
|
+
if (assembled.css !== '') {
|
|
307
|
+
console.warn(`[soma-core][注册中心] 资产钉子缺席:${intake.join(';')}`);
|
|
308
|
+
}
|
|
309
|
+
return null;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const store = options.store ?? getRegistryAssetStore();
|
|
313
|
+
let ref;
|
|
314
|
+
try {
|
|
315
|
+
ref = store.put('component-css', assembled.css);
|
|
316
|
+
} catch (error) {
|
|
317
|
+
// 字节没能落库就整份不钉。指向不存在字节的摘要比没有摘要更坏——
|
|
318
|
+
// 它让对账显示"已钉住",恢复时才发现字节不在,而那已经是回滚现场了。
|
|
319
|
+
console.warn(
|
|
320
|
+
`[soma-core][注册中心] 资产字节未能落库,本版不钉资产:${message(error)}`,
|
|
321
|
+
);
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const packs = sortedPacks(supply.packs);
|
|
326
|
+
const caveats: string[] = [];
|
|
327
|
+
if (assembled.missing.length > 0) {
|
|
328
|
+
caveats.push(
|
|
329
|
+
`供货里没有这些构件的 CSS 分片:${assembled.missing.join('、')}`
|
|
330
|
+
+ '(构件本来就没有样式时这是正常的;构件名写错时也是这个样子,'
|
|
331
|
+
+ '后者由组件存在性闸门 scanUnknownComponents 判)',
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
if (!options.artifact) {
|
|
335
|
+
caveats.push(
|
|
336
|
+
'本次未带演绎产物,构件名单只来自 html:若这一版声明了 ooui: 段,'
|
|
337
|
+
+ '演绎选出的构件没有钉进来',
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
return {
|
|
342
|
+
pinVersion: ASSET_PIN_VERSION,
|
|
343
|
+
compilerVersion: options.compilerVersion,
|
|
344
|
+
...(packs ? { packs } : {}),
|
|
345
|
+
assets: [{ kind: ref.kind, digest: ref.digest, bytes: ref.bytes, members }],
|
|
346
|
+
...(caveats.length > 0 ? { caveats } : {}),
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/** 钉子自身的 JSON 字节数(报体积用;它是**除声明与产物之外**新增在版本记录上的那一份) */
|
|
351
|
+
export function assetPinByteSize(pin: SomaAssetPin | undefined): number {
|
|
352
|
+
if (!pin) return 0;
|
|
353
|
+
return Buffer.byteLength(JSON.stringify(pin), 'utf8');
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* 发布时的漂移告示:上一版与这一版**构件名单一模一样、字节却不同** ⇒ 组件库在两次发布
|
|
358
|
+
* 之间换了。返回一句话,没漂返回 null。
|
|
359
|
+
*
|
|
360
|
+
* 为什么必须在发布这一刻说,而不是等回滚时再说:回滚是**故障现场**,那时候
|
|
361
|
+
* "样式也跟着变了"这条信息来得太晚,而且与故障本身混在一起分不开。
|
|
362
|
+
* 发布时说出来,操作者当场就知道"这次上线不只改了声明,还换了一整套样式基线"。
|
|
363
|
+
*
|
|
364
|
+
* 判据严格卡在"名单相同"上,因为名单不同本来就该产出不同字节(页面自己改了),
|
|
365
|
+
* 那时候报漂移是假警报——而假警报几次之后,真警报也没人看了。
|
|
366
|
+
*/
|
|
367
|
+
export function assetSupplyDriftNotice(
|
|
368
|
+
previous: SomaAssetPin | undefined,
|
|
369
|
+
current: SomaAssetPin | undefined,
|
|
370
|
+
who: string,
|
|
371
|
+
): string | null {
|
|
372
|
+
// 上一版来自**存量 JSON**(`normalizeStoredRecord` 不校验 `assets`),里面可以是任何东西。
|
|
373
|
+
// 这里在发布路径上,一次 `.find is not a function` 会把整次发布变成 500——
|
|
374
|
+
// 一句诊断绝不能成为写路径的新失败面,所以形状不对一律当"没有钉子"。
|
|
375
|
+
const before = pickComponentCss(previous);
|
|
376
|
+
const after = pickComponentCss(current);
|
|
377
|
+
if (!before || !after) return null;
|
|
378
|
+
if (before.digest === after.digest) return null;
|
|
379
|
+
if (before.members.length !== after.members.length) return null;
|
|
380
|
+
if (before.members.some((name, index) => name !== after.members[index])) return null;
|
|
381
|
+
const packs = (pin: SomaAssetPin | undefined) => packLines(pin?.packs)?.join('、') ?? '未报版本';
|
|
382
|
+
return `现状:页面 ${who} 与上一版引用的是同一批构件(${after.members.length} 个),`
|
|
383
|
+
+ `组件 CSS 摘要却从 ${before.digest} 变成了 ${after.digest}`
|
|
384
|
+
+ `(供货版本 ${packs(previous)} → ${packs(current)})。`
|
|
385
|
+
+ '问题:组件库在两次发布之间换了,所以上一版从此**不能靠重新发布复现**——'
|
|
386
|
+
+ '回滚回它的声明,拿到的会是今天这套样式;而页面照常打开,没有任何报错。'
|
|
387
|
+
+ '建议:确认这次组件库升级是有意的;'
|
|
388
|
+
+ '需要复现旧样式时按上一版钉住的摘要从资产库取字节'
|
|
389
|
+
+ '(getRegistryAssetStore().read(digest))。';
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/** 对账判定 */
|
|
393
|
+
export type SomaAssetReconcileStatus = 'match' | 'drift' | 'unpinned' | 'unavailable';
|
|
394
|
+
|
|
395
|
+
export interface SomaAssetReconciliation {
|
|
396
|
+
status: SomaAssetReconcileStatus;
|
|
397
|
+
/** 三段式(现状 / 问题 / 建议)问题清单;`match` 时为空 */
|
|
398
|
+
issues: string[];
|
|
399
|
+
/** 钉住的摘要(有钉子时) */
|
|
400
|
+
pinned?: string;
|
|
401
|
+
/** 按同一份名单、用今天的供货重算出的摘要(能算时) */
|
|
402
|
+
current?: string;
|
|
403
|
+
/** 漂移时:钉住的字节还在资产库里吗(在 ⇒ 这次漂移可恢复) */
|
|
404
|
+
recoverable?: boolean;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/** 对账所需的最小记录形状 */
|
|
408
|
+
export interface ReconcilableRecord {
|
|
409
|
+
name?: string;
|
|
410
|
+
version?: number;
|
|
411
|
+
assets?: unknown;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* 拿这一版的钉子对今天的供货。这是"回滚只回滚了一半"第一次可判定的地方:
|
|
416
|
+
* `reconcilePinnedAssets(v3 记录)` 回答"今天部署的组件 CSS 与 v3 发布那天是否一致"。
|
|
417
|
+
*
|
|
418
|
+
* 判定只有四种,且**都不抛**:对账是读路径上的诊断,它自己绝不能成为新的失败面。
|
|
419
|
+
*/
|
|
420
|
+
export function reconcilePinnedAssets(
|
|
421
|
+
record: ReconcilableRecord,
|
|
422
|
+
options: { store?: RegistryAssetStore } = {},
|
|
423
|
+
): SomaAssetReconciliation {
|
|
424
|
+
const who = `${record?.name ?? '<未命名>'} v${record?.version ?? '?'}`;
|
|
425
|
+
const supply = currentAssetSupply();
|
|
426
|
+
if (!supply) {
|
|
427
|
+
return {
|
|
428
|
+
status: 'unavailable',
|
|
429
|
+
issues: [
|
|
430
|
+
`现状:页面 ${who} 无法对账——宿主没有注册样式供货来源。`
|
|
431
|
+
+ '问题:组件 CSS 住在组件库,core 拿不到它,于是"今天的字节与发布那天是否一致"'
|
|
432
|
+
+ '这个问题在这个进程里没有判据;不判会让回滚的样式漂移一直不被发现。'
|
|
433
|
+
+ '建议:宿主服务端启动时接一次——'
|
|
434
|
+
+ "setPublishedAssetSource(() => ({ ...composed.styles, "
|
|
435
|
+
+ "dependencies: composed.styles.deps, packs: { 'soma-ui': somaUiVersion } }))。",
|
|
436
|
+
],
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const pin = readPin(record?.assets);
|
|
441
|
+
if (!pin) {
|
|
442
|
+
return {
|
|
443
|
+
status: 'unpinned',
|
|
444
|
+
issues: [
|
|
445
|
+
`现状:页面 ${who} 的版本记录里没有可用的资产钉子。`
|
|
446
|
+
+ '问题:没有钉子就没有"发布那天用的是哪一份 CSS",回滚到这一版时样式漂移无从判定'
|
|
447
|
+
+ '(钉子落地之前发布的旧版本属于此列)。'
|
|
448
|
+
+ '建议:重新发布一次这一版(publish 会按当前供货钉住),'
|
|
449
|
+
+ '或按版本号取出声明后重新 publish 以补钉。',
|
|
450
|
+
],
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
const componentCss = pin.assets.find((asset) => asset.kind === 'component-css');
|
|
455
|
+
if (!componentCss) {
|
|
456
|
+
return {
|
|
457
|
+
status: 'unpinned',
|
|
458
|
+
issues: [
|
|
459
|
+
`现状:页面 ${who} 的钉子里没有 component-css 这一项。`
|
|
460
|
+
+ '问题:钉子存在但不含组件 CSS,对账没有可比对的对象。'
|
|
461
|
+
+ '建议:重新发布一次这一版以补钉。',
|
|
462
|
+
],
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
const assembled = assembleComponentCss(supply, componentCss.members);
|
|
467
|
+
const current = somaAssetDigest(assembled.css);
|
|
468
|
+
if (current === componentCss.digest) {
|
|
469
|
+
return { status: 'match', issues: [], pinned: componentCss.digest, current };
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
const store = options.store ?? getRegistryAssetStore();
|
|
473
|
+
let recoverable = false;
|
|
474
|
+
// 资产库查询失败不抛(对账是读路径上的诊断),但也**不吞**:它与"字节已不在库"是两回事,
|
|
475
|
+
// 混成一句"无法按摘要恢复"会把人引去回退组件库,而该修的是资产库的访问。
|
|
476
|
+
let lookupFailure: string | null = null;
|
|
477
|
+
try {
|
|
478
|
+
recoverable = store.has(componentCss.digest);
|
|
479
|
+
} catch (error) {
|
|
480
|
+
lookupFailure = message(error);
|
|
481
|
+
}
|
|
482
|
+
const currentBytes = Buffer.byteLength(assembled.css, 'utf8');
|
|
483
|
+
return {
|
|
484
|
+
status: 'drift',
|
|
485
|
+
pinned: componentCss.digest,
|
|
486
|
+
current,
|
|
487
|
+
recoverable,
|
|
488
|
+
issues: [
|
|
489
|
+
`现状:页面 ${who} 发布时钉住的组件 CSS 是 ${componentCss.digest}`
|
|
490
|
+
+ `(${componentCss.bytes} 字节、${componentCss.members.length} 个构件),`
|
|
491
|
+
+ `按今天的供货对同一份名单重算得到 ${current}(${currentBytes} 字节)。`
|
|
492
|
+
+ '问题:声明回滚了,样式没有跟着回滚——这一版现在渲染出来的间距/字号/断点'
|
|
493
|
+
+ '不是它发布那天的样子,而页面照常打开、没有任何报错。'
|
|
494
|
+
+ driftAdvice(recoverable, lookupFailure),
|
|
495
|
+
],
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/** 漂移时的"建议"一段:按资产库能不能答、答了什么分三种说法 */
|
|
500
|
+
function driftAdvice(recoverable: boolean, lookupFailure: string | null): string {
|
|
501
|
+
if (lookupFailure !== null) {
|
|
502
|
+
return `建议:资产库查询失败(${lookupFailure}),判断不了钉住的字节还在不在——`
|
|
503
|
+
+ '先修资产库的访问(SOMA_REGISTRY_ASSET_DIR 的权限与挂载,或 setRegistryAssetStore 接的自定义后端),'
|
|
504
|
+
+ '再重新对账;在此之前不要据此回退组件库。';
|
|
505
|
+
}
|
|
506
|
+
if (recoverable) {
|
|
507
|
+
return '建议:钉住的字节还在资产库里,可按摘要取回(getRegistryAssetStore().read(digest))'
|
|
508
|
+
+ '并作为这一版的样式表下发;或把组件库回退到与该摘要一致的版本。';
|
|
509
|
+
}
|
|
510
|
+
return '建议:钉住的字节**已不在资产库**,这次漂移无法按摘要恢复。'
|
|
511
|
+
+ '先确认资产目录与页面目录是否同卷'
|
|
512
|
+
+ '(SOMA_REGISTRY_ASSET_DIR / SOMA_PAGE_REGISTRY_DIR),'
|
|
513
|
+
+ '再把组件库回退到与该摘要一致的版本;此后新发布的版本会重新钉住字节。';
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/** 从一份来源不明的钉子里挑出 component-css 那一项;形状不对返回 undefined */
|
|
517
|
+
function pickComponentCss(pin: SomaAssetPin | undefined): SomaPinnedAsset | undefined {
|
|
518
|
+
const entry = readPin(pin)?.assets.find((asset) => asset.kind === 'component-css');
|
|
519
|
+
return entry;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/** 读钉子:形状不对一律当"没有钉子"。存量记录可能带任何东西,读路径不为它抛 */
|
|
523
|
+
function readPin(value: unknown): SomaAssetPin | null {
|
|
524
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
|
|
525
|
+
const raw = value as Record<string, unknown>;
|
|
526
|
+
if (raw.pinVersion !== ASSET_PIN_VERSION) return null;
|
|
527
|
+
if (typeof raw.compilerVersion !== 'string' || raw.compilerVersion === '') return null;
|
|
528
|
+
if (!Array.isArray(raw.assets)) return null;
|
|
529
|
+
const assets: SomaPinnedAsset[] = [];
|
|
530
|
+
for (const entry of raw.assets as Array<Record<string, unknown>>) {
|
|
531
|
+
if (!entry || typeof entry !== 'object') continue;
|
|
532
|
+
if (entry.kind !== 'component-css') continue;
|
|
533
|
+
if (!isSomaAssetDigest(entry.digest)) continue;
|
|
534
|
+
if (typeof entry.bytes !== 'number' || !Number.isInteger(entry.bytes) || entry.bytes < 0) continue;
|
|
535
|
+
if (!Array.isArray(entry.members)) continue;
|
|
536
|
+
const members = (entry.members as unknown[])
|
|
537
|
+
.filter((name): name is string => typeof name === 'string');
|
|
538
|
+
assets.push({ kind: 'component-css', digest: entry.digest, bytes: entry.bytes, members });
|
|
539
|
+
}
|
|
540
|
+
if (assets.length === 0) return null;
|
|
541
|
+
return { pinVersion: ASSET_PIN_VERSION, compilerVersion: raw.compilerVersion, assets };
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/** 供货包版本表:键升序重建,保证同一份供货产出逐字节相同的 JSON */
|
|
545
|
+
function sortedPacks(
|
|
546
|
+
packs: Readonly<Record<string, string>> | undefined,
|
|
547
|
+
): Record<string, string> | undefined {
|
|
548
|
+
const names = validPackNames(packs);
|
|
549
|
+
if (!names) return undefined;
|
|
550
|
+
const result: Record<string, string> = {};
|
|
551
|
+
for (const name of names) result[name] = packs![name];
|
|
552
|
+
return result;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
function message(error: unknown): string {
|
|
556
|
+
return error instanceof Error ? error.message : String(error);
|
|
557
|
+
}
|
|
@@ -10,12 +10,18 @@ import { readQueryParams } from '../service-utils';
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* GET /api/soma-registry/pages/list — 页面摘要清单(分页协议)。
|
|
13
|
-
* 查询参数(全部可选):app / keyword /
|
|
13
|
+
* 查询参数(全部可选):app / keyword / status(published/archived,闭集外的值按未提供
|
|
14
|
+
* 处理)/ includeArchived=1(需 read-private)/ limit / offset。
|
|
14
15
|
* 响应:{ schemaVersion, pages: [{ name, latestVersion, updatedAt, status, app, tags, title? }], total }。
|
|
15
16
|
*
|
|
16
|
-
* **可见性按主体分层**:无 `read-private` 作用域的调用方只看得到 published
|
|
17
|
-
*
|
|
17
|
+
* **可见性按主体分层**:无 `read-private` 作用域的调用方只看得到 published 页面——这条
|
|
18
|
+
* 铁律不受 `status` 影响:非特权主体传 status=archived 依旧看不到任何已下架页面(可见性
|
|
19
|
+
* 过滤先于 status 精筛生效)。草稿名与已下架页面同样是信息——按主体过滤而不是整端点鉴权:
|
|
18
20
|
* 画廊跑在浏览器里、拿不到管理凭据,端点一鉴权它就瞎了。
|
|
21
|
+
*
|
|
22
|
+
* `status` 与 `includeArchived` 的关系:`status` 更具体,选定后覆盖 `includeArchived`
|
|
23
|
+
* 的缺省收窄行为(例如 status=archived 无需再传 includeArchived=1);不传 `status`
|
|
24
|
+
* 时行为不受影响。
|
|
19
25
|
*/
|
|
20
26
|
export default class ListService implements IService {
|
|
21
27
|
async get(req: SomaServiceRequest): Promise<Response> {
|
|
@@ -28,6 +34,7 @@ export default class ListService implements IService {
|
|
|
28
34
|
keyword: readStringParam(params.keyword),
|
|
29
35
|
includeArchived: privileged
|
|
30
36
|
&& (params.includeArchived === '1' || params.includeArchived === 'true'),
|
|
37
|
+
status: readStatusParam(params.status),
|
|
31
38
|
limit: readIntParam(params.limit),
|
|
32
39
|
offset: readIntParam(params.offset),
|
|
33
40
|
};
|
|
@@ -43,6 +50,11 @@ function readStringParam(raw: string | undefined): string | undefined {
|
|
|
43
50
|
return typeof raw === 'string' && raw !== '' ? raw : undefined;
|
|
44
51
|
}
|
|
45
52
|
|
|
53
|
+
/** status 闭集:非 published/archived 按未提供处理(协议宽进严出,不报错) */
|
|
54
|
+
function readStatusParam(raw: string | undefined): 'published' | 'archived' | undefined {
|
|
55
|
+
return raw === 'published' || raw === 'archived' ? raw : undefined;
|
|
56
|
+
}
|
|
57
|
+
|
|
46
58
|
/** 分页参数:非法值(非整数 / 负数)按未提供处理,协议宽进严出 */
|
|
47
59
|
function readIntParam(raw: string | undefined): number | undefined {
|
|
48
60
|
if (raw === undefined || raw === null || raw === '') {
|