@powfix/core-js 0.18.1 → 0.18.2

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 (46) hide show
  1. package/dist/node/cjs/nodejs/constants/TransactionManagerLogLevel.js +11 -0
  2. package/dist/node/cjs/nodejs/constants/TransactionManagerTimeoutAction.js +8 -0
  3. package/dist/node/cjs/nodejs/constants/index.js +18 -0
  4. package/dist/node/cjs/nodejs/index.js +5 -0
  5. package/dist/node/cjs/nodejs/managers/TransactionManager.js +151 -0
  6. package/dist/node/cjs/nodejs/managers/TransactionManager.types.js +2 -0
  7. package/dist/node/cjs/nodejs/managers/index.js +18 -0
  8. package/dist/node/cjs/nodejs/services/index.js +17 -0
  9. package/dist/node/cjs/nodejs/services/redis/RedisClient.js +75 -0
  10. package/dist/node/cjs/nodejs/services/redis/RedisPublisher.js +64 -0
  11. package/dist/node/cjs/nodejs/services/redis/RedisSubscriber.js +73 -0
  12. package/dist/node/cjs/nodejs/services/redis/index.js +20 -0
  13. package/dist/node/cjs/nodejs/types/UpsertResult.js +2 -0
  14. package/dist/node/cjs/nodejs/types/index.js +18 -0
  15. package/dist/node/cjs/nodejs/types/mariaDb.js +2 -0
  16. package/dist/node/esm/nodejs/constants/TransactionManagerLogLevel.mjs +8 -0
  17. package/dist/node/esm/nodejs/constants/TransactionManagerTimeoutAction.mjs +5 -0
  18. package/dist/node/esm/nodejs/constants/index.mjs +2 -0
  19. package/dist/node/esm/nodejs/index.mjs +5 -0
  20. package/dist/node/esm/nodejs/managers/TransactionManager.mjs +144 -0
  21. package/dist/node/esm/nodejs/managers/TransactionManager.types.mjs +1 -0
  22. package/dist/node/esm/nodejs/managers/index.mjs +2 -0
  23. package/dist/node/esm/nodejs/services/index.mjs +1 -0
  24. package/dist/node/esm/nodejs/services/redis/RedisClient.mjs +71 -0
  25. package/dist/node/esm/nodejs/services/redis/RedisPublisher.mjs +60 -0
  26. package/dist/node/esm/nodejs/services/redis/RedisSubscriber.mjs +69 -0
  27. package/dist/node/esm/nodejs/services/redis/index.mjs +4 -0
  28. package/dist/node/esm/nodejs/types/UpsertResult.mjs +1 -0
  29. package/dist/node/esm/nodejs/types/index.mjs +2 -0
  30. package/dist/node/esm/nodejs/types/mariaDb.mjs +1 -0
  31. package/dist/node/types/nodejs/constants/TransactionManagerLogLevel.d.ts +7 -0
  32. package/dist/node/types/nodejs/constants/TransactionManagerTimeoutAction.d.ts +4 -0
  33. package/dist/node/types/nodejs/constants/index.d.ts +2 -0
  34. package/dist/node/types/nodejs/index.d.ts +5 -0
  35. package/dist/node/types/nodejs/managers/TransactionManager.d.ts +27 -0
  36. package/dist/node/types/nodejs/managers/TransactionManager.types.d.ts +9 -0
  37. package/dist/node/types/nodejs/managers/index.d.ts +2 -0
  38. package/dist/node/types/nodejs/services/index.d.ts +1 -0
  39. package/dist/node/types/nodejs/services/redis/RedisClient.d.ts +21 -0
  40. package/dist/node/types/nodejs/services/redis/RedisPublisher.d.ts +13 -0
  41. package/dist/node/types/nodejs/services/redis/RedisSubscriber.d.ts +11 -0
  42. package/dist/node/types/nodejs/services/redis/index.d.ts +3 -0
  43. package/dist/node/types/nodejs/types/UpsertResult.d.ts +2 -0
  44. package/dist/node/types/nodejs/types/index.d.ts +2 -0
  45. package/dist/node/types/nodejs/types/mariaDb.d.ts +8 -0
  46. package/package.json +1 -1
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransactionManagerLogLevel = void 0;
4
+ var TransactionManagerLogLevel;
5
+ (function (TransactionManagerLogLevel) {
6
+ TransactionManagerLogLevel[TransactionManagerLogLevel["VERBOSE"] = 1] = "VERBOSE";
7
+ TransactionManagerLogLevel[TransactionManagerLogLevel["INFO"] = 2] = "INFO";
8
+ TransactionManagerLogLevel[TransactionManagerLogLevel["WARNING"] = 3] = "WARNING";
9
+ TransactionManagerLogLevel[TransactionManagerLogLevel["ERROR"] = 4] = "ERROR";
10
+ TransactionManagerLogLevel[TransactionManagerLogLevel["CRITICAL"] = 5] = "CRITICAL";
11
+ })(TransactionManagerLogLevel || (exports.TransactionManagerLogLevel = TransactionManagerLogLevel = {}));
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransactionManagerTimeoutAction = void 0;
4
+ var TransactionManagerTimeoutAction;
5
+ (function (TransactionManagerTimeoutAction) {
6
+ TransactionManagerTimeoutAction[TransactionManagerTimeoutAction["COMMIT"] = 1] = "COMMIT";
7
+ TransactionManagerTimeoutAction[TransactionManagerTimeoutAction["ROLLBACK"] = 2] = "ROLLBACK";
8
+ })(TransactionManagerTimeoutAction || (exports.TransactionManagerTimeoutAction = TransactionManagerTimeoutAction = {}));
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./TransactionManagerLogLevel"), exports);
18
+ __exportStar(require("./TransactionManagerTimeoutAction"), exports);
@@ -14,4 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./constants"), exports);
18
+ __exportStar(require("./interfaces"), exports);
19
+ __exportStar(require("./managers"), exports);
20
+ __exportStar(require("./services"), exports);
21
+ __exportStar(require("./types"), exports);
17
22
  __exportStar(require("./utils"), exports);
@@ -0,0 +1,151 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.TransactionManager = void 0;
16
+ const eventemitter3_1 = __importDefault(require("eventemitter3"));
17
+ const constants_1 = require("../constants");
18
+ const LOG_TAG = '[TransactionManager]';
19
+ class TransactionManager {
20
+ constructor() {
21
+ // Members
22
+ this.logLevel = constants_1.TransactionManagerLogLevel.VERBOSE;
23
+ this.transactionTimeoutMap = new Map();
24
+ // Emitter
25
+ this.emitter = new eventemitter3_1.default();
26
+ if (this.logLevel <= constants_1.TransactionManagerLogLevel.VERBOSE) {
27
+ console.log(LOG_TAG, 'TransactionManager instance initialized');
28
+ }
29
+ }
30
+ static getInstance() {
31
+ return this.instance || (this.instance = new TransactionManager());
32
+ }
33
+ getTransactionLogArg(transaction) {
34
+ const id = transaction === null || transaction === void 0 ? void 0 : transaction.id;
35
+ return id ? `transaction(${id})` : '';
36
+ }
37
+ setLogLevel(logLevel) {
38
+ this.logLevel = logLevel;
39
+ if (this.logLevel <= constants_1.TransactionManagerLogLevel.VERBOSE) {
40
+ console.log(LOG_TAG, 'log level changed to', logLevel);
41
+ }
42
+ }
43
+ addListener(event, fn) {
44
+ this.emitter.addListener(event, fn);
45
+ }
46
+ removeListener(event, fn) {
47
+ this.emitter.removeListener(event, fn);
48
+ }
49
+ add(transaction, option) {
50
+ var _a, _b;
51
+ if (this.transactionTimeoutMap.has(transaction)) {
52
+ if (this.logLevel <= constants_1.TransactionManagerLogLevel.ERROR) {
53
+ console.error(LOG_TAG, 'transaction already exists');
54
+ }
55
+ return;
56
+ }
57
+ const action = (_a = option === null || option === void 0 ? void 0 : option.timeoutAction) !== null && _a !== void 0 ? _a : TransactionManager.DEFAULT_ACTION;
58
+ const timeout = (_b = option === null || option === void 0 ? void 0 : option.timeout) !== null && _b !== void 0 ? _b : TransactionManager.DEFAULT_TIMEOUT;
59
+ const handler = setTimeout(this.timeout.bind(this), timeout, transaction, action);
60
+ this.transactionTimeoutMap.set(transaction, {
61
+ handler,
62
+ action,
63
+ });
64
+ // Callback
65
+ transaction.afterCommit(this.afterCommit.bind(this));
66
+ }
67
+ remove(transaction) {
68
+ const transactionTimeout = this.transactionTimeoutMap.get(transaction);
69
+ if (transactionTimeout != null) {
70
+ clearTimeout(transactionTimeout.handler);
71
+ this.transactionTimeoutMap.delete(transaction);
72
+ if (this.logLevel <= constants_1.TransactionManagerLogLevel.VERBOSE) {
73
+ console.log(LOG_TAG, this.getTransactionLogArg(transaction), 'removed');
74
+ }
75
+ }
76
+ }
77
+ flush(action) {
78
+ return Promise.allSettled(Array.from(this.transactionTimeoutMap.entries()).map((_a) => __awaiter(this, [_a], void 0, function* ([transaction, transactionTimeout]) {
79
+ const handled = yield this.execute(transaction, action !== null && action !== void 0 ? action : transactionTimeout.action, 'flush');
80
+ this.remove(transaction);
81
+ return {
82
+ handled,
83
+ transaction,
84
+ };
85
+ })));
86
+ }
87
+ execute(transaction, action, reason) {
88
+ return __awaiter(this, void 0, void 0, function* () {
89
+ let handled = false;
90
+ const finished = transaction === null || transaction === void 0 ? void 0 : transaction.finished;
91
+ if (finished != null) {
92
+ if (this.logLevel <= constants_1.TransactionManagerLogLevel.VERBOSE) {
93
+ console.log(LOG_TAG, this.getTransactionLogArg(transaction), `is already handled(${finished}) after`, reason);
94
+ }
95
+ this.remove(transaction);
96
+ return handled;
97
+ }
98
+ try {
99
+ let finished;
100
+ switch (action) {
101
+ case constants_1.TransactionManagerTimeoutAction.ROLLBACK: {
102
+ yield transaction.rollback();
103
+ finished = 'rollback';
104
+ break;
105
+ }
106
+ case constants_1.TransactionManagerTimeoutAction.COMMIT: {
107
+ yield transaction.commit();
108
+ finished = 'commit';
109
+ break;
110
+ }
111
+ default: {
112
+ if (this.logLevel <= constants_1.TransactionManagerLogLevel.ERROR) {
113
+ console.error(LOG_TAG, `unknown action`, action);
114
+ }
115
+ break;
116
+ }
117
+ }
118
+ handled = finished != null;
119
+ if (finished != null) {
120
+ if (this.logLevel <= constants_1.TransactionManagerLogLevel.ERROR) {
121
+ console.error(LOG_TAG, this.getTransactionLogArg(transaction), `handled(${finished}) after`, reason);
122
+ }
123
+ }
124
+ else {
125
+ if (this.logLevel <= constants_1.TransactionManagerLogLevel.ERROR) {
126
+ console.error(LOG_TAG, this.getTransactionLogArg(transaction), `not handled 🚫`);
127
+ }
128
+ }
129
+ }
130
+ catch (e) {
131
+ console.error(e);
132
+ }
133
+ finally {
134
+ this.remove(transaction);
135
+ }
136
+ return handled;
137
+ });
138
+ }
139
+ timeout(transaction, action) {
140
+ return __awaiter(this, void 0, void 0, function* () {
141
+ const handled = yield this.execute(transaction, action, 'timeout');
142
+ this.emitter.emit('onUnhandledTransaction', transaction, handled);
143
+ });
144
+ }
145
+ afterCommit(transaction) {
146
+ this.remove(transaction);
147
+ }
148
+ }
149
+ exports.TransactionManager = TransactionManager;
150
+ TransactionManager.DEFAULT_TIMEOUT = 60 * 1000;
151
+ TransactionManager.DEFAULT_ACTION = constants_1.TransactionManagerTimeoutAction.ROLLBACK;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./TransactionManager"), exports);
18
+ __exportStar(require("./TransactionManager.types"), exports);
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./redis"), exports);
@@ -0,0 +1,75 @@
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.RedisClient = void 0;
13
+ const redis_1 = require("redis");
14
+ const LOG_PREFIX = 'RedisClient';
15
+ class RedisClient {
16
+ constructor(options) {
17
+ this.options = {};
18
+ this.status = RedisClient.Status.STOPPED;
19
+ console.log(Date.now(), LOG_PREFIX, 'initialized');
20
+ if (options) {
21
+ this.options = options;
22
+ }
23
+ if (options === null || options === void 0 ? void 0 : options.redisOptions) {
24
+ this.client = (0, redis_1.createClient)(options.redisOptions);
25
+ }
26
+ else {
27
+ this.client = (0, redis_1.createClient)({});
28
+ }
29
+ }
30
+ getStatus() {
31
+ return this.status;
32
+ }
33
+ start() {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ console.log(LOG_PREFIX, 'trying to start');
36
+ // register event callback
37
+ this.client.on('connect', this.handleOnConnect);
38
+ this.client.on('error', this.handleOnError);
39
+ console.log('before connect');
40
+ yield this.client.connect();
41
+ console.log('after connect');
42
+ this.status = RedisClient.Status.RUNNING;
43
+ console.log(LOG_PREFIX, 'now started');
44
+ return this.status;
45
+ });
46
+ }
47
+ stop() {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ console.log(LOG_PREFIX, 'trying to stop');
50
+ // unregister event callback
51
+ this.client.off('connect', this.handleOnConnect);
52
+ this.client.off('error', this.handleOnError);
53
+ if (this.client.isOpen) {
54
+ yield this.client.disconnect();
55
+ }
56
+ this.status = RedisClient.Status.STOPPED;
57
+ console.log(LOG_PREFIX, 'now stopped');
58
+ return this.status;
59
+ });
60
+ }
61
+ handleOnConnect() {
62
+ console.log(LOG_PREFIX, 'connected');
63
+ }
64
+ handleOnError(error) {
65
+ console.error(LOG_PREFIX, error);
66
+ }
67
+ }
68
+ exports.RedisClient = RedisClient;
69
+ (function (RedisClient) {
70
+ let Status;
71
+ (function (Status) {
72
+ Status[Status["RUNNING"] = 0] = "RUNNING";
73
+ Status[Status["STOPPED"] = 1] = "STOPPED";
74
+ })(Status = RedisClient.Status || (RedisClient.Status = {}));
75
+ })(RedisClient || (exports.RedisClient = RedisClient = {}));
@@ -0,0 +1,64 @@
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.RedisPublisher = void 0;
13
+ const RedisClient_1 = require("./RedisClient");
14
+ const LOG_TAG = '[REDIS-PUB]';
15
+ class RedisPublisher extends RedisClient_1.RedisClient {
16
+ constructor(options) {
17
+ super(options);
18
+ this.logging = 'length';
19
+ console.log(Date.now(), "RedisPublisher", 'initialized');
20
+ }
21
+ start() {
22
+ const _super = Object.create(null, {
23
+ start: { get: () => super.start }
24
+ });
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ return _super.start.call(this);
27
+ });
28
+ }
29
+ stop() {
30
+ const _super = Object.create(null, {
31
+ stop: { get: () => super.stop }
32
+ });
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ return _super.stop.call(this);
35
+ });
36
+ }
37
+ setLogging(logging) {
38
+ this.logging = logging;
39
+ }
40
+ getLogging() {
41
+ return this.logging;
42
+ }
43
+ // Make public method
44
+ publish(channel, data) {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ const stringifyData = typeof data !== 'string' ? JSON.stringify(data) : data;
47
+ switch (this.logging) {
48
+ case "none": {
49
+ break;
50
+ }
51
+ case "length": {
52
+ console.log(new Date().toISOString(), LOG_TAG, channel, `[len=${stringifyData.length}]`);
53
+ break;
54
+ }
55
+ case "data": {
56
+ console.log(new Date().toISOString(), LOG_TAG, channel, stringifyData);
57
+ break;
58
+ }
59
+ }
60
+ yield this.client.publish(channel, stringifyData);
61
+ });
62
+ }
63
+ }
64
+ exports.RedisPublisher = RedisPublisher;
@@ -0,0 +1,73 @@
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.RedisSubscriber = void 0;
13
+ const RedisClient_1 = require("./RedisClient");
14
+ const utils_1 = require("../../../shared/utils");
15
+ class RedisSubscriber extends RedisClient_1.RedisClient {
16
+ constructor(options) {
17
+ super(options);
18
+ console.log(Date.now(), 'Subscriber', 'initialized');
19
+ }
20
+ subscribe(channels, listener, bufferMode) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ for (const channel of (0, utils_1.castArray)(channels)) {
23
+ if ((/\*/g).test(channel)) {
24
+ yield this.client.pSubscribe(channel, listener, bufferMode);
25
+ }
26
+ else {
27
+ yield this.client.subscribe(channel, listener, bufferMode);
28
+ }
29
+ }
30
+ });
31
+ }
32
+ unsubscribe(channels, listener, bufferMode) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ for (const channel of (0, utils_1.castArray)(channels)) {
35
+ if ((/\*/g).test(channel)) {
36
+ yield this.client.pUnsubscribe(channel, listener, bufferMode);
37
+ }
38
+ else {
39
+ yield this.client.unsubscribe(channel, listener, bufferMode);
40
+ }
41
+ }
42
+ });
43
+ }
44
+ start() {
45
+ const _super = Object.create(null, {
46
+ start: { get: () => super.start }
47
+ });
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ const status = yield _super.start.call(this);
50
+ yield this.registerListeners();
51
+ return status;
52
+ });
53
+ }
54
+ stop() {
55
+ const _super = Object.create(null, {
56
+ stop: { get: () => super.stop }
57
+ });
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ const status = yield _super.stop.call(this);
60
+ yield this.unregisterListeners();
61
+ return status;
62
+ });
63
+ }
64
+ registerListeners() {
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ });
67
+ }
68
+ unregisterListeners() {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ });
71
+ }
72
+ }
73
+ exports.RedisSubscriber = RedisSubscriber;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ // Files
18
+ __exportStar(require("./RedisClient"), exports);
19
+ __exportStar(require("./RedisPublisher"), exports);
20
+ __exportStar(require("./RedisSubscriber"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./UpsertResult"), exports);
18
+ __exportStar(require("./mariaDb"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ export var TransactionManagerLogLevel;
2
+ (function (TransactionManagerLogLevel) {
3
+ TransactionManagerLogLevel[TransactionManagerLogLevel["VERBOSE"] = 1] = "VERBOSE";
4
+ TransactionManagerLogLevel[TransactionManagerLogLevel["INFO"] = 2] = "INFO";
5
+ TransactionManagerLogLevel[TransactionManagerLogLevel["WARNING"] = 3] = "WARNING";
6
+ TransactionManagerLogLevel[TransactionManagerLogLevel["ERROR"] = 4] = "ERROR";
7
+ TransactionManagerLogLevel[TransactionManagerLogLevel["CRITICAL"] = 5] = "CRITICAL";
8
+ })(TransactionManagerLogLevel || (TransactionManagerLogLevel = {}));
@@ -0,0 +1,5 @@
1
+ export var TransactionManagerTimeoutAction;
2
+ (function (TransactionManagerTimeoutAction) {
3
+ TransactionManagerTimeoutAction[TransactionManagerTimeoutAction["COMMIT"] = 1] = "COMMIT";
4
+ TransactionManagerTimeoutAction[TransactionManagerTimeoutAction["ROLLBACK"] = 2] = "ROLLBACK";
5
+ })(TransactionManagerTimeoutAction || (TransactionManagerTimeoutAction = {}));
@@ -0,0 +1,2 @@
1
+ export * from './TransactionManagerLogLevel.mjs';
2
+ export * from './TransactionManagerTimeoutAction.mjs';
@@ -1 +1,6 @@
1
+ export * from './constants/index.mjs';
2
+ export * from './interfaces/index.mjs';
3
+ export * from './managers/index.mjs';
4
+ export * from './services/index.mjs';
5
+ export * from './types/index.mjs';
1
6
  export * from './utils/index.mjs';
@@ -0,0 +1,144 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import EventEmitter from 'eventemitter3';
11
+ import { TransactionManagerLogLevel, TransactionManagerTimeoutAction } from "../constants/index.mjs";
12
+ const LOG_TAG = '[TransactionManager]';
13
+ export class TransactionManager {
14
+ constructor() {
15
+ // Members
16
+ this.logLevel = TransactionManagerLogLevel.VERBOSE;
17
+ this.transactionTimeoutMap = new Map();
18
+ // Emitter
19
+ this.emitter = new EventEmitter();
20
+ if (this.logLevel <= TransactionManagerLogLevel.VERBOSE) {
21
+ console.log(LOG_TAG, 'TransactionManager instance initialized');
22
+ }
23
+ }
24
+ static getInstance() {
25
+ return this.instance || (this.instance = new TransactionManager());
26
+ }
27
+ getTransactionLogArg(transaction) {
28
+ const id = transaction === null || transaction === void 0 ? void 0 : transaction.id;
29
+ return id ? `transaction(${id})` : '';
30
+ }
31
+ setLogLevel(logLevel) {
32
+ this.logLevel = logLevel;
33
+ if (this.logLevel <= TransactionManagerLogLevel.VERBOSE) {
34
+ console.log(LOG_TAG, 'log level changed to', logLevel);
35
+ }
36
+ }
37
+ addListener(event, fn) {
38
+ this.emitter.addListener(event, fn);
39
+ }
40
+ removeListener(event, fn) {
41
+ this.emitter.removeListener(event, fn);
42
+ }
43
+ add(transaction, option) {
44
+ var _a, _b;
45
+ if (this.transactionTimeoutMap.has(transaction)) {
46
+ if (this.logLevel <= TransactionManagerLogLevel.ERROR) {
47
+ console.error(LOG_TAG, 'transaction already exists');
48
+ }
49
+ return;
50
+ }
51
+ const action = (_a = option === null || option === void 0 ? void 0 : option.timeoutAction) !== null && _a !== void 0 ? _a : TransactionManager.DEFAULT_ACTION;
52
+ const timeout = (_b = option === null || option === void 0 ? void 0 : option.timeout) !== null && _b !== void 0 ? _b : TransactionManager.DEFAULT_TIMEOUT;
53
+ const handler = setTimeout(this.timeout.bind(this), timeout, transaction, action);
54
+ this.transactionTimeoutMap.set(transaction, {
55
+ handler,
56
+ action,
57
+ });
58
+ // Callback
59
+ transaction.afterCommit(this.afterCommit.bind(this));
60
+ }
61
+ remove(transaction) {
62
+ const transactionTimeout = this.transactionTimeoutMap.get(transaction);
63
+ if (transactionTimeout != null) {
64
+ clearTimeout(transactionTimeout.handler);
65
+ this.transactionTimeoutMap.delete(transaction);
66
+ if (this.logLevel <= TransactionManagerLogLevel.VERBOSE) {
67
+ console.log(LOG_TAG, this.getTransactionLogArg(transaction), 'removed');
68
+ }
69
+ }
70
+ }
71
+ flush(action) {
72
+ return Promise.allSettled(Array.from(this.transactionTimeoutMap.entries()).map((_a) => __awaiter(this, [_a], void 0, function* ([transaction, transactionTimeout]) {
73
+ const handled = yield this.execute(transaction, action !== null && action !== void 0 ? action : transactionTimeout.action, 'flush');
74
+ this.remove(transaction);
75
+ return {
76
+ handled,
77
+ transaction,
78
+ };
79
+ })));
80
+ }
81
+ execute(transaction, action, reason) {
82
+ return __awaiter(this, void 0, void 0, function* () {
83
+ let handled = false;
84
+ const finished = transaction === null || transaction === void 0 ? void 0 : transaction.finished;
85
+ if (finished != null) {
86
+ if (this.logLevel <= TransactionManagerLogLevel.VERBOSE) {
87
+ console.log(LOG_TAG, this.getTransactionLogArg(transaction), `is already handled(${finished}) after`, reason);
88
+ }
89
+ this.remove(transaction);
90
+ return handled;
91
+ }
92
+ try {
93
+ let finished;
94
+ switch (action) {
95
+ case TransactionManagerTimeoutAction.ROLLBACK: {
96
+ yield transaction.rollback();
97
+ finished = 'rollback';
98
+ break;
99
+ }
100
+ case TransactionManagerTimeoutAction.COMMIT: {
101
+ yield transaction.commit();
102
+ finished = 'commit';
103
+ break;
104
+ }
105
+ default: {
106
+ if (this.logLevel <= TransactionManagerLogLevel.ERROR) {
107
+ console.error(LOG_TAG, `unknown action`, action);
108
+ }
109
+ break;
110
+ }
111
+ }
112
+ handled = finished != null;
113
+ if (finished != null) {
114
+ if (this.logLevel <= TransactionManagerLogLevel.ERROR) {
115
+ console.error(LOG_TAG, this.getTransactionLogArg(transaction), `handled(${finished}) after`, reason);
116
+ }
117
+ }
118
+ else {
119
+ if (this.logLevel <= TransactionManagerLogLevel.ERROR) {
120
+ console.error(LOG_TAG, this.getTransactionLogArg(transaction), `not handled 🚫`);
121
+ }
122
+ }
123
+ }
124
+ catch (e) {
125
+ console.error(e);
126
+ }
127
+ finally {
128
+ this.remove(transaction);
129
+ }
130
+ return handled;
131
+ });
132
+ }
133
+ timeout(transaction, action) {
134
+ return __awaiter(this, void 0, void 0, function* () {
135
+ const handled = yield this.execute(transaction, action, 'timeout');
136
+ this.emitter.emit('onUnhandledTransaction', transaction, handled);
137
+ });
138
+ }
139
+ afterCommit(transaction) {
140
+ this.remove(transaction);
141
+ }
142
+ }
143
+ TransactionManager.DEFAULT_TIMEOUT = 60 * 1000;
144
+ TransactionManager.DEFAULT_ACTION = TransactionManagerTimeoutAction.ROLLBACK;
@@ -0,0 +1,2 @@
1
+ export * from './TransactionManager.mjs';
2
+ export * from './TransactionManager.types.mjs';
@@ -0,0 +1 @@
1
+ export * from './redis/index.mjs';
@@ -0,0 +1,71 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { createClient } from 'redis';
11
+ const LOG_PREFIX = 'RedisClient';
12
+ export class RedisClient {
13
+ constructor(options) {
14
+ this.options = {};
15
+ this.status = RedisClient.Status.STOPPED;
16
+ console.log(Date.now(), LOG_PREFIX, 'initialized');
17
+ if (options) {
18
+ this.options = options;
19
+ }
20
+ if (options === null || options === void 0 ? void 0 : options.redisOptions) {
21
+ this.client = createClient(options.redisOptions);
22
+ }
23
+ else {
24
+ this.client = createClient({});
25
+ }
26
+ }
27
+ getStatus() {
28
+ return this.status;
29
+ }
30
+ start() {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ console.log(LOG_PREFIX, 'trying to start');
33
+ // register event callback
34
+ this.client.on('connect', this.handleOnConnect);
35
+ this.client.on('error', this.handleOnError);
36
+ console.log('before connect');
37
+ yield this.client.connect();
38
+ console.log('after connect');
39
+ this.status = RedisClient.Status.RUNNING;
40
+ console.log(LOG_PREFIX, 'now started');
41
+ return this.status;
42
+ });
43
+ }
44
+ stop() {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ console.log(LOG_PREFIX, 'trying to stop');
47
+ // unregister event callback
48
+ this.client.off('connect', this.handleOnConnect);
49
+ this.client.off('error', this.handleOnError);
50
+ if (this.client.isOpen) {
51
+ yield this.client.disconnect();
52
+ }
53
+ this.status = RedisClient.Status.STOPPED;
54
+ console.log(LOG_PREFIX, 'now stopped');
55
+ return this.status;
56
+ });
57
+ }
58
+ handleOnConnect() {
59
+ console.log(LOG_PREFIX, 'connected');
60
+ }
61
+ handleOnError(error) {
62
+ console.error(LOG_PREFIX, error);
63
+ }
64
+ }
65
+ (function (RedisClient) {
66
+ let Status;
67
+ (function (Status) {
68
+ Status[Status["RUNNING"] = 0] = "RUNNING";
69
+ Status[Status["STOPPED"] = 1] = "STOPPED";
70
+ })(Status = RedisClient.Status || (RedisClient.Status = {}));
71
+ })(RedisClient || (RedisClient = {}));
@@ -0,0 +1,60 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { RedisClient } from "./RedisClient.mjs";
11
+ const LOG_TAG = '[REDIS-PUB]';
12
+ export class RedisPublisher extends RedisClient {
13
+ constructor(options) {
14
+ super(options);
15
+ this.logging = 'length';
16
+ console.log(Date.now(), "RedisPublisher", 'initialized');
17
+ }
18
+ start() {
19
+ const _super = Object.create(null, {
20
+ start: { get: () => super.start }
21
+ });
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ return _super.start.call(this);
24
+ });
25
+ }
26
+ stop() {
27
+ const _super = Object.create(null, {
28
+ stop: { get: () => super.stop }
29
+ });
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ return _super.stop.call(this);
32
+ });
33
+ }
34
+ setLogging(logging) {
35
+ this.logging = logging;
36
+ }
37
+ getLogging() {
38
+ return this.logging;
39
+ }
40
+ // Make public method
41
+ publish(channel, data) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ const stringifyData = typeof data !== 'string' ? JSON.stringify(data) : data;
44
+ switch (this.logging) {
45
+ case "none": {
46
+ break;
47
+ }
48
+ case "length": {
49
+ console.log(new Date().toISOString(), LOG_TAG, channel, `[len=${stringifyData.length}]`);
50
+ break;
51
+ }
52
+ case "data": {
53
+ console.log(new Date().toISOString(), LOG_TAG, channel, stringifyData);
54
+ break;
55
+ }
56
+ }
57
+ yield this.client.publish(channel, stringifyData);
58
+ });
59
+ }
60
+ }
@@ -0,0 +1,69 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { RedisClient } from "./RedisClient.mjs";
11
+ import { castArray } from "../../../shared/utils/index.mjs";
12
+ export class RedisSubscriber extends RedisClient {
13
+ constructor(options) {
14
+ super(options);
15
+ console.log(Date.now(), 'Subscriber', 'initialized');
16
+ }
17
+ subscribe(channels, listener, bufferMode) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ for (const channel of castArray(channels)) {
20
+ if ((/\*/g).test(channel)) {
21
+ yield this.client.pSubscribe(channel, listener, bufferMode);
22
+ }
23
+ else {
24
+ yield this.client.subscribe(channel, listener, bufferMode);
25
+ }
26
+ }
27
+ });
28
+ }
29
+ unsubscribe(channels, listener, bufferMode) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ for (const channel of castArray(channels)) {
32
+ if ((/\*/g).test(channel)) {
33
+ yield this.client.pUnsubscribe(channel, listener, bufferMode);
34
+ }
35
+ else {
36
+ yield this.client.unsubscribe(channel, listener, bufferMode);
37
+ }
38
+ }
39
+ });
40
+ }
41
+ start() {
42
+ const _super = Object.create(null, {
43
+ start: { get: () => super.start }
44
+ });
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ const status = yield _super.start.call(this);
47
+ yield this.registerListeners();
48
+ return status;
49
+ });
50
+ }
51
+ stop() {
52
+ const _super = Object.create(null, {
53
+ stop: { get: () => super.stop }
54
+ });
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ const status = yield _super.stop.call(this);
57
+ yield this.unregisterListeners();
58
+ return status;
59
+ });
60
+ }
61
+ registerListeners() {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ });
64
+ }
65
+ unregisterListeners() {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ });
68
+ }
69
+ }
@@ -0,0 +1,4 @@
1
+ // Files
2
+ export * from './RedisClient.mjs';
3
+ export * from './RedisPublisher.mjs';
4
+ export * from './RedisSubscriber.mjs';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from './UpsertResult.mjs';
2
+ export * from './mariaDb.mjs';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ export declare enum TransactionManagerLogLevel {
2
+ VERBOSE = 1,
3
+ INFO = 2,
4
+ WARNING = 3,
5
+ ERROR = 4,
6
+ CRITICAL = 5
7
+ }
@@ -0,0 +1,4 @@
1
+ export declare enum TransactionManagerTimeoutAction {
2
+ COMMIT = 1,
3
+ ROLLBACK = 2
4
+ }
@@ -0,0 +1,2 @@
1
+ export * from './TransactionManagerLogLevel';
2
+ export * from './TransactionManagerTimeoutAction';
@@ -1 +1,6 @@
1
+ export * from './constants';
2
+ export * from './interfaces';
3
+ export * from './managers';
4
+ export * from './services';
5
+ export * from './types';
1
6
  export * from './utils';
@@ -0,0 +1,27 @@
1
+ import { Transaction } from "sequelize";
2
+ import EventEmitter from 'eventemitter3';
3
+ import { TransactionManagerLogLevel, TransactionManagerTimeoutAction } from "../constants";
4
+ import { TransactionManagerAddOption, TransactionManagerEventTypes } from "./TransactionManager.types";
5
+ export declare class TransactionManager {
6
+ static DEFAULT_TIMEOUT: number;
7
+ static DEFAULT_ACTION: TransactionManagerTimeoutAction;
8
+ private static instance;
9
+ private logLevel;
10
+ private transactionTimeoutMap;
11
+ private readonly emitter;
12
+ constructor();
13
+ static getInstance(): TransactionManager;
14
+ private getTransactionLogArg;
15
+ setLogLevel(logLevel: TransactionManagerLogLevel): void;
16
+ addListener<T extends EventEmitter.EventNames<TransactionManagerEventTypes>>(event: T, fn: EventEmitter.EventListener<TransactionManagerEventTypes, T>): void;
17
+ removeListener<T extends EventEmitter.EventNames<TransactionManagerEventTypes>>(event: T, fn: EventEmitter.EventListener<TransactionManagerEventTypes, T>): void;
18
+ add(transaction: Transaction, option?: TransactionManagerAddOption): void;
19
+ remove(transaction: Transaction): void;
20
+ flush(action?: TransactionManagerTimeoutAction): Promise<PromiseSettledResult<{
21
+ handled: boolean;
22
+ transaction: Transaction;
23
+ }>[]>;
24
+ private execute;
25
+ private timeout;
26
+ private afterCommit;
27
+ }
@@ -0,0 +1,9 @@
1
+ import { TransactionManagerTimeoutAction } from "../constants";
2
+ import { Transaction } from "sequelize";
3
+ export interface TransactionManagerAddOption {
4
+ timeout?: number;
5
+ timeoutAction?: TransactionManagerTimeoutAction;
6
+ }
7
+ export type TransactionManagerEventTypes = {
8
+ onUnhandledTransaction: (transaction: Transaction, handled: boolean) => any;
9
+ };
@@ -0,0 +1,2 @@
1
+ export * from './TransactionManager';
2
+ export * from './TransactionManager.types';
@@ -0,0 +1 @@
1
+ export * from './redis';
@@ -0,0 +1,21 @@
1
+ import redis, { RedisClientType, RedisDefaultModules, RedisFunctions, RedisModules, RedisScripts } from 'redis';
2
+ export declare class RedisClient {
3
+ private readonly options;
4
+ private status;
5
+ readonly client: RedisClientType<RedisDefaultModules & RedisModules, RedisFunctions, RedisScripts>;
6
+ constructor(options?: RedisClient.RedisClientOptions);
7
+ getStatus(): RedisClient.Status;
8
+ start(): Promise<RedisClient.Status>;
9
+ stop(): Promise<RedisClient.Status>;
10
+ private handleOnConnect;
11
+ private handleOnError;
12
+ }
13
+ export declare namespace RedisClient {
14
+ enum Status {
15
+ RUNNING = 0,
16
+ STOPPED = 1
17
+ }
18
+ interface RedisClientOptions {
19
+ redisOptions?: redis.RedisClientOptions;
20
+ }
21
+ }
@@ -0,0 +1,13 @@
1
+ import { RedisClient } from "./RedisClient";
2
+ export declare class RedisPublisher extends RedisClient {
3
+ private logging;
4
+ constructor(options?: RedisClient.RedisClientOptions);
5
+ start(): Promise<RedisClient.Status>;
6
+ stop(): Promise<RedisClient.Status>;
7
+ setLogging(logging: RedisPublisher.LOGGING): void;
8
+ getLogging(): RedisPublisher.LOGGING;
9
+ publish(channel: string, data: string | object): Promise<void>;
10
+ }
11
+ export declare namespace RedisPublisher {
12
+ type LOGGING = 'none' | 'length' | 'data';
13
+ }
@@ -0,0 +1,11 @@
1
+ import { RedisClient } from "./RedisClient";
2
+ import { PubSubListener } from "@redis/client/dist/lib/client/pub-sub";
3
+ export declare class RedisSubscriber extends RedisClient {
4
+ constructor(options?: RedisClient.RedisClientOptions);
5
+ subscribe<T extends boolean = false>(channels: string | string[], listener: PubSubListener<T>, bufferMode?: T | undefined): Promise<void>;
6
+ unsubscribe<T extends boolean = false>(channels: string | string[], listener?: PubSubListener<T> | undefined, bufferMode?: T | undefined): Promise<void>;
7
+ start(): Promise<RedisClient.Status>;
8
+ stop(): Promise<RedisClient.Status>;
9
+ protected registerListeners(): Promise<void>;
10
+ protected unregisterListeners(): Promise<void>;
11
+ }
@@ -0,0 +1,3 @@
1
+ export * from './RedisClient';
2
+ export * from './RedisPublisher';
3
+ export * from './RedisSubscriber';
@@ -0,0 +1,2 @@
1
+ import { Model } from "sequelize-typescript";
2
+ export type UpsertResult<M extends Model> = [M, boolean];
@@ -0,0 +1,2 @@
1
+ export * from './UpsertResult';
2
+ export * from './mariaDb';
@@ -0,0 +1,8 @@
1
+ import type { TransactionManager, TransactionManagerAddOption } from "../managers";
2
+ import type { Sequelize } from "sequelize-typescript";
3
+ import type { Transaction, TransactionOptions } from "sequelize";
4
+ export interface MariaDbConnection {
5
+ transactionManager: TransactionManager;
6
+ sequelize: Sequelize;
7
+ transaction: (options?: TransactionOptions, managerOptions?: TransactionManagerAddOption) => Promise<Transaction>;
8
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powfix/core-js",
3
- "version": "0.18.1",
3
+ "version": "0.18.2",
4
4
  "description": "core package",
5
5
  "author": "Kwon Kyung-Min <powfix@gmail.com>",
6
6
  "private": false,