dce-commonkit 4.4.3 → 5.0.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/lib/helpers/parallelLimit.d.ts +7 -1
- package/lib/helpers/parallelLimit.js +34 -8
- package/lib/helpers/parallelLimit.js.map +1 -1
- package/lib/index.d.ts +6 -1
- package/lib/index.js.map +1 -1
- package/package.json +3 -2
- package/src/helpers/parallelLimit.ts +37 -12
- package/src/index.ts +10 -0
|
@@ -6,7 +6,13 @@
|
|
|
6
6
|
* resolve with values
|
|
7
7
|
* @param [limit=no limit] maximum number of asynchronous tasks to permit to run at
|
|
8
8
|
* once
|
|
9
|
+
* @param [onError] optional function to call when a task errors, called for every
|
|
10
|
+
* error that occurs. Only the first task that errors will produce an error that's
|
|
11
|
+
* rethrown, but if there are multiple tasks that error, this function will be called
|
|
12
|
+
* for each task. Note that if there are tasks that have not started yet, they will
|
|
13
|
+
* not be started if any of the tasks error, but when a task errors, other already-started
|
|
14
|
+
* tasks will continue to run to completion or error
|
|
9
15
|
* @returns array of resolved values in the same order as the task functions
|
|
10
16
|
*/
|
|
11
|
-
declare const parallelLimit: (taskFunctions: (() => Promise<any>)[], limit?: number) => Promise<any[]>;
|
|
17
|
+
declare const parallelLimit: (taskFunctions: (() => Promise<any>)[], limit?: number, onError?: (err: any) => void) => Promise<any[]>;
|
|
12
18
|
export default parallelLimit;
|
|
@@ -44,16 +44,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
44
44
|
* resolve with values
|
|
45
45
|
* @param [limit=no limit] maximum number of asynchronous tasks to permit to run at
|
|
46
46
|
* once
|
|
47
|
+
* @param [onError] optional function to call when a task errors, called for every
|
|
48
|
+
* error that occurs. Only the first task that errors will produce an error that's
|
|
49
|
+
* rethrown, but if there are multiple tasks that error, this function will be called
|
|
50
|
+
* for each task. Note that if there are tasks that have not started yet, they will
|
|
51
|
+
* not be started if any of the tasks error, but when a task errors, other already-started
|
|
52
|
+
* tasks will continue to run to completion or error
|
|
47
53
|
* @returns array of resolved values in the same order as the task functions
|
|
48
54
|
*/
|
|
49
|
-
var parallelLimit = function (taskFunctions, limit) { return __awaiter(void 0, void 0, void 0, function () {
|
|
50
|
-
var results;
|
|
55
|
+
var parallelLimit = function (taskFunctions, limit, onError) { return __awaiter(void 0, void 0, void 0, function () {
|
|
56
|
+
var results, exited;
|
|
51
57
|
return __generator(this, function (_a) {
|
|
52
58
|
switch (_a.label) {
|
|
53
59
|
case 0:
|
|
54
60
|
results = [];
|
|
61
|
+
exited = false;
|
|
55
62
|
// Wait until finished with all tasks
|
|
56
|
-
return [4 /*yield*/, new Promise(function (resolve) {
|
|
63
|
+
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
57
64
|
/* ------------- Helpers ------------ */
|
|
58
65
|
var nextTaskIndex = 0;
|
|
59
66
|
var numFinishedTasks = 0;
|
|
@@ -62,7 +69,7 @@ var parallelLimit = function (taskFunctions, limit) { return __awaiter(void 0, v
|
|
|
62
69
|
* @author Gabe Abrams
|
|
63
70
|
*/
|
|
64
71
|
var startTask = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
65
|
-
var taskIndex, taskFunction, result;
|
|
72
|
+
var taskIndex, taskFunction, result, err_1;
|
|
66
73
|
return __generator(this, function (_a) {
|
|
67
74
|
switch (_a.label) {
|
|
68
75
|
case 0:
|
|
@@ -71,18 +78,37 @@ var parallelLimit = function (taskFunctions, limit) { return __awaiter(void 0, v
|
|
|
71
78
|
if (!taskFunction) {
|
|
72
79
|
return [2 /*return*/];
|
|
73
80
|
}
|
|
74
|
-
|
|
81
|
+
_a.label = 1;
|
|
75
82
|
case 1:
|
|
83
|
+
_a.trys.push([1, 3, , 4]);
|
|
84
|
+
return [4 /*yield*/, taskFunction()];
|
|
85
|
+
case 2:
|
|
76
86
|
result = _a.sent();
|
|
77
87
|
// Add results
|
|
78
88
|
results[taskIndex] = result;
|
|
79
89
|
// Tally and finish
|
|
80
90
|
if (++numFinishedTasks === taskFunctions.length) {
|
|
91
|
+
exited = true;
|
|
81
92
|
return [2 /*return*/, resolve()];
|
|
82
93
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
94
|
+
if (!exited) {
|
|
95
|
+
// Not finished! Start another task
|
|
96
|
+
startTask();
|
|
97
|
+
}
|
|
98
|
+
return [3 /*break*/, 4];
|
|
99
|
+
case 3:
|
|
100
|
+
err_1 = _a.sent();
|
|
101
|
+
// Reject only once
|
|
102
|
+
if (!exited) {
|
|
103
|
+
exited = true;
|
|
104
|
+
return [2 /*return*/, reject(err_1)];
|
|
105
|
+
}
|
|
106
|
+
// Either way, call onError if provided
|
|
107
|
+
if (onError) {
|
|
108
|
+
onError(err_1);
|
|
109
|
+
}
|
|
110
|
+
return [3 /*break*/, 4];
|
|
111
|
+
case 4: return [2 /*return*/];
|
|
86
112
|
}
|
|
87
113
|
});
|
|
88
114
|
}); };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parallelLimit.js","sourceRoot":"","sources":["../../src/helpers/parallelLimit.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA
|
|
1
|
+
{"version":3,"file":"parallelLimit.js","sourceRoot":"","sources":["../../src/helpers/parallelLimit.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;GAeG;AACH,IAAM,aAAa,GAAG,UACpB,aAAqC,EACrC,KAAc,EACd,OAA4B;;;;;gBAEtB,OAAO,GAAU,EAAE,CAAC;gBAEtB,MAAM,GAAG,KAAK,CAAC;gBAEnB,qCAAqC;gBACrC,qBAAM,IAAI,OAAO,CAAO,UAAC,OAAO,EAAE,MAAM;wBACtC,wCAAwC;wBAExC,IAAI,aAAa,GAAG,CAAC,CAAC;wBACtB,IAAI,gBAAgB,GAAG,CAAC,CAAC;wBACzB;;;2BAGG;wBACH,IAAM,SAAS,GAAG;;;;;w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9 @@ import CommonKitErrorCode from './types/CommonKitErrorCode';
|
|
|
63
63
|
import LogMetadataContextMap from './types/LogMetadataContextMap';
|
|
64
64
|
import LogMetadataTargetMap from './types/LogMetadataTargetMap';
|
|
65
65
|
import LogReviewerFilterState from './types/LogReviewerFilterState';
|
|
66
|
-
|
|
66
|
+
import DateFilterState from './types/LogReviewerFilterState/DateFilterState';
|
|
67
|
+
import ContextFilterState from './types/LogReviewerFilterState/ContextFilterState';
|
|
68
|
+
import TagFilterState from './types/LogReviewerFilterState/TagFilterState';
|
|
69
|
+
import ActionErrorFilterState from './types/LogReviewerFilterState/ActionErrorFilterState';
|
|
70
|
+
import AdvancedFilterState from './types/LogReviewerFilterState/AdvancedFilterState';
|
|
71
|
+
export { ErrorWithCode, MINUTE_IN_MS, HOUR_IN_MS, DAY_IN_MS, LOG_REVIEW_ROUTE_PATH_PREFIX, LOG_ROUTE_PATH, LOG_REVIEW_STATUS_ROUTE, LOG_REVIEW_GET_LOGS_ROUTE, SELECT_ADMIN_CHECK_ROUTE, CommonKitErrorCode, ParamType, DayOfWeek, Log, LogType, LogSource, LogAction, LogBuiltInMetadata, LogMetadataType, LogFunction, LogTypeSpecificInfo, LogMainInfo, LogSourceSpecificInfo, LogLevel, LogMetadataContextMap, LogMetadataTargetMap, LogReviewerFilterState, DateFilterState, ContextFilterState, TagFilterState, ActionErrorFilterState, AdvancedFilterState, abbreviate, avg, ceilToNumDecimals, floorToNumDecimals, forceNumIntoBounds, padDecimalZeros, padZerosLeft, roundToNumDecimals, sum, waitMs, getOrdinal, getTimeInfoInET, startMinWait, getHumanReadableDate, getPartOfDay, stringsToHumanReadableList, onlyKeepLetters, parallelLimit, getMonthName, genCSV, extractProp, compareArraysByProp, genCommaList, validateEmail, validatePhoneNumber, validateString, getLocalTimeInfo, idify, prefixWithAOrAn, everyAsync, filterAsync, forEachAsync, mapAsync, someAsync, capitalize, shuffleArray, getWordCount, cloneDeep, getTimestampFromTimeInfoInET, };
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;AAAA,gBAAgB;AAChB,yEAAmD;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;AAAA,gBAAgB;AAChB,yEAAmD;AAgFjD,wBAhFK,uBAAa,CAgFL;AA9Ef,mBAAmB;AACnB,0EAAoD;AA+ElD,uBA/EK,sBAAY,CA+EL;AA9Ed,sEAAgD;AA+E9C,qBA/EK,oBAAU,CA+EL;AA9EZ,oEAA8C;AA+E5C,oBA/EK,mBAAS,CA+EL;AA9EX,0GAAoF;AA+ElF,uCA/EK,sCAA4B,CA+EL;AA9E9B,8EAAwD;AA+EtD,yBA/EK,wBAAc,CA+EL;AA9EhB,gGAA0E;AA+ExE,kCA/EK,iCAAuB,CA+EL;AA9EzB,oGAA8E;AA+E5E,oCA/EK,mCAAyB,CA+EL;AA9E3B,kGAA4E;AA+E1E,mCA/EK,kCAAwB,CA+EL;AA7E1B,iBAAiB;AACjB,oEAA8C;AAqG5C,qBArGK,oBAAU,CAqGL;AApGZ,sDAAgC;AAqG9B,cArGK,aAAG,CAqGL;AApGL,kFAA4D;AAqG1D,4BArGK,2BAAiB,CAqGL;AApGnB,oFAA8D;AAqG5D,6BArGK,4BAAkB,CAqGL;AApGpB,oFAA8D;AAqG5D,6BArGK,4BAAkB,CAqGL;AApGpB,8EAAwD;AAqGtD,0BArGK,yBAAe,CAqGL;AApGjB,wEAAkD;AAqGhD,uBArGK,sBAAY,CAqGL;AApGd,oFAA8D;AAqG5D,6BArGK,4BAAkB,CAqGL;AApGpB,sDAAgC;AAqG9B,cArGK,aAAG,CAqGL;AApGL,4DAAsC;AAqGpC,iBArGK,gBAAM,CAqGL;AApGR,oEAA8C;AAqG5C,qBArGK,oBAAU,CAqGL;AApGZ,8EAAwD;AAqGtD,0BArGK,yBAAe,CAqGL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AnG9B,eAAe;AACf,gEAA0C;AAsCxC,oBAtCK,mBAAS,CAsCL;AArCX,gEAA0C;AAsCxC,oBAtCK,mBAAS,CAsCL;AApCX,4DAAsC;AAsCpC,kBAtCK,iBAAO,CAsCL;AArCT,gEAA0C;AAsCxC,oBAtCK,mBAAS,CAsCL;AArCX,gEAA0C;AAsCxC,oBAtCK,mBAAS,CAsCL;AArCX,kFAA4D;AAsC1D,6BAtCK,4BAAkB,CAsCL;AAhCpB,8DAAwC;AAsCtC,mBAtCK,kBAAQ,CAsCL;AArCV,kFAA4D;AAwB1D,6BAxBK,4BAAkB,CAwBL"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dce-commonkit",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Common helpers, constants, and other resources that are shared between dce-reactkit and dce-expresskit",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"DCE",
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"author": "Gabe Abrams <gabeabrams@gmail.com>",
|
|
24
24
|
"type": "commonjs",
|
|
25
25
|
"scripts": {
|
|
26
|
-
"build": "tsc --project ./tsconfig.json"
|
|
26
|
+
"build": "tsc --project ./tsconfig.json",
|
|
27
|
+
"dev:sandbox": "npx tsx ./sandbox.ts"
|
|
27
28
|
},
|
|
28
29
|
"jest": {
|
|
29
30
|
"preset": "ts-jest",
|
|
@@ -6,16 +6,25 @@
|
|
|
6
6
|
* resolve with values
|
|
7
7
|
* @param [limit=no limit] maximum number of asynchronous tasks to permit to run at
|
|
8
8
|
* once
|
|
9
|
+
* @param [onError] optional function to call when a task errors, called for every
|
|
10
|
+
* error that occurs. Only the first task that errors will produce an error that's
|
|
11
|
+
* rethrown, but if there are multiple tasks that error, this function will be called
|
|
12
|
+
* for each task. Note that if there are tasks that have not started yet, they will
|
|
13
|
+
* not be started if any of the tasks error, but when a task errors, other already-started
|
|
14
|
+
* tasks will continue to run to completion or error
|
|
9
15
|
* @returns array of resolved values in the same order as the task functions
|
|
10
16
|
*/
|
|
11
17
|
const parallelLimit = async (
|
|
12
18
|
taskFunctions: (() => Promise<any>)[],
|
|
13
19
|
limit?: number,
|
|
20
|
+
onError?: (err: any) => void,
|
|
14
21
|
): Promise<any[]> => {
|
|
15
22
|
const results: any[] = [];
|
|
16
23
|
|
|
24
|
+
let exited = false;
|
|
25
|
+
|
|
17
26
|
// Wait until finished with all tasks
|
|
18
|
-
await new Promise<void>((resolve) => {
|
|
27
|
+
await new Promise<void>((resolve, reject) => {
|
|
19
28
|
/* ------------- Helpers ------------ */
|
|
20
29
|
|
|
21
30
|
let nextTaskIndex = 0;
|
|
@@ -33,23 +42,39 @@ const parallelLimit = async (
|
|
|
33
42
|
return;
|
|
34
43
|
}
|
|
35
44
|
|
|
36
|
-
|
|
37
|
-
|
|
45
|
+
try {
|
|
46
|
+
// Execute task
|
|
47
|
+
const result = await taskFunction();
|
|
38
48
|
|
|
39
|
-
|
|
40
|
-
|
|
49
|
+
// Add results
|
|
50
|
+
results[taskIndex] = result;
|
|
41
51
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
52
|
+
// Tally and finish
|
|
53
|
+
if (++numFinishedTasks === taskFunctions.length) {
|
|
54
|
+
exited = true;
|
|
55
|
+
return resolve();
|
|
56
|
+
}
|
|
46
57
|
|
|
47
|
-
|
|
48
|
-
|
|
58
|
+
if (!exited) {
|
|
59
|
+
// Not finished! Start another task
|
|
60
|
+
startTask();
|
|
61
|
+
}
|
|
62
|
+
} catch (err) {
|
|
63
|
+
// Reject only once
|
|
64
|
+
if (!exited) {
|
|
65
|
+
exited = true;
|
|
66
|
+
return reject(err);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Either way, call onError if provided
|
|
70
|
+
if (onError) {
|
|
71
|
+
onError(err);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
49
74
|
};
|
|
50
75
|
|
|
51
76
|
/* ----------- Start Tasks ---------- */
|
|
52
|
-
|
|
77
|
+
|
|
53
78
|
// If no limit, start all tasks. At least start 1 task
|
|
54
79
|
const numTasks = Math.max((limit || taskFunctions.length), 1);
|
|
55
80
|
for (let i = 0; i < numTasks; i++) {
|
package/src/index.ts
CHANGED
|
@@ -70,6 +70,11 @@ import CommonKitErrorCode from './types/CommonKitErrorCode';
|
|
|
70
70
|
import LogMetadataContextMap from './types/LogMetadataContextMap';
|
|
71
71
|
import LogMetadataTargetMap from './types/LogMetadataTargetMap';
|
|
72
72
|
import LogReviewerFilterState from './types/LogReviewerFilterState';
|
|
73
|
+
import DateFilterState from './types/LogReviewerFilterState/DateFilterState';
|
|
74
|
+
import ContextFilterState from './types/LogReviewerFilterState/ContextFilterState';
|
|
75
|
+
import TagFilterState from './types/LogReviewerFilterState/TagFilterState';
|
|
76
|
+
import ActionErrorFilterState from './types/LogReviewerFilterState/ActionErrorFilterState';
|
|
77
|
+
import AdvancedFilterState from './types/LogReviewerFilterState/AdvancedFilterState';
|
|
73
78
|
|
|
74
79
|
// Export each item
|
|
75
80
|
export {
|
|
@@ -102,6 +107,11 @@ export {
|
|
|
102
107
|
LogMetadataContextMap,
|
|
103
108
|
LogMetadataTargetMap,
|
|
104
109
|
LogReviewerFilterState,
|
|
110
|
+
DateFilterState,
|
|
111
|
+
ContextFilterState,
|
|
112
|
+
TagFilterState,
|
|
113
|
+
ActionErrorFilterState,
|
|
114
|
+
AdvancedFilterState,
|
|
105
115
|
// Helpers
|
|
106
116
|
abbreviate,
|
|
107
117
|
avg,
|