@powfix/core-js 0.12.11 → 0.13.0

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/dist/browser.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from './src/constants';
1
+ export * from './src/constants/browser';
2
2
  export * from './src/interfaces';
3
3
  export * from './src/scripts';
4
4
  export * from './src/services/browser';
package/dist/browser.js CHANGED
@@ -14,7 +14,7 @@ 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("./src/constants"), exports);
17
+ __exportStar(require("./src/constants/browser"), exports);
18
18
  __exportStar(require("./src/interfaces"), exports);
19
19
  __exportStar(require("./src/scripts"), exports);
20
20
  __exportStar(require("./src/services/browser"), exports);
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export * from './browser';
2
+ export * from './src/constants';
3
+ export * from './src/managers';
2
4
  export * from './src/services';
package/dist/index.js CHANGED
@@ -16,5 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  // Extend browser imports & exports
18
18
  __exportStar(require("./browser"), exports);
19
+ __exportStar(require("./src/constants"), exports);
20
+ __exportStar(require("./src/managers"), exports);
19
21
  // services
20
22
  __exportStar(require("./src/services"), exports);
@@ -0,0 +1,4 @@
1
+ export * from './COORDINATE';
2
+ export * from './CRUD';
3
+ export * from './DISTANCE';
4
+ export * from './DURATION';
@@ -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
+ __exportStar(require("./COORDINATE"), exports);
18
+ __exportStar(require("./CRUD"), exports);
19
+ __exportStar(require("./DISTANCE"), exports);
20
+ __exportStar(require("./DURATION"), exports);
@@ -1,4 +1,2 @@
1
- export * from './COORDINATE';
2
- export * from './CRUD';
3
- export * from './DISTANCE';
4
- export * from './DURATION';
1
+ export * from './transactionManager';
2
+ export * from './browser';
@@ -14,7 +14,5 @@ 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("./COORDINATE"), exports);
18
- __exportStar(require("./CRUD"), exports);
19
- __exportStar(require("./DISTANCE"), exports);
20
- __exportStar(require("./DURATION"), exports);
17
+ __exportStar(require("./transactionManager"), exports);
18
+ __exportStar(require("./browser"), exports);
@@ -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,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,4 @@
1
+ export declare enum TransactionManagerTimeoutAction {
2
+ COMMIT = 1,
3
+ ROLLBACK = 2
4
+ }
@@ -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,2 @@
1
+ export * from './TransactionManagerLogLevel';
2
+ export * from './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);
@@ -0,0 +1,23 @@
1
+ import { Transaction } from "sequelize";
2
+ import EventEmitter from 'eventemitter3';
3
+ import { TransactionManagerLogLevel, TransactionManagerTimeoutAction } from "../constants";
4
+ import { TransactionManagerAddOption, TransactionManagerEventTypes } from "./TransactionManager.types";
5
+ 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
+ private timeout;
21
+ private afterCommit;
22
+ }
23
+ export default TransactionManager;
@@ -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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const eventemitter3_1 = __importDefault(require("eventemitter3"));
16
+ const constants_1 = require("../constants");
17
+ const LOG_TAG = '[TransactionManager]';
18
+ class TransactionManager {
19
+ constructor() {
20
+ // Members
21
+ this.logLevel = constants_1.TransactionManagerLogLevel.VERBOSE;
22
+ this.transactionTimeoutMap = new Map();
23
+ // Emitter
24
+ this.emitter = new eventemitter3_1.default();
25
+ if (this.logLevel >= constants_1.TransactionManagerLogLevel.VERBOSE) {
26
+ console.log(LOG_TAG, 'TransactionManager instance initialized');
27
+ }
28
+ }
29
+ static getInstance() {
30
+ return this.instance || (this.instance = new TransactionManager());
31
+ }
32
+ getTransactionLogArg(transaction) {
33
+ const id = transaction === null || transaction === void 0 ? void 0 : transaction.id;
34
+ return id ? `transaction(${id})` : '';
35
+ }
36
+ setLogLevel(logLevel) {
37
+ this.logLevel = logLevel;
38
+ if (this.logLevel >= constants_1.TransactionManagerLogLevel.VERBOSE) {
39
+ console.log(LOG_TAG, 'log level changed to', logLevel);
40
+ }
41
+ }
42
+ addListener(event, fn) {
43
+ this.emitter.addListener(event, fn);
44
+ }
45
+ removeListener(event, fn) {
46
+ this.emitter.removeListener(event, fn);
47
+ }
48
+ add(transaction, option) {
49
+ var _a, _b;
50
+ if (this.transactionTimeoutMap.has(transaction)) {
51
+ if (this.logLevel >= constants_1.TransactionManagerLogLevel.ERROR) {
52
+ console.error(LOG_TAG, 'transaction already exists');
53
+ }
54
+ return;
55
+ }
56
+ const action = (_a = option === null || option === void 0 ? void 0 : option.timeoutAction) !== null && _a !== void 0 ? _a : TransactionManager.DEFAULT_ACTION;
57
+ const timeout = (_b = option === null || option === void 0 ? void 0 : option.timeout) !== null && _b !== void 0 ? _b : TransactionManager.DEFAULT_TIMEOUT;
58
+ const handler = setTimeout(this.timeout.bind(this), timeout, transaction, action);
59
+ this.transactionTimeoutMap.set(transaction, handler);
60
+ // Callback
61
+ transaction.afterCommit(this.afterCommit.bind(this));
62
+ }
63
+ remove(transaction) {
64
+ const transactionTimeout = this.transactionTimeoutMap.get(transaction);
65
+ if (transactionTimeout != null) {
66
+ clearTimeout(transactionTimeout);
67
+ this.transactionTimeoutMap.delete(transaction);
68
+ if (this.logLevel >= constants_1.TransactionManagerLogLevel.VERBOSE) {
69
+ console.log(LOG_TAG, this.getTransactionLogArg(transaction), 'removed');
70
+ }
71
+ }
72
+ }
73
+ timeout(transaction, action) {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ const finished = transaction === null || transaction === void 0 ? void 0 : transaction.finished;
76
+ if (finished != null) {
77
+ if (this.logLevel >= constants_1.TransactionManagerLogLevel.VERBOSE) {
78
+ console.log(LOG_TAG, this.getTransactionLogArg(transaction), `is already handled(${finished}) after timeout`);
79
+ }
80
+ this.remove(transaction);
81
+ return;
82
+ }
83
+ try {
84
+ let finished;
85
+ switch (action) {
86
+ case constants_1.TransactionManagerTimeoutAction.ROLLBACK: {
87
+ yield transaction.rollback();
88
+ finished = 'rollback';
89
+ break;
90
+ }
91
+ case constants_1.TransactionManagerTimeoutAction.COMMIT: {
92
+ yield transaction.commit();
93
+ finished = 'commit';
94
+ break;
95
+ }
96
+ default: {
97
+ if (this.logLevel >= constants_1.TransactionManagerLogLevel.ERROR) {
98
+ console.error(LOG_TAG, `unknown action`, action);
99
+ }
100
+ break;
101
+ }
102
+ }
103
+ const handled = finished != null;
104
+ if (finished != null) {
105
+ if (this.logLevel >= constants_1.TransactionManagerLogLevel.ERROR) {
106
+ console.error(LOG_TAG, this.getTransactionLogArg(transaction), `handled(${finished}) after timeout`);
107
+ }
108
+ }
109
+ else {
110
+ if (this.logLevel >= constants_1.TransactionManagerLogLevel.ERROR) {
111
+ console.error(LOG_TAG, this.getTransactionLogArg(transaction), `not handled 🚫`);
112
+ }
113
+ }
114
+ // Emit
115
+ this.emitter.emit('onUnhandledTransaction', transaction, handled);
116
+ }
117
+ catch (e) {
118
+ console.error(e);
119
+ }
120
+ });
121
+ }
122
+ afterCommit(transaction) {
123
+ this.remove(transaction);
124
+ }
125
+ }
126
+ TransactionManager.DEFAULT_TIMEOUT = 60 * 1000;
127
+ TransactionManager.DEFAULT_ACTION = constants_1.TransactionManagerTimeoutAction.ROLLBACK;
128
+ exports.default = TransactionManager;
@@ -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
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export * from './TransactionManager';
2
+ export * from './TransactionManager.types';
@@ -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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powfix/core-js",
3
- "version": "0.12.11",
3
+ "version": "0.13.0",
4
4
  "description": "core package",
5
5
  "author": "Kwon Kyung-Min <powfix@gmail.com>",
6
6
  "private": false,