got 11.5.1 → 11.6.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/source/as-promise/create-rejection.d.ts +0 -0
- package/dist/source/as-promise/create-rejection.js +0 -0
- package/dist/source/as-promise/index.d.ts +1 -3
- package/dist/source/as-promise/index.js +44 -125
- package/dist/source/as-promise/normalize-arguments.d.ts +3 -0
- package/dist/source/as-promise/normalize-arguments.js +78 -0
- package/dist/source/as-promise/parse-body.d.ts +3 -0
- package/dist/source/as-promise/parse-body.js +25 -0
- package/dist/source/as-promise/types.d.ts +206 -24
- package/dist/source/as-promise/types.js +18 -7
- package/dist/source/{as-promise → core}/calculate-retry-delay.d.ts +2 -1
- package/dist/source/core/calculate-retry-delay.js +29 -0
- package/dist/source/core/index.d.ts +822 -5
- package/dist/source/core/index.js +234 -46
- package/dist/source/core/utils/dns-ip-version.d.ts +0 -0
- package/dist/source/core/utils/dns-ip-version.js +0 -0
- package/dist/source/core/utils/get-body-size.d.ts +0 -0
- package/dist/source/core/utils/get-body-size.js +0 -0
- package/dist/source/core/utils/get-buffer.d.ts +0 -0
- package/dist/source/core/utils/get-buffer.js +0 -0
- package/dist/source/core/utils/is-form-data.d.ts +0 -0
- package/dist/source/core/utils/is-form-data.js +0 -0
- package/dist/source/core/utils/is-response-ok.d.ts +2 -0
- package/dist/source/core/utils/is-response-ok.js +8 -0
- package/dist/source/core/utils/options-to-url.d.ts +0 -0
- package/dist/source/core/utils/options-to-url.js +0 -0
- package/dist/source/core/utils/proxy-events.d.ts +0 -0
- package/dist/source/core/utils/proxy-events.js +0 -0
- package/dist/source/core/utils/timed-out.d.ts +0 -0
- package/dist/source/core/utils/timed-out.js +0 -0
- package/dist/source/core/utils/unhandle.d.ts +0 -0
- package/dist/source/core/utils/unhandle.js +0 -0
- package/dist/source/core/utils/url-to-options.d.ts +0 -0
- package/dist/source/core/utils/url-to-options.js +0 -0
- package/dist/source/core/utils/weakable-map.d.ts +0 -0
- package/dist/source/core/utils/weakable-map.js +0 -0
- package/dist/source/create.d.ts +0 -0
- package/dist/source/create.js +22 -14
- package/dist/source/index.d.ts +0 -0
- package/dist/source/index.js +3 -2
- package/dist/source/types.d.ts +240 -1
- package/dist/source/types.js +0 -0
- package/dist/source/utils/deep-freeze.d.ts +0 -0
- package/dist/source/utils/deep-freeze.js +0 -0
- package/dist/source/utils/deprecation-warning.d.ts +0 -0
- package/dist/source/utils/deprecation-warning.js +0 -0
- package/license +0 -0
- package/package.json +20 -16
- package/readme.md +180 -40
- package/dist/source/as-promise/calculate-retry-delay.js +0 -38
- package/dist/source/as-promise/core.d.ts +0 -13
- package/dist/source/as-promise/core.js +0 -127
package/dist/source/create.js
CHANGED
|
@@ -7,11 +7,10 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
7
7
|
o[k2] = m[k];
|
|
8
8
|
}));
|
|
9
9
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.defaultHandler = void 0;
|
|
14
|
-
const p_cancelable_1 = require("p-cancelable");
|
|
15
14
|
const is_1 = require("@sindresorhus/is");
|
|
16
15
|
const as_promise_1 = require("./as-promise");
|
|
17
16
|
const create_rejection_1 = require("./as-promise/create-rejection");
|
|
@@ -25,14 +24,23 @@ const errors = {
|
|
|
25
24
|
MaxRedirectsError: as_promise_1.MaxRedirectsError,
|
|
26
25
|
TimeoutError: as_promise_1.TimeoutError,
|
|
27
26
|
ParseError: as_promise_1.ParseError,
|
|
28
|
-
CancelError:
|
|
27
|
+
CancelError: as_promise_1.CancelError,
|
|
29
28
|
UnsupportedProtocolError: as_promise_1.UnsupportedProtocolError,
|
|
30
29
|
UploadError: as_promise_1.UploadError
|
|
31
30
|
};
|
|
32
31
|
// The `delay` package weighs 10KB (!)
|
|
33
|
-
const delay = async (ms) => new Promise(resolve =>
|
|
34
|
-
|
|
35
|
-
|
|
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);
|
|
36
44
|
const isGotInstance = (value) => ('defaults' in value && 'options' in value.defaults);
|
|
37
45
|
const aliases = [
|
|
38
46
|
'get',
|
|
@@ -74,7 +82,7 @@ const create = (defaults) => {
|
|
|
74
82
|
return result;
|
|
75
83
|
}));
|
|
76
84
|
// Got interface
|
|
77
|
-
const got = ((url, options) => {
|
|
85
|
+
const got = ((url, options, _defaults) => {
|
|
78
86
|
var _a, _b;
|
|
79
87
|
let iteration = 0;
|
|
80
88
|
const iterateHandlers = (newOptions) => {
|
|
@@ -101,7 +109,7 @@ const create = (defaults) => {
|
|
|
101
109
|
initHookError = error;
|
|
102
110
|
}
|
|
103
111
|
// Normalize options & call handlers
|
|
104
|
-
const normalizedOptions = normalizeArguments(url, options, defaults.options);
|
|
112
|
+
const normalizedOptions = normalizeArguments(url, options, _defaults !== null && _defaults !== void 0 ? _defaults : defaults.options);
|
|
105
113
|
normalizedOptions[core_1.kIsNormalizedAlready] = true;
|
|
106
114
|
if (initHookError) {
|
|
107
115
|
throw new as_promise_1.RequestError(initHookError.message, initHookError, normalizedOptions);
|
|
@@ -164,9 +172,10 @@ const create = (defaults) => {
|
|
|
164
172
|
// eslint-disable-next-line no-await-in-loop
|
|
165
173
|
await delay(pagination.backoff);
|
|
166
174
|
}
|
|
175
|
+
// @ts-expect-error FIXME!
|
|
167
176
|
// TODO: Throw when result is not an instance of Response
|
|
168
177
|
// eslint-disable-next-line no-await-in-loop
|
|
169
|
-
const result = (await got(normalizedOptions));
|
|
178
|
+
const result = (await got(undefined, undefined, normalizedOptions));
|
|
170
179
|
// eslint-disable-next-line no-await-in-loop
|
|
171
180
|
const parsed = await pagination.transform(result);
|
|
172
181
|
const current = [];
|
|
@@ -198,12 +207,10 @@ const create = (defaults) => {
|
|
|
198
207
|
numberOfRequests++;
|
|
199
208
|
}
|
|
200
209
|
});
|
|
201
|
-
got.paginate =
|
|
202
|
-
return paginateEach(url, options);
|
|
203
|
-
});
|
|
210
|
+
got.paginate = paginateEach;
|
|
204
211
|
got.paginate.all = (async (url, options) => {
|
|
205
212
|
const results = [];
|
|
206
|
-
for await (const item of
|
|
213
|
+
for await (const item of paginateEach(url, options)) {
|
|
207
214
|
results.push(item);
|
|
208
215
|
}
|
|
209
216
|
return results;
|
|
@@ -219,13 +226,14 @@ const create = (defaults) => {
|
|
|
219
226
|
return got(url, { ...options, method, isStream: true });
|
|
220
227
|
});
|
|
221
228
|
}
|
|
222
|
-
Object.assign(got,
|
|
229
|
+
Object.assign(got, errors);
|
|
223
230
|
Object.defineProperty(got, 'defaults', {
|
|
224
231
|
value: defaults.mutableDefaults ? defaults : deep_freeze_1.default(defaults),
|
|
225
232
|
writable: defaults.mutableDefaults,
|
|
226
233
|
configurable: defaults.mutableDefaults,
|
|
227
234
|
enumerable: true
|
|
228
235
|
});
|
|
236
|
+
got.mergeOptions = mergeOptions;
|
|
229
237
|
return got;
|
|
230
238
|
};
|
|
231
239
|
exports.default = create;
|
package/dist/source/index.d.ts
CHANGED
|
File without changes
|
package/dist/source/index.js
CHANGED
|
@@ -7,7 +7,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
7
7
|
o[k2] = m[k];
|
|
8
8
|
}));
|
|
9
9
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
const url_1 = require("url");
|
|
@@ -116,7 +116,8 @@ const defaults = {
|
|
|
116
116
|
stackAllItems: true
|
|
117
117
|
},
|
|
118
118
|
parseJson: (text) => JSON.parse(text),
|
|
119
|
-
stringifyJson: (object) => JSON.stringify(object)
|
|
119
|
+
stringifyJson: (object) => JSON.stringify(object),
|
|
120
|
+
cacheOptions: {}
|
|
120
121
|
},
|
|
121
122
|
handlers: [create_1.defaultHandler],
|
|
122
123
|
mutableDefaults: false
|
package/dist/source/types.d.ts
CHANGED
|
@@ -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,10 +86,60 @@ 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
|
+
*/
|
|
48
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
|
+
*/
|
|
49
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
|
+
*/
|
|
50
139
|
<T, R = unknown>(url: string | URL, options?: OptionsWithPagination<T, R>): AsyncIterableIterator<T>;
|
|
140
|
+
/**
|
|
141
|
+
Same as `GotPaginate.each`.
|
|
142
|
+
*/
|
|
51
143
|
<T, R = unknown>(options?: OptionsWithPagination<T, R>): AsyncIterableIterator<T>;
|
|
52
144
|
}
|
|
53
145
|
export interface GotRequestFunction {
|
|
@@ -74,6 +166,9 @@ export interface GotRequestFunction {
|
|
|
74
166
|
(url: string | URL, options?: Options): CancelableRequest | Request;
|
|
75
167
|
(options: Options): CancelableRequest | Request;
|
|
76
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
All available HTTP request methods provided by Got.
|
|
171
|
+
*/
|
|
77
172
|
export declare type HTTPAlias = 'get' | 'post' | 'put' | 'patch' | 'head' | 'delete';
|
|
78
173
|
interface GotStreamFunction {
|
|
79
174
|
(url: string | URL, options?: Merge<Options, {
|
|
@@ -83,21 +178,165 @@ interface GotStreamFunction {
|
|
|
83
178
|
isStream?: true;
|
|
84
179
|
}>): Request;
|
|
85
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
An instance of `got.stream()`.
|
|
183
|
+
*/
|
|
86
184
|
export declare type GotStream = GotStreamFunction & Record<HTTPAlias, GotStreamFunction>;
|
|
185
|
+
/**
|
|
186
|
+
An instance of `got`.
|
|
187
|
+
*/
|
|
87
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
|
+
*/
|
|
88
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
|
+
*/
|
|
89
223
|
paginate: GotPaginate;
|
|
224
|
+
/**
|
|
225
|
+
The Got defaults used in that instance.
|
|
226
|
+
*/
|
|
90
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
|
+
*/
|
|
91
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
|
+
*/
|
|
92
237
|
RequestError: typeof RequestError;
|
|
238
|
+
/**
|
|
239
|
+
An error to be thrown when reading from response stream fails.
|
|
240
|
+
*/
|
|
93
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
|
+
*/
|
|
94
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
|
+
*/
|
|
95
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
|
+
*/
|
|
96
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
|
+
*/
|
|
97
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
|
+
*/
|
|
98
273
|
CancelError: typeof CancelError;
|
|
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
|
+
*/
|
|
99
302
|
extend: (...instancesOrOptions: Array<Got | ExtendOptions>) => Got;
|
|
303
|
+
/**
|
|
304
|
+
Merges multiple `got` instances into the parent.
|
|
305
|
+
*/
|
|
100
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
|
+
*/
|
|
101
340
|
mergeOptions: (...sources: Options[]) => NormalizedOptions;
|
|
102
341
|
}
|
|
103
342
|
export {};
|
package/dist/source/types.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/license
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "got",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.6.2",
|
|
4
4
|
"description": "Human-friendly and powerful HTTP request library for Node.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "sindresorhus/got",
|
|
@@ -43,14 +43,14 @@
|
|
|
43
43
|
"ky"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@sindresorhus/is": "^3.
|
|
46
|
+
"@sindresorhus/is": "^3.1.1",
|
|
47
47
|
"@szmarczak/http-timer": "^4.0.5",
|
|
48
48
|
"@types/cacheable-request": "^6.0.1",
|
|
49
49
|
"@types/responselike": "^1.0.0",
|
|
50
50
|
"cacheable-lookup": "^5.0.3",
|
|
51
51
|
"cacheable-request": "^7.0.1",
|
|
52
52
|
"decompress-response": "^6.0.0",
|
|
53
|
-
"http2-wrapper": "^1.0.0-beta.5.
|
|
53
|
+
"http2-wrapper": "^1.0.0-beta.5.2",
|
|
54
54
|
"lowercase-keys": "^2.0.0",
|
|
55
55
|
"p-cancelable": "^2.0.0",
|
|
56
56
|
"responselike": "^2.0.0"
|
|
@@ -60,34 +60,38 @@
|
|
|
60
60
|
"@sindresorhus/tsconfig": "^0.7.0",
|
|
61
61
|
"@sinonjs/fake-timers": "^6.0.1",
|
|
62
62
|
"@types/benchmark": "^1.0.33",
|
|
63
|
-
"@types/express": "^4.17.
|
|
64
|
-
"@types/node": "^14.0
|
|
63
|
+
"@types/express": "^4.17.7",
|
|
64
|
+
"@types/node": "^14.6.0",
|
|
65
65
|
"@types/node-fetch": "^2.5.7",
|
|
66
|
+
"@types/pem": "^1.9.5",
|
|
67
|
+
"@types/pify": "^3.0.2",
|
|
66
68
|
"@types/request": "^2.48.5",
|
|
67
|
-
"@types/sinon": "^9.0.
|
|
69
|
+
"@types/sinon": "^9.0.5",
|
|
68
70
|
"@types/tough-cookie": "^4.0.0",
|
|
69
|
-
"ava": "^3.
|
|
70
|
-
"axios": "^0.
|
|
71
|
+
"ava": "^3.11.1",
|
|
72
|
+
"axios": "^0.20.0",
|
|
71
73
|
"benchmark": "^2.1.4",
|
|
72
74
|
"coveralls": "^3.1.0",
|
|
73
75
|
"create-test-server": "^3.0.1",
|
|
74
76
|
"del-cli": "^3.0.1",
|
|
75
|
-
"delay": "^4.
|
|
77
|
+
"delay": "^4.4.0",
|
|
76
78
|
"express": "^4.17.1",
|
|
77
79
|
"form-data": "^3.0.0",
|
|
78
|
-
"get-stream": "^
|
|
79
|
-
"nock": "^13.0.
|
|
80
|
+
"get-stream": "^6.0.0",
|
|
81
|
+
"nock": "^13.0.4",
|
|
80
82
|
"node-fetch": "^2.6.0",
|
|
81
|
-
"np": "^6.
|
|
83
|
+
"np": "^6.4.0",
|
|
82
84
|
"nyc": "^15.1.0",
|
|
83
85
|
"p-event": "^4.2.0",
|
|
84
|
-
"
|
|
86
|
+
"pem": "^1.14.4",
|
|
87
|
+
"pify": "^5.0.0",
|
|
88
|
+
"sinon": "^9.0.3",
|
|
85
89
|
"slow-stream": "0.0.4",
|
|
86
|
-
"tempy": "^0.
|
|
90
|
+
"tempy": "^0.6.0",
|
|
87
91
|
"to-readable-stream": "^2.1.0",
|
|
88
92
|
"tough-cookie": "^4.0.0",
|
|
89
|
-
"typescript": "
|
|
90
|
-
"xo": "^0.
|
|
93
|
+
"typescript": "^4.0.2",
|
|
94
|
+
"xo": "^0.33.0"
|
|
91
95
|
},
|
|
92
96
|
"types": "dist/source",
|
|
93
97
|
"sideEffects": false,
|