soma-kit 0.1.10 → 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 -1278
@@ -8,30 +8,20 @@
8
8
  // 写入结果(pending / saved / failed、响应体、失败文案)落 core 的 write-outcome-store,组件用 `outcome` prop 订阅。
9
9
  // 下载没有 core 端口:GET 用链接、POST 用表单提交到隐藏窗体,都是浏览器原生下载,不经 fetch。
10
10
  //
11
- // 取值路径:body / query 的值以 `$` 开头是路径(`$row.id` / `$focus.id` / `$filter.q` / `$page.page` / `$value` / `$selected.id`),
12
- // 其余是字面量原样发送。DELETE 不在 request 里:删除用 `builtin: remove`(需要 write.delete 的占位符填充与重取)。
11
+ // 页面声明不拼请求体、不写参数取值路径:请求载荷由业务对象 / 具名动作 / 接口一侧提供。
12
+ // DELETE 不在 request 里:删除用 `builtin: remove`(需要 write.delete 的占位符填充与重取)。
13
13
 
14
14
  import { SOMA_STD_KEY_LIMITS } from 'soma-core';
15
+ import { checkNoRelativeOrSystemPath } from '../shared/path-guard';
15
16
  import { KIT_FORM_LINKAGE, KIT_GRAMMAR } from './defaults';
16
17
  import { resetGateRefs } from './action-gate';
17
- import { inKitStepScope, isCanonicalStepId } from './field-value';
18
- import type { KitAction, KitDiagnostic, KitDownloadDecl, KitRequestDecl, KitRequestThenItem } from './types';
18
+ import { abortFilterReloadCollect, beginFilterReloadCollect } from './filter-reload';
19
+ import type { KitAction, KitDiagnostic, KitDownloadDecl, KitRequestDecl } from './types';
19
20
 
20
21
  type Json = Record<string, any>;
21
22
  const RA = KIT_GRAMMAR.requestAction as Json;
22
23
  /** 动作与结果(GA)的闭集与限值:闭集读语法真源 formLinkage.requestExt,数字读 kit-limits,超时区间读 core 语法真源 write.timeoutMs */
23
24
  const EXT = (KIT_FORM_LINKAGE as Json).requestExt as {
24
- promptKeys: readonly string[];
25
- promptFieldKeys: readonly string[];
26
- promptFieldTypes: readonly string[];
27
- promptNamePattern: string;
28
- promptDefaultRefPattern: string;
29
- promptOptionKeys: readonly string[];
30
- promptFieldsMax: number;
31
- promptLabelMax: number;
32
- promptTitleMax: number;
33
- promptOptionsMax: number;
34
- promptTextMax: number;
35
25
  intoKeys: readonly string[];
36
26
  intoKeyPattern: string;
37
27
  intoSplitKeyPattern: string;
@@ -45,22 +35,12 @@ const SEMANTIC_PREFIX: string = RA.semanticPrefix;
45
35
  const OBJECT_PREFIX: string = RA.objectPrefix;
46
36
  const REQUEST_KEYS: readonly string[] = RA.requestKeys;
47
37
  const DOWNLOAD_KEYS: readonly string[] = RA.downloadKeys;
48
- const OK_KEYS: readonly string[] = RA.okKeys;
49
38
  const REQUEST_METHODS: readonly string[] = RA.requestMethods;
50
39
  const DOWNLOAD_METHODS: readonly string[] = RA.downloadMethods;
51
- const THEN_VALUES: readonly string[] = RA.thenValues;
52
- const BIND_ROOTS: readonly string[] = RA.bindRoots;
53
40
  const INTO_PATTERN = /^[a-z][a-zA-Z0-9_]*$/;
54
- /** H1:then 数组项 / 自动触发的闭集(读语法真源 requestAction),项数上限读 formLinkage.then.maxItems */
55
- const THEN_ITEM_KEYS: readonly string[] = RA.thenItemKeys;
56
- const THEN_ITEM_ON: readonly string[] = RA.thenItemOn;
57
- const THEN_ITEM_ON_DEFAULT: 'success' | 'failed' | 'always' = RA.thenItemOnDefault;
58
- const THEN_PATH_RE = new RegExp(RA.thenReloadPathPattern);
59
- const THEN_OBJECT_RE = new RegExp(RA.thenReloadObjectPattern);
60
- const THEN_MAX: number = ((KIT_FORM_LINKAGE as Json).then as { maxItems: number }).maxItems;
41
+ /** 自动触发的闭集(读语法真源 requestAction) */
61
42
  const AUTO_TRIGGERS: readonly string[] = RA.autoTriggers;
62
43
  const AUTO_READ_METHODS: readonly string[] = RA.autoReadMethods;
63
- const AUTO_MOUNT_ROOTS: readonly string[] = RA.autoMountRoots;
64
44
 
65
45
  const isRec = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);
66
46
 
@@ -121,8 +101,6 @@ export interface KitRequestSpec {
121
101
  object: string;
122
102
  api: string;
123
103
  method: string;
124
- body?: Record<string, unknown>;
125
- query?: Record<string, unknown>;
126
104
  /** request:compile 期合成的只写对象名(core data 里声明)与写模式 */
127
105
  writeObject?: string;
128
106
  mode?: 'create' | 'update';
@@ -134,190 +112,110 @@ export interface KitRequestSpec {
134
112
  splitBy?: { path: string; key: string };
135
113
  /** request.cancelable:处理中可取消 */
136
114
  cancelable?: boolean;
137
- ok?: { path?: string; equals?: unknown; message?: string };
138
115
  notify?: string;
139
116
  /** 动作名(页头状态行的『<动作名>处理中…』与通用回退文案用) */
140
117
  label?: string;
141
118
  /** 页头状态行文案(request.status) */
142
119
  status?: { ok?: string; failed?: string };
143
- then?: 'reload' | 'none';
144
- /** H1b / H1c:then 写成数组时的规整项(此时 then 恒为 none,缺省刷新不再发生);on 已补缺省 */
145
- thenItems?: Array<{ reload: true | string; on: 'success' | 'failed' | 'always' }>;
146
- /** H1d / H1e:声明该接口只读,允许自动触发 */
120
+ /** H1d:声明该接口只读,允许自动触发;只读请求成功后宿主不重取(写操作成功后固定重取) */
147
121
  read?: boolean;
148
122
  /** H1d:页面挂载时自动发一次 */
149
123
  auto?: 'mount';
150
- /** 成功后关掉协调组件当前打开的浮层(附加浮层 events 的 then: saved / close 编来;失败时窗口保留) */
124
+ /** 成功后关掉协调组件当前打开的浮层(附加浮层 events 绑的 request 动作编来,写死的收尾协作;失败时窗口保留) */
151
125
  closeOnSuccess?: boolean;
152
126
  filename?: string;
153
- /** GA4:发请求前先弹出的自绘输入表单(确认后输入值作 $prompt 取值根) */
154
- prompt?: KitPromptSpec;
155
127
  /** GA6:请求超时毫秒(编进合成写对象的 write.timeoutMs) */
156
128
  timeoutMs?: number;
157
- }
158
-
159
- /** 请求前输入(request.prompt)的规整形态 */
160
- export interface KitPromptSpec {
161
- title?: string;
162
- submitLabel?: string;
163
- fields: Array<{
164
- name: string;
165
- label?: string;
166
- type: 'text' | 'textarea' | 'number' | 'select' | 'switch';
167
- /** 字面量或 $filter / $row / $focus 取值路径(弹出时解析) */
168
- default?: unknown;
169
- required?: boolean;
170
- placeholder?: string;
171
- options?: Array<{ value: string | number | boolean; label: string }>;
172
- }>;
173
- }
174
-
175
- /** request.prompt 规整;写法不对记 KIT-ACT-005 并返回 null */
176
- export function promptOf(raw: unknown, at: string, diagnostics: KitDiagnostic[]): KitPromptSpec | null {
177
- const bad = (message: string, path = at): null => { diagnostics.push({ code: 'KIT-ACT-005', path, message }); return null; };
178
- if (!isRec(raw)) return bad('prompt 必须是对象 { title?, submitLabel?, fields: [...] }');
179
- const extra = Object.keys(raw).filter((k) => !EXT.promptKeys.includes(k));
180
- if (extra.length > 0) return bad(`prompt 的键 ${extra.join(' / ')} 不在闭集 ${EXT.promptKeys.join(' / ')} 内`);
181
- const out: KitPromptSpec = { fields: [] };
182
- for (const key of ['title', 'submitLabel'] as const) {
183
- const v = raw[key];
184
- if (v === undefined) continue;
185
- if (typeof v !== 'string' || v === '' || v.length > EXT.promptTitleMax) return bad(`prompt.${key} 必须是 1~${EXT.promptTitleMax} 字的文案`, `${at}.${key}`);
186
- out[key] = v;
187
- }
188
- const fields = raw.fields;
189
- if (!Array.isArray(fields) || fields.length === 0 || fields.length > EXT.promptFieldsMax) return bad(`prompt.fields 必须是 1~${EXT.promptFieldsMax} 项的数组`, `${at}.fields`);
190
- const seen = new Set<string>();
191
- const nameRe = new RegExp(EXT.promptNamePattern);
192
- const refRe = new RegExp(EXT.promptDefaultRefPattern);
193
- for (let i = 0; i < fields.length; i += 1) {
194
- const f = fields[i];
195
- const fat = `${at}.fields[${i}]`;
196
- if (!isRec(f)) return bad('每个输入项必须是对象 { name, label?, type?, default?, required?, options?, placeholder? }', fat);
197
- const fx = Object.keys(f).filter((k) => !EXT.promptFieldKeys.includes(k));
198
- if (fx.length > 0) return bad(`输入项的键 ${fx.join(' / ')} 不在闭集 ${EXT.promptFieldKeys.join(' / ')} 内`, fat);
199
- if (typeof f.name !== 'string' || !nameRe.test(f.name)) return bad('输入项的 name 必须是小写字母开头的标识符', `${fat}.name`);
200
- if (seen.has(f.name)) return bad(`输入项 name "${f.name}" 重复`, `${fat}.name`);
201
- seen.add(f.name);
202
- const type = f.type === undefined ? 'text' : String(f.type);
203
- if (!EXT.promptFieldTypes.includes(type)) return bad(`输入项的 type 只许 ${EXT.promptFieldTypes.join(' / ')}`, `${fat}.type`);
204
- const item: KitPromptSpec['fields'][number] = { name: f.name, type: type as 'text' };
205
- if (f.label !== undefined) {
206
- if (typeof f.label !== 'string' || f.label === '' || f.label.length > EXT.promptLabelMax) return bad(`输入项 label 必须是 1~${EXT.promptLabelMax} 字的文案`, `${fat}.label`);
207
- item.label = f.label;
208
- }
209
- if (f.placeholder !== undefined) {
210
- if (typeof f.placeholder !== 'string' || f.placeholder.length > EXT.promptTextMax) return bad('输入项 placeholder 必须是字符串', `${fat}.placeholder`);
211
- item.placeholder = f.placeholder;
212
- }
213
- if (f.required !== undefined) {
214
- if (typeof f.required !== 'boolean') return bad('输入项 required 必须是布尔', `${fat}.required`);
215
- item.required = f.required;
216
- }
217
- if (f.default !== undefined) {
218
- const d = f.default;
219
- const scalar = d === null || ['string', 'number', 'boolean'].includes(typeof d);
220
- if (!scalar) return bad('输入项 default 只许字面量或 $filter / $row / $focus 取值路径', `${fat}.default`);
221
- if (typeof d === 'string' && d.startsWith('$') && !refRe.test(d)) return bad(`输入项 default 的取值路径 ${d} 不合法(可用 $filter.x / $row.x / $focus.x)`, `${fat}.default`);
222
- if (typeof d === 'string' && d.length > EXT.promptTextMax) return bad('输入项 default 过长', `${fat}.default`);
223
- item.default = d;
224
- }
225
- if (type === 'select') {
226
- const opts = f.options;
227
- if (!Array.isArray(opts) || opts.length === 0 || opts.length > EXT.promptOptionsMax) return bad(`select 输入项必须有 1~${EXT.promptOptionsMax} 个 options`, `${fat}.options`);
228
- const list: NonNullable<typeof item.options> = [];
229
- for (let j = 0; j < opts.length; j += 1) {
230
- const o = opts[j];
231
- if (!isRec(o) || Object.keys(o).some((k) => !EXT.promptOptionKeys.includes(k))
232
- || !['string', 'number', 'boolean'].includes(typeof o.value) || typeof o.label !== 'string' || o.label === '') {
233
- return bad('options 的每项必须是 { value, label }', `${fat}.options[${j}]`);
234
- }
235
- list.push({ value: o.value as string, label: String(o.label) });
236
- }
237
- item.options = list;
238
- } else if (f.options !== undefined) return bad('只有 type: select 的输入项能写 options', `${fat}.options`);
239
- out.fields.push(item);
240
- }
241
- return out;
242
- }
243
-
244
- /**
245
- * request.then 数组规整(H1b / H1c):每项恰好 { reload, on? };reload 是 true / 数据对象名 / 以 / 开头的接口路径。
246
- * 写法不对记 KIT-ACT-009 并返回 null(数据对象名与接口路径在本页是否存在,由 attachActionHost 核对)。
247
- */
248
- export function thenItemsOf(raw: unknown, at: string, diagnostics: KitDiagnostic[]): NonNullable<KitRequestSpec['thenItems']> | null {
249
- const bad = (message: string, path = at): null => { diagnostics.push({ code: 'KIT-ACT-009', path, message }); return null; };
250
- if (!Array.isArray(raw) || raw.length === 0 || raw.length > THEN_MAX) return bad(`request.then 写成数组时必须是 1~${THEN_MAX} 项`);
251
- const out: NonNullable<KitRequestSpec['thenItems']> = [];
252
- for (let i = 0; i < raw.length; i += 1) {
253
- const it = raw[i];
254
- const iat = `${at}[${i}]`;
255
- if (!isRec(it)) return bad('每项必须是对象 { reload, on? }', iat);
256
- const extra = Object.keys(it).filter((k) => !THEN_ITEM_KEYS.includes(k));
257
- if (extra.length > 0) return bad(`then 项的键 ${extra.join(' / ')} 不在闭集 ${THEN_ITEM_KEYS.join(' / ')} 内`, iat);
258
- const target = it.reload;
259
- const okTarget = target === true || (typeof target === 'string' && (THEN_PATH_RE.test(target) || THEN_OBJECT_RE.test(target)));
260
- if (!okTarget) return bad('then 项的 reload 必须是 true、数据对象名,或以 / 开头的接口路径(重取 options.from 等于它的字段候选)', `${iat}.reload`);
261
- const on = it.on === undefined ? THEN_ITEM_ON_DEFAULT : String(it.on);
262
- if (!THEN_ITEM_ON.includes(on)) return bad(`then 项的 on 只能是 ${THEN_ITEM_ON.join(' / ')}`, `${iat}.on`);
263
- out.push({ reload: target as true | string, on: on as 'success' });
264
- }
265
- return out;
266
- }
267
-
268
- /** 自动触发(request.on: mount / view.form.onChange)的前置:只读声明与 POST;写类请求一律拒收(KIT-ACT-008) */
269
- export function checkAutoTriggerable(a: KitAction, at: string, diagnostics: KitDiagnostic[]): boolean {
270
- const r = a.request as unknown;
271
- if (!isRec(r)) {
272
- diagnostics.push({ code: 'KIT-ACT-008', path: at, message: `动作 ${a.id} 不是 request 动作,不能自动触发(自动触发只许 request.read 的只读请求)` });
273
- return false;
274
- }
275
- const method = r.method === undefined ? 'POST' : String(r.method);
276
- if (r.read !== true || !AUTO_READ_METHODS.includes(method)) {
277
- diagnostics.push({
278
- code: 'KIT-ACT-008', path: `${at}.request.read`,
279
- message: `动作 ${a.id} 会被自动触发,只许声明 request.read: true 且 method 为 ${AUTO_READ_METHODS.join(' / ')} 的只读请求;写类请求不得自动发`,
280
- });
281
- return false;
282
- }
283
- return true;
129
+ /** 纯字段映射:从当前行/上下文选取同名字段作为请求体 */
130
+ pick?: string[];
131
+ /** 纯字段映射:{ 请求体键名: 当前行/上下文字段名 } */
132
+ bodyMap?: Record<string, string>;
284
133
  }
285
134
 
286
135
  const snake = (s: string): string => s.replace(/([A-Z])/g, '_$1').toLowerCase().replace(/[^a-z0-9_]/g, '_').replace(/_+/g, '_').replace(/^_|_$/g, '');
287
136
 
288
137
  // ---------------------------------------------------------------- 校验
289
138
 
290
- function checkBindings(map: Record<string, unknown> | undefined, at: string, diagnostics: KitDiagnostic[]): boolean {
291
- if (map === undefined) return true;
292
- if (!isRec(map)) {
293
- diagnostics.push({ code: 'KIT-ACT-002', path: at, message: `${at} 必须是对象(键 -> 取值路径或字面量)` });
294
- return false;
295
- }
139
+ const PURE_FIELD_KEY = /^[A-Za-z_][A-Za-z0-9_]*$/;
140
+ const PURE_SOURCE_FIELD = /^(?:row\.)?([A-Za-z_][A-Za-z0-9_]*)$/;
141
+
142
+ /** 校验并规整 request.pick 与 request.bodyMap(只允许纯字段名映射,严禁表达式或计算逻辑) */
143
+ export function checkRequestFieldMapping(
144
+ r: Record<string, unknown>,
145
+ at: string,
146
+ diagnostics: KitDiagnostic[],
147
+ ): { pick?: string[]; bodyMap?: Record<string, string>; ok: boolean } {
296
148
  let ok = true;
297
- for (const [k, v] of Object.entries(map)) {
298
- if (typeof v !== 'string' || !v.startsWith('$')) continue;
299
- const root = v.slice(1).split('.')[0]!;
300
- if (root === 'steps') {
301
- // GB1:$steps.<步骤名>.<字段> 只在 StepForm 的步骤里有效(编译器已把步骤名改写成 s<序号>);别处没有『步骤』可取
302
- const parts = v.slice(1).split('.');
303
- if (!inKitStepScope() || parts.length !== 3 || !isCanonicalStepId(parts[1]!) || parts[2] === '') {
304
- diagnostics.push({ code: 'KIT-STEP-005', path: `${at}.${k}`, message: `取值路径 ${v} 只能用在 StepForm 的步骤动作里,写成 $steps.<更早的步骤名>.<字段>` });
305
- ok = false;
306
- }
307
- continue;
308
- }
309
- if (!BIND_ROOTS.includes(root)) {
310
- diagnostics.push({ code: 'KIT-ACT-002', path: `${at}.${k}`, message: `取值路径 ${v} 的根 "${root}" 不认识(可用:${BIND_ROOTS.map((r) => `$${r}`).join(' / ')})` });
149
+ let pick: string[] | undefined;
150
+ let bodyMap: Record<string, string> | undefined;
151
+
152
+ if (r.pick !== undefined) {
153
+ if (!Array.isArray(r.pick) || r.pick.length === 0) {
154
+ diagnostics.push({ code: 'KIT-ACT-002', path: `${at}.pick`, message: 'request.pick 必须是非空纯字段名数组' });
311
155
  ok = false;
312
- } else if (root === 'loaded' && v.split('.').length < 3) {
313
- // 版本锁取值 $loaded.<对象>.<字段路径>:少一段就读不到值,且缺值会拒绝发出请求
314
- diagnostics.push({ code: 'KIT-SHOW-004', path: `${at}.${k}`, message: `取值路径 ${v} 不完整:版本锁要写 $loaded.<数据对象名>.<字段路径>(如 $loaded.status.version)` });
156
+ } else {
157
+ const normalized: string[] = [];
158
+ const seen = new Set<string>();
159
+ r.pick.forEach((item, idx) => {
160
+ const m = typeof item === 'string' ? PURE_SOURCE_FIELD.exec(item) : null;
161
+ if (!m) {
162
+ diagnostics.push({
163
+ code: 'KIT-ACT-002',
164
+ path: `${at}.pick[${idx}]`,
165
+ message: `request.pick[${idx}] 只允许纯字段名(严禁表达式、$路径或计算逻辑),收到 ${JSON.stringify(item)}`,
166
+ });
167
+ ok = false;
168
+ return;
169
+ }
170
+ const f = m[1]!;
171
+ if (seen.has(f)) {
172
+ diagnostics.push({ code: 'KIT-ACT-002', path: `${at}.pick[${idx}]`, message: `request.pick 字段名 "${f}" 重复` });
173
+ ok = false;
174
+ return;
175
+ }
176
+ seen.add(f);
177
+ normalized.push(f);
178
+ });
179
+ if (normalized.length > 0) pick = normalized;
180
+ }
181
+ }
182
+
183
+ if (r.bodyMap !== undefined) {
184
+ if (!isRec(r.bodyMap) || Object.keys(r.bodyMap).length === 0) {
185
+ diagnostics.push({ code: 'KIT-ACT-002', path: `${at}.bodyMap`, message: 'request.bodyMap 必须是非空 { 目标键: 源字段名 } 映射对象' });
315
186
  ok = false;
187
+ } else {
188
+ const mapped: Record<string, string> = {};
189
+ for (const [targetKey, sourceRaw] of Object.entries(r.bodyMap)) {
190
+ if (!PURE_FIELD_KEY.test(targetKey)) {
191
+ diagnostics.push({
192
+ code: 'KIT-ACT-002',
193
+ path: `${at}.bodyMap.${targetKey}`,
194
+ message: `request.bodyMap 的目标键 "${targetKey}" 必须是纯字段标识符`,
195
+ });
196
+ ok = false;
197
+ continue;
198
+ }
199
+ const m = typeof sourceRaw === 'string' ? PURE_SOURCE_FIELD.exec(sourceRaw) : null;
200
+ if (!m) {
201
+ diagnostics.push({
202
+ code: 'KIT-ACT-002',
203
+ path: `${at}.bodyMap.${targetKey}`,
204
+ message: `request.bodyMap.${targetKey} 的值只允许纯字段名(严禁表达式、$路径或计算逻辑),收到 ${JSON.stringify(sourceRaw)}`,
205
+ });
206
+ ok = false;
207
+ continue;
208
+ }
209
+ mapped[targetKey] = m[1]!;
210
+ }
211
+ if (Object.keys(mapped).length > 0) bodyMap = mapped;
316
212
  }
317
213
  }
318
- return ok;
214
+
215
+ return { ...(pick !== undefined ? { pick } : {}), ...(bodyMap !== undefined ? { bodyMap } : {}), ok };
319
216
  }
320
217
 
218
+
321
219
  function unknownKeys(raw: Record<string, unknown>, allowed: readonly string[], at: string, diagnostics: KitDiagnostic[]): boolean {
322
220
  let ok = true;
323
221
  for (const key of Object.keys(raw)) {
@@ -339,15 +237,20 @@ export function validateRequestAction(a: KitAction, at: string, diagnostics: Kit
339
237
  if (a.request !== undefined) {
340
238
  const r = a.request as unknown;
341
239
  if (!isRec(r)) {
342
- diagnostics.push({ code: 'KIT-ACT-002', path: `${at}.request`, message: 'request 必须是对象 { api, method?, body?, into?, ok?, notify?, then? }' });
240
+ diagnostics.push({ code: 'KIT-ACT-002', path: `${at}.request`, message: 'request 必须是对象 { api, method?, into?, notify?, read?, on?, cancelable?, status?, timeoutMs? }' });
343
241
  return false;
344
242
  }
345
243
  let ok = unknownKeys(r, REQUEST_KEYS, `${at}.request`, diagnostics);
346
244
  if (typeof r.api !== 'string' || r.api.trim() === '') {
347
245
  diagnostics.push({ code: 'KIT-ACT-002', path: `${at}.request.api`, message: 'request.api 必须是非空接口地址' });
348
246
  ok = false;
247
+ } else if (!checkNoRelativeOrSystemPath(r.api, `${at}.request.api`, diagnostics, 'KIT-ACT-002')) {
248
+ ok = false;
349
249
  }
350
- if (r.method !== undefined && !REQUEST_METHODS.includes(String(r.method))) {
250
+ if (typeof r.url === 'string' && !checkNoRelativeOrSystemPath(r.url, `${at}.request.url`, diagnostics, 'KIT-ACT-002')) {
251
+ ok = false;
252
+ }
253
+ if (r.method !== undefined && (typeof r.method !== 'string' || !REQUEST_METHODS.includes(r.method))) {
351
254
  diagnostics.push({ code: 'KIT-ACT-002', path: `${at}.request.method`, message: `request.method 只能是 ${REQUEST_METHODS.join(' / ')}(删除用 builtin: remove;读取用对象的 behavior.from)` });
352
255
  ok = false;
353
256
  }
@@ -357,13 +260,7 @@ export function validateRequestAction(a: KitAction, at: string, diagnostics: Kit
357
260
  diagnostics.push({ code: 'KIT-ACT-002', path: `${at}.request.into`, message: `动作 ${a.id} 的 request.into 写了 key(按行分槽),但它是工具栏动作(on: toolbar),没有「当前行」可取` });
358
261
  ok = false;
359
262
  }
360
- if (Array.isArray(r.then)) {
361
- if (thenItemsOf(r.then, `${at}.request.then`, diagnostics) === null) ok = false;
362
- } else if (r.then !== undefined && !THEN_VALUES.includes(String(r.then))) {
363
- diagnostics.push({ code: 'KIT-ACT-002', path: `${at}.request.then`, message: `request.then 只能是 ${THEN_VALUES.join(' / ')},或 [{ reload, on? }] 数组` });
364
- ok = false;
365
- }
366
- // H1d / H1e:read 声明与挂载自动触发
263
+ // H1d:read 声明与挂载自动触发
367
264
  if (r.read !== undefined && typeof r.read !== 'boolean') {
368
265
  diagnostics.push({ code: 'KIT-ACT-008', path: `${at}.request.read`, message: 'request.read 必须是布尔' });
369
266
  ok = false;
@@ -382,27 +279,13 @@ export function validateRequestAction(a: KitAction, at: string, diagnostics: Kit
382
279
  } else {
383
280
  const mountProblems: string[] = [];
384
281
  if (r.read !== true) mountProblems.push('必须声明 request.read: true(写类请求不得自动发)');
385
- if (r.prompt !== undefined) mountProblems.push('不能写 prompt(挂载时没有人可以输入)');
386
282
  if (a.confirm !== undefined && a.confirm !== '') mountProblems.push('不能写 confirm(自动触发不经确认)');
387
283
  if (a.permission !== undefined && a.permission !== '') mountProblems.push('不能写 permission(自动触发不经权限尾段)');
388
284
  if (r.into !== undefined && intoKeyOf(r.into) !== undefined) mountProblems.push('into 不能按行分槽(挂载时没有当前行)');
389
- if (isRec(r.body)) {
390
- for (const [k, v] of Object.entries(r.body)) {
391
- if (typeof v !== 'string' || !v.startsWith('$')) continue;
392
- const root = v.slice(1).split('.')[0]!;
393
- if (!AUTO_MOUNT_ROOTS.includes(root)) mountProblems.push(`body.${k} 的取值路径 ${v} 在挂载时取不到值(只许 ${AUTO_MOUNT_ROOTS.map((x) => `$${x}`).join(' / ')})`);
394
- }
395
- }
396
285
  for (const m of mountProblems) diagnostics.push({ code: 'KIT-ACT-008', path: `${at}.request.on`, message: `动作 ${a.id} 的 request.on: ${String(r.on)} ${m}` });
397
286
  if (mountProblems.length > 0) ok = false;
398
287
  }
399
288
  }
400
- if (r.ok !== undefined) {
401
- if (!isRec(r.ok)) {
402
- diagnostics.push({ code: 'KIT-ACT-002', path: `${at}.request.ok`, message: 'request.ok 必须是对象 { path, equals?, message? }' });
403
- ok = false;
404
- } else ok = unknownKeys(r.ok, OK_KEYS, `${at}.request.ok`, diagnostics) && ok;
405
- }
406
289
  if (r.notify !== undefined && typeof r.notify !== 'string') {
407
290
  diagnostics.push({ code: 'KIT-ACT-002', path: `${at}.request.notify`, message: 'request.notify 必须是字符串(词条或文案)' });
408
291
  ok = false;
@@ -426,61 +309,43 @@ export function validateRequestAction(a: KitAction, at: string, diagnostics: Kit
426
309
  }
427
310
  }
428
311
  }
429
- ok = checkBindings(r.body as Record<string, unknown> | undefined, `${at}.request.body`, diagnostics) && ok;
430
312
  // GA6:超时毫秒,区间读 core 语法真源 write.timeoutMs
431
313
  if (r.timeoutMs !== undefined && (typeof r.timeoutMs !== 'number' || !Number.isInteger(r.timeoutMs) || r.timeoutMs < TIMEOUT.min || r.timeoutMs > TIMEOUT.max)) {
432
314
  diagnostics.push({ code: 'KIT-ACT-006', path: `${at}.request.timeoutMs`, message: `request.timeoutMs 必须是 ${TIMEOUT.min}~${TIMEOUT.max} 的整数毫秒` });
433
315
  ok = false;
434
316
  }
435
- // GA4:prompt 规整,且 body 里 $prompt.<名> 必须是声明过的输入项
436
- const promptNames = new Set<string>();
437
- if (r.prompt !== undefined) {
438
- const p = promptOf(r.prompt, `${at}.request.prompt`, diagnostics);
439
- if (p === null) ok = false;
440
- else for (const f of p.fields) promptNames.add(f.name);
441
- }
442
- if (isRec(r.body)) {
443
- for (const [k, v] of Object.entries(r.body)) {
444
- if (typeof v !== 'string' || !v.startsWith('$prompt')) continue;
445
- const name = v.slice('$prompt.'.length).split('.')[0] ?? '';
446
- if (!v.startsWith('$prompt.') || !promptNames.has(name)) {
447
- diagnostics.push({ code: 'KIT-ACT-005', path: `${at}.request.body.${k}`, message: r.prompt === undefined ? `${v} 引用了 $prompt,但动作没有写 request.prompt` : `${v} 引用的输入项不在 prompt.fields 里(已声明:${[...promptNames].join(' / ')})` });
448
- ok = false;
449
- }
450
- }
451
- }
452
- if (a.then !== undefined || a.after !== undefined) {
453
- diagnostics.push({ code: 'KIT-ACT-002', path: `${at}.then`, message: `动作 ${a.id} 是 request,成功后的刷新写 request.then;动作级 then / after 不适用(请求由页面级宿主异步执行)` });
454
- ok = false;
455
- }
317
+ const mapping = checkRequestFieldMapping(r, `${at}.request`, diagnostics);
318
+ if (!mapping.ok) ok = false;
456
319
  return ok;
457
320
  }
458
321
  if (a.download !== undefined) {
459
322
  const d = a.download as unknown;
460
323
  if (!isRec(d)) {
461
- diagnostics.push({ code: 'KIT-ACT-002', path: `${at}.download`, message: 'download 必须是对象 { api, method?, body?, query?, filename? }' });
324
+ diagnostics.push({ code: 'KIT-ACT-002', path: `${at}.download`, message: 'download 必须是对象 { api, method?, filename? }' });
462
325
  return false;
463
326
  }
464
327
  let ok = unknownKeys(d, DOWNLOAD_KEYS, `${at}.download`, diagnostics);
465
328
  if (typeof d.api !== 'string' || d.api.trim() === '') {
466
329
  diagnostics.push({ code: 'KIT-ACT-002', path: `${at}.download.api`, message: 'download.api 必须是非空接口地址' });
467
330
  ok = false;
331
+ } else if (!checkNoRelativeOrSystemPath(d.api, `${at}.download.api`, diagnostics, 'KIT-ACT-002')) {
332
+ ok = false;
468
333
  }
469
- const method = d.method === undefined ? DOWNLOAD_METHODS[0]! : String(d.method);
470
- if (!DOWNLOAD_METHODS.includes(method)) {
471
- diagnostics.push({ code: 'KIT-ACT-002', path: `${at}.download.method`, message: `download.method 只能是 ${DOWNLOAD_METHODS.join(' / ')}(浏览器原生下载只有链接与表单两种形态)` });
334
+ if (typeof d.url === 'string' && !checkNoRelativeOrSystemPath(d.url, `${at}.download.url`, diagnostics, 'KIT-ACT-002')) {
472
335
  ok = false;
473
336
  }
474
- if (method === DOWNLOAD_METHODS[0] && d.body !== undefined) {
475
- diagnostics.push({ code: 'KIT-ACT-002', path: `${at}.download.body`, message: 'GET 下载没有请求体,参数写 query;要带体请用 method: POST' });
337
+ const method = d.method === undefined ? DOWNLOAD_METHODS[0]! : (typeof d.method === 'string' ? d.method : '');
338
+ if (typeof d.method === 'string' && !DOWNLOAD_METHODS.includes(method)) {
339
+ diagnostics.push({ code: 'KIT-ACT-002', path: `${at}.download.method`, message: `download.method 只能是 ${DOWNLOAD_METHODS.join(' / ')}(浏览器原生下载只有链接与表单两种形态)` });
340
+ ok = false;
341
+ } else if (d.method !== undefined && typeof d.method !== 'string') {
342
+ diagnostics.push({ code: 'KIT-ACT-002', path: `${at}.download.method`, message: 'download.method 必须是字符串' });
476
343
  ok = false;
477
344
  }
478
345
  if (d.filename !== undefined && typeof d.filename !== 'string') {
479
346
  diagnostics.push({ code: 'KIT-ACT-002', path: `${at}.download.filename`, message: 'download.filename 必须是字符串' });
480
347
  ok = false;
481
348
  }
482
- ok = checkBindings(d.body as Record<string, unknown> | undefined, `${at}.download.body`, diagnostics) && ok;
483
- ok = checkBindings(d.query as Record<string, unknown> | undefined, `${at}.download.query`, diagnostics) && ok;
484
349
  return ok;
485
350
  }
486
351
  return true;
@@ -493,6 +358,19 @@ let collector: Map<string, KitRequestSpec> | null = null;
493
358
 
494
359
  export function beginRequestCollect(): void {
495
360
  collector = new Map();
361
+ beginFilterReloadCollect();
362
+ resetGateRefs();
363
+ }
364
+
365
+ /** 当前是否处于页面编译的收集期(测试与诊断用;编译结束后必须为 false) */
366
+ export function isRequestCollecting(): boolean {
367
+ return collector !== null;
368
+ }
369
+
370
+ /** 编译被提前返回 / 异常打断时的清理:丢掉收集器与 outcome 引用表(正常路径由 endRequestCollect 取走) */
371
+ export function abortRequestCollect(): void {
372
+ collector = null;
373
+ abortFilterReloadCollect();
496
374
  resetGateRefs();
497
375
  }
498
376
 
@@ -532,34 +410,29 @@ export function registerRequestAction(
532
410
  let spec: KitRequestSpec;
533
411
  if (a.request !== undefined) {
534
412
  const r: KitRequestDecl = a.request;
413
+ const mapping = checkRequestFieldMapping(r as unknown as Record<string, unknown>, `${at}.request`, []);
535
414
  const method = r.method ?? 'POST';
536
415
  const writeObject = `${OBJECT_PREFIX}${snake(object)}_${snake(a.id)}`;
537
416
  spec = {
538
417
  kind: 'request', actionId: a.id, object, api: r.api, method,
539
- ...(r.body !== undefined ? { body: r.body } : {}),
540
418
  writeObject, mode: method === 'POST' ? 'create' : 'update', outcome: intoNameOf(r.into) ?? writeObject,
541
419
  ...(intoKeyOf(r.into) !== undefined ? { outcomeKey: intoKeyOf(r.into)! } : {}),
542
420
  ...(intoSplitOf(r.into) !== undefined ? { splitBy: intoSplitOf(r.into)! } : {}),
543
421
  ...(r.cancelable === true ? { cancelable: true } : {}),
544
- ...(r.ok !== undefined ? { ok: r.ok } : {}),
545
422
  ...(r.notify !== undefined ? { notify: r.notify } : {}),
546
423
  ...(a.name !== '' ? { label: a.name } : {}),
547
424
  ...(r.status !== undefined ? { status: { ...r.status } } : {}),
548
- // 写成数组时缺省刷新不再发生(由数组项自己说清楚);声明 read 的请求缺省不刷新(读不改数据)
549
- then: Array.isArray(r.then) ? 'none' : (r.then ?? (r.read === true ? 'none' : 'reload')),
550
- ...(Array.isArray(r.then) ? { thenItems: thenItemsOf(r.then, '', [])! } : {}),
551
425
  ...(r.read === true ? { read: true } : {}),
552
426
  ...(r.on !== undefined ? { auto: r.on } : {}),
553
427
  ...(opts.closeOnSuccess === true ? { closeOnSuccess: true } : {}),
554
- ...(r.prompt !== undefined ? { prompt: promptOf(r.prompt, '', [])! } : {}),
555
428
  ...(r.timeoutMs !== undefined ? { timeoutMs: r.timeoutMs } : {}),
429
+ ...(mapping.pick !== undefined ? { pick: mapping.pick } : {}),
430
+ ...(mapping.bodyMap !== undefined ? { bodyMap: mapping.bodyMap } : {}),
556
431
  };
557
432
  } else {
558
433
  const d: KitDownloadDecl = a.download!;
559
434
  spec = {
560
435
  kind: 'download', actionId: a.id, object, api: d.api, method: d.method ?? 'GET',
561
- ...(d.body !== undefined ? { body: d.body } : {}),
562
- ...(d.query !== undefined ? { query: d.query } : {}),
563
436
  ...(d.filename !== undefined ? { filename: d.filename } : {}),
564
437
  };
565
438
  }
@@ -575,7 +448,115 @@ export function requestWriteObjects(specs: ReadonlyMap<string, KitRequestSpec>):
575
448
  for (const spec of specs.values()) {
576
449
  if (spec.kind !== 'request' || spec.writeObject === undefined) continue;
577
450
  const channel = spec.mode === 'create' ? 'create' : 'update';
578
- out[spec.writeObject] = { fields: {}, write: { [channel]: { api: spec.api, method: spec.method }, ...(spec.timeoutMs !== undefined ? { timeoutMs: spec.timeoutMs } : {}) } };
451
+ const onlyKeys = [
452
+ ...(spec.pick ?? []),
453
+ ...(spec.bodyMap ? Object.keys(spec.bodyMap) : []),
454
+ ];
455
+ const uniqueOnly = [...new Set(onlyKeys)];
456
+ const fields: Record<string, { name: string; type: string }> = {};
457
+ for (const k of uniqueOnly) {
458
+ fields[k] = { name: k, type: 'string' };
459
+ }
460
+ out[spec.writeObject] = {
461
+ fields,
462
+ write: {
463
+ [channel]: { api: spec.api, method: spec.method },
464
+ ...(uniqueOnly.length > 0 ? { only: uniqueOnly } : {}),
465
+ ...(spec.timeoutMs !== undefined ? { timeoutMs: spec.timeoutMs } : {}),
466
+ },
467
+ };
579
468
  }
580
469
  return out;
581
470
  }
471
+
472
+ /**
473
+ * 按 request.pick 与 request.bodyMap 从源数据(row / draft / focus / values)构造请求体 model:
474
+ * - 若声明了 pick: ['id', 'status'],从源对象提取对应同名字段;
475
+ * - 若声明了 bodyMap: { orderId: 'id', orderNo: 'row.code' },读取源字段(去 row. 前缀)并写入目标键名(payload.orderId = src.id)。
476
+ */
477
+ export function buildRequestPayload(
478
+ spec: Pick<KitRequestSpec, 'pick' | 'bodyMap'>,
479
+ sources: Readonly<Record<string, unknown>> | ReadonlyArray<Readonly<Record<string, unknown>> | undefined>,
480
+ ): Record<string, unknown> {
481
+ const list: ReadonlyArray<Readonly<Record<string, unknown>>> = Array.isArray(sources)
482
+ ? sources.filter((s): s is Readonly<Record<string, unknown>> => isRec(s))
483
+ : isRec(sources)
484
+ ? [sources]
485
+ : [];
486
+ const readField = (rawField: string): unknown => {
487
+ const field = rawField.startsWith('row.') ? rawField.slice(4) : rawField;
488
+ for (const src of list) {
489
+ if (field in src && src[field] !== undefined) return src[field];
490
+ if (isRec(src.row) && field in src.row && src.row[field] !== undefined) return src.row[field];
491
+ if (isRec(src.record) && field in src.record && src.record[field] !== undefined) return src.record[field];
492
+ if (isRec(src.values) && field in src.values && src.values[field] !== undefined) return src.values[field];
493
+ }
494
+ return undefined;
495
+ };
496
+ const out: Record<string, unknown> = {};
497
+ if (Array.isArray(spec.pick)) {
498
+ for (const rawKey of spec.pick) {
499
+ const key = rawKey.startsWith('row.') ? rawKey.slice(4) : rawKey;
500
+ const val = readField(key);
501
+ if (val !== undefined) out[key] = val;
502
+ }
503
+ }
504
+ if (isRec(spec.bodyMap)) {
505
+ for (const [targetKey, sourceRaw] of Object.entries(spec.bodyMap)) {
506
+ if (typeof sourceRaw !== 'string') continue;
507
+ const val = readField(sourceRaw);
508
+ if (val !== undefined) out[targetKey] = val;
509
+ }
510
+ }
511
+ return out;
512
+ }
513
+
514
+ /**
515
+ * 针对单对象源数据的请求体映射:按 pick 筛选,按 bodyMap 重命名源字段;
516
+ * 若字段在 bodyMap 中被映射,则优先输出映射后的 targetKey,避免重复输出原始键。
517
+ */
518
+ export function applyRequestPayloadMapping(
519
+ source: Record<string, unknown>,
520
+ mapping: { pick?: readonly string[]; bodyMap?: Readonly<Record<string, string>> },
521
+ ): Record<string, unknown> {
522
+ const readField = (rawField: string): unknown => {
523
+ const field = rawField.startsWith("row.") ? rawField.slice(4) : rawField;
524
+ if (source && typeof source === "object") {
525
+ if (field in source && source[field] !== undefined) return source[field];
526
+ const s = source;
527
+ if (isRec(s.row) && field in s.row && s.row[field] !== undefined) return s.row[field];
528
+ if (isRec(s.record) && field in s.record && s.record[field] !== undefined) return s.record[field];
529
+ if (isRec(s.values) && field in s.values && s.values[field] !== undefined) return s.values[field];
530
+ }
531
+ return undefined;
532
+ };
533
+
534
+ const bodyMap = mapping.bodyMap;
535
+ const pick = mapping.pick;
536
+ const out: Record<string, unknown> = {};
537
+ const mappedSourceKeys = new Set<string>();
538
+
539
+ if (isRec(bodyMap)) {
540
+ for (const [targetKey, sourceRaw] of Object.entries(bodyMap)) {
541
+ if (typeof sourceRaw !== "string") continue;
542
+ const cleanSource = sourceRaw.startsWith("row.") ? sourceRaw.slice(4) : sourceRaw;
543
+ mappedSourceKeys.add(cleanSource);
544
+ const val = readField(sourceRaw);
545
+ if (val !== undefined) out[targetKey] = val;
546
+ }
547
+ }
548
+
549
+ if (Array.isArray(pick)) {
550
+ for (const rawKey of pick) {
551
+ const key = rawKey.startsWith("row.") ? rawKey.slice(4) : rawKey;
552
+ if (!mappedSourceKeys.has(key)) {
553
+ const val = readField(key);
554
+ if (val !== undefined) out[key] = val;
555
+ }
556
+ }
557
+ } else if (!isRec(bodyMap) || Object.keys(bodyMap).length === 0) {
558
+ return { ...source };
559
+ }
560
+
561
+ return out;
562
+ }