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.
- package/README.md +103 -110
- package/bin/soma-kit.mjs +1 -1
- package/bin/soma.mjs +22 -0
- package/package.json +13 -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 +776 -38
- package/spec/generated/kit-page.schema.json +1613 -224
- package/spec/kit-grammar.json +770 -529
- package/spec/kit-grammar.schema.json +1962 -392
- package/src/app/app-config.ts +371 -347
- package/src/app/component-gate.ts +12 -15
- package/src/app/compose-apps.ts +79 -8
- package/src/app/define-kit-actions.ts +245 -41
- package/src/app/define-kit-app.ts +174 -31
- package/src/app/define-kit-view.ts +100 -0
- package/src/app/envelope.ts +1 -161
- package/src/app/index.ts +13 -2
- package/src/app/kit-view-context.ts +290 -0
- package/src/app/notify-renderer.ts +1 -115
- package/src/app/paged-list-adapter.ts +1 -240
- package/src/app/server-pages.ts +8 -2
- package/src/app/server.ts +491 -101
- 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 +663 -0
- package/src/base/action-busy.ts +2 -2
- package/src/base/action-gate.ts +4 -255
- package/src/base/action-slots.ts +47 -0
- package/src/base/alert.ts +5 -3
- package/src/base/avatar.ts +2 -2
- package/src/base/button.ts +46 -29
- package/src/base/cascader.ts +11 -12
- package/src/base/check-core.ts +1 -1
- package/src/base/choice.ts +28 -26
- package/src/base/class-candidates.ts +17 -0
- package/src/base/color-picker.ts +6 -6
- package/src/base/combobox.ts +5 -3
- package/src/base/command-palette.ts +9 -5
- package/src/base/countdown.ts +1 -1
- package/src/base/date-range.ts +25 -11
- package/src/base/date.ts +85 -17
- package/src/base/divider.ts +2 -2
- package/src/base/fab.ts +11 -4
- package/src/base/image.ts +1 -1
- package/src/base/index.ts +9 -3
- 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 +50 -30
- package/src/base/loading-gate.ts +133 -0
- package/src/base/mentions.ts +5 -5
- package/src/base/menu-button.ts +6 -1
- package/src/base/menu-core.ts +4 -0
- package/src/base/motion/aura.ts +2 -2
- package/src/base/motion/hover-3d.ts +2 -2
- package/src/base/motion/hover-gallery.ts +2 -2
- package/src/base/motion/marquee.ts +2 -2
- package/src/base/motion/text-rotate.ts +2 -2
- package/src/base/number.ts +93 -80
- package/src/base/otp.ts +4 -1
- package/src/base/permission-gate.ts +6 -0
- package/src/base/popover.ts +40 -8
- package/src/base/popup.ts +79 -14
- 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 +9 -3
- package/src/base/range.ts +2 -2
- package/src/base/rating.ts +1 -1
- package/src/base/segmented.ts +4 -0
- package/src/base/select.ts +4 -3
- package/src/base/shared.ts +221 -29
- package/src/base/swap.ts +4 -1
- package/src/base/switch.ts +1 -1
- package/src/base/tag-input.ts +14 -10
- package/src/base/tag.ts +5 -1
- package/src/base/text.ts +39 -6
- package/src/base/textarea.ts +37 -11
- package/src/base/time-picker.ts +12 -9
- package/src/base/tree-select.ts +15 -8
- package/src/base/upload.ts +34 -5
- package/src/base/virtual-list.ts +107 -1
- package/src/biz/approval-desk/compile.ts +23 -41
- package/src/biz/auth-panel/compile.ts +37 -52
- package/src/biz/auth-panel/index.ts +1 -1
- package/src/biz/category-crud/compile.ts +22 -36
- package/src/biz/checkout-page/compile.ts +21 -5
- 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 +3 -3
- package/src/biz/index.ts +3 -3
- package/src/biz/landing-page/compile.ts +19 -3
- package/src/biz/link/hub.ts +49 -20
- package/src/biz/link/shared.ts +115 -118
- package/src/biz/master-sub/compile.ts +31 -44
- package/src/biz/multi-board/compile.ts +34 -49
- package/src/biz/multi-board/index.ts +18 -1
- package/src/biz/multi-board/shell.ts +24 -15
- package/src/biz/notification-center/compile.ts +21 -33
- 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/shared.ts +34 -36
- package/src/biz/record-detail/compile.ts +47 -42
- package/src/biz/record-detail/index.ts +11 -1
- package/src/biz/settings-center/compile.ts +6 -5
- package/src/biz/shared/action-host.ts +91 -211
- package/src/biz/shared/compile-helpers.ts +80 -0
- package/src/biz/shared/coordinator.ts +486 -83
- package/src/biz/shared/index.ts +8 -2
- package/src/biz/shared/overlay-shell.ts +80 -0
- package/src/biz/shared/pipes.ts +43 -30
- package/src/biz/shared/remove-key.ts +6 -0
- package/src/biz/shared/remove-wire.ts +29 -0
- package/src/biz/shared/runtime-hub.ts +216 -24
- package/src/biz/single-form/compile.ts +15 -37
- package/src/biz/standard-crud/compile.ts +62 -107
- package/src/biz/standard-crud/shell.ts +16 -66
- package/src/biz/step-form/compile.ts +26 -97
- package/src/biz/step-form/hub.ts +34 -41
- package/src/biz/types.ts +4 -3
- package/src/cli/core-imports.ts +54 -0
- package/src/cli/kit-cli.ts +130 -26
- package/src/cli/kit-init.ts +222 -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 +752 -0
- package/src/compile/action-host-attach.ts +21 -29
- package/src/compile/closed-set.ts +509 -0
- package/src/compile/compile-page.ts +219 -72
- package/src/compile/component-candidates.ts +1 -1
- 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/locate.ts +21 -1
- package/src/compile/parse.ts +370 -41
- package/src/compile/redirect.ts +6 -2
- package/src/compile/styles.ts +35 -2
- package/src/compile/types.ts +18 -2
- package/src/compile/view-check.ts +151 -0
- package/src/data/amount-breakdown.ts +2 -2
- package/src/data/anchor-nav.ts +2 -2
- package/src/data/approval-flow.ts +2 -2
- package/src/data/assignment-picker.ts +40 -29
- package/src/data/async-result-panel.ts +62 -6
- package/src/data/breadcrumbs.ts +2 -2
- package/src/data/calendar.ts +22 -25
- package/src/data/carousel.ts +5 -2
- package/src/data/chart.ts +42 -34
- package/src/data/checklist.ts +2 -2
- package/src/data/code-view.ts +4 -2
- package/src/data/comment-thread.ts +5 -2
- package/src/data/confirm-dialog.ts +10 -0
- 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 +2 -2
- package/src/data/embed.ts +2 -1
- package/src/data/field-mapper.ts +31 -26
- package/src/data/flow-editor-contract.ts +1 -1
- package/src/data/flow-editor.ts +89 -100
- package/src/data/flow-node-options.ts +90 -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 +14 -17
- package/src/data/hero.ts +2 -2
- package/src/data/image-viewer.ts +20 -26
- package/src/data/index.ts +0 -2
- package/src/data/item-list.ts +31 -22
- package/src/data/kanban.ts +43 -42
- package/src/data/media-grid.ts +14 -19
- package/src/data/menu.ts +2 -2
- package/src/data/mockup.ts +2 -2
- package/src/data/modal-dialog.ts +22 -18
- package/src/data/navbar.ts +7 -2
- package/src/data/notify-renderer.ts +235 -0
- package/src/data/object-form.ts +1036 -648
- package/src/data/pager.ts +65 -29
- package/src/data/permission-matrix.ts +20 -21
- package/src/data/permission-tree.ts +28 -26
- package/src/data/pricing-table.ts +9 -3
- package/src/data/reaction-bar.ts +77 -88
- package/src/data/read-rollback.ts +73 -0
- package/src/data/record-card.ts +3 -3
- package/src/data/record-picker.ts +93 -50
- 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 +4 -2
- package/src/data/rich-text.ts +45 -55
- package/src/data/row-editor.ts +285 -52
- package/src/data/rule-builder.ts +18 -12
- package/src/data/shape-util.ts +4 -0
- package/src/data/stat-group.ts +243 -101
- package/src/data/static-registry.ts +22 -11
- package/src/data/steps.ts +2 -2
- package/src/data/survey.ts +24 -29
- package/src/data/system-switcher.ts +2 -2
- package/src/data/timeline.ts +2 -2
- package/src/data/tour-guide.ts +22 -29
- package/src/data/transfer.ts +27 -23
- package/src/data/tree-table.ts +96 -48
- package/src/data/tree.ts +27 -34
- package/src/data/trend-line.ts +6 -24
- package/src/data/virtual-rows.ts +118 -76
- package/src/data/watermark.ts +2 -2
- package/src/data/wrap.ts +63 -38
- package/src/frames/blank-frame.ts +1 -0
- package/src/frames/index.ts +2 -2
- package/src/frames/page-bar.ts +12 -11
- package/src/frames/page-header.ts +14 -5
- package/src/frames/page-status.ts +2 -2
- package/src/frames/shared.ts +23 -17
- package/src/frames/single-frame.ts +1 -0
- package/src/frames/split-frame/shell.ts +5 -5
- package/src/frames/split-frame/wiring.ts +2 -2
- package/src/frames/tabs-frame/shell.ts +2 -13
- package/src/frames/tabs-frame/wiring.ts +4 -8
- package/src/frames/top-main-frame.ts +1 -0
- package/src/frames/types.ts +13 -2
- package/src/frames/workspace-frame/extras.ts +20 -4
- package/src/frames/workspace-frame/index.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +1 -0
- package/src/frames/workspace-frame/state.ts +13 -6
- package/src/frames/workspace-frame/view.ts +119 -25
- package/src/generated/kit-grammar-runtime.ts +430 -366
- package/src/generated/page-origin.ts +0 -11
- package/src/i18n/kit-text.ts +23 -27
- package/src/index.ts +2 -1
- package/src/object-renderer/action-gate.ts +11 -147
- package/src/object-renderer/arrange.ts +71 -77
- 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 +216 -100
- package/src/object-renderer/collection-table.ts +180 -42
- package/src/object-renderer/collection.ts +95 -79
- package/src/object-renderer/compile-data.ts +85 -100
- package/src/object-renderer/crud-bridge.ts +32 -0
- package/src/object-renderer/defaults.ts +8 -14
- package/src/object-renderer/display-checks.ts +3 -24
- package/src/object-renderer/emit-events.ts +186 -172
- package/src/object-renderer/emit-object.ts +15 -2
- package/src/object-renderer/emit-static.ts +174 -132
- 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 +112 -2
- package/src/object-renderer/index.ts +26 -0
- package/src/object-renderer/key-field.ts +12 -0
- package/src/object-renderer/linkage.ts +7 -270
- package/src/object-renderer/merge-class.ts +18 -1
- package/src/object-renderer/path-pick.ts +27 -0
- package/src/object-renderer/render-object.ts +405 -86
- package/src/object-renderer/request-actions.ts +230 -249
- package/src/object-renderer/table-actions.ts +195 -95
- package/src/object-renderer/table-summary.ts +2 -2
- package/src/object-renderer/table-tools.ts +418 -84
- package/src/object-renderer/types.ts +128 -122
- package/src/object-renderer/view-binding.ts +196 -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 +154 -28
- package/src/page-target/target.ts +257 -50
- package/src/page-target/writer-policy.ts +14 -3
- package/src/recipes/container.ts +165 -0
- package/src/recipes/control.ts +219 -0
- package/src/recipes/index.ts +263 -0
- package/src/recipes/overlay.ts +182 -0
- package/src/recipes/state.ts +70 -0
- package/src/recipes/table-row.ts +51 -0
- package/src/recipes/typography.ts +87 -0
- package/src/shared/action-field-guard.ts +41 -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 +240 -0
- package/src/shared/path-guard.ts +127 -0
- package/src/shared/theme-runtime-shared.ts +175 -0
- package/src/shared/view-info.ts +10 -0
- package/src/theme/index.ts +12 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +38 -1
- package/src/theme/kit-theme.tpl +38 -1
- package/src/theme/nine-dim-structure.ts +77 -0
- package/src/theme/surface-layers.ts +97 -0
- package/src/theme/theme-tokens.ts +85 -79
- package/src/theme/theme-types.ts +71 -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/data/prompt-dialog.ts +0 -235
- 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 -1278
|
@@ -1,240 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//
|
|
3
|
-
// kit 列表对象以 `GET ?pageNo=&pageSize=&<筛选字段>=…` 读数据(参数名可由 behavior.list 的 pageParam / sizeParam 改;
|
|
4
|
-
// 筛选字段名就是 schema 字段名,空值不带),期望响应 `{ rows, total }`(缺省 listShape)。旧后台常见三种不一样:
|
|
5
|
-
// 1 后端页码键叫 page / pageNum,页长叫 size / limit,筛选参数名与字段名不同 -> createPagedListAdapter 的 upstream* 与 filterMap;
|
|
6
|
-
// 2 响应是业务信封(失败判定 / 数据位置由 kit.app.yaml 的 envelope 声明),列表键与总数键不统一 -> unwrapBizEnvelope + 适配器的 rowsPath / totalPaths;
|
|
7
|
-
// 3 游标分页(cursor / limit / nextCursor),没有页码 -> cursorPageWindow(沿游标走到第 N 页)。
|
|
8
|
-
// 这里只做形状翻译,不碰业务、不发请求(请求由调用方的 load 函数发)。数字(缺省页长 / 页长上限 / 信封嵌套层数)读 design 的 kit-limits。
|
|
9
|
-
|
|
10
|
-
import { KIT_DATA_LIMITS } from 'soma-foundation/kit-limits';
|
|
11
|
-
import { getKitAppEnvelope, isEnvelopeFailure, unwrapEnvelope, type KitEnvelope, type UnwrappedEnvelope } from './envelope';
|
|
12
|
-
|
|
13
|
-
type Rec = Record<string, unknown>;
|
|
14
|
-
const LIMITS = (KIT_DATA_LIMITS as unknown as { pagedList: { pageSizeDefault: number; pageSizeMax: number; unwrapDepth: number } }).pagedList;
|
|
15
|
-
|
|
16
|
-
const isRec = (v: unknown): v is Rec => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
17
|
-
|
|
18
|
-
/** kit 列表请求里唯一的页码键与页长键;其余键都当筛选(外部后端的参数名由 upstreamPage / upstreamSize 显式配置) */
|
|
19
|
-
const KIT_PAGE_KEY = 'pageNo';
|
|
20
|
-
const KIT_SIZE_KEY = 'pageSize';
|
|
21
|
-
const RESERVED: ReadonlySet<string> = new Set([KIT_PAGE_KEY, KIT_SIZE_KEY, 'window', 'sort', 'order']);
|
|
22
|
-
const DEFAULT_ROW_KEYS: readonly string[] = ['list', 'records', 'rows', 'items', 'data'];
|
|
23
|
-
const DEFAULT_TOTAL_PATHS: readonly string[] = ['totalCount', 'total', 'count'];
|
|
24
|
-
|
|
25
|
-
function positiveInt(raw: unknown): number | null {
|
|
26
|
-
const n = typeof raw === 'number' ? raw : typeof raw === 'string' && raw.trim() !== '' ? Number(raw) : Number.NaN;
|
|
27
|
-
return Number.isInteger(n) && n > 0 ? n : null;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function pathGet(root: unknown, path: string): unknown {
|
|
31
|
-
let cur = root;
|
|
32
|
-
for (const key of path.split('.')) {
|
|
33
|
-
if (!isRec(cur)) return undefined;
|
|
34
|
-
cur = cur[key];
|
|
35
|
-
}
|
|
36
|
-
return cur;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// ---------------------------------------------------------------- 业务信封
|
|
40
|
-
|
|
41
|
-
export type { UnwrappedEnvelope };
|
|
42
|
-
|
|
43
|
-
/** 响应是业务错误信封:命中应用声明的 failWhen(kit.app.yaml 的 envelope;不显式传 env 时取装配登记的应用级信封) */
|
|
44
|
-
export function isBizFailure(raw: unknown, env: KitEnvelope | undefined = getKitAppEnvelope()): raw is Rec {
|
|
45
|
-
return isEnvelopeFailure(raw, env);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* 拆业务信封:失败信封原样放进 `error`(调用方应把它直接回给浏览器,不要再包成成功的列表);
|
|
50
|
-
* 成功则按 envelope.dataPath 取数据(没声明不拆)。写死的 success / ret / data 约定已删,全部来自声明。
|
|
51
|
-
*/
|
|
52
|
-
export function unwrapBizEnvelope(raw: unknown, env: KitEnvelope | undefined = getKitAppEnvelope()): UnwrappedEnvelope {
|
|
53
|
-
return unwrapEnvelope(raw, env);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// ---------------------------------------------------------------- 页码协议适配器
|
|
57
|
-
|
|
58
|
-
export interface PagedListAdapterOptions {
|
|
59
|
-
/** 上游页码参数名(缺省 page) */
|
|
60
|
-
upstreamPage?: string;
|
|
61
|
-
/** 上游页长参数名(缺省 pageSize) */
|
|
62
|
-
upstreamSize?: string;
|
|
63
|
-
/** 响应里行数组的位置:点路径(相对拆信封后的 data),或候选键列表(取第一个数组);缺省 list / records / rows / items / data */
|
|
64
|
-
rowsPath?: string | readonly string[];
|
|
65
|
-
/** 总数的候选位置(相对拆信封后的 data);缺省 totalCount / total / count */
|
|
66
|
-
totalPaths?: readonly string[];
|
|
67
|
-
/** 筛选参数:kit 字段名 -> 上游参数名;数组 = 同名透传的白名单;缺省收全部非保留参数同名透传 */
|
|
68
|
-
filterMap?: Readonly<Record<string, string>> | readonly string[];
|
|
69
|
-
/** 给行补主键 id:依次取这些键里第一个非空值(已有非空 id 不动) */
|
|
70
|
-
rowId?: string | readonly string[];
|
|
71
|
-
/** 缺省页长 / 页长上限(缺省读 kit-limits) */
|
|
72
|
-
defaultPageSize?: number;
|
|
73
|
-
maxPageSize?: number;
|
|
74
|
-
/** 业务信封约定;缺省取 kit.app.yaml 的 envelope(装配登记的应用级信封) */
|
|
75
|
-
envelope?: KitEnvelope;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export interface PagedQuery {
|
|
79
|
-
/** 从 1 起 */
|
|
80
|
-
page: number;
|
|
81
|
-
pageSize: number;
|
|
82
|
-
/** kit 字段名 -> 值(已去空白,空值不进) */
|
|
83
|
-
filters: Record<string, string>;
|
|
84
|
-
/** 可直接拼到上游请求的参数:页码、页长、已改名的筛选 */
|
|
85
|
-
upstream: Record<string, string | number>;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export interface PagedList {
|
|
89
|
-
rows: Rec[];
|
|
90
|
-
total: number;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export interface PagedListAdapter {
|
|
94
|
-
/** 请求里没有页码键 = 旧调用方(调用方可据此原样转交旧服务) */
|
|
95
|
-
hasPage(input: unknown): boolean;
|
|
96
|
-
readQuery(input: unknown): PagedQuery;
|
|
97
|
-
/** 上游响应 -> kit 列表;失败信封返回 { error } */
|
|
98
|
-
toList(raw: unknown, mapRow?: (row: Rec, index: number) => Rec): PagedList | { error: Rec };
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function entriesOf(input: unknown): Array<[string, unknown]> {
|
|
102
|
-
if (input instanceof URLSearchParams) return [...input.entries()];
|
|
103
|
-
if (typeof input === 'string') return [...new URLSearchParams(input.includes('?') ? input.slice(input.indexOf('?') + 1) : input).entries()];
|
|
104
|
-
if (isRec(input)) return Object.entries(input);
|
|
105
|
-
return [];
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function rowsOf(data: unknown, rowsPath: string | readonly string[] | undefined): Rec[] {
|
|
109
|
-
let list: unknown;
|
|
110
|
-
if (Array.isArray(data)) list = data;
|
|
111
|
-
else if (typeof rowsPath === 'string') list = pathGet(data, rowsPath);
|
|
112
|
-
else list = (rowsPath ?? DEFAULT_ROW_KEYS).map((key) => (isRec(data) ? data[key] : undefined)).find(Array.isArray);
|
|
113
|
-
return Array.isArray(list) ? list.filter(isRec) : [];
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function totalOf(data: unknown, paths: readonly string[], fallback: number): number {
|
|
117
|
-
for (const path of paths) {
|
|
118
|
-
const v = pathGet(data, path);
|
|
119
|
-
if (typeof v === 'number' && Number.isFinite(v)) return v;
|
|
120
|
-
if (typeof v === 'string' && v.trim() !== '' && Number.isFinite(Number(v))) return Number(v);
|
|
121
|
-
}
|
|
122
|
-
return fallback;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/** 给行补主键:id 缺省时依次取 keys 里第一个非空值(字符串化),已有非空 id 不动 */
|
|
126
|
-
export function withRowId(row: Rec, keys: string | readonly string[]): Rec {
|
|
127
|
-
if (typeof row.id === 'string' && row.id !== '') return row;
|
|
128
|
-
if (typeof row.id === 'number') return { ...row, id: String(row.id) };
|
|
129
|
-
for (const key of typeof keys === 'string' ? [keys] : keys) {
|
|
130
|
-
const v = row[key];
|
|
131
|
-
if (typeof v === 'string' && v.trim() !== '') return { ...row, id: v.trim() };
|
|
132
|
-
if (typeof v === 'number') return { ...row, id: String(v) };
|
|
133
|
-
}
|
|
134
|
-
return { ...row, id: '' };
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export function createPagedListAdapter(options: PagedListAdapterOptions = {}): PagedListAdapter {
|
|
138
|
-
const upstreamPage = options.upstreamPage ?? 'page';
|
|
139
|
-
const upstreamSize = options.upstreamSize ?? 'pageSize';
|
|
140
|
-
const totalPaths = options.totalPaths ?? DEFAULT_TOTAL_PATHS;
|
|
141
|
-
const defaultSize = options.defaultPageSize ?? LIMITS.pageSizeDefault;
|
|
142
|
-
const maxSize = options.maxPageSize ?? LIMITS.pageSizeMax;
|
|
143
|
-
const filterMap = options.filterMap;
|
|
144
|
-
const filterName = (key: string): string | null => {
|
|
145
|
-
if (filterMap === undefined) return key;
|
|
146
|
-
if (Array.isArray(filterMap)) return filterMap.includes(key) ? key : null;
|
|
147
|
-
const mapped = (filterMap as Readonly<Record<string, string>>)[key];
|
|
148
|
-
return mapped === undefined ? null : mapped;
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
return {
|
|
152
|
-
hasPage(input) {
|
|
153
|
-
return entriesOf(input).some(([k, v]) => k === KIT_PAGE_KEY && positiveInt(v) !== null);
|
|
154
|
-
},
|
|
155
|
-
readQuery(input) {
|
|
156
|
-
const entries = entriesOf(input);
|
|
157
|
-
const pick = (key: string): number | null => {
|
|
158
|
-
const hit = entries.find(([k]) => k === key);
|
|
159
|
-
return hit === undefined ? null : positiveInt(hit[1]);
|
|
160
|
-
};
|
|
161
|
-
const page = pick(KIT_PAGE_KEY) ?? 1;
|
|
162
|
-
const pageSize = Math.min(pick(KIT_SIZE_KEY) ?? defaultSize, maxSize);
|
|
163
|
-
const filters: Record<string, string> = {};
|
|
164
|
-
const upstream: Record<string, string | number> = { [upstreamPage]: page, [upstreamSize]: pageSize };
|
|
165
|
-
for (const [key, value] of entries) {
|
|
166
|
-
if (RESERVED.has(key) || value === undefined || value === null) continue;
|
|
167
|
-
const text = String(value).trim();
|
|
168
|
-
const target = filterName(key);
|
|
169
|
-
if (text === '' || target === null) continue;
|
|
170
|
-
filters[key] = text;
|
|
171
|
-
upstream[target] = text;
|
|
172
|
-
}
|
|
173
|
-
return { page, pageSize, filters, upstream };
|
|
174
|
-
},
|
|
175
|
-
toList(raw, mapRow) {
|
|
176
|
-
const unwrapped = unwrapBizEnvelope(raw, options.envelope ?? getKitAppEnvelope());
|
|
177
|
-
if (!unwrapped.ok) return { error: unwrapped.error };
|
|
178
|
-
let rows = rowsOf(unwrapped.data, options.rowsPath);
|
|
179
|
-
if (options.rowId !== undefined) rows = rows.map((r) => withRowId(r, options.rowId!));
|
|
180
|
-
if (mapRow !== undefined) rows = rows.map(mapRow);
|
|
181
|
-
return { rows, total: totalOf(unwrapped.data, totalPaths, rows.length) };
|
|
182
|
-
},
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// ---------------------------------------------------------------- 游标分页
|
|
187
|
-
|
|
188
|
-
export type CursorLoader = (query: { cursor?: string; limit: number }) => Promise<unknown>;
|
|
189
|
-
|
|
190
|
-
export interface CursorPageOptions<T> {
|
|
191
|
-
load: CursorLoader;
|
|
192
|
-
/** 响应里行数组的键(缺省 rows) */
|
|
193
|
-
rowsKey?: string;
|
|
194
|
-
/** 响应里总数的键(缺省 total) */
|
|
195
|
-
totalKey?: string;
|
|
196
|
-
/** 响应里下一页游标的键(缺省 nextCursor) */
|
|
197
|
-
nextKey?: string;
|
|
198
|
-
parse?: (raw: unknown) => T;
|
|
199
|
-
/** 目标页(从 1 起)与页长 */
|
|
200
|
-
page: number;
|
|
201
|
-
pageSize: number;
|
|
202
|
-
/** 出错信息前缀(如「接口目录」) */
|
|
203
|
-
label: string;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
export interface CursorPageResult<T> {
|
|
207
|
-
rows: T[];
|
|
208
|
-
total: number;
|
|
209
|
-
/** 最后一次取到的原始响应(调用方要读其它字段,如 snapshotVersion);页号超过末页时是末页那次的响应 */
|
|
210
|
-
raw: Rec | null;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* 沿游标走到第 page 页,返回该页行与总数;页号超过末页返回空行(total 仍真实)。
|
|
215
|
-
* 响应结构非法(行不是数组、总数不是非负整数、行数超过页长)抛错,不静默截断;游标重复也抛错(防死循环)。
|
|
216
|
-
*/
|
|
217
|
-
export async function cursorPageWindow<T = unknown>(options: CursorPageOptions<T>): Promise<CursorPageResult<T>> {
|
|
218
|
-
const { load, page, pageSize, label } = options;
|
|
219
|
-
const rowsKey = options.rowsKey ?? 'rows';
|
|
220
|
-
const totalKey = options.totalKey ?? 'total';
|
|
221
|
-
const nextKey = options.nextKey ?? 'nextCursor';
|
|
222
|
-
const parse = options.parse ?? ((raw: unknown) => raw as T);
|
|
223
|
-
let cursor: string | undefined;
|
|
224
|
-
const seen = new Set<string>();
|
|
225
|
-
let total = 0;
|
|
226
|
-
for (let current = 1; current <= page; current += 1) {
|
|
227
|
-
const response = await load({ ...(cursor !== undefined ? { cursor } : {}), limit: pageSize });
|
|
228
|
-
if (!isRec(response)) throw new Error(`${label}分页响应结构非法`);
|
|
229
|
-
const result: Rec = response;
|
|
230
|
-
const raw = result[rowsKey];
|
|
231
|
-
total = Number(result[totalKey]);
|
|
232
|
-
if (!Array.isArray(raw) || !Number.isSafeInteger(total) || total < 0 || raw.length > pageSize) throw new Error(`${label}分页响应结构非法`);
|
|
233
|
-
if (current === page) return { rows: raw.map(parse), total, raw: result };
|
|
234
|
-
const next = typeof result[nextKey] === 'string' ? (result[nextKey] as string).trim() : '';
|
|
235
|
-
if (next === '' || next === cursor || seen.has(next)) return { rows: [], total, raw: result };
|
|
236
|
-
seen.add(next);
|
|
237
|
-
cursor = next;
|
|
238
|
-
}
|
|
239
|
-
return { rows: [], total, raw: null };
|
|
240
|
-
}
|
|
1
|
+
export * from '../shared/paged-list-adapter';
|
package/src/app/server-pages.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// 按 URL 提交(《soma-kit AI 页目标施工规格》§4.3):`pages.submit(地址, kit 源, 选项)` -> 本线闸门 -> 编译 -> 注入 core runtime 空间(owner `soma-kit`)。
|
|
2
|
-
// 与 soma-
|
|
2
|
+
// 与 soma-ui 共用 core 的提交步骤工具集(`soma-core/server/runtime` 的 checkSubmitOptions / decideSubmitAddress /
|
|
3
3
|
// precheckSubmitSlot / checkExpectedGeneration / stampSubmitEnvelope / buildRegisterRequest / registerPageOrReject /
|
|
4
4
|
// createProvenanceLedger / unbindOwnedPage / listPageBindings);方言自己只编排并保留与方言有关的步骤:
|
|
5
5
|
// ① 定址:submit 参数 × 源 `page.url`(占位值 KIT_PLACEHOLDER_URL 视为没写),对账由 core `decideSubmitAddress` 做;
|
|
@@ -51,7 +51,13 @@ export interface KitServerPagesDeps {
|
|
|
51
51
|
readonly now?: () => number;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* 方言源内容摘要:与 URL、授权、调用方无关(dryRun 与 submit 的 `digest` 同值)。
|
|
56
|
+
*
|
|
57
|
+
* 只作来源登记(`options.source.digest`)与结果回显,不是 core 的判重键:`registerPageOrReject` 判重看的 `version`
|
|
58
|
+
* 是 `buildRegisterRequest` 对编译后标准载荷(html / uiYaml / eventYaml / styles / envelope …)取的摘要,
|
|
59
|
+
* 所以应用上下文(主题、词条、组件表、信封约定)变了、编出的载荷随之变了,重新提交不会被判为未变;载荷逐字相同才判未变。
|
|
60
|
+
*/
|
|
55
61
|
export function kitSourceDigest(source: string): string {
|
|
56
62
|
return fnv1a64Hex(canonicalJson({ source }));
|
|
57
63
|
}
|