@kubb/plugin-swr 5.4.1 → 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.
package/dist/index.cjs CHANGED
@@ -324,11 +324,11 @@ function createGroupConfig(group) {
324
324
  //#region kubb-extension.json
325
325
  var compatibility = {
326
326
  "kubb": ">=5.8.3",
327
- "node": ">=22"
327
+ "node": ">=22.12"
328
328
  };
329
329
  //#endregion
330
330
  //#region package.json
331
- var version = "5.4.1";
331
+ var version = "5.4.3";
332
332
  //#endregion
333
333
  //#region ../../internals/client/src/resolveClient.ts
334
334
  /**
@@ -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,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
  /**
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.3";
306
306
  //#endregion
307
307
  //#region ../../internals/client/src/resolveClient.ts
308
308
  /**
@@ -20,7 +20,7 @@
20
20
  "dependencies": ["plugin-ts"],
21
21
  "compatibility": {
22
22
  "kubb": ">=5.8.3",
23
- "node": ">=22"
23
+ "node": ">=22.12"
24
24
  },
25
25
  "role": "consumer",
26
26
  "options": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-swr",
3
- "version": "5.4.1",
3
+ "version": "5.4.3",
4
4
  "description": "Generate type-safe SWR hooks with Kubb. Covers useSWR and useSWRMutation with full TypeScript support.",
5
5
  "keywords": [
6
6
  "code-generation",
@@ -62,9 +62,14 @@
62
62
  },
63
63
  "exports": {
64
64
  ".": {
65
- "types": "./dist/index.d.ts",
66
- "import": "./dist/index.js",
67
- "require": "./dist/index.cjs"
65
+ "import": {
66
+ "types": "./dist/index.d.ts",
67
+ "default": "./dist/index.js"
68
+ },
69
+ "require": {
70
+ "types": "./dist/index.d.cts",
71
+ "default": "./dist/index.cjs"
72
+ }
68
73
  },
69
74
  "./package.json": "./package.json",
70
75
  "./kubb-extension.json": "./kubb-extension.json"
@@ -74,18 +79,18 @@
74
79
  "registry": "https://registry.npmjs.org/"
75
80
  },
76
81
  "dependencies": {
77
- "@kubb/plugin-ts": "^5.0.12"
82
+ "@kubb/plugin-ts": "^5.0.14"
78
83
  },
79
84
  "devDependencies": {
80
85
  "@internals/client": "0.0.0",
81
86
  "@internals/shared": "0.0.0",
82
87
  "@internals/tanstack-query": "0.0.0",
83
88
  "@internals/utils": "0.0.0",
84
- "kubb": "^5.10.2",
89
+ "kubb": "^5.10.3",
85
90
  "swr": "^2.5.1"
86
91
  },
87
92
  "peerDependencies": {
88
- "kubb": "^5.10.2",
93
+ "kubb": "^5.10.3",
89
94
  "swr": "^2.2.0"
90
95
  },
91
96
  "peerDependenciesMeta": {
@@ -94,7 +99,7 @@
94
99
  }
95
100
  },
96
101
  "engines": {
97
- "node": ">=22"
102
+ "node": ">=22.12"
98
103
  },
99
104
  "scripts": {
100
105
  "build": "tsdown",
@@ -1,8 +0,0 @@
1
- //#region \0rolldown/runtime.js
2
- var __defProp = Object.defineProperty;
3
- var __name = (target, value) => __defProp(target, "name", {
4
- value,
5
- configurable: true
6
- });
7
- //#endregion
8
- export { __name as t };