@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.
- package/example/src/chevre/aggregateAllEvents2.ts +10 -7
- package/example/src/chevre/aggregateEventReservation.ts +7 -4
- package/example/src/chevre/processPay.ts +7 -4
- package/example/src/chevre/processRegisterMembership.ts +0 -5
- package/example/src/chevre/processRegisterPaymentCard.ts +0 -5
- package/example/src/chevre/processReserve.ts +7 -4
- package/example/src/chevre/redisConfig.ts +24 -0
- package/example/src/chevre/searchEventTicketOffers.ts +9 -6
- package/example/src/chevre/transaction/callOrderMembershipServiceTask.ts +7 -4
- package/example/src/chevre/transaction/orderMembershipService.ts +7 -4
- package/lib/chevre/repo/action/registerServiceInProgress.d.ts +2 -2
- package/lib/chevre/repo/action/registerServiceInProgress.js +19 -53
- package/lib/chevre/repo/confirmationNumber.d.ts +2 -2
- package/lib/chevre/repo/confirmationNumber.js +40 -53
- package/lib/chevre/repo/itemAvailability/screeningEvent.d.ts +3 -3
- package/lib/chevre/repo/itemAvailability/screeningEvent.js +53 -138
- package/lib/chevre/repo/orderNumber.d.ts +2 -2
- package/lib/chevre/repo/orderNumber.js +44 -55
- package/lib/chevre/repo/rateLimit/offer.d.ts +2 -2
- package/lib/chevre/repo/rateLimit/offer.js +6 -45
- package/lib/chevre/repo/serviceOutputIdentifier.d.ts +2 -2
- package/lib/chevre/repo/serviceOutputIdentifier.js +32 -46
- package/lib/chevre/repo/transactionNumber.d.ts +2 -2
- package/lib/chevre/repo/transactionNumber.js +41 -52
- package/lib/chevre/service/task.d.ts +4 -4
- package/package.json +3 -6
- 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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
|
2
|
-
import
|
|
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:
|
|
9
|
+
connection: Connection;
|
|
10
10
|
/**
|
|
11
11
|
* Redisクライアント
|
|
12
12
|
*/
|
|
13
|
-
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": "
|
|
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": "^
|
|
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.
|
|
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);
|