@dereekb/util 10.2.0 → 11.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fetch/index.cjs.js +223 -145
- package/fetch/package.json +1 -1
- package/index.cjs.js +3919 -2732
- package/index.esm.js +54 -24
- package/package.json +1 -1
- package/src/lib/array/array.d.ts +0 -12
- package/src/lib/date/date.d.ts +8 -1
- package/src/lib/promise/index.d.ts +1 -0
- package/src/lib/promise/promise.factory.d.ts +33 -0
- package/src/lib/value/point.d.ts +1 -1
- package/test/CHANGELOG.md +4 -0
- package/test/package.json +1 -1
- package/test/src/lib/jest.fail.js +3 -3
- package/test/src/lib/jest.fail.js.map +1 -1
- package/test/src/lib/jest.js +8 -7
- package/test/src/lib/jest.js.map +1 -1
- package/test/src/lib/jest.wrap.js +16 -15
- package/test/src/lib/jest.wrap.js.map +1 -1
package/fetch/index.cjs.js
CHANGED
|
@@ -164,8 +164,9 @@ exports.BaseError = BaseError;
|
|
|
164
164
|
*/
|
|
165
165
|
class FetchRequestFactoryError extends makeError.exports.BaseError {
|
|
166
166
|
constructor(error) {
|
|
167
|
-
var
|
|
168
|
-
super(`Fetch request failed to build due to an unexpected error: ${typeof error === 'object' ? (
|
|
167
|
+
var _error$message;
|
|
168
|
+
super(`Fetch request failed to build due to an unexpected error: ${typeof error === 'object' ? (_error$message = error.message) != null ? _error$message : '' : error}`);
|
|
169
|
+
this.error = void 0;
|
|
169
170
|
this.error = error;
|
|
170
171
|
}
|
|
171
172
|
}
|
|
@@ -181,6 +182,7 @@ function fetchOk(inputFetch) {
|
|
|
181
182
|
class FetchResponseError extends makeError.exports.BaseError {
|
|
182
183
|
constructor(response) {
|
|
183
184
|
super(`Fetch response was a non-ok status code (${response.status}): ${response.statusText}`);
|
|
185
|
+
this.response = void 0;
|
|
184
186
|
this.response = response;
|
|
185
187
|
}
|
|
186
188
|
}
|
|
@@ -4834,36 +4836,6 @@ $$1({ global: true, constructor: true, forced: !USE_NATIVE_URL, sham: !DESCRIPTO
|
|
|
4834
4836
|
URL: URLConstructor
|
|
4835
4837
|
});
|
|
4836
4838
|
|
|
4837
|
-
/******************************************************************************
|
|
4838
|
-
Copyright (c) Microsoft Corporation.
|
|
4839
|
-
|
|
4840
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
4841
|
-
purpose with or without fee is hereby granted.
|
|
4842
|
-
|
|
4843
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
4844
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
4845
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
4846
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
4847
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
4848
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
4849
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
4850
|
-
***************************************************************************** */
|
|
4851
|
-
|
|
4852
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
4853
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4854
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4855
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
4856
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
4857
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
4858
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
4859
|
-
});
|
|
4860
|
-
}
|
|
4861
|
-
|
|
4862
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
4863
|
-
var e = new Error(message);
|
|
4864
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
4865
|
-
};
|
|
4866
|
-
|
|
4867
4839
|
var $ = _export;
|
|
4868
4840
|
var NativePromiseConstructor = promiseNativeConstructor;
|
|
4869
4841
|
var fails$1 = fails$g;
|
|
@@ -4909,20 +4881,22 @@ if (isCallable(NativePromiseConstructor)) {
|
|
|
4909
4881
|
class FetchTimeoutError extends makeError.exports.BaseError {
|
|
4910
4882
|
constructor(response, timeout) {
|
|
4911
4883
|
super(`Fetch response was timed out (${timeout})`);
|
|
4884
|
+
this.response = void 0;
|
|
4885
|
+
this.timeout = void 0;
|
|
4912
4886
|
this.response = response;
|
|
4913
4887
|
this.timeout = timeout;
|
|
4914
4888
|
}
|
|
4915
4889
|
}
|
|
4916
4890
|
function fetchTimeout(inputFetch) {
|
|
4917
4891
|
return (input, init) => {
|
|
4918
|
-
var
|
|
4892
|
+
var _init$timeout, _init, _init2;
|
|
4919
4893
|
let controller;
|
|
4920
|
-
const timeout = (
|
|
4894
|
+
const timeout = (_init$timeout = (_init = init) == null ? void 0 : _init.timeout) != null ? _init$timeout : input.timeout;
|
|
4921
4895
|
// if signal is not provided, and a timeout is specified, configure the timeout
|
|
4922
|
-
if (!(
|
|
4896
|
+
if (!((_init2 = init) != null && _init2.signal) && timeout) {
|
|
4923
4897
|
const abortController = new AbortController();
|
|
4924
4898
|
controller = abortController;
|
|
4925
|
-
init = Object.assign(
|
|
4899
|
+
init = Object.assign({}, init, {
|
|
4926
4900
|
signal: abortController.signal // pass the abort signal
|
|
4927
4901
|
});
|
|
4928
4902
|
}
|
|
@@ -4930,7 +4904,8 @@ function fetchTimeout(inputFetch) {
|
|
|
4930
4904
|
let responsePromise = inputFetch(input, init);
|
|
4931
4905
|
if (timeout) {
|
|
4932
4906
|
const timeoutId = setTimeout(() => {
|
|
4933
|
-
|
|
4907
|
+
var _controller;
|
|
4908
|
+
(_controller = controller) == null || _controller.abort();
|
|
4934
4909
|
}, timeout);
|
|
4935
4910
|
responsePromise = responsePromise.finally(() => {
|
|
4936
4911
|
clearTimeout(timeoutId);
|
|
@@ -4946,6 +4921,70 @@ function fetchTimeout(inputFetch) {
|
|
|
4946
4921
|
* @param config
|
|
4947
4922
|
* @returns
|
|
4948
4923
|
*/
|
|
4924
|
+
|
|
4925
|
+
function _await$1(value, then, direct) {
|
|
4926
|
+
if (direct) {
|
|
4927
|
+
return then ? then(value) : value;
|
|
4928
|
+
}
|
|
4929
|
+
if (!value || !value.then) {
|
|
4930
|
+
value = Promise.resolve(value);
|
|
4931
|
+
}
|
|
4932
|
+
return then ? value.then(then) : value;
|
|
4933
|
+
} /**
|
|
4934
|
+
* Creates a function that wraps fetch and uses a FetchRequestFactory to generate a Request before invoking Fetch.
|
|
4935
|
+
*
|
|
4936
|
+
* @param config
|
|
4937
|
+
* @returns
|
|
4938
|
+
*/
|
|
4939
|
+
|
|
4940
|
+
function _async$1(f) {
|
|
4941
|
+
return function () {
|
|
4942
|
+
for (var args = [], i = 0; i < arguments.length; i++) {
|
|
4943
|
+
args[i] = arguments[i];
|
|
4944
|
+
}
|
|
4945
|
+
try {
|
|
4946
|
+
return Promise.resolve(f.apply(this, args));
|
|
4947
|
+
} catch (e) {
|
|
4948
|
+
return Promise.reject(e);
|
|
4949
|
+
}
|
|
4950
|
+
};
|
|
4951
|
+
}
|
|
4952
|
+
function _empty() {}
|
|
4953
|
+
function _invokeIgnored(body) {
|
|
4954
|
+
var result = body();
|
|
4955
|
+
if (result && result.then) {
|
|
4956
|
+
return result.then(_empty);
|
|
4957
|
+
}
|
|
4958
|
+
}
|
|
4959
|
+
function _invoke(body, then) {
|
|
4960
|
+
var result = body();
|
|
4961
|
+
if (result && result.then) {
|
|
4962
|
+
return result.then(then);
|
|
4963
|
+
}
|
|
4964
|
+
return then(result);
|
|
4965
|
+
}
|
|
4966
|
+
function _call(body, then, direct) {
|
|
4967
|
+
if (direct) {
|
|
4968
|
+
return then ? then(body()) : body();
|
|
4969
|
+
}
|
|
4970
|
+
try {
|
|
4971
|
+
var result = Promise.resolve(body());
|
|
4972
|
+
return then ? result.then(then) : result;
|
|
4973
|
+
} catch (e) {
|
|
4974
|
+
return Promise.reject(e);
|
|
4975
|
+
}
|
|
4976
|
+
}
|
|
4977
|
+
function _catch(body, recover) {
|
|
4978
|
+
try {
|
|
4979
|
+
var result = body();
|
|
4980
|
+
} catch (e) {
|
|
4981
|
+
return recover(e);
|
|
4982
|
+
}
|
|
4983
|
+
if (result && result.then) {
|
|
4984
|
+
return result.then(void 0, recover);
|
|
4985
|
+
}
|
|
4986
|
+
return result;
|
|
4987
|
+
}
|
|
4949
4988
|
function fetchService(config) {
|
|
4950
4989
|
const {
|
|
4951
4990
|
makeFetch: inputMakeFetch,
|
|
@@ -4966,12 +5005,6 @@ function fetchService(config) {
|
|
|
4966
5005
|
};
|
|
4967
5006
|
return factory;
|
|
4968
5007
|
}
|
|
4969
|
-
/**
|
|
4970
|
-
* Creates a function that wraps fetch and uses a FetchRequestFactory to generate a Request before invoking Fetch.
|
|
4971
|
-
*
|
|
4972
|
-
* @param config
|
|
4973
|
-
* @returns
|
|
4974
|
-
*/
|
|
4975
5008
|
function configureFetch(config) {
|
|
4976
5009
|
const {
|
|
4977
5010
|
makeFetch: inputMakeFetch = fetch,
|
|
@@ -4989,16 +5022,27 @@ function configureFetch(config) {
|
|
|
4989
5022
|
makeFetch = fetchOk(makeFetch);
|
|
4990
5023
|
}
|
|
4991
5024
|
const makeFetchRequest = fetchRequestFactory(config);
|
|
4992
|
-
return (input, init)
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
5025
|
+
return _async$1(function (input, init) {
|
|
5026
|
+
return _await$1(makeFetchRequest(input, init), function (request) {
|
|
5027
|
+
let response = makeFetch(request);
|
|
5028
|
+
if (mapResponse) {
|
|
5029
|
+
response = mapResponse(response);
|
|
5030
|
+
}
|
|
5031
|
+
return response;
|
|
5032
|
+
});
|
|
4999
5033
|
});
|
|
5000
5034
|
}
|
|
5001
5035
|
function fetchRequestFactory(config) {
|
|
5036
|
+
const asFetchRequest = _async$1(function (input) {
|
|
5037
|
+
const _isPromiseLike = util.isPromiseLike(input);
|
|
5038
|
+
return _await$1(input, function (awaitedInput) {
|
|
5039
|
+
if (isFetchRequest(awaitedInput)) {
|
|
5040
|
+
return awaitedInput;
|
|
5041
|
+
} else {
|
|
5042
|
+
return makeRequest(awaitedInput);
|
|
5043
|
+
}
|
|
5044
|
+
}, !_isPromiseLike);
|
|
5045
|
+
});
|
|
5002
5046
|
const {
|
|
5003
5047
|
makeRequest = (input, init) => new Request(input, init),
|
|
5004
5048
|
baseUrl: inputBaseUrl,
|
|
@@ -5014,60 +5058,62 @@ function fetchRequestFactory(config) {
|
|
|
5014
5058
|
const result = new URL(urlPath, baseUrl);
|
|
5015
5059
|
return result;
|
|
5016
5060
|
} : undefined;
|
|
5017
|
-
function
|
|
5018
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
5019
|
-
const awaitedInput = util.isPromiseLike(input) ? yield input : input;
|
|
5020
|
-
if (isFetchRequest(awaitedInput)) {
|
|
5021
|
-
return awaitedInput;
|
|
5022
|
-
} else {
|
|
5023
|
-
return makeRequest(awaitedInput);
|
|
5024
|
-
}
|
|
5025
|
-
});
|
|
5026
|
-
}
|
|
5027
|
-
const buildRequestWithFixedUrl = buildUrl ? input => __awaiter(this, void 0, void 0, function* () {
|
|
5061
|
+
const buildRequestWithFixedUrl = buildUrl ? _async$1(function (input) {
|
|
5028
5062
|
let relativeUrl;
|
|
5029
5063
|
let baseRequest;
|
|
5030
5064
|
let request;
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
|
|
5045
|
-
|
|
5046
|
-
|
|
5047
|
-
|
|
5065
|
+
return _invoke(function () {
|
|
5066
|
+
if (typeof input === 'string') {
|
|
5067
|
+
relativeUrl = input;
|
|
5068
|
+
} else return _invokeIgnored(function () {
|
|
5069
|
+
if (isFetchRequest(input)) {
|
|
5070
|
+
if (useBaseUrlForConfiguredFetchRequests) {
|
|
5071
|
+
relativeUrl = input.url; // copy the url, and use it as the base.
|
|
5072
|
+
baseRequest = input;
|
|
5073
|
+
} else {
|
|
5074
|
+
request = input;
|
|
5075
|
+
}
|
|
5076
|
+
} else {
|
|
5077
|
+
return _await$1(makeRequest(input), function (_makeRequest) {
|
|
5078
|
+
request = _makeRequest;
|
|
5079
|
+
});
|
|
5080
|
+
}
|
|
5081
|
+
});
|
|
5082
|
+
}, function () {
|
|
5083
|
+
return _invoke(function () {
|
|
5084
|
+
if (!request) {
|
|
5085
|
+
const url = buildUrl(relativeUrl);
|
|
5086
|
+
return _await$1(makeRequest(url.href, baseRequest), function (_makeRequest2) {
|
|
5087
|
+
request = _makeRequest2;
|
|
5088
|
+
});
|
|
5089
|
+
}
|
|
5090
|
+
}, function () {
|
|
5091
|
+
return request;
|
|
5092
|
+
});
|
|
5093
|
+
});
|
|
5048
5094
|
}) : asFetchRequest;
|
|
5049
5095
|
let buildRequestInit;
|
|
5050
5096
|
if (inputBaseRequest != null || timeout != null) {
|
|
5051
|
-
const
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5097
|
+
const combineRequestInits = function combineRequestInits(request, requestInit) {
|
|
5098
|
+
return _call(computeBaseRequest, function (baseRequest) {
|
|
5099
|
+
return _await$1(requestInit, function (_requestInit) {
|
|
5100
|
+
const merged = mergeRequestInits(baseRequest, _requestInit);
|
|
5101
|
+
const timeout = merged.timeout === undefined ? request.timeout : merged.timeout;
|
|
5102
|
+
return Object.assign({}, merged, {
|
|
5103
|
+
timeout
|
|
5104
|
+
});
|
|
5105
|
+
});
|
|
5106
|
+
});
|
|
5107
|
+
};
|
|
5108
|
+
const computeBaseRequest = function computeBaseRequest() {
|
|
5109
|
+
return _call(inputBaseRequestAsGetter, function (computedBaseRequest) {
|
|
5110
|
+
const baseRequest = timeout ? Object.assign({}, computedBaseRequest, {
|
|
5056
5111
|
timeout
|
|
5057
5112
|
}) : computedBaseRequest;
|
|
5058
5113
|
return baseRequest;
|
|
5059
5114
|
});
|
|
5060
|
-
}
|
|
5061
|
-
|
|
5062
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
5063
|
-
const baseRequest = yield computeBaseRequest();
|
|
5064
|
-
const merged = mergeRequestInits(baseRequest, yield requestInit);
|
|
5065
|
-
const timeout = merged.timeout === undefined ? request.timeout : merged.timeout;
|
|
5066
|
-
return Object.assign(Object.assign({}, merged), {
|
|
5067
|
-
timeout
|
|
5068
|
-
});
|
|
5069
|
-
});
|
|
5070
|
-
}
|
|
5115
|
+
};
|
|
5116
|
+
const inputBaseRequestAsGetter = util.asGetter(inputBaseRequest);
|
|
5071
5117
|
if (requestInitFactory) {
|
|
5072
5118
|
buildRequestInit = (req, x) => requestInitFactory(req, combineRequestInits(req, x));
|
|
5073
5119
|
} else {
|
|
@@ -5078,26 +5124,30 @@ function fetchRequestFactory(config) {
|
|
|
5078
5124
|
} else {
|
|
5079
5125
|
buildRequestInit = (_, x) => x;
|
|
5080
5126
|
}
|
|
5081
|
-
return (input, init)
|
|
5082
|
-
|
|
5083
|
-
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
|
|
5127
|
+
return _async$1(function (input, init) {
|
|
5128
|
+
return _catch(function () {
|
|
5129
|
+
return _await$1(buildRequestWithFixedUrl(input), function (fixedRequest) {
|
|
5130
|
+
return _await$1(buildRequestInit(fixedRequest, init), function (_buildRequestInit) {
|
|
5131
|
+
init = _buildRequestInit;
|
|
5132
|
+
return _await$1(makeRequest(fixedRequest, init), function (request) {
|
|
5133
|
+
request.timeout = timeout; // copy/set timeout on the request directly
|
|
5134
|
+
return request;
|
|
5135
|
+
});
|
|
5136
|
+
});
|
|
5137
|
+
});
|
|
5138
|
+
}, function (e) {
|
|
5089
5139
|
if (e instanceof FetchRequestFactoryError) {
|
|
5090
5140
|
throw e;
|
|
5091
5141
|
} else {
|
|
5092
5142
|
throw new FetchRequestFactoryError(e);
|
|
5093
5143
|
}
|
|
5094
|
-
}
|
|
5144
|
+
});
|
|
5095
5145
|
});
|
|
5096
5146
|
}
|
|
5097
5147
|
function mergeRequestInits(base, requestInit) {
|
|
5098
5148
|
if (requestInit) {
|
|
5099
|
-
const headers = mergeRequestHeaders([base.headers, requestInit
|
|
5100
|
-
return Object.assign(
|
|
5149
|
+
const headers = mergeRequestHeaders([base.headers, requestInit == null ? void 0 : requestInit.headers]);
|
|
5150
|
+
return Object.assign({}, base, requestInit, {
|
|
5101
5151
|
headers
|
|
5102
5152
|
});
|
|
5103
5153
|
} else {
|
|
@@ -5141,15 +5191,39 @@ function isFetchRequest(input) {
|
|
|
5141
5191
|
return Boolean(input.url);
|
|
5142
5192
|
}
|
|
5143
5193
|
|
|
5194
|
+
function _await(value, then, direct) {
|
|
5195
|
+
if (direct) {
|
|
5196
|
+
return then ? then(value) : value;
|
|
5197
|
+
}
|
|
5198
|
+
if (!value || !value.then) {
|
|
5199
|
+
value = Promise.resolve(value);
|
|
5200
|
+
}
|
|
5201
|
+
return then ? value.then(then) : value;
|
|
5202
|
+
}
|
|
5203
|
+
function _async(f) {
|
|
5204
|
+
return function () {
|
|
5205
|
+
for (var args = [], i = 0; i < arguments.length; i++) {
|
|
5206
|
+
args[i] = arguments[i];
|
|
5207
|
+
}
|
|
5208
|
+
try {
|
|
5209
|
+
return Promise.resolve(f.apply(this, args));
|
|
5210
|
+
} catch (e) {
|
|
5211
|
+
return Promise.reject(e);
|
|
5212
|
+
}
|
|
5213
|
+
};
|
|
5214
|
+
}
|
|
5144
5215
|
class FetchPageNoNextPageError extends FetchRequestFactoryError {
|
|
5145
5216
|
constructor(page) {
|
|
5146
5217
|
super(`There was no next page for this.`);
|
|
5218
|
+
this.page = void 0;
|
|
5147
5219
|
this.page = page;
|
|
5148
5220
|
}
|
|
5149
5221
|
}
|
|
5150
5222
|
class FetchPageLimitReachedError extends FetchRequestFactoryError {
|
|
5151
5223
|
constructor(page, limit) {
|
|
5152
5224
|
super(`The limit of ${limit} for the number of pages to read was reached.`);
|
|
5225
|
+
this.page = void 0;
|
|
5226
|
+
this.limit = void 0;
|
|
5153
5227
|
this.page = page;
|
|
5154
5228
|
this.limit = limit;
|
|
5155
5229
|
}
|
|
@@ -5174,40 +5248,43 @@ function fetchPageFactory(config) {
|
|
|
5174
5248
|
return (initalInput, options) => {
|
|
5175
5249
|
const {
|
|
5176
5250
|
maxPage: inputMaxPage = defaultMaxPage
|
|
5177
|
-
} = options
|
|
5178
|
-
const maxPage = inputMaxPage === null ? Number.MAX_SAFE_INTEGER : inputMaxPage
|
|
5251
|
+
} = options != null ? options : {};
|
|
5252
|
+
const maxPage = inputMaxPage === null ? Number.MAX_SAFE_INTEGER : inputMaxPage != null ? inputMaxPage : FETCH_PAGE_FACTORY_DEFAULT_MAX_PAGE;
|
|
5179
5253
|
function fetchNextWithInput(input, previous = undefined) {
|
|
5180
|
-
return (
|
|
5181
|
-
|
|
5182
|
-
|
|
5183
|
-
|
|
5184
|
-
|
|
5185
|
-
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
|
|
5195
|
-
|
|
5196
|
-
|
|
5197
|
-
|
|
5198
|
-
|
|
5199
|
-
|
|
5200
|
-
|
|
5201
|
-
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
|
|
5205
|
-
|
|
5206
|
-
|
|
5207
|
-
|
|
5208
|
-
|
|
5209
|
-
|
|
5210
|
-
|
|
5254
|
+
return _async(function () {
|
|
5255
|
+
return _await(fetch(input), function (result) {
|
|
5256
|
+
return _await(readFetchPageResultInfo(result), function ({
|
|
5257
|
+
cursor,
|
|
5258
|
+
hasNext: readHasNext
|
|
5259
|
+
}) {
|
|
5260
|
+
const hasNext = readHasNext !== false;
|
|
5261
|
+
const page = previous ? previous.page + 1 : util.FIRST_PAGE;
|
|
5262
|
+
const isAtMaxPage = page >= maxPage;
|
|
5263
|
+
const nextPageResult = {
|
|
5264
|
+
input,
|
|
5265
|
+
result,
|
|
5266
|
+
page,
|
|
5267
|
+
previous,
|
|
5268
|
+
hasNext,
|
|
5269
|
+
isAtMaxPage,
|
|
5270
|
+
cursor,
|
|
5271
|
+
fetchNext: util.cachedGetter(_async(function () {
|
|
5272
|
+
// assert max page
|
|
5273
|
+
if (isAtMaxPage) {
|
|
5274
|
+
throw new FetchPageLimitReachedError(nextPageResult, maxPage);
|
|
5275
|
+
}
|
|
5276
|
+
// assert next page
|
|
5277
|
+
return _await(hasNext ? buildInputForNextPage(nextPageResult, input) : undefined, function (nextPageInfo) {
|
|
5278
|
+
if (!nextPageInfo) {
|
|
5279
|
+
throw new FetchPageNoNextPageError(nextPageResult);
|
|
5280
|
+
}
|
|
5281
|
+
return fetchNextWithInput(Object.assign({}, input, nextPageInfo), nextPageResult)();
|
|
5282
|
+
}, !hasNext);
|
|
5283
|
+
}))
|
|
5284
|
+
};
|
|
5285
|
+
return nextPageResult;
|
|
5286
|
+
});
|
|
5287
|
+
});
|
|
5211
5288
|
});
|
|
5212
5289
|
}
|
|
5213
5290
|
const page = {
|
|
@@ -5363,6 +5440,7 @@ function fetchURLSearchParamsObjectToURLSearchParams(input) {
|
|
|
5363
5440
|
class JsonResponseParseError extends Error {
|
|
5364
5441
|
constructor(response) {
|
|
5365
5442
|
super('Failed to parse the JSON body.');
|
|
5443
|
+
this.response = void 0;
|
|
5366
5444
|
this.response = response;
|
|
5367
5445
|
}
|
|
5368
5446
|
}
|
|
@@ -5383,17 +5461,17 @@ const returnNullHandleFetchJsonParseErrorFunction = response => null;
|
|
|
5383
5461
|
* Creates a FetchJsonFunction from the input ConfiguredFetch.
|
|
5384
5462
|
*/
|
|
5385
5463
|
function fetchJsonFunction(fetch, inputConfig) {
|
|
5386
|
-
var
|
|
5464
|
+
var _config$handleFetchJs;
|
|
5387
5465
|
let config;
|
|
5388
5466
|
if (typeof inputConfig === 'function') {
|
|
5389
5467
|
config = {
|
|
5390
5468
|
handleFetchJsonParseErrorFunction: inputConfig
|
|
5391
5469
|
};
|
|
5392
5470
|
} else {
|
|
5393
|
-
config = inputConfig
|
|
5471
|
+
config = inputConfig != null ? inputConfig : {};
|
|
5394
5472
|
}
|
|
5395
|
-
config = Object.assign(
|
|
5396
|
-
handleFetchJsonParseErrorFunction: (
|
|
5473
|
+
config = Object.assign({}, config, {
|
|
5474
|
+
handleFetchJsonParseErrorFunction: (_config$handleFetchJs = config.handleFetchJsonParseErrorFunction) != null ? _config$handleFetchJs : throwJsonResponseParseErrorFunction
|
|
5397
5475
|
});
|
|
5398
5476
|
const {
|
|
5399
5477
|
handleFetchJsonParseErrorFunction,
|
|
@@ -5418,7 +5496,7 @@ function fetchJsonRequestInitFunction(config = {}) {
|
|
|
5418
5496
|
mapFetchJsonInput = util.mapIdentityFunction()
|
|
5419
5497
|
} = config;
|
|
5420
5498
|
return (methodOrInput = defaultMethod, body) => {
|
|
5421
|
-
var
|
|
5499
|
+
var _config$method;
|
|
5422
5500
|
let config;
|
|
5423
5501
|
if (methodOrInput === null) {
|
|
5424
5502
|
config = {
|
|
@@ -5433,8 +5511,8 @@ function fetchJsonRequestInitFunction(config = {}) {
|
|
|
5433
5511
|
config = methodOrInput;
|
|
5434
5512
|
}
|
|
5435
5513
|
config = mapFetchJsonInput(config);
|
|
5436
|
-
const requestInit = Object.assign(
|
|
5437
|
-
method: (
|
|
5514
|
+
const requestInit = Object.assign({}, config, {
|
|
5515
|
+
method: (_config$method = config.method) != null ? _config$method : defaultMethod,
|
|
5438
5516
|
body: fetchJsonBodyString(config.body)
|
|
5439
5517
|
});
|
|
5440
5518
|
return requestInit;
|