@chevre/domain 21.2.0-alpha.6 → 21.2.0-alpha.60

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 (232) hide show
  1. package/example/src/chevre/aggregation/aggregateSystem.ts +58 -31
  2. package/example/src/chevre/countDelayedTasks.ts +17 -0
  3. package/example/src/chevre/countDelayedTransactions.ts +60 -0
  4. package/example/src/chevre/countMoneyTransferTransaction.ts +36 -0
  5. package/example/src/chevre/createManyEventsIfNotExist.ts +4 -1
  6. package/example/src/chevre/deleteTasksByName.ts +2 -1
  7. package/example/src/chevre/importEventsFromCOA.ts +3 -4
  8. package/example/src/chevre/migrateOrderAdditionalProperties.ts +85 -0
  9. package/example/src/chevre/migrateStockHolderKeys.ts +89 -0
  10. package/example/src/chevre/saveTasks.ts +13 -10
  11. package/example/src/chevre/searchAbortedTasks.ts +36 -0
  12. package/example/src/chevre/searchSendEmailActions.ts +44 -0
  13. package/example/src/chevre/task/executeTasks.ts +26 -0
  14. package/example/src/chevre/transaction/findCreditCard.ts +1 -1
  15. package/example/src/chevre/transaction/orderMembershipService.ts +1 -1
  16. package/example/src/chevre/transaction/startExportTasks.ts +20 -0
  17. package/example/src/chevre/updateTransaction.ts +1 -1
  18. package/lib/chevre/credentials.d.ts +1 -0
  19. package/lib/chevre/credentials.js +2 -1
  20. package/lib/chevre/eventEmitter/assetTransaction.d.ts +21 -0
  21. package/lib/chevre/eventEmitter/assetTransaction.js +25 -0
  22. package/lib/chevre/eventEmitter/task.d.ts +18 -0
  23. package/lib/chevre/eventEmitter/task.js +25 -0
  24. package/lib/chevre/eventEmitter/transaction.d.ts +21 -0
  25. package/lib/chevre/eventEmitter/transaction.js +25 -0
  26. package/lib/chevre/eventEmitter.d.ts +4 -0
  27. package/lib/chevre/eventEmitter.js +9 -0
  28. package/lib/chevre/index.d.ts +3 -2
  29. package/lib/chevre/index.js +5 -3
  30. package/lib/chevre/repo/account.js +0 -4
  31. package/lib/chevre/repo/accountTitle.js +0 -4
  32. package/lib/chevre/repo/accountTransaction.d.ts +3 -11
  33. package/lib/chevre/repo/accountTransaction.js +1 -58
  34. package/lib/chevre/repo/accountingReport.js +0 -4
  35. package/lib/chevre/repo/action.d.ts +29 -1
  36. package/lib/chevre/repo/action.js +32 -29
  37. package/lib/chevre/repo/additionalProperty.js +0 -4
  38. package/lib/chevre/repo/aggregation.js +0 -4
  39. package/lib/chevre/repo/assetTransaction.d.ts +23 -8
  40. package/lib/chevre/repo/assetTransaction.js +207 -68
  41. package/lib/chevre/repo/categoryCode.js +0 -4
  42. package/lib/chevre/repo/code.js +0 -4
  43. package/lib/chevre/repo/comment.d.ts +4 -1
  44. package/lib/chevre/repo/comment.js +20 -9
  45. package/lib/chevre/repo/confirmationNumber.d.ts +0 -1
  46. package/lib/chevre/repo/confirmationNumber.js +3 -15
  47. package/lib/chevre/repo/creativeWork.d.ts +1 -3
  48. package/lib/chevre/repo/creativeWork.js +0 -4
  49. package/lib/chevre/repo/customer.js +0 -4
  50. package/lib/chevre/repo/emailMessage.d.ts +1 -27
  51. package/lib/chevre/repo/emailMessage.js +0 -4
  52. package/lib/chevre/repo/event.d.ts +5 -1
  53. package/lib/chevre/repo/event.js +0 -4
  54. package/lib/chevre/repo/member.js +0 -4
  55. package/lib/chevre/repo/merchantReturnPolicy.d.ts +1 -3
  56. package/lib/chevre/repo/merchantReturnPolicy.js +0 -4
  57. package/lib/chevre/repo/mongoose/schemas/account.d.ts +5 -2
  58. package/lib/chevre/repo/mongoose/schemas/account.js +1 -0
  59. package/lib/chevre/repo/mongoose/schemas/accountTitle.d.ts +30 -3
  60. package/lib/chevre/repo/mongoose/schemas/accountTitle.js +1 -0
  61. package/lib/chevre/repo/mongoose/schemas/accountTransaction.d.ts +32 -3
  62. package/lib/chevre/repo/mongoose/schemas/accountTransaction.js +2 -1
  63. package/lib/chevre/repo/mongoose/schemas/accountingReport.d.ts +14 -3
  64. package/lib/chevre/repo/mongoose/schemas/accountingReport.js +1 -0
  65. package/lib/chevre/repo/mongoose/schemas/action.d.ts +44 -3
  66. package/lib/chevre/repo/mongoose/schemas/action.js +2 -1
  67. package/lib/chevre/repo/mongoose/schemas/additionalProperty.d.ts +18 -3
  68. package/lib/chevre/repo/mongoose/schemas/additionalProperty.js +1 -0
  69. package/lib/chevre/repo/mongoose/schemas/aggregation.d.ts +5 -2
  70. package/lib/chevre/repo/mongoose/schemas/aggregation.js +1 -0
  71. package/lib/chevre/repo/mongoose/schemas/assetTransaction.d.ts +45 -3
  72. package/lib/chevre/repo/mongoose/schemas/assetTransaction.js +3 -1
  73. package/lib/chevre/repo/mongoose/schemas/authorization.d.ts +20 -3
  74. package/lib/chevre/repo/mongoose/schemas/authorization.js +2 -1
  75. package/lib/chevre/repo/mongoose/schemas/categoryCode.d.ts +26 -3
  76. package/lib/chevre/repo/mongoose/schemas/categoryCode.js +1 -0
  77. package/lib/chevre/repo/mongoose/schemas/comments.d.ts +28 -3
  78. package/lib/chevre/repo/mongoose/schemas/comments.js +2 -1
  79. package/lib/chevre/repo/mongoose/schemas/creativeWork.d.ts +44 -3
  80. package/lib/chevre/repo/mongoose/schemas/creativeWork.js +1 -0
  81. package/lib/chevre/repo/mongoose/schemas/customer.d.ts +26 -3
  82. package/lib/chevre/repo/mongoose/schemas/customer.js +1 -0
  83. package/lib/chevre/repo/mongoose/schemas/emailMessages.d.ts +22 -3
  84. package/lib/chevre/repo/mongoose/schemas/emailMessages.js +1 -0
  85. package/lib/chevre/repo/mongoose/schemas/event.d.ts +72 -3
  86. package/lib/chevre/repo/mongoose/schemas/event.js +1 -0
  87. package/lib/chevre/repo/mongoose/schemas/member.d.ts +14 -3
  88. package/lib/chevre/repo/mongoose/schemas/member.js +1 -0
  89. package/lib/chevre/repo/mongoose/schemas/merchantReturnPolicy.d.ts +22 -3
  90. package/lib/chevre/repo/mongoose/schemas/merchantReturnPolicy.js +1 -0
  91. package/lib/chevre/repo/mongoose/schemas/offer.d.ts +66 -3
  92. package/lib/chevre/repo/mongoose/schemas/offer.js +1 -0
  93. package/lib/chevre/repo/mongoose/schemas/offerCatalog.d.ts +28 -3
  94. package/lib/chevre/repo/mongoose/schemas/offerCatalog.js +1 -0
  95. package/lib/chevre/repo/mongoose/schemas/offerItemCondition.d.ts +74 -0
  96. package/lib/chevre/repo/mongoose/schemas/offerItemCondition.js +45 -0
  97. package/lib/chevre/repo/mongoose/schemas/order.d.ts +52 -3
  98. package/lib/chevre/repo/mongoose/schemas/order.js +2 -1
  99. package/lib/chevre/repo/mongoose/schemas/ownershipInfo.d.ts +26 -3
  100. package/lib/chevre/repo/mongoose/schemas/ownershipInfo.js +2 -1
  101. package/lib/chevre/repo/mongoose/schemas/place.d.ts +50 -3
  102. package/lib/chevre/repo/mongoose/schemas/place.js +1 -0
  103. package/lib/chevre/repo/mongoose/schemas/priceSpecification.d.ts +30 -3
  104. package/lib/chevre/repo/mongoose/schemas/priceSpecification.js +1 -0
  105. package/lib/chevre/repo/mongoose/schemas/product.d.ts +32 -3
  106. package/lib/chevre/repo/mongoose/schemas/product.js +1 -0
  107. package/lib/chevre/repo/mongoose/schemas/project.d.ts +24 -3
  108. package/lib/chevre/repo/mongoose/schemas/project.js +1 -0
  109. package/lib/chevre/repo/mongoose/schemas/reservation.d.ts +62 -3
  110. package/lib/chevre/repo/mongoose/schemas/reservation.js +2 -1
  111. package/lib/chevre/repo/mongoose/schemas/role.d.ts +12 -3
  112. package/lib/chevre/repo/mongoose/schemas/role.js +1 -0
  113. package/lib/chevre/repo/mongoose/schemas/seller.d.ts +32 -3
  114. package/lib/chevre/repo/mongoose/schemas/seller.js +1 -0
  115. package/lib/chevre/repo/mongoose/schemas/serviceOutput.d.ts +12 -3
  116. package/lib/chevre/repo/mongoose/schemas/serviceOutput.js +2 -1
  117. package/lib/chevre/repo/mongoose/schemas/task.d.ts +31 -3
  118. package/lib/chevre/repo/mongoose/schemas/task.js +3 -1
  119. package/lib/chevre/repo/mongoose/schemas/telemetry.d.ts +22 -3
  120. package/lib/chevre/repo/mongoose/schemas/telemetry.js +1 -0
  121. package/lib/chevre/repo/mongoose/schemas/transaction.d.ts +41 -3
  122. package/lib/chevre/repo/mongoose/schemas/transaction.js +3 -1
  123. package/lib/chevre/repo/mongoose/schemas/trip.d.ts +12 -3
  124. package/lib/chevre/repo/mongoose/schemas/trip.js +1 -0
  125. package/lib/chevre/repo/offer.js +0 -5
  126. package/lib/chevre/repo/offerCatalog.js +0 -4
  127. package/lib/chevre/repo/offerItemCondition.d.ts +39 -0
  128. package/lib/chevre/repo/offerItemCondition.js +112 -0
  129. package/lib/chevre/repo/order.d.ts +25 -0
  130. package/lib/chevre/repo/order.js +5 -4
  131. package/lib/chevre/repo/ownershipInfo.js +0 -4
  132. package/lib/chevre/repo/permit.js +0 -4
  133. package/lib/chevre/repo/place.js +0 -4
  134. package/lib/chevre/repo/priceSpecification.js +0 -4
  135. package/lib/chevre/repo/product.js +0 -4
  136. package/lib/chevre/repo/project.js +0 -4
  137. package/lib/chevre/repo/reservation.js +0 -4
  138. package/lib/chevre/repo/role.js +0 -4
  139. package/lib/chevre/repo/seller.js +0 -4
  140. package/lib/chevre/repo/serviceOutput.js +0 -4
  141. package/lib/chevre/repo/stockHolder.js +30 -0
  142. package/lib/chevre/repo/task.d.ts +41 -2
  143. package/lib/chevre/repo/task.js +97 -12
  144. package/lib/chevre/repo/telemetry.js +0 -4
  145. package/lib/chevre/repo/transaction.d.ts +23 -3
  146. package/lib/chevre/repo/transaction.js +174 -58
  147. package/lib/chevre/repo/trip.js +0 -4
  148. package/lib/chevre/repository.d.ts +5 -2
  149. package/lib/chevre/repository.js +8 -4
  150. package/lib/chevre/service/aggregation/system.d.ts +67 -22
  151. package/lib/chevre/service/aggregation/system.js +101 -89
  152. package/lib/chevre/service/assetTransaction/cancelReservation.js +23 -25
  153. package/lib/chevre/service/assetTransaction/moneyTransfer.js +23 -21
  154. package/lib/chevre/service/assetTransaction/pay/potentialActions.js +17 -1
  155. package/lib/chevre/service/assetTransaction/pay.js +32 -24
  156. package/lib/chevre/service/assetTransaction/refund.js +23 -21
  157. package/lib/chevre/service/assetTransaction/registerService.js +23 -22
  158. package/lib/chevre/service/assetTransaction/reserve.js +23 -21
  159. package/lib/chevre/service/assetTransaction.d.ts +6 -2
  160. package/lib/chevre/service/assetTransaction.js +9 -5
  161. package/lib/chevre/service/event.js +3 -1
  162. package/lib/chevre/service/notification/factory.js +2 -2
  163. package/lib/chevre/service/notification.d.ts +3 -1
  164. package/lib/chevre/service/notification.js +41 -7
  165. package/lib/chevre/service/offer/event/voidTransaction.d.ts +2 -0
  166. package/lib/chevre/service/offer/event/voidTransaction.js +17 -1
  167. package/lib/chevre/service/offer.js +1 -1
  168. package/lib/chevre/service/order/deleteOrder.js +8 -8
  169. package/lib/chevre/service/order/onOrderStatusChanged/factory.js +25 -36
  170. package/lib/chevre/service/order/onOrderStatusChanged.js +1 -1
  171. package/lib/chevre/service/order/placeOrder.js +1 -1
  172. package/lib/chevre/service/order/returnOrder.js +1 -5
  173. package/lib/chevre/service/order/sendOrder.js +1 -1
  174. package/lib/chevre/service/payment/any/onPaid.js +1 -1
  175. package/lib/chevre/service/payment/any/onRefund.js +1 -1
  176. package/lib/chevre/service/payment/any.js +60 -10
  177. package/lib/chevre/service/payment/movieTicket/validation.d.ts +3 -2
  178. package/lib/chevre/service/payment/movieTicket/validation.js +12 -25
  179. package/lib/chevre/service/payment/movieTicket.d.ts +1 -1
  180. package/lib/chevre/service/payment/movieTicket.js +4 -3
  181. package/lib/chevre/service/product.js +1 -5
  182. package/lib/chevre/service/report/telemetry.d.ts +0 -11
  183. package/lib/chevre/service/report/telemetry.js +21 -24
  184. package/lib/chevre/service/reserve/cancelReservation.js +0 -2
  185. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.d.ts +0 -3
  186. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.js +20 -20
  187. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.js +2 -3
  188. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +2 -31
  189. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +2 -3
  190. package/lib/chevre/service/reserve/useReservation.js +1 -8
  191. package/lib/chevre/service/task/confirmRegisterServiceTransaction.js +1 -1
  192. package/lib/chevre/service/task/deleteTransaction.js +10 -8
  193. package/lib/chevre/service/task/importOffersFromCOA.js +4 -0
  194. package/lib/chevre/service/task/returnPayTransaction.js +2 -12
  195. package/lib/chevre/service/task/voidReserveTransaction.js +3 -1
  196. package/lib/chevre/service/task.d.ts +9 -0
  197. package/lib/chevre/service/task.js +43 -4
  198. package/lib/chevre/service/transaction/deleteTransaction.d.ts +21 -0
  199. package/lib/chevre/service/transaction/deleteTransaction.js +226 -0
  200. package/lib/chevre/service/transaction/moneyTransfer/exportTasks/factory.js +11 -1
  201. package/lib/chevre/service/transaction/moneyTransfer/factory.js +3 -1
  202. package/lib/chevre/service/transaction/moneyTransfer/potentialActions.d.ts +1 -0
  203. package/lib/chevre/service/transaction/moneyTransfer/potentialActions.js +1 -1
  204. package/lib/chevre/service/transaction/moneyTransfer.js +9 -12
  205. package/lib/chevre/service/transaction/orderProgramMembership.js +2 -1
  206. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +42 -30
  207. package/lib/chevre/service/transaction/placeOrder.js +1 -5
  208. package/lib/chevre/service/transaction/placeOrderInProgress/factory.js +1 -1
  209. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/moneyTransfer.d.ts +1 -0
  210. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/moneyTransfer.js +1 -1
  211. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/registerService.d.ts +1 -0
  212. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/registerService.js +1 -1
  213. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions.d.ts +1 -0
  214. package/lib/chevre/service/transaction/placeOrderInProgress/result/acceptedOffers.d.ts +3 -0
  215. package/lib/chevre/service/transaction/placeOrderInProgress/result/acceptedOffers.js +7 -3
  216. package/lib/chevre/service/transaction/placeOrderInProgress/result.d.ts +1 -0
  217. package/lib/chevre/service/transaction/placeOrderInProgress/result.js +2 -2
  218. package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateMovieTicket.d.ts +1 -1
  219. package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateMovieTicket.js +2 -2
  220. package/lib/chevre/service/transaction/placeOrderInProgress/validation.d.ts +2 -1
  221. package/lib/chevre/service/transaction/placeOrderInProgress/validation.js +23 -17
  222. package/lib/chevre/service/transaction/placeOrderInProgress.d.ts +1 -3
  223. package/lib/chevre/service/transaction/placeOrderInProgress.js +22 -11
  224. package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.js +10 -1
  225. package/lib/chevre/service/transaction/returnOrder.js +1 -5
  226. package/lib/chevre/service/transaction.d.ts +8 -13
  227. package/lib/chevre/service/transaction.js +12 -145
  228. package/lib/chevre/settings.d.ts +6 -1
  229. package/lib/chevre/settings.js +17 -5
  230. package/package.json +5 -5
  231. package/example/src/chevre/migrateMoneyTransferPendingTransactionIdentifier.ts +0 -96
  232. package/example/src/chevre/migrateMovieAdditionalProperties.ts +0 -98
@@ -0,0 +1,112 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.MongoRepository = void 0;
24
+ const factory = require("../factory");
25
+ const offerItemCondition_1 = require("./mongoose/schemas/offerItemCondition");
26
+ /**
27
+ * アイテムコンディションリポジトリ
28
+ */
29
+ class MongoRepository {
30
+ constructor(connection) {
31
+ this.offerItemConditionModel = connection.model(offerItemCondition_1.modelName, offerItemCondition_1.schema);
32
+ }
33
+ static CREATE_MONGO_CONDITIONS(params) {
34
+ var _a, _b, _c, _d;
35
+ const andConditions = [];
36
+ const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
37
+ if (typeof projectIdEq === 'string') {
38
+ andConditions.push({ 'project.id': { $eq: projectIdEq } });
39
+ }
40
+ const identifierEq = (_c = params.identifier) === null || _c === void 0 ? void 0 : _c.$eq;
41
+ if (typeof identifierEq === 'string') {
42
+ andConditions.push({ identifier: { $eq: identifierEq } });
43
+ }
44
+ const identifierIn = (_d = params.identifier) === null || _d === void 0 ? void 0 : _d.$in;
45
+ if (Array.isArray(identifierIn)) {
46
+ andConditions.push({ identifier: { $in: identifierIn } });
47
+ }
48
+ return andConditions;
49
+ }
50
+ findById(params) {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ const doc = yield this.offerItemConditionModel.findOne({ _id: params.id }, {
53
+ __v: 0,
54
+ createdAt: 0,
55
+ updatedAt: 0
56
+ })
57
+ .exec();
58
+ if (doc === null) {
59
+ throw new factory.errors.NotFound(this.offerItemConditionModel.modelName);
60
+ }
61
+ return doc.toObject();
62
+ });
63
+ }
64
+ search(params, projection) {
65
+ var _a;
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
68
+ const positiveProjectionExists = (projection !== undefined && projection !== null)
69
+ ? Object.values(projection)
70
+ .some((value) => value !== 0)
71
+ : false;
72
+ const query = this.offerItemConditionModel.find((conditions.length > 0) ? { $and: conditions } : {}, (positiveProjectionExists)
73
+ ? projection
74
+ : Object.assign(Object.assign({}, projection), { __v: 0, createdAt: 0, updatedAt: 0 }));
75
+ if (typeof params.limit === 'number' && params.limit > 0) {
76
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
77
+ query.limit(params.limit)
78
+ .skip(params.limit * (page - 1));
79
+ }
80
+ if (((_a = params.sort) === null || _a === void 0 ? void 0 : _a.identifier) !== undefined) {
81
+ query.sort({ identifier: params.sort.identifier });
82
+ }
83
+ return query.setOptions({ maxTimeMS: 10000 })
84
+ .exec()
85
+ .then((docs) => docs.map((doc) => doc.toObject()));
86
+ });
87
+ }
88
+ save(params) {
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ let doc;
91
+ if (params.id === '') {
92
+ doc = yield this.offerItemConditionModel.create(params);
93
+ }
94
+ else {
95
+ const { id, identifier, project, typeOf } = params, updateFields = __rest(params, ["id", "identifier", "project", "typeOf"]);
96
+ doc = yield this.offerItemConditionModel.findOneAndUpdate({ _id: params.id }, updateFields, { upsert: false, new: true })
97
+ .exec();
98
+ }
99
+ if (doc === null) {
100
+ throw new factory.errors.NotFound(this.offerItemConditionModel.modelName);
101
+ }
102
+ return doc.toObject();
103
+ });
104
+ }
105
+ deleteById(params) {
106
+ return __awaiter(this, void 0, void 0, function* () {
107
+ yield this.offerItemConditionModel.findOneAndRemove({ _id: params.id })
108
+ .exec();
109
+ });
110
+ }
111
+ }
112
+ exports.MongoRepository = MongoRepository;
@@ -1,3 +1,27 @@
1
+ /// <reference types="mongoose/types/aggregate" />
2
+ /// <reference types="mongoose/types/callback" />
3
+ /// <reference types="mongoose/types/collection" />
4
+ /// <reference types="mongoose/types/connection" />
5
+ /// <reference types="mongoose/types/cursor" />
6
+ /// <reference types="mongoose/types/document" />
7
+ /// <reference types="mongoose/types/error" />
8
+ /// <reference types="mongoose/types/expressions" />
9
+ /// <reference types="mongoose/types/helpers" />
10
+ /// <reference types="mongoose/types/middlewares" />
11
+ /// <reference types="mongoose/types/indexes" />
12
+ /// <reference types="mongoose/types/models" />
13
+ /// <reference types="mongoose/types/mongooseoptions" />
14
+ /// <reference types="mongoose/types/pipelinestage" />
15
+ /// <reference types="mongoose/types/populate" />
16
+ /// <reference types="mongoose/types/query" />
17
+ /// <reference types="mongoose/types/schemaoptions" />
18
+ /// <reference types="mongoose/types/schematypes" />
19
+ /// <reference types="mongoose/types/session" />
20
+ /// <reference types="mongoose/types/types" />
21
+ /// <reference types="mongoose/types/utility" />
22
+ /// <reference types="mongoose/types/validation" />
23
+ /// <reference types="mongoose/types/virtuals" />
24
+ /// <reference types="mongoose/types/inferschematype" />
1
25
  import { Connection } from 'mongoose';
2
26
  import * as factory from '../factory';
3
27
  /**
@@ -86,4 +110,5 @@ export declare class MongoRepository {
86
110
  $in: string[];
87
111
  };
88
112
  }): Promise<(string)[]>;
113
+ getCursor(conditions: any, projection: any): import("mongoose").Cursor<any, import("mongoose").QueryOptions<any>>;
89
114
  }
@@ -11,7 +11,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MongoRepository = void 0;
13
13
  const factory = require("../factory");
14
- const onIndexCreated_1 = require("./mongoose/onIndexCreated");
15
14
  const order_1 = require("./mongoose/schemas/order");
16
15
  const errorHandler_1 = require("../errorHandler");
17
16
  const order_2 = require("../factory/order");
@@ -21,9 +20,6 @@ const order_2 = require("../factory/order");
21
20
  class MongoRepository {
22
21
  constructor(connection) {
23
22
  this.orderModel = connection.model(order_1.modelName, order_1.schema);
24
- if (connection.get('autoIndex') === true) {
25
- this.orderModel.on(onIndexCreated_1.INDEX_EVENT, onIndexCreated_1.onIndexCreated);
26
- }
27
23
  }
28
24
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
29
25
  static CREATE_MONGO_CONDITIONS(params) {
@@ -1014,5 +1010,10 @@ class MongoRepository {
1014
1010
  return [...new Set(reservationNumbers)];
1015
1011
  });
1016
1012
  }
1013
+ getCursor(conditions, projection) {
1014
+ return this.orderModel.find(conditions, projection)
1015
+ .sort({ orderDate: factory.sortType.Descending })
1016
+ .cursor();
1017
+ }
1017
1018
  }
1018
1019
  exports.MongoRepository = MongoRepository;
@@ -11,7 +11,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MongoRepository = void 0;
13
13
  const uuid = require("uuid");
14
- const onIndexCreated_1 = require("./mongoose/onIndexCreated");
15
14
  const ownershipInfo_1 = require("./mongoose/schemas/ownershipInfo");
16
15
  const errorHandler_1 = require("../errorHandler");
17
16
  const factory = require("../factory");
@@ -21,9 +20,6 @@ const factory = require("../factory");
21
20
  class MongoRepository {
22
21
  constructor(connection) {
23
22
  this.ownershipInfoModel = connection.model(ownershipInfo_1.modelName, ownershipInfo_1.schema);
24
- if (connection.get('autoIndex') === true) {
25
- this.ownershipInfoModel.on(onIndexCreated_1.INDEX_EVENT, onIndexCreated_1.onIndexCreated);
26
- }
27
23
  }
28
24
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
29
25
  static CREATE_MONGO_CONDITIONS(params) {
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MongoRepository = void 0;
13
- const onIndexCreated_1 = require("./mongoose/onIndexCreated");
14
13
  const serviceOutput_1 = require("./mongoose/schemas/serviceOutput");
15
14
  const factory = require("../factory");
16
15
  /**
@@ -19,9 +18,6 @@ const factory = require("../factory");
19
18
  class MongoRepository {
20
19
  constructor(connection) {
21
20
  this.serviceOutputModel = connection.model(serviceOutput_1.modelName, serviceOutput_1.schema);
22
- if (connection.get('autoIndex') === true) {
23
- this.serviceOutputModel.on(onIndexCreated_1.INDEX_EVENT, onIndexCreated_1.onIndexCreated);
24
- }
25
21
  }
26
22
  findByIdentifier(params, projection) {
27
23
  var _a, _b;
@@ -22,7 +22,6 @@ var __rest = (this && this.__rest) || function (s, e) {
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.MongoRepository = void 0;
24
24
  const mongoose_1 = require("mongoose");
25
- const onIndexCreated_1 = require("./mongoose/onIndexCreated");
26
25
  const place_1 = require("./mongoose/schemas/place");
27
26
  const factory = require("../factory");
28
27
  /**
@@ -31,9 +30,6 @@ const factory = require("../factory");
31
30
  class MongoRepository {
32
31
  constructor(connection) {
33
32
  this.placeModel = connection.model(place_1.modelName, place_1.schema);
34
- if (connection.get('autoIndex') === true) {
35
- this.placeModel.on(onIndexCreated_1.INDEX_EVENT, onIndexCreated_1.onIndexCreated);
36
- }
37
33
  }
38
34
  // tslint:disable-next-line:max-func-body-length
39
35
  static CREATE_BUS_STOP_MONGO_CONDITIONS(params) {
@@ -22,7 +22,6 @@ var __rest = (this && this.__rest) || function (s, e) {
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.MongoRepository = void 0;
24
24
  const factory = require("../factory");
25
- const onIndexCreated_1 = require("./mongoose/onIndexCreated");
26
25
  const priceSpecification_1 = require("./mongoose/schemas/priceSpecification");
27
26
  /**
28
27
  * 価格仕様リポジトリ
@@ -30,9 +29,6 @@ const priceSpecification_1 = require("./mongoose/schemas/priceSpecification");
30
29
  class MongoRepository {
31
30
  constructor(connection) {
32
31
  this.priceSpecificationModel = connection.model(priceSpecification_1.modelName, priceSpecification_1.schema);
33
- if (connection.get('autoIndex') === true) {
34
- this.priceSpecificationModel.on(onIndexCreated_1.INDEX_EVENT, onIndexCreated_1.onIndexCreated);
35
- }
36
32
  }
37
33
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
38
34
  static CREATE_MONGO_CONDITIONS(params) {
@@ -21,7 +21,6 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.MongoRepository = void 0;
24
- const onIndexCreated_1 = require("./mongoose/onIndexCreated");
25
24
  const product_1 = require("./mongoose/schemas/product");
26
25
  const factory = require("../factory");
27
26
  /**
@@ -30,9 +29,6 @@ const factory = require("../factory");
30
29
  class MongoRepository {
31
30
  constructor(connection) {
32
31
  this.productModel = connection.model(product_1.modelName, product_1.schema);
33
- if (connection.get('autoIndex') === true) {
34
- this.productModel.on(onIndexCreated_1.INDEX_EVENT, onIndexCreated_1.onIndexCreated);
35
- }
36
32
  }
37
33
  // tslint:disable-next-line:max-func-body-length
38
34
  static CREATE_MONGO_CONDITIONS(params) {
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MongoRepository = void 0;
13
- const onIndexCreated_1 = require("./mongoose/onIndexCreated");
14
13
  const project_1 = require("./mongoose/schemas/project");
15
14
  const factory = require("../factory");
16
15
  /**
@@ -19,9 +18,6 @@ const factory = require("../factory");
19
18
  class MongoRepository {
20
19
  constructor(connection) {
21
20
  this.projectModel = connection.model(project_1.modelName, project_1.schema);
22
- if (connection.get('autoIndex') === true) {
23
- this.projectModel.on(onIndexCreated_1.INDEX_EVENT, onIndexCreated_1.onIndexCreated);
24
- }
25
21
  }
26
22
  static CREATE_MONGO_CONDITIONS(params) {
27
23
  // MongoDB検索条件
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MongoRepository = void 0;
13
- const onIndexCreated_1 = require("./mongoose/onIndexCreated");
14
13
  const reservation_1 = require("./mongoose/schemas/reservation");
15
14
  const factory = require("../factory");
16
15
  /**
@@ -19,9 +18,6 @@ const factory = require("../factory");
19
18
  class MongoRepository {
20
19
  constructor(connection) {
21
20
  this.reservationModel = connection.model(reservation_1.modelName, reservation_1.schema);
22
- if (connection.get('autoIndex') === true) {
23
- this.reservationModel.on(onIndexCreated_1.INDEX_EVENT, onIndexCreated_1.onIndexCreated);
24
- }
25
21
  }
26
22
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
27
23
  static CREATE_MONGO_CONDITIONS(params) {
@@ -11,7 +11,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MongoRepository = exports.RoleType = void 0;
13
13
  const factory = require("../factory");
14
- const onIndexCreated_1 = require("./mongoose/onIndexCreated");
15
14
  const role_1 = require("./mongoose/schemas/role");
16
15
  var RoleType;
17
16
  (function (RoleType) {
@@ -23,9 +22,6 @@ var RoleType;
23
22
  class MongoRepository {
24
23
  constructor(connection) {
25
24
  this.roleModel = connection.model(role_1.modelName, role_1.schema);
26
- if (connection.get('autoIndex') === true) {
27
- this.roleModel.on(onIndexCreated_1.INDEX_EVENT, onIndexCreated_1.onIndexCreated);
28
- }
29
25
  }
30
26
  static CREATE_MONGO_CONDITIONS(params) {
31
27
  var _a, _b, _c;
@@ -21,7 +21,6 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.MongoRepository = void 0;
24
- const onIndexCreated_1 = require("./mongoose/onIndexCreated");
25
24
  const seller_1 = require("./mongoose/schemas/seller");
26
25
  const factory = require("../factory");
27
26
  /**
@@ -30,9 +29,6 @@ const factory = require("../factory");
30
29
  class MongoRepository {
31
30
  constructor(connection) {
32
31
  this.organizationModel = connection.model(seller_1.modelName, seller_1.schema);
33
- if (connection.get('autoIndex') === true) {
34
- this.organizationModel.on(onIndexCreated_1.INDEX_EVENT, onIndexCreated_1.onIndexCreated);
35
- }
36
32
  }
37
33
  // tslint:disable-next-line:max-func-body-length
38
34
  static CREATE_MONGO_CONDITIONS(params) {
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MongoRepository = void 0;
13
- const onIndexCreated_1 = require("./mongoose/onIndexCreated");
14
13
  const serviceOutput_1 = require("./mongoose/schemas/serviceOutput");
15
14
  const factory = require("../factory");
16
15
  /**
@@ -19,9 +18,6 @@ const factory = require("../factory");
19
18
  class MongoRepository {
20
19
  constructor(connection) {
21
20
  this.serviceOutputModel = connection.model(serviceOutput_1.modelName, serviceOutput_1.schema);
22
- if (connection.get('autoIndex') === true) {
23
- this.serviceOutputModel.on(onIndexCreated_1.INDEX_EVENT, onIndexCreated_1.onIndexCreated);
24
- }
25
21
  }
26
22
  // tslint:disable-next-line:max-func-body-length
27
23
  static CREATE_MONGO_CONDITIONS(params) {
@@ -22,6 +22,12 @@ class StockHolderRepository {
22
22
  constructor(redisClient) {
23
23
  this.redisClient = redisClient;
24
24
  }
25
+ // public static GET_KEY(params: {
26
+ // eventId: string;
27
+ // startDate: Date;
28
+ // }) {
29
+ // return StockHolderRepository.createKey(params);
30
+ // }
25
31
  static offer2field(params) {
26
32
  var _a, _b;
27
33
  // 予約IDをfieldにする場合
@@ -214,6 +220,30 @@ class StockHolderRepository {
214
220
  return result;
215
221
  });
216
222
  }
223
+ // public async migrateKey(params: {
224
+ // key: string;
225
+ // eventId: string;
226
+ // }): Promise<void> {
227
+ // // 旧キーと新キーの両方存在検証(念のため)
228
+ // const oldKey = StockHolderRepository.createKey({ eventId: params.eventId, startDate: new Date('2020-01-01T00:00:00Z') });
229
+ // const newKey = StockHolderRepository.createKey({ eventId: params.eventId, startDate: new Date('2030-01-01T00:00:00Z') });
230
+ // if (params.key !== oldKey) {
231
+ // // newの場合oldが存在するはずがない
232
+ // const existingOldKeyCount = await this.redisClient.exists(oldKey);
233
+ // debug('existingOldKeyCount:', existingOldKeyCount);
234
+ // if (existingOldKeyCount > 0) {
235
+ // await this.redisClient.del(oldKey);
236
+ // }
237
+ // }
238
+ // if (params.key !== newKey) {
239
+ // // oldの場合newが存在するはずがない
240
+ // const existingNewKeyCount = await this.redisClient.exists(newKey);
241
+ // debug('existingNewKeyCount:', existingNewKeyCount);
242
+ // if (existingNewKeyCount > 0) {
243
+ // await this.redisClient.del(newKey);
244
+ // }
245
+ // }
246
+ // }
217
247
  checkIfConflicted(params) {
218
248
  return __awaiter(this, void 0, void 0, function* () {
219
249
  // 旧キーと新キーの両方存在検証(念のため)
@@ -17,6 +17,9 @@ interface IStatus {
17
17
  export interface IAggregateTask {
18
18
  statuses: IStatus[];
19
19
  }
20
+ interface IOptionOnCreate {
21
+ emitImmediately: boolean;
22
+ }
20
23
  /**
21
24
  * タスクリポジトリ
22
25
  */
@@ -24,13 +27,43 @@ export declare class MongoRepository {
24
27
  readonly taskModel: typeof Model;
25
28
  constructor(connection: Connection);
26
29
  static CREATE_MONGO_CONDITIONS(params: factory.task.ISearchConditions): any[];
27
- saveMany(taskAttributes: factory.task.IAttributes<factory.taskName>[]): Promise<{
30
+ saveMany(taskAttributes: factory.task.IAttributes<factory.taskName>[], options: IOptionOnCreate): Promise<{
28
31
  id: string;
29
32
  }[]>;
30
- createInformTaskIfNotExist(params: factory.task.IAttributes<factory.taskName.TriggerWebhook>): Promise<void>;
33
+ createInformTaskIfNotExist(params: factory.task.IAttributes<factory.taskName.TriggerWebhook>, options: IOptionOnCreate): Promise<void>;
34
+ executeById(params: {
35
+ id: string;
36
+ executor: {
37
+ name: string;
38
+ };
39
+ }): Promise<factory.task.ITask<factory.taskName> | null>;
31
40
  executeOneByName<T extends factory.taskName>(params: {
32
41
  name: T;
42
+ executor: {
43
+ name: string;
44
+ };
33
45
  }): Promise<factory.task.ITask<T> | null>;
46
+ /**
47
+ * 一定期間遅延したタスクを実行する
48
+ */
49
+ executeTasks(params: {
50
+ now: Date;
51
+ /**
52
+ * 指定期間遅延しているタスクを実行する
53
+ */
54
+ delayInSeconds: number;
55
+ limit: number;
56
+ name: {
57
+ /**
58
+ * 指定タスクのみ実行する
59
+ */
60
+ $in?: factory.taskName[];
61
+ /**
62
+ * 指定タスク以外のみ実行する
63
+ */
64
+ $nin?: factory.taskName[];
65
+ };
66
+ }): Promise<Pick<import("@chevre/factory/lib/task").ITask | import("@chevre/factory/lib/task/deleteAssetTransaction").ITask | import("@chevre/factory/lib/task/deleteOrder").ITask | import("@chevre/factory/lib/task/deleteTransaction").ITask | import("@chevre/factory/lib/task/sendEmailMessage").ITask | import("@chevre/factory/lib/task/triggerWebhook").ITask | import("@chevre/factory/lib/task/confirmMoneyTransfer").ITask | import("@chevre/factory/lib/task/confirmRegisterService").ITask | import("@chevre/factory/lib/task/confirmPayTransaction").ITask | import("@chevre/factory/lib/task/confirmRegisterServiceTransaction").ITask | import("@chevre/factory/lib/task/confirmReserveTransaction").ITask | import("@chevre/factory/lib/task/deleteMember").ITask | import("@chevre/factory/lib/task/givePointAward").ITask | import("@chevre/factory/lib/task/orderProgramMembership").ITask | import("@chevre/factory/lib/task/placeOrder").ITask | import("@chevre/factory/lib/task/returnOrder").ITask | import("@chevre/factory/lib/task/returnMoneyTransfer").ITask | import("@chevre/factory/lib/task/returnPayTransaction").ITask | import("@chevre/factory/lib/task/returnPointAward").ITask | import("@chevre/factory/lib/task/returnReserveTransaction").ITask | import("@chevre/factory/lib/task/sendOrder").ITask | import("@chevre/factory/lib/task/voidMoneyTransferTransaction").ITask | import("@chevre/factory/lib/task/voidPayTransaction").ITask | import("@chevre/factory/lib/task/voidRegisterServiceTransaction").ITask | import("@chevre/factory/lib/task/voidReserveTransaction").ITask, "id" | "name" | "status">[]>;
34
67
  retry(params: {
35
68
  intervalInMinutes: number;
36
69
  }): Promise<void>;
@@ -60,7 +93,13 @@ export declare class MongoRepository {
60
93
  }): Promise<void>;
61
94
  deleteByName(params: {
62
95
  name: factory.taskName;
96
+ status?: {
97
+ $eq?: factory.taskStatus;
98
+ };
63
99
  }): Promise<import("mongodb").DeleteResult>;
100
+ countDelayedTasks(params: {
101
+ delayInSeconds: number;
102
+ }): Promise<number>;
64
103
  aggregateTask(params: {
65
104
  project?: {
66
105
  id?: {
@@ -12,8 +12,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MongoRepository = void 0;
13
13
  const moment = require("moment");
14
14
  const factory = require("../factory");
15
- const onIndexCreated_1 = require("./mongoose/onIndexCreated");
16
15
  const task_1 = require("./mongoose/schemas/task");
16
+ const task_2 = require("../eventEmitter/task");
17
17
  /**
18
18
  * タスク実行時のソート条件
19
19
  */
@@ -27,9 +27,6 @@ const sortOrder4executionOfTasks = {
27
27
  class MongoRepository {
28
28
  constructor(connection) {
29
29
  this.taskModel = connection.model(task_1.modelName, task_1.schema);
30
- if (connection.get('autoIndex') === true) {
31
- this.taskModel.on(onIndexCreated_1.INDEX_EVENT, onIndexCreated_1.onIndexCreated);
32
- }
33
30
  }
34
31
  // tslint:disable-next-line:max-func-body-length
35
32
  static CREATE_MONGO_CONDITIONS(params) {
@@ -153,27 +150,43 @@ class MongoRepository {
153
150
  }
154
151
  return andConditions;
155
152
  }
156
- saveMany(taskAttributes) {
153
+ saveMany(taskAttributes, options) {
157
154
  return __awaiter(this, void 0, void 0, function* () {
155
+ const emitImmediately = (options === null || options === void 0 ? void 0 : options.emitImmediately) === true;
158
156
  if (taskAttributes.length > 0) {
159
157
  const result = yield this.taskModel.insertMany(taskAttributes, { ordered: false, rawResult: true });
160
158
  if (result.insertedCount !== taskAttributes.length) {
161
159
  throw new factory.errors.ServiceUnavailable('all tasks not saved');
162
160
  }
163
- // return result.ops;
164
- return Object.values(result.insertedIds)
161
+ const savedTasks = Object.values(result.insertedIds)
165
162
  .map((objectId) => {
166
163
  return { id: objectId.toHexString() };
167
164
  });
165
+ if (emitImmediately) {
166
+ savedTasks.forEach((savedTask) => {
167
+ task_2.taskEventEmitter.emitTaskStatusChanged({
168
+ id: savedTask.id,
169
+ status: factory.taskStatus.Ready
170
+ });
171
+ });
172
+ // taskAttributes.forEach((savedTask) => {
173
+ // taskEventEmitter.emitTaskStatusChanged({
174
+ // name: savedTask.name,
175
+ // status: factory.taskStatus.Ready
176
+ // });
177
+ // });
178
+ }
179
+ // return result.ops;
180
+ return savedTasks;
168
181
  }
169
182
  else {
170
183
  return [];
171
184
  }
172
185
  });
173
186
  }
174
- createInformTaskIfNotExist(params) {
187
+ createInformTaskIfNotExist(params, options) {
175
188
  return __awaiter(this, void 0, void 0, function* () {
176
- yield this.taskModel.findOneAndUpdate({
189
+ const createdTask = yield this.taskModel.findOneAndUpdate({
177
190
  'project.id': { $eq: params.project.id },
178
191
  name: params.name,
179
192
  'data.object.id': {
@@ -181,7 +194,38 @@ class MongoRepository {
181
194
  $eq: String(params.data.object.id)
182
195
  }
183
196
  }, { $setOnInsert: params }, { new: true, upsert: true })
197
+ .select({ _id: 1 })
184
198
  .exec();
199
+ if (options.emitImmediately) {
200
+ task_2.taskEventEmitter.emitTaskStatusChanged({
201
+ id: createdTask.id,
202
+ name: params.name,
203
+ status: factory.taskStatus.Ready
204
+ });
205
+ }
206
+ });
207
+ }
208
+ executeById(params) {
209
+ return __awaiter(this, void 0, void 0, function* () {
210
+ const doc = yield this.taskModel.findOneAndUpdate({
211
+ status: factory.taskStatus.Ready,
212
+ runsAt: { $lt: new Date() },
213
+ _id: { $eq: params.id }
214
+ }, {
215
+ status: factory.taskStatus.Running,
216
+ lastTriedAt: new Date(),
217
+ $inc: {
218
+ remainingNumberOfTries: -1,
219
+ numberOfTried: 1 // トライ回数増やす
220
+ },
221
+ executor: params.executor
222
+ }, { new: true })
223
+ .exec();
224
+ if (doc === null) {
225
+ // tslint:disable-next-line:no-null-keyword
226
+ return null;
227
+ }
228
+ return doc.toObject();
185
229
  });
186
230
  }
187
231
  executeOneByName(params) {
@@ -196,7 +240,8 @@ class MongoRepository {
196
240
  $inc: {
197
241
  remainingNumberOfTries: -1,
198
242
  numberOfTried: 1 // トライ回数増やす
199
- }
243
+ },
244
+ executor: params.executor
200
245
  }, { new: true })
201
246
  .sort(sortOrder4executionOfTasks)
202
247
  .exec();
@@ -207,6 +252,35 @@ class MongoRepository {
207
252
  return doc.toObject();
208
253
  });
209
254
  }
255
+ /**
256
+ * 一定期間遅延したタスクを実行する
257
+ */
258
+ executeTasks(params) {
259
+ return __awaiter(this, void 0, void 0, function* () {
260
+ const runsAtLt = moment(params.now)
261
+ .add(-params.delayInSeconds, 'seconds')
262
+ .toDate();
263
+ const delayedTasks = yield this.taskModel.find(Object.assign(Object.assign({ status: { $eq: factory.taskStatus.Ready }, runsAt: { $lt: runsAtLt } }, (Array.isArray(params.name.$in)) ? { name: { $in: params.name.$in } } : undefined), (Array.isArray(params.name.$nin)) ? { name: { $nin: params.name.$nin } } : undefined))
264
+ .select({
265
+ _id: 1,
266
+ name: 1,
267
+ status: 1
268
+ })
269
+ .limit(params.limit)
270
+ .setOptions({ maxTimeMS: 10000 })
271
+ .exec();
272
+ if (delayedTasks.length > 0) {
273
+ delayedTasks.forEach((delayedTask) => {
274
+ task_2.taskEventEmitter.emitTaskStatusChanged({
275
+ id: delayedTask.id,
276
+ name: delayedTask.name,
277
+ status: delayedTask.status
278
+ });
279
+ });
280
+ }
281
+ return delayedTasks;
282
+ });
283
+ }
210
284
  retry(params) {
211
285
  return __awaiter(this, void 0, void 0, function* () {
212
286
  const lastTriedAtShoudBeLessThan = moment()
@@ -337,9 +411,20 @@ class MongoRepository {
337
411
  });
338
412
  }
339
413
  deleteByName(params) {
414
+ var _a;
340
415
  return __awaiter(this, void 0, void 0, function* () {
341
- return this.taskModel.deleteMany({
342
- name: { $eq: params.name }
416
+ return this.taskModel.deleteMany(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))
417
+ .exec();
418
+ });
419
+ }
420
+ countDelayedTasks(params) {
421
+ return __awaiter(this, void 0, void 0, function* () {
422
+ const runsAtLt = moment()
423
+ .add(-params.delayInSeconds, 'seconds')
424
+ .toDate();
425
+ return this.taskModel.count({
426
+ status: factory.taskStatus.Ready,
427
+ runsAt: { $lt: runsAtLt }
343
428
  })
344
429
  .exec();
345
430
  });