got 11.4.0 → 11.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/source/as-promise/index.d.ts +1 -3
  2. package/dist/source/as-promise/index.js +56 -117
  3. package/dist/source/as-promise/normalize-arguments.d.ts +3 -0
  4. package/dist/source/as-promise/normalize-arguments.js +78 -0
  5. package/dist/source/as-promise/parse-body.d.ts +3 -0
  6. package/dist/source/as-promise/parse-body.js +25 -0
  7. package/dist/source/as-promise/types.d.ts +235 -58
  8. package/dist/source/as-promise/types.js +29 -16
  9. package/dist/source/{as-promise → core}/calculate-retry-delay.d.ts +2 -1
  10. package/dist/source/core/calculate-retry-delay.js +29 -0
  11. package/dist/source/core/index.d.ts +851 -28
  12. package/dist/source/core/index.js +291 -55
  13. package/dist/source/core/utils/dns-ip-version.js +1 -0
  14. package/dist/source/core/utils/get-body-size.d.ts +2 -4
  15. package/dist/source/core/utils/is-form-data.d.ts +2 -2
  16. package/dist/source/core/utils/is-response-ok.d.ts +2 -0
  17. package/dist/source/core/utils/is-response-ok.js +8 -0
  18. package/dist/source/core/utils/options-to-url.d.ts +0 -1
  19. package/dist/source/core/utils/timed-out.js +1 -0
  20. package/dist/source/core/utils/url-to-options.d.ts +0 -1
  21. package/dist/source/core/utils/weakable-map.d.ts +1 -1
  22. package/dist/source/create.js +42 -13
  23. package/dist/source/index.js +16 -6
  24. package/dist/source/types.d.ts +245 -8
  25. package/dist/source/utils/deep-freeze.d.ts +1 -1
  26. package/dist/source/utils/deprecation-warning.js +1 -1
  27. package/package.json +30 -29
  28. package/readme.md +171 -35
  29. package/dist/source/as-promise/calculate-retry-delay.js +0 -38
  30. package/dist/source/as-promise/core.d.ts +0 -13
  31. package/dist/source/as-promise/core.js +0 -124
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dnsLookupIpVersionToFamily = exports.isDnsLookupIpVersion = void 0;
3
4
  const conversionTable = {
4
5
  auto: 0,
5
6
  ipv4: 4,
@@ -1,5 +1,3 @@
1
- /// <reference path="timed-out.d.ts" />
2
- /// <reference types="node" />
3
- /// <reference types="node/http" />
4
- declare const _default: (body: unknown, headers: import("http").OutgoingHttpHeaders | undefined) => Promise<number | undefined>;
1
+ import { ClientRequestArgs } from 'http';
2
+ declare const _default: (body: unknown, headers: ClientRequestArgs['headers']) => Promise<number | undefined>;
5
3
  export default _default;
@@ -1,8 +1,8 @@
1
1
  /// <reference types="node" />
2
2
  import { Readable } from 'stream';
3
3
  interface FormData extends Readable {
4
- getBoundary(): string;
5
- getLength(callback: (error: Error | null, length: number) => void): void;
4
+ getBoundary: () => string;
5
+ getLength: (callback: (error: Error | null, length: number) => void) => void;
6
6
  }
7
7
  declare const _default: (body: unknown) => body is FormData;
8
8
  export default _default;
@@ -0,0 +1,2 @@
1
+ import { Response } from '..';
2
+ export declare const isResponseOk: (response: Response) => boolean;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isResponseOk = void 0;
4
+ exports.isResponseOk = (response) => {
5
+ const { statusCode } = response;
6
+ const limitStatusCode = response.request.options.followRedirect ? 299 : 399;
7
+ return (statusCode >= 200 && statusCode <= limitStatusCode) || statusCode === 304;
8
+ };
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { URL } from 'url';
3
2
  export interface URLOptions {
4
3
  href?: string;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TimeoutError = void 0;
3
4
  const net = require("net");
4
5
  const unhandle_1 = require("./unhandle");
5
6
  const reentry = Symbol('reentry');
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { URL, UrlWithStringQuery } from 'url';
3
2
  export interface LegacyUrlOptions {
4
3
  protocol: string;
@@ -1,5 +1,5 @@
1
1
  export default class WeakableMap<K, V> {
2
- weakMap: WeakMap<object, V>;
2
+ weakMap: WeakMap<Record<string, unknown>, V>;
3
3
  map: Map<K, V>;
4
4
  constructor();
5
5
  set(key: K, value: V): void;
@@ -1,6 +1,16 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
2
12
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const p_cancelable_1 = require("p-cancelable");
13
+ exports.defaultHandler = void 0;
4
14
  const is_1 = require("@sindresorhus/is");
5
15
  const as_promise_1 = require("./as-promise");
6
16
  const create_rejection_1 = require("./as-promise/create-rejection");
@@ -14,12 +24,23 @@ const errors = {
14
24
  MaxRedirectsError: as_promise_1.MaxRedirectsError,
15
25
  TimeoutError: as_promise_1.TimeoutError,
16
26
  ParseError: as_promise_1.ParseError,
17
- CancelError: p_cancelable_1.CancelError,
27
+ CancelError: as_promise_1.CancelError,
18
28
  UnsupportedProtocolError: as_promise_1.UnsupportedProtocolError,
19
29
  UploadError: as_promise_1.UploadError
20
30
  };
21
- const { normalizeArguments, mergeOptions } = as_promise_1.PromisableRequest;
22
- const getPromiseOrStream = (options) => options.isStream ? new core_1.default(options.url, options) : as_promise_1.default(options);
31
+ // The `delay` package weighs 10KB (!)
32
+ const delay = async (ms) => new Promise(resolve => {
33
+ setTimeout(resolve, ms);
34
+ });
35
+ const { normalizeArguments } = core_1.default;
36
+ const mergeOptions = (...sources) => {
37
+ let mergedOptions;
38
+ for (const source of sources) {
39
+ mergedOptions = normalizeArguments(undefined, source, mergedOptions);
40
+ }
41
+ return mergedOptions;
42
+ };
43
+ const getPromiseOrStream = (options) => options.isStream ? new core_1.default(undefined, options) : as_promise_1.default(options);
23
44
  const isGotInstance = (value) => ('defaults' in value && 'options' in value.defaults);
24
45
  const aliases = [
25
46
  'get',
@@ -61,13 +82,13 @@ const create = (defaults) => {
61
82
  return result;
62
83
  }));
63
84
  // Got interface
64
- const got = ((url, options) => {
85
+ const got = ((url, options, _defaults) => {
65
86
  var _a, _b;
66
87
  let iteration = 0;
67
88
  const iterateHandlers = (newOptions) => {
68
89
  return defaults.handlers[iteration++](newOptions, iteration === defaults.handlers.length ? getPromiseOrStream : iterateHandlers);
69
90
  };
70
- // TODO: remove this in Got 12
91
+ // TODO: Remove this in Got 12.
71
92
  if (is_1.default.plainObject(url)) {
72
93
  const mergedOptions = {
73
94
  ...url,
@@ -88,7 +109,7 @@ const create = (defaults) => {
88
109
  initHookError = error;
89
110
  }
90
111
  // Normalize options & call handlers
91
- const normalizedOptions = normalizeArguments(url, options, defaults.options);
112
+ const normalizedOptions = normalizeArguments(url, options, _defaults !== null && _defaults !== void 0 ? _defaults : defaults.options);
92
113
  normalizedOptions[core_1.kIsNormalizedAlready] = true;
93
114
  if (initHookError) {
94
115
  throw new as_promise_1.RequestError(initHookError.message, initHookError, normalizedOptions);
@@ -134,6 +155,9 @@ const create = (defaults) => {
134
155
  };
135
156
  // Pagination
136
157
  const paginateEach = (async function* (url, options) {
158
+ // TODO: Remove this `@ts-expect-error` when upgrading to TypeScript 4.
159
+ // Error: Argument of type 'Merge<Options, PaginationOptions<T, R>> | undefined' is not assignable to parameter of type 'Options | undefined'.
160
+ // @ts-expect-error
137
161
  let normalizedOptions = normalizeArguments(url, options, defaults.options);
138
162
  normalizedOptions.resolveBodyOnly = false;
139
163
  const pagination = normalizedOptions.pagination;
@@ -144,9 +168,14 @@ const create = (defaults) => {
144
168
  let { countLimit } = pagination;
145
169
  let numberOfRequests = 0;
146
170
  while (numberOfRequests < pagination.requestLimit) {
171
+ if (numberOfRequests !== 0) {
172
+ // eslint-disable-next-line no-await-in-loop
173
+ await delay(pagination.backoff);
174
+ }
175
+ // @ts-expect-error FIXME!
147
176
  // TODO: Throw when result is not an instance of Response
148
177
  // eslint-disable-next-line no-await-in-loop
149
- const result = (await got(normalizedOptions));
178
+ const result = (await got(undefined, undefined, normalizedOptions));
150
179
  // eslint-disable-next-line no-await-in-loop
151
180
  const parsed = await pagination.transform(result);
152
181
  const current = [];
@@ -178,12 +207,10 @@ const create = (defaults) => {
178
207
  numberOfRequests++;
179
208
  }
180
209
  });
181
- got.paginate = ((url, options) => {
182
- return paginateEach(url, options);
183
- });
210
+ got.paginate = paginateEach;
184
211
  got.paginate.all = (async (url, options) => {
185
212
  const results = [];
186
- for await (const item of got.paginate(url, options)) {
213
+ for await (const item of paginateEach(url, options)) {
187
214
  results.push(item);
188
215
  }
189
216
  return results;
@@ -199,13 +226,15 @@ const create = (defaults) => {
199
226
  return got(url, { ...options, method, isStream: true });
200
227
  });
201
228
  }
202
- Object.assign(got, { ...errors, mergeOptions });
229
+ Object.assign(got, errors);
203
230
  Object.defineProperty(got, 'defaults', {
204
231
  value: defaults.mutableDefaults ? defaults : deep_freeze_1.default(defaults),
205
232
  writable: defaults.mutableDefaults,
206
233
  configurable: defaults.mutableDefaults,
207
234
  enumerable: true
208
235
  });
236
+ got.mergeOptions = mergeOptions;
209
237
  return got;
210
238
  };
211
239
  exports.default = create;
240
+ __exportStar(require("./types"), exports);
@@ -1,7 +1,14 @@
1
1
  "use strict";
2
- function __export(m) {
3
- for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4
- }
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
5
12
  Object.defineProperty(exports, "__esModule", { value: true });
6
13
  const url_1 = require("url");
7
14
  const create_1 = require("./create");
@@ -104,11 +111,13 @@ const defaults = {
104
111
  filter: () => true,
105
112
  shouldContinue: () => true,
106
113
  countLimit: Infinity,
114
+ backoff: 0,
107
115
  requestLimit: 10000,
108
116
  stackAllItems: true
109
117
  },
110
118
  parseJson: (text) => JSON.parse(text),
111
- stringifyJson: (object) => JSON.stringify(object)
119
+ stringifyJson: (object) => JSON.stringify(object),
120
+ cacheOptions: {}
112
121
  },
113
122
  handlers: [create_1.defaultHandler],
114
123
  mutableDefaults: false
@@ -118,5 +127,6 @@ exports.default = got;
118
127
  // For CommonJS default export support
119
128
  module.exports = got;
120
129
  module.exports.default = got;
121
- __export(require("./create"));
122
- __export(require("./as-promise"));
130
+ module.exports.__esModule = true; // Workaround for TS issue: https://github.com/sindresorhus/got/pull/1267
131
+ __exportStar(require("./create"), exports);
132
+ __exportStar(require("./as-promise"), exports);
@@ -1,20 +1,62 @@
1
1
  /// <reference types="node" />
2
2
  import { URL } from 'url';
3
3
  import { CancelError } from 'p-cancelable';
4
- import { CancelableRequest, Response, Options, NormalizedOptions, Defaults as DefaultOptions, PaginationOptions, ParseError, RequestError, CacheError, ReadError, HTTPError, MaxRedirectsError, TimeoutError } from './as-promise';
4
+ import { CancelableRequest, Response, Options, NormalizedOptions, Defaults as DefaultOptions, PaginationOptions, ParseError, RequestError, CacheError, ReadError, HTTPError, MaxRedirectsError, TimeoutError, UnsupportedProtocolError, UploadError } from './as-promise';
5
5
  import Request from './core';
6
6
  declare type Except<ObjectType, KeysType extends keyof ObjectType> = Pick<ObjectType, Exclude<keyof ObjectType, KeysType>>;
7
7
  declare type Merge<FirstType, SecondType> = Except<FirstType, Extract<keyof FirstType, keyof SecondType>> & SecondType;
8
+ /**
9
+ Defaults for each Got instance.
10
+ */
8
11
  export interface InstanceDefaults {
12
+ /**
13
+ An object containing the default options of Got.
14
+ */
9
15
  options: DefaultOptions;
16
+ /**
17
+ An array of functions. You execute them directly by calling `got()`.
18
+ They are some sort of "global hooks" - these functions are called first.
19
+ The last handler (*it's hidden*) is either `asPromise` or `asStream`, depending on the `options.isStream` property.
20
+
21
+ @default []
22
+ */
10
23
  handlers: HandlerFunction[];
24
+ /**
25
+ A read-only boolean describing whether the defaults are mutable or not.
26
+ If set to `true`, you can update headers over time, for example, update an access token when it expires.
27
+
28
+ @default false
29
+ */
11
30
  mutableDefaults: boolean;
12
31
  _rawHandlers?: HandlerFunction[];
13
32
  }
33
+ /**
34
+ A Request object returned by calling Got, or any of the Got HTTP alias request functions.
35
+ */
14
36
  export declare type GotReturn = Request | CancelableRequest;
37
+ /**
38
+ A function to handle options and returns a Request object.
39
+ It acts sort of like a "global hook", and will be called before any actual request is made.
40
+ */
15
41
  export declare type HandlerFunction = <T extends GotReturn>(options: NormalizedOptions, next: (options: NormalizedOptions) => T) => T | Promise<T>;
42
+ /**
43
+ The options available for `got.extend()`.
44
+ */
16
45
  export interface ExtendOptions extends Options {
46
+ /**
47
+ An array of functions. You execute them directly by calling `got()`.
48
+ They are some sort of "global hooks" - these functions are called first.
49
+ The last handler (*it's hidden*) is either `asPromise` or `asStream`, depending on the `options.isStream` property.
50
+
51
+ @default []
52
+ */
17
53
  handlers?: HandlerFunction[];
54
+ /**
55
+ A read-only boolean describing whether the defaults are mutable or not.
56
+ If set to `true`, you can update headers over time, for example, update an access token when it expires.
57
+
58
+ @default false
59
+ */
18
60
  mutableDefaults?: boolean;
19
61
  }
20
62
  export declare type OptionsOfTextResponseBody = Merge<Options, {
@@ -44,13 +86,61 @@ declare type ResponseBodyOnly = {
44
86
  resolveBodyOnly: true;
45
87
  };
46
88
  export declare type OptionsWithPagination<T = unknown, R = unknown> = Merge<Options, PaginationOptions<T, R>>;
89
+ /**
90
+ An instance of `got.paginate`.
91
+ */
47
92
  export interface GotPaginate {
93
+ /**
94
+ Returns an async iterator.
95
+
96
+ See pagination.options for more pagination options.
97
+
98
+ @example
99
+ ```
100
+ (async () => {
101
+ const countLimit = 10;
102
+
103
+ const pagination = got.paginate('https://api.github.com/repos/sindresorhus/got/commits', {
104
+ pagination: {countLimit}
105
+ });
106
+
107
+ console.log(`Printing latest ${countLimit} Got commits (newest to oldest):`);
108
+
109
+ for await (const commitData of pagination) {
110
+ console.log(commitData.commit.message);
111
+ }
112
+ })();
113
+ ```
114
+ */
115
+ each: (<T, R = unknown>(url: string | URL, options?: OptionsWithPagination<T, R>) => AsyncIterableIterator<T>) & (<T, R = unknown>(options?: OptionsWithPagination<T, R>) => AsyncIterableIterator<T>);
116
+ /**
117
+ Returns a Promise for an array of all results.
118
+
119
+ See pagination.options for more pagination options.
120
+
121
+ @example
122
+ ```
123
+ (async () => {
124
+ const countLimit = 10;
125
+
126
+ const results = await got.paginate.all('https://api.github.com/repos/sindresorhus/got/commits', {
127
+ pagination: {countLimit}
128
+ });
129
+
130
+ console.log(`Printing latest ${countLimit} Got commits (newest to oldest):`);
131
+ console.log(results);
132
+ })();
133
+ ```
134
+ */
135
+ all: (<T, R = unknown>(url: string | URL, options?: OptionsWithPagination<T, R>) => Promise<T[]>) & (<T, R = unknown>(options?: OptionsWithPagination<T, R>) => Promise<T[]>);
136
+ /**
137
+ Same as `GotPaginate.each`.
138
+ */
48
139
  <T, R = unknown>(url: string | URL, options?: OptionsWithPagination<T, R>): AsyncIterableIterator<T>;
140
+ /**
141
+ Same as `GotPaginate.each`.
142
+ */
49
143
  <T, R = unknown>(options?: OptionsWithPagination<T, R>): AsyncIterableIterator<T>;
50
- each<T, R = unknown>(url: string | URL, options?: OptionsWithPagination<T, R>): AsyncIterableIterator<T>;
51
- each<T, R = unknown>(options?: OptionsWithPagination<T, R>): AsyncIterableIterator<T>;
52
- all<T, R = unknown>(url: string | URL, options?: OptionsWithPagination<T, R>): Promise<T[]>;
53
- all<T, R = unknown>(options?: OptionsWithPagination<T, R>): Promise<T[]>;
54
144
  }
55
145
  export interface GotRequestFunction {
56
146
  (url: string | URL, options?: OptionsOfTextResponseBody): CancelableRequest<Response<string>>;
@@ -76,6 +166,9 @@ export interface GotRequestFunction {
76
166
  (url: string | URL, options?: Options): CancelableRequest | Request;
77
167
  (options: Options): CancelableRequest | Request;
78
168
  }
169
+ /**
170
+ All available HTTP request methods provided by Got.
171
+ */
79
172
  export declare type HTTPAlias = 'get' | 'post' | 'put' | 'patch' | 'head' | 'delete';
80
173
  interface GotStreamFunction {
81
174
  (url: string | URL, options?: Merge<Options, {
@@ -85,21 +178,165 @@ interface GotStreamFunction {
85
178
  isStream?: true;
86
179
  }>): Request;
87
180
  }
181
+ /**
182
+ An instance of `got.stream()`.
183
+ */
88
184
  export declare type GotStream = GotStreamFunction & Record<HTTPAlias, GotStreamFunction>;
185
+ /**
186
+ An instance of `got`.
187
+ */
89
188
  export interface Got extends Record<HTTPAlias, GotRequestFunction>, GotRequestFunction {
189
+ /**
190
+ Sets `options.isStream` to `true`.
191
+
192
+ Returns a [duplex stream](https://nodejs.org/api/stream.html#stream_class_stream_duplex) with additional events:
193
+ - request
194
+ - response
195
+ - redirect
196
+ - uploadProgress
197
+ - downloadProgress
198
+ - error
199
+ */
90
200
  stream: GotStream;
201
+ /**
202
+ Returns an async iterator.
203
+
204
+ See pagination.options for more pagination options.
205
+
206
+ @example
207
+ ```
208
+ (async () => {
209
+ const countLimit = 10;
210
+
211
+ const pagination = got.paginate('https://api.github.com/repos/sindresorhus/got/commits', {
212
+ pagination: {countLimit}
213
+ });
214
+
215
+ console.log(`Printing latest ${countLimit} Got commits (newest to oldest):`);
216
+
217
+ for await (const commitData of pagination) {
218
+ console.log(commitData.commit.message);
219
+ }
220
+ })();
221
+ ```
222
+ */
91
223
  paginate: GotPaginate;
224
+ /**
225
+ The Got defaults used in that instance.
226
+ */
92
227
  defaults: InstanceDefaults;
228
+ /**
229
+ An error to be thrown when a cache method fails.
230
+ For example, if the database goes down or there's a filesystem error.
231
+ */
93
232
  CacheError: typeof CacheError;
233
+ /**
234
+ An error to be thrown when a request fails.
235
+ Contains a `code` property with error class code, like `ECONNREFUSED`.
236
+ */
94
237
  RequestError: typeof RequestError;
238
+ /**
239
+ An error to be thrown when reading from response stream fails.
240
+ */
95
241
  ReadError: typeof ReadError;
242
+ /**
243
+ An error to be thrown when server response code is 2xx, and parsing body fails.
244
+ Includes a `response` property.
245
+ */
96
246
  ParseError: typeof ParseError;
247
+ /**
248
+ An error to be thrown when the server response code is not 2xx nor 3xx if `options.followRedirect` is `true`, but always except for 304.
249
+ Includes a `response` property.
250
+ */
97
251
  HTTPError: typeof HTTPError;
252
+ /**
253
+ An error to be thrown when the server redirects you more than ten times.
254
+ Includes a `response` property.
255
+ */
98
256
  MaxRedirectsError: typeof MaxRedirectsError;
257
+ /**
258
+ An error to be thrown when given an unsupported protocol.
259
+ */
260
+ UnsupportedProtocolError: typeof UnsupportedProtocolError;
261
+ /**
262
+ An error to be thrown when the request is aborted due to a timeout.
263
+ Includes an `event` and `timings` property.
264
+ */
99
265
  TimeoutError: typeof TimeoutError;
266
+ /**
267
+ An error to be thrown when the request body is a stream and an error occurs while reading from that stream.
268
+ */
269
+ UploadError: typeof UploadError;
270
+ /**
271
+ An error to be thrown when the request is aborted with `.cancel()`.
272
+ */
100
273
  CancelError: typeof CancelError;
101
- extend(...instancesOrOptions: Array<Got | ExtendOptions>): Got;
102
- mergeInstances(parent: Got, ...instances: Got[]): Got;
103
- mergeOptions(...sources: Options[]): NormalizedOptions;
274
+ /**
275
+ Configure a new `got` instance with default `options`.
276
+ The `options` are merged with the parent instance's `defaults.options` using `got.mergeOptions`.
277
+ You can access the resolved options with the `.defaults` property on the instance.
278
+
279
+ Additionally, `got.extend()` accepts two properties from the `defaults` object: `mutableDefaults` and `handlers`.
280
+
281
+ It is also possible to merges many instances into a single one:
282
+ - options are merged using `got.mergeOptions()` (including hooks),
283
+ - handlers are stored in an array (you can access them through `instance.defaults.handlers`).
284
+
285
+ @example
286
+ ```js
287
+ const client = got.extend({
288
+ prefixUrl: 'https://example.com',
289
+ headers: {
290
+ 'x-unicorn': 'rainbow'
291
+ }
292
+ });
293
+
294
+ client.get('demo');
295
+
296
+ // HTTP Request =>
297
+ // GET /demo HTTP/1.1
298
+ // Host: example.com
299
+ // x-unicorn: rainbow
300
+ ```
301
+ */
302
+ extend: (...instancesOrOptions: Array<Got | ExtendOptions>) => Got;
303
+ /**
304
+ Merges multiple `got` instances into the parent.
305
+ */
306
+ mergeInstances: (parent: Got, ...instances: Got[]) => Got;
307
+ /**
308
+ Extends parent options.
309
+ Avoid using [object spread](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax#Spread_in_object_literals) as it doesn't work recursively.
310
+
311
+ Options are deeply merged to a new object. The value of each key is determined as follows:
312
+
313
+ - If the new property is not defined, the old value is used.
314
+ - If the new property is explicitly set to `undefined`:
315
+ - If the parent property is a plain `object`, the parent value is deeply cloned.
316
+ - Otherwise, `undefined` is used.
317
+ - If the parent value is an instance of `URLSearchParams`:
318
+ - If the new value is a `string`, an `object` or an instance of `URLSearchParams`, a new `URLSearchParams` instance is created.
319
+ The values are merged using [`urlSearchParams.append(key, value)`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/append).
320
+ The keys defined in the new value override the keys defined in the parent value.
321
+ - Otherwise, the only available value is `undefined`.
322
+ - If the new property is a plain `object`:
323
+ - If the parent property is a plain `object` too, both values are merged recursively into a new `object`.
324
+ - Otherwise, only the new value is deeply cloned.
325
+ - If the new property is an `Array`, it overwrites the old one with a deep clone of the new property.
326
+ - Properties that are not enumerable, such as `context`, `body`, `json`, and `form`, will not be merged.
327
+ - Otherwise, the new value is assigned to the key.
328
+
329
+ **Note:** Only Got options are merged! Custom user options should be defined via [`options.context`](#context).
330
+
331
+ @example
332
+ ```
333
+ const a = {headers: {cat: 'meow', wolf: ['bark', 'wrrr']}};
334
+ const b = {headers: {cow: 'moo', wolf: ['auuu']}};
335
+
336
+ {...a, ...b} // => {headers: {cow: 'moo', wolf: ['auuu']}}
337
+ got.mergeOptions(a, b) // => {headers: {cat: 'meow', cow: 'moo', wolf: ['auuu']}}
338
+ ```
339
+ */
340
+ mergeOptions: (...sources: Options[]) => NormalizedOptions;
104
341
  }
105
342
  export {};
@@ -1 +1 @@
1
- export default function deepFreeze<T extends object>(object: T): Readonly<T>;
1
+ export default function deepFreeze<T extends Record<string, any>>(object: T): Readonly<T>;
@@ -6,7 +6,7 @@ exports.default = (message) => {
6
6
  return;
7
7
  }
8
8
  alreadyWarned.add(message);
9
- // @ts-ignore Missing types.
9
+ // @ts-expect-error Missing types.
10
10
  process.emitWarning(`Got: ${message}`, {
11
11
  type: 'DeprecationWarning'
12
12
  });