@kubb/plugin-swr 5.4.1 → 5.4.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.
@@ -0,0 +1,317 @@
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 ../../internals/tanstack-query/src/components/MutationKey.d.ts
39
+ /**
40
+ * Default `mutationKey` builder. Call it from a custom builder to extend the default key.
41
+ *
42
+ * @remarks The returned segments may change between releases. Spread them instead of reading single entries.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * mutationKey: (props) => [JSON.stringify(props.node.operationId), ...mutationKeyTransformer(props)]
47
+ * ```
48
+ */
49
+ export declare const mutationKeyTransformer: Transformer;
50
+ //#endregion
51
+ //#region ../../internals/tanstack-query/src/components/QueryKey.d.ts
52
+ /**
53
+ * Default `queryKey` builder. Call it from a custom builder to extend the default key.
54
+ *
55
+ * @remarks The returned segments may change between releases. Spread them instead of reading single entries.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * queryKey: (props) => [JSON.stringify(props.node.operationId), ...queryKeyTransformer(props)]
60
+ * ```
61
+ */
62
+ export declare const queryKeyTransformer: Transformer;
63
+ //#endregion
64
+ //#region src/types.d.ts
65
+ /**
66
+ * The concrete resolver type for `@kubb/plugin-swr`.
67
+ * Extends the base `Resolver` (which provides `default` naming and option helpers, the top-level
68
+ * `name` casing, and the `file` builder) with plugin-specific naming namespaces for the generated
69
+ * `useSWR` and `useSWRMutation` hooks and their companion helpers.
70
+ */
71
+ type ResolverSwr = Resolver & {
72
+ /**
73
+ * Naming for the generated `useSWR` hook and its companion helpers.
74
+ */
75
+ query: {
76
+ /**
77
+ * Resolves a query hook function name.
78
+ *
79
+ * @example Query hook names
80
+ * `resolver.query.name(node) // → 'useGetPetById'`
81
+ */
82
+ name(node: ast.OperationNode): string;
83
+ /**
84
+ * Resolves the query options helper name.
85
+ *
86
+ * @example Query options helper names
87
+ * `resolver.query.optionsName(node) // → 'getPetByIdQueryOptions'`
88
+ */
89
+ optionsName(node: ast.OperationNode): string;
90
+ /**
91
+ * Resolves the query key helper name.
92
+ *
93
+ * @example Query key helper names
94
+ * `resolver.query.keyName(node) // → 'getPetByIdQueryKey'`
95
+ */
96
+ keyName(node: ast.OperationNode): string;
97
+ /**
98
+ * Resolves the query key type name.
99
+ *
100
+ * @example Query key type names
101
+ * `resolver.query.keyTypeName(node) // → 'GetPetByIdQueryKey'`
102
+ */
103
+ keyTypeName(node: ast.OperationNode): string;
104
+ /**
105
+ * Resolves the client function name generated inline by query hooks.
106
+ *
107
+ * @example Client function names
108
+ * `resolver.query.clientName(node) // → 'getPetById'`
109
+ */
110
+ clientName(node: ast.OperationNode): string;
111
+ };
112
+ /**
113
+ * Naming for the generated `useSWRMutation` hook and its companion helpers.
114
+ */
115
+ mutation: {
116
+ /**
117
+ * Resolves a mutation hook function name.
118
+ *
119
+ * @example Mutation hook names
120
+ * `resolver.mutation.name(node) // → 'useUpdatePet'`
121
+ */
122
+ name(node: ast.OperationNode): string;
123
+ /**
124
+ * Resolves the mutation key helper name.
125
+ *
126
+ * @example Mutation key helper names
127
+ * `resolver.mutation.keyName(node) // → 'updatePetMutationKey'`
128
+ */
129
+ keyName(node: ast.OperationNode): string;
130
+ /**
131
+ * Resolves the mutation key type name.
132
+ *
133
+ * @example Mutation key type names
134
+ * `resolver.mutation.keyTypeName(node) // → 'UpdatePetMutationKey'`
135
+ */
136
+ keyTypeName(node: ast.OperationNode): string;
137
+ /**
138
+ * Resolves the mutation argument type name emitted alongside the mutation hook.
139
+ *
140
+ * @example Mutation argument type names
141
+ * `resolver.mutation.argTypeName(node) // → 'UpdatePetMutationArg'`
142
+ */
143
+ argTypeName(node: ast.OperationNode): string;
144
+ };
145
+ };
146
+ /**
147
+ * Customize the queryKey.
148
+ */
149
+ type QueryKey = Transformer;
150
+ /**
151
+ * Customize the mutationKey.
152
+ */
153
+ type MutationKey = Transformer;
154
+ type Query = {
155
+ /**
156
+ * HTTP methods to use for queries.
157
+ *
158
+ * @default ['GET', 'QUERY']
159
+ */
160
+ methods?: Array<string>;
161
+ /**
162
+ * Path to the useSWR hook for useSWR functionality.
163
+ * Used as `import useSWR from '${importPath}'`.
164
+ * Accepts relative and absolute paths.
165
+ * Path is used as-is. Relative paths are based on the generated file location.
166
+ * @default 'swr'
167
+ */
168
+ importPath?: string;
169
+ };
170
+ type Mutation = {
171
+ /**
172
+ * HTTP methods to use for mutations.
173
+ *
174
+ * @default ['POST', 'PUT', 'PATCH', 'DELETE']
175
+ */
176
+ methods?: Array<string>;
177
+ /**
178
+ * Path to the useSWRMutation hook for useSWRMutation functionality.
179
+ * Used as `import useSWRMutation from '${importPath}'`.
180
+ * Accepts relative and absolute paths.
181
+ * Path is used as-is. Relative paths are based on the generated file location.
182
+ * @default 'swr/mutation'
183
+ */
184
+ importPath?: string;
185
+ };
186
+ /**
187
+ * Where the generated SWR hooks are written and how they are exported, plus the optional `group`
188
+ * strategy. The `group` option organizes `output.mode: 'directory'` output into per-tag or per-path subdirectories.
189
+ *
190
+ * @default { path: 'hooks', barrel: { type: 'named' } }
191
+ */
192
+ type Options = OutputOptions & {
193
+ /**
194
+ * Selects the HTTP client the generated hooks call. Every client plugin speaks the `RequestResult`
195
+ * contract, so the hooks call a contract `<op>` that takes one grouped `options` object.
196
+ *
197
+ * - `'fetch'` / `'axios'` / `'client'` calls the `@kubb/plugin-fetch` / `@kubb/plugin-axios` /
198
+ * `@kubb/plugin-client` functions. When a single client plugin is registered it is
199
+ * auto-detected, so the string is only needed to disambiguate several client plugins.
200
+ *
201
+ * A client plugin must be registered. The hooks always call its `<op>`.
202
+ */
203
+ client?: ClientSelector;
204
+ /**
205
+ * Tags, operations, or paths to exclude from generation.
206
+ */
207
+ exclude?: Array<Exclude>;
208
+ /**
209
+ * Tags, operations, or paths to include in generation.
210
+ */
211
+ include?: Array<Include>;
212
+ /**
213
+ * Override options for specific tags, operations, or paths.
214
+ */
215
+ override?: Array<Override<ResolvedOptions>>;
216
+ /**
217
+ * Custom `queryKey` builder. Use to add a version namespace, swap to
218
+ * operation IDs, or shape keys to match an existing invalidation strategy.
219
+ */
220
+ queryKey?: QueryKey;
221
+ /**
222
+ * Configure useSWR behavior.
223
+ */
224
+ query?: Partial<Query> | false;
225
+ /**
226
+ * Custom `mutationKey` builder. Useful when you match keys from SWR's
227
+ * global `mutate` for cache updates.
228
+ */
229
+ mutationKey?: MutationKey;
230
+ /**
231
+ * Configure useSWRMutation behavior.
232
+ */
233
+ mutation?: Partial<Mutation> | false;
234
+ /**
235
+ * Override naming conventions for function names and types.
236
+ */
237
+ resolver?: ResolverPatch<ResolverSwr>;
238
+ /**
239
+ * Macros that rewrite generated nodes before printing.
240
+ */
241
+ macros?: Array<ast.Macro>;
242
+ };
243
+ type ResolvedOptions = {
244
+ output: Output;
245
+ group: Group | undefined;
246
+ exclude: NonNullable<Options['exclude']>;
247
+ include: Options['include'];
248
+ override: NonNullable<Options['override']>;
249
+ /**
250
+ * The resolved contract client the generators import and call.
251
+ */
252
+ client: ResolvedContractClient;
253
+ queryKey: QueryKey | undefined;
254
+ query: NonNullable<Required<Query>> | false;
255
+ mutationKey: MutationKey | undefined;
256
+ mutation: NonNullable<Required<Mutation>> | false;
257
+ resolver: ResolverSwr;
258
+ };
259
+ type PluginSwr = PluginType<'plugin-swr', Options, ResolvedOptions, ResolverSwr>;
260
+ declare global {
261
+ namespace Kubb {
262
+ interface PluginRegistry {
263
+ 'plugin-swr': PluginSwr;
264
+ }
265
+ }
266
+ }
267
+ //#endregion
268
+ //#region src/plugin.d.ts
269
+ /**
270
+ * Canonical plugin name for `@kubb/plugin-swr`. Used for driver lookups and cross-plugin
271
+ * dependency references.
272
+ */
273
+ export declare const pluginSwrName = "plugin-swr";
274
+ /**
275
+ * Generates SWR hooks from OpenAPI operations. Read operations become `useFoo` hooks built on
276
+ * `useSWR` and write operations become `useFoo` hooks built on `useSWRMutation`, wrapping the
277
+ * client functions from `@kubb/plugin-axios` or `@kubb/plugin-fetch`.
278
+ *
279
+ * @example
280
+ * ```ts
281
+ * import { defineConfig } from 'kubb/config'
282
+ * import { pluginTs } from '@kubb/plugin-ts'
283
+ * import { pluginSwr } from '@kubb/plugin-swr'
284
+ *
285
+ * export default defineConfig({
286
+ * input: './petStore.yaml',
287
+ * output: { path: './src/gen' },
288
+ * plugins: [
289
+ * pluginTs(),
290
+ * pluginSwr({ output: { path: './hooks' } }),
291
+ * ],
292
+ * })
293
+ * ```
294
+ */
295
+ export declare const pluginSwr: import("kubb/kit").PluginFactory<PluginSwr>;
296
+ //#endregion
297
+ //#region src/resolvers/resolverSwr.d.ts
298
+ /**
299
+ * Default resolver used by `@kubb/plugin-swr`. Decides the names and file paths for every generated
300
+ * SWR hook (`useFoo`, `useFooMutation`) and its companion helpers (`fooQueryKey`, `fooQueryOptions`,
301
+ * `fooMutationKey`).
302
+ *
303
+ * Functions and files use the built-in camelCase casing; hooks get the `use` prefix.
304
+ *
305
+ * @example Resolve hook and helper names
306
+ * ```ts
307
+ * import { resolverSwr } from '@kubb/plugin-swr'
308
+ *
309
+ * resolverSwr.query.name(operationNode) // 'useGetPetById'
310
+ * resolverSwr.query.keyName(operationNode) // 'getPetByIdQueryKey'
311
+ * resolverSwr.mutation.name(operationNode) // 'useUpdatePet'
312
+ * ```
313
+ */
314
+ export declare const resolverSwr: ResolverSwr;
315
+ //#endregion
316
+ export { type PluginSwr, type ResolverSwr, type Transformer, pluginSwr as default };
317
+ //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
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";
3
- import "@kubb/plugin-ts";
1
+ import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "kubb/kit";
4
2
  import "@kubb/plugin-zod";
3
+ import "@kubb/plugin-ts";
5
4
  import "kubb/jsx";
6
5
  //#region ../../internals/client/src/resolveClient.d.ts
7
6
  /**
@@ -36,6 +35,32 @@ type Transformer = (props: {
36
35
  variant: KeyVariant;
37
36
  }) => Array<unknown>;
38
37
  //#endregion
38
+ //#region ../../internals/tanstack-query/src/components/MutationKey.d.ts
39
+ /**
40
+ * Default `mutationKey` builder. Call it from a custom builder to extend the default key.
41
+ *
42
+ * @remarks The returned segments may change between releases. Spread them instead of reading single entries.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * mutationKey: (props) => [JSON.stringify(props.node.operationId), ...mutationKeyTransformer(props)]
47
+ * ```
48
+ */
49
+ export declare const mutationKeyTransformer: Transformer;
50
+ //#endregion
51
+ //#region ../../internals/tanstack-query/src/components/QueryKey.d.ts
52
+ /**
53
+ * Default `queryKey` builder. Call it from a custom builder to extend the default key.
54
+ *
55
+ * @remarks The returned segments may change between releases. Spread them instead of reading single entries.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * queryKey: (props) => [JSON.stringify(props.node.operationId), ...queryKeyTransformer(props)]
60
+ * ```
61
+ */
62
+ export declare const queryKeyTransformer: Transformer;
63
+ //#endregion
39
64
  //#region src/types.d.ts
40
65
  /**
41
66
  * The concrete resolver type for `@kubb/plugin-swr`.
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- import "./rolldown-runtime-C0LytTxp.js";
2
1
  import { Diagnostics, Resolver, Url, addGenerator, ast, createResolver, defineExtension, defineGenerator, setMacros, setResolver, useConfig } from "kubb/kit";
3
2
  import path from "node:path";
4
3
  import { createFunctionParameter, createFunctionParameters, createObjectBindingPattern, createTypeLiteral, functionPrinter, pluginTsName } from "@kubb/plugin-ts";
5
4
  import { File, Function, Type, jsxRenderer } from "kubb/jsx";
6
5
  import { Fragment, jsx, jsxs } from "kubb/jsx/jsx-runtime";
6
+ //#endregion
7
7
  //#region ../../internals/shared/src/operation.ts
8
8
  /**
9
9
  * Builds the `ResolverFileParams` every operation generator passes to
@@ -298,11 +298,11 @@ function createGroupConfig(group) {
298
298
  //#region kubb-extension.json
299
299
  var compatibility = {
300
300
  "kubb": ">=5.8.3",
301
- "node": ">=22"
301
+ "node": ">=22.12"
302
302
  };
303
303
  //#endregion
304
304
  //#region package.json
305
- var version = "5.4.1";
305
+ var version = "5.4.4";
306
306
  //#endregion
307
307
  //#region ../../internals/client/src/resolveClient.ts
308
308
  /**
@@ -785,6 +785,16 @@ function buildHookParams(node, options) {
785
785
  //#endregion
786
786
  //#region ../../internals/tanstack-query/src/components/MutationKey.tsx
787
787
  const declarationPrinter$4 = functionPrinter({ mode: "declaration" });
788
+ /**
789
+ * Default `mutationKey` builder. Call it from a custom builder to extend the default key.
790
+ *
791
+ * @remarks The returned segments may change between releases. Spread them instead of reading single entries.
792
+ *
793
+ * @example
794
+ * ```ts
795
+ * mutationKey: (props) => [JSON.stringify(props.node.operationId), ...mutationKeyTransformer(props)]
796
+ * ```
797
+ */
788
798
  const mutationKeyTransformer = ({ node }) => {
789
799
  if (!node.path) return [];
790
800
  return [`{ url: '${Url.toPath(node.path)}' }`];
@@ -876,6 +886,16 @@ function createMutationResolver() {
876
886
  //#endregion
877
887
  //#region ../../internals/tanstack-query/src/components/QueryKey.tsx
878
888
  const declarationPrinter$3 = functionPrinter({ mode: "declaration" });
889
+ /**
890
+ * Default `queryKey` builder. Call it from a custom builder to extend the default key.
891
+ *
892
+ * @remarks The returned segments may change between releases. Spread them instead of reading single entries.
893
+ *
894
+ * @example
895
+ * ```ts
896
+ * queryKey: (props) => [JSON.stringify(props.node.operationId), ...queryKeyTransformer(props)]
897
+ * ```
898
+ */
879
899
  const queryKeyTransformer = ({ node, variant }) => {
880
900
  if (!node.path) return [];
881
901
  const { path, query } = getOperationParameters(node);
@@ -1326,6 +1346,6 @@ const pluginSwr = defineExtension({
1326
1346
  }
1327
1347
  });
1328
1348
  //#endregion
1329
- export { pluginSwr as default, pluginSwr, pluginSwrName, resolverSwr };
1349
+ export { pluginSwr as default, pluginSwr, mutationKeyTransformer, pluginSwrName, queryKeyTransformer, resolverSwr };
1330
1350
 
1331
1351
  //# sourceMappingURL=index.js.map