@nu-art/ts-common 0.204.142 → 0.204.144
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/debug-flags.js +2 -2
- package/core/error-handling.js +1 -1
- package/core/exceptions/exceptions.js +2 -2
- package/core/logger/LogClient.js +2 -2
- package/core/logger/Logger.js +2 -2
- package/core/logger/types.js +1 -1
- package/core/logger/utils.js +4 -5
- package/core/module-manager.d.ts +10 -10
- package/core/module-manager.js +2 -2
- package/mem-storage/MemStorage.d.ts +1 -1
- package/modules/CSVModule.d.ts +0 -2
- package/modules/CSVModuleV3.d.ts +1 -1
- package/modules/csv-serializer.js +1 -2
- package/package.json +1 -1
- package/replacer-v2/ReplacerV2.js +1 -1
- package/testing/consts.d.ts +1 -3
- package/testing/consts.js +2 -2
- package/tools/Replacer.js +1 -1
- package/tools/get-log-style.js +1 -2
- package/utils/array-tools.js +33 -34
- package/utils/crypto-tools.d.ts +0 -1
- package/utils/crypto-tools.js +3 -4
- package/utils/date-time-tools.js +17 -17
- package/utils/db-object-tools.js +6 -6
- package/utils/exception-tools.js +1 -2
- package/utils/filter-tools.js +1 -1
- package/utils/hash-tools.d.ts +0 -1
- package/utils/hash-tools.js +7 -8
- package/utils/json-tools.js +2 -3
- package/utils/merge-tools.js +3 -4
- package/utils/object-tools.js +11 -12
- package/utils/query-params.js +2 -3
- package/utils/random-tools.js +3 -4
- package/utils/string-tools.js +13 -14
- package/utils/tools.js +7 -7
- package/utils/version-tools.d.ts +5 -0
- package/utils/version-tools.js +15 -6
- package/validator/type-validators.d.ts +7 -7
- package/validator/validator-core.d.ts +1 -1
package/core/debug-flags.js
CHANGED
|
@@ -56,8 +56,8 @@ class DebugFlag {
|
|
|
56
56
|
(0, array_tools_1.removeItemFromArray)(DebugFlags.instance.ActiveDebugFlags, this.key);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
DebugFlag.DefaultLogLevel = types_1.LogLevel.Info;
|
|
60
59
|
exports.DebugFlag = DebugFlag;
|
|
60
|
+
DebugFlag.DefaultLogLevel = types_1.LogLevel.Info;
|
|
61
61
|
class DebugFlags {
|
|
62
62
|
constructor() {
|
|
63
63
|
this.AllDebugFlags = {};
|
|
@@ -78,5 +78,5 @@ class DebugFlags {
|
|
|
78
78
|
this.instance.AllDebugFlags[newKey] = flag;
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
DebugFlags.instance = new DebugFlags();
|
|
82
81
|
exports.DebugFlags = DebugFlags;
|
|
82
|
+
DebugFlags.instance = new DebugFlags();
|
package/core/error-handling.js
CHANGED
|
@@ -26,7 +26,7 @@ var ServerErrorSeverity;
|
|
|
26
26
|
ServerErrorSeverity["Warning"] = "Warning";
|
|
27
27
|
ServerErrorSeverity["Error"] = "Error";
|
|
28
28
|
ServerErrorSeverity["Critical"] = "Critical";
|
|
29
|
-
})(ServerErrorSeverity
|
|
29
|
+
})(ServerErrorSeverity || (exports.ServerErrorSeverity = ServerErrorSeverity = {}));
|
|
30
30
|
exports.ServerErrorSeverity_Ordinal = [
|
|
31
31
|
ServerErrorSeverity.Debug,
|
|
32
32
|
ServerErrorSeverity.Info,
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
* Created by TacB0sS on 3/16/17.
|
|
21
21
|
*/
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.ApiException = exports.AssertionException = exports.MissingPermissionException = exports.MissingDataException = exports.ConfigMissingException = exports.WhoCallThisException = exports.DontCallThisException = exports.HasDependenciesException = exports.ThisShouldNotHappenException = exports.NotImplementedYetException = exports.MUSTNeverHappenException = exports.ImplementationMissingException = exports.BadImplementationException = exports.Exception = exports.CustomException =
|
|
23
|
+
exports.ApiException = exports.AssertionException = exports.MissingPermissionException = exports.MissingDataException = exports.ConfigMissingException = exports.WhoCallThisException = exports.DontCallThisException = exports.HasDependenciesException = exports.ThisShouldNotHappenException = exports.NotImplementedYetException = exports.MUSTNeverHappenException = exports.ImplementationMissingException = exports.BadImplementationException = exports.Exception = exports.CustomException = void 0;
|
|
24
|
+
exports.isErrorOfType = isErrorOfType;
|
|
24
25
|
const utils_1 = require("../logger/utils");
|
|
25
26
|
/**
|
|
26
27
|
* # <ins>isErrorOfType</ins>
|
|
@@ -52,7 +53,6 @@ function isErrorOfType(e, _exceptionType) {
|
|
|
52
53
|
if ((_a = _e.isInstanceOf) === null || _a === void 0 ? void 0 : _a.call(_e, _exceptionType))
|
|
53
54
|
return e;
|
|
54
55
|
}
|
|
55
|
-
exports.isErrorOfType = isErrorOfType;
|
|
56
56
|
/**
|
|
57
57
|
* # CustomException
|
|
58
58
|
*
|
package/core/logger/LogClient.js
CHANGED
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.DefaultLogPrefixComposer = exports.
|
|
20
|
+
exports.DefaultLogPrefixComposer = exports._logger_logPrefixes = exports._logger_finalDate = exports._logger_timezoneOffset = exports.LogClient = void 0;
|
|
21
|
+
exports._logger_getPrefix = _logger_getPrefix;
|
|
21
22
|
const types_1 = require("./types");
|
|
22
23
|
class LogClient {
|
|
23
24
|
constructor() {
|
|
@@ -57,7 +58,6 @@ function _logger_getPrefix(level) {
|
|
|
57
58
|
return '---';
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
|
-
exports._logger_getPrefix = _logger_getPrefix;
|
|
61
61
|
const DefaultLogPrefixComposer = (tag, level) => {
|
|
62
62
|
exports._logger_finalDate.setTime(Date.now() - exports._logger_timezoneOffset);
|
|
63
63
|
const date = exports._logger_finalDate.toISOString().replace(/T/, '_').replace(/Z/, '').substring(0, 23);
|
package/core/logger/Logger.js
CHANGED
|
@@ -77,8 +77,8 @@ class Logger {
|
|
|
77
77
|
return this._DEBUG_FLAG.canLog(level);
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
|
-
Logger.defaultFlagState = true;
|
|
81
80
|
exports.Logger = Logger;
|
|
81
|
+
Logger.defaultFlagState = true;
|
|
82
82
|
class StaticLogger {
|
|
83
83
|
static setMinLevel(minLevel) {
|
|
84
84
|
this._DEBUG_FLAG.setMinLevel(minLevel);
|
|
@@ -125,8 +125,8 @@ class StaticLogger {
|
|
|
125
125
|
return this._DEBUG_FLAG.canLog(level);
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
|
+
exports.StaticLogger = StaticLogger;
|
|
128
129
|
StaticLogger._DEBUG_FLAG = debug_flags_1.DebugFlags.createFlag('StaticLogger');
|
|
129
130
|
(() => {
|
|
130
131
|
StaticLogger._DEBUG_FLAG.enable(Logger.defaultFlagState);
|
|
131
132
|
})();
|
|
132
|
-
exports.StaticLogger = StaticLogger;
|
package/core/logger/types.js
CHANGED
|
@@ -25,7 +25,7 @@ var LogLevel;
|
|
|
25
25
|
LogLevel["Info"] = "Info";
|
|
26
26
|
LogLevel["Warning"] = "Warning";
|
|
27
27
|
LogLevel["Error"] = "Error";
|
|
28
|
-
})(LogLevel
|
|
28
|
+
})(LogLevel || (exports.LogLevel = LogLevel = {}));
|
|
29
29
|
exports.LogLevelOrdinal = [
|
|
30
30
|
LogLevel.Verbose,
|
|
31
31
|
LogLevel.Debug,
|
package/core/logger/utils.js
CHANGED
|
@@ -17,7 +17,10 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.
|
|
20
|
+
exports._logger_logObject = _logger_logObject;
|
|
21
|
+
exports._logger_convertLogParamsToStrings = _logger_convertLogParamsToStrings;
|
|
22
|
+
exports._logger_logException = _logger_logException;
|
|
23
|
+
exports._logger_indentNewLineBy = _logger_indentNewLineBy;
|
|
21
24
|
/**
|
|
22
25
|
* Created by TacB0sS on 3/16/17.
|
|
23
26
|
*/
|
|
@@ -26,7 +29,6 @@ const tools_1 = require("../../utils/tools");
|
|
|
26
29
|
function _logger_logObject(instance) {
|
|
27
30
|
return (0, tools_1.__stringify)(instance, true);
|
|
28
31
|
}
|
|
29
|
-
exports._logger_logObject = _logger_logObject;
|
|
30
32
|
function _logger_convertLogParamsToStrings(params) {
|
|
31
33
|
return params.map(toLog => {
|
|
32
34
|
if (typeof toLog === 'undefined')
|
|
@@ -43,7 +45,6 @@ function _logger_convertLogParamsToStrings(params) {
|
|
|
43
45
|
return (0, tools_1.__stringify)(toLog, true);
|
|
44
46
|
});
|
|
45
47
|
}
|
|
46
|
-
exports._logger_convertLogParamsToStrings = _logger_convertLogParamsToStrings;
|
|
47
48
|
function _logger_logException(error, fullStack = '') {
|
|
48
49
|
let toPrint = '';
|
|
49
50
|
let errorMessage;
|
|
@@ -71,8 +72,6 @@ function _logger_logException(error, fullStack = '') {
|
|
|
71
72
|
}
|
|
72
73
|
return toPrint;
|
|
73
74
|
}
|
|
74
|
-
exports._logger_logException = _logger_logException;
|
|
75
75
|
function _logger_indentNewLineBy(linePrefix, input) {
|
|
76
76
|
return linePrefix + input.replace(/\n/g, `\n${linePrefix}`);
|
|
77
77
|
}
|
|
78
|
-
exports._logger_indentNewLineBy = _logger_indentNewLineBy;
|
package/core/module-manager.d.ts
CHANGED
|
@@ -6,11 +6,11 @@ import { Logger } from './logger/Logger';
|
|
|
6
6
|
export declare function moduleResolver(): Module<any, any, import("..").Validator<any> | import("..").TypeValidator<any>>[];
|
|
7
7
|
export declare const RuntimeModules: () => {
|
|
8
8
|
filter: <T>(filter: (item: T, index: number, array: T[]) => boolean) => T[];
|
|
9
|
-
find: <
|
|
10
|
-
some: <
|
|
11
|
-
map: <
|
|
12
|
-
forEach: <
|
|
13
|
-
includes: <
|
|
9
|
+
find: <T>(filter: (item: T, index: number, array: T[]) => boolean) => T;
|
|
10
|
+
some: <T>(filter: (item: T, index: number, array: T[]) => boolean) => T;
|
|
11
|
+
map: <T, S>(processor: (item: T, index: number, array: T[]) => S) => S[];
|
|
12
|
+
forEach: <T>(processor: (item: T, index: number, array: T[]) => void) => void;
|
|
13
|
+
includes: <T>(module: T) => boolean;
|
|
14
14
|
all: Module<any, any, import("..").Validator<any> | import("..").TypeValidator<any>>[];
|
|
15
15
|
};
|
|
16
16
|
export declare const RuntimeVersion: () => string | undefined;
|
|
@@ -18,11 +18,11 @@ export declare class ModuleManager extends Logger {
|
|
|
18
18
|
protected config: any;
|
|
19
19
|
readonly modules: {
|
|
20
20
|
filter: <T>(filter: (item: T, index: number, array: T[]) => boolean) => T[];
|
|
21
|
-
find: <
|
|
22
|
-
some: <
|
|
23
|
-
map: <
|
|
24
|
-
forEach: <
|
|
25
|
-
includes: <
|
|
21
|
+
find: <T>(filter: (item: T, index: number, array: T[]) => boolean) => T;
|
|
22
|
+
some: <T>(filter: (item: T, index: number, array: T[]) => boolean) => T;
|
|
23
|
+
map: <T, S>(processor: (item: T, index: number, array: T[]) => S) => S[];
|
|
24
|
+
forEach: <T>(processor: (item: T, index: number, array: T[]) => void) => void;
|
|
25
|
+
includes: <T>(module: T) => boolean;
|
|
26
26
|
all: Module<any, any, import("..").Validator<any> | import("..").TypeValidator<any>>[];
|
|
27
27
|
};
|
|
28
28
|
static instance: ModuleManager;
|
package/core/module-manager.js
CHANGED
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.ModuleManager = exports.RuntimeVersion = exports.RuntimeModules =
|
|
20
|
+
exports.ModuleManager = exports.RuntimeVersion = exports.RuntimeModules = void 0;
|
|
21
|
+
exports.moduleResolver = moduleResolver;
|
|
21
22
|
const dispatcher_1 = require("./dispatcher");
|
|
22
23
|
const exceptions_1 = require("./exceptions/exceptions");
|
|
23
24
|
const Logger_1 = require("./logger/Logger");
|
|
@@ -27,7 +28,6 @@ const _modules = [];
|
|
|
27
28
|
function moduleResolver() {
|
|
28
29
|
return _modules;
|
|
29
30
|
}
|
|
30
|
-
exports.moduleResolver = moduleResolver;
|
|
31
31
|
const modulesInterface = {
|
|
32
32
|
filter: (filter) => {
|
|
33
33
|
return _modules.filter(filter);
|
|
@@ -11,7 +11,7 @@ export declare class MemKey<T> {
|
|
|
11
11
|
readonly unique: boolean;
|
|
12
12
|
private resolver?;
|
|
13
13
|
constructor(key: string, unique?: boolean);
|
|
14
|
-
setResolver: (resolver?: (
|
|
14
|
+
setResolver: (resolver?: (storage: MemStorage) => T) => this;
|
|
15
15
|
resolve: (storage: MemStorage) => Promise<void>;
|
|
16
16
|
assert: (value?: T) => T;
|
|
17
17
|
get: (value?: T) => T;
|
package/modules/CSVModule.d.ts
CHANGED
package/modules/CSVModuleV3.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare class CSVModuleV3_Class extends Module {
|
|
|
9
9
|
protected init(): void;
|
|
10
10
|
readFromStream: <T>(stream: Readable, processor: (item: T, rowNumber: number, stream: csv.CsvParserStream<csv.ParserRow<any>, csv.ParserRow<any>>) => void) => Promise<void>;
|
|
11
11
|
protected readImpl: <T>(stream: Readable, processor: (item: T, rowNumber: number, stream: csv.CsvParserStream<csv.ParserRow<any>, csv.ParserRow<any>>) => void) => Promise<void>;
|
|
12
|
-
writeToStream: <I extends csv.FormatterRow = csv.FormatterRow, O extends csv.FormatterRow = csv.FormatterRow>(writable: Writable, items: I[], options?: csv.FormatterOptionsArgs<I, O>
|
|
12
|
+
writeToStream: <I extends csv.FormatterRow = csv.FormatterRow, O extends csv.FormatterRow = csv.FormatterRow>(writable: Writable, items: I[], options?: csv.FormatterOptionsArgs<I, O>) => Promise<void>;
|
|
13
13
|
protected writeImpl: <I>(writable: Writable, items: I[], options?: csv.FormatterOptionsArgs<any, any>) => Promise<void>;
|
|
14
14
|
provideFormatter: (transformer?: (item: any) => any) => csv.CsvFormatterStream<csv.FormatterRow, csv.FormatterRow>;
|
|
15
15
|
provideFormatterFromCsv: (transformer?: (item: any) => any) => csv.CsvParserStream<csv.ParserRow<any>, csv.ParserRow<any>>;
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.csvSerializer =
|
|
20
|
+
exports.csvSerializer = csvSerializer;
|
|
21
21
|
function csvSerializer(items, _csvProps) {
|
|
22
22
|
const csvProps = Object.assign({ decimalSeparator: '.', withHeaders: true, fieldWrapper: '"', lineSeparator: '\n', fieldSeparator: ',', columnNames: (k) => k.toString() }, _csvProps);
|
|
23
23
|
function processValue(value) {
|
|
@@ -35,4 +35,3 @@ function csvSerializer(items, _csvProps) {
|
|
|
35
35
|
outputRows.push(...rowsData);
|
|
36
36
|
return outputRows.reduce((content, row) => `${content}${row}${csvProps.lineSeparator}`, '').slice(0, -1);
|
|
37
37
|
}
|
|
38
|
-
exports.csvSerializer = csvSerializer;
|
package/package.json
CHANGED
|
@@ -15,6 +15,6 @@ class ReplacerV2 {
|
|
|
15
15
|
return (0, array_tools_1.filterInstances)(matches.map((param) => { var _a; return (_a = param.match(ReplacerV2.Regexp_param)) === null || _a === void 0 ? void 0 : _a[1]; }));
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
+
exports.ReplacerV2 = ReplacerV2;
|
|
18
19
|
ReplacerV2.Regexp_paramGroup = /\$\{(\{?.*?\}?)\}/g;
|
|
19
20
|
ReplacerV2.Regexp_param = /\$\{(\{?.*?\}?)\}/;
|
|
20
|
-
exports.ReplacerV2 = ReplacerV2;
|
package/testing/consts.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
/// <reference types="chai" />
|
|
2
|
-
/// <reference types="chai-as-promised" />
|
|
3
1
|
import { TestModel, TestSuite } from './types';
|
|
4
2
|
import { ModuleManager } from '../core/module-manager';
|
|
5
3
|
export declare class ModuleManagerTester extends ModuleManager {
|
|
6
4
|
constructor();
|
|
7
5
|
}
|
|
8
6
|
export declare function testSuite_RunTest<Input, ExpectedResult>(testSuit: TestSuite<Input, ExpectedResult>, testCase: TestModel<Input, ExpectedResult>): void;
|
|
9
|
-
export declare const testSuiteTester: <Input, ExpectedResult>(testSuit: TestSuite<Input, ExpectedResult>, ...testcases:
|
|
7
|
+
export declare const testSuiteTester: <Input, ExpectedResult>(testSuit: TestSuite<Input, ExpectedResult>, ...testcases: TestSuite<Input, ExpectedResult>["testcases"]) => void;
|
|
10
8
|
export declare const expectFailAsync: (action: () => Promise<void>) => Promise<Chai.Assertion>;
|
package/testing/consts.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.expectFailAsync = exports.testSuiteTester = exports.
|
|
3
|
+
exports.expectFailAsync = exports.testSuiteTester = exports.ModuleManagerTester = void 0;
|
|
4
|
+
exports.testSuite_RunTest = testSuite_RunTest;
|
|
4
5
|
const chai_1 = require("chai");
|
|
5
6
|
const module_manager_1 = require("../core/module-manager");
|
|
6
7
|
const tools_1 = require("../utils/tools");
|
|
@@ -14,7 +15,6 @@ exports.ModuleManagerTester = ModuleManagerTester;
|
|
|
14
15
|
function testSuite_RunTest(testSuit, testCase) {
|
|
15
16
|
it(testCase.description, () => testSuit.processor(testCase));
|
|
16
17
|
}
|
|
17
|
-
exports.testSuite_RunTest = testSuite_RunTest;
|
|
18
18
|
const testSuiteTester = (testSuit, ...testcases) => {
|
|
19
19
|
describe(testSuit.label, () => {
|
|
20
20
|
//Run pre-process
|
package/tools/Replacer.js
CHANGED
|
@@ -136,10 +136,10 @@ class Replacer extends Logger_1.Logger {
|
|
|
136
136
|
// this.logDebug(value);
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
|
+
exports.Replacer = Replacer;
|
|
139
140
|
Replacer.RuntimeParam = '__runtime';
|
|
140
141
|
Replacer.Indicator_RuntimeParam = '__';
|
|
141
142
|
Replacer.Regexp_paramGroup = /\$\{(\{?.*?\}?)\}/g;
|
|
142
143
|
Replacer.Regexp_param = /\$\{(\{?.*?\}?)\}/;
|
|
143
144
|
Replacer.Regexp_forLoopGroupStart = /\{\{foreach (.*?) in (.*?)\}\}/g;
|
|
144
145
|
Replacer.Regexp_forLoopParam = /\{\{foreach (.*?) in (.*?)\}\}/;
|
|
145
|
-
exports.Replacer = Replacer;
|
package/tools/get-log-style.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.getLogStyle =
|
|
20
|
+
exports.getLogStyle = getLogStyle;
|
|
21
21
|
const object_tools_1 = require("../utils/object-tools");
|
|
22
22
|
/**
|
|
23
23
|
* Returns a style string for console.log()
|
|
@@ -35,4 +35,3 @@ function getLogStyle(...styleObj) {
|
|
|
35
35
|
});
|
|
36
36
|
return style;
|
|
37
37
|
}
|
|
38
|
-
exports.getLogStyle = getLogStyle;
|
package/utils/array-tools.js
CHANGED
|
@@ -17,7 +17,39 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.
|
|
20
|
+
exports.filterInOut = filterInOut;
|
|
21
|
+
exports.removeItemFromArray = removeItemFromArray;
|
|
22
|
+
exports.removeFromArray = removeFromArray;
|
|
23
|
+
exports.removeFromArrayByIndex = removeFromArrayByIndex;
|
|
24
|
+
exports.swapInArrayByIndex = swapInArrayByIndex;
|
|
25
|
+
exports.addItemToArray = addItemToArray;
|
|
26
|
+
exports.addItemToArrayAtIndex = addItemToArrayAtIndex;
|
|
27
|
+
exports.toggleElementInArray = toggleElementInArray;
|
|
28
|
+
exports.filterAsync = filterAsync;
|
|
29
|
+
exports.findDuplicates = findDuplicates;
|
|
30
|
+
exports.filterDuplicates = filterDuplicates;
|
|
31
|
+
exports.filterInstances = filterInstances;
|
|
32
|
+
exports.filterFalsy = filterFalsy;
|
|
33
|
+
exports.arrayToMap = arrayToMap;
|
|
34
|
+
exports.reduceToMap = reduceToMap;
|
|
35
|
+
exports.sortArray = sortArray;
|
|
36
|
+
exports.batchAction = batchAction;
|
|
37
|
+
exports.Promise_all_sequentially = Promise_all_sequentially;
|
|
38
|
+
exports.batchActionParallel = batchActionParallel;
|
|
39
|
+
exports.flatArray = flatArray;
|
|
40
|
+
exports.filterFlatInstances = filterFlatInstances;
|
|
41
|
+
exports.groupArrayBy = groupArrayBy;
|
|
42
|
+
exports.toggleInArray = toggleInArray;
|
|
43
|
+
exports.generateArray = generateArray;
|
|
44
|
+
exports.asArray = asArray;
|
|
45
|
+
exports.asOptionalArray = asOptionalArray;
|
|
46
|
+
exports.lastElement = lastElement;
|
|
47
|
+
exports.firstElement = firstElement;
|
|
48
|
+
exports.arrayIncludesAny = arrayIncludesAny;
|
|
49
|
+
exports.clearArrayInstance = clearArrayInstance;
|
|
50
|
+
exports.arrayIncludesAll = arrayIncludesAll;
|
|
51
|
+
exports.getMax = getMax;
|
|
52
|
+
exports.getMin = getMin;
|
|
21
53
|
const tools_1 = require("./tools");
|
|
22
54
|
const object_tools_1 = require("./object-tools");
|
|
23
55
|
const exceptions_1 = require("../core/exceptions/exceptions");
|
|
@@ -27,7 +59,6 @@ function filterInOut(input, filter) {
|
|
|
27
59
|
filteredOut: input.filter((object) => !filter(object))
|
|
28
60
|
};
|
|
29
61
|
}
|
|
30
|
-
exports.filterInOut = filterInOut;
|
|
31
62
|
/**
|
|
32
63
|
* Finds and removes first instance of item from array
|
|
33
64
|
* tested V
|
|
@@ -36,7 +67,6 @@ function removeItemFromArray(array, item) {
|
|
|
36
67
|
const index = array.indexOf(item);
|
|
37
68
|
return removeFromArrayByIndex(array, index);
|
|
38
69
|
}
|
|
39
|
-
exports.removeItemFromArray = removeItemFromArray;
|
|
40
70
|
/**
|
|
41
71
|
* Removes the first item answering the condition given from array in place
|
|
42
72
|
* tested V
|
|
@@ -45,7 +75,6 @@ function removeFromArray(array, item) {
|
|
|
45
75
|
const index = array.findIndex(item);
|
|
46
76
|
return removeFromArrayByIndex(array, index);
|
|
47
77
|
}
|
|
48
|
-
exports.removeFromArray = removeFromArray;
|
|
49
78
|
/**
|
|
50
79
|
* Removes item from array in index
|
|
51
80
|
* tested V
|
|
@@ -55,7 +84,6 @@ function removeFromArrayByIndex(array, index) {
|
|
|
55
84
|
array.splice(index, 1);
|
|
56
85
|
return array;
|
|
57
86
|
}
|
|
58
|
-
exports.removeFromArrayByIndex = removeFromArrayByIndex;
|
|
59
87
|
function swapInArrayByIndex(array, i1, i2) {
|
|
60
88
|
if (i1 < 0 || i1 >= array.length)
|
|
61
89
|
throw new exceptions_1.BadImplementationException(`index i1 out of bounds: ${i1}`);
|
|
@@ -68,7 +96,6 @@ function swapInArrayByIndex(array, i1, i2) {
|
|
|
68
96
|
array[i2] = temp;
|
|
69
97
|
return array;
|
|
70
98
|
}
|
|
71
|
-
exports.swapInArrayByIndex = swapInArrayByIndex;
|
|
72
99
|
/**
|
|
73
100
|
* Deprecated
|
|
74
101
|
*/
|
|
@@ -76,12 +103,10 @@ function addItemToArray(array, item) {
|
|
|
76
103
|
array.push(item);
|
|
77
104
|
return array;
|
|
78
105
|
}
|
|
79
|
-
exports.addItemToArray = addItemToArray;
|
|
80
106
|
function addItemToArrayAtIndex(array, item, index) {
|
|
81
107
|
array.splice(index, 0, item);
|
|
82
108
|
return array;
|
|
83
109
|
}
|
|
84
|
-
exports.addItemToArrayAtIndex = addItemToArrayAtIndex;
|
|
85
110
|
function toggleElementInArray(array, item) {
|
|
86
111
|
const index = array.indexOf(item);
|
|
87
112
|
if (index > -1)
|
|
@@ -90,7 +115,6 @@ function toggleElementInArray(array, item) {
|
|
|
90
115
|
array.push(item);
|
|
91
116
|
return array;
|
|
92
117
|
}
|
|
93
|
-
exports.toggleElementInArray = toggleElementInArray;
|
|
94
118
|
/**
|
|
95
119
|
* Removes all items answering the condition given from array in place
|
|
96
120
|
*/
|
|
@@ -99,7 +123,6 @@ async function filterAsync(arr, filter) {
|
|
|
99
123
|
const boolArray = await Promise.all(arr.map(item => filter(item)));
|
|
100
124
|
return arr.filter((item, index) => boolArray[index]);
|
|
101
125
|
}
|
|
102
|
-
exports.filterAsync = filterAsync;
|
|
103
126
|
/**
|
|
104
127
|
* builds array that holds all items that are in array1 and array2
|
|
105
128
|
* problem with objects
|
|
@@ -107,7 +130,6 @@ exports.filterAsync = filterAsync;
|
|
|
107
130
|
function findDuplicates(array1, array2) {
|
|
108
131
|
return array1.filter(val => array2.indexOf(val) !== -1);
|
|
109
132
|
}
|
|
110
|
-
exports.findDuplicates = findDuplicates;
|
|
111
133
|
const defaultMapper = (item) => item;
|
|
112
134
|
/**
|
|
113
135
|
remove all duplicates in array
|
|
@@ -118,28 +140,24 @@ function filterDuplicates(source, mapper = defaultMapper) {
|
|
|
118
140
|
const uniqueKeys = new Set(source.map(mapper));
|
|
119
141
|
return source.filter(item => uniqueKeys.delete(mapper(item)));
|
|
120
142
|
}
|
|
121
|
-
exports.filterDuplicates = filterDuplicates;
|
|
122
143
|
/**
|
|
123
144
|
* filter array of all undefined and null
|
|
124
145
|
* */
|
|
125
146
|
function filterInstances(array) {
|
|
126
147
|
return ((array === null || array === void 0 ? void 0 : array.filter(item => (0, tools_1.exists)(item))) || []);
|
|
127
148
|
}
|
|
128
|
-
exports.filterInstances = filterInstances;
|
|
129
149
|
/**
|
|
130
150
|
* filter array of all falsy instances
|
|
131
151
|
* */
|
|
132
152
|
function filterFalsy(array) {
|
|
133
153
|
return ((array === null || array === void 0 ? void 0 : array.filter(item => !!item)) || []);
|
|
134
154
|
}
|
|
135
|
-
exports.filterFalsy = filterFalsy;
|
|
136
155
|
/**
|
|
137
156
|
* receives array and builds hashmap whom keys are decided via function and values are from array
|
|
138
157
|
* */
|
|
139
158
|
function arrayToMap(array, getKey, map = {}) {
|
|
140
159
|
return reduceToMap(array, getKey, item => item, map);
|
|
141
160
|
}
|
|
142
|
-
exports.arrayToMap = arrayToMap;
|
|
143
161
|
/**
|
|
144
162
|
* turns array into object that is similar to hashmap
|
|
145
163
|
*
|
|
@@ -155,7 +173,6 @@ function reduceToMap(array, keyResolver, mapper, map = {}) {
|
|
|
155
173
|
return toRet;
|
|
156
174
|
}, map);
|
|
157
175
|
}
|
|
158
|
-
exports.reduceToMap = reduceToMap;
|
|
159
176
|
/**
|
|
160
177
|
* sorts array
|
|
161
178
|
* */
|
|
@@ -178,7 +195,6 @@ function sortArray(array, map = i => i, invert = false) {
|
|
|
178
195
|
return sortArray(array, item => item[key]);
|
|
179
196
|
}, array);
|
|
180
197
|
}
|
|
181
|
-
exports.sortArray = sortArray;
|
|
182
198
|
/**
|
|
183
199
|
* "splits" array into given size of chunks and then does "action" on chunk and return to array of actions on chunks +-
|
|
184
200
|
* */
|
|
@@ -194,7 +210,6 @@ async function batchAction(arr, chunk, action) {
|
|
|
194
210
|
}
|
|
195
211
|
return result;
|
|
196
212
|
}
|
|
197
|
-
exports.batchAction = batchAction;
|
|
198
213
|
/**
|
|
199
214
|
* Processes an array of promise-returning tasks sequentially.
|
|
200
215
|
*
|
|
@@ -220,7 +235,6 @@ async function Promise_all_sequentially(promises) {
|
|
|
220
235
|
}
|
|
221
236
|
return results;
|
|
222
237
|
}
|
|
223
|
-
exports.Promise_all_sequentially = Promise_all_sequentially;
|
|
224
238
|
async function batchActionParallel(arr, chunk, action) {
|
|
225
239
|
const promises = [];
|
|
226
240
|
for (let i = 0, j = arr.length; i < j; i += chunk) {
|
|
@@ -238,7 +252,6 @@ async function batchActionParallel(arr, chunk, action) {
|
|
|
238
252
|
}
|
|
239
253
|
return toRet;
|
|
240
254
|
}
|
|
241
|
-
exports.batchActionParallel = batchActionParallel;
|
|
242
255
|
/**
|
|
243
256
|
* Returns a flat array from an array of arrays.
|
|
244
257
|
* @param arr An array that is potentially a matrix
|
|
@@ -256,11 +269,9 @@ function flatArray(arr, result = []) {
|
|
|
256
269
|
}
|
|
257
270
|
return result;
|
|
258
271
|
}
|
|
259
|
-
exports.flatArray = flatArray;
|
|
260
272
|
function filterFlatInstances(arr, result = []) {
|
|
261
273
|
return filterInstances(flatArray(arr, result));
|
|
262
274
|
}
|
|
263
|
-
exports.filterFlatInstances = filterFlatInstances;
|
|
264
275
|
function groupArrayBy(arr, mapper) {
|
|
265
276
|
const map = arr.reduce((agg, item, index) => {
|
|
266
277
|
const key = mapper(item, index);
|
|
@@ -269,7 +280,6 @@ function groupArrayBy(arr, mapper) {
|
|
|
269
280
|
}, {});
|
|
270
281
|
return (0, object_tools_1._keys)(map).map(key => ({ key, values: map[key] }));
|
|
271
282
|
}
|
|
272
|
-
exports.groupArrayBy = groupArrayBy;
|
|
273
283
|
function toggleInArray(arr, item, mapper = item => item) {
|
|
274
284
|
const index = arr.findIndex(_item => mapper(_item) === mapper(item));
|
|
275
285
|
if (index !== -1)
|
|
@@ -277,33 +287,26 @@ function toggleInArray(arr, item, mapper = item => item) {
|
|
|
277
287
|
else
|
|
278
288
|
arr.push(item);
|
|
279
289
|
}
|
|
280
|
-
exports.toggleInArray = toggleInArray;
|
|
281
290
|
function generateArray(length, mapper = i => i) {
|
|
282
291
|
return Array.from({ length }).map((e, i) => mapper(i));
|
|
283
292
|
}
|
|
284
|
-
exports.generateArray = generateArray;
|
|
285
293
|
function asArray(toBeArray) {
|
|
286
294
|
return Array.isArray(toBeArray) ? toBeArray : [toBeArray];
|
|
287
295
|
}
|
|
288
|
-
exports.asArray = asArray;
|
|
289
296
|
function asOptionalArray(toBeArray) {
|
|
290
297
|
if (!(0, tools_1.exists)(toBeArray))
|
|
291
298
|
return undefined;
|
|
292
299
|
return asArray(toBeArray);
|
|
293
300
|
}
|
|
294
|
-
exports.asOptionalArray = asOptionalArray;
|
|
295
301
|
function lastElement(array) {
|
|
296
302
|
return array === null || array === void 0 ? void 0 : array[(array === null || array === void 0 ? void 0 : array.length) - 1];
|
|
297
303
|
}
|
|
298
|
-
exports.lastElement = lastElement;
|
|
299
304
|
function firstElement(array) {
|
|
300
305
|
return array === null || array === void 0 ? void 0 : array[0];
|
|
301
306
|
}
|
|
302
|
-
exports.firstElement = firstElement;
|
|
303
307
|
function arrayIncludesAny(arr1, arr2) {
|
|
304
308
|
return arr1.some(item => arr2.includes(item));
|
|
305
309
|
}
|
|
306
|
-
exports.arrayIncludesAny = arrayIncludesAny;
|
|
307
310
|
/**
|
|
308
311
|
* Clear array instance and keep the same instance so save memory
|
|
309
312
|
* This function will take any array and clear it's content completely while keeping the same instance to save memory
|
|
@@ -312,7 +315,6 @@ exports.arrayIncludesAny = arrayIncludesAny;
|
|
|
312
315
|
function clearArrayInstance(arr) {
|
|
313
316
|
arr.length = 0;
|
|
314
317
|
}
|
|
315
|
-
exports.clearArrayInstance = clearArrayInstance;
|
|
316
318
|
/**
|
|
317
319
|
* Returns true if arr1 returns the entirety of arr2
|
|
318
320
|
* @param arr1
|
|
@@ -321,14 +323,11 @@ exports.clearArrayInstance = clearArrayInstance;
|
|
|
321
323
|
function arrayIncludesAll(arr1, arr2) {
|
|
322
324
|
return arr2.every(item => arr1.includes(item));
|
|
323
325
|
}
|
|
324
|
-
exports.arrayIncludesAll = arrayIncludesAll;
|
|
325
326
|
function getMax(arr, mapper = (item) => item) {
|
|
326
327
|
const sorted = sortArray(arr, mapper, true);
|
|
327
328
|
return sorted[0];
|
|
328
329
|
}
|
|
329
|
-
exports.getMax = getMax;
|
|
330
330
|
function getMin(arr, mapper = (item) => item) {
|
|
331
331
|
const sorted = sortArray(arr, mapper);
|
|
332
332
|
return sorted[0];
|
|
333
333
|
}
|
|
334
|
-
exports.getMin = getMin;
|
package/utils/crypto-tools.d.ts
CHANGED
package/utils/crypto-tools.js
CHANGED
|
@@ -17,19 +17,18 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.
|
|
20
|
+
exports.randomNumber = randomNumber;
|
|
21
|
+
exports.randomObject = randomObject;
|
|
22
|
+
exports.hashPasswordWithSalt = hashPasswordWithSalt;
|
|
21
23
|
const crypto_1 = require("crypto");
|
|
22
24
|
function randomNumber(range) {
|
|
23
25
|
return Math.floor(Math.random() * (range));
|
|
24
26
|
}
|
|
25
|
-
exports.randomNumber = randomNumber;
|
|
26
27
|
function randomObject(items) {
|
|
27
28
|
return items[randomNumber(items.length)];
|
|
28
29
|
}
|
|
29
|
-
exports.randomObject = randomObject;
|
|
30
30
|
function hashPasswordWithSalt(salt, password) {
|
|
31
31
|
return (0, crypto_1.createHmac)('sha512', salt)
|
|
32
32
|
.update(password)
|
|
33
33
|
.digest('hex');
|
|
34
34
|
}
|
|
35
|
-
exports.hashPasswordWithSalt = hashPasswordWithSalt;
|