@chevre/domain 21.2.0-alpha.2 → 21.2.0-alpha.21

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 (187) hide show
  1. package/example/src/chevre/aggregateEventReservation.ts +1 -1
  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/lockStockHolder.ts +48 -0
  7. package/example/src/chevre/migrateOrderAdditionalProperties.ts +85 -0
  8. package/example/src/chevre/migrateStockHolderKeys.ts +89 -0
  9. package/example/src/chevre/processReserve.ts +2 -2
  10. package/example/src/chevre/searchEventSeats.ts +42 -0
  11. package/example/src/chevre/transaction/findCreditCard.ts +1 -1
  12. package/example/src/chevre/transaction/makeExpired.ts +18 -0
  13. package/example/src/chevre/transaction/orderMembershipService.ts +1 -1
  14. package/example/src/chevre/transaction/startExportTasks.ts +19 -0
  15. package/example/src/chevre/updateTransaction.ts +1 -1
  16. package/lib/chevre/eventEmitter/task.d.ts +18 -0
  17. package/lib/chevre/eventEmitter/task.js +28 -0
  18. package/lib/chevre/eventEmitter/transaction.d.ts +21 -0
  19. package/lib/chevre/eventEmitter/transaction.js +28 -0
  20. package/lib/chevre/eventEmitter.d.ts +3 -0
  21. package/lib/chevre/eventEmitter.js +7 -0
  22. package/lib/chevre/index.d.ts +3 -2
  23. package/lib/chevre/index.js +5 -3
  24. package/lib/chevre/repo/account.js +0 -4
  25. package/lib/chevre/repo/accountTitle.js +0 -4
  26. package/lib/chevre/repo/accountTransaction.d.ts +0 -10
  27. package/lib/chevre/repo/accountTransaction.js +0 -57
  28. package/lib/chevre/repo/accountingReport.js +0 -4
  29. package/lib/chevre/repo/action.js +0 -4
  30. package/lib/chevre/repo/additionalProperty.js +0 -4
  31. package/lib/chevre/repo/aggregation.js +0 -4
  32. package/lib/chevre/repo/assetTransaction.d.ts +4 -6
  33. package/lib/chevre/repo/assetTransaction.js +69 -45
  34. package/lib/chevre/repo/categoryCode.js +0 -4
  35. package/lib/chevre/repo/code.js +0 -4
  36. package/lib/chevre/repo/comment.js +0 -4
  37. package/lib/chevre/repo/confirmationNumber.js +1 -1
  38. package/lib/chevre/repo/creativeWork.d.ts +1 -3
  39. package/lib/chevre/repo/creativeWork.js +0 -4
  40. package/lib/chevre/repo/customer.js +0 -4
  41. package/lib/chevre/repo/emailMessage.d.ts +1 -27
  42. package/lib/chevre/repo/emailMessage.js +0 -4
  43. package/lib/chevre/repo/event.d.ts +5 -1
  44. package/lib/chevre/repo/event.js +0 -4
  45. package/lib/chevre/repo/member.js +0 -4
  46. package/lib/chevre/repo/merchantReturnPolicy.d.ts +1 -3
  47. package/lib/chevre/repo/merchantReturnPolicy.js +0 -4
  48. package/lib/chevre/repo/mongoose/schemas/account.d.ts +5 -2
  49. package/lib/chevre/repo/mongoose/schemas/account.js +1 -0
  50. package/lib/chevre/repo/mongoose/schemas/accountTitle.d.ts +30 -3
  51. package/lib/chevre/repo/mongoose/schemas/accountTitle.js +1 -0
  52. package/lib/chevre/repo/mongoose/schemas/accountTransaction.d.ts +32 -3
  53. package/lib/chevre/repo/mongoose/schemas/accountTransaction.js +2 -1
  54. package/lib/chevre/repo/mongoose/schemas/accountingReport.d.ts +14 -3
  55. package/lib/chevre/repo/mongoose/schemas/accountingReport.js +1 -0
  56. package/lib/chevre/repo/mongoose/schemas/action.d.ts +44 -3
  57. package/lib/chevre/repo/mongoose/schemas/action.js +2 -1
  58. package/lib/chevre/repo/mongoose/schemas/additionalProperty.d.ts +18 -3
  59. package/lib/chevre/repo/mongoose/schemas/additionalProperty.js +1 -0
  60. package/lib/chevre/repo/mongoose/schemas/aggregation.d.ts +5 -2
  61. package/lib/chevre/repo/mongoose/schemas/aggregation.js +1 -0
  62. package/lib/chevre/repo/mongoose/schemas/assetTransaction.d.ts +42 -3
  63. package/lib/chevre/repo/mongoose/schemas/assetTransaction.js +2 -1
  64. package/lib/chevre/repo/mongoose/schemas/authorization.d.ts +20 -3
  65. package/lib/chevre/repo/mongoose/schemas/authorization.js +2 -1
  66. package/lib/chevre/repo/mongoose/schemas/categoryCode.d.ts +26 -3
  67. package/lib/chevre/repo/mongoose/schemas/categoryCode.js +1 -0
  68. package/lib/chevre/repo/mongoose/schemas/comments.d.ts +28 -3
  69. package/lib/chevre/repo/mongoose/schemas/comments.js +2 -1
  70. package/lib/chevre/repo/mongoose/schemas/creativeWork.d.ts +44 -3
  71. package/lib/chevre/repo/mongoose/schemas/creativeWork.js +1 -0
  72. package/lib/chevre/repo/mongoose/schemas/customer.d.ts +26 -3
  73. package/lib/chevre/repo/mongoose/schemas/customer.js +1 -0
  74. package/lib/chevre/repo/mongoose/schemas/emailMessages.d.ts +22 -3
  75. package/lib/chevre/repo/mongoose/schemas/emailMessages.js +1 -0
  76. package/lib/chevre/repo/mongoose/schemas/event.d.ts +72 -3
  77. package/lib/chevre/repo/mongoose/schemas/event.js +1 -0
  78. package/lib/chevre/repo/mongoose/schemas/member.d.ts +14 -3
  79. package/lib/chevre/repo/mongoose/schemas/member.js +1 -0
  80. package/lib/chevre/repo/mongoose/schemas/merchantReturnPolicy.d.ts +22 -3
  81. package/lib/chevre/repo/mongoose/schemas/merchantReturnPolicy.js +1 -0
  82. package/lib/chevre/repo/mongoose/schemas/offer.d.ts +66 -3
  83. package/lib/chevre/repo/mongoose/schemas/offer.js +1 -0
  84. package/lib/chevre/repo/mongoose/schemas/offerCatalog.d.ts +28 -3
  85. package/lib/chevre/repo/mongoose/schemas/offerCatalog.js +1 -0
  86. package/lib/chevre/repo/mongoose/schemas/order.d.ts +52 -3
  87. package/lib/chevre/repo/mongoose/schemas/order.js +2 -1
  88. package/lib/chevre/repo/mongoose/schemas/ownershipInfo.d.ts +26 -3
  89. package/lib/chevre/repo/mongoose/schemas/ownershipInfo.js +2 -1
  90. package/lib/chevre/repo/mongoose/schemas/place.d.ts +50 -3
  91. package/lib/chevre/repo/mongoose/schemas/place.js +1 -0
  92. package/lib/chevre/repo/mongoose/schemas/priceSpecification.d.ts +30 -3
  93. package/lib/chevre/repo/mongoose/schemas/priceSpecification.js +1 -0
  94. package/lib/chevre/repo/mongoose/schemas/product.d.ts +32 -3
  95. package/lib/chevre/repo/mongoose/schemas/product.js +1 -0
  96. package/lib/chevre/repo/mongoose/schemas/project.d.ts +24 -3
  97. package/lib/chevre/repo/mongoose/schemas/project.js +1 -0
  98. package/lib/chevre/repo/mongoose/schemas/reservation.d.ts +62 -3
  99. package/lib/chevre/repo/mongoose/schemas/reservation.js +2 -1
  100. package/lib/chevre/repo/mongoose/schemas/role.d.ts +12 -3
  101. package/lib/chevre/repo/mongoose/schemas/role.js +1 -0
  102. package/lib/chevre/repo/mongoose/schemas/seller.d.ts +32 -3
  103. package/lib/chevre/repo/mongoose/schemas/seller.js +1 -0
  104. package/lib/chevre/repo/mongoose/schemas/serviceOutput.d.ts +12 -3
  105. package/lib/chevre/repo/mongoose/schemas/serviceOutput.js +2 -1
  106. package/lib/chevre/repo/mongoose/schemas/task.d.ts +31 -3
  107. package/lib/chevre/repo/mongoose/schemas/task.js +3 -1
  108. package/lib/chevre/repo/mongoose/schemas/telemetry.d.ts +22 -3
  109. package/lib/chevre/repo/mongoose/schemas/telemetry.js +1 -0
  110. package/lib/chevre/repo/mongoose/schemas/transaction.d.ts +38 -3
  111. package/lib/chevre/repo/mongoose/schemas/transaction.js +2 -1
  112. package/lib/chevre/repo/mongoose/schemas/trip.d.ts +12 -3
  113. package/lib/chevre/repo/mongoose/schemas/trip.js +1 -0
  114. package/lib/chevre/repo/offer.js +0 -5
  115. package/lib/chevre/repo/offerCatalog.js +0 -4
  116. package/lib/chevre/repo/order.d.ts +25 -0
  117. package/lib/chevre/repo/order.js +5 -4
  118. package/lib/chevre/repo/orderNumber.d.ts +0 -1
  119. package/lib/chevre/repo/orderNumber.js +2 -12
  120. package/lib/chevre/repo/ownershipInfo.js +0 -4
  121. package/lib/chevre/repo/permit.js +0 -4
  122. package/lib/chevre/repo/place.d.ts +5 -1
  123. package/lib/chevre/repo/place.js +1 -10
  124. package/lib/chevre/repo/priceSpecification.js +0 -4
  125. package/lib/chevre/repo/product.js +0 -4
  126. package/lib/chevre/repo/project.js +0 -4
  127. package/lib/chevre/repo/rateLimit/offer.d.ts +3 -2
  128. package/lib/chevre/repo/rateLimit/offer.js +14 -14
  129. package/lib/chevre/repo/reservation.js +0 -4
  130. package/lib/chevre/repo/role.js +0 -4
  131. package/lib/chevre/repo/seller.js +0 -4
  132. package/lib/chevre/repo/serviceOutput.js +0 -4
  133. package/lib/chevre/repo/serviceOutputIdentifier.d.ts +2 -1
  134. package/lib/chevre/repo/serviceOutputIdentifier.js +14 -15
  135. package/lib/chevre/repo/{itemAvailability/screeningEvent.d.ts → stockHolder.d.ts} +5 -6
  136. package/lib/chevre/repo/stockHolder.js +273 -0
  137. package/lib/chevre/repo/task.d.ts +17 -2
  138. package/lib/chevre/repo/task.js +61 -10
  139. package/lib/chevre/repo/telemetry.js +0 -4
  140. package/lib/chevre/repo/transaction.d.ts +3 -2
  141. package/lib/chevre/repo/transaction.js +116 -54
  142. package/lib/chevre/repo/transactionNumber.d.ts +2 -1
  143. package/lib/chevre/repo/transactionNumber.js +14 -15
  144. package/lib/chevre/repo/trip.js +0 -4
  145. package/lib/chevre/repository.d.ts +3 -5
  146. package/lib/chevre/repository.js +5 -8
  147. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.d.ts +2 -2
  148. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +4 -3
  149. package/lib/chevre/service/assetTransaction/cancelReservation.js +1 -5
  150. package/lib/chevre/service/assetTransaction/moneyTransfer.js +1 -1
  151. package/lib/chevre/service/assetTransaction/pay.js +2 -2
  152. package/lib/chevre/service/assetTransaction/refund.js +1 -1
  153. package/lib/chevre/service/assetTransaction/registerService.js +1 -2
  154. package/lib/chevre/service/assetTransaction/reserve.d.ts +4 -4
  155. package/lib/chevre/service/assetTransaction/reserve.js +8 -5
  156. package/lib/chevre/service/assetTransaction.d.ts +0 -2
  157. package/lib/chevre/service/assetTransaction.js +0 -1
  158. package/lib/chevre/service/offer/event/authorize.d.ts +2 -2
  159. package/lib/chevre/service/offer/event/cancel.d.ts +2 -2
  160. package/lib/chevre/service/offer/event/voidTransaction.d.ts +2 -2
  161. package/lib/chevre/service/offer.d.ts +2 -2
  162. package/lib/chevre/service/offer.js +5 -2
  163. package/lib/chevre/service/order/onOrderStatusChanged.js +1 -1
  164. package/lib/chevre/service/order/placeOrder.js +1 -1
  165. package/lib/chevre/service/order/returnOrder.js +1 -5
  166. package/lib/chevre/service/order/sendOrder.js +1 -1
  167. package/lib/chevre/service/payment/any.js +1 -1
  168. package/lib/chevre/service/reserve/cancelReservation.d.ts +3 -3
  169. package/lib/chevre/service/reserve/cancelReservation.js +6 -6
  170. package/lib/chevre/service/task/aggregateScreeningEvent.js +2 -2
  171. package/lib/chevre/service/task/cancelPendingReservation.js +3 -3
  172. package/lib/chevre/service/task/cancelReservation.js +3 -3
  173. package/lib/chevre/service/task/voidReserveTransaction.js +3 -3
  174. package/lib/chevre/service/task.d.ts +9 -0
  175. package/lib/chevre/service/task.js +22 -1
  176. package/lib/chevre/service/transaction/moneyTransfer.js +1 -3
  177. package/lib/chevre/service/transaction/placeOrder.js +1 -5
  178. package/lib/chevre/service/transaction/placeOrderInProgress.js +2 -2
  179. package/lib/chevre/service/transaction/returnOrder.js +1 -5
  180. package/lib/chevre/service/transaction.d.ts +1 -0
  181. package/lib/chevre/service/transaction.js +1 -7
  182. package/lib/chevre/settings.d.ts +2 -1
  183. package/lib/chevre/settings.js +5 -4
  184. package/package.json +4 -4
  185. package/example/src/chevre/migrateMoneyTransferPendingTransactionIdentifier.ts +0 -96
  186. package/example/src/chevre/migrateMovieAdditionalProperties.ts +0 -98
  187. package/lib/chevre/repo/itemAvailability/screeningEvent.js +0 -193
@@ -10,10 +10,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.RedisRepository = void 0;
13
- const createDebug = require("debug");
14
13
  const moment = require("moment");
15
14
  const factory = require("../../factory");
16
- const debug = createDebug('chevre-domain:repo');
15
+ const settings_1 = require("../../settings");
17
16
  /**
18
17
  * オファーレート制限リポジトリ
19
18
  */
@@ -21,11 +20,17 @@ class RedisRepository {
21
20
  constructor(redisClient) {
22
21
  this.redisClient = redisClient;
23
22
  }
24
- static CREATE_REDIS_KEY(ratelimitKey) {
23
+ static createKey(ratelimitKey) {
25
24
  const dateNow = moment(ratelimitKey.reservationFor.startDate);
26
25
  const unitInSeconds = Number(ratelimitKey.reservedTicket.ticketType.validRateLimit.unitInSeconds.toString());
27
- const validFrom = dateNow.unix() - dateNow.unix() % unitInSeconds;
28
- return `${RedisRepository.KEY_PREFIX}:${ratelimitKey.reservedTicket.ticketType.validRateLimit.scope}:${validFrom.toString()}`;
26
+ const validFrom = dateNow.unix() - (dateNow.unix() % unitInSeconds);
27
+ const useNewKey = dateNow.isSameOrAfter(settings_1.USE_NEW_EVENT_AVAILABILITY_KEY_FROM);
28
+ if (useNewKey) {
29
+ return `${RedisRepository.KEY_PREFIX_NEW}:${ratelimitKey.reservedTicket.ticketType.validRateLimit.scope}:${validFrom.toString()}`;
30
+ }
31
+ else {
32
+ return `${RedisRepository.KEY_PREFIX}:${ratelimitKey.reservedTicket.ticketType.validRateLimit.scope}:${validFrom.toString()}`;
33
+ }
29
34
  }
30
35
  /**
31
36
  * ロックする
@@ -34,7 +39,7 @@ class RedisRepository {
34
39
  return __awaiter(this, void 0, void 0, function* () {
35
40
  const datasets = ratelimitKeys.map((ratelimitKey) => {
36
41
  return {
37
- key: RedisRepository.CREATE_REDIS_KEY(ratelimitKey),
42
+ key: RedisRepository.createKey(ratelimitKey),
38
43
  value: ratelimitKey.reservationNumber,
39
44
  ttl: moment(ratelimitKey.reservationFor.startDate)
40
45
  .add(ratelimitKey.reservedTicket.ticketType.validRateLimit.unitInSeconds, 'seconds')
@@ -43,29 +48,24 @@ class RedisRepository {
43
48
  });
44
49
  let multi = this.redisClient.multi();
45
50
  datasets.forEach((dataset) => {
46
- debug('setting if not exist...', dataset.key);
47
51
  multi.setNX(dataset.key, dataset.value)
48
52
  .expire(dataset.key, dataset.ttl);
49
53
  });
50
54
  const results = yield multi.exec();
51
55
  const lockedFields = [];
52
56
  results.forEach((r, index) => {
53
- debug('r, index:', r, index);
54
57
  // tslint:disable-next-line:no-magic-numbers
55
58
  if (index % 2 === 0 && (r === 1 || r === true)) {
56
59
  // tslint:disable-next-line:no-magic-numbers
57
60
  lockedFields.push(datasets[index / 2].key);
58
61
  }
59
62
  });
60
- debug('locked fields:', lockedFields);
61
63
  const lockedAll = lockedFields.length === ratelimitKeys.length;
62
- debug('lockedAll?', lockedAll);
63
64
  if (!lockedAll) {
64
65
  if (lockedFields.length > 0) {
65
66
  // 全てロックできなければロックできたものは解除
66
67
  multi = this.redisClient.multi();
67
68
  lockedFields.forEach((key) => {
68
- debug('deleting...', key);
69
69
  multi.del(key);
70
70
  });
71
71
  yield multi.exec();
@@ -78,8 +78,7 @@ class RedisRepository {
78
78
  return __awaiter(this, void 0, void 0, function* () {
79
79
  const multi = this.redisClient.multi();
80
80
  ratelimitKeys.forEach((ratelimitKey) => {
81
- const key = RedisRepository.CREATE_REDIS_KEY(ratelimitKey);
82
- debug('deleting...', key);
81
+ const key = RedisRepository.createKey(ratelimitKey);
83
82
  multi.del(key);
84
83
  });
85
84
  yield multi.exec();
@@ -87,10 +86,11 @@ class RedisRepository {
87
86
  }
88
87
  getHolder(ratelimitKey) {
89
88
  return __awaiter(this, void 0, void 0, function* () {
90
- const key = RedisRepository.CREATE_REDIS_KEY(ratelimitKey);
89
+ const key = RedisRepository.createKey(ratelimitKey);
91
90
  return this.redisClient.get(key);
92
91
  });
93
92
  }
94
93
  }
94
+ RedisRepository.KEY_PREFIX_NEW = 'rateLimit:offer';
95
95
  RedisRepository.KEY_PREFIX = 'chevre:rateLimit:offer';
96
96
  exports.RedisRepository = RedisRepository;
@@ -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) {
@@ -3,9 +3,10 @@ import { RedisClientType } from 'redis';
3
3
  * サービスアウトプット識別子リポジトリ
4
4
  */
5
5
  export declare class RedisRepository {
6
- static REDIS_KEY_PREFIX: string;
6
+ private static readonly REDIS_KEY_PREFIX;
7
7
  private readonly redisClient;
8
8
  constructor(redisClient: RedisClientType);
9
+ private static createKey;
9
10
  /**
10
11
  * タイムスタンプから発行する
11
12
  */
@@ -23,6 +23,9 @@ class RedisRepository {
23
23
  constructor(redisClient) {
24
24
  this.redisClient = redisClient;
25
25
  }
26
+ static createKey(params) {
27
+ return util.format('%s:%s', RedisRepository.REDIS_KEY_PREFIX, params.timestamp);
28
+ }
26
29
  /**
27
30
  * タイムスタンプから発行する
28
31
  */
@@ -35,30 +38,26 @@ class RedisRepository {
35
38
  const TTL = moment(params.startDate)
36
39
  .add(1, 'minute') // ミリ秒でカウントしていくので、予約日時後1分で十分
37
40
  .diff(now, 'seconds');
38
- const key = util.format('%s:%s', RedisRepository.REDIS_KEY_PREFIX, timestamp);
41
+ const key = RedisRepository.createKey({ startDate: params.startDate, timestamp });
39
42
  const [incrReply] = yield this.redisClient.multi()
40
43
  .incr(key)
41
44
  .expire(key, TTL)
42
45
  .exec();
43
46
  // tslint:disable-next-line:no-single-line-block-comment
44
47
  /* istanbul ignore else: please write tests */
45
- if (typeof incrReply === 'number') {
46
- let identifier = timestamp;
47
- const no = incrReply;
48
- identifier = `${identifier}${no}`;
49
- // checkdigit
50
- const cd = cdigit.luhn.compute(identifier);
51
- const cipher = fpe({ password: cd });
52
- identifier = cipher.encrypt(identifier);
53
- identifier = `${cd}${identifier}`;
54
- return identifier;
55
- }
56
- else {
48
+ if (typeof incrReply !== 'number') {
57
49
  // 基本的にありえないフロー
58
- throw new factory.errors.ServiceUnavailable('ServiceOutput identifier not published');
50
+ throw new factory.errors.ServiceUnavailable('serviceOutput identifier not incremented unexpectedly');
59
51
  }
52
+ let identifier = `${timestamp}${incrReply}`;
53
+ // checkdigit
54
+ const cd = cdigit.luhn.compute(identifier);
55
+ identifier = fpe({ password: cd })
56
+ .encrypt(identifier);
57
+ identifier = `${cd}${identifier}`;
58
+ return identifier;
60
59
  });
61
60
  }
62
61
  }
63
- RedisRepository.REDIS_KEY_PREFIX = 'chevre:serviceOutputIdentifier';
62
+ RedisRepository.REDIS_KEY_PREFIX = 'serviceOutputIdentifier';
64
63
  exports.RedisRepository = RedisRepository;
@@ -1,5 +1,4 @@
1
1
  import { RedisClientType } from 'redis';
2
- import * as factory from '../../factory';
3
2
  export interface IOffer {
4
3
  itemOffered?: {
5
4
  serviceOutput?: {
@@ -24,10 +23,11 @@ export interface IUnlockKey {
24
23
  startDate: Date;
25
24
  offer: IOffer;
26
25
  }
26
+ export type IGetHolderResult = string | null;
27
27
  /**
28
28
  * イベントストックホルダーリポジトリ
29
29
  */
30
- export declare class RedisRepository {
30
+ export declare class StockHolderRepository {
31
31
  static KEY_PREFIX_NEW: string;
32
32
  static KEY_PREFIX: string;
33
33
  private readonly redisClient;
@@ -70,11 +70,10 @@ export declare class RedisRepository {
70
70
  * 在庫状況を検索する
71
71
  * offers.lengthが0だと"ERR wrong number of arguments for 'hmget' command"となるので注意
72
72
  */
73
- searchAvailability(params: {
73
+ searchHolders(params: {
74
74
  eventId: string;
75
75
  startDate: Date;
76
76
  offers: IOffer[];
77
- }): Promise<{
78
- availability: factory.itemAvailability;
79
- }[]>;
77
+ }): Promise<IGetHolderResult[]>;
78
+ private checkIfConflicted;
80
79
  }
@@ -0,0 +1,273 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.StockHolderRepository = void 0;
13
+ const createDebug = require("debug");
14
+ const moment = require("moment");
15
+ const factory = require("../factory");
16
+ const settings_1 = require("../settings");
17
+ const debug = createDebug('chevre-domain:repo');
18
+ /**
19
+ * イベントストックホルダーリポジトリ
20
+ */
21
+ class StockHolderRepository {
22
+ constructor(redisClient) {
23
+ this.redisClient = redisClient;
24
+ }
25
+ // public static GET_KEY(params: {
26
+ // eventId: string;
27
+ // startDate: Date;
28
+ // }) {
29
+ // return StockHolderRepository.createKey(params);
30
+ // }
31
+ static offer2field(params) {
32
+ var _a, _b;
33
+ // 予約IDをfieldにする場合
34
+ const serviceOutputId = (_b = (_a = params.itemOffered) === null || _a === void 0 ? void 0 : _a.serviceOutput) === null || _b === void 0 ? void 0 : _b.id;
35
+ if (typeof serviceOutputId === 'string') {
36
+ return serviceOutputId;
37
+ }
38
+ return `${params.seatSection}:${params.seatNumber}`;
39
+ }
40
+ static createKey(params) {
41
+ if (!(params.startDate instanceof Date)) {
42
+ throw new factory.errors.Argument('startDate', 'must be Date');
43
+ }
44
+ const useNewKey = moment(params.startDate)
45
+ .isSameOrAfter(settings_1.USE_NEW_EVENT_AVAILABILITY_KEY_FROM);
46
+ if (useNewKey) {
47
+ return `${StockHolderRepository.KEY_PREFIX_NEW}:${params.eventId}`;
48
+ }
49
+ else {
50
+ return `${StockHolderRepository.KEY_PREFIX}:${params.eventId}`;
51
+ }
52
+ }
53
+ /**
54
+ * 座席をロックする(maxキャパシティチェック有)
55
+ */
56
+ lockIfNotLimitExceeded(lockKey, maximum) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ const key = StockHolderRepository.createKey({ eventId: lockKey.eventId, startDate: lockKey.startDate });
59
+ yield this.redisClient.watch(key);
60
+ const hashCount = yield this.redisClient.hLen(key);
61
+ // Process result
62
+ // Heavy and time consuming operation here
63
+ debug('checking hash count...hashCount:', hashCount);
64
+ if (hashCount + lockKey.offers.length > maximum) {
65
+ throw new factory.errors.Argument('Event', 'maximumAttendeeCapacity exceeded');
66
+ }
67
+ yield this.lock(lockKey);
68
+ });
69
+ }
70
+ /**
71
+ * 座席をロックする
72
+ */
73
+ lock(lockKey) {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ if (!(lockKey.expires instanceof Date)) {
76
+ throw new factory.errors.Argument('expires', 'must be Date');
77
+ }
78
+ const key = StockHolderRepository.createKey({ eventId: lockKey.eventId, startDate: lockKey.startDate });
79
+ yield this.checkIfConflicted({ key, eventId: lockKey.eventId });
80
+ const value = lockKey.holder;
81
+ const multi = this.redisClient.multi();
82
+ const fields = lockKey.offers.map((offer) => StockHolderRepository.offer2field(offer));
83
+ fields.forEach((field) => {
84
+ multi.hSetNX(key, field, value);
85
+ });
86
+ const results = yield multi.expireAt(key, moment(lockKey.expires)
87
+ .unix())
88
+ .exec();
89
+ const lockedFields = [];
90
+ if (Array.isArray(results)) {
91
+ results.slice(0, fields.length)
92
+ .forEach((r, index) => {
93
+ if (r === 1 || r === true) {
94
+ lockedFields.push(fields[index]);
95
+ }
96
+ });
97
+ }
98
+ const lockedAll = lockedFields.length === fields.length;
99
+ debug('lockedAll?', lockedAll);
100
+ // expireAtReplyの検証も追加する(2023-04-19~)
101
+ const expiredAll = results.slice(fields.length)
102
+ .every((r) => (r === 1 || r === true));
103
+ debug('expiredAll?', expiredAll);
104
+ if (!lockedAll || !expiredAll) {
105
+ if (lockedFields.length > 0) {
106
+ // 全て仮押さえできなければ仮押さえできたものは解除
107
+ yield this.redisClient.multi()
108
+ .hDel(key, lockedFields)
109
+ .exec();
110
+ }
111
+ if (!lockedAll) {
112
+ throw new factory.errors.AlreadyInUse(factory.reservationType.EventReservation, ['ticketedSeat'], 'Already hold');
113
+ }
114
+ else {
115
+ throw new factory.errors.ServiceUnavailable('timeout cannot be set unexpectedly');
116
+ }
117
+ }
118
+ });
119
+ }
120
+ /**
121
+ * 座席ロックを解除する
122
+ */
123
+ unlock(params) {
124
+ return __awaiter(this, void 0, void 0, function* () {
125
+ const key = StockHolderRepository.createKey({ eventId: params.eventId, startDate: params.startDate });
126
+ yield this.checkIfConflicted({ key, eventId: params.eventId });
127
+ const field = StockHolderRepository.offer2field(params.offer);
128
+ yield this.redisClient.multi()
129
+ .hDel(key, field)
130
+ .exec();
131
+ });
132
+ }
133
+ /**
134
+ * 空席でない座席を検索する
135
+ */
136
+ findUnavailableOffersByEventId(params) {
137
+ return __awaiter(this, void 0, void 0, function* () {
138
+ const key = StockHolderRepository.createKey({ eventId: params.eventId, startDate: params.startDate });
139
+ const reply = yield this.redisClient.hGetAll(key);
140
+ let offers = [];
141
+ if (reply !== null) {
142
+ offers = Object.keys(reply)
143
+ .map((field) => {
144
+ const seatSection = field.split(':')[0];
145
+ const seatNumber = field.split(':')[1];
146
+ return { seatSection, seatNumber };
147
+ });
148
+ }
149
+ return offers;
150
+ });
151
+ }
152
+ /**
153
+ * 空席でない座席をカウントする
154
+ */
155
+ countUnavailableOffers(params) {
156
+ return __awaiter(this, void 0, void 0, function* () {
157
+ const key = StockHolderRepository.createKey({ eventId: params.event.id, startDate: params.event.startDate });
158
+ const reply = yield this.redisClient.hLen(key);
159
+ let fieldCount = 0;
160
+ if (typeof reply === 'number') {
161
+ fieldCount = Number(reply);
162
+ }
163
+ return fieldCount;
164
+ });
165
+ }
166
+ /**
167
+ * 保持者を取得する
168
+ */
169
+ getHolder(params) {
170
+ return __awaiter(this, void 0, void 0, function* () {
171
+ const key = StockHolderRepository.createKey({ eventId: params.eventId, startDate: params.startDate });
172
+ const field = StockHolderRepository.offer2field(params.offer);
173
+ return this.redisClient.hGet(key, field);
174
+ });
175
+ }
176
+ /**
177
+ * 在庫状況を検索する
178
+ * offers.lengthが0だと"ERR wrong number of arguments for 'hmget' command"となるので注意
179
+ */
180
+ // public async searchAvailability(params: {
181
+ // eventId: string;
182
+ // startDate: Date;
183
+ // offers: IOffer[];
184
+ // }): Promise<{
185
+ // seatSection: string;
186
+ // seatNumber: string;
187
+ // availability: factory.itemAvailability;
188
+ // }[]> {
189
+ // const key = RedisRepository.createKey({ eventId: params.eventId, startDate: params.startDate });
190
+ // const fields = params.offers.map((o) => {
191
+ // return RedisRepository.offer2field(o);
192
+ // });
193
+ // // Array reply: list of values associated with the given fields, in the same order as they are requested.
194
+ // const result = await this.redisClient.hmGet(key, fields);
195
+ // if (!Array.isArray(result)) {
196
+ // throw new factory.errors.ServiceUnavailable(`searchAvailability got non-array: ${typeof result}`);
197
+ // }
198
+ // return params.offers.map((o, index) => {
199
+ // const value4offer = result[index];
200
+ // return {
201
+ // ...o,
202
+ // availability: (typeof value4offer === 'string')
203
+ // ? factory.itemAvailability.OutOfStock // ホルダーが存在すればOutOfStock
204
+ // : factory.itemAvailability.InStock
205
+ // };
206
+ // });
207
+ // }
208
+ searchHolders(params) {
209
+ return __awaiter(this, void 0, void 0, function* () {
210
+ const key = StockHolderRepository.createKey({ eventId: params.eventId, startDate: params.startDate });
211
+ const fields = params.offers.map((o) => {
212
+ return StockHolderRepository.offer2field(o);
213
+ });
214
+ // Array reply: list of values associated with the given fields, in the same order as they are requested.
215
+ const result = yield this.redisClient.hmGet(key, fields);
216
+ if (!Array.isArray(result)) {
217
+ throw new factory.errors.ServiceUnavailable(`searchAvailability got non-array: ${typeof result}`);
218
+ }
219
+ // そのまま返却(2023-04-17~)
220
+ return result;
221
+ });
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
+ // }
247
+ checkIfConflicted(params) {
248
+ return __awaiter(this, void 0, void 0, function* () {
249
+ // 旧キーと新キーの両方存在検証(念のため)
250
+ const oldKey = StockHolderRepository.createKey({ eventId: params.eventId, startDate: new Date('2020-01-01T00:00:00Z') });
251
+ const newKey = StockHolderRepository.createKey({ eventId: params.eventId, startDate: new Date('2030-01-01T00:00:00Z') });
252
+ if (params.key !== oldKey) {
253
+ // newの場合oldが存在するはずがない
254
+ const existingOldKeyCount = yield this.redisClient.exists(oldKey);
255
+ debug('existingOldKeyCount:', existingOldKeyCount);
256
+ if (existingOldKeyCount > 0) {
257
+ throw new factory.errors.ServiceUnavailable('stockHolder keys conflicted');
258
+ }
259
+ }
260
+ if (params.key !== newKey) {
261
+ // oldの場合newが存在するはずがない
262
+ const existingNewKeyCount = yield this.redisClient.exists(newKey);
263
+ debug('existingNewKeyCount:', existingNewKeyCount);
264
+ if (existingNewKeyCount > 0) {
265
+ throw new factory.errors.ServiceUnavailable('stockHolder keys conflicted');
266
+ }
267
+ }
268
+ });
269
+ }
270
+ }
271
+ StockHolderRepository.KEY_PREFIX_NEW = 'stockHolder';
272
+ StockHolderRepository.KEY_PREFIX = 'chevre:itemAvailability:screeningEvent';
273
+ exports.StockHolderRepository = StockHolderRepository;
@@ -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,12 +27,21 @@ 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>;
34
46
  retry(params: {
35
47
  intervalInMinutes: number;
@@ -61,6 +73,9 @@ export declare class MongoRepository {
61
73
  deleteByName(params: {
62
74
  name: factory.taskName;
63
75
  }): Promise<import("mongodb").DeleteResult>;
76
+ countDelayedTasks(params: {
77
+ delayInSeconds: number;
78
+ }): Promise<number>;
64
79
  aggregateTask(params: {
65
80
  project?: {
66
81
  id?: {