@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-fetch",
3
- "version": "5.5.7",
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.6",
69
- "@kubb/plugin-zod": "^5.4.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.6.3",
74
+ "kubb": "^5.8.0",
75
75
  "typescript": "^6.0.3"
76
76
  },
77
77
  "peerDependencies": {
78
- "kubb": "^5.6.3"
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>((options) => {
40
- const {
41
- output = { path: 'clients', barrel: { type: 'named' } },
42
- exclude = [],
43
- include,
44
- override = [],
45
- baseURL,
46
- throwOnErrorDefault = true,
47
- validator = false,
48
- returnType = 'full',
49
- group,
50
- sdk,
51
- resolver: userResolver,
52
- } = options
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
- const resolved: ResolvedOptions = {
55
- output,
56
- exclude,
57
- include,
58
- override,
59
- group: createGroupConfig(group),
60
- baseURL,
61
- throwOnErrorDefault,
62
- validator,
63
- returnType,
64
- sdk: sdk ? { mode: sdk.mode ?? 'tag', name: sdk.name } : undefined,
65
- resolver: userResolver ? Resolver.merge<ResolverClient>(resolverClient, userResolver) : resolverClient,
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
- // `sdk` swaps the per-operation functions for the class-based SDK; left unset, the standalone
69
- // functions (which query plugins consume) stay.
70
- const selectedGenerators = resolved.sdk ? [createSdkGenerator<PluginFetch>()] : [clientGenerator]
75
+ setResolver(resolved.resolver)
76
+ setMacros([...defaultMacros, ...(options.macros ?? [])])
71
77
 
72
- return {
73
- name: pluginFetchName,
74
- options,
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
- ctx.addGenerator(...selectedGenerators)
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
- const root = path.resolve(ctx.config.root, ctx.config.output.path)
87
- const baseURLExpression = baseURL ? (baseURL.includes('${') ? `\`${baseURL.replaceAll('`', '\\`')}\`` : JSON.stringify(baseURL)) : undefined
85
+ injectFile({
86
+ baseName: 'serializers.ts',
87
+ path: path.resolve(root, '.kubb/serializers.ts'),
88
+ copy: fetchSerializersTemplatePath,
89
+ })
88
90
 
89
- ctx.injectFile({
90
- baseName: 'serializers.ts',
91
- path: path.resolve(root, '.kubb/serializers.ts'),
92
- copy: fetchSerializersTemplatePath,
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
- ctx.injectFile({
96
- baseName: 'client.ts',
97
- path: path.resolve(root, '.kubb/client.ts'),
98
- copy: fetchClientTemplatePath,
99
- footer: baseURLExpression ? `client.setConfig({ baseURL: ${baseURLExpression} })` : undefined,
100
- })
98
+ injectFile({
99
+ baseName: 'standardSchema.ts',
100
+ path: path.resolve(root, '.kubb/standardSchema.ts'),
101
+ copy: standardSchemaTemplatePath,
102
+ })
101
103
 
102
- ctx.injectFile({
103
- baseName: 'standardSchema.ts',
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