soma-kit 0.1.11 → 0.1.13
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.
- package/README.md +106 -112
- package/bin/soma-kit.mjs +32 -2
- package/bin/soma.mjs +22 -0
- package/package.json +14 -7
- package/packs/finance/reconcile-board.ts +5 -2
- package/packs/finance/reconcile-desk/compile.ts +3 -2
- package/spec/generated/kit-app.schema.json +929 -37
- package/spec/generated/kit-page.schema.json +1684 -161
- package/spec/kit-grammar.json +1176 -584
- package/spec/kit-grammar.schema.json +1971 -393
- package/src/app/app-config.ts +449 -347
- package/src/app/component-gate.ts +283 -28
- package/src/app/compose-apps.ts +79 -8
- package/src/app/define-kit-actions.ts +245 -41
- package/src/app/define-kit-app.ts +176 -33
- package/src/app/define-kit-view.ts +104 -0
- package/src/app/dev-diagnostic.ts +5 -0
- package/src/app/envelope.ts +1 -161
- package/src/app/index.ts +29 -6
- package/src/app/kit-view-context.ts +439 -0
- package/src/app/notify-renderer.ts +1 -115
- package/src/app/paged-list-adapter.ts +1 -240
- package/src/app/render-ports.ts +18 -0
- package/src/app/server-pages.ts +11 -3
- package/src/app/server.ts +530 -103
- package/src/app/submit.types.ts +1 -1
- package/src/app/theme-endpoint.ts +63 -0
- package/src/app/theme-runtime-shared.ts +1 -0
- package/src/app/theme-runtime.ts +667 -0
- package/src/base/action-busy.ts +103 -6
- package/src/base/action-gate.ts +4 -255
- package/src/base/action-slots.ts +58 -0
- package/src/base/alert.ts +5 -3
- package/src/base/anchored-layer.ts +50 -0
- package/src/base/avatar.ts +2 -2
- package/src/base/button.ts +99 -37
- package/src/base/cascader.ts +11 -12
- package/src/base/check-core.ts +9 -1
- package/src/base/checkbox.ts +2 -1
- package/src/base/choice.ts +49 -28
- package/src/base/class-candidates.ts +17 -0
- package/src/base/color-picker.ts +16 -11
- package/src/base/combobox.ts +5 -3
- package/src/base/command-palette.ts +10 -6
- package/src/base/context-menu.ts +10 -7
- package/src/base/countdown.ts +1 -1
- package/src/base/date-range.ts +32 -18
- package/src/base/date.ts +135 -28
- package/src/base/delta.ts +72 -0
- package/src/base/divider.ts +2 -2
- package/src/base/end-edge.ts +49 -0
- package/src/base/fab.ts +12 -5
- package/src/base/gap-value.ts +148 -0
- package/src/base/hint-tips.ts +170 -0
- package/src/base/icons.ts +8 -0
- package/src/base/illustrations.ts +94 -0
- package/src/base/image.ts +1 -1
- package/src/base/index.ts +35 -11
- package/src/base/input.ts +42 -13
- package/src/base/kbd.ts +3 -1
- package/src/base/link.ts +4 -4
- package/src/base/listbox-core.ts +56 -35
- package/src/base/loading-gate.ts +186 -0
- package/src/base/mentions.ts +7 -6
- package/src/base/menu-button.ts +28 -12
- package/src/base/menu-core.ts +41 -8
- package/src/base/motion/aura.ts +2 -2
- package/src/base/motion/hover-3d.ts +3 -3
- package/src/base/motion/hover-gallery.ts +2 -2
- package/src/base/motion/marquee.ts +3 -3
- package/src/base/motion/text-rotate.ts +2 -2
- package/src/base/number.ts +93 -80
- package/src/base/otp.ts +9 -5
- package/src/base/overlay-runtime.ts +235 -0
- package/src/base/permission-gate.ts +6 -0
- package/src/base/popover.ts +48 -16
- package/src/base/popup.ts +143 -19
- package/src/base/portal-core.ts +4 -0
- package/src/base/price-text.ts +2 -2
- package/src/base/progress.ts +2 -2
- package/src/base/qr-code.ts +4 -4
- package/src/base/qty-stepper.ts +14 -8
- package/src/base/radio.ts +2 -1
- package/src/base/range.ts +21 -4
- package/src/base/rating.ts +12 -7
- package/src/base/reason-tip.ts +150 -0
- package/src/base/segmented.ts +27 -21
- package/src/base/select.ts +4 -3
- package/src/base/shared.ts +387 -49
- package/src/base/state-panel.ts +346 -0
- package/src/base/status-tone.ts +27 -0
- package/src/base/sticky-edge.ts +116 -0
- package/src/base/swap.ts +10 -7
- package/src/base/switch.ts +11 -6
- package/src/base/tag-input.ts +20 -16
- package/src/base/tag.ts +68 -34
- package/src/base/text.ts +80 -18
- package/src/base/textarea.ts +37 -11
- package/src/base/time-picker.ts +18 -13
- package/src/base/tree-select.ts +21 -12
- package/src/base/trend-tone.ts +9 -0
- package/src/base/upload.ts +48 -14
- package/src/base/view-transition.ts +77 -0
- package/src/base/virtual-list.ts +107 -1
- package/src/biz/approval-desk/compile.ts +23 -41
- package/src/biz/approval-desk/shell.ts +11 -8
- package/src/biz/auth-panel/compile.ts +37 -52
- package/src/biz/auth-panel/index.ts +1 -1
- package/src/biz/auth-panel/shell.ts +5 -4
- package/src/biz/category-crud/compile.ts +23 -37
- package/src/biz/category-crud/shell.ts +2 -1
- package/src/biz/checkout-page/compile.ts +22 -5
- package/src/biz/checkout-page/shell.ts +4 -3
- package/src/biz/compose.ts +13 -27
- package/src/biz/define.ts +5 -4
- package/src/biz/import-wizard/compile.ts +22 -26
- package/src/biz/import-wizard/hub.ts +126 -61
- package/src/biz/import-wizard/shell.ts +5 -4
- package/src/biz/index.ts +3 -3
- package/src/biz/landing-page/compile.ts +19 -3
- package/src/biz/link/hub.ts +69 -22
- package/src/biz/link/shared.ts +127 -119
- package/src/biz/master-sub/compile.ts +127 -48
- package/src/biz/master-sub/index.ts +5 -2
- package/src/biz/master-sub/shell.ts +95 -18
- package/src/biz/multi-board/compile.ts +38 -50
- package/src/biz/multi-board/index.ts +18 -1
- package/src/biz/multi-board/shell.ts +32 -20
- package/src/biz/notification-center/compile.ts +21 -33
- package/src/biz/notification-center/shell.ts +6 -4
- package/src/biz/page-templates/domain-templates.ts +80 -13
- package/src/biz/page-templates/result-page/compile.ts +11 -2
- package/src/biz/page-templates/result-page/shell.ts +2 -1
- package/src/biz/page-templates/shared.ts +34 -36
- package/src/biz/page-templates/sign-in-page/shell.ts +2 -2
- package/src/biz/record-detail/compile.ts +48 -43
- package/src/biz/record-detail/index.ts +11 -1
- package/src/biz/record-detail/shell.ts +8 -6
- package/src/biz/settings-center/compile.ts +7 -5
- package/src/biz/settings-center/shell.ts +6 -4
- package/src/biz/shared/action-host.ts +97 -211
- package/src/biz/shared/compile-helpers.ts +98 -0
- package/src/biz/shared/coordinator.ts +472 -92
- package/src/biz/shared/index.ts +13 -2
- package/src/biz/shared/object-aliases.ts +154 -0
- package/src/biz/shared/overlay-compile.ts +239 -0
- package/src/biz/shared/overlay-shell.ts +209 -0
- package/src/biz/shared/pipes.ts +50 -31
- package/src/biz/shared/remove-wire.ts +14 -0
- package/src/biz/shared/runtime-hub.ts +226 -24
- package/src/biz/single-form/compile.ts +16 -37
- package/src/biz/single-form/shell.ts +4 -3
- package/src/biz/standard-crud/compile.ts +72 -255
- package/src/biz/standard-crud/shell.ts +21 -99
- package/src/biz/step-form/compile.ts +26 -97
- package/src/biz/step-form/hub.ts +34 -41
- package/src/biz/step-form/shell.ts +5 -5
- package/src/biz/types.ts +4 -3
- package/src/cli/core-imports.ts +54 -0
- package/src/cli/kit-cli.ts +254 -25
- package/src/cli/kit-init.ts +227 -0
- package/src/cli/layout-cli.ts +167 -0
- package/src/cli/migrate/index.ts +10 -0
- package/src/cli/migrate/migrate.ts +248 -0
- package/src/cli/migrate/text-utils.ts +306 -0
- package/src/cli/migrate/theme-map.ts +104 -0
- package/src/cli/migrate/ts-rules.ts +235 -0
- package/src/cli/migrate/types.ts +95 -0
- package/src/cli/migrate/view-skeleton.ts +159 -0
- package/src/cli/migrate/yaml-report.ts +376 -0
- package/src/cli/migrate/yaml-rules.ts +465 -0
- package/src/cli/service-endpoint-check.ts +425 -0
- package/src/cli/source-path-check.d.mts +17 -0
- package/src/cli/source-path-check.mjs +334 -0
- package/src/cli/view-writes.ts +761 -0
- package/src/compile/action-host-attach.ts +21 -29
- package/src/compile/closed-set.ts +570 -0
- package/src/compile/compile-page.ts +267 -76
- package/src/compile/component-candidates.ts +13 -2
- package/src/compile/hints.ts +30 -1
- package/src/compile/index.ts +1 -0
- package/src/compile/kit-error.ts +1 -0
- package/src/compile/layout-lint/engine.ts +82 -0
- package/src/compile/layout-lint/index.ts +55 -0
- package/src/compile/layout-lint/rules-composition.ts +218 -0
- package/src/compile/layout-lint/rules-form.ts +192 -0
- package/src/compile/layout-lint/rules-table.ts +194 -0
- package/src/compile/layout-lint/score.ts +52 -0
- package/src/compile/layout-lint/types.ts +51 -0
- package/src/compile/locate.ts +21 -1
- package/src/compile/parse.ts +370 -41
- package/src/compile/redirect.ts +6 -2
- package/src/compile/remove-guard.ts +10 -7
- package/src/compile/styles.ts +63 -2
- package/src/compile/types.ts +31 -3
- package/src/compile/view-check.ts +284 -0
- package/src/data/amount-breakdown.ts +8 -3
- package/src/data/anchor-nav.ts +2 -2
- package/src/data/approval-flow.ts +3 -3
- package/src/data/assignment-picker.ts +92 -55
- package/src/data/async-result-panel.ts +111 -9
- package/src/data/breadcrumbs.ts +5 -4
- package/src/data/calendar.ts +24 -27
- package/src/data/carousel.ts +13 -8
- package/src/data/chart.ts +183 -44
- package/src/data/checklist.ts +20 -7
- package/src/data/code-view.ts +12 -6
- package/src/data/comment-thread.ts +7 -4
- package/src/data/confirm-dialog.ts +81 -18
- package/src/data/context-menu.ts +29 -37
- package/src/data/d9-util.ts +2 -18
- package/src/data/diff.ts +4 -2
- package/src/data/dock.ts +3 -3
- package/src/data/embed.ts +233 -30
- package/src/data/field-mapper.ts +35 -30
- package/src/data/flow-editor-contract.ts +8 -1
- package/src/data/flow-editor.ts +113 -108
- package/src/data/flow-node-options.ts +120 -0
- package/src/data/flow-remote-options.ts +0 -103
- package/src/data/footer.ts +2 -2
- package/src/data/form-draft-registry.ts +2 -4
- package/src/data/gantt.ts +19 -19
- package/src/data/hero.ts +4 -3
- package/src/data/image-viewer.ts +27 -30
- package/src/data/index.ts +5 -2
- package/src/data/item-list.ts +48 -31
- package/src/data/kanban.ts +82 -52
- package/src/data/media-grid.ts +20 -20
- package/src/data/mega-menu.ts +6 -4
- package/src/data/menu-dom.ts +4 -2
- package/src/data/menu.ts +47 -15
- package/src/data/mockup.ts +10 -6
- package/src/data/modal-dialog.ts +49 -25
- package/src/data/navbar.ts +12 -7
- package/src/data/notice-list.ts +268 -0
- package/src/data/notify-renderer.ts +250 -0
- package/src/data/object-form.ts +1360 -666
- package/src/data/outcome-watch.ts +61 -2
- package/src/data/pager.ts +80 -34
- package/src/data/permission-matrix.ts +52 -31
- package/src/data/permission-tree.ts +71 -44
- package/src/data/pricing-table.ts +30 -14
- package/src/data/prompt-dialog.ts +124 -194
- package/src/data/reaction-bar.ts +83 -92
- package/src/data/read-rollback.ts +73 -0
- package/src/data/record-card.ts +26 -5
- package/src/data/record-picker.ts +104 -55
- package/src/data/redirect.ts +32 -32
- package/src/data/remote-options.ts +13 -6
- package/src/data/request-console.ts +5 -3
- package/src/data/resident.ts +2 -1
- package/src/data/result-panel.ts +8 -4
- package/src/data/rich-text.ts +61 -55
- package/src/data/row-editor.ts +362 -76
- package/src/data/rule-builder.ts +26 -20
- package/src/data/shape-util.ts +27 -9
- package/src/data/stat-group.ts +392 -109
- package/src/data/static-lazy.ts +1 -0
- package/src/data/static-registry.ts +24 -11
- package/src/data/steps.ts +10 -5
- package/src/data/survey.ts +27 -32
- package/src/data/system-switcher.ts +3 -3
- package/src/data/text-action-button.ts +17 -0
- package/src/data/timeline.ts +19 -8
- package/src/data/tour-guide.ts +23 -30
- package/src/data/transfer.ts +62 -38
- package/src/data/tree-table.ts +152 -78
- package/src/data/tree.ts +49 -36
- package/src/data/trend-line.ts +6 -24
- package/src/data/virtual-rows.ts +133 -82
- package/src/data/watermark.ts +2 -2
- package/src/data/wrap.ts +63 -38
- package/src/data/wrapped-candidates.ts +10 -0
- package/src/frames/blank-frame.ts +1 -0
- package/src/frames/index.ts +2 -2
- package/src/frames/page-bar.ts +26 -24
- package/src/frames/page-header.ts +14 -5
- package/src/frames/page-status.ts +9 -7
- package/src/frames/shared.ts +36 -25
- package/src/frames/single-frame.ts +1 -0
- package/src/frames/split-frame/shell.ts +6 -6
- package/src/frames/split-frame/wiring.ts +2 -2
- package/src/frames/tabs-frame/shell.ts +4 -14
- package/src/frames/tabs-frame/wiring.ts +5 -8
- package/src/frames/top-main-frame.ts +3 -2
- package/src/frames/types.ts +13 -2
- package/src/frames/workspace-frame/extras.ts +21 -5
- package/src/frames/workspace-frame/index.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +3 -2
- package/src/frames/workspace-frame/state.ts +13 -6
- package/src/frames/workspace-frame/view.ts +250 -48
- package/src/generated/kit-grammar-runtime.ts +645 -397
- package/src/generated/page-origin.ts +0 -11
- package/src/i18n/kit-text.ts +84 -29
- package/src/i18n/resolve-text-refs.ts +22 -6
- package/src/index.ts +2 -1
- package/src/object-renderer/action-gate.ts +11 -147
- package/src/object-renderer/arrange.ts +112 -84
- package/src/object-renderer/collapse-wiring.ts +2 -2
- package/src/object-renderer/collection-expand.ts +2 -2
- package/src/object-renderer/collection-parts.ts +401 -104
- package/src/object-renderer/collection-table.ts +287 -45
- package/src/object-renderer/collection.ts +258 -104
- package/src/object-renderer/compile-data.ts +112 -102
- package/src/object-renderer/crud-bridge.ts +32 -0
- package/src/object-renderer/defaults.ts +38 -16
- package/src/object-renderer/display-checks.ts +4 -25
- package/src/object-renderer/emit-events.ts +224 -176
- package/src/object-renderer/emit-object.ts +15 -2
- package/src/object-renderer/emit-static.ts +533 -151
- package/src/object-renderer/field-value.ts +593 -396
- package/src/object-renderer/filter-reload.ts +70 -0
- package/src/object-renderer/form-detail.ts +111 -2
- package/src/object-renderer/form-notify.ts +45 -0
- package/src/object-renderer/index.ts +26 -0
- package/src/object-renderer/key-field.ts +12 -0
- package/src/object-renderer/layout-facts.ts +386 -0
- package/src/object-renderer/layout-plan.ts +132 -0
- package/src/object-renderer/layout-plan.types.ts +22 -0
- package/src/object-renderer/linkage.ts +7 -270
- package/src/object-renderer/merge-class.ts +18 -1
- package/src/object-renderer/parts.ts +252 -1
- package/src/object-renderer/path-pick.ts +27 -0
- package/src/object-renderer/render-object.ts +456 -89
- package/src/object-renderer/request-actions.ts +232 -249
- package/src/object-renderer/skeleton.ts +58 -19
- package/src/object-renderer/table-actions.ts +319 -111
- package/src/object-renderer/table-summary.ts +2 -2
- package/src/object-renderer/table-tools.ts +429 -94
- package/src/object-renderer/types.ts +204 -127
- package/src/object-renderer/view-binding.ts +393 -0
- package/src/page-target/ai-surface.ts +37 -0
- package/src/page-target/compile.ts +48 -8
- package/src/page-target/index.ts +8 -1
- package/src/page-target/intent-schema.ts +165 -28
- package/src/page-target/target.ts +262 -51
- package/src/page-target/writer-policy.ts +14 -3
- package/src/recipes/container.ts +210 -0
- package/src/recipes/control.ts +277 -0
- package/src/recipes/index.ts +312 -0
- package/src/recipes/nowrap.ts +16 -0
- package/src/recipes/overlay.ts +240 -0
- package/src/recipes/placeholder.ts +79 -0
- package/src/recipes/rail-grid.ts +45 -0
- package/src/recipes/slot-align.ts +56 -0
- package/src/recipes/state.ts +99 -0
- package/src/recipes/status.ts +139 -0
- package/src/recipes/surface.ts +40 -0
- package/src/recipes/table-row.ts +88 -0
- package/src/recipes/title-row.ts +37 -0
- package/src/recipes/typography.ts +99 -0
- package/src/shared/action-field-guard.ts +41 -0
- package/src/shared/confirm-decl.ts +118 -0
- package/src/shared/envelope.ts +207 -0
- package/src/shared/escape.ts +57 -0
- package/src/shared/kit-error.ts +21 -0
- package/src/shared/paged-list-adapter.ts +15 -0
- package/src/shared/path-guard.ts +127 -0
- package/src/shared/theme-runtime-shared.ts +180 -0
- package/src/shared/view-info.ts +10 -0
- package/src/theme/index.ts +13 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +407 -10
- package/src/theme/kit-theme.tpl +407 -10
- package/src/theme/nine-dim-structure.ts +247 -0
- package/src/theme/surface-layers.ts +101 -0
- package/src/theme/theme-tokens.ts +130 -84
- package/src/theme/theme-types.ts +103 -0
- package/src/theme/typography.ts +17 -17
- package/src/biz/shared/step-values.ts +0 -25
- package/src/biz/step-form/steps-ref.ts +0 -112
- package/src/data/options-bus.ts +0 -24
- package/src/object-renderer/adopt-gate.ts +0 -333
- package/src/object-renderer/field-policy.ts +0 -89
- package/src/object-renderer/outcome-draft.ts +0 -61
- package/src/theme/nine-dim-palettes.ts +0 -1473
|
@@ -8,30 +8,20 @@
|
|
|
8
8
|
// 写入结果(pending / saved / failed、响应体、失败文案)落 core 的 write-outcome-store,组件用 `outcome` prop 订阅。
|
|
9
9
|
// 下载没有 core 端口:GET 用链接、POST 用表单提交到隐藏窗体,都是浏览器原生下载,不经 fetch。
|
|
10
10
|
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
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 {
|
|
18
|
-
import type { KitAction, KitDiagnostic, KitDownloadDecl, KitRequestDecl
|
|
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
|
-
/**
|
|
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
|
-
|
|
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
|
|
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
|
-
/**
|
|
160
|
-
|
|
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
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
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
|
|
313
|
-
|
|
314
|
-
|
|
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
|
-
|
|
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?,
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
436
|
-
|
|
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?,
|
|
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
|
-
|
|
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
|
-
|
|
475
|
-
|
|
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,117 @@ 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
|
-
|
|
451
|
+
const onlyKeys = [
|
|
452
|
+
...(spec.pick ?? []),
|
|
453
|
+
...(spec.bodyMap ? Object.keys(spec.bodyMap) : []),
|
|
454
|
+
];
|
|
455
|
+
const uniqueOnly = [...new Set(onlyKeys)];
|
|
456
|
+
// 只用来圈定请求体可出现的键(write.only):不声明 type —— 值可能是数组(ids)、数字(version)或对象,
|
|
457
|
+
// 写类型会让 core 按类型规整(且 core 字段类型闭集里没有 string,旧写法整页注入失败 CORE-INJECT-PAGE-CLOSURE)
|
|
458
|
+
const fields: Record<string, { name: string }> = {};
|
|
459
|
+
for (const k of uniqueOnly) {
|
|
460
|
+
fields[k] = { name: k };
|
|
461
|
+
}
|
|
462
|
+
out[spec.writeObject] = {
|
|
463
|
+
fields,
|
|
464
|
+
write: {
|
|
465
|
+
[channel]: { api: spec.api, method: spec.method },
|
|
466
|
+
...(uniqueOnly.length > 0 ? { only: uniqueOnly } : {}),
|
|
467
|
+
...(spec.timeoutMs !== undefined ? { timeoutMs: spec.timeoutMs } : {}),
|
|
468
|
+
},
|
|
469
|
+
};
|
|
579
470
|
}
|
|
580
471
|
return out;
|
|
581
472
|
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* 按 request.pick 与 request.bodyMap 从源数据(row / draft / focus / values)构造请求体 model:
|
|
476
|
+
* - 若声明了 pick: ['id', 'status'],从源对象提取对应同名字段;
|
|
477
|
+
* - 若声明了 bodyMap: { orderId: 'id', orderNo: 'row.code' },读取源字段(去 row. 前缀)并写入目标键名(payload.orderId = src.id)。
|
|
478
|
+
*/
|
|
479
|
+
export function buildRequestPayload(
|
|
480
|
+
spec: Pick<KitRequestSpec, 'pick' | 'bodyMap'>,
|
|
481
|
+
sources: Readonly<Record<string, unknown>> | ReadonlyArray<Readonly<Record<string, unknown>> | undefined>,
|
|
482
|
+
): Record<string, unknown> {
|
|
483
|
+
const list: ReadonlyArray<Readonly<Record<string, unknown>>> = Array.isArray(sources)
|
|
484
|
+
? sources.filter((s): s is Readonly<Record<string, unknown>> => isRec(s))
|
|
485
|
+
: isRec(sources)
|
|
486
|
+
? [sources]
|
|
487
|
+
: [];
|
|
488
|
+
const readField = (rawField: string): unknown => {
|
|
489
|
+
const field = rawField.startsWith('row.') ? rawField.slice(4) : rawField;
|
|
490
|
+
for (const src of list) {
|
|
491
|
+
if (field in src && src[field] !== undefined) return src[field];
|
|
492
|
+
if (isRec(src.row) && field in src.row && src.row[field] !== undefined) return src.row[field];
|
|
493
|
+
if (isRec(src.record) && field in src.record && src.record[field] !== undefined) return src.record[field];
|
|
494
|
+
if (isRec(src.values) && field in src.values && src.values[field] !== undefined) return src.values[field];
|
|
495
|
+
}
|
|
496
|
+
return undefined;
|
|
497
|
+
};
|
|
498
|
+
const out: Record<string, unknown> = {};
|
|
499
|
+
if (Array.isArray(spec.pick)) {
|
|
500
|
+
for (const rawKey of spec.pick) {
|
|
501
|
+
const key = rawKey.startsWith('row.') ? rawKey.slice(4) : rawKey;
|
|
502
|
+
const val = readField(key);
|
|
503
|
+
if (val !== undefined) out[key] = val;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
if (isRec(spec.bodyMap)) {
|
|
507
|
+
for (const [targetKey, sourceRaw] of Object.entries(spec.bodyMap)) {
|
|
508
|
+
if (typeof sourceRaw !== 'string') continue;
|
|
509
|
+
const val = readField(sourceRaw);
|
|
510
|
+
if (val !== undefined) out[targetKey] = val;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
return out;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* 针对单对象源数据的请求体映射:按 pick 筛选,按 bodyMap 重命名源字段;
|
|
518
|
+
* 若字段在 bodyMap 中被映射,则优先输出映射后的 targetKey,避免重复输出原始键。
|
|
519
|
+
*/
|
|
520
|
+
export function applyRequestPayloadMapping(
|
|
521
|
+
source: Record<string, unknown>,
|
|
522
|
+
mapping: { pick?: readonly string[]; bodyMap?: Readonly<Record<string, string>> },
|
|
523
|
+
): Record<string, unknown> {
|
|
524
|
+
const readField = (rawField: string): unknown => {
|
|
525
|
+
const field = rawField.startsWith("row.") ? rawField.slice(4) : rawField;
|
|
526
|
+
if (source && typeof source === "object") {
|
|
527
|
+
if (field in source && source[field] !== undefined) return source[field];
|
|
528
|
+
const s = source;
|
|
529
|
+
if (isRec(s.row) && field in s.row && s.row[field] !== undefined) return s.row[field];
|
|
530
|
+
if (isRec(s.record) && field in s.record && s.record[field] !== undefined) return s.record[field];
|
|
531
|
+
if (isRec(s.values) && field in s.values && s.values[field] !== undefined) return s.values[field];
|
|
532
|
+
}
|
|
533
|
+
return undefined;
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
const bodyMap = mapping.bodyMap;
|
|
537
|
+
const pick = mapping.pick;
|
|
538
|
+
const out: Record<string, unknown> = {};
|
|
539
|
+
const mappedSourceKeys = new Set<string>();
|
|
540
|
+
|
|
541
|
+
if (isRec(bodyMap)) {
|
|
542
|
+
for (const [targetKey, sourceRaw] of Object.entries(bodyMap)) {
|
|
543
|
+
if (typeof sourceRaw !== "string") continue;
|
|
544
|
+
const cleanSource = sourceRaw.startsWith("row.") ? sourceRaw.slice(4) : sourceRaw;
|
|
545
|
+
mappedSourceKeys.add(cleanSource);
|
|
546
|
+
const val = readField(sourceRaw);
|
|
547
|
+
if (val !== undefined) out[targetKey] = val;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
if (Array.isArray(pick)) {
|
|
552
|
+
for (const rawKey of pick) {
|
|
553
|
+
const key = rawKey.startsWith("row.") ? rawKey.slice(4) : rawKey;
|
|
554
|
+
if (!mappedSourceKeys.has(key)) {
|
|
555
|
+
const val = readField(key);
|
|
556
|
+
if (val !== undefined) out[key] = val;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
} else if (!isRec(bodyMap) || Object.keys(bodyMap).length === 0) {
|
|
560
|
+
return { ...source };
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
return out;
|
|
564
|
+
}
|