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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/example/src/chevre/countDelayedTasks.ts +17 -0
  2. package/example/src/chevre/countDelayedTransactions.ts +60 -0
  3. package/example/src/chevre/countMoneyTransferTransaction.ts +36 -0
  4. package/example/src/chevre/createManyEventsIfNotExist.ts +4 -1
  5. package/example/src/chevre/lockStockHolder.ts +48 -0
  6. package/example/src/chevre/migrateOrderAdditionalProperties.ts +85 -0
  7. package/example/src/chevre/migrateStockHolderKeys.ts +89 -0
  8. package/example/src/chevre/searchAbortedTasks.ts +30 -0
  9. package/example/src/chevre/transaction/findCreditCard.ts +1 -1
  10. package/example/src/chevre/transaction/makeExpired.ts +18 -0
  11. package/example/src/chevre/transaction/orderMembershipService.ts +1 -1
  12. package/example/src/chevre/transaction/startExportTasks.ts +19 -0
  13. package/example/src/chevre/updateTransaction.ts +1 -1
  14. package/lib/chevre/credentials.d.ts +1 -0
  15. package/lib/chevre/credentials.js +2 -1
  16. package/lib/chevre/eventEmitter/assetTransaction.d.ts +21 -0
  17. package/lib/chevre/eventEmitter/assetTransaction.js +28 -0
  18. package/lib/chevre/eventEmitter/task.d.ts +18 -0
  19. package/lib/chevre/eventEmitter/task.js +28 -0
  20. package/lib/chevre/eventEmitter/transaction.d.ts +21 -0
  21. package/lib/chevre/eventEmitter/transaction.js +28 -0
  22. package/lib/chevre/eventEmitter.d.ts +4 -0
  23. package/lib/chevre/eventEmitter.js +9 -0
  24. package/lib/chevre/index.d.ts +3 -2
  25. package/lib/chevre/index.js +5 -3
  26. package/lib/chevre/repo/account.js +0 -4
  27. package/lib/chevre/repo/accountTitle.js +0 -4
  28. package/lib/chevre/repo/accountTransaction.d.ts +0 -10
  29. package/lib/chevre/repo/accountTransaction.js +0 -57
  30. package/lib/chevre/repo/accountingReport.js +0 -4
  31. package/lib/chevre/repo/action.js +0 -4
  32. package/lib/chevre/repo/additionalProperty.js +0 -4
  33. package/lib/chevre/repo/aggregation.js +0 -4
  34. package/lib/chevre/repo/assetTransaction.d.ts +9 -6
  35. package/lib/chevre/repo/assetTransaction.js +132 -48
  36. package/lib/chevre/repo/categoryCode.js +0 -4
  37. package/lib/chevre/repo/code.js +0 -4
  38. package/lib/chevre/repo/comment.js +0 -4
  39. package/lib/chevre/repo/confirmationNumber.d.ts +0 -1
  40. package/lib/chevre/repo/confirmationNumber.js +3 -15
  41. package/lib/chevre/repo/creativeWork.d.ts +1 -3
  42. package/lib/chevre/repo/creativeWork.js +0 -4
  43. package/lib/chevre/repo/customer.js +0 -4
  44. package/lib/chevre/repo/emailMessage.d.ts +1 -27
  45. package/lib/chevre/repo/emailMessage.js +0 -4
  46. package/lib/chevre/repo/event.d.ts +5 -1
  47. package/lib/chevre/repo/event.js +0 -4
  48. package/lib/chevre/repo/member.js +0 -4
  49. package/lib/chevre/repo/merchantReturnPolicy.d.ts +1 -3
  50. package/lib/chevre/repo/merchantReturnPolicy.js +0 -4
  51. package/lib/chevre/repo/mongoose/schemas/account.d.ts +5 -2
  52. package/lib/chevre/repo/mongoose/schemas/account.js +1 -0
  53. package/lib/chevre/repo/mongoose/schemas/accountTitle.d.ts +30 -3
  54. package/lib/chevre/repo/mongoose/schemas/accountTitle.js +1 -0
  55. package/lib/chevre/repo/mongoose/schemas/accountTransaction.d.ts +32 -3
  56. package/lib/chevre/repo/mongoose/schemas/accountTransaction.js +2 -1
  57. package/lib/chevre/repo/mongoose/schemas/accountingReport.d.ts +14 -3
  58. package/lib/chevre/repo/mongoose/schemas/accountingReport.js +1 -0
  59. package/lib/chevre/repo/mongoose/schemas/action.d.ts +44 -3
  60. package/lib/chevre/repo/mongoose/schemas/action.js +2 -1
  61. package/lib/chevre/repo/mongoose/schemas/additionalProperty.d.ts +18 -3
  62. package/lib/chevre/repo/mongoose/schemas/additionalProperty.js +1 -0
  63. package/lib/chevre/repo/mongoose/schemas/aggregation.d.ts +5 -2
  64. package/lib/chevre/repo/mongoose/schemas/aggregation.js +1 -0
  65. package/lib/chevre/repo/mongoose/schemas/assetTransaction.d.ts +45 -3
  66. package/lib/chevre/repo/mongoose/schemas/assetTransaction.js +3 -1
  67. package/lib/chevre/repo/mongoose/schemas/authorization.d.ts +20 -3
  68. package/lib/chevre/repo/mongoose/schemas/authorization.js +2 -1
  69. package/lib/chevre/repo/mongoose/schemas/categoryCode.d.ts +26 -3
  70. package/lib/chevre/repo/mongoose/schemas/categoryCode.js +1 -0
  71. package/lib/chevre/repo/mongoose/schemas/comments.d.ts +28 -3
  72. package/lib/chevre/repo/mongoose/schemas/comments.js +2 -1
  73. package/lib/chevre/repo/mongoose/schemas/creativeWork.d.ts +44 -3
  74. package/lib/chevre/repo/mongoose/schemas/creativeWork.js +1 -0
  75. package/lib/chevre/repo/mongoose/schemas/customer.d.ts +26 -3
  76. package/lib/chevre/repo/mongoose/schemas/customer.js +1 -0
  77. package/lib/chevre/repo/mongoose/schemas/emailMessages.d.ts +22 -3
  78. package/lib/chevre/repo/mongoose/schemas/emailMessages.js +1 -0
  79. package/lib/chevre/repo/mongoose/schemas/event.d.ts +72 -3
  80. package/lib/chevre/repo/mongoose/schemas/event.js +1 -0
  81. package/lib/chevre/repo/mongoose/schemas/member.d.ts +14 -3
  82. package/lib/chevre/repo/mongoose/schemas/member.js +1 -0
  83. package/lib/chevre/repo/mongoose/schemas/merchantReturnPolicy.d.ts +22 -3
  84. package/lib/chevre/repo/mongoose/schemas/merchantReturnPolicy.js +1 -0
  85. package/lib/chevre/repo/mongoose/schemas/offer.d.ts +66 -3
  86. package/lib/chevre/repo/mongoose/schemas/offer.js +1 -0
  87. package/lib/chevre/repo/mongoose/schemas/offerCatalog.d.ts +28 -3
  88. package/lib/chevre/repo/mongoose/schemas/offerCatalog.js +1 -0
  89. package/lib/chevre/repo/mongoose/schemas/order.d.ts +52 -3
  90. package/lib/chevre/repo/mongoose/schemas/order.js +2 -1
  91. package/lib/chevre/repo/mongoose/schemas/ownershipInfo.d.ts +26 -3
  92. package/lib/chevre/repo/mongoose/schemas/ownershipInfo.js +2 -1
  93. package/lib/chevre/repo/mongoose/schemas/place.d.ts +50 -3
  94. package/lib/chevre/repo/mongoose/schemas/place.js +1 -0
  95. package/lib/chevre/repo/mongoose/schemas/priceSpecification.d.ts +30 -3
  96. package/lib/chevre/repo/mongoose/schemas/priceSpecification.js +1 -0
  97. package/lib/chevre/repo/mongoose/schemas/product.d.ts +32 -3
  98. package/lib/chevre/repo/mongoose/schemas/product.js +1 -0
  99. package/lib/chevre/repo/mongoose/schemas/project.d.ts +24 -3
  100. package/lib/chevre/repo/mongoose/schemas/project.js +1 -0
  101. package/lib/chevre/repo/mongoose/schemas/reservation.d.ts +62 -3
  102. package/lib/chevre/repo/mongoose/schemas/reservation.js +2 -1
  103. package/lib/chevre/repo/mongoose/schemas/role.d.ts +12 -3
  104. package/lib/chevre/repo/mongoose/schemas/role.js +1 -0
  105. package/lib/chevre/repo/mongoose/schemas/seller.d.ts +32 -3
  106. package/lib/chevre/repo/mongoose/schemas/seller.js +1 -0
  107. package/lib/chevre/repo/mongoose/schemas/serviceOutput.d.ts +12 -3
  108. package/lib/chevre/repo/mongoose/schemas/serviceOutput.js +2 -1
  109. package/lib/chevre/repo/mongoose/schemas/task.d.ts +31 -3
  110. package/lib/chevre/repo/mongoose/schemas/task.js +3 -1
  111. package/lib/chevre/repo/mongoose/schemas/telemetry.d.ts +22 -3
  112. package/lib/chevre/repo/mongoose/schemas/telemetry.js +1 -0
  113. package/lib/chevre/repo/mongoose/schemas/transaction.d.ts +41 -3
  114. package/lib/chevre/repo/mongoose/schemas/transaction.js +3 -1
  115. package/lib/chevre/repo/mongoose/schemas/trip.d.ts +12 -3
  116. package/lib/chevre/repo/mongoose/schemas/trip.js +1 -0
  117. package/lib/chevre/repo/offer.js +0 -5
  118. package/lib/chevre/repo/offerCatalog.js +0 -4
  119. package/lib/chevre/repo/order.d.ts +25 -0
  120. package/lib/chevre/repo/order.js +5 -4
  121. package/lib/chevre/repo/orderNumber.d.ts +0 -1
  122. package/lib/chevre/repo/orderNumber.js +2 -12
  123. package/lib/chevre/repo/ownershipInfo.js +0 -4
  124. package/lib/chevre/repo/permit.js +0 -4
  125. package/lib/chevre/repo/place.d.ts +5 -1
  126. package/lib/chevre/repo/place.js +1 -10
  127. package/lib/chevre/repo/priceSpecification.js +0 -4
  128. package/lib/chevre/repo/product.js +0 -4
  129. package/lib/chevre/repo/project.js +0 -4
  130. package/lib/chevre/repo/rateLimit/offer.d.ts +3 -2
  131. package/lib/chevre/repo/rateLimit/offer.js +14 -14
  132. package/lib/chevre/repo/reservation.js +0 -4
  133. package/lib/chevre/repo/role.js +0 -4
  134. package/lib/chevre/repo/seller.js +0 -4
  135. package/lib/chevre/repo/serviceOutput.js +0 -4
  136. package/lib/chevre/repo/serviceOutputIdentifier.d.ts +2 -1
  137. package/lib/chevre/repo/serviceOutputIdentifier.js +14 -15
  138. package/lib/chevre/repo/stockHolder.d.ts +1 -0
  139. package/lib/chevre/repo/stockHolder.js +74 -7
  140. package/lib/chevre/repo/task.d.ts +17 -2
  141. package/lib/chevre/repo/task.js +61 -10
  142. package/lib/chevre/repo/telemetry.js +0 -4
  143. package/lib/chevre/repo/transaction.d.ts +10 -2
  144. package/lib/chevre/repo/transaction.js +144 -55
  145. package/lib/chevre/repo/transactionNumber.d.ts +2 -1
  146. package/lib/chevre/repo/transactionNumber.js +14 -15
  147. package/lib/chevre/repo/trip.js +0 -4
  148. package/lib/chevre/service/assetTransaction/cancelReservation.js +1 -5
  149. package/lib/chevre/service/assetTransaction/moneyTransfer.js +1 -1
  150. package/lib/chevre/service/assetTransaction/pay.js +2 -2
  151. package/lib/chevre/service/assetTransaction/refund.js +1 -1
  152. package/lib/chevre/service/assetTransaction/registerService.js +1 -2
  153. package/lib/chevre/service/assetTransaction/reserve.js +1 -1
  154. package/lib/chevre/service/assetTransaction.d.ts +6 -2
  155. package/lib/chevre/service/assetTransaction.js +9 -5
  156. package/lib/chevre/service/notification.d.ts +3 -1
  157. package/lib/chevre/service/notification.js +2 -6
  158. package/lib/chevre/service/order/onOrderStatusChanged.js +1 -1
  159. package/lib/chevre/service/order/placeOrder.js +1 -1
  160. package/lib/chevre/service/order/returnOrder.js +1 -5
  161. package/lib/chevre/service/order/sendOrder.js +1 -1
  162. package/lib/chevre/service/payment/any.js +25 -10
  163. package/lib/chevre/service/reserve/useReservation.js +1 -8
  164. package/lib/chevre/service/task.d.ts +9 -0
  165. package/lib/chevre/service/task.js +43 -4
  166. package/lib/chevre/service/transaction/moneyTransfer.js +1 -3
  167. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +16 -16
  168. package/lib/chevre/service/transaction/placeOrder.js +1 -5
  169. package/lib/chevre/service/transaction/placeOrderInProgress.js +2 -2
  170. package/lib/chevre/service/transaction/returnOrder.js +1 -5
  171. package/lib/chevre/service/transaction.d.ts +6 -0
  172. package/lib/chevre/service/transaction.js +9 -7
  173. package/lib/chevre/settings.d.ts +2 -1
  174. package/lib/chevre/settings.js +4 -5
  175. package/package.json +4 -4
  176. package/example/src/chevre/migrateMoneyTransferPendingTransactionIdentifier.ts +0 -96
  177. package/example/src/chevre/migrateMovieAdditionalProperties.ts +0 -98
@@ -16,7 +16,6 @@ const util = require("util");
16
16
  // tslint:disable-next-line:no-require-imports no-var-requires
17
17
  const fpe = require('node-fpe');
18
18
  const factory = require("../factory");
19
- const settings_1 = require("../settings");
20
19
  const ORDER_NUMBER_SEPARATOR = '-';
21
20
  /**
22
21
  * 注文番号リポジトリ
@@ -26,15 +25,7 @@ class RedisRepository {
26
25
  this.redisClient = redisClient;
27
26
  }
28
27
  static createKey(params) {
29
- const useNewKey = params.orderDate instanceof Date
30
- && moment(params.orderDate)
31
- .isSameOrAfter(settings_1.USE_NEW_ORDER_NUMBER_KEY_FROM);
32
- if (useNewKey) {
33
- return util.format('%s:%s:%s', RedisRepository.REDIS_KEY_PREFIX_NEW, params.projectPrefix, params.timestamp);
34
- }
35
- else {
36
- return util.format('%s:%s:%s', RedisRepository.REDIS_KEY_PREFIX, params.projectPrefix, params.timestamp);
37
- }
28
+ return util.format('%s:%s:%s', RedisRepository.REDIS_KEY_PREFIX, params.projectPrefix, params.timestamp);
38
29
  }
39
30
  /**
40
31
  * タイムスタンプから発行する
@@ -79,6 +70,5 @@ class RedisRepository {
79
70
  });
80
71
  }
81
72
  }
82
- RedisRepository.REDIS_KEY_PREFIX_NEW = 'orderNumber';
83
- RedisRepository.REDIS_KEY_PREFIX = 'cinerino:orderNumber';
73
+ RedisRepository.REDIS_KEY_PREFIX = 'orderNumber';
84
74
  exports.RedisRepository = RedisRepository;
@@ -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;
@@ -48,7 +48,11 @@ export declare class MongoRepository {
48
48
  /**
49
49
  * 施設検索
50
50
  */
51
- searchMovieTheaters(params: factory.place.movieTheater.ISearchConditions): Promise<factory.place.movieTheater.IPlaceWithoutScreeningRoom[]>;
51
+ searchMovieTheaters(params: factory.place.movieTheater.ISearchConditions & {
52
+ $projection?: {
53
+ [key: string]: 0;
54
+ };
55
+ }): Promise<factory.place.movieTheater.IPlaceWithoutScreeningRoom[]>;
52
56
  /**
53
57
  * 施設取得
54
58
  */
@@ -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) {
@@ -276,12 +272,7 @@ class MongoRepository {
276
272
  return __awaiter(this, void 0, void 0, function* () {
277
273
  const conditions = MongoRepository.CREATE_MOVIE_THEATER_MONGO_CONDITIONS(params);
278
274
  // containsPlaceを含めるとデータサイズが大きくなるので、検索結果には含めない
279
- const query = this.placeModel.find((conditions.length > 0) ? { $and: conditions } : {}, {
280
- __v: 0,
281
- createdAt: 0,
282
- updatedAt: 0,
283
- containsPlace: 0
284
- });
275
+ const query = this.placeModel.find((conditions.length > 0) ? { $and: conditions } : {}, Object.assign({ __v: 0, createdAt: 0, updatedAt: 0, containsPlace: 0 }, params.$projection));
285
276
  if (typeof params.limit === 'number' && params.limit > 0) {
286
277
  const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
287
278
  query.limit(params.limit)
@@ -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検索条件
@@ -18,10 +18,11 @@ export interface IRateLimitKey {
18
18
  * オファーレート制限リポジトリ
19
19
  */
20
20
  export declare class RedisRepository {
21
- static KEY_PREFIX: string;
21
+ private static readonly KEY_PREFIX_NEW;
22
+ private static readonly KEY_PREFIX;
22
23
  private readonly redisClient;
23
24
  constructor(redisClient: RedisClientType);
24
- static CREATE_REDIS_KEY(ratelimitKey: IRateLimitKey): string;
25
+ private static createKey;
25
26
  /**
26
27
  * ロックする
27
28
  */
@@ -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;
@@ -75,4 +75,5 @@ export declare class StockHolderRepository {
75
75
  startDate: Date;
76
76
  offers: IOffer[];
77
77
  }): Promise<IGetHolderResult[]>;
78
+ private checkIfConflicted;
78
79
  }
@@ -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にする場合
@@ -32,9 +38,11 @@ class StockHolderRepository {
32
38
  return `${params.seatSection}:${params.seatNumber}`;
33
39
  }
34
40
  static createKey(params) {
35
- const useNewKey = params.startDate instanceof Date
36
- && moment(params.startDate)
37
- .isSameOrAfter(settings_1.USE_NEW_EVENT_AVAILABILITY_KEY_FROM);
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);
38
46
  if (useNewKey) {
39
47
  return `${StockHolderRepository.KEY_PREFIX_NEW}:${params.eventId}`;
40
48
  }
@@ -64,7 +72,11 @@ class StockHolderRepository {
64
72
  */
65
73
  lock(lockKey) {
66
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
+ }
67
78
  const key = StockHolderRepository.createKey({ eventId: lockKey.eventId, startDate: lockKey.startDate });
79
+ yield this.checkIfConflicted({ key, eventId: lockKey.eventId });
68
80
  const value = lockKey.holder;
69
81
  const multi = this.redisClient.multi();
70
82
  const fields = lockKey.offers.map((offer) => StockHolderRepository.offer2field(offer));
@@ -74,7 +86,6 @@ class StockHolderRepository {
74
86
  const results = yield multi.expireAt(key, moment(lockKey.expires)
75
87
  .unix())
76
88
  .exec();
77
- debug('results:', results);
78
89
  const lockedFields = [];
79
90
  if (Array.isArray(results)) {
80
91
  results.slice(0, fields.length)
@@ -84,17 +95,25 @@ class StockHolderRepository {
84
95
  }
85
96
  });
86
97
  }
87
- debug('locked fields:', lockedFields);
88
98
  const lockedAll = lockedFields.length === fields.length;
89
99
  debug('lockedAll?', lockedAll);
90
- if (!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) {
91
105
  if (lockedFields.length > 0) {
92
106
  // 全て仮押さえできなければ仮押さえできたものは解除
93
107
  yield this.redisClient.multi()
94
108
  .hDel(key, lockedFields)
95
109
  .exec();
96
110
  }
97
- throw new factory.errors.AlreadyInUse(factory.reservationType.EventReservation, ['ticketedSeat'], 'Already hold');
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
+ }
98
117
  }
99
118
  });
100
119
  }
@@ -104,6 +123,7 @@ class StockHolderRepository {
104
123
  unlock(params) {
105
124
  return __awaiter(this, void 0, void 0, function* () {
106
125
  const key = StockHolderRepository.createKey({ eventId: params.eventId, startDate: params.startDate });
126
+ yield this.checkIfConflicted({ key, eventId: params.eventId });
107
127
  const field = StockHolderRepository.offer2field(params.offer);
108
128
  yield this.redisClient.multi()
109
129
  .hDel(key, field)
@@ -200,6 +220,53 @@ class StockHolderRepository {
200
220
  return result;
201
221
  });
202
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
+ }
203
270
  }
204
271
  StockHolderRepository.KEY_PREFIX_NEW = 'stockHolder';
205
272
  StockHolderRepository.KEY_PREFIX = 'chevre:itemAvailability:screeningEvent';
@@ -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?: {