@nu-art/ts-common 0.204.134 → 0.204.136
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 +5 -4
- 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 +2 -0
- package/modules/CSVModuleV3.d.ts +1 -1
- package/modules/csv-serializer.js +2 -1
- package/package.json +1 -1
- package/replacer-v2/ReplacerV2.js +1 -1
- package/testing/consts.d.ts +3 -1
- package/testing/consts.js +2 -2
- package/tools/Replacer.js +1 -1
- package/tools/get-log-style.js +2 -1
- package/utils/array-tools.js +34 -33
- package/utils/crypto-tools.d.ts +1 -0
- package/utils/crypto-tools.js +4 -3
- package/utils/date-time-tools.js +17 -17
- package/utils/db-object-tools.js +6 -6
- package/utils/exception-tools.js +2 -1
- package/utils/filter-tools.js +1 -1
- package/utils/hash-tools.d.ts +1 -0
- package/utils/hash-tools.js +8 -7
- package/utils/json-tools.js +3 -2
- package/utils/merge-tools.js +4 -3
- package/utils/object-tools.js +12 -11
- package/utils/query-params.js +3 -2
- package/utils/random-tools.js +4 -3
- package/utils/string-tools.js +14 -13
- package/utils/tools.js +7 -7
- package/utils/version-tools.js +2 -1
- 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
|
-
exports.DebugFlag = DebugFlag;
|
|
60
59
|
DebugFlag.DefaultLogLevel = types_1.LogLevel.Info;
|
|
60
|
+
exports.DebugFlag = DebugFlag;
|
|
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
|
-
exports.DebugFlags = DebugFlags;
|
|
82
81
|
DebugFlags.instance = new DebugFlags();
|
|
82
|
+
exports.DebugFlags = 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 || (exports.ServerErrorSeverity = {}));
|
|
30
30
|
exports.ServerErrorSeverity_Ordinal = [
|
|
31
31
|
ServerErrorSeverity.Debug,
|
|
32
32
|
ServerErrorSeverity.Info,
|
|
@@ -20,8 +20,7 @@
|
|
|
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 = void 0;
|
|
24
|
-
exports.isErrorOfType = isErrorOfType;
|
|
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 = exports.isErrorOfType = void 0;
|
|
25
24
|
const utils_1 = require("../logger/utils");
|
|
26
25
|
/**
|
|
27
26
|
* # <ins>isErrorOfType</ins>
|
|
@@ -53,6 +52,7 @@ function isErrorOfType(e, _exceptionType) {
|
|
|
53
52
|
if ((_a = _e.isInstanceOf) === null || _a === void 0 ? void 0 : _a.call(_e, _exceptionType))
|
|
54
53
|
return e;
|
|
55
54
|
}
|
|
55
|
+
exports.isErrorOfType = isErrorOfType;
|
|
56
56
|
/**
|
|
57
57
|
* # CustomException
|
|
58
58
|
*
|
package/core/logger/LogClient.js
CHANGED
|
@@ -17,8 +17,7 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.DefaultLogPrefixComposer = exports._logger_logPrefixes = exports._logger_finalDate = exports._logger_timezoneOffset = exports.LogClient = void 0;
|
|
21
|
-
exports._logger_getPrefix = _logger_getPrefix;
|
|
20
|
+
exports.DefaultLogPrefixComposer = exports._logger_getPrefix = exports._logger_logPrefixes = exports._logger_finalDate = exports._logger_timezoneOffset = exports.LogClient = void 0;
|
|
22
21
|
const types_1 = require("./types");
|
|
23
22
|
class LogClient {
|
|
24
23
|
constructor() {
|
|
@@ -58,6 +57,7 @@ function _logger_getPrefix(level) {
|
|
|
58
57
|
return '---';
|
|
59
58
|
}
|
|
60
59
|
}
|
|
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
|
-
exports.Logger = Logger;
|
|
81
80
|
Logger.defaultFlagState = true;
|
|
81
|
+
exports.Logger = Logger;
|
|
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;
|
|
129
128
|
StaticLogger._DEBUG_FLAG = debug_flags_1.DebugFlags.createFlag('StaticLogger');
|
|
130
129
|
(() => {
|
|
131
130
|
StaticLogger._DEBUG_FLAG.enable(Logger.defaultFlagState);
|
|
132
131
|
})();
|
|
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 || (exports.LogLevel = {}));
|
|
29
29
|
exports.LogLevelOrdinal = [
|
|
30
30
|
LogLevel.Verbose,
|
|
31
31
|
LogLevel.Debug,
|
package/core/logger/utils.js
CHANGED
|
@@ -17,10 +17,7 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports._logger_logObject =
|
|
21
|
-
exports._logger_convertLogParamsToStrings = _logger_convertLogParamsToStrings;
|
|
22
|
-
exports._logger_logException = _logger_logException;
|
|
23
|
-
exports._logger_indentNewLineBy = _logger_indentNewLineBy;
|
|
20
|
+
exports._logger_indentNewLineBy = exports._logger_logException = exports._logger_convertLogParamsToStrings = exports._logger_logObject = void 0;
|
|
24
21
|
/**
|
|
25
22
|
* Created by TacB0sS on 3/16/17.
|
|
26
23
|
*/
|
|
@@ -29,6 +26,7 @@ const tools_1 = require("../../utils/tools");
|
|
|
29
26
|
function _logger_logObject(instance) {
|
|
30
27
|
return (0, tools_1.__stringify)(instance, true);
|
|
31
28
|
}
|
|
29
|
+
exports._logger_logObject = _logger_logObject;
|
|
32
30
|
function _logger_convertLogParamsToStrings(params) {
|
|
33
31
|
return params.map(toLog => {
|
|
34
32
|
if (typeof toLog === 'undefined')
|
|
@@ -45,6 +43,7 @@ function _logger_convertLogParamsToStrings(params) {
|
|
|
45
43
|
return (0, tools_1.__stringify)(toLog, true);
|
|
46
44
|
});
|
|
47
45
|
}
|
|
46
|
+
exports._logger_convertLogParamsToStrings = _logger_convertLogParamsToStrings;
|
|
48
47
|
function _logger_logException(error, fullStack = '') {
|
|
49
48
|
let toPrint = '';
|
|
50
49
|
let errorMessage;
|
|
@@ -72,6 +71,8 @@ function _logger_logException(error, fullStack = '') {
|
|
|
72
71
|
}
|
|
73
72
|
return toPrint;
|
|
74
73
|
}
|
|
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_1>(filter: (item: T_1, index: number, array: T_1[]) => boolean) => T_1;
|
|
10
|
+
some: <T_2>(filter: (item: T_2, index: number, array: T_2[]) => boolean) => T_2;
|
|
11
|
+
map: <T_3, S>(processor: (item: T_3, index: number, array: T_3[]) => S) => S[];
|
|
12
|
+
forEach: <T_4>(processor: (item: T_4, index: number, array: T_4[]) => void) => void;
|
|
13
|
+
includes: <T_5>(module: T_5) => 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_1>(filter: (item: T_1, index: number, array: T_1[]) => boolean) => T_1;
|
|
22
|
+
some: <T_2>(filter: (item: T_2, index: number, array: T_2[]) => boolean) => T_2;
|
|
23
|
+
map: <T_3, S>(processor: (item: T_3, index: number, array: T_3[]) => S) => S[];
|
|
24
|
+
forEach: <T_4>(processor: (item: T_4, index: number, array: T_4[]) => void) => void;
|
|
25
|
+
includes: <T_5>(module: T_5) => 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,8 +17,7 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.ModuleManager = exports.RuntimeVersion = exports.RuntimeModules = void 0;
|
|
21
|
-
exports.moduleResolver = moduleResolver;
|
|
20
|
+
exports.ModuleManager = exports.RuntimeVersion = exports.RuntimeModules = exports.moduleResolver = void 0;
|
|
22
21
|
const dispatcher_1 = require("./dispatcher");
|
|
23
22
|
const exceptions_1 = require("./exceptions/exceptions");
|
|
24
23
|
const Logger_1 = require("./logger/Logger");
|
|
@@ -28,6 +27,7 @@ const _modules = [];
|
|
|
28
27
|
function moduleResolver() {
|
|
29
28
|
return _modules;
|
|
30
29
|
}
|
|
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?: (storage: MemStorage) => T) => this;
|
|
14
|
+
setResolver: (resolver?: ((storage: MemStorage) => T) | undefined) => 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>) => 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> | undefined) => 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 = void 0;
|
|
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,3 +35,4 @@ 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;
|
|
19
18
|
ReplacerV2.Regexp_paramGroup = /\$\{(\{?.*?\}?)\}/g;
|
|
20
19
|
ReplacerV2.Regexp_param = /\$\{(\{?.*?\}?)\}/;
|
|
20
|
+
exports.ReplacerV2 = ReplacerV2;
|
package/testing/consts.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
/// <reference types="chai" />
|
|
2
|
+
/// <reference types="chai-as-promised" />
|
|
1
3
|
import { TestModel, TestSuite } from './types';
|
|
2
4
|
import { ModuleManager } from '../core/module-manager';
|
|
3
5
|
export declare class ModuleManagerTester extends ModuleManager {
|
|
4
6
|
constructor();
|
|
5
7
|
}
|
|
6
8
|
export declare function testSuite_RunTest<Input, ExpectedResult>(testSuit: TestSuite<Input, ExpectedResult>, testCase: TestModel<Input, ExpectedResult>): void;
|
|
7
|
-
export declare const testSuiteTester: <Input, ExpectedResult>(testSuit: TestSuite<Input, ExpectedResult>, ...testcases:
|
|
9
|
+
export declare const testSuiteTester: <Input, ExpectedResult>(testSuit: TestSuite<Input, ExpectedResult>, ...testcases: TestModel<Input, ExpectedResult>[]) => void;
|
|
8
10
|
export declare const expectFailAsync: (action: () => Promise<void>) => Promise<Chai.Assertion>;
|
package/testing/consts.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.expectFailAsync = exports.testSuiteTester = exports.ModuleManagerTester = void 0;
|
|
4
|
-
exports.testSuite_RunTest = testSuite_RunTest;
|
|
3
|
+
exports.expectFailAsync = exports.testSuiteTester = exports.testSuite_RunTest = exports.ModuleManagerTester = void 0;
|
|
5
4
|
const chai_1 = require("chai");
|
|
6
5
|
const module_manager_1 = require("../core/module-manager");
|
|
7
6
|
const tools_1 = require("../utils/tools");
|
|
@@ -15,6 +14,7 @@ exports.ModuleManagerTester = ModuleManagerTester;
|
|
|
15
14
|
function testSuite_RunTest(testSuit, testCase) {
|
|
16
15
|
it(testCase.description, () => testSuit.processor(testCase));
|
|
17
16
|
}
|
|
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;
|
|
140
139
|
Replacer.RuntimeParam = '__runtime';
|
|
141
140
|
Replacer.Indicator_RuntimeParam = '__';
|
|
142
141
|
Replacer.Regexp_paramGroup = /\$\{(\{?.*?\}?)\}/g;
|
|
143
142
|
Replacer.Regexp_param = /\$\{(\{?.*?\}?)\}/;
|
|
144
143
|
Replacer.Regexp_forLoopGroupStart = /\{\{foreach (.*?) in (.*?)\}\}/g;
|
|
145
144
|
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 = void 0;
|
|
21
21
|
const object_tools_1 = require("../utils/object-tools");
|
|
22
22
|
/**
|
|
23
23
|
* Returns a style string for console.log()
|
|
@@ -35,3 +35,4 @@ function getLogStyle(...styleObj) {
|
|
|
35
35
|
});
|
|
36
36
|
return style;
|
|
37
37
|
}
|
|
38
|
+
exports.getLogStyle = getLogStyle;
|
package/utils/array-tools.js
CHANGED
|
@@ -17,39 +17,7 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.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;
|
|
20
|
+
exports.getMin = exports.getMax = exports.arrayIncludesAll = exports.clearArrayInstance = exports.arrayIncludesAny = exports.firstElement = exports.lastElement = exports.asOptionalArray = exports.asArray = exports.generateArray = exports.toggleInArray = exports.groupArrayBy = exports.filterFlatInstances = exports.flatArray = exports.batchActionParallel = exports.Promise_all_sequentially = exports.batchAction = exports.sortArray = exports.reduceToMap = exports.arrayToMap = exports.filterFalsy = exports.filterInstances = exports.filterDuplicates = exports.findDuplicates = exports.filterAsync = exports.toggleElementInArray = exports.addItemToArrayAtIndex = exports.addItemToArray = exports.swapInArrayByIndex = exports.removeFromArrayByIndex = exports.removeFromArray = exports.removeItemFromArray = exports.filterInOut = void 0;
|
|
53
21
|
const tools_1 = require("./tools");
|
|
54
22
|
const object_tools_1 = require("./object-tools");
|
|
55
23
|
const exceptions_1 = require("../core/exceptions/exceptions");
|
|
@@ -59,6 +27,7 @@ function filterInOut(input, filter) {
|
|
|
59
27
|
filteredOut: input.filter((object) => !filter(object))
|
|
60
28
|
};
|
|
61
29
|
}
|
|
30
|
+
exports.filterInOut = filterInOut;
|
|
62
31
|
/**
|
|
63
32
|
* Finds and removes first instance of item from array
|
|
64
33
|
* tested V
|
|
@@ -67,6 +36,7 @@ function removeItemFromArray(array, item) {
|
|
|
67
36
|
const index = array.indexOf(item);
|
|
68
37
|
return removeFromArrayByIndex(array, index);
|
|
69
38
|
}
|
|
39
|
+
exports.removeItemFromArray = removeItemFromArray;
|
|
70
40
|
/**
|
|
71
41
|
* Removes the first item answering the condition given from array in place
|
|
72
42
|
* tested V
|
|
@@ -75,6 +45,7 @@ function removeFromArray(array, item) {
|
|
|
75
45
|
const index = array.findIndex(item);
|
|
76
46
|
return removeFromArrayByIndex(array, index);
|
|
77
47
|
}
|
|
48
|
+
exports.removeFromArray = removeFromArray;
|
|
78
49
|
/**
|
|
79
50
|
* Removes item from array in index
|
|
80
51
|
* tested V
|
|
@@ -84,6 +55,7 @@ function removeFromArrayByIndex(array, index) {
|
|
|
84
55
|
array.splice(index, 1);
|
|
85
56
|
return array;
|
|
86
57
|
}
|
|
58
|
+
exports.removeFromArrayByIndex = removeFromArrayByIndex;
|
|
87
59
|
function swapInArrayByIndex(array, i1, i2) {
|
|
88
60
|
if (i1 < 0 || i1 >= array.length)
|
|
89
61
|
throw new exceptions_1.BadImplementationException(`index i1 out of bounds: ${i1}`);
|
|
@@ -96,6 +68,7 @@ function swapInArrayByIndex(array, i1, i2) {
|
|
|
96
68
|
array[i2] = temp;
|
|
97
69
|
return array;
|
|
98
70
|
}
|
|
71
|
+
exports.swapInArrayByIndex = swapInArrayByIndex;
|
|
99
72
|
/**
|
|
100
73
|
* Deprecated
|
|
101
74
|
*/
|
|
@@ -103,10 +76,12 @@ function addItemToArray(array, item) {
|
|
|
103
76
|
array.push(item);
|
|
104
77
|
return array;
|
|
105
78
|
}
|
|
79
|
+
exports.addItemToArray = addItemToArray;
|
|
106
80
|
function addItemToArrayAtIndex(array, item, index) {
|
|
107
81
|
array.splice(index, 0, item);
|
|
108
82
|
return array;
|
|
109
83
|
}
|
|
84
|
+
exports.addItemToArrayAtIndex = addItemToArrayAtIndex;
|
|
110
85
|
function toggleElementInArray(array, item) {
|
|
111
86
|
const index = array.indexOf(item);
|
|
112
87
|
if (index > -1)
|
|
@@ -115,6 +90,7 @@ function toggleElementInArray(array, item) {
|
|
|
115
90
|
array.push(item);
|
|
116
91
|
return array;
|
|
117
92
|
}
|
|
93
|
+
exports.toggleElementInArray = toggleElementInArray;
|
|
118
94
|
/**
|
|
119
95
|
* Removes all items answering the condition given from array in place
|
|
120
96
|
*/
|
|
@@ -123,6 +99,7 @@ async function filterAsync(arr, filter) {
|
|
|
123
99
|
const boolArray = await Promise.all(arr.map(item => filter(item)));
|
|
124
100
|
return arr.filter((item, index) => boolArray[index]);
|
|
125
101
|
}
|
|
102
|
+
exports.filterAsync = filterAsync;
|
|
126
103
|
/**
|
|
127
104
|
* builds array that holds all items that are in array1 and array2
|
|
128
105
|
* problem with objects
|
|
@@ -130,6 +107,7 @@ async function filterAsync(arr, filter) {
|
|
|
130
107
|
function findDuplicates(array1, array2) {
|
|
131
108
|
return array1.filter(val => array2.indexOf(val) !== -1);
|
|
132
109
|
}
|
|
110
|
+
exports.findDuplicates = findDuplicates;
|
|
133
111
|
const defaultMapper = (item) => item;
|
|
134
112
|
/**
|
|
135
113
|
remove all duplicates in array
|
|
@@ -140,24 +118,28 @@ function filterDuplicates(source, mapper = defaultMapper) {
|
|
|
140
118
|
const uniqueKeys = new Set(source.map(mapper));
|
|
141
119
|
return source.filter(item => uniqueKeys.delete(mapper(item)));
|
|
142
120
|
}
|
|
121
|
+
exports.filterDuplicates = filterDuplicates;
|
|
143
122
|
/**
|
|
144
123
|
* filter array of all undefined and null
|
|
145
124
|
* */
|
|
146
125
|
function filterInstances(array) {
|
|
147
126
|
return ((array === null || array === void 0 ? void 0 : array.filter(item => (0, tools_1.exists)(item))) || []);
|
|
148
127
|
}
|
|
128
|
+
exports.filterInstances = filterInstances;
|
|
149
129
|
/**
|
|
150
130
|
* filter array of all falsy instances
|
|
151
131
|
* */
|
|
152
132
|
function filterFalsy(array) {
|
|
153
133
|
return ((array === null || array === void 0 ? void 0 : array.filter(item => !!item)) || []);
|
|
154
134
|
}
|
|
135
|
+
exports.filterFalsy = filterFalsy;
|
|
155
136
|
/**
|
|
156
137
|
* receives array and builds hashmap whom keys are decided via function and values are from array
|
|
157
138
|
* */
|
|
158
139
|
function arrayToMap(array, getKey, map = {}) {
|
|
159
140
|
return reduceToMap(array, getKey, item => item, map);
|
|
160
141
|
}
|
|
142
|
+
exports.arrayToMap = arrayToMap;
|
|
161
143
|
/**
|
|
162
144
|
* turns array into object that is similar to hashmap
|
|
163
145
|
*
|
|
@@ -173,6 +155,7 @@ function reduceToMap(array, keyResolver, mapper, map = {}) {
|
|
|
173
155
|
return toRet;
|
|
174
156
|
}, map);
|
|
175
157
|
}
|
|
158
|
+
exports.reduceToMap = reduceToMap;
|
|
176
159
|
/**
|
|
177
160
|
* sorts array
|
|
178
161
|
* */
|
|
@@ -195,6 +178,7 @@ function sortArray(array, map = i => i, invert = false) {
|
|
|
195
178
|
return sortArray(array, item => item[key]);
|
|
196
179
|
}, array);
|
|
197
180
|
}
|
|
181
|
+
exports.sortArray = sortArray;
|
|
198
182
|
/**
|
|
199
183
|
* "splits" array into given size of chunks and then does "action" on chunk and return to array of actions on chunks +-
|
|
200
184
|
* */
|
|
@@ -210,6 +194,7 @@ async function batchAction(arr, chunk, action) {
|
|
|
210
194
|
}
|
|
211
195
|
return result;
|
|
212
196
|
}
|
|
197
|
+
exports.batchAction = batchAction;
|
|
213
198
|
/**
|
|
214
199
|
* Processes an array of promise-returning tasks sequentially.
|
|
215
200
|
*
|
|
@@ -235,6 +220,7 @@ async function Promise_all_sequentially(promises) {
|
|
|
235
220
|
}
|
|
236
221
|
return results;
|
|
237
222
|
}
|
|
223
|
+
exports.Promise_all_sequentially = Promise_all_sequentially;
|
|
238
224
|
async function batchActionParallel(arr, chunk, action) {
|
|
239
225
|
const promises = [];
|
|
240
226
|
for (let i = 0, j = arr.length; i < j; i += chunk) {
|
|
@@ -252,6 +238,7 @@ async function batchActionParallel(arr, chunk, action) {
|
|
|
252
238
|
}
|
|
253
239
|
return toRet;
|
|
254
240
|
}
|
|
241
|
+
exports.batchActionParallel = batchActionParallel;
|
|
255
242
|
/**
|
|
256
243
|
* Returns a flat array from an array of arrays.
|
|
257
244
|
* @param arr An array that is potentially a matrix
|
|
@@ -269,9 +256,11 @@ function flatArray(arr, result = []) {
|
|
|
269
256
|
}
|
|
270
257
|
return result;
|
|
271
258
|
}
|
|
259
|
+
exports.flatArray = flatArray;
|
|
272
260
|
function filterFlatInstances(arr, result = []) {
|
|
273
261
|
return filterInstances(flatArray(arr, result));
|
|
274
262
|
}
|
|
263
|
+
exports.filterFlatInstances = filterFlatInstances;
|
|
275
264
|
function groupArrayBy(arr, mapper) {
|
|
276
265
|
const map = arr.reduce((agg, item, index) => {
|
|
277
266
|
const key = mapper(item, index);
|
|
@@ -280,6 +269,7 @@ function groupArrayBy(arr, mapper) {
|
|
|
280
269
|
}, {});
|
|
281
270
|
return (0, object_tools_1._keys)(map).map(key => ({ key, values: map[key] }));
|
|
282
271
|
}
|
|
272
|
+
exports.groupArrayBy = groupArrayBy;
|
|
283
273
|
function toggleInArray(arr, item, mapper = item => item) {
|
|
284
274
|
const index = arr.findIndex(_item => mapper(_item) === mapper(item));
|
|
285
275
|
if (index !== -1)
|
|
@@ -287,26 +277,33 @@ function toggleInArray(arr, item, mapper = item => item) {
|
|
|
287
277
|
else
|
|
288
278
|
arr.push(item);
|
|
289
279
|
}
|
|
280
|
+
exports.toggleInArray = toggleInArray;
|
|
290
281
|
function generateArray(length, mapper = i => i) {
|
|
291
282
|
return Array.from({ length }).map((e, i) => mapper(i));
|
|
292
283
|
}
|
|
284
|
+
exports.generateArray = generateArray;
|
|
293
285
|
function asArray(toBeArray) {
|
|
294
286
|
return Array.isArray(toBeArray) ? toBeArray : [toBeArray];
|
|
295
287
|
}
|
|
288
|
+
exports.asArray = asArray;
|
|
296
289
|
function asOptionalArray(toBeArray) {
|
|
297
290
|
if (!(0, tools_1.exists)(toBeArray))
|
|
298
291
|
return undefined;
|
|
299
292
|
return asArray(toBeArray);
|
|
300
293
|
}
|
|
294
|
+
exports.asOptionalArray = asOptionalArray;
|
|
301
295
|
function lastElement(array) {
|
|
302
296
|
return array === null || array === void 0 ? void 0 : array[(array === null || array === void 0 ? void 0 : array.length) - 1];
|
|
303
297
|
}
|
|
298
|
+
exports.lastElement = lastElement;
|
|
304
299
|
function firstElement(array) {
|
|
305
300
|
return array === null || array === void 0 ? void 0 : array[0];
|
|
306
301
|
}
|
|
302
|
+
exports.firstElement = firstElement;
|
|
307
303
|
function arrayIncludesAny(arr1, arr2) {
|
|
308
304
|
return arr1.some(item => arr2.includes(item));
|
|
309
305
|
}
|
|
306
|
+
exports.arrayIncludesAny = arrayIncludesAny;
|
|
310
307
|
/**
|
|
311
308
|
* Clear array instance and keep the same instance so save memory
|
|
312
309
|
* This function will take any array and clear it's content completely while keeping the same instance to save memory
|
|
@@ -315,6 +312,7 @@ function arrayIncludesAny(arr1, arr2) {
|
|
|
315
312
|
function clearArrayInstance(arr) {
|
|
316
313
|
arr.length = 0;
|
|
317
314
|
}
|
|
315
|
+
exports.clearArrayInstance = clearArrayInstance;
|
|
318
316
|
/**
|
|
319
317
|
* Returns true if arr1 returns the entirety of arr2
|
|
320
318
|
* @param arr1
|
|
@@ -323,11 +321,14 @@ function clearArrayInstance(arr) {
|
|
|
323
321
|
function arrayIncludesAll(arr1, arr2) {
|
|
324
322
|
return arr2.every(item => arr1.includes(item));
|
|
325
323
|
}
|
|
324
|
+
exports.arrayIncludesAll = arrayIncludesAll;
|
|
326
325
|
function getMax(arr, mapper = (item) => item) {
|
|
327
326
|
const sorted = sortArray(arr, mapper, true);
|
|
328
327
|
return sorted[0];
|
|
329
328
|
}
|
|
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,18 +17,19 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.randomNumber =
|
|
21
|
-
exports.randomObject = randomObject;
|
|
22
|
-
exports.hashPasswordWithSalt = hashPasswordWithSalt;
|
|
20
|
+
exports.hashPasswordWithSalt = exports.randomObject = exports.randomNumber = void 0;
|
|
23
21
|
const crypto_1 = require("crypto");
|
|
24
22
|
function randomNumber(range) {
|
|
25
23
|
return Math.floor(Math.random() * (range));
|
|
26
24
|
}
|
|
25
|
+
exports.randomNumber = randomNumber;
|
|
27
26
|
function randomObject(items) {
|
|
28
27
|
return items[randomNumber(items.length)];
|
|
29
28
|
}
|
|
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,23 +20,7 @@ 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.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;
|
|
23
|
+
exports.deltaDays = exports.isSameDay = exports.DateTimeFormat_DDMMYYYY = exports.DateTimeFormat_yyyyMMDD = exports.DateTimeFormat_yyyyMMDDTHHmmss = exports.DateTimeFormat = exports.normalizeTimestamp = exports.parseTimeString = exports.formatTimestamp = exports.createReadableTimestampObject = exports.currentTimeMillisWithTimeZone = exports.currentLocalTimeMillis = exports.specificTimeTodayMillis = exports.currentTimeMillis = exports.auditBy = exports._clearInterval = exports._setInterval = exports._clearTimeout = exports._setTimeout = exports.sleep = exports.timeout = 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;
|
|
40
24
|
const moment_1 = __importDefault(require("moment"));
|
|
41
25
|
const moment_2 = require("moment");
|
|
42
26
|
exports.Second = 1000;
|
|
@@ -52,23 +36,28 @@ exports.Weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Fri
|
|
|
52
36
|
async function timeout(sleepMs) {
|
|
53
37
|
return new Promise(resolve => setTimeout(resolve, sleepMs, undefined));
|
|
54
38
|
}
|
|
39
|
+
exports.timeout = timeout;
|
|
55
40
|
exports.sleep = timeout;
|
|
56
41
|
function _setTimeout(handler, sleepMs = 0, ...args) {
|
|
57
42
|
return setTimeout(handler, sleepMs, ...args);
|
|
58
43
|
}
|
|
44
|
+
exports._setTimeout = _setTimeout;
|
|
59
45
|
function _clearTimeout(handlerId) {
|
|
60
46
|
if (!handlerId)
|
|
61
47
|
return;
|
|
62
48
|
return clearTimeout(handlerId);
|
|
63
49
|
}
|
|
50
|
+
exports._clearTimeout = _clearTimeout;
|
|
64
51
|
function _setInterval(handler, sleepMs = 0, ...args) {
|
|
65
52
|
return setInterval(handler, sleepMs, ...args);
|
|
66
53
|
}
|
|
54
|
+
exports._setInterval = _setInterval;
|
|
67
55
|
function _clearInterval(handlerId) {
|
|
68
56
|
if (!handlerId)
|
|
69
57
|
return;
|
|
70
58
|
return clearInterval(handlerId);
|
|
71
59
|
}
|
|
60
|
+
exports._clearInterval = _clearInterval;
|
|
72
61
|
/**
|
|
73
62
|
* @param comment @deprecated
|
|
74
63
|
*/
|
|
@@ -81,23 +70,28 @@ function auditBy(user, comment, timestamp = currentTimeMillis()) {
|
|
|
81
70
|
_auditBy.comment = comment;
|
|
82
71
|
return _auditBy;
|
|
83
72
|
}
|
|
73
|
+
exports.auditBy = auditBy;
|
|
84
74
|
function currentTimeMillis() {
|
|
85
75
|
return Date.now();
|
|
86
76
|
}
|
|
77
|
+
exports.currentTimeMillis = currentTimeMillis;
|
|
87
78
|
function specificTimeTodayMillis(hours, minutes) {
|
|
88
79
|
const date = new Date();
|
|
89
80
|
date.setHours(hours);
|
|
90
81
|
date.setMinutes(minutes);
|
|
91
82
|
return date.getTime();
|
|
92
83
|
}
|
|
84
|
+
exports.specificTimeTodayMillis = specificTimeTodayMillis;
|
|
93
85
|
function currentLocalTimeMillis() {
|
|
94
86
|
const date = new Date();
|
|
95
87
|
return date.getTime();
|
|
96
88
|
}
|
|
89
|
+
exports.currentLocalTimeMillis = currentLocalTimeMillis;
|
|
97
90
|
function currentTimeMillisWithTimeZone() {
|
|
98
91
|
const date = new Date();
|
|
99
92
|
return date.getTime() + date.getTimezoneOffset();
|
|
100
93
|
}
|
|
94
|
+
exports.currentTimeMillisWithTimeZone = currentTimeMillisWithTimeZone;
|
|
101
95
|
function createReadableTimestampObject(pattern = exports.Format_HHmmss_DDMMYYYY, timestamp = currentTimeMillis(), timezone) {
|
|
102
96
|
const timeObj = {
|
|
103
97
|
timestamp: timestamp,
|
|
@@ -107,6 +101,7 @@ function createReadableTimestampObject(pattern = exports.Format_HHmmss_DDMMYYYY,
|
|
|
107
101
|
timeObj.timezone = timezone;
|
|
108
102
|
return timeObj;
|
|
109
103
|
}
|
|
104
|
+
exports.createReadableTimestampObject = createReadableTimestampObject;
|
|
110
105
|
/**
|
|
111
106
|
* For detailed list of formats visit https://momentjs.com/docs/#/displaying/format/
|
|
112
107
|
*/
|
|
@@ -116,12 +111,15 @@ function formatTimestamp(pattern = exports.Format_HHmmss_DDMMYYYY, timestamp = c
|
|
|
116
111
|
m.utcOffset(-new Date().getTimezoneOffset());
|
|
117
112
|
return m.format(pattern);
|
|
118
113
|
}
|
|
114
|
+
exports.formatTimestamp = formatTimestamp;
|
|
119
115
|
function parseTimeString(timestamp, pattern = exports.Format_HHmmss_DDMMYYYY) {
|
|
120
116
|
return (0, moment_2.utc)(timestamp, pattern).valueOf();
|
|
121
117
|
}
|
|
118
|
+
exports.parseTimeString = parseTimeString;
|
|
122
119
|
function normalizeTimestamp(timestamp, pattern) {
|
|
123
120
|
return parseTimeString(formatTimestamp(pattern, timestamp), pattern);
|
|
124
121
|
}
|
|
122
|
+
exports.normalizeTimestamp = normalizeTimestamp;
|
|
125
123
|
const DateTimeFormat = (format) => {
|
|
126
124
|
return {
|
|
127
125
|
parse: (timestampAsString) => parseTimeString(timestampAsString, format),
|
|
@@ -135,6 +133,7 @@ exports.DateTimeFormat_DDMMYYYY = (0, exports.DateTimeFormat)('DD/MM/YYYY');
|
|
|
135
133
|
function isSameDay(date1, date2) {
|
|
136
134
|
return (0, moment_1.default)(date1).isSame(date2, 'day');
|
|
137
135
|
}
|
|
136
|
+
exports.isSameDay = isSameDay;
|
|
138
137
|
function deltaDays(d1, d2) {
|
|
139
138
|
const date1 = typeof d1 === 'number' ? new Date(d1) : d1;
|
|
140
139
|
const date2 = typeof d2 === 'number' ? new Date(d2) : d2;
|
|
@@ -149,3 +148,4 @@ function deltaDays(d1, d2) {
|
|
|
149
148
|
const date2Offset = new Date(date2.getTime() + (days * exports.Day));
|
|
150
149
|
return isSameDay(date1, date2Offset) ? days : days + 1;
|
|
151
150
|
}
|
|
151
|
+
exports.deltaDays = deltaDays;
|
package/utils/db-object-tools.js
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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;
|
|
3
|
+
exports.keepPartialObject = exports.keepDBObjectKeys = exports.deleteKeysObject = exports.removeDBObjectKeys = exports.dbObjectToId = exports.KeysOfDB_Object = void 0;
|
|
9
4
|
const object_tools_1 = require("./object-tools");
|
|
10
5
|
const tools_1 = require("./tools");
|
|
11
6
|
exports.KeysOfDB_Object = ['_id', '_v', '__created', '__updated', '__metadata1'];
|
|
12
7
|
function dbObjectToId(i) {
|
|
13
8
|
return i._id;
|
|
14
9
|
}
|
|
10
|
+
exports.dbObjectToId = dbObjectToId;
|
|
15
11
|
function removeDBObjectKeys(instance) {
|
|
16
12
|
return deleteKeysObject(instance, exports.KeysOfDB_Object);
|
|
17
13
|
}
|
|
14
|
+
exports.removeDBObjectKeys = removeDBObjectKeys;
|
|
18
15
|
/**
|
|
19
16
|
* Returns a cloned object with the keys removed.
|
|
20
17
|
*/
|
|
@@ -23,9 +20,11 @@ function deleteKeysObject(instance, keysToRemove) {
|
|
|
23
20
|
keysToRemove.forEach(key => delete _instance[key]);
|
|
24
21
|
return _instance;
|
|
25
22
|
}
|
|
23
|
+
exports.deleteKeysObject = deleteKeysObject;
|
|
26
24
|
function keepDBObjectKeys(instance) {
|
|
27
25
|
return keepPartialObject(instance, exports.KeysOfDB_Object);
|
|
28
26
|
}
|
|
27
|
+
exports.keepDBObjectKeys = keepDBObjectKeys;
|
|
29
28
|
function keepPartialObject(instance, keys) {
|
|
30
29
|
return keys.reduce((objectToRet, key) => {
|
|
31
30
|
if ((0, tools_1.exists)(instance[key]))
|
|
@@ -33,3 +32,4 @@ function keepPartialObject(instance, keys) {
|
|
|
33
32
|
return objectToRet;
|
|
34
33
|
}, {});
|
|
35
34
|
}
|
|
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 = void 0;
|
|
4
4
|
const exceptions_1 = require("../core/exceptions/exceptions");
|
|
5
5
|
const allExceptions = [
|
|
6
6
|
exceptions_1.Exception,
|
|
@@ -16,3 +16,4 @@ 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,7 +195,6 @@ class Filter {
|
|
|
195
195
|
return this;
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
|
-
exports.Filter = Filter;
|
|
199
198
|
Filter.translateStringToRegexFilter = (filter, regexp) => {
|
|
200
199
|
filter = (filter || '').trim();
|
|
201
200
|
filter = filter.toLowerCase();
|
|
@@ -209,3 +208,4 @@ Filter.translateStringToRegexFilter = (filter, regexp) => {
|
|
|
209
208
|
filter.length === 0 ? filter = '.*?' : filter += '.*';
|
|
210
209
|
return new RegExp(filter);
|
|
211
210
|
};
|
|
211
|
+
exports.Filter = Filter;
|
package/utils/hash-tools.d.ts
CHANGED
package/utils/hash-tools.js
CHANGED
|
@@ -17,29 +17,28 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.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;
|
|
20
|
+
exports.decode = exports.encode = exports.sha512 = exports.sha384 = exports.sha256 = exports.sha1 = exports.md5 = void 0;
|
|
27
21
|
const node_forge_1 = require("node-forge");
|
|
28
22
|
function md5(toBeConverted) {
|
|
29
23
|
return node_forge_1.md.md5.create().update(toBeConverted).digest().toHex().toLowerCase();
|
|
30
24
|
}
|
|
25
|
+
exports.md5 = md5;
|
|
31
26
|
function sha1(toBeConverted) {
|
|
32
27
|
return node_forge_1.md.sha1.create().update(toBeConverted).digest().toHex().toLowerCase();
|
|
33
28
|
}
|
|
29
|
+
exports.sha1 = sha1;
|
|
34
30
|
function sha256(toBeConverted) {
|
|
35
31
|
return node_forge_1.md.sha256.create().update(toBeConverted).digest().toHex().toLowerCase();
|
|
36
32
|
}
|
|
33
|
+
exports.sha256 = sha256;
|
|
37
34
|
function sha384(toBeConverted) {
|
|
38
35
|
return node_forge_1.md.sha384.create().update(toBeConverted).digest().toHex().toLowerCase();
|
|
39
36
|
}
|
|
37
|
+
exports.sha384 = sha384;
|
|
40
38
|
function sha512(toBeConverted) {
|
|
41
39
|
return node_forge_1.md.sha512.create().update(toBeConverted).digest().toHex().toLowerCase();
|
|
42
40
|
}
|
|
41
|
+
exports.sha512 = sha512;
|
|
43
42
|
function encode(data, encoding = "base64") {
|
|
44
43
|
let buffer;
|
|
45
44
|
if (Buffer.isBuffer(data))
|
|
@@ -50,6 +49,8 @@ function encode(data, encoding = "base64") {
|
|
|
50
49
|
buffer = Buffer.from(data.toString(), 'utf8');
|
|
51
50
|
return buffer.toString(encoding);
|
|
52
51
|
}
|
|
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,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isValidJson =
|
|
4
|
-
exports.prettifyJson = prettifyJson;
|
|
3
|
+
exports.prettifyJson = exports.isValidJson = void 0;
|
|
5
4
|
const tools_1 = require("./tools");
|
|
6
5
|
function isValidJson(_string) {
|
|
7
6
|
try {
|
|
@@ -12,6 +11,8 @@ function isValidJson(_string) {
|
|
|
12
11
|
return false;
|
|
13
12
|
}
|
|
14
13
|
}
|
|
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,9 +17,7 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.mergeObject =
|
|
21
|
-
exports.mergeArray = mergeArray;
|
|
22
|
-
exports.merge = merge;
|
|
20
|
+
exports.merge = exports.mergeArray = exports.mergeObject = void 0;
|
|
23
21
|
const object_tools_1 = require("./object-tools");
|
|
24
22
|
const tools_1 = require("./tools");
|
|
25
23
|
const exceptions_1 = require("../core/exceptions/exceptions");
|
|
@@ -37,6 +35,7 @@ function mergeObject(original, override) {
|
|
|
37
35
|
return obj;
|
|
38
36
|
}, returnValue);
|
|
39
37
|
}
|
|
38
|
+
exports.mergeObject = mergeObject;
|
|
40
39
|
function mergeArray(original, override) {
|
|
41
40
|
if (original === override) {
|
|
42
41
|
return override;
|
|
@@ -58,6 +57,7 @@ function mergeArray(original, override) {
|
|
|
58
57
|
// });
|
|
59
58
|
return override;
|
|
60
59
|
}
|
|
60
|
+
exports.mergeArray = mergeArray;
|
|
61
61
|
function merge(original, override) {
|
|
62
62
|
if (!(0, tools_1.exists)(override))
|
|
63
63
|
return undefined;
|
|
@@ -71,3 +71,4 @@ 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,17 +17,7 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.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;
|
|
20
|
+
exports.filterKeys = exports.assert = exports.compare = exports.partialCompare = exports.cloneObj = exports.cloneArr = exports._setTypedProp = exports._values = exports._keys = exports.deepClone = exports.getDotNotatedValue = void 0;
|
|
31
21
|
const exceptions_1 = require("../core/exceptions/exceptions");
|
|
32
22
|
const array_tools_1 = require("./array-tools");
|
|
33
23
|
function getDotNotatedValue(key, dotNotatedObject) {
|
|
@@ -36,6 +26,7 @@ function getDotNotatedValue(key, dotNotatedObject) {
|
|
|
36
26
|
return value[_pathPart];
|
|
37
27
|
}, dotNotatedObject);
|
|
38
28
|
}
|
|
29
|
+
exports.getDotNotatedValue = getDotNotatedValue;
|
|
39
30
|
function deepClone(obj) {
|
|
40
31
|
if (typeof obj === 'string' || typeof obj === 'number' || typeof obj === 'boolean' || typeof obj === 'undefined' || obj === null)
|
|
41
32
|
return obj;
|
|
@@ -43,24 +34,30 @@ function deepClone(obj) {
|
|
|
43
34
|
return cloneArr(obj);
|
|
44
35
|
return cloneObj(obj);
|
|
45
36
|
}
|
|
37
|
+
exports.deepClone = deepClone;
|
|
46
38
|
function _keys(instance) {
|
|
47
39
|
return Object.keys(instance);
|
|
48
40
|
}
|
|
41
|
+
exports._keys = _keys;
|
|
49
42
|
function _values(object) {
|
|
50
43
|
return Object.values(object);
|
|
51
44
|
}
|
|
45
|
+
exports._values = _values;
|
|
52
46
|
function _setTypedProp(instance, key, value) {
|
|
53
47
|
instance[key] = value;
|
|
54
48
|
}
|
|
49
|
+
exports._setTypedProp = _setTypedProp;
|
|
55
50
|
function cloneArr(value) {
|
|
56
51
|
return value.map(a => deepClone(a));
|
|
57
52
|
}
|
|
53
|
+
exports.cloneArr = cloneArr;
|
|
58
54
|
function cloneObj(obj) {
|
|
59
55
|
return _keys(obj).reduce((carry, key) => {
|
|
60
56
|
carry[key] = deepClone(obj[key]);
|
|
61
57
|
return carry;
|
|
62
58
|
}, {});
|
|
63
59
|
}
|
|
60
|
+
exports.cloneObj = cloneObj;
|
|
64
61
|
function partialCompare(one, two, keysToFilterOut) {
|
|
65
62
|
one = deepClone(one);
|
|
66
63
|
two = deepClone(two);
|
|
@@ -70,6 +67,7 @@ function partialCompare(one, two, keysToFilterOut) {
|
|
|
70
67
|
});
|
|
71
68
|
return compare(one, two);
|
|
72
69
|
}
|
|
70
|
+
exports.partialCompare = partialCompare;
|
|
73
71
|
/**
|
|
74
72
|
* Returns true for equal.
|
|
75
73
|
*/
|
|
@@ -117,10 +115,12 @@ function compare(one, two, keys) {
|
|
|
117
115
|
}
|
|
118
116
|
return true;
|
|
119
117
|
}
|
|
118
|
+
exports.compare = compare;
|
|
120
119
|
function assert(message, expected, actual) {
|
|
121
120
|
if (!compare(expected, actual))
|
|
122
121
|
throw new exceptions_1.AssertionException(`Assertion Failed:\n -- ${message}\n -- Expected: ${JSON.stringify(expected)}\n -- Actual: ${JSON.stringify(actual)}\n\n`);
|
|
123
122
|
}
|
|
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,3 +131,4 @@ 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,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.composeQueryParams =
|
|
4
|
-
exports.composeUrl = composeUrl;
|
|
3
|
+
exports.composeUrl = exports.composeQueryParams = void 0;
|
|
5
4
|
function composeQueryParams(params = {}) {
|
|
6
5
|
return Object.keys(params).map((paramKey) => {
|
|
7
6
|
let param = params[paramKey];
|
|
@@ -12,6 +11,7 @@ function composeQueryParams(params = {}) {
|
|
|
12
11
|
return `${paramKey}=${encodeURIComponent(param)}`;
|
|
13
12
|
}).join('&');
|
|
14
13
|
}
|
|
14
|
+
exports.composeQueryParams = composeQueryParams;
|
|
15
15
|
function composeUrl(url, params = {}, hash = '') {
|
|
16
16
|
const queryAsEncodedString = composeQueryParams(params);
|
|
17
17
|
if (queryAsEncodedString.length)
|
|
@@ -20,3 +20,4 @@ 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.generateHex =
|
|
21
|
-
exports.generateUUID = generateUUID;
|
|
22
|
-
exports.generateShortURL = generateShortURL;
|
|
20
|
+
exports.generateShortURL = exports.generateUUID = exports.generateHex = void 0;
|
|
23
21
|
const crypto_1 = require("crypto");
|
|
24
22
|
function generateHex(length) {
|
|
25
23
|
return (0, crypto_1.randomBytes)(Math.ceil(length / 2))
|
|
26
24
|
.toString('hex')
|
|
27
25
|
.slice(0, length).toLowerCase();
|
|
28
26
|
}
|
|
27
|
+
exports.generateHex = generateHex;
|
|
29
28
|
function generateUUID() {
|
|
30
29
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
31
30
|
const r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
32
31
|
return v.toString(16);
|
|
33
32
|
});
|
|
34
33
|
}
|
|
34
|
+
exports.generateUUID = generateUUID;
|
|
35
35
|
/**
|
|
36
36
|
* generate 8 characters long string that is value for short url usage
|
|
37
37
|
*/
|
|
@@ -45,3 +45,4 @@ function generateShortURL() {
|
|
|
45
45
|
}
|
|
46
46
|
return result;
|
|
47
47
|
}
|
|
48
|
+
exports.generateShortURL = generateShortURL;
|
package/utils/string-tools.js
CHANGED
|
@@ -17,23 +17,12 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.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;
|
|
20
|
+
exports.convertUpperCamelCase = exports.normalizeString = exports.levenshteinDistance = exports.createLevenshteinDistanceMatrix = exports.capitalizeFirstLetter = exports.capitalizeAllFirstLetters = exports.replaceStringAt = exports.stringFormat = exports.getStringSize = exports.maxSubstring = exports.escape_RegExp = exports.stringToHashCode = exports.padNumber = void 0;
|
|
33
21
|
function padNumber(num, length) {
|
|
34
22
|
const _num = num.toString();
|
|
35
23
|
return _num.length < length ? padNumber('0' + _num, length) : _num;
|
|
36
24
|
}
|
|
25
|
+
exports.padNumber = padNumber;
|
|
37
26
|
function stringToHashCode(stringToHash) {
|
|
38
27
|
let hash = 0;
|
|
39
28
|
if (stringToHash.length === 0)
|
|
@@ -44,9 +33,11 @@ function stringToHashCode(stringToHash) {
|
|
|
44
33
|
}
|
|
45
34
|
return hash;
|
|
46
35
|
}
|
|
36
|
+
exports.stringToHashCode = stringToHashCode;
|
|
47
37
|
function escape_RegExp(string) {
|
|
48
38
|
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
|
|
49
39
|
}
|
|
40
|
+
exports.escape_RegExp = escape_RegExp;
|
|
50
41
|
function maxSubstring(string, maxBytes, direction = 'start') {
|
|
51
42
|
const encoder = new TextEncoder();
|
|
52
43
|
const decoder = new TextDecoder();
|
|
@@ -63,6 +54,7 @@ function maxSubstring(string, maxBytes, direction = 'start') {
|
|
|
63
54
|
}
|
|
64
55
|
return decoder.decode(slicedBytes);
|
|
65
56
|
}
|
|
57
|
+
exports.maxSubstring = maxSubstring;
|
|
66
58
|
/**
|
|
67
59
|
* Calculate the size of a string in the specified unit.
|
|
68
60
|
* @param str - The input string whose size is to be calculated.
|
|
@@ -85,16 +77,19 @@ function getStringSize(str, unit = 'KB') {
|
|
|
85
77
|
throw new Error('Invalid unit. Please specify "KB", "MB", or "GB".');
|
|
86
78
|
}
|
|
87
79
|
}
|
|
80
|
+
exports.getStringSize = getStringSize;
|
|
88
81
|
function stringFormat(input, params = []) {
|
|
89
82
|
return (params === null || params === void 0 ? void 0 : params.reduce((toRet, param, index) => {
|
|
90
83
|
return toRet.replace(new RegExp(`\\{${index}\\}`, 'g'), param);
|
|
91
84
|
}, input || '')) || input;
|
|
92
85
|
}
|
|
86
|
+
exports.stringFormat = stringFormat;
|
|
93
87
|
function replaceStringAt(origin, index, replacement) {
|
|
94
88
|
if (!(origin === null || origin === void 0 ? void 0 : origin.length) || !(replacement === null || replacement === void 0 ? void 0 : replacement.length))
|
|
95
89
|
return origin;
|
|
96
90
|
return origin.substring(0, index) + replacement + origin.substring(index + replacement.length);
|
|
97
91
|
}
|
|
92
|
+
exports.replaceStringAt = replaceStringAt;
|
|
98
93
|
function capitalizeAllFirstLetters(value) {
|
|
99
94
|
let resultString = value;
|
|
100
95
|
for (let i = 0; i < resultString.length; i++) {
|
|
@@ -103,9 +98,11 @@ function capitalizeAllFirstLetters(value) {
|
|
|
103
98
|
}
|
|
104
99
|
return resultString;
|
|
105
100
|
}
|
|
101
|
+
exports.capitalizeAllFirstLetters = capitalizeAllFirstLetters;
|
|
106
102
|
function capitalizeFirstLetter(value) {
|
|
107
103
|
return value.charAt(0).toUpperCase() + value.substr(1).toLowerCase();
|
|
108
104
|
}
|
|
105
|
+
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
109
106
|
function createLevenshteinDistanceMatrix(str1, str2) {
|
|
110
107
|
const len1 = str1.length;
|
|
111
108
|
const len2 = str2.length;
|
|
@@ -122,6 +119,7 @@ function createLevenshteinDistanceMatrix(str1, str2) {
|
|
|
122
119
|
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));
|
|
123
120
|
return matrix;
|
|
124
121
|
}
|
|
122
|
+
exports.createLevenshteinDistanceMatrix = createLevenshteinDistanceMatrix;
|
|
125
123
|
function levenshteinDistance(str1, str2) {
|
|
126
124
|
//Quick exists
|
|
127
125
|
if (str1.length === 0)
|
|
@@ -133,9 +131,12 @@ function levenshteinDistance(str1, str2) {
|
|
|
133
131
|
//Distance between the strings should be at bottom right corner of the matrix
|
|
134
132
|
return matrix[str1.length][str2.length];
|
|
135
133
|
}
|
|
134
|
+
exports.levenshteinDistance = levenshteinDistance;
|
|
136
135
|
function normalizeString(string) {
|
|
137
136
|
return string.replace(/–/g, '-').replace(/\n/g, '').replace(/\s+/g, ' ').replace(/’/g, '\'').trim();
|
|
138
137
|
}
|
|
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,17 +17,12 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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;
|
|
20
|
+
exports.logicalXOR = exports.freeze = exports.exists = exports.resolveFunctionOrValue = exports.resolveContent = exports.functionThatReturnsTrue = exports.functionThatReturnsFalse = exports.voidFunction = exports.EmptyArray = exports.EmptyObject = exports.__stringify = exports.calculateJsonSizeMb = exports.createFilterPattern = exports.regexpCase = void 0;
|
|
27
21
|
const object_tools_1 = require("./object-tools");
|
|
28
22
|
function regexpCase(value, reg) {
|
|
29
23
|
return value.match(new RegExp(reg)) || { input: undefined };
|
|
30
24
|
}
|
|
25
|
+
exports.regexpCase = regexpCase;
|
|
31
26
|
function createFilterPattern(rawFilter) {
|
|
32
27
|
let filter = rawFilter || '';
|
|
33
28
|
filter = filter.trim();
|
|
@@ -36,10 +31,12 @@ function createFilterPattern(rawFilter) {
|
|
|
36
31
|
filter.length === 0 ? filter = '.*?' : filter += '.*';
|
|
37
32
|
return filter;
|
|
38
33
|
}
|
|
34
|
+
exports.createFilterPattern = createFilterPattern;
|
|
39
35
|
function calculateJsonSizeMb(data) {
|
|
40
36
|
const number = JSON.stringify(data).length / 1024 / 1024;
|
|
41
37
|
return Math.round(number * 100) / 100;
|
|
42
38
|
}
|
|
39
|
+
exports.calculateJsonSizeMb = calculateJsonSizeMb;
|
|
43
40
|
function __stringify(obj, pretty) {
|
|
44
41
|
if (!obj)
|
|
45
42
|
return '';
|
|
@@ -53,6 +50,7 @@ function __stringify(obj, pretty) {
|
|
|
53
50
|
return JSON.stringify(obj, null, 2);
|
|
54
51
|
return JSON.stringify(obj);
|
|
55
52
|
}
|
|
53
|
+
exports.__stringify = __stringify;
|
|
56
54
|
exports.EmptyObject = Object.freeze({});
|
|
57
55
|
exports.EmptyArray = Object.freeze([]);
|
|
58
56
|
exports.voidFunction = Object.freeze(async () => {
|
|
@@ -67,9 +65,11 @@ exports.resolveFunctionOrValue = exports.resolveContent;
|
|
|
67
65
|
function exists(item) {
|
|
68
66
|
return item !== undefined && item !== null;
|
|
69
67
|
}
|
|
68
|
+
exports.exists = exists;
|
|
70
69
|
function freeze(item) {
|
|
71
70
|
return Object.freeze(item);
|
|
72
71
|
}
|
|
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 = void 0;
|
|
21
21
|
const exceptions_1 = require("../core/exceptions/exceptions");
|
|
22
22
|
/**
|
|
23
23
|
*
|
|
@@ -47,3 +47,4 @@ 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) => InvalidResultObject<T> | undefined))[];
|
|
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 | undefined) => 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, parentInput?: any) => InvalidResult<T>, mandatory?: boolean) => Validator<T>[];
|
|
6
|
+
export declare const tsValidateCustom: <T>(processor: (input?: T | undefined, 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) => "Input does not match any of the possible types" | InvalidResult<T> | undefined))[];
|
|
12
|
+
export declare const tsValidateUnionV3: <T>(validatorObject: validatorObject<T>, mandatory?: boolean) => (import("./validator-core").ValidatorImpl<any> | ((input?: T | undefined) => "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: T[] |
|
|
19
|
+
export declare const tsValidateValue: <T>(values: readonly T[] | 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) => 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))[];
|
|
26
|
+
export declare const tsValidateNonMandatoryObject: <T extends object | undefined>(validator: ValidatorTypeResolver<T>) => (import("./validator-core").ValidatorImpl<any> | ((input?: T | undefined) => InvalidResult<T> | undefined))[];
|
|
27
|
+
export declare const tsValidateOptionalObject: <T extends object | undefined>(validator: ValidatorTypeResolver<T>) => (import("./validator-core").ValidatorImpl<any> | ((input?: T | undefined) => InvalidResult<T> | undefined))[];
|
|
28
28
|
export declare const tsValidator_valueByKey: <T>(validatorObject: {
|
|
29
|
-
[k: string]:
|
|
29
|
+
[k: string]: Validator<any> | import("./validator-core").TypeValidator<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, parentInstance?: any) => InvalidResult<T> | undefined;
|
|
29
|
+
export declare const tsValidateResult: <T>(instance: T | undefined, _validator: ValidatorTypeResolver<T>, key?: keyof T | undefined, parentInstance?: any) => InvalidResult<T> | undefined;
|
|
30
30
|
export declare const tsValidateObject: <T extends object>(__validator: TypeValidator<T>, instance: T, path?: string) => InvalidResultObject<T> | undefined;
|