@dereekb/util 13.0.0 → 13.0.2

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.
@@ -1,153 +1,582 @@
1
1
  'use strict';
2
2
 
3
3
  var makeError = require('make-error');
4
- require('core-js/modules/es.iterator.constructor.js');
5
- require('core-js/modules/es.iterator.for-each.js');
6
- require('core-js/modules/es.set.difference.v2.js');
7
- require('core-js/modules/es.set.symmetric-difference.v2.js');
8
- require('core-js/modules/es.set.union.v2.js');
9
4
  var util = require('@dereekb/util');
10
5
  var fastContentTypeParse = require('fast-content-type-parse');
11
- require('core-js/modules/es.iterator.map.js');
12
- require('core-js/modules/es.json.stringify.js');
13
6
 
7
+ function _assert_this_initialized$3(self) {
8
+ if (self === void 0) {
9
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
10
+ }
11
+ return self;
12
+ }
13
+ function _call_super$3(_this, derived, args) {
14
+ derived = _get_prototype_of$3(derived);
15
+ return _possible_constructor_return$3(_this, _is_native_reflect_construct$3() ? Reflect.construct(derived, args || [], _get_prototype_of$3(_this).constructor) : derived.apply(_this, args));
16
+ }
17
+ function _class_call_check$3(instance, Constructor) {
18
+ if (!(instance instanceof Constructor)) {
19
+ throw new TypeError("Cannot call a class as a function");
20
+ }
21
+ }
22
+ function _define_property$5(obj, key, value) {
23
+ if (key in obj) {
24
+ Object.defineProperty(obj, key, {
25
+ value: value,
26
+ enumerable: true,
27
+ configurable: true,
28
+ writable: true
29
+ });
30
+ } else {
31
+ obj[key] = value;
32
+ }
33
+ return obj;
34
+ }
35
+ function _get_prototype_of$3(o) {
36
+ _get_prototype_of$3 = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
37
+ return o.__proto__ || Object.getPrototypeOf(o);
38
+ };
39
+ return _get_prototype_of$3(o);
40
+ }
41
+ function _inherits$3(subClass, superClass) {
42
+ if (typeof superClass !== "function" && superClass !== null) {
43
+ throw new TypeError("Super expression must either be null or a function");
44
+ }
45
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
46
+ constructor: {
47
+ value: subClass,
48
+ writable: true,
49
+ configurable: true
50
+ }
51
+ });
52
+ if (superClass) _set_prototype_of$3(subClass, superClass);
53
+ }
54
+ function _possible_constructor_return$3(self, call) {
55
+ if (call && (_type_of$5(call) === "object" || typeof call === "function")) {
56
+ return call;
57
+ }
58
+ return _assert_this_initialized$3(self);
59
+ }
60
+ function _set_prototype_of$3(o, p) {
61
+ _set_prototype_of$3 = Object.setPrototypeOf || function setPrototypeOf(o, p) {
62
+ o.__proto__ = p;
63
+ return o;
64
+ };
65
+ return _set_prototype_of$3(o, p);
66
+ }
67
+ function _type_of$5(obj) {
68
+ "@swc/helpers - typeof";
69
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
70
+ }
71
+ function _is_native_reflect_construct$3() {
72
+ try {
73
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
74
+ } catch (_) {}
75
+ return (_is_native_reflect_construct$3 = function() {
76
+ return !!result;
77
+ })();
78
+ }
14
79
  /**
15
80
  * Thrown by a FetchRequestFactory if one of the async request initialization steps fails.
16
- */
17
- class FetchRequestFactoryError extends makeError.BaseError {
18
- constructor(error) {
19
- super(`Fetch request failed to build due to an unexpected error: ${typeof error === 'object' ? error.message ?? '' : error}`);
20
- this.error = void 0;
21
- this.error = error;
22
- }
23
- }
81
+ */ var FetchRequestFactoryError = /*#__PURE__*/ function(BaseError) {
82
+ _inherits$3(FetchRequestFactoryError, BaseError);
83
+ function FetchRequestFactoryError(error) {
84
+ _class_call_check$3(this, FetchRequestFactoryError);
85
+ var _this;
86
+ var _error_message;
87
+ _this = _call_super$3(this, FetchRequestFactoryError, [
88
+ "Fetch request failed to build due to an unexpected error: ".concat((typeof error === "undefined" ? "undefined" : _type_of$5(error)) === 'object' ? (_error_message = error.message) !== null && _error_message !== void 0 ? _error_message : '' : error)
89
+ ]), _define_property$5(_this, "error", void 0);
90
+ _this.error = error;
91
+ return _this;
92
+ }
93
+ return FetchRequestFactoryError;
94
+ }(makeError.BaseError);
24
95
  /**
25
96
  * Wraps the input fetch function to always pass the fetch response promise to requireOkResponse().
26
97
  *
27
98
  * @param inputFetch
28
99
  * @returns
29
- */
30
- function fetchOk(inputFetch) {
31
- return (input, init) => requireOkResponse(inputFetch(input, init));
32
- }
33
- class FetchResponseError extends makeError.BaseError {
34
- constructor(response) {
35
- super(`Fetch response was a non-ok status code (${response.status}): ${response.statusText}`);
36
- this.response = void 0;
37
- this.response = response;
38
- }
100
+ */ function fetchOk(inputFetch) {
101
+ return function(input, init) {
102
+ return requireOkResponse(inputFetch(input, init));
103
+ };
39
104
  }
40
- function requireOkResponse(responsePromise) {
41
- return responsePromise.then(response => {
42
- if (!response.ok) {
43
- throw new FetchResponseError(response);
105
+ var FetchResponseError = /*#__PURE__*/ function(BaseError) {
106
+ _inherits$3(FetchResponseError, BaseError);
107
+ function FetchResponseError(response) {
108
+ _class_call_check$3(this, FetchResponseError);
109
+ var _this;
110
+ _this = _call_super$3(this, FetchResponseError, [
111
+ "Fetch response was a non-ok status code (".concat(response.status, "): ").concat(response.statusText)
112
+ ]), _define_property$5(_this, "response", void 0);
113
+ _this.response = response;
114
+ return _this;
44
115
  }
45
- return response;
46
- });
116
+ return FetchResponseError;
117
+ }(makeError.BaseError);
118
+ function requireOkResponse(responsePromise) {
119
+ return responsePromise.then(function(response) {
120
+ if (!response.ok) {
121
+ throw new FetchResponseError(response);
122
+ }
123
+ return response;
124
+ });
47
125
  }
48
126
 
49
- class FetchTimeoutError extends makeError.BaseError {
50
- constructor(response, timeout) {
51
- super(`Fetch response was timed out (${timeout})`);
52
- this.response = void 0;
53
- this.timeout = void 0;
54
- this.response = response;
55
- this.timeout = timeout;
56
- }
127
+ function _assert_this_initialized$2(self) {
128
+ if (self === void 0) {
129
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
130
+ }
131
+ return self;
132
+ }
133
+ function _call_super$2(_this, derived, args) {
134
+ derived = _get_prototype_of$2(derived);
135
+ return _possible_constructor_return$2(_this, _is_native_reflect_construct$2() ? Reflect.construct(derived, args || [], _get_prototype_of$2(_this).constructor) : derived.apply(_this, args));
136
+ }
137
+ function _class_call_check$2(instance, Constructor) {
138
+ if (!(instance instanceof Constructor)) {
139
+ throw new TypeError("Cannot call a class as a function");
140
+ }
141
+ }
142
+ function _define_property$4(obj, key, value) {
143
+ if (key in obj) {
144
+ Object.defineProperty(obj, key, {
145
+ value: value,
146
+ enumerable: true,
147
+ configurable: true,
148
+ writable: true
149
+ });
150
+ } else {
151
+ obj[key] = value;
152
+ }
153
+ return obj;
154
+ }
155
+ function _get_prototype_of$2(o) {
156
+ _get_prototype_of$2 = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
157
+ return o.__proto__ || Object.getPrototypeOf(o);
158
+ };
159
+ return _get_prototype_of$2(o);
160
+ }
161
+ function _inherits$2(subClass, superClass) {
162
+ if (typeof superClass !== "function" && superClass !== null) {
163
+ throw new TypeError("Super expression must either be null or a function");
164
+ }
165
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
166
+ constructor: {
167
+ value: subClass,
168
+ writable: true,
169
+ configurable: true
170
+ }
171
+ });
172
+ if (superClass) _set_prototype_of$2(subClass, superClass);
57
173
  }
174
+ function _object_spread$4(target) {
175
+ for(var i = 1; i < arguments.length; i++){
176
+ var source = arguments[i] != null ? arguments[i] : {};
177
+ var ownKeys = Object.keys(source);
178
+ if (typeof Object.getOwnPropertySymbols === "function") {
179
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
180
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
181
+ }));
182
+ }
183
+ ownKeys.forEach(function(key) {
184
+ _define_property$4(target, key, source[key]);
185
+ });
186
+ }
187
+ return target;
188
+ }
189
+ function ownKeys$3(object, enumerableOnly) {
190
+ var keys = Object.keys(object);
191
+ if (Object.getOwnPropertySymbols) {
192
+ var symbols = Object.getOwnPropertySymbols(object);
193
+ keys.push.apply(keys, symbols);
194
+ }
195
+ return keys;
196
+ }
197
+ function _object_spread_props$3(target, source) {
198
+ source = source != null ? source : {};
199
+ if (Object.getOwnPropertyDescriptors) {
200
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
201
+ } else {
202
+ ownKeys$3(Object(source)).forEach(function(key) {
203
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
204
+ });
205
+ }
206
+ return target;
207
+ }
208
+ function _possible_constructor_return$2(self, call) {
209
+ if (call && (_type_of$4(call) === "object" || typeof call === "function")) {
210
+ return call;
211
+ }
212
+ return _assert_this_initialized$2(self);
213
+ }
214
+ function _set_prototype_of$2(o, p) {
215
+ _set_prototype_of$2 = Object.setPrototypeOf || function setPrototypeOf(o, p) {
216
+ o.__proto__ = p;
217
+ return o;
218
+ };
219
+ return _set_prototype_of$2(o, p);
220
+ }
221
+ function _type_of$4(obj) {
222
+ "@swc/helpers - typeof";
223
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
224
+ }
225
+ function _is_native_reflect_construct$2() {
226
+ try {
227
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
228
+ } catch (_) {}
229
+ return (_is_native_reflect_construct$2 = function() {
230
+ return !!result;
231
+ })();
232
+ }
233
+ var FetchTimeoutError = /*#__PURE__*/ function(BaseError) {
234
+ _inherits$2(FetchTimeoutError, BaseError);
235
+ function FetchTimeoutError(response, timeout) {
236
+ _class_call_check$2(this, FetchTimeoutError);
237
+ var _this;
238
+ _this = _call_super$2(this, FetchTimeoutError, [
239
+ "Fetch response was timed out (".concat(timeout, ")")
240
+ ]), _define_property$4(_this, "response", void 0), _define_property$4(_this, "timeout", void 0);
241
+ _this.response = response;
242
+ _this.timeout = timeout;
243
+ return _this;
244
+ }
245
+ return FetchTimeoutError;
246
+ }(makeError.BaseError);
58
247
  function fetchTimeout(inputFetch) {
59
- return (input, init) => {
60
- let controller;
61
- const timeout = init?.timeout ?? input.timeout;
62
- // if signal is not provided, and a timeout is specified, configure the timeout
63
- if (!init?.signal && timeout) {
64
- const abortController = new AbortController();
65
- controller = abortController;
66
- init = {
67
- ...init,
68
- signal: abortController.signal // pass the abort signal
69
- };
70
- }
71
- let responsePromise = inputFetch(input, init);
72
- if (timeout) {
73
- const timeoutId = setTimeout(() => {
74
- controller?.abort();
75
- }, timeout);
76
- responsePromise = responsePromise.finally(() => {
77
- clearTimeout(timeoutId);
78
- });
79
- }
80
- return responsePromise;
81
- };
248
+ return function(input, init) {
249
+ var _ref;
250
+ var controller;
251
+ var timeout = (_ref = init === null || init === void 0 ? void 0 : init.timeout) !== null && _ref !== void 0 ? _ref : input.timeout;
252
+ // if signal is not provided, and a timeout is specified, configure the timeout
253
+ if (!(init === null || init === void 0 ? void 0 : init.signal) && timeout) {
254
+ var abortController = new AbortController();
255
+ controller = abortController;
256
+ init = _object_spread_props$3(_object_spread$4({}, init), {
257
+ signal: abortController.signal // pass the abort signal
258
+ });
259
+ }
260
+ var responsePromise = inputFetch(input, init);
261
+ if (timeout) {
262
+ var timeoutId = setTimeout(function() {
263
+ controller === null || controller === void 0 ? void 0 : controller.abort();
264
+ }, timeout);
265
+ responsePromise = responsePromise.finally(function() {
266
+ clearTimeout(timeoutId);
267
+ });
268
+ }
269
+ return responsePromise;
270
+ };
82
271
  }
83
272
 
273
+ function _array_like_to_array$2(arr, len) {
274
+ if (len == null || len > arr.length) len = arr.length;
275
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
276
+ return arr2;
277
+ }
278
+ function _array_with_holes$2(arr) {
279
+ if (Array.isArray(arr)) return arr;
280
+ }
281
+ function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
282
+ try {
283
+ var info = gen[key](arg);
284
+ var value = info.value;
285
+ } catch (error) {
286
+ reject(error);
287
+ return;
288
+ }
289
+ if (info.done) {
290
+ resolve(value);
291
+ } else {
292
+ Promise.resolve(value).then(_next, _throw);
293
+ }
294
+ }
295
+ function _async_to_generator$3(fn) {
296
+ return function() {
297
+ var self = this, args = arguments;
298
+ return new Promise(function(resolve, reject) {
299
+ var gen = fn.apply(self, args);
300
+ function _next(value) {
301
+ asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
302
+ }
303
+ function _throw(err) {
304
+ asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
305
+ }
306
+ _next(undefined);
307
+ });
308
+ };
309
+ }
310
+ function _define_property$3(obj, key, value) {
311
+ if (key in obj) {
312
+ Object.defineProperty(obj, key, {
313
+ value: value,
314
+ enumerable: true,
315
+ configurable: true,
316
+ writable: true
317
+ });
318
+ } else {
319
+ obj[key] = value;
320
+ }
321
+ return obj;
322
+ }
323
+ function _instanceof$1(left, right) {
324
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
325
+ return !!right[Symbol.hasInstance](left);
326
+ } else {
327
+ return left instanceof right;
328
+ }
329
+ }
330
+ function _iterable_to_array_limit$2(arr, i) {
331
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
332
+ if (_i == null) return;
333
+ var _arr = [];
334
+ var _n = true;
335
+ var _d = false;
336
+ var _s, _e;
337
+ try {
338
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
339
+ _arr.push(_s.value);
340
+ if (i && _arr.length === i) break;
341
+ }
342
+ } catch (err) {
343
+ _d = true;
344
+ _e = err;
345
+ } finally{
346
+ try {
347
+ if (!_n && _i["return"] != null) _i["return"]();
348
+ } finally{
349
+ if (_d) throw _e;
350
+ }
351
+ }
352
+ return _arr;
353
+ }
354
+ function _non_iterable_rest$2() {
355
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
356
+ }
357
+ function _object_spread$3(target) {
358
+ for(var i = 1; i < arguments.length; i++){
359
+ var source = arguments[i] != null ? arguments[i] : {};
360
+ var ownKeys = Object.keys(source);
361
+ if (typeof Object.getOwnPropertySymbols === "function") {
362
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
363
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
364
+ }));
365
+ }
366
+ ownKeys.forEach(function(key) {
367
+ _define_property$3(target, key, source[key]);
368
+ });
369
+ }
370
+ return target;
371
+ }
372
+ function ownKeys$2(object, enumerableOnly) {
373
+ var keys = Object.keys(object);
374
+ if (Object.getOwnPropertySymbols) {
375
+ var symbols = Object.getOwnPropertySymbols(object);
376
+ keys.push.apply(keys, symbols);
377
+ }
378
+ return keys;
379
+ }
380
+ function _object_spread_props$2(target, source) {
381
+ source = source != null ? source : {};
382
+ if (Object.getOwnPropertyDescriptors) {
383
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
384
+ } else {
385
+ ownKeys$2(Object(source)).forEach(function(key) {
386
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
387
+ });
388
+ }
389
+ return target;
390
+ }
391
+ function _sliced_to_array$2(arr, i) {
392
+ return _array_with_holes$2(arr) || _iterable_to_array_limit$2(arr, i) || _unsupported_iterable_to_array$2(arr, i) || _non_iterable_rest$2();
393
+ }
394
+ function _type_of$3(obj) {
395
+ "@swc/helpers - typeof";
396
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
397
+ }
398
+ function _unsupported_iterable_to_array$2(o, minLen) {
399
+ if (!o) return;
400
+ if (typeof o === "string") return _array_like_to_array$2(o, minLen);
401
+ var n = Object.prototype.toString.call(o).slice(8, -1);
402
+ if (n === "Object" && o.constructor) n = o.constructor.name;
403
+ if (n === "Map" || n === "Set") return Array.from(n);
404
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$2(o, minLen);
405
+ }
406
+ function _ts_generator$3(thisArg, body) {
407
+ var f, y, t, _ = {
408
+ label: 0,
409
+ sent: function() {
410
+ if (t[0] & 1) throw t[1];
411
+ return t[1];
412
+ },
413
+ trys: [],
414
+ ops: []
415
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
416
+ return d(g, "next", {
417
+ value: verb(0)
418
+ }), d(g, "throw", {
419
+ value: verb(1)
420
+ }), d(g, "return", {
421
+ value: verb(2)
422
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
423
+ value: function() {
424
+ return this;
425
+ }
426
+ }), g;
427
+ function verb(n) {
428
+ return function(v) {
429
+ return step([
430
+ n,
431
+ v
432
+ ]);
433
+ };
434
+ }
435
+ function step(op) {
436
+ if (f) throw new TypeError("Generator is already executing.");
437
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
438
+ 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;
439
+ if (y = 0, t) op = [
440
+ op[0] & 2,
441
+ t.value
442
+ ];
443
+ switch(op[0]){
444
+ case 0:
445
+ case 1:
446
+ t = op;
447
+ break;
448
+ case 4:
449
+ _.label++;
450
+ return {
451
+ value: op[1],
452
+ done: false
453
+ };
454
+ case 5:
455
+ _.label++;
456
+ y = op[1];
457
+ op = [
458
+ 0
459
+ ];
460
+ continue;
461
+ case 7:
462
+ op = _.ops.pop();
463
+ _.trys.pop();
464
+ continue;
465
+ default:
466
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
467
+ _ = 0;
468
+ continue;
469
+ }
470
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
471
+ _.label = op[1];
472
+ break;
473
+ }
474
+ if (op[0] === 6 && _.label < t[1]) {
475
+ _.label = t[1];
476
+ t = op;
477
+ break;
478
+ }
479
+ if (t && _.label < t[2]) {
480
+ _.label = t[2];
481
+ _.ops.push(op);
482
+ break;
483
+ }
484
+ if (t[2]) _.ops.pop();
485
+ _.trys.pop();
486
+ continue;
487
+ }
488
+ op = body.call(thisArg, _);
489
+ } catch (e) {
490
+ op = [
491
+ 6,
492
+ e
493
+ ];
494
+ y = 0;
495
+ } finally{
496
+ f = t = 0;
497
+ }
498
+ if (op[0] & 5) throw op[1];
499
+ return {
500
+ value: op[0] ? op[1] : void 0,
501
+ done: true
502
+ };
503
+ }
504
+ }
84
505
  /**
85
506
  * Used to create a FetchService.
86
507
  *
87
508
  * @param config
88
509
  * @returns
89
- */
90
- function fetchService(config) {
91
- const {
92
- makeFetch: inputMakeFetch,
93
- makeRequest,
94
- baseRequest
95
- } = config;
96
- const factory = {
97
- fetchRequestFactory: config => fetchRequestFactory({
98
- makeRequest,
99
- baseRequest,
100
- ...config
101
- }),
102
- makeFetch: (config = {}) => configureFetch({
103
- makeRequest,
104
- makeFetch: inputMakeFetch,
105
- baseRequest,
106
- ...config
107
- }),
108
- makeRequest: config.makeRequest
109
- };
110
- return factory;
510
+ */ function fetchService(config) {
511
+ var inputMakeFetch = config.makeFetch, makeRequest = config.makeRequest, baseRequest = config.baseRequest;
512
+ var factory = {
513
+ fetchRequestFactory: function fetchRequestFactory1(config) {
514
+ return fetchRequestFactory(_object_spread$3({
515
+ makeRequest: makeRequest,
516
+ baseRequest: baseRequest
517
+ }, config));
518
+ },
519
+ makeFetch: function makeFetch() {
520
+ var _$config = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
521
+ return configureFetch(_object_spread$3({
522
+ makeRequest: makeRequest,
523
+ makeFetch: inputMakeFetch,
524
+ baseRequest: baseRequest
525
+ }, _$config));
526
+ },
527
+ makeRequest: config.makeRequest
528
+ };
529
+ return factory;
111
530
  }
112
531
  /**
113
532
  * Default FetchHabdler
114
533
  * @param request
115
534
  * @param makeFetch
116
535
  * @returns
117
- */
118
- const DEFAULT_FETCH_HANDLER = (request, makeFetch) => makeFetch(request);
536
+ */ var DEFAULT_FETCH_HANDLER = function DEFAULT_FETCH_HANDLER(request, makeFetch) {
537
+ return makeFetch(request);
538
+ };
119
539
  /**
120
540
  * Creates a function that wraps fetch and uses a FetchRequestFactory to generate a Request before invoking Fetch.
121
541
  *
122
542
  * @param config
123
543
  * @returns
124
- */
125
- function configureFetch(config) {
126
- const {
127
- makeFetch: inputMakeFetch = fetch,
128
- fetchHandler = DEFAULT_FETCH_HANDLER,
129
- useTimeout,
130
- requireOkResponse: inputRequireOkResponse,
131
- mapResponse
132
- } = config;
133
- let makeFetch = inputMakeFetch;
134
- if (useTimeout) {
135
- // add fetchTimeout
136
- makeFetch = fetchTimeout(makeFetch);
137
- }
138
- if (inputRequireOkResponse) {
139
- // Add fetchOk
140
- makeFetch = fetchOk(makeFetch);
141
- }
142
- const makeFetchRequest = fetchRequestFactory(config);
143
- return async (input, init) => {
144
- const request = await makeFetchRequest(input, init);
145
- let response = fetchHandler(request, makeFetch);
146
- if (mapResponse) {
147
- response = mapResponse(response);
148
- }
149
- return response;
150
- };
544
+ */ function configureFetch(config) {
545
+ var tmp = config.makeFetch, inputMakeFetch = tmp === void 0 ? fetch : tmp, _config_fetchHandler = config.fetchHandler, fetchHandler = _config_fetchHandler === void 0 ? DEFAULT_FETCH_HANDLER : _config_fetchHandler, useTimeout = config.useTimeout, inputRequireOkResponse = config.requireOkResponse, mapResponse = config.mapResponse;
546
+ var makeFetch = inputMakeFetch;
547
+ if (useTimeout) {
548
+ // add fetchTimeout
549
+ makeFetch = fetchTimeout(makeFetch);
550
+ }
551
+ if (inputRequireOkResponse) {
552
+ // Add fetchOk
553
+ makeFetch = fetchOk(makeFetch);
554
+ }
555
+ var makeFetchRequest = fetchRequestFactory(config);
556
+ return function(input, init) {
557
+ return _async_to_generator$3(function() {
558
+ var request, response;
559
+ return _ts_generator$3(this, function(_state) {
560
+ switch(_state.label){
561
+ case 0:
562
+ return [
563
+ 4,
564
+ makeFetchRequest(input, init)
565
+ ];
566
+ case 1:
567
+ request = _state.sent();
568
+ response = fetchHandler(request, makeFetch);
569
+ if (mapResponse) {
570
+ response = mapResponse(response);
571
+ }
572
+ return [
573
+ 2,
574
+ response
575
+ ];
576
+ }
577
+ });
578
+ })();
579
+ };
151
580
  }
152
581
  /**
153
582
  * The deafult FetchRequestFactory implementation that uses window/global Request.
@@ -155,448 +584,1368 @@ function configureFetch(config) {
155
584
  * @param input
156
585
  * @param init
157
586
  * @returns
158
- */
159
- const DEFAULT_FETCH_REQUEST_FACTORY = (input, init) => new Request(input, init);
587
+ */ var DEFAULT_FETCH_REQUEST_FACTORY = function DEFAULT_FETCH_REQUEST_FACTORY(input, init) {
588
+ return new Request(input, init);
589
+ };
160
590
  function fetchRequestFactory(config) {
161
- const {
162
- makeRequest = DEFAULT_FETCH_REQUEST_FACTORY,
163
- baseUrl: inputBaseUrl,
164
- baseRequest: inputBaseRequest,
165
- timeout,
166
- requestInitFactory,
167
- useBaseUrlForConfiguredFetchRequests = false,
168
- forceBaseUrlForWebsiteUrlWithPrefix = useBaseUrlForConfiguredFetchRequests
169
- } = config;
170
- const baseUrl = inputBaseUrl ? new URL(util.removeTrailingSlashes(inputBaseUrl)) : undefined;
171
- const buildUrl = baseUrl ? url => {
172
- let result;
173
- const urlString = url.toString();
174
- // retain the origin and any pathname from the base url, unless the url contains a prefix
175
- if (!forceBaseUrlForWebsiteUrlWithPrefix && util.isWebsiteUrlWithPrefix(urlString)) {
176
- result = new URL(urlString);
177
- } else {
178
- const urlPath = baseUrl.origin + util.fixMultiSlashesInSlashPath('/' + baseUrl.pathname + '/' + url);
179
- result = new URL(urlPath, baseUrl);
591
+ var _config_makeRequest = config.makeRequest, makeRequest = _config_makeRequest === void 0 ? DEFAULT_FETCH_REQUEST_FACTORY : _config_makeRequest, inputBaseUrl = config.baseUrl, inputBaseRequest = config.baseRequest, timeout = config.timeout, requestInitFactory = config.requestInitFactory, _config_useBaseUrlForConfiguredFetchRequests = config.useBaseUrlForConfiguredFetchRequests, useBaseUrlForConfiguredFetchRequests = _config_useBaseUrlForConfiguredFetchRequests === void 0 ? false : _config_useBaseUrlForConfiguredFetchRequests, _config_forceBaseUrlForWebsiteUrlWithPrefix = config.forceBaseUrlForWebsiteUrlWithPrefix, forceBaseUrlForWebsiteUrlWithPrefix = _config_forceBaseUrlForWebsiteUrlWithPrefix === void 0 ? useBaseUrlForConfiguredFetchRequests : _config_forceBaseUrlForWebsiteUrlWithPrefix;
592
+ var baseUrl = inputBaseUrl ? new URL(util.removeTrailingSlashes(inputBaseUrl)) : undefined;
593
+ var buildUrl = baseUrl ? function(url) {
594
+ var result;
595
+ var urlString = url.toString();
596
+ // retain the origin and any pathname from the base url, unless the url contains a prefix
597
+ if (!forceBaseUrlForWebsiteUrlWithPrefix && util.isWebsiteUrlWithPrefix(urlString)) {
598
+ result = new URL(urlString);
599
+ } else {
600
+ var urlPath = baseUrl.origin + util.fixMultiSlashesInSlashPath('/' + baseUrl.pathname + '/' + url);
601
+ result = new URL(urlPath, baseUrl);
602
+ }
603
+ return result;
604
+ } : undefined;
605
+ function asFetchRequest(input) {
606
+ return _async_to_generator$3(function() {
607
+ var awaitedInput, _tmp;
608
+ return _ts_generator$3(this, function(_state) {
609
+ switch(_state.label){
610
+ case 0:
611
+ if (!util.isPromiseLike(input)) return [
612
+ 3,
613
+ 2
614
+ ];
615
+ return [
616
+ 4,
617
+ input
618
+ ];
619
+ case 1:
620
+ _tmp = _state.sent();
621
+ return [
622
+ 3,
623
+ 3
624
+ ];
625
+ case 2:
626
+ _tmp = input;
627
+ _state.label = 3;
628
+ case 3:
629
+ awaitedInput = _tmp;
630
+ if (isFetchRequest(awaitedInput)) {
631
+ return [
632
+ 2,
633
+ awaitedInput
634
+ ];
635
+ } else {
636
+ return [
637
+ 2,
638
+ makeRequest(awaitedInput)
639
+ ];
640
+ }
641
+ }
642
+ });
643
+ })();
180
644
  }
181
- return result;
182
- } : undefined;
183
- async function asFetchRequest(input) {
184
- const awaitedInput = util.isPromiseLike(input) ? await input : input;
185
- if (isFetchRequest(awaitedInput)) {
186
- return awaitedInput;
645
+ var buildRequestWithFixedUrl = buildUrl ? function(input) {
646
+ return _async_to_generator$3(function() {
647
+ var relativeUrl, baseRequest, request, url;
648
+ return _ts_generator$3(this, function(_state) {
649
+ switch(_state.label){
650
+ case 0:
651
+ if (!(typeof input === 'string')) return [
652
+ 3,
653
+ 1
654
+ ];
655
+ relativeUrl = input;
656
+ return [
657
+ 3,
658
+ 4
659
+ ];
660
+ case 1:
661
+ if (!isFetchRequest(input)) return [
662
+ 3,
663
+ 2
664
+ ];
665
+ if (useBaseUrlForConfiguredFetchRequests) {
666
+ relativeUrl = input.url; // copy the url, and use it as the base.
667
+ baseRequest = input;
668
+ } else {
669
+ request = input;
670
+ }
671
+ return [
672
+ 3,
673
+ 4
674
+ ];
675
+ case 2:
676
+ return [
677
+ 4,
678
+ makeRequest(input)
679
+ ];
680
+ case 3:
681
+ request = _state.sent();
682
+ _state.label = 4;
683
+ case 4:
684
+ if (!!request) return [
685
+ 3,
686
+ 6
687
+ ];
688
+ url = buildUrl(relativeUrl);
689
+ return [
690
+ 4,
691
+ makeRequest(url.href, baseRequest)
692
+ ];
693
+ case 5:
694
+ request = _state.sent();
695
+ _state.label = 6;
696
+ case 6:
697
+ return [
698
+ 2,
699
+ request
700
+ ];
701
+ }
702
+ });
703
+ })();
704
+ } : asFetchRequest;
705
+ var buildRequestInit;
706
+ if (inputBaseRequest != null || timeout != null) {
707
+ var computeBaseRequest = function computeBaseRequest() {
708
+ return _async_to_generator$3(function() {
709
+ var computedBaseRequest, baseRequest;
710
+ return _ts_generator$3(this, function(_state) {
711
+ switch(_state.label){
712
+ case 0:
713
+ return [
714
+ 4,
715
+ inputBaseRequestAsGetter()
716
+ ];
717
+ case 1:
718
+ computedBaseRequest = _state.sent();
719
+ baseRequest = timeout ? _object_spread_props$2(_object_spread$3({}, computedBaseRequest), {
720
+ timeout: timeout
721
+ }) : computedBaseRequest;
722
+ return [
723
+ 2,
724
+ baseRequest
725
+ ];
726
+ }
727
+ });
728
+ })();
729
+ };
730
+ var combineRequestInits = function combineRequestInits(request, requestInit) {
731
+ return _async_to_generator$3(function() {
732
+ var baseRequest, merged, _tmp, timeout;
733
+ return _ts_generator$3(this, function(_state) {
734
+ switch(_state.label){
735
+ case 0:
736
+ return [
737
+ 4,
738
+ computeBaseRequest()
739
+ ];
740
+ case 1:
741
+ baseRequest = _state.sent();
742
+ _tmp = [
743
+ baseRequest
744
+ ];
745
+ return [
746
+ 4,
747
+ requestInit
748
+ ];
749
+ case 2:
750
+ merged = mergeRequestInits.apply(void 0, _tmp.concat([
751
+ _state.sent()
752
+ ]));
753
+ timeout = merged.timeout === undefined ? request.timeout : merged.timeout;
754
+ return [
755
+ 2,
756
+ _object_spread_props$2(_object_spread$3({}, merged), {
757
+ timeout: timeout
758
+ })
759
+ ];
760
+ }
761
+ });
762
+ })();
763
+ };
764
+ var inputBaseRequestAsGetter = util.asGetter(inputBaseRequest);
765
+ if (requestInitFactory) {
766
+ buildRequestInit = function buildRequestInit(req, x) {
767
+ return requestInitFactory(req, combineRequestInits(req, x));
768
+ };
769
+ } else {
770
+ buildRequestInit = function buildRequestInit(req, x) {
771
+ return combineRequestInits(req, x);
772
+ };
773
+ }
774
+ } else if (requestInitFactory) {
775
+ buildRequestInit = requestInitFactory;
187
776
  } else {
188
- return makeRequest(awaitedInput);
777
+ buildRequestInit = function buildRequestInit(_, x) {
778
+ return x;
779
+ };
189
780
  }
190
- }
191
- const buildRequestWithFixedUrl = buildUrl ? async input => {
192
- let relativeUrl;
193
- let baseRequest;
194
- let request;
195
- if (typeof input === 'string') {
196
- relativeUrl = input;
197
- } else if (isFetchRequest(input)) {
198
- if (useBaseUrlForConfiguredFetchRequests) {
199
- relativeUrl = input.url; // copy the url, and use it as the base.
200
- baseRequest = input;
201
- } else {
202
- request = input;
203
- }
204
- } else {
205
- request = await makeRequest(input);
206
- }
207
- if (!request) {
208
- const url = buildUrl(relativeUrl);
209
- request = await makeRequest(url.href, baseRequest);
210
- }
211
- return request;
212
- } : asFetchRequest;
213
- let buildRequestInit;
214
- if (inputBaseRequest != null || timeout != null) {
215
- const inputBaseRequestAsGetter = util.asGetter(inputBaseRequest);
216
- async function computeBaseRequest() {
217
- const computedBaseRequest = await inputBaseRequestAsGetter();
218
- const baseRequest = timeout ? {
219
- ...computedBaseRequest,
220
- timeout
221
- } : computedBaseRequest;
222
- return baseRequest;
223
- }
224
- async function combineRequestInits(request, requestInit) {
225
- const baseRequest = await computeBaseRequest();
226
- const merged = mergeRequestInits(baseRequest, await requestInit);
227
- const timeout = merged.timeout === undefined ? request.timeout : merged.timeout;
228
- return {
229
- ...merged,
230
- timeout
231
- };
232
- }
233
- if (requestInitFactory) {
234
- buildRequestInit = (req, x) => requestInitFactory(req, combineRequestInits(req, x));
235
- } else {
236
- buildRequestInit = (req, x) => combineRequestInits(req, x);
237
- }
238
- } else if (requestInitFactory) {
239
- buildRequestInit = requestInitFactory;
240
- } else {
241
- buildRequestInit = (_, x) => x;
242
- }
243
- return async (input, init) => {
244
- try {
245
- const fixedRequest = await buildRequestWithFixedUrl(input);
246
- init = await buildRequestInit(fixedRequest, init);
247
- const request = await makeRequest(fixedRequest, init);
248
- request.timeout = timeout; // copy/set timeout on the request directly
249
- return request;
250
- } catch (e) {
251
- if (e instanceof FetchRequestFactoryError) {
252
- throw e;
253
- } else {
254
- throw new FetchRequestFactoryError(e);
255
- }
256
- }
257
- };
781
+ return function(input, init) {
782
+ return _async_to_generator$3(function() {
783
+ var fixedRequest, request, e;
784
+ return _ts_generator$3(this, function(_state) {
785
+ switch(_state.label){
786
+ case 0:
787
+ _state.trys.push([
788
+ 0,
789
+ 4,
790
+ ,
791
+ 5
792
+ ]);
793
+ return [
794
+ 4,
795
+ buildRequestWithFixedUrl(input)
796
+ ];
797
+ case 1:
798
+ fixedRequest = _state.sent();
799
+ return [
800
+ 4,
801
+ buildRequestInit(fixedRequest, init)
802
+ ];
803
+ case 2:
804
+ init = _state.sent();
805
+ return [
806
+ 4,
807
+ makeRequest(fixedRequest, init)
808
+ ];
809
+ case 3:
810
+ request = _state.sent();
811
+ request.timeout = timeout; // copy/set timeout on the request directly
812
+ return [
813
+ 2,
814
+ request
815
+ ];
816
+ case 4:
817
+ e = _state.sent();
818
+ if (_instanceof$1(e, FetchRequestFactoryError)) {
819
+ throw e;
820
+ } else {
821
+ throw new FetchRequestFactoryError(e);
822
+ }
823
+ case 5:
824
+ return [
825
+ 2
826
+ ];
827
+ }
828
+ });
829
+ })();
830
+ };
258
831
  }
259
832
  function mergeRequestInits(base, requestInit) {
260
- if (requestInit) {
261
- const headers = mergeRequestHeaders([base.headers, requestInit?.headers]);
262
- return {
263
- ...base,
264
- ...requestInit,
265
- headers
266
- };
267
- } else {
268
- return base;
269
- }
833
+ if (requestInit) {
834
+ var headers = mergeRequestHeaders([
835
+ base.headers,
836
+ requestInit === null || requestInit === void 0 ? void 0 : requestInit.headers
837
+ ]);
838
+ return _object_spread_props$2(_object_spread$3({}, base, requestInit), {
839
+ headers: headers
840
+ });
841
+ } else {
842
+ return base;
843
+ }
270
844
  }
271
845
  function mergeRequestHeaders(inputHeadersArray) {
272
- const headersMap = util.multiValueMapBuilder();
273
- util.filterMaybeArrayValues(inputHeadersArray).forEach(headers => {
274
- const tuples = headersToHeadersTuple(headers);
275
- const visitedKeysSet = new Set();
276
- tuples.forEach(([key, value]) => {
277
- if (!visitedKeysSet.has(key)) {
278
- headersMap.delete(key); // delete all existing values to "override" them
279
- visitedKeysSet.add(key);
280
- }
281
- if (value) {
282
- headersMap.add(key, value);
283
- }
846
+ var headersMap = util.multiValueMapBuilder();
847
+ util.filterMaybeArrayValues(inputHeadersArray).forEach(function(headers) {
848
+ var tuples = headersToHeadersTuple(headers);
849
+ var visitedKeysSet = new Set();
850
+ tuples.forEach(function(param) {
851
+ var _param = _sliced_to_array$2(param, 2), key = _param[0], value = _param[1];
852
+ if (!visitedKeysSet.has(key)) {
853
+ headersMap.delete(key); // delete all existing values to "override" them
854
+ visitedKeysSet.add(key);
855
+ }
856
+ if (value) {
857
+ headersMap.add(key, value);
858
+ }
859
+ });
284
860
  });
285
- });
286
- return headersMap.tuples();
861
+ return headersMap.tuples();
287
862
  }
288
863
  function headersToHeadersTuple(headers) {
289
- let tuples = [];
290
- if (Array.isArray(headers)) {
291
- // use as tuples
292
- tuples = headers;
293
- } else if (typeof headers.forEach === 'function') {
294
- // use as a headers object
295
- headers.forEach((value, key) => {
296
- tuples.push([key, value]);
297
- });
298
- } else if (typeof headers === 'object') {
299
- // use as a normal object
300
- tuples = Object.entries(headers);
301
- }
302
- return tuples;
864
+ var tuples = [];
865
+ if (Array.isArray(headers)) {
866
+ // use as tuples
867
+ tuples = headers;
868
+ } else if (typeof headers.forEach === 'function') {
869
+ // use as a headers object
870
+ headers.forEach(function(value, key) {
871
+ tuples.push([
872
+ key,
873
+ value
874
+ ]);
875
+ });
876
+ } else if ((typeof headers === "undefined" ? "undefined" : _type_of$3(headers)) === 'object') {
877
+ // use as a normal object
878
+ tuples = Object.entries(headers);
879
+ }
880
+ return tuples;
303
881
  }
304
882
  function isFetchRequest(input) {
305
- return Boolean(input.url);
883
+ return Boolean(input.url);
306
884
  }
307
885
 
308
886
  function fetchUploadFile(input) {
309
- const {
310
- fetch: inputFetch,
311
- url,
312
- body: inputBody
313
- } = input;
314
- const useFetch = inputFetch ?? fetch;
315
- return useFetch(url, {
316
- method: input.method ?? 'POST',
317
- body: inputBody.body,
318
- headers: {
319
- 'Content-Type': inputBody.mimeType
320
- }
321
- });
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
895
+ }
896
+ });
322
897
  }
323
898
  /**
324
899
  * Parses the file response and returns the response wrapped in a FetchFileResponse object.
325
900
  *
326
901
  * @param response
327
902
  * @returns
328
- */
329
- function parseFetchFileResponse(response) {
330
- const rawContentType = response.headers.get('content-type');
331
- const parseContentTypeResult = fastContentTypeParse.safeParse(rawContentType ?? '');
332
- const contentType = parseContentTypeResult.type !== '' ? parseContentTypeResult : undefined;
333
- return {
334
- response,
335
- rawContentType,
336
- contentType,
337
- mimeType: contentType?.type
338
- };
903
+ */ function parseFetchFileResponse(response) {
904
+ var rawContentType = response.headers.get('content-type');
905
+ var parseContentTypeResult = fastContentTypeParse.safeParse(rawContentType !== null && rawContentType !== void 0 ? rawContentType : '');
906
+ var contentType = parseContentTypeResult.type !== '' ? parseContentTypeResult : undefined;
907
+ return {
908
+ response: response,
909
+ rawContentType: rawContentType,
910
+ contentType: contentType,
911
+ mimeType: contentType === null || contentType === void 0 ? void 0 : contentType.type
912
+ };
339
913
  }
340
914
 
915
+ function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
916
+ try {
917
+ var info = gen[key](arg);
918
+ var value = info.value;
919
+ } catch (error) {
920
+ reject(error);
921
+ return;
922
+ }
923
+ if (info.done) {
924
+ resolve(value);
925
+ } else {
926
+ Promise.resolve(value).then(_next, _throw);
927
+ }
928
+ }
929
+ function _async_to_generator$2(fn) {
930
+ return function() {
931
+ var self = this, args = arguments;
932
+ return new Promise(function(resolve, reject) {
933
+ var gen = fn.apply(self, args);
934
+ function _next(value) {
935
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
936
+ }
937
+ function _throw(err) {
938
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
939
+ }
940
+ _next(undefined);
941
+ });
942
+ };
943
+ }
944
+ function _ts_generator$2(thisArg, body) {
945
+ var f, y, t, _ = {
946
+ label: 0,
947
+ sent: function() {
948
+ if (t[0] & 1) throw t[1];
949
+ return t[1];
950
+ },
951
+ trys: [],
952
+ ops: []
953
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
954
+ return d(g, "next", {
955
+ value: verb(0)
956
+ }), d(g, "throw", {
957
+ value: verb(1)
958
+ }), d(g, "return", {
959
+ value: verb(2)
960
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
961
+ value: function() {
962
+ return this;
963
+ }
964
+ }), g;
965
+ function verb(n) {
966
+ return function(v) {
967
+ return step([
968
+ n,
969
+ v
970
+ ]);
971
+ };
972
+ }
973
+ function step(op) {
974
+ if (f) throw new TypeError("Generator is already executing.");
975
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
976
+ 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;
977
+ if (y = 0, t) op = [
978
+ op[0] & 2,
979
+ t.value
980
+ ];
981
+ switch(op[0]){
982
+ case 0:
983
+ case 1:
984
+ t = op;
985
+ break;
986
+ case 4:
987
+ _.label++;
988
+ return {
989
+ value: op[1],
990
+ done: false
991
+ };
992
+ case 5:
993
+ _.label++;
994
+ y = op[1];
995
+ op = [
996
+ 0
997
+ ];
998
+ continue;
999
+ case 7:
1000
+ op = _.ops.pop();
1001
+ _.trys.pop();
1002
+ continue;
1003
+ default:
1004
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
1005
+ _ = 0;
1006
+ continue;
1007
+ }
1008
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
1009
+ _.label = op[1];
1010
+ break;
1011
+ }
1012
+ if (op[0] === 6 && _.label < t[1]) {
1013
+ _.label = t[1];
1014
+ t = op;
1015
+ break;
1016
+ }
1017
+ if (t && _.label < t[2]) {
1018
+ _.label = t[2];
1019
+ _.ops.push(op);
1020
+ break;
1021
+ }
1022
+ if (t[2]) _.ops.pop();
1023
+ _.trys.pop();
1024
+ continue;
1025
+ }
1026
+ op = body.call(thisArg, _);
1027
+ } catch (e) {
1028
+ op = [
1029
+ 6,
1030
+ e
1031
+ ];
1032
+ y = 0;
1033
+ } finally{
1034
+ f = t = 0;
1035
+ }
1036
+ if (op[0] & 5) throw op[1];
1037
+ return {
1038
+ value: op[0] ? op[1] : void 0,
1039
+ done: true
1040
+ };
1041
+ }
1042
+ }
341
1043
  function rateLimitedFetchHandler(config) {
342
- const {
343
- updateWithResponse,
344
- maxRetries: inputMaxRetries
345
- } = config;
346
- const maxRetries = inputMaxRetries ?? 1;
347
- const _rateLimiter = config.rateLimiter;
348
- const fetchHandler = async (request, makeFetch) => {
349
- async function tryFetch(retriesAttempted) {
350
- // wait for the rate limiter
351
- await _rateLimiter.waitForRateLimit();
352
- let response;
353
- let fetchResponseError;
354
- try {
355
- response = await makeFetch(request.clone());
356
- } catch (e) {
357
- fetchResponseError = e;
358
- response = fetchResponseError.response;
359
- }
360
- // response could be null in some cases
361
- const shouldRetry = response ? await updateWithResponse(response, fetchResponseError) : false;
362
- if (shouldRetry && retriesAttempted < maxRetries) {
363
- response = await tryFetch(retriesAttempted + 1);
364
- } else {
365
- // re-throw the fetch response error if it exists and we cannot retry
366
- if (fetchResponseError != null) {
367
- throw fetchResponseError;
368
- }
369
- }
370
- // if response is null at this point but fetchResponseError is not, rethrow the error
371
- if (response == null && fetchResponseError != null) {
372
- throw fetchResponseError;
373
- }
374
- return response;
375
- }
376
- return tryFetch(0);
377
- };
378
- fetchHandler._rateLimiter = _rateLimiter;
379
- return fetchHandler;
1044
+ var updateWithResponse = config.updateWithResponse, inputMaxRetries = config.maxRetries;
1045
+ var maxRetries = inputMaxRetries !== null && inputMaxRetries !== void 0 ? inputMaxRetries : 1;
1046
+ var _rateLimiter = config.rateLimiter;
1047
+ var fetchHandler = function fetchHandler(request, makeFetch) {
1048
+ return _async_to_generator$2(function() {
1049
+ function tryFetch(retriesAttempted) {
1050
+ return _async_to_generator$2(function() {
1051
+ var response, fetchResponseError, e, shouldRetry, _tmp;
1052
+ return _ts_generator$2(this, function(_state) {
1053
+ switch(_state.label){
1054
+ case 0:
1055
+ // wait for the rate limiter
1056
+ return [
1057
+ 4,
1058
+ _rateLimiter.waitForRateLimit()
1059
+ ];
1060
+ case 1:
1061
+ _state.sent();
1062
+ _state.label = 2;
1063
+ case 2:
1064
+ _state.trys.push([
1065
+ 2,
1066
+ 4,
1067
+ ,
1068
+ 5
1069
+ ]);
1070
+ return [
1071
+ 4,
1072
+ makeFetch(request.clone())
1073
+ ];
1074
+ case 3:
1075
+ response = _state.sent();
1076
+ return [
1077
+ 3,
1078
+ 5
1079
+ ];
1080
+ case 4:
1081
+ e = _state.sent();
1082
+ fetchResponseError = e;
1083
+ response = fetchResponseError.response;
1084
+ return [
1085
+ 3,
1086
+ 5
1087
+ ];
1088
+ case 5:
1089
+ if (!response) return [
1090
+ 3,
1091
+ 7
1092
+ ];
1093
+ return [
1094
+ 4,
1095
+ updateWithResponse(response, fetchResponseError)
1096
+ ];
1097
+ case 6:
1098
+ _tmp = _state.sent();
1099
+ return [
1100
+ 3,
1101
+ 8
1102
+ ];
1103
+ case 7:
1104
+ _tmp = false;
1105
+ _state.label = 8;
1106
+ case 8:
1107
+ shouldRetry = _tmp;
1108
+ if (!(shouldRetry && retriesAttempted < maxRetries)) return [
1109
+ 3,
1110
+ 10
1111
+ ];
1112
+ return [
1113
+ 4,
1114
+ tryFetch(retriesAttempted + 1)
1115
+ ];
1116
+ case 9:
1117
+ response = _state.sent();
1118
+ return [
1119
+ 3,
1120
+ 11
1121
+ ];
1122
+ case 10:
1123
+ // re-throw the fetch response error if it exists and we cannot retry
1124
+ if (fetchResponseError != null) {
1125
+ throw fetchResponseError;
1126
+ }
1127
+ _state.label = 11;
1128
+ case 11:
1129
+ // if response is null at this point but fetchResponseError is not, rethrow the error
1130
+ if (response == null && fetchResponseError != null) {
1131
+ throw fetchResponseError;
1132
+ }
1133
+ return [
1134
+ 2,
1135
+ response
1136
+ ];
1137
+ }
1138
+ });
1139
+ })();
1140
+ }
1141
+ return _ts_generator$2(this, function(_state) {
1142
+ return [
1143
+ 2,
1144
+ tryFetch(0)
1145
+ ];
1146
+ });
1147
+ })();
1148
+ };
1149
+ fetchHandler._rateLimiter = _rateLimiter;
1150
+ return fetchHandler;
380
1151
  }
381
1152
 
382
- class FetchPageNoNextPageError extends FetchRequestFactoryError {
383
- constructor(page) {
384
- super(`There was no next page for this.`);
385
- this.page = void 0;
386
- this.page = page;
387
- }
388
- }
389
- class FetchPageLimitReachedError extends FetchRequestFactoryError {
390
- constructor(page, limit) {
391
- super(`The limit of ${limit} for the number of pages to read was reached.`);
392
- this.page = void 0;
393
- this.limit = void 0;
394
- this.page = page;
395
- this.limit = limit;
396
- }
1153
+ function _assert_this_initialized$1(self) {
1154
+ if (self === void 0) {
1155
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
1156
+ }
1157
+ return self;
1158
+ }
1159
+ function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
1160
+ try {
1161
+ var info = gen[key](arg);
1162
+ var value = info.value;
1163
+ } catch (error) {
1164
+ reject(error);
1165
+ return;
1166
+ }
1167
+ if (info.done) {
1168
+ resolve(value);
1169
+ } else {
1170
+ Promise.resolve(value).then(_next, _throw);
1171
+ }
397
1172
  }
1173
+ function _async_to_generator$1(fn) {
1174
+ return function() {
1175
+ var self = this, args = arguments;
1176
+ return new Promise(function(resolve, reject) {
1177
+ var gen = fn.apply(self, args);
1178
+ function _next(value) {
1179
+ asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
1180
+ }
1181
+ function _throw(err) {
1182
+ asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
1183
+ }
1184
+ _next(undefined);
1185
+ });
1186
+ };
1187
+ }
1188
+ function _call_super$1(_this, derived, args) {
1189
+ derived = _get_prototype_of$1(derived);
1190
+ return _possible_constructor_return$1(_this, _is_native_reflect_construct$1() ? Reflect.construct(derived, args || [], _get_prototype_of$1(_this).constructor) : derived.apply(_this, args));
1191
+ }
1192
+ function _class_call_check$1(instance, Constructor) {
1193
+ if (!(instance instanceof Constructor)) {
1194
+ throw new TypeError("Cannot call a class as a function");
1195
+ }
1196
+ }
1197
+ function _define_property$2(obj, key, value) {
1198
+ if (key in obj) {
1199
+ Object.defineProperty(obj, key, {
1200
+ value: value,
1201
+ enumerable: true,
1202
+ configurable: true,
1203
+ writable: true
1204
+ });
1205
+ } else {
1206
+ obj[key] = value;
1207
+ }
1208
+ return obj;
1209
+ }
1210
+ function _get_prototype_of$1(o) {
1211
+ _get_prototype_of$1 = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
1212
+ return o.__proto__ || Object.getPrototypeOf(o);
1213
+ };
1214
+ return _get_prototype_of$1(o);
1215
+ }
1216
+ function _inherits$1(subClass, superClass) {
1217
+ if (typeof superClass !== "function" && superClass !== null) {
1218
+ throw new TypeError("Super expression must either be null or a function");
1219
+ }
1220
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
1221
+ constructor: {
1222
+ value: subClass,
1223
+ writable: true,
1224
+ configurable: true
1225
+ }
1226
+ });
1227
+ if (superClass) _set_prototype_of$1(subClass, superClass);
1228
+ }
1229
+ function _object_spread$2(target) {
1230
+ for(var i = 1; i < arguments.length; i++){
1231
+ var source = arguments[i] != null ? arguments[i] : {};
1232
+ var ownKeys = Object.keys(source);
1233
+ if (typeof Object.getOwnPropertySymbols === "function") {
1234
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
1235
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
1236
+ }));
1237
+ }
1238
+ ownKeys.forEach(function(key) {
1239
+ _define_property$2(target, key, source[key]);
1240
+ });
1241
+ }
1242
+ return target;
1243
+ }
1244
+ function _possible_constructor_return$1(self, call) {
1245
+ if (call && (_type_of$2(call) === "object" || typeof call === "function")) {
1246
+ return call;
1247
+ }
1248
+ return _assert_this_initialized$1(self);
1249
+ }
1250
+ function _set_prototype_of$1(o, p) {
1251
+ _set_prototype_of$1 = Object.setPrototypeOf || function setPrototypeOf(o, p) {
1252
+ o.__proto__ = p;
1253
+ return o;
1254
+ };
1255
+ return _set_prototype_of$1(o, p);
1256
+ }
1257
+ function _type_of$2(obj) {
1258
+ "@swc/helpers - typeof";
1259
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
1260
+ }
1261
+ function _is_native_reflect_construct$1() {
1262
+ try {
1263
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
1264
+ } catch (_) {}
1265
+ return (_is_native_reflect_construct$1 = function() {
1266
+ return !!result;
1267
+ })();
1268
+ }
1269
+ function _ts_generator$1(thisArg, body) {
1270
+ var f, y, t, _ = {
1271
+ label: 0,
1272
+ sent: function() {
1273
+ if (t[0] & 1) throw t[1];
1274
+ return t[1];
1275
+ },
1276
+ trys: [],
1277
+ ops: []
1278
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
1279
+ return d(g, "next", {
1280
+ value: verb(0)
1281
+ }), d(g, "throw", {
1282
+ value: verb(1)
1283
+ }), d(g, "return", {
1284
+ value: verb(2)
1285
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
1286
+ value: function() {
1287
+ return this;
1288
+ }
1289
+ }), g;
1290
+ function verb(n) {
1291
+ return function(v) {
1292
+ return step([
1293
+ n,
1294
+ v
1295
+ ]);
1296
+ };
1297
+ }
1298
+ function step(op) {
1299
+ if (f) throw new TypeError("Generator is already executing.");
1300
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
1301
+ 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;
1302
+ if (y = 0, t) op = [
1303
+ op[0] & 2,
1304
+ t.value
1305
+ ];
1306
+ switch(op[0]){
1307
+ case 0:
1308
+ case 1:
1309
+ t = op;
1310
+ break;
1311
+ case 4:
1312
+ _.label++;
1313
+ return {
1314
+ value: op[1],
1315
+ done: false
1316
+ };
1317
+ case 5:
1318
+ _.label++;
1319
+ y = op[1];
1320
+ op = [
1321
+ 0
1322
+ ];
1323
+ continue;
1324
+ case 7:
1325
+ op = _.ops.pop();
1326
+ _.trys.pop();
1327
+ continue;
1328
+ default:
1329
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
1330
+ _ = 0;
1331
+ continue;
1332
+ }
1333
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
1334
+ _.label = op[1];
1335
+ break;
1336
+ }
1337
+ if (op[0] === 6 && _.label < t[1]) {
1338
+ _.label = t[1];
1339
+ t = op;
1340
+ break;
1341
+ }
1342
+ if (t && _.label < t[2]) {
1343
+ _.label = t[2];
1344
+ _.ops.push(op);
1345
+ break;
1346
+ }
1347
+ if (t[2]) _.ops.pop();
1348
+ _.trys.pop();
1349
+ continue;
1350
+ }
1351
+ op = body.call(thisArg, _);
1352
+ } catch (e) {
1353
+ op = [
1354
+ 6,
1355
+ e
1356
+ ];
1357
+ y = 0;
1358
+ } finally{
1359
+ f = t = 0;
1360
+ }
1361
+ if (op[0] & 5) throw op[1];
1362
+ return {
1363
+ value: op[0] ? op[1] : void 0,
1364
+ done: true
1365
+ };
1366
+ }
1367
+ }
1368
+ var FetchPageNoNextPageError = /*#__PURE__*/ function(FetchRequestFactoryError) {
1369
+ _inherits$1(FetchPageNoNextPageError, FetchRequestFactoryError);
1370
+ function FetchPageNoNextPageError(page) {
1371
+ _class_call_check$1(this, FetchPageNoNextPageError);
1372
+ var _this;
1373
+ _this = _call_super$1(this, FetchPageNoNextPageError, [
1374
+ "There was no next page for this."
1375
+ ]), _define_property$2(_this, "page", void 0);
1376
+ _this.page = page;
1377
+ return _this;
1378
+ }
1379
+ return FetchPageNoNextPageError;
1380
+ }(FetchRequestFactoryError);
1381
+ var FetchPageLimitReachedError = /*#__PURE__*/ function(FetchRequestFactoryError) {
1382
+ _inherits$1(FetchPageLimitReachedError, FetchRequestFactoryError);
1383
+ function FetchPageLimitReachedError(page, limit) {
1384
+ _class_call_check$1(this, FetchPageLimitReachedError);
1385
+ var _this;
1386
+ _this = _call_super$1(this, FetchPageLimitReachedError, [
1387
+ "The limit of ".concat(limit, " for the number of pages to read was reached.")
1388
+ ]), _define_property$2(_this, "page", void 0), _define_property$2(_this, "limit", void 0);
1389
+ _this.page = page;
1390
+ _this.limit = limit;
1391
+ return _this;
1392
+ }
1393
+ return FetchPageLimitReachedError;
1394
+ }(FetchRequestFactoryError);
398
1395
  /**
399
1396
  * Default max page for a FetchPageFactory.
400
- */
401
- const FETCH_PAGE_FACTORY_DEFAULT_MAX_PAGE = 100;
1397
+ */ var FETCH_PAGE_FACTORY_DEFAULT_MAX_PAGE = 100;
402
1398
  /**
403
1399
  * Creates a new FetchPageFactory from the input.
404
1400
  *
405
1401
  * @param config
406
1402
  * @returns
407
- */
408
- function fetchPageFactory(config) {
409
- const {
410
- fetch,
411
- readFetchPageResultInfo,
412
- buildInputForNextPage,
413
- defaultMaxPage,
414
- defaultMaxItemsPerPage
415
- } = config;
416
- return (initalInput, options) => {
417
- const {
418
- maxPage: inputMaxPage = defaultMaxPage,
419
- maxItemsPerPage: inputMaxItemsPerPage
420
- } = options ?? {};
421
- const maxItemsPerPage = inputMaxItemsPerPage ?? defaultMaxItemsPerPage;
422
- const maxPage = inputMaxPage === null ? Number.MAX_SAFE_INTEGER : inputMaxPage ?? FETCH_PAGE_FACTORY_DEFAULT_MAX_PAGE;
423
- function fetchNextWithInput(input, previous = undefined) {
424
- return async () => {
425
- const result = await fetch(input);
426
- const {
427
- cursor: readCursor,
428
- nextPageCursor,
429
- hasNext: readHasNext
430
- } = await readFetchPageResultInfo(result);
431
- const cursor = readCursor ?? previous?.cursor;
432
- const hasNext = readHasNext !== false;
433
- const page = previous ? previous.page + 1 : util.FIRST_PAGE;
434
- const isAtMaxPage = page >= maxPage;
435
- const nextPageResult = {
436
- input,
437
- result,
438
- page,
439
- previous,
440
- hasNext,
441
- isAtMaxPage,
442
- cursor,
443
- nextPageCursor,
444
- fetchNext: util.cachedGetter(async () => {
445
- // assert max page
446
- if (isAtMaxPage) {
447
- throw new FetchPageLimitReachedError(nextPageResult, maxPage);
1403
+ */ function fetchPageFactory(config) {
1404
+ var fetch = config.fetch, readFetchPageResultInfo = config.readFetchPageResultInfo, buildInputForNextPage = config.buildInputForNextPage, defaultMaxPage = config.defaultMaxPage, defaultMaxItemsPerPage = config.defaultMaxItemsPerPage;
1405
+ return function(initalInput, options) {
1406
+ var _ref = options !== null && options !== void 0 ? options : {}, tmp = _ref.maxPage, inputMaxPage = tmp === void 0 ? defaultMaxPage : tmp, inputMaxItemsPerPage = _ref.maxItemsPerPage;
1407
+ var maxItemsPerPage = inputMaxItemsPerPage !== null && inputMaxItemsPerPage !== void 0 ? inputMaxItemsPerPage : defaultMaxItemsPerPage;
1408
+ var maxPage = inputMaxPage === null ? Number.MAX_SAFE_INTEGER : inputMaxPage !== null && inputMaxPage !== void 0 ? inputMaxPage : FETCH_PAGE_FACTORY_DEFAULT_MAX_PAGE;
1409
+ function fetchNextWithInput(input) {
1410
+ var previous = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : undefined;
1411
+ return function() {
1412
+ return _async_to_generator$1(function() {
1413
+ var result, _ref, readCursor, nextPageCursor, readHasNext, cursor, hasNext, page, isAtMaxPage, nextPageResult;
1414
+ return _ts_generator$1(this, function(_state) {
1415
+ switch(_state.label){
1416
+ case 0:
1417
+ return [
1418
+ 4,
1419
+ fetch(input)
1420
+ ];
1421
+ case 1:
1422
+ result = _state.sent();
1423
+ return [
1424
+ 4,
1425
+ readFetchPageResultInfo(result)
1426
+ ];
1427
+ case 2:
1428
+ _ref = _state.sent(), readCursor = _ref.cursor, nextPageCursor = _ref.nextPageCursor, readHasNext = _ref.hasNext;
1429
+ cursor = readCursor !== null && readCursor !== void 0 ? readCursor : previous === null || previous === void 0 ? void 0 : previous.cursor;
1430
+ hasNext = readHasNext !== false;
1431
+ page = previous ? previous.page + 1 : util.FIRST_PAGE;
1432
+ isAtMaxPage = page >= maxPage;
1433
+ nextPageResult = {
1434
+ input: input,
1435
+ result: result,
1436
+ page: page,
1437
+ previous: previous,
1438
+ hasNext: hasNext,
1439
+ isAtMaxPage: isAtMaxPage,
1440
+ cursor: cursor,
1441
+ nextPageCursor: nextPageCursor,
1442
+ fetchNext: util.cachedGetter(function() {
1443
+ return _async_to_generator$1(function() {
1444
+ var nextPageInfo, _tmp;
1445
+ return _ts_generator$1(this, function(_state) {
1446
+ switch(_state.label){
1447
+ case 0:
1448
+ // assert max page
1449
+ if (isAtMaxPage) {
1450
+ throw new FetchPageLimitReachedError(nextPageResult, maxPage);
1451
+ }
1452
+ if (!hasNext) return [
1453
+ 3,
1454
+ 2
1455
+ ];
1456
+ return [
1457
+ 4,
1458
+ buildInputForNextPage(nextPageResult, input, {
1459
+ maxPage: maxPage,
1460
+ maxItemsPerPage: maxItemsPerPage
1461
+ })
1462
+ ];
1463
+ case 1:
1464
+ _tmp = _state.sent();
1465
+ return [
1466
+ 3,
1467
+ 3
1468
+ ];
1469
+ case 2:
1470
+ _tmp = undefined;
1471
+ _state.label = 3;
1472
+ case 3:
1473
+ nextPageInfo = _tmp;
1474
+ if (!nextPageInfo) {
1475
+ throw new FetchPageNoNextPageError(nextPageResult);
1476
+ }
1477
+ return [
1478
+ 2,
1479
+ fetchNextWithInput(_object_spread$2({}, input, nextPageInfo), nextPageResult)()
1480
+ ];
1481
+ }
1482
+ });
1483
+ })();
1484
+ })
1485
+ };
1486
+ return [
1487
+ 2,
1488
+ nextPageResult
1489
+ ];
1490
+ }
1491
+ });
1492
+ })();
1493
+ };
1494
+ }
1495
+ var page = {
1496
+ input: initalInput,
1497
+ fetchNext: util.cachedGetter(function() {
1498
+ return fetchNextWithInput(initalInput)();
1499
+ })
1500
+ };
1501
+ return page;
1502
+ };
1503
+ }
1504
+
1505
+ function _array_like_to_array$1(arr, len) {
1506
+ if (len == null || len > arr.length) len = arr.length;
1507
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
1508
+ return arr2;
1509
+ }
1510
+ function _array_with_holes$1(arr) {
1511
+ if (Array.isArray(arr)) return arr;
1512
+ }
1513
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
1514
+ try {
1515
+ var info = gen[key](arg);
1516
+ var value = info.value;
1517
+ } catch (error) {
1518
+ reject(error);
1519
+ return;
1520
+ }
1521
+ if (info.done) {
1522
+ resolve(value);
1523
+ } else {
1524
+ Promise.resolve(value).then(_next, _throw);
1525
+ }
1526
+ }
1527
+ function _async_to_generator(fn) {
1528
+ return function() {
1529
+ var self = this, args = arguments;
1530
+ return new Promise(function(resolve, reject) {
1531
+ var gen = fn.apply(self, args);
1532
+ function _next(value) {
1533
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
448
1534
  }
449
- // assert next page
450
- const nextPageInfo = hasNext ? await buildInputForNextPage(nextPageResult, input, {
451
- maxPage,
452
- maxItemsPerPage
453
- }) : undefined;
454
- if (!nextPageInfo) {
455
- throw new FetchPageNoNextPageError(nextPageResult);
1535
+ function _throw(err) {
1536
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
456
1537
  }
457
- return fetchNextWithInput({
458
- ...input,
459
- ...nextPageInfo
460
- }, nextPageResult)();
461
- })
1538
+ _next(undefined);
1539
+ });
1540
+ };
1541
+ }
1542
+ function _define_property$1(obj, key, value) {
1543
+ if (key in obj) {
1544
+ Object.defineProperty(obj, key, {
1545
+ value: value,
1546
+ enumerable: true,
1547
+ configurable: true,
1548
+ writable: true
1549
+ });
1550
+ } else {
1551
+ obj[key] = value;
1552
+ }
1553
+ return obj;
1554
+ }
1555
+ function _iterable_to_array_limit$1(arr, i) {
1556
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
1557
+ if (_i == null) return;
1558
+ var _arr = [];
1559
+ var _n = true;
1560
+ var _d = false;
1561
+ var _s, _e;
1562
+ try {
1563
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
1564
+ _arr.push(_s.value);
1565
+ if (i && _arr.length === i) break;
1566
+ }
1567
+ } catch (err) {
1568
+ _d = true;
1569
+ _e = err;
1570
+ } finally{
1571
+ try {
1572
+ if (!_n && _i["return"] != null) _i["return"]();
1573
+ } finally{
1574
+ if (_d) throw _e;
1575
+ }
1576
+ }
1577
+ return _arr;
1578
+ }
1579
+ function _non_iterable_rest$1() {
1580
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1581
+ }
1582
+ function _object_spread$1(target) {
1583
+ for(var i = 1; i < arguments.length; i++){
1584
+ var source = arguments[i] != null ? arguments[i] : {};
1585
+ var ownKeys = Object.keys(source);
1586
+ if (typeof Object.getOwnPropertySymbols === "function") {
1587
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
1588
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
1589
+ }));
1590
+ }
1591
+ ownKeys.forEach(function(key) {
1592
+ _define_property$1(target, key, source[key]);
1593
+ });
1594
+ }
1595
+ return target;
1596
+ }
1597
+ function ownKeys$1(object, enumerableOnly) {
1598
+ var keys = Object.keys(object);
1599
+ if (Object.getOwnPropertySymbols) {
1600
+ var symbols = Object.getOwnPropertySymbols(object);
1601
+ keys.push.apply(keys, symbols);
1602
+ }
1603
+ return keys;
1604
+ }
1605
+ function _object_spread_props$1(target, source) {
1606
+ source = source != null ? source : {};
1607
+ if (Object.getOwnPropertyDescriptors) {
1608
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
1609
+ } else {
1610
+ ownKeys$1(Object(source)).forEach(function(key) {
1611
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
1612
+ });
1613
+ }
1614
+ return target;
1615
+ }
1616
+ function _sliced_to_array$1(arr, i) {
1617
+ return _array_with_holes$1(arr) || _iterable_to_array_limit$1(arr, i) || _unsupported_iterable_to_array$1(arr, i) || _non_iterable_rest$1();
1618
+ }
1619
+ function _unsupported_iterable_to_array$1(o, minLen) {
1620
+ if (!o) return;
1621
+ if (typeof o === "string") return _array_like_to_array$1(o, minLen);
1622
+ var n = Object.prototype.toString.call(o).slice(8, -1);
1623
+ if (n === "Object" && o.constructor) n = o.constructor.name;
1624
+ if (n === "Map" || n === "Set") return Array.from(n);
1625
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$1(o, minLen);
1626
+ }
1627
+ function _ts_generator(thisArg, body) {
1628
+ var f, y, t, _ = {
1629
+ label: 0,
1630
+ sent: function() {
1631
+ if (t[0] & 1) throw t[1];
1632
+ return t[1];
1633
+ },
1634
+ trys: [],
1635
+ ops: []
1636
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
1637
+ return d(g, "next", {
1638
+ value: verb(0)
1639
+ }), d(g, "throw", {
1640
+ value: verb(1)
1641
+ }), d(g, "return", {
1642
+ value: verb(2)
1643
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
1644
+ value: function() {
1645
+ return this;
1646
+ }
1647
+ }), g;
1648
+ function verb(n) {
1649
+ return function(v) {
1650
+ return step([
1651
+ n,
1652
+ v
1653
+ ]);
1654
+ };
1655
+ }
1656
+ function step(op) {
1657
+ if (f) throw new TypeError("Generator is already executing.");
1658
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
1659
+ 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;
1660
+ if (y = 0, t) op = [
1661
+ op[0] & 2,
1662
+ t.value
1663
+ ];
1664
+ switch(op[0]){
1665
+ case 0:
1666
+ case 1:
1667
+ t = op;
1668
+ break;
1669
+ case 4:
1670
+ _.label++;
1671
+ return {
1672
+ value: op[1],
1673
+ done: false
1674
+ };
1675
+ case 5:
1676
+ _.label++;
1677
+ y = op[1];
1678
+ op = [
1679
+ 0
1680
+ ];
1681
+ continue;
1682
+ case 7:
1683
+ op = _.ops.pop();
1684
+ _.trys.pop();
1685
+ continue;
1686
+ default:
1687
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
1688
+ _ = 0;
1689
+ continue;
1690
+ }
1691
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
1692
+ _.label = op[1];
1693
+ break;
1694
+ }
1695
+ if (op[0] === 6 && _.label < t[1]) {
1696
+ _.label = t[1];
1697
+ t = op;
1698
+ break;
1699
+ }
1700
+ if (t && _.label < t[2]) {
1701
+ _.label = t[2];
1702
+ _.ops.push(op);
1703
+ break;
1704
+ }
1705
+ if (t[2]) _.ops.pop();
1706
+ _.trys.pop();
1707
+ continue;
1708
+ }
1709
+ op = body.call(thisArg, _);
1710
+ } catch (e) {
1711
+ op = [
1712
+ 6,
1713
+ e
1714
+ ];
1715
+ y = 0;
1716
+ } finally{
1717
+ f = t = 0;
1718
+ }
1719
+ if (op[0] & 5) throw op[1];
1720
+ return {
1721
+ value: op[0] ? op[1] : void 0,
1722
+ done: true
462
1723
  };
463
- return nextPageResult;
464
- };
465
1724
  }
466
- const page = {
467
- input: initalInput,
468
- fetchNext: util.cachedGetter(() => fetchNextWithInput(initalInput)())
469
- };
470
- return page;
471
- };
472
1725
  }
473
-
474
1726
  /**
475
1727
  * Iterates through the pages of a created FetchPage instance by each item individually.
476
1728
  *
477
1729
  * @param config
478
1730
  * @returns
479
- */
480
- async function iterateFetchPagesByEachItem(config) {
481
- const {
482
- iterateEachPageItem,
483
- iteratePerformTasksConfig
484
- } = config;
485
- return iterateFetchPagesByItems({
486
- ...config,
487
- iteratePageItems: async (items, fetchPageResult, startIndex) => {
488
- const itemIndexPairs = items.map((x, i) => [x, i + startIndex]);
489
- const performTasksResults = await util.performAsyncTasks(itemIndexPairs, ([item, i]) => {
490
- return iterateEachPageItem(item, i, fetchPageResult);
491
- }, {
492
- sequential: true,
493
- // sequential by default
494
- ...iteratePerformTasksConfig
495
- });
496
- return performTasksResults;
497
- }
498
- });
1731
+ */ function iterateFetchPagesByEachItem(config) {
1732
+ return _async_to_generator(function() {
1733
+ var iterateEachPageItem, iteratePerformTasksConfig;
1734
+ return _ts_generator(this, function(_state) {
1735
+ iterateEachPageItem = config.iterateEachPageItem, iteratePerformTasksConfig = config.iteratePerformTasksConfig;
1736
+ return [
1737
+ 2,
1738
+ iterateFetchPagesByItems(_object_spread_props$1(_object_spread$1({}, config), {
1739
+ iteratePageItems: function iteratePageItems(items, fetchPageResult, startIndex) {
1740
+ return _async_to_generator(function() {
1741
+ var itemIndexPairs, performTasksResults;
1742
+ return _ts_generator(this, function(_state) {
1743
+ switch(_state.label){
1744
+ case 0:
1745
+ itemIndexPairs = items.map(function(x, i) {
1746
+ return [
1747
+ x,
1748
+ i + startIndex
1749
+ ];
1750
+ });
1751
+ return [
1752
+ 4,
1753
+ util.performAsyncTasks(itemIndexPairs, function(param) {
1754
+ var _param = _sliced_to_array$1(param, 2), item = _param[0], i = _param[1];
1755
+ return iterateEachPageItem(item, i, fetchPageResult);
1756
+ }, _object_spread$1({
1757
+ sequential: true
1758
+ }, iteratePerformTasksConfig))
1759
+ ];
1760
+ case 1:
1761
+ performTasksResults = _state.sent();
1762
+ return [
1763
+ 2,
1764
+ performTasksResults
1765
+ ];
1766
+ }
1767
+ });
1768
+ })();
1769
+ }
1770
+ }))
1771
+ ];
1772
+ });
1773
+ })();
499
1774
  }
500
1775
  /**
501
1776
  * Iterates through the pages of a created FetchPage instance.
502
1777
  *
503
1778
  * @param config
504
1779
  * @returns
505
- */
506
- async function iterateFetchPagesByItems(config) {
507
- const {
508
- readItemsFromPageResult,
509
- iterateItemsLimit: inputTotalIterateItemsLimit,
510
- loadItemLimit: inputTotalLoadItemLimit,
511
- filterPageItems: inputFilterPageItems,
512
- iteratePageItems
513
- } = config;
514
- const iterateItemsLimit = inputTotalIterateItemsLimit ?? Number.MAX_SAFE_INTEGER;
515
- const loadItemLimit = inputTotalLoadItemLimit ?? Number.MAX_SAFE_INTEGER;
516
- const filterPageItems = inputFilterPageItems ?? util.mapIdentityFunction();
517
- let totalItemsLoaded = 0;
518
- let totalItemsVisited = 0;
519
- let hasReachedFinalItem = false;
520
- const fetchPagesConfig = {
521
- ...config,
522
- iteratePage: async fetchPageResult => {
523
- const items = readItemsFromPageResult(fetchPageResult);
524
- const filteredItems = await filterPageItems(items, fetchPageResult);
525
- const results = await iteratePageItems(filteredItems, fetchPageResult, totalItemsVisited);
526
- totalItemsLoaded += items.length;
527
- totalItemsVisited += filteredItems.length;
528
- hasReachedFinalItem = totalItemsLoaded >= loadItemLimit || totalItemsVisited >= iterateItemsLimit;
529
- return results;
530
- },
531
- endEarly: () => hasReachedFinalItem
532
- };
533
- const iterateFetchPagesResult = await iterateFetchPages(fetchPagesConfig);
534
- return {
535
- ...iterateFetchPagesResult,
536
- totalItemsLoaded,
537
- totalItemsVisited
538
- };
539
- }
540
- async function iterateFetchPages(config) {
541
- const {
542
- iteratePage,
543
- fetchPage: inputFetchPage,
544
- input,
545
- fetchPageFactory,
546
- usePageResult,
547
- maxParallelPages,
548
- waitBetweenPages,
549
- maxPage,
550
- maxItemsPerPage,
551
- endEarly
552
- } = config;
553
- let hasReachedEnd = false;
554
- let fetchPage = inputFetchPage ?? fetchPageFactory(input, {
555
- maxPage,
556
- maxItemsPerPage
557
- });
558
- let currentNextPage;
559
- async function taskInputFactory() {
560
- if (hasReachedEnd) {
561
- return null; // issue no more tasks
562
- }
563
- if (currentNextPage != null && (currentNextPage.isAtMaxPage || !currentNextPage.hasNext)) {
564
- hasReachedEnd = true;
565
- return null;
566
- }
567
- currentNextPage = await fetchPage.fetchNext();
568
- fetchPage = currentNextPage;
569
- return {
570
- i: currentNextPage.page,
571
- fetchPageResult: currentNextPage
572
- };
573
- }
574
- const performTaskFn = util.performTasksFromFactoryInParallelFunction({
575
- maxParallelTasks: maxParallelPages,
576
- waitBetweenTasks: waitBetweenPages,
577
- taskFactory: async ({
578
- i,
579
- fetchPageResult
580
- }) => {
581
- const result = await iteratePage(fetchPageResult);
582
- const iterationResult = {
583
- i,
584
- fetchPageResult,
585
- result
586
- };
587
- await usePageResult?.(iterationResult);
588
- const shouldEndEarly = endEarly?.(iterationResult);
589
- if (shouldEndEarly) {
590
- hasReachedEnd = true;
591
- }
592
- }
593
- });
594
- await performTaskFn(taskInputFactory);
595
- const result = {
596
- totalPages: (currentNextPage?.page ?? 0) + 1,
597
- totalPagesLimitReached: currentNextPage?.isAtMaxPage ?? false
598
- };
599
- return result;
1780
+ */ function iterateFetchPagesByItems(config) {
1781
+ return _async_to_generator(function() {
1782
+ var readItemsFromPageResult, inputTotalIterateItemsLimit, inputTotalLoadItemLimit, inputFilterPageItems, iteratePageItems, iterateItemsLimit, loadItemLimit, filterPageItems, totalItemsLoaded, totalItemsVisited, hasReachedFinalItem, fetchPagesConfig, iterateFetchPagesResult;
1783
+ return _ts_generator(this, function(_state) {
1784
+ switch(_state.label){
1785
+ case 0:
1786
+ readItemsFromPageResult = config.readItemsFromPageResult, inputTotalIterateItemsLimit = config.iterateItemsLimit, inputTotalLoadItemLimit = config.loadItemLimit, inputFilterPageItems = config.filterPageItems, iteratePageItems = config.iteratePageItems;
1787
+ iterateItemsLimit = inputTotalIterateItemsLimit !== null && inputTotalIterateItemsLimit !== void 0 ? inputTotalIterateItemsLimit : Number.MAX_SAFE_INTEGER;
1788
+ loadItemLimit = inputTotalLoadItemLimit !== null && inputTotalLoadItemLimit !== void 0 ? inputTotalLoadItemLimit : Number.MAX_SAFE_INTEGER;
1789
+ filterPageItems = inputFilterPageItems !== null && inputFilterPageItems !== void 0 ? inputFilterPageItems : util.mapIdentityFunction();
1790
+ totalItemsLoaded = 0;
1791
+ totalItemsVisited = 0;
1792
+ hasReachedFinalItem = false;
1793
+ fetchPagesConfig = _object_spread_props$1(_object_spread$1({}, config), {
1794
+ iteratePage: function iteratePage(fetchPageResult) {
1795
+ return _async_to_generator(function() {
1796
+ var items, filteredItems, results;
1797
+ return _ts_generator(this, function(_state) {
1798
+ switch(_state.label){
1799
+ case 0:
1800
+ items = readItemsFromPageResult(fetchPageResult);
1801
+ return [
1802
+ 4,
1803
+ filterPageItems(items, fetchPageResult)
1804
+ ];
1805
+ case 1:
1806
+ filteredItems = _state.sent();
1807
+ return [
1808
+ 4,
1809
+ iteratePageItems(filteredItems, fetchPageResult, totalItemsVisited)
1810
+ ];
1811
+ case 2:
1812
+ results = _state.sent();
1813
+ totalItemsLoaded += items.length;
1814
+ totalItemsVisited += filteredItems.length;
1815
+ hasReachedFinalItem = totalItemsLoaded >= loadItemLimit || totalItemsVisited >= iterateItemsLimit;
1816
+ return [
1817
+ 2,
1818
+ results
1819
+ ];
1820
+ }
1821
+ });
1822
+ })();
1823
+ },
1824
+ endEarly: function endEarly() {
1825
+ return hasReachedFinalItem;
1826
+ }
1827
+ });
1828
+ return [
1829
+ 4,
1830
+ iterateFetchPages(fetchPagesConfig)
1831
+ ];
1832
+ case 1:
1833
+ iterateFetchPagesResult = _state.sent();
1834
+ return [
1835
+ 2,
1836
+ _object_spread_props$1(_object_spread$1({}, iterateFetchPagesResult), {
1837
+ totalItemsLoaded: totalItemsLoaded,
1838
+ totalItemsVisited: totalItemsVisited
1839
+ })
1840
+ ];
1841
+ }
1842
+ });
1843
+ })();
1844
+ }
1845
+ function iterateFetchPages(config) {
1846
+ return _async_to_generator(function() {
1847
+ var _ref, _ref1, iteratePage, inputFetchPage, input, fetchPageFactory, usePageResult, maxParallelPages, waitBetweenPages, maxPage, maxItemsPerPage, endEarly, hasReachedEnd, fetchPage, currentNextPage, performTaskFn, result;
1848
+ function taskInputFactory() {
1849
+ return _async_to_generator(function() {
1850
+ return _ts_generator(this, function(_state) {
1851
+ switch(_state.label){
1852
+ case 0:
1853
+ if (hasReachedEnd) {
1854
+ return [
1855
+ 2,
1856
+ null
1857
+ ]; // issue no more tasks
1858
+ }
1859
+ if (currentNextPage != null && (currentNextPage.isAtMaxPage || !currentNextPage.hasNext)) {
1860
+ hasReachedEnd = true;
1861
+ return [
1862
+ 2,
1863
+ null
1864
+ ];
1865
+ }
1866
+ return [
1867
+ 4,
1868
+ fetchPage.fetchNext()
1869
+ ];
1870
+ case 1:
1871
+ currentNextPage = _state.sent();
1872
+ fetchPage = currentNextPage;
1873
+ return [
1874
+ 2,
1875
+ {
1876
+ i: currentNextPage.page,
1877
+ fetchPageResult: currentNextPage
1878
+ }
1879
+ ];
1880
+ }
1881
+ });
1882
+ })();
1883
+ }
1884
+ return _ts_generator(this, function(_state) {
1885
+ switch(_state.label){
1886
+ case 0:
1887
+ iteratePage = config.iteratePage, inputFetchPage = config.fetchPage, input = config.input, fetchPageFactory = config.fetchPageFactory, usePageResult = config.usePageResult, maxParallelPages = config.maxParallelPages, waitBetweenPages = config.waitBetweenPages, maxPage = config.maxPage, maxItemsPerPage = config.maxItemsPerPage, endEarly = config.endEarly;
1888
+ hasReachedEnd = false;
1889
+ fetchPage = inputFetchPage !== null && inputFetchPage !== void 0 ? inputFetchPage : fetchPageFactory(input, {
1890
+ maxPage: maxPage,
1891
+ maxItemsPerPage: maxItemsPerPage
1892
+ });
1893
+ performTaskFn = util.performTasksFromFactoryInParallelFunction({
1894
+ maxParallelTasks: maxParallelPages,
1895
+ waitBetweenTasks: waitBetweenPages,
1896
+ taskFactory: function taskFactory(param) {
1897
+ var i = param.i, fetchPageResult = param.fetchPageResult;
1898
+ return _async_to_generator(function() {
1899
+ var result, iterationResult, shouldEndEarly;
1900
+ return _ts_generator(this, function(_state) {
1901
+ switch(_state.label){
1902
+ case 0:
1903
+ return [
1904
+ 4,
1905
+ iteratePage(fetchPageResult)
1906
+ ];
1907
+ case 1:
1908
+ result = _state.sent();
1909
+ iterationResult = {
1910
+ i: i,
1911
+ fetchPageResult: fetchPageResult,
1912
+ result: result
1913
+ };
1914
+ return [
1915
+ 4,
1916
+ usePageResult === null || usePageResult === void 0 ? void 0 : usePageResult(iterationResult)
1917
+ ];
1918
+ case 2:
1919
+ _state.sent();
1920
+ shouldEndEarly = endEarly === null || endEarly === void 0 ? void 0 : endEarly(iterationResult);
1921
+ if (shouldEndEarly) {
1922
+ hasReachedEnd = true;
1923
+ }
1924
+ return [
1925
+ 2
1926
+ ];
1927
+ }
1928
+ });
1929
+ })();
1930
+ }
1931
+ });
1932
+ return [
1933
+ 4,
1934
+ performTaskFn(taskInputFactory)
1935
+ ];
1936
+ case 1:
1937
+ _state.sent();
1938
+ result = {
1939
+ totalPages: ((_ref = currentNextPage === null || currentNextPage === void 0 ? void 0 : currentNextPage.page) !== null && _ref !== void 0 ? _ref : 0) + 1,
1940
+ totalPagesLimitReached: (_ref1 = currentNextPage === null || currentNextPage === void 0 ? void 0 : currentNextPage.isAtMaxPage) !== null && _ref1 !== void 0 ? _ref1 : false
1941
+ };
1942
+ return [
1943
+ 2,
1944
+ result
1945
+ ];
1946
+ }
1947
+ });
1948
+ })();
600
1949
  }
601
1950
 
602
1951
  /**
@@ -605,209 +1954,429 @@ async function iterateFetchPages(config) {
605
1954
  * @param input
606
1955
  * @param omitKeys
607
1956
  * @returns
608
- */
609
- function makeUrlSearchParams(input, options) {
610
- const {
611
- omitKeys,
612
- filterEmptyValues: filterValues
613
- } = options ?? {};
614
- const mergedInput = Array.isArray(input) ? util.mergeObjects(input) : input;
615
- const filteredInput = filterValues ?? true ? util.filterEmptyPojoValues(mergedInput ?? {}) : mergedInput;
616
- const searchParams = new URLSearchParams(filteredInput);
617
- if (omitKeys != null) {
618
- util.useIterableOrValue(omitKeys, key => searchParams.delete(key), false);
619
- }
620
- return searchParams;
1957
+ */ function makeUrlSearchParams(input, options) {
1958
+ var _ref = options !== null && options !== void 0 ? options : {}, omitKeys = _ref.omitKeys, filterValues = _ref.filterEmptyValues;
1959
+ var mergedInput = Array.isArray(input) ? util.mergeObjects(input) : input;
1960
+ var filteredInput = (filterValues !== null && filterValues !== void 0 ? filterValues : true) ? util.filterEmptyPojoValues(mergedInput !== null && mergedInput !== void 0 ? mergedInput : {}) : mergedInput;
1961
+ var searchParams = new URLSearchParams(filteredInput);
1962
+ if (omitKeys != null) {
1963
+ util.useIterableOrValue(omitKeys, function(key) {
1964
+ return searchParams.delete(key);
1965
+ }, false);
1966
+ }
1967
+ return searchParams;
621
1968
  }
622
1969
  /**
623
1970
  * Merges an array of MakeUrlSearchParamsOptions into a single MakeUrlSearchParamsOptions value.
624
- */
625
- function mergeMakeUrlSearchParamsOptions(options) {
626
- const omitKeys = new Set();
627
- util.useIterableOrValue(options, x => {
628
- if (x?.omitKeys != null) {
629
- util.useIterableOrValue(x.omitKeys, key => omitKeys.add(key));
630
- }
631
- });
632
- return {
633
- omitKeys: omitKeys.size > 0 ? Array.from(omitKeys) : undefined
634
- };
1971
+ */ function mergeMakeUrlSearchParamsOptions(options) {
1972
+ var omitKeys = new Set();
1973
+ util.useIterableOrValue(options, function(x) {
1974
+ if ((x === null || x === void 0 ? void 0 : x.omitKeys) != null) {
1975
+ util.useIterableOrValue(x.omitKeys, function(key) {
1976
+ return omitKeys.add(key);
1977
+ });
1978
+ }
1979
+ });
1980
+ return {
1981
+ omitKeys: omitKeys.size > 0 ? Array.from(omitKeys) : undefined
1982
+ };
635
1983
  }
636
1984
 
1985
+ function _array_like_to_array(arr, len) {
1986
+ if (len == null || len > arr.length) len = arr.length;
1987
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
1988
+ return arr2;
1989
+ }
1990
+ function _array_with_holes(arr) {
1991
+ if (Array.isArray(arr)) return arr;
1992
+ }
1993
+ function _instanceof(left, right) {
1994
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
1995
+ return !!right[Symbol.hasInstance](left);
1996
+ } else {
1997
+ return left instanceof right;
1998
+ }
1999
+ }
2000
+ function _iterable_to_array_limit(arr, i) {
2001
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
2002
+ if (_i == null) return;
2003
+ var _arr = [];
2004
+ var _n = true;
2005
+ var _d = false;
2006
+ var _s, _e;
2007
+ try {
2008
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
2009
+ _arr.push(_s.value);
2010
+ if (i && _arr.length === i) break;
2011
+ }
2012
+ } catch (err) {
2013
+ _d = true;
2014
+ _e = err;
2015
+ } finally{
2016
+ try {
2017
+ if (!_n && _i["return"] != null) _i["return"]();
2018
+ } finally{
2019
+ if (_d) throw _e;
2020
+ }
2021
+ }
2022
+ return _arr;
2023
+ }
2024
+ function _non_iterable_rest() {
2025
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
2026
+ }
2027
+ function _sliced_to_array(arr, i) {
2028
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
2029
+ }
2030
+ function _type_of$1(obj) {
2031
+ "@swc/helpers - typeof";
2032
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
2033
+ }
2034
+ function _unsupported_iterable_to_array(o, minLen) {
2035
+ if (!o) return;
2036
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
2037
+ var n = Object.prototype.toString.call(o).slice(8, -1);
2038
+ if (n === "Object" && o.constructor) n = o.constructor.name;
2039
+ if (n === "Map" || n === "Set") return Array.from(n);
2040
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
2041
+ }
637
2042
  function fetchURL(input) {
638
- let url;
639
- if (typeof input === 'string') {
640
- url = input;
641
- } else if (isURL(input)) {
642
- url = input.href;
643
- } else {
644
- const baseUrl = fetchURL(input.url);
645
- if (input.queryParams) {
646
- const searchParams = queryParamsToSearchParams(input.queryParams);
647
- if (!util.isEmptyIterable(searchParams)) {
648
- url = util.fixExtraQueryParameters(baseUrl + `?${searchParams.toString()}`);
649
- } else {
650
- url = baseUrl;
651
- }
2043
+ var url;
2044
+ if (typeof input === 'string') {
2045
+ url = input;
2046
+ } else if (isURL(input)) {
2047
+ url = input.href;
652
2048
  } else {
653
- url = baseUrl;
2049
+ var baseUrl = fetchURL(input.url);
2050
+ if (input.queryParams) {
2051
+ var searchParams = queryParamsToSearchParams(input.queryParams);
2052
+ if (!util.isEmptyIterable(searchParams)) {
2053
+ url = util.fixExtraQueryParameters(baseUrl + "?".concat(searchParams.toString()));
2054
+ } else {
2055
+ url = baseUrl;
2056
+ }
2057
+ } else {
2058
+ url = baseUrl;
2059
+ }
654
2060
  }
655
- }
656
- return url;
2061
+ return url;
657
2062
  }
658
2063
  function isURL(input) {
659
- return typeof input === 'object' && input instanceof URL;
2064
+ return (typeof input === "undefined" ? "undefined" : _type_of$1(input)) === 'object' && _instanceof(input, URL);
660
2065
  }
661
2066
  function isURLSearchParams(input) {
662
- return typeof input === 'object' && input instanceof URLSearchParams;
2067
+ return (typeof input === "undefined" ? "undefined" : _type_of$1(input)) === 'object' && _instanceof(input, URLSearchParams);
663
2068
  }
664
2069
  /**
665
2070
  * Converts the input
666
2071
  *
667
2072
  * @param input
668
2073
  * @returns
669
- */
670
- function fetchURLQueryKeyValueStringTuples(input) {
671
- const paramTuples = [];
672
- util.forEachInIterable(input, tuple => {
673
- const [key, values] = tuple;
674
- // ignore null/undefined keys and values
675
- if (key != null && values != null) {
676
- const keyString = String(key);
677
- util.useIterableOrValue(values, value => {
678
- // ignore null/undefined values
679
- if (value != null) {
680
- paramTuples.push([keyString, String(value)]);
681
- }
682
- });
683
- }
684
- });
685
- return paramTuples;
2074
+ */ function fetchURLQueryKeyValueStringTuples(input) {
2075
+ var paramTuples = [];
2076
+ util.forEachInIterable(input, function(tuple) {
2077
+ var _tuple = _sliced_to_array(tuple, 2), key = _tuple[0], values = _tuple[1];
2078
+ // ignore null/undefined keys and values
2079
+ if (key != null && values != null) {
2080
+ var keyString = String(key);
2081
+ util.useIterableOrValue(values, function(value) {
2082
+ // ignore null/undefined values
2083
+ if (value != null) {
2084
+ paramTuples.push([
2085
+ keyString,
2086
+ String(value)
2087
+ ]);
2088
+ }
2089
+ });
2090
+ }
2091
+ });
2092
+ return paramTuples;
686
2093
  }
687
2094
  function queryParamsToSearchParams(input) {
688
- let result;
689
- if (isURLSearchParams(input)) {
690
- // by url search params
691
- result = input;
692
- } else if (typeof input === 'string') {
693
- result = new URLSearchParams(input);
694
- } else if (util.isIterable(input)) {
695
- // By tuples
696
- result = new URLSearchParams(fetchURLQueryKeyValueStringTuples(input));
697
- } else {
698
- result = fetchURLSearchParamsObjectToURLSearchParams(input);
699
- }
700
- return result;
2095
+ var result;
2096
+ if (isURLSearchParams(input)) {
2097
+ // by url search params
2098
+ result = input;
2099
+ } else if (typeof input === 'string') {
2100
+ result = new URLSearchParams(input);
2101
+ } else if (util.isIterable(input)) {
2102
+ // By tuples
2103
+ result = new URLSearchParams(fetchURLQueryKeyValueStringTuples(input));
2104
+ } else {
2105
+ result = fetchURLSearchParamsObjectToURLSearchParams(input);
2106
+ }
2107
+ return result;
701
2108
  }
702
2109
  function fetchURLSearchParamsObjectToURLSearchParams(input) {
703
- const paramTuples = [];
704
- util.forEachKeyValue(input, {
705
- forEach: tuple => {
706
- const [key, values] = tuple;
707
- // ignore null/undefined keys and values
708
- if (key != null && values != null) {
709
- const keyString = String(key);
710
- util.useIterableOrValue(values, x => {
711
- // ignore null/undefined values
712
- if (x != null) {
713
- paramTuples.push([keyString, String(x)]);
714
- }
2110
+ var paramTuples = [];
2111
+ util.forEachKeyValue(input, {
2112
+ forEach: function forEach(tuple) {
2113
+ var _tuple = _sliced_to_array(tuple, 2), key = _tuple[0], values = _tuple[1];
2114
+ // ignore null/undefined keys and values
2115
+ if (key != null && values != null) {
2116
+ var keyString = String(key);
2117
+ util.useIterableOrValue(values, function(x) {
2118
+ // ignore null/undefined values
2119
+ if (x != null) {
2120
+ paramTuples.push([
2121
+ keyString,
2122
+ String(x)
2123
+ ]);
2124
+ }
2125
+ });
2126
+ }
2127
+ }
2128
+ });
2129
+ return new URLSearchParams(paramTuples);
2130
+ }
2131
+
2132
+ function _assert_this_initialized(self) {
2133
+ if (self === void 0) {
2134
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
2135
+ }
2136
+ return self;
2137
+ }
2138
+ function _call_super(_this, derived, args) {
2139
+ derived = _get_prototype_of(derived);
2140
+ return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
2141
+ }
2142
+ function _class_call_check(instance, Constructor) {
2143
+ if (!(instance instanceof Constructor)) {
2144
+ throw new TypeError("Cannot call a class as a function");
2145
+ }
2146
+ }
2147
+ function _construct(Parent, args, Class) {
2148
+ if (_is_native_reflect_construct()) {
2149
+ _construct = Reflect.construct;
2150
+ } else {
2151
+ _construct = function construct(Parent, args, Class) {
2152
+ var a = [
2153
+ null
2154
+ ];
2155
+ a.push.apply(a, args);
2156
+ var Constructor = Function.bind.apply(Parent, a);
2157
+ var instance = new Constructor();
2158
+ if (Class) _set_prototype_of(instance, Class.prototype);
2159
+ return instance;
2160
+ };
2161
+ }
2162
+ return _construct.apply(null, arguments);
2163
+ }
2164
+ function _define_property(obj, key, value) {
2165
+ if (key in obj) {
2166
+ Object.defineProperty(obj, key, {
2167
+ value: value,
2168
+ enumerable: true,
2169
+ configurable: true,
2170
+ writable: true
2171
+ });
2172
+ } else {
2173
+ obj[key] = value;
2174
+ }
2175
+ return obj;
2176
+ }
2177
+ function _get_prototype_of(o) {
2178
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
2179
+ return o.__proto__ || Object.getPrototypeOf(o);
2180
+ };
2181
+ return _get_prototype_of(o);
2182
+ }
2183
+ function _inherits(subClass, superClass) {
2184
+ if (typeof superClass !== "function" && superClass !== null) {
2185
+ throw new TypeError("Super expression must either be null or a function");
2186
+ }
2187
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
2188
+ constructor: {
2189
+ value: subClass,
2190
+ writable: true,
2191
+ configurable: true
2192
+ }
2193
+ });
2194
+ if (superClass) _set_prototype_of(subClass, superClass);
2195
+ }
2196
+ function _is_native_function(fn) {
2197
+ return Function.toString.call(fn).indexOf("[native code]") !== -1;
2198
+ }
2199
+ function _object_spread(target) {
2200
+ for(var i = 1; i < arguments.length; i++){
2201
+ var source = arguments[i] != null ? arguments[i] : {};
2202
+ var ownKeys = Object.keys(source);
2203
+ if (typeof Object.getOwnPropertySymbols === "function") {
2204
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
2205
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
2206
+ }));
2207
+ }
2208
+ ownKeys.forEach(function(key) {
2209
+ _define_property(target, key, source[key]);
715
2210
  });
716
- }
717
2211
  }
718
- });
719
- return new URLSearchParams(paramTuples);
2212
+ return target;
720
2213
  }
721
-
722
- class JsonResponseParseError extends Error {
723
- constructor(response) {
724
- super('Failed to parse the JSON body.');
725
- this.response = void 0;
726
- this.response = response;
727
- }
2214
+ function ownKeys(object, enumerableOnly) {
2215
+ var keys = Object.keys(object);
2216
+ if (Object.getOwnPropertySymbols) {
2217
+ var symbols = Object.getOwnPropertySymbols(object);
2218
+ keys.push.apply(keys, symbols);
2219
+ }
2220
+ return keys;
2221
+ }
2222
+ function _object_spread_props(target, source) {
2223
+ source = source != null ? source : {};
2224
+ if (Object.getOwnPropertyDescriptors) {
2225
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
2226
+ } else {
2227
+ ownKeys(Object(source)).forEach(function(key) {
2228
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
2229
+ });
2230
+ }
2231
+ return target;
2232
+ }
2233
+ function _possible_constructor_return(self, call) {
2234
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
2235
+ return call;
2236
+ }
2237
+ return _assert_this_initialized(self);
2238
+ }
2239
+ function _set_prototype_of(o, p) {
2240
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
2241
+ o.__proto__ = p;
2242
+ return o;
2243
+ };
2244
+ return _set_prototype_of(o, p);
2245
+ }
2246
+ function _type_of(obj) {
2247
+ "@swc/helpers - typeof";
2248
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
728
2249
  }
2250
+ function _wrap_native_super(Class) {
2251
+ var _cache = typeof Map === "function" ? new Map() : undefined;
2252
+ _wrap_native_super = function wrapNativeSuper(Class) {
2253
+ if (Class === null || !_is_native_function(Class)) return Class;
2254
+ if (typeof Class !== "function") {
2255
+ throw new TypeError("Super expression must either be null or a function");
2256
+ }
2257
+ if (typeof _cache !== "undefined") {
2258
+ if (_cache.has(Class)) return _cache.get(Class);
2259
+ _cache.set(Class, Wrapper);
2260
+ }
2261
+ function Wrapper() {
2262
+ return _construct(Class, arguments, _get_prototype_of(this).constructor);
2263
+ }
2264
+ Wrapper.prototype = Object.create(Class.prototype, {
2265
+ constructor: {
2266
+ value: Wrapper,
2267
+ enumerable: false,
2268
+ writable: true,
2269
+ configurable: true
2270
+ }
2271
+ });
2272
+ return _set_prototype_of(Wrapper, Class);
2273
+ };
2274
+ return _wrap_native_super(Class);
2275
+ }
2276
+ function _is_native_reflect_construct() {
2277
+ try {
2278
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
2279
+ } catch (_) {}
2280
+ return (_is_native_reflect_construct = function() {
2281
+ return !!result;
2282
+ })();
2283
+ }
2284
+ var JsonResponseParseError = /*#__PURE__*/ function(Error1) {
2285
+ _inherits(JsonResponseParseError, Error1);
2286
+ function JsonResponseParseError(response) {
2287
+ _class_call_check(this, JsonResponseParseError);
2288
+ var _this;
2289
+ _this = _call_super(this, JsonResponseParseError, [
2290
+ 'Failed to parse the JSON body.'
2291
+ ]), _define_property(_this, "response", void 0);
2292
+ _this.response = response;
2293
+ return _this;
2294
+ }
2295
+ return JsonResponseParseError;
2296
+ }(_wrap_native_super(Error));
729
2297
  /**
730
2298
  * Converts the input to a JSON string, or undefined if not provided.
731
2299
  *
732
2300
  * @param body
733
2301
  * @returns
734
- */
735
- function fetchJsonBodyString(body) {
736
- return body != null ? typeof body === 'string' ? body : JSON.stringify(body) : undefined;
2302
+ */ function fetchJsonBodyString(body) {
2303
+ return body != null ? typeof body === 'string' ? body : JSON.stringify(body) : undefined;
737
2304
  }
738
- const throwJsonResponseParseErrorFunction = response => {
739
- throw new JsonResponseParseError(response);
2305
+ var throwJsonResponseParseErrorFunction = function throwJsonResponseParseErrorFunction(response) {
2306
+ throw new JsonResponseParseError(response);
2307
+ };
2308
+ var returnNullHandleFetchJsonParseErrorFunction = function returnNullHandleFetchJsonParseErrorFunction(_) {
2309
+ return null;
740
2310
  };
741
- const returnNullHandleFetchJsonParseErrorFunction = _ => null;
742
2311
  /**
743
2312
  * Creates a FetchJsonFunction from the input ConfiguredFetch.
744
- */
745
- function fetchJsonFunction(fetch, inputConfig) {
746
- let config;
747
- if (typeof inputConfig === 'function') {
748
- config = {
749
- handleFetchJsonParseErrorFunction: inputConfig
750
- };
751
- } else {
752
- config = inputConfig ?? {};
753
- }
754
- config = {
755
- ...config,
756
- handleFetchJsonParseErrorFunction: config.handleFetchJsonParseErrorFunction ?? throwJsonResponseParseErrorFunction
757
- };
758
- const {
759
- handleFetchJsonParseErrorFunction,
760
- interceptJsonResponse
761
- } = config;
762
- const configuredFetchJsonRequestInit = fetchJsonRequestInitFunction(config);
763
- return (url, methodOrInput, body) => {
764
- const requestUrl = fetchURL(url);
765
- const requestInit = configuredFetchJsonRequestInit(methodOrInput, body);
766
- const inputIntercept = typeof methodOrInput === 'object' ? methodOrInput.interceptResponse : undefined;
767
- const responsePromise = fetch(requestUrl, requestInit);
768
- return responsePromise.then(response => {
769
- const jsonPromise = response.json().catch(handleFetchJsonParseErrorFunction);
770
- const interceptedJsonResponsePromise = interceptJsonResponse ? jsonPromise.then(json => interceptJsonResponse(json, response)) : jsonPromise;
771
- return inputIntercept ? interceptedJsonResponsePromise.then(result => inputIntercept(result, response)) : interceptedJsonResponsePromise;
772
- });
773
- };
774
- }
775
- function fetchJsonRequestInitFunction(config = {}) {
776
- const {
777
- defaultMethod = 'GET',
778
- mapFetchJsonInput = util.mapIdentityFunction()
779
- } = config;
780
- return (methodOrInput = defaultMethod, body) => {
781
- let config;
782
- if (methodOrInput === null) {
783
- config = {
784
- method: defaultMethod
785
- };
786
- } else if (typeof methodOrInput === 'string') {
787
- config = {
788
- method: methodOrInput,
789
- body
790
- };
2313
+ */ function fetchJsonFunction(fetch, inputConfig) {
2314
+ var _config_handleFetchJsonParseErrorFunction;
2315
+ var config;
2316
+ if (typeof inputConfig === 'function') {
2317
+ config = {
2318
+ handleFetchJsonParseErrorFunction: inputConfig
2319
+ };
791
2320
  } else {
792
- config = methodOrInput;
2321
+ config = inputConfig !== null && inputConfig !== void 0 ? inputConfig : {};
793
2322
  }
794
- config = mapFetchJsonInput(config);
795
- const requestInit = {
796
- ...config,
797
- method: config.method ?? defaultMethod,
798
- body: fetchJsonBodyString(config.body)
2323
+ config = _object_spread_props(_object_spread({}, config), {
2324
+ handleFetchJsonParseErrorFunction: (_config_handleFetchJsonParseErrorFunction = config.handleFetchJsonParseErrorFunction) !== null && _config_handleFetchJsonParseErrorFunction !== void 0 ? _config_handleFetchJsonParseErrorFunction : throwJsonResponseParseErrorFunction
2325
+ });
2326
+ var handleFetchJsonParseErrorFunction = config.handleFetchJsonParseErrorFunction, interceptJsonResponse = config.interceptJsonResponse;
2327
+ var configuredFetchJsonRequestInit = fetchJsonRequestInitFunction(config);
2328
+ return function(url, methodOrInput, body) {
2329
+ var requestUrl = fetchURL(url);
2330
+ var requestInit = configuredFetchJsonRequestInit(methodOrInput, body);
2331
+ var inputIntercept = (typeof methodOrInput === "undefined" ? "undefined" : _type_of(methodOrInput)) === 'object' ? methodOrInput.interceptResponse : undefined;
2332
+ var responsePromise = fetch(requestUrl, requestInit);
2333
+ return responsePromise.then(function(response) {
2334
+ var jsonPromise = response.json().catch(handleFetchJsonParseErrorFunction);
2335
+ var interceptedJsonResponsePromise = interceptJsonResponse ? jsonPromise.then(function(json) {
2336
+ return interceptJsonResponse(json, response);
2337
+ }) : jsonPromise;
2338
+ return inputIntercept ? interceptedJsonResponsePromise.then(function(result) {
2339
+ return inputIntercept(result, response);
2340
+ }) : interceptedJsonResponsePromise;
2341
+ });
799
2342
  };
800
- return requestInit;
801
- };
802
2343
  }
803
- const fetchJsonRequestInit = fetchJsonRequestInitFunction();
2344
+ function fetchJsonRequestInitFunction() {
2345
+ var config = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
2346
+ var _config_defaultMethod = config.defaultMethod, defaultMethod = _config_defaultMethod === void 0 ? 'GET' : _config_defaultMethod, _config_mapFetchJsonInput = config.mapFetchJsonInput, mapFetchJsonInput = _config_mapFetchJsonInput === void 0 ? util.mapIdentityFunction() : _config_mapFetchJsonInput;
2347
+ return function() {
2348
+ var methodOrInput = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : defaultMethod, body = arguments.length > 1 ? arguments[1] : void 0;
2349
+ var _config_method;
2350
+ var config;
2351
+ if (methodOrInput === null) {
2352
+ config = {
2353
+ method: defaultMethod
2354
+ };
2355
+ } else if (typeof methodOrInput === 'string') {
2356
+ config = {
2357
+ method: methodOrInput,
2358
+ body: body
2359
+ };
2360
+ } else {
2361
+ config = methodOrInput;
2362
+ }
2363
+ config = mapFetchJsonInput(config);
2364
+ var requestInit = _object_spread_props(_object_spread({}, config), {
2365
+ method: (_config_method = config.method) !== null && _config_method !== void 0 ? _config_method : defaultMethod,
2366
+ body: fetchJsonBodyString(config.body)
2367
+ });
2368
+ return requestInit;
2369
+ };
2370
+ }
2371
+ var fetchJsonRequestInit = fetchJsonRequestInitFunction();
804
2372
 
805
2373
  /**
806
2374
  * Default FetchService implementation that uses the native Fetch api.
807
- */
808
- const fetchApiFetchService = fetchService({
809
- makeFetch: fetch,
810
- makeRequest: (x, y) => new Request(x, y)
2375
+ */ var fetchApiFetchService = fetchService({
2376
+ makeFetch: fetch,
2377
+ makeRequest: function makeRequest(x, y) {
2378
+ return new Request(x, y);
2379
+ }
811
2380
  });
812
2381
 
813
2382
  exports.DEFAULT_FETCH_HANDLER = DEFAULT_FETCH_HANDLER;