@kubb/plugin-swr 5.4.0 → 5.4.3

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,291 @@
1
+ import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "kubb/kit";
2
+ import "@kubb/plugin-zod";
3
+ import "@kubb/plugin-ts";
4
+ import "kubb/jsx";
5
+ //#region ../../internals/client/src/resolveClient.d.ts
6
+ /**
7
+ * The client selector accepted by a consumer's `client` option. Each calls a registered contract
8
+ * client plugin.
9
+ */
10
+ type ClientSelector = 'fetch' | 'axios' | 'client';
11
+ /**
12
+ * The resolved client strategy stored in a consumer plugin's options: the generated code always
13
+ * imports and calls a registered contract client plugin's `<op>`. The client runtime lives in
14
+ * plugin-axios / plugin-fetch, so nothing is bundled by the consumer.
15
+ */
16
+ type ResolvedContractClient = {
17
+ kind: 'contract';
18
+ pluginName: string;
19
+ };
20
+ //#endregion
21
+ //#region ../../internals/tanstack-query/src/types.d.ts
22
+ type ParamsCasing = 'camelcase' | undefined;
23
+ /**
24
+ * The hook a key is built for. Plain and suspense queries can share a key, but an infinite query
25
+ * caches `InfiniteData` and must never share one with a plain query.
26
+ */
27
+ type KeyVariant = 'query' | 'suspenseQuery' | 'infiniteQuery' | 'suspenseInfiniteQuery' | 'mutation';
28
+ /**
29
+ * Builds query or mutation key segments for an operation node.
30
+ * Receives `variant` indicating which hook or composable the key is built for.
31
+ */
32
+ type Transformer = (props: {
33
+ node: ast.OperationNode;
34
+ casing: ParamsCasing;
35
+ variant: KeyVariant;
36
+ }) => Array<unknown>;
37
+ //#endregion
38
+ //#region src/types.d.ts
39
+ /**
40
+ * The concrete resolver type for `@kubb/plugin-swr`.
41
+ * Extends the base `Resolver` (which provides `default` naming and option helpers, the top-level
42
+ * `name` casing, and the `file` builder) with plugin-specific naming namespaces for the generated
43
+ * `useSWR` and `useSWRMutation` hooks and their companion helpers.
44
+ */
45
+ type ResolverSwr = Resolver & {
46
+ /**
47
+ * Naming for the generated `useSWR` hook and its companion helpers.
48
+ */
49
+ query: {
50
+ /**
51
+ * Resolves a query hook function name.
52
+ *
53
+ * @example Query hook names
54
+ * `resolver.query.name(node) // → 'useGetPetById'`
55
+ */
56
+ name(node: ast.OperationNode): string;
57
+ /**
58
+ * Resolves the query options helper name.
59
+ *
60
+ * @example Query options helper names
61
+ * `resolver.query.optionsName(node) // → 'getPetByIdQueryOptions'`
62
+ */
63
+ optionsName(node: ast.OperationNode): string;
64
+ /**
65
+ * Resolves the query key helper name.
66
+ *
67
+ * @example Query key helper names
68
+ * `resolver.query.keyName(node) // → 'getPetByIdQueryKey'`
69
+ */
70
+ keyName(node: ast.OperationNode): string;
71
+ /**
72
+ * Resolves the query key type name.
73
+ *
74
+ * @example Query key type names
75
+ * `resolver.query.keyTypeName(node) // → 'GetPetByIdQueryKey'`
76
+ */
77
+ keyTypeName(node: ast.OperationNode): string;
78
+ /**
79
+ * Resolves the client function name generated inline by query hooks.
80
+ *
81
+ * @example Client function names
82
+ * `resolver.query.clientName(node) // → 'getPetById'`
83
+ */
84
+ clientName(node: ast.OperationNode): string;
85
+ };
86
+ /**
87
+ * Naming for the generated `useSWRMutation` hook and its companion helpers.
88
+ */
89
+ mutation: {
90
+ /**
91
+ * Resolves a mutation hook function name.
92
+ *
93
+ * @example Mutation hook names
94
+ * `resolver.mutation.name(node) // → 'useUpdatePet'`
95
+ */
96
+ name(node: ast.OperationNode): string;
97
+ /**
98
+ * Resolves the mutation key helper name.
99
+ *
100
+ * @example Mutation key helper names
101
+ * `resolver.mutation.keyName(node) // → 'updatePetMutationKey'`
102
+ */
103
+ keyName(node: ast.OperationNode): string;
104
+ /**
105
+ * Resolves the mutation key type name.
106
+ *
107
+ * @example Mutation key type names
108
+ * `resolver.mutation.keyTypeName(node) // → 'UpdatePetMutationKey'`
109
+ */
110
+ keyTypeName(node: ast.OperationNode): string;
111
+ /**
112
+ * Resolves the mutation argument type name emitted alongside the mutation hook.
113
+ *
114
+ * @example Mutation argument type names
115
+ * `resolver.mutation.argTypeName(node) // → 'UpdatePetMutationArg'`
116
+ */
117
+ argTypeName(node: ast.OperationNode): string;
118
+ };
119
+ };
120
+ /**
121
+ * Customize the queryKey.
122
+ */
123
+ type QueryKey = Transformer;
124
+ /**
125
+ * Customize the mutationKey.
126
+ */
127
+ type MutationKey = Transformer;
128
+ type Query = {
129
+ /**
130
+ * HTTP methods to use for queries.
131
+ *
132
+ * @default ['GET', 'QUERY']
133
+ */
134
+ methods?: Array<string>;
135
+ /**
136
+ * Path to the useSWR hook for useSWR functionality.
137
+ * Used as `import useSWR from '${importPath}'`.
138
+ * Accepts relative and absolute paths.
139
+ * Path is used as-is. Relative paths are based on the generated file location.
140
+ * @default 'swr'
141
+ */
142
+ importPath?: string;
143
+ };
144
+ type Mutation = {
145
+ /**
146
+ * HTTP methods to use for mutations.
147
+ *
148
+ * @default ['POST', 'PUT', 'PATCH', 'DELETE']
149
+ */
150
+ methods?: Array<string>;
151
+ /**
152
+ * Path to the useSWRMutation hook for useSWRMutation functionality.
153
+ * Used as `import useSWRMutation from '${importPath}'`.
154
+ * Accepts relative and absolute paths.
155
+ * Path is used as-is. Relative paths are based on the generated file location.
156
+ * @default 'swr/mutation'
157
+ */
158
+ importPath?: string;
159
+ };
160
+ /**
161
+ * Where the generated SWR hooks are written and how they are exported, plus the optional `group`
162
+ * strategy. The `group` option organizes `output.mode: 'directory'` output into per-tag or per-path subdirectories.
163
+ *
164
+ * @default { path: 'hooks', barrel: { type: 'named' } }
165
+ */
166
+ type Options = OutputOptions & {
167
+ /**
168
+ * Selects the HTTP client the generated hooks call. Every client plugin speaks the `RequestResult`
169
+ * contract, so the hooks call a contract `<op>` that takes one grouped `options` object.
170
+ *
171
+ * - `'fetch'` / `'axios'` / `'client'` calls the `@kubb/plugin-fetch` / `@kubb/plugin-axios` /
172
+ * `@kubb/plugin-client` functions. When a single client plugin is registered it is
173
+ * auto-detected, so the string is only needed to disambiguate several client plugins.
174
+ *
175
+ * A client plugin must be registered. The hooks always call its `<op>`.
176
+ */
177
+ client?: ClientSelector;
178
+ /**
179
+ * Tags, operations, or paths to exclude from generation.
180
+ */
181
+ exclude?: Array<Exclude>;
182
+ /**
183
+ * Tags, operations, or paths to include in generation.
184
+ */
185
+ include?: Array<Include>;
186
+ /**
187
+ * Override options for specific tags, operations, or paths.
188
+ */
189
+ override?: Array<Override<ResolvedOptions>>;
190
+ /**
191
+ * Custom `queryKey` builder. Use to add a version namespace, swap to
192
+ * operation IDs, or shape keys to match an existing invalidation strategy.
193
+ */
194
+ queryKey?: QueryKey;
195
+ /**
196
+ * Configure useSWR behavior.
197
+ */
198
+ query?: Partial<Query> | false;
199
+ /**
200
+ * Custom `mutationKey` builder. Useful when you match keys from SWR's
201
+ * global `mutate` for cache updates.
202
+ */
203
+ mutationKey?: MutationKey;
204
+ /**
205
+ * Configure useSWRMutation behavior.
206
+ */
207
+ mutation?: Partial<Mutation> | false;
208
+ /**
209
+ * Override naming conventions for function names and types.
210
+ */
211
+ resolver?: ResolverPatch<ResolverSwr>;
212
+ /**
213
+ * Macros that rewrite generated nodes before printing.
214
+ */
215
+ macros?: Array<ast.Macro>;
216
+ };
217
+ type ResolvedOptions = {
218
+ output: Output;
219
+ group: Group | undefined;
220
+ exclude: NonNullable<Options['exclude']>;
221
+ include: Options['include'];
222
+ override: NonNullable<Options['override']>;
223
+ /**
224
+ * The resolved contract client the generators import and call.
225
+ */
226
+ client: ResolvedContractClient;
227
+ queryKey: QueryKey | undefined;
228
+ query: NonNullable<Required<Query>> | false;
229
+ mutationKey: MutationKey | undefined;
230
+ mutation: NonNullable<Required<Mutation>> | false;
231
+ resolver: ResolverSwr;
232
+ };
233
+ type PluginSwr = PluginType<'plugin-swr', Options, ResolvedOptions, ResolverSwr>;
234
+ declare global {
235
+ namespace Kubb {
236
+ interface PluginRegistry {
237
+ 'plugin-swr': PluginSwr;
238
+ }
239
+ }
240
+ }
241
+ //#endregion
242
+ //#region src/plugin.d.ts
243
+ /**
244
+ * Canonical plugin name for `@kubb/plugin-swr`. Used for driver lookups and cross-plugin
245
+ * dependency references.
246
+ */
247
+ export declare const pluginSwrName = "plugin-swr";
248
+ /**
249
+ * Generates SWR hooks from OpenAPI operations. Read operations become `useFoo` hooks built on
250
+ * `useSWR` and write operations become `useFoo` hooks built on `useSWRMutation`, wrapping the
251
+ * client functions from `@kubb/plugin-axios` or `@kubb/plugin-fetch`.
252
+ *
253
+ * @example
254
+ * ```ts
255
+ * import { defineConfig } from 'kubb/config'
256
+ * import { pluginTs } from '@kubb/plugin-ts'
257
+ * import { pluginSwr } from '@kubb/plugin-swr'
258
+ *
259
+ * export default defineConfig({
260
+ * input: './petStore.yaml',
261
+ * output: { path: './src/gen' },
262
+ * plugins: [
263
+ * pluginTs(),
264
+ * pluginSwr({ output: { path: './hooks' } }),
265
+ * ],
266
+ * })
267
+ * ```
268
+ */
269
+ export declare const pluginSwr: import("kubb/kit").PluginFactory<PluginSwr>;
270
+ //#endregion
271
+ //#region src/resolvers/resolverSwr.d.ts
272
+ /**
273
+ * Default resolver used by `@kubb/plugin-swr`. Decides the names and file paths for every generated
274
+ * SWR hook (`useFoo`, `useFooMutation`) and its companion helpers (`fooQueryKey`, `fooQueryOptions`,
275
+ * `fooMutationKey`).
276
+ *
277
+ * Functions and files use the built-in camelCase casing; hooks get the `use` prefix.
278
+ *
279
+ * @example Resolve hook and helper names
280
+ * ```ts
281
+ * import { resolverSwr } from '@kubb/plugin-swr'
282
+ *
283
+ * resolverSwr.query.name(operationNode) // 'useGetPetById'
284
+ * resolverSwr.query.keyName(operationNode) // 'getPetByIdQueryKey'
285
+ * resolverSwr.mutation.name(operationNode) // 'useUpdatePet'
286
+ * ```
287
+ */
288
+ export declare const resolverSwr: ResolverSwr;
289
+ //#endregion
290
+ export { type PluginSwr, type ResolverSwr, type Transformer, pluginSwr as default };
291
+ //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -1,30 +1,22 @@
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";
2
+ import "@kubb/plugin-zod";
3
3
  import "@kubb/plugin-ts";
4
4
  import "kubb/jsx";
5
- import "@kubb/plugin-zod";
6
5
  //#region ../../internals/client/src/resolveClient.d.ts
7
- /**
8
- * Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
9
- * operation, shared so the selection rules and diagnostics stay in one place.
10
- *
11
- * Every client runtime lives in a dedicated client plugin, so a consumer always calls a registered
12
- * contract client plugin (plugin-fetch, plugin-axios, or plugin-client) and never emits its own
13
- * inline client:
14
- *
15
- * - `contract` — a registered contract client plugin owns the `<op>` functions and the consumer
16
- * imports and calls them.
17
- * - `error` — no client plugin is registered, several are registered without a selector, the
18
- * requested one is missing, or `client` is not a known selector.
19
- *
20
- * The `client` string selects explicitly (`'fetch'` / `'axios'` / `'client'`); when it is unset a
21
- * lone registered contract client plugin is picked up automatically.
22
- */
23
6
  /**
24
7
  * The client selector accepted by a consumer's `client` option. Each calls a registered contract
25
8
  * client plugin.
26
9
  */
27
10
  type ClientSelector = 'fetch' | 'axios' | 'client';
11
+ /**
12
+ * The resolved client strategy stored in a consumer plugin's options: the generated code always
13
+ * imports and calls a registered contract client plugin's `<op>`. The client runtime lives in
14
+ * plugin-axios / plugin-fetch, so nothing is bundled by the consumer.
15
+ */
16
+ type ResolvedContractClient = {
17
+ kind: 'contract';
18
+ pluginName: string;
19
+ };
28
20
  //#endregion
29
21
  //#region ../../internals/tanstack-query/src/types.d.ts
30
22
  type ParamsCasing = 'camelcase' | undefined;
@@ -222,14 +214,6 @@ type Options = OutputOptions & {
222
214
  */
223
215
  macros?: Array<ast.Macro>;
224
216
  };
225
- /**
226
- * The resolved client strategy for the generated hooks, computed once during setup. The hooks always
227
- * import and call a registered contract client plugin's `<op>`.
228
- */
229
- type ResolvedClient = {
230
- kind: 'contract';
231
- pluginName: string;
232
- };
233
217
  type ResolvedOptions = {
234
218
  output: Output;
235
219
  group: Group | undefined;
@@ -239,7 +223,7 @@ type ResolvedOptions = {
239
223
  /**
240
224
  * The resolved contract client the generators import and call.
241
225
  */
242
- client: ResolvedClient;
226
+ client: ResolvedContractClient;
243
227
  queryKey: QueryKey | undefined;
244
228
  query: NonNullable<Required<Query>> | false;
245
229
  mutationKey: MutationKey | undefined;