soma-core 2.2.5 → 2.2.6

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 (259) 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 +1848 -3244
  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/SomaContainerAdapter.ts +9 -1
  26. package/core/client/data/data-object-resolver.ts +516 -181
  27. package/core/client/data/data-write-actions.ts +79 -15
  28. package/core/client/data/format-config.ts +3 -1
  29. package/core/client/data/region-scope-port.ts +11 -0
  30. package/core/client/engine/asset-resolver.ts +2 -5
  31. package/core/client/engine/dom-renderer.ts +7 -40
  32. package/core/client/engine/event-engine.ts +1 -105
  33. package/core/client/engine/property-watcher.ts +1 -1
  34. package/core/client/engine/reactive-proxy.ts +78 -17
  35. package/core/client/engine/runtime-builder.ts +0 -14
  36. package/core/client/engine/scope-resolver.ts +18 -0
  37. package/core/client/engine/soma-bootstrap.ts +385 -98
  38. package/core/client/engine/style-binder.ts +49 -106
  39. package/core/client/engine/timer-engine.ts +11 -1
  40. package/core/client/host-bridge/load-host-domain-class.ts +2 -1
  41. package/core/client/infra/http/SomaHttpService.ts +15 -4
  42. package/core/client/infra/i18n/pack-locales.ts +2 -2
  43. package/core/client/mount/domain-rule.ts +7 -3
  44. package/core/client/mount/mount-page.ts +38 -5
  45. package/core/client/mount/types.ts +2 -0
  46. package/core/client/parser/confirm-spec.ts +1 -1
  47. package/core/client/parser/data-config-parser.ts +27 -210
  48. package/core/client/parser/pipeline-parser.ts +14 -59
  49. package/core/client/parser/style-config-parser.ts +101 -95
  50. package/core/client/parser/timer-parser.ts +21 -0
  51. package/core/client/parser/ui-config-parser.ts +64 -12
  52. package/core/client/registry/declaration-renderer.ts +1 -1
  53. package/core/client/runtime/SomaRuntimeServices.ts +2 -1
  54. package/core/client/runtime/SomaSnapshotStore.ts +5 -0
  55. package/core/client/security/url-guard.ts +71 -11
  56. package/core/client/validation/async-check-registry.ts +2 -1
  57. package/core/client/validation/contract-validator.ts +2 -6
  58. package/core/client/validation/field-rules.ts +3 -13
  59. package/core/client/validation/object-rules.ts +2 -10
  60. package/core/index.ts +1 -35
  61. package/core/inspect/check-product.ts +5 -5
  62. package/core/inspect/runtime.ts +2 -1
  63. package/core/server/api/dispatch-service-api.ts +35 -36
  64. package/core/server/api/load-host-service.ts +5 -4
  65. package/core/server/compile-port.ts +1 -1
  66. package/core/server/host/app-config-composer.ts +2 -1
  67. package/core/server/host/host-assembly-entry.ts +1 -0
  68. package/core/server/host/host-assembly.ts +47 -3
  69. package/core/server/host/host-caller.ts +2 -1
  70. package/core/server/host/host-dir.ts +9 -0
  71. package/core/server/host/host-response-headers.ts +2 -1
  72. package/core/server/host/invoke-host-request-hook.ts +28 -4
  73. package/core/server/host/published-page-assets.ts +2 -1
  74. package/core/server/host/resolve-host-request-hook.ts +25 -7
  75. package/core/server/host/server-page-assets.ts +4 -4
  76. package/core/server/host/virtual-pages.ts +3 -2
  77. package/core/server/infra/cache/ServerFileCache.ts +79 -9
  78. package/core/server/registry/api-registry-store.ts +3 -1
  79. package/core/server/registry/declaration-precompiler.ts +0 -2
  80. package/core/server/registry/page-registry-repository.ts +2 -1
  81. package/core/server/registry/page-registry-store.ts +2 -1
  82. package/core/server/registry/registry-error.ts +6 -1
  83. package/core/server/registry/registry-file-lock.ts +296 -23
  84. package/core/server/registry/request-body-limit.ts +3 -2
  85. package/core/server/registry/validation/declaration-safety-scan.ts +151 -27
  86. package/core/server/runtime-space/access-gate.ts +21 -7
  87. package/core/server/runtime-space/bindings.ts +3 -6
  88. package/core/server/runtime-space/dynamic-pages.ts +181 -49
  89. package/core/server/runtime-space/errors.ts +3 -0
  90. package/core/server/runtime-space/inject.ts +74 -15
  91. package/core/server/runtime-space/page-grants.ts +7 -1
  92. package/core/server/runtime-space/resolve.ts +66 -19
  93. package/core/server/runtime-space/store.ts +32 -3
  94. package/core/server/runtime-space/submit-steps.ts +2 -1
  95. package/core/server/runtime-space/types.ts +3 -1
  96. package/core/shared/component-tree-errors.ts +2 -1
  97. package/core/shared/contract-a11y.ts +1 -1
  98. package/core/shared/contract-sections.ts +2 -2
  99. package/core/shared/core-diagnostic-codes.ts +8 -0
  100. package/core/shared/declaration-keys.ts +1 -1
  101. package/core/shared/engines/engine-error.ts +2 -1
  102. package/core/shared/generation-error.ts +2 -1
  103. package/core/shared/page-envelope.ts +1 -1
  104. package/core/shared/pure-binding.ts +88 -0
  105. package/core/shared/registry-generated/diagnostic-registry-index.ts +16 -19
  106. package/core/shared/registry-generated/diagnostic-registry.ts +135 -177
  107. package/core/shared/registry-generated/limits.ts +49 -13
  108. package/core/shared/registry-generated/std-grammar-completion.ts +0 -4
  109. package/core/shared/registry-generated/std-grammar-views.ts +40 -10
  110. package/core/shared/registry-generated/std-grammar.ts +42 -20
  111. package/core/shared/soma-error.ts +36 -0
  112. package/core/shared/types/compile-port.types.ts +1 -1
  113. package/core/shared/types/data-config.types.ts +17 -17
  114. package/core/shared/types/engine.types.ts +0 -3
  115. package/core/shared/types/event.types.ts +1 -11
  116. package/core/shared/types/generation-error.types.ts +5 -1
  117. package/core/shared/types/host-assembly.types.ts +7 -1
  118. package/core/shared/types/manifest.types.ts +0 -3
  119. package/core/shared/types/region-scope.types.ts +5 -1
  120. package/core/shared/types/scope-manifest.types.ts +0 -2
  121. package/core/shared/types/style-config.types.ts +21 -21
  122. package/core/shared/types/ui-config.types.ts +4 -5
  123. package/core/shared/types/watcher.types.ts +1 -1
  124. package/dist/browser/runtime-bundle.manifest.json +11 -13
  125. package/dist/browser/soma-runtime.js +2567 -2696
  126. package/dist/core/index.cjs +5446 -5486
  127. package/dist/host-native/aot-builder.cjs +46 -1
  128. package/dist/host-native/native-server.cjs +4879 -4505
  129. package/dist/lsp/component-tree.cjs +5814 -7042
  130. package/dist/types/build/compiler/full-manifest-builder.d.ts +0 -2
  131. package/dist/types/build/compiler/page-closure.d.ts +21 -0
  132. package/dist/types/build/compiler/page-declaration-compiler.d.ts +2 -4
  133. package/dist/types/build/compiler/soma-precompile.d.ts +1 -3
  134. package/dist/types/build/component-tree/artifact-codec.d.ts +0 -2
  135. package/dist/types/client/a11y/a11y-config.d.ts +2 -1
  136. package/dist/types/client/base/SomaHttpClient.d.ts +1 -1
  137. package/dist/types/client/base/SomaPageRootBase.d.ts +5 -0
  138. package/dist/types/client/base/defineSomaView.d.ts +46 -0
  139. package/dist/types/client/base/index.d.ts +2 -0
  140. package/dist/types/client/base/view-context.d.ts +136 -0
  141. package/dist/types/client/behavior/adapter-collection.d.ts +1 -1
  142. package/dist/types/client/compiler/manifest-compiler.d.ts +0 -3
  143. package/dist/types/client/component/component-definition.types.d.ts +2 -1
  144. package/dist/types/client/component/component-manager.d.ts +29 -0
  145. package/dist/types/client/data/data-object-resolver.d.ts +91 -31
  146. package/dist/types/client/data/format-config.d.ts +2 -1
  147. package/dist/types/client/engine/dom-renderer.d.ts +1 -2
  148. package/dist/types/client/engine/event-engine.d.ts +0 -7
  149. package/dist/types/client/engine/reactive-proxy.d.ts +11 -4
  150. package/dist/types/client/engine/runtime-builder.d.ts +0 -4
  151. package/dist/types/client/engine/soma-bootstrap.d.ts +44 -6
  152. package/dist/types/client/engine/style-binder.d.ts +8 -4
  153. package/dist/types/client/host-bridge/load-host-domain-class.d.ts +2 -1
  154. package/dist/types/client/mount/domain-rule.d.ts +2 -0
  155. package/dist/types/client/mount/mount-page.d.ts +2 -1
  156. package/dist/types/client/mount/types.d.ts +2 -0
  157. package/dist/types/client/parser/data-config-parser.d.ts +6 -5
  158. package/dist/types/client/parser/style-config-parser.d.ts +7 -3
  159. package/dist/types/client/parser/timer-parser.d.ts +5 -0
  160. package/dist/types/client/parser/ui-config-parser.d.ts +6 -2
  161. package/dist/types/client/runtime/SomaSnapshotStore.d.ts +2 -0
  162. package/dist/types/client/security/url-guard.d.ts +14 -0
  163. package/dist/types/client/validation/async-check-registry.d.ts +2 -1
  164. package/dist/types/client/validation/object-rules.d.ts +0 -5
  165. package/dist/types/index.d.ts +2 -7
  166. package/dist/types/inspect/runtime.d.ts +2 -1
  167. package/dist/types/server/api/dispatch-service-api.d.ts +5 -0
  168. package/dist/types/server/api/load-host-service.d.ts +1 -1
  169. package/dist/types/server/compile-port.d.ts +1 -1
  170. package/dist/types/server/host/host-assembly-entry.d.ts +1 -1
  171. package/dist/types/server/host/host-assembly.d.ts +2 -0
  172. package/dist/types/server/host/host-dir.d.ts +2 -0
  173. package/dist/types/server/host/invoke-host-request-hook.d.ts +10 -3
  174. package/dist/types/server/host/published-page-assets.d.ts +2 -1
  175. package/dist/types/server/host/resolve-host-request-hook.d.ts +18 -5
  176. package/dist/types/server/host/server-page-assets.d.ts +2 -1
  177. package/dist/types/server/infra/cache/ServerFileCache.d.ts +8 -0
  178. package/dist/types/server/registry/declaration-precompiler.d.ts +0 -1
  179. package/dist/types/server/registry/registry-error.d.ts +5 -1
  180. package/dist/types/server/registry/registry-file-lock.d.ts +30 -0
  181. package/dist/types/server/registry/request-body-limit.d.ts +3 -2
  182. package/dist/types/server/registry/validation/declaration-safety-scan.d.ts +3 -0
  183. package/dist/types/server/runtime-space/access-gate.d.ts +7 -0
  184. package/dist/types/server/runtime-space/bindings.d.ts +3 -2
  185. package/dist/types/server/runtime-space/dynamic-pages.d.ts +6 -1
  186. package/dist/types/server/runtime-space/errors.d.ts +1 -1
  187. package/dist/types/server/runtime-space/resolve.d.ts +2 -0
  188. package/dist/types/server/runtime-space/store.d.ts +8 -1
  189. package/dist/types/server/runtime-space/submit-steps.d.ts +2 -1
  190. package/dist/types/server/runtime-space/types.d.ts +3 -1
  191. package/dist/types/shared/component-tree-errors.d.ts +2 -1
  192. package/dist/types/shared/core-diagnostic-codes.d.ts +1 -1
  193. package/dist/types/shared/declaration-keys.d.ts +1 -1
  194. package/dist/types/shared/engines/engine-error.d.ts +2 -1
  195. package/dist/types/shared/generation-error.d.ts +2 -1
  196. package/dist/types/shared/pure-binding.d.ts +48 -0
  197. package/dist/types/shared/registry-generated/diagnostic-registry.d.ts +119 -158
  198. package/dist/types/shared/registry-generated/limits.d.ts +40 -10
  199. package/dist/types/shared/registry-generated/std-grammar-completion.d.ts +0 -30
  200. package/dist/types/shared/registry-generated/std-grammar-views.d.ts +97 -23
  201. package/dist/types/shared/registry-generated/std-grammar.d.ts +109 -241
  202. package/dist/types/shared/soma-error.d.ts +15 -0
  203. package/dist/types/shared/types/data-config.types.d.ts +14 -16
  204. package/dist/types/shared/types/engine.types.d.ts +0 -3
  205. package/dist/types/shared/types/event.types.d.ts +1 -7
  206. package/dist/types/shared/types/generation-error.types.d.ts +1 -1
  207. package/dist/types/shared/types/host-assembly.types.d.ts +2 -0
  208. package/dist/types/shared/types/manifest.types.d.ts +0 -3
  209. package/dist/types/shared/types/region-scope.types.d.ts +4 -1
  210. package/dist/types/shared/types/scope-manifest.types.d.ts +0 -2
  211. package/dist/types/shared/types/style-config.types.d.ts +17 -19
  212. package/dist/types/shared/types/ui-config.types.d.ts +4 -5
  213. package/host-native/bin/host-native.cjs +22 -1
  214. package/host-native/client/browser-entry.ts +21 -172
  215. package/host-native/src/aot-builder.ts +52 -0
  216. package/host-native/src/host-prepare.ts +39 -5
  217. package/host-native/src/manifest-http.ts +2 -3
  218. package/host-native/src/native-server.ts +812 -174
  219. package/host-native/src/page-http.ts +3 -3
  220. package/host-native/src/public-packages.cjs +0 -1
  221. package/host-native/src/registry-handler.ts +12 -5
  222. package/host-native/src/static-file.ts +203 -53
  223. package/package.json +3 -2
  224. package/core/client/engine/step-runner.ts +0 -212
  225. package/core/client/engine/trigger-engine.ts +0 -55
  226. package/core/client/format/zoned.ts +0 -10
  227. package/core/client/parser/step-parser.ts +0 -359
  228. package/core/client/parser/trigger-parser.ts +0 -90
  229. package/core/client/parser/value-lang.ts +0 -340
  230. package/core/client/time/instant.ts +0 -2
  231. package/core/shared/calc/coerce.ts +0 -2
  232. package/core/shared/calc/errors.ts +0 -40
  233. package/core/shared/calc/evaluator.ts +0 -113
  234. package/core/shared/calc/index.ts +0 -11
  235. package/core/shared/calc/lexer.ts +0 -189
  236. package/core/shared/calc/parser.ts +0 -193
  237. package/core/shared/calc/typer.ts +0 -171
  238. package/core/shared/date-parts.ts +0 -2
  239. package/core/shared/show-when.ts +0 -77
  240. package/core/shared/types/step.types.ts +0 -91
  241. package/core/shared/types/trigger.types.ts +0 -14
  242. package/dist/types/client/engine/step-runner.d.ts +0 -42
  243. package/dist/types/client/engine/trigger-engine.d.ts +0 -16
  244. package/dist/types/client/format/zoned.d.ts +0 -1
  245. package/dist/types/client/parser/step-parser.d.ts +0 -23
  246. package/dist/types/client/parser/trigger-parser.d.ts +0 -13
  247. package/dist/types/client/parser/value-lang.d.ts +0 -63
  248. package/dist/types/client/time/instant.d.ts +0 -1
  249. package/dist/types/shared/calc/coerce.d.ts +0 -1
  250. package/dist/types/shared/calc/errors.d.ts +0 -14
  251. package/dist/types/shared/calc/evaluator.d.ts +0 -2
  252. package/dist/types/shared/calc/index.d.ts +0 -6
  253. package/dist/types/shared/calc/lexer.d.ts +0 -19
  254. package/dist/types/shared/calc/parser.d.ts +0 -43
  255. package/dist/types/shared/calc/typer.d.ts +0 -11
  256. package/dist/types/shared/date-parts.d.ts +0 -1
  257. package/dist/types/shared/show-when.d.ts +0 -21
  258. package/dist/types/shared/types/step.types.d.ts +0 -76
  259. package/dist/types/shared/types/trigger.types.d.ts +0 -12
@@ -14,6 +14,7 @@
14
14
  // 检查器签名沿用 `SomaAsyncFieldChecker`(`async-rules.ts`):`(input) => Promise<{ outcome: 'valid' | 'invalid' | 'error', message? }>`。
15
15
  // 纯逻辑、无 DOM。
16
16
 
17
+ import { SomaError } from '../../shared/soma-error';
17
18
  import type { SomaAsyncFieldChecker } from './async-rules';
18
19
 
19
20
  /** 登记表:`{ 检查器名: 检查器 }` */
@@ -31,7 +32,7 @@ export interface SomaValidationService {
31
32
 
32
33
  export type SomaAsyncCheckErrorCode = 'CORE-ASYNC-CHECK-TABLE' | 'CORE-ASYNC-CHECK-UNREGISTERED';
33
34
 
34
- export class SomaAsyncCheckError extends Error {
35
+ export class SomaAsyncCheckError extends SomaError {
35
36
  constructor(readonly code: SomaAsyncCheckErrorCode, message: string, readonly names: readonly string[] = []) {
36
37
  super(`[${code}] ${message}`);
37
38
  this.name = 'SomaAsyncCheckError';
@@ -256,7 +256,7 @@ export class SomaContractValidator {
256
256
  }
257
257
  if (value.when) {
258
258
  this.validateReadablePath(
259
- typeof value.when === 'string' ? value.when : value.when.field,
259
+ value.when,
260
260
  `${currentPath}.when`,
261
261
  resolver,
262
262
  rootInstance,
@@ -344,16 +344,12 @@ export class SomaContractValidator {
344
344
  rootInstance: object,
345
345
  report: SomaContractReport,
346
346
  ): void {
347
- let path = rawPath.trim();
347
+ const path = rawPath.trim();
348
348
  if (!path) {
349
349
  this.addError(report, `${location}: 绑定路径不能为空`);
350
350
  return;
351
351
  }
352
352
 
353
- if (path.startsWith('!')) {
354
- path = path.slice(1);
355
- }
356
-
357
353
  const segments = path.split('.').filter(Boolean);
358
354
  if (segments.length === 0) {
359
355
  this.addError(report, `${location}: 绑定路径不能为空`);
@@ -1,4 +1,4 @@
1
- // 字段规则求值核已下沉通用值区 `soma-foundation/values`;这里把谓词求值接回 core 装好的完整引擎(数量比较、相对日期),其余再导出。
1
+ // 字段规则求值核在通用值区 `soma-foundation/values`;页面规则只有 required / 长度 / 范围 / 正则 / 步长 / async,不含条件求值,这里原样转出。
2
2
  import {
3
3
  checkField as checkFieldBase,
4
4
  checkFieldAll as checkFieldAllBase,
@@ -6,16 +6,6 @@ import {
6
6
  type FieldRule,
7
7
  type RuleFailure,
8
8
  } from 'soma-foundation/values';
9
- import {
10
- evaluatePredicate,
11
- type SomaFieldPredicate as CorePredicate,
12
- type SomaNamedPredicates as CoreNamedPredicates,
13
- } from '../../shared/predicates';
14
-
15
- /** core 装好的求值端口:算子名在基础区是泛型 string,这里收窄回 core 的算子闭集 */
16
- const evaluateWithCore: NonNullable<FieldCheckContext['evaluate']> = (predicate, values, named) =>
17
- evaluatePredicate(predicate as CorePredicate, values, named as CoreNamedPredicates | undefined);
18
-
19
9
  export {
20
10
  RULE_MESSAGE_KEYS,
21
11
  SOMA_ASYNC_UNAVAILABLE_I18N_KEY,
@@ -36,7 +26,7 @@ export function checkField(
36
26
  value: unknown,
37
27
  context: FieldCheckContext = {},
38
28
  ): RuleFailure | null {
39
- return checkFieldBase(rules, value, { evaluate: evaluateWithCore, ...context });
29
+ return checkFieldBase(rules, value, context);
40
30
  }
41
31
 
42
32
  /** 单字段校验,返回全部失败(含非 hard 档) */
@@ -45,5 +35,5 @@ export function checkFieldAll(
45
35
  value: unknown,
46
36
  context: FieldCheckContext = {},
47
37
  ): RuleFailure[] {
48
- return checkFieldAllBase(rules, value, { evaluate: evaluateWithCore, ...context });
38
+ return checkFieldAllBase(rules, value, context);
49
39
  }
@@ -1,6 +1,6 @@
1
1
  // 对象级记录校验(WP3b-A S4 / S8 / S9 的运行期兑现):按数据对象字典一次校验一份表单值。
2
2
  //
3
- // 声明面:字段 `rules`(含条件规则 `when`)、写通道 `validate_on`(校验时机)。
3
+ // 声明面:字段 `rules`、写通道 `validate_on`(校验时机)。
4
4
  // 求值核仍是 `checkField`(长度按码点,AD-15)。
5
5
  // 日期粒度、时间型值形状、链接策略等领域值协议不在 core:方言装配层经 `protocolCheck` 入参接入
6
6
  // (链接策略可直接用 `security/url-guard` 的 `resolveSafeUrl`)。
@@ -10,7 +10,6 @@ import type {
10
10
  SomaDataWriteConfig,
11
11
  SomaValidateTrigger,
12
12
  } from '../../shared/types/data-config.types';
13
- import type { SomaNamedPredicates } from '../../shared/predicates';
14
13
  import { checkFieldAll, isBlank, severityOfFailure, type RuleFailure } from './field-rules';
15
14
 
16
15
  /** 写通道声明的校验时机里有没有这一个:没声明 `validate_on` 恒为真(时机由调用方决定,存量口径) */
@@ -21,10 +20,6 @@ export function shouldValidateOn(write: Pick<SomaDataWriteConfig, 'validate_on'>
21
20
  export interface ObjectRecordCheckOptions {
22
21
  /** 只校验这些字段(缺省 = 字典里全部字段) */
23
22
  readonly keys?: readonly string[];
24
- /** 对象的具名谓词表(条件规则的 `{ ref }`) */
25
- readonly named?: SomaNamedPredicates;
26
- /** 条件规则的求值记录(缺省 = `record` 本身);数据端口传「读态 ∪ 表单值」 */
27
- readonly context?: Readonly<Record<string, unknown>>;
28
23
  /** 方言接入的领域值协议检查(日期粒度、时间型值形状等):非空值逐字段调用,返回失败或 null;缺省不检查 */
29
24
  readonly protocolCheck?: (field: SomaDataFieldConfig, value: unknown) => RuleFailure | null;
30
25
  }
@@ -44,10 +39,7 @@ export function validateObjectRecordGraded(
44
39
  const field = Object.hasOwn(fields, key) ? fields[key] : undefined;
45
40
  if (field === undefined) continue;
46
41
  const value = record[key];
47
- const failures = checkFieldAll(field.rules, value, {
48
- record: options.context ?? record,
49
- ...(options.named !== undefined ? { named: options.named } : {}),
50
- });
42
+ const failures = checkFieldAll(field.rules, value);
51
43
  if (!isBlank(value)) {
52
44
  const protocol = options.protocolCheck?.(field, value) ?? null;
53
45
  if (protocol !== null) failures.push(protocol);
package/core/index.ts CHANGED
@@ -45,7 +45,6 @@ export {
45
45
  parseDataConfig,
46
46
  parseDataYaml,
47
47
  parseDataRef,
48
- normalizeDataPipeValue,
49
48
  SomaDataConfigError,
50
49
  // 对象声明的各层键集:AI 提示词词汇、闸门共用同一份,不得本地抄一份——
51
50
  // 抄本漂开那天的表现是「能写、不报错、值被静默丢弃」
@@ -116,12 +115,6 @@ export type {
116
115
  SomaPredicateValidateOptions,
117
116
  } from './shared/predicates';
118
117
 
119
- // 动作编排:一个交互按顺序做好几件事。编排图是纯数据——
120
- // 可画、可 diff、可在编译期判定可终止性。逃生舱是具名动作注册表,不是脚本。
121
- export { parseSteps } from './client/parser/step-parser';
122
- export type { StepParseInput, StepParseDeps } from './client/parser/step-parser';
123
- export { runSteps } from './client/engine/step-runner';
124
-
125
118
  // 页面态切片:分享链接与地址栏同步共用一套结构。
126
119
  export {
127
120
  parsePageState,
@@ -134,18 +127,6 @@ export type {
134
127
  SomaPageState,
135
128
  SomaPageStateConfig,
136
129
  } from './shared/types/page-state.types';
137
- export type { StepRunContext, StepRunResult } from './client/engine/step-runner';
138
- export type {
139
- SomaStep,
140
- SomaDoStep,
141
- SomaSwitchStep,
142
- SomaParallelStep,
143
- SomaForEachStep,
144
- SomaStepOnError,
145
- SomaStepSlot,
146
- SomaCompiledStep,
147
- SomaStepGraph,
148
- } from './shared/types/step.types';
149
130
 
150
131
  // ── 调度原语两件套(F-11 – F-14 / 契约 C7)──
151
132
  // 也可经 `soma-core/scheduling` 子路径单独引入:不 attach 即不加载不执行。
@@ -424,26 +405,11 @@ export {
424
405
  type PackLocalesIssue,
425
406
  } from './client/infra/i18n/pack-locales';
426
407
 
427
- // 值语言(REQ-005 F4):算术六词元 + 管道链的唯一值规则。
428
- // 规格见 soma-core/doc/soma DSL 语法全书.md 值语言一节(纯函数、无依赖)。
429
- export {
430
- parseValueSegment,
431
- evaluateValueNode,
432
- isArithSegment,
433
- isPlainPath,
434
- describeNode,
435
- SomaValueLangError,
436
- type ValueNode,
437
- type PipedValue,
438
- type ValuePosition,
439
- type HasVarFn,
440
- type EvalOptions,
441
- } from './client/parser/value-lang';
442
-
443
408
  // 四件套编译与 HTML 锚点扫描的值函数只在 `soma-core/server/page-declaration`。
444
409
  // 根入口保留类型,不能让客户端加载页面编译实现。
445
410
  export type { CompiledFlatPage, FlatPageInput, SomaFlatDoc } from './build/compiler/flat-page';
446
411
  export { SomaDeclarationError } from './shared/declaration-errors';
412
+ export { SomaError, isSomaError, somaErrorCodeOf } from './shared/soma-error';
447
413
  export type { HtmlAnchorIndex, HtmlAnchorInfo } from './build/compiler/html-index';
448
414
  // 统一寻址(AD-49):页面 html 与 fragments.regions[].html 共用一个 data-soma-id 空间
449
415
  export {
@@ -14,7 +14,7 @@
14
14
  import fs from 'node:fs';
15
15
  import path from 'node:path';
16
16
  import yaml from 'js-yaml';
17
- import { compileFlatPage, flatUiNonStandardKeys, type CompiledFlatPage, type SomaFlatDoc } from '../build/compiler/flat-page';
17
+ import { compileFlatPage, flatUiNonStandardKeys, readFlatDoc, type CompiledFlatPage, type SomaFlatDoc } from '../build/compiler/flat-page';
18
18
  import { expandSomaHtmlIncludes } from '../build/compiler/html-include-expander';
19
19
  import {
20
20
  compilePageDeclaration,
@@ -177,13 +177,14 @@ export function validateCoreProduct(
177
177
  }
178
178
  if (nonStandard.length > 0) return done();
179
179
  let compiled: CompiledFlatPage;
180
+ let rawEvent: Record<string, unknown> = {};
180
181
  try {
181
182
  compiled = compileFlatPage({
182
183
  html,
183
184
  uiYaml: input.uiYaml,
184
- ...(input.eventYaml !== undefined ? { eventYaml: input.eventYaml } : {}),
185
185
  ...(input.styleYaml !== undefined ? { styleYaml: input.styleYaml } : {}),
186
186
  });
187
+ rawEvent = readFlatDoc(input.eventYaml, 'event');
187
188
  } catch (error) {
188
189
  report(SOMA_CORE_CHECK_CODES.blocks, 'blocks', '', messageOf(error));
189
190
  return done();
@@ -217,7 +218,7 @@ export function validateCoreProduct(
217
218
  // ⑤ 事件管道
218
219
  let events: readonly ParsedEvent[] = [];
219
220
  try {
220
- events = compileEventConfigFromRaw(compiled.event).events;
221
+ events = compileEventConfigFromRaw(rawEvent).events;
221
222
  } catch (error) {
222
223
  report(SOMA_CORE_CHECK_CODES.events, 'events', '', messageOf(error));
223
224
  }
@@ -281,7 +282,7 @@ const sortedKeys = (value: unknown): string[] => (isRecord(value) ? Object.keys(
281
282
  function dumpField(raw: unknown): SomaDumpField {
282
283
  const field = isRecord(raw) ? raw : {};
283
284
  const rules = Array.isArray(field.rules)
284
- ? [...new Set(field.rules.flatMap((rule) => (isRecord(rule) ? Object.keys(rule).filter((key) => key !== 'message' && key !== 'when') : [])))].sort()
285
+ ? [...new Set(field.rules.flatMap((rule) => (isRecord(rule) ? Object.keys(rule).filter((key) => key !== 'message') : [])))].sort()
285
286
  : [];
286
287
  const options = Array.isArray(field.options)
287
288
  ? field.options.filter(isRecord).map((option) => ({
@@ -414,7 +415,6 @@ function eventTarget(event: ParsedEvent): string | undefined {
414
415
  return `${event.scope.scope}:${event.scope.verb}${tail ? `:${tail}` : ''}`;
415
416
  }
416
417
  if (event.notify) return `notify:${event.notify.level}`;
417
- if (event.steps) return 'steps';
418
418
  return event.funcPath ?? event.targetUrl ?? (event.targetId !== undefined ? `${event.targetId}:${event.action ?? 'toggle'}` : undefined);
419
419
  }
420
420
 
@@ -4,6 +4,7 @@
4
4
  // 只增不减(M03 / M26 / 目标架构):observe / runtimeBundle / styleKeys / SomaRuntimeExitError / setLocale /
5
5
  // evaluatePredicate / 最小数据端口类型。
6
6
 
7
+ import { SomaError } from '../shared/soma-error';
7
8
  import fs from 'node:fs';
8
9
  import path from 'node:path';
9
10
  import { fileURLToPath } from 'node:url';
@@ -32,7 +33,7 @@ export { evaluatePredicate } from '../shared/predicates';
32
33
  export type { SomaDataPort } from '../shared/types/data-config.types';
33
34
 
34
35
  /** 运行出口的可辨认错误(testkit 据 code 报 ERR-VERIFY-EXIT-MODE) */
35
- export class SomaRuntimeExitError extends Error {
36
+ export class SomaRuntimeExitError extends SomaError {
36
37
  readonly code: 'CORE-OBSERVE-OFF';
37
38
  constructor(code: 'CORE-OBSERVE-OFF', message: string) {
38
39
  super(message);
@@ -1,3 +1,4 @@
1
+ import { randomUUID } from "node:crypto";
1
2
  import type { IService } from "./IService";
2
3
  import {
3
4
  getAotServiceResolver,
@@ -6,6 +7,7 @@ import {
6
7
  } from "./load-host-service";
7
8
  import { invokeHostRequestHook } from "../host/invoke-host-request-hook";
8
9
  import { withHostResponseHeaders } from "../host/host-response-headers";
10
+ import { currentHostDir } from "../host/host-dir";
9
11
 
10
12
  export interface RequestCookie {
11
13
  readonly name: string;
@@ -21,6 +23,11 @@ export interface RequestCookiesAdapter {
21
23
  export interface DispatchHostServiceApiOptions {
22
24
  readonly segments?: readonly string[];
23
25
  readonly hostDir?: string;
26
+ /**
27
+ * 内部选项:标记宿主壳是否已经执行过请求钩子。
28
+ * 仅供原生宿主壳(如 native-server)在读请求体前已执行过鉴权钩子时使用,为 true 时避免重复执行钩子。
29
+ */
30
+ readonly requestHookHandled?: boolean;
24
31
  }
25
32
 
26
33
  function parseCookieHeader(headerValue: string | null): RequestCookiesAdapter {
@@ -116,7 +123,7 @@ export async function dispatchHostServiceApiRequest(
116
123
  ? { segments: segmentsOrOptions }
117
124
  : (segmentsOrOptions as DispatchHostServiceApiOptions | undefined);
118
125
 
119
- const hostDir = options?.hostDir ?? process.env.SOMA_HOST_DIR;
126
+ const hostDir = options?.hostDir ?? currentHostDir();
120
127
 
121
128
  let segments: string[];
122
129
  if (options?.segments && options.segments.length > 0) {
@@ -132,15 +139,22 @@ export async function dispatchHostServiceApiRequest(
132
139
  }
133
140
 
134
141
  const pathname = polyfilledReq.nextUrl.pathname;
135
- const rejected = await invokeHostRequestHook(polyfilledReq, {
136
- kind: "api",
137
- path: pathname,
138
- });
139
- if (rejected) {
140
- return withHostResponseHeaders(rejected, {
141
- method: request.method,
142
- pathname,
143
- }, hostDir);
142
+ if (!options?.requestHookHandled) {
143
+ const rejected = await invokeHostRequestHook(
144
+ polyfilledReq,
145
+ {
146
+ kind: "api",
147
+ path: pathname,
148
+ },
149
+ undefined,
150
+ { hostDir },
151
+ );
152
+ if (rejected) {
153
+ return withHostResponseHeaders(rejected, {
154
+ method: request.method,
155
+ pathname,
156
+ }, hostDir);
157
+ }
144
158
  }
145
159
 
146
160
  if (segments.length === 0) {
@@ -151,31 +165,16 @@ export async function dispatchHostServiceApiRequest(
151
165
  return withHostResponseHeaders(res, { method: request.method, pathname }, hostDir);
152
166
  }
153
167
 
154
- let service: IService | null = null;
155
- if (hostDir) {
156
- const prevHostDir = process.env.SOMA_HOST_DIR;
157
- try {
158
- process.env.SOMA_HOST_DIR = hostDir;
159
- service = loadHostService(segments);
160
- if (!service) {
161
- const aotResolver = getAotServiceResolver(hostDir);
162
- if (aotResolver) {
163
- const routeKey = segments.join("/");
164
- const resolved = await aotResolver(routeKey, segments);
165
- if (resolved) {
166
- service = resolveServiceExport(resolved, `[aot:${routeKey}]`);
167
- }
168
- }
169
- }
170
- } finally {
171
- if (prevHostDir === undefined) {
172
- delete process.env.SOMA_HOST_DIR;
173
- } else {
174
- process.env.SOMA_HOST_DIR = prevHostDir;
168
+ let service: IService | null = loadHostService(segments, hostDir);
169
+ if (!service && hostDir) {
170
+ const aotResolver = getAotServiceResolver(hostDir);
171
+ if (aotResolver) {
172
+ const routeKey = segments.join("/");
173
+ const resolved = await aotResolver(routeKey, segments);
174
+ if (resolved) {
175
+ service = resolveServiceExport(resolved, `[aot:${routeKey}]`);
175
176
  }
176
177
  }
177
- } else {
178
- service = loadHostService(segments);
179
178
  }
180
179
 
181
180
  if (!service) {
@@ -201,10 +200,10 @@ export async function dispatchHostServiceApiRequest(
201
200
  const response = await handlerFn.call(service, polyfilledReq);
202
201
  return withHostResponseHeaders(response, { method: request.method, pathname }, hostDir);
203
202
  } catch (e: unknown) {
204
- const message = e instanceof Error ? e.message : String(e);
205
- console.error(`[soma-core][接口] ${method} /api/${segments.join("/")}:`, message);
203
+ const eventId = randomUUID();
204
+ console.error(`[soma-core][接口][eventId=${eventId}] ${method} /api/${segments.join("/")}:`, e);
206
205
  const res = Response.json(
207
- { error: message || "Internal server error" },
206
+ { error: "Internal server error", eventId },
208
207
  { status: 500 },
209
208
  );
210
209
  return withHostResponseHeaders(res, { method: request.method, pathname }, hostDir);
@@ -9,6 +9,7 @@ import {
9
9
  getSomaHostSourceRoot,
10
10
  } from "../host/source-packages";
11
11
  import { ensureNodeServerOnlyInterop, getJitiFactory } from "../host/host-assembly";
12
+ import { currentHostDir } from "../host/host-dir";
12
13
 
13
14
  export type AotServiceResolver = (routeKey: string, segments: readonly string[]) => unknown | Promise<unknown>;
14
15
 
@@ -143,12 +144,12 @@ function getJitiLoader(
143
144
  /**
144
145
  * 按约定从宿主 apiRoot 加载 IService 实例(运行时按需加载,零手动 registry)。
145
146
  */
146
- export function loadHostService(segments: string[]): IService | null {
147
+ export function loadHostService(segments: string[], hostDir?: string): IService | null {
147
148
  if (typeof process !== "undefined" && process.env.NEXT_RUNTIME === "edge") return null;
148
- const hostDir = process.env.SOMA_HOST_DIR;
149
- if (!hostDir) return null;
149
+ const resolvedHostDir = hostDir || currentHostDir();
150
+ if (!resolvedHostDir) return null;
150
151
 
151
- const normalizedHostDir = path.resolve(hostDir);
152
+ const normalizedHostDir = path.resolve(resolvedHostDir);
152
153
  const routeKey = segments.join("/");
153
154
 
154
155
  // 1. AOT 预编译服务快速命中(零磁盘、零 jiti)
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Server-side compile-port entry (subpath `soma-core/server/compile-port`, 06e §2.10).
3
3
  *
4
- * core 不持有编译器,也不回调方言编译器:方言(soma-ui / soma-lite)在运行期把自己的页面编译成标准格式后按 URL 注入 core。
4
+ * core 不持有编译器,也不回调方言编译器:方言(soma-ui / soma-kit)在运行期把自己的页面编译成标准格式后按 URL 注入 core。
5
5
  * 这里只剩编译用途闭集与页面生成资产来源的类型。
6
6
  *
7
7
  * 刻意不 `import 'server-only'`(与 `server/page-declaration.ts` 同一理由):宿主的 `soma.app.ts`
@@ -1,6 +1,7 @@
1
1
  import fs from 'node:fs';
2
2
  import yaml from 'js-yaml';
3
3
  import { resolveHostAppConfigPath } from './host-config-paths';
4
+ import { currentHostDir } from './host-dir';
4
5
 
5
6
  type AppConfigRecord = Record<string, unknown>;
6
7
 
@@ -70,7 +71,7 @@ export function composeAppConfigYaml(
70
71
  }
71
72
 
72
73
  /** Browser metadata uses the Host App's displayName, never a source-package brand. */
73
- export function readHostAppDisplayName(hostDir = process.env.SOMA_HOST_DIR): string {
74
+ export function readHostAppDisplayName(hostDir = currentHostDir()): string {
74
75
  if (!hostDir) {
75
76
  return '';
76
77
  }
@@ -3,6 +3,7 @@
3
3
  // 宿主壳(host-next)经这里加载装配、登记自己的路由、解析登录页路径;不再直接改装配对象,也不深导入 core 内部文件。
4
4
  export {
5
5
  loadHostAssembly,
6
+ invalidateHostAssembly,
6
7
  runHostStartup,
7
8
  isHostAssemblyReady,
8
9
  assertReservedRoutesShape,
@@ -70,16 +70,22 @@ const HOLDER_KEY = Symbol.for('soma.core.hostAssemblyHolder');
70
70
  interface Holder {
71
71
  readonly cache: Map<string, LoadedApp | null>;
72
72
  readonly ready: Set<string>;
73
+ /** 当前代可共享的 server() Promise */
73
74
  readonly pendingServer: Map<string, Promise<void>>;
75
+ /** 同一应用根的跨代 server() 顺序屏障,防止旧代晚完成覆盖新代副作用 */
76
+ readonly serverBarrier: Map<string, Promise<void>>;
77
+ readonly generations: Map<string, number>;
74
78
  readonly startups: Map<string, Promise<void>>;
75
79
  }
76
80
  const holder: Holder = ((globalThis as Record<symbol, unknown>)[HOLDER_KEY] ??= {
77
81
  cache: new Map<string, LoadedApp | null>(),
78
82
  ready: new Set<string>(),
79
83
  pendingServer: new Map<string, Promise<void>>(),
84
+ serverBarrier: new Map<string, Promise<void>>(),
85
+ generations: new Map<string, number>(),
80
86
  startups: new Map<string, Promise<void>>(),
81
87
  }) as Holder;
82
- const { cache, ready, pendingServer, startups } = holder;
88
+ const { cache, ready, pendingServer, serverBarrier, generations, startups } = holder;
83
89
 
84
90
  function isRecord(value: unknown): value is Record<string, unknown> {
85
91
  return value !== null && typeof value === 'object' && !Array.isArray(value);
@@ -281,6 +287,7 @@ function loadAppSync(appRoot: string): LoadedApp | null {
281
287
  const coreDir = resolveSelfCoreDir();
282
288
  const loader = createJiti(path.resolve(key, 'package.json'), {
283
289
  interopDefault: false,
290
+ moduleCache: false,
284
291
  requireCache: false,
285
292
  alias: {
286
293
  '@soma-host': hostRoot,
@@ -304,13 +311,38 @@ export async function loadHostAssembly(appRoot: string): Promise<SomaHostAssembl
304
311
  const key = path.resolve(appRoot);
305
312
  const app = loadAppSync(key);
306
313
  if (app === null) return null;
314
+ const generation = generations.get(key) ?? 0;
307
315
  if (app.server !== undefined && !ready.has(key)) {
308
316
  let pending = pendingServer.get(key);
309
317
  if (pending === undefined) {
310
- pending = app.server().then(() => { ready.add(key); }, (error) => { pendingServer.delete(key); throw error; });
318
+ const previous = serverBarrier.get(key);
319
+ pending = (async () => {
320
+ if (previous !== undefined) await previous.catch(() => {});
321
+ // 等旧代的服务端副作用结算期间又发生了失效:不启动已经过期的装配。
322
+ if ((generations.get(key) ?? 0) !== generation) return;
323
+ await app.server!();
324
+ if ((generations.get(key) ?? 0) === generation) ready.add(key);
325
+ })();
311
326
  pendingServer.set(key, pending);
327
+ serverBarrier.set(key, pending);
328
+ const clearBarrier = () => {
329
+ if (serverBarrier.get(key) === pending) serverBarrier.delete(key);
330
+ };
331
+ void pending.then(clearBarrier, () => {
332
+ if ((generations.get(key) ?? 0) === generation && pendingServer.get(key) === pending) {
333
+ pendingServer.delete(key);
334
+ }
335
+ clearBarrier();
336
+ });
337
+ }
338
+ try {
339
+ await pending;
340
+ } catch (error) {
341
+ if ((generations.get(key) ?? 0) !== generation) return loadHostAssembly(key);
342
+ throw error;
312
343
  }
313
- await pending;
344
+ // 同步 load() 已读出的装配若在等待期间被失效,旧调用方也只能收到当前代结果。
345
+ if ((generations.get(key) ?? 0) !== generation) return loadHostAssembly(key);
314
346
  }
315
347
  return app.host;
316
348
  }
@@ -345,8 +377,20 @@ export function isHostAssemblyReady(appRoot: string): boolean {
345
377
 
346
378
  /** 只给测试用:清空装配缓存 */
347
379
  export function resetHostAssemblyCache(): void {
380
+ const keys = new Set([...cache.keys(), ...pendingServer.keys(), ...serverBarrier.keys()]);
381
+ for (const key of keys) generations.set(key, (generations.get(key) ?? 0) + 1);
348
382
  cache.clear();
349
383
  ready.clear();
350
384
  pendingServer.clear();
385
+ // 保留未结算的 serverBarrier:后续装配必须等旧代副作用结束。
351
386
  startups.clear();
352
387
  }
388
+
389
+ /** 清除单个应用的装配缓存(热更新重装配用);启动钩子记忆仍按进程保留一次 */
390
+ export function invalidateHostAssembly(appRoot: string): void {
391
+ const key = path.resolve(appRoot);
392
+ generations.set(key, (generations.get(key) ?? 0) + 1);
393
+ cache.delete(key);
394
+ ready.delete(key);
395
+ pendingServer.delete(key);
396
+ }
@@ -6,6 +6,7 @@
6
6
  // 装配的服务端面装配失败属于「拒绝启动」,仍原样上抛。
7
7
  import { loadHostAssembly } from './host-assembly';
8
8
  import { readAccessIdentity } from '../runtime-space/access-gate';
9
+ import { currentHostDir } from './host-dir';
9
10
 
10
11
  export interface SomaHostCaller {
11
12
  readonly signedIn: boolean;
@@ -39,7 +40,7 @@ export function readHostCaller(raw: unknown): SomaHostCaller {
39
40
  /** 解析这次请求的调用方;装配的 `identity` 抛错按匿名处理 */
40
41
  export async function resolveHostCaller(
41
42
  request: Request | undefined,
42
- hostDir: string | undefined = process.env.SOMA_HOST_DIR,
43
+ hostDir: string | undefined = currentHostDir(),
43
44
  ): Promise<SomaHostCaller> {
44
45
  if (request === undefined || hostDir === undefined || hostDir.trim() === '') return ANONYMOUS;
45
46
  const assembly = await loadHostAssembly(hostDir);
@@ -0,0 +1,9 @@
1
+ // 宿主根的唯一读取点:`SOMA_HOST_DIR`(缺省不设)。
2
+ // 无依赖的小模块,供底层模块直接引用而不引入循环;`runtime-space/bindings.ts` 从这里再导出。
3
+ import path from 'node:path';
4
+
5
+ /** 宿主根(SOMA_HOST_DIR,未设或空白 → undefined;否则 path.resolve 后的绝对路径) */
6
+ export function currentHostDir(): string | undefined {
7
+ const configured = process.env.SOMA_HOST_DIR;
8
+ return configured !== undefined && configured.trim() !== '' ? path.resolve(configured) : undefined;
9
+ }
@@ -5,6 +5,7 @@
5
5
  // 同名头以装配返回值为准。core 不认识具体头,也不替业务挑选类型(图片除外之类的取舍在装配的回调里写)。
6
6
  import { loadHostAssembly } from './host-assembly';
7
7
  import type { SomaHostResponseHeadersContext } from '../../shared/types/host-assembly.types';
8
+ import { currentHostDir } from './host-dir';
8
9
 
9
10
  /** 按路径分类:`/api/*` → api;`/_next/*`、`/soma-runtime/*`、`/favicon.ico`、带文件扩展名的路径 → asset;其余 → page */
10
11
  export function classifyHostResponseKind(pathname: string): SomaHostResponseHeadersContext['kind'] {
@@ -21,7 +22,7 @@ export function classifyHostResponseKind(pathname: string): SomaHostResponseHead
21
22
  */
22
23
  export async function resolveHostResponseHeaders(
23
24
  request: { readonly method: string; readonly pathname: string },
24
- hostDir: string | undefined = process.env.SOMA_HOST_DIR,
25
+ hostDir: string | undefined = currentHostDir(),
25
26
  ): Promise<Readonly<Record<string, string>> | undefined> {
26
27
  if (hostDir === undefined || hostDir.trim() === '') return undefined;
27
28
  if (typeof process !== 'undefined' && process.env.NEXT_RUNTIME === 'edge') return undefined;
@@ -1,11 +1,23 @@
1
1
  import { loadHostAssembly } from './host-assembly';
2
2
  import {
3
3
  resolveHostRequestHook,
4
+ type ResolveHostRequestHookOptions,
4
5
  type SomaHostRequestContext,
5
6
  type SomaRequestHook,
6
7
  } from './resolve-host-request-hook';
8
+ import { currentHostDir } from './host-dir';
7
9
 
8
- export type SomaRequestHookResolver = () => Promise<SomaRequestHook | null>;
10
+ export type SomaRequestHookResolver = (
11
+ options?: ResolveHostRequestHookOptions,
12
+ ) => Promise<SomaRequestHook | null>;
13
+
14
+ export interface InvokeHostRequestHookOptions {
15
+ /**
16
+ * 显式传入的主机根目录。
17
+ * 仅当调用方未传时才回退环境变量 process.env.SOMA_HOST_DIR(兼容旧对外导出调用方)。
18
+ */
19
+ readonly hostDir?: string;
20
+ }
9
21
 
10
22
  function requestPathname(path: string): string {
11
23
  try {
@@ -27,16 +39,28 @@ export function isSomaInternalRequestPath(path: string): boolean {
27
39
  export async function invokeHostRequestHook(
28
40
  request: Request,
29
41
  context: SomaHostRequestContext,
30
- resolveHook: SomaRequestHookResolver = resolveHostRequestHook,
42
+ resolveHookOrOptions?: SomaRequestHookResolver | InvokeHostRequestHookOptions,
43
+ maybeOptions?: InvokeHostRequestHookOptions,
31
44
  ): Promise<Response | undefined> {
45
+ const resolveHook: SomaRequestHookResolver =
46
+ typeof resolveHookOrOptions === 'function'
47
+ ? resolveHookOrOptions
48
+ : resolveHostRequestHook;
49
+
50
+ const options: InvokeHostRequestHookOptions | undefined =
51
+ typeof resolveHookOrOptions === 'object' && resolveHookOrOptions !== null
52
+ ? resolveHookOrOptions
53
+ : maybeOptions;
54
+
32
55
  // 有 soma.app.ts 时先等 Host 装配的服务端面完成(装配 S1–S8;失败即拒绝启动,原样上抛):
33
56
  // /soma 内部路径虽不进 Host 钩子,其后的取页 / 编译点同样依赖装配已就绪,所以这一步在分流之前。
34
- const hostDir = process.env.SOMA_HOST_DIR;
57
+ // 显式 hostDir 优先;仅当调用方未传时才回退环境变量 process.env.SOMA_HOST_DIR(兼容对外导出)
58
+ const hostDir = options?.hostDir ?? currentHostDir();
35
59
  if (hostDir !== undefined && hostDir.trim() !== '') await loadHostAssembly(hostDir);
36
60
  if (isSomaInternalRequestPath(context.path)) {
37
61
  return undefined;
38
62
  }
39
63
 
40
- const hook = await resolveHook();
64
+ const hook = await resolveHook({ hostDir });
41
65
  return hook?.(request, context);
42
66
  }
@@ -6,6 +6,7 @@
6
6
  // (见 published-page-artifact-cache.ts)。
7
7
  // 2. 产物随编译器漂移。存档的编译身份与当前不等是**第一级**:只记提示(一次),不重编——何时用新编译器重编,由维护者显式重发布决定(D63)。
8
8
 
9
+ import { SomaError } from '../../shared/soma-error';
9
10
  import { publishedPageSlugFromPath } from '../../shared/published-page-route';
10
11
  import { getPageRegistryRepository } from '../registry/page-registry-repository';
11
12
  import { currentComponentSupply } from '../registry/component-supply';
@@ -21,7 +22,7 @@ export const registryPageNameFromPath = publishedPageSlugFromPath;
21
22
  * 整页错误(页面主题整体解析失败等,端口给的整页失败):不存档、不缓存,Host 路由据此回受控文案 + 诊断码,
22
23
  * 而不是静默替换成平台默认主题或把整页混成 404。`message` 是对访客的受控文案(不含内部细节),细节在 `diagnostics`。
23
24
  */
24
- export class SomaPublishedPageError extends Error {
25
+ export class SomaPublishedPageError extends SomaError {
25
26
  readonly code: string;
26
27
  readonly diagnostics: readonly SomaGenerationErrorShape[];
27
28