@nu-art/ts-common 0.300.8 → 0.400.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/consts/consts.js +2 -4
- package/consts/consts.js.map +1 -0
- package/core/application.d.ts +1 -1
- package/core/application.js +3 -6
- package/core/application.js.map +1 -0
- package/core/debug-flags.d.ts +1 -1
- package/core/debug-flags.js +15 -17
- package/core/debug-flags.js.map +1 -0
- package/core/dispatcher.d.ts +2 -2
- package/core/dispatcher.js +7 -8
- package/core/dispatcher.js.map +1 -0
- package/core/error-handling.d.ts +5 -5
- package/core/error-handling.js +7 -9
- package/core/error-handling.js.map +1 -0
- package/core/exceptions/exceptions.d.ts +2 -2
- package/core/exceptions/exceptions.js +33 -44
- package/core/exceptions/exceptions.js.map +1 -0
- package/core/exceptions/http-codes.d.ts +8 -2
- package/core/exceptions/http-codes.js +6 -6
- package/core/exceptions/http-codes.js.map +1 -0
- package/core/exceptions/types.js +2 -2
- package/core/exceptions/types.js.map +1 -0
- package/core/logger/BeLogged.d.ts +2 -2
- package/core/logger/BeLogged.js +9 -11
- package/core/logger/BeLogged.js.map +1 -0
- package/core/logger/LogClient.d.ts +3 -1
- package/core/logger/LogClient.js +21 -24
- package/core/logger/LogClient.js.map +1 -0
- package/core/logger/LogClient_BaseRotate.d.ts +2 -2
- package/core/logger/LogClient_BaseRotate.js +12 -12
- package/core/logger/LogClient_BaseRotate.js.map +1 -0
- package/core/logger/LogClient_Browser.d.ts +2 -2
- package/core/logger/LogClient_Browser.js +40 -45
- package/core/logger/LogClient_Browser.js.map +1 -0
- package/core/logger/LogClient_BrowserGroups.d.ts +2 -2
- package/core/logger/LogClient_BrowserGroups.js +65 -67
- package/core/logger/LogClient_BrowserGroups.js.map +1 -0
- package/core/logger/LogClient_ConsoleProxy.d.ts +23 -0
- package/core/logger/LogClient_ConsoleProxy.js +89 -0
- package/core/logger/LogClient_ConsoleProxy.js.map +1 -0
- package/core/logger/LogClient_File.d.ts +1 -1
- package/core/logger/LogClient_File.js +6 -30
- package/core/logger/LogClient_File.js.map +1 -0
- package/core/logger/LogClient_Function.d.ts +2 -2
- package/core/logger/LogClient_Function.js +6 -8
- package/core/logger/LogClient_Function.js.map +1 -0
- package/core/logger/LogClient_MemBuffer.d.ts +2 -2
- package/core/logger/LogClient_MemBuffer.js +19 -21
- package/core/logger/LogClient_MemBuffer.js.map +1 -0
- package/core/logger/LogClient_Terminal.d.ts +2 -2
- package/core/logger/LogClient_Terminal.js +16 -21
- package/core/logger/LogClient_Terminal.js.map +1 -0
- package/core/logger/Logger.d.ts +2 -2
- package/core/logger/Logger.js +37 -39
- package/core/logger/Logger.js.map +1 -0
- package/core/logger/types.js +4 -6
- package/core/logger/types.js.map +1 -0
- package/core/logger/utils.d.ts +1 -1
- package/core/logger/utils.js +10 -15
- package/core/logger/utils.js.map +1 -0
- package/core/module-manager.d.ts +8 -6
- package/core/module-manager.js +28 -26
- package/core/module-manager.js.map +1 -0
- package/core/module.d.ts +5 -5
- package/core/module.js +28 -28
- package/core/module.js.map +1 -0
- package/csv.d.ts +2 -2
- package/csv.js +3 -18
- package/csv.js.map +1 -0
- package/db/consts.d.ts +3 -0
- package/db/consts.js +17 -7
- package/db/consts.js.map +1 -0
- package/db/dependencies-test.js +2 -2
- package/db/dependencies-test.js.map +1 -0
- package/db/types.d.ts +10 -2
- package/db/types.js +2 -2
- package/db/types.js.map +1 -0
- package/esm.d.ts +1 -0
- package/esm.js +4 -0
- package/esm.js.map +1 -0
- package/index.d.ts +50 -49
- package/index.js +51 -65
- package/index.js.map +1 -0
- package/mem-storage/MemStorage.d.ts +3 -1
- package/mem-storage/MemStorage.js +90 -72
- package/mem-storage/MemStorage.js.map +1 -0
- package/mem-storage/index.d.ts +1 -0
- package/mem-storage/index.js +2 -0
- package/mem-storage/index.js.map +1 -0
- package/modules/CSVModule.d.ts +2 -2
- package/modules/CSVModule.js +22 -48
- package/modules/CSVModule.js.map +1 -0
- package/modules/CSVModuleV3.d.ts +2 -2
- package/modules/CSVModuleV3.js +60 -86
- package/modules/CSVModuleV3.js.map +1 -0
- package/modules/CliParamsModule.d.ts +2 -2
- package/modules/CliParamsModule.js +23 -28
- package/modules/CliParamsModule.js.map +1 -0
- package/modules/JSONCSVModule.d.ts +2 -2
- package/modules/JSONCSVModule.js +56 -78
- package/modules/JSONCSVModule.js.map +1 -0
- package/modules/csv-serializer.d.ts +1 -1
- package/modules/csv-serializer.js +11 -5
- package/modules/csv-serializer.js.map +1 -0
- package/package.json +20 -11
- package/replacer-v2/ReplacerV2.d.ts +1 -1
- package/replacer-v2/ReplacerV2.js +6 -9
- package/replacer-v2/ReplacerV2.js.map +1 -0
- package/test-index.d.ts +2 -2
- package/test-index.js +3 -18
- package/test-index.js.map +1 -0
- package/testing/consts.d.ts +13 -2
- package/testing/consts.js +66 -26
- package/testing/consts.js.map +1 -0
- package/testing/test-template.test.d.ts +1 -0
- package/testing/test-template.test.js +42 -0
- package/testing/test-template.test.js.map +1 -0
- package/testing/types.d.ts +17 -5
- package/testing/types.js +2 -2
- package/testing/types.js.map +1 -0
- package/testing/workspace-creator.d.ts +10 -0
- package/testing/workspace-creator.js +79 -0
- package/testing/workspace-creator.js.map +1 -0
- package/tools/Replacer.d.ts +2 -2
- package/tools/Replacer.js +22 -24
- package/tools/Replacer.js.map +1 -0
- package/tools/get-log-style.js +4 -6
- package/tools/get-log-style.js.map +1 -0
- package/utils/FileSystemUtils.d.ts +34 -0
- package/utils/FileSystemUtils.js +153 -0
- package/utils/FileSystemUtils.js.map +1 -0
- package/utils/array-tools.d.ts +4 -4
- package/utils/array-tools.js +56 -83
- package/utils/array-tools.js.map +1 -0
- package/utils/conflict-tools.d.ts +1 -0
- package/utils/conflict-tools.js +3 -0
- package/utils/conflict-tools.js.map +1 -0
- package/utils/crypto-tools.d.ts +44 -0
- package/utils/crypto-tools.js +101 -10
- package/utils/crypto-tools.js.map +1 -0
- package/utils/date-time-tools.d.ts +48 -4
- package/utils/date-time-tools.js +166 -64
- package/utils/date-time-tools.js.map +1 -0
- package/utils/db-object-tools.d.ts +7 -2
- package/utils/db-object-tools.js +20 -20
- package/utils/db-object-tools.js.map +1 -0
- package/utils/exception-tools.js +13 -15
- package/utils/exception-tools.js.map +1 -0
- package/utils/filter-tools.js +48 -48
- package/utils/filter-tools.js.map +1 -0
- package/utils/hash-tools.js +14 -22
- package/utils/hash-tools.js.map +1 -0
- package/utils/index.d.ts +27 -0
- package/utils/index.js +28 -0
- package/utils/index.js.map +1 -0
- package/utils/json-tools.js +5 -8
- package/utils/json-tools.js.map +1 -0
- package/utils/merge-tools.d.ts +9 -0
- package/utils/merge-tools.js +18 -19
- package/utils/merge-tools.js.map +1 -0
- package/utils/mimetype-tools.d.ts +1 -0
- package/utils/mimetype-tools.js +26 -27
- package/utils/mimetype-tools.js.map +1 -0
- package/utils/number-tools.js +3 -7
- package/utils/number-tools.js.map +1 -0
- package/utils/object-tools.d.ts +15 -1
- package/utils/object-tools.js +110 -33
- package/utils/object-tools.js.map +1 -0
- package/utils/promise-tools.d.ts +5 -0
- package/utils/promise-tools.js +9 -5
- package/utils/promise-tools.js.map +1 -0
- package/utils/query-params.js +3 -6
- package/utils/query-params.js.map +1 -0
- package/utils/queue-v2.d.ts +1 -1
- package/utils/queue-v2.js +72 -73
- package/utils/queue-v2.js.map +1 -0
- package/utils/queue.d.ts +1 -1
- package/utils/queue.js +15 -17
- package/utils/queue.js.map +1 -0
- package/utils/random-tools.js +7 -11
- package/utils/random-tools.js.map +1 -0
- package/utils/storage-capacity-tools.js +7 -9
- package/utils/storage-capacity-tools.js.map +1 -0
- package/utils/string-tools.js +17 -31
- package/utils/string-tools.js.map +1 -0
- package/utils/time-proxy.d.ts +8 -0
- package/utils/time-proxy.js +10 -0
- package/utils/time-proxy.js.map +1 -0
- package/utils/tools.d.ts +1 -1
- package/utils/tools.js +18 -28
- package/utils/tools.js.map +1 -0
- package/utils/types.d.ts +9 -3
- package/utils/types.js +2 -4
- package/utils/types.js.map +1 -0
- package/utils/ui-tools.js +6 -12
- package/utils/ui-tools.js.map +1 -0
- package/utils/url-tools.d.ts +5 -0
- package/utils/url-tools.js +20 -0
- package/utils/url-tools.js.map +1 -0
- package/utils/version-tools.js +17 -12
- package/utils/version-tools.js.map +1 -0
- package/validator/type-validators.d.ts +14 -10
- package/validator/type-validators.js +84 -105
- package/validator/type-validators.js.map +1 -0
- package/validator/validator-core.d.ts +4 -4
- package/validator/validator-core.js +16 -21
- package/validator/validator-core.js.map +1 -0
- package/validator/validators.d.ts +9 -5
- package/validator/validators.js +48 -47
- package/validator/validators.js.map +1 -0
- package/tsconfig.json +0 -23
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export declare class MemStorage {
|
|
2
2
|
private readonly cache;
|
|
3
3
|
constructor();
|
|
4
|
-
|
|
4
|
+
static getStore(): MemStorage | undefined;
|
|
5
|
+
init<R>(makeItContext: () => Promise<R>, enclosingContextStorage?: MemStorage): Promise<R>;
|
|
5
6
|
initSync<R>(makeItContext: () => R): R;
|
|
6
7
|
private set;
|
|
7
8
|
private get;
|
|
@@ -14,6 +15,7 @@ export declare class MemKey<T> {
|
|
|
14
15
|
setResolver: (resolver?: (storage: MemStorage) => T) => this;
|
|
15
16
|
resolve: (storage: MemStorage) => Promise<void>;
|
|
16
17
|
assert: (value?: T) => T;
|
|
18
|
+
peak: () => (T | undefined);
|
|
17
19
|
get: (value?: T) => T;
|
|
18
20
|
set: (value: T) => T;
|
|
19
21
|
merge: (value: T) => any;
|
|
@@ -1,84 +1,102 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const validator_core_1 = require("../validator/validator-core");
|
|
9
|
-
const asyncLocalStorage = new async_hooks_1.AsyncLocalStorage();
|
|
10
|
-
class MemStorage {
|
|
1
|
+
import { __stringify, exists } from '../utils/tools.js';
|
|
2
|
+
import { BadImplementationException } from '../core/exceptions/exceptions.js';
|
|
3
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
4
|
+
import { ValidationException } from '../validator/validator-core.js';
|
|
5
|
+
const asyncLocalStorage = new AsyncLocalStorage();
|
|
6
|
+
export class MemStorage {
|
|
7
|
+
cache = {};
|
|
11
8
|
constructor() {
|
|
12
|
-
// console.log(`---- ${this.cache.__myId} created`);
|
|
13
|
-
this.cache = { __myId: (0, random_tools_1.generateHex)(4) };
|
|
14
|
-
this.set = (key, value) => {
|
|
15
|
-
// console.log(`-- ${this.cache.__myId} set: ${key.key} -> `, value);
|
|
16
|
-
const currentValue = this.cache[key.key];
|
|
17
|
-
if ((0, tools_1.exists)(currentValue) && key.unique && value !== currentValue) {
|
|
18
|
-
throw new exceptions_1.BadImplementationException(`Unique storage key is being overridden for key: ${key.key}
|
|
19
|
-
\ncurrent: ${(0, tools_1.__stringify)(currentValue)}
|
|
20
|
-
\nnew: ${(0, tools_1.__stringify)(value)}`);
|
|
21
|
-
}
|
|
22
|
-
return this.cache[key.key] = value;
|
|
23
|
-
};
|
|
24
|
-
this.get = (key, defaultValue) => {
|
|
25
|
-
let currentValue = this.cache[key.key];
|
|
26
|
-
if (!(0, tools_1.exists)(currentValue))
|
|
27
|
-
currentValue = defaultValue;
|
|
28
|
-
return currentValue;
|
|
29
|
-
};
|
|
30
9
|
}
|
|
31
|
-
|
|
32
|
-
return asyncLocalStorage.
|
|
10
|
+
static getStore() {
|
|
11
|
+
return asyncLocalStorage.getStore();
|
|
12
|
+
}
|
|
13
|
+
async init(makeItContext, enclosingContextStorage) {
|
|
14
|
+
let isSameContext = false;
|
|
15
|
+
const response = await asyncLocalStorage.run(this, async () => {
|
|
16
|
+
const currentStorage = MemStorage.getStore();
|
|
17
|
+
if (currentStorage === enclosingContextStorage) {
|
|
18
|
+
isSameContext = true;
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (enclosingContextStorage)
|
|
22
|
+
for (const key in enclosingContextStorage.cache) {
|
|
23
|
+
currentStorage.cache[key] = enclosingContextStorage.cache[key];
|
|
24
|
+
}
|
|
25
|
+
return makeItContext();
|
|
26
|
+
});
|
|
27
|
+
if (isSameContext)
|
|
28
|
+
return makeItContext();
|
|
29
|
+
return response;
|
|
33
30
|
}
|
|
34
31
|
initSync(makeItContext) {
|
|
35
32
|
return asyncLocalStorage.run(this, makeItContext);
|
|
36
33
|
}
|
|
34
|
+
set = (key, value) => {
|
|
35
|
+
const currentValue = this.cache[key.key];
|
|
36
|
+
if (exists(currentValue) && key.unique && value !== currentValue) {
|
|
37
|
+
throw new BadImplementationException(`Unique storage key is being overridden for key: ${key.key}
|
|
38
|
+
\ncurrent: ${__stringify(currentValue)}
|
|
39
|
+
\nnew: ${__stringify(value)}`);
|
|
40
|
+
}
|
|
41
|
+
return this.cache[key.key] = value;
|
|
42
|
+
};
|
|
43
|
+
get = (key, defaultValue) => {
|
|
44
|
+
let currentValue = this.cache[key.key];
|
|
45
|
+
if (!exists(currentValue))
|
|
46
|
+
currentValue = defaultValue;
|
|
47
|
+
return currentValue;
|
|
48
|
+
};
|
|
37
49
|
}
|
|
38
|
-
|
|
39
|
-
|
|
50
|
+
export class MemKey {
|
|
51
|
+
key;
|
|
52
|
+
unique;
|
|
53
|
+
resolver;
|
|
40
54
|
constructor(key, unique = false) {
|
|
41
|
-
this.setResolver = (resolver) => {
|
|
42
|
-
this.resolver = resolver;
|
|
43
|
-
return this;
|
|
44
|
-
};
|
|
45
|
-
this.resolve = async (storage) => {
|
|
46
|
-
var _a;
|
|
47
|
-
const value = (_a = this.resolver) === null || _a === void 0 ? void 0 : _a.call(this, storage);
|
|
48
|
-
if (!(0, tools_1.exists)(value))
|
|
49
|
-
return;
|
|
50
|
-
this.set(value);
|
|
51
|
-
};
|
|
52
|
-
this.assert = (value) => {
|
|
53
|
-
const storedValue = this.get();
|
|
54
|
-
if (!(0, tools_1.exists)(value))
|
|
55
|
-
return storedValue;
|
|
56
|
-
if (value !== storedValue) {
|
|
57
|
-
throw new validator_core_1.ValidationException(`Asserting MemKey(${this.key}) ${value} !== ${storedValue}!`);
|
|
58
|
-
}
|
|
59
|
-
return storedValue;
|
|
60
|
-
};
|
|
61
|
-
this.get = (value) => {
|
|
62
|
-
// @ts-ignore
|
|
63
|
-
const memValue = asyncLocalStorage.getStore().get(this, value);
|
|
64
|
-
if (!(0, tools_1.exists)(memValue))
|
|
65
|
-
throw new exceptions_1.BadImplementationException(`Trying to access MemKey(${this.key}) before it was set!`);
|
|
66
|
-
return memValue;
|
|
67
|
-
};
|
|
68
|
-
this.set = (value) => {
|
|
69
|
-
// console.log(this.key, value);
|
|
70
|
-
if (!(0, tools_1.exists)(value))
|
|
71
|
-
throw new exceptions_1.BadImplementationException(`Cannot set MemKey(${this.key}) to undefined or null!`);
|
|
72
|
-
// @ts-ignore
|
|
73
|
-
return asyncLocalStorage.getStore().set(this, value);
|
|
74
|
-
};
|
|
75
|
-
this.merge = (value) => {
|
|
76
|
-
const currentValue = this.get();
|
|
77
|
-
// @ts-ignore
|
|
78
|
-
return asyncLocalStorage.getStore().set(this, merge(currentValue, value));
|
|
79
|
-
};
|
|
80
55
|
this.key = key;
|
|
81
56
|
this.unique = unique;
|
|
82
57
|
}
|
|
58
|
+
setResolver = (resolver) => {
|
|
59
|
+
this.resolver = resolver;
|
|
60
|
+
return this;
|
|
61
|
+
};
|
|
62
|
+
resolve = async (storage) => {
|
|
63
|
+
const value = this.resolver?.(storage);
|
|
64
|
+
if (!exists(value))
|
|
65
|
+
return;
|
|
66
|
+
this.set(value);
|
|
67
|
+
};
|
|
68
|
+
assert = (value) => {
|
|
69
|
+
const storedValue = this.get();
|
|
70
|
+
if (!exists(value))
|
|
71
|
+
return storedValue;
|
|
72
|
+
if (value !== storedValue) {
|
|
73
|
+
throw new ValidationException(`Asserting MemKey(${this.key}) ${value} !== ${storedValue}!`);
|
|
74
|
+
}
|
|
75
|
+
return storedValue;
|
|
76
|
+
};
|
|
77
|
+
peak = () => {
|
|
78
|
+
// @ts-ignore
|
|
79
|
+
const memValue = asyncLocalStorage.getStore().get(this);
|
|
80
|
+
return memValue;
|
|
81
|
+
};
|
|
82
|
+
get = (value) => {
|
|
83
|
+
// @ts-ignore
|
|
84
|
+
const memValue = asyncLocalStorage.getStore().get(this, value);
|
|
85
|
+
if (!exists(memValue))
|
|
86
|
+
throw new BadImplementationException(`Trying to access MemKey(${this.key}) before it was set!`);
|
|
87
|
+
return memValue;
|
|
88
|
+
};
|
|
89
|
+
set = (value) => {
|
|
90
|
+
// console.log(this.key, value);
|
|
91
|
+
if (!exists(value))
|
|
92
|
+
throw new BadImplementationException(`Cannot set MemKey(${this.key}) to undefined or null!`);
|
|
93
|
+
// @ts-ignore
|
|
94
|
+
return asyncLocalStorage.getStore().set(this, value);
|
|
95
|
+
};
|
|
96
|
+
merge = (value) => {
|
|
97
|
+
const currentValue = this.get();
|
|
98
|
+
// @ts-ignore
|
|
99
|
+
return asyncLocalStorage.getStore().set(this, merge(currentValue, value));
|
|
100
|
+
};
|
|
83
101
|
}
|
|
84
|
-
|
|
102
|
+
//# sourceMappingURL=MemStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemStorage.js","sourceRoot":"/Users/tacb0ss/dev/nu-art/beamz/_thunderstorm/ts-common/src/main/","sources":["mem-storage/MemStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,MAAM,EAAC,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAC,0BAA0B,EAAC,MAAM,kCAAkC,CAAC;AAE5E,OAAO,EAAC,iBAAiB,EAAC,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAC,mBAAmB,EAAC,MAAM,gCAAgC,CAAC;AAGnE,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,EAAc,CAAC;AAE9D,MAAM,OAAO,UAAU;IACL,KAAK,GAAQ,EAAE,CAAC;IAEjC;IACA,CAAC;IAED,MAAM,CAAC,QAAQ;QACd,OAAO,iBAAiB,CAAC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":["mem-storage/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
package/modules/CSVModule.d.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Created by tacb0ss on 07/05/2018.
|
|
3
3
|
*/
|
|
4
4
|
import { ExportToCsv, Options } from 'export-to-csv';
|
|
5
|
-
import { StringMap, TS_Object } from '../utils/types';
|
|
6
|
-
import { Module } from '../core/module';
|
|
5
|
+
import { StringMap, TS_Object } from '../utils/types.js';
|
|
6
|
+
import { Module } from '../core/module.js';
|
|
7
7
|
import { Readable, Transform } from 'stream';
|
|
8
8
|
type Config = {
|
|
9
9
|
options: Options;
|
package/modules/CSVModule.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*
|
|
3
2
|
* ts-common is the basic building blocks of our typescript projects
|
|
4
3
|
*
|
|
@@ -16,41 +15,16 @@
|
|
|
16
15
|
* See the License for the specific language governing permissions and
|
|
17
16
|
* limitations under the License.
|
|
18
17
|
*/
|
|
19
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
20
|
-
if (k2 === undefined) k2 = k;
|
|
21
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
22
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
23
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
24
|
-
}
|
|
25
|
-
Object.defineProperty(o, k2, desc);
|
|
26
|
-
}) : (function(o, m, k, k2) {
|
|
27
|
-
if (k2 === undefined) k2 = k;
|
|
28
|
-
o[k2] = m[k];
|
|
29
|
-
}));
|
|
30
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
31
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
32
|
-
}) : function(o, v) {
|
|
33
|
-
o["default"] = v;
|
|
34
|
-
});
|
|
35
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
36
|
-
if (mod && mod.__esModule) return mod;
|
|
37
|
-
var result = {};
|
|
38
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
39
|
-
__setModuleDefault(result, mod);
|
|
40
|
-
return result;
|
|
41
|
-
};
|
|
42
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
-
exports.CSVModule = void 0;
|
|
44
18
|
/**
|
|
45
19
|
* Created by tacb0ss on 07/05/2018.
|
|
46
20
|
*/
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
21
|
+
import { ExportToCsv } from 'export-to-csv';
|
|
22
|
+
import { createReadStream, promises as fs } from 'fs';
|
|
23
|
+
import { Module } from '../core/module.js';
|
|
24
|
+
import { Readable } from 'stream';
|
|
25
|
+
import { Queue } from '../utils/queue.js';
|
|
26
|
+
import * as csvParser from 'csv-parser';
|
|
27
|
+
import * as csv from 'fast-csv';
|
|
54
28
|
const DefaultConfig = {
|
|
55
29
|
options: {
|
|
56
30
|
fieldSeparator: ',',
|
|
@@ -64,7 +38,8 @@ const DefaultConfig = {
|
|
|
64
38
|
useKeysAsHeaders: true,
|
|
65
39
|
}
|
|
66
40
|
};
|
|
67
|
-
class CSVModule_Class extends
|
|
41
|
+
class CSVModule_Class extends Module {
|
|
42
|
+
csvExporter;
|
|
68
43
|
constructor() {
|
|
69
44
|
super();
|
|
70
45
|
this.setDefaultConfig(DefaultConfig);
|
|
@@ -73,7 +48,7 @@ class CSVModule_Class extends module_1.Module {
|
|
|
73
48
|
this.csvExporter = CSVModule_Class.createExporter(this.config.options);
|
|
74
49
|
}
|
|
75
50
|
static createExporter(options) {
|
|
76
|
-
return new
|
|
51
|
+
return new ExportToCsv(options);
|
|
77
52
|
}
|
|
78
53
|
updateExporterSettings(options) {
|
|
79
54
|
this.csvExporter = CSVModule_Class.createExporter(options);
|
|
@@ -83,21 +58,21 @@ class CSVModule_Class extends module_1.Module {
|
|
|
83
58
|
}
|
|
84
59
|
async saveToFile(outputFile, items, columnsToProps) {
|
|
85
60
|
const csv = this.csvExporter.generateCsv(items, true);
|
|
86
|
-
return
|
|
61
|
+
return fs.writeFile(outputFile, csv, { encoding: 'utf8' });
|
|
87
62
|
}
|
|
88
63
|
async readCsvFromFile(inputFile, readOptions) {
|
|
89
|
-
const stream =
|
|
64
|
+
const stream = createReadStream(inputFile, { encoding: 'utf8' });
|
|
90
65
|
return this.readCsvFromStream(stream, readOptions);
|
|
91
66
|
}
|
|
92
67
|
async readCsvFromBuffer(buffer, readOptions) {
|
|
93
|
-
const stream =
|
|
68
|
+
const stream = Readable.from(buffer.toString('utf-8'), { encoding: 'utf8' });
|
|
94
69
|
return this.readCsvFromStream(stream, readOptions);
|
|
95
70
|
}
|
|
96
71
|
async readCsvFromStream(stream, readOptions = {}) {
|
|
97
72
|
return new Promise((resolve, reject) => {
|
|
98
73
|
const results = [];
|
|
99
74
|
stream
|
|
100
|
-
.pipe(csvParser(this.createReadParserOptions(readOptions)))
|
|
75
|
+
.pipe(csvParser.default(this.createReadParserOptions(readOptions)))
|
|
101
76
|
.on('data', (instance) => {
|
|
102
77
|
delete instance['undefined'];
|
|
103
78
|
results.push(instance);
|
|
@@ -108,10 +83,10 @@ class CSVModule_Class extends module_1.Module {
|
|
|
108
83
|
}
|
|
109
84
|
async forEachCsvRowFromStreamAsync(stream, callback, readOptions = {}, queueCount = 5) {
|
|
110
85
|
return new Promise((resolve, reject) => {
|
|
111
|
-
const instancesQueue = new
|
|
86
|
+
const instancesQueue = new Queue('instancesQueue');
|
|
112
87
|
instancesQueue.setParallelCount(queueCount);
|
|
113
88
|
stream
|
|
114
|
-
.pipe(csvParser(this.createReadParserOptions(readOptions)))
|
|
89
|
+
.pipe(csvParser.default(this.createReadParserOptions(readOptions)))
|
|
115
90
|
.on('data', (instance) => instancesQueue.addItem(() => callback(instance)))
|
|
116
91
|
.on('error', (err) => reject(err))
|
|
117
92
|
.on('end', () => instancesQueue.setOnQueueEmpty(() => resolve()));
|
|
@@ -120,7 +95,7 @@ class CSVModule_Class extends module_1.Module {
|
|
|
120
95
|
async forEachCsvRowFromStreamSync(stream, callback, readOptions = {}) {
|
|
121
96
|
return new Promise((resolve, reject) => {
|
|
122
97
|
let rowIndex = 0;
|
|
123
|
-
const csvStream = csvParser(this.createReadParserOptions(readOptions));
|
|
98
|
+
const csvStream = csvParser.default(this.createReadParserOptions(readOptions));
|
|
124
99
|
stream
|
|
125
100
|
.pipe(csvStream)
|
|
126
101
|
.on('data', (instance) => callback(instance, rowIndex++, csvStream))
|
|
@@ -150,17 +125,16 @@ class CSVModule_Class extends module_1.Module {
|
|
|
150
125
|
createReadParserOptions(readOptions) {
|
|
151
126
|
return {
|
|
152
127
|
mapHeaders: (args) => {
|
|
153
|
-
|
|
154
|
-
return ((_b = (_a = readOptions.columnsToProps) === null || _a === void 0 ? void 0 : _a[args.header]) !== null && _b !== void 0 ? _b : args.header);
|
|
128
|
+
return (readOptions.columnsToProps?.[args.header] ?? args.header);
|
|
155
129
|
},
|
|
156
130
|
mapValues: (args) => {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
return mapValues !== null && mapValues !== void 0 ? mapValues : args.value;
|
|
131
|
+
const mapValues = readOptions.mapValues?.(args.header, args.value, args.index);
|
|
132
|
+
return mapValues ?? args.value;
|
|
160
133
|
},
|
|
161
134
|
quote: readOptions.quote || '"',
|
|
162
135
|
headers: readOptions.headers,
|
|
163
136
|
};
|
|
164
137
|
}
|
|
165
138
|
}
|
|
166
|
-
|
|
139
|
+
export const CSVModule = new CSVModule_Class();
|
|
140
|
+
//# sourceMappingURL=CSVModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CSVModule.js","sourceRoot":"/Users/tacb0ss/dev/nu-art/beamz/_thunderstorm/ts-common/src/main/","sources":["modules/CSVModule.ts"],"names":[],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AC;QACxB,CAAC,CAAC,CAAC;IACJ,CAAC;IAEO,uBAAuB,CAAsB,WAA2B;QAC/E,OAAO;YACN,UAAU,EAAE,CAAC,IAAwB,EAAE,EAAE;gBACxC,OAAO,CAAC,WAAW,CAAC,cAAc,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,CAAW,CAAC;YAC7E,CAAC;YACD,SAAS,EAAE,CAAC,IAAsD,EAAE,EAAE;gBACrE,MAAM,SAAS,GAAG,WAAW,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;gBAC/E,OAAO,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC;YAChC,CAAC;YACD,KAAK,EAAE,WAAW,CAAC,KAAK,IAAI,GAAG;YAC/B,OAAO,EAAE,WAAW,CAAC,OAAO;SAE5B,CAAC;IACH,CAAC;CACD;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,eAAe,EAAE,CAAC"}
|
package/modules/CSVModuleV3.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Created by tacb0ss on 07/05/2018.
|
|
3
3
|
*/
|
|
4
4
|
import { Readable, Writable } from 'stream';
|
|
5
|
-
import { Module } from '../core/module';
|
|
5
|
+
import { Module } from '../core/module.js';
|
|
6
6
|
import * as csv from 'fast-csv';
|
|
7
7
|
export declare class CSVModuleV3_Class extends Module {
|
|
8
8
|
constructor();
|
|
@@ -12,7 +12,7 @@ export declare class CSVModuleV3_Class extends Module {
|
|
|
12
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
|
-
provideFormatterFromCsv: (transformer?: (item: any) => any) => csv.CsvParserStream<csv.ParserRow
|
|
15
|
+
provideFormatterFromCsv: (transformer?: (item: any) => any) => csv.CsvParserStream<csv.ParserRow, csv.ParserRow>;
|
|
16
16
|
fromString: (str: string) => Promise<any[]>;
|
|
17
17
|
}
|
|
18
18
|
export declare const CSVModuleV3: CSVModuleV3_Class;
|
package/modules/CSVModuleV3.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*
|
|
3
2
|
* ts-common is the basic building blocks of our typescript projects
|
|
4
3
|
*
|
|
@@ -16,94 +15,69 @@
|
|
|
16
15
|
* See the License for the specific language governing permissions and
|
|
17
16
|
* limitations under the License.
|
|
18
17
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
23
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
24
|
-
}
|
|
25
|
-
Object.defineProperty(o, k2, desc);
|
|
26
|
-
}) : (function(o, m, k, k2) {
|
|
27
|
-
if (k2 === undefined) k2 = k;
|
|
28
|
-
o[k2] = m[k];
|
|
29
|
-
}));
|
|
30
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
31
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
32
|
-
}) : function(o, v) {
|
|
33
|
-
o["default"] = v;
|
|
34
|
-
});
|
|
35
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
36
|
-
if (mod && mod.__esModule) return mod;
|
|
37
|
-
var result = {};
|
|
38
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
39
|
-
__setModuleDefault(result, mod);
|
|
40
|
-
return result;
|
|
41
|
-
};
|
|
42
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
-
exports.CSVModuleV3 = exports.CSVModuleV3_Class = void 0;
|
|
44
|
-
const module_1 = require("../core/module");
|
|
45
|
-
const csv = __importStar(require("fast-csv"));
|
|
46
|
-
class CSVModuleV3_Class extends module_1.Module {
|
|
18
|
+
import { Module } from '../core/module.js';
|
|
19
|
+
import * as csv from 'fast-csv';
|
|
20
|
+
export class CSVModuleV3_Class extends Module {
|
|
47
21
|
constructor() {
|
|
48
22
|
super();
|
|
49
|
-
this.readFromStream = async (stream, processor) => {
|
|
50
|
-
return this.readImpl(stream, processor);
|
|
51
|
-
};
|
|
52
|
-
this.readImpl = async (stream, processor) => {
|
|
53
|
-
return new Promise((resolve, reject) => {
|
|
54
|
-
let rowIndex = 0;
|
|
55
|
-
const csvParser = csv.parse({ headers: true, trim: true });
|
|
56
|
-
csvParser
|
|
57
|
-
.on('data', (instance) => {
|
|
58
|
-
processor(instance, rowIndex++, csvParser);
|
|
59
|
-
})
|
|
60
|
-
.on('error', (err) => reject(err))
|
|
61
|
-
.on('end', () => {
|
|
62
|
-
this.logInfo('read ended');
|
|
63
|
-
resolve();
|
|
64
|
-
});
|
|
65
|
-
stream.pipe(csvParser);
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
this.writeToStream = (writable, items, options) => {
|
|
69
|
-
return this.writeImpl(writable, items, options);
|
|
70
|
-
};
|
|
71
|
-
this.writeImpl = (writable, items, options) => {
|
|
72
|
-
return new Promise((resolve, reject) => {
|
|
73
|
-
csv.writeToStream(writable, items, options)
|
|
74
|
-
.on('finish', () => resolve())
|
|
75
|
-
.on('error', err => reject(err));
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
this.provideFormatter = (transformer = item => item) => {
|
|
79
|
-
return csv.format({ headers: true })
|
|
80
|
-
.transform(transformer);
|
|
81
|
-
};
|
|
82
|
-
this.provideFormatterFromCsv = (transformer = item => item) => {
|
|
83
|
-
return csv.parse({ headers: true, trim: true })
|
|
84
|
-
.transform(transformer);
|
|
85
|
-
};
|
|
86
|
-
this.fromString = async (str) => {
|
|
87
|
-
return new Promise((resolve, reject) => {
|
|
88
|
-
const data = [];
|
|
89
|
-
csv.parseString(str, { headers: true })
|
|
90
|
-
.on('data', row => {
|
|
91
|
-
console.log('HERE - data');
|
|
92
|
-
data.push(row);
|
|
93
|
-
})
|
|
94
|
-
.on('end', () => {
|
|
95
|
-
console.log('HERE - end');
|
|
96
|
-
resolve(data);
|
|
97
|
-
})
|
|
98
|
-
.on('error', err => {
|
|
99
|
-
console.log('HERE - err');
|
|
100
|
-
reject(err);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
};
|
|
104
23
|
}
|
|
105
24
|
init() {
|
|
106
25
|
}
|
|
26
|
+
readFromStream = async (stream, processor) => {
|
|
27
|
+
return this.readImpl(stream, processor);
|
|
28
|
+
};
|
|
29
|
+
readImpl = async (stream, processor) => {
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
let rowIndex = 0;
|
|
32
|
+
const csvParser = csv.parse({ headers: true, trim: true });
|
|
33
|
+
csvParser
|
|
34
|
+
.on('data', (instance) => {
|
|
35
|
+
processor(instance, rowIndex++, csvParser);
|
|
36
|
+
})
|
|
37
|
+
.on('error', (err) => reject(err))
|
|
38
|
+
.on('end', () => {
|
|
39
|
+
this.logInfo('read ended');
|
|
40
|
+
resolve();
|
|
41
|
+
});
|
|
42
|
+
stream.pipe(csvParser);
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
writeToStream = (writable, items, options) => {
|
|
46
|
+
return this.writeImpl(writable, items, options);
|
|
47
|
+
};
|
|
48
|
+
writeImpl = (writable, items, options) => {
|
|
49
|
+
return new Promise((resolve, reject) => {
|
|
50
|
+
csv.writeToStream(writable, items, options)
|
|
51
|
+
.on('finish', () => resolve())
|
|
52
|
+
.on('error', err => reject(err));
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
provideFormatter = (transformer = item => item) => {
|
|
56
|
+
return csv.format({ headers: true })
|
|
57
|
+
.transform(transformer);
|
|
58
|
+
};
|
|
59
|
+
provideFormatterFromCsv = (transformer = item => item) => {
|
|
60
|
+
return csv.parse({ headers: true, trim: true })
|
|
61
|
+
.transform(transformer);
|
|
62
|
+
};
|
|
63
|
+
fromString = async (str) => {
|
|
64
|
+
return new Promise((resolve, reject) => {
|
|
65
|
+
const data = [];
|
|
66
|
+
csv.parseString(str, { headers: true })
|
|
67
|
+
.on('data', row => {
|
|
68
|
+
console.log('HERE - data');
|
|
69
|
+
data.push(row);
|
|
70
|
+
})
|
|
71
|
+
.on('end', () => {
|
|
72
|
+
console.log('HERE - end');
|
|
73
|
+
resolve(data);
|
|
74
|
+
})
|
|
75
|
+
.on('error', err => {
|
|
76
|
+
console.log('HERE - err');
|
|
77
|
+
reject(err);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
};
|
|
107
81
|
}
|
|
108
|
-
|
|
109
|
-
|
|
82
|
+
export const CSVModuleV3 = new CSVModuleV3_Class();
|
|
83
|
+
//# sourceMappingURL=CSVModuleV3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CSVModuleV3.js","sourceRoot":"/Users/tacb0ss/dev/nu-art/beamz/_thunderstorm/ts-common/src/main/","sources":["modules/CSVModuleV3.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAOH,OAAO,EAAC,MAAM,EAAC,MAAM,mBAAmB,CAAC;AACzC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAEhC,MAAM,OAAO,iBACZ,SAAQ,MAAM;IAEd;QACC,KAAK,EAAE,CAAC;IACT,CAAC;IAES,IAAI;IACd,CAAC;IAEM,cAAc,GAAG,KAAK,EAAK,MAAgB,EAAE,SAAoH,EAAiB,EAAE;QAC1L,OAAO,IAAI,CAAC,QAAQ,CAAI,MAAM,EAAE,SAAS,CAAC,CAAC;IAC5C,CAAC,CAAC;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C,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IAEJ,CAAC,CAAC;CACF;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,iBAAiB,EAAE,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Module } from '../core/module';
|
|
2
|
-
import { TypedMap } from '../utils/types';
|
|
1
|
+
import { Module } from '../core/module.js';
|
|
2
|
+
import { TypedMap } from '../utils/types.js';
|
|
3
3
|
export type CliParam<K, T extends string | string[] = string> = {
|
|
4
4
|
keys: string[];
|
|
5
5
|
name: string;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*
|
|
3
2
|
* ts-common is the basic building blocks of our typescript projects
|
|
4
3
|
*
|
|
@@ -16,28 +15,11 @@
|
|
|
16
15
|
* See the License for the specific language governing permissions and
|
|
17
16
|
* limitations under the License.
|
|
18
17
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
class CliParamsModule_Class extends module_1.Module {
|
|
25
|
-
constructor() {
|
|
26
|
-
super(...arguments);
|
|
27
|
-
this.paramsValue = {};
|
|
28
|
-
this.printHowTo = (params) => {
|
|
29
|
-
const missingParams = params.filter((param) => !this.paramsValue[param.keyName] && !param.optional);
|
|
30
|
-
const foundParams = params.filter((param) => this.paramsValue[param.keyName]);
|
|
31
|
-
this.printFoundArgs('Found Args', foundParams, this.paramsValue);
|
|
32
|
-
if (missingParams.length === 0)
|
|
33
|
-
return;
|
|
34
|
-
this.printFoundArgs('Missing Args', missingParams, this.paramsValue);
|
|
35
|
-
throw new exceptions_1.ImplementationMissingException('Missing cli params');
|
|
36
|
-
};
|
|
37
|
-
this.getParams = () => {
|
|
38
|
-
return this.paramsValue;
|
|
39
|
-
};
|
|
40
|
-
}
|
|
18
|
+
import { Module } from '../core/module.js';
|
|
19
|
+
import { BadImplementationException, ImplementationMissingException } from '../core/exceptions/exceptions.js';
|
|
20
|
+
import { filterInstances, flatArray } from '../utils/array-tools.js';
|
|
21
|
+
class CliParamsModule_Class extends Module {
|
|
22
|
+
paramsValue = {};
|
|
41
23
|
init() {
|
|
42
24
|
this.config.params.forEach((param) => this.paramsValue[param.keyName] = this.getParam(param));
|
|
43
25
|
this.printHowTo(this.config.params);
|
|
@@ -45,7 +27,7 @@ class CliParamsModule_Class extends module_1.Module {
|
|
|
45
27
|
}
|
|
46
28
|
getParam(param, args = process.argv.slice(2, process.argv.length)) {
|
|
47
29
|
if (!this.config.params.find(_param => _param.keyName === param.keyName))
|
|
48
|
-
throw new
|
|
30
|
+
throw new BadImplementationException('Requested not existing param');
|
|
49
31
|
let value = this.extractParam(param, args);
|
|
50
32
|
if (!value)
|
|
51
33
|
value = param.defaultValue;
|
|
@@ -56,17 +38,30 @@ class CliParamsModule_Class extends module_1.Module {
|
|
|
56
38
|
extractParam(param, argv) {
|
|
57
39
|
if (param.isArray)
|
|
58
40
|
return param.keys.reduce((values, key) => {
|
|
59
|
-
values.push(...
|
|
41
|
+
values.push(...filterInstances(argv.map(arg => arg.match(new RegExp(`${key}=(.*)`))?.[1])));
|
|
60
42
|
return values;
|
|
61
43
|
}, []);
|
|
62
|
-
const find = param.keys.map(key => argv.map(arg =>
|
|
63
|
-
return
|
|
44
|
+
const find = param.keys.map(key => argv.map(arg => arg.match(new RegExp(`${key}=(.*)`))?.[1]));
|
|
45
|
+
return flatArray(find).find(k => k);
|
|
64
46
|
}
|
|
47
|
+
printHowTo = (params) => {
|
|
48
|
+
const missingParams = params.filter((param) => !this.paramsValue[param.keyName] && !param.optional);
|
|
49
|
+
const foundParams = params.filter((param) => this.paramsValue[param.keyName]);
|
|
50
|
+
this.printFoundArgs('Found Args', foundParams, this.paramsValue);
|
|
51
|
+
if (missingParams.length === 0)
|
|
52
|
+
return;
|
|
53
|
+
this.printFoundArgs('Missing Args', missingParams, this.paramsValue);
|
|
54
|
+
throw new ImplementationMissingException('Missing cli params');
|
|
55
|
+
};
|
|
65
56
|
printFoundArgs(title, params, foundArgs) {
|
|
66
57
|
if (params.length)
|
|
67
58
|
return;
|
|
68
59
|
this.logInfoBold(` ${title}:`);
|
|
69
60
|
params.forEach((param) => this.logInfo(` ${param.keys[0]}=${foundArgs[param.keyName] || `<${param.name}>`}`));
|
|
70
61
|
}
|
|
62
|
+
getParams = () => {
|
|
63
|
+
return this.paramsValue;
|
|
64
|
+
};
|
|
71
65
|
}
|
|
72
|
-
|
|
66
|
+
export const CliParamsModule = new CliParamsModule_Class();
|
|
67
|
+
//# sourceMappingURL=CliParamsModule.js.map
|