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.
Files changed (229) hide show
  1. package/README.md +42 -0
  2. package/app/SomaPageClient.tsx +26 -2
  3. package/app/[...path]/page.tsx +7 -6
  4. package/app/api/[...path]/route.ts +3 -3
  5. package/app/api/soma-registry/[...path]/route.ts +67 -0
  6. package/app/components/SomaHostPage.tsx +3 -8
  7. package/app/components/SomaPageClientBoundary.tsx +13 -0
  8. package/app/layout.tsx +6 -1
  9. package/app/page.tsx +3 -3
  10. package/app/soma/manifest/route.ts +1 -0
  11. package/app/soma/page-object/route.ts +1 -1
  12. package/core/build/compiler/full-manifest-builder.ts +6 -1
  13. package/core/build/compiler/rollup-plugin-soma.ts +6 -0
  14. package/core/build/compiler/soma-manifest-webpack-plugin.js +4 -0
  15. package/core/build/compiler/soma-precompile.js +3507 -2387
  16. package/core/build/compiler/soma-precompile.ts +31 -2
  17. package/core/build/compiler/soma-rspack-yaml-loader.js +3 -0
  18. package/core/build/compiler/soma-webpack-loader.js +7 -1
  19. package/core/build/compiler/vite-plugin-soma.ts +11 -1
  20. package/core/build/component/package-loader.ts +135 -0
  21. package/core/build/eject/apply-eject.ts +133 -0
  22. package/core/build/eject/plan-eject.ts +139 -0
  23. package/core/client/adaptive/flush-scheduler.ts +96 -0
  24. package/core/client/adaptive/hysteresis.ts +56 -0
  25. package/core/client/adaptive/index.ts +23 -0
  26. package/core/client/adaptive/observer-pool.ts +90 -0
  27. package/core/client/base/SomaPageRootBase.ts +50 -0
  28. package/core/client/compiler/adaptive-compile.ts +136 -0
  29. package/core/client/compiler/manifest-compiler.ts +155 -27
  30. package/core/client/component/ai-catalog.ts +262 -0
  31. package/core/client/component/component-definition.types.ts +65 -0
  32. package/core/client/component/component-expander.ts +119 -0
  33. package/core/client/component/component-manager.ts +933 -0
  34. package/core/client/component/component-pack.ts +271 -0
  35. package/core/client/component/component-registry.ts +71 -0
  36. package/core/client/component/pack-styles.ts +94 -0
  37. package/core/client/component/scoped-adapter.ts +85 -0
  38. package/core/client/component/verify-pack.ts +247 -0
  39. package/core/client/container/MiniProgramContainerAdapter.ts +15 -1
  40. package/core/client/container/ReactNativeContainerAdapter.ts +15 -1
  41. package/core/client/container/SomaContainerAdapter.ts +186 -180
  42. package/core/client/data/data-object-resolver.ts +417 -0
  43. package/core/client/diagnostics/SomaDiagnostics.ts +187 -186
  44. package/core/client/diagnostics/boot-timings.ts +152 -0
  45. package/core/client/engine/asset-resolver.ts +12 -2
  46. package/core/client/engine/dom-renderer.ts +235 -16
  47. package/core/client/engine/emit-event.ts +21 -0
  48. package/core/client/engine/event-engine.ts +34 -4
  49. package/core/client/engine/on-change-engine.ts +1 -1
  50. package/core/client/engine/property-watcher.ts +1 -1
  51. package/core/client/engine/reactive-proxy.ts +3 -3
  52. package/core/client/engine/render-engine.ts +39 -4
  53. package/core/client/engine/runtime-builder.ts +23 -0
  54. package/core/client/engine/soma-bootstrap.ts +359 -4
  55. package/core/client/engine/style-binder.ts +47 -1
  56. package/core/client/host-bridge/empty-host/data/README.md +17 -0
  57. package/core/client/observability/error-reporter.ts +173 -0
  58. package/core/client/parser/adaptive-parser.ts +264 -0
  59. package/core/client/parser/data-config-parser.ts +396 -0
  60. package/core/client/parser/pipeline-parser.ts +15 -3
  61. package/core/client/parser/style-config-parser.ts +65 -2
  62. package/core/client/parser/ui-config-parser.ts +52 -3
  63. package/core/client/pipes/pipe-registry.ts +249 -0
  64. package/core/client/quality/SomaQualityRegistry.ts +3 -0
  65. package/core/client/registry/declaration-renderer.ts +159 -0
  66. package/core/client/registry/index.ts +28 -0
  67. package/core/client/registry/page-lifecycle.ts +171 -0
  68. package/core/client/registry/remote-page.ts +139 -0
  69. package/core/client/runtime/SomaRuntimeServices.ts +24 -0
  70. package/core/client/security/attribute-presence.ts +70 -0
  71. package/core/client/security/html-sanitizer.ts +113 -0
  72. package/core/client/security/url-guard.ts +0 -0
  73. package/core/client/theme/theme-engine.ts +936 -0
  74. package/core/client/typography/typography-base.ts +34 -0
  75. package/core/client/validation/contract-validator.ts +48 -5
  76. package/core/index.ts +190 -2
  77. package/core/server/api/IService.ts +18 -6
  78. package/core/server/api/load-host-service.ts +3 -3
  79. package/core/server/host/content-security-policy.ts +190 -0
  80. package/core/server/host/csp-nonce-metadata.ts +75 -0
  81. package/core/server/host/resolve-host-request-hook.ts +5 -0
  82. package/core/server/host/server-page-assets.ts +10 -0
  83. package/core/server/index.ts +30 -1
  84. package/core/server/infra/cache/ServerFileCache.ts +1 -1
  85. package/core/server/mock/node/cli.mjs +2 -2
  86. package/core/server/registry/api-registry-store.ts +518 -0
  87. package/core/server/registry/conditional-object-store.ts +29 -0
  88. package/core/server/registry/declaration-precompiler.ts +129 -0
  89. package/core/server/registry/in-memory-conditional-object-store.ts +43 -0
  90. package/core/server/registry/index.ts +142 -0
  91. package/core/server/registry/page-registry-repository.ts +373 -0
  92. package/core/server/registry/page-registry-store.ts +903 -0
  93. package/core/server/registry/registry-error.ts +17 -0
  94. package/core/server/registry/registry-file-lock.ts +173 -0
  95. package/core/server/registry/registry-response.ts +71 -0
  96. package/core/server/registry/registry-subjects.ts +194 -0
  97. package/core/server/registry/registry-write-pipeline.ts +240 -0
  98. package/core/server/registry/request-body-limit.ts +99 -0
  99. package/core/server/registry/services/apis/Get.ts +25 -0
  100. package/core/server/registry/services/apis/List.ts +41 -0
  101. package/core/server/registry/services/apis/Register.ts +39 -0
  102. package/core/server/registry/services/apis/Unregister.ts +24 -0
  103. package/core/server/registry/services/index.ts +40 -0
  104. package/core/server/registry/services/pages/Get.ts +86 -0
  105. package/core/server/registry/services/pages/List.ts +53 -0
  106. package/core/server/registry/services/pages/Register.ts +49 -0
  107. package/core/server/registry/services/pages/Rollback.ts +36 -0
  108. package/core/server/registry/services/pages/Unregister.ts +23 -0
  109. package/core/server/registry/services/service-utils.ts +21 -0
  110. package/core/server/registry/validation/compile-gate.ts +71 -0
  111. package/core/server/registry/validation/component-existence.ts +55 -0
  112. package/core/server/registry/validation/credential-ban.ts +86 -0
  113. package/core/server/registry/validation/cross-check.ts +77 -0
  114. package/core/server/registry/validation/declaration-safety-scan.ts +102 -0
  115. package/core/shared/types/adaptive.types.ts +109 -0
  116. package/core/shared/types/component-contract.types.ts +110 -0
  117. package/core/shared/types/data-config.types.ts +105 -0
  118. package/core/shared/types/domain.types.ts +6 -0
  119. package/core/shared/types/engine.types.ts +41 -35
  120. package/core/shared/types/manifest.types.ts +55 -32
  121. package/core/shared/types/scope-manifest.types.ts +96 -0
  122. package/core/shared/types/style-config.types.ts +9 -0
  123. package/core/shared/types/ui-config.types.ts +118 -98
  124. package/dist/cli/soma.js +20 -5
  125. package/dist/core/index.cjs +5341 -894
  126. package/dist/types/build/compiler/full-manifest-builder.d.ts +4 -0
  127. package/dist/types/build/compiler/rollup-plugin-soma.d.ts +1 -0
  128. package/dist/types/build/compiler/soma-precompile.d.ts +9 -0
  129. package/dist/types/build/compiler/vite-plugin-soma.d.ts +3 -0
  130. package/dist/types/build/component/package-loader.d.ts +9 -0
  131. package/dist/types/build/eject/apply-eject.d.ts +22 -0
  132. package/dist/types/build/eject/plan-eject.d.ts +32 -0
  133. package/dist/types/client/adaptive/flush-scheduler.d.ts +13 -0
  134. package/dist/types/client/adaptive/hysteresis.d.ts +16 -0
  135. package/dist/types/client/adaptive/index.d.ts +5 -0
  136. package/dist/types/client/adaptive/observer-pool.d.ts +15 -0
  137. package/dist/types/client/base/SomaPageRootBase.d.ts +33 -0
  138. package/dist/types/client/compiler/adaptive-compile.d.ts +26 -0
  139. package/dist/types/client/compiler/manifest-compiler.d.ts +13 -2
  140. package/dist/types/client/component/ai-catalog.d.ts +73 -0
  141. package/dist/types/client/component/component-definition.types.d.ts +54 -0
  142. package/dist/types/client/component/component-expander.d.ts +25 -0
  143. package/dist/types/client/component/component-manager.d.ts +160 -0
  144. package/dist/types/client/component/component-pack.d.ts +90 -0
  145. package/dist/types/client/component/component-registry.d.ts +12 -0
  146. package/dist/types/client/component/pack-styles.d.ts +22 -0
  147. package/dist/types/client/component/scoped-adapter.d.ts +18 -0
  148. package/dist/types/client/component/verify-pack.d.ts +14 -0
  149. package/dist/types/client/data/data-object-resolver.d.ts +71 -0
  150. package/dist/types/client/diagnostics/SomaDiagnostics.d.ts +2 -1
  151. package/dist/types/client/diagnostics/boot-timings.d.ts +30 -0
  152. package/dist/types/client/engine/asset-resolver.d.ts +7 -1
  153. package/dist/types/client/engine/dom-renderer.d.ts +49 -1
  154. package/dist/types/client/engine/emit-event.d.ts +6 -0
  155. package/dist/types/client/engine/event-engine.d.ts +6 -0
  156. package/dist/types/client/engine/render-engine.d.ts +25 -1
  157. package/dist/types/client/engine/runtime-builder.d.ts +7 -0
  158. package/dist/types/client/engine/soma-bootstrap.d.ts +116 -0
  159. package/dist/types/client/observability/error-reporter.d.ts +51 -0
  160. package/dist/types/client/parser/adaptive-parser.d.ts +28 -0
  161. package/dist/types/client/parser/data-config-parser.d.ts +34 -0
  162. package/dist/types/client/parser/pipeline-parser.d.ts +2 -0
  163. package/dist/types/client/parser/style-config-parser.d.ts +5 -3
  164. package/dist/types/client/parser/ui-config-parser.d.ts +22 -1
  165. package/dist/types/client/pipes/pipe-registry.d.ts +38 -0
  166. package/dist/types/client/registry/declaration-renderer.d.ts +51 -0
  167. package/dist/types/client/registry/index.d.ts +10 -0
  168. package/dist/types/client/registry/page-lifecycle.d.ts +61 -0
  169. package/dist/types/client/registry/remote-page.d.ts +52 -0
  170. package/dist/types/client/runtime/SomaRuntimeServices.d.ts +16 -0
  171. package/dist/types/client/security/attribute-presence.d.ts +7 -0
  172. package/dist/types/client/security/html-sanitizer.d.ts +37 -0
  173. package/dist/types/client/security/url-guard.d.ts +11 -0
  174. package/dist/types/client/theme/theme-engine.d.ts +49 -0
  175. package/dist/types/client/typography/typography-base.d.ts +15 -0
  176. package/dist/types/client/validation/contract-validator.d.ts +2 -0
  177. package/dist/types/index.d.ts +36 -2
  178. package/dist/types/server/api/IService.d.ts +18 -6
  179. package/dist/types/server/host/content-security-policy.d.ts +53 -0
  180. package/dist/types/server/host/csp-nonce-metadata.d.ts +32 -0
  181. package/dist/types/server/host/resolve-host-request-hook.d.ts +5 -0
  182. package/dist/types/server/host/server-page-assets.d.ts +5 -0
  183. package/dist/types/server/index.d.ts +4 -1
  184. package/dist/types/server/registry/api-registry-store.d.ts +141 -0
  185. package/dist/types/server/registry/conditional-object-store.d.ts +27 -0
  186. package/dist/types/server/registry/declaration-precompiler.d.ts +30 -0
  187. package/dist/types/server/registry/in-memory-conditional-object-store.d.ts +8 -0
  188. package/dist/types/server/registry/index.d.ts +29 -0
  189. package/dist/types/server/registry/page-registry-repository.d.ts +58 -0
  190. package/dist/types/server/registry/page-registry-store.d.ts +259 -0
  191. package/dist/types/server/registry/registry-error.d.ts +12 -0
  192. package/dist/types/server/registry/registry-file-lock.d.ts +20 -0
  193. package/dist/types/server/registry/registry-response.d.ts +18 -0
  194. package/dist/types/server/registry/registry-subjects.d.ts +59 -0
  195. package/dist/types/server/registry/registry-write-pipeline.d.ts +48 -0
  196. package/dist/types/server/registry/request-body-limit.d.ts +31 -0
  197. package/dist/types/server/registry/services/apis/Get.d.ts +10 -0
  198. package/dist/types/server/registry/services/apis/List.d.ts +10 -0
  199. package/dist/types/server/registry/services/apis/Register.d.ts +13 -0
  200. package/dist/types/server/registry/services/apis/Unregister.d.ts +12 -0
  201. package/dist/types/server/registry/services/index.d.ts +3 -0
  202. package/dist/types/server/registry/services/pages/Get.d.ts +10 -0
  203. package/dist/types/server/registry/services/pages/List.d.ts +13 -0
  204. package/dist/types/server/registry/services/pages/Register.d.ts +11 -0
  205. package/dist/types/server/registry/services/pages/Rollback.d.ts +9 -0
  206. package/dist/types/server/registry/services/pages/Unregister.d.ts +9 -0
  207. package/dist/types/server/registry/services/service-utils.d.ts +10 -0
  208. package/dist/types/server/registry/validation/compile-gate.d.ts +10 -0
  209. package/dist/types/server/registry/validation/component-existence.d.ts +14 -0
  210. package/dist/types/server/registry/validation/credential-ban.d.ts +15 -0
  211. package/dist/types/server/registry/validation/cross-check.d.ts +16 -0
  212. package/dist/types/server/registry/validation/declaration-safety-scan.d.ts +15 -0
  213. package/dist/types/shared/types/adaptive.types.d.ts +88 -0
  214. package/dist/types/shared/types/component-contract.types.d.ts +68 -0
  215. package/dist/types/shared/types/data-config.types.d.ts +81 -0
  216. package/dist/types/shared/types/domain.types.d.ts +6 -0
  217. package/dist/types/shared/types/engine.types.d.ts +6 -0
  218. package/dist/types/shared/types/manifest.types.d.ts +23 -0
  219. package/dist/types/shared/types/scope-manifest.types.d.ts +82 -0
  220. package/dist/types/shared/types/style-config.types.d.ts +8 -0
  221. package/dist/types/shared/types/ui-config.types.d.ts +20 -0
  222. package/global.d.ts +4 -0
  223. package/next.config.js +76 -1
  224. package/package.json +32 -11
  225. package/proxy.ts +62 -0
  226. package/core/client/engine/theme-variables.ts +0 -37
  227. package/dist/tsconfig.types.tsbuildinfo +0 -1
  228. package/dist/types/client/engine/theme-variables.d.ts +0 -3
  229. package/middleware.ts +0 -33
@@ -1,32 +1,55 @@
1
- import type { BindingType } from './engine.types';
2
- import type { ParsedEvent } from './event.types';
3
- import type { SomaTaskPriority } from './scheduler.types';
4
- import type { ShowMapping } from './ui-config.types';
5
-
6
- export interface SomaCompiledBinding {
7
- id: string;
8
- somaId: string;
9
- type: BindingType;
10
- dataPath: string;
11
- watchPaths: string[];
12
- attrName?: string;
13
- negate?: boolean;
14
- classRules?: Record<string, string>;
15
- childShowConfig?: ShowMapping;
16
- /** 静态提升标记:值在初始化后不会变化,不需要注册 watchPaths */
17
- static?: boolean;
18
- }
19
-
20
- export interface SomaCompiledEvent extends ParsedEvent {
21
- eventKey: string;
22
- priority: SomaTaskPriority;
23
- }
24
-
25
- export interface SomaRuntimeManifest {
26
- bindings: SomaCompiledBinding[];
27
- bindingIndex: Map<string, SomaCompiledBinding[]>;
28
- events: SomaCompiledEvent[];
29
- eventIndex: Map<string, SomaCompiledEvent>;
30
- /** 启动时一次性初始化的属性(来自 _ui.yaml initProps) */
31
- initProps?: Record<string, unknown>;
32
- }
1
+ import type { BindingType } from './engine.types';
2
+ import type { ParsedEvent } from './event.types';
3
+ import type { SomaTaskPriority } from './scheduler.types';
4
+ import type { ShowMapping } from './ui-config.types';
5
+ import type { SomaPipeCall } from './scope-manifest.types';
6
+ import type { SomaCompiledAdaptive } from './adaptive.types';
7
+
8
+ export interface SomaCompiledBinding {
9
+ id: string;
10
+ somaId: string;
11
+ type: BindingType;
12
+ dataPath: string;
13
+ watchPaths: string[];
14
+ attrName?: string;
15
+ negate?: boolean;
16
+ classRules?: Record<string, string>;
17
+ childShowConfig?: ShowMapping;
18
+ /** 静态提升标记:值在初始化后不会变化,不需要注册 watchPaths */
19
+ static?: boolean;
20
+ /** 展示格式化管道链(text/attr 绑定专用,见 pipe-registry) */
21
+ pipes?: SomaPipeCall[];
22
+ /** 异构列表模板选择器(行相对路径,list 绑定专用) */
23
+ roleBy?: string;
24
+ }
25
+
26
+ export interface SomaCompiledEvent extends ParsedEvent {
27
+ /**
28
+ * 同锚点同 DOM 事件的多按键候选(仅当一个锚点绑了多个 keyModifier 时出现)。
29
+ * 派发侧按 event.key 从中挑一条;单绑定时不存在此字段,零额外开销。
30
+ */
31
+ keyVariants?: SomaCompiledEvent[];
32
+ eventKey: string;
33
+ priority: SomaTaskPriority;
34
+ /**
35
+ * 组件 emit 路由标记:somaId 为组件实例、domEvent 为契约 emit 名。
36
+ * 标记后不注册 DOM 监听、不响应冒泡 DOM 事件,仅由组件管理器 dispatchEmit 触发;
37
+ * Domain 处理器第二实参为 emit payload(DOM 路由保持 originalEvent)。
38
+ */
39
+ emitRoute?: boolean;
40
+ }
41
+
42
+ export interface SomaRuntimeManifest {
43
+ bindings: SomaCompiledBinding[];
44
+ bindingIndex: Map<string, SomaCompiledBinding[]>;
45
+ events: SomaCompiledEvent[];
46
+ eventIndex: Map<string, SomaCompiledEvent>;
47
+ /** 启动时一次性初始化的属性(来自 _ui.yaml initProps) */
48
+ initProps?: Record<string, unknown>;
49
+ /**
50
+ * 阶梯编译产物(来自 _ui.yaml adaptive)。
51
+ * 未声明 adaptive 时**此字段不存在**(不是空对象、不是 null)——
52
+ * 零破坏保证要求产物字节级不变,写一个空壳就已经破了。
53
+ */
54
+ adaptive?: SomaCompiledAdaptive;
55
+ }
@@ -0,0 +1,96 @@
1
+ import type { SomaCompiledBinding, SomaCompiledEvent, SomaRuntimeManifest } from './manifest.types';
2
+
3
+ /**
4
+ * v2 作用域清单树(组件体系 P0)。
5
+ *
6
+ * 设计规范:soma-core/doc/soma 作用域清单树.md
7
+ * 兼容承诺:v1 清单(SomaRuntimeManifest)长期保留;无组件页面继续走 v1 原路径,
8
+ * 本文件只做类型新增,不修改任何既有类型。
9
+ *
10
+ * 节点结构保持可 JSON 序列化(仅数组/普通对象,无 Map)——构建期产物与
11
+ * 运行期客户端编译产物必须深度相等(规范 7.4),索引一律在运行时装配。
12
+ */
13
+
14
+ export type SomaScopeKind = 'page' | 'list' | 'component';
15
+
16
+ export type SomaPropMode = 'oneway' | 'model';
17
+
18
+ /** 管道实参:字面量,或取值自绑定路径 */
19
+ export interface SomaPipeArg {
20
+ kind: 'literal' | 'binding';
21
+ value: string | number | boolean;
22
+ }
23
+
24
+ /** 格式化管道调用(DSL 扩展规范第 3 章),按声明顺序从左到右执行 */
25
+ export interface SomaPipeCall {
26
+ name: string;
27
+ args?: Record<string, SomaPipeArg>;
28
+ }
29
+
30
+ /** 页面表达式 → 组件契约 prop 的绑定(下行通道) */
31
+ export interface SomaPropBinding {
32
+ prop: string;
33
+ /** 已解析的绑定路径;与 literal 二选一 */
34
+ source?: string;
35
+ literal?: unknown;
36
+ /** 布尔 prop 的 `!` 前缀(沿用 when 语义,不引入其他运算) */
37
+ negate?: boolean;
38
+ mode: SomaPropMode;
39
+ pipes?: SomaPipeCall[];
40
+ }
41
+
42
+ /**
43
+ * 契约 emit → 页面 Pipeline 的路由(上行通道)。
44
+ *
45
+ * 处理器分型(作用域清单树规范 1.1 R2):
46
+ * emit 路由的 Domain 处理器收 (currentVar, payload);
47
+ * DOM 事件路由保持既有 (currentVar, originalEvent),运行时按 kind 分发,不做猜测。
48
+ */
49
+ export interface SomaEmitRoute {
50
+ kind: 'emit';
51
+ emit: string;
52
+ /** 复用既有 Pipeline 编译产物;somaId 为实例锚点 id */
53
+ pipeline: SomaCompiledEvent;
54
+ }
55
+
56
+ /** 组件实例元数据(kind === 'component' 的节点持有) */
57
+ export interface SomaComponentInstanceMeta {
58
+ /** 契约名(PascalCase) */
59
+ name: string;
60
+ /** 契约 semver,升级破坏点定位用(契约规范 C8) */
61
+ version: string;
62
+ props: SomaPropBinding[];
63
+ emits: SomaEmitRoute[];
64
+ /**
65
+ * 插槽内容子树。插槽内容归父(页面/外层)作用域:其 bindings 的数据路径
66
+ * 相对父作用域求值,组件只决定投影位置与显隐(契约规范第 5 章)。
67
+ */
68
+ slots?: Record<string, SomaScopeNode>;
69
+ }
70
+
71
+ export interface SomaScopeNode {
72
+ kind: SomaScopeKind;
73
+ /** page: 页面 base;list/component: 宿主锚点 data-soma-id */
74
+ id: string;
75
+ component?: SomaComponentInstanceMeta;
76
+ /** kind === 'list':行变量名(currentVar 语义与既有列表一致) */
77
+ listVar?: string;
78
+ /** 异构列表模板选择器的绑定路径(DSL 扩展规范 2.1,行模板后缀 = 该路径取值) */
79
+ roleBy?: string;
80
+ /** 本作用域直属锚点的绑定(结构与 v1 逐字段同构) */
81
+ bindings: SomaCompiledBinding[];
82
+ events: SomaCompiledEvent[];
83
+ children: SomaScopeNode[];
84
+ }
85
+
86
+ export interface SomaRuntimeManifestV2 {
87
+ version: 2;
88
+ root: SomaScopeNode;
89
+ initProps?: Record<string, unknown>;
90
+ }
91
+
92
+ export type SomaAnyRuntimeManifest = SomaRuntimeManifest | SomaRuntimeManifestV2;
93
+
94
+ export function isManifestV2(manifest: SomaAnyRuntimeManifest): manifest is SomaRuntimeManifestV2 {
95
+ return (manifest as SomaRuntimeManifestV2).version === 2;
96
+ }
@@ -1,6 +1,15 @@
1
1
  // 样式配置类型定义 — 对应 _style.yaml
2
2
  // 定义 SOMA 框架中样式配置文件的 TypeScript 类型
3
3
 
4
+ /**
5
+ * 样式声明的违规类别(解析期硬校验用)。
6
+ *
7
+ * `layout-class`:`_style.yaml` 里出现了布局组装类。
8
+ * 布局的合法归宿是 HTML 骨架与布局原语;样式配置只承载视觉与显隐。
9
+ * 该类别不设 warn 档、不设开关——开关会立刻制造两份事实("开了的项目"与"没开的项目")。
10
+ */
11
+ export type SomaStyleViolationKind = 'layout-class';
12
+
4
13
  /**
5
14
  * 状态驱动的样式规则
6
15
  * 当 condition 路径的值等于 value 时,将 apply 中的类名应用到对应 DOM 节点
@@ -1,98 +1,118 @@
1
- // UI 配置类型定义 — 对应模块 2
2
- // 定义 SOMA 框架中 _ui.yaml 配置文件的 TypeScript 类型
3
-
4
- import type { OnChangeRule } from './watcher.types';
5
-
6
- /**
7
- * 作用域声明
8
- * 定义数据源路径和当前作用域别名
9
- */
10
- export interface BindDeclaration {
11
- /** 数据源路径。顶层 = Class 标识;嵌套层 = 父 var.属性路径 */
12
- obj: string;
13
- /** 当前层级别名,子层级和事件配置通过此别名引用数据 */
14
- var: string;
15
- /** 属性变化时触发的 Domain 方法(声明式 watch) */
16
- onChange?: OnChangeRule[];
17
- }
18
-
19
- /**
20
- * 展示映射值 - 支持多种绑定类型
21
- *
22
- * 可以是以下形式之一:
23
- * - 简单文本绑定字符串:"var.prop"
24
- * - 嵌套绑定:包含 bind + show 的嵌套结构
25
- * - 扩展绑定:包含 text / model / when / class 等高级绑定
26
- */
27
- export type ShowValue =
28
- | string // 简单文本绑定:"var.prop"
29
- | NestedShowMapping // 嵌套绑定(对象/列表)
30
- | ExtendedShowValue; // 扩展绑定
31
-
32
- /**
33
- * 嵌套展示映射
34
- * 用于对象或列表级别的子作用域绑定
35
- */
36
- export interface NestedShowMapping {
37
- /** 子作用域声明 */
38
- bind: BindDeclaration;
39
- /** 子级展示映射 */
40
- show: ShowMapping;
41
- }
42
-
43
- /**
44
- * 扩展绑定值
45
- * 支持 text、model、when、class 等高级绑定类型
46
- */
47
- export interface ExtendedShowValue {
48
- /** 文本绑定路径 */
49
- text?: string;
50
- /** 双向绑定路径(表单控件) */
51
- model?: string;
52
- /** 条件渲染路径(truthy 显示,"!path" 取反) */
53
- when?: string;
54
- /** CSS 类名动态绑定 { "class-names": "condition-path" } */
55
- class?: Record<string, string>;
56
- /** 子级展示映射 */
57
- show?: ShowMapping;
58
- }
59
-
60
- /**
61
- * 展示映射
62
- * 键为 data-soma-id 属性值,值为 ShowValue
63
- *
64
- * 键的格式:
65
- * - "somaId" — 默认文本绑定
66
- * - "somaId@attr" — 属性绑定(如 somaId@src, somaId@href)
67
- * - "somaId@html" — HTML 内容注入
68
- */
69
- export type ShowMapping = Record<string, ShowValue>;
70
-
71
- /**
72
- * UI 配置顶层结构
73
- * 对应 _ui.yaml 文件的完整结构
74
- */
75
- export interface UiConfig {
76
- /** 顶级作用域声明 */
77
- bind: BindDeclaration;
78
- /** 顶级展示映射 */
79
- show: ShowMapping;
80
- /**
81
- * 初始化属性(引擎启动、Proxy 创建前写入)
82
- * 键为 var 别名路径(如 page.title),值为初始值
83
- */
84
- initProps?: Record<string, unknown>;
85
- }
86
-
87
- /**
88
- * 解析后的 show 条目
89
- * somaId@attr 语法拆分为 somaId + attrName
90
- */
91
- export interface ParsedShowEntry {
92
- /** 纯 data-soma-id(不含 @attr 后缀) */
93
- somaId: string;
94
- /** 属性绑定时的属性名(如 src、href、value) */
95
- attrName?: string;
96
- /** 原始绑定值 */
97
- value: ShowValue;
98
- }
1
+ // UI 配置类型定义 — 对应模块 2
2
+ // 定义 SOMA 框架中 _ui.yaml 配置文件的 TypeScript 类型
3
+
4
+ import type { OnChangeRule } from './watcher.types';
5
+ import type { SomaAdaptiveConfig } from './adaptive.types';
6
+
7
+ /**
8
+ * 作用域声明
9
+ * 定义数据源路径和当前作用域别名
10
+ */
11
+ export interface BindDeclaration {
12
+ /** 数据源路径。顶层 = Class 标识;嵌套层 = 父 var.属性路径 */
13
+ obj: string;
14
+ /** 当前层级别名,子层级和事件配置通过此别名引用数据 */
15
+ var: string;
16
+ /** 属性变化时触发的 Domain 方法(声明式 watch) */
17
+ onChange?: OnChangeRule[];
18
+ /**
19
+ * 异构列表模板选择器(行相对路径,如 msg.type):
20
+ * 取值匹配 <template data-soma-role="item:取值">,无匹配回落 item 默认模板。
21
+ */
22
+ role_by?: string;
23
+ }
24
+
25
+ /**
26
+ * 展示映射值 - 支持多种绑定类型
27
+ *
28
+ * 可以是以下形式之一:
29
+ * - 简单文本绑定字符串:"var.prop"
30
+ * - 嵌套绑定:包含 bind + show 的嵌套结构
31
+ * - 扩展绑定:包含 text / model / when / class 等高级绑定
32
+ */
33
+ export type ShowValue =
34
+ | string // 简单文本绑定:"var.prop"
35
+ | NestedShowMapping // 嵌套绑定(对象/列表)
36
+ | ExtendedShowValue; // 扩展绑定
37
+
38
+ /**
39
+ * 嵌套展示映射
40
+ * 用于对象或列表级别的子作用域绑定
41
+ */
42
+ export interface NestedShowMapping {
43
+ /** 子作用域声明 */
44
+ bind: BindDeclaration;
45
+ /** 子级展示映射 */
46
+ show: ShowMapping;
47
+ /** 整块显隐:与 bind 同处一个配置对象(另起同名键会覆盖列表绑定) */
48
+ when?: string;
49
+ }
50
+
51
+ /**
52
+ * 扩展绑定值
53
+ * 支持 text、model、when、class 等高级绑定类型
54
+ */
55
+ export interface ExtendedShowValue {
56
+ /** 文本绑定路径 */
57
+ text?: string;
58
+ /** 双向绑定路径(表单控件) */
59
+ model?: string;
60
+ /** 条件渲染路径(truthy 显示,"!path" 取反) */
61
+ when?: string;
62
+ /** CSS 类名动态绑定 { "class-names": "condition-path" } */
63
+ class?: Record<string, string>;
64
+ /** 子级展示映射 */
65
+ show?: ShowMapping;
66
+ /**
67
+ * 组件实例 props(键为契约 prop 名)。
68
+ * 值:绑定路径字符串 / 字面量 / 一层嵌套对象与数组(字段值递归同规则)。
69
+ * 仅当锚点元素带 data-soma-component 时生效。
70
+ */
71
+ props?: Record<string, unknown>;
72
+ }
73
+
74
+ /**
75
+ * 展示映射
76
+ * 键为 data-soma-id 属性值,值为 ShowValue
77
+ *
78
+ * 键的格式:
79
+ * - "somaId" — 默认文本绑定
80
+ * - "somaId@attr" — 属性绑定(如 somaId@src, somaId@href)
81
+ * - "somaId@html" — HTML 内容注入
82
+ */
83
+ export type ShowMapping = Record<string, ShowValue>;
84
+
85
+ /**
86
+ * UI 配置顶层结构
87
+ * 对应 _ui.yaml 文件的完整结构
88
+ */
89
+ export interface UiConfig {
90
+ /** 顶级作用域声明 */
91
+ bind: BindDeclaration;
92
+ /** 顶级展示映射 */
93
+ show: ShowMapping;
94
+ /**
95
+ * 初始化属性(引擎启动、Proxy 创建前写入)
96
+ * 键为 var 别名路径(如 page.title),值为初始值
97
+ */
98
+ initProps?: Record<string, unknown>;
99
+ /**
100
+ * 降级阶梯声明(保留键,可选)。
101
+ * **未声明时编译产物与迁移前字节级一致**——这是零破坏保证的实现锚点,
102
+ * 所以此键必须保持可选,且缺席时不得在下游产生任何默认值。
103
+ */
104
+ adaptive?: SomaAdaptiveConfig;
105
+ }
106
+
107
+ /**
108
+ * 解析后的 show 条目
109
+ * somaId@attr 语法拆分为 somaId + attrName
110
+ */
111
+ export interface ParsedShowEntry {
112
+ /** 纯 data-soma-id(不含 @attr 后缀) */
113
+ somaId: string;
114
+ /** 属性绑定时的属性名(如 src、href、value) */
115
+ attrName?: string;
116
+ /** 原始绑定值 */
117
+ value: ShowValue;
118
+ }
package/dist/cli/soma.js CHANGED
@@ -9,7 +9,7 @@ const node_fs_1 = __importDefault(require("node:fs"));
9
9
  const node_path_1 = __importDefault(require("node:path"));
10
10
  const args = process.argv.slice(2);
11
11
  const command = args[0] || 'dev';
12
- const delegated = ['doctor', 'sync', 'lsp', 'codegen', 'init', 'package-vscode'];
12
+ const delegated = ['doctor', 'sync', 'lsp', 'codegen', 'init', 'package-vscode', 'eject'];
13
13
  const packageRoot = node_path_1.default.resolve(__dirname, '../..');
14
14
  if (command === 'db') {
15
15
  const child = (0, node_child_process_1.spawnSync)(process.execPath, [node_path_1.default.join(packageRoot, 'bin', 'soma-db.cjs'), ...args.slice(1)], { cwd: process.cwd(), stdio: 'inherit', env: process.env });
@@ -395,7 +395,10 @@ function ensureNextWorkspace(hostDir) {
395
395
  writeFileIfChanged(node_path_1.default.join(workspaceDir, 'package.json'), JSON.stringify({ private: true, name: 'soma-next-workspace' }, null, 2) + '\n');
396
396
  copyDirectory(node_path_1.default.join(packageRoot, 'app'), node_path_1.default.join(workspaceDir, 'app'));
397
397
  linkOrCopy(node_path_1.default.join(packageRoot, 'core'), node_path_1.default.join(workspaceDir, 'core'), 'dir');
398
- linkOrCopy(node_path_1.default.join(packageRoot, 'middleware.ts'), node_path_1.default.join(workspaceDir, 'middleware.ts'), 'file');
398
+ const legacyMiddleware = node_path_1.default.join(workspaceDir, 'middleware.ts');
399
+ if (lstatIfPresent(legacyMiddleware))
400
+ node_fs_1.default.unlinkSync(legacyMiddleware);
401
+ linkOrCopy(node_path_1.default.join(packageRoot, 'proxy.ts'), node_path_1.default.join(workspaceDir, 'proxy.ts'), 'file');
399
402
  linkOrCopy(node_path_1.default.join(packageRoot, 'postcss.config.js'), node_path_1.default.join(workspaceDir, 'postcss.config.js'), 'file');
400
403
  linkOrCopy(node_path_1.default.join(packageRoot, 'tailwind.config.ts'), node_path_1.default.join(workspaceDir, 'tailwind.config.ts'), 'file');
401
404
  linkOrCopy(node_path_1.default.join(packageRoot, 'global.d.ts'), node_path_1.default.join(workspaceDir, 'global.d.ts'), 'file');
@@ -406,11 +409,16 @@ function ensureNextWorkspace(hostDir) {
406
409
  return workspaceDir;
407
410
  }
408
411
  if (delegated.includes(command)) {
409
- const inline = node_path_1.default.join(__dirname, 'soma-inline.cjs');
412
+ // 用 packageRoot 而不是 __dirname:编译产物在 dist/cli/ 下,那里没有 soma-inline.cjs,
413
+ // 于是全部 delegated 命令(doctor/sync/lsp/codegen/init/eject)一走 dist 就报
414
+ // "Cannot find module"。源码目录跑得通、装出去就坏,是最难发现的一类路径 bug。
415
+ const inline = node_path_1.default.join(packageRoot, 'bin', 'soma-inline.cjs');
410
416
  const child = (0, node_child_process_1.spawnSync)(process.execPath, [inline, command, ...args.slice(1)], {
411
417
  cwd: packageRoot,
412
418
  stdio: 'inherit',
413
- env: process.env,
419
+ // 委派要以包根为 cwd(内联实现按包根解析自己的资源),但**调用方的 cwd 不能丢**:
420
+ // eject 这类命令作用于"我现在所在的宿主目录",丢了它就会去 soma-core 里找宿主。
421
+ env: { ...process.env, SOMA_INVOKE_CWD: process.cwd() },
414
422
  });
415
423
  process.exit(child.status === null ? 1 : child.status);
416
424
  }
@@ -425,7 +433,14 @@ if (!nextBin) {
425
433
  }
426
434
  const hostDir = node_path_1.default.resolve(process.cwd());
427
435
  const nextWorkspace = ensureNextWorkspace(hostDir);
428
- const child = (0, node_child_process_1.spawnSync)(process.execPath, [nextBin, command, nextWorkspace, ...args.slice(1)], {
436
+ const nextArgs = [
437
+ nextBin,
438
+ command,
439
+ nextWorkspace,
440
+ ...((command === 'dev' || command === 'build') ? ['--webpack'] : []),
441
+ ...args.slice(1),
442
+ ];
443
+ const child = (0, node_child_process_1.spawnSync)(process.execPath, nextArgs, {
429
444
  cwd: nextWorkspace,
430
445
  stdio: 'inherit',
431
446
  env: {