openapi-typesafe-fetch 0.0.0 → 1.0.0-rc.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/LICENSE +22 -0
- package/README.md +52 -1
- package/dist/index.cjs +620 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +413 -0
- package/dist/index.d.mts +413 -0
- package/dist/index.d.ts +413 -0
- package/dist/index.mjs +604 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +87 -4
- package/src/index.d.ts +423 -0
- package/src/index.js +814 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
import { OperationRequestBodyContent, MediaType, HttpMethod, PathsWithMethod, RequiredKeysOf, Writable, IsOperationRequestBodyOptional, FilterKeys, Readable, SuccessResponse, ResponseObjectMap, ErrorResponse } from 'openapi-typesafe-helpers';
|
|
2
|
+
|
|
3
|
+
/** Options for each client instance */
|
|
4
|
+
interface ClientOptions extends Omit<RequestInit, "headers"> {
|
|
5
|
+
/** set the common root URL for all API requests */
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
/** custom fetch (defaults to globalThis.fetch) */
|
|
8
|
+
fetch?: (input: Request) => Promise<Response>;
|
|
9
|
+
/** custom Request (defaults to globalThis.Request) */
|
|
10
|
+
Request?: typeof Request;
|
|
11
|
+
/** global querySerializer */
|
|
12
|
+
querySerializer?: QuerySerializer<unknown> | QuerySerializerOptions;
|
|
13
|
+
/** global bodySerializer */
|
|
14
|
+
bodySerializer?: BodySerializer<unknown>;
|
|
15
|
+
/** global pathSerializer */
|
|
16
|
+
pathSerializer?: PathSerializer;
|
|
17
|
+
headers?: HeadersOptions;
|
|
18
|
+
/** RequestInit extension object to pass as 2nd argument to fetch when supported (defaults to undefined) */
|
|
19
|
+
requestInitExt?: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* `ClientOptions` for a Fetch API implementation with its own types, such as the `undici` package
|
|
24
|
+
* (upstream #2562). TypeScript cannot relate its `Request` and `Response` to the DOM lib's (`duplex`,
|
|
25
|
+
* `RequestDestination`, `BodyInit` differ), so only what the client needs is checked: a `fetch`
|
|
26
|
+
* that returns a promise and a `Request` class that takes a URL. Pass the `fetch` and the `Request`
|
|
27
|
+
* of the same implementation; middleware and results still use the DOM types. The `createClient`
|
|
28
|
+
* overload with `ClientOptions` comes first, so an inline `fetch` gets a typed `Request` input.
|
|
29
|
+
*/
|
|
30
|
+
interface OtherFetchClientOptions extends Omit<ClientOptions, "fetch" | "Request"> {
|
|
31
|
+
/** `fetch` of another implementation (for example `fetch` from `undici`) */
|
|
32
|
+
fetch?: (input: never, init?: never) => PromiseLike<object>;
|
|
33
|
+
/** `Request` of the same implementation (for example `Request` from `undici`) */
|
|
34
|
+
Request?: new (
|
|
35
|
+
input: string,
|
|
36
|
+
init: never,
|
|
37
|
+
) => object;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
type HeadersOptions =
|
|
41
|
+
| Required<RequestInit>["headers"]
|
|
42
|
+
| Record<string, string | number | boolean | (string | number | boolean)[] | null | undefined>;
|
|
43
|
+
|
|
44
|
+
type QuerySerializer<T> = (
|
|
45
|
+
query: T extends { parameters: any } ? NonNullable<T["parameters"]["query"]> : Record<string, unknown>,
|
|
46
|
+
) => string;
|
|
47
|
+
|
|
48
|
+
/** @see https://swagger.io/docs/specification/serialization/#query */
|
|
49
|
+
type QuerySerializerOptions = {
|
|
50
|
+
/** Set serialization for arrays. @see https://swagger.io/docs/specification/serialization/#query */
|
|
51
|
+
array?: {
|
|
52
|
+
/** default: "form" */
|
|
53
|
+
style: "form" | "spaceDelimited" | "pipeDelimited";
|
|
54
|
+
/** default: true */
|
|
55
|
+
explode: boolean;
|
|
56
|
+
};
|
|
57
|
+
/** Set serialization for objects. @see https://swagger.io/docs/specification/serialization/#query */
|
|
58
|
+
object?: {
|
|
59
|
+
/** default: "deepObject" */
|
|
60
|
+
style: "form" | "deepObject";
|
|
61
|
+
/** default: true */
|
|
62
|
+
explode: boolean;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* The `allowReserved` keyword specifies whether the reserved characters
|
|
66
|
+
* `:/?#[]@!$&'()*+,;=` in parameter values are allowed to be sent as they
|
|
67
|
+
* are, or should be percent-encoded. By default, allowReserved is `false`,
|
|
68
|
+
* and reserved characters are percent-encoded.
|
|
69
|
+
* @see https://swagger.io/docs/specification/serialization/#query
|
|
70
|
+
*/
|
|
71
|
+
allowReserved?: boolean;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
type BodySerializer<T> = (body: OperationRequestBodyContent<T>) => any;
|
|
75
|
+
|
|
76
|
+
type PathSerializer = (pathname: string, pathParams: Record<string, unknown>) => string;
|
|
77
|
+
|
|
78
|
+
type BodyType<T = unknown> = {
|
|
79
|
+
json: T;
|
|
80
|
+
text: Awaited<ReturnType<Response["text"]>>;
|
|
81
|
+
blob: Awaited<ReturnType<Response["blob"]>>;
|
|
82
|
+
arrayBuffer: Awaited<ReturnType<Response["arrayBuffer"]>>;
|
|
83
|
+
stream: Response["body"];
|
|
84
|
+
};
|
|
85
|
+
type ParseAs = keyof BodyType;
|
|
86
|
+
type ParseAsResponse<T, Options> = Options extends {
|
|
87
|
+
parseAs: ParseAs;
|
|
88
|
+
}
|
|
89
|
+
? BodyType<T>[Options["parseAs"]]
|
|
90
|
+
: T;
|
|
91
|
+
|
|
92
|
+
interface DefaultParamsOption {
|
|
93
|
+
params?: {
|
|
94
|
+
query?: Record<string, unknown>;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
type ParamsOption<T> = T extends {
|
|
99
|
+
parameters: any;
|
|
100
|
+
}
|
|
101
|
+
? RequiredKeysOf<T["parameters"]> extends never
|
|
102
|
+
? { params?: T["parameters"] }
|
|
103
|
+
: { params: T["parameters"] }
|
|
104
|
+
: DefaultParamsOption;
|
|
105
|
+
|
|
106
|
+
/** `true` for `any`: the operation of `createClient<any>()`, which says nothing about its body. */
|
|
107
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
108
|
+
|
|
109
|
+
// Writable<T> strips $Read markers (readOnly properties excluded from request body).
|
|
110
|
+
// An `any` operation is checked first: a conditional type on `any` takes both branches, which
|
|
111
|
+
// gave `{ body?: never } | { body: any }` and so a required init (upstream #2526).
|
|
112
|
+
type RequestBodyOption<T> =
|
|
113
|
+
IsAny<T> extends true
|
|
114
|
+
? { body?: any }
|
|
115
|
+
: Writable<OperationRequestBodyContent<T>> extends never
|
|
116
|
+
? { body?: never }
|
|
117
|
+
: IsOperationRequestBodyOptional<T> extends true
|
|
118
|
+
? { body?: Writable<OperationRequestBodyContent<T>> }
|
|
119
|
+
: { body: Writable<OperationRequestBodyContent<T>> };
|
|
120
|
+
|
|
121
|
+
type FetchOptions<T> = RequestOptions<T> & Omit<RequestInit, "body" | "headers">;
|
|
122
|
+
|
|
123
|
+
// Readable<T> strips $Write markers (writeOnly properties excluded from response)
|
|
124
|
+
type FetchResponse<T extends Record<string | number, any>, Options, Media extends MediaType> =
|
|
125
|
+
| {
|
|
126
|
+
data: ParseAsResponse<Readable<SuccessResponse<ResponseObjectMap<T>, Media>>, Options>;
|
|
127
|
+
error?: never;
|
|
128
|
+
response: Response;
|
|
129
|
+
}
|
|
130
|
+
| {
|
|
131
|
+
data?: never;
|
|
132
|
+
error: Readable<ErrorResponse<ResponseObjectMap<T>, Media>>;
|
|
133
|
+
response: Response;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
type RequestOptions<T> = ParamsOption<T> &
|
|
137
|
+
RequestBodyOption<T> & {
|
|
138
|
+
baseUrl?: string;
|
|
139
|
+
querySerializer?: QuerySerializer<T> | QuerySerializerOptions;
|
|
140
|
+
bodySerializer?: BodySerializer<T>;
|
|
141
|
+
pathSerializer?: PathSerializer;
|
|
142
|
+
parseAs?: ParseAs;
|
|
143
|
+
fetch?: ClientOptions["fetch"];
|
|
144
|
+
headers?: HeadersOptions;
|
|
145
|
+
middleware?: Middleware[];
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
type MergedOptions<T = unknown> = {
|
|
149
|
+
baseUrl: string;
|
|
150
|
+
parseAs: ParseAs;
|
|
151
|
+
querySerializer: QuerySerializer<T>;
|
|
152
|
+
bodySerializer: BodySerializer<T>;
|
|
153
|
+
pathSerializer: PathSerializer;
|
|
154
|
+
fetch: typeof globalThis.fetch;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
interface MiddlewareRequestParams {
|
|
158
|
+
query?: Record<string, unknown>;
|
|
159
|
+
header?: Record<string, unknown>;
|
|
160
|
+
path?: Record<string, unknown>;
|
|
161
|
+
cookie?: Record<string, unknown>;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
interface MiddlewareCallbackParams {
|
|
165
|
+
/** Current Request object */
|
|
166
|
+
request: Request;
|
|
167
|
+
/** The original OpenAPI schema path (including curly braces) */
|
|
168
|
+
readonly schemaPath: string;
|
|
169
|
+
/** OpenAPI parameters as provided from openapi-typesafe-fetch */
|
|
170
|
+
readonly params: MiddlewareRequestParams;
|
|
171
|
+
/** Unique ID for this request */
|
|
172
|
+
readonly id: string;
|
|
173
|
+
/** createClient options (read-only) */
|
|
174
|
+
readonly options: MergedOptions;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
type MiddlewareOnRequest = (
|
|
178
|
+
options: MiddlewareCallbackParams,
|
|
179
|
+
) => void | Request | Response | undefined | Promise<Request | Response | undefined | void>;
|
|
180
|
+
type MiddlewareOnResponse = (
|
|
181
|
+
options: MiddlewareCallbackParams & { response: Response },
|
|
182
|
+
) => void | Response | undefined | Promise<Response | undefined | void>;
|
|
183
|
+
type MiddlewareOnError = (
|
|
184
|
+
options: MiddlewareCallbackParams & { error: unknown },
|
|
185
|
+
) => void | Response | Error | Promise<void | Response | Error>;
|
|
186
|
+
|
|
187
|
+
type Middleware =
|
|
188
|
+
| {
|
|
189
|
+
onRequest: MiddlewareOnRequest;
|
|
190
|
+
onResponse?: MiddlewareOnResponse;
|
|
191
|
+
onError?: MiddlewareOnError;
|
|
192
|
+
}
|
|
193
|
+
| {
|
|
194
|
+
onRequest?: MiddlewareOnRequest;
|
|
195
|
+
onResponse: MiddlewareOnResponse;
|
|
196
|
+
onError?: MiddlewareOnError;
|
|
197
|
+
}
|
|
198
|
+
| {
|
|
199
|
+
onRequest?: MiddlewareOnRequest;
|
|
200
|
+
onResponse?: MiddlewareOnResponse;
|
|
201
|
+
onError: MiddlewareOnError;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
/** The init of one operation, `undefined` too when nothing in it is required. */
|
|
205
|
+
type OperationInit<Operation> =
|
|
206
|
+
RequiredKeysOf<FetchOptions<Operation>> extends never ? FetchOptions<Operation> | undefined : FetchOptions<Operation>;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* This type helper makes the 2nd function param required if params/requestBody are required;
|
|
210
|
+
* otherwise, optional. `Location` is any key: with `Paths extends {}` a method is not known to be a
|
|
211
|
+
* key of `Paths[Path]` (upstream #2267). For a union of operations, the union of their inits: one
|
|
212
|
+
* deep type of every init gave TS2589 on hundreds of paths (upstream #1882).
|
|
213
|
+
*/
|
|
214
|
+
type MaybeOptionalInit<Params, Location extends PropertyKey> = OperationInits<FilterKeys<Params, Location>>;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Each operation's init. A distributive alias, not `extends infer Operation`: while the path is
|
|
218
|
+
* not known, TypeScript reads an `infer` type as `unknown`, so the init lost its type as the
|
|
219
|
+
* contextual type of an argument and a literal such as `"available"` widened to `string`
|
|
220
|
+
* (swr-openapi's `Exact<Init>` checks).
|
|
221
|
+
*/
|
|
222
|
+
type OperationInits<Operation> = Operation extends unknown ? OperationInit<Operation> : never;
|
|
223
|
+
|
|
224
|
+
/** For each init of a union, whether it may be left out: nothing in it is required. */
|
|
225
|
+
type InitOptionality<Init> = Init extends unknown ? (RequiredKeysOf<Init> extends never ? true : false) : never;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* `true` when the init may be left out: nothing in it is required. For a union of inits (a union
|
|
229
|
+
* of paths, or `Parameters<typeof client.request>`), only when each of them may be left out: a
|
|
230
|
+
* call to one of the paths sends the init it gets, and a path parameter left out stays `{id}` in
|
|
231
|
+
* the URL.
|
|
232
|
+
*/
|
|
233
|
+
type IsInitOptional<Init> = InitOptionality<Init> extends true ? true : false;
|
|
234
|
+
|
|
235
|
+
// The final init param to accept.
|
|
236
|
+
// - Determines if the param is optional or not.
|
|
237
|
+
// - Performs arbitrary [key: string] addition.
|
|
238
|
+
// Note: the addition MUST happen after all the inference happens (otherwise TS can’t infer if init is required or not).
|
|
239
|
+
// - Reads `InitOptionality` and names the addition: through `IsInitOptional`, or with the addition
|
|
240
|
+
// written out in both branches, TypeScript gave `never` for `Parameters` of the methods.
|
|
241
|
+
type InitParam<Init> = InitOptionality<Init> extends true ? [WithAnyKeys<Init>?] : [WithAnyKeys<Init>];
|
|
242
|
+
|
|
243
|
+
/** The init with any other key (`[key: string]: unknown`), added after inference. */
|
|
244
|
+
type WithAnyKeys<Init> = Init & { [key: string]: unknown };
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* The operation of `Method` on `Path`. Not `Paths[Path][Method]`: `Paths` is only `{}`, because
|
|
248
|
+
* the generated `interface paths` has no index signature and failed a `Record<string, …>`
|
|
249
|
+
* constraint with TS2344 (upstream #2267), so TypeScript does not know `Method` is a key. For a
|
|
250
|
+
* union of paths or methods, the union of their operations; a method a path lacks (`put?: never`)
|
|
251
|
+
* adds none.
|
|
252
|
+
*/
|
|
253
|
+
type PathOperation<Paths, Path, Method> = Extract<
|
|
254
|
+
FilterKeys<Paths[Path & keyof Paths], Method>,
|
|
255
|
+
Record<string | number, any>
|
|
256
|
+
>;
|
|
257
|
+
|
|
258
|
+
type ClientMethod<Paths extends {}, Method extends HttpMethod, Media extends MediaType> = <
|
|
259
|
+
Path extends PathsWithMethod<Paths, Method>,
|
|
260
|
+
Init extends MaybeOptionalInit<Paths[Path], Method>,
|
|
261
|
+
>(
|
|
262
|
+
url: Path,
|
|
263
|
+
...init: InitParam<Init>
|
|
264
|
+
) => Promise<FetchResponse<PathOperation<Paths, Path, Method>, Init, Media>>;
|
|
265
|
+
|
|
266
|
+
type ClientRequestMethod<Paths extends {}, Media extends MediaType> = <
|
|
267
|
+
Method extends HttpMethod,
|
|
268
|
+
Path extends PathsWithMethod<Paths, Method>,
|
|
269
|
+
Init extends MaybeOptionalInit<Paths[Path], Method>,
|
|
270
|
+
>(
|
|
271
|
+
method: Method,
|
|
272
|
+
url: Path,
|
|
273
|
+
...init: InitParam<Init>
|
|
274
|
+
) => Promise<FetchResponse<PathOperation<Paths, Path, Method>, Init, Media>>;
|
|
275
|
+
|
|
276
|
+
// Only HTTP method keys become calls: `parameters` and `additionalOperations` are not methods.
|
|
277
|
+
type ClientForPath<PathInfo extends Record<string | number, any>, Media extends MediaType> = {
|
|
278
|
+
[Method in keyof PathInfo as Method extends HttpMethod ? Uppercase<Method> : never]: <
|
|
279
|
+
Init extends MaybeOptionalInit<PathInfo, Method>,
|
|
280
|
+
>(
|
|
281
|
+
...init: InitParam<Init>
|
|
282
|
+
) => Promise<FetchResponse<PathInfo[Method], Init, Media>>;
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
interface Client<Paths extends {}, Media extends MediaType = MediaType> {
|
|
286
|
+
request: ClientRequestMethod<Paths, Media>;
|
|
287
|
+
/** Call a GET endpoint */
|
|
288
|
+
GET: ClientMethod<Paths, "get", Media>;
|
|
289
|
+
/** Call a PUT endpoint */
|
|
290
|
+
PUT: ClientMethod<Paths, "put", Media>;
|
|
291
|
+
/** Call a POST endpoint */
|
|
292
|
+
POST: ClientMethod<Paths, "post", Media>;
|
|
293
|
+
/** Call a DELETE endpoint */
|
|
294
|
+
DELETE: ClientMethod<Paths, "delete", Media>;
|
|
295
|
+
/** Call a OPTIONS endpoint */
|
|
296
|
+
OPTIONS: ClientMethod<Paths, "options", Media>;
|
|
297
|
+
/** Call a HEAD endpoint */
|
|
298
|
+
HEAD: ClientMethod<Paths, "head", Media>;
|
|
299
|
+
/** Call a PATCH endpoint */
|
|
300
|
+
PATCH: ClientMethod<Paths, "patch", Media>;
|
|
301
|
+
/** Call a TRACE endpoint */
|
|
302
|
+
TRACE: ClientMethod<Paths, "trace", Media>;
|
|
303
|
+
/** Call a QUERY endpoint (OpenAPI 3.2) */
|
|
304
|
+
QUERY: ClientMethod<Paths, "query", Media>;
|
|
305
|
+
/** Register middleware */
|
|
306
|
+
use(...middleware: Middleware[]): void;
|
|
307
|
+
/** Unregister middleware */
|
|
308
|
+
eject(...middleware: Middleware[]): void;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
type ClientPathsWithMethod<CreatedClient extends Client<any, any>, Method extends HttpMethod> =
|
|
312
|
+
CreatedClient extends Client<infer Paths, infer _Media> ? PathsWithMethod<Paths, Method> : never;
|
|
313
|
+
|
|
314
|
+
type MethodResponse<
|
|
315
|
+
CreatedClient extends Client<any, any>,
|
|
316
|
+
Method extends HttpMethod,
|
|
317
|
+
Path extends ClientPathsWithMethod<CreatedClient, Method>,
|
|
318
|
+
Options = {},
|
|
319
|
+
> =
|
|
320
|
+
CreatedClient extends Client<infer Paths extends { [key: string]: any }, infer Media extends MediaType>
|
|
321
|
+
? NonNullable<FetchResponse<Paths[Path][Method], Options, Media>["data"]>
|
|
322
|
+
: never;
|
|
323
|
+
|
|
324
|
+
declare function createClient<Paths extends {}, Media extends MediaType = MediaType>(
|
|
325
|
+
clientOptions?: ClientOptions,
|
|
326
|
+
): Client<Paths, Media>;
|
|
327
|
+
declare function createClient<Paths extends {}, Media extends MediaType = MediaType>(
|
|
328
|
+
clientOptions?: OtherFetchClientOptions,
|
|
329
|
+
): Client<Paths, Media>;
|
|
330
|
+
|
|
331
|
+
type PathBasedClient<Paths extends Record<string | number, any>, Media extends MediaType = MediaType> = {
|
|
332
|
+
[Path in keyof Paths]: ClientForPath<Paths[Path], Media>;
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
declare function wrapAsPathBasedClient<Paths extends {}, Media extends MediaType = MediaType>(
|
|
336
|
+
client: Client<Paths, Media>,
|
|
337
|
+
): PathBasedClient<Paths, Media>;
|
|
338
|
+
|
|
339
|
+
declare function createPathBasedClient<Paths extends {}, Media extends MediaType = MediaType>(
|
|
340
|
+
clientOptions?: ClientOptions,
|
|
341
|
+
): PathBasedClient<Paths, Media>;
|
|
342
|
+
declare function createPathBasedClient<Paths extends {}, Media extends MediaType = MediaType>(
|
|
343
|
+
clientOptions?: OtherFetchClientOptions,
|
|
344
|
+
): PathBasedClient<Paths, Media>;
|
|
345
|
+
|
|
346
|
+
/** Serialize primitive params to string */
|
|
347
|
+
declare function serializePrimitiveParam(
|
|
348
|
+
name: string,
|
|
349
|
+
value: string,
|
|
350
|
+
options?: { allowReserved?: boolean },
|
|
351
|
+
): string;
|
|
352
|
+
|
|
353
|
+
/** Serialize object param to string */
|
|
354
|
+
declare function serializeObjectParam(
|
|
355
|
+
name: string,
|
|
356
|
+
value: Record<string, unknown>,
|
|
357
|
+
options: {
|
|
358
|
+
style: "simple" | "label" | "matrix" | "form" | "deepObject";
|
|
359
|
+
explode: boolean;
|
|
360
|
+
allowReserved?: boolean;
|
|
361
|
+
},
|
|
362
|
+
): string;
|
|
363
|
+
|
|
364
|
+
/** Serialize array param to string */
|
|
365
|
+
declare function serializeArrayParam(
|
|
366
|
+
name: string,
|
|
367
|
+
value: unknown[],
|
|
368
|
+
options: {
|
|
369
|
+
style: "simple" | "label" | "matrix" | "form" | "spaceDelimited" | "pipeDelimited";
|
|
370
|
+
explode: boolean;
|
|
371
|
+
allowReserved?: boolean;
|
|
372
|
+
},
|
|
373
|
+
): string;
|
|
374
|
+
|
|
375
|
+
/** Serialize query params to string */
|
|
376
|
+
declare function createQuerySerializer<T = unknown>(
|
|
377
|
+
options?: QuerySerializerOptions,
|
|
378
|
+
): (queryParams: T) => string;
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Handle different OpenAPI 3.x serialization styles
|
|
382
|
+
* @type {import("./index.js").defaultPathSerializer}
|
|
383
|
+
* @see https://swagger.io/docs/specification/serialization/#path
|
|
384
|
+
*/
|
|
385
|
+
declare function defaultPathSerializer(pathname: string, pathParams: Record<string, unknown>): string;
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Serialize body object to string; with a form content type in `headers`, as URL-encoded form data.
|
|
389
|
+
*/
|
|
390
|
+
declare function defaultBodySerializer<T>(body: T, headers?: HeadersOptions): string;
|
|
391
|
+
|
|
392
|
+
/** Construct URL string from baseUrl and handle path and query params */
|
|
393
|
+
declare function createFinalURL<O>(
|
|
394
|
+
pathname: string,
|
|
395
|
+
options: {
|
|
396
|
+
baseUrl: string;
|
|
397
|
+
params: {
|
|
398
|
+
query?: Record<string, unknown>;
|
|
399
|
+
path?: Record<string, unknown>;
|
|
400
|
+
};
|
|
401
|
+
querySerializer: QuerySerializer<O>;
|
|
402
|
+
pathSerializer: PathSerializer;
|
|
403
|
+
},
|
|
404
|
+
): string;
|
|
405
|
+
|
|
406
|
+
/** Merge headers a and b, with b taking priority */
|
|
407
|
+
declare function mergeHeaders(...allHeaders: (HeadersOptions | undefined)[]): Headers;
|
|
408
|
+
|
|
409
|
+
/** Remove trailing slash from url */
|
|
410
|
+
declare function removeTrailingSlash(url: string): string;
|
|
411
|
+
|
|
412
|
+
export { createFinalURL, createPathBasedClient, createQuerySerializer, createClient as default, defaultBodySerializer, defaultPathSerializer, mergeHeaders, removeTrailingSlash, serializeArrayParam, serializeObjectParam, serializePrimitiveParam, wrapAsPathBasedClient };
|
|
413
|
+
export type { BodySerializer, Client, ClientForPath, ClientMethod, ClientOptions, ClientPathsWithMethod, ClientRequestMethod, DefaultParamsOption, FetchOptions, FetchResponse, HeadersOptions, IsInitOptional, MaybeOptionalInit, MergedOptions, MethodResponse, Middleware, MiddlewareCallbackParams, MiddlewareRequestParams, OtherFetchClientOptions, ParamsOption, ParseAs, ParseAsResponse, PathBasedClient, PathOperation, PathSerializer, QuerySerializer, QuerySerializerOptions, RequestBodyOption, RequestOptions };
|