@kubb/plugin-fetch 5.0.0-beta.76 → 5.0.0-beta.77

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/templates/fetch.ts +15 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-fetch",
3
- "version": "5.0.0-beta.76",
3
+ "version": "5.0.0-beta.77",
4
4
  "description": "Generate a slim, type-safe HTTP client with Kubb based on the native Fetch api.",
5
5
  "keywords": [
6
6
  "api-client",
@@ -52,8 +52,8 @@
52
52
  "@kubb/ast": "5.0.0-beta.74",
53
53
  "@kubb/core": "5.0.0-beta.74",
54
54
  "@kubb/renderer-jsx": "5.0.0-beta.74",
55
- "@kubb/plugin-ts": "5.0.0-beta.76",
56
- "@kubb/plugin-zod": "5.0.0-beta.76"
55
+ "@kubb/plugin-ts": "5.0.0-beta.77",
56
+ "@kubb/plugin-zod": "5.0.0-beta.77"
57
57
  },
58
58
  "devDependencies": {
59
59
  "typescript": "^6.0.3",
@@ -112,6 +112,14 @@ export type AuthToken = string | undefined
112
112
  */
113
113
  export type AuthResolver = AuthToken | ((auth: Auth) => AuthToken | Promise<AuthToken>)
114
114
 
115
+ /**
116
+ * Extra `fetch` init the transport spreads onto every `Request`, an escape hatch for the fields the
117
+ * runtime does not set itself: `cache`, `mode`, `redirect`, `keepalive`, `duplex`, and Next.js's
118
+ * non-standard `next` (`{ revalidate, tags }`). `method`, `headers`, `body`, `signal`, and
119
+ * `credentials` are always controlled by the runtime and override anything set here.
120
+ */
121
+ export type FetchOptions = RequestInit & { next?: Record<string, unknown> }
122
+
115
123
  /**
116
124
  * The request a generated function hands to the runtime. `body` / `headers` / `path` / `query` come
117
125
  * from the grouped options; everything else is plain request configuration.
@@ -127,6 +135,7 @@ export type RequestConfig<TBody = unknown, TRequest = Request, TResponse = Respo
127
135
  headers?: HeadersInit
128
136
  signal?: AbortSignal
129
137
  credentials?: RequestCredentials
138
+ options?: FetchOptions
130
139
  contentType?: string
131
140
  responseType?: ResponseType
132
141
  throwOnError?: boolean
@@ -160,6 +169,7 @@ export type ClientConfig<TRequest = Request, TResponse = Response> = {
160
169
  baseURL?: string
161
170
  headers?: HeadersInit
162
171
  credentials?: RequestCredentials
172
+ options?: FetchOptions
163
173
  throwOnError?: boolean
164
174
  transport?: Transport<TRequest, TResponse>
165
175
  querySerializer?: QuerySerializer
@@ -178,6 +188,7 @@ export type ResolvedRequest = {
178
188
  body?: BodyInit
179
189
  signal?: AbortSignal
180
190
  credentials?: RequestCredentials
191
+ options?: FetchOptions
181
192
  responseType?: ResponseType
182
193
  }
183
194
 
@@ -480,6 +491,8 @@ export function createClientCore<TRequest = Request, TResponse = Response>(
480
491
  }
481
492
  const url = serializeUrl([config.baseURL, requestConfig.baseURL, requestConfig.url], requestConfig.path ?? {}, querySerializer(query))
482
493
 
494
+ const options = config.options || requestConfig.options ? { ...config.options, ...requestConfig.options } : undefined
495
+
483
496
  let resolvedRequest: ResolvedRequest = {
484
497
  url,
485
498
  method: (requestConfig.method ?? 'GET').toUpperCase(),
@@ -487,6 +500,7 @@ export function createClientCore<TRequest = Request, TResponse = Response>(
487
500
  body,
488
501
  signal: requestConfig.signal,
489
502
  credentials: requestConfig.credentials,
503
+ options,
490
504
  responseType: requestConfig.responseType,
491
505
  }
492
506
  resolvedRequest = await interceptors.request.run(resolvedRequest)
@@ -590,6 +604,7 @@ async function parseResponse(response: Response, responseType?: ResponseType): P
590
604
  */
591
605
  const defaultTransport: Transport = async (request: ResolvedRequest): Promise<TransportResult> => {
592
606
  const init: RequestInit = {
607
+ ...request.options, // cache, mode, redirect, keepalive, duplex, next, …
593
608
  method: request.method,
594
609
  headers: request.headers,
595
610
  body: request.body,