@kubb/plugin-axios 5.5.0-canary.20260924T111237 → 5.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-axios",
3
- "version": "5.5.0-canary.20260924T111237",
3
+ "version": "5.5.1",
4
4
  "description": "Generate a slim, type-safe HTTP client with Kubb based on axios.",
5
5
  "keywords": [
6
6
  "api-client",
@@ -65,19 +65,19 @@
65
65
  "registry": "https://registry.npmjs.org/"
66
66
  },
67
67
  "dependencies": {
68
- "@kubb/plugin-ts": "^5.1.0-canary.20260924T111237",
69
- "@kubb/plugin-zod": "^5.3.0-canary.20260924T111237"
68
+ "@kubb/plugin-ts": "^5.0.2",
69
+ "@kubb/plugin-zod": "^5.2.2"
70
70
  },
71
71
  "devDependencies": {
72
- "@internals/client": "0.1.0-canary.20260924T111237",
73
- "@internals/shared": "0.1.0-canary.20260924T111237",
72
+ "@internals/client": "0.0.0",
73
+ "@internals/shared": "0.0.0",
74
74
  "axios": "^1.20.0",
75
- "kubb": "^5.3.13",
75
+ "kubb": "^5.3.15",
76
76
  "typescript": "^6.0.3"
77
77
  },
78
78
  "peerDependencies": {
79
79
  "axios": "^1.20.0",
80
- "kubb": "^5.3.13"
80
+ "kubb": "^5.3.15"
81
81
  },
82
82
  "peerDependenciesMeta": {
83
83
  "axios": {
package/src/plugin.ts CHANGED
@@ -1,8 +1,7 @@
1
- import { readFileSync } from 'node:fs'
2
1
  import path from 'node:path'
3
2
  import { createSdkGenerator, defaultMacros, resolverClient } from '@internals/client'
4
3
  import { createGroupConfig } from '@internals/shared'
5
- import { ast, definePlugin, Resolver } from 'kubb/kit'
4
+ import { definePlugin, Resolver } from 'kubb/kit'
6
5
  import { pluginTsName } from '@kubb/plugin-ts'
7
6
  import { pluginZodName } from '@kubb/plugin-zod'
8
7
  import { clientGenerator } from './generators/clientGenerator.tsx'
@@ -44,6 +43,7 @@ export const pluginAxios = definePlugin<PluginAxios>((options) => {
44
43
  include,
45
44
  override = [],
46
45
  baseURL,
46
+ throwOnErrorDefault = true,
47
47
  validator = false,
48
48
  returnType = 'full',
49
49
  group,
@@ -58,6 +58,7 @@ export const pluginAxios = definePlugin<PluginAxios>((options) => {
58
58
  override,
59
59
  group: createGroupConfig(group),
60
60
  baseURL,
61
+ throwOnErrorDefault,
61
62
  validator,
62
63
  returnType,
63
64
  sdk: sdk ? { mode: sdk.mode ?? 'tag', name: sdk.name } : undefined,
@@ -91,45 +92,10 @@ export const pluginAxios = definePlugin<PluginAxios>((options) => {
91
92
  copy: axiosSerializersTemplatePath,
92
93
  })
93
94
 
94
- const clientPath = path.resolve(root, '.kubb/client.ts')
95
- const clientSource = readFileSync(axiosClientTemplatePath, 'utf8')
96
- const clientBody = clientSource.slice(clientSource.indexOf('\n\n') + 2)
97
- const runtimeRoot = path.dirname(clientPath)
98
-
99
95
  ctx.injectFile({
100
96
  baseName: 'client.ts',
101
- path: clientPath,
102
- imports: [
103
- ast.factory.createImport({ name: 'axios', path: 'axios' }),
104
- ast.factory.createImport({
105
- name: ['AxiosError', 'AxiosInstance', 'AxiosRequestConfig', 'AxiosResponse', 'InternalAxiosRequestConfig'],
106
- path: 'axios',
107
- isTypeOnly: true,
108
- }),
109
- ast.factory.createImport({
110
- name: ['applyHeaderStyles', 'defaultBodySerializer', 'defaultPathSerializer', 'defaultQuerySerializer', 'isDefaultJsonBody', 'serializeCookies'],
111
- path: path.resolve(root, '.kubb/serializers.ts'),
112
- root: runtimeRoot,
113
- }),
114
- ast.factory.createImport({
115
- name: ['HeadersInit', 'PathParamStyle', 'PathSerializer', 'Serializers', 'Styles'],
116
- path: path.resolve(root, '.kubb/serializers.ts'),
117
- root: runtimeRoot,
118
- isTypeOnly: true,
119
- }),
120
- ast.factory.createImport({
121
- name: ['ParseError', 'validateStandardSchema'],
122
- path: path.resolve(root, '.kubb/standardSchema.ts'),
123
- root: runtimeRoot,
124
- }),
125
- ast.factory.createImport({
126
- name: ['StandardSchemaValidator'],
127
- path: path.resolve(root, '.kubb/standardSchema.ts'),
128
- root: runtimeRoot,
129
- isTypeOnly: true,
130
- }),
131
- ],
132
- sources: [ast.factory.createSource({ nodes: [ast.factory.createText(clientBody)] })],
97
+ path: path.resolve(root, '.kubb/client.ts'),
98
+ copy: axiosClientTemplatePath,
133
99
  footer: baseURLExpression ? `client.setConfig({ baseURL: ${baseURLExpression} })` : undefined,
134
100
  })
135
101
 
@@ -111,10 +111,8 @@ export function withUnwrap<T extends { data: unknown; error: unknown }>(promise:
111
111
  }
112
112
 
113
113
  /**
114
- * The shape a generated operation returns when `returnType: 'data'` is set: the bare success body
115
- * once `throwOnError` (on by default) narrows away the error branch, falling back to the full
116
- * `RequestResult` when a call sets `throwOnError: false` and still needs `error` to discriminate a
117
- * failed response.
114
+ * The shape a generated operation returns with `returnType: 'data'`: the success body when
115
+ * `throwOnError` is true, or the full `RequestResult` when it is false.
118
116
  */
119
117
  export type UnwrappedResult<
120
118
  TResponses,
@@ -124,11 +122,8 @@ export type UnwrappedResult<
124
122
  > = ThrowOnError extends true ? RequestResult<TResponses, true, TRequest, TResponse>['data'] : RequestResult<TResponses, ThrowOnError, TRequest, TResponse>
125
123
 
126
124
  /**
127
- * Narrows a resolved call down to its success body once `throwOnError` (on by default) rules out
128
- * the error branch, the same default the runtime itself applies. Falls back to the full result for
129
- * a call that sets `throwOnError: false`, since that path still needs `error` to discriminate a
130
- * failed response. Backs `returnType: 'data'`, mirroring how `toEventStream` centralizes the
131
- * post-processing for `text/event-stream` operations.
125
+ * Returns the success body when `throwOnError` is true, or the full result when it is false.
126
+ * Backs generated operations with `returnType: 'data'`.
132
127
  */
133
128
  export function unwrapResult<T extends { data: unknown; error: unknown }>(promise: Promise<T>, throwOnError: boolean | undefined): Promise<T | T['data']> {
134
129
  return promise.then((result) => ((throwOnError ?? true) ? result.data : result))