soma-core 1.3.1 → 1.3.3
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 +42 -0
- package/app/SomaPageClient.tsx +39 -2
- 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/core/build/compiler/full-manifest-builder.ts +6 -1
- package/core/build/compiler/rollup-plugin-soma.ts +6 -0
- package/core/build/compiler/soma-manifest-webpack-plugin.js +4 -0
- package/core/build/compiler/soma-precompile.js +3507 -2387
- package/core/build/compiler/soma-precompile.ts +31 -2
- package/core/build/compiler/soma-rspack-yaml-loader.js +3 -0
- package/core/build/compiler/soma-webpack-loader.js +7 -1
- package/core/build/compiler/vite-plugin-soma.ts +11 -1
- package/core/build/component/package-loader.ts +135 -0
- package/core/build/eject/apply-eject.ts +133 -0
- package/core/build/eject/plan-eject.ts +139 -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 +262 -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 +271 -0
- package/core/client/component/component-registry.ts +71 -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 +235 -16
- 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 +3 -3
- package/core/client/engine/render-engine.ts +43 -4
- package/core/client/engine/runtime-builder.ts +23 -0
- package/core/client/engine/soma-bootstrap.ts +389 -5
- package/core/client/engine/style-binder.ts +47 -1
- package/core/client/host-bridge/empty-host/data/README.md +17 -0
- package/core/client/infra/http/SomaHttpService.ts +5 -0
- 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/pipes/pipe-registry.ts +249 -0
- package/core/client/quality/SomaQualityRegistry.ts +3 -0
- package/core/client/registry/declaration-renderer.ts +159 -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/scheduler/SomaScheduler.ts +29 -1
- 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/theme-engine.ts +936 -0
- package/core/client/typography/typography-base.ts +34 -0
- package/core/client/validation/contract-validator.ts +48 -5
- package/core/index.ts +190 -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 +10 -0
- package/core/server/index.ts +30 -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 +129 -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 +903 -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 +86 -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 +71 -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 +77 -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 +110 -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 +5388 -888
- package/dist/types/build/compiler/full-manifest-builder.d.ts +4 -0
- package/dist/types/build/compiler/rollup-plugin-soma.d.ts +1 -0
- package/dist/types/build/compiler/soma-precompile.d.ts +9 -0
- package/dist/types/build/compiler/vite-plugin-soma.d.ts +3 -0
- package/dist/types/build/component/package-loader.d.ts +9 -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/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 +90 -0
- package/dist/types/client/component/component-registry.d.ts +12 -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 +49 -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 +26 -1
- package/dist/types/client/engine/runtime-builder.d.ts +7 -0
- package/dist/types/client/engine/soma-bootstrap.d.ts +122 -0
- package/dist/types/client/infra/http/SomaHttpService.d.ts +2 -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/pipes/pipe-registry.d.ts +38 -0
- package/dist/types/client/registry/declaration-renderer.d.ts +51 -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/scheduler/SomaScheduler.d.ts +8 -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/theme-engine.d.ts +49 -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 +36 -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 +5 -0
- package/dist/types/server/index.d.ts +4 -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 +10 -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 +68 -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/global.d.ts +12 -0
- package/next.config.js +76 -1
- package/package.json +32 -11
- package/proxy.ts +62 -0
- 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/middleware.ts +0 -33
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
// 职责:从解析后的资产 + DOM 容器组装完整的运行时引擎组
|
|
3
3
|
|
|
4
4
|
import { SomaManifestCompiler } from '../compiler/manifest-compiler';
|
|
5
|
+
import { applyCompiledAdaptive } from '../compiler/adaptive-compile';
|
|
6
|
+
import type { SomaAdaptiveVocabulary } from '../../shared/types/adaptive.types';
|
|
5
7
|
import type { IContainerAdapter } from '../container/IContainerAdapter';
|
|
6
8
|
import type { SomaDiagnostics } from '../diagnostics/SomaDiagnostics';
|
|
9
|
+
import { markBootPhase } from '../diagnostics/boot-timings';
|
|
7
10
|
import type { SomaMiddlewareChain } from '../middleware/SomaMiddlewareChain';
|
|
8
11
|
import type { SomaScheduler } from '../scheduler/SomaScheduler';
|
|
9
12
|
import type { ParsedEvent } from '../../shared/types/event.types';
|
|
@@ -37,6 +40,10 @@ export interface RuntimeBuildInput {
|
|
|
37
40
|
diagnostics: SomaDiagnostics;
|
|
38
41
|
renderMiddleware?: SomaMiddlewareChain<SomaRenderMiddlewareContext>;
|
|
39
42
|
eventMiddleware?: SomaMiddlewareChain<SomaEventMiddlewareContext>;
|
|
43
|
+
/** 格式化管道注册表(缺省内置管道集) */
|
|
44
|
+
pipeRegistry?: import('../pipes/pipe-registry').SomaPipeRegistry;
|
|
45
|
+
/** 阶梯词汇表(F-09),经宿主 bootstrap 注入;无 adaptive 声明的页面用不到 */
|
|
46
|
+
adaptiveVocabulary?: SomaAdaptiveVocabulary;
|
|
40
47
|
}
|
|
41
48
|
|
|
42
49
|
export interface SomaRuntime {
|
|
@@ -48,6 +55,8 @@ export interface SomaRuntime {
|
|
|
48
55
|
triggerEngine: SomaTriggerEngine;
|
|
49
56
|
timerEngine: SomaTimerEngine;
|
|
50
57
|
resolver: SomaScopeResolver;
|
|
58
|
+
/** 页面运行时清单(组件管理器标记 emit 路由用) */
|
|
59
|
+
manifest: import('../../shared/types/manifest.types').SomaRuntimeManifest;
|
|
51
60
|
}
|
|
52
61
|
|
|
53
62
|
/**
|
|
@@ -75,8 +84,17 @@ export class SomaRuntimeBuilder {
|
|
|
75
84
|
uiConfig: input.uiConfig,
|
|
76
85
|
eventConfig: input.eventConfig,
|
|
77
86
|
resolver,
|
|
87
|
+
pipes: input.pipeRegistry,
|
|
88
|
+
adaptiveVocabulary: input.adaptiveVocabulary,
|
|
78
89
|
});
|
|
79
90
|
|
|
91
|
+
// 阶梯落地:写宿主根画像属性 + 挂断点型作用域类。
|
|
92
|
+
// 放在 render 之前,是为了让首帧就带着正确的作用域类——
|
|
93
|
+
// 渲染后再补类会先闪一帧默认档(首帧协议要求可降解而不是可见跳变)。
|
|
94
|
+
if (manifest.adaptive) {
|
|
95
|
+
applyCompiledAdaptive(manifest.adaptive, input.container, input.adapter);
|
|
96
|
+
}
|
|
97
|
+
|
|
80
98
|
const propertyWatcher = new SomaPropertyWatcher();
|
|
81
99
|
propertyWatcher.setRoot(input.proxiedInstance);
|
|
82
100
|
|
|
@@ -90,9 +108,13 @@ export class SomaRuntimeBuilder {
|
|
|
90
108
|
diagnostics: input.diagnostics,
|
|
91
109
|
middleware: input.renderMiddleware,
|
|
92
110
|
propertyWatcher,
|
|
111
|
+
pipeRegistry: input.pipeRegistry,
|
|
93
112
|
});
|
|
94
113
|
|
|
114
|
+
// 首屏三段打点:编译段止于此(作用域解析 + 契约校验 + manifest 编译),渲染段自此开始
|
|
115
|
+
markBootPhase('compiled');
|
|
95
116
|
renderEngine.render();
|
|
117
|
+
markBootPhase('rendered');
|
|
96
118
|
|
|
97
119
|
const eventEngine = new SomaEventEngine({
|
|
98
120
|
manifest,
|
|
@@ -153,6 +175,7 @@ export class SomaRuntimeBuilder {
|
|
|
153
175
|
triggerEngine,
|
|
154
176
|
timerEngine,
|
|
155
177
|
resolver,
|
|
178
|
+
manifest,
|
|
156
179
|
};
|
|
157
180
|
}
|
|
158
181
|
|
|
@@ -6,6 +6,7 @@ import type { IContainerAdapter } from '../container/IContainerAdapter';
|
|
|
6
6
|
import { SomaDiagnostics, type SomaDiagnosticsSnapshot } from '../diagnostics/SomaDiagnostics';
|
|
7
7
|
import { SomaTelemetry } from '../diagnostics/SomaTelemetry';
|
|
8
8
|
import { setActiveTelemetry, recordMetric } from '../diagnostics/telemetry-context';
|
|
9
|
+
import { markBootPhase, maybeStartBootTimings } from '../diagnostics/boot-timings';
|
|
9
10
|
import { SomaMiddlewareChain } from '../middleware/SomaMiddlewareChain';
|
|
10
11
|
import { SomaScheduler } from '../scheduler/SomaScheduler';
|
|
11
12
|
import type { ParsedEvent } from '../../shared/types/event.types';
|
|
@@ -13,6 +14,7 @@ import type { PropertyTrigger } from '../../shared/types/trigger.types';
|
|
|
13
14
|
import type { ParsedTimer } from '../../shared/types/timer.types';
|
|
14
15
|
import type { StyleConfig } from '../../shared/types/style-config.types';
|
|
15
16
|
import type { UiConfig } from '../../shared/types/ui-config.types';
|
|
17
|
+
import type { SomaAdaptiveVocabulary } from '../../shared/types/adaptive.types';
|
|
16
18
|
import type { SomaPageRoot } from '../../shared/types/domain.types';
|
|
17
19
|
import { SomaSnapshotStore } from '../runtime/SomaSnapshotStore';
|
|
18
20
|
import { SomaAssetResolver } from './asset-resolver';
|
|
@@ -29,8 +31,22 @@ import type { SomaOnChangeEngine } from './on-change-engine';
|
|
|
29
31
|
import type { SomaTriggerEngine } from './trigger-engine';
|
|
30
32
|
import type { SomaTimerEngine } from './timer-engine';
|
|
31
33
|
import { createDefaultRuntimeServices } from '../runtime/SomaRuntimeServices';
|
|
32
|
-
import { getBrowserUrlPath } from '../infra/router/router-path';
|
|
34
|
+
import { getBrowserUrlPath, readQueryParam } from '../infra/router/router-path';
|
|
35
|
+
import { parseDataYaml } from '../parser/data-config-parser';
|
|
36
|
+
import { SomaDataObjectResolver } from '../data/data-object-resolver';
|
|
37
|
+
import type { SomaDataConfig, SomaDataDicts } from '../../shared/types/data-config.types';
|
|
33
38
|
import type { WatchCallback, WatcherOptions } from '../../shared/types/watcher.types';
|
|
39
|
+
import type { SomaComponentDefinition } from '../component/component-definition.types';
|
|
40
|
+
import { SomaComponentRegistry } from '../component/component-registry';
|
|
41
|
+
import { SomaComponentManager } from '../component/component-manager';
|
|
42
|
+
import { SomaPipeRegistry, type SomaPipeFn } from '../pipes/pipe-registry';
|
|
43
|
+
import { applyTheme, type SomaThemeInput } from '../theme/theme-engine';
|
|
44
|
+
import {
|
|
45
|
+
installSomaErrorReporter,
|
|
46
|
+
type SomaErrorEvent,
|
|
47
|
+
type SomaErrorReporterHandle,
|
|
48
|
+
type SomaPageIdentity,
|
|
49
|
+
} from '../observability/error-reporter';
|
|
34
50
|
|
|
35
51
|
// ─── 类型定义 ──────────────────────────────────────────
|
|
36
52
|
|
|
@@ -45,6 +61,13 @@ export interface SomaPageAssets {
|
|
|
45
61
|
styleYaml?: string;
|
|
46
62
|
localeYaml?: string;
|
|
47
63
|
appConfigYaml?: string;
|
|
64
|
+
/**
|
|
65
|
+
* 数据对象层声明(*_data.yaml,五件套可选件)。
|
|
66
|
+
* 提供后 bootstrap 在首渲前解析声明、异步取数并注入 page.data,
|
|
67
|
+
* 完成后触发一次全量渲染;解析/取数失败不阻塞页面(data 保持空对象 + console.error)。
|
|
68
|
+
* 不提供时加载路径零变化。
|
|
69
|
+
*/
|
|
70
|
+
dataYaml?: string;
|
|
48
71
|
|
|
49
72
|
// ── 预编译模式(构建阶段已解析,运行时零开销) ──
|
|
50
73
|
uiConfig?: UiConfig;
|
|
@@ -54,9 +77,39 @@ export interface SomaPageAssets {
|
|
|
54
77
|
styleConfig?: StyleConfig;
|
|
55
78
|
locale?: Record<string, unknown>;
|
|
56
79
|
appConfig?: unknown;
|
|
80
|
+
/** 数据对象层声明的预编译形态(构建阶段已解析校验,优先于 dataYaml) */
|
|
81
|
+
dataConfig?: SomaDataConfig;
|
|
57
82
|
|
|
58
83
|
/** Full router path including query string (e.g. /items/detail?id=1) */
|
|
59
84
|
routerPath?: string;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 组件运行时定义(组件体系模块 7,可选)。
|
|
88
|
+
* 键为契约名;页面 HTML 中 data-soma-component 引用的组件必须在此提供。
|
|
89
|
+
* 不提供时组件能力整体旁路,页面走既有路径。
|
|
90
|
+
*/
|
|
91
|
+
components?: Record<string, SomaComponentDefinition>;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 错误采集接线声明(可观测性,默认关闭)。
|
|
96
|
+
*
|
|
97
|
+
* 为什么放在 bootstrap 而不是让 Host 自己 install:采集器本身只会记"出了什么错",
|
|
98
|
+
* 记不住"这是哪个页面的哪个版本"——而页面身份只有挂载时点知道。挂在生命周期
|
|
99
|
+
* 编排器上,身份随挂载自动盖戳、随卸载自动摘监听,Host 不需要维护任何状态。
|
|
100
|
+
*/
|
|
101
|
+
export interface SomaBootstrapErrorReporting {
|
|
102
|
+
/** 页面身份:错误归因到「页面名@版本」的唯一依据(声明态页面必须带 version) */
|
|
103
|
+
page: SomaPageIdentity;
|
|
104
|
+
/**
|
|
105
|
+
* 上报通道。缺省走 console.error 单行 JSON——宿主一行开启就先有数据,
|
|
106
|
+
* 等接了真通道(sendBeacon / 第三方 SDK)再替换,不必为"先看看"写胶水。
|
|
107
|
+
*/
|
|
108
|
+
report?: (event: SomaErrorEvent) => void;
|
|
109
|
+
/** 同签名错误去重窗口(毫秒),透传采集器 */
|
|
110
|
+
dedupeWindowMs?: number;
|
|
111
|
+
/** 单页上报条数上限,透传采集器 */
|
|
112
|
+
maxEvents?: number;
|
|
60
113
|
}
|
|
61
114
|
|
|
62
115
|
export interface SomaBootstrapOptions {
|
|
@@ -65,6 +118,25 @@ export interface SomaBootstrapOptions {
|
|
|
65
118
|
diagnostics?: SomaDiagnostics;
|
|
66
119
|
telemetry?: SomaTelemetry;
|
|
67
120
|
assetResolver?: SomaAssetResolver;
|
|
121
|
+
/**
|
|
122
|
+
* Host 级组件注册(组件体系模块 7)。
|
|
123
|
+
* 经 `@soma-host/bootstrap/soma-bootstrap.ts` 的 configureSomaBootstrap 注入,
|
|
124
|
+
* 对该 Host 的所有页面生效;页面资产 components 同名时覆盖 Host 级定义。
|
|
125
|
+
*/
|
|
126
|
+
components?: Record<string, SomaComponentDefinition>;
|
|
127
|
+
/**
|
|
128
|
+
* Host 自定义格式化管道(模块 7 U4):{ 管道名: 纯函数 },与内置管道合并。
|
|
129
|
+
* 内置:money / tpl / date / percent / plural。
|
|
130
|
+
*/
|
|
131
|
+
pipes?: Record<string, SomaPipeFn>;
|
|
132
|
+
/**
|
|
133
|
+
* 阶梯词汇注册位(F-09 / 契约 C5),与组件注册同点:
|
|
134
|
+
* `adaptiveVocabulary: createSomaUiAdaptiveVocabulary()`。
|
|
135
|
+
*
|
|
136
|
+
* core **不内置任何级语义**——语法归语言、词汇归组件。不注册而页面声明了
|
|
137
|
+
* `adaptive.ladder` 时按"词汇未知"快速失败,而不是静默忽略那些级。
|
|
138
|
+
*/
|
|
139
|
+
adaptiveVocabulary?: SomaAdaptiveVocabulary;
|
|
68
140
|
/** Render-engine middleware chain (opt-in) */
|
|
69
141
|
renderMiddleware?: SomaMiddlewareChain<SomaRenderMiddlewareContext>;
|
|
70
142
|
/**
|
|
@@ -72,6 +144,20 @@ export interface SomaBootstrapOptions {
|
|
|
72
144
|
* Use `createPermissionMiddleware` when events declare `permission:code` in pipeline.
|
|
73
145
|
*/
|
|
74
146
|
eventMiddleware?: SomaMiddlewareChain<SomaEventMiddlewareContext>;
|
|
147
|
+
/**
|
|
148
|
+
* 错误采集接线(默认关闭:不给就一个全局监听都不装)。
|
|
149
|
+
* 库不该擅自劫持 window 的错误钩子,是否采集由 Host 显式决定。
|
|
150
|
+
*/
|
|
151
|
+
errorReporting?: SomaBootstrapErrorReporting;
|
|
152
|
+
// 主题不在此:无 theme / themeEngine。声明走 appConfig.theme,函数走 applyTheme(引擎内建)。
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* 缺省上报通道:单行 JSON 进 console.error。
|
|
157
|
+
* 单行 JSON 而不是人读叙述——服务端日志采集器 / jq 能直接聚合(日志规范 §5.2)。
|
|
158
|
+
*/
|
|
159
|
+
function reportToConsole(event: SomaErrorEvent): void {
|
|
160
|
+
console.error(`[soma-core][可观测] ${JSON.stringify(event)}`);
|
|
75
161
|
}
|
|
76
162
|
|
|
77
163
|
export interface ParsedRuntimeAssets {
|
|
@@ -104,19 +190,41 @@ export class SomaBootstrap {
|
|
|
104
190
|
private triggerEngine: SomaTriggerEngine | null = null;
|
|
105
191
|
private timerEngine: SomaTimerEngine | null = null;
|
|
106
192
|
private parsedTimers: ParsedTimer[] = [];
|
|
193
|
+
private runtimeResolver: SomaScopeResolver | null = null;
|
|
107
194
|
private proxy: SomaReactiveProxy | null = null;
|
|
108
195
|
private domainInstance: SomaPageRoot | null = null;
|
|
196
|
+
private componentManager: SomaComponentManager | null = null;
|
|
197
|
+
private hostComponents: Record<string, SomaComponentDefinition> = {};
|
|
198
|
+
private pipeRegistry: SomaPipeRegistry;
|
|
199
|
+
/** 阶梯词汇表:Host 级注册,对该 Host 全部页面生效;未注册时恒为 undefined */
|
|
200
|
+
private readonly adaptiveVocabulary?: SomaAdaptiveVocabulary;
|
|
201
|
+
/** 数据对象层:当前页面的声明(无 *_data.yaml 时为 null,整条路径旁路) */
|
|
202
|
+
private dataConfig: SomaDataConfig | null = null;
|
|
203
|
+
/** 数据对象层:最近一次取数任务(whenDataReady 暴露给测试/调试) */
|
|
204
|
+
private dataReady: Promise<void> | null = null;
|
|
205
|
+
/** 数据对象层:字段字典产物(soma-ui 双态映射消费) */
|
|
206
|
+
private dataDicts: SomaDataDicts = {};
|
|
109
207
|
private mounted = false;
|
|
110
208
|
private diagnostics: SomaDiagnostics;
|
|
111
209
|
private readonly telemetry: SomaTelemetry;
|
|
112
210
|
private container: HTMLElement | null = null;
|
|
113
211
|
private assets: SomaPageAssets | null = null;
|
|
212
|
+
/** 错误采集配置(null = 未开启,整条路径旁路) */
|
|
213
|
+
private readonly errorReporting: SomaBootstrapErrorReporting | null;
|
|
214
|
+
/** 错误采集句柄:mount 时装、cleanup 时摘,生命周期与页面严格同寿 */
|
|
215
|
+
private errorReporter: SomaErrorReporterHandle | null = null;
|
|
114
216
|
constructor(options: SomaBootstrapOptions = {}) {
|
|
115
217
|
this.adapter = options.adapter ?? new SomaContainerAdapter();
|
|
116
218
|
this.scheduler = options.scheduler ?? new SomaScheduler();
|
|
117
219
|
this.diagnostics = options.diagnostics ?? new SomaDiagnostics();
|
|
118
220
|
this.telemetry = options.telemetry ?? new SomaTelemetry();
|
|
119
|
-
this.
|
|
221
|
+
this.adaptiveVocabulary = options.adaptiveVocabulary;
|
|
222
|
+
this.assetResolver = options.assetResolver
|
|
223
|
+
?? new SomaAssetResolver(undefined, { adaptiveVocabulary: this.adaptiveVocabulary });
|
|
224
|
+
this.hostComponents = options.components ?? {};
|
|
225
|
+
this.pipeRegistry = new SomaPipeRegistry(options.pipes);
|
|
226
|
+
// 复制一份:身份会随 setErrorReportingPage 变,不该改到调用方手里的对象
|
|
227
|
+
this.errorReporting = options.errorReporting ? { ...options.errorReporting } : null;
|
|
120
228
|
|
|
121
229
|
this.renderMiddleware = options.renderMiddleware ?? new SomaMiddlewareChain();
|
|
122
230
|
|
|
@@ -125,7 +233,13 @@ export class SomaBootstrap {
|
|
|
125
233
|
|
|
126
234
|
async mount(container: HTMLElement, assets: SomaPageAssets): Promise<void> {
|
|
127
235
|
const mountStarted = globalThis.performance?.now?.() ?? Date.now();
|
|
236
|
+
// 首屏三段打点:走到这里资产已经在手(宿主若在拉取前 startBootTimings,段一即覆盖网络耗时;
|
|
237
|
+
// 宿主直接带资产调 mount 时段一趋近 0,属实测事实而非误差)。默认未开启时这两行是两次布尔判断。
|
|
238
|
+
maybeStartBootTimings();
|
|
239
|
+
markBootPhase('assetsReady');
|
|
128
240
|
setActiveTelemetry(this.telemetry);
|
|
241
|
+
// 采集器先于一切装上:挂载途中炸掉的错误同样要能归因到页面
|
|
242
|
+
this.setupErrorReporting();
|
|
129
243
|
try {
|
|
130
244
|
// 仅当未注入时才创建新的 diagnostics
|
|
131
245
|
if (!this.mounted) {
|
|
@@ -140,9 +254,19 @@ export class SomaBootstrap {
|
|
|
140
254
|
// 2. 挂载 HTML
|
|
141
255
|
this.adapter.mount(container, assets.html, assets.includes);
|
|
142
256
|
|
|
257
|
+
// 2.5 组件展开(页面引擎构建前:模板注入、锚点作用域化、插槽投影)
|
|
258
|
+
this.setupComponentManager(container, assets, parsed.uiConfig);
|
|
259
|
+
|
|
260
|
+
// 2.6 主题派生与注入(app.config theme: { brand } 一行换装,缺省旁路)
|
|
261
|
+
this.applyHostTheme(parsed.appConfig);
|
|
262
|
+
|
|
143
263
|
// 3. 创建领域实例并注入配置
|
|
144
264
|
this.domainInstance = this.createDomainInstance(assets.DomainClass, parsed, assets.routerPath);
|
|
145
265
|
|
|
266
|
+
// 3.5 数据对象层(五件套可选件):首渲前解析声明并注入 reloadData 钩子;
|
|
267
|
+
// 声明非法只告警不阻断挂载(data 保持空对象)
|
|
268
|
+
this.prepareDataLayer(this.domainInstance, assets);
|
|
269
|
+
|
|
146
270
|
// 4. 包装响应式代理
|
|
147
271
|
this.proxy = new SomaReactiveProxy(undefined, this.diagnostics);
|
|
148
272
|
this.domainInstance = this.proxy.wrap(this.domainInstance);
|
|
@@ -150,14 +274,20 @@ export class SomaBootstrap {
|
|
|
150
274
|
// 5. 构建运行时(委托给 RuntimeBuilder)
|
|
151
275
|
await this.buildRuntime(parsed);
|
|
152
276
|
|
|
153
|
-
|
|
277
|
+
// 5.5 数据对象层:异步取数(不阻塞首屏),完成后注入 page.data 并全量渲染
|
|
278
|
+
if (this.dataConfig) {
|
|
279
|
+
void this.loadDataObjects();
|
|
280
|
+
}
|
|
154
281
|
if (typeof this.domainInstance.onMount === 'function') {
|
|
155
282
|
await this.domainInstance.onMount();
|
|
156
283
|
}
|
|
157
284
|
this.startDeclarativeTimers();
|
|
285
|
+
this.mounted = true;
|
|
158
286
|
recordMetric('bootstrap.mount', (globalThis.performance?.now?.() ?? Date.now()) - mountStarted);
|
|
159
287
|
} catch (error) {
|
|
160
|
-
console.error('[
|
|
288
|
+
console.error('[soma-core][引擎] 页面挂载失败:', error);
|
|
289
|
+
// 必须在 cleanup 之前上报:cleanup 会摘掉采集器
|
|
290
|
+
this.captureEngineError(error);
|
|
161
291
|
this.cleanup();
|
|
162
292
|
throw error;
|
|
163
293
|
}
|
|
@@ -195,7 +325,19 @@ export class SomaBootstrap {
|
|
|
195
325
|
}
|
|
196
326
|
|
|
197
327
|
const parsed = this.assetResolver.resolve(merged);
|
|
328
|
+
|
|
329
|
+
// 旧页面的组件实例必须在 DOM 被换掉**之前**销毁。
|
|
330
|
+
// adapter.mount 是 `container.innerHTML = html`:跑完之后旧宿主已是游离节点,
|
|
331
|
+
// 此时才触发的 ctrl.onUnmount 里,归还焦点、解锁滚动、按 host 定位的
|
|
332
|
+
// portal/observer 清理全部静默落空(游离节点上 focus() 是 no-op,不报错);
|
|
333
|
+
// 更坏的是 `document.querySelector` 这类反查会**命中新页面的同名节点**,
|
|
334
|
+
// 清理动作落到刚挂上来的新 DOM 上——不报错,还误伤。
|
|
335
|
+
// setupComponentManager 里那次 destroy() 是防御性兜底,删这一行会把上述后果全部放回来。
|
|
336
|
+
this.componentManager?.destroy();
|
|
337
|
+
this.componentManager = null;
|
|
338
|
+
|
|
198
339
|
this.adapter.mount(this.container, merged.html, merged.includes);
|
|
340
|
+
this.setupComponentManager(this.container, merged, parsed.uiConfig);
|
|
199
341
|
|
|
200
342
|
if (overrides.DomainClass) {
|
|
201
343
|
this.proxy?.dispose();
|
|
@@ -217,6 +359,12 @@ export class SomaBootstrap {
|
|
|
217
359
|
await this.buildRuntime(parsed);
|
|
218
360
|
this.startDeclarativeTimers();
|
|
219
361
|
|
|
362
|
+
// 数据对象层:hotSwap 后按合并资产重建声明并重取(无声明时零路径变化)
|
|
363
|
+
this.prepareDataLayer(this.domainInstance, merged);
|
|
364
|
+
if (this.dataConfig) {
|
|
365
|
+
void this.loadDataObjects();
|
|
366
|
+
}
|
|
367
|
+
|
|
220
368
|
if (snapshotId !== null) {
|
|
221
369
|
try {
|
|
222
370
|
this.restoreSnapshot(snapshotId);
|
|
@@ -266,7 +414,8 @@ export class SomaBootstrap {
|
|
|
266
414
|
this.domainInstance.onUnmount();
|
|
267
415
|
}
|
|
268
416
|
} catch (error) {
|
|
269
|
-
console.error('[
|
|
417
|
+
console.error('[soma-core][引擎] onUnmount 回调异常:', error);
|
|
418
|
+
this.captureEngineError(error);
|
|
270
419
|
}
|
|
271
420
|
|
|
272
421
|
this.cleanup();
|
|
@@ -297,6 +446,42 @@ export class SomaBootstrap {
|
|
|
297
446
|
return this.domainInstance;
|
|
298
447
|
}
|
|
299
448
|
|
|
449
|
+
isInitialized(): boolean {
|
|
450
|
+
return this.mounted && this.domainInstance !== null && this.renderEngine !== null;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
isSettled(): boolean {
|
|
454
|
+
return this.isInitialized()
|
|
455
|
+
&& this.scheduler.isSettled()
|
|
456
|
+
&& (this.domainInstance?._services?.http.pendingCount() ?? 0) === 0;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
async whenSettled(): Promise<void> {
|
|
460
|
+
await this.scheduler.whenSettled();
|
|
461
|
+
while (this.isInitialized() && (this.domainInstance?._services?.http.pendingCount() ?? 0) > 0) {
|
|
462
|
+
await new Promise<void>((resolve) => setTimeout(resolve, 0));
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
getDomainValue(path: string): unknown {
|
|
467
|
+
if (!this.domainInstance || !this.runtimeResolver) return undefined;
|
|
468
|
+
return this.runtimeResolver.readFromRoot(this.runtimeResolver.resolvePath(path));
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
getRegisteredSomaIds(): string[] {
|
|
472
|
+
return this.renderEngine?.getRegisteredSomaIds() ?? [];
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/** 数据对象层字段字典产物(对象名 → 字段名 → 字典条目;无声明时为空对象) */
|
|
476
|
+
getDataDicts(): SomaDataDicts {
|
|
477
|
+
return this.dataDicts;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/** 等待当前数据对象取数任务完成(测试 / 调试;无声明时立即 resolve) */
|
|
481
|
+
whenDataReady(): Promise<void> {
|
|
482
|
+
return this.dataReady ?? Promise.resolve();
|
|
483
|
+
}
|
|
484
|
+
|
|
300
485
|
/** 获取渲染引擎(测试 / 调试) */
|
|
301
486
|
getRenderEngine(): SomaRenderEngine | null {
|
|
302
487
|
return this.renderEngine;
|
|
@@ -310,8 +495,48 @@ export class SomaBootstrap {
|
|
|
310
495
|
return this.renderEngine.watch(path, callback, options);
|
|
311
496
|
}
|
|
312
497
|
|
|
498
|
+
/**
|
|
499
|
+
* 更新错误采集的页面身份。
|
|
500
|
+
* 声明态页面"发布新版本 → 原地重渲"时调用,后续错误立刻落在新版本上——
|
|
501
|
+
* 这一个调用就是"哪个版本引入的错误"这个问题的全部答案。
|
|
502
|
+
* 未开启采集时是安全的空操作。
|
|
503
|
+
*/
|
|
504
|
+
setErrorReportingPage(page: SomaPageIdentity): void {
|
|
505
|
+
if (this.errorReporting) {
|
|
506
|
+
this.errorReporting.page = page;
|
|
507
|
+
}
|
|
508
|
+
this.errorReporter?.setPage(page);
|
|
509
|
+
}
|
|
510
|
+
|
|
313
511
|
// ─── 私有方法 ──────────────────────────────────────────
|
|
314
512
|
|
|
513
|
+
/** 装(或复用)错误采集器;未配置时整条路径旁路,一个全局监听都不装 */
|
|
514
|
+
private setupErrorReporting(): void {
|
|
515
|
+
if (!this.errorReporting) {
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
if (this.errorReporter) {
|
|
519
|
+
// 同一 bootstrap 重复 mount / hotSwap:只换身份,不重复挂全局监听
|
|
520
|
+
this.errorReporter.setPage(this.errorReporting.page);
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
this.errorReporter = installSomaErrorReporter({
|
|
524
|
+
page: this.errorReporting.page,
|
|
525
|
+
report: this.errorReporting.report ?? reportToConsole,
|
|
526
|
+
dedupeWindowMs: this.errorReporting.dedupeWindowMs,
|
|
527
|
+
maxEvents: this.errorReporting.maxEvents,
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* 引擎自身捕获的异常进同一采集通道。
|
|
533
|
+
* 全局 error 监听抓不到这些——它们已经被引擎 catch 住了(页面不崩,但确实错了),
|
|
534
|
+
* 不显式补一条,可观测数据就会漏掉最该看的那类问题。
|
|
535
|
+
*/
|
|
536
|
+
private captureEngineError(error: unknown): void {
|
|
537
|
+
this.errorReporter?.capture(error, 'runtime');
|
|
538
|
+
}
|
|
539
|
+
|
|
315
540
|
private createDomainInstance(
|
|
316
541
|
DomainClass: new () => SomaPageRoot,
|
|
317
542
|
parsed: ParsedRuntimeAssets,
|
|
@@ -343,6 +568,133 @@ export class SomaBootstrap {
|
|
|
343
568
|
return raw;
|
|
344
569
|
}
|
|
345
570
|
|
|
571
|
+
// ─── 数据对象层(*_data.yaml,可选件) ─────────────────────
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* 首渲前解析数据对象声明并向 Domain 实例注入 reloadData 钩子。
|
|
575
|
+
* 无声明(dataConfig/dataYaml 均缺省)时整条路径旁路,加载零变化;
|
|
576
|
+
* 声明非法只 console.error,页面继续以空 data 挂载(不阻塞)。
|
|
577
|
+
*/
|
|
578
|
+
private prepareDataLayer(instance: SomaPageRoot, assets: SomaPageAssets): void {
|
|
579
|
+
this.dataConfig = null;
|
|
580
|
+
this.dataReady = null;
|
|
581
|
+
this.dataDicts = {};
|
|
582
|
+
|
|
583
|
+
const hasDeclaration = assets.dataConfig !== undefined
|
|
584
|
+
|| (typeof assets.dataYaml === 'string' && assets.dataYaml.trim() !== '');
|
|
585
|
+
if (!hasDeclaration) return;
|
|
586
|
+
|
|
587
|
+
try {
|
|
588
|
+
const config = assets.dataConfig ?? parseDataYaml(assets.dataYaml!);
|
|
589
|
+
if (Object.keys(config.objects).length === 0) return;
|
|
590
|
+
this.dataConfig = config;
|
|
591
|
+
} catch (error) {
|
|
592
|
+
console.error('[soma-core][数据] 数据对象声明解析失败(页面继续以空 data 挂载):', error);
|
|
593
|
+
this.captureEngineError(error);
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
instance._reloadData = () => this.loadDataObjects();
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* 执行数据对象取数:解析完成后注入 page.data、缓存字段字典并触发一次全量渲染。
|
|
602
|
+
* 任何失败均不阻塞页面:data 置空对象 + console.error。
|
|
603
|
+
*/
|
|
604
|
+
private loadDataObjects(): Promise<void> {
|
|
605
|
+
const instance = this.domainInstance;
|
|
606
|
+
const config = this.dataConfig;
|
|
607
|
+
const services = instance?._services;
|
|
608
|
+
if (!instance || !config || !services) {
|
|
609
|
+
return Promise.resolve();
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// api 声明允许写全路径(如 /api/order/detail):与 http 服务 baseURL 重叠时去重,
|
|
613
|
+
// 避免拼出 /api/api/... 的双前缀
|
|
614
|
+
const baseURL = String(services.config.get('apiBaseUrl') ?? '/api');
|
|
615
|
+
const http = {
|
|
616
|
+
get: <T,>(url: string, requestConfig?: { params?: Record<string, string> }) =>
|
|
617
|
+
services.http.get<T>(
|
|
618
|
+
baseURL && baseURL !== '/' && url.startsWith(`${baseURL}/`) ? url.slice(baseURL.length) : url,
|
|
619
|
+
requestConfig,
|
|
620
|
+
),
|
|
621
|
+
};
|
|
622
|
+
|
|
623
|
+
const task = Promise.resolve()
|
|
624
|
+
.then(() => {
|
|
625
|
+
const resolver = new SomaDataObjectResolver(config, {
|
|
626
|
+
http,
|
|
627
|
+
query: (key) => readQueryParam(key, services.router.getCurrentPath()),
|
|
628
|
+
page: () => this.domainInstance,
|
|
629
|
+
pipes: this.pipeRegistry,
|
|
630
|
+
locale: () => instance._locale as Record<string, unknown> | undefined,
|
|
631
|
+
});
|
|
632
|
+
return resolver.resolve();
|
|
633
|
+
})
|
|
634
|
+
.then((result) => {
|
|
635
|
+
if (this.domainInstance !== instance) return; // 页面已卸载/热换,丢弃过期结果
|
|
636
|
+
this.dataDicts = result.dicts;
|
|
637
|
+
this.domainInstance.data = result.objects;
|
|
638
|
+
this.renderEngine?.render();
|
|
639
|
+
})
|
|
640
|
+
.catch((error) => {
|
|
641
|
+
console.error('[soma-core][数据] 数据对象解析失败(data 保持空对象):', error);
|
|
642
|
+
this.captureEngineError(error);
|
|
643
|
+
if (this.domainInstance === instance) {
|
|
644
|
+
this.domainInstance.data = {};
|
|
645
|
+
this.renderEngine?.render();
|
|
646
|
+
}
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
this.dataReady = task;
|
|
650
|
+
return task;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
/**
|
|
654
|
+
* 主题派生注入:app.config 声明 theme.brand 时全库换装;配置非法只告警不阻断挂载。
|
|
655
|
+
* 主题是引擎内建路径,不是 bootstrap 可注册能力。
|
|
656
|
+
*/
|
|
657
|
+
private applyHostTheme(appConfig: unknown): void {
|
|
658
|
+
const theme = (appConfig as { theme?: SomaThemeInput } | undefined)?.theme;
|
|
659
|
+
if (!theme?.brand) {
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
try {
|
|
663
|
+
applyTheme(theme);
|
|
664
|
+
} catch (error) {
|
|
665
|
+
console.error('[soma-core][主题] 主题派生失败(保持默认令牌):', error);
|
|
666
|
+
this.captureEngineError(error);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
/** 组件管理器装配:无 components 资产时保持 null,组件能力整体旁路 */
|
|
671
|
+
private setupComponentManager(
|
|
672
|
+
container: HTMLElement,
|
|
673
|
+
assets: SomaPageAssets,
|
|
674
|
+
uiConfig: UiConfig,
|
|
675
|
+
): void {
|
|
676
|
+
// 兜底销毁:真正的销毁时机由调用方负责(hotSwap 必须在 adapter.mount 之前销毁,
|
|
677
|
+
// 否则 onUnmount 拿到的是游离宿主)。这里保留是为了任何新调用方都不会漏销毁。
|
|
678
|
+
this.componentManager?.destroy();
|
|
679
|
+
this.componentManager = null;
|
|
680
|
+
|
|
681
|
+
// Host 级注册(构造选项)+ 页面级资产,页面同名覆盖
|
|
682
|
+
const defs = { ...this.hostComponents, ...(assets.components ?? {}) };
|
|
683
|
+
if (Object.keys(defs).length === 0) {
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
const registry = new SomaComponentRegistry();
|
|
688
|
+
registry.registerAll(defs);
|
|
689
|
+
this.componentManager = new SomaComponentManager({
|
|
690
|
+
registry,
|
|
691
|
+
scheduler: this.scheduler,
|
|
692
|
+
diagnostics: this.diagnostics,
|
|
693
|
+
pipeRegistry: this.pipeRegistry,
|
|
694
|
+
});
|
|
695
|
+
this.componentManager.prepare(container, uiConfig);
|
|
696
|
+
}
|
|
697
|
+
|
|
346
698
|
private async buildRuntime(parsed: ParsedRuntimeAssets): Promise<void> {
|
|
347
699
|
if (!this.container || !this.domainInstance) return;
|
|
348
700
|
|
|
@@ -367,10 +719,13 @@ export class SomaBootstrap {
|
|
|
367
719
|
diagnostics: this.diagnostics,
|
|
368
720
|
renderMiddleware: this.renderMiddleware,
|
|
369
721
|
eventMiddleware: this.eventMiddleware,
|
|
722
|
+
pipeRegistry: this.pipeRegistry,
|
|
723
|
+
adaptiveVocabulary: this.adaptiveVocabulary,
|
|
370
724
|
});
|
|
371
725
|
|
|
372
726
|
this.parsedTimers = parsed.timers;
|
|
373
727
|
this.renderEngine = runtime.renderEngine;
|
|
728
|
+
this.runtimeResolver = runtime.resolver;
|
|
374
729
|
this.eventEngine = runtime.eventEngine;
|
|
375
730
|
this.styleBinder = runtime.styleBinder;
|
|
376
731
|
this.propertyWatcher = runtime.propertyWatcher;
|
|
@@ -378,6 +733,26 @@ export class SomaBootstrap {
|
|
|
378
733
|
this.triggerEngine = runtime.triggerEngine;
|
|
379
734
|
this.timerEngine = runtime.timerEngine;
|
|
380
735
|
|
|
736
|
+
// 组件实例挂载(页面引擎就绪后:emit 路由标记、props watch、行内钩子)
|
|
737
|
+
this.componentManager?.activate({
|
|
738
|
+
container: this.container,
|
|
739
|
+
renderEngine: runtime.renderEngine,
|
|
740
|
+
eventEngine: runtime.eventEngine,
|
|
741
|
+
resolver: runtime.resolver,
|
|
742
|
+
manifest: runtime.manifest,
|
|
743
|
+
services: this.domainInstance._services as unknown as Record<string, unknown> | undefined,
|
|
744
|
+
});
|
|
745
|
+
|
|
746
|
+
// 界面中途提交接线:Domain 在长任务里调 `this.publishUi()` 时,
|
|
747
|
+
// 把此刻积累的 patch 立刻上屏而不结束事件事务(见 SomaRuntimeServices.ui)
|
|
748
|
+
if (this.domainInstance?._services) {
|
|
749
|
+
this.domainInstance._services.ui = {
|
|
750
|
+
publish: async () => {
|
|
751
|
+
await runtime.renderEngine.publishInTransaction();
|
|
752
|
+
},
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
|
|
381
756
|
this.proxy?.setOnChange((path, value, oldValue) => {
|
|
382
757
|
this.renderEngine?.schedulePatch(path, value);
|
|
383
758
|
this.styleBinder?.onPropertyChange(path, value);
|
|
@@ -419,6 +794,8 @@ export class SomaBootstrap {
|
|
|
419
794
|
private cleanup(): void {
|
|
420
795
|
this.scheduler.cancelAll('unmount');
|
|
421
796
|
this.stopDeclarativeTimers();
|
|
797
|
+
this.componentManager?.destroy();
|
|
798
|
+
this.componentManager = null;
|
|
422
799
|
this.proxy?.dispose();
|
|
423
800
|
this.eventEngine?.destroy();
|
|
424
801
|
this.renderEngine?.destroy();
|
|
@@ -430,6 +807,12 @@ export class SomaBootstrap {
|
|
|
430
807
|
this.routerUnsubscribe?.();
|
|
431
808
|
this.routerUnsubscribe = null;
|
|
432
809
|
|
|
810
|
+
this.errorReporter?.dispose();
|
|
811
|
+
this.errorReporter = null;
|
|
812
|
+
|
|
813
|
+
this.dataConfig = null;
|
|
814
|
+
this.dataReady = null;
|
|
815
|
+
this.dataDicts = {};
|
|
433
816
|
this.eventEngine = null;
|
|
434
817
|
this.renderEngine = null;
|
|
435
818
|
this.styleBinder = null;
|
|
@@ -439,6 +822,7 @@ export class SomaBootstrap {
|
|
|
439
822
|
this.parsedTimers = [];
|
|
440
823
|
this.propertyWatcher = null;
|
|
441
824
|
this.proxy = null;
|
|
825
|
+
this.runtimeResolver = null;
|
|
442
826
|
this.domainInstance = null;
|
|
443
827
|
this.mounted = false;
|
|
444
828
|
this.container = null;
|