Skip to content

Commit

Permalink
refactor(types): move customFetch options into its own interface
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Dec 2, 2024
1 parent db5af11 commit 57d8355
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 33 deletions.
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ Support from the community to continue maintaining and improving this module is
- [ConfigurationProperties](interfaces/ConfigurationProperties.md)
- [ConfirmationClaims](interfaces/ConfirmationClaims.md)
- [CryptoKeyPair](interfaces/CryptoKeyPair.md)
- [CustomFetchOptions](interfaces/CustomFetchOptions.md)
- [DecryptionKey](interfaces/DecryptionKey.md)
- [DeviceAuthorizationResponse](interfaces/DeviceAuthorizationResponse.md)
- [DeviceAutorizationGrantPollOptions](interfaces/DeviceAutorizationGrantPollOptions.md)
Expand Down
49 changes: 49 additions & 0 deletions docs/interfaces/CustomFetchOptions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Interface: CustomFetchOptions

[💗 Help the project](https://github.com/sponsors/panva)

Support from the community to continue maintaining and improving this module is welcome. If you find the module useful, please consider supporting the project by [becoming a sponsor](https://github.com/sponsors/panva).

***

## Properties

### body

**body**: [`FetchBody`](../type-aliases/FetchBody.md)

The request body content to send to the server

***

### headers

**headers**: [`Record`](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type)\<`string`, `string`\>

HTTP Headers

***

### method

**method**: `string`

The
[request method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods)

***

### redirect

**redirect**: `"manual"`

See [Request.redirect](https://developer.mozilla.org/docs/Web/API/Request/redirect)

***

### signal?

`optional` **signal**: [`AbortSignal`](https://developer.mozilla.org/docs/Web/API/AbortSignal)

An AbortSignal configured as per the [ConfigurationProperties.timeout](ConfigurationProperties.md#timeout)
value
13 changes: 4 additions & 9 deletions docs/type-aliases/CustomFetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,10 @@ Support from the community to continue maintaining and improving this module is

## Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `url` | `string` | - |
| `options` | `object` | - |
| `options.body` | [`FetchBody`](FetchBody.md) | The request body content to send to the server |
| `options.headers` | [`Record`](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type)\<`string`, `string`\> | HTTP Headers |
| `options.method` | `string` | The [request method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods) |
| `options.redirect` | `"manual"` | See [Request.redirect](https://developer.mozilla.org/docs/Web/API/Request/redirect) |
| `options.signal`? | [`AbortSignal`](https://developer.mozilla.org/docs/Web/API/AbortSignal) | An AbortSignal configured as per the [ConfigurationProperties.timeout](../interfaces/ConfigurationProperties.md#timeout) value |
| Parameter | Type |
| ------ | ------ |
| `url` | `string` |
| `options` | [`CustomFetchOptions`](../interfaces/CustomFetchOptions.md) |

## Returns

Expand Down
50 changes: 26 additions & 24 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,31 @@ export interface ConfigurationMethods {
serverMetadata(): Readonly<ServerMetadata> & ServerMetadataHelpers
}

export interface CustomFetchOptions {
/**
* The request body content to send to the server
*/
body: FetchBody
/**
* HTTP Headers
*/
headers: Record<string, string>
/**
* The
* {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods request method}
*/
method: string
/**
* See {@link !Request.redirect}
*/
redirect: 'manual'
/**
* An AbortSignal configured as per the {@link ConfigurationProperties.timeout}
* value
*/
signal?: AbortSignal
}

/**
* @see {@link customFetch}
*/
Expand All @@ -1525,30 +1550,7 @@ export type CustomFetch = (
/**
* Options otherwise sent to {@link !fetch} as the `options` argument
*/
options: {
/**
* The request body content to send to the server
*/
body: FetchBody
/**
* HTTP Headers
*/
headers: Record<string, string>
/**
* The
* {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods request method}
*/
method: string
/**
* See {@link !Request.redirect}
*/
redirect: 'manual'
/**
* An AbortSignal configured as per the
* {@link ConfigurationProperties.timeout} value
*/
signal?: AbortSignal
},
options: CustomFetchOptions,
) => Promise<Response>

/**
Expand Down

0 comments on commit 57d8355

Please sign in to comment.