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
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
// `soma kit check` 的接口落点告警:页面里 from / write / 动作 request·download / options.from 指向的站内 /api/... 地址,
|
|
2
|
+
// 是否在应用的 api/service 下有对应服务文件、服务文件是否实现了该 HTTP 方法。输出是告警(不是诊断码、不影响退出码);宁可漏报不误报。
|
|
3
|
+
//
|
|
4
|
+
// URL -> 文件规则以运行时为准,优先直接复用 soma-core 的解析函数(`soma-core/server` 导出):
|
|
5
|
+
// - service-path.ts:8-13 toPascalCase:末段按 - / _ 切分后各段首字母大写
|
|
6
|
+
// - service-path.ts:19-35 validateServiceSegments:空段、. / ..、以 _ 开头的段(私有模块,不可达)一律不可路由
|
|
7
|
+
// - service-path.ts:72-108 resolveHostServiceCandidate:<apiRoot>/api/service、<apiRoot>/../api/service、<apiRoot>/service
|
|
8
|
+
// 下按 .ts .js .mjs .cjs 顺序找 <dirs>/<ClassName><ext>;没有 index 约定,也没有动态段
|
|
9
|
+
// - load-host-service.ts:186-203 apiRoot = getSomaHostApiRoot(SOMA_API_DIR > package.json soma.apiRoot|serviceRoot > 源根);
|
|
10
|
+
// 宿主根找不到时再找依赖里的源包(getSomaAssetSources)
|
|
11
|
+
// - dispatch-service-api.ts:188-196 方法按 service[get|post|put|patch|delete] 是否为函数裁决,没有则 405
|
|
12
|
+
// 核心导出加载失败时整体跳过核对(不维护平行实现,避免与运行时规则出入)。
|
|
13
|
+
import { KIT_CORE_MAPPING } from '../object-renderer/defaults';
|
|
14
|
+
|
|
15
|
+
export interface ServiceEndpointRef {
|
|
16
|
+
/** 接口地址(含可能的查询串 / 占位符,核对时去掉查询串) */
|
|
17
|
+
readonly url: string;
|
|
18
|
+
/** 大写 HTTP 方法 */
|
|
19
|
+
readonly method: string;
|
|
20
|
+
/** 页面文件(相对应用根,/ 分隔) */
|
|
21
|
+
readonly file: string;
|
|
22
|
+
/** YAML 路径(用户实际写下的位置),如 page.objects.orders.behavior.write */
|
|
23
|
+
readonly yamlPath: string;
|
|
24
|
+
/** 字符串 / 单地址形式的 write 同时对应新建与编辑两个通道:记录本条核对的是哪个通道,供告警原因说明 */
|
|
25
|
+
readonly channel?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ServiceEndpointWarning {
|
|
29
|
+
readonly file: string;
|
|
30
|
+
readonly yamlPath: string;
|
|
31
|
+
readonly url: string;
|
|
32
|
+
readonly method: string;
|
|
33
|
+
readonly reason: '未找到对应的服务文件' | '服务文件未实现该方法';
|
|
34
|
+
/** 期望的服务文件位置(相对应用根)或已找到的服务文件与其已实现的方法 */
|
|
35
|
+
readonly hint: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface ServiceEndpointReport {
|
|
39
|
+
readonly warnings: readonly ServiceEndpointWarning[];
|
|
40
|
+
/** 整体跳过的原因(有值时 warnings 为空) */
|
|
41
|
+
readonly skipped?: string;
|
|
42
|
+
/** 应用配置了请求钩子(照常核对;文本输出在告警段加提示,钩子直接应答的地址可忽略对应告警) */
|
|
43
|
+
readonly hasRequestHook?: boolean;
|
|
44
|
+
/** 参与核对的接口引用条数 */
|
|
45
|
+
readonly checked: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const SKIP_DIRS = new Set(['node_modules', 'tests', 'test', 'dist', 'build', 'coverage']);
|
|
49
|
+
const isRec = (v: unknown): v is Record<string, unknown> => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
50
|
+
|
|
51
|
+
// ------------------------------------------------------------------ 收集接口引用
|
|
52
|
+
|
|
53
|
+
/** 从一份已解析的页面声明收集接口引用(覆盖读、三个写通道、详情读、动作 request / download、options.from) */
|
|
54
|
+
export function collectEndpointRefsFromParsed(raw: unknown, file: string): ServiceEndpointRef[] {
|
|
55
|
+
const out: ServiceEndpointRef[] = [];
|
|
56
|
+
const method = (name: string): string => (KIT_CORE_MAPPING.writeChannels[name]?.method ?? '').toUpperCase();
|
|
57
|
+
const push = (url: string, m: string, yamlPath: string, channel?: string): void => {
|
|
58
|
+
if (url !== '') out.push({ url, method: m, file, yamlPath, ...(channel !== undefined ? { channel } : {}) });
|
|
59
|
+
};
|
|
60
|
+
const endpoint = (value: unknown, defaultMethod: string, at: string, channel?: string): void => {
|
|
61
|
+
if (typeof value === 'string') return push(value, defaultMethod, at, channel);
|
|
62
|
+
if (Array.isArray(value)) return value.forEach((item, i) => endpoint(item, defaultMethod, `${at}[${i}]`, channel));
|
|
63
|
+
if (!isRec(value)) return;
|
|
64
|
+
const m = typeof value.method === 'string' ? value.method.toUpperCase() : defaultMethod;
|
|
65
|
+
let found = false;
|
|
66
|
+
for (const key of ['api', 'url', 'path'] as const) {
|
|
67
|
+
if (typeof value[key] === 'string') {
|
|
68
|
+
push(value[key] as string, m, `${at}.${key}`, channel);
|
|
69
|
+
found = true;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (!found) for (const [k, v] of Object.entries(value)) endpoint(v, m, `${at}.${k}`, channel);
|
|
73
|
+
};
|
|
74
|
+
const seen = new Set<object>();
|
|
75
|
+
const walk = (value: unknown, at: string): void => {
|
|
76
|
+
if (value === null || typeof value !== 'object' || seen.has(value)) return;
|
|
77
|
+
seen.add(value);
|
|
78
|
+
if (Array.isArray(value)) return value.forEach((item, i) => walk(item, `${at}[${i}]`));
|
|
79
|
+
const rec = value as Record<string, unknown>;
|
|
80
|
+
if (isRec(rec.behavior)) {
|
|
81
|
+
const b = rec.behavior;
|
|
82
|
+
if (b.from !== undefined) endpoint(b.from, 'GET', `${at}.behavior.from`);
|
|
83
|
+
if (b.write !== undefined) {
|
|
84
|
+
const w = b.write;
|
|
85
|
+
if (isRec(w) && ['create', 'update', 'delete'].some((k) => Object.hasOwn(w, k))) {
|
|
86
|
+
for (const ch of ['create', 'update', 'delete'] as const) {
|
|
87
|
+
if (w[ch] !== undefined) endpoint(w[ch], method(ch), `${at}.behavior.write.${ch}`);
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
// 字符串 / 单地址形式:新建(POST)与编辑(PUT)共用同一地址,YAML 路径都是用户写的 behavior.write
|
|
91
|
+
endpoint(w, method('create'), `${at}.behavior.write`, `新建(${method('create')})通道`);
|
|
92
|
+
endpoint(w, method('update'), `${at}.behavior.write`, `编辑(${method('update')})通道`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (isRec(b.detail) && b.detail.from !== undefined) endpoint(b.detail.from, 'GET', `${at}.behavior.detail.from`);
|
|
96
|
+
if (Array.isArray(b.actions)) {
|
|
97
|
+
b.actions.forEach((a, i) => {
|
|
98
|
+
if (!isRec(a)) return;
|
|
99
|
+
if (a.request !== undefined) endpoint(a.request, 'POST', `${at}.behavior.actions[${i}].request`);
|
|
100
|
+
if (a.download !== undefined) endpoint(a.download, 'GET', `${at}.behavior.actions[${i}].download`);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// 选项源:任意位置的 options.from(目标收集函数没有覆盖)
|
|
105
|
+
if (isRec(rec.options) && rec.options.from !== undefined) endpoint(rec.options.from, 'GET', `${at}.options.from`);
|
|
106
|
+
for (const [k, v] of Object.entries(rec)) walk(v, at === '' ? k : `${at}.${k}`);
|
|
107
|
+
};
|
|
108
|
+
walk(raw, '');
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** 扫描应用根下全部 *.kit.yaml 收集接口引用;解析不了的页面跳过(由编译步骤报错) */
|
|
113
|
+
export async function collectEndpointRefs(appDir: string): Promise<ServiceEndpointRef[] | undefined> {
|
|
114
|
+
const path = await import(/* webpackIgnore: true */ 'node:path');
|
|
115
|
+
const fs = await import(/* webpackIgnore: true */ 'node:fs');
|
|
116
|
+
let parse: (text: string, kind: 'ui') => { ok: boolean; value?: unknown };
|
|
117
|
+
try {
|
|
118
|
+
parse = (await import('soma-core/server/runtime')).parseSomaDsl as typeof parse;
|
|
119
|
+
} catch {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
const root = path.resolve(appDir);
|
|
123
|
+
const refs: ServiceEndpointRef[] = [];
|
|
124
|
+
const walk = (dir: string): void => {
|
|
125
|
+
let entries: import('node:fs').Dirent[];
|
|
126
|
+
try {
|
|
127
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
128
|
+
} catch {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
for (const e of entries.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
132
|
+
if (e.name.startsWith('.') || SKIP_DIRS.has(e.name)) continue;
|
|
133
|
+
const full = path.join(dir, e.name);
|
|
134
|
+
if (e.isDirectory()) walk(full);
|
|
135
|
+
else if (e.isFile() && e.name.endsWith('.kit.yaml')) {
|
|
136
|
+
try {
|
|
137
|
+
const parsed = parse(fs.readFileSync(full, 'utf8'), 'ui');
|
|
138
|
+
if (parsed.ok) refs.push(...collectEndpointRefsFromParsed(parsed.value, path.relative(root, full).split(path.sep).join('/')));
|
|
139
|
+
} catch {
|
|
140
|
+
// 读不到 / 解析失败:交给编译步骤
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
walk(root);
|
|
146
|
+
return refs;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// ------------------------------------------------------------------ 服务落点解析
|
|
150
|
+
|
|
151
|
+
interface CoreResolver {
|
|
152
|
+
apiRoot(appRoot: string): string;
|
|
153
|
+
candidate(appRoot: string, apiRoot: string, segments: string[]): string | null;
|
|
154
|
+
validate(segments: string[]): { dirSegments: string[]; className: string } | null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
async function loadCoreResolver(): Promise<CoreResolver | undefined> {
|
|
158
|
+
try {
|
|
159
|
+
const core = (await import('soma-core/server/node')) as unknown as {
|
|
160
|
+
getSomaHostApiRoot: (hostDir: string) => string;
|
|
161
|
+
getSomaHostSourceRoot: (hostDir: string) => string;
|
|
162
|
+
getSomaAssetSources: (hostDir: string) => ReadonlyArray<{ type: string; apiRoot?: string; codeRoot?: string }>;
|
|
163
|
+
resolveHostServiceCandidate: (apiRoot: string, segments: string[], o?: { allowDirectRoot?: boolean }) => string | null;
|
|
164
|
+
validateServiceSegments: (segments: readonly string[]) => { dirSegments: string[]; className: string } | null;
|
|
165
|
+
};
|
|
166
|
+
if (typeof core.resolveHostServiceCandidate !== 'function' || typeof core.getSomaHostApiRoot !== 'function') return undefined;
|
|
167
|
+
return {
|
|
168
|
+
apiRoot: (appRoot) => core.getSomaHostApiRoot(appRoot),
|
|
169
|
+
validate: (segments) => core.validateServiceSegments(segments),
|
|
170
|
+
// 与 load-host-service.ts:186-203 同序:宿主 apiRoot(直取根仅当 apiRoot !== 源根)→ 依赖源包
|
|
171
|
+
candidate: (appRoot, apiRoot, segments) => {
|
|
172
|
+
const own = core.resolveHostServiceCandidate(apiRoot, segments, { allowDirectRoot: apiRoot !== core.getSomaHostSourceRoot(appRoot) });
|
|
173
|
+
if (own !== null) return own;
|
|
174
|
+
for (const source of core.getSomaAssetSources(appRoot)) {
|
|
175
|
+
if (source.type !== 'package') continue;
|
|
176
|
+
const hit = core.resolveHostServiceCandidate(source.apiRoot || source.codeRoot || '', segments, { allowDirectRoot: false });
|
|
177
|
+
if (hit !== null) return hit;
|
|
178
|
+
}
|
|
179
|
+
return null;
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
} catch {
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** 从模板字符串正文(开引号之后)起跳到闭合反引号之后;`${ }` 内按代码递归扫描;失衡返回 -1 */
|
|
188
|
+
function skipTemplate(text: string, start: number): number {
|
|
189
|
+
const n = text.length;
|
|
190
|
+
let i = start;
|
|
191
|
+
while (i < n) {
|
|
192
|
+
const t = text[i]!;
|
|
193
|
+
if (t === '\\') i += 2;
|
|
194
|
+
else if (t === '`') return i + 1;
|
|
195
|
+
else if (t === '$' && text[i + 1] === '{') {
|
|
196
|
+
const j = skipCode(text, i + 2);
|
|
197
|
+
if (j < 0) return -1;
|
|
198
|
+
i = j;
|
|
199
|
+
} else i++;
|
|
200
|
+
}
|
|
201
|
+
return -1;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** 从模板表达式内部(`${` 之后)起跳到配对的 `}` 之后:识别注释、字符串、嵌套模板,花括号深度只统计这些之外的;失衡返回 -1 */
|
|
205
|
+
function skipCode(text: string, start: number): number {
|
|
206
|
+
const n = text.length;
|
|
207
|
+
let i = start;
|
|
208
|
+
let depth = 0;
|
|
209
|
+
while (i < n) {
|
|
210
|
+
const c = text[i]!;
|
|
211
|
+
const d = text[i + 1];
|
|
212
|
+
if (c === '/' && d === '/') {
|
|
213
|
+
while (i < n && text[i] !== '\n') i++;
|
|
214
|
+
} else if (c === '/' && d === '*') {
|
|
215
|
+
const end = text.indexOf('*/', i + 2);
|
|
216
|
+
if (end === -1) return -1;
|
|
217
|
+
i = end + 2;
|
|
218
|
+
} else if (c === '"' || c === "'") {
|
|
219
|
+
i++;
|
|
220
|
+
while (i < n && text[i] !== c && text[i] !== '\n') i += text[i] === '\\' ? 2 : 1;
|
|
221
|
+
if (i >= n || text[i] !== c) return -1;
|
|
222
|
+
i++;
|
|
223
|
+
} else if (c === '`') {
|
|
224
|
+
const j = skipTemplate(text, i + 1);
|
|
225
|
+
if (j < 0) return -1;
|
|
226
|
+
i = j;
|
|
227
|
+
} else if (c === '{') {
|
|
228
|
+
depth++;
|
|
229
|
+
i++;
|
|
230
|
+
} else if (c === '}') {
|
|
231
|
+
if (depth === 0) return i + 1;
|
|
232
|
+
depth--;
|
|
233
|
+
i++;
|
|
234
|
+
} else i++;
|
|
235
|
+
}
|
|
236
|
+
return -1;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* 抹掉注释与字符串(含模板字符串)的字符扫描:注释换成空格、字符串换成 `""`。
|
|
241
|
+
* 先按字符状态识别再抹,所以 `'http://x'` 里的 `//` 不会被当成注释;模板的 `${ }` 内同样识别字符串 / 嵌套模板 / 注释。
|
|
242
|
+
* 扫描失衡(未闭合的字符串 / 模板 / 注释 / 模板表达式,或正则字面量里的引号造成的错位)返回 undefined:调用方整体放弃方法核对。
|
|
243
|
+
*/
|
|
244
|
+
function stripCommentsAndStrings(text: string): string | undefined {
|
|
245
|
+
let out = '';
|
|
246
|
+
let i = 0;
|
|
247
|
+
const n = text.length;
|
|
248
|
+
while (i < n) {
|
|
249
|
+
const c = text[i]!;
|
|
250
|
+
const d = text[i + 1];
|
|
251
|
+
if (c === '/' && d === '/') {
|
|
252
|
+
while (i < n && text[i] !== '\n') i++;
|
|
253
|
+
out += ' ';
|
|
254
|
+
} else if (c === '/' && d === '*') {
|
|
255
|
+
const end = text.indexOf('*/', i + 2);
|
|
256
|
+
if (end === -1) return undefined;
|
|
257
|
+
i = end + 2;
|
|
258
|
+
out += ' ';
|
|
259
|
+
} else if (c === '"' || c === "'") {
|
|
260
|
+
i++;
|
|
261
|
+
while (i < n && text[i] !== c && text[i] !== '\n') i += text[i] === '\\' ? 2 : 1;
|
|
262
|
+
if (i >= n || text[i] !== c) return undefined;
|
|
263
|
+
i++;
|
|
264
|
+
out += '""';
|
|
265
|
+
} else if (c === '`') {
|
|
266
|
+
const j = skipTemplate(text, i + 1);
|
|
267
|
+
if (j < 0) return undefined;
|
|
268
|
+
i = j;
|
|
269
|
+
out += '""';
|
|
270
|
+
} else {
|
|
271
|
+
out += c;
|
|
272
|
+
i++;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return out;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** 从 open 处的 `(` 起找配对的 `)`;找不到返回 -1 */
|
|
279
|
+
function matchingParen(text: string, open: number): number {
|
|
280
|
+
let depth = 0;
|
|
281
|
+
for (let i = open; i < text.length; i++) {
|
|
282
|
+
if (text[i] === '(') depth++;
|
|
283
|
+
else if (text[i] === ')' && --depth === 0) return i;
|
|
284
|
+
}
|
|
285
|
+
return -1;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* 是否存在「成员定义处的计算属性名」:方括号前面(忽略空白)是成员 / 语句起点(`{ , ; }`、行首、`*`,或 static / async / get / set 关键字之后),
|
|
290
|
+
* 且方括号后面跟 `( : = <`。前面是标识符字符、`)`、`]`、`.` 的是下标访问(如 `rows[0] = x`),不算。
|
|
291
|
+
*/
|
|
292
|
+
function hasComputedMemberName(clean: string): boolean {
|
|
293
|
+
for (const m of clean.matchAll(/\[[^\]]*\]\s*[(:=<]/g)) {
|
|
294
|
+
const raw = clean.slice(0, m.index);
|
|
295
|
+
const before = raw.trimEnd();
|
|
296
|
+
if (before === '') return true;
|
|
297
|
+
const last = before[before.length - 1]!;
|
|
298
|
+
if ('{,;}*'.includes(last)) return true;
|
|
299
|
+
if (/\n/.test(raw.slice(before.length))) return true;
|
|
300
|
+
if (/(?:^|[^\w$.])(?:static|async|get|set)$/.test(before)) return true;
|
|
301
|
+
}
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const METHOD_NAME = /(?<![.\w$])(get|post|put|patch|delete)(?![\w$])\s*(?:<[^<>(){};]*(?:<[^<>]*>[^<>(){};]*)*>)?\s*(\(|:|=(?![=>]))/g;
|
|
306
|
+
const DECL_KEYWORD_BEFORE = /\b(?:const|let|var|function|import|type|interface|enum|class)\s+$/;
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* 服务文件已声明的 HTTP 方法;不能可靠判断返回 undefined(宁可不报也不误报):
|
|
310
|
+
* 含继承 / 对象展开 / Object.assign / 计算属性名 / 对 this.<方法名> 的赋值,或一个方法都没认出。
|
|
311
|
+
* 词法判断:抹掉注释与字符串后找 get / post / put / patch / delete 的方法声明(允许泛型)或属性;
|
|
312
|
+
* 方法名前不能是 `.`、标识符字符或 `$`,写成 `name(...)` 时括号后必须跟方法体 `{`(区分普通函数调用)。
|
|
313
|
+
*/
|
|
314
|
+
export function declaredServiceMethods(text: string): Set<string> | undefined {
|
|
315
|
+
const clean = stripCommentsAndStrings(text);
|
|
316
|
+
if (clean === undefined) return undefined;
|
|
317
|
+
if (hasComputedMemberName(clean)) return undefined;
|
|
318
|
+
if (/\bextends\b|\.\.\.|Object\.assign|\bthis\s*\.\s*(?:get|post|put|patch|delete)\s*=(?!=)/.test(clean)) return undefined;
|
|
319
|
+
const methods = new Set<string>();
|
|
320
|
+
for (const m of clean.matchAll(METHOD_NAME)) {
|
|
321
|
+
const before = clean.slice(0, m.index).replace(/\basync\s+$/, '');
|
|
322
|
+
if (/\bstatic\s+$/.test(before)) continue; // 静态方法不是路由处理方法
|
|
323
|
+
if (DECL_KEYWORD_BEFORE.test(before)) continue;
|
|
324
|
+
if (m[2] === '(') {
|
|
325
|
+
const open = m.index! + m[0].length - 1;
|
|
326
|
+
const close = matchingParen(clean, open);
|
|
327
|
+
if (close === -1 || !/^\s*(?::[^;{}]*)?\{/.test(clean.slice(close + 1))) continue;
|
|
328
|
+
}
|
|
329
|
+
methods.add(m[1]!.toUpperCase());
|
|
330
|
+
}
|
|
331
|
+
return methods.size === 0 ? undefined : methods;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// ------------------------------------------------------------------ 核对
|
|
335
|
+
|
|
336
|
+
/** 纯核对:给定应用根与接口引用,返回告警;apiRoot 无服务目录、声明了请求代理时整体跳过;配了请求钩子照常核对,仅在报告里标记 */
|
|
337
|
+
export async function checkServiceEndpoints(appDir: string, refs: readonly ServiceEndpointRef[]): Promise<ServiceEndpointReport> {
|
|
338
|
+
const path = await import(/* webpackIgnore: true */ 'node:path');
|
|
339
|
+
const fs = await import(/* webpackIgnore: true */ 'node:fs');
|
|
340
|
+
const root = path.resolve(appDir);
|
|
341
|
+
const skip = (reason: string): ServiceEndpointReport => ({ warnings: [], skipped: reason, checked: 0 });
|
|
342
|
+
const rel = (p: string): string => path.relative(root, p).split(path.sep).join('/') || '.';
|
|
343
|
+
|
|
344
|
+
if (refs.length === 0) return { warnings: [], checked: 0 };
|
|
345
|
+
|
|
346
|
+
// 请求代理 / 外部后端转发:package.json 的 proxy / soma.proxy / soma.apiProxy
|
|
347
|
+
try {
|
|
348
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8')) as { proxy?: unknown; soma?: Record<string, unknown> };
|
|
349
|
+
if (pkg.proxy !== undefined || pkg.soma?.proxy !== undefined || pkg.soma?.apiProxy !== undefined) return skip('应用声明了请求代理 / 外部后端转发');
|
|
350
|
+
} catch {
|
|
351
|
+
// 没有 package.json:不构成跳过理由
|
|
352
|
+
}
|
|
353
|
+
// 请求钩子通常只做鉴权放行 / 拒绝,不让不存在的服务文件变得可用:不跳过,只标记
|
|
354
|
+
let hasRequestHook = false;
|
|
355
|
+
for (const name of ['soma.server.ts', 'soma.server.mts', 'soma.server.js', 'soma.server.mjs']) {
|
|
356
|
+
try {
|
|
357
|
+
if (/\brequestHook\b|\bonRequest\b/.test(fs.readFileSync(path.join(root, name), 'utf8'))) hasRequestHook = true;
|
|
358
|
+
} catch {
|
|
359
|
+
// 不存在
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
const resolver = await loadCoreResolver();
|
|
364
|
+
if (resolver === undefined) return skip('无法加载运行时解析规则');
|
|
365
|
+
const apiRoot = resolver.apiRoot(root);
|
|
366
|
+
const isDir = (p: string): boolean => fs.statSync(p, { throwIfNoEntry: false })?.isDirectory() === true;
|
|
367
|
+
const serviceBases = [path.join(apiRoot, 'api', 'service'), path.join(apiRoot, '..', 'api', 'service'), path.join(apiRoot, 'service')];
|
|
368
|
+
if (!serviceBases.some(isDir)) return skip(`${rel(apiRoot)} 下没有 api/service 目录(纯前端或服务在别处)`);
|
|
369
|
+
|
|
370
|
+
const warnings: ServiceEndpointWarning[] = [];
|
|
371
|
+
const methodCache = new Map<string, Set<string> | undefined>();
|
|
372
|
+
let checked = 0;
|
|
373
|
+
for (const ref of refs) {
|
|
374
|
+
const pathname = ref.url.split(/[?#]/)[0]!;
|
|
375
|
+
if (!pathname.startsWith('/api/') || pathname.includes('{') || pathname.includes('${') || pathname.includes('%')) continue;
|
|
376
|
+
const segments = pathname.slice('/api/'.length).split('/');
|
|
377
|
+
if (segments[segments.length - 1] === '') segments.pop();
|
|
378
|
+
if (segments.length === 0 || segments.some((s) => s === '' || s === '.' || s === '..' || /[:*]/.test(s))) continue;
|
|
379
|
+
checked++;
|
|
380
|
+
const validated = resolver.validate(segments);
|
|
381
|
+
const file = validated === null ? null : resolver.candidate(root, apiRoot, segments);
|
|
382
|
+
if (file === null) {
|
|
383
|
+
const expected = validated === null
|
|
384
|
+
? '以 _ 开头的目录 / 文件是私有模块,不可经 /api 访问'
|
|
385
|
+
: `期望 ${rel(path.join(apiRoot, 'api', 'service', ...validated.dirSegments, `${validated.className}.ts`))}`;
|
|
386
|
+
warnings.push({ file: ref.file, yamlPath: ref.yamlPath, url: ref.url, method: ref.method, reason: '未找到对应的服务文件', hint: expected });
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
if (!methodCache.has(file)) {
|
|
390
|
+
try {
|
|
391
|
+
methodCache.set(file, declaredServiceMethods(fs.readFileSync(file, 'utf8')));
|
|
392
|
+
} catch {
|
|
393
|
+
methodCache.set(file, undefined);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
const declared = methodCache.get(file);
|
|
397
|
+
if (declared !== undefined && !declared.has(ref.method)) {
|
|
398
|
+
warnings.push({
|
|
399
|
+
file: ref.file, yamlPath: ref.yamlPath, url: ref.url, method: ref.method, reason: '服务文件未实现该方法',
|
|
400
|
+
hint: `${rel(file)} 只实现了 ${[...declared].join(' / ')}${ref.channel !== undefined ? `;该地址来自 write 的${ref.channel}` : ''}`,
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
return { warnings, checked, ...(hasRequestHook ? { hasRequestHook } : {}) };
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/** `soma kit check` 用:收集 + 核对;任何内部异常都归为「跳过」,绝不影响检查结果 */
|
|
408
|
+
export async function runServiceEndpointCheck(appDir: string): Promise<ServiceEndpointReport> {
|
|
409
|
+
try {
|
|
410
|
+
const refs = await collectEndpointRefs(appDir);
|
|
411
|
+
if (refs === undefined) return { warnings: [], skipped: '无法加载页面解析器', checked: 0 };
|
|
412
|
+
return await checkServiceEndpoints(appDir, refs);
|
|
413
|
+
} catch (error) {
|
|
414
|
+
return { warnings: [], skipped: `核对过程出错:${(error as Error)?.message ?? String(error)}`, checked: 0 };
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/** 文本模式输出段;没有告警也没有跳过时返回空串 */
|
|
419
|
+
export function formatServiceEndpointReport(report: ServiceEndpointReport): string {
|
|
420
|
+
if (report.skipped !== undefined) return `未核对接口落点:${report.skipped}\n`;
|
|
421
|
+
if (report.warnings.length === 0) return '';
|
|
422
|
+
const lines = report.warnings.map((w) => ` ${w.file} ${w.yamlPath}:${w.method} ${w.url} ${w.reason}(${w.hint})`);
|
|
423
|
+
const hookNote = report.hasRequestHook === true ? ' 提示:应用配置了请求钩子;若该地址由钩子直接应答,可忽略对应告警\n' : '';
|
|
424
|
+
return `接口落点告警(不影响检查结果)${report.warnings.length} 条\n${lines.join('\n')}\n${hookNote}`;
|
|
425
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface SourcePathIssue {
|
|
2
|
+
kind: 'url' | 'filesystem';
|
|
3
|
+
pathKind?: 'absolute' | 'relative';
|
|
4
|
+
index: number;
|
|
5
|
+
callee: string;
|
|
6
|
+
value: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface SourcePathScanOptions {
|
|
10
|
+
/** 实际源文件名,用来选择 TS / TSX / JS 语法模式。 */
|
|
11
|
+
fileName?: string;
|
|
12
|
+
/** 返回 true 表示 URL 值不符合调用处的 URL 路径语境。 */
|
|
13
|
+
isInvalidUrl?: (value: string, allowExternalHref: boolean) => boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** 使用 TypeScript AST 扫描 URL 调用与 Node 文件系统调用。 */
|
|
17
|
+
export function scanPathSourceUsages(source: string, options?: SourcePathScanOptions): SourcePathIssue[];
|