@mldong/jeeflow 1.8.64 → 1.8.66

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/facade.d.ts CHANGED
@@ -66,6 +66,20 @@ export declare class JeeflowFacade {
66
66
  * 位序照 java `taskRecall`:operator 空判在前、主键缺失判在后。
67
67
  */
68
68
  private taskRecall;
69
+ /**
70
+ * 动态协办(issues/253,规范 06 §processTask/aidant):主办把"这活"交给别人干——按人派生
71
+ * `task_type=1` 协办子行,主办行原样保留 DOING,节点推进仍由主办行办结触发。
72
+ *
73
+ * 门面只做参数归一与信封包装,判据/建单/账本全在引擎(`EngineImpl.aidantTask`,与 recall
74
+ * 同分工)。`operator` 硬必填(不接受缺省,与 transfer/withdraw 同口径);`actorIds` 逗号串
75
+ * 与数组两形共用 §2.11 那枚归一单点(`engine.parseActorIds` → `spi.normalizeActors`),
76
+ * 空 ⇒ 逐字「actorIds 必填」。`waitCompletion` 选填 bool,缺省 false=不等。
77
+ *
78
+ * 成功 `data → null`(规范 06);失败 msg 见跨栈统一文案表协办六行。
79
+ * 权限码复用 `wf:processTask:execute`(OR 规则,照 246/247 B 案惯例)。
80
+ * 位序照 java taskAidant:operator 空判在前、主键缺失判在后、actorIds 空判第三。
81
+ */
82
+ private taskAidant;
69
83
  /**
70
84
  * 动态会签发起分流(issues/247,规范 04 · 动态会签):征询节点带 `tf_addSignOperators` 的
71
85
  * 提交=只建成员行、**不办结主办行**;返回响应 marker(`data.dynamicCountersign`),
package/dist/facade.js CHANGED
@@ -23,6 +23,9 @@ import { AddSignRoundKey, MSG_MUTEX, MSG_SELF, maxRoundsOf, msgMaxRounds, nextOp
23
23
  // 且不进 execute 参数空间语义);已办撤回(issues/246)的门面腿只做参数归一与信封包装。
24
24
  import { appendCollectHistory, appendRevokeHistory, buildProjection, dynamicCountersignOf, isMemberRow, lastRound, memberCounts, memberRows, MSG_MEMBER_PULL, MSG_NO_PERMISSION_REVOKE, MSG_NOT_ALLOWED_EXECUTE, KeyAddSignReason, pendingMembers as collectPendingMembers, msgDuplicate, msgNoPending, msgPending, } from './collect.js';
25
25
  import { inRoster, isPrivilegedOperator } from './recall.js';
26
+ // 动态协办(issues/253):门面只做参数归一与信封包装,判据/建单/账本/闸门全在引擎
27
+ // (形状基准=java `JeeflowFacade.taskAidant`/`parseWaitCompletion`)
28
+ import { MSG_NO_ACTORS as MSG_AIDANT_NO_ACTORS, buildProjection as buildAidantProjection } from './aidant.js';
26
29
  import { VAR_BRANCH_CTX, VAR_REAPPLY_CTX } from './reapply.js';
27
30
  // submitType 枚举(对齐 boot3)
28
31
  const SUBMIT_APPLY = 0;
@@ -361,6 +364,8 @@ export class JeeflowFacade {
361
364
  return this.taskRecall(args);
362
365
  case 'processTask/revokeDynamicCountersign': // issues/247 撤回动态会签(第 49 个 action)
363
366
  return this.taskRevokeCountersign(args);
367
+ case 'processTask/aidant': // issues/253 动态协办(第 50 个 action,data → null)
368
+ return this.taskAidant(args);
364
369
  case 'processTask/latest':
365
370
  return this.taskLatest(args);
366
371
  case 'processInstance/stats/overview':
@@ -599,6 +604,35 @@ export class JeeflowFacade {
599
604
  const resurrected = await this.engine.recallTask(taskId, operator);
600
605
  return { processTaskId: resurrected.id, taskState: resurrected.taskState };
601
606
  }
607
+ /**
608
+ * 动态协办(issues/253,规范 06 §processTask/aidant):主办把"这活"交给别人干——按人派生
609
+ * `task_type=1` 协办子行,主办行原样保留 DOING,节点推进仍由主办行办结触发。
610
+ *
611
+ * 门面只做参数归一与信封包装,判据/建单/账本全在引擎(`EngineImpl.aidantTask`,与 recall
612
+ * 同分工)。`operator` 硬必填(不接受缺省,与 transfer/withdraw 同口径);`actorIds` 逗号串
613
+ * 与数组两形共用 §2.11 那枚归一单点(`engine.parseActorIds` → `spi.normalizeActors`),
614
+ * 空 ⇒ 逐字「actorIds 必填」。`waitCompletion` 选填 bool,缺省 false=不等。
615
+ *
616
+ * 成功 `data → null`(规范 06);失败 msg 见跨栈统一文案表协办六行。
617
+ * 权限码复用 `wf:processTask:execute`(OR 规则,照 246/247 B 案惯例)。
618
+ * 位序照 java taskAidant:operator 空判在前、主键缺失判在后、actorIds 空判第三。
619
+ */
620
+ async taskAidant(args) {
621
+ const operator = String(args.operator ?? '').trim();
622
+ if (!operator)
623
+ throw new Error('operator 必填');
624
+ const rawId = args.processTaskId;
625
+ if (rawId == null || String(rawId).trim() === '')
626
+ throw new Error('processTaskId 缺失');
627
+ const taskId = toId(rawId);
628
+ const actorIds = parseActorIds(args.actorIds);
629
+ if (actorIds.length === 0)
630
+ throw new Error(MSG_AIDANT_NO_ACTORS);
631
+ const reason = String(args.reason ?? '');
632
+ const waitCompletion = parseWaitCompletion(args.waitCompletion);
633
+ await this.engine.aidantTask(taskId, actorIds, reason, waitCompletion, operator);
634
+ return null;
635
+ }
602
636
  /**
603
637
  * 动态会签发起分流(issues/247,规范 04 · 动态会签):征询节点带 `tf_addSignOperators` 的
604
638
  * 提交=只建成员行、**不办结主办行**;返回响应 marker(`data.dynamicCountersign`),
@@ -1406,6 +1440,12 @@ export class JeeflowFacade {
1406
1440
  if (dc)
1407
1441
  tExt.dynamicCountersign = dc;
1408
1442
  }
1443
+ // 动态协办投影(issues/253,规范 06 §2.7):主办行 ext.aidant 从 task_parent_id+
1444
+ // task_type=1 现算,不落新存储。**无节点开关**——协办档只由运行期派生,任何任务
1445
+ // 节点都可能有(故不套征询那层开关判据)。整段同在 try 内=读数失败不打断 detail 主腿。
1446
+ const ap = buildAidantProjection(await this.repo.findHistoryTasks(inst.id), task);
1447
+ if (ap)
1448
+ tExt.aidant = ap;
1409
1449
  break;
1410
1450
  }
1411
1451
  }
@@ -2298,6 +2338,19 @@ function operatorArg(args) {
2298
2338
  const s = toStr(args.operator);
2299
2339
  return s.trim() !== '' ? s : 'user1';
2300
2340
  }
2341
+ /**
2342
+ * `waitCompletion` 入参解析(issues/253,规范 06「选填 bool,缺省 false」)。
2343
+ * 布尔与 "true"/"false" 字符串两形都认(前端 JSON 与表单串两种来源);其余值按缺省 false
2344
+ * 处理——契约只定义了 bool 档,**不为非法值新造文案**(跨栈统一文案表协办六行之外不加第七行)。
2345
+ * 形状基准=java `JeeflowFacade.parseWaitCompletion`。
2346
+ */
2347
+ function parseWaitCompletion(value) {
2348
+ if (value === null || value === undefined)
2349
+ return false;
2350
+ if (typeof value === 'boolean')
2351
+ return value;
2352
+ return String(value).trim().toLowerCase() === 'true';
2353
+ }
2301
2354
  function toId(v) {
2302
2355
  // issue 38 E9:id 全程 string 承载——Java 雪花 id(>2^53)经 Number() 必丢精度。
2303
2356
  // 数字输入(JS 安全整数内)转字符串;字符串输入原样保留(含超长雪花 id)。
@@ -76,6 +76,9 @@ export declare class JdbcRepository implements ProcessRepository {
76
76
  updateInstance(inst: ProcessInstance): Promise<void>;
77
77
  private static TASK_COLS;
78
78
  findTaskById(taskId: string): Promise<ProcessTask | null>;
79
+ /** 实例级事务排他(spec 04 · 并发保护):实例行 SELECT … FOR UPDATE,
80
+ * 锁随最外层 withTx 提交/回滚释放;行不存在不新造失败面。 */
81
+ lockInstance(instanceId: string): Promise<void>;
79
82
  saveTask(task: ProcessTask): Promise<void>;
80
83
  updateTask(task: ProcessTask): Promise<void>;
81
84
  /** 用指定连接更新任务(实例级联时与实例更新同连接) */
@@ -345,6 +345,19 @@ export class JdbcRepository {
345
345
  await this.done(conn);
346
346
  }
347
347
  }
348
+ /** 实例级事务排他(spec 04 · 并发保护):实例行 SELECT … FOR UPDATE,
349
+ * 锁随最外层 withTx 提交/回滚释放;行不存在不新造失败面。 */
350
+ async lockInstance(instanceId) {
351
+ if (!instanceId)
352
+ return;
353
+ const conn = await this.c();
354
+ try {
355
+ await conn.fetchOne(this.sql('SELECT id FROM wf_process_instance WHERE id = ? FOR UPDATE'), [instanceId]);
356
+ }
357
+ finally {
358
+ await this.done(conn);
359
+ }
360
+ }
348
361
  async saveTask(task) {
349
362
  const conn = await this.c();
350
363
  try {
package/dist/spi.d.ts CHANGED
@@ -145,6 +145,10 @@ export interface TaskStatsRow {
145
145
  expireTime: Date | string | null;
146
146
  }
147
147
  export interface ProcessRepository {
148
+ /** 实例级事务排他(spec 04);未实现的仓储退化为引擎进程内互斥 */
149
+ lockInstance?(instanceId: string): Promise<void>;
150
+ /** 实例级事务排他(spec 04);未实现的仓储退化为引擎进程内互斥 */
151
+ lockInstance?(instanceId: string): Promise<void>;
148
152
  /** 事务载体(audit8 145-2,spec/12 §12.2)——JDBC 仓储天然实现(AsyncLocalStorage);
149
153
  * 内存仓没有此方法 ⇒ 引擎 inTx 显式降级裸跑(§12.1 原则 4)。 */
150
154
  withTx?<T>(fn: () => Promise<T>): Promise<T>;
@@ -344,3 +348,20 @@ export interface ProcessExtRepository {
344
348
  pageSurrogates(pageNum?: number, pageSize?: number, filters?: Record<string, any>, conditions?: QueryCondition[]): Promise<[ProcessSurrogate[], number]>;
345
349
  getSurrogate(operator: string, processName: string, at?: Date): Promise<ProcessSurrogate | null>;
346
350
  }
351
+ /** 任务时限动作凭证(spec 04 · 任务时限动作):dueAt 用 UTC 毫秒。 */
352
+ export interface TimeAction {
353
+ type: 'REMIND' | 'AUTO_COMPLETE' | 'CALLBACK';
354
+ dueAt: number;
355
+ instanceId: string;
356
+ taskId: string;
357
+ nodeKey: string;
358
+ occurrenceNo: number;
359
+ idempotencyKey: string;
360
+ }
361
+ /** 时限动作凭证仓储侧实现(集成层按框架执行队列实现,引擎在业务事务内回调)。
362
+ * 取消只清 REMIND/AUTO_COMPLETE;CALLBACK 表达既成事实、不随失效取消。 */
363
+ export interface TimeActionSink {
364
+ insertTimeAction(action: TimeAction): Promise<void>;
365
+ cancelTaskTimeActions(taskId: string): Promise<void>;
366
+ cancelInstanceTimeActions(instanceId: string): Promise<void>;
367
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mldong/jeeflow",
3
- "version": "1.8.64",
3
+ "version": "1.8.66",
4
4
  "description": "jeeflow workflow engine — Node.js / TypeScript implementation",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -19,7 +19,7 @@
19
19
  "scripts": {
20
20
  "build": "tsc",
21
21
  "typecheck": "tsc -p tsconfig.check.json",
22
- "test": "node --import tsx __tests__/spec.test.ts && node --import tsx --test __tests__/reapply.test.ts && node --import tsx --test __tests__/add-sign-after.test.ts && node --import tsx --test __tests__/recall.test.ts && node --import tsx --test __tests__/dynamic-countersign.test.ts && node --import tsx --test __tests__/action-permission.test.ts && node --import tsx --test __tests__/persist.test.ts",
22
+ "test": "node --import tsx __tests__/spec.test.ts && node --import tsx --test __tests__/reapply.test.ts && node --import tsx --test __tests__/add-sign-after.test.ts && node --import tsx --test __tests__/recall.test.ts && node --import tsx --test __tests__/dynamic-countersign.test.ts && node --import tsx --test __tests__/aidant.test.ts && node --import tsx --test __tests__/action-permission.test.ts && node --import tsx --test __tests__/persist.test.ts && node --import tsx --test __tests__/tasktype-secondary-ban.test.ts && node --import tsx --test __tests__/time-limit-action.test.ts",
23
23
  "test-mysql": "node --import tsx --test --test-concurrency=1 __tests__/jdbc.test.ts __tests__/tx-tier-145.test.ts __tests__/after_commit_r77.test.ts __tests__/recall-collect-mysql.test.ts __tests__/instance-state-mysql.test.ts",
24
24
  "demo": "node --import tsx demo/main.ts",
25
25
  "prepublishOnly": "npm run build"