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
@@ -6,6 +6,8 @@ import { parseUiConfig } from '../../client/parser/ui-config-parser';
6
6
  import { parseEventConfig } from '../../client/parser/pipeline-parser';
7
7
  import { splitEventConfigRaw } from '../../client/parser/trigger-parser';
8
8
  import { parseStyleConfig } from '../../client/parser/style-config-parser';
9
+ import { parseDataConfig } from '../../client/parser/data-config-parser';
10
+ import type { SomaDataConfig } from '../../shared/types/data-config.types';
9
11
  import type { UiConfig } from '../../shared/types/ui-config.types';
10
12
  import type { ParsedEvent } from '../../shared/types/event.types';
11
13
  import type { PropertyTrigger } from '../../shared/types/trigger.types';
@@ -20,12 +22,22 @@ export interface CompiledEventConfig {
20
22
  }
21
23
  import type { StyleConfig } from '../../shared/types/style-config.types';
22
24
 
25
+ /**
26
+ * 构建期解析选项。
27
+ *
28
+ * 词汇不作要求:预编译发生在宿主 bootstrap 加载之前,阶梯词汇表无处可取。
29
+ * `adaptive` 的结构校验(级数 / 单键 / pin 冲突 / profile)在此照常执行,
30
+ * 只有"级值是否在词汇表内"这一项推迟到运行期 `compileAdaptive`——
31
+ * 那一刻词汇必然在手,报错与指路口径完全相同。
32
+ */
33
+ const PRECOMPILE_PARSE_OPTIONS = { adaptiveVocabularyRequired: false } as const;
34
+
23
35
  /**
24
36
  * 预编译 UI YAML → JSON 字符串
25
37
  */
26
38
  export function precompileUiYaml(yamlStr: string): string {
27
39
  const raw = yaml.load(yamlStr);
28
- const uiConfig = parseUiConfig(raw);
40
+ const uiConfig = parseUiConfig(raw, PRECOMPILE_PARSE_OPTIONS);
29
41
  return JSON.stringify(uiConfig);
30
42
  }
31
43
 
@@ -54,7 +66,7 @@ export function precompileStyleYaml(yamlStr: string): string {
54
66
  * 预编译 UI YAML → UiConfig 对象
55
67
  */
56
68
  export function compileUiConfig(yamlStr: string): UiConfig {
57
- return parseUiConfig(yaml.load(yamlStr));
69
+ return parseUiConfig(yaml.load(yamlStr), PRECOMPILE_PARSE_OPTIONS);
58
70
  }
59
71
 
60
72
  /**
@@ -85,6 +97,23 @@ export function compileStyleConfig(yamlStr: string): StyleConfig | undefined {
85
97
  return parseStyleConfig(raw);
86
98
  }
87
99
 
100
+ /**
101
+ * 预编译 Data YAML(数据对象层声明)→ SomaDataConfig 对象
102
+ */
103
+ export function compileDataConfig(yamlStr: string): SomaDataConfig {
104
+ if (!yamlStr.trim()) {
105
+ return { objects: {} };
106
+ }
107
+ return parseDataConfig(yaml.load(yamlStr));
108
+ }
109
+
110
+ /**
111
+ * 预编译 Data YAML(数据对象层声明)→ JSON 字符串
112
+ */
113
+ export function precompileDataYaml(yamlStr: string): string {
114
+ return JSON.stringify(compileDataConfig(yamlStr));
115
+ }
116
+
88
117
  /**
89
118
  * 预编译任意 YAML → JSON 字符串(locale、app.config 等纯数据配置)
90
119
  */
@@ -2,6 +2,7 @@ const {
2
2
  precompileUiYaml,
3
3
  precompileEventYaml,
4
4
  precompileStyleYaml,
5
+ precompileDataYaml,
5
6
  precompileYaml,
6
7
  } = require('./soma-precompile');
7
8
 
@@ -10,12 +11,14 @@ module.exports = function somaRspackYamlLoader(source) {
10
11
  const uiSuffix = options.uiSuffix ?? '_ui.yaml';
11
12
  const eventSuffix = options.eventSuffix ?? '_event.yaml';
12
13
  const styleSuffix = options.styleSuffix ?? '_style.yaml';
14
+ const dataSuffix = options.dataSuffix ?? '_data.yaml';
13
15
  const resourcePath = this.resourcePath ?? '';
14
16
 
15
17
  let compiled;
16
18
  if (resourcePath.endsWith(uiSuffix)) compiled = precompileUiYaml(source);
17
19
  else if (resourcePath.endsWith(eventSuffix)) compiled = precompileEventYaml(source);
18
20
  else if (resourcePath.endsWith(styleSuffix)) compiled = precompileStyleYaml(source);
21
+ else if (resourcePath.endsWith(dataSuffix)) compiled = precompileDataYaml(source);
19
22
  else compiled = precompileYaml(source);
20
23
 
21
24
  return `export default ${compiled};`;
@@ -7,7 +7,7 @@ module.exports = function somaWebpackLoader(source) {
7
7
  const resourcePath = this.resourcePath;
8
8
 
9
9
  try {
10
- const { precompileUiYaml, precompileEventYaml, precompileStyleYaml, precompileYaml } = require('./soma-precompile');
10
+ const { precompileUiYaml, precompileEventYaml, precompileStyleYaml, precompileDataYaml, precompileYaml } = require('./soma-precompile');
11
11
 
12
12
  // SOMA UI 配置
13
13
  if (resourcePath.endsWith('_ui.yaml')) {
@@ -27,6 +27,12 @@ module.exports = function somaWebpackLoader(source) {
27
27
  return `export default ${compiled};`;
28
28
  }
29
29
 
30
+ // SOMA Data 配置(数据对象层,可选件)
31
+ if (resourcePath.endsWith('_data.yaml')) {
32
+ const compiled = precompileDataYaml(source);
33
+ return `export default ${compiled};`;
34
+ }
35
+
30
36
  // 通用 YAML(locale、app.config 等)
31
37
  if (resourcePath.endsWith('.yaml') || resourcePath.endsWith('.yml')) {
32
38
  const compiled = precompileYaml(source);
@@ -2,7 +2,7 @@
2
2
  // Vite 预编译插件:在构建阶段将所有声明式 YAML 配置编译为 JS 模块
3
3
 
4
4
  import type { Plugin } from 'vite';
5
- import { precompileUiYaml, precompileEventYaml, precompileStyleYaml, precompileYaml } from './soma-precompile';
5
+ import { precompileUiYaml, precompileEventYaml, precompileStyleYaml, precompileDataYaml, precompileYaml } from './soma-precompile';
6
6
 
7
7
  export interface SomaPluginOptions {
8
8
  /** UI 配置文件后缀,默认 _ui.yaml */
@@ -11,6 +11,8 @@ export interface SomaPluginOptions {
11
11
  eventSuffix?: string;
12
12
  /** 样式配置文件后缀,默认 _style.yaml */
13
13
  styleSuffix?: string;
14
+ /** 数据对象层配置文件后缀,默认 _data.yaml */
15
+ dataSuffix?: string;
14
16
  }
15
17
 
16
18
  /**
@@ -23,6 +25,7 @@ export interface SomaPluginOptions {
23
25
  * - `_ui.yaml` → UiConfig 对象(parseUiConfig 预编译)
24
26
  * - `_event.yaml` → ParsedEvent[] 数组(parseEventConfig 预编译)
25
27
  * - `_style.yaml` → StyleConfig 对象(parseStyleConfig 预编译)
28
+ * - `_data.yaml` → SomaDataConfig 对象(parseDataConfig 预编译)
26
29
  * - `locale.yaml` → Record<string, unknown>
27
30
  * - `*.config.yaml` → 任意配置对象
28
31
  * - 其他 `.yaml` → 通用 YAML → JS 对象
@@ -41,6 +44,7 @@ export function somaPlugin(options: SomaPluginOptions = {}): Plugin {
41
44
  const uiSuffix = options.uiSuffix ?? '_ui.yaml';
42
45
  const eventSuffix = options.eventSuffix ?? '_event.yaml';
43
46
  const styleSuffix = options.styleSuffix ?? '_style.yaml';
47
+ const dataSuffix = options.dataSuffix ?? '_data.yaml';
44
48
 
45
49
  return {
46
50
  name: 'vite-plugin-soma',
@@ -70,6 +74,12 @@ export function somaPlugin(options: SomaPluginOptions = {}): Plugin {
70
74
  return { code: `export default ${compiled};`, map: null };
71
75
  }
72
76
 
77
+ // SOMA Data 配置(数据对象层,可选件)
78
+ if (id.endsWith(dataSuffix)) {
79
+ const compiled = precompileDataYaml(code);
80
+ return { code: `export default ${compiled};`, map: null };
81
+ }
82
+
73
83
  // 通用 YAML(locale、app.config 等)
74
84
  const compiled = precompileYaml(code);
75
85
  return { code: `export default ${compiled};`, map: null };
@@ -0,0 +1,135 @@
1
+ // 组件包文件态加载器(P1 尾款,契约规范第 1/12 章):
2
+ //
3
+ // components/qty-stepper/
4
+ // contract.yaml 必需(唯一事实源)
5
+ // template.html 必需
6
+ // ui.yaml 可选(内部绑定,作用域根 p/ctrl)
7
+ // event.yaml 可选(内部事件 Pipeline)
8
+ //
9
+ // 装载为 SomaComponentDefinition,供 Host bootstrap 注册。声明式组件(无控制器)
10
+ // 可全文件态交付——这是"AI 自产组件落盘即用"生长层的文件通道;
11
+ // 需要控制器逻辑的组件仍用 TS 形态(controllerFactory)。
12
+
13
+ import fs from 'node:fs';
14
+ import path from 'node:path';
15
+ import yaml from 'js-yaml';
16
+ import { parseUiConfig } from '../../client/parser/ui-config-parser';
17
+ import { parseEventConfig } from '../../client/parser/pipeline-parser';
18
+ import {
19
+ findNestedMutableContractDefault,
20
+ type SomaComponentContract,
21
+ } from '../../shared/types/component-contract.types';
22
+ import type { SomaComponentDefinition } from '../../client/component/component-definition.types';
23
+
24
+ export class SomaComponentPackageError extends Error {
25
+ constructor(message: string, readonly packageDir: string) {
26
+ super(`[SomaComponentPackage] ${message}(组件包: ${packageDir})`);
27
+ this.name = 'SomaComponentPackageError';
28
+ }
29
+ }
30
+
31
+ const LAYERS = new Set(['atom', 'composite', 'solution', 'template']);
32
+
33
+ /** 装载单个组件包目录 → 运行时定义(结构校验 fail fast) */
34
+ export function loadComponentPackage(packageDir: string): SomaComponentDefinition {
35
+ const contractPath = path.join(packageDir, 'contract.yaml');
36
+ const templatePath = path.join(packageDir, 'template.html');
37
+
38
+ if (!fs.existsSync(contractPath)) {
39
+ throw new SomaComponentPackageError('缺少 contract.yaml', packageDir);
40
+ }
41
+ if (!fs.existsSync(templatePath)) {
42
+ throw new SomaComponentPackageError('缺少 template.html', packageDir);
43
+ }
44
+
45
+ const rawContract = yaml.load(fs.readFileSync(contractPath, 'utf-8'));
46
+ const contract = validateContract(rawContract, packageDir);
47
+
48
+ const templateHtml = fs.readFileSync(templatePath, 'utf-8').trim();
49
+ if (!templateHtml) {
50
+ throw new SomaComponentPackageError('template.html 为空', packageDir);
51
+ }
52
+
53
+ const definition: SomaComponentDefinition = { contract, templateHtml };
54
+
55
+ const uiPath = path.join(packageDir, 'ui.yaml');
56
+ if (fs.existsSync(uiPath)) {
57
+ try {
58
+ definition.uiConfig = parseUiConfig(yaml.load(fs.readFileSync(uiPath, 'utf-8')));
59
+ } catch (error) {
60
+ throw new SomaComponentPackageError(`ui.yaml 非法: ${(error as Error).message}`, packageDir);
61
+ }
62
+ }
63
+
64
+ const eventPath = path.join(packageDir, 'event.yaml');
65
+ if (fs.existsSync(eventPath)) {
66
+ try {
67
+ const rawEvents = yaml.load(fs.readFileSync(eventPath, 'utf-8'));
68
+ definition.eventConfig = parseEventConfig((rawEvents ?? {}) as Record<string, never>);
69
+ } catch (error) {
70
+ throw new SomaComponentPackageError(`event.yaml 非法: ${(error as Error).message}`, packageDir);
71
+ }
72
+ }
73
+
74
+ const servicesRaw = (rawContract as { autonomous?: { services?: unknown } })?.autonomous?.services;
75
+ if (Array.isArray(servicesRaw)) {
76
+ definition.services = servicesRaw.map(String);
77
+ }
78
+
79
+ return definition;
80
+ }
81
+
82
+ /** 扫描根目录下的全部组件包(含 contract.yaml 的一级子目录) */
83
+ export function loadComponentPackages(rootDir: string): Record<string, SomaComponentDefinition> {
84
+ if (!fs.existsSync(rootDir)) {
85
+ return {};
86
+ }
87
+ const result: Record<string, SomaComponentDefinition> = {};
88
+ for (const entry of fs.readdirSync(rootDir, { withFileTypes: true })) {
89
+ if (!entry.isDirectory()) continue;
90
+ const dir = path.join(rootDir, entry.name);
91
+ if (!fs.existsSync(path.join(dir, 'contract.yaml'))) continue;
92
+ const def = loadComponentPackage(dir);
93
+ result[def.contract.name] = def;
94
+ }
95
+ return result;
96
+ }
97
+
98
+ function validateContract(raw: unknown, packageDir: string): SomaComponentContract {
99
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
100
+ throw new SomaComponentPackageError('contract.yaml 必须是对象', packageDir);
101
+ }
102
+ const contract = raw as Record<string, unknown>;
103
+
104
+ for (const field of ['name', 'layer', 'version', 'description'] as const) {
105
+ if (typeof contract[field] !== 'string' || !contract[field]) {
106
+ throw new SomaComponentPackageError(`契约缺少必填字段 ${field}`, packageDir);
107
+ }
108
+ }
109
+ if (!/^[A-Z][A-Za-z0-9]*$/.test(String(contract.name))) {
110
+ throw new SomaComponentPackageError(`契约 name "${contract.name}" 必须是 PascalCase`, packageDir);
111
+ }
112
+ if (!LAYERS.has(String(contract.layer))) {
113
+ throw new SomaComponentPackageError(`契约 layer "${contract.layer}" 非法(atom|composite|template)`, packageDir);
114
+ }
115
+
116
+ // C1/C4:props 需 desc;可选 prop 必须有 default
117
+ for (const [propName, propRaw] of Object.entries((contract.props as Record<string, unknown>) ?? {})) {
118
+ const prop = propRaw as Record<string, unknown> | null;
119
+ if (!prop || typeof prop !== 'object' || typeof prop.type !== 'string') {
120
+ throw new SomaComponentPackageError(`prop "${propName}" 缺少 type`, packageDir);
121
+ }
122
+ if (prop.required !== true && prop.default === undefined) {
123
+ throw new SomaComponentPackageError(`可选 prop "${propName}" 缺少 default(契约规则 C4)`, packageDir);
124
+ }
125
+ const nestedMutablePath = findNestedMutableContractDefault(prop.default);
126
+ if (nestedMutablePath) {
127
+ throw new SomaComponentPackageError(
128
+ `prop "${propName}" default.${nestedMutablePath} 是嵌套可变默认值(契约规则 C4a)`,
129
+ packageDir,
130
+ );
131
+ }
132
+ }
133
+
134
+ return contract as unknown as SomaComponentContract;
135
+ }
@@ -0,0 +1,133 @@
1
+ // 固化的落盘与回滚。
2
+ //
3
+ // 固化最危险的失败不是"没写成",而是**写了一半**:三个文件写进去、第四个撞了名字,
4
+ // 宿主目录从此半新半旧,而 git status 里躺着一堆看不出来历的文件。
5
+ // 所以这里的顺序是死的:
6
+ // 1. 全部目标路径先查一遍冲突(默认撞名即整体中止,不写任何一个字节);
7
+ // 2. 一次性写完;
8
+ // 3. 调用方跑校验(测试/构建),不过就调 rollback —— 把这次写的**全部**删掉,
9
+ // 连中途建出来的空目录也一并清理。
10
+ //
11
+ // 回滚只删这次新建的东西:覆盖模式下被改写的既有文件会先备份、回滚时按原样还回去。
12
+ // 换句话说,固化失败之后,宿主目录应当与固化之前一字不差。
13
+
14
+ import fs from 'node:fs';
15
+ import path from 'node:path';
16
+ import type { EjectFile, EjectPlan } from './plan-eject';
17
+
18
+ export class EjectApplyError extends Error {}
19
+
20
+ export interface ApplyEjectOptions {
21
+ /** 宿主根目录 */
22
+ hostDir: string;
23
+ /** 覆盖既有文件(默认 false:撞名即整体中止) */
24
+ force?: boolean;
25
+ }
26
+
27
+ export interface EjectApplyResult {
28
+ /** 实际写入的文件(相对宿主根) */
29
+ written: string[];
30
+ /** 被覆盖的既有文件(force 模式下才可能非空) */
31
+ overwritten: string[];
32
+ /** 撤销这次固化:新建的删掉、覆盖的还原、空目录清理 */
33
+ rollback(): void;
34
+ }
35
+
36
+ interface Backup {
37
+ absolute: string;
38
+ /** 既有内容;新建文件为 null */
39
+ previous: string | null;
40
+ /** 为写这个文件而新建的目录(从深到浅),回滚时逐个尝试删除 */
41
+ createdDirs: string[];
42
+ }
43
+
44
+ function conflictsOf(plan: EjectPlan, hostDir: string): string[] {
45
+ return plan.files
46
+ .filter((file) => fs.existsSync(path.join(hostDir, file.path)))
47
+ .map((file) => file.path);
48
+ }
49
+
50
+ /** 建目录并记下"这次新建了哪些层",供回滚清理 */
51
+ function ensureDir(dir: string): string[] {
52
+ const created: string[] = [];
53
+ let current = dir;
54
+ const missing: string[] = [];
55
+ while (!fs.existsSync(current)) {
56
+ missing.push(current);
57
+ const parent = path.dirname(current);
58
+ if (parent === current) break;
59
+ current = parent;
60
+ }
61
+ for (const target of [...missing].reverse()) {
62
+ fs.mkdirSync(target);
63
+ created.push(target);
64
+ }
65
+ return created.reverse();
66
+ }
67
+
68
+ /**
69
+ * 落盘一个固化计划。返回句柄带 rollback——校验不过时调它,
70
+ * 宿主目录回到固化之前的样子。
71
+ */
72
+ export function applyEject(plan: EjectPlan, options: ApplyEjectOptions): EjectApplyResult {
73
+ const hostDir = path.resolve(options.hostDir);
74
+ if (!fs.existsSync(hostDir)) {
75
+ throw new EjectApplyError(`宿主目录不存在:${hostDir}`);
76
+ }
77
+ const conflicts = conflictsOf(plan, hostDir);
78
+ if (conflicts.length > 0 && !options.force) {
79
+ throw new EjectApplyError(
80
+ `以下文件已存在,拒绝固化(不覆盖是默认行为,确认要盖再加 --force):\n ${conflicts.join('\n ')}`,
81
+ );
82
+ }
83
+
84
+ const backups: Backup[] = [];
85
+ const written: string[] = [];
86
+ const overwritten: string[] = [];
87
+
88
+ const undo = (): void => {
89
+ // 逆序还原:先写的后撤,目录清理才不会被后写的文件挡住
90
+ for (const backup of [...backups].reverse()) {
91
+ try {
92
+ if (backup.previous === null) {
93
+ fs.rmSync(backup.absolute, { force: true });
94
+ } else {
95
+ fs.writeFileSync(backup.absolute, backup.previous, 'utf8');
96
+ }
97
+ for (const dir of backup.createdDirs) {
98
+ try {
99
+ fs.rmdirSync(dir);
100
+ } catch {
101
+ // 目录非空(别的东西也在用)就留着——回滚只撤自己造的
102
+ }
103
+ }
104
+ } catch {
105
+ // 单个文件撤不掉不该让整个回滚停下;剩下的继续撤
106
+ }
107
+ }
108
+ };
109
+
110
+ try {
111
+ for (const file of plan.files as EjectFile[]) {
112
+ const absolute = path.join(hostDir, file.path);
113
+ const createdDirs = ensureDir(path.dirname(absolute));
114
+ const existed = fs.existsSync(absolute);
115
+ backups.push({
116
+ absolute,
117
+ previous: existed ? fs.readFileSync(absolute, 'utf8') : null,
118
+ createdDirs,
119
+ });
120
+ fs.writeFileSync(absolute, file.contents, 'utf8');
121
+ written.push(file.path);
122
+ if (existed) overwritten.push(file.path);
123
+ }
124
+ } catch (error) {
125
+ // 写到一半炸了:立刻撤干净再抛。半新半旧的宿主目录比失败本身更难收拾。
126
+ undo();
127
+ throw error instanceof Error
128
+ ? new EjectApplyError(`固化写入失败,已回滚:${error.message}`)
129
+ : new EjectApplyError('固化写入失败,已回滚');
130
+ }
131
+
132
+ return { written, overwritten, rollback: undo };
133
+ }
@@ -0,0 +1,139 @@
1
+ // 固化(eject):把运行态的页面声明变回开发态的源码文件。
2
+ //
3
+ // 两态模型(REQ-002 §1)里,运行态页面按名寻址、不占 URL;要独立 URL 的**唯一**路径
4
+ // 就是固化成 html + ts 源码,进 git、走文件路由——从此它归开发态管辖,
5
+ // 受全仓闸门看守、随版本管理,与人手写的页面再无区别。
6
+ //
7
+ // 这个模块只做**规划**,不碰磁盘:输入声明与页面名,输出"该写哪些文件、内容是什么"。
8
+ // 写盘、跑校验、回滚、提交都是 CLI 的事。分开的理由很实际——固化最危险的部分
9
+ // 是"写了一半",而一个纯函数的规划器可以先把全部产物算出来、全部检查完,
10
+ // 再由调用方一次性落盘。
11
+ //
12
+ // 命名约定(与 Next Host 的文件寻址一致,见 server-page-assets):
13
+ // 页面名 order-board → html/order-board.html · ui/order-board_ui.yaml
14
+ // · event/order-board_event.yaml · domain/ui/order-boardClass.ts
15
+ // Domain 类名 OrderBoardPage,必须与 html 的 data-soma-host 一致。
16
+
17
+ /** 页面名:小写字母/数字/连字符——它同时是文件名与 URL 片段 */
18
+ export const EJECT_NAME_PATTERN = /^[a-z0-9-]{1,64}$/;
19
+
20
+ export interface EjectDeclaration {
21
+ html: string;
22
+ uiYaml: string;
23
+ eventYaml?: string;
24
+ styleYaml?: string;
25
+ dataYaml?: string;
26
+ }
27
+
28
+ export interface EjectFile {
29
+ /** 相对宿主根目录的路径 */
30
+ path: string;
31
+ contents: string;
32
+ }
33
+
34
+ export interface EjectPlan {
35
+ /** 页面名(URL 片段与文件名) */
36
+ name: string;
37
+ /** Domain 类名,已写进 html 的 data-soma-host 与 ui 的 bind.obj */
38
+ domainClass: string;
39
+ /** 固化后可访问的 URL */
40
+ url: string;
41
+ files: EjectFile[];
42
+ }
43
+
44
+ export class EjectPlanError extends Error {}
45
+
46
+ /** order-board → OrderBoardPage */
47
+ export function domainClassNameOf(name: string): string {
48
+ const pascal = name
49
+ .split('-')
50
+ .filter(Boolean)
51
+ .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
52
+ .join('');
53
+ return pascal.endsWith('Page') ? pascal : `${pascal}Page`;
54
+ }
55
+
56
+ /**
57
+ * 把声明里的宿主类名换成固化后的类名。
58
+ *
59
+ * 为什么必须换:运行态声明的 host 是通道给的占位(PreviewPageRoot / GeneratedPage),
60
+ * 固化后页面有了自己的 Domain 类,html 的 data-soma-host 与 _ui.yaml 的 bind.obj
61
+ * 必须与类名三处一致——差一处,页面加载时就是"Domain class missing"。
62
+ */
63
+ function rewriteHost(html: string, domainClass: string): { html: string; previous: string } {
64
+ const match = html.match(/data-soma-host="([^"]+)"/);
65
+ if (!match) {
66
+ throw new EjectPlanError('声明的 html 缺少 data-soma-host——它不是一份完整的页面声明');
67
+ }
68
+ return {
69
+ html: html.replace(/data-soma-host="[^"]+"/, `data-soma-host="${domainClass}"`),
70
+ previous: match[1],
71
+ };
72
+ }
73
+
74
+ /** 把 _ui.yaml 的 bind.obj 换成固化后的类名(flow 与块两种写法都认) */
75
+ function rewriteBind(uiYaml: string, previousHost: string, domainClass: string): string {
76
+ if (previousHost === domainClass) return uiYaml;
77
+ const escaped = previousHost.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
78
+ const flow = new RegExp(`(bind:\\s*\\{[^}]*obj:\\s*)${escaped}\\b`);
79
+ if (flow.test(uiYaml)) return uiYaml.replace(flow, `$1${domainClass}`);
80
+ const block = new RegExp(`(bind:[\\s\\S]*?\\n\\s*obj:\\s*)${escaped}\\b`);
81
+ if (block.test(uiYaml)) return uiYaml.replace(block, `$1${domainClass}`);
82
+ throw new EjectPlanError(
83
+ `_ui.yaml 的 bind.obj 不是 "${previousHost}"——html 与 ui 的宿主对不上,拒绝固化`,
84
+ );
85
+ }
86
+
87
+ /** 最小 Domain 类:固化后的页面从这里开始长业务代码 */
88
+ function domainSource(name: string, domainClass: string): string {
89
+ return [
90
+ `// ${name} —— 由 \`soma eject\` 从运行态声明固化而来。`,
91
+ '//',
92
+ '// 固化的意思是:这一页从此归开发态管辖——进 git、走文件路由、受全仓闸门看守,',
93
+ '// 与人手写的页面再无区别。声明里的数据先前来自 initProps 或数据对象层;',
94
+ '// 要接真业务逻辑,就在这个类里写(事件处理、取数编排、跳转)。',
95
+ '',
96
+ "import { SomaPageRootBase } from 'soma-core/base';",
97
+ '',
98
+ `export default class ${domainClass} extends SomaPageRootBase {`,
99
+ ' // 事件在 _event.yaml 里绑到这里的方法上;先留空,按需要添加。',
100
+ '}',
101
+ '',
102
+ ].join('\n');
103
+ }
104
+
105
+ /**
106
+ * 规划一次固化。不碰磁盘——产出"该写哪些文件、内容是什么",
107
+ * 由调用方检查冲突、一次性落盘、失败时整体回滚。
108
+ */
109
+ export function planEject(name: string, declaration: EjectDeclaration): EjectPlan {
110
+ if (!EJECT_NAME_PATTERN.test(name)) {
111
+ throw new EjectPlanError('页面名必须匹配 [a-z0-9-]{1,64}(它同时是文件名与 URL 片段)');
112
+ }
113
+ if (!declaration?.html?.trim() || !declaration?.uiYaml?.trim()) {
114
+ throw new EjectPlanError('声明缺少 html 或 uiYaml,不是一份可固化的页面');
115
+ }
116
+ const domainClass = domainClassNameOf(name);
117
+ const { html, previous } = rewriteHost(declaration.html, domainClass);
118
+ const uiYaml = rewriteBind(declaration.uiYaml, previous, domainClass);
119
+
120
+ const files: EjectFile[] = [
121
+ { path: `html/${name}.html`, contents: ensureTrailingNewline(html) },
122
+ { path: `ui/${name}_ui.yaml`, contents: ensureTrailingNewline(uiYaml) },
123
+ { path: `domain/ui/${name}Class.ts`, contents: domainSource(name, domainClass) },
124
+ ];
125
+ if (declaration.eventYaml?.trim()) {
126
+ files.push({ path: `event/${name}_event.yaml`, contents: ensureTrailingNewline(declaration.eventYaml) });
127
+ }
128
+ if (declaration.styleYaml?.trim()) {
129
+ files.push({ path: `ui/${name}_style.yaml`, contents: ensureTrailingNewline(declaration.styleYaml) });
130
+ }
131
+ if (declaration.dataYaml?.trim()) {
132
+ files.push({ path: `data/${name}_data.yaml`, contents: ensureTrailingNewline(declaration.dataYaml) });
133
+ }
134
+ return { name, domainClass, url: `/${name}`, files };
135
+ }
136
+
137
+ function ensureTrailingNewline(text: string): string {
138
+ return text.endsWith('\n') ? text : `${text}\n`;
139
+ }
@@ -0,0 +1,96 @@
1
+ // core/client/adaptive/flush-scheduler.ts — 帧内三相调度与写去重(F-12)
2
+ //
3
+ // 三相:读 → 算 → 写,同帧内不交错。
4
+ // 读:尺寸已由观察者回调带进调用方状态,本相**不做任何 DOM 读取**(零主动测量);
5
+ // 算:逐作用域调用调用方传入的 decide(),不触碰 DOM;
6
+ // 写:仅对 plan ≠ prevPlan 者调用 write(plan)。
7
+ //
8
+ // 这样写入次数等于**档位切换次数**(个位数),而不是 resize 事件次数(数百)。
9
+ // 读写分相是"零强制回流"的机制来源:一帧里若先写后读,浏览器必须把样式算完
10
+ // 才能回答读,于是每次交错都是一次同步布局。
11
+ //
12
+ // 本模块不含任何决策逻辑,也不做时间维度的节流防抖——
13
+ // 空间维度的稳定由 hysteresis.ts 负责,两者各管一维,合成一个 API 就都测不了。
14
+
15
+ export interface SomaAdaptiveTask<P = unknown> {
16
+ /** 算相:返回本帧的 plan;返回 null 表示"本帧无意见",一字节不写 */
17
+ decide(): P | null;
18
+ /** 写相:只在 plan 与上一次不同时被调用 */
19
+ write(plan: P): void;
20
+ }
21
+
22
+ /** 上一帧已写入的 plan。WeakMap:task 被丢弃即随之回收 */
23
+ const lastPlans = new WeakMap<SomaAdaptiveTask<any>, unknown>();
24
+
25
+ /** 本帧待处理的 task 集合。Set 天然合帧:同帧重复提交同一 task 只算一次 */
26
+ let pending: Set<SomaAdaptiveTask<any>> | null = null;
27
+
28
+ /**
29
+ * 把若干作用域任务并入本帧的调度批次。
30
+ *
31
+ * 同帧内重复提交同一 task 以最后一次为准(task 对象自带最新状态,Set 去重即合帧)。
32
+ * 无 rAF 环境(SSR)直接返回,不排队也不同步执行——页面以默认档渲染即可(F-14)。
33
+ */
34
+ export function scheduleAdaptiveFlush(tasks: readonly SomaAdaptiveTask<any>[]): void {
35
+ if (typeof requestAnimationFrame !== 'function') return;
36
+ if (!tasks || tasks.length === 0) return;
37
+
38
+ if (!pending) {
39
+ pending = new Set();
40
+ requestAnimationFrame(flush);
41
+ }
42
+ for (const task of tasks) pending.add(task);
43
+ }
44
+
45
+ function flush(): void {
46
+ const batch = pending;
47
+ pending = null;
48
+ if (!batch) return;
49
+
50
+ // ── 算相:批量决策,不触碰 DOM ──
51
+ const writes: Array<{ task: SomaAdaptiveTask<any>; plan: unknown }> = [];
52
+ for (const task of batch) {
53
+ let plan: unknown;
54
+ try {
55
+ plan = task.decide();
56
+ } catch {
57
+ // 隔离:一个作用域的决策炸了不该拖垮同帧其它作用域;
58
+ // 跳过本帧写入并保持上一 plan,下一帧尺寸再变时自然重试。
59
+ continue;
60
+ }
61
+ if (plan === null || plan === undefined) continue;
62
+ if (samePlan(lastPlans.get(task), plan)) continue;
63
+ writes.push({ task, plan });
64
+ }
65
+
66
+ // ── 写相:只写变化者,只写 CSS 变量与 data 属性(不写 width/height/inset) ──
67
+ for (const { task, plan } of writes) {
68
+ try {
69
+ task.write(plan);
70
+ lastPlans.set(task, plan);
71
+ } catch {
72
+ // 写失败不记账:下一帧同 plan 仍会被判为"有变化",从而自动重试
73
+ }
74
+ }
75
+ }
76
+
77
+ /**
78
+ * plan 浅比较。
79
+ * plan 是扁平的离散档位对象(档位数是常量),所以浅比较的复杂度是 O(1);
80
+ * 深比较在这里既没有收益,又会把"plan 里能放什么"变成一条隐性契约。
81
+ */
82
+ function samePlan(prev: unknown, next: unknown): boolean {
83
+ if (prev === next) return true;
84
+ if (prev === undefined || prev === null || next === null) return false;
85
+ if (typeof prev !== 'object' || typeof next !== 'object') return false;
86
+
87
+ const prevKeys = Object.keys(prev as object);
88
+ const nextKeys = Object.keys(next as object);
89
+ if (prevKeys.length !== nextKeys.length) return false;
90
+ for (const key of prevKeys) {
91
+ if ((prev as Record<string, unknown>)[key] !== (next as Record<string, unknown>)[key]) {
92
+ return false;
93
+ }
94
+ }
95
+ return true;
96
+ }