@mldong/jeeflow 1.8.35 → 1.8.36

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.
@@ -11,7 +11,7 @@
11
11
  import { AsyncLocalStorage } from 'node:async_hooks';
12
12
  import { ProcessInstance, ProcessTask } from '../model.js';
13
13
  import { TaskState } from '../model.js';
14
- import { isBlankOwnership, isBlankValue } from '../spi.js';
14
+ import { isBlankOwnership, isBlankValue, hasEffectiveCcOwnership, defaultCreateCcInstanceIfAbsent, normalizeActorValue, normalizeActors } from '../spi.js';
15
15
  // ═══ 列白名单(issues/05-5,与 mldong-boot2 别名一致) ═══
16
16
  const TASK_WHITELIST = new Set([
17
17
  't.id', 't.task_name', 't.display_name', 't.task_type', 't.perform_type', 't.task_state',
@@ -369,9 +369,20 @@ export class JdbcRepository {
369
369
  await conn.execute(this.sql('DELETE FROM wf_process_task_actor WHERE process_task_id = ?'), [taskId]);
370
370
  await this.insertTaskActors(conn, taskId, actors);
371
371
  }
372
+ /**
373
+ * `wf_process_task_actor` 的**唯一 INSERT 腿**(`saveTask`/`updateInstance` 级联的
374
+ * `replaceTaskActors` 与 `addTaskActor` 两条路都从这里下库)。
375
+ *
376
+ * <p>issues/142 B 批(spec 06 §2.11「归属值写侧归一」):绑定进 `actor_id` 的值先过
377
+ * `spi.normalizeActors` **那一枚**单点——逐元素 trim、空串/纯空白/`null`/`undefined` 丢弃、
378
+ * 同一次调用内的重复折叠。判据落在这一层而不是只落门面腿:绕过
379
+ * `processTask/addCandidate`/`surrogate`/`transfer` 直连仓储的调用方(集成层、第三方仓储消费者)
380
+ * 同样不得把空归属值灌进归属列——那正是 issues/129 那族"空归属值读全库"的上游进水口。
381
+ * ⚠️ 与内存仓 `MemoryRepository.writeActors` 同一判据、同一份实现,两仓必须同答案。
382
+ */
372
383
  async insertTaskActors(conn, taskId, actors) {
373
384
  const now = new Date();
374
- for (const a of actors) {
385
+ for (const a of normalizeActors(actors)) {
375
386
  await conn.execute(this.sql('INSERT INTO wf_process_task_actor (id, process_task_id, actor_id, create_time, create_user) VALUES (?,?,?,?,?)'), [this.idGen.nextId(), taskId, a, now, 'jeeflow']);
376
387
  }
377
388
  }
@@ -386,12 +397,17 @@ export class JdbcRepository {
386
397
  }
387
398
  }
388
399
  async addTaskActor(taskId, actors) {
389
- if (actors.length === 0)
400
+ // issues/142 B 批(spec 06 §2.11):写侧兜底——改前这里**判重不判空不 trim**,
401
+ // `""`/`" "`/`"null"`(门面数组腿串化出来的假归属人)全放行。
402
+ // 归一交给 `insertTaskActors` 那一枚单点(与内存仓 writeActors 同一份实现),本方法只多一道
403
+ // "与库里既有行判重":判重两侧取的都是 trim 后的值,`" 123 "` 与 `"123"` 是同一个人。
404
+ const normalized = normalizeActors(actors);
405
+ if (normalized.length === 0)
390
406
  return;
391
407
  // 追加语义(对齐 boot2/boot3,issues/03):查已有参与者,去重后仅插入新增,不清空原参与者
392
408
  const existing = await this.findTaskActors(taskId);
393
409
  const seen = new Set(existing);
394
- const toAdd = actors.filter(a => !seen.has(a));
410
+ const toAdd = normalized.filter(a => !seen.has(a));
395
411
  if (toAdd.length === 0)
396
412
  return;
397
413
  const conn = await this.c();
@@ -415,22 +431,64 @@ export class JdbcRepository {
415
431
  }
416
432
  // ── CcInstance(抄送)─────────────────────────────────────────────────────
417
433
  async createCcInstance(instanceId, creator, ...actorIds) {
434
+ // issues/141 G2 写侧判重=幂等空操作(spec 06 §4),与内存仓同一条判据:同一 (实例, 被抄送人)
435
+ // 已有 cc 行 ⇒ 直接跳过——①不新增行、②不重置未读(state 保持原值)、③不更新原行时间
436
+ // (不碰 UPDATE,create_time/update_time 逐字不变)。判重放在**写侧**而不是查询侧:
437
+ // 查询不引入 DISTINCT(owner 2026-09-29 拍),历史重复行也不清理。
438
+ //
439
+ // issues/141 G10「空不创建行」(spec 06 §2.10):入参先过 `spi.normalizeActorValue`
440
+ // (旧名 normalizeCcActorValue 是它的别名,同一枚函数)——
441
+ // 空串/纯空白/null 一律丢弃,绑进 actor_id 的值取 trim 后的串(`" 123 "` 与 `"123"` 是同一个人,
442
+ // 与上面的写侧判重同一条尺子)。绕过引擎/门面直连仓储的第三方调用方也建不出 actor_id='' 的行,
443
+ // 那正是 issues/129 那族"空 operator 读全库"的病根。⚠️ 与内存仓共用一份判据,两仓必须同答案。
444
+ const existing = await this.findCcActorIds(instanceId);
418
445
  const conn = await this.c();
419
446
  try {
420
447
  const now = new Date();
421
- for (const actorId of actorIds) {
448
+ for (const rawActorId of actorIds) {
449
+ const actorId = normalizeActorValue(rawActorId);
450
+ if (actorId === '' || existing.includes(actorId))
451
+ continue;
422
452
  await conn.execute(this.sql('INSERT INTO wf_process_cc_instance (id, process_instance_id, actor_id, state, ' +
423
453
  'create_time, create_user, update_time, update_user) VALUES (?,?,?,0,?,?,?,?)'), [this.idGen.nextId(), instanceId, actorId, now, creator, now, creator]);
454
+ // 同一次调用内的重复也算"已存在",只落一行
455
+ existing.push(actorId);
424
456
  }
425
457
  }
426
458
  finally {
427
459
  await this.done(conn);
428
460
  }
429
461
  }
462
+ /**
463
+ * issues/141 G2:某实例已有的 cc 行 actor id(写侧判重的读侧,对齐 java `findCcActorIds`)。
464
+ * 排序按 id ASC 与本仓 `findTaskActors` 同形,让"既有集合"在两仓/跨驱动都稳定可断言。
465
+ * ⚠️ 查询侧不带 DISTINCT:判重在写侧,历史重复行原样返回(owner 拍为接受既成事实)。
466
+ */
467
+ async findCcActorIds(instanceId) {
468
+ const conn = await this.c();
469
+ try {
470
+ const rows = await conn.fetchAll(this.sql('SELECT actor_id FROM wf_process_cc_instance WHERE process_instance_id = ? ORDER BY id ASC'), [instanceId]);
471
+ return rows.map(r => String(r.actor_id));
472
+ }
473
+ finally {
474
+ await this.done(conn);
475
+ }
476
+ }
477
+ async createCcInstanceIfAbsent(instanceId, creator, ...actorIds) {
478
+ // spi 里那份 java default 的对应物(本仓的 findCcActorIds/createCcInstance 已自带判重,
479
+ // 本方法只负责把"实际新建的子集"回传给调用方去 fire)
480
+ return defaultCreateCcInstanceIfAbsent(this, instanceId, creator, actorIds);
481
+ }
430
482
  async updateCcStatus(instanceId, actorId) {
483
+ // issues/142 B 批(spec 06 §2.11 表第四行):归属值入参**归一后再比**——比较值取 trim 后的串
484
+ // (`" 123 "` 打不中行里的 `"123"` 就是"点了已读没反应"),归一后为空 ⇒ **一条 UPDATE 都不发**
485
+ // (空 operator 会把 state=1 打到历史 `actor_id=''` 的脏行上)。与内存仓同一枚判据。
486
+ const actor = normalizeActorValue(actorId);
487
+ if (actor === '')
488
+ return;
431
489
  const conn = await this.c();
432
490
  try {
433
- await conn.execute(this.sql('UPDATE wf_process_cc_instance SET state=1, update_time=? WHERE process_instance_id=? AND actor_id=?'), [new Date(), instanceId, actorId]);
491
+ await conn.execute(this.sql('UPDATE wf_process_cc_instance SET state=1, update_time=? WHERE process_instance_id=? AND actor_id=?'), [new Date(), instanceId, actor]);
434
492
  }
435
493
  finally {
436
494
  await this.done(conn);
@@ -631,8 +689,14 @@ export class JdbcRepository {
631
689
  }
632
690
  // pageCcInstances 我的抄送分页(v1.3.0):cc 表 join 实例 + 定义,按抄送人过滤(对齐 Java pageCcInstances)
633
691
  async pageCcInstances(pageNum, pageSize, actorId, conditions) {
634
- // issues/129 案 A 第二层:位置参归属过滤(cc.actor_id)为空 ⇒ 空页(与内存仓/java 同判据)
635
- if (isBlankValue(actorId))
692
+ // issues/141 G1 归属条件必填(spec 06 §2.5):cc.actor_id 上没有有效归属证据 ⇒ 空页。
693
+ // 这一格补的是 issues/129 那把尺子的**延长档**:129 收了"归属列给了空值"(下面 buildWhere 的
694
+ // OWNERSHIP_COLUMNS ⇒ `AND 1=0`,位置参空值那一路也一并由 hasEffectiveCcOwnership 覆盖),
695
+ // G1 收的是"空集合也算没填"(`[]`/空 IN ⇒ 空页,而不是让数组下库或整条条件静默消失)。
696
+ // 旧形状在这一侧是 `FROM wf_process_instance t LEFT JOIN wf_process_cc_instance cc` 不带条件
697
+ // 返回**全部实例**(php PDO 那面反面教材),而它自家内存仓只放"有 cc 行的实例"——同一栈两仓
698
+ // 两个答案正是 issues/117 场景 27 立过法的形状,所以判据两仓共用 hasEffectiveCcOwnership 一份实现。
699
+ if (!hasEffectiveCcOwnership(actorId, conditions))
636
700
  return { rows: [], total: 0 };
637
701
  const cond = this.buildWhere(conditions ?? [], CC_WHITELIST);
638
702
  const where = ' FROM wf_process_instance t' +
package/dist/memory.d.ts CHANGED
@@ -5,6 +5,22 @@ import type { ProcessRepository, QueryCondition } from './spi.js';
5
5
  export declare function matchConditions(conditions: QueryCondition[] | undefined, fields: Record<string, any>): boolean;
6
6
  /** EQ:值或集合包含判断(pta.actor_id/cc.actor_id 为数组) */
7
7
  export declare function eqValue(v: any, expect: any): boolean;
8
+ /**
9
+ * 内存仓的 cc 行(issues/141 G2)——形状对齐表 `wf_process_cc_instance`:
10
+ * actor id + 未读状态(0 未读 / 1 已读)+ 建行时间与更新时间。
11
+ *
12
+ * 旧形状是「按实例存一串 actor id」,那种存法把 G2 的②「不重置未读」和③「不更新原行时间」
13
+ * 照不出来(没有 state、也没有时间可比较 ⇒ 只能测①),重复抄送把已读抹回未读、
14
+ * 把原行时间刷成 now 这两种**假修**在测试面上是隐形的。java 侧同一个升级
15
+ * (`MemoryProcessRepository.CcRow`);既有断言语义一字不改。
16
+ */
17
+ export interface CcRow {
18
+ actorId: string;
19
+ /** 0 未读 / 1 已读(对齐 `wf_process_cc_instance.state`) */
20
+ state: number;
21
+ createTime: Date;
22
+ updateTime: Date;
23
+ }
8
24
  export declare class MemoryRepository implements ProcessRepository {
9
25
  private defines;
10
26
  private instances;
@@ -29,10 +45,31 @@ export declare class MemoryRepository implements ProcessRepository {
29
45
  findDoneTasks(instanceId: string, _taskNames?: string[]): Promise<ProcessTask[]>;
30
46
  findHistoryTasks(instanceId: string): Promise<ProcessTask[]>;
31
47
  findTaskActors(taskId: string): Promise<string[]>;
48
+ /**
49
+ * 参与者落到本仓 Map 之前的**写侧闸**(issues/142 B 批 · spec 06 §2.11):
50
+ * `addTaskActor`(追加语义)与 `saveTask`/`updateTask`(整体替换语义)三条腿都过
51
+ * `spi.normalizeActors` **那一枚**单点——逐元素 trim、空串/纯空白/`null`/`undefined` 丢弃、
52
+ * 同一次调用内的重复折叠。判据只有那一处,本方法只是把三条腿接到同一枚上(不是第二份尺子)。
53
+ *
54
+ * ⚠️ 与 SQL 仓 `JdbcRepository.insertTaskActors` **同一判据、同一份实现**(两仓必须同答案,
55
+ * issues/117 场景 27 那把尺子);只修门面腿的话,绕过门面直连仓储的调用方照样能把
56
+ * 空归属值灌进 `wf_process_task_actor.actor_id`——那正是 issues/129 那族"空归属值读全库"的病根。
57
+ *
58
+ * @param append true 追加并判重(addTaskActor)/false 整体替换(saveTask/updateTask)
59
+ */
60
+ private writeActors;
32
61
  addTaskActor(taskId: string, actors: string[]): Promise<void>;
33
62
  removeTaskActor(taskId: string, actors: string[]): Promise<void>;
34
63
  createCcInstance(instanceId: string, _creator: string, ...actorIds: string[]): Promise<void>;
35
- updateCcStatus(_instanceId: string, _actorId: string): Promise<void>;
64
+ findCcActorIds(instanceId: string): Promise<string[]>;
65
+ createCcInstanceIfAbsent(instanceId: string, creator: string, ...actorIds: string[]): Promise<string[]>;
66
+ updateCcStatus(instanceId: string, actorId: string): Promise<void>;
67
+ /**
68
+ * 测试访问器:读回某实例的 cc **行**(issues/141 G2)。②「不重置未读」与③「不更新原行时间」
69
+ * 必须看 state 与两个时间字段,只看 actor id 集合照不出那两种假修(java 同名 `ccRowsForTest`)。
70
+ * 返回浅拷贝数组,调用方改数组不影响仓储;行对象本身是引用(时间与状态才可比)。
71
+ */
72
+ ccRowsForTest(instanceId: string): CcRow[];
36
73
  pageDefines(pageNum?: number, pageSize?: number, conditions?: QueryCondition[]): Promise<{
37
74
  rows: DefineRow[];
38
75
  total: number;
package/dist/memory.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { TaskState } from './model.js';
2
2
  import { cloneInstance, cloneTask } from './model.js';
3
- import { isBlankOwnership } from './spi.js';
3
+ import { hasEffectiveCcOwnership, isBlankOwnership, defaultCreateCcInstanceIfAbsent, normalizeActorValue, normalizeActors } from './spi.js';
4
4
  // ═══ 条件匹配基建(issues/05-5,对齐 JDBC 白名单语义) ═══
5
5
  // 行字段映射(列名 → 行属性,白名单列均可匹配)
6
6
  const TASK_FIELDS = {
@@ -111,6 +111,9 @@ export function eqValue(v, expect) {
111
111
  * (`!op.is_empty()` 判据)同形;非空值**原样比较、不 trim**,与 java `t.operator = ?`
112
112
  * 及本栈 SQL 侧 `= ?` 的取值口径一致(不借机放宽成模糊匹配)。
113
113
  * 返回 null 表示"归属值为空",调用方据此让每一行都不匹配。
114
+ *
115
+ * ⚠️ `pageCcInstances` 自 issues/141 G1 起不再走本函数,改走 `hasEffectiveCcOwnership`
116
+ * (同一条尺子再延长一档:空集合也算没填,且 conditions 里 `cc.actor_id` 的空值一并收进空页)。
114
117
  */
115
118
  function ownershipKey(wanted) {
116
119
  const op = wanted ?? '';
@@ -174,8 +177,10 @@ export class MemoryRepository {
174
177
  const tc = cloneTask(t);
175
178
  tc.actorIds = [];
176
179
  this.tasks.set(t.id, tc);
180
+ // issues/142 B 批(spec 06 §2.11):级联腿同样过那一枚写侧闸("只有真写了参与者才动 Map"
181
+ // 的既有前置条件不变,动的是**落库值**:trim+丢空+同次折叠)
177
182
  if (t.actorIds?.length)
178
- this.actors.set(t.id, [...t.actorIds]);
183
+ this.writeActors(t.id, t.actorIds, false);
179
184
  }
180
185
  }
181
186
  async findInstanceById(id) {
@@ -207,15 +212,16 @@ export class MemoryRepository {
207
212
  const cp = cloneTask(task);
208
213
  cp.actorIds = [];
209
214
  this.tasks.set(task.id, cp);
215
+ // issues/142 B 批(spec 06 §2.11):建单腿的参与者落库值也过那一枚写侧闸(trim+丢空+同次折叠)
210
216
  if (task.actorIds?.length)
211
- this.actors.set(task.id, [...task.actorIds]);
217
+ this.writeActors(task.id, task.actorIds, false);
212
218
  }
213
219
  async updateTask(task) {
214
220
  const cp = cloneTask(task);
215
221
  cp.actorIds = [];
216
222
  this.tasks.set(task.id, cp);
217
223
  if (task.actorIds?.length)
218
- this.actors.set(task.id, [...task.actorIds]);
224
+ this.writeActors(task.id, task.actorIds, false);
219
225
  }
220
226
  async findDoingTasks(instanceId, taskNames) {
221
227
  const result = [];
@@ -253,10 +259,27 @@ export class MemoryRepository {
253
259
  return result;
254
260
  }
255
261
  async findTaskActors(taskId) { return this.actors.get(taskId) ?? []; }
256
- async addTaskActor(taskId, actors) {
262
+ /**
263
+ * 参与者落到本仓 Map 之前的**写侧闸**(issues/142 B 批 · spec 06 §2.11):
264
+ * `addTaskActor`(追加语义)与 `saveTask`/`updateTask`(整体替换语义)三条腿都过
265
+ * `spi.normalizeActors` **那一枚**单点——逐元素 trim、空串/纯空白/`null`/`undefined` 丢弃、
266
+ * 同一次调用内的重复折叠。判据只有那一处,本方法只是把三条腿接到同一枚上(不是第二份尺子)。
267
+ *
268
+ * ⚠️ 与 SQL 仓 `JdbcRepository.insertTaskActors` **同一判据、同一份实现**(两仓必须同答案,
269
+ * issues/117 场景 27 那把尺子);只修门面腿的话,绕过门面直连仓储的调用方照样能把
270
+ * 空归属值灌进 `wf_process_task_actor.actor_id`——那正是 issues/129 那族"空归属值读全库"的病根。
271
+ *
272
+ * @param append true 追加并判重(addTaskActor)/false 整体替换(saveTask/updateTask)
273
+ */
274
+ writeActors(taskId, actors, append) {
275
+ const normalized = normalizeActors(actors);
276
+ if (!append) {
277
+ this.actors.set(taskId, normalized);
278
+ return;
279
+ }
257
280
  const existing = this.actors.get(taskId) ?? [];
258
281
  const seen = new Set(existing);
259
- for (const a of actors) {
282
+ for (const a of normalized) {
260
283
  if (!seen.has(a)) {
261
284
  existing.push(a);
262
285
  seen.add(a);
@@ -264,22 +287,66 @@ export class MemoryRepository {
264
287
  }
265
288
  this.actors.set(taskId, existing);
266
289
  }
290
+ async addTaskActor(taskId, actors) {
291
+ // issues/142 B 批:改前这里**判重不判空不 trim**(`""`/`" "`/`"null"` 全放行)
292
+ this.writeActors(taskId, actors, true);
293
+ }
267
294
  async removeTaskActor(taskId, actors) {
268
295
  const remove = new Set(actors);
269
296
  this.actors.set(taskId, (this.actors.get(taskId) ?? []).filter(a => !remove.has(a)));
270
297
  }
271
298
  async createCcInstance(instanceId, _creator, ...actorIds) {
272
- const existing = this.ccInstances.get(instanceId) ?? [];
273
- const seen = new Set(existing);
274
- for (const a of actorIds) {
275
- if (!seen.has(a)) {
276
- existing.push(a);
277
- seen.add(a);
299
+ // issues/141 G2 写侧判重=幂等空操作(spec 06 §4),与 JdbcRepository.createCcInstance 同一条判据:
300
+ // 同一 (实例, 被抄送人) 已有 cc 行 ⇒ 跳过——①不新增行、②不重置未读(state 保持原值)、
301
+ // ③不更新原行时间(createTime/updateTime 逐字不变)。判重在写侧,查询侧不引入去重。
302
+ //
303
+ // issues/141 G10「空不创建行」(spec 06 §2.10):与 JdbcRepository 同一判据、同一份实现
304
+ // (`spi.normalizeActorValue`,旧名 normalizeCcActorValue 是它的别名)——空串/纯空白/null 丢弃,
305
+ // 落库值取 trim 后的串。
306
+ // 两仓必须同答案(issues/117 场景 27 那把尺子),且这一层是"绕过引擎/门面直连仓储"的兜底。
307
+ const rows = this.ccInstances.get(instanceId) ?? [];
308
+ for (const rawActorId of actorIds) {
309
+ const actorId = normalizeActorValue(rawActorId);
310
+ if (actorId === '' || rows.some(r => r.actorId === actorId))
311
+ continue;
312
+ const now = new Date();
313
+ rows.push({ actorId, state: 0, createTime: now, updateTime: now });
314
+ }
315
+ this.ccInstances.set(instanceId, rows);
316
+ }
317
+ async findCcActorIds(instanceId) {
318
+ return (this.ccInstances.get(instanceId) ?? []).map(r => r.actorId);
319
+ }
320
+ async createCcInstanceIfAbsent(instanceId, creator, ...actorIds) {
321
+ // 走 spi 里那份 java default 的对应物(与 JdbcRepository 同一条判重逻辑,不各写一遍)
322
+ return defaultCreateCcInstanceIfAbsent(this, instanceId, creator, actorIds);
323
+ }
324
+ async updateCcStatus(instanceId, actorId) {
325
+ // 已读:state 0→1 + 刷 updateTime(对齐 `wf_process_cc_instance.state` 与 java 内存仓同款)。
326
+ // G2 之前这里是纯 no-op ⇒ 「重复抄送不得把已读抹回未读」这一档在内存仓根本测不出来。
327
+ //
328
+ // issues/142 B 批(spec 06 §2.11 表第四行):`actorId` 是归属值,**入参归一后再比**——
329
+ // 比较值取 `spi.normalizeActorValue` 的 trim 后串(否则 `" 123 "` 打不中库里的 `"123"`,
330
+ // 用户点了已读没反应),归一后为空 ⇒ **这一支什么都不做**(空 operator 会把 state=1
331
+ // 打到历史 `actor_id=''` 的脏行上)。与 SQL 仓同一枚判据、两仓同答案。
332
+ const actor = normalizeActorValue(actorId);
333
+ if (actor === '')
334
+ return;
335
+ for (const row of this.ccInstances.get(instanceId) ?? []) {
336
+ if (row.actorId === actor) {
337
+ row.state = 1;
338
+ row.updateTime = new Date();
278
339
  }
279
340
  }
280
- this.ccInstances.set(instanceId, existing);
281
341
  }
282
- async updateCcStatus(_instanceId, _actorId) { }
342
+ /**
343
+ * 测试访问器:读回某实例的 cc **行**(issues/141 G2)。②「不重置未读」与③「不更新原行时间」
344
+ * 必须看 state 与两个时间字段,只看 actor id 集合照不出那两种假修(java 同名 `ccRowsForTest`)。
345
+ * 返回浅拷贝数组,调用方改数组不影响仓储;行对象本身是引用(时间与状态才可比)。
346
+ */
347
+ ccRowsForTest(instanceId) {
348
+ return [...(this.ccInstances.get(instanceId) ?? [])];
349
+ }
283
350
  // ── 核心表分页(v1.5.0)──
284
351
  async pageDefines(pageNum = 1, pageSize = 10, conditions) {
285
352
  const rows = [...this.defines.values()].map(d => ({
@@ -368,10 +435,15 @@ export class MemoryRepository {
368
435
  }
369
436
  // pageCcInstances 我的抄送分页(v1.3.0):按抄送人 actorId 过滤,join 实例 + 定义
370
437
  async pageCcInstances(pageNum = 1, pageSize = 10, actorId, conditions) {
438
+ // issues/141 G1 归属条件必填(spec 06 §2.5):cc.actor_id 上没有有效归属证据 ⇒ 空页,
439
+ // 绝不能退化成"这条不加"放出所有有 cc 行的实例。判据与 JdbcRepository.pageCcInstances
440
+ // 共用 hasEffectiveCcOwnership 那**一份**实现(issues/117 场景 27 那把尺子:同一份数据
441
+ // 两仓必须同答案;旧形状是 SQL 仓不带条件放全部实例、本仓只放有 cc 行的实例,两仓相反)。
442
+ if (!hasEffectiveCcOwnership(actorId, conditions))
443
+ return { rows: [], total: 0 };
371
444
  const rows = [];
372
- const op = ownershipKey(actorId); // issues/129 案 A 第二层:空 ⇒ 空页(cc.actor_id 为归属列)
373
- for (const [instId, actors] of this.ccInstances) {
374
- if (op == null || !actors.includes(op))
445
+ for (const [instId, ccRows] of this.ccInstances) {
446
+ if (!ccRows.some(r => r.actorId === actorId))
375
447
  continue;
376
448
  const inst = this.instances.get(instId);
377
449
  if (!inst)
@@ -387,7 +459,7 @@ export class MemoryRepository {
387
459
  defineVersion: def?.version ?? 0,
388
460
  };
389
461
  const fields = pickFields(r, INSTANCE_FIELDS);
390
- fields['cc.actor_id'] = actors;
462
+ fields['cc.actor_id'] = ccRows.map(row => row.actorId);
391
463
  if (matchConditions(conditions, fields))
392
464
  rows.push(r);
393
465
  }
package/dist/model.d.ts CHANGED
@@ -181,6 +181,21 @@ export declare class ProcessInstance {
181
181
  *
182
182
  * 创建任务(子实体工厂)——performType:0 普通 / 1 会签(issues/52 E24 落库对齐 Java) */
183
183
  createTask(id: string, taskName: string, displayName: string, actor: string, operator: string, formKey: string, now: Date, parentId: string, isFirst: boolean, performType?: number): ProcessTask;
184
+ /**
185
+ * 记录类历史行工厂(issues/142 A 批 · spec 02-flow-definition.md §6.1/§6.2,owner 2026-09-29/09-30 两次拍)
186
+ *
187
+ * 形状基准=jeeflow-java `ProcessInstance.createHistoryTask`(domain/ProcessInstance.java:425)
188
+ * + python `create_history_task`(jeeflow/model.py:223):`taskState=20(DONE)`、
189
+ * 参与者=`[operator]`(**留痕主体,不是待办**——java 那侧是 `Collections.singletonList(operator)`)、
190
+ * 无 formKey、无会签字段、`finishTime` 已落;建单不变量(`parentTaskId` + 行级 `isFirstTaskNode`)
191
+ * 与 `createTask` 同规格适用(issues/121 P1,java 那边也是同一句注释)。
192
+ *
193
+ * ⚠️ 这一支存在的理由:记录类节点(`snaker:custom`)**没有参与者是正常形态**,既不许按任务类
194
+ * 建 DOING 行(§6.1 禁止形状①),也不许"兜底把行挂给当前操作人"伪造一条他不该收到的待办
195
+ * (禁止形状②——行是 DONE ⇒ 谁也办不动,天然不在待办里),更不许直接跳过节点丢留痕(禁止形状③)。
196
+ * 调用方必须把返回的行**真落库**(`repo.saveTask`)——§6.2 第 1 条:只在聚合 `tasks` 里 append
197
+ * 不算做到,java/c# 现读正是栽在这条上的(基准自身的洞,本栈不照抄)。 */
198
+ createHistoryTask(id: string, taskName: string, displayName: string, operator: string, now: Date, parentId: string, isFirst: boolean): ProcessTask;
184
199
  }
185
200
  export declare class ProcessTask {
186
201
  id: string;
package/dist/model.js CHANGED
@@ -179,6 +179,33 @@ export class ProcessInstance {
179
179
  this.tasks.push(task);
180
180
  return task;
181
181
  }
182
+ /**
183
+ * 记录类历史行工厂(issues/142 A 批 · spec 02-flow-definition.md §6.1/§6.2,owner 2026-09-29/09-30 两次拍)
184
+ *
185
+ * 形状基准=jeeflow-java `ProcessInstance.createHistoryTask`(domain/ProcessInstance.java:425)
186
+ * + python `create_history_task`(jeeflow/model.py:223):`taskState=20(DONE)`、
187
+ * 参与者=`[operator]`(**留痕主体,不是待办**——java 那侧是 `Collections.singletonList(operator)`)、
188
+ * 无 formKey、无会签字段、`finishTime` 已落;建单不变量(`parentTaskId` + 行级 `isFirstTaskNode`)
189
+ * 与 `createTask` 同规格适用(issues/121 P1,java 那边也是同一句注释)。
190
+ *
191
+ * ⚠️ 这一支存在的理由:记录类节点(`snaker:custom`)**没有参与者是正常形态**,既不许按任务类
192
+ * 建 DOING 行(§6.1 禁止形状①),也不许"兜底把行挂给当前操作人"伪造一条他不该收到的待办
193
+ * (禁止形状②——行是 DONE ⇒ 谁也办不动,天然不在待办里),更不许直接跳过节点丢留痕(禁止形状③)。
194
+ * 调用方必须把返回的行**真落库**(`repo.saveTask`)——§6.2 第 1 条:只在聚合 `tasks` 里 append
195
+ * 不算做到,java/c# 现读正是栽在这条上的(基准自身的洞,本栈不照抄)。 */
196
+ createHistoryTask(id, taskName, displayName, operator, now, parentId, isFirst) {
197
+ const task = new ProcessTask({
198
+ id, processInstanceId: this.id,
199
+ taskName, displayName, taskState: TaskState.Done,
200
+ actorId: operator ?? '', actorIds: operator ? [operator] : [],
201
+ taskType: 0, performType: 0, formKey: '', parentTaskId: parentId,
202
+ variables: { isFirstTaskNode: isFirst },
203
+ finishTime: now,
204
+ createTime: now, updateTime: now, createUser: operator, updateUser: operator,
205
+ });
206
+ this.tasks.push(task);
207
+ return task;
208
+ }
182
209
  }
183
210
  // ─── 子实体:ProcessTask ────────────────────────────────────────────────────────
184
211
  export class ProcessTask {
@@ -8,8 +8,24 @@ export interface IAssignmentHandler {
8
8
  export interface IDecisionHandler {
9
9
  decide(node: FlowNode, inst: ProcessInstance, vars: Record<string, any>): string | Promise<string>;
10
10
  }
11
+ /**
12
+ * 记录类节点(`snaker:custom`)处理器接口 —— issues/142 A 批 · spec 02-flow-definition.md §6.2 第 2 条。
13
+ *
14
+ * 注册键=流程定义里 `properties.clazz` 的**原样字符串**(如夹具
15
+ * `flows/08-custom-node.json` 的 `com.mldong.jeeflow.test.TestCustomHandler`)。
16
+ * java 那边是 `Class.forName(clazz).newInstance()` 的反射按名实例化;TS 没有可依托的反射语义,
17
+ * 共享夹具里的 JVM 类名在 node 永远实例化不到,故与 **c#(`Context.CustomHandlers`) /
18
+ * python(`HandlerRegistry.register_custom`) 同策**:集成方按名注册实例,引擎按名解析后调用。
19
+ *
20
+ * 返回值非 `undefined` 时由引擎写进执行变量,键=节点 `properties.val`(缺省 `custom_return_val`),
21
+ * 对齐 java `CustomParser.java:20-22` + `CustomModel.java:46-48`。
22
+ * 可同步可异步(与 `IAssignmentHandler.assign` 一样两侧都吃)。
23
+ */
24
+ export interface ICustomHandler {
25
+ handle(node: FlowNode, inst: ProcessInstance, operator: string, vars: Record<string, any>): any | Promise<any>;
26
+ }
11
27
  /** 处理器类型名(对齐 Java/go/python HandlerMeta.type,四语言通用) */
12
- export type HandlerType = 'AssignmentHandler' | 'CandidateHandler' | 'FlowInterceptor' | 'DecisionHandler';
28
+ export type HandlerType = 'AssignmentHandler' | 'CandidateHandler' | 'FlowInterceptor' | 'DecisionHandler' | 'CustomHandler';
13
29
  /** 处理器元数据(v1.4.0,SPI 实现清单字典源) */
14
30
  export interface HandlerMeta {
15
31
  /** 处理器类型(内置 AssignmentHandler 元数据自动携带;老数据缺省按 AssignmentHandler 归类) */
@@ -29,16 +45,26 @@ export declare const BUILTIN_ASSIGNMENT_METAS: HandlerMeta[];
29
45
  export declare class HandlerRegistry {
30
46
  private assignments;
31
47
  private decisions;
48
+ private customs;
32
49
  private metas;
33
50
  /** 构造即内置 7 个通用 AssignmentHandler 元数据(v1.6.0 issues/16,注册名与 Java 类全限定名一致) */
34
51
  constructor();
35
52
  registerAssignment(name: string, handler: IAssignmentHandler, meta?: Omit<HandlerMeta, 'name' | 'type'>): void;
36
53
  registerDecision(name: string, handler: IDecisionHandler, meta?: Omit<HandlerMeta, 'name' | 'type'>): void;
54
+ /**
55
+ * 注册记录类节点处理器(issues/142 A 批 · spec 02 §6.2 第 2 条)。
56
+ * `name` 必须是流程定义 `properties.clazz` 的**原样字符串**(引擎按名解析,不做反射、不做包名裁剪)。
57
+ */
58
+ registerCustom(name: string, handler: ICustomHandler, meta?: Omit<HandlerMeta, 'name' | 'type'>): void;
37
59
  /** 注册处理器元数据(不绑定运行时实现,对齐 Java HandlerRegistry.register;
38
60
  * 拦截器/候选类清单等无运行时注册表的类型用) */
39
61
  registerMeta(type: HandlerType, meta: Omit<HandlerMeta, 'type'>): void;
40
62
  resolveAssignment(name: string): IAssignmentHandler | undefined;
41
63
  resolveDecision(name: string): IDecisionHandler | undefined;
64
+ /**
65
+ * 按 `clazz` 原样串解析记录类节点处理器;空名/未注册 ⇒ `undefined`
66
+ * (引擎侧分档记日志后照常落历史行并续流,**不抛错** —— spec 02 §6.2 第 2 条)。 */
67
+ resolveCustom(name: string): ICustomHandler | undefined;
42
68
  /** 按处理器类型列出可用实现的元数据(按 order 升序;
43
69
  * AssignmentHandler/DecisionHandler 并集运行时注册名,其余类型只列显式元数据) */
44
70
  listHandlers(typeName: HandlerType): HandlerMeta[];
package/dist/registry.js CHANGED
@@ -12,6 +12,7 @@ export const BUILTIN_ASSIGNMENT_METAS = [
12
12
  export class HandlerRegistry {
13
13
  assignments = new Map();
14
14
  decisions = new Map();
15
+ customs = new Map();
15
16
  metas = new Map();
16
17
  /** 构造即内置 7 个通用 AssignmentHandler 元数据(v1.6.0 issues/16,注册名与 Java 类全限定名一致) */
17
18
  constructor() {
@@ -29,6 +30,15 @@ export class HandlerRegistry {
29
30
  if (meta)
30
31
  this.metas.set(name, { type: 'DecisionHandler', name, ...meta });
31
32
  }
33
+ /**
34
+ * 注册记录类节点处理器(issues/142 A 批 · spec 02 §6.2 第 2 条)。
35
+ * `name` 必须是流程定义 `properties.clazz` 的**原样字符串**(引擎按名解析,不做反射、不做包名裁剪)。
36
+ */
37
+ registerCustom(name, handler, meta) {
38
+ this.customs.set(name, handler);
39
+ if (meta)
40
+ this.metas.set(name, { type: 'CustomHandler', name, ...meta });
41
+ }
32
42
  /** 注册处理器元数据(不绑定运行时实现,对齐 Java HandlerRegistry.register;
33
43
  * 拦截器/候选类清单等无运行时注册表的类型用) */
34
44
  registerMeta(type, meta) {
@@ -40,6 +50,12 @@ export class HandlerRegistry {
40
50
  resolveDecision(name) {
41
51
  return this.decisions.get(name);
42
52
  }
53
+ /**
54
+ * 按 `clazz` 原样串解析记录类节点处理器;空名/未注册 ⇒ `undefined`
55
+ * (引擎侧分档记日志后照常落历史行并续流,**不抛错** —— spec 02 §6.2 第 2 条)。 */
56
+ resolveCustom(name) {
57
+ return name ? this.customs.get(name) : undefined;
58
+ }
43
59
  // ── SPI 实现清单(v1.4.0)──
44
60
  /** 按处理器类型列出可用实现的元数据(按 order 升序;
45
61
  * AssignmentHandler/DecisionHandler 并集运行时注册名,其余类型只列显式元数据) */
@@ -53,6 +69,10 @@ export class HandlerRegistry {
53
69
  for (const n of this.decisions.keys())
54
70
  names.add(n);
55
71
  }
72
+ else if (typeName === 'CustomHandler') {
73
+ for (const n of this.customs.keys())
74
+ names.add(n);
75
+ }
56
76
  for (const [n, m] of this.metas) {
57
77
  // 老数据无 type 时按 AssignmentHandler 归类(与历史 listHandlers 行为一致)
58
78
  if ((m.type ?? 'AssignmentHandler') === typeName)
@@ -68,6 +88,6 @@ export class HandlerRegistry {
68
88
  }
69
89
  /** 已注册的处理器名称清单(含未带元数据的) */
70
90
  listHandlerNames() {
71
- return [...this.assignments.keys(), ...this.decisions.keys()];
91
+ return [...this.assignments.keys(), ...this.decisions.keys(), ...this.customs.keys()];
72
92
  }
73
93
  }