@chevre/domain 22.11.0-alpha.2 → 22.11.0-alpha.20

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.
Files changed (146) hide show
  1. package/example/src/chevre/assetTransaction/processReserve.ts +0 -1
  2. package/example/src/chevre/notifyAbortedTasksByEmail.ts +1 -1
  3. package/example/src/chevre/orders/searchWithUnwoundAcceptedOffers.ts +73 -0
  4. package/example/src/chevre/roles/addAdminPermissionIfNotExists.ts +132 -0
  5. package/example/src/chevre/roles/addDefaultPermissionIfNotExists.ts +37 -0
  6. package/example/src/chevre/roles/addEventOfferPermissionIfNotExists.ts +27 -0
  7. package/example/src/chevre/roles/addPermissionIfNotExists.ts +39 -6
  8. package/example/src/chevre/roles/addProjectCreatorRole.ts +48 -0
  9. package/example/src/chevre/roles/assignGlobalRoles.ts +72 -0
  10. package/example/src/chevre/roles/findPermissions.ts +84 -0
  11. package/example/src/chevre/roles/findRoleNames.ts +117 -0
  12. package/example/src/chevre/roles/removeConsolePermissionIfExists.ts +38 -0
  13. package/example/src/chevre/roles/removePermissionFromAPIRoles.ts +46 -0
  14. package/example/src/chevre/roles/removePermissionIfExists.ts +39 -0
  15. package/example/src/chevre/settings/addSettings.ts +23 -17
  16. package/example/src/chevre/stockHolder/checkRedisKeyCount.ts +11 -20
  17. package/example/src/chevre/unsetUnnecessaryFields.ts +8 -5
  18. package/example/src/idaas/auth0/adminApplications.ts +183 -0
  19. package/example/src/idaas/auth0/getToken.ts +55 -0
  20. package/example/src/idaas/auth0/getTokenByPrivateKeyJWT.ts +84 -0
  21. package/example/src/regex.ts +31 -0
  22. package/lib/chevre/eventEmitter/task.d.ts +13 -4
  23. package/lib/chevre/index.d.ts +0 -2
  24. package/lib/chevre/index.js +0 -10
  25. package/lib/chevre/repo/acceptedOffer.d.ts +3 -1
  26. package/lib/chevre/repo/acceptedOffer.js +11 -3
  27. package/lib/chevre/repo/confirmationNumber.d.ts +0 -11
  28. package/lib/chevre/repo/confirmationNumber.js +15 -54
  29. package/lib/chevre/repo/identity.d.ts +11 -33
  30. package/lib/chevre/repo/identity.js +10 -15
  31. package/lib/chevre/repo/member.d.ts +22 -4
  32. package/lib/chevre/repo/member.js +81 -27
  33. package/lib/chevre/repo/mongoose/schemas/identity.d.ts +1 -1
  34. package/lib/chevre/repo/mongoose/schemas/member/global.d.ts +14 -0
  35. package/lib/chevre/repo/mongoose/schemas/member/global.js +82 -0
  36. package/lib/chevre/repo/mongoose/schemas/setting.d.ts +11 -0
  37. package/lib/chevre/repo/mongoose/schemas/setting.js +1 -0
  38. package/lib/chevre/repo/orderNumber.d.ts +0 -11
  39. package/lib/chevre/repo/orderNumber.js +13 -51
  40. package/lib/chevre/repo/role.d.ts +16 -4
  41. package/lib/chevre/repo/role.js +71 -32
  42. package/lib/chevre/repo/serviceOutputIdentifier.d.ts +0 -4
  43. package/lib/chevre/repo/serviceOutputIdentifier.js +13 -38
  44. package/lib/chevre/repo/setting.d.ts +5 -10
  45. package/lib/chevre/repo/setting.js +4 -7
  46. package/lib/chevre/repo/stockHolder.js +0 -11
  47. package/lib/chevre/repo/task.d.ts +31 -25
  48. package/lib/chevre/repo/task.js +110 -201
  49. package/lib/chevre/repo/transactionNumber.d.ts +0 -11
  50. package/lib/chevre/repo/transactionNumber.js +13 -51
  51. package/lib/chevre/repo/transactionNumberCounter.d.ts +0 -10
  52. package/lib/chevre/repo/transactionNumberCounter.js +34 -29
  53. package/lib/chevre/service/assetTransaction/cancelReservation/start.d.ts +1 -1
  54. package/lib/chevre/service/code.d.ts +5 -28
  55. package/lib/chevre/service/code.js +3 -79
  56. package/lib/chevre/service/iam.d.ts +17 -7
  57. package/lib/chevre/service/iam.js +26 -6
  58. package/lib/chevre/service/notification/notifyAbortedTasksByEmail.d.ts +15 -0
  59. package/lib/chevre/service/notification/notifyAbortedTasksByEmail.js +38 -0
  60. package/lib/chevre/service/notification.d.ts +2 -1
  61. package/lib/chevre/service/notification.js +3 -1
  62. package/lib/chevre/service/task/acceptCOAOffer.d.ts +1 -1
  63. package/lib/chevre/service/task/acceptCOAOffer.js +6 -5
  64. package/lib/chevre/service/task/aggregateOffers.d.ts +1 -1
  65. package/lib/chevre/service/task/aggregateOnSystem.d.ts +4 -2
  66. package/lib/chevre/service/task/aggregateScreeningEvent.d.ts +1 -1
  67. package/lib/chevre/service/task/authorizePayment.d.ts +1 -1
  68. package/lib/chevre/service/task/authorizePayment.js +7 -6
  69. package/lib/chevre/service/task/cancelMoneyTransfer.d.ts +1 -1
  70. package/lib/chevre/service/task/cancelPendingReservation.d.ts +1 -1
  71. package/lib/chevre/service/task/cancelReservation.d.ts +1 -1
  72. package/lib/chevre/service/task/checkMovieTicket.d.ts +1 -1
  73. package/lib/chevre/service/task/checkMovieTicket.js +4 -3
  74. package/lib/chevre/service/task/checkResource.d.ts +1 -1
  75. package/lib/chevre/service/task/confirmMoneyTransfer.d.ts +1 -1
  76. package/lib/chevre/service/task/confirmPayTransaction.d.ts +1 -1
  77. package/lib/chevre/service/task/confirmRegisterService.d.ts +1 -1
  78. package/lib/chevre/service/task/confirmRegisterServiceTransaction.d.ts +1 -1
  79. package/lib/chevre/service/task/confirmReserveTransaction.d.ts +1 -1
  80. package/lib/chevre/service/task/createAccountingReport.d.ts +1 -1
  81. package/lib/chevre/service/task/createEvent.d.ts +1 -1
  82. package/lib/chevre/service/task/deletePerson.d.ts +1 -1
  83. package/lib/chevre/service/task/deleteTransaction.d.ts +1 -1
  84. package/lib/chevre/service/task/givePointAward.d.ts +1 -1
  85. package/lib/chevre/service/task/givePointAward.js +1 -1
  86. package/lib/chevre/service/task/handleNotification.d.ts +4 -2
  87. package/lib/chevre/service/task/importEventCapacitiesFromCOA.d.ts +1 -1
  88. package/lib/chevre/service/task/importEventsFromCOA.d.ts +1 -1
  89. package/lib/chevre/service/task/importOffersFromCOA.d.ts +1 -1
  90. package/lib/chevre/service/task/invalidatePaymentUrl.d.ts +1 -1
  91. package/lib/chevre/service/task/moneyTransfer.d.ts +1 -1
  92. package/lib/chevre/service/task/moneyTransfer.js +1 -1
  93. package/lib/chevre/service/task/onAssetTransactionStatusChanged.d.ts +1 -1
  94. package/lib/chevre/service/task/onAuthorizationCreated.d.ts +1 -1
  95. package/lib/chevre/service/task/onEventChanged.d.ts +1 -1
  96. package/lib/chevre/service/task/onOrderPaymentCompleted.d.ts +1 -1
  97. package/lib/chevre/service/task/onResourceUpdated.d.ts +1 -1
  98. package/lib/chevre/service/task/pay.d.ts +1 -1
  99. package/lib/chevre/service/task/placeOrder.d.ts +1 -1
  100. package/lib/chevre/service/task/publishPaymentUrl.d.ts +1 -1
  101. package/lib/chevre/service/task/publishPaymentUrl.js +6 -7
  102. package/lib/chevre/service/task/refund.d.ts +1 -1
  103. package/lib/chevre/service/task/refund.js +1 -1
  104. package/lib/chevre/service/task/registerService.d.ts +1 -1
  105. package/lib/chevre/service/task/reserve.d.ts +1 -1
  106. package/lib/chevre/service/task/returnMoneyTransfer.d.ts +1 -1
  107. package/lib/chevre/service/task/returnMoneyTransfer.js +1 -1
  108. package/lib/chevre/service/task/returnOrder.d.ts +1 -1
  109. package/lib/chevre/service/task/returnPayTransaction.d.ts +1 -1
  110. package/lib/chevre/service/task/returnPayTransaction.js +1 -1
  111. package/lib/chevre/service/task/returnPointAward.d.ts +1 -1
  112. package/lib/chevre/service/task/returnPointAward.js +1 -1
  113. package/lib/chevre/service/task/returnReserveTransaction.d.ts +1 -1
  114. package/lib/chevre/service/task/returnReserveTransaction.js +1 -1
  115. package/lib/chevre/service/task/sendEmailMessage.d.ts +1 -1
  116. package/lib/chevre/service/task/sendOrder.d.ts +1 -1
  117. package/lib/chevre/service/task/triggerWebhook.d.ts +1 -1
  118. package/lib/chevre/service/task/useReservation.d.ts +1 -1
  119. package/lib/chevre/service/task/voidMoneyTransferTransaction.d.ts +1 -1
  120. package/lib/chevre/service/task/voidPayTransaction.d.ts +1 -1
  121. package/lib/chevre/service/task/voidPayment.d.ts +1 -1
  122. package/lib/chevre/service/task/voidRegisterServiceTransaction.d.ts +1 -1
  123. package/lib/chevre/service/task/voidReserveTransaction.d.ts +1 -1
  124. package/lib/chevre/service/task/voidReserveTransaction.js +4 -3
  125. package/lib/chevre/service/task.d.ts +1 -23
  126. package/lib/chevre/service/task.js +3 -110
  127. package/lib/chevre/service/taskHandler.d.ts +26 -0
  128. package/lib/chevre/service/taskHandler.js +139 -0
  129. package/lib/chevre/service/validation/validateOrder.js +55 -37
  130. package/lib/chevre/service.d.ts +0 -4
  131. package/lib/chevre/service.js +10 -14
  132. package/lib/chevre/settings/aggregation.d.ts +6 -1
  133. package/lib/chevre/settings/aggregation.js +2 -1
  134. package/package.json +5 -3
  135. package/example/src/chevre/adminAuth/adminIdentity.ts +0 -38
  136. package/example/src/chevre/findExecutableTask.ts +0 -50
  137. package/example/src/chevre/findSetting.ts +0 -79
  138. package/example/src/chevre/roles/addRoleMembers.ts +0 -75
  139. package/example/src/chevre/searchPermissions.ts +0 -46
  140. package/example/src/chevre/transactionNumber/publishConfimationNumber.ts +0 -37
  141. package/example/src/chevre/transactionNumber/publishOrderNumber.ts +0 -40
  142. package/example/src/chevre/transactionNumber/setUseMongo4confirmationNumberFrom.ts +0 -45
  143. package/example/src/chevre/transactionNumber/setUseMongo4orderNumberFrom.ts +0 -41
  144. package/example/src/chevre/transactionNumber/setUseMongo4transactionNumberFrom.ts +0 -41
  145. package/lib/chevre/adminAuth.d.ts +0 -2
  146. package/lib/chevre/adminAuth.js +0 -6
@@ -242,48 +242,6 @@ class TaskRepo {
242
242
  return { id, status };
243
243
  });
244
244
  }
245
- // public async createIfNotExistByIdentifier(
246
- // params: factory.task.IAttributes<factory.taskName> & {
247
- // // resolve uniqueness of identifier(2025-03-27~)
248
- // identifier: string;
249
- // },
250
- // options: IOptionOnCreate
251
- // ): Promise<void> {
252
- // if (typeof params.identifier !== 'string' || params.identifier.length === 0) {
253
- // throw new factory.errors.ArgumentNull('identifier');
254
- // }
255
- // try {
256
- // const createdTask = await this.taskModel.findOneAndUpdate(
257
- // {
258
- // 'project.id': { $eq: params.project.id },
259
- // name: { $eq: params.name },
260
- // identifier: { $exists: true, $eq: params.identifier }
261
- // },
262
- // { $setOnInsert: params },
263
- // { new: true, upsert: true }
264
- // )
265
- // .select({ _id: 1 })
266
- // .exec();
267
- // if (options.emitImmediately) {
268
- // taskEventEmitter.emitTaskStatusChanged({
269
- // id: createdTask.id,
270
- // name: params.name,
271
- // status: factory.taskStatus.Ready
272
- // });
273
- // }
274
- // } catch (error) {
275
- // let throwsError = true;
276
- // if (await isMongoError(error)) {
277
- // // すでにidentifierが存在する場合ok
278
- // if (error.code === MongoErrorCode.DuplicateKey) {
279
- // throwsError = false;
280
- // }
281
- // }
282
- // if (throwsError) {
283
- // throw error;
284
- // }
285
- // }
286
- // }
287
245
  /**
288
246
  * タスク識別子から冪等作成する
289
247
  * reimplement createIfNotExistByIdentifier(2025-03-28~)
@@ -341,40 +299,6 @@ class TaskRepo {
341
299
  }
342
300
  });
343
301
  }
344
- // public async createInformTaskIfNotExist(
345
- // // resolve uniqueness of identifier(2025-03-27~)
346
- // params: Pick<
347
- // factory.task.IAttributes<factory.taskName.TriggerWebhook>,
348
- // 'data' | 'executionResults' | 'name' | 'numberOfTried' | 'project' | 'remainingNumberOfTries' | 'runsAt' | 'status'
349
- // > & {
350
- // data: factory.task.triggerWebhook.IInformAnyResourceAction & {
351
- // object: factory.notification.person.IPersonAsNotification;
352
- // };
353
- // },
354
- // options: IOptionOnCreate
355
- // ): Promise<void> {
356
- // const createdTask = await this.taskModel.findOneAndUpdate(
357
- // {
358
- // 'project.id': { $eq: params.project.id },
359
- // name: params.name,
360
- // 'data.object.id': {
361
- // $exists: true,
362
- // $eq: String(params.data.object.id)
363
- // }
364
- // },
365
- // { $setOnInsert: params },
366
- // { new: true, upsert: true }
367
- // )
368
- // .select({ _id: 1 })
369
- // .exec();
370
- // if (options.emitImmediately) {
371
- // taskEventEmitter.emitTaskStatusChanged({
372
- // id: createdTask.id,
373
- // name: params.name,
374
- // status: factory.taskStatus.Ready
375
- // });
376
- // }
377
- // }
378
302
  /**
379
303
  * 取引削除タスク冪等作成
380
304
  */
@@ -401,36 +325,6 @@ class TaskRepo {
401
325
  }
402
326
  });
403
327
  }
404
- // public async createConfirmReserveTransactionTaskIfNotExist(
405
- // params: factory.task.IAttributes<factory.taskName.ConfirmReserveTransaction>,
406
- // options: IOptionOnCreate
407
- // ): Promise<void> {
408
- // const createdTask = await this.taskModel.findOneAndUpdate(
409
- // {
410
- // 'project.id': { $eq: params.project.id },
411
- // name: { $eq: params.name },
412
- // 'data.object.transactionNumber': {
413
- // $exists: true,
414
- // $eq: String(params.data.object.transactionNumber)
415
- // },
416
- // 'data.purpose.orderNumber': {
417
- // $exists: true,
418
- // $eq: String(params.data.purpose.orderNumber)
419
- // }
420
- // },
421
- // { $setOnInsert: params },
422
- // { new: true, upsert: true }
423
- // )
424
- // .select({ _id: 1 })
425
- // .exec();
426
- // if (options.emitImmediately) {
427
- // taskEventEmitter.emitTaskStatusChanged({
428
- // id: createdTask.id,
429
- // name: params.name,
430
- // status: factory.taskStatus.Ready
431
- // });
432
- // }
433
- // }
434
328
  createOnAssetTransactionStatusChangedTaskIfNotExist(
435
329
  // resolve uniqueness of identifier(2025-03-27~)
436
330
  params, options) {
@@ -458,6 +352,10 @@ class TaskRepo {
458
352
  }
459
353
  });
460
354
  }
355
+ /**
356
+ * Ready -> remainingNumberOfTriesが1減る
357
+ * Running -> findOneするだけ
358
+ */
461
359
  executeOneById(params) {
462
360
  return __awaiter(this, void 0, void 0, function* () {
463
361
  const now = new Date();
@@ -492,7 +390,7 @@ class TaskRepo {
492
390
  });
493
391
  }
494
392
  /**
495
- * support no name(2025-03-04~)
393
+ * Readyのタスクをname指定でひとつRunningに変更する
496
394
  */
497
395
  executeOneIfExists(params) {
498
396
  return __awaiter(this, void 0, void 0, function* () {
@@ -552,7 +450,11 @@ class TaskRepo {
552
450
  return { count };
553
451
  });
554
452
  }
555
- emitRunningIfExists(params) {
453
+ /**
454
+ * 実行日時を一定期間過ぎたReadyタスクについて、Runningスタータスに変更した上で、Runningイベントを発生させる
455
+ */
456
+ emitRunningIfExists(params, next // support next function(2025-08-02~)
457
+ ) {
556
458
  return __awaiter(this, void 0, void 0, function* () {
557
459
  var _a, _b;
558
460
  if (!(params.runsAt.$lt instanceof Date)) {
@@ -591,40 +493,55 @@ class TaskRepo {
591
493
  task_1.taskEventEmitter.emitTaskStatusChanged({
592
494
  id: doc.id,
593
495
  status: factory.taskStatus.Running
594
- });
595
- return doc;
596
- });
597
- }
598
- findExecutableOne(params) {
599
- return __awaiter(this, void 0, void 0, function* () {
600
- var _a, _b;
601
- if (!(params.runsAt.$lt instanceof Date)) {
602
- throw new factory.errors.Argument('runsAt.$lt', 'must be Date');
603
- }
604
- const nameEq = (_a = params.name) === null || _a === void 0 ? void 0 : _a.$eq;
605
- const nameNin = (_b = params.name) === null || _b === void 0 ? void 0 : _b.$nin;
606
- const query = this.taskModel.findOne(Object.assign({ status: { $eq: factory.taskStatus.Ready }, runsAt: { $lt: params.runsAt.$lt } }, (typeof nameEq === 'string' || Array.isArray(nameNin))
607
- ? {
608
- name: Object.assign(Object.assign({}, (typeof nameEq === 'string') ? { $eq: nameEq } : undefined), (Array.isArray(nameNin)) ? { $nin: nameNin } : undefined)
609
- }
610
- : undefined), executableTaskProjection)
611
- .sort({
612
- runsAt: factory.sortType.Ascending
613
- });
614
- // .hint('executeOneByName');
615
- // const explainResult = await query.explain();
616
- // console.dir(explainResult, { depth: null });
617
- // console.log(explainResult[0].executionStats.allPlansExecution.map((e: any) => e.executionStages.inputStage));
618
- const doc = yield query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
619
- .lean()
620
- .exec();
621
- if (doc === null) {
622
- // tslint:disable-next-line:no-null-keyword
623
- return null;
624
- }
496
+ }, (typeof next === 'function') ? next : undefined);
625
497
  return doc;
626
498
  });
627
499
  }
500
+ // public async findExecutableOne(params: {
501
+ // name?: {
502
+ // $eq?: factory.taskName;
503
+ // $nin?: factory.taskName[];
504
+ // };
505
+ // runsAt: {
506
+ // $lt: Date;
507
+ // };
508
+ // }): Promise<IExecutableTask<factory.taskName> | null> {
509
+ // if (!(params.runsAt.$lt instanceof Date)) {
510
+ // throw new factory.errors.Argument('runsAt.$lt', 'must be Date');
511
+ // }
512
+ // const nameEq = params.name?.$eq;
513
+ // const nameNin = params.name?.$nin;
514
+ // const query = this.taskModel.findOne(
515
+ // {
516
+ // status: { $eq: factory.taskStatus.Ready },
517
+ // runsAt: { $lt: params.runsAt.$lt },
518
+ // ...(typeof nameEq === 'string' || Array.isArray(nameNin))
519
+ // ? {
520
+ // name: {
521
+ // ...(typeof nameEq === 'string') ? { $eq: nameEq } : undefined,
522
+ // ...(Array.isArray(nameNin)) ? { $nin: nameNin } : undefined
523
+ // }
524
+ // }
525
+ // : undefined
526
+ // },
527
+ // executableTaskProjection
528
+ // )
529
+ // .sort({
530
+ // runsAt: factory.sortType.Ascending
531
+ // });
532
+ // // .hint('executeOneByName');
533
+ // // const explainResult = await query.explain();
534
+ // // console.dir(explainResult, { depth: null });
535
+ // // console.log(explainResult[0].executionStats.allPlansExecution.map((e: any) => e.executionStages.inputStage));
536
+ // const doc = await query.setOptions({ maxTimeMS: MONGO_MAX_TIME_MS })
537
+ // .lean<IExecutableTask<factory.taskName>>()
538
+ // .exec();
539
+ // if (doc === null) {
540
+ // // tslint:disable-next-line:no-null-keyword
541
+ // return null;
542
+ // }
543
+ // return doc;
544
+ // }
628
545
  // discontinue(2025-05-26~)
629
546
  /**
630
547
  * emit OnTaskStatusChanged on delayed tasks
@@ -682,7 +599,7 @@ class TaskRepo {
682
599
  // return delayedTasks;
683
600
  // }
684
601
  /**
685
- * make tasks expired
602
+ * Readyのままで期限切れのタスクをExpiredに変更する
686
603
  */
687
604
  makeExpiredMany(params) {
688
605
  return __awaiter(this, void 0, void 0, function* () {
@@ -702,20 +619,24 @@ class TaskRepo {
702
619
  });
703
620
  }
704
621
  /**
705
- * 実行中ステータスのままになっているタスクをリトライする
622
+ * Runningのまま一定期間超過し、かつ、remainingNumberOfTries>0のタスクをReadyに変更する
706
623
  */
707
- retry(params) {
624
+ retryMany(params) {
708
625
  return __awaiter(this, void 0, void 0, function* () {
709
626
  const lastTriedAtShoudBeLessThan = moment()
710
627
  .add(-params.intervalInMinutes, 'minutes')
711
628
  .toDate();
712
- return this.taskModel.updateMany({
629
+ const remainingNumberOfTriesGt = params.remainingNumberOfTries.$gt;
630
+ return this.taskModel.updateMany(
631
+ // name: 'retry'のindexと連動しているので、条件の順序などには注意すること
632
+ // @see schemas/task
633
+ {
713
634
  status: { $eq: factory.taskStatus.Running },
714
635
  lastTriedAt: {
715
636
  $type: 'date',
716
637
  $lt: lastTriedAtShoudBeLessThan
717
638
  },
718
- remainingNumberOfTries: { $gt: 0 }
639
+ remainingNumberOfTries: { $gt: remainingNumberOfTriesGt }
719
640
  }, {
720
641
  $set: {
721
642
  status: factory.taskStatus.Ready // 実行前に変更
@@ -744,34 +665,42 @@ class TaskRepo {
744
665
  .exec();
745
666
  });
746
667
  }
747
- abortOne(params) {
748
- return __awaiter(this, void 0, void 0, function* () {
749
- const lastTriedAtShoudBeLessThan = moment()
750
- .add(-params.intervalInMinutes, 'minutes')
751
- .toDate();
752
- const projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(AVAILABLE_PROJECT_FIELDS.map((key) => ([key, 1]))));
753
- const doc = yield this.taskModel.findOneAndUpdate({
754
- status: { $eq: factory.taskStatus.Running },
755
- lastTriedAt: {
756
- $type: 'date',
757
- $lt: lastTriedAtShoudBeLessThan
758
- },
759
- remainingNumberOfTries: { $eq: 0 }
760
- }, {
761
- $set: {
762
- status: factory.taskStatus.Aborted,
763
- dateAborted: new Date()
764
- }
765
- }, { new: true, projection })
766
- .lean() // lean(2024-09-26~)
767
- .exec();
768
- if (doc === null) {
769
- // tslint:disable-next-line:no-null-keyword
770
- return null;
771
- }
772
- return doc;
773
- });
774
- }
668
+ // public async abortOne(params: {
669
+ // intervalInMinutes: number;
670
+ // }): Promise<factory.task.ITask<factory.taskName> | null> {
671
+ // const lastTriedAtShoudBeLessThan = moment()
672
+ // .add(-params.intervalInMinutes, 'minutes')
673
+ // .toDate();
674
+ // const projection: ProjectionType<factory.task.ITask<factory.taskName>> = {
675
+ // _id: 0,
676
+ // id: { $toString: '$_id' },
677
+ // ...Object.fromEntries<1>(AVAILABLE_PROJECT_FIELDS.map((key) => ([key, 1])))
678
+ // };
679
+ // const doc = await this.taskModel.findOneAndUpdate(
680
+ // {
681
+ // status: { $eq: factory.taskStatus.Running },
682
+ // lastTriedAt: {
683
+ // $type: 'date',
684
+ // $lt: lastTriedAtShoudBeLessThan
685
+ // },
686
+ // remainingNumberOfTries: { $eq: 0 }
687
+ // },
688
+ // {
689
+ // $set: {
690
+ // status: factory.taskStatus.Aborted,
691
+ // dateAborted: new Date()
692
+ // }
693
+ // },
694
+ // { new: true, projection }
695
+ // )
696
+ // .lean<factory.task.ITask<factory.taskName>>() // lean(2024-09-26~)
697
+ // .exec();
698
+ // if (doc === null) {
699
+ // // tslint:disable-next-line:no-null-keyword
700
+ // return null;
701
+ // }
702
+ // return doc;
703
+ // }
775
704
  abortMany(params) {
776
705
  return __awaiter(this, void 0, void 0, function* () {
777
706
  const lastTriedAtShoudBeLessThan = moment()
@@ -794,48 +723,28 @@ class TaskRepo {
794
723
  });
795
724
  }
796
725
  /**
797
- * 実行結果を保管する
726
+ * タスクIDから実行結果とステータスを保管する
727
+ * Abortedの場合、dateAbortedもセットする
798
728
  */
799
- pushExecutionResultById(params, executionResult,
729
+ setExecutionResultAndStatus(params, update,
800
730
  // support customr function(2025-05-25~)
801
731
  next) {
802
732
  return __awaiter(this, void 0, void 0, function* () {
803
- const { id, status } = params;
733
+ const { id, remainingNumberOfTries, name } = params;
734
+ const { status, executionResult } = update;
804
735
  yield this.taskModel.updateOne({ _id: { $eq: id } }, {
805
- $set: { status },
736
+ $set: Object.assign({ status }, (status === factory.taskStatus.Aborted) ? { dateAborted: executionResult.endDate } : undefined // 2025-08-04~
737
+ ),
806
738
  $push: { executionResults: executionResult }
807
739
  })
808
740
  .exec();
809
741
  // emit event(2025-05-26~)
810
742
  if (typeof next === 'function') {
811
- task_1.taskEventEmitter.emitTaskStatusChanged({ id, status, executionResult }, next);
743
+ const changedTask = { id, name, status, remainingNumberOfTries, executionResult };
744
+ task_1.taskEventEmitter.emitTaskStatusChanged(changedTask, next);
812
745
  }
813
746
  });
814
747
  }
815
- /**
816
- * 特定タスク検索
817
- */
818
- // public async findById<T extends factory.taskName>(params: {
819
- // name: T;
820
- // id: string;
821
- // }): Promise<factory.task.ITask<T>> {
822
- // const doc = await this.taskModel.findOne(
823
- // {
824
- // name: { $eq: params.name },
825
- // _id: { $eq: params.id }
826
- // },
827
- // {
828
- // __v: 0,
829
- // createdAt: 0,
830
- // updatedAt: 0
831
- // }
832
- // )
833
- // .exec();
834
- // if (doc === null) {
835
- // throw new factory.errors.NotFound('Task');
836
- // }
837
- // return doc.toObject();
838
- // }
839
748
  count(params) {
840
749
  return __awaiter(this, void 0, void 0, function* () {
841
750
  const { limit } = params;
@@ -1,6 +1,4 @@
1
1
  import type { Connection } from 'mongoose';
2
- import { RedisClientType } from 'redis';
3
- import { ISetting } from './mongoose/schemas/setting';
4
2
  interface IPublishResult {
5
3
  transactionNumber: string;
6
4
  }
@@ -8,10 +6,8 @@ interface IPublishResult {
8
6
  * 取引番号リポジトリ
9
7
  */
10
8
  export declare class TransactionNumberRepo {
11
- private readonly settingModel;
12
9
  private readonly counterRepo;
13
10
  constructor(params: {
14
- redisClient: RedisClientType;
15
11
  connection: Connection;
16
12
  });
17
13
  /**
@@ -20,12 +16,5 @@ export declare class TransactionNumberRepo {
20
16
  publishByTimestamp(params: {
21
17
  startDate: Date;
22
18
  }): Promise<IPublishResult>;
23
- /**
24
- * DB移行時のみに使用目的の設定更新
25
- */
26
- setUseMongo4transactionNumberFrom(params: {
27
- useMongo4transactionNumberFrom: Date;
28
- }): Promise<Pick<ISetting, "useMongo4transactionNumberFrom"> | null>;
29
- private useMongoBySettings;
30
19
  }
31
20
  export {};
@@ -12,9 +12,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.TransactionNumberRepo = void 0;
13
13
  const cdigit = require("cdigit");
14
14
  const moment = require("moment-timezone");
15
+ // import { RedisClientType } from 'redis';
15
16
  // tslint:disable-next-line:no-require-imports no-var-requires
16
17
  const fpe = require('node-fpe');
17
- const setting_1 = require("./mongoose/schemas/setting");
18
+ // import { createSchema as createSettingSchema, modelName as settingModelName } from './mongoose/schemas/setting';
18
19
  const transactionNumber_1 = require("./mongoose/schemas/transactionNumber");
19
20
  const transactionNumberCounter_1 = require("./transactionNumberCounter");
20
21
  /**
@@ -22,8 +23,8 @@ const transactionNumberCounter_1 = require("./transactionNumberCounter");
22
23
  */
23
24
  class TransactionNumberRepo {
24
25
  constructor(params) {
25
- const { connection } = params;
26
- this.settingModel = connection.model(setting_1.modelName, (0, setting_1.createSchema)());
26
+ // const { connection } = params;
27
+ // this.settingModel = connection.model(settingModelName, createSettingSchema());
27
28
  this.counterRepo = new transactionNumberCounter_1.TransactionNumberCounterRepo(params);
28
29
  }
29
30
  // private static createKey(params: {
@@ -47,27 +48,15 @@ class TransactionNumberRepo {
47
48
  let dataFeedExpires;
48
49
  const dataFeedIdentifier = timestamp;
49
50
  let incrReply;
50
- const useMongoBySettings = yield this.useMongoBySettings(params);
51
- if (useMongoBySettings) {
52
- dataFeedExpires = moment(params.startDate)
53
- .add(1, 'minute') // ミリ秒でカウントしていくので、予約日時後1分で十分
54
- .toDate();
55
- incrReply = yield this.counterRepo.incrementByMongo({
56
- identifier: dataFeedIdentifier,
57
- includedInDataCatalog: { identifier: transactionNumber_1.DataCatalogIdentifier.transactionNumber },
58
- expires: dataFeedExpires
59
- });
60
- }
61
- else {
62
- dataFeedExpires = moment(params.startDate)
63
- .add(1, 'minute') // ミリ秒でカウントしていくので、予約日時後1分で十分
64
- .toDate();
65
- incrReply = yield this.counterRepo.incrementByRedis({
66
- identifier: dataFeedIdentifier,
67
- includedInDataCatalog: { identifier: transactionNumber_1.DataCatalogIdentifier.transactionNumber },
68
- expires: dataFeedExpires
69
- });
70
- }
51
+ // const useMongoBySettings = await this.useMongoBySettings(params);
52
+ dataFeedExpires = moment(params.startDate)
53
+ .add(1, 'minute') // ミリ秒でカウントしていくので、予約日時後1分で十分
54
+ .toDate();
55
+ incrReply = yield this.counterRepo.incrementByMongo({
56
+ identifier: dataFeedIdentifier,
57
+ includedInDataCatalog: { identifier: transactionNumber_1.DataCatalogIdentifier.transactionNumber },
58
+ expires: dataFeedExpires
59
+ });
71
60
  let transactionNumber = `${timestamp}${incrReply}`;
72
61
  // checkdigit
73
62
  const cd = cdigit.luhn.compute(transactionNumber);
@@ -77,32 +66,5 @@ class TransactionNumberRepo {
77
66
  return { transactionNumber };
78
67
  });
79
68
  }
80
- /**
81
- * DB移行時のみに使用目的の設定更新
82
- */
83
- setUseMongo4transactionNumberFrom(params) {
84
- return __awaiter(this, void 0, void 0, function* () {
85
- const { useMongo4transactionNumberFrom } = params;
86
- return this.settingModel.findOneAndUpdate({ 'project.id': { $eq: '*' } }, {
87
- $set: { useMongo4transactionNumberFrom }
88
- }, { projection: { _id: 0, useMongo4transactionNumberFrom: 1 } })
89
- .lean()
90
- .exec();
91
- });
92
- }
93
- useMongoBySettings(params) {
94
- return __awaiter(this, void 0, void 0, function* () {
95
- const setting = yield this.settingModel.findOne({ 'project.id': { $eq: '*' } }, {
96
- _id: 0,
97
- useMongo4transactionNumberFrom: 1
98
- })
99
- .lean()
100
- .exec();
101
- const useMongo4transactionNumberFrom = setting === null || setting === void 0 ? void 0 : setting.useMongo4transactionNumberFrom;
102
- return useMongo4transactionNumberFrom instanceof Date
103
- && moment(params.startDate)
104
- .isSameOrAfter(moment(useMongo4transactionNumberFrom));
105
- });
106
- }
107
69
  }
108
70
  exports.TransactionNumberRepo = TransactionNumberRepo;
@@ -1,23 +1,13 @@
1
1
  import type { Connection } from 'mongoose';
2
- import { RedisClientType } from 'redis';
3
2
  import { DataCatalogIdentifier } from './mongoose/schemas/transactionNumber';
4
3
  /**
5
4
  * 取引番号カウンターリポジトリ
6
5
  */
7
6
  export declare class TransactionNumberCounterRepo {
8
- private readonly redisClient;
9
7
  private readonly transactionNumberModel;
10
8
  constructor(params: {
11
- redisClient: RedisClientType;
12
9
  connection: Connection;
13
10
  });
14
- incrementByRedis(params: {
15
- identifier: string;
16
- includedInDataCatalog: {
17
- identifier: DataCatalogIdentifier;
18
- };
19
- expires: Date;
20
- }): Promise<number>;
21
11
  incrementByMongo(params: {
22
12
  identifier: string;
23
13
  includedInDataCatalog: {
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.TransactionNumberCounterRepo = void 0;
13
+ // import { RedisClientType } from 'redis';
13
14
  const errorHandler_1 = require("../errorHandler");
14
15
  const factory = require("../factory");
15
16
  const transactionNumber_1 = require("./mongoose/schemas/transactionNumber");
@@ -19,37 +20,41 @@ const MAX_RETRY_INCREMENT = 1;
19
20
  */
20
21
  class TransactionNumberCounterRepo {
21
22
  constructor(params) {
22
- const { redisClient, connection } = params;
23
- this.redisClient = redisClient;
23
+ const { connection } = params;
24
+ // this.redisClient = redisClient;
24
25
  this.transactionNumberModel = connection.model(transactionNumber_1.modelName, (0, transactionNumber_1.createSchema)());
25
26
  }
26
- incrementByRedis(params) {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- // const now = moment();
29
- const { expires } = params;
30
- const key = `${params.includedInDataCatalog.identifier}:${params.identifier}`;
31
- // const TTL = moment(expires)
32
- // .diff(now, 'seconds');
33
- const [incrReply, expireAtReply] = yield this.redisClient.multi()
34
- .incr(key)
35
- // .expire(key, TTL)
36
- .expireAt(key, expires)
37
- .exec();
38
- // tslint:disable-next-line:no-single-line-block-comment
39
- /* istanbul ignore else: please write tests */
40
- if (typeof incrReply !== 'number') {
41
- // 基本的にありえないフロー
42
- throw new factory.errors.Internal('transaction number not incremented unexpectedly');
43
- }
44
- // expireAtReplyの検証も追加する(2023-04-19~)
45
- const expiredSet = expireAtReply === 1 || expireAtReply === true;
46
- if (!expiredSet) {
47
- // 基本的にありえないフロー
48
- throw new factory.errors.Internal('transaction number expiration not set unexpectedly');
49
- }
50
- return incrReply;
51
- });
52
- }
27
+ // public async incrementByRedis(params: {
28
+ // identifier: string;
29
+ // includedInDataCatalog: {
30
+ // identifier: DataCatalogIdentifier;
31
+ // };
32
+ // expires: Date;
33
+ // }): Promise<number> {
34
+ // // const now = moment();
35
+ // const { expires } = params;
36
+ // const key = `${params.includedInDataCatalog.identifier}:${params.identifier}`;
37
+ // // const TTL = moment(expires)
38
+ // // .diff(now, 'seconds');
39
+ // const [incrReply, expireAtReply] = await this.redisClient.multi()
40
+ // .incr(key)
41
+ // // .expire(key, TTL)
42
+ // .expireAt(key, expires)
43
+ // .exec();
44
+ // // tslint:disable-next-line:no-single-line-block-comment
45
+ // /* istanbul ignore else: please write tests */
46
+ // if (typeof incrReply !== 'number') {
47
+ // // 基本的にありえないフロー
48
+ // throw new factory.errors.Internal('transaction number not incremented unexpectedly');
49
+ // }
50
+ // // expireAtReplyの検証も追加する(2023-04-19~)
51
+ // const expiredSet = expireAtReply === 1 || <any>expireAtReply === true;
52
+ // if (!expiredSet) {
53
+ // // 基本的にありえないフロー
54
+ // throw new factory.errors.Internal('transaction number expiration not set unexpectedly');
55
+ // }
56
+ // return incrReply;
57
+ // }
53
58
  incrementByMongo(params) {
54
59
  return __awaiter(this, void 0, void 0, function* () {
55
60
  var _a;
@@ -18,7 +18,7 @@ export declare function validateStartParams(params: IStartParams): (repos: {
18
18
  assetTransaction: AssetTransactionRepo;
19
19
  }) => Promise<{
20
20
  reserveTransaction: import("@chevre/factory/lib/assetTransaction/reserve").ITransaction | undefined;
21
- reservations: (Pick<import("@chevre/factory/lib/reservation/event").IReservation, "id" | "typeOf" | "reservationNumber" | "issuedThrough"> & {
21
+ reservations: (Pick<import("@chevre/factory/lib/reservation/event").IReservation, "id" | "typeOf" | "issuedThrough" | "reservationNumber"> & {
22
22
  reservationFor: Pick<factory.reservation.IReservationFor<factory.reservationType.EventReservation>, "id" | "typeOf">;
23
23
  })[] | undefined;
24
24
  }>;