@chevre/domain 22.11.0-alpha.9 → 22.12.0-alpha.0

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 (156) hide show
  1. package/example/src/chevre/aggregation/aggregateOrderOfCustomer.ts +25 -11
  2. package/example/src/chevre/aggregation/aggregateOrderOfCustomerGlobally.ts +34 -0
  3. package/example/src/chevre/aggregation/aggregateTasks.ts +41 -0
  4. package/example/src/chevre/checkCustomerAttributesLength.ts +109 -0
  5. package/example/src/chevre/notifyAbortedTasksByEmail.ts +1 -1
  6. package/example/src/chevre/reIndex.ts +1 -1
  7. package/example/src/chevre/roles/addEventOfferPermissionIfNotExists.ts +27 -0
  8. package/example/src/chevre/roles/{addAdminInventoryManagerRole.ts → addProjectCreatorRole.ts} +6 -8
  9. package/example/src/chevre/roles/assignGlobalRoles.ts +72 -0
  10. package/example/src/chevre/roles/findPermissions.ts +84 -0
  11. package/example/src/chevre/roles/findRoleNames.ts +117 -0
  12. package/example/src/chevre/roles/removeConsolePermissionIfExists.ts +38 -0
  13. package/example/src/chevre/searchEventSeats.ts +1 -1
  14. package/example/src/chevre/searchProducts.ts +28 -0
  15. package/example/src/chevre/settings/addSettings.ts +31 -17
  16. package/example/src/chevre/task/countPotentiallyRunning.ts +41 -0
  17. package/example/src/chevre/task/countTasks.ts +51 -0
  18. package/example/src/chevre/{deleteRunsAtPassedCertainPeriod.ts → task/deleteRunsAtPassedCertainPeriod.ts} +4 -3
  19. package/example/src/chevre/task/deleteUnexpectedTasks.ts +23 -0
  20. package/example/src/chevre/task/emitRunning.ts +89 -0
  21. package/example/src/idaas/auth0/adminApplications.ts +183 -0
  22. package/example/src/idaas/auth0/getToken.ts +55 -0
  23. package/example/src/idaas/auth0/getTokenByPrivateKeyJWT.ts +84 -0
  24. package/example/src/regex.ts +31 -0
  25. package/lib/chevre/eventEmitter/task.d.ts +29 -6
  26. package/lib/chevre/factory/event.d.ts +1 -1
  27. package/lib/chevre/index.d.ts +0 -2
  28. package/lib/chevre/index.js +0 -10
  29. package/lib/chevre/repo/event.js +1 -1
  30. package/lib/chevre/repo/member.d.ts +22 -4
  31. package/lib/chevre/repo/member.js +81 -27
  32. package/lib/chevre/repo/mongoose/schemas/aggregateOrder.js +9 -0
  33. package/lib/chevre/repo/mongoose/schemas/event.js +1 -0
  34. package/lib/chevre/repo/mongoose/schemas/member/global.d.ts +14 -0
  35. package/lib/chevre/repo/mongoose/schemas/member/global.js +82 -0
  36. package/lib/chevre/repo/mongoose/schemas/product.js +9 -0
  37. package/lib/chevre/repo/mongoose/schemas/setting.d.ts +15 -0
  38. package/lib/chevre/repo/mongoose/schemas/setting.js +1 -0
  39. package/lib/chevre/repo/mongoose/schemas/task.js +9 -0
  40. package/lib/chevre/repo/order.d.ts +23 -2
  41. package/lib/chevre/repo/order.js +70 -8
  42. package/lib/chevre/repo/pendingReservation.js +1 -0
  43. package/lib/chevre/repo/product.js +12 -17
  44. package/lib/chevre/repo/role.d.ts +5 -4
  45. package/lib/chevre/repo/role.js +35 -32
  46. package/lib/chevre/repo/setting.d.ts +1 -10
  47. package/lib/chevre/repo/setting.js +2 -11
  48. package/lib/chevre/repo/stockHolder.d.ts +4 -27
  49. package/lib/chevre/repo/stockHolder.js +163 -175
  50. package/lib/chevre/repo/task.d.ts +58 -38
  51. package/lib/chevre/repo/task.js +126 -296
  52. package/lib/chevre/repo/transaction.js +10 -10
  53. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +7 -4
  54. package/lib/chevre/service/assetTransaction/cancelReservation/start.d.ts +1 -1
  55. package/lib/chevre/service/assetTransaction/registerService.js +4 -0
  56. package/lib/chevre/service/assetTransaction/reserve/start/createSubReservations.js +19 -16
  57. package/lib/chevre/service/assetTransaction/reserve/start.js +5 -1
  58. package/lib/chevre/service/code.d.ts +5 -28
  59. package/lib/chevre/service/code.js +3 -79
  60. package/lib/chevre/service/iam.d.ts +17 -7
  61. package/lib/chevre/service/iam.js +26 -6
  62. package/lib/chevre/service/notification/notifyAbortedTasksByEmail.d.ts +15 -0
  63. package/lib/chevre/service/notification/notifyAbortedTasksByEmail.js +38 -0
  64. package/lib/chevre/service/notification.d.ts +2 -1
  65. package/lib/chevre/service/notification.js +3 -1
  66. package/lib/chevre/service/offer/product.js +4 -0
  67. package/lib/chevre/service/order/confirmPayTransaction.d.ts +6 -1
  68. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/processOrder.js +3 -3
  69. package/lib/chevre/service/task/acceptCOAOffer.d.ts +1 -1
  70. package/lib/chevre/service/task/aggregateOffers.d.ts +1 -1
  71. package/lib/chevre/service/task/aggregateOffers.js +1 -1
  72. package/lib/chevre/service/task/aggregateOnSystem.d.ts +4 -2
  73. package/lib/chevre/service/task/aggregateScreeningEvent.d.ts +1 -1
  74. package/lib/chevre/service/task/aggregateScreeningEvent.js +1 -1
  75. package/lib/chevre/service/task/authorizePayment.d.ts +1 -1
  76. package/lib/chevre/service/task/cancelMoneyTransfer.d.ts +1 -1
  77. package/lib/chevre/service/task/cancelPendingReservation.d.ts +1 -1
  78. package/lib/chevre/service/task/cancelPendingReservation.js +1 -1
  79. package/lib/chevre/service/task/cancelReservation.d.ts +1 -1
  80. package/lib/chevre/service/task/cancelReservation.js +1 -1
  81. package/lib/chevre/service/task/checkMovieTicket.d.ts +1 -1
  82. package/lib/chevre/service/task/checkResource.d.ts +1 -1
  83. package/lib/chevre/service/task/checkResource.js +1 -1
  84. package/lib/chevre/service/task/confirmMoneyTransfer.d.ts +1 -1
  85. package/lib/chevre/service/task/confirmPayTransaction.d.ts +2 -2
  86. package/lib/chevre/service/task/confirmPayTransaction.js +3 -2
  87. package/lib/chevre/service/task/confirmRegisterService.d.ts +1 -1
  88. package/lib/chevre/service/task/confirmRegisterServiceTransaction.d.ts +1 -1
  89. package/lib/chevre/service/task/confirmReserveTransaction.d.ts +6 -2
  90. package/lib/chevre/service/task/confirmReserveTransaction.js +3 -3
  91. package/lib/chevre/service/task/createAccountingReport.d.ts +1 -1
  92. package/lib/chevre/service/task/createEvent.d.ts +1 -1
  93. package/lib/chevre/service/task/deletePerson.d.ts +1 -1
  94. package/lib/chevre/service/task/deleteTransaction.d.ts +1 -1
  95. package/lib/chevre/service/task/givePointAward.d.ts +1 -1
  96. package/lib/chevre/service/task/handleNotification.d.ts +4 -2
  97. package/lib/chevre/service/task/importEventCapacitiesFromCOA.d.ts +1 -1
  98. package/lib/chevre/service/task/importEventsFromCOA.d.ts +1 -1
  99. package/lib/chevre/service/task/importOffersFromCOA.d.ts +1 -1
  100. package/lib/chevre/service/task/invalidatePaymentUrl.d.ts +1 -1
  101. package/lib/chevre/service/task/moneyTransfer.d.ts +1 -1
  102. package/lib/chevre/service/task/onAssetTransactionStatusChanged.d.ts +1 -1
  103. package/lib/chevre/service/task/onAuthorizationCreated.d.ts +1 -1
  104. package/lib/chevre/service/task/onEventChanged.d.ts +1 -1
  105. package/lib/chevre/service/task/onOrderPaymentCompleted.d.ts +1 -1
  106. package/lib/chevre/service/task/onResourceUpdated.d.ts +1 -1
  107. package/lib/chevre/service/task/pay.d.ts +1 -1
  108. package/lib/chevre/service/task/placeOrder.d.ts +1 -1
  109. package/lib/chevre/service/task/publishPaymentUrl.d.ts +1 -1
  110. package/lib/chevre/service/task/refund.d.ts +1 -1
  111. package/lib/chevre/service/task/registerService.d.ts +1 -1
  112. package/lib/chevre/service/task/reserve.d.ts +1 -1
  113. package/lib/chevre/service/task/returnMoneyTransfer.d.ts +1 -1
  114. package/lib/chevre/service/task/returnOrder.d.ts +1 -1
  115. package/lib/chevre/service/task/returnPayTransaction.d.ts +1 -1
  116. package/lib/chevre/service/task/returnPointAward.d.ts +1 -1
  117. package/lib/chevre/service/task/returnReserveTransaction.d.ts +1 -1
  118. package/lib/chevre/service/task/sendEmailMessage.d.ts +1 -1
  119. package/lib/chevre/service/task/sendOrder.d.ts +1 -1
  120. package/lib/chevre/service/task/triggerWebhook.d.ts +1 -1
  121. package/lib/chevre/service/task/useReservation.d.ts +1 -1
  122. package/lib/chevre/service/task/voidMoneyTransferTransaction.d.ts +1 -1
  123. package/lib/chevre/service/task/voidPayTransaction.d.ts +1 -1
  124. package/lib/chevre/service/task/voidPayment.d.ts +1 -1
  125. package/lib/chevre/service/task/voidRegisterServiceTransaction.d.ts +1 -1
  126. package/lib/chevre/service/task/voidReserveTransaction.d.ts +1 -1
  127. package/lib/chevre/service/task/voidReserveTransaction.js +1 -1
  128. package/lib/chevre/service/task.d.ts +7 -29
  129. package/lib/chevre/service/task.js +9 -114
  130. package/lib/chevre/service/taskHandler/onOperationFailed/informTaskIfNeeded.d.ts +11 -0
  131. package/lib/chevre/service/taskHandler/onOperationFailed/informTaskIfNeeded.js +105 -0
  132. package/lib/chevre/service/taskHandler/onOperationFailed.d.ts +17 -0
  133. package/lib/chevre/service/taskHandler/onOperationFailed.js +70 -0
  134. package/lib/chevre/service/taskHandler.d.ts +26 -0
  135. package/lib/chevre/service/taskHandler.js +97 -0
  136. package/lib/chevre/service/validation/validateEvent.d.ts +2 -2
  137. package/lib/chevre/service/validation/validateEvent.js +16 -10
  138. package/lib/chevre/service.d.ts +0 -4
  139. package/lib/chevre/service.js +10 -14
  140. package/lib/chevre/settings/aggregation.d.ts +6 -1
  141. package/lib/chevre/settings/aggregation.js +2 -1
  142. package/package.json +6 -4
  143. package/example/src/chevre/adminAuth/adminIdentity.ts +0 -38
  144. package/example/src/chevre/executeOneTask.ts +0 -41
  145. package/example/src/chevre/executeTaskIfExists.ts +0 -80
  146. package/example/src/chevre/findExecutableTask.ts +0 -50
  147. package/example/src/chevre/findSetting.ts +0 -79
  148. package/example/src/chevre/searchPermissions.ts +0 -46
  149. package/example/src/chevre/searchProductOffers.ts +0 -29
  150. package/example/src/chevre/stockHolder/checkIfConflicted.ts +0 -76
  151. package/example/src/chevre/stockHolder/checkRedisKeyCount.ts +0 -186
  152. package/example/src/chevre/stockHolder/migratePendingReservations.ts +0 -96
  153. package/example/src/chevre/stockHolder/playAroundStockHolder.ts +0 -256
  154. package/example/src/chevre/upsertProductsByProductId.ts +0 -100
  155. package/lib/chevre/adminAuth.d.ts +0 -2
  156. package/lib/chevre/adminAuth.js +0 -6
@@ -10,71 +10,67 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.StockHolderRepo = void 0;
13
- const createDebug = require("debug");
14
- const moment = require("moment");
13
+ // import type { RedisClientType } from 'redis';
15
14
  const factory = require("../factory");
16
- // import { createSchema, IModel, ISetting, modelName } from './mongoose/schemas/setting';
17
15
  const pendingReservation_1 = require("./pendingReservation");
18
- const debug = createDebug('chevre-domain:repo:stockHolder');
19
16
  const SEARCH_OFFERS_MAX_LENGTH = 100;
20
- const USE_STOCK_HOLDER_CHECK_CONFLICT = process.env.USE_STOCK_HOLDER_CHECK_CONFLICT === '1';
21
17
  /**
22
- * イベントストックホルダーリポジトリ
18
+ * 保留予約リポジトリ
23
19
  */
24
20
  class StockHolderRepo {
25
- constructor(redisClient, connection) {
26
- this.redisClient = redisClient;
27
- // this.settingModel = connection.model(modelName, createSchema());
21
+ constructor(params) {
22
+ const { connection } = params;
23
+ // this.redisClient = redisClient;
28
24
  this.pendingReservationRepo = new pendingReservation_1.PendingReservationRepo(connection);
29
25
  }
30
- static offer2field(params, hasTicketedSeat) {
31
- var _a, _b;
32
- if (hasTicketedSeat) {
33
- return `${params.seatSection}:${params.seatNumber}`;
34
- }
35
- else {
36
- // 予約IDをfieldにする場合
37
- const serviceOutputId = (_b = (_a = params.itemOffered) === null || _a === void 0 ? void 0 : _a.serviceOutput) === null || _b === void 0 ? void 0 : _b.id;
38
- if (typeof serviceOutputId === 'string') {
39
- return serviceOutputId;
40
- }
41
- else {
42
- throw new factory.errors.Internal('offer2field requires itemOffered.serviceOutput.id');
43
- }
44
- }
45
- }
46
- static createKey(params) {
47
- if (!(params.startDate instanceof Date)) {
48
- throw new factory.errors.Argument('startDate', 'must be Date');
49
- }
50
- return `${StockHolderRepo.KEY_PREFIX_NEW}:${params.eventId}`;
51
- }
26
+ // private static offer2field(params: IOffer, hasTicketedSeat: boolean) {
27
+ // if (hasTicketedSeat) {
28
+ // return `${params.seatSection}:${params.seatNumber}`;
29
+ // } else {
30
+ // // 予約IDをfieldにする場合
31
+ // const serviceOutputId = params.itemOffered?.serviceOutput?.id;
32
+ // if (typeof serviceOutputId === 'string') {
33
+ // return serviceOutputId;
34
+ // } else {
35
+ // throw new factory.errors.Internal('offer2field requires itemOffered.serviceOutput.id');
36
+ // }
37
+ // }
38
+ // }
39
+ // private static createKey(params: {
40
+ // eventId: string;
41
+ // startDate: Date;
42
+ // }): string {
43
+ // if (!(params.startDate instanceof Date)) {
44
+ // throw new factory.errors.Argument('startDate', 'must be Date');
45
+ // }
46
+ // return `${StockHolderRepo.KEY_PREFIX_NEW}:${params.eventId}`;
47
+ // }
52
48
  /**
53
49
  * 座席をロックする(maxキャパシティチェック有)
54
50
  */
55
51
  lockIfNotLimitExceeded(lockKey, maximum) {
56
52
  return __awaiter(this, void 0, void 0, function* () {
57
- const useMongoose = yield this.useMongoose({
53
+ const useMongoose = this.useMongoose({
58
54
  project: { id: lockKey.project.id },
59
55
  eventId: lockKey.eventId,
60
56
  startDate: lockKey.startDate,
61
57
  hasTicketedSeat: lockKey.hasTicketedSeat
62
58
  });
63
59
  if (useMongoose) {
64
- // throw new factory.errors.NotImplemented('new stock holder repository not implemented');
65
60
  return this.pendingReservationRepo.lockIfNotLimitExceeded(lockKey, maximum);
66
61
  }
67
62
  else {
68
- const key = StockHolderRepo.createKey({ eventId: lockKey.eventId, startDate: lockKey.startDate });
69
- yield this.redisClient.watch(key);
70
- const hashCount = yield this.redisClient.hLen(key);
71
- // Process result
72
- // Heavy and time consuming operation here
73
- debug('checking hash count...hashCount:', hashCount);
74
- if (hashCount + lockKey.offers.length > maximum) {
75
- throw new factory.errors.Argument('Event', 'maximumAttendeeCapacity exceeded');
76
- }
77
- yield this.lock(lockKey);
63
+ throw new factory.errors.NotImplemented('useRedis discontinued.');
64
+ // if (this.redisClient === undefined) {
65
+ // throw new factory.errors.Internal('redisClient required');
66
+ // }
67
+ // const key = StockHolderRepo.createKey({ eventId: lockKey.eventId, startDate: lockKey.startDate });
68
+ // await this.redisClient.watch(key);
69
+ // const hashCount = await this.redisClient.hLen(key);
70
+ // if (hashCount + lockKey.offers.length > maximum) {
71
+ // throw new factory.errors.Argument('Event', 'maximumAttendeeCapacity exceeded');
72
+ // }
73
+ // await this.lock(lockKey);
78
74
  }
79
75
  });
80
76
  }
@@ -87,62 +83,65 @@ class StockHolderRepo {
87
83
  if (!(lockKey.expires instanceof Date)) {
88
84
  throw new factory.errors.Argument('expires', 'must be Date');
89
85
  }
90
- const useMongoose = yield this.useMongoose({
86
+ const useMongoose = this.useMongoose({
91
87
  project: { id: lockKey.project.id },
92
88
  eventId: lockKey.eventId,
93
89
  startDate: lockKey.startDate,
94
90
  hasTicketedSeat: lockKey.hasTicketedSeat
95
91
  });
96
- const key = StockHolderRepo.createKey({ eventId: lockKey.eventId, startDate: lockKey.startDate });
92
+ // const key = StockHolderRepo.createKey({ eventId: lockKey.eventId, startDate: lockKey.startDate });
97
93
  // await this.checkIfConflicted({ key, eventId: lockKey.eventId, useMongoose });
98
94
  if (useMongoose) {
99
- // throw new factory.errors.NotImplemented('new stock holder repository not implemented');
100
95
  return this.pendingReservationRepo.lock(lockKey);
101
96
  }
102
97
  else {
103
- const value = lockKey.holder;
104
- const multi = this.redisClient.multi();
105
- const fields = lockKey.offers.map((offer) => StockHolderRepo.offer2field(offer, lockKey.hasTicketedSeat));
106
- // check uniqueness(2025-04-20~)
107
- const uniqueFields = [...new Set(fields)];
108
- if (uniqueFields.length !== fields.length) {
109
- throw new factory.errors.Argument('offers', 'offers must be unique');
110
- }
111
- fields.forEach((field) => {
112
- multi.hSetNX(key, field, value);
113
- });
114
- const results = yield multi.expireAt(key, moment(lockKey.expires)
115
- .unix())
116
- .exec();
117
- const lockedFields = [];
118
- if (Array.isArray(results)) {
119
- results.slice(0, fields.length)
120
- .forEach((r, index) => {
121
- if (r === 1 || r === true) {
122
- lockedFields.push(fields[index]);
123
- }
124
- });
125
- }
126
- const lockedAll = lockedFields.length === fields.length;
127
- debug('lockedAll?', lockedAll);
128
- // expireAtReplyの検証も追加する(2023-04-19~)
129
- const expiredAll = results.slice(fields.length)
130
- .every((r) => (r === 1 || r === true));
131
- debug('expiredAll?', expiredAll);
132
- if (!lockedAll || !expiredAll) {
133
- if (lockedFields.length > 0) {
134
- // 全て仮押さえできなければ仮押さえできたものは解除
135
- yield this.redisClient.multi()
136
- .hDel(key, lockedFields)
137
- .exec();
138
- }
139
- if (!lockedAll) {
140
- throw new factory.errors.AlreadyInUse(factory.reservationType.EventReservation, ['ticketedSeat'], 'Already hold');
141
- }
142
- else {
143
- throw new factory.errors.Internal('timeout cannot be set unexpectedly');
144
- }
145
- }
98
+ throw new factory.errors.NotImplemented('useRedis discontinued.');
99
+ // if (this.redisClient === undefined) {
100
+ // throw new factory.errors.Internal('redisClient required');
101
+ // }
102
+ // const value = lockKey.holder;
103
+ // const multi = this.redisClient.multi();
104
+ // const fields = lockKey.offers.map((offer) => StockHolderRepo.offer2field(offer, lockKey.hasTicketedSeat));
105
+ // // check uniqueness(2025-04-20~)
106
+ // const uniqueFields = [...new Set(fields)];
107
+ // if (uniqueFields.length !== fields.length) {
108
+ // throw new factory.errors.Argument('offers', 'offers must be unique');
109
+ // }
110
+ // fields.forEach((field) => {
111
+ // multi.hSetNX(key, field, value);
112
+ // });
113
+ // const results = await multi.expireAt(
114
+ // key,
115
+ // moment(lockKey.expires)
116
+ // .unix()
117
+ // )
118
+ // .exec();
119
+ // const lockedFields: string[] = [];
120
+ // if (Array.isArray(results)) {
121
+ // results.slice(0, fields.length)
122
+ // .forEach((r, index) => {
123
+ // if (r === 1 || (<any>r) === true) {
124
+ // lockedFields.push(fields[index]);
125
+ // }
126
+ // });
127
+ // }
128
+ // const lockedAll = lockedFields.length === fields.length;
129
+ // // expireAtReplyの検証も追加する(2023-04-19~)
130
+ // const expiredAll = results.slice(fields.length)
131
+ // .every((r) => (r === 1 || (<any>r) === true));
132
+ // if (!lockedAll || !expiredAll) {
133
+ // if (lockedFields.length > 0) {
134
+ // // 全て仮押さえできなければ仮押さえできたものは解除
135
+ // await this.redisClient.multi()
136
+ // .hDel(key, lockedFields)
137
+ // .exec();
138
+ // }
139
+ // if (!lockedAll) {
140
+ // throw new factory.errors.AlreadyInUse(factory.reservationType.EventReservation, ['ticketedSeat'], 'Already hold');
141
+ // } else {
142
+ // throw new factory.errors.Internal('timeout cannot be set unexpectedly');
143
+ // }
144
+ // }
146
145
  }
147
146
  });
148
147
  }
@@ -151,23 +150,26 @@ class StockHolderRepo {
151
150
  */
152
151
  unlock(params) {
153
152
  return __awaiter(this, void 0, void 0, function* () {
154
- const useMongoose = yield this.useMongoose({
153
+ const useMongoose = this.useMongoose({
155
154
  project: { id: params.project.id },
156
155
  eventId: params.eventId,
157
156
  startDate: params.startDate,
158
157
  hasTicketedSeat: params.hasTicketedSeat
159
158
  });
160
- const key = StockHolderRepo.createKey({ eventId: params.eventId, startDate: params.startDate });
159
+ // const key = StockHolderRepo.createKey({ eventId: params.eventId, startDate: params.startDate });
161
160
  // await this.checkIfConflicted({ key, eventId: params.eventId, useMongoose });
162
161
  if (useMongoose) {
163
- // throw new factory.errors.NotImplemented('new stock holder repository not implemented');
164
162
  return this.pendingReservationRepo.unlock(params);
165
163
  }
166
164
  else {
167
- const field = StockHolderRepo.offer2field(params.offer, params.hasTicketedSeat);
168
- yield this.redisClient.multi()
169
- .hDel(key, field)
170
- .exec();
165
+ throw new factory.errors.NotImplemented('useRedis discontinued.');
166
+ // if (this.redisClient === undefined) {
167
+ // throw new factory.errors.Internal('redisClient required');
168
+ // }
169
+ // const field = StockHolderRepo.offer2field(params.offer, params.hasTicketedSeat);
170
+ // await this.redisClient.multi()
171
+ // .hDel(key, field)
172
+ // .exec();
171
173
  }
172
174
  });
173
175
  }
@@ -176,23 +178,26 @@ class StockHolderRepo {
176
178
  */
177
179
  countUnavailableOffers(params) {
178
180
  return __awaiter(this, void 0, void 0, function* () {
179
- if (yield this.useMongoose({
181
+ if (this.useMongoose({
180
182
  project: { id: params.project.id },
181
183
  eventId: params.event.id,
182
184
  startDate: params.event.startDate,
183
185
  hasTicketedSeat: params.event.hasTicketedSeat
184
186
  })) {
185
- // throw new factory.errors.NotImplemented('new stock holder repository not implemented');
186
187
  return this.pendingReservationRepo.countUnavailableOffers(params);
187
188
  }
188
189
  else {
189
- const key = StockHolderRepo.createKey({ eventId: params.event.id, startDate: params.event.startDate });
190
- const reply = yield this.redisClient.hLen(key);
191
- let fieldCount = 0;
192
- if (typeof reply === 'number') {
193
- fieldCount = Number(reply);
194
- }
195
- return fieldCount;
190
+ throw new factory.errors.NotImplemented('useRedis discontinued.');
191
+ // if (this.redisClient === undefined) {
192
+ // throw new factory.errors.Internal('redisClient required');
193
+ // }
194
+ // const key = StockHolderRepo.createKey({ eventId: params.event.id, startDate: params.event.startDate });
195
+ // const reply = await this.redisClient.hLen(key);
196
+ // let fieldCount: number = 0;
197
+ // if (typeof reply === 'number') {
198
+ // fieldCount = Number(reply);
199
+ // }
200
+ // return fieldCount;
196
201
  }
197
202
  });
198
203
  }
@@ -201,19 +206,22 @@ class StockHolderRepo {
201
206
  */
202
207
  getHolder(params) {
203
208
  return __awaiter(this, void 0, void 0, function* () {
204
- if (yield this.useMongoose({
209
+ if (this.useMongoose({
205
210
  project: { id: params.project.id },
206
211
  eventId: params.eventId,
207
212
  startDate: params.startDate,
208
213
  hasTicketedSeat: params.hasTicketedSeat
209
214
  })) {
210
- // throw new factory.errors.NotImplemented('new stock holder repository not implemented');
211
215
  return this.pendingReservationRepo.getHolder(params);
212
216
  }
213
217
  else {
214
- const key = StockHolderRepo.createKey({ eventId: params.eventId, startDate: params.startDate });
215
- const field = StockHolderRepo.offer2field(params.offer, params.hasTicketedSeat);
216
- return this.redisClient.hGet(key, field);
218
+ throw new factory.errors.NotImplemented('useRedis discontinued.');
219
+ // if (this.redisClient === undefined) {
220
+ // throw new factory.errors.Internal('redisClient required');
221
+ // }
222
+ // const key = StockHolderRepo.createKey({ eventId: params.eventId, startDate: params.startDate });
223
+ // const field = StockHolderRepo.offer2field(params.offer, params.hasTicketedSeat);
224
+ // return this.redisClient.hGet(key, field);
217
225
  }
218
226
  });
219
227
  }
@@ -223,86 +231,66 @@ class StockHolderRepo {
223
231
  if (params.offers.length > SEARCH_OFFERS_MAX_LENGTH) {
224
232
  throw new factory.errors.Argument('offers', `offers.length must be <= ${SEARCH_OFFERS_MAX_LENGTH}`);
225
233
  }
226
- if (yield this.useMongoose({
234
+ if (this.useMongoose({
227
235
  project: { id: params.project.id },
228
236
  eventId: params.eventId,
229
237
  startDate: params.startDate,
230
238
  hasTicketedSeat: params.hasTicketedSeat
231
239
  })) {
232
- // throw new factory.errors.NotImplemented('new stock holder repository not implemented');
233
240
  return this.pendingReservationRepo.searchHolders(params);
234
241
  }
235
242
  else {
236
- const key = StockHolderRepo.createKey({ eventId: params.eventId, startDate: params.startDate });
237
- const fields = params.offers.map((o) => {
238
- return StockHolderRepo.offer2field(o, params.hasTicketedSeat);
239
- });
240
- // Array reply: list of values associated with the given fields, in the same order as they are requested.
241
- const result = yield this.redisClient.hmGet(key, fields);
242
- if (!Array.isArray(result)) {
243
- throw new factory.errors.Internal(`searchAvailability got non-array: ${typeof result}`);
244
- }
245
- // そのまま返却(2023-04-17~)
246
- return result;
247
- }
248
- });
249
- }
250
- redisKeyExists(params) {
251
- return __awaiter(this, void 0, void 0, function* () {
252
- const key = StockHolderRepo.createKey(params);
253
- const existingRedisKeyCount = yield this.redisClient.exists(key);
254
- if (typeof existingRedisKeyCount !== 'number') {
255
- throw new factory.errors.Internal(`unexpected existingKeyCount: ${typeof existingRedisKeyCount}`);
243
+ throw new factory.errors.NotImplemented('useRedis discontinued.');
244
+ // if (this.redisClient === undefined) {
245
+ // throw new factory.errors.Internal('redisClient required');
246
+ // }
247
+ // const key = StockHolderRepo.createKey({ eventId: params.eventId, startDate: params.startDate });
248
+ // const fields = params.offers.map((o) => {
249
+ // return StockHolderRepo.offer2field(o, params.hasTicketedSeat);
250
+ // });
251
+ // // Array reply: list of values associated with the given fields, in the same order as they are requested.
252
+ // const result = await this.redisClient.hmGet(key, fields);
253
+ // if (!Array.isArray(result)) {
254
+ // throw new factory.errors.Internal(`searchAvailability got non-array: ${typeof result}`);
255
+ // }
256
+ // // そのまま返却(2023-04-17~)
257
+ // return result;
256
258
  }
257
- return existingRedisKeyCount > 0;
258
- });
259
- }
260
- checkIfConflicted(params) {
261
- return __awaiter(this, void 0, void 0, function* () {
262
- const redisKeyExists = yield this.redisKeyExists(params);
263
- const mongoDocExists = yield this.pendingReservationRepo.docExists(params);
264
- if (redisKeyExists && mongoDocExists) {
265
- throw new factory.errors.Internal(`repository conflicted. eventId:${params.eventId}`);
266
- }
267
- });
268
- }
269
- /**
270
- * 万が一に備えて、保留予約をredis->mongo移行
271
- */
272
- migrate2mongoJustInCase(params) {
273
- return __awaiter(this, void 0, void 0, function* () {
274
- const redisKey = StockHolderRepo.createKey({ eventId: params.eventId, startDate: params.startDate });
275
- return {
276
- expireTime: yield this.redisClient.expireTime(redisKey),
277
- hash: yield this.redisClient.hGetAll(redisKey)
278
- };
279
259
  });
280
260
  }
261
+ // public async checkIfConflicted(params: {
262
+ // eventId: string;
263
+ // startDate: Date;
264
+ // }): Promise<void> {
265
+ // const redisKeyExists = await this.redisKeyExists(params);
266
+ // const mongoDocExists = await this.pendingReservationRepo.docExists(params);
267
+ // if (redisKeyExists && mongoDocExists) {
268
+ // throw new factory.errors.Internal(`repository conflicted. eventId:${params.eventId}`);
269
+ // }
270
+ // }
281
271
  /**
282
272
  * 新リポジトリを使用するかどうか
283
273
  */
274
+ // tslint:disable-next-line:prefer-function-over-method
284
275
  useMongoose(params) {
285
- return __awaiter(this, void 0, void 0, function* () {
286
- if (!(params.startDate instanceof Date)) {
287
- throw new factory.errors.Argument('startDate', 'must be Date');
288
- }
289
- let useMongoose = false;
290
- // always use mongo(2025-05-21~)
291
- const redisKeyExists = yield this.redisKeyExists(params);
292
- if (redisKeyExists) {
293
- useMongoose = false;
294
- }
295
- else {
296
- // redis keyが存在しなければmongo利用
297
- useMongoose = true;
298
- }
299
- // check confliction for test
300
- if (USE_STOCK_HOLDER_CHECK_CONFLICT) {
301
- yield this.checkIfConflicted(params);
302
- }
303
- return useMongoose;
304
- });
276
+ if (!(params.startDate instanceof Date)) {
277
+ throw new factory.errors.Argument('startDate', 'must be Date');
278
+ }
279
+ // always use mongo(2025-08-17~)
280
+ return true;
281
+ // let useMongoose = false;
282
+ // const redisKeyExists = await this.redisKeyExists(params);
283
+ // if (redisKeyExists) {
284
+ // useMongoose = false;
285
+ // } else {
286
+ // // redis keyが存在しなければmongo利用
287
+ // useMongoose = true;
288
+ // }
289
+ // // check confliction for test
290
+ // if (USE_STOCK_HOLDER_CHECK_CONFLICT) {
291
+ // await this.checkIfConflicted(params);
292
+ // }
293
+ // return useMongoose;
305
294
  }
306
295
  }
307
296
  exports.StockHolderRepo = StockHolderRepo;
308
- StockHolderRepo.KEY_PREFIX_NEW = 'stockHolder';
@@ -23,7 +23,9 @@ interface IOptionOnCreate {
23
23
  emitImmediately: boolean;
24
24
  }
25
25
  export type IExecutableTaskKeys = 'data' | 'id' | 'name' | 'status' | 'numberOfTried' | 'project' | 'remainingNumberOfTries' | 'runsAt' | 'expires';
26
- export type IExecutableTask<T extends factory.taskName> = Pick<factory.task.ITask<T>, IExecutableTaskKeys>;
26
+ export type IExecutableTask<T extends factory.taskName> = Pick<factory.task.ITask<T>, IExecutableTaskKeys> & {
27
+ status: factory.taskStatus.Running;
28
+ };
27
29
  type IKeyOfProjection = keyof factory.task.ITask<factory.taskName>;
28
30
  type ICreatingTask = Pick<factory.task.IAttributes<factory.taskName>, 'data' | 'executionResults' | 'name' | 'numberOfTried' | 'project' | 'remainingNumberOfTries' | 'runsAt' | 'status' | 'identifier' | 'description'>;
29
31
  /**
@@ -68,6 +70,10 @@ export declare class TaskRepo {
68
70
  */
69
71
  createDeleteTransactionTaskIfNotExist(params: Pick<factory.task.IAttributes<factory.taskName.DeleteTransaction>, 'data' | 'executionResults' | 'name' | 'numberOfTried' | 'project' | 'remainingNumberOfTries' | 'runsAt' | 'status'>, options: IOptionOnCreate): Promise<void>;
70
72
  createOnAssetTransactionStatusChangedTaskIfNotExist(params: Pick<factory.task.IAttributes<factory.taskName.OnAssetTransactionStatusChanged>, 'data' | 'executionResults' | 'name' | 'numberOfTried' | 'project' | 'remainingNumberOfTries' | 'runsAt' | 'status'>, options: IOptionOnCreate): Promise<void>;
73
+ /**
74
+ * Ready -> remainingNumberOfTriesが1減る
75
+ * Running -> findOneするだけ
76
+ */
71
77
  executeOneById(params: {
72
78
  id: string;
73
79
  status: factory.taskStatus.Ready | factory.taskStatus.Running;
@@ -77,12 +83,11 @@ export declare class TaskRepo {
77
83
  expires?: Date;
78
84
  }): Promise<IExecutableTask<factory.taskName> | null>;
79
85
  /**
80
- * support no name(2025-03-04~)
86
+ * Readyのタスクをname指定でひとつRunningに変更する
81
87
  */
82
88
  executeOneIfExists(params: {
83
- name?: {
84
- $eq?: factory.taskName;
85
- $nin?: factory.taskName[];
89
+ name: {
90
+ $eq: factory.taskName;
86
91
  };
87
92
  executor: {
88
93
  name: string;
@@ -90,6 +95,10 @@ export declare class TaskRepo {
90
95
  runsAt: {
91
96
  $lt: Date;
92
97
  };
98
+ sort: {
99
+ numberOfTried?: factory.sortType;
100
+ runsAt?: factory.sortType;
101
+ };
93
102
  }): Promise<IExecutableTask<factory.taskName> | null>;
94
103
  /**
95
104
  * add(2025-03-16~)
@@ -97,7 +106,7 @@ export declare class TaskRepo {
97
106
  countPotentiallyRunning(params: {
98
107
  name?: {
99
108
  $eq?: factory.taskName;
100
- $nin?: factory.taskName[];
109
+ $in?: factory.taskName[];
101
110
  };
102
111
  runsAt: {
103
112
  $lt: Date;
@@ -106,45 +115,54 @@ export declare class TaskRepo {
106
115
  }): Promise<{
107
116
  count: number;
108
117
  }>;
118
+ /**
119
+ * 実行日時を一定期間過ぎたReadyタスクについて、Runningスタータスに変更した上で、Runningイベントを発生させる
120
+ */
109
121
  emitRunningIfExists(params: {
110
- name?: {
111
- $eq?: factory.taskName;
112
- $nin?: factory.taskName[];
113
- };
114
- executor: {
115
- name: string;
122
+ /**
123
+ * 必ずタスク名指定で実行する
124
+ */
125
+ name: {
126
+ $eq: factory.taskName;
127
+ $in?: never;
128
+ } | {
129
+ $eq?: never;
130
+ $in: factory.taskName[];
116
131
  };
117
132
  runsAt: {
118
133
  $lt: Date;
119
134
  };
120
135
  sort: {
121
136
  numberOfTried?: factory.sortType;
122
- runsAt: factory.sortType;
137
+ runsAt?: factory.sortType;
123
138
  };
124
- }): Promise<Pick<factory.task.ITask<factory.taskName>, 'id' | 'name'> | null>;
125
- findExecutableOne(params: {
126
- name?: {
127
- $eq?: factory.taskName;
128
- $nin?: factory.taskName[];
129
- };
130
- runsAt: {
131
- $lt: Date;
139
+ executor: {
140
+ name: string;
132
141
  };
133
- }): Promise<IExecutableTask<factory.taskName> | null>;
134
- /**
135
- * emit OnTaskStatusChanged on delayed tasks
136
- */
142
+ nameFilterBeforeRunsAt: boolean;
143
+ }, next?: INextFunction): Promise<Pick<factory.task.ITask<factory.taskName>, 'id' | 'name'> | null>;
137
144
  /**
138
- * make tasks expired
145
+ * Readyのままで期限切れのタスクをExpiredに変更する
139
146
  */
140
147
  makeExpiredMany(params: {
141
148
  expiresLt: Date;
142
149
  }): Promise<UpdateWriteOpResult>;
143
150
  /**
144
- * 実行中ステータスのままになっているタスクをリトライする
151
+ * Runningのまま一定期間超過し、かつ、remainingNumberOfTries>0のタスクをReadyに変更する
145
152
  */
146
- retry(params: {
153
+ retryMany(params: {
147
154
  intervalInMinutes: number;
155
+ /**
156
+ * リトライ条件に残り試行回数条件を追加する
157
+ * 十分に小さい数値を指定すれば、実質残り試行回数に関係なくRunningがReadyに変更されることになる
158
+ */
159
+ remainingNumberOfTries: {
160
+ $gte?: number;
161
+ $lte?: number;
162
+ };
163
+ name: {
164
+ $in?: factory.taskName[];
165
+ };
148
166
  }): Promise<UpdateWriteOpResult>;
149
167
  /**
150
168
  * 実行中止済タスクを強制的にリトライ
@@ -154,25 +172,27 @@ export declare class TaskRepo {
154
172
  id: string;
155
173
  remainingNumberOfTries: number;
156
174
  }): Promise<UpdateWriteOpResult>;
157
- abortOne(params: {
158
- intervalInMinutes: number;
159
- }): Promise<factory.task.ITask<factory.taskName> | null>;
160
175
  abortMany(params: {
161
176
  intervalInMinutes: number;
177
+ name: {
178
+ $in?: factory.taskName[];
179
+ };
162
180
  }): Promise<UpdateWriteOpResult>;
163
181
  /**
164
- * 実行結果を保管する
182
+ * タスクIDから実行結果とステータスを保管する
183
+ * Abortedの場合、dateAbortedもセットする
165
184
  */
166
- pushExecutionResultById(params: {
185
+ setExecutionResultAndStatus(params: {
167
186
  /**
168
187
  * タスクID
169
188
  */
170
189
  id: string;
171
- status: factory.taskStatus;
172
- }, executionResult: factory.task.IExecutionResult, next?: INextFunction): Promise<void>;
173
- /**
174
- * 特定タスク検索
175
- */
190
+ remainingNumberOfTries: number;
191
+ name: factory.taskName;
192
+ }, update: {
193
+ status: factory.taskStatus.Executed | factory.taskStatus.Running | factory.taskStatus.Aborted;
194
+ executionResult: factory.task.IExecutionResult;
195
+ }, next?: INextFunction): Promise<void>;
176
196
  count(params: factory.task.ISearchConditions): Promise<{
177
197
  count: number;
178
198
  }>;