@mldong/jeeflow 1.8.52 → 1.8.54
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/dist/engine.d.ts +18 -4
- package/dist/engine.js +71 -28
- package/dist/facade.js +8 -2
- package/dist/jdbc/shared.d.ts +10 -0
- package/dist/jdbc/shared.js +38 -4
- package/dist/memory.d.ts +1 -0
- package/dist/memory.js +7 -0
- package/dist/model.d.ts +1 -0
- package/dist/model.js +2 -0
- package/dist/spi.d.ts +5 -0
- package/package.json +2 -2
package/dist/engine.d.ts
CHANGED
|
@@ -101,12 +101,19 @@ export declare class EngineImpl implements Engine {
|
|
|
101
101
|
setExtensions(ext: EngineExtensions): void;
|
|
102
102
|
setRegistry(reg: HandlerRegistry): void;
|
|
103
103
|
private interceptorCache;
|
|
104
|
-
/**
|
|
105
|
-
*
|
|
106
|
-
|
|
104
|
+
/** 流程根 pre/post 声明缓存(每 defineId 只回查一行定义):节点档拆开后若逐节点读定义行,
|
|
105
|
+
* 就把 issue 34 的"读一次"放大成逐任务读——spec.test 的 defineReads 次数不变量钉的就是它。 */
|
|
106
|
+
private rootDeclCache;
|
|
107
|
+
/** 定义级/节点级拦截器解析(issue 34 + audit8 R91,对齐 java `NodeModel.java:49-59`):
|
|
108
|
+
* 档位=`pre`/`post` 两档各自独立取串——节点 properties 声明优先,串空才回落流程根同名键,
|
|
109
|
+
* **两档不叠加**(spec02 §3「节点级拦截器的优先序、回落与键形」);两档都没声明才回落引擎级列表
|
|
110
|
+
* (向后兼容)。解析键=注册名(键形按丙=各家注册表沿用 java 全类名串,本栈不另发明短名)。
|
|
111
|
+
* 结果缓存键含 defineId+节点+档位(issues/234 §4.2:按 defineId 单键会把两个节点的声明串档)。
|
|
107
112
|
* issues/60:解析与校验分离——定义读取/JSON 解析失败回落引擎级(现状语义),
|
|
108
|
-
*
|
|
113
|
+
* 声明中存在未注册名时抛错(不静默跳过,带节点 id 与档位),且错误不写缓存保证持续报错。 */
|
|
109
114
|
private resolveInterceptors;
|
|
115
|
+
/** 流程根 pre/post 声明:每一定义只回查一行(读取/JSON 解析失败按 issues/60 现状语义视作"根级未声明",同样缓存)。 */
|
|
116
|
+
private resolveRootDecls;
|
|
110
117
|
private firePre;
|
|
111
118
|
/** 表达式求值(v1.5.0,门面 highLight 决策分支过滤用) */
|
|
112
119
|
evalExpr(expr: string, vars: Record<string, any>): Promise<any>;
|
|
@@ -151,6 +158,12 @@ export declare class EngineImpl implements Engine {
|
|
|
151
158
|
/** 事务包裹:有事务载体(JDBC `withTx`)则整段并入外层/自开一段;无(内存仓)裸跑。
|
|
152
159
|
* 引擎入口包裹与门面动作级包裹都走这一枚 —— 嵌套调用由 withTx 的 join 支并入最外层。 */
|
|
153
160
|
inTx<T>(fn: () => Promise<T>): Promise<T>;
|
|
161
|
+
/** 提交后腿通道(audit8 R77 读法一,issues/234 §4.3/spec12 §12.3.1;java 形状=监听器侧自取
|
|
162
|
+
* afterCommit,php 侧 R25 已收口同形):监听器/集成层把"必须看到已提交世界"的那一腿(反查、
|
|
163
|
+
* 外发通知、二次写)交到这里声明 ⇒ COMMIT 之后执行、回滚整批丢弃。
|
|
164
|
+
* 没有活动事务(或仓储没这条通道)⇒ 立即执行,行为与上一版逐字一致。
|
|
165
|
+
* ⚠ 引擎自身的 fire 不经过这里:派发点与「监听器随事件拿到动作事务连接」由 145-3 钉住。 */
|
|
166
|
+
runAfterCommit(fn: () => any | Promise<any>): Promise<void>;
|
|
154
167
|
startProcessInstanceById(defineId: string, operator: string, args?: Record<string, any>): Promise<ProcessInstance>;
|
|
155
168
|
private startProcessInstanceByIdInner;
|
|
156
169
|
executeProcessTask(taskId: string, operator: string, args?: Record<string, any>): Promise<ProcessTask[]>;
|
|
@@ -226,6 +239,7 @@ export declare class EngineImpl implements Engine {
|
|
|
226
239
|
/** issues/116:把代理人并入参与者集合——授权人保留、原顺序不动、代理人按参与人顺序追加、去重。
|
|
227
240
|
* 返回新数组(无代理命中时返回原数组引用,零开销)。 */
|
|
228
241
|
export declare function mergeAgents(actors: string[], agents: Map<string, string>): string[];
|
|
242
|
+
export declare function unknownEdgeWarning(from: string, to: string): string;
|
|
229
243
|
/** 会签判定(issue 42,对齐 Java ProcessTaskPerformTypeEnum.codeOf):
|
|
230
244
|
* '1' / 'ALL' / 'COUNTERSIGN'(大小写不敏感)→ 会签。
|
|
231
245
|
* 设计器属性面板保存 'ALL' 字符串符合 Java 契约,引擎必须兼容 */
|
package/dist/engine.js
CHANGED
|
@@ -193,52 +193,74 @@ export class EngineImpl {
|
|
|
193
193
|
setExtensions(ext) {
|
|
194
194
|
this.ext = ext;
|
|
195
195
|
this.interceptorCache = new Map();
|
|
196
|
+
this.rootDeclCache = new Map();
|
|
196
197
|
}
|
|
197
198
|
setRegistry(reg) { this.registry = reg; }
|
|
198
199
|
interceptorCache = new Map();
|
|
199
|
-
/**
|
|
200
|
-
*
|
|
201
|
-
|
|
200
|
+
/** 流程根 pre/post 声明缓存(每 defineId 只回查一行定义):节点档拆开后若逐节点读定义行,
|
|
201
|
+
* 就把 issue 34 的"读一次"放大成逐任务读——spec.test 的 defineReads 次数不变量钉的就是它。 */
|
|
202
|
+
rootDeclCache = new Map();
|
|
203
|
+
/** 定义级/节点级拦截器解析(issue 34 + audit8 R91,对齐 java `NodeModel.java:49-59`):
|
|
204
|
+
* 档位=`pre`/`post` 两档各自独立取串——节点 properties 声明优先,串空才回落流程根同名键,
|
|
205
|
+
* **两档不叠加**(spec02 §3「节点级拦截器的优先序、回落与键形」);两档都没声明才回落引擎级列表
|
|
206
|
+
* (向后兼容)。解析键=注册名(键形按丙=各家注册表沿用 java 全类名串,本栈不另发明短名)。
|
|
207
|
+
* 结果缓存键含 defineId+节点+档位(issues/234 §4.2:按 defineId 单键会把两个节点的声明串档)。
|
|
202
208
|
* issues/60:解析与校验分离——定义读取/JSON 解析失败回落引擎级(现状语义),
|
|
203
|
-
*
|
|
204
|
-
async resolveInterceptors(inst) {
|
|
209
|
+
* 声明中存在未注册名时抛错(不静默跳过,带节点 id 与档位),且错误不写缓存保证持续报错。 */
|
|
210
|
+
async resolveInterceptors(node, inst, phase) {
|
|
205
211
|
if (!this.ext)
|
|
206
212
|
return [];
|
|
207
213
|
const defineId = inst.defineId;
|
|
214
|
+
const key = `${defineId}|${node.id}|${phase}`;
|
|
208
215
|
if (defineId == null)
|
|
209
216
|
return this.ext.interceptors ?? [];
|
|
210
|
-
const cached = this.interceptorCache.get(
|
|
217
|
+
const cached = this.interceptorCache.get(key);
|
|
211
218
|
if (cached)
|
|
212
219
|
return cached;
|
|
213
|
-
|
|
214
|
-
let declared = '';
|
|
220
|
+
const prop = `${phase}Interceptors`;
|
|
221
|
+
let declared = String(node.properties?.[prop] ?? '').trim();
|
|
222
|
+
if (!declared) {
|
|
223
|
+
const list = this.ext.interceptors ?? [];
|
|
224
|
+
declared = (await this.resolveRootDecls(defineId))[phase];
|
|
225
|
+
if (!declared) {
|
|
226
|
+
this.interceptorCache.set(key, list);
|
|
227
|
+
return list;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
const list = [];
|
|
231
|
+
for (const name of declared.split(',').map(n => n.trim())) {
|
|
232
|
+
if (!name)
|
|
233
|
+
continue;
|
|
234
|
+
const ic = this.ext.interceptorRegistry?.[name];
|
|
235
|
+
if (!ic)
|
|
236
|
+
throw new Error(`${prop} 声明的拦截器未注册: ${name}(nodeId=${node.id})`);
|
|
237
|
+
list.push(ic);
|
|
238
|
+
}
|
|
239
|
+
this.interceptorCache.set(key, list);
|
|
240
|
+
return list;
|
|
241
|
+
}
|
|
242
|
+
/** 流程根 pre/post 声明:每一定义只回查一行(读取/JSON 解析失败按 issues/60 现状语义视作"根级未声明",同样缓存)。 */
|
|
243
|
+
async resolveRootDecls(defineId) {
|
|
244
|
+
const cached = this.rootDeclCache.get(defineId);
|
|
245
|
+
if (cached)
|
|
246
|
+
return cached;
|
|
247
|
+
let decl = { pre: '', post: '' };
|
|
215
248
|
try {
|
|
216
249
|
const def = await this.repo.findDefineById(defineId);
|
|
217
250
|
if (def) {
|
|
218
251
|
const content = typeof def.content === 'string' ? def.content : new TextDecoder().decode(def.content);
|
|
219
252
|
const meta = JSON.parse(content);
|
|
220
|
-
|
|
253
|
+
decl = { pre: String(meta.preInterceptors ?? '').trim(), post: String(meta.postInterceptors ?? '').trim() };
|
|
221
254
|
}
|
|
222
255
|
}
|
|
223
256
|
catch { /* 定义读取/JSON 解析失败回落引擎级 */ }
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
for (const name of declared.split(',').map(n => n.trim())) {
|
|
227
|
-
if (!name)
|
|
228
|
-
continue;
|
|
229
|
-
const ic = this.ext.interceptorRegistry?.[name];
|
|
230
|
-
if (!ic)
|
|
231
|
-
throw new Error(`postInterceptors 声明的拦截器未注册: ${name}`);
|
|
232
|
-
list.push(ic);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
this.interceptorCache.set(defineId, list);
|
|
236
|
-
return list;
|
|
257
|
+
this.rootDeclCache.set(defineId, decl);
|
|
258
|
+
return decl;
|
|
237
259
|
}
|
|
238
260
|
async firePre(node, inst) {
|
|
239
261
|
if (!this.ext?.interceptors && !this.ext?.interceptorRegistry)
|
|
240
262
|
return true;
|
|
241
|
-
const list = await this.resolveInterceptors(inst);
|
|
263
|
+
const list = await this.resolveInterceptors(node, inst, 'pre');
|
|
242
264
|
for (const ic of [...list].sort((a, b) => a.order - b.order))
|
|
243
265
|
if (!(await ic.preHandle(node, inst)))
|
|
244
266
|
return false;
|
|
@@ -253,7 +275,7 @@ export class EngineImpl {
|
|
|
253
275
|
async firePost(node, inst) {
|
|
254
276
|
if (!this.ext?.interceptors && !this.ext?.interceptorRegistry)
|
|
255
277
|
return;
|
|
256
|
-
for (const ic of await this.resolveInterceptors(inst))
|
|
278
|
+
for (const ic of await this.resolveInterceptors(node, inst, 'post'))
|
|
257
279
|
await ic.postHandle(node, inst);
|
|
258
280
|
}
|
|
259
281
|
async fireEvent(evt) {
|
|
@@ -337,6 +359,16 @@ export class EngineImpl {
|
|
|
337
359
|
async inTx(fn) {
|
|
338
360
|
return this.repo.withTx ? this.repo.withTx(fn) : fn();
|
|
339
361
|
}
|
|
362
|
+
/** 提交后腿通道(audit8 R77 读法一,issues/234 §4.3/spec12 §12.3.1;java 形状=监听器侧自取
|
|
363
|
+
* afterCommit,php 侧 R25 已收口同形):监听器/集成层把"必须看到已提交世界"的那一腿(反查、
|
|
364
|
+
* 外发通知、二次写)交到这里声明 ⇒ COMMIT 之后执行、回滚整批丢弃。
|
|
365
|
+
* 没有活动事务(或仓储没这条通道)⇒ 立即执行,行为与上一版逐字一致。
|
|
366
|
+
* ⚠ 引擎自身的 fire 不经过这里:派发点与「监听器随事件拿到动作事务连接」由 145-3 钉住。 */
|
|
367
|
+
async runAfterCommit(fn) {
|
|
368
|
+
if (this.repo.afterCommit?.call(this.repo, fn))
|
|
369
|
+
return;
|
|
370
|
+
await fn();
|
|
371
|
+
}
|
|
340
372
|
// ─── Start ─────────────────────────────────────────────────────────────────
|
|
341
373
|
async startProcessInstanceById(defineId, operator, args = {}) {
|
|
342
374
|
// audit8 145-2①:入口级包裹——直连引擎的调用方也拿到"一次动作一笔原子"(spec/12 §12.2)。
|
|
@@ -1135,11 +1167,22 @@ function findNode(flow, id) {
|
|
|
1135
1167
|
function findNodeByType(flow, type) {
|
|
1136
1168
|
return flow.nodes.find(n => n.type === type);
|
|
1137
1169
|
}
|
|
1170
|
+
export function unknownEdgeWarning(from, to) {
|
|
1171
|
+
return `[jeeflow] WARNING 转移出边的目标节点不在模型里(该节点类型未建档,解析期已跳过),本次流转停在这条边: from=${from}, to=${to}`;
|
|
1172
|
+
}
|
|
1138
1173
|
function followEdges(flow, sourceId) {
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1174
|
+
const out = [];
|
|
1175
|
+
for (const e of flow.edges) {
|
|
1176
|
+
if (e.sourceNodeId !== sourceId)
|
|
1177
|
+
continue;
|
|
1178
|
+
const n = findNode(flow, e.targetNodeId);
|
|
1179
|
+
if (!n) {
|
|
1180
|
+
console.warn(unknownEdgeWarning(sourceId, e.targetNodeId));
|
|
1181
|
+
continue;
|
|
1182
|
+
}
|
|
1183
|
+
out.push(n);
|
|
1184
|
+
}
|
|
1185
|
+
return out;
|
|
1143
1186
|
}
|
|
1144
1187
|
function getCsState(vars, nodeId) {
|
|
1145
1188
|
const actors = vars[`operatorList_${nodeId}`] ?? null;
|
package/dist/facade.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// (code=0 成功 / 99999999 失败)。操作人约定:args.operator 显式传入。
|
|
6
6
|
import { dirname as pathDirname, join as pathJoin, sep as pathSep } from 'node:path';
|
|
7
7
|
import { fileURLToPath } from 'node:url';
|
|
8
|
-
import { TaskState, } from './model.js';
|
|
8
|
+
import { TaskState, EXIST_UN_FINISH_INSTANCE, } from './model.js';
|
|
9
9
|
// issues/142 B 批(spec 06 §2.11):transfer 的 fromActor/toActor 用 cc 侧已落地的那一枚单值判据归一
|
|
10
10
|
// (旧名 normalizeCcActorValue = 新名 normalizeActorValue,同一函数),不在此另写一份 trim+判空
|
|
11
11
|
import { normalizeActorValue } from './spi.js';
|
|
@@ -634,7 +634,13 @@ export class JeeflowFacade {
|
|
|
634
634
|
}
|
|
635
635
|
/** 删除定义(issues/28:兼容 {ids} 批量与单 {id}) */
|
|
636
636
|
async defineRemove(args) {
|
|
637
|
-
|
|
637
|
+
const ids = idListArgs(args);
|
|
638
|
+
// audit8 R110:先对整批做存在性校验再删,避免"前面的删了、后面的被拒"的半删。
|
|
639
|
+
for (const id of ids) {
|
|
640
|
+
if (await this.repo.hasInstancesByDefineId(id))
|
|
641
|
+
throw new Error(EXIST_UN_FINISH_INSTANCE);
|
|
642
|
+
}
|
|
643
|
+
for (const id of ids)
|
|
638
644
|
await this.repo.removeDefine(id);
|
|
639
645
|
return {};
|
|
640
646
|
}
|
package/dist/jdbc/shared.d.ts
CHANGED
|
@@ -2,6 +2,11 @@ import { AsyncLocalStorage } from 'node:async_hooks';
|
|
|
2
2
|
import { ProcessInstance, ProcessTask, type ProcessDefine, type CcInstanceRow, type DefineRow, type InstanceRow, type TaskRow } from '../model.js';
|
|
3
3
|
import type { IDGenerator, ProcessRepository, QueryCondition, InstanceStatsRow, TaskStatsRow } from '../spi.js';
|
|
4
4
|
export declare const txStore: AsyncLocalStorage<SqlConnection>;
|
|
5
|
+
export interface AfterCommitScope {
|
|
6
|
+
cbs: Array<() => any | Promise<any>>;
|
|
7
|
+
done: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const afterCommitStore: AsyncLocalStorage<AfterCommitScope>;
|
|
5
10
|
/** 当前事务连接(无事务 ⇒ null)。集成方自研写腿(如 DynamicTableWriter 的 MySQL 实现)
|
|
6
11
|
* 用它并入引擎事务——spec/12 §12.2 覆盖面:一次动作内所有写腿取同一条连接。 */
|
|
7
12
|
export declare function currentTxConnection(): SqlConnection | null;
|
|
@@ -48,6 +53,10 @@ export declare class JdbcRepository implements ProcessRepository {
|
|
|
48
53
|
private readonly adapter;
|
|
49
54
|
private readonly idGen;
|
|
50
55
|
constructor(adapter: SqlAdapter, idGen?: IDGenerator);
|
|
56
|
+
/** 登记「本次事务提交之后」执行的回调(audit8 R77 读法一;java 形状=监听器侧自取 afterCommit,
|
|
57
|
+
* php 侧 R25 已收口同形)。返回 false=当前无活动事务 ⇒ 调用方须自行立即执行
|
|
58
|
+
* (门面级没外包事务模板的栈,「落库后」与「提交后」等价)。 */
|
|
59
|
+
afterCommit(fn: () => any | Promise<any>): boolean;
|
|
51
60
|
private sql;
|
|
52
61
|
withTx<T>(fn: () => Promise<T>): Promise<T>;
|
|
53
62
|
/** 返回当前连接:有事务绑定用事务连接,否则从适配器获取 */
|
|
@@ -59,6 +68,7 @@ export declare class JdbcRepository implements ProcessRepository {
|
|
|
59
68
|
updateDefine(define: ProcessDefine): Promise<void>;
|
|
60
69
|
updateDefineState(defineId: string, state: number): Promise<void>;
|
|
61
70
|
removeDefine(defineId: string): Promise<void>;
|
|
71
|
+
hasInstancesByDefineId(defineId: string): Promise<boolean>;
|
|
62
72
|
findDefineByName(name: string): Promise<ProcessDefine | null>;
|
|
63
73
|
private static INSTANCE_COLS;
|
|
64
74
|
findInstanceById(id: string): Promise<ProcessInstance | null>;
|
package/dist/jdbc/shared.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// - 本文件是**唯一维护点**:15 个仓储方法的 SQL 逻辑、行映射、ID 生成
|
|
5
5
|
// - SQL 占位符统一使用 `?`,由各数据库适配器(SqlAdapter)转换为自家风格
|
|
6
6
|
// (MySQL `?` 原生 / PostgreSQL `$n`)
|
|
7
|
-
// -
|
|
7
|
+
// - 事务(规范 05「事务约定」节):withTx 用 AsyncLocalStorage 绑定当前异步上下文的事务连接
|
|
8
8
|
//
|
|
9
9
|
// 新增数据库 = 写一个适配器(约 80 行):实现 SqlAdapter + 连接包装
|
|
10
10
|
// (execute/fetchOne/fetchAll/begin/commit/rollback)。参考 mysql.ts / postgres.ts。
|
|
@@ -40,6 +40,7 @@ const DEFINE_WHITELIST = new Set([
|
|
|
40
40
|
// audit8 145-2:**导出**——ext.ts 必须共用这一枚(此前它自带第二枚且从不 run,扩展写腿
|
|
41
41
|
// 永远逃逸出引擎事务)。集成方写腿也可经 currentTxConnection/transactionAwarePool 并入。
|
|
42
42
|
export const txStore = new AsyncLocalStorage();
|
|
43
|
+
export const afterCommitStore = new AsyncLocalStorage();
|
|
43
44
|
/** 当前事务连接(无事务 ⇒ null)。集成方自研写腿(如 DynamicTableWriter 的 MySQL 实现)
|
|
44
45
|
* 用它并入引擎事务——spec/12 §12.2 覆盖面:一次动作内所有写腿取同一条连接。 */
|
|
45
46
|
export function currentTxConnection() {
|
|
@@ -108,25 +109,48 @@ export class JdbcRepository {
|
|
|
108
109
|
this.adapter = adapter;
|
|
109
110
|
this.idGen = idGen;
|
|
110
111
|
}
|
|
112
|
+
/** 登记「本次事务提交之后」执行的回调(audit8 R77 读法一;java 形状=监听器侧自取 afterCommit,
|
|
113
|
+
* php 侧 R25 已收口同形)。返回 false=当前无活动事务 ⇒ 调用方须自行立即执行
|
|
114
|
+
* (门面级没外包事务模板的栈,「落库后」与「提交后」等价)。 */
|
|
115
|
+
afterCommit(fn) {
|
|
116
|
+
const sc = afterCommitStore.getStore();
|
|
117
|
+
if (!sc || sc.done)
|
|
118
|
+
return false;
|
|
119
|
+
sc.cbs.push(fn);
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
111
122
|
sql(s) {
|
|
112
123
|
return convertPlaceholder(s, this.adapter.placeholder);
|
|
113
124
|
}
|
|
114
|
-
// ──
|
|
125
|
+
// ── 事务(规范 05「事务约定」节:AsyncLocalStorage 绑定连接)─────────────────────────
|
|
115
126
|
async withTx(fn) {
|
|
116
127
|
// audit8 145-2③(spec/12 §12.2 归属面):已有活动事务 ⇒ **并入**(不再开第二段事务、
|
|
117
128
|
// 不提前提交;提交/回滚归最外层)——引擎入口包裹与门面动作级包裹嵌套时落这一支。
|
|
118
129
|
if (txStore.getStore())
|
|
119
130
|
return fn();
|
|
120
131
|
const conn = await this.adapter.acquire();
|
|
132
|
+
const scope = { cbs: [], done: false };
|
|
121
133
|
try {
|
|
122
134
|
await conn.begin();
|
|
123
135
|
try {
|
|
124
|
-
const result = await txStore.run(conn, fn);
|
|
136
|
+
const result = await txStore.run(conn, () => afterCommitStore.run(scope, fn));
|
|
125
137
|
await conn.commit();
|
|
138
|
+
scope.done = true;
|
|
139
|
+
// R77 提交后腿:逐条吞掉自家异常,不打断主流程(登记方自己承担失败语义)
|
|
140
|
+
for (const cb of scope.cbs) {
|
|
141
|
+
try {
|
|
142
|
+
await cb();
|
|
143
|
+
}
|
|
144
|
+
catch (err) {
|
|
145
|
+
console.warn('[jeeflow] afterCommit 回调失败: ' + String(err));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
126
148
|
return result;
|
|
127
149
|
}
|
|
128
150
|
catch (err) {
|
|
129
151
|
await conn.rollback();
|
|
152
|
+
scope.done = true;
|
|
153
|
+
scope.cbs = []; // R77:回滚 ⇒ 提交后腿整批丢弃(监听器不得看到未提交的世界)
|
|
130
154
|
throw err;
|
|
131
155
|
}
|
|
132
156
|
}
|
|
@@ -213,6 +237,16 @@ export class JdbcRepository {
|
|
|
213
237
|
await this.done(conn);
|
|
214
238
|
}
|
|
215
239
|
}
|
|
240
|
+
async hasInstancesByDefineId(defineId) {
|
|
241
|
+
const conn = await this.c();
|
|
242
|
+
try {
|
|
243
|
+
const row = await conn.fetchOne(this.sql('SELECT COUNT(*) FROM wf_process_instance WHERE process_define_id=?'), [defineId]);
|
|
244
|
+
return Number(Object.values(row)[0] ?? 0) > 0;
|
|
245
|
+
}
|
|
246
|
+
finally {
|
|
247
|
+
await this.done(conn);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
216
250
|
// findDefineByName 按流程编码查最新一条定义(v1.1.0,deploy 版本管理用)
|
|
217
251
|
async findDefineByName(name) {
|
|
218
252
|
const conn = await this.c();
|
|
@@ -283,7 +317,7 @@ export class JdbcRepository {
|
|
|
283
317
|
'operator=?, expire_time=?, variable=?, update_time=?, update_user=? WHERE id=?'), [inst.state, inst.parentNodeName ?? '', inst.businessNo ?? '', inst.operator,
|
|
284
318
|
inst.expireTime ?? null, JSON.stringify(inst.variables ?? {}),
|
|
285
319
|
inst.updateTime, inst.updateUser, inst.id]);
|
|
286
|
-
// v1.0.1
|
|
320
|
+
// v1.0.1:级联持久化聚合根内任务状态变更(同连接,规范 05「事务约定」节)
|
|
287
321
|
for (const task of inst.tasks) {
|
|
288
322
|
if (task.id)
|
|
289
323
|
await this.updateTaskWithConn(conn, task);
|
package/dist/memory.d.ts
CHANGED
|
@@ -35,6 +35,7 @@ export declare class MemoryRepository implements ProcessRepository {
|
|
|
35
35
|
updateDefine(def: ProcessDefine): Promise<void>;
|
|
36
36
|
updateDefineState(defineId: string, state: number): Promise<void>;
|
|
37
37
|
removeDefine(defineId: string): Promise<void>;
|
|
38
|
+
hasInstancesByDefineId(defineId: string): Promise<boolean>;
|
|
38
39
|
saveInstance(inst: ProcessInstance): Promise<void>;
|
|
39
40
|
updateInstance(inst: ProcessInstance): Promise<void>;
|
|
40
41
|
findInstanceById(id: string): Promise<ProcessInstance | null>;
|
package/dist/memory.js
CHANGED
|
@@ -159,6 +159,13 @@ export class MemoryRepository {
|
|
|
159
159
|
async removeDefine(defineId) {
|
|
160
160
|
this.defines.delete(defineId);
|
|
161
161
|
}
|
|
162
|
+
async hasInstancesByDefineId(defineId) {
|
|
163
|
+
for (const inst of this.instances.values()) {
|
|
164
|
+
if (String(inst.defineId) === String(defineId))
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
162
169
|
async saveInstance(inst) {
|
|
163
170
|
if (!inst.id)
|
|
164
171
|
inst.id = String(this.seq++);
|
package/dist/model.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ export interface FlowEdge {
|
|
|
34
34
|
value: string;
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
+
export declare const EXIST_UN_FINISH_INSTANCE = "\u5B58\u5728\u6B63\u5728\u672A\u5B8C\u6210\u7684\u6D41\u7A0B\u5B9E\u4F8B\uFF0C\u4E0D\u5141\u8BB8\u5220\u9664\uFF01";
|
|
37
38
|
export declare const TypeStart = "snaker:start";
|
|
38
39
|
export declare const TypeEnd = "snaker:end";
|
|
39
40
|
export declare const TypeTask = "snaker:task";
|
package/dist/model.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// ─── LogicFlow JSON Types ─────────────────────────────────────────────────────
|
|
2
2
|
// ─── Node Type Constants ──────────────────────────────────────────────────────
|
|
3
|
+
// 删除定义的实例守卫文案(内部码 20010005,逐字沿用 boot2)
|
|
4
|
+
export const EXIST_UN_FINISH_INSTANCE = '存在正在未完成的流程实例,不允许删除!';
|
|
3
5
|
export const TypeStart = 'snaker:start';
|
|
4
6
|
export const TypeEnd = 'snaker:end';
|
|
5
7
|
export const TypeTask = 'snaker:task';
|
package/dist/spi.d.ts
CHANGED
|
@@ -148,12 +148,17 @@ export interface ProcessRepository {
|
|
|
148
148
|
/** 事务载体(audit8 145-2,spec/12 §12.2)——JDBC 仓储天然实现(AsyncLocalStorage);
|
|
149
149
|
* 内存仓没有此方法 ⇒ 引擎 inTx 显式降级裸跑(§12.1 原则 4)。 */
|
|
150
150
|
withTx?<T>(fn: () => Promise<T>): Promise<T>;
|
|
151
|
+
/** 提交后腿通道(audit8 R77 读法一,spec/12 §12.3.1):有活动事务时登记回调并返回 true
|
|
152
|
+
* (Commit 后执行、回滚丢弃);无活动事务返回 false ⇒ 调用方须自行立即执行。
|
|
153
|
+
* 内存仓没有此方法 ⇒ 一律立即执行(与"落库后"等价)。 */
|
|
154
|
+
afterCommit?(fn: () => any | Promise<any>): boolean;
|
|
151
155
|
findDefineById(id: string): Promise<ProcessDefine | null>;
|
|
152
156
|
findDefineByName(name: string): Promise<ProcessDefine | null>;
|
|
153
157
|
saveDefine(define: ProcessDefine): Promise<void>;
|
|
154
158
|
updateDefine(define: ProcessDefine): Promise<void>;
|
|
155
159
|
updateDefineState(defineId: string, state: number): Promise<void>;
|
|
156
160
|
removeDefine(defineId: string): Promise<void>;
|
|
161
|
+
hasInstancesByDefineId(defineId: string): Promise<boolean>;
|
|
157
162
|
findInstanceById(id: string): Promise<ProcessInstance | null>;
|
|
158
163
|
saveInstance(inst: ProcessInstance): Promise<void>;
|
|
159
164
|
updateInstance(inst: ProcessInstance): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mldong/jeeflow",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.54",
|
|
4
4
|
"description": "jeeflow workflow engine — Node.js / TypeScript implementation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"build": "tsc",
|
|
21
21
|
"typecheck": "tsc -p tsconfig.check.json",
|
|
22
22
|
"test": "node --import tsx __tests__/spec.test.ts",
|
|
23
|
-
"test-mysql": "node --import tsx --test __tests__/jdbc.test.ts __tests__/tx-tier-145.test.ts",
|
|
23
|
+
"test-mysql": "node --import tsx --test __tests__/jdbc.test.ts __tests__/tx-tier-145.test.ts __tests__/after_commit_r77.test.ts",
|
|
24
24
|
"demo": "node --import tsx demo/main.ts",
|
|
25
25
|
"prepublishOnly": "npm run build"
|
|
26
26
|
},
|