@kubb/plugin-fetch 5.5.7 → 5.5.8
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 +57 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +58 -51
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/plugin.ts +60 -64
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-fetch",
|
|
3
|
-
"version": "5.5.
|
|
3
|
+
"version": "5.5.8",
|
|
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",
|
|
@@ -65,17 +65,17 @@
|
|
|
65
65
|
"registry": "https://registry.npmjs.org/"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@kubb/plugin-ts": "^5.0.
|
|
69
|
-
"@kubb/plugin-zod": "^5.4.
|
|
68
|
+
"@kubb/plugin-ts": "^5.0.7",
|
|
69
|
+
"@kubb/plugin-zod": "^5.4.5"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@internals/client": "0.0.0",
|
|
73
73
|
"@internals/shared": "0.0.0",
|
|
74
|
-
"kubb": "^5.
|
|
74
|
+
"kubb": "^5.8.0",
|
|
75
75
|
"typescript": "^6.0.3"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
78
|
-
"kubb": "^5.
|
|
78
|
+
"kubb": "^5.8.0"
|
|
79
79
|
},
|
|
80
80
|
"engines": {
|
|
81
81
|
"node": ">=22"
|
package/src/plugin.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
2
|
import { createSdkGenerator, defaultMacros, resolverClient } from '@internals/client'
|
|
3
3
|
import { createGroupConfig } from '@internals/shared'
|
|
4
|
-
import { definePlugin, Resolver } from 'kubb/kit'
|
|
4
|
+
import { addGenerator, definePlugin, injectFile, Resolver, setMacros, setResolver, useConfig } from 'kubb/kit'
|
|
5
|
+
import { version } from '../package.json'
|
|
5
6
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
6
7
|
import { pluginZodName } from '@kubb/plugin-zod'
|
|
7
8
|
import { clientGenerator } from './generators/clientGenerator.tsx'
|
|
@@ -36,77 +37,72 @@ export const pluginFetchName = 'plugin-fetch' satisfies PluginFetch['name']
|
|
|
36
37
|
* })
|
|
37
38
|
* ```
|
|
38
39
|
*/
|
|
39
|
-
export const pluginFetch = definePlugin<PluginFetch>(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
40
|
+
export const pluginFetch = definePlugin<PluginFetch>({
|
|
41
|
+
meta: { name: pluginFetchName, version, compatibility: { kubb: '>=5.8.0' } },
|
|
42
|
+
// Both are ordering hints, skipped when the plugin is not in the pipeline. `plugin-ts` supplies
|
|
43
|
+
// the operation types unless it is absent, in which case `pluginZod({ inferred: true })` does.
|
|
44
|
+
dependencies: { [pluginTsName]: { optional: true }, [pluginZodName]: { optional: true } },
|
|
45
|
+
setup(options) {
|
|
46
|
+
const config = useConfig()
|
|
47
|
+
const {
|
|
48
|
+
output = { path: 'clients', barrel: { type: 'named' } },
|
|
49
|
+
exclude = [],
|
|
50
|
+
include,
|
|
51
|
+
override = [],
|
|
52
|
+
baseURL,
|
|
53
|
+
throwOnErrorDefault = true,
|
|
54
|
+
validator = false,
|
|
55
|
+
returnType = 'full',
|
|
56
|
+
group,
|
|
57
|
+
sdk,
|
|
58
|
+
resolver: userResolver,
|
|
59
|
+
} = options
|
|
53
60
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
61
|
+
const resolved: ResolvedOptions = {
|
|
62
|
+
output,
|
|
63
|
+
exclude,
|
|
64
|
+
include,
|
|
65
|
+
override,
|
|
66
|
+
group: createGroupConfig(group),
|
|
67
|
+
baseURL,
|
|
68
|
+
throwOnErrorDefault,
|
|
69
|
+
validator,
|
|
70
|
+
returnType,
|
|
71
|
+
sdk: sdk ? { mode: sdk.mode ?? 'tag', name: sdk.name } : undefined,
|
|
72
|
+
resolver: userResolver ? Resolver.merge<ResolverClient>(resolverClient, userResolver) : resolverClient,
|
|
73
|
+
}
|
|
67
74
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const selectedGenerators = resolved.sdk ? [createSdkGenerator<PluginFetch>()] : [clientGenerator]
|
|
75
|
+
setResolver(resolved.resolver)
|
|
76
|
+
setMacros([...defaultMacros, ...(options.macros ?? [])])
|
|
71
77
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
// Both are ordering hints, dropped when the plugin is not in the pipeline. `plugin-ts` supplies
|
|
76
|
-
// the operation types unless it is absent, in which case `pluginZod({ inferred: true })` does.
|
|
77
|
-
dependencies: [pluginTsName, pluginZodName],
|
|
78
|
-
hooks: {
|
|
79
|
-
'kubb:plugin:setup'(ctx) {
|
|
80
|
-
ctx.setOptions(resolved)
|
|
81
|
-
ctx.setResolver(resolved.resolver)
|
|
82
|
-
ctx.setMacros([...defaultMacros, ...(options.macros ?? [])])
|
|
78
|
+
// `sdk` swaps the per-operation functions for the class-based SDK; left unset, the standalone
|
|
79
|
+
// functions (which query plugins consume) stay.
|
|
80
|
+
addGenerator(resolved.sdk ? createSdkGenerator<PluginFetch>() : clientGenerator)
|
|
83
81
|
|
|
84
|
-
|
|
82
|
+
const root = path.resolve(config.root, config.output.path)
|
|
83
|
+
const baseURLExpression = baseURL ? (baseURL.includes('${') ? `\`${baseURL.replaceAll('`', '\\`')}\`` : JSON.stringify(baseURL)) : undefined
|
|
85
84
|
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
injectFile({
|
|
86
|
+
baseName: 'serializers.ts',
|
|
87
|
+
path: path.resolve(root, '.kubb/serializers.ts'),
|
|
88
|
+
copy: fetchSerializersTemplatePath,
|
|
89
|
+
})
|
|
88
90
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
injectFile({
|
|
92
|
+
baseName: 'client.ts',
|
|
93
|
+
path: path.resolve(root, '.kubb/client.ts'),
|
|
94
|
+
copy: fetchClientTemplatePath,
|
|
95
|
+
footer: baseURLExpression ? `client.setConfig({ baseURL: ${baseURLExpression} })` : undefined,
|
|
96
|
+
})
|
|
94
97
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
})
|
|
98
|
+
injectFile({
|
|
99
|
+
baseName: 'standardSchema.ts',
|
|
100
|
+
path: path.resolve(root, '.kubb/standardSchema.ts'),
|
|
101
|
+
copy: standardSchemaTemplatePath,
|
|
102
|
+
})
|
|
101
103
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
path: path.resolve(root, '.kubb/standardSchema.ts'),
|
|
105
|
-
copy: standardSchemaTemplatePath,
|
|
106
|
-
})
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
}
|
|
104
|
+
return resolved
|
|
105
|
+
},
|
|
110
106
|
})
|
|
111
107
|
|
|
112
108
|
export default pluginFetch
|