@kubb/plugin-axios 5.0.0-beta.98 → 5.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-axios",
3
- "version": "5.0.0-beta.98",
3
+ "version": "5.0.0",
4
4
  "description": "Generate a slim, type-safe HTTP client with Kubb based on axios.",
5
5
  "keywords": [
6
6
  "api-client",
@@ -49,19 +49,19 @@
49
49
  "registry": "https://registry.npmjs.org/"
50
50
  },
51
51
  "dependencies": {
52
- "@kubb/plugin-ts": "5.0.0-beta.98",
53
- "@kubb/plugin-zod": "5.0.0-beta.97"
52
+ "@kubb/plugin-ts": "^5.0.0",
53
+ "@kubb/plugin-zod": "^5.0.0"
54
54
  },
55
55
  "devDependencies": {
56
- "axios": "^1.18.1",
57
- "kubb": "5.0.0-beta.97",
56
+ "axios": "^1.19.0",
57
+ "kubb": "^5.0.0",
58
58
  "typescript": "^6.0.3",
59
59
  "@internals/client": "0.0.0",
60
60
  "@internals/shared": "0.0.0"
61
61
  },
62
62
  "peerDependencies": {
63
- "axios": "^1.7.2",
64
- "kubb": "5.0.0-beta.97"
63
+ "axios": "^1.19.0",
64
+ "kubb": "^5.0.0"
65
65
  },
66
66
  "peerDependenciesMeta": {
67
67
  "axios": {
@@ -76,9 +76,6 @@
76
76
  "clean": "node -e \"require('node:fs').rmSync('./dist', {recursive:true,force:true})\"",
77
77
  "lint": "oxlint .",
78
78
  "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
79
  "start": "tsdown --watch",
83
80
  "test": "vitest --passWithNoTests",
84
81
  "typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
@@ -1,106 +1,9 @@
1
- import path from 'node:path'
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 that
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 = defineGenerator<PluginAxios>({
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')
@@ -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 = requestConfig.validateStatus ?? config.validateStatus ?? (throwOnError ? undefined : () => true)
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