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,49 @@
|
|
|
1
|
+
import type { SomaPageRoot, SomaAppConfig } from '../types/domain.types';
|
|
2
|
+
import type { SomaRuntimeServices } from '../runtime/SomaRuntimeServices';
|
|
3
|
+
/**
|
|
4
|
+
* SomaPageRootBase — 页面聚合根基类
|
|
5
|
+
*
|
|
6
|
+
* 与物理页面(如 index.html)严格 1:1 绑定的聚合根对象。
|
|
7
|
+
* 提供页面级状态管理和生命周期钩子的默认实现。
|
|
8
|
+
*
|
|
9
|
+
* 子类应当:
|
|
10
|
+
* - override onMount() 实现页面初始化逻辑(加载数据、字典等)
|
|
11
|
+
* - override onUnmount() 实现页面清理逻辑(取消请求、清除定时器等)
|
|
12
|
+
* - 聚合业务对象和常量对象作为属性
|
|
13
|
+
*/
|
|
14
|
+
export declare abstract class SomaPageRootBase implements SomaPageRoot {
|
|
15
|
+
/** 页面级 loading 状态(Proxy 响应式) */
|
|
16
|
+
pageLoading: boolean;
|
|
17
|
+
/** 页面级错误信息(Proxy 响应式) */
|
|
18
|
+
pageError: string | null;
|
|
19
|
+
/**
|
|
20
|
+
* Content strings from locale.yaml injected by bootstrap.
|
|
21
|
+
* Not a multi-locale switcher — replace locale.yaml to change copy.
|
|
22
|
+
*/
|
|
23
|
+
_locale: Record<string, string>;
|
|
24
|
+
/**
|
|
25
|
+
* 由引擎注入的应用配置
|
|
26
|
+
* 包含 API 地址、分页大小、超时时间等外部配置
|
|
27
|
+
*/
|
|
28
|
+
_config: SomaAppConfig;
|
|
29
|
+
/** 由引擎注入的运行时基础设施(router / http / notify 等) */
|
|
30
|
+
_services?: SomaRuntimeServices;
|
|
31
|
+
/**
|
|
32
|
+
* 封装页面级异步操作:自动管理 pageLoading / pageError
|
|
33
|
+
*/
|
|
34
|
+
protected runAsync<R>(fn: () => Promise<R>): Promise<R | null>;
|
|
35
|
+
/** 读取 URL query(优先内存路由,回退地址栏) */
|
|
36
|
+
protected readQueryParam(key: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* 页面初始化生命周期钩子
|
|
39
|
+
* 引擎在渲染完成后调用
|
|
40
|
+
* 子类 override 实现具体初始化逻辑
|
|
41
|
+
*/
|
|
42
|
+
onMount(): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* 页面销毁前生命周期钩子
|
|
45
|
+
* 引擎在卸载时调用
|
|
46
|
+
* 子类 override 实现清理逻辑
|
|
47
|
+
*/
|
|
48
|
+
onUnmount(): void;
|
|
49
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { ValidationRule, ValidationResult } from '../types/domain.types';
|
|
2
|
+
/**
|
|
3
|
+
* SomaValidator — 数据校验器
|
|
4
|
+
*
|
|
5
|
+
* 提供以下能力:
|
|
6
|
+
* - 链式 addRule:为字段添加校验规则
|
|
7
|
+
* - validate:批量校验实体对象,返回结构化的校验结果
|
|
8
|
+
* - 支持的内置校验:required / minLength / maxLength / min / max / pattern
|
|
9
|
+
* - 支持自定义校验函数(custom)
|
|
10
|
+
*
|
|
11
|
+
* 使用示例:
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const validator = new SomaValidator()
|
|
14
|
+
* .addRule('name', { required: true, message: '名称不能为空' })
|
|
15
|
+
* .addRule('value', { min: 0, max: 1000, message: '数值必须在0-1000之间' });
|
|
16
|
+
*
|
|
17
|
+
* const result = validator.validate({ name: '', value: 2000 });
|
|
18
|
+
* // result.valid === false
|
|
19
|
+
* // result.errors === { name: ['名称不能为空'], value: ['数值必须在0-1000之间'] }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare class SomaValidator {
|
|
23
|
+
/** 字段 -> 校验规则列表 的映射 */
|
|
24
|
+
private rules;
|
|
25
|
+
/**
|
|
26
|
+
* 为字段添加一条或多条校验规则
|
|
27
|
+
* 支持链式调用
|
|
28
|
+
*
|
|
29
|
+
* @param field 字段名
|
|
30
|
+
* @param rules 校验规则(可传多个)
|
|
31
|
+
* @returns this(支持链式调用)
|
|
32
|
+
*/
|
|
33
|
+
addRule(field: string, ...rules: ValidationRule[]): this;
|
|
34
|
+
/**
|
|
35
|
+
* 校验实体对象
|
|
36
|
+
* 遍历所有已注册的字段规则,逐条检查
|
|
37
|
+
*
|
|
38
|
+
* @param entity 待校验的对象
|
|
39
|
+
* @returns 校验结果,包含 valid 标志和各字段的错误消息
|
|
40
|
+
*/
|
|
41
|
+
validate(entity: Record<string, any>): ValidationResult;
|
|
42
|
+
/**
|
|
43
|
+
* 移除指定字段的所有校验规则
|
|
44
|
+
*
|
|
45
|
+
* @param field 字段名
|
|
46
|
+
* @returns this(支持链式调用)
|
|
47
|
+
*/
|
|
48
|
+
removeRules(field: string): this;
|
|
49
|
+
/**
|
|
50
|
+
* 清空所有校验规则
|
|
51
|
+
*
|
|
52
|
+
* @returns this(支持链式调用)
|
|
53
|
+
*/
|
|
54
|
+
clearRules(): this;
|
|
55
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface EventEntry {
|
|
2
|
+
methodName: string;
|
|
3
|
+
pipeline: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* @Event(pipelineString) — 标记交互方法
|
|
7
|
+
* 格式: "anchorId.domEvent: ACTION_TYPE | [funcPath] | [target]"
|
|
8
|
+
*/
|
|
9
|
+
export declare function Event(pipelineString: string): MethodDecorator;
|
|
10
|
+
export declare function getEventMetadata(ctor: Function): EventEntry[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface LocaleEntry {
|
|
2
|
+
propertyKey: string;
|
|
3
|
+
localeKey: string;
|
|
4
|
+
}
|
|
5
|
+
/** Bind a locale.yaml key to a domain property (injected after _locale load) */
|
|
6
|
+
export declare function Locale(key: string): PropertyDecorator;
|
|
7
|
+
export declare function applyLocaleMetadata(instance: object): void;
|
|
8
|
+
export declare function getLocaleMetadata(ctor: new (...args: unknown[]) => object): LocaleEntry[];
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface ShowListEntry {
|
|
2
|
+
propertyKey: string;
|
|
3
|
+
somaId: string;
|
|
4
|
+
entityClass: new (...args: unknown[]) => object;
|
|
5
|
+
itemVar?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* @ShowList(somaId, EntityClass, itemVar?) — 列表绑定,声明子实体类型
|
|
9
|
+
* itemVar 默认取属性名首字母(如 sensors → s)
|
|
10
|
+
*/
|
|
11
|
+
export declare function ShowList(somaId: string, entityClass: new (...args: unknown[]) => object, itemVar?: string): PropertyDecorator;
|
|
12
|
+
export declare function getShowListMetadata(ctor: Function): ShowListEntry[];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Locale, applyLocaleMetadata, getLocaleMetadata } from './Locale';
|
|
2
|
+
export { Page, getPageId, hasPageMetadata } from './Page';
|
|
3
|
+
export { Show, getShowMetadata, type ShowEntry } from './Show';
|
|
4
|
+
export { ShowList, getShowListMetadata, type ShowListEntry } from './ShowList';
|
|
5
|
+
export { Event, getEventMetadata, type EventEntry } from './Event';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './SomaApi';
|
|
2
|
+
export * from './SomaLocaleOnlyPageRoot';
|
|
3
|
+
export * from './SomaDict';
|
|
4
|
+
export * from './SomaEntity';
|
|
5
|
+
export * from './SomaHttpClient';
|
|
6
|
+
export * from './SomaPageRootBase';
|
|
7
|
+
export * from './SomaValidator';
|
|
8
|
+
export * from './runAsync';
|
|
9
|
+
export * from './decorators/index';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** 支持 runAsync 的状态宿主(SomaEntity / SomaPageRootBase 均满足) */
|
|
2
|
+
export interface AsyncStateHost {
|
|
3
|
+
loading?: boolean;
|
|
4
|
+
error?: string | null;
|
|
5
|
+
pageLoading?: boolean;
|
|
6
|
+
pageError?: string | null;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* 独立 runAsync 工具 — 自动管理 loading / error 状态
|
|
10
|
+
* SomaEntity 与 SomaPageRootBase 内部均委托此方法
|
|
11
|
+
*/
|
|
12
|
+
export declare function runAsync<R>(host: AsyncStateHost, fn: () => Promise<R>): Promise<R | null>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { UiConfig } from '../types/ui-config.types';
|
|
2
|
+
import type { ParsedEvent } from '../types/event.types';
|
|
3
|
+
import type { PropertyTrigger } from '../types/trigger.types';
|
|
4
|
+
import type { ParsedTimer } from '../types/timer.types';
|
|
5
|
+
import type { StyleConfig } from '../types/style-config.types';
|
|
6
|
+
import { type SomaRouteEntry } from './route-builder';
|
|
7
|
+
export interface SomaPrecompiledPage {
|
|
8
|
+
path: string;
|
|
9
|
+
uiConfig: UiConfig;
|
|
10
|
+
eventConfig: ParsedEvent[];
|
|
11
|
+
triggers: PropertyTrigger[];
|
|
12
|
+
timers: ParsedTimer[];
|
|
13
|
+
styleConfig?: StyleConfig;
|
|
14
|
+
}
|
|
15
|
+
export interface SomaPrecompiledManifest {
|
|
16
|
+
routes: SomaRouteEntry[];
|
|
17
|
+
locale: Record<string, unknown>;
|
|
18
|
+
appConfig: unknown;
|
|
19
|
+
pages: SomaPrecompiledPage[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 全量预编译整个项目的所有声明式配置。
|
|
23
|
+
* 构建产物是一个 JS 模块,运行时 import 即可使用,零解析。
|
|
24
|
+
*/
|
|
25
|
+
export declare function precompileAll(inputs: {
|
|
26
|
+
htmlFiles: string[];
|
|
27
|
+
localeYaml: string;
|
|
28
|
+
appConfigYaml: string;
|
|
29
|
+
pages: Array<{
|
|
30
|
+
path: string;
|
|
31
|
+
uiYaml: string;
|
|
32
|
+
eventYaml: string;
|
|
33
|
+
styleYaml?: string;
|
|
34
|
+
}>;
|
|
35
|
+
}): SomaPrecompiledManifest;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { IContainerAdapter } from '../container/IContainerAdapter';
|
|
2
|
+
import type { SomaScopeResolver } from '../engine/scope-resolver';
|
|
3
|
+
import type { SomaRuntimeManifest } from '../types/manifest.types';
|
|
4
|
+
import type { UiConfig } from '../types/ui-config.types';
|
|
5
|
+
import type { ParsedEvent } from '../types/event.types';
|
|
6
|
+
export interface SomaManifestCompilerInput {
|
|
7
|
+
container: HTMLElement;
|
|
8
|
+
adapter: IContainerAdapter;
|
|
9
|
+
uiConfig: UiConfig;
|
|
10
|
+
eventConfig: ParsedEvent[];
|
|
11
|
+
resolver: SomaScopeResolver;
|
|
12
|
+
}
|
|
13
|
+
export declare class SomaManifestCompiler {
|
|
14
|
+
/** 事件编译缓存:eventConfig 不依赖 DOM,可安全缓存 */
|
|
15
|
+
private eventCache;
|
|
16
|
+
compile(input: SomaManifestCompilerInput): SomaRuntimeManifest;
|
|
17
|
+
private walkShow;
|
|
18
|
+
private compileExtendedValue;
|
|
19
|
+
private parseSomaKey;
|
|
20
|
+
private parseConditionalPath;
|
|
21
|
+
private resolveBindingType;
|
|
22
|
+
/**
|
|
23
|
+
* 判断 dataPath 是否为静态(初始化后不会变化)。
|
|
24
|
+
* _locale.* 和 _config.* 在 mount 时设置一次,不受业务逻辑变更影响。
|
|
25
|
+
*/
|
|
26
|
+
private isStaticPath;
|
|
27
|
+
private isNestedShowMapping;
|
|
28
|
+
private isExtendedShowValue;
|
|
29
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve URL path to html/ui/event base name (without .html).
|
|
3
|
+
* Tries exact path first, then foo/index short form (/items → items/index).
|
|
4
|
+
*/
|
|
5
|
+
export declare function urlPathToCandidates(urlPath: string): string[];
|
|
6
|
+
export declare function isSafePageBase(base: string): boolean;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SomaPrecompiledManifest, SomaPrecompiledPage } from '../compiler/full-manifest-builder';
|
|
2
|
+
/** Load full precompiled manifest from HOST .soma/manifest.json */
|
|
3
|
+
export declare function loadPrecompiledManifest(hostDir: string): SomaPrecompiledManifest | null;
|
|
4
|
+
/** Find precompiled page by route (supports /items → items/index short path) */
|
|
5
|
+
export declare function findPrecompiledPage(manifest: SomaPrecompiledManifest, urlPath: string): SomaPrecompiledPage | null;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface SomaRollupPluginOptions {
|
|
2
|
+
uiSuffix?: string;
|
|
3
|
+
eventSuffix?: string;
|
|
4
|
+
styleSuffix?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function somaRollupPlugin(options?: SomaRollupPluginOptions): {
|
|
7
|
+
name: string;
|
|
8
|
+
transform(code: string, id: string): {
|
|
9
|
+
code: string;
|
|
10
|
+
map: {
|
|
11
|
+
mappings: string;
|
|
12
|
+
};
|
|
13
|
+
} | null;
|
|
14
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface SomaRouteEntry {
|
|
2
|
+
path: string;
|
|
3
|
+
htmlFile: string;
|
|
4
|
+
uiFile: string;
|
|
5
|
+
eventFile: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* 从 HTML 文件列表生成路由表。
|
|
9
|
+
* shared/ 和 system/ 目录下的文件被排除(非页面文件)。
|
|
10
|
+
*/
|
|
11
|
+
export declare function buildRouteTable(htmlFiles: string[]): SomaRouteEntry[];
|
|
12
|
+
export declare function precompileRouteTable(htmlFiles: string[]): string;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { UiConfig } from '../types/ui-config.types';
|
|
2
|
+
import type { ParsedEvent } from '../types/event.types';
|
|
3
|
+
import type { PropertyTrigger } from '../types/trigger.types';
|
|
4
|
+
import type { ParsedTimer } from '../types/timer.types';
|
|
5
|
+
/** _event.yaml 预编译产物 */
|
|
6
|
+
export interface CompiledEventConfig {
|
|
7
|
+
events: ParsedEvent[];
|
|
8
|
+
triggers: PropertyTrigger[];
|
|
9
|
+
timers: ParsedTimer[];
|
|
10
|
+
}
|
|
11
|
+
import type { StyleConfig } from '../types/style-config.types';
|
|
12
|
+
/**
|
|
13
|
+
* 预编译 UI YAML → JSON 字符串
|
|
14
|
+
*/
|
|
15
|
+
export declare function precompileUiYaml(yamlStr: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* 预编译 Event YAML → JSON 字符串(含 events + triggers)
|
|
18
|
+
*/
|
|
19
|
+
export declare function precompileEventYaml(yamlStr: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* 预编译 Style YAML → JSON 字符串
|
|
22
|
+
*/
|
|
23
|
+
export declare function precompileStyleYaml(yamlStr: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* 预编译 UI YAML → UiConfig 对象
|
|
26
|
+
*/
|
|
27
|
+
export declare function compileUiConfig(yamlStr: string): UiConfig;
|
|
28
|
+
/**
|
|
29
|
+
* 预编译 Event YAML → CompiledEventConfig 对象
|
|
30
|
+
*/
|
|
31
|
+
export declare function compileEventConfig(yamlStr: string): CompiledEventConfig;
|
|
32
|
+
export declare function compileEventConfigFromRaw(raw: unknown): CompiledEventConfig;
|
|
33
|
+
/**
|
|
34
|
+
* 预编译 Style YAML → StyleConfig 对象
|
|
35
|
+
*/
|
|
36
|
+
export declare function compileStyleConfig(yamlStr: string): StyleConfig | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* 预编译任意 YAML → JSON 字符串(locale、app.config 等纯数据配置)
|
|
39
|
+
*/
|
|
40
|
+
export declare function precompileYaml(yamlStr: string): string;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
export interface SomaPluginOptions {
|
|
3
|
+
/** UI 配置文件后缀,默认 _ui.yaml */
|
|
4
|
+
uiSuffix?: string;
|
|
5
|
+
/** 事件配置文件后缀,默认 _event.yaml */
|
|
6
|
+
eventSuffix?: string;
|
|
7
|
+
/** 样式配置文件后缀,默认 _style.yaml */
|
|
8
|
+
styleSuffix?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* SOMA Vite 预编译插件
|
|
12
|
+
*
|
|
13
|
+
* 在 transform 阶段拦截所有 YAML 配置文件,将 YAML → JS 对象的转换
|
|
14
|
+
* 移到构建时完成。运行时直接 import 得到已解析的对象。
|
|
15
|
+
*
|
|
16
|
+
* 覆盖范围:
|
|
17
|
+
* - `_ui.yaml` → UiConfig 对象(parseUiConfig 预编译)
|
|
18
|
+
* - `_event.yaml` → ParsedEvent[] 数组(parseEventConfig 预编译)
|
|
19
|
+
* - `_style.yaml` → StyleConfig 对象(parseStyleConfig 预编译)
|
|
20
|
+
* - `locale.yaml` → Record<string, unknown>
|
|
21
|
+
* - `*.config.yaml` → 任意配置对象
|
|
22
|
+
* - 其他 `.yaml` → 通用 YAML → JS 对象
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* // vite.config.ts
|
|
27
|
+
* import { somaPlugin } from './core/compiler/vite-plugin-soma';
|
|
28
|
+
*
|
|
29
|
+
* export default defineConfig({
|
|
30
|
+
* plugins: [somaPlugin()],
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function somaPlugin(options?: SomaPluginOptions): Plugin;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** 容器适配层协议 — Web / Test / RN / 小程序统一接口 */
|
|
2
|
+
export interface SomaAnchorStats {
|
|
3
|
+
anchors: Set<string>;
|
|
4
|
+
duplicates: Map<string, number>;
|
|
5
|
+
}
|
|
6
|
+
export interface IContainerAdapter {
|
|
7
|
+
mount(container: HTMLElement, html: string, includes?: Record<string, string>): void;
|
|
8
|
+
collectAnchors(container: HTMLElement): SomaAnchorStats;
|
|
9
|
+
findAnchor(root: ParentNode, somaId: string): HTMLElement | null;
|
|
10
|
+
findClosestAnchor(target: EventTarget | null): HTMLElement | null;
|
|
11
|
+
getAnchorId(element: HTMLElement): string | null;
|
|
12
|
+
readRole(element: HTMLElement): string | null;
|
|
13
|
+
getTemplate(element: HTMLElement): HTMLTemplateElement | null;
|
|
14
|
+
cloneTemplate(element: HTMLElement): DocumentFragment | null;
|
|
15
|
+
clearRenderedChildren(element: HTMLElement): void;
|
|
16
|
+
appendFragment(element: HTMLElement, fragment: DocumentFragment): void;
|
|
17
|
+
setText(element: HTMLElement, value: string): void;
|
|
18
|
+
setAttribute(element: HTMLElement, attrName: string, value: string): void;
|
|
19
|
+
setHtml(element: HTMLElement, value: string): void;
|
|
20
|
+
setVisibility(element: HTMLElement, visible: boolean): void;
|
|
21
|
+
isVisible(element: HTMLElement): boolean;
|
|
22
|
+
toggleClasses(element: HTMLElement, classes: string[], enabled: boolean): void;
|
|
23
|
+
setValue(element: HTMLElement, value: string): void;
|
|
24
|
+
getValue(element: HTMLElement): string;
|
|
25
|
+
listen(element: HTMLElement, eventType: string, listener: (event: Event) => void, signal: AbortSignal): void;
|
|
26
|
+
confirm(message: string): boolean;
|
|
27
|
+
navigate(url: string): void;
|
|
28
|
+
now(): number;
|
|
29
|
+
setNavigateHandler?(handler: (url: string) => void): void;
|
|
30
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 小程序容器适配器 — 映射 WXML 风格节点树(示范实现)
|
|
3
|
+
*/
|
|
4
|
+
import type { IContainerAdapter, SomaAnchorStats } from './IContainerAdapter';
|
|
5
|
+
export interface MpElementNode {
|
|
6
|
+
somaId: string | null;
|
|
7
|
+
tag: string;
|
|
8
|
+
attrs: Record<string, string>;
|
|
9
|
+
children: MpElementNode[];
|
|
10
|
+
text?: string;
|
|
11
|
+
}
|
|
12
|
+
/** 模拟 wx API 表面 */
|
|
13
|
+
export interface MiniProgramHost {
|
|
14
|
+
setData?(data: Record<string, unknown>): void;
|
|
15
|
+
navigateTo?(opts: {
|
|
16
|
+
url: string;
|
|
17
|
+
}): void;
|
|
18
|
+
}
|
|
19
|
+
export declare class MiniProgramContainerAdapter implements IContainerAdapter {
|
|
20
|
+
readonly platform: "miniprogram";
|
|
21
|
+
private tree;
|
|
22
|
+
private domBridge;
|
|
23
|
+
private host;
|
|
24
|
+
private navigateHandler;
|
|
25
|
+
constructor(host?: MiniProgramHost);
|
|
26
|
+
setNavigateHandler(handler: (url: string) => void): void;
|
|
27
|
+
mount(container: HTMLElement, html: string, includes?: Record<string, string>): void;
|
|
28
|
+
collectAnchors(container: HTMLElement): SomaAnchorStats;
|
|
29
|
+
findAnchor(root: ParentNode, somaId: string): HTMLElement | null;
|
|
30
|
+
findClosestAnchor(target: EventTarget | null): HTMLElement | null;
|
|
31
|
+
getAnchorId(element: HTMLElement): string | null;
|
|
32
|
+
readRole(element: HTMLElement): string | null;
|
|
33
|
+
getTemplate(element: HTMLElement): HTMLTemplateElement | null;
|
|
34
|
+
cloneTemplate(element: HTMLElement): DocumentFragment | null;
|
|
35
|
+
clearRenderedChildren(element: HTMLElement): void;
|
|
36
|
+
appendFragment(element: HTMLElement, fragment: DocumentFragment): void;
|
|
37
|
+
setText(element: HTMLElement, value: string): void;
|
|
38
|
+
setAttribute(element: HTMLElement, attrName: string, value: string): void;
|
|
39
|
+
setHtml(element: HTMLElement, value: string): void;
|
|
40
|
+
setVisibility(element: HTMLElement, visible: boolean): void;
|
|
41
|
+
isVisible(element: HTMLElement): boolean;
|
|
42
|
+
toggleClasses(element: HTMLElement, classes: string[], enabled: boolean): void;
|
|
43
|
+
setValue(element: HTMLElement, value: string): void;
|
|
44
|
+
getValue(element: HTMLElement): string;
|
|
45
|
+
listen(element: HTMLElement, eventType: string, listener: (event: Event) => void, signal: AbortSignal): void;
|
|
46
|
+
confirm(_message: string): boolean;
|
|
47
|
+
navigate(url: string): void;
|
|
48
|
+
now(): number;
|
|
49
|
+
getMpTree(): MpElementNode;
|
|
50
|
+
private findMpNode;
|
|
51
|
+
private htmlToMpTree;
|
|
52
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Native 容器适配器 — 将 SOMA 渲染指令映射为 RN 样式树(示范实现)
|
|
3
|
+
* 生产环境需对接 react-native 组件;此处用内存节点 + jsdom HTMLElement 桥接测试。
|
|
4
|
+
*/
|
|
5
|
+
import type { IContainerAdapter, SomaAnchorStats } from './IContainerAdapter';
|
|
6
|
+
export interface RNElementNode {
|
|
7
|
+
somaId: string | null;
|
|
8
|
+
tag: string;
|
|
9
|
+
props: Record<string, string>;
|
|
10
|
+
children: RNElementNode[];
|
|
11
|
+
text?: string;
|
|
12
|
+
templateRole?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class ReactNativeContainerAdapter implements IContainerAdapter {
|
|
15
|
+
readonly platform: "react-native";
|
|
16
|
+
private root;
|
|
17
|
+
private navigateHandler;
|
|
18
|
+
private listeners;
|
|
19
|
+
/** 桥接用 DOM 容器(测试 / 混合渲染) */
|
|
20
|
+
private domBridge;
|
|
21
|
+
setNavigateHandler(handler: (url: string) => void): void;
|
|
22
|
+
mount(container: HTMLElement, html: string, includes?: Record<string, string>): void;
|
|
23
|
+
collectAnchors(container: HTMLElement): SomaAnchorStats;
|
|
24
|
+
findAnchor(root: ParentNode, somaId: string): HTMLElement | null;
|
|
25
|
+
findClosestAnchor(target: EventTarget | null): HTMLElement | null;
|
|
26
|
+
getAnchorId(element: HTMLElement): string | null;
|
|
27
|
+
readRole(element: HTMLElement): string | null;
|
|
28
|
+
getTemplate(element: HTMLElement): HTMLTemplateElement | null;
|
|
29
|
+
cloneTemplate(element: HTMLElement): DocumentFragment | null;
|
|
30
|
+
clearRenderedChildren(element: HTMLElement): void;
|
|
31
|
+
appendFragment(element: HTMLElement, fragment: DocumentFragment): void;
|
|
32
|
+
setText(element: HTMLElement, value: string): void;
|
|
33
|
+
setAttribute(element: HTMLElement, attrName: string, value: string): void;
|
|
34
|
+
setHtml(element: HTMLElement, value: string): void;
|
|
35
|
+
setVisibility(element: HTMLElement, visible: boolean): void;
|
|
36
|
+
isVisible(element: HTMLElement): boolean;
|
|
37
|
+
toggleClasses(element: HTMLElement, classes: string[], enabled: boolean): void;
|
|
38
|
+
setValue(element: HTMLElement, value: string): void;
|
|
39
|
+
getValue(element: HTMLElement): string;
|
|
40
|
+
listen(element: HTMLElement, eventType: string, listener: (event: Event) => void, signal: AbortSignal): void;
|
|
41
|
+
confirm(_message: string): boolean;
|
|
42
|
+
navigate(url: string): void;
|
|
43
|
+
now(): number;
|
|
44
|
+
getStyleTree(): RNElementNode;
|
|
45
|
+
private findInTree;
|
|
46
|
+
private parseHtmlToTree;
|
|
47
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { IContainerAdapter, SomaAnchorStats } from './IContainerAdapter';
|
|
2
|
+
export type { SomaAnchorStats } from './IContainerAdapter';
|
|
3
|
+
export declare class SomaContainerAdapter implements IContainerAdapter {
|
|
4
|
+
private navigateHandler;
|
|
5
|
+
/** 注入自定义导航处理器(如 SomaRouter + Next.js 路由) */
|
|
6
|
+
setNavigateHandler(handler: (url: string) => void): void;
|
|
7
|
+
mount(container: HTMLElement, html: string, includes?: Record<string, string>): void;
|
|
8
|
+
collectAnchors(container: HTMLElement): SomaAnchorStats;
|
|
9
|
+
findAnchor(root: ParentNode, somaId: string): HTMLElement | null;
|
|
10
|
+
findClosestAnchor(target: EventTarget | null): HTMLElement | null;
|
|
11
|
+
getAnchorId(element: HTMLElement): string | null;
|
|
12
|
+
readRole(element: HTMLElement): string | null;
|
|
13
|
+
getTemplate(element: HTMLElement): HTMLTemplateElement | null;
|
|
14
|
+
cloneTemplate(element: HTMLElement): DocumentFragment | null;
|
|
15
|
+
clearRenderedChildren(element: HTMLElement): void;
|
|
16
|
+
appendFragment(element: HTMLElement, fragment: DocumentFragment): void;
|
|
17
|
+
setText(element: HTMLElement, value: string): void;
|
|
18
|
+
setAttribute(element: HTMLElement, attrName: string, value: string): void;
|
|
19
|
+
setHtml(element: HTMLElement, value: string): void;
|
|
20
|
+
setVisibility(element: HTMLElement, visible: boolean): void;
|
|
21
|
+
isVisible(element: HTMLElement): boolean;
|
|
22
|
+
toggleClasses(element: HTMLElement, classes: string[], enabled: boolean): void;
|
|
23
|
+
setValue(element: HTMLElement, value: string): void;
|
|
24
|
+
getValue(element: HTMLElement): string;
|
|
25
|
+
listen(element: HTMLElement, eventType: string, listener: (event: Event) => void, signal: AbortSignal): void;
|
|
26
|
+
confirm(message: string): boolean;
|
|
27
|
+
navigate(url: string): void;
|
|
28
|
+
now(): number;
|
|
29
|
+
private resolveIncludes;
|
|
30
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export interface SomaMutationRecord {
|
|
2
|
+
path: string;
|
|
3
|
+
valuePreview: string;
|
|
4
|
+
timestamp: number;
|
|
5
|
+
}
|
|
6
|
+
export interface SomaRenderRecord {
|
|
7
|
+
phase: 'full-render' | 'patch' | 'commit';
|
|
8
|
+
path?: string;
|
|
9
|
+
bindingCount: number;
|
|
10
|
+
affectedCount: number;
|
|
11
|
+
durationMs: number;
|
|
12
|
+
timestamp: number;
|
|
13
|
+
}
|
|
14
|
+
export interface SomaEventRecord {
|
|
15
|
+
somaId: string;
|
|
16
|
+
domEvent: string;
|
|
17
|
+
eventType: string;
|
|
18
|
+
funcPath?: string | null;
|
|
19
|
+
status: 'success' | 'blocked' | 'error';
|
|
20
|
+
durationMs: number;
|
|
21
|
+
message?: string;
|
|
22
|
+
timestamp: number;
|
|
23
|
+
}
|
|
24
|
+
export interface SomaValidationRecord {
|
|
25
|
+
level: 'warning' | 'error';
|
|
26
|
+
message: string;
|
|
27
|
+
timestamp: number;
|
|
28
|
+
}
|
|
29
|
+
export interface SomaSchedulerRecord {
|
|
30
|
+
priority: 'immediate' | 'visible' | 'background';
|
|
31
|
+
label?: string;
|
|
32
|
+
durationMs: number;
|
|
33
|
+
status?: 'success' | 'error';
|
|
34
|
+
timestamp: number;
|
|
35
|
+
}
|
|
36
|
+
export interface SomaDiagnosticsSnapshot {
|
|
37
|
+
mutations: SomaMutationRecord[];
|
|
38
|
+
renders: SomaRenderRecord[];
|
|
39
|
+
events: SomaEventRecord[];
|
|
40
|
+
validations: SomaValidationRecord[];
|
|
41
|
+
scheduler: SomaSchedulerRecord[];
|
|
42
|
+
counters: {
|
|
43
|
+
mutations: number;
|
|
44
|
+
renders: number;
|
|
45
|
+
events: number;
|
|
46
|
+
validations: number;
|
|
47
|
+
scheduler: number;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export declare class SomaDiagnostics {
|
|
51
|
+
private mutations;
|
|
52
|
+
private renders;
|
|
53
|
+
private events;
|
|
54
|
+
private validations;
|
|
55
|
+
private scheduler;
|
|
56
|
+
constructor(maxEntries?: number);
|
|
57
|
+
recordMutation(path: string, value: any): void;
|
|
58
|
+
recordRender(record: Omit<SomaRenderRecord, 'timestamp'>): void;
|
|
59
|
+
recordEvent(record: Omit<SomaEventRecord, 'timestamp'>): void;
|
|
60
|
+
recordValidation(level: SomaValidationRecord['level'], message: string): void;
|
|
61
|
+
recordScheduler(record: Omit<SomaSchedulerRecord, 'timestamp'>): void;
|
|
62
|
+
snapshot(): SomaDiagnosticsSnapshot;
|
|
63
|
+
private preview;
|
|
64
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** CSS / 编译 Telemetry 度量 — 聚合诊断与编译指标 */
|
|
2
|
+
export interface TelemetryMetric {
|
|
3
|
+
name: string;
|
|
4
|
+
value: number;
|
|
5
|
+
unit: string;
|
|
6
|
+
timestamp: number;
|
|
7
|
+
}
|
|
8
|
+
export interface TelemetryExportOptions {
|
|
9
|
+
/** 导出为 OpenTelemetry 兼容 JSON 结构 */
|
|
10
|
+
format?: 'json' | 'otlp';
|
|
11
|
+
serviceName?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare class SomaTelemetry {
|
|
14
|
+
private metrics;
|
|
15
|
+
private readonly maxEntries;
|
|
16
|
+
constructor(maxEntries?: number);
|
|
17
|
+
record(name: string, value: number, unit?: string): void;
|
|
18
|
+
getMetrics(name?: string): TelemetryMetric[];
|
|
19
|
+
aggregate(name: string): {
|
|
20
|
+
count: number;
|
|
21
|
+
avg: number;
|
|
22
|
+
max: number;
|
|
23
|
+
min: number;
|
|
24
|
+
};
|
|
25
|
+
snapshot(): Record<string, ReturnType<SomaTelemetry['aggregate']>>;
|
|
26
|
+
/** 导出原始指标 JSON */
|
|
27
|
+
exportJson(): string;
|
|
28
|
+
/** 导出 OpenTelemetry 兼容 metrics 结构(简化版) */
|
|
29
|
+
exportOpenTelemetry(options?: TelemetryExportOptions): string;
|
|
30
|
+
/** POST 到自定义 endpoint(浏览器 / Node fetch) */
|
|
31
|
+
report(endpoint: string, format?: 'json' | 'otlp'): Promise<void>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SomaTelemetry } from './SomaTelemetry';
|
|
2
|
+
export declare function setActiveTelemetry(telemetry: SomaTelemetry | null): void;
|
|
3
|
+
export declare function getActiveTelemetry(): SomaTelemetry | null;
|
|
4
|
+
export declare function recordMetric(name: string, value: number, unit?: string): void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ICache } from '../infra/cache/ICache';
|
|
2
|
+
import type { SomaPageAssets, ParsedRuntimeAssets } from './soma-bootstrap';
|
|
3
|
+
/**
|
|
4
|
+
* 资产解析器:将 SomaPageAssets 解析为引擎可消费的 ParsedRuntimeAssets。
|
|
5
|
+
*
|
|
6
|
+
* 支持两种模式:
|
|
7
|
+
* - 预编译模式:assets 中已有 uiConfig/eventConfig,直接使用,零开销
|
|
8
|
+
* - 字符串模式:assets 中是 yaml 字符串,运行时解析,带 LRU 缓存
|
|
9
|
+
*/
|
|
10
|
+
export declare class SomaAssetResolver {
|
|
11
|
+
private cache;
|
|
12
|
+
constructor(cache?: ICache<ParsedRuntimeAssets>);
|
|
13
|
+
resolve(assets: SomaPageAssets): ParsedRuntimeAssets;
|
|
14
|
+
private parseLocale;
|
|
15
|
+
private parseAppConfig;
|
|
16
|
+
private parseStyleConfig;
|
|
17
|
+
}
|