@kubb/plugin-fetch 5.13.0-canary.20261105T105941 → 5.13.0

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.
@@ -0,0 +1,3 @@
1
+ import { a as Options, c as ResponseError, d as createClient, f as defaultTransport, i as NativeResponse, l as client, n as FetchOptions, o as RequestConfig, r as NativeRequest, s as ResolvedRequest, t as ClientConfig } from "../client-Dn80AjdR.js";
2
+ export * from "@kubb/plugin-client/templates/core.ts";
3
+ export { ClientConfig, FetchOptions, NativeRequest, NativeResponse, Options, RequestConfig, ResolvedRequest, ResponseError, client, createClient, defaultTransport };
@@ -0,0 +1,2 @@
1
+ import "../core-D6FAGTsL.js";
2
+ export * from "@kubb/plugin-client/templates/core.ts";
@@ -1,406 +1,6 @@
1
- import { HeadersInit, RequestBody, Serializers, Styles } from "./serializers.js";
2
- import { ParseError, StandardSchemaValidator } from "./standardSchema.js";
3
- /**
4
- * HTTP status codes treated as a success, everything else is an error.
5
- */
6
- export type SuccessStatusCode = '200' | '201' | '202' | '203' | '204' | '205' | '206' | '207' | '208' | '226';
7
- export type SuccessOf<TResponses> = TResponses[Extract<keyof TResponses, SuccessStatusCode>];
8
- export type ErrorOf<TResponses> = TResponses[Exclude<keyof TResponses, SuccessStatusCode>];
9
- /**
10
- * Converts a response record's string status key to its numeric literal, leaving non-numeric keys like `default` as `number`.
11
- */
12
- export type ToStatusNumber<TStatus> = TStatus extends `${infer TNumber extends number}` ? TNumber : number;
13
- /**
14
- * Unwraps content-type variants to keep the bare body on `error`.
15
- */
16
- export type DataOf<T> = T extends {
17
- contentType: string;
18
- data: infer TData;
19
- } ? TData : T;
20
- /**
21
- * Keeps `contentType` beside `data` so switching on it narrows the body.
22
- */
23
- export type SuccessVariant<TStatus, TEntry, TRequest, TResponse> = TEntry extends {
24
- contentType: string;
25
- data: unknown;
26
- } ? TEntry extends {
27
- contentType: infer TContentType;
28
- data: infer TData;
29
- } ? {
30
- status: ToStatusNumber<TStatus>;
31
- data: TData;
32
- error: undefined;
33
- contentType: TContentType;
34
- request: TRequest;
35
- response: TResponse;
36
- } : never : {
37
- status: ToStatusNumber<TStatus>;
38
- data: TEntry;
39
- error: undefined;
40
- contentType: string | undefined;
41
- request: TRequest;
42
- response: TResponse;
43
- };
44
- /**
45
- * Narrows `data` or `error` when switching on the numeric status.
46
- */
47
- export type ResultByStatus<TResponses, TStatus extends keyof TResponses, TRequest, TResponse> = TStatus extends SuccessStatusCode ? SuccessVariant<TStatus, TResponses[TStatus], TRequest, TResponse> : {
48
- status: ToStatusNumber<TStatus>;
49
- data: undefined;
50
- error: DataOf<TResponses[TStatus]>;
51
- contentType: string | undefined;
52
- request: TRequest;
53
- response: TResponse;
54
- };
55
- export type ResultUnion<TResponses, TRequest, TResponse> = { [TStatus in keyof TResponses]: ResultByStatus<TResponses, TStatus, TRequest, TResponse>; }[keyof TResponses];
56
- /**
57
- * Selects success statuses without letting untyped error payloads widen `data`.
58
- */
59
- export type SuccessResultUnion<TResponses, TRequest, TResponse> = { [TStatus in Extract<keyof TResponses, SuccessStatusCode>]: ResultByStatus<TResponses, TStatus, TRequest, TResponse>; }[Extract<keyof TResponses, SuccessStatusCode>];
60
- /**
61
- * Narrows `data` and `error` by status. With `throwOnError`, includes only success variants.
62
- */
63
- export type RequestResult<TResponses, ThrowOnError extends boolean = true, TRequest = Request, TResponse = Response> = ThrowOnError extends true ? [SuccessResultUnion<TResponses, TRequest, TResponse>] extends [never] ? {
64
- status: number;
65
- data: SuccessOf<TResponses>;
66
- error: undefined;
67
- contentType: string | undefined;
68
- request: TRequest;
69
- response: TResponse;
70
- } : SuccessResultUnion<TResponses, TRequest, TResponse> : [ResultUnion<TResponses, TRequest, TResponse>] extends [never] ? {
71
- status: number;
72
- data: undefined;
73
- error: undefined;
74
- contentType: string | undefined;
75
- request: TRequest;
76
- response: TResponse;
77
- } : ResultUnion<TResponses, TRequest, TResponse>;
78
- /**
79
- * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body.
80
- */
81
- export type Unwrappable<T extends {
82
- data: unknown;
83
- error: unknown;
84
- }> = Promise<T> & {
85
- unwrap: () => Promise<Extract<T, {
86
- error: undefined;
87
- }>['data']>;
88
- };
89
- /**
90
- * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one.
91
- *
92
- * @example
93
- * ```ts
94
- * const { data, error } = await getPetById({ path: { petId: 1 } })
95
- * ```
96
- *
97
- * @example
98
- * ```ts
99
- * const pet = await getPetById({ path: { petId: 1 } }).unwrap()
100
- * ```
101
- */
102
- export declare function withUnwrap<T extends {
103
- data: unknown;
104
- error: unknown;
105
- }>(promise: Promise<T>): Unwrappable<T>;
106
- /**
107
- * The shape a generated operation returns with `returnType: 'data'`: the success body when
108
- * `throwOnError` is true, or the full `RequestResult` when it is false.
109
- */
110
- export type UnwrappedResult<TResponses, ThrowOnError extends boolean = true, TRequest = Request, TResponse = Response> = ThrowOnError extends true ? RequestResult<TResponses, true, TRequest, TResponse>['data'] : RequestResult<TResponses, ThrowOnError, TRequest, TResponse>;
111
- /**
112
- * Returns the success body when `throwOnError` is true, or the full result when it is false.
113
- */
114
- export declare function unwrapResult<T extends {
115
- data: unknown;
116
- error: unknown;
117
- }>(promise: Promise<T>, throwOnError: boolean | undefined): Promise<T | T['data']>;
118
- export type DataShape = {
119
- body?: unknown;
120
- cookies?: unknown;
121
- headers?: unknown;
122
- path?: unknown;
123
- query?: unknown;
124
- };
125
- export type RequestCredentials = 'omit' | 'same-origin' | 'include';
126
- export type ResponseType = 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream';
127
- /**
128
- * Decodes a response body for a codec's media type.
129
- */
130
- export type Deserializer<T = unknown> = (raw: unknown, contentType: string) => T | Promise<T>;
131
- /**
132
- * Encodes a request body for a codec's media type.
133
- */
134
- export type ContentBodySerializer = (body: unknown, contentType?: string) => RequestBody | undefined;
135
- /**
136
- * Encodes requests or decodes responses for a media type. Either direction can be omitted.
137
- */
138
- export type Codec = {
139
- serialize?: ContentBodySerializer;
140
- deserialize?: Deserializer;
141
- };
142
- /**
143
- * A string sets the request content type. The object form can also set `Accept`.
144
- */
145
- export type ContentType = string | {
146
- request?: string;
147
- response?: string;
148
- };
149
- /**
150
- * Validates request bodies and params, success bodies, or non-throwing error bodies with Standard Schema.
151
- */
152
- export type Validator<T = unknown> = StandardSchemaValidator<T>;
153
- /**
154
- * Identifies the value and request that failed validation in `onValidationError`.
155
- */
156
- export type ValidationErrorContext = {
157
- value: unknown;
158
- direction: 'request' | 'response' | 'error';
159
- source: 'body' | 'path' | 'query' | 'headers';
160
- method?: string;
161
- url?: string;
162
- status?: number;
163
- };
164
- /**
165
- * Return `{ value }` to substitute a failed value, including `undefined`. Returning nothing rethrows the `ParseError`.
166
- */
167
- export type ValidationErrorHandler = (error: ParseError, context: ValidationErrorContext) => {
168
- value: unknown;
169
- } | void | Promise<{
170
- value: unknown;
171
- } | void>;
172
- /**
173
- * Turns generated validation on or off. `false` skips every validator, an object skips only the directions set to `false`:
174
- * `request` is the body, `params` are path, query, and header params, `response` and `error` are the response bodies.
175
- * @default true
176
- */
177
- export type ValidateOption = boolean | {
178
- request?: boolean;
179
- params?: boolean;
180
- response?: boolean;
181
- error?: boolean;
182
- };
183
- /**
184
- * A resolved security scheme carried on each generated call's `security` array and passed to the `auth` resolver.
185
- */
186
- export type Auth = {
187
- type: 'http' | 'apiKey' | 'oauth2' | 'openIdConnect';
188
- scheme?: 'bearer' | 'basic';
189
- name?: string;
190
- in?: 'header' | 'query' | 'cookie';
191
- scopes?: Array<string>;
192
- };
193
- /**
194
- * Return `user:password` for basic auth, or `undefined` to skip a scheme.
195
- */
196
- export type AuthToken = string | undefined;
197
- /**
198
- * Resolves the token for a security scheme, either a static token or a callback called per scheme until one returns a token.
199
- */
200
- export type AuthResolver = AuthToken | ((auth: Auth) => AuthToken | Promise<AuthToken>);
201
- /**
202
- * Extra `fetch` init the transport spreads onto every `Request`, an escape hatch for fields the runtime does not set itself such as `cache`, `redirect`, and Next.js's `next`.
203
- */
204
- export type FetchOptions = RequestInit & {
205
- next?: Record<string, unknown>;
206
- };
207
- export type RequestConfig<TBody = unknown, TRequest = Request, TResponse = Response> = {
208
- baseURL?: string;
209
- url?: string;
210
- method?: 'GET' | 'PUT' | 'PATCH' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'QUERY';
211
- path?: unknown;
212
- query?: unknown;
213
- params?: unknown;
214
- cookies?: unknown;
215
- body?: TBody;
216
- headers?: unknown;
217
- styles?: Styles;
218
- signal?: AbortSignal;
219
- credentials?: RequestCredentials;
220
- options?: FetchOptions;
221
- contentType?: ContentType;
222
- responseType?: ResponseType;
223
- throwOnError?: boolean;
224
- client?: ClientInstance<TRequest, TResponse>;
225
- transport?: Transport<TRequest, TResponse>;
226
- serializer?: Serializers;
227
- codecs?: Record<string, Codec>;
228
- validator?: {
229
- request?: Validator;
230
- path?: Validator;
231
- query?: Validator;
232
- headers?: Validator;
233
- response?: Validator;
234
- error?: Validator;
235
- };
236
- onValidationError?: ValidationErrorHandler;
237
- validate?: ValidateOption;
238
- security?: Array<Auth>;
239
- auth?: AuthResolver;
240
- };
241
- /**
242
- * Combines client options with the operation's typed request params and body.
243
- */
244
- export type Options<TData extends DataShape, ThrowOnError extends boolean = true, TRequest = Request, TResponse = Response> = Omit<RequestConfig<unknown, TRequest, TResponse>, keyof DataShape | 'url'> & TData & {
245
- client?: ClientInstance<TRequest, TResponse>;
246
- throwOnError?: ThrowOnError;
247
- };
248
- /**
249
- * Client-level configuration shared by every call an instance makes, overridden by the per-call `RequestConfig`.
250
- */
251
- export type ClientConfig<TRequest = Request, TResponse = Response> = {
252
- baseURL?: string;
253
- headers?: HeadersInit;
254
- credentials?: RequestCredentials;
255
- options?: FetchOptions;
256
- throwOnError?: boolean;
257
- transport?: Transport<TRequest, TResponse>;
258
- serializer?: Serializers;
259
- codecs?: Record<string, Codec>;
260
- onValidationError?: ValidationErrorHandler;
261
- validate?: ValidateOption;
262
- auth?: AuthResolver;
263
- };
264
- /**
265
- * The normalized request the transport receives, with all serialization, auth, and header work already done.
266
- */
267
- export type ResolvedRequest = {
268
- url: string;
269
- method: string;
270
- headers: Record<string, string>;
271
- body?: RequestBody;
272
- signal?: AbortSignal;
273
- credentials?: RequestCredentials;
274
- options?: FetchOptions;
275
- responseType?: ResponseType;
276
- };
277
- /**
278
- * What a transport returns: the parsed body plus the native request and response objects.
279
- */
280
- export type TransportResult<TData = unknown, TRequest = Request, TResponse = Response> = {
281
- data: TData;
282
- status: number;
283
- statusText: string;
284
- headers: Headers;
285
- contentType?: string;
286
- request: TRequest;
287
- response: TResponse;
288
- };
289
- /**
290
- * The per-plugin send, supplied to `createClientCore` as `defaultTransport`.
291
- */
292
- export type Transport<TRequest = Request, TResponse = Response> = (request: ResolvedRequest) => Promise<TransportResult<unknown, TRequest, TResponse>>;
293
- export type CallResult<TRequest = Request, TResponse = Response> = {
294
- status: number;
295
- data: unknown;
296
- error: unknown;
297
- contentType: string | undefined;
298
- request: TRequest;
299
- response: TResponse;
300
- };
301
- export type InterceptorFn<T, TContext = never> = (value: T, context?: TContext) => T | Promise<T>;
302
- /**
303
- * A single interceptor channel with a transport-agnostic `use` / `eject` / `update` API.
304
- */
305
- export type InterceptorStack<T, TContext = never> = {
306
- use: (fn: InterceptorFn<T, TContext>) => number;
307
- eject: (id: number) => void;
308
- update: (id: number, fn: InterceptorFn<T, TContext>) => void;
309
- run: (value: T, context?: TContext) => Promise<T>;
310
- };
311
- export type Interceptors<TRequest = Request, TResponse = Response> = {
312
- request: InterceptorStack<ResolvedRequest, RequestConfig<unknown, TRequest, TResponse>>;
313
- response: InterceptorStack<TransportResult<unknown, TRequest, TResponse>, RequestConfig<unknown, TRequest, TResponse>>;
314
- error: InterceptorStack<ResponseError<unknown, TRequest, TResponse>, RequestConfig<unknown, TRequest, TResponse>>;
315
- };
316
- export type UrlConfig = Pick<RequestConfig, 'baseURL' | 'url' | 'path' | 'query' | 'params' | 'serializer' | 'styles'>;
317
- /**
318
- * A client instance: the callable send plus configuration, interceptors, and an isolated
319
- * `createClient` factory bound to the same transport.
320
- */
321
- export type ClientInstance<TRequest = Request, TResponse = Response> = {
322
- <TBody = unknown>(config: RequestConfig<TBody, TRequest, TResponse>): Promise<CallResult<TRequest, TResponse>>;
323
- getConfig: () => ClientConfig<TRequest, TResponse>;
324
- setConfig: (config: ClientConfig<TRequest, TResponse>) => ClientConfig<TRequest, TResponse>;
325
- getUrl: (config: UrlConfig) => string;
326
- interceptors: Interceptors<TRequest, TResponse>;
327
- createClient: (config?: ClientConfig<TRequest, TResponse>) => ClientInstance<TRequest, TResponse>;
328
- };
329
- /**
330
- * Thrown for a non-2xx response, so a resolved call always means success.
331
- */
332
- export declare class ResponseError<TError = unknown, TRequest = Request, TResponse = Response> extends Error {
333
- data: TError;
334
- status: number;
335
- statusText: string;
336
- contentType: string | undefined;
337
- request: TRequest;
338
- response: TResponse;
339
- constructor(config: {
340
- data: TError;
341
- status: number;
342
- statusText: string;
343
- contentType?: string;
344
- request: TRequest;
345
- response: TResponse;
346
- method?: string;
347
- url?: string;
348
- });
349
- /**
350
- * Matches on `name`, not `instanceof`: every generated client bundles its own `ResponseError` class.
351
- */
352
- static is(error: unknown): error is ResponseError<unknown, unknown, unknown>;
1
+ import { a as Options, c as ResponseError, d as createClient, f as defaultTransport, i as NativeResponse, l as client, n as FetchOptions, o as RequestConfig, r as NativeRequest, s as ResolvedRequest, t as ClientConfig, u as client_d_exports } from "../client-Dn80AjdR.js";
2
+ export * from "@kubb/plugin-client/templates/core.ts";
3
+ declare namespace fetch_d_exports {
4
+ export { ClientConfig, FetchOptions, NativeRequest, NativeResponse, Options, RequestConfig, ResolvedRequest, ResponseError, client, createClient, defaultTransport };
353
5
  }
354
- export type ResponseErrorConfig<TError = unknown> = ResponseError<TError>;
355
- /**
356
- * Creates a transport-agnostic interceptor channel that runs interceptors in registration order.
357
- */
358
- export declare function createInterceptorStack<T, TContext = never>(): InterceptorStack<T, TContext>;
359
- /**
360
- * Walks the per-operation security in order and places the first resolved token on the request, mutating `headers` / `query` in place.
361
- */
362
- export declare function resolveAuth(params: {
363
- security: Array<Auth> | undefined;
364
- auth: AuthResolver | undefined;
365
- headers: Record<string, string>;
366
- query: Record<string, unknown>;
367
- }): Promise<void>;
368
- /**
369
- * Creates an isolated client using the supplied default transport.
370
- */
371
- export declare function createClientCore<TRequest = Request, TResponse = Response>(options: {
372
- defaultTransport: Transport<TRequest, TResponse>;
373
- } & ClientConfig<TRequest, TResponse>): ClientInstance<TRequest, TResponse>;
374
- /**
375
- * The default transport that sends the resolved request through `globalThis.fetch` and returns the parsed body with the native request and response.
376
- */
377
- export declare const defaultTransport: Transport;
378
- /**
379
- * One decoded Server-Sent Event, with `data` parsed as JSON when valid and kept as the raw string otherwise.
380
- */
381
- export type ServerSentEvent<TData = unknown> = {
382
- data: TData;
383
- event?: string;
384
- id?: string;
385
- retry?: number;
386
- };
387
- /**
388
- * Parses a `text/event-stream` body into typed Server-Sent Events, consumed with `for await` and stopped early by breaking the loop.
389
- */
390
- export declare function parseEventStream<TData = unknown>(stream: ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>): AsyncGenerator<ServerSentEvent<TData>>;
391
- /**
392
- * Returns parsed events alongside the native response.
393
- */
394
- export type EventStreamResult<TData = unknown, TResponse = Response> = {
395
- stream: AsyncGenerator<ServerSentEvent<TData>>;
396
- response: TResponse;
397
- };
398
- /**
399
- * Exposes a streaming response body as typed Server-Sent Events.
400
- */
401
- export declare function toEventStream<TData = unknown>(result: Promise<{
402
- data: unknown;
403
- response: Response;
404
- }>): Promise<EventStreamResult<TData>>;
405
- export declare const client: ClientInstance<Request, Response>;
406
- export declare const createClient: (config?: Parameters<typeof client.createClient>[0]) => ClientInstance<Request, Response>;
6
+ export { ClientConfig, FetchOptions, NativeRequest, NativeResponse, Options, RequestConfig, ResolvedRequest, ResponseError, client, createClient, defaultTransport };
@@ -1,179 +1 @@
1
- export type HeaderValue = string | number | boolean | null | undefined | object;
2
- export type HeadersInit = Array<[string, HeaderValue]> | Record<string, HeaderValue>;
3
- /**
4
- * The request body type `fetch` accepts, derived from `RequestInit` instead of the global `BodyInit`
5
- * name, which a Node-only project (`@types/node` without the `dom` lib) does not declare.
6
- */
7
- export type RequestBody = NonNullable<RequestInit['body']>;
8
- /**
9
- * The OpenAPI query-parameter serialization style. `form` is the default; `spaceDelimited` and
10
- * `pipeDelimited` join arrays with a space or pipe, and `deepObject` renders objects as
11
- * `key[prop]=value`.
12
- */
13
- export type QueryStyle = 'form' | 'spaceDelimited' | 'pipeDelimited' | 'deepObject';
14
- /**
15
- * The serialization metadata shared by the styled parameter locations: the OpenAPI `style` (typed per
16
- * location through `TStyle`), `explode`, and `allowReserved` (keeps RFC 3986 reserved characters
17
- * unencoded, used by query and request bodies).
18
- */
19
- export type SerializationStyle<TStyle = string> = {
20
- style?: TStyle;
21
- explode?: boolean;
22
- allowReserved?: boolean;
23
- };
24
- /** The media type of a parameter described with `content`; JSON sends one JSON-encoded value. */
25
- export type ParamContentType = {
26
- contentType?: string;
27
- };
28
- /**
29
- * The per-parameter query serialization metadata carried by the generated request.
30
- */
31
- export type QueryParamStyle = SerializationStyle<QueryStyle> & ParamContentType;
32
- /**
33
- * Serializes the query object into a search string. The optional second argument carries the
34
- * per-parameter OpenAPI `style` / `explode` / `allowReserved` metadata; without it arrays explode
35
- * into repeated keys and nested objects use the `deepObject` style.
36
- */
37
- export type QuerySerializer = (params: Record<string, unknown>, options?: Record<string, QueryParamStyle>) => string;
38
- /**
39
- * The per-parameter cookie serialization metadata carried by the generated request. Cookies use the
40
- * OpenAPI `form` style, so only `explode` is configurable.
41
- */
42
- export type CookieParamStyle = ParamContentType & {
43
- explode?: boolean;
44
- };
45
- /**
46
- * The per-parameter header serialization metadata carried by the generated request. Headers use the
47
- * OpenAPI `simple` style, so only `explode` is configurable.
48
- *
49
- * @example
50
- * ```ts
51
- * // styles.header: { 'X-Ids': { explode: false } }, header [3, 4] -> 'X-Ids: 3,4'
52
- * // styles.header: { 'X-Filter': { explode: true } }, header { role: 'admin' } -> 'X-Filter: role=admin'
53
- * ```
54
- */
55
- export type HeaderParamStyle = ParamContentType & {
56
- explode?: boolean;
57
- };
58
- /**
59
- * The per-property `encoding` metadata for an `application/x-www-form-urlencoded` or
60
- * `multipart/form-data` request body. `contentType` overrides the part's media type; `style` /
61
- * `explode` / `allowReserved` follow the OpenAPI query rules for urlencoded bodies.
62
- */
63
- export type BodyEncoding = SerializationStyle<QueryStyle> & {
64
- contentType?: string;
65
- };
66
- /**
67
- * Serializes the request body. JSON by default; `FormData`, `URLSearchParams`, `Blob`,
68
- * `ArrayBuffer`, and string bodies pass through untouched. The optional `encoding` argument carries
69
- * the per-property OpenAPI `encoding` metadata for form bodies.
70
- */
71
- export type BodySerializer = (args: {
72
- body: unknown;
73
- contentType?: string;
74
- encoding?: Record<string, BodyEncoding>;
75
- }) => RequestBody | undefined;
76
- /**
77
- * The OpenAPI path-parameter serialization style. `simple` is the default and emits the bare value;
78
- * `label` prefixes a `.` and `matrix` prefixes a `;name=` segment.
79
- */
80
- export type PathStyle = 'simple' | 'label' | 'matrix';
81
- /**
82
- * The per-parameter serialization metadata carried by the generated request. `style` selects the
83
- * OpenAPI style and `explode` controls how arrays and objects expand.
84
- */
85
- export type PathParamStyle = SerializationStyle<PathStyle>;
86
- /**
87
- * Serializes a single path parameter for interpolation into the URL, honoring the OpenAPI `style` /
88
- * `explode` passed as `options`. Defaults to `simple` style with `explode: false`: primitives are
89
- * URL-encoded, arrays join their members with commas, and objects flatten to `key,value` pairs.
90
- */
91
- export type PathSerializer = (args: {
92
- name: string;
93
- value: unknown;
94
- options?: PathParamStyle;
95
- }) => string;
96
- /**
97
- * The per-concern serializers, grouped so they can be set in one place and overridden per client or
98
- * per call. Each field falls back to the matching `default*Serializer` when omitted.
99
- */
100
- export type Serializers = {
101
- query?: QuerySerializer;
102
- body?: BodySerializer;
103
- path?: PathSerializer;
104
- };
105
- /**
106
- * The per-parameter OpenAPI `style` / `explode` metadata a generated request carries, grouped by
107
- * location and keyed by parameter name. Mirrors the `serializer` grouping and feeds the default
108
- * serializers; `body` carries the form `encoding` for a urlencoded or multipart body.
109
- */
110
- export type Styles = {
111
- path?: Record<string, PathParamStyle>;
112
- query?: Record<string, QueryParamStyle>;
113
- header?: Record<string, HeaderParamStyle>;
114
- cookie?: Record<string, CookieParamStyle>;
115
- body?: Record<string, BodyEncoding>;
116
- };
117
- export declare function isDefaultJsonBody(body: unknown): boolean;
118
- /**
119
- * Default body serializer: passes binary/form bodies through and JSON-serializes everything else.
120
- * For `multipart/form-data` plain objects become `FormData` and for
121
- * `application/x-www-form-urlencoded` they become `URLSearchParams`. When `encoding` is supplied each
122
- * urlencoded property follows its OpenAPI `style` / `explode` / `allowReserved`.
123
- *
124
- * @example
125
- * ```ts
126
- * defaultBodySerializer({ body: { name: 'odie' } }) // '{"name":"odie"}'
127
- * defaultBodySerializer({ body: { field: 'x' }, contentType: 'multipart/form-data' }) // FormData
128
- * defaultBodySerializer({ body: { tags: ['a', 'b'] }, contentType: 'application/x-www-form-urlencoded', encoding: { tags: { explode: false } } }) // 'tags=a,b'
129
- * defaultBodySerializer({ body: { meta: { a: 1 } }, contentType: 'multipart/form-data', encoding: { meta: { contentType: 'application/json' } } }) // FormData with a typed Blob part
130
- * ```
131
- */
132
- export declare const defaultBodySerializer: BodySerializer;
133
- /**
134
- * Serializes cookie parameters into a `Cookie` header value using the OpenAPI `form` style, joined
135
- * with `; `. Values are URL-encoded and `explode` is honored per parameter.
136
- *
137
- * @example
138
- * ```ts
139
- * serializeCookies({ session: 'abc', ids: [1, 2] }) // 'session=abc; ids=1,2'
140
- * serializeCookies({ ids: [1, 2] }, { ids: { explode: true } }) // 'ids=1; ids=2'
141
- * ```
142
- */
143
- export declare function serializeCookies(cookies: Record<string, unknown>, styles?: Record<string, CookieParamStyle>): string;
144
- /**
145
- * Default query serializer. Members with `options` metadata follow their OpenAPI `style` / `explode`
146
- * / `allowReserved`. Members without it keep the defaults: arrays explode into repeated keys and
147
- * nested objects use the `deepObject` style (`key[prop]=value`).
148
- *
149
- * @example
150
- * ```ts
151
- * defaultQuerySerializer({ id: [3, 4, 5] }) // 'id=3&id=4&id=5'
152
- * defaultQuerySerializer({ id: [3, 4, 5] }, { id: { style: 'form', explode: false } }) // 'id=3,4,5'
153
- * defaultQuerySerializer({ id: [3, 4, 5] }, { id: { style: 'spaceDelimited', explode: false } }) // 'id=3%204%205'
154
- * defaultQuerySerializer({ id: [3, 4, 5] }, { id: { style: 'pipeDelimited', explode: false } }) // 'id=3|4|5'
155
- * defaultQuerySerializer({ a: { b: 1 } }, { a: { style: 'deepObject' } }) // 'a%5Bb%5D=1'
156
- * defaultQuerySerializer({ a: { b: { c: 1 } } }, { a: { style: 'deepObject' } }) // 'a%5Bb%5D%5Bc%5D=1'
157
- * ```
158
- */
159
- export declare const defaultQuerySerializer: QuerySerializer;
160
- /**
161
- * Default path serializer honoring the OpenAPI `style` / `explode` metadata. Without metadata it
162
- * falls back to `simple` style with `explode: false`. Replaces the previous `String(value)`
163
- * interpolation, which emitted `[object Object]` for object path params.
164
- *
165
- * @example
166
- * ```ts
167
- * defaultPathSerializer({ name: 'id', value: [3, 4, 5] }) // '3,4,5'
168
- * defaultPathSerializer({ name: 'id', value: [3, 4, 5], options: { style: 'label', explode: true } }) // '.3.4.5'
169
- * defaultPathSerializer({ name: 'id', value: [3, 4, 5], options: { style: 'matrix', explode: true } }) // ';id=3;id=4;id=5'
170
- * defaultPathSerializer({ name: 'pt', value: { x: 1, y: 2 } }) // 'x,1,y,2'
171
- * ```
172
- */
173
- export declare const defaultPathSerializer: PathSerializer;
174
- /**
175
- * Serializes array and object header parameters with the OpenAPI `simple` style before they are
176
- * merged. Header values are not URL-encoded. Primitive values and headers without metadata pass
177
- * through untouched.
178
- */
179
- export declare function applyHeaderStyles(headers: HeadersInit | undefined, styles: Record<string, HeaderParamStyle> | undefined): HeadersInit | undefined;
1
+ export * from "@kubb/plugin-client/templates/serializers.ts";
@@ -1,63 +1 @@
1
- /**
2
- * A Standard Schema-compatible validator: a minimal duck-type covering Zod v3/v4, valibot, and
3
- * arktype schemas. Only the `~standard.validate` method is required at runtime.
4
- */
5
- export type StandardSchemaValidator<TOutput = unknown> = {
6
- readonly '~standard': {
7
- validate(value: unknown): StandardSchemaResult<TOutput> | Promise<StandardSchemaResult<TOutput>>;
8
- };
9
- };
10
- /**
11
- * The two possible outcomes of a Standard Schema `validate` call. A successful result carries
12
- * `value`; a failed result carries `issues`.
13
- */
14
- export type StandardSchemaResult<TOutput> = {
15
- readonly value: TOutput;
16
- readonly issues?: undefined;
17
- } | {
18
- readonly issues: ReadonlyArray<StandardSchemaIssue>;
19
- };
20
- /**
21
- * One validation issue from a Standard Schema `validate` call.
22
- */
23
- export type StandardSchemaIssue = {
24
- readonly message?: string;
25
- readonly path?: ReadonlyArray<PropertyKey | {
26
- readonly key: PropertyKey;
27
- }>;
28
- };
29
- /**
30
- * Thrown by `validateStandardSchema` when validation fails. Carries the raw `issues` array from
31
- * the schema's `validate` result so callers receive a uniform error shape regardless of which
32
- * schema library is in use.
33
- */
34
- export declare class ParseError extends Error {
35
- readonly issues: ReadonlyArray<StandardSchemaIssue>;
36
- constructor({ issues, message }: {
37
- issues: ReadonlyArray<StandardSchemaIssue>;
38
- message?: string;
39
- });
40
- }
41
- /**
42
- * Validates `value` against a Standard Schema-compatible `schema`. Returns the parsed output on
43
- * success; throws `ParseError` with the schema's `issues` on failure. Handles both sync and async
44
- * `validate` implementations transparently.
45
- *
46
- * @example
47
- * const pet = await validateStandardSchema(PetSchema, rawData)
48
- */
49
- export declare function validateStandardSchema<TOutput>(schema: StandardSchemaValidator<TOutput>, value: unknown): Promise<TOutput>;
50
- /**
51
- * Wraps an object schema so its keys match case-insensitively.
52
- * Keys the schema does not declare pass through untouched.
53
- * The declared keys are validated with `schema` under their declared names.
54
- * Every key, and every issue path, keeps the casing the caller used.
55
- *
56
- * @param schema Standard Schema-compatible object schema.
57
- * @param entries The record of keys the passed object schema validates.
58
- * @example
59
- * ```ts
60
- * validator: { headers: toHeadersStandardSchema(putEventHeadersSchema, putEventHeadersSchema.shape) }
61
- * ```
62
- */
63
- export declare function toHeadersStandardSchema(schema: StandardSchemaValidator, entries: Record<string, unknown>): StandardSchemaValidator;
1
+ export * from "@kubb/plugin-client/templates/standardSchema.ts";