@kubb/plugin-swr 3.0.0-alpha.2 → 3.0.0-alpha.20

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 (58) hide show
  1. package/README.md +13 -4
  2. package/dist/chunk-7WG6LPZJ.js +185 -0
  3. package/dist/chunk-7WG6LPZJ.js.map +1 -0
  4. package/dist/chunk-DGY6XSP2.js +187 -0
  5. package/dist/chunk-DGY6XSP2.js.map +1 -0
  6. package/dist/chunk-RMG5RYPG.cjs +189 -0
  7. package/dist/chunk-RMG5RYPG.cjs.map +1 -0
  8. package/dist/chunk-WI3XUYBA.cjs +194 -0
  9. package/dist/chunk-WI3XUYBA.cjs.map +1 -0
  10. package/dist/components.cjs +15 -6
  11. package/dist/components.cjs.map +1 -1
  12. package/dist/components.d.cts +49 -6
  13. package/dist/components.d.ts +49 -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 +10 -0
  19. package/dist/generators.d.ts +10 -0
  20. package/dist/generators.js +4 -0
  21. package/dist/generators.js.map +1 -0
  22. package/dist/index.cjs +90 -127
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +1 -4
  25. package/dist/index.d.ts +1 -4
  26. package/dist/index.js +70 -114
  27. package/dist/index.js.map +1 -1
  28. package/dist/types-BCd4p4VZ.d.cts +127 -0
  29. package/dist/types-BCd4p4VZ.d.ts +127 -0
  30. package/package.json +22 -16
  31. package/src/components/Mutation.tsx +82 -227
  32. package/src/components/Query.tsx +86 -264
  33. package/src/components/QueryOptions.tsx +58 -179
  34. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +40 -0
  35. package/src/generators/__snapshots__/clientGetImportPath.ts +40 -0
  36. package/src/generators/__snapshots__/clientPostImportPath.ts +30 -0
  37. package/src/generators/__snapshots__/findByTags.ts +40 -0
  38. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +40 -0
  39. package/src/generators/__snapshots__/findByTagsWithZod.ts +40 -0
  40. package/src/generators/__snapshots__/getAsMutation.ts +32 -0
  41. package/src/generators/__snapshots__/postAsQuery.ts +39 -0
  42. package/src/generators/__snapshots__/updatePetById.ts +30 -0
  43. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +34 -0
  44. package/src/generators/index.ts +2 -0
  45. package/src/generators/mutationGenerator.tsx +96 -0
  46. package/src/generators/queryGenerator.tsx +101 -0
  47. package/src/plugin.ts +61 -50
  48. package/src/types.ts +63 -55
  49. package/dist/chunk-ECJ346AA.js +0 -542
  50. package/dist/chunk-ECJ346AA.js.map +0 -1
  51. package/dist/chunk-H4LHXYRJ.cjs +0 -542
  52. package/dist/chunk-H4LHXYRJ.cjs.map +0 -1
  53. package/dist/index-B3C-JOIU.d.cts +0 -299
  54. package/dist/index-B3C-JOIU.d.ts +0 -299
  55. package/src/OperationGenerator.tsx +0 -75
  56. package/src/components/SchemaType.tsx +0 -59
  57. package/src/components/__snapshots__/Mutation/Pets.ts +0 -42
  58. package/src/components/__snapshots__/Query/showPetById.ts +0 -55
package/README.md CHANGED
@@ -13,10 +13,6 @@
13
13
  [![Coverage][coverage-src]][coverage-href]
14
14
  [![License][license-src]][license-href]
15
15
 
16
- <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
17
- <!-- ALL-CONTRIBUTORS-BADGE:END -->
18
- </p>
19
-
20
16
  <h4>
21
17
  <a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/alpha/examples/typescript" target="_blank">View Demo</a>
22
18
  <span> · </span>
@@ -28,6 +24,19 @@
28
24
  </h4>
29
25
  </div>
30
26
 
27
+ ## Supporting Kubb
28
+
29
+ Kubb uses an MIT-licensed open source project with its ongoing development made possible entirely by the support of Sponsors. If you would like to become a sponsor, please consider:
30
+
31
+ - [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
32
+
33
+ <p align="center">
34
+ <a href="https://github.com/sponsors/stijnvanhulle">
35
+ <img src="https://raw.githubusercontent.com/stijnvanhulle/sponsors/main/sponsors.svg" alt="My sponsors" />
36
+ </a>
37
+ </p>
38
+
39
+
31
40
  <!-- Badges -->
32
41
 
33
42
  [npm-version-src]: https://img.shields.io/npm/v/@kubb/plugin-swr?flat&colorA=18181B&colorB=f58517
@@ -0,0 +1,185 @@
1
+ import { URLPath } from '@kubb/core/utils';
2
+ import { File, Function, FunctionParams } from '@kubb/react';
3
+ import { isOptional } from '@kubb/oas';
4
+ import { Client } from '@kubb/plugin-client/components';
5
+ import { getComments, getPathParams } from '@kubb/plugin-oas/utils';
6
+ import { jsx } from '@kubb/react/jsx-runtime';
7
+
8
+ // src/components/Mutation.tsx
9
+ function getParams({ pathParamsType, dataReturnType, typeSchemas }) {
10
+ const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
11
+ return FunctionParams.factory({
12
+ pathParams: {
13
+ mode: pathParamsType === "object" ? "object" : "inlineSpread",
14
+ children: getPathParams(typeSchemas.pathParams, { typed: true })
15
+ },
16
+ params: typeSchemas.queryParams?.name ? {
17
+ type: typeSchemas.queryParams?.name,
18
+ optional: isOptional(typeSchemas.queryParams?.schema)
19
+ } : void 0,
20
+ headers: typeSchemas.headerParams?.name ? {
21
+ type: typeSchemas.headerParams?.name,
22
+ optional: isOptional(typeSchemas.headerParams?.schema)
23
+ } : void 0,
24
+ options: {
25
+ type: `
26
+ {
27
+ mutation?: SWRMutationConfiguration<${[TData, typeSchemas.errors?.map((item) => item.name).join(" | ") || "unknown"].join(", ")}>,
28
+ client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : "Partial<RequestConfig>"},
29
+ shouldFetch?: boolean,
30
+ }
31
+ `,
32
+ default: "{}"
33
+ }
34
+ });
35
+ }
36
+ function Mutation({ name, clientName, pathParamsType, dataReturnType, typeSchemas, operation }) {
37
+ const path = new URLPath(operation.path);
38
+ const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
39
+ const hookGenerics = [TData, typeSchemas.errors?.map((item) => item.name).join(" | ") || "unknown", "Key"];
40
+ const params = getParams({
41
+ pathParamsType,
42
+ dataReturnType,
43
+ typeSchemas
44
+ });
45
+ const clientParams = Client.getParams({
46
+ typeSchemas,
47
+ pathParamsType
48
+ });
49
+ const swrKey = [path.template, typeSchemas.queryParams?.name ? "params" : void 0].filter(Boolean);
50
+ return /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(
51
+ Function,
52
+ {
53
+ name,
54
+ export: true,
55
+ params: params.toConstructor(),
56
+ JSDoc: {
57
+ comments: getComments(operation)
58
+ },
59
+ children: `
60
+ const { mutation: mutationOptions, client: config = {}, shouldFetch = true } = options ?? {}
61
+
62
+ const swrKey = [${swrKey.join(", ")}] as const
63
+ return useSWRMutation<${hookGenerics}>(
64
+ shouldFetch ? swrKey : null,
65
+ async (_url${typeSchemas.request?.name ? ", { arg: data }" : ""}) => {
66
+ return ${clientName}(${clientParams.toCall()})
67
+ },
68
+ mutationOptions
69
+ )
70
+ `
71
+ }
72
+ ) });
73
+ }
74
+ function getParams2({ pathParamsType, typeSchemas }) {
75
+ return FunctionParams.factory({
76
+ pathParams: {
77
+ mode: pathParamsType === "object" ? "object" : "inlineSpread",
78
+ children: getPathParams(typeSchemas.pathParams, { typed: true })
79
+ },
80
+ data: typeSchemas.request?.name ? {
81
+ type: typeSchemas.request?.name,
82
+ optional: isOptional(typeSchemas.request?.schema)
83
+ } : void 0,
84
+ params: typeSchemas.queryParams?.name ? {
85
+ type: typeSchemas.queryParams?.name,
86
+ optional: isOptional(typeSchemas.queryParams?.schema)
87
+ } : void 0,
88
+ headers: typeSchemas.headerParams?.name ? {
89
+ type: typeSchemas.headerParams?.name,
90
+ optional: isOptional(typeSchemas.headerParams?.schema)
91
+ } : void 0,
92
+ config: {
93
+ type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : "Partial<RequestConfig>",
94
+ default: "{}"
95
+ }
96
+ });
97
+ }
98
+ function QueryOptions({ name, clientName, typeSchemas, pathParamsType }) {
99
+ const params = getParams2({ pathParamsType, typeSchemas });
100
+ const clientParams = Client.getParams({
101
+ typeSchemas,
102
+ pathParamsType
103
+ });
104
+ return /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(Function, { name, export: true, params: params.toConstructor(), children: `
105
+ return {
106
+ fetcher: async () => {
107
+ return ${clientName}(${clientParams.toCall()})
108
+ },
109
+ }
110
+ ` }) });
111
+ }
112
+ QueryOptions.getParams = getParams2;
113
+ function getParams3({ pathParamsType, dataReturnType, typeSchemas }) {
114
+ const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
115
+ return FunctionParams.factory({
116
+ pathParams: {
117
+ mode: pathParamsType === "object" ? "object" : "inlineSpread",
118
+ children: getPathParams(typeSchemas.pathParams, { typed: true })
119
+ },
120
+ data: typeSchemas.request?.name ? {
121
+ type: typeSchemas.request?.name,
122
+ optional: isOptional(typeSchemas.request?.schema)
123
+ } : void 0,
124
+ params: typeSchemas.queryParams?.name ? {
125
+ type: typeSchemas.queryParams?.name,
126
+ optional: isOptional(typeSchemas.queryParams?.schema)
127
+ } : void 0,
128
+ headers: typeSchemas.headerParams?.name ? {
129
+ type: typeSchemas.headerParams?.name,
130
+ optional: isOptional(typeSchemas.headerParams?.schema)
131
+ } : void 0,
132
+ options: {
133
+ type: `
134
+ {
135
+ query?: SWRConfiguration<${[TData, typeSchemas.errors?.map((item) => item.name).join(" | ") || "unknown"].join(", ")}>,
136
+ client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : "Partial<RequestConfig>"},
137
+ shouldFetch?: boolean,
138
+ }
139
+ `,
140
+ default: "{}"
141
+ }
142
+ });
143
+ }
144
+ function Query({ name, typeSchemas, queryOptionsName, operation, dataReturnType, pathParamsType }) {
145
+ const path = new URLPath(operation.path);
146
+ const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
147
+ const hookGenerics = [TData, typeSchemas.errors?.map((item) => item.name).join(" | ") || "unknown", "Key"];
148
+ const params = getParams3({
149
+ pathParamsType,
150
+ dataReturnType,
151
+ typeSchemas
152
+ });
153
+ const queryOptionsParams = QueryOptions.getParams({
154
+ pathParamsType,
155
+ typeSchemas
156
+ });
157
+ const swrKey = [path.template, typeSchemas.queryParams?.name ? "params" : void 0].filter(Boolean);
158
+ return /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(
159
+ Function,
160
+ {
161
+ name,
162
+ export: true,
163
+ params: params.toConstructor(),
164
+ JSDoc: {
165
+ comments: getComments(operation)
166
+ },
167
+ children: `
168
+ const { query: queryOptions, client: config = {}, shouldFetch = true } = options ?? {}
169
+
170
+ const swrKey = [${swrKey.join(", ")}] as const
171
+ return useSWR<${hookGenerics.join(", ")}>(
172
+ shouldFetch ? swrKey : null,
173
+ {
174
+ ...${queryOptionsName}(${queryOptionsParams.toCall()})
175
+ ...queryOptions
176
+ }
177
+ )
178
+ `
179
+ }
180
+ ) });
181
+ }
182
+
183
+ export { Mutation, Query, QueryOptions };
184
+ //# sourceMappingURL=chunk-7WG6LPZJ.js.map
185
+ //# sourceMappingURL=chunk-7WG6LPZJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/Mutation.tsx","../src/components/QueryOptions.tsx","../src/components/Query.tsx"],"names":["getParams","FunctionParams","getPathParams","isOptional","Client","jsx","File","Function","URLPath","getComments"],"mappings":";;;;;;;;AA6BA,SAAS,SAAU,CAAA,EAAE,cAAgB,EAAA,cAAA,EAAgB,aAA+B,EAAA;AAClF,EAAM,MAAA,KAAA,GAAQ,mBAAmB,MAAS,GAAA,WAAA,CAAY,SAAS,IAAO,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AAAA,MAC7B,KAAO,EAAA;AAAA,QACL,QAAA,EAAUE,YAAY,SAAS,CAAA;AAAA,OACjC;AAAA,MAEC,QAAA,EAAA,CAAA;AAAA;AAAA;AAAA,uBAGgB,EAAA,MAAA,CAAO,IAAK,CAAA,IAAI,CAAC,CAAA;AAAA,qBACnB,EAAA,YAAA,CAAa,IAAK,CAAA,IAAI,CAAC,CAAA;AAAA;AAAA;AAAA,aAAA,EAG/B,gBAAgB,CAAA,CAAA,EAAI,kBAAmB,CAAA,MAAA,EAAQ,CAAA;AAAA;AAAA;AAAA;AAAA,OAAA,CAAA;AAAA,KAAA;AAAA,GAM1D,EAAA,CAAA,CAAA;AAEJ","file":"chunk-7WG6LPZJ.js","sourcesContent":["import { URLPath } from '@kubb/core/utils'\nimport { File, Function, FunctionParams } from '@kubb/react'\n\nimport { type Operation, isOptional } from '@kubb/oas'\nimport { Client } from '@kubb/plugin-client/components'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport { getComments, getPathParams } from '@kubb/plugin-oas/utils'\nimport type { ReactNode } from 'react'\nimport type { PluginSwr } from '../types.ts'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n clientName: string\n typeSchemas: OperationSchemas\n operation: Operation\n dataReturnType: PluginSwr['resolvedOptions']['client']['dataReturnType']\n pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']\n}\n\ntype GetParamsProps = {\n pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']\n dataReturnType: PluginSwr['resolvedOptions']['client']['dataReturnType']\n typeSchemas: OperationSchemas\n}\n\nfunction getParams({ pathParamsType, dataReturnType, typeSchemas }: GetParamsProps) {\n const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`\n\n return FunctionParams.factory({\n pathParams: {\n mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',\n children: getPathParams(typeSchemas.pathParams, { typed: true }),\n },\n params: typeSchemas.queryParams?.name\n ? {\n type: typeSchemas.queryParams?.name,\n optional: isOptional(typeSchemas.queryParams?.schema),\n }\n : undefined,\n headers: typeSchemas.headerParams?.name\n ? {\n type: typeSchemas.headerParams?.name,\n optional: isOptional(typeSchemas.headerParams?.schema),\n }\n : undefined,\n options: {\n type: `\n{\n mutation?: SWRMutationConfiguration<${[TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'unknown'].join(', ')}>,\n client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>'},\n shouldFetch?: boolean,\n}\n`,\n default: '{}',\n },\n })\n}\n\nexport function Mutation({ name, clientName, pathParamsType, dataReturnType, typeSchemas, operation }: Props): ReactNode {\n const path = new URLPath(operation.path)\n const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`\n const hookGenerics = [TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'unknown', 'Key']\n\n const params = getParams({\n pathParamsType,\n dataReturnType,\n typeSchemas,\n })\n\n const clientParams = Client.getParams({\n typeSchemas,\n pathParamsType,\n })\n\n //fixed name, see Query.getParams and params\n const swrKey = [path.template, typeSchemas.queryParams?.name ? 'params' : undefined].filter(Boolean)\n\n return (\n <File.Source name={name} isExportable isIndexable>\n <Function\n name={name}\n export\n params={params.toConstructor()}\n JSDoc={{\n comments: getComments(operation),\n }}\n >\n {`\n const { mutation: mutationOptions, client: config = {}, shouldFetch = true } = options ?? {}\n\n const swrKey = [${swrKey.join(', ')}] as const\n return useSWRMutation<${hookGenerics}>(\n shouldFetch ? swrKey : null,\n async (_url${typeSchemas.request?.name ? ', { arg: data }' : ''}) => {\n return ${clientName}(${clientParams.toCall()})\n },\n mutationOptions\n )\n `}\n </Function>\n </File.Source>\n )\n}\n","import { getPathParams } from '@kubb/plugin-oas/utils'\nimport { File, Function, FunctionParams } from '@kubb/react'\n\nimport type { ReactNode } from 'react'\nimport type { PluginSwr } from '../types.ts'\n\nimport { isOptional } from '@kubb/oas'\nimport { Client } from '@kubb/plugin-client/components'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\n\ntype Props = {\n name: string\n clientName: string\n typeSchemas: OperationSchemas\n pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']\n}\n\ntype GetParamsProps = {\n pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']\n typeSchemas: OperationSchemas\n}\n\nfunction getParams({ pathParamsType, typeSchemas }: GetParamsProps) {\n return FunctionParams.factory({\n pathParams: {\n mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',\n children: getPathParams(typeSchemas.pathParams, { typed: true }),\n },\n data: typeSchemas.request?.name\n ? {\n type: typeSchemas.request?.name,\n optional: isOptional(typeSchemas.request?.schema),\n }\n : undefined,\n params: typeSchemas.queryParams?.name\n ? {\n type: typeSchemas.queryParams?.name,\n optional: isOptional(typeSchemas.queryParams?.schema),\n }\n : undefined,\n headers: typeSchemas.headerParams?.name\n ? {\n type: typeSchemas.headerParams?.name,\n optional: isOptional(typeSchemas.headerParams?.schema),\n }\n : undefined,\n config: {\n type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>',\n default: '{}',\n },\n })\n}\n\nexport function QueryOptions({ name, clientName, typeSchemas, pathParamsType }: Props): ReactNode {\n const params = getParams({ pathParamsType, typeSchemas })\n const clientParams = Client.getParams({\n typeSchemas,\n pathParamsType,\n })\n\n return (\n <File.Source name={name} isExportable isIndexable>\n <Function name={name} export params={params.toConstructor()}>\n {`\n return {\n fetcher: async () => {\n return ${clientName}(${clientParams.toCall()})\n },\n }\n `}\n </Function>\n </File.Source>\n )\n}\n\nQueryOptions.getParams = getParams\n","import { URLPath } from '@kubb/core/utils'\nimport { File, Function, FunctionParams } from '@kubb/react'\n\nimport { type Operation, isOptional } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport { getComments, getPathParams } from '@kubb/plugin-oas/utils'\nimport type { ReactNode } from 'react'\nimport type { PluginSwr } from '../types.ts'\nimport { QueryOptions } from './QueryOptions.tsx'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n queryOptionsName: string\n typeSchemas: OperationSchemas\n pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']\n dataReturnType: PluginSwr['resolvedOptions']['client']['dataReturnType']\n operation: Operation\n}\n\ntype GetParamsProps = {\n pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']\n dataReturnType: PluginSwr['resolvedOptions']['client']['dataReturnType']\n\n typeSchemas: OperationSchemas\n}\n\nfunction getParams({ pathParamsType, dataReturnType, typeSchemas }: GetParamsProps) {\n const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`\n\n return FunctionParams.factory({\n pathParams: {\n mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',\n children: getPathParams(typeSchemas.pathParams, { typed: true }),\n },\n data: typeSchemas.request?.name\n ? {\n type: typeSchemas.request?.name,\n optional: isOptional(typeSchemas.request?.schema),\n }\n : undefined,\n params: typeSchemas.queryParams?.name\n ? {\n type: typeSchemas.queryParams?.name,\n optional: isOptional(typeSchemas.queryParams?.schema),\n }\n : undefined,\n headers: typeSchemas.headerParams?.name\n ? {\n type: typeSchemas.headerParams?.name,\n optional: isOptional(typeSchemas.headerParams?.schema),\n }\n : undefined,\n options: {\n type: `\n{\n query?: SWRConfiguration<${[TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'unknown'].join(', ')}>,\n client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>'},\n shouldFetch?: boolean,\n}\n`,\n default: '{}',\n },\n })\n}\n\nexport function Query({ name, typeSchemas, queryOptionsName, operation, dataReturnType, pathParamsType }: Props): ReactNode {\n const path = new URLPath(operation.path)\n const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`\n const hookGenerics = [TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'unknown', 'Key']\n const params = getParams({\n pathParamsType,\n dataReturnType,\n typeSchemas,\n })\n\n const queryOptionsParams = QueryOptions.getParams({\n pathParamsType,\n typeSchemas,\n })\n\n //fixed name, see Query.getParams and params\n const swrKey = [path.template, typeSchemas.queryParams?.name ? 'params' : undefined].filter(Boolean)\n\n return (\n <File.Source name={name} isExportable isIndexable>\n <Function\n name={name}\n export\n params={params.toConstructor()}\n JSDoc={{\n comments: getComments(operation),\n }}\n >\n {`\n const { query: queryOptions, client: config = {}, shouldFetch = true } = options ?? {}\n\n const swrKey = [${swrKey.join(', ')}] as const\n return useSWR<${hookGenerics.join(', ')}>(\n shouldFetch ? swrKey : null,\n {\n ...${queryOptionsName}(${queryOptionsParams.toCall()})\n ...queryOptions\n }\n )\n `}\n </Function>\n </File.Source>\n )\n}\n"]}
@@ -0,0 +1,187 @@
1
+ import { QueryOptions, Query, Mutation } from './chunk-7WG6LPZJ.js';
2
+ import transformers from '@kubb/core/transformers';
3
+ import { pluginClientName } from '@kubb/plugin-client';
4
+ import { Client } from '@kubb/plugin-client/components';
5
+ import { createReactGenerator } from '@kubb/plugin-oas';
6
+ import { useOperationManager } from '@kubb/plugin-oas/hooks';
7
+ import { pluginTsName } from '@kubb/plugin-ts';
8
+ import { pluginZodName } from '@kubb/plugin-zod';
9
+ import { useApp, File } from '@kubb/react';
10
+ import { jsxs, jsx } from '@kubb/react/jsx-runtime';
11
+
12
+ var queryGenerator = createReactGenerator({
13
+ name: "swr-query",
14
+ Operation({ options, operation }) {
15
+ const {
16
+ plugin: {
17
+ options: { output }
18
+ }
19
+ } = useApp();
20
+ const { getSchemas, getName, getFile } = useOperationManager();
21
+ const isQuery = typeof options.query === "boolean" ? options.query : !!options.query.methods?.some((method) => operation.method === method);
22
+ const query = {
23
+ name: getName(operation, { type: "function", prefix: "use" }),
24
+ typeName: getName(operation, { type: "type" }),
25
+ file: getFile(operation, { prefix: "use" })
26
+ };
27
+ const client = {
28
+ name: getName(operation, { type: "function", pluginKey: [pluginClientName] })
29
+ };
30
+ const queryOptions = {
31
+ name: transformers.camelCase(`${operation.getOperationId()} QueryOptions`)
32
+ };
33
+ const type = {
34
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
35
+ //todo remove type?
36
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: "type" })
37
+ };
38
+ const zod = {
39
+ file: getFile(operation, { pluginKey: [pluginZodName] }),
40
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: "function" })
41
+ };
42
+ if (!isQuery) {
43
+ return null;
44
+ }
45
+ return /* @__PURE__ */ jsxs(File, { baseName: query.file.baseName, path: query.file.path, meta: query.file.meta, banner: output?.banner, footer: output?.footer, children: [
46
+ options.parser === "zod" && /* @__PURE__ */ jsx(File.Import, { extName: output?.extName, name: [zod.schemas.response.name], root: query.file.path, path: zod.file.path }),
47
+ /* @__PURE__ */ jsx(File.Import, { name: ["Key"], path: "swr", isTypeOnly: true }),
48
+ /* @__PURE__ */ jsx(File.Import, { name: "useSWR", path: options.query.importPath }),
49
+ /* @__PURE__ */ jsx(File.Import, { name: ["SWRConfiguration", "SWRResponse"], path: options.query.importPath, isTypeOnly: true }),
50
+ /* @__PURE__ */ jsx(File.Import, { name: "client", path: options.client.importPath }),
51
+ /* @__PURE__ */ jsx(File.Import, { name: ["RequestConfig"], path: options.client.importPath, isTypeOnly: true }),
52
+ options.client.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, { name: ["ResponseConfig"], path: options.client.importPath, isTypeOnly: true }),
53
+ /* @__PURE__ */ jsx(
54
+ File.Import,
55
+ {
56
+ extName: output?.extName,
57
+ name: [
58
+ type.schemas.request?.name,
59
+ type.schemas.response.name,
60
+ type.schemas.pathParams?.name,
61
+ type.schemas.queryParams?.name,
62
+ type.schemas.headerParams?.name,
63
+ ...type.schemas.statusCodes?.map((item) => item.name) || []
64
+ ].filter(Boolean),
65
+ root: query.file.path,
66
+ path: type.file.path,
67
+ isTypeOnly: true
68
+ }
69
+ ),
70
+ /* @__PURE__ */ jsx(
71
+ Client,
72
+ {
73
+ name: client.name,
74
+ isExportable: false,
75
+ isIndexable: false,
76
+ baseURL: options.baseURL,
77
+ operation,
78
+ typeSchemas: type.schemas,
79
+ zodSchemas: zod.schemas,
80
+ dataReturnType: options.client.dataReturnType,
81
+ pathParamsType: options.pathParamsType,
82
+ parser: options.parser
83
+ }
84
+ ),
85
+ /* @__PURE__ */ jsx(QueryOptions, { name: queryOptions.name, clientName: client.name, typeSchemas: type.schemas, pathParamsType: options.pathParamsType }),
86
+ /* @__PURE__ */ jsx(
87
+ Query,
88
+ {
89
+ name: query.name,
90
+ queryOptionsName: queryOptions.name,
91
+ typeSchemas: type.schemas,
92
+ pathParamsType: options.pathParamsType,
93
+ operation,
94
+ dataReturnType: options.client.dataReturnType
95
+ }
96
+ )
97
+ ] });
98
+ }
99
+ });
100
+ var mutationGenerator = createReactGenerator({
101
+ name: "swr-mutation",
102
+ Operation({ options, operation }) {
103
+ const {
104
+ plugin: {
105
+ options: { output }
106
+ }
107
+ } = useApp();
108
+ const { getSchemas, getName, getFile } = useOperationManager();
109
+ const isMutate = typeof options.query === "boolean" ? options.mutation : !!options.mutation.methods?.some((method) => operation.method === method);
110
+ const mutation = {
111
+ name: getName(operation, { type: "function", prefix: "use" }),
112
+ typeName: getName(operation, { type: "type" }),
113
+ file: getFile(operation, { prefix: "use" })
114
+ };
115
+ const type = {
116
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
117
+ //todo remove type?
118
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: "type" })
119
+ };
120
+ const zod = {
121
+ file: getFile(operation, { pluginKey: [pluginZodName] }),
122
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: "function" })
123
+ };
124
+ const client = {
125
+ name: getName(operation, { type: "function", pluginKey: [pluginClientName] })
126
+ };
127
+ if (!isMutate) {
128
+ return null;
129
+ }
130
+ return /* @__PURE__ */ jsxs(File, { baseName: mutation.file.baseName, path: mutation.file.path, meta: mutation.file.meta, banner: output?.banner, footer: output?.footer, children: [
131
+ options.parser === "zod" && /* @__PURE__ */ jsx(File.Import, { extName: output?.extName, name: [zod.schemas.response.name], root: mutation.file.path, path: zod.file.path }),
132
+ /* @__PURE__ */ jsx(File.Import, { name: ["Key"], path: "swr", isTypeOnly: true }),
133
+ /* @__PURE__ */ jsx(File.Import, { name: "useSWRMutation", path: options.mutation.importPath }),
134
+ /* @__PURE__ */ jsx(File.Import, { name: ["SWRMutationConfiguration", "SWRMutationResponse"], path: options.mutation.importPath, isTypeOnly: true }),
135
+ /* @__PURE__ */ jsx(File.Import, { name: "client", path: options.client.importPath }),
136
+ /* @__PURE__ */ jsx(File.Import, { name: ["RequestConfig", "ResponseConfig"], path: options.client.importPath, isTypeOnly: true }),
137
+ /* @__PURE__ */ jsx(
138
+ File.Import,
139
+ {
140
+ extName: output?.extName,
141
+ name: [
142
+ type.schemas.request?.name,
143
+ type.schemas.response.name,
144
+ type.schemas.pathParams?.name,
145
+ type.schemas.queryParams?.name,
146
+ type.schemas.headerParams?.name,
147
+ ...type.schemas.statusCodes?.map((item) => item.name) || []
148
+ ].filter(Boolean),
149
+ root: mutation.file.path,
150
+ path: type.file.path,
151
+ isTypeOnly: true
152
+ }
153
+ ),
154
+ /* @__PURE__ */ jsx(
155
+ Client,
156
+ {
157
+ name: client.name,
158
+ isExportable: false,
159
+ isIndexable: false,
160
+ baseURL: options.baseURL,
161
+ operation,
162
+ typeSchemas: type.schemas,
163
+ zodSchemas: zod.schemas,
164
+ dataReturnType: options.client.dataReturnType,
165
+ pathParamsType: options.pathParamsType,
166
+ parser: options.parser
167
+ }
168
+ ),
169
+ /* @__PURE__ */ jsx(
170
+ Mutation,
171
+ {
172
+ name: mutation.name,
173
+ clientName: client.name,
174
+ typeName: mutation.typeName,
175
+ typeSchemas: type.schemas,
176
+ operation,
177
+ dataReturnType: options.client.dataReturnType,
178
+ pathParamsType: options.pathParamsType
179
+ }
180
+ )
181
+ ] });
182
+ }
183
+ });
184
+
185
+ export { mutationGenerator, queryGenerator };
186
+ //# sourceMappingURL=chunk-DGY6XSP2.js.map
187
+ //# sourceMappingURL=chunk-DGY6XSP2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/generators/queryGenerator.tsx","../src/generators/mutationGenerator.tsx"],"names":["createReactGenerator","useApp","useOperationManager","pluginTsName","pluginZodName","pluginClientName","jsxs","File","jsx","Client"],"mappings":";;;;;;;;;;;AAWO,IAAM,iBAAiB,oBAAgC,CAAA;AAAA,EAC5D,IAAM,EAAA,WAAA;AAAA,EACN,SAAU,CAAA,EAAE,OAAS,EAAA,SAAA,EAAa,EAAA;AAChC,IAAM,MAAA;AAAA,MACJ,MAAQ,EAAA;AAAA,QACN,OAAA,EAAS,EAAE,MAAO,EAAA;AAAA,OACpB;AAAA,QACE,MAAkB,EAAA,CAAA;AACtB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,OAAA,KAAY,mBAAoB,EAAA,CAAA;AAE7D,IAAA,MAAM,UAAU,OAAO,OAAA,CAAQ,KAAU,KAAA,SAAA,GAAY,QAAQ,KAAQ,GAAA,CAAC,CAAC,OAAA,CAAQ,MAAM,OAAS,EAAA,IAAA,CAAK,CAAC,MAAW,KAAA,SAAA,CAAU,WAAW,MAAM,CAAA,CAAA;AAE1I,IAAA,MAAM,KAAQ,GAAA;AAAA,MACZ,IAAA,EAAM,QAAQ,SAAW,EAAA,EAAE,MAAM,UAAY,EAAA,MAAA,EAAQ,OAAO,CAAA;AAAA,MAC5D,UAAU,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,QAAQ,CAAA;AAAA,MAC7C,MAAM,OAAQ,CAAA,SAAA,EAAW,EAAE,MAAA,EAAQ,OAAO,CAAA;AAAA,KAC5C,CAAA;AAEA,IAAA,MAAM,MAAS,GAAA;AAAA,MACb,IAAA,EAAM,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,SAAW,EAAA,CAAC,g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EAAA,IAAA;AAAA,SAAA;AAAA,OACZ;AAAA,sBACAC,GAAAA;AAAA,QAACC,MAAAA;AAAA,QAAA;AAAA,UACC,MAAM,MAAO,CAAA,IAAA;AAAA,UACb,YAAc,EAAA,KAAA;AAAA,UACd,WAAa,EAAA,KAAA;AAAA,UACb,SAAS,OAAQ,CAAA,OAAA;AAAA,UACjB,SAAA;AAAA,UACA,aAAa,IAAK,CAAA,OAAA;AAAA,UAClB,YAAY,GAAI,CAAA,OAAA;AAAA,UAChB,cAAA,EAAgB,QAAQ,MAAO,CAAA,cAAA;AAAA,UAC/B,gBAAgB,OAAQ,CAAA,cAAA;AAAA,UACxB,QAAQ,OAAQ,CAAA,MAAA;AAAA,SAAA;AAAA,OAClB;AAAA,sBACAD,GAAAA;AAAA,QAAC,QAAA;AAAA,QAAA;AAAA,UACC,MAAM,QAAS,CAAA,IAAA;AAAA,UACf,YAAY,MAAO,CAAA,IAAA;AAAA,UACnB,UAAU,QAAS,CAAA,QAAA;AAAA,UACnB,aAAa,IAAK,CAAA,OAAA;AAAA,UAClB,SAAA;AAAA,UACA,cAAA,EAAgB,QAAQ,MAAO,CAAA,cAAA;AAAA,UAC/B,gBAAgB,OAAQ,CAAA,cAAA;AAAA,SAAA;AAAA,OAC1B;AAAA,KACF,EAAA,CAAA,CAAA;AAAA,GAEJ;AACF,CAAC","file":"chunk-DGY6XSP2.js","sourcesContent":["import transformers from '@kubb/core/transformers'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { Client } from '@kubb/plugin-client/components'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { File, useApp } from '@kubb/react'\nimport { Query, QueryOptions } from '../components'\nimport type { PluginSwr } from '../types'\n\nexport const queryGenerator = createReactGenerator<PluginSwr>({\n name: 'swr-query',\n Operation({ options, operation }) {\n const {\n plugin: {\n options: { output },\n },\n } = useApp<PluginSwr>()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const isQuery = typeof options.query === 'boolean' ? options.query : !!options.query.methods?.some((method) => operation.method === method)\n\n const query = {\n name: getName(operation, { type: 'function', prefix: 'use' }),\n typeName: getName(operation, { type: 'type' }),\n file: getFile(operation, { prefix: 'use' }),\n }\n\n const client = {\n name: getName(operation, { type: 'function', pluginKey: [pluginClientName] }),\n }\n\n const queryOptions = {\n name: transformers.camelCase(`${operation.getOperationId()} QueryOptions`),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n //todo remove type?\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n const zod = {\n file: getFile(operation, { pluginKey: [pluginZodName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),\n }\n\n if (!isQuery) {\n return null\n }\n\n return (\n <File baseName={query.file.baseName} path={query.file.path} meta={query.file.meta} banner={output?.banner} footer={output?.footer}>\n {options.parser === 'zod' && <File.Import extName={output?.extName} name={[zod.schemas.response.name]} root={query.file.path} path={zod.file.path} />}\n <File.Import name={['Key']} path=\"swr\" isTypeOnly />\n <File.Import name=\"useSWR\" path={options.query.importPath} />\n <File.Import name={['SWRConfiguration', 'SWRResponse']} path={options.query.importPath} isTypeOnly />\n <File.Import name={'client'} path={options.client.importPath} />\n <File.Import name={['RequestConfig']} path={options.client.importPath} isTypeOnly />\n {options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}\n\n <File.Import\n extName={output?.extName}\n name={[\n type.schemas.request?.name,\n type.schemas.response.name,\n type.schemas.pathParams?.name,\n type.schemas.queryParams?.name,\n type.schemas.headerParams?.name,\n ...(type.schemas.statusCodes?.map((item) => item.name) || []),\n ].filter(Boolean)}\n root={query.file.path}\n path={type.file.path}\n isTypeOnly\n />\n <Client\n name={client.name}\n isExportable={false}\n isIndexable={false}\n baseURL={options.baseURL}\n operation={operation}\n typeSchemas={type.schemas}\n zodSchemas={zod.schemas}\n dataReturnType={options.client.dataReturnType}\n pathParamsType={options.pathParamsType}\n parser={options.parser}\n />\n <QueryOptions name={queryOptions.name} clientName={client.name} typeSchemas={type.schemas} pathParamsType={options.pathParamsType} />\n <Query\n name={query.name}\n queryOptionsName={queryOptions.name}\n typeSchemas={type.schemas}\n pathParamsType={options.pathParamsType}\n operation={operation}\n dataReturnType={options.client.dataReturnType}\n />\n </File>\n )\n },\n})\n","import { pluginClientName } from '@kubb/plugin-client'\nimport { Client } from '@kubb/plugin-client/components'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { File, useApp } from '@kubb/react'\nimport { Mutation } from '../components'\nimport type { PluginSwr } from '../types'\n\nexport const mutationGenerator = createReactGenerator<PluginSwr>({\n name: 'swr-mutation',\n Operation({ options, operation }) {\n const {\n plugin: {\n options: { output },\n },\n } = useApp<PluginSwr>()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const isMutate = typeof options.query === 'boolean' ? options.mutation : !!options.mutation.methods?.some((method) => operation.method === method)\n\n const mutation = {\n name: getName(operation, { type: 'function', prefix: 'use' }),\n typeName: getName(operation, { type: 'type' }),\n file: getFile(operation, { prefix: 'use' }),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n //todo remove type?\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n const zod = {\n file: getFile(operation, { pluginKey: [pluginZodName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),\n }\n\n const client = {\n name: getName(operation, { type: 'function', pluginKey: [pluginClientName] }),\n }\n\n if (!isMutate) {\n return null\n }\n\n return (\n <File baseName={mutation.file.baseName} path={mutation.file.path} meta={mutation.file.meta} banner={output?.banner} footer={output?.footer}>\n {options.parser === 'zod' && (\n <File.Import extName={output?.extName} name={[zod.schemas.response.name]} root={mutation.file.path} path={zod.file.path} />\n )}\n <File.Import name={['Key']} path=\"swr\" isTypeOnly />\n <File.Import name=\"useSWRMutation\" path={options.mutation.importPath} />\n <File.Import name={['SWRMutationConfiguration', 'SWRMutationResponse']} path={options.mutation.importPath} isTypeOnly />\n <File.Import name={'client'} path={options.client.importPath} />\n <File.Import name={['RequestConfig', 'ResponseConfig']} path={options.client.importPath} isTypeOnly />\n <File.Import\n extName={output?.extName}\n name={[\n type.schemas.request?.name,\n type.schemas.response.name,\n type.schemas.pathParams?.name,\n type.schemas.queryParams?.name,\n type.schemas.headerParams?.name,\n ...(type.schemas.statusCodes?.map((item) => item.name) || []),\n ].filter(Boolean)}\n root={mutation.file.path}\n path={type.file.path}\n isTypeOnly\n />\n <Client\n name={client.name}\n isExportable={false}\n isIndexable={false}\n baseURL={options.baseURL}\n operation={operation}\n typeSchemas={type.schemas}\n zodSchemas={zod.schemas}\n dataReturnType={options.client.dataReturnType}\n pathParamsType={options.pathParamsType}\n parser={options.parser}\n />\n <Mutation\n name={mutation.name}\n clientName={client.name}\n typeName={mutation.typeName}\n typeSchemas={type.schemas}\n operation={operation}\n dataReturnType={options.client.dataReturnType}\n pathParamsType={options.pathParamsType}\n />\n </File>\n )\n },\n})\n"]}
@@ -0,0 +1,189 @@
1
+ 'use strict';
2
+
3
+ var utils = require('@kubb/core/utils');
4
+ var react = require('@kubb/react');
5
+ var oas = require('@kubb/oas');
6
+ var components = require('@kubb/plugin-client/components');
7
+ var utils$1 = require('@kubb/plugin-oas/utils');
8
+ var jsxRuntime = require('@kubb/react/jsx-runtime');
9
+
10
+ // src/components/Mutation.tsx
11
+ function getParams({ pathParamsType, dataReturnType, typeSchemas }) {
12
+ const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
13
+ return react.FunctionParams.factory({
14
+ pathParams: {
15
+ mode: pathParamsType === "object" ? "object" : "inlineSpread",
16
+ children: utils$1.getPathParams(typeSchemas.pathParams, { typed: true })
17
+ },
18
+ params: typeSchemas.queryParams?.name ? {
19
+ type: typeSchemas.queryParams?.name,
20
+ optional: oas.isOptional(typeSchemas.queryParams?.schema)
21
+ } : void 0,
22
+ headers: typeSchemas.headerParams?.name ? {
23
+ type: typeSchemas.headerParams?.name,
24
+ optional: oas.isOptional(typeSchemas.headerParams?.schema)
25
+ } : void 0,
26
+ options: {
27
+ type: `
28
+ {
29
+ mutation?: SWRMutationConfiguration<${[TData, typeSchemas.errors?.map((item) => item.name).join(" | ") || "unknown"].join(", ")}>,
30
+ client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : "Partial<RequestConfig>"},
31
+ shouldFetch?: boolean,
32
+ }
33
+ `,
34
+ default: "{}"
35
+ }
36
+ });
37
+ }
38
+ function Mutation({ name, clientName, pathParamsType, dataReturnType, typeSchemas, operation }) {
39
+ const path = new utils.URLPath(operation.path);
40
+ const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
41
+ const hookGenerics = [TData, typeSchemas.errors?.map((item) => item.name).join(" | ") || "unknown", "Key"];
42
+ const params = getParams({
43
+ pathParamsType,
44
+ dataReturnType,
45
+ typeSchemas
46
+ });
47
+ const clientParams = components.Client.getParams({
48
+ typeSchemas,
49
+ pathParamsType
50
+ });
51
+ const swrKey = [path.template, typeSchemas.queryParams?.name ? "params" : void 0].filter(Boolean);
52
+ return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(
53
+ react.Function,
54
+ {
55
+ name,
56
+ export: true,
57
+ params: params.toConstructor(),
58
+ JSDoc: {
59
+ comments: utils$1.getComments(operation)
60
+ },
61
+ children: `
62
+ const { mutation: mutationOptions, client: config = {}, shouldFetch = true } = options ?? {}
63
+
64
+ const swrKey = [${swrKey.join(", ")}] as const
65
+ return useSWRMutation<${hookGenerics}>(
66
+ shouldFetch ? swrKey : null,
67
+ async (_url${typeSchemas.request?.name ? ", { arg: data }" : ""}) => {
68
+ return ${clientName}(${clientParams.toCall()})
69
+ },
70
+ mutationOptions
71
+ )
72
+ `
73
+ }
74
+ ) });
75
+ }
76
+ function getParams2({ pathParamsType, typeSchemas }) {
77
+ return react.FunctionParams.factory({
78
+ pathParams: {
79
+ mode: pathParamsType === "object" ? "object" : "inlineSpread",
80
+ children: utils$1.getPathParams(typeSchemas.pathParams, { typed: true })
81
+ },
82
+ data: typeSchemas.request?.name ? {
83
+ type: typeSchemas.request?.name,
84
+ optional: oas.isOptional(typeSchemas.request?.schema)
85
+ } : void 0,
86
+ params: typeSchemas.queryParams?.name ? {
87
+ type: typeSchemas.queryParams?.name,
88
+ optional: oas.isOptional(typeSchemas.queryParams?.schema)
89
+ } : void 0,
90
+ headers: typeSchemas.headerParams?.name ? {
91
+ type: typeSchemas.headerParams?.name,
92
+ optional: oas.isOptional(typeSchemas.headerParams?.schema)
93
+ } : void 0,
94
+ config: {
95
+ type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : "Partial<RequestConfig>",
96
+ default: "{}"
97
+ }
98
+ });
99
+ }
100
+ function QueryOptions({ name, clientName, typeSchemas, pathParamsType }) {
101
+ const params = getParams2({ pathParamsType, typeSchemas });
102
+ const clientParams = components.Client.getParams({
103
+ typeSchemas,
104
+ pathParamsType
105
+ });
106
+ return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Function, { name, export: true, params: params.toConstructor(), children: `
107
+ return {
108
+ fetcher: async () => {
109
+ return ${clientName}(${clientParams.toCall()})
110
+ },
111
+ }
112
+ ` }) });
113
+ }
114
+ QueryOptions.getParams = getParams2;
115
+ function getParams3({ pathParamsType, dataReturnType, typeSchemas }) {
116
+ const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
117
+ return react.FunctionParams.factory({
118
+ pathParams: {
119
+ mode: pathParamsType === "object" ? "object" : "inlineSpread",
120
+ children: utils$1.getPathParams(typeSchemas.pathParams, { typed: true })
121
+ },
122
+ data: typeSchemas.request?.name ? {
123
+ type: typeSchemas.request?.name,
124
+ optional: oas.isOptional(typeSchemas.request?.schema)
125
+ } : void 0,
126
+ params: typeSchemas.queryParams?.name ? {
127
+ type: typeSchemas.queryParams?.name,
128
+ optional: oas.isOptional(typeSchemas.queryParams?.schema)
129
+ } : void 0,
130
+ headers: typeSchemas.headerParams?.name ? {
131
+ type: typeSchemas.headerParams?.name,
132
+ optional: oas.isOptional(typeSchemas.headerParams?.schema)
133
+ } : void 0,
134
+ options: {
135
+ type: `
136
+ {
137
+ query?: SWRConfiguration<${[TData, typeSchemas.errors?.map((item) => item.name).join(" | ") || "unknown"].join(", ")}>,
138
+ client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : "Partial<RequestConfig>"},
139
+ shouldFetch?: boolean,
140
+ }
141
+ `,
142
+ default: "{}"
143
+ }
144
+ });
145
+ }
146
+ function Query({ name, typeSchemas, queryOptionsName, operation, dataReturnType, pathParamsType }) {
147
+ const path = new utils.URLPath(operation.path);
148
+ const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
149
+ const hookGenerics = [TData, typeSchemas.errors?.map((item) => item.name).join(" | ") || "unknown", "Key"];
150
+ const params = getParams3({
151
+ pathParamsType,
152
+ dataReturnType,
153
+ typeSchemas
154
+ });
155
+ const queryOptionsParams = QueryOptions.getParams({
156
+ pathParamsType,
157
+ typeSchemas
158
+ });
159
+ const swrKey = [path.template, typeSchemas.queryParams?.name ? "params" : void 0].filter(Boolean);
160
+ return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(
161
+ react.Function,
162
+ {
163
+ name,
164
+ export: true,
165
+ params: params.toConstructor(),
166
+ JSDoc: {
167
+ comments: utils$1.getComments(operation)
168
+ },
169
+ children: `
170
+ const { query: queryOptions, client: config = {}, shouldFetch = true } = options ?? {}
171
+
172
+ const swrKey = [${swrKey.join(", ")}] as const
173
+ return useSWR<${hookGenerics.join(", ")}>(
174
+ shouldFetch ? swrKey : null,
175
+ {
176
+ ...${queryOptionsName}(${queryOptionsParams.toCall()})
177
+ ...queryOptions
178
+ }
179
+ )
180
+ `
181
+ }
182
+ ) });
183
+ }
184
+
185
+ exports.Mutation = Mutation;
186
+ exports.Query = Query;
187
+ exports.QueryOptions = QueryOptions;
188
+ //# sourceMappingURL=chunk-RMG5RYPG.cjs.map
189
+ //# sourceMappingURL=chunk-RMG5RYPG.cjs.map