@chevre/domain 23.2.0-alpha.60 → 23.2.0-alpha.62

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 (513) hide show
  1. package/lib/chevre/credentials/customSearch.js +2 -0
  2. package/lib/chevre/credentials/lineNotify.js +4 -0
  3. package/lib/chevre/credentials/sendGrid.js +2 -0
  4. package/lib/chevre/credentials.js +15 -30
  5. package/lib/chevre/emailMessageBuilder.js +225 -250
  6. package/lib/chevre/errorHandler.js +38 -54
  7. package/lib/chevre/factory/event.js +69 -42
  8. package/lib/chevre/factory/transactionNumber.js +3 -1
  9. package/lib/chevre/index.js +15 -30
  10. package/lib/chevre/repo/acceptedOffer.js +178 -197
  11. package/lib/chevre/repo/acceptedPaymentMethod.js +131 -143
  12. package/lib/chevre/repo/account.js +196 -223
  13. package/lib/chevre/repo/accountTitle.js +9 -21
  14. package/lib/chevre/repo/accountTransaction.js +189 -189
  15. package/lib/chevre/repo/accountingReport.js +88 -107
  16. package/lib/chevre/repo/action.js +853 -880
  17. package/lib/chevre/repo/additionalProperty.js +65 -91
  18. package/lib/chevre/repo/advanceBookingRequirement.js +69 -90
  19. package/lib/chevre/repo/aggregateOffer.js +394 -427
  20. package/lib/chevre/repo/aggregateOrder.js +50 -62
  21. package/lib/chevre/repo/aggregateReservation.js +76 -89
  22. package/lib/chevre/repo/aggregation.js +42 -63
  23. package/lib/chevre/repo/assetTransaction.js +696 -716
  24. package/lib/chevre/repo/authorization.js +115 -127
  25. package/lib/chevre/repo/categoryCode.js +115 -143
  26. package/lib/chevre/repo/comment.js +74 -82
  27. package/lib/chevre/repo/concurrentLock.js +17 -29
  28. package/lib/chevre/repo/confirmationNumber.js +21 -33
  29. package/lib/chevre/repo/creativeWork.js +154 -176
  30. package/lib/chevre/repo/credentials.js +40 -51
  31. package/lib/chevre/repo/customer.js +65 -88
  32. package/lib/chevre/repo/customerType.js +52 -61
  33. package/lib/chevre/repo/emailMessage.js +52 -80
  34. package/lib/chevre/repo/event.d.ts +0 -15
  35. package/lib/chevre/repo/event.js +720 -744
  36. package/lib/chevre/repo/eventOffer.js +122 -125
  37. package/lib/chevre/repo/eventSellerMakesOffer.js +64 -76
  38. package/lib/chevre/repo/eventSeries.d.ts +1 -7
  39. package/lib/chevre/repo/eventSeries.js +258 -277
  40. package/lib/chevre/repo/identity.js +94 -106
  41. package/lib/chevre/repo/identityProvider.js +72 -95
  42. package/lib/chevre/repo/issuer.js +102 -135
  43. package/lib/chevre/repo/member.js +238 -258
  44. package/lib/chevre/repo/memberProgram.js +157 -177
  45. package/lib/chevre/repo/merchantReturnPolicy.js +62 -93
  46. package/lib/chevre/repo/message.js +122 -135
  47. package/lib/chevre/repo/mongoose/schemas/acceptedPaymentMethod.js +1 -1
  48. package/lib/chevre/repo/mongoose/schemas/account.js +1 -1
  49. package/lib/chevre/repo/mongoose/schemas/accountTitle.js +1 -1
  50. package/lib/chevre/repo/mongoose/schemas/accountTransaction.js +1 -1
  51. package/lib/chevre/repo/mongoose/schemas/accountingReport.js +1 -1
  52. package/lib/chevre/repo/mongoose/schemas/action.js +1 -1
  53. package/lib/chevre/repo/mongoose/schemas/actionRecipe.js +1 -1
  54. package/lib/chevre/repo/mongoose/schemas/additionalProperty.js +1 -1
  55. package/lib/chevre/repo/mongoose/schemas/advanceBookingRequirement.js +1 -1
  56. package/lib/chevre/repo/mongoose/schemas/aggregateOffer.js +1 -1
  57. package/lib/chevre/repo/mongoose/schemas/aggregateOrder.js +1 -1
  58. package/lib/chevre/repo/mongoose/schemas/aggregateReservation.js +1 -1
  59. package/lib/chevre/repo/mongoose/schemas/aggregation.js +1 -1
  60. package/lib/chevre/repo/mongoose/schemas/assetTransaction.js +1 -1
  61. package/lib/chevre/repo/mongoose/schemas/authorization.js +1 -1
  62. package/lib/chevre/repo/mongoose/schemas/categoryCode.js +1 -1
  63. package/lib/chevre/repo/mongoose/schemas/civicStructure.js +1 -1
  64. package/lib/chevre/repo/mongoose/schemas/creativeWork.js +1 -1
  65. package/lib/chevre/repo/mongoose/schemas/customer.js +1 -1
  66. package/lib/chevre/repo/mongoose/schemas/customerType.js +1 -1
  67. package/lib/chevre/repo/mongoose/schemas/event.js +1 -1
  68. package/lib/chevre/repo/mongoose/schemas/eventOffer.js +1 -1
  69. package/lib/chevre/repo/mongoose/schemas/eventSeries.js +41 -14
  70. package/lib/chevre/repo/mongoose/schemas/identity.js +1 -1
  71. package/lib/chevre/repo/mongoose/schemas/identityProvider.js +1 -1
  72. package/lib/chevre/repo/mongoose/schemas/issuer.js +1 -1
  73. package/lib/chevre/repo/mongoose/schemas/member/global.js +1 -1
  74. package/lib/chevre/repo/mongoose/schemas/member.js +1 -1
  75. package/lib/chevre/repo/mongoose/schemas/merchantReturnPolicy.js +1 -1
  76. package/lib/chevre/repo/mongoose/schemas/message.js +1 -1
  77. package/lib/chevre/repo/mongoose/schemas/movieTicketTypes.js +1 -1
  78. package/lib/chevre/repo/mongoose/schemas/note.js +1 -1
  79. package/lib/chevre/repo/mongoose/schemas/offerCatalog.js +1 -1
  80. package/lib/chevre/repo/mongoose/schemas/offerCatalogItem.js +1 -1
  81. package/lib/chevre/repo/mongoose/schemas/offerItemCondition.js +1 -1
  82. package/lib/chevre/repo/mongoose/schemas/order.js +1 -1
  83. package/lib/chevre/repo/mongoose/schemas/paymentService.js +1 -1
  84. package/lib/chevre/repo/mongoose/schemas/paymentServiceChannel.js +1 -1
  85. package/lib/chevre/repo/mongoose/schemas/pendingReservation.js +1 -1
  86. package/lib/chevre/repo/mongoose/schemas/pendingReservationAggregate.js +1 -1
  87. package/lib/chevre/repo/mongoose/schemas/place.js +1 -1
  88. package/lib/chevre/repo/mongoose/schemas/potentialAction.js +1 -1
  89. package/lib/chevre/repo/mongoose/schemas/product.js +1 -1
  90. package/lib/chevre/repo/mongoose/schemas/productModel.js +1 -1
  91. package/lib/chevre/repo/mongoose/schemas/productOffer.js +1 -1
  92. package/lib/chevre/repo/mongoose/schemas/reservation.js +1 -1
  93. package/lib/chevre/repo/mongoose/schemas/reserveInterface.js +1 -1
  94. package/lib/chevre/repo/mongoose/schemas/role.js +1 -1
  95. package/lib/chevre/repo/mongoose/schemas/schedule.js +1 -1
  96. package/lib/chevre/repo/mongoose/schemas/seller.js +1 -1
  97. package/lib/chevre/repo/mongoose/schemas/sellerReturnPolicy.js +1 -1
  98. package/lib/chevre/repo/mongoose/schemas/service/availableHour.js +1 -1
  99. package/lib/chevre/repo/mongoose/schemas/setting.js +1 -1
  100. package/lib/chevre/repo/mongoose/schemas/task.js +1 -1
  101. package/lib/chevre/repo/mongoose/schemas/ticket.js +1 -1
  102. package/lib/chevre/repo/mongoose/schemas/transaction.js +1 -1
  103. package/lib/chevre/repo/mongoose/schemas/transactionNumber.js +1 -1
  104. package/lib/chevre/repo/mongoose/schemas/trip.js +1 -1
  105. package/lib/chevre/repo/mongoose/schemas/webSite.js +1 -1
  106. package/lib/chevre/repo/movieTicketType.js +68 -89
  107. package/lib/chevre/repo/note.js +143 -146
  108. package/lib/chevre/repo/noteAboutOrder.js +112 -113
  109. package/lib/chevre/repo/offer/unitPriceInCatalog.js +331 -313
  110. package/lib/chevre/repo/offerCatalog.js +302 -333
  111. package/lib/chevre/repo/offerCatalogItem.js +289 -316
  112. package/lib/chevre/repo/offerItemCondition.js +60 -85
  113. package/lib/chevre/repo/order.js +563 -572
  114. package/lib/chevre/repo/orderInTransaction.js +113 -136
  115. package/lib/chevre/repo/orderNumber.d.ts +0 -1
  116. package/lib/chevre/repo/orderNumber.js +108 -122
  117. package/lib/chevre/repo/ownershipInfo.js +213 -233
  118. package/lib/chevre/repo/passport.js +94 -102
  119. package/lib/chevre/repo/paymentMethod/creditCard.js +153 -169
  120. package/lib/chevre/repo/paymentService.js +180 -199
  121. package/lib/chevre/repo/paymentServiceChannel.js +76 -99
  122. package/lib/chevre/repo/paymentServiceProvider.js +186 -201
  123. package/lib/chevre/repo/pendingReservation.js +275 -305
  124. package/lib/chevre/repo/permit.js +47 -42
  125. package/lib/chevre/repo/person.js +227 -247
  126. package/lib/chevre/repo/place/busStop.js +77 -103
  127. package/lib/chevre/repo/place/entranceGate.js +123 -128
  128. package/lib/chevre/repo/place/hasPOS.js +108 -120
  129. package/lib/chevre/repo/place/movieTheater.js +187 -219
  130. package/lib/chevre/repo/place/screeningRoom.js +340 -324
  131. package/lib/chevre/repo/place/seat.js +539 -475
  132. package/lib/chevre/repo/place/section.js +329 -292
  133. package/lib/chevre/repo/potentialAction.js +67 -86
  134. package/lib/chevre/repo/priceSpecification.js +103 -141
  135. package/lib/chevre/repo/product.js +204 -238
  136. package/lib/chevre/repo/productHasOfferCatalog.js +39 -50
  137. package/lib/chevre/repo/productModel.js +94 -126
  138. package/lib/chevre/repo/productOffer.js +119 -118
  139. package/lib/chevre/repo/project.js +123 -141
  140. package/lib/chevre/repo/projectMakesOffer.js +96 -108
  141. package/lib/chevre/repo/rateLimit/offer.js +43 -56
  142. package/lib/chevre/repo/reservation.js +370 -345
  143. package/lib/chevre/repo/reserveInterface.js +31 -42
  144. package/lib/chevre/repo/role.js +94 -112
  145. package/lib/chevre/repo/schedule.js +25 -36
  146. package/lib/chevre/repo/seller.js +115 -145
  147. package/lib/chevre/repo/sellerMakesOffer.js +95 -110
  148. package/lib/chevre/repo/sellerPaymentAccepted.js +92 -109
  149. package/lib/chevre/repo/sellerReturnPolicy.js +74 -96
  150. package/lib/chevre/repo/service/availableHour.js +27 -38
  151. package/lib/chevre/repo/serviceOutput.js +55 -66
  152. package/lib/chevre/repo/serviceOutputIdentifier.js +46 -57
  153. package/lib/chevre/repo/setting/jwt.js +40 -50
  154. package/lib/chevre/repo/setting.js +48 -48
  155. package/lib/chevre/repo/stockHolder.js +179 -197
  156. package/lib/chevre/repo/task.d.ts +1 -1
  157. package/lib/chevre/repo/task.js +615 -617
  158. package/lib/chevre/repo/telemetry.js +1 -0
  159. package/lib/chevre/repo/ticket.js +52 -65
  160. package/lib/chevre/repo/transaction.js +758 -795
  161. package/lib/chevre/repo/transactionNumber.js +67 -80
  162. package/lib/chevre/repo/transactionNumberCounter.js +69 -79
  163. package/lib/chevre/repo/transactionProcess.js +36 -47
  164. package/lib/chevre/repo/trip.js +145 -163
  165. package/lib/chevre/repo/webSite.js +90 -105
  166. package/lib/chevre/repository.js +455 -646
  167. package/lib/chevre/service/account.js +9 -18
  168. package/lib/chevre/service/accountTransaction/deposit.js +16 -17
  169. package/lib/chevre/service/accountTransaction/transfer.js +18 -19
  170. package/lib/chevre/service/accountTransaction/withdraw.js +16 -17
  171. package/lib/chevre/service/accountTransaction.js +4 -13
  172. package/lib/chevre/service/aggregation/event/aggregateOffers.js +63 -60
  173. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +52 -55
  174. package/lib/chevre/service/aggregation/event/findEventOffers.js +7 -17
  175. package/lib/chevre/service/aggregation/event/importFromCOA.js +4 -13
  176. package/lib/chevre/service/aggregation/project.js +10 -19
  177. package/lib/chevre/service/aggregation/system.js +182 -99
  178. package/lib/chevre/service/assetTransaction/cancelReservation/factory.js +31 -17
  179. package/lib/chevre/service/assetTransaction/cancelReservation/start.js +17 -23
  180. package/lib/chevre/service/assetTransaction/cancelReservation/startAndConfirm.js +17 -15
  181. package/lib/chevre/service/assetTransaction/cancelReservation.js +7 -16
  182. package/lib/chevre/service/assetTransaction/cancelReservationCOA/factory.js +11 -4
  183. package/lib/chevre/service/assetTransaction/cancelReservationCOA.js +4 -13
  184. package/lib/chevre/service/assetTransaction/fixInformAction.d.ts +3 -0
  185. package/lib/chevre/service/assetTransaction/fixInformAction.js +9 -16
  186. package/lib/chevre/service/assetTransaction/moneyTransfer/potentialActions.js +13 -25
  187. package/lib/chevre/service/assetTransaction/moneyTransfer.js +101 -88
  188. package/lib/chevre/service/assetTransaction/pay/cancel.d.ts +12 -0
  189. package/lib/chevre/service/assetTransaction/pay/cancel.js +16 -0
  190. package/lib/chevre/service/assetTransaction/pay/check.d.ts +23 -0
  191. package/lib/chevre/service/assetTransaction/pay/check.js +27 -0
  192. package/lib/chevre/service/assetTransaction/pay/confirm.d.ts +24 -0
  193. package/lib/chevre/service/assetTransaction/pay/confirm.js +69 -0
  194. package/lib/chevre/service/assetTransaction/pay/exportTasksById.d.ts +18 -0
  195. package/lib/chevre/service/assetTransaction/pay/exportTasksById.js +102 -0
  196. package/lib/chevre/service/assetTransaction/pay/publishPaymentUrl.d.ts +48 -0
  197. package/lib/chevre/service/assetTransaction/pay/publishPaymentUrl.js +165 -0
  198. package/lib/chevre/service/assetTransaction/pay/searchGMOTrade.d.ts +20 -0
  199. package/lib/chevre/service/assetTransaction/pay/searchGMOTrade.js +49 -0
  200. package/lib/chevre/service/assetTransaction/pay/{account → start/account}/validation.d.ts +2 -2
  201. package/lib/chevre/service/assetTransaction/pay/{account → start/account}/validation.js +7 -17
  202. package/lib/chevre/service/assetTransaction/pay/{factory.d.ts → start/factory.d.ts} +1 -1
  203. package/lib/chevre/service/assetTransaction/pay/{factory.js → start/factory.js} +65 -37
  204. package/lib/chevre/service/assetTransaction/pay/{validateAcceptedPaymentMethodIfNeeded.d.ts → start/preStart/validateAcceptedPaymentMethodIfNeeded.d.ts} +4 -4
  205. package/lib/chevre/service/assetTransaction/pay/{validateAcceptedPaymentMethodIfNeeded.js → start/preStart/validateAcceptedPaymentMethodIfNeeded.js} +8 -21
  206. package/lib/chevre/service/assetTransaction/pay/start/preStart/validateSeller.d.ts +8 -0
  207. package/lib/chevre/service/assetTransaction/pay/start/preStart/validateSeller.js +44 -0
  208. package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeAccount.d.ts +13 -0
  209. package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeAccount.js +39 -0
  210. package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeCreditCard.d.ts +29 -0
  211. package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeCreditCard.js +31 -0
  212. package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeMovieTicket.d.ts +42 -0
  213. package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeMovieTicket.js +22 -0
  214. package/lib/chevre/service/assetTransaction/pay/start.d.ts +60 -0
  215. package/lib/chevre/service/assetTransaction/pay/start.js +139 -0
  216. package/lib/chevre/service/assetTransaction/pay.d.ts +8 -170
  217. package/lib/chevre/service/assetTransaction/pay.js +16 -623
  218. package/lib/chevre/service/assetTransaction/refund/factory.js +36 -16
  219. package/lib/chevre/service/assetTransaction/refund/potentialActions.js +12 -21
  220. package/lib/chevre/service/assetTransaction/refund.js +35 -39
  221. package/lib/chevre/service/assetTransaction/registerService/factory.js +65 -28
  222. package/lib/chevre/service/assetTransaction/registerService/potentialActions.js +50 -41
  223. package/lib/chevre/service/assetTransaction/registerService.js +45 -52
  224. package/lib/chevre/service/assetTransaction/reserve/cancel.js +5 -14
  225. package/lib/chevre/service/assetTransaction/reserve/confirm/factory.js +15 -3
  226. package/lib/chevre/service/assetTransaction/reserve/confirm.js +21 -26
  227. package/lib/chevre/service/assetTransaction/reserve/exportTasksById.js +3 -12
  228. package/lib/chevre/service/assetTransaction/reserve/start/createSubReservations.js +99 -79
  229. package/lib/chevre/service/assetTransaction/reserve/start/factory/createPointAward.js +17 -12
  230. package/lib/chevre/service/assetTransaction/reserve/start/factory/createReservation.js +108 -70
  231. package/lib/chevre/service/assetTransaction/reserve/start/factory/createStartParams.js +69 -30
  232. package/lib/chevre/service/assetTransaction/reserve/start/factory/price.js +29 -20
  233. package/lib/chevre/service/assetTransaction/reserve/start.js +91 -106
  234. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/fixExtendedEventOffer.js +5 -15
  235. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateIssuedOfferIfExists.js +41 -54
  236. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateMemberTierIfExists.js +42 -55
  237. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/verifyTicketTokenAsNeeded.js +7 -17
  238. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.js +15 -27
  239. package/lib/chevre/service/assetTransaction/reserveCOA/cancel.js +24 -24
  240. package/lib/chevre/service/assetTransaction/reserveCOA/factory.js +12 -4
  241. package/lib/chevre/service/assetTransaction/reserveCOA.js +4 -13
  242. package/lib/chevre/service/assetTransaction.js +17 -21
  243. package/lib/chevre/service/delivery/factory.js +3 -4
  244. package/lib/chevre/service/delivery/product/factory.js +16 -7
  245. package/lib/chevre/service/delivery/reservation/factory.js +14 -3
  246. package/lib/chevre/service/delivery.js +47 -49
  247. package/lib/chevre/service/event/processUpdateMovieTheater.js +21 -23
  248. package/lib/chevre/service/event/saveScreeningEventSeries.js +56 -37
  249. package/lib/chevre/service/event/saveScreeningEvents.js +14 -23
  250. package/lib/chevre/service/event.js +34 -27
  251. package/lib/chevre/service/iam.js +8 -17
  252. package/lib/chevre/service/moneyTransfer.js +128 -112
  253. package/lib/chevre/service/notification/factory.js +11 -8
  254. package/lib/chevre/service/notification/notifyAbortedTasksByEmail.js +11 -15
  255. package/lib/chevre/service/notification/notifyByEmail.js +7 -17
  256. package/lib/chevre/service/notification/sendEmailMessage.js +23 -26
  257. package/lib/chevre/service/notification/triggerWebhook.js +58 -54
  258. package/lib/chevre/service/offer/any.js +6 -15
  259. package/lib/chevre/service/offer/event/authorize/factory.js +139 -61
  260. package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre/requestedProgramMembershipUsed2permit.js +8 -18
  261. package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre.js +43 -27
  262. package/lib/chevre/service/offer/event/authorize.js +114 -68
  263. package/lib/chevre/service/offer/event/checkAvailability.js +5 -15
  264. package/lib/chevre/service/offer/event/importFromCOA/factory.js +9 -2
  265. package/lib/chevre/service/offer/event/importFromCOA.js +13 -19
  266. package/lib/chevre/service/offer/event/issueEventOfferTicket.js +38 -39
  267. package/lib/chevre/service/offer/event/searchEventTicketOffers.js +26 -38
  268. package/lib/chevre/service/offer/event/searchOfferAppliesToMovieTicket.js +11 -22
  269. package/lib/chevre/service/offer/event/searchOfferCatalogItemAvailability.js +13 -24
  270. package/lib/chevre/service/offer/event/searchOfferCatalogItems.js +15 -22
  271. package/lib/chevre/service/offer/event/searchOffersByIds.js +24 -36
  272. package/lib/chevre/service/offer/event/searchPriceSpecs4event.js +5 -14
  273. package/lib/chevre/service/offer/event/voidTransaction/processVoidTransaction4chevre.js +4 -13
  274. package/lib/chevre/service/offer/event/voidTransaction/processVoidTransaction4coa.js +6 -15
  275. package/lib/chevre/service/offer/event/voidTransaction.js +35 -39
  276. package/lib/chevre/service/offer/event/voidTransactionByActionId.js +14 -20
  277. package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer/authorize.js +52 -40
  278. package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer/factory.js +5 -1
  279. package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer.js +34 -37
  280. package/lib/chevre/service/offer/eventServiceByCOA/authorize/factory.js +45 -22
  281. package/lib/chevre/service/offer/eventServiceByCOA/authorize/validateAcceptedOffers.js +67 -59
  282. package/lib/chevre/service/offer/eventServiceByCOA/authorize.js +16 -26
  283. package/lib/chevre/service/offer/eventServiceByCOA/authorizeByAcceptAction.js +8 -18
  284. package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.js +42 -41
  285. package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.js +22 -25
  286. package/lib/chevre/service/offer/factory.js +18 -7
  287. package/lib/chevre/service/offer/moneyTransfer/authorize.js +31 -36
  288. package/lib/chevre/service/offer/moneyTransfer/returnMoneyTransfer.js +9 -18
  289. package/lib/chevre/service/offer/moneyTransfer/settleTransaction.js +10 -19
  290. package/lib/chevre/service/offer/moneyTransfer/voidTransaction.js +14 -24
  291. package/lib/chevre/service/offer/onEventChanged.js +69 -64
  292. package/lib/chevre/service/offer/product/factory.js +54 -29
  293. package/lib/chevre/service/offer/product/searchProductOffers.js +30 -23
  294. package/lib/chevre/service/offer/product.js +106 -80
  295. package/lib/chevre/service/offer.js +48 -44
  296. package/lib/chevre/service/order/confirmPayTransaction.js +28 -27
  297. package/lib/chevre/service/order/createAccountingReportIfNotExist.js +54 -41
  298. package/lib/chevre/service/order/deleteOrder.js +28 -35
  299. package/lib/chevre/service/order/findPlaceOrderTransaction.js +3 -12
  300. package/lib/chevre/service/order/onAssetTransactionStatusChanged.js +64 -68
  301. package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled/factory.d.ts +1 -1
  302. package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled/factory.js +1 -2
  303. package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled.js +3 -12
  304. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered/factory.js +11 -6
  305. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered.js +5 -14
  306. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially/factory.d.ts +1 -1
  307. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially/factory.js +22 -9
  308. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially.js +5 -14
  309. package/lib/chevre/service/order/onOrderStatusChanged/onOrderInTransit.js +23 -26
  310. package/lib/chevre/service/order/onOrderStatusChanged/onOrderPaymentDue.js +13 -19
  311. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.js +5 -14
  312. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.js +24 -13
  313. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/processOrder.js +23 -32
  314. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +8 -18
  315. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.d.ts +1 -1
  316. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.js +10 -9
  317. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned.js +23 -28
  318. package/lib/chevre/service/order/onOrderUpdated/factory.js +3 -5
  319. package/lib/chevre/service/order/onOrderUpdated.js +13 -15
  320. package/lib/chevre/service/order/payOrder.js +3 -12
  321. package/lib/chevre/service/order/placeOrder/createPlacingOrderFromExistingTransaction.js +9 -19
  322. package/lib/chevre/service/order/placeOrder/factory/orderedItem.js +31 -15
  323. package/lib/chevre/service/order/placeOrder/factory.js +35 -22
  324. package/lib/chevre/service/order/placeOrder/voidAcceptedOfferIfNecessary.js +3 -12
  325. package/lib/chevre/service/order/placeOrder.js +12 -22
  326. package/lib/chevre/service/order/placeOrderWithoutTransaction.js +10 -18
  327. package/lib/chevre/service/order/returnOrder.js +27 -29
  328. package/lib/chevre/service/order/sendOrder.js +37 -36
  329. package/lib/chevre/service/payment/any/authorize/fixTransactionNumber.js +19 -25
  330. package/lib/chevre/service/payment/any/authorize/handlePrePublishedPaymentMethodIdOnAuthorizing.js +24 -37
  331. package/lib/chevre/service/payment/any/factory.js +106 -49
  332. package/lib/chevre/service/payment/any/fixOrderAsNeeded.js +4 -13
  333. package/lib/chevre/service/payment/any/onPayActionCompleted.js +13 -18
  334. package/lib/chevre/service/payment/any/onPaymentStatusChanged/onPaid.js +34 -37
  335. package/lib/chevre/service/payment/any/onPaymentStatusChanged/onRefunded.js +18 -24
  336. package/lib/chevre/service/payment/any/onPaymentStatusChanged.js +16 -16
  337. package/lib/chevre/service/payment/any/onRefundActionCompletedOrFailed.js +15 -20
  338. package/lib/chevre/service/payment/any/person2username.js +33 -45
  339. package/lib/chevre/service/payment/any/publishPaymentUrl/fixTransactionNumberOnPublishPaymentUrl.js +8 -18
  340. package/lib/chevre/service/payment/any/verifyTicketTokenAsNeeded.js +5 -15
  341. package/lib/chevre/service/payment/any.js +181 -137
  342. package/lib/chevre/service/payment/creditCard/authorize/handleAuthorizeError.js +2 -2
  343. package/lib/chevre/service/payment/creditCard/authorize/processAuthorizeCreditCard.js +44 -24
  344. package/lib/chevre/service/payment/creditCard/authorize/processAuthorizeCreditCard3ds.js +6 -15
  345. package/lib/chevre/service/payment/creditCard/authorize/processAuthorizeCreditCard3dsResult2recipe.js +5 -1
  346. package/lib/chevre/service/payment/creditCard/authorize/processAuthorizeCreditCardResult2recipe.js +10 -2
  347. package/lib/chevre/service/payment/creditCard/authorize.js +20 -22
  348. package/lib/chevre/service/payment/creditCard/factory.js +22 -4
  349. package/lib/chevre/service/payment/creditCard/getGMOInfoFromSeller.js +8 -18
  350. package/lib/chevre/service/payment/creditCard/payCreditCard.js +31 -36
  351. package/lib/chevre/service/payment/creditCard/refundCreditCard.js +40 -49
  352. package/lib/chevre/service/payment/creditCard/searchGMOTrade.js +33 -45
  353. package/lib/chevre/service/payment/creditCard/voidTransaction.js +15 -25
  354. package/lib/chevre/service/payment/faceToFace.js +14 -23
  355. package/lib/chevre/service/payment/factory/createPayObjectServiceOutput.js +44 -25
  356. package/lib/chevre/service/payment/factory.js +50 -23
  357. package/lib/chevre/service/payment/movieTicket/authorize.js +35 -28
  358. package/lib/chevre/service/payment/movieTicket/checkMovieTicket.js +22 -25
  359. package/lib/chevre/service/payment/movieTicket/factory.js +33 -10
  360. package/lib/chevre/service/payment/movieTicket/getCredentials.js +5 -15
  361. package/lib/chevre/service/payment/movieTicket/payMovieTicket.js +29 -40
  362. package/lib/chevre/service/payment/movieTicket/processPurchaseNumberAuth.js +8 -18
  363. package/lib/chevre/service/payment/movieTicket/refundMovieTicket.js +60 -59
  364. package/lib/chevre/service/payment/movieTicket/validation.js +41 -36
  365. package/lib/chevre/service/payment/movieTicket/voidTransaction.js +8 -18
  366. package/lib/chevre/service/payment/paymentCard.js +87 -103
  367. package/lib/chevre/service/permit.js +36 -35
  368. package/lib/chevre/service/product.js +23 -27
  369. package/lib/chevre/service/project.js +22 -31
  370. package/lib/chevre/service/report/ownershipInfo.js +3 -4
  371. package/lib/chevre/service/report/telemetry.js +51 -55
  372. package/lib/chevre/service/reserve/cancelReservation.js +92 -90
  373. package/lib/chevre/service/reserve/checkInReservation.js +24 -29
  374. package/lib/chevre/service/reserve/confirmReservation.js +33 -38
  375. package/lib/chevre/service/reserve/factory.js +42 -20
  376. package/lib/chevre/service/reserve/findByCode.js +13 -18
  377. package/lib/chevre/service/reserve/potentialActions/onPendingReservationCanceled.js +18 -24
  378. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.js +17 -24
  379. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.js +38 -29
  380. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +45 -35
  381. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +37 -32
  382. package/lib/chevre/service/reserve/potentialActions/onReservationsCreated.js +17 -23
  383. package/lib/chevre/service/reserve/searchByOrder.js +10 -19
  384. package/lib/chevre/service/reserve/useReservation.js +47 -32
  385. package/lib/chevre/service/reserve/verifyToken4reservation.js +7 -14
  386. package/lib/chevre/service/reserveCOA/cancelReservation.js +7 -16
  387. package/lib/chevre/service/reserveCOA/factory.js +5 -1
  388. package/lib/chevre/service/task/acceptCOAOffer.js +20 -24
  389. package/lib/chevre/service/task/aggregateOffers.js +3 -12
  390. package/lib/chevre/service/task/aggregateOnSystem.js +4 -14
  391. package/lib/chevre/service/task/aggregateScreeningEvent.js +3 -12
  392. package/lib/chevre/service/task/authorizePayment.js +9 -15
  393. package/lib/chevre/service/task/cancelMoneyTransfer.js +3 -12
  394. package/lib/chevre/service/task/cancelPendingReservation.js +10 -20
  395. package/lib/chevre/service/task/cancelReservation.js +3 -12
  396. package/lib/chevre/service/task/checkMovieTicket.js +16 -19
  397. package/lib/chevre/service/task/checkResource.js +7 -16
  398. package/lib/chevre/service/task/confirmMoneyTransfer.js +3 -12
  399. package/lib/chevre/service/task/confirmPayTransaction.js +6 -12
  400. package/lib/chevre/service/task/confirmRegisterService.js +3 -12
  401. package/lib/chevre/service/task/confirmRegisterServiceTransaction.js +24 -31
  402. package/lib/chevre/service/task/confirmReserveTransaction.js +48 -42
  403. package/lib/chevre/service/task/createAccountingReport.js +14 -20
  404. package/lib/chevre/service/task/deletePerson.js +48 -58
  405. package/lib/chevre/service/task/deleteTransaction.js +3 -12
  406. package/lib/chevre/service/task/givePointAward.js +3 -12
  407. package/lib/chevre/service/task/handleNotification.js +4 -14
  408. package/lib/chevre/service/task/importEventCapacitiesFromCOA.js +6 -16
  409. package/lib/chevre/service/task/importEventsFromCOA.js +6 -16
  410. package/lib/chevre/service/task/importOffersFromCOA.js +8 -18
  411. package/lib/chevre/service/task/invalidatePaymentUrl.js +6 -12
  412. package/lib/chevre/service/task/moneyTransfer.js +3 -12
  413. package/lib/chevre/service/task/onAssetTransactionStatusChanged.js +3 -12
  414. package/lib/chevre/service/task/onAuthorizationCreated.js +11 -18
  415. package/lib/chevre/service/task/onEventChanged.js +3 -12
  416. package/lib/chevre/service/task/onOrderPaymentCompleted.js +3 -12
  417. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByAggregateOffer.js +7 -16
  418. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByEventSeries.js +7 -16
  419. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByMovieTheater.js +8 -17
  420. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByOfferCatalog.js +10 -19
  421. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByProduct.js +8 -17
  422. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByRoom.js +6 -15
  423. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesBySeller.js +14 -23
  424. package/lib/chevre/service/task/onResourceDeleted.js +17 -26
  425. package/lib/chevre/service/task/onResourceUpdated/onAggregateOfferUpdated.js +9 -21
  426. package/lib/chevre/service/task/onResourceUpdated/onCategoryCodeUpdated.js +3 -12
  427. package/lib/chevre/service/task/onResourceUpdated/onHasPOSUpdated.js +11 -23
  428. package/lib/chevre/service/task/onResourceUpdated/onOfferCatalogUpdated.js +13 -25
  429. package/lib/chevre/service/task/onResourceUpdated/syncCategoryCode.js +9 -15
  430. package/lib/chevre/service/task/onResourceUpdated/syncOfferCatalog.js +21 -27
  431. package/lib/chevre/service/task/onResourceUpdated.js +113 -153
  432. package/lib/chevre/service/task/pay.js +8 -16
  433. package/lib/chevre/service/task/payment/invalidatePaymentUrlByTask.js +4 -14
  434. package/lib/chevre/service/task/payment/payByTask.js +49 -38
  435. package/lib/chevre/service/task/payment/refundByTask.js +7 -17
  436. package/lib/chevre/service/task/payment/voidPaymentByTask.js +6 -15
  437. package/lib/chevre/service/task/placeOrder.js +6 -12
  438. package/lib/chevre/service/task/publishPaymentUrl.js +9 -14
  439. package/lib/chevre/service/task/refund.js +8 -16
  440. package/lib/chevre/service/task/registerService.js +3 -12
  441. package/lib/chevre/service/task/reserve.js +3 -12
  442. package/lib/chevre/service/task/returnMoneyTransfer.js +3 -12
  443. package/lib/chevre/service/task/returnOrder.js +6 -12
  444. package/lib/chevre/service/task/returnPayTransaction.js +54 -48
  445. package/lib/chevre/service/task/returnPointAward.js +3 -12
  446. package/lib/chevre/service/task/returnReserveTransaction.js +29 -30
  447. package/lib/chevre/service/task/sendEmailMessage.js +6 -13
  448. package/lib/chevre/service/task/sendOrder.js +12 -15
  449. package/lib/chevre/service/task/syncResourcesFromCOA.js +39 -40
  450. package/lib/chevre/service/task/triggerWebhook.js +6 -12
  451. package/lib/chevre/service/task/useReservation.js +11 -14
  452. package/lib/chevre/service/task/voidMoneyTransferTransaction.js +3 -12
  453. package/lib/chevre/service/task/voidPayTransaction.js +7 -12
  454. package/lib/chevre/service/task/voidPayment.js +3 -12
  455. package/lib/chevre/service/task/voidRegisterServiceTransaction.js +3 -12
  456. package/lib/chevre/service/task/voidReserveTransaction.js +10 -16
  457. package/lib/chevre/service/task.js +16 -22
  458. package/lib/chevre/service/taskHandler/onOperationFailed/informTaskIfNeeded.js +9 -20
  459. package/lib/chevre/service/taskHandler/onOperationFailed.js +20 -17
  460. package/lib/chevre/service/taskHandler.js +19 -21
  461. package/lib/chevre/service/transaction/deleteTransaction.js +104 -84
  462. package/lib/chevre/service/transaction/moneyTransfer/exportTasks/factory.js +15 -6
  463. package/lib/chevre/service/transaction/moneyTransfer/factory.js +13 -4
  464. package/lib/chevre/service/transaction/moneyTransfer/potentialActions.js +12 -24
  465. package/lib/chevre/service/transaction/moneyTransfer.js +119 -96
  466. package/lib/chevre/service/transaction/placeOrder/confirm/potentialActions/sendEmailMessage.js +49 -51
  467. package/lib/chevre/service/transaction/placeOrder/confirm/potentialActions.js +14 -25
  468. package/lib/chevre/service/transaction/placeOrder/confirm/publishCode.js +4 -14
  469. package/lib/chevre/service/transaction/placeOrder/confirm/validation/validateInvoiceReferencesOrder.js +3 -4
  470. package/lib/chevre/service/transaction/placeOrder/confirm/validation/validateMovieTicket.js +3 -4
  471. package/lib/chevre/service/transaction/placeOrder/confirm/validation/validatePrice.js +2 -3
  472. package/lib/chevre/service/transaction/placeOrder/confirm/validation.js +30 -45
  473. package/lib/chevre/service/transaction/placeOrder/confirm.js +75 -55
  474. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +31 -13
  475. package/lib/chevre/service/transaction/placeOrder/exportTasksById.js +6 -15
  476. package/lib/chevre/service/transaction/placeOrder/publishConfirmationNumberIfNotExist.js +6 -15
  477. package/lib/chevre/service/transaction/placeOrder/publishOrderNumberIfNotExist.js +7 -16
  478. package/lib/chevre/service/transaction/placeOrder/start/factory.js +27 -7
  479. package/lib/chevre/service/transaction/placeOrder/start/validateStartRequest.js +53 -59
  480. package/lib/chevre/service/transaction/placeOrder/start.js +14 -18
  481. package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.js +13 -6
  482. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPaymentMethod.js +176 -190
  483. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPointAward.js +77 -89
  484. package/lib/chevre/service/transaction/returnOrder/potentialActions/sendEmailMessage.js +40 -48
  485. package/lib/chevre/service/transaction/returnOrder/potentialActions.js +52 -56
  486. package/lib/chevre/service/transaction/returnOrder/preStart/findApplicableReturnPolicy.js +100 -102
  487. package/lib/chevre/service/transaction/returnOrder/preStart/getReturnPolicyByProject.js +60 -80
  488. package/lib/chevre/service/transaction/returnOrder/preStart.js +42 -46
  489. package/lib/chevre/service/transaction/returnOrder.js +32 -36
  490. package/lib/chevre/service/transaction.js +75 -46
  491. package/lib/chevre/service/validation/validateEvent.js +2 -11
  492. package/lib/chevre/service/validation/validateOrder.js +7 -16
  493. package/lib/chevre/service.js +85 -128
  494. package/lib/chevre/settings/aggregation.js +4 -0
  495. package/lib/chevre/settings.js +7 -0
  496. package/package.json +8 -11
  497. package/example/src/chevre/addEventBySchedule.ts +0 -46
  498. package/example/src/chevre/orderNumber/decryptOrderNumber.ts +0 -14
  499. package/example/src/idaas/auth0/adminApplications.ts +0 -183
  500. package/example/src/idaas/auth0/getToken.ts +0 -55
  501. package/example/src/idaas/auth0/getTokenByPrivateKeyJWT.ts +0 -84
  502. package/lib/chevre/service/task/createEvent/createEvent.d.ts +0 -25
  503. package/lib/chevre/service/task/createEvent/createEvent.js +0 -45
  504. package/lib/chevre/service/task/createEvent/createEventBySchedule/factory.d.ts +0 -22
  505. package/lib/chevre/service/task/createEvent/createEventBySchedule/factory.js +0 -190
  506. package/lib/chevre/service/task/createEvent/createEventBySchedule/schedule2events.d.ts +0 -15
  507. package/lib/chevre/service/task/createEvent/createEventBySchedule/schedule2events.js +0 -118
  508. package/lib/chevre/service/task/createEvent/createEventBySchedule.d.ts +0 -25
  509. package/lib/chevre/service/task/createEvent/createEventBySchedule.js +0 -107
  510. package/lib/chevre/service/task/createEvent/createEventSeries.d.ts +0 -13
  511. package/lib/chevre/service/task/createEvent/createEventSeries.js +0 -118
  512. package/lib/chevre/service/task/createEvent.d.ts +0 -6
  513. package/lib/chevre/service/task/createEvent.js +0 -46
@@ -1,24 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
2
  Object.defineProperty(exports, "__esModule", { value: true });
23
3
  exports.TaskRepo = void 0;
24
4
  const moment = require("moment");
@@ -69,18 +49,18 @@ const AVAILABLE_PROJECT_FIELDS = [
69
49
  * タスクリポジトリ
70
50
  */
71
51
  class TaskRepo {
52
+ taskModel;
72
53
  constructor(connection) {
73
54
  this.taskModel = connection.model(task_2.modelName, (0, task_2.createSchema)());
74
55
  }
75
56
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
76
57
  static CREATE_MONGO_CONDITIONS(params) {
77
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
78
58
  const andConditions = [];
79
- const idEq = (_a = params.id) === null || _a === void 0 ? void 0 : _a.$eq;
59
+ const idEq = params.id?.$eq;
80
60
  if (typeof idEq === 'string') {
81
61
  andConditions.push({ _id: { $eq: idEq } });
82
62
  }
83
- const projectIdEq = (_c = (_b = params.project) === null || _b === void 0 ? void 0 : _b.id) === null || _c === void 0 ? void 0 : _c.$eq;
63
+ const projectIdEq = params.project?.id?.$eq;
84
64
  if (typeof projectIdEq === 'string') {
85
65
  andConditions.push({ 'project.id': { $eq: projectIdEq } });
86
66
  }
@@ -88,16 +68,16 @@ class TaskRepo {
88
68
  andConditions.push({ name: { $eq: params.name } });
89
69
  }
90
70
  else {
91
- const nameIn = (_d = params.name) === null || _d === void 0 ? void 0 : _d.$in;
71
+ const nameIn = params.name?.$in;
92
72
  if (Array.isArray(nameIn)) {
93
73
  andConditions.push({ name: { $in: nameIn } });
94
74
  }
95
- const nameNin = (_e = params.name) === null || _e === void 0 ? void 0 : _e.$nin;
75
+ const nameNin = params.name?.$nin;
96
76
  if (Array.isArray(nameNin)) {
97
77
  andConditions.push({ name: { $nin: nameNin } });
98
78
  }
99
79
  }
100
- const statusEq = (_f = params.status) === null || _f === void 0 ? void 0 : _f.$eq;
80
+ const statusEq = params.status?.$eq;
101
81
  if (typeof statusEq === 'string') {
102
82
  andConditions.push({ status: { $eq: statusEq } });
103
83
  }
@@ -116,206 +96,170 @@ class TaskRepo {
116
96
  if (params.lastTriedThrough instanceof Date) {
117
97
  andConditions.push({ lastTriedAt: { $type: 'date', $lte: params.lastTriedThrough } });
118
98
  }
119
- const dateAbortedGte = (_g = params.dateAborted) === null || _g === void 0 ? void 0 : _g.$gte;
99
+ const dateAbortedGte = params.dateAborted?.$gte;
120
100
  if (dateAbortedGte instanceof Date) {
121
101
  andConditions.push({ dateAborted: { $type: 'date', $gte: dateAbortedGte } });
122
102
  }
123
- const dateAbortedLte = (_h = params.dateAborted) === null || _h === void 0 ? void 0 : _h.$lte;
103
+ const dateAbortedLte = params.dateAborted?.$lte;
124
104
  if (dateAbortedLte instanceof Date) {
125
105
  andConditions.push({ dateAborted: { $type: 'date', $lte: dateAbortedLte } });
126
106
  }
127
- const objectIdEq = (_l = (_k = (_j = params.data) === null || _j === void 0 ? void 0 : _j.object) === null || _k === void 0 ? void 0 : _k.id) === null || _l === void 0 ? void 0 : _l.$eq;
107
+ const objectIdEq = params.data?.object?.id?.$eq;
128
108
  if (typeof objectIdEq === 'string') {
129
109
  andConditions.push({ 'data.object.id': { $exists: true, $eq: objectIdEq } });
130
110
  }
131
- const objectOrderNumberEq = (_p = (_o = (_m = params.data) === null || _m === void 0 ? void 0 : _m.object) === null || _o === void 0 ? void 0 : _o.orderNumber) === null || _p === void 0 ? void 0 : _p.$eq;
111
+ const objectOrderNumberEq = params.data?.object?.orderNumber?.$eq;
132
112
  if (typeof objectOrderNumberEq === 'string') {
133
113
  andConditions.push({ 'data.object.orderNumber': { $exists: true, $eq: objectOrderNumberEq } });
134
114
  }
135
- const objectTransactionNumberEq = (_s = (_r = (_q = params.data) === null || _q === void 0 ? void 0 : _q.object) === null || _r === void 0 ? void 0 : _r.transactionNumber) === null || _s === void 0 ? void 0 : _s.$eq;
115
+ const objectTransactionNumberEq = params.data?.object?.transactionNumber?.$eq;
136
116
  if (typeof objectTransactionNumberEq === 'string') {
137
117
  andConditions.push({ 'data.object.transactionNumber': { $exists: true, $eq: objectTransactionNumberEq } });
138
118
  }
139
- const objectPurposeIdEq = (_v = (_u = (_t = params.data) === null || _t === void 0 ? void 0 : _t.purpose) === null || _u === void 0 ? void 0 : _u.id) === null || _v === void 0 ? void 0 : _v.$eq;
119
+ const objectPurposeIdEq = params.data?.purpose?.id?.$eq;
140
120
  if (typeof objectPurposeIdEq === 'string') {
141
121
  andConditions.push({ 'data.purpose.id': { $exists: true, $eq: objectPurposeIdEq } });
142
122
  }
143
- const objectPurposeOrderNumberEq = (_y = (_x = (_w = params.data) === null || _w === void 0 ? void 0 : _w.purpose) === null || _x === void 0 ? void 0 : _x.orderNumber) === null || _y === void 0 ? void 0 : _y.$eq;
123
+ const objectPurposeOrderNumberEq = params.data?.purpose?.orderNumber?.$eq;
144
124
  if (typeof objectPurposeOrderNumberEq === 'string') {
145
125
  andConditions.push({ 'data.purpose.orderNumber': { $exists: true, $eq: objectPurposeOrderNumberEq } });
146
126
  }
147
- const alternateNameRegex = (_z = params.alternateName) === null || _z === void 0 ? void 0 : _z.$regex;
127
+ const alternateNameRegex = params.alternateName?.$regex;
148
128
  if (typeof alternateNameRegex === 'string' && alternateNameRegex.length > 0) {
149
129
  andConditions.push({ alternateName: { $exists: true, $regex: new RegExp(alternateNameRegex) } });
150
130
  }
151
- const identifierRegex = (_0 = params.identifier) === null || _0 === void 0 ? void 0 : _0.$regex;
131
+ const identifierRegex = params.identifier?.$regex;
152
132
  if (typeof identifierRegex === 'string' && identifierRegex.length > 0) {
153
133
  andConditions.push({ identifier: { $exists: true, $regex: new RegExp(identifierRegex) } });
154
134
  }
155
135
  return andConditions;
156
136
  }
157
- runImmediately(
137
+ async runImmediately(
158
138
  // resolve uniqueness of identifier(2025-03-27~)
159
139
  params,
160
140
  // support customr function(2025-05-25~)
161
141
  next) {
162
- return __awaiter(this, void 0, void 0, function* () {
163
- var _a, _b;
164
- const { expires } = params;
165
- if (!(expires instanceof Date)) {
166
- throw new factory.errors.Argument('expires', 'must be Date');
167
- }
168
- const savingTask = Object.assign(Object.assign({}, params), { status: factory.taskStatus.Ready, numberOfTried: 0, executionResults: [] });
169
- const result = yield this.taskModel.insertMany(savingTask, { rawResult: true });
170
- const id = (_b = (_a = result.insertedIds) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.toHexString();
171
- if (typeof id !== 'string') {
172
- throw new factory.errors.Internal('task not saved');
173
- }
174
- task_1.taskEventEmitter.emitTaskStatusChanged({
175
- id,
176
- status: factory.taskStatus.Ready,
177
- expires // emit expires(2025-03-31~)
178
- }, next);
179
- return { id };
180
- });
142
+ const { expires } = params;
143
+ if (!(expires instanceof Date)) {
144
+ throw new factory.errors.Argument('expires', 'must be Date');
145
+ }
146
+ const savingTask = {
147
+ ...params,
148
+ status: factory.taskStatus.Ready,
149
+ numberOfTried: 0,
150
+ executionResults: []
151
+ };
152
+ const result = await this.taskModel.insertMany(savingTask, { rawResult: true });
153
+ const id = result.insertedIds?.[0]?.toHexString();
154
+ if (typeof id !== 'string') {
155
+ throw new factory.errors.Internal('task not saved');
156
+ }
157
+ task_1.taskEventEmitter.emitTaskStatusChanged({
158
+ id,
159
+ status: factory.taskStatus.Ready,
160
+ expires // emit expires(2025-03-31~)
161
+ }, next);
162
+ return { id };
181
163
  }
182
- saveMany(taskAttributes, options) {
183
- return __awaiter(this, void 0, void 0, function* () {
184
- const emitImmediately = (options === null || options === void 0 ? void 0 : options.emitImmediately) === true;
185
- if (taskAttributes.length > 0) {
186
- // resolve uniqueness of identifier(2025-03-27~)
187
- const creatingTasks = taskAttributes.map((_a) => {
188
- var { identifier } = _a, creatingTask = __rest(_a, ["identifier"]);
189
- return creatingTask;
190
- });
191
- const result = yield this.taskModel.insertMany(creatingTasks, { ordered: false, rawResult: true });
192
- if (result.insertedCount !== taskAttributes.length) {
193
- throw new factory.errors.Internal('all tasks not saved');
194
- }
195
- const savedTasks = Object.values(result.insertedIds)
196
- .map((objectId) => {
197
- return { id: objectId.toHexString() };
198
- });
199
- if (emitImmediately) {
200
- savedTasks.forEach((savedTask) => {
201
- task_1.taskEventEmitter.emitTaskStatusChanged({
202
- id: savedTask.id,
203
- status: factory.taskStatus.Ready
204
- });
164
+ async saveMany(taskAttributes, options) {
165
+ const emitImmediately = options?.emitImmediately === true;
166
+ if (taskAttributes.length > 0) {
167
+ // resolve uniqueness of identifier(2025-03-27~)
168
+ const creatingTasks = taskAttributes.map(({ identifier, ...creatingTask }) => creatingTask);
169
+ const result = await this.taskModel.insertMany(creatingTasks, { ordered: false, rawResult: true });
170
+ if (result.insertedCount !== taskAttributes.length) {
171
+ throw new factory.errors.Internal('all tasks not saved');
172
+ }
173
+ const savedTasks = Object.values(result.insertedIds)
174
+ .map((objectId) => {
175
+ return { id: objectId.toHexString() };
176
+ });
177
+ if (emitImmediately) {
178
+ savedTasks.forEach((savedTask) => {
179
+ task_1.taskEventEmitter.emitTaskStatusChanged({
180
+ id: savedTask.id,
181
+ status: factory.taskStatus.Ready
205
182
  });
206
- // taskAttributes.forEach((savedTask) => {
207
- // taskEventEmitter.emitTaskStatusChanged({
208
- // name: savedTask.name,
209
- // status: factory.taskStatus.Ready
210
- // });
211
- // });
212
- }
213
- // return result.ops;
214
- return savedTasks;
215
- }
216
- else {
217
- return [];
218
- }
219
- });
183
+ });
184
+ // taskAttributes.forEach((savedTask) => {
185
+ // taskEventEmitter.emitTaskStatusChanged({
186
+ // name: savedTask.name,
187
+ // status: factory.taskStatus.Ready
188
+ // });
189
+ // });
190
+ }
191
+ // return result.ops;
192
+ return savedTasks;
193
+ }
194
+ else {
195
+ return [];
196
+ }
220
197
  }
221
198
  /**
222
199
  * タスク識別子から検索する
223
200
  */
224
- findByIdentifier(params) {
225
- return __awaiter(this, void 0, void 0, function* () {
226
- const projection = {
227
- _id: 0,
228
- id: { $toString: '$_id' },
229
- status: 1
230
- };
231
- const doc = yield this.taskModel.findOne({
232
- 'project.id': { $eq: params.project.id },
233
- name: { $eq: params.name },
234
- identifier: { $exists: true, $eq: params.identifier }
235
- }, projection)
236
- .lean() // lean(2024-09-26~)
237
- .exec();
238
- if (doc === null) {
239
- return;
240
- }
241
- const { id, status } = doc;
242
- return { id, status };
243
- });
201
+ async findByIdentifier(params) {
202
+ const projection = {
203
+ _id: 0,
204
+ id: { $toString: '$_id' },
205
+ status: 1
206
+ };
207
+ const doc = await this.taskModel.findOne({
208
+ 'project.id': { $eq: params.project.id },
209
+ name: { $eq: params.name },
210
+ identifier: { $exists: true, $eq: params.identifier }
211
+ }, projection)
212
+ .lean() // lean(2024-09-26~)
213
+ .exec();
214
+ if (doc === null) {
215
+ return;
216
+ }
217
+ const { id, status } = doc;
218
+ return { id, status };
244
219
  }
245
220
  /**
246
221
  * タスク識別子から冪等作成する
247
222
  * reimplement createIfNotExistByIdentifier(2025-03-28~)
248
223
  */
249
- createIfNotExistByAlternateName(params, options) {
250
- return __awaiter(this, void 0, void 0, function* () {
251
- if (typeof params.alternateName !== 'string' || params.alternateName.length === 0) {
252
- throw new factory.errors.ArgumentNull('alternateName');
253
- }
254
- let createdTask;
255
- const filterQuery = {
256
- 'project.id': { $eq: params.project.id },
257
- name: { $eq: params.name },
258
- alternateName: { $exists: true, $eq: params.alternateName }
259
- };
260
- const projection = {
261
- _id: 0,
262
- id: { $toString: '$_id' }
263
- };
264
- try {
265
- createdTask = yield this.taskModel.findOneAndUpdate(filterQuery, { $setOnInsert: params }, {
266
- new: true,
267
- upsert: true,
268
- projection
269
- })
270
- .lean()
271
- .exec();
272
- }
273
- catch (error) {
274
- let throwsError = true;
275
- if (yield (0, errorHandler_1.isMongoError)(error)) {
276
- // すでにalternateNameが存在する場合ok
277
- if (error.code === errorHandler_1.MongoErrorCode.DuplicateKey) {
278
- throwsError = false;
279
- createdTask = yield this.taskModel.findOne(filterQuery, projection)
280
- .lean()
281
- .exec();
282
- }
283
- }
284
- if (throwsError) {
285
- throw error;
286
- }
287
- }
288
- if (typeof (createdTask === null || createdTask === void 0 ? void 0 : createdTask.id) === 'string') {
289
- if (options.emitImmediately) {
290
- task_1.taskEventEmitter.emitTaskStatusChanged({
291
- id: createdTask.id,
292
- name: params.name,
293
- status: factory.taskStatus.Ready
294
- });
224
+ async createIfNotExistByAlternateName(params, options) {
225
+ if (typeof params.alternateName !== 'string' || params.alternateName.length === 0) {
226
+ throw new factory.errors.ArgumentNull('alternateName');
227
+ }
228
+ let createdTask;
229
+ const filterQuery = {
230
+ 'project.id': { $eq: params.project.id },
231
+ name: { $eq: params.name },
232
+ alternateName: { $exists: true, $eq: params.alternateName }
233
+ };
234
+ const projection = {
235
+ _id: 0,
236
+ id: { $toString: '$_id' }
237
+ };
238
+ try {
239
+ createdTask = await this.taskModel.findOneAndUpdate(filterQuery, { $setOnInsert: params }, {
240
+ new: true,
241
+ upsert: true,
242
+ projection
243
+ })
244
+ .lean()
245
+ .exec();
246
+ }
247
+ catch (error) {
248
+ let throwsError = true;
249
+ if (await (0, errorHandler_1.isMongoError)(error)) {
250
+ // すでにalternateNameが存在する場合ok
251
+ if (error.code === errorHandler_1.MongoErrorCode.DuplicateKey) {
252
+ throwsError = false;
253
+ createdTask = await this.taskModel.findOne(filterQuery, projection)
254
+ .lean()
255
+ .exec();
295
256
  }
296
257
  }
297
- else {
298
- throw new factory.errors.Internal(`falied in creating a task unexpectedly. ${params.alternateName}`);
299
- }
300
- });
301
- }
302
- /**
303
- * 取引削除タスク冪等作成
304
- */
305
- createDeleteTransactionTaskIfNotExist(
306
- // resolve uniqueness of identifier(2025-03-27~)
307
- params, options) {
308
- return __awaiter(this, void 0, void 0, function* () {
309
- if (params.data.object.specifyingMethod !== factory.action.update.deleteAction.ObjectAsTransactionSpecifyingMethod.Id) {
310
- throw new factory.errors.NotImplemented(`only ${factory.action.update.deleteAction.ObjectAsTransactionSpecifyingMethod.Id} implemented`);
258
+ if (throwsError) {
259
+ throw error;
311
260
  }
312
- const createdTask = yield this.taskModel.findOneAndUpdate({
313
- 'project.id': { $eq: params.project.id },
314
- name: { $eq: params.name },
315
- 'data.object.id': { $exists: true, $eq: params.data.object.id }
316
- }, { $setOnInsert: params }, { new: true, upsert: true })
317
- .select({ _id: 1 })
318
- .exec();
261
+ }
262
+ if (typeof createdTask?.id === 'string') {
319
263
  if (options.emitImmediately) {
320
264
  task_1.taskEventEmitter.emitTaskStatusChanged({
321
265
  id: createdTask.id,
@@ -323,157 +267,204 @@ class TaskRepo {
323
267
  status: factory.taskStatus.Ready
324
268
  });
325
269
  }
326
- });
270
+ }
271
+ else {
272
+ throw new factory.errors.Internal(`falied in creating a task unexpectedly. ${params.alternateName}`);
273
+ }
274
+ }
275
+ /**
276
+ * 取引削除タスク冪等作成
277
+ */
278
+ async createDeleteTransactionTaskIfNotExist(
279
+ // resolve uniqueness of identifier(2025-03-27~)
280
+ params, options) {
281
+ if (params.data.object.specifyingMethod !== factory.action.update.deleteAction.ObjectAsTransactionSpecifyingMethod.Id) {
282
+ throw new factory.errors.NotImplemented(`only ${factory.action.update.deleteAction.ObjectAsTransactionSpecifyingMethod.Id} implemented`);
283
+ }
284
+ const createdTask = await this.taskModel.findOneAndUpdate({
285
+ 'project.id': { $eq: params.project.id },
286
+ name: { $eq: params.name },
287
+ 'data.object.id': { $exists: true, $eq: params.data.object.id }
288
+ }, { $setOnInsert: params }, { new: true, upsert: true })
289
+ .select({ _id: 1 })
290
+ .exec();
291
+ if (options.emitImmediately) {
292
+ task_1.taskEventEmitter.emitTaskStatusChanged({
293
+ id: createdTask.id,
294
+ name: params.name,
295
+ status: factory.taskStatus.Ready
296
+ });
297
+ }
327
298
  }
328
- createOnAssetTransactionStatusChangedTaskIfNotExist(
299
+ async createOnAssetTransactionStatusChangedTaskIfNotExist(
329
300
  // resolve uniqueness of identifier(2025-03-27~)
330
301
  params, options) {
331
- return __awaiter(this, void 0, void 0, function* () {
332
- const createdTask = yield this.taskModel.findOneAndUpdate({
333
- 'project.id': { $eq: params.project.id },
334
- name: { $eq: params.name },
335
- 'data.object.transactionNumber': {
336
- $exists: true,
337
- $eq: String(params.data.object.transactionNumber)
338
- },
339
- 'data.purpose.orderNumber': {
340
- $exists: true,
341
- $eq: String(params.data.purpose.orderNumber)
342
- }
343
- }, { $setOnInsert: params }, { new: true, upsert: true })
344
- .select({ _id: 1 })
345
- .exec();
346
- if (options.emitImmediately) {
347
- task_1.taskEventEmitter.emitTaskStatusChanged({
348
- id: createdTask.id,
349
- name: params.name,
350
- status: factory.taskStatus.Ready
351
- });
352
- }
353
- });
302
+ const createdTask = await this.taskModel.findOneAndUpdate({
303
+ 'project.id': { $eq: params.project.id },
304
+ name: { $eq: params.name },
305
+ 'data.object.transactionNumber': {
306
+ $exists: true,
307
+ $eq: String(params.data.object.transactionNumber)
308
+ },
309
+ 'data.purpose.orderNumber': {
310
+ $exists: true,
311
+ $eq: String(params.data.purpose.orderNumber)
312
+ }
313
+ }, { $setOnInsert: params }, { new: true, upsert: true })
314
+ .select({ _id: 1 })
315
+ .exec();
316
+ if (options.emitImmediately) {
317
+ task_1.taskEventEmitter.emitTaskStatusChanged({
318
+ id: createdTask.id,
319
+ name: params.name,
320
+ status: factory.taskStatus.Ready
321
+ });
322
+ }
354
323
  }
355
324
  /**
356
325
  * Ready -> remainingNumberOfTriesが1減る
357
326
  * Running -> findOneするだけ
358
327
  */
359
- executeOneById(params) {
360
- return __awaiter(this, void 0, void 0, function* () {
361
- const now = new Date();
362
- let doc;
363
- if (params.status === factory.taskStatus.Running) {
364
- doc = yield this.taskModel.findOne(Object.assign({ _id: { $eq: params.id }, status: { $eq: params.status }, runsAt: { $lt: now } }, (params.expires instanceof Date) ? { expires: { $gt: now } } : undefined), executableTaskProjection)
365
- .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
366
- .lean()
367
- .exec();
368
- }
369
- else {
370
- doc = yield this.taskModel.findOneAndUpdate(Object.assign({ _id: { $eq: params.id }, status: { $eq: params.status }, runsAt: { $lt: now } }, (params.expires instanceof Date) ? { expires: { $gt: now } } : undefined), {
371
- $set: {
372
- status: factory.taskStatus.Running, // 実行中に変更
373
- lastTriedAt: now,
374
- executor: params.executor
375
- },
376
- $inc: {
377
- remainingNumberOfTries: -1, // 残りトライ可能回数減らす
378
- numberOfTried: 1 // トライ回数増やす
379
- }
380
- }, { new: true, projection: executableTaskProjection })
381
- .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
382
- .lean() // lean(2024-09-26~)
383
- .exec();
384
- }
385
- if (doc === null) {
386
- // tslint:disable-next-line:no-null-keyword
387
- return null;
388
- }
389
- return doc;
390
- });
391
- }
392
- /**
393
- * Readyのタスクをname指定でひとつRunningに変更する
394
- */
395
- executeOneIfExists(params) {
396
- return __awaiter(this, void 0, void 0, function* () {
397
- var _a;
398
- if (!(params.runsAt.$lt instanceof Date)) {
399
- throw new factory.errors.Argument('runsAt.$lt', 'must be Date');
400
- }
401
- const nameEq = (_a = params.name) === null || _a === void 0 ? void 0 : _a.$eq;
402
- // const nameNin = params.name?.$nin;
403
- const doc = yield this.taskModel.findOneAndUpdate(Object.assign({ status: { $eq: factory.taskStatus.Ready }, runsAt: { $lt: params.runsAt.$lt } }, (typeof nameEq === 'string')
404
- ? {
405
- name: Object.assign({}, (typeof nameEq === 'string') ? { $eq: nameEq } : undefined
406
- // ...(Array.isArray(nameNin)) ? { $nin: nameNin } : undefined
407
- )
408
- }
409
- : undefined), {
328
+ async executeOneById(params) {
329
+ const now = new Date();
330
+ let doc;
331
+ if (params.status === factory.taskStatus.Running) {
332
+ doc = await this.taskModel.findOne({
333
+ _id: { $eq: params.id },
334
+ status: { $eq: params.status },
335
+ runsAt: { $lt: now },
336
+ ...(params.expires instanceof Date) ? { expires: { $gt: now } } : undefined
337
+ }, executableTaskProjection)
338
+ .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
339
+ .lean()
340
+ .exec();
341
+ }
342
+ else {
343
+ doc = await this.taskModel.findOneAndUpdate({
344
+ _id: { $eq: params.id },
345
+ status: { $eq: params.status },
346
+ runsAt: { $lt: now },
347
+ ...(params.expires instanceof Date) ? { expires: { $gt: now } } : undefined
348
+ }, {
410
349
  $set: {
411
350
  status: factory.taskStatus.Running, // 実行中に変更
412
- lastTriedAt: new Date(),
351
+ lastTriedAt: now,
413
352
  executor: params.executor
414
353
  },
415
354
  $inc: {
416
355
  remainingNumberOfTries: -1, // 残りトライ可能回数減らす
417
356
  numberOfTried: 1 // トライ回数増やす
418
357
  }
419
- }, Object.assign({ new: true, projection: executableTaskProjection }, (typeof params.sort.numberOfTried === 'number' || typeof params.sort.runsAt === 'number')
420
- ? { sort: params.sort }
421
- : undefined))
358
+ }, { new: true, projection: executableTaskProjection })
422
359
  .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
423
360
  .lean() // lean(2024-09-26~)
424
361
  .exec();
425
- if (doc === null) {
426
- // tslint:disable-next-line:no-null-keyword
427
- return null;
428
- }
429
- return doc;
430
- });
362
+ }
363
+ if (doc === null) {
364
+ // tslint:disable-next-line:no-null-keyword
365
+ return null;
366
+ }
367
+ return doc;
368
+ }
369
+ /**
370
+ * Readyのタスクをname指定でひとつRunningに変更する
371
+ */
372
+ async executeOneIfExists(params) {
373
+ if (!(params.runsAt.$lt instanceof Date)) {
374
+ throw new factory.errors.Argument('runsAt.$lt', 'must be Date');
375
+ }
376
+ const nameEq = params.name?.$eq;
377
+ // const nameNin = params.name?.$nin;
378
+ const doc = await this.taskModel.findOneAndUpdate({
379
+ status: { $eq: factory.taskStatus.Ready },
380
+ runsAt: { $lt: params.runsAt.$lt },
381
+ ...(typeof nameEq === 'string')
382
+ ? {
383
+ name: {
384
+ ...(typeof nameEq === 'string') ? { $eq: nameEq } : undefined
385
+ // ...(Array.isArray(nameNin)) ? { $nin: nameNin } : undefined
386
+ }
387
+ }
388
+ : undefined
389
+ }, {
390
+ $set: {
391
+ status: factory.taskStatus.Running, // 実行中に変更
392
+ lastTriedAt: new Date(),
393
+ executor: params.executor
394
+ },
395
+ $inc: {
396
+ remainingNumberOfTries: -1, // 残りトライ可能回数減らす
397
+ numberOfTried: 1 // トライ回数増やす
398
+ }
399
+ }, {
400
+ new: true,
401
+ projection: executableTaskProjection,
402
+ ...(typeof params.sort.numberOfTried === 'number' || typeof params.sort.runsAt === 'number')
403
+ ? { sort: params.sort }
404
+ : undefined
405
+ })
406
+ .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
407
+ .lean() // lean(2024-09-26~)
408
+ .exec();
409
+ if (doc === null) {
410
+ // tslint:disable-next-line:no-null-keyword
411
+ return null;
412
+ }
413
+ return doc;
431
414
  }
432
415
  /**
433
416
  * add(2025-03-16~)
434
417
  */
435
- countPotentiallyRunning(params) {
436
- return __awaiter(this, void 0, void 0, function* () {
437
- const { runsAt, limit, name } = params;
438
- const nameEq = name === null || name === void 0 ? void 0 : name.$eq;
439
- // const nameNin = name?.$nin;
440
- const nameIn = name === null || name === void 0 ? void 0 : name.$in;
441
- if (!(runsAt.$lt instanceof Date)) {
442
- throw new factory.errors.Argument('runsAt.$lt', 'must be Date');
443
- }
444
- const query = this.taskModel.countDocuments(Object.assign({ status: { $eq: factory.taskStatus.Ready }, runsAt: { $lt: params.runsAt.$lt } }, (typeof nameEq === 'string' || Array.isArray(nameIn))
418
+ async countPotentiallyRunning(params) {
419
+ const { runsAt, limit, name } = params;
420
+ const nameEq = name?.$eq;
421
+ // const nameNin = name?.$nin;
422
+ const nameIn = name?.$in;
423
+ if (!(runsAt.$lt instanceof Date)) {
424
+ throw new factory.errors.Argument('runsAt.$lt', 'must be Date');
425
+ }
426
+ const query = this.taskModel.countDocuments({
427
+ status: { $eq: factory.taskStatus.Ready },
428
+ runsAt: { $lt: params.runsAt.$lt },
429
+ ...(typeof nameEq === 'string' || Array.isArray(nameIn))
445
430
  ? {
446
- name: Object.assign(Object.assign({}, (typeof nameEq === 'string') ? { $eq: nameEq } : undefined), (Array.isArray(nameIn)) ? { $in: nameIn } : undefined)
431
+ name: {
432
+ ...(typeof nameEq === 'string') ? { $eq: nameEq } : undefined,
433
+ // ...(Array.isArray(nameNin)) ? { $nin: nameNin } : undefined,
434
+ ...(Array.isArray(nameIn)) ? { $in: nameIn } : undefined
435
+ }
447
436
  }
448
- : undefined));
449
- if (typeof limit === 'number' && limit >= 0) {
450
- query.limit(limit);
451
- }
452
- const count = yield query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
453
- .exec();
454
- return { count };
437
+ : undefined
455
438
  });
439
+ if (typeof limit === 'number' && limit >= 0) {
440
+ query.limit(limit);
441
+ }
442
+ const count = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
443
+ .exec();
444
+ return { count };
456
445
  }
457
446
  /**
458
447
  * 実行日時を一定期間過ぎたReadyタスクについて、Runningスタータスに変更した上で、Runningイベントを発生させる
459
448
  */
460
- emitRunningIfExists(params, next // support next function(2025-08-02~)
449
+ async emitRunningIfExists(params, next // support next function(2025-08-02~)
461
450
  ) {
462
- return __awaiter(this, void 0, void 0, function* () {
463
- var _a;
464
- if (!(params.runsAt.$lt instanceof Date)) {
465
- throw new factory.errors.Argument('runsAt.$lt', 'must be Date');
466
- }
467
- const projection = {
468
- _id: 0,
469
- id: { $toString: '$_id' },
470
- name: 1
471
- };
472
- const nameEq = (_a = params.name) === null || _a === void 0 ? void 0 : _a.$eq;
473
- // const nameNin = params.name?.$nin;
474
- // const nameIn = params.name?.$in;
475
- const { nameFilterBeforeRunsAt } = params;
476
- const filter = Object.assign(Object.assign(Object.assign({ status: { $eq: factory.taskStatus.Ready } }, (nameFilterBeforeRunsAt) ? { name: params.name } : undefined), { runsAt: { $lt: params.runsAt.$lt } }), (!nameFilterBeforeRunsAt) ? { name: params.name } : undefined
451
+ if (!(params.runsAt.$lt instanceof Date)) {
452
+ throw new factory.errors.Argument('runsAt.$lt', 'must be Date');
453
+ }
454
+ const projection = {
455
+ _id: 0,
456
+ id: { $toString: '$_id' },
457
+ name: 1
458
+ };
459
+ const nameEq = params.name?.$eq;
460
+ // const nameNin = params.name?.$nin;
461
+ // const nameIn = params.name?.$in;
462
+ const { nameFilterBeforeRunsAt } = params;
463
+ const filter = {
464
+ status: { $eq: factory.taskStatus.Ready },
465
+ ...(nameFilterBeforeRunsAt) ? { name: params.name } : undefined,
466
+ runsAt: { $lt: params.runsAt.$lt },
467
+ ...(!nameFilterBeforeRunsAt) ? { name: params.name } : undefined
477
468
  // ...(typeof nameEq === 'string' || Array.isArray(nameIn))
478
469
  // ? {
479
470
  // name: {
@@ -483,109 +474,115 @@ class TaskRepo {
483
474
  // }
484
475
  // }
485
476
  // : undefined
486
- );
487
- const doc = yield this.taskModel.findOneAndUpdate(filter, {
488
- $set: {
489
- status: factory.taskStatus.Running, // 実行中に変更
490
- lastTriedAt: new Date(),
491
- executor: params.executor
492
- },
493
- $inc: {
494
- remainingNumberOfTries: -1, // 残りトライ可能回数減らす
495
- numberOfTried: 1 // トライ回数増やす
496
- }
497
- }, Object.assign({ new: true, projection }, (typeof params.sort.numberOfTried === 'number' || typeof params.sort.runsAt === 'number')
477
+ };
478
+ const doc = await this.taskModel.findOneAndUpdate(filter, {
479
+ $set: {
480
+ status: factory.taskStatus.Running, // 実行中に変更
481
+ lastTriedAt: new Date(),
482
+ executor: params.executor
483
+ },
484
+ $inc: {
485
+ remainingNumberOfTries: -1, // 残りトライ可能回数減らす
486
+ numberOfTried: 1 // トライ回数増やす
487
+ }
488
+ }, {
489
+ new: true,
490
+ projection,
491
+ ...(typeof params.sort.numberOfTried === 'number' || typeof params.sort.runsAt === 'number')
498
492
  ? { sort: params.sort }
499
- : undefined))
500
- .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
501
- .lean()
502
- .exec();
503
- if (doc === null) {
504
- // tslint:disable-next-line:no-null-keyword
505
- return null;
506
- }
507
- let changedTask;
508
- if (typeof nameEq === 'string') {
509
- changedTask = {
510
- id: doc.id,
511
- status: factory.taskStatus.Running,
512
- name: nameEq
513
- };
514
- }
515
- else {
516
- changedTask = {
517
- id: doc.id,
518
- status: factory.taskStatus.Running
519
- };
520
- }
521
- task_1.taskEventEmitter.emitTaskStatusChanged(changedTask, (typeof next === 'function') ? next : undefined);
522
- return doc;
523
- });
493
+ : undefined
494
+ })
495
+ .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
496
+ .lean()
497
+ .exec();
498
+ if (doc === null) {
499
+ // tslint:disable-next-line:no-null-keyword
500
+ return null;
501
+ }
502
+ let changedTask;
503
+ if (typeof nameEq === 'string') {
504
+ changedTask = {
505
+ id: doc.id,
506
+ status: factory.taskStatus.Running,
507
+ name: nameEq
508
+ };
509
+ }
510
+ else {
511
+ changedTask = {
512
+ id: doc.id,
513
+ status: factory.taskStatus.Running
514
+ };
515
+ }
516
+ task_1.taskEventEmitter.emitTaskStatusChanged(changedTask, (typeof next === 'function') ? next : undefined);
517
+ return doc;
524
518
  }
525
519
  /**
526
520
  * Readyのままで期限切れのタスクをExpiredに変更する
527
521
  */
528
- makeExpiredMany(params) {
529
- return __awaiter(this, void 0, void 0, function* () {
530
- const { expiresLt } = params;
531
- if (!(expiresLt instanceof Date)) {
532
- throw new factory.errors.Argument('expiresLt', 'must be Date');
533
- }
534
- return this.taskModel.updateMany({
535
- status: { $eq: factory.taskStatus.Ready },
536
- expires: { $exists: true, $lt: expiresLt }
537
- }, {
538
- $set: {
539
- status: factory.taskStatus.Expired
540
- }
541
- })
542
- .exec();
543
- });
522
+ async makeExpiredMany(params) {
523
+ const { expiresLt } = params;
524
+ if (!(expiresLt instanceof Date)) {
525
+ throw new factory.errors.Argument('expiresLt', 'must be Date');
526
+ }
527
+ return this.taskModel.updateMany({
528
+ status: { $eq: factory.taskStatus.Ready },
529
+ expires: { $exists: true, $lt: expiresLt }
530
+ }, {
531
+ $set: {
532
+ status: factory.taskStatus.Expired
533
+ }
534
+ })
535
+ .exec();
544
536
  }
545
537
  /**
546
538
  * Runningのまま一定期間超過し、かつ、remainingNumberOfTries>0のタスクをReadyに変更する
547
539
  */
548
- retryMany(params) {
549
- return __awaiter(this, void 0, void 0, function* () {
550
- const lastTriedAtShoudBeLessThan = moment()
551
- .add(-params.intervalInMinutes, 'minutes')
552
- .toDate();
553
- const remainingNumberOfTriesGte = params.remainingNumberOfTries.$gte;
554
- const remainingNumberOfTriesLte = params.remainingNumberOfTries.$lte;
555
- return this.taskModel.updateMany(Object.assign(Object.assign(Object.assign({ status: { $eq: factory.taskStatus.Running }, lastTriedAt: {
556
- $type: 'date',
557
- $lt: lastTriedAtShoudBeLessThan
558
- } }, (typeof remainingNumberOfTriesGte === 'number')
540
+ async retryMany(params) {
541
+ const lastTriedAtShoudBeLessThan = moment()
542
+ .add(-params.intervalInMinutes, 'minutes')
543
+ .toDate();
544
+ const remainingNumberOfTriesGte = params.remainingNumberOfTries.$gte;
545
+ const remainingNumberOfTriesLte = params.remainingNumberOfTries.$lte;
546
+ return this.taskModel.updateMany(
547
+ // name: 'retry'のindexと連動しているので、条件の順序などには注意すること
548
+ // @see schemas/task
549
+ {
550
+ status: { $eq: factory.taskStatus.Running },
551
+ lastTriedAt: {
552
+ $type: 'date',
553
+ $lt: lastTriedAtShoudBeLessThan
554
+ },
555
+ ...(typeof remainingNumberOfTriesGte === 'number')
559
556
  ? { remainingNumberOfTries: { $gte: remainingNumberOfTriesGte } }
560
- : undefined), (typeof remainingNumberOfTriesLte === 'number')
557
+ : undefined,
558
+ ...(typeof remainingNumberOfTriesLte === 'number')
561
559
  ? { remainingNumberOfTries: { $lte: remainingNumberOfTriesLte } }
562
- : undefined), (Array.isArray(params.name.$in)) ? { name: { $in: params.name.$in } } : undefined), {
563
- $set: {
564
- status: factory.taskStatus.Ready // 実行前に変更
565
- }
566
- })
567
- .exec();
568
- });
560
+ : undefined,
561
+ ...(Array.isArray(params.name.$in)) ? { name: { $in: params.name.$in } } : undefined
562
+ }, {
563
+ $set: {
564
+ status: factory.taskStatus.Ready // 実行前に変更
565
+ }
566
+ })
567
+ .exec();
569
568
  }
570
569
  /**
571
570
  * 実行中止済タスクを強制的にリトライ
572
571
  * 中止済タスクでなければ何もしない
573
572
  */
574
- retryForciblyIfAborted(params) {
575
- return __awaiter(this, void 0, void 0, function* () {
576
- return this.taskModel.updateOne({
577
- _id: { $eq: params.id },
578
- status: { $eq: factory.taskStatus.Aborted }
579
- }, {
580
- $set: {
581
- status: factory.taskStatus.Ready
582
- },
583
- $inc: {
584
- remainingNumberOfTries: params.remainingNumberOfTries
585
- }
586
- })
587
- .exec();
588
- });
573
+ async retryForciblyIfAborted(params) {
574
+ return this.taskModel.updateOne({
575
+ _id: { $eq: params.id },
576
+ status: { $eq: factory.taskStatus.Aborted }
577
+ }, {
578
+ $set: {
579
+ status: factory.taskStatus.Ready
580
+ },
581
+ $inc: {
582
+ remainingNumberOfTries: params.remainingNumberOfTries
583
+ }
584
+ })
585
+ .exec();
589
586
  }
590
587
  // public async abortOne(params: {
591
588
  // intervalInMinutes: number;
@@ -623,278 +620,279 @@ class TaskRepo {
623
620
  // }
624
621
  // return doc;
625
622
  // }
626
- abortMany(params) {
627
- return __awaiter(this, void 0, void 0, function* () {
628
- const lastTriedAtShoudBeLessThan = moment()
629
- .add(-params.intervalInMinutes, 'minutes')
630
- .toDate();
631
- return this.taskModel.updateMany(Object.assign({ status: { $eq: factory.taskStatus.Running }, lastTriedAt: {
632
- $type: 'date',
633
- $lt: lastTriedAtShoudBeLessThan
634
- }, remainingNumberOfTries: { $eq: 0 } }, (Array.isArray(params.name.$in)) ? { name: { $in: params.name.$in } } : undefined), {
635
- $set: {
636
- status: factory.taskStatus.Aborted,
637
- dateAborted: new Date()
638
- }
639
- })
640
- .exec();
641
- });
623
+ async abortMany(params) {
624
+ const lastTriedAtShoudBeLessThan = moment()
625
+ .add(-params.intervalInMinutes, 'minutes')
626
+ .toDate();
627
+ return this.taskModel.updateMany({
628
+ status: { $eq: factory.taskStatus.Running },
629
+ lastTriedAt: {
630
+ $type: 'date',
631
+ $lt: lastTriedAtShoudBeLessThan
632
+ },
633
+ remainingNumberOfTries: { $eq: 0 },
634
+ ...(Array.isArray(params.name.$in)) ? { name: { $in: params.name.$in } } : undefined
635
+ }, {
636
+ $set: {
637
+ status: factory.taskStatus.Aborted,
638
+ dateAborted: new Date()
639
+ }
640
+ })
641
+ .exec();
642
642
  }
643
643
  /**
644
644
  * タスクIDから実行結果とステータスを保管する
645
645
  * Abortedの場合、dateAbortedもセットする
646
646
  */
647
- setExecutionResultAndStatus(params, update,
647
+ async setExecutionResultAndStatus(params, update,
648
648
  // support customr function(2025-05-25~)
649
649
  next) {
650
- return __awaiter(this, void 0, void 0, function* () {
651
- const { id, remainingNumberOfTries, name } = params;
652
- const { status, executionResult } = update;
653
- yield this.taskModel.updateOne({ _id: { $eq: id } }, {
654
- $set: Object.assign({ status }, (status === factory.taskStatus.Aborted) ? { dateAborted: executionResult.endDate } : undefined // 2025-08-04~
655
- ),
656
- $push: { executionResults: executionResult }
657
- })
658
- .exec();
659
- // emit event(2025-05-26~)
660
- if (typeof next === 'function') {
661
- const changedTask = { id, name, status, remainingNumberOfTries, executionResult };
662
- task_1.taskEventEmitter.emitTaskStatusChanged(changedTask, next);
663
- }
664
- });
650
+ const { id, remainingNumberOfTries, name } = params;
651
+ const { status, executionResult } = update;
652
+ await this.taskModel.updateOne({ _id: { $eq: id } }, {
653
+ $set: {
654
+ status,
655
+ ...(status === factory.taskStatus.Aborted) ? { dateAborted: executionResult.endDate } : undefined // 2025-08-04~
656
+ },
657
+ $push: { executionResults: executionResult }
658
+ })
659
+ .exec();
660
+ // emit event(2025-05-26~)
661
+ if (typeof next === 'function') {
662
+ const changedTask = { id, name, status, remainingNumberOfTries, executionResult };
663
+ task_1.taskEventEmitter.emitTaskStatusChanged(changedTask, next);
664
+ }
665
665
  }
666
- count(params) {
667
- return __awaiter(this, void 0, void 0, function* () {
668
- const { limit } = params;
669
- const conditions = TaskRepo.CREATE_MONGO_CONDITIONS(params);
670
- const query = this.taskModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {});
671
- if (typeof limit === 'number' && limit >= 0) {
672
- query.limit(limit);
673
- }
674
- const count = yield query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
675
- .exec();
676
- return { count };
677
- });
666
+ async count(params) {
667
+ const { limit } = params;
668
+ const conditions = TaskRepo.CREATE_MONGO_CONDITIONS(params);
669
+ const query = this.taskModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {});
670
+ if (typeof limit === 'number' && limit >= 0) {
671
+ query.limit(limit);
672
+ }
673
+ const count = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
674
+ .exec();
675
+ return { count };
678
676
  }
679
677
  /**
680
678
  * 検索する
681
679
  */
682
- projectFields(params,
680
+ async projectFields(params,
683
681
  // projection?: IProjection
684
682
  inclusion) {
685
- return __awaiter(this, void 0, void 0, function* () {
686
- var _a;
687
- const conditions = TaskRepo.CREATE_MONGO_CONDITIONS(params);
688
- // const positiveProjectionExists: boolean = (projection !== undefined && projection !== null)
689
- // ? Object.values(projection)
690
- // .some((value) => value !== 0)
691
- // : false;
692
- let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
693
- if (Array.isArray(inclusion) && inclusion.length > 0) {
694
- positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
695
- }
696
- else {
697
- // no op
698
- }
699
- const projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1]))));
700
- const query = this.taskModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
701
- if (typeof params.limit === 'number' && params.limit > 0) {
702
- const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
703
- query.limit(params.limit)
704
- .skip(params.limit * (page - 1));
705
- }
706
- if (((_a = params.sort) === null || _a === void 0 ? void 0 : _a.runsAt) !== undefined) {
707
- query.sort({ runsAt: params.sort.runsAt });
708
- }
709
- return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
710
- .lean() // lean(2024-09-26~)
711
- .exec();
712
- });
683
+ const conditions = TaskRepo.CREATE_MONGO_CONDITIONS(params);
684
+ // const positiveProjectionExists: boolean = (projection !== undefined && projection !== null)
685
+ // ? Object.values(projection)
686
+ // .some((value) => value !== 0)
687
+ // : false;
688
+ let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
689
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
690
+ positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
691
+ }
692
+ else {
693
+ // no op
694
+ }
695
+ const projection = {
696
+ _id: 0,
697
+ id: { $toString: '$_id' },
698
+ ...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
699
+ };
700
+ const query = this.taskModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
701
+ if (typeof params.limit === 'number' && params.limit > 0) {
702
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
703
+ query.limit(params.limit)
704
+ .skip(params.limit * (page - 1));
705
+ }
706
+ if (params.sort?.runsAt !== undefined) {
707
+ query.sort({ runsAt: params.sort.runsAt });
708
+ }
709
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
710
+ .lean() // lean(2024-09-26~)
711
+ .exec();
713
712
  }
714
- deleteByProject(params) {
715
- return __awaiter(this, void 0, void 0, function* () {
716
- yield this.taskModel.deleteMany({
717
- 'project.id': { $eq: params.project.id }
718
- })
719
- .exec();
720
- });
713
+ async deleteByProject(params) {
714
+ await this.taskModel.deleteMany({
715
+ 'project.id': { $eq: params.project.id }
716
+ })
717
+ .exec();
721
718
  }
722
- deleteByName(params) {
723
- return __awaiter(this, void 0, void 0, function* () {
724
- var _a, _b;
725
- return this.taskModel.deleteMany(Object.assign(Object.assign({ name: { $eq: params.name } }, (typeof ((_a = params.status) === null || _a === void 0 ? void 0 : _a.$eq) === 'string') ? { status: { $eq: params.status.$eq } } : undefined), (((_b = params.runsAt) === null || _b === void 0 ? void 0 : _b.$gte) instanceof Date)
719
+ async deleteByName(params) {
720
+ return this.taskModel.deleteMany({
721
+ name: { $eq: params.name },
722
+ ...(typeof params.status?.$eq === 'string') ? { status: { $eq: params.status.$eq } } : undefined,
723
+ ...(params.runsAt?.$gte instanceof Date)
726
724
  ? {
727
725
  runsAt: { $gte: params.runsAt.$gte, $lte: params.runsAt.$lte }
728
726
  }
729
- : undefined))
730
- .exec();
731
- });
727
+ : undefined
728
+ })
729
+ .exec();
732
730
  }
733
731
  /**
734
732
  * 不要なタスクを削除する
735
733
  */
736
- deleteRunsAtPassedCertainPeriod(params) {
737
- return __awaiter(this, void 0, void 0, function* () {
738
- return this.taskModel.deleteMany({
739
- runsAt: { $lt: params.runsAt.$lt },
740
- status: {
741
- $in: [
742
- factory.taskStatus.Aborted,
743
- factory.taskStatus.Executed,
744
- factory.taskStatus.Expired
745
- ]
746
- }
747
- })
748
- .exec();
749
- });
734
+ async deleteRunsAtPassedCertainPeriod(params) {
735
+ return this.taskModel.deleteMany({
736
+ runsAt: { $lt: params.runsAt.$lt },
737
+ status: {
738
+ $in: [
739
+ factory.taskStatus.Aborted,
740
+ factory.taskStatus.Executed,
741
+ factory.taskStatus.Expired
742
+ ]
743
+ }
744
+ })
745
+ .exec();
750
746
  }
751
- countDelayedTasks(params) {
752
- return __awaiter(this, void 0, void 0, function* () {
753
- const { limit } = params;
754
- const runsAtLt = moment()
755
- .add(-params.delayInSeconds, 'seconds')
756
- .toDate();
757
- const query = this.taskModel.countDocuments(Object.assign({ status: { $eq: factory.taskStatus.Ready }, runsAt: { $lt: runsAtLt } }, (Array.isArray(params.name.$nin)) ? { name: { $nin: params.name.$nin } } : undefined));
758
- if (typeof limit === 'number' && limit >= 0) {
759
- query.limit(limit);
760
- }
761
- const count = yield query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
762
- .exec();
763
- return { count };
747
+ async countDelayedTasks(params) {
748
+ const { limit } = params;
749
+ const runsAtLt = moment()
750
+ .add(-params.delayInSeconds, 'seconds')
751
+ .toDate();
752
+ const query = this.taskModel.countDocuments({
753
+ status: { $eq: factory.taskStatus.Ready },
754
+ runsAt: { $lt: runsAtLt },
755
+ ...(Array.isArray(params.name.$nin)) ? { name: { $nin: params.name.$nin } } : undefined
764
756
  });
757
+ if (typeof limit === 'number' && limit >= 0) {
758
+ query.limit(limit);
759
+ }
760
+ const count = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
761
+ .exec();
762
+ return { count };
765
763
  }
766
764
  getCursor(conditions, projection) {
767
765
  return this.taskModel.find(conditions, projection)
768
766
  .sort({ runsAt: factory.sortType.Ascending })
769
767
  .cursor();
770
768
  }
771
- unsetUnnecessaryFields(params) {
772
- return __awaiter(this, void 0, void 0, function* () {
773
- return this.taskModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
774
- .exec();
775
- });
769
+ async unsetUnnecessaryFields(params) {
770
+ return this.taskModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
771
+ .exec();
776
772
  }
777
- aggregateTask(params) {
778
- return __awaiter(this, void 0, void 0, function* () {
779
- const statuses = yield Promise.all([
780
- factory.taskStatus.Executed,
781
- factory.taskStatus.Aborted
782
- ].map((taskStatus) => __awaiter(this, void 0, void 0, function* () {
783
- var _a, _b;
784
- const matchConditions = Object.assign({ runsAt: {
785
- $gte: params.runsFrom,
786
- $lte: params.runsThrough
787
- }, status: { $eq: taskStatus } }, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
773
+ async aggregateTask(params) {
774
+ const statuses = await Promise.all([
775
+ factory.taskStatus.Executed,
776
+ factory.taskStatus.Aborted
777
+ ].map(async (taskStatus) => {
778
+ const matchConditions = {
779
+ runsAt: {
780
+ $gte: params.runsFrom,
781
+ $lte: params.runsThrough
782
+ },
783
+ status: { $eq: taskStatus },
784
+ ...(typeof params.project?.id?.$ne === 'string')
788
785
  ? { 'project.id': { $ne: params.project.id.$ne } }
789
- : undefined);
790
- return this.agggregateByStatus({ matchConditions, status: taskStatus });
791
- })));
792
- return { statuses };
793
- });
786
+ : undefined
787
+ };
788
+ return this.agggregateByStatus({ matchConditions, status: taskStatus });
789
+ }));
790
+ return { statuses };
794
791
  }
795
792
  // tslint:disable-next-line:max-func-body-length
796
- agggregateByStatus(params) {
797
- return __awaiter(this, void 0, void 0, function* () {
798
- const matchConditions = params.matchConditions;
799
- const taskStatus = params.status;
800
- const aggregate1 = this.taskModel.aggregate([
801
- {
802
- $match: matchConditions
803
- },
804
- {
805
- $project: {
806
- latency: { $subtract: ['$lastTriedAt', '$runsAt'] },
807
- status: '$status',
808
- runsAt: '$runsAt',
809
- lastTriedAt: '$lastTriedAt'
810
- }
811
- },
812
- {
813
- $group: {
814
- _id: '$status',
815
- taskCount: { $sum: 1 },
816
- maxLatency: { $max: '$latency' },
817
- minLatency: { $min: '$latency' },
818
- avgLatency: { $avg: '$latency' }
819
- }
820
- },
821
- {
822
- $project: {
823
- _id: 0,
824
- taskCount: '$taskCount',
825
- avgLatency: '$avgLatency',
826
- maxLatency: '$maxLatency',
827
- minLatency: '$minLatency'
828
- }
793
+ async agggregateByStatus(params) {
794
+ const matchConditions = params.matchConditions;
795
+ const taskStatus = params.status;
796
+ const aggregate1 = this.taskModel.aggregate([
797
+ {
798
+ $match: matchConditions
799
+ },
800
+ {
801
+ $project: {
802
+ latency: { $subtract: ['$lastTriedAt', '$runsAt'] },
803
+ status: '$status',
804
+ runsAt: '$runsAt',
805
+ lastTriedAt: '$lastTriedAt'
829
806
  }
830
- ]);
831
- // const explainResult = await aggregate1.explain();
832
- // console.dir(explainResult, { depth: null });
833
- // return;
834
- const aggregations = yield aggregate1.exec();
835
- // tslint:disable-next-line:no-magic-numbers
836
- const percents = [50, 95, 99];
837
- if (aggregations.length === 0) {
838
- return {
839
- status: taskStatus,
840
- aggregation: {
841
- taskCount: 0,
842
- avgLatency: 0,
843
- maxLatency: 0,
844
- minLatency: 0,
845
- percentilesLatency: percents.map((percent) => {
846
- return {
847
- name: String(percent),
848
- value: 0
849
- };
850
- })
851
- }
852
- };
853
- }
854
- const ranks4percentile = percents.map((percentile) => {
855
- return {
856
- percentile,
857
- // tslint:disable-next-line:no-magic-numbers
858
- rank: Math.floor(aggregations[0].taskCount * percentile / 100)
859
- };
860
- });
861
- const aggregate2 = this.taskModel.aggregate([
862
- {
863
- $match: matchConditions
864
- },
865
- {
866
- $project: {
867
- latency: { $subtract: ['$lastTriedAt', '$runsAt'] },
868
- status: '$status',
869
- runsAt: '$runsAt',
870
- lastTriedAt: '$lastTriedAt'
871
- }
872
- },
873
- { $sort: { latency: 1 } },
874
- {
875
- $group: {
876
- _id: '$status',
877
- latencies: { $push: '$latency' }
878
- }
879
- },
880
- {
881
- $project: {
882
- _id: 0,
883
- percentilesLatency: ranks4percentile.map((rank) => {
884
- return {
885
- name: String(rank.percentile),
886
- value: { $arrayElemAt: ['$latencies', rank.rank] }
887
- };
888
- })
889
- }
807
+ },
808
+ {
809
+ $group: {
810
+ _id: '$status',
811
+ taskCount: { $sum: 1 },
812
+ maxLatency: { $max: '$latency' },
813
+ minLatency: { $min: '$latency' },
814
+ avgLatency: { $avg: '$latency' }
815
+ }
816
+ },
817
+ {
818
+ $project: {
819
+ _id: 0,
820
+ taskCount: '$taskCount',
821
+ avgLatency: '$avgLatency',
822
+ maxLatency: '$maxLatency',
823
+ minLatency: '$minLatency'
890
824
  }
891
- ]);
892
- const aggregations2 = yield aggregate2.exec();
825
+ }
826
+ ]);
827
+ // const explainResult = await aggregate1.explain();
828
+ // console.dir(explainResult, { depth: null });
829
+ // return;
830
+ const aggregations = await aggregate1.exec();
831
+ // tslint:disable-next-line:no-magic-numbers
832
+ const percents = [50, 95, 99];
833
+ if (aggregations.length === 0) {
893
834
  return {
894
835
  status: taskStatus,
895
- aggregation: Object.assign(Object.assign({}, aggregations[0]), aggregations2[0])
836
+ aggregation: {
837
+ taskCount: 0,
838
+ avgLatency: 0,
839
+ maxLatency: 0,
840
+ minLatency: 0,
841
+ percentilesLatency: percents.map((percent) => {
842
+ return {
843
+ name: String(percent),
844
+ value: 0
845
+ };
846
+ })
847
+ }
848
+ };
849
+ }
850
+ const ranks4percentile = percents.map((percentile) => {
851
+ return {
852
+ percentile,
853
+ // tslint:disable-next-line:no-magic-numbers
854
+ rank: Math.floor(aggregations[0].taskCount * percentile / 100)
896
855
  };
897
856
  });
857
+ const aggregate2 = this.taskModel.aggregate([
858
+ {
859
+ $match: matchConditions
860
+ },
861
+ {
862
+ $project: {
863
+ latency: { $subtract: ['$lastTriedAt', '$runsAt'] },
864
+ status: '$status',
865
+ runsAt: '$runsAt',
866
+ lastTriedAt: '$lastTriedAt'
867
+ }
868
+ },
869
+ { $sort: { latency: 1 } },
870
+ {
871
+ $group: {
872
+ _id: '$status',
873
+ latencies: { $push: '$latency' }
874
+ }
875
+ },
876
+ {
877
+ $project: {
878
+ _id: 0,
879
+ percentilesLatency: ranks4percentile.map((rank) => {
880
+ return {
881
+ name: String(rank.percentile),
882
+ value: { $arrayElemAt: ['$latencies', rank.rank] }
883
+ };
884
+ })
885
+ }
886
+ }
887
+ ]);
888
+ const aggregations2 = await aggregate2.exec();
889
+ return {
890
+ status: taskStatus,
891
+ aggregation: {
892
+ ...aggregations[0],
893
+ ...aggregations2[0]
894
+ }
895
+ };
898
896
  }
899
897
  }
900
898
  exports.TaskRepo = TaskRepo;