soma-core 1.3.2 → 1.3.4
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 +43 -0
- package/app/SomaPageClient.tsx +22 -68
- 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/bin/soma-lsp.cjs +1 -4
- package/core/build/compiler/full-manifest-builder.ts +19 -23
- package/core/build/compiler/html-include-expander.ts +56 -0
- package/core/build/compiler/page-assets.ts +26 -0
- package/core/build/compiler/page-declaration-compiler.ts +85 -0
- package/core/build/compiler/rollup-plugin-soma.ts +4 -13
- package/core/build/compiler/route-builder.ts +0 -2
- package/core/build/compiler/rspack-plugin-soma.js +1 -10
- package/core/build/compiler/soma-manifest-webpack-plugin.js +54 -9
- package/core/build/compiler/soma-precompile.js +3581 -2387
- package/core/build/compiler/soma-precompile.ts +44 -2
- package/core/build/compiler/soma-rspack-yaml-loader.js +5 -8
- package/core/build/compiler/soma-webpack-loader.js +6 -15
- package/core/build/compiler/vite-plugin-soma.ts +9 -21
- package/core/build/component/pack-from-dir.ts +58 -0
- package/core/build/component/package-loader.ts +281 -0
- package/core/build/eject/apply-eject.ts +133 -0
- package/core/build/eject/plan-eject.ts +133 -0
- package/core/build/lsp/cross-file-diagnostics.cjs +82 -113
- package/core/build/lsp/extra-completion.cjs +14 -8
- package/core/build/lsp/lsp-navigation.cjs +50 -43
- package/core/build/lsp/soma-declaration.cjs +85 -0
- package/core/build/lsp/ui-yaml-completion.cjs +98 -104
- package/core/build/v2/block-compile.ts +200 -0
- package/core/build/v2/block-loader.ts +33 -0
- package/core/build/v2/html-index.ts +120 -0
- package/core/build/v2/migrate-v1.ts +370 -0
- package/core/build/v2/soma-file-loader.ts +216 -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 +277 -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 +445 -0
- package/core/client/component/component-registry.ts +71 -0
- package/core/client/component/contract-compat.ts +132 -0
- package/core/client/component/example-v2.ts +132 -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 +249 -24
- 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 +11 -10
- 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 +380 -7
- package/core/client/engine/style-binder.ts +47 -1
- 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/parser/v2/namespace.ts +182 -0
- package/core/client/parser/v2/page-parser.ts +359 -0
- package/core/client/parser/v2/use-parser.ts +412 -0
- package/core/client/parser/value-lang.ts +340 -0
- package/core/client/pipes/pipe-registry.ts +249 -0
- package/core/client/quality/SomaQualityRegistry.ts +3 -0
- package/core/client/registry/declaration-renderer.ts +161 -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/harmony.ts +307 -0
- package/core/client/theme/scene-tokens.ts +134 -0
- package/core/client/theme/theme-axes.ts +228 -0
- package/core/client/theme/theme-engine.ts +1196 -0
- package/core/client/theme/tone-solver.ts +118 -0
- package/core/client/typography/typography-base.ts +34 -0
- package/core/client/validation/contract-validator.ts +48 -5
- package/core/index.ts +262 -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 +34 -7
- package/core/server/host/soma-page-compile.ts +33 -0
- package/core/server/index.ts +45 -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 +99 -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 +932 -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 +96 -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 +54 -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 +67 -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 +120 -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 +7811 -1380
- package/dist/types/build/compiler/full-manifest-builder.d.ts +6 -2
- package/dist/types/build/compiler/html-include-expander.d.ts +19 -0
- package/dist/types/build/compiler/page-assets.d.ts +3 -0
- package/dist/types/build/compiler/page-declaration-compiler.d.ts +33 -0
- package/dist/types/build/compiler/rollup-plugin-soma.d.ts +0 -2
- package/dist/types/build/compiler/route-builder.d.ts +0 -1
- package/dist/types/build/compiler/soma-precompile.d.ts +17 -0
- package/dist/types/build/compiler/vite-plugin-soma.d.ts +2 -7
- package/dist/types/build/component/pack-from-dir.d.ts +17 -0
- package/dist/types/build/component/package-loader.d.ts +40 -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/build/v2/block-compile.d.ts +28 -0
- package/dist/types/build/v2/block-loader.d.ts +9 -0
- package/dist/types/build/v2/html-index.d.ts +37 -0
- package/dist/types/build/v2/migrate-v1.d.ts +32 -0
- package/dist/types/build/v2/soma-file-loader.d.ts +45 -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 +110 -0
- package/dist/types/client/component/component-registry.d.ts +12 -0
- package/dist/types/client/component/contract-compat.d.ts +16 -0
- package/dist/types/client/component/example-v2.d.ts +9 -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 +51 -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 +118 -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/parser/v2/namespace.d.ts +52 -0
- package/dist/types/client/parser/v2/page-parser.d.ts +21 -0
- package/dist/types/client/parser/v2/use-parser.d.ts +72 -0
- package/dist/types/client/parser/value-lang.d.ts +63 -0
- package/dist/types/client/pipes/pipe-registry.d.ts +38 -0
- package/dist/types/client/registry/declaration-renderer.d.ts +50 -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/harmony.d.ts +77 -0
- package/dist/types/client/theme/scene-tokens.d.ts +25 -0
- package/dist/types/client/theme/theme-axes.d.ts +81 -0
- package/dist/types/client/theme/theme-engine.d.ts +77 -0
- package/dist/types/client/theme/tone-solver.d.ts +47 -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 +47 -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 +2 -0
- package/dist/types/server/host/soma-page-compile.d.ts +7 -0
- package/dist/types/server/index.d.ts +6 -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 +12 -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 +78 -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/editor/vscode/package.json +1 -24
- package/global.d.ts +5 -11
- package/next.config.js +85 -28
- package/package.json +33 -11
- package/proxy.ts +62 -0
- package/tailwind.config.ts +0 -1
- package/core/build/lsp/event-yaml-completion.cjs +0 -106
- 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/editor/vscode/syntaxes/soma-event-yaml.tmLanguage.json +0 -30
- package/middleware.ts +0 -33
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { type SomaPaletteAxes, type SomaResolvedAxes, type SomaSceneAxes } from './theme-axes';
|
|
2
|
+
import { type SomaToneName } from './harmony';
|
|
3
|
+
export type { SomaPaletteAxes, SomaSceneAxes, SomaResolvedAxes } from './theme-axes';
|
|
4
|
+
export type { SomaToneName } from './harmony';
|
|
5
|
+
export interface SomaThemeInput {
|
|
6
|
+
/** 品牌主色(#rgb / #rrggbb) */
|
|
7
|
+
brand: string;
|
|
8
|
+
/**
|
|
9
|
+
* 色彩轴(REQ-007):色相编排 / 语义忠实度 / 彩度 / 反差 / 显式辅色。
|
|
10
|
+
* 整组可省——省略时派生结果与 REQ-007 之前字节级一致。
|
|
11
|
+
*/
|
|
12
|
+
palette?: SomaPaletteAxes;
|
|
13
|
+
/** 场景轴(REQ-007):背景场 / 场强 / 材质缺省档。整组可省 */
|
|
14
|
+
scene?: SomaSceneAxes;
|
|
15
|
+
/** 中性灰气质:warm 暖灰 / cool 冷灰 / neutral 跟随品牌色相(默认) */
|
|
16
|
+
mode?: 'warm' | 'cool' | 'neutral';
|
|
17
|
+
/** 应用暗色令牌(applyTheme 时生效;deriveTheme 恒产出亮暗两套) */
|
|
18
|
+
dark?: boolean;
|
|
19
|
+
/** 逐令牌精调通道:最后合并进 cssVars 与 darkCssVars,优先级最高(亮暗同时生效) */
|
|
20
|
+
overrides?: Record<string, string>;
|
|
21
|
+
}
|
|
22
|
+
export interface SomaThemeMeta {
|
|
23
|
+
/** 本次派生实际生效的轴位(含缺省回落)——诊断与测试的观测面 */
|
|
24
|
+
readonly axes: SomaResolvedAxes;
|
|
25
|
+
/** 语义分离闸是否触发(品牌撞进语义色地盘时为 true) */
|
|
26
|
+
readonly separationApplied: boolean;
|
|
27
|
+
/** 被推开的语气 */
|
|
28
|
+
readonly pushed: readonly SomaToneName[];
|
|
29
|
+
}
|
|
30
|
+
export interface SomaDerivedTheme {
|
|
31
|
+
/** 品牌色阶 50~950(11 档 hex) */
|
|
32
|
+
scale: Record<string, string>;
|
|
33
|
+
/** 语义令牌 → CSS 变量表(--soma-*),soma-ui 全组件消费面(亮色) */
|
|
34
|
+
cssVars: Record<string, string>;
|
|
35
|
+
/** 暗色令牌(同名变量的暗色重映射:主色提亮、深色基底、文字反转) */
|
|
36
|
+
darkCssVars: Record<string, string>;
|
|
37
|
+
/** 对比度报告:主色上文字的 WCAG 对比度(亮/暗均保障 ≥ 4.5) */
|
|
38
|
+
contrast: {
|
|
39
|
+
primaryFg: number;
|
|
40
|
+
darkPrimaryFg: number;
|
|
41
|
+
};
|
|
42
|
+
/** 轴位与闸门观测面(REQ-007 新增;既有消费方零感知) */
|
|
43
|
+
meta: SomaThemeMeta;
|
|
44
|
+
}
|
|
45
|
+
interface Oklch {
|
|
46
|
+
l: number;
|
|
47
|
+
c: number;
|
|
48
|
+
h: number;
|
|
49
|
+
}
|
|
50
|
+
export declare function hexToOklch(hex: string): Oklch;
|
|
51
|
+
/** OKLCH → hex;超 sRGB 色域时压缩 chroma 直到入域(保色相/亮度) */
|
|
52
|
+
export declare function oklchToHex(color: Oklch): string;
|
|
53
|
+
export declare function contrastRatio(hexA: string, hexB: string): number;
|
|
54
|
+
export declare function deriveTheme(input: SomaThemeInput): SomaDerivedTheme;
|
|
55
|
+
/**
|
|
56
|
+
* 派生结果 → 根元素属性。
|
|
57
|
+
*
|
|
58
|
+
* 纯函数而不是写在 applyTheme 里:服务端渲染路径要用同一份逻辑预先戳属性,
|
|
59
|
+
* 否则 immersive 主题的页面会在补水前用色相编码、补水后切成信号编码,
|
|
60
|
+
* 闪一下。属性是编码通道的开关,必须和首屏 HTML 一起到达。
|
|
61
|
+
*/
|
|
62
|
+
export declare function themeRootAttributes(theme: SomaDerivedTheme): Record<string, string>;
|
|
63
|
+
/**
|
|
64
|
+
* 换肤期间挂在根节点上的过渡抑制类名(生产化强化 §6,作业单 P-4)。
|
|
65
|
+
*
|
|
66
|
+
* 为什么需要:一次换肤要改 86 个 CSS 变量,而组件库里大量元素带 `transition`
|
|
67
|
+
* (按钮/输入框的 background、border、color 都在过渡列表里)。变量一改,
|
|
68
|
+
* 这些元素会同时进入过渡——视觉上是"整页缓慢褪色",且几百个元素并发过渡实打实吃 CPU。
|
|
69
|
+
* 换肤是一次状态切换,不是一次交互反馈,它本来就不该有动画。
|
|
70
|
+
*
|
|
71
|
+
* 配套 CSS 规则由 soma-ui 的聚合样式表提供(`THEME_SWITCHING_CSS`):
|
|
72
|
+
* 类名是两包之间的契约,改名要两边一起改。未接入 soma-ui 的 Host 只是拿不到抑制效果,
|
|
73
|
+
* 不会因此出错——挂一个没有规则匹配的类不产生任何副作用。
|
|
74
|
+
*/
|
|
75
|
+
export declare const THEME_SWITCHING_CLASS = "soma-theme-switching";
|
|
76
|
+
/** 把派生令牌注入 :root(运行时换肤/切暗色:重复调用即时生效) */
|
|
77
|
+
export declare function applyTheme(input: SomaThemeInput, root?: HTMLElement): SomaDerivedTheme;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { SomaAxisParams, SomaContrastTargets } from './theme-axes';
|
|
2
|
+
export interface Oklch {
|
|
3
|
+
l: number;
|
|
4
|
+
c: number;
|
|
5
|
+
h: number;
|
|
6
|
+
}
|
|
7
|
+
/** 求解需要的色彩原语由编排者注入——本模块不 import theme-engine,避免循环依赖 */
|
|
8
|
+
export interface ToneSolverDeps {
|
|
9
|
+
oklchToHex(c: Oklch): string;
|
|
10
|
+
hexToOklch(hex: string): Oklch;
|
|
11
|
+
contrastRatio(a: string, b: string): number;
|
|
12
|
+
bestFg(bg: string): string;
|
|
13
|
+
}
|
|
14
|
+
/** 与现状五处循环一致的上限:推 16 轮仍不达标就交出当前最优 */
|
|
15
|
+
export declare const MAX_SOLVE_ITER = 16;
|
|
16
|
+
/**
|
|
17
|
+
* 沿明度方向推色直到谓词满足。
|
|
18
|
+
*
|
|
19
|
+
* **幂等**:谓词一开始就满足时原值返回——这条性质让"S3 推过色相后回跑 S2"
|
|
20
|
+
* 成为无脑安全的操作(未被推动的语气原样穿过,不会因为多跑一次而漂移)。
|
|
21
|
+
*/
|
|
22
|
+
export declare function pushLightnessUntil(color: Oklch, satisfied: (candidate: Oklch) => boolean, direction: 'lighten' | 'darken', maxIter?: number): Oklch;
|
|
23
|
+
/**
|
|
24
|
+
* 现状五处循环的等价封装:不达 AA 就推明度,推的方向按当前明暗自适应。
|
|
25
|
+
*
|
|
26
|
+
* 保留"方向按 l > 0.55 判定"这个既有行为——它不是随手写的:
|
|
27
|
+
* 亮色推更亮、暗色推更暗,才不会把一个中亮度的色推穿到对面去。
|
|
28
|
+
*/
|
|
29
|
+
export declare function ensureContrast(bg: string, deps: ToneSolverDeps, minRatio?: number, maxIter?: number, forceDirection?: 'lighten' | 'darken'): {
|
|
30
|
+
bg: string;
|
|
31
|
+
fg: string;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* 解一个语气的实心底:命中 toneOnPage 目标。
|
|
35
|
+
*
|
|
36
|
+
* 前景(-fg)仍由既有 ④ 系代码解——那部分是实测校准过的 AA 保障,不在此重复。
|
|
37
|
+
*
|
|
38
|
+
* **裁决**:粉彩带约束与对比度目标冲突时**对比度赢**(AA 底线不随 contrast 档
|
|
39
|
+
* 移动,是《主题属性设计》§3 原则 4 的承诺)。带被突破时通过返回值旁路上报,
|
|
40
|
+
* 由编排者收进 meta,供观测——不报错,因为"带"是气质偏好不是硬约束。
|
|
41
|
+
*/
|
|
42
|
+
export declare function solveTone(seed: Oklch, pageHex: string, target: SomaContrastTargets, band: readonly [number, number] | null, deps: ToneSolverDeps): {
|
|
43
|
+
tone: Oklch;
|
|
44
|
+
bandBroken: boolean;
|
|
45
|
+
};
|
|
46
|
+
/** 彩度个性:把 chroma 轴的乘数应用到一个种子彩度上(下限护栏防止推成死灰) */
|
|
47
|
+
export declare function applyChroma(baseChroma: number, params: SomaAxisParams): number;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 中文排版基线样式。Host 集成时随主题一并注入。
|
|
3
|
+
*
|
|
4
|
+
* 条款与理由:
|
|
5
|
+
* - `text-autospace`:中西文之间的自动空隙(盘古之白)。
|
|
6
|
+
* 由排版引擎产生,手敲空格是内容污染——空格会进搜索索引、进复制粘贴、进后端字段。
|
|
7
|
+
* - `line-break: strict`:行首行尾禁则(避免"。"落行首、"("落行尾)。
|
|
8
|
+
* - `word-break: normal` + `overflow-wrap: break-word`:
|
|
9
|
+
* 中文按正常规则断,长 URL / 哈希这类无空格长串才允许强断,两者缺一都会出问题。
|
|
10
|
+
* - `hanging-punctuation: first last`:标点悬挂,让首尾行的文字边缘对齐。
|
|
11
|
+
*
|
|
12
|
+
* 不承诺竖排(`writing-mode`);繁体 / 日文的禁则差异走 i18n 层 locale 排版参数,
|
|
13
|
+
* 本资产只预留概念位。
|
|
14
|
+
*/
|
|
15
|
+
export declare const TYPOGRAPHY_BASE_CSS = "[data-soma-host] {\n text-autospace: normal;\n line-break: strict;\n word-break: normal;\n overflow-wrap: break-word;\n hanging-punctuation: first last;\n}";
|
|
@@ -25,6 +25,8 @@ export declare class SomaContractValidator {
|
|
|
25
25
|
constructor(diagnostics?: SomaDiagnostics);
|
|
26
26
|
validate(input: SomaContractValidationInput): SomaContractReport;
|
|
27
27
|
private collectAnchorStats;
|
|
28
|
+
/** 展示值可携带格式化管道:仅校验管道前的基础路径与绑定型实参路径 */
|
|
29
|
+
private validatePipedPath;
|
|
28
30
|
private validateShowMapping;
|
|
29
31
|
private validateEvents;
|
|
30
32
|
private validateReadablePath;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,12 +3,42 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export * from './client/base/index';
|
|
5
5
|
export type { SomaAppConfig, SomaPageRoot } from './shared/types/domain.types';
|
|
6
|
-
export type { IService } from './server/api/IService';
|
|
6
|
+
export type { IService, SomaServiceRequest } from './server/api/IService';
|
|
7
7
|
export { SomaBootstrap } from './client/engine/soma-bootstrap';
|
|
8
|
-
export type { SomaPageAssets, SomaBootstrapOptions } from './client/engine/soma-bootstrap';
|
|
8
|
+
export type { SomaPageAssets, SomaBootstrapOptions, SomaBootstrapErrorReporting, } from './client/engine/soma-bootstrap';
|
|
9
|
+
export { SomaComponentRegistry } from './client/component/component-registry';
|
|
10
|
+
export { SomaComponentManager } from './client/component/component-manager';
|
|
11
|
+
export { generateAiCatalog, buildCatalogEntry } from './client/component/ai-catalog';
|
|
12
|
+
export type { SomaAiCatalog, SomaAiCatalogEntry, GenerateAiCatalogOptions, } from './client/component/ai-catalog';
|
|
13
|
+
export { SomaPipeRegistry, defaultPipeRegistry } from './client/pipes/pipe-registry';
|
|
14
|
+
export type { SomaPipeFn, SomaPipeContext } from './client/pipes/pipe-registry';
|
|
15
|
+
export { SomaDataObjectResolver, SomaDataCycleError, isSomaMockEnabled, } from './client/data/data-object-resolver';
|
|
16
|
+
export type { SomaDataHttpLike, SomaDataResolverOptions, SomaDataResolveResult, } from './client/data/data-object-resolver';
|
|
17
|
+
export { parseDataConfig, parseDataYaml, parseDataRef, normalizeDataPipeValue, SomaDataConfigError, } from './client/parser/data-config-parser';
|
|
18
|
+
export type { SomaDataRef } from './client/parser/data-config-parser';
|
|
19
|
+
export type { SomaDataConfig, SomaDataObjectConfig, SomaDataSourceConfig, SomaDataFieldConfig, SomaDataFieldRule, SomaDataFieldOption, SomaDataFieldType, SomaDataFieldPermission, SomaDataDicts, } from './shared/types/data-config.types';
|
|
20
|
+
export { deriveTheme, applyTheme, contrastRatio, THEME_SWITCHING_CLASS, } from './client/theme/theme-engine';
|
|
21
|
+
export type { SomaThemeInput, SomaDerivedTheme, SomaThemeMeta } from './client/theme/theme-engine';
|
|
22
|
+
export { themeRootAttributes } from './client/theme/theme-engine';
|
|
23
|
+
export type { SomaPaletteAxes, SomaSceneAxes, SomaResolvedAxes, SomaHarmony, SomaSemantics, SomaChroma, SomaContrast, SomaField, SomaIntensity, SomaMaterial, } from './client/theme/theme-axes';
|
|
24
|
+
export { TYPOGRAPHY_BASE_CSS } from './client/typography/typography-base';
|
|
25
|
+
export { parseAdaptiveConfig, createAdaptiveVocabulary, SomaAdaptiveConfigError, } from './client/parser/adaptive-parser';
|
|
26
|
+
export { compileAdaptive, applyCompiledAdaptive, SOMA_ADAPTIVE_PROFILE_ATTR, } from './client/compiler/adaptive-compile';
|
|
27
|
+
export { SOMA_ADAPTIVE_PROFILES, SOMA_ADAPTIVE_MAX_LADDER, } from './shared/types/adaptive.types';
|
|
28
|
+
export type { SomaAdaptiveProfile, SomaAdaptiveConfig, SomaAdaptiveLevel, SomaAdaptiveLevelKind, SomaAdaptiveLevelDefinition, SomaAdaptiveVocabulary, SomaAdaptiveScopeClass, SomaAdaptiveExecutorConfig, SomaCompiledAdaptive, } from './shared/types/adaptive.types';
|
|
29
|
+
export { createAdaptiveObserverPool, scheduleAdaptiveFlush, resolveTierWithHysteresis, SOMA_DEFAULT_HYSTERESIS, } from './client/adaptive/index';
|
|
30
|
+
export type { SomaAdaptiveObserverPool, SomaAdaptiveSize, SomaAdaptiveSizeCallback, SomaAdaptiveTask, } from './client/adaptive/index';
|
|
31
|
+
export type { SomaComponentDefinition, SomaComponentControllerContext, SomaComponentControllerFactory, } from './client/component/component-definition.types';
|
|
32
|
+
export type { SomaComponentContract, SomaComponentLayer, SomaGeometryFamily, SomaContractProp, SomaContractEmit, SomaContractSlot, } from './shared/types/component-contract.types';
|
|
33
|
+
export { findNestedMutableContractDefault } from './shared/types/component-contract.types';
|
|
9
34
|
export { createDefaultRuntimeServices } from './client/runtime/SomaRuntimeServices';
|
|
10
35
|
export type { SomaRuntimeServices } from './client/runtime/SomaRuntimeServices';
|
|
11
36
|
export { SomaDiagnostics } from './client/diagnostics/SomaDiagnostics';
|
|
37
|
+
export { installSomaErrorReporter } from './client/observability/error-reporter';
|
|
38
|
+
export type { SomaErrorEvent, SomaPageIdentity, SomaErrorReporterOptions, SomaErrorReporterHandle, } from './client/observability/error-reporter';
|
|
39
|
+
export { sanitizeAttributeWrite, hasBlockedScheme, isEventHandlerAttribute } from './client/security/url-guard';
|
|
40
|
+
export { setSomaHtmlSanitizer, resolveSomaHtmlSanitizer, sanitizeSomaHtml, escapeSomaHtml, SOMA_PURIFY_PROFILE, } from './client/security/html-sanitizer';
|
|
41
|
+
export type { SomaHtmlSanitizer, SomaHtmlSanitizeResult } from './client/security/html-sanitizer';
|
|
12
42
|
export type { SomaDiagnosticsSnapshot } from './client/diagnostics/SomaDiagnostics';
|
|
13
43
|
export { matchGlobPath } from './client/engine/property-watcher';
|
|
14
44
|
export { extractConfigFromDomainClass } from './client/parser/annotation-extractor';
|
|
@@ -19,6 +49,8 @@ export type { AsyncStateHost } from './client/base/runAsync';
|
|
|
19
49
|
export { SomaQualityRegistry } from './client/quality/SomaQualityRegistry';
|
|
20
50
|
export { SomaTelemetry } from './client/diagnostics/SomaTelemetry';
|
|
21
51
|
export { setActiveTelemetry, recordMetric } from './client/diagnostics/telemetry-context';
|
|
52
|
+
export { startBootTimings, maybeStartBootTimings, markBootPhase, readBootTimings, resetBootTimings, isBootTimingsEnabled, } from './client/diagnostics/boot-timings';
|
|
53
|
+
export type { SomaBootTimings, SomaBootPhase } from './client/diagnostics/boot-timings';
|
|
22
54
|
export type { IContainerAdapter, SomaAnchorStats } from './client/container/IContainerAdapter';
|
|
23
55
|
export { SomaContainerAdapter } from './client/container/SomaContainerAdapter';
|
|
24
56
|
export { ReactNativeContainerAdapter } from './client/container/ReactNativeContainerAdapter';
|
|
@@ -36,3 +68,16 @@ export { resolveHostBootstrapOptions } from './client/host-bridge/resolve-host-b
|
|
|
36
68
|
export type { SomaHostRequestContext, SomaHostRequestKind, SomaRequestHook, } from './server/host/resolve-host-request-hook';
|
|
37
69
|
export type { SomaDomainLoadContext, SomaDomainLoader, SomaDomainLoaderMap, SomaDomainLoaderModule, SomaDomainModule, SomaDomainModuleResolver, } from './client/host-bridge/soma-domain-loaders';
|
|
38
70
|
export { createSomaDomainLoaderKey, findSomaDomainLoader, loadSomaDomainModuleFromRegistry, } from './client/host-bridge/soma-domain-loaders';
|
|
71
|
+
export { createGeneratedPagePreview, createSomaPageLifecycle, renderPublishedPage, SomaPageLifecycle, type GeneratedPageDeclarations, type GeneratedPagePreviewOptions, type PrecompiledDeclarationAssets, type PreviewHandle, type PreviewObservabilityOptions, type MountedPageInfo, type PublishedPageHandle, type PublishedPageRecord, type RegisterDeclarationOptions, type RenderPublishedPageOptions, type SomaPageLifecycleOptions, } from './client/registry/index';
|
|
72
|
+
export { composeComponentPacks, generatePackCatalog, ComponentPackError, PACK_NAME_PATTERN, type ComposedComponentPacks, type ComposePacksOptions, type SomaComponentPack, type SomaComponentPackStyles, type PackOverrideEvent, } from './client/component/component-pack';
|
|
73
|
+
export { verifyComponentPack, type VerifyPackOptions } from './client/component/verify-pack';
|
|
74
|
+
export { parseValueSegment, evaluateValueNode, isArithSegment, isPlainPath, describeNode, SomaValueLangError, type ValueNode, type PipedValue, type ValuePosition, type HasVarFn, type EvalOptions, } from './client/parser/value-lang';
|
|
75
|
+
export { loadSomaFile, SomaV2ParseError, PAGE_BLOCK_ID, type RawBlock, type SomaFileLoadInput, } from './build/v2/soma-file-loader';
|
|
76
|
+
export { buildHtmlAnchorIndex, type HtmlAnchorIndex, type HtmlAnchorInfo, } from './build/v2/html-index';
|
|
77
|
+
export { compilePageAssets } from './build/compiler/page-assets';
|
|
78
|
+
export { compileSomaV2, type CompiledSomaV2, type CompileSomaV2Input, } from './build/v2/block-compile';
|
|
79
|
+
export { parsePageBlock, type PageBlockAst, } from './client/parser/v2/page-parser';
|
|
80
|
+
export { parseUseBlock, type UseBlockAst, type DataObjectDecl, type FieldDecl, type ActionDecl, } from './client/parser/v2/use-parser';
|
|
81
|
+
export { buildBlockScope, resolvePath, resolveApiRef, expandPath, scopeHasVar, SomaScopeError, type BlockScope, } from './client/parser/v2/namespace';
|
|
82
|
+
export { checkOverrideCompat, type ContractCompatIssue, type ContractCompatIssueKind, } from './client/component/contract-compat';
|
|
83
|
+
export { attachPackStyles, ensurePackBaseStyles, resetPackStyleInjection, type PackStyleOptions, } from './client/component/pack-styles';
|
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The service boundary deliberately uses the Web Request surface instead of a
|
|
3
|
+
* concrete NextRequest class. Hosts can resolve soma-core and Next.js through
|
|
4
|
+
* different workspace copies (for example a published AI package may use
|
|
5
|
+
* Next 14 while the host runs Next 16); those classes are structurally the
|
|
6
|
+
* same request at this boundary but are nominally incompatible in TypeScript.
|
|
7
|
+
*/
|
|
8
|
+
export interface SomaServiceRequest {
|
|
9
|
+
readonly headers: Headers;
|
|
10
|
+
readonly signal: AbortSignal;
|
|
11
|
+
readonly method: string;
|
|
12
|
+
readonly url: string;
|
|
13
|
+
}
|
|
2
14
|
/**
|
|
3
15
|
* SOMA 后端服务接口 —— 宿主项目 `api/service/` 下的服务类可实现此接口。
|
|
4
16
|
*
|
|
@@ -20,9 +32,9 @@ import { NextRequest } from 'next/server';
|
|
|
20
32
|
* ```
|
|
21
33
|
*/
|
|
22
34
|
export interface IService {
|
|
23
|
-
get?(req:
|
|
24
|
-
post?(req:
|
|
25
|
-
put?(req:
|
|
26
|
-
patch?(req:
|
|
27
|
-
delete?(req:
|
|
35
|
+
get?(req: SomaServiceRequest): Promise<Response>;
|
|
36
|
+
post?(req: SomaServiceRequest): Promise<Response>;
|
|
37
|
+
put?(req: SomaServiceRequest): Promise<Response>;
|
|
38
|
+
patch?(req: SomaServiceRequest): Promise<Response>;
|
|
39
|
+
delete?(req: SomaServiceRequest): Promise<Response>;
|
|
28
40
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** 策略档位:off 不发头 / report-only 只上报 / enforce 强制拦截 */
|
|
2
|
+
export type SomaCspMode = 'off' | 'report-only' | 'enforce';
|
|
3
|
+
/** 开关与调参的环境变量(Host 的 .env 里配) */
|
|
4
|
+
export declare const SOMA_CSP_MODE_ENV = "SOMA_CSP";
|
|
5
|
+
export declare const SOMA_CSP_CONNECT_SRC_ENV = "SOMA_CSP_CONNECT_SRC";
|
|
6
|
+
export declare const SOMA_CSP_IMG_SRC_ENV = "SOMA_CSP_IMG_SRC";
|
|
7
|
+
export declare const SOMA_CSP_FRAME_SRC_ENV = "SOMA_CSP_FRAME_SRC";
|
|
8
|
+
export declare const SOMA_CSP_REPORT_URI_ENV = "SOMA_CSP_REPORT_URI";
|
|
9
|
+
/**
|
|
10
|
+
* 中间件把本轮 nonce 放在这个请求头上,页面/组件侧要给动态注入的 `<style>` 打 nonce 时取用。
|
|
11
|
+
* (Next 自身的内联脚本由框架依据**请求上的 CSP 头**自动打 nonce,不需要这个头。)
|
|
12
|
+
*/
|
|
13
|
+
export declare const SOMA_CSP_NONCE_HEADER = "x-soma-csp-nonce";
|
|
14
|
+
export interface SomaCspOptions {
|
|
15
|
+
mode: SomaCspMode;
|
|
16
|
+
/** 本轮请求的 nonce;缺省表示不启用 nonce(dev 档用 'unsafe-inline' 顶替) */
|
|
17
|
+
nonce?: string;
|
|
18
|
+
/** dev 档:Next 的 React Refresh 需要 eval 与内联脚本,HMR 需要 ws: */
|
|
19
|
+
dev?: boolean;
|
|
20
|
+
/** 业务追加的 connect-src 源(AI 上游域、埋点域) */
|
|
21
|
+
connectSrc?: string[];
|
|
22
|
+
/** 业务追加的 img-src 源(CDN 图床) */
|
|
23
|
+
imgSrc?: string[];
|
|
24
|
+
/** 允许宿主 iframe 加载的 frame-src 源;缺省为空,策略保持 'none'。 */
|
|
25
|
+
frameSrc?: string[];
|
|
26
|
+
/** 违规上报端点 */
|
|
27
|
+
reportUri?: string;
|
|
28
|
+
}
|
|
29
|
+
/** 生成一次性 nonce(Web Crypto,Edge 与 Node 18+ 都有,不引 node:crypto 以便跑在 Edge 运行时) */
|
|
30
|
+
export declare function createSomaCspNonce(): string;
|
|
31
|
+
/** 环境变量取值归一化:只认三个档位,别的写法一律当 off(配错不该悄悄半开) */
|
|
32
|
+
export declare function resolveSomaCspMode(raw: string | undefined): SomaCspMode;
|
|
33
|
+
/** 从进程环境解析出完整选项(dev 档由 NODE_ENV 判定,不额外开关) */
|
|
34
|
+
export declare function resolveSomaCspOptionsFromEnv(env: Record<string, string | undefined>): SomaCspOptions;
|
|
35
|
+
/**
|
|
36
|
+
* 指令表(有序):key 为指令名,value 为源列表(空数组表示无值指令,如 upgrade-insecure-requests)。
|
|
37
|
+
* 单独导出便于宿主做差异化覆盖与测试逐条断言。
|
|
38
|
+
*/
|
|
39
|
+
export declare function buildSomaCspDirectives(options: SomaCspOptions): Array<[string, string[]]>;
|
|
40
|
+
/** 指令表序列化为响应头值 */
|
|
41
|
+
export declare function buildSomaCspHeaderValue(options: SomaCspOptions): string;
|
|
42
|
+
/** 档位对应的响应头名 */
|
|
43
|
+
export declare function somaCspHeaderName(mode: Exclude<SomaCspMode, 'off'>): string;
|
|
44
|
+
export interface SomaCspHeader {
|
|
45
|
+
name: string;
|
|
46
|
+
value: string;
|
|
47
|
+
/** 本轮 nonce(dev 档与 off 档为 undefined) */
|
|
48
|
+
nonce?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 中间件接线点:返回应写的响应头;off 档返回 null(调用方原样放行,零副作用)。
|
|
52
|
+
*/
|
|
53
|
+
export declare function createSomaCspHeader(options: SomaCspOptions): SomaCspHeader | null;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Next `headers()` 的返回形状(只用到 get);单测据此做替身,不必拉起整个框架 */
|
|
2
|
+
export interface SomaCspHeaderBag {
|
|
3
|
+
get(name: string): string | null;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* 读取本轮请求的 CSP nonce;CSP 未开或取不到时返回 null。
|
|
7
|
+
*
|
|
8
|
+
* `readHeaders` 由调用方传入(官方 layout 传 `() => headers()`)。做成参数而不是在这里
|
|
9
|
+
* `import { headers } from 'next/headers'`,是为了让这个模块不绑死 Next:中间件与 CSP 策略
|
|
10
|
+
* 模块都能跑在 Edge 运行时,这里也不该成为唯一的框架耦合点。
|
|
11
|
+
*
|
|
12
|
+
* 为什么先判档位再调 readHeaders:Next 的 `headers()` 一被调用,整棵路由树就掉出静态渲染。
|
|
13
|
+
* CSP 缺省是关的(`SOMA_CSP` 未设 = off),绝大多数宿主永远用不到这个 nonce,
|
|
14
|
+
* 不能让他们为一个不会渲染的 meta 丢掉静态化。
|
|
15
|
+
*/
|
|
16
|
+
export declare function readSomaCspNonce(readHeaders: () => SomaCspHeaderBag, env?: Record<string, string | undefined>): string | null;
|
|
17
|
+
/**
|
|
18
|
+
* 供 Next `generateMetadata()` 展开的片段:CSP 开且拿到 nonce 时产出
|
|
19
|
+
* `{ other: { 'csp-nonce': '<r>' } }`(渲染为 `<meta name="csp-nonce" content="<r>">`),
|
|
20
|
+
* 否则产出空对象(缺省行为一字不变)。
|
|
21
|
+
*
|
|
22
|
+
* 走 Metadata API 的 `other` 而不是在 layout 里手写 `<head><meta/></head>`:
|
|
23
|
+
* Next App Router 要求根布局的头部标签由 Metadata API 产出,手写 `<head>` 会与框架
|
|
24
|
+
* 自己的头部注入打架。
|
|
25
|
+
*/
|
|
26
|
+
export declare function somaCspNonceMetadata(readHeaders: () => SomaCspHeaderBag, env?: Record<string, string | undefined>): {
|
|
27
|
+
other?: Record<string, string>;
|
|
28
|
+
};
|
|
29
|
+
/** Next 15+ 的 `headers()` 为异步 API;CSP 关闭时仍不触发请求态读取。 */
|
|
30
|
+
export declare function somaCspNonceMetadataAsync(readHeaders: () => Promise<SomaCspHeaderBag>, env?: Record<string, string | undefined>): Promise<{
|
|
31
|
+
other?: Record<string, string>;
|
|
32
|
+
}>;
|
|
@@ -7,6 +7,11 @@ export interface SomaHostRequestContext {
|
|
|
7
7
|
/**
|
|
8
8
|
* Generic server ingress extension. soma-core does not know authentication,
|
|
9
9
|
* authorization, Admin, or any business application.
|
|
10
|
+
*
|
|
11
|
+
* The hook receives the same Request object later dispatched to the Host
|
|
12
|
+
* service. A Host may therefore normalize or add server-only request headers
|
|
13
|
+
* before returning undefined. Returning a Response still short-circuits the
|
|
14
|
+
* request. Secrets must never be copied into a response or client config.
|
|
10
15
|
*/
|
|
11
16
|
export type SomaRequestHook = (request: Request, context: SomaHostRequestContext) => Response | undefined | Promise<Response | undefined>;
|
|
12
17
|
export interface SomaRequestHookModule {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface SomaPageCompileResult {
|
|
2
|
+
ui: string;
|
|
3
|
+
event: string;
|
|
4
|
+
dataYaml?: string;
|
|
5
|
+
}
|
|
6
|
+
/** 外置块约定 `ui/{base}.blocks/*.yaml`,与页面声明同目录。 */
|
|
7
|
+
export declare function compileSomaPageAssets(uiRaw: string, html: string, uiDir: string, base: string, includes?: Readonly<Record<string, string>>): SomaPageCompileResult;
|
|
@@ -10,12 +10,17 @@
|
|
|
10
10
|
import 'server-only';
|
|
11
11
|
export { ServerFileCache } from './infra/cache/ServerFileCache';
|
|
12
12
|
export { withSomaServerRequestContext, type SomaServerRequestContextOptions, } from './infra/http/soma-server-request-context';
|
|
13
|
-
export type { IService } from './api/IService';
|
|
13
|
+
export type { IService, SomaServiceRequest } from './api/IService';
|
|
14
14
|
export { loadHostService } from './api/load-host-service';
|
|
15
15
|
export { resolveServiceFilePath, toPascalCase } from './api/service-path';
|
|
16
16
|
export { invokeHostRequestHook } from './host/invoke-host-request-hook';
|
|
17
17
|
export { resolveHostRequestHook, type SomaHostRequestContext, type SomaHostRequestKind, type SomaRequestHook, } from './host/resolve-host-request-hook';
|
|
18
|
+
export { createSomaCspHeader, createSomaCspNonce, buildSomaCspDirectives, buildSomaCspHeaderValue, resolveSomaCspMode, resolveSomaCspOptionsFromEnv, somaCspHeaderName, SOMA_CSP_MODE_ENV, SOMA_CSP_CONNECT_SRC_ENV, SOMA_CSP_IMG_SRC_ENV, SOMA_CSP_FRAME_SRC_ENV, SOMA_CSP_REPORT_URI_ENV, SOMA_CSP_NONCE_HEADER, type SomaCspMode, type SomaCspOptions, type SomaCspHeader, } from './host/content-security-policy';
|
|
19
|
+
export { readSomaCspNonce, somaCspNonceMetadata, type SomaCspHeaderBag, } from './host/csp-nonce-metadata';
|
|
18
20
|
export { loadSomaServerPageAssets, SomaPageAssetError, type SomaServerPageAssets, type SomaPageAssetLoadProfile, } from './host/server-page-assets';
|
|
21
|
+
export { loadComponentPackage, loadComponentPackages, scanComponentPackages, SomaComponentPackageError, type LoadPackagesOptions, type PackScanWarning, } from '../build/component/package-loader';
|
|
22
|
+
export { loadComponentPackFromDir, type LoadPackFromDirOptions, } from '../build/component/pack-from-dir';
|
|
23
|
+
export { loadExternalBlocks, blocksDirOf, } from '../build/v2/block-loader';
|
|
19
24
|
export { setSomaDb, getSomaDb, resetSomaDb, createSomaDbSingleton, registerSomaDbProvider, disconnectSomaDb, withSomaDb, type ISomaDbProvider, } from './infra/db/soma-db';
|
|
20
25
|
export { SomaQuery } from './infra/db/query/SomaQuery';
|
|
21
26
|
export type { SomaBaseMapper } from './infra/db/mapper/SomaBaseMapper';
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import type { SomaDataFieldConfig } from '../../shared/types/data-config.types';
|
|
2
|
+
import { RegistryError } from './registry-error';
|
|
3
|
+
/** 注册名约束:与页面名同形(可直接用作文件名与 URL 片段) */
|
|
4
|
+
export declare const API_NAME_PATTERN: RegExp;
|
|
5
|
+
/** 应用命名空间约束:与页面表同形 */
|
|
6
|
+
export declare const API_APP_PATTERN: RegExp;
|
|
7
|
+
/** 允许登记的 HTTP 方法(白名单;登记不是代理,方法只用于描述与自查) */
|
|
8
|
+
export declare const API_METHODS: readonly ["GET", "POST", "PUT", "PATCH", "DELETE"];
|
|
9
|
+
export type ApiMethod = (typeof API_METHODS)[number];
|
|
10
|
+
/** 单条 API 记录的体积上限:字典再大也不该有 64KB */
|
|
11
|
+
export declare const API_RECORD_MAX_BYTES: number;
|
|
12
|
+
export declare const ApiRegistryErrorCodes: {
|
|
13
|
+
/** 注册名非法 */
|
|
14
|
+
readonly API_NAME_INVALID: 4531;
|
|
15
|
+
/** 记录缺必填字段 / 字段类型不对 / 体积超限 */
|
|
16
|
+
readonly API_RECORD_INVALID: 4532;
|
|
17
|
+
/** 接口不存在 */
|
|
18
|
+
readonly API_NOT_FOUND: 4533;
|
|
19
|
+
/** 登记内容里出现凭据类字段(鉴权归宿主运行时,注册表不许持有) */
|
|
20
|
+
readonly API_CREDENTIAL_FORBIDDEN: 4534;
|
|
21
|
+
};
|
|
22
|
+
export type ApiRegistryErrorCode = (typeof ApiRegistryErrorCodes)[keyof typeof ApiRegistryErrorCodes];
|
|
23
|
+
export declare class ApiRegistryError extends RegistryError {
|
|
24
|
+
readonly code: ApiRegistryErrorCode;
|
|
25
|
+
constructor(code: ApiRegistryErrorCode, message: string);
|
|
26
|
+
}
|
|
27
|
+
/** 存储单元:一个接口的当下描述 */
|
|
28
|
+
export interface ApiRecord {
|
|
29
|
+
/** 注册名(页面与人引用它的稳定标识) */
|
|
30
|
+
name: string;
|
|
31
|
+
/** HTTP 方法 */
|
|
32
|
+
method: ApiMethod;
|
|
33
|
+
/** 后端接口路径——**交叉校验的匹配键**,必须以 / 开头 */
|
|
34
|
+
path: string;
|
|
35
|
+
/** 一句话说明这个接口给什么 */
|
|
36
|
+
description?: string;
|
|
37
|
+
/** 字段字典(字段名 → 条目),复用数据对象层词汇;生成链据此绑字段 */
|
|
38
|
+
fields?: Record<string, SomaDataFieldConfig>;
|
|
39
|
+
/** 应用命名空间(缺省 'default') */
|
|
40
|
+
app: string;
|
|
41
|
+
/** 标签(目录化 / 过滤) */
|
|
42
|
+
tags: string[];
|
|
43
|
+
createdAt: number;
|
|
44
|
+
updatedAt: number;
|
|
45
|
+
/** 操作者标识(可选) */
|
|
46
|
+
operator?: string;
|
|
47
|
+
}
|
|
48
|
+
export interface ApiRegisterInput {
|
|
49
|
+
method?: unknown;
|
|
50
|
+
path?: unknown;
|
|
51
|
+
description?: unknown;
|
|
52
|
+
fields?: unknown;
|
|
53
|
+
app?: unknown;
|
|
54
|
+
tags?: unknown;
|
|
55
|
+
operator?: unknown;
|
|
56
|
+
}
|
|
57
|
+
export interface ApiRegistryListOptions {
|
|
58
|
+
/** 只看某应用命名空间 */
|
|
59
|
+
app?: string;
|
|
60
|
+
/** 关键词:命中注册名 / 路径 / 描述(不区分大小写) */
|
|
61
|
+
keyword?: string;
|
|
62
|
+
offset?: number;
|
|
63
|
+
limit?: number;
|
|
64
|
+
}
|
|
65
|
+
export interface ApiRegistryListItem {
|
|
66
|
+
name: string;
|
|
67
|
+
method: ApiMethod;
|
|
68
|
+
path: string;
|
|
69
|
+
app: string;
|
|
70
|
+
tags: string[];
|
|
71
|
+
description?: string;
|
|
72
|
+
/** 字段字典条数(清单不返回字典本体,取详情再拿) */
|
|
73
|
+
fieldCount: number;
|
|
74
|
+
updatedAt: number;
|
|
75
|
+
}
|
|
76
|
+
export interface ApiRegistryListResult {
|
|
77
|
+
apis: ApiRegistryListItem[];
|
|
78
|
+
total: number;
|
|
79
|
+
}
|
|
80
|
+
export interface ApiRegistryStoreOptions {
|
|
81
|
+
/** 持久化目录(每接口一个 <name>.json),默认 data/soma-runtime/apis */
|
|
82
|
+
baseDir?: string;
|
|
83
|
+
/** 时钟注入点,默认 Date.now;测试传确定性时钟 */
|
|
84
|
+
now?: () => number;
|
|
85
|
+
}
|
|
86
|
+
export declare class ApiRegistryStore {
|
|
87
|
+
private readonly baseDir;
|
|
88
|
+
private readonly now;
|
|
89
|
+
/** 读缓存:注册名 → { 记录, 落盘指纹 }。指纹变了就重读(与页面表同口径) */
|
|
90
|
+
private readonly cache;
|
|
91
|
+
constructor(options?: ApiRegistryStoreOptions);
|
|
92
|
+
storageDirectory(): string;
|
|
93
|
+
/** 注册(upsert):名字已存在即更新描述,返回记录与 created 位 */
|
|
94
|
+
register(name: string, input: ApiRegisterInput): {
|
|
95
|
+
record: ApiRecord;
|
|
96
|
+
created: boolean;
|
|
97
|
+
};
|
|
98
|
+
/** 取一条;不存在报 API_NOT_FOUND */
|
|
99
|
+
get(name: string): ApiRecord;
|
|
100
|
+
/** 注销:删掉记录(接口描述不是可回滚资产,不留墓碑);不存在报 API_NOT_FOUND */
|
|
101
|
+
unregister(name: string): ApiRecord;
|
|
102
|
+
/** 清单(按注册名排序,分页协议 { apis, total }) */
|
|
103
|
+
list(options?: ApiRegistryListOptions): ApiRegistryListResult;
|
|
104
|
+
/**
|
|
105
|
+
* 已注册的接口路径集合——交叉校验的判据来源。
|
|
106
|
+
* 路径是匹配键而非注册名:页面声明里写的是路径。
|
|
107
|
+
*
|
|
108
|
+
* 成本:每次调用扫一遍目录并 stat 每条记录(内容没变就命中缓存,不重复解析)。
|
|
109
|
+
* 刻意不给这个集合再加一层缓存——它只在**页面注册**这条低频路径上被调用,
|
|
110
|
+
* 而一层"目录级"缓存必须靠目录 mtime 失效,那在原地改写某条记录时不会变,
|
|
111
|
+
* 会把白名单卡在旧值上:判据宁可每次重算,也不能有可能是错的。
|
|
112
|
+
*/
|
|
113
|
+
registeredPaths(): ReadonlySet<string>;
|
|
114
|
+
private names;
|
|
115
|
+
private read;
|
|
116
|
+
private save;
|
|
117
|
+
/** 缓存上限:一条记录很小,但仓库可以很大——不留无上限的 Map(2GB 机器纪律) */
|
|
118
|
+
private trimCache;
|
|
119
|
+
private stampOf;
|
|
120
|
+
private fileOf;
|
|
121
|
+
}
|
|
122
|
+
export declare function assertApiName(name: unknown): string;
|
|
123
|
+
interface NormalizedApiInput {
|
|
124
|
+
method: ApiMethod;
|
|
125
|
+
path: string;
|
|
126
|
+
description?: string;
|
|
127
|
+
fields?: Record<string, SomaDataFieldConfig>;
|
|
128
|
+
app: string;
|
|
129
|
+
tags: string[];
|
|
130
|
+
operator?: string;
|
|
131
|
+
}
|
|
132
|
+
/** 结构校验 + 凭据禁令:两道一起过,拒绝时点名违规项 */
|
|
133
|
+
export declare function normalizeApiInput(input: ApiRegisterInput): NormalizedApiInput;
|
|
134
|
+
/** 存量记录归一化:补 app/tags 缺省值,名字以文件名为准 */
|
|
135
|
+
export declare function normalizeStoredApiRecord(raw: Record<string, unknown>, name: string): ApiRecord;
|
|
136
|
+
export declare function cloneApiRecord(record: ApiRecord): ApiRecord;
|
|
137
|
+
/** 共享实例:baseDir 可用环境变量 SOMA_API_REGISTRY_DIR 覆盖(默认 data/soma-runtime/apis) */
|
|
138
|
+
export declare function getApiRegistryStore(): ApiRegistryStore;
|
|
139
|
+
/** 替换 / 复位共享实例(测试用;不传参即清空,下次访问按当前环境重建) */
|
|
140
|
+
export declare function resetApiRegistryStore(store?: ApiRegistryStore): void;
|
|
141
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type ObjectRevision = string;
|
|
2
|
+
export interface ObjectSnapshot {
|
|
3
|
+
readonly key: string;
|
|
4
|
+
readonly text: string;
|
|
5
|
+
readonly revision: ObjectRevision;
|
|
6
|
+
}
|
|
7
|
+
export type WriteCondition = {
|
|
8
|
+
readonly kind: 'absent';
|
|
9
|
+
} | {
|
|
10
|
+
readonly kind: 'revision';
|
|
11
|
+
readonly revision: ObjectRevision;
|
|
12
|
+
};
|
|
13
|
+
export type ConditionalWriteResult = {
|
|
14
|
+
readonly committed: true;
|
|
15
|
+
readonly revision: ObjectRevision;
|
|
16
|
+
} | {
|
|
17
|
+
readonly committed: false;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* 对象存储最小一致性契约:点读必须 read-after-write,revision/ETag 是不透明值。
|
|
21
|
+
* S3 对应 If-None-Match:* / If-Match:<etag>;数据库对应版本列条件 UPDATE。
|
|
22
|
+
*/
|
|
23
|
+
export interface ConditionalObjectStore {
|
|
24
|
+
read(key: string): Promise<ObjectSnapshot | null>;
|
|
25
|
+
list(prefix: string): Promise<readonly string[]>;
|
|
26
|
+
compareAndSet(key: string, expected: WriteCondition, text: string): Promise<ConditionalWriteResult>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { PageRegistryDeclaration } from './page-registry-store';
|
|
2
|
+
/**
|
|
3
|
+
* 编译器版本。与 soma-core 的包版本对齐——语义变更必然伴随版本号变化,
|
|
4
|
+
* 拿它当"这份缓存还能不能用"的判据,比自己再造一套指纹可靠。
|
|
5
|
+
*
|
|
6
|
+
* 读不到版本时**故意返回一个永不相等的值**(带进程随机后缀),而不是回落成 '0'。
|
|
7
|
+
* 回落成固定值会让版本闸恒真——库里的旧产物照样被采用,那正是这道闸要防的事。
|
|
8
|
+
* 失败方向必须是"不用缓存",不是"照用"。
|
|
9
|
+
*/
|
|
10
|
+
export declare const DECLARATION_COMPILER_VERSION: string;
|
|
11
|
+
/** 落库的完整运行时产物。 */
|
|
12
|
+
export interface CompiledDeclaration {
|
|
13
|
+
compilerVersion: string;
|
|
14
|
+
uiConfig?: unknown;
|
|
15
|
+
eventConfig?: unknown;
|
|
16
|
+
triggerConfig?: unknown;
|
|
17
|
+
timerConfig?: unknown;
|
|
18
|
+
styleConfig?: unknown;
|
|
19
|
+
dataConfig?: unknown;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 把统一声明一次编译成运行时可直接消费的完整配置对象。
|
|
23
|
+
* 编译失败返回 null,不产生可被误用的半成品。
|
|
24
|
+
*/
|
|
25
|
+
export declare function precompileDeclaration(declaration: PageRegistryDeclaration): CompiledDeclaration | null;
|
|
26
|
+
/**
|
|
27
|
+
* 消费端的版本闸:编译器版本对不上就整份丢弃。
|
|
28
|
+
* 这是"缓存不是真理"那条纪律的执行点。
|
|
29
|
+
*/
|
|
30
|
+
export declare function isCompiledUsable(compiled: CompiledDeclaration | null | undefined, runtimeVersion?: string): boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ConditionalObjectStore, ConditionalWriteResult, ObjectSnapshot, WriteCondition } from './conditional-object-store';
|
|
2
|
+
/** 可运行参考与测试后端;单进程内串行比较并交换,语义等同远端原子条件写。 */
|
|
3
|
+
export declare class InMemoryConditionalObjectStore implements ConditionalObjectStore {
|
|
4
|
+
private readonly objects;
|
|
5
|
+
read(key: string): Promise<ObjectSnapshot | null>;
|
|
6
|
+
list(prefix: string): Promise<readonly string[]>;
|
|
7
|
+
compareAndSet(key: string, expected: WriteCondition, text: string): Promise<ConditionalWriteResult>;
|
|
8
|
+
}
|