hook-fetch 0.0.2-beta → 0.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.
package/dist/es/index.js CHANGED
@@ -6,7 +6,7 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
6
6
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
7
7
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
8
8
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
9
- var _message, _name, _status, _statusText, _response, _config, _plugins, _controller, _config2, _promise, _isTimeout, _HookFetch_instances, init_fn, createNormalizeError_fn, normalizeError_fn, json_get, response_get, _timeout, _baseURL, _commonHeaders, _queue, _plugins2, _withCredentials, _Base_instances, requestWithParams_fn, requestWithBody_fn;
9
+ var _message, _name, _status, _statusText, _response, _config, _plugins, _controller, _config2, _promise, _isTimeout, _executor, _finallyCallbacks, _responseType, _fullOptions, _HookFetch_instances, init_fn, createNormalizeError_fn, normalizeError_fn, json_get, getExecutor_get, resolve_fn, response_get, _timeout, _baseURL, _commonHeaders, _queue, _plugins2, _withCredentials, _Base_instances, requestWithParams_fn, requestWithBody_fn;
10
10
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
11
11
  function getDefaultExportFromCjs(x) {
12
12
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
@@ -118,8 +118,8 @@ function requireObjectInspect() {
118
118
  "double": /(["\\])/g,
119
119
  single: /(['\\])/g
120
120
  };
121
- objectInspect = function inspect_(obj, options, depth, seen) {
122
- var opts = options || {};
121
+ objectInspect = function inspect_(obj, options2, depth, seen) {
122
+ var opts = options2 || {};
123
123
  if (has(opts, "quoteStyle") && !has(quotes, opts.quoteStyle)) {
124
124
  throw new TypeError('option "quoteStyle" must be "single" or "double"');
125
125
  }
@@ -1077,10 +1077,10 @@ function requireCallBindApplyHelpers() {
1077
1077
  };
1078
1078
  return callBindApplyHelpers;
1079
1079
  }
1080
- var get;
1080
+ var get$1;
1081
1081
  var hasRequiredGet;
1082
1082
  function requireGet() {
1083
- if (hasRequiredGet) return get;
1083
+ if (hasRequiredGet) return get$1;
1084
1084
  hasRequiredGet = 1;
1085
1085
  var callBind = requireCallBindApplyHelpers();
1086
1086
  var gOPD2 = /* @__PURE__ */ requireGopd();
@@ -1100,13 +1100,13 @@ function requireGet() {
1100
1100
  );
1101
1101
  var $Object = Object;
1102
1102
  var $getPrototypeOf = $Object.getPrototypeOf;
1103
- get = desc && typeof desc.get === "function" ? callBind([desc.get]) : typeof $getPrototypeOf === "function" ? (
1103
+ get$1 = desc && typeof desc.get === "function" ? callBind([desc.get]) : typeof $getPrototypeOf === "function" ? (
1104
1104
  /** @type {import('./get')} */
1105
1105
  function getDunder(value) {
1106
1106
  return $getPrototypeOf(value == null ? value : $Object(value));
1107
1107
  }
1108
1108
  ) : false;
1109
- return get;
1109
+ return get$1;
1110
1110
  }
1111
1111
  var getProto;
1112
1112
  var hasRequiredGetProto;
@@ -1716,8 +1716,8 @@ function requireUtils() {
1716
1716
  }
1717
1717
  }
1718
1718
  };
1719
- var arrayToObject = function arrayToObject2(source, options) {
1720
- var obj = options && options.plainObjects ? { __proto__: null } : {};
1719
+ var arrayToObject = function arrayToObject2(source, options2) {
1720
+ var obj = options2 && options2.plainObjects ? { __proto__: null } : {};
1721
1721
  for (var i = 0; i < source.length; ++i) {
1722
1722
  if (typeof source[i] !== "undefined") {
1723
1723
  obj[i] = source[i];
@@ -1725,7 +1725,7 @@ function requireUtils() {
1725
1725
  }
1726
1726
  return obj;
1727
1727
  };
1728
- var merge = function merge2(target, source, options) {
1728
+ var merge = function merge2(target, source, options2) {
1729
1729
  if (!source) {
1730
1730
  return target;
1731
1731
  }
@@ -1733,7 +1733,7 @@ function requireUtils() {
1733
1733
  if (isArray(target)) {
1734
1734
  target.push(source);
1735
1735
  } else if (target && typeof target === "object") {
1736
- if (options && (options.plainObjects || options.allowPrototypes) || !has.call(Object.prototype, source)) {
1736
+ if (options2 && (options2.plainObjects || options2.allowPrototypes) || !has.call(Object.prototype, source)) {
1737
1737
  target[source] = true;
1738
1738
  }
1739
1739
  } else {
@@ -1746,14 +1746,14 @@ function requireUtils() {
1746
1746
  }
1747
1747
  var mergeTarget = target;
1748
1748
  if (isArray(target) && !isArray(source)) {
1749
- mergeTarget = arrayToObject(target, options);
1749
+ mergeTarget = arrayToObject(target, options2);
1750
1750
  }
1751
1751
  if (isArray(target) && isArray(source)) {
1752
1752
  source.forEach(function(item, i) {
1753
1753
  if (has.call(target, i)) {
1754
1754
  var targetItem = target[i];
1755
1755
  if (targetItem && typeof targetItem === "object" && item && typeof item === "object") {
1756
- target[i] = merge2(targetItem, item, options);
1756
+ target[i] = merge2(targetItem, item, options2);
1757
1757
  } else {
1758
1758
  target.push(item);
1759
1759
  }
@@ -1766,7 +1766,7 @@ function requireUtils() {
1766
1766
  return Object.keys(source).reduce(function(acc, key) {
1767
1767
  var value = source[key];
1768
1768
  if (has.call(acc, key)) {
1769
- acc[key] = merge2(acc[key], value, options);
1769
+ acc[key] = merge2(acc[key], value, options2);
1770
1770
  } else {
1771
1771
  acc[key] = value;
1772
1772
  }
@@ -2111,33 +2111,33 @@ function requireStringify() {
2111
2111
  };
2112
2112
  stringify_1 = function(object, opts) {
2113
2113
  var obj = object;
2114
- var options = normalizeStringifyOptions(opts);
2114
+ var options2 = normalizeStringifyOptions(opts);
2115
2115
  var objKeys;
2116
2116
  var filter;
2117
- if (typeof options.filter === "function") {
2118
- filter = options.filter;
2117
+ if (typeof options2.filter === "function") {
2118
+ filter = options2.filter;
2119
2119
  obj = filter("", obj);
2120
- } else if (isArray(options.filter)) {
2121
- filter = options.filter;
2120
+ } else if (isArray(options2.filter)) {
2121
+ filter = options2.filter;
2122
2122
  objKeys = filter;
2123
2123
  }
2124
2124
  var keys = [];
2125
2125
  if (typeof obj !== "object" || obj === null) {
2126
2126
  return "";
2127
2127
  }
2128
- var generateArrayPrefix = arrayPrefixGenerators[options.arrayFormat];
2129
- var commaRoundTrip = generateArrayPrefix === "comma" && options.commaRoundTrip;
2128
+ var generateArrayPrefix = arrayPrefixGenerators[options2.arrayFormat];
2129
+ var commaRoundTrip = generateArrayPrefix === "comma" && options2.commaRoundTrip;
2130
2130
  if (!objKeys) {
2131
2131
  objKeys = Object.keys(obj);
2132
2132
  }
2133
- if (options.sort) {
2134
- objKeys.sort(options.sort);
2133
+ if (options2.sort) {
2134
+ objKeys.sort(options2.sort);
2135
2135
  }
2136
2136
  var sideChannel2 = getSideChannel();
2137
2137
  for (var i = 0; i < objKeys.length; ++i) {
2138
2138
  var key = objKeys[i];
2139
2139
  var value = obj[key];
2140
- if (options.skipNulls && value === null) {
2140
+ if (options2.skipNulls && value === null) {
2141
2141
  continue;
2142
2142
  }
2143
2143
  pushToArray(keys, stringify(
@@ -2145,26 +2145,26 @@ function requireStringify() {
2145
2145
  key,
2146
2146
  generateArrayPrefix,
2147
2147
  commaRoundTrip,
2148
- options.allowEmptyArrays,
2149
- options.strictNullHandling,
2150
- options.skipNulls,
2151
- options.encodeDotInKeys,
2152
- options.encode ? options.encoder : null,
2153
- options.filter,
2154
- options.sort,
2155
- options.allowDots,
2156
- options.serializeDate,
2157
- options.format,
2158
- options.formatter,
2159
- options.encodeValuesOnly,
2160
- options.charset,
2148
+ options2.allowEmptyArrays,
2149
+ options2.strictNullHandling,
2150
+ options2.skipNulls,
2151
+ options2.encodeDotInKeys,
2152
+ options2.encode ? options2.encoder : null,
2153
+ options2.filter,
2154
+ options2.sort,
2155
+ options2.allowDots,
2156
+ options2.serializeDate,
2157
+ options2.format,
2158
+ options2.formatter,
2159
+ options2.encodeValuesOnly,
2160
+ options2.charset,
2161
2161
  sideChannel2
2162
2162
  ));
2163
2163
  }
2164
- var joined = keys.join(options.delimiter);
2165
- var prefix = options.addQueryPrefix === true ? "?" : "";
2166
- if (options.charsetSentinel) {
2167
- if (options.charset === "iso-8859-1") {
2164
+ var joined = keys.join(options2.delimiter);
2165
+ var prefix = options2.addQueryPrefix === true ? "?" : "";
2166
+ if (options2.charsetSentinel) {
2167
+ if (options2.charset === "iso-8859-1") {
2168
2168
  prefix += "utf8=%26%2310003%3B&";
2169
2169
  } else {
2170
2170
  prefix += "utf8=%E2%9C%93&";
@@ -2210,33 +2210,33 @@ function requireParse() {
2210
2210
  return String.fromCharCode(parseInt(numberStr, 10));
2211
2211
  });
2212
2212
  };
2213
- var parseArrayValue = function(val, options, currentArrayLength) {
2214
- if (val && typeof val === "string" && options.comma && val.indexOf(",") > -1) {
2213
+ var parseArrayValue = function(val, options2, currentArrayLength) {
2214
+ if (val && typeof val === "string" && options2.comma && val.indexOf(",") > -1) {
2215
2215
  return val.split(",");
2216
2216
  }
2217
- if (options.throwOnLimitExceeded && currentArrayLength >= options.arrayLimit) {
2218
- throw new RangeError("Array limit exceeded. Only " + options.arrayLimit + " element" + (options.arrayLimit === 1 ? "" : "s") + " allowed in an array.");
2217
+ if (options2.throwOnLimitExceeded && currentArrayLength >= options2.arrayLimit) {
2218
+ throw new RangeError("Array limit exceeded. Only " + options2.arrayLimit + " element" + (options2.arrayLimit === 1 ? "" : "s") + " allowed in an array.");
2219
2219
  }
2220
2220
  return val;
2221
2221
  };
2222
2222
  var isoSentinel = "utf8=%26%2310003%3B";
2223
2223
  var charsetSentinel = "utf8=%E2%9C%93";
2224
- var parseValues = function parseQueryStringValues(str, options) {
2224
+ var parseValues = function parseQueryStringValues(str, options2) {
2225
2225
  var obj = { __proto__: null };
2226
- var cleanStr = options.ignoreQueryPrefix ? str.replace(/^\?/, "") : str;
2226
+ var cleanStr = options2.ignoreQueryPrefix ? str.replace(/^\?/, "") : str;
2227
2227
  cleanStr = cleanStr.replace(/%5B/gi, "[").replace(/%5D/gi, "]");
2228
- var limit = options.parameterLimit === Infinity ? void 0 : options.parameterLimit;
2228
+ var limit = options2.parameterLimit === Infinity ? void 0 : options2.parameterLimit;
2229
2229
  var parts = cleanStr.split(
2230
- options.delimiter,
2231
- options.throwOnLimitExceeded ? limit + 1 : limit
2230
+ options2.delimiter,
2231
+ options2.throwOnLimitExceeded ? limit + 1 : limit
2232
2232
  );
2233
- if (options.throwOnLimitExceeded && parts.length > limit) {
2233
+ if (options2.throwOnLimitExceeded && parts.length > limit) {
2234
2234
  throw new RangeError("Parameter limit exceeded. Only " + limit + " parameter" + (limit === 1 ? "" : "s") + " allowed.");
2235
2235
  }
2236
2236
  var skipIndex = -1;
2237
2237
  var i;
2238
- var charset = options.charset;
2239
- if (options.charsetSentinel) {
2238
+ var charset = options2.charset;
2239
+ if (options2.charsetSentinel) {
2240
2240
  for (i = 0; i < parts.length; ++i) {
2241
2241
  if (parts[i].indexOf("utf8=") === 0) {
2242
2242
  if (parts[i] === charsetSentinel) {
@@ -2259,56 +2259,56 @@ function requireParse() {
2259
2259
  var key;
2260
2260
  var val;
2261
2261
  if (pos === -1) {
2262
- key = options.decoder(part, defaults.decoder, charset, "key");
2263
- val = options.strictNullHandling ? null : "";
2262
+ key = options2.decoder(part, defaults.decoder, charset, "key");
2263
+ val = options2.strictNullHandling ? null : "";
2264
2264
  } else {
2265
- key = options.decoder(part.slice(0, pos), defaults.decoder, charset, "key");
2265
+ key = options2.decoder(part.slice(0, pos), defaults.decoder, charset, "key");
2266
2266
  val = utils2.maybeMap(
2267
2267
  parseArrayValue(
2268
2268
  part.slice(pos + 1),
2269
- options,
2269
+ options2,
2270
2270
  isArray(obj[key]) ? obj[key].length : 0
2271
2271
  ),
2272
2272
  function(encodedVal) {
2273
- return options.decoder(encodedVal, defaults.decoder, charset, "value");
2273
+ return options2.decoder(encodedVal, defaults.decoder, charset, "value");
2274
2274
  }
2275
2275
  );
2276
2276
  }
2277
- if (val && options.interpretNumericEntities && charset === "iso-8859-1") {
2277
+ if (val && options2.interpretNumericEntities && charset === "iso-8859-1") {
2278
2278
  val = interpretNumericEntities(String(val));
2279
2279
  }
2280
2280
  if (part.indexOf("[]=") > -1) {
2281
2281
  val = isArray(val) ? [val] : val;
2282
2282
  }
2283
2283
  var existing = has.call(obj, key);
2284
- if (existing && options.duplicates === "combine") {
2284
+ if (existing && options2.duplicates === "combine") {
2285
2285
  obj[key] = utils2.combine(obj[key], val);
2286
- } else if (!existing || options.duplicates === "last") {
2286
+ } else if (!existing || options2.duplicates === "last") {
2287
2287
  obj[key] = val;
2288
2288
  }
2289
2289
  }
2290
2290
  return obj;
2291
2291
  };
2292
- var parseObject = function(chain, val, options, valuesParsed) {
2292
+ var parseObject = function(chain, val, options2, valuesParsed) {
2293
2293
  var currentArrayLength = 0;
2294
2294
  if (chain.length > 0 && chain[chain.length - 1] === "[]") {
2295
2295
  var parentKey = chain.slice(0, -1).join("");
2296
2296
  currentArrayLength = Array.isArray(val) && val[parentKey] ? val[parentKey].length : 0;
2297
2297
  }
2298
- var leaf = valuesParsed ? val : parseArrayValue(val, options, currentArrayLength);
2298
+ var leaf = valuesParsed ? val : parseArrayValue(val, options2, currentArrayLength);
2299
2299
  for (var i = chain.length - 1; i >= 0; --i) {
2300
2300
  var obj;
2301
2301
  var root = chain[i];
2302
- if (root === "[]" && options.parseArrays) {
2303
- obj = options.allowEmptyArrays && (leaf === "" || options.strictNullHandling && leaf === null) ? [] : utils2.combine([], leaf);
2302
+ if (root === "[]" && options2.parseArrays) {
2303
+ obj = options2.allowEmptyArrays && (leaf === "" || options2.strictNullHandling && leaf === null) ? [] : utils2.combine([], leaf);
2304
2304
  } else {
2305
- obj = options.plainObjects ? { __proto__: null } : {};
2305
+ obj = options2.plainObjects ? { __proto__: null } : {};
2306
2306
  var cleanRoot = root.charAt(0) === "[" && root.charAt(root.length - 1) === "]" ? root.slice(1, -1) : root;
2307
- var decodedRoot = options.decodeDotInKeys ? cleanRoot.replace(/%2E/g, ".") : cleanRoot;
2307
+ var decodedRoot = options2.decodeDotInKeys ? cleanRoot.replace(/%2E/g, ".") : cleanRoot;
2308
2308
  var index = parseInt(decodedRoot, 10);
2309
- if (!options.parseArrays && decodedRoot === "") {
2309
+ if (!options2.parseArrays && decodedRoot === "") {
2310
2310
  obj = { 0: leaf };
2311
- } else if (!isNaN(index) && root !== decodedRoot && String(index) === decodedRoot && index >= 0 && (options.parseArrays && index <= options.arrayLimit)) {
2311
+ } else if (!isNaN(index) && root !== decodedRoot && String(index) === decodedRoot && index >= 0 && (options2.parseArrays && index <= options2.arrayLimit)) {
2312
2312
  obj = [];
2313
2313
  obj[index] = leaf;
2314
2314
  } else if (decodedRoot !== "__proto__") {
@@ -2319,41 +2319,41 @@ function requireParse() {
2319
2319
  }
2320
2320
  return leaf;
2321
2321
  };
2322
- var parseKeys = function parseQueryStringKeys(givenKey, val, options, valuesParsed) {
2322
+ var parseKeys = function parseQueryStringKeys(givenKey, val, options2, valuesParsed) {
2323
2323
  if (!givenKey) {
2324
2324
  return;
2325
2325
  }
2326
- var key = options.allowDots ? givenKey.replace(/\.([^.[]+)/g, "[$1]") : givenKey;
2326
+ var key = options2.allowDots ? givenKey.replace(/\.([^.[]+)/g, "[$1]") : givenKey;
2327
2327
  var brackets = /(\[[^[\]]*])/;
2328
2328
  var child = /(\[[^[\]]*])/g;
2329
- var segment = options.depth > 0 && brackets.exec(key);
2329
+ var segment = options2.depth > 0 && brackets.exec(key);
2330
2330
  var parent = segment ? key.slice(0, segment.index) : key;
2331
2331
  var keys = [];
2332
2332
  if (parent) {
2333
- if (!options.plainObjects && has.call(Object.prototype, parent)) {
2334
- if (!options.allowPrototypes) {
2333
+ if (!options2.plainObjects && has.call(Object.prototype, parent)) {
2334
+ if (!options2.allowPrototypes) {
2335
2335
  return;
2336
2336
  }
2337
2337
  }
2338
2338
  keys.push(parent);
2339
2339
  }
2340
2340
  var i = 0;
2341
- while (options.depth > 0 && (segment = child.exec(key)) !== null && i < options.depth) {
2341
+ while (options2.depth > 0 && (segment = child.exec(key)) !== null && i < options2.depth) {
2342
2342
  i += 1;
2343
- if (!options.plainObjects && has.call(Object.prototype, segment[1].slice(1, -1))) {
2344
- if (!options.allowPrototypes) {
2343
+ if (!options2.plainObjects && has.call(Object.prototype, segment[1].slice(1, -1))) {
2344
+ if (!options2.allowPrototypes) {
2345
2345
  return;
2346
2346
  }
2347
2347
  }
2348
2348
  keys.push(segment[1]);
2349
2349
  }
2350
2350
  if (segment) {
2351
- if (options.strictDepth === true) {
2352
- throw new RangeError("Input depth exceeded depth option of " + options.depth + " and strictDepth is true");
2351
+ if (options2.strictDepth === true) {
2352
+ throw new RangeError("Input depth exceeded depth option of " + options2.depth + " and strictDepth is true");
2353
2353
  }
2354
2354
  keys.push("[" + key.slice(segment.index) + "]");
2355
2355
  }
2356
- return parseObject(keys, val, options, valuesParsed);
2356
+ return parseObject(keys, val, options2, valuesParsed);
2357
2357
  };
2358
2358
  var normalizeParseOptions = function normalizeParseOptions2(opts) {
2359
2359
  if (!opts) {
@@ -2406,19 +2406,19 @@ function requireParse() {
2406
2406
  };
2407
2407
  };
2408
2408
  parse = function(str, opts) {
2409
- var options = normalizeParseOptions(opts);
2409
+ var options2 = normalizeParseOptions(opts);
2410
2410
  if (str === "" || str === null || typeof str === "undefined") {
2411
- return options.plainObjects ? { __proto__: null } : {};
2411
+ return options2.plainObjects ? { __proto__: null } : {};
2412
2412
  }
2413
- var tempObj = typeof str === "string" ? parseValues(str, options) : str;
2414
- var obj = options.plainObjects ? { __proto__: null } : {};
2413
+ var tempObj = typeof str === "string" ? parseValues(str, options2) : str;
2414
+ var obj = options2.plainObjects ? { __proto__: null } : {};
2415
2415
  var keys = Object.keys(tempObj);
2416
2416
  for (var i = 0; i < keys.length; ++i) {
2417
2417
  var key = keys[i];
2418
- var newObj = parseKeys(key, tempObj[key], options, typeof str === "string");
2419
- obj = utils2.merge(obj, newObj, options);
2418
+ var newObj = parseKeys(key, tempObj[key], options2, typeof str === "string");
2419
+ obj = utils2.merge(obj, newObj, options2);
2420
2420
  }
2421
- if (options.allowSparse === true) {
2421
+ if (options2.allowSparse === true) {
2422
2422
  return obj;
2423
2423
  }
2424
2424
  return utils2.compact(obj);
@@ -2603,15 +2603,21 @@ const getBody = (body, method, headers, qsArrayFormat = "repeat") => {
2603
2603
  }
2604
2604
  return res;
2605
2605
  };
2606
- class HookFetch {
2607
- constructor(options) {
2606
+ const _HookFetch = class _HookFetch {
2607
+ constructor(options2) {
2608
2608
  __privateAdd(this, _HookFetch_instances);
2609
2609
  __privateAdd(this, _plugins);
2610
2610
  __privateAdd(this, _controller);
2611
2611
  __privateAdd(this, _config2);
2612
2612
  __privateAdd(this, _promise);
2613
2613
  __privateAdd(this, _isTimeout, false);
2614
- const { plugins = [], controller, url, baseURL = "", params, data, qsArrayFormat = "repeat", withCredentials, extra, method = "GET", headers } = options;
2614
+ // eslint-disable-next-line no-explicit-any
2615
+ __privateAdd(this, _executor, null);
2616
+ __privateAdd(this, _finallyCallbacks, []);
2617
+ __privateAdd(this, _responseType, "json");
2618
+ __privateAdd(this, _fullOptions);
2619
+ __privateSet(this, _fullOptions, options2);
2620
+ const { plugins = [], controller, url, baseURL = "", params, data, qsArrayFormat = "repeat", withCredentials, extra, method = "GET", headers } = options2;
2615
2621
  __privateSet(this, _controller, controller ?? new AbortController());
2616
2622
  __privateSet(this, _plugins, parsePlugins(plugins));
2617
2623
  __privateSet(this, _config2, {
@@ -2625,35 +2631,75 @@ class HookFetch {
2625
2631
  headers,
2626
2632
  qsArrayFormat
2627
2633
  });
2628
- __privateSet(this, _promise, __privateMethod(this, _HookFetch_instances, init_fn).call(this, options));
2634
+ __privateSet(this, _promise, __privateMethod(this, _HookFetch_instances, init_fn).call(this, options2));
2635
+ }
2636
+ lazyFinally(onfinally) {
2637
+ if (!__privateGet(this, _executor)) {
2638
+ if (onfinally) {
2639
+ __privateGet(this, _finallyCallbacks).push(onfinally);
2640
+ }
2641
+ return null;
2642
+ }
2643
+ return __privateGet(this, _executor).finally(() => {
2644
+ for (const callback of __privateGet(this, _finallyCallbacks)) {
2645
+ callback();
2646
+ }
2647
+ __privateSet(this, _finallyCallbacks, []);
2648
+ });
2629
2649
  }
2630
2650
  then(onfulfilled, onrejected) {
2631
- return __privateGet(this, _HookFetch_instances, json_get).then(onfulfilled, onrejected);
2651
+ return __privateGet(this, _HookFetch_instances, getExecutor_get).then(
2652
+ async (v) => onfulfilled == null ? void 0 : onfulfilled.call(this, await __privateMethod(this, _HookFetch_instances, resolve_fn).call(this, v)),
2653
+ async (e) => onrejected == null ? void 0 : onrejected.call(this, await __privateMethod(this, _HookFetch_instances, normalizeError_fn).call(this, e))
2654
+ );
2632
2655
  }
2633
- // 没有走插件错误处理x
2634
2656
  catch(onrejected) {
2635
- return __privateGet(this, _HookFetch_instances, json_get).catch(onrejected);
2657
+ return __privateGet(this, _HookFetch_instances, getExecutor_get).catch(onrejected);
2636
2658
  }
2637
2659
  finally(onfinally) {
2638
- return __privateGet(this, _HookFetch_instances, json_get).finally(onfinally);
2660
+ return __privateGet(this, _HookFetch_instances, getExecutor_get).finally(onfinally);
2639
2661
  }
2640
2662
  abort() {
2641
2663
  __privateGet(this, _controller).abort();
2642
2664
  }
2643
2665
  blob() {
2644
- return __privateGet(this, _HookFetch_instances, response_get).then((r) => r.blob());
2666
+ __privateSet(this, _executor, __privateGet(this, _HookFetch_instances, response_get).then((r) => r.blob()).then((r) => {
2667
+ __privateSet(this, _responseType, "blob");
2668
+ return __privateMethod(this, _HookFetch_instances, resolve_fn).call(this, r);
2669
+ }));
2670
+ return __privateGet(this, _executor);
2645
2671
  }
2646
2672
  text() {
2647
- return __privateGet(this, _HookFetch_instances, response_get).then((r) => r.text());
2673
+ __privateSet(this, _executor, __privateGet(this, _HookFetch_instances, response_get).then((r) => r.text()).then((r) => {
2674
+ __privateSet(this, _responseType, "text");
2675
+ return __privateMethod(this, _HookFetch_instances, resolve_fn).call(this, r);
2676
+ }));
2677
+ __privateGet(this, _executor).finally(this.lazyFinally.bind(this));
2678
+ return __privateGet(this, _executor);
2648
2679
  }
2649
2680
  arrayBuffer() {
2650
- return __privateGet(this, _HookFetch_instances, response_get).then((r) => r.arrayBuffer());
2681
+ __privateSet(this, _executor, __privateGet(this, _HookFetch_instances, response_get).then((r) => r.arrayBuffer()).then((r) => {
2682
+ __privateSet(this, _responseType, "arrayBuffer");
2683
+ return __privateMethod(this, _HookFetch_instances, resolve_fn).call(this, r);
2684
+ }));
2685
+ __privateGet(this, _executor).finally(this.lazyFinally.bind(this));
2686
+ return __privateGet(this, _executor);
2651
2687
  }
2652
2688
  formData() {
2653
- return __privateGet(this, _HookFetch_instances, response_get).then((r) => r.formData());
2689
+ __privateSet(this, _executor, __privateGet(this, _HookFetch_instances, response_get).then((r) => r.formData()).then((r) => {
2690
+ __privateSet(this, _responseType, "formData");
2691
+ return __privateMethod(this, _HookFetch_instances, resolve_fn).call(this, r);
2692
+ }));
2693
+ __privateGet(this, _executor).finally(this.lazyFinally.bind(this));
2694
+ return __privateGet(this, _executor);
2654
2695
  }
2655
2696
  bytes() {
2656
- return __privateGet(this, _HookFetch_instances, response_get).then((r) => r.bytes());
2697
+ __privateSet(this, _executor, __privateGet(this, _HookFetch_instances, response_get).then((r) => r.bytes()).then((r) => {
2698
+ __privateSet(this, _responseType, "bytes");
2699
+ return __privateMethod(this, _HookFetch_instances, resolve_fn).call(this, r);
2700
+ }));
2701
+ __privateGet(this, _executor).finally(this.lazyFinally.bind(this));
2702
+ return __privateGet(this, _executor);
2657
2703
  }
2658
2704
  async *stream() {
2659
2705
  var _a, _b;
@@ -2684,12 +2730,23 @@ class HookFetch {
2684
2730
  }
2685
2731
  }
2686
2732
  }
2687
- }
2733
+ retry() {
2734
+ const { controller: _, ...options2 } = __privateGet(this, _fullOptions);
2735
+ return new _HookFetch(options2);
2736
+ }
2737
+ get response() {
2738
+ return __privateGet(this, _HookFetch_instances, response_get);
2739
+ }
2740
+ };
2688
2741
  _plugins = new WeakMap();
2689
2742
  _controller = new WeakMap();
2690
2743
  _config2 = new WeakMap();
2691
2744
  _promise = new WeakMap();
2692
2745
  _isTimeout = new WeakMap();
2746
+ _executor = new WeakMap();
2747
+ _finallyCallbacks = new WeakMap();
2748
+ _responseType = new WeakMap();
2749
+ _fullOptions = new WeakMap();
2693
2750
  _HookFetch_instances = new WeakSet();
2694
2751
  init_fn = function({ timeout }) {
2695
2752
  return new Promise(async (resolve, reject) => {
@@ -2701,7 +2758,7 @@ init_fn = function({ timeout }) {
2701
2758
  const _url_ = buildUrl(config.baseURL + config.url, config.params, config.qsArrayFormat);
2702
2759
  const body = getBody(config.data, config.method, config.headers, config.qsArrayFormat);
2703
2760
  const otherOptions = omit(config ?? {}, ["baseURL", "data", "extra", "headers", "method", "params", "url", "withCredentials"]);
2704
- const options = {
2761
+ const options2 = {
2705
2762
  ...otherOptions,
2706
2763
  method: config.method,
2707
2764
  headers: config.headers,
@@ -2709,7 +2766,7 @@ init_fn = function({ timeout }) {
2709
2766
  credentials: config.withCredentials ? "include" : "omit",
2710
2767
  body
2711
2768
  };
2712
- const req = fetch(_url_, options);
2769
+ const req = fetch(_url_, options2);
2713
2770
  let promises = [req];
2714
2771
  let timeoutId = null;
2715
2772
  if (timeout) {
@@ -2802,31 +2859,35 @@ normalizeError_fn = async function(error) {
2802
2859
  return err;
2803
2860
  };
2804
2861
  json_get = function() {
2805
- return new Promise((resolve, reject) => {
2806
- __privateGet(this, _HookFetch_instances, response_get).then((r) => r.json()).then(async (res) => {
2807
- let result = res;
2808
- for (const plugin of __privateGet(this, _plugins).afterResponsePlugins) {
2809
- result = await plugin(result);
2810
- }
2811
- resolve(result);
2812
- }).catch(async (err) => {
2813
- reject(await __privateMethod(this, _HookFetch_instances, normalizeError_fn).call(this, err));
2814
- }).finally(async () => {
2815
- const options = {
2816
- config: __privateGet(this, _config2),
2817
- response: await __privateGet(this, _HookFetch_instances, response_get).then((r) => r.clone())
2818
- };
2819
- for (const plugin of __privateGet(this, _plugins).finallyPlugins) {
2820
- plugin(options);
2821
- }
2822
- });
2862
+ return __privateGet(this, _HookFetch_instances, response_get).then((r) => r.json()).then((r) => {
2863
+ __privateSet(this, _responseType, "json");
2864
+ return __privateMethod(this, _HookFetch_instances, resolve_fn).call(this, r);
2823
2865
  });
2824
2866
  };
2867
+ getExecutor_get = function() {
2868
+ if (__privateGet(this, _executor)) return __privateGet(this, _executor);
2869
+ return __privateGet(this, _HookFetch_instances, json_get);
2870
+ };
2871
+ resolve_fn = async function(v) {
2872
+ const plugins = __privateGet(this, _plugins).afterResponsePlugins;
2873
+ let ctx = {
2874
+ config: __privateGet(this, _config2),
2875
+ response: await __privateGet(this, _HookFetch_instances, response_get).then((r) => r.clone()),
2876
+ responseType: __privateGet(this, _responseType),
2877
+ controller: __privateGet(this, _controller),
2878
+ result: v
2879
+ };
2880
+ for (const plugin of plugins) {
2881
+ ctx = await plugin(ctx);
2882
+ }
2883
+ return ctx.result;
2884
+ };
2825
2885
  response_get = function() {
2826
2886
  return __privateGet(this, _promise).then((r) => r.clone());
2827
2887
  };
2828
- const request = (options) => {
2829
- return new HookFetch(options);
2888
+ let HookFetch = _HookFetch;
2889
+ const _request_ = (options2) => {
2890
+ return new HookFetch(options2);
2830
2891
  };
2831
2892
  class Base {
2832
2893
  constructor({ timeout = 0, baseURL = "", headers = {}, plugins = [], withCredentials = false }) {
@@ -2842,16 +2903,26 @@ class Base {
2842
2903
  __privateSet(this, _commonHeaders, headers);
2843
2904
  __privateSet(this, _plugins2, plugins);
2844
2905
  __privateSet(this, _withCredentials, withCredentials);
2906
+ this.request = this.request.bind(this);
2907
+ this.get = this.get.bind(this);
2908
+ this.head = this.head.bind(this);
2909
+ this.options = this.options.bind(this);
2910
+ this.delete = this.delete.bind(this);
2911
+ this.post = this.post.bind(this);
2912
+ this.put = this.put.bind(this);
2913
+ this.patch = this.patch.bind(this);
2914
+ this.abortAll = this.abortAll.bind(this);
2915
+ this.use = this.use.bind(this);
2845
2916
  }
2846
2917
  // eslint-disable-next-line no-explicit-any
2847
2918
  use(plugin) {
2848
2919
  __privateGet(this, _plugins2).push(plugin);
2849
2920
  return this;
2850
2921
  }
2851
- request(url, { timeout, headers, method = "GET", params, data, qsArrayFormat, withCredentials, extra } = {}) {
2922
+ request(url, { timeout, headers, method = "GET", params = {}, data, qsArrayFormat, withCredentials, extra } = {}) {
2852
2923
  const controller = new AbortController();
2853
2924
  __privateGet(this, _queue).push(controller);
2854
- const req = request({
2925
+ const req = _request_({
2855
2926
  url,
2856
2927
  baseURL: __privateGet(this, _baseURL),
2857
2928
  timeout: timeout ?? __privateGet(this, _timeout),
@@ -2865,31 +2936,31 @@ class Base {
2865
2936
  withCredentials: withCredentials ?? __privateGet(this, _withCredentials),
2866
2937
  extra
2867
2938
  });
2868
- req.finally(() => {
2939
+ req.lazyFinally(() => {
2869
2940
  __privateSet(this, _queue, __privateGet(this, _queue).filter((item) => item !== controller));
2870
2941
  });
2871
2942
  return req;
2872
2943
  }
2873
- get(url, params = {}, options) {
2874
- return __privateMethod(this, _Base_instances, requestWithParams_fn).call(this, url, params, options);
2944
+ get(url, params = {}, options2) {
2945
+ return __privateMethod(this, _Base_instances, requestWithParams_fn).call(this, url, params, { ...options2, method: "GET" });
2875
2946
  }
2876
- head(url, params = {}, options) {
2877
- return __privateMethod(this, _Base_instances, requestWithParams_fn).call(this, url, params, options);
2947
+ head(url, params = {}, options2) {
2948
+ return __privateMethod(this, _Base_instances, requestWithParams_fn).call(this, url, params, { ...options2, method: "HEAD" });
2878
2949
  }
2879
- options(url, params = {}, options) {
2880
- return __privateMethod(this, _Base_instances, requestWithParams_fn).call(this, url, params, options);
2950
+ options(url, params = {}, options2) {
2951
+ return __privateMethod(this, _Base_instances, requestWithParams_fn).call(this, url, params, { ...options2, method: "OPTIONS" });
2881
2952
  }
2882
- delete(url, options) {
2883
- return this.request(url, options);
2953
+ delete(url, options2) {
2954
+ return this.request(url, { ...options2, method: "DELETE" });
2884
2955
  }
2885
- post(url, data, options) {
2886
- return __privateMethod(this, _Base_instances, requestWithBody_fn).call(this, url, data, options);
2956
+ post(url, data, options2) {
2957
+ return __privateMethod(this, _Base_instances, requestWithBody_fn).call(this, url, data, { ...options2, method: "POST" });
2887
2958
  }
2888
- put(url, data, options) {
2889
- return __privateMethod(this, _Base_instances, requestWithBody_fn).call(this, url, data, options);
2959
+ put(url, data, options2) {
2960
+ return __privateMethod(this, _Base_instances, requestWithBody_fn).call(this, url, data, { ...options2, method: "PUT" });
2890
2961
  }
2891
- patch(url, data, options) {
2892
- return __privateMethod(this, _Base_instances, requestWithBody_fn).call(this, url, data, options);
2962
+ patch(url, data, options2) {
2963
+ return __privateMethod(this, _Base_instances, requestWithBody_fn).call(this, url, data, { ...options2, method: "PATCH" });
2893
2964
  }
2894
2965
  abortAll() {
2895
2966
  __privateGet(this, _queue).forEach((controller) => controller.abort());
@@ -2903,20 +2974,68 @@ _queue = new WeakMap();
2903
2974
  _plugins2 = new WeakMap();
2904
2975
  _withCredentials = new WeakMap();
2905
2976
  _Base_instances = new WeakSet();
2906
- requestWithParams_fn = function(url, params = {}, options = {}) {
2907
- return this.request(url, { ...options, params });
2977
+ requestWithParams_fn = function(url, params = {}, options2 = {}) {
2978
+ return this.request(url, { ...options2, params });
2908
2979
  };
2909
- requestWithBody_fn = function(url, data = {}, options = {}) {
2910
- return this.request(url, { ...options, data });
2980
+ requestWithBody_fn = function(url, data = {}, options2 = {}) {
2981
+ return this.request(url, { ...options2, data });
2911
2982
  };
2912
- const useRequest = (url, options = {}) => request({
2983
+ const useRequest = (url, options2 = {}) => _request_({
2913
2984
  url,
2914
2985
  baseURL: "",
2915
- ...options
2986
+ ...options2
2916
2987
  });
2988
+ const requestWithParams = (url, params, options2 = {}) => {
2989
+ return useRequest(url, { ...options2, params });
2990
+ };
2991
+ const requestWithBody = (url, data = null, options2 = {}) => {
2992
+ return useRequest(url, { ...options2, data });
2993
+ };
2994
+ const request = useRequest;
2995
+ const get = (url, params = {}, options2) => {
2996
+ return requestWithParams(url, params, { ...options2, method: "GET" });
2997
+ };
2998
+ const head = (url, params = {}, options2) => {
2999
+ return requestWithParams(url, params, { ...options2, method: "HEAD" });
3000
+ };
3001
+ const options = (url, params = {}, options2) => {
3002
+ return requestWithParams(url, params, { ...options2, method: "OPTIONS" });
3003
+ };
3004
+ const del = (url, options2) => {
3005
+ return useRequest(url, { ...options2, method: "DELETE" });
3006
+ };
3007
+ const post = (url, data, options2) => {
3008
+ return requestWithBody(url, data, { ...options2, method: "POST" });
3009
+ };
3010
+ const put = (url, data, options2) => {
3011
+ return requestWithBody(url, data, { ...options2, method: "PUT" });
3012
+ };
3013
+ const patch = (url, data, options2) => {
3014
+ return requestWithBody(url, data, { ...options2, method: "PATCH" });
3015
+ };
2917
3016
  const defaultFn = useRequest;
2918
- defaultFn.create = (options) => new Base(options);
3017
+ defaultFn.create = (options2) => {
3018
+ const context = new Base(options2);
3019
+ const instance = context.request.bind(void 0);
3020
+ Object.assign(instance, Base.prototype, context);
3021
+ return instance;
3022
+ };
3023
+ defaultFn.get = get;
3024
+ defaultFn.head = head;
3025
+ defaultFn.options = options;
3026
+ defaultFn.delete = del;
3027
+ defaultFn.post = post;
3028
+ defaultFn.put = put;
3029
+ defaultFn.patch = patch;
2919
3030
  export {
2920
- defaultFn as default
3031
+ defaultFn as default,
3032
+ del,
3033
+ get,
3034
+ head,
3035
+ options,
3036
+ patch,
3037
+ post,
3038
+ put,
3039
+ request
2921
3040
  };
2922
3041
  //# sourceMappingURL=index.js.map