@chevre/domain 21.1.0-alpha.0 → 21.1.0-alpha.1

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 (27) hide show
  1. package/example/src/chevre/aggregateAllEvents2.ts +10 -7
  2. package/example/src/chevre/aggregateEventReservation.ts +7 -4
  3. package/example/src/chevre/processPay.ts +7 -4
  4. package/example/src/chevre/processRegisterMembership.ts +0 -5
  5. package/example/src/chevre/processRegisterPaymentCard.ts +0 -5
  6. package/example/src/chevre/processReserve.ts +7 -4
  7. package/example/src/chevre/redisConfig.ts +24 -0
  8. package/example/src/chevre/searchEventTicketOffers.ts +9 -6
  9. package/example/src/chevre/transaction/callOrderMembershipServiceTask.ts +7 -4
  10. package/example/src/chevre/transaction/orderMembershipService.ts +7 -4
  11. package/lib/chevre/repo/action/registerServiceInProgress.d.ts +2 -2
  12. package/lib/chevre/repo/action/registerServiceInProgress.js +19 -53
  13. package/lib/chevre/repo/confirmationNumber.d.ts +2 -2
  14. package/lib/chevre/repo/confirmationNumber.js +40 -53
  15. package/lib/chevre/repo/itemAvailability/screeningEvent.d.ts +3 -3
  16. package/lib/chevre/repo/itemAvailability/screeningEvent.js +53 -138
  17. package/lib/chevre/repo/orderNumber.d.ts +2 -2
  18. package/lib/chevre/repo/orderNumber.js +44 -55
  19. package/lib/chevre/repo/rateLimit/offer.d.ts +2 -2
  20. package/lib/chevre/repo/rateLimit/offer.js +6 -45
  21. package/lib/chevre/repo/serviceOutputIdentifier.d.ts +2 -2
  22. package/lib/chevre/repo/serviceOutputIdentifier.js +32 -46
  23. package/lib/chevre/repo/transactionNumber.d.ts +2 -2
  24. package/lib/chevre/repo/transactionNumber.js +41 -52
  25. package/lib/chevre/service/task.d.ts +4 -4
  26. package/package.json +3 -6
  27. package/example/src/chevre/copyRedisKeys.ts +0 -102
@@ -30,58 +30,47 @@ class RedisRepository {
30
30
  */
31
31
  publishByTimestamp(params) {
32
32
  return __awaiter(this, void 0, void 0, function* () {
33
- return new Promise((resolve, reject) => {
34
- // tslint:disable-next-line:no-magic-numbers
35
- // const projectPrefix = params.project.id.slice(0, 3)
36
- // .toUpperCase();
37
- const timestamp = moment(params.startDate)
38
- .valueOf()
39
- .toString();
40
- const now = moment();
41
- const TTL = moment(params.startDate)
42
- .add(1, 'minute') // ミリ秒でカウントしていくので、予約日時後1分で十分
43
- .diff(now, 'seconds');
44
- debug(`TTL:${TTL} seconds`);
45
- const key = util.format(
46
- // '%s:%s:%s',
47
- '%s:%s', RedisRepository.REDIS_KEY_PREFIX,
48
- // projectPrefix,
49
- timestamp);
50
- this.redisClient.multi()
51
- .incr(key, debug)
52
- .expire(key, TTL)
53
- .exec((err, results) => {
54
- debug('results:', results);
55
- // tslint:disable-next-line:no-single-line-block-comment
56
- /* istanbul ignore if: please write tests */
57
- if (err instanceof Error) {
58
- reject(err);
59
- }
60
- else {
61
- // tslint:disable-next-line:no-single-line-block-comment
62
- /* istanbul ignore else: please write tests */
63
- if (Array.isArray(results) && Number.isInteger(results[0])) {
64
- let transactionNumber = timestamp;
65
- const no = results[0];
66
- debug('no incremented.', no);
67
- transactionNumber = `${transactionNumber}${no}`;
68
- // checkdigit
69
- const cd = cdigit.luhn.compute(transactionNumber);
70
- const cipher = fpe({ password: cd });
71
- transactionNumber = cipher.encrypt(transactionNumber);
72
- // debug('publishing transactionNumber from', projectPrefix, timestamp, no, cd);
73
- // transactionNumber = `${projectPrefix}${cd}${transactionNumber}`;
74
- debug('publishing transactionNumber from', timestamp, no, cd);
75
- transactionNumber = `${cd}${transactionNumber}`;
76
- resolve({ transactionNumber });
77
- }
78
- else {
79
- // 基本的にありえないフロー
80
- reject(new factory.errors.ServiceUnavailable('Transaction number not published'));
81
- }
82
- }
83
- });
84
- });
33
+ // tslint:disable-next-line:no-magic-numbers
34
+ // const projectPrefix = params.project.id.slice(0, 3)
35
+ // .toUpperCase();
36
+ const timestamp = moment(params.startDate)
37
+ .valueOf()
38
+ .toString();
39
+ const now = moment();
40
+ const TTL = moment(params.startDate)
41
+ .add(1, 'minute') // ミリ秒でカウントしていくので、予約日時後1分で十分
42
+ .diff(now, 'seconds');
43
+ debug(`TTL:${TTL} seconds`);
44
+ const key = util.format(
45
+ // '%s:%s:%s',
46
+ '%s:%s', RedisRepository.REDIS_KEY_PREFIX,
47
+ // projectPrefix,
48
+ timestamp);
49
+ const results = yield this.redisClient.multi()
50
+ .incr(key)
51
+ .expire(key, TTL)
52
+ .exec();
53
+ // tslint:disable-next-line:no-single-line-block-comment
54
+ /* istanbul ignore else: please write tests */
55
+ if (Array.isArray(results) && typeof results[0] === 'number') {
56
+ let transactionNumber = timestamp;
57
+ const no = results[0];
58
+ debug('no incremented.', no);
59
+ transactionNumber = `${transactionNumber}${no}`;
60
+ // checkdigit
61
+ const cd = cdigit.luhn.compute(transactionNumber);
62
+ const cipher = fpe({ password: cd });
63
+ transactionNumber = cipher.encrypt(transactionNumber);
64
+ // debug('publishing transactionNumber from', projectPrefix, timestamp, no, cd);
65
+ // transactionNumber = `${projectPrefix}${cd}${transactionNumber}`;
66
+ debug('publishing transactionNumber from', timestamp, no, cd);
67
+ transactionNumber = `${cd}${transactionNumber}`;
68
+ return { transactionNumber };
69
+ }
70
+ else {
71
+ // 基本的にありえないフロー
72
+ throw new factory.errors.ServiceUnavailable('Transaction number not published');
73
+ }
85
74
  });
86
75
  }
87
76
  }
@@ -1,16 +1,16 @@
1
- import * as mongoose from 'mongoose';
2
- import * as redis from 'redis';
1
+ import { Connection } from 'mongoose';
2
+ import { RedisClientType } from 'redis';
3
3
  import * as factory from '../factory';
4
4
  import { MongoRepository as TaskRepo } from '../repo/task';
5
5
  export interface IConnectionSettings {
6
6
  /**
7
7
  * MongoDBコネクション
8
8
  */
9
- connection: mongoose.Connection;
9
+ connection: Connection;
10
10
  /**
11
11
  * Redisクライアント
12
12
  */
13
- redisClient?: redis.RedisClient;
13
+ redisClient?: RedisClientType;
14
14
  }
15
15
  export type TaskOperation<T> = (repos: {
16
16
  task: TaskRepo;
package/package.json CHANGED
@@ -46,8 +46,6 @@
46
46
  "@types/node": "14.18.42",
47
47
  "@types/power-assert": "^1.5.3",
48
48
  "@types/pug": "^2.0.4",
49
- "@types/redis": "^2.8.32",
50
- "@types/redis-mock": "^0.17.0",
51
49
  "@types/request": "^2.48.5",
52
50
  "@types/request-promise-native": "^1.0.18",
53
51
  "@types/sinon": "^4.3.3",
@@ -64,8 +62,7 @@
64
62
  "nock": "^9.6.1",
65
63
  "nyc": "^15.1.0",
66
64
  "power-assert": "^1.6.1",
67
- "redis": "^3.1.2",
68
- "redis-mock": "^0.56.3",
65
+ "redis": "4.6.5",
69
66
  "request-promise-native": "^1.0.9",
70
67
  "rimraf": "^2.7.1",
71
68
  "sinon": "^4.5.0",
@@ -78,7 +75,7 @@
78
75
  "peerDependencies": {
79
76
  "aws-sdk": "^2.0.0",
80
77
  "mongoose": "^6.0.0",
81
- "redis": "^3.1.2"
78
+ "redis": "^4.6.5"
82
79
  },
83
80
  "engines": {
84
81
  "node": ">=14.0.0",
@@ -120,5 +117,5 @@
120
117
  "postversion": "git push origin --tags",
121
118
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
122
119
  },
123
- "version": "21.1.0-alpha.0"
120
+ "version": "21.1.0-alpha.1"
124
121
  }
@@ -1,102 +0,0 @@
1
- // tslint:disable:no-console
2
- import * as redis from 'redis';
3
- // import * as mongoose from 'mongoose';
4
-
5
- // import { chevre } from '../../../lib/index';
6
-
7
- async function main() {
8
-
9
- const client = redis.createClient({
10
- host: process.env.REDIS_HOST,
11
- port: Number(process.env.REDIS_PORT),
12
- password: process.env.REDIS_KEY,
13
- tls: { servername: process.env.REDIS_HOST }
14
- });
15
-
16
- const newClient = redis.createClient({
17
- host: process.env.NEW_REDIS_HOST,
18
- port: Number(process.env.NEW_REDIS_PORT),
19
- password: process.env.NEW_REDIS_KEY
20
- });
21
-
22
- client.keys('chevre:itemAvailability:screeningEvent:*', async (err, keysreply) => {
23
- console.log(err, keysreply.length, 'keys found');
24
- const targetKeys = keysreply;
25
-
26
- await Promise.all(targetKeys.map(async (targetKey) => {
27
- const newKey = targetKey;
28
-
29
- return new Promise<void>((resolve, reject) => {
30
- client.hgetall(targetKey, (hgetallerr, reply) => {
31
- console.log('reply:', reply);
32
- if (hgetallerr !== null) {
33
- reject(hgetallerr);
34
- } else {
35
- if (reply !== null) {
36
- client.ttl(targetKey, (__, ttl) => {
37
- console.log('ttl:', ttl);
38
- const args = Object.keys(reply)
39
- .reduce(
40
- (a: any[], b) => {
41
- return [...a, b, reply[b]];
42
- },
43
- []
44
- );
45
- console.log(args.length, 'args ready');
46
-
47
- newClient.multi()
48
- .hmset(newKey, ...args)
49
- .expire(newKey, ttl)
50
- .exec((hmsetErr, execreply) => {
51
- console.log('hmset result:', hmsetErr, execreply);
52
- resolve();
53
- });
54
- });
55
- } else {
56
- reject(new Error('targetKey not found'));
57
- }
58
- }
59
- });
60
- });
61
- }));
62
- });
63
-
64
- client.keys('chevre:reservationNumber:*', async (err, keysreply) => {
65
- console.log(err, keysreply.length, 'keys found');
66
- const targetKeys = keysreply;
67
-
68
- await Promise.all(targetKeys.map(async (targetKey) => {
69
- const newKey = targetKey;
70
-
71
- return new Promise<void>((resolve, reject) => {
72
- client.get(targetKey, (hgetallerr, reply) => {
73
- console.log('reply:', reply);
74
- if (hgetallerr !== null) {
75
- reject(hgetallerr);
76
- } else {
77
- if (reply !== null) {
78
- client.ttl(targetKey, (__, ttl) => {
79
- console.log('ttl:', ttl);
80
- const args = reply;
81
-
82
- newClient.multi()
83
- .set(newKey, args)
84
- .expire(newKey, ttl)
85
- .exec((setErr, execreply) => {
86
- console.log('set result:', setErr, execreply);
87
- resolve();
88
- });
89
- });
90
- } else {
91
- reject(new Error('targetKey not found'));
92
- }
93
- }
94
- });
95
- });
96
- }));
97
- });
98
- }
99
-
100
- main()
101
- .then(console.log)
102
- .catch(console.error);