@kubb/plugin-fetch 5.1.0 → 5.1.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-fetch",
3
- "version": "5.1.0",
3
+ "version": "5.1.1",
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",
@@ -61,13 +61,13 @@
61
61
  },
62
62
  "dependencies": {
63
63
  "@kubb/plugin-ts": "^5.0.0",
64
- "@kubb/plugin-zod": "^5.1.0"
64
+ "@kubb/plugin-zod": "^5.1.1"
65
65
  },
66
66
  "devDependencies": {
67
- "kubb": "^5.0.1",
68
- "typescript": "^6.0.3",
67
+ "@internals/client": "0.0.0",
69
68
  "@internals/shared": "0.0.0",
70
- "@internals/client": "0.0.0"
69
+ "kubb": "^5.0.1",
70
+ "typescript": "^6.0.3"
71
71
  },
72
72
  "peerDependencies": {
73
73
  "kubb": "^5.0.1"
@@ -126,11 +126,22 @@ export function isDefaultJsonBody(body: unknown): boolean {
126
126
  return body !== undefined && body !== null && !isFormBody(body)
127
127
  }
128
128
 
129
+ /**
130
+ * Emits a `bigint` (`format: int64`) as a JSON number, which `JSON.stringify` refuses to do itself.
131
+ * Past the safe-integer range it throws, so an id never goes out silently truncated.
132
+ */
133
+ function jsonReplacer(_key: string, value: unknown): unknown {
134
+ if (typeof value !== 'bigint') return value
135
+ if (value > Number.MAX_SAFE_INTEGER || value < Number.MIN_SAFE_INTEGER)
136
+ throw new TypeError(`Cannot serialize ${value}n as JSON without losing precision, register a serializer.body to send it another way.`)
137
+ return Number(value)
138
+ }
139
+
129
140
  function appendFormDataValue({ formData, key, value, contentType }: { formData: FormData; key: string; value: unknown; contentType?: string }): void {
130
141
  if (value === undefined || value === null) return
131
142
  if (value instanceof Blob) formData.append(key, value)
132
143
  else if (typeof value === 'object' && !(value instanceof Date)) {
133
- const json = JSON.stringify(value)
144
+ const json = JSON.stringify(value, jsonReplacer)
134
145
  // A part's media type can only be set by wrapping the value in a typed Blob.
135
146
  formData.append(key, contentType ? new Blob([json], { type: contentType }) : json)
136
147
  } else formData.append(key, toValue(value))
@@ -166,7 +177,7 @@ export const defaultBodySerializer: BodySerializer = ({ body, contentType, encod
166
177
  if (encoding) return serializeUrlencodedBody(body as Record<string, unknown>, encoding)
167
178
  return new URLSearchParams(body as Record<string, string>)
168
179
  }
169
- return JSON.stringify(body)
180
+ return JSON.stringify(body, jsonReplacer)
170
181
  }
171
182
 
172
183
  function serializeUrlencodedBody(body: Record<string, unknown>, encoding: Record<string, BodyEncoding>): string {