@chevre/domain 22.10.0-alpha.16 → 22.10.0-alpha.17

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 (35) hide show
  1. package/example/src/chevre/assetTransaction/processReserve.ts +4 -1
  2. package/example/src/chevre/createTaskIfNotExistByAlternateName.ts +1 -1
  3. package/example/src/chevre/{confirmationNumber → transactionNumber}/publishConfimationNumber.ts +6 -3
  4. package/example/src/chevre/transactionNumber/publishOrderNumber.ts +40 -0
  5. package/example/src/chevre/{confirmationNumber → transactionNumber}/setUseMongo4confirmationNumberFrom.ts +9 -6
  6. package/lib/chevre/eventEmitter/task.d.ts +3 -1
  7. package/lib/chevre/eventEmitter.d.ts +2 -2
  8. package/lib/chevre/eventEmitter.js +2 -2
  9. package/lib/chevre/repo/confirmationNumber.d.ts +5 -9
  10. package/lib/chevre/repo/confirmationNumber.js +38 -108
  11. package/lib/chevre/repo/mongoose/schemas/setting.d.ts +2 -0
  12. package/lib/chevre/repo/mongoose/schemas/transactionNumber.d.ts +4 -1
  13. package/lib/chevre/repo/mongoose/schemas/transactionNumber.js +3 -0
  14. package/lib/chevre/repo/orderNumber.d.ts +8 -4
  15. package/lib/chevre/repo/orderNumber.js +51 -23
  16. package/lib/chevre/repo/serviceOutputIdentifier.d.ts +8 -4
  17. package/lib/chevre/repo/serviceOutputIdentifier.js +47 -21
  18. package/lib/chevre/repo/task.d.ts +3 -1
  19. package/lib/chevre/repo/task.js +4 -6
  20. package/lib/chevre/repo/transactionNumber.d.ts +8 -4
  21. package/lib/chevre/repo/transactionNumber.js +47 -21
  22. package/lib/chevre/repo/transactionNumberCounter.d.ts +28 -0
  23. package/lib/chevre/repo/transactionNumberCounter.js +128 -0
  24. package/lib/chevre/service/offer/product.js +0 -40
  25. package/lib/chevre/service/task/acceptCOAOffer.js +2 -2
  26. package/lib/chevre/service/task/authorizePayment.js +3 -3
  27. package/lib/chevre/service/task/givePointAward.js +1 -1
  28. package/lib/chevre/service/task/moneyTransfer.js +1 -1
  29. package/lib/chevre/service/task/publishPaymentUrl.js +2 -2
  30. package/lib/chevre/service/task/refund.js +1 -1
  31. package/lib/chevre/service/task/returnMoneyTransfer.js +1 -1
  32. package/lib/chevre/service/task/returnPayTransaction.js +1 -1
  33. package/lib/chevre/service/task/returnPointAward.js +1 -1
  34. package/lib/chevre/service/task/returnReserveTransaction.js +1 -1
  35. package/package.json +1 -1
@@ -18,7 +18,10 @@ async function main() {
18
18
  await redisClient.connect();
19
19
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
20
20
 
21
- const transactionNumberRepo = await chevre.repository.TransactionNumber.createInstance(redisClient);
21
+ const transactionNumberRepo = await chevre.repository.TransactionNumber.createInstance({
22
+ redisClient,
23
+ connection: mongoose.connection
24
+ });
22
25
  const assetTransactionRepo = await chevre.repository.AssetTransaction.createInstance(mongoose.connection);
23
26
 
24
27
  const { transactionNumber } = await transactionNumberRepo.publishByTimestamp({ startDate: new Date() });
@@ -5,7 +5,7 @@ import { chevre } from '../../../lib/index';
5
5
 
6
6
  const project = { id: String(process.env.PROJECT_ID) };
7
7
 
8
- chevre.eventEmitter.task.onTaskStatusChanged((event) => {
8
+ chevre.eventEmitter.task.taskEventEmitter.onTaskStatusChanged((event) => {
9
9
  console.log('onTaskStatusChanged', event);
10
10
  });
11
11
 
@@ -5,7 +5,7 @@ import { chevre } from '../../../../lib/index';
5
5
 
6
6
  // const project = { id: String(process.env.PROJECT_ID) };
7
7
 
8
- const client = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
8
+ const redisClient = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
9
9
  socket: {
10
10
  port: Number(<string>process.env.REDIS_PORT),
11
11
  host: <string>process.env.REDIS_HOST
@@ -18,11 +18,14 @@ const client = redis.createClient<redis.RedisDefaultModules, Record<string, neve
18
18
  console.error('createDefaultRedisClient: client onError:', err);
19
19
  // reject(err);
20
20
  });
21
- client.connect();
21
+ redisClient.connect();
22
22
  mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
23
23
 
24
24
  async function main() {
25
- const confirmationNumberRepo = await chevre.repository.ConfirmationNumber.createInstance(client, mongoose.connection);
25
+ const confirmationNumberRepo = await chevre.repository.ConfirmationNumber.createInstance({
26
+ redisClient,
27
+ connection: mongoose.connection
28
+ });
26
29
  const result = await confirmationNumberRepo.publish({ orderDate: new Date() });
27
30
  console.log(result);
28
31
  }
@@ -0,0 +1,40 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+ import * as redis from 'redis';
4
+ import { chevre } from '../../../../lib/index';
5
+
6
+ // const project = { id: String(process.env.PROJECT_ID) };
7
+
8
+ const redisClient = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
9
+ socket: {
10
+ port: Number(<string>process.env.REDIS_PORT),
11
+ host: <string>process.env.REDIS_HOST
12
+ },
13
+ password: <string>process.env.REDIS_KEY,
14
+ name: 'checkRedisKeyCount'
15
+ })
16
+ .on('error', (err) => {
17
+ // eslint-disable-next-line no-console
18
+ console.error('createDefaultRedisClient: client onError:', err);
19
+ // reject(err);
20
+ });
21
+ redisClient.connect();
22
+ mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
23
+
24
+ async function main() {
25
+ const orderNumberRepo = await chevre.repository.OrderNumber.createInstance({
26
+ redisClient,
27
+ connection: mongoose.connection
28
+ });
29
+ const result = await orderNumberRepo.publishByTimestamp({
30
+ project: { alternateName: 'CIN' },
31
+ orderDate: new Date()
32
+ });
33
+ console.log(result);
34
+ }
35
+
36
+ main()
37
+ .then(() => {
38
+ console.log('success!');
39
+ })
40
+ .catch(console.error);
@@ -6,7 +6,7 @@ import { chevre } from '../../../../lib/index';
6
6
 
7
7
  // const project = { id: String(process.env.PROJECT_ID) };
8
8
 
9
- const client = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
9
+ const redisClient = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
10
10
  socket: {
11
11
  port: Number(<string>process.env.REDIS_PORT),
12
12
  host: <string>process.env.REDIS_HOST
@@ -19,18 +19,21 @@ const client = redis.createClient<redis.RedisDefaultModules, Record<string, neve
19
19
  console.error('createDefaultRedisClient: client onError:', err);
20
20
  // reject(err);
21
21
  });
22
- client.connect();
22
+ redisClient.connect();
23
23
  mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
24
24
 
25
25
  async function main() {
26
- const confirmationNumberRepo = await chevre.repository.ConfirmationNumber.createInstance(client, mongoose.connection);
26
+ const confirmationNumberRepo = await chevre.repository.ConfirmationNumber.createInstance({
27
+ redisClient,
28
+ connection: mongoose.connection
29
+ });
27
30
  const result = await confirmationNumberRepo.setUseMongo4confirmationNumberFrom({
28
31
  // useMongo4confirmationNumberFrom: moment('2025-05-22T23:50:00Z')
29
32
  // .toDate(),
30
- useMongo4confirmationNumberFrom: moment('2025-05-25T15:00:00Z')
31
- .toDate()
32
- // useMongo4confirmationNumberFrom: moment('2025-05-31T15:00:00Z')
33
+ // useMongo4confirmationNumberFrom: moment('2025-05-25T15:00:00Z')
33
34
  // .toDate()
35
+ useMongo4confirmationNumberFrom: moment('2025-05-31T15:00:00Z')
36
+ .toDate()
34
37
  });
35
38
  console.log(result);
36
39
  }
@@ -1,10 +1,12 @@
1
1
  import { EventEmitter } from 'events';
2
2
  import * as factory from '../factory';
3
+ type ICustomFunction = () => Promise<void>;
3
4
  interface IListenArgsOnTaskStatusChanged {
4
5
  id: string;
5
6
  name?: factory.taskName;
6
7
  status: factory.taskStatus.Ready | factory.taskStatus.Running;
7
8
  expires?: Date;
9
+ customFunction?: ICustomFunction;
8
10
  }
9
11
  type IOnTaskStatusChangedListener = (listenArgs: IListenArgsOnTaskStatusChanged) => void;
10
12
  /**
@@ -15,4 +17,4 @@ declare class TaskEventEmitter extends EventEmitter {
15
17
  emitTaskStatusChanged(args: IListenArgsOnTaskStatusChanged): void;
16
18
  }
17
19
  declare const taskEventEmitter: TaskEventEmitter;
18
- export { IOnTaskStatusChangedListener, taskEventEmitter };
20
+ export { ICustomFunction, IListenArgsOnTaskStatusChanged, IOnTaskStatusChangedListener, taskEventEmitter };
@@ -1,4 +1,4 @@
1
1
  import { assetTransactionEventEmitter } from './eventEmitter/assetTransaction';
2
- import { taskEventEmitter } from './eventEmitter/task';
2
+ import * as task from './eventEmitter/task';
3
3
  import { transactionEventEmitter } from './eventEmitter/transaction';
4
- export { assetTransactionEventEmitter as assetTransaction, taskEventEmitter as task, transactionEventEmitter as transaction };
4
+ export { assetTransactionEventEmitter as assetTransaction, task, transactionEventEmitter as transaction };
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transaction = exports.task = exports.assetTransaction = void 0;
4
4
  const assetTransaction_1 = require("./eventEmitter/assetTransaction");
5
5
  Object.defineProperty(exports, "assetTransaction", { enumerable: true, get: function () { return assetTransaction_1.assetTransactionEventEmitter; } });
6
- const task_1 = require("./eventEmitter/task");
7
- Object.defineProperty(exports, "task", { enumerable: true, get: function () { return task_1.taskEventEmitter; } });
6
+ const task = require("./eventEmitter/task");
7
+ exports.task = task;
8
8
  const transaction_1 = require("./eventEmitter/transaction");
9
9
  Object.defineProperty(exports, "transaction", { enumerable: true, get: function () { return transaction_1.transactionEventEmitter; } });
@@ -5,13 +5,13 @@ import { ISetting } from './mongoose/schemas/setting';
5
5
  * 確認番号リポジトリ
6
6
  */
7
7
  export declare class ConfirmationNumberRepo {
8
- private static readonly REDIS_KEY_PREFIX_NEW;
9
- private readonly redisClient;
10
8
  private readonly settingModel;
11
- private readonly transactionNumberModel;
12
- constructor(redisClient: RedisClientType, connection: Connection);
9
+ private readonly counterRepo;
10
+ constructor(params: {
11
+ redisClient: RedisClientType;
12
+ connection: Connection;
13
+ });
13
14
  private static alignDigits;
14
- private static createKey;
15
15
  private static createDataFeedIdentifier;
16
16
  private static count2confirmationNumber;
17
17
  /**
@@ -26,9 +26,5 @@ export declare class ConfirmationNumberRepo {
26
26
  setUseMongo4confirmationNumberFrom(params: {
27
27
  useMongo4confirmationNumberFrom: Date;
28
28
  }): Promise<Pick<ISetting, "useMongo4confirmationNumberFrom"> | null>;
29
- /**
30
- * 発行する
31
- */
32
- private publishByMongo;
33
29
  private useMongoBySettings;
34
30
  }
@@ -12,24 +12,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.ConfirmationNumberRepo = void 0;
13
13
  const cdigit = require("cdigit");
14
14
  const moment = require("moment-timezone");
15
- const util = require("util");
16
15
  // tslint:disable-next-line:no-require-imports no-var-requires
17
16
  const fpe = require('node-fpe');
18
- const errorHandler_1 = require("../errorHandler");
19
- const factory = require("../factory");
20
17
  const setting_1 = require("./mongoose/schemas/setting");
21
18
  const transactionNumber_1 = require("./mongoose/schemas/transactionNumber");
19
+ const transactionNumberCounter_1 = require("./transactionNumberCounter");
22
20
  const CONFIRMATION_NUMBER_MIN_LENGH = 4;
23
21
  const TIMEZONE = 'Asia/Tokyo';
24
- const MAX_RETRY_INCREMENT = 1;
25
22
  /**
26
23
  * 確認番号リポジトリ
27
24
  */
28
25
  class ConfirmationNumberRepo {
29
- constructor(redisClient, connection) {
30
- this.redisClient = redisClient;
26
+ constructor(params) {
27
+ const { connection } = params;
31
28
  this.settingModel = connection.model(setting_1.modelName, (0, setting_1.createSchema)());
32
- this.transactionNumberModel = connection.model(transactionNumber_1.modelName, (0, transactionNumber_1.createSchema)());
29
+ this.counterRepo = new transactionNumberCounter_1.TransactionNumberCounterRepo(params);
33
30
  }
34
31
  static alignDigits(params) {
35
32
  let aligndNumber = String(params);
@@ -39,11 +36,17 @@ class ConfirmationNumberRepo {
39
36
  }
40
37
  return aligndNumber;
41
38
  }
42
- static createKey(params) {
43
- return util.format('%s:%s', ConfirmationNumberRepo.REDIS_KEY_PREFIX_NEW, moment(params.orderDate)
44
- .tz(TIMEZONE)
45
- .format('YYMM'));
46
- }
39
+ // private static createKey(params: {
40
+ // orderDate: Date;
41
+ // }): string {
42
+ // return util.format(
43
+ // '%s:%s',
44
+ // ConfirmationNumberRepo.REDIS_KEY_PREFIX_NEW,
45
+ // moment(params.orderDate)
46
+ // .tz(TIMEZONE)
47
+ // .format('YYMM')
48
+ // );
49
+ // }
47
50
  static createDataFeedIdentifier(params) {
48
51
  return moment(params.orderDate)
49
52
  .tz(TIMEZONE)
@@ -65,25 +68,33 @@ class ConfirmationNumberRepo {
65
68
  */
66
69
  publish(params) {
67
70
  return __awaiter(this, void 0, void 0, function* () {
71
+ let dataFeedExpires;
72
+ const dataFeedIdentifier = ConfirmationNumberRepo.createDataFeedIdentifier({ orderDate: params.orderDate });
73
+ let incrReply;
68
74
  // support publishByMongo(2025-05-23~)
69
75
  const useMongoBySettings = yield this.useMongoBySettings(params);
70
76
  if (useMongoBySettings) {
71
- return this.publishByMongo(params);
77
+ // データ保管期間はとりあえず2 months
78
+ dataFeedExpires = moment(params.orderDate)
79
+ // tslint:disable-next-line:no-magic-numbers
80
+ .add(2, 'months')
81
+ .toDate();
82
+ incrReply = yield this.counterRepo.incrementByMongo({
83
+ identifier: dataFeedIdentifier,
84
+ includedInDataCatalog: { identifier: transactionNumber_1.DataCatalogIdentifier.confirmationNumber },
85
+ expires: dataFeedExpires
86
+ });
72
87
  }
73
- // データ保管期間はとりあえず一か月
74
- const TTL = moment(params.orderDate)
75
- .add(1, 'month')
76
- .diff(moment(params.orderDate), 'seconds');
77
- const key = ConfirmationNumberRepo.createKey({ orderDate: params.orderDate });
78
- const [incrReply] = yield this.redisClient.multi()
79
- .incr(key)
80
- .expire(key, TTL)
81
- .exec();
82
- // tslint:disable-next-line:no-single-line-block-comment
83
- /* istanbul ignore if */
84
- if (typeof incrReply !== 'number') {
85
- // 基本的にありえないフロー
86
- throw new factory.errors.Internal('confirmation number not incremented unexpectedly');
88
+ else {
89
+ // データ保管期間はとりあえず一か月
90
+ dataFeedExpires = moment(params.orderDate)
91
+ .add(1, 'month')
92
+ .toDate();
93
+ incrReply = yield this.counterRepo.incrementByRedis({
94
+ identifier: dataFeedIdentifier,
95
+ includedInDataCatalog: { identifier: transactionNumber_1.DataCatalogIdentifier.confirmationNumber },
96
+ expires: dataFeedExpires
97
+ });
87
98
  }
88
99
  return ConfirmationNumberRepo.count2confirmationNumber({ count: incrReply });
89
100
  });
@@ -101,86 +112,6 @@ class ConfirmationNumberRepo {
101
112
  .exec();
102
113
  });
103
114
  }
104
- /**
105
- * 発行する
106
- */
107
- publishByMongo(params) {
108
- return __awaiter(this, void 0, void 0, function* () {
109
- const now = new Date();
110
- // データ保管期間はとりあえず2 months
111
- const dataFeedExpires = moment(params.orderDate)
112
- // tslint:disable-next-line:no-magic-numbers
113
- .add(2, 'months')
114
- .toDate();
115
- const dataFeedIdentifier = ConfirmationNumberRepo.createDataFeedIdentifier({ orderDate: params.orderDate });
116
- const dataFeed = {
117
- typeOf: 'DataFeed',
118
- includedInDataCatalog: {
119
- identifier: transactionNumber_1.DataCatalogIdentifier.confirmationNumber,
120
- typeOf: 'DataCatalog'
121
- },
122
- dateCreated: now,
123
- expires: dataFeedExpires,
124
- identifier: dataFeedIdentifier,
125
- interactionStatistic: {
126
- typeOf: 'InteractionCounter',
127
- userInteractionCount: 0
128
- },
129
- project: { id: '*', typeOf: factory.organizationType.Project }
130
- };
131
- const { typeOf, includedInDataCatalog, dateCreated, expires, identifier, project, interactionStatistic } = dataFeed;
132
- let doc;
133
- let retryCount = 0;
134
- while (retryCount <= MAX_RETRY_INCREMENT) {
135
- try {
136
- doc = yield this.transactionNumberModel.findOneAndUpdate({
137
- 'project.id': { $eq: dataFeed.project.id },
138
- 'includedInDataCatalog.identifier': { $eq: dataFeed.includedInDataCatalog.identifier },
139
- identifier: { $eq: dataFeed.identifier }
140
- }, {
141
- $set: {
142
- dateModified: now
143
- },
144
- $setOnInsert: {
145
- typeOf, includedInDataCatalog, dateCreated, expires, identifier, project,
146
- 'interactionStatistic.typeOf': interactionStatistic.typeOf
147
- },
148
- $inc: {
149
- 'interactionStatistic.userInteractionCount': 1
150
- }
151
- }, {
152
- upsert: true,
153
- new: true,
154
- projection: { _id: 0, interactionStatistic: 1 }
155
- })
156
- .lean()
157
- .exec();
158
- break;
159
- }
160
- catch (error) {
161
- if (yield (0, errorHandler_1.isMongoError)(error)) {
162
- if (error.code === errorHandler_1.MongoErrorCode.DuplicateKey) {
163
- // すでに存在するので、リトライすればincrementに成功するはず
164
- retryCount += 1;
165
- continue;
166
- }
167
- }
168
- throw error;
169
- }
170
- }
171
- if (doc === undefined) {
172
- throw new factory.errors.NotFound('DataFeed');
173
- }
174
- const incrReply = doc.interactionStatistic.userInteractionCount;
175
- // tslint:disable-next-line:no-single-line-block-comment
176
- /* istanbul ignore if */
177
- if (typeof incrReply !== 'number') {
178
- // 基本的にありえないフロー
179
- throw new factory.errors.Internal('confirmation number not incremented unexpectedly');
180
- }
181
- return ConfirmationNumberRepo.count2confirmationNumber({ count: incrReply });
182
- });
183
- }
184
115
  useMongoBySettings(params) {
185
116
  return __awaiter(this, void 0, void 0, function* () {
186
117
  const setting = yield this.settingModel.findOne({ 'project.id': { $eq: '*' } }, {
@@ -197,4 +128,3 @@ class ConfirmationNumberRepo {
197
128
  }
198
129
  }
199
130
  exports.ConfirmationNumberRepo = ConfirmationNumberRepo;
200
- ConfirmationNumberRepo.REDIS_KEY_PREFIX_NEW = 'confirmationNumber';
@@ -123,6 +123,8 @@ export interface ISetting {
123
123
  useMongoAsStockHolder?: boolean;
124
124
  useMongoAsStockHolderProjects?: string[];
125
125
  useMongo4confirmationNumberFrom?: Date;
126
+ useMongo4orderNumberFrom?: Date;
127
+ useMongo4transactionNumberFrom?: Date;
126
128
  }
127
129
  type IDocType = ISetting;
128
130
  type IModel = Model<IDocType>;
@@ -1,7 +1,10 @@
1
1
  import { Model, Schema, SchemaDefinition } from 'mongoose';
2
2
  import * as factory from '../../../factory';
3
3
  declare enum DataCatalogIdentifier {
4
- confirmationNumber = "confirmationNumber"
4
+ confirmationNumber = "confirmationNumber",
5
+ transactionNumber = "transactionNumber",
6
+ orderNumber = "orderNumber",
7
+ serviceOutputIdentifier = "serviceOutputIdentifier"
5
8
  }
6
9
  interface IDataCatalog {
7
10
  identifier: DataCatalogIdentifier;
@@ -8,6 +8,9 @@ const settings_1 = require("../../../settings");
8
8
  var DataCatalogIdentifier;
9
9
  (function (DataCatalogIdentifier) {
10
10
  DataCatalogIdentifier["confirmationNumber"] = "confirmationNumber";
11
+ DataCatalogIdentifier["transactionNumber"] = "transactionNumber";
12
+ DataCatalogIdentifier["orderNumber"] = "orderNumber";
13
+ DataCatalogIdentifier["serviceOutputIdentifier"] = "serviceOutputIdentifier";
11
14
  })(DataCatalogIdentifier || (exports.DataCatalogIdentifier = DataCatalogIdentifier = {}));
12
15
  const modelName = 'TransactionNumber';
13
16
  exports.modelName = modelName;
@@ -1,12 +1,15 @@
1
+ import type { Connection } from 'mongoose';
1
2
  import { RedisClientType } from 'redis';
2
3
  /**
3
4
  * 注文番号リポジトリ
4
5
  */
5
6
  export declare class OrderNumberRepo {
6
- private static readonly REDIS_KEY_PREFIX;
7
- private readonly redisClient;
8
- constructor(redisClient: RedisClientType);
9
- private static createKey;
7
+ private readonly settingModel;
8
+ private readonly counterRepo;
9
+ constructor(params: {
10
+ redisClient: RedisClientType;
11
+ connection: Connection;
12
+ });
10
13
  /**
11
14
  * タイムスタンプから発行する
12
15
  */
@@ -19,4 +22,5 @@ export declare class OrderNumberRepo {
19
22
  */
20
23
  orderDate: Date;
21
24
  }): Promise<string>;
25
+ private useMongoBySettings;
22
26
  }
@@ -12,45 +12,60 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.OrderNumberRepo = void 0;
13
13
  const cdigit = require("cdigit");
14
14
  const moment = require("moment-timezone");
15
- const util = require("util");
16
15
  // tslint:disable-next-line:no-require-imports no-var-requires
17
16
  const fpe = require('node-fpe');
18
17
  const factory = require("../factory");
18
+ const setting_1 = require("./mongoose/schemas/setting");
19
+ const transactionNumber_1 = require("./mongoose/schemas/transactionNumber");
20
+ const transactionNumberCounter_1 = require("./transactionNumberCounter");
19
21
  const ORDER_NUMBER_SEPARATOR = '-';
20
22
  /**
21
23
  * 注文番号リポジトリ
22
24
  */
23
25
  class OrderNumberRepo {
24
- constructor(redisClient) {
25
- this.redisClient = redisClient;
26
- }
27
- static createKey(params) {
28
- return util.format('%s:%s:%s', OrderNumberRepo.REDIS_KEY_PREFIX, params.projectPrefix, params.timestamp);
26
+ constructor(params) {
27
+ const { connection } = params;
28
+ this.settingModel = connection.model(setting_1.modelName, (0, setting_1.createSchema)());
29
+ this.counterRepo = new transactionNumberCounter_1.TransactionNumberCounterRepo(params);
29
30
  }
31
+ // private static createKey(params: {
32
+ // orderDate: Date;
33
+ // projectPrefix: string;
34
+ // timestamp: string;
35
+ // }): string {
36
+ // return util.format(
37
+ // '%s:%s:%s',
38
+ // OrderNumberRepo.REDIS_KEY_PREFIX,
39
+ // params.projectPrefix,
40
+ // params.timestamp
41
+ // );
42
+ // }
30
43
  /**
31
44
  * タイムスタンプから発行する
32
45
  */
33
46
  publishByTimestamp(params) {
34
47
  return __awaiter(this, void 0, void 0, function* () {
35
- const projectPrefix = params.project.alternateName
36
- .toUpperCase();
37
48
  const timestamp = moment(params.orderDate)
38
49
  .valueOf()
39
50
  .toString();
40
- const now = moment();
41
- const TTL = moment(params.orderDate)
42
- .add(1, 'minute') // ミリ秒でカウントしていくので、注文日時後1分で十分
43
- .diff(now, 'seconds');
44
- const key = OrderNumberRepo.createKey({ orderDate: params.orderDate, projectPrefix, timestamp });
45
- const [incrReply] = yield this.redisClient.multi()
46
- .incr(key)
47
- .expire(key, TTL)
48
- .exec();
49
- // tslint:disable-next-line:no-single-line-block-comment
50
- /* istanbul ignore if */
51
- if (typeof incrReply !== 'number') {
52
- // 基本的にありえないフロー
53
- throw new factory.errors.Internal('order number not incremented unexpectedly');
51
+ const projectPrefix = params.project.alternateName
52
+ .toUpperCase();
53
+ let dataFeedExpires;
54
+ const dataFeedIdentifier = `${projectPrefix}:${timestamp}`;
55
+ let incrReply;
56
+ const useMongoBySettings = yield this.useMongoBySettings(params);
57
+ if (useMongoBySettings) {
58
+ throw new factory.errors.NotImplemented();
59
+ }
60
+ else {
61
+ dataFeedExpires = moment(params.orderDate)
62
+ .add(1, 'minute') // ミリ秒でカウントしていくので、注文日時後1分で十分
63
+ .toDate();
64
+ incrReply = yield this.counterRepo.incrementByRedis({
65
+ identifier: dataFeedIdentifier,
66
+ includedInDataCatalog: { identifier: transactionNumber_1.DataCatalogIdentifier.orderNumber },
67
+ expires: dataFeedExpires
68
+ });
54
69
  }
55
70
  let orderNumber = `${timestamp}${incrReply}`;
56
71
  // checkdigit
@@ -69,6 +84,19 @@ class OrderNumberRepo {
69
84
  return orderNumber;
70
85
  });
71
86
  }
87
+ useMongoBySettings(params) {
88
+ return __awaiter(this, void 0, void 0, function* () {
89
+ const setting = yield this.settingModel.findOne({ 'project.id': { $eq: '*' } }, {
90
+ _id: 0,
91
+ useMongo4orderNumberFrom: 1
92
+ })
93
+ .lean()
94
+ .exec();
95
+ const useMongo4orderNumberFrom = setting === null || setting === void 0 ? void 0 : setting.useMongo4orderNumberFrom;
96
+ return useMongo4orderNumberFrom instanceof Date
97
+ && moment(params.orderDate)
98
+ .isSameOrAfter(moment(useMongo4orderNumberFrom));
99
+ });
100
+ }
72
101
  }
73
102
  exports.OrderNumberRepo = OrderNumberRepo;
74
- OrderNumberRepo.REDIS_KEY_PREFIX = 'orderNumber';
@@ -1,16 +1,20 @@
1
+ import type { Connection } from 'mongoose';
1
2
  import { RedisClientType } from 'redis';
2
3
  /**
3
4
  * サービスアウトプット識別子リポジトリ
4
5
  */
5
6
  export declare class ServiceOutputIdentifierRepo {
6
- private static readonly REDIS_KEY_PREFIX;
7
- private readonly redisClient;
8
- constructor(redisClient: RedisClientType);
9
- private static createKey;
7
+ private readonly settingModel;
8
+ private readonly counterRepo;
9
+ constructor(params: {
10
+ redisClient: RedisClientType;
11
+ connection: Connection;
12
+ });
10
13
  /**
11
14
  * タイムスタンプから発行する
12
15
  */
13
16
  publishByTimestamp(params: {
14
17
  startDate: Date;
15
18
  }): Promise<string>;
19
+ private useMongoBySettings;
16
20
  }
@@ -12,20 +12,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.ServiceOutputIdentifierRepo = void 0;
13
13
  const cdigit = require("cdigit");
14
14
  const moment = require("moment-timezone");
15
- const util = require("util");
16
15
  // tslint:disable-next-line:no-require-imports no-var-requires
17
16
  const fpe = require('node-fpe');
18
17
  const factory = require("../factory");
18
+ const setting_1 = require("./mongoose/schemas/setting");
19
+ const transactionNumber_1 = require("./mongoose/schemas/transactionNumber");
20
+ const transactionNumberCounter_1 = require("./transactionNumberCounter");
19
21
  /**
20
22
  * サービスアウトプット識別子リポジトリ
21
23
  */
22
24
  class ServiceOutputIdentifierRepo {
23
- constructor(redisClient) {
24
- this.redisClient = redisClient;
25
- }
26
- static createKey(params) {
27
- return util.format('%s:%s', ServiceOutputIdentifierRepo.REDIS_KEY_PREFIX, params.timestamp);
25
+ constructor(params) {
26
+ const { connection } = params;
27
+ this.settingModel = connection.model(setting_1.modelName, (0, setting_1.createSchema)());
28
+ this.counterRepo = new transactionNumberCounter_1.TransactionNumberCounterRepo(params);
28
29
  }
30
+ // private static createKey(params: {
31
+ // startDate: Date;
32
+ // timestamp: string;
33
+ // }): string {
34
+ // return util.format(
35
+ // '%s:%s',
36
+ // ServiceOutputIdentifierRepo.REDIS_KEY_PREFIX,
37
+ // params.timestamp
38
+ // );
39
+ // }
29
40
  /**
30
41
  * タイムスタンプから発行する
31
42
  */
@@ -34,20 +45,22 @@ class ServiceOutputIdentifierRepo {
34
45
  const timestamp = moment(params.startDate)
35
46
  .valueOf()
36
47
  .toString();
37
- const now = moment();
38
- const TTL = moment(params.startDate)
39
- .add(1, 'minute') // ミリ秒でカウントしていくので、予約日時後1分で十分
40
- .diff(now, 'seconds');
41
- const key = ServiceOutputIdentifierRepo.createKey({ startDate: params.startDate, timestamp });
42
- const [incrReply] = yield this.redisClient.multi()
43
- .incr(key)
44
- .expire(key, TTL)
45
- .exec();
46
- // tslint:disable-next-line:no-single-line-block-comment
47
- /* istanbul ignore else: please write tests */
48
- if (typeof incrReply !== 'number') {
49
- // 基本的にありえないフロー
50
- throw new factory.errors.Internal('serviceOutput identifier not incremented unexpectedly');
48
+ let dataFeedExpires;
49
+ const dataFeedIdentifier = timestamp;
50
+ let incrReply;
51
+ const useMongoBySettings = yield this.useMongoBySettings(params);
52
+ if (useMongoBySettings) {
53
+ throw new factory.errors.NotImplemented();
54
+ }
55
+ else {
56
+ dataFeedExpires = moment(params.startDate)
57
+ .add(1, 'minute') // ミリ秒でカウントしていくので、予約日時後1分で十分
58
+ .toDate();
59
+ incrReply = yield this.counterRepo.incrementByRedis({
60
+ identifier: dataFeedIdentifier,
61
+ includedInDataCatalog: { identifier: transactionNumber_1.DataCatalogIdentifier.serviceOutputIdentifier },
62
+ expires: dataFeedExpires
63
+ });
51
64
  }
52
65
  let identifier = `${timestamp}${incrReply}`;
53
66
  // checkdigit
@@ -58,6 +71,19 @@ class ServiceOutputIdentifierRepo {
58
71
  return identifier;
59
72
  });
60
73
  }
74
+ useMongoBySettings(params) {
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ const setting = yield this.settingModel.findOne({ 'project.id': { $eq: '*' } }, {
77
+ _id: 0,
78
+ useMongo4transactionNumberFrom: 1
79
+ })
80
+ .lean()
81
+ .exec();
82
+ const useMongo4transactionNumberFrom = setting === null || setting === void 0 ? void 0 : setting.useMongo4transactionNumberFrom;
83
+ return useMongo4transactionNumberFrom instanceof Date
84
+ && moment(params.startDate)
85
+ .isSameOrAfter(moment(useMongo4transactionNumberFrom));
86
+ });
87
+ }
61
88
  }
62
89
  exports.ServiceOutputIdentifierRepo = ServiceOutputIdentifierRepo;
63
- ServiceOutputIdentifierRepo.REDIS_KEY_PREFIX = 'serviceOutputIdentifier';
@@ -1,4 +1,5 @@
1
1
  import type { AnyKeys, Connection, FilterQuery, ProjectionType, UpdateWriteOpResult } from 'mongoose';
2
+ import { IListenArgsOnTaskStatusChanged } from '../eventEmitter/task';
2
3
  import * as factory from '../factory';
3
4
  import { IModel } from './mongoose/schemas/task';
4
5
  interface IAggregationByStatus {
@@ -36,7 +37,8 @@ export declare class TaskRepo {
36
37
  runImmediately(params: Pick<factory.task.IAttributes<factory.taskName>, 'data' | 'expires' | 'name' | 'project' | 'remainingNumberOfTries' | 'runsAt'> & {
37
38
  alternateName?: never;
38
39
  identifier?: never;
39
- }): Promise<{
40
+ expires: Date;
41
+ }, options: Pick<IListenArgsOnTaskStatusChanged, 'customFunction'>): Promise<{
40
42
  id: string;
41
43
  }>;
42
44
  saveMany(taskAttributes: ICreatingTask[], options: IOptionOnCreate): Promise<{
@@ -156,7 +156,9 @@ class TaskRepo {
156
156
  }
157
157
  runImmediately(
158
158
  // resolve uniqueness of identifier(2025-03-27~)
159
- params) {
159
+ params,
160
+ // support customr function(2025-05-25~)
161
+ options) {
160
162
  return __awaiter(this, void 0, void 0, function* () {
161
163
  var _a, _b;
162
164
  const { expires } = params;
@@ -169,11 +171,7 @@ class TaskRepo {
169
171
  if (typeof id !== 'string') {
170
172
  throw new factory.errors.Internal('task not saved');
171
173
  }
172
- task_1.taskEventEmitter.emitTaskStatusChanged({
173
- id,
174
- status: factory.taskStatus.Ready,
175
- expires // emit expires(2025-03-31~)
176
- });
174
+ task_1.taskEventEmitter.emitTaskStatusChanged(Object.assign({ id, status: factory.taskStatus.Ready, expires }, (typeof options.customFunction === 'function') ? { customFunction: options.customFunction } : undefined));
177
175
  return { id };
178
176
  });
179
177
  }
@@ -1,3 +1,4 @@
1
+ import type { Connection } from 'mongoose';
1
2
  import { RedisClientType } from 'redis';
2
3
  interface IPublishResult {
3
4
  transactionNumber: string;
@@ -6,15 +7,18 @@ interface IPublishResult {
6
7
  * 取引番号リポジトリ
7
8
  */
8
9
  export declare class TransactionNumberRepo {
9
- private static readonly REDIS_KEY_PREFIX;
10
- private readonly redisClient;
11
- constructor(redisClient: RedisClientType);
12
- private static createKey;
10
+ private readonly settingModel;
11
+ private readonly counterRepo;
12
+ constructor(params: {
13
+ redisClient: RedisClientType;
14
+ connection: Connection;
15
+ });
13
16
  /**
14
17
  * タイムスタンプから発行する
15
18
  */
16
19
  publishByTimestamp(params: {
17
20
  startDate: Date;
18
21
  }): Promise<IPublishResult>;
22
+ private useMongoBySettings;
19
23
  }
20
24
  export {};
@@ -12,20 +12,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.TransactionNumberRepo = void 0;
13
13
  const cdigit = require("cdigit");
14
14
  const moment = require("moment-timezone");
15
- const util = require("util");
16
15
  // tslint:disable-next-line:no-require-imports no-var-requires
17
16
  const fpe = require('node-fpe');
18
17
  const factory = require("../factory");
18
+ const setting_1 = require("./mongoose/schemas/setting");
19
+ const transactionNumber_1 = require("./mongoose/schemas/transactionNumber");
20
+ const transactionNumberCounter_1 = require("./transactionNumberCounter");
19
21
  /**
20
22
  * 取引番号リポジトリ
21
23
  */
22
24
  class TransactionNumberRepo {
23
- constructor(redisClient) {
24
- this.redisClient = redisClient;
25
- }
26
- static createKey(params) {
27
- return util.format('%s:%s', TransactionNumberRepo.REDIS_KEY_PREFIX, params.timestamp);
25
+ constructor(params) {
26
+ const { connection } = params;
27
+ this.settingModel = connection.model(setting_1.modelName, (0, setting_1.createSchema)());
28
+ this.counterRepo = new transactionNumberCounter_1.TransactionNumberCounterRepo(params);
28
29
  }
30
+ // private static createKey(params: {
31
+ // startDate: Date;
32
+ // timestamp: string;
33
+ // }): string {
34
+ // return util.format(
35
+ // '%s:%s',
36
+ // TransactionNumberRepo.REDIS_KEY_PREFIX,
37
+ // params.timestamp
38
+ // );
39
+ // }
29
40
  /**
30
41
  * タイムスタンプから発行する
31
42
  */
@@ -34,20 +45,22 @@ class TransactionNumberRepo {
34
45
  const timestamp = moment(params.startDate)
35
46
  .valueOf()
36
47
  .toString();
37
- const now = moment();
38
- const TTL = moment(params.startDate)
39
- .add(1, 'minute') // ミリ秒でカウントしていくので、予約日時後1分で十分
40
- .diff(now, 'seconds');
41
- const key = TransactionNumberRepo.createKey({ startDate: params.startDate, timestamp });
42
- const [incrReply] = yield this.redisClient.multi()
43
- .incr(key)
44
- .expire(key, TTL)
45
- .exec();
46
- // tslint:disable-next-line:no-single-line-block-comment
47
- /* istanbul ignore else: please write tests */
48
- if (typeof incrReply !== 'number') {
49
- // 基本的にありえないフロー
50
- throw new factory.errors.Internal('transaction number not incremented unexpectedly');
48
+ let dataFeedExpires;
49
+ const dataFeedIdentifier = timestamp;
50
+ let incrReply;
51
+ const useMongoBySettings = yield this.useMongoBySettings(params);
52
+ if (useMongoBySettings) {
53
+ throw new factory.errors.NotImplemented();
54
+ }
55
+ else {
56
+ dataFeedExpires = moment(params.startDate)
57
+ .add(1, 'minute') // ミリ秒でカウントしていくので、予約日時後1分で十分
58
+ .toDate();
59
+ incrReply = yield this.counterRepo.incrementByRedis({
60
+ identifier: dataFeedIdentifier,
61
+ includedInDataCatalog: { identifier: transactionNumber_1.DataCatalogIdentifier.transactionNumber },
62
+ expires: dataFeedExpires
63
+ });
51
64
  }
52
65
  let transactionNumber = `${timestamp}${incrReply}`;
53
66
  // checkdigit
@@ -58,6 +71,19 @@ class TransactionNumberRepo {
58
71
  return { transactionNumber };
59
72
  });
60
73
  }
74
+ useMongoBySettings(params) {
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ const setting = yield this.settingModel.findOne({ 'project.id': { $eq: '*' } }, {
77
+ _id: 0,
78
+ useMongo4transactionNumberFrom: 1
79
+ })
80
+ .lean()
81
+ .exec();
82
+ const useMongo4transactionNumberFrom = setting === null || setting === void 0 ? void 0 : setting.useMongo4transactionNumberFrom;
83
+ return useMongo4transactionNumberFrom instanceof Date
84
+ && moment(params.startDate)
85
+ .isSameOrAfter(moment(useMongo4transactionNumberFrom));
86
+ });
87
+ }
61
88
  }
62
89
  exports.TransactionNumberRepo = TransactionNumberRepo;
63
- TransactionNumberRepo.REDIS_KEY_PREFIX = 'transactionNumber';
@@ -0,0 +1,28 @@
1
+ import type { Connection } from 'mongoose';
2
+ import { RedisClientType } from 'redis';
3
+ import { DataCatalogIdentifier } from './mongoose/schemas/transactionNumber';
4
+ /**
5
+ * 取引番号カウンターリポジトリ
6
+ */
7
+ export declare class TransactionNumberCounterRepo {
8
+ private readonly redisClient;
9
+ private readonly transactionNumberModel;
10
+ constructor(params: {
11
+ redisClient: RedisClientType;
12
+ connection: Connection;
13
+ });
14
+ incrementByRedis(params: {
15
+ identifier: string;
16
+ includedInDataCatalog: {
17
+ identifier: DataCatalogIdentifier;
18
+ };
19
+ expires: Date;
20
+ }): Promise<number>;
21
+ incrementByMongo(params: {
22
+ identifier: string;
23
+ includedInDataCatalog: {
24
+ identifier: DataCatalogIdentifier;
25
+ };
26
+ expires: Date;
27
+ }): Promise<number>;
28
+ }
@@ -0,0 +1,128 @@
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.TransactionNumberCounterRepo = void 0;
13
+ const errorHandler_1 = require("../errorHandler");
14
+ const factory = require("../factory");
15
+ const transactionNumber_1 = require("./mongoose/schemas/transactionNumber");
16
+ const MAX_RETRY_INCREMENT = 1;
17
+ /**
18
+ * 取引番号カウンターリポジトリ
19
+ */
20
+ class TransactionNumberCounterRepo {
21
+ constructor(params) {
22
+ const { redisClient, connection } = params;
23
+ this.redisClient = redisClient;
24
+ this.transactionNumberModel = connection.model(transactionNumber_1.modelName, (0, transactionNumber_1.createSchema)());
25
+ }
26
+ incrementByRedis(params) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ // const now = moment();
29
+ const { expires } = params;
30
+ const key = `${params.includedInDataCatalog.identifier}:${params.identifier}`;
31
+ // const TTL = moment(expires)
32
+ // .diff(now, 'seconds');
33
+ const [incrReply, expireAtReply] = yield this.redisClient.multi()
34
+ .incr(key)
35
+ // .expire(key, TTL)
36
+ .expireAt(key, expires)
37
+ .exec();
38
+ // tslint:disable-next-line:no-single-line-block-comment
39
+ /* istanbul ignore else: please write tests */
40
+ if (typeof incrReply !== 'number') {
41
+ // 基本的にありえないフロー
42
+ throw new factory.errors.Internal('transaction number not incremented unexpectedly');
43
+ }
44
+ // expireAtReplyの検証も追加する(2023-04-19~)
45
+ const expiredSet = expireAtReply === 1 || expireAtReply === true;
46
+ if (!expiredSet) {
47
+ // 基本的にありえないフロー
48
+ throw new factory.errors.Internal('transaction number expiration not set unexpectedly');
49
+ }
50
+ return incrReply;
51
+ });
52
+ }
53
+ incrementByMongo(params) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ var _a;
56
+ const now = new Date();
57
+ const dataFeedExpires = params.expires;
58
+ const dataFeedIdentifier = params.identifier;
59
+ const dataFeed = {
60
+ typeOf: 'DataFeed',
61
+ includedInDataCatalog: {
62
+ identifier: params.includedInDataCatalog.identifier,
63
+ typeOf: 'DataCatalog'
64
+ },
65
+ dateCreated: now,
66
+ expires: dataFeedExpires,
67
+ identifier: dataFeedIdentifier,
68
+ interactionStatistic: {
69
+ typeOf: 'InteractionCounter',
70
+ userInteractionCount: 0
71
+ },
72
+ project: { id: '*', typeOf: factory.organizationType.Project }
73
+ };
74
+ const { typeOf, includedInDataCatalog, dateCreated, expires, identifier, project, interactionStatistic } = dataFeed;
75
+ let doc;
76
+ let retryCount = 0;
77
+ while (retryCount <= MAX_RETRY_INCREMENT) {
78
+ try {
79
+ doc = yield this.transactionNumberModel.findOneAndUpdate({
80
+ 'project.id': { $eq: dataFeed.project.id },
81
+ 'includedInDataCatalog.identifier': { $eq: dataFeed.includedInDataCatalog.identifier },
82
+ identifier: { $eq: dataFeed.identifier }
83
+ }, {
84
+ $set: {
85
+ dateModified: now
86
+ },
87
+ $setOnInsert: {
88
+ typeOf, includedInDataCatalog, dateCreated, expires, identifier, project,
89
+ 'interactionStatistic.typeOf': interactionStatistic.typeOf
90
+ },
91
+ $inc: {
92
+ 'interactionStatistic.userInteractionCount': 1
93
+ }
94
+ }, {
95
+ upsert: true,
96
+ new: true,
97
+ projection: { _id: 0, interactionStatistic: 1 }
98
+ })
99
+ .lean()
100
+ .exec();
101
+ break;
102
+ }
103
+ catch (error) {
104
+ if (yield (0, errorHandler_1.isMongoError)(error)) {
105
+ if (error.code === errorHandler_1.MongoErrorCode.DuplicateKey) {
106
+ // すでに存在するので、リトライすればincrementに成功するはず
107
+ retryCount += 1;
108
+ continue;
109
+ }
110
+ }
111
+ throw error;
112
+ }
113
+ }
114
+ if (doc === undefined) {
115
+ throw new factory.errors.NotFound('DataFeed');
116
+ }
117
+ const incrReply = (_a = doc.interactionStatistic) === null || _a === void 0 ? void 0 : _a.userInteractionCount;
118
+ // tslint:disable-next-line:no-single-line-block-comment
119
+ /* istanbul ignore if */
120
+ if (typeof incrReply !== 'number') {
121
+ // 基本的にありえないフロー
122
+ throw new factory.errors.Internal('confirmation number not incremented unexpectedly');
123
+ }
124
+ return incrReply;
125
+ });
126
+ }
127
+ }
128
+ exports.TransactionNumberCounterRepo = TransactionNumberCounterRepo;
@@ -388,43 +388,3 @@ function createServiceOutputIdentifier(params) {
388
388
  })));
389
389
  });
390
390
  }
391
- // function processLockRegisterMembershipService(params: {
392
- // agent: { id: string };
393
- // product: factory.product.IProduct;
394
- // purpose: factory.action.authorize.offer.product.IPurpose;
395
- // }) {
396
- // return async (repos: {
397
- // registerActionInProgress: RegisterServiceInProgressRepo;
398
- // }) => {
399
- // if (params.product.typeOf === factory.product.ProductType.MembershipService) {
400
- // await repos.registerActionInProgress.lock(
401
- // {
402
- // agent: { id: params.agent.id },
403
- // product: { id: String(params.product.id) }
404
- // },
405
- // params.purpose.id
406
- // );
407
- // }
408
- // };
409
- // }
410
- // export function processUnlockRegisterMembershipService(params: {
411
- // agent: { id: string };
412
- // product: { id: string };
413
- // purpose: factory.action.authorize.offer.product.IPurpose;
414
- // }) {
415
- // return async (repos: {
416
- // registerActionInProgress: RegisterServiceInProgressRepo;
417
- // }) => {
418
- // // 登録ロックIDが取引IDであればロック解除
419
- // const holder = await repos.registerActionInProgress.getHolder({
420
- // agent: { id: params.agent.id },
421
- // product: { id: params.product.id }
422
- // });
423
- // if (holder === params.purpose.id) {
424
- // await repos.registerActionInProgress.unlock({
425
- // agent: { id: params.agent.id },
426
- // product: { id: params.product.id }
427
- // });
428
- // }
429
- // };
430
- // }
@@ -86,7 +86,7 @@ function call(params) {
86
86
  })({
87
87
  action: actionRepo,
88
88
  event: new event_1.EventRepo(connection),
89
- orderNumber: new orderNumber_1.OrderNumberRepo(redisClient),
89
+ orderNumber: new orderNumber_1.OrderNumberRepo({ redisClient, connection }),
90
90
  project: new project_1.ProjectRepo(connection),
91
91
  transaction: new transaction_1.TransactionRepo(connection),
92
92
  reserveService,
@@ -104,7 +104,7 @@ function call(params) {
104
104
  })({
105
105
  action: actionRepo,
106
106
  event: new event_1.EventRepo(connection),
107
- orderNumber: new orderNumber_1.OrderNumberRepo(redisClient),
107
+ orderNumber: new orderNumber_1.OrderNumberRepo({ redisClient, connection }),
108
108
  project: new project_1.ProjectRepo(connection),
109
109
  transaction: new transaction_1.TransactionRepo(connection),
110
110
  reserveService,
@@ -57,13 +57,13 @@ function call(params) {
57
57
  action: actionRepo,
58
58
  assetTransaction: new assetTransaction_1.AssetTransactionRepo(connection),
59
59
  authorization: new authorization_1.AuthorizationRepo(connection),
60
- confirmationNumber: new confirmationNumber_1.ConfirmationNumberRepo(redisClient, connection),
60
+ confirmationNumber: new confirmationNumber_1.ConfirmationNumberRepo({ redisClient, connection }),
61
61
  credentials: new credentials_1.CredentialsRepo(redisClient, {
62
62
  scope: `${factory.service.paymentService.PaymentServiceType.MovieTicket}:${paymentServiceId}`,
63
63
  expireInSeconds: (useCredentialsRepo) ? credentialsExpireInSeconds : 0
64
64
  }),
65
65
  event: new event_1.EventRepo(connection),
66
- orderNumber: new orderNumber_1.OrderNumberRepo(redisClient),
66
+ orderNumber: new orderNumber_1.OrderNumberRepo({ redisClient, connection }),
67
67
  paymentAccepted: new sellerPaymentAccepted_1.SellerPaymentAcceptedRepo(connection),
68
68
  paymentService: new paymentService_1.PaymentServiceRepo(connection),
69
69
  paymentServiceProvider: new paymentServiceProvider_1.PaymentServiceProviderRepo(connection),
@@ -73,7 +73,7 @@ function call(params) {
73
73
  task: new task_1.TaskRepo(connection),
74
74
  ticket: new ticket_1.TicketRepo(connection),
75
75
  transaction: new transaction_1.TransactionRepo(connection),
76
- transactionNumber: new transactionNumber_1.TransactionNumberRepo(redisClient),
76
+ transactionNumber: new transactionNumber_1.TransactionNumberRepo({ redisClient, connection }),
77
77
  transactionProcess: transactionProcessRepo
78
78
  }, settings);
79
79
  }
@@ -29,7 +29,7 @@ function call(data) {
29
29
  const assetTransactionRepo = new assetTransaction_1.AssetTransactionRepo(connection);
30
30
  const productRepo = new product_1.ProductRepo(connection);
31
31
  const projectRepo = new project_1.ProjectRepo(connection);
32
- const transactionNumberRepo = new transactionNumber_1.TransactionNumberRepo(redisClient);
32
+ const transactionNumberRepo = new transactionNumber_1.TransactionNumberRepo({ redisClient, connection });
33
33
  yield DeliveryService.givePointAward(data)({
34
34
  action: actionRepo,
35
35
  assetTransaction: assetTransactionRepo,
@@ -25,7 +25,7 @@ function call(data) {
25
25
  }
26
26
  const actionRepo = new action_1.ActionRepo(connection);
27
27
  const productRepo = new product_1.ProductRepo(connection);
28
- const transactionNumberRepo = new transactionNumber_1.TransactionNumberRepo(redisClient);
28
+ const transactionNumberRepo = new transactionNumber_1.TransactionNumberRepo({ redisClient, connection });
29
29
  yield MoneyTransferService.moneyTransfer(data)({
30
30
  action: actionRepo,
31
31
  product: productRepo,
@@ -43,14 +43,14 @@ function call(params) {
43
43
  action: actionRepo,
44
44
  assetTransaction: new assetTransaction_1.AssetTransactionRepo(connection),
45
45
  authorization: new authorization_1.AuthorizationRepo(connection),
46
- orderNumber: new orderNumber_1.OrderNumberRepo(redisClient),
46
+ orderNumber: new orderNumber_1.OrderNumberRepo({ redisClient, connection }),
47
47
  paymentAccepted: new sellerPaymentAccepted_1.SellerPaymentAcceptedRepo(connection),
48
48
  paymentService: new paymentService_1.PaymentServiceRepo(connection),
49
49
  paymentServiceProvider: new paymentServiceProvider_1.PaymentServiceProviderRepo(connection),
50
50
  project: new project_1.ProjectRepo(connection),
51
51
  ticket: new ticket_1.TicketRepo(connection),
52
52
  transaction: new transaction_1.TransactionRepo(connection),
53
- transactionNumber: new transactionNumber_1.TransactionNumberRepo(redisClient)
53
+ transactionNumber: new transactionNumber_1.TransactionNumberRepo({ redisClient, connection })
54
54
  }, settings);
55
55
  }
56
56
  catch (error) {
@@ -58,7 +58,7 @@ function call(params) {
58
58
  project: new project_1.ProjectRepo(connection),
59
59
  task: new task_1.TaskRepo(connection),
60
60
  assetTransaction: new assetTransaction_1.AssetTransactionRepo(connection),
61
- transactionNumber: new transactionNumber_1.TransactionNumberRepo(redisClient)
61
+ transactionNumber: new transactionNumber_1.TransactionNumberRepo({ redisClient, connection })
62
62
  }, settings);
63
63
  });
64
64
  }
@@ -29,7 +29,7 @@ function call(data) {
29
29
  const assetTransactionRepo = new assetTransaction_1.AssetTransactionRepo(connection);
30
30
  const productRepo = new product_1.ProductRepo(connection);
31
31
  const projectRepo = new project_1.ProjectRepo(connection);
32
- const transactionNumberRepo = new transactionNumber_1.TransactionNumberRepo(redisClient);
32
+ const transactionNumberRepo = new transactionNumber_1.TransactionNumberRepo({ redisClient, connection });
33
33
  yield (0, returnMoneyTransfer_1.returnMoneyTransfer)(data)({
34
34
  action: actionRepo,
35
35
  assetTransaction: assetTransactionRepo,
@@ -39,7 +39,7 @@ function call(params) {
39
39
  product: new product_1.ProductRepo(connection),
40
40
  task: new task_1.TaskRepo(connection),
41
41
  transaction: new transaction_1.TransactionRepo(connection),
42
- transactionNumber: new transactionNumber_1.TransactionNumberRepo(redisClient)
42
+ transactionNumber: new transactionNumber_1.TransactionNumberRepo({ redisClient, connection })
43
43
  });
44
44
  });
45
45
  }
@@ -29,7 +29,7 @@ function call(data) {
29
29
  const assetTransactionRepo = new assetTransaction_1.AssetTransactionRepo(connection);
30
30
  const productRepo = new product_1.ProductRepo(connection);
31
31
  const projectRepo = new project_1.ProjectRepo(connection);
32
- const transactionNumberRepo = new transactionNumber_1.TransactionNumberRepo(redisClient);
32
+ const transactionNumberRepo = new transactionNumber_1.TransactionNumberRepo({ redisClient, connection });
33
33
  yield DeliveryService.returnPointAward(data)({
34
34
  action: actionRepo,
35
35
  assetTransaction: assetTransactionRepo,
@@ -55,7 +55,7 @@ function call(params) {
55
55
  assetTransaction: new assetTransaction_1.AssetTransactionRepo(connection),
56
56
  project: new project_1.ProjectRepo(connection),
57
57
  reservation: new reservation_1.ReservationRepo(connection),
58
- transactionNumber: new transactionNumber_1.TransactionNumberRepo(redisClient),
58
+ transactionNumber: new transactionNumber_1.TransactionNumberRepo({ redisClient, connection }),
59
59
  reserveService
60
60
  });
61
61
  });
package/package.json CHANGED
@@ -113,5 +113,5 @@
113
113
  "postversion": "git push origin --tags",
114
114
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
115
115
  },
116
- "version": "22.10.0-alpha.16"
116
+ "version": "22.10.0-alpha.17"
117
117
  }