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
package/core/index.ts
CHANGED
|
@@ -69,12 +69,20 @@ export type {
|
|
|
69
69
|
SomaDataWriteEndpoint,
|
|
70
70
|
SomaDataSubmitResult,
|
|
71
71
|
SomaDataPort,
|
|
72
|
+
// 对象级语义(REQ-014 期 2'.1):演绎链与业务方都要按结构消费它们,
|
|
73
|
+
// 不公开的话每个消费方只能本地重声明一份——那正是「同一个概念多份抄本」的起点
|
|
74
|
+
SomaDataObjectRoles,
|
|
75
|
+
SomaDataObjectRelation,
|
|
76
|
+
SomaDataRelationCardinality,
|
|
72
77
|
} from './shared/types/data-config.types';
|
|
73
78
|
// 字段类型的唯一真源(值导出):块解析器与 soma-ui 的双态映射表都消费它,
|
|
74
79
|
// 消费方不得再手抄一份清单——四份手写副本里漏改一份,就是「一处合法、一处静默按 text 渲染」。
|
|
75
80
|
export {
|
|
76
81
|
SOMA_DATA_FIELD_TYPES,
|
|
77
82
|
SOMA_DATA_FIELD_TYPE_ALIASES,
|
|
83
|
+
// 角色名与关系基数同样是封闭集,同样只准有一份(理由同上一段)
|
|
84
|
+
SOMA_DATA_OBJECT_ROLES,
|
|
85
|
+
SOMA_DATA_RELATION_CARDINALITIES,
|
|
78
86
|
} from './shared/types/data-config.types';
|
|
79
87
|
|
|
80
88
|
// 字段谓词图(REQ-010 S1b):三个消费者共用的封闭布尔代数——
|
|
@@ -311,10 +319,15 @@ export {
|
|
|
311
319
|
} from './shared/component/field-lines';
|
|
312
320
|
export {
|
|
313
321
|
deriveContractSample,
|
|
322
|
+
deriveContractPreviewSample,
|
|
314
323
|
deriveFieldSample,
|
|
315
324
|
hasRenderableSample,
|
|
316
325
|
} from './shared/component/derive-sample';
|
|
317
|
-
export type {
|
|
326
|
+
export type {
|
|
327
|
+
DerivePreviewSampleResult,
|
|
328
|
+
DeriveSampleResult,
|
|
329
|
+
SampleGap,
|
|
330
|
+
} from './shared/component/derive-sample';
|
|
318
331
|
// 组件级令牌(REQ-009 M-1)的命名规则。宿主与闸门都要按同一条规则拼名字——
|
|
319
332
|
// 各自拼一遍的话,主题的 `components` 段覆盖不上任何东西,而覆盖不上是静默的。
|
|
320
333
|
export {
|
|
@@ -349,7 +362,12 @@ export type { SomaHtmlSanitizer, SomaHtmlSanitizeResult } from './client/securit
|
|
|
349
362
|
export type { SomaDiagnosticsSnapshot } from './client/diagnostics/SomaDiagnostics';
|
|
350
363
|
export { matchGlobPath } from './client/engine/property-watcher';
|
|
351
364
|
export { extractConfigFromDomainClass } from './client/parser/annotation-extractor';
|
|
352
|
-
|
|
365
|
+
// Rollup is a build-time integration and must not be re-exported from the
|
|
366
|
+
// browser-facing root barrel. Keeping it here makes bundlers traverse the
|
|
367
|
+
// CJS precompiler (`soma-precompile.js`) while compiling every client that
|
|
368
|
+
// imports `soma-core`, which fails in a browser because `module` is absent.
|
|
369
|
+
// Consumers that need Rollup use the explicit `soma-core/compiler/rollup`
|
|
370
|
+
// entry instead.
|
|
353
371
|
export { Page, Show, ShowList, Event } from './client/base/decorators';
|
|
354
372
|
export { runAsync } from './client/base/runAsync';
|
|
355
373
|
export type { AsyncStateHost } from './client/base/runAsync';
|
|
@@ -478,9 +496,10 @@ export {
|
|
|
478
496
|
type HtmlAnchorIndex,
|
|
479
497
|
type HtmlAnchorInfo,
|
|
480
498
|
} from './build/blocks/html-index';
|
|
481
|
-
//
|
|
482
|
-
//
|
|
483
|
-
|
|
499
|
+
// `compilePageAssets` 是服务端/测试的构建期入口,不能从这个浏览器根 barrel
|
|
500
|
+
// 导出。它会装载声明编译器(含 Node 专用的 OOUI 内容指纹),而 Host bootstrap
|
|
501
|
+
// 从根包导入运行时 API;把它放在这里会让 Webpack 尝试解析 `node:crypto`。
|
|
502
|
+
// 服务端调用方请通过 `soma-core/server/page-assets` 延迟加载。
|
|
484
503
|
export {
|
|
485
504
|
compileSomaBlocks,
|
|
486
505
|
type CompiledSomaBlocks,
|
|
@@ -52,8 +52,14 @@ export function loadHostService(segments: string[]): IService | null {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
try {
|
|
55
|
-
const
|
|
56
|
-
|
|
55
|
+
const loaded = getJiti(hostDir)(filePath) as unknown;
|
|
56
|
+
// Jiti with `interopDefault: true` returns a lone default export directly.
|
|
57
|
+
// A default class that extends another default-exported class can inherit a
|
|
58
|
+
// static `.default` from its base, so reading `loaded.default` first would
|
|
59
|
+
// instantiate the base service and silently drop the Host subclass setup.
|
|
60
|
+
const ServiceClass = typeof loaded === 'function'
|
|
61
|
+
? loaded as new () => IService
|
|
62
|
+
: (loaded as { default?: new () => IService } | null)?.default;
|
|
57
63
|
if (!ServiceClass || typeof ServiceClass !== 'function') {
|
|
58
64
|
console.warn(`[soma-core][接口] ${filePath} missing default export`);
|
|
59
65
|
return null;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-only declaration injection scanner public entry.
|
|
3
|
+
*
|
|
4
|
+
* 刻意不 `import 'server-only'`:soma-ai 的声明校验器在经 jiti 加载的宿主服务里
|
|
5
|
+
* import 本入口,server-only 在纯 Node 语境下会抛错(理由同 `server/page-declaration.ts`)。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
scanDeclarationSafety,
|
|
10
|
+
type ScannableDeclaration,
|
|
11
|
+
} from './registry/validation/declaration-safety-scan';
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
// 发布页运行时产物缓存:请求路径上的 SOMA DSL 编译,同一份声明只做一次。
|
|
2
|
+
//
|
|
3
|
+
// 这个失败模式为什么是静默的?
|
|
4
|
+
//
|
|
5
|
+
// 一、慢是没有红灯的。`/soma/page` 是 `dynamic='force-dynamic'` + `cache-control: no-store`,
|
|
6
|
+
// 每一次取页都把 Registry 里的 canonical 声明重新编译一遍。页面照常渲染、接口照常 200,
|
|
7
|
+
// 监控里看不见任何异常,只有 P99 被慢慢抬起来;等演绎链(semantic→…→artifact)接进来,
|
|
8
|
+
// 抬的幅度还会随声明规模一起长。没有异常、没有告警,只有一条谁也说不出源头的曲线——
|
|
9
|
+
// 这正是「性能退化」比「功能报错」更难查的原因:它不发生在任何一次请求里,
|
|
10
|
+
// 只发生在所有请求的分布上。
|
|
11
|
+
//
|
|
12
|
+
// 二、产物会随引擎漂移,而版本号一动不动。请求期编译让运行时产物变成
|
|
13
|
+
// `(声明, 当前进程里跑着的编译器)` 的函数。同一份 v3 声明,引擎升一版就可能编出不同产物,
|
|
14
|
+
// Registry 记的却还是 v3——「回滚到 v3」回的是声明,不是产物。若缓存键只取声明哈希,
|
|
15
|
+
// 一次热升级(同进程被替换、多副本灰度)就能让同一个 key 端出两个时代的产物,
|
|
16
|
+
// 并且两边都不报错。所以键里必须钉进编译身份,判据与
|
|
17
|
+
// `registry/declaration-precompiler.ts` 的 `isCompiledUsable` 同源:
|
|
18
|
+
// **缓存是缓存,不是真理;身份对不上就整份丢弃、重新编译。**
|
|
19
|
+
//
|
|
20
|
+
// 编译身份是三样,缺一样就有一条换了引擎还端旧产物的路:
|
|
21
|
+
// · 编译器版本(`DECLARATION_COMPILER_VERSION`,引擎那一维);
|
|
22
|
+
// · 供货指纹(`currentAssetSupplyKey()`,词表版本那一维——isCompiledUsable 的第三道闸);
|
|
23
|
+
// · 本进程演绎引擎的身份(`resolveOouiEngine()` 那个对象)。
|
|
24
|
+
// 后两样曾经不在键里:宿主换了供货(组件库升版)或 `registerOouiPacks(..., { override: true })`
|
|
25
|
+
// 换了词汇包之后,同一份声明编出来的已是另一份产物,而键没变——缓存照样命中、
|
|
26
|
+
// 端出上一套引擎的产物,也就走不到 `published-page-assets.ts` 只在未命中时才打的
|
|
27
|
+
// 漂移告警,一行日志都没有。
|
|
28
|
+
// 引擎身份只在进程内有意义(对象身份,不跨进程),所以它只进这份进程内缓存的键,
|
|
29
|
+
// 不进落库产物;落库产物跨进程的那一维由供货指纹承担。
|
|
30
|
+
//
|
|
31
|
+
// 三、无界缓存不会崩,只会胀。发布页按「声明内容」寻址,页面数 × 历史版本数没有上界,
|
|
32
|
+
// 一个不设容量的 Map 在长活进程里就是一条只涨不落的内存曲线,同样不报错。
|
|
33
|
+
// 所以这里是有容量的 LRU,容量与命中数可被 `publishedPageArtifactCacheStats()` 观测。
|
|
34
|
+
|
|
35
|
+
import { createHash } from 'node:crypto';
|
|
36
|
+
import { compilePageDeclaration } from '../../build/compiler/page-declaration-compiler';
|
|
37
|
+
import { resolveOouiEngine } from '../../build/ooui/engine-slot';
|
|
38
|
+
import { DECLARATION_COMPILER_VERSION } from '../registry/declaration-precompiler';
|
|
39
|
+
import { currentAssetSupplyKey } from '../registry/publish-asset-pin';
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 参与编译、因而必须参与哈希的声明字段闭集。
|
|
43
|
+
* `notes` 等元信息不进编译器,也不进键——把它算进去只会让相同产物反复重算。
|
|
44
|
+
*/
|
|
45
|
+
export interface PublishedPageDeclaration {
|
|
46
|
+
html: string;
|
|
47
|
+
uiYaml: string;
|
|
48
|
+
eventYaml?: string;
|
|
49
|
+
styleYaml?: string;
|
|
50
|
+
dataYaml?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** 浏览器最终收到的运行时资产。缓存条目一律冻结:共享对象被就地改写是另一种静默污染。 */
|
|
54
|
+
export interface PublishedPageArtifact {
|
|
55
|
+
readonly uiYaml: string;
|
|
56
|
+
readonly eventYaml: string;
|
|
57
|
+
readonly dataYaml?: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface PublishedPageArtifactResult {
|
|
61
|
+
artifact: PublishedPageArtifact;
|
|
62
|
+
/** true = 命中缓存,本次没有重新编译。调用方据此决定要不要打漂移日志。 */
|
|
63
|
+
cached: boolean;
|
|
64
|
+
/** 缓存键(编译身份 + 声明指纹),排障时可直接比对。 */
|
|
65
|
+
key: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface PublishedPageArtifactCacheStats {
|
|
69
|
+
size: number;
|
|
70
|
+
capacity: number;
|
|
71
|
+
hits: number;
|
|
72
|
+
misses: number;
|
|
73
|
+
evictions: number;
|
|
74
|
+
compilerVersion: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
interface CacheEntry {
|
|
78
|
+
/** 产出这份产物时的编译身份(`compileIdentity()` 的串形) */
|
|
79
|
+
identity: string;
|
|
80
|
+
artifact: PublishedPageArtifact;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 容量上限。发布页产物是几 KB 量级的字符串,64 份足够覆盖一个进程的活跃页面集,
|
|
85
|
+
* 又不会让「历史版本被逐个访问」把常驻内存推上去。
|
|
86
|
+
*/
|
|
87
|
+
const CACHE_CAPACITY = 64;
|
|
88
|
+
|
|
89
|
+
const cache = new Map<string, CacheEntry>();
|
|
90
|
+
let hits = 0;
|
|
91
|
+
let misses = 0;
|
|
92
|
+
let evictions = 0;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 声明指纹。逐字段**带长度前缀**地喂哈希:直接拼接会让
|
|
96
|
+
* `{uiYaml:'ab', dataYaml:''}` 与 `{uiYaml:'a', dataYaml:'b'}` 落到同一个键——
|
|
97
|
+
* 那种碰撞不会抛错,只会让 A 页面拿到 B 页面的产物。
|
|
98
|
+
*/
|
|
99
|
+
export function declarationFingerprint(declaration: PublishedPageDeclaration): string {
|
|
100
|
+
const hash = createHash('sha256');
|
|
101
|
+
const fields: ReadonlyArray<readonly [string, string]> = [
|
|
102
|
+
['html', declaration.html],
|
|
103
|
+
['uiYaml', declaration.uiYaml],
|
|
104
|
+
['eventYaml', declaration.eventYaml ?? ''],
|
|
105
|
+
['styleYaml', declaration.styleYaml ?? ''],
|
|
106
|
+
['dataYaml', declaration.dataYaml ?? ''],
|
|
107
|
+
];
|
|
108
|
+
for (const [field, value] of fields) {
|
|
109
|
+
const bytes = Buffer.from(value, 'utf8');
|
|
110
|
+
hash.update(`${field}:${bytes.length}:`);
|
|
111
|
+
hash.update(bytes);
|
|
112
|
+
}
|
|
113
|
+
return hash.digest('hex');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 进程内演绎引擎的身份号:同一个引擎对象恒得同一个号;换了对象(`override` 重注册、
|
|
118
|
+
* 复位后再注册)就换号;没注册引擎单独一档。
|
|
119
|
+
*
|
|
120
|
+
* 取对象身份而不取词汇包指纹:指纹住在槽位内部、不对外;而对这份**进程内**缓存来说
|
|
121
|
+
* 对象身份恰好就是判据——幂等的重复注册返回的是同一个引擎对象(不换号、不白白重编),
|
|
122
|
+
* 真换了词汇包一定是新对象。WeakMap 不留住旧引擎,换下来的引擎照常被回收。
|
|
123
|
+
*/
|
|
124
|
+
const engineIds = new WeakMap<object, number>();
|
|
125
|
+
let nextEngineId = 1;
|
|
126
|
+
|
|
127
|
+
function oouiEngineIdentity(engine: object | undefined): string {
|
|
128
|
+
if (!engine) return 'ooui:none';
|
|
129
|
+
let id = engineIds.get(engine);
|
|
130
|
+
if (id === undefined) {
|
|
131
|
+
id = nextEngineId;
|
|
132
|
+
nextEngineId += 1;
|
|
133
|
+
engineIds.set(engine, id);
|
|
134
|
+
}
|
|
135
|
+
return `ooui:${id}`;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* 当前的编译身份:编译器版本 + 供货指纹 + 演绎引擎(见文件头「二」)。
|
|
140
|
+
*
|
|
141
|
+
* 每次取页现读,不缓存:供货与引擎都可能在进程内被宿主换掉,缓存住的身份
|
|
142
|
+
* 恰好就是那条"换了引擎还端旧产物"的路。两样都是微秒级——供货指纹只摘要
|
|
143
|
+
* `packs` 的名字与版本号(`currentAssetSupplyKey` 的头注释说明了为什么不哈希全库字节)。
|
|
144
|
+
* 宿主没报供货时单独一档(`supply:-`),不与报了的混用。
|
|
145
|
+
*/
|
|
146
|
+
function compileIdentity(compilerVersion: string): string {
|
|
147
|
+
return `${compilerVersion} ${currentAssetSupplyKey() ?? 'supply:-'} ${oouiEngineIdentity(resolveOouiEngine())}`;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 缓存键 = 编译身份 + 声明指纹。任一变化都必然换键,也就必然重算。
|
|
152
|
+
*
|
|
153
|
+
* `identity` 缺省现算;`resolvePublishedPageArtifact` 传入它已算好的那一份——
|
|
154
|
+
* 同一次取页里键与条目核对用的必须是同一个身份,也不必把宿主的供货来源问两遍。
|
|
155
|
+
*/
|
|
156
|
+
export function publishedPageArtifactKey(
|
|
157
|
+
declaration: PublishedPageDeclaration,
|
|
158
|
+
compilerVersion: string = DECLARATION_COMPILER_VERSION,
|
|
159
|
+
identity: string = compileIdentity(compilerVersion),
|
|
160
|
+
): string {
|
|
161
|
+
return `${identity} ${declarationFingerprint(declaration)}`;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* 无缓存编译:把统一声明编成运行时资产。
|
|
166
|
+
* 传给编译器的字段与参与哈希的字段是同一个闭集——只有这样,
|
|
167
|
+
* 「键相同」才真的等价于「编译输入相同」。
|
|
168
|
+
*/
|
|
169
|
+
export function compilePublishedPageArtifact(
|
|
170
|
+
declaration: PublishedPageDeclaration,
|
|
171
|
+
): PublishedPageArtifact {
|
|
172
|
+
const compiled = compilePageDeclaration({
|
|
173
|
+
html: declaration.html,
|
|
174
|
+
uiYaml: declaration.uiYaml,
|
|
175
|
+
...(declaration.eventYaml ? { eventYaml: declaration.eventYaml } : {}),
|
|
176
|
+
...(declaration.styleYaml ? { styleYaml: declaration.styleYaml } : {}),
|
|
177
|
+
...(declaration.dataYaml ? { dataYaml: declaration.dataYaml } : {}),
|
|
178
|
+
});
|
|
179
|
+
return Object.freeze({
|
|
180
|
+
uiYaml: compiled.runtimeAssets.uiYaml,
|
|
181
|
+
eventYaml: compiled.runtimeAssets.eventYaml,
|
|
182
|
+
...(compiled.runtimeAssets.dataYaml ? { dataYaml: compiled.runtimeAssets.dataYaml } : {}),
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* 取产物:命中缓存直接返回,否则编译并落缓存。
|
|
188
|
+
*
|
|
189
|
+
* 编译抛错**不缓存**:失败面必须在每次请求上如实复现,
|
|
190
|
+
* 把一次失败钉进缓存等于把偶发问题变成常驻问题。
|
|
191
|
+
*/
|
|
192
|
+
export function resolvePublishedPageArtifact(
|
|
193
|
+
declaration: PublishedPageDeclaration,
|
|
194
|
+
options: { compilerVersion?: string } = {},
|
|
195
|
+
): PublishedPageArtifactResult {
|
|
196
|
+
const compilerVersion = options.compilerVersion ?? DECLARATION_COMPILER_VERSION;
|
|
197
|
+
const identity = compileIdentity(compilerVersion);
|
|
198
|
+
const key = publishedPageArtifactKey(declaration, compilerVersion, identity);
|
|
199
|
+
|
|
200
|
+
const entry = cache.get(key);
|
|
201
|
+
if (entry) {
|
|
202
|
+
// 身份闸(与 isCompiledUsable 同源的判据):键里已含身份,这里是第二道保险——
|
|
203
|
+
// 万一将来键的构成被改动,条目也不会带着别的编译身份被端出去。
|
|
204
|
+
if (entry.identity === identity) {
|
|
205
|
+
cache.delete(key);
|
|
206
|
+
cache.set(key, entry);
|
|
207
|
+
hits += 1;
|
|
208
|
+
return { artifact: entry.artifact, cached: true, key };
|
|
209
|
+
}
|
|
210
|
+
cache.delete(key);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
misses += 1;
|
|
214
|
+
const artifact = compilePublishedPageArtifact(declaration);
|
|
215
|
+
if (cache.size >= CACHE_CAPACITY) {
|
|
216
|
+
const oldest = cache.keys().next();
|
|
217
|
+
if (!oldest.done) {
|
|
218
|
+
cache.delete(oldest.value);
|
|
219
|
+
evictions += 1;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
cache.set(key, { identity, artifact });
|
|
223
|
+
return { artifact, cached: false, key };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** 测试与排障用:清空缓存与计数。生产路径不调用。 */
|
|
227
|
+
export function resetPublishedPageArtifactCache(): void {
|
|
228
|
+
cache.clear();
|
|
229
|
+
hits = 0;
|
|
230
|
+
misses = 0;
|
|
231
|
+
evictions = 0;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** 观测点:没有这个,「缓存到底有没有生效」只能靠猜。 */
|
|
235
|
+
export function publishedPageArtifactCacheStats(): PublishedPageArtifactCacheStats {
|
|
236
|
+
return {
|
|
237
|
+
size: cache.size,
|
|
238
|
+
capacity: CACHE_CAPACITY,
|
|
239
|
+
hits,
|
|
240
|
+
misses,
|
|
241
|
+
evictions,
|
|
242
|
+
compilerVersion: DECLARATION_COMPILER_VERSION,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
// 发布页路径接线:Registry canonical 声明 → 服务端内存编译 → Host 运行时资产。
|
|
2
|
+
//
|
|
3
|
+
// 这条路径上有两件事是不出声的,产物缓存与版本闸就是冲它们去的:
|
|
4
|
+
// 1. 编译在**请求路径**上。取一次页编一次,功能全对、监控全绿,只有耗时在涨。
|
|
5
|
+
// `resolvePublishedPageArtifact` 用「声明指纹 + 编译身份」把它压成一次
|
|
6
|
+
// (编译身份 = 编译器版本 + 供货指纹 + 本进程演绎引擎,见 published-page-artifact-cache.ts)。
|
|
7
|
+
// 2. 产物随引擎漂移。发布期落库的 `record.compiled` 带 `compilerVersion`,
|
|
8
|
+
// 而这里是按**当前进程**的编译器现编——两者版本不一致时,用户以为在看 v3 的产物,
|
|
9
|
+
// 实际看的是「v3 声明喂给今天的引擎」。这不会报错,所以必须由日志说出来:
|
|
10
|
+
// `isCompiledUsable` 是 Registry 侧既有的同一道版本闸,判据不另起一套。
|
|
2
11
|
|
|
3
|
-
import { compilePageDeclaration } from '../../build/compiler/page-declaration-compiler';
|
|
4
12
|
import { publishedPageSlugFromPath } from '../../shared/published-page-route';
|
|
13
|
+
import {
|
|
14
|
+
DECLARATION_COMPILER_VERSION,
|
|
15
|
+
isCompiledUsable,
|
|
16
|
+
} from '../registry/declaration-precompiler';
|
|
5
17
|
import { getPageRegistryRepository } from '../registry/page-registry-repository';
|
|
18
|
+
import type { PageVersionRecord } from '../registry/page-registry-store';
|
|
19
|
+
import { currentAssetSupplyKey } from '../registry/publish-asset-pin';
|
|
20
|
+
import { resolvePublishedPageArtifact } from './published-page-artifact-cache';
|
|
6
21
|
|
|
7
22
|
/** Registry `myworkspace` 的正式地址是 `/myworkspace`;兼容读取旧 `/pages/myworkspace`。 */
|
|
8
23
|
export const registryPageNameFromPath = publishedPageSlugFromPath;
|
|
@@ -13,18 +28,42 @@ export async function loadPublishedRegistryPageAssets(pagePath: string) {
|
|
|
13
28
|
if (!name) return null;
|
|
14
29
|
|
|
15
30
|
const record = await getPageRegistryRepository().get(name);
|
|
16
|
-
const
|
|
31
|
+
const { artifact, cached } = resolvePublishedPageArtifact(record.declaration);
|
|
32
|
+
if (!cached) warnOnCompilerDrift(record);
|
|
33
|
+
|
|
17
34
|
return {
|
|
18
35
|
base: record.name,
|
|
19
36
|
sourceType: 'registry' as const,
|
|
20
37
|
sourcePackage: null,
|
|
21
38
|
html: record.declaration.html,
|
|
22
|
-
ui:
|
|
23
|
-
event:
|
|
39
|
+
ui: artifact.uiYaml,
|
|
40
|
+
event: artifact.eventYaml,
|
|
24
41
|
styleYaml: '',
|
|
25
|
-
...(
|
|
42
|
+
...(artifact.dataYaml ? { dataYaml: artifact.dataYaml } : {}),
|
|
26
43
|
localeYaml: '',
|
|
27
44
|
appConfigYaml: '',
|
|
28
45
|
registryPage: { name: record.name, version: record.version },
|
|
29
46
|
};
|
|
30
47
|
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 只在真正重新编译时(缓存未命中)检查一次,命中缓存不再重复刷屏;
|
|
51
|
+
* 条目被 LRU 淘汰后最多再说一遍,噪声由缓存容量天然封顶。
|
|
52
|
+
*/
|
|
53
|
+
function warnOnCompilerDrift(record: PageVersionRecord): void {
|
|
54
|
+
if (isCompiledUsable(record.compiled)) return;
|
|
55
|
+
const stored = record.compiled?.compilerVersion ?? '无落库产物';
|
|
56
|
+
// 版本号一样也可能判不可用:供货指纹相左(组件库在发布之后换过版本)。
|
|
57
|
+
// 那时只报两个一模一样的版本号,读的人会以为这条告警是误报。
|
|
58
|
+
const storedSupply = record.compiled?.assetSupplyKey;
|
|
59
|
+
const currentSupply = currentAssetSupplyKey();
|
|
60
|
+
const supplyDrift = storedSupply && currentSupply && storedSupply !== currentSupply
|
|
61
|
+
? `落库时的供货指纹为 ${storedSupply},当前为 ${currentSupply}(组件库在发布之后换过);`
|
|
62
|
+
: '';
|
|
63
|
+
console.warn(
|
|
64
|
+
`[soma-core][缓存] 发布页 ${record.name} v${record.version} 的落库产物版本为 ${stored},`
|
|
65
|
+
+ `当前进程编译器版本为 ${DECLARATION_COMPILER_VERSION};${supplyDrift}`
|
|
66
|
+
+ '本次按当前编译器重新编译。回滚只回滚声明、不回滚产物,'
|
|
67
|
+
+ '若需产物级回滚请在发布期落库运行时资产,并让本路径直接读取 record.compiled。',
|
|
68
|
+
);
|
|
69
|
+
}
|
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
import { filterMockEnvironment } from './environment-policy.mjs';
|
|
11
11
|
|
|
12
12
|
const MOCK_COMMANDS = new Set(['dev', 'build', 'start']);
|
|
13
|
-
const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../..');
|
|
14
13
|
const DEFAULT_PRELOAD_URL = pathToFileURL(
|
|
15
14
|
path.join(path.dirname(fileURLToPath(import.meta.url)), 'preload.mjs'),
|
|
16
15
|
).href;
|
|
@@ -4,7 +4,6 @@ import { isIP } from 'node:net';
|
|
|
4
4
|
const DEFAULT_ARRAY_LENGTH = 2;
|
|
5
5
|
const MAX_GENERATED_COLLECTION_SIZE = 100;
|
|
6
6
|
const MAX_SCHEMA_DEPTH = 32;
|
|
7
|
-
const JSON_SCHEMA_2020_12_URI = 'https://json-schema.org/draft/2020-12/schema';
|
|
8
7
|
const SUPPORTED_STRING_FORMATS = new Set([
|
|
9
8
|
'date',
|
|
10
9
|
'date-time',
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-only OOUI assembly entry.
|
|
3
|
+
*
|
|
4
|
+
* Component libraries provide the vocabulary; soma-core only owns the
|
|
5
|
+
* process-level slot and compiler-facing engine. Hosts that still use OOUI
|
|
6
|
+
* can register their composed pack through this public subpath without
|
|
7
|
+
* reaching into `core/build`.
|
|
8
|
+
*
|
|
9
|
+
* `contractView` is exported here because a Host has to turn the component
|
|
10
|
+
* table it actually registered into `SomaOouiPack.contracts`
|
|
11
|
+
* (`createSomaUiOouiPack({ contracts })` in soma-ui requires exactly that).
|
|
12
|
+
* Without it a third-party Host could only deep-import the composition layer
|
|
13
|
+
* or re-implement the conversion — a second copy that drifts silently.
|
|
14
|
+
*/
|
|
15
|
+
import 'server-only';
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
registerOouiPacks,
|
|
19
|
+
resolveOouiEngine,
|
|
20
|
+
registeredOouiPackNames,
|
|
21
|
+
resetOouiEngineSlot,
|
|
22
|
+
type RegisterOouiPacksOptions,
|
|
23
|
+
} from '../build/ooui/engine-slot';
|
|
24
|
+
|
|
25
|
+
export { contractView } from '../build/ooui';
|
|
26
|
+
|
|
27
|
+
export type {
|
|
28
|
+
SomaComponentContractView,
|
|
29
|
+
SomaEnvironment,
|
|
30
|
+
SomaOouiEngine,
|
|
31
|
+
SomaOouiHatch,
|
|
32
|
+
SomaOouiPack,
|
|
33
|
+
SomaOouiFragment,
|
|
34
|
+
} from '../build/ooui';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-only compilation entry used by preview and smoke-test hosts.
|
|
3
|
+
*
|
|
4
|
+
* 刻意不 `import 'server-only'`:soma-ai 的冒烟探测器在经 jiti 加载的宿主服务里
|
|
5
|
+
* 动态 import 本入口,server-only 在纯 Node 语境下会抛错(理由同 `server/page-declaration.ts`)。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export { compilePageAssets } from '../build/compiler/page-assets';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-only page declaration compiler entry.
|
|
3
|
+
*
|
|
4
|
+
* Hosts and server packages must import this public subpath rather than reach
|
|
5
|
+
* into `core/build`. Keeping it separate from the root barrel prevents the
|
|
6
|
+
* Node-only OOUI compiler dependencies from entering browser bundles.
|
|
7
|
+
*
|
|
8
|
+
* 刻意不 `import 'server-only'`(与 `server/registry/index.ts` 同一理由):宿主的
|
|
9
|
+
* `api/service/*` 由服务加载器经 jiti 在纯 Node 语境加载(`core/server/api/load-host-service.ts`),
|
|
10
|
+
* 而 soma-web 的发布服务、soma-ai 的页面生成服务都从这里 import 编译器——
|
|
11
|
+
* server-only 在那里按 default 条件解析到会抛错的那一份,整个服务类加载失败、端点 404。
|
|
12
|
+
* soma-core 自己的客户端依赖图够不到 core/server,由 verify:client-dep-graph 看守。
|
|
13
|
+
*/
|
|
14
|
+
export {
|
|
15
|
+
compilePageDeclaration,
|
|
16
|
+
type CompiledPageDeclaration,
|
|
17
|
+
type SomaPageDeclarationInput,
|
|
18
|
+
} from '../build/compiler/page-declaration-compiler';
|