@mldong/jeeflow 1.8.51 → 1.8.52

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 CHANGED
@@ -1,4 +1,4 @@
1
- import { ProcessInstance } from './model.js';
1
+ import { ProcessInstance, type ProcessTask } from './model.js';
2
2
  import type { ProcessRepository, ProcessExtRepository, UserProvider, IDGenerator, ExpressionEvaluator } from './spi.js';
3
3
  import { type EngineExtensions, type ProcessEvent } from './extensions.js';
4
4
  import { HandlerRegistry } from './registry.js';
@@ -40,10 +40,10 @@ export declare function parseActorIds(v: any): string[];
40
40
  export declare const parseCcActors: (v: any) => string[];
41
41
  export interface Engine {
42
42
  startProcessInstanceById(defineId: string, operator: string, args?: Record<string, any>): Promise<ProcessInstance>;
43
- executeProcessTask(taskId: string, operator: string, args?: Record<string, any>): Promise<ProcessInstance>;
44
- executeAndJumpToEnd(taskId: string, operator: string, args?: Record<string, any>): Promise<ProcessInstance>;
45
- executeAndJumpTask(taskId: string, operator: string, args: Record<string, any>, targetTaskName?: string): Promise<ProcessInstance>;
46
- executeAndJumpToFirstTaskNode(taskId: string, operator: string, args?: Record<string, any>): Promise<ProcessInstance>;
43
+ executeProcessTask(taskId: string, operator: string, args?: Record<string, any>): Promise<ProcessTask[]>;
44
+ executeAndJumpToEnd(taskId: string, operator: string, args?: Record<string, any>): Promise<ProcessTask[]>;
45
+ executeAndJumpTask(taskId: string, operator: string, args: Record<string, any>, targetTaskName?: string): Promise<ProcessTask[]>;
46
+ executeAndJumpToFirstTaskNode(taskId: string, operator: string, args?: Record<string, any>): Promise<ProcessTask[]>;
47
47
  /** 事务包裹(audit8 145-2 / spec/12 §12.2):仓储有事务载体则并入(嵌套经 withTx 的 join 支),
48
48
  * 无(内存仓)则裸跑=显式降级(§12.1 原则 4)。门面动作级包裹也走这一枚。 */
49
49
  inTx<T>(fn: () => Promise<T>): Promise<T>;
@@ -67,6 +67,8 @@ export declare class EngineImpl implements Engine {
67
67
  private userProv?;
68
68
  private idGen?;
69
69
  private exprEval?;
70
+ /** R92:执行族产出列表的每次调用作用域(AsyncLocalStorage,并发安全)。 */
71
+ private readonly createdScope;
70
72
  private ext?;
71
73
  private registry?;
72
74
  private surrogateRepo?;
@@ -151,13 +153,13 @@ export declare class EngineImpl implements Engine {
151
153
  inTx<T>(fn: () => Promise<T>): Promise<T>;
152
154
  startProcessInstanceById(defineId: string, operator: string, args?: Record<string, any>): Promise<ProcessInstance>;
153
155
  private startProcessInstanceByIdInner;
154
- executeProcessTask(taskId: string, operator: string, args?: Record<string, any>): Promise<ProcessInstance>;
156
+ executeProcessTask(taskId: string, operator: string, args?: Record<string, any>): Promise<ProcessTask[]>;
155
157
  private executeProcessTaskInner;
156
- executeAndJumpToEnd(taskId: string, operator: string, args?: Record<string, any>): Promise<ProcessInstance>;
158
+ executeAndJumpToEnd(taskId: string, operator: string, args?: Record<string, any>): Promise<ProcessTask[]>;
157
159
  private executeAndJumpToEndInner;
158
- executeAndJumpTask(taskId: string, operator: string, args?: Record<string, any>, targetTaskName?: string): Promise<ProcessInstance>;
160
+ executeAndJumpTask(taskId: string, operator: string, args?: Record<string, any>, targetTaskName?: string): Promise<ProcessTask[]>;
159
161
  private executeAndJumpTaskInner;
160
- executeAndJumpToFirstTaskNode(taskId: string, operator: string, args?: Record<string, any>): Promise<ProcessInstance>;
162
+ executeAndJumpToFirstTaskNode(taskId: string, operator: string, args?: Record<string, any>): Promise<ProcessTask[]>;
161
163
  private executeAndJumpToFirstTaskNodeInner;
162
164
  private prepareExecuteTask;
163
165
  private isFirstTaskNode;
package/dist/engine.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { AsyncLocalStorage } from 'node:async_hooks';
1
2
  import { TypeStart, TypeEnd, TypeTask, TypeDecision, TypeFork, TypeJoin, TypeCustom, KnownNodeTypes, ProcessInstance, InstanceState, TaskState, SubmitType, } from './model.js';
2
3
  // issues/141 G2:cc 写侧判重的 java `default` 方法在 TS 里的对应物(第三方仓储未实现判重 SPI 时兜旧行为)
3
4
  // issues/141 G10:归属值单值/集合归一的**那一份**判据(漏斗层与写侧层共用;issues/142 B 批
@@ -114,6 +115,8 @@ export class EngineImpl {
114
115
  userProv;
115
116
  idGen;
116
117
  exprEval;
118
+ /** R92:执行族产出列表的每次调用作用域(AsyncLocalStorage,并发安全)。 */
119
+ createdScope = new AsyncLocalStorage();
117
120
  ext;
118
121
  registry;
119
122
  // issues/116:委托代理自动生效——内置能力,注入查询源后默认开启
@@ -378,7 +381,12 @@ export class EngineImpl {
378
381
  // ─── Execute ───────────────────────────────────────────────────────────────
379
382
  async executeProcessTask(taskId, operator, args = {}) {
380
383
  // audit8 145-2①:入口级包裹(同 startProcessInstanceById 注释)
381
- return this.inTx(() => this.executeProcessTaskInner(taskId, operator, args));
384
+ const created = [];
385
+ // spec04 §完成任务:公开方法回传「本次动作产出的任务行」(基准=java exec.getProcessTaskList())。
386
+ // 作用域用 AsyncLocalStorage:一个 EngineImpl 实例并发处理多个请求,class 字段会互踩;
387
+ // 而 node 没有 go 那样的 ctx 可挂,ALS 是等价的每次调用作用域(见 R92 notes)。
388
+ await this.createdScope.run(created, () => this.inTx(() => this.executeProcessTaskInner(taskId, operator, args)));
389
+ return created;
382
390
  }
383
391
  async executeProcessTaskInner(taskId, operator, args = {}) {
384
392
  const { task, inst, flow, vars } = await this.prepareExecuteTask(taskId, operator, args);
@@ -439,6 +447,7 @@ export class EngineImpl {
439
447
  // 变量源=实例变量(与建单同档),取时基准=本行 createTime 用的同一个 now。
440
448
  applyNodeExpireTime(nt, curNode.properties?.expireTime, inst.variables, now);
441
449
  await this.repo.saveTask(nt);
450
+ this.createdScope.getStore()?.push(nt);
442
451
  // PROCESS_TASK_START:顺序会签推进新任务落库后 fire(对齐 Java CreateTaskHandler / Rust)
443
452
  await this.fireEvent({ type: EventType.ProcessTaskStart, instanceId: inst.id, taskId: nt.id, nodeId: curNode.id, operator, actors: [...nt.actorIds] });
444
453
  return finishExecute();
@@ -504,7 +513,12 @@ export class EngineImpl {
504
513
  // ─── Reject ────────────────────────────────────────────────────────────────
505
514
  async executeAndJumpToEnd(taskId, operator, args = {}) {
506
515
  // audit8 145-2①:入口级包裹(同 startProcessInstanceById 注释)
507
- return this.inTx(() => this.executeAndJumpToEndInner(taskId, operator, args));
516
+ const created = [];
517
+ // spec04 §完成任务:公开方法回传「本次动作产出的任务行」(基准=java exec.getProcessTaskList())。
518
+ // 作用域用 AsyncLocalStorage:一个 EngineImpl 实例并发处理多个请求,class 字段会互踩;
519
+ // 而 node 没有 go 那样的 ctx 可挂,ALS 是等价的每次调用作用域(见 R92 notes)。
520
+ await this.createdScope.run(created, () => this.inTx(() => this.executeAndJumpToEndInner(taskId, operator, args)));
521
+ return created;
508
522
  }
509
523
  async executeAndJumpToEndInner(taskId, operator, args = {}) {
510
524
  const { inst } = await this.prepareExecuteTask(taskId, operator, args);
@@ -519,7 +533,12 @@ export class EngineImpl {
519
533
  // ─── Jump(ROLLBACK 空 target / JUMP 命名 target,boot2 executeAndJumpTask)────
520
534
  async executeAndJumpTask(taskId, operator, args = {}, targetTaskName) {
521
535
  // audit8 145-2①:入口级包裹(同 startProcessInstanceById 注释)
522
- return this.inTx(() => this.executeAndJumpTaskInner(taskId, operator, args, targetTaskName));
536
+ const created = [];
537
+ // spec04 §完成任务:公开方法回传「本次动作产出的任务行」(基准=java exec.getProcessTaskList())。
538
+ // 作用域用 AsyncLocalStorage:一个 EngineImpl 实例并发处理多个请求,class 字段会互踩;
539
+ // 而 node 没有 go 那样的 ctx 可挂,ALS 是等价的每次调用作用域(见 R92 notes)。
540
+ await this.createdScope.run(created, () => this.inTx(() => this.executeAndJumpTaskInner(taskId, operator, args, targetTaskName)));
541
+ return created;
523
542
  }
524
543
  async executeAndJumpTaskInner(taskId, operator, args = {}, targetTaskName) {
525
544
  const { task, inst, flow, vars } = await this.prepareExecuteTask(taskId, operator, args);
@@ -546,7 +565,12 @@ export class EngineImpl {
546
565
  // ─── Jump To First Task(退回发起人,boot2 ROLLBACK_TO_OPERATOR=6)────────────
547
566
  async executeAndJumpToFirstTaskNode(taskId, operator, args = {}) {
548
567
  // audit8 145-2①:入口级包裹(同 startProcessInstanceById 注释)
549
- return this.inTx(() => this.executeAndJumpToFirstTaskNodeInner(taskId, operator, args));
568
+ const created = [];
569
+ // spec04 §完成任务:公开方法回传「本次动作产出的任务行」(基准=java exec.getProcessTaskList())。
570
+ // 作用域用 AsyncLocalStorage:一个 EngineImpl 实例并发处理多个请求,class 字段会互踩;
571
+ // 而 node 没有 go 那样的 ctx 可挂,ALS 是等价的每次调用作用域(见 R92 notes)。
572
+ await this.createdScope.run(created, () => this.inTx(() => this.executeAndJumpToFirstTaskNodeInner(taskId, operator, args)));
573
+ return created;
550
574
  }
551
575
  async executeAndJumpToFirstTaskNodeInner(taskId, operator, args = {}) {
552
576
  const { inst, flow, vars } = await this.prepareExecuteTask(taskId, operator, args);
@@ -652,6 +676,7 @@ export class EngineImpl {
652
676
  if (eff.length > 1)
653
677
  nt.actorIds = eff;
654
678
  await this.repo.saveTask(nt);
679
+ this.createdScope.getStore()?.push(nt);
655
680
  await this.fireEvent({ type: EventType.ProcessTaskStart, instanceId: inst.id,
656
681
  taskId: nt.id, nodeId: prev.id, operator, actors: [...nt.actorIds] });
657
682
  }
@@ -865,6 +890,7 @@ export class EngineImpl {
865
890
  nt.actorIds = eff;
866
891
  applyNodeExpireTime(nt, expireExpr, expireArgs, now); // 并行会签全员
867
892
  await this.repo.saveTask(nt);
893
+ this.createdScope.getStore()?.push(nt);
868
894
  // PROCESS_TASK_START:任务落库后逐个 fire(会签多任务逐个,对齐 Java CreateTaskHandler)
869
895
  await this.fireEvent({ type: EventType.ProcessTaskStart, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator, actors: [...nt.actorIds] });
870
896
  }
@@ -883,6 +909,7 @@ export class EngineImpl {
883
909
  nt.actorIds = eff;
884
910
  applyNodeExpireTime(nt, expireExpr, expireArgs, now); // 串行会签首位成员
885
911
  await this.repo.saveTask(nt);
912
+ this.createdScope.getStore()?.push(nt);
886
913
  await this.fireEvent({ type: EventType.ProcessTaskStart, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator, actors: [...nt.actorIds] });
887
914
  return;
888
915
  }
@@ -894,6 +921,7 @@ export class EngineImpl {
894
921
  nt.actorIds = eff;
895
922
  applyNodeExpireTime(nt, expireExpr, expireArgs, now); // 未配会签类型=全员预创建,与并行同档
896
923
  await this.repo.saveTask(nt);
924
+ this.createdScope.getStore()?.push(nt);
897
925
  await this.fireEvent({ type: EventType.ProcessTaskStart, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator, actors: [...nt.actorIds] });
898
926
  }
899
927
  return;
@@ -909,6 +937,7 @@ export class EngineImpl {
909
937
  nt.actorIds = effActors;
910
938
  applyNodeExpireTime(nt, expireExpr, expireArgs, now); // 普通建单
911
939
  await this.repo.saveTask(nt);
940
+ this.createdScope.getStore()?.push(nt);
912
941
  await this.fireEvent({ type: EventType.ProcessTaskStart, instanceId: inst.id, taskId: nt.id, nodeId: node.id, operator, actors: [...nt.actorIds] });
913
942
  }
914
943
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mldong/jeeflow",
3
- "version": "1.8.51",
3
+ "version": "1.8.52",
4
4
  "description": "jeeflow workflow engine — Node.js / TypeScript implementation",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",