@things-factory/lock-client 7.0.0-alpha.18
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/CHANGELOG.md +8 -0
- package/config/config.development.js +12 -0
- package/config/config.production.js +12 -0
- package/dist-server/controllers/config.js +7 -0
- package/dist-server/controllers/config.js.map +1 -0
- package/dist-server/controllers/lock-api/index.js +8 -0
- package/dist-server/controllers/lock-api/index.js.map +1 -0
- package/dist-server/controllers/lock-api/locks.js +18 -0
- package/dist-server/controllers/lock-api/locks.js.map +1 -0
- package/dist-server/controllers/lock-api/release-lock.js +30 -0
- package/dist-server/controllers/lock-api/release-lock.js.map +1 -0
- package/dist-server/controllers/lock-api/request-lock.js +20 -0
- package/dist-server/controllers/lock-api/request-lock.js.map +1 -0
- package/dist-server/controllers/lock-api/try-lock.js +39 -0
- package/dist-server/controllers/lock-api/try-lock.js.map +1 -0
- package/dist-server/controllers/lock-service-local/index.js +5 -0
- package/dist-server/controllers/lock-service-local/index.js.map +1 -0
- package/dist-server/controllers/lock-service-local/lock.js +25 -0
- package/dist-server/controllers/lock-service-local/lock.js.map +1 -0
- package/dist-server/controllers/lock-service-local/locks.js +43 -0
- package/dist-server/controllers/lock-service-local/locks.js.map +1 -0
- package/dist-server/controllers/types.js +3 -0
- package/dist-server/controllers/types.js.map +1 -0
- package/dist-server/index.js +12 -0
- package/dist-server/index.js.map +1 -0
- package/dist-server/tsconfig.tsbuildinfo +1 -0
- package/helps/config/lock-service.md +20 -0
- package/logs/.08636eb59927f12972f6774f5947c8507b3564c2-audit.json +20 -0
- package/logs/application-2024-02-28-22.log +0 -0
- package/logs/application-2024-02-28-23.log +0 -0
- package/package.json +30 -0
- package/server/controllers/config.ts +4 -0
- package/server/controllers/lock-api/index.ts +4 -0
- package/server/controllers/lock-api/locks.ts +14 -0
- package/server/controllers/lock-api/release-lock.ts +26 -0
- package/server/controllers/lock-api/request-lock.ts +17 -0
- package/server/controllers/lock-api/try-lock.ts +37 -0
- package/server/controllers/lock-service-local/index.ts +1 -0
- package/server/controllers/lock-service-local/lock.ts +24 -0
- package/server/controllers/lock-service-local/locks.ts +53 -0
- package/server/controllers/types.ts +11 -0
- package/server/index.ts +11 -0
- package/server/tsconfig.json +10 -0
- package/tests/lock-service-local.spec.ts +40 -0
- package/tests/try-lock.spec.ts +59 -0
- package/things-factory.config.js +1 -0
- package/translations/en.json +1 -0
- package/translations/ja.json +1 -0
- package/translations/ko.json +1 -0
- package/translations/ms.json +1 -0
- package/translations/zh.json +1 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
|
6
|
+
and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
<!-- ## [Unreleased] -->
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
lock: {
|
|
3
|
+
/* Name to be used for setting client's "application" properties when trying alock */
|
|
4
|
+
application: 'operato-lock',
|
|
5
|
+
/*
|
|
6
|
+
Lock service endpoint
|
|
7
|
+
caution) endpoint for "localhost" has some problem.
|
|
8
|
+
https://github.com/node-fetch/node-fetch/issues/1624
|
|
9
|
+
*/
|
|
10
|
+
endpoint: 'http://127.0.0.1:9910'
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
lock: {
|
|
3
|
+
/* Name to be used for setting client's "application" properties when trying alock */
|
|
4
|
+
application: 'operato-lock',
|
|
5
|
+
/*
|
|
6
|
+
Lock service endpoint
|
|
7
|
+
caution) endpoint for "localhost" has some problem.
|
|
8
|
+
https://github.com/node-fetch/node-fetch/issues/1624
|
|
9
|
+
*/
|
|
10
|
+
endpoint: 'http://127.0.0.1:9910'
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Application = exports.LockServiceEndpoint = void 0;
|
|
4
|
+
const env_1 = require("@things-factory/env");
|
|
5
|
+
exports.LockServiceEndpoint = env_1.config.get('lock/endpoint', 'http://127.0.0.1:9910');
|
|
6
|
+
exports.Application = env_1.config.get('lock/application');
|
|
7
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../server/controllers/config.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAE/B,QAAA,mBAAmB,GAAW,YAAM,CAAC,GAAG,CAAC,eAAe,EAAE,uBAAuB,CAAC,CAAA;AAClF,QAAA,WAAW,GAAW,YAAM,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAA","sourcesContent":["import { config } from '@things-factory/env'\n\nexport const LockServiceEndpoint: string = config.get('lock/endpoint', 'http://127.0.0.1:9910')\nexport const Application: string = config.get('lock/application')\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./request-lock"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./try-lock"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./release-lock"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./locks"), exports);
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/controllers/lock-api/index.ts"],"names":[],"mappings":";;;AAAA,yDAA8B;AAC9B,qDAA0B;AAC1B,yDAA8B;AAC9B,kDAAuB","sourcesContent":["export * from './request-lock'\nexport * from './try-lock'\nexport * from './release-lock'\nexport * from './locks'\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLocks = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
|
|
6
|
+
const config_1 = require("../config");
|
|
7
|
+
async function getLocks() {
|
|
8
|
+
const response = await (0, node_fetch_1.default)(config_1.LockServiceEndpoint + '/locks', {
|
|
9
|
+
method: 'get',
|
|
10
|
+
headers: {
|
|
11
|
+
accept: 'application/json',
|
|
12
|
+
'Content-Type': 'application/json'
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
return await response.json();
|
|
16
|
+
}
|
|
17
|
+
exports.getLocks = getLocks;
|
|
18
|
+
//# sourceMappingURL=locks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locks.js","sourceRoot":"","sources":["../../../server/controllers/lock-api/locks.ts"],"names":[],"mappings":";;;;AAAA,oEAA8B;AAC9B,sCAA+C;AAExC,KAAK,UAAU,QAAQ;IAC5B,MAAM,QAAQ,GAAG,MAAM,IAAA,oBAAK,EAAC,4BAAmB,GAAG,QAAQ,EAAE;QAC3D,MAAM,EAAE,KAAK;QACb,OAAO,EAAE;YACP,MAAM,EAAE,kBAAkB;YAC1B,cAAc,EAAE,kBAAkB;SACnC;KACF,CAAC,CAAA;IAEF,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;AAC9B,CAAC;AAVD,4BAUC","sourcesContent":["import fetch from 'node-fetch'\nimport { LockServiceEndpoint } from '../config'\n\nexport async function getLocks() {\n const response = await fetch(LockServiceEndpoint + '/locks', {\n method: 'get',\n headers: {\n accept: 'application/json',\n 'Content-Type': 'application/json'\n }\n })\n\n return await response.json()\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.releaseLock = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
|
|
6
|
+
const config_1 = require("../config");
|
|
7
|
+
async function releaseLock(request) {
|
|
8
|
+
var body = JSON.stringify(request);
|
|
9
|
+
const response = await (0, node_fetch_1.default)(config_1.LockServiceEndpoint + '/locking/release', {
|
|
10
|
+
method: 'post',
|
|
11
|
+
headers: {
|
|
12
|
+
accept: 'application/json',
|
|
13
|
+
'Content-Type': 'application/json'
|
|
14
|
+
},
|
|
15
|
+
body
|
|
16
|
+
});
|
|
17
|
+
var result;
|
|
18
|
+
if (response.ok) {
|
|
19
|
+
result = await response.json();
|
|
20
|
+
}
|
|
21
|
+
else if (response.status === 404) {
|
|
22
|
+
result = { error: 'Item not found' };
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
result = { error: await response.text() };
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
exports.releaseLock = releaseLock;
|
|
30
|
+
//# sourceMappingURL=release-lock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"release-lock.js","sourceRoot":"","sources":["../../../server/controllers/lock-api/release-lock.ts"],"names":[],"mappings":";;;;AAAA,oEAA8B;AAC9B,sCAA+C;AAGxC,KAAK,UAAU,WAAW,CAAC,OAAoB;IACpD,IAAI,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;IAClC,MAAM,QAAQ,GAAG,MAAM,IAAA,oBAAK,EAAC,4BAAmB,GAAG,kBAAkB,EAAE;QACrE,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,MAAM,EAAE,kBAAkB;YAC1B,cAAc,EAAE,kBAAkB;SACnC;QACD,IAAI;KACL,CAAC,CAAA;IAEF,IAAI,MAAM,CAAA;IACV,IAAI,QAAQ,CAAC,EAAE,EAAE;QACf,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;KAC/B;SAAM,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE;QAClC,MAAM,GAAG,EAAE,KAAK,EAAE,gBAAgB,EAAE,CAAA;KACrC;SAAM;QACL,MAAM,GAAG,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAA;KAC1C;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AArBD,kCAqBC","sourcesContent":["import fetch from 'node-fetch'\nimport { LockServiceEndpoint } from '../config'\nimport { LockRequest } from '../types'\n\nexport async function releaseLock(request: LockRequest) {\n var body = JSON.stringify(request)\n const response = await fetch(LockServiceEndpoint + '/locking/release', {\n method: 'post',\n headers: {\n accept: 'application/json',\n 'Content-Type': 'application/json'\n },\n body\n })\n\n var result\n if (response.ok) {\n result = await response.json()\n } else if (response.status === 404) {\n result = { error: 'Item not found' }\n } else {\n result = { error: await response.text() }\n }\n\n return result\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.requestLock = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
|
|
6
|
+
const config_1 = require("../config");
|
|
7
|
+
async function requestLock() {
|
|
8
|
+
const response = await (0, node_fetch_1.default)(config_1.LockServiceEndpoint + '/locking', {
|
|
9
|
+
method: 'POST',
|
|
10
|
+
headers: {
|
|
11
|
+
accept: 'application/json',
|
|
12
|
+
'Content-Type': 'application/json'
|
|
13
|
+
},
|
|
14
|
+
body: ''
|
|
15
|
+
});
|
|
16
|
+
const { id } = await response.json();
|
|
17
|
+
return id;
|
|
18
|
+
}
|
|
19
|
+
exports.requestLock = requestLock;
|
|
20
|
+
//# sourceMappingURL=request-lock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-lock.js","sourceRoot":"","sources":["../../../server/controllers/lock-api/request-lock.ts"],"names":[],"mappings":";;;;AAAA,oEAA8B;AAE9B,sCAA+C;AAExC,KAAK,UAAU,WAAW;IAC/B,MAAM,QAAQ,GAAG,MAAM,IAAA,oBAAK,EAAC,4BAAmB,GAAG,UAAU,EAAE;QAC7D,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,MAAM,EAAE,kBAAkB;YAC1B,cAAc,EAAE,kBAAkB;SACnC;QACD,IAAI,EAAE,EAAE;KACT,CAAC,CAAA;IAEF,MAAM,EAAE,EAAE,EAAE,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;IACpC,OAAO,EAAE,CAAA;AACX,CAAC;AAZD,kCAYC","sourcesContent":["import fetch from 'node-fetch'\n\nimport { LockServiceEndpoint } from '../config'\n\nexport async function requestLock() {\n const response = await fetch(LockServiceEndpoint + '/locking', {\n method: 'POST',\n headers: {\n accept: 'application/json',\n 'Content-Type': 'application/json'\n },\n body: ''\n })\n\n const { id } = await response.json()\n return id\n}\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tryLock = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_fetch_1 = tslib_1.__importStar(require("node-fetch"));
|
|
6
|
+
const config_1 = require("../config");
|
|
7
|
+
const release_lock_1 = require("./release-lock");
|
|
8
|
+
async function tryLock(request, maxTimeout = 3000) {
|
|
9
|
+
var body = JSON.stringify(request);
|
|
10
|
+
const controller = new AbortController();
|
|
11
|
+
const timeout = setTimeout(() => {
|
|
12
|
+
controller.abort();
|
|
13
|
+
}, maxTimeout);
|
|
14
|
+
try {
|
|
15
|
+
const response = await (0, node_fetch_1.default)(config_1.LockServiceEndpoint + '/locking/try', {
|
|
16
|
+
method: 'POST',
|
|
17
|
+
headers: {
|
|
18
|
+
accept: 'application/json',
|
|
19
|
+
'Content-Type': 'application/json'
|
|
20
|
+
},
|
|
21
|
+
body,
|
|
22
|
+
signal: controller.signal
|
|
23
|
+
});
|
|
24
|
+
return await response.json();
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
if (e instanceof node_fetch_1.AbortError) {
|
|
28
|
+
await (0, release_lock_1.releaseLock)(request);
|
|
29
|
+
return {
|
|
30
|
+
payload: { error: 'timeout' }
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
clearTimeout(timeout);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.tryLock = tryLock;
|
|
39
|
+
//# sourceMappingURL=try-lock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"try-lock.js","sourceRoot":"","sources":["../../../server/controllers/lock-api/try-lock.ts"],"names":[],"mappings":";;;;AAAA,iEAA8C;AAE9C,sCAA+C;AAE/C,iDAA4C;AAErC,KAAK,UAAU,OAAO,CAAC,OAAoB,EAAE,aAAqB,IAAI;IAC3E,IAAI,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;IAElC,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAA;IACxC,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;QAC9B,UAAU,CAAC,KAAK,EAAE,CAAA;IACpB,CAAC,EAAE,UAAU,CAAC,CAAA;IAEd,IAAI;QACF,MAAM,QAAQ,GAAG,MAAM,IAAA,oBAAK,EAAC,4BAAmB,GAAG,cAAc,EAAE;YACjE,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,MAAM,EAAE,kBAAkB;gBAC1B,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI;YACJ,MAAM,EAAE,UAAU,CAAC,MAAM;SAC1B,CAAC,CAAA;QAEF,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;KAC7B;IAAC,OAAO,CAAC,EAAE;QACV,IAAI,CAAC,YAAY,uBAAU,EAAE;YAC3B,MAAM,IAAA,0BAAW,EAAC,OAAO,CAAC,CAAA;YAC1B,OAAO;gBACL,OAAO,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE;aAC9B,CAAA;SACF;KACF;YAAS;QACR,YAAY,CAAC,OAAO,CAAC,CAAA;KACtB;AACH,CAAC;AA9BD,0BA8BC","sourcesContent":["import fetch, { AbortError } from 'node-fetch'\n\nimport { LockServiceEndpoint } from '../config'\nimport { LockRequest } from '../types'\nimport { releaseLock } from './release-lock'\n\nexport async function tryLock(request: LockRequest, maxTimeout: number = 3000) {\n var body = JSON.stringify(request)\n\n const controller = new AbortController()\n const timeout = setTimeout(() => {\n controller.abort()\n }, maxTimeout)\n\n try {\n const response = await fetch(LockServiceEndpoint + '/locking/try', {\n method: 'POST',\n headers: {\n accept: 'application/json',\n 'Content-Type': 'application/json'\n },\n body,\n signal: controller.signal\n })\n\n return await response.json()\n } catch (e) {\n if (e instanceof AbortError) {\n await releaseLock(request)\n return {\n payload: { error: 'timeout' }\n }\n }\n } finally {\n clearTimeout(timeout)\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/controllers/lock-service-local/index.ts"],"names":[],"mappings":";;;AAAA,kDAAuB","sourcesContent":["export * from './locks'\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Lock = void 0;
|
|
4
|
+
class Lock {
|
|
5
|
+
acquire(timeout) {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
if (!this.resolver) {
|
|
8
|
+
this.resolver = resolve;
|
|
9
|
+
this.timeout = setTimeout(() => {
|
|
10
|
+
reject('timeout');
|
|
11
|
+
}, timeout);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
release(result) {
|
|
16
|
+
if (this.resolver) {
|
|
17
|
+
clearTimeout(this.timeout);
|
|
18
|
+
const resolve = this.resolver;
|
|
19
|
+
this.resolver = null;
|
|
20
|
+
resolve(result);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.Lock = Lock;
|
|
25
|
+
//# sourceMappingURL=lock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lock.js","sourceRoot":"","sources":["../../../server/controllers/lock-service-local/lock.ts"],"names":[],"mappings":";;;AAAA,MAAa,IAAI;IAIf,OAAO,CAAC,OAAe;QACrB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;gBAClB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAA;gBACvB,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;oBAC7B,MAAM,CAAC,SAAS,CAAC,CAAA;gBACnB,CAAC,EAAE,OAAO,CAAC,CAAA;aACZ;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,CAAC,MAAM;QACZ,IAAI,IAAI,CAAC,QAAQ,EAAE;YACjB,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;YAC1B,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAA;YAC7B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAA;YACpB,OAAO,CAAC,MAAM,CAAC,CAAA;SAChB;IACH,CAAC;CACF;AAvBD,oBAuBC","sourcesContent":["export class Lock {\n private resolver: (value: unknown) => any\n private timeout: any\n\n acquire(timeout: number) {\n return new Promise((resolve, reject) => {\n if (!this.resolver) {\n this.resolver = resolve\n this.timeout = setTimeout(() => {\n reject('timeout')\n }, timeout)\n }\n })\n }\n\n release(result) {\n if (this.resolver) {\n clearTimeout(this.timeout)\n const resolve = this.resolver\n this.resolver = null\n resolve(result)\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.releaseLock = exports.tryLock = exports.requestLock = exports.getLocks = void 0;
|
|
4
|
+
const lock_1 = require("./lock");
|
|
5
|
+
const locks = {};
|
|
6
|
+
var id = 1;
|
|
7
|
+
async function getLocks() {
|
|
8
|
+
return this.locks;
|
|
9
|
+
}
|
|
10
|
+
exports.getLocks = getLocks;
|
|
11
|
+
async function requestLock() {
|
|
12
|
+
return String(id++);
|
|
13
|
+
}
|
|
14
|
+
exports.requestLock = requestLock;
|
|
15
|
+
async function tryLock(request, maxTimeout = 30000) {
|
|
16
|
+
const { id, payload } = request;
|
|
17
|
+
if (locks[id]) {
|
|
18
|
+
throw `Lock [id:${id}] is already taken.`;
|
|
19
|
+
}
|
|
20
|
+
const lock = new lock_1.Lock();
|
|
21
|
+
locks[id] = {
|
|
22
|
+
lock,
|
|
23
|
+
payload
|
|
24
|
+
};
|
|
25
|
+
try {
|
|
26
|
+
return await lock.acquire(maxTimeout);
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
throw e;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.tryLock = tryLock;
|
|
33
|
+
function releaseLock(request) {
|
|
34
|
+
const { id, payload } = request;
|
|
35
|
+
const lock = locks[id];
|
|
36
|
+
if (!lock) {
|
|
37
|
+
throw `Lock [id:${id}] is not found.`;
|
|
38
|
+
}
|
|
39
|
+
delete locks[id];
|
|
40
|
+
lock.lock.release(payload);
|
|
41
|
+
}
|
|
42
|
+
exports.releaseLock = releaseLock;
|
|
43
|
+
//# sourceMappingURL=locks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locks.js","sourceRoot":"","sources":["../../../server/controllers/lock-service-local/locks.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAI7B,MAAM,KAAK,GAKP,EAAE,CAAA;AAEN,IAAI,EAAE,GAAG,CAAC,CAAA;AAEH,KAAK,UAAU,QAAQ;IAC5B,OAAO,IAAI,CAAC,KAAK,CAAA;AACnB,CAAC;AAFD,4BAEC;AAEM,KAAK,UAAU,WAAW;IAC/B,OAAO,MAAM,CAAC,EAAE,EAAE,CAAC,CAAA;AACrB,CAAC;AAFD,kCAEC;AAEM,KAAK,UAAU,OAAO,CAAC,OAAoB,EAAE,aAAqB,KAAK;IAC5E,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,OAAO,CAAA;IAE/B,IAAI,KAAK,CAAC,EAAE,CAAC,EAAE;QACb,MAAM,YAAY,EAAE,qBAAqB,CAAA;KAC1C;IACD,MAAM,IAAI,GAAG,IAAI,WAAI,EAAE,CAAA;IAEvB,KAAK,CAAC,EAAE,CAAC,GAAG;QACV,IAAI;QACJ,OAAO;KACR,CAAA;IAED,IAAI;QACF,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;KACtC;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,CAAC,CAAA;KACR;AACH,CAAC;AAlBD,0BAkBC;AAED,SAAgB,WAAW,CAAC,OAAoB;IAC9C,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,OAAO,CAAA;IAC/B,MAAM,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC,CAAA;IAEtB,IAAI,CAAC,IAAI,EAAE;QACT,MAAM,YAAY,EAAE,iBAAiB,CAAA;KACtC;IAED,OAAO,KAAK,CAAC,EAAE,CAAC,CAAA;IAEhB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;AAC5B,CAAC;AAXD,kCAWC","sourcesContent":["import { Lock } from './lock'\nimport { LockServiceEndpoint } from '../config'\nimport { LockRequest } from '../types'\n\nconst locks: {\n [id: string]: {\n lock: Lock\n payload: any\n }\n} = {}\n\nvar id = 1\n\nexport async function getLocks() {\n return this.locks\n}\n\nexport async function requestLock() {\n return String(id++)\n}\n\nexport async function tryLock(request: LockRequest, maxTimeout: number = 30000) {\n const { id, payload } = request\n\n if (locks[id]) {\n throw `Lock [id:${id}] is already taken.`\n }\n const lock = new Lock()\n\n locks[id] = {\n lock,\n payload\n }\n\n try {\n return await lock.acquire(maxTimeout)\n } catch (e) {\n throw e\n }\n}\n\nexport function releaseLock(request: LockRequest) {\n const { id, payload } = request\n const lock = locks[id]\n\n if (!lock) {\n throw `Lock [id:${id}] is not found.`\n }\n\n delete locks[id]\n\n lock.lock.release(payload)\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../server/controllers/types.ts"],"names":[],"mappings":"","sourcesContent":["export type LockRequest = {\n id?: string\n payload?: any\n}\n\nexport interface LockClient {\n getLocks: (name: string, group: string, dlq: boolean) => Promise<any>\n requestLock: () => Promise<any>\n tryLock: (request: LockRequest, maxTimeout?: number) => Promise<any>\n releaseLock: (request: LockRequest) => void\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.releaseLock = exports.tryLock = exports.requestLock = exports.getLocks = void 0;
|
|
4
|
+
const config_1 = require("./controllers/config");
|
|
5
|
+
const lock_api_1 = require("./controllers/lock-api");
|
|
6
|
+
const lock_service_local_1 = require("./controllers/lock-service-local");
|
|
7
|
+
const useLocalLock = config_1.LockServiceEndpoint == 'internal';
|
|
8
|
+
exports.getLocks = useLocalLock ? lock_service_local_1.getLocks : lock_api_1.getLocks;
|
|
9
|
+
exports.requestLock = useLocalLock ? lock_service_local_1.requestLock : lock_api_1.requestLock;
|
|
10
|
+
exports.tryLock = useLocalLock ? lock_service_local_1.tryLock : lock_api_1.tryLock;
|
|
11
|
+
exports.releaseLock = useLocalLock ? lock_service_local_1.releaseLock : lock_api_1.releaseLock;
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;;AAAA,iDAA0D;AAE1D,qDAAiK;AACjK,yEAAuK;AAEvK,MAAM,YAAY,GAAG,4BAAmB,IAAI,UAAU,CAAA;AAEzC,QAAA,QAAQ,GAAG,YAAY,CAAC,CAAC,CAAC,6BAAa,CAAC,CAAC,CAAC,mBAAc,CAAA;AACxD,QAAA,WAAW,GAAG,YAAY,CAAC,CAAC,CAAC,gCAAgB,CAAC,CAAC,CAAC,sBAAiB,CAAA;AACjE,QAAA,OAAO,GAAG,YAAY,CAAC,CAAC,CAAC,4BAAY,CAAC,CAAC,CAAC,kBAAa,CAAA;AACrD,QAAA,WAAW,GAAG,YAAY,CAAC,CAAC,CAAC,gCAAgB,CAAC,CAAC,CAAC,sBAAiB,CAAA","sourcesContent":["import { LockServiceEndpoint } from './controllers/config'\n\nimport { getLocks as remoteGetLocks, requestLock as remoteRequestLock, tryLock as remoteTryLock, releaseLock as remoteReleaseLock } from './controllers/lock-api'\nimport { getLocks as localGetLocks, requestLock as localRequestLock, tryLock as localTryLock, releaseLock as localReleaseLock } from './controllers/lock-service-local'\n\nconst useLocalLock = LockServiceEndpoint == 'internal'\n\nexport const getLocks = useLocalLock ? localGetLocks : remoteGetLocks\nexport const requestLock = useLocalLock ? localRequestLock : remoteRequestLock\nexport const tryLock = useLocalLock ? localTryLock : remoteTryLock\nexport const releaseLock = useLocalLock ? localReleaseLock : remoteReleaseLock\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"program":{"fileNames":["../../../node_modules/lerna/node_modules/typescript/lib/lib.es5.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2015.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2016.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2017.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2018.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2019.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2020.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.dom.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.dom.iterable.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2015.core.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2017.object.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2017.string.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2017.intl.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2018.intl.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2018.promise.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2019.array.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2019.object.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2019.string.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2019.intl.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2020.date.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2020.promise.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2020.string.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2020.intl.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2020.number.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.esnext.intl.d.ts","../../../node_modules/tslib/tslib.d.ts","../server/controllers/config.ts","../../../node_modules/@types/node/assert.d.ts","../../../node_modules/@types/node/assert/strict.d.ts","../../../node_modules/buffer/index.d.ts","../../../node_modules/undici-types/header.d.ts","../../../node_modules/undici-types/readable.d.ts","../../../node_modules/undici-types/file.d.ts","../../../node_modules/undici-types/fetch.d.ts","../../../node_modules/undici-types/formdata.d.ts","../../../node_modules/undici-types/connector.d.ts","../../../node_modules/undici-types/client.d.ts","../../../node_modules/undici-types/errors.d.ts","../../../node_modules/undici-types/dispatcher.d.ts","../../../node_modules/undici-types/global-dispatcher.d.ts","../../../node_modules/undici-types/global-origin.d.ts","../../../node_modules/undici-types/pool-stats.d.ts","../../../node_modules/undici-types/pool.d.ts","../../../node_modules/undici-types/handlers.d.ts","../../../node_modules/undici-types/balanced-pool.d.ts","../../../node_modules/undici-types/agent.d.ts","../../../node_modules/undici-types/mock-interceptor.d.ts","../../../node_modules/undici-types/mock-agent.d.ts","../../../node_modules/undici-types/mock-client.d.ts","../../../node_modules/undici-types/mock-pool.d.ts","../../../node_modules/undici-types/mock-errors.d.ts","../../../node_modules/undici-types/proxy-agent.d.ts","../../../node_modules/undici-types/api.d.ts","../../../node_modules/undici-types/cookies.d.ts","../../../node_modules/undici-types/patch.d.ts","../../../node_modules/undici-types/filereader.d.ts","../../../node_modules/undici-types/diagnostics-channel.d.ts","../../../node_modules/undici-types/websocket.d.ts","../../../node_modules/undici-types/content-type.d.ts","../../../node_modules/undici-types/cache.d.ts","../../../node_modules/undici-types/interceptors.d.ts","../../../node_modules/undici-types/index.d.ts","../../../node_modules/@types/node/globals.d.ts","../../../node_modules/@types/node/async_hooks.d.ts","../../../node_modules/@types/node/buffer.d.ts","../../../node_modules/@types/node/child_process.d.ts","../../../node_modules/@types/node/cluster.d.ts","../../../node_modules/@types/node/console.d.ts","../../../node_modules/@types/node/constants.d.ts","../../../node_modules/@types/node/crypto.d.ts","../../../node_modules/@types/node/dgram.d.ts","../../../node_modules/@types/node/diagnostics_channel.d.ts","../../../node_modules/@types/node/dns.d.ts","../../../node_modules/@types/node/dns/promises.d.ts","../../../node_modules/@types/node/domain.d.ts","../../../node_modules/@types/node/dom-events.d.ts","../../../node_modules/@types/node/events.d.ts","../../../node_modules/@types/node/fs.d.ts","../../../node_modules/@types/node/fs/promises.d.ts","../../../node_modules/@types/node/http.d.ts","../../../node_modules/@types/node/http2.d.ts","../../../node_modules/@types/node/https.d.ts","../../../node_modules/@types/node/inspector.d.ts","../../../node_modules/@types/node/module.d.ts","../../../node_modules/@types/node/net.d.ts","../../../node_modules/@types/node/os.d.ts","../../../node_modules/@types/node/path.d.ts","../../../node_modules/@types/node/perf_hooks.d.ts","../../../node_modules/@types/node/process.d.ts","../../../node_modules/@types/node/punycode.d.ts","../../../node_modules/@types/node/querystring.d.ts","../../../node_modules/@types/node/readline.d.ts","../../../node_modules/@types/node/readline/promises.d.ts","../../../node_modules/@types/node/repl.d.ts","../../../node_modules/@types/node/stream.d.ts","../../../node_modules/@types/node/stream/promises.d.ts","../../../node_modules/@types/node/stream/consumers.d.ts","../../../node_modules/@types/node/stream/web.d.ts","../../../node_modules/@types/node/string_decoder.d.ts","../../../node_modules/@types/node/test.d.ts","../../../node_modules/@types/node/timers.d.ts","../../../node_modules/@types/node/timers/promises.d.ts","../../../node_modules/@types/node/tls.d.ts","../../../node_modules/@types/node/trace_events.d.ts","../../../node_modules/@types/node/tty.d.ts","../../../node_modules/@types/node/url.d.ts","../../../node_modules/@types/node/util.d.ts","../../../node_modules/@types/node/v8.d.ts","../../../node_modules/@types/node/vm.d.ts","../../../node_modules/@types/node/wasi.d.ts","../../../node_modules/@types/node/worker_threads.d.ts","../../../node_modules/@types/node/zlib.d.ts","../../../node_modules/@types/node/globals.global.d.ts","../../../node_modules/@types/node/index.d.ts","../../../node_modules/form-data/index.d.ts","../../../node_modules/@types/node-fetch/externals.d.ts","../../../node_modules/@types/node-fetch/index.d.ts","../server/controllers/lock-api/request-lock.ts","../server/controllers/types.ts","../server/controllers/lock-api/release-lock.ts","../server/controllers/lock-api/try-lock.ts","../server/controllers/lock-api/locks.ts","../server/controllers/lock-api/index.ts","../server/controllers/lock-service-local/lock.ts","../server/controllers/lock-service-local/locks.ts","../server/controllers/lock-service-local/index.ts","../server/index.ts","../../../node_modules/@jest/expect-utils/build/index.d.ts","../../../node_modules/chalk/index.d.ts","../../../node_modules/@sinclair/typebox/typebox.d.ts","../../../node_modules/@jest/schemas/build/index.d.ts","../../../node_modules/pretty-format/build/index.d.ts","../../../node_modules/jest-diff/build/index.d.ts","../../../node_modules/jest-matcher-utils/build/index.d.ts","../../../node_modules/expect/build/index.d.ts","../../../node_modules/@types/jest/index.d.ts"],"fileInfos":[{"version":"8730f4bf322026ff5229336391a18bcaa1f94d4f82416c8b2f3954e2ccaae2ba","affectsGlobalScope":true},"dc47c4fa66b9b9890cf076304de2a9c5201e94b740cffdf09f87296d877d71f6","7a387c58583dfca701b6c85e0adaf43fb17d590fb16d5b2dc0a2fbd89f35c467","8a12173c586e95f4433e0c6dc446bc88346be73ffe9ca6eec7aa63c8f3dca7f9","5f4e733ced4e129482ae2186aae29fde948ab7182844c3a5a51dd346182c7b06","4b421cbfb3a38a27c279dec1e9112c3d1da296f77a1a85ddadf7e7a425d45d18","1fc5ab7a764205c68fa10d381b08417795fc73111d6dd16b5b1ed36badb743d9",{"version":"3aafcb693fe5b5c3bd277bd4c3a617b53db474fe498fc5df067c5603b1eebde7","affectsGlobalScope":true},{"version":"f3d4da15233e593eacb3965cde7960f3fddf5878528d882bcedd5cbaba0193c7","affectsGlobalScope":true},{"version":"adb996790133eb33b33aadb9c09f15c2c575e71fb57a62de8bf74dbf59ec7dfb","affectsGlobalScope":true},{"version":"8cc8c5a3bac513368b0157f3d8b31cfdcfe78b56d3724f30f80ed9715e404af8","affectsGlobalScope":true},{"version":"cdccba9a388c2ee3fd6ad4018c640a471a6c060e96f1232062223063b0a5ac6a","affectsGlobalScope":true},{"version":"c5c05907c02476e4bde6b7e76a79ffcd948aedd14b6a8f56e4674221b0417398","affectsGlobalScope":true},{"version":"5f406584aef28a331c36523df688ca3650288d14f39c5d2e555c95f0d2ff8f6f","affectsGlobalScope":true},{"version":"22f230e544b35349cfb3bd9110b6ef37b41c6d6c43c3314a31bd0d9652fcec72","affectsGlobalScope":true},{"version":"7ea0b55f6b315cf9ac2ad622b0a7813315bb6e97bf4bb3fbf8f8affbca7dc695","affectsGlobalScope":true},{"version":"3013574108c36fd3aaca79764002b3717da09725a36a6fc02eac386593110f93","affectsGlobalScope":true},{"version":"eb26de841c52236d8222f87e9e6a235332e0788af8c87a71e9e210314300410a","affectsGlobalScope":true},{"version":"3be5a1453daa63e031d266bf342f3943603873d890ab8b9ada95e22389389006","affectsGlobalScope":true},{"version":"17bb1fc99591b00515502d264fa55dc8370c45c5298f4a5c2083557dccba5a2a","affectsGlobalScope":true},{"version":"7ce9f0bde3307ca1f944119f6365f2d776d281a393b576a18a2f2893a2d75c98","affectsGlobalScope":true},{"version":"6a6b173e739a6a99629a8594bfb294cc7329bfb7b227f12e1f7c11bc163b8577","affectsGlobalScope":true},{"version":"81cac4cbc92c0c839c70f8ffb94eb61e2d32dc1c3cf6d95844ca099463cf37ea","affectsGlobalScope":true},{"version":"b0124885ef82641903d232172577f2ceb5d3e60aed4da1153bab4221e1f6dd4e","affectsGlobalScope":true},{"version":"0eb85d6c590b0d577919a79e0084fa1744c1beba6fd0d4e951432fa1ede5510a","affectsGlobalScope":true},{"version":"da233fc1c8a377ba9e0bed690a73c290d843c2c3d23a7bd7ec5cd3d7d73ba1e0","affectsGlobalScope":true},{"version":"d154ea5bb7f7f9001ed9153e876b2d5b8f5c2bb9ec02b3ae0d239ec769f1f2ae","affectsGlobalScope":true},{"version":"bb2d3fb05a1d2ffbca947cc7cbc95d23e1d053d6595391bd325deb265a18d36c","affectsGlobalScope":true},{"version":"c80df75850fea5caa2afe43b9949338ce4e2de086f91713e9af1a06f973872b8","affectsGlobalScope":true},{"version":"9d57b2b5d15838ed094aa9ff1299eecef40b190722eb619bac4616657a05f951","affectsGlobalScope":true},{"version":"6c51b5dd26a2c31dbf37f00cfc32b2aa6a92e19c995aefb5b97a3a64f1ac99de","affectsGlobalScope":true},{"version":"6e7997ef61de3132e4d4b2250e75343f487903ddf5370e7ce33cf1b9db9a63ed","affectsGlobalScope":true},{"version":"2ad234885a4240522efccd77de6c7d99eecf9b4de0914adb9a35c0c22433f993","affectsGlobalScope":true},{"version":"5e5e095c4470c8bab227dbbc61374878ecead104c74ab9960d3adcccfee23205","affectsGlobalScope":true},{"version":"09aa50414b80c023553090e2f53827f007a301bc34b0495bfb2c3c08ab9ad1eb","affectsGlobalScope":true},{"version":"d7f680a43f8cd12a6b6122c07c54ba40952b0c8aa140dcfcf32eb9e6cb028596","affectsGlobalScope":true},{"version":"3787b83e297de7c315d55d4a7c546ae28e5f6c0a361b7a1dcec1f1f50a54ef11","affectsGlobalScope":true},{"version":"e7e8e1d368290e9295ef18ca23f405cf40d5456fa9f20db6373a61ca45f75f40","affectsGlobalScope":true},{"version":"faf0221ae0465363c842ce6aa8a0cbda5d9296940a8e26c86e04cc4081eea21e","affectsGlobalScope":true},{"version":"06393d13ea207a1bfe08ec8d7be562549c5e2da8983f2ee074e00002629d1871","affectsGlobalScope":true},{"version":"2768ef564cfc0689a1b76106c421a2909bdff0acbe87da010785adab80efdd5c","affectsGlobalScope":true},{"version":"b248e32ca52e8f5571390a4142558ae4f203ae2f94d5bac38a3084d529ef4e58","affectsGlobalScope":true},{"version":"52d1bb7ab7a3306fd0375c8bff560feed26ed676a5b0457fa8027b563aecb9a4","affectsGlobalScope":true},"7a1971efcba559ea9002ada4c4e3c925004fb67a755300d53b5edf9399354900","dccbd4a87d6d3661baf2d028682effb96a50f057d1effc883e6c605c45e1109f","efc7d584a33fe3422847783d228f315c4cd1afe74bd7cf8e3f0e4c1125129fef","7394959e5a741b185456e1ef5d64599c36c60a323207450991e7a42e08911419","4967529644e391115ca5592184d4b63980569adf60ee685f968fd59ab1557188","5929864ce17fba74232584d90cb721a89b7ad277220627cc97054ba15a98ea8f","7180c03fd3cb6e22f911ce9ba0f8a7008b1a6ddbe88ccf16a9c8140ef9ac1686","25c8056edf4314820382a5fdb4bb7816999acdcb929c8f75e3f39473b87e85bc","54cb85a47d760da1c13c00add10d26b5118280d44d58e6908d8e89abbd9d7725","3e4825171442666d31c845aeb47fcd34b62e14041bb353ae2b874285d78482aa","c6fd2c5a395f2432786c9cb8deb870b9b0e8ff7e22c029954fabdd692bff6195","a967bfe3ad4e62243eb604bf956101e4c740f5921277c60debaf325c1320bf88","e9775e97ac4877aebf963a0289c81abe76d1ec9a2a7778dbe637e5151f25c5f3","471e1da5a78350bc55ef8cef24eb3aca6174143c281b8b214ca2beda51f5e04a","cadc8aced301244057c4e7e73fbcae534b0f5b12a37b150d80e5a45aa4bebcbd","385aab901643aa54e1c36f5ef3107913b10d1b5bb8cbcd933d4263b80a0d7f20","9670d44354bab9d9982eca21945686b5c24a3f893db73c0dae0fd74217a4c219","db3435f3525cd785bf21ec6769bf8da7e8a776be1a99e2e7efb5f244a2ef5fee","c3b170c45fc031db31f782e612adf7314b167e60439d304b49e704010e7bafe5","40383ebef22b943d503c6ce2cb2e060282936b952a01bea5f9f493d5fb487cc7","4893a895ea92c85345017a04ed427cbd6a1710453338df26881a6019432febdd","3a84b7cb891141824bd00ef8a50b6a44596aded4075da937f180c90e362fe5f6","13f6f39e12b1518c6650bbb220c8985999020fe0f21d818e28f512b7771d00f9","9b5369969f6e7175740bf51223112ff209f94ba43ecd3bb09eefff9fd675624a","4fe9e626e7164748e8769bbf74b538e09607f07ed17c2f20af8d680ee49fc1da","24515859bc0b836719105bb6cc3d68255042a9f02a6022b3187948b204946bd2","33203609eba548914dc83ddf6cadbc0bcb6e8ef89f6d648ca0908ae887f9fcc5","0db18c6e78ea846316c012478888f33c11ffadab9efd1cc8bcc12daded7a60b6","89167d696a849fce5ca508032aabfe901c0868f833a8625d5a9c6e861ef935d2","e53a3c2a9f624d90f24bf4588aacd223e7bec1b9d0d479b68d2f4a9e6011147f","339dc5265ee5ed92e536a93a04c4ebbc2128f45eeec6ed29f379e0085283542c","9f0a92164925aa37d4a5d9dd3e0134cff8177208dba55fd2310cd74beea40ee2","8bfdb79bf1a9d435ec48d9372dc93291161f152c0865b81fc0b2694aedb4578d","2e85db9e6fd73cfa3d7f28e0ab6b55417ea18931423bd47b409a96e4a169e8e6","c46e079fe54c76f95c67fb89081b3e399da2c7d109e7dca8e4b58d83e332e605","d32275be3546f252e3ad33976caf8c5e842c09cb87d468cb40d5f4cf092d1acc","4a0c3504813a3289f7fb1115db13967c8e004aa8e4f8a9021b95285502221bd1",{"version":"a14ed46fa3f5ffc7a8336b497cd07b45c2084213aaca933a22443fcb2eef0d07","affectsGlobalScope":true},"cce1f5f86974c1e916ec4a8cab6eec9aa8e31e8148845bf07fbaa8e1d97b1a2c",{"version":"7fd7fcbf021a5845bdd9397d4649fcf2fe17152d2098140fc723099a215d19ad","affectsGlobalScope":true},"df3389f71a71a38bc931aaf1ef97a65fada98f0a27f19dd12f8b8de2b0f4e461","7b43160a49cf2c6082da0465876c4a0b164e160b81187caeb0a6ca7a281e85ba",{"version":"41fb2a1c108fbf46609ce5a451b7ec78eb9b5ada95fd5b94643e4b26397de0b3","affectsGlobalScope":true},"a40826e8476694e90da94aa008283a7de50d1dafd37beada623863f1901cb7fb",{"version":"8b809082dfeffc8cc4f3b9c59f55c0ff52ba12f5ae0766cb5c35deee83b8552e","affectsGlobalScope":true},"bd3f5d05b6b5e4bfcea7739a45f3ffb4a7f4a3442ba7baf93e0200799285b8f1","4c775c2fccabf49483c03cd5e3673f87c1ffb6079d98e7b81089c3def79e29c6","8806ae97308ef26363bd7ec8071bca4d07fb575f905ee3d8a91aff226df6d618","af5bf1db6f1804fb0069039ae77a05d60133c77a2158d9635ea27b6bb2828a8f","b7fe70be794e13d1b7940e318b8770cd1fb3eced7707805318a2e3aaac2c3e9e",{"version":"2c71199d1fc83bf17636ad5bf63a945633406b7b94887612bba4ef027c662b3e","affectsGlobalScope":true},{"version":"674168aa3db414ea0a19b2a31d901b2d49705c7a495e43ffdc96928543010f8c","affectsGlobalScope":true},"fe1fd6afdfe77976d4c702f3746c05fb05a7e566845c890e0e970fe9376d6a90","313a0b063f5188037db113509de1b934a0e286f14e9479af24fada241435e707","afb1701fd4be413a8a5a88df6befdd4510c30a31372c07a4138facf61594c66d","87ef1a23caa071b07157c72077fa42b86d30568f9dc9e31eed24d5d14fc30ba8","396a8939b5e177542bdf9b5262b4eee85d29851b2d57681fa9d7eae30e225830","21773f5ac69ddf5a05636ba1f50b5239f4f2d27e4420db147fc2f76a5ae598ac",{"version":"ea455cc68871b049bcecd9f56d4cf27b852d6dafd5e3b54468ca87cc11604e4d","affectsGlobalScope":true},"c07146dbbbd8b347241b5df250a51e48f2d7bef19b1e187b1a3f20c849988ff1","45b1053e691c5af9bfe85060a3e1542835f8d84a7e6e2e77ca305251eda0cb3c","0f05c06ff6196958d76b865ae17245b52d8fe01773626ac3c43214a2458ea7b7",{"version":"ae5507fc333d637dec9f37c6b3f4d423105421ea2820a64818de55db85214d66","affectsGlobalScope":true},{"version":"0666f4c99b8688c7be5956df8fecf5d1779d3b22f8f2a88258ae7072c7b6026f","affectsGlobalScope":true},"8abd0566d2854c4bd1c5e48e05df5c74927187f1541e6770001d9637ac41542e","54e854615c4eafbdd3fd7688bd02a3aafd0ccf0e87c98f79d3e9109f047ce6b8","d8dba11dc34d50cb4202de5effa9a1b296d7a2f4a029eec871f894bddfb6430d","8b71dd18e7e63b6f991b511a201fad7c3bf8d1e0dd98acb5e3d844f335a73634","01d8e1419c84affad359cc240b2b551fb9812b450b4d3d456b64cda8102d4f60","8221b00f271cf7f535a8eeec03b0f80f0929c7a16116e2d2df089b41066de69b","269929a24b2816343a178008ac9ae9248304d92a8ba8e233055e0ed6dbe6ef71","93452d394fdd1dc551ec62f5042366f011a00d342d36d50793b3529bfc9bd633","7fa32887f8a97909fca35ebba3740f8caf8df146618d8fff957a3f89f67a2f6a","9a9634296cca836c3308923ba7aa094fa6ed76bb1e366d8ddcf5c65888ab1024",{"version":"bddce945d552a963c9733db106b17a25474eefcab7fc990157a2134ef55d4954","affectsGlobalScope":true},{"version":"7052b7b0c3829df3b4985bab2fd74531074b4835d5a7b263b75c82f0916ad62f","affectsGlobalScope":true},"aa34c3aa493d1c699601027c441b9664547c3024f9dbab1639df7701d63d18fa","4b55240c2a03b2c71e98a7fc528b16136faa762211c92e781a01c37821915ea6","7c651f8dce91a927ab62925e73f190763574c46098f2b11fb8ddc1b147a6709a","7440ab60f4cb031812940cc38166b8bb6fbf2540cfe599f87c41c08011f0c1df",{"version":"94c086dff8dbc5998749326bc69b520e8e4273fb5b7b58b50e0210e0885dfcde","affectsGlobalScope":true},{"version":"f5b5dc128973498b75f52b1b8c2d5f8629869104899733ae485100c2309b4c12","affectsGlobalScope":true},"ebe5facd12fd7745cda5f4bc3319f91fb29dc1f96e57e9c6f8b260a7cc5b67ee","79bad8541d5779c85e82a9fb119c1fe06af77a71cc40f869d62ad379473d4b75","37dc027f781c75f0f546e329cfac7cf92a6b289f42458f47a9adc25e516b6839",{"version":"629d20681ca284d9e38c0a019f647108f5fe02f9c59ac164d56f5694fc3faf4d","affectsGlobalScope":true},"e7dbf5716d76846c7522e910896c5747b6df1abd538fee8f5291bdc843461795",{"version":"ab9b9a36e5284fd8d3bf2f7d5fcbc60052f25f27e4d20954782099282c60d23e","affectsGlobalScope":true},"b510d0a18e3db42ac9765d26711083ec1e8b4e21caaca6dc4d25ae6e8623f447","736097ddbb2903bef918bb3b5811ef1c9c5656f2a73bd39b22a91b9cc2525e50","4340936f4e937c452ae783514e7c7bbb7fc06d0c97993ff4865370d0962bb9cf","5fc6e6b8232254d80ed6b802372dba7f426f0a596f5fe26b7773acfdc8232926","ba4725715356027701e55349caabb2cc4eaba84da6316732835a1e29025b0b84","223bd06de80eba051768301a211a783d7e1589ab7e4c2f47ece07746cd2a27ab","d1dc090cac0ad68f0b8d7295033207fe8d0099b827d6271df48f55a98a3ec598","28937be53ea939a99684bafff1947454126385cdc6637feec18e7d50fcf76fc4","1999c6e958fde500ce2d9017e015c8d29440abfbab80ddbf26f894c44d124c40","232c3add067cd12d4a5a011d398e9ef43a097681c579551a95471370dc8a04b7","51e9a3d626cfe611d53bc8a8ad2254b6992bca520b8319cbcc3e8f51dba805fb","a66777319fed1725e28a738776e920bbecdcca4738f80d44ed37860df0caf69c","29b374a6d60cf72690b4ce17e5cc20fb60404cc0c87bd6f0ef9e02d00812559e","1c681a43fe82b8df31a87c6b47a959b536982900c0c7a4e6f4fd8af97ad34bb8","cdcc132f207d097d7d3aa75615ab9a2e71d6a478162dde8b67f88ea19f3e54de","0d14fa22c41fdc7277e6f71473b20ebc07f40f00e38875142335d5b63cdfc9d2","c085e9aa62d1ae1375794c1fb927a445fa105fed891a7e24edbb1c3300f7384a","f315e1e65a1f80992f0509e84e4ae2df15ecd9ef73df975f7c98813b71e4c8da","5b9586e9b0b6322e5bfbd2c29bd3b8e21ab9d871f82346cb71020e3d84bae73e","3e70a7e67c2cb16f8cd49097360c0309fe9d1e3210ff9222e9dac1f8df9d4fb6","ab68d2a3e3e8767c3fba8f80de099a1cfc18c0de79e42cb02ae66e22dfe14a66","d96cc6598148bf1a98fb2e8dcf01c63a4b3558bdaec6ef35e087fd0562eb40ec",{"version":"5ab630d466ac55baa6d32820378098404fc18ba9da6f7bc5df30c5dbb1cffae8","affectsGlobalScope":true}],"options":{"allowSyntheticDefaultImports":true,"declaration":false,"emitDecoratorMetadata":true,"esModuleInterop":true,"experimentalDecorators":true,"importHelpers":true,"inlineSources":true,"module":1,"noEmitOnError":true,"noImplicitAny":false,"outDir":"./","skipLibCheck":true,"sourceMap":true,"strict":false,"target":4,"useDefineForClassFields":false},"fileIdsList":[[148],[150,153],[98,124,132,133,134],[46],[82],[83,88,116],[84,95,96,103,113,124],[84,85,95,103],[86,125],[87,88,96,104],[88,113,121],[89,91,95,103],[82,90],[91,92],[95],[93,95],[82,95],[95,96,97,113,124],[95,96,97,110,113,116],[80,83,129],[91,95,98,103,113,124],[95,96,98,99,103,113,121,124],[98,100,113,121,124],[46,47,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131],[95,101],[102,124,129],[91,95,103,113],[104],[105],[82,106],[107,123,129],[108],[109],[95,110,111],[110,112,125,127],[83,95,113,114,115,116],[83,113,115],[113,114],[116],[117],[82,113],[95,119,120],[119,120],[88,103,113,121],[122],[103,123],[83,98,109,124],[88,125],[113,126],[102,127],[128],[83,88,95,97,106,113,124,127,129],[113,130],[146,152],[98,113,132],[150],[147,151],[149],[57,61,124],[57,113,124],[52],[54,57,121,124],[103,121],[132],[52,132],[54,57,103,124],[49,50,53,56,83,95,113,124],[49,55],[53,57,83,116,124,132],[83,132],[73,83,132],[51,52,132],[57],[51,52,53,54,55,56,57,58,59,61,62,63,64,65,66,67,68,69,70,71,72,74,75,76,77,78,79],[57,64,65],[55,57,65,66],[56],[49,52,57],[57,61,65,66],[61],[55,57,60,124],[49,54,55,57,61,64],[83,113],[52,57,73,83,129,132],[44],[44,136,138,139,140],[44,45,135],[44,45,135,137],[44,45,135,137,138],[44,143],[44,45,137,142],[44,45,141,144]],"referencedMap":[[149,1],[154,2],[135,3],[46,4],[47,4],[82,5],[83,6],[84,7],[85,8],[86,9],[87,10],[88,11],[89,12],[90,13],[91,14],[92,14],[94,15],[93,16],[95,17],[96,18],[97,19],[81,20],[98,21],[99,22],[100,23],[132,24],[101,25],[102,26],[103,27],[104,28],[105,29],[106,30],[107,31],[108,32],[109,33],[110,34],[111,34],[112,35],[113,36],[115,37],[114,38],[116,39],[117,40],[118,41],[119,42],[120,43],[121,44],[122,45],[123,46],[124,47],[125,48],[126,49],[127,50],[128,51],[129,52],[130,53],[153,54],[133,55],[151,56],[152,57],[150,58],[64,59],[71,60],[63,59],[78,61],[55,62],[54,63],[77,64],[72,65],[75,66],[57,67],[56,68],[52,69],[51,70],[74,71],[53,72],[58,73],[62,73],[80,74],[79,73],[66,75],[67,76],[69,77],[65,78],[68,79],[73,64],[60,80],[61,81],[70,82],[50,83],[76,84],[45,85],[141,86],[140,87],[138,88],[136,87],[139,89],[144,90],[142,85],[143,91],[137,85],[145,92]],"exportedModulesMap":[[149,1],[154,2],[135,3],[46,4],[47,4],[82,5],[83,6],[84,7],[85,8],[86,9],[87,10],[88,11],[89,12],[90,13],[91,14],[92,14],[94,15],[93,16],[95,17],[96,18],[97,19],[81,20],[98,21],[99,22],[100,23],[132,24],[101,25],[102,26],[103,27],[104,28],[105,29],[106,30],[107,31],[108,32],[109,33],[110,34],[111,34],[112,35],[113,36],[115,37],[114,38],[116,39],[117,40],[118,41],[119,42],[120,43],[121,44],[122,45],[123,46],[124,47],[125,48],[126,49],[127,50],[128,51],[129,52],[130,53],[153,54],[133,55],[151,56],[152,57],[150,58],[64,59],[71,60],[63,59],[78,61],[55,62],[54,63],[77,64],[72,65],[75,66],[57,67],[56,68],[52,69],[51,70],[74,71],[53,72],[58,73],[62,73],[80,74],[79,73],[66,75],[67,76],[69,77],[65,78],[68,79],[73,64],[60,80],[61,81],[70,82],[50,83],[76,84],[45,85],[141,86],[140,87],[138,88],[136,87],[139,89],[144,90],[142,85],[143,91],[137,85],[145,92]],"semanticDiagnosticsPerFile":[146,149,148,154,134,135,46,47,82,83,84,85,86,87,88,89,90,91,92,94,93,95,96,97,81,131,98,99,100,132,101,102,103,104,105,106,107,108,109,110,111,112,113,115,114,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,48,147,153,133,151,152,8,9,11,10,2,12,13,14,15,16,17,18,19,3,4,23,20,21,22,24,25,26,5,27,28,29,30,6,34,31,32,33,35,7,36,41,42,37,38,39,40,1,43,150,44,64,71,63,78,55,54,77,72,75,57,56,52,51,74,53,58,59,62,49,80,79,66,67,69,65,68,73,60,61,70,50,76,45,141,140,138,136,139,144,142,143,137,145]},"version":"4.9.5"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# lock-service
|
|
2
|
+
|
|
3
|
+
Lock Service(https://github.com/hatiolab/operato-foundation-service) 서비스 연결 정보 설정
|
|
4
|
+
|
|
5
|
+
## 예시
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
module.exports = {
|
|
9
|
+
lock: {
|
|
10
|
+
/* Name to be used for setting client's "application" properties when trying a lock */
|
|
11
|
+
application: 'operato-lock',
|
|
12
|
+
/*
|
|
13
|
+
Lock service endpoint
|
|
14
|
+
caution) endpoint for "localhost" has some problem.
|
|
15
|
+
https://github.com/node-fetch/node-fetch/issues/1624
|
|
16
|
+
*/
|
|
17
|
+
endpoint: 'http://127.0.0.1:9902'
|
|
18
|
+
},
|
|
19
|
+
}
|
|
20
|
+
```
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"keep": {
|
|
3
|
+
"days": true,
|
|
4
|
+
"amount": 2
|
|
5
|
+
},
|
|
6
|
+
"auditLog": "logs/.08636eb59927f12972f6774f5947c8507b3564c2-audit.json",
|
|
7
|
+
"files": [
|
|
8
|
+
{
|
|
9
|
+
"date": 1709125953037,
|
|
10
|
+
"name": "logs/application-2024-02-28-22.log",
|
|
11
|
+
"hash": "6073bd0aad5c94c65e8423169d232549019b393b7d8d59c095cf3efb97777fa8"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"date": 1709129008763,
|
|
15
|
+
"name": "logs/application-2024-02-28-23.log",
|
|
16
|
+
"hash": "adc0056c45944c69923971071201490cfee929ea494af0746ebba5d1246408aa"
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"hashType": "sha256"
|
|
20
|
+
}
|
|
File without changes
|
|
File without changes
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@things-factory/lock-client",
|
|
3
|
+
"version": "7.0.0-alpha.18",
|
|
4
|
+
"main": "dist-server/index.js",
|
|
5
|
+
"things-factory": true,
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "heartyoh <heartyoh@hatiolab.com>",
|
|
8
|
+
"description": "lock client module",
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public",
|
|
11
|
+
"@things-factory:registry": "https://registry.npmjs.org"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/hatiolab/things-factory.git",
|
|
16
|
+
"directory": "packages/lock-client"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "npm run build:server",
|
|
20
|
+
"build:server": "npx tsc --p ./server/tsconfig.json",
|
|
21
|
+
"clean:server": "npx rimraf dist-server",
|
|
22
|
+
"clean": "npm run clean:server"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@things-factory/auth-base": "^7.0.0-alpha.18",
|
|
26
|
+
"@things-factory/env": "^7.0.0-alpha.0",
|
|
27
|
+
"@things-factory/shell": "^7.0.0-alpha.18"
|
|
28
|
+
},
|
|
29
|
+
"gitHead": "f695ce9c0e3a8f2d715d27a2e7674c9b9c6b1ee1"
|
|
30
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import fetch from 'node-fetch'
|
|
2
|
+
import { LockServiceEndpoint } from '../config'
|
|
3
|
+
|
|
4
|
+
export async function getLocks() {
|
|
5
|
+
const response = await fetch(LockServiceEndpoint + '/locks', {
|
|
6
|
+
method: 'get',
|
|
7
|
+
headers: {
|
|
8
|
+
accept: 'application/json',
|
|
9
|
+
'Content-Type': 'application/json'
|
|
10
|
+
}
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
return await response.json()
|
|
14
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import fetch from 'node-fetch'
|
|
2
|
+
import { LockServiceEndpoint } from '../config'
|
|
3
|
+
import { LockRequest } from '../types'
|
|
4
|
+
|
|
5
|
+
export async function releaseLock(request: LockRequest) {
|
|
6
|
+
var body = JSON.stringify(request)
|
|
7
|
+
const response = await fetch(LockServiceEndpoint + '/locking/release', {
|
|
8
|
+
method: 'post',
|
|
9
|
+
headers: {
|
|
10
|
+
accept: 'application/json',
|
|
11
|
+
'Content-Type': 'application/json'
|
|
12
|
+
},
|
|
13
|
+
body
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
var result
|
|
17
|
+
if (response.ok) {
|
|
18
|
+
result = await response.json()
|
|
19
|
+
} else if (response.status === 404) {
|
|
20
|
+
result = { error: 'Item not found' }
|
|
21
|
+
} else {
|
|
22
|
+
result = { error: await response.text() }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return result
|
|
26
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import fetch from 'node-fetch'
|
|
2
|
+
|
|
3
|
+
import { LockServiceEndpoint } from '../config'
|
|
4
|
+
|
|
5
|
+
export async function requestLock() {
|
|
6
|
+
const response = await fetch(LockServiceEndpoint + '/locking', {
|
|
7
|
+
method: 'POST',
|
|
8
|
+
headers: {
|
|
9
|
+
accept: 'application/json',
|
|
10
|
+
'Content-Type': 'application/json'
|
|
11
|
+
},
|
|
12
|
+
body: ''
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
const { id } = await response.json()
|
|
16
|
+
return id
|
|
17
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import fetch, { AbortError } from 'node-fetch'
|
|
2
|
+
|
|
3
|
+
import { LockServiceEndpoint } from '../config'
|
|
4
|
+
import { LockRequest } from '../types'
|
|
5
|
+
import { releaseLock } from './release-lock'
|
|
6
|
+
|
|
7
|
+
export async function tryLock(request: LockRequest, maxTimeout: number = 3000) {
|
|
8
|
+
var body = JSON.stringify(request)
|
|
9
|
+
|
|
10
|
+
const controller = new AbortController()
|
|
11
|
+
const timeout = setTimeout(() => {
|
|
12
|
+
controller.abort()
|
|
13
|
+
}, maxTimeout)
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
const response = await fetch(LockServiceEndpoint + '/locking/try', {
|
|
17
|
+
method: 'POST',
|
|
18
|
+
headers: {
|
|
19
|
+
accept: 'application/json',
|
|
20
|
+
'Content-Type': 'application/json'
|
|
21
|
+
},
|
|
22
|
+
body,
|
|
23
|
+
signal: controller.signal
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
return await response.json()
|
|
27
|
+
} catch (e) {
|
|
28
|
+
if (e instanceof AbortError) {
|
|
29
|
+
await releaseLock(request)
|
|
30
|
+
return {
|
|
31
|
+
payload: { error: 'timeout' }
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
} finally {
|
|
35
|
+
clearTimeout(timeout)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './locks'
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export class Lock {
|
|
2
|
+
private resolver: (value: unknown) => any
|
|
3
|
+
private timeout: any
|
|
4
|
+
|
|
5
|
+
acquire(timeout: number) {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
if (!this.resolver) {
|
|
8
|
+
this.resolver = resolve
|
|
9
|
+
this.timeout = setTimeout(() => {
|
|
10
|
+
reject('timeout')
|
|
11
|
+
}, timeout)
|
|
12
|
+
}
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
release(result) {
|
|
17
|
+
if (this.resolver) {
|
|
18
|
+
clearTimeout(this.timeout)
|
|
19
|
+
const resolve = this.resolver
|
|
20
|
+
this.resolver = null
|
|
21
|
+
resolve(result)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Lock } from './lock'
|
|
2
|
+
import { LockServiceEndpoint } from '../config'
|
|
3
|
+
import { LockRequest } from '../types'
|
|
4
|
+
|
|
5
|
+
const locks: {
|
|
6
|
+
[id: string]: {
|
|
7
|
+
lock: Lock
|
|
8
|
+
payload: any
|
|
9
|
+
}
|
|
10
|
+
} = {}
|
|
11
|
+
|
|
12
|
+
var id = 1
|
|
13
|
+
|
|
14
|
+
export async function getLocks() {
|
|
15
|
+
return this.locks
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function requestLock() {
|
|
19
|
+
return String(id++)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function tryLock(request: LockRequest, maxTimeout: number = 30000) {
|
|
23
|
+
const { id, payload } = request
|
|
24
|
+
|
|
25
|
+
if (locks[id]) {
|
|
26
|
+
throw `Lock [id:${id}] is already taken.`
|
|
27
|
+
}
|
|
28
|
+
const lock = new Lock()
|
|
29
|
+
|
|
30
|
+
locks[id] = {
|
|
31
|
+
lock,
|
|
32
|
+
payload
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
return await lock.acquire(maxTimeout)
|
|
37
|
+
} catch (e) {
|
|
38
|
+
throw e
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function releaseLock(request: LockRequest) {
|
|
43
|
+
const { id, payload } = request
|
|
44
|
+
const lock = locks[id]
|
|
45
|
+
|
|
46
|
+
if (!lock) {
|
|
47
|
+
throw `Lock [id:${id}] is not found.`
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
delete locks[id]
|
|
51
|
+
|
|
52
|
+
lock.lock.release(payload)
|
|
53
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type LockRequest = {
|
|
2
|
+
id?: string
|
|
3
|
+
payload?: any
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface LockClient {
|
|
7
|
+
getLocks: (name: string, group: string, dlq: boolean) => Promise<any>
|
|
8
|
+
requestLock: () => Promise<any>
|
|
9
|
+
tryLock: (request: LockRequest, maxTimeout?: number) => Promise<any>
|
|
10
|
+
releaseLock: (request: LockRequest) => void
|
|
11
|
+
}
|
package/server/index.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { LockServiceEndpoint } from './controllers/config'
|
|
2
|
+
|
|
3
|
+
import { getLocks as remoteGetLocks, requestLock as remoteRequestLock, tryLock as remoteTryLock, releaseLock as remoteReleaseLock } from './controllers/lock-api'
|
|
4
|
+
import { getLocks as localGetLocks, requestLock as localRequestLock, tryLock as localTryLock, releaseLock as localReleaseLock } from './controllers/lock-service-local'
|
|
5
|
+
|
|
6
|
+
const useLocalLock = LockServiceEndpoint == 'internal'
|
|
7
|
+
|
|
8
|
+
export const getLocks = useLocalLock ? localGetLocks : remoteGetLocks
|
|
9
|
+
export const requestLock = useLocalLock ? localRequestLock : remoteRequestLock
|
|
10
|
+
export const tryLock = useLocalLock ? localTryLock : remoteTryLock
|
|
11
|
+
export const releaseLock = useLocalLock ? localReleaseLock : remoteReleaseLock
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const { tryLock, releaseLock, requestLock } = require('../dist-server/controllers/lock-service-local')
|
|
2
|
+
|
|
3
|
+
describe('Local Locking Service', () => {
|
|
4
|
+
describe('requestLock', () => {
|
|
5
|
+
it('should return 1, 2, 3, 4, ..', async () => {
|
|
6
|
+
const ids = await Promise.all(Array.from({ length: 4 }, (_, index) => requestLock()))
|
|
7
|
+
|
|
8
|
+
expect(ids.length).toBe(4)
|
|
9
|
+
expect(ids[2]).toBe('3')
|
|
10
|
+
})
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
describe('tryLock', () => {
|
|
14
|
+
it('should throw timeout error if there is no releaseLock for given duration', async () => {
|
|
15
|
+
const id = await requestLock()
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
var result = await tryLock({ id }, 1000)
|
|
19
|
+
} catch (e) {
|
|
20
|
+
expect(e).toBe('timeout')
|
|
21
|
+
return
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
expect(true).toBe(false) // failed
|
|
25
|
+
})
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
describe('tryLock', () => {
|
|
29
|
+
it('should return the payload provided by releaseLock', async () => {
|
|
30
|
+
const id = await requestLock()
|
|
31
|
+
|
|
32
|
+
setTimeout(async () => {
|
|
33
|
+
await releaseLock({ id, payload: 'result' })
|
|
34
|
+
}, 1000)
|
|
35
|
+
var result = await tryLock({ id }, 2000)
|
|
36
|
+
|
|
37
|
+
expect(result).toBe('result')
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
})
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const { tryLock, releaseLock, requestLock } = require('../dist-server/controllers/lock-api')
|
|
2
|
+
|
|
3
|
+
describe('Locking Service', () => {
|
|
4
|
+
describe('request and release', () => {
|
|
5
|
+
it('should return unique id', async () => {
|
|
6
|
+
const id1 = await requestLock()
|
|
7
|
+
const id2 = await requestLock()
|
|
8
|
+
expect(id1).not.toBe(id2)
|
|
9
|
+
|
|
10
|
+
await releaseLock({ id: id1 })
|
|
11
|
+
await releaseLock({ id: id2 })
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('invalid id should return error', async () => {
|
|
15
|
+
const response = await releaseLock({ id: 'invalid-id' })
|
|
16
|
+
expect(response).toEqual({ error: 'Item not found' })
|
|
17
|
+
})
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
describe('requestLock, tryLock and releaseLock', () => {
|
|
21
|
+
it('normal flow of locking service', async () => {
|
|
22
|
+
const id = await requestLock()
|
|
23
|
+
|
|
24
|
+
setTimeout(async () => {
|
|
25
|
+
await releaseLock({
|
|
26
|
+
id,
|
|
27
|
+
payload: {
|
|
28
|
+
result: 'test1'
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
}, 1000)
|
|
32
|
+
|
|
33
|
+
const { payload } = await tryLock({ id }, 30000)
|
|
34
|
+
|
|
35
|
+
expect(payload).toEqual({
|
|
36
|
+
result: 'test1'
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('should return timeout error', async () => {
|
|
41
|
+
const id = await requestLock()
|
|
42
|
+
|
|
43
|
+
setTimeout(async () => {
|
|
44
|
+
await releaseLock({
|
|
45
|
+
id,
|
|
46
|
+
payload: {
|
|
47
|
+
result: 'test2'
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
}, 1000)
|
|
51
|
+
|
|
52
|
+
const { payload } = await tryLock({ id }, 500)
|
|
53
|
+
|
|
54
|
+
expect(payload).toEqual({
|
|
55
|
+
error: 'timeout'
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|