@chevre/domain 26.0.0-alpha.3 → 26.0.0-alpha.31

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 (189) hide show
  1. package/lib/chevre/eventEmitter/task.d.ts +8 -23
  2. package/lib/chevre/eventEmitter/task.js +2 -2
  3. package/lib/chevre/repo/acceptedOffer.d.ts +0 -7
  4. package/lib/chevre/repo/acceptedOffer.js +27 -27
  5. package/lib/chevre/repo/action/actionProcess.d.ts +1 -1
  6. package/lib/chevre/repo/action/inform.d.ts +38 -0
  7. package/lib/chevre/repo/action/inform.js +159 -0
  8. package/lib/chevre/repo/action/update.d.ts +56 -0
  9. package/lib/chevre/repo/action/update.js +173 -0
  10. package/lib/chevre/repo/action.d.ts +3 -19
  11. package/lib/chevre/repo/action.js +0 -298
  12. package/lib/chevre/repo/adminAssetTransaction.d.ts +126 -0
  13. package/lib/chevre/repo/adminAssetTransaction.js +491 -0
  14. package/lib/chevre/repo/adminAsyncAction.d.ts +2 -2
  15. package/lib/chevre/repo/adminScheduledTask.d.ts +1 -1
  16. package/lib/chevre/repo/adminTask.d.ts +25 -8
  17. package/lib/chevre/repo/adminTask.js +31 -32
  18. package/lib/chevre/repo/adminTransaction.d.ts +131 -0
  19. package/lib/chevre/repo/adminTransaction.js +237 -0
  20. package/lib/chevre/repo/aggregateAssetTransaction.d.ts +43 -0
  21. package/lib/chevre/repo/aggregateAssetTransaction.js +166 -0
  22. package/lib/chevre/repo/aggregateScheduledTask.d.ts +32 -0
  23. package/lib/chevre/repo/aggregateScheduledTask.js +136 -0
  24. package/lib/chevre/repo/aggregateTransaction.d.ts +39 -0
  25. package/lib/chevre/repo/aggregateTransaction.js +166 -0
  26. package/lib/chevre/repo/aggregation.d.ts +0 -8
  27. package/lib/chevre/repo/aggregation.js +0 -10
  28. package/lib/chevre/repo/assetTransaction.d.ts +10 -235
  29. package/lib/chevre/repo/assetTransaction.js +48 -636
  30. package/lib/chevre/repo/asyncAction.d.ts +2 -2
  31. package/lib/chevre/repo/authorization.d.ts +0 -6
  32. package/lib/chevre/repo/authorization.js +15 -27
  33. package/lib/chevre/repo/message.d.ts +0 -7
  34. package/lib/chevre/repo/message.js +0 -38
  35. package/lib/chevre/repo/mongoose/schemas/{ownershipInfo.d.ts → action/inform.d.ts} +5 -5
  36. package/lib/chevre/repo/mongoose/schemas/action/inform.js +81 -0
  37. package/lib/chevre/repo/mongoose/schemas/action/update.d.ts +12 -0
  38. package/lib/chevre/repo/mongoose/schemas/action/update.js +107 -0
  39. package/lib/chevre/repo/mongoose/schemas/action.d.ts +1 -1
  40. package/lib/chevre/repo/mongoose/schemas/action.js +8 -1
  41. package/lib/chevre/repo/mongoose/schemas/actionRecipe.js +7 -0
  42. package/lib/chevre/repo/mongoose/schemas/aggregateReservation.js +8 -9
  43. package/lib/chevre/repo/mongoose/schemas/aggregation.js +8 -1
  44. package/lib/chevre/repo/mongoose/schemas/assetTransaction.js +95 -76
  45. package/lib/chevre/repo/mongoose/schemas/authorization.js +25 -18
  46. package/lib/chevre/repo/mongoose/schemas/event.js +7 -0
  47. package/lib/chevre/repo/mongoose/schemas/eventOffer.js +7 -0
  48. package/lib/chevre/repo/mongoose/schemas/message.js +8 -1
  49. package/lib/chevre/repo/mongoose/schemas/pendingReservation.js +11 -4
  50. package/lib/chevre/repo/mongoose/schemas/setting.d.ts +1 -0
  51. package/lib/chevre/repo/mongoose/schemas/task.d.ts +2 -5
  52. package/lib/chevre/repo/mongoose/schemas/task.js +134 -118
  53. package/lib/chevre/repo/mongoose/schemas/ticket.js +8 -1
  54. package/lib/chevre/repo/orderInTransaction.d.ts +0 -3
  55. package/lib/chevre/repo/orderInTransaction.js +30 -22
  56. package/lib/chevre/repo/scheduledTask.d.ts +5 -2
  57. package/lib/chevre/repo/scheduledTask.js +3 -25
  58. package/lib/chevre/repo/task.d.ts +45 -171
  59. package/lib/chevre/repo/task.js +20 -475
  60. package/lib/chevre/repo/taskDelayed.d.ts +74 -0
  61. package/lib/chevre/repo/taskDelayed.js +195 -0
  62. package/lib/chevre/repo/taskRunning.d.ts +35 -0
  63. package/lib/chevre/repo/taskRunning.js +89 -0
  64. package/lib/chevre/repo/ticket.d.ts +0 -6
  65. package/lib/chevre/repo/ticket.js +0 -11
  66. package/lib/chevre/repo/transaction.d.ts +1 -187
  67. package/lib/chevre/repo/transaction.js +2 -383
  68. package/lib/chevre/repository.d.ts +40 -5
  69. package/lib/chevre/repository.js +90 -13
  70. package/lib/chevre/service/aggregation/system.d.ts +17 -9
  71. package/lib/chevre/service/aggregation/system.js +46 -4
  72. package/lib/chevre/service/assetTransaction/cancelReservation/start.js +10 -17
  73. package/lib/chevre/service/assetTransaction/refund.js +2 -2
  74. package/lib/chevre/service/asyncAction.d.ts +2 -2
  75. package/lib/chevre/service/asyncAction.js +1 -4
  76. package/lib/chevre/service/asyncActionHandler/onOperationFailed.d.ts +2 -2
  77. package/lib/chevre/service/asyncActionHandler/onOperationFailed.js +0 -2
  78. package/lib/chevre/service/asyncActionHandler.d.ts +4 -4
  79. package/lib/chevre/service/asyncActionHandler.js +11 -13
  80. package/lib/chevre/service/event/processUpdateMovieTheater.d.ts +4 -2
  81. package/lib/chevre/service/event/processUpdateMovieTheater.js +3 -3
  82. package/lib/chevre/service/event.d.ts +4 -2
  83. package/lib/chevre/service/event.js +3 -3
  84. package/lib/chevre/service/notification/triggerWebhook.d.ts +4 -2
  85. package/lib/chevre/service/notification/triggerWebhook.js +5 -16
  86. package/lib/chevre/service/offer/event/voidTransaction/processVoidTransaction4chevre.js +1 -3
  87. package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.d.ts +0 -4
  88. package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.js +19 -19
  89. package/lib/chevre/service/offer/onEventChanged.js +0 -2
  90. package/lib/chevre/service/order/confirmPayTransaction.js +4 -1
  91. package/lib/chevre/service/order/deleteOrder.js +0 -1
  92. package/lib/chevre/service/order/onAssetTransactionStatusChanged/isDeliverable.js +1 -49
  93. package/lib/chevre/service/order/onAssetTransactionStatusChanged/onPayTransactionConfirmed.js +2 -2
  94. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered/factory.js +2 -4
  95. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially/factory.js +2 -4
  96. package/lib/chevre/service/order/onOrderStatusChanged/onOrderInTransit.js +4 -4
  97. package/lib/chevre/service/order/onOrderStatusChanged/onOrderPaymentDue.js +2 -2
  98. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.js +2 -2
  99. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.d.ts +2 -2
  100. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.js +3 -5
  101. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/processOrder.js +2 -2
  102. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +1 -1
  103. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.js +5 -7
  104. package/lib/chevre/service/order/onOrderUpdated/factory.js +0 -3
  105. package/lib/chevre/service/order/returnOrder.d.ts +0 -2
  106. package/lib/chevre/service/order/returnOrder.js +8 -40
  107. package/lib/chevre/service/order/sendOrder.d.ts +0 -2
  108. package/lib/chevre/service/order/sendOrder.js +41 -55
  109. package/lib/chevre/service/payment/any/findAcceptAction.d.ts +0 -4
  110. package/lib/chevre/service/payment/any/findAcceptAction.js +19 -19
  111. package/lib/chevre/service/payment/any/findAuthorizeAction.d.ts +0 -4
  112. package/lib/chevre/service/payment/any/findAuthorizeAction.js +19 -19
  113. package/lib/chevre/service/payment/any/findCheckAction.d.ts +0 -4
  114. package/lib/chevre/service/payment/any/findCheckAction.js +19 -19
  115. package/lib/chevre/service/payment/any/processVoidPayTransaction.js +1 -1
  116. package/lib/chevre/service/payment/any/publishPaymentUrl.d.ts +0 -2
  117. package/lib/chevre/service/payment/any/publishPaymentUrl.js +2 -2
  118. package/lib/chevre/service/project.d.ts +0 -3
  119. package/lib/chevre/service/project.js +0 -1
  120. package/lib/chevre/service/reserve/cancelReservation.js +3 -3
  121. package/lib/chevre/service/reserve/checkInReservation.js +2 -2
  122. package/lib/chevre/service/reserve/confirmReservation.js +1 -1
  123. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +2 -2
  124. package/lib/chevre/service/reserve/useReservation.js +1 -1
  125. package/lib/chevre/service/scheduledTask.d.ts +1 -4
  126. package/lib/chevre/service/scheduledTask.js +3 -10
  127. package/lib/chevre/service/scheduledTaskHandler/onOperationFailed.js +1 -2
  128. package/lib/chevre/service/scheduledTaskHandler.js +0 -13
  129. package/lib/chevre/service/task/acceptCOAOffer.js +1 -14
  130. package/lib/chevre/service/task/authorizePayment.js +1 -7
  131. package/lib/chevre/service/task/checkMovieTicket.js +1 -7
  132. package/lib/chevre/service/task/confirmReserveTransaction.js +3 -1
  133. package/lib/chevre/service/task/deleteTransaction.js +8 -39
  134. package/lib/chevre/service/task/importEventsFromCOA.js +4 -2
  135. package/lib/chevre/service/task/onAuthorizationCreated.js +2 -2
  136. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByAggregateOffer.d.ts +4 -2
  137. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByAggregateOffer.js +4 -4
  138. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByEventSeries.d.ts +4 -2
  139. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByEventSeries.js +4 -4
  140. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByMovieTheater.d.ts +4 -2
  141. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByMovieTheater.js +4 -4
  142. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByOfferCatalog.d.ts +4 -2
  143. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByOfferCatalog.js +4 -4
  144. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByProduct.d.ts +4 -2
  145. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByProduct.js +4 -4
  146. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByRoom.d.ts +4 -2
  147. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByRoom.js +4 -4
  148. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesBySeller.d.ts +4 -2
  149. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesBySeller.js +4 -4
  150. package/lib/chevre/service/task/onResourceDeleted.js +4 -3
  151. package/lib/chevre/service/task/onResourceUpdated/onAggregateOfferUpdated.js +0 -1
  152. package/lib/chevre/service/task/onResourceUpdated/onHasPOSUpdated.js +0 -1
  153. package/lib/chevre/service/task/onResourceUpdated/onOfferCatalogUpdated.js +0 -1
  154. package/lib/chevre/service/task/onResourceUpdated.js +0 -8
  155. package/lib/chevre/service/task/publishPaymentUrl.js +2 -13
  156. package/lib/chevre/service/task/returnOrder.js +2 -5
  157. package/lib/chevre/service/task/returnPayTransaction.js +2 -2
  158. package/lib/chevre/service/task/sendOrder.js +2 -2
  159. package/lib/chevre/service/task/syncResourcesFromCOA.js +31 -23
  160. package/lib/chevre/service/task/triggerWebhook.js +4 -2
  161. package/lib/chevre/service/task/voidReserveTransaction.js +5 -8
  162. package/lib/chevre/service/task.d.ts +3 -22
  163. package/lib/chevre/service/task.js +8 -40
  164. package/lib/chevre/service/taskHandler/onOperationFailed/informTaskIfNeeded.js +0 -1
  165. package/lib/chevre/service/taskHandler/onOperationFailed.d.ts +3 -2
  166. package/lib/chevre/service/taskHandler/onOperationFailed.js +5 -16
  167. package/lib/chevre/service/taskHandler.d.ts +1 -2
  168. package/lib/chevre/service/taskHandler.js +7 -19
  169. package/lib/chevre/service/transaction/deleteTransaction/deletePayTransactionsByPlaceOrder.js +2 -2
  170. package/lib/chevre/service/transaction/deleteTransaction/deleteReservationsByPlaceOrder.js +2 -2
  171. package/lib/chevre/service/transaction/deleteTransaction.d.ts +6 -2
  172. package/lib/chevre/service/transaction/deleteTransaction.js +5 -5
  173. package/lib/chevre/service/transaction/placeOrder/confirm.js +1 -1
  174. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.d.ts +8 -4
  175. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +55 -103
  176. package/lib/chevre/service/transaction/placeOrder/exportTasksById.d.ts +2 -0
  177. package/lib/chevre/service/transaction/placeOrder/exportTasksById.js +14 -10
  178. package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.d.ts +13 -3
  179. package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.js +48 -51
  180. package/lib/chevre/service/transaction/returnOrder.d.ts +2 -0
  181. package/lib/chevre/service/transaction/returnOrder.js +15 -13
  182. package/lib/chevre/service/transaction.d.ts +2 -0
  183. package/lib/chevre/service/transaction.js +0 -2
  184. package/lib/chevre/service/validation/validateOrder.js +2 -2
  185. package/lib/chevre/taskSettings.d.ts +4 -4
  186. package/package.json +2 -2
  187. package/lib/chevre/repo/mongoose/schemas/ownershipInfo.js +0 -227
  188. package/lib/chevre/repo/ownershipInfo.d.ts +0 -122
  189. package/lib/chevre/repo/ownershipInfo.js +0 -466
@@ -16,9 +16,6 @@ interface IReadyTask {
16
16
  id: string;
17
17
  name?: factory.taskName;
18
18
  status: factory.taskStatus.Ready;
19
- remainingNumberOfTries?: never;
20
- expires?: Date;
21
- executionResult?: never;
22
19
  }
23
20
  /**
24
21
  * タスク名不明の遅延実行中タスク
@@ -27,9 +24,6 @@ interface IRunningTask {
27
24
  id: string;
28
25
  status: factory.taskStatus.Running;
29
26
  name?: never;
30
- remainingNumberOfTries?: never;
31
- expires?: never;
32
- executionResult?: never;
33
27
  }
34
28
  /**
35
29
  * タスク名指定での遅延実行中タスク
@@ -38,35 +32,26 @@ interface IRunningTaskByName {
38
32
  id: string;
39
33
  status: factory.taskStatus.Running;
40
34
  name: factory.taskName;
41
- remainingNumberOfTries?: never;
42
- expires?: never;
43
- executionResult?: never;
44
35
  }
45
36
  /**
46
- * 実行後タスクイベント
37
+ * タスクステータス変更イベント発火時パラメータとしてのタスク
47
38
  */
48
- interface IExecutedTask {
39
+ type IChangedTask = IReadyTask | IRunningTask | IRunningTaskByName;
40
+ type IOperationExecute<T> = (settings: IExecuteSettings) => Promise<T>;
41
+ interface ITaskAsNextFunctionParam {
49
42
  id: string;
50
43
  status: factory.taskStatus.Executed | factory.taskStatus.Running | factory.taskStatus.Aborted;
51
44
  name: factory.taskName;
52
- executionResult: factory.task.IExecutionResult;
53
- /**
54
- * 実行されたタスクの残り試行回数
55
- */
56
- remainingNumberOfTries: number;
57
- expires?: never;
58
45
  }
59
- type IChangedTask = IReadyTask | IRunningTask | IRunningTaskByName | IExecutedTask;
60
- type IOperationExecute<T> = (settings: IExecuteSettings) => Promise<T>;
61
- type INextFunction = (task: IExecutedTask) => IOperationExecute<void>;
62
- type IOnTaskStatusChangedListener = (task: IChangedTask, next?: INextFunction) => void;
46
+ type IAsyncActionNextFunction = (task: ITaskAsNextFunctionParam) => IOperationExecute<void>;
47
+ type IOnTaskStatusChangedListener = (task: IChangedTask) => void;
63
48
  type RedisClientType = ReturnType<typeof createClient>;
64
49
  /**
65
50
  * タスクイベントエミッター
66
51
  */
67
52
  declare class TaskEventEmitter extends EventEmitter {
68
53
  onTaskStatusChanged(listener: IOnTaskStatusChangedListener): void;
69
- emitTaskStatusChanged(task: IChangedTask, next?: INextFunction): void;
54
+ emitTaskStatusChanged(task: IChangedTask): void;
70
55
  }
71
56
  declare const taskEventEmitter: TaskEventEmitter;
72
- export { IChangedTask, IReadyTask, IRunningTask, IRunningTaskByName, IExecutedTask, IExecuteSettings, INextFunction, IOnTaskStatusChangedListener, taskEventEmitter };
57
+ export { IChangedTask, IReadyTask, IRunningTask, IRunningTaskByName, IExecuteSettings, IOnTaskStatusChangedListener, taskEventEmitter, ITaskAsNextFunctionParam, IAsyncActionNextFunction };
@@ -14,8 +14,8 @@ class TaskEventEmitter extends events_1.EventEmitter {
14
14
  this.on(EventName.OnTaskStatusChanged, listener);
15
15
  }
16
16
  // support next function required(2025-05-25~)
17
- emitTaskStatusChanged(task, next) {
18
- this.emit(EventName.OnTaskStatusChanged, task, (typeof next === 'function') ? next : undefined);
17
+ emitTaskStatusChanged(task) {
18
+ this.emit(EventName.OnTaskStatusChanged, task);
19
19
  }
20
20
  }
21
21
  const taskEventEmitter = new TaskEventEmitter();
@@ -27,13 +27,6 @@ export declare class AcceptedOfferRepo extends AcceptedOfferInReserveRepo {
27
27
  acceptedOffers: [IAcceptedOffer];
28
28
  _id?: never;
29
29
  })[]>;
30
- aggreateOwnershipInfosByOrder(filter: {
31
- orderNumber: {
32
- $eq: string;
33
- };
34
- }): Promise<{
35
- identifier: string;
36
- }[]>;
37
30
  /**
38
31
  * 注文オファーを展開して検索する
39
32
  * 注文番号指定で1注文ドキュメントから参照する想定
@@ -105,33 +105,33 @@ class AcceptedOfferRepo extends acceptedOfferInReserve_1.AcceptedOfferInReserveR
105
105
  return orders;
106
106
  }
107
107
  }
108
- async aggreateOwnershipInfosByOrder(filter) {
109
- const aggregate = this.orderModel.aggregate([
110
- { $match: { orderNumber: { $eq: filter.orderNumber.$eq } } },
111
- { $match: { typeOf: { $eq: factory_1.factory.order.OrderType.Order } } },
112
- {
113
- $unwind: {
114
- path: '$acceptedOffers',
115
- includeArrayIndex: 'acceptedOfferIndex'
116
- }
117
- },
118
- {
119
- $project: {
120
- _id: 0,
121
- // acceptedOfferIndex: '$acceptedOfferIndex',
122
- // itemOfferedTypeOf: '$acceptedOffers.itemOffered.typeOf',
123
- // customerId: '$customer.id',
124
- // orderNumber: '$orderNumber',
125
- identifier: {
126
- $concat: ['$customer.id', '-', '$acceptedOffers.itemOffered.typeOf', '-', '$orderNumber', '-', { $toString: '$acceptedOfferIndex' }]
127
- }
128
- }
129
- }
130
- ]);
131
- return aggregate
132
- .option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
133
- .exec();
134
- }
108
+ // public async aggreateOwnershipInfosByOrder(
109
+ // filter: {
110
+ // orderNumber: { $eq: string };
111
+ // }
112
+ // ): Promise<{ identifier: string }[]> {
113
+ // const aggregate = this.orderModel.aggregate<{ identifier: string }>([
114
+ // { $match: { orderNumber: { $eq: filter.orderNumber.$eq } } },
115
+ // { $match: { typeOf: { $eq: factory.order.OrderType.Order } } },
116
+ // {
117
+ // $unwind: {
118
+ // path: '$acceptedOffers',
119
+ // includeArrayIndex: 'acceptedOfferIndex'
120
+ // }
121
+ // },
122
+ // {
123
+ // $project: {
124
+ // _id: 0,
125
+ // identifier: {
126
+ // $concat: ['$customer.id', '-', '$acceptedOffers.itemOffered.typeOf', '-', '$orderNumber', '-', { $toString: '$acceptedOfferIndex' }]
127
+ // }
128
+ // }
129
+ // }
130
+ // ]);
131
+ // return aggregate
132
+ // .option({ maxTimeMS: MONGO_MAX_TIME_MS })
133
+ // .exec();
134
+ // }
135
135
  /**
136
136
  * 注文オファーを展開して検索する
137
137
  * 注文番号指定で1注文ドキュメントから参照する想定
@@ -3,7 +3,7 @@ import { factory } from '../../factory';
3
3
  import { IModel as IActionModel } from '../mongoose/schemas/action';
4
4
  import { IModel as IActionRecipeModel } from '../mongoose/schemas/actionRecipe';
5
5
  export type IAction4transaction<T extends factory.actionType.AcceptAction | factory.actionType.AuthorizeAction> = T extends factory.actionType.AcceptAction ? factory.action.accept.coaOffer.IAction | factory.action.accept.pay.IAction : T extends factory.actionType.AuthorizeAction ? (factory.action.authorize.offer.eventService.IAction | factory.action.authorize.paymentMethod.any.IAction) : never;
6
- export type IAction<T extends factory.actionType> = T extends factory.actionType.OrderAction ? factory.action.trade.order.IAction : T extends factory.actionType.AcceptAction ? IAction4transaction<factory.actionType.AcceptAction> : T extends factory.actionType.AuthorizeAction ? factory.action.authorize.IAction<factory.action.authorize.IAttributes<any, any>> : T extends factory.actionType.CheckAction ? (factory.action.check.paymentMethod.movieTicket.IAction | factory.action.check.thing.IAction) : T extends factory.actionType.CreateAction ? factory.action.create.IAction : T extends factory.actionType.AddAction ? factory.action.update.add.IAction : T extends factory.actionType.ReplaceAction ? factory.action.update.replace.IAction : T extends factory.actionType.UpdateAction ? factory.action.update.update.IAction : T extends factory.actionType.InformAction ? factory.action.interact.inform.IAction<factory.action.interact.inform.IAttributes<factory.action.interact.inform.IObject>> & {
6
+ export type IAction<T extends factory.actionType> = T extends factory.actionType.OrderAction ? factory.action.trade.order.IAction : T extends factory.actionType.AcceptAction ? IAction4transaction<factory.actionType.AcceptAction> : T extends factory.actionType.AuthorizeAction ? factory.action.authorize.IAction<factory.action.authorize.IAttributes<any, any>> : T extends factory.actionType.CheckAction ? (factory.action.check.paymentMethod.movieTicket.IAction | factory.action.check.thing.IAction) : T extends factory.actionType.CreateAction ? factory.action.create.IAction : T extends factory.actionType.AddAction ? factory.action.update.add.IAction : T extends factory.actionType.ReplaceAction ? factory.action.update.replace.IAction : T extends factory.actionType.UpdateAction ? factory.action.update.update.IAction : T extends factory.actionType.InformAction ? factory.action.interact.inform.IAction & {
7
7
  error?: any;
8
8
  purpose?: never;
9
9
  } : factory.action.IAction<factory.action.IAttributes<T, any, any>>;
@@ -0,0 +1,38 @@
1
+ import { Connection, FilterQuery } from 'mongoose';
2
+ import { factory } from '../../factory';
3
+ import { IDocType } from '../mongoose/schemas/action/inform';
4
+ type StartableActionType = factory.actionType.InformAction;
5
+ type IAction = IDocType & {
6
+ id: string;
7
+ };
8
+ type IKeyOfProjection = keyof IDocType;
9
+ type IFindParams = Pick<factory.action.ISearchConditions, 'limit' | 'page' | 'project' | 'sort' | 'startFrom' | 'startThrough'> & {
10
+ id?: string;
11
+ };
12
+ /**
13
+ * 通知アクションリポジトリ
14
+ */
15
+ export declare class InformActionRepo {
16
+ private readonly informActionModel;
17
+ constructor(connection: Connection);
18
+ static CREATE_MONGO_CONDITIONS(params: IFindParams): FilterQuery<IDocType>[];
19
+ /**
20
+ * アクション開始
21
+ */
22
+ startInformAction(attributes: factory.action.interact.inform.IAttributes): Promise<Pick<IAction, 'id' | 'typeOf' | 'startDate'>>;
23
+ completeInformAction(params: {
24
+ typeOf: StartableActionType;
25
+ id: string;
26
+ result: factory.action.interact.inform.IResult;
27
+ }): Promise<void>;
28
+ /**
29
+ * アクション失敗
30
+ */
31
+ giveUpInformAction(params: {
32
+ typeOf: StartableActionType;
33
+ id: string;
34
+ error: Error | Error[] | unknown;
35
+ }): Promise<void>;
36
+ findInformActions(params: IFindParams, inclusion: IKeyOfProjection[]): Promise<IAction[]>;
37
+ }
38
+ export {};
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InformActionRepo = void 0;
4
+ const factory_1 = require("../../factory");
5
+ const settings_1 = require("../../settings");
6
+ const inform_1 = require("../mongoose/schemas/action/inform");
7
+ const AVAILABLE_PROJECT_FIELDS = [
8
+ 'project',
9
+ 'actionStatus',
10
+ 'typeOf',
11
+ 'agent',
12
+ 'result',
13
+ 'error',
14
+ 'object',
15
+ 'startDate',
16
+ 'endDate',
17
+ 'about',
18
+ 'purpose',
19
+ 'recipient',
20
+ 'target'
21
+ ];
22
+ // 内部で正規化関数を定義(または外部ヘルパーを呼び出す)
23
+ function unknown2actionError(e) {
24
+ if (e instanceof Error) {
25
+ // Errorオブジェクトの場合は、既存のロジック通り展開
26
+ return { ...e, name: e.name, message: e.message };
27
+ }
28
+ else {
29
+ // Error以外(文字列など)が投げられた場合のハンドリング
30
+ return { name: 'UnknownError', message: String(e) };
31
+ }
32
+ }
33
+ ;
34
+ /**
35
+ * 通知アクションリポジトリ
36
+ */
37
+ class InformActionRepo {
38
+ informActionModel;
39
+ constructor(connection) {
40
+ this.informActionModel = connection.model(inform_1.modelName, (0, inform_1.createSchema)());
41
+ }
42
+ static CREATE_MONGO_CONDITIONS(params) {
43
+ const andConditions = [];
44
+ const idEq = params.id;
45
+ if (typeof idEq === 'string') {
46
+ andConditions.push({ _id: { $eq: idEq } });
47
+ }
48
+ const projectIdEq = params.project?.id?.$eq;
49
+ if (typeof projectIdEq === 'string') {
50
+ andConditions.push({ 'project.id': { $eq: projectIdEq } });
51
+ }
52
+ // const objectIdEq = params.object?.id;
53
+ // if (typeof objectIdEq === 'string') {
54
+ // andConditions.push({ 'object.id': { $exists: true, $eq: objectIdEq } });
55
+ // }
56
+ // const objectOrderNumberEq = params.object?.orderNumber;
57
+ // if (typeof objectOrderNumberEq === 'string') {
58
+ // andConditions.push({ 'object.orderNumber': { $exists: true, $eq: objectOrderNumberEq } });
59
+ // }
60
+ // const aboutOrderNumberEq = params.about?.orderNumber;
61
+ // if (typeof aboutOrderNumberEq === 'string') {
62
+ // andConditions.push({ 'about.orderNumber': { $exists: true, $eq: aboutOrderNumberEq } });
63
+ // }
64
+ const startDateGte = params.startFrom;
65
+ if (startDateGte instanceof Date) {
66
+ andConditions.push({ startDate: { $gte: startDateGte } });
67
+ }
68
+ const startDateLte = params.startThrough;
69
+ if (startDateLte instanceof Date) {
70
+ andConditions.push({ startDate: { $lte: startDateLte } });
71
+ }
72
+ return andConditions;
73
+ }
74
+ /**
75
+ * アクション開始
76
+ */
77
+ async startInformAction(attributes) {
78
+ const startDate = new Date();
79
+ const creatingAction = {
80
+ ...attributes,
81
+ actionStatus: factory_1.factory.actionStatusType.ActiveActionStatus,
82
+ startDate
83
+ };
84
+ const result = await this.informActionModel.insertMany(creatingAction, { rawResult: true });
85
+ const id = result.insertedIds?.[0]?.toHexString();
86
+ if (typeof id !== 'string') {
87
+ throw new factory_1.factory.errors.Internal('action not saved');
88
+ }
89
+ return { id, startDate, typeOf: creatingAction.typeOf };
90
+ }
91
+ async completeInformAction(params) {
92
+ const doc = await this.informActionModel.findOneAndUpdate({
93
+ _id: { $eq: params.id },
94
+ typeOf: { $eq: params.typeOf }
95
+ }, {
96
+ $set: {
97
+ actionStatus: factory_1.factory.actionStatusType.CompletedActionStatus,
98
+ result: params.result,
99
+ endDate: new Date()
100
+ }
101
+ }, { new: false, projection: { _id: 1 } })
102
+ .lean()
103
+ .exec();
104
+ if (doc === null) {
105
+ throw new factory_1.factory.errors.NotFound(this.informActionModel.modelName);
106
+ }
107
+ }
108
+ /**
109
+ * アクション失敗
110
+ */
111
+ async giveUpInformAction(params) {
112
+ const actionError = Array.isArray(params.error)
113
+ ? params.error.map(unknown2actionError)
114
+ : unknown2actionError(params.error);
115
+ const doc = await this.informActionModel.findOneAndUpdate({
116
+ typeOf: { $eq: params.typeOf },
117
+ _id: { $eq: params.id }
118
+ }, {
119
+ $set: {
120
+ actionStatus: factory_1.factory.actionStatusType.FailedActionStatus,
121
+ error: actionError,
122
+ endDate: new Date()
123
+ }
124
+ }, { new: true, projection: { _id: 1 } })
125
+ .lean()
126
+ .exec();
127
+ if (doc === null) {
128
+ throw new factory_1.factory.errors.NotFound(this.informActionModel.modelName);
129
+ }
130
+ }
131
+ async findInformActions(params, inclusion) {
132
+ const conditions = InformActionRepo.CREATE_MONGO_CONDITIONS(params);
133
+ let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
134
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
135
+ positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
136
+ }
137
+ const projection = {
138
+ _id: 0,
139
+ id: { $toString: '$_id' },
140
+ ...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
141
+ };
142
+ const query = this.informActionModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
143
+ if (typeof params.limit === 'number' && params.limit > 0) {
144
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
145
+ query.limit(params.limit)
146
+ .skip(params.limit * (page - 1));
147
+ }
148
+ /* istanbul ignore else */
149
+ if (params.sort?.startDate !== undefined) {
150
+ query.sort({ startDate: params.sort.startDate });
151
+ }
152
+ // const explainResult = await (<any>query).explain();
153
+ // console.log(explainResult[0].executionStats.allPlansExecution.map((e: any) => e.executionStages.inputStage));
154
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
155
+ .lean() // 2024-08-26~
156
+ .exec();
157
+ }
158
+ }
159
+ exports.InformActionRepo = InformActionRepo;
@@ -0,0 +1,56 @@
1
+ import { Connection, FilterQuery } from 'mongoose';
2
+ import { factory } from '../../factory';
3
+ import { IDocType } from '../mongoose/schemas/action/update';
4
+ type StartableActionType = factory.actionType.AddAction | factory.actionType.UpdateAction | factory.actionType.ReplaceAction | factory.actionType.DeleteAction;
5
+ type IAction<T extends StartableActionType> = T extends factory.actionType.AddAction ? factory.action.update.add.IAction : T extends factory.actionType.ReplaceAction ? factory.action.update.replace.IAction : T extends factory.actionType.UpdateAction ? factory.action.update.update.IAction : T extends factory.actionType.DeleteAction ? factory.action.update.deleteAction.IAction : never;
6
+ type IKeyOfProjection = keyof IDocType;
7
+ type IFindParams = Pick<factory.action.ISearchConditions, 'limit' | 'page' | 'project' | 'sort' | 'startFrom' | 'startThrough'> & {
8
+ id?: string;
9
+ typeOf?: StartableActionType;
10
+ object?: {
11
+ id?: string;
12
+ };
13
+ result?: {
14
+ id?: string;
15
+ };
16
+ };
17
+ /**
18
+ * リソース編集アクションリポジトリ
19
+ */
20
+ export declare class UpdateActionRepo {
21
+ private readonly updateActionModel;
22
+ constructor(connection: Connection);
23
+ static CREATE_MONGO_CONDITIONS(params: IFindParams): FilterQuery<IDocType>[];
24
+ /**
25
+ * アクション開始
26
+ */
27
+ startUpdateAction<T extends StartableActionType>(attributes: factory.action.IAttributes<T, any, any>): Promise<Pick<IAction<T>, 'id' | 'typeOf' | 'startDate'>>;
28
+ completeUpdateAction(params: {
29
+ typeOf: StartableActionType;
30
+ id: string;
31
+ result: any;
32
+ }): Promise<void>;
33
+ /**
34
+ * アクション失敗
35
+ */
36
+ giveUpUpdateAction(params: {
37
+ typeOf: StartableActionType;
38
+ id: string;
39
+ error: Error | Error[] | unknown;
40
+ }): Promise<void>;
41
+ findUpdateActions(params: IFindParams, inclusion: IKeyOfProjection[]): Promise<IAction<StartableActionType>[]>;
42
+ findUpdateActionsBySameAs(params: {
43
+ sameAs: {
44
+ id: {
45
+ $eq: string;
46
+ };
47
+ };
48
+ /**
49
+ * 1taskから複数actionが発生する可能性があるので、typeOf指定が必須
50
+ */
51
+ typeOf: {
52
+ $eq: StartableActionType;
53
+ };
54
+ }): Promise<Pick<IAction<StartableActionType>, 'id' | 'actionStatus' | 'error'>[]>;
55
+ }
56
+ export {};
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UpdateActionRepo = void 0;
4
+ const factory_1 = require("../../factory");
5
+ const settings_1 = require("../../settings");
6
+ const update_1 = require("../mongoose/schemas/action/update");
7
+ const AVAILABLE_PROJECT_FIELDS = [
8
+ 'project',
9
+ 'actionStatus',
10
+ 'typeOf',
11
+ 'agent',
12
+ 'result',
13
+ 'error',
14
+ 'object',
15
+ 'startDate',
16
+ 'endDate',
17
+ 'instrument',
18
+ 'targetCollection',
19
+ 'sameAs',
20
+ ];
21
+ // 内部で正規化関数を定義(または外部ヘルパーを呼び出す)
22
+ function unknown2actionError(e) {
23
+ if (e instanceof Error) {
24
+ // Errorオブジェクトの場合は、既存のロジック通り展開
25
+ return { ...e, name: e.name, message: e.message };
26
+ }
27
+ else {
28
+ // Error以外(文字列など)が投げられた場合のハンドリング
29
+ return { name: 'UnknownError', message: String(e) };
30
+ }
31
+ }
32
+ ;
33
+ /**
34
+ * リソース編集アクションリポジトリ
35
+ */
36
+ class UpdateActionRepo {
37
+ updateActionModel;
38
+ constructor(connection) {
39
+ this.updateActionModel = connection.model(update_1.modelName, (0, update_1.createSchema)());
40
+ }
41
+ static CREATE_MONGO_CONDITIONS(params) {
42
+ const andConditions = [];
43
+ const idEq = params.id;
44
+ if (typeof idEq === 'string') {
45
+ andConditions.push({ _id: { $eq: idEq } });
46
+ }
47
+ const projectIdEq = params.project?.id?.$eq;
48
+ if (typeof projectIdEq === 'string') {
49
+ andConditions.push({ 'project.id': { $eq: projectIdEq } });
50
+ }
51
+ const objectIdEq = params.object?.id;
52
+ if (typeof objectIdEq === 'string') {
53
+ andConditions.push({ 'object.id': { $exists: true, $eq: objectIdEq } });
54
+ }
55
+ const resultIdEq = params.result?.id;
56
+ if (typeof resultIdEq === 'string') {
57
+ andConditions.push({ 'result.id': { $exists: true, $eq: resultIdEq } });
58
+ }
59
+ if (typeof params.typeOf === 'string') {
60
+ andConditions.push({ typeOf: { $eq: params.typeOf } });
61
+ }
62
+ const startDateGte = params.startFrom;
63
+ if (startDateGte instanceof Date) {
64
+ andConditions.push({ startDate: { $gte: startDateGte } });
65
+ }
66
+ const startDateLte = params.startThrough;
67
+ if (startDateLte instanceof Date) {
68
+ andConditions.push({ startDate: { $lte: startDateLte } });
69
+ }
70
+ return andConditions;
71
+ }
72
+ /**
73
+ * アクション開始
74
+ */
75
+ async startUpdateAction(attributes) {
76
+ const startDate = new Date();
77
+ const creatingAction = {
78
+ ...attributes,
79
+ actionStatus: factory_1.factory.actionStatusType.ActiveActionStatus,
80
+ startDate
81
+ };
82
+ const result = await this.updateActionModel.insertMany(creatingAction, { rawResult: true });
83
+ const id = result.insertedIds?.[0]?.toHexString();
84
+ if (typeof id !== 'string') {
85
+ throw new factory_1.factory.errors.Internal('action not saved');
86
+ }
87
+ return { id, startDate, typeOf: creatingAction.typeOf };
88
+ }
89
+ async completeUpdateAction(params) {
90
+ const doc = await this.updateActionModel.findOneAndUpdate({
91
+ _id: { $eq: params.id },
92
+ typeOf: { $eq: params.typeOf }
93
+ }, {
94
+ $set: {
95
+ actionStatus: factory_1.factory.actionStatusType.CompletedActionStatus,
96
+ result: params.result,
97
+ endDate: new Date()
98
+ }
99
+ }, { new: false, projection: { _id: 1 } })
100
+ .lean()
101
+ .exec();
102
+ if (doc === null) {
103
+ throw new factory_1.factory.errors.NotFound(this.updateActionModel.modelName);
104
+ }
105
+ }
106
+ /**
107
+ * アクション失敗
108
+ */
109
+ async giveUpUpdateAction(params) {
110
+ const actionError = Array.isArray(params.error)
111
+ ? params.error.map(unknown2actionError)
112
+ : unknown2actionError(params.error);
113
+ const doc = await this.updateActionModel.findOneAndUpdate({
114
+ typeOf: { $eq: params.typeOf },
115
+ _id: { $eq: params.id }
116
+ }, {
117
+ $set: {
118
+ actionStatus: factory_1.factory.actionStatusType.FailedActionStatus,
119
+ error: actionError,
120
+ endDate: new Date()
121
+ }
122
+ }, { new: true, projection: { _id: 1 } })
123
+ .lean()
124
+ .exec();
125
+ if (doc === null) {
126
+ throw new factory_1.factory.errors.NotFound(this.updateActionModel.modelName);
127
+ }
128
+ }
129
+ async findUpdateActions(params, inclusion) {
130
+ const conditions = UpdateActionRepo.CREATE_MONGO_CONDITIONS(params);
131
+ let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
132
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
133
+ positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
134
+ }
135
+ const projection = {
136
+ _id: 0,
137
+ id: { $toString: '$_id' },
138
+ ...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
139
+ };
140
+ const query = this.updateActionModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
141
+ if (typeof params.limit === 'number' && params.limit > 0) {
142
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
143
+ query.limit(params.limit)
144
+ .skip(params.limit * (page - 1));
145
+ }
146
+ /* istanbul ignore else */
147
+ if (params.sort?.startDate !== undefined) {
148
+ query.sort({ startDate: params.sort.startDate });
149
+ }
150
+ // const explainResult = await (<any>query).explain();
151
+ // console.log(explainResult[0].executionStats.allPlansExecution.map((e: any) => e.executionStages.inputStage));
152
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
153
+ .lean() // 2024-08-26~
154
+ .exec();
155
+ }
156
+ async findUpdateActionsBySameAs(params) {
157
+ const projection = {
158
+ _id: 0,
159
+ id: { $toString: '$_id' },
160
+ actionStatus: 1,
161
+ error: 1
162
+ };
163
+ const query = this.updateActionModel.find({
164
+ typeOf: { $eq: params.typeOf.$eq },
165
+ 'sameAs.id': { $exists: true, $eq: params.sameAs.id.$eq }
166
+ }, projection)
167
+ .limit(1);
168
+ return query
169
+ .lean()
170
+ .exec();
171
+ }
172
+ }
173
+ exports.UpdateActionRepo = UpdateActionRepo;
@@ -7,7 +7,7 @@ export { ICancelActionAction };
7
7
  /**
8
8
  * 汎用アクションリポジトリで開始可能なアクションタイプ
9
9
  */
10
- type StartableActionType = Exclude<factory.actionType, factory.actionType.AcceptAction | factory.actionType.CheckAction | factory.actionType.AuthorizeAction | factory.actionType.PayAction | factory.actionType.RefundAction>;
10
+ type StartableActionType = Exclude<factory.actionType, factory.actionType.AcceptAction | factory.actionType.CheckAction | factory.actionType.AuthorizeAction | factory.actionType.PayAction | factory.actionType.RefundAction | factory.actionType.AddAction | factory.actionType.UpdateAction | factory.actionType.ReplaceAction | factory.actionType.DeleteAction | factory.actionType.InformAction>;
11
11
  type IAvailableActionRecipe = IActionRecipe<Exclude<factory.recipe.RecipeCategory, factory.recipe.RecipeCategory.publishPaymentUrl | factory.recipe.RecipeCategory.checkMovieTicket | factory.recipe.RecipeCategory.acceptCOAOffer | factory.recipe.RecipeCategory.authorizeInvoice | factory.recipe.RecipeCategory.authorizeInvoice3ds | factory.recipe.RecipeCategory.payCreditCard | factory.recipe.RecipeCategory.payMovieTicket | factory.recipe.RecipeCategory.refundCreditCard | factory.recipe.RecipeCategory.refundMovieTicket>>;
12
12
  export interface IDeleteActionResult {
13
13
  identifier: string;
@@ -68,22 +68,6 @@ export declare class ActionRepo extends ActionProcessRepo<IAction<StartableActio
68
68
  id: string;
69
69
  };
70
70
  }): Promise<void>;
71
- /**
72
- * 開始日時を一定期間過ぎたアクションを削除する
73
- */
74
- deleteStartDatePassedCertainPeriod(params: {
75
- $lt: Date;
76
- }): Promise<import("mongodb").DeleteResult>;
77
- /**
78
- * 終了日時を一定期間過ぎたアクションを削除する
79
- * 作成日時を一定期間過ぎたアクションレシピも削除する
80
- */
81
- deleteEndDatePassedCertainPeriod(params: {
82
- $lt: Date;
83
- }): Promise<{
84
- deleteActionRecipesResult: import("mongodb").DeleteResult;
85
- deleteActionsResult: import("mongodb").DeleteResult;
86
- } | undefined>;
87
71
  /**
88
72
  * 取引からアクションを削除する
89
73
  */
@@ -99,13 +83,13 @@ export declare class ActionRepo extends ActionProcessRepo<IAction<StartableActio
99
83
  $in: factory.actionType[];
100
84
  };
101
85
  }): Promise<IDeleteActionResult[]>;
102
- getCursor(conditions: any, projection: any): import("mongoose").Cursor<import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & Omit<import("@chevre/factory/lib/chevre/action").IAction<import("@chevre/factory/lib/chevre/action").IAttributes<factory.actionType, any, any>>, "id"> & {
86
+ getCursor(conditions: any, projection: any): import("mongoose").Cursor<import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & Omit<import("@chevre/factory/lib/chevre/action").IAction<import("@chevre/factory/lib/chevre/action").IAttributes<factory.actionType, any, any>>, "id" | "replacer"> & {
103
87
  identifier?: string;
104
88
  } & {
105
89
  _id: import("mongoose").Types.ObjectId;
106
90
  } & {
107
91
  __v: number;
108
- }, import("mongoose").QueryOptions<IDocType>, (import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & Omit<import("@chevre/factory/lib/chevre/action").IAction<import("@chevre/factory/lib/chevre/action").IAttributes<factory.actionType, any, any>>, "id"> & {
92
+ }, import("mongoose").QueryOptions<IDocType>, (import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & Omit<import("@chevre/factory/lib/chevre/action").IAction<import("@chevre/factory/lib/chevre/action").IAttributes<factory.actionType, any, any>>, "id" | "replacer"> & {
109
93
  identifier?: string;
110
94
  } & {
111
95
  _id: import("mongoose").Types.ObjectId;