@nu-art/ts-common 0.204.141 → 0.204.143
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.js +1 -2
- 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;
|
package/utils/date-time-tools.js
CHANGED
|
@@ -20,7 +20,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
20
20
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.
|
|
23
|
+
exports.DateTimeFormat_DDMMYYYY = exports.DateTimeFormat_yyyyMMDD = exports.DateTimeFormat_yyyyMMDDTHHmmss = exports.DateTimeFormat = exports.sleep = exports.Weekdays = exports.Format_YYYYMMDD_HHmmss = exports.Format_HHmmss_DDMMYYYY = exports.Month = exports.Year = exports.Week = exports.Day = exports.Hour = exports.Minute = exports.Second = void 0;
|
|
24
|
+
exports.timeout = timeout;
|
|
25
|
+
exports._setTimeout = _setTimeout;
|
|
26
|
+
exports._clearTimeout = _clearTimeout;
|
|
27
|
+
exports._setInterval = _setInterval;
|
|
28
|
+
exports._clearInterval = _clearInterval;
|
|
29
|
+
exports.auditBy = auditBy;
|
|
30
|
+
exports.currentTimeMillis = currentTimeMillis;
|
|
31
|
+
exports.specificTimeTodayMillis = specificTimeTodayMillis;
|
|
32
|
+
exports.currentLocalTimeMillis = currentLocalTimeMillis;
|
|
33
|
+
exports.currentTimeMillisWithTimeZone = currentTimeMillisWithTimeZone;
|
|
34
|
+
exports.createReadableTimestampObject = createReadableTimestampObject;
|
|
35
|
+
exports.formatTimestamp = formatTimestamp;
|
|
36
|
+
exports.parseTimeString = parseTimeString;
|
|
37
|
+
exports.normalizeTimestamp = normalizeTimestamp;
|
|
38
|
+
exports.isSameDay = isSameDay;
|
|
39
|
+
exports.deltaDays = deltaDays;
|
|
24
40
|
const moment_1 = __importDefault(require("moment"));
|
|
25
41
|
const moment_2 = require("moment");
|
|
26
42
|
exports.Second = 1000;
|
|
@@ -36,28 +52,23 @@ exports.Weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Fri
|
|
|
36
52
|
async function timeout(sleepMs) {
|
|
37
53
|
return new Promise(resolve => setTimeout(resolve, sleepMs, undefined));
|
|
38
54
|
}
|
|
39
|
-
exports.timeout = timeout;
|
|
40
55
|
exports.sleep = timeout;
|
|
41
56
|
function _setTimeout(handler, sleepMs = 0, ...args) {
|
|
42
57
|
return setTimeout(handler, sleepMs, ...args);
|
|
43
58
|
}
|
|
44
|
-
exports._setTimeout = _setTimeout;
|
|
45
59
|
function _clearTimeout(handlerId) {
|
|
46
60
|
if (!handlerId)
|
|
47
61
|
return;
|
|
48
62
|
return clearTimeout(handlerId);
|
|
49
63
|
}
|
|
50
|
-
exports._clearTimeout = _clearTimeout;
|
|
51
64
|
function _setInterval(handler, sleepMs = 0, ...args) {
|
|
52
65
|
return setInterval(handler, sleepMs, ...args);
|
|
53
66
|
}
|
|
54
|
-
exports._setInterval = _setInterval;
|
|
55
67
|
function _clearInterval(handlerId) {
|
|
56
68
|
if (!handlerId)
|
|
57
69
|
return;
|
|
58
70
|
return clearInterval(handlerId);
|
|
59
71
|
}
|
|
60
|
-
exports._clearInterval = _clearInterval;
|
|
61
72
|
/**
|
|
62
73
|
* @param comment @deprecated
|
|
63
74
|
*/
|
|
@@ -70,28 +81,23 @@ function auditBy(user, comment, timestamp = currentTimeMillis()) {
|
|
|
70
81
|
_auditBy.comment = comment;
|
|
71
82
|
return _auditBy;
|
|
72
83
|
}
|
|
73
|
-
exports.auditBy = auditBy;
|
|
74
84
|
function currentTimeMillis() {
|
|
75
85
|
return Date.now();
|
|
76
86
|
}
|
|
77
|
-
exports.currentTimeMillis = currentTimeMillis;
|
|
78
87
|
function specificTimeTodayMillis(hours, minutes) {
|
|
79
88
|
const date = new Date();
|
|
80
89
|
date.setHours(hours);
|
|
81
90
|
date.setMinutes(minutes);
|
|
82
91
|
return date.getTime();
|
|
83
92
|
}
|
|
84
|
-
exports.specificTimeTodayMillis = specificTimeTodayMillis;
|
|
85
93
|
function currentLocalTimeMillis() {
|
|
86
94
|
const date = new Date();
|
|
87
95
|
return date.getTime();
|
|
88
96
|
}
|
|
89
|
-
exports.currentLocalTimeMillis = currentLocalTimeMillis;
|
|
90
97
|
function currentTimeMillisWithTimeZone() {
|
|
91
98
|
const date = new Date();
|
|
92
99
|
return date.getTime() + date.getTimezoneOffset();
|
|
93
100
|
}
|
|
94
|
-
exports.currentTimeMillisWithTimeZone = currentTimeMillisWithTimeZone;
|
|
95
101
|
function createReadableTimestampObject(pattern = exports.Format_HHmmss_DDMMYYYY, timestamp = currentTimeMillis(), timezone) {
|
|
96
102
|
const timeObj = {
|
|
97
103
|
timestamp: timestamp,
|
|
@@ -101,7 +107,6 @@ function createReadableTimestampObject(pattern = exports.Format_HHmmss_DDMMYYYY,
|
|
|
101
107
|
timeObj.timezone = timezone;
|
|
102
108
|
return timeObj;
|
|
103
109
|
}
|
|
104
|
-
exports.createReadableTimestampObject = createReadableTimestampObject;
|
|
105
110
|
/**
|
|
106
111
|
* For detailed list of formats visit https://momentjs.com/docs/#/displaying/format/
|
|
107
112
|
*/
|
|
@@ -111,15 +116,12 @@ function formatTimestamp(pattern = exports.Format_HHmmss_DDMMYYYY, timestamp = c
|
|
|
111
116
|
m.utcOffset(-new Date().getTimezoneOffset());
|
|
112
117
|
return m.format(pattern);
|
|
113
118
|
}
|
|
114
|
-
exports.formatTimestamp = formatTimestamp;
|
|
115
119
|
function parseTimeString(timestamp, pattern = exports.Format_HHmmss_DDMMYYYY) {
|
|
116
120
|
return (0, moment_2.utc)(timestamp, pattern).valueOf();
|
|
117
121
|
}
|
|
118
|
-
exports.parseTimeString = parseTimeString;
|
|
119
122
|
function normalizeTimestamp(timestamp, pattern) {
|
|
120
123
|
return parseTimeString(formatTimestamp(pattern, timestamp), pattern);
|
|
121
124
|
}
|
|
122
|
-
exports.normalizeTimestamp = normalizeTimestamp;
|
|
123
125
|
const DateTimeFormat = (format) => {
|
|
124
126
|
return {
|
|
125
127
|
parse: (timestampAsString) => parseTimeString(timestampAsString, format),
|
|
@@ -133,7 +135,6 @@ exports.DateTimeFormat_DDMMYYYY = (0, exports.DateTimeFormat)('DD/MM/YYYY');
|
|
|
133
135
|
function isSameDay(date1, date2) {
|
|
134
136
|
return (0, moment_1.default)(date1).isSame(date2, 'day');
|
|
135
137
|
}
|
|
136
|
-
exports.isSameDay = isSameDay;
|
|
137
138
|
function deltaDays(d1, d2) {
|
|
138
139
|
const date1 = typeof d1 === 'number' ? new Date(d1) : d1;
|
|
139
140
|
const date2 = typeof d2 === 'number' ? new Date(d2) : d2;
|
|
@@ -148,4 +149,3 @@ function deltaDays(d1, d2) {
|
|
|
148
149
|
const date2Offset = new Date(date2.getTime() + (days * exports.Day));
|
|
149
150
|
return isSameDay(date1, date2Offset) ? days : days + 1;
|
|
150
151
|
}
|
|
151
|
-
exports.deltaDays = deltaDays;
|
package/utils/db-object-tools.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.KeysOfDB_Object = void 0;
|
|
4
|
+
exports.dbObjectToId = dbObjectToId;
|
|
5
|
+
exports.removeDBObjectKeys = removeDBObjectKeys;
|
|
6
|
+
exports.deleteKeysObject = deleteKeysObject;
|
|
7
|
+
exports.keepDBObjectKeys = keepDBObjectKeys;
|
|
8
|
+
exports.keepPartialObject = keepPartialObject;
|
|
4
9
|
const object_tools_1 = require("./object-tools");
|
|
5
10
|
const tools_1 = require("./tools");
|
|
6
11
|
exports.KeysOfDB_Object = ['_id', '_v', '__created', '__updated', '__metadata1'];
|
|
7
12
|
function dbObjectToId(i) {
|
|
8
13
|
return i._id;
|
|
9
14
|
}
|
|
10
|
-
exports.dbObjectToId = dbObjectToId;
|
|
11
15
|
function removeDBObjectKeys(instance) {
|
|
12
16
|
return deleteKeysObject(instance, exports.KeysOfDB_Object);
|
|
13
17
|
}
|
|
14
|
-
exports.removeDBObjectKeys = removeDBObjectKeys;
|
|
15
18
|
/**
|
|
16
19
|
* Returns a cloned object with the keys removed.
|
|
17
20
|
*/
|
|
@@ -20,11 +23,9 @@ function deleteKeysObject(instance, keysToRemove) {
|
|
|
20
23
|
keysToRemove.forEach(key => delete _instance[key]);
|
|
21
24
|
return _instance;
|
|
22
25
|
}
|
|
23
|
-
exports.deleteKeysObject = deleteKeysObject;
|
|
24
26
|
function keepDBObjectKeys(instance) {
|
|
25
27
|
return keepPartialObject(instance, exports.KeysOfDB_Object);
|
|
26
28
|
}
|
|
27
|
-
exports.keepDBObjectKeys = keepDBObjectKeys;
|
|
28
29
|
function keepPartialObject(instance, keys) {
|
|
29
30
|
return keys.reduce((objectToRet, key) => {
|
|
30
31
|
if ((0, tools_1.exists)(instance[key]))
|
|
@@ -32,4 +33,3 @@ function keepPartialObject(instance, keys) {
|
|
|
32
33
|
return objectToRet;
|
|
33
34
|
}, {});
|
|
34
35
|
}
|
|
35
|
-
exports.keepPartialObject = keepPartialObject;
|
package/utils/exception-tools.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isCustomException =
|
|
3
|
+
exports.isCustomException = isCustomException;
|
|
4
4
|
const exceptions_1 = require("../core/exceptions/exceptions");
|
|
5
5
|
const allExceptions = [
|
|
6
6
|
exceptions_1.Exception,
|
|
@@ -16,4 +16,3 @@ const allExceptions = [
|
|
|
16
16
|
function isCustomException(e) {
|
|
17
17
|
return allExceptions.some(exc => !!(0, exceptions_1.isErrorOfType)(e, exc));
|
|
18
18
|
}
|
|
19
|
-
exports.isCustomException = isCustomException;
|
package/utils/filter-tools.js
CHANGED
|
@@ -195,6 +195,7 @@ class Filter {
|
|
|
195
195
|
return this;
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
|
+
exports.Filter = Filter;
|
|
198
199
|
Filter.translateStringToRegexFilter = (filter, regexp) => {
|
|
199
200
|
filter = (filter || '').trim();
|
|
200
201
|
filter = filter.toLowerCase();
|
|
@@ -208,4 +209,3 @@ Filter.translateStringToRegexFilter = (filter, regexp) => {
|
|
|
208
209
|
filter.length === 0 ? filter = '.*?' : filter += '.*';
|
|
209
210
|
return new RegExp(filter);
|
|
210
211
|
};
|
|
211
|
-
exports.Filter = Filter;
|
package/utils/hash-tools.d.ts
CHANGED
package/utils/hash-tools.js
CHANGED
|
@@ -17,28 +17,29 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.
|
|
20
|
+
exports.md5 = md5;
|
|
21
|
+
exports.sha1 = sha1;
|
|
22
|
+
exports.sha256 = sha256;
|
|
23
|
+
exports.sha384 = sha384;
|
|
24
|
+
exports.sha512 = sha512;
|
|
25
|
+
exports.encode = encode;
|
|
26
|
+
exports.decode = decode;
|
|
21
27
|
const node_forge_1 = require("node-forge");
|
|
22
28
|
function md5(toBeConverted) {
|
|
23
29
|
return node_forge_1.md.md5.create().update(toBeConverted).digest().toHex().toLowerCase();
|
|
24
30
|
}
|
|
25
|
-
exports.md5 = md5;
|
|
26
31
|
function sha1(toBeConverted) {
|
|
27
32
|
return node_forge_1.md.sha1.create().update(toBeConverted).digest().toHex().toLowerCase();
|
|
28
33
|
}
|
|
29
|
-
exports.sha1 = sha1;
|
|
30
34
|
function sha256(toBeConverted) {
|
|
31
35
|
return node_forge_1.md.sha256.create().update(toBeConverted).digest().toHex().toLowerCase();
|
|
32
36
|
}
|
|
33
|
-
exports.sha256 = sha256;
|
|
34
37
|
function sha384(toBeConverted) {
|
|
35
38
|
return node_forge_1.md.sha384.create().update(toBeConverted).digest().toHex().toLowerCase();
|
|
36
39
|
}
|
|
37
|
-
exports.sha384 = sha384;
|
|
38
40
|
function sha512(toBeConverted) {
|
|
39
41
|
return node_forge_1.md.sha512.create().update(toBeConverted).digest().toHex().toLowerCase();
|
|
40
42
|
}
|
|
41
|
-
exports.sha512 = sha512;
|
|
42
43
|
function encode(data, encoding = "base64") {
|
|
43
44
|
let buffer;
|
|
44
45
|
if (Buffer.isBuffer(data))
|
|
@@ -49,8 +50,6 @@ function encode(data, encoding = "base64") {
|
|
|
49
50
|
buffer = Buffer.from(data.toString(), 'utf8');
|
|
50
51
|
return buffer.toString(encoding);
|
|
51
52
|
}
|
|
52
|
-
exports.encode = encode;
|
|
53
53
|
function decode(encoded, from = "base64", to = "utf8") {
|
|
54
54
|
return Buffer.from(encoded, from).toString(to);
|
|
55
55
|
}
|
|
56
|
-
exports.decode = decode;
|
package/utils/json-tools.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isValidJson = isValidJson;
|
|
4
|
+
exports.prettifyJson = prettifyJson;
|
|
4
5
|
const tools_1 = require("./tools");
|
|
5
6
|
function isValidJson(_string) {
|
|
6
7
|
try {
|
|
@@ -11,8 +12,6 @@ function isValidJson(_string) {
|
|
|
11
12
|
return false;
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
|
-
exports.isValidJson = isValidJson;
|
|
15
15
|
function prettifyJson(obj) {
|
|
16
16
|
return (0, tools_1.__stringify)(obj, true);
|
|
17
17
|
}
|
|
18
|
-
exports.prettifyJson = prettifyJson;
|
package/utils/merge-tools.js
CHANGED
|
@@ -17,7 +17,9 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.
|
|
20
|
+
exports.mergeObject = mergeObject;
|
|
21
|
+
exports.mergeArray = mergeArray;
|
|
22
|
+
exports.merge = merge;
|
|
21
23
|
const object_tools_1 = require("./object-tools");
|
|
22
24
|
const tools_1 = require("./tools");
|
|
23
25
|
const exceptions_1 = require("../core/exceptions/exceptions");
|
|
@@ -35,7 +37,6 @@ function mergeObject(original, override) {
|
|
|
35
37
|
return obj;
|
|
36
38
|
}, returnValue);
|
|
37
39
|
}
|
|
38
|
-
exports.mergeObject = mergeObject;
|
|
39
40
|
function mergeArray(original, override) {
|
|
40
41
|
if (original === override) {
|
|
41
42
|
return override;
|
|
@@ -57,7 +58,6 @@ function mergeArray(original, override) {
|
|
|
57
58
|
// });
|
|
58
59
|
return override;
|
|
59
60
|
}
|
|
60
|
-
exports.mergeArray = mergeArray;
|
|
61
61
|
function merge(original, override) {
|
|
62
62
|
if (!(0, tools_1.exists)(override))
|
|
63
63
|
return undefined;
|
|
@@ -71,4 +71,3 @@ function merge(original, override) {
|
|
|
71
71
|
return mergeObject(original || {}, override);
|
|
72
72
|
return override;
|
|
73
73
|
}
|
|
74
|
-
exports.merge = merge;
|
package/utils/object-tools.js
CHANGED
|
@@ -17,7 +17,17 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.
|
|
20
|
+
exports.getDotNotatedValue = getDotNotatedValue;
|
|
21
|
+
exports.deepClone = deepClone;
|
|
22
|
+
exports._keys = _keys;
|
|
23
|
+
exports._values = _values;
|
|
24
|
+
exports._setTypedProp = _setTypedProp;
|
|
25
|
+
exports.cloneArr = cloneArr;
|
|
26
|
+
exports.cloneObj = cloneObj;
|
|
27
|
+
exports.partialCompare = partialCompare;
|
|
28
|
+
exports.compare = compare;
|
|
29
|
+
exports.assert = assert;
|
|
30
|
+
exports.filterKeys = filterKeys;
|
|
21
31
|
const exceptions_1 = require("../core/exceptions/exceptions");
|
|
22
32
|
const array_tools_1 = require("./array-tools");
|
|
23
33
|
function getDotNotatedValue(key, dotNotatedObject) {
|
|
@@ -26,7 +36,6 @@ function getDotNotatedValue(key, dotNotatedObject) {
|
|
|
26
36
|
return value[_pathPart];
|
|
27
37
|
}, dotNotatedObject);
|
|
28
38
|
}
|
|
29
|
-
exports.getDotNotatedValue = getDotNotatedValue;
|
|
30
39
|
function deepClone(obj) {
|
|
31
40
|
if (typeof obj === 'string' || typeof obj === 'number' || typeof obj === 'boolean' || typeof obj === 'undefined' || obj === null)
|
|
32
41
|
return obj;
|
|
@@ -34,30 +43,24 @@ function deepClone(obj) {
|
|
|
34
43
|
return cloneArr(obj);
|
|
35
44
|
return cloneObj(obj);
|
|
36
45
|
}
|
|
37
|
-
exports.deepClone = deepClone;
|
|
38
46
|
function _keys(instance) {
|
|
39
47
|
return Object.keys(instance);
|
|
40
48
|
}
|
|
41
|
-
exports._keys = _keys;
|
|
42
49
|
function _values(object) {
|
|
43
50
|
return Object.values(object);
|
|
44
51
|
}
|
|
45
|
-
exports._values = _values;
|
|
46
52
|
function _setTypedProp(instance, key, value) {
|
|
47
53
|
instance[key] = value;
|
|
48
54
|
}
|
|
49
|
-
exports._setTypedProp = _setTypedProp;
|
|
50
55
|
function cloneArr(value) {
|
|
51
56
|
return value.map(a => deepClone(a));
|
|
52
57
|
}
|
|
53
|
-
exports.cloneArr = cloneArr;
|
|
54
58
|
function cloneObj(obj) {
|
|
55
59
|
return _keys(obj).reduce((carry, key) => {
|
|
56
60
|
carry[key] = deepClone(obj[key]);
|
|
57
61
|
return carry;
|
|
58
62
|
}, {});
|
|
59
63
|
}
|
|
60
|
-
exports.cloneObj = cloneObj;
|
|
61
64
|
function partialCompare(one, two, keysToFilterOut) {
|
|
62
65
|
one = deepClone(one);
|
|
63
66
|
two = deepClone(two);
|
|
@@ -67,7 +70,6 @@ function partialCompare(one, two, keysToFilterOut) {
|
|
|
67
70
|
});
|
|
68
71
|
return compare(one, two);
|
|
69
72
|
}
|
|
70
|
-
exports.partialCompare = partialCompare;
|
|
71
73
|
/**
|
|
72
74
|
* Returns true for equal.
|
|
73
75
|
*/
|
|
@@ -115,12 +117,10 @@ function compare(one, two, keys) {
|
|
|
115
117
|
}
|
|
116
118
|
return true;
|
|
117
119
|
}
|
|
118
|
-
exports.compare = compare;
|
|
119
120
|
function assert(message, expected, actual) {
|
|
120
121
|
if (!compare(expected, actual))
|
|
121
122
|
throw new exceptions_1.AssertionException(`Assertion Failed:\n -- ${message}\n -- Expected: ${JSON.stringify(expected)}\n -- Actual: ${JSON.stringify(actual)}\n\n`);
|
|
122
123
|
}
|
|
123
|
-
exports.assert = assert;
|
|
124
124
|
function filterKeys(obj, keys = _keys(obj), filter = (k) => obj[k] === undefined || obj[k] === null) {
|
|
125
125
|
if (typeof obj !== 'object' || obj === null) {
|
|
126
126
|
throw new exceptions_1.BadImplementationException('Passed parameter for "obj" must be an object');
|
|
@@ -131,4 +131,3 @@ function filterKeys(obj, keys = _keys(obj), filter = (k) => obj[k] === undefined
|
|
|
131
131
|
});
|
|
132
132
|
return obj;
|
|
133
133
|
}
|
|
134
|
-
exports.filterKeys = filterKeys;
|
package/utils/query-params.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.composeQueryParams = composeQueryParams;
|
|
4
|
+
exports.composeUrl = composeUrl;
|
|
4
5
|
function composeQueryParams(params = {}) {
|
|
5
6
|
return Object.keys(params).map((paramKey) => {
|
|
6
7
|
let param = params[paramKey];
|
|
@@ -11,7 +12,6 @@ function composeQueryParams(params = {}) {
|
|
|
11
12
|
return `${paramKey}=${encodeURIComponent(param)}`;
|
|
12
13
|
}).join('&');
|
|
13
14
|
}
|
|
14
|
-
exports.composeQueryParams = composeQueryParams;
|
|
15
15
|
function composeUrl(url, params = {}, hash = '') {
|
|
16
16
|
const queryAsEncodedString = composeQueryParams(params);
|
|
17
17
|
if (queryAsEncodedString.length)
|
|
@@ -20,4 +20,3 @@ function composeUrl(url, params = {}, hash = '') {
|
|
|
20
20
|
return `${url}${hash.startsWith('#') ? hash : `#${hash}`}`;
|
|
21
21
|
return url;
|
|
22
22
|
}
|
|
23
|
-
exports.composeUrl = composeUrl;
|
package/utils/random-tools.js
CHANGED
|
@@ -17,21 +17,21 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.
|
|
20
|
+
exports.generateHex = generateHex;
|
|
21
|
+
exports.generateUUID = generateUUID;
|
|
22
|
+
exports.generateShortURL = generateShortURL;
|
|
21
23
|
const crypto_1 = require("crypto");
|
|
22
24
|
function generateHex(length) {
|
|
23
25
|
return (0, crypto_1.randomBytes)(Math.ceil(length / 2))
|
|
24
26
|
.toString('hex')
|
|
25
27
|
.slice(0, length).toLowerCase();
|
|
26
28
|
}
|
|
27
|
-
exports.generateHex = generateHex;
|
|
28
29
|
function generateUUID() {
|
|
29
30
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
30
31
|
const r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
31
32
|
return v.toString(16);
|
|
32
33
|
});
|
|
33
34
|
}
|
|
34
|
-
exports.generateUUID = generateUUID;
|
|
35
35
|
/**
|
|
36
36
|
* generate 8 characters long string that is value for short url usage
|
|
37
37
|
*/
|
|
@@ -45,4 +45,3 @@ function generateShortURL() {
|
|
|
45
45
|
}
|
|
46
46
|
return result;
|
|
47
47
|
}
|
|
48
|
-
exports.generateShortURL = generateShortURL;
|
package/utils/string-tools.js
CHANGED
|
@@ -17,12 +17,23 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.
|
|
20
|
+
exports.padNumber = padNumber;
|
|
21
|
+
exports.stringToHashCode = stringToHashCode;
|
|
22
|
+
exports.escape_RegExp = escape_RegExp;
|
|
23
|
+
exports.maxSubstring = maxSubstring;
|
|
24
|
+
exports.getStringSize = getStringSize;
|
|
25
|
+
exports.stringFormat = stringFormat;
|
|
26
|
+
exports.replaceStringAt = replaceStringAt;
|
|
27
|
+
exports.capitalizeAllFirstLetters = capitalizeAllFirstLetters;
|
|
28
|
+
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
29
|
+
exports.createLevenshteinDistanceMatrix = createLevenshteinDistanceMatrix;
|
|
30
|
+
exports.levenshteinDistance = levenshteinDistance;
|
|
31
|
+
exports.normalizeString = normalizeString;
|
|
32
|
+
exports.convertUpperCamelCase = convertUpperCamelCase;
|
|
21
33
|
function padNumber(num, length) {
|
|
22
34
|
const _num = num.toString();
|
|
23
35
|
return _num.length < length ? padNumber('0' + _num, length) : _num;
|
|
24
36
|
}
|
|
25
|
-
exports.padNumber = padNumber;
|
|
26
37
|
function stringToHashCode(stringToHash) {
|
|
27
38
|
let hash = 0;
|
|
28
39
|
if (stringToHash.length === 0)
|
|
@@ -33,11 +44,9 @@ function stringToHashCode(stringToHash) {
|
|
|
33
44
|
}
|
|
34
45
|
return hash;
|
|
35
46
|
}
|
|
36
|
-
exports.stringToHashCode = stringToHashCode;
|
|
37
47
|
function escape_RegExp(string) {
|
|
38
48
|
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
|
|
39
49
|
}
|
|
40
|
-
exports.escape_RegExp = escape_RegExp;
|
|
41
50
|
function maxSubstring(string, maxBytes, direction = 'start') {
|
|
42
51
|
const encoder = new TextEncoder();
|
|
43
52
|
const decoder = new TextDecoder();
|
|
@@ -54,7 +63,6 @@ function maxSubstring(string, maxBytes, direction = 'start') {
|
|
|
54
63
|
}
|
|
55
64
|
return decoder.decode(slicedBytes);
|
|
56
65
|
}
|
|
57
|
-
exports.maxSubstring = maxSubstring;
|
|
58
66
|
/**
|
|
59
67
|
* Calculate the size of a string in the specified unit.
|
|
60
68
|
* @param str - The input string whose size is to be calculated.
|
|
@@ -77,19 +85,16 @@ function getStringSize(str, unit = 'KB') {
|
|
|
77
85
|
throw new Error('Invalid unit. Please specify "KB", "MB", or "GB".');
|
|
78
86
|
}
|
|
79
87
|
}
|
|
80
|
-
exports.getStringSize = getStringSize;
|
|
81
88
|
function stringFormat(input, params = []) {
|
|
82
89
|
return (params === null || params === void 0 ? void 0 : params.reduce((toRet, param, index) => {
|
|
83
90
|
return toRet.replace(new RegExp(`\\{${index}\\}`, 'g'), param);
|
|
84
91
|
}, input || '')) || input;
|
|
85
92
|
}
|
|
86
|
-
exports.stringFormat = stringFormat;
|
|
87
93
|
function replaceStringAt(origin, index, replacement) {
|
|
88
94
|
if (!(origin === null || origin === void 0 ? void 0 : origin.length) || !(replacement === null || replacement === void 0 ? void 0 : replacement.length))
|
|
89
95
|
return origin;
|
|
90
96
|
return origin.substring(0, index) + replacement + origin.substring(index + replacement.length);
|
|
91
97
|
}
|
|
92
|
-
exports.replaceStringAt = replaceStringAt;
|
|
93
98
|
function capitalizeAllFirstLetters(value) {
|
|
94
99
|
let resultString = value;
|
|
95
100
|
for (let i = 0; i < resultString.length; i++) {
|
|
@@ -98,11 +103,9 @@ function capitalizeAllFirstLetters(value) {
|
|
|
98
103
|
}
|
|
99
104
|
return resultString;
|
|
100
105
|
}
|
|
101
|
-
exports.capitalizeAllFirstLetters = capitalizeAllFirstLetters;
|
|
102
106
|
function capitalizeFirstLetter(value) {
|
|
103
107
|
return value.charAt(0).toUpperCase() + value.substr(1).toLowerCase();
|
|
104
108
|
}
|
|
105
|
-
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
106
109
|
function createLevenshteinDistanceMatrix(str1, str2) {
|
|
107
110
|
const len1 = str1.length;
|
|
108
111
|
const len2 = str2.length;
|
|
@@ -119,7 +122,6 @@ function createLevenshteinDistanceMatrix(str1, str2) {
|
|
|
119
122
|
matrix[i][j] = Math.min((matrix[i - 1][j]) + 1, (matrix[i][j - 1]) + 1, (matrix[i - 1][j - 1]) + (str1[i - 1] === str2[j - 1] ? 0 : 1));
|
|
120
123
|
return matrix;
|
|
121
124
|
}
|
|
122
|
-
exports.createLevenshteinDistanceMatrix = createLevenshteinDistanceMatrix;
|
|
123
125
|
function levenshteinDistance(str1, str2) {
|
|
124
126
|
//Quick exists
|
|
125
127
|
if (str1.length === 0)
|
|
@@ -131,12 +133,9 @@ function levenshteinDistance(str1, str2) {
|
|
|
131
133
|
//Distance between the strings should be at bottom right corner of the matrix
|
|
132
134
|
return matrix[str1.length][str2.length];
|
|
133
135
|
}
|
|
134
|
-
exports.levenshteinDistance = levenshteinDistance;
|
|
135
136
|
function normalizeString(string) {
|
|
136
137
|
return string.replace(/–/g, '-').replace(/\n/g, '').replace(/\s+/g, ' ').replace(/’/g, '\'').trim();
|
|
137
138
|
}
|
|
138
|
-
exports.normalizeString = normalizeString;
|
|
139
139
|
function convertUpperCamelCase(upperCamelCase, delimiter = ' ') {
|
|
140
140
|
return upperCamelCase.replace(/([a-z0-9])([A-Z])/g, `$1${delimiter}$2`);
|
|
141
141
|
}
|
|
142
|
-
exports.convertUpperCamelCase = convertUpperCamelCase;
|
package/utils/tools.js
CHANGED
|
@@ -17,12 +17,17 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.logicalXOR = exports.
|
|
20
|
+
exports.logicalXOR = exports.resolveFunctionOrValue = exports.resolveContent = exports.functionThatReturnsTrue = exports.functionThatReturnsFalse = exports.voidFunction = exports.EmptyArray = exports.EmptyObject = void 0;
|
|
21
|
+
exports.regexpCase = regexpCase;
|
|
22
|
+
exports.createFilterPattern = createFilterPattern;
|
|
23
|
+
exports.calculateJsonSizeMb = calculateJsonSizeMb;
|
|
24
|
+
exports.__stringify = __stringify;
|
|
25
|
+
exports.exists = exists;
|
|
26
|
+
exports.freeze = freeze;
|
|
21
27
|
const object_tools_1 = require("./object-tools");
|
|
22
28
|
function regexpCase(value, reg) {
|
|
23
29
|
return value.match(new RegExp(reg)) || { input: undefined };
|
|
24
30
|
}
|
|
25
|
-
exports.regexpCase = regexpCase;
|
|
26
31
|
function createFilterPattern(rawFilter) {
|
|
27
32
|
let filter = rawFilter || '';
|
|
28
33
|
filter = filter.trim();
|
|
@@ -31,12 +36,10 @@ function createFilterPattern(rawFilter) {
|
|
|
31
36
|
filter.length === 0 ? filter = '.*?' : filter += '.*';
|
|
32
37
|
return filter;
|
|
33
38
|
}
|
|
34
|
-
exports.createFilterPattern = createFilterPattern;
|
|
35
39
|
function calculateJsonSizeMb(data) {
|
|
36
40
|
const number = JSON.stringify(data).length / 1024 / 1024;
|
|
37
41
|
return Math.round(number * 100) / 100;
|
|
38
42
|
}
|
|
39
|
-
exports.calculateJsonSizeMb = calculateJsonSizeMb;
|
|
40
43
|
function __stringify(obj, pretty) {
|
|
41
44
|
if (!obj)
|
|
42
45
|
return '';
|
|
@@ -50,7 +53,6 @@ function __stringify(obj, pretty) {
|
|
|
50
53
|
return JSON.stringify(obj, null, 2);
|
|
51
54
|
return JSON.stringify(obj);
|
|
52
55
|
}
|
|
53
|
-
exports.__stringify = __stringify;
|
|
54
56
|
exports.EmptyObject = Object.freeze({});
|
|
55
57
|
exports.EmptyArray = Object.freeze([]);
|
|
56
58
|
exports.voidFunction = Object.freeze(async () => {
|
|
@@ -65,11 +67,9 @@ exports.resolveFunctionOrValue = exports.resolveContent;
|
|
|
65
67
|
function exists(item) {
|
|
66
68
|
return item !== undefined && item !== null;
|
|
67
69
|
}
|
|
68
|
-
exports.exists = exists;
|
|
69
70
|
function freeze(item) {
|
|
70
71
|
return Object.freeze(item);
|
|
71
72
|
}
|
|
72
|
-
exports.freeze = freeze;
|
|
73
73
|
const logicalXOR = (a, b) => {
|
|
74
74
|
return (a && !b) || (!a && b);
|
|
75
75
|
};
|
package/utils/version-tools.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.compareVersions =
|
|
20
|
+
exports.compareVersions = compareVersions;
|
|
21
21
|
const exceptions_1 = require("../core/exceptions/exceptions");
|
|
22
22
|
/**
|
|
23
23
|
*
|
|
@@ -47,4 +47,3 @@ function compareVersions(firstVersion, secondVersion) {
|
|
|
47
47
|
}
|
|
48
48
|
return 0;
|
|
49
49
|
}
|
|
50
|
-
exports.compareVersions = compareVersions;
|
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
import { InvalidResult, InvalidResultArray, InvalidResultObject, Validator, ValidatorTypeResolver } from './validator-core';
|
|
2
2
|
import { TimeRange } from '../utils/date-time-tools';
|
|
3
3
|
import { ArrayType, AuditBy, RangeTimestamp, TypedMap } from '../utils/types';
|
|
4
|
-
export declare const tsValidateDynamicObject: <T extends object>(valuesValidator: ValidatorTypeResolver<T[keyof T]>, keysValidator: ValidatorTypeResolver<string>, mandatory?: boolean) => (import("./validator-core").ValidatorImpl<any> | ((input?: T
|
|
4
|
+
export declare const tsValidateDynamicObject: <T extends object>(valuesValidator: ValidatorTypeResolver<T[keyof T]>, keysValidator: ValidatorTypeResolver<string>, mandatory?: boolean) => (import("./validator-core").ValidatorImpl<any> | ((input?: T) => InvalidResultObject<T> | undefined))[];
|
|
5
5
|
export declare const tsValidateUnion: <T>(validators: ValidatorTypeResolver<T>[], mandatory?: boolean) => (import("./validator-core").ValidatorImpl<any> | ((input?: any) => InvalidResultArray<T>[] | undefined))[];
|
|
6
|
-
export declare const tsValidateCustom: <T>(processor: (input?: T
|
|
6
|
+
export declare const tsValidateCustom: <T>(processor: (input?: T, parentInput?: any) => InvalidResult<T>, mandatory?: boolean) => Validator<T>[];
|
|
7
7
|
declare const typeFunc: (type: any) => "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
|
|
8
8
|
type types = ReturnType<typeof typeFunc>;
|
|
9
9
|
type validatorObject<T> = {
|
|
10
10
|
[k in types]?: ValidatorTypeResolver<T>;
|
|
11
11
|
};
|
|
12
|
-
export declare const tsValidateUnionV3: <T>(validatorObject: validatorObject<T>, mandatory?: boolean) => (import("./validator-core").ValidatorImpl<any> | ((input?: T
|
|
12
|
+
export declare const tsValidateUnionV3: <T>(validatorObject: validatorObject<T>, mandatory?: boolean) => (import("./validator-core").ValidatorImpl<any> | ((input?: T) => "Input does not match any of the possible types" | InvalidResult<T> | undefined))[];
|
|
13
13
|
export declare const tsValidateArray: <T extends any[], I extends ArrayType<T> = ArrayType<T>>(validator: ValidatorTypeResolver<I> | ValidatorTypeResolver<I>[], mandatory?: boolean, minimumLength?: number) => Validator<I[]>;
|
|
14
14
|
export declare const tsValidateString: (length?: number | [number, number], mandatory?: boolean) => Validator<string>;
|
|
15
15
|
export declare const tsValidateStringMinLength: (length: number, mandatory?: boolean) => Validator<string>;
|
|
16
16
|
export declare const tsValidateNumber: (mandatory?: boolean) => Validator<number>;
|
|
17
17
|
export declare const tsValidateEnum: (enumType: TypedMap<number | string>, mandatory?: boolean) => Validator<number | string>;
|
|
18
18
|
export declare const tsValidateBoolean: (mandatory?: boolean) => Validator<boolean>;
|
|
19
|
-
export declare const tsValidateValue: <T>(values:
|
|
19
|
+
export declare const tsValidateValue: <T>(values: T[] | ReadonlyArray<T>, mandatory?: boolean) => Validator<any>;
|
|
20
20
|
export declare const tsValidateIsInRange: (ranges: [number, number][], mandatory?: boolean) => Validator<number>;
|
|
21
21
|
export declare const tsValidateRange: (mandatory?: boolean) => Validator<[number, number] | undefined>;
|
|
22
22
|
export declare const tsValidateRegexp: (regexp: RegExp, mandatory?: boolean) => Validator<string>;
|
|
23
23
|
export declare const tsValidateTimestamp: (interval?: number, mandatory?: boolean) => Validator<number>;
|
|
24
24
|
export declare const tsValidateAudit: (range?: RangeTimestamp) => (audit?: AuditBy) => string | undefined;
|
|
25
25
|
export declare const tsValidateTimeRange: (mandatory?: boolean) => Validator<TimeRange>;
|
|
26
|
-
export declare const tsValidateNonMandatoryObject: <T extends object | undefined>(validator: ValidatorTypeResolver<T>) => (import("./validator-core").ValidatorImpl<any> | ((input?: T
|
|
27
|
-
export declare const tsValidateOptionalObject: <T extends object | undefined>(validator: ValidatorTypeResolver<T>) => (import("./validator-core").ValidatorImpl<any> | ((input?: T
|
|
26
|
+
export declare const tsValidateNonMandatoryObject: <T extends object | undefined>(validator: ValidatorTypeResolver<T>) => (import("./validator-core").ValidatorImpl<any> | ((input?: T) => InvalidResult<T> | undefined))[];
|
|
27
|
+
export declare const tsValidateOptionalObject: <T extends object | undefined>(validator: ValidatorTypeResolver<T>) => (import("./validator-core").ValidatorImpl<any> | ((input?: T) => InvalidResult<T> | undefined))[];
|
|
28
28
|
export declare const tsValidator_valueByKey: <T>(validatorObject: {
|
|
29
|
-
[k: string]:
|
|
29
|
+
[k: string]: ValidatorTypeResolver<any>;
|
|
30
30
|
}, prop?: string) => ValidatorTypeResolver<T>;
|
|
31
31
|
export declare const tsValidator_ArrayOfObjectsByKey: <T extends Object>(key: keyof T, validatorMap: {
|
|
32
32
|
[k: string]: ValidatorTypeResolver<T>;
|
|
@@ -26,5 +26,5 @@ export declare class ValidationException<T> extends CustomException {
|
|
|
26
26
|
}
|
|
27
27
|
export declare const tsValidateExists: (mandatory?: boolean) => ValidatorImpl<any>;
|
|
28
28
|
export declare const tsValidate: <T>(instance: T | undefined, _validator: ValidatorTypeResolver<T>, strict?: boolean) => InvalidResult<T> | undefined;
|
|
29
|
-
export declare const tsValidateResult: <T>(instance: T | undefined, _validator: ValidatorTypeResolver<T>, key?: keyof T
|
|
29
|
+
export declare const tsValidateResult: <T>(instance: T | undefined, _validator: ValidatorTypeResolver<T>, key?: keyof T, parentInstance?: any) => InvalidResult<T> | undefined;
|
|
30
30
|
export declare const tsValidateObject: <T extends object>(__validator: TypeValidator<T>, instance: T, path?: string) => InvalidResultObject<T> | undefined;
|