oak-domain 5.1.14 → 5.1.15

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.
@@ -1405,16 +1405,24 @@ class CascadeStore extends RowStore_1.RowStore {
1405
1405
  },
1406
1406
  };
1407
1407
  };
1408
- if (option.modiParentEntity && !['modi', 'modiEntity'].includes(entity)) {
1409
- // 延时更新,变成对modi的操作
1410
- if (action === 'update' && Object.keys(data).length === 0) {
1411
- return {};
1408
+ const saveRecordAndCreateOper = async () => {
1409
+ if (action === 'remove') {
1410
+ if (!option.dontCollect) {
1411
+ context.saveOpRecord(entity, {
1412
+ id: operId,
1413
+ action,
1414
+ data: data,
1415
+ filter: {
1416
+ id: {
1417
+ $in: ids,
1418
+ }
1419
+ },
1420
+ });
1421
+ }
1412
1422
  }
1413
- return createModi();
1414
- }
1415
- else {
1416
- const saveRecordAndCreateOper = async () => {
1417
- if (action === 'remove') {
1423
+ else {
1424
+ const updateAttrCount = Object.keys(data).length;
1425
+ if (updateAttrCount > 0) {
1418
1426
  if (!option.dontCollect) {
1419
1427
  context.saveOpRecord(entity, {
1420
1428
  id: operId,
@@ -1428,68 +1436,61 @@ class CascadeStore extends RowStore_1.RowStore {
1428
1436
  });
1429
1437
  }
1430
1438
  }
1431
- else {
1432
- const updateAttrCount = Object.keys(data).length;
1433
- if (updateAttrCount > 0) {
1434
- if (!option.dontCollect) {
1435
- context.saveOpRecord(entity, {
1436
- id: operId,
1437
- action,
1438
- data: data,
1439
- filter: {
1440
- id: {
1441
- $in: ids,
1442
- }
1443
- },
1444
- });
1445
- }
1446
- }
1447
- else {
1448
- return {};
1449
- }
1450
- }
1451
- if (!option.dontCreateOper && !['oper', 'operEntity', 'modiEntity', 'modi', 'log'].includes(entity) && ids.length > 0) {
1452
- // 按照框架要求生成Oper和OperEntity这两个内置的对象
1453
- (0, assert_1.default)(operId);
1454
- const operatorId = context.getCurrentUserId(true);
1455
- const createOper = {
1456
- id: 'dummy',
1457
- action: 'create',
1458
- data: {
1459
- id: operId,
1460
- action,
1461
- data,
1462
- targetEntity: entity,
1463
- bornAt,
1464
- operatorId,
1465
- operEntity$oper: {
1466
- id: 'dummy',
1467
- action: 'create',
1468
- data: await Promise.all(ids.map(async (ele) => ({
1469
- id: await (0, uuid_1.generateNewIdAsync)(),
1470
- entityId: ele,
1471
- entity: entity,
1472
- })))
1473
- },
1474
- filter: {
1475
- id: { $in: ids },
1476
- },
1477
- logId: entity === 'log' ? undefined : option.logId,
1478
- undoData,
1439
+ }
1440
+ if (!option.dontCreateOper && !['oper', 'operEntity', 'modiEntity', 'modi', 'log'].includes(entity) && ids.length > 0) {
1441
+ // 按照框架要求生成Oper和OperEntity这两个内置的对象
1442
+ (0, assert_1.default)(operId);
1443
+ const operatorId = context.getCurrentUserId(true);
1444
+ const createOper = {
1445
+ id: 'dummy',
1446
+ action: 'create',
1447
+ data: {
1448
+ id: operId,
1449
+ action,
1450
+ data,
1451
+ targetEntity: entity,
1452
+ bornAt,
1453
+ operatorId,
1454
+ operEntity$oper: {
1455
+ id: 'dummy',
1456
+ action: 'create',
1457
+ data: await Promise.all(ids.map(async (ele) => ({
1458
+ id: await (0, uuid_1.generateNewIdAsync)(),
1459
+ entityId: ele,
1460
+ entity: entity,
1461
+ })))
1479
1462
  },
1480
- };
1481
- const closeRootMode = context.openRootMode();
1482
- await this.cascadeUpdateAsync('oper', createOper, context, {
1483
- dontCollect: !option.logId, // 如果是在创建log,则把oper收集回去
1484
- });
1485
- closeRootMode();
1486
- }
1487
- return {
1488
- [entity]: {
1489
- [action]: ids.length,
1490
- }
1463
+ filter: {
1464
+ id: { $in: ids },
1465
+ },
1466
+ logId: entity === 'log' ? undefined : option.logId,
1467
+ undoData,
1468
+ },
1491
1469
  };
1470
+ const closeRootMode = context.openRootMode();
1471
+ await this.cascadeUpdateAsync('oper', createOper, context, {
1472
+ dontCollect: !option.logId, // 如果是在创建log,则把oper收集回去
1473
+ });
1474
+ closeRootMode();
1475
+ }
1476
+ return {
1477
+ [entity]: {
1478
+ [action]: ids.length,
1479
+ }
1492
1480
  };
1481
+ };
1482
+ if (action !== 'remove' && Object.keys(data).length === 0) {
1483
+ if (action !== 'update') {
1484
+ // 如果不是update,这里还是记一条oper
1485
+ return saveRecordAndCreateOper();
1486
+ }
1487
+ return {};
1488
+ }
1489
+ if (option.modiParentEntity && !['modi', 'modiEntity'].includes(entity)) {
1490
+ // 延时更新,变成对modi的操作
1491
+ return createModi();
1492
+ }
1493
+ else {
1493
1494
  const count = await this.updateAbjointRowAsync(entity, operation, context, option);
1494
1495
  if (count === ids.length) {
1495
1496
  return await saveRecordAndCreateOper();
@@ -352,11 +352,11 @@ class TriggerExecutor {
352
352
  const trigger = this.triggerNameMap[name];
353
353
  (0, assert_1.default)(trigger && trigger.when === 'commit');
354
354
  // assert(ids.length > 0);
355
- const { fn } = trigger;
355
+ const { fn, cleanTriggerDataBySelf } = trigger;
356
356
  const closeRoot = trigger.asRoot && context.openRootMode();
357
357
  try {
358
358
  const callback = await fn({ ids }, context, option);
359
- if (trigger.strict === 'makeSure' && ids.length) {
359
+ if (trigger.strict === 'makeSure' && ids.length && !cleanTriggerDataBySelf) {
360
360
  // 这里开root模式,否则还可能有权限问题
361
361
  const closeRoot2 = context.openRootMode();
362
362
  try {
@@ -485,67 +485,10 @@ class TriggerExecutor {
485
485
  }
486
486
  async checkpoint(timestamp) {
487
487
  let result = 0;
488
- for (const entity of this.volatileEntities) {
489
- const filter = {
490
- [Entity_1.TriggerUuidAttribute]: {
491
- $exists: true,
492
- },
493
- [Entity_1.UpdateAtAttribute]: {
494
- $lt: timestamp,
495
- }
496
- };
497
- const context = this.contextBuilder();
498
- await context.begin();
499
- try {
500
- const rows = await context.select(entity, {
501
- data: {
502
- id: 1,
503
- },
504
- filter,
505
- }, {
506
- includedDeleted: true,
507
- dontCollect: true,
508
- });
509
- if (rows.length > 0) {
510
- // 要用id来再锁一次,不然会锁住filter的范围,影响并发性
511
- // by Xc 20240314,在haina-busi和haina-cn数据sync过程中发现这个问题
512
- const rows2 = await context.select(entity, {
513
- data: {
514
- id: 1,
515
- [Entity_1.TriggerDataAttribute]: 1,
516
- [Entity_1.TriggerUuidAttribute]: 1,
517
- },
518
- filter: {
519
- id: {
520
- $in: rows.map(ele => ele.id),
521
- },
522
- },
523
- }, {
524
- includedDeleted: true,
525
- dontCollect: true,
526
- forUpdate: 'skip locked', // 如果加不上锁就下次再处理,或者有可能应用自己在处理
527
- });
528
- const grouped = (0, lodash_1.groupBy)(rows2, Entity_1.TriggerUuidAttribute);
529
- for (const uuid in grouped) {
530
- const rs = grouped[uuid];
531
- const { [Entity_1.TriggerDataAttribute]: triggerData } = rs[0];
532
- const { name, cxtStr, option } = triggerData;
533
- await context.initialize(JSON.parse(cxtStr), true);
534
- await this.execVolatileTrigger(entity, name, rs.map(ele => ele.id), context, option);
535
- }
536
- }
537
- await context.commit();
538
- result += rows.length;
539
- }
540
- catch (err) {
541
- if (!(err instanceof types_1.OakPartialSuccess)) {
542
- await context.rollback();
543
- this.logger.error(`error in checkpoint on entity 「${entity}」`, err);
544
- }
545
- else {
546
- await context.commit();
547
- this.logger.error(`error in checkpoint on entity 「${entity}」`, err);
548
- }
488
+ for (const name in this.triggerNameMap) {
489
+ const trigger = this.triggerNameMap[name];
490
+ if (trigger && trigger.when === 'commit') {
491
+ result += await this.independentCheckPoint(name, timestamp);
549
492
  }
550
493
  }
551
494
  return result;
@@ -40,6 +40,7 @@ interface TriggerCrossTxn<ED extends EntityDict & BaseEntityDict, Cxt extends As
40
40
  when: 'commit';
41
41
  strict?: 'takeEasy' | 'makeSure';
42
42
  cs?: true;
43
+ cleanTriggerDataBySelf?: true;
43
44
  singleton?: true;
44
45
  grouped?: true;
45
46
  fn: (event: {
@@ -78,8 +78,7 @@ class SimpleConnector {
78
78
  ;
79
79
  async parseAspectResult(response) {
80
80
  if (response.status > 299) {
81
- const err = new types_1.OakServerProxyException(`网络请求返回status是${response.status}`);
82
- throw this.makeException(err);
81
+ throw new types_1.OakServerProxyException(`网络请求返回status是${response.status}`);
83
82
  }
84
83
  const message = response.headers.get('oak-message');
85
84
  const responseType = response.headers.get('Content-Type') ||
@@ -120,14 +119,10 @@ class SimpleConnector {
120
119
  }
121
120
  catch (err) {
122
121
  // fetch返回异常一定是网络异常
123
- let exception = err;
124
122
  if (err instanceof types_1.OakRequestTimeoutException) {
125
- exception = new types_1.OakNetworkException(`接口请求超时`);
123
+ throw new types_1.OakNetworkException(`接口请求超时`);
126
124
  }
127
- else {
128
- exception = new types_1.OakNetworkException(`接口请求时发生网络异常`);
129
- }
130
- throw this.makeException(exception);
125
+ throw new types_1.OakNetworkException(`接口请求时发生网络异常`);
131
126
  }
132
127
  return this.parseAspectResult(response);
133
128
  }
@@ -149,18 +144,13 @@ class SimpleConnector {
149
144
  response = await this.fetchWithTimeout(this.serverSubscribePointUrl, {}, this.timeout);
150
145
  }
151
146
  catch (err) {
152
- let exception = err;
153
147
  if (err instanceof types_1.OakRequestTimeoutException) {
154
- exception = new types_1.OakNetworkException(`接口请求超时`);
155
- }
156
- else {
157
- exception = new types_1.OakNetworkException(`接口请求时发生网络异常`);
148
+ throw new types_1.OakNetworkException(`接口请求超时`);
158
149
  }
159
- throw this.makeException(exception);
150
+ throw new types_1.OakNetworkException(`接口请求时发生网络异常`);
160
151
  }
161
152
  if (response.status > 299) {
162
- const err = new types_1.OakServerProxyException(`网络请求返回status是${response.status}`);
163
- throw this.makeException(err);
153
+ throw new types_1.OakServerProxyException(`网络请求返回status是${response.status}`);
164
154
  }
165
155
  const message = response.headers.get('oak-message');
166
156
  const responseType = response.headers.get('Content-Type') ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oak-domain",
3
- "version": "5.1.14",
3
+ "version": "5.1.15",
4
4
  "author": {
5
5
  "name": "XuChang"
6
6
  },