soma-core 1.0.1 → 1.0.2
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/app/SomaPageClient.tsx +336 -0
- package/app/api/[...path]/route.ts +9 -85
- package/app/api/page/route.ts +18 -16
- package/app/api/soma-manifest/route.ts +39 -0
- package/app/components/SomaHydrationShell.tsx +23 -0
- package/app/layout.tsx +2 -2
- package/app/loading.tsx +5 -0
- package/app/page.tsx +19 -128
- package/bin/soma-lsp.cjs +195 -0
- package/bin/soma-sync.cjs +3 -0
- package/bin/soma.cjs +14 -2
- package/core/api/IService.ts +6 -10
- package/core/api/load-host-service.ts +72 -0
- package/core/api/service-path.ts +39 -0
- package/core/base/SomaEntity.ts +3 -10
- package/core/base/SomaLocaleOnlyPageRoot.ts +3 -4
- package/core/base/SomaPageRootBase.ts +20 -3
- package/core/base/decorators/Event.ts +23 -0
- package/core/base/decorators/Locale.ts +35 -0
- package/core/base/decorators/Page.ts +16 -0
- package/core/base/decorators/Show.ts +20 -0
- package/core/base/decorators/ShowList.ts +34 -0
- package/core/base/decorators/index.ts +5 -0
- package/core/base/index.ts +2 -0
- package/core/base/runAsync.ts +32 -0
- package/core/compiler/full-manifest-builder.ts +33 -7
- package/core/compiler/host-config-sync.cjs +38 -0
- package/core/compiler/manifest-compiler.ts +3 -2
- package/core/compiler/page-base-resolver.ts +23 -0
- package/core/compiler/precompiled-manifest-loader.ts +34 -0
- package/core/compiler/rollup-plugin-soma.ts +45 -0
- package/core/compiler/rspack-plugin-soma.js +33 -0
- package/core/compiler/soma-manifest-webpack-plugin.js +72 -0
- package/core/compiler/soma-precompile.js +3513 -0
- package/core/compiler/soma-precompile.ts +52 -6
- package/core/compiler/soma-rspack-yaml-loader.js +22 -0
- package/core/compiler/soma-webpack-loader.js +7 -1
- package/core/compiler/vite-plugin-soma.ts +11 -1
- package/core/container/IContainerAdapter.ts +36 -0
- package/core/container/MiniProgramContainerAdapter.ts +190 -0
- package/core/container/ReactNativeContainerAdapter.ts +189 -0
- package/core/container/SomaContainerAdapter.ts +17 -6
- package/core/diagnostics/SomaDiagnostics.ts +1 -1
- package/core/diagnostics/SomaTelemetry.ts +100 -0
- package/core/diagnostics/telemetry-context.ts +15 -0
- package/core/engine/asset-resolver.ts +39 -4
- package/core/engine/dom-renderer.ts +9 -11
- package/core/engine/event-engine.ts +110 -41
- package/core/engine/on-change-engine.ts +71 -0
- package/core/engine/property-watcher.ts +117 -0
- package/core/engine/reactive-proxy.ts +11 -5
- package/core/engine/render-engine.ts +97 -11
- package/core/engine/runtime-builder.ts +88 -11
- package/core/engine/scope-resolver.ts +65 -9
- package/core/engine/soma-bootstrap.ts +448 -244
- package/core/engine/style-binder.ts +423 -0
- package/core/engine/theme-variables.ts +37 -0
- package/core/engine/timer-engine.ts +92 -0
- package/core/engine/trigger-engine.ts +55 -0
- package/core/host/resolve-host-bootstrap.ts +28 -0
- package/core/host/soma-bootstrap-host.stub.ts +4 -0
- package/core/index.ts +33 -2
- package/core/infra/auth/TokenAuthService.ts +17 -3
- package/core/infra/http/IHttpClient.ts +11 -1
- package/core/infra/http/SomaHttpService.ts +89 -31
- package/core/infra/i18n/DefaultI18n.ts +6 -18
- package/core/infra/i18n/II18n.ts +2 -3
- package/core/infra/notify/DomNotifyService.ts +98 -0
- package/core/infra/notify/INotifyTheme.ts +22 -0
- package/core/infra/realtime/IRealtimeService.ts +23 -0
- package/core/infra/realtime/IRealtimeTransport.ts +9 -0
- package/core/infra/realtime/SomaRealtimeService.ts +95 -0
- package/core/infra/realtime/SseRealtimeTransport.ts +36 -0
- package/core/infra/realtime/WebSocketRealtimeTransport.ts +102 -0
- package/core/infra/router/router-path.ts +28 -0
- package/core/infra/storage/SessionStorageService.ts +59 -0
- package/core/lsp/cross-file-diagnostics.cjs +160 -0
- package/core/lsp/event-yaml-completion.cjs +106 -0
- package/core/lsp/extra-completion.cjs +64 -0
- package/core/lsp/lsp-navigation.cjs +191 -0
- package/core/lsp/ui-yaml-completion.cjs +170 -0
- package/core/manifest/manifest-contract.ts +12 -0
- package/core/middleware/createPermissionMiddleware.ts +37 -0
- package/core/parser/annotation-extractor.ts +113 -0
- package/core/parser/pipeline-parser.ts +344 -276
- package/core/parser/style-config-parser.ts +340 -0
- package/core/parser/timer-parser.ts +70 -0
- package/core/parser/trigger-parser.ts +90 -0
- package/core/parser/ui-config-parser.ts +73 -1
- package/core/quality/SomaQualityRegistry.ts +68 -0
- package/core/runtime/SomaRuntimeServices.ts +100 -0
- package/core/runtime/SomaSnapshotStore.ts +5 -3
- package/core/types/domain.types.ts +5 -2
- package/core/types/event.types.ts +82 -57
- package/core/types/manifest.types.ts +2 -0
- package/core/types/style-config.types.ts +76 -0
- package/core/types/timer.types.ts +23 -0
- package/core/types/trigger.types.ts +14 -0
- package/core/types/ui-config.types.ts +9 -0
- package/core/types/watcher.types.ts +29 -0
- package/dist/cli/soma.js +23 -23
- package/dist/core/index.cjs +8968 -0
- package/dist/diagnostics/telemetry.cjs +105 -0
- package/dist/preview-export.cjs +3401 -0
- package/dist/tsconfig.types.tsbuildinfo +1 -0
- package/dist/types/api/IService.d.ts +28 -0
- package/dist/types/api/load-host-service.d.ts +5 -0
- package/dist/types/api/service-path.d.ts +13 -0
- package/dist/types/base/SomaApi.d.ts +5 -0
- package/dist/types/base/SomaDict.d.ts +89 -0
- package/dist/types/base/SomaEntity.d.ts +15 -0
- package/dist/types/base/SomaHttpClient.d.ts +66 -0
- package/dist/types/base/SomaLocaleOnlyPageRoot.d.ts +3 -0
- package/dist/types/base/SomaPageRootBase.d.ts +49 -0
- package/dist/types/base/SomaValidator.d.ts +55 -0
- package/dist/types/base/decorators/Event.d.ts +10 -0
- package/dist/types/base/decorators/Locale.d.ts +9 -0
- package/dist/types/base/decorators/Page.d.ts +4 -0
- package/dist/types/base/decorators/Show.d.ts +7 -0
- package/dist/types/base/decorators/ShowList.d.ts +12 -0
- package/dist/types/base/decorators/index.d.ts +5 -0
- package/dist/types/base/index.d.ts +9 -0
- package/dist/types/base/runAsync.d.ts +12 -0
- package/dist/types/compiler/full-manifest-builder.d.ts +35 -0
- package/dist/types/compiler/manifest-compiler.d.ts +29 -0
- package/dist/types/compiler/page-base-resolver.d.ts +6 -0
- package/dist/types/compiler/precompiled-manifest-loader.d.ts +5 -0
- package/dist/types/compiler/rollup-plugin-soma.d.ts +14 -0
- package/dist/types/compiler/route-builder.d.ts +12 -0
- package/dist/types/compiler/soma-precompile.d.ts +40 -0
- package/dist/types/compiler/vite-plugin-soma.d.ts +34 -0
- package/dist/types/container/IContainerAdapter.d.ts +30 -0
- package/dist/types/container/MiniProgramContainerAdapter.d.ts +52 -0
- package/dist/types/container/ReactNativeContainerAdapter.d.ts +47 -0
- package/dist/types/container/SomaContainerAdapter.d.ts +30 -0
- package/dist/types/diagnostics/SomaDiagnostics.d.ts +64 -0
- package/dist/types/diagnostics/SomaTelemetry.d.ts +32 -0
- package/dist/types/diagnostics/telemetry-context.d.ts +4 -0
- package/dist/types/engine/asset-resolver.d.ts +17 -0
- package/dist/types/engine/dom-renderer.d.ts +35 -0
- package/dist/types/engine/event-engine.d.ts +64 -0
- package/dist/types/engine/lis.d.ts +10 -0
- package/dist/types/engine/on-change-engine.d.ts +16 -0
- package/dist/types/engine/property-watcher.d.ts +18 -0
- package/dist/types/engine/reactive-proxy.d.ts +58 -0
- package/dist/types/engine/render-engine.d.ts +73 -0
- package/dist/types/engine/runtime-builder.d.ts +58 -0
- package/dist/types/engine/scope-resolver.d.ts +90 -0
- package/dist/types/engine/soma-bootstrap.d.ts +112 -0
- package/dist/types/engine/style-binder.d.ts +81 -0
- package/dist/types/engine/theme-variables.d.ts +3 -0
- package/dist/types/engine/timer-engine.d.ts +19 -0
- package/dist/types/engine/trigger-engine.d.ts +16 -0
- package/dist/types/host/resolve-host-bootstrap.d.ts +11 -0
- package/dist/types/host/soma-bootstrap-host.stub.d.ts +3 -0
- package/dist/types/index.d.ts +35 -0
- package/dist/types/infra/auth/IAuthService.d.ts +12 -0
- package/dist/types/infra/auth/TokenAuthService.d.ts +26 -0
- package/dist/types/infra/cache/ICache.d.ts +12 -0
- package/dist/types/infra/cache/MemoryCache.d.ts +14 -0
- package/dist/types/infra/cache/ServerFileCache.d.ts +37 -0
- package/dist/types/infra/config/IConfig.d.ts +9 -0
- package/dist/types/infra/config/SomaConfig.d.ts +21 -0
- package/dist/types/infra/event-bus/IEventBus.d.ts +8 -0
- package/dist/types/infra/event-bus/SomaEventBus.d.ts +9 -0
- package/dist/types/infra/http/IHttpClient.d.ts +28 -0
- package/dist/types/infra/http/SomaHttpService.d.ts +27 -0
- package/dist/types/infra/i18n/DefaultI18n.d.ts +7 -0
- package/dist/types/infra/i18n/II18n.d.ts +6 -0
- package/dist/types/infra/logger/ConsoleLogger.d.ts +14 -0
- package/dist/types/infra/logger/ILogger.d.ts +17 -0
- package/dist/types/infra/notify/DefaultNotifyService.d.ts +16 -0
- package/dist/types/infra/notify/DomNotifyService.d.ts +16 -0
- package/dist/types/infra/notify/INotifyService.d.ts +12 -0
- package/dist/types/infra/notify/INotifyTheme.d.ts +12 -0
- package/dist/types/infra/permission/IPermission.d.ts +10 -0
- package/dist/types/infra/permission/SomaPermission.d.ts +19 -0
- package/dist/types/infra/realtime/IRealtimeService.d.ts +13 -0
- package/dist/types/infra/realtime/IRealtimeTransport.d.ts +8 -0
- package/dist/types/infra/realtime/SomaRealtimeService.d.ts +20 -0
- package/dist/types/infra/realtime/SseRealtimeTransport.d.ts +11 -0
- package/dist/types/infra/realtime/WebSocketRealtimeTransport.d.ts +30 -0
- package/dist/types/infra/router/IRouter.d.ts +16 -0
- package/dist/types/infra/router/SomaRouter.d.ts +18 -0
- package/dist/types/infra/router/router-path.d.ts +6 -0
- package/dist/types/infra/storage/IStorageService.d.ts +7 -0
- package/dist/types/infra/storage/MemoryStorageService.d.ts +15 -0
- package/dist/types/infra/storage/SessionStorageService.d.ts +14 -0
- package/dist/types/infra/timer/ITimer.d.ts +13 -0
- package/dist/types/infra/timer/SomaTimer.d.ts +21 -0
- package/dist/types/manifest/manifest-contract.d.ts +4 -0
- package/dist/types/middleware/SomaMiddlewareChain.d.ts +6 -0
- package/dist/types/middleware/createPermissionMiddleware.d.ts +14 -0
- package/dist/types/parser/annotation-extractor.d.ts +12 -0
- package/dist/types/parser/pipeline-parser.d.ts +62 -0
- package/dist/types/parser/style-config-parser.d.ts +20 -0
- package/dist/types/parser/timer-parser.d.ts +6 -0
- package/dist/types/parser/trigger-parser.d.ts +13 -0
- package/dist/types/parser/ui-config-parser.d.ts +34 -0
- package/dist/types/parser/yaml-loader.d.ts +21 -0
- package/dist/types/quality/SomaQualityRegistry.d.ts +31 -0
- package/dist/types/runtime/SomaRuntimeServices.d.ts +35 -0
- package/dist/types/runtime/SomaSnapshotStore.d.ts +13 -0
- package/dist/types/scheduler/SomaScheduler.d.ts +25 -0
- package/dist/types/types/domain.types.d.ts +82 -0
- package/dist/types/types/engine.types.d.ts +22 -0
- package/dist/types/types/event.types.d.ts +61 -0
- package/dist/types/types/keyboard.types.d.ts +4 -0
- package/dist/types/types/manifest.types.d.ts +29 -0
- package/dist/types/types/scheduler.types.d.ts +8 -0
- package/dist/types/types/style-config.types.d.ts +62 -0
- package/dist/types/types/timer.types.d.ts +19 -0
- package/dist/types/types/trigger.types.d.ts +12 -0
- package/dist/types/types/ui-config.types.d.ts +85 -0
- package/dist/types/types/watcher.types.d.ts +24 -0
- package/dist/types/validation/contract-validator.d.ts +40 -0
- package/editor/vscode/extension.js +39 -0
- package/editor/vscode/language-configuration.json +17 -0
- package/editor/vscode/package.json +98 -0
- package/editor/vscode/syntaxes/soma-event-yaml.tmLanguage.json +30 -0
- package/editor/vscode/syntaxes/soma-ui-yaml.tmLanguage.json +42 -0
- package/global.d.ts +19 -0
- package/next.config.js +9 -4
- package/package.json +53 -16
- package/tailwind.config.ts +26 -7
- package/tsconfig.json +6 -2
- package/core/router/RouteHandler.ts +0 -93
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
// core/parser/style-config-parser.ts — SOMA 样式配置解析器
|
|
2
|
+
// 负责将 _style.yaml 解析后的原始对象转换为类型安全的 StyleConfig 结构
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
StyleConfig,
|
|
6
|
+
StyleStateRule,
|
|
7
|
+
StyleTransition,
|
|
8
|
+
ThemeConfig,
|
|
9
|
+
TransitionTrigger,
|
|
10
|
+
} from '../types/style-config.types';
|
|
11
|
+
|
|
12
|
+
// ─── 错误类 ───────────────────────────────────────────────────────────────────
|
|
13
|
+
|
|
14
|
+
export class SomaStyleConfigError extends Error {
|
|
15
|
+
public readonly path: string;
|
|
16
|
+
|
|
17
|
+
constructor(message: string, path: string = '') {
|
|
18
|
+
const prefix = path ? ` (路径: ${path})` : '';
|
|
19
|
+
super(`[SOMA StyleConfigParser] ${message}${prefix}`);
|
|
20
|
+
this.name = 'SomaStyleConfigError';
|
|
21
|
+
this.path = path;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// ─── 常量 ─────────────────────────────────────────────────────────────────────
|
|
26
|
+
|
|
27
|
+
const VALID_TRIGGERS = new Set<TransitionTrigger>([
|
|
28
|
+
'hover', 'focus', 'active', 'enter', 'leave', 'active_state',
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
// ─── 内部校验函数 ─────────────────────────────────────────────────────────────
|
|
32
|
+
|
|
33
|
+
function isValidConditionPath(path: string): boolean {
|
|
34
|
+
if (!path) return false;
|
|
35
|
+
// 纯属性路径:仅允许 字母/数字/下划线 + 点分隔
|
|
36
|
+
return /^[a-zA-Z_]\w*(\.[a-zA-Z_]\w*)*$/.test(path);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function isPrimitiveValue(value: unknown): value is string | number | boolean | null {
|
|
40
|
+
if (value === null) return true;
|
|
41
|
+
const t = typeof value;
|
|
42
|
+
return t === 'string' || t === 'number' || t === 'boolean';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function validateSomaId(somaId: string, path: string): void {
|
|
46
|
+
if (!somaId || typeof somaId !== 'string') {
|
|
47
|
+
throw new SomaStyleConfigError(`data-soma-id 不能为空`, path);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// ─── base 解析 ────────────────────────────────────────────────────────────────
|
|
52
|
+
|
|
53
|
+
function parseBase(raw: unknown, path: string): Record<string, string> {
|
|
54
|
+
if (!raw) return {};
|
|
55
|
+
if (typeof raw !== 'object' || Array.isArray(raw)) {
|
|
56
|
+
throw new SomaStyleConfigError(`base 必须是对象(somaId → 类名字符串)`, path);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const result: Record<string, string> = {};
|
|
60
|
+
for (const [somaId, classes] of Object.entries(raw as Record<string, unknown>)) {
|
|
61
|
+
validateSomaId(somaId, `${path}.${somaId}`);
|
|
62
|
+
if (typeof classes !== 'string') {
|
|
63
|
+
throw new SomaStyleConfigError(
|
|
64
|
+
`base 的值必须是 Tailwind 类名字符串,当前值: ${JSON.stringify(classes)}`,
|
|
65
|
+
`${path}.${somaId}`,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
result[somaId] = classes;
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// ─── states 解析 ──────────────────────────────────────────────────────────────
|
|
74
|
+
|
|
75
|
+
function parseStateRule(raw: unknown, path: string): StyleStateRule {
|
|
76
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
77
|
+
throw new SomaStyleConfigError(`状态规则必须是对象`, path);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const obj = raw as Record<string, unknown>;
|
|
81
|
+
|
|
82
|
+
// condition
|
|
83
|
+
if (!obj.condition || typeof obj.condition !== 'string') {
|
|
84
|
+
throw new SomaStyleConfigError(
|
|
85
|
+
`condition 必须是非空字符串,当前值: ${JSON.stringify(obj.condition)}`,
|
|
86
|
+
path,
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
if (!isValidConditionPath(obj.condition)) {
|
|
90
|
+
throw new SomaStyleConfigError(
|
|
91
|
+
`condition 必须是纯属性路径(如 "a.b.c"),禁止包含运算符,当前值: "${obj.condition}"`,
|
|
92
|
+
path,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// value
|
|
97
|
+
if (!('value' in obj)) {
|
|
98
|
+
throw new SomaStyleConfigError(`缺少必填字段 value`, path);
|
|
99
|
+
}
|
|
100
|
+
if (!isPrimitiveValue(obj.value)) {
|
|
101
|
+
throw new SomaStyleConfigError(
|
|
102
|
+
`value 必须是基础类型(string/number/boolean/null),当前值: ${JSON.stringify(obj.value)}`,
|
|
103
|
+
path,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// apply
|
|
108
|
+
if (!obj.apply || typeof obj.apply !== 'string') {
|
|
109
|
+
throw new SomaStyleConfigError(
|
|
110
|
+
`apply 必须是非空 Tailwind 类名字符串,当前值: ${JSON.stringify(obj.apply)}`,
|
|
111
|
+
path,
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
condition: obj.condition,
|
|
117
|
+
value: obj.value as string | number | boolean | null,
|
|
118
|
+
apply: obj.apply,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function parseStates(raw: unknown, path: string): Record<string, StyleStateRule[]> {
|
|
123
|
+
if (!raw) return {};
|
|
124
|
+
if (typeof raw !== 'object' || Array.isArray(raw)) {
|
|
125
|
+
throw new SomaStyleConfigError(`states 必须是对象(somaId → 规则数组)`, path);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const result: Record<string, StyleStateRule[]> = {};
|
|
129
|
+
for (const [somaId, rules] of Object.entries(raw as Record<string, unknown>)) {
|
|
130
|
+
validateSomaId(somaId, `${path}.${somaId}`);
|
|
131
|
+
if (!Array.isArray(rules)) {
|
|
132
|
+
throw new SomaStyleConfigError(
|
|
133
|
+
`states.${somaId} 的值必须是数组,当前类型: ${typeof rules}`,
|
|
134
|
+
`${path}.${somaId}`,
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
result[somaId] = rules.map((rule, idx) =>
|
|
138
|
+
parseStateRule(rule, `${path}.${somaId}[${idx}]`),
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// ─── transitions 解析 ─────────────────────────────────────────────────────────
|
|
145
|
+
|
|
146
|
+
function parseTransition(raw: unknown, somaId: string, path: string): StyleTransition {
|
|
147
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
148
|
+
throw new SomaStyleConfigError(`过渡配置必须是对象`, path);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const obj = raw as Record<string, unknown>;
|
|
152
|
+
|
|
153
|
+
// trigger
|
|
154
|
+
if (!obj.trigger || typeof obj.trigger !== 'string') {
|
|
155
|
+
throw new SomaStyleConfigError(
|
|
156
|
+
`trigger 必须是非空字符串,当前值: ${JSON.stringify(obj.trigger)}`,
|
|
157
|
+
path,
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
if (!VALID_TRIGGERS.has(obj.trigger as TransitionTrigger)) {
|
|
161
|
+
throw new SomaStyleConfigError(
|
|
162
|
+
`不支持的 trigger "${obj.trigger}",支持的值: ${[...VALID_TRIGGERS].join(', ')}`,
|
|
163
|
+
path,
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// apply
|
|
168
|
+
if (!obj.apply || typeof obj.apply !== 'string') {
|
|
169
|
+
throw new SomaStyleConfigError(
|
|
170
|
+
`apply 必须是非空 Tailwind 类名字符串,当前值: ${JSON.stringify(obj.apply)}`,
|
|
171
|
+
path,
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const result: StyleTransition = {
|
|
176
|
+
trigger: obj.trigger as TransitionTrigger,
|
|
177
|
+
apply: obj.apply,
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
// active_state 专有字段
|
|
181
|
+
if (obj.trigger === 'active_state') {
|
|
182
|
+
if (!obj.condition || typeof obj.condition !== 'string') {
|
|
183
|
+
throw new SomaStyleConfigError(
|
|
184
|
+
`active_state 类型的 trigger 必须提供 condition 字段`,
|
|
185
|
+
path,
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
if (!isValidConditionPath(obj.condition)) {
|
|
189
|
+
throw new SomaStyleConfigError(
|
|
190
|
+
`condition 必须是纯属性路径,当前值: "${obj.condition}"`,
|
|
191
|
+
path,
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
if (!('value' in obj)) {
|
|
195
|
+
throw new SomaStyleConfigError(
|
|
196
|
+
`active_state 类型的 trigger 必须提供 value 字段`,
|
|
197
|
+
path,
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
if (!isPrimitiveValue(obj.value)) {
|
|
201
|
+
throw new SomaStyleConfigError(
|
|
202
|
+
`value 必须是基础类型,当前值: ${JSON.stringify(obj.value)}`,
|
|
203
|
+
path,
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
result.condition = obj.condition;
|
|
207
|
+
result.value = obj.value as string | number | boolean | null;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return result;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function parseTransitions(raw: unknown, path: string): Record<string, StyleTransition> {
|
|
214
|
+
if (!raw) return {};
|
|
215
|
+
if (typeof raw !== 'object' || Array.isArray(raw)) {
|
|
216
|
+
throw new SomaStyleConfigError(`transitions 必须是对象(somaId → 过渡配置)`, path);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const result: Record<string, StyleTransition> = {};
|
|
220
|
+
for (const [somaId, config] of Object.entries(raw as Record<string, unknown>)) {
|
|
221
|
+
validateSomaId(somaId, `${path}.${somaId}`);
|
|
222
|
+
result[somaId] = parseTransition(config, somaId, `${path}.${somaId}`);
|
|
223
|
+
}
|
|
224
|
+
return result;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// ─── themes 解析 ──────────────────────────────────────────────────────────────
|
|
228
|
+
|
|
229
|
+
function parseTheme(raw: unknown, themeName: string, path: string): ThemeConfig {
|
|
230
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
231
|
+
throw new SomaStyleConfigError(`主题 "${themeName}" 必须是对象`, path);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const obj = raw as Record<string, unknown>;
|
|
235
|
+
const base: Record<string, string> = {};
|
|
236
|
+
const states: Record<string, StyleStateRule[]> = {};
|
|
237
|
+
let vars: Record<string, string> | undefined;
|
|
238
|
+
|
|
239
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
240
|
+
if (key === 'states') {
|
|
241
|
+
// 嵌套 states 覆盖
|
|
242
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
243
|
+
throw new SomaStyleConfigError(
|
|
244
|
+
`主题内的 states 必须是对象`,
|
|
245
|
+
`${path}.states`,
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
for (const [somaId, rules] of Object.entries(value as Record<string, unknown>)) {
|
|
249
|
+
validateSomaId(somaId, `${path}.states.${somaId}`);
|
|
250
|
+
if (!Array.isArray(rules)) {
|
|
251
|
+
throw new SomaStyleConfigError(
|
|
252
|
+
`主题 states.${somaId} 必须是数组`,
|
|
253
|
+
`${path}.states.${somaId}`,
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
states[somaId] = rules.map((rule, idx) =>
|
|
257
|
+
parseStateRule(rule, `${path}.states.${somaId}[${idx}]`),
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
} else if (key === 'vars') {
|
|
261
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
262
|
+
throw new SomaStyleConfigError(`主题 vars 必须是对象`, `${path}.vars`);
|
|
263
|
+
}
|
|
264
|
+
vars = {};
|
|
265
|
+
for (const [varKey, varVal] of Object.entries(value as Record<string, unknown>)) {
|
|
266
|
+
if (typeof varVal !== 'string') {
|
|
267
|
+
throw new SomaStyleConfigError(`vars.${varKey} 必须是字符串`, `${path}.vars.${varKey}`);
|
|
268
|
+
}
|
|
269
|
+
vars[varKey] = varVal;
|
|
270
|
+
}
|
|
271
|
+
} else {
|
|
272
|
+
// 直铺的 somaId → 类名覆盖
|
|
273
|
+
if (typeof value !== 'string') {
|
|
274
|
+
throw new SomaStyleConfigError(
|
|
275
|
+
`主题基础覆盖的值必须是 Tailwind 类名字符串,当前值: ${JSON.stringify(value)}`,
|
|
276
|
+
`${path}.${key}`,
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
base[key] = value;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return { base, states, vars };
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function parseThemes(raw: unknown, path: string): Record<string, ThemeConfig> {
|
|
287
|
+
if (!raw) return {};
|
|
288
|
+
if (typeof raw !== 'object' || Array.isArray(raw)) {
|
|
289
|
+
throw new SomaStyleConfigError(`themes 必须是对象(主题名 → 配置)`, path);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const result: Record<string, ThemeConfig> = {};
|
|
293
|
+
for (const [themeName, config] of Object.entries(raw as Record<string, unknown>)) {
|
|
294
|
+
if (!themeName) {
|
|
295
|
+
throw new SomaStyleConfigError(`主题名不能为空`, path);
|
|
296
|
+
}
|
|
297
|
+
result[themeName] = parseTheme(config, themeName, `${path}.${themeName}`);
|
|
298
|
+
}
|
|
299
|
+
return result;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// ─── 公共 API ─────────────────────────────────────────────────────────────────
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* 将 YAML 解析后的原始对象转换为类型安全的 StyleConfig
|
|
306
|
+
*
|
|
307
|
+
* 校验规则:
|
|
308
|
+
* - host 必须是非空字符串
|
|
309
|
+
* - base 的值必须是纯 Tailwind 类名字符串
|
|
310
|
+
* - states 的 condition 必须是纯属性路径,value 必须是基础类型
|
|
311
|
+
* - transitions 的 trigger 必须是有效枚举值
|
|
312
|
+
* - themes 仅允许覆盖视觉类名,不可引入新的布局类
|
|
313
|
+
*
|
|
314
|
+
* @param raw - YAML 解析后的原始对象
|
|
315
|
+
* @returns 类型安全的 StyleConfig
|
|
316
|
+
* @throws SomaStyleConfigError 格式不合法时抛出
|
|
317
|
+
*/
|
|
318
|
+
export function parseStyleConfig(raw: unknown): StyleConfig {
|
|
319
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
320
|
+
throw new SomaStyleConfigError(`样式配置必须是对象`);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const obj = raw as Record<string, unknown>;
|
|
324
|
+
|
|
325
|
+
// host
|
|
326
|
+
if (!obj.host || typeof obj.host !== 'string') {
|
|
327
|
+
throw new SomaStyleConfigError(
|
|
328
|
+
`host 必须是非空字符串,当前值: ${JSON.stringify(obj.host)}`,
|
|
329
|
+
'host',
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
return {
|
|
334
|
+
host: obj.host,
|
|
335
|
+
base: parseBase(obj.base, 'base'),
|
|
336
|
+
states: parseStates(obj.states, 'states'),
|
|
337
|
+
transitions: parseTransitions(obj.transitions, 'transitions'),
|
|
338
|
+
themes: parseThemes(obj.themes, 'themes'),
|
|
339
|
+
};
|
|
340
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// core/parser/timer-parser.ts — 解析 _event.yaml 的 timers 块
|
|
2
|
+
|
|
3
|
+
import { parsePipelineBody } from './pipeline-parser';
|
|
4
|
+
import type { ParsedTimer } from '../types/timer.types';
|
|
5
|
+
|
|
6
|
+
export class SomaTimerParseError extends Error {
|
|
7
|
+
constructor(message: string) {
|
|
8
|
+
super(`[SOMA TimerParser] ${message}`);
|
|
9
|
+
this.name = 'SomaTimerParseError';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function parseTimerItem(raw: unknown, index: number): ParsedTimer {
|
|
14
|
+
if (!raw || typeof raw !== 'object') {
|
|
15
|
+
throw new SomaTimerParseError(`timers[${index}] 必须是对象`);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const item = raw as Record<string, unknown>;
|
|
19
|
+
|
|
20
|
+
if (typeof item.id !== 'string' || !item.id.trim()) {
|
|
21
|
+
throw new SomaTimerParseError(`timers[${index}].id 必须是非空字符串`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const tick = item.tick;
|
|
25
|
+
if (typeof tick !== 'string' || !tick.trim()) {
|
|
26
|
+
throw new SomaTimerParseError(`timers[${index}].tick 必须是 Pipeline 表达式`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const once = item.once === true;
|
|
30
|
+
const delayMs = typeof item.delay === 'number' && item.delay >= 0 ? item.delay : 0;
|
|
31
|
+
|
|
32
|
+
let intervalMs = 0;
|
|
33
|
+
if (typeof item.interval === 'number' && item.interval > 0) {
|
|
34
|
+
intervalMs = item.interval;
|
|
35
|
+
} else if (once && typeof item.delay === 'number' && item.delay > 0) {
|
|
36
|
+
intervalMs = item.delay;
|
|
37
|
+
} else {
|
|
38
|
+
throw new SomaTimerParseError(
|
|
39
|
+
`timers[${index}] 需指定 interval(周期毫秒)或 once: true 且 delay > 0`,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
id: item.id.trim(),
|
|
45
|
+
intervalMs,
|
|
46
|
+
delayMs,
|
|
47
|
+
once,
|
|
48
|
+
pipeline: parsePipelineBody(tick.trim()),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function parseTimers(raw: unknown): ParsedTimer[] {
|
|
53
|
+
if (raw === undefined || raw === null) {
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
if (!Array.isArray(raw)) {
|
|
57
|
+
throw new SomaTimerParseError('timers 必须是数组');
|
|
58
|
+
}
|
|
59
|
+
return raw.map((item, index) => parseTimerItem(item, index));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function compileTimer(timer: ParsedTimer): import('../types/timer.types').SomaCompiledTimer {
|
|
63
|
+
const somaId = `@timer.${timer.id}`;
|
|
64
|
+
return {
|
|
65
|
+
...timer,
|
|
66
|
+
somaId,
|
|
67
|
+
domEvent: 'tick',
|
|
68
|
+
eventKey: `tick:${somaId}`,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// core/parser/trigger-parser.ts — 解析 _event.yaml 的 triggers 块
|
|
2
|
+
|
|
3
|
+
import type { PropertyTrigger } from '../types/trigger.types';
|
|
4
|
+
import { parseTimers } from './timer-parser';
|
|
5
|
+
import type { ParsedTimer } from '../types/timer.types';
|
|
6
|
+
|
|
7
|
+
export class SomaTriggerParseError extends Error {
|
|
8
|
+
constructor(message: string) {
|
|
9
|
+
super(`[SOMA TriggerParser] ${message}`);
|
|
10
|
+
this.name = 'SomaTriggerParseError';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function parseTriggerItem(raw: unknown, index: number): PropertyTrigger {
|
|
15
|
+
if (!raw || typeof raw !== 'object') {
|
|
16
|
+
throw new SomaTriggerParseError(`triggers[${index}] 必须是对象`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const item = raw as Record<string, unknown>;
|
|
20
|
+
|
|
21
|
+
if (typeof item.condition !== 'string' || !item.condition.trim()) {
|
|
22
|
+
throw new SomaTriggerParseError(`triggers[${index}].condition 必须是非空字符串`);
|
|
23
|
+
}
|
|
24
|
+
if (typeof item.target !== 'string' || !item.target.trim()) {
|
|
25
|
+
throw new SomaTriggerParseError(`triggers[${index}].target 必须是非空字符串`);
|
|
26
|
+
}
|
|
27
|
+
if (typeof item.event !== 'string' || !item.event.trim()) {
|
|
28
|
+
throw new SomaTriggerParseError(`triggers[${index}].event 必须是非空字符串`);
|
|
29
|
+
}
|
|
30
|
+
if (!('value' in item)) {
|
|
31
|
+
throw new SomaTriggerParseError(`triggers[${index}].value 为必填字段`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const value = item.value as PropertyTrigger['value'];
|
|
35
|
+
if (
|
|
36
|
+
value !== null &&
|
|
37
|
+
typeof value !== 'string' &&
|
|
38
|
+
typeof value !== 'number' &&
|
|
39
|
+
typeof value !== 'boolean'
|
|
40
|
+
) {
|
|
41
|
+
throw new SomaTriggerParseError(
|
|
42
|
+
`triggers[${index}].value 必须是 string | number | boolean | null`,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const trigger: PropertyTrigger = {
|
|
47
|
+
condition: item.condition.trim(),
|
|
48
|
+
value,
|
|
49
|
+
target: item.target.trim(),
|
|
50
|
+
event: item.event.trim(),
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
if (item.detail !== undefined) {
|
|
54
|
+
if (typeof item.detail !== 'object' || item.detail === null || Array.isArray(item.detail)) {
|
|
55
|
+
throw new SomaTriggerParseError(`triggers[${index}].detail 必须是对象`);
|
|
56
|
+
}
|
|
57
|
+
trigger.detail = item.detail as Record<string, unknown>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return trigger;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** 解析 triggers 数组(YAML 中 triggers: [...]) */
|
|
64
|
+
export function parseTriggers(raw: unknown): PropertyTrigger[] {
|
|
65
|
+
if (raw === undefined || raw === null) {
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
if (!Array.isArray(raw)) {
|
|
69
|
+
throw new SomaTriggerParseError('triggers 必须是数组');
|
|
70
|
+
}
|
|
71
|
+
return raw.map((item, index) => parseTriggerItem(item, index));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** 从 event 配置根对象分离 triggers / timers 与事件声明 */
|
|
75
|
+
export function splitEventConfigRaw(raw: unknown): {
|
|
76
|
+
eventsRaw: Record<string, unknown>;
|
|
77
|
+
triggers: PropertyTrigger[];
|
|
78
|
+
timers: ParsedTimer[];
|
|
79
|
+
} {
|
|
80
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
81
|
+
return { eventsRaw: {}, triggers: [], timers: [] };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const { triggers: triggersRaw, timers: timersRaw, ...eventsRaw } = raw as Record<string, unknown>;
|
|
85
|
+
return {
|
|
86
|
+
eventsRaw,
|
|
87
|
+
triggers: parseTriggers(triggersRaw),
|
|
88
|
+
timers: parseTimers(timersRaw),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
@@ -10,6 +10,7 @@ import type {
|
|
|
10
10
|
ExtendedShowValue,
|
|
11
11
|
ParsedShowEntry,
|
|
12
12
|
} from '../types/ui-config.types';
|
|
13
|
+
import type { OnChangeRule } from '../types/watcher.types';
|
|
13
14
|
|
|
14
15
|
// ─── 错误类 ───────────────────────────────────────────────────────────────────
|
|
15
16
|
|
|
@@ -60,6 +61,67 @@ function validateBind(bind: any, path: string): asserts bind is BindDeclaration
|
|
|
60
61
|
path,
|
|
61
62
|
);
|
|
62
63
|
}
|
|
64
|
+
|
|
65
|
+
if ('onChange' in bind && bind.onChange !== undefined) {
|
|
66
|
+
parseOnChangeRules(bind.onChange, `${path}.onChange`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function parseOnChangeRules(raw: unknown, path: string): OnChangeRule[] {
|
|
71
|
+
if (!Array.isArray(raw)) {
|
|
72
|
+
throw new SomaUiConfigError('onChange 必须是数组', path);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return raw.map((item, index) => {
|
|
76
|
+
const itemPath = `${path}[${index}]`;
|
|
77
|
+
if (!item || typeof item !== 'object') {
|
|
78
|
+
throw new SomaUiConfigError('onChange 条目必须是对象', itemPath);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const rule = item as Record<string, unknown>;
|
|
82
|
+
if (typeof rule.condition !== 'string' || !rule.condition.trim()) {
|
|
83
|
+
throw new SomaUiConfigError('condition 必须是非空字符串', itemPath);
|
|
84
|
+
}
|
|
85
|
+
if (typeof rule.callback !== 'string' || !rule.callback.trim()) {
|
|
86
|
+
throw new SomaUiConfigError('callback 必须是非空字符串', itemPath);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const parsed: OnChangeRule = {
|
|
90
|
+
condition: rule.condition.trim(),
|
|
91
|
+
callback: rule.callback.trim(),
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
if (rule.refresh !== undefined) {
|
|
95
|
+
if (typeof rule.refresh !== 'boolean') {
|
|
96
|
+
throw new SomaUiConfigError('refresh 必须是布尔值', itemPath);
|
|
97
|
+
}
|
|
98
|
+
parsed.refresh = rule.refresh;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (rule.debounce !== undefined) {
|
|
102
|
+
if (typeof rule.debounce !== 'number' || rule.debounce < 0) {
|
|
103
|
+
throw new SomaUiConfigError('debounce 必须是非负数字', itemPath);
|
|
104
|
+
}
|
|
105
|
+
parsed.debounce = rule.debounce;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return parsed;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function parseInitProps(raw: unknown, path: string): Record<string, unknown> {
|
|
113
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
114
|
+
throw new SomaUiConfigError('initProps 必须是对象', path);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const result: Record<string, unknown> = {};
|
|
118
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
119
|
+
if (!key.trim()) {
|
|
120
|
+
throw new SomaUiConfigError('initProps 的键不能为空', path);
|
|
121
|
+
}
|
|
122
|
+
result[key] = value;
|
|
123
|
+
}
|
|
124
|
+
return result;
|
|
63
125
|
}
|
|
64
126
|
|
|
65
127
|
/**
|
|
@@ -306,9 +368,19 @@ export function parseUiConfig(raw: any): UiConfig {
|
|
|
306
368
|
var: raw.bind.var,
|
|
307
369
|
};
|
|
308
370
|
|
|
371
|
+
if (Array.isArray(raw.bind.onChange)) {
|
|
372
|
+
bind.onChange = parseOnChangeRules(raw.bind.onChange, 'bind.onChange');
|
|
373
|
+
}
|
|
374
|
+
|
|
309
375
|
const show = parseShowMapping(raw.show, 'show');
|
|
310
376
|
|
|
311
|
-
|
|
377
|
+
const config: UiConfig = { bind, show };
|
|
378
|
+
|
|
379
|
+
if ('initProps' in raw && raw.initProps !== undefined) {
|
|
380
|
+
config.initProps = parseInitProps(raw.initProps, 'initProps');
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
return config;
|
|
312
384
|
}
|
|
313
385
|
|
|
314
386
|
/**
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { SomaDiagnosticsSnapshot } from '../diagnostics/SomaDiagnostics';
|
|
2
|
+
|
|
3
|
+
export interface QualityPillar {
|
|
4
|
+
id: 'contract' | 'diagnostics' | 'snapshot' | 'dev-guard';
|
|
5
|
+
name: string;
|
|
6
|
+
carrier: string;
|
|
7
|
+
description: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface PerformanceLayer {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
carrier: string;
|
|
14
|
+
description: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ExtensibilityDimension {
|
|
18
|
+
id: string;
|
|
19
|
+
name: string;
|
|
20
|
+
carrier: string;
|
|
21
|
+
description: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Registry of quality, performance, and extensibility capabilities */
|
|
25
|
+
export class SomaQualityRegistry {
|
|
26
|
+
static readonly qualityPillars: QualityPillar[] = [
|
|
27
|
+
{ id: 'contract', name: 'Contract validation', carrier: 'SomaContractValidator', description: 'Validate host anchors and func paths before mount' },
|
|
28
|
+
{ id: 'diagnostics', name: 'Runtime diagnostics', carrier: 'SomaDiagnostics', description: 'Track mutation/render/event/validation/scheduler records' },
|
|
29
|
+
{ id: 'snapshot', name: 'State snapshots', carrier: 'SomaSnapshotStore', description: 'Deep-clone capture/restore for time-travel debugging' },
|
|
30
|
+
{ id: 'dev-guard', name: 'Array mutation warnings', carrier: 'SomaReactiveProxy', description: 'Warn on in-place array mutations in dev mode' },
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
static readonly performanceLayers: PerformanceLayer[] = [
|
|
34
|
+
{ id: 'manifest', name: 'Compiled manifest', carrier: 'SomaManifestCompiler', description: 'O(1) bindingIndex and eventIndex lookups' },
|
|
35
|
+
{ id: 'scheduler', name: 'Task scheduler', carrier: 'SomaScheduler', description: 'Three-priority queue with microtask flush' },
|
|
36
|
+
{ id: 'parallel-patch', name: 'Parallel patch', carrier: 'SomaRenderEngine', description: 'Concurrent render for multiple paths in one batch' },
|
|
37
|
+
{ id: 'lis', name: 'Keyed list diff', carrier: 'lis.ts + DomRenderer', description: 'O(n log n) LIS minimal DOM moves' },
|
|
38
|
+
{ id: 'cache', name: 'Parse cache', carrier: 'SomaAssetResolver', description: 'LRU cache for YAML parse results' },
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
static readonly extensibilityDimensions: ExtensibilityDimension[] = [
|
|
42
|
+
{ id: 'adapter', name: 'Container adapter', carrier: 'SomaContainerAdapter', description: 'Isolate DOM ops for cross-platform hosts' },
|
|
43
|
+
{ id: 'middleware', name: 'Middleware chains', carrier: 'SomaMiddlewareChain', description: 'Onion-model hooks for render and event engines' },
|
|
44
|
+
{ id: 'hotswap', name: 'Hot swap', carrier: 'SomaBootstrap.hotSwap', description: 'Replace ui/event/style/DomainClass at runtime' },
|
|
45
|
+
{ id: 'services', name: 'Runtime services', carrier: 'SomaRuntimeServices', description: 'Inject router/http/notify and other infra into domain' },
|
|
46
|
+
{ id: 'aot', name: 'AOT precompile', carrier: 'soma-precompile + bundler plugins', description: 'Compile YAML to JS at build time' },
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
getSummary(): {
|
|
50
|
+
quality: QualityPillar[];
|
|
51
|
+
performance: PerformanceLayer[];
|
|
52
|
+
extensibility: ExtensibilityDimension[];
|
|
53
|
+
} {
|
|
54
|
+
return {
|
|
55
|
+
quality: SomaQualityRegistry.qualityPillars,
|
|
56
|
+
performance: SomaQualityRegistry.performanceLayers,
|
|
57
|
+
extensibility: SomaQualityRegistry.extensibilityDimensions,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
computeHealthScore(snapshot: SomaDiagnosticsSnapshot): number {
|
|
62
|
+
const errors =
|
|
63
|
+
snapshot.events.filter((e) => e.status === 'error').length +
|
|
64
|
+
snapshot.validations.length;
|
|
65
|
+
const total = snapshot.counters.events + snapshot.counters.validations + 1;
|
|
66
|
+
return Math.max(0, Math.round(100 - (errors / total) * 100));
|
|
67
|
+
}
|
|
68
|
+
}
|