@dereekb/util 13.0.6 → 13.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/fetch/index.cjs.js +274 -33
  2. package/fetch/index.esm.js +274 -35
  3. package/fetch/package.json +2 -2
  4. package/fetch/src/lib/fetch.file.d.ts +67 -20
  5. package/fetch/src/lib/fetch.page.iterate.d.ts +277 -49
  6. package/index.cjs.js +4107 -1516
  7. package/index.esm.js +4107 -1516
  8. package/package.json +1 -2
  9. package/src/lib/array/array.d.ts +92 -47
  10. package/src/lib/array/array.find.d.ts +14 -18
  11. package/src/lib/array/array.index.d.ts +43 -14
  12. package/src/lib/array/array.indexed.d.ts +66 -17
  13. package/src/lib/array/array.limit.d.ts +11 -0
  14. package/src/lib/array/array.make.d.ts +9 -3
  15. package/src/lib/array/array.map.d.ts +20 -8
  16. package/src/lib/array/array.number.d.ts +63 -5
  17. package/src/lib/array/array.random.d.ts +12 -9
  18. package/src/lib/array/array.set.d.ts +24 -1
  19. package/src/lib/array/array.string.d.ts +104 -0
  20. package/src/lib/array/array.unique.d.ts +60 -8
  21. package/src/lib/array/array.value.d.ts +20 -11
  22. package/src/lib/assertion/assertion.d.ts +30 -2
  23. package/src/lib/assertion/assertion.generic.d.ts +8 -0
  24. package/src/lib/assertion/assertion.number.d.ts +16 -0
  25. package/src/lib/auth/auth.role.claims.d.ts +14 -8
  26. package/src/lib/boolean.d.ts +54 -1
  27. package/src/lib/contact/domain.d.ts +22 -4
  28. package/src/lib/contact/random.d.ts +24 -0
  29. package/src/lib/date/date.d.ts +8 -13
  30. package/src/lib/date/hour.d.ts +51 -32
  31. package/src/lib/date/minute.d.ts +4 -4
  32. package/src/lib/date/time.d.ts +12 -3
  33. package/src/lib/date/week.d.ts +77 -10
  34. package/src/lib/error/error.d.ts +54 -3
  35. package/src/lib/error/error.server.d.ts +25 -2
  36. package/src/lib/file/pdf.d.ts +15 -0
  37. package/src/lib/filter/filter.d.ts +12 -7
  38. package/src/lib/function/function.boolean.d.ts +4 -4
  39. package/src/lib/function/function.d.ts +2 -5
  40. package/src/lib/function/function.forward.d.ts +19 -3
  41. package/src/lib/getter/getter.cache.d.ts +9 -5
  42. package/src/lib/getter/getter.d.ts +39 -22
  43. package/src/lib/getter/getter.map.d.ts +10 -4
  44. package/src/lib/getter/getter.util.d.ts +3 -3
  45. package/src/lib/grouping.d.ts +98 -31
  46. package/src/lib/hash.d.ts +15 -8
  47. package/src/lib/iterable/iterable.d.ts +62 -50
  48. package/src/lib/iterable/iterable.map.d.ts +4 -4
  49. package/src/lib/iterate.d.ts +17 -1
  50. package/src/lib/key.d.ts +32 -10
  51. package/src/lib/lifecycle.d.ts +10 -1
  52. package/src/lib/map/map.d.ts +17 -16
  53. package/src/lib/map/map.intersection.d.ts +5 -4
  54. package/src/lib/map/map.key.d.ts +16 -15
  55. package/src/lib/misc/host.d.ts +6 -3
  56. package/src/lib/model/id.batch.d.ts +7 -3
  57. package/src/lib/model/id.factory.d.ts +16 -1
  58. package/src/lib/model/model.conversion.d.ts +49 -6
  59. package/src/lib/model/model.conversion.field.d.ts +13 -3
  60. package/src/lib/model/model.copy.d.ts +11 -0
  61. package/src/lib/model/model.d.ts +174 -1
  62. package/src/lib/model/model.modify.d.ts +24 -5
  63. package/src/lib/nodejs/stream.d.ts +8 -6
  64. package/src/lib/number/bitwise.dencoder.d.ts +43 -3
  65. package/src/lib/number/bound.d.ts +34 -5
  66. package/src/lib/number/dollar.d.ts +13 -6
  67. package/src/lib/number/factory.d.ts +11 -3
  68. package/src/lib/number/number.d.ts +55 -32
  69. package/src/lib/number/random.d.ts +13 -3
  70. package/src/lib/number/round.d.ts +47 -26
  71. package/src/lib/number/sort.d.ts +7 -1
  72. package/src/lib/number/transform.d.ts +16 -0
  73. package/src/lib/object/object.array.d.ts +16 -2
  74. package/src/lib/object/object.array.delta.d.ts +6 -2
  75. package/src/lib/object/object.d.ts +33 -5
  76. package/src/lib/object/object.empty.d.ts +4 -2
  77. package/src/lib/object/object.equal.d.ts +21 -4
  78. package/src/lib/object/object.filter.tuple.d.ts +105 -3
  79. package/src/lib/object/object.key.d.ts +13 -6
  80. package/src/lib/object/object.map.d.ts +30 -19
  81. package/src/lib/page/page.d.ts +21 -0
  82. package/src/lib/page/page.filter.d.ts +16 -9
  83. package/src/lib/path/path.d.ts +101 -14
  84. package/src/lib/path/path.tree.d.ts +16 -0
  85. package/src/lib/promise/callback.d.ts +18 -0
  86. package/src/lib/promise/is.d.ts +10 -3
  87. package/src/lib/promise/map.d.ts +5 -3
  88. package/src/lib/promise/poll.d.ts +14 -4
  89. package/src/lib/promise/promise.d.ts +84 -18
  90. package/src/lib/promise/promise.factory.d.ts +18 -2
  91. package/src/lib/promise/promise.limit.d.ts +22 -2
  92. package/src/lib/promise/promise.loop.d.ts +69 -1
  93. package/src/lib/promise/promise.ref.d.ts +14 -2
  94. package/src/lib/promise/promise.task.d.ts +8 -4
  95. package/src/lib/promise/promise.type.d.ts +4 -4
  96. package/src/lib/promise/use.d.ts +6 -4
  97. package/src/lib/promise/wait.d.ts +5 -2
  98. package/src/lib/relation/relation.d.ts +98 -0
  99. package/src/lib/service/handler.config.d.ts +47 -9
  100. package/src/lib/service/handler.d.ts +43 -1
  101. package/src/lib/service/typed.service.d.ts +21 -2
  102. package/src/lib/set/set.allowed.d.ts +6 -4
  103. package/src/lib/set/set.d.ts +174 -46
  104. package/src/lib/set/set.decision.d.ts +4 -2
  105. package/src/lib/set/set.delta.d.ts +16 -3
  106. package/src/lib/set/set.hashset.d.ts +43 -0
  107. package/src/lib/set/set.selection.d.ts +7 -3
  108. package/src/lib/sort.d.ts +36 -16
  109. package/src/lib/string/char.d.ts +48 -34
  110. package/src/lib/string/dencoder.d.ts +84 -13
  111. package/src/lib/string/factory.d.ts +13 -4
  112. package/src/lib/string/html.d.ts +7 -6
  113. package/src/lib/string/mimetype.d.ts +65 -1
  114. package/src/lib/string/prefix.d.ts +21 -7
  115. package/src/lib/string/record.d.ts +7 -4
  116. package/src/lib/string/replace.d.ts +77 -33
  117. package/src/lib/string/search.d.ts +19 -9
  118. package/src/lib/string/sort.d.ts +10 -1
  119. package/src/lib/string/string.d.ts +74 -21
  120. package/src/lib/string/transform.d.ts +7 -0
  121. package/src/lib/string/tree.d.ts +91 -29
  122. package/src/lib/string/url.d.ts +148 -63
  123. package/src/lib/tree/tree.explore.d.ts +84 -17
  124. package/src/lib/tree/tree.flatten.d.ts +44 -7
  125. package/src/lib/type.d.ts +15 -12
  126. package/src/lib/value/address.d.ts +66 -17
  127. package/src/lib/value/bound.d.ts +253 -17
  128. package/src/lib/value/build.d.ts +30 -5
  129. package/src/lib/value/comparator.d.ts +53 -25
  130. package/src/lib/value/cron.d.ts +14 -6
  131. package/src/lib/value/decision.d.ts +57 -13
  132. package/src/lib/value/equal.d.ts +44 -13
  133. package/src/lib/value/indexed.d.ts +253 -82
  134. package/src/lib/value/label.d.ts +16 -5
  135. package/src/lib/value/map.d.ts +77 -20
  136. package/src/lib/value/maybe.d.ts +47 -49
  137. package/src/lib/value/modifier.d.ts +82 -27
  138. package/src/lib/value/point.d.ts +248 -54
  139. package/src/lib/value/url.d.ts +10 -3
  140. package/src/lib/value/use.d.ts +99 -8
  141. package/src/lib/value/vector.d.ts +71 -9
  142. package/test/index.cjs.js +86 -23
  143. package/test/index.esm.js +86 -23
  144. package/test/package.json +2 -2
  145. package/test/src/lib/shared/shared.d.ts +31 -5
  146. package/test/src/lib/shared/shared.fail.d.ts +72 -9
  147. package/test/src/lib/shared/shared.function.d.ts +40 -2
  148. package/test/src/lib/shared/shared.wrap.d.ts +20 -1
@@ -1,5 +1,5 @@
1
1
  import { BaseError } from 'make-error';
2
- import { removeTrailingSlashes, asGetter, multiValueMapBuilder, filterMaybeArrayValues, isWebsiteUrlWithPrefix, fixMultiSlashesInSlashPath, isPromiseLike, cachedGetter, FIRST_PAGE, mapIdentityFunction, performTasksFromFactoryInParallelFunction, performAsyncTasks, mergeObjects, filterEmptyPojoValues, useIterableOrValue, isEmptyIterable, fixExtraQueryParameters, forEachInIterable, forEachKeyValue, isIterable } from '@dereekb/util';
2
+ import { removeTrailingSlashes, asGetter, multiValueMapBuilder, filterMaybeArrayValues, isWebsiteUrlWithPrefix, fixMultiSlashesInSlashPath, isPromiseLike, asArray, urlWithoutParameters, cachedGetter, FIRST_PAGE, mapIdentityFunction, performTasksFromFactoryInParallelFunction, performAsyncTasks, mergeObjects, filterEmptyPojoValues, useIterableOrValue, isEmptyIterable, fixExtraQueryParameters, forEachInIterable, forEachKeyValue, isIterable } from '@dereekb/util';
3
3
  import { safeParse } from 'fast-content-type-parse';
4
4
 
5
5
  function _assert_this_initialized$3(self) {
@@ -276,7 +276,7 @@ function _array_like_to_array$2(arr, len) {
276
276
  function _array_with_holes$2(arr) {
277
277
  if (Array.isArray(arr)) return arr;
278
278
  }
279
- function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
279
+ function asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, key, arg) {
280
280
  try {
281
281
  var info = gen[key](arg);
282
282
  var value = info.value;
@@ -290,16 +290,16 @@ function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
290
290
  Promise.resolve(value).then(_next, _throw);
291
291
  }
292
292
  }
293
- function _async_to_generator$3(fn) {
293
+ function _async_to_generator$4(fn) {
294
294
  return function() {
295
295
  var self = this, args = arguments;
296
296
  return new Promise(function(resolve, reject) {
297
297
  var gen = fn.apply(self, args);
298
298
  function _next(value) {
299
- asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
299
+ asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "next", value);
300
300
  }
301
301
  function _throw(err) {
302
- asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
302
+ asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "throw", err);
303
303
  }
304
304
  _next(undefined);
305
305
  });
@@ -401,7 +401,7 @@ function _unsupported_iterable_to_array$2(o, minLen) {
401
401
  if (n === "Map" || n === "Set") return Array.from(n);
402
402
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$2(o, minLen);
403
403
  }
404
- function _ts_generator$3(thisArg, body) {
404
+ function _ts_generator$4(thisArg, body) {
405
405
  var f, y, t, _ = {
406
406
  label: 0,
407
407
  sent: function() {
@@ -552,9 +552,9 @@ function _ts_generator$3(thisArg, body) {
552
552
  }
553
553
  var makeFetchRequest = fetchRequestFactory(config);
554
554
  return function(input, init) {
555
- return _async_to_generator$3(function() {
555
+ return _async_to_generator$4(function() {
556
556
  var request, response;
557
- return _ts_generator$3(this, function(_state) {
557
+ return _ts_generator$4(this, function(_state) {
558
558
  switch(_state.label){
559
559
  case 0:
560
560
  return [
@@ -601,9 +601,9 @@ function fetchRequestFactory(config) {
601
601
  return result;
602
602
  } : undefined;
603
603
  function asFetchRequest(input) {
604
- return _async_to_generator$3(function() {
604
+ return _async_to_generator$4(function() {
605
605
  var awaitedInput, _tmp;
606
- return _ts_generator$3(this, function(_state) {
606
+ return _ts_generator$4(this, function(_state) {
607
607
  switch(_state.label){
608
608
  case 0:
609
609
  if (!isPromiseLike(input)) return [
@@ -641,9 +641,9 @@ function fetchRequestFactory(config) {
641
641
  })();
642
642
  }
643
643
  var buildRequestWithFixedUrl = buildUrl ? function(input) {
644
- return _async_to_generator$3(function() {
644
+ return _async_to_generator$4(function() {
645
645
  var relativeUrl, baseRequest, request, url;
646
- return _ts_generator$3(this, function(_state) {
646
+ return _ts_generator$4(this, function(_state) {
647
647
  switch(_state.label){
648
648
  case 0:
649
649
  if (!(typeof input === 'string')) return [
@@ -703,9 +703,9 @@ function fetchRequestFactory(config) {
703
703
  var buildRequestInit;
704
704
  if (inputBaseRequest != null || timeout != null) {
705
705
  var computeBaseRequest = function computeBaseRequest() {
706
- return _async_to_generator$3(function() {
706
+ return _async_to_generator$4(function() {
707
707
  var computedBaseRequest, baseRequest;
708
- return _ts_generator$3(this, function(_state) {
708
+ return _ts_generator$4(this, function(_state) {
709
709
  switch(_state.label){
710
710
  case 0:
711
711
  return [
@@ -726,9 +726,9 @@ function fetchRequestFactory(config) {
726
726
  })();
727
727
  };
728
728
  var combineRequestInits = function combineRequestInits(request, requestInit) {
729
- return _async_to_generator$3(function() {
729
+ return _async_to_generator$4(function() {
730
730
  var baseRequest, merged, _tmp, timeout;
731
- return _ts_generator$3(this, function(_state) {
731
+ return _ts_generator$4(this, function(_state) {
732
732
  switch(_state.label){
733
733
  case 0:
734
734
  return [
@@ -777,9 +777,9 @@ function fetchRequestFactory(config) {
777
777
  };
778
778
  }
779
779
  return function(input, init) {
780
- return _async_to_generator$3(function() {
780
+ return _async_to_generator$4(function() {
781
781
  var fixedRequest, request, e;
782
- return _ts_generator$3(this, function(_state) {
782
+ return _ts_generator$4(this, function(_state) {
783
783
  switch(_state.label){
784
784
  case 0:
785
785
  _state.trys.push([
@@ -881,17 +881,200 @@ function isFetchRequest(input) {
881
881
  return Boolean(input.url);
882
882
  }
883
883
 
884
- function fetchUploadFile(input) {
885
- var _input_method;
886
- var inputFetch = input.fetch, url = input.url, inputBody = input.body;
887
- var useFetch = inputFetch !== null && inputFetch !== void 0 ? inputFetch : fetch;
888
- return useFetch(url, {
889
- method: (_input_method = input.method) !== null && _input_method !== void 0 ? _input_method : 'POST',
890
- body: inputBody.body,
891
- headers: {
892
- 'Content-Type': inputBody.mimeType
884
+ function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
885
+ try {
886
+ var info = gen[key](arg);
887
+ var value = info.value;
888
+ } catch (error) {
889
+ reject(error);
890
+ return;
891
+ }
892
+ if (info.done) {
893
+ resolve(value);
894
+ } else {
895
+ Promise.resolve(value).then(_next, _throw);
896
+ }
897
+ }
898
+ function _async_to_generator$3(fn) {
899
+ return function() {
900
+ var self = this, args = arguments;
901
+ return new Promise(function(resolve, reject) {
902
+ var gen = fn.apply(self, args);
903
+ function _next(value) {
904
+ asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
905
+ }
906
+ function _throw(err) {
907
+ asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
908
+ }
909
+ _next(undefined);
910
+ });
911
+ };
912
+ }
913
+ function _ts_generator$3(thisArg, body) {
914
+ var f, y, t, _ = {
915
+ label: 0,
916
+ sent: function() {
917
+ if (t[0] & 1) throw t[1];
918
+ return t[1];
919
+ },
920
+ trys: [],
921
+ ops: []
922
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
923
+ return d(g, "next", {
924
+ value: verb(0)
925
+ }), d(g, "throw", {
926
+ value: verb(1)
927
+ }), d(g, "return", {
928
+ value: verb(2)
929
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
930
+ value: function() {
931
+ return this;
893
932
  }
894
- });
933
+ }), g;
934
+ function verb(n) {
935
+ return function(v) {
936
+ return step([
937
+ n,
938
+ v
939
+ ]);
940
+ };
941
+ }
942
+ function step(op) {
943
+ if (f) throw new TypeError("Generator is already executing.");
944
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
945
+ 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;
946
+ if (y = 0, t) op = [
947
+ op[0] & 2,
948
+ t.value
949
+ ];
950
+ switch(op[0]){
951
+ case 0:
952
+ case 1:
953
+ t = op;
954
+ break;
955
+ case 4:
956
+ _.label++;
957
+ return {
958
+ value: op[1],
959
+ done: false
960
+ };
961
+ case 5:
962
+ _.label++;
963
+ y = op[1];
964
+ op = [
965
+ 0
966
+ ];
967
+ continue;
968
+ case 7:
969
+ op = _.ops.pop();
970
+ _.trys.pop();
971
+ continue;
972
+ default:
973
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
974
+ _ = 0;
975
+ continue;
976
+ }
977
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
978
+ _.label = op[1];
979
+ break;
980
+ }
981
+ if (op[0] === 6 && _.label < t[1]) {
982
+ _.label = t[1];
983
+ t = op;
984
+ break;
985
+ }
986
+ if (t && _.label < t[2]) {
987
+ _.label = t[2];
988
+ _.ops.push(op);
989
+ break;
990
+ }
991
+ if (t[2]) _.ops.pop();
992
+ _.trys.pop();
993
+ continue;
994
+ }
995
+ op = body.call(thisArg, _);
996
+ } catch (e) {
997
+ op = [
998
+ 6,
999
+ e
1000
+ ];
1001
+ y = 0;
1002
+ } finally{
1003
+ f = t = 0;
1004
+ }
1005
+ if (op[0] & 5) throw op[1];
1006
+ return {
1007
+ value: op[0] ? op[1] : void 0,
1008
+ done: true
1009
+ };
1010
+ }
1011
+ }
1012
+ /**
1013
+ * Creates a File object from the given input.
1014
+ *
1015
+ * @example
1016
+ * makeFileForFetch({ content: pdfBuffer, fileName: 'doc.pdf', mimeType: 'application/pdf' })
1017
+ */ function makeFileForFetch(input) {
1018
+ var options = {};
1019
+ if (input.mimeType) {
1020
+ options.type = input.mimeType;
1021
+ }
1022
+ if (input.lastModified != null) {
1023
+ options.lastModified = input.lastModified;
1024
+ }
1025
+ return new File(asArray(input.content), input.fileName, options);
1026
+ }
1027
+ function fetchFileFromUrl(input, safe) {
1028
+ return _async_to_generator$3(function() {
1029
+ var url, mimeType, inputFetch, useFetch, response, result, _ref, _ref1, _input_fileName, buffer, responseMimeType, fileName, options;
1030
+ return _ts_generator$3(this, function(_state) {
1031
+ switch(_state.label){
1032
+ case 0:
1033
+ url = input.url, mimeType = input.mimeType, inputFetch = input.fetch;
1034
+ useFetch = inputFetch !== null && inputFetch !== void 0 ? inputFetch : fetch;
1035
+ return [
1036
+ 4,
1037
+ useFetch(url, {
1038
+ method: 'GET'
1039
+ })
1040
+ ];
1041
+ case 1:
1042
+ response = _state.sent();
1043
+ if (!!response.ok) return [
1044
+ 3,
1045
+ 2
1046
+ ];
1047
+ if (!safe) {
1048
+ throw new Error("Failed to fetch file from ".concat(url, ": ").concat(response.status, " ").concat(response.statusText));
1049
+ }
1050
+ return [
1051
+ 3,
1052
+ 4
1053
+ ];
1054
+ case 2:
1055
+ return [
1056
+ 4,
1057
+ response.arrayBuffer()
1058
+ ];
1059
+ case 3:
1060
+ buffer = _state.sent();
1061
+ responseMimeType = (_ref = mimeType !== null && mimeType !== void 0 ? mimeType : response.headers.get('content-type')) !== null && _ref !== void 0 ? _ref : undefined;
1062
+ fileName = (_ref1 = (_input_fileName = input.fileName) !== null && _input_fileName !== void 0 ? _input_fileName : urlWithoutParameters(url).split('/').pop()) !== null && _ref1 !== void 0 ? _ref1 : 'file';
1063
+ options = responseMimeType ? {
1064
+ type: responseMimeType
1065
+ } : {};
1066
+ result = new File([
1067
+ buffer
1068
+ ], fileName, options);
1069
+ _state.label = 4;
1070
+ case 4:
1071
+ return [
1072
+ 2,
1073
+ result
1074
+ ];
1075
+ }
1076
+ });
1077
+ })();
895
1078
  }
896
1079
  /**
897
1080
  * Parses the file response and returns the response wrapped in a FetchFileResponse object.
@@ -909,6 +1092,20 @@ function fetchUploadFile(input) {
909
1092
  mimeType: contentType === null || contentType === void 0 ? void 0 : contentType.type
910
1093
  };
911
1094
  }
1095
+ /**
1096
+ * @deprecated Use makeFileForFetch() with FormData and context.fetch() instead.
1097
+ */ function fetchUploadFile(input) {
1098
+ var _input_method;
1099
+ var inputFetch = input.fetch, url = input.url, inputBody = input.body;
1100
+ var useFetch = inputFetch !== null && inputFetch !== void 0 ? inputFetch : fetch;
1101
+ return useFetch(url, {
1102
+ method: (_input_method = input.method) !== null && _input_method !== void 0 ? _input_method : 'POST',
1103
+ body: inputBody.body,
1104
+ headers: {
1105
+ 'Content-Type': inputBody.mimeType
1106
+ }
1107
+ });
1108
+ }
912
1109
 
913
1110
  function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
914
1111
  try {
@@ -1722,10 +1919,30 @@ function _ts_generator(thisArg, body) {
1722
1919
  }
1723
1920
  }
1724
1921
  /**
1725
- * Iterates through the pages of a created FetchPage instance by each item individually.
1922
+ * Iterates through all pages of a paginated fetch and processes each item individually.
1726
1923
  *
1727
- * @param config
1728
- * @returns
1924
+ * Built on top of {@link iterateFetchPagesByItems}, this function handles per-item granularity
1925
+ * by extracting items from each page and delegating to {@link performAsyncTasks}. Items are
1926
+ * processed sequentially by default to preserve ordering guarantees, but can be parallelized
1927
+ * via `iteratePerformTasksConfig`.
1928
+ *
1929
+ * Each item's callback receives a global index that reflects its position across all pages,
1930
+ * not just within the current page.
1931
+ *
1932
+ * @param config - Configuration specifying the fetch page source, item extraction, and per-item callback
1933
+ * @returns Combined result from {@link iterateFetchPagesByItems} including page/item counts and per-item task results
1934
+ *
1935
+ * @example
1936
+ * ```typescript
1937
+ * const result = await iterateFetchPagesByEachItem({
1938
+ * fetchPageFactory: myPageFactory,
1939
+ * input: { query: 'active' },
1940
+ * readItemsFromPageResult: (r) => r.result.items,
1941
+ * iterateEachPageItem: async (item, index, pageResult) => {
1942
+ * return processItem(item);
1943
+ * }
1944
+ * });
1945
+ * ```
1729
1946
  */ function iterateFetchPagesByEachItem(config) {
1730
1947
  return _async_to_generator(function() {
1731
1948
  var iterateEachPageItem, iteratePerformTasksConfig;
@@ -1771,10 +1988,32 @@ function _ts_generator(thisArg, body) {
1771
1988
  })();
1772
1989
  }
1773
1990
  /**
1774
- * Iterates through the pages of a created FetchPage instance.
1991
+ * Iterates through paginated fetch results at the item batch level.
1775
1992
  *
1776
- * @param config
1777
- * @returns
1993
+ * Fetches pages sequentially (or in parallel via `maxParallelPages`), extracts items
1994
+ * from each page using `readItemsFromPageResult`, optionally filters them, then
1995
+ * passes the batch to `iteratePageItems`. Tracks both raw loaded counts and
1996
+ * post-filter visited counts, terminating when either limit is reached or pages
1997
+ * are exhausted.
1998
+ *
1999
+ * For per-item processing instead of batch processing, use {@link iterateFetchPagesByEachItem}.
2000
+ *
2001
+ * @param config - Configuration specifying fetch source, item extraction, filtering, limits, and batch callback
2002
+ * @returns Result with page count and item counters (loaded and visited)
2003
+ *
2004
+ * @example
2005
+ * ```typescript
2006
+ * const result = await iterateFetchPagesByItems({
2007
+ * fetchPageFactory: myPageFactory,
2008
+ * input: { status: 'active' },
2009
+ * readItemsFromPageResult: (r) => r.result.records,
2010
+ * filterPageItems: (items) => items.filter(x => x.isValid),
2011
+ * iterateItemsLimit: 500,
2012
+ * iteratePageItems: async (items, pageResult, totalVisited) => {
2013
+ * await bulkInsert(items);
2014
+ * }
2015
+ * });
2016
+ * ```
1778
2017
  */ function iterateFetchPagesByItems(config) {
1779
2018
  return _async_to_generator(function() {
1780
2019
  var readItemsFromPageResult, inputTotalIterateItemsLimit, inputTotalLoadItemLimit, inputFilterPageItems, iteratePageItems, iterateItemsLimit, loadItemLimit, filterPageItems, totalItemsLoaded, totalItemsVisited, hasReachedFinalItem, fetchPagesConfig, iterateFetchPagesResult;
@@ -2377,4 +2616,4 @@ var fetchJsonRequestInit = fetchJsonRequestInitFunction();
2377
2616
  }
2378
2617
  });
2379
2618
 
2380
- export { DEFAULT_FETCH_HANDLER, DEFAULT_FETCH_REQUEST_FACTORY, FETCH_PAGE_FACTORY_DEFAULT_MAX_PAGE, FetchPageLimitReachedError, FetchPageNoNextPageError, FetchRequestFactoryError, FetchResponseError, FetchTimeoutError, JsonResponseParseError, configureFetch, fetchApiFetchService, fetchJsonBodyString, fetchJsonFunction, fetchJsonRequestInit, fetchJsonRequestInitFunction, fetchOk, fetchPageFactory, fetchRequestFactory, fetchService, fetchTimeout, fetchURL, fetchURLQueryKeyValueStringTuples, fetchURLSearchParamsObjectToURLSearchParams, fetchUploadFile, headersToHeadersTuple, isFetchRequest, isURL, isURLSearchParams, iterateFetchPages, iterateFetchPagesByEachItem, iterateFetchPagesByItems, makeUrlSearchParams, mergeMakeUrlSearchParamsOptions, mergeRequestHeaders, mergeRequestInits, parseFetchFileResponse, queryParamsToSearchParams, rateLimitedFetchHandler, requireOkResponse, returnNullHandleFetchJsonParseErrorFunction, throwJsonResponseParseErrorFunction };
2619
+ export { DEFAULT_FETCH_HANDLER, DEFAULT_FETCH_REQUEST_FACTORY, FETCH_PAGE_FACTORY_DEFAULT_MAX_PAGE, FetchPageLimitReachedError, FetchPageNoNextPageError, FetchRequestFactoryError, FetchResponseError, FetchTimeoutError, JsonResponseParseError, configureFetch, fetchApiFetchService, fetchFileFromUrl, fetchJsonBodyString, fetchJsonFunction, fetchJsonRequestInit, fetchJsonRequestInitFunction, fetchOk, fetchPageFactory, fetchRequestFactory, fetchService, fetchTimeout, fetchURL, fetchURLQueryKeyValueStringTuples, fetchURLSearchParamsObjectToURLSearchParams, fetchUploadFile, headersToHeadersTuple, isFetchRequest, isURL, isURLSearchParams, iterateFetchPages, iterateFetchPagesByEachItem, iterateFetchPagesByItems, makeFileForFetch, makeUrlSearchParams, mergeMakeUrlSearchParamsOptions, mergeRequestHeaders, mergeRequestInits, parseFetchFileResponse, queryParamsToSearchParams, rateLimitedFetchHandler, requireOkResponse, returnNullHandleFetchJsonParseErrorFunction, throwJsonResponseParseErrorFunction };
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@dereekb/util/fetch",
3
- "version": "13.0.6",
3
+ "version": "13.1.0",
4
4
  "peerDependencies": {
5
- "@dereekb/util": "13.0.6",
5
+ "@dereekb/util": "13.1.0",
6
6
  "make-error": "^1.3.0",
7
7
  "fast-content-type-parse": "^3.0.0"
8
8
  },
@@ -1,45 +1,72 @@
1
- import { type ContentTypeMimeType, type Maybe, type MimeTypeWithoutParameters } from '@dereekb/util';
1
+ import { type ArrayOrValue, type ContentTypeMimeType, type Maybe, type MimeTypeWithoutParameters } from '@dereekb/util';
2
2
  import { safeParse as parseContentType } from 'fast-content-type-parse';
3
3
  import { type FetchMethod } from './fetch.type';
4
4
  /**
5
- * Input for fetchUploadFile().
5
+ * Input for makeFileForFetch().
6
6
  */
7
- export interface FetchUploadFile {
7
+ export interface MakeFileForFetchInput {
8
8
  /**
9
- * URL to upload the file to.
9
+ * File content. Can be a string, ArrayBuffer, Blob, or array of BlobParts.
10
10
  */
11
- readonly url: string;
11
+ readonly content: ArrayOrValue<BlobPart>;
12
12
  /**
13
- * Fetch function to use.
13
+ * File name including extension.
14
14
  *
15
- * Defaults to the global fetch function.
15
+ * @example 'document.pdf'
16
16
  */
17
- readonly fetch?: typeof fetch;
17
+ readonly fileName: string;
18
18
  /**
19
- * Method to use. Defaults to 'POST'.
19
+ * MIME type of the file.
20
+ *
21
+ * @example 'application/pdf'
20
22
  */
21
- readonly method?: FetchMethod;
23
+ readonly mimeType?: ContentTypeMimeType;
22
24
  /**
23
- * Body data to upload.
25
+ * Last modified timestamp in milliseconds.
24
26
  */
25
- readonly body: FetchUploadFileBody;
27
+ readonly lastModified?: number;
26
28
  }
27
29
  /**
28
- * A mime type and body pair to upload.
30
+ * Creates a File object from the given input.
31
+ *
32
+ * @example
33
+ * makeFileForFetch({ content: pdfBuffer, fileName: 'doc.pdf', mimeType: 'application/pdf' })
29
34
  */
30
- export interface FetchUploadFileBody {
35
+ export declare function makeFileForFetch(input: MakeFileForFetchInput): File;
36
+ /**
37
+ * Input for fetchFileFromUrl().
38
+ */
39
+ export interface FetchFileFromUrlInput {
31
40
  /**
32
- * The mime type of the body content to upload.
41
+ * URL to download the file from.
33
42
  */
34
- readonly mimeType: ContentTypeMimeType;
43
+ readonly url: string;
35
44
  /**
36
- * The body, passed to fetch.
45
+ * File name to use for the resulting File object.
37
46
  *
38
- * Can be a Uint8Array, Buffer, FormData, string, etc.
47
+ * If not provided, attempts to derive the name from the URL path or falls back to 'file'.
39
48
  */
40
- readonly body: BodyInit;
49
+ readonly fileName?: Maybe<string>;
50
+ /**
51
+ * MIME type override. If not provided, uses the Content-Type from the response.
52
+ */
53
+ readonly mimeType?: Maybe<ContentTypeMimeType>;
54
+ /**
55
+ * Fetch function to use. Defaults to the global fetch.
56
+ */
57
+ readonly fetch?: Maybe<typeof fetch>;
41
58
  }
42
- export declare function fetchUploadFile(input: FetchUploadFile): Promise<Response>;
59
+ /**
60
+ * Downloads a file from the given URL and returns it as a File object.
61
+ *
62
+ * When safe is true, returns undefined instead of throwing on fetch failure.
63
+ *
64
+ * @example
65
+ * const file = await fetchFileFromUrl({ url: 'https://example.com/doc.pdf' })
66
+ * formData.append('file', file)
67
+ */
68
+ export declare function fetchFileFromUrl(input: FetchFileFromUrlInput): Promise<File>;
69
+ export declare function fetchFileFromUrl(input: FetchFileFromUrlInput, safe: true): Promise<Maybe<File>>;
43
70
  export type FetchFileResponseContentType = ReturnType<typeof parseContentType>;
44
71
  export interface FetchFileResponse {
45
72
  /**
@@ -66,3 +93,23 @@ export interface FetchFileResponse {
66
93
  * @returns
67
94
  */
68
95
  export declare function parseFetchFileResponse(response: Response): FetchFileResponse;
96
+ /**
97
+ * @deprecated Use makeFileForFetch() with FormData instead.
98
+ */
99
+ export interface FetchUploadFile {
100
+ readonly url: string;
101
+ readonly fetch?: typeof fetch;
102
+ readonly method?: FetchMethod;
103
+ readonly body: FetchUploadFileBody;
104
+ }
105
+ /**
106
+ * @deprecated Use makeFileForFetch() with FormData instead.
107
+ */
108
+ export interface FetchUploadFileBody {
109
+ readonly mimeType: ContentTypeMimeType;
110
+ readonly body: BodyInit;
111
+ }
112
+ /**
113
+ * @deprecated Use makeFileForFetch() with FormData and context.fetch() instead.
114
+ */
115
+ export declare function fetchUploadFile(input: FetchUploadFile): Promise<Response>;