nx-kv 0.69.0 → 0.70.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/CHANGELOG.md +69 -0
- package/README.md +20 -2
- package/package.json +21 -8
- package/packages/plugin-dir-annotate/dist/client/client.js +3 -0
- package/packages/plugin-dir-annotate/dist/client/style.css +2 -0
- package/packages/plugin-dir-annotate/dist/server/index.js +109 -0
- package/packages/plugin-dir-annotate/package.json +31 -0
- package/packages/plugin-dir-annotate/src/client/AnnotatePage.tsx +313 -0
- package/packages/plugin-dir-annotate/src/client/SettingsPage.tsx +116 -0
- package/packages/plugin-dir-annotate/src/client/index.tsx +23 -0
- package/packages/plugin-dir-annotate/src/client/style.css +91 -0
- package/packages/plugin-dir-annotate/src/server/index.ts +43 -0
- package/packages/plugin-dir-annotate/src/server/settings.ts +75 -0
- package/packages/plugin-dir-annotate/tsconfig.client.json +13 -0
- package/packages/plugin-dir-annotate/tsconfig.server.json +16 -0
- package/packages/plugin-dir-annotate/vite.config.ts +33 -0
- package/packages/plugin-sdk/dist/client.d.ts +56 -0
- package/packages/plugin-sdk/dist/client.d.ts.map +1 -0
- package/packages/plugin-sdk/dist/client.js +2 -0
- package/packages/plugin-sdk/dist/client.js.map +1 -0
- package/packages/plugin-sdk/dist/index.d.ts +160 -0
- package/packages/plugin-sdk/dist/index.d.ts.map +1 -0
- package/packages/plugin-sdk/dist/index.js +28 -0
- package/packages/plugin-sdk/dist/index.js.map +1 -0
- package/packages/plugin-sdk/dist/template.d.ts +5 -0
- package/packages/plugin-sdk/dist/template.d.ts.map +1 -0
- package/packages/plugin-sdk/dist/template.js +23 -0
- package/packages/plugin-sdk/dist/template.js.map +1 -0
- package/packages/plugin-sdk/package.json +27 -0
- package/packages/plugin-sdk/src/client.ts +63 -0
- package/packages/plugin-sdk/src/index.ts +183 -0
- package/packages/plugin-sdk/src/template.ts +24 -0
- package/packages/plugin-sdk/tsconfig.json +17 -0
- package/packages/plugin-task-template/dist/client/client.js +9 -0
- package/packages/plugin-task-template/dist/client/style.css +2 -0
- package/packages/plugin-task-template/dist/server/index.js +557 -0
- package/packages/plugin-task-template/package.json +31 -0
- package/packages/plugin-task-template/src/client/EntryForm.tsx +84 -0
- package/packages/plugin-task-template/src/client/EntryRow.tsx +15 -0
- package/packages/plugin-task-template/src/client/ManagePage.tsx +229 -0
- package/packages/plugin-task-template/src/client/index.tsx +28 -0
- package/packages/plugin-task-template/src/client/style.css +67 -0
- package/packages/plugin-task-template/src/server/builtin-body.ts +79 -0
- package/packages/plugin-task-template/src/server/index.ts +141 -0
- package/packages/plugin-task-template/src/server/scope.ts +56 -0
- package/packages/plugin-task-template/src/server/storage.ts +32 -0
- package/packages/plugin-task-template/src/server/templates.ts +317 -0
- package/packages/plugin-task-template/tsconfig.client.json +13 -0
- package/packages/plugin-task-template/tsconfig.server.json +16 -0
- package/packages/plugin-task-template/vite.config.ts +33 -0
- package/src/core/attachmentdb/resources.ts +8 -7
- package/src/core/db/bootstrap.ts +1 -10
- package/src/core/db/import-json/extras.ts +52 -32
- package/src/core/db/migrations/index.ts +10 -0
- package/src/core/db/migrations/v16-data.ts +0 -1
- package/src/core/db/migrations/v18.sql +24 -0
- package/src/core/db/migrations/v19-data.ts +62 -0
- package/src/core/db/migrations/v19.sql +41 -0
- package/src/core/db/migrations/v20-data.ts +71 -0
- package/src/core/db/migrations/v20.sql +6 -0
- package/src/core/db/migrations/v21.sql +7 -0
- package/src/core/db/repo-match.ts +0 -6
- package/src/core/db/verify.ts +4 -1
- package/src/core/db/version.ts +9 -1
- package/src/modules/db/actions/_manifest.generated.ts +3 -0
- package/src/modules/db/actions/db-data.ts +28 -0
- package/src/modules/db/service.ts +139 -0
- package/src/modules/localtask/actions/localtask-add.ts +4 -4
- package/src/modules/localtask/actions/localtask-boardtasks.ts +4 -17
- package/src/modules/localtask/actions/localtask-reopen.ts +1 -1
- package/src/modules/localtask/actions/localtask-tasks.ts +5 -18
- package/src/modules/localtask/infra/repo/tasks.ts +3 -3
- package/src/modules/localtask/infra/repo/topics.ts +8 -45
- package/src/modules/localtask/lifecycle/task-ops.ts +14 -0
- package/src/modules/localtask/lifecycle/task-view.ts +3 -6
- package/src/modules/localtask/lifecycle/topics.ts +16 -5
- package/src/modules/localtask/ops/attach-resource.ts +1 -7
- package/src/modules/plugin/actions/_manifest.generated.ts +47 -0
- package/src/modules/plugin/actions/plugin-context.ts +41 -0
- package/src/modules/plugin/actions/plugin-entries.ts +42 -0
- package/src/modules/plugin/actions/plugin-file.ts +28 -0
- package/src/modules/plugin/actions/plugin-list.ts +30 -0
- package/src/modules/plugin/actions/plugin-rpc.ts +37 -0
- package/src/modules/plugin/actions/plugin-set-default.ts +23 -0
- package/src/modules/plugin/actions/plugin-set-state.ts +26 -0
- package/src/modules/plugin/actions/plugin-set-visibility.ts +42 -0
- package/src/modules/plugin/actions/plugin-tree.ts +31 -0
- package/src/modules/plugin/actions/plugin-visibility.ts +28 -0
- package/src/modules/plugin/actions/pretask-draft.ts +47 -0
- package/src/modules/plugin/assets.ts +51 -0
- package/src/modules/plugin/context.ts +196 -0
- package/src/modules/plugin/fs.ts +169 -0
- package/src/modules/plugin/host.ts +396 -0
- package/src/modules/plugin/index.ts +21 -0
- package/src/modules/plugin/plugins.generated.ts +14 -0
- package/src/modules/plugin/registry.ts +109 -0
- package/src/modules/plugin/repo/db.ts +12 -0
- package/src/modules/plugin/repo/legacy.ts +45 -0
- package/src/modules/plugin/repo/migrations.ts +22 -0
- package/src/modules/plugin/repo/state.ts +32 -0
- package/src/modules/plugin/repo/visibility.ts +94 -0
- package/src/modules/plugin/service.ts +12 -0
- package/src/modules/plugin/template.ts +16 -0
- package/src/modules/repos/actions/_manifest.generated.ts +3 -0
- package/src/modules/repos/actions/repo-dirs.ts +37 -0
- package/src/modules/repos/service/dirs.ts +61 -0
- package/src/runtime/registry.ts +2 -2
- package/src/runtime/server.ts +36 -0
- package/src/shared/task-title.ts +32 -0
- package/src/web/frontend/App.tsx +29 -65
- package/src/web/frontend/api/cli-tree.json +164 -50
- package/src/web/frontend/api/client.generated.ts +160 -61
- package/src/web/frontend/app-context.tsx +0 -3
- package/src/web/frontend/components/layout/crumbs.ts +13 -10
- package/src/web/frontend/components/layout/vsc-crumbs-model.ts +1 -0
- package/src/web/frontend/components/layout/vsc-crumbs.css +15 -0
- package/src/web/frontend/components/layout/vsc-crumbs.tsx +11 -0
- package/src/web/frontend/components/md/attachments/attach-modal.tsx +1 -1
- package/src/web/frontend/components/md/composer/composer-panel.tsx +14 -144
- package/src/web/frontend/components/md/hooks/use-live-preview.ts +1 -1
- package/src/web/frontend/components/md/model/divider/index.ts +0 -3
- package/src/web/frontend/components/md/panes/md-panes-helpers.ts +1 -3
- package/src/web/frontend/components/md/panes/md-panes.tsx +2 -0
- package/src/web/frontend/components/md/pm/pm-editor-host.tsx +35 -0
- package/src/web/frontend/components/md/pm/pm-editor.tsx +209 -0
- package/src/web/frontend/components/md/pm/pm.css +47 -0
- package/src/web/frontend/components/popup/index.tsx +9 -0
- package/src/web/frontend/components/popup/style.css +4 -0
- package/src/web/frontend/components/sidebar/index.tsx +5 -3
- package/src/web/frontend/components/sidebar/ns-dialogs.tsx +2 -2
- package/src/web/frontend/components/sidebar/ns-manage-modal.tsx +75 -17
- package/src/web/frontend/components/sidebar/plugin-foot.tsx +30 -0
- package/src/web/frontend/components/sidebar/queue-nav.ts +15 -10
- package/src/web/frontend/components/sidebar/task-children.tsx +23 -3
- package/src/web/frontend/components/sidebar/use-ns.ts +12 -14
- package/src/web/frontend/components/tool-acts/layout-panel.tsx +2 -8
- package/src/web/frontend/components/tool-acts/style.css +0 -2
- package/src/web/frontend/modules/md/md-parse.ts +1 -1
- package/src/web/frontend/modules/md/pm/adapter.ts +99 -0
- package/src/web/frontend/modules/md/pm/inline.ts +241 -0
- package/src/web/frontend/modules/md/pm/schema.ts +150 -0
- package/src/web/frontend/modules/md/styles/editor.css +0 -26
- package/src/web/frontend/modules/md/styles/panels.css +3 -0
- package/src/web/frontend/modules/pretask/menu.tsx +31 -0
- package/src/web/frontend/modules/pretask/open-entry.ts +139 -0
- package/src/web/frontend/modules/pretask/types.ts +45 -0
- package/src/web/frontend/modules/pretask/use-plugins.ts +45 -0
- package/src/web/frontend/modules/pretask/use-pretask.ts +111 -0
- package/src/web/frontend/page/data/api.ts +49 -0
- package/src/web/frontend/page/data/index.tsx +89 -0
- package/src/web/frontend/page/data/style.css +84 -0
- package/src/web/frontend/page/data/table-view.tsx +126 -0
- package/src/web/frontend/page/dir/index.tsx +52 -57
- package/src/web/frontend/page/dir/task-actions.ts +6 -5
- package/src/web/frontend/page/dir/task-preview-modal.tsx +1 -1
- package/src/web/frontend/page/dir/task-utils.ts +3 -2
- package/src/web/frontend/page/dir/task.tsx +15 -10
- package/src/web/frontend/page/doc/index.tsx +4 -2
- package/src/web/frontend/page/group/index.tsx +90 -72
- package/src/web/frontend/page/settings/index.tsx +14 -1
- package/src/web/frontend/page/settings/plugins-section.tsx +78 -0
- package/src/web/frontend/panels.tsx +15 -26
- package/src/web/frontend/plugin-host/loader.ts +92 -0
- package/src/web/frontend/plugin-host/plugin-component.tsx +22 -0
- package/src/web/frontend/plugin-host/plugin-page.tsx +103 -0
- package/src/web/frontend/plugin-host/registry.ts +80 -0
- package/src/web/frontend/plugin-host/session.ts +29 -0
- package/src/web/frontend/plugin-host/style.css +41 -0
- package/src/web/frontend/plugin-host/visibility-panel.tsx +233 -0
- package/src/web/frontend/registry.ts +2 -0
- package/src/web/frontend/routes/index.ts +4 -3
- package/src/web/frontend/routes/plugin.ts +37 -0
- package/src/web/frontend/routes/route-eq.ts +5 -1
- package/src/web/frontend/routes/static.ts +3 -0
- package/src/web/frontend/styles-v2/sidebar.css +21 -2
- package/src/web/frontend/types.ts +5 -40
- package/src/web/frontend/use-ns-persist.ts +15 -4
- package/src/web/frontend/workspace/areas.ts +2 -1
- package/src/web/frontend/workspace/open.ts +32 -1
- package/src/web/frontend/workspace/panels.ts +1 -1
- package/src/web/public/assets/app-context-DnSScbEM.js +1 -0
- package/src/web/public/assets/bar-BEUdeltT.js +1 -0
- package/src/web/public/assets/board-view-DS6VzeG9.js +1 -0
- package/src/web/public/assets/client-73i4d2M4.js +1 -0
- package/src/web/public/assets/composer-launch-BOiu_85p.js +1 -0
- package/src/web/public/assets/composer-panel-BTWUPrF4.js +1 -0
- package/src/web/public/assets/dag-HEqXue8k.js +1 -0
- package/src/web/public/assets/data-Br0MR-Xk.css +1 -0
- package/src/web/public/assets/data-DJR0eP7U.js +1 -0
- package/src/web/public/assets/dir-BvcqEReL.js +1 -0
- package/src/web/public/assets/doc-store-sv1-1xal.js +1 -0
- package/src/web/public/assets/group-DhOuMegf.js +1 -0
- package/src/web/public/assets/icons-B05qzdxw.js +1 -0
- package/src/web/public/assets/index-BTYjj0YL.css +1 -0
- package/src/web/public/assets/index-_cjoyGJr.js +27 -0
- package/src/web/public/assets/md-history-CumFTbbK.js +45 -0
- package/src/web/public/assets/md-parse-BhjiD83o.js +6 -0
- package/src/web/public/assets/member-picker-B2EiDJ87.js +1 -0
- package/src/web/public/assets/plugin-component-BL69zZxx.js +1 -0
- package/src/web/public/assets/plugin-page-CLYrGvrM.js +1 -0
- package/src/web/public/assets/popup-DqWl8bjK.js +1 -0
- package/src/web/public/assets/popup-DrRYEe1w.css +1 -0
- package/src/web/public/assets/progress-DeGuv-S0.js +3 -0
- package/src/web/public/assets/refs-XyV92GFq.js +2 -0
- package/src/web/public/assets/registry-B4536DGP.js +1 -0
- package/src/web/public/assets/{reopen-text-D0eQ2XAC.js → reopen-text-cEGm0jzz.js} +1 -1
- package/src/web/public/assets/repos-BtKLD2-Y.js +12 -0
- package/src/web/public/assets/session-y2Ujr5bl.js +1 -0
- package/src/web/public/assets/settings-C6Wp4TEN.js +1 -0
- package/src/web/public/assets/style-BjfD0mtO.css +1 -0
- package/src/web/public/assets/task-DGOTk3il.css +1 -0
- package/src/web/public/assets/task-Dntjc9kS.js +14 -0
- package/src/web/public/assets/task-ops-V0KvmOJt.js +2 -0
- package/src/web/public/assets/task-status-DmR2rgbz.js +1 -0
- package/src/web/public/assets/task-utils-BJnDgdnA.js +1 -0
- package/src/web/public/assets/toast-OkR-KSSm.css +1 -0
- package/src/web/public/assets/toast-RYmip1Zl.js +1 -0
- package/src/web/public/assets/{tool-bar-CLIs9Dr0.css → tool-bar-B3K3eMeS.css} +1 -1
- package/src/web/public/assets/tool-bar-CeRPJ9OK.js +1 -0
- package/src/web/public/assets/use-pretask-QAtAPePc.js +1 -0
- package/src/web/public/assets/visibility-panel-BhCkxAHB.js +1 -0
- package/src/web/public/assets/workspace-C7kkUJNn.js +28 -0
- package/src/web/public/index.html +20 -17
- package/src/core/db/seed-templates.ts +0 -202
- package/src/modules/templates/actions/_manifest.generated.ts +0 -32
- package/src/modules/templates/actions/template-add.ts +0 -52
- package/src/modules/templates/actions/template-default.ts +0 -45
- package/src/modules/templates/actions/template-list.ts +0 -34
- package/src/modules/templates/actions/template-remove.ts +0 -31
- package/src/modules/templates/actions/template-reorder.ts +0 -28
- package/src/modules/templates/actions/template-update.ts +0 -43
- package/src/modules/templates/index.ts +0 -24
- package/src/modules/templates/repo/index.ts +0 -16
- package/src/modules/templates/repo/open.ts +0 -72
- package/src/modules/templates/repo/templates.ts +0 -185
- package/src/modules/templates/scope.ts +0 -113
- package/src/modules/templates/service.ts +0 -409
- package/src/modules/templates/support.ts +0 -32
- package/src/web/frontend/modules/md/fill-session.ts +0 -36
- package/src/web/frontend/modules/md/manage-session.ts +0 -24
- package/src/web/frontend/modules/md/new-task-from-template.ts +0 -22
- package/src/web/frontend/modules/md/use-templates.ts +0 -183
- package/src/web/frontend/modules/prompts/render-template-body.ts +0 -14
- package/src/web/frontend/modules/prompts/template-preview.ts +0 -61
- package/src/web/frontend/page/templates/fill.tsx +0 -128
- package/src/web/frontend/page/templates/index.tsx +0 -297
- package/src/web/frontend/page/templates/manage.tsx +0 -188
- package/src/web/frontend/page/templates/style.css +0 -93
- package/src/web/frontend/page/templates/template-list.tsx +0 -175
- package/src/web/frontend/routes/templates.ts +0 -85
- package/src/web/public/assets/app-context-DPFYOrgE.js +0 -1
- package/src/web/public/assets/bar-I4qGaKTO.js +0 -1
- package/src/web/public/assets/board-view-jt8QixVg.js +0 -1
- package/src/web/public/assets/button-DA4lNJeC.css +0 -1
- package/src/web/public/assets/button-VP4pjVsx.js +0 -1
- package/src/web/public/assets/composer-launch-BL344XZg.js +0 -1
- package/src/web/public/assets/composer-panel-D0ojgf7z.js +0 -1
- package/src/web/public/assets/dag-BY0lf-Nl.js +0 -1
- package/src/web/public/assets/dir-BNHyviHQ.js +0 -1
- package/src/web/public/assets/doc-Ka-2V5jn.css +0 -1
- package/src/web/public/assets/doc-wmc4swmo.js +0 -6
- package/src/web/public/assets/group-BSQ9_Gjs.js +0 -1
- package/src/web/public/assets/index-D2P-v30u.js +0 -3
- package/src/web/public/assets/index-DHLeXl42.css +0 -1
- package/src/web/public/assets/manage-session-CuaL7QqQ.js +0 -1
- package/src/web/public/assets/md-history-D0bYVPZY.js +0 -47
- package/src/web/public/assets/md-parse-BjzYV8n7.js +0 -6
- package/src/web/public/assets/member-picker-BtWykPer.js +0 -1
- package/src/web/public/assets/popup-DLfU1TXG.js +0 -1
- package/src/web/public/assets/popup-DzBICcYS.css +0 -1
- package/src/web/public/assets/progress-CQAvP9-n.js +0 -3
- package/src/web/public/assets/refs-Cf4ZbAra.js +0 -2
- package/src/web/public/assets/repo-form-modal-BahZhXq3.js +0 -1
- package/src/web/public/assets/repos-C2cZtRFo.js +0 -12
- package/src/web/public/assets/route-crumb-DS76cmRK.js +0 -1
- package/src/web/public/assets/settings-C_VmzG7F.js +0 -1
- package/src/web/public/assets/task-C4Sqe4vT.js +0 -14
- package/src/web/public/assets/task-Dcd2eA8B.css +0 -1
- package/src/web/public/assets/task-ops-SFagO-OC.js +0 -2
- package/src/web/public/assets/task-utils-Y-j-zi8J.js +0 -1
- package/src/web/public/assets/template-preview-EM3OQ1Rc.js +0 -1
- package/src/web/public/assets/templates-B8jnGSAl.js +0 -10
- package/src/web/public/assets/templates-DiEKBY-m.css +0 -1
- package/src/web/public/assets/tool-bar-NHeX0Kmo.js +0 -28
- package/src/web/public/assets/use-rail-drag-CtZxisjE.js +0 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "ES2022",
|
|
5
|
+
"lib": ["ES2023"],
|
|
6
|
+
"module": "NodeNext",
|
|
7
|
+
"moduleResolution": "NodeNext",
|
|
8
|
+
"rootDir": "src/server",
|
|
9
|
+
"outDir": "dist/server",
|
|
10
|
+
"declaration": true,
|
|
11
|
+
"sourceMap": true,
|
|
12
|
+
"composite": false,
|
|
13
|
+
"types": ["node"]
|
|
14
|
+
},
|
|
15
|
+
"include": ["src/server/**/*.ts"]
|
|
16
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { defineConfig } from 'vite';
|
|
2
|
+
import react from '@vitejs/plugin-react';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
|
|
5
|
+
const PACKAGE_DIR = fileURLToPath(new URL('.', import.meta.url));
|
|
6
|
+
|
|
7
|
+
export default defineConfig({
|
|
8
|
+
root: PACKAGE_DIR,
|
|
9
|
+
plugins: [react()],
|
|
10
|
+
build: {
|
|
11
|
+
outDir: 'dist/client',
|
|
12
|
+
emptyOutDir: true,
|
|
13
|
+
cssCodeSplit: false,
|
|
14
|
+
lib: {
|
|
15
|
+
entry: 'src/client/index.tsx',
|
|
16
|
+
formats: ['iife'],
|
|
17
|
+
name: 'NxkvPluginDirAnnotate',
|
|
18
|
+
fileName: () => 'client.js',
|
|
19
|
+
},
|
|
20
|
+
rollupOptions: {
|
|
21
|
+
external: ['react', 'react-dom', 'react/jsx-runtime'],
|
|
22
|
+
output: {
|
|
23
|
+
globals: {
|
|
24
|
+
react: 'NxkvReact',
|
|
25
|
+
'react-dom': 'NxkvReactDOM',
|
|
26
|
+
'react/jsx-runtime': 'NxkvJsxRuntime',
|
|
27
|
+
},
|
|
28
|
+
assetFileNames: (asset) =>
|
|
29
|
+
asset.name && asset.name.endsWith('.css') ? 'style.css' : 'assets/[name][extname]',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
|
+
import type { EntryView, PretaskContext, PretaskDraft } from './index.js';
|
|
3
|
+
export type { PluginContextView, PluginFileView, PluginRepoView, PluginTreeEntry, PluginTreeView, PluginTopicInfo, } from './index.js';
|
|
4
|
+
export interface PluginClientApi {
|
|
5
|
+
pluginId: string;
|
|
6
|
+
ctx: PretaskContext;
|
|
7
|
+
/** entry-form 页面才有。 */
|
|
8
|
+
entry?: EntryView;
|
|
9
|
+
rpc(method: string, params?: unknown): Promise<any>;
|
|
10
|
+
/** 请求宿主 HTTP(只允许 /api/ 路径);缺上下文时用它自行构造内容。 */
|
|
11
|
+
host: {
|
|
12
|
+
get<T = any>(path: string, params?: Record<string, string | number | boolean | null | undefined>): Promise<T>;
|
|
13
|
+
};
|
|
14
|
+
draft(entryId: string, values: Record<string, string>): Promise<PretaskDraft>;
|
|
15
|
+
/**
|
|
16
|
+
* 宿主写草稿并打开 task 编辑页。
|
|
17
|
+
* opts.project / opts.board:组场景下插件自选仓库时覆盖落点归属(缺省用 ctx)。
|
|
18
|
+
*/
|
|
19
|
+
createDraft(draft: PretaskDraft, opts?: {
|
|
20
|
+
submit?: boolean;
|
|
21
|
+
project?: string;
|
|
22
|
+
board?: string;
|
|
23
|
+
}): void;
|
|
24
|
+
navigate(hash: string): void;
|
|
25
|
+
closePage(): void;
|
|
26
|
+
toast(msg: string): void;
|
|
27
|
+
}
|
|
28
|
+
export interface PluginSidebarEntry {
|
|
29
|
+
id: string;
|
|
30
|
+
label: string;
|
|
31
|
+
icon?: string;
|
|
32
|
+
order?: number;
|
|
33
|
+
/** 指向 pages 的 key。 */
|
|
34
|
+
page: string;
|
|
35
|
+
}
|
|
36
|
+
export interface PluginUiDefinition {
|
|
37
|
+
api: '^1' | string;
|
|
38
|
+
components: Record<string, ComponentType<any>>;
|
|
39
|
+
pages?: Record<string, {
|
|
40
|
+
title: string;
|
|
41
|
+
}>;
|
|
42
|
+
sidebar?: PluginSidebarEntry[];
|
|
43
|
+
}
|
|
44
|
+
export interface PluginHostGlobal {
|
|
45
|
+
api: string;
|
|
46
|
+
registerPlugin(id: string, def: PluginUiDefinition): void;
|
|
47
|
+
}
|
|
48
|
+
declare global {
|
|
49
|
+
interface Window {
|
|
50
|
+
NxkvPluginHost?: PluginHostGlobal;
|
|
51
|
+
NxkvReact?: unknown;
|
|
52
|
+
NxkvReactDOM?: unknown;
|
|
53
|
+
NxkvJsxRuntime?: unknown;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1E,YAAY,EACV,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,eAAe,EACf,cAAc,EACd,eAAe,GAChB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,cAAc,CAAC;IACpB,uBAAuB;IACvB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IACpD,6CAA6C;IAC7C,IAAI,EAAE;QACJ,GAAG,CA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AAC;IACZ,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,kBAAkB,GAAG,IAAI,CAAC;CAC3D;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,cAAc,CAAC,EAAE,gBAAgB,CAAC;QAClC,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,cAAc,CAAC,EAAE,OAAO,CAAC;KAC1B;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
export declare const PLUGIN_API = "^1";
|
|
2
|
+
/** 插件可用的最小 DB 形状(宿主把它包在 single-writer 事务里传进来)。 */
|
|
3
|
+
export interface PluginDb {
|
|
4
|
+
path?: string;
|
|
5
|
+
readOnly?: boolean;
|
|
6
|
+
exec(sql: string): void;
|
|
7
|
+
get(sql: string, params?: unknown): any;
|
|
8
|
+
all(sql: string, params?: unknown): any[];
|
|
9
|
+
run(sql: string, params?: unknown): {
|
|
10
|
+
changes?: number | bigint;
|
|
11
|
+
lastInsertRowid?: number | bigint;
|
|
12
|
+
};
|
|
13
|
+
scalar?(sql: string, params?: unknown): any;
|
|
14
|
+
}
|
|
15
|
+
export type TopicKind = 'repo' | 'group' | 'unknown';
|
|
16
|
+
/** 当前 topic 的完整定位;插件缺东西时可用 host.get('/api/plugins/context') 再取。 */
|
|
17
|
+
export interface PluginTopicInfo {
|
|
18
|
+
key: string;
|
|
19
|
+
name: string;
|
|
20
|
+
kind: TopicKind;
|
|
21
|
+
cwd: string;
|
|
22
|
+
repoKey: string;
|
|
23
|
+
groupKey: string;
|
|
24
|
+
repoName?: string;
|
|
25
|
+
groupName?: string;
|
|
26
|
+
/** 仓库本机根目录(repo topic 或 group topic 的成员 repo) */
|
|
27
|
+
repoRoot?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface PluginLocation {
|
|
30
|
+
dirKey?: string;
|
|
31
|
+
groupId?: string;
|
|
32
|
+
board?: string;
|
|
33
|
+
project?: string;
|
|
34
|
+
taskId?: string;
|
|
35
|
+
}
|
|
36
|
+
/** /api/plugins/context 里的仓库行。 */
|
|
37
|
+
export interface PluginRepoView {
|
|
38
|
+
key: string;
|
|
39
|
+
type: string;
|
|
40
|
+
name: string;
|
|
41
|
+
path: string;
|
|
42
|
+
description: string;
|
|
43
|
+
}
|
|
44
|
+
/** /api/plugins/context 的返回:topic + 当前 repo/group + 组内 repo 列表。 */
|
|
45
|
+
export interface PluginContextView {
|
|
46
|
+
topic: PluginTopicInfo;
|
|
47
|
+
repo: PluginRepoView | null;
|
|
48
|
+
group: PluginRepoView | null;
|
|
49
|
+
repos: PluginRepoView[];
|
|
50
|
+
}
|
|
51
|
+
/** /api/plugins/tree 的目录项。 */
|
|
52
|
+
export interface PluginTreeEntry {
|
|
53
|
+
name: string;
|
|
54
|
+
path: string;
|
|
55
|
+
type: 'dir' | 'file';
|
|
56
|
+
size?: number;
|
|
57
|
+
}
|
|
58
|
+
/** /api/plugins/tree 的返回。 */
|
|
59
|
+
export interface PluginTreeView {
|
|
60
|
+
repoKey: string;
|
|
61
|
+
repoName: string;
|
|
62
|
+
repoRoot: string;
|
|
63
|
+
path: string;
|
|
64
|
+
entries: PluginTreeEntry[];
|
|
65
|
+
truncated: boolean;
|
|
66
|
+
}
|
|
67
|
+
/** /api/plugins/file 的返回(二进制不给正文)。 */
|
|
68
|
+
export interface PluginFileView {
|
|
69
|
+
repoKey: string;
|
|
70
|
+
path: string;
|
|
71
|
+
size: number;
|
|
72
|
+
binary: boolean;
|
|
73
|
+
truncated: boolean;
|
|
74
|
+
content: string;
|
|
75
|
+
}
|
|
76
|
+
/** 插件看到的宿主上下文:只给任务/主题定位,不给宿主内部对象。 */
|
|
77
|
+
export interface PretaskContext {
|
|
78
|
+
topicKey?: string;
|
|
79
|
+
groupKey?: string;
|
|
80
|
+
repoKey?: string;
|
|
81
|
+
cwd?: string;
|
|
82
|
+
dirKey?: string;
|
|
83
|
+
groupId?: string;
|
|
84
|
+
board?: string;
|
|
85
|
+
project?: string;
|
|
86
|
+
/** 宿主解析后的完整 topic(前端可传,宿主会按 DB 补全) */
|
|
87
|
+
topic?: PluginTopicInfo | null;
|
|
88
|
+
/** 组/看板/项目等定位(前端上下文透传) */
|
|
89
|
+
location?: PluginLocation;
|
|
90
|
+
}
|
|
91
|
+
export interface SlotDecl {
|
|
92
|
+
key: string;
|
|
93
|
+
label: string;
|
|
94
|
+
type: 'text';
|
|
95
|
+
required?: boolean;
|
|
96
|
+
hint?: string;
|
|
97
|
+
default?: string;
|
|
98
|
+
}
|
|
99
|
+
export interface PretaskDraft {
|
|
100
|
+
body: string;
|
|
101
|
+
title?: string;
|
|
102
|
+
}
|
|
103
|
+
export interface EntryView {
|
|
104
|
+
/** `${pluginId}:${localId}`,全局唯一、稳定。 */
|
|
105
|
+
id: string;
|
|
106
|
+
pluginId: string;
|
|
107
|
+
label: string;
|
|
108
|
+
description?: string;
|
|
109
|
+
icon?: string;
|
|
110
|
+
kind: 'draft' | 'panel';
|
|
111
|
+
order: number;
|
|
112
|
+
default?: boolean;
|
|
113
|
+
builtin?: boolean;
|
|
114
|
+
/** kind=draft:模板槽位与原始正文。 */
|
|
115
|
+
slots?: SlotDecl[];
|
|
116
|
+
previewBody?: string;
|
|
117
|
+
values?: Record<string, string>;
|
|
118
|
+
/** 插件 client bundle 注册的 UI 组件 key。 */
|
|
119
|
+
ui?: {
|
|
120
|
+
row?: string;
|
|
121
|
+
form?: string;
|
|
122
|
+
panel?: string;
|
|
123
|
+
};
|
|
124
|
+
/** kind=panel 的兜底元信息。 */
|
|
125
|
+
panel?: {
|
|
126
|
+
title?: string;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
export interface PluginContext extends PretaskContext {
|
|
130
|
+
storage: PluginDb;
|
|
131
|
+
storageVersion: number;
|
|
132
|
+
log: (level: string, msg: string) => void;
|
|
133
|
+
/** 宿主暂存的旧数据(如 v18 templates);插件成功导入后宿主会删除。 */
|
|
134
|
+
legacy: {
|
|
135
|
+
take(kind: string): Promise<unknown | null>;
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
export interface NxkvPlugin {
|
|
139
|
+
id: string;
|
|
140
|
+
version: string;
|
|
141
|
+
api: typeof PLUGIN_API | string;
|
|
142
|
+
name: string;
|
|
143
|
+
description?: string;
|
|
144
|
+
order: number;
|
|
145
|
+
defaultEnabled: boolean;
|
|
146
|
+
entries(ctx: PluginContext): Promise<EntryView[]> | EntryView[];
|
|
147
|
+
buildDraft(ctx: PluginContext, entryId: string, values: Record<string, string>): Promise<PretaskDraft>;
|
|
148
|
+
rpc?: Record<string, (ctx: PluginContext, params: any) => Promise<any>>;
|
|
149
|
+
/** 插件自己的表结构目标版本;宿主据此记录 plugin_storage_migrations。 */
|
|
150
|
+
storageVersion?: number;
|
|
151
|
+
/** 插件自己的建表/升级逻辑;fromVersion 由宿主传入。 */
|
|
152
|
+
migrateStorage?(db: PluginDb, fromVersion: number): number | void;
|
|
153
|
+
/** 宿主暂存数据的一次性导入;按业务 id 幂等。 */
|
|
154
|
+
migrateLegacy?(ctx: PluginContext, kind: string, payload: unknown): Promise<void>;
|
|
155
|
+
}
|
|
156
|
+
/** 插件 server 入口的默认导出必须包一层,宿主据此做运行时校验。 */
|
|
157
|
+
export declare function definePlugin(plugin: NxkvPlugin): NxkvPlugin;
|
|
158
|
+
/** 供插件做 rpc 参数兜底:把未知值收成普通对象。 */
|
|
159
|
+
export declare function paramsOf(raw: unknown): Record<string, any>;
|
|
160
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,UAAU,OAAO,CAAC;AAE/B,kDAAkD;AAClD,MAAM,WAAW,QAAQ;IACvB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Aa,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACnF;AAED,yCAAyC;AACzC,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAS3D;AAED,gCAAgC;AAChC,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAE1D"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// nx-kv 内部插件 SDK:server 半侧契约。
|
|
2
|
+
//
|
|
3
|
+
// 插件包只依赖本包与 Node 内置能力;宿主不 import 插件包内部,插件也不 import 宿主 src。
|
|
4
|
+
// v1 是进程内可信插件;API 版本先固定 '^1',后续 worker/sidecar 用同一份契约。
|
|
5
|
+
export const PLUGIN_API = '^1';
|
|
6
|
+
/** 插件 server 入口的默认导出必须包一层,宿主据此做运行时校验。 */
|
|
7
|
+
export function definePlugin(plugin) {
|
|
8
|
+
if (!plugin || typeof plugin !== 'object')
|
|
9
|
+
throw new Error('definePlugin: 需要插件对象');
|
|
10
|
+
if (!plugin.id || /[:.]/.test(plugin.id))
|
|
11
|
+
throw new Error(`definePlugin: 非法插件 id「${String(plugin.id)}」(只允许字母/数字/短横线)`);
|
|
12
|
+
if (!plugin.api || !/^\^1(\.|$)/.test(plugin.api))
|
|
13
|
+
throw new Error(`definePlugin: 不支持的 api「${String(plugin.api)}」(当前 '^1')`);
|
|
14
|
+
if (!plugin.version)
|
|
15
|
+
throw new Error('definePlugin: 需要 version');
|
|
16
|
+
if (!plugin.name)
|
|
17
|
+
throw new Error('definePlugin: 需要 name');
|
|
18
|
+
if (typeof plugin.entries !== 'function')
|
|
19
|
+
throw new Error('definePlugin: 需要 entries()');
|
|
20
|
+
if (typeof plugin.buildDraft !== 'function')
|
|
21
|
+
throw new Error('definePlugin: 需要 buildDraft()');
|
|
22
|
+
return plugin;
|
|
23
|
+
}
|
|
24
|
+
/** 供插件做 rpc 参数兜底:把未知值收成普通对象。 */
|
|
25
|
+
export function paramsOf(raw) {
|
|
26
|
+
return raw && typeof raw === 'object' && !Array.isArray(raw) ? raw : {};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,EAAE;AACF,2DAA2D;AAC3D,uDAAuD;AAEvD,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC;AAkK/B,yCAAyC;AACzC,MAAM,UAAU,YAAY,CAAC,MAAkB;IAC7C,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IACnF,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,iBAAiB,CAAC,CAAC;IACvH,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,0BAA0B,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAC7H,IAAI,CAAC,MAAM,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;IACjE,IAAI,CAAC,MAAM,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC3D,IAAI,OAAO,MAAM,CAAC,OAAO,KAAK,UAAU;QAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IACxF,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,UAAU;QAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IAC9F,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,gCAAgC;AAChC,MAAM,UAAU,QAAQ,CAAC,GAAY;IACnC,OAAO,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,GAA2B,CAAC,CAAC,CAAC,EAAE,CAAC;AACnG,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** 模板正文里声明了哪些槽位(按首次出现顺序去重)。 */
|
|
2
|
+
export declare function templateSlots(body: unknown): string[];
|
|
3
|
+
/** 渲染模板正文:{{槽位名}} → 槽位值(没值留空)。 */
|
|
4
|
+
export declare function renderTemplateBody(body: unknown, values?: Record<string, unknown> | null): string;
|
|
5
|
+
//# sourceMappingURL=template.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../src/template.ts"],"names":[],"mappings":"AAKA,+BAA+B;AAC/B,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,CAOrD;AAED,kCAAkC;AAClC,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,MAAM,CAOjG"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// 任务模板槽位/渲染的共享纯函数:宿主与插件包必须同一口径。
|
|
2
|
+
// 零依赖正则实现,不引入 Handlebars。
|
|
3
|
+
const SLOT_RE = /\{\{\s*([^}{\s][^{}]*?)\s*\}\}/g;
|
|
4
|
+
/** 模板正文里声明了哪些槽位(按首次出现顺序去重)。 */
|
|
5
|
+
export function templateSlots(body) {
|
|
6
|
+
const seen = new Set();
|
|
7
|
+
for (const m of String(body ?? '').matchAll(SLOT_RE)) {
|
|
8
|
+
const key = String(m[1] ?? '').trim();
|
|
9
|
+
if (key)
|
|
10
|
+
seen.add(key);
|
|
11
|
+
}
|
|
12
|
+
return [...seen];
|
|
13
|
+
}
|
|
14
|
+
/** 渲染模板正文:{{槽位名}} → 槽位值(没值留空)。 */
|
|
15
|
+
export function renderTemplateBody(body, values) {
|
|
16
|
+
const vals = values && typeof values === 'object' ? values : {};
|
|
17
|
+
return String(body ?? '').replace(SLOT_RE, (_all, name) => {
|
|
18
|
+
const key = String(name).trim();
|
|
19
|
+
const v = vals[key];
|
|
20
|
+
return v === undefined || v === null ? '' : String(v);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template.js","sourceRoot":"","sources":["../src/template.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,0BAA0B;AAE1B,MAAM,OAAO,GAAG,iCAAiC,CAAC;AAElD,+BAA+B;AAC/B,MAAM,UAAU,aAAa,CAAC,IAAa;IACzC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QACrD,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACtC,IAAI,GAAG;YAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IACD,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;AACnB,CAAC;AAED,kCAAkC;AAClC,MAAM,UAAU,kBAAkB,CAAC,IAAa,EAAE,MAAuC;IACvF,MAAM,IAAI,GAA4B,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IACzF,OAAO,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;QACxD,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;QAChC,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;QACpB,OAAO,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nx-kv/plugin-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./client": {
|
|
14
|
+
"types": "./dist/client.d.ts",
|
|
15
|
+
"import": "./dist/client.js"
|
|
16
|
+
},
|
|
17
|
+
"./template": {
|
|
18
|
+
"types": "./dist/template.d.ts",
|
|
19
|
+
"import": "./dist/template.js"
|
|
20
|
+
},
|
|
21
|
+
"./package.json": "./package.json"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"package.json"
|
|
26
|
+
]
|
|
27
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// nx-kv 插件 SDK:client 半侧契约(只给插件 UI 包用,宿主只提供实现)。
|
|
2
|
+
import type { ComponentType } from 'react';
|
|
3
|
+
import type { EntryView, PretaskContext, PretaskDraft } from './index.js';
|
|
4
|
+
|
|
5
|
+
export type {
|
|
6
|
+
PluginContextView,
|
|
7
|
+
PluginFileView,
|
|
8
|
+
PluginRepoView,
|
|
9
|
+
PluginTreeEntry,
|
|
10
|
+
PluginTreeView,
|
|
11
|
+
PluginTopicInfo,
|
|
12
|
+
} from './index.js';
|
|
13
|
+
|
|
14
|
+
export interface PluginClientApi {
|
|
15
|
+
pluginId: string;
|
|
16
|
+
ctx: PretaskContext;
|
|
17
|
+
/** entry-form 页面才有。 */
|
|
18
|
+
entry?: EntryView;
|
|
19
|
+
rpc(method: string, params?: unknown): Promise<any>;
|
|
20
|
+
/** 请求宿主 HTTP(只允许 /api/ 路径);缺上下文时用它自行构造内容。 */
|
|
21
|
+
host: {
|
|
22
|
+
get<T = any>(path: string, params?: Record<string, string | number | boolean | null | undefined>): Promise<T>;
|
|
23
|
+
};
|
|
24
|
+
draft(entryId: string, values: Record<string, string>): Promise<PretaskDraft>;
|
|
25
|
+
/**
|
|
26
|
+
* 宿主写草稿并打开 task 编辑页。
|
|
27
|
+
* opts.project / opts.board:组场景下插件自选仓库时覆盖落点归属(缺省用 ctx)。
|
|
28
|
+
*/
|
|
29
|
+
createDraft(draft: PretaskDraft, opts?: { submit?: boolean; project?: string; board?: string }): void;
|
|
30
|
+
navigate(hash: string): void;
|
|
31
|
+
closePage(): void;
|
|
32
|
+
toast(msg: string): void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface PluginSidebarEntry {
|
|
36
|
+
id: string;
|
|
37
|
+
label: string;
|
|
38
|
+
icon?: string;
|
|
39
|
+
order?: number;
|
|
40
|
+
/** 指向 pages 的 key。 */
|
|
41
|
+
page: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface PluginUiDefinition {
|
|
45
|
+
api: '^1' | string;
|
|
46
|
+
components: Record<string, ComponentType<any>>;
|
|
47
|
+
pages?: Record<string, { title: string }>;
|
|
48
|
+
sidebar?: PluginSidebarEntry[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface PluginHostGlobal {
|
|
52
|
+
api: string;
|
|
53
|
+
registerPlugin(id: string, def: PluginUiDefinition): void;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
declare global {
|
|
57
|
+
interface Window {
|
|
58
|
+
NxkvPluginHost?: PluginHostGlobal;
|
|
59
|
+
NxkvReact?: unknown;
|
|
60
|
+
NxkvReactDOM?: unknown;
|
|
61
|
+
NxkvJsxRuntime?: unknown;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// nx-kv 内部插件 SDK:server 半侧契约。
|
|
2
|
+
//
|
|
3
|
+
// 插件包只依赖本包与 Node 内置能力;宿主不 import 插件包内部,插件也不 import 宿主 src。
|
|
4
|
+
// v1 是进程内可信插件;API 版本先固定 '^1',后续 worker/sidecar 用同一份契约。
|
|
5
|
+
|
|
6
|
+
export const PLUGIN_API = '^1';
|
|
7
|
+
|
|
8
|
+
/** 插件可用的最小 DB 形状(宿主把它包在 single-writer 事务里传进来)。 */
|
|
9
|
+
export interface PluginDb {
|
|
10
|
+
path?: string;
|
|
11
|
+
readOnly?: boolean;
|
|
12
|
+
exec(sql: string): void;
|
|
13
|
+
get(sql: string, params?: unknown): any;
|
|
14
|
+
all(sql: string, params?: unknown): any[];
|
|
15
|
+
run(sql: string, params?: unknown): { changes?: number | bigint; lastInsertRowid?: number | bigint };
|
|
16
|
+
scalar?(sql: string, params?: unknown): any;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type TopicKind = 'repo' | 'group' | 'unknown';
|
|
20
|
+
|
|
21
|
+
/** 当前 topic 的完整定位;插件缺东西时可用 host.get('/api/plugins/context') 再取。 */
|
|
22
|
+
export interface PluginTopicInfo {
|
|
23
|
+
key: string;
|
|
24
|
+
name: string;
|
|
25
|
+
kind: TopicKind;
|
|
26
|
+
cwd: string;
|
|
27
|
+
repoKey: string;
|
|
28
|
+
groupKey: string;
|
|
29
|
+
repoName?: string;
|
|
30
|
+
groupName?: string;
|
|
31
|
+
/** 仓库本机根目录(repo topic 或 group topic 的成员 repo) */
|
|
32
|
+
repoRoot?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface PluginLocation {
|
|
36
|
+
dirKey?: string;
|
|
37
|
+
groupId?: string;
|
|
38
|
+
board?: string;
|
|
39
|
+
project?: string;
|
|
40
|
+
taskId?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** /api/plugins/context 里的仓库行。 */
|
|
44
|
+
export interface PluginRepoView {
|
|
45
|
+
key: string;
|
|
46
|
+
type: string;
|
|
47
|
+
name: string;
|
|
48
|
+
path: string;
|
|
49
|
+
description: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** /api/plugins/context 的返回:topic + 当前 repo/group + 组内 repo 列表。 */
|
|
53
|
+
export interface PluginContextView {
|
|
54
|
+
topic: PluginTopicInfo;
|
|
55
|
+
repo: PluginRepoView | null;
|
|
56
|
+
group: PluginRepoView | null;
|
|
57
|
+
repos: PluginRepoView[];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** /api/plugins/tree 的目录项。 */
|
|
61
|
+
export interface PluginTreeEntry {
|
|
62
|
+
name: string;
|
|
63
|
+
path: string;
|
|
64
|
+
type: 'dir' | 'file';
|
|
65
|
+
size?: number;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** /api/plugins/tree 的返回。 */
|
|
69
|
+
export interface PluginTreeView {
|
|
70
|
+
repoKey: string;
|
|
71
|
+
repoName: string;
|
|
72
|
+
repoRoot: string;
|
|
73
|
+
path: string;
|
|
74
|
+
entries: PluginTreeEntry[];
|
|
75
|
+
truncated: boolean;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** /api/plugins/file 的返回(二进制不给正文)。 */
|
|
79
|
+
export interface PluginFileView {
|
|
80
|
+
repoKey: string;
|
|
81
|
+
path: string;
|
|
82
|
+
size: number;
|
|
83
|
+
binary: boolean;
|
|
84
|
+
truncated: boolean;
|
|
85
|
+
content: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** 插件看到的宿主上下文:只给任务/主题定位,不给宿主内部对象。 */
|
|
89
|
+
export interface PretaskContext {
|
|
90
|
+
topicKey?: string;
|
|
91
|
+
groupKey?: string;
|
|
92
|
+
repoKey?: string;
|
|
93
|
+
cwd?: string;
|
|
94
|
+
dirKey?: string;
|
|
95
|
+
groupId?: string;
|
|
96
|
+
board?: string;
|
|
97
|
+
project?: string;
|
|
98
|
+
/** 宿主解析后的完整 topic(前端可传,宿主会按 DB 补全) */
|
|
99
|
+
topic?: PluginTopicInfo | null;
|
|
100
|
+
/** 组/看板/项目等定位(前端上下文透传) */
|
|
101
|
+
location?: PluginLocation;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface SlotDecl {
|
|
105
|
+
key: string;
|
|
106
|
+
label: string;
|
|
107
|
+
type: 'text';
|
|
108
|
+
required?: boolean;
|
|
109
|
+
hint?: string;
|
|
110
|
+
default?: string;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface PretaskDraft {
|
|
114
|
+
body: string;
|
|
115
|
+
title?: string;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface EntryView {
|
|
119
|
+
/** `${pluginId}:${localId}`,全局唯一、稳定。 */
|
|
120
|
+
id: string;
|
|
121
|
+
pluginId: string;
|
|
122
|
+
label: string;
|
|
123
|
+
description?: string;
|
|
124
|
+
icon?: string;
|
|
125
|
+
kind: 'draft' | 'panel';
|
|
126
|
+
order: number;
|
|
127
|
+
default?: boolean;
|
|
128
|
+
builtin?: boolean;
|
|
129
|
+
/** kind=draft:模板槽位与原始正文。 */
|
|
130
|
+
slots?: SlotDecl[];
|
|
131
|
+
previewBody?: string;
|
|
132
|
+
values?: Record<string, string>;
|
|
133
|
+
/** 插件 client bundle 注册的 UI 组件 key。 */
|
|
134
|
+
ui?: { row?: string; form?: string; panel?: string };
|
|
135
|
+
/** kind=panel 的兜底元信息。 */
|
|
136
|
+
panel?: { title?: string };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export interface PluginContext extends PretaskContext {
|
|
140
|
+
storage: PluginDb;
|
|
141
|
+
storageVersion: number;
|
|
142
|
+
log: (level: string, msg: string) => void;
|
|
143
|
+
/** 宿主暂存的旧数据(如 v18 templates);插件成功导入后宿主会删除。 */
|
|
144
|
+
legacy: {
|
|
145
|
+
take(kind: string): Promise<unknown | null>;
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export interface NxkvPlugin {
|
|
150
|
+
id: string;
|
|
151
|
+
version: string;
|
|
152
|
+
api: typeof PLUGIN_API | string;
|
|
153
|
+
name: string;
|
|
154
|
+
description?: string;
|
|
155
|
+
order: number;
|
|
156
|
+
defaultEnabled: boolean;
|
|
157
|
+
entries(ctx: PluginContext): Promise<EntryView[]> | EntryView[];
|
|
158
|
+
buildDraft(ctx: PluginContext, entryId: string, values: Record<string, string>): Promise<PretaskDraft>;
|
|
159
|
+
rpc?: Record<string, (ctx: PluginContext, params: any) => Promise<any>>;
|
|
160
|
+
/** 插件自己的表结构目标版本;宿主据此记录 plugin_storage_migrations。 */
|
|
161
|
+
storageVersion?: number;
|
|
162
|
+
/** 插件自己的建表/升级逻辑;fromVersion 由宿主传入。 */
|
|
163
|
+
migrateStorage?(db: PluginDb, fromVersion: number): number | void;
|
|
164
|
+
/** 宿主暂存数据的一次性导入;按业务 id 幂等。 */
|
|
165
|
+
migrateLegacy?(ctx: PluginContext, kind: string, payload: unknown): Promise<void>;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** 插件 server 入口的默认导出必须包一层,宿主据此做运行时校验。 */
|
|
169
|
+
export function definePlugin(plugin: NxkvPlugin): NxkvPlugin {
|
|
170
|
+
if (!plugin || typeof plugin !== 'object') throw new Error('definePlugin: 需要插件对象');
|
|
171
|
+
if (!plugin.id || /[:.]/.test(plugin.id)) throw new Error(`definePlugin: 非法插件 id「${String(plugin.id)}」(只允许字母/数字/短横线)`);
|
|
172
|
+
if (!plugin.api || !/^\^1(\.|$)/.test(plugin.api)) throw new Error(`definePlugin: 不支持的 api「${String(plugin.api)}」(当前 '^1')`);
|
|
173
|
+
if (!plugin.version) throw new Error('definePlugin: 需要 version');
|
|
174
|
+
if (!plugin.name) throw new Error('definePlugin: 需要 name');
|
|
175
|
+
if (typeof plugin.entries !== 'function') throw new Error('definePlugin: 需要 entries()');
|
|
176
|
+
if (typeof plugin.buildDraft !== 'function') throw new Error('definePlugin: 需要 buildDraft()');
|
|
177
|
+
return plugin;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** 供插件做 rpc 参数兜底:把未知值收成普通对象。 */
|
|
181
|
+
export function paramsOf(raw: unknown): Record<string, any> {
|
|
182
|
+
return raw && typeof raw === 'object' && !Array.isArray(raw) ? (raw as Record<string, any>) : {};
|
|
183
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// 任务模板槽位/渲染的共享纯函数:宿主与插件包必须同一口径。
|
|
2
|
+
// 零依赖正则实现,不引入 Handlebars。
|
|
3
|
+
|
|
4
|
+
const SLOT_RE = /\{\{\s*([^}{\s][^{}]*?)\s*\}\}/g;
|
|
5
|
+
|
|
6
|
+
/** 模板正文里声明了哪些槽位(按首次出现顺序去重)。 */
|
|
7
|
+
export function templateSlots(body: unknown): string[] {
|
|
8
|
+
const seen = new Set<string>();
|
|
9
|
+
for (const m of String(body ?? '').matchAll(SLOT_RE)) {
|
|
10
|
+
const key = String(m[1] ?? '').trim();
|
|
11
|
+
if (key) seen.add(key);
|
|
12
|
+
}
|
|
13
|
+
return [...seen];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** 渲染模板正文:{{槽位名}} → 槽位值(没值留空)。 */
|
|
17
|
+
export function renderTemplateBody(body: unknown, values?: Record<string, unknown> | null): string {
|
|
18
|
+
const vals: Record<string, unknown> = values && typeof values === 'object' ? values : {};
|
|
19
|
+
return String(body ?? '').replace(SLOT_RE, (_all, name) => {
|
|
20
|
+
const key = String(name).trim();
|
|
21
|
+
const v = vals[key];
|
|
22
|
+
return v === undefined || v === null ? '' : String(v);
|
|
23
|
+
});
|
|
24
|
+
}
|