@vendit-dev/thirdparty-adapters 0.1.0 → 0.1.3

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/lib/index.js CHANGED
@@ -1,2 +1,8 @@
1
- import SanhaWingsAdapter from './adapters/sanhaWings';
2
- export { SanhaWingsAdapter, };
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SanhaWingsAdapter = void 0;
7
+ var sanhaWings_1 = __importDefault(require("./adapters/sanhaWings"));
8
+ exports.SanhaWingsAdapter = sanhaWings_1.default;
@@ -1,15 +1,14 @@
1
- import { Redis } from 'ioredis';
2
1
  export default class MutexLock {
3
- redis: Redis;
2
+ redis: any;
4
3
  hashPrefix: string;
5
4
  mutexLockInterval: number;
6
5
  constructor({ redis, hashPrefix, mutexLockInterval }: {
7
- redis: Redis;
6
+ redis: any;
8
7
  hashPrefix: string;
9
8
  mutexLockInterval?: number;
10
9
  });
11
10
  getMutexLockKey: (id: string) => string;
12
- tryMutexLock: (streamId: string, lockHash: string) => Promise<"OK" | null>;
11
+ tryMutexLock: (streamId: string, lockHash: string) => any;
13
12
  getMutexLock: (streamId: string) => Promise<string>;
14
- unlockMutexLock: (streamId: string, lockHash: string) => Promise<string | null>;
13
+ unlockMutexLock: (streamId: string, lockHash: string) => Promise<any>;
15
14
  }
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -7,31 +8,82 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
9
  });
9
10
  };
10
- import { v4 as uuid } from 'uuid';
11
- const sleep = (sleepTime) => new Promise(resolve => setTimeout(resolve, sleepTime));
12
- export default class MutexLock {
13
- constructor({ redis, hashPrefix, mutexLockInterval = 50 }) {
14
- this.getMutexLockKey = (id) => `${this.hashPrefix}${id}`;
15
- this.tryMutexLock = (streamId, lockHash) => this.redis.set(this.getMutexLockKey(streamId), lockHash, 'EX', 60, 'NX');
16
- this.getMutexLock = (streamId) => __awaiter(this, void 0, void 0, function* () {
17
- const lockHash = uuid();
18
- let lock;
19
- while (!lock) {
20
- lock = yield this.tryMutexLock(streamId, lockHash); // eslint-disable-line
21
- yield sleep(this.mutexLockInterval); // eslint-disable-line
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
22
32
  }
23
- return lockHash;
24
- });
25
- this.unlockMutexLock = (streamId, lockHash) => __awaiter(this, void 0, void 0, function* () {
26
- const existingLockHash = yield this.redis.get(this.getMutexLockKey(streamId));
27
- if (existingLockHash === lockHash) {
28
- yield this.redis.del(this.getMutexLockKey(streamId));
29
- return existingLockHash;
30
- }
31
- return null;
32
- });
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ var uuid_1 = require("uuid");
40
+ var sleep = function (sleepTime) { return new Promise(function (resolve) { return setTimeout(resolve, sleepTime); }); };
41
+ var MutexLock = /** @class */ (function () {
42
+ function MutexLock(_a) {
43
+ var _this = this;
44
+ var redis = _a.redis, hashPrefix = _a.hashPrefix, _b = _a.mutexLockInterval, mutexLockInterval = _b === void 0 ? 50 : _b;
45
+ this.getMutexLockKey = function (id) { return "" + _this.hashPrefix + id; };
46
+ this.tryMutexLock = function (streamId, lockHash) { return _this.redis.set(_this.getMutexLockKey(streamId), lockHash, 'EX', 60, 'NX'); };
47
+ this.getMutexLock = function (streamId) { return __awaiter(_this, void 0, void 0, function () {
48
+ var lockHash, lock;
49
+ return __generator(this, function (_a) {
50
+ switch (_a.label) {
51
+ case 0:
52
+ lockHash = uuid_1.v4();
53
+ _a.label = 1;
54
+ case 1:
55
+ if (!!lock) return [3 /*break*/, 4];
56
+ return [4 /*yield*/, this.tryMutexLock(streamId, lockHash)];
57
+ case 2:
58
+ lock = _a.sent(); // eslint-disable-line
59
+ return [4 /*yield*/, sleep(this.mutexLockInterval)];
60
+ case 3:
61
+ _a.sent(); // eslint-disable-line
62
+ return [3 /*break*/, 1];
63
+ case 4: return [2 /*return*/, lockHash];
64
+ }
65
+ });
66
+ }); };
67
+ this.unlockMutexLock = function (streamId, lockHash) { return __awaiter(_this, void 0, void 0, function () {
68
+ var existingLockHash;
69
+ return __generator(this, function (_a) {
70
+ switch (_a.label) {
71
+ case 0: return [4 /*yield*/, this.redis.get(this.getMutexLockKey(streamId))];
72
+ case 1:
73
+ existingLockHash = _a.sent();
74
+ if (!(existingLockHash === lockHash)) return [3 /*break*/, 3];
75
+ return [4 /*yield*/, this.redis.del(this.getMutexLockKey(streamId))];
76
+ case 2:
77
+ _a.sent();
78
+ return [2 /*return*/, existingLockHash];
79
+ case 3: return [2 /*return*/, null];
80
+ }
81
+ });
82
+ }); };
33
83
  this.redis = redis;
34
84
  this.hashPrefix = hashPrefix;
35
85
  this.mutexLockInterval = mutexLockInterval;
36
86
  }
37
- }
87
+ return MutexLock;
88
+ }());
89
+ exports.default = MutexLock;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vendit-dev/thirdparty-adapters",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "description": "Third party adapters between v-cloud and other PMS/CMS providers.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -13,17 +13,27 @@
13
13
  "author": "Vendit <dev@vendit.co.kr> (https://vendit.co.kr)",
14
14
  "license": "MIT",
15
15
  "devDependencies": {
16
- "@typescript-eslint/eslint-plugin": "^5.18.0",
17
- "@typescript-eslint/parser": "^5.18.0",
16
+ "@babel/cli": "^7.10.5",
17
+ "@babel/core": "^7.10.5",
18
+ "@babel/node": "^7.10.5",
19
+ "@babel/plugin-proposal-class-properties": "^7.10.4",
20
+ "@babel/plugin-proposal-optional-chaining": "^7.10.4",
21
+ "@babel/preset-env": "^7.10.4",
22
+ "@babel/preset-flow": "^7.10.4",
23
+ "@types/node": "^14.11.4",
24
+ "@typescript-eslint/eslint-plugin": "^3.6.1",
25
+ "@typescript-eslint/parser": "^3.6.1",
18
26
  "@vendit-dev/utility-modules": "^0.10.3",
27
+ "babel-eslint": "^10.1.0",
28
+ "babel-plugin-module-resolver": "^4.0.0",
29
+ "cross-env": "^7.0.2",
30
+ "eslint": "^7.4.0",
19
31
  "eslint-config-airbnb-base": "^13.1.0",
20
32
  "eslint-plugin-import": "^2.16.0",
21
- "eslint": "^8.12.0",
22
- "tslint": "^6.1.3",
23
- "typescript": "^4.6.3"
33
+ "sequelize": "^6.6.2",
34
+ "typescript": "^3.9.6"
24
35
  },
25
36
  "dependencies": {
26
- "ioredis": "^5.0.4",
27
37
  "moment": "^2.29.2",
28
38
  "node-fetch": "^3.2.3",
29
39
  "uuid": "^8.3.2"
package/readme.md CHANGED
@@ -1,131 +1,4 @@
1
- # Passive Promise
1
+ # ThirdParty-Adapters
2
2
 
3
- Promise that's resolvable from outside of executor context.
3
+ adapter modules for third party PMS & CMS providers.
4
4
 
5
- It comes with super light-weighted bundle with 0 dependencies.
6
-
7
- ## What is this?
8
-
9
- This library exports the class named `PassivePromise` which works exactly like normal Promises, but can be resolved outside of promise executor context.
10
-
11
- ## Installation
12
-
13
- `npm install passive-promise`
14
-
15
- or
16
-
17
- `yarn add passive-promise`
18
-
19
- The library exported with esnext module syntax.
20
-
21
- ## Usage Examples
22
-
23
- Just use exactly like normal promise, but returned promise (which is extended Promise class) also comes with the `resolve()` and `reject()` method in it, which you can use them to force resolve or reject the promise from outside.
24
-
25
- All the chain methods such as then, catch, finally works as expected, but remind that the both resolve, reject method of any chained PassivePromise instance will propagate to the root PassivePromise instance regardless of its depth.
26
-
27
- ### Common Usage
28
-
29
- ```javascript
30
- import PassivePromise from 'passive-promise';
31
-
32
- (async () => {
33
- const foo = new PassivePromise((resolve, reject) => setTimeout(() => resolve(1), 1000));
34
-
35
- console.log(await foo); // 1 after 1 sec
36
-
37
- const bar = new PassivePromise((resolve, reject) => setTimeout(() => resolve(1), 1000));
38
-
39
- bar.resolve(-1);
40
-
41
- console.log(await bar); // -1 immedietly
42
-
43
- const baz = new PassivePromise((resolve, reject) => setTimeout(() => resolve(1), 1000));
44
-
45
- baz.reject(0) // Unhandled promise rejection.
46
- })()
47
-
48
- (async () => {
49
- const foo = new PassivePromise(() => {})
50
- .then((fulfilled) => console.log(fulfilled));
51
-
52
- foo.resolve(1); // 1
53
-
54
-
55
- const bar = new PassivePromise(() => {})
56
- .then((fulfilled) => console.log(fulfilled))
57
- .catch((errored) => console.log('Promise rejected!', errored));
58
-
59
- bar.reject(-1); // Promise rejected! -1
60
-
61
- const baz = new PassivePromise(() => {})
62
- .then(
63
- (fulfilled) => console.log(fulfilled),
64
- (errored) => console.log('Promise rejected!', errored),
65
- )
66
- .finally(() => console.log('Finally.'));
67
-
68
- baz.reject(-1) // Promise rejected! -1 Finally.
69
- })()
70
-
71
- ```
72
-
73
- ### Chain propagation
74
-
75
-
76
- ```javascript
77
- import PassivePromise from 'passive-promise';
78
-
79
- (async () => {
80
- const chainedPromise = new PassivePromise(() => {})
81
- .then((firstRes) => {
82
- console.log('first.');
83
- })
84
- .then((secondRes) => {
85
- console.log('second.');
86
- })
87
- .then((thirdRes) => {
88
- console.log('third.');
89
- });
90
-
91
- chainedPromise.resolve(1);
92
-
93
- await chainedPromise; // first. second. third.
94
-
95
- const middleChain = new PassivePromise(() => {})
96
- .then((firstRes) => {
97
- console.log('first.');
98
- })
99
- .then((secondRes) => {
100
- console.log('second.');
101
- });
102
-
103
- middleChain.then((thirdRes) => {
104
- console.log('third.');
105
- });
106
-
107
- // Regardless of position of PassivePromise instance in the chained promises, they always resolve root promise in the chain.
108
- middleChain.resolve(1);
109
-
110
- await middleChain; // first. second. third.
111
-
112
- // If you want to resolve the instance itself rather than root instance, use passiveResolve() and passiveReject() instead.
113
-
114
- const anotherChain = new PassivePromise(() => {})
115
- .then((firstRes) => {
116
- console.log('first.');
117
- })
118
- .then((secondRes) => {
119
- console.log('second.');
120
- });
121
-
122
- anotherChain.then((thirdRes) => {
123
- console.log('third.');
124
- });
125
-
126
- // We want to directly resolve this promise rather than the whole promise chain here.
127
- anotherChain.passiveResolve(1);
128
-
129
- await anotherChain; // third.
130
- })()
131
- ```