soma-kit 0.1.11 → 0.1.12

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 (302) hide show
  1. package/README.md +103 -110
  2. package/bin/soma-kit.mjs +1 -1
  3. package/bin/soma.mjs +22 -0
  4. package/package.json +13 -7
  5. package/packs/finance/reconcile-board.ts +5 -2
  6. package/packs/finance/reconcile-desk/compile.ts +3 -2
  7. package/spec/generated/kit-app.schema.json +776 -38
  8. package/spec/generated/kit-page.schema.json +1613 -224
  9. package/spec/kit-grammar.json +770 -529
  10. package/spec/kit-grammar.schema.json +1962 -392
  11. package/src/app/app-config.ts +371 -347
  12. package/src/app/component-gate.ts +12 -15
  13. package/src/app/compose-apps.ts +79 -8
  14. package/src/app/define-kit-actions.ts +245 -41
  15. package/src/app/define-kit-app.ts +174 -31
  16. package/src/app/define-kit-view.ts +100 -0
  17. package/src/app/envelope.ts +1 -161
  18. package/src/app/index.ts +13 -2
  19. package/src/app/kit-view-context.ts +290 -0
  20. package/src/app/notify-renderer.ts +1 -115
  21. package/src/app/paged-list-adapter.ts +1 -240
  22. package/src/app/server-pages.ts +8 -2
  23. package/src/app/server.ts +491 -101
  24. package/src/app/submit.types.ts +1 -1
  25. package/src/app/theme-endpoint.ts +63 -0
  26. package/src/app/theme-runtime-shared.ts +1 -0
  27. package/src/app/theme-runtime.ts +663 -0
  28. package/src/base/action-busy.ts +2 -2
  29. package/src/base/action-gate.ts +4 -255
  30. package/src/base/action-slots.ts +47 -0
  31. package/src/base/alert.ts +5 -3
  32. package/src/base/avatar.ts +2 -2
  33. package/src/base/button.ts +46 -29
  34. package/src/base/cascader.ts +11 -12
  35. package/src/base/check-core.ts +1 -1
  36. package/src/base/choice.ts +28 -26
  37. package/src/base/class-candidates.ts +17 -0
  38. package/src/base/color-picker.ts +6 -6
  39. package/src/base/combobox.ts +5 -3
  40. package/src/base/command-palette.ts +9 -5
  41. package/src/base/countdown.ts +1 -1
  42. package/src/base/date-range.ts +25 -11
  43. package/src/base/date.ts +85 -17
  44. package/src/base/divider.ts +2 -2
  45. package/src/base/fab.ts +11 -4
  46. package/src/base/image.ts +1 -1
  47. package/src/base/index.ts +9 -3
  48. package/src/base/input.ts +42 -13
  49. package/src/base/kbd.ts +3 -1
  50. package/src/base/link.ts +4 -4
  51. package/src/base/listbox-core.ts +50 -30
  52. package/src/base/loading-gate.ts +133 -0
  53. package/src/base/mentions.ts +5 -5
  54. package/src/base/menu-button.ts +6 -1
  55. package/src/base/menu-core.ts +4 -0
  56. package/src/base/motion/aura.ts +2 -2
  57. package/src/base/motion/hover-3d.ts +2 -2
  58. package/src/base/motion/hover-gallery.ts +2 -2
  59. package/src/base/motion/marquee.ts +2 -2
  60. package/src/base/motion/text-rotate.ts +2 -2
  61. package/src/base/number.ts +93 -80
  62. package/src/base/otp.ts +4 -1
  63. package/src/base/permission-gate.ts +6 -0
  64. package/src/base/popover.ts +40 -8
  65. package/src/base/popup.ts +79 -14
  66. package/src/base/price-text.ts +2 -2
  67. package/src/base/progress.ts +2 -2
  68. package/src/base/qr-code.ts +4 -4
  69. package/src/base/qty-stepper.ts +9 -3
  70. package/src/base/range.ts +2 -2
  71. package/src/base/rating.ts +1 -1
  72. package/src/base/segmented.ts +4 -0
  73. package/src/base/select.ts +4 -3
  74. package/src/base/shared.ts +221 -29
  75. package/src/base/swap.ts +4 -1
  76. package/src/base/switch.ts +1 -1
  77. package/src/base/tag-input.ts +14 -10
  78. package/src/base/tag.ts +5 -1
  79. package/src/base/text.ts +39 -6
  80. package/src/base/textarea.ts +37 -11
  81. package/src/base/time-picker.ts +12 -9
  82. package/src/base/tree-select.ts +15 -8
  83. package/src/base/upload.ts +34 -5
  84. package/src/base/virtual-list.ts +107 -1
  85. package/src/biz/approval-desk/compile.ts +23 -41
  86. package/src/biz/auth-panel/compile.ts +37 -52
  87. package/src/biz/auth-panel/index.ts +1 -1
  88. package/src/biz/category-crud/compile.ts +22 -36
  89. package/src/biz/checkout-page/compile.ts +21 -5
  90. package/src/biz/compose.ts +13 -27
  91. package/src/biz/define.ts +5 -4
  92. package/src/biz/import-wizard/compile.ts +22 -26
  93. package/src/biz/import-wizard/hub.ts +126 -61
  94. package/src/biz/import-wizard/shell.ts +3 -3
  95. package/src/biz/index.ts +3 -3
  96. package/src/biz/landing-page/compile.ts +19 -3
  97. package/src/biz/link/hub.ts +49 -20
  98. package/src/biz/link/shared.ts +115 -118
  99. package/src/biz/master-sub/compile.ts +31 -44
  100. package/src/biz/multi-board/compile.ts +34 -49
  101. package/src/biz/multi-board/index.ts +18 -1
  102. package/src/biz/multi-board/shell.ts +24 -15
  103. package/src/biz/notification-center/compile.ts +21 -33
  104. package/src/biz/page-templates/domain-templates.ts +80 -13
  105. package/src/biz/page-templates/result-page/compile.ts +11 -2
  106. package/src/biz/page-templates/shared.ts +34 -36
  107. package/src/biz/record-detail/compile.ts +47 -42
  108. package/src/biz/record-detail/index.ts +11 -1
  109. package/src/biz/settings-center/compile.ts +6 -5
  110. package/src/biz/shared/action-host.ts +91 -211
  111. package/src/biz/shared/compile-helpers.ts +80 -0
  112. package/src/biz/shared/coordinator.ts +486 -83
  113. package/src/biz/shared/index.ts +8 -2
  114. package/src/biz/shared/overlay-shell.ts +80 -0
  115. package/src/biz/shared/pipes.ts +43 -30
  116. package/src/biz/shared/remove-key.ts +6 -0
  117. package/src/biz/shared/remove-wire.ts +29 -0
  118. package/src/biz/shared/runtime-hub.ts +216 -24
  119. package/src/biz/single-form/compile.ts +15 -37
  120. package/src/biz/standard-crud/compile.ts +62 -107
  121. package/src/biz/standard-crud/shell.ts +16 -66
  122. package/src/biz/step-form/compile.ts +26 -97
  123. package/src/biz/step-form/hub.ts +34 -41
  124. package/src/biz/types.ts +4 -3
  125. package/src/cli/core-imports.ts +54 -0
  126. package/src/cli/kit-cli.ts +130 -26
  127. package/src/cli/kit-init.ts +222 -0
  128. package/src/cli/service-endpoint-check.ts +425 -0
  129. package/src/cli/source-path-check.d.mts +17 -0
  130. package/src/cli/source-path-check.mjs +334 -0
  131. package/src/cli/view-writes.ts +752 -0
  132. package/src/compile/action-host-attach.ts +21 -29
  133. package/src/compile/closed-set.ts +509 -0
  134. package/src/compile/compile-page.ts +219 -72
  135. package/src/compile/component-candidates.ts +1 -1
  136. package/src/compile/hints.ts +30 -1
  137. package/src/compile/index.ts +1 -0
  138. package/src/compile/kit-error.ts +1 -0
  139. package/src/compile/locate.ts +21 -1
  140. package/src/compile/parse.ts +370 -41
  141. package/src/compile/redirect.ts +6 -2
  142. package/src/compile/styles.ts +35 -2
  143. package/src/compile/types.ts +18 -2
  144. package/src/compile/view-check.ts +151 -0
  145. package/src/data/amount-breakdown.ts +2 -2
  146. package/src/data/anchor-nav.ts +2 -2
  147. package/src/data/approval-flow.ts +2 -2
  148. package/src/data/assignment-picker.ts +40 -29
  149. package/src/data/async-result-panel.ts +62 -6
  150. package/src/data/breadcrumbs.ts +2 -2
  151. package/src/data/calendar.ts +22 -25
  152. package/src/data/carousel.ts +5 -2
  153. package/src/data/chart.ts +42 -34
  154. package/src/data/checklist.ts +2 -2
  155. package/src/data/code-view.ts +4 -2
  156. package/src/data/comment-thread.ts +5 -2
  157. package/src/data/confirm-dialog.ts +10 -0
  158. package/src/data/context-menu.ts +29 -37
  159. package/src/data/d9-util.ts +2 -18
  160. package/src/data/diff.ts +4 -2
  161. package/src/data/dock.ts +2 -2
  162. package/src/data/embed.ts +2 -1
  163. package/src/data/field-mapper.ts +31 -26
  164. package/src/data/flow-editor-contract.ts +1 -1
  165. package/src/data/flow-editor.ts +89 -100
  166. package/src/data/flow-node-options.ts +90 -0
  167. package/src/data/flow-remote-options.ts +0 -103
  168. package/src/data/footer.ts +2 -2
  169. package/src/data/form-draft-registry.ts +2 -4
  170. package/src/data/gantt.ts +14 -17
  171. package/src/data/hero.ts +2 -2
  172. package/src/data/image-viewer.ts +20 -26
  173. package/src/data/index.ts +0 -2
  174. package/src/data/item-list.ts +31 -22
  175. package/src/data/kanban.ts +43 -42
  176. package/src/data/media-grid.ts +14 -19
  177. package/src/data/menu.ts +2 -2
  178. package/src/data/mockup.ts +2 -2
  179. package/src/data/modal-dialog.ts +22 -18
  180. package/src/data/navbar.ts +7 -2
  181. package/src/data/notify-renderer.ts +235 -0
  182. package/src/data/object-form.ts +1036 -648
  183. package/src/data/pager.ts +65 -29
  184. package/src/data/permission-matrix.ts +20 -21
  185. package/src/data/permission-tree.ts +28 -26
  186. package/src/data/pricing-table.ts +9 -3
  187. package/src/data/reaction-bar.ts +77 -88
  188. package/src/data/read-rollback.ts +73 -0
  189. package/src/data/record-card.ts +3 -3
  190. package/src/data/record-picker.ts +93 -50
  191. package/src/data/redirect.ts +32 -32
  192. package/src/data/remote-options.ts +13 -6
  193. package/src/data/request-console.ts +5 -3
  194. package/src/data/resident.ts +2 -1
  195. package/src/data/result-panel.ts +4 -2
  196. package/src/data/rich-text.ts +45 -55
  197. package/src/data/row-editor.ts +285 -52
  198. package/src/data/rule-builder.ts +18 -12
  199. package/src/data/shape-util.ts +4 -0
  200. package/src/data/stat-group.ts +243 -101
  201. package/src/data/static-registry.ts +22 -11
  202. package/src/data/steps.ts +2 -2
  203. package/src/data/survey.ts +24 -29
  204. package/src/data/system-switcher.ts +2 -2
  205. package/src/data/timeline.ts +2 -2
  206. package/src/data/tour-guide.ts +22 -29
  207. package/src/data/transfer.ts +27 -23
  208. package/src/data/tree-table.ts +96 -48
  209. package/src/data/tree.ts +27 -34
  210. package/src/data/trend-line.ts +6 -24
  211. package/src/data/virtual-rows.ts +118 -76
  212. package/src/data/watermark.ts +2 -2
  213. package/src/data/wrap.ts +63 -38
  214. package/src/frames/blank-frame.ts +1 -0
  215. package/src/frames/index.ts +2 -2
  216. package/src/frames/page-bar.ts +12 -11
  217. package/src/frames/page-header.ts +14 -5
  218. package/src/frames/page-status.ts +2 -2
  219. package/src/frames/shared.ts +23 -17
  220. package/src/frames/single-frame.ts +1 -0
  221. package/src/frames/split-frame/shell.ts +5 -5
  222. package/src/frames/split-frame/wiring.ts +2 -2
  223. package/src/frames/tabs-frame/shell.ts +2 -13
  224. package/src/frames/tabs-frame/wiring.ts +4 -8
  225. package/src/frames/top-main-frame.ts +1 -0
  226. package/src/frames/types.ts +13 -2
  227. package/src/frames/workspace-frame/extras.ts +20 -4
  228. package/src/frames/workspace-frame/index.ts +1 -1
  229. package/src/frames/workspace-frame/shell.ts +1 -0
  230. package/src/frames/workspace-frame/state.ts +13 -6
  231. package/src/frames/workspace-frame/view.ts +119 -25
  232. package/src/generated/kit-grammar-runtime.ts +430 -366
  233. package/src/generated/page-origin.ts +0 -11
  234. package/src/i18n/kit-text.ts +23 -27
  235. package/src/index.ts +2 -1
  236. package/src/object-renderer/action-gate.ts +11 -147
  237. package/src/object-renderer/arrange.ts +71 -77
  238. package/src/object-renderer/collapse-wiring.ts +2 -2
  239. package/src/object-renderer/collection-expand.ts +2 -2
  240. package/src/object-renderer/collection-parts.ts +216 -100
  241. package/src/object-renderer/collection-table.ts +180 -42
  242. package/src/object-renderer/collection.ts +95 -79
  243. package/src/object-renderer/compile-data.ts +85 -100
  244. package/src/object-renderer/crud-bridge.ts +32 -0
  245. package/src/object-renderer/defaults.ts +8 -14
  246. package/src/object-renderer/display-checks.ts +3 -24
  247. package/src/object-renderer/emit-events.ts +186 -172
  248. package/src/object-renderer/emit-object.ts +15 -2
  249. package/src/object-renderer/emit-static.ts +174 -132
  250. package/src/object-renderer/field-value.ts +593 -396
  251. package/src/object-renderer/filter-reload.ts +70 -0
  252. package/src/object-renderer/form-detail.ts +112 -2
  253. package/src/object-renderer/index.ts +26 -0
  254. package/src/object-renderer/key-field.ts +12 -0
  255. package/src/object-renderer/linkage.ts +7 -270
  256. package/src/object-renderer/merge-class.ts +18 -1
  257. package/src/object-renderer/path-pick.ts +27 -0
  258. package/src/object-renderer/render-object.ts +405 -86
  259. package/src/object-renderer/request-actions.ts +230 -249
  260. package/src/object-renderer/table-actions.ts +195 -95
  261. package/src/object-renderer/table-summary.ts +2 -2
  262. package/src/object-renderer/table-tools.ts +418 -84
  263. package/src/object-renderer/types.ts +128 -122
  264. package/src/object-renderer/view-binding.ts +196 -0
  265. package/src/page-target/ai-surface.ts +37 -0
  266. package/src/page-target/compile.ts +48 -8
  267. package/src/page-target/index.ts +8 -1
  268. package/src/page-target/intent-schema.ts +154 -28
  269. package/src/page-target/target.ts +257 -50
  270. package/src/page-target/writer-policy.ts +14 -3
  271. package/src/recipes/container.ts +165 -0
  272. package/src/recipes/control.ts +219 -0
  273. package/src/recipes/index.ts +263 -0
  274. package/src/recipes/overlay.ts +182 -0
  275. package/src/recipes/state.ts +70 -0
  276. package/src/recipes/table-row.ts +51 -0
  277. package/src/recipes/typography.ts +87 -0
  278. package/src/shared/action-field-guard.ts +41 -0
  279. package/src/shared/envelope.ts +207 -0
  280. package/src/shared/escape.ts +57 -0
  281. package/src/shared/kit-error.ts +21 -0
  282. package/src/shared/paged-list-adapter.ts +240 -0
  283. package/src/shared/path-guard.ts +127 -0
  284. package/src/shared/theme-runtime-shared.ts +175 -0
  285. package/src/shared/view-info.ts +10 -0
  286. package/src/theme/index.ts +12 -0
  287. package/src/theme/kit-theme-text.ts +1 -1
  288. package/src/theme/kit-theme.css +38 -1
  289. package/src/theme/kit-theme.tpl +38 -1
  290. package/src/theme/nine-dim-structure.ts +77 -0
  291. package/src/theme/surface-layers.ts +97 -0
  292. package/src/theme/theme-tokens.ts +85 -79
  293. package/src/theme/theme-types.ts +71 -0
  294. package/src/theme/typography.ts +17 -17
  295. package/src/biz/shared/step-values.ts +0 -25
  296. package/src/biz/step-form/steps-ref.ts +0 -112
  297. package/src/data/options-bus.ts +0 -24
  298. package/src/data/prompt-dialog.ts +0 -235
  299. package/src/object-renderer/adopt-gate.ts +0 -333
  300. package/src/object-renderer/field-policy.ts +0 -89
  301. package/src/object-renderer/outcome-draft.ts +0 -61
  302. package/src/theme/nine-dim-palettes.ts +0 -1473
@@ -1,25 +1,22 @@
1
- // 页面里存在 request / download 动作时,把页面级 KitActionHost 与它依赖的声明补进已装框的片段。
2
- // 补三样:宿主实例(html + show props)、语义作用域 kit_act(切片 results 的 owner 是宿主)、request 动作合成的 core 只写对象(data 段)。
1
+ // 页面里存在 request / download 动作、或筛选条提交后重取的登记(见 object-renderer/filter-reload.ts)时,把页面级 KitActionHost 与它依赖的声明补进已装框的片段。
2
+ // 补三样:宿主实例(html + show props:requests / watches)、语义作用域 kit_act(切片 results 的 owner 是宿主)、request 动作合成的 core 只写对象(data 段)。
3
3
 
4
4
  import { KIT_ACT_HOST, KIT_ACT_SCOPE, requestWriteObjects, type KitRequestSpec } from '../object-renderer/request-actions';
5
+ import { resolveSliceReloadObjects, type KitSliceReload } from '../object-renderer/filter-reload';
5
6
  import type { KitDiagnostic } from '../object-renderer/types';
6
- import { getCompileEnvelope } from '../app/envelope';
7
+ import { getCompileEnvelope } from '../shared/envelope';
7
8
  import type { KitFragment } from './fragment';
8
9
 
9
10
  const HOST_ANCHOR = 'kit-act-host';
10
11
 
11
12
  const isRec = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);
12
13
 
13
- /** 递归收集 show 里所有字符串叶子(核对 then 点名的 options.from 接口路径在本页真有字段在用) */
14
- function collectStrings(root: unknown, into: Set<string> = new Set()): Set<string> {
15
- if (typeof root === 'string') into.add(root);
16
- else if (Array.isArray(root)) for (const v of root) collectStrings(v, into);
17
- else if (isRec(root)) for (const v of Object.values(root)) collectStrings(v, into);
18
- return into;
19
- }
20
-
21
14
  /** 就地补进 framed;返回诊断(into 与页面已有数据对象重名、作用域重复) */
22
- export function attachActionHost(framed: KitFragment, specs: ReadonlyMap<string, KitRequestSpec>): KitDiagnostic[] {
15
+ export function attachActionHost(
16
+ framed: KitFragment,
17
+ specs: ReadonlyMap<string, KitRequestSpec>,
18
+ watches: readonly KitSliceReload[] = [],
19
+ ): KitDiagnostic[] {
23
20
  const diagnostics: KitDiagnostic[] = [];
24
21
  const data = (framed.ui.data ??= {});
25
22
 
@@ -31,22 +28,6 @@ export function attachActionHost(framed: KitFragment, specs: ReadonlyMap<string,
31
28
  diagnostics.push({ code: 'KIT-ACT-002', path: `behavior.actions.${spec.actionId}.request.into`, message: `into "${spec.outcome}" 与页面里的数据对象重名:into 是写入结果的范围名,换一个不重复的名字` });
32
29
  }
33
30
  }
34
- // H1b / H1c:request.then 数组里点名的数据对象 / 选项接口路径必须在本页找得到(拼错了静默不刷新最难查)
35
- let optionPaths: Set<string> | undefined;
36
- for (const spec of specs.values()) {
37
- for (const [i, it] of (spec.thenItems ?? []).entries()) {
38
- if (it.reload === true) continue;
39
- const at = `behavior.actions.${spec.actionId}.request.then[${i}].reload`;
40
- if (it.reload.startsWith('/')) {
41
- optionPaths ??= collectStrings(framed.ui.show);
42
- if (!optionPaths.has(it.reload)) {
43
- diagnostics.push({ code: 'KIT-ACT-009', path: at, message: `reload 点名的接口路径 ${it.reload} 在本页没有任何字段把它写作 options.from,重取不到任何候选(路径拼错了?)` });
44
- }
45
- } else if (!(it.reload in data) || it.reload in writeObjects) {
46
- diagnostics.push({ code: 'KIT-ACT-009', path: at, message: `reload 点名的数据对象 ${it.reload} 不在本页(页面里的数据对象:${Object.keys(data).filter((n) => !(n in writeObjects)).join(' / ')})` });
47
- }
48
- }
49
- }
50
31
  if (diagnostics.length > 0) return diagnostics;
51
32
  for (const [name, decl] of Object.entries(writeObjects)) data[name] = decl;
52
33
 
@@ -67,9 +48,20 @@ export function attachActionHost(framed: KitFragment, specs: ReadonlyMap<string,
67
48
 
68
49
  // 宿主实例
69
50
  const requests: Record<string, KitRequestSpec> = Object.fromEntries(specs);
51
+ // 重取登记的数据对象:按页面最终的作用域声明补(作用域没有 object 就留空,宿主退回重取全部)
52
+ const scopeObject = new Map<string, string>();
53
+ for (const sc of scopes) if (typeof sc.id === 'string' && typeof sc.object === 'string') scopeObject.set(sc.id, sc.object);
54
+ const resolvedWatches = resolveSliceReloadObjects(watches, (id) => scopeObject.get(id));
70
55
  const show = (framed.ui.show ??= {});
71
56
  const envelope = getCompileEnvelope();
72
- show[HOST_ANCHOR] = { props: { scope: KIT_ACT_SCOPE, requests, ...(envelope !== undefined ? { envelope } : {}) } };
57
+ show[HOST_ANCHOR] = {
58
+ props: {
59
+ scope: KIT_ACT_SCOPE,
60
+ requests,
61
+ ...(resolvedWatches.length > 0 ? { watches: resolvedWatches } : {}),
62
+ ...(envelope !== undefined ? { envelope } : {}),
63
+ },
64
+ };
73
65
  framed.html = `${framed.html}\n<div data-soma-component="${KIT_ACT_HOST}" data-soma-id="${HOST_ANCHOR}"></div>`;
74
66
  if (!framed.components.includes(KIT_ACT_HOST)) framed.components.push(KIT_ACT_HOST);
75
67
  return diagnostics;
@@ -0,0 +1,509 @@
1
+ // 对象声明的逐层闭集校验(解析阶段,纯函数,不查注册表)。
2
+ //
3
+ // 页面声明里没有逻辑语法:值的派生、条件显示 / 禁用 / 必填、跨字段 / 跨步骤取值、请求体拼装、回填、联动连线都不存在。
4
+ // 所以这里对一个对象声明(schema / behavior / view)的每一层都按真源闭集查键,写了闭集之外的键(含曾经的逻辑键)
5
+ // 一律报该层已有的未知键码并拒绝编译,不静默丢弃、不透传给 core。
6
+ //
7
+ // 闭集全部读 spec/kit-grammar.json;层级与码:
8
+ // schema 字段 / 页面骨架 / fields[] / view 槽 / collection / batchActions / expand KIT-PAGE-001(未知键)
9
+ // view 下的非槽位键 KIT-OBJ-005
10
+ // 分组 groups[] KIT-OBJ-008
11
+ // schema.<字段>.options 对象(含 params 值必须是字面量) KIT-FORM-003
12
+ // behavior.list KIT-FORM-004
13
+ // behavior.subscribe KIT-FORM-005
14
+ // schema.<字段>.default(字符串不得以 $ 开头) KIT-FORM-010
15
+ // request / request.status / request.into / download KIT-ACT-002
16
+ // 已删除的声明式顺序键(动作 then / after、request.then、view.form.afterSave、浮层 events 的 then)按未知键报 KIT-PAGE-001
17
+ // behavior.detail KIT-DET-001
18
+
19
+ import grammarJson from '../../spec/kit-grammar.json';
20
+ import type { KitDiagnostic } from '../object-renderer/types';
21
+ import { checkEnumOptionsAndEditCompatibility, checkFieldRules, checkViewFlowNodeOptions, checkViewRowColumns, dollarPathOf } from '../object-renderer/field-value';
22
+ import { checkRequestFieldMapping } from '../object-renderer/request-actions';
23
+ import { KIT_ACTION_TONES } from '../object-renderer/emit-events';
24
+ import { isValidBuiltinName, isValidPermissionCode, formatBuiltinInvalidMessage, formatPermissionInvalidMessage } from '../shared/action-field-guard';
25
+
26
+ type Rec = Record<string, unknown>;
27
+
28
+ interface G {
29
+ objectKeys: { schema: string[]; behavior: string[]; view: string[] };
30
+ objectLayer: { fieldEmphasis: string[]; containerEmphasis: string[]; surface: string[] };
31
+ actionKeys: string[];
32
+ fieldRefKeys: string[];
33
+ viewFormKeys: string[];
34
+ viewSlots: string[];
35
+ arrangeKeys: string[];
36
+ collectionKeys: { table: string[]; tableExt: { batchActionKeys: string[] } };
37
+ treeTable: { keys: string[]; treeKeys: string[]; childrenFromKeys: string[] };
38
+ groupCollapse: { groupKeys: string[] };
39
+ dividerItem: { keys: string[]; declKeys: string[] };
40
+ overlayEventRoles: { actionForm: { keys: string[] } };
41
+ coreMapping: { ruleKeys: string[]; writeChannels: Record<string, unknown> };
42
+ formDetail: { detailKeys: string[]; fromKeys: string[] };
43
+ requestAction: { requestKeys: string[]; requestStatusKeys: string[]; downloadKeys: string[] };
44
+ formLinkage: {
45
+ optionsFrom: { keys: string[] };
46
+ listAdapter: { listKeys: string[] };
47
+ behaviorPassthrough: { subscribe: { keys: string[] } };
48
+ requestExt: { intoKeys: string[]; resultKeys: string[] };
49
+ };
50
+ }
51
+ const KIT_GRAMMAR = grammarJson as unknown as G;
52
+ const g = KIT_GRAMMAR;
53
+
54
+ const isRec = (v: unknown): v is Rec => v !== null && typeof v === 'object' && !Array.isArray(v);
55
+
56
+ /** behavior 里编译器认、真源 objectKeys 没列全的键(与 parse.ts 的 BEHAVIOR_EXTRA_KEYS 同) */
57
+ const BEHAVIOR_KEYS: readonly string[] = [...g.objectKeys.behavior, 'params', 'list'];
58
+ /** behavior.write 对象写法:三条写通道 + 版本锁字段名 */
59
+ const WRITE_KEYS: readonly string[] = [...Object.keys(g.coreMapping.writeChannels), 'version'];
60
+ const SLOT_NAMES: readonly string[] = g.viewSlots;
61
+ /** view 下允许的键:槽位 + 视图级简写键(page / rowActions 等)+ 槽内键(biz 组件会把视图级散键并入槽) */
62
+ const VIEW_KEYS: readonly string[] = [...new Set([...g.objectKeys.view, ...g.viewFormKeys])];
63
+ /** 槽内允许的键:viewFormKeys + 真源 objectKeys.view 里的非槽位键(page / rowActions) */
64
+ const SLOT_KEYS: readonly string[] = [...new Set([...g.viewFormKeys, ...g.objectKeys.view.filter((k) => !SLOT_NAMES.includes(k))])];
65
+ /** collection 允许的键:table 集合键 + treeTable 键 + cards / stack 的版式键 */
66
+ const COLLECTION_KEYS: readonly string[] = [...new Set([...g.collectionKeys.table, ...g.treeTable.keys, 'cols', 'class', 'state', 'loading', 'empty', 'error', 'bordered', 'contextMenu'])];
67
+ const EXPAND_KEYS: readonly string[] = ['view', 'list', 'link'];
68
+ const FIELD_ITEM_KEYS: readonly string[] = [...g.fieldRefKeys, 'name'];
69
+
70
+ function unknownIn(obj: Rec, allowed: readonly string[], path: string, out: KitDiagnostic[], code = 'KIT-PAGE-001'): void {
71
+ for (const k of Object.keys(obj)) {
72
+ if (!allowed.includes(k)) {
73
+ out.push({ code, path: `${path}.${k}`, message: `未知键 ${k}(${path} 允许:${allowed.join(' / ')})` });
74
+ }
75
+ }
76
+ }
77
+
78
+ function shape(path: string, message: string, out: KitDiagnostic[], code = 'KIT-PAGE-004'): void {
79
+ out.push({ code, path, message });
80
+ }
81
+
82
+ import {
83
+ checkNoRelativeOrSystemPath,
84
+ isRelativePathValue,
85
+ isSystemAbsolutePath,
86
+ type PathCheckOptions,
87
+ } from '../shared/path-guard';
88
+
89
+ export {
90
+ checkNoRelativeOrSystemPath,
91
+ isRelativePathValue,
92
+ isSystemAbsolutePath,
93
+ type PathCheckOptions,
94
+ };
95
+
96
+ function checkEndpointValue(raw: unknown, fieldPath: string, out: KitDiagnostic[], code = 'KIT-PAGE-004'): void {
97
+ if (typeof raw === 'string') {
98
+ checkNoRelativeOrSystemPath(raw, fieldPath, out, code);
99
+ } else if (isRec(raw)) {
100
+ if (typeof raw.api === 'string') checkNoRelativeOrSystemPath(raw.api, `${fieldPath}.api`, out, code);
101
+ if (typeof raw.url === 'string') checkNoRelativeOrSystemPath(raw.url, `${fieldPath}.url`, out, code);
102
+ if (typeof raw.path === 'string') checkNoRelativeOrSystemPath(raw.path, `${fieldPath}.path`, out, code);
103
+ } else if (Array.isArray(raw)) {
104
+ raw.forEach((item, i) => checkEndpointValue(item, `${fieldPath}[${i}]`, out, code));
105
+ }
106
+ }
107
+
108
+ // ---------------------------------------------------------------- schema
109
+
110
+ function checkRemoteOptions(opts: Rec, path: string, out: KitDiagnostic[]): void {
111
+ unknownIn(opts, g.formLinkage.optionsFrom.keys, path, out, 'KIT-FORM-003');
112
+ if (typeof opts.from === 'string') checkNoRelativeOrSystemPath(opts.from, `${path}.from`, out, 'KIT-FORM-003');
113
+ if (typeof opts.url === 'string') checkNoRelativeOrSystemPath(opts.url, `${path}.url`, out, 'KIT-FORM-003');
114
+ if (opts.params !== undefined) {
115
+ if (!isRec(opts.params)) {
116
+ shape(`${path}.params`, 'params 必须是 { 参数名: 字面量 } 的映射', out, 'KIT-FORM-003');
117
+ return;
118
+ }
119
+ for (const [name, val] of Object.entries(opts.params)) {
120
+ if (!(val === null || ['string', 'number', 'boolean'].includes(typeof val))) {
121
+ shape(`${path}.params.${name}`, `params.${name} 必须是字面量(字符串 / 数字 / 布尔),不接受对象或数组形态的取值写法`, out, 'KIT-FORM-003');
122
+ }
123
+ }
124
+ }
125
+ }
126
+
127
+ const FIELD_ACCESS_VALUES: readonly string[] = ["read", "write", "create", "r", "w"];
128
+ const FIELD_EMPHASIS_VALUES: readonly string[] = KIT_GRAMMAR.objectLayer.fieldEmphasis;
129
+ const CONTAINER_EMPHASIS_VALUES: readonly string[] = KIT_GRAMMAR.objectLayer.containerEmphasis;
130
+ const SURFACE_RECIPE_VALUES: readonly string[] = KIT_GRAMMAR.objectLayer.surface;
131
+
132
+ function checkFieldKnobs(def: Rec, path: string, out: KitDiagnostic[]): void {
133
+ if (def.emphasis !== undefined && (typeof def.emphasis !== "string" || !FIELD_EMPHASIS_VALUES.includes(def.emphasis))) {
134
+ out.push({ code: "KIT-OBJ-009", path: `${path}.emphasis`, message: `字段 emphasis "${String(def.emphasis)}" 不合法(允许:${FIELD_EMPHASIS_VALUES.join(' / ')})` });
135
+ }
136
+ if (def.highlight !== undefined && typeof def.highlight !== "boolean") {
137
+ out.push({ code: "KIT-OBJ-009", path: `${path}.highlight`, message: "字段 highlight 必须是布尔值" });
138
+ }
139
+ }
140
+
141
+ function checkContainerKnobs(rec: Rec, path: string, out: KitDiagnostic[], code = "KIT-OBJ-009"): void {
142
+ if (rec.emphasis !== undefined && (typeof rec.emphasis !== "string" || !CONTAINER_EMPHASIS_VALUES.includes(rec.emphasis))) {
143
+ out.push({ code, path: `${path}.emphasis`, message: `区块 emphasis "${String(rec.emphasis)}" 不合法(允许:${CONTAINER_EMPHASIS_VALUES.join(' / ')})` });
144
+ }
145
+ if (rec.surface !== undefined && (typeof rec.surface !== "string" || !SURFACE_RECIPE_VALUES.includes(rec.surface))) {
146
+ out.push({ code, path: `${path}.surface`, message: `容器 surface "${String(rec.surface)}" 不合法(允许:${SURFACE_RECIPE_VALUES.join(' / ')})` });
147
+ }
148
+ if (rec.highlight !== undefined && typeof rec.highlight !== "boolean") {
149
+ out.push({ code, path: `${path}.highlight`, message: "highlight 必须是布尔值" });
150
+ }
151
+ }
152
+
153
+ function checkSchemaField(name: string, def: Rec, path: string, out: KitDiagnostic[]): void {
154
+ unknownIn(def, g.objectKeys.schema, path, out);
155
+ if (def.access !== undefined && (typeof def.access !== "string" || !FIELD_ACCESS_VALUES.includes(def.access))) {
156
+ out.push({ code: "KIT-OBJ-006", path: `${path}.access`, message: `字段 ${name} 的 access "${String(def.access)}" 不合法(允许:read / write / create)` });
157
+ }
158
+ if (def.permission !== undefined && (typeof def.permission !== "string" || !FIELD_ACCESS_VALUES.includes(def.permission))) {
159
+ out.push({ code: "KIT-OBJ-006", path: `${path}.permission`, message: `字段 ${name} 的 permission "${String(def.permission)}" 不合法(允许:r / w / create / read / write)` });
160
+ }
161
+ if (def.readonly !== undefined && typeof def.readonly !== "boolean") {
162
+ out.push({ code: "KIT-PAGE-004", path: `${path}.readonly`, message: `字段 ${name} 的 readonly 必须是布尔值` });
163
+ }
164
+ checkFieldKnobs(def, path, out);
165
+ if (isRec(def.options)) checkRemoteOptions(def.options, `${path}.options`, out);
166
+ checkFieldRules(name, def.rules, `${path}.rules`, out);
167
+ if (def.default !== undefined) {
168
+ const hit = dollarPathOf(def.default);
169
+ if (hit !== undefined) {
170
+ out.push({ code: 'KIT-FORM-010', path: `${path}.default`, message: `字段 ${name} 的 default 必须是字面量,不接受以 $ 开头的取值路径(${hit})` });
171
+ }
172
+ }
173
+ }
174
+
175
+ // ---------------------------------------------------------------- behavior
176
+
177
+ const REQUEST_ALLOWED_KEYS: readonly string[] = g.requestAction.requestKeys;
178
+ const PAGE_DECL_KEYS: readonly string[] = ['size', 'sizes', 'jump', 'mode', 'layout', 'show_total'];
179
+
180
+ function checkRequest(raw: unknown, path: string, out: KitDiagnostic[]): void {
181
+ if (!isRec(raw)) return;
182
+ unknownIn(raw, REQUEST_ALLOWED_KEYS, path, out, 'KIT-ACT-002');
183
+ if (raw.api !== undefined && typeof raw.api !== 'string') {
184
+ out.push({ code: 'KIT-ACT-002', path: `${path}.api`, message: 'request.api 必须是字符串' });
185
+ } else if (typeof raw.api === 'string') {
186
+ checkNoRelativeOrSystemPath(raw.api, `${path}.api`, out, 'KIT-ACT-002');
187
+ }
188
+ if (raw.url !== undefined && typeof raw.url !== 'string') {
189
+ out.push({ code: 'KIT-ACT-002', path: `${path}.url`, message: 'request.url 必须是字符串' });
190
+ } else if (typeof raw.url === 'string') {
191
+ checkNoRelativeOrSystemPath(raw.url, `${path}.url`, out, 'KIT-ACT-002');
192
+ }
193
+ if (raw.method !== undefined && typeof raw.method !== 'string') {
194
+ out.push({ code: 'KIT-ACT-002', path: `${path}.method`, message: 'request.method 必须是字符串' });
195
+ }
196
+ if (isRec(raw.status)) unknownIn(raw.status, g.requestAction.requestStatusKeys, `${path}.status`, out, 'KIT-ACT-002');
197
+ if (isRec(raw.into)) unknownIn(raw.into, g.formLinkage.requestExt.intoKeys, `${path}.into`, out, 'KIT-ACT-002');
198
+ checkRequestFieldMapping(raw, path, out);
199
+ }
200
+
201
+ function checkDownload(raw: unknown, path: string, out: KitDiagnostic[]): void {
202
+ if (isRec(raw)) {
203
+ unknownIn(raw, g.requestAction.downloadKeys, path, out, 'KIT-ACT-002');
204
+ if (raw.api !== undefined && typeof raw.api !== 'string') {
205
+ out.push({ code: 'KIT-ACT-002', path: `${path}.api`, message: 'download.api 必须是字符串' });
206
+ } else if (typeof raw.api === 'string') {
207
+ checkNoRelativeOrSystemPath(raw.api, `${path}.api`, out, 'KIT-ACT-002');
208
+ }
209
+ if (raw.url !== undefined && typeof raw.url !== 'string') {
210
+ out.push({ code: 'KIT-ACT-002', path: `${path}.url`, message: 'download.url 必须是字符串' });
211
+ } else if (typeof raw.url === 'string') {
212
+ checkNoRelativeOrSystemPath(raw.url, `${path}.url`, out, 'KIT-ACT-002');
213
+ }
214
+ if (raw.method !== undefined && typeof raw.method !== 'string') {
215
+ out.push({ code: 'KIT-ACT-002', path: `${path}.method`, message: 'download.method 必须是字符串' });
216
+ }
217
+ if (raw.filename !== undefined && typeof raw.filename !== 'string') {
218
+ out.push({ code: 'KIT-ACT-002', path: `${path}.filename`, message: 'download.filename 必须是字符串' });
219
+ }
220
+ }
221
+ }
222
+
223
+ function checkActionItem(a: unknown, at: string, out: KitDiagnostic[], checkUnknown = true): void {
224
+ if (!isRec(a)) return;
225
+ if (checkUnknown) unknownIn(a, g.actionKeys, at, out);
226
+
227
+ if (a.id !== undefined && typeof a.id !== 'string') {
228
+ out.push({ code: 'KIT-ACT-010', path: `${at}.id`, message: `动作 id 必须是字符串(收到 ${typeof a.id})` });
229
+ }
230
+ if (a.name !== undefined && typeof a.name !== 'string') {
231
+ out.push({ code: 'KIT-ACT-010', path: `${at}.name`, message: `动作 name 必须是字符串(收到 ${typeof a.name})` });
232
+ }
233
+ if (a.label !== undefined && typeof a.label !== 'string') {
234
+ out.push({ code: 'KIT-ACT-010', path: `${at}.label`, message: '动作 label 必须是字符串' });
235
+ }
236
+ if (a.title !== undefined && typeof a.title !== 'string') {
237
+ out.push({ code: 'KIT-ACT-010', path: `${at}.title`, message: '动作 title 必须是字符串' });
238
+ }
239
+ if (a.on !== undefined && typeof a.on !== 'string') {
240
+ out.push({ code: 'KIT-ACT-010', path: `${at}.on`, message: `动作 on 必须是字符串(收到 ${typeof a.on})` });
241
+ }
242
+ if (a.submit !== undefined && typeof a.submit !== 'string') {
243
+ out.push({ code: 'KIT-ACT-010', path: `${at}.submit`, message: `动作 submit 必须是字符串(收到 ${typeof a.submit})` });
244
+ }
245
+ if (a.tone !== undefined) {
246
+ if (typeof a.tone !== 'string' || !KIT_ACTION_TONES.includes(a.tone)) {
247
+ out.push({
248
+ code: 'KIT-ACT-010',
249
+ path: `${at}.tone`,
250
+ message: `动作 ${typeof a.id === 'string' ? a.id : ''} 的 tone "${String(a.tone)}" 不在闭集(允许:${KIT_ACTION_TONES.join(' / ')})`,
251
+ });
252
+ }
253
+ }
254
+ if (a.builtin !== undefined) {
255
+ if (typeof a.builtin !== 'string') {
256
+ out.push({ code: 'KIT-ACT-010', path: `${at}.builtin`, message: `动作 builtin 必须是字符串(收到 ${typeof a.builtin})` });
257
+ } else if (a.builtin !== '' && !isValidBuiltinName(a.builtin)) {
258
+ out.push({
259
+ code: 'KIT-ACT-010',
260
+ path: `${at}.builtin`,
261
+ message: formatBuiltinInvalidMessage(a.builtin),
262
+ });
263
+ }
264
+ }
265
+ if (a.confirm !== undefined) {
266
+ if (typeof a.confirm !== 'string') {
267
+ out.push({ code: 'KIT-ACT-010', path: `${at}.confirm`, message: `动作 confirm 必须是字符串(收到 ${typeof a.confirm})` });
268
+ } else if (a.confirm.includes('|')) {
269
+ out.push({ code: 'KIT-ACT-010', path: `${at}.confirm`, message: '动作 confirm 文案含 "|",管道尾段不支持转义' });
270
+ }
271
+ }
272
+ if (a.targetOverlay !== undefined && typeof a.targetOverlay !== 'string') {
273
+ out.push({ code: 'KIT-ACT-010', path: `${at}.targetOverlay`, message: `动作 targetOverlay 必须是字符串(收到 ${typeof a.targetOverlay})` });
274
+ }
275
+ if (a.more !== undefined && typeof a.more !== 'boolean') {
276
+ out.push({ code: 'KIT-ACT-010', path: `${at}.more`, message: `动作 more 必须是布尔值(收到 ${typeof a.more})` });
277
+ }
278
+ for (const key of ['disabled', 'hidden'] as const) {
279
+ if (a[key] !== undefined && typeof a[key] !== 'string') {
280
+ out.push({ code: 'KIT-ACT-010', path: `${at}.${key}`, message: `动作 ${key} 必须是路径字符串(收到 ${typeof a[key]})` });
281
+ }
282
+ }
283
+ if (a.permission !== undefined) {
284
+ if (Array.isArray(a.permission)) {
285
+ out.push({ code: 'KIT-OBJ-006', path: `${at}.permission`, message: '动作 permission 写成数组:kit 层每个动作只允许一个权限码' });
286
+ } else if (typeof a.permission !== 'string') {
287
+ out.push({ code: 'KIT-ACT-010', path: `${at}.permission`, message: `动作 permission 必须是字符串(收到 ${typeof a.permission})` });
288
+ } else if (a.permission !== '' && !isValidPermissionCode(a.permission)) {
289
+ out.push({
290
+ code: 'KIT-ACT-010',
291
+ path: `${at}.permission`,
292
+ message: formatPermissionInvalidMessage(a.permission),
293
+ });
294
+ }
295
+ }
296
+
297
+ for (const key of ['to', 'href', 'url'] as const) {
298
+ const value = a[key];
299
+ if (value === undefined) continue;
300
+ if (typeof value !== 'string') {
301
+ out.push({ code: 'KIT-ACT-010', path: `${at}.${key}`, message: `动作 ${key} 必须是字符串(收到 ${typeof value})` });
302
+ } else if (key === 'href') {
303
+ checkNoRelativeOrSystemPath(value, `${at}.${key}`, out, 'KIT-ACT-010', { allowExternalHref: true });
304
+ } else {
305
+ checkNoRelativeOrSystemPath(value, `${at}.${key}`, out, 'KIT-ACT-010');
306
+ }
307
+ }
308
+ checkRequest(a.request, `${at}.request`, out);
309
+ checkDownload(a.download, `${at}.download`, out);
310
+ }
311
+
312
+ function checkBehavior(b: Rec, path: string, out: KitDiagnostic[]): void {
313
+ unknownIn(b, BEHAVIOR_KEYS, path, out);
314
+ if (b.from !== undefined) checkEndpointValue(b.from, `${path}.from`, out, 'KIT-PAGE-004');
315
+ if (b.requireParams !== undefined) {
316
+ if (!Array.isArray(b.requireParams)) {
317
+ out.push({ code: 'KIT-FORM-004', path: `${path}.requireParams`, message: 'behavior.requireParams 必须是非空字符串数组' });
318
+ } else {
319
+ b.requireParams.forEach((k, i) => {
320
+ if (typeof k !== 'string' || k.trim() === '' || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(k)) {
321
+ out.push({ code: 'KIT-FORM-004', path: `${path}.requireParams[${i}]`, message: `behavior.requireParams[${i}] 必须是合法的参数名标识符` });
322
+ }
323
+ });
324
+ }
325
+ }
326
+ if (typeof b.write === 'string') {
327
+ checkNoRelativeOrSystemPath(b.write, `${path}.write`, out, 'KIT-PAGE-004');
328
+ } else if (isRec(b.write)) {
329
+ unknownIn(b.write, WRITE_KEYS, `${path}.write`, out);
330
+ checkEndpointValue(b.write, `${path}.write`, out, 'KIT-PAGE-004');
331
+ for (const ch of Object.keys(g.coreMapping.writeChannels)) {
332
+ if (b.write[ch] !== undefined) checkEndpointValue(b.write[ch], `${path}.write.${ch}`, out, 'KIT-PAGE-004');
333
+ }
334
+ }
335
+ if (isRec(b.list)) unknownIn(b.list, g.formLinkage.listAdapter.listKeys, `${path}.list`, out, 'KIT-FORM-004');
336
+ const sub = b.subscribe;
337
+ const subs = Array.isArray(sub) ? sub : sub === undefined ? [] : [sub];
338
+ subs.forEach((s, i) => {
339
+ if (isRec(s)) unknownIn(s, g.formLinkage.behaviorPassthrough.subscribe.keys, Array.isArray(sub) ? `${path}.subscribe[${i}]` : `${path}.subscribe`, out, 'KIT-FORM-005');
340
+ });
341
+ if (isRec(b.detail)) {
342
+ unknownIn(b.detail, g.formDetail.detailKeys, `${path}.detail`, out, 'KIT-DET-001');
343
+ if (isRec(b.detail.from)) {
344
+ unknownIn(b.detail.from, g.formDetail.fromKeys, `${path}.detail.from`, out, 'KIT-DET-001');
345
+ checkEndpointValue(b.detail.from, `${path}.detail.from`, out, 'KIT-DET-001');
346
+ }
347
+ }
348
+ if (Array.isArray(b.actions)) {
349
+ b.actions.forEach((a, i) => {
350
+ checkActionItem(a, `${path}.actions[${i}]`, out);
351
+ });
352
+ }
353
+ }
354
+
355
+ // ---------------------------------------------------------------- view
356
+
357
+ /** fields[] / groups[].fields 的一项:字符串 | { divider } | { name, ...字段引用键 } | { 字段名: { ...字段引用键 } } */
358
+ function checkFieldItems(items: unknown, path: string, out: KitDiagnostic[]): void {
359
+ if (!Array.isArray(items)) return;
360
+ items.forEach((item, i) => {
361
+ const at = `${path}[${i}]`;
362
+ if (typeof item === 'string') return;
363
+ if (!isRec(item)) {
364
+ shape(at, '字段项必须是字段名字符串,或对象写法', out);
365
+ return;
366
+ }
367
+ if ('divider' in item && item.name === undefined) {
368
+ unknownIn(item, g.dividerItem.keys, at, out);
369
+ if (isRec(item.divider)) unknownIn(item.divider, g.dividerItem.declKeys, `${at}.divider`, out);
370
+ return;
371
+ }
372
+ if (typeof item.name === 'string') {
373
+ unknownIn(item, FIELD_ITEM_KEYS, at, out);
374
+ checkFieldKnobs(item, at, out);
375
+ return;
376
+ }
377
+ const keys = Object.keys(item);
378
+ if (keys.length !== 1) {
379
+ shape(at, '字段项必须是 { name, ... }、{ 字段名: { ... } }、{ divider } 之一', out);
380
+ return;
381
+ }
382
+ const inner = item[keys[0]!];
383
+ if (isRec(inner)) {
384
+ unknownIn(inner, FIELD_ITEM_KEYS, `${at}.${keys[0]}`, out);
385
+ checkFieldKnobs(inner, `${at}.${keys[0]}`, out);
386
+ }
387
+ else if (inner !== null && inner !== undefined) shape(`${at}.${keys[0]}`, `字段项 ${keys[0]} 的值必须是对象`, out);
388
+ });
389
+ }
390
+
391
+ function checkCollection(c: Rec, path: string, out: KitDiagnostic[]): void {
392
+ // 表级密度键已删除:密度只在 kit.app.yaml 的 theme.density(九维枚举),写了(任何取值)报 KIT-OBJ-011 而不是泛泛的未知键
393
+ if (c.density !== undefined) {
394
+ out.push({ code: 'KIT-OBJ-011', path: `${path}.density`, message: 'collection.density 已删除:密度只在 kit.app.yaml 的 theme.density(COMPACT_DENSE / STANDARD_BALANCED / SPACIOUS_AIRY),表格随它走' });
395
+ }
396
+ unknownIn(Object.fromEntries(Object.entries(c).filter(([k]) => k !== 'density')), COLLECTION_KEYS, path, out);
397
+ if (isRec(c.tree)) {
398
+ unknownIn(c.tree, g.treeTable.treeKeys, `${path}.tree`, out);
399
+ if (isRec(c.tree.childrenFrom)) {
400
+ unknownIn(c.tree.childrenFrom, g.treeTable.childrenFromKeys, `${path}.tree.childrenFrom`, out);
401
+ checkEndpointValue(c.tree.childrenFrom, `${path}.tree.childrenFrom`, out, 'KIT-OBJ-010');
402
+ }
403
+ }
404
+ if (isRec(c.expand)) unknownIn(c.expand, EXPAND_KEYS, `${path}.expand`, out);
405
+ if (c.page !== undefined && c.page !== false) {
406
+ if (isRec(c.page)) unknownIn(c.page, PAGE_DECL_KEYS, `${path}.page`, out);
407
+ else out.push({ code: 'KIT-OBJ-009', path: `${path}.page`, message: 'collection.page 必须是 false 或对象' });
408
+ }
409
+ if (Array.isArray(c.batchActions)) {
410
+ c.batchActions.forEach((b, i) => {
411
+ if (isRec(b)) {
412
+ unknownIn(b, g.collectionKeys.tableExt.batchActionKeys, `${path}.batchActions[${i}]`, out);
413
+ checkActionItem(b, `${path}.batchActions[${i}]`, out, false);
414
+ }
415
+ });
416
+ }
417
+ }
418
+
419
+ /** 视图槽(或视图级散键)的子层;closed = 是否同时查本层键闭集(视图级散键的闭集由 checkView 按 VIEW_KEYS 查) */
420
+ function checkSlot(slot: Rec, path: string, out: KitDiagnostic[], closed = true): void {
421
+ if (closed) unknownIn(slot, SLOT_KEYS, path, out);
422
+ checkContainerKnobs(slot, path, out);
423
+ checkFieldItems(slot.fields, `${path}.fields`, out);
424
+ if (isRec(slot.arrange)) unknownIn(slot.arrange, g.arrangeKeys, `${path}.arrange`, out);
425
+ if (isRec(slot.collection)) checkCollection(slot.collection, `${path}.collection`, out);
426
+ if (Array.isArray(slot.groups)) {
427
+ slot.groups.forEach((grp, i) => {
428
+ const at = `${path}.groups[${i}]`;
429
+ if (!isRec(grp)) return;
430
+ unknownIn(grp, g.groupCollapse.groupKeys, at, out, 'KIT-OBJ-008');
431
+ checkContainerKnobs(grp, at, out, 'KIT-OBJ-008');
432
+ checkFieldItems(grp.fields, `${at}.fields`, out);
433
+ });
434
+ }
435
+ if (isRec(slot.result)) unknownIn(slot.result, g.formLinkage.requestExt.resultKeys, `${path}.result`, out, 'KIT-PAGE-001');
436
+ if (isRec(slot.on)) {
437
+ for (const [ev, val] of Object.entries(slot.on)) {
438
+ if (isRec(val)) unknownIn(val, g.overlayEventRoles.actionForm.keys, `${path}.on.${ev}`, out);
439
+ }
440
+ }
441
+ }
442
+
443
+ function checkView(view: Rec, path: string, out: KitDiagnostic[]): void {
444
+ unknownIn(view, VIEW_KEYS, path, out, 'KIT-OBJ-005');
445
+ for (const name of SLOT_NAMES) {
446
+ const slot = view[name];
447
+ if (isRec(slot)) checkSlot(slot, `${path}.${name}`, out);
448
+ }
449
+ // 视图级散键(fields / collection / groups / on 等简写,biz 组件会并入槽)按槽内同样的规则查其子层
450
+ checkSlot(view, path, out, false);
451
+ }
452
+
453
+ // ---------------------------------------------------------------- 入口
454
+
455
+ /**
456
+ * 对象声明逐层闭集校验:schema 字段 / options / rules / default、behavior(write / list / subscribe / detail / actions
457
+ * 的 request / download)、view 各槽与 fields[] / groups / collection。
458
+ * @param obj 对象声明(已确认是对象);顶层键由调用方查
459
+ * @param path 诊断路径前缀,如 `product.objects.entity`
460
+ */
461
+ export function checkObjectClosedSet(obj: Rec, path: string, out: KitDiagnostic[]): void {
462
+ checkContainerKnobs(obj, path, out);
463
+ const section = (key: 'schema' | 'behavior' | 'view'): Rec | undefined => {
464
+ const v = obj[key];
465
+ if (v === undefined || v === null) return undefined;
466
+ if (!isRec(v)) {
467
+ shape(`${path}.${key}`, `${path}.${key} 必须是对象`, out);
468
+ return undefined;
469
+ }
470
+ return v;
471
+ };
472
+ const schema = section('schema');
473
+ if (schema !== undefined) {
474
+ for (const [name, def] of Object.entries(schema)) {
475
+ if (isRec(def)) checkSchemaField(name, def, `${path}.schema.${name}`, out);
476
+ }
477
+ }
478
+ const behavior = section('behavior');
479
+ if (behavior !== undefined) checkBehavior(behavior, `${path}.behavior`, out);
480
+ if (obj.from !== undefined) checkEndpointValue(obj.from, `${path}.from`, out, 'KIT-PAGE-004');
481
+ if (obj.write !== undefined) {
482
+ checkEndpointValue(obj.write, `${path}.write`, out, 'KIT-PAGE-004');
483
+ if (isRec(obj.write)) {
484
+ for (const ch of Object.keys(g.coreMapping.writeChannels)) {
485
+ if (obj.write[ch] !== undefined) checkEndpointValue(obj.write[ch], `${path}.write.${ch}`, out, 'KIT-PAGE-004');
486
+ }
487
+ }
488
+ }
489
+ if (Array.isArray(obj.actions)) {
490
+ obj.actions.forEach((a, i) => {
491
+ checkActionItem(a, `${path}.actions[${i}]`, out);
492
+ });
493
+ }
494
+ const view = section('view');
495
+ if (view !== undefined) {
496
+ checkView(view, `${path}.view`, out);
497
+ checkViewRowColumns(view, out);
498
+ checkViewFlowNodeOptions(view, out);
499
+ }
500
+ if (schema !== undefined) {
501
+ checkEnumOptionsAndEditCompatibility(schema, view, path, out);
502
+ }
503
+ // 浮层 events:值是动作字符串,或 { action }
504
+ if (isRec(obj.events)) {
505
+ for (const [ev, val] of Object.entries(obj.events)) {
506
+ if (isRec(val)) unknownIn(val, g.overlayEventRoles.actionForm.keys, `${path}.events.${ev}`, out);
507
+ }
508
+ }
509
+ }