diff --git a/index.d.ts b/index.d.ts index fca5115..65cd243 100644 --- a/index.d.ts +++ b/index.d.ts @@ -2,12 +2,6 @@ import Conf from 'conf'; import {Options} from 'got'; export interface FetchOptions extends Partial { - // Deprecated, but left for backwards-compatibility. - /** - URL search parameters. - */ - readonly query?: string | Record | URLSearchParams | undefined; - /** Number of milliseconds this request should be cached. */ diff --git a/index.js b/index.js index 4955897..bc3f51d 100644 --- a/index.js +++ b/index.js @@ -116,25 +116,26 @@ alfy.fetch = async (url, options) => { ...options, }; - const {transform, maxAge} = options; - delete options.transform; - delete options.maxAge; - - // Deprecated, but left for backwards-compatibility. + // TODO: Remove this in 2024. if (options.query) { - options.searchParams = options.query; - delete options.query; + throw new Error('The `query` option was renamed to `searchParams`.'); } if (typeof url !== 'string') { throw new TypeError(`Expected \`url\` to be a \`string\`, got \`${typeof url}\``); } - if (transform && typeof transform !== 'function') { - throw new TypeError(`Expected \`transform\` to be a \`function\`, got \`${typeof transform}\``); + if (options.transform && typeof options.transform !== 'function') { + throw new TypeError(`Expected \`transform\` to be a \`function\`, got \`${typeof options.transform}\``); } const rawKey = url + JSON.stringify(options); + + // This must be below the cache key generation. + const {transform, maxAge} = options; + delete options.transform; + delete options.maxAge; + const key = rawKey.replace(/\./g, '\\.'); const cachedResponse = alfy.cache.get(key, {ignoreMaxAge: true}); diff --git a/readme.md b/readme.md index 0cb9c17..4361bec 100644 --- a/readme.md +++ b/readme.md @@ -21,8 +21,8 @@ You need [Node.js 14+](https://nodejs.org) and [Alfred 4](https://www.alfredapp. ## Install -``` -$ npm install alfy +```sh +npm install alfy ``` ## Usage @@ -121,8 +121,8 @@ You can remove [these](https://github.com/samverschueren/alfred-link#infoplist) After publishing your workflow to npm, your users can easily install or update the workflow. -``` -$ npm install --global alfred-unicorn +```sh +npm install --global alfred-unicorn ``` > 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. Type: `object` -Any of the [`got` options](https://github.com/sindresorhus/got/tree/v11.8.3#api) and the below options. +Any of the [`got` options](https://github.com/sindresorhus/got/tree/v12.0.3#api) and the below options. ###### json diff --git a/test/fetch.js b/test/fetch.js index e3a15c8..729a505 100644 --- a/test/fetch.js +++ b/test/fetch.js @@ -56,8 +56,8 @@ test('cache', async t => { test('cache key', async t => { const alfy = createAlfy(); - t.deepEqual(await alfy.fetch(`${URL}/cache-key`, {query: {unicorn: 'rainbow'}, maxAge: 5000}), {unicorn: 'rainbow'}); - t.truthy(alfy.cache.store['https://foo.bar/cache-key{"query":{"unicorn":"rainbow"},"maxAge":5000}']); + t.deepEqual(await alfy.fetch(`${URL}/cache-key`, {searchParams: {unicorn: 'rainbow'}, maxAge: 5000}), {unicorn: 'rainbow'}); + t.truthy(alfy.cache.store['https://foo.bar/cache-key{"searchParams":{"unicorn":"rainbow"},"maxAge":5000}']); }); test('invalid version', async t => {