got 10.5.7 → 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/dist/source/{calculate-retry-delay.d.ts → as-promise/calculate-retry-delay.d.ts} +0 -0
- package/dist/source/{calculate-retry-delay.js → as-promise/calculate-retry-delay.js} +6 -7
- package/dist/source/as-promise/core.d.ts +13 -0
- package/dist/source/as-promise/core.js +124 -0
- package/dist/source/as-promise/create-rejection.d.ts +2 -0
- package/dist/source/as-promise/create-rejection.js +30 -0
- package/dist/source/as-promise/index.d.ts +5 -0
- package/dist/source/as-promise/index.js +203 -0
- package/dist/source/as-promise/types.d.ts +77 -0
- package/dist/source/as-promise/types.js +27 -0
- package/dist/source/core/index.d.ts +272 -0
- package/dist/source/core/index.js +1091 -0
- package/dist/source/{utils → core/utils}/get-body-size.d.ts +0 -0
- package/dist/source/{utils → core/utils}/get-body-size.js +0 -0
- package/dist/source/core/utils/is-form-data.d.ts +8 -0
- package/dist/source/{utils → core/utils}/is-form-data.js +0 -0
- package/dist/source/core/utils/options-to-url.d.ts +15 -0
- package/dist/source/{utils → core/utils}/options-to-url.js +5 -34
- package/dist/source/core/utils/proxy-events.d.ts +3 -0
- package/dist/source/core/utils/proxy-events.js +17 -0
- package/dist/source/{utils → core/utils}/timed-out.d.ts +0 -0
- package/dist/source/{utils → core/utils}/timed-out.js +2 -5
- package/dist/source/{utils → core/utils}/unhandle.d.ts +1 -1
- package/dist/source/{utils → core/utils}/unhandle.js +0 -0
- package/dist/source/{utils → core/utils}/url-to-options.d.ts +0 -0
- package/dist/source/{utils → core/utils}/url-to-options.js +0 -0
- package/dist/source/core/utils/weakable-map.d.ts +8 -0
- package/dist/source/core/utils/weakable-map.js +29 -0
- package/dist/source/create.d.ts +3 -79
- package/dist/source/create.js +83 -39
- package/dist/source/index.d.ts +3 -6
- package/dist/source/index.js +13 -19
- package/dist/source/types.d.ts +84 -198
- package/dist/source/types.js +0 -1
- package/package.json +41 -37
- package/readme.md +211 -97
- package/dist/source/as-promise.d.ts +0 -3
- package/dist/source/as-promise.js +0 -152
- package/dist/source/as-stream.d.ts +0 -7
- package/dist/source/as-stream.js +0 -121
- package/dist/source/errors.d.ts +0 -41
- package/dist/source/errors.js +0 -103
- package/dist/source/get-response.d.ts +0 -6
- package/dist/source/get-response.js +0 -25
- package/dist/source/known-hook-events.d.ts +0 -88
- package/dist/source/known-hook-events.js +0 -11
- package/dist/source/normalize-arguments.d.ts +0 -19
- package/dist/source/normalize-arguments.js +0 -436
- package/dist/source/progress.d.ts +0 -4
- package/dist/source/progress.js +0 -40
- package/dist/source/request-as-event-emitter.d.ts +0 -12
- package/dist/source/request-as-event-emitter.js +0 -284
- package/dist/source/utils/dynamic-require.d.ts +0 -3
- package/dist/source/utils/dynamic-require.js +0 -4
- package/dist/source/utils/is-form-data.d.ts +0 -3
- package/dist/source/utils/merge.d.ts +0 -6
- package/dist/source/utils/merge.js +0 -35
- package/dist/source/utils/options-to-url.d.ts +0 -19
- package/dist/source/utils/supports-brotli.d.ts +0 -2
- package/dist/source/utils/supports-brotli.js +0 -4
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Readable } from 'stream';
|
|
3
|
+
interface FormData extends Readable {
|
|
4
|
+
getBoundary(): string;
|
|
5
|
+
getLength(callback: (error: Error | null, length: number) => void): void;
|
|
6
|
+
}
|
|
7
|
+
declare const _default: (body: unknown) => body is FormData;
|
|
8
|
+
export default _default;
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { URL } from 'url';
|
|
3
|
+
export interface URLOptions {
|
|
4
|
+
href?: string;
|
|
5
|
+
protocol?: string;
|
|
6
|
+
host?: string;
|
|
7
|
+
hostname?: string;
|
|
8
|
+
port?: string | number;
|
|
9
|
+
pathname?: string;
|
|
10
|
+
search?: string;
|
|
11
|
+
searchParams?: unknown;
|
|
12
|
+
path?: string;
|
|
13
|
+
}
|
|
14
|
+
declare const _default: (origin: string, options: URLOptions) => URL;
|
|
15
|
+
export default _default;
|
|
@@ -1,27 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/* istanbul ignore file: deprecated */
|
|
3
4
|
const url_1 = require("url");
|
|
4
|
-
function validateSearchParams(searchParams) {
|
|
5
|
-
for (const value of Object.values(searchParams)) {
|
|
6
|
-
if (typeof value !== 'string' && typeof value !== 'number' && typeof value !== 'boolean' && value !== null) {
|
|
7
|
-
throw new TypeError(`The \`searchParams\` value '${String(value)}' must be a string, number, boolean or null`);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
5
|
const keys = [
|
|
12
6
|
'protocol',
|
|
13
|
-
'username',
|
|
14
|
-
'password',
|
|
15
7
|
'host',
|
|
16
8
|
'hostname',
|
|
17
9
|
'port',
|
|
18
10
|
'pathname',
|
|
19
|
-
'search'
|
|
20
|
-
'hash'
|
|
11
|
+
'search'
|
|
21
12
|
];
|
|
22
|
-
exports.default = (options) => {
|
|
13
|
+
exports.default = (origin, options) => {
|
|
23
14
|
var _a, _b;
|
|
24
|
-
let origin;
|
|
25
15
|
if (options.path) {
|
|
26
16
|
if (options.pathname) {
|
|
27
17
|
throw new TypeError('Parameters `path` and `pathname` are mutually exclusive.');
|
|
@@ -33,19 +23,10 @@ exports.default = (options) => {
|
|
|
33
23
|
throw new TypeError('Parameters `path` and `searchParams` are mutually exclusive.');
|
|
34
24
|
}
|
|
35
25
|
}
|
|
36
|
-
if (Reflect.has(options, 'auth')) {
|
|
37
|
-
throw new TypeError('Parameter `auth` is deprecated. Use `username` / `password` instead.');
|
|
38
|
-
}
|
|
39
26
|
if (options.search && options.searchParams) {
|
|
40
27
|
throw new TypeError('Parameters `search` and `searchParams` are mutually exclusive.');
|
|
41
28
|
}
|
|
42
|
-
if (
|
|
43
|
-
return new url_1.URL(options.href);
|
|
44
|
-
}
|
|
45
|
-
if (options.origin) {
|
|
46
|
-
origin = options.origin;
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
29
|
+
if (!origin) {
|
|
49
30
|
if (!options.protocol) {
|
|
50
31
|
throw new TypeError('No URL protocol specified');
|
|
51
32
|
}
|
|
@@ -61,22 +42,12 @@ exports.default = (options) => {
|
|
|
61
42
|
options.pathname = options.path.slice(0, searchIndex);
|
|
62
43
|
options.search = options.path.slice(searchIndex + 1);
|
|
63
44
|
}
|
|
64
|
-
}
|
|
65
|
-
if (Reflect.has(options, 'path')) {
|
|
66
45
|
delete options.path;
|
|
67
46
|
}
|
|
68
47
|
for (const key of keys) {
|
|
69
|
-
if (
|
|
48
|
+
if (options[key]) {
|
|
70
49
|
url[key] = options[key].toString();
|
|
71
50
|
}
|
|
72
51
|
}
|
|
73
|
-
if (options.searchParams) {
|
|
74
|
-
if (typeof options.searchParams !== 'string' && !(options.searchParams instanceof url_1.URLSearchParams)) {
|
|
75
|
-
validateSearchParams(options.searchParams);
|
|
76
|
-
}
|
|
77
|
-
(new url_1.URLSearchParams(options.searchParams)).forEach((value, key) => {
|
|
78
|
-
url.searchParams.append(key, value);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
52
|
return url;
|
|
82
53
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function default_1(from, to, events) {
|
|
4
|
+
const fns = {};
|
|
5
|
+
for (const event of events) {
|
|
6
|
+
fns[event] = (...args) => {
|
|
7
|
+
to.emit(event, ...args);
|
|
8
|
+
};
|
|
9
|
+
from.on(event, fns[event]);
|
|
10
|
+
}
|
|
11
|
+
return () => {
|
|
12
|
+
for (const event of events) {
|
|
13
|
+
from.off(event, fns[event]);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
exports.default = default_1;
|
|
File without changes
|
|
@@ -14,7 +14,7 @@ class TimeoutError extends Error {
|
|
|
14
14
|
}
|
|
15
15
|
exports.TimeoutError = TimeoutError;
|
|
16
16
|
exports.default = (request, delays, options) => {
|
|
17
|
-
if (
|
|
17
|
+
if (reentry in request) {
|
|
18
18
|
return noop;
|
|
19
19
|
}
|
|
20
20
|
request[reentry] = true;
|
|
@@ -33,11 +33,9 @@ exports.default = (request, delays, options) => {
|
|
|
33
33
|
const { host, hostname } = options;
|
|
34
34
|
const timeoutHandler = (delay, event) => {
|
|
35
35
|
if (request.socket) {
|
|
36
|
-
// @ts-ignore We do not want the `socket hang up` error
|
|
37
36
|
request.socket._hadError = true;
|
|
38
37
|
}
|
|
39
|
-
request.
|
|
40
|
-
request.emit('error', new TimeoutError(delay, event));
|
|
38
|
+
request.destroy(new TimeoutError(delay, event));
|
|
41
39
|
};
|
|
42
40
|
const cancelTimeouts = () => {
|
|
43
41
|
for (const cancel of cancelers) {
|
|
@@ -73,7 +71,6 @@ exports.default = (request, delays, options) => {
|
|
|
73
71
|
}
|
|
74
72
|
once(request, 'socket', (socket) => {
|
|
75
73
|
var _a;
|
|
76
|
-
// @ts-ignore Node typings doesn't have this property
|
|
77
74
|
const { socketPath } = request;
|
|
78
75
|
/* istanbul ignore next: hard to test */
|
|
79
76
|
if (socket.connecting) {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class WeakableMap {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.weakMap = new WeakMap();
|
|
6
|
+
this.map = new Map();
|
|
7
|
+
}
|
|
8
|
+
set(key, value) {
|
|
9
|
+
if (typeof key === 'object') {
|
|
10
|
+
this.weakMap.set(key, value);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
this.map.set(key, value);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
get(key) {
|
|
17
|
+
if (typeof key === 'object') {
|
|
18
|
+
return this.weakMap.get(key);
|
|
19
|
+
}
|
|
20
|
+
return this.map.get(key);
|
|
21
|
+
}
|
|
22
|
+
has(key) {
|
|
23
|
+
if (typeof key === 'object') {
|
|
24
|
+
return this.weakMap.has(key);
|
|
25
|
+
}
|
|
26
|
+
return this.map.has(key);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.default = WeakableMap;
|
package/dist/source/create.d.ts
CHANGED
|
@@ -1,81 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import { Merge } from 'type-fest';
|
|
3
|
-
import { ProxyStream } from './as-stream';
|
|
4
|
-
import * as errors from './errors';
|
|
5
|
-
import { CancelableRequest, Defaults, ExtendOptions, HandlerFunction, NormalizedOptions, Options, Response, URLOrOptions, PaginationOptions } from './types';
|
|
6
|
-
export declare type HTTPAlias = 'get' | 'post' | 'put' | 'patch' | 'head' | 'delete';
|
|
7
|
-
export declare type ReturnStream = <T>(url: string | Merge<Options, {
|
|
8
|
-
isStream?: true;
|
|
9
|
-
}>, options?: Merge<Options, {
|
|
10
|
-
isStream?: true;
|
|
11
|
-
}>) => ProxyStream<T>;
|
|
12
|
-
export declare type GotReturn<T = unknown> = CancelableRequest<T> | ProxyStream<T>;
|
|
13
|
-
export declare type OptionsOfDefaultResponseBody = Merge<Options, {
|
|
14
|
-
isStream?: false;
|
|
15
|
-
resolveBodyOnly?: false;
|
|
16
|
-
responseType?: 'default';
|
|
17
|
-
}>;
|
|
18
|
-
declare type OptionsOfTextResponseBody = Merge<Options, {
|
|
19
|
-
isStream?: false;
|
|
20
|
-
resolveBodyOnly?: false;
|
|
21
|
-
responseType: 'text';
|
|
22
|
-
}>;
|
|
23
|
-
declare type OptionsOfJSONResponseBody = Merge<Options, {
|
|
24
|
-
isStream?: false;
|
|
25
|
-
resolveBodyOnly?: false;
|
|
26
|
-
responseType: 'json';
|
|
27
|
-
}>;
|
|
28
|
-
declare type OptionsOfBufferResponseBody = Merge<Options, {
|
|
29
|
-
isStream?: false;
|
|
30
|
-
resolveBodyOnly?: false;
|
|
31
|
-
responseType: 'buffer';
|
|
32
|
-
}>;
|
|
33
|
-
declare type ResponseBodyOnly = {
|
|
34
|
-
resolveBodyOnly: true;
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
Can be used to match methods explicitly or parameters extraction: `Parameters<GotRequestMethod>`.
|
|
38
|
-
*/
|
|
39
|
-
export interface GotRequestMethod {
|
|
40
|
-
<T = string>(url: string | OptionsOfDefaultResponseBody, options?: OptionsOfDefaultResponseBody): CancelableRequest<Response<T>>;
|
|
41
|
-
(url: string | OptionsOfTextResponseBody, options?: OptionsOfTextResponseBody): CancelableRequest<Response<string>>;
|
|
42
|
-
<T>(url: string | OptionsOfJSONResponseBody, options?: OptionsOfJSONResponseBody): CancelableRequest<Response<T>>;
|
|
43
|
-
(url: string | OptionsOfBufferResponseBody, options?: OptionsOfBufferResponseBody): CancelableRequest<Response<Buffer>>;
|
|
44
|
-
<T = string>(url: string | Merge<OptionsOfDefaultResponseBody, ResponseBodyOnly>, options?: Merge<OptionsOfDefaultResponseBody, ResponseBodyOnly>): CancelableRequest<T>;
|
|
45
|
-
(url: string | Merge<OptionsOfTextResponseBody, ResponseBodyOnly>, options?: Merge<OptionsOfTextResponseBody, ResponseBodyOnly>): CancelableRequest<string>;
|
|
46
|
-
<T>(url: string | Merge<OptionsOfJSONResponseBody, ResponseBodyOnly>, options?: Merge<OptionsOfJSONResponseBody, ResponseBodyOnly>): CancelableRequest<T>;
|
|
47
|
-
(url: string | Merge<OptionsOfBufferResponseBody, ResponseBodyOnly>, options?: Merge<OptionsOfBufferResponseBody, ResponseBodyOnly>): CancelableRequest<Buffer>;
|
|
48
|
-
<T>(url: string | Merge<Options, {
|
|
49
|
-
isStream: true;
|
|
50
|
-
}>, options?: Merge<Options, {
|
|
51
|
-
isStream: true;
|
|
52
|
-
}>): ProxyStream<T>;
|
|
53
|
-
}
|
|
54
|
-
export interface GotPaginate {
|
|
55
|
-
<T>(url: URLOrOptions & PaginationOptions<T>, options?: Options & PaginationOptions<T>): AsyncIterableIterator<T>;
|
|
56
|
-
all<T>(url: URLOrOptions & PaginationOptions<T>, options?: Options & PaginationOptions<T>): Promise<T[]>;
|
|
57
|
-
}
|
|
58
|
-
export interface Got extends Record<HTTPAlias, GotRequestMethod>, GotRequestMethod {
|
|
59
|
-
stream: GotStream;
|
|
60
|
-
paginate: GotPaginate;
|
|
61
|
-
defaults: Defaults;
|
|
62
|
-
GotError: typeof errors.GotError;
|
|
63
|
-
CacheError: typeof errors.CacheError;
|
|
64
|
-
RequestError: typeof errors.RequestError;
|
|
65
|
-
ReadError: typeof errors.ReadError;
|
|
66
|
-
ParseError: typeof errors.ParseError;
|
|
67
|
-
HTTPError: typeof errors.HTTPError;
|
|
68
|
-
MaxRedirectsError: typeof errors.MaxRedirectsError;
|
|
69
|
-
UnsupportedProtocolError: typeof errors.UnsupportedProtocolError;
|
|
70
|
-
TimeoutError: typeof errors.TimeoutError;
|
|
71
|
-
CancelError: typeof errors.CancelError;
|
|
72
|
-
extend(...instancesOrOptions: Array<Got | ExtendOptions>): Got;
|
|
73
|
-
mergeInstances(parent: Got, ...instances: Got[]): Got;
|
|
74
|
-
mergeOptions(...sources: Options[]): NormalizedOptions;
|
|
75
|
-
}
|
|
76
|
-
export interface GotStream extends Record<HTTPAlias, ReturnStream> {
|
|
77
|
-
(url: URLOrOptions, options?: Options): ProxyStream;
|
|
78
|
-
}
|
|
1
|
+
import { Got, HandlerFunction, InstanceDefaults } from './types';
|
|
79
2
|
export declare const defaultHandler: HandlerFunction;
|
|
80
|
-
declare const create: (defaults:
|
|
3
|
+
declare const create: (defaults: InstanceDefaults) => Got;
|
|
81
4
|
export default create;
|
|
5
|
+
export * from './types';
|
package/dist/source/create.js
CHANGED
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const p_cancelable_1 = require("p-cancelable");
|
|
3
4
|
const is_1 = require("@sindresorhus/is");
|
|
4
5
|
const as_promise_1 = require("./as-promise");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const normalize_arguments_1 = require("./normalize-arguments");
|
|
6
|
+
const create_rejection_1 = require("./as-promise/create-rejection");
|
|
7
|
+
const core_1 = require("./core");
|
|
8
8
|
const deep_freeze_1 = require("./utils/deep-freeze");
|
|
9
|
-
const
|
|
10
|
-
|
|
9
|
+
const errors = {
|
|
10
|
+
RequestError: as_promise_1.RequestError,
|
|
11
|
+
CacheError: as_promise_1.CacheError,
|
|
12
|
+
ReadError: as_promise_1.ReadError,
|
|
13
|
+
HTTPError: as_promise_1.HTTPError,
|
|
14
|
+
MaxRedirectsError: as_promise_1.MaxRedirectsError,
|
|
15
|
+
TimeoutError: as_promise_1.TimeoutError,
|
|
16
|
+
ParseError: as_promise_1.ParseError,
|
|
17
|
+
CancelError: p_cancelable_1.CancelError,
|
|
18
|
+
UnsupportedProtocolError: as_promise_1.UnsupportedProtocolError,
|
|
19
|
+
UploadError: as_promise_1.UploadError
|
|
20
|
+
};
|
|
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);
|
|
23
|
+
const isGotInstance = (value) => ('defaults' in value && 'options' in value.defaults);
|
|
11
24
|
const aliases = [
|
|
12
25
|
'get',
|
|
13
26
|
'post',
|
|
@@ -17,6 +30,13 @@ const aliases = [
|
|
|
17
30
|
'delete'
|
|
18
31
|
];
|
|
19
32
|
exports.defaultHandler = (options, next) => next(options);
|
|
33
|
+
const callInitHooks = (hooks, options) => {
|
|
34
|
+
if (hooks) {
|
|
35
|
+
for (const hook of hooks) {
|
|
36
|
+
hook(options);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
20
40
|
const create = (defaults) => {
|
|
21
41
|
// Proxy properties from next handlers
|
|
22
42
|
defaults._rawHandlers = defaults.handlers;
|
|
@@ -40,28 +60,50 @@ const create = (defaults) => {
|
|
|
40
60
|
}
|
|
41
61
|
return result;
|
|
42
62
|
}));
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
var _a;
|
|
63
|
+
const got = ((url, options = {}) => {
|
|
64
|
+
var _a, _b, _c, _d, _e;
|
|
46
65
|
let iteration = 0;
|
|
47
66
|
const iterateHandlers = (newOptions) => {
|
|
48
67
|
return defaults.handlers[iteration++](newOptions, iteration === defaults.handlers.length ? getPromiseOrStream : iterateHandlers);
|
|
49
68
|
};
|
|
50
|
-
|
|
69
|
+
if (is_1.default.plainObject(url)) {
|
|
70
|
+
options = {
|
|
71
|
+
...url,
|
|
72
|
+
...options
|
|
73
|
+
};
|
|
74
|
+
url = undefined;
|
|
75
|
+
}
|
|
51
76
|
try {
|
|
52
|
-
|
|
77
|
+
// Call `init` hooks
|
|
78
|
+
let initHookError;
|
|
79
|
+
try {
|
|
80
|
+
callInitHooks(defaults.options.hooks.init, options);
|
|
81
|
+
callInitHooks((_b = (_a = options) === null || _a === void 0 ? void 0 : _a.hooks) === null || _b === void 0 ? void 0 : _b.init, options);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
initHookError = error;
|
|
85
|
+
}
|
|
86
|
+
// Normalize options & call handlers
|
|
87
|
+
const normalizedOptions = normalizeArguments(url, options, defaults.options);
|
|
88
|
+
normalizedOptions[core_1.kIsNormalizedAlready] = true;
|
|
89
|
+
if (initHookError) {
|
|
90
|
+
throw new as_promise_1.RequestError(initHookError.message, initHookError, normalizedOptions);
|
|
91
|
+
}
|
|
92
|
+
// A bug.
|
|
93
|
+
// eslint-disable-next-line @typescript-eslint/return-await
|
|
94
|
+
return iterateHandlers(normalizedOptions);
|
|
53
95
|
}
|
|
54
96
|
catch (error) {
|
|
55
|
-
if ((
|
|
97
|
+
if ((_c = options) === null || _c === void 0 ? void 0 : _c.isStream) {
|
|
56
98
|
throw error;
|
|
57
99
|
}
|
|
58
100
|
else {
|
|
59
|
-
//
|
|
60
|
-
return
|
|
101
|
+
// A bug.
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/return-await
|
|
103
|
+
return create_rejection_1.default(error, defaults.options.hooks.beforeError, (_e = (_d = options) === null || _d === void 0 ? void 0 : _d.hooks) === null || _e === void 0 ? void 0 : _e.beforeError);
|
|
61
104
|
}
|
|
62
105
|
}
|
|
63
|
-
|
|
64
|
-
};
|
|
106
|
+
});
|
|
65
107
|
got.extend = (...instancesOrOptions) => {
|
|
66
108
|
const optionsArray = [defaults.options];
|
|
67
109
|
let handlers = [...defaults._rawHandlers];
|
|
@@ -74,7 +116,7 @@ const create = (defaults) => {
|
|
|
74
116
|
}
|
|
75
117
|
else {
|
|
76
118
|
optionsArray.push(value);
|
|
77
|
-
if (
|
|
119
|
+
if ('handlers' in value) {
|
|
78
120
|
handlers.push(...value.handlers);
|
|
79
121
|
}
|
|
80
122
|
isMutableDefaults = value.mutableDefaults;
|
|
@@ -85,61 +127,63 @@ const create = (defaults) => {
|
|
|
85
127
|
handlers.push(exports.defaultHandler);
|
|
86
128
|
}
|
|
87
129
|
return create({
|
|
88
|
-
options:
|
|
130
|
+
options: mergeOptions(...optionsArray),
|
|
89
131
|
handlers,
|
|
90
132
|
mutableDefaults: Boolean(isMutableDefaults)
|
|
91
133
|
});
|
|
92
134
|
};
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
got[method] = (url, options) => got(url, { ...options, method });
|
|
98
|
-
got.stream[method] = (url, options) => got.stream(url, { ...options, method });
|
|
99
|
-
}
|
|
100
|
-
// @ts-ignore The missing property is added below
|
|
101
|
-
got.paginate = async function* (url, options) {
|
|
102
|
-
let normalizedOptions = normalize_arguments_1.normalizeArguments(url, options, defaults);
|
|
103
|
-
const pagination = normalizedOptions._pagination;
|
|
135
|
+
got.paginate = (async function* (url, options) {
|
|
136
|
+
let normalizedOptions = normalizeArguments(url, options, defaults.options);
|
|
137
|
+
normalizedOptions.resolveBodyOnly = false;
|
|
138
|
+
const pagination = normalizedOptions.pagination;
|
|
104
139
|
if (!is_1.default.object(pagination)) {
|
|
105
|
-
throw new
|
|
140
|
+
throw new TypeError('`options.pagination` must be implemented');
|
|
106
141
|
}
|
|
107
142
|
const all = [];
|
|
108
143
|
while (true) {
|
|
109
|
-
//
|
|
144
|
+
// TODO: Throw when result is not an instance of Response
|
|
110
145
|
// eslint-disable-next-line no-await-in-loop
|
|
111
|
-
const result = await got(normalizedOptions);
|
|
146
|
+
const result = (await got('', normalizedOptions));
|
|
112
147
|
// eslint-disable-next-line no-await-in-loop
|
|
113
148
|
const parsed = await pagination.transform(result);
|
|
149
|
+
const current = [];
|
|
114
150
|
for (const item of parsed) {
|
|
115
|
-
if (pagination.filter(item, all)) {
|
|
116
|
-
if (!pagination.shouldContinue(item, all)) {
|
|
151
|
+
if (pagination.filter(item, all, current)) {
|
|
152
|
+
if (!pagination.shouldContinue(item, all, current)) {
|
|
117
153
|
return;
|
|
118
154
|
}
|
|
119
155
|
yield item;
|
|
120
156
|
all.push(item);
|
|
157
|
+
current.push(item);
|
|
121
158
|
if (all.length === pagination.countLimit) {
|
|
122
159
|
return;
|
|
123
160
|
}
|
|
124
161
|
}
|
|
125
162
|
}
|
|
126
|
-
const optionsToMerge = pagination.paginate(result);
|
|
163
|
+
const optionsToMerge = pagination.paginate(result, all, current);
|
|
127
164
|
if (optionsToMerge === false) {
|
|
128
165
|
return;
|
|
129
166
|
}
|
|
130
167
|
if (optionsToMerge !== undefined) {
|
|
131
|
-
normalizedOptions =
|
|
168
|
+
normalizedOptions = normalizeArguments(undefined, optionsToMerge, normalizedOptions);
|
|
132
169
|
}
|
|
133
170
|
}
|
|
134
|
-
};
|
|
135
|
-
got.paginate.all = async (url, options) => {
|
|
171
|
+
});
|
|
172
|
+
got.paginate.all = (async (url, options) => {
|
|
136
173
|
const results = [];
|
|
137
174
|
for await (const item of got.paginate(url, options)) {
|
|
138
175
|
results.push(item);
|
|
139
176
|
}
|
|
140
177
|
return results;
|
|
141
|
-
};
|
|
142
|
-
|
|
178
|
+
});
|
|
179
|
+
got.stream = ((url, options) => got(url, { ...options, isStream: true }));
|
|
180
|
+
for (const method of aliases) {
|
|
181
|
+
got[method] = ((url, options) => got(url, { ...options, method }));
|
|
182
|
+
got.stream[method] = ((url, options) => {
|
|
183
|
+
return got(url, { ...options, method, isStream: true });
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
Object.assign(got, { ...errors, mergeOptions });
|
|
143
187
|
Object.defineProperty(got, 'defaults', {
|
|
144
188
|
value: defaults.mutableDefaults ? defaults : deep_freeze_1.default(defaults),
|
|
145
189
|
writable: defaults.mutableDefaults,
|
package/dist/source/index.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
declare const got: import("./
|
|
1
|
+
declare const got: import("./types").Got;
|
|
2
2
|
export default got;
|
|
3
|
-
export * from './
|
|
4
|
-
export
|
|
5
|
-
export { ProxyStream as ResponseStream } from './as-stream';
|
|
6
|
-
export { GotError, CacheError, RequestError, ReadError, ParseError, HTTPError, MaxRedirectsError, UnsupportedProtocolError, TimeoutError, CancelError } from './errors';
|
|
7
|
-
export { InitHook, BeforeRequestHook, BeforeRedirectHook, BeforeRetryHook, BeforeErrorHook, AfterResponseHook, HookType, Hooks, HookEvent } from './known-hook-events';
|
|
3
|
+
export * from './create';
|
|
4
|
+
export * from './as-promise';
|
package/dist/source/index.js
CHANGED
|
@@ -4,6 +4,7 @@ function __export(m) {
|
|
|
4
4
|
}
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const url_1 = require("url");
|
|
7
|
+
const cacheable_lookup_1 = require("cacheable-lookup");
|
|
7
8
|
const create_1 = require("./create");
|
|
8
9
|
const defaults = {
|
|
9
10
|
options: {
|
|
@@ -55,13 +56,12 @@ const defaults = {
|
|
|
55
56
|
beforeError: [],
|
|
56
57
|
afterResponse: []
|
|
57
58
|
},
|
|
59
|
+
cache: undefined,
|
|
60
|
+
dnsCache: new cacheable_lookup_1.default(),
|
|
58
61
|
decompress: true,
|
|
59
62
|
throwHttpErrors: true,
|
|
60
63
|
followRedirect: true,
|
|
61
64
|
isStream: false,
|
|
62
|
-
cache: false,
|
|
63
|
-
dnsCache: false,
|
|
64
|
-
useElectronNet: false,
|
|
65
65
|
responseType: 'text',
|
|
66
66
|
resolveBodyOnly: false,
|
|
67
67
|
maxRedirects: 10,
|
|
@@ -69,8 +69,15 @@ const defaults = {
|
|
|
69
69
|
methodRewriting: true,
|
|
70
70
|
ignoreInvalidCookies: false,
|
|
71
71
|
context: {},
|
|
72
|
-
|
|
72
|
+
// TODO: Set this to `true` when Got 12 gets released
|
|
73
|
+
http2: false,
|
|
74
|
+
allowGetBody: false,
|
|
75
|
+
rejectUnauthorized: true,
|
|
76
|
+
pagination: {
|
|
73
77
|
transform: (response) => {
|
|
78
|
+
if (response.request.options.responseType === 'json') {
|
|
79
|
+
return response.body;
|
|
80
|
+
}
|
|
74
81
|
return JSON.parse(response.body);
|
|
75
82
|
},
|
|
76
83
|
paginate: response => {
|
|
@@ -108,18 +115,5 @@ exports.default = got;
|
|
|
108
115
|
// For CommonJS default export support
|
|
109
116
|
module.exports = got;
|
|
110
117
|
module.exports.default = got;
|
|
111
|
-
|
|
112
|
-
__export(require("./
|
|
113
|
-
var as_stream_1 = require("./as-stream");
|
|
114
|
-
exports.ResponseStream = as_stream_1.ProxyStream;
|
|
115
|
-
var errors_1 = require("./errors");
|
|
116
|
-
exports.GotError = errors_1.GotError;
|
|
117
|
-
exports.CacheError = errors_1.CacheError;
|
|
118
|
-
exports.RequestError = errors_1.RequestError;
|
|
119
|
-
exports.ReadError = errors_1.ReadError;
|
|
120
|
-
exports.ParseError = errors_1.ParseError;
|
|
121
|
-
exports.HTTPError = errors_1.HTTPError;
|
|
122
|
-
exports.MaxRedirectsError = errors_1.MaxRedirectsError;
|
|
123
|
-
exports.UnsupportedProtocolError = errors_1.UnsupportedProtocolError;
|
|
124
|
-
exports.TimeoutError = errors_1.TimeoutError;
|
|
125
|
-
exports.CancelError = errors_1.CancelError;
|
|
118
|
+
__export(require("./create"));
|
|
119
|
+
__export(require("./as-promise"));
|