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