soma-core 1.3.2 → 1.3.4
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/README.md +43 -0
- package/app/SomaPageClient.tsx +22 -68
- package/app/[...path]/page.tsx +7 -6
- package/app/api/[...path]/route.ts +3 -3
- package/app/api/soma-registry/[...path]/route.ts +67 -0
- package/app/components/SomaHostPage.tsx +3 -8
- package/app/components/SomaPageClientBoundary.tsx +13 -0
- package/app/layout.tsx +6 -1
- package/app/page.tsx +3 -3
- package/app/soma/manifest/route.ts +1 -0
- package/app/soma/page-object/route.ts +1 -1
- package/bin/soma-lsp.cjs +1 -4
- package/core/build/compiler/full-manifest-builder.ts +19 -23
- package/core/build/compiler/html-include-expander.ts +56 -0
- package/core/build/compiler/page-assets.ts +26 -0
- package/core/build/compiler/page-declaration-compiler.ts +85 -0
- package/core/build/compiler/rollup-plugin-soma.ts +4 -13
- package/core/build/compiler/route-builder.ts +0 -2
- package/core/build/compiler/rspack-plugin-soma.js +1 -10
- package/core/build/compiler/soma-manifest-webpack-plugin.js +54 -9
- package/core/build/compiler/soma-precompile.js +3581 -2387
- package/core/build/compiler/soma-precompile.ts +44 -2
- package/core/build/compiler/soma-rspack-yaml-loader.js +5 -8
- package/core/build/compiler/soma-webpack-loader.js +6 -15
- package/core/build/compiler/vite-plugin-soma.ts +9 -21
- package/core/build/component/pack-from-dir.ts +58 -0
- package/core/build/component/package-loader.ts +281 -0
- package/core/build/eject/apply-eject.ts +133 -0
- package/core/build/eject/plan-eject.ts +133 -0
- package/core/build/lsp/cross-file-diagnostics.cjs +82 -113
- package/core/build/lsp/extra-completion.cjs +14 -8
- package/core/build/lsp/lsp-navigation.cjs +50 -43
- package/core/build/lsp/soma-declaration.cjs +85 -0
- package/core/build/lsp/ui-yaml-completion.cjs +98 -104
- package/core/build/v2/block-compile.ts +200 -0
- package/core/build/v2/block-loader.ts +33 -0
- package/core/build/v2/html-index.ts +120 -0
- package/core/build/v2/migrate-v1.ts +370 -0
- package/core/build/v2/soma-file-loader.ts +216 -0
- package/core/client/adaptive/flush-scheduler.ts +96 -0
- package/core/client/adaptive/hysteresis.ts +56 -0
- package/core/client/adaptive/index.ts +23 -0
- package/core/client/adaptive/observer-pool.ts +90 -0
- package/core/client/base/SomaPageRootBase.ts +50 -0
- package/core/client/compiler/adaptive-compile.ts +136 -0
- package/core/client/compiler/manifest-compiler.ts +155 -27
- package/core/client/component/ai-catalog.ts +277 -0
- package/core/client/component/component-definition.types.ts +65 -0
- package/core/client/component/component-expander.ts +119 -0
- package/core/client/component/component-manager.ts +933 -0
- package/core/client/component/component-pack.ts +445 -0
- package/core/client/component/component-registry.ts +71 -0
- package/core/client/component/contract-compat.ts +132 -0
- package/core/client/component/example-v2.ts +132 -0
- package/core/client/component/pack-styles.ts +94 -0
- package/core/client/component/scoped-adapter.ts +85 -0
- package/core/client/component/verify-pack.ts +247 -0
- package/core/client/container/MiniProgramContainerAdapter.ts +15 -1
- package/core/client/container/ReactNativeContainerAdapter.ts +15 -1
- package/core/client/container/SomaContainerAdapter.ts +186 -180
- package/core/client/data/data-object-resolver.ts +417 -0
- package/core/client/diagnostics/SomaDiagnostics.ts +187 -186
- package/core/client/diagnostics/boot-timings.ts +152 -0
- package/core/client/engine/asset-resolver.ts +12 -2
- package/core/client/engine/dom-renderer.ts +249 -24
- package/core/client/engine/emit-event.ts +21 -0
- package/core/client/engine/event-engine.ts +34 -4
- package/core/client/engine/on-change-engine.ts +1 -1
- package/core/client/engine/property-watcher.ts +1 -1
- package/core/client/engine/reactive-proxy.ts +11 -10
- package/core/client/engine/render-engine.ts +39 -4
- package/core/client/engine/runtime-builder.ts +23 -0
- package/core/client/engine/soma-bootstrap.ts +380 -7
- package/core/client/engine/style-binder.ts +47 -1
- package/core/client/observability/error-reporter.ts +173 -0
- package/core/client/parser/adaptive-parser.ts +264 -0
- package/core/client/parser/data-config-parser.ts +396 -0
- package/core/client/parser/pipeline-parser.ts +15 -3
- package/core/client/parser/style-config-parser.ts +65 -2
- package/core/client/parser/ui-config-parser.ts +52 -3
- package/core/client/parser/v2/namespace.ts +182 -0
- package/core/client/parser/v2/page-parser.ts +359 -0
- package/core/client/parser/v2/use-parser.ts +412 -0
- package/core/client/parser/value-lang.ts +340 -0
- package/core/client/pipes/pipe-registry.ts +249 -0
- package/core/client/quality/SomaQualityRegistry.ts +3 -0
- package/core/client/registry/declaration-renderer.ts +161 -0
- package/core/client/registry/index.ts +28 -0
- package/core/client/registry/page-lifecycle.ts +171 -0
- package/core/client/registry/remote-page.ts +139 -0
- package/core/client/runtime/SomaRuntimeServices.ts +24 -0
- package/core/client/security/attribute-presence.ts +70 -0
- package/core/client/security/html-sanitizer.ts +113 -0
- package/core/client/security/url-guard.ts +0 -0
- package/core/client/theme/harmony.ts +307 -0
- package/core/client/theme/scene-tokens.ts +134 -0
- package/core/client/theme/theme-axes.ts +228 -0
- package/core/client/theme/theme-engine.ts +1196 -0
- package/core/client/theme/tone-solver.ts +118 -0
- package/core/client/typography/typography-base.ts +34 -0
- package/core/client/validation/contract-validator.ts +48 -5
- package/core/index.ts +262 -2
- package/core/server/api/IService.ts +18 -6
- package/core/server/api/load-host-service.ts +3 -3
- package/core/server/host/content-security-policy.ts +190 -0
- package/core/server/host/csp-nonce-metadata.ts +75 -0
- package/core/server/host/resolve-host-request-hook.ts +5 -0
- package/core/server/host/server-page-assets.ts +34 -7
- package/core/server/host/soma-page-compile.ts +33 -0
- package/core/server/index.ts +45 -1
- package/core/server/infra/cache/ServerFileCache.ts +1 -1
- package/core/server/mock/node/cli.mjs +2 -2
- package/core/server/registry/api-registry-store.ts +518 -0
- package/core/server/registry/conditional-object-store.ts +29 -0
- package/core/server/registry/declaration-precompiler.ts +99 -0
- package/core/server/registry/in-memory-conditional-object-store.ts +43 -0
- package/core/server/registry/index.ts +142 -0
- package/core/server/registry/page-registry-repository.ts +373 -0
- package/core/server/registry/page-registry-store.ts +932 -0
- package/core/server/registry/registry-error.ts +17 -0
- package/core/server/registry/registry-file-lock.ts +173 -0
- package/core/server/registry/registry-response.ts +71 -0
- package/core/server/registry/registry-subjects.ts +194 -0
- package/core/server/registry/registry-write-pipeline.ts +240 -0
- package/core/server/registry/request-body-limit.ts +99 -0
- package/core/server/registry/services/apis/Get.ts +25 -0
- package/core/server/registry/services/apis/List.ts +41 -0
- package/core/server/registry/services/apis/Register.ts +39 -0
- package/core/server/registry/services/apis/Unregister.ts +24 -0
- package/core/server/registry/services/index.ts +40 -0
- package/core/server/registry/services/pages/Get.ts +96 -0
- package/core/server/registry/services/pages/List.ts +53 -0
- package/core/server/registry/services/pages/Register.ts +49 -0
- package/core/server/registry/services/pages/Rollback.ts +36 -0
- package/core/server/registry/services/pages/Unregister.ts +23 -0
- package/core/server/registry/services/service-utils.ts +21 -0
- package/core/server/registry/validation/compile-gate.ts +54 -0
- package/core/server/registry/validation/component-existence.ts +55 -0
- package/core/server/registry/validation/credential-ban.ts +86 -0
- package/core/server/registry/validation/cross-check.ts +67 -0
- package/core/server/registry/validation/declaration-safety-scan.ts +102 -0
- package/core/shared/types/adaptive.types.ts +109 -0
- package/core/shared/types/component-contract.types.ts +120 -0
- package/core/shared/types/data-config.types.ts +105 -0
- package/core/shared/types/domain.types.ts +6 -0
- package/core/shared/types/engine.types.ts +41 -35
- package/core/shared/types/manifest.types.ts +55 -32
- package/core/shared/types/scope-manifest.types.ts +96 -0
- package/core/shared/types/style-config.types.ts +9 -0
- package/core/shared/types/ui-config.types.ts +118 -98
- package/dist/cli/soma.js +20 -5
- package/dist/core/index.cjs +7811 -1380
- package/dist/types/build/compiler/full-manifest-builder.d.ts +6 -2
- package/dist/types/build/compiler/html-include-expander.d.ts +19 -0
- package/dist/types/build/compiler/page-assets.d.ts +3 -0
- package/dist/types/build/compiler/page-declaration-compiler.d.ts +33 -0
- package/dist/types/build/compiler/rollup-plugin-soma.d.ts +0 -2
- package/dist/types/build/compiler/route-builder.d.ts +0 -1
- package/dist/types/build/compiler/soma-precompile.d.ts +17 -0
- package/dist/types/build/compiler/vite-plugin-soma.d.ts +2 -7
- package/dist/types/build/component/pack-from-dir.d.ts +17 -0
- package/dist/types/build/component/package-loader.d.ts +40 -0
- package/dist/types/build/eject/apply-eject.d.ts +22 -0
- package/dist/types/build/eject/plan-eject.d.ts +32 -0
- package/dist/types/build/v2/block-compile.d.ts +28 -0
- package/dist/types/build/v2/block-loader.d.ts +9 -0
- package/dist/types/build/v2/html-index.d.ts +37 -0
- package/dist/types/build/v2/migrate-v1.d.ts +32 -0
- package/dist/types/build/v2/soma-file-loader.d.ts +45 -0
- package/dist/types/client/adaptive/flush-scheduler.d.ts +13 -0
- package/dist/types/client/adaptive/hysteresis.d.ts +16 -0
- package/dist/types/client/adaptive/index.d.ts +5 -0
- package/dist/types/client/adaptive/observer-pool.d.ts +15 -0
- package/dist/types/client/base/SomaPageRootBase.d.ts +33 -0
- package/dist/types/client/compiler/adaptive-compile.d.ts +26 -0
- package/dist/types/client/compiler/manifest-compiler.d.ts +13 -2
- package/dist/types/client/component/ai-catalog.d.ts +73 -0
- package/dist/types/client/component/component-definition.types.d.ts +54 -0
- package/dist/types/client/component/component-expander.d.ts +25 -0
- package/dist/types/client/component/component-manager.d.ts +160 -0
- package/dist/types/client/component/component-pack.d.ts +110 -0
- package/dist/types/client/component/component-registry.d.ts +12 -0
- package/dist/types/client/component/contract-compat.d.ts +16 -0
- package/dist/types/client/component/example-v2.d.ts +9 -0
- package/dist/types/client/component/pack-styles.d.ts +22 -0
- package/dist/types/client/component/scoped-adapter.d.ts +18 -0
- package/dist/types/client/component/verify-pack.d.ts +14 -0
- package/dist/types/client/data/data-object-resolver.d.ts +71 -0
- package/dist/types/client/diagnostics/SomaDiagnostics.d.ts +2 -1
- package/dist/types/client/diagnostics/boot-timings.d.ts +30 -0
- package/dist/types/client/engine/asset-resolver.d.ts +7 -1
- package/dist/types/client/engine/dom-renderer.d.ts +51 -1
- package/dist/types/client/engine/emit-event.d.ts +6 -0
- package/dist/types/client/engine/event-engine.d.ts +6 -0
- package/dist/types/client/engine/render-engine.d.ts +25 -1
- package/dist/types/client/engine/runtime-builder.d.ts +7 -0
- package/dist/types/client/engine/soma-bootstrap.d.ts +118 -0
- package/dist/types/client/observability/error-reporter.d.ts +51 -0
- package/dist/types/client/parser/adaptive-parser.d.ts +28 -0
- package/dist/types/client/parser/data-config-parser.d.ts +34 -0
- package/dist/types/client/parser/pipeline-parser.d.ts +2 -0
- package/dist/types/client/parser/style-config-parser.d.ts +5 -3
- package/dist/types/client/parser/ui-config-parser.d.ts +22 -1
- package/dist/types/client/parser/v2/namespace.d.ts +52 -0
- package/dist/types/client/parser/v2/page-parser.d.ts +21 -0
- package/dist/types/client/parser/v2/use-parser.d.ts +72 -0
- package/dist/types/client/parser/value-lang.d.ts +63 -0
- package/dist/types/client/pipes/pipe-registry.d.ts +38 -0
- package/dist/types/client/registry/declaration-renderer.d.ts +50 -0
- package/dist/types/client/registry/index.d.ts +10 -0
- package/dist/types/client/registry/page-lifecycle.d.ts +61 -0
- package/dist/types/client/registry/remote-page.d.ts +52 -0
- package/dist/types/client/runtime/SomaRuntimeServices.d.ts +16 -0
- package/dist/types/client/security/attribute-presence.d.ts +7 -0
- package/dist/types/client/security/html-sanitizer.d.ts +37 -0
- package/dist/types/client/security/url-guard.d.ts +11 -0
- package/dist/types/client/theme/harmony.d.ts +77 -0
- package/dist/types/client/theme/scene-tokens.d.ts +25 -0
- package/dist/types/client/theme/theme-axes.d.ts +81 -0
- package/dist/types/client/theme/theme-engine.d.ts +77 -0
- package/dist/types/client/theme/tone-solver.d.ts +47 -0
- package/dist/types/client/typography/typography-base.d.ts +15 -0
- package/dist/types/client/validation/contract-validator.d.ts +2 -0
- package/dist/types/index.d.ts +47 -2
- package/dist/types/server/api/IService.d.ts +18 -6
- package/dist/types/server/host/content-security-policy.d.ts +53 -0
- package/dist/types/server/host/csp-nonce-metadata.d.ts +32 -0
- package/dist/types/server/host/resolve-host-request-hook.d.ts +5 -0
- package/dist/types/server/host/server-page-assets.d.ts +2 -0
- package/dist/types/server/host/soma-page-compile.d.ts +7 -0
- package/dist/types/server/index.d.ts +6 -1
- package/dist/types/server/registry/api-registry-store.d.ts +141 -0
- package/dist/types/server/registry/conditional-object-store.d.ts +27 -0
- package/dist/types/server/registry/declaration-precompiler.d.ts +30 -0
- package/dist/types/server/registry/in-memory-conditional-object-store.d.ts +8 -0
- package/dist/types/server/registry/index.d.ts +29 -0
- package/dist/types/server/registry/page-registry-repository.d.ts +58 -0
- package/dist/types/server/registry/page-registry-store.d.ts +259 -0
- package/dist/types/server/registry/registry-error.d.ts +12 -0
- package/dist/types/server/registry/registry-file-lock.d.ts +20 -0
- package/dist/types/server/registry/registry-response.d.ts +18 -0
- package/dist/types/server/registry/registry-subjects.d.ts +59 -0
- package/dist/types/server/registry/registry-write-pipeline.d.ts +48 -0
- package/dist/types/server/registry/request-body-limit.d.ts +31 -0
- package/dist/types/server/registry/services/apis/Get.d.ts +10 -0
- package/dist/types/server/registry/services/apis/List.d.ts +10 -0
- package/dist/types/server/registry/services/apis/Register.d.ts +13 -0
- package/dist/types/server/registry/services/apis/Unregister.d.ts +12 -0
- package/dist/types/server/registry/services/index.d.ts +3 -0
- package/dist/types/server/registry/services/pages/Get.d.ts +10 -0
- package/dist/types/server/registry/services/pages/List.d.ts +13 -0
- package/dist/types/server/registry/services/pages/Register.d.ts +11 -0
- package/dist/types/server/registry/services/pages/Rollback.d.ts +9 -0
- package/dist/types/server/registry/services/pages/Unregister.d.ts +9 -0
- package/dist/types/server/registry/services/service-utils.d.ts +10 -0
- package/dist/types/server/registry/validation/compile-gate.d.ts +12 -0
- package/dist/types/server/registry/validation/component-existence.d.ts +14 -0
- package/dist/types/server/registry/validation/credential-ban.d.ts +15 -0
- package/dist/types/server/registry/validation/cross-check.d.ts +16 -0
- package/dist/types/server/registry/validation/declaration-safety-scan.d.ts +15 -0
- package/dist/types/shared/types/adaptive.types.d.ts +88 -0
- package/dist/types/shared/types/component-contract.types.d.ts +78 -0
- package/dist/types/shared/types/data-config.types.d.ts +81 -0
- package/dist/types/shared/types/domain.types.d.ts +6 -0
- package/dist/types/shared/types/engine.types.d.ts +6 -0
- package/dist/types/shared/types/manifest.types.d.ts +23 -0
- package/dist/types/shared/types/scope-manifest.types.d.ts +82 -0
- package/dist/types/shared/types/style-config.types.d.ts +8 -0
- package/dist/types/shared/types/ui-config.types.d.ts +20 -0
- package/editor/vscode/package.json +1 -24
- package/global.d.ts +5 -11
- package/next.config.js +85 -28
- package/package.json +33 -11
- package/proxy.ts +62 -0
- package/tailwind.config.ts +0 -1
- package/core/build/lsp/event-yaml-completion.cjs +0 -106
- package/core/client/engine/theme-variables.ts +0 -37
- package/dist/tsconfig.types.tsbuildinfo +0 -1
- package/dist/types/client/engine/theme-variables.d.ts +0 -3
- package/editor/vscode/syntaxes/soma-event-yaml.tmLanguage.json +0 -30
- package/middleware.ts +0 -33
|
@@ -1,186 +1,187 @@
|
|
|
1
|
-
// ─── 环形缓冲区:O(1) 写入,替代 push + shift 的 O(n) ─────
|
|
2
|
-
|
|
3
|
-
class RingBuffer<T> {
|
|
4
|
-
private buffer: (T | undefined)[];
|
|
5
|
-
private head = 0;
|
|
6
|
-
private count = 0;
|
|
7
|
-
|
|
8
|
-
constructor(private readonly capacity: number) {
|
|
9
|
-
this.buffer = new Array(capacity);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
push(item: T): void {
|
|
13
|
-
const index = (this.head + this.count) % this.capacity;
|
|
14
|
-
if (this.count < this.capacity) {
|
|
15
|
-
this.count++;
|
|
16
|
-
} else {
|
|
17
|
-
// 满了,覆盖最旧的条目,head 前移
|
|
18
|
-
this.head = (this.head + 1) % this.capacity;
|
|
19
|
-
}
|
|
20
|
-
this.buffer[index] = item;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
toArray(): T[] {
|
|
24
|
-
const result: T[] = [];
|
|
25
|
-
for (let i = 0; i < this.count; i++) {
|
|
26
|
-
result.push(this.buffer[(this.head + i) % this.capacity] as T);
|
|
27
|
-
}
|
|
28
|
-
return result;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
get length(): number {
|
|
32
|
-
return this.count;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// ─── 高精度时间戳工具 ─────────────────────────────────
|
|
37
|
-
|
|
38
|
-
function highResTimestamp(): number {
|
|
39
|
-
return globalThis.performance?.now?.() ?? Date.now();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// ─── 类型定义 ─────────────────────────────────────────
|
|
43
|
-
|
|
44
|
-
export interface SomaMutationRecord {
|
|
45
|
-
path: string;
|
|
46
|
-
valuePreview: string;
|
|
47
|
-
timestamp: number;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export interface SomaRenderRecord {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
private
|
|
104
|
-
private
|
|
105
|
-
private
|
|
106
|
-
private
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
this.
|
|
111
|
-
this.
|
|
112
|
-
this.
|
|
113
|
-
this.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
if (value ===
|
|
173
|
-
if (
|
|
174
|
-
if (typeof value === '
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
1
|
+
// ─── 环形缓冲区:O(1) 写入,替代 push + shift 的 O(n) ─────
|
|
2
|
+
|
|
3
|
+
class RingBuffer<T> {
|
|
4
|
+
private buffer: (T | undefined)[];
|
|
5
|
+
private head = 0;
|
|
6
|
+
private count = 0;
|
|
7
|
+
|
|
8
|
+
constructor(private readonly capacity: number) {
|
|
9
|
+
this.buffer = new Array(capacity);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
push(item: T): void {
|
|
13
|
+
const index = (this.head + this.count) % this.capacity;
|
|
14
|
+
if (this.count < this.capacity) {
|
|
15
|
+
this.count++;
|
|
16
|
+
} else {
|
|
17
|
+
// 满了,覆盖最旧的条目,head 前移
|
|
18
|
+
this.head = (this.head + 1) % this.capacity;
|
|
19
|
+
}
|
|
20
|
+
this.buffer[index] = item;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
toArray(): T[] {
|
|
24
|
+
const result: T[] = [];
|
|
25
|
+
for (let i = 0; i < this.count; i++) {
|
|
26
|
+
result.push(this.buffer[(this.head + i) % this.capacity] as T);
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get length(): number {
|
|
32
|
+
return this.count;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// ─── 高精度时间戳工具 ─────────────────────────────────
|
|
37
|
+
|
|
38
|
+
function highResTimestamp(): number {
|
|
39
|
+
return globalThis.performance?.now?.() ?? Date.now();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// ─── 类型定义 ─────────────────────────────────────────
|
|
43
|
+
|
|
44
|
+
export interface SomaMutationRecord {
|
|
45
|
+
path: string;
|
|
46
|
+
valuePreview: string;
|
|
47
|
+
timestamp: number;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface SomaRenderRecord {
|
|
51
|
+
/** publish = 事务中途的自愿提交(长任务播进展) */
|
|
52
|
+
phase: 'full-render' | 'patch' | 'commit' | 'publish';
|
|
53
|
+
path?: string;
|
|
54
|
+
bindingCount: number;
|
|
55
|
+
affectedCount: number;
|
|
56
|
+
durationMs: number;
|
|
57
|
+
timestamp: number;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface SomaEventRecord {
|
|
61
|
+
somaId: string;
|
|
62
|
+
domEvent: string;
|
|
63
|
+
eventType: string;
|
|
64
|
+
funcPath?: string | null;
|
|
65
|
+
status: 'success' | 'blocked' | 'error';
|
|
66
|
+
durationMs: number;
|
|
67
|
+
message?: string;
|
|
68
|
+
timestamp: number;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface SomaValidationRecord {
|
|
72
|
+
level: 'warning' | 'error';
|
|
73
|
+
message: string;
|
|
74
|
+
timestamp: number;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface SomaSchedulerRecord {
|
|
78
|
+
priority: 'immediate' | 'visible' | 'background';
|
|
79
|
+
label?: string;
|
|
80
|
+
durationMs: number;
|
|
81
|
+
status?: 'success' | 'error';
|
|
82
|
+
timestamp: number;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface SomaDiagnosticsSnapshot {
|
|
86
|
+
mutations: SomaMutationRecord[];
|
|
87
|
+
renders: SomaRenderRecord[];
|
|
88
|
+
events: SomaEventRecord[];
|
|
89
|
+
validations: SomaValidationRecord[];
|
|
90
|
+
scheduler: SomaSchedulerRecord[];
|
|
91
|
+
counters: {
|
|
92
|
+
mutations: number;
|
|
93
|
+
renders: number;
|
|
94
|
+
events: number;
|
|
95
|
+
validations: number;
|
|
96
|
+
scheduler: number;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// ─── 诊断系统 ─────────────────────────────────────────
|
|
101
|
+
|
|
102
|
+
export class SomaDiagnostics {
|
|
103
|
+
private mutations: RingBuffer<SomaMutationRecord>;
|
|
104
|
+
private renders: RingBuffer<SomaRenderRecord>;
|
|
105
|
+
private events: RingBuffer<SomaEventRecord>;
|
|
106
|
+
private validations: RingBuffer<SomaValidationRecord>;
|
|
107
|
+
private scheduler: RingBuffer<SomaSchedulerRecord>;
|
|
108
|
+
|
|
109
|
+
constructor(maxEntries: number = 200) {
|
|
110
|
+
this.mutations = new RingBuffer(maxEntries);
|
|
111
|
+
this.renders = new RingBuffer(maxEntries);
|
|
112
|
+
this.events = new RingBuffer(maxEntries);
|
|
113
|
+
this.validations = new RingBuffer(maxEntries);
|
|
114
|
+
this.scheduler = new RingBuffer(maxEntries);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
recordMutation(path: string, value: any): void {
|
|
118
|
+
this.mutations.push({
|
|
119
|
+
path,
|
|
120
|
+
valuePreview: this.preview(value),
|
|
121
|
+
timestamp: highResTimestamp(),
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
recordRender(record: Omit<SomaRenderRecord, 'timestamp'>): void {
|
|
126
|
+
this.renders.push({
|
|
127
|
+
...record,
|
|
128
|
+
timestamp: highResTimestamp(),
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
recordEvent(record: Omit<SomaEventRecord, 'timestamp'>): void {
|
|
133
|
+
this.events.push({
|
|
134
|
+
...record,
|
|
135
|
+
timestamp: highResTimestamp(),
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
recordValidation(level: SomaValidationRecord['level'], message: string): void {
|
|
140
|
+
this.validations.push({
|
|
141
|
+
level,
|
|
142
|
+
message,
|
|
143
|
+
timestamp: highResTimestamp(),
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
recordScheduler(record: Omit<SomaSchedulerRecord, 'timestamp'>): void {
|
|
148
|
+
this.scheduler.push({
|
|
149
|
+
...record,
|
|
150
|
+
timestamp: highResTimestamp(),
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
snapshot(): SomaDiagnosticsSnapshot {
|
|
155
|
+
return {
|
|
156
|
+
mutations: this.mutations.toArray(),
|
|
157
|
+
renders: this.renders.toArray(),
|
|
158
|
+
events: this.events.toArray(),
|
|
159
|
+
validations: this.validations.toArray(),
|
|
160
|
+
scheduler: this.scheduler.toArray(),
|
|
161
|
+
counters: {
|
|
162
|
+
mutations: this.mutations.length,
|
|
163
|
+
renders: this.renders.length,
|
|
164
|
+
events: this.events.length,
|
|
165
|
+
validations: this.validations.length,
|
|
166
|
+
scheduler: this.scheduler.length,
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private preview(value: any): string {
|
|
172
|
+
if (value === null) return 'null';
|
|
173
|
+
if (value === undefined) return 'undefined';
|
|
174
|
+
if (typeof value === 'string') return value;
|
|
175
|
+
if (typeof value === 'number' || typeof value === 'boolean') {
|
|
176
|
+
return String(value);
|
|
177
|
+
}
|
|
178
|
+
if (Array.isArray(value)) {
|
|
179
|
+
return `[Array(${value.length})]`;
|
|
180
|
+
}
|
|
181
|
+
try {
|
|
182
|
+
return JSON.stringify(value);
|
|
183
|
+
} catch {
|
|
184
|
+
return Object.prototype.toString.call(value);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// core/client/diagnostics/boot-timings.ts
|
|
2
|
+
// 首屏三段打点(生产化强化文档 §6,作业单 P-1)。
|
|
3
|
+
//
|
|
4
|
+
// 为什么切成三段而不是记一个总耗时:SOMA 页面的首屏成本只可能沉在三处——
|
|
5
|
+
// ① 资产就绪:把页面四件套(或预编译产物)拿到手,成本在网络与模块加载;
|
|
6
|
+
// ② 编译完成:把资产解析成运行时清单(YAML 解析 + 作用域解析 + manifest 编译),成本在 CPU;
|
|
7
|
+
// ③ 首次渲染完成:清单驱动写出首帧 DOM,成本在 CPU 与布局。
|
|
8
|
+
// 三段的优化手段互不相通(缓存/发布时预编译落库/窗口化渲染),
|
|
9
|
+
// 只有一个总数时无法判断该动哪一处,所以打点粒度必须是三段。
|
|
10
|
+
//
|
|
11
|
+
// 为什么默认关闭:打点要分配状态对象、要往 performance 缓冲区塞条目,
|
|
12
|
+
// 而生产页面绝大多数时候并不需要这些数字。未开启时下面每个入口都只做
|
|
13
|
+
// 一次布尔判断即返回——不分配对象、不调用 performance.mark,真正零开销。
|
|
14
|
+
// 开启方式二选一:
|
|
15
|
+
// · 引导前置 `globalThis.__SOMA_BOOT_TIMINGS__ = true`(宿主/E2E 探针用);
|
|
16
|
+
// · 直接调用 `startBootTimings()`(单测与手工排查用)。
|
|
17
|
+
|
|
18
|
+
import { recordMetric } from './telemetry-context';
|
|
19
|
+
|
|
20
|
+
/** 三段的终点标记;起点由 startBootTimings 打下 */
|
|
21
|
+
export type SomaBootPhase = 'assetsReady' | 'compiled' | 'rendered';
|
|
22
|
+
|
|
23
|
+
export interface SomaBootTimings {
|
|
24
|
+
/** 段一 资产就绪:引导开始 → 页面资产到手(ms);未走到该段为 null */
|
|
25
|
+
assetsMs: number | null;
|
|
26
|
+
/** 段二 编译完成:资产到手 → 运行时清单编译完毕(ms);未走到该段为 null */
|
|
27
|
+
compileMs: number | null;
|
|
28
|
+
/** 段三 首次渲染完成:清单编译完毕 → 首帧 DOM 写完(ms);未走到该段为 null */
|
|
29
|
+
renderMs: number | null;
|
|
30
|
+
/** 引导开始 → 首次渲染完成的总耗时(ms);未走完为 null */
|
|
31
|
+
totalMs: number | null;
|
|
32
|
+
/** 三段是否都已走完(未走完的数字不可用于 p95 统计) */
|
|
33
|
+
complete: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** performance 时间线上的标记名:统一 `soma:boot:` 前缀,便于在 DevTools 里按前缀筛选 */
|
|
37
|
+
const MARK_NAMES: Record<'start' | SomaBootPhase, string> = {
|
|
38
|
+
start: 'soma:boot:start',
|
|
39
|
+
assetsReady: 'soma:boot:assets-ready',
|
|
40
|
+
compiled: 'soma:boot:compiled',
|
|
41
|
+
rendered: 'soma:boot:rendered',
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** 每段 measure 的名字与它的起点标记(段与段首尾相接,构成一条无缝时间线) */
|
|
45
|
+
const MEASURE_SPECS: Record<SomaBootPhase, { name: string; from: string; metric: string }> = {
|
|
46
|
+
assetsReady: { name: 'soma:boot:assets', from: MARK_NAMES.start, metric: 'boot.assets' },
|
|
47
|
+
compiled: { name: 'soma:boot:compile', from: MARK_NAMES.assetsReady, metric: 'boot.compile' },
|
|
48
|
+
rendered: { name: 'soma:boot:render', from: MARK_NAMES.compiled, metric: 'boot.render' },
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
interface BootState {
|
|
52
|
+
start: number;
|
|
53
|
+
assetsReady: number | null;
|
|
54
|
+
compiled: number | null;
|
|
55
|
+
rendered: number | null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// 未开启时恒为 null——这既是「关」的开关,也是零分配的保证
|
|
59
|
+
let state: BootState | null = null;
|
|
60
|
+
|
|
61
|
+
function now(): number {
|
|
62
|
+
return globalThis.performance?.now?.() ?? Date.now();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// User Timing 在小程序/RN 等容器里可能缺席,打点降级为纯数字,不能因此让引导炸掉
|
|
66
|
+
function safeMark(name: string): void {
|
|
67
|
+
try {
|
|
68
|
+
globalThis.performance?.mark?.(name);
|
|
69
|
+
} catch {
|
|
70
|
+
/* 容器不支持 User Timing:只保留内部数字 */
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function safeMeasure(name: string, from: string, to: string): void {
|
|
75
|
+
try {
|
|
76
|
+
globalThis.performance?.measure?.(name, from, to);
|
|
77
|
+
} catch {
|
|
78
|
+
/* 起点标记缺失或容器不支持:measure 是给 DevTools 看的附赠品,缺了不影响读数 */
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** 开启打点并落下起点标记(重复调用即重新计时;供单测与手工排查直接使用) */
|
|
83
|
+
export function startBootTimings(): void {
|
|
84
|
+
state = { start: now(), assetsReady: null, compiled: null, rendered: null };
|
|
85
|
+
safeMark(MARK_NAMES.start);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 按需开启:仅当宿主显式置了 `globalThis.__SOMA_BOOT_TIMINGS__ = true` 才计时。
|
|
90
|
+
* 已在计时(含首屏已计完)时不重置——首屏只有一次,SPA 后续换页不应覆盖首屏数字;
|
|
91
|
+
* 要量后续页面请显式 resetBootTimings() + startBootTimings()。
|
|
92
|
+
*/
|
|
93
|
+
export function maybeStartBootTimings(): void {
|
|
94
|
+
if (state) return;
|
|
95
|
+
if ((globalThis as { __SOMA_BOOT_TIMINGS__?: boolean }).__SOMA_BOOT_TIMINGS__ !== true) return;
|
|
96
|
+
startBootTimings();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** 落下一段的终点。未开启、首屏已计完、同段重复打点,三种情况都直接返回 */
|
|
100
|
+
export function markBootPhase(phase: SomaBootPhase): void {
|
|
101
|
+
const s = state;
|
|
102
|
+
if (!s) return;
|
|
103
|
+
// 首屏已经走完:后续 hotSwap / 换页复用同一条挂载路径,不能污染首屏读数
|
|
104
|
+
if (s.rendered !== null) return;
|
|
105
|
+
if (s[phase] !== null) return;
|
|
106
|
+
|
|
107
|
+
s[phase] = now();
|
|
108
|
+
safeMark(MARK_NAMES[phase]);
|
|
109
|
+
|
|
110
|
+
const spec = MEASURE_SPECS[phase];
|
|
111
|
+
safeMeasure(spec.name, spec.from, MARK_NAMES[phase]);
|
|
112
|
+
|
|
113
|
+
const elapsed = segmentMs(s, phase);
|
|
114
|
+
if (elapsed !== null) {
|
|
115
|
+
recordMetric(spec.metric, elapsed);
|
|
116
|
+
}
|
|
117
|
+
if (phase === 'rendered') {
|
|
118
|
+
safeMeasure('soma:boot:total', MARK_NAMES.start, MARK_NAMES.rendered);
|
|
119
|
+
recordMetric('boot.total', s.rendered! - s.start);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** 读取三段耗时;从未开启过打点时返回 null(调用方据此区分「没量」和「量出来是 0」) */
|
|
124
|
+
export function readBootTimings(): SomaBootTimings | null {
|
|
125
|
+
const s = state;
|
|
126
|
+
if (!s) return null;
|
|
127
|
+
return {
|
|
128
|
+
assetsMs: segmentMs(s, 'assetsReady'),
|
|
129
|
+
compileMs: segmentMs(s, 'compiled'),
|
|
130
|
+
renderMs: segmentMs(s, 'rendered'),
|
|
131
|
+
totalMs: s.rendered !== null ? s.rendered - s.start : null,
|
|
132
|
+
complete: s.assetsReady !== null && s.compiled !== null && s.rendered !== null,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** 关闭打点并清空状态,回到零开销状态(单测隔离、以及要重新量一次时使用) */
|
|
137
|
+
export function resetBootTimings(): void {
|
|
138
|
+
state = null;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** 当前是否在计时(宿主可据此决定要不要上报) */
|
|
142
|
+
export function isBootTimingsEnabled(): boolean {
|
|
143
|
+
return state !== null;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** 段耗时 = 本段终点 - 上一段终点;上一段缺席(乱序打点)时该段不可计算 */
|
|
147
|
+
function segmentMs(s: BootState, phase: SomaBootPhase): number | null {
|
|
148
|
+
const end = s[phase];
|
|
149
|
+
if (end === null) return null;
|
|
150
|
+
const begin = phase === 'assetsReady' ? s.start : phase === 'compiled' ? s.assetsReady : s.compiled;
|
|
151
|
+
return begin === null ? null : end - begin;
|
|
152
|
+
}
|
|
@@ -9,6 +9,7 @@ import { splitEventConfigRaw } from '../parser/trigger-parser';
|
|
|
9
9
|
import { parseStyleConfig } from '../parser/style-config-parser';
|
|
10
10
|
import { parseUiConfig } from '../parser/ui-config-parser';
|
|
11
11
|
import type { PropertyTrigger } from '../../shared/types/trigger.types';
|
|
12
|
+
import type { SomaAdaptiveVocabulary } from '../../shared/types/adaptive.types';
|
|
12
13
|
import { extractConfigFromDomainClass } from '../parser/annotation-extractor';
|
|
13
14
|
import { hasPageMetadata } from '../base/decorators/Page';
|
|
14
15
|
import type { SomaPageAssets, ParsedRuntimeAssets } from './soma-bootstrap';
|
|
@@ -20,11 +21,18 @@ import type { SomaPageAssets, ParsedRuntimeAssets } from './soma-bootstrap';
|
|
|
20
21
|
* - 预编译模式:assets 中已有 uiConfig/eventConfig,直接使用,零开销
|
|
21
22
|
* - 字符串模式:assets 中是 yaml 字符串,运行时解析,带 LRU 缓存
|
|
22
23
|
*/
|
|
24
|
+
export interface SomaAssetResolverOptions {
|
|
25
|
+
/** 阶梯词汇表(F-09):随 bootstrap 注入,用于 `_ui.yaml` 的 adaptive 校验 */
|
|
26
|
+
adaptiveVocabulary?: SomaAdaptiveVocabulary;
|
|
27
|
+
}
|
|
28
|
+
|
|
23
29
|
export class SomaAssetResolver {
|
|
24
30
|
private cache: ICache<ParsedRuntimeAssets>;
|
|
31
|
+
private readonly adaptiveVocabulary?: SomaAdaptiveVocabulary;
|
|
25
32
|
|
|
26
|
-
constructor(cache?: ICache<ParsedRuntimeAssets
|
|
33
|
+
constructor(cache?: ICache<ParsedRuntimeAssets>, options?: SomaAssetResolverOptions) {
|
|
27
34
|
this.cache = cache ?? new MemoryCache({ maxSize: 50 });
|
|
35
|
+
this.adaptiveVocabulary = options?.adaptiveVocabulary;
|
|
28
36
|
}
|
|
29
37
|
|
|
30
38
|
resolve(assets: SomaPageAssets): ParsedRuntimeAssets {
|
|
@@ -70,7 +78,9 @@ export class SomaAssetResolver {
|
|
|
70
78
|
const { eventsRaw, triggers, timers } = splitEventConfigRaw(eventRaw);
|
|
71
79
|
|
|
72
80
|
const result: ParsedRuntimeAssets = {
|
|
73
|
-
uiConfig: parseUiConfig(yaml.load(uiYaml)
|
|
81
|
+
uiConfig: parseUiConfig(yaml.load(uiYaml), {
|
|
82
|
+
adaptiveVocabulary: this.adaptiveVocabulary,
|
|
83
|
+
}),
|
|
74
84
|
eventConfig: parseEventConfig(eventsRaw as any),
|
|
75
85
|
triggers,
|
|
76
86
|
timers,
|