@kubb/plugin-fetch 5.6.2 → 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 +2 -2
- package/dist/index.d.cts +237 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.js +3 -3
- package/kubb-extension.json +1 -1
- package/package.json +14 -9
- package/dist/rolldown-runtime-C0LytTxp.js +0 -8
package/dist/index.cjs
CHANGED
|
@@ -1424,11 +1424,11 @@ const clientGenerator = createClientGenerator("fetch");
|
|
|
1424
1424
|
//#region kubb-extension.json
|
|
1425
1425
|
var compatibility = {
|
|
1426
1426
|
"kubb": ">=5.8.3",
|
|
1427
|
-
"node": ">=22"
|
|
1427
|
+
"node": ">=22.12"
|
|
1428
1428
|
};
|
|
1429
1429
|
//#endregion
|
|
1430
1430
|
//#region package.json
|
|
1431
|
-
var version = "5.6.
|
|
1431
|
+
var version = "5.6.4";
|
|
1432
1432
|
//#endregion
|
|
1433
1433
|
//#region src/templates.ts
|
|
1434
1434
|
/** Absolute path to the fetch client template, copied into `.kubb/client.ts`. */
|
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,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Diagnostics, Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "kubb/kit";
|
|
1
|
+
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "kubb/kit";
|
|
3
2
|
import "@kubb/plugin-zod";
|
|
4
3
|
//#region ../../internals/client/src/types.d.ts
|
|
5
4
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import "./rolldown-runtime-C0LytTxp.js";
|
|
2
1
|
import { Diagnostics, Resolver, Url, addGenerator, assertPluginOption, ast, createResolver, defineExtension, defineGenerator, injectFile, macroSimplifyUnion, setMacros, setResolver, useConfig } from "kubb/kit";
|
|
3
2
|
import path from "node:path";
|
|
4
3
|
import { pluginZodName } from "@kubb/plugin-zod";
|
|
@@ -6,6 +5,7 @@ import { File, Function, jsxRenderer } from "kubb/jsx";
|
|
|
6
5
|
import { createFunctionParameter, createFunctionParameters, functionPrinter, pluginTsName } from "@kubb/plugin-ts";
|
|
7
6
|
import { Fragment, jsx, jsxs } from "kubb/jsx/jsx-runtime";
|
|
8
7
|
import { fileURLToPath } from "node:url";
|
|
8
|
+
//#endregion
|
|
9
9
|
//#region ../../internals/shared/src/operation.ts
|
|
10
10
|
/**
|
|
11
11
|
* Builds the `ResolverFileParams` every operation generator passes to
|
|
@@ -1398,11 +1398,11 @@ const clientGenerator = createClientGenerator("fetch");
|
|
|
1398
1398
|
//#region kubb-extension.json
|
|
1399
1399
|
var compatibility = {
|
|
1400
1400
|
"kubb": ">=5.8.3",
|
|
1401
|
-
"node": ">=22"
|
|
1401
|
+
"node": ">=22.12"
|
|
1402
1402
|
};
|
|
1403
1403
|
//#endregion
|
|
1404
1404
|
//#region package.json
|
|
1405
|
-
var version = "5.6.
|
|
1405
|
+
var version = "5.6.4";
|
|
1406
1406
|
//#endregion
|
|
1407
1407
|
//#region src/templates.ts
|
|
1408
1408
|
/** Absolute path to the fetch client template, copied into `.kubb/client.ts`. */
|
package/kubb-extension.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-fetch",
|
|
3
|
-
"version": "5.6.
|
|
3
|
+
"version": "5.6.4",
|
|
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",
|
|
@@ -55,9 +55,14 @@
|
|
|
55
55
|
},
|
|
56
56
|
"exports": {
|
|
57
57
|
".": {
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
"import": {
|
|
59
|
+
"types": "./dist/index.d.ts",
|
|
60
|
+
"default": "./dist/index.js"
|
|
61
|
+
},
|
|
62
|
+
"require": {
|
|
63
|
+
"types": "./dist/index.d.cts",
|
|
64
|
+
"default": "./dist/index.cjs"
|
|
65
|
+
}
|
|
61
66
|
},
|
|
62
67
|
"./package.json": "./package.json",
|
|
63
68
|
"./kubb-extension.json": "./kubb-extension.json",
|
|
@@ -75,20 +80,20 @@
|
|
|
75
80
|
"registry": "https://registry.npmjs.org/"
|
|
76
81
|
},
|
|
77
82
|
"dependencies": {
|
|
78
|
-
"@kubb/plugin-ts": "^5.0.
|
|
79
|
-
"@kubb/plugin-zod": "^5.4.
|
|
83
|
+
"@kubb/plugin-ts": "^5.0.14",
|
|
84
|
+
"@kubb/plugin-zod": "^5.4.12"
|
|
80
85
|
},
|
|
81
86
|
"devDependencies": {
|
|
82
87
|
"@internals/client": "0.0.0",
|
|
83
88
|
"@internals/shared": "0.0.0",
|
|
84
|
-
"kubb": "^5.10.
|
|
89
|
+
"kubb": "^5.10.3",
|
|
85
90
|
"typescript": "^6.0.3"
|
|
86
91
|
},
|
|
87
92
|
"peerDependencies": {
|
|
88
|
-
"kubb": "^5.10.
|
|
93
|
+
"kubb": "^5.10.3"
|
|
89
94
|
},
|
|
90
95
|
"engines": {
|
|
91
|
-
"node": ">=22"
|
|
96
|
+
"node": ">=22.12"
|
|
92
97
|
},
|
|
93
98
|
"scripts": {
|
|
94
99
|
"build": "tsdown",
|