@chevre/domain 25.2.0-alpha.5 → 25.2.0-alpha.51

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 (202) hide show
  1. package/lib/chevre/eventEmitter/task.d.ts +2 -1
  2. package/lib/chevre/factory/customerTelephone2COATelNum.d.ts +3 -0
  3. package/lib/chevre/factory/customerTelephone2COATelNum.js +22 -0
  4. package/lib/chevre/repo/action/acceptPay.d.ts +15 -0
  5. package/lib/chevre/repo/action/acceptPay.js +47 -19
  6. package/lib/chevre/repo/action/actionProcess.js +57 -57
  7. package/lib/chevre/repo/action.d.ts +16 -9
  8. package/lib/chevre/repo/action.js +99 -180
  9. package/lib/chevre/repo/aggregateOffer.d.ts +3 -14
  10. package/lib/chevre/repo/aggregateOffer.js +16 -125
  11. package/lib/chevre/repo/asyncAction.d.ts +69 -0
  12. package/lib/chevre/repo/asyncAction.js +237 -0
  13. package/lib/chevre/repo/concurrentLock.d.ts +3 -1
  14. package/lib/chevre/repo/creativeWork.d.ts +2 -3
  15. package/lib/chevre/repo/credentials.d.ts +2 -1
  16. package/lib/chevre/repo/customerType.d.ts +2 -3
  17. package/lib/chevre/repo/event.d.ts +10 -11
  18. package/lib/chevre/repo/eventOffer.d.ts +4 -5
  19. package/lib/chevre/repo/eventSellerMakesOffer.d.ts +2 -3
  20. package/lib/chevre/repo/eventSeries.d.ts +4 -5
  21. package/lib/chevre/repo/message.d.ts +1 -1
  22. package/lib/chevre/repo/message.js +1 -1
  23. package/lib/chevre/repo/mongoose/schemas/action.js +67 -66
  24. package/lib/chevre/repo/mongoose/schemas/asyncAction.d.ts +11 -0
  25. package/lib/chevre/repo/mongoose/schemas/asyncAction.js +89 -0
  26. package/lib/chevre/repo/mongoose/schemas/order.d.ts +4 -0
  27. package/lib/chevre/repo/mongoose/schemas/order.js +10 -0
  28. package/lib/chevre/repo/mongoose/schemas/setting.d.ts +4 -0
  29. package/lib/chevre/repo/mongoose/schemas/task.js +12 -12
  30. package/lib/chevre/repo/note.d.ts +3 -4
  31. package/lib/chevre/repo/noteAboutOrder.d.ts +2 -3
  32. package/lib/chevre/repo/offer/offerInCatalogReadOnly.d.ts +2 -2
  33. package/lib/chevre/repo/offer/unitPriceInCatalog.d.ts +2 -2
  34. package/lib/chevre/repo/offer/unitPriceInCatalog.js +59 -11
  35. package/lib/chevre/repo/offerCatalog.d.ts +2 -3
  36. package/lib/chevre/repo/offerCatalogItem.d.ts +2 -3
  37. package/lib/chevre/repo/order.d.ts +2 -0
  38. package/lib/chevre/repo/order.js +14 -14
  39. package/lib/chevre/repo/orderInTransaction.d.ts +68 -1
  40. package/lib/chevre/repo/orderInTransaction.js +181 -3
  41. package/lib/chevre/repo/passport.d.ts +2 -1
  42. package/lib/chevre/repo/person.d.ts +0 -15
  43. package/lib/chevre/repo/person.js +122 -108
  44. package/lib/chevre/repo/place/entranceGate.d.ts +4 -5
  45. package/lib/chevre/repo/place/movieTheater.d.ts +3 -4
  46. package/lib/chevre/repo/place/screeningRoom.d.ts +4 -5
  47. package/lib/chevre/repo/place/seat.d.ts +4 -5
  48. package/lib/chevre/repo/place/section.d.ts +3 -4
  49. package/lib/chevre/repo/priceSpecification.d.ts +4 -4
  50. package/lib/chevre/repo/product.d.ts +3 -4
  51. package/lib/chevre/repo/rateLimit/offer.d.ts +3 -1
  52. package/lib/chevre/repo/rateLimit/offer.js +0 -12
  53. package/lib/chevre/repo/reservation.d.ts +2 -3
  54. package/lib/chevre/repo/sellerMakesOffer.d.ts +3 -4
  55. package/lib/chevre/repo/stockHolder.d.ts +1 -1
  56. package/lib/chevre/repo/stockHolder.js +0 -146
  57. package/lib/chevre/repo/transaction/placeOrder.d.ts +2 -45
  58. package/lib/chevre/repo/transaction/placeOrder.js +43 -83
  59. package/lib/chevre/repo/transaction.d.ts +2 -2
  60. package/lib/chevre/repo/transactionNumberCounter.js +0 -34
  61. package/lib/chevre/repo/transactionProcess.d.ts +2 -1
  62. package/lib/chevre/repo/transactionProcess.js +0 -13
  63. package/lib/chevre/repository.d.ts +5 -0
  64. package/lib/chevre/repository.js +12 -1
  65. package/lib/chevre/service/assetTransaction/pay/publishPaymentUrl.js +1 -1
  66. package/lib/chevre/service/assetTransaction/pay/start/factory.d.ts +1 -1
  67. package/lib/chevre/service/assetTransaction/pay/start/factory.js +3 -4
  68. package/lib/chevre/service/assetTransaction/pay/start.d.ts +1 -1
  69. package/lib/chevre/service/asyncAction.d.ts +16 -0
  70. package/lib/chevre/service/asyncAction.js +36 -0
  71. package/lib/chevre/service/asyncActionHandler/onOperationFailed.d.ts +15 -0
  72. package/lib/chevre/service/asyncActionHandler/onOperationFailed.js +42 -0
  73. package/lib/chevre/service/asyncActionHandler.d.ts +13 -0
  74. package/lib/chevre/service/asyncActionHandler.js +89 -0
  75. package/lib/chevre/service/notification/factory.d.ts +2 -4
  76. package/lib/chevre/service/notification/factory.js +26 -24
  77. package/lib/chevre/service/notification/notifyAbortedTasksByEmail.d.ts +11 -5
  78. package/lib/chevre/service/notification/notifyAbortedTasksByEmail.js +11 -3
  79. package/lib/chevre/service/offer/event/authorize/factory.d.ts +3 -5
  80. package/lib/chevre/service/offer/event/authorize/factory.js +93 -75
  81. package/lib/chevre/service/offer/event/authorize.d.ts +0 -4
  82. package/lib/chevre/service/offer/event/authorize.js +2 -2
  83. package/lib/chevre/service/offer/eventServiceByCOA/authorize/factory.d.ts +6 -7
  84. package/lib/chevre/service/offer/eventServiceByCOA/authorize/factory.js +10 -10
  85. package/lib/chevre/service/offer/eventServiceByCOA/authorize/validateAcceptedOffers.js +2 -1
  86. package/lib/chevre/service/offer/eventServiceByCOA/authorize.d.ts +0 -5
  87. package/lib/chevre/service/offer/eventServiceByCOA/authorize.js +15 -12
  88. package/lib/chevre/service/offer/eventServiceByCOA/authorizeByAcceptAction.d.ts +0 -5
  89. package/lib/chevre/service/offer/eventServiceByCOA/authorizeByAcceptAction.js +2 -2
  90. package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.d.ts +4 -0
  91. package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.js +22 -9
  92. package/lib/chevre/service/order/deleteOrder.d.ts +5 -1
  93. package/lib/chevre/service/order/deleteOrder.js +8 -1
  94. package/lib/chevre/service/order/onAssetTransactionStatusChanged/onPayTransactionCanceled.js +19 -11
  95. package/lib/chevre/service/order/onAssetTransactionStatusChanged/onPayTransactionConfirmed.d.ts +2 -0
  96. package/lib/chevre/service/order/onAssetTransactionStatusChanged/paymentDue2Processing.d.ts +2 -2
  97. package/lib/chevre/service/order/onAssetTransactionStatusChanged/paymentDue2Processing.js +1 -7
  98. package/lib/chevre/service/order/onAssetTransactionStatusChanged.d.ts +2 -0
  99. package/lib/chevre/service/order/onAssetTransactionStatusChanged.js +2 -0
  100. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.d.ts +5 -1
  101. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.js +95 -33
  102. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.d.ts +2 -2
  103. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +4 -2
  104. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned.js +2 -6
  105. package/lib/chevre/service/order/payOrder.d.ts +2 -0
  106. package/lib/chevre/service/order/placeOrder/createPlacingOrderFromExistingTransaction.d.ts +2 -1
  107. package/lib/chevre/service/order/placeOrder/createPlacingOrderFromExistingTransaction.js +13 -58
  108. package/lib/chevre/service/order/placeOrder/factory.js +3 -21
  109. package/lib/chevre/service/order/placeOrder.d.ts +4 -5
  110. package/lib/chevre/service/order/placeOrder.js +20 -31
  111. package/lib/chevre/service/payment/any/authorize/fixOrderAsNeeded.js +1 -2
  112. package/lib/chevre/service/payment/any/authorize/fixTransactionNumber.d.ts +3 -2
  113. package/lib/chevre/service/payment/any/authorize/handlePrePublishedPaymentMethodIdOnAuthorizing.d.ts +4 -3
  114. package/lib/chevre/service/payment/any/authorize/handlePrePublishedPaymentMethodIdOnAuthorizing.js +3 -31
  115. package/lib/chevre/service/payment/any/authorize.js +13 -37
  116. package/lib/chevre/service/payment/any/factory.d.ts +7 -7
  117. package/lib/chevre/service/payment/any/factory.js +19 -22
  118. package/lib/chevre/service/payment/any/findAcceptAction.d.ts +3 -1
  119. package/lib/chevre/service/payment/any/findAcceptAction.js +14 -6
  120. package/lib/chevre/service/payment/any/invalidatePaymentUrl.d.ts +2 -0
  121. package/lib/chevre/service/payment/any/invalidatePaymentUrl.js +4 -66
  122. package/lib/chevre/service/payment/any/publishPaymentUrl.d.ts +4 -0
  123. package/lib/chevre/service/payment/any/publishPaymentUrl.js +4 -18
  124. package/lib/chevre/service/payment/any/voidPayTransaction.d.ts +2 -0
  125. package/lib/chevre/service/payment/any/voidPayTransaction.js +1 -23
  126. package/lib/chevre/service/payment/creditCard/authorize/processAuthorizeCreditCard.d.ts +1 -1
  127. package/lib/chevre/service/payment/creditCard/authorize/processAuthorizeCreditCard.js +5 -9
  128. package/lib/chevre/service/reserve/adminFindReservations.d.ts +15 -0
  129. package/lib/chevre/service/reserve/adminFindReservations.js +35 -0
  130. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +17 -8
  131. package/lib/chevre/service/reserve/searchByOrder.js +2 -6
  132. package/lib/chevre/service/reserve.d.ts +2 -2
  133. package/lib/chevre/service/reserve.js +3 -3
  134. package/lib/chevre/service/task/aggregateOffers.d.ts +2 -2
  135. package/lib/chevre/service/task/aggregateOffers.js +2 -1
  136. package/lib/chevre/service/task/aggregateScreeningEvent.d.ts +2 -2
  137. package/lib/chevre/service/task/aggregateScreeningEvent.js +2 -1
  138. package/lib/chevre/service/task/authorizePayment.js +3 -1
  139. package/lib/chevre/service/task/cancelReservation.d.ts +2 -2
  140. package/lib/chevre/service/task/cancelReservation.js +2 -1
  141. package/lib/chevre/service/task/confirmPayTransaction.js +0 -1
  142. package/lib/chevre/service/task/confirmReserveTransaction.js +2 -7
  143. package/lib/chevre/service/task/deleteTransaction.d.ts +2 -2
  144. package/lib/chevre/service/task/deleteTransaction.js +2 -1
  145. package/lib/chevre/service/task/onAssetTransactionStatusChanged.d.ts +2 -2
  146. package/lib/chevre/service/task/onAssetTransactionStatusChanged.js +4 -3
  147. package/lib/chevre/service/task/onEventChanged.d.ts +2 -2
  148. package/lib/chevre/service/task/onEventChanged.js +2 -1
  149. package/lib/chevre/service/task/onOrderPaymentCompleted.d.ts +2 -2
  150. package/lib/chevre/service/task/onOrderPaymentCompleted.js +4 -1
  151. package/lib/chevre/service/task/onResourceUpdated/onAggregateOfferUpdated.js +1 -1
  152. package/lib/chevre/service/task/onResourceUpdated.d.ts +2 -2
  153. package/lib/chevre/service/task/onResourceUpdated.js +2 -1
  154. package/lib/chevre/service/task/placeOrder.d.ts +2 -2
  155. package/lib/chevre/service/task/placeOrder.js +6 -3
  156. package/lib/chevre/service/task/publishPaymentUrl.js +7 -3
  157. package/lib/chevre/service/task/refund.d.ts +2 -2
  158. package/lib/chevre/service/task/refund.js +4 -10
  159. package/lib/chevre/service/task/reserve.d.ts +2 -2
  160. package/lib/chevre/service/task/reserve.js +2 -1
  161. package/lib/chevre/service/task/returnOrder.d.ts +2 -2
  162. package/lib/chevre/service/task/returnOrder.js +2 -1
  163. package/lib/chevre/service/task/sendOrder.d.ts +2 -2
  164. package/lib/chevre/service/task/sendOrder.js +2 -1
  165. package/lib/chevre/service/task/voidPayTransaction.js +3 -7
  166. package/lib/chevre/service/task/voidPayment.d.ts +2 -2
  167. package/lib/chevre/service/task/voidPayment.js +2 -1
  168. package/lib/chevre/service/taskHandler/onOperationFailed.js +1 -1
  169. package/lib/chevre/service/taskHandler.d.ts +2 -2
  170. package/lib/chevre/service/taskHandler.js +36 -37
  171. package/lib/chevre/service/transaction/deleteTransaction/deletePayTransactionsByPlaceOrder.d.ts +15 -0
  172. package/lib/chevre/service/transaction/deleteTransaction/deletePayTransactionsByPlaceOrder.js +51 -0
  173. package/lib/chevre/service/transaction/deleteTransaction/deleteReservationsByPlaceOrder.d.ts +23 -0
  174. package/lib/chevre/service/transaction/deleteTransaction/deleteReservationsByPlaceOrder.js +64 -0
  175. package/lib/chevre/service/transaction/deleteTransaction.js +15 -152
  176. package/lib/chevre/service/transaction/placeOrder/confirm/potentialActions/sendEmailMessage.d.ts +28 -2
  177. package/lib/chevre/service/transaction/placeOrder/confirm/potentialActions/sendEmailMessage.js +11 -12
  178. package/lib/chevre/service/transaction/placeOrder/confirm/potentialActions.d.ts +4 -2
  179. package/lib/chevre/service/transaction/placeOrder/confirm/potentialActions.js +6 -7
  180. package/lib/chevre/service/transaction/placeOrder/confirm/prepareUnitPriceOfferConditions.d.ts +35 -2
  181. package/lib/chevre/service/transaction/placeOrder/confirm/prepareUnitPriceOfferConditions.js +15 -11
  182. package/lib/chevre/service/transaction/placeOrder/confirm/validation/factory.d.ts +5 -1
  183. package/lib/chevre/service/transaction/placeOrder/confirm/validation.d.ts +11 -2
  184. package/lib/chevre/service/transaction/placeOrder/confirm/validation.js +53 -32
  185. package/lib/chevre/service/transaction/placeOrder/confirm.d.ts +6 -5
  186. package/lib/chevre/service/transaction/placeOrder/confirm.js +33 -78
  187. package/lib/chevre/service/transaction/placeOrder/publishConfirmationNumberIfNotExist.d.ts +4 -7
  188. package/lib/chevre/service/transaction/placeOrder/publishConfirmationNumberIfNotExist.js +33 -15
  189. package/lib/chevre/service/transaction/placeOrder/start.d.ts +1 -1
  190. package/lib/chevre/service/transaction/placeOrder/updateAgent/fixCustomer.d.ts +20 -0
  191. package/lib/chevre/service/transaction/placeOrder/updateAgent/fixCustomer.js +63 -0
  192. package/lib/chevre/service/transaction/placeOrder/updateAgent.d.ts +0 -1
  193. package/lib/chevre/service/transaction/placeOrder/updateAgent.js +17 -86
  194. package/lib/chevre/service/transaction/returnOrder/preStart.js +1 -1
  195. package/lib/chevre/service.d.ts +4 -0
  196. package/lib/chevre/service.js +12 -1
  197. package/lib/chevre/taskSettings.d.ts +1 -3
  198. package/package.json +8 -11
  199. package/lib/chevre/service/order/findConfirmedPlaceOrder.d.ts +0 -13
  200. package/lib/chevre/service/order/findConfirmedPlaceOrder.js +0 -32
  201. package/lib/chevre/service/reserve/findReservations.d.ts +0 -33
  202. package/lib/chevre/service/reserve/findReservations.js +0 -61
@@ -1,5 +1,4 @@
1
- import type { BulkWriteResult } from 'mongodb';
2
- import { AnyExpression, Connection, Document, FilterQuery, PipelineStage } from 'mongoose';
1
+ import { AnyExpression, Connection, Document, FilterQuery, PipelineStage, mongo } from 'mongoose';
3
2
  import { factory } from '../factory';
4
3
  import { IDocType as IAggregateOfferDocType } from './mongoose/schemas/aggregateOffer';
5
4
  type IMatchStage = PipelineStage.Match;
@@ -13,7 +12,7 @@ export declare class AggregateOfferRepo {
13
12
  constructor(connection: Connection);
14
13
  static CREATE_MATCH_STAGE(params: Omit<factory.unitPriceOffer.ISearchConditions, 'limit' | 'page' | 'sort'>): IMatchStage[];
15
14
  static CREATE_AGGREGATE_OFFERS_PROJECTION(params: IProjection): Record<string, AnyExpression>;
16
- search(params: factory.unitPriceOffer.ISearchConditions, projection?: IProjection): Promise<factory.aggregateOffer.IAggregateOffer[]>;
15
+ findAggregateOffers(params: factory.unitPriceOffer.ISearchConditions, projection?: IProjection): Promise<Pick<factory.aggregateOffer.IAggregateOffer, 'id' | 'offers' | 'typeOf'>[]>;
17
16
  pushIncludedInDataCatalog(params: {
18
17
  project: {
19
18
  id: string;
@@ -80,7 +79,7 @@ export declare class AggregateOfferRepo {
80
79
  */
81
80
  productType: factory.product.ProductType;
82
81
  }): Promise<{
83
- bulkWriteResult?: BulkWriteResult;
82
+ bulkWriteResult?: mongo.BulkWriteResult;
84
83
  modifiedOffers?: {
85
84
  id: string;
86
85
  }[];
@@ -110,15 +109,5 @@ export declare class AggregateOfferRepo {
110
109
  };
111
110
  };
112
111
  }): Promise<import("mongoose").UpdateWriteOpResult | undefined>;
113
- countIncludedInDataCatalog(params: {
114
- id: {
115
- $eq: string;
116
- };
117
- }): Promise<{
118
- includedInDataCatalogCount: number;
119
- }[]>;
120
- maxIncludedInDataCatalogCount(): Promise<{
121
- includedInDataCatalogCount: number;
122
- }[]>;
123
112
  }
124
113
  export {};
@@ -374,11 +374,11 @@ class AggregateOfferRepo {
374
374
  _id: 0,
375
375
  id: '$_id',
376
376
  typeOf: '$typeOf',
377
- project: '$project',
378
377
  offers: [{ $first: '$offers' }],
379
- highPrice: { $max: '$offers.priceSpecification.price' },
380
- lowPrice: { $min: '$offers.priceSpecification.price' },
381
- offerCount: { $size: '$offers' }
378
+ // project: '$project', // discontinue(2026-07-24~)
379
+ // highPrice: { $max: '$offers.priceSpecification.price' }, // offers.length:1に限定につき廃止(2026-07-24~)
380
+ // lowPrice: { $min: '$offers.priceSpecification.price' }, // offers.length:1に限定につき廃止(2026-07-24~)
381
+ // offerCount: { $size: '$offers' } // offers.length:1に限定につき廃止(2026-07-24~)
382
382
  };
383
383
  const positiveProjectionFields = Object.keys(params)
384
384
  .filter((key) => params[key] !== 0);
@@ -389,11 +389,10 @@ class AggregateOfferRepo {
389
389
  _id: 0,
390
390
  id: '$_id',
391
391
  typeOf: '$typeOf',
392
- project: '$project',
393
- // offers: [{ $first: '$offers' }],
394
- highPrice: { $max: '$offers.priceSpecification.price' },
395
- lowPrice: { $min: '$offers.priceSpecification.price' },
396
- offerCount: { $size: '$offers' }
392
+ // project: '$project', // discontinue(2026-07-24~)
393
+ // highPrice: { $max: '$offers.priceSpecification.price' }, // offers.length:1に限定につき廃止(2026-07-24~)
394
+ // lowPrice: { $min: '$offers.priceSpecification.price' }, // offers.length:1に限定につき廃止(2026-07-24~)
395
+ // offerCount: { $size: '$offers' } // offers.length:1に限定につき廃止(2026-07-24~)
397
396
  };
398
397
  const offersProjection = {};
399
398
  positiveProjectionFields.forEach((field) => {
@@ -410,7 +409,7 @@ class AggregateOfferRepo {
410
409
  }
411
410
  return projectStage;
412
411
  }
413
- async search(params, projection) {
412
+ async findAggregateOffers(params, projection) {
414
413
  const matchStages = AggregateOfferRepo.CREATE_MATCH_STAGE(params);
415
414
  const projectStage = AggregateOfferRepo.CREATE_AGGREGATE_OFFERS_PROJECTION({ ...projection });
416
415
  const sortByPrice = params.sort?.['priceSpecification.price'];
@@ -436,8 +435,11 @@ class AggregateOfferRepo {
436
435
  /* istanbul ignore else */
437
436
  if (typeof params.limit === 'number' && params.limit > 0) {
438
437
  const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
439
- aggregate.limit(params.limit * page)
440
- .skip(params.limit * (page - 1));
438
+ // support skip -> limit(2026-07-24~)
439
+ // aggregate.limit(params.limit * page)
440
+ // .skip(params.limit * (page - 1));
441
+ aggregate.skip(params.limit * (page - 1))
442
+ .limit(params.limit);
441
443
  }
442
444
  return aggregate.exec();
443
445
  }
@@ -499,25 +501,6 @@ class AggregateOfferRepo {
499
501
  }, { projection: { _id: 1 } })
500
502
  .exec();
501
503
  }
502
- // 単価オファー最適化作業における一時的な処理
503
- // public async optimizeOffers() {
504
- // return this.aggregateOfferModel.updateMany(
505
- // {
506
- // $or: [
507
- // { 'offers.id': { $exists: true } },
508
- // { 'offers.project': { $exists: true } }
509
- // ]
510
- // },
511
- // {
512
- // $set: {},
513
- // $unset: {
514
- // 'offers.0.id': 1,
515
- // 'offers.0.project': 1
516
- // }
517
- // }
518
- // )
519
- // .exec();
520
- // }
521
504
  getCursor(conditions, projection) {
522
505
  return this.aggregateOfferModel.find(conditions, projection)
523
506
  .sort({ 'offers.identifier': factory_1.factory.sortType.Ascending })
@@ -530,15 +513,12 @@ class AggregateOfferRepo {
530
513
  async save(params) {
531
514
  let doc;
532
515
  let aggregateOfferId;
533
- // const { $unset, ...paramsWithoutUnset } = params;
534
516
  const { ...paramsWithoutUnset } = params;
535
- // let savedUnitPriceOffer: factory.unitPriceOffer.IUnitPriceOffer;
536
517
  if (typeof params.id !== 'string' || params.id.length === 0) {
537
518
  const { default: uniqid } = await import('uniqid');
538
519
  const newId = uniqid();
539
520
  aggregateOfferId = newId;
540
521
  // サブオファー最適化(2023-12-22~)
541
- // savedUnitPriceOffer = { ...paramsWithoutUnset, id };
542
522
  const { id, project, ...savedUnitPriceOffer } = paramsWithoutUnset; // eslint-disable-line @typescript-eslint/no-unused-vars
543
523
  const aggregateOffer = {
544
524
  typeOf: factory_1.factory.offerType.AggregateOffer,
@@ -552,18 +532,7 @@ class AggregateOfferRepo {
552
532
  }
553
533
  else {
554
534
  aggregateOfferId = params.id;
555
- // const unitPriceOffers = <Pick<factory.unitPriceOffer.IUnitPriceOffer, 'id' | 'identifier' | 'project' | 'typeOf'>[]>
556
- // await this.search(
557
- // {
558
- // limit: 1,
559
- // page: 1,
560
- // project: { id: { $eq: params.project.id } },
561
- // id: { $eq: params.id }
562
- // },
563
- // { identifier: 1, project: 1, typeOf: 1 }
564
- // );
565
- // const originalUnitPriceOffer = unitPriceOffers.shift();
566
- const aggregateOffers = await this.search({
535
+ const aggregateOffers = await this.findAggregateOffers({
567
536
  limit: 1,
568
537
  page: 1,
569
538
  project: { id: { $eq: params.project.id } },
@@ -579,26 +548,17 @@ class AggregateOfferRepo {
579
548
  // サブオファー最適化(2023-12-22~)
580
549
  const subOffer = {
581
550
  ...updateFields,
582
- // id: originalUnitPriceOffer.id,
583
551
  identifier: originalUnitPriceOffer.identifier,
584
- // project: originalUnitPriceOffer.project,
585
552
  typeOf: originalUnitPriceOffer.typeOf
586
553
  };
587
- doc = await this.aggregateOfferModel.findOneAndUpdate(
588
- // { 'offers.id': params.id },
589
- { _id: params.id }, // _idに変更(2023-12-22~)
554
+ doc = await this.aggregateOfferModel.findOneAndUpdate({ _id: params.id }, // _idに変更(2023-12-22~)
590
555
  {
591
556
  $set: {
592
- // 'offers.$[offer]': savedUnitPriceOffer
593
557
  'offers.0': subOffer // _idに変更(2023-12-22~)
594
558
  }
595
559
  }, {
596
560
  upsert: false,
597
561
  new: true
598
- // _idに変更(2023-12-22~)
599
- // arrayFilters: [
600
- // { 'offer.id': { $eq: params.id } }
601
- // ]
602
562
  })
603
563
  .exec();
604
564
  }
@@ -676,7 +636,6 @@ class AggregateOfferRepo {
676
636
  async saveManyByIdentifier4sskts(params) {
677
637
  const { default: uniqid } = await import('uniqid');
678
638
  const insertBulkWriteOps = [];
679
- // const updateBulkWriteOps: AnyBulkWriteOperation[] = [];
680
639
  if (Array.isArray(params)) {
681
640
  params.forEach((p) => {
682
641
  const newOfferId = uniqid();
@@ -710,7 +669,6 @@ class AggregateOfferRepo {
710
669
  }
711
670
  if (insertBulkWriteOps.length > 0) {
712
671
  await this.aggregateOfferModel.bulkWrite(insertBulkWriteOps, { ordered: false });
713
- // await this.aggregateOfferModel.bulkWrite(updateBulkWriteOps, { ordered: false });
714
672
  }
715
673
  }
716
674
  /**
@@ -724,13 +682,6 @@ class AggregateOfferRepo {
724
682
  'project.id': { $eq: params.project.id },
725
683
  'offers.addOn.itemOffered.id': { $exists: true, $in: params.addOn.itemOffered.id.$in }
726
684
  };
727
- // const updatingOffers = <Pick<factory.unitPriceOffer.IUnitPriceOffer, 'id' | 'identifier'>[]>await this.search(
728
- // {
729
- // project: { id: { $eq: params.project.id } },
730
- // addOn: { itemOffered: { id: { $in: params.addOn.itemOffered.id.$in } } }
731
- // },
732
- // { identifier: 1 }
733
- // );
734
685
  return this.aggregateOfferModel.updateMany(conditions, {
735
686
  $pull: {
736
687
  'offers.$[offer].addOn': {
@@ -743,66 +694,6 @@ class AggregateOfferRepo {
743
694
  ]
744
695
  })
745
696
  .exec();
746
- // if (updatingOffers.length > 0) {
747
- // // no op
748
- // }
749
- // return result;
750
- }
751
- async countIncludedInDataCatalog(params) {
752
- const aggregate = this.aggregateOfferModel.aggregate([
753
- {
754
- $match: {
755
- _id: { $eq: params.id.$eq }
756
- }
757
- },
758
- {
759
- $project: {
760
- _id: 0,
761
- includedInDataCatalogCount: {
762
- $cond: {
763
- if: { $isArray: '$includedInDataCatalog' },
764
- then: { $size: '$includedInDataCatalog' },
765
- else: 0
766
- }
767
- }
768
- }
769
- }
770
- ]);
771
- return aggregate.exec();
772
- }
773
- async maxIncludedInDataCatalogCount() {
774
- const aggregate = this.aggregateOfferModel.aggregate([
775
- // {
776
- // $match: {
777
- // _id: { $eq: params.id.$eq }
778
- // }
779
- // },
780
- {
781
- $project: {
782
- _id: 0,
783
- includedInDataCatalogCount: {
784
- $cond: {
785
- if: { $isArray: '$includedInDataCatalog' },
786
- then: { $size: '$includedInDataCatalog' },
787
- else: 0
788
- }
789
- }
790
- }
791
- },
792
- {
793
- $group: {
794
- _id: null,
795
- maxCount: { $max: '$includedInDataCatalogCount' }
796
- }
797
- },
798
- {
799
- $project: {
800
- _id: 0,
801
- maxCount: '$maxCount'
802
- }
803
- }
804
- ]);
805
- return aggregate.exec();
806
697
  }
807
698
  }
808
699
  exports.AggregateOfferRepo = AggregateOfferRepo;
@@ -0,0 +1,69 @@
1
+ import type { Connection, FilterQuery } from 'mongoose';
2
+ import { factory } from '../factory';
3
+ import { IModel, IDocType } from './mongoose/schemas/asyncAction';
4
+ import type { IExecutableTask } from '../taskSettings';
5
+ type ISavingTask = Pick<factory.task.IAttributes<factory.taskName>, 'data' | 'executionResults' | 'expires' | 'name' | 'project' | 'runsAt' | 'status'> & {
6
+ expires: Date;
7
+ };
8
+ export type IExecutableAsyncAction = Pick<IExecutableTask<factory.taskName>, 'data' | 'expires' | 'id' | 'name' | 'project' | 'runsAt' | 'status'>;
9
+ type IKeyOfProjection = keyof factory.task.ITask<factory.taskName>;
10
+ type IFindParams = Pick<factory.task.ISearchConditions, 'id' | 'name' | 'project' | 'runsFrom' | 'runsThrough' | 'status' | 'limit' | 'page' | 'sort'>;
11
+ /**
12
+ * 非同期アクションリポジトリ
13
+ */
14
+ export declare class AsyncActionRepo {
15
+ readonly asyncActionModel: IModel;
16
+ constructor(connection: Connection);
17
+ static CREATE_MONGO_CONDITIONS(params: Pick<IFindParams, 'id' | 'name' | 'project' | 'runsFrom' | 'runsThrough' | 'status'>): FilterQuery<import("@chevre/factory/lib/chevre/task").ITask | import("@chevre/factory/lib/chevre/task/confirmPayTransaction").ITask | import("@chevre/factory/lib/chevre/task/confirmReserveTransaction").ITask | import("@chevre/factory/lib/chevre/task/createAccountingReport").ITask | import("@chevre/factory/lib/chevre/task/deleteTransaction").ITask | import("@chevre/factory/lib/chevre/task/onAssetTransactionStatusChanged").ITask | import("@chevre/factory/lib/chevre/task/onAuthorizationCreated").ITask | import("@chevre/factory/lib/chevre/task/onEventChanged").ITask | import("@chevre/factory/lib/chevre/task/onResourceDeleted").ITask | import("@chevre/factory/lib/chevre/task/onResourceUpdated").ITask | import("@chevre/factory/lib/chevre/task/onOrderPaymentCompleted").ITask | import("@chevre/factory/lib/chevre/task/placeOrder").ITask | import("@chevre/factory/lib/chevre/task/returnOrder").ITask | import("@chevre/factory/lib/chevre/task/returnPayTransaction").ITask | import("@chevre/factory/lib/chevre/task/returnReserveTransaction").ITask | import("@chevre/factory/lib/chevre/task/sendEmailMessage").ITask | import("@chevre/factory/lib/chevre/task/sendOrder").ITask | import("@chevre/factory/lib/chevre/task/triggerWebhook").ITask | import("@chevre/factory/lib/chevre/task/useReservation").ITask | import("@chevre/factory/lib/chevre/task/voidPayTransaction").ITask | import("@chevre/factory/lib/chevre/task/voidReserveTransaction").ITask>[];
18
+ findAsyncActions(params: IFindParams, inclusion: IKeyOfProjection[]): Promise<(IDocType & {
19
+ id: string;
20
+ })[]>;
21
+ /**
22
+ * Readyタスクをひとつ追加する
23
+ */
24
+ addReadyAsyncAction(params: Pick<ISavingTask, 'data' | 'expires' | 'name' | 'project' | 'runsAt'> & {
25
+ alternateName?: never;
26
+ identifier?: never;
27
+ }): Promise<{
28
+ id: string;
29
+ }>;
30
+ /**
31
+ * Ready -> Running
32
+ */
33
+ executeAsyncActionById(params: {
34
+ id: string;
35
+ executor: {
36
+ name: string;
37
+ };
38
+ }): Promise<IExecutableAsyncAction | null>;
39
+ /**
40
+ * 非同期アクションの状態を参照する
41
+ */
42
+ findAsyncActionById(params: {
43
+ id: {
44
+ $eq: string;
45
+ };
46
+ project: {
47
+ id: {
48
+ $eq: string;
49
+ };
50
+ };
51
+ name: factory.taskName;
52
+ }, inclusion: IKeyOfProjection[]): Promise<(IDocType & {
53
+ id: string;
54
+ } | undefined)>;
55
+ /**
56
+ * タスクIDから実行結果とステータスを保管する
57
+ * Abortedの場合、dateAbortedもセットする
58
+ */
59
+ setExecutionResultAndStatus(params: {
60
+ /**
61
+ * タスクID
62
+ */
63
+ id: string;
64
+ }, update: {
65
+ status: factory.taskStatus.Executed | factory.taskStatus.Aborted;
66
+ executionResult: factory.task.IExecutionResult;
67
+ }): Promise<void>;
68
+ }
69
+ export {};
@@ -0,0 +1,237 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AsyncActionRepo = void 0;
4
+ const factory_1 = require("../factory");
5
+ const settings_1 = require("../settings");
6
+ const asyncAction_1 = require("./mongoose/schemas/asyncAction");
7
+ const executableTaskProjection = {
8
+ _id: 0,
9
+ id: { $toString: '$_id' },
10
+ // 必要最低限にprojection(2024-04-23~)
11
+ data: 1,
12
+ name: 1,
13
+ status: 1,
14
+ project: 1,
15
+ runsAt: 1,
16
+ expires: 1
17
+ };
18
+ const AVAILABLE_PROJECT_FIELDS = [
19
+ 'project',
20
+ 'name',
21
+ 'status',
22
+ 'runsAt',
23
+ 'lastTriedAt',
24
+ 'executionResults',
25
+ 'executor',
26
+ 'data',
27
+ 'dateAborted',
28
+ 'expires'
29
+ ];
30
+ /**
31
+ * 非同期アクションリポジトリ
32
+ */
33
+ class AsyncActionRepo {
34
+ asyncActionModel;
35
+ constructor(connection) {
36
+ this.asyncActionModel = connection.model(asyncAction_1.modelName, (0, asyncAction_1.createSchema)());
37
+ }
38
+ static CREATE_MONGO_CONDITIONS(params) {
39
+ const andConditions = [];
40
+ const idEq = params.id?.$eq;
41
+ if (typeof idEq === 'string') {
42
+ andConditions.push({ _id: { $eq: idEq } });
43
+ }
44
+ const projectIdEq = params.project?.id?.$eq;
45
+ if (typeof projectIdEq === 'string') {
46
+ andConditions.push({ 'project.id': { $eq: projectIdEq } });
47
+ }
48
+ if (typeof params.name === 'string') {
49
+ andConditions.push({ name: { $eq: params.name } });
50
+ }
51
+ else {
52
+ const nameIn = params.name?.$in;
53
+ if (Array.isArray(nameIn)) {
54
+ andConditions.push({ name: { $in: nameIn } });
55
+ }
56
+ const nameNin = params.name?.$nin;
57
+ if (Array.isArray(nameNin)) {
58
+ andConditions.push({ name: { $nin: nameNin } });
59
+ }
60
+ }
61
+ const statusEq = params.status?.$eq;
62
+ if (typeof statusEq === 'string') {
63
+ andConditions.push({ status: { $eq: statusEq } });
64
+ }
65
+ if (params.runsFrom instanceof Date) {
66
+ andConditions.push({ runsAt: { $gte: params.runsFrom } });
67
+ }
68
+ if (params.runsThrough instanceof Date) {
69
+ andConditions.push({ runsAt: { $lte: params.runsThrough } });
70
+ }
71
+ return andConditions;
72
+ }
73
+ async findAsyncActions(params, inclusion) {
74
+ const conditions = AsyncActionRepo.CREATE_MONGO_CONDITIONS(params);
75
+ let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
76
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
77
+ positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
78
+ }
79
+ const projection = {
80
+ _id: 0,
81
+ id: { $toString: '$_id' },
82
+ ...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
83
+ };
84
+ const query = this.asyncActionModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
85
+ if (typeof params.limit === 'number' && params.limit > 0) {
86
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
87
+ query.limit(params.limit)
88
+ .skip(params.limit * (page - 1));
89
+ }
90
+ if (params.sort?.runsAt !== undefined) {
91
+ query.sort({ runsAt: params.sort.runsAt });
92
+ }
93
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
94
+ .lean()
95
+ .exec();
96
+ }
97
+ /**
98
+ * Readyタスクをひとつ追加する
99
+ */
100
+ async addReadyAsyncAction(params) {
101
+ const { expires } = params;
102
+ if (!(expires instanceof Date)) {
103
+ throw new factory_1.factory.errors.Argument('expires', 'must be Date');
104
+ }
105
+ const savingTask = {
106
+ ...params,
107
+ status: factory_1.factory.taskStatus.Ready,
108
+ executionResults: []
109
+ };
110
+ const result = await this.asyncActionModel.insertMany(savingTask, { rawResult: true });
111
+ const id = result.insertedIds?.[0]?.toHexString();
112
+ if (typeof id !== 'string') {
113
+ throw new factory_1.factory.errors.Internal('task not saved');
114
+ }
115
+ return { id };
116
+ }
117
+ /**
118
+ * Ready -> Running
119
+ */
120
+ async executeAsyncActionById(params) {
121
+ const now = new Date();
122
+ const doc = await this.asyncActionModel.findOneAndUpdate({
123
+ _id: { $eq: params.id },
124
+ status: { $eq: factory_1.factory.taskStatus.Ready }, // Readyのものしか実行しない
125
+ runsAt: { $lt: now },
126
+ expires: { $gt: now }, // ワンタイムタスクなのでexpiresは必ず存在する
127
+ }, {
128
+ $set: {
129
+ status: factory_1.factory.taskStatus.Running, // 実行中に変更
130
+ lastTriedAt: now,
131
+ executor: params.executor
132
+ },
133
+ }, { new: true, projection: executableTaskProjection })
134
+ .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
135
+ .lean() // lean(2024-09-26~)
136
+ .exec();
137
+ if (doc === null) {
138
+ return null;
139
+ }
140
+ return doc;
141
+ }
142
+ /**
143
+ * 非同期アクションの状態を参照する
144
+ */
145
+ async findAsyncActionById(params, inclusion) {
146
+ let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
147
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
148
+ positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
149
+ }
150
+ else {
151
+ // no op
152
+ }
153
+ const projection = {
154
+ _id: 0,
155
+ id: { $toString: '$_id' },
156
+ ...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
157
+ };
158
+ const query = this.asyncActionModel.findOne({
159
+ _id: { $eq: params.id.$eq },
160
+ 'project.id': { $eq: params.project.id.$eq },
161
+ name: { $eq: params.name }
162
+ }, projection);
163
+ const doc = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
164
+ .lean()
165
+ .exec();
166
+ if (doc === null) {
167
+ return;
168
+ }
169
+ return doc;
170
+ }
171
+ // /**
172
+ // * Readyのままで期限切れのタスクをExpiredに変更する
173
+ // */
174
+ // public async makeExpiredMany(params: {
175
+ // expiresLt: Date;
176
+ // }): Promise<UpdateWriteOpResult> {
177
+ // const { expiresLt } = params;
178
+ // if (!(expiresLt instanceof Date)) {
179
+ // throw new factory.errors.Argument('expiresLt', 'must be Date');
180
+ // }
181
+ // return this.asyncActionModel.updateMany(
182
+ // {
183
+ // status: { $eq: factory.taskStatus.Ready },
184
+ // expires: { $lt: expiresLt }
185
+ // },
186
+ // {
187
+ // $set: {
188
+ // status: factory.taskStatus.Expired
189
+ // }
190
+ // }
191
+ // )
192
+ // .exec();
193
+ // }
194
+ // /**
195
+ // * taskNameに関わらず、Runningのまま放置された非同期アクションをAbortedに変更する
196
+ // */
197
+ // public async abortMany(params: {
198
+ // intervalInMinutes: number;
199
+ // }): Promise<UpdateWriteOpResult> {
200
+ // const lastTriedAtShoudBeLessThan = moment()
201
+ // .add(-params.intervalInMinutes, 'minutes')
202
+ // .toDate();
203
+ // return this.asyncActionModel.updateMany(
204
+ // {
205
+ // status: { $eq: factory.taskStatus.Running },
206
+ // lastTriedAt: {
207
+ // $exists: true,
208
+ // $lt: lastTriedAtShoudBeLessThan
209
+ // }
210
+ // },
211
+ // {
212
+ // $set: {
213
+ // status: factory.taskStatus.Aborted,
214
+ // dateAborted: new Date()
215
+ // }
216
+ // }
217
+ // )
218
+ // .exec();
219
+ // }
220
+ /**
221
+ * タスクIDから実行結果とステータスを保管する
222
+ * Abortedの場合、dateAbortedもセットする
223
+ */
224
+ async setExecutionResultAndStatus(params, update) {
225
+ const { id } = params;
226
+ const { status, executionResult } = update;
227
+ await this.asyncActionModel.updateOne({ _id: { $eq: id } }, {
228
+ $set: {
229
+ status,
230
+ ...(status === factory_1.factory.taskStatus.Aborted) ? { dateAborted: executionResult.endDate } : undefined // 2025-08-04~
231
+ },
232
+ $push: { executionResults: executionResult }
233
+ })
234
+ .exec();
235
+ }
236
+ }
237
+ exports.AsyncActionRepo = AsyncActionRepo;
@@ -1,5 +1,6 @@
1
- import type { RedisClientType } from 'redis';
1
+ import type { createClient } from 'redis';
2
2
  import { AbstractConcurrentLockRepo, ILockParams, IUnlockParams } from './concurrentLockAbstract';
3
+ type RedisClientType = ReturnType<typeof createClient>;
3
4
  /**
4
5
  * 同時実行ロックリポジトリ
5
6
  */
@@ -12,3 +13,4 @@ export declare class ConcurrentLockRepo implements AbstractConcurrentLockRepo {
12
13
  lock(params: ILockParams): Promise<void>;
13
14
  unlock(params: IUnlockParams): Promise<void>;
14
15
  }
16
+ export {};
@@ -1,5 +1,4 @@
1
- import type { BulkWriteResult } from 'mongodb';
2
- import { Connection, FilterQuery, Types } from 'mongoose';
1
+ import { Connection, FilterQuery, Types, mongo } from 'mongoose';
3
2
  import { factory } from '../factory';
4
3
  import { IDocType } from './mongoose/schemas/creativeWork';
5
4
  type IKeyOfProjection = keyof factory.creativeWork.movie.ICreativeWork;
@@ -32,7 +31,7 @@ export declare class CreativeWorkRepo {
32
31
  [key in keyof factory.creativeWork.movie.ICreativeWork]?: 1;
33
32
  };
34
33
  }[]): Promise<{
35
- bulkWriteResult?: BulkWriteResult;
34
+ bulkWriteResult?: mongo.BulkWriteResult;
36
35
  }>;
37
36
  /**
38
37
  * コンテンツを検索する
@@ -1,9 +1,10 @@
1
1
  import type { COA } from '@motionpicture/coa-service';
2
- import type { RedisClientType } from 'redis';
2
+ import type { createClient } from 'redis';
3
3
  interface IOptions {
4
4
  scope: string;
5
5
  expireInSeconds: number;
6
6
  }
7
+ type RedisClientType = ReturnType<typeof createClient>;
7
8
  /**
8
9
  * 認証情報リポジトリ
9
10
  */
@@ -1,5 +1,4 @@
1
- import type { BulkWriteResult } from 'mongodb';
2
- import { Connection, FilterQuery } from 'mongoose';
1
+ import type { Connection, FilterQuery, mongo } from 'mongoose';
3
2
  import { ICustomerType } from './mongoose/schemas/customerType';
4
3
  import { factory } from '../factory';
5
4
  type IKeyOfProjection = keyof ICustomerType;
@@ -17,6 +16,6 @@ export declare class CustomerTypeRepo {
17
16
  saveManyByCodeValue(params: {
18
17
  attributes: ICustomerType;
19
18
  upsert?: boolean;
20
- }[]): Promise<BulkWriteResult | undefined>;
19
+ }[]): Promise<mongo.BulkWriteResult | undefined>;
21
20
  }
22
21
  export {};