Skip to content

Commit 495fbba

Browse files
committed
Remove the query option for fetch()
1 parent e2c9751 commit 495fbba

File tree

4 files changed

+17
-22
lines changed

4 files changed

+17
-22
lines changed

index.d.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@ import Conf from 'conf';
22
import {Options} from 'got';
33

44
export interface FetchOptions extends Partial<Options> {
5-
// Deprecated, but left for backwards-compatibility.
6-
/**
7-
URL search parameters.
8-
*/
9-
readonly query?: string | Record<string, string | number | boolean | undefined> | URLSearchParams | undefined;
10-
115
/**
126
Number of milliseconds this request should be cached.
137
*/

index.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,25 +116,26 @@ alfy.fetch = async (url, options) => {
116116
...options,
117117
};
118118

119-
const {transform, maxAge} = options;
120-
delete options.transform;
121-
delete options.maxAge;
122-
123-
// Deprecated, but left for backwards-compatibility.
119+
// TODO: Remove this in 2024.
124120
if (options.query) {
125-
options.searchParams = options.query;
126-
delete options.query;
121+
throw new Error('The `query` option was renamed to `searchParams`.');
127122
}
128123

129124
if (typeof url !== 'string') {
130125
throw new TypeError(`Expected \`url\` to be a \`string\`, got \`${typeof url}\``);
131126
}
132127

133-
if (transform && typeof transform !== 'function') {
134-
throw new TypeError(`Expected \`transform\` to be a \`function\`, got \`${typeof transform}\``);
128+
if (options.transform && typeof options.transform !== 'function') {
129+
throw new TypeError(`Expected \`transform\` to be a \`function\`, got \`${typeof options.transform}\``);
135130
}
136131

137132
const rawKey = url + JSON.stringify(options);
133+
134+
// This must be below the cache key generation.
135+
const {transform, maxAge} = options;
136+
delete options.transform;
137+
delete options.maxAge;
138+
138139
const key = rawKey.replace(/\./g, '\\.');
139140
const cachedResponse = alfy.cache.get(key, {ignoreMaxAge: true});
140141

readme.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ You need [Node.js 14+](https://nodejs.org) and [Alfred 4](https://www.alfredapp.
2121

2222
## Install
2323

24-
```
25-
$ npm install alfy
24+
```sh
25+
npm install alfy
2626
```
2727

2828
## Usage
@@ -121,8 +121,8 @@ You can remove [these](https://github.com/samverschueren/alfred-link#infoplist)
121121

122122
After publishing your workflow to npm, your users can easily install or update the workflow.
123123

124-
```
125-
$ npm install --global alfred-unicorn
124+
```sh
125+
npm install --global alfred-unicorn
126126
```
127127

128128
> Tip: instead of manually updating every workflow yourself, use the [alfred-updater](https://github.com/SamVerschueren/alfred-updater) workflow to do that for you.
@@ -351,7 +351,7 @@ URL to fetch.
351351

352352
Type: `object`
353353

354-
Any of the [`got` options](https://github.com/sindresorhus/got/tree/v11.8.3#api) and the below options.
354+
Any of the [`got` options](https://github.com/sindresorhus/got/tree/v12.0.3#api) and the below options.
355355

356356
###### json
357357

test/fetch.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ test('cache', async t => {
5656
test('cache key', async t => {
5757
const alfy = createAlfy();
5858

59-
t.deepEqual(await alfy.fetch(`${URL}/cache-key`, {query: {unicorn: 'rainbow'}, maxAge: 5000}), {unicorn: 'rainbow'});
60-
t.truthy(alfy.cache.store['https://foo.bar/cache-key{"query":{"unicorn":"rainbow"},"maxAge":5000}']);
59+
t.deepEqual(await alfy.fetch(`${URL}/cache-key`, {searchParams: {unicorn: 'rainbow'}, maxAge: 5000}), {unicorn: 'rainbow'});
60+
t.truthy(alfy.cache.store['https://foo.bar/cache-key{"searchParams":{"unicorn":"rainbow"},"maxAge":5000}']);
6161
});
6262

6363
test('invalid version', async t => {

0 commit comments

Comments
 (0)