soma-core 2.2.5 → 2.2.7

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 (283) hide show
  1. package/README.md +5 -6
  2. package/bin/soma.cjs +2 -2
  3. package/core/build/compiler/flat-page.ts +16 -0
  4. package/core/build/compiler/full-manifest-builder.ts +0 -3
  5. package/core/build/compiler/page-assets.ts +0 -1
  6. package/core/build/compiler/page-closure.ts +245 -0
  7. package/core/build/compiler/page-declaration-compiler.ts +2 -5
  8. package/core/build/compiler/soma-precompile.js +1972 -3312
  9. package/core/build/compiler/soma-precompile.ts +4 -7
  10. package/core/build/component-tree/artifact-codec.ts +4 -8
  11. package/core/build/lsp/soma-declaration.cjs +1 -1
  12. package/core/build/lsp/std-completion.generated.json +3 -3
  13. package/core/client/a11y/a11y-config.ts +2 -1
  14. package/core/client/a11y/dom-id.ts +1 -1
  15. package/core/client/base/SomaHttpClient.ts +11 -3
  16. package/core/client/base/SomaPageRootBase.ts +6 -0
  17. package/core/client/base/defineSomaView.ts +178 -0
  18. package/core/client/base/index.ts +13 -0
  19. package/core/client/base/view-context.ts +328 -0
  20. package/core/client/behavior/adapter-collection.ts +2 -2
  21. package/core/client/compiler/manifest-compiler.ts +5 -36
  22. package/core/client/component/component-definition.types.ts +2 -1
  23. package/core/client/component/component-manager.ts +110 -20
  24. package/core/client/component/structure-adapter.ts +3 -7
  25. package/core/client/container/IContainerAdapter.ts +4 -0
  26. package/core/client/container/SomaContainerAdapter.ts +52 -3
  27. package/core/client/data/data-object-resolver.ts +523 -184
  28. package/core/client/data/data-write-actions.ts +79 -15
  29. package/core/client/data/format-config.ts +3 -1
  30. package/core/client/data/region-scope-port.ts +11 -0
  31. package/core/client/engine/asset-resolver.ts +2 -5
  32. package/core/client/engine/dom-renderer.ts +7 -40
  33. package/core/client/engine/event-engine.ts +29 -108
  34. package/core/client/engine/property-watcher.ts +1 -1
  35. package/core/client/engine/reactive-proxy.ts +78 -17
  36. package/core/client/engine/runtime-builder.ts +0 -14
  37. package/core/client/engine/scope-resolver.ts +18 -0
  38. package/core/client/engine/soma-bootstrap.ts +387 -99
  39. package/core/client/engine/style-binder.ts +49 -106
  40. package/core/client/engine/timer-engine.ts +11 -1
  41. package/core/client/host-bridge/load-host-domain-class.ts +2 -1
  42. package/core/client/infra/http/SomaHttpService.ts +15 -4
  43. package/core/client/infra/i18n/pack-locales.ts +2 -2
  44. package/core/client/infra/notify/DefaultNotifyService.ts +2 -2
  45. package/core/client/mount/domain-rule.ts +7 -3
  46. package/core/client/mount/mount-page.ts +38 -5
  47. package/core/client/mount/types.ts +2 -0
  48. package/core/client/parser/confirm-spec.ts +100 -7
  49. package/core/client/parser/data-config-parser.ts +28 -211
  50. package/core/client/parser/pipeline-parser.ts +16 -60
  51. package/core/client/parser/style-config-parser.ts +101 -95
  52. package/core/client/parser/timer-parser.ts +21 -0
  53. package/core/client/parser/ui-config-parser.ts +64 -12
  54. package/core/client/registry/declaration-renderer.ts +1 -1
  55. package/core/client/render-ports/hide-transition.ts +9 -0
  56. package/core/client/render-ports/index.ts +4 -0
  57. package/core/client/render-ports/notify-renderer.ts +2 -1
  58. package/core/client/runtime/SomaRuntimeServices.ts +2 -1
  59. package/core/client/runtime/SomaSnapshotStore.ts +5 -0
  60. package/core/client/security/url-guard.ts +71 -11
  61. package/core/client/validation/async-check-registry.ts +2 -1
  62. package/core/client/validation/contract-validator.ts +2 -6
  63. package/core/client/validation/field-rules.ts +3 -13
  64. package/core/client/validation/object-rules.ts +2 -10
  65. package/core/index.ts +17 -39
  66. package/core/inspect/check-product.ts +5 -5
  67. package/core/inspect/runtime.ts +2 -1
  68. package/core/server/api/dispatch-service-api.ts +35 -36
  69. package/core/server/api/load-host-service.ts +8 -4
  70. package/core/server/api/paged-list.ts +259 -0
  71. package/core/server/compile-port.ts +1 -1
  72. package/core/server/host/app-config-composer.ts +2 -1
  73. package/core/server/host/empty-host-bootstrap.mjs +3 -0
  74. package/core/server/host/host-assembly-entry.ts +1 -0
  75. package/core/server/host/host-assembly.ts +50 -3
  76. package/core/server/host/host-caller.ts +2 -1
  77. package/core/server/host/host-dir.ts +9 -0
  78. package/core/server/host/host-response-headers.ts +2 -1
  79. package/core/server/host/invoke-host-request-hook.ts +28 -4
  80. package/core/server/host/published-page-assets.ts +2 -1
  81. package/core/server/host/resolve-host-request-hook.ts +25 -7
  82. package/core/server/host/server-page-assets.ts +4 -4
  83. package/core/server/host/source-aliases.cjs +345 -0
  84. package/core/server/host/source-aliases.ts +32 -0
  85. package/core/server/host/source-packages.cjs +1 -0
  86. package/core/server/host/virtual-pages.ts +3 -2
  87. package/core/server/infra/cache/ServerFileCache.ts +83 -10
  88. package/core/server/node.ts +10 -0
  89. package/core/server/registry/api-registry-store.ts +3 -1
  90. package/core/server/registry/declaration-precompiler.ts +0 -2
  91. package/core/server/registry/page-registry-repository.ts +2 -1
  92. package/core/server/registry/page-registry-store.ts +2 -1
  93. package/core/server/registry/registry-error.ts +6 -1
  94. package/core/server/registry/registry-file-lock.ts +296 -23
  95. package/core/server/registry/request-body-limit.ts +3 -2
  96. package/core/server/registry/validation/declaration-safety-scan.ts +151 -27
  97. package/core/server/runtime-space/access-gate.ts +21 -7
  98. package/core/server/runtime-space/bindings.ts +3 -6
  99. package/core/server/runtime-space/dynamic-pages.ts +181 -49
  100. package/core/server/runtime-space/errors.ts +3 -0
  101. package/core/server/runtime-space/inject.ts +78 -16
  102. package/core/server/runtime-space/page-grants.ts +7 -1
  103. package/core/server/runtime-space/resolve.ts +66 -19
  104. package/core/server/runtime-space/store.ts +32 -3
  105. package/core/server/runtime-space/submit-steps.ts +2 -1
  106. package/core/server/runtime-space/types.ts +3 -1
  107. package/core/shared/component-tree-errors.ts +2 -1
  108. package/core/shared/contract-a11y.ts +1 -1
  109. package/core/shared/contract-sections.ts +2 -2
  110. package/core/shared/core-diagnostic-codes.ts +14 -0
  111. package/core/shared/data-declaration-checks.ts +29 -3
  112. package/core/shared/declaration-keys.ts +1 -1
  113. package/core/shared/engines/engine-error.ts +2 -1
  114. package/core/shared/generation-error.ts +2 -1
  115. package/core/shared/page-envelope.ts +1 -1
  116. package/core/shared/pure-binding.ts +88 -0
  117. package/core/shared/registry-generated/diagnostic-registry-index.ts +21 -19
  118. package/core/shared/registry-generated/diagnostic-registry.ts +170 -177
  119. package/core/shared/registry-generated/limits.ts +65 -13
  120. package/core/shared/registry-generated/std-grammar-completion.ts +0 -4
  121. package/core/shared/registry-generated/std-grammar-views.ts +40 -10
  122. package/core/shared/registry-generated/std-grammar.ts +43 -21
  123. package/core/shared/soma-error.ts +36 -0
  124. package/core/shared/types/compile-port.types.ts +1 -1
  125. package/core/shared/types/data-config.types.ts +20 -18
  126. package/core/shared/types/engine.types.ts +0 -3
  127. package/core/shared/types/event.types.ts +10 -11
  128. package/core/shared/types/generation-error.types.ts +5 -1
  129. package/core/shared/types/host-assembly.types.ts +7 -1
  130. package/core/shared/types/manifest.types.ts +0 -3
  131. package/core/shared/types/region-scope.types.ts +5 -1
  132. package/core/shared/types/scope-manifest.types.ts +0 -2
  133. package/core/shared/types/style-config.types.ts +21 -21
  134. package/core/shared/types/ui-config.types.ts +4 -5
  135. package/core/shared/types/watcher.types.ts +1 -1
  136. package/dist/browser/runtime-bundle.manifest.json +11 -13
  137. package/dist/browser/soma-runtime.js +2733 -2712
  138. package/dist/core/index.cjs +5665 -5534
  139. package/dist/host-native/aot-builder.cjs +330 -1
  140. package/dist/host-native/native-server.cjs +5434 -4726
  141. package/dist/lsp/component-tree.cjs +5868 -7040
  142. package/dist/types/build/compiler/full-manifest-builder.d.ts +0 -2
  143. package/dist/types/build/compiler/page-closure.d.ts +21 -0
  144. package/dist/types/build/compiler/page-declaration-compiler.d.ts +2 -4
  145. package/dist/types/build/compiler/soma-precompile.d.ts +1 -3
  146. package/dist/types/build/component-tree/artifact-codec.d.ts +0 -2
  147. package/dist/types/client/a11y/a11y-config.d.ts +2 -1
  148. package/dist/types/client/base/SomaHttpClient.d.ts +1 -1
  149. package/dist/types/client/base/SomaPageRootBase.d.ts +5 -0
  150. package/dist/types/client/base/defineSomaView.d.ts +46 -0
  151. package/dist/types/client/base/index.d.ts +2 -0
  152. package/dist/types/client/base/view-context.d.ts +136 -0
  153. package/dist/types/client/behavior/adapter-collection.d.ts +1 -1
  154. package/dist/types/client/compiler/manifest-compiler.d.ts +0 -3
  155. package/dist/types/client/component/component-definition.types.d.ts +2 -1
  156. package/dist/types/client/component/component-manager.d.ts +29 -0
  157. package/dist/types/client/container/IContainerAdapter.d.ts +3 -0
  158. package/dist/types/client/container/SomaContainerAdapter.d.ts +5 -0
  159. package/dist/types/client/data/data-object-resolver.d.ts +93 -31
  160. package/dist/types/client/data/format-config.d.ts +2 -1
  161. package/dist/types/client/engine/dom-renderer.d.ts +1 -2
  162. package/dist/types/client/engine/event-engine.d.ts +0 -7
  163. package/dist/types/client/engine/reactive-proxy.d.ts +11 -4
  164. package/dist/types/client/engine/runtime-builder.d.ts +0 -4
  165. package/dist/types/client/engine/soma-bootstrap.d.ts +44 -6
  166. package/dist/types/client/engine/style-binder.d.ts +8 -4
  167. package/dist/types/client/host-bridge/load-host-domain-class.d.ts +2 -1
  168. package/dist/types/client/mount/domain-rule.d.ts +2 -0
  169. package/dist/types/client/mount/mount-page.d.ts +2 -1
  170. package/dist/types/client/mount/types.d.ts +2 -0
  171. package/dist/types/client/parser/confirm-spec.d.ts +27 -3
  172. package/dist/types/client/parser/data-config-parser.d.ts +6 -5
  173. package/dist/types/client/parser/style-config-parser.d.ts +7 -3
  174. package/dist/types/client/parser/timer-parser.d.ts +5 -0
  175. package/dist/types/client/parser/ui-config-parser.d.ts +6 -2
  176. package/dist/types/client/render-ports/hide-transition.d.ts +9 -0
  177. package/dist/types/client/render-ports/index.d.ts +4 -0
  178. package/dist/types/client/render-ports/notify-renderer.d.ts +2 -1
  179. package/dist/types/client/runtime/SomaSnapshotStore.d.ts +2 -0
  180. package/dist/types/client/security/url-guard.d.ts +14 -0
  181. package/dist/types/client/validation/async-check-registry.d.ts +2 -1
  182. package/dist/types/client/validation/object-rules.d.ts +0 -5
  183. package/dist/types/index.d.ts +6 -11
  184. package/dist/types/inspect/runtime.d.ts +2 -1
  185. package/dist/types/server/api/dispatch-service-api.d.ts +5 -0
  186. package/dist/types/server/api/load-host-service.d.ts +1 -1
  187. package/dist/types/server/api/paged-list.d.ts +101 -0
  188. package/dist/types/server/compile-port.d.ts +1 -1
  189. package/dist/types/server/host/host-assembly-entry.d.ts +1 -1
  190. package/dist/types/server/host/host-assembly.d.ts +2 -0
  191. package/dist/types/server/host/host-dir.d.ts +2 -0
  192. package/dist/types/server/host/invoke-host-request-hook.d.ts +10 -3
  193. package/dist/types/server/host/published-page-assets.d.ts +2 -1
  194. package/dist/types/server/host/resolve-host-request-hook.d.ts +18 -5
  195. package/dist/types/server/host/server-page-assets.d.ts +2 -1
  196. package/dist/types/server/host/source-aliases.d.cts +53 -0
  197. package/dist/types/server/host/source-aliases.d.ts +30 -0
  198. package/dist/types/server/host/source-packages.d.cts +2 -0
  199. package/dist/types/server/infra/cache/ServerFileCache.d.ts +8 -0
  200. package/dist/types/server/node.d.ts +1 -0
  201. package/dist/types/server/registry/declaration-precompiler.d.ts +0 -1
  202. package/dist/types/server/registry/registry-error.d.ts +5 -1
  203. package/dist/types/server/registry/registry-file-lock.d.ts +30 -0
  204. package/dist/types/server/registry/request-body-limit.d.ts +3 -2
  205. package/dist/types/server/registry/validation/declaration-safety-scan.d.ts +3 -0
  206. package/dist/types/server/runtime-space/access-gate.d.ts +7 -0
  207. package/dist/types/server/runtime-space/bindings.d.ts +3 -2
  208. package/dist/types/server/runtime-space/dynamic-pages.d.ts +6 -1
  209. package/dist/types/server/runtime-space/errors.d.ts +1 -1
  210. package/dist/types/server/runtime-space/resolve.d.ts +2 -0
  211. package/dist/types/server/runtime-space/store.d.ts +8 -1
  212. package/dist/types/server/runtime-space/submit-steps.d.ts +2 -1
  213. package/dist/types/server/runtime-space/types.d.ts +3 -1
  214. package/dist/types/shared/component-tree-errors.d.ts +2 -1
  215. package/dist/types/shared/core-diagnostic-codes.d.ts +1 -1
  216. package/dist/types/shared/declaration-keys.d.ts +1 -1
  217. package/dist/types/shared/engines/engine-error.d.ts +2 -1
  218. package/dist/types/shared/generation-error.d.ts +2 -1
  219. package/dist/types/shared/pure-binding.d.ts +48 -0
  220. package/dist/types/shared/registry-generated/diagnostic-registry.d.ts +149 -158
  221. package/dist/types/shared/registry-generated/limits.d.ts +54 -10
  222. package/dist/types/shared/registry-generated/std-grammar-completion.d.ts +0 -30
  223. package/dist/types/shared/registry-generated/std-grammar-views.d.ts +97 -23
  224. package/dist/types/shared/registry-generated/std-grammar.d.ts +110 -242
  225. package/dist/types/shared/soma-error.d.ts +15 -0
  226. package/dist/types/shared/types/data-config.types.d.ts +17 -17
  227. package/dist/types/shared/types/engine.types.d.ts +0 -3
  228. package/dist/types/shared/types/event.types.d.ts +9 -7
  229. package/dist/types/shared/types/generation-error.types.d.ts +1 -1
  230. package/dist/types/shared/types/host-assembly.types.d.ts +2 -0
  231. package/dist/types/shared/types/manifest.types.d.ts +0 -3
  232. package/dist/types/shared/types/region-scope.types.d.ts +4 -1
  233. package/dist/types/shared/types/scope-manifest.types.d.ts +0 -2
  234. package/dist/types/shared/types/style-config.types.d.ts +17 -19
  235. package/dist/types/shared/types/ui-config.types.d.ts +4 -5
  236. package/host-native/bin/host-native.cjs +22 -1
  237. package/host-native/client/browser-entry.ts +21 -172
  238. package/host-native/src/aot-builder.ts +75 -0
  239. package/host-native/src/host-prepare.ts +39 -5
  240. package/host-native/src/manifest-http.ts +2 -3
  241. package/host-native/src/native-server.ts +812 -174
  242. package/host-native/src/page-http.ts +3 -3
  243. package/host-native/src/public-packages.cjs +0 -1
  244. package/host-native/src/registry-handler.ts +12 -5
  245. package/host-native/src/static-file.ts +203 -53
  246. package/host-native/styles/globals.css +30 -28
  247. package/package.json +14 -2
  248. package/core/client/engine/step-runner.ts +0 -212
  249. package/core/client/engine/trigger-engine.ts +0 -55
  250. package/core/client/format/zoned.ts +0 -10
  251. package/core/client/parser/step-parser.ts +0 -359
  252. package/core/client/parser/trigger-parser.ts +0 -90
  253. package/core/client/parser/value-lang.ts +0 -340
  254. package/core/client/time/instant.ts +0 -2
  255. package/core/shared/calc/coerce.ts +0 -2
  256. package/core/shared/calc/errors.ts +0 -40
  257. package/core/shared/calc/evaluator.ts +0 -113
  258. package/core/shared/calc/index.ts +0 -11
  259. package/core/shared/calc/lexer.ts +0 -189
  260. package/core/shared/calc/parser.ts +0 -193
  261. package/core/shared/calc/typer.ts +0 -171
  262. package/core/shared/date-parts.ts +0 -2
  263. package/core/shared/show-when.ts +0 -77
  264. package/core/shared/types/step.types.ts +0 -91
  265. package/core/shared/types/trigger.types.ts +0 -14
  266. package/dist/types/client/engine/step-runner.d.ts +0 -42
  267. package/dist/types/client/engine/trigger-engine.d.ts +0 -16
  268. package/dist/types/client/format/zoned.d.ts +0 -1
  269. package/dist/types/client/parser/step-parser.d.ts +0 -23
  270. package/dist/types/client/parser/trigger-parser.d.ts +0 -13
  271. package/dist/types/client/parser/value-lang.d.ts +0 -63
  272. package/dist/types/client/time/instant.d.ts +0 -1
  273. package/dist/types/shared/calc/coerce.d.ts +0 -1
  274. package/dist/types/shared/calc/errors.d.ts +0 -14
  275. package/dist/types/shared/calc/evaluator.d.ts +0 -2
  276. package/dist/types/shared/calc/index.d.ts +0 -6
  277. package/dist/types/shared/calc/lexer.d.ts +0 -19
  278. package/dist/types/shared/calc/parser.d.ts +0 -43
  279. package/dist/types/shared/calc/typer.d.ts +0 -11
  280. package/dist/types/shared/date-parts.d.ts +0 -1
  281. package/dist/types/shared/show-when.d.ts +0 -21
  282. package/dist/types/shared/types/step.types.d.ts +0 -76
  283. package/dist/types/shared/types/trigger.types.d.ts +0 -12
@@ -1,11 +1,11 @@
1
1
  // core/client/parser/data-config-parser.ts — 数据对象层(page 块 `data:`)声明解析器
2
2
  // 负责将 page 块 `data:` 解析后的原始对象转换为类型安全的 SomaDataConfig 结构。
3
- // 只认 core 的最小声明:对象 from / transform / fields / write / predicates / name / poll,顶层 subscribe。
4
- // 校验范围:type 枚举合法性、rules 形状、`$` 引用语法、transform 管道语法、写通道闭集键与引用;
3
+ // 只认 core 的最小声明:对象 from / fields / write / name / poll,顶层 subscribe。
4
+ // 校验范围:type 枚举合法性、rules 形状、`$` 引用语法、写通道闭集键与引用;
5
5
  // 非法声明抛带定位路径的 SomaDataConfigError(风格与 contract-validator/style-config-parser 一致)。
6
6
 
7
+ import { SomaError } from '../../shared/soma-error';
7
8
  import yaml from 'js-yaml';
8
- import { hasPipes, parsePipedValue } from '../pipes/pipe-registry';
9
9
  import type {
10
10
  SomaDataConfig,
11
11
  SomaDataFieldConfig,
@@ -31,7 +31,6 @@ import {
31
31
  type SomaObjectIssue,
32
32
  } from '../../shared/data-declaration-checks';
33
33
  import type { SomaFieldPredicate } from '../../shared/predicates';
34
- import { validateNamedPredicates, validatePredicate } from '../../shared/predicates';
35
34
  import {
36
35
  SOMA_STD_DOMAIN_COMMAND_METHODS,
37
36
  SOMA_STD_DOMAIN_VALIDATION_SEVERITIES,
@@ -41,21 +40,13 @@ import {
41
40
  SOMA_DATA_RULE_KEYS,
42
41
  SOMA_DATA_WRITE_KEYS,
43
42
  } from '../../shared/registry-generated/std-grammar-views';
44
- import {
45
- assertCalcResultType,
46
- collectCalcRefs,
47
- inferCalcType,
48
- parseCalc,
49
- SomaCalcSyntaxError,
50
- SomaCalcTypeError,
51
- } from '../../shared/calc';
52
43
  import { parseAsyncFieldChecks } from '../validation/async-rules';
53
44
  import { inspectEnvelopeFailure } from '../data/envelope-failure';
54
45
  import { parseSubscriptions } from './subscribe-parser';
55
46
 
56
47
  // ─── 错误类 ───────────────────────────────────────────────────────────────────
57
48
 
58
- export class SomaDataConfigError extends Error {
49
+ export class SomaDataConfigError extends SomaError {
59
50
  /** 首条问题的精确路径(单条问题时就是唯一路径) */
60
51
  public readonly path: string;
61
52
  /** 全部结构化问题(路径为绝对路径);只有一条或不带结构化信息时只含首条 */
@@ -64,7 +55,7 @@ export class SomaDataConfigError extends Error {
64
55
  * 可选的诊断码:目前只有「闭集外键」类拒收带码(write 未知键 = ERR-BIZ-001),
65
56
  * 与语法真源上下文的 `unknownKeyCode` 同一个值;不带码的错误由调用方按位置定码。
66
57
  */
67
- public readonly code?: string;
58
+ declare public readonly code?: string;
68
59
 
69
60
  constructor(message: string, path: string = '', issues?: readonly SomaObjectIssue[], code?: string) {
70
61
  const prefix = path ? ` (路径: ${path})` : '';
@@ -72,7 +63,7 @@ export class SomaDataConfigError extends Error {
72
63
  this.name = 'SomaDataConfigError';
73
64
  this.path = path;
74
65
  this.issues = issues ?? [{ path, message }];
75
- if (code !== undefined) this.code = code;
66
+ if (code !== undefined) (this as { code?: string }).code = code;
76
67
  }
77
68
  }
78
69
 
@@ -105,7 +96,7 @@ const WRITE_KEY_SET: ReadonlySet<string> = new Set(SOMA_DATA_WRITE_KEYS);
105
96
  const WRITE_UNKNOWN_KEY_CODE = 'ERR-BIZ-001';
106
97
 
107
98
  /** 规则修饰键:`message`(提示文案)、`when`(条件规则)与 `severity`(校验强度),都不是条件 */
108
- const RULE_MODIFIER_KEYS: readonly string[] = ['message', 'when', 'severity'];
99
+ const RULE_MODIFIER_KEYS: readonly string[] = ['message', 'severity'];
109
100
 
110
101
  /** 规则条件键(语法真源 `field.rule` 上下文去掉修饰键):每条规则恰好写其中一个 */
111
102
  type RuleConditionKey = Exclude<(typeof SOMA_DATA_RULE_KEYS)[number], 'message' | 'when' | 'severity'>;
@@ -158,23 +149,6 @@ export function parseDataRef(text: string): SomaDataRef | null {
158
149
  return { source: 'object', object: head, path };
159
150
  }
160
151
 
161
- // ─── transform 管道语法归一化 ─────────────────────────────────────────────────
162
-
163
- /**
164
- * 归一化 transform 值中的管道段:规格允许 `date: 'YYYY-MM-DD'` 的冒号简写,
165
- * 统一改写成 pipe-registry 的标准语法 `date('YYYY-MM-DD')` 后复用其解析器。
166
- * 首段(字段路径)原样保留。
167
- */
168
- export function normalizeDataPipeValue(rawValue: string): string {
169
- const segments = rawValue.split(/\s+\|\s+/);
170
- if (segments.length <= 1) return rawValue.trim();
171
- const normalized = segments.slice(1).map((segment) => {
172
- const match = segment.trim().match(/^([a-z][a-zA-Z0-9_]*)\s*:\s*(.+)$/);
173
- return match ? `${match[1]}(${match[2].trim()})` : segment.trim();
174
- });
175
- return [segments[0].trim(), ...normalized].join(' | ');
176
- }
177
-
178
152
  // ─── 内部校验函数 ─────────────────────────────────────────────────────────────
179
153
 
180
154
  function assertPlainObject(value: unknown, what: string, path: string): asserts value is Record<string, unknown> {
@@ -183,18 +157,6 @@ function assertPlainObject(value: unknown, what: string, path: string): asserts
183
157
  }
184
158
  }
185
159
 
186
- function isPlainObject(value: unknown): value is Record<string, unknown> {
187
- return typeof value === 'object' && value !== null && !Array.isArray(value);
188
- }
189
-
190
- /** 条件写法归一:谓词对象原样;非空列表按「且」包成 `{ all_of }`。其他返回 undefined(由调用方报形状) */
191
- function normalizePredicate(raw: unknown): SomaFieldPredicate | undefined {
192
- if (Array.isArray(raw)) {
193
- return raw.length > 0 ? ({ all_of: raw as SomaFieldPredicate[] }) : undefined;
194
- }
195
- return isPlainObject(raw) ? (raw as unknown as SomaFieldPredicate) : undefined;
196
- }
197
-
198
160
  /** 递归校验 params 中的 `$` 引用语法,并收集引用到的其他数据对象名 */
199
161
  function validateParamRefs(
200
162
  value: unknown,
@@ -239,6 +201,20 @@ function validateParamRefs(
239
201
  }
240
202
  }
241
203
 
204
+ /**
205
+ * 接口地址形状(请求端是 `${baseURL}${path}` 直接拼接):必须是以单个 `/` 开头的站内路径。
206
+ * 拒绝 `@host/x`、`//host/x`、`/\\host`、反斜杠、空白 / 控制字符,以及 `javascript:` 等带协议的写法(都不以 `/` 开头)。
207
+ * 占位符 `{id}` 与查询串不受影响。返回问题描述,合规返回 null。
208
+ */
209
+ export function inspectApiShape(api: string): string | null {
210
+ if (!api.startsWith('/')) return '必须以 `/` 开头的站内路径(不接受 `@host`、协议、绝对 URL 或不带前导斜杠的相对路径)';
211
+ if (api.startsWith('//') || api.startsWith('/\\')) return '不得以 `//` 或 `/\\` 开头(会被解析成别的主机)';
212
+ if (api.includes('\\')) return '不得含反斜杠';
213
+ // eslint-disable-next-line no-control-regex
214
+ if (/[\s\u0000-\u001f\u007f]/.test(api)) return '不得含空白或控制字符';
215
+ return null;
216
+ }
217
+
242
218
  function parseSource(
243
219
  raw: unknown,
244
220
  path: string,
@@ -255,6 +231,8 @@ function parseSource(
255
231
  if (typeof value !== 'string' || !value.trim()) {
256
232
  throw new SomaDataConfigError(`api 必须是非空字符串`, `${path}.api`);
257
233
  }
234
+ const shape = inspectApiShape(value.trim());
235
+ if (shape !== null) throw new SomaDataConfigError(`api ${shape},当前值: ${JSON.stringify(value)}`, `${path}.api`);
258
236
  source.api = value.trim();
259
237
  } else if (key === 'params') {
260
238
  assertPlainObject(value, 'params', `${path}.params`);
@@ -303,44 +281,14 @@ function parseSource(
303
281
  SOMA_FROM_REQUIRE_CODE,
304
282
  );
305
283
  }
306
- source.require = [...(requireRaw as string[])];
284
+ source.require = (requireRaw as Array<string | string[]>).map((entry) => (Array.isArray(entry) ? [...entry] : entry));
307
285
  }
308
286
  return source;
309
287
  }
310
288
 
311
- function parseTransform(raw: unknown, path: string): Record<string, string> {
312
- assertPlainObject(raw, 'transform', path);
313
- const result: Record<string, string> = {};
314
- for (const [key, value] of Object.entries(raw)) {
315
- if (typeof value !== 'string' || !value.trim()) {
316
- throw new SomaDataConfigError(
317
- `派生字段的值必须是 "字段路径 | 管道链" 字符串,当前值: ${JSON.stringify(value)}`,
318
- `${path}.${key}`,
319
- );
320
- }
321
- const normalized = normalizeDataPipeValue(value);
322
- if (hasPipes(normalized)) {
323
- try {
324
- // 语法级校验(管道名白名单由解析器结合注册表在运行时校验)
325
- parsePipedValue(normalized, () => false);
326
- } catch (error) {
327
- throw new SomaDataConfigError(
328
- `派生字段管道链解析失败: ${(error as Error).message}`,
329
- `${path}.${key}`,
330
- );
331
- }
332
- }
333
- result[key] = normalized;
334
- }
335
- return result;
336
- }
337
-
338
- const WHEN_SHAPE_MESSAGE = 'when 必须是字段谓词 { field, op, value? }、非空谓词列表(全部成立)、{ all_of | any_of | none_of } 或 { ref: 具名谓词 }';
339
-
340
289
  function parseRule(raw: unknown, path: string): SomaDataFieldRule {
341
290
  assertPlainObject(raw, '校验规则', path);
342
291
  const keys = Object.keys(raw);
343
- // `when`(条件规则)不是条件键:它决定本条规则是否参与
344
292
  const ruleKeys = keys.filter((key) => !RULE_MODIFIER_KEYS.includes(key));
345
293
 
346
294
  if (typeof raw.message !== 'string' || !raw.message) {
@@ -376,18 +324,10 @@ function parseRule(raw: unknown, path: string): SomaDataFieldRule {
376
324
  const expected = RULE_VALUE_TYPES[ruleKey as RuleConditionKey];
377
325
  const ruleValue = raw[ruleKey];
378
326
 
379
- let when: SomaDataFieldRule['when'];
380
- if (Object.hasOwn(raw, 'when')) {
381
- // 只做值形状;字段存在与算子配对要整本字典与具名谓词表就位(见 validateRuleWhenRefs)
382
- when = normalizePredicate(raw.when);
383
- if (when === undefined) throw new SomaDataConfigError(WHEN_SHAPE_MESSAGE, `${path}.when`);
384
- }
385
-
386
327
  if (expected === 'async') {
387
328
  const asyncRule = parseAsyncRule(raw, ruleValue, path);
388
329
  return {
389
330
  ...asyncRule,
390
- ...(when !== undefined ? { when } : {}),
391
331
  ...(severity !== undefined ? { severity } : {}),
392
332
  };
393
333
  }
@@ -412,7 +352,6 @@ function parseRule(raw: unknown, path: string): SomaDataFieldRule {
412
352
  return {
413
353
  [ruleKey]: ruleValue,
414
354
  message: raw.message,
415
- ...(when !== undefined ? { when } : {}),
416
355
  ...(severity !== undefined ? { severity } : {}),
417
356
  } as SomaDataFieldRule;
418
357
  }
@@ -508,93 +447,11 @@ function parseField(raw: unknown, path: string): SomaDataFieldConfig {
508
447
  } else if (key === 'default') {
509
448
  // 字面量深拷贝:声明对象不与解析产物共享引用
510
449
  field.default = value !== null && typeof value === 'object' ? JSON.parse(JSON.stringify(value)) : value;
511
- } else if (key === 'calc') {
512
- // 表达式本身在这里还校验不了:它引用的是兄弟字段,而兄弟还没解析完。留到 validateDerivedFields 统一对账。
513
- if (typeof value !== 'string' || value.trim() === '') {
514
- throw new SomaDataConfigError('calc 必须是非空表达式字符串', `${path}.calc`);
515
- }
516
- field.calc = value;
517
450
  }
518
451
  }
519
452
  return field;
520
453
  }
521
454
 
522
- /** 派生列能落进哪些字段类型——与 calc 的结果类型对账表同源 */
523
- const CALC_WRITABLE_TYPES = new Set([
524
- 'int', 'float', 'money', 'percent', 'progress', 'text', 'url', 'enum', 'date', 'datetime',
525
- ]);
526
-
527
- /**
528
- * 派生列对账:表达式引用的字段要在同一本字典里,推出来的结果类型要与声明的 `type` 一致,
529
- * 且派生列之间不能成环。
530
- */
531
- function validateDerivedFields(
532
- fields: Record<string, SomaDataFieldConfig>,
533
- path: string,
534
- ): void {
535
- const derived = Object.keys(fields).filter((key) => fields[key].calc !== undefined);
536
- if (derived.length === 0) return;
537
-
538
- const fieldTypes: Record<string, string | undefined> = Object.fromEntries(
539
- Object.keys(fields).map((key) => [key, fields[key].type]),
540
- );
541
- const refsOf: Record<string, string[]> = {};
542
-
543
- for (const key of derived) {
544
- const at = `${path}.${key}.calc`;
545
- const source = fields[key].calc!;
546
- const declared = fields[key].type ?? 'text';
547
- if (!CALC_WRITABLE_TYPES.has(declared)) {
548
- throw new SomaDataConfigError(`calc 算不出 ${declared} 类型的值(字段 "${key}")`, at);
549
- }
550
- try {
551
- const node = parseCalc(source);
552
- const ctx = { fieldTypes, source };
553
- assertCalcResultType(inferCalcType(node, ctx), declared, ctx, node);
554
- const refs = collectCalcRefs(node);
555
- for (const ref of refs) {
556
- if (!Object.hasOwn(fields, ref)) {
557
- throw new SomaDataConfigError(
558
- `calc 引用了不存在的字段 "${ref}"(本对象字典:${Object.keys(fields).join(' / ')})`,
559
- at,
560
- );
561
- }
562
- if (ref === key) {
563
- throw new SomaDataConfigError(`calc 引用了它自己(字段 "${key}")`, at);
564
- }
565
- }
566
- refsOf[key] = refs;
567
- } catch (error) {
568
- if (error instanceof SomaCalcSyntaxError || error instanceof SomaCalcTypeError) {
569
- throw new SomaDataConfigError(error.message, at);
570
- }
571
- throw error;
572
- }
573
- }
574
-
575
- // 派生列之间成环:求值会无限递归。深度优先找回边,报错打印整条路径。
576
- const state: Record<string, 'visiting' | 'done'> = {};
577
- const stack: string[] = [];
578
- const walk = (key: string): void => {
579
- if (state[key] === 'done') return;
580
- if (state[key] === 'visiting') {
581
- const from = stack.indexOf(key);
582
- throw new SomaDataConfigError(
583
- `派生列成环:${[...stack.slice(from), key].join(' → ')}`,
584
- `${path}.${key}.calc`,
585
- );
586
- }
587
- state[key] = 'visiting';
588
- stack.push(key);
589
- for (const ref of refsOf[key] ?? []) {
590
- if (refsOf[ref] !== undefined) walk(ref);
591
- }
592
- stack.pop();
593
- state[key] = 'done';
594
- };
595
- for (const key of derived) walk(key);
596
- }
597
-
598
455
  const WRITE_METHODS = new Set<string>(SOMA_STD_DOMAIN_COMMAND_METHODS);
599
456
 
600
457
  /**
@@ -750,6 +607,8 @@ function parseDeleteEndpoint(raw: unknown, path: string): NonNullable<SomaDataWr
750
607
  }
751
608
  const problems = scanApiTemplate(record.api.trim()).problems;
752
609
  if (problems.length > 0) throw new SomaDataConfigError(`delete.api ${problems.join(';')}`, `${path}.api`);
610
+ const deleteShape = inspectApiShape(record.api.trim());
611
+ if (deleteShape !== null) throw new SomaDataConfigError(`delete.api ${deleteShape},当前值: ${JSON.stringify(record.api)}`, `${path}.api`);
753
612
  if (record.method !== undefined
754
613
  && (typeof record.method !== 'string' || record.method.trim().toUpperCase() !== 'DELETE')) {
755
614
  throw new SomaDataConfigError(
@@ -760,29 +619,6 @@ function parseDeleteEndpoint(raw: unknown, path: string): NonNullable<SomaDataWr
760
619
  return { api: record.api.trim(), method: 'DELETE' };
761
620
  }
762
621
 
763
- /**
764
- * 条件规则(`rules[].when`)的引用对账:谓词只能引用本对象字段,算子与类型配对,`{ ref }` 指向已声明的具名谓词。
765
- */
766
- function validateRuleWhenRefs(
767
- fields: Readonly<Record<string, SomaDataFieldConfig>>,
768
- fieldKeys: readonly string[],
769
- fieldTypes: Readonly<Record<string, string | undefined>>,
770
- named: SomaDataObjectConfig['predicates'],
771
- path: string,
772
- ): void {
773
- for (const [name, field] of Object.entries(fields)) {
774
- (field.rules ?? []).forEach((rule, index) => {
775
- if (rule.when === undefined) return;
776
- const at = `${path}.fields.${name}.rules[${index}].when`;
777
- const issues = validatePredicate(rule.when, fieldKeys, 'when', {
778
- fieldTypes,
779
- ...(named !== undefined ? { named } : {}),
780
- });
781
- if (issues.length > 0) throw new SomaDataConfigError(issues.join(';'), at);
782
- });
783
- }
784
- }
785
-
786
622
  function parseWriteEndpoint(raw: unknown, path: string): SomaDataWriteEndpoint {
787
623
  assertPlainObject(raw, '写端点', path);
788
624
  const api = (raw as Record<string, unknown>).api;
@@ -790,6 +626,8 @@ function parseWriteEndpoint(raw: unknown, path: string): SomaDataWriteEndpoint {
790
626
  if (typeof api !== 'string' || !api.trim()) {
791
627
  throw new SomaDataConfigError('写端点缺少 api(后端接口是唯一数据边界)', `${path}.api`);
792
628
  }
629
+ const writeShape = inspectApiShape(api.trim());
630
+ if (writeShape !== null) throw new SomaDataConfigError(`写端点 api ${writeShape},当前值: ${JSON.stringify(api)}`, `${path}.api`);
793
631
  // 大小写不敏感,产物统一大写:文档示例都写小写(`method: put`),只认大写等于让第一个示例就过不了解析
794
632
  const method = typeof declaredMethod === 'string' ? declaredMethod.toUpperCase() : declaredMethod;
795
633
  if (typeof method !== 'string' || !WRITE_METHODS.has(method)) {
@@ -820,7 +658,6 @@ function parseObject(
820
658
  const deps = new Set<string>();
821
659
  const config: SomaDataObjectConfig = { name, from: [], deps: [] };
822
660
  let writeRaw: unknown;
823
- let predicatesRaw: unknown;
824
661
 
825
662
  for (const [key, value] of Object.entries(raw)) {
826
663
  if (!OBJECT_KEY_SET.has(key)) {
@@ -836,20 +673,15 @@ function parseObject(
836
673
  config.from = value.map((source, index) =>
837
674
  parseSource(source, `${path}.from[${index}]`, objectNames, name, deps),
838
675
  );
839
- } else if (key === 'transform') {
840
- config.transform = parseTransform(value, `${path}.transform`);
841
676
  } else if (key === 'fields') {
842
677
  assertPlainObject(value, 'fields', `${path}.fields`);
843
678
  const fields: Record<string, SomaDataFieldConfig> = {};
844
679
  for (const [fieldName, fieldRaw] of Object.entries(value)) {
845
680
  fields[fieldName] = parseField(fieldRaw, `${path}.fields.${fieldName}`);
846
681
  }
847
- validateDerivedFields(fields, `${path}.fields`);
848
682
  config.fields = fields;
849
683
  } else if (key === 'write') {
850
684
  writeRaw = value;
851
- } else if (key === 'predicates') {
852
- predicatesRaw = value;
853
685
  } else if (key === 'name') {
854
686
  // 显示名。YAML 键 `name` 在产物里叫 displayName——`config.name` 是对象键名
855
687
  if (typeof value !== 'string' || value.trim() === '') {
@@ -866,9 +698,6 @@ function parseObject(
866
698
 
867
699
  const fields = config.fields ?? {};
868
700
  const fieldKeys = Object.keys(fields);
869
- const fieldTypes: Record<string, string | undefined> = Object.fromEntries(
870
- fieldKeys.map((key) => [key, fields[key].type]),
871
- );
872
701
 
873
702
  // 写通道要等字典就位(map / only / version 指向字典里的字段)
874
703
  if (writeRaw !== undefined) {
@@ -882,18 +711,6 @@ function parseObject(
882
711
  throw new SomaDataConfigError(`缺少 from 取数来源(无 from 的对象须声明 write 的 create / update / delete 端点)`, `${path}.from`);
883
712
  }
884
713
 
885
- // 具名谓词表:一条判断声明一次,多处 { ref } 复用
886
- if (predicatesRaw !== undefined) {
887
- const issues = validateNamedPredicates(predicatesRaw, fieldKeys, fieldTypes);
888
- if (issues.length > 0) {
889
- throw new SomaDataConfigError(issues.join(';'), `${path}.predicates`);
890
- }
891
- config.predicates = predicatesRaw as SomaDataObjectConfig['predicates'];
892
- }
893
-
894
- // 条件规则(rules[].when)同理要字典与具名谓词表都就位
895
- validateRuleWhenRefs(fields, fieldKeys, fieldTypes, config.predicates, path);
896
-
897
714
  // poll 引用的是本对象的字段与候选:要等字典就位才对得上
898
715
  if (config.poll !== undefined) {
899
716
  const issues = inspectPollRefs(config.poll, fields);
@@ -1,7 +1,6 @@
1
1
  // core/client/parser/pipeline-parser.ts — SOMA Pipeline DSL 解析器
2
2
  // 负责解析 _event.yaml 中的 Pipeline 表达式,将其转换为类型安全的 ParsedEvent 结构
3
3
 
4
- import { parseSteps } from './step-parser';
5
4
  import type {
6
5
  ParsedEvent,
7
6
  EventType,
@@ -21,6 +20,7 @@ import {
21
20
  import { parseConfirmSegment } from './confirm-spec';
22
21
  import type { SomaConfirmSpec } from '../../shared/types/event.types';
23
22
  import { isRegionSliceName, isScopeIdentifier, isScopePath } from '../../shared/region-scope-decl';
23
+ import { hasBlockedScheme } from '../security/url-guard';
24
24
 
25
25
  // ─── 错误类 ───────────────────────────────────────────────────────────────────
26
26
 
@@ -72,39 +72,6 @@ export function isKnownDomEvent(name: string): boolean {
72
72
  return VALID_DOM_EVENTS.has(name);
73
73
  }
74
74
 
75
- /** `{ steps: [...] }` 形态识别:值是对象且恰好带一个数组型 `steps` 键 */
76
- function isStepsDeclaration(value: unknown): value is { steps: unknown[] } {
77
- return value !== null
78
- && typeof value === 'object'
79
- && !Array.isArray(value)
80
- && Array.isArray((value as { steps?: unknown }).steps);
81
- }
82
-
83
- /**
84
- * 从步骤声明里收集 `when` 引用到的根名,当作载荷字段的作用域。
85
- *
86
- * 事件载荷的字段在编译期不可知——它来自组件契约的 emit payload,而 `_event.yaml`
87
- * 手上没有契约。给空作用域的话,每一条 `when` 都会被判成"引用了不存在的字段",
88
- * 编排事实上就写不出来了。所以这里放行载荷引用,只保留**槽的前向引用**这条真正
89
- * 只靠步骤本身就能判的规则;载荷字段名对不对,归组件契约那一侧管。
90
- */
91
- function collectWhenRoots(steps: unknown): string[] {
92
- const roots = new Set<string>();
93
- const walk = (node: unknown): void => {
94
- if (Array.isArray(node)) {
95
- for (const item of node) walk(item);
96
- return;
97
- }
98
- if (node === null || typeof node !== 'object') return;
99
- for (const [key, value] of Object.entries(node)) {
100
- if (key === 'field' && typeof value === 'string') roots.add(value.split('.')[0]);
101
- else walk(value);
102
- }
103
- };
104
- walk(steps);
105
- return [...roots];
106
- }
107
-
108
75
  /** Pipeline optional confirm segment prefix */
109
76
  const CONFIRM_PREFIX = 'confirm:';
110
77
 
@@ -247,7 +214,8 @@ function splitOptionalSegments(parts: string[]): {
247
214
  const segment = parseConfirmSegment(message);
248
215
  if ('error' in segment) throw new SomaEventParseError(segment.error, parts.join(' | '));
249
216
  confirm = segment.spec.text;
250
- confirmSpec = segment.spec.level === 'plain' ? undefined : segment.spec;
217
+ // plain 且无语气 = 只有 confirm 文案(旧写法逐字不变);有分级或 tone: danger 才带规格
218
+ confirmSpec = segment.spec.level === 'plain' && segment.spec.tone === undefined ? undefined : segment.spec;
251
219
  continue;
252
220
  }
253
221
  if (index > 0 && part.startsWith(PERMISSION_PREFIX)) {
@@ -429,6 +397,9 @@ export function parsePipelineBody(
429
397
  if (!parts[1]) {
430
398
  throw new SomaEventParseError(`NAV_STATIC 缺少必填参数 targetUrl`, expression);
431
399
  }
400
+ if (hasBlockedScheme('href', parts[1])) {
401
+ throw new SomaEventParseError(`NAV_STATIC 目标 URL 包含危险伪协议 "${parts[1]}"`, expression);
402
+ }
432
403
  result.targetUrl = parts[1];
433
404
  if (parseNavTail(parts.slice(2), type, expression)) result.navReplace = true;
434
405
  break;
@@ -440,6 +411,9 @@ export function parsePipelineBody(
440
411
  if (!parts[2]) {
441
412
  throw new SomaEventParseError(`NAV_ACTION 缺少必填参数 targetUrl`, expression);
442
413
  }
414
+ if (hasBlockedScheme('href', parts[2])) {
415
+ throw new SomaEventParseError(`NAV_ACTION 目标 URL 包含危险伪协议 "${parts[2]}"`, expression);
416
+ }
443
417
  result.funcPath = parts[1];
444
418
  result.targetUrl = parts[2];
445
419
  if (parseNavTail(parts.slice(3), type, expression)) result.navReplace = true;
@@ -574,35 +548,17 @@ export function parseEventConfig(
574
548
  }
575
549
  throw error;
576
550
  }
577
- } else if (isStepsDeclaration(value)) {
578
- // 编排事件(REQ-010 F-13):`{ steps: [...] }`。
579
- // 它长得像"嵌套层级",所以必须先于递归分支判掉——否则 `steps` 会被当成
580
- // 一个子锚点名递归下去,而数组值又不是字符串,于是整条声明被静默丢弃。
581
- const { somaId, domEvent, keyModifier } = parseSelector(key);
582
- const graph = parseSteps(
583
- {
584
- raw: (value as { steps: unknown }).steps,
585
- // 事件载荷的字段在编译期不可知(它来自组件契约的 emit payload)。
586
- // 给空作用域会把所有 `when` 都判成越界,所以这里放行载荷引用、
587
- // 只校验槽的前向引用——载荷字段名的校验归组件契约那一侧。
588
- payloadFields: collectWhenRoots((value as { steps: unknown }).steps),
589
- path: `${[...parentPath, key].join(' > ')}.steps`,
590
- },
591
- {
592
- fail(message: string): never {
593
- throw new SomaEventParseError(message, key);
594
- },
595
- parsePipeline: parsePipelineBody,
596
- },
597
- );
598
- const event: ParsedEvent = { somaId, domEvent, type: 'STEPS', steps: graph };
599
- if (keyModifier) event.keyModifier = keyModifier;
600
- events.push(event);
601
- } else if (typeof value === 'object' && value !== null) {
551
+ } else if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
602
552
  // 嵌套层级:递归解析
603
553
  events.push(
604
554
  ...parseEventConfig(value as EventConfigRaw, [...parentPath, key]),
605
555
  );
556
+ } else {
557
+ // 事件声明只有两种形态:管道字符串、嵌套映射。其余(数组、数字、布尔、null——含曾有的 `steps` 编排)一律拒绝,不静默丢弃
558
+ throw new SomaEventParseError(
559
+ `事件声明必须是管道字符串或嵌套映射,当前值: ${JSON.stringify(value)}(页面不承载编排与条件,逻辑归 Domain 方法或 ACTION)(路径: ${[...parentPath, key].join(' > ')})`,
560
+ key,
561
+ );
606
562
  }
607
563
  }
608
564