@kubb/plugin-swr 3.0.0-alpha.9 → 3.0.0-beta.2

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 (61) hide show
  1. package/README.md +14 -5
  2. package/dist/chunk-4EGGCGSE.js +217 -0
  3. package/dist/chunk-4EGGCGSE.js.map +1 -0
  4. package/dist/chunk-H23WKEYP.js +243 -0
  5. package/dist/chunk-H23WKEYP.js.map +1 -0
  6. package/dist/chunk-JWGWABV5.cjs +249 -0
  7. package/dist/chunk-JWGWABV5.cjs.map +1 -0
  8. package/dist/chunk-PTOQHHST.cjs +220 -0
  9. package/dist/chunk-PTOQHHST.cjs.map +1 -0
  10. package/dist/components.cjs +23 -6
  11. package/dist/components.cjs.map +1 -1
  12. package/dist/components.d.cts +88 -6
  13. package/dist/components.d.ts +88 -6
  14. package/dist/components.js +2 -10
  15. package/dist/components.js.map +1 -1
  16. package/dist/generators.cjs +17 -0
  17. package/dist/generators.cjs.map +1 -0
  18. package/dist/generators.d.cts +11 -0
  19. package/dist/generators.d.ts +11 -0
  20. package/dist/generators.js +4 -0
  21. package/dist/generators.js.map +1 -0
  22. package/dist/index.cjs +93 -123
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +2 -4
  25. package/dist/index.d.ts +2 -4
  26. package/dist/index.js +77 -114
  27. package/dist/index.js.map +1 -1
  28. package/dist/types-DaH2Sc1M.d.cts +103 -0
  29. package/dist/types-DaH2Sc1M.d.ts +103 -0
  30. package/package.json +23 -17
  31. package/src/components/Mutation.tsx +93 -227
  32. package/src/components/MutationKey.tsx +48 -0
  33. package/src/components/Query.tsx +93 -259
  34. package/src/components/QueryKey.tsx +73 -0
  35. package/src/components/QueryOptions.tsx +54 -177
  36. package/src/components/index.ts +2 -0
  37. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +43 -0
  38. package/src/generators/__snapshots__/clientGetImportPath.ts +43 -0
  39. package/src/generators/__snapshots__/clientPostImportPath.ts +32 -0
  40. package/src/generators/__snapshots__/findByTags.ts +43 -0
  41. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +43 -0
  42. package/src/generators/__snapshots__/findByTagsWithZod.ts +43 -0
  43. package/src/generators/__snapshots__/getAsMutation.ts +34 -0
  44. package/src/generators/__snapshots__/postAsQuery.ts +41 -0
  45. package/src/generators/__snapshots__/updatePetById.ts +32 -0
  46. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +36 -0
  47. package/src/generators/index.ts +2 -0
  48. package/src/generators/mutationGenerator.tsx +109 -0
  49. package/src/generators/queryGenerator.tsx +114 -0
  50. package/src/plugin.ts +71 -52
  51. package/src/types.ts +62 -78
  52. package/dist/chunk-TGLXUPN4.cjs +0 -536
  53. package/dist/chunk-TGLXUPN4.cjs.map +0 -1
  54. package/dist/chunk-XWXMQJD6.js +0 -536
  55. package/dist/chunk-XWXMQJD6.js.map +0 -1
  56. package/dist/index-B3C-JOIU.d.cts +0 -299
  57. package/dist/index-B3C-JOIU.d.ts +0 -299
  58. package/src/OperationGenerator.tsx +0 -75
  59. package/src/components/SchemaType.tsx +0 -63
  60. package/src/components/__snapshots__/Mutation/Pets.ts +0 -46
  61. package/src/components/__snapshots__/Query/showPetById.ts +0 -59
@@ -0,0 +1,109 @@
1
+ import transformers from '@kubb/core/transformers'
2
+ import { pluginClientName } from '@kubb/plugin-client'
3
+ import { Client } from '@kubb/plugin-client/components'
4
+ import { createReactGenerator } from '@kubb/plugin-oas'
5
+ import { useOperationManager } from '@kubb/plugin-oas/hooks'
6
+ import { pluginTsName } from '@kubb/plugin-ts'
7
+ import { pluginZodName } from '@kubb/plugin-zod'
8
+ import { File, useApp } from '@kubb/react'
9
+ import { MutationKey } from '../components'
10
+ import { Mutation } from '../components'
11
+ import type { PluginSwr } from '../types'
12
+
13
+ export const mutationGenerator = createReactGenerator<PluginSwr>({
14
+ name: 'swr-mutation',
15
+ Operation({ options, operation }) {
16
+ const {
17
+ plugin: {
18
+ options: { output },
19
+ },
20
+ } = useApp<PluginSwr>()
21
+ const { getSchemas, getName, getFile } = useOperationManager()
22
+
23
+ const isMutate = typeof options.query === 'boolean' ? options.mutation : !!options.mutation.methods?.some((method) => operation.method === method)
24
+
25
+ const mutation = {
26
+ name: getName(operation, { type: 'function', prefix: 'use' }),
27
+ typeName: getName(operation, { type: 'type' }),
28
+ file: getFile(operation, { prefix: 'use' }),
29
+ }
30
+
31
+ const type = {
32
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
33
+ //todo remove type?
34
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
35
+ }
36
+
37
+ const zod = {
38
+ file: getFile(operation, { pluginKey: [pluginZodName] }),
39
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
40
+ }
41
+
42
+ const client = {
43
+ name: getName(operation, { type: 'function', pluginKey: [pluginClientName] }),
44
+ }
45
+
46
+ const mutationKey = {
47
+ name: getName(operation, { type: 'const', suffix: 'MutationKey' }),
48
+ typeName: getName(operation, { type: 'type', suffix: 'MutationKey' }),
49
+ }
50
+
51
+ if (!isMutate) {
52
+ return null
53
+ }
54
+
55
+ return (
56
+ <File baseName={mutation.file.baseName} path={mutation.file.path} meta={mutation.file.meta} banner={output?.banner} footer={output?.footer}>
57
+ {options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={mutation.file.path} path={zod.file.path} />}
58
+ <File.Import name="useSWRMutation" path={options.mutation.importPath} />
59
+ <File.Import name={['SWRMutationResponse']} path={options.mutation.importPath} isTypeOnly />
60
+ <File.Import name={'client'} path={options.client.importPath} />
61
+ <File.Import name={['RequestConfig', 'ResponseConfig']} path={options.client.importPath} isTypeOnly />
62
+ <File.Import
63
+ name={[
64
+ type.schemas.request?.name,
65
+ type.schemas.response.name,
66
+ type.schemas.pathParams?.name,
67
+ type.schemas.queryParams?.name,
68
+ type.schemas.headerParams?.name,
69
+ ...(type.schemas.statusCodes?.map((item) => item.name) || []),
70
+ ].filter(Boolean)}
71
+ root={mutation.file.path}
72
+ path={type.file.path}
73
+ isTypeOnly
74
+ />
75
+ <MutationKey
76
+ name={mutationKey.name}
77
+ typeName={mutationKey.typeName}
78
+ operation={operation}
79
+ pathParamsType={options.pathParamsType}
80
+ typeSchemas={type.schemas}
81
+ keysFn={options.mutation.key}
82
+ />
83
+ <Client
84
+ name={client.name}
85
+ isExportable={false}
86
+ isIndexable={false}
87
+ baseURL={options.baseURL}
88
+ operation={operation}
89
+ typeSchemas={type.schemas}
90
+ zodSchemas={zod.schemas}
91
+ dataReturnType={options.client.dataReturnType}
92
+ pathParamsType={options.pathParamsType}
93
+ parser={options.parser}
94
+ />
95
+ <Mutation
96
+ name={mutation.name}
97
+ clientName={client.name}
98
+ typeName={mutation.typeName}
99
+ typeSchemas={type.schemas}
100
+ operation={operation}
101
+ dataReturnType={options.client.dataReturnType}
102
+ pathParamsType={options.pathParamsType}
103
+ mutationKeyName={mutationKey.name}
104
+ mutationKeyTypeName={mutationKey.typeName}
105
+ />
106
+ </File>
107
+ )
108
+ },
109
+ })
@@ -0,0 +1,114 @@
1
+ import transformers from '@kubb/core/transformers'
2
+ import { pluginClientName } from '@kubb/plugin-client'
3
+ import { Client } from '@kubb/plugin-client/components'
4
+ import { createReactGenerator } from '@kubb/plugin-oas'
5
+ import { useOperationManager } from '@kubb/plugin-oas/hooks'
6
+ import { pluginTsName } from '@kubb/plugin-ts'
7
+ import { pluginZodName } from '@kubb/plugin-zod'
8
+ import { File, useApp } from '@kubb/react'
9
+ import { Query, QueryOptions } from '../components'
10
+ import { QueryKey } from '../components'
11
+ import type { PluginSwr } from '../types'
12
+
13
+ export const queryGenerator = createReactGenerator<PluginSwr>({
14
+ name: 'swr-query',
15
+ Operation({ options, operation }) {
16
+ const {
17
+ plugin: {
18
+ options: { output },
19
+ },
20
+ } = useApp<PluginSwr>()
21
+ const { getSchemas, getName, getFile } = useOperationManager()
22
+
23
+ const isQuery = typeof options.query === 'boolean' ? options.query : !!options.query.methods?.some((method) => operation.method === method)
24
+
25
+ const query = {
26
+ name: getName(operation, { type: 'function', prefix: 'use' }),
27
+ typeName: getName(operation, { type: 'type' }),
28
+ file: getFile(operation, { prefix: 'use' }),
29
+ }
30
+
31
+ const client = {
32
+ name: getName(operation, { type: 'function', pluginKey: [pluginClientName] }),
33
+ }
34
+
35
+ const queryOptions = {
36
+ name: getName(operation, { type: 'function', suffix: 'QueryOptions' }),
37
+ }
38
+ const queryKey = {
39
+ name: getName(operation, { type: 'const', suffix: 'QueryKey' }),
40
+ typeName: getName(operation, { type: 'type', suffix: 'QueryKey' }),
41
+ }
42
+
43
+ const type = {
44
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
45
+ //todo remove type?
46
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
47
+ }
48
+
49
+ const zod = {
50
+ file: getFile(operation, { pluginKey: [pluginZodName] }),
51
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
52
+ }
53
+
54
+ if (!isQuery) {
55
+ return null
56
+ }
57
+
58
+ return (
59
+ <File baseName={query.file.baseName} path={query.file.path} meta={query.file.meta} banner={output?.banner} footer={output?.footer}>
60
+ {options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={query.file.path} path={zod.file.path} />}
61
+ <File.Import name="useSWR" path={options.query.importPath} />
62
+ <File.Import name={['SWRResponse']} path={options.query.importPath} isTypeOnly />
63
+ <File.Import name={'client'} path={options.client.importPath} />
64
+ <File.Import name={['RequestConfig']} path={options.client.importPath} isTypeOnly />
65
+ {options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}
66
+
67
+ <File.Import
68
+ name={[
69
+ type.schemas.request?.name,
70
+ type.schemas.response.name,
71
+ type.schemas.pathParams?.name,
72
+ type.schemas.queryParams?.name,
73
+ type.schemas.headerParams?.name,
74
+ ...(type.schemas.statusCodes?.map((item) => item.name) || []),
75
+ ].filter(Boolean)}
76
+ root={query.file.path}
77
+ path={type.file.path}
78
+ isTypeOnly
79
+ />
80
+ <QueryKey
81
+ name={queryKey.name}
82
+ typeName={queryKey.typeName}
83
+ operation={operation}
84
+ pathParamsType={options.pathParamsType}
85
+ typeSchemas={type.schemas}
86
+ keysFn={options.query.key}
87
+ />
88
+ <Client
89
+ name={client.name}
90
+ isExportable={false}
91
+ isIndexable={false}
92
+ baseURL={options.baseURL}
93
+ operation={operation}
94
+ typeSchemas={type.schemas}
95
+ zodSchemas={zod.schemas}
96
+ dataReturnType={options.client.dataReturnType}
97
+ pathParamsType={options.pathParamsType}
98
+ parser={options.parser}
99
+ />
100
+ <QueryOptions name={queryOptions.name} clientName={client.name} typeSchemas={type.schemas} pathParamsType={options.pathParamsType} />
101
+ <Query
102
+ name={query.name}
103
+ queryOptionsName={queryOptions.name}
104
+ typeSchemas={type.schemas}
105
+ pathParamsType={options.pathParamsType}
106
+ operation={operation}
107
+ dataReturnType={options.client.dataReturnType}
108
+ queryKeyName={queryKey.name}
109
+ queryKeyTypeName={queryKey.typeName}
110
+ />
111
+ </File>
112
+ )
113
+ },
114
+ })
package/src/plugin.ts CHANGED
@@ -1,52 +1,72 @@
1
1
  import path from 'node:path'
2
2
 
3
- import { FileManager, PluginManager, createPlugin } from '@kubb/core'
3
+ import { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'
4
4
  import { camelCase, pascalCase } from '@kubb/core/transformers'
5
5
  import { renderTemplate } from '@kubb/core/utils'
6
- import { pluginOasName } from '@kubb/plugin-oas'
6
+ import { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'
7
7
 
8
8
  import { pluginTsName } from '@kubb/plugin-ts'
9
9
  import { pluginZodName } from '@kubb/plugin-zod'
10
10
 
11
- import { OperationGenerator } from './OperationGenerator.tsx'
12
- import { Mutation, Query, QueryOptions } from './components/index.ts'
13
-
14
11
  import type { Plugin } from '@kubb/core'
15
12
  import type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'
13
+ import { mutationGenerator, queryGenerator } from './generators'
16
14
  import type { PluginSwr } from './types.ts'
17
15
 
18
16
  export const pluginSwrName = 'plugin-swr' satisfies PluginSwr['name']
19
17
 
20
18
  export const pluginSwr = createPlugin<PluginSwr>((options) => {
21
- const { output = { path: 'hooks' }, group, exclude = [], include, override = [], parser, transformers = {}, templates, dataReturnType = 'data' } = options
22
- const template = group?.output ? group.output : `${output.path}/{{tag}}SWRController`
19
+ const {
20
+ output = { path: 'hooks', barrelType: 'named' },
21
+ group,
22
+ exclude = [],
23
+ include,
24
+ override = [],
25
+ parser = 'client',
26
+ transformers = {},
27
+ query,
28
+ mutation,
29
+ client,
30
+ pathParamsType = 'inline',
31
+ generators = [queryGenerator, mutationGenerator].filter(Boolean),
32
+ } = options
23
33
 
24
34
  return {
25
35
  name: pluginSwrName,
26
- output: {
27
- exportType: 'barrelNamed',
28
- ...output,
29
- },
30
36
  options: {
31
- extName: output.extName,
32
- templates: {
33
- mutation: Mutation.templates,
34
- query: Query.templates,
35
- queryOptions: QueryOptions.templates,
36
- ...templates,
37
- },
37
+ output,
38
+ pathParamsType,
38
39
  client: {
39
40
  importPath: '@kubb/plugin-client/client',
40
- ...options.client,
41
+ dataReturnType: 'data',
42
+ ...client,
43
+ },
44
+ query: {
45
+ key: (key: unknown[]) => key,
46
+ importPath: 'swr',
47
+ methods: ['get'],
48
+ ...query,
49
+ },
50
+ mutation: {
51
+ key: (key: unknown[]) => key,
52
+ importPath: 'swr/mutation',
53
+ methods: ['post', 'put', 'delete', 'patch'],
54
+ ...mutation,
41
55
  },
42
- dataReturnType,
43
56
  parser,
57
+ baseURL: undefined,
44
58
  },
45
59
  pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),
46
60
  resolvePath(baseName, pathMode, options) {
47
61
  const root = path.resolve(this.config.root, this.config.output.path)
48
62
  const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))
49
63
 
64
+ if (options?.tag && group?.type === 'tag') {
65
+ const groupName: Group['name'] = group?.name ? group.name : (ctx) => `${ctx.group}Controller`
66
+
67
+ return path.resolve(root, output.path, groupName({ group: camelCase(options.tag) }), baseName)
68
+ }
69
+
50
70
  if (mode === 'single') {
51
71
  /**
52
72
  * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
@@ -55,12 +75,6 @@ export const pluginSwr = createPlugin<PluginSwr>((options) => {
55
75
  return path.resolve(root, output.path)
56
76
  }
57
77
 
58
- if (options?.tag && group?.type === 'tag') {
59
- const tag = camelCase(options.tag)
60
-
61
- return path.resolve(root, renderTemplate(template, { tag }), baseName)
62
- }
63
-
64
78
  return path.resolve(root, output.path, baseName)
65
79
  },
66
80
  resolveName(name, type) {
@@ -68,7 +82,6 @@ export const pluginSwr = createPlugin<PluginSwr>((options) => {
68
82
 
69
83
  if (type === 'file' || type === 'function') {
70
84
  resolvedName = camelCase(name, {
71
- prefix: 'use',
72
85
  isFile: type === 'file',
73
86
  })
74
87
  }
@@ -89,34 +102,40 @@ export const pluginSwr = createPlugin<PluginSwr>((options) => {
89
102
  const oas = await swaggerPlugin.context.getOas()
90
103
  const root = path.resolve(this.config.root, this.config.output.path)
91
104
  const mode = FileManager.getMode(path.resolve(root, output.path))
92
-
93
- const operationGenerator = new OperationGenerator(this.plugin.options, {
94
- oas,
95
- pluginManager: this.pluginManager,
96
- plugin: this.plugin,
97
- contentType: swaggerPlugin.context.contentType,
98
- exclude,
99
- include,
100
- override,
101
- mode,
102
- })
103
-
104
- const files = await operationGenerator.build()
105
+ const baseURL = await swaggerPlugin.context.getBaseURL()
106
+
107
+ const operationGenerator = new OperationGenerator(
108
+ {
109
+ ...this.plugin.options,
110
+ baseURL,
111
+ },
112
+ {
113
+ oas,
114
+ pluginManager: this.pluginManager,
115
+ plugin: this.plugin,
116
+ contentType: swaggerPlugin.context.contentType,
117
+ exclude,
118
+ include,
119
+ override,
120
+ mode,
121
+ },
122
+ )
123
+
124
+ const files = await operationGenerator.build(...generators)
105
125
  await this.addFile(...files)
106
126
 
107
- if (this.config.output.exportType) {
108
- const barrelFiles = await this.fileManager.getBarrelFiles({
109
- root,
110
- output,
111
- files: this.fileManager.files,
112
- meta: {
113
- pluginKey: this.plugin.key,
114
- },
115
- logger: this.logger,
116
- })
127
+ const barrelFiles = await this.fileManager.getBarrelFiles({
128
+ type: output.barrelType ?? 'named',
129
+ root,
130
+ output,
131
+ files: this.fileManager.files,
132
+ meta: {
133
+ pluginKey: this.plugin.key,
134
+ },
135
+ logger: this.logger,
136
+ })
117
137
 
118
- await this.addFile(...barrelFiles)
119
- }
138
+ await this.addFile(...barrelFiles)
120
139
  },
121
140
  }
122
141
  })
package/src/types.ts CHANGED
@@ -1,59 +1,17 @@
1
- import type { Plugin, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
2
- import type * as KubbFile from '@kubb/fs/types'
3
- import type { Exclude, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
4
- import type { Mutation } from './components/Mutation.tsx'
5
- import type { Query } from './components/Query.tsx'
6
- import type { QueryOptions } from './components/QueryOptions.tsx'
7
-
8
- type Templates = {
9
- mutation?: typeof Mutation.templates | false
10
- query?: typeof Query.templates | false
11
- queryOptions?: typeof QueryOptions.templates | false
12
- }
1
+ import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
2
+ import type { HttpMethod } from '@kubb/oas'
3
+ import type { PluginClient } from '@kubb/plugin-client'
4
+ import type { Exclude, Generator, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
13
5
 
14
6
  export type Options = {
15
- output?: {
16
- /**
17
- * Output to save the SWR hooks.
18
- * @default `"hooks"`
19
- */
20
- path: string
21
- /**
22
- * Name to be used for the `export * as {{exportAs}} from './'`
23
- */
24
- exportAs?: string
25
- /**
26
- * Add an extension to the generated imports and exports, default it will not use an extension
27
- */
28
- extName?: KubbFile.Extname
29
- /**
30
- * Define what needs to exported, here you can also disable the export of barrel files
31
- * @default `'barrel'`
32
- */
33
- exportType?: 'barrel' | 'barrelNamed' | false
34
- }
7
+ /**
8
+ * @default 'hooks'
9
+ */
10
+ output?: Output
35
11
  /**
36
12
  * Group the SWR hooks based on the provided name.
37
13
  */
38
- group?: {
39
- /**
40
- * Tag will group based on the operation tag inside the Swagger file
41
- */
42
- type: 'tag'
43
- /**
44
- * Relative path to save the grouped SWR hooks.
45
- *
46
- * `{{tag}}` will be replaced by the current tagName.
47
- * @example `${output}/{{tag}}Controller` => `hooks/PetController`
48
- * @default `${output}/{{tag}}Controller`
49
- */
50
- output?: string
51
- /**
52
- * Name to be used for the `export * as {{exportAs}} from './`
53
- * @default `"{{tag}}SWRHooks"`
54
- */
55
- exportAs?: string
56
- }
14
+ group?: Group
57
15
  /**
58
16
  * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
59
17
  */
@@ -66,26 +24,60 @@ export type Options = {
66
24
  * Array containing override parameters to override `options` based on tags/operations/methods/paths.
67
25
  */
68
26
  override?: Array<Override<ResolvedOptions>>
69
- client?: {
27
+ client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath'>
28
+ query?: {
70
29
  /**
71
- * Path to the client import path that will be used to do the API calls.
72
- * It will be used as `import client from '${client.importPath}'`.
73
- * It allow both relative and absolute path.
74
- * the path will be applied as is, so relative path shoule be based on the file being generated.
75
- * @default '@kubb/plugin-client/client'
30
+ * Customize the queryKey, here you can specify a suffix.
31
+ */
32
+ key: (key: unknown[]) => unknown[]
33
+ /**
34
+ * Define which HttpMethods can be used for queries
35
+ * @default ['get']
36
+ */
37
+ methods?: Array<HttpMethod>
38
+ /**
39
+ * Path to the useQuery that will be used to do the useQuery functionality.
40
+ * It will be used as `import { useQuery } from '${importPath}'`.
41
+ * It allows both relative and absolute path.
42
+ * the path will be applied as is, so relative path should be based on the file being generated.
43
+ * @default '@tanstack/react-query' if 'framework' is set to 'react'
44
+ */
45
+ importPath?: string
46
+ }
47
+ mutation?: {
48
+ /**
49
+ * Customize the queryKey, here you can specify a suffix.
50
+ */
51
+ key: (key: unknown[]) => unknown[]
52
+ /**
53
+ * Define which HttpMethods can be used for queries
54
+ * @default ['post', 'put', 'delete', 'patch']
55
+ */
56
+ methods?: Array<HttpMethod>
57
+ /**
58
+ * Path to the useQuery that will be used to do the useQuery functionality.
59
+ * It will be used as `import { useQuery } from '${importPath}'`.
60
+ * It allows both relative and absolute path.
61
+ * the path will be applied as is, so relative path should be based on the file being generated.
62
+ * @default '@tanstack/react-query' if 'framework' is set to 'react'
76
63
  */
77
64
  importPath?: string
78
65
  }
79
66
  /**
80
- * ReturnType that needs to be used when calling client().
67
+ * How to pass your pathParams.
81
68
  *
82
- * `Data` will return ResponseConfig[data].
69
+ * `object` will return the pathParams as an object.
83
70
  *
84
- * `Full` will return ResponseConfig.
85
- * @default `'data'`
71
+ * `inline` will return the pathParams as comma separated params.
72
+ * @default `'inline'`
86
73
  * @private
87
74
  */
88
- dataReturnType?: 'data' | 'full'
75
+ pathParamsType?: PluginClient['options']['pathParamsType']
76
+ /**
77
+ * Which parser can be used before returning the data to `swr`.
78
+ * `'zod'` will use `@kubb/plugin-zod` to parse the data.
79
+ */
80
+ parser?: PluginClient['options']['parser']
89
81
  transformers?: {
90
82
  /**
91
83
  * Customize the names based on the type that is provided by the plugin.
@@ -93,27 +85,19 @@ export type Options = {
93
85
  name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
94
86
  }
95
87
  /**
96
- * Which parser can be used before returning the data to `@tanstack/query`.
97
- * `'zod'` will use `@kubb/plugin-zod` to parse the data.
98
- */
99
- parser?: 'zod'
100
- /**
101
- * Make it possible to override one of the templates
88
+ * Define some generators next to the swr generators
102
89
  */
103
- templates?: Partial<Templates>
90
+ generators?: Array<Generator<PluginSwr>>
104
91
  }
105
92
 
106
93
  type ResolvedOptions = {
107
- extName: KubbFile.Extname | undefined
94
+ output: Output
95
+ baseURL: string | undefined
108
96
  client: Required<NonNullable<Options['client']>>
109
- dataReturnType: NonNullable<Options['dataReturnType']>
110
- templates: NonNullable<Templates>
111
- parser: Options['parser']
112
- }
113
-
114
- export type FileMeta = {
115
- pluginKey?: Plugin['key']
116
- tag?: string
97
+ parser: Required<NonNullable<Options['parser']>>
98
+ mutation: Required<NonNullable<Options['mutation']>>
99
+ query: Required<NonNullable<Options['query']>>
100
+ pathParamsType: NonNullable<Options['pathParamsType']>
117
101
  }
118
102
 
119
103
  export type PluginSwr = PluginFactoryOptions<'plugin-swr', Options, ResolvedOptions, never, ResolvePathOptions>