@zerodep-dev/flow-ts-engine 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/client/client.d.ts +112 -0
- package/dist/client/client.d.ts.map +1 -0
- package/dist/client/client.js +67 -0
- package/dist/client/client.js.map +1 -0
- package/dist/client/endpoint.d.ts +20 -0
- package/dist/client/endpoint.d.ts.map +1 -0
- package/dist/client/endpoint.js +153 -0
- package/dist/client/endpoint.js.map +1 -0
- package/dist/client/http.d.ts +30 -0
- package/dist/client/http.d.ts.map +1 -0
- package/dist/client/http.js +67 -0
- package/dist/client/http.js.map +1 -0
- package/dist/client/index.d.ts +12 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +11 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/port.d.ts +24 -0
- package/dist/client/port.d.ts.map +1 -0
- package/dist/client/port.js +53 -0
- package/dist/client/port.js.map +1 -0
- package/dist/client/protocol.d.ts +26 -0
- package/dist/client/protocol.d.ts.map +1 -0
- package/dist/client/protocol.js +13 -0
- package/dist/client/protocol.js.map +1 -0
- package/dist/commands/admin.d.ts +41 -0
- package/dist/commands/admin.d.ts.map +1 -0
- package/dist/commands/admin.js +228 -0
- package/dist/commands/admin.js.map +1 -0
- package/dist/commands/complete.d.ts +36 -0
- package/dist/commands/complete.d.ts.map +1 -0
- package/dist/commands/complete.js +289 -0
- package/dist/commands/complete.js.map +1 -0
- package/dist/commands/dispatch.d.ts +11 -0
- package/dist/commands/dispatch.d.ts.map +1 -0
- package/dist/commands/dispatch.js +77 -0
- package/dist/commands/dispatch.js.map +1 -0
- package/dist/commands/operate.d.ts +14 -0
- package/dist/commands/operate.d.ts.map +1 -0
- package/dist/commands/operate.js +72 -0
- package/dist/commands/operate.js.map +1 -0
- package/dist/commands/operations.d.ts +75 -0
- package/dist/commands/operations.d.ts.map +1 -0
- package/dist/commands/operations.js +417 -0
- package/dist/commands/operations.js.map +1 -0
- package/dist/commands/signal.d.ts +9 -0
- package/dist/commands/signal.d.ts.map +1 -0
- package/dist/commands/signal.js +78 -0
- package/dist/commands/signal.js.map +1 -0
- package/dist/commands/start.d.ts +41 -0
- package/dist/commands/start.d.ts.map +1 -0
- package/dist/commands/start.js +186 -0
- package/dist/commands/start.js.map +1 -0
- package/dist/commands/submission.d.ts +20 -0
- package/dist/commands/submission.d.ts.map +1 -0
- package/dist/commands/submission.js +29 -0
- package/dist/commands/submission.js.map +1 -0
- package/dist/core/channels.d.ts +13 -0
- package/dist/core/channels.d.ts.map +1 -0
- package/dist/core/channels.js +13 -0
- package/dist/core/channels.js.map +1 -0
- package/dist/core/context.d.ts +76 -0
- package/dist/core/context.d.ts.map +1 -0
- package/dist/core/context.js +148 -0
- package/dist/core/context.js.map +1 -0
- package/dist/core/entities.d.ts +392 -0
- package/dist/core/entities.d.ts.map +1 -0
- package/dist/core/entities.js +282 -0
- package/dist/core/entities.js.map +1 -0
- package/dist/core/errors.d.ts +35 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +18 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/engine.d.ts +146 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +85 -0
- package/dist/engine.js.map +1 -0
- package/dist/extensions.d.ts +198 -0
- package/dist/extensions.d.ts.map +1 -0
- package/dist/extensions.js +7 -0
- package/dist/extensions.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/jobs/jobs.d.ts +27 -0
- package/dist/jobs/jobs.d.ts.map +1 -0
- package/dist/jobs/jobs.js +299 -0
- package/dist/jobs/jobs.js.map +1 -0
- package/dist/notify/collect.d.ts +38 -0
- package/dist/notify/collect.d.ts.map +1 -0
- package/dist/notify/collect.js +100 -0
- package/dist/notify/collect.js.map +1 -0
- package/dist/notify/inbox.d.ts +26 -0
- package/dist/notify/inbox.d.ts.map +1 -0
- package/dist/notify/inbox.js +87 -0
- package/dist/notify/inbox.js.map +1 -0
- package/dist/org/directory.d.ts +74 -0
- package/dist/org/directory.d.ts.map +1 -0
- package/dist/org/directory.js +254 -0
- package/dist/org/directory.js.map +1 -0
- package/dist/org/entities.d.ts +69 -0
- package/dist/org/entities.d.ts.map +1 -0
- package/dist/org/entities.js +39 -0
- package/dist/org/entities.js.map +1 -0
- package/dist/org/index.d.ts +5 -0
- package/dist/org/index.d.ts.map +1 -0
- package/dist/org/index.js +5 -0
- package/dist/org/index.js.map +1 -0
- package/dist/proxy/proxies.d.ts +18 -0
- package/dist/proxy/proxies.d.ts.map +1 -0
- package/dist/proxy/proxies.js +102 -0
- package/dist/proxy/proxies.js.map +1 -0
- package/dist/publish/project.d.ts +45 -0
- package/dist/publish/project.d.ts.map +1 -0
- package/dist/publish/project.js +176 -0
- package/dist/publish/project.js.map +1 -0
- package/dist/publish/publish.d.ts +42 -0
- package/dist/publish/publish.d.ts.map +1 -0
- package/dist/publish/publish.js +274 -0
- package/dist/publish/publish.js.map +1 -0
- package/dist/queries/queries.d.ts +24 -0
- package/dist/queries/queries.d.ts.map +1 -0
- package/dist/queries/queries.js +326 -0
- package/dist/queries/queries.js.map +1 -0
- package/dist/queries/stats.d.ts +9 -0
- package/dist/queries/stats.d.ts.map +1 -0
- package/dist/queries/stats.js +189 -0
- package/dist/queries/stats.js.map +1 -0
- package/dist/runtime/assignees.d.ts +32 -0
- package/dist/runtime/assignees.d.ts.map +1 -0
- package/dist/runtime/assignees.js +93 -0
- package/dist/runtime/assignees.js.map +1 -0
- package/dist/runtime/calls.d.ts +18 -0
- package/dist/runtime/calls.d.ts.map +1 -0
- package/dist/runtime/calls.js +182 -0
- package/dist/runtime/calls.js.map +1 -0
- package/dist/runtime/countersign.d.ts +26 -0
- package/dist/runtime/countersign.d.ts.map +1 -0
- package/dist/runtime/countersign.js +63 -0
- package/dist/runtime/countersign.js.map +1 -0
- package/dist/runtime/execution.d.ts +150 -0
- package/dist/runtime/execution.d.ts.map +1 -0
- package/dist/runtime/execution.js +792 -0
- package/dist/runtime/execution.js.map +1 -0
- package/dist/runtime/next-steps.d.ts +56 -0
- package/dist/runtime/next-steps.d.ts.map +1 -0
- package/dist/runtime/next-steps.js +145 -0
- package/dist/runtime/next-steps.js.map +1 -0
- package/dist/runtime/state.d.ts +26 -0
- package/dist/runtime/state.d.ts.map +1 -0
- package/dist/runtime/state.js +32 -0
- package/dist/runtime/state.js.map +1 -0
- package/dist/testing/scenarios.d.ts +35 -0
- package/dist/testing/scenarios.d.ts.map +1 -0
- package/dist/testing/scenarios.js +63 -0
- package/dist/testing/scenarios.js.map +1 -0
- package/dist/testing/simulate.d.ts +55 -0
- package/dist/testing/simulate.d.ts.map +1 -0
- package/dist/testing/simulate.js +122 -0
- package/dist/testing/simulate.js.map +1 -0
- package/dist/testing/testing.d.ts +31 -0
- package/dist/testing/testing.d.ts.map +1 -0
- package/dist/testing/testing.js +54 -0
- package/dist/testing/testing.js.map +1 -0
- package/dist/types.d.ts +283 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/views.d.ts +317 -0
- package/dist/views.d.ts.map +1 -0
- package/dist/views.js +9 -0
- package/dist/views.js.map +1 -0
- package/package.json +76 -3
- package/src/client/client.ts +194 -0
- package/src/client/endpoint.ts +174 -0
- package/src/client/http.ts +99 -0
- package/src/client/index.ts +12 -0
- package/src/client/port.ts +78 -0
- package/src/client/protocol.ts +36 -0
- package/src/commands/admin.ts +308 -0
- package/src/commands/complete.ts +368 -0
- package/src/commands/dispatch.ts +106 -0
- package/src/commands/operate.ts +110 -0
- package/src/commands/operations.ts +524 -0
- package/src/commands/signal.ts +96 -0
- package/src/commands/start.ts +255 -0
- package/src/commands/submission.ts +51 -0
- package/src/core/channels.ts +14 -0
- package/src/core/context.ts +252 -0
- package/src/core/entities.ts +335 -0
- package/src/core/errors.ts +42 -0
- package/src/engine.ts +247 -0
- package/src/extensions.ts +231 -0
- package/src/index.ts +77 -0
- package/src/jobs/jobs.ts +320 -0
- package/src/notify/collect.ts +155 -0
- package/src/notify/inbox.ts +107 -0
- package/src/org/directory.ts +332 -0
- package/src/org/entities.ts +62 -0
- package/src/org/index.ts +21 -0
- package/src/proxy/proxies.ts +132 -0
- package/src/publish/project.ts +230 -0
- package/src/publish/publish.ts +314 -0
- package/src/queries/queries.ts +427 -0
- package/src/queries/stats.ts +207 -0
- package/src/runtime/assignees.ts +121 -0
- package/src/runtime/calls.ts +196 -0
- package/src/runtime/countersign.ts +83 -0
- package/src/runtime/execution.ts +915 -0
- package/src/runtime/next-steps.ts +213 -0
- package/src/runtime/state.ts +55 -0
- package/src/testing/scenarios.ts +95 -0
- package/src/testing/simulate.ts +190 -0
- package/src/testing/testing.ts +84 -0
- package/src/types.ts +286 -0
- package/src/views.ts +334 -0
- package/README.md +0 -3
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 预测下一步(Java 场景 preview-skip-sign、purchase-views、pick):发起页、待办详情按选的结果往下看会到哪些节点、谁处理。
|
|
3
|
+
* - 按模型包的 selectEdges 选边,穿过网关与抄送;会被自动跳过的人工节点(处理人就是发起人、与上一步相同)不停,按“同意”接着看;
|
|
4
|
+
* - 会签列出参与的每个人,单人的列出那个人,落到角色、部门(收件箱)的说 inbox;结束、自动节点列出来但不往后看。
|
|
5
|
+
*
|
|
6
|
+
* 上一步选下一步的处理人:节点的处理人写 `{ pick: { from?, max? } }` 时,由走到它之前的那一步选人。预测里带上要选人的节点与能选的人,
|
|
7
|
+
* 提交时查(没选、选了不能选的人、选多了),记进运行状态的 picks,走到那个节点时由选的人处理(assignees.ts)。
|
|
8
|
+
*/
|
|
9
|
+
import {
|
|
10
|
+
selectEdges,
|
|
11
|
+
type ProcessDefinition,
|
|
12
|
+
type ProcessGraph,
|
|
13
|
+
type Outcome,
|
|
14
|
+
type ProcessNode,
|
|
15
|
+
type RouteInput,
|
|
16
|
+
type TaskNode,
|
|
17
|
+
} from '@zerodep-dev/flow-ts-model';
|
|
18
|
+
import { expandToUsers, resolveCandidates, type ResolveScope } from './assignees.ts';
|
|
19
|
+
import { FlowError } from '../core/errors.ts';
|
|
20
|
+
import type { Execution } from './execution.ts';
|
|
21
|
+
import type { FlowEngineOptions } from '../types.ts';
|
|
22
|
+
|
|
23
|
+
/** 一个要选处理人的下一步 */
|
|
24
|
+
export interface PickPrompt {
|
|
25
|
+
/** 节点 */
|
|
26
|
+
readonly node: string;
|
|
27
|
+
/** 节点的名字 */
|
|
28
|
+
readonly nodeName: string;
|
|
29
|
+
/** 最多选几个;不限时为 null */
|
|
30
|
+
readonly max: number | null;
|
|
31
|
+
/** 能选的人(用户编号);不限时为 null(从整个组织里选) */
|
|
32
|
+
readonly candidates: readonly string[] | null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** 预测的一个下一步 */
|
|
36
|
+
export interface NextStep {
|
|
37
|
+
readonly node: string;
|
|
38
|
+
readonly nodeName: string;
|
|
39
|
+
/** 节点类型:task、end、service…… */
|
|
40
|
+
readonly type: ProcessNode['type'];
|
|
41
|
+
/** 处理的人(用户编号):单人的那一个、会签的每一个;进收件箱、要上一步选人时是空的 */
|
|
42
|
+
readonly handlers: readonly string[];
|
|
43
|
+
/** 进收件箱(角色、部门里谁有空谁认领) */
|
|
44
|
+
readonly inbox: boolean;
|
|
45
|
+
/** 要上一步选处理人时:能选的人与最多几个 */
|
|
46
|
+
readonly pick: PickPrompt | null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 提交时选的人:节点 → 用户编号 */
|
|
50
|
+
export type Picks = Readonly<Record<string, readonly (string | number)[]>>;
|
|
51
|
+
|
|
52
|
+
/** 预测时要知道的:图、定义的设置、解析处理人、发起人与这一步的处理人(自动跳过按它们判断) */
|
|
53
|
+
export interface PredictScope extends ResolveScope {
|
|
54
|
+
readonly graph: ProcessGraph;
|
|
55
|
+
readonly definition: ProcessDefinition;
|
|
56
|
+
/** 刚处理完的人(发起时是发起人) */
|
|
57
|
+
readonly previous: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** 预测时穿过去的节点:网关与抄送 */
|
|
61
|
+
const PASS_THROUGH: ReadonlySet<string> = new Set(['exclusive', 'inclusive', 'parallel', 'cc']);
|
|
62
|
+
|
|
63
|
+
/** 节点的 `{ pick }` 来源 */
|
|
64
|
+
function pickOf(node: TaskNode) {
|
|
65
|
+
for (const source of node.assignees ?? []) if ('pick' in source) return source.pick;
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** 没写处理人时用所在泳道的收件箱(同 execution.ts) */
|
|
70
|
+
function sourcesOf(graph: ProcessGraph, node: TaskNode) {
|
|
71
|
+
if (node.assignees) return node.assignees;
|
|
72
|
+
const inbox = graph.lane(node.lane)?.inbox;
|
|
73
|
+
if (!inbox) return [];
|
|
74
|
+
if ('role' in inbox) return [{ role: inbox.role }];
|
|
75
|
+
if ('department' in inbox) return [{ department: inbox.department }];
|
|
76
|
+
return [{ group: inbox.group, id: inbox.id }];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** 从一个节点按结果往下看 */
|
|
80
|
+
export async function nextSteps(
|
|
81
|
+
scope: PredictScope,
|
|
82
|
+
from: string,
|
|
83
|
+
input: RouteInput,
|
|
84
|
+
): Promise<NextStep[]> {
|
|
85
|
+
const steps: NextStep[] = [];
|
|
86
|
+
const seen = new Set<string>();
|
|
87
|
+
const base = (node: ProcessNode) => ({ node: node.id, nodeName: node.name, type: node.type });
|
|
88
|
+
const walk = async (id: string, outcome: string | null): Promise<void> => {
|
|
89
|
+
for (const edge of selectEdges(scope.graph, id, { read: input.read, outcome })) {
|
|
90
|
+
const node = scope.graph.node(edge.to);
|
|
91
|
+
if (!node || seen.has(node.id)) continue;
|
|
92
|
+
seen.add(node.id);
|
|
93
|
+
if (PASS_THROUGH.has(node.type)) {
|
|
94
|
+
await walk(node.id, null);
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (node.type !== 'task') {
|
|
98
|
+
steps.push({ ...base(node), handlers: [], inbox: false, pick: null });
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const pick = pickOf(node);
|
|
102
|
+
if (pick) {
|
|
103
|
+
const candidates = pick.from
|
|
104
|
+
? await expandToUsers(await resolveCandidates(pick.from, scope), scope.options)
|
|
105
|
+
: null;
|
|
106
|
+
steps.push({
|
|
107
|
+
...base(node),
|
|
108
|
+
handlers: [],
|
|
109
|
+
inbox: false,
|
|
110
|
+
pick: { node: node.id, nodeName: node.name, max: pick.max ?? null, candidates },
|
|
111
|
+
});
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (node.multi) {
|
|
115
|
+
const sources = Array.isArray(node.multi.participants)
|
|
116
|
+
? node.multi.participants
|
|
117
|
+
: [{ user: node.multi.participants as never }];
|
|
118
|
+
const users = await expandToUsers(await resolveCandidates(sources, scope), scope.options);
|
|
119
|
+
steps.push({ ...base(node), handlers: users, inbox: false, pick: null });
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const candidates = await resolveCandidates(sourcesOf(scope.graph, node), scope);
|
|
123
|
+
const direct =
|
|
124
|
+
candidates.length === 1 && candidates[0]!.kind === 'user' ? candidates[0]!.value : null;
|
|
125
|
+
// 会被自动跳过:按“同意”接着往下看(同 execution.ts 的 arriveTask)
|
|
126
|
+
const skip = node.autoSkip ?? scope.definition.settings?.autoSkip;
|
|
127
|
+
const approve = node.outcomes.find((o) => (o.kind ?? 'approve') === 'approve');
|
|
128
|
+
const skipped =
|
|
129
|
+
direct !== null &&
|
|
130
|
+
approve !== undefined &&
|
|
131
|
+
((skip?.initiator && direct === scope.context.instance.startedBy) ||
|
|
132
|
+
(skip?.sameAsPrevious && direct === scope.previous));
|
|
133
|
+
if (skipped) {
|
|
134
|
+
await walk(node.id, approve.key);
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
steps.push({
|
|
138
|
+
...base(node),
|
|
139
|
+
handlers: direct === null ? [] : [direct],
|
|
140
|
+
inbox: direct === null && candidates.length > 0,
|
|
141
|
+
pick: null,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
await walk(from, input.outcome ?? null);
|
|
146
|
+
return steps;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** 预测里要选处理人的节点 */
|
|
150
|
+
export const picksOf = (steps: readonly NextStep[]): PickPrompt[] =>
|
|
151
|
+
steps.flatMap((step) => (step.pick ? [step.pick] : []));
|
|
152
|
+
|
|
153
|
+
/** 查提交的选人:每个要选的节点都选了、选的人能选、没选多;通过时返回整理好的(编号是文字) */
|
|
154
|
+
export function checkPicks(
|
|
155
|
+
prompts: readonly PickPrompt[],
|
|
156
|
+
given: Picks | undefined,
|
|
157
|
+
): Record<string, string[]> {
|
|
158
|
+
const picks: Record<string, string[]> = {};
|
|
159
|
+
const errors: { field: string; code: string }[] = [];
|
|
160
|
+
for (const prompt of prompts) {
|
|
161
|
+
const ids = [...new Set((given?.[prompt.node] ?? []).map(String))];
|
|
162
|
+
const field = `picks.${prompt.node}`;
|
|
163
|
+
if (ids.length === 0) errors.push({ field, code: 'required' });
|
|
164
|
+
else if (prompt.candidates && ids.some((id) => !prompt.candidates!.includes(id)))
|
|
165
|
+
errors.push({ field, code: 'not-allowed' });
|
|
166
|
+
else if (prompt.max !== null && ids.length > prompt.max)
|
|
167
|
+
errors.push({ field, code: 'too-many' });
|
|
168
|
+
else picks[prompt.node] = ids;
|
|
169
|
+
}
|
|
170
|
+
const [first] = errors;
|
|
171
|
+
if (first) {
|
|
172
|
+
const name = prompts.find((p) => `picks.${p.node}` === first.field)?.nodeName ?? first.field;
|
|
173
|
+
throw new FlowError(
|
|
174
|
+
'invalid-input',
|
|
175
|
+
first.code === 'required' ? `要给“${name}”选处理人` : `给“${name}”选的人不对`,
|
|
176
|
+
{ field: first.field, code: first.code, errors },
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
return picks;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** 预测下一步用的:解析处理人、图与设置,previous 是刚处理完的人(自动跳过按它判断) */
|
|
183
|
+
export function predictScope(
|
|
184
|
+
options: FlowEngineOptions,
|
|
185
|
+
exec: Execution,
|
|
186
|
+
previous: string,
|
|
187
|
+
): PredictScope {
|
|
188
|
+
return {
|
|
189
|
+
context: exec.context(),
|
|
190
|
+
handledBy: exec.state.handledBy,
|
|
191
|
+
options,
|
|
192
|
+
resolver: (name: string) => exec.extension('resolvers', name),
|
|
193
|
+
graph: exec.graph,
|
|
194
|
+
definition: exec.definition,
|
|
195
|
+
previous,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** 选这个结果之后会到哪些节点:退回、终止不往下走;会签的一份不定下一步 */
|
|
200
|
+
export async function stepsAfter(
|
|
201
|
+
options: FlowEngineOptions,
|
|
202
|
+
exec: Execution,
|
|
203
|
+
node: TaskNode,
|
|
204
|
+
outcome: Outcome,
|
|
205
|
+
actor: string,
|
|
206
|
+
): Promise<NextStep[]> {
|
|
207
|
+
const kind = outcome.kind ?? 'approve';
|
|
208
|
+
if (node.multi || kind === 'return' || kind === 'terminate') return [];
|
|
209
|
+
return nextSteps(predictScope(options, exec, actor), node.id, {
|
|
210
|
+
outcome: outcome.key,
|
|
211
|
+
read: exec.read,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 实例的运行状态(存在 flow_instance.state 的 JSON 列,随实例行一起锁、一起写回):推进时要记住、表里又不好放的东西
|
|
3
|
+
*/
|
|
4
|
+
export interface RunState {
|
|
5
|
+
/** 汇合网关还要等几条分支:分叉时记下选出的边数,到一条减一 */
|
|
6
|
+
waiting: Record<string, number>;
|
|
7
|
+
/** 每个节点到了第几轮 */
|
|
8
|
+
rounds: Record<string, number>;
|
|
9
|
+
/** 每个人工节点最后的处理人(`sameAs`、自动跳过用) */
|
|
10
|
+
handledBy: Record<string, string>;
|
|
11
|
+
/** 被退回的节点 → 退回它的节点(`returnTo: 'resubmit'` 时直接回去) */
|
|
12
|
+
returnedFrom: Record<string, string>;
|
|
13
|
+
/** 依次会签还没轮到的人:会签组 → 处理人 */
|
|
14
|
+
queues: Record<string, string[]>;
|
|
15
|
+
/** 同步的调用节点还在等几个子实例 */
|
|
16
|
+
calls: Record<string, number>;
|
|
17
|
+
/** 自定义节点在等的事件:节点 → 事件名 */
|
|
18
|
+
events: Record<string, string>;
|
|
19
|
+
/** 上一步选的下一步处理人(`assignees` 写 `{ pick }` 的节点):节点 → 用户编号 */
|
|
20
|
+
picks: Record<string, string[]>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** 迁移版本时按节点改名:按节点记的键、值里的节点、会签组(节点#轮次)都换成新版本的节点 */
|
|
24
|
+
export function renameNodes(state: RunState, mapping: Readonly<Record<string, string>>): RunState {
|
|
25
|
+
const node = (id: string) => mapping[id] ?? id;
|
|
26
|
+
const keys = <T>(record: Record<string, T>, value: (v: T) => T = (v) => v) =>
|
|
27
|
+
Object.fromEntries(Object.entries(record).map(([k, v]) => [node(k), value(v)]));
|
|
28
|
+
const group = (key: string) => {
|
|
29
|
+
const at = key.lastIndexOf('#');
|
|
30
|
+
return at < 0 ? node(key) : `${node(key.slice(0, at))}${key.slice(at)}`;
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
...state,
|
|
34
|
+
waiting: keys(state.waiting),
|
|
35
|
+
rounds: keys(state.rounds),
|
|
36
|
+
handledBy: keys(state.handledBy),
|
|
37
|
+
returnedFrom: keys(state.returnedFrom, node),
|
|
38
|
+
queues: Object.fromEntries(Object.entries(state.queues).map(([k, v]) => [group(k), v])),
|
|
39
|
+
calls: keys(state.calls),
|
|
40
|
+
events: keys(state.events),
|
|
41
|
+
picks: keys(state.picks ?? {}),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** 新实例的运行状态 */
|
|
46
|
+
export const emptyRunState = (): RunState => ({
|
|
47
|
+
waiting: {},
|
|
48
|
+
rounds: {},
|
|
49
|
+
handledBy: {},
|
|
50
|
+
returnedFrom: {},
|
|
51
|
+
queues: {},
|
|
52
|
+
calls: {},
|
|
53
|
+
events: {},
|
|
54
|
+
picks: {},
|
|
55
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 场景测试(流程工程的 test.ts,`defineScenarios`):编译工程、取出场景,逐个试运行(simulate),对照期望。
|
|
3
|
+
* 工作室的“测试”页签与单元测试都用它;工程里没有 test.ts 时没有场景。
|
|
4
|
+
*
|
|
5
|
+
* const results = await runScenarios(project, { options: { transform, org, extensions } });
|
|
6
|
+
* results.filter((r) => !r.passed).map((r) => `${r.name}:${r.problems.join(';')}`);
|
|
7
|
+
*/
|
|
8
|
+
import type { FlowProject, ProcessDefinition } from '@zerodep-dev/flow-ts-model';
|
|
9
|
+
import { PROJECT_FILES } from '@zerodep-dev/flow-ts-model';
|
|
10
|
+
import type { Scenario, ScenarioExpect, Scenarios } from '../extensions.ts';
|
|
11
|
+
import { buildProject } from '../publish/project.ts';
|
|
12
|
+
import type { Actor } from '../types.ts';
|
|
13
|
+
import { simulate, type SimulationInput, type SimulationResult } from './simulate.ts';
|
|
14
|
+
|
|
15
|
+
/** 场景测试的文件 */
|
|
16
|
+
export const TEST_FILE = PROJECT_FILES.test;
|
|
17
|
+
|
|
18
|
+
/** 一个场景的结果 */
|
|
19
|
+
export interface ScenarioResult {
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly passed: boolean;
|
|
22
|
+
/** 哪里和期望不一样(通过时为空) */
|
|
23
|
+
readonly problems: readonly string[];
|
|
24
|
+
readonly run: SimulationResult;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** runScenarios 的选项 */
|
|
28
|
+
export interface RunScenariosOptions {
|
|
29
|
+
/** 引擎的选项(编译用的 transform、组织、扩展);同 simulate */
|
|
30
|
+
readonly options?: SimulationInput['options'];
|
|
31
|
+
/** 先发布的别的流程(被调用的) */
|
|
32
|
+
readonly processes?: readonly (ProcessDefinition | FlowProject)[];
|
|
33
|
+
/** 场景里写的发起人编号换成 Actor(角色、部门);不给时只有编号 */
|
|
34
|
+
readonly actorOf?: (id: string) => Actor | undefined | Promise<Actor | undefined>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const sorted = (values: readonly string[]) => [...values].sort();
|
|
38
|
+
const list = (values: readonly string[]) => (values.length ? values.join('、') : '无');
|
|
39
|
+
|
|
40
|
+
/** 试运行的结果对照期望:写了的才核对 */
|
|
41
|
+
export function scenarioProblems(run: SimulationResult, expect: ScenarioExpect): string[] {
|
|
42
|
+
const problems: string[] = [];
|
|
43
|
+
if (expect.error) {
|
|
44
|
+
if (!run.error) problems.push('期望出错,没有出错');
|
|
45
|
+
else {
|
|
46
|
+
if (expect.error.step !== undefined && run.error.step !== expect.error.step)
|
|
47
|
+
problems.push(`在第 ${run.error.step} 步出错,期望第 ${expect.error.step} 步`);
|
|
48
|
+
if (expect.error.message && !run.error.message.includes(expect.error.message))
|
|
49
|
+
problems.push(`错误是“${run.error.message}”,期望含“${expect.error.message}”`);
|
|
50
|
+
}
|
|
51
|
+
} else if (run.error) {
|
|
52
|
+
problems.push(`第 ${run.error.step} 步出错:${run.error.message}`);
|
|
53
|
+
}
|
|
54
|
+
if (expect.status && run.status !== expect.status)
|
|
55
|
+
problems.push(`状态是 ${run.status},期望 ${expect.status}`);
|
|
56
|
+
if (expect.result !== undefined && run.result !== expect.result)
|
|
57
|
+
problems.push(`结果是 ${run.result ?? '无'},期望 ${expect.result}`);
|
|
58
|
+
if (expect.at) {
|
|
59
|
+
const at = sorted(run.open.map((o) => o.node));
|
|
60
|
+
if (at.join() !== sorted(expect.at).join())
|
|
61
|
+
problems.push(`停在 ${list(at)},期望 ${list(sorted(expect.at))}`);
|
|
62
|
+
}
|
|
63
|
+
if (expect.waitingFor) {
|
|
64
|
+
const waiting = sorted(run.open.flatMap((o) => (o.assignee ? [o.assignee] : [])));
|
|
65
|
+
if (waiting.join() !== sorted(expect.waitingFor).join())
|
|
66
|
+
problems.push(`等 ${list(waiting)} 处理,期望 ${list(sorted(expect.waitingFor))}`);
|
|
67
|
+
}
|
|
68
|
+
return problems;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 跑工程里 test.ts 的全部场景;编译不过照常抛(invalid-definition,带文件) */
|
|
72
|
+
export async function runScenarios(
|
|
73
|
+
project: FlowProject,
|
|
74
|
+
{ options, processes, actorOf }: RunScenariosOptions = {},
|
|
75
|
+
): Promise<ScenarioResult[]> {
|
|
76
|
+
if (project.files[TEST_FILE] === undefined) return [];
|
|
77
|
+
const { linked } = await buildProject(project, options?.transform, options?.modules);
|
|
78
|
+
const scenarios = (linked.module(TEST_FILE)['default'] ?? {}) as Scenarios;
|
|
79
|
+
const results: ScenarioResult[] = [];
|
|
80
|
+
for (const [name, scenario] of Object.entries(scenarios) as [string, Scenario][]) {
|
|
81
|
+
const initiator = scenario.initiator
|
|
82
|
+
? ((await actorOf?.(scenario.initiator)) ?? { id: scenario.initiator })
|
|
83
|
+
: undefined;
|
|
84
|
+
const run = await simulate(project, {
|
|
85
|
+
...(scenario.variables ? { variables: scenario.variables } : {}),
|
|
86
|
+
...(initiator ? { initiator } : {}),
|
|
87
|
+
...(scenario.steps ? { steps: scenario.steps } : {}),
|
|
88
|
+
...(options ? { options } : {}),
|
|
89
|
+
...(processes ? { processes } : {}),
|
|
90
|
+
});
|
|
91
|
+
const problems = scenarioProblems(run, scenario.expect);
|
|
92
|
+
results.push({ name, passed: problems.length === 0, problems, run });
|
|
93
|
+
}
|
|
94
|
+
return results;
|
|
95
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 试运行(ROADMAP 14.6):在内存库与假时钟上按步骤走一遍流程,返回走过的路、停在哪、等谁处理。
|
|
3
|
+
* 设计器的“试运行”经接口调用它(与真实引擎同一套规则),单元测试也直接用。出错不抛出,放在结果里给人看。
|
|
4
|
+
*
|
|
5
|
+
* const run = await simulate(purchase, {
|
|
6
|
+
* variables: { amount: '12000' },
|
|
7
|
+
* steps: [{ node: 'review', outcome: 'pass' }, { wait: { hours: 4 } }],
|
|
8
|
+
* });
|
|
9
|
+
* run.status; run.path.map((e) => e.node); run.open; run.error
|
|
10
|
+
*/
|
|
11
|
+
import type { FlowProject, ProcessDefinition } from '@zerodep-dev/flow-ts-model';
|
|
12
|
+
import { parseCandidate } from '../runtime/assignees.ts';
|
|
13
|
+
import { FlowWorkItem } from '../core/entities.ts';
|
|
14
|
+
import { FlowError } from '../core/errors.ts';
|
|
15
|
+
import { createTestEngine } from './testing.ts';
|
|
16
|
+
import type { Actor, FlowEngineOptions, FlowEventView, InstanceSummary } from '../types.ts';
|
|
17
|
+
import type { SimulationStep } from '../extensions.ts';
|
|
18
|
+
|
|
19
|
+
export type { SimulationStep };
|
|
20
|
+
|
|
21
|
+
/** 试运行的输入 */
|
|
22
|
+
export interface SimulationInput {
|
|
23
|
+
/** 发起时的流程变量 */
|
|
24
|
+
readonly variables?: Readonly<Record<string, unknown>>;
|
|
25
|
+
/** 发起人;不写时是 'initiator' */
|
|
26
|
+
readonly initiator?: Actor;
|
|
27
|
+
readonly steps?: readonly SimulationStep[];
|
|
28
|
+
/** 扩展、组织:试运行时多半给假的实现 */
|
|
29
|
+
readonly options?: Omit<FlowEngineOptions, 'adapter' | 'clock'>;
|
|
30
|
+
/** 先发布的别的流程(试运行的流程调用它们时要有) */
|
|
31
|
+
readonly processes?: readonly (ProcessDefinition | FlowProject)[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** 停在某个节点上等谁 */
|
|
35
|
+
export interface OpenItem {
|
|
36
|
+
readonly node: string;
|
|
37
|
+
readonly nodeName: string;
|
|
38
|
+
readonly assignee: string | null;
|
|
39
|
+
/** 收件箱的候选(角色、部门写成“种类:编号”) */
|
|
40
|
+
readonly candidates: readonly string[];
|
|
41
|
+
readonly dueAt: Date | null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** 试运行的结果 */
|
|
45
|
+
export interface SimulationResult {
|
|
46
|
+
readonly status: InstanceSummary['status'] | 'not-started';
|
|
47
|
+
readonly result: string | null;
|
|
48
|
+
readonly current: InstanceSummary['current'];
|
|
49
|
+
readonly variables: Readonly<Record<string, unknown>>;
|
|
50
|
+
/** 走过的路:全部流转记录 */
|
|
51
|
+
readonly path: readonly FlowEventView[];
|
|
52
|
+
/** 还开着的待办 */
|
|
53
|
+
readonly open: readonly OpenItem[];
|
|
54
|
+
/** 哪一步出了错(发起是第 0 步,之后按 steps 从 1 数);没出错时没有 */
|
|
55
|
+
readonly error?: { readonly step: number; readonly code: string; readonly message: string };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** 试运行共用一个测试库,一次只跑一个 */
|
|
59
|
+
let queue: Promise<unknown> = Promise.resolve();
|
|
60
|
+
|
|
61
|
+
/** 按步骤试运行一个流程定义或流程工程(不用先发布到真实的库);同时调用时排队 */
|
|
62
|
+
export function simulate(
|
|
63
|
+
definition: ProcessDefinition | FlowProject,
|
|
64
|
+
input: SimulationInput = {},
|
|
65
|
+
): Promise<SimulationResult> {
|
|
66
|
+
const run = queue.then(() => simulateNow(definition, input));
|
|
67
|
+
queue = run.catch(() => undefined);
|
|
68
|
+
return run;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function simulateNow(
|
|
72
|
+
definition: ProcessDefinition | FlowProject,
|
|
73
|
+
input: SimulationInput,
|
|
74
|
+
): Promise<SimulationResult> {
|
|
75
|
+
const { engine, clock } = await createTestEngine({ admins: ['admin'], ...input.options });
|
|
76
|
+
const initiator = input.initiator ?? { id: 'initiator' };
|
|
77
|
+
const admin: Actor = { id: 'admin', admin: true };
|
|
78
|
+
let instanceId: number | undefined;
|
|
79
|
+
let error: SimulationResult['error'];
|
|
80
|
+
|
|
81
|
+
const fail = (step: number, cause: unknown) => {
|
|
82
|
+
error = {
|
|
83
|
+
step,
|
|
84
|
+
code: cause instanceof FlowError ? cause.code : 'error',
|
|
85
|
+
message: cause instanceof Error ? cause.message : String(cause),
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
for (const other of input.processes ?? []) await engine.publish(other);
|
|
91
|
+
const { key } = await engine.publish(definition);
|
|
92
|
+
const started = await engine.run(
|
|
93
|
+
{ type: 'start', process: key, variables: input.variables ?? {} },
|
|
94
|
+
initiator,
|
|
95
|
+
);
|
|
96
|
+
instanceId = started.instance.id;
|
|
97
|
+
} catch (cause) {
|
|
98
|
+
fail(0, cause);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
for (const [index, step] of (input.steps ?? []).entries()) {
|
|
102
|
+
if (error || instanceId === undefined) break;
|
|
103
|
+
try {
|
|
104
|
+
if ('wait' in step) {
|
|
105
|
+
clock.advance({
|
|
106
|
+
days:
|
|
107
|
+
'days' in step.wait ? step.wait.days : 'workdays' in step.wait ? step.wait.workdays : 0,
|
|
108
|
+
hours: 'hours' in step.wait ? step.wait.hours : 0,
|
|
109
|
+
minutes: 'minutes' in step.wait ? step.wait.minutes : 0,
|
|
110
|
+
});
|
|
111
|
+
// 作业可能排出新的、同样到点的作业(提醒接超时):做到没有为止
|
|
112
|
+
while ((await engine.jobs.runDue()) > 0);
|
|
113
|
+
} else if ('signal' in step) {
|
|
114
|
+
await engine.signal(
|
|
115
|
+
{
|
|
116
|
+
event: step.signal,
|
|
117
|
+
instance: instanceId,
|
|
118
|
+
...(step.outcome !== undefined ? { outcome: step.outcome } : {}),
|
|
119
|
+
...(step.data !== undefined ? { data: step.data } : {}),
|
|
120
|
+
},
|
|
121
|
+
admin,
|
|
122
|
+
);
|
|
123
|
+
} else {
|
|
124
|
+
const item = await engine.db
|
|
125
|
+
.queryable(FlowWorkItem)
|
|
126
|
+
.where((w) => [w.instanceId.eq(instanceId!), w.node.eq(step.node), w.state.eq('open')])
|
|
127
|
+
.orderBy((w) => w.id)
|
|
128
|
+
.first();
|
|
129
|
+
if (!item) throw new FlowError('not-found', `节点 ${step.node} 上没有开着的待办`);
|
|
130
|
+
// 以能处理它的人的身份:落到的人,或收件箱里候选的角色、部门的成员
|
|
131
|
+
const pool = item.candidates.map(parseCandidate);
|
|
132
|
+
const of = (kind: string) => pool.filter((c) => c.kind === kind).map((c) => c.value);
|
|
133
|
+
const actor: Actor = {
|
|
134
|
+
id: item.assignee ?? of('user')[0] ?? 'simulator',
|
|
135
|
+
roles: of('role'),
|
|
136
|
+
departments: of('department'),
|
|
137
|
+
groups: of('group'),
|
|
138
|
+
};
|
|
139
|
+
await engine.run(
|
|
140
|
+
{
|
|
141
|
+
type: 'complete',
|
|
142
|
+
workItem: item.id,
|
|
143
|
+
outcome: step.outcome,
|
|
144
|
+
...(step.variables ? { variables: step.variables } : {}),
|
|
145
|
+
...(step.comment !== undefined ? { comment: step.comment } : {}),
|
|
146
|
+
...(step.returnTo !== undefined ? { returnTo: step.returnTo } : {}),
|
|
147
|
+
},
|
|
148
|
+
actor,
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
} catch (cause) {
|
|
152
|
+
fail(index + 1, cause);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (instanceId === undefined) {
|
|
157
|
+
return {
|
|
158
|
+
status: 'not-started',
|
|
159
|
+
result: null,
|
|
160
|
+
current: [],
|
|
161
|
+
variables: {},
|
|
162
|
+
path: [],
|
|
163
|
+
open: [],
|
|
164
|
+
...(error ? { error } : {}),
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
const detail = await engine.query.instance(instanceId);
|
|
168
|
+
const items = await engine.db
|
|
169
|
+
.queryable(FlowWorkItem)
|
|
170
|
+
.where((w) => [w.instanceId.eq(instanceId!), w.state.eq('open')])
|
|
171
|
+
.orderBy((w) => w.id)
|
|
172
|
+
.toList();
|
|
173
|
+
return {
|
|
174
|
+
status: detail.instance.status,
|
|
175
|
+
result: detail.instance.result,
|
|
176
|
+
current: detail.current,
|
|
177
|
+
variables: detail.instance.variables,
|
|
178
|
+
path: detail.events,
|
|
179
|
+
open: items.map((item) => ({
|
|
180
|
+
node: item.node,
|
|
181
|
+
nodeName: item.nodeName,
|
|
182
|
+
assignee: item.assignee,
|
|
183
|
+
candidates: item.candidates.map((token) =>
|
|
184
|
+
token.startsWith('user:') ? token.slice(5) : token,
|
|
185
|
+
),
|
|
186
|
+
dueAt: item.dueAt,
|
|
187
|
+
})),
|
|
188
|
+
...(error ? { error } : {}),
|
|
189
|
+
};
|
|
190
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 测试用的引擎(docs/decisions/0001 第 8 节):PGlite(进程内的 PostgreSQL,Node 与浏览器都能跑)、建好表、假时钟。
|
|
3
|
+
* 单元测试与设计器的试运行共用。
|
|
4
|
+
*
|
|
5
|
+
* const { engine, clock } = await createTestEngine({ extensions });
|
|
6
|
+
* await engine.publish(purchase);
|
|
7
|
+
* clock.advance({ hours: 3 });
|
|
8
|
+
* await engine.jobs.runDue();
|
|
9
|
+
*/
|
|
10
|
+
import { PGlite } from '@electric-sql/pglite';
|
|
11
|
+
import type { Adapter } from '@zerodep-dev/easy-query-ts';
|
|
12
|
+
import { pglite } from '@zerodep-dev/easy-query-ts-pg/pglite';
|
|
13
|
+
import { flowSchema } from '../core/entities.ts';
|
|
14
|
+
import { createFlowEngine, type FlowEngine } from '../engine.ts';
|
|
15
|
+
import type { FlowEngineOptions } from '../types.ts';
|
|
16
|
+
|
|
17
|
+
/** 可以拨的时钟 */
|
|
18
|
+
export interface TestClock {
|
|
19
|
+
now: () => Date;
|
|
20
|
+
/** 拨到某一刻 */
|
|
21
|
+
set(at: Date | string): void;
|
|
22
|
+
/** 往后拨 */
|
|
23
|
+
advance(by: { days?: number; hours?: number; minutes?: number }): void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** 假时钟:从 start 开始,只在 set、advance 时变 */
|
|
27
|
+
export function createTestClock(start: Date | string = '2026-01-05T09:00:00Z'): TestClock {
|
|
28
|
+
let current = new Date(start);
|
|
29
|
+
return {
|
|
30
|
+
now: () => new Date(current),
|
|
31
|
+
set: (at) => {
|
|
32
|
+
current = new Date(at);
|
|
33
|
+
},
|
|
34
|
+
advance: ({ days = 0, hours = 0, minutes = 0 }) => {
|
|
35
|
+
current = new Date(current.getTime() + ((days * 24 + hours) * 60 + minutes) * 60_000);
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** 共用的 PGlite:启动要一两秒,清空只要几毫秒,所以一个进程(标签页)只启动一个 */
|
|
41
|
+
let shared: PGlite | undefined;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 测试用的引擎:假时钟,库默认是共用的 PGlite、每次清空重建(同一时刻只用一个测试引擎;试运行自己排队)。
|
|
45
|
+
* 给了 adapter(实库)时先删掉引擎的表再建,每次都是空的
|
|
46
|
+
*/
|
|
47
|
+
export async function createTestEngine(
|
|
48
|
+
options: Omit<FlowEngineOptions, 'adapter' | 'clock'> & {
|
|
49
|
+
start?: Date | string;
|
|
50
|
+
adapter?: Adapter;
|
|
51
|
+
} = {},
|
|
52
|
+
): Promise<{ engine: FlowEngine; clock: TestClock }> {
|
|
53
|
+
const clock = createTestClock(options.start);
|
|
54
|
+
const engine = createFlowEngine({
|
|
55
|
+
...options,
|
|
56
|
+
adapter: options.adapter ?? pglite((shared ??= new PGlite())),
|
|
57
|
+
clock: clock.now,
|
|
58
|
+
});
|
|
59
|
+
if (options.adapter) {
|
|
60
|
+
for (const entity of Object.values(flowSchema.entities)) {
|
|
61
|
+
await engine.db.sql.execute`DROP TABLE IF EXISTS ${engine.db.sql.ident(entity.table)}`;
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
await engine.db.sql.execute`DROP SCHEMA IF EXISTS public CASCADE`;
|
|
65
|
+
await engine.db.sql.execute`CREATE SCHEMA public`;
|
|
66
|
+
}
|
|
67
|
+
await engine.createTables();
|
|
68
|
+
return { engine, clock };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export {
|
|
72
|
+
simulate,
|
|
73
|
+
type OpenItem,
|
|
74
|
+
type SimulationInput,
|
|
75
|
+
type SimulationResult,
|
|
76
|
+
type SimulationStep,
|
|
77
|
+
} from './simulate.ts';
|
|
78
|
+
export {
|
|
79
|
+
runScenarios,
|
|
80
|
+
scenarioProblems,
|
|
81
|
+
TEST_FILE,
|
|
82
|
+
type RunScenariosOptions,
|
|
83
|
+
type ScenarioResult,
|
|
84
|
+
} from './scenarios.ts';
|