@zerodep-dev/flow-ts-engine 0.0.0-stage → 1.0.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.
Files changed (219) hide show
  1. package/LICENSE +202 -0
  2. package/dist/.tsbuildinfo +1 -0
  3. package/dist/client/client.d.ts +112 -0
  4. package/dist/client/client.d.ts.map +1 -0
  5. package/dist/client/client.js +67 -0
  6. package/dist/client/client.js.map +1 -0
  7. package/dist/client/endpoint.d.ts +20 -0
  8. package/dist/client/endpoint.d.ts.map +1 -0
  9. package/dist/client/endpoint.js +153 -0
  10. package/dist/client/endpoint.js.map +1 -0
  11. package/dist/client/http.d.ts +30 -0
  12. package/dist/client/http.d.ts.map +1 -0
  13. package/dist/client/http.js +67 -0
  14. package/dist/client/http.js.map +1 -0
  15. package/dist/client/index.d.ts +12 -0
  16. package/dist/client/index.d.ts.map +1 -0
  17. package/dist/client/index.js +11 -0
  18. package/dist/client/index.js.map +1 -0
  19. package/dist/client/port.d.ts +24 -0
  20. package/dist/client/port.d.ts.map +1 -0
  21. package/dist/client/port.js +53 -0
  22. package/dist/client/port.js.map +1 -0
  23. package/dist/client/protocol.d.ts +26 -0
  24. package/dist/client/protocol.d.ts.map +1 -0
  25. package/dist/client/protocol.js +13 -0
  26. package/dist/client/protocol.js.map +1 -0
  27. package/dist/commands/admin.d.ts +41 -0
  28. package/dist/commands/admin.d.ts.map +1 -0
  29. package/dist/commands/admin.js +228 -0
  30. package/dist/commands/admin.js.map +1 -0
  31. package/dist/commands/complete.d.ts +36 -0
  32. package/dist/commands/complete.d.ts.map +1 -0
  33. package/dist/commands/complete.js +289 -0
  34. package/dist/commands/complete.js.map +1 -0
  35. package/dist/commands/dispatch.d.ts +11 -0
  36. package/dist/commands/dispatch.d.ts.map +1 -0
  37. package/dist/commands/dispatch.js +77 -0
  38. package/dist/commands/dispatch.js.map +1 -0
  39. package/dist/commands/operate.d.ts +14 -0
  40. package/dist/commands/operate.d.ts.map +1 -0
  41. package/dist/commands/operate.js +72 -0
  42. package/dist/commands/operate.js.map +1 -0
  43. package/dist/commands/operations.d.ts +75 -0
  44. package/dist/commands/operations.d.ts.map +1 -0
  45. package/dist/commands/operations.js +417 -0
  46. package/dist/commands/operations.js.map +1 -0
  47. package/dist/commands/signal.d.ts +9 -0
  48. package/dist/commands/signal.d.ts.map +1 -0
  49. package/dist/commands/signal.js +78 -0
  50. package/dist/commands/signal.js.map +1 -0
  51. package/dist/commands/start.d.ts +41 -0
  52. package/dist/commands/start.d.ts.map +1 -0
  53. package/dist/commands/start.js +186 -0
  54. package/dist/commands/start.js.map +1 -0
  55. package/dist/commands/submission.d.ts +20 -0
  56. package/dist/commands/submission.d.ts.map +1 -0
  57. package/dist/commands/submission.js +29 -0
  58. package/dist/commands/submission.js.map +1 -0
  59. package/dist/core/channels.d.ts +13 -0
  60. package/dist/core/channels.d.ts.map +1 -0
  61. package/dist/core/channels.js +13 -0
  62. package/dist/core/channels.js.map +1 -0
  63. package/dist/core/context.d.ts +76 -0
  64. package/dist/core/context.d.ts.map +1 -0
  65. package/dist/core/context.js +148 -0
  66. package/dist/core/context.js.map +1 -0
  67. package/dist/core/entities.d.ts +392 -0
  68. package/dist/core/entities.d.ts.map +1 -0
  69. package/dist/core/entities.js +282 -0
  70. package/dist/core/entities.js.map +1 -0
  71. package/dist/core/errors.d.ts +35 -0
  72. package/dist/core/errors.d.ts.map +1 -0
  73. package/dist/core/errors.js +18 -0
  74. package/dist/core/errors.js.map +1 -0
  75. package/dist/engine.d.ts +146 -0
  76. package/dist/engine.d.ts.map +1 -0
  77. package/dist/engine.js +85 -0
  78. package/dist/engine.js.map +1 -0
  79. package/dist/extensions.d.ts +198 -0
  80. package/dist/extensions.d.ts.map +1 -0
  81. package/dist/extensions.js +7 -0
  82. package/dist/extensions.js.map +1 -0
  83. package/dist/index.d.ts +19 -0
  84. package/dist/index.d.ts.map +1 -0
  85. package/dist/index.js +15 -0
  86. package/dist/index.js.map +1 -0
  87. package/dist/jobs/jobs.d.ts +27 -0
  88. package/dist/jobs/jobs.d.ts.map +1 -0
  89. package/dist/jobs/jobs.js +299 -0
  90. package/dist/jobs/jobs.js.map +1 -0
  91. package/dist/notify/collect.d.ts +38 -0
  92. package/dist/notify/collect.d.ts.map +1 -0
  93. package/dist/notify/collect.js +100 -0
  94. package/dist/notify/collect.js.map +1 -0
  95. package/dist/notify/inbox.d.ts +26 -0
  96. package/dist/notify/inbox.d.ts.map +1 -0
  97. package/dist/notify/inbox.js +87 -0
  98. package/dist/notify/inbox.js.map +1 -0
  99. package/dist/org/directory.d.ts +74 -0
  100. package/dist/org/directory.d.ts.map +1 -0
  101. package/dist/org/directory.js +254 -0
  102. package/dist/org/directory.js.map +1 -0
  103. package/dist/org/entities.d.ts +69 -0
  104. package/dist/org/entities.d.ts.map +1 -0
  105. package/dist/org/entities.js +39 -0
  106. package/dist/org/entities.js.map +1 -0
  107. package/dist/org/index.d.ts +5 -0
  108. package/dist/org/index.d.ts.map +1 -0
  109. package/dist/org/index.js +5 -0
  110. package/dist/org/index.js.map +1 -0
  111. package/dist/proxy/proxies.d.ts +18 -0
  112. package/dist/proxy/proxies.d.ts.map +1 -0
  113. package/dist/proxy/proxies.js +102 -0
  114. package/dist/proxy/proxies.js.map +1 -0
  115. package/dist/publish/project.d.ts +45 -0
  116. package/dist/publish/project.d.ts.map +1 -0
  117. package/dist/publish/project.js +176 -0
  118. package/dist/publish/project.js.map +1 -0
  119. package/dist/publish/publish.d.ts +42 -0
  120. package/dist/publish/publish.d.ts.map +1 -0
  121. package/dist/publish/publish.js +274 -0
  122. package/dist/publish/publish.js.map +1 -0
  123. package/dist/queries/queries.d.ts +24 -0
  124. package/dist/queries/queries.d.ts.map +1 -0
  125. package/dist/queries/queries.js +326 -0
  126. package/dist/queries/queries.js.map +1 -0
  127. package/dist/queries/stats.d.ts +9 -0
  128. package/dist/queries/stats.d.ts.map +1 -0
  129. package/dist/queries/stats.js +189 -0
  130. package/dist/queries/stats.js.map +1 -0
  131. package/dist/runtime/assignees.d.ts +32 -0
  132. package/dist/runtime/assignees.d.ts.map +1 -0
  133. package/dist/runtime/assignees.js +93 -0
  134. package/dist/runtime/assignees.js.map +1 -0
  135. package/dist/runtime/calls.d.ts +18 -0
  136. package/dist/runtime/calls.d.ts.map +1 -0
  137. package/dist/runtime/calls.js +182 -0
  138. package/dist/runtime/calls.js.map +1 -0
  139. package/dist/runtime/countersign.d.ts +26 -0
  140. package/dist/runtime/countersign.d.ts.map +1 -0
  141. package/dist/runtime/countersign.js +63 -0
  142. package/dist/runtime/countersign.js.map +1 -0
  143. package/dist/runtime/execution.d.ts +150 -0
  144. package/dist/runtime/execution.d.ts.map +1 -0
  145. package/dist/runtime/execution.js +792 -0
  146. package/dist/runtime/execution.js.map +1 -0
  147. package/dist/runtime/next-steps.d.ts +56 -0
  148. package/dist/runtime/next-steps.d.ts.map +1 -0
  149. package/dist/runtime/next-steps.js +145 -0
  150. package/dist/runtime/next-steps.js.map +1 -0
  151. package/dist/runtime/state.d.ts +26 -0
  152. package/dist/runtime/state.d.ts.map +1 -0
  153. package/dist/runtime/state.js +32 -0
  154. package/dist/runtime/state.js.map +1 -0
  155. package/dist/testing/scenarios.d.ts +35 -0
  156. package/dist/testing/scenarios.d.ts.map +1 -0
  157. package/dist/testing/scenarios.js +63 -0
  158. package/dist/testing/scenarios.js.map +1 -0
  159. package/dist/testing/simulate.d.ts +55 -0
  160. package/dist/testing/simulate.d.ts.map +1 -0
  161. package/dist/testing/simulate.js +122 -0
  162. package/dist/testing/simulate.js.map +1 -0
  163. package/dist/testing/testing.d.ts +31 -0
  164. package/dist/testing/testing.d.ts.map +1 -0
  165. package/dist/testing/testing.js +54 -0
  166. package/dist/testing/testing.js.map +1 -0
  167. package/dist/types.d.ts +283 -0
  168. package/dist/types.d.ts.map +1 -0
  169. package/dist/types.js +2 -0
  170. package/dist/types.js.map +1 -0
  171. package/dist/views.d.ts +317 -0
  172. package/dist/views.d.ts.map +1 -0
  173. package/dist/views.js +9 -0
  174. package/dist/views.js.map +1 -0
  175. package/package.json +76 -3
  176. package/src/client/client.ts +194 -0
  177. package/src/client/endpoint.ts +174 -0
  178. package/src/client/http.ts +99 -0
  179. package/src/client/index.ts +12 -0
  180. package/src/client/port.ts +78 -0
  181. package/src/client/protocol.ts +36 -0
  182. package/src/commands/admin.ts +308 -0
  183. package/src/commands/complete.ts +368 -0
  184. package/src/commands/dispatch.ts +106 -0
  185. package/src/commands/operate.ts +110 -0
  186. package/src/commands/operations.ts +524 -0
  187. package/src/commands/signal.ts +96 -0
  188. package/src/commands/start.ts +255 -0
  189. package/src/commands/submission.ts +51 -0
  190. package/src/core/channels.ts +14 -0
  191. package/src/core/context.ts +252 -0
  192. package/src/core/entities.ts +335 -0
  193. package/src/core/errors.ts +42 -0
  194. package/src/engine.ts +247 -0
  195. package/src/extensions.ts +231 -0
  196. package/src/index.ts +77 -0
  197. package/src/jobs/jobs.ts +320 -0
  198. package/src/notify/collect.ts +155 -0
  199. package/src/notify/inbox.ts +107 -0
  200. package/src/org/directory.ts +332 -0
  201. package/src/org/entities.ts +62 -0
  202. package/src/org/index.ts +21 -0
  203. package/src/proxy/proxies.ts +132 -0
  204. package/src/publish/project.ts +230 -0
  205. package/src/publish/publish.ts +314 -0
  206. package/src/queries/queries.ts +427 -0
  207. package/src/queries/stats.ts +207 -0
  208. package/src/runtime/assignees.ts +121 -0
  209. package/src/runtime/calls.ts +196 -0
  210. package/src/runtime/countersign.ts +83 -0
  211. package/src/runtime/execution.ts +915 -0
  212. package/src/runtime/next-steps.ts +213 -0
  213. package/src/runtime/state.ts +55 -0
  214. package/src/testing/scenarios.ts +95 -0
  215. package/src/testing/simulate.ts +190 -0
  216. package/src/testing/testing.ts +84 -0
  217. package/src/types.ts +286 -0
  218. package/src/views.ts +334 -0
  219. package/README.md +0 -3
package/src/types.ts ADDED
@@ -0,0 +1,286 @@
1
+ /**
2
+ * 引擎的选项与命令(docs/decisions/0001 第 5 节):一个入口 `engine.run(command, actor)`,命令是可辨识联合;
3
+ * 扩展点是选项里的函数,按变化点分类:谁来处理(org、resolvers)、能不能过(guards)、自动做什么(actions)、算一个值(functions)、
4
+ * 发生了什么(on)
5
+ */
6
+ import type { Adapter } from '@zerodep-dev/easy-query-ts';
7
+ import type { FlowProject } from '@zerodep-dev/flow-ts-model';
8
+ import type { ASSIGNMENTS, INSTANCE_STATUSES } from './core/entities.ts';
9
+
10
+ /** 实例的状态:草稿、进行中、已完成、已终止、已撤回、已暂停 */
11
+ export type InstanceStatus = (typeof INSTANCE_STATUSES)[number];
12
+ import type { WorkItemOperation } from './commands/operations.ts';
13
+ import type { HostModules, TransformCode } from './publish/project.ts';
14
+ import type { Actor, FlowExtensions, FlowOrg } from './extensions.ts';
15
+ import type { NotificationView } from './views.ts';
16
+ export type * from './extensions.ts';
17
+
18
+ /** 流转记录(监听拿到的、实例详情里列的) */
19
+ export interface FlowEventView {
20
+ readonly type: string;
21
+ readonly instanceId: number;
22
+ readonly workItemId: number | null;
23
+ readonly at: Date;
24
+ readonly actor: string | null;
25
+ readonly node: string | null;
26
+ readonly edge: string | null;
27
+ readonly outcome: string | null;
28
+ readonly comment: string | null;
29
+ readonly data: Readonly<Record<string, unknown>> | null;
30
+ }
31
+
32
+ /** 监听:事件类型 → 处理函数,在事务提交后执行(通知、发消息);`'*'` 收所有事件 */
33
+ export type FlowListeners = Readonly<
34
+ Record<string, (event: FlowEventView) => void | Promise<void>>
35
+ >;
36
+
37
+ /** 类型检查的一处问题 */
38
+ export interface TypeProblem {
39
+ readonly file: string;
40
+ /** 从 1 数 */
41
+ readonly line: number;
42
+ readonly column: number;
43
+ readonly code: number;
44
+ readonly message: string;
45
+ }
46
+
47
+ /** 类型检查:工程的文件与宿主模块的声明 → 问题 */
48
+ export type CheckTypes = (
49
+ project: FlowProject,
50
+ modules: HostModules,
51
+ ) => readonly TypeProblem[] | Promise<readonly TypeProblem[]>;
52
+
53
+ /** createFlowEngine 的选项 */
54
+ export interface FlowEngineOptions {
55
+ /** easy-query 的 PostgreSQL 适配器(pg 连接池或 PGlite):引擎在这个库里建自己的表 */
56
+ readonly adapter: Adapter;
57
+ /** 待办上的动作:加自定义的,同名的覆盖内置的(commands/operations.ts) */
58
+ readonly operations?: readonly WorkItemOperation[];
59
+ /** 流程工程能 import 的宿主模块(组件库、zod、业务服务……):模块名 → 导出或加载函数,带上声明给类型检查 */
60
+ readonly modules?: HostModules;
61
+ /** 流程工程的 TS / TSX 怎么编译:Node 里用 flow-ts-studio 的 compileInPlace,浏览器页面里传 Worker 编译 */
62
+ readonly transform?: TransformCode;
63
+ /** 发布流程工程前做类型检查(`@zerodep-dev/flow-ts-studio/typecheck` 的 createTypeChecker);有错不让发布 */
64
+ readonly checkTypes?: CheckTypes;
65
+ readonly org?: FlowOrg;
66
+ readonly extensions?: FlowExtensions;
67
+ readonly on?: FlowListeners;
68
+ /**
69
+ * 通知的外部投递(邮件、短信、IM):每条通知提交后交给 deliver,抛错的留在发件箱、到点作业再试(最多 5 次);
70
+ * 不给时只有站内信箱(engine.notifications)
71
+ */
72
+ readonly notifications?: {
73
+ readonly deliver?: (notification: NotificationView) => void | Promise<void>;
74
+ };
75
+ /** 处理人解析为空、节点要求交给管理员时,交给这些人 */
76
+ readonly admins?: readonly string[];
77
+ /** 时钟;测试用假时钟 */
78
+ readonly clock?: () => Date;
79
+ /** 工作日:默认周一到周五 */
80
+ readonly isWorkday?: (day: Date) => boolean;
81
+ /**
82
+ * 命令拦截:before 在执行前,可以返回改过的命令,抛错就不执行(权限、审计、改参数);
83
+ * after 在命令做完、提交之前,抛错时整个命令回滚
84
+ */
85
+ readonly intercept?: {
86
+ readonly before?: (
87
+ command: FlowCommand,
88
+ actor: Actor,
89
+ ) => FlowCommand | void | Promise<FlowCommand | void>;
90
+ readonly after?: (
91
+ command: FlowCommand,
92
+ result: RunResult,
93
+ actor: Actor,
94
+ ) => void | Promise<void>;
95
+ };
96
+ }
97
+
98
+ /** 命令:一个入口 engine.run(command, actor) */
99
+ export type FlowCommand =
100
+ /** 发起:按流程的最新启用版本;给了 draft 时从那份草稿发起(同一个实例,草稿的值加上这次给的) */
101
+ | {
102
+ readonly type: 'start';
103
+ readonly process: string;
104
+ readonly draft?: number;
105
+ readonly variables?: Readonly<Record<string, unknown>>;
106
+ readonly businessKey?: string;
107
+ readonly title?: string;
108
+ /** 给接下来要选处理人的节点选的人(startView 的 picks):节点 → 用户编号 */
109
+ readonly picks?: Readonly<Record<string, readonly (string | number)[]>>;
110
+ }
111
+ /** 待办上的动作(commands/operations.ts):认领、转办、委托、加签……;input 是动作要填的 */
112
+ | {
113
+ readonly type: 'operate';
114
+ readonly workItem: number;
115
+ readonly operation: string;
116
+ readonly input?: Readonly<Record<string, unknown>>;
117
+ }
118
+ /** 认领收件箱里的待办(operate 的简写) */
119
+ | { readonly type: 'claim'; readonly workItem: number }
120
+ /** 处理:选一个结果;退回到“运行时选”的节点时写 returnTo */
121
+ | {
122
+ readonly type: 'complete';
123
+ readonly workItem: number;
124
+ readonly outcome: string;
125
+ readonly comment?: string;
126
+ readonly variables?: Readonly<Record<string, unknown>>;
127
+ readonly returnTo?: string;
128
+ /** 给这个结果之后要选处理人的节点选的人(待办详情 outcomes 的 picks):节点 → 用户编号 */
129
+ readonly picks?: Readonly<Record<string, readonly (string | number)[]>>;
130
+ }
131
+ /** 转办:交给另一个人处理(operate 的简写) */
132
+ | {
133
+ readonly type: 'transfer';
134
+ readonly workItem: number;
135
+ readonly to: string;
136
+ readonly comment?: string;
137
+ }
138
+ /** 发起人撤回整个实例(按流程的 withdraw 设置) */
139
+ | { readonly type: 'withdraw'; readonly instance: number; readonly comment?: string }
140
+ /** 管理员终止 */
141
+ | {
142
+ readonly type: 'terminate';
143
+ readonly instance: number;
144
+ readonly comment?: string;
145
+ readonly result?: string;
146
+ }
147
+ /** 管理员暂停、恢复:暂停期间不能认领、处理,作业往后推 */
148
+ | { readonly type: 'suspend'; readonly instance: number; readonly comment?: string }
149
+ | { readonly type: 'resume'; readonly instance: number }
150
+ /** 催办:发起人或管理员催还开着的待办(不写 workItem 时催实例上全部) */
151
+ | {
152
+ readonly type: 'remind';
153
+ readonly instance: number;
154
+ readonly workItem?: number;
155
+ readonly message?: string;
156
+ }
157
+ /** 管理员改派(operate 的简写)、跳转、跳过失败的异步动作 */
158
+ | {
159
+ readonly type: 'reassign';
160
+ readonly workItem: number;
161
+ readonly to: string;
162
+ readonly comment?: string;
163
+ }
164
+ | {
165
+ readonly type: 'jump';
166
+ readonly instance: number;
167
+ readonly node: string;
168
+ readonly comment?: string;
169
+ }
170
+ | {
171
+ readonly type: 'skipJob';
172
+ readonly job: number;
173
+ readonly outcome?: string;
174
+ readonly reason?: string;
175
+ }
176
+ /**
177
+ * 管理员把实例迁到流程的另一个版本:正在用的节点按对应关系换到新版本的节点(同名的可以不写),
178
+ * 新版本里没有或类型不同时报 invalid-input,不迁;待办、运行状态、作业跟着改,记 instance.migrated
179
+ */
180
+ | {
181
+ readonly type: 'migrate';
182
+ readonly instance: number;
183
+ readonly version: number;
184
+ /** 旧节点 → 新节点 */
185
+ readonly nodes?: Readonly<Record<string, string>>;
186
+ readonly comment: string;
187
+ }
188
+ /** 管理员改单据数据:记下每个字段改前、改后的值(instance.dataChanged) */
189
+ | {
190
+ readonly type: 'changeData';
191
+ readonly instance: number;
192
+ readonly variables: Readonly<Record<string, unknown>>;
193
+ readonly comment?: string;
194
+ }
195
+ /** 留言:记进流转记录 */
196
+ | { readonly type: 'comment'; readonly instance: number; readonly text: string }
197
+ /** 手动抄送 */
198
+ | {
199
+ readonly type: 'cc';
200
+ readonly instance: number;
201
+ readonly users: readonly string[];
202
+ readonly message?: string;
203
+ };
204
+
205
+ /** 列表的筛选:流程、时间段(已办按处理的时刻,我发起的、查单据按发起的时刻) */
206
+ export interface ListFilter {
207
+ readonly processKey?: string;
208
+ readonly from?: Date | string;
209
+ readonly to?: Date | string;
210
+ }
211
+
212
+ /** 查单据(engine.query.search)的条件 */
213
+ export interface InstanceSearch extends ListFilter {
214
+ /**
215
+ * 范围:我发起的;我经手的(发起、处理过、在我的待办或我能认领的收件箱里、抄送给我);全部(只有管理员能查)
216
+ * @default 'involved'
217
+ */
218
+ readonly scope?: 'started' | 'involved' | 'all';
219
+ /** 只要这些状态的;不给时除草稿以外都要(草稿只在草稿箱里) */
220
+ readonly status?: readonly InstanceStatus[];
221
+ /** 标题或业务编号里有这段文字(不分大小写) */
222
+ readonly text?: string;
223
+ /** 第几页,从 1 开始 */
224
+ readonly page?: number;
225
+ /** 每页几行,默认 20 */
226
+ readonly size?: number;
227
+ }
228
+
229
+ /** 一页结果:这一页的行与总行数 */
230
+ export interface ResultPage<T> {
231
+ readonly rows: readonly T[];
232
+ readonly total: number;
233
+ readonly page: number;
234
+ readonly size: number;
235
+ }
236
+
237
+ /** 批量执行(engine.runMany)里一条命令的结果:各自成败,失败的带错误代号 */
238
+ export type BatchResult =
239
+ | { readonly ok: true; readonly result: RunResult }
240
+ | { readonly ok: false; readonly code: string; readonly message: string };
241
+
242
+ /** 外部事件(engine.signal):送到等这个事件的实例,按实例或业务编号找 */
243
+ export interface SignalInput {
244
+ readonly event: string;
245
+ readonly instance?: number;
246
+ readonly businessKey?: string;
247
+ readonly outcome?: string;
248
+ readonly data?: Readonly<Record<string, unknown>>;
249
+ }
250
+
251
+ /** 实例的概要 */
252
+ export interface InstanceSummary {
253
+ readonly id: number;
254
+ readonly processKey: string;
255
+ readonly version: number;
256
+ readonly status: InstanceStatus;
257
+ readonly result: string | null;
258
+ readonly title: string | null;
259
+ /** 正在处理的节点与名称 */
260
+ readonly current: readonly { readonly node: string; readonly name: string }[];
261
+ readonly variables: Readonly<Record<string, unknown>>;
262
+ }
263
+
264
+ /** 待办的概要 */
265
+ export interface WorkItemSummary {
266
+ readonly id: number;
267
+ readonly instanceId: number;
268
+ readonly node: string;
269
+ readonly nodeName: string;
270
+ readonly round: number;
271
+ readonly state: 'open' | 'waiting' | 'done' | 'canceled';
272
+ readonly assignment: (typeof ASSIGNMENTS)[number];
273
+ readonly assignee: string | null;
274
+ /** 代理:本该是谁的(他设了代理,交给了 assignee) */
275
+ readonly proxyFor: string | null;
276
+ readonly arrival: string;
277
+ readonly createdAt: Date;
278
+ readonly dueAt: Date | null;
279
+ }
280
+
281
+ /** 命令的结果:实例现在的样子、这次新建的待办、这次记下的流转记录 */
282
+ export interface RunResult {
283
+ readonly instance: InstanceSummary;
284
+ readonly workItems: readonly WorkItemSummary[];
285
+ readonly events: readonly FlowEventView[];
286
+ }
package/src/views.ts ADDED
@@ -0,0 +1,334 @@
1
+ /**
2
+ * 引擎给出的结果的形状:待办与已办的行、待办详情、发起视图、实例详情、抄送、异常、版本。
3
+ * 查询(queries/queries.ts)与命令的结果按它们给出,前端(flow-ts-ui、流程中心)按它们渲染。
4
+ */
5
+ import {
6
+ type NodeFormAccess,
7
+ type FormManifest,
8
+ type NotifyEvent,
9
+ type Outcome,
10
+ type Problem,
11
+ type ProcessDefinition,
12
+ type VariableDeclaration,
13
+ } from '@zerodep-dev/flow-ts-model';
14
+ import { type NextStep, type PickPrompt } from './runtime/next-steps.ts';
15
+ import { type InstanceRow, type WorkItemRow } from './runtime/execution.ts';
16
+ import { type OperationView } from './commands/operations.ts';
17
+ import type { Actor, FlowEventView, RunResult, TypeProblem, WorkItemSummary } from './types.ts';
18
+
19
+ /** 待办列表里的一行:待办加所属实例的标题、流程与摘要列(定义里 summary 列出的字段) */
20
+ export interface TodoItem extends WorkItemSummary {
21
+ readonly processKey: string;
22
+ readonly title: string | null;
23
+ readonly summary: Readonly<Record<string, unknown>>;
24
+ /** 实例现在的状态:已办里看得出单子结束了没有 */
25
+ readonly instanceStatus: InstanceRow['status'];
26
+ /** 处理的时间与选的结果(已办;待办时为空) */
27
+ readonly completedAt: Date | null;
28
+ readonly outcome: string | null;
29
+ /**
30
+ * 批量处理(勾几条一起同意)时选的结果:节点上第一个同意类、不要求写意见的结果;没有时这份不能批量处理,已办里为空。
31
+ * 单据没填全、要给下一步选人的,批量时由引擎逐条拒绝(runMany 的结果里写着原因)
32
+ */
33
+ readonly quickOutcome: string | null;
34
+ }
35
+
36
+ /** 退回到运行时选的节点时能选的一个:上游走到过的人工节点与它上次的处理人 */
37
+ export interface ReturnTarget {
38
+ readonly node: string;
39
+ readonly nodeName: string;
40
+ /** 上次处理它的人(退回后落回这个人) */
41
+ readonly handler: string | null;
42
+ }
43
+
44
+ /**
45
+ * 待办详情里的一个结果(能处理这份待办的人才有后面几项):选它之后会到哪些节点、要给哪些节点选处理人;
46
+ * 退回到运行时选的节点(target: 'choose')时能选的节点
47
+ */
48
+ export type OutcomeView = Outcome & {
49
+ readonly next: readonly NextStep[];
50
+ readonly picks: readonly PickPrompt[];
51
+ readonly targets: readonly ReturnTarget[];
52
+ };
53
+
54
+ /** 发起视图:流程、单据的清单与发起时的权限、默认值,接下来要选处理人的节点 */
55
+ export interface StartView {
56
+ readonly process: { readonly key: string; readonly name: string; readonly version: number };
57
+ readonly manifest: FormManifest;
58
+ readonly access: NodeFormAccess | null;
59
+ readonly values: Readonly<Record<string, unknown>>;
60
+ /** 发起后会到哪些节点 */
61
+ readonly next: readonly NextStep[];
62
+ readonly picks: readonly PickPrompt[];
63
+ }
64
+
65
+ /** 待办详情:待办、实例、能选的结果,这个人能不能认领、能不能处理、能不能转办,退回时能选的节点 */
66
+ export interface WorkItemDetail {
67
+ readonly workItem: WorkItemRow;
68
+ readonly instance: InstanceRow;
69
+ readonly outcomes: readonly OutcomeView[];
70
+ readonly claimable: boolean;
71
+ /** 能选结果处理:是候选人,待办开着,不在委托中(委托出去的由受托人办完交回) */
72
+ readonly completable: boolean;
73
+ /** 处理前暂存的值与意见:只有处理人看得到,别人是 null */
74
+ readonly draft: WorkItemRow['draft'];
75
+ /** 这个人此刻能做的动作(认领、转办、委托、加签……)与要填的 */
76
+ readonly operations: readonly OperationView[];
77
+ /**
78
+ * 单据的字段在这一步的样子:流程声明的变量按环节的表单权限(node.form)算,隐藏的不列;
79
+ * 不是候选人(只是来看的)时一律只读
80
+ */
81
+ readonly fields: readonly WorkItemField[];
82
+ }
83
+
84
+ /** 待办详情里的一个字段 */
85
+ export interface WorkItemField {
86
+ readonly name: string;
87
+ readonly label: string;
88
+ readonly type: VariableDeclaration['type'];
89
+ readonly value: unknown;
90
+ readonly editable: boolean;
91
+ readonly required: boolean;
92
+ }
93
+
94
+ /** 抄送列表里的一行 */
95
+ export interface CcItem {
96
+ readonly id: number;
97
+ readonly instanceId: number;
98
+ /** 抄送节点;手动抄送时为空 */
99
+ readonly node: string | null;
100
+ readonly recipient: string;
101
+ /** 谁抄送的;抄送节点时为空 */
102
+ readonly sender: string | null;
103
+ readonly message: string | null;
104
+ readonly at: Date;
105
+ readonly readAt: Date | null;
106
+ readonly processKey: string;
107
+ readonly title: string | null;
108
+ readonly status: InstanceRow['status'];
109
+ }
110
+
111
+ /** 失败的作业(异常) */
112
+ export interface Incident {
113
+ readonly jobId: number;
114
+ readonly instanceId: number;
115
+ readonly instanceTitle: string | null;
116
+ readonly kind: string;
117
+ readonly node: string | null;
118
+ readonly nodeName: string | null;
119
+ readonly attempts: number;
120
+ readonly error: string | null;
121
+ /** 异步动作能跳过(按选的结果往下走) */
122
+ readonly skippable: boolean;
123
+ /** 跳过时能选的结果 */
124
+ readonly outcomes: readonly string[];
125
+ }
126
+
127
+ /** 实例详情 */
128
+ export interface InstanceDetail {
129
+ readonly instance: InstanceRow;
130
+ /** 实例按的那个版本的定义(画流程图) */
131
+ readonly definition: ProcessDefinition;
132
+ /** 正在处理的节点与名称 */
133
+ readonly current: readonly { readonly node: string; readonly name: string }[];
134
+ readonly workItems: readonly WorkItemSummary[];
135
+ readonly events: readonly FlowEventView[];
136
+ /** 看的人此刻能对实例做的(query.instance 给了 actor 时算,否则都是 false) */
137
+ readonly actions: InstanceActions;
138
+ }
139
+
140
+ /** 实例上能做的:页面按它显示按钮,规则只在引擎里 */
141
+ export interface InstanceActions {
142
+ /** 发起人撤回(按流程的 withdraw 设置) */
143
+ readonly withdraw: boolean;
144
+ /** 发起人或管理员催还开着的待办 */
145
+ readonly remind: boolean;
146
+ /** 管理员的干预:暂停或恢复、终止、跳转、改派、改单据、迁移版本 */
147
+ readonly manage: boolean;
148
+ }
149
+
150
+ /** 发布的选项 */
151
+ export interface PublishOptions {
152
+ readonly actor?: Actor;
153
+ /** 发布说明 */
154
+ readonly note?: string;
155
+ }
156
+
157
+ /** 一个已发布的版本 */
158
+ export interface VersionInfo {
159
+ readonly id: number;
160
+ readonly version: number;
161
+ readonly name: string;
162
+ readonly enabled: boolean;
163
+ readonly publishedBy: string | null;
164
+ readonly publishedAt: Date;
165
+ readonly note: string | null;
166
+ }
167
+
168
+ /**
169
+ * 检查(engine.check):编译、单据并进去、校验、类型检查都做一遍,不发布。工作室边改边查用。
170
+ * 某个文件编译不过时 error 写着原因与文件(field),其余为空
171
+ */
172
+ export interface CheckResult {
173
+ /** 编译后、单据并进去的定义 */
174
+ readonly definition: ProcessDefinition | null;
175
+ /** 定义、logic 引用、单据清单的问题(含警告) */
176
+ readonly problems: readonly Problem[];
177
+ readonly types: readonly TypeProblem[];
178
+ readonly error: { readonly message: string; readonly field: string | null } | null;
179
+ }
180
+
181
+ /** 迁移预览里的一张单:正在用的节点在目标版本里对应到哪 */
182
+ export interface MigrationCandidate {
183
+ readonly instance: number;
184
+ readonly title: string | null;
185
+ readonly status: InstanceRow['status'];
186
+ /** 现在按的版本 */
187
+ readonly version: number;
188
+ /**
189
+ * 正在用的节点(正在处理的、开着或在等加签的待办所在的):target 是目标版本里同名同类型的节点,没有时为空;
190
+ * choices 是目标版本里同类型的节点,手动对应时从中选(migrate 命令的 nodes)
191
+ */
192
+ readonly nodes: readonly {
193
+ readonly node: string;
194
+ readonly name: string;
195
+ readonly target: string | null;
196
+ readonly choices: readonly { readonly node: string; readonly name: string }[];
197
+ }[];
198
+ /** 都对应得上,能直接迁(不用写节点的对应) */
199
+ readonly ready: boolean;
200
+ }
201
+
202
+ /** 一条通知(我的通知、外部投递拿到的):文案由界面按 event 拼,message 是流程配了模板时渲染好的文字 */
203
+ export interface NotificationView {
204
+ readonly id: number;
205
+ readonly recipient: string;
206
+ readonly event: NotifyEvent;
207
+ readonly instanceId: number;
208
+ readonly workItemId: number | null;
209
+ readonly node: string | null;
210
+ readonly nodeName: string | null;
211
+ readonly processKey: string;
212
+ /** 当时实例的标题 */
213
+ readonly title: string | null;
214
+ readonly message: string | null;
215
+ /** 谁的动作引起的(催办、抄送的人) */
216
+ readonly sender: string | null;
217
+ readonly createdAt: Date;
218
+ readonly readAt: Date | null;
219
+ }
220
+
221
+ /** 一条代理规则(docs/decisions/0010 第 3 节) */
222
+ export interface ProxyView {
223
+ readonly id: number;
224
+ /** 委托人:不在的那个人 */
225
+ readonly principal: string;
226
+ /** 代理人 */
227
+ readonly agent: string;
228
+ /** 哪些流程;空是全部 */
229
+ readonly processKeys: readonly string[];
230
+ readonly startsAt: Date;
231
+ /** 结束;为空是一直到撤销 */
232
+ readonly endsAt: Date | null;
233
+ readonly note: string | null;
234
+ readonly createdAt: Date;
235
+ /** 这一刻在生效(开始了、没结束) */
236
+ readonly active: boolean;
237
+ }
238
+
239
+ /** 设一条代理 */
240
+ export interface ProxyInput {
241
+ /** 替谁设(管理员才能写别人);不写是自己 */
242
+ readonly principal?: string;
243
+ readonly agent: string;
244
+ readonly processKeys?: readonly string[];
245
+ /** 不写是现在 */
246
+ readonly startsAt?: Date;
247
+ /** 不写是一直到撤销 */
248
+ readonly endsAt?: Date | null;
249
+ readonly note?: string;
250
+ }
251
+
252
+ /** 统计的范围 */
253
+ export interface StatsFilter {
254
+ /** 不写是 to 往前 30 天 */
255
+ readonly from?: Date;
256
+ /** 不写是现在 */
257
+ readonly to?: Date;
258
+ readonly processKey?: string;
259
+ /** 按天的趋势用哪个时区分日子(IANA 名,如 Asia/Shanghai);不写是 UTC */
260
+ readonly timeZone?: string;
261
+ }
262
+
263
+ /** 监控看板的数(docs/decisions/0010 第 4 节) */
264
+ export interface FlowStats {
265
+ readonly from: Date;
266
+ readonly to: Date;
267
+ readonly totals: {
268
+ /** 进行中(含暂停)的实例 */
269
+ readonly active: number;
270
+ /** 这段时间发起的、结束的;结束里没走完的(终止、撤回) */
271
+ readonly started: number;
272
+ readonly finished: number;
273
+ readonly rejected: number;
274
+ /** 现在开着的待办(落到人的)、其中超时的 */
275
+ readonly open: number;
276
+ readonly overdue: number;
277
+ /** 失败的作业(异常) */
278
+ readonly incidents: number;
279
+ };
280
+ /** 各流程:进行中、这段时间发起、结束、平均走多久(小时) */
281
+ readonly processes: readonly {
282
+ readonly processKey: string;
283
+ readonly active: number;
284
+ readonly started: number;
285
+ readonly finished: number;
286
+ readonly averageHours: number | null;
287
+ }[];
288
+ /** 各环节:这段时间办了几份、平均停多久(小时)、超时几份;慢的在前(瓶颈) */
289
+ readonly nodes: readonly {
290
+ readonly processKey: string;
291
+ readonly node: string;
292
+ readonly nodeName: string;
293
+ readonly done: number;
294
+ readonly averageHours: number;
295
+ readonly overdue: number;
296
+ }[];
297
+ /** 谁手上压着待办:开着的、其中超时的;多的在前 */
298
+ readonly workload: readonly {
299
+ readonly user: string;
300
+ readonly open: number;
301
+ readonly overdue: number;
302
+ }[];
303
+ /** 按天:发起、结束 */
304
+ readonly daily: readonly {
305
+ readonly date: string;
306
+ readonly started: number;
307
+ readonly finished: number;
308
+ }[];
309
+ }
310
+
311
+ /** 全部流程里的一个:最新一版的信息,加上流程的键、发布过几版、现在能不能发起 */
312
+ export interface CatalogEntry extends VersionInfo {
313
+ readonly key: string;
314
+ readonly versions: number;
315
+ /** 有哪一版是启用的(能发起) */
316
+ readonly startable: boolean;
317
+ }
318
+
319
+ /** 带单据类型的流程 */
320
+ export interface TypedProcess<V extends object> {
321
+ start(
322
+ input: { readonly variables: V; readonly title?: string; readonly businessKey?: string },
323
+ actor: Actor,
324
+ ): Promise<RunResult>;
325
+ complete(
326
+ input: {
327
+ readonly workItem: number;
328
+ readonly outcome: string;
329
+ readonly variables?: Partial<V>;
330
+ readonly comment?: string;
331
+ },
332
+ actor: Actor,
333
+ ): Promise<RunResult>;
334
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.