soma-core 1.3.2 → 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 +26 -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 +39 -4
- package/core/client/engine/runtime-builder.ts +23 -0
- package/core/client/engine/soma-bootstrap.ts +359 -4
- package/core/client/engine/style-binder.ts +47 -1
- package/core/client/host-bridge/empty-host/data/README.md +17 -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/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 +5341 -894
- 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 +25 -1
- package/dist/types/client/engine/runtime-builder.d.ts +7 -0
- package/dist/types/client/engine/soma-bootstrap.d.ts +116 -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/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 +4 -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
package/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# soma-core
|
|
2
|
+
|
|
3
|
+
SOMA 运行时引擎:页面 = 四件套声明文件(html/_ui.yaml/_event.yaml/_style.yaml,另加可选
|
|
4
|
+
`data/<page>_data.yaml` 数据对象声明)+ 可选 Domain TS —— 声明即数据,落盘即渲染,零构建。
|
|
5
|
+
|
|
6
|
+
## 当前能力(以代码为准)
|
|
7
|
+
|
|
8
|
+
- **编译管线**:ManifestCompiler 把四件套编译为运行时 Manifest;`soma-precompile` 预编译产物
|
|
9
|
+
由 `verify:precompile` 闸门看守新鲜度(`core/build/`)。
|
|
10
|
+
- **渲染引擎 + 事件引擎**:Pipeline 四动词(`NAV_STATIC / NAV_ACTION / UI_REFRESH / UI_INTERACT`)
|
|
11
|
+
+ triggers/timers + confirm 段;格式化管道;作用域清单树与增量刷新
|
|
12
|
+
(`core/client/engine`、`core/client/runtime`)。
|
|
13
|
+
- **组件运行时**:实例 = 迷你运行时(作用域隔离/props/emit 路由/插槽/自治生命周期),
|
|
14
|
+
`data-soma-component` 声明接入;文件态组件包加载器 `loadComponentPackages(dir)`
|
|
15
|
+
(contract.yaml + template.html + ui.yaml + event.yaml,AI 自产组件落盘即用)。
|
|
16
|
+
- **数据对象层**:`*_data.yaml` 解析器(多接口 DAG 依赖编排/字段字典/类型双态映射/速记列/
|
|
17
|
+
mock 兜底),解析结果注入 `page.data`,支持 `reloadData`(`core/client/data`)。
|
|
18
|
+
- **主题引擎**:54+ 业界标准令牌,brand 一行 → OKLCH 派生亮暗双套,WCAG AA 硬保障,
|
|
19
|
+
overrides 精调,`#soma-ui-styles` 整张换皮(`core/client/theme`)。
|
|
20
|
+
- **宿主与 CLI**:Next Host(`app/`,含静态 public/ 托管)+ `soma` CLI
|
|
21
|
+
(`dev/build/start/db generate|push`、mock 服务器、LSP、codegen,见 `bin/`)。
|
|
22
|
+
|
|
23
|
+
## 文档索引(`doc/`)
|
|
24
|
+
|
|
25
|
+
- `SOMA.md` — 框架本体:四件套、Pipeline、Host 集成
|
|
26
|
+
- `soma DSL 语法全书.md` — 四件套 + data.yaml 全语法、绑定形态白名单、速记、管道、YAML 引号纪律
|
|
27
|
+
- `soma 运行时引擎详设.md` — 编译管线、组件运行时、作用域、emit 路由、services 白名单
|
|
28
|
+
- `soma 设计令牌与主题.md` — 令牌总表、派生算法、换肤协议
|
|
29
|
+
- `soma 数据对象层.md` — `*_data.yaml` 语法与解析器
|
|
30
|
+
- `soma 组件dsl扩展.md` / `soma 作用域清单树.md` — 页面侧组件用法与运行时机制
|
|
31
|
+
- 其余:`SOMA-HOST-CLI.md`、`soma 事件引擎.md`、`soma 渲染引擎.md`、`mock-data.md` 等
|
|
32
|
+
|
|
33
|
+
## 测试
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm test -w soma-core # vitest 631+ 用例 + mock 服务器 53(node --test)
|
|
37
|
+
npm run typecheck -w soma-core
|
|
38
|
+
npm run verify:precompile -w soma-core # 预编译产物新鲜度闸门
|
|
39
|
+
npm run verify:client-boundary -w soma-core
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
改解析器/编译器后:`npm run build:precompile` + `npm run build:types`,并重启 dev 服务器。
|
package/app/SomaPageClient.tsx
CHANGED
|
@@ -5,6 +5,7 @@ import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
|
|
5
5
|
import { SomaHydrationShell } from './components/SomaHydrationShell';
|
|
6
6
|
import type { SomaBootstrap as SomaBootstrapType, SomaPageAssets } from '../core/client/engine/soma-bootstrap';
|
|
7
7
|
import { loadHostDomainClass } from '../core/client/host-bridge/load-host-domain-class';
|
|
8
|
+
import { maybeStartBootTimings, readBootTimings } from '../core/client/diagnostics/boot-timings';
|
|
8
9
|
|
|
9
10
|
const isDev = process.env.NODE_ENV !== 'production';
|
|
10
11
|
|
|
@@ -39,6 +40,7 @@ type PagePayload = {
|
|
|
39
40
|
ui: string;
|
|
40
41
|
event: string;
|
|
41
42
|
styleYaml?: string;
|
|
43
|
+
dataYaml?: string;
|
|
42
44
|
includes?: Record<string, string>;
|
|
43
45
|
localeYaml: string;
|
|
44
46
|
appConfigYaml: string;
|
|
@@ -46,7 +48,7 @@ type PagePayload = {
|
|
|
46
48
|
|
|
47
49
|
type PrecompiledAssets = Pick<
|
|
48
50
|
SomaPageAssets,
|
|
49
|
-
'uiConfig' | 'eventConfig' | 'triggerConfig' | 'timerConfig' | 'styleConfig' | 'locale' | 'appConfig'
|
|
51
|
+
'uiConfig' | 'eventConfig' | 'triggerConfig' | 'timerConfig' | 'styleConfig' | 'locale' | 'appConfig' | 'dataConfig'
|
|
50
52
|
>;
|
|
51
53
|
|
|
52
54
|
function normalizeEventBundle(raw: unknown): {
|
|
@@ -83,6 +85,7 @@ async function loadPrecompiledFromManifest(base: string, path: string): Promise<
|
|
|
83
85
|
styleConfig: data.styleConfig,
|
|
84
86
|
locale: data.locale ?? {},
|
|
85
87
|
appConfig: data.appConfig ?? null,
|
|
88
|
+
dataConfig: data.dataConfig ?? undefined,
|
|
86
89
|
};
|
|
87
90
|
} catch {
|
|
88
91
|
return null;
|
|
@@ -91,7 +94,7 @@ async function loadPrecompiledFromManifest(base: string, path: string): Promise<
|
|
|
91
94
|
|
|
92
95
|
async function loadPrecompiledAssets(base: string, urlPath = `/${base}`): Promise<PrecompiledAssets | null> {
|
|
93
96
|
try {
|
|
94
|
-
const [uiMod, eventMod, styleMod, localeMod, configMod] = await Promise.all([
|
|
97
|
+
const [uiMod, eventMod, styleMod, localeMod, configMod, dataMod] = await Promise.all([
|
|
95
98
|
import(
|
|
96
99
|
/* webpackInclude: /\/ui\/.*_ui\.yaml$/ */
|
|
97
100
|
`@soma-host/ui/${base}_ui.yaml`
|
|
@@ -112,6 +115,10 @@ async function loadPrecompiledAssets(base: string, urlPath = `/${base}`): Promis
|
|
|
112
115
|
/* webpackInclude: /\/config\/app\.config\.yaml$/ */
|
|
113
116
|
'@soma-host/config/app.config.yaml'
|
|
114
117
|
).catch(() => null),
|
|
118
|
+
import(
|
|
119
|
+
/* webpackInclude: /\/data\/.*_data\.yaml$/ */
|
|
120
|
+
`@soma-host/data/${base}_data.yaml`
|
|
121
|
+
).catch(() => null),
|
|
115
122
|
]);
|
|
116
123
|
|
|
117
124
|
if (!uiMod?.default || !eventMod?.default) {
|
|
@@ -128,6 +135,7 @@ async function loadPrecompiledAssets(base: string, urlPath = `/${base}`): Promis
|
|
|
128
135
|
styleConfig: styleMod?.default ?? undefined,
|
|
129
136
|
locale: (localeMod?.default ?? {}) as Record<string, unknown>,
|
|
130
137
|
appConfig: configMod?.default ?? null,
|
|
138
|
+
dataConfig: dataMod?.default ?? undefined,
|
|
131
139
|
};
|
|
132
140
|
} catch {
|
|
133
141
|
return null;
|
|
@@ -186,6 +194,14 @@ function SomaPageRenderer({
|
|
|
186
194
|
isSettled: () => bs.isSettled(),
|
|
187
195
|
getDomainValue: (path: string) => bs.getDomainValue(path),
|
|
188
196
|
getRegisteredSomaIds: () => bs.getRegisteredSomaIds(),
|
|
197
|
+
// 只读 CSP nonce 链:响应头 nonce → meta → 运行期注入的样式元素。
|
|
198
|
+
// 浏览器插入后会抹掉 nonce 内容属性,这里读 IDL 属性。
|
|
199
|
+
getCspNonceChain: () => ({
|
|
200
|
+
meta: document.querySelector('meta[name="csp-nonce"]')?.getAttribute('content')?.trim() ?? '',
|
|
201
|
+
styles: Array.from(document.head.querySelectorAll('style'))
|
|
202
|
+
.map((style) => (style as HTMLStyleElement).nonce ?? '')
|
|
203
|
+
.filter(Boolean),
|
|
204
|
+
}),
|
|
189
205
|
};
|
|
190
206
|
window.__SOMA_READY__ = bs.isInitialized();
|
|
191
207
|
}
|
|
@@ -218,6 +234,8 @@ function SomaPageRenderer({
|
|
|
218
234
|
getDiagnosticsSnapshot: () => bs.getDiagnosticsSnapshot(),
|
|
219
235
|
getTelemetrySnapshot: () => bs.getTelemetrySnapshot(),
|
|
220
236
|
getAvailableThemes: () => bs.getAvailableThemes(),
|
|
237
|
+
// 首屏三段:E2E/手工排查从这里读,不必自己去翻 performance 时间线
|
|
238
|
+
getBootTimings: () => readBootTimings(),
|
|
221
239
|
getDomainInstance: () => bs.getDomainInstance(),
|
|
222
240
|
captureSnapshot: () => bs.captureSnapshot(),
|
|
223
241
|
restoreSnapshot: (id: number) => bs.restoreSnapshot(id),
|
|
@@ -228,6 +246,9 @@ function SomaPageRenderer({
|
|
|
228
246
|
|
|
229
247
|
const run = async () => {
|
|
230
248
|
try {
|
|
249
|
+
// 首屏三段打点的起点:放在页面资产拉取之前,段一才量得到网络那一截。
|
|
250
|
+
// 未开启(globalThis.__SOMA_BOOT_TIMINGS__ 未置真)时只是一次布尔判断。
|
|
251
|
+
maybeStartBootTimings();
|
|
231
252
|
setError(null);
|
|
232
253
|
setMounting(true);
|
|
233
254
|
|
|
@@ -267,6 +288,7 @@ function SomaPageRenderer({
|
|
|
267
288
|
uiYaml: cached.ui,
|
|
268
289
|
eventYaml: cached.event,
|
|
269
290
|
styleYaml: cached.styleYaml,
|
|
291
|
+
dataYaml: cached.dataYaml,
|
|
270
292
|
localeYaml: cached.localeYaml ?? '',
|
|
271
293
|
appConfigYaml: cached.appConfigYaml ?? '',
|
|
272
294
|
...routeAssets,
|
|
@@ -282,6 +304,7 @@ function SomaPageRenderer({
|
|
|
282
304
|
ui: data.ui,
|
|
283
305
|
event: data.event,
|
|
284
306
|
styleYaml: data.styleYaml ?? '',
|
|
307
|
+
dataYaml: typeof data.dataYaml === 'string' ? data.dataYaml : undefined,
|
|
285
308
|
includes: data.includes,
|
|
286
309
|
localeYaml: data.localeYaml ?? '',
|
|
287
310
|
appConfigYaml: data.appConfigYaml ?? '',
|
|
@@ -295,6 +318,7 @@ function SomaPageRenderer({
|
|
|
295
318
|
uiYaml: payload.ui,
|
|
296
319
|
eventYaml: payload.event,
|
|
297
320
|
styleYaml: payload.styleYaml,
|
|
321
|
+
dataYaml: payload.dataYaml,
|
|
298
322
|
localeYaml: payload.localeYaml ?? '',
|
|
299
323
|
appConfigYaml: payload.appConfigYaml ?? '',
|
|
300
324
|
...routeAssets,
|
package/app/[...path]/page.tsx
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import { SomaHostPage, type SomaPageSearchParams } from '../components/SomaHostPage';
|
|
2
2
|
import { notFound } from 'next/navigation';
|
|
3
3
|
|
|
4
|
-
export default function SomaCatchAllPage({
|
|
4
|
+
export default async function SomaCatchAllPage({
|
|
5
5
|
params,
|
|
6
6
|
searchParams,
|
|
7
7
|
}: {
|
|
8
|
-
params: { path: string[] }
|
|
9
|
-
searchParams?: SomaPageSearchParams
|
|
8
|
+
params: Promise<{ path: string[] }>;
|
|
9
|
+
searchParams?: Promise<SomaPageSearchParams>;
|
|
10
10
|
}) {
|
|
11
|
-
const
|
|
11
|
+
const resolvedParams = await params;
|
|
12
|
+
const lastSegment = resolvedParams.path.at(-1) ?? '';
|
|
12
13
|
if (/\.[a-zA-Z0-9]+$/.test(lastSegment) && !/\.html$/i.test(lastSegment)) {
|
|
13
14
|
notFound();
|
|
14
15
|
}
|
|
15
16
|
return (
|
|
16
17
|
<SomaHostPage
|
|
17
|
-
pathname={`/${
|
|
18
|
-
searchParams={searchParams}
|
|
18
|
+
pathname={`/${resolvedParams.path.join('/')}`}
|
|
19
|
+
searchParams={await searchParams}
|
|
19
20
|
/>
|
|
20
21
|
);
|
|
21
22
|
}
|
|
@@ -12,9 +12,9 @@ function createHandler(method: HttpMethod) {
|
|
|
12
12
|
|
|
13
13
|
return async function handler(
|
|
14
14
|
req: NextRequest,
|
|
15
|
-
{ params }: { params: { path: string[] } },
|
|
15
|
+
{ params }: { params: Promise<{ path: string[] }> },
|
|
16
16
|
): Promise<Response> {
|
|
17
|
-
const segments = params.path || [];
|
|
17
|
+
const segments = (await params).path || [];
|
|
18
18
|
|
|
19
19
|
const rejected = await invokeHostRequestHook(req, {
|
|
20
20
|
kind: 'api',
|
|
@@ -57,7 +57,7 @@ function createHandler(method: HttpMethod) {
|
|
|
57
57
|
return await handlerFn.call(service, req);
|
|
58
58
|
} catch (e: unknown) {
|
|
59
59
|
const message = e instanceof Error ? e.message : String(e);
|
|
60
|
-
console.error(`[soma-
|
|
60
|
+
console.error(`[soma-core][接口] ${method} /api/${segments.join('/')}:`, message);
|
|
61
61
|
return Response.json(
|
|
62
62
|
{ error: message || 'Internal server error' },
|
|
63
63
|
{ status: 500 },
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { NextRequest } from 'next/server';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import type { IService } from '../../../../core/server/api/IService';
|
|
4
|
+
import { resolveRegistryService } from '../../../../core/server/registry/services/index';
|
|
5
|
+
import { invokeHostRequestHook } from '../../../../core/server/host/invoke-host-request-hook';
|
|
6
|
+
|
|
7
|
+
// 注册中心内置端点(/api/soma-registry/*)。
|
|
8
|
+
// 比通用宿主服务路由(/api/[...path])更具体,Next 自动优先匹配——core 自带,宿主零接线。
|
|
9
|
+
// 鉴权分两层:宿主请求钩子先跑(应用决定谁可管理),端点内的主体鉴权再跑(平台底线)。
|
|
10
|
+
|
|
11
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
12
|
+
|
|
13
|
+
function createHandler(method: HttpMethod) {
|
|
14
|
+
const methodKey = method.toLowerCase() as keyof IService;
|
|
15
|
+
|
|
16
|
+
return async function handler(
|
|
17
|
+
req: NextRequest,
|
|
18
|
+
{ params }: { params: Promise<{ path: string[] }> },
|
|
19
|
+
): Promise<Response> {
|
|
20
|
+
const segments = (await params).path || [];
|
|
21
|
+
|
|
22
|
+
const rejected = await invokeHostRequestHook(req, {
|
|
23
|
+
kind: 'api',
|
|
24
|
+
path: req.nextUrl.pathname,
|
|
25
|
+
});
|
|
26
|
+
if (rejected) {
|
|
27
|
+
return rejected;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const service = resolveRegistryService(segments);
|
|
31
|
+
if (!service) {
|
|
32
|
+
return Response.json(
|
|
33
|
+
{ error: `API not found: /api/soma-registry/${segments.join('/')}` },
|
|
34
|
+
{ status: 404 },
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const handlerFn = service[methodKey];
|
|
39
|
+
if (typeof handlerFn !== 'function') {
|
|
40
|
+
return Response.json(
|
|
41
|
+
{ error: `Method ${method} not allowed: /api/soma-registry/${segments.join('/')}` },
|
|
42
|
+
{ status: 405 },
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
return await handlerFn.call(service, req);
|
|
48
|
+
} catch (e: unknown) {
|
|
49
|
+
// 未预期异常:细节只进服务端日志,回给调用方的只有事件号(不泄漏路径与部署形态)
|
|
50
|
+
const eventId = randomUUID().slice(0, 8);
|
|
51
|
+
console.error(
|
|
52
|
+
`[soma-core][注册中心] 事件 ${eventId} 未处理异常 ${method} /api/soma-registry/${segments.join('/')}:`,
|
|
53
|
+
e instanceof Error ? (e.stack ?? e.message) : String(e),
|
|
54
|
+
);
|
|
55
|
+
return Response.json(
|
|
56
|
+
{ error: `服务器内部错误(事件 ${eventId},详情见服务端日志)` },
|
|
57
|
+
{ status: 500 },
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const GET = createHandler('GET');
|
|
64
|
+
export const POST = createHandler('POST');
|
|
65
|
+
export const PUT = createHandler('PUT');
|
|
66
|
+
export const PATCH = createHandler('PATCH');
|
|
67
|
+
export const DELETE = createHandler('DELETE');
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import dynamic from 'next/dynamic';
|
|
2
1
|
import { headers } from 'next/headers';
|
|
3
2
|
import { redirect } from 'next/navigation';
|
|
4
3
|
import { Suspense } from 'react';
|
|
5
4
|
import { invokeHostRequestHook } from '../../core/server/host/invoke-host-request-hook';
|
|
6
5
|
import { SomaHydrationShell } from './SomaHydrationShell';
|
|
7
|
-
|
|
8
|
-
const SomaPageClient = dynamic(() => import('../SomaPageClient'), {
|
|
9
|
-
ssr: false,
|
|
10
|
-
loading: () => <SomaHydrationShell />,
|
|
11
|
-
});
|
|
6
|
+
import { SomaPageClientBoundary } from './SomaPageClientBoundary';
|
|
12
7
|
|
|
13
8
|
export type SomaPageSearchParams = Record<string, string | string[] | undefined>;
|
|
14
9
|
|
|
@@ -83,7 +78,7 @@ export async function SomaHostPage({
|
|
|
83
78
|
pathname: string;
|
|
84
79
|
searchParams?: SomaPageSearchParams;
|
|
85
80
|
}) {
|
|
86
|
-
const incomingHeaders = headers();
|
|
81
|
+
const incomingHeaders = await headers();
|
|
87
82
|
const requestHeaders = new Headers();
|
|
88
83
|
incomingHeaders.forEach((value, key) => requestHeaders.set(key, value));
|
|
89
84
|
|
|
@@ -127,7 +122,7 @@ export async function SomaHostPage({
|
|
|
127
122
|
|
|
128
123
|
return (
|
|
129
124
|
<Suspense fallback={<SomaHydrationShell />}>
|
|
130
|
-
<
|
|
125
|
+
<SomaPageClientBoundary />
|
|
131
126
|
</Suspense>
|
|
132
127
|
);
|
|
133
128
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import dynamic from 'next/dynamic';
|
|
4
|
+
import { SomaHydrationShell } from './SomaHydrationShell';
|
|
5
|
+
|
|
6
|
+
const SomaPageClient = dynamic(() => import('../SomaPageClient'), {
|
|
7
|
+
ssr: false,
|
|
8
|
+
loading: () => <SomaHydrationShell />,
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export function SomaPageClientBoundary() {
|
|
12
|
+
return <SomaPageClient />;
|
|
13
|
+
}
|
package/app/layout.tsx
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
+
import { headers } from 'next/headers';
|
|
1
2
|
import './globals.css';
|
|
2
3
|
import { readHostAppDisplayName } from '../core/server/host/app-config-composer';
|
|
4
|
+
import { somaCspNonceMetadataAsync } from '../core/server/host/csp-nonce-metadata';
|
|
3
5
|
|
|
4
|
-
export function generateMetadata() {
|
|
6
|
+
export async function generateMetadata() {
|
|
5
7
|
const displayName = readHostAppDisplayName();
|
|
6
8
|
return {
|
|
7
9
|
title: displayName || 'SOMA',
|
|
8
10
|
description: displayName || 'SOMA declarative UI runtime',
|
|
11
|
+
// CSP 开启时透出 `<meta name="csp-nonce">`,供 soma-ui 的运行期 `<style>` 注入器取用
|
|
12
|
+
// (作业单 D-5)。CSP 关(缺省)时展开的是空对象,headers() 也不会被调用,静态渲染不受影响。
|
|
13
|
+
...await somaCspNonceMetadataAsync(() => headers()),
|
|
9
14
|
};
|
|
10
15
|
}
|
|
11
16
|
|
package/app/page.tsx
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { SomaHostPage, type SomaPageSearchParams } from './components/SomaHostPage';
|
|
2
2
|
|
|
3
|
-
export default function SomaRootPage({
|
|
3
|
+
export default async function SomaRootPage({
|
|
4
4
|
searchParams,
|
|
5
5
|
}: {
|
|
6
|
-
searchParams?: SomaPageSearchParams
|
|
6
|
+
searchParams?: Promise<SomaPageSearchParams>;
|
|
7
7
|
}) {
|
|
8
|
-
return <SomaHostPage pathname="/" searchParams={searchParams} />;
|
|
8
|
+
return <SomaHostPage pathname="/" searchParams={await searchParams} />;
|
|
9
9
|
}
|
|
@@ -29,6 +29,7 @@ export async function GET(request: Request): Promise<Response> {
|
|
|
29
29
|
triggers: page.triggers,
|
|
30
30
|
timers: page.timers ?? [],
|
|
31
31
|
styleConfig: page.styleConfig,
|
|
32
|
+
dataConfig: page.dataConfig,
|
|
32
33
|
locale: manifest.locale,
|
|
33
34
|
appConfig: page.appConfig ?? manifest.appConfig,
|
|
34
35
|
manifestVersion: '1.0.0',
|
|
@@ -34,7 +34,7 @@ function errorResponse(error: unknown, pagePath: string): Response {
|
|
|
34
34
|
: 'SOMA_HEADLESS_PAGE_FAILED';
|
|
35
35
|
const message = error instanceof Error ? error.message : String(error);
|
|
36
36
|
if (status >= 500) {
|
|
37
|
-
console.error('[soma-
|
|
37
|
+
console.error('[soma-core][无头渲染] ' + pagePath + ': ' + message);
|
|
38
38
|
}
|
|
39
39
|
return Response.json(
|
|
40
40
|
{
|
|
@@ -6,7 +6,8 @@ import type { ParsedEvent } from '../../shared/types/event.types';
|
|
|
6
6
|
import type { PropertyTrigger } from '../../shared/types/trigger.types';
|
|
7
7
|
import type { ParsedTimer } from '../../shared/types/timer.types';
|
|
8
8
|
import type { StyleConfig } from '../../shared/types/style-config.types';
|
|
9
|
-
import {
|
|
9
|
+
import type { SomaDataConfig } from '../../shared/types/data-config.types';
|
|
10
|
+
import { compileUiConfig, compileStyleConfig, compileDataConfig, precompileYaml } from '@core/build/compiler/soma-precompile';
|
|
10
11
|
import { parseEventConfig } from '../../client/parser/pipeline-parser';
|
|
11
12
|
import { splitEventConfigRaw } from '../../client/parser/trigger-parser';
|
|
12
13
|
import { buildRouteTable, type SomaRouteEntry } from './route-builder';
|
|
@@ -36,6 +37,8 @@ export interface SomaPrecompiledPage {
|
|
|
36
37
|
timers: ParsedTimer[];
|
|
37
38
|
styleConfig?: StyleConfig;
|
|
38
39
|
appConfig?: unknown;
|
|
40
|
+
/** 数据对象层声明(*_data.yaml 预编译物化产物,可选件) */
|
|
41
|
+
dataConfig?: SomaDataConfig;
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
export interface SomaPrecompiledManifest {
|
|
@@ -58,6 +61,7 @@ export function precompileAll(inputs: {
|
|
|
58
61
|
uiYaml: string;
|
|
59
62
|
eventYaml: string;
|
|
60
63
|
styleYaml?: string;
|
|
64
|
+
dataYaml?: string;
|
|
61
65
|
appConfigYaml?: string;
|
|
62
66
|
}>;
|
|
63
67
|
}): SomaPrecompiledManifest {
|
|
@@ -75,6 +79,7 @@ export function precompileAll(inputs: {
|
|
|
75
79
|
triggers: eventBundle.triggers,
|
|
76
80
|
timers: eventBundle.timers,
|
|
77
81
|
styleConfig: p.styleYaml ? compileStyleConfig(p.styleYaml) : undefined,
|
|
82
|
+
dataConfig: p.dataYaml ? compileDataConfig(p.dataYaml) : undefined,
|
|
78
83
|
appConfig: p.appConfigYaml
|
|
79
84
|
? mergeSourcePackageAppConfig(parseAppConfigYaml(p.appConfigYaml), hostAppConfig)
|
|
80
85
|
: undefined,
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
precompileUiYaml,
|
|
6
6
|
precompileEventYaml,
|
|
7
7
|
precompileStyleYaml,
|
|
8
|
+
precompileDataYaml,
|
|
8
9
|
precompileYaml,
|
|
9
10
|
} from './soma-precompile';
|
|
10
11
|
|
|
@@ -12,12 +13,14 @@ export interface SomaRollupPluginOptions {
|
|
|
12
13
|
uiSuffix?: string;
|
|
13
14
|
eventSuffix?: string;
|
|
14
15
|
styleSuffix?: string;
|
|
16
|
+
dataSuffix?: string;
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
export function somaRollupPlugin(options: SomaRollupPluginOptions = {}) {
|
|
18
20
|
const uiSuffix = options.uiSuffix ?? '_ui.yaml';
|
|
19
21
|
const eventSuffix = options.eventSuffix ?? '_event.yaml';
|
|
20
22
|
const styleSuffix = options.styleSuffix ?? '_style.yaml';
|
|
23
|
+
const dataSuffix = options.dataSuffix ?? '_data.yaml';
|
|
21
24
|
|
|
22
25
|
return {
|
|
23
26
|
name: 'rollup-plugin-soma',
|
|
@@ -36,6 +39,9 @@ export function somaRollupPlugin(options: SomaRollupPluginOptions = {}) {
|
|
|
36
39
|
if (id.endsWith(styleSuffix)) {
|
|
37
40
|
return { code: `export default ${precompileStyleYaml(code)};`, map: { mappings: '' } };
|
|
38
41
|
}
|
|
42
|
+
if (id.endsWith(dataSuffix)) {
|
|
43
|
+
return { code: `export default ${precompileDataYaml(code)};`, map: { mappings: '' } };
|
|
44
|
+
}
|
|
39
45
|
return { code: `export default ${precompileYaml(code)};`, map: { mappings: '' } };
|
|
40
46
|
} catch (err) {
|
|
41
47
|
throw new Error(`[rollup-plugin-soma] Failed to compile ${id}: ${err}`);
|
|
@@ -191,6 +191,10 @@ class SomaManifestWebpackPlugin {
|
|
|
191
191
|
uiYaml: readYaml(path.join(source.assetRoot, 'ui', `${base}_ui.yaml`)),
|
|
192
192
|
eventYaml: readYaml(path.join(source.assetRoot, 'event', `${base}_event.yaml`)),
|
|
193
193
|
styleYaml: readYaml(path.join(source.assetRoot, 'ui', `${base}_style.yaml`)) || undefined,
|
|
194
|
+
// 数据对象层(可选件):约定优先 data/,回退 ui/ 同目录
|
|
195
|
+
dataYaml: readYaml(path.join(source.assetRoot, 'data', `${base}_data.yaml`))
|
|
196
|
+
|| readYaml(path.join(source.assetRoot, 'ui', `${base}_data.yaml`))
|
|
197
|
+
|| undefined,
|
|
194
198
|
appConfigYaml: sourceAppConfigPath
|
|
195
199
|
? readYaml(sourceAppConfigPath)
|
|
196
200
|
: (hostAppConfigPath ? readYaml(hostAppConfigPath) : ''),
|