@kubb/plugin-fetch 5.6.1 → 5.6.4
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 +295 -328
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +237 -0
- package/dist/index.d.ts +0 -2
- package/dist/index.js +296 -329
- package/dist/index.js.map +1 -1
- package/kubb-extension.json +1 -1
- package/package.json +14 -9
- package/src/plugin.ts +26 -5
- package/dist/rolldown-runtime-C0LytTxp.js +0 -8
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "kubb/kit";
|
|
2
|
+
import "@kubb/plugin-zod";
|
|
3
|
+
//#region ../../internals/client/src/types.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Validator applied to request and response bodies using schemas from `@kubb/plugin-zod`.
|
|
6
|
+
* - `false`: no validation.
|
|
7
|
+
* - `'zod'`: validates the success (2xx) response body, and the error body when a non-2xx call does
|
|
8
|
+
* not throw (`throwOnError: false`).
|
|
9
|
+
* - `{ request?: 'zod'; response?: 'zod' }`: opt in per direction. `request` validates the request
|
|
10
|
+
* body before the call; `response` validates the success response body and,
|
|
11
|
+
* on the non-throw path, the error body.
|
|
12
|
+
*/
|
|
13
|
+
type ValidatorOptions = false | 'zod' | {
|
|
14
|
+
request?: 'zod';
|
|
15
|
+
response?: 'zod';
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* How the class-based SDK groups operations.
|
|
19
|
+
* - `'tag'`: one class per tag, optionally composed into a root client.
|
|
20
|
+
* - `'flat'`: one class with every operation as a direct method.
|
|
21
|
+
*/
|
|
22
|
+
type Mode = 'tag' | 'flat';
|
|
23
|
+
/**
|
|
24
|
+
* Shape of the value a generated operation function resolves to.
|
|
25
|
+
* - `'full'`: the complete `{ status, data, error, contentType, request, response }` result.
|
|
26
|
+
* - `'data'`: the bare success body when `throwOnError` is true, or the full result when it is false
|
|
27
|
+
* so callers can inspect `error`.
|
|
28
|
+
* - `'plain'`: the client's own promise typed as `RequestResult`, with no `withUnwrap` / `unwrapResult`
|
|
29
|
+
* helper. Backs `@kubb/plugin-client`.
|
|
30
|
+
*/
|
|
31
|
+
type ReturnTypeOption = 'full' | 'data' | 'plain';
|
|
32
|
+
/**
|
|
33
|
+
* The resolver shared by the client plugins. Inherits the built-in camelCase `name` and `file`;
|
|
34
|
+
* classes and tag groups use PascalCase (with a `Client` suffix for groups).
|
|
35
|
+
*/
|
|
36
|
+
type ResolverClient = Resolver & {
|
|
37
|
+
/**
|
|
38
|
+
* Resolves the generated class name for class-based clients.
|
|
39
|
+
*/
|
|
40
|
+
className(this: ResolverClient, name: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Resolves the generated class name for a tag-based client group. The default appends a
|
|
43
|
+
* `Client` suffix (tag `pet` becomes `PetClient`) so the class never collides with the schema
|
|
44
|
+
* model of the same name in the barrel.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* `resolver.groupName('pet') // -> 'PetClient'`
|
|
48
|
+
*/
|
|
49
|
+
groupName(this: ResolverClient, name: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* Resolves the property name a tag client is exposed under on the composed root SDK
|
|
52
|
+
* (`new PetStore(config).pet`).
|
|
53
|
+
*/
|
|
54
|
+
propertyName(this: ResolverClient, name: string): string;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* The shared options surface for the client plugins. Deliberately small: there is one
|
|
58
|
+
* response contract and one grouped options object. Each plugin extends this with its own
|
|
59
|
+
* `transport` field.
|
|
60
|
+
*/
|
|
61
|
+
type Options = OutputOptions & {
|
|
62
|
+
/**
|
|
63
|
+
* Skip operations matching at least one entry in the list.
|
|
64
|
+
*/
|
|
65
|
+
exclude?: Array<Exclude>;
|
|
66
|
+
/**
|
|
67
|
+
* Restrict generation to operations matching at least one entry in the list.
|
|
68
|
+
*/
|
|
69
|
+
include?: Array<Include>;
|
|
70
|
+
/**
|
|
71
|
+
* Apply a different options object to operations matching a pattern.
|
|
72
|
+
*/
|
|
73
|
+
override?: Array<Override<Omit<ResolvedOptions, 'throwOnErrorDefault'>>>;
|
|
74
|
+
/**
|
|
75
|
+
* Base URL prepended to every request. When omitted, the generated client sets no base URL, so
|
|
76
|
+
* set one at runtime with `client.setConfig({ baseURL })`. The adapter's server URL is not used.
|
|
77
|
+
* Values containing a `${...}` interpolation are emitted as template literals in the generated
|
|
78
|
+
* client config, which keeps runtime environment reads dynamic.
|
|
79
|
+
*/
|
|
80
|
+
baseURL?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Default error behavior for generated operations and their client. Per-call `throwOnError`
|
|
83
|
+
* takes precedence.
|
|
84
|
+
*
|
|
85
|
+
* @default true
|
|
86
|
+
*/
|
|
87
|
+
throwOnErrorDefault?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Validate request and response bodies with schemas from `@kubb/plugin-zod`.
|
|
90
|
+
*
|
|
91
|
+
* @default false
|
|
92
|
+
*/
|
|
93
|
+
validator?: ValidatorOptions;
|
|
94
|
+
/**
|
|
95
|
+
* Shape of the value a generated operation function resolves to. Applies to the standalone
|
|
96
|
+
* functions and the class-based SDK; not to the query-hook plugins (`@kubb/plugin-react-query`,
|
|
97
|
+
* `@kubb/plugin-vue-query`, `@kubb/plugin-swr`), which keep calling the client directly and
|
|
98
|
+
* expect the full result.
|
|
99
|
+
*
|
|
100
|
+
* @default 'full'
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* pluginAxios({ returnType: 'data' })
|
|
104
|
+
* // const pet = await getPetById({ path: { petId: 1 } }) // Pet, not { status, data, ... }
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
returnType?: ReturnTypeOption;
|
|
108
|
+
/**
|
|
109
|
+
* Generates a class-based SDK instead of the standalone functions. Each tag client is an instance
|
|
110
|
+
* class whose constructor takes a client config and builds its own client, so every environment is
|
|
111
|
+
* a separate instance. Leave `sdk` unset to keep the standalone per-operation functions (the
|
|
112
|
+
* default), which is also what query plugins consume.
|
|
113
|
+
*
|
|
114
|
+
* @example Instance class per tag
|
|
115
|
+
* ```ts
|
|
116
|
+
* pluginFetch({ sdk: {} })
|
|
117
|
+
* // const api = new PetClient({ baseURL: 'https://api.example.com' })
|
|
118
|
+
* // await api.getPetById({ path: { petId: 1 } })
|
|
119
|
+
* ```
|
|
120
|
+
* @example Composed root that instantiates every tag client from one config
|
|
121
|
+
* ```ts
|
|
122
|
+
* pluginFetch({ sdk: { name: 'petStore' } })
|
|
123
|
+
* // class PetStore {
|
|
124
|
+
* // readonly pet: PetClient
|
|
125
|
+
* // readonly store: StoreClient
|
|
126
|
+
* // constructor(config = {}) { ... }
|
|
127
|
+
* // }
|
|
128
|
+
* // const api = new PetStore({ baseURL })
|
|
129
|
+
* // await api.pet.getPetById({ path: { petId: 1 } })
|
|
130
|
+
* ```
|
|
131
|
+
* @example Flat class with every operation as a direct method
|
|
132
|
+
* ```ts
|
|
133
|
+
* pluginFetch({ sdk: { name: 'petStore', mode: 'flat' } })
|
|
134
|
+
* // const api = new PetStore({ baseURL })
|
|
135
|
+
* // await api.getPetById({ path: { petId: 1 } })
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
sdk?: {
|
|
139
|
+
/**
|
|
140
|
+
* How the SDK groups operations.
|
|
141
|
+
* - `'tag'`: one class per tag. With `name`, a composed root instantiates every tag client.
|
|
142
|
+
* - `'flat'`: one class named by `name`, with every operation as a direct method.
|
|
143
|
+
*
|
|
144
|
+
* @default 'tag'
|
|
145
|
+
*/
|
|
146
|
+
mode?: Mode;
|
|
147
|
+
/**
|
|
148
|
+
* Name of the generated entry point, also the file name. With `mode: 'tag'` it emits a
|
|
149
|
+
* composed root class that instantiates every tag client from one shared config. With
|
|
150
|
+
* `mode: 'flat'` it names the single class.
|
|
151
|
+
*/
|
|
152
|
+
name?: string;
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* Override how names and file paths are built. Methods you omit fall back to the default resolver.
|
|
156
|
+
*/
|
|
157
|
+
resolver?: ResolverPatch<ResolverClient>;
|
|
158
|
+
/**
|
|
159
|
+
* Macros applied to each operation node before code is printed.
|
|
160
|
+
*/
|
|
161
|
+
macros?: Array<ast.Macro>;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* The resolved options after defaults are applied.
|
|
165
|
+
*/
|
|
166
|
+
type ResolvedOptions = {
|
|
167
|
+
output: Output;
|
|
168
|
+
exclude: Array<Exclude>;
|
|
169
|
+
include: Array<Include> | undefined;
|
|
170
|
+
override: Array<Override<Omit<ResolvedOptions, 'throwOnErrorDefault'>>>;
|
|
171
|
+
group: Group | null;
|
|
172
|
+
baseURL: Options['baseURL'];
|
|
173
|
+
throwOnErrorDefault: boolean;
|
|
174
|
+
validator: NonNullable<Options['validator']>;
|
|
175
|
+
returnType: ReturnTypeOption;
|
|
176
|
+
sdk: {
|
|
177
|
+
mode: Mode;
|
|
178
|
+
name: string | undefined;
|
|
179
|
+
} | undefined;
|
|
180
|
+
resolver: ResolverClient;
|
|
181
|
+
};
|
|
182
|
+
//#endregion
|
|
183
|
+
//#region src/types.d.ts
|
|
184
|
+
/**
|
|
185
|
+
* The plugin factory type for `@kubb/plugin-fetch`. Shares the options surface, resolver, and
|
|
186
|
+
* resolved-options shape with the other client plugins; only the plugin name and transport
|
|
187
|
+
* differ.
|
|
188
|
+
*/
|
|
189
|
+
type PluginFetch = PluginType<'plugin-fetch', Options, ResolvedOptions, ResolverClient>;
|
|
190
|
+
declare global {
|
|
191
|
+
namespace Kubb {
|
|
192
|
+
interface PluginRegistry {
|
|
193
|
+
'plugin-fetch': PluginFetch;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
//#endregion
|
|
198
|
+
//#region src/generators/clientGenerator.d.ts
|
|
199
|
+
/**
|
|
200
|
+
* Built-in operation generator for `@kubb/plugin-fetch`. Emits one async function per OpenAPI
|
|
201
|
+
* operation using the shared `Operation` component: a grouped `<Name>Request` type and a function
|
|
202
|
+
* that forwards a single `options` object to the bundled `client` and returns the `RequestResult`.
|
|
203
|
+
*/
|
|
204
|
+
export declare const clientGenerator: import("kubb/kit").Generator<PluginFetch>;
|
|
205
|
+
//#endregion
|
|
206
|
+
//#region src/plugin.d.ts
|
|
207
|
+
/**
|
|
208
|
+
* Canonical plugin name for `@kubb/plugin-fetch`. Used for driver lookups and cross-plugin
|
|
209
|
+
* dependency references.
|
|
210
|
+
*/
|
|
211
|
+
export declare const pluginFetchName = "plugin-fetch";
|
|
212
|
+
/**
|
|
213
|
+
* Generates a type-safe HTTP client pinned to the Fetch API. Each operation becomes one async
|
|
214
|
+
* function that takes a single grouped `options` object and returns the shared `RequestResult`
|
|
215
|
+
* contract. The runtime is always bundled into `.kubb/client.ts`, so generated code never imports
|
|
216
|
+
* from `@kubb/plugin-fetch` and the only runtime dependency is the global `fetch`.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```ts
|
|
220
|
+
* import { defineConfig } from 'kubb/config'
|
|
221
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
222
|
+
* import { pluginFetch } from '@kubb/plugin-fetch'
|
|
223
|
+
*
|
|
224
|
+
* export default defineConfig({
|
|
225
|
+
* input: './petStore.yaml',
|
|
226
|
+
* output: { path: './src/gen' },
|
|
227
|
+
* plugins: [
|
|
228
|
+
* pluginTs(),
|
|
229
|
+
* pluginFetch({ output: { path: './clients' } }),
|
|
230
|
+
* ],
|
|
231
|
+
* })
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
export declare const pluginFetch: import("kubb/kit").PluginFactory<PluginFetch>;
|
|
235
|
+
//#endregion
|
|
236
|
+
export { type Options, type PluginFetch, type ResolvedOptions, type ResolverClient, pluginFetch as default };
|
|
237
|
+
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
|
|
2
1
|
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "kubb/kit";
|
|
3
|
-
import "kubb/jsx";
|
|
4
2
|
import "@kubb/plugin-zod";
|
|
5
3
|
//#region ../../internals/client/src/types.d.ts
|
|
6
4
|
/**
|