soma-kit 0.0.0-stage → 0.1.0
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 +539 -2
- package/bin/soma-kit.mjs +27 -0
- package/package.json +66 -4
- package/packs/ai/agent-run-card.ts +64 -0
- package/packs/ai/evaluation-card.ts +51 -0
- package/packs/ai/guardrail-policy-card.ts +48 -0
- package/packs/ai/index.ts +31 -0
- package/packs/ai/model-card.ts +55 -0
- package/packs/ai/model-routing-card.ts +49 -0
- package/packs/ai/prompt-template-card.ts +49 -0
- package/packs/ai/texts.ts +19 -0
- package/packs/commerce/address-card.ts +58 -0
- package/packs/commerce/coupon-card.ts +64 -0
- package/packs/commerce/index.ts +25 -0
- package/packs/commerce/order-card.ts +60 -0
- package/packs/commerce/purchase-order-card.ts +74 -0
- package/packs/commerce/texts.ts +14 -0
- package/packs/finance/index.ts +30 -0
- package/packs/finance/invoice-summary-card.ts +48 -0
- package/packs/finance/reconcile-board.ts +450 -0
- package/packs/finance/reconcile-case-card.ts +70 -0
- package/packs/finance/reconcile-desk/compile.ts +208 -0
- package/packs/finance/reconcile-desk/index.ts +20 -0
- package/packs/finance/reconcile-desk/shell.ts +27 -0
- package/packs/finance/texts.ts +21 -0
- package/packs/ops/change-window-card.ts +54 -0
- package/packs/ops/dependency-status-card.ts +50 -0
- package/packs/ops/error-budget-card.ts +60 -0
- package/packs/ops/execution-task-runner.ts +61 -0
- package/packs/ops/index.ts +36 -0
- package/packs/ops/integration-status-card.ts +45 -0
- package/packs/ops/release-readiness-card.ts +63 -0
- package/packs/ops/runbook-execution-card.ts +81 -0
- package/packs/ops/texts.ts +21 -0
- package/packs/security/control-evidence-card.ts +54 -0
- package/packs/security/finding-card.ts +96 -0
- package/packs/security/index.ts +29 -0
- package/packs/security/texts.ts +31 -0
- package/packs/shared/card-util.ts +60 -0
- package/packs/shared/wrap.ts +13 -0
- package/spec/generated/kit-app.schema.json +84 -0
- package/spec/generated/kit-page.schema.json +2766 -0
- package/spec/kit-grammar.json +1358 -0
- package/spec/kit-grammar.schema.json +716 -0
- package/src/app/app-config.ts +108 -0
- package/src/app/compose-apps.ts +139 -0
- package/src/app/define-kit-actions.ts +89 -0
- package/src/app/define-kit-app.ts +362 -0
- package/src/app/define-kit-pack.ts +114 -0
- package/src/app/envelope.ts +117 -0
- package/src/app/index.ts +50 -0
- package/src/app/notify-renderer.ts +114 -0
- package/src/app/paged-list-adapter.ts +246 -0
- package/src/app/server-pages.ts +303 -0
- package/src/app/server.ts +244 -0
- package/src/app/submit.types.ts +87 -0
- package/src/base/action-busy.ts +159 -0
- package/src/base/action-gate.ts +267 -0
- package/src/base/action-status.ts +31 -0
- package/src/base/alert.ts +136 -0
- package/src/base/avatar.ts +271 -0
- package/src/base/button.ts +139 -0
- package/src/base/cascader.ts +523 -0
- package/src/base/check-core.ts +214 -0
- package/src/base/checkbox.ts +35 -0
- package/src/base/choice.ts +183 -0
- package/src/base/color-picker.ts +316 -0
- package/src/base/combobox.ts +61 -0
- package/src/base/command-palette.ts +371 -0
- package/src/base/context-menu.ts +103 -0
- package/src/base/countdown.ts +168 -0
- package/src/base/date-range.ts +444 -0
- package/src/base/date.ts +899 -0
- package/src/base/divider.ts +156 -0
- package/src/base/fab.ts +192 -0
- package/src/base/icons.ts +106 -0
- package/src/base/image.ts +177 -0
- package/src/base/index.ts +214 -0
- package/src/base/input.ts +316 -0
- package/src/base/kbd.ts +99 -0
- package/src/base/link.ts +167 -0
- package/src/base/listbox-core.ts +965 -0
- package/src/base/mentions.ts +323 -0
- package/src/base/menu-button.ts +240 -0
- package/src/base/menu-core.ts +341 -0
- package/src/base/month-grid.ts +171 -0
- package/src/base/motion/aura.ts +94 -0
- package/src/base/motion/hover-3d.ts +154 -0
- package/src/base/motion/hover-gallery.ts +185 -0
- package/src/base/motion/index.ts +27 -0
- package/src/base/motion/limits.ts +75 -0
- package/src/base/motion/marquee.ts +157 -0
- package/src/base/motion/text-rotate.ts +195 -0
- package/src/base/number.ts +121 -0
- package/src/base/otp.ts +259 -0
- package/src/base/permission-gate.ts +99 -0
- package/src/base/popover.ts +352 -0
- package/src/base/popup.ts +542 -0
- package/src/base/portal-core.ts +297 -0
- package/src/base/price-text.ts +126 -0
- package/src/base/progress.ts +216 -0
- package/src/base/qr-code.ts +446 -0
- package/src/base/qty-stepper.ts +241 -0
- package/src/base/radio.ts +33 -0
- package/src/base/range.ts +444 -0
- package/src/base/rating.ts +249 -0
- package/src/base/segmented.ts +286 -0
- package/src/base/select.ts +57 -0
- package/src/base/shared.ts +708 -0
- package/src/base/swap.ts +86 -0
- package/src/base/switch.ts +111 -0
- package/src/base/tag-input.ts +464 -0
- package/src/base/tag.ts +250 -0
- package/src/base/text.ts +126 -0
- package/src/base/textarea.ts +129 -0
- package/src/base/time-picker.ts +606 -0
- package/src/base/tree-select.ts +629 -0
- package/src/base/upload.ts +548 -0
- package/src/base/virtual-list.ts +286 -0
- package/src/biz/approval-desk/compile.ts +179 -0
- package/src/biz/approval-desk/index.ts +21 -0
- package/src/biz/approval-desk/shell.ts +50 -0
- package/src/biz/auth-panel/compile.ts +196 -0
- package/src/biz/auth-panel/index.ts +24 -0
- package/src/biz/auth-panel/shell.ts +46 -0
- package/src/biz/category-crud/compile.ts +173 -0
- package/src/biz/category-crud/index.ts +19 -0
- package/src/biz/category-crud/shell.ts +29 -0
- package/src/biz/checkout-page/compile.ts +111 -0
- package/src/biz/checkout-page/index.ts +20 -0
- package/src/biz/checkout-page/shell.ts +50 -0
- package/src/biz/compose.ts +313 -0
- package/src/biz/data-components.ts +26 -0
- package/src/biz/define.ts +23 -0
- package/src/biz/import-wizard/compile.ts +204 -0
- package/src/biz/import-wizard/hub.ts +540 -0
- package/src/biz/import-wizard/index.ts +24 -0
- package/src/biz/import-wizard/shell.ts +161 -0
- package/src/biz/index.ts +80 -0
- package/src/biz/landing-page/compile.ts +67 -0
- package/src/biz/landing-page/index.ts +20 -0
- package/src/biz/landing-page/shell.ts +48 -0
- package/src/biz/link/hub.ts +255 -0
- package/src/biz/link/shared.ts +493 -0
- package/src/biz/master-sub/compile.ts +232 -0
- package/src/biz/master-sub/index.ts +20 -0
- package/src/biz/master-sub/shell.ts +56 -0
- package/src/biz/multi-board/compile.ts +234 -0
- package/src/biz/multi-board/index.ts +19 -0
- package/src/biz/multi-board/shell.ts +70 -0
- package/src/biz/names.ts +30 -0
- package/src/biz/notification-center/compile.ts +138 -0
- package/src/biz/notification-center/index.ts +29 -0
- package/src/biz/notification-center/shell.ts +42 -0
- package/src/biz/page-templates/result-page/compile.ts +46 -0
- package/src/biz/page-templates/result-page/index.ts +19 -0
- package/src/biz/page-templates/result-page/shell.ts +31 -0
- package/src/biz/page-templates/shared.ts +121 -0
- package/src/biz/page-templates/sign-in-page/compile.ts +176 -0
- package/src/biz/page-templates/sign-in-page/index.ts +18 -0
- package/src/biz/page-templates/sign-in-page/shell.ts +116 -0
- package/src/biz/record-detail/compile.ts +290 -0
- package/src/biz/record-detail/index.ts +22 -0
- package/src/biz/record-detail/shell.ts +64 -0
- package/src/biz/settings-center/compile.ts +100 -0
- package/src/biz/settings-center/index.ts +18 -0
- package/src/biz/settings-center/shell.ts +51 -0
- package/src/biz/shared/action-host.ts +469 -0
- package/src/biz/shared/coordinator.ts +516 -0
- package/src/biz/shared/index.ts +9 -0
- package/src/biz/shared/pipes.ts +58 -0
- package/src/biz/shared/runtime-hub.ts +112 -0
- package/src/biz/shared/step-values.ts +25 -0
- package/src/biz/single-form/compile.ts +146 -0
- package/src/biz/single-form/index.ts +18 -0
- package/src/biz/single-form/shell.ts +38 -0
- package/src/biz/standard-crud/bridge.ts +11 -0
- package/src/biz/standard-crud/compile.ts +546 -0
- package/src/biz/standard-crud/index.ts +18 -0
- package/src/biz/standard-crud/shell.ts +157 -0
- package/src/biz/step-form/compile.ts +400 -0
- package/src/biz/step-form/hub.ts +412 -0
- package/src/biz/step-form/index.ts +23 -0
- package/src/biz/step-form/shell.ts +96 -0
- package/src/biz/step-form/steps-ref.ts +112 -0
- package/src/biz/types.ts +96 -0
- package/src/cli/kit-cli.ts +102 -0
- package/src/compile/action-host-attach.ts +76 -0
- package/src/compile/compile-page.ts +472 -0
- package/src/compile/component-candidates.ts +147 -0
- package/src/compile/fragment.ts +104 -0
- package/src/compile/hints.ts +255 -0
- package/src/compile/index.ts +16 -0
- package/src/compile/locate.ts +166 -0
- package/src/compile/page-params.ts +80 -0
- package/src/compile/parse.ts +355 -0
- package/src/compile/redirect.ts +90 -0
- package/src/compile/registry.ts +30 -0
- package/src/compile/remove-guard.ts +99 -0
- package/src/compile/styles.ts +244 -0
- package/src/compile/types.ts +106 -0
- package/src/data/amount-breakdown.ts +132 -0
- package/src/data/anchor-nav.ts +225 -0
- package/src/data/approval-flow.ts +269 -0
- package/src/data/assignment-picker.ts +652 -0
- package/src/data/async-result-panel.ts +308 -0
- package/src/data/breadcrumbs.ts +197 -0
- package/src/data/calendar.ts +363 -0
- package/src/data/carousel.ts +408 -0
- package/src/data/chart.ts +726 -0
- package/src/data/checklist.ts +215 -0
- package/src/data/code-view.ts +415 -0
- package/src/data/comment-thread.ts +342 -0
- package/src/data/confirm-dialog.ts +144 -0
- package/src/data/context-menu.ts +216 -0
- package/src/data/d9-limits.ts +42 -0
- package/src/data/d9-util.ts +81 -0
- package/src/data/diff.ts +239 -0
- package/src/data/display-util.ts +135 -0
- package/src/data/dock.ts +152 -0
- package/src/data/embed.ts +200 -0
- package/src/data/field-mapper.ts +544 -0
- package/src/data/flow-editor-contract.ts +41 -0
- package/src/data/flow-editor.ts +2622 -0
- package/src/data/flow-remote-options.ts +257 -0
- package/src/data/footer.ts +157 -0
- package/src/data/form-draft-registry.ts +76 -0
- package/src/data/gantt.ts +430 -0
- package/src/data/hero.ts +149 -0
- package/src/data/image-viewer.ts +333 -0
- package/src/data/index.ts +268 -0
- package/src/data/item-list.ts +335 -0
- package/src/data/kanban.ts +667 -0
- package/src/data/media-grid.ts +246 -0
- package/src/data/mega-menu.ts +257 -0
- package/src/data/menu-dom.ts +169 -0
- package/src/data/menu.ts +464 -0
- package/src/data/mockup.ts +176 -0
- package/src/data/modal-dialog.ts +182 -0
- package/src/data/navbar.ts +292 -0
- package/src/data/object-form.ts +1981 -0
- package/src/data/options-bus.ts +24 -0
- package/src/data/outcome-watch.ts +40 -0
- package/src/data/overlay-portal.ts +6 -0
- package/src/data/pager.ts +473 -0
- package/src/data/permission-matrix.ts +432 -0
- package/src/data/permission-tree.ts +916 -0
- package/src/data/pricing-table.ts +269 -0
- package/src/data/prompt-dialog.ts +235 -0
- package/src/data/reaction-bar.ts +236 -0
- package/src/data/record-card.ts +413 -0
- package/src/data/record-picker.ts +489 -0
- package/src/data/redirect.ts +109 -0
- package/src/data/remote-options.ts +54 -0
- package/src/data/request-console.ts +399 -0
- package/src/data/resident.ts +58 -0
- package/src/data/result-panel.ts +160 -0
- package/src/data/rich-text.ts +626 -0
- package/src/data/row-editor.ts +1066 -0
- package/src/data/rule-builder.ts +1137 -0
- package/src/data/shape-util.ts +221 -0
- package/src/data/staged-rows.ts +69 -0
- package/src/data/stat-group.ts +231 -0
- package/src/data/static-lazy.ts +63 -0
- package/src/data/static-registry.ts +227 -0
- package/src/data/steps.ts +195 -0
- package/src/data/survey.ts +455 -0
- package/src/data/system-switcher.ts +243 -0
- package/src/data/timeline.ts +204 -0
- package/src/data/tour-guide.ts +392 -0
- package/src/data/transfer.ts +597 -0
- package/src/data/tree-check.ts +30 -0
- package/src/data/tree-table.ts +674 -0
- package/src/data/tree.ts +656 -0
- package/src/data/trend-line.ts +147 -0
- package/src/data/virtual-rows.ts +556 -0
- package/src/data/watermark.ts +140 -0
- package/src/data/wrap.ts +267 -0
- package/src/data/wrapped-candidates.ts +96 -0
- package/src/frames/blank-frame.ts +19 -0
- package/src/frames/index.ts +44 -0
- package/src/frames/page-bar.ts +185 -0
- package/src/frames/page-header.ts +185 -0
- package/src/frames/page-status.ts +54 -0
- package/src/frames/resize-handle.ts +147 -0
- package/src/frames/shared.ts +242 -0
- package/src/frames/single-frame.ts +16 -0
- package/src/frames/split-frame/index.ts +4 -0
- package/src/frames/split-frame/shell.ts +219 -0
- package/src/frames/split-frame/span.ts +64 -0
- package/src/frames/split-frame/wiring.ts +164 -0
- package/src/frames/tabs-frame/index.ts +3 -0
- package/src/frames/tabs-frame/shell.ts +112 -0
- package/src/frames/tabs-frame/wiring.ts +69 -0
- package/src/frames/top-main-frame.ts +20 -0
- package/src/frames/types.ts +72 -0
- package/src/frames/workspace-frame/extras.ts +197 -0
- package/src/frames/workspace-frame/index.ts +13 -0
- package/src/frames/workspace-frame/shell.ts +282 -0
- package/src/frames/workspace-frame/state.ts +152 -0
- package/src/frames/workspace-frame/view.ts +1013 -0
- package/src/generated/kit-grammar-runtime.ts +2822 -0
- package/src/generated/page-origin.ts +57 -0
- package/src/i18n/index.ts +22 -0
- package/src/i18n/kit-text.ts +692 -0
- package/src/i18n/resolve-text-refs.ts +128 -0
- package/src/index.ts +6 -0
- package/src/object-renderer/action-gate.ts +216 -0
- package/src/object-renderer/adopt-gate.ts +333 -0
- package/src/object-renderer/arrange.ts +411 -0
- package/src/object-renderer/candidates.ts +68 -0
- package/src/object-renderer/collapse-wiring.ts +99 -0
- package/src/object-renderer/collection-expand.ts +185 -0
- package/src/object-renderer/collection-parts.ts +653 -0
- package/src/object-renderer/collection-table.ts +503 -0
- package/src/object-renderer/collection.ts +628 -0
- package/src/object-renderer/compile-data.ts +549 -0
- package/src/object-renderer/defaults.ts +252 -0
- package/src/object-renderer/display-checks.ts +153 -0
- package/src/object-renderer/emit-events.ts +498 -0
- package/src/object-renderer/emit-object.ts +98 -0
- package/src/object-renderer/emit-static.ts +1036 -0
- package/src/object-renderer/field-policy.ts +89 -0
- package/src/object-renderer/field-value.ts +581 -0
- package/src/object-renderer/form-detail.ts +116 -0
- package/src/object-renderer/index.ts +13 -0
- package/src/object-renderer/linkage.ts +371 -0
- package/src/object-renderer/merge-class.ts +126 -0
- package/src/object-renderer/mode.ts +25 -0
- package/src/object-renderer/outcome-draft.ts +61 -0
- package/src/object-renderer/parts.ts +136 -0
- package/src/object-renderer/pick-component.ts +36 -0
- package/src/object-renderer/render-object.ts +724 -0
- package/src/object-renderer/request-actions.ts +581 -0
- package/src/object-renderer/skeleton.ts +101 -0
- package/src/object-renderer/table-actions.ts +438 -0
- package/src/object-renderer/table-summary.ts +105 -0
- package/src/object-renderer/table-tools.ts +1072 -0
- package/src/object-renderer/types.ts +936 -0
- package/src/page-target/ai-surface.ts +154 -0
- package/src/page-target/compile.ts +354 -0
- package/src/page-target/drift.ts +186 -0
- package/src/page-target/index.ts +25 -0
- package/src/page-target/intent-map.ts +137 -0
- package/src/page-target/intent-schema.ts +711 -0
- package/src/page-target/origin.ts +17 -0
- package/src/page-target/target.ts +450 -0
- package/src/page-target/writer-policy.ts +315 -0
- package/src/theme/block-theme.ts +202 -0
- package/src/theme/kit-theme-text.ts +2 -0
- package/src/theme/kit-theme.css +275 -0
- package/src/theme/kit-theme.tpl +275 -0
- package/src/theme/theme-tokens.ts +135 -0
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
// defineKitApp:soma-kit 应用的唯一装配入口(soma.app.ts 的默认导出)。
|
|
2
|
+
// 返回 core 认的 Host 装配形状 `{ kind: 'soma-app', host: { kind: 'soma-host', ... }, server(), browserMount() }`:
|
|
3
|
+
// - 浏览器面(本文件,可进浏览器包,不 import 任何 node 内置模块):交出基础组件 / 数据组件 / 应用组件与具名动作表;
|
|
4
|
+
// - 服务端面(./server,惰性 import):扫描 kit.app.yaml 与 pages/*.kit.yaml,五步编译,owner 'soma-kit' 按 URL 注册进 core;
|
|
5
|
+
// 失败(任何诊断)即拒绝启动。
|
|
6
|
+
// 应用组件、业务组件、页面框重名必须显式点名,不静默覆盖。
|
|
7
|
+
|
|
8
|
+
import type {
|
|
9
|
+
SomaAuthOption,
|
|
10
|
+
SomaComponentDefinition,
|
|
11
|
+
SomaEventMiddlewareContext,
|
|
12
|
+
SomaMiddlewareChain,
|
|
13
|
+
SomaRenderPorts,
|
|
14
|
+
} from 'soma-core';
|
|
15
|
+
import { createKitNotifyRenderer } from './notify-renderer';
|
|
16
|
+
import type { SomaHostAssembly } from 'soma-core/server/host-assembly';
|
|
17
|
+
import { createKitBaseComponents, KIT_BASE_COMPONENTS } from '../base/index';
|
|
18
|
+
import { bizDataComponents, KIT_BIZ_DATA_COMPONENTS } from '../biz/data-components';
|
|
19
|
+
import { KIT_BIZ_COMPONENT_NAMES, KIT_FRAME_NAMES } from '../biz/names';
|
|
20
|
+
import type { KitBizDefinition } from '../biz/types';
|
|
21
|
+
import type { KitThemeConfig } from '../theme/theme-tokens';
|
|
22
|
+
import { KitPackError, type KitPack } from './define-kit-pack';
|
|
23
|
+
import type { KitDiagnostic } from '../object-renderer/types';
|
|
24
|
+
import { createKitResidentDataComponents } from '../data/resident';
|
|
25
|
+
import { addWrappedOwnCandidates } from '../data/wrapped-candidates';
|
|
26
|
+
import { KIT_STATIC_BUILTIN_LAZY_NAMES as KIT_STATIC_BUILTIN_NAMES, KIT_STATIC_LAZY_LOADERS } from '../data/static-lazy';
|
|
27
|
+
import type { KitFrameDefinition } from '../frames/types';
|
|
28
|
+
import type { KitNamedAction } from './define-kit-actions';
|
|
29
|
+
import type { KitServerFace } from './server';
|
|
30
|
+
|
|
31
|
+
type ComponentInput = SomaComponentDefinition | (() => SomaComponentDefinition);
|
|
32
|
+
|
|
33
|
+
/** 写死形状数据组件的代码登记:只给定义(accept 取 kit.app.yaml),或同时给 accept */
|
|
34
|
+
export type KitStaticComponentInput =
|
|
35
|
+
| ComponentInput
|
|
36
|
+
| { define: ComponentInput; accept: 'single' | 'list'; desc?: string };
|
|
37
|
+
|
|
38
|
+
export interface DefineKitAppOptions {
|
|
39
|
+
/** kit.app.yaml 相对应用根的路径;缺省 'kit.app.yaml',文件不存在视为空配置 */
|
|
40
|
+
app?: string;
|
|
41
|
+
/** 应用根;缺省取环境变量 SOMA_HOST_DIR,再缺省 process.cwd() */
|
|
42
|
+
root?: string;
|
|
43
|
+
/** 页面目录相对应用根;缺省 'pages' */
|
|
44
|
+
pagesDir?: string;
|
|
45
|
+
/**
|
|
46
|
+
* 额外的页面目录(绝对路径,或相对应用根),与主 pagesDir 一起扫描、一起编译;
|
|
47
|
+
* 不同目录里的页面 URL 重复报 KIT-PAGE-004。目录不存在视为空。
|
|
48
|
+
*/
|
|
49
|
+
extraPagesDirs?: string[];
|
|
50
|
+
/** kit.app.yaml 没写 `theme` 时使用的主题(写了 `theme` 则完全以 yaml 为准,不做字段级合并) */
|
|
51
|
+
defaultTheme?: KitThemeConfig;
|
|
52
|
+
/**
|
|
53
|
+
* 领域包(`defineKitPack` 的返回值,如 soma-kit/packs/commerce 的 commercePack)。
|
|
54
|
+
* 装配时把包内的数据组件、业务组件、协作数据组件与候选类并入;重名报 KIT-PACK-002。
|
|
55
|
+
*/
|
|
56
|
+
packs?: readonly KitPack[];
|
|
57
|
+
/** 应用扩展的基础组件(名字以 App 开头) */
|
|
58
|
+
baseComponents?: Record<string, ComponentInput>;
|
|
59
|
+
/** 应用扩展的写死形状数据组件(名字以 App 开头;accept 登记在 kit.app.yaml) */
|
|
60
|
+
staticObjectComponents?: Record<string, KitStaticComponentInput>;
|
|
61
|
+
/** defineKitActions 的返回值 */
|
|
62
|
+
actions?: Record<string, KitNamedAction>;
|
|
63
|
+
/** 应用扩展的业务组件 / 页面框;与内置同名必须在 overrides 点名 */
|
|
64
|
+
bizComponents?: Record<string, KitBizDefinition>;
|
|
65
|
+
frames?: Record<string, KitFrameDefinition>;
|
|
66
|
+
overrides?: readonly string[];
|
|
67
|
+
/** 应用组件里写死的 Tailwind 类(样式引擎扫不到组件控制器里的类串,由应用交入) */
|
|
68
|
+
appCandidates?: readonly string[];
|
|
69
|
+
/** 浏览器引导信息 */
|
|
70
|
+
appName?: string;
|
|
71
|
+
title?: string;
|
|
72
|
+
locales?: string[];
|
|
73
|
+
defaultLocale?: string;
|
|
74
|
+
/** 角色集来源(core `auth`):原样交给浏览器引导,供 `permission:` 判定 */
|
|
75
|
+
auth?: SomaAuthOption;
|
|
76
|
+
/** 事件中间件链(core `eventMiddleware`):原样交给浏览器引导 */
|
|
77
|
+
eventMiddleware?: SomaMiddlewareChain<SomaEventMiddlewareContext>;
|
|
78
|
+
/** 渲染端口;缺省 `{ notify: kit 最小通知端口 }`,给了就整体替换(要关掉通知给 `{}`) */
|
|
79
|
+
renderPorts?: SomaRenderPorts;
|
|
80
|
+
/** Host 装配的其余可选面,原样透传 */
|
|
81
|
+
services?: SomaHostAssembly['services'];
|
|
82
|
+
identity?: SomaHostAssembly['identity'];
|
|
83
|
+
defaultAccess?: SomaHostAssembly['defaultAccess'];
|
|
84
|
+
pageGrants?: SomaHostAssembly['pageGrants'];
|
|
85
|
+
requestHook?: SomaHostAssembly['requestHook'];
|
|
86
|
+
reservedRoutes?: readonly string[];
|
|
87
|
+
login?: { path?: string };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** 装配后的应用登记(server 面按它建编译上下文) */
|
|
91
|
+
export interface KitAppRegistry {
|
|
92
|
+
baseComponents: Record<string, SomaComponentDefinition>;
|
|
93
|
+
staticComponents: Record<string, { definition: SomaComponentDefinition; accept?: 'single' | 'list' }>;
|
|
94
|
+
actions: Record<string, KitNamedAction>;
|
|
95
|
+
bizComponents: Record<string, KitBizDefinition>;
|
|
96
|
+
frames: Record<string, KitFrameDefinition>;
|
|
97
|
+
appCandidates: readonly string[];
|
|
98
|
+
/** 领域包的协作数据组件(已实例化,并入浏览器组件表;页面不可直接选用) */
|
|
99
|
+
packDataComponents: Record<string, SomaComponentDefinition>;
|
|
100
|
+
/** 已登记的领域包名 */
|
|
101
|
+
packNames: readonly string[];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface KitBrowserMount {
|
|
105
|
+
/** 全部组件:基础 13 + 应用基础 + KitObjectForm / KitTableActions / Tree / StatGroup / Pager + 应用数据组件 */
|
|
106
|
+
components: Record<string, SomaComponentDefinition>;
|
|
107
|
+
/** 内置写死形状数据组件(Tree / Chart / Timeline 等)的按需加载工厂:core 只补载本页引用到的,打包器按动态 import 分片 */
|
|
108
|
+
lazyComponents: Record<string, () => Promise<SomaComponentDefinition>>;
|
|
109
|
+
actions: Record<string, KitNamedAction>;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface KitApp {
|
|
113
|
+
readonly kind: 'soma-app';
|
|
114
|
+
readonly host: SomaHostAssembly;
|
|
115
|
+
/** 应用登记(只读,测试与 server 面用) */
|
|
116
|
+
readonly registry: KitAppRegistry;
|
|
117
|
+
readonly options: DefineKitAppOptions;
|
|
118
|
+
/** 服务端面:装配 + 编译 + 注册;同一应用只装配一次,失败原样上抛 */
|
|
119
|
+
server(): Promise<KitServerFace>;
|
|
120
|
+
browserMount(): KitBrowserMount;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const APP_NAME = /^App[A-Z][A-Za-z0-9]*$/;
|
|
124
|
+
const ACTION_NAME = /^[a-z][a-zA-Z0-9_]*$/;
|
|
125
|
+
|
|
126
|
+
function instantiate(name: string, input: ComponentInput): SomaComponentDefinition {
|
|
127
|
+
const def = typeof input === 'function' ? input() : input;
|
|
128
|
+
if (def === null || typeof def !== 'object' || (def as { contract?: unknown }).contract === undefined) {
|
|
129
|
+
throw new Error(`[soma-kit] 应用组件 ${name} 不是组件定义(需 defineComponent 的返回值或返回它的函数)`);
|
|
130
|
+
}
|
|
131
|
+
if (def.contract.name !== name) {
|
|
132
|
+
throw new Error(`[soma-kit] 应用组件登记名 "${name}" 与契约名 "${def.contract.name}" 不一致`);
|
|
133
|
+
}
|
|
134
|
+
return def;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** `{ define, accept }` 登记形:define 可以是定义对象,也可以是返回定义的函数 */
|
|
138
|
+
function isSpec(v: KitStaticComponentInput): v is { define: ComponentInput; accept: 'single' | 'list'; desc?: string } {
|
|
139
|
+
if (typeof v !== 'object' || v === null || (v as { contract?: unknown }).contract !== undefined) return false;
|
|
140
|
+
const d = (v as { define?: unknown }).define;
|
|
141
|
+
return typeof d === 'function' || (typeof d === 'object' && d !== null);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** 校验并规整应用登记;任何冲突当场抛(装配期失败,不拖到运行期) */
|
|
145
|
+
export function buildAppRegistry(options: DefineKitAppOptions): KitAppRegistry {
|
|
146
|
+
const allow = new Set(options.overrides ?? []);
|
|
147
|
+
const builtinBase = new Set<string>(Object.keys(KIT_BASE_COMPONENTS));
|
|
148
|
+
const baseComponents: KitAppRegistry['baseComponents'] = {};
|
|
149
|
+
for (const [name, input] of Object.entries(options.baseComponents ?? {})) {
|
|
150
|
+
if (!APP_NAME.test(name)) throw new Error(`[soma-kit] 应用基础组件名必须以 App 开头(如 AppCopyCode),收到 "${name}"`);
|
|
151
|
+
if (builtinBase.has(name) && !allow.has(name)) throw new Error(`[soma-kit] 基础组件 "${name}" 已内置;要覆盖请在 overrides 点名`);
|
|
152
|
+
const def = instantiate(name, input);
|
|
153
|
+
if (def.contract['layer'] !== 'basic') throw new Error(`[soma-kit] 应用基础组件 ${name} 的契约 layer 必须是 basic`);
|
|
154
|
+
baseComponents[name] = def;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const staticComponents: KitAppRegistry['staticComponents'] = {};
|
|
158
|
+
for (const [name, input] of Object.entries(options.staticObjectComponents ?? {})) {
|
|
159
|
+
if (!APP_NAME.test(name)) throw new Error(`[soma-kit] 应用数据组件名必须以 App 开头(如 AppLogisticsTrack),收到 "${name}"`);
|
|
160
|
+
if (KIT_STATIC_BUILTIN_NAMES.includes(name) && !allow.has(name)) {
|
|
161
|
+
throw new Error(`[soma-kit] 写死形状组件 "${name}" 已内置;要覆盖请在 overrides 点名`);
|
|
162
|
+
}
|
|
163
|
+
if (name in baseComponents) throw new Error(`[soma-kit] "${name}" 同时登记为基础组件与数据组件`);
|
|
164
|
+
const spec = isSpec(input);
|
|
165
|
+
const def = instantiate(name, spec ? input.define : input);
|
|
166
|
+
if (def.contract['layer'] !== 'data') throw new Error(`[soma-kit] 应用数据组件 ${name} 的契约 layer 必须是 data`);
|
|
167
|
+
staticComponents[name] = spec ? { definition: def, accept: input.accept } : { definition: def };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const actions: Record<string, KitNamedAction> = {};
|
|
171
|
+
for (const [name, fn] of Object.entries(options.actions ?? {})) {
|
|
172
|
+
if (!ACTION_NAME.test(name)) throw new Error(`[soma-kit] 具名动作名不合法:"${name}"`);
|
|
173
|
+
if (typeof fn !== 'function') throw new Error(`[soma-kit] 具名动作 "${name}" 不是函数(用 defineKitActions 包装)`);
|
|
174
|
+
actions[name] = fn;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// 业务组件 / 页面框与内置同名:必须在 overrides 点名,不静默覆盖;登记名必须等于定义的 kind
|
|
178
|
+
for (const [name, def] of Object.entries(options.bizComponents ?? {})) {
|
|
179
|
+
if (def === null || typeof def !== 'object' || def.kind !== name) throw new Error(`[soma-kit] 业务组件登记名 "${name}" 与定义的 kind 不一致`);
|
|
180
|
+
if (KIT_BIZ_COMPONENT_NAMES.includes(name) && !allow.has(name)) {
|
|
181
|
+
throw new Error(`[soma-kit] 业务组件 "${name}" 已内置;要覆盖请在 overrides 点名`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
for (const [name, def] of Object.entries(options.frames ?? {})) {
|
|
185
|
+
if (def === null || typeof def !== 'object' || def.kind !== name) throw new Error(`[soma-kit] 页面框登记名 "${name}" 与定义的 kind 不一致`);
|
|
186
|
+
if (KIT_FRAME_NAMES.includes(name) && !allow.has(name)) {
|
|
187
|
+
throw new Error(`[soma-kit] 页面框 "${name}" 已内置;要覆盖请在 overrides 点名`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const bizComponents: Record<string, KitBizDefinition> = { ...(options.bizComponents ?? {}) };
|
|
191
|
+
const packDataComponents: Record<string, SomaComponentDefinition> = {};
|
|
192
|
+
const candidates = new Set<string>(options.appCandidates ?? []);
|
|
193
|
+
const packNames: string[] = [];
|
|
194
|
+
mergePacks(options.packs ?? [], { baseComponents, staticComponents, bizComponents, packDataComponents, candidates, packNames });
|
|
195
|
+
|
|
196
|
+
return {
|
|
197
|
+
baseComponents,
|
|
198
|
+
staticComponents,
|
|
199
|
+
actions,
|
|
200
|
+
bizComponents,
|
|
201
|
+
frames: { ...(options.frames ?? {}) },
|
|
202
|
+
appCandidates: options.packs !== undefined && options.packs.length > 0 ? [...candidates] : (options.appCandidates ?? []),
|
|
203
|
+
packDataComponents,
|
|
204
|
+
packNames,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
interface PackMergeTarget {
|
|
209
|
+
baseComponents: KitAppRegistry['baseComponents'];
|
|
210
|
+
staticComponents: KitAppRegistry['staticComponents'];
|
|
211
|
+
bizComponents: Record<string, KitBizDefinition>;
|
|
212
|
+
packDataComponents: Record<string, SomaComponentDefinition>;
|
|
213
|
+
candidates: Set<string>;
|
|
214
|
+
packNames: string[];
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* 领域包合并(只在这里做一次):组件表、业务组件表、协作数据组件、候选类。
|
|
219
|
+
* 重名一律报诊断(KIT-PACK-002),包重复登记报 KIT-PACK-003,不静默覆盖,不看 overrides。
|
|
220
|
+
*/
|
|
221
|
+
function mergePacks(packs: readonly KitPack[], t: PackMergeTarget): void {
|
|
222
|
+
if (packs.length === 0) return;
|
|
223
|
+
const diagnostics: KitDiagnostic[] = [];
|
|
224
|
+
// 名字 -> 先占用者说明;基础、内置数据、内置业务、协作件、应用自己的登记先占位
|
|
225
|
+
const taken = new Map<string, string>();
|
|
226
|
+
for (const n of Object.keys(KIT_BASE_COMPONENTS)) taken.set(n, '内置基础组件');
|
|
227
|
+
for (const n of KIT_STATIC_BUILTIN_NAMES) taken.set(n, '内置数据组件');
|
|
228
|
+
for (const n of KIT_BIZ_COMPONENT_NAMES) taken.set(n, '内置业务组件');
|
|
229
|
+
for (const n of Object.keys(KIT_BIZ_DATA_COMPONENTS)) taken.set(n, '内置协作数据组件');
|
|
230
|
+
for (const n of Object.keys(t.baseComponents)) taken.set(n, '应用基础组件');
|
|
231
|
+
for (const n of Object.keys(t.staticComponents)) taken.set(n, '应用数据组件');
|
|
232
|
+
for (const n of Object.keys(t.bizComponents)) taken.set(n, '应用业务组件');
|
|
233
|
+
|
|
234
|
+
const claim = (name: string, path: string, who: string): boolean => {
|
|
235
|
+
const prev = taken.get(name);
|
|
236
|
+
if (prev !== undefined) {
|
|
237
|
+
diagnostics.push({ code: 'KIT-PACK-002', path, message: `组件名 ${name} 已被${prev}占用,领域包不静默覆盖` });
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
taken.set(name, who);
|
|
241
|
+
return true;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
const seenPacks = new Set<string>();
|
|
245
|
+
for (const pack of packs) {
|
|
246
|
+
if (pack === null || typeof pack !== 'object' || pack.kind !== 'soma-kit-pack') {
|
|
247
|
+
diagnostics.push({ code: 'KIT-PACK-001', path: 'packs', message: 'packs 里的项必须是 defineKitPack 的返回值' });
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
if (seenPacks.has(pack.name)) {
|
|
251
|
+
diagnostics.push({ code: 'KIT-PACK-003', path: `pack.${pack.name}`, message: `领域包 ${pack.name} 登记了两次` });
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
seenPacks.add(pack.name);
|
|
255
|
+
t.packNames.push(pack.name);
|
|
256
|
+
const who = `领域包 ${pack.name}`;
|
|
257
|
+
|
|
258
|
+
for (const [name, spec] of Object.entries(pack.staticComponents)) {
|
|
259
|
+
const path = `pack.${pack.name}.staticComponents.${name}`;
|
|
260
|
+
if (!claim(name, path, who)) continue;
|
|
261
|
+
const def = instantiate(name, spec.define);
|
|
262
|
+
if (def.contract['layer'] !== 'data') {
|
|
263
|
+
diagnostics.push({ code: 'KIT-PACK-001', path, message: `领域包数据组件 ${name} 的契约 layer 必须是 data` });
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
t.staticComponents[name] = { definition: def, accept: spec.accept };
|
|
267
|
+
}
|
|
268
|
+
for (const [name, def] of Object.entries(pack.bizComponents)) {
|
|
269
|
+
if (!claim(name, `pack.${pack.name}.bizComponents.${name}`, who)) continue;
|
|
270
|
+
t.bizComponents[name] = def;
|
|
271
|
+
}
|
|
272
|
+
for (const [name, make] of Object.entries(pack.dataComponents)) {
|
|
273
|
+
const path = `pack.${pack.name}.dataComponents.${name}`;
|
|
274
|
+
if (!claim(name, path, who)) continue;
|
|
275
|
+
const def = instantiate(name, make);
|
|
276
|
+
if (def.contract['layer'] !== 'data') {
|
|
277
|
+
diagnostics.push({ code: 'KIT-PACK-001', path, message: `领域包协作数据组件 ${name} 的契约 layer 必须是 data` });
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
t.packDataComponents[name] = def;
|
|
281
|
+
}
|
|
282
|
+
for (const c of pack.candidates) if (c !== '') t.candidates.add(c);
|
|
283
|
+
// 按组件登记的类挂在组件定义上:页面用到该组件才并入
|
|
284
|
+
for (const [name, list] of Object.entries(pack.componentCandidates ?? {})) {
|
|
285
|
+
const def = t.staticComponents[name]?.definition ?? t.packDataComponents[name];
|
|
286
|
+
if (def !== undefined) addWrappedOwnCandidates(def, list);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (diagnostics.length > 0) throw new KitPackError(diagnostics);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** 浏览器面:组件表 = 基础(内置 + 应用)+ 数据(内置 + 应用) */
|
|
293
|
+
export function buildBrowserMount(registry: KitAppRegistry): KitBrowserMount {
|
|
294
|
+
const base: Record<string, SomaComponentDefinition> = { ...createKitBaseComponents(), ...registry.baseComponents };
|
|
295
|
+
const data = createKitResidentDataComponents(base);
|
|
296
|
+
// 业务组件壳依赖的协作数据组件(KitCrudBridge 等)与内置数据组件同表;内置名不与应用名冲突(应用名须 App 开头)
|
|
297
|
+
const components: Record<string, SomaComponentDefinition> = { ...base, ...data, ...bizDataComponents() };
|
|
298
|
+
for (const [name, entry] of Object.entries(registry.staticComponents)) components[name] = entry.definition;
|
|
299
|
+
for (const [name, def] of Object.entries(registry.packDataComponents)) components[name] = def;
|
|
300
|
+
// 应用登记项同名覆盖内置时,常驻表优先(core 以 components 为准),不再按需加载内置版
|
|
301
|
+
return { components, lazyComponents: { ...KIT_STATIC_LAZY_LOADERS }, actions: { ...registry.actions } };
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const TREE_CONTEXT = {
|
|
305
|
+
registrySnapshot: { components: {}, digest: 'soma-kit-registry-snapshot-v1' },
|
|
306
|
+
compositionPolicy: { policyId: 'soma-kit-tree-policy-v1', version: '1.0.0', roots: ['SomaLocaleOnlyPageRoot'] },
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
export function defineKitApp(options: DefineKitAppOptions = {}): KitApp {
|
|
310
|
+
const registry = buildAppRegistry(options);
|
|
311
|
+
let mount: KitBrowserMount | undefined;
|
|
312
|
+
const browserMount = (): KitBrowserMount => (mount ??= buildBrowserMount(registry));
|
|
313
|
+
let renderPorts: SomaRenderPorts | undefined;
|
|
314
|
+
|
|
315
|
+
// 服务端面按变量说明符惰性 import:浏览器打包器不跟进服务端入口(它含 node:fs 与服务端样式引擎)
|
|
316
|
+
type ServerModule = typeof import('./server');
|
|
317
|
+
const SERVER_ENTRY = 'soma-kit/app/server';
|
|
318
|
+
let serverFace: Promise<Awaited<ReturnType<ServerModule['assembleKitServer']>>> | undefined;
|
|
319
|
+
const server = (): Promise<Awaited<ReturnType<ServerModule['assembleKitServer']>>> => {
|
|
320
|
+
const specifier = SERVER_ENTRY;
|
|
321
|
+
const preloaded = (globalThis as Record<symbol, unknown>)[Symbol.for('soma-kit.serverModule')] as ServerModule | undefined;
|
|
322
|
+
serverFace ??= (preloaded !== undefined
|
|
323
|
+
? Promise.resolve(preloaded)
|
|
324
|
+
: (import(/* webpackIgnore: true */ /* @vite-ignore */ specifier) as Promise<ServerModule>)
|
|
325
|
+
).then((m) => m.assembleKitServer(options, registry));
|
|
326
|
+
return serverFace;
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
const host: SomaHostAssembly = {
|
|
330
|
+
kind: 'soma-host',
|
|
331
|
+
...(options.reservedRoutes !== undefined ? { reservedRoutes: options.reservedRoutes } : {}),
|
|
332
|
+
...(options.login !== undefined ? { login: options.login } : {}),
|
|
333
|
+
bootstrap() {
|
|
334
|
+
const m = browserMount();
|
|
335
|
+
return {
|
|
336
|
+
...(options.appName !== undefined ? { appName: options.appName } : {}),
|
|
337
|
+
...(options.title !== undefined ? { title: options.title } : {}),
|
|
338
|
+
...(options.locales !== undefined ? { locales: options.locales } : {}),
|
|
339
|
+
...(options.defaultLocale !== undefined ? { defaultLocale: options.defaultLocale } : {}),
|
|
340
|
+
components: m.components,
|
|
341
|
+
lazyComponents: m.lazyComponents,
|
|
342
|
+
actions: m.actions,
|
|
343
|
+
...(options.auth !== undefined ? { auth: options.auth } : {}),
|
|
344
|
+
...(options.eventMiddleware !== undefined ? { eventMiddleware: options.eventMiddleware } : {}),
|
|
345
|
+
renderPorts: (renderPorts ??= options.renderPorts ?? { notify: createKitNotifyRenderer() }),
|
|
346
|
+
};
|
|
347
|
+
},
|
|
348
|
+
services: options.services ?? (() => ({ kind: 'table', routes: {} })),
|
|
349
|
+
virtualPages: () => [],
|
|
350
|
+
treeContext: () => TREE_CONTEXT as unknown as ReturnType<SomaHostAssembly['treeContext']>,
|
|
351
|
+
...(options.identity !== undefined ? { identity: options.identity } : {}),
|
|
352
|
+
...(options.defaultAccess !== undefined ? { defaultAccess: options.defaultAccess } : {}),
|
|
353
|
+
...(options.pageGrants !== undefined ? { pageGrants: options.pageGrants } : {}),
|
|
354
|
+
...(options.requestHook !== undefined ? { requestHook: options.requestHook } : {}),
|
|
355
|
+
async prewarm() {
|
|
356
|
+
const face = await server();
|
|
357
|
+
await face.prewarm();
|
|
358
|
+
},
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
return { kind: 'soma-app', host, registry, options, server, browserMount };
|
|
362
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// defineKitPack:领域包(规格 2.1a 第 ③ 档「领域包」与第 ④ 档「领域流程」)的登记入口。
|
|
2
|
+
//
|
|
3
|
+
// 一个包 = 名字 + 写死形状数据组件 + 业务组件 + 包私有的协作数据组件 + 候选类。
|
|
4
|
+
// 应用在 `defineKitApp({ packs: [commercePack] })` 登记;合并只在 buildAppRegistry 里做一次(浏览器端与服务端同源)。
|
|
5
|
+
// 包内组件不走应用组件的 `App` 前缀检查,改走包内前缀:组件名必须以「包名首字母大写」开头(commerce -> Commerce*)。
|
|
6
|
+
// 重名(与内置、与别的包、与应用自己的登记)报诊断 KIT-PACK-002,不静默覆盖;包形状不合法报 KIT-PACK-001;同名包登记两次报 KIT-PACK-003。
|
|
7
|
+
|
|
8
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
9
|
+
import type { KitBizDefinition } from '../biz/types';
|
|
10
|
+
import type { KitDiagnostic } from '../object-renderer/types';
|
|
11
|
+
|
|
12
|
+
export interface KitPackStaticComponent {
|
|
13
|
+
define: () => SomaComponentDefinition;
|
|
14
|
+
accept: 'single' | 'list';
|
|
15
|
+
desc?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface KitPackInput {
|
|
19
|
+
/** 包名:小写字母数字(commerce / finance),决定组件名前缀 */
|
|
20
|
+
name: string;
|
|
21
|
+
/** 写死形状数据组件(页面 `view.staticComponent` 可选用) */
|
|
22
|
+
staticComponents?: Record<string, KitPackStaticComponent>;
|
|
23
|
+
/** 业务组件(页面 `product.kind` 可选用) */
|
|
24
|
+
bizComponents?: Record<string, KitBizDefinition>;
|
|
25
|
+
/** 包私有的协作数据组件(业务组件壳依赖,页面不可直接选用;layer 必须是 data) */
|
|
26
|
+
dataComponents?: Record<string, () => SomaComponentDefinition>;
|
|
27
|
+
/** 包内控制器里写死的 Tailwind 类(样式引擎扫不到控制器里的类串,由包交入) */
|
|
28
|
+
candidates?: readonly string[];
|
|
29
|
+
/**
|
|
30
|
+
* 按组件登记的写死类(组件名必须是本包的数据组件 / 协作数据组件):页面只用到该组件时才并入,不再整包并入每页。
|
|
31
|
+
* 业务组件的类请写进它编出的片段候选类。包一层内置件的数据组件,底层类已随包装元数据自动并入,不必再列。
|
|
32
|
+
*/
|
|
33
|
+
componentCandidates?: Readonly<Record<string, readonly string[]>>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface KitPack {
|
|
37
|
+
readonly kind: 'soma-kit-pack';
|
|
38
|
+
readonly name: string;
|
|
39
|
+
/** 组件名前缀(包名首字母大写) */
|
|
40
|
+
readonly prefix: string;
|
|
41
|
+
readonly staticComponents: Readonly<Record<string, KitPackStaticComponent>>;
|
|
42
|
+
readonly bizComponents: Readonly<Record<string, KitBizDefinition>>;
|
|
43
|
+
readonly dataComponents: Readonly<Record<string, () => SomaComponentDefinition>>;
|
|
44
|
+
readonly candidates: readonly string[];
|
|
45
|
+
readonly componentCandidates: Readonly<Record<string, readonly string[]>>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** 领域包诊断错误:带 KIT-PACK-* 诊断列表 */
|
|
49
|
+
export class KitPackError extends Error {
|
|
50
|
+
readonly diagnostics: KitDiagnostic[];
|
|
51
|
+
constructor(diagnostics: KitDiagnostic[]) {
|
|
52
|
+
super(`[soma-kit] 领域包登记失败\n${diagnostics.map((d) => ` [${d.code}] ${d.path}:${d.message}`).join('\n')}`);
|
|
53
|
+
this.name = 'KitPackError';
|
|
54
|
+
this.diagnostics = diagnostics;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const PACK_NAME = /^[a-z][a-z0-9]*$/;
|
|
59
|
+
|
|
60
|
+
export function packPrefix(name: string): string {
|
|
61
|
+
return name.charAt(0).toUpperCase() + name.slice(1);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function prefixed(prefix: string, name: string): boolean {
|
|
65
|
+
return name.startsWith(prefix) && name.length > prefix.length && /[A-Z]/.test(name.charAt(prefix.length));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function defineKitPack(input: KitPackInput): KitPack {
|
|
69
|
+
const diagnostics: KitDiagnostic[] = [];
|
|
70
|
+
const bad = (path: string, message: string): void => { diagnostics.push({ code: 'KIT-PACK-001', path, message }); };
|
|
71
|
+
if (typeof input.name !== 'string' || !PACK_NAME.test(input.name)) {
|
|
72
|
+
throw new KitPackError([{ code: 'KIT-PACK-001', path: 'name', message: `包名必须是小写字母数字且以字母开头(如 commerce),收到 "${String(input.name)}"` }]);
|
|
73
|
+
}
|
|
74
|
+
const prefix = packPrefix(input.name);
|
|
75
|
+
const where = `pack.${input.name}`;
|
|
76
|
+
const staticComponents = { ...(input.staticComponents ?? {}) };
|
|
77
|
+
const bizComponents = { ...(input.bizComponents ?? {}) };
|
|
78
|
+
const dataComponents = { ...(input.dataComponents ?? {}) };
|
|
79
|
+
|
|
80
|
+
for (const [name, spec] of Object.entries(staticComponents)) {
|
|
81
|
+
if (!prefixed(prefix, name)) bad(`${where}.staticComponents.${name}`, `组件名必须以 ${prefix} 开头(后接大写字母)`);
|
|
82
|
+
if (spec === null || typeof spec !== 'object' || typeof spec.define !== 'function') bad(`${where}.staticComponents.${name}`, '需要 { define, accept }');
|
|
83
|
+
else if (spec.accept !== 'single' && spec.accept !== 'list') bad(`${where}.staticComponents.${name}.accept`, 'accept 只能是 single / list');
|
|
84
|
+
}
|
|
85
|
+
for (const [name, def] of Object.entries(bizComponents)) {
|
|
86
|
+
if (!prefixed(prefix, name)) bad(`${where}.bizComponents.${name}`, `业务组件名必须以 ${prefix} 开头(后接大写字母)`);
|
|
87
|
+
if (def === null || typeof def !== 'object' || def.kind !== name) bad(`${where}.bizComponents.${name}`, `登记名与定义的 kind(${String((def as { kind?: unknown } | null)?.kind)})不一致,需用 defineKitBizComponent 定义`);
|
|
88
|
+
}
|
|
89
|
+
for (const [name, make] of Object.entries(dataComponents)) {
|
|
90
|
+
if (!prefixed(prefix, name)) bad(`${where}.dataComponents.${name}`, `协作数据组件名必须以 ${prefix} 开头(后接大写字母)`);
|
|
91
|
+
if (typeof make !== 'function') bad(`${where}.dataComponents.${name}`, '需要返回组件定义的函数');
|
|
92
|
+
}
|
|
93
|
+
const seen = new Set<string>();
|
|
94
|
+
for (const name of [...Object.keys(staticComponents), ...Object.keys(dataComponents)]) {
|
|
95
|
+
if (seen.has(name)) bad(`${where}.${name}`, `组件名 ${name} 在包内同时登记为数据组件与协作数据组件`);
|
|
96
|
+
seen.add(name);
|
|
97
|
+
}
|
|
98
|
+
const componentCandidates = { ...(input.componentCandidates ?? {}) };
|
|
99
|
+
for (const name of Object.keys(componentCandidates)) {
|
|
100
|
+
if (!(name in staticComponents) && !(name in dataComponents)) bad(`${where}.componentCandidates.${name}`, '按组件登记候选类的组件必须是本包的数据组件或协作数据组件');
|
|
101
|
+
}
|
|
102
|
+
if (diagnostics.length > 0) throw new KitPackError(diagnostics);
|
|
103
|
+
|
|
104
|
+
return Object.freeze({
|
|
105
|
+
componentCandidates: Object.freeze(componentCandidates),
|
|
106
|
+
kind: 'soma-kit-pack' as const,
|
|
107
|
+
name: input.name,
|
|
108
|
+
prefix,
|
|
109
|
+
staticComponents: Object.freeze(staticComponents),
|
|
110
|
+
bizComponents: Object.freeze(bizComponents),
|
|
111
|
+
dataComponents: Object.freeze(dataComponents),
|
|
112
|
+
candidates: Object.freeze([...(input.candidates ?? [])]),
|
|
113
|
+
});
|
|
114
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// 业务信封约定:应用在 kit.app.yaml 声明一次(页面 page.envelope 可覆写),kit 里所有读响应的地方读这一份,
|
|
2
|
+
// 不再各写各的「success:false / ret≠0」。
|
|
3
|
+
//
|
|
4
|
+
// envelope:
|
|
5
|
+
// failWhen: { field: success, op: eq, value: false } # 闭集谓词(复用 core 的 {field, op, value} 与 all_of / any_of),命中 = 业务失败
|
|
6
|
+
// messagePath: message # 失败时业务文案在响应里的点路径
|
|
7
|
+
// dataPath: data # 成功时数据在响应里的点路径(缺省不拆)
|
|
8
|
+
//
|
|
9
|
+
// 编译时:失败判定编进 core 的 `failWhen / messagePath`(写通道与取数来源),业务失败 -> 写入结果 failed。
|
|
10
|
+
// 运行时:详情预取、分页适配等 kit 自己读响应的地方用本文件的纯函数。
|
|
11
|
+
|
|
12
|
+
import { evaluatePredicate, validatePredicate, collectPredicateFields } from 'soma-core/predicates';
|
|
13
|
+
import type { KitDiagnostic } from '../object-renderer/types';
|
|
14
|
+
|
|
15
|
+
type Rec = Record<string, unknown>;
|
|
16
|
+
const isRec = (v: unknown): v is Rec => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
17
|
+
const PATH = /^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*$/;
|
|
18
|
+
const ENVELOPE_KEYS = ['failWhen', 'messagePath', 'dataPath'] as const;
|
|
19
|
+
|
|
20
|
+
/** 规整后的信封约定(可序列化,作为 prop / 编译产物的一部分) */
|
|
21
|
+
export interface KitEnvelope {
|
|
22
|
+
failWhen?: Rec;
|
|
23
|
+
messagePath?: string;
|
|
24
|
+
dataPath?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** 校验并规整;非法记 KIT-APP-001(应用级)或 KIT-PAGE-004(页面级) */
|
|
28
|
+
export function parseKitEnvelope(raw: unknown, at: string, code: 'KIT-APP-001' | 'KIT-PAGE-004', diagnostics: KitDiagnostic[]): KitEnvelope | undefined {
|
|
29
|
+
if (raw === undefined || raw === null) return undefined;
|
|
30
|
+
const bad = (message: string, path = at): undefined => {
|
|
31
|
+
diagnostics.push({ code, path, message });
|
|
32
|
+
return undefined;
|
|
33
|
+
};
|
|
34
|
+
if (!isRec(raw)) return bad('envelope 必须是 { failWhen?, messagePath?, dataPath? }');
|
|
35
|
+
const extra = Object.keys(raw).filter((k) => !(ENVELOPE_KEYS as readonly string[]).includes(k));
|
|
36
|
+
if (extra.length > 0) return bad(`envelope 不认键 ${extra.join(' / ')}(可用:${ENVELOPE_KEYS.join(' / ')})`);
|
|
37
|
+
const out: KitEnvelope = {};
|
|
38
|
+
if (raw.failWhen !== undefined) {
|
|
39
|
+
const problems = validatePredicate(raw.failWhen, collectPredicateFields(raw.failWhen as never), `${at}.failWhen`, {});
|
|
40
|
+
if (!isRec(raw.failWhen) || problems.length > 0) return bad(`envelope.failWhen 不是合法的闭集谓词:${problems.join(';') || '必须是对象'}`, `${at}.failWhen`);
|
|
41
|
+
out.failWhen = raw.failWhen;
|
|
42
|
+
}
|
|
43
|
+
for (const key of ['messagePath', 'dataPath'] as const) {
|
|
44
|
+
const v = raw[key];
|
|
45
|
+
if (v === undefined) continue;
|
|
46
|
+
if (typeof v !== 'string' || !PATH.test(v)) return bad(`envelope.${key} 必须是点路径(如 data.record)`, `${at}.${key}`);
|
|
47
|
+
out[key] = v;
|
|
48
|
+
}
|
|
49
|
+
if (out.messagePath !== undefined && out.failWhen === undefined) return bad('envelope.messagePath 必须与 failWhen 一起声明', `${at}.messagePath`);
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function pathGet(root: unknown, path: string): unknown {
|
|
54
|
+
let cur = root;
|
|
55
|
+
for (const key of path.split('.')) {
|
|
56
|
+
if (!isRec(cur)) return undefined;
|
|
57
|
+
cur = cur[key];
|
|
58
|
+
}
|
|
59
|
+
return cur;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** 响应命中信封失败判定(没有声明 failWhen 一律不判失败) */
|
|
63
|
+
export function isEnvelopeFailure(raw: unknown, env: KitEnvelope | undefined): raw is Rec {
|
|
64
|
+
if (env?.failWhen === undefined || !isRec(raw)) return false;
|
|
65
|
+
return evaluatePredicate(env.failWhen as never, raw);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** 失败信封里的业务文案(messagePath 取到的非空字符串,取不到为空串) */
|
|
69
|
+
export function envelopeMessage(raw: unknown, env: KitEnvelope | undefined): string {
|
|
70
|
+
if (env?.messagePath === undefined) return '';
|
|
71
|
+
const v = pathGet(raw, env.messagePath);
|
|
72
|
+
return typeof v === 'string' ? v.trim() : '';
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export type UnwrappedEnvelope = { ok: true; data: unknown } | { ok: false; error: Rec };
|
|
76
|
+
|
|
77
|
+
/** 拆信封:命中失败 -> { ok:false, error: 原信封 };否则按 dataPath 取数据(没声明 dataPath 不拆) */
|
|
78
|
+
export function unwrapEnvelope(raw: unknown, env: KitEnvelope | undefined): UnwrappedEnvelope {
|
|
79
|
+
if (isEnvelopeFailure(raw, env)) return { ok: false, error: raw };
|
|
80
|
+
if (env?.dataPath === undefined) return { ok: true, data: raw };
|
|
81
|
+
return { ok: true, data: pathGet(raw, env.dataPath) };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// ---------------------------------------------------------------- 当前信封(编译期 / 服务端缺省)
|
|
85
|
+
|
|
86
|
+
let compileEnvelope: KitEnvelope | undefined;
|
|
87
|
+
/** 页面编译期间的有效信封(compile-page 在编译开始设置、结束清掉;编译第 2-3 步是同步的) */
|
|
88
|
+
export function setCompileEnvelope(env: KitEnvelope | undefined): void {
|
|
89
|
+
compileEnvelope = env;
|
|
90
|
+
}
|
|
91
|
+
export function getCompileEnvelope(): KitEnvelope | undefined {
|
|
92
|
+
return compileEnvelope;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
let appEnvelope: KitEnvelope | undefined;
|
|
96
|
+
/** 服务端装配读完 kit.app.yaml 后登记的应用级信封:服务端薄壳(分页适配等)不显式传 envelope 时用它 */
|
|
97
|
+
export function setKitAppEnvelope(env: KitEnvelope | undefined): void {
|
|
98
|
+
appEnvelope = env;
|
|
99
|
+
}
|
|
100
|
+
export function getKitAppEnvelope(): KitEnvelope | undefined {
|
|
101
|
+
return appEnvelope;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** 把有效信封编进一份 core 数据声明(`data:` 段):写通道与取数来源各加 failWhen / messagePath,已自带的不覆盖 */
|
|
105
|
+
export function applyEnvelopeToData(data: Record<string, unknown>, env: KitEnvelope | undefined): void {
|
|
106
|
+
if (env?.failWhen === undefined) return;
|
|
107
|
+
for (const decl of Object.values(data)) {
|
|
108
|
+
if (!isRec(decl)) continue;
|
|
109
|
+
const stamp = (target: Rec): void => {
|
|
110
|
+
if (target.failWhen !== undefined) return;
|
|
111
|
+
target.failWhen = env.failWhen;
|
|
112
|
+
if (env.messagePath !== undefined) target.messagePath = env.messagePath;
|
|
113
|
+
};
|
|
114
|
+
if (isRec(decl.write)) stamp(decl.write);
|
|
115
|
+
if (Array.isArray(decl.from)) for (const source of decl.from) if (isRec(source)) stamp(source);
|
|
116
|
+
}
|
|
117
|
+
}
|
package/src/app/index.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// `soma-kit/app`:浏览器可进的装配入口。服务端面经 defineKitApp 惰性载入,不在这里导出。
|
|
2
|
+
export { defineKitApp, buildAppRegistry, buildBrowserMount } from './define-kit-app';
|
|
3
|
+
export type {
|
|
4
|
+
DefineKitAppOptions,
|
|
5
|
+
KitApp,
|
|
6
|
+
KitAppRegistry,
|
|
7
|
+
KitBrowserMount,
|
|
8
|
+
KitStaticComponentInput,
|
|
9
|
+
} from './define-kit-app';
|
|
10
|
+
export { defineKitPack, KitPackError, packPrefix } from './define-kit-pack';
|
|
11
|
+
export type { KitPack, KitPackInput, KitPackStaticComponent } from './define-kit-pack';
|
|
12
|
+
export { defineKitActions, kitActionHttp, createKitActionHttp } from './define-kit-actions';
|
|
13
|
+
export type { KitActionArgs, KitActionHandler, KitActionHttp, KitNamedAction } from './define-kit-actions';
|
|
14
|
+
export { createPagedListAdapter, unwrapBizEnvelope, isBizFailure, withRowId, cursorPageWindow } from './paged-list-adapter';
|
|
15
|
+
export type { PagedListAdapter, PagedListAdapterOptions, PagedQuery, PagedList, UnwrappedEnvelope, CursorLoader, CursorPageOptions, CursorPageResult } from './paged-list-adapter';
|
|
16
|
+
export { KIT_PLACEHOLDER_URL, KitSubmitError } from './submit.types';
|
|
17
|
+
export type {
|
|
18
|
+
KitPageBindingView,
|
|
19
|
+
KitPageGrant,
|
|
20
|
+
KitPageGrantAccess,
|
|
21
|
+
KitPageSource,
|
|
22
|
+
KitServerPages,
|
|
23
|
+
KitSubmitOptions,
|
|
24
|
+
KitSubmitPersist,
|
|
25
|
+
KitSubmitResult,
|
|
26
|
+
} from './submit.types';
|
|
27
|
+
export { isEnvelopeFailure, envelopeMessage, unwrapEnvelope, parseKitEnvelope, getKitAppEnvelope } from './envelope';
|
|
28
|
+
export type { KitEnvelope } from './envelope';
|
|
29
|
+
export { parseAppConfig } from './app-config';
|
|
30
|
+
export type { KitAppConfig, KitAppTheme } from './app-config';
|
|
31
|
+
export { createKitNotifyRenderer, KIT_NOTIFY_CLASS_CANDIDATES } from './notify-renderer';
|
|
32
|
+
/** 权限集异步加载完成后显式调用:已挂载的带权限码按钮按新权限重判显隐(core 权限服务无变更通知) */
|
|
33
|
+
export { addKitPermissionChecker, kitPermissionAllows, refreshKitPermissionGates, setKitPermissionChecker } from '../base/permission-gate';
|
|
34
|
+
// 应用叠加合并:把叠加应用并入基座应用的选项(登记表重名报错、基座独占面、requestHook 链、pageGrants 并集)与权限并集的点击拦截
|
|
35
|
+
export { composeKitApps, createKitPermissionMiddleware, mergeKitTables } from './compose-apps';
|
|
36
|
+
export type { ComposeKitAppsOptions } from './compose-apps';
|
|
37
|
+
|
|
38
|
+
// 应用自定义业务组件 / 页面框所需的公开类型与函数(K1-4)
|
|
39
|
+
export { defineKitBizComponent } from '../biz/define';
|
|
40
|
+
export { wrapKitBizComponent, composeKitBizComponents } from '../biz/compose';
|
|
41
|
+
export type { WrapBizOptions, WrapBizShellContext, ComposeBizPart, ComposeBizOptions, ComposeBizShellContext } from '../biz/compose';
|
|
42
|
+
export { wrapKitDataComponent, wrapBuiltin, composeKitDataComponents, mapKeys } from '../data/wrap';
|
|
43
|
+
export type { PackProps, WrapDataOptions, WrapOptions, ComposeDataPart, ComposeDataOptions, ComposeEventForward } from '../data/wrap';
|
|
44
|
+
export { mountKitComponent, mountKitSelectField, createKitEmbedBag } from '../data/embed';
|
|
45
|
+
export { declareKitUses } from '../data/wrapped-candidates';
|
|
46
|
+
export type { KitBizContext, KitBizDefinition, KitBizInput, KitBizRole, KitOverlayDecl } from '../biz/types';
|
|
47
|
+
export type { KitFrameDefinition, KitFrameInput, KitPageMeta } from '../frames/types';
|
|
48
|
+
export { emptyFragment, mergeFragments, fragmentFromEmit } from '../compile/fragment';
|
|
49
|
+
export type { KitFragment } from '../compile/fragment';
|
|
50
|
+
export type { KitDiagnostic, KitObject } from '../object-renderer/types';
|