@@ -23,6 +23,15 @@ export type ApplyDefaults<Defaults, Target> = {
23
23
[ K in keyof Target as K extends keyof Defaults ? K : never ] : Target [ K ]
24
24
} ;
25
25
26
+ declare global {
27
+ interface RequestInit {
28
+ next ?: {
29
+ revalidate ?: boolean | number ;
30
+ tags ?: string [ ] ;
31
+ } ;
32
+ }
33
+ }
34
+
26
35
export type RouteOptions = {
27
36
headers ?: HeadersInit ;
28
37
params ?: unknown ;
@@ -37,6 +46,8 @@ export type DefaultRouteOptions = {
37
46
payload ?: never ;
38
47
query ?: never ;
39
48
response ?: unknown ;
49
+ cache ?: RequestInit [ "cache" ] ;
50
+ next ?: RequestInit [ "next" ] ;
40
51
} ;
41
52
42
53
export type RouteDefinition = Record < string , RouteOptions > ;
@@ -114,7 +125,7 @@ export class Client<T extends RouteTable> {
114
125
}
115
126
}
116
127
117
- async #fetch< O extends RouteOptions = RouteOptions > ( method : RequestMethod , path : string , options ?: WithoutResponse < O > ) : Promise < ClientResponse < O [ "response" ] > > {
128
+ async #fetch< O extends DefaultRouteOptions = DefaultRouteOptions > ( method : RequestMethod , path : string , options ?: WithoutResponse < O > ) : Promise < ClientResponse < O [ "response" ] > > {
118
129
const realPath = options && "params" in options
119
130
? replaceParams ( path , options . params as Record < string , string > )
120
131
: path ;
@@ -167,6 +178,8 @@ export class Client<T extends RouteTable> {
167
178
method,
168
179
headers,
169
180
body : options && "payload" in options ? JSON . stringify ( options . payload ) : undefined ,
181
+ cache : options ?. cache ,
182
+ next : options ?. next ,
170
183
} ) ;
171
184
172
185
const isJsonResponse = fetchResponse . headers . get ( "content-type" ) ?. startsWith ( "application/json" ) ;
0 commit comments