soma-core 1.3.5 → 1.4.1

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 (169) hide show
  1. package/README.md +20 -7
  2. package/app/SomaPageClient.tsx +4 -4
  3. package/app/components/SomaHostPage.tsx +5 -5
  4. package/app/components/SomaHydrationShell.tsx +4 -7
  5. package/app/globals.css +126 -3
  6. package/core/build/{v2 → blocks}/block-compile.ts +47 -18
  7. package/core/build/{v2/soma-file-loader.ts → blocks/block-container.ts} +28 -37
  8. package/core/build/{v2 → blocks}/block-loader.ts +1 -1
  9. package/core/build/{v2 → blocks}/html-index.ts +1 -1
  10. package/core/build/{v2/migrate-v1.ts → blocks/migrate-flat.ts} +27 -27
  11. package/core/build/compiler/host-config-sync.cjs +2 -9
  12. package/core/build/compiler/page-declaration-compiler.ts +32 -4
  13. package/core/build/compiler/soma-manifest-webpack-plugin.js +1 -1
  14. package/core/build/compiler/soma-precompile.js +2057 -35
  15. package/core/build/compiler/soma-precompile.ts +2 -2
  16. package/core/build/component/component-graph.ts +208 -0
  17. package/core/build/eject/component-eject.ts +473 -0
  18. package/core/build/eject/component-upgrade.ts +359 -0
  19. package/core/build/layout/constraint-solver.ts +235 -0
  20. package/core/build/layout/css-emitter.ts +116 -0
  21. package/core/build/layout/page-layout.ts +85 -0
  22. package/core/build/pack/pack-init.ts +265 -0
  23. package/core/client/base/SomaPageRootBase.ts +61 -0
  24. package/core/client/component/ai-catalog.ts +83 -8
  25. package/core/client/component/component-defaults.ts +100 -0
  26. package/core/client/component/component-definition.types.ts +39 -0
  27. package/core/client/component/component-manager.ts +79 -4
  28. package/core/client/component/component-pack.ts +126 -2
  29. package/core/client/component/contract-compat.ts +32 -3
  30. package/core/client/component/{example-v2.ts → example-blocks.ts} +19 -19
  31. package/core/client/component/keyboard-matrix.ts +144 -0
  32. package/core/client/component/pack-styles.ts +59 -1
  33. package/core/client/component/style-features.ts +131 -0
  34. package/core/client/component/theme-component-tokens.ts +83 -0
  35. package/core/client/data/data-object-resolver.ts +407 -4
  36. package/core/client/data/reaction-engine.ts +176 -0
  37. package/core/client/data/window-engine.ts +477 -0
  38. package/core/client/engine/event-engine.ts +98 -0
  39. package/core/client/engine/soma-bootstrap.ts +286 -7
  40. package/core/client/engine/step-runner.ts +134 -0
  41. package/core/client/engine/style-binder.ts +1 -1
  42. package/core/client/infra/notify/DomNotifyService.ts +2 -1
  43. package/core/client/infra/notify/INotifyTheme.ts +1 -1
  44. package/core/client/parser/{v2 → blocks}/namespace.ts +1 -1
  45. package/core/client/parser/{v2 → blocks}/page-parser.ts +30 -16
  46. package/core/client/parser/{v2 → blocks}/use-parser.ts +24 -25
  47. package/core/client/parser/data-config-parser.ts +316 -8
  48. package/core/client/parser/duration.ts +16 -0
  49. package/core/client/parser/layout-parser.ts +157 -0
  50. package/core/client/parser/page-state-parser.ts +166 -0
  51. package/core/client/parser/pipeline-parser.ts +76 -1
  52. package/core/client/parser/reaction-parser.ts +459 -0
  53. package/core/client/parser/reaction-sugar.ts +47 -0
  54. package/core/client/parser/step-parser.ts +359 -0
  55. package/core/client/parser/style-config-parser.ts +7 -7
  56. package/core/client/parser/ui-config-parser.ts +59 -0
  57. package/core/client/parser/value-lang.ts +1 -1
  58. package/core/client/parser/window-parser.ts +294 -0
  59. package/core/client/registry/index.ts +8 -0
  60. package/core/client/theme/theme-engine.ts +144 -16
  61. package/core/client/typography/typography-base.ts +1 -1
  62. package/core/index.ts +188 -13
  63. package/core/server/host/csp-nonce-metadata.ts +1 -1
  64. package/core/server/host/published-page-assets.ts +3 -8
  65. package/core/server/host/soma-page-compile.ts +1 -1
  66. package/core/server/index.ts +2 -2
  67. package/core/shared/block-errors.ts +11 -0
  68. package/core/shared/calc/coerce.ts +29 -0
  69. package/core/shared/calc/errors.ts +43 -0
  70. package/core/shared/calc/evaluator.ts +101 -0
  71. package/core/shared/calc/index.ts +12 -0
  72. package/core/shared/calc/lexer.ts +194 -0
  73. package/core/shared/calc/parser.ts +204 -0
  74. package/core/shared/calc/typer.ts +184 -0
  75. package/core/shared/path-algebra.ts +169 -0
  76. package/core/shared/predicates/index.ts +527 -0
  77. package/core/shared/published-page-route.ts +61 -0
  78. package/core/shared/types/adaptive.types.ts +1 -1
  79. package/core/shared/types/component-contract.types.ts +128 -2
  80. package/core/shared/types/data-config.types.ts +149 -2
  81. package/core/shared/types/domain.types.ts +13 -0
  82. package/core/shared/types/event.types.ts +22 -2
  83. package/core/shared/types/layout-constraint.types.ts +73 -0
  84. package/core/shared/types/page-state.types.ts +60 -0
  85. package/core/shared/types/reaction.types.ts +144 -0
  86. package/core/shared/types/scope-manifest.types.ts +11 -15
  87. package/core/shared/types/step.types.ts +91 -0
  88. package/core/shared/types/style-config.types.ts +4 -4
  89. package/core/shared/types/ui-config.types.ts +18 -0
  90. package/core/shared/types/window.types.ts +177 -0
  91. package/dist/cli/soma.js +28 -3
  92. package/dist/core/index.cjs +4829 -405
  93. package/dist/types/build/{v2 → blocks}/block-compile.d.ts +7 -7
  94. package/dist/types/build/{v2/soma-file-loader.d.ts → blocks/block-container.d.ts} +6 -11
  95. package/dist/types/build/{v2/migrate-v1.d.ts → blocks/migrate-flat.d.ts} +6 -6
  96. package/dist/types/build/compiler/page-declaration-compiler.d.ts +2 -0
  97. package/dist/types/build/component/component-graph.d.ts +85 -0
  98. package/dist/types/build/eject/component-eject.d.ts +121 -0
  99. package/dist/types/build/eject/component-upgrade.d.ts +43 -0
  100. package/dist/types/build/layout/constraint-solver.d.ts +36 -0
  101. package/dist/types/build/layout/css-emitter.d.ts +18 -0
  102. package/dist/types/build/layout/page-layout.d.ts +24 -0
  103. package/dist/types/build/pack/pack-init.d.ts +8 -0
  104. package/dist/types/client/base/SomaPageRootBase.d.ts +28 -0
  105. package/dist/types/client/component/ai-catalog.d.ts +24 -1
  106. package/dist/types/client/component/component-defaults.d.ts +15 -0
  107. package/dist/types/client/component/component-definition.types.d.ts +38 -0
  108. package/dist/types/client/component/component-manager.d.ts +36 -0
  109. package/dist/types/client/component/component-pack.d.ts +32 -2
  110. package/dist/types/client/component/contract-compat.d.ts +2 -2
  111. package/dist/types/client/component/example-blocks.d.ts +9 -0
  112. package/dist/types/client/component/keyboard-matrix.d.ts +24 -0
  113. package/dist/types/client/component/pack-styles.d.ts +21 -0
  114. package/dist/types/client/component/style-features.d.ts +26 -0
  115. package/dist/types/client/component/theme-component-tokens.d.ts +14 -0
  116. package/dist/types/client/data/data-object-resolver.d.ts +106 -1
  117. package/dist/types/client/data/reaction-engine.d.ts +21 -0
  118. package/dist/types/client/data/window-engine.d.ts +27 -0
  119. package/dist/types/client/engine/event-engine.d.ts +15 -0
  120. package/dist/types/client/engine/soma-bootstrap.d.ts +70 -0
  121. package/dist/types/client/engine/step-runner.d.ts +24 -0
  122. package/dist/types/client/infra/notify/DomNotifyService.d.ts +2 -1
  123. package/dist/types/client/infra/notify/INotifyTheme.d.ts +1 -1
  124. package/dist/types/client/parser/{v2 → blocks}/page-parser.d.ts +2 -2
  125. package/dist/types/client/parser/{v2 → blocks}/use-parser.d.ts +3 -3
  126. package/dist/types/client/parser/duration.d.ts +1 -0
  127. package/dist/types/client/parser/layout-parser.d.ts +9 -0
  128. package/dist/types/client/parser/page-state-parser.d.ts +32 -0
  129. package/dist/types/client/parser/reaction-parser.d.ts +16 -0
  130. package/dist/types/client/parser/reaction-sugar.d.ts +13 -0
  131. package/dist/types/client/parser/step-parser.d.ts +23 -0
  132. package/dist/types/client/parser/style-config-parser.d.ts +1 -1
  133. package/dist/types/client/parser/ui-config-parser.d.ts +5 -0
  134. package/dist/types/client/parser/window-parser.d.ts +25 -0
  135. package/dist/types/client/registry/index.d.ts +1 -0
  136. package/dist/types/client/theme/theme-engine.d.ts +37 -0
  137. package/dist/types/index.d.ts +40 -9
  138. package/dist/types/server/host/published-page-assets.d.ts +3 -2
  139. package/dist/types/server/index.d.ts +1 -1
  140. package/dist/types/shared/block-errors.d.ts +5 -0
  141. package/dist/types/shared/calc/coerce.d.ts +4 -0
  142. package/dist/types/shared/calc/errors.d.ts +14 -0
  143. package/dist/types/shared/calc/evaluator.d.ts +2 -0
  144. package/dist/types/shared/calc/index.d.ts +6 -0
  145. package/dist/types/shared/calc/lexer.d.ts +20 -0
  146. package/dist/types/shared/calc/parser.d.ts +49 -0
  147. package/dist/types/shared/calc/typer.d.ts +16 -0
  148. package/dist/types/shared/path-algebra.d.ts +56 -0
  149. package/dist/types/shared/predicates/index.d.ts +79 -0
  150. package/dist/types/shared/published-page-route.d.ts +21 -0
  151. package/dist/types/shared/types/component-contract.types.d.ts +112 -0
  152. package/dist/types/shared/types/data-config.types.d.ts +132 -2
  153. package/dist/types/shared/types/domain.types.d.ts +12 -0
  154. package/dist/types/shared/types/event.types.d.ts +8 -2
  155. package/dist/types/shared/types/layout-constraint.types.d.ts +52 -0
  156. package/dist/types/shared/types/page-state.types.d.ts +49 -0
  157. package/dist/types/shared/types/reaction.types.d.ts +115 -0
  158. package/dist/types/shared/types/scope-manifest.types.d.ts +11 -11
  159. package/dist/types/shared/types/step.types.d.ts +76 -0
  160. package/dist/types/shared/types/style-config.types.d.ts +4 -4
  161. package/dist/types/shared/types/ui-config.types.d.ts +18 -0
  162. package/dist/types/shared/types/window.types.d.ts +171 -0
  163. package/package.json +2 -6
  164. package/dist/types/client/component/example-v2.d.ts +0 -9
  165. package/postcss.config.js +0 -6
  166. package/tailwind.config.ts +0 -43
  167. /package/dist/types/build/{v2 → blocks}/block-loader.d.ts +0 -0
  168. /package/dist/types/build/{v2 → blocks}/html-index.d.ts +0 -0
  169. /package/dist/types/client/parser/{v2 → blocks}/namespace.d.ts +0 -0
@@ -1,4 +1,6 @@
1
1
  import type { ExtendedShowValue } from '../../../shared/types/ui-config.types';
2
+ import { parseDuration } from '../duration';
3
+ export { parseDuration };
2
4
  import { type BlockScope } from './namespace';
3
5
  export interface DataObjectDecl {
4
6
  localName: string;
@@ -56,7 +58,7 @@ export interface UseBlockAst {
56
58
  /** emit 路由:emit 名 → Pipeline 表达式 */
57
59
  emitRoutes: Record<string, string>;
58
60
  scope: BlockScope;
59
- /** 供 v1 编译管线消费的 props 形态 */
61
+ /** 供既有编译管线消费的 props 形态 */
60
62
  toShowValue(): ExtendedShowValue;
61
63
  }
62
64
  export interface ParseUseInput {
@@ -68,5 +70,3 @@ export interface ParseUseInput {
68
70
  rowVars?: Iterable<string>;
69
71
  }
70
72
  export declare function parseUseBlock(input: ParseUseInput): UseBlockAst;
71
- /** `30s` → 30000;单位封闭 ms/s/m,无单位报错(不猜) */
72
- export declare function parseDuration(raw: string, where: string, fail: (m: string) => never): number;
@@ -0,0 +1 @@
1
+ export declare function parseDuration(raw: string, where: string, fail: (m: string) => never): number;
@@ -0,0 +1,9 @@
1
+ import { type SomaLayoutConstraint } from '../../shared/types/layout-constraint.types';
2
+ export interface LayoutParseInput {
3
+ raw: unknown;
4
+ path: string;
5
+ }
6
+ export interface LayoutParseDeps {
7
+ fail(message: string, path: string): never;
8
+ }
9
+ export declare function parseLayoutConstraint(input: LayoutParseInput, deps: LayoutParseDeps): SomaLayoutConstraint;
@@ -0,0 +1,32 @@
1
+ import type { SomaPageState, SomaPageStateConfig } from '../../shared/types/page-state.types';
2
+ export interface PageStateParseInput {
3
+ raw: unknown;
4
+ /** 已声明的数据对象名(`window` 切片只能指向它们) */
5
+ objectNames: readonly string[];
6
+ /** 页面上的锚点 id(`columns` 切片只能指向它们);不给就跳过这一层校验 */
7
+ anchorIds?: readonly string[];
8
+ path: string;
9
+ }
10
+ export interface PageStateParseDeps {
11
+ fail(message: string, path: string): never;
12
+ }
13
+ export declare function parsePageState(input: PageStateParseInput, deps: PageStateParseDeps): SomaPageStateConfig;
14
+ /**
15
+ * 校验一份具体的状态值(`initial_state`、URL 还原、`setState` 入参共用)。
16
+ *
17
+ * 越界的切片**丢弃并点名**,而不是整份拒收:一份来自旧版本 URL 的状态里多半只有
18
+ * 一两块对不上,整份丢掉等于让分享链接彻底失效——而它本来还能恢复大半。
19
+ */
20
+ export declare function parseStateValue(raw: unknown, path: string, config: SomaPageStateConfig, fail: (message: string, at: string) => never): SomaPageState;
21
+ /**
22
+ * 页面态 ⇄ URL 的紧凑序列化。
23
+ *
24
+ * 用 base64url 包一层 JSON 而不是把每个切片摊成 query 参数:状态是树形的
25
+ * (`window.orders.filter` 是一棵递归 AST),摊平会得到一串 `window.orders.filter.conditions[0].op=in`
26
+ * 这样的东西——既难读,也会撞上 URL 长度与转义的一堆边角。
27
+ *
28
+ * 不用 `btoa`:它只吃 Latin-1,中文过滤值会直接抛。
29
+ */
30
+ export declare function encodePageState(state: SomaPageState): string;
31
+ /** URL → 页面态;坏串返回 null(一条被截断的链接不该让页面打不开) */
32
+ export declare function decodePageState(encoded: string): SomaPageState | null;
@@ -0,0 +1,16 @@
1
+ import type { SomaReactionGraph } from '../../shared/types/reaction.types';
2
+ import type { SomaDataFieldConfig } from '../../shared/types/data-config.types';
3
+ import type { SomaNamedPredicates } from '../../shared/predicates';
4
+ /** 与 data-config-parser 同一个错误类;由调用方注入以免循环依赖 */
5
+ export interface ReactionParseDeps {
6
+ fail(message: string, path: string): never;
7
+ }
8
+ export interface ReactionParseInput {
9
+ raw: unknown;
10
+ fields: Record<string, SomaDataFieldConfig>;
11
+ named: SomaNamedPredicates;
12
+ /** 字段 → 来源接口(读通道 `from[].api`),用于回溯表 */
13
+ sourceApiOf?: Readonly<Record<string, string | undefined>>;
14
+ path: string;
15
+ }
16
+ export declare function parseReactions(input: ReactionParseInput, deps: ReactionParseDeps): SomaReactionGraph;
@@ -0,0 +1,13 @@
1
+ import type { SomaReactionConfig } from '../../shared/types/reaction.types';
2
+ /** 展开所需的最小字段形状(不绑定 UI 侧的字段声明类型) */
3
+ export interface SomaSugarField {
4
+ key: string;
5
+ visible_when?: unknown;
6
+ disabled_when?: unknown;
7
+ }
8
+ /**
9
+ * `visible_when` 不成立时用 `display: none` 而不是 `hidden`——这是**行为等价**的要求:
10
+ * REQ-009 的 FormPanel 对隐藏字段既不渲染、也不校验、也不进提交载荷(`projected` 删键),
11
+ * 而 `hidden` 只是不给看、数据仍在。选错这一档,等价回归会红在提交载荷上。
12
+ */
13
+ export declare function compileFieldSugar(fields: readonly SomaSugarField[]): SomaReactionConfig[];
@@ -0,0 +1,23 @@
1
+ import type { ParsedEvent } from '../../shared/types/event.types';
2
+ import type { SomaStepGraph } from '../../shared/types/step.types';
3
+ export interface StepParseInput {
4
+ raw: unknown;
5
+ /** 事件载荷里的字段名:`when` 的作用域起点 */
6
+ payloadFields: readonly string[];
7
+ /** bootstrap 注册的具名动作;给了就校验 `do: ACTION | <name>` 的名字存在 */
8
+ actionNames?: readonly string[];
9
+ path: string;
10
+ }
11
+ export interface StepParseDeps {
12
+ fail(message: string, path: string): never;
13
+ /**
14
+ * 单条管道的解析器(`pipeline-parser` 的 `parsePipelineBody`)。
15
+ *
16
+ * 由调用方注入而不是直接 import,是为了不成环:`pipeline-parser` 的
17
+ * `parseEventConfig` 要认 `{ steps: [...] }` 形态,于是它得调本模块;
18
+ * 本模块再反向 import 它就构成循环,而循环 import 在 ESM 下"多数时候能跑"
19
+ * ——它坏起来是模块初始化顺序变了之后的一个 undefined,跟本次改动毫无关联。
20
+ */
21
+ parsePipeline(expression: string): Omit<ParsedEvent, 'somaId' | 'domEvent'>;
22
+ }
23
+ export declare function parseSteps(input: StepParseInput, deps: StepParseDeps): SomaStepGraph;
@@ -10,7 +10,7 @@ export declare class SomaStyleConfigError extends Error {
10
10
  *
11
11
  * 校验规则:
12
12
  * - host 必须是非空字符串
13
- * - base 的值必须是纯 Tailwind 类名字符串
13
+ * - base 的值必须是纯 CSS 类名字符串;core 不解析也不编译具体类名
14
14
  * - states 的 condition 必须是纯属性路径,value 必须是基础类型
15
15
  * - transitions 的 trigger 必须是有效枚举值
16
16
  * - base / themes 命中布局类模式即失败;states / transitions 放行显隐对(F-06)
@@ -24,6 +24,11 @@ export interface SomaUiConfigParseOptions {
24
24
  * 所以推迟的是报错时机,不是报错本身。
25
25
  */
26
26
  adaptiveVocabularyRequired?: boolean;
27
+ /**
28
+ * 已声明的数据对象名(`state.window` 切片只能指向它们)。
29
+ * 不给时跳过这一层校验——见 `state` 分支里的说明。
30
+ */
31
+ dataObjectNames?: readonly string[];
27
32
  }
28
33
  /**
29
34
  * 将 YAML 解析后的原始对象转换为类型安全的 UiConfig
@@ -0,0 +1,25 @@
1
+ import { type SomaWindowConfig } from '../../shared/types/window.types';
2
+ import type { SomaDataFieldConfig } from '../../shared/types/data-config.types';
3
+ export interface WindowParseInput {
4
+ raw: unknown;
5
+ fields: Record<string, SomaDataFieldConfig>;
6
+ path: string;
7
+ }
8
+ export interface WindowParseDeps {
9
+ fail(message: string, path: string): never;
10
+ }
11
+ export declare function parseWindow(input: WindowParseInput, deps: WindowParseDeps): SomaWindowConfig;
12
+ /**
13
+ * 字段字典的稳定哈希:字段名 + 类型 + 权限。
14
+ *
15
+ * 随每个请求下发,让后端能拒收「按一份它不认识的字典发来的意图」——这是本层唯一
16
+ * 对方结构上做不到的事(AG Grid 的列是函数,没有可哈希的字典)。
17
+ *
18
+ * 只取名/类型/权限三项:它们决定了**哪些意图是合法的**(能不能排序、能不能求和、
19
+ * 能不能进请求体)。`name` 这类展示位改了不该让后端拒收——那会把一次文案调整变成一次
20
+ * 前后端联合发布。字段先按名排序,声明顺序变化不改哈希,同理。
21
+ *
22
+ * 用 FNV-1a 而不是 sha256:这里要的是「字典变了没有」的指纹,不是抗碰撞的安全摘要,
23
+ * 而 `crypto.subtle` 是异步的——为一个同步的解析步骤引入异步是不划算的交换。
24
+ */
25
+ export declare function dictHash(fields: Record<string, SomaDataFieldConfig>): string;
@@ -8,3 +8,4 @@
8
8
  export { createGeneratedPagePreview, type GeneratedPageDeclarations, type GeneratedPagePreviewOptions, type PrecompiledDeclarationAssets, type PreviewHandle, type PreviewObservabilityOptions, } from './declaration-renderer';
9
9
  export { createSomaPageLifecycle, SomaPageLifecycle, type MountedPageInfo, type RegisterDeclarationOptions, type SomaPageLifecycleOptions, } from './page-lifecycle';
10
10
  export { renderPublishedPage, type PublishedPageHandle, type PublishedPageRecord, type RenderPublishedPageOptions, } from './remote-page';
11
+ export { PUBLISHED_PAGE_SLUG_PATTERN, RESERVED_PUBLISHED_PAGE_SLUGS, isPublishedPageSlug, normalizePublishedPageSlug, publishedPagePath, publishedPageSlugFromPath, } from '../../shared/published-page-route';
@@ -18,6 +18,34 @@ export interface SomaThemeInput {
18
18
  dark?: boolean;
19
19
  /** 逐令牌精调通道:最后合并进 cssVars 与 darkCssVars,优先级最高(亮暗同时生效) */
20
20
  overrides?: Record<string, string>;
21
+ /**
22
+ * 暗色专属精调:只并进 darkCssVars,在 `overrides` **之后**合并(同键胜出)。
23
+ *
24
+ * 为什么需要它:`overrides` 一份表同时盖亮暗两套,等于「一个令牌只能有一个值」。
25
+ * 后果不是理论问题——`soma-ui/src/daisy-presets.ts` 里 daisyLight / daisyDark 因此
26
+ * 被迫拆成两套完整独立预设,而 `ThemeScope` 的 `mode: 'system'` 只认一个预设名,
27
+ * 于是 35 套 daisy 主题的跟随系统亮暗**全部失效**。
28
+ *
29
+ * 缺省不给 = 行为与之前字节级一致(不影响任何既有预设)。
30
+ */
31
+ darkOverrides?: Record<string, string>;
32
+ /**
33
+ * 组件级令牌覆盖(REQ-009 M-1):组件名 → { 令牌名: 值 }。
34
+ *
35
+ * 这是三级令牌的第三级在主题输入侧的入口。它存在的理由:今天想只改 Button 的圆角,
36
+ * 只能改全局 `--soma-radius-control`,于是**所有 control 族**跟着变。
37
+ *
38
+ * 与 MUI 的 `theme.components.MuiX.styleOverrides.<slot>` 的关键差别:
39
+ * 这里能改的只有**组件自己在契约 `tokens` 段声明过的旋钮**,
40
+ * 而不是任意内部元素的任意 CSS 声明。组件内部结构仍然封闭
41
+ * (页面永不可寻址组件内部,`scopeAnchors()` 的既定边界)。
42
+ *
43
+ * 引擎不认识组件,所以这里只做展平;「组件名 / 令牌名是否存在」由装配层的
44
+ * `validateThemeComponentTokens` 在 bootstrap 期核对契约。
45
+ */
46
+ components?: Record<string, Record<string, string>>;
47
+ /** 组件令牌的暗色专属覆盖:与 `darkOverrides` 同一纪律,只并进 darkCssVars */
48
+ darkComponents?: Record<string, Record<string, string>>;
21
49
  }
22
50
  export interface SomaThemeMeta {
23
51
  /** 本次派生实际生效的轴位(含缺省回落)——诊断与测试的观测面 */
@@ -26,6 +54,8 @@ export interface SomaThemeMeta {
26
54
  readonly separationApplied: boolean;
27
55
  /** 被推开的语气 */
28
56
  readonly pushed: readonly SomaToneName[];
57
+ /** 本次写出的组件级令牌变量名(M-1)——快照与闸门的观测面 */
58
+ readonly componentTokens: readonly string[];
29
59
  }
30
60
  export interface SomaDerivedTheme {
31
61
  /** 品牌色阶 50~950(11 档 hex) */
@@ -52,6 +82,13 @@ export declare function hexToOklch(hex: string): Oklch;
52
82
  export declare function oklchToHex(color: Oklch): string;
53
83
  export declare function contrastRatio(hexA: string, hexB: string): number;
54
84
  export declare function deriveTheme(input: SomaThemeInput): SomaDerivedTheme;
85
+ /**
86
+ * 引擎会写出的令牌名全集(静态令牌 + 派生令牌),不跑派生。
87
+ *
88
+ * 给 soma-ui 的 `token-existence-lint` 用:契约 `tokens.default` 引用的语义令牌
89
+ * 必须真的存在,否则组件令牌指向一个空变量,回退值一路生效而没人发现。
90
+ */
91
+ export declare function listThemeTokenNames(): readonly string[];
55
92
  /**
56
93
  * 派生结果 → 根元素属性。
57
94
  *
@@ -9,6 +9,8 @@ export type { SomaPageAssets, SomaBootstrapOptions, SomaBootstrapErrorReporting,
9
9
  export { SomaComponentRegistry } from './client/component/component-registry';
10
10
  export { SomaComponentManager } from './client/component/component-manager';
11
11
  export { generateAiCatalog, buildCatalogEntry } from './client/component/ai-catalog';
12
+ export { deriveKeyboardMatrix, renderKeyboardMatrixLine, SOMA_KEYBOARD_INTENTS, } from './client/component/keyboard-matrix';
13
+ export type { SomaKeyboardIntent, SomaKeyboardMatrixRow } from './client/component/keyboard-matrix';
12
14
  export type { SomaAiCatalog, SomaAiCatalogEntry, GenerateAiCatalogOptions, } from './client/component/ai-catalog';
13
15
  export { SomaPipeRegistry, defaultPipeRegistry } from './client/pipes/pipe-registry';
14
16
  export type { SomaPipeFn, SomaPipeContext } from './client/pipes/pipe-registry';
@@ -16,7 +18,35 @@ export { SomaDataObjectResolver, SomaDataCycleError, isSomaMockEnabled, } from '
16
18
  export type { SomaDataHttpLike, SomaDataResolverOptions, SomaDataResolveResult, } from './client/data/data-object-resolver';
17
19
  export { parseDataConfig, parseDataYaml, parseDataRef, normalizeDataPipeValue, SomaDataConfigError, } from './client/parser/data-config-parser';
18
20
  export type { SomaDataRef } from './client/parser/data-config-parser';
19
- export type { SomaDataConfig, SomaDataObjectConfig, SomaDataSourceConfig, SomaDataFieldConfig, SomaDataFieldRule, SomaDataFieldOption, SomaDataFieldType, SomaDataFieldPermission, SomaDataDicts, } from './shared/types/data-config.types';
21
+ export type { SomaDataConfig, SomaDataObjectConfig, SomaDataSourceConfig, SomaDataFieldConfig, SomaDataFieldRule, SomaDataFieldOption, SomaDataFieldType, SomaDataFieldPermission, SomaDataDicts, SomaDataWriteConfig, SomaDataWriteEndpoint, SomaDataSubmitResult, SomaDataPort, } from './shared/types/data-config.types';
22
+ export { SOMA_DATA_FIELD_TYPES, SOMA_DATA_FIELD_TYPE_ALIASES, } from './shared/types/data-config.types';
23
+ export { SOMA_FIELD_PREDICATE_OPS, evaluatePredicate, validatePredicate, validateNamedPredicates, collectPredicateFields, } from './shared/predicates';
24
+ export type { SomaFieldPredicateOp, SomaFieldCondition, SomaFieldPredicateRef, SomaFieldPredicateAllOf, SomaFieldPredicateAnyOf, SomaFieldPredicateNoneOf, SomaFieldPredicate, SomaNamedPredicates, SomaPredicateValidateOptions, } from './shared/predicates';
25
+ export { parseCalc, collectCalcRefs, inferCalcType, assertCalcResultType, evaluateCalc, SomaCalcSyntaxError, SomaCalcTypeError, CALC_FUNCTIONS, } from './shared/calc';
26
+ export type { CalcAst, CalcType, CalcTypeContext, CalcSpan } from './shared/calc';
27
+ export { parseReactions } from './client/parser/reaction-parser';
28
+ export { compileFieldSugar } from './client/parser/reaction-sugar';
29
+ export type { SomaSugarField } from './client/parser/reaction-sugar';
30
+ export { runReactions, explainField } from './client/data/reaction-engine';
31
+ export { parseWindow, dictHash } from './client/parser/window-parser';
32
+ export { createWindow } from './client/data/window-engine';
33
+ export { parseSteps } from './client/parser/step-parser';
34
+ export type { StepParseInput, StepParseDeps } from './client/parser/step-parser';
35
+ export { runSteps } from './client/engine/step-runner';
36
+ export { parsePageState, parseStateValue, encodePageState, decodePageState, } from './client/parser/page-state-parser';
37
+ export { isListPath, parseListPath, expandListPath, readListPath, validateListPath, SomaPathError, } from './shared/path-algebra';
38
+ export type { SomaListPath, SomaPathSelector } from './shared/path-algebra';
39
+ export { parseLayoutConstraint } from './client/parser/layout-parser';
40
+ export { SOMA_LAYOUT_PRIORITIES, SOMA_LAYOUT_ALIGNS } from './shared/types/layout-constraint.types';
41
+ export type { SomaSizing, SomaPriority, SomaWrap, SomaAlign, SomaLayoutNodeConstraint, SomaLayoutConstraint, SomaLayoutSolution, SomaLayoutPlan, } from './shared/types/layout-constraint.types';
42
+ export type { SomaPageState, SomaPageStateConfig, SomaWindowStateSlice, SomaColumnStateSlice, } from './shared/types/page-state.types';
43
+ export type { StepRunContext, StepRunResult } from './client/engine/step-runner';
44
+ export type { SomaStep, SomaDoStep, SomaSwitchStep, SomaParallelStep, SomaForEachStep, SomaStepOnError, SomaStepSlot, SomaCompiledStep, SomaStepGraph, } from './shared/types/step.types';
45
+ export type { SomaWindowHttpLike, SomaWindowDeps } from './client/data/window-engine';
46
+ export { SOMA_AGGREGATE_FNS, SOMA_SELECT_ALL_MODES } from './shared/types/window.types';
47
+ export type { SomaFilterNode, SomaWindowSort, SomaAggregateFn, SomaWindowAggregate, SomaSelectAllMode, SomaWindowSelection, SomaWindowBlockConfig, SomaWindowConfig, SomaWindowRequest, SomaWindowResponse, SomaWindowRequestPatch, SomaWindowHandle, SomaTransaction, } from './shared/types/window.types';
48
+ export { SOMA_REACTION_PHASES, SOMA_FIELD_DISPLAYS, SOMA_FIELD_PATTERNS, SOMA_REACTION_FORM_KEY, } from './shared/types/reaction.types';
49
+ export type { SomaReactionPhase, SomaFieldDisplay, SomaFieldPattern, SomaFieldValuePatch, SomaFieldStatePatch, SomaFormStatePatch, SomaReactionConfig, SomaCompiledReaction, SomaFieldProvenance, SomaReactionGraph, SomaReactionResult, } from './shared/types/reaction.types';
20
50
  export { deriveTheme, applyTheme, contrastRatio, THEME_SWITCHING_CLASS, } from './client/theme/theme-engine';
21
51
  export type { SomaThemeInput, SomaDerivedTheme, SomaThemeMeta } from './client/theme/theme-engine';
22
52
  export { themeRootAttributes } from './client/theme/theme-engine';
@@ -29,8 +59,9 @@ export type { SomaAdaptiveProfile, SomaAdaptiveConfig, SomaAdaptiveLevel, SomaAd
29
59
  export { createAdaptiveObserverPool, scheduleAdaptiveFlush, resolveTierWithHysteresis, SOMA_DEFAULT_HYSTERESIS, } from './client/adaptive/index';
30
60
  export type { SomaAdaptiveObserverPool, SomaAdaptiveSize, SomaAdaptiveSizeCallback, SomaAdaptiveTask, } from './client/adaptive/index';
31
61
  export type { SomaComponentDefinition, SomaComponentControllerContext, SomaComponentControllerFactory, } from './client/component/component-definition.types';
32
- export type { SomaComponentContract, SomaComponentLayer, SomaGeometryFamily, SomaContractProp, SomaContractEmit, SomaContractSlot, } from './shared/types/component-contract.types';
62
+ export type { SomaComponentContract, SomaComponentLayer, SomaGeometryFamily, SomaContractProp, SomaContractEmit, SomaContractSlot, SomaContractKeyboard, SomaContractOverlay, SomaContractToken, } from './shared/types/component-contract.types';
33
63
  export { findNestedMutableContractDefault } from './shared/types/component-contract.types';
64
+ export { componentTokenPrefix, componentTokenVar, COMPONENT_TOKEN_KEY_PATTERN, } from './shared/types/component-contract.types';
34
65
  export { createDefaultRuntimeServices } from './client/runtime/SomaRuntimeServices';
35
66
  export type { SomaRuntimeServices } from './client/runtime/SomaRuntimeServices';
36
67
  export { SomaDiagnostics } from './client/diagnostics/SomaDiagnostics';
@@ -68,16 +99,16 @@ export { resolveHostBootstrapOptions } from './client/host-bridge/resolve-host-b
68
99
  export type { SomaHostRequestContext, SomaHostRequestKind, SomaRequestHook, } from './server/host/resolve-host-request-hook';
69
100
  export type { SomaDomainLoadContext, SomaDomainLoader, SomaDomainLoaderMap, SomaDomainLoaderModule, SomaDomainModule, SomaDomainModuleResolver, } from './client/host-bridge/soma-domain-loaders';
70
101
  export { createSomaDomainLoaderKey, findSomaDomainLoader, loadSomaDomainModuleFromRegistry, } from './client/host-bridge/soma-domain-loaders';
71
- export { createGeneratedPagePreview, createSomaPageLifecycle, renderPublishedPage, SomaPageLifecycle, type GeneratedPageDeclarations, type GeneratedPagePreviewOptions, type PrecompiledDeclarationAssets, type PreviewHandle, type PreviewObservabilityOptions, type MountedPageInfo, type PublishedPageHandle, type PublishedPageRecord, type RegisterDeclarationOptions, type RenderPublishedPageOptions, type SomaPageLifecycleOptions, } from './client/registry/index';
102
+ export { createGeneratedPagePreview, createSomaPageLifecycle, renderPublishedPage, SomaPageLifecycle, type GeneratedPageDeclarations, type GeneratedPagePreviewOptions, type PrecompiledDeclarationAssets, type PreviewHandle, type PreviewObservabilityOptions, type MountedPageInfo, type PublishedPageHandle, type PublishedPageRecord, type RegisterDeclarationOptions, type RenderPublishedPageOptions, type SomaPageLifecycleOptions, PUBLISHED_PAGE_SLUG_PATTERN, RESERVED_PUBLISHED_PAGE_SLUGS, isPublishedPageSlug, normalizePublishedPageSlug, publishedPagePath, publishedPageSlugFromPath, } from './client/registry/index';
72
103
  export { composeComponentPacks, generatePackCatalog, ComponentPackError, PACK_NAME_PATTERN, type ComposedComponentPacks, type ComposePacksOptions, type SomaComponentPack, type SomaComponentPackStyles, type PackOverrideEvent, } from './client/component/component-pack';
73
104
  export { verifyComponentPack, type VerifyPackOptions } from './client/component/verify-pack';
74
105
  export { parseValueSegment, evaluateValueNode, isArithSegment, isPlainPath, describeNode, SomaValueLangError, type ValueNode, type PipedValue, type ValuePosition, type HasVarFn, type EvalOptions, } from './client/parser/value-lang';
75
- export { loadSomaFile, SomaV2ParseError, PAGE_BLOCK_ID, type RawBlock, type SomaFileLoadInput, } from './build/v2/soma-file-loader';
76
- export { buildHtmlAnchorIndex, type HtmlAnchorIndex, type HtmlAnchorInfo, } from './build/v2/html-index';
106
+ export { loadSomaFile, SomaBlockParseError, PAGE_BLOCK_ID, type RawBlock, type SomaFileLoadInput, } from './build/blocks/block-container';
107
+ export { buildHtmlAnchorIndex, type HtmlAnchorIndex, type HtmlAnchorInfo, } from './build/blocks/html-index';
77
108
  export { compilePageAssets } from './build/compiler/page-assets';
78
- export { compileSomaV2, type CompiledSomaV2, type CompileSomaV2Input, } from './build/v2/block-compile';
79
- export { parsePageBlock, type PageBlockAst, } from './client/parser/v2/page-parser';
80
- export { parseUseBlock, type UseBlockAst, type DataObjectDecl, type FieldDecl, type ActionDecl, } from './client/parser/v2/use-parser';
81
- export { buildBlockScope, resolvePath, resolveApiRef, expandPath, scopeHasVar, SomaScopeError, type BlockScope, } from './client/parser/v2/namespace';
109
+ export { compileSomaBlocks, type CompiledSomaBlocks, type CompileSomaBlocksInput, } from './build/blocks/block-compile';
110
+ export { parsePageBlock, type PageBlockAst, } from './client/parser/blocks/page-parser';
111
+ export { parseUseBlock, type UseBlockAst, type DataObjectDecl, type FieldDecl, type ActionDecl, } from './client/parser/blocks/use-parser';
112
+ export { buildBlockScope, resolvePath, resolveApiRef, expandPath, scopeHasVar, SomaScopeError, type BlockScope, } from './client/parser/blocks/namespace';
82
113
  export { checkOverrideCompat, type ContractCompatIssue, type ContractCompatIssueKind, } from './client/component/contract-compat';
83
114
  export { attachPackStyles, ensurePackBaseStyles, resetPackStyleInjection, type PackStyleOptions, } from './client/component/pack-styles';
@@ -1,5 +1,6 @@
1
- /** `/pages/<registry-name>` 是发布声明的稳定浏览路径;更深层路径仍归普通 Host 页面。 */
2
- export declare function registryPageNameFromPath(pagePath: string): string | null;
1
+ import { publishedPageSlugFromPath } from '../../shared/published-page-route';
2
+ /** Registry `myworkspace` 的正式地址是 `/myworkspace`;兼容读取旧 `/pages/myworkspace`。 */
3
+ export declare const registryPageNameFromPath: typeof publishedPageSlugFromPath;
3
4
  /** Registry 声明只在服务端编译,浏览器收到的仍是既有运行时资产。 */
4
5
  export declare function loadPublishedRegistryPageAssets(pagePath: string): Promise<{
5
6
  localeYaml: string;
@@ -20,7 +20,7 @@ export { readSomaCspNonce, somaCspNonceMetadata, type SomaCspHeaderBag, } from '
20
20
  export { loadSomaServerPageAssets, SomaPageAssetError, type SomaServerPageAssets, type SomaPageAssetLoadProfile, } from './host/server-page-assets';
21
21
  export { loadComponentPackage, loadComponentPackages, scanComponentPackages, SomaComponentPackageError, type LoadPackagesOptions, type PackScanWarning, } from '../build/component/package-loader';
22
22
  export { loadComponentPackFromDir, type LoadPackFromDirOptions, } from '../build/component/pack-from-dir';
23
- export { loadExternalBlocks, blocksDirOf, } from '../build/v2/block-loader';
23
+ export { loadExternalBlocks, blocksDirOf, } from '../build/blocks/block-loader';
24
24
  export { setSomaDb, getSomaDb, resetSomaDb, createSomaDbSingleton, registerSomaDbProvider, disconnectSomaDb, withSomaDb, type ISomaDbProvider, } from './infra/db/soma-db';
25
25
  export { SomaQuery } from './infra/db/query/SomaQuery';
26
26
  export type { SomaBaseMapper } from './infra/db/mapper/SomaBaseMapper';
@@ -0,0 +1,5 @@
1
+ export declare class SomaBlockParseError extends Error {
2
+ readonly blockId?: string | undefined;
3
+ readonly line?: number | undefined;
4
+ constructor(message: string, blockId?: string | undefined, line?: number | undefined);
5
+ }
@@ -0,0 +1,4 @@
1
+ /** 数值/日期归一:能当数用就返回数,否则 null */
2
+ export declare function ordinalOf(value: unknown): number | null;
3
+ /** 文本化:null/undefined → 空串(CONCAT 与等值比较共用) */
4
+ export declare function textOf(value: unknown): string;
@@ -0,0 +1,14 @@
1
+ /** 源串里的字符区间 [起, 止),用于错误定位 */
2
+ export type CalcSpan = readonly [number, number];
3
+ export declare class SomaCalcSyntaxError extends Error {
4
+ readonly pos: CalcSpan;
5
+ /** 出错处附近的原文片段(供报错时回显) */
6
+ readonly near: string;
7
+ constructor(message: string, source: string, pos: CalcSpan);
8
+ }
9
+ export declare class SomaCalcTypeError extends Error {
10
+ readonly pos: CalcSpan;
11
+ readonly expected: string;
12
+ readonly actual: string;
13
+ constructor(message: string, source: string, pos: CalcSpan, expected: string, actual: string);
14
+ }
@@ -0,0 +1,2 @@
1
+ import type { CalcAst } from './parser';
2
+ export declare function evaluateCalc(ast: CalcAst, values: Record<string, unknown>): unknown;
@@ -0,0 +1,6 @@
1
+ export { SomaCalcSyntaxError, SomaCalcTypeError, type CalcSpan } from './errors';
2
+ export { tokenize, parseDateLiteral, CALC_FUNCTIONS, type CalcToken, type CalcTokenKind, type CalcFunctionName } from './lexer';
3
+ export { parseCalc, collectCalcRefs, type CalcAst, type CalcBinaryOp } from './parser';
4
+ export { inferCalcType, assertCalcResultType, type CalcType, type CalcTypeContext } from './typer';
5
+ export { evaluateCalc } from './evaluator';
6
+ export { ordinalOf, textOf } from './coerce';
@@ -0,0 +1,20 @@
1
+ import { type CalcSpan } from './errors';
2
+ export type CalcTokenKind = 'number' | 'string' | 'date' | 'bool' | 'ref' | 'ident' | 'op' | 'lparen' | 'rparen' | 'comma' | 'eof';
3
+ export interface CalcToken {
4
+ kind: CalcTokenKind;
5
+ /** number → 数值;string → 已去引号去转义的文本;date → UTC 毫秒;bool → 布尔;
6
+ * ref → 字段名;ident → 函数名;op → 运算符原文 */
7
+ value: string | number | boolean;
8
+ pos: CalcSpan;
9
+ }
10
+ /** 六个函数名——封闭集。新增必须走需求文档,不许在这里顺手加 */
11
+ export declare const CALC_FUNCTIONS: readonly ["IF", "MIN", "MAX", "ROUND", "CONCAT", "ABS"];
12
+ export type CalcFunctionName = typeof CALC_FUNCTIONS[number];
13
+ export declare function tokenize(source: string): CalcToken[];
14
+ /**
15
+ * 日期字面量 → UTC 毫秒。
16
+ *
17
+ * 用 `Date.UTC` 而不是 `Date.parse`:后者对无时区的串在各引擎上曾有本地/UTC 之争,
18
+ * 而派生列的日期比较必须在任何机器上给同一个答案。
19
+ */
20
+ export declare function parseDateLiteral(text: string): number | null;
@@ -0,0 +1,49 @@
1
+ import { type CalcSpan } from './errors';
2
+ import { type CalcFunctionName } from './lexer';
3
+ export type CalcBinaryOp = '+' | '-' | '*' | '/' | '>' | '>=' | '<' | '<=' | '==' | '!=';
4
+ export type CalcAst = {
5
+ k: 'num';
6
+ v: number;
7
+ pos: CalcSpan;
8
+ } | {
9
+ k: 'str';
10
+ v: string;
11
+ pos: CalcSpan;
12
+ } | {
13
+ k: 'date';
14
+ v: number;
15
+ pos: CalcSpan;
16
+ } | {
17
+ k: 'bool';
18
+ v: boolean;
19
+ pos: CalcSpan;
20
+ } | {
21
+ k: 'ref';
22
+ name: string;
23
+ pos: CalcSpan;
24
+ } | {
25
+ k: 'un';
26
+ op: '-';
27
+ arg: CalcAst;
28
+ pos: CalcSpan;
29
+ } | {
30
+ k: 'bin';
31
+ op: CalcBinaryOp;
32
+ left: CalcAst;
33
+ right: CalcAst;
34
+ pos: CalcSpan;
35
+ } | {
36
+ k: 'call';
37
+ fn: CalcFunctionName;
38
+ args: CalcAst[];
39
+ pos: CalcSpan;
40
+ };
41
+ export declare function parseCalc(source: string): CalcAst;
42
+ /**
43
+ * 收集表达式引用的字段名(去重、首次出现序)。
44
+ *
45
+ * 这是 RG 反应图建 DAG 的原料之一:`total: { calc: "[amount] - [discount]" }`
46
+ * 的入边就是 `amount` 与 `discount`。Formily / amis 的依赖靠运行时收集,
47
+ * 所以它们建不出这张图——这个函数是那条结构性差异的落点。
48
+ */
49
+ export declare function collectCalcRefs(ast: CalcAst): string[];
@@ -0,0 +1,16 @@
1
+ import type { CalcAst } from './parser';
2
+ export type CalcType = 'number' | 'text' | 'bool' | 'date';
3
+ export interface CalcTypeContext {
4
+ /** 字段名 → 字典里的 `type`(缺省视为 text,与字典本身的缺省一致) */
5
+ fieldTypes: Readonly<Record<string, string | undefined>>;
6
+ /** 原始表达式串,仅用于错误定位 */
7
+ source: string;
8
+ }
9
+ export declare function inferCalcType(ast: CalcAst, ctx: CalcTypeContext): CalcType;
10
+ /**
11
+ * 与字段声明的 `type` 对账。
12
+ *
13
+ * 单独一个函数而不是塞进 `infer`:解析器可能被用在「只想知道类型」的场合
14
+ * (如 DW 的派生列预览),那时还没有目标字段。
15
+ */
16
+ export declare function assertCalcResultType(result: CalcType, declaredFieldType: string | undefined, ctx: CalcTypeContext, ast: CalcAst): void;
@@ -0,0 +1,56 @@
1
+ /** 三种形态的判别式 */
2
+ export type SomaPathSelector = {
3
+ kind: 'each';
4
+ } | {
5
+ kind: 'self';
6
+ } | {
7
+ kind: 'offset';
8
+ delta: number;
9
+ };
10
+ export interface SomaListPath {
11
+ /** 列表字段名(`items`) */
12
+ list: string;
13
+ selector: SomaPathSelector;
14
+ /** 项内字段名(`discount`);支持多级 `a.b` */
15
+ field: string;
16
+ /** 原样保留,报错时回指作者写的那串 */
17
+ source: string;
18
+ }
19
+ /** 一个引用是不是列表路径(不是的话按普通顶层字段处理) */
20
+ export declare function isListPath(reference: string): boolean;
21
+ export declare class SomaPathError extends Error {
22
+ constructor(message: string);
23
+ }
24
+ export declare function parseListPath(reference: string): SomaListPath;
25
+ /**
26
+ * 展开成逐项的具体路径。
27
+ *
28
+ * `count` 是运行期的项数——展开发生在**每次求值前**而不是解析期:
29
+ * 项数会变(用户增删行),而解析期展开出来的模板会立刻过期。
30
+ * 解析期做的是**校验**(列表字段在不在字典里、项内字段在不在 `item_fields` 里),
31
+ * 那部分才是静态的。
32
+ *
33
+ * 越界的偏移(最后一项的 `[+1]`)产出 `null` 而不是抛:
34
+ * 「最后一段没有下一段」是正常的数据形态,不是错误。调用方按"读不到值"处理。
35
+ */
36
+ export declare function expandListPath(path: SomaListPath, count: number, currentIndex?: number): Array<{
37
+ index: number;
38
+ path: string;
39
+ } | null>;
40
+ /**
41
+ * 从一份值里读列表路径指向的值。
42
+ *
43
+ * 读不到一律 `null`(不抛、不返回 undefined):反应图的求值面对的是**半填的表单**,
44
+ * 缺值是常态。抛的话,一个还没填到的明细行会炸掉整张表的联动。
45
+ */
46
+ export declare function readListPath(values: Record<string, unknown>, path: SomaListPath, index: number): unknown;
47
+ /**
48
+ * 声明期校验:列表字段在不在字典里、它是不是 list、项内字段在不在 `item_fields` 里。
49
+ *
50
+ * 这三条是静态的,所以必须在声明期查完——留到运行期的话,一个拼错的项内字段名
51
+ * 只会让那条联动**永远不成立**,而"永远不成立"和"条件确实没满足"看不出区别。
52
+ */
53
+ export declare function validateListPath(path: SomaListPath, fields: Record<string, {
54
+ type?: string;
55
+ item_fields?: unknown;
56
+ }>): string[];
@@ -0,0 +1,79 @@
1
+ /** 十二个具名算子——封闭集合,不接受任何其他取值 */
2
+ export declare const SOMA_FIELD_PREDICATE_OPS: readonly ["eq", "ne", "in", "not_in", "empty", "not_empty", "gt", "gte", "lt", "lte", "between", "matches", "starts_with", "ends_with", "contains"];
3
+ export type SomaFieldPredicateOp = typeof SOMA_FIELD_PREDICATE_OPS[number];
4
+ /** 单条件:某个字段的当前值满足某个算子 */
5
+ export interface SomaFieldCondition {
6
+ /** 被观察字段的 key(必须是同一层里真实存在的字段) */
7
+ field: string;
8
+ op: SomaFieldPredicateOp;
9
+ /**
10
+ * eq/ne/gt/gte/lt/lte 的比较值;in/not_in 的候选数组;between 的 [低, 高](闭区间);
11
+ * matches 的正则源串(不带斜杠与 flag);empty/not_empty 不用
12
+ */
13
+ value?: unknown;
14
+ /**
15
+ * 深取路径:字段值是对象时读它的子键。只允许 `a.b.c` 与 `a[0].b` 两种写法——
16
+ * 它是 JSONPath 的一个极小子集,刻意不支持通配与过滤(那些属于查询语言)。
17
+ */
18
+ path?: string;
19
+ }
20
+ /** 引用一条具名谓词(在 `predicates:` 表里声明过的名字) */
21
+ export interface SomaFieldPredicateRef {
22
+ ref: string;
23
+ }
24
+ /** 全部成立 */
25
+ export interface SomaFieldPredicateAllOf {
26
+ all_of: SomaFieldPredicate[];
27
+ }
28
+ /** 任一成立 */
29
+ export interface SomaFieldPredicateAnyOf {
30
+ any_of: SomaFieldPredicate[];
31
+ }
32
+ /** 全部不成立(取反) */
33
+ export interface SomaFieldPredicateNoneOf {
34
+ none_of: SomaFieldPredicate[];
35
+ }
36
+ export type SomaFieldPredicate = SomaFieldCondition | SomaFieldPredicateRef | SomaFieldPredicateAllOf | SomaFieldPredicateAnyOf | SomaFieldPredicateNoneOf;
37
+ /** 具名谓词表:名字 → 谓词。声明一次,到处 `{ ref: 名字 }` */
38
+ export type SomaNamedPredicates = Readonly<Record<string, SomaFieldPredicate>>;
39
+ /** 校验期可选上下文 */
40
+ export interface SomaPredicateValidateOptions {
41
+ /** 字段名 → 字段类型(来自字典 `type`);给了就做算子 × 类型配对 */
42
+ fieldTypes?: Readonly<Record<string, string | undefined>>;
43
+ /** 具名谓词表;给了才允许 `{ ref }`,且会一并校验被引用的谓词 */
44
+ named?: SomaNamedPredicates;
45
+ }
46
+ /**
47
+ * 谓词求值。
48
+ *
49
+ * `values` 是**同一层**的值对象:顶层字段传整张表的 values,`item_fields` 的谓词传那一项
50
+ * 自己的对象。`named` 是具名谓词表;`{ ref }` 在这里解析。
51
+ *
52
+ * 环保护:具名谓词互相引用成环时(校验期本该拦下,但运行期不能指望它)按「不成立」处理,
53
+ * 绝不无限递归——一个写错的声明不该把页面挂死。
54
+ */
55
+ export declare function evaluatePredicate(predicate: SomaFieldPredicate | null | undefined, values: Record<string, unknown>, named?: SomaNamedPredicates): boolean;
56
+ /**
57
+ * 谓词静态校验:返回问题清单(空数组 = 通过)。
58
+ *
59
+ * @param fieldKeys 同一层里合法的字段名全集
60
+ * @param path 问题定位用的声明路径(如 `fields[2].visible_when`)
61
+ * @param options 可选:字段类型表(做算子配对)与具名谓词表(允许并校验 `ref`)
62
+ *
63
+ * 调用方拿到非空清单时的正确处置是「当作不成立 + `console.warn` 点名」——
64
+ * 让一个写错的联动声明**看得见**,而不是让字段悄悄消失。
65
+ */
66
+ export declare function validatePredicate(predicate: unknown, fieldKeys: readonly string[], path: string, options?: SomaPredicateValidateOptions): string[];
67
+ /**
68
+ * 具名谓词表整体校验:每一条都合法、彼此不成环。
69
+ * 表单在挂载时调一次;问题清单非空时 `console.warn` 点名并把有问题的那几条当作不成立。
70
+ */
71
+ export declare function validateNamedPredicates(named: unknown, fieldKeys: readonly string[], fieldTypes?: Readonly<Record<string, string | undefined>>): string[];
72
+ /**
73
+ * 收集一条谓词直接或经 ref 间接依赖的全部字段名(去重、声明序)。
74
+ *
75
+ * 这是反应图(REQ-010 S1)建 DAG 的原料:知道「这条反应看哪些字段」,
76
+ * 才能在编译期排出求值顺序、检出环、并回答「改这个字段会牵动哪些反应」。
77
+ * amis / Formily 的依赖是运行时收集的,所以做不到这一步。
78
+ */
79
+ export declare function collectPredicateFields(predicate: SomaFieldPredicate | null | undefined, named?: SomaNamedPredicates): string[];