@orioro/util 0.9.0 → 0.11.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/dist/array/dataJoin.d.ts +9 -0
- package/dist/array/index.d.ts +1 -0
- package/dist/array/join.d.ts +9 -0
- package/dist/debug/debugFn/index.d.ts +3 -2
- package/dist/deprecate.d.ts +3 -0
- package/dist/hookFn/index.d.ts +10 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.js +1514 -0
- package/dist/index.mjs +635 -794
- package/dist/interpolate/index.d.ts +1 -1
- package/dist/pathResolve/index.d.ts +7 -0
- package/dist/promise/index.d.ts +5 -0
- package/dist/promise/isPromise.d.ts +1 -0
- package/dist/promise/makeDeferred.d.ts +6 -0
- package/dist/promise/maybeAsyncFn.d.ts +20 -0
- package/dist/promise/maybeReturnPromise.d.ts +1 -0
- package/dist/promise/untilConditionIsSatisfiedReducer.d.ts +1 -0
- package/dist/slugify/index.d.ts +2 -0
- package/dist/strAutoCast/index.d.ts +1 -0
- package/dist/strAutoCast/strAutoCast.d.ts +1 -0
- package/dist/strExpr/index.d.ts +2 -0
- package/dist/strExpr/strExpr.d.ts +14 -0
- package/dist/strExpr/syntheticJson.d.ts +1 -0
- package/dist/typeOf.d.ts +23 -1
- package/dist/url/index.d.ts +2 -0
- package/dist/url/isValidUrl.d.ts +1 -0
- package/dist/url/url.d.ts +18 -0
- package/dist/validate/common/validators/type.d.ts +2 -2
- package/package.json +8 -4
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
|
+
import { keyBy, set, get } from 'lodash-es';
|
|
1
2
|
import EventEmitter from 'eventemitter3';
|
|
2
3
|
import copy from 'fast-copy';
|
|
3
|
-
import { getProperty, setProperty } from 'dot-prop';
|
|
4
4
|
import traverse from 'traverse';
|
|
5
5
|
import { backOff } from 'exponential-backoff';
|
|
6
|
+
import { isPlainObject } from 'is-plain-object';
|
|
7
|
+
import memoizeOne from 'memoize-one';
|
|
8
|
+
import queryString from 'query-string';
|
|
9
|
+
|
|
10
|
+
function arrayChunk(array, chunkSize) {
|
|
11
|
+
var chunks = [];
|
|
12
|
+
for (var i = 0; i < array.length; i += chunkSize) {
|
|
13
|
+
chunks.push(array.slice(i, i + chunkSize));
|
|
14
|
+
}
|
|
15
|
+
return chunks;
|
|
16
|
+
}
|
|
6
17
|
|
|
7
18
|
function _typeof(o) {
|
|
8
19
|
"@babel/helpers - typeof";
|
|
@@ -28,7 +39,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
28
39
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
29
40
|
PERFORMANCE OF THIS SOFTWARE.
|
|
30
41
|
***************************************************************************** */
|
|
31
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
42
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
32
43
|
|
|
33
44
|
var _extendStatics = function extendStatics(d, b) {
|
|
34
45
|
_extendStatics = Object.setPrototypeOf || {
|
|
@@ -58,14 +69,6 @@ var _assign = function __assign() {
|
|
|
58
69
|
};
|
|
59
70
|
return _assign.apply(this, arguments);
|
|
60
71
|
};
|
|
61
|
-
function __rest(s, e) {
|
|
62
|
-
var t = {};
|
|
63
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
64
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
65
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
66
|
-
}
|
|
67
|
-
return t;
|
|
68
|
-
}
|
|
69
72
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
70
73
|
function adopt(value) {
|
|
71
74
|
return value instanceof P ? value : new P(function (resolve) {
|
|
@@ -106,12 +109,8 @@ function __generator(thisArg, body) {
|
|
|
106
109
|
f,
|
|
107
110
|
y,
|
|
108
111
|
t,
|
|
109
|
-
g;
|
|
110
|
-
return g = {
|
|
111
|
-
next: verb(0),
|
|
112
|
-
"throw": verb(1),
|
|
113
|
-
"return": verb(2)
|
|
114
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
112
|
+
g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
113
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
115
114
|
return this;
|
|
116
115
|
}), g;
|
|
117
116
|
function verb(n) {
|
|
@@ -195,6 +194,104 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
195
194
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
196
195
|
};
|
|
197
196
|
|
|
197
|
+
function _isTupleDatasetInput(input) {
|
|
198
|
+
return Array.isArray(input) && typeof input[0] === 'string' && Array.isArray(input[1]);
|
|
199
|
+
}
|
|
200
|
+
function _parseDatasetInput(defaultOnKey, datasetInput) {
|
|
201
|
+
var _a;
|
|
202
|
+
if (_isTupleDatasetInput(datasetInput)) {
|
|
203
|
+
var keyInput = datasetInput[0];
|
|
204
|
+
var key = keyInput;
|
|
205
|
+
var srcKey = null;
|
|
206
|
+
if (typeof keyInput === 'string') {
|
|
207
|
+
var keySplit = keyInput.split(':');
|
|
208
|
+
if (keySplit.length === 1) {
|
|
209
|
+
srcKey = null;
|
|
210
|
+
key = keyInput;
|
|
211
|
+
} else {
|
|
212
|
+
srcKey = keySplit[0];
|
|
213
|
+
key = keySplit[1];
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return {
|
|
217
|
+
srcKey: srcKey,
|
|
218
|
+
key: key,
|
|
219
|
+
entries: datasetInput[1],
|
|
220
|
+
path: (_a = datasetInput[2]) !== null && _a !== void 0 ? _a : null
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
return {
|
|
224
|
+
srcKey: null,
|
|
225
|
+
key: defaultOnKey,
|
|
226
|
+
entries: datasetInput,
|
|
227
|
+
path: null
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
function dataJoin(datasets, _a) {
|
|
231
|
+
var _b = _a === void 0 ? {} : _a,
|
|
232
|
+
_c = _b.key,
|
|
233
|
+
defaultOnKey = _c === void 0 ? 'id' : _c,
|
|
234
|
+
_d = _b.mode,
|
|
235
|
+
mode = _d === void 0 ? 'left' : _d;
|
|
236
|
+
var base = datasets[0],
|
|
237
|
+
others = datasets.slice(1);
|
|
238
|
+
//
|
|
239
|
+
// Base dataset requires no byKey dict
|
|
240
|
+
//
|
|
241
|
+
var baseDataset = _parseDatasetInput(defaultOnKey, base);
|
|
242
|
+
//
|
|
243
|
+
// Other datasets require byKey dict
|
|
244
|
+
//
|
|
245
|
+
var otherSets = others.map(function (setInput) {
|
|
246
|
+
var parsed = _parseDatasetInput(defaultOnKey, setInput);
|
|
247
|
+
return _assign(_assign({}, parsed), {
|
|
248
|
+
byKey: keyBy(parsed.entries, parsed.key)
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
//
|
|
252
|
+
// Prepare a set of functions that
|
|
253
|
+
// retrieve a given entry's key relative
|
|
254
|
+
// to another dataset
|
|
255
|
+
//
|
|
256
|
+
function _entryKey(entry, otherSet) {
|
|
257
|
+
var _a;
|
|
258
|
+
return ((_a = otherSet.srcKey ? get(entry, otherSet.srcKey) : get(entry, baseDataset.key)) !== null && _a !== void 0 ? _a : '').toString();
|
|
259
|
+
}
|
|
260
|
+
//
|
|
261
|
+
// If mode === inner, filter out missing data
|
|
262
|
+
//
|
|
263
|
+
var baseEntries = mode === 'inner' ? baseDataset.entries.filter(function (entry) {
|
|
264
|
+
return otherSets.every(function (set) {
|
|
265
|
+
return set.byKey[_entryKey(entry, set)];
|
|
266
|
+
});
|
|
267
|
+
}) : baseDataset.entries;
|
|
268
|
+
//
|
|
269
|
+
// Loop over baseDataset.entries joining it with other data
|
|
270
|
+
//
|
|
271
|
+
return baseEntries.map(function (entry) {
|
|
272
|
+
var _a;
|
|
273
|
+
//
|
|
274
|
+
// Setup a base entry over which data will be set
|
|
275
|
+
//
|
|
276
|
+
var baseEntry = baseDataset.path ? (_a = {}, _a[baseDataset.path] = entry, _a) : Object.assign({}, entry);
|
|
277
|
+
//
|
|
278
|
+
// Loop over all other sets to pick up data
|
|
279
|
+
//
|
|
280
|
+
return otherSets.reduce(function (acc, otherSet) {
|
|
281
|
+
var entryKey = _entryKey(entry, otherSet);
|
|
282
|
+
var otherEntry = otherSet.byKey[entryKey];
|
|
283
|
+
if (otherEntry) {
|
|
284
|
+
if (otherSet.path) {
|
|
285
|
+
set(acc, otherSet.path, otherEntry);
|
|
286
|
+
} else {
|
|
287
|
+
Object.assign(acc, otherEntry);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return acc;
|
|
291
|
+
}, baseEntry);
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
|
|
198
295
|
var PromiseLikeEventEmitter = /** @class */function (_super) {
|
|
199
296
|
__extends(PromiseLikeEventEmitter, _super);
|
|
200
297
|
function PromiseLikeEventEmitter() {
|
|
@@ -282,13 +379,22 @@ function generateDeterministicId(args) {
|
|
|
282
379
|
return simpleHash(argsString);
|
|
283
380
|
}
|
|
284
381
|
|
|
285
|
-
function
|
|
382
|
+
function sequentialCallIdGenerator() {
|
|
383
|
+
var count = 0;
|
|
384
|
+
return function () {
|
|
385
|
+
return count += 1;
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
function debugFn(fnName, fn, logCall, logResult, generateCallId) {
|
|
389
|
+
if (generateCallId === void 0) {
|
|
390
|
+
generateCallId = generateDeterministicId;
|
|
391
|
+
}
|
|
286
392
|
return function () {
|
|
287
393
|
var args = [];
|
|
288
394
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
289
395
|
args[_i] = arguments[_i];
|
|
290
396
|
}
|
|
291
|
-
var callId =
|
|
397
|
+
var callId = generateCallId(__spreadArray([fnName, fn], args, true));
|
|
292
398
|
if (typeof logCall === 'function') {
|
|
293
399
|
// Deep clone args, so that we may detect mutations later on
|
|
294
400
|
logCall({
|
|
@@ -335,7 +441,12 @@ function debugFn(fnName, fn, logCall, logResult) {
|
|
|
335
441
|
*
|
|
336
442
|
* @const {RegExp} INTERPOLATION_REGEXP
|
|
337
443
|
*/
|
|
338
|
-
var INTERPOLATION_REGEXP = /\$\{\s*([\w
|
|
444
|
+
var INTERPOLATION_REGEXP = /\$\{\s*([\w$.=\s]+)\s*\}/g;
|
|
445
|
+
var DEFAULT_SIGN = '=';
|
|
446
|
+
function _parsePathExpr(pathExpr) {
|
|
447
|
+
var splitRes = pathExpr.split(DEFAULT_SIGN);
|
|
448
|
+
return splitRes.length > 1 ? [splitRes[0].trim(), splitRes.slice(1).join(DEFAULT_SIGN).trim()] : [splitRes[0].trim()];
|
|
449
|
+
}
|
|
339
450
|
/**
|
|
340
451
|
* @function $stringInterpolate
|
|
341
452
|
* @param {String} template Basic JS template string like `${value.path}` value
|
|
@@ -352,8 +463,12 @@ function interpolate(template, data, _a) {
|
|
|
352
463
|
if (template.length > maxLength) {
|
|
353
464
|
throw new Error("Template exceeds maxLength ".concat(maxLength));
|
|
354
465
|
}
|
|
355
|
-
|
|
356
|
-
|
|
466
|
+
data = _typeof(data) === 'object' ? data : [data];
|
|
467
|
+
return template.replace(INTERPOLATION_REGEXP, function (_, pathExpr) {
|
|
468
|
+
var _a = _parsePathExpr(pathExpr),
|
|
469
|
+
path = _a[0],
|
|
470
|
+
defaultValue = _a[1];
|
|
471
|
+
var value = get(data, path);
|
|
357
472
|
switch (_typeof(value)) {
|
|
358
473
|
case 'number':
|
|
359
474
|
{
|
|
@@ -365,8 +480,12 @@ function interpolate(template, data, _a) {
|
|
|
365
480
|
}
|
|
366
481
|
default:
|
|
367
482
|
{
|
|
368
|
-
|
|
369
|
-
|
|
483
|
+
if (typeof value === 'undefined' || value === null) {
|
|
484
|
+
return typeof defaultValue === 'string' ? defaultValue : '';
|
|
485
|
+
} else {
|
|
486
|
+
console.warn("Attempting to use non interpolatable value in interpolate ".concat(value));
|
|
487
|
+
return '';
|
|
488
|
+
}
|
|
370
489
|
}
|
|
371
490
|
}
|
|
372
491
|
});
|
|
@@ -386,13 +505,13 @@ function pickPaths(sourceObj, paths) {
|
|
|
386
505
|
targetPath = _a[0],
|
|
387
506
|
resolver = _a[1],
|
|
388
507
|
defaultValue = _a[2];
|
|
389
|
-
var value = typeof resolver === 'string' ?
|
|
508
|
+
var value = typeof resolver === 'string' ? get(sourceObj, resolver) : resolver(sourceObj);
|
|
390
509
|
var valueAfterDefault = typeof value === 'undefined' ? defaultValue : value;
|
|
391
510
|
//
|
|
392
511
|
// Undefined values are skipped in order to avoid nested
|
|
393
512
|
// setting undefined values
|
|
394
513
|
//
|
|
395
|
-
return typeof valueAfterDefault !== 'undefined' ?
|
|
514
|
+
return typeof valueAfterDefault !== 'undefined' ? set(acc, targetPath, valueAfterDefault) : acc;
|
|
396
515
|
}, {});
|
|
397
516
|
}
|
|
398
517
|
|
|
@@ -475,14 +594,6 @@ function resolveNestedPromises(node, options, ctx) {
|
|
|
475
594
|
});
|
|
476
595
|
}
|
|
477
596
|
|
|
478
|
-
function arrayChunk(array, chunkSize) {
|
|
479
|
-
var chunks = [];
|
|
480
|
-
for (var i = 0; i < array.length; i += chunkSize) {
|
|
481
|
-
chunks.push(array.slice(i, i + chunkSize));
|
|
482
|
-
}
|
|
483
|
-
return chunks;
|
|
484
|
-
}
|
|
485
|
-
|
|
486
597
|
var TimeoutError = /** @class */function (_super) {
|
|
487
598
|
__extends(TimeoutError, _super);
|
|
488
599
|
function TimeoutError(message) {
|
|
@@ -668,6 +779,292 @@ function parseBatchedResults(inputs, results) {
|
|
|
668
779
|
});
|
|
669
780
|
}
|
|
670
781
|
|
|
782
|
+
function makeDeferred() {
|
|
783
|
+
var resolve = function resolve() {};
|
|
784
|
+
var reject = function reject() {};
|
|
785
|
+
var settled = false;
|
|
786
|
+
var promise = new Promise(function (_resolve, _reject) {
|
|
787
|
+
resolve = function resolve(value) {
|
|
788
|
+
if (!settled) {
|
|
789
|
+
settled = true;
|
|
790
|
+
_resolve(value);
|
|
791
|
+
}
|
|
792
|
+
};
|
|
793
|
+
reject = function reject(reason) {
|
|
794
|
+
if (!settled) {
|
|
795
|
+
settled = true;
|
|
796
|
+
_reject(reason);
|
|
797
|
+
}
|
|
798
|
+
};
|
|
799
|
+
});
|
|
800
|
+
return {
|
|
801
|
+
promise: promise,
|
|
802
|
+
resolve: resolve,
|
|
803
|
+
reject: reject
|
|
804
|
+
};
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
function isPromise(value) {
|
|
808
|
+
return value !== null && _typeof(value) === 'object' && typeof value.then === 'function';
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
//
|
|
812
|
+
// Checks whether the input itself is a promise
|
|
813
|
+
// or has any nested promises
|
|
814
|
+
//
|
|
815
|
+
// TODO: implement maxDepth
|
|
816
|
+
//
|
|
817
|
+
function hasNestedPromises(input) {
|
|
818
|
+
if (isPromise(input)) {
|
|
819
|
+
return true;
|
|
820
|
+
} else if (Array.isArray(input) || isPlainObject(input)) {
|
|
821
|
+
return traverse(input).reduce(function (acc, value) {
|
|
822
|
+
return acc === true ? true : isPromise(value);
|
|
823
|
+
// if (acc === true) {
|
|
824
|
+
// //
|
|
825
|
+
// // Stop is not well documented
|
|
826
|
+
// //
|
|
827
|
+
// this.stop()
|
|
828
|
+
// return true
|
|
829
|
+
// } else {
|
|
830
|
+
// return isPromise(value)
|
|
831
|
+
// }
|
|
832
|
+
}, false);
|
|
833
|
+
} else {
|
|
834
|
+
return false;
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
function _makeDefaultAsyncExpFn(syncFn) {
|
|
838
|
+
return function defaultAsyncExpFn() {
|
|
839
|
+
var args = [];
|
|
840
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
841
|
+
args[_i] = arguments[_i];
|
|
842
|
+
}
|
|
843
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
844
|
+
var resolvedArgs;
|
|
845
|
+
return __generator(this, function (_a) {
|
|
846
|
+
switch (_a.label) {
|
|
847
|
+
case 0:
|
|
848
|
+
return [4 /*yield*/, Promise.all(args.map(function (arg) {
|
|
849
|
+
return resolveNestedPromises(arg);
|
|
850
|
+
}))];
|
|
851
|
+
case 1:
|
|
852
|
+
resolvedArgs = _a.sent();
|
|
853
|
+
return [2 /*return*/, syncFn.apply(void 0, resolvedArgs)];
|
|
854
|
+
}
|
|
855
|
+
});
|
|
856
|
+
});
|
|
857
|
+
};
|
|
858
|
+
}
|
|
859
|
+
function _defaultArgsContainPromises(args) {
|
|
860
|
+
return args.some(function (arg) {
|
|
861
|
+
return hasNestedPromises(arg);
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
/**
|
|
865
|
+
* Takes in a function and optionally takes in
|
|
866
|
+
* an async version of that same function.
|
|
867
|
+
* If no async version is defined, a default async
|
|
868
|
+
* version is prepared.
|
|
869
|
+
*
|
|
870
|
+
* Returns a new function that, before executing the wrapped
|
|
871
|
+
* functions verifies if there are any promises
|
|
872
|
+
* in the inputs and executes sync or async versions
|
|
873
|
+
* accordingly
|
|
874
|
+
*/
|
|
875
|
+
function maybeAsyncFn(_a) {
|
|
876
|
+
var syncFn = _a.syncFn,
|
|
877
|
+
_b = _a.asyncFn,
|
|
878
|
+
asyncFn = _b === void 0 ? _makeDefaultAsyncExpFn(syncFn) : _b,
|
|
879
|
+
//
|
|
880
|
+
// By default, argsContainPromises checks
|
|
881
|
+
// if the any of the arguments provided are
|
|
882
|
+
// themselves a promise or if they have a nested promise
|
|
883
|
+
//
|
|
884
|
+
// Allow the argsContainPromises to be configurable.
|
|
885
|
+
// This allows for more specialized checks that
|
|
886
|
+
// would perform better, some examples:
|
|
887
|
+
// - If the first argument includes a promise
|
|
888
|
+
// - If some deeply nested argument is set
|
|
889
|
+
// to a value that will incur in the need
|
|
890
|
+
// for async resolution, even if the input arg
|
|
891
|
+
// itself is not a promise
|
|
892
|
+
//
|
|
893
|
+
_c = _a.argsContainPromises,
|
|
894
|
+
//
|
|
895
|
+
// By default, argsContainPromises checks
|
|
896
|
+
// if the any of the arguments provided are
|
|
897
|
+
// themselves a promise or if they have a nested promise
|
|
898
|
+
//
|
|
899
|
+
// Allow the argsContainPromises to be configurable.
|
|
900
|
+
// This allows for more specialized checks that
|
|
901
|
+
// would perform better, some examples:
|
|
902
|
+
// - If the first argument includes a promise
|
|
903
|
+
// - If some deeply nested argument is set
|
|
904
|
+
// to a value that will incur in the need
|
|
905
|
+
// for async resolution, even if the input arg
|
|
906
|
+
// itself is not a promise
|
|
907
|
+
//
|
|
908
|
+
argsContainPromises = _c === void 0 ? _defaultArgsContainPromises : _c;
|
|
909
|
+
return function () {
|
|
910
|
+
var args = [];
|
|
911
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
912
|
+
args[_i] = arguments[_i];
|
|
913
|
+
}
|
|
914
|
+
return argsContainPromises(args) ? asyncFn.apply(void 0, args) : syncFn.apply(void 0, args);
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
function untilConditionIsSatisfiedReducer(condition, reduce) {
|
|
919
|
+
return function reducer(acc, value, index, allValues) {
|
|
920
|
+
if (isPromise(acc) || condition(acc)) {
|
|
921
|
+
//
|
|
922
|
+
// Has already resolved, as any false value
|
|
923
|
+
// should render the whole $and expression to false
|
|
924
|
+
//
|
|
925
|
+
//
|
|
926
|
+
// The previous condition returned a promise,
|
|
927
|
+
// thus assume it will properly handle resolution
|
|
928
|
+
//
|
|
929
|
+
return acc;
|
|
930
|
+
} else {
|
|
931
|
+
//
|
|
932
|
+
// Resolve currentValue
|
|
933
|
+
//
|
|
934
|
+
var syncResult = reduce(acc, value, index, allValues);
|
|
935
|
+
if (isPromise(syncResult)) {
|
|
936
|
+
var remainingValues_1 = allValues.slice(index + 1);
|
|
937
|
+
return syncResult.then(function (asyncResult) {
|
|
938
|
+
return condition(asyncResult) ? asyncResult : remainingValues_1.reduce(reducer, asyncResult);
|
|
939
|
+
});
|
|
940
|
+
} else {
|
|
941
|
+
return syncResult;
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
};
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
function maybeReturnPromise(result, parseResult) {
|
|
948
|
+
return isPromise(result) ? result.then(parseResult) : parseResult(result);
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
function syntheticJson(str) {
|
|
952
|
+
// Step 1: Replace single quotes with double quotes
|
|
953
|
+
var normalized = str.replace(/'/g, '"');
|
|
954
|
+
// Step 2: Add quotes around unquoted keys (letters, digits, underscores)
|
|
955
|
+
normalized = normalized.replace(/([a-zA-Z0-9_]+)\s*:/g, '"$1":');
|
|
956
|
+
// Step 3: Parse as JSON
|
|
957
|
+
try {
|
|
958
|
+
return JSON.parse(normalized);
|
|
959
|
+
} catch (error) {
|
|
960
|
+
throw new Error("Invalid synthetic JSON: ".concat(str));
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
function _jsonLikeParseArgs(argsStr) {
|
|
965
|
+
try {
|
|
966
|
+
argsStr = "[".concat(argsStr, "]");
|
|
967
|
+
return syntheticJson(argsStr);
|
|
968
|
+
// // Replace single quotes with double quotes
|
|
969
|
+
// argsStr = argsStr.replace(/'/g, '"')
|
|
970
|
+
// // Add double quotes around unquoted keys
|
|
971
|
+
// argsStr = argsStr.replace(/(\w+)\s*:/g, '"$1":')
|
|
972
|
+
// return JSON.parse(argsStr)
|
|
973
|
+
} catch (err) {
|
|
974
|
+
throw new Error("Failed to parse arguments: ".concat(err.message));
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
// Utility to escape regex special characters
|
|
978
|
+
function escapeRegExp(str) {
|
|
979
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
980
|
+
}
|
|
981
|
+
function strExpr(_a) {
|
|
982
|
+
var expressions = _a.expressions,
|
|
983
|
+
_b = _a.pipe,
|
|
984
|
+
pipe = _b === void 0 ? '|' : _b,
|
|
985
|
+
_c = _a.parseArgs,
|
|
986
|
+
parseArgs = _c === void 0 ? _jsonLikeParseArgs : _c;
|
|
987
|
+
var _d = Array.isArray(expressions) ? [expressions, null] : [Object.keys(expressions), expressions],
|
|
988
|
+
expressionIds = _d[0],
|
|
989
|
+
expressionFns = _d[1];
|
|
990
|
+
if (expressionIds.length === 0) {
|
|
991
|
+
throw new Error('No expressions provided');
|
|
992
|
+
}
|
|
993
|
+
//
|
|
994
|
+
// Used to split piping expressions
|
|
995
|
+
//
|
|
996
|
+
var PIPE_RE = new RegExp('\\s*' + escapeRegExp(pipe) + '\\s*', 'g');
|
|
997
|
+
//
|
|
998
|
+
// Matches and captures the name of the expression
|
|
999
|
+
//
|
|
1000
|
+
var EXP_NAME_PART = "(".concat(expressionIds.map(escapeRegExp).join('|'), ")");
|
|
1001
|
+
//
|
|
1002
|
+
// Optionally matches and captures arguments ("value1", "value2")
|
|
1003
|
+
//
|
|
1004
|
+
var PARAMS_PART = "(?:\\(([^)]*)\\))?";
|
|
1005
|
+
var EXPRESSIONS_RE = new RegExp("^".concat(EXP_NAME_PART).concat(PARAMS_PART, "$"));
|
|
1006
|
+
//
|
|
1007
|
+
// Takes a string in the format:
|
|
1008
|
+
// 'expr1("param", "param2") | expr2() | expr3()'
|
|
1009
|
+
//
|
|
1010
|
+
// and returns an array denoting expression name and arguments
|
|
1011
|
+
//
|
|
1012
|
+
var parse = memoizeOne(function parse(expr) {
|
|
1013
|
+
var parts = expr.split(PIPE_RE).map(function (expr) {
|
|
1014
|
+
return expr.trim();
|
|
1015
|
+
});
|
|
1016
|
+
return parts.map(function (part) {
|
|
1017
|
+
var exprMatch = part.match(EXPRESSIONS_RE);
|
|
1018
|
+
if (!exprMatch) {
|
|
1019
|
+
throw new Error("Invalid expression part '".concat(part, "'"));
|
|
1020
|
+
}
|
|
1021
|
+
var exprName = exprMatch[1];
|
|
1022
|
+
var exprArgsStr = exprMatch[2] ? exprMatch[2].trim() : '';
|
|
1023
|
+
return [exprName, exprArgsStr ? parseArgs(exprArgsStr) : []];
|
|
1024
|
+
});
|
|
1025
|
+
});
|
|
1026
|
+
//
|
|
1027
|
+
// Applies the expression against a provided input
|
|
1028
|
+
//
|
|
1029
|
+
var apply = expressionFns ? function apply(exprParts, input) {
|
|
1030
|
+
exprParts = typeof exprParts === 'string' ? parse(exprParts) : exprParts;
|
|
1031
|
+
return exprParts.reduce(function (acc, part) {
|
|
1032
|
+
var exprName = part[0];
|
|
1033
|
+
var exprArgs = part[1];
|
|
1034
|
+
var exprFn = expressionFns[exprName];
|
|
1035
|
+
if (!exprFn) {
|
|
1036
|
+
throw new Error("Expression '".concat(exprName, "' not found"));
|
|
1037
|
+
}
|
|
1038
|
+
//
|
|
1039
|
+
// It seems fn.apply is significantly faster than spread operator
|
|
1040
|
+
// Some references:
|
|
1041
|
+
// - https://jonlinnell.co.uk/articles/spread-operator-performance
|
|
1042
|
+
//
|
|
1043
|
+
var _withExprArgs = exprFn.apply(null, exprArgs);
|
|
1044
|
+
// const _withExprArgs = exprFn(...exprArgs)
|
|
1045
|
+
return maybeReturnPromise(acc, function (accRes) {
|
|
1046
|
+
return _withExprArgs(accRes);
|
|
1047
|
+
});
|
|
1048
|
+
}, input);
|
|
1049
|
+
} : function () {
|
|
1050
|
+
throw new Error('Cannot apply expression: No expression functions provided');
|
|
1051
|
+
};
|
|
1052
|
+
//
|
|
1053
|
+
// Compiles an expression into an executable function
|
|
1054
|
+
//
|
|
1055
|
+
function compile(expr) {
|
|
1056
|
+
var parsed = parse(expr);
|
|
1057
|
+
return function (input) {
|
|
1058
|
+
return apply(parsed, input);
|
|
1059
|
+
};
|
|
1060
|
+
}
|
|
1061
|
+
return {
|
|
1062
|
+
parse: parse,
|
|
1063
|
+
apply: apply,
|
|
1064
|
+
compile: compile
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1067
|
+
|
|
671
1068
|
function testCriteria(criteria, input) {
|
|
672
1069
|
switch (_typeof(criteria)) {
|
|
673
1070
|
case 'function':
|
|
@@ -708,37 +1105,6 @@ function switchExec(input, cases) {
|
|
|
708
1105
|
return fn.apply(void 0, args);
|
|
709
1106
|
}
|
|
710
1107
|
|
|
711
|
-
/*!
|
|
712
|
-
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
|
|
713
|
-
*
|
|
714
|
-
* Copyright (c) 2014-2017, Jon Schlinkert.
|
|
715
|
-
* Released under the MIT License.
|
|
716
|
-
*/
|
|
717
|
-
|
|
718
|
-
function isObject(o) {
|
|
719
|
-
return Object.prototype.toString.call(o) === '[object Object]';
|
|
720
|
-
}
|
|
721
|
-
function isPlainObject(o) {
|
|
722
|
-
var ctor, prot;
|
|
723
|
-
if (isObject(o) === false) return false;
|
|
724
|
-
|
|
725
|
-
// If has modified constructor
|
|
726
|
-
ctor = o.constructor;
|
|
727
|
-
if (ctor === undefined) return true;
|
|
728
|
-
|
|
729
|
-
// If has modified prototype
|
|
730
|
-
prot = ctor.prototype;
|
|
731
|
-
if (isObject(prot) === false) return false;
|
|
732
|
-
|
|
733
|
-
// If constructor does not have an Object-specific method
|
|
734
|
-
if (prot.hasOwnProperty('isPrototypeOf') === false) {
|
|
735
|
-
return false;
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
// Most likely a plain Object
|
|
739
|
-
return true;
|
|
740
|
-
}
|
|
741
|
-
|
|
742
1108
|
//
|
|
743
1109
|
// The only role of this function is to let typescript
|
|
744
1110
|
// be aware of the available types
|
|
@@ -813,729 +1179,6 @@ var DEFAULT_TYPES = typeMap({
|
|
|
813
1179
|
});
|
|
814
1180
|
var typeOf = makeTypeOf(DEFAULT_TYPES);
|
|
815
1181
|
|
|
816
|
-
var TYPE_RE = /([a-z0-9]+)(\!)?$/i;
|
|
817
|
-
var TYPE_SEPARATOR_RE = /\s*\|\s*/g;
|
|
818
|
-
function parseSingleType(typeInput) {
|
|
819
|
-
var match = typeInput.match(TYPE_RE);
|
|
820
|
-
if (!match) {
|
|
821
|
-
throw new Error("Invalid type ".concat(typeInput));
|
|
822
|
-
} else {
|
|
823
|
-
var typeName = match[1],
|
|
824
|
-
requiredSignal = match[2];
|
|
825
|
-
return {
|
|
826
|
-
type: typeName,
|
|
827
|
-
required: requiredSignal === '!'
|
|
828
|
-
};
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
function serializeExpectedTypes(expectedTypes) {
|
|
832
|
-
return expectedTypes.map(function (expectedType) {
|
|
833
|
-
return "".concat(expectedType.type).concat(expectedType.required ? '!' : '');
|
|
834
|
-
}).join(' | ');
|
|
835
|
-
}
|
|
836
|
-
function parseExpectedTypes(expectedTypesInput) {
|
|
837
|
-
switch (typeOf(expectedTypesInput)) {
|
|
838
|
-
case 'string':
|
|
839
|
-
{
|
|
840
|
-
return expectedTypesInput.split(TYPE_SEPARATOR_RE).map(function (typeInput) {
|
|
841
|
-
return parseSingleType(typeInput);
|
|
842
|
-
});
|
|
843
|
-
}
|
|
844
|
-
case 'array':
|
|
845
|
-
{
|
|
846
|
-
return expectedTypesInput.map(function (expectedType) {
|
|
847
|
-
return typeof expectedType === 'string' ? parseSingleType(expectedType) : expectedType;
|
|
848
|
-
});
|
|
849
|
-
}
|
|
850
|
-
case 'object':
|
|
851
|
-
{
|
|
852
|
-
return [expectedTypesInput];
|
|
853
|
-
}
|
|
854
|
-
default:
|
|
855
|
-
{
|
|
856
|
-
throw new Error("Invalid expectedType ".concat(expectedTypesInput));
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
function typeValidator(expectedTypesInput) {
|
|
861
|
-
var expectedTypes = parseExpectedTypes(expectedTypesInput);
|
|
862
|
-
return function validateType(input) {
|
|
863
|
-
var inputType = typeOf(input);
|
|
864
|
-
var nullOrUndefined = function nullOrUndefined() {
|
|
865
|
-
return expectedTypes.some(function (expectedType) {
|
|
866
|
-
return expectedType.type === 'undefined' || expectedType.type === 'null' || expectedType.required === false;
|
|
867
|
-
});
|
|
868
|
-
};
|
|
869
|
-
var isValid = switchExec(inputType, {
|
|
870
|
-
"null": nullOrUndefined,
|
|
871
|
-
undefined: nullOrUndefined,
|
|
872
|
-
"default": function _default() {
|
|
873
|
-
return expectedTypes.some(function (expectedType) {
|
|
874
|
-
return expectedType.type === inputType;
|
|
875
|
-
});
|
|
876
|
-
}
|
|
877
|
-
});
|
|
878
|
-
if (isValid) {
|
|
879
|
-
return true;
|
|
880
|
-
} else {
|
|
881
|
-
return {
|
|
882
|
-
expectedTypes: serializeExpectedTypes(expectedTypes),
|
|
883
|
-
input: input
|
|
884
|
-
};
|
|
885
|
-
}
|
|
886
|
-
};
|
|
887
|
-
}
|
|
888
|
-
|
|
889
|
-
//
|
|
890
|
-
// And operator (serial)
|
|
891
|
-
//
|
|
892
|
-
function and$1(validators) {
|
|
893
|
-
return function validateAnd(input, _a) {
|
|
894
|
-
var validateSync = _a.validateSync;
|
|
895
|
-
var result = validators.reduce(function (acc, validator) {
|
|
896
|
-
return acc !== true ? acc : validateSync(validator, input);
|
|
897
|
-
}, true);
|
|
898
|
-
if (result === true) {
|
|
899
|
-
return true;
|
|
900
|
-
} else {
|
|
901
|
-
return result;
|
|
902
|
-
}
|
|
903
|
-
};
|
|
904
|
-
}
|
|
905
|
-
//
|
|
906
|
-
// Or operator (serial)
|
|
907
|
-
//
|
|
908
|
-
function or$1(validators) {
|
|
909
|
-
return function validateOr(input, _a) {
|
|
910
|
-
var validateSync = _a.validateSync;
|
|
911
|
-
var someIsValid = validators.some(function (validator) {
|
|
912
|
-
return validateSync(validator, input) === true;
|
|
913
|
-
});
|
|
914
|
-
return someIsValid;
|
|
915
|
-
};
|
|
916
|
-
}
|
|
917
|
-
//
|
|
918
|
-
// Not
|
|
919
|
-
//
|
|
920
|
-
function not$1(validator) {
|
|
921
|
-
return function validateNot(input, _a) {
|
|
922
|
-
var validateSync = _a.validateSync;
|
|
923
|
-
return validateSync(validator, input) !== true;
|
|
924
|
-
};
|
|
925
|
-
}
|
|
926
|
-
|
|
927
|
-
function _shapeGeneralValidator$1(_a) {
|
|
928
|
-
var input = _a.input,
|
|
929
|
-
baseType = _a.baseType,
|
|
930
|
-
collectNestedErrors = _a.collectNestedErrors,
|
|
931
|
-
validateSync = _a.validateSync;
|
|
932
|
-
var baseTypeValidation = validateSync(typeValidator({
|
|
933
|
-
type: baseType,
|
|
934
|
-
required: true
|
|
935
|
-
}), input);
|
|
936
|
-
if (baseTypeValidation !== true) {
|
|
937
|
-
return baseTypeValidation;
|
|
938
|
-
}
|
|
939
|
-
var nestedErrors = collectNestedErrors();
|
|
940
|
-
return nestedErrors.length === 0 ? true : {
|
|
941
|
-
input: input,
|
|
942
|
-
nestedErrors: nestedErrors
|
|
943
|
-
};
|
|
944
|
-
}
|
|
945
|
-
function obj$1(objShape) {
|
|
946
|
-
return function validateObject(input, _a) {
|
|
947
|
-
var validateSync = _a.validateSync;
|
|
948
|
-
return _shapeGeneralValidator$1({
|
|
949
|
-
input: input,
|
|
950
|
-
baseType: 'object',
|
|
951
|
-
validateSync: validateSync,
|
|
952
|
-
collectNestedErrors: function collectNestedErrors() {
|
|
953
|
-
return Object.entries(objShape).reduce(function (acc, _a) {
|
|
954
|
-
var path = _a[0],
|
|
955
|
-
pathValidator = _a[1];
|
|
956
|
-
var pathInput = getProperty(input, path);
|
|
957
|
-
var pathResult = validateSync(pathValidator, pathInput);
|
|
958
|
-
return pathResult === true ? acc : __spreadArray(__spreadArray([], acc, true), [_assign(_assign({}, pathResult), {
|
|
959
|
-
path: path
|
|
960
|
-
})], false);
|
|
961
|
-
}, []);
|
|
962
|
-
}
|
|
963
|
-
});
|
|
964
|
-
};
|
|
965
|
-
}
|
|
966
|
-
function objOf$1(ofType) {
|
|
967
|
-
return function validateObjOf(input, _a) {
|
|
968
|
-
var validateSync = _a.validateSync;
|
|
969
|
-
return _shapeGeneralValidator$1({
|
|
970
|
-
input: input,
|
|
971
|
-
baseType: 'object',
|
|
972
|
-
validateSync: validateSync,
|
|
973
|
-
collectNestedErrors: function collectNestedErrors() {
|
|
974
|
-
return Object.entries(input).reduce(function (acc, _a) {
|
|
975
|
-
var key = _a[0],
|
|
976
|
-
keyInput = _a[1];
|
|
977
|
-
var indexResult = validateSync(ofType, keyInput);
|
|
978
|
-
return indexResult === true ? acc : __spreadArray(__spreadArray([], acc, true), [_assign(_assign({}, indexResult), {
|
|
979
|
-
path: key
|
|
980
|
-
})], false);
|
|
981
|
-
}, []);
|
|
982
|
-
}
|
|
983
|
-
});
|
|
984
|
-
};
|
|
985
|
-
}
|
|
986
|
-
function tuple$1(tupleShape) {
|
|
987
|
-
return function validateTuple(input, _a) {
|
|
988
|
-
var validateSync = _a.validateSync;
|
|
989
|
-
return _shapeGeneralValidator$1({
|
|
990
|
-
input: input,
|
|
991
|
-
baseType: 'array',
|
|
992
|
-
validateSync: validateSync,
|
|
993
|
-
collectNestedErrors: function collectNestedErrors() {
|
|
994
|
-
return tupleShape.reduce(function (acc, indexValidator, index) {
|
|
995
|
-
var indexInput = input[index];
|
|
996
|
-
var indexResult = validateSync(indexValidator, indexInput);
|
|
997
|
-
return indexResult === true ? acc : __spreadArray(__spreadArray([], acc, true), [_assign(_assign({}, indexResult), {
|
|
998
|
-
path: index + ''
|
|
999
|
-
})], false);
|
|
1000
|
-
}, []);
|
|
1001
|
-
}
|
|
1002
|
-
});
|
|
1003
|
-
};
|
|
1004
|
-
}
|
|
1005
|
-
function arrayOf$1(ofType) {
|
|
1006
|
-
return function validateArrayOf(input, _a) {
|
|
1007
|
-
var validateSync = _a.validateSync;
|
|
1008
|
-
return _shapeGeneralValidator$1({
|
|
1009
|
-
input: input,
|
|
1010
|
-
baseType: 'array',
|
|
1011
|
-
validateSync: validateSync,
|
|
1012
|
-
collectNestedErrors: function collectNestedErrors() {
|
|
1013
|
-
return input.reduce(function (acc, indexInput, index) {
|
|
1014
|
-
var indexResult = validateSync(ofType, indexInput);
|
|
1015
|
-
return indexResult === true ? acc : __spreadArray(__spreadArray([], acc, true), [_assign(_assign({}, indexResult), {
|
|
1016
|
-
path: index + ''
|
|
1017
|
-
})], false);
|
|
1018
|
-
}, []);
|
|
1019
|
-
}
|
|
1020
|
-
});
|
|
1021
|
-
};
|
|
1022
|
-
}
|
|
1023
|
-
|
|
1024
|
-
function defaultErrorMessage(_a) {
|
|
1025
|
-
var input = _a.input,
|
|
1026
|
-
message = _a.message,
|
|
1027
|
-
nestedErrors = _a.nestedErrors,
|
|
1028
|
-
expectedTypes = _a.expectedTypes;
|
|
1029
|
-
if (message) {
|
|
1030
|
-
return message;
|
|
1031
|
-
}
|
|
1032
|
-
if (nestedErrors) {
|
|
1033
|
-
return "Invalid input: `".concat(JSON.stringify(input), "`.\n").concat(nestedErrors.map(function (error) {
|
|
1034
|
-
return " - ".concat(error.path, ": ").concat(error.message);
|
|
1035
|
-
}).join('\n'));
|
|
1036
|
-
} else if (expectedTypes) {
|
|
1037
|
-
var inputType = typeOf(input);
|
|
1038
|
-
return "Invalid input: '".concat(input, "'. Expected type(s) `").concat(expectedTypes, "`, but got type `").concat(inputType === null ? 'unknown' : inputType, "`");
|
|
1039
|
-
} else {
|
|
1040
|
-
return "Invalid input: '".concat(input, "'.");
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
function resolveValidationResult(_a) {
|
|
1045
|
-
var input = _a.input,
|
|
1046
|
-
result = _a.result,
|
|
1047
|
-
errorMessage = _a.errorMessage;
|
|
1048
|
-
if (result === true) {
|
|
1049
|
-
return true;
|
|
1050
|
-
} else {
|
|
1051
|
-
var _falseLikeResult = function _falseLikeResult() {
|
|
1052
|
-
return {
|
|
1053
|
-
message: errorMessage({
|
|
1054
|
-
input: input
|
|
1055
|
-
})
|
|
1056
|
-
};
|
|
1057
|
-
};
|
|
1058
|
-
return _assign({
|
|
1059
|
-
input: input
|
|
1060
|
-
}, switchExec(typeOf(result), {
|
|
1061
|
-
string: function string() {
|
|
1062
|
-
return {
|
|
1063
|
-
message: result
|
|
1064
|
-
};
|
|
1065
|
-
},
|
|
1066
|
-
error: function error() {
|
|
1067
|
-
return {
|
|
1068
|
-
message: result.message,
|
|
1069
|
-
error: result
|
|
1070
|
-
};
|
|
1071
|
-
},
|
|
1072
|
-
object: function object() {
|
|
1073
|
-
var result_ = result;
|
|
1074
|
-
return _assign(_assign({}, result_), {
|
|
1075
|
-
message: errorMessage(result_)
|
|
1076
|
-
});
|
|
1077
|
-
},
|
|
1078
|
-
//
|
|
1079
|
-
// Boolean result here MUST be false, as true was tested earlier
|
|
1080
|
-
//
|
|
1081
|
-
"boolean": _falseLikeResult,
|
|
1082
|
-
"null": _falseLikeResult,
|
|
1083
|
-
undefined: _falseLikeResult,
|
|
1084
|
-
//
|
|
1085
|
-
// Unsupported validation result
|
|
1086
|
-
//
|
|
1087
|
-
"default": function _default() {
|
|
1088
|
-
throw new Error("Invalid validation result: ".concat(result, " (").concat(typeOf(result), ")"));
|
|
1089
|
-
}
|
|
1090
|
-
}));
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
1093
|
-
|
|
1094
|
-
function parseValidatorInput(_a, validatorInput) {
|
|
1095
|
-
var objValidator = _a.objValidator;
|
|
1096
|
-
//
|
|
1097
|
-
// Parses the validator fn.
|
|
1098
|
-
// If provided with a string, will return a type validator
|
|
1099
|
-
// If provided with a function, will return the function itself
|
|
1100
|
-
//
|
|
1101
|
-
function _parseValidatorFn(fnInput) {
|
|
1102
|
-
switch (typeOf(fnInput)) {
|
|
1103
|
-
case 'string':
|
|
1104
|
-
{
|
|
1105
|
-
return typeValidator(fnInput);
|
|
1106
|
-
}
|
|
1107
|
-
case 'object':
|
|
1108
|
-
{
|
|
1109
|
-
return objValidator(fnInput);
|
|
1110
|
-
}
|
|
1111
|
-
case 'function':
|
|
1112
|
-
{
|
|
1113
|
-
return fnInput;
|
|
1114
|
-
}
|
|
1115
|
-
default:
|
|
1116
|
-
{
|
|
1117
|
-
throw new TypeError("Unsupported fnInput ".concat(fnInput));
|
|
1118
|
-
}
|
|
1119
|
-
}
|
|
1120
|
-
}
|
|
1121
|
-
function _parseValidatorErrorMessageFn(fnInput) {
|
|
1122
|
-
switch (_typeof(fnInput)) {
|
|
1123
|
-
case 'string':
|
|
1124
|
-
{
|
|
1125
|
-
return function (details) {
|
|
1126
|
-
return interpolate(fnInput, details);
|
|
1127
|
-
};
|
|
1128
|
-
}
|
|
1129
|
-
case 'function':
|
|
1130
|
-
{
|
|
1131
|
-
return fnInput;
|
|
1132
|
-
}
|
|
1133
|
-
default:
|
|
1134
|
-
{
|
|
1135
|
-
throw new TypeError("Unsupported error message input ".concat(fnInput));
|
|
1136
|
-
}
|
|
1137
|
-
}
|
|
1138
|
-
}
|
|
1139
|
-
//
|
|
1140
|
-
// Parses the validator input. For more details, see:
|
|
1141
|
-
// types/common.ts -> ValidatorSystem
|
|
1142
|
-
//
|
|
1143
|
-
// Ensures the return result is always of the following format:
|
|
1144
|
-
// [ValidatorFn, ValidatorErrorMessageInput]
|
|
1145
|
-
//
|
|
1146
|
-
var _b = Array.isArray(validatorInput) ? validatorInput : [validatorInput, defaultErrorMessage],
|
|
1147
|
-
fnInput = _b[0],
|
|
1148
|
-
errorMessageInput = _b[1];
|
|
1149
|
-
return [_parseValidatorFn(fnInput), _parseValidatorErrorMessageFn(errorMessageInput)];
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1152
|
-
function validateSyncFn(validatorInput, input) {
|
|
1153
|
-
var result;
|
|
1154
|
-
var _a = parseValidatorInput({
|
|
1155
|
-
objValidator: obj$1
|
|
1156
|
-
}, validatorInput),
|
|
1157
|
-
validatorFn = _a[0],
|
|
1158
|
-
errorMessage = _a[1];
|
|
1159
|
-
try {
|
|
1160
|
-
result = validatorFn(input, {
|
|
1161
|
-
validateSync: validateSyncFn
|
|
1162
|
-
});
|
|
1163
|
-
} catch (err) {
|
|
1164
|
-
result = err;
|
|
1165
|
-
}
|
|
1166
|
-
if (result instanceof Promise) {
|
|
1167
|
-
throw new Error('Promises not supported in sync validation method');
|
|
1168
|
-
}
|
|
1169
|
-
return resolveValidationResult({
|
|
1170
|
-
errorMessage: errorMessage,
|
|
1171
|
-
input: input,
|
|
1172
|
-
result: result
|
|
1173
|
-
});
|
|
1174
|
-
}
|
|
1175
|
-
|
|
1176
|
-
var ValidationError = /** @class */function (_super) {
|
|
1177
|
-
__extends(ValidationError, _super);
|
|
1178
|
-
function ValidationError(_a) {
|
|
1179
|
-
var _this = this;
|
|
1180
|
-
var message = _a.message,
|
|
1181
|
-
details = __rest(_a, ["message"]);
|
|
1182
|
-
_this = _super.call(this, message || "Invalid input ".concat(details.input)) || this;
|
|
1183
|
-
_this.name = 'ValidationError';
|
|
1184
|
-
// Capture correct stack trace in V8 environments (Node.js, Google Chrome)
|
|
1185
|
-
if (Error.captureStackTrace) {
|
|
1186
|
-
Error.captureStackTrace(_this, ValidationError);
|
|
1187
|
-
}
|
|
1188
|
-
Object.assign(_this, details);
|
|
1189
|
-
return _this;
|
|
1190
|
-
}
|
|
1191
|
-
ValidationError.prototype.toJSON = function () {
|
|
1192
|
-
return {
|
|
1193
|
-
message: this.message,
|
|
1194
|
-
input: this.input,
|
|
1195
|
-
code: this.code,
|
|
1196
|
-
error: this.error,
|
|
1197
|
-
path: this.path,
|
|
1198
|
-
nestedErrors: this.nestedErrors
|
|
1199
|
-
};
|
|
1200
|
-
};
|
|
1201
|
-
return ValidationError;
|
|
1202
|
-
}(Error);
|
|
1203
|
-
|
|
1204
|
-
function assertValidSync(validator, input) {
|
|
1205
|
-
var validationResult = validate(validator, input);
|
|
1206
|
-
if (validationResult === true) {
|
|
1207
|
-
return input;
|
|
1208
|
-
} else {
|
|
1209
|
-
throw new ValidationError(validationResult);
|
|
1210
|
-
}
|
|
1211
|
-
}
|
|
1212
|
-
var validate = validateSyncFn;
|
|
1213
|
-
validate.type = typeValidator;
|
|
1214
|
-
validate.obj = obj$1;
|
|
1215
|
-
validate.objOf = objOf$1;
|
|
1216
|
-
validate.tuple = tuple$1;
|
|
1217
|
-
validate.arrayOf = arrayOf$1;
|
|
1218
|
-
validate.and = and$1;
|
|
1219
|
-
validate.or = or$1;
|
|
1220
|
-
validate.not = not$1;
|
|
1221
|
-
validate.assertValid = assertValidSync;
|
|
1222
|
-
|
|
1223
|
-
function _shapeGeneralValidator(_a) {
|
|
1224
|
-
var input = _a.input,
|
|
1225
|
-
baseType = _a.baseType,
|
|
1226
|
-
validateAsync = _a.validateAsync,
|
|
1227
|
-
collectNestedErrors = _a.collectNestedErrors;
|
|
1228
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1229
|
-
var objectValidation, nestedErrors;
|
|
1230
|
-
return __generator(this, function (_b) {
|
|
1231
|
-
switch (_b.label) {
|
|
1232
|
-
case 0:
|
|
1233
|
-
return [4 /*yield*/, validateAsync(typeValidator({
|
|
1234
|
-
type: baseType,
|
|
1235
|
-
required: true
|
|
1236
|
-
}), input)];
|
|
1237
|
-
case 1:
|
|
1238
|
-
objectValidation = _b.sent();
|
|
1239
|
-
if (objectValidation !== true) {
|
|
1240
|
-
return [2 /*return*/, objectValidation];
|
|
1241
|
-
}
|
|
1242
|
-
return [4 /*yield*/, collectNestedErrors()];
|
|
1243
|
-
case 2:
|
|
1244
|
-
nestedErrors = _b.sent();
|
|
1245
|
-
return [2 /*return*/, nestedErrors.length === 0 ? true : {
|
|
1246
|
-
input: input,
|
|
1247
|
-
nestedErrors: nestedErrors
|
|
1248
|
-
}];
|
|
1249
|
-
}
|
|
1250
|
-
});
|
|
1251
|
-
});
|
|
1252
|
-
}
|
|
1253
|
-
function obj(objShape) {
|
|
1254
|
-
return function asyncValidateObj(input, _a) {
|
|
1255
|
-
var validateAsync = _a.validateAsync;
|
|
1256
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1257
|
-
var _this = this;
|
|
1258
|
-
return __generator(this, function (_b) {
|
|
1259
|
-
return [2 /*return*/, _shapeGeneralValidator({
|
|
1260
|
-
input: input,
|
|
1261
|
-
baseType: 'object',
|
|
1262
|
-
validateAsync: validateAsync,
|
|
1263
|
-
collectNestedErrors: function collectNestedErrors() {
|
|
1264
|
-
return promiseReduce(Object.entries(objShape), function (acc, _a) {
|
|
1265
|
-
var path = _a[0],
|
|
1266
|
-
pathValidator = _a[1];
|
|
1267
|
-
return __awaiter(_this, void 0, void 0, function () {
|
|
1268
|
-
var pathInput, pathResult;
|
|
1269
|
-
return __generator(this, function (_b) {
|
|
1270
|
-
switch (_b.label) {
|
|
1271
|
-
case 0:
|
|
1272
|
-
pathInput = getProperty(input, path);
|
|
1273
|
-
return [4 /*yield*/, validateAsync(pathValidator, pathInput)];
|
|
1274
|
-
case 1:
|
|
1275
|
-
pathResult = _b.sent();
|
|
1276
|
-
return [2 /*return*/, pathResult === true ? acc : __spreadArray(__spreadArray([], acc, true), [_assign(_assign({}, pathResult), {
|
|
1277
|
-
path: path
|
|
1278
|
-
})], false)];
|
|
1279
|
-
}
|
|
1280
|
-
});
|
|
1281
|
-
});
|
|
1282
|
-
}, []);
|
|
1283
|
-
}
|
|
1284
|
-
})];
|
|
1285
|
-
});
|
|
1286
|
-
});
|
|
1287
|
-
};
|
|
1288
|
-
}
|
|
1289
|
-
function objOf(ofType) {
|
|
1290
|
-
return function asyncValidateObjOf(input, _a) {
|
|
1291
|
-
var validateAsync = _a.validateAsync;
|
|
1292
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1293
|
-
var _this = this;
|
|
1294
|
-
return __generator(this, function (_b) {
|
|
1295
|
-
return [2 /*return*/, _shapeGeneralValidator({
|
|
1296
|
-
input: input,
|
|
1297
|
-
baseType: 'object',
|
|
1298
|
-
validateAsync: validateAsync,
|
|
1299
|
-
collectNestedErrors: function collectNestedErrors() {
|
|
1300
|
-
return promiseReduce(Object.entries(input), function (acc, _a) {
|
|
1301
|
-
var key = _a[0],
|
|
1302
|
-
keyInput = _a[1];
|
|
1303
|
-
return __awaiter(_this, void 0, void 0, function () {
|
|
1304
|
-
var indexResult;
|
|
1305
|
-
return __generator(this, function (_b) {
|
|
1306
|
-
switch (_b.label) {
|
|
1307
|
-
case 0:
|
|
1308
|
-
return [4 /*yield*/, validateAsync(ofType, keyInput)];
|
|
1309
|
-
case 1:
|
|
1310
|
-
indexResult = _b.sent();
|
|
1311
|
-
return [2 /*return*/, indexResult === true ? acc : __spreadArray(__spreadArray([], acc, true), [_assign(_assign({}, indexResult), {
|
|
1312
|
-
path: key
|
|
1313
|
-
})], false)];
|
|
1314
|
-
}
|
|
1315
|
-
});
|
|
1316
|
-
});
|
|
1317
|
-
}, []);
|
|
1318
|
-
}
|
|
1319
|
-
})];
|
|
1320
|
-
});
|
|
1321
|
-
});
|
|
1322
|
-
};
|
|
1323
|
-
}
|
|
1324
|
-
function tuple(tupleShape) {
|
|
1325
|
-
return function asyncValidateTuple(input, _a) {
|
|
1326
|
-
var validateAsync = _a.validateAsync;
|
|
1327
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1328
|
-
var _this = this;
|
|
1329
|
-
return __generator(this, function (_b) {
|
|
1330
|
-
return [2 /*return*/, _shapeGeneralValidator({
|
|
1331
|
-
input: input,
|
|
1332
|
-
baseType: 'array',
|
|
1333
|
-
validateAsync: validateAsync,
|
|
1334
|
-
collectNestedErrors: function collectNestedErrors() {
|
|
1335
|
-
return promiseReduce(tupleShape, function (acc, indexValidator, index) {
|
|
1336
|
-
return __awaiter(_this, void 0, void 0, function () {
|
|
1337
|
-
var indexInput, indexResult;
|
|
1338
|
-
return __generator(this, function (_a) {
|
|
1339
|
-
switch (_a.label) {
|
|
1340
|
-
case 0:
|
|
1341
|
-
indexInput = input[index];
|
|
1342
|
-
return [4 /*yield*/, validateAsync(indexValidator, indexInput)];
|
|
1343
|
-
case 1:
|
|
1344
|
-
indexResult = _a.sent();
|
|
1345
|
-
return [2 /*return*/, indexResult === true ? acc : __spreadArray(__spreadArray([], acc, true), [_assign(_assign({}, indexResult), {
|
|
1346
|
-
path: index + ''
|
|
1347
|
-
})], false)];
|
|
1348
|
-
}
|
|
1349
|
-
});
|
|
1350
|
-
});
|
|
1351
|
-
}, []);
|
|
1352
|
-
}
|
|
1353
|
-
})];
|
|
1354
|
-
});
|
|
1355
|
-
});
|
|
1356
|
-
};
|
|
1357
|
-
}
|
|
1358
|
-
function arrayOf(ofType) {
|
|
1359
|
-
return function asyncValidateArrayOf(input, _a) {
|
|
1360
|
-
var validateAsync = _a.validateAsync;
|
|
1361
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1362
|
-
var _this = this;
|
|
1363
|
-
return __generator(this, function (_b) {
|
|
1364
|
-
return [2 /*return*/, _shapeGeneralValidator({
|
|
1365
|
-
input: input,
|
|
1366
|
-
baseType: 'array',
|
|
1367
|
-
validateAsync: validateAsync,
|
|
1368
|
-
collectNestedErrors: function collectNestedErrors() {
|
|
1369
|
-
return promiseReduce(input, function (acc, indexInput, index) {
|
|
1370
|
-
return __awaiter(_this, void 0, void 0, function () {
|
|
1371
|
-
var indexResult;
|
|
1372
|
-
return __generator(this, function (_a) {
|
|
1373
|
-
switch (_a.label) {
|
|
1374
|
-
case 0:
|
|
1375
|
-
return [4 /*yield*/, validateAsync(ofType, indexInput)];
|
|
1376
|
-
case 1:
|
|
1377
|
-
indexResult = _a.sent();
|
|
1378
|
-
return [2 /*return*/, indexResult === true ? acc : __spreadArray(__spreadArray([], acc, true), [_assign(_assign({}, indexResult), {
|
|
1379
|
-
path: index + ''
|
|
1380
|
-
})], false)];
|
|
1381
|
-
}
|
|
1382
|
-
});
|
|
1383
|
-
});
|
|
1384
|
-
}, []);
|
|
1385
|
-
}
|
|
1386
|
-
})];
|
|
1387
|
-
});
|
|
1388
|
-
});
|
|
1389
|
-
};
|
|
1390
|
-
}
|
|
1391
|
-
|
|
1392
|
-
//
|
|
1393
|
-
// And operator (serial)
|
|
1394
|
-
//
|
|
1395
|
-
function and(validators) {
|
|
1396
|
-
return function validateAnd(input, _a) {
|
|
1397
|
-
var validateAsync = _a.validateAsync;
|
|
1398
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1399
|
-
var result;
|
|
1400
|
-
return __generator(this, function (_b) {
|
|
1401
|
-
switch (_b.label) {
|
|
1402
|
-
case 0:
|
|
1403
|
-
return [4 /*yield*/, promiseReduce(validators, function (acc, validator) {
|
|
1404
|
-
return acc !== true ? acc : validateAsync(validator, input);
|
|
1405
|
-
}, true)];
|
|
1406
|
-
case 1:
|
|
1407
|
-
result = _b.sent();
|
|
1408
|
-
if (result === true) {
|
|
1409
|
-
return [2 /*return*/, true];
|
|
1410
|
-
} else {
|
|
1411
|
-
return [2 /*return*/, result];
|
|
1412
|
-
}
|
|
1413
|
-
}
|
|
1414
|
-
});
|
|
1415
|
-
});
|
|
1416
|
-
};
|
|
1417
|
-
}
|
|
1418
|
-
//
|
|
1419
|
-
// Or operator (serial)
|
|
1420
|
-
//
|
|
1421
|
-
function or(validators) {
|
|
1422
|
-
return function validateOr(input, _a) {
|
|
1423
|
-
var validateAsync = _a.validateAsync;
|
|
1424
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1425
|
-
var someIsValid;
|
|
1426
|
-
var _this = this;
|
|
1427
|
-
return __generator(this, function (_b) {
|
|
1428
|
-
switch (_b.label) {
|
|
1429
|
-
case 0:
|
|
1430
|
-
return [4 /*yield*/, promiseReduce(validators, function (acc, validator) {
|
|
1431
|
-
return __awaiter(_this, void 0, void 0, function () {
|
|
1432
|
-
var _a;
|
|
1433
|
-
return __generator(this, function (_b) {
|
|
1434
|
-
switch (_b.label) {
|
|
1435
|
-
case 0:
|
|
1436
|
-
_a = acc === true;
|
|
1437
|
-
if (_a) return [3 /*break*/, 2];
|
|
1438
|
-
return [4 /*yield*/, validateAsync(validator, input)];
|
|
1439
|
-
case 1:
|
|
1440
|
-
_a = _b.sent() === true;
|
|
1441
|
-
_b.label = 2;
|
|
1442
|
-
case 2:
|
|
1443
|
-
return [2 /*return*/, _a];
|
|
1444
|
-
}
|
|
1445
|
-
});
|
|
1446
|
-
});
|
|
1447
|
-
}, false)];
|
|
1448
|
-
case 1:
|
|
1449
|
-
someIsValid = _b.sent();
|
|
1450
|
-
return [2 /*return*/, someIsValid];
|
|
1451
|
-
}
|
|
1452
|
-
});
|
|
1453
|
-
});
|
|
1454
|
-
};
|
|
1455
|
-
}
|
|
1456
|
-
//
|
|
1457
|
-
// Not
|
|
1458
|
-
//
|
|
1459
|
-
function not(validator) {
|
|
1460
|
-
return function validateNot(input, _a) {
|
|
1461
|
-
var validateAsync = _a.validateAsync;
|
|
1462
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1463
|
-
var result;
|
|
1464
|
-
return __generator(this, function (_b) {
|
|
1465
|
-
switch (_b.label) {
|
|
1466
|
-
case 0:
|
|
1467
|
-
return [4 /*yield*/, validateAsync(validator, input)];
|
|
1468
|
-
case 1:
|
|
1469
|
-
result = _b.sent();
|
|
1470
|
-
return [2 /*return*/, result !== true];
|
|
1471
|
-
}
|
|
1472
|
-
});
|
|
1473
|
-
});
|
|
1474
|
-
};
|
|
1475
|
-
}
|
|
1476
|
-
|
|
1477
|
-
function validateAsyncFn(validatorInput, input) {
|
|
1478
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1479
|
-
var result, _a, validatorFn, errorMessage, err_1;
|
|
1480
|
-
return __generator(this, function (_b) {
|
|
1481
|
-
switch (_b.label) {
|
|
1482
|
-
case 0:
|
|
1483
|
-
_a = parseValidatorInput({
|
|
1484
|
-
objValidator: obj
|
|
1485
|
-
}, validatorInput), validatorFn = _a[0], errorMessage = _a[1];
|
|
1486
|
-
_b.label = 1;
|
|
1487
|
-
case 1:
|
|
1488
|
-
_b.trys.push([1, 3,, 4]);
|
|
1489
|
-
return [4 /*yield*/, validatorFn(input, {
|
|
1490
|
-
validateAsync: validateAsyncFn
|
|
1491
|
-
})];
|
|
1492
|
-
case 2:
|
|
1493
|
-
result = _b.sent();
|
|
1494
|
-
return [3 /*break*/, 4];
|
|
1495
|
-
case 3:
|
|
1496
|
-
err_1 = _b.sent();
|
|
1497
|
-
result = err_1;
|
|
1498
|
-
return [3 /*break*/, 4];
|
|
1499
|
-
case 4:
|
|
1500
|
-
return [2 /*return*/, resolveValidationResult({
|
|
1501
|
-
errorMessage: errorMessage,
|
|
1502
|
-
input: input,
|
|
1503
|
-
result: result
|
|
1504
|
-
})];
|
|
1505
|
-
}
|
|
1506
|
-
});
|
|
1507
|
-
});
|
|
1508
|
-
}
|
|
1509
|
-
|
|
1510
|
-
function assertValidAsync(validator, input) {
|
|
1511
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1512
|
-
var validationResult;
|
|
1513
|
-
return __generator(this, function (_a) {
|
|
1514
|
-
switch (_a.label) {
|
|
1515
|
-
case 0:
|
|
1516
|
-
return [4 /*yield*/, validateAsync(validator, input)];
|
|
1517
|
-
case 1:
|
|
1518
|
-
validationResult = _a.sent();
|
|
1519
|
-
if (validationResult === true) {
|
|
1520
|
-
return [2 /*return*/, input];
|
|
1521
|
-
} else {
|
|
1522
|
-
throw new ValidationError(validationResult);
|
|
1523
|
-
}
|
|
1524
|
-
}
|
|
1525
|
-
});
|
|
1526
|
-
});
|
|
1527
|
-
}
|
|
1528
|
-
var validateAsync = validateAsyncFn;
|
|
1529
|
-
validateAsync.type = typeValidator;
|
|
1530
|
-
validateAsync.obj = obj;
|
|
1531
|
-
validateAsync.objOf = objOf;
|
|
1532
|
-
validateAsync.tuple = tuple;
|
|
1533
|
-
validateAsync.arrayOf = arrayOf;
|
|
1534
|
-
validateAsync.and = and;
|
|
1535
|
-
validateAsync.or = or;
|
|
1536
|
-
validateAsync.not = not;
|
|
1537
|
-
validateAsync.assertValid = assertValidAsync;
|
|
1538
|
-
|
|
1539
1182
|
function defaultParseResponse(response) {
|
|
1540
1183
|
return response.json();
|
|
1541
1184
|
}
|
|
@@ -1592,7 +1235,7 @@ function fetchAllPages(_a) {
|
|
|
1592
1235
|
case 1:
|
|
1593
1236
|
return [4 /*yield*/, store.getSize()];
|
|
1594
1237
|
case 2:
|
|
1595
|
-
currentOffset = _d.sent()
|
|
1238
|
+
currentOffset = _d.sent();
|
|
1596
1239
|
return [4 /*yield*/, fetchPage({
|
|
1597
1240
|
offset: currentOffset,
|
|
1598
1241
|
pageSize: pageSize
|
|
@@ -1619,12 +1262,210 @@ function fetchAllPages(_a) {
|
|
|
1619
1262
|
});
|
|
1620
1263
|
}
|
|
1621
1264
|
|
|
1622
|
-
function
|
|
1623
|
-
|
|
1624
|
-
|
|
1265
|
+
function deprecateFn(fn, message) {
|
|
1266
|
+
// Creating a new function that wraps the original function
|
|
1267
|
+
var wrappedFunction = function wrappedFunction() {
|
|
1268
|
+
var args = [];
|
|
1269
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1270
|
+
args[_i] = arguments[_i];
|
|
1271
|
+
}
|
|
1272
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1273
|
+
console.warn(["[deprecated][fn] ".concat(fn.name, " is deprecated"), message].filter(Boolean).join(': '));
|
|
1274
|
+
}
|
|
1275
|
+
return fn.apply(void 0, args);
|
|
1276
|
+
};
|
|
1277
|
+
// Copying the original function's properties to the new function
|
|
1278
|
+
Object.assign(wrappedFunction, fn);
|
|
1279
|
+
// Setting the name property explicitly to preserve the original function's name
|
|
1280
|
+
Object.defineProperty(wrappedFunction, 'name', {
|
|
1281
|
+
value: "".concat(fn.name, "_DEPRECATED"),
|
|
1282
|
+
configurable: true
|
|
1283
|
+
});
|
|
1284
|
+
return wrappedFunction;
|
|
1285
|
+
}
|
|
1286
|
+
function deprecateProperty(obj, key, value, message) {
|
|
1287
|
+
// Create a new object that includes all properties of the original object
|
|
1288
|
+
var newObj = Object.create(Object.getPrototypeOf(obj), Object.getOwnPropertyDescriptors(obj));
|
|
1289
|
+
Object.defineProperty(newObj, key, {
|
|
1290
|
+
get: function get() {
|
|
1291
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1292
|
+
console.warn(["[deprecated][property] ".concat(key, " is deprecated"), message].filter(Boolean).join(': '));
|
|
1293
|
+
}
|
|
1294
|
+
return value;
|
|
1295
|
+
}
|
|
1296
|
+
});
|
|
1297
|
+
return newObj;
|
|
1298
|
+
}
|
|
1299
|
+
function deprecateInput(inputValue, message, convert) {
|
|
1300
|
+
if (typeof inputValue === 'undefined') {
|
|
1301
|
+
return undefined;
|
|
1302
|
+
} else {
|
|
1303
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1304
|
+
console.warn("[deprecated][input] ".concat(message, " | received: ").concat(inputValue));
|
|
1305
|
+
}
|
|
1306
|
+
return typeof convert === 'function' ? convert(inputValue) : inputValue;
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
function slugify(str, delimiter) {
|
|
1311
|
+
if (delimiter === void 0) {
|
|
1312
|
+
delimiter = '-';
|
|
1313
|
+
}
|
|
1314
|
+
// Escape the delimiter for safe use in regex
|
|
1315
|
+
var safeDelimiter = delimiter.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
1316
|
+
var CONSECUTIVE_DELIMITER_RE = new RegExp("".concat(safeDelimiter, "+"), 'g');
|
|
1317
|
+
var LEADING_TRAILING_DELIMITER_RE = new RegExp("^".concat(safeDelimiter, "+|").concat(safeDelimiter, "+$"), 'g');
|
|
1318
|
+
return str.trim() // Trim leading and trailing spaces
|
|
1625
1319
|
.toLowerCase() // Convert to lowercase
|
|
1626
|
-
.
|
|
1627
|
-
.
|
|
1320
|
+
.normalize('NFD') // Decompose accented characters
|
|
1321
|
+
.replace(/[\u0300-\u036f]/g, '') // Remove diacritics
|
|
1322
|
+
.replace(/[^a-z0-9]+/g, delimiter) // Replace non-alphanumeric with hyphens
|
|
1323
|
+
.replace(CONSECUTIVE_DELIMITER_RE, delimiter) // Collapse consecutive hyphens
|
|
1324
|
+
.replace(LEADING_TRAILING_DELIMITER_RE, ''); // Remove leading/trailing hyphens
|
|
1325
|
+
}
|
|
1326
|
+
var normalizeString = deprecateFn(slugify, 'normalizeString is depreacted, use @orioro/util -> slugify instead');
|
|
1327
|
+
|
|
1328
|
+
//
|
|
1329
|
+
// Hook module
|
|
1330
|
+
//
|
|
1331
|
+
function hookFn(fn, _a) {
|
|
1332
|
+
var input = _a.input,
|
|
1333
|
+
validate = _a.validate,
|
|
1334
|
+
before = _a.before,
|
|
1335
|
+
output = _a.output,
|
|
1336
|
+
after = _a.after;
|
|
1337
|
+
return function () {
|
|
1338
|
+
var args = [];
|
|
1339
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1340
|
+
args[_i] = arguments[_i];
|
|
1341
|
+
}
|
|
1342
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1343
|
+
var _input, _a, validationResult, error, rawResult, result, _b;
|
|
1344
|
+
return __generator(this, function (_c) {
|
|
1345
|
+
switch (_c.label) {
|
|
1346
|
+
case 0:
|
|
1347
|
+
if (!(typeof input === 'function')) return [3 /*break*/, 2];
|
|
1348
|
+
return [4 /*yield*/, input.apply(void 0, args)];
|
|
1349
|
+
case 1:
|
|
1350
|
+
_a = _c.sent();
|
|
1351
|
+
return [3 /*break*/, 3];
|
|
1352
|
+
case 2:
|
|
1353
|
+
_a = args;
|
|
1354
|
+
_c.label = 3;
|
|
1355
|
+
case 3:
|
|
1356
|
+
_input = _a;
|
|
1357
|
+
if (!Array.isArray(_input)) {
|
|
1358
|
+
throw new TypeError('Input hook must resolve an array of args');
|
|
1359
|
+
}
|
|
1360
|
+
if (!(typeof validate === 'function')) return [3 /*break*/, 5];
|
|
1361
|
+
return [4 /*yield*/, validate.apply(void 0, _input)];
|
|
1362
|
+
case 4:
|
|
1363
|
+
validationResult = _c.sent();
|
|
1364
|
+
if (validationResult !== true) {
|
|
1365
|
+
error = typeof validationResult === 'string' ? new Error(validationResult) : validationResult instanceof Error ? validationResult : new Error('Invalid input');
|
|
1366
|
+
throw error;
|
|
1367
|
+
}
|
|
1368
|
+
_c.label = 5;
|
|
1369
|
+
case 5:
|
|
1370
|
+
if (!(typeof before === 'function')) return [3 /*break*/, 7];
|
|
1371
|
+
return [4 /*yield*/, before.apply(void 0, _input)];
|
|
1372
|
+
case 6:
|
|
1373
|
+
_c.sent();
|
|
1374
|
+
_c.label = 7;
|
|
1375
|
+
case 7:
|
|
1376
|
+
return [4 /*yield*/, fn.apply(void 0, _input)];
|
|
1377
|
+
case 8:
|
|
1378
|
+
rawResult = _c.sent();
|
|
1379
|
+
if (!(typeof output === 'function')) return [3 /*break*/, 10];
|
|
1380
|
+
return [4 /*yield*/, output(rawResult)];
|
|
1381
|
+
case 9:
|
|
1382
|
+
_b = _c.sent();
|
|
1383
|
+
return [3 /*break*/, 11];
|
|
1384
|
+
case 10:
|
|
1385
|
+
_b = rawResult;
|
|
1386
|
+
_c.label = 11;
|
|
1387
|
+
case 11:
|
|
1388
|
+
result = _b;
|
|
1389
|
+
if (!(typeof after === 'function')) return [3 /*break*/, 13];
|
|
1390
|
+
return [4 /*yield*/, after.apply(void 0, __spreadArray([result], _input, false))];
|
|
1391
|
+
case 12:
|
|
1392
|
+
_c.sent();
|
|
1393
|
+
_c.label = 13;
|
|
1394
|
+
case 13:
|
|
1395
|
+
return [2 /*return*/, result];
|
|
1396
|
+
}
|
|
1397
|
+
});
|
|
1398
|
+
});
|
|
1399
|
+
};
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
function isValidUrl(url) {
|
|
1403
|
+
try {
|
|
1404
|
+
new URL(url);
|
|
1405
|
+
return true;
|
|
1406
|
+
} catch (_a) {
|
|
1407
|
+
return false;
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
//
|
|
1412
|
+
// https://nodejs.org/api/url.html#url-strings-and-url-objects
|
|
1413
|
+
//
|
|
1414
|
+
// ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
|
|
1415
|
+
// │ href │
|
|
1416
|
+
// ├──────────┬──┬─────────────────────┬────────────────────────┬───────────────────────────┬───────┤
|
|
1417
|
+
// │ protocol │ │ auth │ host │ path │ hash │
|
|
1418
|
+
// │ │ │ ├─────────────────┬──────┼──────────┬────────────────┤ │
|
|
1419
|
+
// │ │ │ │ hostname │ port │ pathname │ search │ │
|
|
1420
|
+
// │ │ │ │ │ │ ├─┬──────────────┤ │
|
|
1421
|
+
// │ │ │ │ │ │ │ │ query │ │
|
|
1422
|
+
// " https: // user : pass @ sub.example.com : 8080 /p/a/t/h ? query=string #hash "
|
|
1423
|
+
// │ │ │ │ │ hostname │ port │ │ │ │
|
|
1424
|
+
// │ │ │ │ ├─────────────────┴──────┤ │ │ │
|
|
1425
|
+
// │ protocol │ │ username │ password │ host │ │ │ │
|
|
1426
|
+
// ├──────────┴──┼──────────┴──────────┼────────────────────────┤ │ │ │
|
|
1427
|
+
// │ origin │ │ origin │ pathname │ search │ hash │
|
|
1428
|
+
// ├─────────────┴─────────────────────┴────────────────────────┴──────────┴────────────────┴───────┤
|
|
1429
|
+
// │ href │
|
|
1430
|
+
// └────────────────────────────────────────────────────────────────────────────────────────────────┘
|
|
1431
|
+
//
|
|
1432
|
+
var DEFAULT_PROTOCOL = 'https:';
|
|
1433
|
+
function _protocol(protocol) {
|
|
1434
|
+
return !protocol ? DEFAULT_PROTOCOL : protocol.endsWith(':') ? protocol : "".concat(protocol, ":");
|
|
1435
|
+
}
|
|
1436
|
+
function _baseHref(spec) {
|
|
1437
|
+
if (spec.href) {
|
|
1438
|
+
return spec.href;
|
|
1439
|
+
} else {
|
|
1440
|
+
var protocol = _protocol(spec.protocol);
|
|
1441
|
+
var host = spec.host || spec.hostname;
|
|
1442
|
+
if (!host) {
|
|
1443
|
+
throw new Error("Invalid URL spec: either 'href', 'host' or 'hostname' must be defined.");
|
|
1444
|
+
}
|
|
1445
|
+
return "".concat(protocol, "//").concat(host);
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
function url(spec) {
|
|
1449
|
+
if (typeof spec === 'string') {
|
|
1450
|
+
return new URL(spec).href;
|
|
1451
|
+
} else {
|
|
1452
|
+
var url_1 = new URL(_baseHref(spec));
|
|
1453
|
+
if (spec.protocol) url_1.protocol = spec.protocol;
|
|
1454
|
+
if (spec.username) url_1.username = spec.username;
|
|
1455
|
+
if (spec.password) url_1.password = spec.password;
|
|
1456
|
+
if (spec.host) url_1.host = spec.host;
|
|
1457
|
+
if (spec.hostname) url_1.hostname = spec.hostname;
|
|
1458
|
+
if (spec.port) url_1.port = spec.port;
|
|
1459
|
+
if (spec.pathname) url_1.pathname = spec.pathname;
|
|
1460
|
+
if (spec.search) url_1.search = spec.search;
|
|
1461
|
+
// Handle searchParams
|
|
1462
|
+
if (spec.searchParams) {
|
|
1463
|
+
var searchString = Array.isArray(spec.searchParams) ? queryString.stringify(spec.searchParams[0], spec.searchParams[1]) : queryString.stringify(spec.searchParams);
|
|
1464
|
+
url_1.search = searchString;
|
|
1465
|
+
}
|
|
1466
|
+
if (spec.hash) url_1.hash = spec.hash;
|
|
1467
|
+
return url_1.href;
|
|
1468
|
+
}
|
|
1628
1469
|
}
|
|
1629
1470
|
|
|
1630
|
-
export { PromiseLikeEventEmitter, SKIPPED, TimeoutError,
|
|
1471
|
+
export { DEFAULT_TYPES, PromiseLikeEventEmitter, SKIPPED, TimeoutError, arrayChunk, batchFn, dataJoin, debugFn, deepFreeze, deprecateFn, deprecateInput, deprecateProperty, fetchAllPages, hasNestedPromises, hookFn, inMemoryDataStore, interpolate, isPromise, isValidUrl, makeDeferred, makeTypeOf, maybeAsyncFn, maybeFn, maybeReturnPromise, normalizeString, paginatedHttpFetch, parseBatchedResults, pickPaths, promiseReduce, resolveNestedPromises, sequentialCallIdGenerator, slugify, strExpr, switchExec, switchValue, syntheticJson, typeMap, typeOf, untilConditionIsSatisfiedReducer, url, wait, withTimeout };
|