@kubb/plugin-axios 5.0.0-beta.99 → 5.0.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/dist/index.cjs +333 -359
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +332 -358
- package/dist/index.js.map +1 -1
- package/package.json +18 -10
- package/src/generators/clientGenerator.tsx +4 -101
- package/templates/axios.ts +3 -2
- package/templates/standardSchema.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-axios",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "Generate a slim, type-safe HTTP client with Kubb based on axios.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api-client",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"swagger",
|
|
14
14
|
"typescript"
|
|
15
15
|
],
|
|
16
|
+
"homepage": "https://kubb.dev/plugins/plugin-axios",
|
|
16
17
|
"license": "MIT",
|
|
17
18
|
"author": "stijnvanhulle",
|
|
18
19
|
"repository": {
|
|
@@ -20,6 +21,16 @@
|
|
|
20
21
|
"url": "git+https://github.com/kubb-labs/plugins.git",
|
|
21
22
|
"directory": "packages/plugin-axios"
|
|
22
23
|
},
|
|
24
|
+
"funding": [
|
|
25
|
+
{
|
|
26
|
+
"type": "github",
|
|
27
|
+
"url": "https://github.com/sponsors/stijnvanhulle"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"type": "opencollective",
|
|
31
|
+
"url": "https://opencollective.com/kubb"
|
|
32
|
+
}
|
|
33
|
+
],
|
|
23
34
|
"files": [
|
|
24
35
|
"src",
|
|
25
36
|
"dist",
|
|
@@ -49,19 +60,19 @@
|
|
|
49
60
|
"registry": "https://registry.npmjs.org/"
|
|
50
61
|
},
|
|
51
62
|
"dependencies": {
|
|
52
|
-
"@kubb/plugin-ts": "5.0.0
|
|
53
|
-
"@kubb/plugin-zod": "5.0.0
|
|
63
|
+
"@kubb/plugin-ts": "^5.0.0",
|
|
64
|
+
"@kubb/plugin-zod": "^5.0.0"
|
|
54
65
|
},
|
|
55
66
|
"devDependencies": {
|
|
56
|
-
"axios": "^1.
|
|
57
|
-
"kubb": "5.0.0
|
|
67
|
+
"axios": "^1.19.0",
|
|
68
|
+
"kubb": "^5.0.0",
|
|
58
69
|
"typescript": "^6.0.3",
|
|
59
70
|
"@internals/client": "0.0.0",
|
|
60
71
|
"@internals/shared": "0.0.0"
|
|
61
72
|
},
|
|
62
73
|
"peerDependencies": {
|
|
63
|
-
"axios": "^1.
|
|
64
|
-
"kubb": "5.0.0
|
|
74
|
+
"axios": "^1.19.0",
|
|
75
|
+
"kubb": "^5.0.0"
|
|
65
76
|
},
|
|
66
77
|
"peerDependenciesMeta": {
|
|
67
78
|
"axios": {
|
|
@@ -76,9 +87,6 @@
|
|
|
76
87
|
"clean": "node -e \"require('node:fs').rmSync('./dist', {recursive:true,force:true})\"",
|
|
77
88
|
"lint": "oxlint .",
|
|
78
89
|
"lint:fix": "oxlint --fix .",
|
|
79
|
-
"release": "pnpm publish --no-git-check",
|
|
80
|
-
"release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
|
|
81
|
-
"release:stage": "pnpm stage publish --no-git-check",
|
|
82
90
|
"start": "tsdown --watch",
|
|
83
91
|
"test": "vitest --passWithNoTests",
|
|
84
92
|
"typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
|
|
@@ -1,106 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
buildZodErrorParse,
|
|
4
|
-
getOperationSecurity,
|
|
5
|
-
Operation,
|
|
6
|
-
resolveRequestValidator,
|
|
7
|
-
resolveResponseValidator,
|
|
8
|
-
type SecurityDocument,
|
|
9
|
-
} from '@internals/client'
|
|
10
|
-
import { isEventStream, operationFileEntry } from '@internals/shared'
|
|
11
|
-
import { ast, defineGenerator } from 'kubb/kit'
|
|
12
|
-
import { pluginTsName } from '@kubb/plugin-ts'
|
|
13
|
-
import { pluginZodName } from '@kubb/plugin-zod'
|
|
14
|
-
import { File, jsxRenderer } from 'kubb/jsx'
|
|
1
|
+
import { createClientGenerator } from '@internals/client'
|
|
15
2
|
import type { PluginAxios } from '../types.ts'
|
|
16
3
|
|
|
17
4
|
/**
|
|
18
5
|
* Built-in operation generator for `@kubb/plugin-axios`. Emits one async function per OpenAPI
|
|
19
|
-
* operation using the shared `Operation` component: a grouped `<Name>Request` type and a function
|
|
20
|
-
* forwards a single `options` object to the bundled `client` and returns the `RequestResult`.
|
|
6
|
+
* operation using the shared `Operation` component: a grouped `<Name>Request` type and a function
|
|
7
|
+
* that forwards a single `options` object to the bundled `client` and returns the `RequestResult`.
|
|
21
8
|
*/
|
|
22
|
-
export const clientGenerator =
|
|
23
|
-
name: 'axios',
|
|
24
|
-
renderer: jsxRenderer,
|
|
25
|
-
operation(node, ctx) {
|
|
26
|
-
if (!ast.isHttpOperationNode(node)) return null
|
|
27
|
-
|
|
28
|
-
const { config, driver, resolver, root } = ctx
|
|
29
|
-
const { output, validator, group } = ctx.options
|
|
30
|
-
|
|
31
|
-
const pluginTs = driver.getPlugin(pluginTsName)
|
|
32
|
-
if (!pluginTs) return null
|
|
33
|
-
|
|
34
|
-
const tsResolver = driver.getResolver(pluginTsName)
|
|
35
|
-
|
|
36
|
-
const validatorEnabled = resolveResponseValidator(validator) === 'zod' || resolveRequestValidator(validator) === 'zod'
|
|
37
|
-
const pluginZod = validatorEnabled ? driver.getPlugin(pluginZodName) : null
|
|
38
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null
|
|
39
|
-
|
|
40
|
-
const hasRequestBody = Boolean(node.requestBody?.content?.[0]?.schema)
|
|
41
|
-
const importedTypeNames = [tsResolver.response.options(node), tsResolver.response.responses(node)]
|
|
42
|
-
|
|
43
|
-
const importedZodNames = zodResolver
|
|
44
|
-
? [
|
|
45
|
-
resolveResponseValidator(validator) === 'zod' ? zodResolver.response.response?.(node) : null,
|
|
46
|
-
resolveResponseValidator(validator) === 'zod' ? (buildZodErrorParse(node, zodResolver)?.expression ?? null) : null,
|
|
47
|
-
resolveRequestValidator(validator) === 'zod' && hasRequestBody ? zodResolver.response.body?.(node) : null,
|
|
48
|
-
].filter((name): name is string => Boolean(name))
|
|
49
|
-
: []
|
|
50
|
-
|
|
51
|
-
const meta = {
|
|
52
|
-
name: resolver.name(node.operationId),
|
|
53
|
-
file: resolver.file({ ...operationFileEntry(node, node.operationId), root, output, group: group ?? undefined }),
|
|
54
|
-
fileTs: tsResolver.file({
|
|
55
|
-
...operationFileEntry(node, node.operationId),
|
|
56
|
-
root,
|
|
57
|
-
output: pluginTs.options?.output ?? output,
|
|
58
|
-
group: pluginTs.options?.group ?? undefined,
|
|
59
|
-
}),
|
|
60
|
-
fileZod:
|
|
61
|
-
zodResolver && pluginZod?.options
|
|
62
|
-
? zodResolver.file({
|
|
63
|
-
...operationFileEntry(node, node.operationId),
|
|
64
|
-
root,
|
|
65
|
-
output: pluginZod.options.output ?? output,
|
|
66
|
-
group: pluginZod.options?.group ?? undefined,
|
|
67
|
-
})
|
|
68
|
-
: null,
|
|
69
|
-
} as const
|
|
70
|
-
|
|
71
|
-
const security = getOperationSecurity({
|
|
72
|
-
document: ctx.adapter.document as SecurityDocument | null | undefined,
|
|
73
|
-
method: node.method,
|
|
74
|
-
path: node.path,
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
const clientPath = path.resolve(root, '.kubb/client.ts')
|
|
78
|
-
const eventStream = isEventStream(node)
|
|
79
|
-
|
|
80
|
-
return (
|
|
81
|
-
<File
|
|
82
|
-
baseName={meta.file.baseName}
|
|
83
|
-
path={meta.file.path}
|
|
84
|
-
meta={meta.file.meta}
|
|
85
|
-
banner={resolver.default.banner(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
|
|
86
|
-
footer={resolver.default.footer(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
|
|
87
|
-
>
|
|
88
|
-
<File.Import name={eventStream ? ['client', 'toEventStream'] : ['client']} root={meta.file.path} path={clientPath} />
|
|
89
|
-
<File.Import
|
|
90
|
-
name={eventStream ? ['Options', 'EventStreamResult', 'SuccessOf'] : ['Options', 'RequestResult']}
|
|
91
|
-
root={meta.file.path}
|
|
92
|
-
path={clientPath}
|
|
93
|
-
isTypeOnly
|
|
94
|
-
/>
|
|
95
|
-
|
|
96
|
-
{meta.fileTs && importedTypeNames.length > 0 && (
|
|
97
|
-
<File.Import name={Array.from(new Set(importedTypeNames))} root={meta.file.path} path={meta.fileTs.path} isTypeOnly />
|
|
98
|
-
)}
|
|
99
|
-
|
|
100
|
-
{meta.fileZod && importedZodNames.length > 0 && <File.Import name={importedZodNames} root={meta.file.path} path={meta.fileZod.path} />}
|
|
101
|
-
|
|
102
|
-
<Operation name={meta.name} node={node} tsResolver={tsResolver} zodResolver={zodResolver} validator={validator} security={security} />
|
|
103
|
-
</File>
|
|
104
|
-
)
|
|
105
|
-
},
|
|
106
|
-
})
|
|
9
|
+
export const clientGenerator = createClientGenerator<PluginAxios>('axios')
|
package/templates/axios.ts
CHANGED
|
@@ -2,7 +2,7 @@ import axios from 'axios'
|
|
|
2
2
|
import type { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios'
|
|
3
3
|
import { applyHeaderStyles, defaultBodySerializer, defaultPathSerializer, defaultQuerySerializer, isDefaultJsonBody, serializeCookies } from './serializers'
|
|
4
4
|
import type { HeadersInit, PathParamStyle, PathSerializer, Serializers, Styles } from './serializers'
|
|
5
|
-
import { type StandardSchemaValidator, validateStandardSchema } from './standardSchema
|
|
5
|
+
import { type StandardSchemaValidator, validateStandardSchema } from './standardSchema'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* HTTP status codes treated as a success, everything else is an error.
|
|
@@ -483,7 +483,8 @@ async function resolveRequest<TBody, TRequest, TResponse>({
|
|
|
483
483
|
)
|
|
484
484
|
|
|
485
485
|
const throwOnError = requestConfig.throwOnError ?? config.throwOnError ?? true
|
|
486
|
-
const validateStatus =
|
|
486
|
+
const validateStatus =
|
|
487
|
+
requestConfig.validateStatus ?? config.validateStatus ?? (throwOnError ? (status: number) => status >= 200 && status < 300 : () => true)
|
|
487
488
|
|
|
488
489
|
const options = config.options || requestConfig.options ? { ...config.options, ...requestConfig.options } : undefined
|
|
489
490
|
|