@chevre/domain 21.0.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 (29) 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/aggregation/aggregateSystem.ts +2 -2
  4. package/example/src/chevre/processPay.ts +7 -4
  5. package/example/src/chevre/processRegisterMembership.ts +0 -5
  6. package/example/src/chevre/processRegisterPaymentCard.ts +0 -5
  7. package/example/src/chevre/processReserve.ts +7 -4
  8. package/example/src/chevre/redisConfig.ts +24 -0
  9. package/example/src/chevre/searchEventTicketOffers.ts +9 -6
  10. package/example/src/chevre/transaction/callOrderMembershipServiceTask.ts +7 -4
  11. package/example/src/chevre/transaction/orderMembershipService.ts +7 -4
  12. package/lib/chevre/repo/action/registerServiceInProgress.d.ts +2 -2
  13. package/lib/chevre/repo/action/registerServiceInProgress.js +19 -53
  14. package/lib/chevre/repo/confirmationNumber.d.ts +2 -2
  15. package/lib/chevre/repo/confirmationNumber.js +40 -53
  16. package/lib/chevre/repo/itemAvailability/screeningEvent.d.ts +3 -3
  17. package/lib/chevre/repo/itemAvailability/screeningEvent.js +53 -138
  18. package/lib/chevre/repo/orderNumber.d.ts +2 -2
  19. package/lib/chevre/repo/orderNumber.js +44 -55
  20. package/lib/chevre/repo/rateLimit/offer.d.ts +2 -2
  21. package/lib/chevre/repo/rateLimit/offer.js +6 -45
  22. package/lib/chevre/repo/serviceOutputIdentifier.d.ts +2 -2
  23. package/lib/chevre/repo/serviceOutputIdentifier.js +32 -46
  24. package/lib/chevre/repo/transactionNumber.d.ts +2 -2
  25. package/lib/chevre/repo/transactionNumber.js +41 -52
  26. package/lib/chevre/service/task.d.ts +4 -4
  27. package/lib/chevre/settings.js +7 -13
  28. package/package.json +3 -6
  29. package/example/src/chevre/copyRedisKeys.ts +0 -102
@@ -1,3 +1,4 @@
1
+ // tslint:disable:no-console
1
2
  /**
2
3
  * イベント集計タスク実行
3
4
  */
@@ -6,14 +7,16 @@ import { chevre } from '../../../lib/index';
6
7
  import * as mongoose from 'mongoose';
7
8
  import * as redis from 'redis';
8
9
 
9
- const redisClient = redis.createClient({
10
- port: Number(<string>process.env.REDIS_PORT),
11
- host: <string>process.env.REDIS_HOST,
12
- password: <string>process.env.REDIS_KEY,
13
- tls: (process.env.REDIS_TLS_SERVERNAME !== undefined) ? { servername: process.env.REDIS_TLS_SERVERNAME } : undefined
14
- });
15
-
16
10
  export async function aggregateScreeningEvent() {
11
+ const redisClient = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
12
+ socket: {
13
+ port: Number(<string>process.env.REDIS_PORT),
14
+ host: <string>process.env.REDIS_HOST
15
+ },
16
+ password: <string>process.env.REDIS_KEY
17
+ });
18
+ await redisClient.connect();
19
+
17
20
  await mongoose.connect(<string>process.env.MONGOLAB_URI);
18
21
 
19
22
  let count = 0;
@@ -8,11 +8,14 @@ import { chevre } from '../../../lib/index';
8
8
 
9
9
  async function main() {
10
10
  await mongoose.connect(<string>process.env.MONGOLAB_URI);
11
- const client = redis.createClient({
12
- host: process.env.REDIS_HOST,
13
- port: Number(process.env.REDIS_PORT),
14
- password: process.env.REDIS_KEY
11
+ const client = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
12
+ socket: {
13
+ port: Number(<string>process.env.REDIS_PORT),
14
+ host: <string>process.env.REDIS_HOST
15
+ },
16
+ password: <string>process.env.REDIS_KEY
15
17
  });
18
+ await client.connect();
16
19
 
17
20
  // const now = new Date();
18
21
  await chevre.service.aggregation.event.aggregateScreeningEvent({
@@ -3,10 +3,10 @@ import * as mongoose from 'mongoose';
3
3
 
4
4
  import { chevre } from '../../../../lib/index';
5
5
 
6
- // const project = { id: <string>process.env.PROJECT_ID };
7
6
  const EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
8
7
  const AGGREGATE_DAYS = Number(process.env.AGGREGATE_DAYS);
9
- const AGGREGATE_CLIENT_IDS = (typeof process.env.AGGREGATE_CLIENT_IDS === 'string') ? process.env.AGGREGATE_CLIENT_IDS.split(',') : [];
8
+ const AGGREGATE_CLIENT_IDS = (typeof process.env.AGGREGATE_CLIENT_IDS === 'string') ? process.env.AGGREGATE_CLIENT_IDS.split(' ') : [];
9
+ console.log('AGGREGATE_CLIENT_IDS:', AGGREGATE_CLIENT_IDS);
10
10
 
11
11
  async function main() {
12
12
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
@@ -9,11 +9,14 @@ const project = { id: String(process.env.PROJECT_ID) };
9
9
 
10
10
  // tslint:disable-next-line:max-func-body-length
11
11
  async function main() {
12
- const client = redis.createClient({
13
- host: process.env.REDIS_HOST,
14
- port: Number(process.env.REDIS_PORT),
15
- password: process.env.REDIS_KEY
12
+ const client = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
13
+ socket: {
14
+ port: Number(<string>process.env.REDIS_PORT),
15
+ host: <string>process.env.REDIS_HOST
16
+ },
17
+ password: <string>process.env.REDIS_KEY
16
18
  });
19
+ await client.connect();
17
20
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
18
21
 
19
22
  const accountingReportRepo = new chevre.repository.AccountingReport(mongoose.connection);
@@ -9,11 +9,6 @@ const project = { id: String(process.env.PROJECT_ID) };
9
9
 
10
10
  // tslint:disable-next-line:max-func-body-length
11
11
  async function main() {
12
- // const client = redis.createClient({
13
- // host: process.env.REDIS_HOST,
14
- // port: Number(process.env.REDIS_PORT),
15
- // password: process.env.REDIS_KEY
16
- // });
17
12
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
18
13
 
19
14
  const accountRepo = new chevre.repository.Account(mongoose.connection);
@@ -9,11 +9,6 @@ const project = { id: String(process.env.PROJECT_ID) };
9
9
 
10
10
  // tslint:disable-next-line:max-func-body-length
11
11
  async function main() {
12
- // const client = redis.createClient({
13
- // host: process.env.REDIS_HOST,
14
- // port: Number(process.env.REDIS_PORT),
15
- // password: process.env.REDIS_KEY
16
- // });
17
12
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
18
13
 
19
14
  const accountRepo = new chevre.repository.Account(mongoose.connection);
@@ -9,11 +9,14 @@ const project = { id: String(process.env.PROJECT_ID) };
9
9
 
10
10
  // tslint:disable-next-line:max-func-body-length
11
11
  async function main() {
12
- const client = redis.createClient({
13
- host: process.env.REDIS_HOST,
14
- port: Number(process.env.REDIS_PORT),
15
- password: process.env.REDIS_KEY
12
+ const client = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
13
+ socket: {
14
+ port: Number(<string>process.env.REDIS_PORT),
15
+ host: <string>process.env.REDIS_HOST
16
+ },
17
+ password: <string>process.env.REDIS_KEY
16
18
  });
19
+ await client.connect();
17
20
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
18
21
 
19
22
  const offerRepo = new chevre.repository.Offer(mongoose.connection);
@@ -0,0 +1,24 @@
1
+ // tslint:disable:no-console
2
+ import * as redis from 'redis';
3
+
4
+ // const project = { id: String(process.env.PROJECT_ID) };
5
+
6
+ // tslint:disable-next-line:max-func-body-length
7
+ async function main() {
8
+ const client = redis.createClient({
9
+ socket: {
10
+ host: process.env.REDIS_HOST,
11
+ port: Number(process.env.REDIS_PORT)
12
+ },
13
+ password: process.env.REDIS_KEY
14
+ });
15
+ await client.connect();
16
+
17
+ console.log(await client.info());
18
+ }
19
+
20
+ main()
21
+ .then(() => {
22
+ console.log('success!');
23
+ })
24
+ .catch(console.error);
@@ -6,13 +6,16 @@ import { chevre } from '../../../lib/index';
6
6
 
7
7
  // const PROJECT_ID = process.env.PROJECT_ID;
8
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
- });
14
-
15
9
  async function main() {
10
+ const client = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
11
+ socket: {
12
+ port: Number(<string>process.env.REDIS_PORT),
13
+ host: <string>process.env.REDIS_HOST
14
+ },
15
+ password: <string>process.env.REDIS_KEY
16
+ });
17
+ await client.connect();
18
+
16
19
  await mongoose.connect(<string>process.env.MONGOLAB_URI);
17
20
 
18
21
  const eventRepo = new chevre.repository.Event(mongoose.connection);
@@ -10,11 +10,14 @@ const project = { id: String(process.env.PROJECT_ID) };
10
10
  async function main() {
11
11
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
12
12
 
13
- const redisClient = redis.createClient({
14
- host: process.env.REDIS_HOST,
15
- port: Number(process.env.REDIS_PORT),
16
- password: process.env.REDIS_KEY
13
+ const redisClient = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
14
+ socket: {
15
+ port: Number(<string>process.env.REDIS_PORT),
16
+ host: <string>process.env.REDIS_HOST
17
+ },
18
+ password: <string>process.env.REDIS_KEY
17
19
  });
20
+ await redisClient.connect();
18
21
 
19
22
  const result = await call(
20
23
  {
@@ -10,11 +10,14 @@ const project = { id: String(process.env.PROJECT_ID) };
10
10
  async function main() {
11
11
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
12
12
 
13
- const redisClient = redis.createClient({
14
- host: process.env.REDIS_HOST,
15
- port: Number(process.env.REDIS_PORT),
16
- password: process.env.REDIS_KEY
13
+ const redisClient = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
14
+ socket: {
15
+ port: Number(<string>process.env.REDIS_PORT),
16
+ host: <string>process.env.REDIS_HOST
17
+ },
18
+ password: <string>process.env.REDIS_KEY
17
19
  });
20
+ await redisClient.connect();
18
21
 
19
22
  const personRepo = new chevre.repository.Person({ userPoolId: chevre.settings.userPoolIdNew });
20
23
  const actionRepo = new chevre.repository.Action(mongoose.connection);
@@ -1,4 +1,4 @@
1
- import * as redis from 'redis';
1
+ import { RedisClientType } from 'redis';
2
2
  /**
3
3
  * 進行アクションキーインターフェース
4
4
  */
@@ -16,7 +16,7 @@ export interface IProgressKey {
16
16
  export declare class RedisRepository {
17
17
  private static readonly KEY_PREFIX;
18
18
  private readonly redisClient;
19
- constructor(redisClient: redis.RedisClient);
19
+ constructor(redisClient: RedisClientType);
20
20
  /**
21
21
  * ロックする
22
22
  */
@@ -24,32 +24,21 @@ class RedisRepository {
24
24
  */
25
25
  lock(progressKey, holder) {
26
26
  return __awaiter(this, void 0, void 0, function* () {
27
- return new Promise((resolve, reject) => {
28
- const key = `${RedisRepository.KEY_PREFIX}:${progressKey.agent.id}:${progressKey.product.id}`;
29
- const ttl = 7200;
30
- debug('locking...', key, ttl);
31
- this.redisClient.multi()
32
- .setnx(key, holder, debug)
33
- .expire(key, ttl, debug)
34
- .exec((err, results) => {
35
- debug('results:', results);
36
- // tslint:disable-next-line:no-single-line-block-comment
37
- /* istanbul ignore if: please write tests */
38
- if (err instanceof Error) {
39
- reject(err);
40
- }
41
- else {
42
- // tslint:disable-next-line:no-single-line-block-comment
43
- /* istanbul ignore else: please write tests */
44
- if (results[0] === 1) {
45
- resolve(results[0]);
46
- }
47
- else {
48
- reject(new Error('Already in progress.'));
49
- }
50
- }
51
- });
52
- });
27
+ const key = `${RedisRepository.KEY_PREFIX}:${progressKey.agent.id}:${progressKey.product.id}`;
28
+ const ttl = 7200;
29
+ debug('locking...', key, ttl);
30
+ const results = yield this.redisClient.multi()
31
+ .setNX(key, holder)
32
+ .expire(key, ttl)
33
+ .exec();
34
+ // tslint:disable-next-line:no-single-line-block-comment
35
+ /* istanbul ignore else: please write tests */
36
+ if (results[0] === 1) {
37
+ return results[0];
38
+ }
39
+ else {
40
+ throw new Error('Already in progress.');
41
+ }
53
42
  });
54
43
  }
55
44
  /**
@@ -57,37 +46,14 @@ class RedisRepository {
57
46
  */
58
47
  unlock(progressKey) {
59
48
  return __awaiter(this, void 0, void 0, function* () {
60
- return new Promise((resolve, reject) => {
61
- const key = `${RedisRepository.KEY_PREFIX}:${progressKey.agent.id}:${progressKey.product.id}`;
62
- this.redisClient.del([key], (err, res) => {
63
- debug(err, res);
64
- // tslint:disable-next-line:no-single-line-block-comment
65
- /* istanbul ignore if: please write tests */
66
- if (err instanceof Error) {
67
- reject(err);
68
- }
69
- else {
70
- resolve();
71
- }
72
- });
73
- });
49
+ const key = `${RedisRepository.KEY_PREFIX}:${progressKey.agent.id}:${progressKey.product.id}`;
50
+ yield this.redisClient.del([key]);
74
51
  });
75
52
  }
76
53
  getHolder(progressKey) {
77
54
  return __awaiter(this, void 0, void 0, function* () {
78
- return new Promise((resolve, reject) => {
79
- const key = `${RedisRepository.KEY_PREFIX}:${progressKey.agent.id}:${progressKey.product.id}`;
80
- this.redisClient.get(key, (err, res) => {
81
- // tslint:disable-next-line:no-single-line-block-comment
82
- /* istanbul ignore if: please write tests */
83
- if (err instanceof Error) {
84
- reject(err);
85
- }
86
- else {
87
- resolve(res);
88
- }
89
- });
90
- });
55
+ const key = `${RedisRepository.KEY_PREFIX}:${progressKey.agent.id}:${progressKey.product.id}`;
56
+ return this.redisClient.get(key);
91
57
  });
92
58
  }
93
59
  }
@@ -1,11 +1,11 @@
1
- import { RedisClient } from 'redis';
1
+ import { RedisClientType } from 'redis';
2
2
  /**
3
3
  * 確認番号リポジトリ
4
4
  */
5
5
  export declare class RedisRepository {
6
6
  private static readonly REDIS_KEY_PREFIX;
7
7
  private readonly redisClient;
8
- constructor(redisClient: RedisClient);
8
+ constructor(redisClient: RedisClientType);
9
9
  static ALIGN_DIGITS(params: string): string;
10
10
  /**
11
11
  * 発行する
@@ -11,13 +11,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.RedisRepository = void 0;
13
13
  const cdigit = require("cdigit");
14
- const createDebug = require("debug");
15
14
  const moment = require("moment-timezone");
16
15
  const util = require("util");
17
16
  // tslint:disable-next-line:no-require-imports no-var-requires
18
17
  const fpe = require('node-fpe');
19
18
  const factory = require("../factory");
20
- const debug = createDebug('chevre-domain:repository');
21
19
  const CONFIRMATION_NUMBER_MIN_LENGH = 4;
22
20
  /**
23
21
  * 確認番号リポジトリ
@@ -39,57 +37,46 @@ class RedisRepository {
39
37
  */
40
38
  publish(params) {
41
39
  return __awaiter(this, void 0, void 0, function* () {
42
- return new Promise((resolve, reject) => {
43
- // データ保管期間はとりあえず一か月
44
- const TTL = moment(params.orderDate)
45
- .add(1, 'month')
46
- .diff(moment(params.orderDate), 'seconds');
47
- const key = util.format('%s:%s', RedisRepository.REDIS_KEY_PREFIX, moment(params.orderDate)
48
- .tz('Asia/Tokyo')
49
- .format('YYMM'));
50
- this.redisClient.multi()
51
- .incr(key, debug)
52
- .expire(key, TTL)
53
- .exec((err, results) => {
54
- // tslint:disable-next-line:no-single-line-block-comment
55
- /* istanbul ignore if: please write tests */
56
- if (err instanceof Error) {
57
- reject(err);
58
- }
59
- else {
60
- if (!Array.isArray(results)) {
61
- // なぜかresults: nullのことがあるのでハンドリング
62
- reject(new factory.errors.ServiceUnavailable('incr confirmationNumber result not array'));
63
- return;
64
- }
65
- // tslint:disable-next-line:no-single-line-block-comment
66
- /* istanbul ignore else: please write tests */
67
- if (typeof results[0] === 'number') {
68
- const no = results[0];
69
- // debug('no incremented.', no);
70
- // 桁数調整
71
- let confirmationNumber = RedisRepository.ALIGN_DIGITS(String(no));
72
- // debug('encrypting confirmationNumber...', confirmationNumber);
73
- // checkdigit
74
- const cd = cdigit.luhn.compute(confirmationNumber);
75
- // debug('check digit:', cd);
76
- confirmationNumber = fpe({ password: cd })
77
- .encrypt(confirmationNumber);
78
- confirmationNumber = `${cd}${confirmationNumber}`;
79
- // console.log(
80
- // 'decrypted confirmationNumber:',
81
- // fpe({ password: confirmationNumber.slice(0, 1) })
82
- // .decrypt(confirmationNumber.slice(1))
83
- // );
84
- resolve(confirmationNumber);
85
- }
86
- else {
87
- // 基本的にありえないフロー
88
- reject(new factory.errors.ServiceUnavailable('Confirmation number not published'));
89
- }
90
- }
91
- });
92
- });
40
+ // データ保管期間はとりあえず一か月
41
+ const TTL = moment(params.orderDate)
42
+ .add(1, 'month')
43
+ .diff(moment(params.orderDate), 'seconds');
44
+ const key = util.format('%s:%s', RedisRepository.REDIS_KEY_PREFIX, moment(params.orderDate)
45
+ .tz('Asia/Tokyo')
46
+ .format('YYMM'));
47
+ const results = yield this.redisClient.multi()
48
+ .incr(key)
49
+ .expire(key, TTL)
50
+ .exec();
51
+ if (!Array.isArray(results)) {
52
+ // なぜかresults: nullのことがあるのでハンドリング
53
+ throw new factory.errors.ServiceUnavailable('incr confirmationNumber result not array');
54
+ }
55
+ // tslint:disable-next-line:no-single-line-block-comment
56
+ /* istanbul ignore else: please write tests */
57
+ if (typeof results[0] === 'number') {
58
+ const no = results[0];
59
+ // debug('no incremented.', no);
60
+ // 桁数調整
61
+ let confirmationNumber = RedisRepository.ALIGN_DIGITS(String(no));
62
+ // debug('encrypting confirmationNumber...', confirmationNumber);
63
+ // checkdigit
64
+ const cd = cdigit.luhn.compute(confirmationNumber);
65
+ // debug('check digit:', cd);
66
+ confirmationNumber = fpe({ password: cd })
67
+ .encrypt(confirmationNumber);
68
+ confirmationNumber = `${cd}${confirmationNumber}`;
69
+ // console.log(
70
+ // 'decrypted confirmationNumber:',
71
+ // fpe({ password: confirmationNumber.slice(0, 1) })
72
+ // .decrypt(confirmationNumber.slice(1))
73
+ // );
74
+ return confirmationNumber;
75
+ }
76
+ else {
77
+ // 基本的にありえないフロー
78
+ throw new factory.errors.ServiceUnavailable('Confirmation number not published');
79
+ }
93
80
  });
94
81
  }
95
82
  }
@@ -1,4 +1,4 @@
1
- import * as redis from 'redis';
1
+ import { RedisClientType } from 'redis';
2
2
  import * as factory from '../../factory';
3
3
  export interface IOffer {
4
4
  itemOffered?: {
@@ -28,7 +28,7 @@ export interface IUnlockKey {
28
28
  export declare class RedisRepository {
29
29
  static KEY_PREFIX: string;
30
30
  private readonly redisClient;
31
- constructor(redisClient: redis.RedisClient);
31
+ constructor(redisClient: RedisClientType);
32
32
  static OFFER2FIELD(params: IOffer): string;
33
33
  /**
34
34
  * 座席をロックする(maxキャパシティチェック有)
@@ -59,7 +59,7 @@ export declare class RedisRepository {
59
59
  /**
60
60
  * 保持者を取得する
61
61
  */
62
- getHolder(params: IUnlockKey): Promise<string | null>;
62
+ getHolder(params: IUnlockKey): Promise<string | null | undefined>;
63
63
  /**
64
64
  * 在庫状況を検索する
65
65
  * offers.lengthが0だと"ERR wrong number of arguments for 'hmget' command"となるので注意