@allgemein/base 1.6.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/Constants.d.ts +11 -0
- package/Constants.js +15 -0
- package/Constants.js.map +1 -0
- package/LICENSE +23 -0
- package/MetaArgs.d.ts +9 -0
- package/MetaArgs.js +21 -0
- package/MetaArgs.js.map +1 -0
- package/MetadataStorage.d.ts +17 -0
- package/MetadataStorage.js +47 -0
- package/MetadataStorage.js.map +1 -0
- package/README.md +6 -0
- package/browser.d.ts +2 -0
- package/browser.js +32 -0
- package/browser.js.map +1 -0
- package/exceptions/NestedException.d.ts +11 -0
- package/exceptions/NestedException.js +31 -0
- package/exceptions/NestedException.js.map +1 -0
- package/exceptions/NotSupportedError.d.ts +3 -0
- package/exceptions/NotSupportedError.js +11 -0
- package/exceptions/NotSupportedError.js.map +1 -0
- package/exceptions/NotYetImplementedError.d.ts +3 -0
- package/exceptions/NotYetImplementedError.js +11 -0
- package/exceptions/NotYetImplementedError.js.map +1 -0
- package/exceptions/TodoException.d.ts +3 -0
- package/exceptions/TodoException.js +11 -0
- package/exceptions/TodoException.js.map +1 -0
- package/index.d.ts +4 -0
- package/index.js +36 -0
- package/index.js.map +1 -0
- package/locking/LockFactory.d.ts +15 -0
- package/locking/LockFactory.js +60 -0
- package/locking/LockFactory.js.map +1 -0
- package/locking/Semaphore.d.ts +45 -0
- package/locking/Semaphore.js +108 -0
- package/locking/Semaphore.js.map +1 -0
- package/logging/AbstractLogger.d.ts +24 -0
- package/logging/AbstractLogger.js +73 -0
- package/logging/AbstractLogger.js.map +1 -0
- package/logging/ConsoleLogger.d.ts +4 -0
- package/logging/ConsoleLogger.js +31 -0
- package/logging/ConsoleLogger.js.map +1 -0
- package/logging/ILogLevel.d.ts +4 -0
- package/logging/ILogLevel.js +4 -0
- package/logging/ILogLevel.js.map +1 -0
- package/logging/ILoggerApi.d.ts +12 -0
- package/logging/ILoggerApi.js +4 -0
- package/logging/ILoggerApi.js.map +1 -0
- package/logging/ILoggerOptions.d.ts +7 -0
- package/logging/ILoggerOptions.js +4 -0
- package/logging/ILoggerOptions.js.map +1 -0
- package/logging/Logger.d.ts +23 -0
- package/logging/Logger.js +66 -0
- package/logging/Logger.js.map +1 -0
- package/package.json +63 -0
- package/shared.d.ts +20 -0
- package/shared.js +47 -0
- package/shared.js.map +1 -0
- package/utils/ClassLoader.d.ts +28 -0
- package/utils/ClassLoader.js +183 -0
- package/utils/ClassLoader.js.map +1 -0
- package/utils/ClassUtils.d.ts +5 -0
- package/utils/ClassUtils.js +50 -0
- package/utils/ClassUtils.js.map +1 -0
- package/utils/CryptUtils.d.ts +10 -0
- package/utils/CryptUtils.js +64 -0
- package/utils/CryptUtils.js.map +1 -0
- package/utils/FileUtils.d.ts +14 -0
- package/utils/FileUtils.js +99 -0
- package/utils/FileUtils.js.map +1 -0
- package/utils/JsonUtils.d.ts +5 -0
- package/utils/JsonUtils.js +35 -0
- package/utils/JsonUtils.js.map +1 -0
- package/utils/PlatformUtils.d.ts +97 -0
- package/utils/PlatformUtils.js +288 -0
- package/utils/PlatformUtils.js.map +1 -0
- package/utils/PlatformUtilsBrowser.d.ts +86 -0
- package/utils/PlatformUtilsBrowser.js +177 -0
- package/utils/PlatformUtilsBrowser.js.map +1 -0
- package/utils/Serializer.d.ts +9 -0
- package/utils/Serializer.js +84 -0
- package/utils/Serializer.js.map +1 -0
- package/utils/TreeUtils.d.ts +12 -0
- package/utils/TreeUtils.js +110 -0
- package/utils/TreeUtils.js.map +1 -0
package/Constants.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare type StringOrFunction = string | Function;
|
|
2
|
+
export declare const __SOURCE__ = "__SOURCE__";
|
|
3
|
+
export declare const __CLASS__ = "__CLASS__";
|
|
4
|
+
export declare const C_DEFAULT = "default";
|
|
5
|
+
export declare const C_CONSOLE = "console";
|
|
6
|
+
export declare const C_WARN = "warn";
|
|
7
|
+
export declare const C_ERROR = "error";
|
|
8
|
+
export declare const C_DEBUG = "debug";
|
|
9
|
+
export declare const C_TRACE = "trace";
|
|
10
|
+
export declare const C_INFO = "info";
|
|
11
|
+
export declare const ISO8601: RegExp;
|
package/Constants.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ISO8601 = exports.C_INFO = exports.C_TRACE = exports.C_DEBUG = exports.C_ERROR = exports.C_WARN = exports.C_CONSOLE = exports.C_DEFAULT = exports.__CLASS__ = exports.__SOURCE__ = void 0;
|
|
4
|
+
exports.__SOURCE__ = '__SOURCE__';
|
|
5
|
+
exports.__CLASS__ = '__CLASS__';
|
|
6
|
+
exports.C_DEFAULT = 'default';
|
|
7
|
+
exports.C_CONSOLE = 'console';
|
|
8
|
+
exports.C_WARN = 'warn';
|
|
9
|
+
exports.C_ERROR = 'error';
|
|
10
|
+
exports.C_DEBUG = 'debug';
|
|
11
|
+
exports.C_TRACE = 'trace';
|
|
12
|
+
exports.C_INFO = 'info';
|
|
13
|
+
exports.ISO8601 = /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(\.\d+)?(([+-]\d\d:\d\d)|Z)?$/i;
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=Constants.js.map
|
package/Constants.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/Constants.ts"],"names":[],"mappings":";;;AAEa,QAAA,UAAU,GAAG,YAAY,CAAC;AAC1B,QAAA,SAAS,GAAG,WAAW,CAAC;AAGxB,QAAA,SAAS,GAAG,SAAS,CAAC;AACtB,QAAA,SAAS,GAAG,SAAS,CAAC;AAEtB,QAAA,MAAM,GAAG,MAAM,CAAC;AAChB,QAAA,OAAO,GAAG,OAAO,CAAC;AAClB,QAAA,OAAO,GAAG,OAAO,CAAC;AAClB,QAAA,OAAO,GAAG,OAAO,CAAC;AAClB,QAAA,MAAM,GAAG,MAAM,CAAC;AAGhB,QAAA,OAAO,GAAG,+DAA+D,CAAC","file":"Constants.js","sourcesContent":["export type StringOrFunction = string | Function;\n\nexport const __SOURCE__ = '__SOURCE__';\nexport const __CLASS__ = '__CLASS__';\n\n\nexport const C_DEFAULT = 'default';\nexport const C_CONSOLE = 'console';\n\nexport const C_WARN = 'warn';\nexport const C_ERROR = 'error';\nexport const C_DEBUG = 'debug';\nexport const C_TRACE = 'trace';\nexport const C_INFO = 'info';\n\n\nexport const ISO8601 = /^\\d{4}-\\d\\d-\\d\\dT\\d\\d:\\d\\d:\\d\\d(\\.\\d+)?(([+-]\\d\\d:\\d\\d)|Z)?$/i;\n\n\n"],"sourceRoot":"."}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Robert Kania
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person
|
|
6
|
+
obtaining a copy of this software and associated documentation
|
|
7
|
+
files (the "Software"), to deal in the Software without
|
|
8
|
+
restriction, including without limitation the rights to use,
|
|
9
|
+
copy, modify, merge, publish, distribute, sublicense, and/or
|
|
10
|
+
sell copies of the Software, and to permit persons to whom the
|
|
11
|
+
Software is furnished to do so, subject to the following
|
|
12
|
+
conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be
|
|
15
|
+
included in all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
20
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
21
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
22
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
23
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/MetaArgs.d.ts
ADDED
package/MetaArgs.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MetaArgs = void 0;
|
|
4
|
+
const MetadataStorage_1 = require("./MetadataStorage");
|
|
5
|
+
/**
|
|
6
|
+
* Replaced in future by MetadataStorage
|
|
7
|
+
*/
|
|
8
|
+
class MetaArgs {
|
|
9
|
+
static $() {
|
|
10
|
+
return MetadataStorage_1.MetadataStorage.$();
|
|
11
|
+
}
|
|
12
|
+
static key(k) {
|
|
13
|
+
return this.$().key(k);
|
|
14
|
+
}
|
|
15
|
+
static clear() {
|
|
16
|
+
return MetadataStorage_1.MetadataStorage.clear();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.MetaArgs = MetaArgs;
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=MetaArgs.js.map
|
package/MetaArgs.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/MetaArgs.ts"],"names":[],"mappings":";;;AAAA,uDAAkD;AAElD;;GAEG;AACH,MAAa,QAAQ;IAGnB,MAAM,CAAC,CAAC;QACN,OAAO,iCAAe,CAAC,CAAC,EAAE,CAAC;IAC7B,CAAC;IAGD,MAAM,CAAC,GAAG,CAAC,CAAS;QAClB,OAAO,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC;IAGD,MAAM,CAAC,KAAK;QACV,OAAO,iCAAe,CAAC,KAAK,EAAE,CAAC;IACjC,CAAC;CAGF;AAlBD,4BAkBC","file":"MetaArgs.js","sourcesContent":["import {MetadataStorage} from './MetadataStorage';\n\n/**\n * Replaced in future by MetadataStorage\n */\nexport class MetaArgs {\n\n\n static $(): MetadataStorage {\n return MetadataStorage.$();\n }\n\n\n static key(k: string): any[] {\n return this.$().key(k);\n }\n\n\n static clear() {\n return MetadataStorage.clear();\n }\n\n\n}\n"],"sourceRoot":"."}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare class MetadataStorage {
|
|
2
|
+
[k: string]: any;
|
|
3
|
+
static $self: MetadataStorage;
|
|
4
|
+
static $(): MetadataStorage;
|
|
5
|
+
static key(k: string): any[];
|
|
6
|
+
static clear(): void;
|
|
7
|
+
/**
|
|
8
|
+
* Create or get a cached key by object / array
|
|
9
|
+
*
|
|
10
|
+
* @param key
|
|
11
|
+
* @param initial
|
|
12
|
+
*/
|
|
13
|
+
key(key: string, initial?: any): any[];
|
|
14
|
+
has(path: string): boolean;
|
|
15
|
+
get(key: string): any;
|
|
16
|
+
remove(key: string): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MetadataStorage = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
class MetadataStorage {
|
|
6
|
+
static $() {
|
|
7
|
+
if (!this.$self) {
|
|
8
|
+
this.$self = new MetadataStorage();
|
|
9
|
+
}
|
|
10
|
+
return this.$self;
|
|
11
|
+
}
|
|
12
|
+
static key(k) {
|
|
13
|
+
return this.$().key(k);
|
|
14
|
+
}
|
|
15
|
+
static clear() {
|
|
16
|
+
this.$self = null;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Create or get a cached key by object / array
|
|
20
|
+
*
|
|
21
|
+
* @param key
|
|
22
|
+
* @param initial
|
|
23
|
+
*/
|
|
24
|
+
key(key, initial = []) {
|
|
25
|
+
if (!lodash_1.has(this, key)) {
|
|
26
|
+
this[key] = initial;
|
|
27
|
+
}
|
|
28
|
+
return this[key];
|
|
29
|
+
}
|
|
30
|
+
has(path) {
|
|
31
|
+
return lodash_1.has(this, path);
|
|
32
|
+
}
|
|
33
|
+
get(key) {
|
|
34
|
+
if (lodash_1.has(this, key)) {
|
|
35
|
+
return this[key];
|
|
36
|
+
}
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
remove(key) {
|
|
40
|
+
if (lodash_1.has(this, key)) {
|
|
41
|
+
delete this[key];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.MetadataStorage = MetadataStorage;
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=MetadataStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/MetadataStorage.ts"],"names":[],"mappings":";;;AAAA,mCAA2B;AAG3B,MAAa,eAAe;IAS1B,MAAM,CAAC,CAAC;QACN,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;YACf,IAAI,CAAC,KAAK,GAAG,IAAI,eAAe,EAAE,CAAC;SACpC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAGD,MAAM,CAAC,GAAG,CAAC,CAAS;QAClB,OAAO,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC;IAGD,MAAM,CAAC,KAAK;QACV,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,GAAW,EAAE,UAAe,EAAE;QAChC,IAAI,CAAC,YAAG,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE;YACnB,IAAI,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC;SACrB;QACD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;IAGD,GAAG,CAAC,IAAY;QACd,OAAO,YAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACzB,CAAC;IAGD,GAAG,CAAC,GAAW;QACb,IAAI,YAAG,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE;YAClB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;SAClB;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAGD,MAAM,CAAC,GAAW;QAChB,IAAI,YAAG,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE;YAClB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;SAClB;IACH,CAAC;CAEF;AA3DD,0CA2DC","file":"MetadataStorage.js","sourcesContent":["import {has} from 'lodash';\n\n\nexport class MetadataStorage {\n\n\n [k: string]: any;\n\n\n static $self: MetadataStorage;\n\n\n static $() {\n if (!this.$self) {\n this.$self = new MetadataStorage();\n }\n return this.$self;\n }\n\n\n static key(k: string): any[] {\n return this.$().key(k);\n }\n\n\n static clear() {\n this.$self = null;\n }\n\n /**\n * Create or get a cached key by object / array\n *\n * @param key\n * @param initial\n */\n key(key: string, initial: any = []): any[] {\n if (!has(this, key)) {\n this[key] = initial;\n }\n return this[key];\n }\n\n\n has(path: string) {\n return has(this, path);\n }\n\n\n get(key: string) {\n if (has(this, key)) {\n return this[key];\n }\n return undefined;\n }\n\n\n remove(key: string) {\n if (has(this, key)) {\n delete this[key];\n }\n }\n\n}\n"],"sourceRoot":"."}
|
package/README.md
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
|
|
2
|
+
# @allgemein/base
|
|
3
|
+
|
|
4
|
+
[](https://travis-ci.org/allgemein-node/base)
|
|
5
|
+
[](https://codecov.io/gh/allgemein-node/base)
|
|
6
|
+
[](https://david-dm.org/allgemein-node/base)
|
package/browser.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { JsonUtils, TreeUtils, CryptUtils, ClassUtils, NotSupportedError, NotYetImplementedError, TodoException, NestedException, Logger, ILogLevel, ILoggerOptions, ILoggerApi, ConsoleLogger, AbstractLogger, MetaArgs, StringOrFunction, ISO8601, C_WARN, C_TRACE, C_INFO, C_ERROR, C_DEBUG, C_CONSOLE, __SOURCE__, C_DEFAULT, MetadataStorage, Semaphore, LockFactory } from './shared';
|
|
2
|
+
export { PlatformUtils } from './utils/PlatformUtilsBrowser';
|
package/browser.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlatformUtils = exports.LockFactory = exports.Semaphore = exports.MetadataStorage = exports.C_DEFAULT = exports.__SOURCE__ = exports.C_CONSOLE = exports.C_DEBUG = exports.C_ERROR = exports.C_INFO = exports.C_TRACE = exports.C_WARN = exports.ISO8601 = exports.MetaArgs = exports.AbstractLogger = exports.ConsoleLogger = exports.Logger = exports.NestedException = exports.TodoException = exports.NotYetImplementedError = exports.NotSupportedError = exports.ClassUtils = exports.CryptUtils = exports.TreeUtils = exports.JsonUtils = void 0;
|
|
4
|
+
var shared_1 = require("./shared");
|
|
5
|
+
Object.defineProperty(exports, "JsonUtils", { enumerable: true, get: function () { return shared_1.JsonUtils; } });
|
|
6
|
+
Object.defineProperty(exports, "TreeUtils", { enumerable: true, get: function () { return shared_1.TreeUtils; } });
|
|
7
|
+
Object.defineProperty(exports, "CryptUtils", { enumerable: true, get: function () { return shared_1.CryptUtils; } });
|
|
8
|
+
Object.defineProperty(exports, "ClassUtils", { enumerable: true, get: function () { return shared_1.ClassUtils; } });
|
|
9
|
+
Object.defineProperty(exports, "NotSupportedError", { enumerable: true, get: function () { return shared_1.NotSupportedError; } });
|
|
10
|
+
Object.defineProperty(exports, "NotYetImplementedError", { enumerable: true, get: function () { return shared_1.NotYetImplementedError; } });
|
|
11
|
+
Object.defineProperty(exports, "TodoException", { enumerable: true, get: function () { return shared_1.TodoException; } });
|
|
12
|
+
Object.defineProperty(exports, "NestedException", { enumerable: true, get: function () { return shared_1.NestedException; } });
|
|
13
|
+
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return shared_1.Logger; } });
|
|
14
|
+
Object.defineProperty(exports, "ConsoleLogger", { enumerable: true, get: function () { return shared_1.ConsoleLogger; } });
|
|
15
|
+
Object.defineProperty(exports, "AbstractLogger", { enumerable: true, get: function () { return shared_1.AbstractLogger; } });
|
|
16
|
+
Object.defineProperty(exports, "MetaArgs", { enumerable: true, get: function () { return shared_1.MetaArgs; } });
|
|
17
|
+
Object.defineProperty(exports, "ISO8601", { enumerable: true, get: function () { return shared_1.ISO8601; } });
|
|
18
|
+
Object.defineProperty(exports, "C_WARN", { enumerable: true, get: function () { return shared_1.C_WARN; } });
|
|
19
|
+
Object.defineProperty(exports, "C_TRACE", { enumerable: true, get: function () { return shared_1.C_TRACE; } });
|
|
20
|
+
Object.defineProperty(exports, "C_INFO", { enumerable: true, get: function () { return shared_1.C_INFO; } });
|
|
21
|
+
Object.defineProperty(exports, "C_ERROR", { enumerable: true, get: function () { return shared_1.C_ERROR; } });
|
|
22
|
+
Object.defineProperty(exports, "C_DEBUG", { enumerable: true, get: function () { return shared_1.C_DEBUG; } });
|
|
23
|
+
Object.defineProperty(exports, "C_CONSOLE", { enumerable: true, get: function () { return shared_1.C_CONSOLE; } });
|
|
24
|
+
Object.defineProperty(exports, "__SOURCE__", { enumerable: true, get: function () { return shared_1.__SOURCE__; } });
|
|
25
|
+
Object.defineProperty(exports, "C_DEFAULT", { enumerable: true, get: function () { return shared_1.C_DEFAULT; } });
|
|
26
|
+
Object.defineProperty(exports, "MetadataStorage", { enumerable: true, get: function () { return shared_1.MetadataStorage; } });
|
|
27
|
+
Object.defineProperty(exports, "Semaphore", { enumerable: true, get: function () { return shared_1.Semaphore; } });
|
|
28
|
+
Object.defineProperty(exports, "LockFactory", { enumerable: true, get: function () { return shared_1.LockFactory; } });
|
|
29
|
+
var PlatformUtilsBrowser_1 = require("./utils/PlatformUtilsBrowser");
|
|
30
|
+
Object.defineProperty(exports, "PlatformUtils", { enumerable: true, get: function () { return PlatformUtilsBrowser_1.PlatformUtils; } });
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=browser.js.map
|
package/browser.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/browser.ts"],"names":[],"mappings":";;;AAAA,mCA6BkB;AA5BhB,mGAAA,SAAS,OAAA;AACT,mGAAA,SAAS,OAAA;AACT,oGAAA,UAAU,OAAA;AACV,oGAAA,UAAU,OAAA;AACV,2GAAA,iBAAiB,OAAA;AACjB,gHAAA,sBAAsB,OAAA;AACtB,uGAAA,aAAa,OAAA;AACb,yGAAA,eAAe,OAAA;AACf,gGAAA,MAAM,OAAA;AAIN,uGAAA,aAAa,OAAA;AACb,wGAAA,cAAc,OAAA;AACd,kGAAA,QAAQ,OAAA;AAER,iGAAA,OAAO,OAAA;AACP,gGAAA,MAAM,OAAA;AACN,iGAAA,OAAO,OAAA;AACP,gGAAA,MAAM,OAAA;AACN,iGAAA,OAAO,OAAA;AACP,iGAAA,OAAO,OAAA;AACP,mGAAA,SAAS,OAAA;AACT,oGAAA,UAAU,OAAA;AACV,mGAAA,SAAS,OAAA;AACT,yGAAA,eAAe,OAAA;AACf,mGAAA,SAAS,OAAA;AACT,qGAAA,WAAW,OAAA;AAEb,qEAA2D;AAAnD,qHAAA,aAAa,OAAA","file":"browser.js","sourcesContent":["export {\n JsonUtils,\n TreeUtils,\n CryptUtils,\n ClassUtils,\n NotSupportedError,\n NotYetImplementedError,\n TodoException,\n NestedException,\n Logger,\n ILogLevel,\n ILoggerOptions,\n ILoggerApi,\n ConsoleLogger,\n AbstractLogger,\n MetaArgs,\n StringOrFunction,\n ISO8601,\n C_WARN,\n C_TRACE,\n C_INFO,\n C_ERROR,\n C_DEBUG,\n C_CONSOLE,\n __SOURCE__,\n C_DEFAULT,\n MetadataStorage,\n Semaphore,\n LockFactory\n} from './shared';\nexport {PlatformUtils} from './utils/PlatformUtilsBrowser';\n"],"sourceRoot":"."}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class NestedException extends Error {
|
|
2
|
+
private _code;
|
|
3
|
+
private _error;
|
|
4
|
+
constructor(err: Error, code: string);
|
|
5
|
+
get stack(): string;
|
|
6
|
+
get code(): string;
|
|
7
|
+
get name(): string;
|
|
8
|
+
get message(): string;
|
|
9
|
+
get error(): Error;
|
|
10
|
+
toString(): string;
|
|
11
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NestedException = void 0;
|
|
4
|
+
class NestedException extends Error {
|
|
5
|
+
constructor(err, code) {
|
|
6
|
+
super();
|
|
7
|
+
this._error = err;
|
|
8
|
+
this._code = code;
|
|
9
|
+
}
|
|
10
|
+
get stack() {
|
|
11
|
+
return this.error.stack;
|
|
12
|
+
}
|
|
13
|
+
get code() {
|
|
14
|
+
return this._code;
|
|
15
|
+
}
|
|
16
|
+
get name() {
|
|
17
|
+
return this.error.name;
|
|
18
|
+
}
|
|
19
|
+
get message() {
|
|
20
|
+
return this.error.message;
|
|
21
|
+
}
|
|
22
|
+
get error() {
|
|
23
|
+
return this._error;
|
|
24
|
+
}
|
|
25
|
+
toString() {
|
|
26
|
+
return [this.name, this.message].join(': ');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.NestedException = NestedException;
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=NestedException.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/exceptions/NestedException.ts"],"names":[],"mappings":";;;AAEA,MAAa,eAAgB,SAAQ,KAAK;IAMtC,YAAY,GAAU,EAAE,IAAW;QAC/B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC;QAClB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;IACrB,CAAC;IAED,IAAI,KAAK;QACL,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAA;IAC3B,CAAC;IAED,IAAI,IAAI;QACJ,OAAO,IAAI,CAAC,KAAK,CAAA;IACrB,CAAC;IAED,IAAI,IAAI;QACJ,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAA;IAC1B,CAAC;IAED,IAAI,OAAO;QACP,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAA;IAC7B,CAAC;IAED,IAAI,KAAK;QACL,OAAO,IAAI,CAAC,MAAM,CAAA;IACtB,CAAC;IAED,QAAQ;QACJ,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC/C,CAAC;CAEJ;AApCD,0CAoCC","file":"NestedException.js","sourcesContent":["\n\nexport class NestedException extends Error {\n\n private _code : string;\n\n private _error : Error;\n\n constructor(err: Error, code:string){\n super();\n this._error = err;\n this._code = code\n }\n\n get stack():string{\n return this.error.stack\n }\n\n get code():string{\n return this._code\n }\n\n get name():string{\n return this.error.name\n }\n\n get message():string{\n return this.error.message\n }\n\n get error():Error{\n return this._error\n }\n\n toString() :string{\n return [this.name, this.message].join(': ')\n }\n\n}"],"sourceRoot":".."}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotSupportedError = void 0;
|
|
4
|
+
class NotSupportedError extends Error {
|
|
5
|
+
constructor(msg) {
|
|
6
|
+
super(msg);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.NotSupportedError = NotSupportedError;
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=NotSupportedError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/exceptions/NotSupportedError.ts"],"names":[],"mappings":";;;AAEA,MAAa,iBAAkB,SAAQ,KAAK;IAE1C,YAAY,GAAU;QACpB,KAAK,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;CACF;AALD,8CAKC","file":"NotSupportedError.js","sourcesContent":["\n\nexport class NotSupportedError extends Error {\n\n constructor(msg:string){\n super(msg);\n }\n}\n"],"sourceRoot":".."}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotYetImplementedError = void 0;
|
|
4
|
+
class NotYetImplementedError extends Error {
|
|
5
|
+
constructor(msg = "please make an issue ...") {
|
|
6
|
+
super('Not yet implemented. Planned or forgotten ;) ' + msg);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.NotYetImplementedError = NotYetImplementedError;
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=NotYetImplementedError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/exceptions/NotYetImplementedError.ts"],"names":[],"mappings":";;;AAAA,MAAa,sBAAuB,SAAQ,KAAK;IAC/C,YAAY,MAAa,0BAA0B;QACjD,KAAK,CAAC,+CAA+C,GAAC,GAAG,CAAC,CAAC;IAC7D,CAAC;CACF;AAJD,wDAIC","file":"NotYetImplementedError.js","sourcesContent":["export class NotYetImplementedError extends Error {\n constructor(msg:string = \"please make an issue ...\") {\n super('Not yet implemented. Planned or forgotten ;) '+msg);\n }\n}\n"],"sourceRoot":".."}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TodoException = void 0;
|
|
4
|
+
class TodoException extends Error {
|
|
5
|
+
constructor(msg = 'TODO EXCEPTION') {
|
|
6
|
+
super(msg);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.TodoException = TodoException;
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=TodoException.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/exceptions/TodoException.ts"],"names":[],"mappings":";;;AACA,MAAa,aAAc,SAAQ,KAAK;IACpC,YAAY,MAAa,gBAAgB;QACrC,KAAK,CAAC,GAAG,CAAC,CAAA;IACd,CAAC;CACJ;AAJD,sCAIC","file":"TodoException.js","sourcesContent":["\nexport class TodoException extends Error {\n constructor(msg:string = 'TODO EXCEPTION'){\n super(msg)\n }\n}\n"],"sourceRoot":".."}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { JsonUtils, TreeUtils, CryptUtils, ClassUtils, NotSupportedError, NotYetImplementedError, TodoException, NestedException, Logger, ILogLevel, ILoggerOptions, ILoggerApi, ConsoleLogger, AbstractLogger, MetaArgs, StringOrFunction, ISO8601, C_WARN, C_TRACE, C_INFO, C_ERROR, C_DEBUG, C_CONSOLE, __SOURCE__, C_DEFAULT, MetadataStorage, LockFactory, Semaphore } from './shared';
|
|
2
|
+
export { ClassLoader } from './utils/ClassLoader';
|
|
3
|
+
export { PlatformUtils } from './utils/PlatformUtils';
|
|
4
|
+
export { FileUtils } from './utils/FileUtils';
|
package/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FileUtils = exports.PlatformUtils = exports.ClassLoader = exports.Semaphore = exports.LockFactory = exports.MetadataStorage = exports.C_DEFAULT = exports.__SOURCE__ = exports.C_CONSOLE = exports.C_DEBUG = exports.C_ERROR = exports.C_INFO = exports.C_TRACE = exports.C_WARN = exports.ISO8601 = exports.MetaArgs = exports.AbstractLogger = exports.ConsoleLogger = exports.Logger = exports.NestedException = exports.TodoException = exports.NotYetImplementedError = exports.NotSupportedError = exports.ClassUtils = exports.CryptUtils = exports.TreeUtils = exports.JsonUtils = void 0;
|
|
4
|
+
var shared_1 = require("./shared");
|
|
5
|
+
Object.defineProperty(exports, "JsonUtils", { enumerable: true, get: function () { return shared_1.JsonUtils; } });
|
|
6
|
+
Object.defineProperty(exports, "TreeUtils", { enumerable: true, get: function () { return shared_1.TreeUtils; } });
|
|
7
|
+
Object.defineProperty(exports, "CryptUtils", { enumerable: true, get: function () { return shared_1.CryptUtils; } });
|
|
8
|
+
Object.defineProperty(exports, "ClassUtils", { enumerable: true, get: function () { return shared_1.ClassUtils; } });
|
|
9
|
+
Object.defineProperty(exports, "NotSupportedError", { enumerable: true, get: function () { return shared_1.NotSupportedError; } });
|
|
10
|
+
Object.defineProperty(exports, "NotYetImplementedError", { enumerable: true, get: function () { return shared_1.NotYetImplementedError; } });
|
|
11
|
+
Object.defineProperty(exports, "TodoException", { enumerable: true, get: function () { return shared_1.TodoException; } });
|
|
12
|
+
Object.defineProperty(exports, "NestedException", { enumerable: true, get: function () { return shared_1.NestedException; } });
|
|
13
|
+
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return shared_1.Logger; } });
|
|
14
|
+
Object.defineProperty(exports, "ConsoleLogger", { enumerable: true, get: function () { return shared_1.ConsoleLogger; } });
|
|
15
|
+
Object.defineProperty(exports, "AbstractLogger", { enumerable: true, get: function () { return shared_1.AbstractLogger; } });
|
|
16
|
+
Object.defineProperty(exports, "MetaArgs", { enumerable: true, get: function () { return shared_1.MetaArgs; } });
|
|
17
|
+
Object.defineProperty(exports, "ISO8601", { enumerable: true, get: function () { return shared_1.ISO8601; } });
|
|
18
|
+
Object.defineProperty(exports, "C_WARN", { enumerable: true, get: function () { return shared_1.C_WARN; } });
|
|
19
|
+
Object.defineProperty(exports, "C_TRACE", { enumerable: true, get: function () { return shared_1.C_TRACE; } });
|
|
20
|
+
Object.defineProperty(exports, "C_INFO", { enumerable: true, get: function () { return shared_1.C_INFO; } });
|
|
21
|
+
Object.defineProperty(exports, "C_ERROR", { enumerable: true, get: function () { return shared_1.C_ERROR; } });
|
|
22
|
+
Object.defineProperty(exports, "C_DEBUG", { enumerable: true, get: function () { return shared_1.C_DEBUG; } });
|
|
23
|
+
Object.defineProperty(exports, "C_CONSOLE", { enumerable: true, get: function () { return shared_1.C_CONSOLE; } });
|
|
24
|
+
Object.defineProperty(exports, "__SOURCE__", { enumerable: true, get: function () { return shared_1.__SOURCE__; } });
|
|
25
|
+
Object.defineProperty(exports, "C_DEFAULT", { enumerable: true, get: function () { return shared_1.C_DEFAULT; } });
|
|
26
|
+
Object.defineProperty(exports, "MetadataStorage", { enumerable: true, get: function () { return shared_1.MetadataStorage; } });
|
|
27
|
+
Object.defineProperty(exports, "LockFactory", { enumerable: true, get: function () { return shared_1.LockFactory; } });
|
|
28
|
+
Object.defineProperty(exports, "Semaphore", { enumerable: true, get: function () { return shared_1.Semaphore; } });
|
|
29
|
+
var ClassLoader_1 = require("./utils/ClassLoader");
|
|
30
|
+
Object.defineProperty(exports, "ClassLoader", { enumerable: true, get: function () { return ClassLoader_1.ClassLoader; } });
|
|
31
|
+
var PlatformUtils_1 = require("./utils/PlatformUtils");
|
|
32
|
+
Object.defineProperty(exports, "PlatformUtils", { enumerable: true, get: function () { return PlatformUtils_1.PlatformUtils; } });
|
|
33
|
+
var FileUtils_1 = require("./utils/FileUtils");
|
|
34
|
+
Object.defineProperty(exports, "FileUtils", { enumerable: true, get: function () { return FileUtils_1.FileUtils; } });
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/index.ts"],"names":[],"mappings":";;;AAAA,mCA6BkB;AA5BhB,mGAAA,SAAS,OAAA;AACT,mGAAA,SAAS,OAAA;AACT,oGAAA,UAAU,OAAA;AACV,oGAAA,UAAU,OAAA;AACV,2GAAA,iBAAiB,OAAA;AACjB,gHAAA,sBAAsB,OAAA;AACtB,uGAAA,aAAa,OAAA;AACb,yGAAA,eAAe,OAAA;AACf,gGAAA,MAAM,OAAA;AAIN,uGAAA,aAAa,OAAA;AACb,wGAAA,cAAc,OAAA;AACd,kGAAA,QAAQ,OAAA;AAER,iGAAA,OAAO,OAAA;AACP,gGAAA,MAAM,OAAA;AACN,iGAAA,OAAO,OAAA;AACP,gGAAA,MAAM,OAAA;AACN,iGAAA,OAAO,OAAA;AACP,iGAAA,OAAO,OAAA;AACP,mGAAA,SAAS,OAAA;AACT,oGAAA,UAAU,OAAA;AACV,mGAAA,SAAS,OAAA;AACT,yGAAA,eAAe,OAAA;AACf,qGAAA,WAAW,OAAA;AACX,mGAAA,SAAS,OAAA;AAIX,mDAAgD;AAAxC,0GAAA,WAAW,OAAA;AACnB,uDAAoD;AAA5C,8GAAA,aAAa,OAAA;AACrB,+CAA4C;AAApC,sGAAA,SAAS,OAAA","file":"index.js","sourcesContent":["export {\n JsonUtils,\n TreeUtils,\n CryptUtils,\n ClassUtils,\n NotSupportedError,\n NotYetImplementedError,\n TodoException,\n NestedException,\n Logger,\n ILogLevel,\n ILoggerOptions,\n ILoggerApi,\n ConsoleLogger,\n AbstractLogger,\n MetaArgs,\n StringOrFunction,\n ISO8601,\n C_WARN,\n C_TRACE,\n C_INFO,\n C_ERROR,\n C_DEBUG,\n C_CONSOLE,\n __SOURCE__,\n C_DEFAULT,\n MetadataStorage,\n LockFactory,\n Semaphore\n} from './shared';\n\n\nexport {ClassLoader} from './utils/ClassLoader';\nexport {PlatformUtils} from './utils/PlatformUtils';\nexport {FileUtils} from './utils/FileUtils';\n\n"],"sourceRoot":"."}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import { Semaphore } from './Semaphore';
|
|
4
|
+
export declare class LockFactory extends EventEmitter {
|
|
5
|
+
constructor();
|
|
6
|
+
static NAME: string;
|
|
7
|
+
static __self__: LockFactory;
|
|
8
|
+
private semaphores;
|
|
9
|
+
static $(): LockFactory;
|
|
10
|
+
static reset(): void;
|
|
11
|
+
semaphore(max: number): Semaphore;
|
|
12
|
+
remove(s: Semaphore): void;
|
|
13
|
+
await(): Promise<any>;
|
|
14
|
+
shutdown(timeout?: number): Promise<void>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LockFactory = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const events_1 = require("events");
|
|
6
|
+
const Semaphore_1 = require("./Semaphore");
|
|
7
|
+
class LockFactory extends events_1.EventEmitter {
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
this.semaphores = [];
|
|
11
|
+
this.setMaxListeners(1000);
|
|
12
|
+
}
|
|
13
|
+
static $() {
|
|
14
|
+
if (!this.__self__) {
|
|
15
|
+
this.__self__ = new LockFactory();
|
|
16
|
+
}
|
|
17
|
+
return this.__self__;
|
|
18
|
+
}
|
|
19
|
+
static reset() {
|
|
20
|
+
this.__self__ = null;
|
|
21
|
+
}
|
|
22
|
+
semaphore(max) {
|
|
23
|
+
const sem = new Semaphore_1.Semaphore(max);
|
|
24
|
+
this.semaphores.push(sem);
|
|
25
|
+
return sem;
|
|
26
|
+
}
|
|
27
|
+
remove(s) {
|
|
28
|
+
lodash_1.remove(this.semaphores, s);
|
|
29
|
+
if (lodash_1.isEmpty(this.semaphores)) {
|
|
30
|
+
this.emit('empty');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
await() {
|
|
34
|
+
if (lodash_1.isEmpty(this.semaphores)) {
|
|
35
|
+
return Promise.resolve();
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return new Promise(resolve => {
|
|
39
|
+
this.once('empty', () => {
|
|
40
|
+
resolve(null);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async shutdown(timeout = 10000) {
|
|
46
|
+
await Promise.all(this.semaphores.map(x => x.await(timeout)));
|
|
47
|
+
for (const s of this.semaphores.reverse()) {
|
|
48
|
+
try {
|
|
49
|
+
s.purge();
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
}
|
|
53
|
+
this.remove(s);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.LockFactory = LockFactory;
|
|
58
|
+
LockFactory.NAME = LockFactory.name;
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=LockFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/locking/LockFactory.ts"],"names":[],"mappings":";;;AAAA,mCAAuC;AACvC,mCAAoC;AACpC,2CAAsC;AAEtC,MAAa,WAAY,SAAQ,qBAAY;IAE3C;QACE,KAAK,EAAE,CAAC;QASF,eAAU,GAAgB,EAAE,CAAC;QARnC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IASD,MAAM,CAAC,CAAC;QACN,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAClB,IAAI,CAAC,QAAQ,GAAG,IAAI,WAAW,EAAE,CAAC;SACnC;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,MAAM,CAAC,KAAK;QACV,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IACvB,CAAC;IAED,SAAS,CAAC,GAAW;QACnB,MAAM,GAAG,GAAG,IAAI,qBAAS,CAAC,GAAG,CAAC,CAAC;QAC/B,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC1B,OAAO,GAAG,CAAC;IACb,CAAC;IAED,MAAM,CAAC,CAAY;QACjB,eAAM,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;QAC3B,IAAI,gBAAO,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;YAC5B,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SACpB;IACH,CAAC;IAGD,KAAK;QACH,IAAI,gBAAO,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;YAC5B,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;SAC1B;aAAM;YACL,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;gBAC3B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE;oBACtB,OAAO,CAAC,IAAI,CAAC,CAAC;gBAChB,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,OAAO,GAAG,KAAK;QAC5B,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAe,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAC5E,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE;YACzC,IAAI;gBACF,CAAC,CAAC,KAAK,EAAE,CAAC;aACX;YAAC,OAAO,CAAC,EAAE;aACX;YACD,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;SAChB;IAEH,CAAC;;AA7DH,kCA+DC;AAvDQ,gBAAI,GAAW,WAAW,CAAC,IAAI,CAAC","file":"LockFactory.js","sourcesContent":["import {isEmpty, remove} from 'lodash';\nimport {EventEmitter} from 'events';\nimport {Semaphore} from './Semaphore';\n\nexport class LockFactory extends EventEmitter {\n\n constructor() {\n super();\n this.setMaxListeners(1000);\n }\n\n\n static NAME: string = LockFactory.name;\n\n static __self__: LockFactory;\n\n private semaphores: Semaphore[] = [];\n\n static $() {\n if (!this.__self__) {\n this.__self__ = new LockFactory();\n }\n return this.__self__;\n }\n\n static reset() {\n this.__self__ = null;\n }\n\n semaphore(max: number) {\n const sem = new Semaphore(max);\n this.semaphores.push(sem);\n return sem;\n }\n\n remove(s: Semaphore) {\n remove(this.semaphores, s);\n if (isEmpty(this.semaphores)) {\n this.emit('empty');\n }\n }\n\n\n await(): Promise<any> {\n if (isEmpty(this.semaphores)) {\n return Promise.resolve();\n } else {\n return new Promise(resolve => {\n this.once('empty', () => {\n resolve(null);\n });\n });\n }\n }\n\n async shutdown(timeout = 10000) {\n await Promise.all(this.semaphores.map(x => <Promise<any>>x.await(timeout)));\n for (const s of this.semaphores.reverse()) {\n try {\n s.purge();\n } catch (e) {\n }\n this.remove(s);\n }\n\n }\n\n}\n"],"sourceRoot":".."}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* https://gist.github.com/Gericop/e33be1f201cf242197d9c4d0a1fa7335
|
|
4
|
+
*/
|
|
5
|
+
import { EventEmitter } from 'events';
|
|
6
|
+
/**
|
|
7
|
+
* Semaphore implementation
|
|
8
|
+
*/
|
|
9
|
+
export declare class Semaphore extends EventEmitter {
|
|
10
|
+
/**
|
|
11
|
+
* Count resource usage
|
|
12
|
+
*/
|
|
13
|
+
private counter;
|
|
14
|
+
/**
|
|
15
|
+
* Waiting queue
|
|
16
|
+
*/
|
|
17
|
+
private waiting;
|
|
18
|
+
private readonly max;
|
|
19
|
+
private readonly name;
|
|
20
|
+
constructor(max: number, name?: string);
|
|
21
|
+
/**
|
|
22
|
+
* Take the next waiting caller
|
|
23
|
+
*/
|
|
24
|
+
private take;
|
|
25
|
+
/**
|
|
26
|
+
* Acquire semaphore for resource use
|
|
27
|
+
*/
|
|
28
|
+
acquire(): Promise<unknown>;
|
|
29
|
+
/**
|
|
30
|
+
* Release semaphore and free resource
|
|
31
|
+
*/
|
|
32
|
+
release(): void;
|
|
33
|
+
/**
|
|
34
|
+
* Purge acquired leases
|
|
35
|
+
*/
|
|
36
|
+
purge(): number;
|
|
37
|
+
/**
|
|
38
|
+
* Has waiting entries
|
|
39
|
+
*/
|
|
40
|
+
isReserved(): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Wait till semaphore is fully released
|
|
43
|
+
*/
|
|
44
|
+
await(timeout?: number): Promise<unknown>;
|
|
45
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Semaphore = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* https://gist.github.com/Gericop/e33be1f201cf242197d9c4d0a1fa7335
|
|
6
|
+
*/
|
|
7
|
+
const events_1 = require("events");
|
|
8
|
+
/**
|
|
9
|
+
* Semaphore implementation
|
|
10
|
+
*/
|
|
11
|
+
class Semaphore extends events_1.EventEmitter {
|
|
12
|
+
constructor(max, name = null) {
|
|
13
|
+
super();
|
|
14
|
+
/**
|
|
15
|
+
* Count resource usage
|
|
16
|
+
*/
|
|
17
|
+
this.counter = 0;
|
|
18
|
+
/**
|
|
19
|
+
* Waiting queue
|
|
20
|
+
*/
|
|
21
|
+
// eslint-disable-next-line no-unused-vars
|
|
22
|
+
this.waiting = [];
|
|
23
|
+
this.setMaxListeners(10000);
|
|
24
|
+
this.max = max;
|
|
25
|
+
this.name = name;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Take the next waiting caller
|
|
29
|
+
*/
|
|
30
|
+
take() {
|
|
31
|
+
if (this.waiting.length > 0 && this.counter < this.max) {
|
|
32
|
+
this.counter++;
|
|
33
|
+
const promise = this.waiting.shift();
|
|
34
|
+
promise.resolve();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Acquire semaphore for resource use
|
|
39
|
+
*/
|
|
40
|
+
acquire() {
|
|
41
|
+
if (this.counter < this.max) {
|
|
42
|
+
this.counter++;
|
|
43
|
+
return new Promise(resolve => {
|
|
44
|
+
resolve(null);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
return new Promise((resolve, err) => {
|
|
49
|
+
this.waiting.push({ resolve: resolve, err: err });
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Release semaphore and free resource
|
|
55
|
+
*/
|
|
56
|
+
release() {
|
|
57
|
+
this.counter--;
|
|
58
|
+
this.take();
|
|
59
|
+
if (this.counter === 0) {
|
|
60
|
+
this.emit('empty');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Purge acquired leases
|
|
65
|
+
*/
|
|
66
|
+
purge() {
|
|
67
|
+
const unresolved = this.waiting.length;
|
|
68
|
+
for (let i = 0; i < unresolved; i++) {
|
|
69
|
+
this.waiting[i].err('Task has been purged.');
|
|
70
|
+
}
|
|
71
|
+
this.counter = 0;
|
|
72
|
+
this.waiting = [];
|
|
73
|
+
this.removeAllListeners();
|
|
74
|
+
return unresolved;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Has waiting entries
|
|
78
|
+
*/
|
|
79
|
+
isReserved() {
|
|
80
|
+
return this.counter > 0;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Wait till semaphore is fully released
|
|
84
|
+
*/
|
|
85
|
+
await(timeout = 1000) {
|
|
86
|
+
if (this.counter === 0) {
|
|
87
|
+
return Promise.resolve();
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
let timer = null;
|
|
91
|
+
return new Promise((resolve, reject) => {
|
|
92
|
+
const fn = () => {
|
|
93
|
+
clearTimeout(timer);
|
|
94
|
+
this.removeAllListeners();
|
|
95
|
+
resolve(null);
|
|
96
|
+
};
|
|
97
|
+
this.once('empty', fn);
|
|
98
|
+
timer = setTimeout(() => {
|
|
99
|
+
this.removeAllListeners();
|
|
100
|
+
reject(new Error('timeout waiting for free semaphore ' + this.name));
|
|
101
|
+
}, timeout);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.Semaphore = Semaphore;
|
|
107
|
+
|
|
108
|
+
//# sourceMappingURL=Semaphore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/locking/Semaphore.ts"],"names":[],"mappings":"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","file":"Semaphore.js","sourcesContent":["/**\n * https://gist.github.com/Gericop/e33be1f201cf242197d9c4d0a1fa7335\n */\nimport { EventEmitter } from 'events';\n\n/**\n * Semaphore implementation\n */\nexport class Semaphore extends EventEmitter {\n\n\n /**\n * Count resource usage\n */\n private counter = 0;\n\n /**\n * Waiting queue\n */\n // eslint-disable-next-line no-unused-vars\n private waiting: { resolve: (value?: any) => void; err: (reason?: any) => void }[] = [];\n\n private readonly max: number;\n private readonly name: string;\n\n constructor(max: number, name: string = null) {\n super();\n this.setMaxListeners(10000);\n this.max = max;\n this.name = name;\n }\n\n /**\n * Take the next waiting caller\n */\n private take() {\n if (this.waiting.length > 0 && this.counter < this.max) {\n this.counter++;\n const promise = this.waiting.shift();\n promise.resolve();\n }\n }\n\n /**\n * Acquire semaphore for resource use\n */\n acquire() {\n if (this.counter < this.max) {\n this.counter++;\n return new Promise(resolve => {\n resolve(null);\n });\n } else {\n return new Promise((resolve, err) => {\n this.waiting.push({ resolve: resolve, err: err });\n });\n }\n }\n\n /**\n * Release semaphore and free resource\n */\n release() {\n this.counter--;\n this.take();\n if (this.counter === 0) {\n this.emit('empty');\n }\n }\n\n /**\n * Purge acquired leases\n */\n purge() {\n const unresolved = this.waiting.length;\n for (let i = 0; i < unresolved; i++) {\n this.waiting[i].err('Task has been purged.');\n }\n this.counter = 0;\n this.waiting = [];\n this.removeAllListeners();\n return unresolved;\n }\n\n /**\n * Has waiting entries\n */\n isReserved() {\n return this.counter > 0;\n }\n\n\n /**\n * Wait till semaphore is fully released\n */\n await(timeout = 1000) {\n if (this.counter === 0) {\n return Promise.resolve();\n } else {\n let timer: any = null;\n return new Promise((resolve, reject) => {\n const fn = () => {\n clearTimeout(timer);\n this.removeAllListeners();\n resolve(null);\n };\n this.once('empty', fn);\n timer = setTimeout(() => {\n this.removeAllListeners();\n reject(new Error('timeout waiting for free semaphore ' + this.name));\n }, timeout);\n });\n }\n }\n}\n"],"sourceRoot":".."}
|