Skip to content

Commit daededd

Browse files
committed
fix: move fetch option to better fetch option
1 parent 656a156 commit daededd

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@better-tools/fetch",
3-
"version": "1.3.1",
3+
"version": "1.3.2",
44
"packageManager": "[email protected]",
55
"main": "./dist/index.cjs",
66
"module": "./dist/index.js",

src/index.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import { z } from "zod";
1414
interface RequestContext {
1515
request: Request;
1616
controller: AbortController;
17-
options: FetchOption;
17+
options: BetterFetchOption;
1818
}
1919

2020
interface ResponseContext {
2121
response: Response;
2222
}
2323

24-
export type BetterFetchOptions<B extends Record<string, any> = any> = {
24+
export type BaseFetchOptions<B extends Record<string, any> = any> = {
2525
/**
2626
* a base url that will be prepended to the url
2727
*/
@@ -103,22 +103,22 @@ export type BetterFetchOptions<B extends Record<string, any> = any> = {
103103
* All plugins will be called before the request is made.
104104
*/
105105
export interface Plugin {
106-
(url: string, options?: FetchOption): Promise<{
106+
(url: string, options?: BetterFetchOption): Promise<{
107107
url: string;
108-
options?: FetchOption;
108+
options?: BetterFetchOption;
109109
}>;
110110
}
111111

112112
// biome-ignore lint/suspicious/noEmptyInterface: <explanation>
113-
export interface CreateFetchOption extends BetterFetchOptions {}
113+
export interface CreateFetchOption extends BaseFetchOptions {}
114114

115115
export type PayloadMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
116116
export type NonPayloadMethod = "GET" | "HEAD" | "OPTIONS";
117117

118-
export type FetchOption<
118+
export type BetterFetchOption<
119119
T extends Record<string, unknown> = any,
120120
Q extends Record<string, unknown> = any,
121-
> = InferBody<T> & InferQuery<Q> & BetterFetchOptions;
121+
> = InferBody<T> & InferQuery<Q> & BaseFetchOptions;
122122

123123
type InferBody<T> = T extends Record<string, any> ? { body: T } : { body?: T };
124124
type InferQuery<Q> = Q extends Record<string, any>
@@ -176,7 +176,7 @@ export const betterFetch: BetterFetch = async (url, options) => {
176176
_url.searchParams.append(key, String(value));
177177
}
178178
}
179-
const _options: FetchOption = {
179+
const _options: BetterFetchOption = {
180180
signal,
181181
...options,
182182
body: shouldStringifyBody
@@ -327,16 +327,16 @@ export interface BetterFetch<
327327
url: K | URL | Omit<string, keyof Routes>,
328328
...options: Routes[K]["input"] extends z.Schema
329329
? [
330-
FetchOption<
330+
BetterFetchOption<
331331
z.infer<Routes[K]["input"]>,
332332
Routes[K]["query"] extends z.ZodSchema
333333
? z.infer<Routes[K]["query"]>
334334
: any
335335
>,
336336
]
337337
: Routes[K]["query"] extends z.ZodSchema
338-
? [FetchOption<any, z.infer<Routes[K]["query"]>>]
339-
: [FetchOption?]
338+
? [BetterFetchOption<any, z.infer<Routes[K]["query"]>>]
339+
: [BetterFetchOption?]
340340
): Promise<
341341
BetterFetchResponse<
342342
Routes[K]["output"] extends z.ZodSchema

src/react.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useEffect, useState } from "react";
22
import {
33
BetterFetchResponse,
44
createFetch,
5-
FetchOption,
5+
BetterFetchOption,
66
PayloadMethod,
77
} from ".";
88
import { isPayloadMethod } from "./utils";
@@ -47,9 +47,9 @@ export type ReactFetchOptions<T = any> = {
4747
* @default false
4848
*/
4949
disableCache?: boolean;
50-
} & FetchOption;
50+
} & BetterFetchOption;
5151

52-
export type ReactMutateOptions = {} & FetchOption;
52+
export type ReactMutateOptions = {} & BetterFetchOption;
5353

5454
const defaultOptions: ReactFetchOptions = {
5555
refetchInterval: 0,

0 commit comments

Comments
 (0)