got 11.0.2 → 11.0.3

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.
@@ -20,12 +20,10 @@ exports.parseBody = (response, responseType, encoding) => {
20
20
  if (responseType === 'buffer') {
21
21
  return Buffer.from(rawBody);
22
22
  }
23
- if (!exports.knownBodyTypes.includes(responseType)) {
24
- throw new types_1.ParseError({
25
- message: `Unknown body type '${responseType}'`,
26
- name: 'Error'
27
- }, response);
28
- }
23
+ throw new types_1.ParseError({
24
+ message: `Unknown body type '${responseType}'`,
25
+ name: 'Error'
26
+ }, response);
29
27
  }
30
28
  catch (error) {
31
29
  throw new types_1.ParseError(error, response);
@@ -68,9 +68,9 @@ function asPromise(options) {
68
68
  rawBody = await getStream.buffer(request);
69
69
  response.rawBody = rawBody;
70
70
  }
71
- catch (error) {
72
- // TODO: Call `request._beforeError`, see https://github.com/nodejs/node/issues/32995
73
- reject(new types_1.ReadError(error, request));
71
+ catch (_) {
72
+ // The same error is caught below.
73
+ // See request.once('error')
74
74
  return;
75
75
  }
76
76
  // Parse body
@@ -91,7 +91,6 @@ function asPromise(options) {
91
91
  // @ts-ignore TS doesn't notice that CancelableRequest is a Promise
92
92
  // eslint-disable-next-line no-await-in-loop
93
93
  response = await hook(response, async (updatedOptions) => {
94
- request.destroy();
95
94
  const typedOptions = core_1.default.normalizeArguments(undefined, {
96
95
  ...updatedOptions,
97
96
  retry: {
@@ -118,12 +117,7 @@ function asPromise(options) {
118
117
  }
119
118
  catch (error) {
120
119
  // TODO: Call `request._beforeError`, see https://github.com/nodejs/node/issues/32995
121
- if (error instanceof types_1.RequestError) {
122
- reject(error);
123
- }
124
- else {
125
- reject(new types_1.RequestError(error.message, error, request));
126
- }
120
+ reject(new types_1.RequestError(error.message, error, request));
127
121
  return;
128
122
  }
129
123
  if (throwHttpErrors && !isOk()) {
@@ -35,6 +35,7 @@ export interface PaginationOptions<T> {
35
35
  paginate?: (response: Response, allItems: T[], currentItems: T[]) => Options | false;
36
36
  shouldContinue?: (item: T, allItems: T[], currentItems: T[]) => boolean;
37
37
  countLimit?: number;
38
+ requestLimit?: number;
38
39
  };
39
40
  }
40
41
  export interface Options extends RequestOptions, PaginationOptions<unknown> {
@@ -28,6 +28,7 @@ declare const kStartedReading: unique symbol;
28
28
  declare const kStopReading: unique symbol;
29
29
  declare const kTriggerRead: unique symbol;
30
30
  declare const kBody: unique symbol;
31
+ declare const kJobs: unique symbol;
31
32
  export declare const kIsNormalizedAlready: unique symbol;
32
33
  export interface Agents {
33
34
  http?: http.Agent;
@@ -240,6 +241,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
240
241
  [kStopReading]: boolean;
241
242
  [kTriggerRead]: boolean;
242
243
  [kBody]: Options['body'];
244
+ [kJobs]: Array<() => void>;
243
245
  [kBodySize]?: number;
244
246
  [kServerResponsesPiped]: Set<ServerResponse>;
245
247
  [kIsFromCache]?: boolean;
@@ -252,7 +254,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
252
254
  _progressCallbacks: Array<() => void>;
253
255
  options: NormalizedOptions;
254
256
  requestUrl: string;
255
- finalized: boolean;
257
+ requestInitialized: boolean;
256
258
  redirects: string[];
257
259
  constructor(url: string | URL, options?: Options, defaults?: Defaults);
258
260
  static normalizeArguments(url?: string | URL, options?: Options, defaults?: Defaults): NormalizedOptions;
@@ -37,6 +37,7 @@ const kStartedReading = Symbol('startedReading');
37
37
  const kStopReading = Symbol('stopReading');
38
38
  const kTriggerRead = Symbol('triggerRead');
39
39
  const kBody = Symbol('body');
40
+ const kJobs = Symbol('jobs');
40
41
  exports.kIsNormalizedAlready = Symbol('isNormalizedAlready');
41
42
  const supportsBrotli = is_1.default.string(process.versions.brotli);
42
43
  exports.withoutBody = new Set(['GET', 'HEAD']);
@@ -207,11 +208,12 @@ class Request extends stream_1.Duplex {
207
208
  });
208
209
  this[kDownloadedSize] = 0;
209
210
  this[kUploadedSize] = 0;
210
- this.finalized = false;
211
+ this.requestInitialized = false;
211
212
  this[kServerResponsesPiped] = new Set();
212
213
  this.redirects = [];
213
214
  this[kStopReading] = false;
214
215
  this[kTriggerRead] = false;
216
+ this[kJobs] = [];
215
217
  // TODO: Remove this when targeting Node.js >= 12
216
218
  this._progressCallbacks = [];
217
219
  const unlockWrite = () => this._unlockWrite();
@@ -241,6 +243,7 @@ class Request extends stream_1.Duplex {
241
243
  this._lockWrite();
242
244
  }
243
245
  (async (nonNormalizedOptions) => {
246
+ var _a;
244
247
  try {
245
248
  if (nonNormalizedOptions.body instanceof fs_1.ReadStream) {
246
249
  await waitForOpenFile(nonNormalizedOptions.body);
@@ -260,8 +263,15 @@ class Request extends stream_1.Duplex {
260
263
  decodeURI(this.requestUrl);
261
264
  await this._finalizeBody();
262
265
  await this._makeRequest();
263
- this.finalized = true;
264
- this.emit('finalized');
266
+ if (this.destroyed) {
267
+ (_a = this[kRequest]) === null || _a === void 0 ? void 0 : _a.abort();
268
+ return;
269
+ }
270
+ // Queued writes etc.
271
+ for (const job of this[kJobs]) {
272
+ job();
273
+ }
274
+ this.requestInitialized = true;
265
275
  }
266
276
  catch (error) {
267
277
  if (error instanceof RequestError) {
@@ -273,8 +283,10 @@ class Request extends stream_1.Duplex {
273
283
  })(options);
274
284
  }
275
285
  static normalizeArguments(url, options, defaults) {
276
- var _a, _b, _c, _d, _e, _f;
286
+ var _a, _b, _c, _d;
277
287
  const rawOptions = options;
288
+ const searchParameters = options === null || options === void 0 ? void 0 : options.searchParams;
289
+ const hooks = options === null || options === void 0 ? void 0 : options.hooks;
278
290
  if (is_1.default.object(url) && !is_1.default.urlInstance(url)) {
279
291
  options = { ...defaults, ...url, ...options };
280
292
  }
@@ -287,6 +299,20 @@ class Request extends stream_1.Duplex {
287
299
  options.url = url;
288
300
  }
289
301
  }
302
+ // Prevent duplicating default search params & hooks
303
+ if (searchParameters === undefined) {
304
+ delete options.searchParams;
305
+ }
306
+ else {
307
+ options.searchParams = searchParameters;
308
+ }
309
+ if (hooks === undefined) {
310
+ delete options.hooks;
311
+ }
312
+ else {
313
+ options.hooks = hooks;
314
+ }
315
+ // Setting options to `undefined` turns off its functionalities
290
316
  if (rawOptions && defaults) {
291
317
  for (const key in rawOptions) {
292
318
  // @ts-ignore Dear TypeScript, all object keys are strings (or symbols which are NOT enumerable).
@@ -330,11 +356,11 @@ class Request extends stream_1.Duplex {
330
356
  if (is_1.default.undefined(options.headers)) {
331
357
  options.headers = {};
332
358
  }
333
- else if (options.headers === ((_a = defaults) === null || _a === void 0 ? void 0 : _a.headers)) {
359
+ else if (options.headers === (defaults === null || defaults === void 0 ? void 0 : defaults.headers)) {
334
360
  options.headers = { ...options.headers };
335
361
  }
336
362
  else {
337
- options.headers = lowercaseKeys({ ...((_b = defaults) === null || _b === void 0 ? void 0 : _b.headers), ...options.headers });
363
+ options.headers = lowercaseKeys({ ...(defaults === null || defaults === void 0 ? void 0 : defaults.headers), ...options.headers });
338
364
  }
339
365
  // Disallow legacy `url.Url`
340
366
  if ('slashes' in options) {
@@ -344,6 +370,23 @@ class Request extends stream_1.Duplex {
344
370
  if ('auth' in options) {
345
371
  throw new TypeError('Parameter `auth` is deprecated. Use `username` / `password` instead.');
346
372
  }
373
+ // `options.searchParams`
374
+ if (options.searchParams) {
375
+ if (!is_1.default.string(options.searchParams) && !(options.searchParams instanceof url_1.URLSearchParams)) {
376
+ validateSearchParameters(options.searchParams);
377
+ }
378
+ options.searchParams = new url_1.URLSearchParams(options.searchParams);
379
+ // `normalizeArguments()` is also used to merge options
380
+ (_a = defaults === null || defaults === void 0 ? void 0 : defaults.searchParams) === null || _a === void 0 ? void 0 : _a.forEach((value, key) => {
381
+ options.searchParams.append(key, value);
382
+ });
383
+ }
384
+ else {
385
+ options.searchParams = defaults === null || defaults === void 0 ? void 0 : defaults.searchParams;
386
+ }
387
+ // `options.username` & `options.password`
388
+ options.username = (_b = options.username) !== null && _b !== void 0 ? _b : '';
389
+ options.password = (_c = options.password) !== null && _c !== void 0 ? _c : '';
347
390
  // `options.prefixUrl` & `options.url`
348
391
  if (options.prefixUrl) {
349
392
  options.prefixUrl = options.prefixUrl.toString();
@@ -377,25 +420,27 @@ class Request extends stream_1.Duplex {
377
420
  },
378
421
  get: () => prefixUrl
379
422
  });
380
- // Protocol check
423
+ // Support UNIX sockets
381
424
  let { protocol } = options.url;
382
425
  if (protocol === 'unix:') {
383
426
  protocol = 'http:';
384
427
  options.url = new url_1.URL(`http://unix${options.url.pathname}${options.url.search}`);
385
428
  }
429
+ // Set search params
430
+ if (options.searchParams) {
431
+ options.url.search = options.searchParams.toString();
432
+ }
433
+ // Trigger search params normalization
386
434
  if (options.url.search) {
387
435
  const triggerSearchParameters = '_GOT_INTERNAL_TRIGGER_NORMALIZATION';
388
436
  options.url.searchParams.append(triggerSearchParameters, '');
389
437
  options.url.searchParams.delete(triggerSearchParameters);
390
438
  }
439
+ // Protocol check
391
440
  if (protocol !== 'http:' && protocol !== 'https:') {
392
441
  throw new UnsupportedProtocolError(options);
393
442
  }
394
- }
395
- // `options.username` & `options.password`
396
- options.username = (_c = options.username, (_c !== null && _c !== void 0 ? _c : ''));
397
- options.password = (_d = options.password, (_d !== null && _d !== void 0 ? _d : ''));
398
- if (options.url) {
443
+ // Update `username` & `password`
399
444
  options.url.username = options.username;
400
445
  options.url.password = options.password;
401
446
  }
@@ -415,23 +460,6 @@ class Request extends stream_1.Duplex {
415
460
  };
416
461
  }
417
462
  }
418
- // `options.searchParams`
419
- if (options.searchParams) {
420
- if (!is_1.default.string(options.searchParams) && !(options.searchParams instanceof url_1.URLSearchParams)) {
421
- validateSearchParameters(options.searchParams);
422
- }
423
- options.searchParams = new url_1.URLSearchParams(options.searchParams);
424
- // `normalizeArguments()` is also used to merge options
425
- const defaultsAsOptions = defaults;
426
- if (defaultsAsOptions && defaultsAsOptions.searchParams instanceof url_1.URLSearchParams) {
427
- defaultsAsOptions.searchParams.forEach((value, key) => {
428
- options.searchParams.append(key, value);
429
- });
430
- }
431
- if (options.url) {
432
- options.url.search = options.searchParams.toString();
433
- }
434
- }
435
463
  // `options.cache`
436
464
  const { cache } = options;
437
465
  if (cache) {
@@ -464,7 +492,6 @@ class Request extends stream_1.Duplex {
464
492
  options.context = {};
465
493
  }
466
494
  // `options.hooks`
467
- const areHooksUserDefined = options.hooks !== ((_e = defaults) === null || _e === void 0 ? void 0 : _e.hooks);
468
495
  options.hooks = { ...options.hooks };
469
496
  for (const event of exports.knownHookEvents) {
470
497
  if (event in options.hooks) {
@@ -480,7 +507,7 @@ class Request extends stream_1.Duplex {
480
507
  options.hooks[event] = [];
481
508
  }
482
509
  }
483
- if (defaults && areHooksUserDefined) {
510
+ if (defaults) {
484
511
  for (const event of exports.knownHookEvents) {
485
512
  const defaultHooks = defaults.hooks[event];
486
513
  if (defaultHooks.length !== 0) {
@@ -503,7 +530,7 @@ class Request extends stream_1.Duplex {
503
530
  }
504
531
  }
505
532
  }
506
- options.maxRedirects = (_f = options.maxRedirects, (_f !== null && _f !== void 0 ? _f : 0));
533
+ options.maxRedirects = (_d = options.maxRedirects) !== null && _d !== void 0 ? _d : 0;
507
534
  // Set non-enumerable properties
508
535
  setNonEnumerableProperties([defaults, options], options);
509
536
  return options;
@@ -614,7 +641,7 @@ class Request extends stream_1.Duplex {
614
641
  this[kResponseSize] = this[kDownloadedSize];
615
642
  this.emit('downloadProgress', this.downloadProgress);
616
643
  });
617
- response.on('error', (error) => {
644
+ response.once('error', (error) => {
618
645
  this._beforeError(new ReadError(error, this));
619
646
  });
620
647
  response.once('aborted', () => {
@@ -810,7 +837,7 @@ class Request extends stream_1.Duplex {
810
837
  });
811
838
  }
812
839
  async _makeRequest() {
813
- var _a, _b;
840
+ var _a;
814
841
  const { options } = this;
815
842
  const { url, headers, request, agent, timeout } = options;
816
843
  for (const key in headers) {
@@ -847,7 +874,7 @@ class Request extends stream_1.Duplex {
847
874
  // UNIX sockets
848
875
  if (url.hostname === 'unix') {
849
876
  const matches = /(?<socketPath>.+?):(?<path>.+)/.exec(`${url.pathname}${url.search}`);
850
- if ((_a = matches) === null || _a === void 0 ? void 0 : _a.groups) {
877
+ if (matches === null || matches === void 0 ? void 0 : matches.groups) {
851
878
  const { socketPath, path } = matches.groups;
852
879
  Object.assign(options, {
853
880
  socketPath,
@@ -864,7 +891,7 @@ class Request extends stream_1.Duplex {
864
891
  else {
865
892
  fallbackFn = isHttps ? https.request : http.request;
866
893
  }
867
- const realFn = (_b = options.request, (_b !== null && _b !== void 0 ? _b : fallbackFn));
894
+ const realFn = (_a = options.request) !== null && _a !== void 0 ? _a : fallbackFn;
868
895
  const fn = options.cache ? this._createCacheableRequest.bind(this) : realFn;
869
896
  if (agent && !options.http2) {
870
897
  options.agent = agent[isHttps ? 'https' : 'http'];
@@ -955,11 +982,11 @@ class Request extends stream_1.Duplex {
955
982
  const write = () => {
956
983
  this._writeRequest(chunk, encoding, callback);
957
984
  };
958
- if (this.finalized) {
985
+ if (this.requestInitialized) {
959
986
  write();
960
987
  }
961
988
  else {
962
- this.once('finalized', write);
989
+ this[kJobs].push(write);
963
990
  }
964
991
  }
965
992
  _writeRequest(chunk, encoding, callback) {
@@ -970,6 +997,7 @@ class Request extends stream_1.Duplex {
970
997
  this.emit('uploadProgress', progress);
971
998
  }
972
999
  });
1000
+ // TODO: What happens if it's from cache? Then this[kRequest] won't be defined.
973
1001
  this[kRequest].write(chunk, encoding, (error) => {
974
1002
  if (!error && this._progressCallbacks.length !== 0) {
975
1003
  this._progressCallbacks.shift()();
@@ -998,28 +1026,24 @@ class Request extends stream_1.Duplex {
998
1026
  callback(error);
999
1027
  });
1000
1028
  };
1001
- if (this.finalized) {
1029
+ if (this.requestInitialized) {
1002
1030
  endRequest();
1003
1031
  }
1004
1032
  else {
1005
- this.once('finalized', endRequest);
1033
+ this[kJobs].push(endRequest);
1006
1034
  }
1007
1035
  }
1008
1036
  _destroy(error, callback) {
1009
1037
  var _a;
1010
1038
  if (kRequest in this) {
1011
- // TODO: Remove the next `if` when https://github.com/nodejs/node/issues/32851 gets fixed
1012
- if (!((_a = this[kResponse]) === null || _a === void 0 ? void 0 : _a.complete)) {
1039
+ this[kCancelTimeouts]();
1040
+ // TODO: Remove the next `if` when these get fixed:
1041
+ // - https://github.com/nodejs/node/issues/32851
1042
+ // - https://github.com/nock/nock/issues/1981
1043
+ if (!((_a = this[kResponse]) === null || _a === void 0 ? void 0 : _a.complete) && !this[kRequest].destroyed) {
1013
1044
  this[kRequest].abort();
1014
1045
  }
1015
1046
  }
1016
- else {
1017
- this.once('finalized', () => {
1018
- if (kRequest in this) {
1019
- this[kRequest].abort();
1020
- }
1021
- });
1022
- }
1023
1047
  if (error !== null && !is_1.default.undefined(error) && !(error instanceof RequestError)) {
1024
1048
  error = new RequestError(error.message, error, this);
1025
1049
  }
@@ -30,7 +30,7 @@ exports.default = (origin, options) => {
30
30
  if (!options.protocol) {
31
31
  throw new TypeError('No URL protocol specified');
32
32
  }
33
- origin = `${options.protocol}//${_b = (_a = options.hostname, (_a !== null && _a !== void 0 ? _a : options.host)), (_b !== null && _b !== void 0 ? _b : '')}`;
33
+ origin = `${options.protocol}//${(_b = (_a = options.hostname) !== null && _a !== void 0 ? _a : options.host) !== null && _b !== void 0 ? _b : ''}`;
34
34
  }
35
35
  const url = new url_1.URL(origin);
36
36
  if (options.path) {
@@ -21,9 +21,9 @@ exports.default = (request, delays, options) => {
21
21
  const cancelers = [];
22
22
  const { once, unhandleAll } = unhandle_1.default();
23
23
  const addTimeout = (delay, callback, event) => {
24
- var _a, _b;
24
+ var _a;
25
25
  const timeout = setTimeout(callback, delay, delay, event);
26
- (_b = (_a = timeout).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
26
+ (_a = timeout.unref) === null || _a === void 0 ? void 0 : _a.call(timeout);
27
27
  const cancel = () => {
28
28
  clearTimeout(timeout);
29
29
  };
@@ -32,9 +32,6 @@ exports.default = (request, delays, options) => {
32
32
  };
33
33
  const { host, hostname } = options;
34
34
  const timeoutHandler = (delay, event) => {
35
- if (request.socket) {
36
- request.socket._hadError = true;
37
- }
38
35
  request.destroy(new TimeoutError(delay, event));
39
36
  };
40
37
  const cancelTimeouts = () => {
@@ -46,6 +43,7 @@ exports.default = (request, delays, options) => {
46
43
  request.once('error', error => {
47
44
  cancelTimeouts();
48
45
  // Save original behavior
46
+ /* istanbul ignore next */
49
47
  if (request.listenerCount('error') === 0) {
50
48
  throw error;
51
49
  }
@@ -74,7 +72,7 @@ exports.default = (request, delays, options) => {
74
72
  const { socketPath } = request;
75
73
  /* istanbul ignore next: hard to test */
76
74
  if (socket.connecting) {
77
- const hasPath = Boolean((socketPath !== null && socketPath !== void 0 ? socketPath : net.isIP((_a = (hostname !== null && hostname !== void 0 ? hostname : host), (_a !== null && _a !== void 0 ? _a : ''))) !== 0));
75
+ const hasPath = Boolean(socketPath !== null && socketPath !== void 0 ? socketPath : net.isIP((_a = hostname !== null && hostname !== void 0 ? hostname : host) !== null && _a !== void 0 ? _a : '') !== 0);
78
76
  if (typeof delays.lookup !== 'undefined' && !hasPath && typeof socket.address().address === 'undefined') {
79
77
  const cancelTimeout = addTimeout(delays.lookup, timeoutHandler, 'lookup');
80
78
  once(socket, 'lookup', cancelTimeout);
@@ -60,8 +60,8 @@ const create = (defaults) => {
60
60
  }
61
61
  return result;
62
62
  }));
63
- const got = ((url, options = {}) => {
64
- var _a, _b, _c, _d, _e;
63
+ const got = ((url, options) => {
64
+ var _a, _b;
65
65
  let iteration = 0;
66
66
  const iterateHandlers = (newOptions) => {
67
67
  return defaults.handlers[iteration++](newOptions, iteration === defaults.handlers.length ? getPromiseOrStream : iterateHandlers);
@@ -78,7 +78,7 @@ const create = (defaults) => {
78
78
  let initHookError;
79
79
  try {
80
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);
81
+ callInitHooks((_a = options === null || options === void 0 ? void 0 : options.hooks) === null || _a === void 0 ? void 0 : _a.init, options);
82
82
  }
83
83
  catch (error) {
84
84
  initHookError = error;
@@ -94,13 +94,13 @@ const create = (defaults) => {
94
94
  return iterateHandlers(normalizedOptions);
95
95
  }
96
96
  catch (error) {
97
- if ((_c = options) === null || _c === void 0 ? void 0 : _c.isStream) {
97
+ if (options === null || options === void 0 ? void 0 : options.isStream) {
98
98
  throw error;
99
99
  }
100
100
  else {
101
101
  // A bug.
102
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);
103
+ return create_rejection_1.default(error, defaults.options.hooks.beforeError, (_b = options === null || options === void 0 ? void 0 : options.hooks) === null || _b === void 0 ? void 0 : _b.beforeError);
104
104
  }
105
105
  }
106
106
  });
@@ -140,7 +140,8 @@ const create = (defaults) => {
140
140
  throw new TypeError('`options.pagination` must be implemented');
141
141
  }
142
142
  const all = [];
143
- while (true) {
143
+ let numberOfRequests = 0;
144
+ while (numberOfRequests < pagination.requestLimit) {
144
145
  // TODO: Throw when result is not an instance of Response
145
146
  // eslint-disable-next-line no-await-in-loop
146
147
  const result = (await got('', normalizedOptions));
@@ -167,6 +168,7 @@ const create = (defaults) => {
167
168
  if (optionsToMerge !== undefined) {
168
169
  normalizedOptions = normalizeArguments(undefined, optionsToMerge, normalizedOptions);
169
170
  }
171
+ numberOfRequests++;
170
172
  }
171
173
  });
172
174
  got.paginate.all = (async (url, options) => {
@@ -104,7 +104,8 @@ const defaults = {
104
104
  },
105
105
  filter: () => true,
106
106
  shouldContinue: () => true,
107
- countLimit: Infinity
107
+ countLimit: Infinity,
108
+ requestLimit: 10000
108
109
  }
109
110
  },
110
111
  handlers: [create_1.defaultHandler],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "got",
3
- "version": "11.0.2",
3
+ "version": "11.0.3",
4
4
  "description": "Human-friendly and powerful HTTP request library for Node.js",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/got",
@@ -67,8 +67,6 @@
67
67
  "@types/request": "^2.48.4",
68
68
  "@types/sinon": "^9.0.0",
69
69
  "@types/tough-cookie": "^4.0.0",
70
- "@typescript-eslint/eslint-plugin": "^2.27.0",
71
- "@typescript-eslint/parser": "^2.27.0",
72
70
  "ava": "^3.6.0",
73
71
  "axios": "^0.19.2",
74
72
  "benchmark": "^2.1.4",
@@ -76,7 +74,6 @@
76
74
  "create-test-server": "^3.0.1",
77
75
  "del-cli": "^3.0.0",
78
76
  "delay": "^4.3.0",
79
- "eslint-config-xo-typescript": "^0.27.0",
80
77
  "express": "^4.17.1",
81
78
  "form-data": "^3.0.0",
82
79
  "lolex": "^6.0.0",
@@ -90,8 +87,8 @@
90
87
  "tempy": "^0.5.0",
91
88
  "to-readable-stream": "^2.1.0",
92
89
  "tough-cookie": "^4.0.0",
93
- "typescript": "3.7.5",
94
- "xo": "^0.29.0"
90
+ "typescript": "3.8.3",
91
+ "xo": "^0.30.0"
95
92
  },
96
93
  "types": "dist/source",
97
94
  "sideEffects": false,
@@ -115,10 +112,6 @@
115
112
  ]
116
113
  },
117
114
  "xo": {
118
- "extends": "xo-typescript",
119
- "extensions": [
120
- "ts"
121
- ],
122
115
  "ignores": [
123
116
  "documentation/examples/*"
124
117
  ],
@@ -127,11 +120,10 @@
127
120
  "@typescript-eslint/no-base-to-string": "off",
128
121
  "node/prefer-global/url": "off",
129
122
  "node/prefer-global/url-search-params": "off",
130
- "unicorn/string-content": "off",
131
123
  "@typescript-eslint/prefer-readonly-parameter-types": "off",
132
- "@typescript-eslint/no-unsafe-member-access": "off",
133
- "@typescript-eslint/no-unsafe-call": "off",
134
- "@typescript-eslint/no-unsafe-return": "off"
124
+ "@typescript-eslint/no-floating-promises": "off",
125
+ "@typescript-eslint/method-signature-style": "off",
126
+ "unicorn/no-fn-reference-in-iterator": "off"
135
127
  }
136
128
  }
137
129
  }
package/readme.md CHANGED
@@ -56,6 +56,8 @@ $ npm install got
56
56
 
57
57
  ## Usage
58
58
 
59
+ ###### Promise
60
+
59
61
  ```js
60
62
  const got = require('got');
61
63
 
@@ -71,6 +73,26 @@ const got = require('got');
71
73
  })();
72
74
  ```
73
75
 
76
+ ###### JSON
77
+
78
+ ```js
79
+ const got = require('got');
80
+
81
+ (async () => {
82
+ const {body} = await got.post('https://httpbin.org/anything', {
83
+ json: {
84
+ hello: 'world'
85
+ },
86
+ responseType: 'json'
87
+ });
88
+
89
+ console.log(body.data);
90
+ //=> {hello: 'world'}
91
+ })();
92
+ ```
93
+
94
+ See [JSON mode](#json-mode) for more details.
95
+
74
96
  ###### Streams
75
97
 
76
98
  ```js
@@ -452,14 +474,14 @@ If this is disabled, a compressed response is returned as a `Buffer`. This may b
452
474
 
453
475
  ###### cache
454
476
 
455
- Type: `object`\
477
+ Type: `object | false`\
456
478
  Default: `false`
457
479
 
458
480
  [Cache adapter instance](#cache-adapters) for storing cached response data.
459
481
 
460
482
  ###### dnsCache
461
483
 
462
- Type: `object`\
484
+ Type: `object | false`\
463
485
  Default: `new CacheableLookup()`
464
486
 
465
487
  An instance of [`CacheableLookup`](https://github.com/szmarczak/cacheable-lookup) used for making DNS lookups.
@@ -760,6 +782,15 @@ Default: `Infinity`
760
782
 
761
783
  The maximum amount of items that should be emitted.
762
784
 
785
+ ###### pagination.requestLimit
786
+
787
+ Type: `number`\
788
+ Default: `10000`
789
+
790
+ The maximum amount of request that should be triggered. [Retries on failure](#retry) are not counted towards this limit.
791
+
792
+ For example, it can be helpful during development to avoid an infinite number of requests.
793
+
763
794
  ##### localAddress
764
795
 
765
796
  Type: `string`
@@ -972,6 +1003,25 @@ Returns an async iterator:
972
1003
 
973
1004
  See [`options.pagination`](#pagination) for more pagination options.
974
1005
 
1006
+ #### got.paginate.all(url, options?)
1007
+
1008
+ Returns a Promise for an array of all results:
1009
+
1010
+ ```js
1011
+ (async () => {
1012
+ const countLimit = 10;
1013
+
1014
+ const results = await got.paginate.all('https://api.github.com/repos/sindresorhus/got/commits', {
1015
+ pagination: {countLimit}
1016
+ });
1017
+
1018
+ console.log(`Printing latest ${countLimit} Got commits (newest to oldest):`);
1019
+ console.log(results);
1020
+ })();
1021
+ ```
1022
+
1023
+ See [`options.pagination`](#pagination) for more pagination options.
1024
+
975
1025
  #### got.get(url, options?)
976
1026
  #### got.post(url, options?)
977
1027
  #### got.put(url, options?)
@@ -1382,11 +1432,13 @@ const got = require('got');
1382
1432
  const tunnel = require('tunnel');
1383
1433
 
1384
1434
  got('https://sindresorhus.com', {
1385
- agent: tunnel.httpOverHttp({
1386
- proxy: {
1387
- host: 'localhost'
1388
- }
1389
- })
1435
+ agent: {
1436
+ https: tunnel.httpOverHttp({
1437
+ proxy: {
1438
+ host: 'localhost'
1439
+ }
1440
+ })
1441
+ }
1390
1442
  });
1391
1443
  ```
1392
1444
 
@@ -1684,7 +1736,7 @@ The Electron `net` module is not consistent with the Node.js `http` module. See
1684
1736
  <!-- GITHUB -->
1685
1737
  [k0]: https://github.com/sindresorhus/ky
1686
1738
  [r0]: https://github.com/request/request
1687
- [n0]: https://github.com/bitinn/node-fetch
1739
+ [n0]: https://github.com/node-fetch/node-fetch
1688
1740
  [a0]: https://github.com/axios/axios
1689
1741
  [s0]: https://github.com/visionmedia/superagent
1690
1742