@vendit-dev/thirdparty-adapters 0.1.1 → 0.1.4

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.1",
3
+ "version": "0.1.4",
4
4
  "description": "Third party adapters between v-cloud and other PMS/CMS providers.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -13,19 +13,30 @@
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
+ "@types/node-fetch": "^2.6.1",
25
+ "@typescript-eslint/eslint-plugin": "^3.6.1",
26
+ "@typescript-eslint/parser": "^3.6.1",
18
27
  "@vendit-dev/utility-modules": "^0.10.3",
28
+ "babel-eslint": "^10.1.0",
29
+ "babel-plugin-module-resolver": "^4.0.0",
30
+ "cross-env": "^7.0.2",
31
+ "eslint": "^7.4.0",
19
32
  "eslint-config-airbnb-base": "^13.1.0",
20
33
  "eslint-plugin-import": "^2.16.0",
21
- "eslint": "^8.12.0",
22
- "tslint": "^6.1.3",
23
- "typescript": "^4.6.3"
34
+ "sequelize": "^6.6.2",
35
+ "typescript": "^3.9.6"
24
36
  },
25
37
  "dependencies": {
26
- "ioredis": "^5.0.4",
27
38
  "moment": "^2.29.2",
28
- "node-fetch": "^3.2.3",
39
+ "node-fetch": "2",
29
40
  "uuid": "^8.3.2"
30
41
  }
31
42
  }