@kubb/plugin-fetch 5.6.2 → 5.6.5

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.
@@ -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 { t as __name } from "./rolldown-runtime-C0LytTxp.js";
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
@@ -688,21 +688,23 @@ function toKey(name, location) {
688
688
  return isValidVarName(key) ? key : JSON.stringify(key);
689
689
  }
690
690
  /**
691
- * Serializes one parameter's metadata into a `{ style, explode }` literal, or `null` when the
692
- * parameter carries neither. Path and query carry the serialization `style`; header and cookie use a
693
- * fixed style (`simple` and `form`), so only `explode` is emitted for them.
691
+ * Serializes one parameter's metadata into a `{ style, explode, allowReserved }` literal, or `null`
692
+ * when the parameter carries none. Path and query carry the serialization `style`; header and cookie
693
+ * use a fixed style (`simple` and `form`), so only `explode` is emitted for them. `allowReserved`
694
+ * only applies to query parameters.
694
695
  */
695
696
  function serializeParameter(parameter) {
696
697
  const parts = [];
697
698
  if ((parameter.in === "path" || parameter.in === "query") && parameter.style) parts.push(`style: '${parameter.style}'`);
698
699
  if (parameter.explode !== void 0) parts.push(`explode: ${parameter.explode}`);
700
+ if (parameter.in === "query" && parameter.allowReserved !== void 0) parts.push(`allowReserved: ${parameter.allowReserved}`);
699
701
  return parts.length > 0 ? `{ ${parts.join(", ")} }` : null;
700
702
  }
701
703
  /**
702
704
  * Builds the per-operation `styles` literal from the operation's parameters, grouped by location.
703
705
  * Path entries are keyed by the camelCased name to match the URL template placeholders; query,
704
706
  * header, and cookie entries keep the spec name to match the keys the runtime serializes.
705
- * Only parameters whose source defines `style` or `explode` are emitted, so calls without
707
+ * Only parameters whose source defines `style`, `explode`, or `allowReserved` are emitted, so calls without
706
708
  * serialization metadata keep the runtime defaults and existing output is unchanged. Returns `null`
707
709
  * when no parameter carries metadata.
708
710
  *
@@ -1398,11 +1400,11 @@ const clientGenerator = createClientGenerator("fetch");
1398
1400
  //#region kubb-extension.json
1399
1401
  var compatibility = {
1400
1402
  "kubb": ">=5.8.3",
1401
- "node": ">=22"
1403
+ "node": ">=22.12"
1402
1404
  };
1403
1405
  //#endregion
1404
1406
  //#region package.json
1405
- var version = "5.6.2";
1407
+ var version = "5.6.5";
1406
1408
  //#endregion
1407
1409
  //#region src/templates.ts
1408
1410
  /** Absolute path to the fetch client template, copied into `.kubb/client.ts`. */