@kubb/plugin-swr 3.16.1 → 3.16.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components-BQIcQmn3.js +435 -0
- package/dist/components-BQIcQmn3.js.map +1 -0
- package/dist/components-Zv6v8ZAm.cjs +493 -0
- package/dist/components-Zv6v8ZAm.cjs.map +1 -0
- package/dist/components.cjs +6 -27
- package/dist/components.d.cts +177 -78
- package/dist/components.d.ts +177 -78
- package/dist/components.js +3 -3
- package/dist/generators-B-fWjDXL.js +328 -0
- package/dist/generators-B-fWjDXL.js.map +1 -0
- package/dist/generators-ByyKDjyt.cjs +339 -0
- package/dist/generators-ByyKDjyt.cjs.map +1 -0
- package/dist/generators.cjs +4 -16
- package/dist/generators.d.cts +8 -9
- package/dist/generators.d.ts +8 -9
- package/dist/generators.js +4 -4
- package/dist/index.cjs +107 -136
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -8
- package/dist/index.d.ts +6 -8
- package/dist/index.js +107 -130
- package/dist/index.js.map +1 -1
- package/dist/types-CSnGy9Uj.d.ts +1355 -0
- package/dist/types-CjDGkyWH.d.cts +1355 -0
- package/package.json +25 -30
- package/dist/chunk-2N4Q32XH.cjs +0 -285
- package/dist/chunk-2N4Q32XH.cjs.map +0 -1
- package/dist/chunk-GWLPXHRE.js +0 -282
- package/dist/chunk-GWLPXHRE.js.map +0 -1
- package/dist/chunk-MNOTKHSE.cjs +0 -367
- package/dist/chunk-MNOTKHSE.cjs.map +0 -1
- package/dist/chunk-RZTUH4QW.js +0 -361
- package/dist/chunk-RZTUH4QW.js.map +0 -1
- package/dist/components.cjs.map +0 -1
- package/dist/components.js.map +0 -1
- package/dist/generators.cjs.map +0 -1
- package/dist/generators.js.map +0 -1
- package/dist/types-DVQ2siUx.d.cts +0 -134
- package/dist/types-DVQ2siUx.d.ts +0 -134
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
const __kubb_react = __toESM(require("@kubb/react"));
|
|
25
|
+
const __kubb_oas = __toESM(require("@kubb/oas"));
|
|
26
|
+
const __kubb_plugin_client_components = __toESM(require("@kubb/plugin-client/components"));
|
|
27
|
+
const __kubb_plugin_oas_utils = __toESM(require("@kubb/plugin-oas/utils"));
|
|
28
|
+
const __kubb_core_utils = __toESM(require("@kubb/core/utils"));
|
|
29
|
+
const __kubb_react_jsx_runtime = __toESM(require("@kubb/react/jsx-runtime"));
|
|
30
|
+
|
|
31
|
+
//#region src/components/MutationKey.tsx
|
|
32
|
+
function getParams$4({}) {
|
|
33
|
+
return __kubb_react.FunctionParams.factory({});
|
|
34
|
+
}
|
|
35
|
+
const getTransformer$1 = ({ operation, casing }) => {
|
|
36
|
+
const path = new __kubb_core_utils.URLPath(operation.path, { casing });
|
|
37
|
+
return [JSON.stringify({ url: path.path })].filter(Boolean);
|
|
38
|
+
};
|
|
39
|
+
function MutationKey({ name, typeSchemas, paramsCasing, pathParamsType, operation, typeName, transformer = getTransformer$1 }) {
|
|
40
|
+
const params = getParams$4({
|
|
41
|
+
pathParamsType,
|
|
42
|
+
typeSchemas
|
|
43
|
+
});
|
|
44
|
+
const keys = transformer({
|
|
45
|
+
operation,
|
|
46
|
+
schemas: typeSchemas,
|
|
47
|
+
casing: paramsCasing
|
|
48
|
+
});
|
|
49
|
+
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Source, {
|
|
50
|
+
name,
|
|
51
|
+
isExportable: true,
|
|
52
|
+
isIndexable: true,
|
|
53
|
+
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.Function.Arrow, {
|
|
54
|
+
name,
|
|
55
|
+
export: true,
|
|
56
|
+
params: params.toConstructor(),
|
|
57
|
+
singleLine: true,
|
|
58
|
+
children: `[${keys.join(", ")}] as const`
|
|
59
|
+
})
|
|
60
|
+
}), /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Source, {
|
|
61
|
+
name: typeName,
|
|
62
|
+
isExportable: true,
|
|
63
|
+
isIndexable: true,
|
|
64
|
+
isTypeOnly: true,
|
|
65
|
+
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.Type, {
|
|
66
|
+
name: typeName,
|
|
67
|
+
export: true,
|
|
68
|
+
children: `ReturnType<typeof ${name}>`
|
|
69
|
+
})
|
|
70
|
+
})] });
|
|
71
|
+
}
|
|
72
|
+
MutationKey.getParams = getParams$4;
|
|
73
|
+
MutationKey.getTransformer = getTransformer$1;
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/components/Mutation.tsx
|
|
77
|
+
function getParams$3({ pathParamsType, paramsCasing, dataReturnType, typeSchemas, mutationKeyTypeName }) {
|
|
78
|
+
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
79
|
+
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
80
|
+
return __kubb_react.FunctionParams.factory({
|
|
81
|
+
pathParams: {
|
|
82
|
+
mode: pathParamsType === "object" ? "object" : "inlineSpread",
|
|
83
|
+
children: (0, __kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
|
|
84
|
+
typed: true,
|
|
85
|
+
casing: paramsCasing
|
|
86
|
+
})
|
|
87
|
+
},
|
|
88
|
+
params: typeSchemas.queryParams?.name ? {
|
|
89
|
+
type: typeSchemas.queryParams?.name,
|
|
90
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
|
|
91
|
+
} : void 0,
|
|
92
|
+
headers: typeSchemas.headerParams?.name ? {
|
|
93
|
+
type: typeSchemas.headerParams?.name,
|
|
94
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
|
|
95
|
+
} : void 0,
|
|
96
|
+
options: {
|
|
97
|
+
type: `
|
|
98
|
+
{
|
|
99
|
+
mutation?: Parameters<typeof useSWRMutation<${[
|
|
100
|
+
TData,
|
|
101
|
+
TError,
|
|
102
|
+
mutationKeyTypeName,
|
|
103
|
+
typeSchemas.request?.name
|
|
104
|
+
].join(", ")}>>[2],
|
|
105
|
+
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }"},
|
|
106
|
+
shouldFetch?: boolean,
|
|
107
|
+
}
|
|
108
|
+
`,
|
|
109
|
+
default: "{}"
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas, operation }) {
|
|
114
|
+
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
115
|
+
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
116
|
+
const generics = [
|
|
117
|
+
TData,
|
|
118
|
+
TError,
|
|
119
|
+
`${mutationKeyTypeName} | null`,
|
|
120
|
+
typeSchemas.request?.name
|
|
121
|
+
].filter(Boolean);
|
|
122
|
+
const mutationKeyParams = MutationKey.getParams({
|
|
123
|
+
pathParamsType,
|
|
124
|
+
typeSchemas
|
|
125
|
+
});
|
|
126
|
+
const params = getParams$3({
|
|
127
|
+
paramsCasing,
|
|
128
|
+
pathParamsType,
|
|
129
|
+
dataReturnType,
|
|
130
|
+
typeSchemas,
|
|
131
|
+
mutationKeyTypeName
|
|
132
|
+
});
|
|
133
|
+
const clientParams = __kubb_plugin_client_components.Client.getParams({
|
|
134
|
+
paramsCasing,
|
|
135
|
+
paramsType,
|
|
136
|
+
typeSchemas,
|
|
137
|
+
pathParamsType,
|
|
138
|
+
isConfigurable: true
|
|
139
|
+
});
|
|
140
|
+
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Source, {
|
|
141
|
+
name,
|
|
142
|
+
isExportable: true,
|
|
143
|
+
isIndexable: true,
|
|
144
|
+
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.Function, {
|
|
145
|
+
name,
|
|
146
|
+
export: true,
|
|
147
|
+
params: params.toConstructor(),
|
|
148
|
+
JSDoc: { comments: (0, __kubb_plugin_oas_utils.getComments)(operation) },
|
|
149
|
+
children: `
|
|
150
|
+
const { mutation: mutationOptions, client: config = {}, shouldFetch = true } = options ?? {}
|
|
151
|
+
const mutationKey = ${mutationKeyName}(${mutationKeyParams.toCall()})
|
|
152
|
+
|
|
153
|
+
return useSWRMutation<${generics}>(
|
|
154
|
+
shouldFetch ? mutationKey : null,
|
|
155
|
+
async (_url${typeSchemas.request?.name ? ", { arg: data }" : ""}) => {
|
|
156
|
+
return ${clientName}(${clientParams.toCall()})
|
|
157
|
+
},
|
|
158
|
+
mutationOptions
|
|
159
|
+
)
|
|
160
|
+
`
|
|
161
|
+
})
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
//#endregion
|
|
166
|
+
//#region src/components/QueryKey.tsx
|
|
167
|
+
function getParams$2({ pathParamsType, paramsCasing, typeSchemas }) {
|
|
168
|
+
return __kubb_react.FunctionParams.factory({
|
|
169
|
+
pathParams: {
|
|
170
|
+
mode: pathParamsType === "object" ? "object" : "inlineSpread",
|
|
171
|
+
children: (0, __kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
|
|
172
|
+
typed: true,
|
|
173
|
+
casing: paramsCasing
|
|
174
|
+
})
|
|
175
|
+
},
|
|
176
|
+
data: typeSchemas.request?.name ? {
|
|
177
|
+
type: typeSchemas.request?.name,
|
|
178
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.request?.schema)
|
|
179
|
+
} : void 0,
|
|
180
|
+
params: typeSchemas.queryParams?.name ? {
|
|
181
|
+
type: typeSchemas.queryParams?.name,
|
|
182
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
|
|
183
|
+
} : void 0
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
const getTransformer = ({ operation, schemas, casing }) => {
|
|
187
|
+
const path = new __kubb_core_utils.URLPath(operation.path, { casing });
|
|
188
|
+
const keys = [
|
|
189
|
+
path.toObject({
|
|
190
|
+
type: "path",
|
|
191
|
+
stringify: true
|
|
192
|
+
}),
|
|
193
|
+
schemas.queryParams?.name ? "...(params ? [params] : [])" : void 0,
|
|
194
|
+
schemas.request?.name ? "...(data ? [data] : [])" : void 0
|
|
195
|
+
].filter(Boolean);
|
|
196
|
+
return keys;
|
|
197
|
+
};
|
|
198
|
+
function QueryKey({ name, typeSchemas, paramsCasing, pathParamsType, operation, typeName, transformer = getTransformer }) {
|
|
199
|
+
const params = getParams$2({
|
|
200
|
+
pathParamsType,
|
|
201
|
+
paramsCasing,
|
|
202
|
+
typeSchemas
|
|
203
|
+
});
|
|
204
|
+
const keys = transformer({
|
|
205
|
+
operation,
|
|
206
|
+
schemas: typeSchemas,
|
|
207
|
+
casing: paramsCasing
|
|
208
|
+
});
|
|
209
|
+
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Source, {
|
|
210
|
+
name,
|
|
211
|
+
isExportable: true,
|
|
212
|
+
isIndexable: true,
|
|
213
|
+
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.Function.Arrow, {
|
|
214
|
+
name,
|
|
215
|
+
export: true,
|
|
216
|
+
params: params.toConstructor(),
|
|
217
|
+
singleLine: true,
|
|
218
|
+
children: `[${keys.join(", ")}] as const`
|
|
219
|
+
})
|
|
220
|
+
}), /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Source, {
|
|
221
|
+
name: typeName,
|
|
222
|
+
isExportable: true,
|
|
223
|
+
isIndexable: true,
|
|
224
|
+
isTypeOnly: true,
|
|
225
|
+
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.Type, {
|
|
226
|
+
name: typeName,
|
|
227
|
+
export: true,
|
|
228
|
+
children: `ReturnType<typeof ${name}>`
|
|
229
|
+
})
|
|
230
|
+
})] });
|
|
231
|
+
}
|
|
232
|
+
QueryKey.getParams = getParams$2;
|
|
233
|
+
QueryKey.getTransformer = getTransformer;
|
|
234
|
+
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region src/components/QueryOptions.tsx
|
|
237
|
+
function getParams$1({ paramsType, paramsCasing, pathParamsType, typeSchemas }) {
|
|
238
|
+
if (paramsType === "object") return __kubb_react.FunctionParams.factory({
|
|
239
|
+
data: {
|
|
240
|
+
mode: "object",
|
|
241
|
+
children: {
|
|
242
|
+
...(0, __kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
|
|
243
|
+
typed: true,
|
|
244
|
+
casing: paramsCasing
|
|
245
|
+
}),
|
|
246
|
+
data: typeSchemas.request?.name ? {
|
|
247
|
+
type: typeSchemas.request?.name,
|
|
248
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.request?.schema)
|
|
249
|
+
} : void 0,
|
|
250
|
+
params: typeSchemas.queryParams?.name ? {
|
|
251
|
+
type: typeSchemas.queryParams?.name,
|
|
252
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
|
|
253
|
+
} : void 0,
|
|
254
|
+
headers: typeSchemas.headerParams?.name ? {
|
|
255
|
+
type: typeSchemas.headerParams?.name,
|
|
256
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
|
|
257
|
+
} : void 0
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
config: {
|
|
261
|
+
type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }",
|
|
262
|
+
default: "{}"
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
return __kubb_react.FunctionParams.factory({
|
|
266
|
+
pathParams: typeSchemas.pathParams?.name ? {
|
|
267
|
+
mode: pathParamsType === "object" ? "object" : "inlineSpread",
|
|
268
|
+
children: (0, __kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
|
|
269
|
+
typed: true,
|
|
270
|
+
casing: paramsCasing
|
|
271
|
+
}),
|
|
272
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.pathParams?.schema)
|
|
273
|
+
} : void 0,
|
|
274
|
+
data: typeSchemas.request?.name ? {
|
|
275
|
+
type: typeSchemas.request?.name,
|
|
276
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.request?.schema)
|
|
277
|
+
} : void 0,
|
|
278
|
+
params: typeSchemas.queryParams?.name ? {
|
|
279
|
+
type: typeSchemas.queryParams?.name,
|
|
280
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
|
|
281
|
+
} : void 0,
|
|
282
|
+
headers: typeSchemas.headerParams?.name ? {
|
|
283
|
+
type: typeSchemas.headerParams?.name,
|
|
284
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
|
|
285
|
+
} : void 0,
|
|
286
|
+
config: {
|
|
287
|
+
type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }",
|
|
288
|
+
default: "{}"
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
function QueryOptions({ name, clientName, typeSchemas, paramsCasing, paramsType, pathParamsType }) {
|
|
293
|
+
const params = getParams$1({
|
|
294
|
+
paramsType,
|
|
295
|
+
paramsCasing,
|
|
296
|
+
pathParamsType,
|
|
297
|
+
typeSchemas
|
|
298
|
+
});
|
|
299
|
+
const clientParams = __kubb_plugin_client_components.Client.getParams({
|
|
300
|
+
paramsCasing,
|
|
301
|
+
paramsType,
|
|
302
|
+
typeSchemas,
|
|
303
|
+
pathParamsType,
|
|
304
|
+
isConfigurable: true
|
|
305
|
+
});
|
|
306
|
+
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Source, {
|
|
307
|
+
name,
|
|
308
|
+
isExportable: true,
|
|
309
|
+
isIndexable: true,
|
|
310
|
+
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.Function, {
|
|
311
|
+
name,
|
|
312
|
+
export: true,
|
|
313
|
+
params: params.toConstructor(),
|
|
314
|
+
children: `
|
|
315
|
+
return {
|
|
316
|
+
fetcher: async () => {
|
|
317
|
+
return ${clientName}(${clientParams.toCall()})
|
|
318
|
+
},
|
|
319
|
+
}
|
|
320
|
+
`
|
|
321
|
+
})
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
QueryOptions.getParams = getParams$1;
|
|
325
|
+
|
|
326
|
+
//#endregion
|
|
327
|
+
//#region src/components/Query.tsx
|
|
328
|
+
function getParams({ paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas }) {
|
|
329
|
+
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
330
|
+
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
331
|
+
if (paramsType === "object") return __kubb_react.FunctionParams.factory({
|
|
332
|
+
data: {
|
|
333
|
+
mode: "object",
|
|
334
|
+
children: {
|
|
335
|
+
...(0, __kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
|
|
336
|
+
typed: true,
|
|
337
|
+
casing: paramsCasing
|
|
338
|
+
}),
|
|
339
|
+
data: typeSchemas.request?.name ? {
|
|
340
|
+
type: typeSchemas.request?.name,
|
|
341
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.request?.schema)
|
|
342
|
+
} : void 0,
|
|
343
|
+
params: typeSchemas.queryParams?.name ? {
|
|
344
|
+
type: typeSchemas.queryParams?.name,
|
|
345
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
|
|
346
|
+
} : void 0,
|
|
347
|
+
headers: typeSchemas.headerParams?.name ? {
|
|
348
|
+
type: typeSchemas.headerParams?.name,
|
|
349
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
|
|
350
|
+
} : void 0
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
options: {
|
|
354
|
+
type: `
|
|
355
|
+
{
|
|
356
|
+
query?: Parameters<typeof useSWR<${[TData, TError].join(", ")}>>[2],
|
|
357
|
+
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }"},
|
|
358
|
+
shouldFetch?: boolean,
|
|
359
|
+
immutable?: boolean
|
|
360
|
+
}
|
|
361
|
+
`,
|
|
362
|
+
default: "{}"
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
return __kubb_react.FunctionParams.factory({
|
|
366
|
+
pathParams: typeSchemas.pathParams?.name ? {
|
|
367
|
+
mode: pathParamsType === "object" ? "object" : "inlineSpread",
|
|
368
|
+
children: (0, __kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
|
|
369
|
+
typed: true,
|
|
370
|
+
casing: paramsCasing
|
|
371
|
+
}),
|
|
372
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.pathParams?.schema)
|
|
373
|
+
} : void 0,
|
|
374
|
+
data: typeSchemas.request?.name ? {
|
|
375
|
+
type: typeSchemas.request?.name,
|
|
376
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.request?.schema)
|
|
377
|
+
} : void 0,
|
|
378
|
+
params: typeSchemas.queryParams?.name ? {
|
|
379
|
+
type: typeSchemas.queryParams?.name,
|
|
380
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
|
|
381
|
+
} : void 0,
|
|
382
|
+
headers: typeSchemas.headerParams?.name ? {
|
|
383
|
+
type: typeSchemas.headerParams?.name,
|
|
384
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
|
|
385
|
+
} : void 0,
|
|
386
|
+
options: {
|
|
387
|
+
type: `
|
|
388
|
+
{
|
|
389
|
+
query?: Parameters<typeof useSWR<${[TData, TError].join(", ")}>>[2],
|
|
390
|
+
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }"},
|
|
391
|
+
shouldFetch?: boolean,
|
|
392
|
+
immutable?: boolean
|
|
393
|
+
}
|
|
394
|
+
`,
|
|
395
|
+
default: "{}"
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
function Query({ name, typeSchemas, queryKeyName, queryKeyTypeName, queryOptionsName, operation, dataReturnType, paramsType, paramsCasing, pathParamsType }) {
|
|
400
|
+
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
401
|
+
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
402
|
+
const generics = [
|
|
403
|
+
TData,
|
|
404
|
+
TError,
|
|
405
|
+
`${queryKeyTypeName} | null`
|
|
406
|
+
];
|
|
407
|
+
const queryKeyParams = QueryKey.getParams({
|
|
408
|
+
pathParamsType,
|
|
409
|
+
typeSchemas,
|
|
410
|
+
paramsCasing
|
|
411
|
+
});
|
|
412
|
+
const params = getParams({
|
|
413
|
+
paramsCasing,
|
|
414
|
+
paramsType,
|
|
415
|
+
pathParamsType,
|
|
416
|
+
dataReturnType,
|
|
417
|
+
typeSchemas
|
|
418
|
+
});
|
|
419
|
+
const queryOptionsParams = QueryOptions.getParams({
|
|
420
|
+
paramsCasing,
|
|
421
|
+
paramsType,
|
|
422
|
+
pathParamsType,
|
|
423
|
+
typeSchemas
|
|
424
|
+
});
|
|
425
|
+
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Source, {
|
|
426
|
+
name,
|
|
427
|
+
isExportable: true,
|
|
428
|
+
isIndexable: true,
|
|
429
|
+
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.Function, {
|
|
430
|
+
name,
|
|
431
|
+
export: true,
|
|
432
|
+
params: params.toConstructor(),
|
|
433
|
+
JSDoc: { comments: (0, __kubb_plugin_oas_utils.getComments)(operation) },
|
|
434
|
+
children: `
|
|
435
|
+
const { query: queryOptions, client: config = {}, shouldFetch = true, immutable } = options ?? {}
|
|
436
|
+
|
|
437
|
+
const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
|
|
438
|
+
|
|
439
|
+
return useSWR<${generics.join(", ")}>(
|
|
440
|
+
shouldFetch ? queryKey : null,
|
|
441
|
+
{
|
|
442
|
+
...${queryOptionsName}(${queryOptionsParams.toCall()}),
|
|
443
|
+
...(immutable ? {
|
|
444
|
+
revalidateIfStale: false,
|
|
445
|
+
revalidateOnFocus: false,
|
|
446
|
+
revalidateOnReconnect: false
|
|
447
|
+
} : { }),
|
|
448
|
+
...queryOptions
|
|
449
|
+
}
|
|
450
|
+
)
|
|
451
|
+
`
|
|
452
|
+
})
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
//#endregion
|
|
457
|
+
Object.defineProperty(exports, 'Mutation', {
|
|
458
|
+
enumerable: true,
|
|
459
|
+
get: function () {
|
|
460
|
+
return Mutation;
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
Object.defineProperty(exports, 'MutationKey', {
|
|
464
|
+
enumerable: true,
|
|
465
|
+
get: function () {
|
|
466
|
+
return MutationKey;
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
Object.defineProperty(exports, 'Query', {
|
|
470
|
+
enumerable: true,
|
|
471
|
+
get: function () {
|
|
472
|
+
return Query;
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
Object.defineProperty(exports, 'QueryKey', {
|
|
476
|
+
enumerable: true,
|
|
477
|
+
get: function () {
|
|
478
|
+
return QueryKey;
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
Object.defineProperty(exports, 'QueryOptions', {
|
|
482
|
+
enumerable: true,
|
|
483
|
+
get: function () {
|
|
484
|
+
return QueryOptions;
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
Object.defineProperty(exports, '__toESM', {
|
|
488
|
+
enumerable: true,
|
|
489
|
+
get: function () {
|
|
490
|
+
return __toESM;
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
//# sourceMappingURL=components-Zv6v8ZAm.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components-Zv6v8ZAm.cjs","names":["getParams","FunctionParams","getTransformer: Transformer","URLPath","getTransformer","File","Function","Type","getParams","FunctionParams","Client","File","Function","getParams","FunctionParams","getTransformer: Transformer","URLPath","File","Function","Type","getParams","FunctionParams","Client","File","Function","FunctionParams","File","Function"],"sources":["../src/components/MutationKey.tsx","../src/components/Mutation.tsx","../src/components/QueryKey.tsx","../src/components/QueryOptions.tsx","../src/components/Query.tsx"],"sourcesContent":["import { URLPath } from '@kubb/core/utils'\nimport { File, Function, FunctionParams, Type } from '@kubb/react'\n\nimport type { Operation } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport type { ReactNode } from 'react'\nimport type { PluginSwr, Transformer } from '../types'\n\ntype Props = {\n name: string\n typeName: string\n typeSchemas: OperationSchemas\n operation: Operation\n paramsCasing: PluginSwr['resolvedOptions']['paramsCasing']\n pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']\n transformer: Transformer | undefined\n}\n\ntype GetParamsProps = {\n pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']\n typeSchemas: OperationSchemas\n}\n\nfunction getParams({}: GetParamsProps) {\n return FunctionParams.factory({})\n}\n\nconst getTransformer: Transformer = ({ operation, casing }) => {\n const path = new URLPath(operation.path, { casing })\n\n return [JSON.stringify({ url: path.path })].filter(Boolean)\n}\n\nexport function MutationKey({ name, typeSchemas, paramsCasing, pathParamsType, operation, typeName, transformer = getTransformer }: Props): ReactNode {\n const params = getParams({ pathParamsType, typeSchemas })\n const keys = transformer({ operation, schemas: typeSchemas, casing: paramsCasing })\n\n return (\n <>\n <File.Source name={name} isExportable isIndexable>\n <Function.Arrow name={name} export params={params.toConstructor()} singleLine>\n {`[${keys.join(', ')}] as const`}\n </Function.Arrow>\n </File.Source>\n <File.Source name={typeName} isExportable isIndexable isTypeOnly>\n <Type name={typeName} export>\n {`ReturnType<typeof ${name}>`}\n </Type>\n </File.Source>\n </>\n )\n}\n\nMutationKey.getParams = getParams\nMutationKey.getTransformer = getTransformer\n","import { 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'\nimport { MutationKey } from './MutationKey.tsx'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n clientName: string\n mutationKeyName: string\n mutationKeyTypeName: string\n typeSchemas: OperationSchemas\n operation: Operation\n paramsCasing: PluginSwr['resolvedOptions']['paramsCasing']\n paramsType: PluginSwr['resolvedOptions']['paramsType']\n dataReturnType: PluginSwr['resolvedOptions']['client']['dataReturnType']\n pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']\n}\n\ntype GetParamsProps = {\n paramsCasing: PluginSwr['resolvedOptions']['paramsCasing']\n pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']\n dataReturnType: PluginSwr['resolvedOptions']['client']['dataReturnType']\n typeSchemas: OperationSchemas\n mutationKeyTypeName: string\n}\n// TODO add same logic as being done for react-query mutations\nfunction getParams({ pathParamsType, paramsCasing, dataReturnType, typeSchemas, mutationKeyTypeName }: GetParamsProps) {\n const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`\n const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`\n\n return FunctionParams.factory({\n pathParams: {\n mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',\n children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\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?: Parameters<typeof useSWRMutation<${[TData, TError, mutationKeyTypeName, typeSchemas.request?.name].join(', ')}>>[2],\n client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : 'Partial<RequestConfig> & { client?: typeof fetch }'},\n shouldFetch?: boolean,\n}\n`,\n default: '{}',\n },\n })\n}\n\nexport function Mutation({\n name,\n clientName,\n mutationKeyName,\n mutationKeyTypeName,\n paramsType,\n paramsCasing,\n pathParamsType,\n dataReturnType,\n typeSchemas,\n operation,\n}: Props): ReactNode {\n const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`\n const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`\n\n const generics = [\n TData,\n TError,\n `${mutationKeyTypeName} | null`,\n typeSchemas.request?.name, //arg: data\n ].filter(Boolean)\n\n const mutationKeyParams = MutationKey.getParams({\n pathParamsType,\n typeSchemas,\n })\n\n const params = getParams({\n paramsCasing,\n pathParamsType,\n dataReturnType,\n typeSchemas,\n mutationKeyTypeName,\n })\n\n const clientParams = Client.getParams({\n paramsCasing,\n paramsType,\n typeSchemas,\n pathParamsType,\n isConfigurable: true,\n })\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 const mutationKey = ${mutationKeyName}(${mutationKeyParams.toCall()})\n\n return useSWRMutation<${generics}>(\n shouldFetch ? mutationKey : 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 { URLPath } from '@kubb/core/utils'\nimport { getPathParams } from '@kubb/plugin-oas/utils'\nimport { File, Function, FunctionParams, Type } from '@kubb/react'\n\nimport { type Operation, isOptional } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport type { ReactNode } from 'react'\nimport type { PluginSwr, Transformer } from '../types'\n\ntype Props = {\n name: string\n typeName: string\n typeSchemas: OperationSchemas\n operation: Operation\n paramsCasing: PluginSwr['resolvedOptions']['paramsCasing']\n pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']\n transformer: Transformer | undefined\n}\n\ntype GetParamsProps = {\n paramsCasing: PluginSwr['resolvedOptions']['paramsCasing']\n pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']\n typeSchemas: OperationSchemas\n}\n\nfunction getParams({ pathParamsType, paramsCasing, typeSchemas }: GetParamsProps) {\n return FunctionParams.factory({\n pathParams: {\n mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',\n children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\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 })\n}\n\nconst getTransformer: Transformer = ({ operation, schemas, casing }) => {\n const path = new URLPath(operation.path, { casing })\n const keys = [\n path.toObject({\n type: 'path',\n stringify: true,\n }),\n schemas.queryParams?.name ? '...(params ? [params] : [])' : undefined,\n schemas.request?.name ? '...(data ? [data] : [])' : undefined,\n ].filter(Boolean)\n\n return keys\n}\n\nexport function QueryKey({ name, typeSchemas, paramsCasing, pathParamsType, operation, typeName, transformer = getTransformer }: Props): ReactNode {\n const params = getParams({ pathParamsType, paramsCasing, typeSchemas })\n const keys = transformer({\n operation,\n schemas: typeSchemas,\n casing: paramsCasing,\n })\n\n return (\n <>\n <File.Source name={name} isExportable isIndexable>\n <Function.Arrow name={name} export params={params.toConstructor()} singleLine>\n {`[${keys.join(', ')}] as const`}\n </Function.Arrow>\n </File.Source>\n <File.Source name={typeName} isExportable isIndexable isTypeOnly>\n <Type name={typeName} export>\n {`ReturnType<typeof ${name}>`}\n </Type>\n </File.Source>\n </>\n )\n}\n\nQueryKey.getParams = getParams\nQueryKey.getTransformer = getTransformer\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 paramsCasing: PluginSwr['resolvedOptions']['paramsCasing']\n paramsType: PluginSwr['resolvedOptions']['paramsType']\n pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']\n}\n\ntype GetParamsProps = {\n paramsType: PluginSwr['resolvedOptions']['paramsType']\n paramsCasing: PluginSwr['resolvedOptions']['paramsCasing']\n pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']\n typeSchemas: OperationSchemas\n}\n\nfunction getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps) {\n if (paramsType === 'object') {\n return FunctionParams.factory({\n data: {\n mode: 'object',\n children: {\n ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\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 },\n },\n config: {\n type: typeSchemas.request?.name\n ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }`\n : 'Partial<RequestConfig> & { client?: typeof fetch }',\n default: '{}',\n },\n })\n }\n\n return FunctionParams.factory({\n pathParams: typeSchemas.pathParams?.name\n ? {\n mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',\n children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\n optional: isOptional(typeSchemas.pathParams?.schema),\n }\n : undefined,\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\n ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }`\n : 'Partial<RequestConfig> & { client?: typeof fetch }',\n default: '{}',\n },\n })\n}\n\nexport function QueryOptions({ name, clientName, typeSchemas, paramsCasing, paramsType, pathParamsType }: Props): ReactNode {\n const params = getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas })\n const clientParams = Client.getParams({\n paramsCasing,\n paramsType,\n typeSchemas,\n pathParamsType,\n isConfigurable: true,\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 { 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 { QueryKey } from './QueryKey.tsx'\nimport { QueryOptions } from './QueryOptions.tsx'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n queryOptionsName: string\n queryKeyName: string\n queryKeyTypeName: string\n typeSchemas: OperationSchemas\n paramsCasing: PluginSwr['resolvedOptions']['paramsCasing']\n paramsType: PluginSwr['resolvedOptions']['paramsType']\n pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']\n dataReturnType: PluginSwr['resolvedOptions']['client']['dataReturnType']\n operation: Operation\n}\n\ntype GetParamsProps = {\n paramsCasing: PluginSwr['resolvedOptions']['paramsCasing']\n paramsType: PluginSwr['resolvedOptions']['paramsType']\n pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']\n dataReturnType: PluginSwr['resolvedOptions']['client']['dataReturnType']\n typeSchemas: OperationSchemas\n}\n\nfunction getParams({ paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas }: GetParamsProps) {\n const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`\n const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`\n\n if (paramsType === 'object') {\n return FunctionParams.factory({\n data: {\n mode: 'object',\n children: {\n ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\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 },\n },\n options: {\n type: `\n{\n query?: Parameters<typeof useSWR<${[TData, TError].join(', ')}>>[2],\n client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : 'Partial<RequestConfig> & { client?: typeof fetch }'},\n shouldFetch?: boolean,\n immutable?: boolean\n}\n`,\n default: '{}',\n },\n })\n }\n\n return FunctionParams.factory({\n pathParams: typeSchemas.pathParams?.name\n ? {\n mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',\n children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\n optional: isOptional(typeSchemas.pathParams?.schema),\n }\n : undefined,\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?: Parameters<typeof useSWR<${[TData, TError].join(', ')}>>[2],\n client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : 'Partial<RequestConfig> & { client?: typeof fetch }'},\n shouldFetch?: boolean,\n immutable?: boolean\n}\n`,\n default: '{}',\n },\n })\n}\n\nexport function Query({\n name,\n typeSchemas,\n queryKeyName,\n queryKeyTypeName,\n queryOptionsName,\n operation,\n dataReturnType,\n paramsType,\n paramsCasing,\n pathParamsType,\n}: Props): ReactNode {\n const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`\n const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`\n const generics = [TData, TError, `${queryKeyTypeName} | null`]\n\n const queryKeyParams = QueryKey.getParams({\n pathParamsType,\n typeSchemas,\n paramsCasing,\n })\n const params = getParams({\n paramsCasing,\n paramsType,\n pathParamsType,\n dataReturnType,\n typeSchemas,\n })\n\n const queryOptionsParams = QueryOptions.getParams({\n paramsCasing,\n paramsType,\n pathParamsType,\n typeSchemas,\n })\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, immutable } = options ?? {}\n\n const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})\n\n return useSWR<${generics.join(', ')}>(\n shouldFetch ? queryKey : null,\n {\n ...${queryOptionsName}(${queryOptionsParams.toCall()}),\n ...(immutable ? {\n revalidateIfStale: false,\n revalidateOnFocus: false,\n revalidateOnReconnect: false\n } : { }),\n ...queryOptions\n }\n )\n `}\n </Function>\n </File.Source>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAASA,YAAU,EAAkB,EAAE;AACrC,QAAOC,4BAAe,QAAQ,CAAE,EAAC;AAClC;AAED,MAAMC,mBAA8B,CAAC,EAAE,WAAW,QAAQ,KAAK;CAC7D,MAAM,OAAO,IAAIC,0BAAQ,UAAU,MAAM,EAAE,OAAQ;AAEnD,QAAO,CAAC,KAAK,UAAU,EAAE,KAAK,KAAK,KAAM,EAAC,AAAC,EAAC,OAAO,QAAQ;AAC5D;AAED,SAAgB,YAAY,EAAE,MAAM,aAAa,cAAc,gBAAgB,WAAW,UAAU,cAAcC,kBAAuB,EAAa;CACpJ,MAAM,SAASJ,YAAU;EAAE;EAAgB;CAAa,EAAC;CACzD,MAAM,OAAO,YAAY;EAAE;EAAW,SAAS;EAAa,QAAQ;CAAc,EAAC;AAEnF,6JAEKK,kBAAK;EAAa;EAAM;EAAa;8DACnCC,sBAAS;GAAY;GAAM;GAAO,QAAQ,OAAO,eAAe;GAAE;aAChE,CAAC,CAAC,EAAE,KAAK,KAAK,KAAK,CAAC,UAAU,CAAC;IACjB;GACL,oDACbD,kBAAK;EAAO,MAAM;EAAU;EAAa;EAAY;8DACnDE;GAAK,MAAM;GAAU;aACnB,CAA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AC,EAAE,mBAAmB,QAAQ,CAAC;;;;;;;;;OASxD,CAAC;IACS;GACC;AAEjB"}
|
package/dist/components.cjs
CHANGED
|
@@ -1,28 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
const require_components = require('./components-Zv6v8ZAm.cjs');
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function () { return chunkMNOTKHSE_cjs.Mutation; }
|
|
10
|
-
});
|
|
11
|
-
Object.defineProperty(exports, "MutationKey", {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: function () { return chunkMNOTKHSE_cjs.MutationKey; }
|
|
14
|
-
});
|
|
15
|
-
Object.defineProperty(exports, "Query", {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
get: function () { return chunkMNOTKHSE_cjs.Query; }
|
|
18
|
-
});
|
|
19
|
-
Object.defineProperty(exports, "QueryKey", {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
get: function () { return chunkMNOTKHSE_cjs.QueryKey; }
|
|
22
|
-
});
|
|
23
|
-
Object.defineProperty(exports, "QueryOptions", {
|
|
24
|
-
enumerable: true,
|
|
25
|
-
get: function () { return chunkMNOTKHSE_cjs.QueryOptions; }
|
|
26
|
-
});
|
|
27
|
-
//# sourceMappingURL=components.cjs.map
|
|
28
|
-
//# sourceMappingURL=components.cjs.map
|
|
3
|
+
exports.Mutation = require_components.Mutation;
|
|
4
|
+
exports.MutationKey = require_components.MutationKey;
|
|
5
|
+
exports.Query = require_components.Query;
|
|
6
|
+
exports.QueryKey = require_components.QueryKey;
|
|
7
|
+
exports.QueryOptions = require_components.QueryOptions;
|