diff --git a/index.d.ts b/index.d.ts index 18c49a5..7c87e9e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -2,6 +2,7 @@ import Conf from 'conf'; import {Options} from 'got'; export interface FetchOptions extends Options { + // Deprecated, but left for backwards-compatibility. /** URL search parameters. */ diff --git a/index.js b/index.js index c758928..af63a16 100644 --- a/index.js +++ b/index.js @@ -116,12 +116,17 @@ alfy.fetch = async (url, options) => { ...options, }; + // Deprecated, but left for backwards-compatibility. + if (options.query) { + options.searchParams = options.query; + } + if (typeof url !== 'string') { - return Promise.reject(new TypeError(`Expected \`url\` to be a \`string\`, got \`${typeof url}\``)); + throw new TypeError(`Expected \`url\` to be a \`string\`, got \`${typeof url}\``); } if (options.transform && typeof options.transform !== 'function') { - return Promise.reject(new TypeError(`Expected \`transform\` to be a \`function\`, got \`${typeof options.transform}\``)); + throw new TypeError(`Expected \`transform\` to be a \`function\`, got \`${typeof options.transform}\``); } const rawKey = url + JSON.stringify(options); @@ -129,12 +134,12 @@ alfy.fetch = async (url, options) => { const cachedResponse = alfy.cache.get(key, {ignoreMaxAge: true}); if (cachedResponse && !alfy.cache.isExpired(key)) { - return Promise.resolve(cachedResponse); + return cachedResponse; } let response; try { - response = await got(url, {searchParams: options.query}).json(); + response = await got(url, options).json(); } catch (error) { if (cachedResponse) { return cachedResponse; diff --git a/readme.md b/readme.md index 90e137d..0cb9c17 100644 --- a/readme.md +++ b/readme.md @@ -351,7 +351,7 @@ URL to fetch. Type: `object` -Any of the [`got` options](https://github.com/sindresorhus/got#options). +Any of the [`got` options](https://github.com/sindresorhus/got/tree/v11.8.3#api) and the below options. ###### json