@dereekb/util 13.0.5 → 13.0.7

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.
@@ -278,7 +278,7 @@ function _array_like_to_array$2(arr, len) {
278
278
  function _array_with_holes$2(arr) {
279
279
  if (Array.isArray(arr)) return arr;
280
280
  }
281
- function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
281
+ function asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, key, arg) {
282
282
  try {
283
283
  var info = gen[key](arg);
284
284
  var value = info.value;
@@ -292,16 +292,16 @@ function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
292
292
  Promise.resolve(value).then(_next, _throw);
293
293
  }
294
294
  }
295
- function _async_to_generator$3(fn) {
295
+ function _async_to_generator$4(fn) {
296
296
  return function() {
297
297
  var self = this, args = arguments;
298
298
  return new Promise(function(resolve, reject) {
299
299
  var gen = fn.apply(self, args);
300
300
  function _next(value) {
301
- asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
301
+ asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "next", value);
302
302
  }
303
303
  function _throw(err) {
304
- asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
304
+ asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "throw", err);
305
305
  }
306
306
  _next(undefined);
307
307
  });
@@ -403,7 +403,7 @@ function _unsupported_iterable_to_array$2(o, minLen) {
403
403
  if (n === "Map" || n === "Set") return Array.from(n);
404
404
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$2(o, minLen);
405
405
  }
406
- function _ts_generator$3(thisArg, body) {
406
+ function _ts_generator$4(thisArg, body) {
407
407
  var f, y, t, _ = {
408
408
  label: 0,
409
409
  sent: function() {
@@ -554,9 +554,9 @@ function _ts_generator$3(thisArg, body) {
554
554
  }
555
555
  var makeFetchRequest = fetchRequestFactory(config);
556
556
  return function(input, init) {
557
- return _async_to_generator$3(function() {
557
+ return _async_to_generator$4(function() {
558
558
  var request, response;
559
- return _ts_generator$3(this, function(_state) {
559
+ return _ts_generator$4(this, function(_state) {
560
560
  switch(_state.label){
561
561
  case 0:
562
562
  return [
@@ -603,9 +603,9 @@ function fetchRequestFactory(config) {
603
603
  return result;
604
604
  } : undefined;
605
605
  function asFetchRequest(input) {
606
- return _async_to_generator$3(function() {
606
+ return _async_to_generator$4(function() {
607
607
  var awaitedInput, _tmp;
608
- return _ts_generator$3(this, function(_state) {
608
+ return _ts_generator$4(this, function(_state) {
609
609
  switch(_state.label){
610
610
  case 0:
611
611
  if (!util.isPromiseLike(input)) return [
@@ -643,9 +643,9 @@ function fetchRequestFactory(config) {
643
643
  })();
644
644
  }
645
645
  var buildRequestWithFixedUrl = buildUrl ? function(input) {
646
- return _async_to_generator$3(function() {
646
+ return _async_to_generator$4(function() {
647
647
  var relativeUrl, baseRequest, request, url;
648
- return _ts_generator$3(this, function(_state) {
648
+ return _ts_generator$4(this, function(_state) {
649
649
  switch(_state.label){
650
650
  case 0:
651
651
  if (!(typeof input === 'string')) return [
@@ -705,9 +705,9 @@ function fetchRequestFactory(config) {
705
705
  var buildRequestInit;
706
706
  if (inputBaseRequest != null || timeout != null) {
707
707
  var computeBaseRequest = function computeBaseRequest() {
708
- return _async_to_generator$3(function() {
708
+ return _async_to_generator$4(function() {
709
709
  var computedBaseRequest, baseRequest;
710
- return _ts_generator$3(this, function(_state) {
710
+ return _ts_generator$4(this, function(_state) {
711
711
  switch(_state.label){
712
712
  case 0:
713
713
  return [
@@ -728,9 +728,9 @@ function fetchRequestFactory(config) {
728
728
  })();
729
729
  };
730
730
  var combineRequestInits = function combineRequestInits(request, requestInit) {
731
- return _async_to_generator$3(function() {
731
+ return _async_to_generator$4(function() {
732
732
  var baseRequest, merged, _tmp, timeout;
733
- return _ts_generator$3(this, function(_state) {
733
+ return _ts_generator$4(this, function(_state) {
734
734
  switch(_state.label){
735
735
  case 0:
736
736
  return [
@@ -779,9 +779,9 @@ function fetchRequestFactory(config) {
779
779
  };
780
780
  }
781
781
  return function(input, init) {
782
- return _async_to_generator$3(function() {
782
+ return _async_to_generator$4(function() {
783
783
  var fixedRequest, request, e;
784
- return _ts_generator$3(this, function(_state) {
784
+ return _ts_generator$4(this, function(_state) {
785
785
  switch(_state.label){
786
786
  case 0:
787
787
  _state.trys.push([
@@ -883,17 +883,200 @@ function isFetchRequest(input) {
883
883
  return Boolean(input.url);
884
884
  }
885
885
 
886
- function fetchUploadFile(input) {
887
- var _input_method;
888
- var inputFetch = input.fetch, url = input.url, inputBody = input.body;
889
- var useFetch = inputFetch !== null && inputFetch !== void 0 ? inputFetch : fetch;
890
- return useFetch(url, {
891
- method: (_input_method = input.method) !== null && _input_method !== void 0 ? _input_method : 'POST',
892
- body: inputBody.body,
893
- headers: {
894
- 'Content-Type': inputBody.mimeType
886
+ function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
887
+ try {
888
+ var info = gen[key](arg);
889
+ var value = info.value;
890
+ } catch (error) {
891
+ reject(error);
892
+ return;
893
+ }
894
+ if (info.done) {
895
+ resolve(value);
896
+ } else {
897
+ Promise.resolve(value).then(_next, _throw);
898
+ }
899
+ }
900
+ function _async_to_generator$3(fn) {
901
+ return function() {
902
+ var self = this, args = arguments;
903
+ return new Promise(function(resolve, reject) {
904
+ var gen = fn.apply(self, args);
905
+ function _next(value) {
906
+ asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
907
+ }
908
+ function _throw(err) {
909
+ asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
910
+ }
911
+ _next(undefined);
912
+ });
913
+ };
914
+ }
915
+ function _ts_generator$3(thisArg, body) {
916
+ var f, y, t, _ = {
917
+ label: 0,
918
+ sent: function() {
919
+ if (t[0] & 1) throw t[1];
920
+ return t[1];
921
+ },
922
+ trys: [],
923
+ ops: []
924
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
925
+ return d(g, "next", {
926
+ value: verb(0)
927
+ }), d(g, "throw", {
928
+ value: verb(1)
929
+ }), d(g, "return", {
930
+ value: verb(2)
931
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
932
+ value: function() {
933
+ return this;
895
934
  }
896
- });
935
+ }), g;
936
+ function verb(n) {
937
+ return function(v) {
938
+ return step([
939
+ n,
940
+ v
941
+ ]);
942
+ };
943
+ }
944
+ function step(op) {
945
+ if (f) throw new TypeError("Generator is already executing.");
946
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
947
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
948
+ if (y = 0, t) op = [
949
+ op[0] & 2,
950
+ t.value
951
+ ];
952
+ switch(op[0]){
953
+ case 0:
954
+ case 1:
955
+ t = op;
956
+ break;
957
+ case 4:
958
+ _.label++;
959
+ return {
960
+ value: op[1],
961
+ done: false
962
+ };
963
+ case 5:
964
+ _.label++;
965
+ y = op[1];
966
+ op = [
967
+ 0
968
+ ];
969
+ continue;
970
+ case 7:
971
+ op = _.ops.pop();
972
+ _.trys.pop();
973
+ continue;
974
+ default:
975
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
976
+ _ = 0;
977
+ continue;
978
+ }
979
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
980
+ _.label = op[1];
981
+ break;
982
+ }
983
+ if (op[0] === 6 && _.label < t[1]) {
984
+ _.label = t[1];
985
+ t = op;
986
+ break;
987
+ }
988
+ if (t && _.label < t[2]) {
989
+ _.label = t[2];
990
+ _.ops.push(op);
991
+ break;
992
+ }
993
+ if (t[2]) _.ops.pop();
994
+ _.trys.pop();
995
+ continue;
996
+ }
997
+ op = body.call(thisArg, _);
998
+ } catch (e) {
999
+ op = [
1000
+ 6,
1001
+ e
1002
+ ];
1003
+ y = 0;
1004
+ } finally{
1005
+ f = t = 0;
1006
+ }
1007
+ if (op[0] & 5) throw op[1];
1008
+ return {
1009
+ value: op[0] ? op[1] : void 0,
1010
+ done: true
1011
+ };
1012
+ }
1013
+ }
1014
+ /**
1015
+ * Creates a File object from the given input.
1016
+ *
1017
+ * @example
1018
+ * makeFileForFetch({ content: pdfBuffer, fileName: 'doc.pdf', mimeType: 'application/pdf' })
1019
+ */ function makeFileForFetch(input) {
1020
+ var options = {};
1021
+ if (input.mimeType) {
1022
+ options.type = input.mimeType;
1023
+ }
1024
+ if (input.lastModified != null) {
1025
+ options.lastModified = input.lastModified;
1026
+ }
1027
+ return new File(util.asArray(input.content), input.fileName, options);
1028
+ }
1029
+ function fetchFileFromUrl(input, safe) {
1030
+ return _async_to_generator$3(function() {
1031
+ var url, mimeType, inputFetch, useFetch, response, result, _ref, _ref1, _input_fileName, buffer, responseMimeType, fileName, options;
1032
+ return _ts_generator$3(this, function(_state) {
1033
+ switch(_state.label){
1034
+ case 0:
1035
+ url = input.url, mimeType = input.mimeType, inputFetch = input.fetch;
1036
+ useFetch = inputFetch !== null && inputFetch !== void 0 ? inputFetch : fetch;
1037
+ return [
1038
+ 4,
1039
+ useFetch(url, {
1040
+ method: 'GET'
1041
+ })
1042
+ ];
1043
+ case 1:
1044
+ response = _state.sent();
1045
+ if (!!response.ok) return [
1046
+ 3,
1047
+ 2
1048
+ ];
1049
+ if (!safe) {
1050
+ throw new Error("Failed to fetch file from ".concat(url, ": ").concat(response.status, " ").concat(response.statusText));
1051
+ }
1052
+ return [
1053
+ 3,
1054
+ 4
1055
+ ];
1056
+ case 2:
1057
+ return [
1058
+ 4,
1059
+ response.arrayBuffer()
1060
+ ];
1061
+ case 3:
1062
+ buffer = _state.sent();
1063
+ responseMimeType = (_ref = mimeType !== null && mimeType !== void 0 ? mimeType : response.headers.get('content-type')) !== null && _ref !== void 0 ? _ref : undefined;
1064
+ fileName = (_ref1 = (_input_fileName = input.fileName) !== null && _input_fileName !== void 0 ? _input_fileName : util.urlWithoutParameters(url).split('/').pop()) !== null && _ref1 !== void 0 ? _ref1 : 'file';
1065
+ options = responseMimeType ? {
1066
+ type: responseMimeType
1067
+ } : {};
1068
+ result = new File([
1069
+ buffer
1070
+ ], fileName, options);
1071
+ _state.label = 4;
1072
+ case 4:
1073
+ return [
1074
+ 2,
1075
+ result
1076
+ ];
1077
+ }
1078
+ });
1079
+ })();
897
1080
  }
898
1081
  /**
899
1082
  * Parses the file response and returns the response wrapped in a FetchFileResponse object.
@@ -911,6 +1094,20 @@ function fetchUploadFile(input) {
911
1094
  mimeType: contentType === null || contentType === void 0 ? void 0 : contentType.type
912
1095
  };
913
1096
  }
1097
+ /**
1098
+ * @deprecated Use makeFileForFetch() with FormData and context.fetch() instead.
1099
+ */ function fetchUploadFile(input) {
1100
+ var _input_method;
1101
+ var inputFetch = input.fetch, url = input.url, inputBody = input.body;
1102
+ var useFetch = inputFetch !== null && inputFetch !== void 0 ? inputFetch : fetch;
1103
+ return useFetch(url, {
1104
+ method: (_input_method = input.method) !== null && _input_method !== void 0 ? _input_method : 'POST',
1105
+ body: inputBody.body,
1106
+ headers: {
1107
+ 'Content-Type': inputBody.mimeType
1108
+ }
1109
+ });
1110
+ }
914
1111
 
915
1112
  function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
916
1113
  try {
@@ -1724,10 +1921,30 @@ function _ts_generator(thisArg, body) {
1724
1921
  }
1725
1922
  }
1726
1923
  /**
1727
- * Iterates through the pages of a created FetchPage instance by each item individually.
1924
+ * Iterates through all pages of a paginated fetch and processes each item individually.
1728
1925
  *
1729
- * @param config
1730
- * @returns
1926
+ * Built on top of {@link iterateFetchPagesByItems}, this function handles per-item granularity
1927
+ * by extracting items from each page and delegating to {@link performAsyncTasks}. Items are
1928
+ * processed sequentially by default to preserve ordering guarantees, but can be parallelized
1929
+ * via `iteratePerformTasksConfig`.
1930
+ *
1931
+ * Each item's callback receives a global index that reflects its position across all pages,
1932
+ * not just within the current page.
1933
+ *
1934
+ * @param config - Configuration specifying the fetch page source, item extraction, and per-item callback
1935
+ * @returns Combined result from {@link iterateFetchPagesByItems} including page/item counts and per-item task results
1936
+ *
1937
+ * @example
1938
+ * ```typescript
1939
+ * const result = await iterateFetchPagesByEachItem({
1940
+ * fetchPageFactory: myPageFactory,
1941
+ * input: { query: 'active' },
1942
+ * readItemsFromPageResult: (r) => r.result.items,
1943
+ * iterateEachPageItem: async (item, index, pageResult) => {
1944
+ * return processItem(item);
1945
+ * }
1946
+ * });
1947
+ * ```
1731
1948
  */ function iterateFetchPagesByEachItem(config) {
1732
1949
  return _async_to_generator(function() {
1733
1950
  var iterateEachPageItem, iteratePerformTasksConfig;
@@ -1773,10 +1990,32 @@ function _ts_generator(thisArg, body) {
1773
1990
  })();
1774
1991
  }
1775
1992
  /**
1776
- * Iterates through the pages of a created FetchPage instance.
1993
+ * Iterates through paginated fetch results at the item batch level.
1777
1994
  *
1778
- * @param config
1779
- * @returns
1995
+ * Fetches pages sequentially (or in parallel via `maxParallelPages`), extracts items
1996
+ * from each page using `readItemsFromPageResult`, optionally filters them, then
1997
+ * passes the batch to `iteratePageItems`. Tracks both raw loaded counts and
1998
+ * post-filter visited counts, terminating when either limit is reached or pages
1999
+ * are exhausted.
2000
+ *
2001
+ * For per-item processing instead of batch processing, use {@link iterateFetchPagesByEachItem}.
2002
+ *
2003
+ * @param config - Configuration specifying fetch source, item extraction, filtering, limits, and batch callback
2004
+ * @returns Result with page count and item counters (loaded and visited)
2005
+ *
2006
+ * @example
2007
+ * ```typescript
2008
+ * const result = await iterateFetchPagesByItems({
2009
+ * fetchPageFactory: myPageFactory,
2010
+ * input: { status: 'active' },
2011
+ * readItemsFromPageResult: (r) => r.result.records,
2012
+ * filterPageItems: (items) => items.filter(x => x.isValid),
2013
+ * iterateItemsLimit: 500,
2014
+ * iteratePageItems: async (items, pageResult, totalVisited) => {
2015
+ * await bulkInsert(items);
2016
+ * }
2017
+ * });
2018
+ * ```
1780
2019
  */ function iterateFetchPagesByItems(config) {
1781
2020
  return _async_to_generator(function() {
1782
2021
  var readItemsFromPageResult, inputTotalIterateItemsLimit, inputTotalLoadItemLimit, inputFilterPageItems, iteratePageItems, iterateItemsLimit, loadItemLimit, filterPageItems, totalItemsLoaded, totalItemsVisited, hasReachedFinalItem, fetchPagesConfig, iterateFetchPagesResult;
@@ -2390,6 +2629,7 @@ exports.FetchTimeoutError = FetchTimeoutError;
2390
2629
  exports.JsonResponseParseError = JsonResponseParseError;
2391
2630
  exports.configureFetch = configureFetch;
2392
2631
  exports.fetchApiFetchService = fetchApiFetchService;
2632
+ exports.fetchFileFromUrl = fetchFileFromUrl;
2393
2633
  exports.fetchJsonBodyString = fetchJsonBodyString;
2394
2634
  exports.fetchJsonFunction = fetchJsonFunction;
2395
2635
  exports.fetchJsonRequestInit = fetchJsonRequestInit;
@@ -2410,6 +2650,7 @@ exports.isURLSearchParams = isURLSearchParams;
2410
2650
  exports.iterateFetchPages = iterateFetchPages;
2411
2651
  exports.iterateFetchPagesByEachItem = iterateFetchPagesByEachItem;
2412
2652
  exports.iterateFetchPagesByItems = iterateFetchPagesByItems;
2653
+ exports.makeFileForFetch = makeFileForFetch;
2413
2654
  exports.makeUrlSearchParams = makeUrlSearchParams;
2414
2655
  exports.mergeMakeUrlSearchParamsOptions = mergeMakeUrlSearchParamsOptions;
2415
2656
  exports.mergeRequestHeaders = mergeRequestHeaders;