@kubb/plugin-fetch 5.6.1 → 5.6.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.
- package/dist/index.cjs +294 -327
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.js +295 -328
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/plugin.ts +26 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-fetch",
|
|
3
|
-
"version": "5.6.
|
|
3
|
+
"version": "5.6.2",
|
|
4
4
|
"description": "Generate a slim, type-safe HTTP client with Kubb based on the native Fetch api.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api-client",
|
|
@@ -75,17 +75,17 @@
|
|
|
75
75
|
"registry": "https://registry.npmjs.org/"
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
|
-
"@kubb/plugin-ts": "^5.0.
|
|
79
|
-
"@kubb/plugin-zod": "^5.4.
|
|
78
|
+
"@kubb/plugin-ts": "^5.0.12",
|
|
79
|
+
"@kubb/plugin-zod": "^5.4.10"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
82
|
"@internals/client": "0.0.0",
|
|
83
83
|
"@internals/shared": "0.0.0",
|
|
84
|
-
"kubb": "^5.
|
|
84
|
+
"kubb": "^5.10.2",
|
|
85
85
|
"typescript": "^6.0.3"
|
|
86
86
|
},
|
|
87
87
|
"peerDependencies": {
|
|
88
|
-
"kubb": "^5.
|
|
88
|
+
"kubb": "^5.10.2"
|
|
89
89
|
},
|
|
90
90
|
"engines": {
|
|
91
91
|
"node": ">=22"
|
package/src/plugin.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
-
import { createSdkGenerator, defaultMacros, resolverClient } from '@internals/client'
|
|
2
|
+
import { createSdkGenerator, defaultMacros, isValidatorEnabled, resolverClient } from '@internals/client'
|
|
3
3
|
import { createGroupConfig } from '@internals/shared'
|
|
4
|
-
import { addGenerator, defineExtension, injectFile, Resolver, setMacros, setResolver, useConfig } from 'kubb/kit'
|
|
4
|
+
import { addGenerator, assertPluginOption, defineExtension, injectFile, Resolver, setMacros, setResolver, useConfig } from 'kubb/kit'
|
|
5
5
|
import { compatibility } from '../kubb-extension.json'
|
|
6
6
|
import { version } from '../package.json'
|
|
7
7
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
@@ -41,9 +41,9 @@ export const pluginFetchName = 'plugin-fetch' satisfies PluginFetch['name']
|
|
|
41
41
|
export const pluginFetch = defineExtension<PluginFetch>({
|
|
42
42
|
kind: 'plugin',
|
|
43
43
|
meta: { name: pluginFetchName, version, compatibility },
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
dependencies: { [pluginTsName]: { optional: true }, [pluginZodName]: { optional:
|
|
44
|
+
// `plugin-ts` supplies the operation types unless it is absent, in which case `pluginZod({ inferred: true })`
|
|
45
|
+
// does. `plugin-zod` is required once `validator` enables a direction, so a missing one fails setup instead of codegen.
|
|
46
|
+
dependencies: (options) => ({ [pluginTsName]: { optional: true }, [pluginZodName]: { optional: !isValidatorEnabled(options.validator) } }),
|
|
47
47
|
setup(options) {
|
|
48
48
|
const config = useConfig()
|
|
49
49
|
const {
|
|
@@ -74,6 +74,27 @@ export const pluginFetch = defineExtension<PluginFetch>({
|
|
|
74
74
|
resolver: userResolver ? Resolver.merge<ResolverClient>(resolverClient, userResolver) : resolverClient,
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
const allowedReturnTypes = ['full', 'data', 'plain'] satisfies Array<ResolvedOptions['returnType']>
|
|
78
|
+
assertPluginOption({ plugin: pluginFetchName, option: 'returnType', value: returnType, allowed: allowedReturnTypes })
|
|
79
|
+
// An override replaces `returnType` per operation, so its values are checked too.
|
|
80
|
+
for (const [index, entry] of override.entries()) {
|
|
81
|
+
if (entry.options.returnType === undefined) continue
|
|
82
|
+
assertPluginOption({
|
|
83
|
+
plugin: pluginFetchName,
|
|
84
|
+
option: `override[${index}].options.returnType`,
|
|
85
|
+
value: entry.options.returnType,
|
|
86
|
+
allowed: allowedReturnTypes,
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
if (resolved.sdk) {
|
|
90
|
+
assertPluginOption({
|
|
91
|
+
plugin: pluginFetchName,
|
|
92
|
+
option: 'sdk.mode',
|
|
93
|
+
value: resolved.sdk.mode,
|
|
94
|
+
allowed: ['tag', 'flat'] satisfies Array<NonNullable<ResolvedOptions['sdk']>['mode']>,
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
|
|
77
98
|
setResolver(resolved.resolver)
|
|
78
99
|
setMacros([...defaultMacros, ...(options.macros ?? [])])
|
|
79
100
|
|