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
|
@@ -1,244 +1,448 @@
|
|
|
1
|
-
// core/engine/soma-bootstrap.ts
|
|
2
|
-
// 职责:生命周期编排(唯一职责)
|
|
3
|
-
|
|
4
|
-
import { SomaContainerAdapter } from '../container/SomaContainerAdapter';
|
|
5
|
-
import {
|
|
6
|
-
import type
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import type {
|
|
14
|
-
import {
|
|
15
|
-
import type {
|
|
16
|
-
import type {
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
this.
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
if (!this.
|
|
171
|
-
throw new Error('[SomaBootstrap] Cannot
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
this.
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
this.
|
|
243
|
-
|
|
244
|
-
}
|
|
1
|
+
// core/engine/soma-bootstrap.ts
|
|
2
|
+
// 职责:生命周期编排(唯一职责)
|
|
3
|
+
|
|
4
|
+
import { SomaContainerAdapter } from '../container/SomaContainerAdapter';
|
|
5
|
+
import type { IContainerAdapter } from '../container/IContainerAdapter';
|
|
6
|
+
import { SomaDiagnostics, type SomaDiagnosticsSnapshot } from '../diagnostics/SomaDiagnostics';
|
|
7
|
+
import { SomaTelemetry } from '../diagnostics/SomaTelemetry';
|
|
8
|
+
import { setActiveTelemetry, recordMetric } from '../diagnostics/telemetry-context';
|
|
9
|
+
import { SomaMiddlewareChain } from '../middleware/SomaMiddlewareChain';
|
|
10
|
+
import { SomaScheduler } from '../scheduler/SomaScheduler';
|
|
11
|
+
import type { ParsedEvent } from '../types/event.types';
|
|
12
|
+
import type { PropertyTrigger } from '../types/trigger.types';
|
|
13
|
+
import type { ParsedTimer } from '../types/timer.types';
|
|
14
|
+
import type { StyleConfig } from '../types/style-config.types';
|
|
15
|
+
import type { UiConfig } from '../types/ui-config.types';
|
|
16
|
+
import type { SomaPageRoot } from '../types/domain.types';
|
|
17
|
+
import { SomaSnapshotStore } from '../runtime/SomaSnapshotStore';
|
|
18
|
+
import { SomaAssetResolver } from './asset-resolver';
|
|
19
|
+
import type { SomaEventMiddlewareContext } from './event-engine';
|
|
20
|
+
import { SomaReactiveProxy } from './reactive-proxy';
|
|
21
|
+
import type { SomaRenderEngine, SomaRenderMiddlewareContext } from './render-engine';
|
|
22
|
+
import type { SomaEventEngine } from './event-engine';
|
|
23
|
+
import type { SomaStyleBinder } from './style-binder';
|
|
24
|
+
import { SomaRuntimeBuilder } from './runtime-builder';
|
|
25
|
+
import { applyLocaleMetadata } from '../base/decorators/Locale';
|
|
26
|
+
import { SomaScopeResolver } from './scope-resolver';
|
|
27
|
+
import type { SomaPropertyWatcher } from './property-watcher';
|
|
28
|
+
import type { SomaOnChangeEngine } from './on-change-engine';
|
|
29
|
+
import type { SomaTriggerEngine } from './trigger-engine';
|
|
30
|
+
import type { SomaTimerEngine } from './timer-engine';
|
|
31
|
+
import { createDefaultRuntimeServices } from '../runtime/SomaRuntimeServices';
|
|
32
|
+
import { getBrowserUrlPath } from '../infra/router/router-path';
|
|
33
|
+
import type { WatchCallback, WatcherOptions } from '../types/watcher.types';
|
|
34
|
+
|
|
35
|
+
// ─── 类型定义 ──────────────────────────────────────────
|
|
36
|
+
|
|
37
|
+
export interface SomaPageAssets {
|
|
38
|
+
html: string;
|
|
39
|
+
includes?: Record<string, string>;
|
|
40
|
+
DomainClass: new () => SomaPageRoot;
|
|
41
|
+
|
|
42
|
+
// ── 字符串模式(运行时解析,向后兼容) ──
|
|
43
|
+
uiYaml?: string;
|
|
44
|
+
eventYaml?: string;
|
|
45
|
+
styleYaml?: string;
|
|
46
|
+
localeYaml?: string;
|
|
47
|
+
appConfigYaml?: string;
|
|
48
|
+
|
|
49
|
+
// ── 预编译模式(构建阶段已解析,运行时零开销) ──
|
|
50
|
+
uiConfig?: UiConfig;
|
|
51
|
+
eventConfig?: ParsedEvent[];
|
|
52
|
+
triggerConfig?: PropertyTrigger[];
|
|
53
|
+
timerConfig?: ParsedTimer[];
|
|
54
|
+
styleConfig?: StyleConfig;
|
|
55
|
+
locale?: Record<string, unknown>;
|
|
56
|
+
appConfig?: unknown;
|
|
57
|
+
|
|
58
|
+
/** Full router path including query string (e.g. /items/detail?id=1) */
|
|
59
|
+
routerPath?: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface SomaBootstrapOptions {
|
|
63
|
+
adapter?: IContainerAdapter;
|
|
64
|
+
scheduler?: SomaScheduler;
|
|
65
|
+
diagnostics?: SomaDiagnostics;
|
|
66
|
+
telemetry?: SomaTelemetry;
|
|
67
|
+
assetResolver?: SomaAssetResolver;
|
|
68
|
+
/** Render-engine middleware chain (opt-in) */
|
|
69
|
+
renderMiddleware?: SomaMiddlewareChain<SomaRenderMiddlewareContext>;
|
|
70
|
+
/**
|
|
71
|
+
* Event-engine middleware chain (opt-in).
|
|
72
|
+
* Use `createPermissionMiddleware` when events declare `permission:code` in pipeline.
|
|
73
|
+
*/
|
|
74
|
+
eventMiddleware?: SomaMiddlewareChain<SomaEventMiddlewareContext>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface ParsedRuntimeAssets {
|
|
78
|
+
uiConfig: UiConfig;
|
|
79
|
+
eventConfig: ParsedEvent[];
|
|
80
|
+
triggers: PropertyTrigger[];
|
|
81
|
+
timers: ParsedTimer[];
|
|
82
|
+
styleConfig?: StyleConfig;
|
|
83
|
+
locale: Record<string, unknown>;
|
|
84
|
+
appConfig: unknown;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// ─── 生命周期编排器 ──────────────────────────────────────
|
|
88
|
+
|
|
89
|
+
export class SomaBootstrap {
|
|
90
|
+
private readonly adapter: IContainerAdapter;
|
|
91
|
+
private readonly scheduler: SomaScheduler;
|
|
92
|
+
private readonly assetResolver: SomaAssetResolver;
|
|
93
|
+
private readonly runtimeBuilder = new SomaRuntimeBuilder();
|
|
94
|
+
private readonly snapshotStore = new SomaSnapshotStore();
|
|
95
|
+
private readonly renderMiddleware: SomaMiddlewareChain<SomaRenderMiddlewareContext>;
|
|
96
|
+
private readonly eventMiddleware: SomaMiddlewareChain<SomaEventMiddlewareContext>;
|
|
97
|
+
private routerUnsubscribe: (() => void) | null = null;
|
|
98
|
+
|
|
99
|
+
private renderEngine: SomaRenderEngine | null = null;
|
|
100
|
+
private eventEngine: SomaEventEngine | null = null;
|
|
101
|
+
private styleBinder: SomaStyleBinder | null = null;
|
|
102
|
+
private propertyWatcher: SomaPropertyWatcher | null = null;
|
|
103
|
+
private onChangeEngine: SomaOnChangeEngine | null = null;
|
|
104
|
+
private triggerEngine: SomaTriggerEngine | null = null;
|
|
105
|
+
private timerEngine: SomaTimerEngine | null = null;
|
|
106
|
+
private parsedTimers: ParsedTimer[] = [];
|
|
107
|
+
private proxy: SomaReactiveProxy | null = null;
|
|
108
|
+
private domainInstance: SomaPageRoot | null = null;
|
|
109
|
+
private mounted = false;
|
|
110
|
+
private diagnostics: SomaDiagnostics;
|
|
111
|
+
private readonly telemetry: SomaTelemetry;
|
|
112
|
+
private container: HTMLElement | null = null;
|
|
113
|
+
private assets: SomaPageAssets | null = null;
|
|
114
|
+
constructor(options: SomaBootstrapOptions = {}) {
|
|
115
|
+
this.adapter = options.adapter ?? new SomaContainerAdapter();
|
|
116
|
+
this.scheduler = options.scheduler ?? new SomaScheduler();
|
|
117
|
+
this.diagnostics = options.diagnostics ?? new SomaDiagnostics();
|
|
118
|
+
this.telemetry = options.telemetry ?? new SomaTelemetry();
|
|
119
|
+
this.assetResolver = options.assetResolver ?? new SomaAssetResolver();
|
|
120
|
+
|
|
121
|
+
this.renderMiddleware = options.renderMiddleware ?? new SomaMiddlewareChain();
|
|
122
|
+
|
|
123
|
+
this.eventMiddleware = options.eventMiddleware ?? new SomaMiddlewareChain();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async mount(container: HTMLElement, assets: SomaPageAssets): Promise<void> {
|
|
127
|
+
const mountStarted = globalThis.performance?.now?.() ?? Date.now();
|
|
128
|
+
setActiveTelemetry(this.telemetry);
|
|
129
|
+
try {
|
|
130
|
+
// 仅当未注入时才创建新的 diagnostics
|
|
131
|
+
if (!this.mounted) {
|
|
132
|
+
this.scheduler.setDiagnostics(this.diagnostics);
|
|
133
|
+
}
|
|
134
|
+
this.container = container;
|
|
135
|
+
this.assets = { ...assets };
|
|
136
|
+
|
|
137
|
+
// 1. 解析资产(委托给 AssetResolver)
|
|
138
|
+
const parsed = this.assetResolver.resolve(assets);
|
|
139
|
+
|
|
140
|
+
// 2. 挂载 HTML
|
|
141
|
+
this.adapter.mount(container, assets.html, assets.includes);
|
|
142
|
+
|
|
143
|
+
// 3. 创建领域实例并注入配置
|
|
144
|
+
this.domainInstance = this.createDomainInstance(assets.DomainClass, parsed, assets.routerPath);
|
|
145
|
+
|
|
146
|
+
// 4. 包装响应式代理
|
|
147
|
+
this.proxy = new SomaReactiveProxy(undefined, this.diagnostics);
|
|
148
|
+
this.domainInstance = this.proxy.wrap(this.domainInstance);
|
|
149
|
+
|
|
150
|
+
// 5. 构建运行时(委托给 RuntimeBuilder)
|
|
151
|
+
await this.buildRuntime(parsed);
|
|
152
|
+
|
|
153
|
+
this.mounted = true;
|
|
154
|
+
if (typeof this.domainInstance.onMount === 'function') {
|
|
155
|
+
await this.domainInstance.onMount();
|
|
156
|
+
}
|
|
157
|
+
this.startDeclarativeTimers();
|
|
158
|
+
recordMetric('bootstrap.mount', (globalThis.performance?.now?.() ?? Date.now()) - mountStarted);
|
|
159
|
+
} catch (error) {
|
|
160
|
+
console.error('[SomaBootstrap] Mount failed:', error);
|
|
161
|
+
this.cleanup();
|
|
162
|
+
throw error;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
async hotSwap(
|
|
167
|
+
overrides: Partial<SomaPageAssets>,
|
|
168
|
+
options?: { resetDiagnostics?: boolean; preserveState?: boolean },
|
|
169
|
+
): Promise<void> {
|
|
170
|
+
if (!this.mounted || !this.container || !this.assets || !this.domainInstance) {
|
|
171
|
+
throw new Error('[SomaBootstrap] Cannot hotSwap before mount');
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const savedLocale =
|
|
175
|
+
overrides.localeYaml !== undefined && this.domainInstance._locale
|
|
176
|
+
? { ...this.domainInstance._locale }
|
|
177
|
+
: null;
|
|
178
|
+
|
|
179
|
+
const snapshotId = options?.preserveState
|
|
180
|
+
? this.snapshotStore.capture(
|
|
181
|
+
this.domainInstance,
|
|
182
|
+
overrides.localeYaml !== undefined ? { exclude: ['_locale'] } : undefined,
|
|
183
|
+
)
|
|
184
|
+
: null;
|
|
185
|
+
|
|
186
|
+
const merged: SomaPageAssets = {
|
|
187
|
+
...this.assets,
|
|
188
|
+
...overrides,
|
|
189
|
+
DomainClass: overrides.DomainClass ?? this.assets.DomainClass,
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
if (options?.resetDiagnostics) {
|
|
193
|
+
this.diagnostics = new SomaDiagnostics();
|
|
194
|
+
this.scheduler.setDiagnostics(this.diagnostics);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const parsed = this.assetResolver.resolve(merged);
|
|
198
|
+
this.adapter.mount(this.container, merged.html, merged.includes);
|
|
199
|
+
|
|
200
|
+
if (overrides.DomainClass) {
|
|
201
|
+
this.proxy?.dispose();
|
|
202
|
+
const raw = this.createDomainInstance(merged.DomainClass, parsed, merged.routerPath);
|
|
203
|
+
this.proxy = new SomaReactiveProxy(undefined, this.diagnostics);
|
|
204
|
+
this.domainInstance = this.proxy.wrap(raw);
|
|
205
|
+
} else {
|
|
206
|
+
if (!options?.preserveState || overrides.localeYaml !== undefined) {
|
|
207
|
+
this.domainInstance._locale = parsed.locale as Record<string, string>;
|
|
208
|
+
this.domainInstance._services?.i18n.loadContent(parsed.locale as Record<string, string>);
|
|
209
|
+
}
|
|
210
|
+
if (parsed.appConfig) {
|
|
211
|
+
this.domainInstance._config = parsed.appConfig as any;
|
|
212
|
+
}
|
|
213
|
+
applyLocaleMetadata(this.domainInstance);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
this.assets = merged;
|
|
217
|
+
await this.buildRuntime(parsed);
|
|
218
|
+
this.startDeclarativeTimers();
|
|
219
|
+
|
|
220
|
+
if (snapshotId !== null) {
|
|
221
|
+
try {
|
|
222
|
+
this.restoreSnapshot(snapshotId);
|
|
223
|
+
} catch {
|
|
224
|
+
/* snapshot 与新区划不兼容时忽略 */
|
|
225
|
+
}
|
|
226
|
+
if (savedLocale) {
|
|
227
|
+
this.domainInstance._locale = { ...savedLocale, ...parsed.locale } as Record<string, string>;
|
|
228
|
+
applyLocaleMetadata(this.domainInstance);
|
|
229
|
+
this.renderEngine?.render();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
captureSnapshot(options?: { exclude?: string[] }): number {
|
|
235
|
+
if (!this.domainInstance) {
|
|
236
|
+
throw new Error('[SomaBootstrap] Cannot capture snapshot before mount');
|
|
237
|
+
}
|
|
238
|
+
return this.snapshotStore.capture(this.domainInstance, options);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
restoreSnapshot(snapshotId: number): void {
|
|
242
|
+
if (!this.domainInstance) {
|
|
243
|
+
throw new Error('[SomaBootstrap] Cannot restore snapshot before mount');
|
|
244
|
+
}
|
|
245
|
+
this.snapshotStore.restore(snapshotId, this.domainInstance);
|
|
246
|
+
this.renderEngine?.render();
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
batch(fn: () => void): void {
|
|
250
|
+
if (!this.proxy) {
|
|
251
|
+
throw new Error('[SomaBootstrap] Cannot batch before mount');
|
|
252
|
+
}
|
|
253
|
+
this.proxy.beginBatch();
|
|
254
|
+
try {
|
|
255
|
+
fn();
|
|
256
|
+
} finally {
|
|
257
|
+
this.proxy.endBatch();
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
async unmount(): Promise<void> {
|
|
262
|
+
if (!this.mounted) return;
|
|
263
|
+
|
|
264
|
+
try {
|
|
265
|
+
if (this.domainInstance && typeof this.domainInstance.onUnmount === 'function') {
|
|
266
|
+
this.domainInstance.onUnmount();
|
|
267
|
+
}
|
|
268
|
+
} catch (error) {
|
|
269
|
+
console.error('[SomaBootstrap] onUnmount error:', error);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
this.cleanup();
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
getDiagnosticsSnapshot(): SomaDiagnosticsSnapshot {
|
|
276
|
+
return this.diagnostics.snapshot();
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
getTelemetrySnapshot(): ReturnType<SomaTelemetry['snapshot']> {
|
|
280
|
+
return this.telemetry.snapshot();
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
getAvailableThemes(): string[] {
|
|
284
|
+
return this.styleBinder?.getAvailableThemes() ?? [];
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
getStyleBinder(): SomaStyleBinder | null {
|
|
288
|
+
return this.styleBinder;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
switchTheme(themeName: string | null): void {
|
|
292
|
+
this.styleBinder?.switchTheme(themeName);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/** 获取当前挂载的业务实例(测试 / 调试) */
|
|
296
|
+
getDomainInstance(): SomaPageRoot | null {
|
|
297
|
+
return this.domainInstance;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** 获取渲染引擎(测试 / 调试) */
|
|
301
|
+
getRenderEngine(): SomaRenderEngine | null {
|
|
302
|
+
return this.renderEngine;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** 监听属性变更(委托 RenderEngine.watch) */
|
|
306
|
+
watch(path: string, callback: WatchCallback, options?: WatcherOptions): () => void {
|
|
307
|
+
if (!this.renderEngine) {
|
|
308
|
+
throw new Error('[SomaBootstrap] Cannot watch before mount');
|
|
309
|
+
}
|
|
310
|
+
return this.renderEngine.watch(path, callback, options);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// ─── 私有方法 ──────────────────────────────────────────
|
|
314
|
+
|
|
315
|
+
private createDomainInstance(
|
|
316
|
+
DomainClass: new () => SomaPageRoot,
|
|
317
|
+
parsed: ParsedRuntimeAssets,
|
|
318
|
+
routerPath?: string,
|
|
319
|
+
): SomaPageRoot {
|
|
320
|
+
const raw = new DomainClass();
|
|
321
|
+
raw._locale = parsed.locale as Record<string, string>;
|
|
322
|
+
if (parsed.appConfig) {
|
|
323
|
+
raw._config = parsed.appConfig as any;
|
|
324
|
+
}
|
|
325
|
+
applyLocaleMetadata(raw);
|
|
326
|
+
|
|
327
|
+
raw._services = createDefaultRuntimeServices({
|
|
328
|
+
appConfig: parsed.appConfig,
|
|
329
|
+
locale: parsed.locale,
|
|
330
|
+
initialPath: routerPath ?? getBrowserUrlPath(),
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
this.wireRouter(raw);
|
|
334
|
+
|
|
335
|
+
if (parsed.uiConfig.initProps) {
|
|
336
|
+
const preResolver = new SomaScopeResolver();
|
|
337
|
+
preResolver.build(parsed.uiConfig, raw);
|
|
338
|
+
for (const [path, value] of Object.entries(parsed.uiConfig.initProps)) {
|
|
339
|
+
preResolver.writeToRoot(path, value);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
return raw;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
private async buildRuntime(parsed: ParsedRuntimeAssets): Promise<void> {
|
|
347
|
+
if (!this.container || !this.domainInstance) return;
|
|
348
|
+
|
|
349
|
+
this.stopDeclarativeTimers();
|
|
350
|
+
this.eventEngine?.destroy();
|
|
351
|
+
this.renderEngine?.destroy();
|
|
352
|
+
this.styleBinder?.destroy();
|
|
353
|
+
this.onChangeEngine?.destroy();
|
|
354
|
+
this.triggerEngine?.destroy();
|
|
355
|
+
this.propertyWatcher?.destroy();
|
|
356
|
+
|
|
357
|
+
const runtime = this.runtimeBuilder.build({
|
|
358
|
+
container: this.container,
|
|
359
|
+
adapter: this.adapter,
|
|
360
|
+
uiConfig: parsed.uiConfig,
|
|
361
|
+
eventConfig: parsed.eventConfig,
|
|
362
|
+
triggers: parsed.triggers,
|
|
363
|
+
timers: parsed.timers,
|
|
364
|
+
styleConfig: parsed.styleConfig,
|
|
365
|
+
proxiedInstance: this.domainInstance,
|
|
366
|
+
scheduler: this.scheduler,
|
|
367
|
+
diagnostics: this.diagnostics,
|
|
368
|
+
renderMiddleware: this.renderMiddleware,
|
|
369
|
+
eventMiddleware: this.eventMiddleware,
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
this.parsedTimers = parsed.timers;
|
|
373
|
+
this.renderEngine = runtime.renderEngine;
|
|
374
|
+
this.eventEngine = runtime.eventEngine;
|
|
375
|
+
this.styleBinder = runtime.styleBinder;
|
|
376
|
+
this.propertyWatcher = runtime.propertyWatcher;
|
|
377
|
+
this.onChangeEngine = runtime.onChangeEngine;
|
|
378
|
+
this.triggerEngine = runtime.triggerEngine;
|
|
379
|
+
this.timerEngine = runtime.timerEngine;
|
|
380
|
+
|
|
381
|
+
this.proxy?.setOnChange((path, value, oldValue) => {
|
|
382
|
+
this.renderEngine?.schedulePatch(path, value);
|
|
383
|
+
this.styleBinder?.onPropertyChange(path, value);
|
|
384
|
+
this.propertyWatcher?.notify(path, value, oldValue);
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
private startDeclarativeTimers(): void {
|
|
389
|
+
if (!this.container || !this.eventEngine || !this.timerEngine || !this.domainInstance?._services) {
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
this.runtimeBuilder.startTimers(
|
|
393
|
+
{ eventEngine: this.eventEngine, timerEngine: this.timerEngine },
|
|
394
|
+
{
|
|
395
|
+
container: this.container,
|
|
396
|
+
adapter: this.adapter,
|
|
397
|
+
timers: this.parsedTimers,
|
|
398
|
+
timerService: this.domainInstance._services.timer,
|
|
399
|
+
},
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
private stopDeclarativeTimers(): void {
|
|
404
|
+
if (this.timerEngine && this.domainInstance?._services) {
|
|
405
|
+
this.timerEngine.stop(this.domainInstance._services.timer);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
private wireRouter(raw: SomaPageRoot): void {
|
|
410
|
+
const services = raw._services;
|
|
411
|
+
if (!services) return;
|
|
412
|
+
|
|
413
|
+
this.routerUnsubscribe?.();
|
|
414
|
+
this.adapter.setNavigateHandler?.((url) => {
|
|
415
|
+
void services.router.navigate(url);
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
private cleanup(): void {
|
|
420
|
+
this.scheduler.cancelAll('unmount');
|
|
421
|
+
this.stopDeclarativeTimers();
|
|
422
|
+
this.proxy?.dispose();
|
|
423
|
+
this.eventEngine?.destroy();
|
|
424
|
+
this.renderEngine?.destroy();
|
|
425
|
+
this.styleBinder?.destroy();
|
|
426
|
+
this.onChangeEngine?.destroy();
|
|
427
|
+
this.triggerEngine?.destroy();
|
|
428
|
+
this.propertyWatcher?.destroy();
|
|
429
|
+
|
|
430
|
+
this.routerUnsubscribe?.();
|
|
431
|
+
this.routerUnsubscribe = null;
|
|
432
|
+
|
|
433
|
+
this.eventEngine = null;
|
|
434
|
+
this.renderEngine = null;
|
|
435
|
+
this.styleBinder = null;
|
|
436
|
+
this.onChangeEngine = null;
|
|
437
|
+
this.triggerEngine = null;
|
|
438
|
+
this.timerEngine = null;
|
|
439
|
+
this.parsedTimers = [];
|
|
440
|
+
this.propertyWatcher = null;
|
|
441
|
+
this.proxy = null;
|
|
442
|
+
this.domainInstance = null;
|
|
443
|
+
this.mounted = false;
|
|
444
|
+
this.container = null;
|
|
445
|
+
this.assets = null;
|
|
446
|
+
setActiveTelemetry(null);
|
|
447
|
+
}
|
|
448
|
+
}
|