@kubb/plugin-axios 5.9.0 → 5.9.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.
@@ -6,27 +6,21 @@ import { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalA
6
6
  * HTTP status codes treated as a success, everything else is an error.
7
7
  */
8
8
  export type SuccessStatusCode = '200' | '201' | '202' | '203' | '204' | '205' | '206' | '207' | '208' | '226';
9
- /**
10
- * The success members of a per-status responses record.
11
- */
12
9
  export type SuccessOf<TResponses> = TResponses[Extract<keyof TResponses, SuccessStatusCode>];
13
- /**
14
- * The error members of a per-status responses record, every documented status that is not a 2xx.
15
- */
16
10
  export type ErrorOf<TResponses> = TResponses[Exclude<keyof TResponses, SuccessStatusCode>];
17
11
  /**
18
12
  * Converts a response record's string status key to its numeric literal, leaving non-numeric keys like `default` as `number`.
19
13
  */
20
14
  export type ToStatusNumber<TStatus> = TStatus extends `${infer TNumber extends number}` ? TNumber : number;
21
15
  /**
22
- * The plain body of a per-status response, unwrapping the `{ contentType; data }` union so an error result keeps the bare body union on `error`.
16
+ * Unwraps content-type variants to keep the bare body on `error`.
23
17
  */
24
18
  export type DataOf<T> = T extends {
25
19
  contentType: string;
26
20
  data: infer TData;
27
21
  } ? TData : T;
28
22
  /**
29
- * The success variant for a single status, flattened so the negotiated `contentType` sits next to `data` and `switch (result.contentType)` narrows it.
23
+ * Keeps `contentType` beside `data` so switching on it narrows the body.
30
24
  */
31
25
  export type SuccessVariant<TStatus, TEntry, TRequest, TResponse> = TEntry extends {
32
26
  contentType: string;
@@ -50,7 +44,7 @@ export type SuccessVariant<TStatus, TEntry, TRequest, TResponse> = TEntry extend
50
44
  response: TResponse;
51
45
  };
52
46
  /**
53
- * One result variant for a single documented status, keyed by the numeric `status` so a `switch (result.status)` narrows `data` or `error`.
47
+ * Narrows `data` or `error` when switching on the numeric status.
54
48
  */
55
49
  export type ResultByStatus<TResponses, TStatus extends keyof TResponses, TRequest, TResponse> = TStatus extends SuccessStatusCode ? SuccessVariant<TStatus, TResponses[TStatus], TRequest, TResponse> : {
56
50
  status: ToStatusNumber<TStatus>;
@@ -60,16 +54,13 @@ export type ResultByStatus<TResponses, TStatus extends keyof TResponses, TReques
60
54
  request: TRequest;
61
55
  response: TResponse;
62
56
  };
63
- /**
64
- * The union of every documented status' result variant.
65
- */
66
57
  export type ResultUnion<TResponses, TRequest, TResponse> = { [TStatus in keyof TResponses]: ResultByStatus<TResponses, TStatus, TRequest, TResponse>; }[keyof TResponses];
67
58
  /**
68
- * The union of just the success (2xx) status variants, selected by status code so an untyped error payload can never widen `data`.
59
+ * Selects success statuses without letting untyped error payloads widen `data`.
69
60
  */
70
61
  export type SuccessResultUnion<TResponses, TRequest, TResponse> = { [TStatus in Extract<keyof TResponses, SuccessStatusCode>]: ResultByStatus<TResponses, TStatus, TRequest, TResponse>; }[Extract<keyof TResponses, SuccessStatusCode>];
71
62
  /**
72
- * The shape every generated function returns, discriminated by the top-level `status`, narrowing to the 2xx variants under `throwOnError` and to every documented status without it.
63
+ * Narrows `data` and `error` by status. With `throwOnError`, includes only success variants.
73
64
  */
74
65
  export type RequestResult<TResponses, ThrowOnError extends boolean = true, TRequest = AxiosRequestConfig, TResponse = AxiosResponse> = ThrowOnError extends true ? [SuccessResultUnion<TResponses, TRequest, TResponse>] extends [never] ? {
75
66
  status: number;
@@ -100,11 +91,15 @@ export type Unwrappable<T extends {
100
91
  /**
101
92
  * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one.
102
93
  *
103
- * @example Full result
104
- * `const { data, error } = await getPetById({ path: { petId: 1 } })`
94
+ * @example
95
+ * ```ts
96
+ * const { data, error } = await getPetById({ path: { petId: 1 } })
97
+ * ```
105
98
  *
106
- * @example Success body only
107
- * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()`
99
+ * @example
100
+ * ```ts
101
+ * const pet = await getPetById({ path: { petId: 1 } }).unwrap()
102
+ * ```
108
103
  */
109
104
  export declare function withUnwrap<T extends {
110
105
  data: unknown;
@@ -117,15 +112,11 @@ export declare function withUnwrap<T extends {
117
112
  export type UnwrappedResult<TResponses, ThrowOnError extends boolean = true, TRequest = AxiosRequestConfig, TResponse = AxiosResponse> = ThrowOnError extends true ? RequestResult<TResponses, true, TRequest, TResponse>['data'] : RequestResult<TResponses, ThrowOnError, TRequest, TResponse>;
118
113
  /**
119
114
  * Returns the success body when `throwOnError` is true, or the full result when it is false.
120
- * Backs generated operations with `returnType: 'data'`.
121
115
  */
122
116
  export declare function unwrapResult<T extends {
123
117
  data: unknown;
124
118
  error: unknown;
125
119
  }>(promise: Promise<T>, throwOnError: boolean | undefined): Promise<T | T['data']>;
126
- /**
127
- * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation.
128
- */
129
120
  export type DataShape = {
130
121
  body?: unknown;
131
122
  cookies?: unknown;
@@ -135,41 +126,33 @@ export type DataShape = {
135
126
  };
136
127
  export type ResponseType = 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream' | 'formdata';
137
128
  /**
138
- * Turns a raw response body into a parsed value, registered per media type as a codec's `deserialize` to handle formats the runtime does not decode itself.
129
+ * Decodes a response body for a codec's media type.
139
130
  */
140
131
  export type Deserializer<T = unknown> = (raw: unknown, contentType: string) => T | Promise<T>;
141
132
  /**
142
- * 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.
133
+ * Encodes a request body for a codec's media type.
143
134
  */
144
135
  export type ContentBodySerializer = (body: unknown, contentType?: string) => unknown;
145
136
  /**
146
- * A per-content-type codec registered on `codecs`, keyed by content type. `serialize` encodes the
147
- * request body for that media type and `deserialize` decodes the response body. Either half is
148
- * optional, so a codec can handle one direction.
137
+ * Encodes requests or decodes responses for a media type. Either direction can be omitted.
149
138
  */
150
139
  export type Codec = {
151
140
  serialize?: ContentBodySerializer;
152
141
  deserialize?: Deserializer;
153
142
  };
154
143
  /**
155
- * The per-call content type selection, where a bare string sets the request content type and the object form also sets the response format sent as `Accept`.
144
+ * A string sets the request content type. The object form can also set `Accept`.
156
145
  */
157
146
  export type ContentType = string | {
158
147
  request?: string;
159
148
  response?: string;
160
149
  };
161
150
  /**
162
- * A Standard Schema validator (zod, valibot, arktype) that parses a value before it is sent or after
163
- * it is received. `runValidator` runs it through `validateStandardSchema`. Wired through the per-call
164
- * `validator.request` / `validator.response` / `validator.error` hooks (`error` runs on the error body when a
165
- * non-2xx call does not throw), and `validator.path` / `validator.query` / `validator.headers` for the
166
- * request params.
151
+ * Validates request bodies and params, success bodies, or non-throwing error bodies with Standard Schema.
167
152
  */
168
153
  export type Validator<T = unknown> = StandardSchemaValidator<T>;
169
154
  /**
170
- * The failing value and the call it came from, handed to `onValidationError` alongside the `ParseError`.
171
- * `direction` says which side rejected it: the request, the success body, or the error body. `source`
172
- * says which part of it: the body, or one of the request param groups.
155
+ * Identifies the value and request that failed validation in `onValidationError`.
173
156
  */
174
157
  export type ValidationErrorContext = {
175
158
  value: unknown;
@@ -180,9 +163,7 @@ export type ValidationErrorContext = {
180
163
  status?: number;
181
164
  };
182
165
  /**
183
- * Decides what a failed validation does. Returning nothing rethrows the `ParseError`; returning
184
- * `{ value }` resolves the call with that value instead, so a drifted body can be reported and still
185
- * delivered. The box keeps an explicit `{ value: undefined }` substitution distinct from declining.
166
+ * Return `{ value }` to substitute a failed value, including `undefined`. Returning nothing rethrows the `ParseError`.
186
167
  */
187
168
  export type ValidationErrorHandler = (error: ParseError, context: ValidationErrorContext) => {
188
169
  value: unknown;
@@ -200,7 +181,7 @@ export type Auth = {
200
181
  scopes?: Array<string>;
201
182
  };
202
183
  /**
203
- * The raw token a consumer returns for a scheme (or `user:password` for basic), or `undefined` to skip it.
184
+ * Return `user:password` for basic auth, or `undefined` to skip a scheme.
204
185
  */
205
186
  export type AuthToken = string | undefined;
206
187
  /**
@@ -211,9 +192,6 @@ export type AuthResolver = AuthToken | ((auth: Auth) => AuthToken | Promise<Auth
211
192
  * Extra axios config the runtime spreads onto every request, an escape hatch for per-call fields it does not set itself such as `timeout`, `proxy`, and the progress callbacks.
212
193
  */
213
194
  export type AxiosOptions = AxiosRequestConfig;
214
- /**
215
- * The request a generated function hands to the runtime, with `body` / `headers` / `path` / `query` from the grouped options.
216
- */
217
195
  export type RequestConfig<TBody = unknown, TRequest = AxiosRequestConfig, TResponse = AxiosResponse> = {
218
196
  baseURL?: string;
219
197
  url?: string;
@@ -248,8 +226,7 @@ export type RequestConfig<TBody = unknown, TRequest = AxiosRequestConfig, TRespo
248
226
  auth?: AuthResolver;
249
227
  };
250
228
  /**
251
- * The grouped options object passed to every generated function: the request config minus the
252
- * data-shaped keys and the literal `url`, plus the per-operation `<Name>Request`.
229
+ * Combines client options with the operation's typed request params and body.
253
230
  */
254
231
  export type Options<TData extends DataShape, ThrowOnError extends boolean = true, TRequest = AxiosRequestConfig, TResponse = AxiosResponse> = Omit<RequestConfig<unknown, TRequest, TResponse>, keyof DataShape | 'url'> & TData & {
255
232
  client?: ClientInstance<TRequest, TResponse>;
@@ -270,9 +247,6 @@ export type ClientConfig = {
270
247
  onValidationError?: ValidationErrorHandler;
271
248
  auth?: AuthResolver;
272
249
  };
273
- /**
274
- * The result a resolved call produces before it is cast to `RequestResult` by the generated wrapper.
275
- */
276
250
  export type CallResult<TRequest = AxiosRequestConfig, TResponse = AxiosResponse> = {
277
251
  status: number;
278
252
  data: unknown;
@@ -283,7 +257,7 @@ export type CallResult<TRequest = AxiosRequestConfig, TResponse = AxiosResponse>
283
257
  };
284
258
  export type InterceptorFn<T, TRequest = AxiosRequestConfig, TResponse = AxiosResponse> = (value: T, requestConfig?: RequestConfig<unknown, TRequest, TResponse>) => T | Promise<T>;
285
259
  /**
286
- * A single interceptor channel with a transport-agnostic `use` / `eject` / `update` API, backed by axios's native interceptor managers.
260
+ * Registers, removes, or replaces handlers on axios's native interceptor managers.
287
261
  */
288
262
  export type InterceptorChannel<T, TRequest = AxiosRequestConfig, TResponse = AxiosResponse> = {
289
263
  use: (fn: InterceptorFn<T, TRequest, TResponse>) => number;
@@ -291,7 +265,7 @@ export type InterceptorChannel<T, TRequest = AxiosRequestConfig, TResponse = Axi
291
265
  update: (id: number, fn: InterceptorFn<T, TRequest, TResponse>) => void;
292
266
  };
293
267
  /**
294
- * The three interceptor channels every client instance exposes, wrapping axios's native managers with `error` mapped onto the response rejection handler.
268
+ * Maps error interceptors to axios's response rejection handler.
295
269
  */
296
270
  export type Interceptors<TRequest = AxiosRequestConfig, TResponse = AxiosResponse> = {
297
271
  request: InterceptorChannel<InternalAxiosRequestConfig, TRequest, TResponse>;
@@ -347,7 +321,7 @@ export declare function resolveAuth(params: {
347
321
  query: Record<string, unknown>;
348
322
  }): Promise<void>;
349
323
  /**
350
- * Builds the shared client core bound to an axios instance (defaulting to `defaultTransport`, else `axios.create()`), with `throwOnError` riding axios's `validateStatus`.
324
+ * Uses the configured axios instance or creates one. `throwOnError` sets axios's default `validateStatus`.
351
325
  */
352
326
  export declare function createClientCore<TRequest = AxiosRequestConfig, TResponse = AxiosResponse>(options?: {
353
327
  defaultTransport?: AxiosInstance;
@@ -370,16 +344,14 @@ export type ServerSentEvent<TData = unknown> = {
370
344
  */
371
345
  export declare function parseEventStream<TData = unknown>(stream: ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>): AsyncGenerator<ServerSentEvent<TData>>;
372
346
  /**
373
- * The resolved shape returned by a generated `text/event-stream` operation: the typed event
374
- * `stream` plus the native `response`.
347
+ * Returns parsed events alongside the native response.
375
348
  */
376
349
  export type EventStreamResult<TData = unknown, TResponse = AxiosResponse> = {
377
350
  stream: AsyncGenerator<ServerSentEvent<TData>>;
378
351
  response: TResponse;
379
352
  };
380
353
  /**
381
- * Wraps a transport result whose `data` is a streaming body into an `EventStreamResult`, exposing
382
- * the parsed events as a typed async iterator. Generated SSE operations call this.
354
+ * Exposes a streaming response body as typed Server-Sent Events.
383
355
  */
384
356
  export declare function toEventStream<TData = unknown>(result: Promise<{
385
357
  data: unknown;
package/docs/options.md CHANGED
@@ -93,7 +93,7 @@ export default defineConfig({
93
93
 
94
94
  Only the params your OpenAPI spec declares are sent. Path and query keys the spec does not declare are stripped, so a key such as an undocumented filter or a cache-buster never reaches the URL. Declare it in the spec, or leave `params` off. Headers are the exception: client-level `headers` (such as `Authorization` or tracing headers) are merged with the call's headers before validation, so headers the spec does not declare pass through unchanged, and declared header params match in any casing.
95
95
 
96
- Pair `request` and `params` with `pluginZod({ inferred: 'direction' })` when the schemas use codecs, so the request types accept the domain values (such as a `Date`) that the validators encode. See [`inferred`](https://kubb.dev/extensions/kubb-labs/plugin-zod/options#inferred).
96
+ Pair `request` and `params` with `pluginZod({ inferred: 'codec' })` when the schemas use codecs, so the request types accept the domain values (such as a `Date`) that the validators encode. See [`inferred`](https://kubb.dev/extensions/kubb-labs/plugin-zod/options#inferred).
97
97
 
98
98
  ### sdk
99
99
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-axios",
3
- "version": "5.9.0",
3
+ "version": "5.9.2",
4
4
  "description": "Generate a slim, type-safe HTTP client with Kubb based on axios.",
5
5
  "keywords": [
6
6
  "api-client",
@@ -80,19 +80,19 @@
80
80
  "registry": "https://registry.npmjs.org/"
81
81
  },
82
82
  "dependencies": {
83
- "@kubb/plugin-ts": "^5.1.0",
84
- "@kubb/plugin-zod": "^5.7.0"
83
+ "@kubb/plugin-ts": "^5.2.0",
84
+ "@kubb/plugin-zod": "^5.7.2"
85
85
  },
86
86
  "devDependencies": {
87
87
  "@internals/client": "0.0.0",
88
88
  "@internals/shared": "0.0.0",
89
89
  "axios": "^1.20.0",
90
- "kubb": "^5.13.0",
90
+ "kubb": "^5.14.0",
91
91
  "typescript": "^7.0.2"
92
92
  },
93
93
  "peerDependencies": {
94
94
  "axios": "^1.20.0",
95
- "kubb": "^5.13.0"
95
+ "kubb": "^5.14.0"
96
96
  },
97
97
  "peerDependenciesMeta": {
98
98
  "axios": {