nx-kv 0.48.0 → 0.48.2

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.
Files changed (242) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/package.json +1 -1
  3. package/src/modules/auth/actions/auth-login.ts +13 -6
  4. package/src/modules/auth/actions/auth-logout.ts +11 -6
  5. package/src/modules/auth/actions/auth-me.ts +11 -6
  6. package/src/modules/auth/actions/auth-status.ts +11 -6
  7. package/src/modules/bundled/actions/bundled-get.ts +14 -6
  8. package/src/modules/bundled/actions/bundled-groups.ts +11 -6
  9. package/src/modules/bundled/actions/bundled-install.ts +15 -6
  10. package/src/modules/bundled/actions/bundled-list.ts +11 -6
  11. package/src/modules/db/actions/db-backup.ts +12 -6
  12. package/src/modules/db/actions/db-migrate.ts +12 -6
  13. package/src/modules/db/actions/db-status.ts +11 -6
  14. package/src/modules/db/actions/db-verify.ts +11 -6
  15. package/src/modules/docs/actions/doc-add.ts +14 -6
  16. package/src/modules/docs/actions/doc-attach-note.ts +13 -6
  17. package/src/modules/docs/actions/doc-attach.ts +20 -6
  18. package/src/modules/docs/actions/doc-attachments.ts +11 -6
  19. package/src/modules/docs/actions/doc-detach.ts +13 -6
  20. package/src/modules/docs/actions/doc-get.ts +11 -6
  21. package/src/modules/docs/actions/doc-list.ts +11 -6
  22. package/src/modules/docs/actions/doc-remove.ts +11 -6
  23. package/src/modules/docs/actions/doc-update.ts +14 -6
  24. package/src/modules/docs/actions/docs-bind.ts +15 -6
  25. package/src/modules/docs/actions/docs-index.ts +11 -6
  26. package/src/modules/docs/actions/docs-link.ts +16 -6
  27. package/src/modules/docs/actions/docs-notebind.ts +15 -6
  28. package/src/modules/docs/actions/docs-seed.ts +11 -6
  29. package/src/modules/file/actions/file-content.ts +18 -10
  30. package/src/modules/file/actions/file-get.ts +12 -6
  31. package/src/modules/file/actions/file-list.ts +13 -6
  32. package/src/modules/file/actions/file-orphans.ts +11 -6
  33. package/src/modules/file/actions/file-prune.ts +12 -6
  34. package/src/modules/file/actions/file-remove.ts +12 -6
  35. package/src/modules/file/actions/file-sync.ts +15 -6
  36. package/src/modules/file/actions/file-upload.ts +17 -6
  37. package/src/modules/localtask/actions/localtask-add.ts +26 -6
  38. package/src/modules/localtask/actions/localtask-attach-note.ts +15 -6
  39. package/src/modules/localtask/actions/localtask-attach.ts +24 -6
  40. package/src/modules/localtask/actions/localtask-attachments.ts +13 -6
  41. package/src/modules/localtask/actions/localtask-cancel.ts +12 -6
  42. package/src/modules/localtask/actions/localtask-cancelMany.ts +13 -6
  43. package/src/modules/localtask/actions/localtask-chain.ts +13 -6
  44. package/src/modules/localtask/actions/localtask-claim.ts +14 -6
  45. package/src/modules/localtask/actions/localtask-clone.ts +13 -6
  46. package/src/modules/localtask/actions/localtask-closeMany.ts +15 -6
  47. package/src/modules/localtask/actions/localtask-config.ts +23 -8
  48. package/src/modules/localtask/actions/localtask-detach.ts +15 -6
  49. package/src/modules/localtask/actions/localtask-done.ts +14 -6
  50. package/src/modules/localtask/actions/localtask-events.ts +19 -9
  51. package/src/modules/localtask/actions/localtask-fork.ts +13 -6
  52. package/src/modules/localtask/actions/localtask-get.ts +13 -6
  53. package/src/modules/localtask/actions/localtask-importRemote.ts +20 -9
  54. package/src/modules/localtask/actions/localtask-list.ts +11 -6
  55. package/src/modules/localtask/actions/localtask-presence.ts +11 -6
  56. package/src/modules/localtask/actions/localtask-preview.ts +15 -6
  57. package/src/modules/localtask/actions/localtask-prune.ts +12 -6
  58. package/src/modules/localtask/actions/localtask-remove.ts +14 -6
  59. package/src/modules/localtask/actions/localtask-removeMany.ts +14 -6
  60. package/src/modules/localtask/actions/localtask-reopen.ts +22 -7
  61. package/src/modules/localtask/actions/localtask-reorder.ts +17 -6
  62. package/src/modules/localtask/actions/localtask-task-restore.ts +13 -6
  63. package/src/modules/localtask/actions/localtask-timegoalLog.ts +13 -6
  64. package/src/modules/localtask/actions/localtask-topic-add.ts +12 -6
  65. package/src/modules/localtask/actions/localtask-topic-remove.ts +13 -6
  66. package/src/modules/localtask/actions/localtask-topic-removeMany.ts +14 -6
  67. package/src/modules/localtask/actions/localtask-update.ts +24 -6
  68. package/src/modules/localtask/actions/localtask-wait.ts +15 -6
  69. package/src/modules/localtask/actions/task-move.ts +23 -6
  70. package/src/modules/repos/actions/board-add.ts +12 -6
  71. package/src/modules/repos/actions/board-assign.ts +14 -6
  72. package/src/modules/repos/actions/board-export.ts +11 -6
  73. package/src/modules/repos/actions/board-get.ts +11 -6
  74. package/src/modules/repos/actions/board-import.ts +17 -7
  75. package/src/modules/repos/actions/board-list.ts +11 -6
  76. package/src/modules/repos/actions/board-note.ts +13 -6
  77. package/src/modules/repos/actions/board-prefix.ts +12 -6
  78. package/src/modules/repos/actions/board-prune.ts +13 -6
  79. package/src/modules/repos/actions/board-rekey.ts +13 -6
  80. package/src/modules/repos/actions/board-remove.ts +11 -6
  81. package/src/modules/repos/actions/board-update.ts +13 -6
  82. package/src/modules/repos/actions/repo-add.ts +19 -6
  83. package/src/modules/repos/actions/repo-bind-topics.ts +12 -6
  84. package/src/modules/repos/actions/repo-bind.ts +14 -6
  85. package/src/modules/repos/actions/repo-clone.ts +16 -6
  86. package/src/modules/repos/actions/repo-detect.ts +11 -6
  87. package/src/modules/repos/actions/repo-doc-add.ts +17 -6
  88. package/src/modules/repos/actions/repo-doc-list.ts +11 -6
  89. package/src/modules/repos/actions/repo-doc-remove.ts +12 -6
  90. package/src/modules/repos/actions/repo-export.ts +14 -6
  91. package/src/modules/repos/actions/repo-get.ts +11 -6
  92. package/src/modules/repos/actions/repo-import-diff.ts +12 -6
  93. package/src/modules/repos/actions/repo-import.ts +16 -6
  94. package/src/modules/repos/actions/repo-key-migrate.ts +11 -6
  95. package/src/modules/repos/actions/repo-key-refresh.ts +13 -6
  96. package/src/modules/repos/actions/repo-key-set.ts +13 -6
  97. package/src/modules/repos/actions/repo-knowledge.ts +12 -6
  98. package/src/modules/repos/actions/repo-list.ts +11 -6
  99. package/src/modules/repos/actions/repo-open.ts +11 -6
  100. package/src/modules/repos/actions/repo-ref-add.ts +15 -6
  101. package/src/modules/repos/actions/repo-ref-backfill.ts +12 -6
  102. package/src/modules/repos/actions/repo-ref-check.ts +11 -6
  103. package/src/modules/repos/actions/repo-ref-clone.ts +18 -6
  104. package/src/modules/repos/actions/repo-ref-note.ts +14 -6
  105. package/src/modules/repos/actions/repo-ref-of.ts +11 -6
  106. package/src/modules/repos/actions/repo-ref-sync.ts +12 -6
  107. package/src/modules/repos/actions/repo-remote-check.ts +12 -6
  108. package/src/modules/repos/actions/repo-remote-list.ts +11 -6
  109. package/src/modules/repos/actions/repo-remote-pick.ts +12 -6
  110. package/src/modules/repos/actions/repo-remote.ts +13 -6
  111. package/src/modules/repos/actions/repo-remove.ts +11 -6
  112. package/src/modules/repos/actions/repo-scan.ts +13 -6
  113. package/src/modules/repos/actions/repo-update.ts +23 -6
  114. package/src/modules/setting/actions/setting-get.ts +11 -6
  115. package/src/modules/setting/actions/setting-set.ts +14 -6
  116. package/src/modules/system/actions/bootstrap.ts +9 -7
  117. package/src/modules/system/actions/health.ts +8 -6
  118. package/src/modules/system/actions/routes.ts +13 -6
  119. package/src/modules/system/routes.ts +1 -1
  120. package/src/modules/tasktool/actions/timegoal-check.ts +13 -6
  121. package/src/modules/tasktool/actions/timegoal-clear.ts +11 -6
  122. package/src/modules/tasktool/actions/timegoal-list.ts +11 -6
  123. package/src/modules/tasktool/actions/timegoal-log.ts +11 -6
  124. package/src/modules/tasktool/actions/timegoal-prune.ts +11 -6
  125. package/src/modules/tasktool/actions/timegoal-set.ts +13 -6
  126. package/src/modules/tasktool/actions/timegoal-show.ts +12 -6
  127. package/src/modules/tasktool/actions/timegoal-update.ts +13 -6
  128. package/src/modules/templates/actions/templates-add.ts +19 -6
  129. package/src/modules/templates/actions/templates-default.ts +15 -6
  130. package/src/modules/templates/actions/templates-list.ts +13 -6
  131. package/src/modules/templates/actions/templates-remove.ts +11 -6
  132. package/src/modules/templates/actions/templates-update.ts +17 -6
  133. package/src/modules/todo/actions/group-add.ts +12 -6
  134. package/src/modules/todo/actions/group-current.ts +11 -6
  135. package/src/modules/todo/actions/group-get.ts +11 -6
  136. package/src/modules/todo/actions/group-list.ts +11 -6
  137. package/src/modules/todo/actions/group-members.ts +11 -6
  138. package/src/modules/todo/actions/group-remove.ts +11 -6
  139. package/src/modules/todo/actions/group-update.ts +13 -6
  140. package/src/modules/todo/actions/group-use.ts +11 -6
  141. package/src/modules/todo/actions/prompt-get.ts +12 -6
  142. package/src/modules/todo/actions/prompt-remove.ts +12 -6
  143. package/src/modules/todo/actions/prompt-set.ts +13 -6
  144. package/src/modules/todo/actions/todo-add.ts +13 -6
  145. package/src/modules/todo/actions/todo-archive.ts +12 -6
  146. package/src/modules/todo/actions/todo-attach.ts +19 -6
  147. package/src/modules/todo/actions/todo-attachments.ts +14 -6
  148. package/src/modules/todo/actions/todo-done.ts +15 -6
  149. package/src/modules/todo/actions/todo-freeze.ts +14 -6
  150. package/src/modules/todo/actions/todo-get.ts +14 -6
  151. package/src/modules/todo/actions/todo-list.ts +13 -6
  152. package/src/modules/todo/actions/todo-remove.ts +14 -6
  153. package/src/modules/todo/actions/todo-unfreeze.ts +14 -6
  154. package/src/modules/todo/actions/todo-update.ts +17 -6
  155. package/src/modules/todo/actions/topic-add.ts +12 -6
  156. package/src/modules/todo/actions/topic-list.ts +11 -6
  157. package/src/modules/todo/actions/topic-remove.ts +12 -6
  158. package/src/runtime/action-base.ts +41 -1
  159. package/src/runtime/action-decorator.ts +28 -13
  160. package/src/runtime/codegen.ts +26 -41
  161. package/src/runtime/registry.ts +2 -2
  162. package/src/web/frontend/api/client.generated.ts +550 -698
  163. package/src/web/frontend/page/cloud/api.ts +99 -0
  164. package/src/web/frontend/page/cloud/index.tsx +13 -32
  165. package/src/web/frontend/page/dag/api.ts +20 -0
  166. package/src/web/frontend/page/dag/index.tsx +2 -5
  167. package/src/web/frontend/page/dir/api.ts +135 -0
  168. package/src/web/frontend/page/dir/index.tsx +37 -57
  169. package/src/web/frontend/page/dir/task-actions.ts +39 -59
  170. package/src/web/frontend/page/dir/task-chain.ts +2 -2
  171. package/src/web/frontend/page/dir/task-feedback.ts +19 -23
  172. package/src/web/frontend/page/dir/task-goal.ts +3 -3
  173. package/src/web/frontend/page/dir/task.tsx +3 -3
  174. package/src/web/frontend/page/doc/api.ts +82 -0
  175. package/src/web/frontend/page/doc/index.tsx +29 -32
  176. package/src/web/frontend/page/group/api.ts +24 -0
  177. package/src/web/frontend/page/group/index.tsx +7 -16
  178. package/src/web/frontend/page/overview/api.ts +16 -0
  179. package/src/web/frontend/page/overview/index.tsx +2 -2
  180. package/src/web/frontend/page/progress/api.ts +20 -0
  181. package/src/web/frontend/page/progress/index.tsx +3 -6
  182. package/src/web/frontend/page/refs/api.ts +14 -0
  183. package/src/web/frontend/page/refs/index.tsx +2 -4
  184. package/src/web/frontend/page/repos/api.ts +197 -0
  185. package/src/web/frontend/page/repos/bind-modals.tsx +4 -7
  186. package/src/web/frontend/page/repos/board-admin.tsx +6 -6
  187. package/src/web/frontend/page/repos/doc-search-modal.tsx +4 -4
  188. package/src/web/frontend/page/repos/index.tsx +10 -14
  189. package/src/web/frontend/page/repos/pending-section.tsx +7 -13
  190. package/src/web/frontend/page/repos/ref-panel.tsx +9 -14
  191. package/src/web/frontend/page/repos/remote-modal.tsx +4 -28
  192. package/src/web/frontend/page/repos/repo-form-modal.tsx +4 -4
  193. package/src/web/frontend/page/settings/api.ts +29 -0
  194. package/src/web/frontend/page/settings/index.tsx +3 -3
  195. package/src/web/frontend/page/settings/prompt-templates-section.tsx +4 -4
  196. package/src/web/frontend/page/settings/sidebar-section.tsx +2 -2
  197. package/src/web/public/assets/Introduction-Du_dycft.js +6 -0
  198. package/src/web/public/assets/{bar-B9WWmCpt.js → bar-B52NTf_v.js} +1 -1
  199. package/src/web/public/assets/cloud-Droja_aT.js +3 -0
  200. package/src/web/public/assets/{composer-panel-ByezS8Xv.js → composer-panel-DpiU2h50.js} +1 -1
  201. package/src/web/public/assets/dag-Ca-wjIxQ.js +1 -0
  202. package/src/web/public/assets/{deleted-panel-BcbtctNF.js → deleted-panel-K9GgfR8t.js} +1 -1
  203. package/src/web/public/assets/dir-DacRpcBt.js +5 -0
  204. package/src/web/public/assets/group-TPuU-QVc.js +2 -0
  205. package/src/web/public/assets/{index-D8MvtVAm.js → index-BkLkooKe.js} +2 -2
  206. package/src/web/public/assets/{md-history-BqZvzWiD.js → md-history-0GBWw4qr.js} +1 -1
  207. package/src/web/public/assets/overview-B3kHI66i.js +1 -0
  208. package/src/web/public/assets/progress-CdhFz0Lz.js +3 -0
  209. package/src/web/public/assets/refs-BDxfuH6R.js +1 -0
  210. package/src/web/public/assets/repos-C8jRM7wS.js +15 -0
  211. package/src/web/public/assets/{route-crumb-CWVu80du.js → route-crumb-QvahotvN.js} +1 -1
  212. package/src/web/public/assets/settings-BBcdGLTc.js +1 -0
  213. package/src/web/public/assets/{status-tag-DRl9E2Os.js → status-tag-BheHByek.js} +1 -1
  214. package/src/web/public/assets/task-CUkQaLBZ.js +11 -0
  215. package/src/web/public/assets/task-utils-_JAWRAz6.js +12 -0
  216. package/src/web/public/assets/{templates-Df__0k-F.js → templates-CbRyW3PJ.js} +1 -1
  217. package/src/web/public/assets/{tool-bar-Cv7f6p4v.js → tool-bar-BAmT-BI-.js} +1 -1
  218. package/src/web/public/index.html +1 -1
  219. package/src/modules/auth/schemas.ts +0 -27
  220. package/src/modules/bundled/schemas.ts +0 -32
  221. package/src/modules/db/schemas.ts +0 -27
  222. package/src/modules/docs/schemas.ts +0 -107
  223. package/src/modules/file/schemas.ts +0 -61
  224. package/src/modules/localtask/schemas.ts +0 -310
  225. package/src/modules/repos/schemas.ts +0 -310
  226. package/src/modules/setting/schemas.ts +0 -18
  227. package/src/modules/system/schemas.ts +0 -29
  228. package/src/modules/tasktool/schemas.ts +0 -52
  229. package/src/modules/templates/schemas.ts +0 -50
  230. package/src/modules/todo/schemas.ts +0 -177
  231. package/src/web/public/assets/Introduction-aQCeCLrV.js +0 -6
  232. package/src/web/public/assets/cloud-C4b8SU7C.js +0 -3
  233. package/src/web/public/assets/dag-jvrjx4i7.js +0 -1
  234. package/src/web/public/assets/dir-B82XBb1J.js +0 -5
  235. package/src/web/public/assets/group-BPUOO_QM.js +0 -2
  236. package/src/web/public/assets/overview-DMihuyzh.js +0 -1
  237. package/src/web/public/assets/progress-D-rMgz3w.js +0 -3
  238. package/src/web/public/assets/refs-D21jmrn6.js +0 -1
  239. package/src/web/public/assets/repos-B94tMDGs.js +0 -15
  240. package/src/web/public/assets/settings-DgTt4JG5.js +0 -1
  241. package/src/web/public/assets/task-B2x5GoV3.js +0 -11
  242. package/src/web/public/assets/task-utils-By8gLpHY.js +0 -12
@@ -1,22 +1,33 @@
1
1
  // todo.update —— 由 .tool/migrate-module.mjs 从 legacy 形态迁来(模板形态:一条 action 一个文件)。
2
2
  //
3
- // 契约常量在 ../schemas.ts(zod);本文件只做「声明 + 实现」,业务在服务层。
3
+ // 契约(zod schema)就声明在本文件里——入参类型由基类泛型模板封装;本文件只做「声明 + 实现」,业务在服务层。
4
4
  import { action } from '../../../runtime/action-decorator.js';
5
- import { ActionBase } from '../../../runtime/action-base.js';
6
- import { todoUpdateInput } from '../schemas.js';
5
+ import { z } from 'zod';
6
+ import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
7
7
  import * as serviceNs from '../service.js';
8
8
  const service: any = serviceNs;
9
9
 
10
- export class TodoUpdateAction extends ActionBase {
10
+ /** todo.update 的入参契约(CLI 与 HTTP 共用同一份)。 */
11
+ const input = z.object({
12
+ ref: z.string().describe("要改的那条的内容(整串)"),
13
+ topic: z.string().optional().describe("改成这个主题"),
14
+ text: z.string().optional().describe("改成这个内容"),
15
+ note: z.string().optional(),
16
+ matchTopic: z.string().optional().describe("消歧:同内容有多条时用主题收窄"),
17
+ pick: z.number().optional().describe("消歧:同内容多条时按编号选(配合报错里的列表)"),
18
+ group: z.number().optional().describe("工作空间 id(默认取当前)"),
19
+ });
20
+
21
+ export class TodoUpdateAction extends ActionBase<typeof input> {
11
22
  @action({
12
23
  id: 'todo.update',
13
24
  cli: ['todo', 'update'],
14
25
  http: ['PATCH', '/api/todo/item'],
15
26
  summary: '编辑任务(按内容定位,只改传入的字段)',
16
- input: todoUpdateInput,
27
+ input,
17
28
  render: (d: any) => `已更新(在 ${d.bucket}): [${d.task.topic}] ${d.task.text}`,
18
29
  })
19
- async update(ctx: any) {
30
+ override async run(ctx: ActionInput<this['_input']>) {
20
31
 
21
32
  return service.updateTodo(ctx.ref, {
22
33
  topic: ctx.topic,
@@ -1,23 +1,29 @@
1
1
  // topic.add —— 由 .tool/migrate-module.mjs 从 legacy 形态迁来(模板形态:一条 action 一个文件)。
2
2
  //
3
- // 契约常量在 ../schemas.ts(zod);本文件只做「声明 + 实现」,业务在服务层。
3
+ // 契约(zod schema)就声明在本文件里——入参类型由基类泛型模板封装;本文件只做「声明 + 实现」,业务在服务层。
4
4
  import { action } from '../../../runtime/action-decorator.js';
5
- import { ActionBase } from '../../../runtime/action-base.js';
6
- import { topicAddInput } from '../schemas.js';
5
+ import { z } from 'zod';
6
+ import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
7
7
  import * as serviceNs from '../service.js';
8
8
  const service: any = serviceNs;
9
9
 
10
- export class TopicAddAction extends ActionBase {
10
+ /** topic.add 的入参契约(CLI 与 HTTP 共用同一份)。 */
11
+ const input = z.object({
12
+ name: z.string(),
13
+ group: z.number().optional().describe("工作空间 id(默认取当前)"),
14
+ });
15
+
16
+ export class TopicAddAction extends ActionBase<typeof input> {
11
17
  @action({
12
18
  id: 'topic.add',
13
19
  cli: ['topic', 'add'],
14
20
  http: ['POST', '/api/topics'],
15
21
  summary: '加入快捷主题',
16
22
  args: ['name'],
17
- input: topicAddInput,
23
+ input,
18
24
  render: (d: any) => (d.added ? `已加入快捷主题: ${d.name}` : `${d.name} 已在快捷列表中`),
19
25
  })
20
- async add(ctx: any) {
26
+ override async run(ctx: ActionInput<this['_input']>) {
21
27
 
22
28
  return service.addTopic(ctx.name, { groupId: ctx.group });
23
29
 
@@ -1,19 +1,24 @@
1
1
  // topic.list —— 由 .tool/migrate-module.mjs 从 legacy 形态迁来(模板形态:一条 action 一个文件)。
2
2
  //
3
- // 契约常量在 ../schemas.ts(zod);本文件只做「声明 + 实现」,业务在服务层。
3
+ // 契约(zod schema)就声明在本文件里——入参类型由基类泛型模板封装;本文件只做「声明 + 实现」,业务在服务层。
4
4
  import { action } from '../../../runtime/action-decorator.js';
5
- import { ActionBase } from '../../../runtime/action-base.js';
6
- import { topicListInput } from '../schemas.js';
5
+ import { z } from 'zod';
6
+ import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
7
7
  import * as serviceNs from '../service.js';
8
8
  const service: any = serviceNs;
9
9
 
10
- export class TopicListAction extends ActionBase {
10
+ /** topic.list 的入参契约(CLI 与 HTTP 共用同一份)。 */
11
+ const input = z.object({
12
+ group: z.number().optional().describe("工作空间 id(默认取当前)"),
13
+ });
14
+
15
+ export class TopicListAction extends ActionBase<typeof input> {
11
16
  @action({
12
17
  id: 'topic.list',
13
18
  cli: ['topic', 'list'],
14
19
  http: ['GET', '/api/topics'],
15
20
  summary: '快捷主题列表(含各状态任务数)',
16
- input: topicListInput,
21
+ input,
17
22
  render: (list: any) => {
18
23
  if (!list.length) return '(暂无快捷主题)';
19
24
  const w: any = Math.max(...list.map((t: any) => t.name.length));
@@ -22,7 +27,7 @@ export class TopicListAction extends ActionBase {
22
27
  .join('\n');
23
28
  },
24
29
  })
25
- async list(ctx: any) {
30
+ override async run(ctx: ActionInput<this['_input']>) {
26
31
 
27
32
  return service.listTopics({ groupId: ctx.group });
28
33
 
@@ -1,20 +1,26 @@
1
1
  // topic.remove —— 由 .tool/migrate-module.mjs 从 legacy 形态迁来(模板形态:一条 action 一个文件)。
2
2
  //
3
- // 契约常量在 ../schemas.ts(zod);本文件只做「声明 + 实现」,业务在服务层。
3
+ // 契约(zod schema)就声明在本文件里——入参类型由基类泛型模板封装;本文件只做「声明 + 实现」,业务在服务层。
4
4
  import { action } from '../../../runtime/action-decorator.js';
5
- import { ActionBase } from '../../../runtime/action-base.js';
6
- import { topicRemoveInput } from '../schemas.js';
5
+ import { z } from 'zod';
6
+ import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
7
7
  import * as serviceNs from '../service.js';
8
8
  const service: any = serviceNs;
9
9
 
10
- export class TopicRemoveAction extends ActionBase {
10
+ /** topic.remove 的入参契约(CLI 与 HTTP 共用同一份)。 */
11
+ const input = z.object({
12
+ name: z.string(),
13
+ group: z.number().optional().describe("工作空间 id(默认取当前)"),
14
+ });
15
+
16
+ export class TopicRemoveAction extends ActionBase<typeof input> {
11
17
  @action({
12
18
  id: 'topic.remove',
13
19
  cli: ['topic', 'remove'],
14
20
  http: ['DELETE', '/api/topics'],
15
21
  summary: '移出快捷主题(不动已有任务;仍被任务使用时会在结果里提示)',
16
22
  args: ['name'],
17
- input: topicRemoveInput,
23
+ input,
18
24
  render: (d: any) => {
19
25
  if (!d.removed) return `${d.name} 本就不在快捷列表中`;
20
26
  return d.inUse
@@ -22,7 +28,7 @@ export class TopicRemoveAction extends ActionBase {
22
28
  : `已移出快捷主题: ${d.name}`;
23
29
  },
24
30
  })
25
- async remove(ctx: any) {
31
+ override async run(ctx: ActionInput<this['_input']>) {
26
32
 
27
33
  return service.removeTopic(ctx.name, { groupId: ctx.group });
28
34
 
@@ -7,8 +7,48 @@
7
7
  // ——新增依赖不必改调用方;
8
8
  // - action 类只负责「声明 + 实现」,装配(模块编排、依赖注入、注册表收集)
9
9
  // 都在基类与容器这一层。
10
+ //
11
+ // 泛型模板(#177 验收反馈):TInput 定住**入参类型**。子类把 schema 绑在类上,
12
+ // handler 的注解用统一的样板 `ctx: ActionInput<this['_input']>` 从基类推导——
13
+ // 类型只声明一次(schema 常量),不再手写 z.output、更不落 any:
14
+ //
15
+ // export class GetAction extends ActionBase<typeof localtaskGetInput> {
16
+ // @action({ id: 'localtask.get', …, input: localtaskGetInput })
17
+ // override async run(ctx: ActionInput<this['_input']>) { … }
18
+ // }
19
+ //
20
+ // 为什么注解还是不能省:TS 对类成员声明没有任何上下文类型注入通路——
21
+ // override 不从基类取参类型(repro:override 与装饰器两种形态都拿不到),
22
+ // TC39 装饰器也不给被标方法的参数做推断。幻影字段 _input + this['…'] 是
23
+ // 「注解可写、类型不重述」的唯一通路:类上的类型实参是唯一声明点。
24
+ //
25
+ // 出参没有模板——**实现即契约**:返回类型由实现推断,apiclient codegen 直接
26
+ // 从方法签名读(runtime/codegen.ts)。@action 的 meta.input 与 TInput 必须是
27
+ // 同一个 schema:装饰器把方法约束在 `(input: z.output<S>, meta?) => unknown` 上,
28
+ // 两处不一致编译期即红(action-decorator.ts)。
29
+ import type { z, ZodType } from 'zod';
10
30
  import type { Container } from './container.js';
11
31
 
12
- export abstract class ActionBase {
32
+ /** handler 入参类型:解析后的形状(z.output,.default 字段必填)。配 `this['_input']` 用。 */
33
+ export type ActionInput<S extends ZodType> = z.output<S>;
34
+
35
+ /** run 的第二参:传输通道标记。stream 的 req/res/url 走 input.__raw(api.ts 注入),不在这里。 */
36
+ export interface ActionRunMeta {
37
+ transport?: string;
38
+ }
39
+
40
+ export abstract class ActionBase<TInput extends ZodType = ZodType> {
41
+ /**
42
+ * 幻影字段:把 TInput 暴露给子类方法注解里的 `this['_input']`。
43
+ * `declare` 只存在于类型层,不产生任何运行时成员。
44
+ */
45
+ declare readonly _input: TInput;
46
+
13
47
  constructor(protected readonly deps: Container) {}
48
+
49
+ /**
50
+ * 唯一的执行入口。子类 override 它并写统一注解
51
+ * `override run(ctx: ActionInput<this['_input']>)`。
52
+ */
53
+ abstract run(input: z.output<TInput>, meta?: ActionRunMeta): unknown;
14
54
  }
@@ -1,7 +1,7 @@
1
1
  // action 装饰器:在 ModuleBase 子类的方法上声明 action(zod schema 即契约)。
2
2
  //
3
- // 单一通道:全部新业务 action 都走这里——声明(@action 元数据)与实现同文件,
4
- // 契约常量放同域 schemas.ts;模块的 actions 字段由 zodActionsOf(instance) 收集。
3
+ // 单一通道:全部新业务 action 都走这里——声明(@action 元数据)、契约(zod schema)
4
+ // 与实现同文件;模块的 actions 字段由 zodActionsOf(instance) 收集。
5
5
  // legacy plain-object action(flags 表契约)只剩 runtime 内建命令在用
6
6
  // (serve / help / version)——它们是平台命令,不是业务 action。
7
7
  // Registry / CliApp / ApiRouter 仍对两通道无感;内建命令迁进 platform 模块后,
@@ -14,13 +14,19 @@
14
14
  // 是 undefined——tsc 编译后交给原生 Node 时 context.metadata 就是 undefined,
15
15
  // 元数据会静默丢失。挂函数上与运行时无关,最稳。
16
16
  //
17
- // (b) 装饰器**不改方法签名**(TC39 要求返回类型与原方法兼容),handler 的入参类型
18
- // 只能手写 `z.output<typeof schema>`。z.input(调用方形状,.default 字段可选)
19
- // 与 z.output(解析后形状,.default 字段必填)别混:handler 拿的是 z.output。
17
+ // (b) 装饰器**不改方法签名**(TC39 要求返回类型与原方法兼容),也给不了被标方法
18
+ // 的参数做推断——handler 的入参类型走基类泛型模板:类绑
19
+ // `extends ActionBase<typeof xxxInput>`,方法注解统一写
20
+ // `run(ctx: ActionInput<this['_input']>)`(由幻影字段从类型实参推导,
21
+ // 见 action-base.ts)。装饰器因此 value 用 any **透传**:this 依赖类型
22
+ // 出了类声明不可解析,任何收紧的参数签名都会让应用点全红。
23
+ // z.input(调用方形状,.default 字段可选)与 z.output(解析后形状,
24
+ // .default 字段必填)别混:handler 拿的是 z.output。
20
25
  //
21
26
  // (c) 出参没有 schema——**实现即契约**:apiclient 的返回类型从 action 类的方法签名
22
27
  // 直接推断(codegen type-only 引类),同一信息只声明一次。
23
28
  import { describeInput, type FieldDesc } from './zod-bridge.js';
29
+ import type { ActionRunMeta } from './action-base.js';
24
30
  import type { ZodType } from 'zod';
25
31
 
26
32
  /**
@@ -39,7 +45,7 @@ export interface BoundAction {
39
45
  summary?: string;
40
46
  // meta 形参刻意与 legacy 的 run(ctx, { transport }) 同形(宽松 string 而非字面量联合):
41
47
  // Registry / CliApp / ApiRouter 把两通道 action 装进同一个数组,run 必须可互相赋值。
42
- run: (input: unknown, meta?: { transport?: string }) => unknown;
48
+ run: (input: unknown, meta?: ActionRunMeta) => unknown;
43
49
  [k: string]: unknown;
44
50
  }
45
51
 
@@ -73,15 +79,24 @@ const META = new WeakMap<object, ActionMeta>();
73
79
  * 标注一个 action 方法。用法:
74
80
  *
75
81
  * ```ts
76
- * export class SystemModule extends ModuleBase {
77
- * @action({ id: 'system.bootstrap', cli: ['bootstrap'], http: ['GET', '/api/bootstrap'],
78
- * summary: '…', input: systemBootstrapInput })
79
- * bootstrap(ctx: z.output<typeof systemBootstrapInput>) { return this.svc.bootstrap(); }
82
+ * export class XAction extends ActionBase<typeof xInput> {
83
+ * @action({ id: 'x.do', cli: ['x', 'do'], http: ['GET', '/api/x'],
84
+ * summary: '…', input: xInput })
85
+ * override async run(ctx: ActionInput<this['_input']>) { … }
80
86
  * }
81
87
  * ```
88
+ *
89
+ * 入参/出参的静态类型完全由**声明自持**(类上的 TInput 经幻影字段推导注解,
90
+ * 返回类型即实现),装饰器只收运行期元数据、不做类型层的参数对账——
91
+ * value 用 any 透传:`ActionInput<this['_input']>` 是 this 依赖类型,出了类声明
92
+ * 就不可解析,收紧 value 的签名会让每个应用点都报「装饰器签名无法解析」。
82
93
  */
83
- export function action(meta: ActionMeta) {
84
- return function <F extends (...args: never[]) => unknown>(value: F, context: { kind: string }): F {
94
+ export function action<S extends ZodType>(meta: Omit<ActionMeta, 'input'> & { input: S }) {
95
+ // value 用 any:入参注解 `ActionInput<this['_input']>` 是 this 依赖类型,出了类
96
+ // 声明不可解析——收紧成具体函数签名会让所有应用点报「装饰器签名无法解析」。
97
+ // 静态类型由声明自持(见上),这里只收元数据 + 运行期 kind 校验。
98
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- 同上
99
+ return function (value: any, context: { kind: string }): any {
85
100
  if (context.kind !== 'method') {
86
101
  throw new Error(`@action 只能标注方法(收到 kind=${context.kind})`);
87
102
  }
@@ -164,7 +179,7 @@ export function zodActionsOf(instance: object): ZodBoundAction[] {
164
179
  }
165
180
 
166
181
  const fields = describeInput(meta.input, args);
167
- const bound = method as (this: typeof instance, input: unknown, meta?: { transport?: string }) => unknown;
182
+ const bound = method as (this: typeof instance, input: unknown, meta?: ActionRunMeta) => unknown;
168
183
  out.push({
169
184
  id: meta.id,
170
185
  cli: meta.cli,
@@ -15,9 +15,10 @@
15
15
  // 只生成 zod 通道(@action 装饰)的 action;legacy flags 通道的 action 继续由前端
16
16
  // 手写 client.js 调用(迁移完成后删除)。
17
17
  //
18
- // 入参 schema 常量命名约定:<camelCase(actionId)>Input(如 system.bootstrap →
19
- // systemBootstrapInput)。约定破了 codegen 会生成指向不存在符号的 import,
20
- // tests/unit/api-client.test.mjs 的新鲜度对账会当场红。
18
+ // 入参 schema 常量**不再跨文件引用**:契约(zod)就声明在各自的 action 文件里,
19
+ // 入参类型经基类泛型模板(ActionBase<typeof input> + 幻影字段 _input)流到前端——
20
+ // 生成物只引 action 类(清单),不引契约文件,也不再依赖
21
+ // `<camelCase(actionId)>Input` 命名约定。
21
22
  //
22
23
  // 出参没有 schema——**实现即契约**:返回类型直接从 action 类的方法签名推断,
23
24
  // 同一信息只声明一次,「两份声明漂移」无从发生。
@@ -25,16 +26,9 @@ import { describeInput } from './zod-bridge.js';
25
26
  import { routeParams, type ZodBoundAction } from './action-decorator.js';
26
27
  import { cliPathsOf } from './spec.js';
27
28
 
28
- /** actionId → 入参 schema 常量名:system.bootstrap → systemBootstrapInput */
29
- export function schemaName(actionId: string): string {
30
- const parts = actionId.split(/[.\-_]/).filter(Boolean);
31
- const camel = parts
32
- .map((seg, i) => (i === 0 ? seg : seg[0]!.toUpperCase() + seg.slice(1)))
33
- .join('');
34
- return camel + 'Input';
35
- }
36
-
37
- /** 前端方法名:取 actionId 最后一段,撞名时加模块前缀(todo.get 与 repo.get → get / repoGet)。 */
29
+ /**
30
+ * 前端方法名:取 actionId 最后一段,撞名时加模块前缀(todo.get 与 repo.get → get / repoGet)。
31
+ */
38
32
  export function clientMethodNames(actions: readonly ZodBoundAction[]): Map<string, string> {
39
33
  const used = new Set<string>();
40
34
  const names = new Map<string, string>();
@@ -56,53 +50,44 @@ export function clientMethodNames(actions: readonly ZodBoundAction[]): Map<strin
56
50
  }
57
51
 
58
52
  /**
59
- * schema 常量按**模块**分组 import:一个模块一份 schemas.ts
60
- * (src/modules/<域>/schemas.ts),生成物从 src/web/frontend/api/ 算起
61
- * 的相对路径固定为 '../../../modules/<域>/schemas.js'。
53
+ * 入参类型锚点:**从 action 类反推**——类上的泛型实参(基类模板封装的 schema 类型)
54
+ * 经幻影字段 `_input` 露出,前端只引 action 类即可拿到入参形状:
55
+ *
56
+ * z.input<InstanceType<typeof LocaltaskGetAction>['_input']>
57
+ *
58
+ * 契约常量因此降级为「文件内的实现细节」——不再有独立的 schemas.ts,
59
+ * 也不再需要 `<camelCase(actionId)>Input` 命名约定(约定破了会生成指向不存在
60
+ * 符号的代码,是旧方案最大的脆弱点)。
62
61
  */
63
- function schemaModuleOf(moduleId: string): string {
64
- return `../../../modules/${moduleId}/schemas.js`;
62
+ function inputTypeOf(a: ZodBoundAction): string {
63
+ return `z.input<InstanceType<typeof ${a.className}>['_input']>`;
65
64
  }
66
65
 
67
- /** 生成前端 apiclient 的 TS 源码(type-only 引 schema:zod 不进浏览器包)。 */
66
+ /** 生成前端 apiclient 的 TS 源码(type-only 引 action 类:zod 不进浏览器包)。 */
68
67
  export function generateClientSource(actions: readonly ZodBoundAction[]): string {
69
68
  const withHttp = actions.filter((a) => a.http);
70
69
  const methodNames = clientMethodNames(withHttp);
71
70
 
72
- // 按模块分组收集两类类型锚点:入参 schema 常量(schemas.ts)+ action 类(清单)。
73
- // 返回类型不引 schema——**实现即契约**:从 action 类的方法签名直接推断。
74
- const inputTypes = new Map<string, Set<string>>();
71
+ // 类型锚点只有一类:action 类(清单)。入参形状由类上的泛型推出来,
72
+ // 返回类型则从方法签名直接推断——**实现即契约**。
75
73
  const actionClasses = new Map<string, Set<string>>();
76
74
  for (const a of withHttp) {
77
- if (describeInput(a.input, a.args ?? []).length) {
78
- const set = inputTypes.get(a.module) || new Set<string>();
79
- set.add(schemaName(a.id));
80
- inputTypes.set(a.module, set);
81
- }
82
75
  const classes = actionClasses.get(a.module) || new Set<string>();
83
76
  classes.add(a.className);
84
77
  actionClasses.set(a.module, classes);
85
78
  }
86
- const imports = [...inputTypes.entries()]
79
+ const imports = [...actionClasses.entries()]
87
80
  .sort(([a], [b]) => a.localeCompare(b))
88
81
  .map(([module, names]) => {
89
82
  const list = [...names].sort().map((n) => ` ${n},`).join('\n');
90
- return `import type {\n${list}\n} from '${schemaModuleOf(module)}';`;
83
+ return `import type {\n${list}\n} from '../../../modules/${module}/actions/_manifest.generated.js';`;
91
84
  })
92
- .concat(
93
- [...actionClasses.entries()]
94
- .sort(([a], [b]) => a.localeCompare(b))
95
- .map(([module, names]) => {
96
- const list = [...names].sort().map((n) => ` ${n},`).join('\n');
97
- return `import type {\n${list}\n} from '../../../modules/${module}/actions/_manifest.generated.js';`;
98
- }),
99
- )
100
85
  .join('\n');
101
86
 
102
87
  const iface = withHttp
103
88
  .map((a) => {
104
89
  const fields = describeInput(a.input, a.args ?? []);
105
- const paramType = `z.input<typeof ${schemaName(a.id)}>`;
90
+ const paramType = inputTypeOf(a);
106
91
  const required = fields.some((f) => f.required);
107
92
  const sig = fields.length === 0 ? '' : required ? `input: ${paramType}` : `input?: ${paramType}`;
108
93
  const doc = a.summary ? `/** ${a.summary} */\n ` : '';
@@ -112,7 +97,7 @@ export function generateClientSource(actions: readonly ZodBoundAction[]): string
112
97
 
113
98
  const impl = withHttp
114
99
  .map((a) => {
115
- const inName = schemaName(a.id);
100
+ const paramType = inputTypeOf(a);
116
101
  const methodName = methodNames.get(a.id)!;
117
102
  const [method, pattern] = a.http!;
118
103
  const params = routeParams(pattern);
@@ -124,11 +109,11 @@ export function generateClientSource(actions: readonly ZodBoundAction[]): string
124
109
  const lines: string[] = [];
125
110
  lines.push(` // action: ${a.id}`);
126
111
  const argSig =
127
- fields.length === 0 ? '' : required ? `input: z.input<typeof ${inName}>` : `input?: z.input<typeof ${inName}>`;
112
+ fields.length === 0 ? '' : required ? `input: ${paramType}` : `input?: ${paramType}`;
128
113
  lines.push(` async ${methodName}(${argSig}) {`);
129
114
  if (fields.length) {
130
115
  // 可选入参统一兜底成对象:后面的索引访问不用再判 undefined
131
- lines.push(` const inp = input ?? ({} as z.input<typeof ${inName}>);`);
116
+ lines.push(` const inp = input ?? ({} as ${paramType});`);
132
117
  }
133
118
 
134
119
  // 路径参数是位置参数(zodActionsOf 已校验 :param ⊆ args),编码后插进模板。
@@ -5,8 +5,8 @@
5
5
  // 一条 action 同时声明 cli 与 http,二者写在同一处,不可能分叉。
6
6
  //
7
7
  // 新增功能域:
8
- // 1. 写 src/modules/<name>/(模板形态:index.ts 装配 ModuleBase 子类 + schemas.ts
9
- // 契约 + actions/*.ts 一条 action 一个文件 + _manifest.generated.ts)
8
+ // 1. 写 src/modules/<name>/(模板形态:index.ts 装配 ModuleBase 子类 +
9
+ // actions/*.ts 一条 action 一个文件(契约 zod 就声明在该文件里)+ _manifest.generated.ts)
10
10
  // 2. 在下面的 create 调用里加上它的实例
11
11
  // 3. 需要面板的话,到 web/frontend/ 写视图并在前端 registry 登记——**不经过后端**
12
12
  //