Skip to content

Commit

Permalink
Follow-up fix
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak committed Jul 30, 2021
1 parent 1018c20 commit 732e9bd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
24 changes: 12 additions & 12 deletions source/core/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,21 +425,21 @@ export interface PaginationOptions<ElementType, BodyType> {
const limit = 10;
const items = got.paginate('https://example.com/items', {
searchParameters: {
searchParams: {
limit,
offset: 0
},
pagination: {
paginate: ({response, currentItems}) => {
const previousSearchParams = response.request.options.searchParameters;
const previousSearchParams = response.request.options.searchParams;
const previousOffset = previousSearchParams.get('offset');
if (currentItems.length < limit) {
return false;
}
return {
searchParameters: {
searchParams: {
...previousSearchParams,
offset: Number(previousOffset) + limit,
}
Expand Down Expand Up @@ -707,10 +707,10 @@ const defaultInternals: Options['_internals'] = {
maxHeaderSize: undefined,
};

const cloneInternals = (internals: typeof defaultInternals): typeof defaultInternals => {
const cloneInternals = (internals: typeof defaultInternals) => {
const {hooks, retry} = internals;

const result = {
const result: typeof defaultInternals = {
...internals,
context: {...internals.context},
cacheOptions: {...internals.cacheOptions},
Expand All @@ -732,7 +732,7 @@ const cloneInternals = (internals: typeof defaultInternals): typeof defaultInter
beforeRetry: [...hooks.beforeRetry],
afterResponse: [...hooks.afterResponse],
},
searchParameters: internals.searchParams ? new URLSearchParams(internals.searchParams as URLSearchParams) : undefined,
searchParams: internals.searchParams ? new URLSearchParams(internals.searchParams as URLSearchParams) : undefined,
pagination: {...internals.pagination},
};

Expand Down Expand Up @@ -1176,10 +1176,10 @@ export default class Options {
@example
```
await got('https://example.com/?query=a b'); //=> https://example.com/?query=a%20b
await got('https://example.com/', {searchParameters: {query: 'a b'}}); //=> https://example.com/?query=a+b
await got('https://example.com/', {searchParams: {query: 'a b'}}); //=> https://example.com/?query=a+b
// The query string is overridden by `searchParameters`
await got('https://example.com/?query=a b', {searchParameters: {query: 'a b'}}); //=> https://example.com/?query=a+b
// The query string is overridden by `searchParams`
await got('https://example.com/?query=a b', {searchParams: {query: 'a b'}}); //=> https://example.com/?query=a+b
```
*/
get url(): string | URL | undefined {
Expand Down Expand Up @@ -1312,11 +1312,11 @@ export default class Options {
```
import got from 'got';
const searchParameters = new URLSearchParams([['key', 'a'], ['key', 'b']]);
const searchParams = new URLSearchParams([['key', 'a'], ['key', 'b']]);
await got('https://example.com', {searchParameters});
await got('https://example.com', {searchParams});
console.log(searchParameters.toString());
console.log(searchParams.toString());
//=> 'key=a&key=b'
```
*/
Expand Down
12 changes: 6 additions & 6 deletions test/normalize-arguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,18 @@ test('extending responseType', t => {
});

test('searchParams - multiple values for one key', t => {
const searchParams = new URLSearchParams();
const searchParameters = new URLSearchParams();

searchParams.append('a', '100');
searchParams.append('a', '200');
searchParams.append('a', '300');
searchParameters.append('a', '100');
searchParameters.append('a', '200');
searchParameters.append('a', '300');

const options = new Options({
searchParams
searchParams: searchParameters,
});

t.deepEqual(
(options.searchParams as URLSearchParams).getAll('a'),
['100', '200', '300']
['100', '200', '300'],
);
});

0 comments on commit 732e9bd

Please sign in to comment.