@nu-art/ts-common 0.200.78 → 0.200.80
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/core/logger/LogClient_Browser.js +7 -7
- package/core/module.d.ts +3 -1
- package/core/module.js +4 -4
- package/index.d.ts +0 -1
- package/index.js +0 -1
- package/modules/CliParamsModule.js +3 -3
- package/package.json +1 -1
- package/utils/merge-tools.js +7 -5
- package/utils/object-tools.d.ts +1 -1
- package/utils/object-tools.js +4 -4
- package/utils/queue.js +3 -3
- package/utils/version-tools.js +3 -3
- package/validator/type-validators.d.ts +3 -0
- package/validator/type-validators.js +7 -1
- package/validator/validator-core.d.ts +0 -3
- package/validator/validator-core.js +1 -8
- package/permissions/permission-group.d.ts +0 -8
- package/permissions/permission-group.js +0 -34
|
@@ -20,7 +20,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
20
20
|
exports.LogClient_Browser = void 0;
|
|
21
21
|
const types_1 = require("./types");
|
|
22
22
|
const LogClient_1 = require("./LogClient");
|
|
23
|
-
const
|
|
23
|
+
const get_log_style_1 = require("../../tools/get-log-style");
|
|
24
24
|
class LogClient_Browser_class extends LogClient_1.LogClient {
|
|
25
25
|
constructor() {
|
|
26
26
|
super(...arguments);
|
|
@@ -51,17 +51,17 @@ class LogClient_Browser_class extends LogClient_1.LogClient {
|
|
|
51
51
|
getColor(level, bold) {
|
|
52
52
|
switch (level) {
|
|
53
53
|
case types_1.LogLevel.Verbose:
|
|
54
|
-
return (0,
|
|
54
|
+
return (0, get_log_style_1.getLogStyle)(this.style.base, this.style.verbose);
|
|
55
55
|
case types_1.LogLevel.Debug:
|
|
56
|
-
return (0,
|
|
56
|
+
return (0, get_log_style_1.getLogStyle)(this.style.base, this.style.debug);
|
|
57
57
|
case types_1.LogLevel.Info:
|
|
58
|
-
return (0,
|
|
58
|
+
return (0, get_log_style_1.getLogStyle)(this.style.base, this.style.info);
|
|
59
59
|
case types_1.LogLevel.Warning:
|
|
60
|
-
return (0,
|
|
60
|
+
return (0, get_log_style_1.getLogStyle)(this.style.base, this.style.warning);
|
|
61
61
|
case types_1.LogLevel.Error:
|
|
62
|
-
return (0,
|
|
62
|
+
return (0, get_log_style_1.getLogStyle)(this.style.base, this.style.error);
|
|
63
63
|
default:
|
|
64
|
-
return (0,
|
|
64
|
+
return (0, get_log_style_1.getLogStyle)({ 'color': '#000000' });
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
logMessage(level, bold, prefix, toLog) {
|
package/core/module.d.ts
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { ModuleManager } from './module-manager';
|
|
5
5
|
import { Logger } from './logger/Logger';
|
|
6
|
-
import { LogLevel
|
|
6
|
+
import { LogLevel } from './logger/types';
|
|
7
|
+
import { ValidatorTypeResolver } from '../validator/validator-core';
|
|
8
|
+
import { TimerHandler } from '../utils/date-time-tools';
|
|
7
9
|
type _FinalConfig<Config = any> = Config & {
|
|
8
10
|
minLogLevel?: LogLevel;
|
|
9
11
|
};
|
package/core/module.js
CHANGED
|
@@ -21,7 +21,7 @@ exports.Module = void 0;
|
|
|
21
21
|
const exceptions_1 = require("./exceptions");
|
|
22
22
|
const merge_tools_1 = require("../utils/merge-tools");
|
|
23
23
|
const Logger_1 = require("./logger/Logger");
|
|
24
|
-
const
|
|
24
|
+
const date_time_tools_1 = require("../utils/date-time-tools");
|
|
25
25
|
class Module extends Logger_1.Logger {
|
|
26
26
|
// noinspection TypeScriptAbstractClassConstructorCanBeMadeProtected
|
|
27
27
|
constructor(tag) {
|
|
@@ -45,8 +45,8 @@ class Module extends Logger_1.Logger {
|
|
|
45
45
|
this.name = this.name.replace('_Class', '');
|
|
46
46
|
}
|
|
47
47
|
debounce(handler, key, ms = 0) {
|
|
48
|
-
(0,
|
|
49
|
-
this.timeoutMap[key] = (0,
|
|
48
|
+
(0, date_time_tools_1._clearTimeout)(this.timeoutMap[key]);
|
|
49
|
+
this.timeoutMap[key] = (0, date_time_tools_1._setTimeout)(handler, ms);
|
|
50
50
|
}
|
|
51
51
|
// // possibly to add
|
|
52
52
|
// public async debounceSync(handler: TimerHandler, key: string, ms = 0) {
|
|
@@ -66,7 +66,7 @@ class Module extends Logger_1.Logger {
|
|
|
66
66
|
throttle(handler, key, ms = 0) {
|
|
67
67
|
if (this.timeoutMap[key])
|
|
68
68
|
return;
|
|
69
|
-
this.timeoutMap[key] = (0,
|
|
69
|
+
this.timeoutMap[key] = (0, date_time_tools_1._setTimeout)(() => {
|
|
70
70
|
handler();
|
|
71
71
|
delete this.timeoutMap[key];
|
|
72
72
|
}, ms);
|
package/index.d.ts
CHANGED
|
@@ -15,7 +15,6 @@ export * from './core/logger/BeLogged';
|
|
|
15
15
|
export * from './core/logger/Logger';
|
|
16
16
|
export * from './core/logger/types';
|
|
17
17
|
export * from './core/logger/LogClient';
|
|
18
|
-
export * from './permissions/permission-group';
|
|
19
18
|
export * from './tools/Replacer';
|
|
20
19
|
export * from './tools/get-log-style';
|
|
21
20
|
export * from './utils/queue';
|
package/index.js
CHANGED
|
@@ -48,7 +48,6 @@ __exportStar(require("./core/logger/BeLogged"), exports);
|
|
|
48
48
|
__exportStar(require("./core/logger/Logger"), exports);
|
|
49
49
|
__exportStar(require("./core/logger/types"), exports);
|
|
50
50
|
__exportStar(require("./core/logger/LogClient"), exports);
|
|
51
|
-
__exportStar(require("./permissions/permission-group"), exports);
|
|
52
51
|
__exportStar(require("./tools/Replacer"), exports);
|
|
53
52
|
__exportStar(require("./tools/get-log-style"), exports);
|
|
54
53
|
__exportStar(require("./utils/queue"), exports);
|
|
@@ -20,7 +20,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
20
20
|
exports.CliParamsModule = void 0;
|
|
21
21
|
const module_1 = require("../core/module");
|
|
22
22
|
const exceptions_1 = require("../core/exceptions");
|
|
23
|
-
const
|
|
23
|
+
const array_tools_1 = require("../utils/array-tools");
|
|
24
24
|
class CliParamsModule_Class extends module_1.Module {
|
|
25
25
|
constructor() {
|
|
26
26
|
super(...arguments);
|
|
@@ -56,11 +56,11 @@ class CliParamsModule_Class extends module_1.Module {
|
|
|
56
56
|
extractParam(param, argv) {
|
|
57
57
|
if (param.isArray)
|
|
58
58
|
return param.keys.reduce((values, key) => {
|
|
59
|
-
values.push(...(0,
|
|
59
|
+
values.push(...(0, array_tools_1.filterInstances)(argv.map(arg => { var _a; return (_a = arg.match(new RegExp(`${key}=(.*)`))) === null || _a === void 0 ? void 0 : _a[1]; })));
|
|
60
60
|
return values;
|
|
61
61
|
}, []);
|
|
62
62
|
const find = param.keys.map(key => argv.map(arg => { var _a; return (_a = arg.match(new RegExp(`${key}=(.*)`))) === null || _a === void 0 ? void 0 : _a[1]; }));
|
|
63
|
-
return (0,
|
|
63
|
+
return (0, array_tools_1.flatArray)(find).find(k => k);
|
|
64
64
|
}
|
|
65
65
|
printFoundArgs(title, params, foundArgs) {
|
|
66
66
|
if (params.length)
|
package/package.json
CHANGED
package/utils/merge-tools.js
CHANGED
|
@@ -18,12 +18,14 @@
|
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.merge = exports.mergeArray = exports.mergeObject = void 0;
|
|
21
|
-
const
|
|
21
|
+
const object_tools_1 = require("./object-tools");
|
|
22
|
+
const tools_1 = require("./tools");
|
|
23
|
+
const exceptions_1 = require("../core/exceptions");
|
|
22
24
|
function mergeObject(original, override) {
|
|
23
25
|
if (original === override) {
|
|
24
26
|
return override;
|
|
25
27
|
}
|
|
26
|
-
const returnValue = (0,
|
|
28
|
+
const returnValue = (0, object_tools_1.deepClone)(original);
|
|
27
29
|
return Object.keys(override).reduce((obj, key) => {
|
|
28
30
|
obj[key] = merge(original[key], override[key]);
|
|
29
31
|
if (obj[key] === undefined)
|
|
@@ -55,12 +57,12 @@ function mergeArray(original, override) {
|
|
|
55
57
|
}
|
|
56
58
|
exports.mergeArray = mergeArray;
|
|
57
59
|
function merge(original, override) {
|
|
58
|
-
if (!(0,
|
|
60
|
+
if (!(0, tools_1.exists)(override))
|
|
59
61
|
return undefined;
|
|
60
|
-
if (!(0,
|
|
62
|
+
if (!(0, tools_1.exists)(original))
|
|
61
63
|
return override;
|
|
62
64
|
if (typeof original !== typeof override || (typeof original === 'object' && typeof override === 'object' && Array.isArray(original) !== Array.isArray(override)))
|
|
63
|
-
throw new
|
|
65
|
+
throw new exceptions_1.BadImplementationException(`trying to merge object of different types!! \\n Original: ${JSON.stringify(original)}\\n Override: ${JSON.stringify(override)}`);
|
|
64
66
|
if (Array.isArray(original) && Array.isArray(override))
|
|
65
67
|
return mergeArray(original, override);
|
|
66
68
|
if (typeof original === 'object' && typeof override === 'object' && !Array.isArray(original) && !Array.isArray(override))
|
package/utils/object-tools.d.ts
CHANGED
package/utils/object-tools.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.filterKeys = exports.assert = exports.compare = exports.partialCompare = exports.cloneObj = exports.cloneArr = exports._setTypedProp = exports._values = exports._keys = exports.deepClone = void 0;
|
|
21
|
-
const
|
|
21
|
+
const exceptions_1 = require("../core/exceptions");
|
|
22
22
|
function deepClone(obj) {
|
|
23
23
|
if (typeof obj === 'string' || typeof obj === 'number' || typeof obj === 'boolean' || typeof obj === 'undefined' || obj === null)
|
|
24
24
|
return obj;
|
|
@@ -74,7 +74,7 @@ function compare(one, two, keys) {
|
|
|
74
74
|
if (one === null || two === null)
|
|
75
75
|
return false;
|
|
76
76
|
if (typeofOne === 'function')
|
|
77
|
-
throw new
|
|
77
|
+
throw new exceptions_1.BadImplementationException('This compare meant to compare two POJOs.. nothing more');
|
|
78
78
|
if (typeofOne !== 'object')
|
|
79
79
|
return one === two;
|
|
80
80
|
if (Array.isArray(one) && Array.isArray(two)) {
|
|
@@ -107,12 +107,12 @@ function compare(one, two, keys) {
|
|
|
107
107
|
exports.compare = compare;
|
|
108
108
|
function assert(message, expected, actual) {
|
|
109
109
|
if (!compare(expected, actual))
|
|
110
|
-
throw new
|
|
110
|
+
throw new exceptions_1.AssertionException(`Assertion Failed:\n -- ${message}\n -- Expected: ${JSON.stringify(expected)}\n -- Actual: ${JSON.stringify(actual)}\n\n`);
|
|
111
111
|
}
|
|
112
112
|
exports.assert = assert;
|
|
113
113
|
function filterKeys(obj, keys, filter = (k) => obj[k] === undefined || obj[k] === null) {
|
|
114
114
|
if (typeof obj !== 'object' || obj === null) {
|
|
115
|
-
throw new
|
|
115
|
+
throw new exceptions_1.BadImplementationException('Passed parameter for "obj" must be an object');
|
|
116
116
|
}
|
|
117
117
|
if (!Array.isArray(keys))
|
|
118
118
|
keys = [keys];
|
package/utils/queue.js
CHANGED
|
@@ -27,8 +27,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.Queue = void 0;
|
|
30
|
-
const index_1 = require("../index");
|
|
31
30
|
const Logger_1 = require("../core/logger/Logger");
|
|
31
|
+
const array_tools_1 = require("./array-tools");
|
|
32
32
|
class Queue extends Logger_1.Logger {
|
|
33
33
|
constructor(name) {
|
|
34
34
|
super(name);
|
|
@@ -51,7 +51,7 @@ class Queue extends Logger_1.Logger {
|
|
|
51
51
|
this.execute();
|
|
52
52
|
}
|
|
53
53
|
addItemImpl(toExecute, onCompleted, onError) {
|
|
54
|
-
(0,
|
|
54
|
+
(0, array_tools_1.addItemToArray)(this.queue, (resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
55
55
|
this.running++;
|
|
56
56
|
try {
|
|
57
57
|
const output = yield toExecute();
|
|
@@ -80,7 +80,7 @@ class Queue extends Logger_1.Logger {
|
|
|
80
80
|
}
|
|
81
81
|
for (let i = 0; this.running < this.parallelCount && i < this.queue.length; i++) {
|
|
82
82
|
const toExecute = this.queue[0];
|
|
83
|
-
(0,
|
|
83
|
+
(0, array_tools_1.removeItemFromArray)(this.queue, toExecute);
|
|
84
84
|
new Promise(toExecute.bind(this))
|
|
85
85
|
.then(this.ignore)
|
|
86
86
|
.catch(this.ignore);
|
package/utils/version-tools.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.compareVersions = void 0;
|
|
21
|
-
const
|
|
21
|
+
const exceptions_1 = require("../core/exceptions");
|
|
22
22
|
/**
|
|
23
23
|
*
|
|
24
24
|
* @param firstVersion a version
|
|
@@ -30,9 +30,9 @@ const index_1 = require("../index");
|
|
|
30
30
|
*/
|
|
31
31
|
function compareVersions(firstVersion, secondVersion) {
|
|
32
32
|
if (!firstVersion)
|
|
33
|
-
throw new
|
|
33
|
+
throw new exceptions_1.BadImplementationException("First version is undefined");
|
|
34
34
|
if (!secondVersion)
|
|
35
|
-
throw new
|
|
35
|
+
throw new exceptions_1.BadImplementationException("Second version is undefined");
|
|
36
36
|
const firstVersionAsArray = firstVersion.split("\.");
|
|
37
37
|
const secondVersionAsArray = secondVersion.split("\.");
|
|
38
38
|
for (let i = 0; i < firstVersionAsArray.length; i++) {
|
|
@@ -21,4 +21,7 @@ export declare const tsValidateRegexp: (regexp: RegExp, mandatory?: boolean) =>
|
|
|
21
21
|
export declare const tsValidateTimestamp: (interval?: number, mandatory?: boolean) => Validator<number>;
|
|
22
22
|
export declare const tsValidateAudit: (range?: RangeTimestamp) => (audit?: AuditBy) => any;
|
|
23
23
|
export declare const tsValidateNonMandatoryObject: <T>(validator: ValidatorTypeResolver<T>) => ((input?: T | undefined) => any)[];
|
|
24
|
+
export declare const tsValidator_valueByKey: <T extends unknown>(validatorObject: {
|
|
25
|
+
[k: string]: Validator<any> | import("./validator-core").TypeValidator<any>;
|
|
26
|
+
}) => ValidatorTypeResolver<T>;
|
|
24
27
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.tsValidateNonMandatoryObject = exports.tsValidateAudit = exports.tsValidateTimestamp = exports.tsValidateRegexp = exports.tsValidateRange = exports.tsValidateIsInRange = exports.tsValidateValue = exports.tsValidateBoolean = exports.tsValidateEnum = exports.tsValidateNumber = exports.tsValidateString = exports.tsValidateArray = exports.tsValidateUnionV3 = exports.tsValidateCustom = exports.tsValidateUnion = exports.tsValidateDynamicObject = void 0;
|
|
3
|
+
exports.tsValidator_valueByKey = exports.tsValidateNonMandatoryObject = exports.tsValidateAudit = exports.tsValidateTimestamp = exports.tsValidateRegexp = exports.tsValidateRange = exports.tsValidateIsInRange = exports.tsValidateValue = exports.tsValidateBoolean = exports.tsValidateEnum = exports.tsValidateNumber = exports.tsValidateString = exports.tsValidateArray = exports.tsValidateUnionV3 = exports.tsValidateCustom = exports.tsValidateUnion = exports.tsValidateDynamicObject = void 0;
|
|
4
4
|
const tools_1 = require("../utils/tools");
|
|
5
5
|
const validator_core_1 = require("./validator-core");
|
|
6
6
|
const date_time_tools_1 = require("../utils/date-time-tools");
|
|
@@ -180,3 +180,9 @@ const tsValidateNonMandatoryObject = (validator) => {
|
|
|
180
180
|
(input) => (0, validator_core_1.tsValidateResult)(input, validator)];
|
|
181
181
|
};
|
|
182
182
|
exports.tsValidateNonMandatoryObject = tsValidateNonMandatoryObject;
|
|
183
|
+
const tsValidator_valueByKey = (validatorObject) => {
|
|
184
|
+
return (0, exports.tsValidateCustom)((value, parentObject) => {
|
|
185
|
+
return (0, validator_core_1.tsValidateResult)(value, validatorObject[parentObject.type]);
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
exports.tsValidator_valueByKey = tsValidator_valueByKey;
|
|
@@ -29,6 +29,3 @@ export declare const tsValidateExists: (mandatory?: boolean) => ValidatorImpl<an
|
|
|
29
29
|
export declare const tsValidate: <T extends unknown>(instance: T | undefined, _validator: ValidatorTypeResolver<T>, strict?: boolean) => any;
|
|
30
30
|
export declare const tsValidateResult: <T extends unknown>(instance: T | undefined, _validator: ValidatorTypeResolver<T>, key?: keyof T | undefined, parentInstance?: any) => any;
|
|
31
31
|
export declare const tsValidateObject: <T>(__validator: TypeValidator<object>, instance: T, path?: string) => InvalidResultObject<T> | undefined;
|
|
32
|
-
export declare const tsValidator_valueByKey: <T extends unknown>(validatorObject: {
|
|
33
|
-
[k: string]: Validator<any> | TypeValidator<any>;
|
|
34
|
-
}) => ValidatorTypeResolver<T>;
|
|
@@ -17,8 +17,7 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.
|
|
21
|
-
const __1 = require("..");
|
|
20
|
+
exports.tsValidateObject = exports.tsValidateResult = exports.tsValidate = exports.tsValidateExists = exports.assertValidateMandatoryProperty = exports.ValidationException = void 0;
|
|
22
21
|
const exceptions_1 = require("../core/exceptions");
|
|
23
22
|
const object_tools_1 = require("../utils/object-tools");
|
|
24
23
|
class ValidationException extends exceptions_1.CustomException {
|
|
@@ -110,9 +109,3 @@ const tsValidateObject = (__validator, instance, path = '') => {
|
|
|
110
109
|
return result;
|
|
111
110
|
};
|
|
112
111
|
exports.tsValidateObject = tsValidateObject;
|
|
113
|
-
const tsValidator_valueByKey = (validatorObject) => {
|
|
114
|
-
return (0, __1.tsValidateCustom)((value, parentObject) => {
|
|
115
|
-
return (0, exports.tsValidateResult)(value, validatorObject[parentObject.type]);
|
|
116
|
-
});
|
|
117
|
-
};
|
|
118
|
-
exports.tsValidator_valueByKey = tsValidator_valueByKey;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export declare class PermissionCategory<P extends number> {
|
|
2
|
-
readonly key: string;
|
|
3
|
-
readonly levels: string[];
|
|
4
|
-
readonly permissionsEnum: any;
|
|
5
|
-
readonly defaultValue: P;
|
|
6
|
-
constructor(key: string, permissionsEnum: any, defaultValue: P);
|
|
7
|
-
getClosestMatch(permission: number): string | undefined;
|
|
8
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PermissionCategory = void 0;
|
|
4
|
-
/*
|
|
5
|
-
* ts-common is the basic building blocks of our typescript projects
|
|
6
|
-
*
|
|
7
|
-
* Copyright (C) 2020 Adam van der Kruk aka TacB0sS
|
|
8
|
-
*
|
|
9
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
-
* you may not use this file except in compliance with the License.
|
|
11
|
-
* You may obtain a copy of the License at
|
|
12
|
-
*
|
|
13
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
-
*
|
|
15
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
-
* See the License for the specific language governing permissions and
|
|
19
|
-
* limitations under the License.
|
|
20
|
-
*/
|
|
21
|
-
const index_1 = require("../index");
|
|
22
|
-
class PermissionCategory {
|
|
23
|
-
constructor(key, permissionsEnum, defaultValue) {
|
|
24
|
-
this.key = key;
|
|
25
|
-
this.permissionsEnum = permissionsEnum;
|
|
26
|
-
this.defaultValue = defaultValue;
|
|
27
|
-
const _levels = Object.keys(permissionsEnum).filter(value => isNaN(parseInt(value)));
|
|
28
|
-
this.levels = (0, index_1.sortArray)(_levels, (_key) => permissionsEnum[_key]).reverse();
|
|
29
|
-
}
|
|
30
|
-
getClosestMatch(permission) {
|
|
31
|
-
return (0, index_1.deepClone)(this.levels).reverse().find(((level) => this.permissionsEnum[level] <= permission));
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.PermissionCategory = PermissionCategory;
|