@saeeol/sdk 7.3.3 → 7.3.4

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 (39) hide show
  1. package/package.json +2 -2
  2. package/src/client.ts +64 -0
  3. package/src/gen/client/client.gen.ts +215 -0
  4. package/src/gen/client/index.ts +25 -0
  5. package/src/gen/client/types.gen.ts +222 -0
  6. package/src/gen/client/utils.gen.ts +287 -0
  7. package/src/gen/client.gen.ts +22 -0
  8. package/src/gen/core/auth.gen.ts +41 -0
  9. package/src/gen/core/bodySerializer.gen.ts +74 -0
  10. package/src/gen/core/params.gen.ts +144 -0
  11. package/src/gen/core/pathSerializer.gen.ts +167 -0
  12. package/src/gen/core/queryKeySerializer.gen.ts +111 -0
  13. package/src/gen/core/serverSentEvents.gen.ts +210 -0
  14. package/src/gen/core/types.gen.ts +91 -0
  15. package/src/gen/core/utils.gen.ts +109 -0
  16. package/src/gen/sdk.gen.ts +1197 -0
  17. package/src/gen/types.gen.ts +3905 -0
  18. package/src/index.ts +21 -0
  19. package/src/process.ts +31 -0
  20. package/src/server.ts +165 -0
  21. package/src/v2/client.ts +97 -0
  22. package/src/v2/data.ts +32 -0
  23. package/src/v2/gen/client/client.gen.ts +285 -0
  24. package/src/v2/gen/client/index.ts +25 -0
  25. package/src/v2/gen/client/types.gen.ts +202 -0
  26. package/src/v2/gen/client/utils.gen.ts +289 -0
  27. package/src/v2/gen/client.gen.ts +18 -0
  28. package/src/v2/gen/core/auth.gen.ts +41 -0
  29. package/src/v2/gen/core/bodySerializer.gen.ts +82 -0
  30. package/src/v2/gen/core/params.gen.ts +169 -0
  31. package/src/v2/gen/core/pathSerializer.gen.ts +167 -0
  32. package/src/v2/gen/core/queryKeySerializer.gen.ts +111 -0
  33. package/src/v2/gen/core/serverSentEvents.gen.ts +239 -0
  34. package/src/v2/gen/core/types.gen.ts +86 -0
  35. package/src/v2/gen/core/utils.gen.ts +137 -0
  36. package/src/v2/gen/sdk.gen.ts +6316 -0
  37. package/src/v2/gen/types.gen.ts +7495 -0
  38. package/src/v2/index.ts +23 -0
  39. package/src/v2/server.ts +163 -0
@@ -0,0 +1,202 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+
3
+ import type { Auth } from "../core/auth.gen.js"
4
+ import type { ServerSentEventsOptions, ServerSentEventsResult } from "../core/serverSentEvents.gen.js"
5
+ import type { Client as CoreClient, Config as CoreConfig } from "../core/types.gen.js"
6
+ import type { Middleware } from "./utils.gen.js"
7
+
8
+ export type ResponseStyle = "data" | "fields"
9
+
10
+ export interface Config<T extends ClientOptions = ClientOptions>
11
+ extends Omit<RequestInit, "body" | "headers" | "method">,
12
+ CoreConfig {
13
+ /**
14
+ * Base URL for all requests made by this client.
15
+ */
16
+ baseUrl?: T["baseUrl"]
17
+ /**
18
+ * Fetch API implementation. You can use this option to provide a custom
19
+ * fetch instance.
20
+ *
21
+ * @default globalThis.fetch
22
+ */
23
+ fetch?: typeof fetch
24
+ /**
25
+ * Please don't use the Fetch client for Next.js applications. The `next`
26
+ * options won't have any effect.
27
+ *
28
+ * Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead.
29
+ */
30
+ next?: never
31
+ /**
32
+ * Return the response data parsed in a specified format. By default, `auto`
33
+ * will infer the appropriate method from the `Content-Type` response header.
34
+ * You can override this behavior with any of the {@link Body} methods.
35
+ * Select `stream` if you don't want to parse response data at all.
36
+ *
37
+ * @default 'auto'
38
+ */
39
+ parseAs?: "arrayBuffer" | "auto" | "blob" | "formData" | "json" | "stream" | "text"
40
+ /**
41
+ * Should we return only data or multiple fields (data, error, response, etc.)?
42
+ *
43
+ * @default 'fields'
44
+ */
45
+ responseStyle?: ResponseStyle
46
+ /**
47
+ * Throw an error instead of returning it in the response?
48
+ *
49
+ * @default false
50
+ */
51
+ throwOnError?: T["throwOnError"]
52
+ }
53
+
54
+ export interface RequestOptions<
55
+ TData = unknown,
56
+ TResponseStyle extends ResponseStyle = "fields",
57
+ ThrowOnError extends boolean = boolean,
58
+ Url extends string = string,
59
+ > extends Config<{
60
+ responseStyle: TResponseStyle
61
+ throwOnError: ThrowOnError
62
+ }>,
63
+ Pick<
64
+ ServerSentEventsOptions<TData>,
65
+ "onSseError" | "onSseEvent" | "sseDefaultRetryDelay" | "sseMaxRetryAttempts" | "sseMaxRetryDelay"
66
+ > {
67
+ /**
68
+ * Any body that you want to add to your request.
69
+ *
70
+ * {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
71
+ */
72
+ body?: unknown
73
+ path?: Record<string, unknown>
74
+ query?: Record<string, unknown>
75
+ /**
76
+ * Security mechanism(s) to use for the request.
77
+ */
78
+ security?: ReadonlyArray<Auth>
79
+ url: Url
80
+ }
81
+
82
+ export interface ResolvedRequestOptions<
83
+ TResponseStyle extends ResponseStyle = "fields",
84
+ ThrowOnError extends boolean = boolean,
85
+ Url extends string = string,
86
+ > extends RequestOptions<unknown, TResponseStyle, ThrowOnError, Url> {
87
+ serializedBody?: string
88
+ }
89
+
90
+ export type RequestResult<
91
+ TData = unknown,
92
+ TError = unknown,
93
+ ThrowOnError extends boolean = boolean,
94
+ TResponseStyle extends ResponseStyle = "fields",
95
+ > = ThrowOnError extends true
96
+ ? Promise<
97
+ TResponseStyle extends "data"
98
+ ? TData extends Record<string, unknown>
99
+ ? TData[keyof TData]
100
+ : TData
101
+ : {
102
+ data: TData extends Record<string, unknown> ? TData[keyof TData] : TData
103
+ request: Request
104
+ response: Response
105
+ }
106
+ >
107
+ : Promise<
108
+ TResponseStyle extends "data"
109
+ ? (TData extends Record<string, unknown> ? TData[keyof TData] : TData) | undefined
110
+ : (
111
+ | {
112
+ data: TData extends Record<string, unknown> ? TData[keyof TData] : TData
113
+ error: undefined
114
+ }
115
+ | {
116
+ data: undefined
117
+ error: TError extends Record<string, unknown> ? TError[keyof TError] : TError
118
+ }
119
+ ) & {
120
+ request: Request
121
+ response: Response
122
+ }
123
+ >
124
+
125
+ export interface ClientOptions {
126
+ baseUrl?: string
127
+ responseStyle?: ResponseStyle
128
+ throwOnError?: boolean
129
+ }
130
+
131
+ type MethodFn = <
132
+ TData = unknown,
133
+ TError = unknown,
134
+ ThrowOnError extends boolean = false,
135
+ TResponseStyle extends ResponseStyle = "fields",
136
+ >(
137
+ options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, "method">,
138
+ ) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>
139
+
140
+ type SseFn = <
141
+ TData = unknown,
142
+ TError = unknown,
143
+ ThrowOnError extends boolean = false,
144
+ TResponseStyle extends ResponseStyle = "fields",
145
+ >(
146
+ options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, "method">,
147
+ ) => Promise<ServerSentEventsResult<TData, TError>>
148
+
149
+ type RequestFn = <
150
+ TData = unknown,
151
+ TError = unknown,
152
+ ThrowOnError extends boolean = false,
153
+ TResponseStyle extends ResponseStyle = "fields",
154
+ >(
155
+ options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, "method"> &
156
+ Pick<Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>, "method">,
157
+ ) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>
158
+
159
+ type BuildUrlFn = <
160
+ TData extends {
161
+ body?: unknown
162
+ path?: Record<string, unknown>
163
+ query?: Record<string, unknown>
164
+ url: string
165
+ },
166
+ >(
167
+ options: TData & Options<TData>,
168
+ ) => string
169
+
170
+ export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
171
+ interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions>
172
+ }
173
+
174
+ /**
175
+ * The `createClientConfig()` function will be called on client initialization
176
+ * and the returned object will become the client's initial configuration.
177
+ *
178
+ * You may want to initialize your client this way instead of calling
179
+ * `setConfig()`. This is useful for example if you're using Next.js
180
+ * to ensure your client always has the correct values.
181
+ */
182
+ export type CreateClientConfig<T extends ClientOptions = ClientOptions> = (
183
+ override?: Config<ClientOptions & T>,
184
+ ) => Config<Required<ClientOptions> & T>
185
+
186
+ export interface TDataShape {
187
+ body?: unknown
188
+ headers?: unknown
189
+ path?: unknown
190
+ query?: unknown
191
+ url: string
192
+ }
193
+
194
+ type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>
195
+
196
+ export type Options<
197
+ TData extends TDataShape = TDataShape,
198
+ ThrowOnError extends boolean = boolean,
199
+ TResponse = unknown,
200
+ TResponseStyle extends ResponseStyle = "fields",
201
+ > = OmitKeys<RequestOptions<TResponse, TResponseStyle, ThrowOnError>, "body" | "path" | "query" | "url"> &
202
+ ([TData] extends [never] ? unknown : Omit<TData, "url">)
@@ -0,0 +1,289 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+
3
+ import { getAuthToken } from "../core/auth.gen.js"
4
+ import type { QuerySerializerOptions } from "../core/bodySerializer.gen.js"
5
+ import { jsonBodySerializer } from "../core/bodySerializer.gen.js"
6
+ import { serializeArrayParam, serializeObjectParam, serializePrimitiveParam } from "../core/pathSerializer.gen.js"
7
+ import { getUrl } from "../core/utils.gen.js"
8
+ import type { Client, ClientOptions, Config, RequestOptions } from "./types.gen.js"
9
+
10
+ export const createQuerySerializer = <T = unknown>({ parameters = {}, ...args }: QuerySerializerOptions = {}) => {
11
+ const querySerializer = (queryParams: T) => {
12
+ const search: string[] = []
13
+ if (queryParams && typeof queryParams === "object") {
14
+ for (const name in queryParams) {
15
+ const value = queryParams[name]
16
+
17
+ if (value === undefined || value === null) {
18
+ continue
19
+ }
20
+
21
+ const options = parameters[name] || args
22
+
23
+ if (Array.isArray(value)) {
24
+ const serializedArray = serializeArrayParam({
25
+ allowReserved: options.allowReserved,
26
+ explode: true,
27
+ name,
28
+ style: "form",
29
+ value,
30
+ ...options.array,
31
+ })
32
+ if (serializedArray) search.push(serializedArray)
33
+ } else if (typeof value === "object") {
34
+ const serializedObject = serializeObjectParam({
35
+ allowReserved: options.allowReserved,
36
+ explode: true,
37
+ name,
38
+ style: "deepObject",
39
+ value: value as Record<string, unknown>,
40
+ ...options.object,
41
+ })
42
+ if (serializedObject) search.push(serializedObject)
43
+ } else {
44
+ const serializedPrimitive = serializePrimitiveParam({
45
+ allowReserved: options.allowReserved,
46
+ name,
47
+ value: value as string,
48
+ })
49
+ if (serializedPrimitive) search.push(serializedPrimitive)
50
+ }
51
+ }
52
+ }
53
+ return search.join("&")
54
+ }
55
+ return querySerializer
56
+ }
57
+
58
+ /**
59
+ * Infers parseAs value from provided Content-Type header.
60
+ */
61
+ export const getParseAs = (contentType: string | null): Exclude<Config["parseAs"], "auto"> => {
62
+ if (!contentType) {
63
+ // If no Content-Type header is provided, the best we can do is return the raw response body,
64
+ // which is effectively the same as the 'stream' option.
65
+ return "stream"
66
+ }
67
+
68
+ const cleanContent = contentType.split(";")[0]?.trim()
69
+
70
+ if (!cleanContent) {
71
+ return
72
+ }
73
+
74
+ if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
75
+ return "json"
76
+ }
77
+
78
+ if (cleanContent === "multipart/form-data") {
79
+ return "formData"
80
+ }
81
+
82
+ if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
83
+ return "blob"
84
+ }
85
+
86
+ if (cleanContent.startsWith("text/")) {
87
+ return "text"
88
+ }
89
+
90
+ return
91
+ }
92
+
93
+ const checkForExistence = (
94
+ options: Pick<RequestOptions, "auth" | "query"> & {
95
+ headers: Headers
96
+ },
97
+ name?: string,
98
+ ): boolean => {
99
+ if (!name) {
100
+ return false
101
+ }
102
+ if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
103
+ return true
104
+ }
105
+ return false
106
+ }
107
+
108
+ export const setAuthParams = async ({
109
+ security,
110
+ ...options
111
+ }: Pick<Required<RequestOptions>, "security"> &
112
+ Pick<RequestOptions, "auth" | "query"> & {
113
+ headers: Headers
114
+ }) => {
115
+ for (const auth of security) {
116
+ if (checkForExistence(options, auth.name)) {
117
+ continue
118
+ }
119
+
120
+ const token = await getAuthToken(auth, options.auth)
121
+
122
+ if (!token) {
123
+ continue
124
+ }
125
+
126
+ const name = auth.name ?? "Authorization"
127
+
128
+ switch (auth.in) {
129
+ case "query":
130
+ if (!options.query) {
131
+ options.query = {}
132
+ }
133
+ options.query[name] = token
134
+ break
135
+ case "cookie":
136
+ options.headers.append("Cookie", `${name}=${token}`)
137
+ break
138
+ case "header":
139
+ default:
140
+ options.headers.set(name, token)
141
+ break
142
+ }
143
+ }
144
+ }
145
+
146
+ export const buildUrl: Client["buildUrl"] = (options) =>
147
+ getUrl({
148
+ baseUrl: options.baseUrl as string,
149
+ path: options.path,
150
+ query: options.query,
151
+ querySerializer:
152
+ typeof options.querySerializer === "function"
153
+ ? options.querySerializer
154
+ : createQuerySerializer(options.querySerializer),
155
+ url: options.url,
156
+ })
157
+
158
+ export const mergeConfigs = (a: Config, b: Config): Config => {
159
+ const config = { ...a, ...b }
160
+ if (config.baseUrl?.endsWith("/")) {
161
+ config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1)
162
+ }
163
+ config.headers = mergeHeaders(a.headers, b.headers)
164
+ return config
165
+ }
166
+
167
+ const headersEntries = (headers: Headers): Array<[string, string]> => {
168
+ const entries: Array<[string, string]> = []
169
+ headers.forEach((value, key) => {
170
+ entries.push([key, value])
171
+ })
172
+ return entries
173
+ }
174
+
175
+ export const mergeHeaders = (...headers: Array<Required<Config>["headers"] | undefined>): Headers => {
176
+ const mergedHeaders = new Headers()
177
+ for (const header of headers) {
178
+ if (!header) {
179
+ continue
180
+ }
181
+
182
+ const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header)
183
+
184
+ for (const [key, value] of iterator) {
185
+ if (value === null) {
186
+ mergedHeaders.delete(key)
187
+ } else if (Array.isArray(value)) {
188
+ for (const v of value) {
189
+ mergedHeaders.append(key, v as string)
190
+ }
191
+ } else if (value !== undefined) {
192
+ // assume object headers are meant to be JSON stringified, i.e. their
193
+ // content value in OpenAPI specification is 'application/json'
194
+ mergedHeaders.set(key, typeof value === "object" ? JSON.stringify(value) : (value as string))
195
+ }
196
+ }
197
+ }
198
+ return mergedHeaders
199
+ }
200
+
201
+ type ErrInterceptor<Err, Res, Req, Options> = (
202
+ error: Err,
203
+ response: Res,
204
+ request: Req,
205
+ options: Options,
206
+ ) => Err | Promise<Err>
207
+
208
+ type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>
209
+
210
+ type ResInterceptor<Res, Req, Options> = (response: Res, request: Req, options: Options) => Res | Promise<Res>
211
+
212
+ class Interceptors<Interceptor> {
213
+ fns: Array<Interceptor | null> = []
214
+
215
+ clear(): void {
216
+ this.fns = []
217
+ }
218
+
219
+ eject(id: number | Interceptor): void {
220
+ const index = this.getInterceptorIndex(id)
221
+ if (this.fns[index]) {
222
+ this.fns[index] = null
223
+ }
224
+ }
225
+
226
+ exists(id: number | Interceptor): boolean {
227
+ const index = this.getInterceptorIndex(id)
228
+ return Boolean(this.fns[index])
229
+ }
230
+
231
+ getInterceptorIndex(id: number | Interceptor): number {
232
+ if (typeof id === "number") {
233
+ return this.fns[id] ? id : -1
234
+ }
235
+ return this.fns.indexOf(id)
236
+ }
237
+
238
+ update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false {
239
+ const index = this.getInterceptorIndex(id)
240
+ if (this.fns[index]) {
241
+ this.fns[index] = fn
242
+ return id
243
+ }
244
+ return false
245
+ }
246
+
247
+ use(fn: Interceptor): number {
248
+ this.fns.push(fn)
249
+ return this.fns.length - 1
250
+ }
251
+ }
252
+
253
+ export interface Middleware<Req, Res, Err, Options> {
254
+ error: Interceptors<ErrInterceptor<Err, Res, Req, Options>>
255
+ request: Interceptors<ReqInterceptor<Req, Options>>
256
+ response: Interceptors<ResInterceptor<Res, Req, Options>>
257
+ }
258
+
259
+ export const createInterceptors = <Req, Res, Err, Options>(): Middleware<Req, Res, Err, Options> => ({
260
+ error: new Interceptors<ErrInterceptor<Err, Res, Req, Options>>(),
261
+ request: new Interceptors<ReqInterceptor<Req, Options>>(),
262
+ response: new Interceptors<ResInterceptor<Res, Req, Options>>(),
263
+ })
264
+
265
+ const defaultQuerySerializer = createQuerySerializer({
266
+ allowReserved: false,
267
+ array: {
268
+ explode: true,
269
+ style: "form",
270
+ },
271
+ object: {
272
+ explode: true,
273
+ style: "deepObject",
274
+ },
275
+ })
276
+
277
+ const defaultHeaders = {
278
+ "Content-Type": "application/json",
279
+ }
280
+
281
+ export const createConfig = <T extends ClientOptions = ClientOptions>(
282
+ override: Config<Omit<ClientOptions, keyof T> & T> = {},
283
+ ): Config<Omit<ClientOptions, keyof T> & T> => ({
284
+ ...jsonBodySerializer,
285
+ headers: defaultHeaders,
286
+ parseAs: "auto",
287
+ querySerializer: defaultQuerySerializer,
288
+ ...override,
289
+ })
@@ -0,0 +1,18 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+
3
+ import { type ClientOptions, type Config, createClient, createConfig } from "./client/index.js"
4
+ import type { ClientOptions as ClientOptions2 } from "./types.gen.js"
5
+
6
+ /**
7
+ * The `createClientConfig()` function will be called on client initialization
8
+ * and the returned object will become the client's initial configuration.
9
+ *
10
+ * You may want to initialize your client this way instead of calling
11
+ * `setConfig()`. This is useful for example if you're using Next.js
12
+ * to ensure your client always has the correct values.
13
+ */
14
+ export type CreateClientConfig<T extends ClientOptions = ClientOptions2> = (
15
+ override?: Config<ClientOptions & T>,
16
+ ) => Config<Required<ClientOptions> & T>
17
+
18
+ export const client = createClient(createConfig<ClientOptions2>({ baseUrl: "http://localhost:4096" }))
@@ -0,0 +1,41 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+
3
+ export type AuthToken = string | undefined
4
+
5
+ export interface Auth {
6
+ /**
7
+ * Which part of the request do we use to send the auth?
8
+ *
9
+ * @default 'header'
10
+ */
11
+ in?: "header" | "query" | "cookie"
12
+ /**
13
+ * Header or query parameter name.
14
+ *
15
+ * @default 'Authorization'
16
+ */
17
+ name?: string
18
+ scheme?: "basic" | "bearer"
19
+ type: "apiKey" | "http"
20
+ }
21
+
22
+ export const getAuthToken = async (
23
+ auth: Auth,
24
+ callback: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken,
25
+ ): Promise<string | undefined> => {
26
+ const token = typeof callback === "function" ? await callback(auth) : callback
27
+
28
+ if (!token) {
29
+ return
30
+ }
31
+
32
+ if (auth.scheme === "bearer") {
33
+ return `Bearer ${token}`
34
+ }
35
+
36
+ if (auth.scheme === "basic") {
37
+ return `Basic ${btoa(token)}`
38
+ }
39
+
40
+ return token
41
+ }
@@ -0,0 +1,82 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+
3
+ import type { ArrayStyle, ObjectStyle, SerializerOptions } from "./pathSerializer.gen.js"
4
+
5
+ export type QuerySerializer = (query: Record<string, unknown>) => string
6
+
7
+ export type BodySerializer = (body: any) => any
8
+
9
+ type QuerySerializerOptionsObject = {
10
+ allowReserved?: boolean
11
+ array?: Partial<SerializerOptions<ArrayStyle>>
12
+ object?: Partial<SerializerOptions<ObjectStyle>>
13
+ }
14
+
15
+ export type QuerySerializerOptions = QuerySerializerOptionsObject & {
16
+ /**
17
+ * Per-parameter serialization overrides. When provided, these settings
18
+ * override the global array/object settings for specific parameter names.
19
+ */
20
+ parameters?: Record<string, QuerySerializerOptionsObject>
21
+ }
22
+
23
+ const serializeFormDataPair = (data: FormData, key: string, value: unknown): void => {
24
+ if (typeof value === "string" || value instanceof Blob) {
25
+ data.append(key, value)
26
+ } else if (value instanceof Date) {
27
+ data.append(key, value.toISOString())
28
+ } else {
29
+ data.append(key, JSON.stringify(value))
30
+ }
31
+ }
32
+
33
+ const serializeUrlSearchParamsPair = (data: URLSearchParams, key: string, value: unknown): void => {
34
+ if (typeof value === "string") {
35
+ data.append(key, value)
36
+ } else {
37
+ data.append(key, JSON.stringify(value))
38
+ }
39
+ }
40
+
41
+ export const formDataBodySerializer = {
42
+ bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T): FormData => {
43
+ const data = new FormData()
44
+
45
+ Object.entries(body).forEach(([key, value]) => {
46
+ if (value === undefined || value === null) {
47
+ return
48
+ }
49
+ if (Array.isArray(value)) {
50
+ value.forEach((v) => serializeFormDataPair(data, key, v))
51
+ } else {
52
+ serializeFormDataPair(data, key, value)
53
+ }
54
+ })
55
+
56
+ return data
57
+ },
58
+ }
59
+
60
+ export const jsonBodySerializer = {
61
+ bodySerializer: <T>(body: T): string =>
62
+ JSON.stringify(body, (_key, value) => (typeof value === "bigint" ? value.toString() : value)),
63
+ }
64
+
65
+ export const urlSearchParamsBodySerializer = {
66
+ bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T): string => {
67
+ const data = new URLSearchParams()
68
+
69
+ Object.entries(body).forEach(([key, value]) => {
70
+ if (value === undefined || value === null) {
71
+ return
72
+ }
73
+ if (Array.isArray(value)) {
74
+ value.forEach((v) => serializeUrlSearchParamsPair(data, key, v))
75
+ } else {
76
+ serializeUrlSearchParamsPair(data, key, value)
77
+ }
78
+ })
79
+
80
+ return data.toString()
81
+ },
82
+ }