Skip to content

Commit

Permalink
remove dependency on dom or node-fetch types, offer interface to merg…
Browse files Browse the repository at this point in the history
…e with instead

fixes #507
  • Loading branch information
d-fischer committed May 22, 2023
1 parent ed99624 commit cd536e2
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 10 deletions.
3 changes: 1 addition & 2 deletions packages/api-call/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@
"funding": "https://github.com/sponsors/d-fischer",
"license": "MIT",
"dependencies": {
"@d-fischer/cross-fetch": "^4.0.2",
"@d-fischer/cross-fetch": "^5.0.1",
"@d-fischer/qs": "^7.0.2",
"@d-fischer/shared-utils": "^3.6.1",
"@twurple/common": "7.0.0-pre.0",
"@types/node-fetch": "^2.5.7",
"tslib": "^2.0.3"
},
"files": [
Expand Down
38 changes: 33 additions & 5 deletions packages/api-call/src/TwitchApiCallOptions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/// <reference lib="dom" />

import type { RequestInit as NodeRequestInit } from 'node-fetch';

/**
* The endpoint to call, i.e. /helix or a custom (potentially unsupported) endpoint.
*/
Expand Down Expand Up @@ -51,4 +47,36 @@ export interface TwitchApiCallOptions {
auth?: boolean;
}

export type TwitchApiCallFetchOptions = Omit<RequestInit | NodeRequestInit, 'headers' | 'method' | 'body'>;
/**
* An interface to merge compatible fetch options into.
*
* :::warning
*
* You should make sure that this does not include the properties `headers`, `method` or `body`
* in order to not conflict with the internally used properties.
*
* :::
*
* To make use of the web fetch options, merge them into this like so
* (assuming that RequestInit is the global type from the dom lib):
*
* ```ts
* declare module '@twurple/api-call' {
* export interface TwitchApiCallFetchOptions extends Omit<RequestInit, 'headers' | 'method' | 'body'> {}
* }
* ```
*
* To make use of the node-fetch options, merge them into this like so:
*
* ```ts
* import type { RequestInit as NodeRequestInit } from 'node-fetch';
*
* declare module '@twurple/api-call' {
* export interface TwitchApiCallFetchOptions extends Omit<NodeRequestInit, 'headers' | 'method' | 'body'> {}
* }
* ```
*/
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface TwitchApiCallFetchOptions {
/** @private */ _dummy?: never;
}
4 changes: 1 addition & 3 deletions packages/api-call/src/apiCall.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/// <reference lib="dom" />

import fetch, { Headers } from '@d-fischer/cross-fetch';
import fetch, { Headers, type RequestInit, type Response } from '@d-fischer/cross-fetch';
import { stringify } from '@d-fischer/qs';
import { handleTwitchApiResponseError, transformTwitchApiResponse } from './helpers/transform';
import { getTwitchApiUrl } from './helpers/url';
Expand Down
1 change: 1 addition & 0 deletions packages/api-call/src/helpers/transform.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { type Response } from '@d-fischer/cross-fetch';
import { stringify } from '@d-fischer/qs';
import { HttpStatusCodeError } from '../errors/HttpStatusCodeError';
import type { TwitchApiCallOptions } from '../TwitchApiCallOptions';
Expand Down
1 change: 1 addition & 0 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"license": "MIT",
"dependencies": {
"@d-fischer/cache-decorators": "^3.0.0",
"@d-fischer/cross-fetch": "^5.0.1",
"@d-fischer/detect-node": "^3.0.1",
"@d-fischer/logger": "^4.2.1",
"@d-fischer/rate-limiter": "^0.7.2",
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/client/ApiClient.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { type Response } from '@d-fischer/cross-fetch';
import { isNode } from '@d-fischer/detect-node';
import { createLogger, type LoggerOptions } from '@d-fischer/logger';
import { PartitionedRateLimiter, PartitionedTimeBasedRateLimiter } from '@d-fischer/rate-limiter';
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/client/BaseApiClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Cacheable, CachedGetter } from '@d-fischer/cache-decorators';
import { type Response } from '@d-fischer/cross-fetch';
import type { Logger } from '@d-fischer/logger';
import type { RateLimiter, RateLimiterStats } from '@d-fischer/rate-limiter';
import { ResponseBasedRateLimiter } from '@d-fischer/rate-limiter';
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/client/UserContextApiClient.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { type Response } from '@d-fischer/cross-fetch';
import { type Logger } from '@d-fischer/logger';
import { type RateLimiter } from '@d-fischer/rate-limiter';
import { rtfm } from '@twurple/common';
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/utils/HelixRateLimiter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { type Response } from '@d-fischer/cross-fetch';
import type { RateLimiterResponseParameters } from '@d-fischer/rate-limiter';
import { ResponseBasedRateLimiter } from '@d-fischer/rate-limiter';
import { callTwitchApiRaw } from '@twurple/api-call';
Expand Down

0 comments on commit cd536e2

Please sign in to comment.