@nu-art/ts-common 0.204.0 → 0.204.1
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/dispatcher.js +19 -36
- package/mem-storage/MemStorage.js +4 -15
- package/modules/CSVModule.js +53 -76
- package/modules/CSVModuleV3.js +6 -15
- package/modules/JSONCSVModule.js +4 -13
- package/package.json +1 -1
- package/testing/consts.js +4 -13
- package/utils/array-tools.js +37 -54
- package/utils/date-time-tools.js +2 -13
- package/utils/queue-v2.js +4 -15
- package/utils/queue.js +7 -18
- package/utils/tools.js +2 -11
- package/utils/ui-tools.js +6 -15
package/core/dispatcher.js
CHANGED
|
@@ -16,15 +16,6 @@
|
|
|
16
16
|
* See the License for the specific language governing permissions and
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
20
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
21
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
22
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
23
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
24
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
25
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
20
|
exports.Dispatcher = exports.Processor = void 0;
|
|
30
21
|
const Logger_1 = require("./logger/Logger");
|
|
@@ -37,20 +28,16 @@ class Processor extends Logger_1.Logger {
|
|
|
37
28
|
processModules(processor) {
|
|
38
29
|
return this.filterModules().filter(this.filter).map(processor);
|
|
39
30
|
}
|
|
40
|
-
processModulesAsync(processor) {
|
|
41
|
-
return
|
|
42
|
-
return Promise.all(this.filterModules().map(processor));
|
|
43
|
-
});
|
|
31
|
+
async processModulesAsync(processor) {
|
|
32
|
+
return Promise.all(this.filterModules().map(processor));
|
|
44
33
|
}
|
|
45
|
-
processModulesAsyncSerial(processor) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return toRet;
|
|
53
|
-
});
|
|
34
|
+
async processModulesAsyncSerial(processor) {
|
|
35
|
+
const modules = this.filterModules();
|
|
36
|
+
const toRet = [];
|
|
37
|
+
for (const module of modules) {
|
|
38
|
+
toRet.push(await processor(module));
|
|
39
|
+
}
|
|
40
|
+
return toRet;
|
|
54
41
|
}
|
|
55
42
|
filterModules() {
|
|
56
43
|
const listeners = Dispatcher.modulesResolver();
|
|
@@ -68,26 +55,22 @@ class Dispatcher extends Processor {
|
|
|
68
55
|
return (listener[this.method])(...p);
|
|
69
56
|
});
|
|
70
57
|
}
|
|
71
|
-
dispatchModuleAsync(...p) {
|
|
72
|
-
return
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return listener[this.method](...p);
|
|
78
|
-
});
|
|
58
|
+
async dispatchModuleAsync(...p) {
|
|
59
|
+
return this.processModulesAsync((listener) => {
|
|
60
|
+
// const newVar = this.resolveListenerName(listener);
|
|
61
|
+
// this.logVerbose(`Calling ${newVar} (${p})`);
|
|
62
|
+
// @ts-ignore
|
|
63
|
+
return listener[this.method](...p);
|
|
79
64
|
});
|
|
80
65
|
}
|
|
81
66
|
// private resolveListenerName(listener: any) {
|
|
82
67
|
// return 'name' in listener ? listener.name :
|
|
83
68
|
// 'constructor' in listener ? listener['constructor']['name'] : '';
|
|
84
69
|
// }
|
|
85
|
-
dispatchModuleAsyncSerial(...p) {
|
|
86
|
-
return
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return listener[this.method](...p);
|
|
90
|
-
});
|
|
70
|
+
async dispatchModuleAsyncSerial(...p) {
|
|
71
|
+
return this.processModulesAsyncSerial((listener) => {
|
|
72
|
+
// @ts-ignore
|
|
73
|
+
return listener[this.method](...p);
|
|
91
74
|
});
|
|
92
75
|
}
|
|
93
76
|
}
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.MemKey = exports.MemStorage = void 0;
|
|
13
4
|
const tools_1 = require("../utils/tools");
|
|
@@ -37,10 +28,8 @@ class MemStorage {
|
|
|
37
28
|
return currentValue;
|
|
38
29
|
};
|
|
39
30
|
}
|
|
40
|
-
init(makeItContext) {
|
|
41
|
-
return
|
|
42
|
-
return asyncLocalStorage.run(this, makeItContext);
|
|
43
|
-
});
|
|
31
|
+
async init(makeItContext) {
|
|
32
|
+
return asyncLocalStorage.run(this, makeItContext);
|
|
44
33
|
}
|
|
45
34
|
initSync(makeItContext) {
|
|
46
35
|
return asyncLocalStorage.run(this, makeItContext);
|
|
@@ -53,13 +42,13 @@ class MemKey {
|
|
|
53
42
|
this.resolver = resolver;
|
|
54
43
|
return this;
|
|
55
44
|
};
|
|
56
|
-
this.resolve = (storage) =>
|
|
45
|
+
this.resolve = async (storage) => {
|
|
57
46
|
var _a;
|
|
58
47
|
const value = (_a = this.resolver) === null || _a === void 0 ? void 0 : _a.call(this, storage);
|
|
59
48
|
if (!(0, tools_1.exists)(value))
|
|
60
49
|
return;
|
|
61
50
|
this.set(value);
|
|
62
|
-
}
|
|
51
|
+
};
|
|
63
52
|
this.assert = (value) => {
|
|
64
53
|
const storedValue = this.get();
|
|
65
54
|
if (!(0, tools_1.exists)(value))
|
package/modules/CSVModule.js
CHANGED
|
@@ -16,15 +16,6 @@
|
|
|
16
16
|
* See the License for the specific language governing permissions and
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
20
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
21
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
22
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
23
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
24
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
25
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
20
|
exports.CSVModule = void 0;
|
|
30
21
|
/**
|
|
@@ -67,84 +58,70 @@ class CSVModule_Class extends module_1.Module {
|
|
|
67
58
|
export(items, returnCsv = true) {
|
|
68
59
|
return this.csvExporter.generateCsv(items, returnCsv);
|
|
69
60
|
}
|
|
70
|
-
saveToFile(outputFile, items, columnsToProps) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return fs_1.promises.writeFile(outputFile, csv, { encoding: 'utf8' });
|
|
74
|
-
});
|
|
61
|
+
async saveToFile(outputFile, items, columnsToProps) {
|
|
62
|
+
const csv = this.csvExporter.generateCsv(items, true);
|
|
63
|
+
return fs_1.promises.writeFile(outputFile, csv, { encoding: 'utf8' });
|
|
75
64
|
}
|
|
76
|
-
readCsvFromFile(inputFile, readOptions) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return this.readCsvFromStream(stream, readOptions);
|
|
80
|
-
});
|
|
65
|
+
async readCsvFromFile(inputFile, readOptions) {
|
|
66
|
+
const stream = (0, fs_1.createReadStream)(inputFile, { encoding: 'utf8' });
|
|
67
|
+
return this.readCsvFromStream(stream, readOptions);
|
|
81
68
|
}
|
|
82
|
-
readCsvFromBuffer(buffer, readOptions) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return this.readCsvFromStream(stream, readOptions);
|
|
86
|
-
});
|
|
69
|
+
async readCsvFromBuffer(buffer, readOptions) {
|
|
70
|
+
const stream = stream_1.Readable.from(buffer.toString('utf-8'), { encoding: 'utf8' });
|
|
71
|
+
return this.readCsvFromStream(stream, readOptions);
|
|
87
72
|
}
|
|
88
|
-
readCsvFromStream(stream, readOptions = {}) {
|
|
89
|
-
return
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
.on('end', () => resolve(results));
|
|
100
|
-
});
|
|
73
|
+
async readCsvFromStream(stream, readOptions = {}) {
|
|
74
|
+
return new Promise((resolve, reject) => {
|
|
75
|
+
const results = [];
|
|
76
|
+
stream
|
|
77
|
+
.pipe(csvParser(this.createReadParserOptions(readOptions)))
|
|
78
|
+
.on('data', (instance) => {
|
|
79
|
+
delete instance['undefined'];
|
|
80
|
+
results.push(instance);
|
|
81
|
+
})
|
|
82
|
+
.on('error', (err) => reject(err))
|
|
83
|
+
.on('end', () => resolve(results));
|
|
101
84
|
});
|
|
102
85
|
}
|
|
103
|
-
forEachCsvRowFromStreamAsync(stream, callback, readOptions = {}, queueCount = 5) {
|
|
104
|
-
return
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
.on('end', () => instancesQueue.setOnQueueEmpty(() => resolve()));
|
|
113
|
-
});
|
|
86
|
+
async forEachCsvRowFromStreamAsync(stream, callback, readOptions = {}, queueCount = 5) {
|
|
87
|
+
return new Promise((resolve, reject) => {
|
|
88
|
+
const instancesQueue = new queue_1.Queue('instancesQueue');
|
|
89
|
+
instancesQueue.setParallelCount(queueCount);
|
|
90
|
+
stream
|
|
91
|
+
.pipe(csvParser(this.createReadParserOptions(readOptions)))
|
|
92
|
+
.on('data', (instance) => instancesQueue.addItem(() => callback(instance)))
|
|
93
|
+
.on('error', (err) => reject(err))
|
|
94
|
+
.on('end', () => instancesQueue.setOnQueueEmpty(() => resolve()));
|
|
114
95
|
});
|
|
115
96
|
}
|
|
116
|
-
forEachCsvRowFromStreamSync(stream, callback, readOptions = {}) {
|
|
117
|
-
return
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
resolve();
|
|
128
|
-
});
|
|
97
|
+
async forEachCsvRowFromStreamSync(stream, callback, readOptions = {}) {
|
|
98
|
+
return new Promise((resolve, reject) => {
|
|
99
|
+
let rowIndex = 0;
|
|
100
|
+
const csvStream = csvParser(this.createReadParserOptions(readOptions));
|
|
101
|
+
stream
|
|
102
|
+
.pipe(csvStream)
|
|
103
|
+
.on('data', (instance) => callback(instance, rowIndex++, csvStream))
|
|
104
|
+
.on('error', (err) => reject(err))
|
|
105
|
+
.on('end', () => {
|
|
106
|
+
this.logInfo('read ended');
|
|
107
|
+
resolve();
|
|
129
108
|
});
|
|
130
109
|
});
|
|
131
110
|
}
|
|
132
|
-
forEachCsvRowFromStreamSync_FastCSV(stream, callback, readOptions = {}) {
|
|
133
|
-
return
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
resolve();
|
|
145
|
-
});
|
|
146
|
-
stream.pipe(csvStream);
|
|
111
|
+
async forEachCsvRowFromStreamSync_FastCSV(stream, callback, readOptions = {}) {
|
|
112
|
+
return new Promise((resolve, reject) => {
|
|
113
|
+
let rowIndex = 0;
|
|
114
|
+
const csvStream = csv.parse({ headers: true, trim: true });
|
|
115
|
+
csvStream
|
|
116
|
+
.on('data', (instance) => {
|
|
117
|
+
callback(instance, rowIndex++, csvStream);
|
|
118
|
+
})
|
|
119
|
+
.on('error', (err) => reject(err))
|
|
120
|
+
.on('end', () => {
|
|
121
|
+
this.logInfo('read ended');
|
|
122
|
+
resolve();
|
|
147
123
|
});
|
|
124
|
+
stream.pipe(csvStream);
|
|
148
125
|
});
|
|
149
126
|
}
|
|
150
127
|
createReadParserOptions(readOptions) {
|
package/modules/CSVModuleV3.js
CHANGED
|
@@ -16,15 +16,6 @@
|
|
|
16
16
|
* See the License for the specific language governing permissions and
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
20
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
21
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
22
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
23
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
24
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
25
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
20
|
exports.CSVModuleV3 = exports.CSVModuleV3_Class = void 0;
|
|
30
21
|
const module_1 = require("../core/module");
|
|
@@ -32,10 +23,10 @@ const csv = require("fast-csv");
|
|
|
32
23
|
class CSVModuleV3_Class extends module_1.Module {
|
|
33
24
|
constructor() {
|
|
34
25
|
super();
|
|
35
|
-
this.readFromStream = (stream, processor) =>
|
|
26
|
+
this.readFromStream = async (stream, processor) => {
|
|
36
27
|
return this.readImpl(stream, processor);
|
|
37
|
-
}
|
|
38
|
-
this.readImpl = (stream, processor) =>
|
|
28
|
+
};
|
|
29
|
+
this.readImpl = async (stream, processor) => {
|
|
39
30
|
return new Promise((resolve, reject) => {
|
|
40
31
|
let rowIndex = 0;
|
|
41
32
|
const csvParser = csv.parse({ headers: true, trim: true });
|
|
@@ -50,7 +41,7 @@ class CSVModuleV3_Class extends module_1.Module {
|
|
|
50
41
|
});
|
|
51
42
|
stream.pipe(csvParser);
|
|
52
43
|
});
|
|
53
|
-
}
|
|
44
|
+
};
|
|
54
45
|
this.writeToStream = (writable, items, options) => {
|
|
55
46
|
return this.writeImpl(writable, items, options);
|
|
56
47
|
};
|
|
@@ -69,7 +60,7 @@ class CSVModuleV3_Class extends module_1.Module {
|
|
|
69
60
|
return csv.parse({ headers: true, trim: true })
|
|
70
61
|
.transform(transformer);
|
|
71
62
|
};
|
|
72
|
-
this.fromString = (str) =>
|
|
63
|
+
this.fromString = async (str) => {
|
|
73
64
|
return new Promise((resolve, reject) => {
|
|
74
65
|
const data = [];
|
|
75
66
|
csv.parseString(str, { headers: true })
|
|
@@ -86,7 +77,7 @@ class CSVModuleV3_Class extends module_1.Module {
|
|
|
86
77
|
reject(err);
|
|
87
78
|
});
|
|
88
79
|
});
|
|
89
|
-
}
|
|
80
|
+
};
|
|
90
81
|
}
|
|
91
82
|
init() {
|
|
92
83
|
}
|
package/modules/JSONCSVModule.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.JSONCSVModule_Class = void 0;
|
|
13
4
|
const CSVModuleV3_1 = require("./CSVModuleV3");
|
|
@@ -38,16 +29,16 @@ class JSONCSVModule_Class extends CSVModuleV3_1.CSVModuleV3_Class {
|
|
|
38
29
|
return i;
|
|
39
30
|
};
|
|
40
31
|
// @ts-ignore
|
|
41
|
-
this.writeImpl = (writable, items, options) =>
|
|
32
|
+
this.writeImpl = async (writable, items, options) => {
|
|
42
33
|
return new Promise((resolve, reject) => {
|
|
43
34
|
const _options = Object.assign(Object.assign({}, options), { transform: this.processToJSON });
|
|
44
35
|
csv.writeToStream(writable, items, _options)
|
|
45
36
|
.on('finish', () => resolve())
|
|
46
37
|
.on('error', err => reject(err));
|
|
47
38
|
});
|
|
48
|
-
}
|
|
39
|
+
};
|
|
49
40
|
// @ts-ignore
|
|
50
|
-
this.readImpl = (stream, processor) =>
|
|
41
|
+
this.readImpl = async (stream, processor) => {
|
|
51
42
|
return new Promise((resolve, reject) => {
|
|
52
43
|
let rowIndex = 0;
|
|
53
44
|
const csvParser = csv.parse({ headers: true, trim: true });
|
|
@@ -62,7 +53,7 @@ class JSONCSVModule_Class extends CSVModuleV3_1.CSVModuleV3_Class {
|
|
|
62
53
|
});
|
|
63
54
|
stream.pipe(csvParser);
|
|
64
55
|
});
|
|
65
|
-
}
|
|
56
|
+
};
|
|
66
57
|
this.keysToStringify = keysToStringify;
|
|
67
58
|
}
|
|
68
59
|
}
|
package/package.json
CHANGED
package/testing/consts.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.expectFailAsync = exports.testSuiteTester = exports.testSuite_RunTest = exports.ModuleManagerTester = void 0;
|
|
13
4
|
const chai_1 = require("chai");
|
|
@@ -31,14 +22,14 @@ const testSuiteTester = (testSuit, ...testcases) => {
|
|
|
31
22
|
it(`${testSuit.label} - Preprocessing`, testSuit.preProcessor);
|
|
32
23
|
}
|
|
33
24
|
(testcases.length > 0 ? testcases : testSuit.testcases).forEach(testCase => {
|
|
34
|
-
new MemStorage_1.MemStorage().init(() =>
|
|
25
|
+
new MemStorage_1.MemStorage().init(async () => testSuite_RunTest(testSuit, testCase));
|
|
35
26
|
});
|
|
36
27
|
}).timeout(testSuit.timeout || 5000);
|
|
37
28
|
};
|
|
38
29
|
exports.testSuiteTester = testSuiteTester;
|
|
39
|
-
const expectFailAsync = (action) =>
|
|
30
|
+
const expectFailAsync = async (action) => {
|
|
40
31
|
try {
|
|
41
|
-
|
|
32
|
+
await action();
|
|
42
33
|
return (0, chai_1.expect)(tools_1.voidFunction);
|
|
43
34
|
}
|
|
44
35
|
catch (e) {
|
|
@@ -46,5 +37,5 @@ const expectFailAsync = (action) => __awaiter(void 0, void 0, void 0, function*
|
|
|
46
37
|
throw e;
|
|
47
38
|
});
|
|
48
39
|
}
|
|
49
|
-
}
|
|
40
|
+
};
|
|
50
41
|
exports.expectFailAsync = expectFailAsync;
|
package/utils/array-tools.js
CHANGED
|
@@ -16,15 +16,6 @@
|
|
|
16
16
|
* See the License for the specific language governing permissions and
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
20
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
21
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
22
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
23
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
24
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
25
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
20
|
exports.arrayIncludesAll = 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;
|
|
30
21
|
const tools_1 = require("./tools");
|
|
@@ -103,12 +94,10 @@ exports.toggleElementInArray = toggleElementInArray;
|
|
|
103
94
|
/**
|
|
104
95
|
* Removes all items answering the condition given from array in place
|
|
105
96
|
*/
|
|
106
|
-
function filterAsync(arr, filter) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
return arr.filter((item, index) => boolArray[index]);
|
|
111
|
-
});
|
|
97
|
+
async function filterAsync(arr, filter) {
|
|
98
|
+
//const boolArray = await arr.map(item => filter(item)); changed
|
|
99
|
+
const boolArray = await Promise.all(arr.map(item => filter(item)));
|
|
100
|
+
return arr.filter((item, index) => boolArray[index]);
|
|
112
101
|
}
|
|
113
102
|
exports.filterAsync = filterAsync;
|
|
114
103
|
/**
|
|
@@ -193,19 +182,17 @@ exports.sortArray = sortArray;
|
|
|
193
182
|
/**
|
|
194
183
|
* "splits" array into given size of chunks and then does "action" on chunk and return to array of actions on chunks +-
|
|
195
184
|
* */
|
|
196
|
-
function batchAction(arr, chunk, action) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
return result;
|
|
208
|
-
});
|
|
185
|
+
async function batchAction(arr, chunk, action) {
|
|
186
|
+
const result = [];
|
|
187
|
+
for (let i = 0, j = arr.length; i < j; i += chunk) {
|
|
188
|
+
const items = await action(arr.slice(i, i + chunk));
|
|
189
|
+
if (Array.isArray(items))
|
|
190
|
+
//addAllItemToArray(result, items);
|
|
191
|
+
result.push(...items);
|
|
192
|
+
else
|
|
193
|
+
addItemToArray(result, items);
|
|
194
|
+
}
|
|
195
|
+
return result;
|
|
209
196
|
}
|
|
210
197
|
exports.batchAction = batchAction;
|
|
211
198
|
/**
|
|
@@ -226,34 +213,30 @@ exports.batchAction = batchAction;
|
|
|
226
213
|
* ```
|
|
227
214
|
* @param promises
|
|
228
215
|
*/
|
|
229
|
-
function Promise_all_sequentially(promises) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
return results;
|
|
236
|
-
});
|
|
216
|
+
async function Promise_all_sequentially(promises) {
|
|
217
|
+
const results = [];
|
|
218
|
+
for (const promise of promises) {
|
|
219
|
+
results.push(await promise());
|
|
220
|
+
}
|
|
221
|
+
return results;
|
|
237
222
|
}
|
|
238
223
|
exports.Promise_all_sequentially = Promise_all_sequentially;
|
|
239
|
-
function batchActionParallel(arr, chunk, action) {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
return toRet;
|
|
256
|
-
});
|
|
224
|
+
async function batchActionParallel(arr, chunk, action) {
|
|
225
|
+
const promises = [];
|
|
226
|
+
for (let i = 0, j = arr.length; i < j; i += chunk) {
|
|
227
|
+
addItemToArray(promises, action(arr.slice(i, i + chunk)));
|
|
228
|
+
}
|
|
229
|
+
const toRet = [];
|
|
230
|
+
const results = await Promise.all(promises);
|
|
231
|
+
for (const items of results) {
|
|
232
|
+
if (Array.isArray(items))
|
|
233
|
+
//addAllItemToArray(toRet, items);
|
|
234
|
+
toRet.push(...items);
|
|
235
|
+
else
|
|
236
|
+
//addItemToArray(toRet, items);
|
|
237
|
+
toRet.push(items);
|
|
238
|
+
}
|
|
239
|
+
return toRet;
|
|
257
240
|
}
|
|
258
241
|
exports.batchActionParallel = batchActionParallel;
|
|
259
242
|
/**
|
package/utils/date-time-tools.js
CHANGED
|
@@ -16,15 +16,6 @@
|
|
|
16
16
|
* See the License for the specific language governing permissions and
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
20
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
21
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
22
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
23
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
24
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
25
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
20
|
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;
|
|
30
21
|
const moment = require("moment");
|
|
@@ -39,10 +30,8 @@ exports.Month = exports.Year / 12;
|
|
|
39
30
|
exports.Format_HHmmss_DDMMYYYY = 'HH:mm:ss_DD-MM-YYYY';
|
|
40
31
|
exports.Format_YYYYMMDD_HHmmss = 'YYYY-MM-DD_HH:mm:ss';
|
|
41
32
|
exports.Weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
|
42
|
-
function timeout(sleepMs) {
|
|
43
|
-
return
|
|
44
|
-
return new Promise(resolve => setTimeout(resolve, sleepMs, undefined));
|
|
45
|
-
});
|
|
33
|
+
async function timeout(sleepMs) {
|
|
34
|
+
return new Promise(resolve => setTimeout(resolve, sleepMs, undefined));
|
|
46
35
|
}
|
|
47
36
|
exports.timeout = timeout;
|
|
48
37
|
exports.sleep = timeout;
|
package/utils/queue-v2.js
CHANGED
|
@@ -16,15 +16,6 @@
|
|
|
16
16
|
* See the License for the specific language governing permissions and
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
20
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
21
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
22
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
23
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
24
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
25
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
20
|
exports.QueueV2 = void 0;
|
|
30
21
|
const Logger_1 = require("../core/logger/Logger");
|
|
@@ -106,12 +97,10 @@ class QueueV2 extends Logger_1.Logger {
|
|
|
106
97
|
this.filter = filter;
|
|
107
98
|
return this;
|
|
108
99
|
}
|
|
109
|
-
executeSync() {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
this.execute();
|
|
114
|
-
});
|
|
100
|
+
async executeSync() {
|
|
101
|
+
await new Promise(resolve => {
|
|
102
|
+
this.finalResolve = resolve;
|
|
103
|
+
this.execute();
|
|
115
104
|
});
|
|
116
105
|
}
|
|
117
106
|
}
|
package/utils/queue.js
CHANGED
|
@@ -16,15 +16,6 @@
|
|
|
16
16
|
* See the License for the specific language governing permissions and
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
20
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
21
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
22
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
23
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
24
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
25
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
20
|
exports.Queue = void 0;
|
|
30
21
|
const Logger_1 = require("../core/logger/Logger");
|
|
@@ -51,10 +42,10 @@ class Queue extends Logger_1.Logger {
|
|
|
51
42
|
this.execute();
|
|
52
43
|
}
|
|
53
44
|
addItemImpl(toExecute, onCompleted, onError) {
|
|
54
|
-
(0, array_tools_1.addItemToArray)(this.queue, (resolve) =>
|
|
45
|
+
(0, array_tools_1.addItemToArray)(this.queue, async (resolve) => {
|
|
55
46
|
this.runningOperationsCount++;
|
|
56
47
|
try {
|
|
57
|
-
const output =
|
|
48
|
+
const output = await toExecute();
|
|
58
49
|
onCompleted && onCompleted(output);
|
|
59
50
|
}
|
|
60
51
|
catch (e) {
|
|
@@ -70,7 +61,7 @@ class Queue extends Logger_1.Logger {
|
|
|
70
61
|
this.runningOperationsCount--;
|
|
71
62
|
resolve();
|
|
72
63
|
this.execute();
|
|
73
|
-
})
|
|
64
|
+
});
|
|
74
65
|
}
|
|
75
66
|
execute() {
|
|
76
67
|
var _a;
|
|
@@ -86,12 +77,10 @@ class Queue extends Logger_1.Logger {
|
|
|
86
77
|
.catch(this.ignore);
|
|
87
78
|
}
|
|
88
79
|
}
|
|
89
|
-
executeSync() {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
this.execute();
|
|
94
|
-
});
|
|
80
|
+
async executeSync() {
|
|
81
|
+
await new Promise(resolve => {
|
|
82
|
+
this.finalResolve = resolve;
|
|
83
|
+
this.execute();
|
|
95
84
|
});
|
|
96
85
|
}
|
|
97
86
|
}
|
package/utils/tools.js
CHANGED
|
@@ -16,15 +16,6 @@
|
|
|
16
16
|
* See the License for the specific language governing permissions and
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
20
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
21
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
22
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
23
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
24
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
25
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
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;
|
|
30
21
|
const object_tools_1 = require("./object-tools");
|
|
@@ -62,8 +53,8 @@ function __stringify(obj, pretty) {
|
|
|
62
53
|
exports.__stringify = __stringify;
|
|
63
54
|
exports.EmptyObject = Object.freeze({});
|
|
64
55
|
exports.EmptyArray = Object.freeze([]);
|
|
65
|
-
exports.voidFunction = Object.freeze(() =>
|
|
66
|
-
})
|
|
56
|
+
exports.voidFunction = Object.freeze(async () => {
|
|
57
|
+
});
|
|
67
58
|
exports.functionThatReturnsFalse = Object.freeze(() => false);
|
|
68
59
|
exports.functionThatReturnsTrue = Object.freeze(() => true);
|
|
69
60
|
const resolveContent = (content, ...param) => {
|
package/utils/ui-tools.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.awaitedDebounce = exports.debounce = void 0;
|
|
13
4
|
/**
|
|
@@ -73,16 +64,16 @@ const awaitedDebounce = (params) => {
|
|
|
73
64
|
var _a, _b;
|
|
74
65
|
const timeout = (_a = params.timeout) !== null && _a !== void 0 ? _a : 500;
|
|
75
66
|
_clearTimeout('timer');
|
|
76
|
-
timers.timer = setTimeout(() =>
|
|
67
|
+
timers.timer = setTimeout(async () => {
|
|
77
68
|
_clearTimeouts();
|
|
78
|
-
resolve(
|
|
79
|
-
}
|
|
69
|
+
resolve(await params.func(...args));
|
|
70
|
+
}, timeout);
|
|
80
71
|
if (!timers.fallbackTimer) {
|
|
81
72
|
const fallbackTimeout = (_b = params.fallbackTimeout) !== null && _b !== void 0 ? _b : 1000;
|
|
82
|
-
timers.fallbackTimer = setTimeout(() =>
|
|
73
|
+
timers.fallbackTimer = setTimeout(async () => {
|
|
83
74
|
_clearTimeouts();
|
|
84
|
-
resolve(
|
|
85
|
-
}
|
|
75
|
+
resolve(await params.func(...args));
|
|
76
|
+
}, fallbackTimeout);
|
|
86
77
|
}
|
|
87
78
|
});
|
|
88
79
|
};
|