@kubb/plugin-swr 5.0.0-alpha.34 → 5.0.0-alpha.35

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.
Files changed (41) hide show
  1. package/dist/components-BJSzUg7M.cjs +955 -0
  2. package/dist/components-BJSzUg7M.cjs.map +1 -0
  3. package/dist/components-JQ2KRFCa.js +877 -0
  4. package/dist/components-JQ2KRFCa.js.map +1 -0
  5. package/dist/components.cjs +1 -1
  6. package/dist/components.d.ts +77 -37
  7. package/dist/components.js +1 -1
  8. package/dist/generators-17ulS9mu.cjs +537 -0
  9. package/dist/generators-17ulS9mu.cjs.map +1 -0
  10. package/dist/generators-Cl7nr-FB.js +526 -0
  11. package/dist/generators-Cl7nr-FB.js.map +1 -0
  12. package/dist/generators.cjs +1 -1
  13. package/dist/generators.d.ts +4 -4
  14. package/dist/generators.js +1 -1
  15. package/dist/index.cjs +132 -110
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.ts +22 -2
  18. package/dist/index.js +132 -110
  19. package/dist/index.js.map +1 -1
  20. package/dist/{types-BVDtH9S7.d.ts → types-FA5mH9Ch.d.ts} +46 -90
  21. package/package.json +7 -11
  22. package/src/components/Mutation.tsx +165 -170
  23. package/src/components/MutationKey.tsx +50 -1
  24. package/src/components/Query.tsx +122 -126
  25. package/src/components/QueryKey.tsx +65 -1
  26. package/src/components/QueryOptions.tsx +38 -93
  27. package/src/generators/mutationGenerator.tsx +194 -117
  28. package/src/generators/queryGenerator.tsx +205 -139
  29. package/src/plugin.ts +117 -152
  30. package/src/resolvers/resolverSwr.ts +26 -0
  31. package/src/resolvers/resolverSwrLegacy.ts +17 -0
  32. package/src/types.ts +55 -18
  33. package/src/utils.ts +209 -0
  34. package/dist/components-DaCTPplv.js +0 -756
  35. package/dist/components-DaCTPplv.js.map +0 -1
  36. package/dist/components-Qs8_faOt.cjs +0 -834
  37. package/dist/components-Qs8_faOt.cjs.map +0 -1
  38. package/dist/generators-0YayIrse.js +0 -400
  39. package/dist/generators-0YayIrse.js.map +0 -1
  40. package/dist/generators-Bd4rCa3l.cjs +0 -411
  41. package/dist/generators-Bd4rCa3l.cjs.map +0 -1
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["fetchClientSource","axiosClientSource","configSource"],"sources":["../package.json","../src/plugin.ts"],"sourcesContent":["","import path from 'node:path'\nimport { camelCase, pascalCase } from '@internals/utils'\nimport { createFile, createSource, createText } from '@kubb/ast'\nimport type { FileNode } from '@kubb/ast/types'\nimport { createPlugin, getBarrelFiles, type UserGroup } from '@kubb/core'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { source as axiosClientSource } from '@kubb/plugin-client/templates/clients/axios.source'\nimport { source as fetchClientSource } from '@kubb/plugin-client/templates/clients/fetch.source'\nimport { source as configSource } from '@kubb/plugin-client/templates/config.source'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { version } from '../package.json'\nimport { MutationKey, QueryKey } from './components'\nimport { mutationGenerator, queryGenerator } from './generators'\nimport type { PluginSwr } from './types.ts'\n\nexport const pluginSwrName = 'plugin-swr' satisfies PluginSwr['name']\n\nexport const pluginSwr = createPlugin<PluginSwr>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n transformers = {},\n query,\n mutation,\n client,\n paramsType = 'inline',\n pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',\n mutationKey = MutationKey.getTransformer,\n queryKey = QueryKey.getTransformer,\n generators = [queryGenerator, mutationGenerator].filter(Boolean),\n paramsCasing,\n contentType,\n } = options\n\n const clientName = client?.client ?? 'axios'\n const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)\n\n return {\n name: pluginSwrName,\n version,\n options: {\n output,\n client: {\n bundle: client?.bundle,\n baseURL: client?.baseURL,\n client: clientName,\n clientType: client?.clientType ?? 'function',\n importPath: clientImportPath,\n dataReturnType: client?.dataReturnType ?? 'data',\n paramsCasing,\n },\n queryKey,\n query:\n query === false\n ? false\n : {\n importPath: 'swr',\n methods: ['get'],\n ...query,\n },\n mutationKey,\n mutation:\n mutation === false\n ? false\n : {\n importPath: 'swr/mutation',\n methods: ['post', 'put', 'delete', 'patch'],\n ...mutation,\n },\n parser,\n paramsType,\n pathParamsType,\n paramsCasing,\n group,\n exclude,\n include,\n override,\n },\n pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = this.root\n const mode = pathMode ?? this.getMode(output)\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: UserGroup['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name)\n\n if (type === 'file' || type === 'function') {\n resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n }\n\n if (type === 'type') {\n resolvedName = pascalCase(name)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const root = this.root\n const mode = this.getMode(output)\n const oas = await this.getOas()\n const baseURL = await this.getBaseURL()\n\n if (baseURL) {\n this.plugin.options.client.baseURL = baseURL\n }\n\n const hasClientPlugin = !!this.getPlugin(pluginClientName)\n\n if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) {\n // pre add bundled fetch\n await this.upsertFile(\n createFile({\n baseName: 'fetch.ts',\n path: path.resolve(root, '.kubb/fetch.ts'),\n sources: [\n createSource({\n name: 'fetch',\n nodes: [createText(this.plugin.options.client.client === 'fetch' ? fetchClientSource : axiosClientSource)],\n isExportable: true,\n isIndexable: true,\n }),\n ],\n }),\n )\n }\n\n if (!hasClientPlugin) {\n await this.addFile(\n createFile({\n baseName: 'config.ts',\n path: path.resolve(root, '.kubb/config.ts'),\n sources: [\n createSource({\n name: 'config',\n nodes: [createText(configSource)],\n isExportable: false,\n isIndexable: false,\n }),\n ],\n }),\n )\n }\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n driver: this.driver,\n events: this.events,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.upsertFile(...files)\n\n const barrelFiles = await getBarrelFiles(this.driver.fileManager.files as unknown as FileNode[], {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginName: this.plugin.name,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;;;;ACiBA,MAAa,gBAAgB;AAE7B,MAAa,YAAY,cAAyB,YAAY;CAC5D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAS,YAAY;EAAS,EAC/C,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,SAAS,UACT,eAAe,EAAE,EACjB,OACA,UACA,QACA,aAAa,UACb,iBAAiB,eAAe,WAAW,WAAW,QAAQ,kBAAkB,UAChF,cAAc,YAAY,gBAC1B,WAAW,SAAS,gBACpB,aAAa,CAAC,gBAAgB,kBAAkB,CAAC,OAAO,QAAQ,EAChE,cACA,gBACE;CAEJ,MAAM,aAAa,QAAQ,UAAU;CACrC,MAAM,mBAAmB,QAAQ,eAAe,CAAC,QAAQ,SAAS,+BAA+B,eAAe,KAAA;AAE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AO,MACzB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
1
+ {"version":3,"file":"index.js","names":["fetchClientSource","axiosClientSource","configSource"],"sources":["../src/resolvers/resolverSwr.ts","../src/resolvers/resolverSwrLegacy.ts","../src/plugin.ts"],"sourcesContent":["import { camelCase } from '@internals/utils'\nimport { defineResolver } from '@kubb/core'\nimport type { PluginSwr } from '../types.ts'\n\n/**\n * Resolver for `@kubb/plugin-swr` that provides the default naming\n * and path-resolution helpers used by the plugin.\n *\n * @example\n * ```ts\n * import { resolverSwr } from '@kubb/plugin-swr'\n *\n * resolverSwr.default('list pets', 'function') // -> 'listPets'\n * resolverSwr.resolveName('show pet by id') // -> 'showPetById'\n * ```\n */\nexport const resolverSwr = defineResolver<PluginSwr>(() => ({\n name: 'default',\n pluginName: 'plugin-swr',\n default(name, type) {\n return camelCase(name, { isFile: type === 'file' })\n },\n resolveName(name) {\n return this.default(name, 'function')\n },\n}))\n","import { defineResolver } from '@kubb/core'\nimport type { PluginSwr } from '../types.ts'\nimport { resolverSwr } from './resolverSwr.ts'\n\n/**\n * Legacy resolver for `@kubb/plugin-swr` that reproduces the naming conventions\n * used in Kubb v4. Enable via `compatibilityPreset: 'kubbV4'`.\n *\n * The naming logic is identical to the default resolver — the only difference\n * is the `name` field (`'kubbV4'` vs `'default'`) so the driver can\n * distinguish presets.\n */\nexport const resolverSwrLegacy = defineResolver<PluginSwr>(() => ({\n ...resolverSwr,\n name: 'kubbV4',\n pluginName: 'plugin-swr',\n}))\n","import path from 'node:path'\nimport { camelCase } from '@internals/utils'\n\nimport { ast, definePlugin, type Group } from '@kubb/core'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { source as axiosClientSource } from '@kubb/plugin-client/templates/clients/axios.source'\nimport { source as fetchClientSource } from '@kubb/plugin-client/templates/clients/fetch.source'\nimport { source as configSource } from '@kubb/plugin-client/templates/config.source'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { MutationKey, QueryKey } from './components'\nimport { mutationGenerator, queryGenerator } from './generators'\nimport { resolverSwr } from './resolvers/resolverSwr.ts'\nimport { resolverSwrLegacy } from './resolvers/resolverSwrLegacy.ts'\nimport type { PluginSwr } from './types.ts'\n\n/**\n * Canonical plugin name for `@kubb/plugin-swr`, used to identify the plugin\n * in driver lookups and warnings.\n */\nexport const pluginSwrName = 'plugin-swr' satisfies PluginSwr['name']\n\n/**\n * The `@kubb/plugin-swr` plugin factory.\n *\n * Generates SWR hooks from an OpenAPI/AST `RootNode`.\n * Walks operations, delegates rendering to the active generators,\n * and writes barrel files based on `output.barrelType`.\n *\n * @example\n * ```ts\n * import { pluginSwr } from '@kubb/plugin-swr'\n *\n * export default defineConfig({\n * plugins: [pluginSwr({ output: { path: 'hooks' } })],\n * })\n * ```\n */\nexport const pluginSwr = definePlugin<PluginSwr>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n transformers = {},\n query,\n mutation,\n client,\n paramsType = 'inline',\n pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',\n mutationKey = MutationKey.getTransformer,\n queryKey = QueryKey.getTransformer,\n paramsCasing,\n resolver: userResolver,\n transformer: userTransformer,\n generators: userGenerators = [],\n compatibilityPreset = 'default',\n } = options\n\n const defaultResolver = compatibilityPreset === 'kubbV4' ? resolverSwrLegacy : resolverSwr\n\n const clientName = client?.client ?? 'axios'\n const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)\n\n const selectedGenerators = options.generators ?? [queryGenerator, mutationGenerator].filter(Boolean)\n\n const groupConfig = group\n ? ({\n ...group,\n name: group.name\n ? group.name\n : (ctx: { group: string }) => {\n if (group.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n },\n } satisfies Group)\n : undefined\n\n return {\n name: pluginSwrName,\n options,\n dependencies: [pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),\n hooks: {\n 'kubb:plugin:setup'(ctx) {\n const resolver = userResolver ? { ...defaultResolver, ...userResolver } : defaultResolver\n\n ctx.setOptions({\n output,\n transformers,\n client: {\n bundle: client?.bundle,\n baseURL: client?.baseURL,\n client: clientName,\n clientType: client?.clientType ?? 'function',\n importPath: clientImportPath,\n dataReturnType: client?.dataReturnType ?? 'data',\n paramsCasing,\n },\n queryKey,\n query:\n query === false\n ? false\n : {\n importPath: 'swr',\n methods: ['get'],\n ...query,\n },\n mutationKey,\n mutation:\n mutation === false\n ? false\n : {\n importPath: 'swr/mutation',\n methods: ['post', 'put', 'delete', 'patch'],\n ...mutation,\n },\n parser,\n paramsType,\n pathParamsType,\n paramsCasing,\n group: groupConfig,\n exclude,\n include,\n override,\n resolver,\n })\n ctx.setResolver(resolver)\n if (userTransformer) {\n ctx.setTransformer(userTransformer)\n }\n for (const gen of selectedGenerators) {\n ctx.addGenerator(gen)\n }\n for (const gen of userGenerators) {\n ctx.addGenerator(gen)\n }\n\n const root = path.resolve(ctx.config.root, ctx.config.output.path)\n\n const hasClientPlugin = !!ctx.config.plugins?.some((p) => (p as { name?: string }).name === pluginClientName)\n\n if (client?.bundle && !hasClientPlugin && !clientImportPath) {\n ctx.injectFile({\n baseName: 'fetch.ts',\n path: path.resolve(root, '.kubb/fetch.ts'),\n sources: [\n ast.createSource({\n name: 'fetch',\n nodes: [ast.createText(clientName === 'fetch' ? fetchClientSource : axiosClientSource)],\n isExportable: true,\n isIndexable: true,\n }),\n ],\n })\n }\n\n if (!hasClientPlugin) {\n ctx.injectFile({\n baseName: 'config.ts',\n path: path.resolve(root, '.kubb/config.ts'),\n sources: [\n ast.createSource({\n name: 'config',\n nodes: [ast.createText(configSource)],\n isExportable: false,\n isIndexable: false,\n }),\n ],\n })\n }\n },\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAgBA,MAAa,cAAc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WAAWC,SAAa,CAAC;KACrC,cAAc;KACd,aAAa;KACd,CAAC,CACH;IACF,CAAC;KAGP;EACF;EACD"}
@@ -1,83 +1,27 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { FunctionParams, Output, PluginFactoryOptions, ResolveNameParams, UserGroup } from "@kubb/core";
2
+ import { CompatibilityPreset, Exclude, Generator, Group, Include, Output, Override, PluginFactoryOptions, ResolvePathOptions, Resolver, UserGroup, ast } from "@kubb/core";
3
3
  import { ClientImportPath, PluginClient } from "@kubb/plugin-client";
4
- import { Exclude, Include, OperationSchemas, Override, ResolvePathOptions } from "@kubb/plugin-oas";
5
- import { HttpMethod, Oas, Operation, contentType } from "@kubb/oas";
6
- import { Generator } from "@kubb/plugin-oas/generators";
7
- import { KubbReactNode } from "@kubb/renderer-jsx/types";
8
4
 
9
- //#region ../../internals/tanstack-query/src/types.d.ts
10
- type ParamsCasing = 'camelcase' | undefined;
11
- type PathParamsType = 'object' | 'inline';
12
- type TransformerProps = {
13
- operation: Operation;
14
- schemas: OperationSchemas;
15
- casing: ParamsCasing;
16
- };
17
- type Transformer = (props: TransformerProps) => unknown[];
18
- //#endregion
19
- //#region ../../internals/tanstack-query/src/components/MutationKey.d.ts
20
- type Props$1 = {
21
- name: string;
22
- typeName: string;
23
- typeSchemas: OperationSchemas;
24
- operation: Operation;
25
- paramsCasing: ParamsCasing;
26
- pathParamsType: PathParamsType;
27
- transformer: Transformer | undefined;
28
- };
29
- type GetParamsProps$1 = {
30
- pathParamsType: PathParamsType;
31
- typeSchemas: OperationSchemas;
32
- };
33
- declare function MutationKey$1({
34
- name,
35
- typeSchemas,
36
- pathParamsType,
37
- paramsCasing,
38
- operation,
39
- typeName,
40
- transformer
41
- }: Props$1): KubbReactNode;
42
- declare namespace MutationKey$1 {
43
- var getParams: ({}: GetParamsProps$1) => FunctionParams;
44
- var getTransformer: Transformer;
45
- }
46
- //#endregion
47
- //#region ../../internals/tanstack-query/src/components/QueryKey.d.ts
48
- type Props = {
49
- name: string;
50
- typeName: string;
51
- typeSchemas: OperationSchemas;
52
- operation: Operation;
53
- paramsCasing: ParamsCasing;
54
- pathParamsType: PathParamsType;
55
- transformer: Transformer | undefined;
56
- };
57
- type GetParamsProps = {
58
- paramsCasing: ParamsCasing;
59
- pathParamsType: PathParamsType;
60
- typeSchemas: OperationSchemas;
61
- };
62
- declare function QueryKey$1({
63
- name,
64
- typeSchemas,
65
- paramsCasing,
66
- pathParamsType,
67
- operation,
68
- typeName,
69
- transformer
70
- }: Props): KubbReactNode;
71
- declare namespace QueryKey$1 {
72
- var getParams: ({
73
- pathParamsType,
74
- paramsCasing,
75
- typeSchemas
76
- }: GetParamsProps) => FunctionParams;
77
- var getTransformer: Transformer;
78
- }
79
- //#endregion
80
5
  //#region src/types.d.ts
6
+ /**
7
+ * Customizes how queryKey or mutationKey arrays are built.
8
+ */
9
+ type Transformer = (props: {
10
+ node: ast.OperationNode;
11
+ casing: 'camelcase' | undefined;
12
+ }) => unknown[];
13
+ /**
14
+ * The concrete resolver type for `@kubb/plugin-swr`.
15
+ * Extends the base `Resolver` with a `resolveName` helper for hook function names.
16
+ */
17
+ type ResolverSwr = Resolver & {
18
+ /**
19
+ * Resolves the hook function name for a given raw operation name.
20
+ * @example
21
+ * resolver.resolveName('show pet by id') // -> 'showPetById'
22
+ */
23
+ resolveName(this: ResolverSwr, name: string): string;
24
+ };
81
25
  /**
82
26
  * Customize the queryKey
83
27
  */
@@ -91,7 +35,7 @@ type Query = {
91
35
  * Define which HttpMethods can be used for queries
92
36
  * @default ['get']
93
37
  */
94
- methods?: Array<HttpMethod>;
38
+ methods?: Array<string>;
95
39
  /**
96
40
  * Path to the useQuery hook for useQuery functionality.
97
41
  * Used as `import { useQuery } from '${importPath}'`.
@@ -106,7 +50,7 @@ type Mutation = {
106
50
  * Define which HttpMethods can be used for queries
107
51
  * @default ['post', 'put', 'delete', 'patch']
108
52
  */
109
- methods?: Array<HttpMethod>;
53
+ methods?: Array<string>;
110
54
  /**
111
55
  * Path to the useQuery hook for useQuery functionality.
112
56
  * Used as `import { useQuery } from '${importPath}'`.
@@ -128,12 +72,7 @@ type Options = {
128
72
  * Specify the export location for the files and define the behavior of the output
129
73
  * @default { path: 'hooks', barrelType: 'named' }
130
74
  */
131
- output?: Output<Oas>;
132
- /**
133
- * Define which contentType should be used.
134
- * By default, the first JSON valid mediaType is used
135
- */
136
- contentType?: contentType;
75
+ output?: Output;
137
76
  /**
138
77
  * Group the SWR hooks based on the provided name.
139
78
  */
@@ -183,15 +122,30 @@ type Options = {
183
122
  /**
184
123
  * Customize the names based on the type that is provided by the plugin.
185
124
  */
186
- name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
125
+ name?: (name: string, type?: string) => string;
187
126
  };
127
+ /**
128
+ * Apply a compatibility naming preset.
129
+ * @default 'default'
130
+ */
131
+ compatibilityPreset?: CompatibilityPreset;
132
+ /**
133
+ * Override individual resolver methods. Any method you omit falls back to the
134
+ * preset resolver's implementation. Use `this.default(...)` to call it.
135
+ */
136
+ resolver?: Partial<ResolverSwr> & ThisType<ResolverSwr>;
137
+ /**
138
+ * Single AST visitor applied to each node before printing.
139
+ * Return `null` or `undefined` from a method to leave the node unchanged.
140
+ */
141
+ transformer?: ast.Visitor;
188
142
  /**
189
143
  * Define some generators next to the swr generators
190
144
  */
191
145
  generators?: Array<Generator<PluginSwr>>;
192
146
  };
193
147
  type ResolvedOptions = {
194
- output: Output<Oas>;
148
+ output: Output;
195
149
  client: Pick<PluginClient['options'], 'client' | 'clientType' | 'dataReturnType' | 'importPath' | 'baseURL' | 'bundle' | 'paramsCasing'>;
196
150
  parser: Required<NonNullable<Options['parser']>>;
197
151
  queryKey: QueryKey | undefined;
@@ -201,12 +155,14 @@ type ResolvedOptions = {
201
155
  paramsCasing: Options['paramsCasing'];
202
156
  paramsType: NonNullable<Options['paramsType']>;
203
157
  pathParamsType: NonNullable<Options['pathParamsType']>;
204
- group: Options['group'];
158
+ transformers: NonNullable<Options['transformers']>;
159
+ group: Group | undefined;
205
160
  exclude: NonNullable<Options['exclude']>;
206
161
  include: Options['include'];
207
162
  override: NonNullable<Options['override']>;
163
+ resolver: ResolverSwr;
208
164
  };
209
- type PluginSwr = PluginFactoryOptions<'plugin-swr', Options, ResolvedOptions, never, ResolvePathOptions>;
165
+ type PluginSwr = PluginFactoryOptions<'plugin-swr', Options, ResolvedOptions, never, ResolvePathOptions, ResolverSwr>;
210
166
  declare global {
211
167
  namespace Kubb {
212
168
  interface PluginRegistry {
@@ -215,5 +171,5 @@ declare global {
215
171
  }
216
172
  }
217
173
  //#endregion
218
- export { MutationKey$1 as i, PluginSwr as n, QueryKey$1 as r, Options as t };
219
- //# sourceMappingURL=types-BVDtH9S7.d.ts.map
174
+ export { PluginSwr as n, Transformer as r, Options as t };
175
+ //# sourceMappingURL=types-FA5mH9Ch.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-swr",
3
- "version": "5.0.0-alpha.34",
3
+ "version": "5.0.0-alpha.35",
4
4
  "description": "SWR hooks generator plugin for Kubb, creating type-safe data fetching hooks from OpenAPI specifications for React and Next.js applications.",
5
5
  "keywords": [
6
6
  "swr",
@@ -75,17 +75,14 @@
75
75
  ],
76
76
  "dependencies": {
77
77
  "remeda": "^2.33.7",
78
- "@kubb/ast": "5.0.0-alpha.34",
79
- "@kubb/core": "5.0.0-alpha.34",
80
- "@kubb/oas": "5.0.0-alpha.34",
81
- "@kubb/plugin-client": "5.0.0-alpha.34",
82
- "@kubb/plugin-oas": "5.0.0-alpha.34",
83
- "@kubb/plugin-ts": "5.0.0-alpha.34",
84
- "@kubb/plugin-zod": "5.0.0-alpha.34",
85
- "@kubb/renderer-jsx": "5.0.0-alpha.34"
78
+ "@kubb/core": "5.0.0-alpha.35",
79
+ "@kubb/plugin-client": "5.0.0-alpha.35",
80
+ "@kubb/plugin-ts": "5.0.0-alpha.35",
81
+ "@kubb/plugin-zod": "5.0.0-alpha.35",
82
+ "@kubb/renderer-jsx": "5.0.0-alpha.35"
86
83
  },
87
84
  "peerDependencies": {
88
- "@kubb/renderer-jsx": "5.0.0-alpha.34"
85
+ "@kubb/renderer-jsx": "5.0.0-alpha.35"
89
86
  },
90
87
  "engines": {
91
88
  "node": ">=22"
@@ -97,7 +94,6 @@
97
94
  "main": "./dist/index.cjs",
98
95
  "module": "./dist/index.js",
99
96
  "devDependencies": {
100
- "@internals/tanstack-query": "0.0.0",
101
97
  "@internals/utils": "0.0.0"
102
98
  },
103
99
  "scripts": {