@kubb/plugin-fetch 5.2.1 → 5.2.2
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.
- package/package.json +3 -3
- package/templates/fetch.ts +3 -3
- package/templates/serializers.ts +9 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-fetch",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.2",
|
|
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",
|
|
@@ -67,11 +67,11 @@
|
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@internals/client": "0.0.0",
|
|
69
69
|
"@internals/shared": "0.0.0",
|
|
70
|
-
"kubb": "^5.0.
|
|
70
|
+
"kubb": "^5.0.6",
|
|
71
71
|
"typescript": "^6.0.3"
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|
|
74
|
-
"kubb": "^5.0.
|
|
74
|
+
"kubb": "^5.0.6"
|
|
75
75
|
},
|
|
76
76
|
"engines": {
|
|
77
77
|
"node": ">=22"
|
package/templates/fetch.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { applyHeaderStyles, defaultBodySerializer, defaultPathSerializer, defaultQuerySerializer, isDefaultJsonBody, serializeCookies } from './serializers'
|
|
2
|
-
import type { HeadersInit, PathParamStyle, PathSerializer, Serializers, Styles } from './serializers'
|
|
2
|
+
import type { HeadersInit, PathParamStyle, PathSerializer, RequestBody, Serializers, Styles } from './serializers'
|
|
3
3
|
import { type StandardSchemaValidator, validateStandardSchema } from './standardSchema'
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -124,7 +124,7 @@ export type Deserializer<T = unknown> = (raw: unknown, contentType: string) => T
|
|
|
124
124
|
/**
|
|
125
125
|
* Serializes a request body for a single media type, registered per content type as a codec's `serialize` to encode formats the default serializer does not handle.
|
|
126
126
|
*/
|
|
127
|
-
export type ContentBodySerializer = (body: unknown, contentType?: string) =>
|
|
127
|
+
export type ContentBodySerializer = (body: unknown, contentType?: string) => RequestBody | undefined
|
|
128
128
|
|
|
129
129
|
/**
|
|
130
130
|
* A per-content-type codec registered on `codecs`, keyed by content type. `serialize` encodes the
|
|
@@ -238,7 +238,7 @@ export type ResolvedRequest = {
|
|
|
238
238
|
url: string
|
|
239
239
|
method: string
|
|
240
240
|
headers: Record<string, string>
|
|
241
|
-
body?:
|
|
241
|
+
body?: RequestBody
|
|
242
242
|
signal?: AbortSignal
|
|
243
243
|
credentials?: RequestCredentials
|
|
244
244
|
options?: FetchOptions
|
package/templates/serializers.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
export type HeaderValue = string | number | boolean | null | undefined | object
|
|
2
2
|
export type HeadersInit = Array<[string, HeaderValue]> | Record<string, HeaderValue>
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* The request body type `fetch` accepts, derived from `RequestInit` instead of the global `BodyInit`
|
|
6
|
+
* name, which a Node-only project (`@types/node` without the `dom` lib) does not declare.
|
|
7
|
+
*/
|
|
8
|
+
export type RequestBody = NonNullable<RequestInit['body']>
|
|
9
|
+
|
|
4
10
|
/**
|
|
5
11
|
* The OpenAPI query-parameter serialization style. `form` is the default; `spaceDelimited` and
|
|
6
12
|
* `pipeDelimited` join arrays with a space or pipe, and `deepObject` renders objects as
|
|
@@ -67,7 +73,7 @@ export type BodyEncoding = SerializationStyle<QueryStyle> & {
|
|
|
67
73
|
* `ArrayBuffer`, and string bodies pass through untouched. The optional `encoding` argument carries
|
|
68
74
|
* the per-property OpenAPI `encoding` metadata for form bodies.
|
|
69
75
|
*/
|
|
70
|
-
export type BodySerializer = (args: { body: unknown; contentType?: string; encoding?: Record<string, BodyEncoding> }) =>
|
|
76
|
+
export type BodySerializer = (args: { body: unknown; contentType?: string; encoding?: Record<string, BodyEncoding> }) => RequestBody | undefined
|
|
71
77
|
|
|
72
78
|
/**
|
|
73
79
|
* The OpenAPI path-parameter serialization style. `simple` is the default and emits the bare value;
|
|
@@ -111,7 +117,7 @@ export type Styles = {
|
|
|
111
117
|
body?: Record<string, BodyEncoding>
|
|
112
118
|
}
|
|
113
119
|
|
|
114
|
-
function isFormBody(body: unknown): body is
|
|
120
|
+
function isFormBody(body: unknown): body is RequestBody {
|
|
115
121
|
return (
|
|
116
122
|
body instanceof FormData ||
|
|
117
123
|
body instanceof URLSearchParams ||
|
|
@@ -163,7 +169,7 @@ function appendFormDataValue({ formData, key, value, contentType }: { formData:
|
|
|
163
169
|
*/
|
|
164
170
|
export const defaultBodySerializer: BodySerializer = ({ body, contentType, encoding }) => {
|
|
165
171
|
if (body === undefined || body === null) return undefined
|
|
166
|
-
if (isFormBody(body)) return body as
|
|
172
|
+
if (isFormBody(body)) return body as RequestBody
|
|
167
173
|
if (contentType?.includes('multipart/form-data')) {
|
|
168
174
|
const formData = new FormData()
|
|
169
175
|
for (const [key, value] of Object.entries(body as Record<string, unknown>)) {
|