@orioro/util 0.10.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/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 debugFn(fnName, fn, logCall, logResult) {
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 = generateDeterministicId(__spreadArray([fnName, fn], args, true));
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$.]+)\s*\}/g;
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
- return template.replace(INTERPOLATION_REGEXP, function (_, path) {
356
- var value = getProperty(data, path);
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
- console.warn("Attempting to use non interpolatable value in interpolate ".concat(value));
369
- return '';
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' ? getProperty(sourceObj, resolver) : resolver(sourceObj);
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' ? setProperty(acc, targetPath, valueAfterDefault) : acc;
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) {
@@ -693,6 +804,267 @@ function makeDeferred() {
693
804
  };
694
805
  }
695
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
+
696
1068
  function testCriteria(criteria, input) {
697
1069
  switch (_typeof(criteria)) {
698
1070
  case 'function':
@@ -733,37 +1105,6 @@ function switchExec(input, cases) {
733
1105
  return fn.apply(void 0, args);
734
1106
  }
735
1107
 
736
- /*!
737
- * is-plain-object <https://github.com/jonschlinkert/is-plain-object>
738
- *
739
- * Copyright (c) 2014-2017, Jon Schlinkert.
740
- * Released under the MIT License.
741
- */
742
-
743
- function isObject(o) {
744
- return Object.prototype.toString.call(o) === '[object Object]';
745
- }
746
- function isPlainObject(o) {
747
- var ctor, prot;
748
- if (isObject(o) === false) return false;
749
-
750
- // If has modified constructor
751
- ctor = o.constructor;
752
- if (ctor === undefined) return true;
753
-
754
- // If has modified prototype
755
- prot = ctor.prototype;
756
- if (isObject(prot) === false) return false;
757
-
758
- // If constructor does not have an Object-specific method
759
- if (prot.hasOwnProperty('isPrototypeOf') === false) {
760
- return false;
761
- }
762
-
763
- // Most likely a plain Object
764
- return true;
765
- }
766
-
767
1108
  //
768
1109
  // The only role of this function is to let typescript
769
1110
  // be aware of the available types
@@ -838,729 +1179,6 @@ var DEFAULT_TYPES = typeMap({
838
1179
  });
839
1180
  var typeOf = makeTypeOf(DEFAULT_TYPES);
840
1181
 
841
- var TYPE_RE = /([a-z0-9]+)(\!)?$/i;
842
- var TYPE_SEPARATOR_RE = /\s*\|\s*/g;
843
- function parseSingleType(typeInput) {
844
- var match = typeInput.match(TYPE_RE);
845
- if (!match) {
846
- throw new Error("Invalid type ".concat(typeInput));
847
- } else {
848
- var typeName = match[1],
849
- requiredSignal = match[2];
850
- return {
851
- type: typeName,
852
- required: requiredSignal === '!'
853
- };
854
- }
855
- }
856
- function serializeExpectedTypes(expectedTypes) {
857
- return expectedTypes.map(function (expectedType) {
858
- return "".concat(expectedType.type).concat(expectedType.required ? '!' : '');
859
- }).join(' | ');
860
- }
861
- function parseExpectedTypes(expectedTypesInput) {
862
- switch (typeOf(expectedTypesInput)) {
863
- case 'string':
864
- {
865
- return expectedTypesInput.split(TYPE_SEPARATOR_RE).map(function (typeInput) {
866
- return parseSingleType(typeInput);
867
- });
868
- }
869
- case 'array':
870
- {
871
- return expectedTypesInput.map(function (expectedType) {
872
- return typeof expectedType === 'string' ? parseSingleType(expectedType) : expectedType;
873
- });
874
- }
875
- case 'object':
876
- {
877
- return [expectedTypesInput];
878
- }
879
- default:
880
- {
881
- throw new Error("Invalid expectedType ".concat(expectedTypesInput));
882
- }
883
- }
884
- }
885
- function typeValidator(expectedTypesInput) {
886
- var expectedTypes = parseExpectedTypes(expectedTypesInput);
887
- return function validateType(input) {
888
- var inputType = typeOf(input);
889
- var nullOrUndefined = function nullOrUndefined() {
890
- return expectedTypes.some(function (expectedType) {
891
- return expectedType.type === 'undefined' || expectedType.type === 'null' || expectedType.required === false;
892
- });
893
- };
894
- var isValid = switchExec(inputType, {
895
- "null": nullOrUndefined,
896
- undefined: nullOrUndefined,
897
- "default": function _default() {
898
- return expectedTypes.some(function (expectedType) {
899
- return expectedType.type === inputType;
900
- });
901
- }
902
- });
903
- if (isValid) {
904
- return true;
905
- } else {
906
- return {
907
- expectedTypes: serializeExpectedTypes(expectedTypes),
908
- input: input
909
- };
910
- }
911
- };
912
- }
913
-
914
- //
915
- // And operator (serial)
916
- //
917
- function and$1(validators) {
918
- return function validateAnd(input, _a) {
919
- var validateSync = _a.validateSync;
920
- var result = validators.reduce(function (acc, validator) {
921
- return acc !== true ? acc : validateSync(validator, input);
922
- }, true);
923
- if (result === true) {
924
- return true;
925
- } else {
926
- return result;
927
- }
928
- };
929
- }
930
- //
931
- // Or operator (serial)
932
- //
933
- function or$1(validators) {
934
- return function validateOr(input, _a) {
935
- var validateSync = _a.validateSync;
936
- var someIsValid = validators.some(function (validator) {
937
- return validateSync(validator, input) === true;
938
- });
939
- return someIsValid;
940
- };
941
- }
942
- //
943
- // Not
944
- //
945
- function not$1(validator) {
946
- return function validateNot(input, _a) {
947
- var validateSync = _a.validateSync;
948
- return validateSync(validator, input) !== true;
949
- };
950
- }
951
-
952
- function _shapeGeneralValidator$1(_a) {
953
- var input = _a.input,
954
- baseType = _a.baseType,
955
- collectNestedErrors = _a.collectNestedErrors,
956
- validateSync = _a.validateSync;
957
- var baseTypeValidation = validateSync(typeValidator({
958
- type: baseType,
959
- required: true
960
- }), input);
961
- if (baseTypeValidation !== true) {
962
- return baseTypeValidation;
963
- }
964
- var nestedErrors = collectNestedErrors();
965
- return nestedErrors.length === 0 ? true : {
966
- input: input,
967
- nestedErrors: nestedErrors
968
- };
969
- }
970
- function obj$1(objShape) {
971
- return function validateObject(input, _a) {
972
- var validateSync = _a.validateSync;
973
- return _shapeGeneralValidator$1({
974
- input: input,
975
- baseType: 'object',
976
- validateSync: validateSync,
977
- collectNestedErrors: function collectNestedErrors() {
978
- return Object.entries(objShape).reduce(function (acc, _a) {
979
- var path = _a[0],
980
- pathValidator = _a[1];
981
- var pathInput = getProperty(input, path);
982
- var pathResult = validateSync(pathValidator, pathInput);
983
- return pathResult === true ? acc : __spreadArray(__spreadArray([], acc, true), [_assign(_assign({}, pathResult), {
984
- path: path
985
- })], false);
986
- }, []);
987
- }
988
- });
989
- };
990
- }
991
- function objOf$1(ofType) {
992
- return function validateObjOf(input, _a) {
993
- var validateSync = _a.validateSync;
994
- return _shapeGeneralValidator$1({
995
- input: input,
996
- baseType: 'object',
997
- validateSync: validateSync,
998
- collectNestedErrors: function collectNestedErrors() {
999
- return Object.entries(input).reduce(function (acc, _a) {
1000
- var key = _a[0],
1001
- keyInput = _a[1];
1002
- var indexResult = validateSync(ofType, keyInput);
1003
- return indexResult === true ? acc : __spreadArray(__spreadArray([], acc, true), [_assign(_assign({}, indexResult), {
1004
- path: key
1005
- })], false);
1006
- }, []);
1007
- }
1008
- });
1009
- };
1010
- }
1011
- function tuple$1(tupleShape) {
1012
- return function validateTuple(input, _a) {
1013
- var validateSync = _a.validateSync;
1014
- return _shapeGeneralValidator$1({
1015
- input: input,
1016
- baseType: 'array',
1017
- validateSync: validateSync,
1018
- collectNestedErrors: function collectNestedErrors() {
1019
- return tupleShape.reduce(function (acc, indexValidator, index) {
1020
- var indexInput = input[index];
1021
- var indexResult = validateSync(indexValidator, indexInput);
1022
- return indexResult === true ? acc : __spreadArray(__spreadArray([], acc, true), [_assign(_assign({}, indexResult), {
1023
- path: index + ''
1024
- })], false);
1025
- }, []);
1026
- }
1027
- });
1028
- };
1029
- }
1030
- function arrayOf$1(ofType) {
1031
- return function validateArrayOf(input, _a) {
1032
- var validateSync = _a.validateSync;
1033
- return _shapeGeneralValidator$1({
1034
- input: input,
1035
- baseType: 'array',
1036
- validateSync: validateSync,
1037
- collectNestedErrors: function collectNestedErrors() {
1038
- return input.reduce(function (acc, indexInput, index) {
1039
- var indexResult = validateSync(ofType, indexInput);
1040
- return indexResult === true ? acc : __spreadArray(__spreadArray([], acc, true), [_assign(_assign({}, indexResult), {
1041
- path: index + ''
1042
- })], false);
1043
- }, []);
1044
- }
1045
- });
1046
- };
1047
- }
1048
-
1049
- function defaultErrorMessage(_a) {
1050
- var input = _a.input,
1051
- message = _a.message,
1052
- nestedErrors = _a.nestedErrors,
1053
- expectedTypes = _a.expectedTypes;
1054
- if (message) {
1055
- return message;
1056
- }
1057
- if (nestedErrors) {
1058
- return "Invalid input: `".concat(JSON.stringify(input), "`.\n").concat(nestedErrors.map(function (error) {
1059
- return " - ".concat(error.path, ": ").concat(error.message);
1060
- }).join('\n'));
1061
- } else if (expectedTypes) {
1062
- var inputType = typeOf(input);
1063
- return "Invalid input: '".concat(input, "'. Expected type(s) `").concat(expectedTypes, "`, but got type `").concat(inputType === null ? 'unknown' : inputType, "`");
1064
- } else {
1065
- return "Invalid input: '".concat(input, "'.");
1066
- }
1067
- }
1068
-
1069
- function resolveValidationResult(_a) {
1070
- var input = _a.input,
1071
- result = _a.result,
1072
- errorMessage = _a.errorMessage;
1073
- if (result === true) {
1074
- return true;
1075
- } else {
1076
- var _falseLikeResult = function _falseLikeResult() {
1077
- return {
1078
- message: errorMessage({
1079
- input: input
1080
- })
1081
- };
1082
- };
1083
- return _assign({
1084
- input: input
1085
- }, switchExec(typeOf(result), {
1086
- string: function string() {
1087
- return {
1088
- message: result
1089
- };
1090
- },
1091
- error: function error() {
1092
- return {
1093
- message: result.message,
1094
- error: result
1095
- };
1096
- },
1097
- object: function object() {
1098
- var result_ = result;
1099
- return _assign(_assign({}, result_), {
1100
- message: errorMessage(result_)
1101
- });
1102
- },
1103
- //
1104
- // Boolean result here MUST be false, as true was tested earlier
1105
- //
1106
- "boolean": _falseLikeResult,
1107
- "null": _falseLikeResult,
1108
- undefined: _falseLikeResult,
1109
- //
1110
- // Unsupported validation result
1111
- //
1112
- "default": function _default() {
1113
- throw new Error("Invalid validation result: ".concat(result, " (").concat(typeOf(result), ")"));
1114
- }
1115
- }));
1116
- }
1117
- }
1118
-
1119
- function parseValidatorInput(_a, validatorInput) {
1120
- var objValidator = _a.objValidator;
1121
- //
1122
- // Parses the validator fn.
1123
- // If provided with a string, will return a type validator
1124
- // If provided with a function, will return the function itself
1125
- //
1126
- function _parseValidatorFn(fnInput) {
1127
- switch (typeOf(fnInput)) {
1128
- case 'string':
1129
- {
1130
- return typeValidator(fnInput);
1131
- }
1132
- case 'object':
1133
- {
1134
- return objValidator(fnInput);
1135
- }
1136
- case 'function':
1137
- {
1138
- return fnInput;
1139
- }
1140
- default:
1141
- {
1142
- throw new TypeError("Unsupported fnInput ".concat(fnInput));
1143
- }
1144
- }
1145
- }
1146
- function _parseValidatorErrorMessageFn(fnInput) {
1147
- switch (_typeof(fnInput)) {
1148
- case 'string':
1149
- {
1150
- return function (details) {
1151
- return interpolate(fnInput, details);
1152
- };
1153
- }
1154
- case 'function':
1155
- {
1156
- return fnInput;
1157
- }
1158
- default:
1159
- {
1160
- throw new TypeError("Unsupported error message input ".concat(fnInput));
1161
- }
1162
- }
1163
- }
1164
- //
1165
- // Parses the validator input. For more details, see:
1166
- // types/common.ts -> ValidatorSystem
1167
- //
1168
- // Ensures the return result is always of the following format:
1169
- // [ValidatorFn, ValidatorErrorMessageInput]
1170
- //
1171
- var _b = Array.isArray(validatorInput) ? validatorInput : [validatorInput, defaultErrorMessage],
1172
- fnInput = _b[0],
1173
- errorMessageInput = _b[1];
1174
- return [_parseValidatorFn(fnInput), _parseValidatorErrorMessageFn(errorMessageInput)];
1175
- }
1176
-
1177
- function validateSyncFn(validatorInput, input) {
1178
- var result;
1179
- var _a = parseValidatorInput({
1180
- objValidator: obj$1
1181
- }, validatorInput),
1182
- validatorFn = _a[0],
1183
- errorMessage = _a[1];
1184
- try {
1185
- result = validatorFn(input, {
1186
- validateSync: validateSyncFn
1187
- });
1188
- } catch (err) {
1189
- result = err;
1190
- }
1191
- if (result instanceof Promise) {
1192
- throw new Error('Promises not supported in sync validation method');
1193
- }
1194
- return resolveValidationResult({
1195
- errorMessage: errorMessage,
1196
- input: input,
1197
- result: result
1198
- });
1199
- }
1200
-
1201
- var ValidationError = /** @class */function (_super) {
1202
- __extends(ValidationError, _super);
1203
- function ValidationError(_a) {
1204
- var _this = this;
1205
- var message = _a.message,
1206
- details = __rest(_a, ["message"]);
1207
- _this = _super.call(this, message || "Invalid input ".concat(details.input)) || this;
1208
- _this.name = 'ValidationError';
1209
- // Capture correct stack trace in V8 environments (Node.js, Google Chrome)
1210
- if (Error.captureStackTrace) {
1211
- Error.captureStackTrace(_this, ValidationError);
1212
- }
1213
- Object.assign(_this, details);
1214
- return _this;
1215
- }
1216
- ValidationError.prototype.toJSON = function () {
1217
- return {
1218
- message: this.message,
1219
- input: this.input,
1220
- code: this.code,
1221
- error: this.error,
1222
- path: this.path,
1223
- nestedErrors: this.nestedErrors
1224
- };
1225
- };
1226
- return ValidationError;
1227
- }(Error);
1228
-
1229
- function assertValidSync(validator, input) {
1230
- var validationResult = validate(validator, input);
1231
- if (validationResult === true) {
1232
- return input;
1233
- } else {
1234
- throw new ValidationError(validationResult);
1235
- }
1236
- }
1237
- var validate = validateSyncFn;
1238
- validate.type = typeValidator;
1239
- validate.obj = obj$1;
1240
- validate.objOf = objOf$1;
1241
- validate.tuple = tuple$1;
1242
- validate.arrayOf = arrayOf$1;
1243
- validate.and = and$1;
1244
- validate.or = or$1;
1245
- validate.not = not$1;
1246
- validate.assertValid = assertValidSync;
1247
-
1248
- function _shapeGeneralValidator(_a) {
1249
- var input = _a.input,
1250
- baseType = _a.baseType,
1251
- validateAsync = _a.validateAsync,
1252
- collectNestedErrors = _a.collectNestedErrors;
1253
- return __awaiter(this, void 0, void 0, function () {
1254
- var objectValidation, nestedErrors;
1255
- return __generator(this, function (_b) {
1256
- switch (_b.label) {
1257
- case 0:
1258
- return [4 /*yield*/, validateAsync(typeValidator({
1259
- type: baseType,
1260
- required: true
1261
- }), input)];
1262
- case 1:
1263
- objectValidation = _b.sent();
1264
- if (objectValidation !== true) {
1265
- return [2 /*return*/, objectValidation];
1266
- }
1267
- return [4 /*yield*/, collectNestedErrors()];
1268
- case 2:
1269
- nestedErrors = _b.sent();
1270
- return [2 /*return*/, nestedErrors.length === 0 ? true : {
1271
- input: input,
1272
- nestedErrors: nestedErrors
1273
- }];
1274
- }
1275
- });
1276
- });
1277
- }
1278
- function obj(objShape) {
1279
- return function asyncValidateObj(input, _a) {
1280
- var validateAsync = _a.validateAsync;
1281
- return __awaiter(this, void 0, void 0, function () {
1282
- var _this = this;
1283
- return __generator(this, function (_b) {
1284
- return [2 /*return*/, _shapeGeneralValidator({
1285
- input: input,
1286
- baseType: 'object',
1287
- validateAsync: validateAsync,
1288
- collectNestedErrors: function collectNestedErrors() {
1289
- return promiseReduce(Object.entries(objShape), function (acc, _a) {
1290
- var path = _a[0],
1291
- pathValidator = _a[1];
1292
- return __awaiter(_this, void 0, void 0, function () {
1293
- var pathInput, pathResult;
1294
- return __generator(this, function (_b) {
1295
- switch (_b.label) {
1296
- case 0:
1297
- pathInput = getProperty(input, path);
1298
- return [4 /*yield*/, validateAsync(pathValidator, pathInput)];
1299
- case 1:
1300
- pathResult = _b.sent();
1301
- return [2 /*return*/, pathResult === true ? acc : __spreadArray(__spreadArray([], acc, true), [_assign(_assign({}, pathResult), {
1302
- path: path
1303
- })], false)];
1304
- }
1305
- });
1306
- });
1307
- }, []);
1308
- }
1309
- })];
1310
- });
1311
- });
1312
- };
1313
- }
1314
- function objOf(ofType) {
1315
- return function asyncValidateObjOf(input, _a) {
1316
- var validateAsync = _a.validateAsync;
1317
- return __awaiter(this, void 0, void 0, function () {
1318
- var _this = this;
1319
- return __generator(this, function (_b) {
1320
- return [2 /*return*/, _shapeGeneralValidator({
1321
- input: input,
1322
- baseType: 'object',
1323
- validateAsync: validateAsync,
1324
- collectNestedErrors: function collectNestedErrors() {
1325
- return promiseReduce(Object.entries(input), function (acc, _a) {
1326
- var key = _a[0],
1327
- keyInput = _a[1];
1328
- return __awaiter(_this, void 0, void 0, function () {
1329
- var indexResult;
1330
- return __generator(this, function (_b) {
1331
- switch (_b.label) {
1332
- case 0:
1333
- return [4 /*yield*/, validateAsync(ofType, keyInput)];
1334
- case 1:
1335
- indexResult = _b.sent();
1336
- return [2 /*return*/, indexResult === true ? acc : __spreadArray(__spreadArray([], acc, true), [_assign(_assign({}, indexResult), {
1337
- path: key
1338
- })], false)];
1339
- }
1340
- });
1341
- });
1342
- }, []);
1343
- }
1344
- })];
1345
- });
1346
- });
1347
- };
1348
- }
1349
- function tuple(tupleShape) {
1350
- return function asyncValidateTuple(input, _a) {
1351
- var validateAsync = _a.validateAsync;
1352
- return __awaiter(this, void 0, void 0, function () {
1353
- var _this = this;
1354
- return __generator(this, function (_b) {
1355
- return [2 /*return*/, _shapeGeneralValidator({
1356
- input: input,
1357
- baseType: 'array',
1358
- validateAsync: validateAsync,
1359
- collectNestedErrors: function collectNestedErrors() {
1360
- return promiseReduce(tupleShape, function (acc, indexValidator, index) {
1361
- return __awaiter(_this, void 0, void 0, function () {
1362
- var indexInput, indexResult;
1363
- return __generator(this, function (_a) {
1364
- switch (_a.label) {
1365
- case 0:
1366
- indexInput = input[index];
1367
- return [4 /*yield*/, validateAsync(indexValidator, indexInput)];
1368
- case 1:
1369
- indexResult = _a.sent();
1370
- return [2 /*return*/, indexResult === true ? acc : __spreadArray(__spreadArray([], acc, true), [_assign(_assign({}, indexResult), {
1371
- path: index + ''
1372
- })], false)];
1373
- }
1374
- });
1375
- });
1376
- }, []);
1377
- }
1378
- })];
1379
- });
1380
- });
1381
- };
1382
- }
1383
- function arrayOf(ofType) {
1384
- return function asyncValidateArrayOf(input, _a) {
1385
- var validateAsync = _a.validateAsync;
1386
- return __awaiter(this, void 0, void 0, function () {
1387
- var _this = this;
1388
- return __generator(this, function (_b) {
1389
- return [2 /*return*/, _shapeGeneralValidator({
1390
- input: input,
1391
- baseType: 'array',
1392
- validateAsync: validateAsync,
1393
- collectNestedErrors: function collectNestedErrors() {
1394
- return promiseReduce(input, function (acc, indexInput, index) {
1395
- return __awaiter(_this, void 0, void 0, function () {
1396
- var indexResult;
1397
- return __generator(this, function (_a) {
1398
- switch (_a.label) {
1399
- case 0:
1400
- return [4 /*yield*/, validateAsync(ofType, indexInput)];
1401
- case 1:
1402
- indexResult = _a.sent();
1403
- return [2 /*return*/, indexResult === true ? acc : __spreadArray(__spreadArray([], acc, true), [_assign(_assign({}, indexResult), {
1404
- path: index + ''
1405
- })], false)];
1406
- }
1407
- });
1408
- });
1409
- }, []);
1410
- }
1411
- })];
1412
- });
1413
- });
1414
- };
1415
- }
1416
-
1417
- //
1418
- // And operator (serial)
1419
- //
1420
- function and(validators) {
1421
- return function validateAnd(input, _a) {
1422
- var validateAsync = _a.validateAsync;
1423
- return __awaiter(this, void 0, void 0, function () {
1424
- var result;
1425
- return __generator(this, function (_b) {
1426
- switch (_b.label) {
1427
- case 0:
1428
- return [4 /*yield*/, promiseReduce(validators, function (acc, validator) {
1429
- return acc !== true ? acc : validateAsync(validator, input);
1430
- }, true)];
1431
- case 1:
1432
- result = _b.sent();
1433
- if (result === true) {
1434
- return [2 /*return*/, true];
1435
- } else {
1436
- return [2 /*return*/, result];
1437
- }
1438
- }
1439
- });
1440
- });
1441
- };
1442
- }
1443
- //
1444
- // Or operator (serial)
1445
- //
1446
- function or(validators) {
1447
- return function validateOr(input, _a) {
1448
- var validateAsync = _a.validateAsync;
1449
- return __awaiter(this, void 0, void 0, function () {
1450
- var someIsValid;
1451
- var _this = this;
1452
- return __generator(this, function (_b) {
1453
- switch (_b.label) {
1454
- case 0:
1455
- return [4 /*yield*/, promiseReduce(validators, function (acc, validator) {
1456
- return __awaiter(_this, void 0, void 0, function () {
1457
- var _a;
1458
- return __generator(this, function (_b) {
1459
- switch (_b.label) {
1460
- case 0:
1461
- _a = acc === true;
1462
- if (_a) return [3 /*break*/, 2];
1463
- return [4 /*yield*/, validateAsync(validator, input)];
1464
- case 1:
1465
- _a = _b.sent() === true;
1466
- _b.label = 2;
1467
- case 2:
1468
- return [2 /*return*/, _a];
1469
- }
1470
- });
1471
- });
1472
- }, false)];
1473
- case 1:
1474
- someIsValid = _b.sent();
1475
- return [2 /*return*/, someIsValid];
1476
- }
1477
- });
1478
- });
1479
- };
1480
- }
1481
- //
1482
- // Not
1483
- //
1484
- function not(validator) {
1485
- return function validateNot(input, _a) {
1486
- var validateAsync = _a.validateAsync;
1487
- return __awaiter(this, void 0, void 0, function () {
1488
- var result;
1489
- return __generator(this, function (_b) {
1490
- switch (_b.label) {
1491
- case 0:
1492
- return [4 /*yield*/, validateAsync(validator, input)];
1493
- case 1:
1494
- result = _b.sent();
1495
- return [2 /*return*/, result !== true];
1496
- }
1497
- });
1498
- });
1499
- };
1500
- }
1501
-
1502
- function validateAsyncFn(validatorInput, input) {
1503
- return __awaiter(this, void 0, void 0, function () {
1504
- var result, _a, validatorFn, errorMessage, err_1;
1505
- return __generator(this, function (_b) {
1506
- switch (_b.label) {
1507
- case 0:
1508
- _a = parseValidatorInput({
1509
- objValidator: obj
1510
- }, validatorInput), validatorFn = _a[0], errorMessage = _a[1];
1511
- _b.label = 1;
1512
- case 1:
1513
- _b.trys.push([1, 3,, 4]);
1514
- return [4 /*yield*/, validatorFn(input, {
1515
- validateAsync: validateAsyncFn
1516
- })];
1517
- case 2:
1518
- result = _b.sent();
1519
- return [3 /*break*/, 4];
1520
- case 3:
1521
- err_1 = _b.sent();
1522
- result = err_1;
1523
- return [3 /*break*/, 4];
1524
- case 4:
1525
- return [2 /*return*/, resolveValidationResult({
1526
- errorMessage: errorMessage,
1527
- input: input,
1528
- result: result
1529
- })];
1530
- }
1531
- });
1532
- });
1533
- }
1534
-
1535
- function assertValidAsync(validator, input) {
1536
- return __awaiter(this, void 0, void 0, function () {
1537
- var validationResult;
1538
- return __generator(this, function (_a) {
1539
- switch (_a.label) {
1540
- case 0:
1541
- return [4 /*yield*/, validateAsync(validator, input)];
1542
- case 1:
1543
- validationResult = _a.sent();
1544
- if (validationResult === true) {
1545
- return [2 /*return*/, input];
1546
- } else {
1547
- throw new ValidationError(validationResult);
1548
- }
1549
- }
1550
- });
1551
- });
1552
- }
1553
- var validateAsync = validateAsyncFn;
1554
- validateAsync.type = typeValidator;
1555
- validateAsync.obj = obj;
1556
- validateAsync.objOf = objOf;
1557
- validateAsync.tuple = tuple;
1558
- validateAsync.arrayOf = arrayOf;
1559
- validateAsync.and = and;
1560
- validateAsync.or = or;
1561
- validateAsync.not = not;
1562
- validateAsync.assertValid = assertValidAsync;
1563
-
1564
1182
  function defaultParseResponse(response) {
1565
1183
  return response.json();
1566
1184
  }
@@ -1617,7 +1235,7 @@ function fetchAllPages(_a) {
1617
1235
  case 1:
1618
1236
  return [4 /*yield*/, store.getSize()];
1619
1237
  case 2:
1620
- currentOffset = _d.sent() + 1;
1238
+ currentOffset = _d.sent();
1621
1239
  return [4 /*yield*/, fetchPage({
1622
1240
  offset: currentOffset,
1623
1241
  pageSize: pageSize
@@ -1644,13 +1262,68 @@ function fetchAllPages(_a) {
1644
1262
  });
1645
1263
  }
1646
1264
 
1647
- function normalizeString(str) {
1648
- return str.normalize('NFD') // Decompose accented characters
1649
- .replace(/[\u0300-\u036f]/g, '') // Remove diacritical marks
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
1650
1319
  .toLowerCase() // Convert to lowercase
1651
- .replace(/\s+/g, '-') // Replace multiple spaces with a single space
1652
- .trim(); // Trim leading and trailing spaces
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
1653
1325
  }
1326
+ var normalizeString = deprecateFn(slugify, 'normalizeString is depreacted, use @orioro/util -> slugify instead');
1654
1327
 
1655
1328
  //
1656
1329
  // Hook module
@@ -1726,4 +1399,73 @@ function hookFn(fn, _a) {
1726
1399
  };
1727
1400
  }
1728
1401
 
1729
- export { PromiseLikeEventEmitter, SKIPPED, TimeoutError, ValidationError, batchFn, debugFn, deepFreeze, fetchAllPages, hookFn, inMemoryDataStore, interpolate, makeDeferred, makeTypeOf, maybeFn, normalizeString, paginatedHttpFetch, parseBatchedResults, pickPaths, promiseReduce, resolveNestedPromises, switchExec, switchValue, typeMap, typeOf, validate, validateAsync, wait, withTimeout };
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
+ }
1469
+ }
1470
+
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 };