@kubb/plugin-swr 0.0.0-canary-20241104172400
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +53 -0
- package/dist/chunk-2KDZWGWG.js +342 -0
- package/dist/chunk-2KDZWGWG.js.map +1 -0
- package/dist/chunk-64KLXAGI.cjs +237 -0
- package/dist/chunk-64KLXAGI.cjs.map +1 -0
- package/dist/chunk-AFAHUG3Q.cjs +348 -0
- package/dist/chunk-AFAHUG3Q.cjs.map +1 -0
- package/dist/chunk-T6K6P5I7.js +234 -0
- package/dist/chunk-T6K6P5I7.js.map +1 -0
- package/dist/components.cjs +28 -0
- package/dist/components.cjs.map +1 -0
- package/dist/components.d.cts +95 -0
- package/dist/components.d.ts +95 -0
- package/dist/components.js +3 -0
- package/dist/components.js.map +1 -0
- package/dist/generators.cjs +17 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +11 -0
- package/dist/generators.d.ts +11 -0
- package/dist/generators.js +4 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.cjs +127 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +120 -0
- package/dist/index.js.map +1 -0
- package/dist/types-AhGZx7jH.d.cts +272 -0
- package/dist/types-AhGZx7jH.d.ts +272 -0
- package/package.json +104 -0
- package/src/components/Mutation.tsx +129 -0
- package/src/components/MutationKey.tsx +54 -0
- package/src/components/Query.tsx +175 -0
- package/src/components/QueryKey.tsx +83 -0
- package/src/components/QueryOptions.tsx +116 -0
- package/src/components/index.ts +5 -0
- package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +49 -0
- package/src/generators/__snapshots__/clientGetImportPath.ts +49 -0
- package/src/generators/__snapshots__/clientPostImportPath.ts +32 -0
- package/src/generators/__snapshots__/findByTags.ts +49 -0
- package/src/generators/__snapshots__/findByTagsObject.ts +49 -0
- package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +49 -0
- package/src/generators/__snapshots__/findByTagsWithZod.ts +49 -0
- package/src/generators/__snapshots__/getAsMutation.ts +34 -0
- package/src/generators/__snapshots__/postAsQuery.ts +50 -0
- package/src/generators/__snapshots__/updatePetById.ts +32 -0
- package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +34 -0
- package/src/generators/index.ts +2 -0
- package/src/generators/mutationGenerator.tsx +117 -0
- package/src/generators/queryGenerator.tsx +127 -0
- package/src/index.ts +4 -0
- package/src/plugin.ts +141 -0
- package/src/types.ts +126 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkAFAHUG3Q_cjs = require('./chunk-AFAHUG3Q.cjs');
|
|
4
|
+
var pluginClient = require('@kubb/plugin-client');
|
|
5
|
+
var components = require('@kubb/plugin-client/components');
|
|
6
|
+
var pluginOas = require('@kubb/plugin-oas');
|
|
7
|
+
var hooks = require('@kubb/plugin-oas/hooks');
|
|
8
|
+
var pluginTs = require('@kubb/plugin-ts');
|
|
9
|
+
var pluginZod = require('@kubb/plugin-zod');
|
|
10
|
+
var react = require('@kubb/react');
|
|
11
|
+
var jsxRuntime = require('@kubb/react/jsx-runtime');
|
|
12
|
+
|
|
13
|
+
var queryGenerator = pluginOas.createReactGenerator({
|
|
14
|
+
name: "swr-query",
|
|
15
|
+
Operation({ options, operation }) {
|
|
16
|
+
const {
|
|
17
|
+
plugin: {
|
|
18
|
+
options: { output }
|
|
19
|
+
}
|
|
20
|
+
} = react.useApp();
|
|
21
|
+
const { getSchemas, getName, getFile } = hooks.useOperationManager();
|
|
22
|
+
const isQuery = typeof options.query === "boolean" ? options.query : !!options.query.methods?.some((method) => operation.method === method);
|
|
23
|
+
const importPath = options.query ? options.query.importPath : "swr/mutation";
|
|
24
|
+
const query = {
|
|
25
|
+
name: getName(operation, { type: "function", prefix: "use" }),
|
|
26
|
+
typeName: getName(operation, { type: "type" }),
|
|
27
|
+
file: getFile(operation, { prefix: "use" })
|
|
28
|
+
};
|
|
29
|
+
const client = {
|
|
30
|
+
name: getName(operation, { type: "function", pluginKey: [pluginClient.pluginClientName] })
|
|
31
|
+
};
|
|
32
|
+
const queryOptions = {
|
|
33
|
+
name: getName(operation, { type: "function", suffix: "QueryOptions" })
|
|
34
|
+
};
|
|
35
|
+
const queryKey = {
|
|
36
|
+
name: getName(operation, { type: "const", suffix: "QueryKey" }),
|
|
37
|
+
typeName: getName(operation, { type: "type", suffix: "QueryKey" })
|
|
38
|
+
};
|
|
39
|
+
const type = {
|
|
40
|
+
file: getFile(operation, { pluginKey: [pluginTs.pluginTsName] }),
|
|
41
|
+
//todo remove type?
|
|
42
|
+
schemas: getSchemas(operation, { pluginKey: [pluginTs.pluginTsName], type: "type" })
|
|
43
|
+
};
|
|
44
|
+
const zod = {
|
|
45
|
+
file: getFile(operation, { pluginKey: [pluginZod.pluginZodName] }),
|
|
46
|
+
schemas: getSchemas(operation, { pluginKey: [pluginZod.pluginZodName], type: "function" })
|
|
47
|
+
};
|
|
48
|
+
if (!isQuery) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: query.file.baseName, path: query.file.path, meta: query.file.meta, banner: output?.banner, footer: output?.footer, children: [
|
|
52
|
+
options.parser === "zod" && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [zod.schemas.response.name], root: query.file.path, path: zod.file.path }),
|
|
53
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: "client", path: options.client.importPath }),
|
|
54
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["RequestConfig"], path: options.client.importPath, isTypeOnly: true }),
|
|
55
|
+
options.client.dataReturnType === "full" && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["ResponseConfig"], path: options.client.importPath, isTypeOnly: true }),
|
|
56
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
57
|
+
react.File.Import,
|
|
58
|
+
{
|
|
59
|
+
name: [
|
|
60
|
+
type.schemas.request?.name,
|
|
61
|
+
type.schemas.response.name,
|
|
62
|
+
type.schemas.pathParams?.name,
|
|
63
|
+
type.schemas.queryParams?.name,
|
|
64
|
+
type.schemas.headerParams?.name,
|
|
65
|
+
...type.schemas.statusCodes?.map((item) => item.name) || []
|
|
66
|
+
].filter(Boolean),
|
|
67
|
+
root: query.file.path,
|
|
68
|
+
path: type.file.path,
|
|
69
|
+
isTypeOnly: true
|
|
70
|
+
}
|
|
71
|
+
),
|
|
72
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
73
|
+
chunkAFAHUG3Q_cjs.QueryKey,
|
|
74
|
+
{
|
|
75
|
+
name: queryKey.name,
|
|
76
|
+
typeName: queryKey.typeName,
|
|
77
|
+
operation,
|
|
78
|
+
pathParamsType: options.pathParamsType,
|
|
79
|
+
typeSchemas: type.schemas,
|
|
80
|
+
transformer: options.queryKey
|
|
81
|
+
}
|
|
82
|
+
),
|
|
83
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
84
|
+
components.Client,
|
|
85
|
+
{
|
|
86
|
+
name: client.name,
|
|
87
|
+
isExportable: false,
|
|
88
|
+
isIndexable: false,
|
|
89
|
+
baseURL: options.client.baseURL,
|
|
90
|
+
operation,
|
|
91
|
+
typeSchemas: type.schemas,
|
|
92
|
+
zodSchemas: zod.schemas,
|
|
93
|
+
dataReturnType: options.client.dataReturnType,
|
|
94
|
+
paramsType: options.paramsType,
|
|
95
|
+
pathParamsType: options.pathParamsType,
|
|
96
|
+
parser: options.parser
|
|
97
|
+
}
|
|
98
|
+
),
|
|
99
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
100
|
+
chunkAFAHUG3Q_cjs.QueryOptions,
|
|
101
|
+
{
|
|
102
|
+
name: queryOptions.name,
|
|
103
|
+
clientName: client.name,
|
|
104
|
+
typeSchemas: type.schemas,
|
|
105
|
+
paramsType: options.paramsType,
|
|
106
|
+
pathParamsType: options.pathParamsType
|
|
107
|
+
}
|
|
108
|
+
),
|
|
109
|
+
options.query && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
110
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: "useSWR", path: importPath }),
|
|
111
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["SWRResponse"], path: importPath, isTypeOnly: true }),
|
|
112
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
113
|
+
chunkAFAHUG3Q_cjs.Query,
|
|
114
|
+
{
|
|
115
|
+
name: query.name,
|
|
116
|
+
queryOptionsName: queryOptions.name,
|
|
117
|
+
typeSchemas: type.schemas,
|
|
118
|
+
paramsType: options.paramsType,
|
|
119
|
+
pathParamsType: options.pathParamsType,
|
|
120
|
+
operation,
|
|
121
|
+
dataReturnType: options.client.dataReturnType,
|
|
122
|
+
queryKeyName: queryKey.name,
|
|
123
|
+
queryKeyTypeName: queryKey.typeName
|
|
124
|
+
}
|
|
125
|
+
)
|
|
126
|
+
] })
|
|
127
|
+
] });
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
var mutationGenerator = pluginOas.createReactGenerator({
|
|
131
|
+
name: "swr-mutation",
|
|
132
|
+
Operation({ options, operation }) {
|
|
133
|
+
const {
|
|
134
|
+
plugin: {
|
|
135
|
+
options: { output }
|
|
136
|
+
}
|
|
137
|
+
} = react.useApp();
|
|
138
|
+
const { getSchemas, getName, getFile } = hooks.useOperationManager();
|
|
139
|
+
const isQuery = typeof options.query === "boolean" ? true : options.query?.methods.some((method) => operation.method === method);
|
|
140
|
+
const isMutation = !isQuery && options.mutation && options.mutation.methods.some((method) => operation.method === method);
|
|
141
|
+
const importPath = options.mutation ? options.mutation.importPath : "swr";
|
|
142
|
+
const mutation = {
|
|
143
|
+
name: getName(operation, { type: "function", prefix: "use" }),
|
|
144
|
+
typeName: getName(operation, { type: "type" }),
|
|
145
|
+
file: getFile(operation, { prefix: "use" })
|
|
146
|
+
};
|
|
147
|
+
const type = {
|
|
148
|
+
file: getFile(operation, { pluginKey: [pluginTs.pluginTsName] }),
|
|
149
|
+
//todo remove type?
|
|
150
|
+
schemas: getSchemas(operation, { pluginKey: [pluginTs.pluginTsName], type: "type" })
|
|
151
|
+
};
|
|
152
|
+
const zod = {
|
|
153
|
+
file: getFile(operation, { pluginKey: [pluginZod.pluginZodName] }),
|
|
154
|
+
schemas: getSchemas(operation, { pluginKey: [pluginZod.pluginZodName], type: "function" })
|
|
155
|
+
};
|
|
156
|
+
const client = {
|
|
157
|
+
name: getName(operation, { type: "function", pluginKey: [pluginClient.pluginClientName] })
|
|
158
|
+
};
|
|
159
|
+
const mutationKey = {
|
|
160
|
+
name: getName(operation, { type: "const", suffix: "MutationKey" }),
|
|
161
|
+
typeName: getName(operation, { type: "type", suffix: "MutationKey" })
|
|
162
|
+
};
|
|
163
|
+
if (!isMutation) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: mutation.file.baseName, path: mutation.file.path, meta: mutation.file.meta, banner: output?.banner, footer: output?.footer, children: [
|
|
167
|
+
options.parser === "zod" && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [zod.schemas.response.name], root: mutation.file.path, path: zod.file.path }),
|
|
168
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: "useSWRMutation", path: importPath }),
|
|
169
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["SWRMutationResponse"], path: importPath, isTypeOnly: true }),
|
|
170
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: "client", path: options.client.importPath }),
|
|
171
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["RequestConfig", "ResponseConfig"], path: options.client.importPath, isTypeOnly: true }),
|
|
172
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
173
|
+
react.File.Import,
|
|
174
|
+
{
|
|
175
|
+
name: [
|
|
176
|
+
type.schemas.request?.name,
|
|
177
|
+
type.schemas.response.name,
|
|
178
|
+
type.schemas.pathParams?.name,
|
|
179
|
+
type.schemas.queryParams?.name,
|
|
180
|
+
type.schemas.headerParams?.name,
|
|
181
|
+
...type.schemas.statusCodes?.map((item) => item.name) || []
|
|
182
|
+
].filter(Boolean),
|
|
183
|
+
root: mutation.file.path,
|
|
184
|
+
path: type.file.path,
|
|
185
|
+
isTypeOnly: true
|
|
186
|
+
}
|
|
187
|
+
),
|
|
188
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
189
|
+
chunkAFAHUG3Q_cjs.MutationKey,
|
|
190
|
+
{
|
|
191
|
+
name: mutationKey.name,
|
|
192
|
+
typeName: mutationKey.typeName,
|
|
193
|
+
operation,
|
|
194
|
+
pathParamsType: options.pathParamsType,
|
|
195
|
+
typeSchemas: type.schemas,
|
|
196
|
+
transformer: options.mutationKey
|
|
197
|
+
}
|
|
198
|
+
),
|
|
199
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
200
|
+
components.Client,
|
|
201
|
+
{
|
|
202
|
+
name: client.name,
|
|
203
|
+
isExportable: false,
|
|
204
|
+
isIndexable: false,
|
|
205
|
+
baseURL: options.client.baseURL,
|
|
206
|
+
operation,
|
|
207
|
+
typeSchemas: type.schemas,
|
|
208
|
+
zodSchemas: zod.schemas,
|
|
209
|
+
dataReturnType: options.client.dataReturnType,
|
|
210
|
+
paramsType: options.paramsType,
|
|
211
|
+
pathParamsType: options.pathParamsType,
|
|
212
|
+
parser: options.parser
|
|
213
|
+
}
|
|
214
|
+
),
|
|
215
|
+
options.mutation && /* @__PURE__ */ jsxRuntime.jsx(
|
|
216
|
+
chunkAFAHUG3Q_cjs.Mutation,
|
|
217
|
+
{
|
|
218
|
+
name: mutation.name,
|
|
219
|
+
clientName: client.name,
|
|
220
|
+
typeName: mutation.typeName,
|
|
221
|
+
typeSchemas: type.schemas,
|
|
222
|
+
operation,
|
|
223
|
+
dataReturnType: options.client.dataReturnType,
|
|
224
|
+
paramsType: options.paramsType,
|
|
225
|
+
pathParamsType: options.pathParamsType,
|
|
226
|
+
mutationKeyName: mutationKey.name,
|
|
227
|
+
mutationKeyTypeName: mutationKey.typeName
|
|
228
|
+
}
|
|
229
|
+
)
|
|
230
|
+
] });
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
exports.mutationGenerator = mutationGenerator;
|
|
235
|
+
exports.queryGenerator = queryGenerator;
|
|
236
|
+
//# sourceMappingURL=chunk-64KLXAGI.cjs.map
|
|
237
|
+
//# sourceMappingURL=chunk-64KLXAGI.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/generators/queryGenerator.tsx","../src/generators/mutationGenerator.tsx"],"names":["createReactGenerator","useApp","useOperationManager","pluginClientName","pluginTsName","pluginZodName","File","jsx","QueryKey","Client","QueryOptions","jsxs","Fragment","Query","MutationKey","Mutation"],"mappings":";;;;;;;;;;;;AAWO,IAAM,iBAAiBA,8BAAgC,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;AAAA;AACpB,QACEC,YAAkB,EAAA;AACtB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,OAAA,KAAYC,yBAAoB,EAAA;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;AAC1I,IAAA,MAAM,UAAa,GAAA,OAAA,CAAQ,KAAQ,GAAA,OAAA,CAAQ,MAAM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,QAACE,iBAAAA;AAAA,QAAA;AAAA,UACC,MAAM,MAAO,CAAA,IAAA;AAAA,UACb,YAAc,EAAA,KAAA;AAAA,UACd,WAAa,EAAA,KAAA;AAAA,UACb,OAAA,EAAS,QAAQ,MAAO,CAAA,OAAA;AAAA,UACxB,SAAA;AAAA,UACA,aAAa,IAAK,CAAA,OAAA;AAAA,UAClB,YAAY,GAAI,CAAA,OAAA;AAAA,UAChB,cAAA,EAAgB,QAAQ,MAAO,CAAA,cAAA;AAAA,UAC/B,YAAY,OAAQ,CAAA,UAAA;AAAA,UACpB,gBAAgB,OAAQ,CAAA,cAAA;AAAA,UACxB,QAAQ,OAAQ,CAAA;AAAA;AAAA,OAClB;AAAA,MACC,OAAA,CAAQ,4BACPF,cAAAA;AAAA,QAACQ,0BAAA;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,YAAY,OAAQ,CAAA,UAAA;AAAA,UACpB,gBAAgB,OAAQ,CAAA,cAAA;AAAA,UACxB,iBAAiB,WAAY,CAAA,IAAA;AAAA,UAC7B,qBAAqB,WAAY,CAAA;AAAA;AAAA;AACnC,KAEJ,EAAA,CAAA;AAAA;AAGN,CAAC","file":"chunk-64KLXAGI.cjs","sourcesContent":["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 { Query, QueryOptions } from '../components'\nimport { QueryKey } 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 const importPath = options.query ? options.query.importPath : 'swr/mutation'\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: getName(operation, { type: 'function', suffix: 'QueryOptions' }),\n }\n const queryKey = {\n name: getName(operation, { type: 'const', suffix: 'QueryKey' }),\n typeName: getName(operation, { type: 'type', suffix: 'QueryKey' }),\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 name={[zod.schemas.response.name]} root={query.file.path} path={zod.file.path} />}\n\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 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 <QueryKey\n name={queryKey.name}\n typeName={queryKey.typeName}\n operation={operation}\n pathParamsType={options.pathParamsType}\n typeSchemas={type.schemas}\n transformer={options.queryKey}\n />\n <Client\n name={client.name}\n isExportable={false}\n isIndexable={false}\n baseURL={options.client.baseURL}\n operation={operation}\n typeSchemas={type.schemas}\n zodSchemas={zod.schemas}\n dataReturnType={options.client.dataReturnType}\n paramsType={options.paramsType}\n pathParamsType={options.pathParamsType}\n parser={options.parser}\n />\n <QueryOptions\n name={queryOptions.name}\n clientName={client.name}\n typeSchemas={type.schemas}\n paramsType={options.paramsType}\n pathParamsType={options.pathParamsType}\n />\n {options.query && (\n <>\n <File.Import name=\"useSWR\" path={importPath} />\n <File.Import name={['SWRResponse']} path={importPath} isTypeOnly />\n <Query\n name={query.name}\n queryOptionsName={queryOptions.name}\n typeSchemas={type.schemas}\n paramsType={options.paramsType}\n pathParamsType={options.pathParamsType}\n operation={operation}\n dataReturnType={options.client.dataReturnType}\n queryKeyName={queryKey.name}\n queryKeyTypeName={queryKey.typeName}\n />\n </>\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 { MutationKey } from '../components'\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 isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)\n const isMutation = !isQuery && options.mutation && options.mutation.methods.some((method) => operation.method === method)\n\n const importPath = options.mutation ? options.mutation.importPath : 'swr'\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 const mutationKey = {\n name: getName(operation, { type: 'const', suffix: 'MutationKey' }),\n typeName: getName(operation, { type: 'type', suffix: 'MutationKey' }),\n }\n\n if (!isMutation) {\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' && <File.Import name={[zod.schemas.response.name]} root={mutation.file.path} path={zod.file.path} />}\n <File.Import name=\"useSWRMutation\" path={importPath} />\n <File.Import name={['SWRMutationResponse']} path={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 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\n <MutationKey\n name={mutationKey.name}\n typeName={mutationKey.typeName}\n operation={operation}\n pathParamsType={options.pathParamsType}\n typeSchemas={type.schemas}\n transformer={options.mutationKey}\n />\n\n <Client\n name={client.name}\n isExportable={false}\n isIndexable={false}\n baseURL={options.client.baseURL}\n operation={operation}\n typeSchemas={type.schemas}\n zodSchemas={zod.schemas}\n dataReturnType={options.client.dataReturnType}\n paramsType={options.paramsType}\n pathParamsType={options.pathParamsType}\n parser={options.parser}\n />\n {options.mutation && (\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 paramsType={options.paramsType}\n pathParamsType={options.pathParamsType}\n mutationKeyName={mutationKey.name}\n mutationKeyTypeName={mutationKey.typeName}\n />\n )}\n </File>\n )\n },\n})\n"]}
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('@kubb/react');
|
|
4
|
+
var oas = require('@kubb/oas');
|
|
5
|
+
var components = require('@kubb/plugin-client/components');
|
|
6
|
+
var utils = require('@kubb/plugin-oas/utils');
|
|
7
|
+
var utils$1 = require('@kubb/core/utils');
|
|
8
|
+
var jsxRuntime = require('@kubb/react/jsx-runtime');
|
|
9
|
+
|
|
10
|
+
// src/components/Mutation.tsx
|
|
11
|
+
function getParams({}) {
|
|
12
|
+
return react.FunctionParams.factory({});
|
|
13
|
+
}
|
|
14
|
+
var getTransformer = ({ operation }) => {
|
|
15
|
+
const path = new utils$1.URLPath(operation.path);
|
|
16
|
+
return [JSON.stringify({ url: path.path })].filter(Boolean);
|
|
17
|
+
};
|
|
18
|
+
function MutationKey({ name, typeSchemas, pathParamsType, operation, typeName, transformer = getTransformer }) {
|
|
19
|
+
const params = getParams({ pathParamsType, typeSchemas });
|
|
20
|
+
const keys = transformer({ operation, schemas: typeSchemas });
|
|
21
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
22
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Function.Arrow, { name, export: true, params: params.toConstructor(), singleLine: true, children: `[${keys.join(", ")}] as const` }) }),
|
|
23
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: typeName, isExportable: true, isIndexable: true, isTypeOnly: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Type, { name: typeName, export: true, children: `ReturnType<typeof ${name}>` }) })
|
|
24
|
+
] });
|
|
25
|
+
}
|
|
26
|
+
MutationKey.getParams = getParams;
|
|
27
|
+
MutationKey.getTransformer = getTransformer;
|
|
28
|
+
function getParams2({ pathParamsType, dataReturnType, typeSchemas, mutationKeyTypeName }) {
|
|
29
|
+
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
30
|
+
return react.FunctionParams.factory({
|
|
31
|
+
pathParams: {
|
|
32
|
+
mode: pathParamsType === "object" ? "object" : "inlineSpread",
|
|
33
|
+
children: utils.getPathParams(typeSchemas.pathParams, { typed: true })
|
|
34
|
+
},
|
|
35
|
+
params: typeSchemas.queryParams?.name ? {
|
|
36
|
+
type: typeSchemas.queryParams?.name,
|
|
37
|
+
optional: oas.isOptional(typeSchemas.queryParams?.schema)
|
|
38
|
+
} : void 0,
|
|
39
|
+
headers: typeSchemas.headerParams?.name ? {
|
|
40
|
+
type: typeSchemas.headerParams?.name,
|
|
41
|
+
optional: oas.isOptional(typeSchemas.headerParams?.schema)
|
|
42
|
+
} : void 0,
|
|
43
|
+
options: {
|
|
44
|
+
type: `
|
|
45
|
+
{
|
|
46
|
+
mutation?: Parameters<typeof useSWRMutation<${[TData, typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error", mutationKeyTypeName, typeSchemas.request?.name].join(", ")}>>[2],
|
|
47
|
+
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : "Partial<RequestConfig>"},
|
|
48
|
+
shouldFetch?: boolean,
|
|
49
|
+
}
|
|
50
|
+
`,
|
|
51
|
+
default: "{}"
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function Mutation({
|
|
56
|
+
name,
|
|
57
|
+
clientName,
|
|
58
|
+
mutationKeyName,
|
|
59
|
+
mutationKeyTypeName,
|
|
60
|
+
paramsType,
|
|
61
|
+
pathParamsType,
|
|
62
|
+
dataReturnType,
|
|
63
|
+
typeSchemas,
|
|
64
|
+
operation
|
|
65
|
+
}) {
|
|
66
|
+
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
67
|
+
const generics = [
|
|
68
|
+
TData,
|
|
69
|
+
typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error",
|
|
70
|
+
`${mutationKeyTypeName} | null`,
|
|
71
|
+
typeSchemas.request?.name
|
|
72
|
+
//arg: data
|
|
73
|
+
].filter(Boolean);
|
|
74
|
+
const mutationKeyParams = MutationKey.getParams({
|
|
75
|
+
pathParamsType,
|
|
76
|
+
typeSchemas
|
|
77
|
+
});
|
|
78
|
+
const params = getParams2({
|
|
79
|
+
pathParamsType,
|
|
80
|
+
dataReturnType,
|
|
81
|
+
typeSchemas,
|
|
82
|
+
mutationKeyTypeName
|
|
83
|
+
});
|
|
84
|
+
const clientParams = components.Client.getParams({
|
|
85
|
+
paramsType,
|
|
86
|
+
typeSchemas,
|
|
87
|
+
pathParamsType
|
|
88
|
+
});
|
|
89
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
90
|
+
react.Function,
|
|
91
|
+
{
|
|
92
|
+
name,
|
|
93
|
+
export: true,
|
|
94
|
+
params: params.toConstructor(),
|
|
95
|
+
JSDoc: {
|
|
96
|
+
comments: utils.getComments(operation)
|
|
97
|
+
},
|
|
98
|
+
children: `
|
|
99
|
+
const { mutation: mutationOptions, client: config = {}, shouldFetch = true } = options ?? {}
|
|
100
|
+
const mutationKey = ${mutationKeyName}(${mutationKeyParams.toCall()})
|
|
101
|
+
|
|
102
|
+
return useSWRMutation<${generics}>(
|
|
103
|
+
shouldFetch ? mutationKey : null,
|
|
104
|
+
async (_url${typeSchemas.request?.name ? ", { arg: data }" : ""}) => {
|
|
105
|
+
return ${clientName}(${clientParams.toCall()})
|
|
106
|
+
},
|
|
107
|
+
mutationOptions
|
|
108
|
+
)
|
|
109
|
+
`
|
|
110
|
+
}
|
|
111
|
+
) });
|
|
112
|
+
}
|
|
113
|
+
function getParams3({ pathParamsType, typeSchemas }) {
|
|
114
|
+
return react.FunctionParams.factory({
|
|
115
|
+
pathParams: {
|
|
116
|
+
mode: pathParamsType === "object" ? "object" : "inlineSpread",
|
|
117
|
+
children: utils.getPathParams(typeSchemas.pathParams, { typed: true })
|
|
118
|
+
},
|
|
119
|
+
data: typeSchemas.request?.name ? {
|
|
120
|
+
type: typeSchemas.request?.name,
|
|
121
|
+
optional: oas.isOptional(typeSchemas.request?.schema)
|
|
122
|
+
} : void 0,
|
|
123
|
+
params: typeSchemas.queryParams?.name ? {
|
|
124
|
+
type: typeSchemas.queryParams?.name,
|
|
125
|
+
optional: oas.isOptional(typeSchemas.queryParams?.schema)
|
|
126
|
+
} : void 0
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
var getTransformer2 = ({ operation, schemas }) => {
|
|
130
|
+
const path = new utils$1.URLPath(operation.path);
|
|
131
|
+
const keys = [
|
|
132
|
+
path.toObject({
|
|
133
|
+
type: "path",
|
|
134
|
+
stringify: true
|
|
135
|
+
}),
|
|
136
|
+
schemas.queryParams?.name ? "...(params ? [params] : [])" : void 0,
|
|
137
|
+
schemas.request?.name ? "...(data ? [data] : [])" : void 0
|
|
138
|
+
].filter(Boolean);
|
|
139
|
+
return keys;
|
|
140
|
+
};
|
|
141
|
+
function QueryKey({ name, typeSchemas, pathParamsType, operation, typeName, transformer = getTransformer2 }) {
|
|
142
|
+
const params = getParams3({ pathParamsType, typeSchemas });
|
|
143
|
+
const keys = transformer({
|
|
144
|
+
operation,
|
|
145
|
+
schemas: typeSchemas
|
|
146
|
+
});
|
|
147
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
148
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Function.Arrow, { name, export: true, params: params.toConstructor(), singleLine: true, children: `[${keys.join(", ")}] as const` }) }),
|
|
149
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: typeName, isExportable: true, isIndexable: true, isTypeOnly: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Type, { name: typeName, export: true, children: `ReturnType<typeof ${name}>` }) })
|
|
150
|
+
] });
|
|
151
|
+
}
|
|
152
|
+
QueryKey.getParams = getParams3;
|
|
153
|
+
QueryKey.getTransformer = getTransformer2;
|
|
154
|
+
function getParams4({ paramsType, pathParamsType, typeSchemas }) {
|
|
155
|
+
if (paramsType === "object") {
|
|
156
|
+
return react.FunctionParams.factory({
|
|
157
|
+
data: {
|
|
158
|
+
mode: "object",
|
|
159
|
+
children: {
|
|
160
|
+
...utils.getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
161
|
+
data: typeSchemas.request?.name ? {
|
|
162
|
+
type: typeSchemas.request?.name,
|
|
163
|
+
optional: oas.isOptional(typeSchemas.request?.schema)
|
|
164
|
+
} : void 0,
|
|
165
|
+
params: typeSchemas.queryParams?.name ? {
|
|
166
|
+
type: typeSchemas.queryParams?.name,
|
|
167
|
+
optional: oas.isOptional(typeSchemas.queryParams?.schema)
|
|
168
|
+
} : void 0,
|
|
169
|
+
headers: typeSchemas.headerParams?.name ? {
|
|
170
|
+
type: typeSchemas.headerParams?.name,
|
|
171
|
+
optional: oas.isOptional(typeSchemas.headerParams?.schema)
|
|
172
|
+
} : void 0
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
config: {
|
|
176
|
+
type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : "Partial<RequestConfig>",
|
|
177
|
+
default: "{}"
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
return react.FunctionParams.factory({
|
|
182
|
+
pathParams: typeSchemas.pathParams?.name ? {
|
|
183
|
+
mode: pathParamsType === "object" ? "object" : "inlineSpread",
|
|
184
|
+
children: utils.getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
185
|
+
type: typeSchemas.pathParams?.name,
|
|
186
|
+
optional: oas.isOptional(typeSchemas.pathParams?.schema)
|
|
187
|
+
} : void 0,
|
|
188
|
+
data: typeSchemas.request?.name ? {
|
|
189
|
+
type: typeSchemas.request?.name,
|
|
190
|
+
optional: oas.isOptional(typeSchemas.request?.schema)
|
|
191
|
+
} : void 0,
|
|
192
|
+
params: typeSchemas.queryParams?.name ? {
|
|
193
|
+
type: typeSchemas.queryParams?.name,
|
|
194
|
+
optional: oas.isOptional(typeSchemas.queryParams?.schema)
|
|
195
|
+
} : void 0,
|
|
196
|
+
headers: typeSchemas.headerParams?.name ? {
|
|
197
|
+
type: typeSchemas.headerParams?.name,
|
|
198
|
+
optional: oas.isOptional(typeSchemas.headerParams?.schema)
|
|
199
|
+
} : void 0,
|
|
200
|
+
config: {
|
|
201
|
+
type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : "Partial<RequestConfig>",
|
|
202
|
+
default: "{}"
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
function QueryOptions({ name, clientName, typeSchemas, paramsType, pathParamsType }) {
|
|
207
|
+
const params = getParams4({ paramsType, pathParamsType, typeSchemas });
|
|
208
|
+
const clientParams = components.Client.getParams({
|
|
209
|
+
paramsType,
|
|
210
|
+
typeSchemas,
|
|
211
|
+
pathParamsType
|
|
212
|
+
});
|
|
213
|
+
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: `
|
|
214
|
+
return {
|
|
215
|
+
fetcher: async () => {
|
|
216
|
+
return ${clientName}(${clientParams.toCall()})
|
|
217
|
+
},
|
|
218
|
+
}
|
|
219
|
+
` }) });
|
|
220
|
+
}
|
|
221
|
+
QueryOptions.getParams = getParams4;
|
|
222
|
+
function getParams5({ paramsType, pathParamsType, dataReturnType, typeSchemas, queryKeyTypeName }) {
|
|
223
|
+
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
224
|
+
if (paramsType === "object") {
|
|
225
|
+
return react.FunctionParams.factory({
|
|
226
|
+
data: {
|
|
227
|
+
mode: "object",
|
|
228
|
+
children: {
|
|
229
|
+
...utils.getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
230
|
+
data: typeSchemas.request?.name ? {
|
|
231
|
+
type: typeSchemas.request?.name,
|
|
232
|
+
optional: oas.isOptional(typeSchemas.request?.schema)
|
|
233
|
+
} : void 0,
|
|
234
|
+
params: typeSchemas.queryParams?.name ? {
|
|
235
|
+
type: typeSchemas.queryParams?.name,
|
|
236
|
+
optional: oas.isOptional(typeSchemas.queryParams?.schema)
|
|
237
|
+
} : void 0,
|
|
238
|
+
headers: typeSchemas.headerParams?.name ? {
|
|
239
|
+
type: typeSchemas.headerParams?.name,
|
|
240
|
+
optional: oas.isOptional(typeSchemas.headerParams?.schema)
|
|
241
|
+
} : void 0
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
options: {
|
|
245
|
+
type: `
|
|
246
|
+
{
|
|
247
|
+
query?: Parameters<typeof useSWR<${[TData, typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error", `${queryKeyTypeName} | null`].join(", ")}, any>>[2],
|
|
248
|
+
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : "Partial<RequestConfig>"},
|
|
249
|
+
shouldFetch?: boolean,
|
|
250
|
+
}
|
|
251
|
+
`,
|
|
252
|
+
default: "{}"
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
return react.FunctionParams.factory({
|
|
257
|
+
pathParams: typeSchemas.pathParams?.name ? {
|
|
258
|
+
mode: pathParamsType === "object" ? "object" : "inlineSpread",
|
|
259
|
+
children: utils.getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
260
|
+
type: typeSchemas.pathParams?.name,
|
|
261
|
+
optional: oas.isOptional(typeSchemas.pathParams?.schema)
|
|
262
|
+
} : void 0,
|
|
263
|
+
data: typeSchemas.request?.name ? {
|
|
264
|
+
type: typeSchemas.request?.name,
|
|
265
|
+
optional: oas.isOptional(typeSchemas.request?.schema)
|
|
266
|
+
} : void 0,
|
|
267
|
+
params: typeSchemas.queryParams?.name ? {
|
|
268
|
+
type: typeSchemas.queryParams?.name,
|
|
269
|
+
optional: oas.isOptional(typeSchemas.queryParams?.schema)
|
|
270
|
+
} : void 0,
|
|
271
|
+
headers: typeSchemas.headerParams?.name ? {
|
|
272
|
+
type: typeSchemas.headerParams?.name,
|
|
273
|
+
optional: oas.isOptional(typeSchemas.headerParams?.schema)
|
|
274
|
+
} : void 0,
|
|
275
|
+
options: {
|
|
276
|
+
type: `
|
|
277
|
+
{
|
|
278
|
+
query?: Parameters<typeof useSWR<${[TData, typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error", `${queryKeyTypeName} | null`].join(", ")}, any>>[2],
|
|
279
|
+
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : "Partial<RequestConfig>"},
|
|
280
|
+
shouldFetch?: boolean,
|
|
281
|
+
}
|
|
282
|
+
`,
|
|
283
|
+
default: "{}"
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
function Query({
|
|
288
|
+
name,
|
|
289
|
+
typeSchemas,
|
|
290
|
+
queryKeyName,
|
|
291
|
+
queryKeyTypeName,
|
|
292
|
+
queryOptionsName,
|
|
293
|
+
operation,
|
|
294
|
+
dataReturnType,
|
|
295
|
+
paramsType,
|
|
296
|
+
pathParamsType
|
|
297
|
+
}) {
|
|
298
|
+
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
299
|
+
const generics = [TData, typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error", `${queryKeyTypeName} | null`];
|
|
300
|
+
const queryKeyParams = QueryKey.getParams({
|
|
301
|
+
pathParamsType,
|
|
302
|
+
typeSchemas
|
|
303
|
+
});
|
|
304
|
+
const params = getParams5({
|
|
305
|
+
paramsType,
|
|
306
|
+
pathParamsType,
|
|
307
|
+
dataReturnType,
|
|
308
|
+
typeSchemas,
|
|
309
|
+
queryKeyTypeName
|
|
310
|
+
});
|
|
311
|
+
const queryOptionsParams = QueryOptions.getParams({
|
|
312
|
+
paramsType,
|
|
313
|
+
pathParamsType,
|
|
314
|
+
typeSchemas
|
|
315
|
+
});
|
|
316
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
317
|
+
react.Function,
|
|
318
|
+
{
|
|
319
|
+
name,
|
|
320
|
+
export: true,
|
|
321
|
+
params: params.toConstructor(),
|
|
322
|
+
JSDoc: {
|
|
323
|
+
comments: utils.getComments(operation)
|
|
324
|
+
},
|
|
325
|
+
children: `
|
|
326
|
+
const { query: queryOptions, client: config = {}, shouldFetch = true } = options ?? {}
|
|
327
|
+
|
|
328
|
+
const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
|
|
329
|
+
|
|
330
|
+
return useSWR<${generics.join(", ")}>(
|
|
331
|
+
shouldFetch ? queryKey : null,
|
|
332
|
+
{
|
|
333
|
+
...${queryOptionsName}(${queryOptionsParams.toCall()})
|
|
334
|
+
...queryOptions
|
|
335
|
+
}
|
|
336
|
+
)
|
|
337
|
+
`
|
|
338
|
+
}
|
|
339
|
+
) });
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
exports.Mutation = Mutation;
|
|
343
|
+
exports.MutationKey = MutationKey;
|
|
344
|
+
exports.Query = Query;
|
|
345
|
+
exports.QueryKey = QueryKey;
|
|
346
|
+
exports.QueryOptions = QueryOptions;
|
|
347
|
+
//# sourceMappingURL=chunk-AFAHUG3Q.cjs.map
|
|
348
|
+
//# sourceMappingURL=chunk-AFAHUG3Q.cjs.map
|