@kubb/plugin-swr 5.0.0-alpha.34 → 5.0.0-alpha.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components-BJSzUg7M.cjs +955 -0
- package/dist/components-BJSzUg7M.cjs.map +1 -0
- package/dist/components-JQ2KRFCa.js +877 -0
- package/dist/components-JQ2KRFCa.js.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +77 -37
- package/dist/components.js +1 -1
- package/dist/generators-17ulS9mu.cjs +537 -0
- package/dist/generators-17ulS9mu.cjs.map +1 -0
- package/dist/generators-Cl7nr-FB.js +526 -0
- package/dist/generators-Cl7nr-FB.js.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +4 -4
- package/dist/generators.js +1 -1
- package/dist/index.cjs +132 -110
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +22 -2
- package/dist/index.js +132 -110
- package/dist/index.js.map +1 -1
- package/dist/{types-BVDtH9S7.d.ts → types-FA5mH9Ch.d.ts} +46 -90
- package/package.json +7 -11
- package/src/components/Mutation.tsx +165 -170
- package/src/components/MutationKey.tsx +50 -1
- package/src/components/Query.tsx +122 -126
- package/src/components/QueryKey.tsx +65 -1
- package/src/components/QueryOptions.tsx +38 -93
- package/src/generators/mutationGenerator.tsx +194 -117
- package/src/generators/queryGenerator.tsx +205 -139
- package/src/plugin.ts +117 -152
- package/src/resolvers/resolverSwr.ts +26 -0
- package/src/resolvers/resolverSwrLegacy.ts +17 -0
- package/src/types.ts +55 -18
- package/src/utils.ts +209 -0
- package/dist/components-DaCTPplv.js +0 -756
- package/dist/components-DaCTPplv.js.map +0 -1
- package/dist/components-Qs8_faOt.cjs +0 -834
- package/dist/components-Qs8_faOt.cjs.map +0 -1
- package/dist/generators-0YayIrse.js +0 -400
- package/dist/generators-0YayIrse.js.map +0 -1
- package/dist/generators-Bd4rCa3l.cjs +0 -411
- package/dist/generators-Bd4rCa3l.cjs.map +0 -1
|
@@ -1,756 +0,0 @@
|
|
|
1
|
-
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { FunctionParams } from "@kubb/core";
|
|
3
|
-
import { ClientLegacy } from "@kubb/plugin-client";
|
|
4
|
-
import { getDefaultValue, isOptional } from "@kubb/oas";
|
|
5
|
-
import { getComments, getPathParams } from "@kubb/plugin-oas/utils";
|
|
6
|
-
import { File, Function as Function$1, Type } from "@kubb/renderer-jsx";
|
|
7
|
-
import { Fragment, jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
|
|
8
|
-
//#region ../../internals/utils/src/casing.ts
|
|
9
|
-
/**
|
|
10
|
-
* Shared implementation for camelCase and PascalCase conversion.
|
|
11
|
-
* Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
|
|
12
|
-
* and capitalizes each word according to `pascal`.
|
|
13
|
-
*
|
|
14
|
-
* When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
|
|
15
|
-
*/
|
|
16
|
-
function toCamelOrPascal(text, pascal) {
|
|
17
|
-
return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
|
|
18
|
-
if (word.length > 1 && word === word.toUpperCase()) return word;
|
|
19
|
-
if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1);
|
|
20
|
-
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
21
|
-
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Splits `text` on `.` and applies `transformPart` to each segment.
|
|
25
|
-
* The last segment receives `isLast = true`, all earlier segments receive `false`.
|
|
26
|
-
* Segments are joined with `/` to form a file path.
|
|
27
|
-
*
|
|
28
|
-
* Only splits on dots followed by a letter so that version numbers
|
|
29
|
-
* embedded in operationIds (e.g. `v2025.0`) are kept intact.
|
|
30
|
-
*/
|
|
31
|
-
function applyToFileParts(text, transformPart) {
|
|
32
|
-
const parts = text.split(/\.(?=[a-zA-Z])/);
|
|
33
|
-
return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Converts `text` to camelCase.
|
|
37
|
-
* When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* camelCase('hello-world') // 'helloWorld'
|
|
41
|
-
* camelCase('pet.petId', { isFile: true }) // 'pet/petId'
|
|
42
|
-
*/
|
|
43
|
-
function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
44
|
-
if (isFile) return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? {
|
|
45
|
-
prefix,
|
|
46
|
-
suffix
|
|
47
|
-
} : {}));
|
|
48
|
-
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Converts `text` to PascalCase.
|
|
52
|
-
* When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* pascalCase('hello-world') // 'HelloWorld'
|
|
56
|
-
* pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'
|
|
57
|
-
*/
|
|
58
|
-
function pascalCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
59
|
-
if (isFile) return applyToFileParts(text, (part, isLast) => isLast ? pascalCase(part, {
|
|
60
|
-
prefix,
|
|
61
|
-
suffix
|
|
62
|
-
}) : camelCase(part));
|
|
63
|
-
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
|
|
64
|
-
}
|
|
65
|
-
//#endregion
|
|
66
|
-
//#region ../../internals/utils/src/reserved.ts
|
|
67
|
-
/**
|
|
68
|
-
* Returns `true` when `name` is a syntactically valid JavaScript variable name.
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```ts
|
|
72
|
-
* isValidVarName('status') // true
|
|
73
|
-
* isValidVarName('class') // false (reserved word)
|
|
74
|
-
* isValidVarName('42foo') // false (starts with digit)
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
function isValidVarName(name) {
|
|
78
|
-
try {
|
|
79
|
-
new Function(`var ${name}`);
|
|
80
|
-
} catch {
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
//#endregion
|
|
86
|
-
//#region ../../internals/utils/src/urlPath.ts
|
|
87
|
-
/**
|
|
88
|
-
* Parses and transforms an OpenAPI/Swagger path string into various URL formats.
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* const p = new URLPath('/pet/{petId}')
|
|
92
|
-
* p.URL // '/pet/:petId'
|
|
93
|
-
* p.template // '`/pet/${petId}`'
|
|
94
|
-
*/
|
|
95
|
-
var URLPath = class {
|
|
96
|
-
/**
|
|
97
|
-
* The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`.
|
|
98
|
-
*/
|
|
99
|
-
path;
|
|
100
|
-
#options;
|
|
101
|
-
constructor(path, options = {}) {
|
|
102
|
-
this.path = path;
|
|
103
|
-
this.#options = options;
|
|
104
|
-
}
|
|
105
|
-
/** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`.
|
|
106
|
-
*
|
|
107
|
-
* @example
|
|
108
|
-
* ```ts
|
|
109
|
-
* new URLPath('/pet/{petId}').URL // '/pet/:petId'
|
|
110
|
-
* ```
|
|
111
|
-
*/
|
|
112
|
-
get URL() {
|
|
113
|
-
return this.toURLPath();
|
|
114
|
-
}
|
|
115
|
-
/** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`).
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
118
|
-
* ```ts
|
|
119
|
-
* new URLPath('https://petstore.swagger.io/v2/pet').isURL // true
|
|
120
|
-
* new URLPath('/pet/{petId}').isURL // false
|
|
121
|
-
* ```
|
|
122
|
-
*/
|
|
123
|
-
get isURL() {
|
|
124
|
-
try {
|
|
125
|
-
return !!new URL(this.path).href;
|
|
126
|
-
} catch {
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Converts the OpenAPI path to a TypeScript template literal string.
|
|
132
|
-
*
|
|
133
|
-
* @example
|
|
134
|
-
* new URLPath('/pet/{petId}').template // '`/pet/${petId}`'
|
|
135
|
-
* new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'
|
|
136
|
-
*/
|
|
137
|
-
get template() {
|
|
138
|
-
return this.toTemplateString();
|
|
139
|
-
}
|
|
140
|
-
/** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set.
|
|
141
|
-
*
|
|
142
|
-
* @example
|
|
143
|
-
* ```ts
|
|
144
|
-
* new URLPath('/pet/{petId}').object
|
|
145
|
-
* // { url: '/pet/:petId', params: { petId: 'petId' } }
|
|
146
|
-
* ```
|
|
147
|
-
*/
|
|
148
|
-
get object() {
|
|
149
|
-
return this.toObject();
|
|
150
|
-
}
|
|
151
|
-
/** Returns a map of path parameter names, or `undefined` when the path has no parameters.
|
|
152
|
-
*
|
|
153
|
-
* @example
|
|
154
|
-
* ```ts
|
|
155
|
-
* new URLPath('/pet/{petId}').params // { petId: 'petId' }
|
|
156
|
-
* new URLPath('/pet').params // undefined
|
|
157
|
-
* ```
|
|
158
|
-
*/
|
|
159
|
-
get params() {
|
|
160
|
-
return this.getParams();
|
|
161
|
-
}
|
|
162
|
-
#transformParam(raw) {
|
|
163
|
-
const param = isValidVarName(raw) ? raw : camelCase(raw);
|
|
164
|
-
return this.#options.casing === "camelcase" ? camelCase(param) : param;
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name.
|
|
168
|
-
*/
|
|
169
|
-
#eachParam(fn) {
|
|
170
|
-
for (const match of this.path.matchAll(/\{([^}]+)\}/g)) {
|
|
171
|
-
const raw = match[1];
|
|
172
|
-
fn(raw, this.#transformParam(raw));
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
toObject({ type = "path", replacer, stringify } = {}) {
|
|
176
|
-
const object = {
|
|
177
|
-
url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
|
|
178
|
-
params: this.getParams()
|
|
179
|
-
};
|
|
180
|
-
if (stringify) {
|
|
181
|
-
if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
182
|
-
if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
|
|
183
|
-
return `{ url: '${object.url}' }`;
|
|
184
|
-
}
|
|
185
|
-
return object;
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Converts the OpenAPI path to a TypeScript template literal string.
|
|
189
|
-
* An optional `replacer` can transform each extracted parameter name before interpolation.
|
|
190
|
-
*
|
|
191
|
-
* @example
|
|
192
|
-
* new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
|
|
193
|
-
*/
|
|
194
|
-
toTemplateString({ prefix = "", replacer } = {}) {
|
|
195
|
-
return `\`${prefix}${this.path.split(/\{([^}]+)\}/).map((part, i) => {
|
|
196
|
-
if (i % 2 === 0) return part;
|
|
197
|
-
const param = this.#transformParam(part);
|
|
198
|
-
return `\${${replacer ? replacer(param) : param}}`;
|
|
199
|
-
}).join("")}\``;
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Extracts all `{param}` segments from the path and returns them as a key-value map.
|
|
203
|
-
* An optional `replacer` transforms each parameter name in both key and value positions.
|
|
204
|
-
* Returns `undefined` when no path parameters are found.
|
|
205
|
-
*
|
|
206
|
-
* @example
|
|
207
|
-
* ```ts
|
|
208
|
-
* new URLPath('/pet/{petId}/tag/{tagId}').getParams()
|
|
209
|
-
* // { petId: 'petId', tagId: 'tagId' }
|
|
210
|
-
* ```
|
|
211
|
-
*/
|
|
212
|
-
getParams(replacer) {
|
|
213
|
-
const params = {};
|
|
214
|
-
this.#eachParam((_raw, param) => {
|
|
215
|
-
const key = replacer ? replacer(param) : param;
|
|
216
|
-
params[key] = key;
|
|
217
|
-
});
|
|
218
|
-
return Object.keys(params).length > 0 ? params : void 0;
|
|
219
|
-
}
|
|
220
|
-
/** Converts the OpenAPI path to Express-style colon syntax.
|
|
221
|
-
*
|
|
222
|
-
* @example
|
|
223
|
-
* ```ts
|
|
224
|
-
* new URLPath('/pet/{petId}').toURLPath() // '/pet/:petId'
|
|
225
|
-
* ```
|
|
226
|
-
*/
|
|
227
|
-
toURLPath() {
|
|
228
|
-
return this.path.replace(/\{([^}]+)\}/g, ":$1");
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
//#endregion
|
|
232
|
-
//#region ../../internals/tanstack-query/src/components/MutationKey.tsx
|
|
233
|
-
function getParams$4({}) {
|
|
234
|
-
return FunctionParams.factory({});
|
|
235
|
-
}
|
|
236
|
-
__name(getParams$4, "getParams");
|
|
237
|
-
const getTransformer$1 = /* @__PURE__ */ __name(({ operation, casing }) => {
|
|
238
|
-
return [`{ url: '${new URLPath(operation.path, { casing }).toURLPath()}' }`];
|
|
239
|
-
}, "getTransformer");
|
|
240
|
-
function MutationKey({ name, typeSchemas, pathParamsType, paramsCasing, operation, typeName, transformer = getTransformer$1 }) {
|
|
241
|
-
const params = getParams$4({
|
|
242
|
-
pathParamsType,
|
|
243
|
-
typeSchemas
|
|
244
|
-
});
|
|
245
|
-
const keys = transformer({
|
|
246
|
-
operation,
|
|
247
|
-
schemas: typeSchemas,
|
|
248
|
-
casing: paramsCasing
|
|
249
|
-
});
|
|
250
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Source, {
|
|
251
|
-
name,
|
|
252
|
-
isExportable: true,
|
|
253
|
-
isIndexable: true,
|
|
254
|
-
children: /* @__PURE__ */ jsx(Function$1.Arrow, {
|
|
255
|
-
name,
|
|
256
|
-
export: true,
|
|
257
|
-
params: params.toConstructor(),
|
|
258
|
-
singleLine: true,
|
|
259
|
-
children: `[${keys.join(", ")}] as const`
|
|
260
|
-
})
|
|
261
|
-
}), /* @__PURE__ */ jsx(File.Source, {
|
|
262
|
-
name: typeName,
|
|
263
|
-
isExportable: true,
|
|
264
|
-
isIndexable: true,
|
|
265
|
-
isTypeOnly: true,
|
|
266
|
-
children: /* @__PURE__ */ jsx(Type, {
|
|
267
|
-
name: typeName,
|
|
268
|
-
export: true,
|
|
269
|
-
children: `ReturnType<typeof ${name}>`
|
|
270
|
-
})
|
|
271
|
-
})] });
|
|
272
|
-
}
|
|
273
|
-
MutationKey.getParams = getParams$4;
|
|
274
|
-
MutationKey.getTransformer = getTransformer$1;
|
|
275
|
-
//#endregion
|
|
276
|
-
//#region ../../internals/tanstack-query/src/components/QueryKey.tsx
|
|
277
|
-
function getParams$3({ pathParamsType, paramsCasing, typeSchemas }) {
|
|
278
|
-
return FunctionParams.factory({
|
|
279
|
-
pathParams: typeSchemas.pathParams?.name ? {
|
|
280
|
-
mode: pathParamsType === "object" ? "object" : "inlineSpread",
|
|
281
|
-
children: getPathParams(typeSchemas.pathParams, {
|
|
282
|
-
typed: true,
|
|
283
|
-
casing: paramsCasing
|
|
284
|
-
})
|
|
285
|
-
} : void 0,
|
|
286
|
-
data: typeSchemas.request?.name ? {
|
|
287
|
-
type: typeSchemas.request?.name,
|
|
288
|
-
optional: isOptional(typeSchemas.request?.schema)
|
|
289
|
-
} : void 0,
|
|
290
|
-
params: typeSchemas.queryParams?.name ? {
|
|
291
|
-
type: typeSchemas.queryParams?.name,
|
|
292
|
-
optional: isOptional(typeSchemas.queryParams?.schema)
|
|
293
|
-
} : void 0
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
__name(getParams$3, "getParams");
|
|
297
|
-
const getTransformer = ({ operation, schemas, casing }) => {
|
|
298
|
-
return [
|
|
299
|
-
new URLPath(operation.path, { casing }).toObject({
|
|
300
|
-
type: "path",
|
|
301
|
-
stringify: true
|
|
302
|
-
}),
|
|
303
|
-
schemas.queryParams?.name ? "...(params ? [params] : [])" : void 0,
|
|
304
|
-
schemas.request?.name ? "...(data ? [data] : [])" : void 0
|
|
305
|
-
].filter(Boolean);
|
|
306
|
-
};
|
|
307
|
-
function QueryKey({ name, typeSchemas, paramsCasing, pathParamsType, operation, typeName, transformer = getTransformer }) {
|
|
308
|
-
const params = getParams$3({
|
|
309
|
-
pathParamsType,
|
|
310
|
-
typeSchemas,
|
|
311
|
-
paramsCasing
|
|
312
|
-
});
|
|
313
|
-
const keys = transformer({
|
|
314
|
-
operation,
|
|
315
|
-
schemas: typeSchemas,
|
|
316
|
-
casing: paramsCasing
|
|
317
|
-
});
|
|
318
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Source, {
|
|
319
|
-
name,
|
|
320
|
-
isExportable: true,
|
|
321
|
-
isIndexable: true,
|
|
322
|
-
children: /* @__PURE__ */ jsx(Function$1.Arrow, {
|
|
323
|
-
name,
|
|
324
|
-
export: true,
|
|
325
|
-
params: params.toConstructor(),
|
|
326
|
-
singleLine: true,
|
|
327
|
-
children: `[${keys.join(", ")}] as const`
|
|
328
|
-
})
|
|
329
|
-
}), /* @__PURE__ */ jsx(File.Source, {
|
|
330
|
-
name: typeName,
|
|
331
|
-
isExportable: true,
|
|
332
|
-
isIndexable: true,
|
|
333
|
-
isTypeOnly: true,
|
|
334
|
-
children: /* @__PURE__ */ jsx(Type, {
|
|
335
|
-
name: typeName,
|
|
336
|
-
export: true,
|
|
337
|
-
children: `ReturnType<typeof ${name}>`
|
|
338
|
-
})
|
|
339
|
-
})] });
|
|
340
|
-
}
|
|
341
|
-
QueryKey.getParams = getParams$3;
|
|
342
|
-
QueryKey.getTransformer = getTransformer;
|
|
343
|
-
//#endregion
|
|
344
|
-
//#region src/components/Mutation.tsx
|
|
345
|
-
function getParams$2({ pathParamsType, paramsCasing, dataReturnType, typeSchemas, mutationKeyTypeName }) {
|
|
346
|
-
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
347
|
-
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
348
|
-
const TExtraArg = typeSchemas.request?.name || "never";
|
|
349
|
-
return FunctionParams.factory({
|
|
350
|
-
pathParams: {
|
|
351
|
-
mode: pathParamsType === "object" ? "object" : "inlineSpread",
|
|
352
|
-
children: getPathParams(typeSchemas.pathParams, {
|
|
353
|
-
typed: true,
|
|
354
|
-
casing: paramsCasing
|
|
355
|
-
})
|
|
356
|
-
},
|
|
357
|
-
params: typeSchemas.queryParams?.name ? {
|
|
358
|
-
type: typeSchemas.queryParams?.name,
|
|
359
|
-
optional: isOptional(typeSchemas.queryParams?.schema)
|
|
360
|
-
} : void 0,
|
|
361
|
-
headers: typeSchemas.headerParams?.name ? {
|
|
362
|
-
type: typeSchemas.headerParams?.name,
|
|
363
|
-
optional: isOptional(typeSchemas.headerParams?.schema)
|
|
364
|
-
} : void 0,
|
|
365
|
-
options: {
|
|
366
|
-
type: `
|
|
367
|
-
{
|
|
368
|
-
mutation?: SWRMutationConfiguration<${TData}, ${TError}, ${mutationKeyTypeName} | null, ${TExtraArg}> & { throwOnError?: boolean },
|
|
369
|
-
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"},
|
|
370
|
-
shouldFetch?: boolean,
|
|
371
|
-
}
|
|
372
|
-
`,
|
|
373
|
-
default: "{}"
|
|
374
|
-
}
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
__name(getParams$2, "getParams");
|
|
378
|
-
function getTriggerParams({ dataReturnType, typeSchemas, mutationKeyTypeName, mutationArgTypeName }) {
|
|
379
|
-
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
380
|
-
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
381
|
-
return FunctionParams.factory({ options: {
|
|
382
|
-
type: `
|
|
383
|
-
{
|
|
384
|
-
mutation?: SWRMutationConfiguration<${TData}, ${TError}, ${mutationKeyTypeName} | null, ${mutationArgTypeName}> & { throwOnError?: boolean },
|
|
385
|
-
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"},
|
|
386
|
-
shouldFetch?: boolean,
|
|
387
|
-
}
|
|
388
|
-
`,
|
|
389
|
-
default: "{}"
|
|
390
|
-
} });
|
|
391
|
-
}
|
|
392
|
-
function getMutationParams({ paramsCasing, typeSchemas }) {
|
|
393
|
-
return FunctionParams.factory({
|
|
394
|
-
...getPathParams(typeSchemas.pathParams, {
|
|
395
|
-
typed: true,
|
|
396
|
-
casing: paramsCasing
|
|
397
|
-
}),
|
|
398
|
-
data: typeSchemas.request?.name ? {
|
|
399
|
-
type: typeSchemas.request?.name,
|
|
400
|
-
optional: isOptional(typeSchemas.request?.schema)
|
|
401
|
-
} : void 0,
|
|
402
|
-
params: typeSchemas.queryParams?.name ? {
|
|
403
|
-
type: typeSchemas.queryParams?.name,
|
|
404
|
-
optional: isOptional(typeSchemas.queryParams?.schema)
|
|
405
|
-
} : void 0,
|
|
406
|
-
headers: typeSchemas.headerParams?.name ? {
|
|
407
|
-
type: typeSchemas.headerParams?.name,
|
|
408
|
-
optional: isOptional(typeSchemas.headerParams?.schema)
|
|
409
|
-
} : void 0
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
|
-
function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas, operation, paramsToTrigger = false }) {
|
|
413
|
-
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
414
|
-
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
415
|
-
const mutationKeyParams = MutationKey.getParams({
|
|
416
|
-
pathParamsType,
|
|
417
|
-
typeSchemas
|
|
418
|
-
});
|
|
419
|
-
const clientParams = ClientLegacy.getParams({
|
|
420
|
-
paramsCasing,
|
|
421
|
-
paramsType,
|
|
422
|
-
typeSchemas,
|
|
423
|
-
pathParamsType,
|
|
424
|
-
isConfigurable: true
|
|
425
|
-
});
|
|
426
|
-
if (paramsToTrigger) {
|
|
427
|
-
const mutationParams = getMutationParams({
|
|
428
|
-
paramsCasing,
|
|
429
|
-
typeSchemas
|
|
430
|
-
});
|
|
431
|
-
const mutationArgTypeName = `${mutationKeyTypeName.replace("MutationKey", "")}MutationArg`;
|
|
432
|
-
const hasMutationParams = Object.keys(mutationParams.params).length > 0;
|
|
433
|
-
const argParams = FunctionParams.factory({ data: {
|
|
434
|
-
mode: "object",
|
|
435
|
-
children: Object.entries(mutationParams.params).reduce((acc, [key, value]) => {
|
|
436
|
-
if (value) acc[key] = {
|
|
437
|
-
...value,
|
|
438
|
-
type: void 0
|
|
439
|
-
};
|
|
440
|
-
return acc;
|
|
441
|
-
}, {})
|
|
442
|
-
} });
|
|
443
|
-
const params = getTriggerParams({
|
|
444
|
-
dataReturnType,
|
|
445
|
-
typeSchemas,
|
|
446
|
-
mutationKeyTypeName,
|
|
447
|
-
mutationArgTypeName
|
|
448
|
-
});
|
|
449
|
-
const generics = [
|
|
450
|
-
TData,
|
|
451
|
-
TError,
|
|
452
|
-
`${mutationKeyTypeName} | null`,
|
|
453
|
-
mutationArgTypeName
|
|
454
|
-
].filter(Boolean);
|
|
455
|
-
const mutationArg = mutationParams.toConstructor();
|
|
456
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Source, {
|
|
457
|
-
name: mutationArgTypeName,
|
|
458
|
-
isExportable: true,
|
|
459
|
-
isIndexable: true,
|
|
460
|
-
isTypeOnly: true,
|
|
461
|
-
children: /* @__PURE__ */ jsx(Type, {
|
|
462
|
-
name: mutationArgTypeName,
|
|
463
|
-
export: true,
|
|
464
|
-
children: hasMutationParams ? `{${mutationArg}}` : "never"
|
|
465
|
-
})
|
|
466
|
-
}), /* @__PURE__ */ jsx(File.Source, {
|
|
467
|
-
name,
|
|
468
|
-
isExportable: true,
|
|
469
|
-
isIndexable: true,
|
|
470
|
-
children: /* @__PURE__ */ jsx(Function$1, {
|
|
471
|
-
name,
|
|
472
|
-
export: true,
|
|
473
|
-
params: params.toConstructor(),
|
|
474
|
-
JSDoc: { comments: getComments(operation) },
|
|
475
|
-
children: `
|
|
476
|
-
const { mutation: mutationOptions, client: config = {}, shouldFetch = true } = options ?? {}
|
|
477
|
-
const mutationKey = ${mutationKeyName}(${mutationKeyParams.toCall()})
|
|
478
|
-
|
|
479
|
-
return useSWRMutation<${generics.join(", ")}>(
|
|
480
|
-
shouldFetch ? mutationKey : null,
|
|
481
|
-
async (_url${hasMutationParams ? `, { arg: ${argParams.toCall()} }` : ""}) => {
|
|
482
|
-
return ${clientName}(${clientParams.toCall()})
|
|
483
|
-
},
|
|
484
|
-
mutationOptions
|
|
485
|
-
)
|
|
486
|
-
`
|
|
487
|
-
})
|
|
488
|
-
})] });
|
|
489
|
-
}
|
|
490
|
-
const generics = [
|
|
491
|
-
TData,
|
|
492
|
-
TError,
|
|
493
|
-
`${mutationKeyTypeName} | null`,
|
|
494
|
-
typeSchemas.request?.name
|
|
495
|
-
].filter(Boolean);
|
|
496
|
-
const params = getParams$2({
|
|
497
|
-
paramsCasing,
|
|
498
|
-
pathParamsType,
|
|
499
|
-
dataReturnType,
|
|
500
|
-
typeSchemas,
|
|
501
|
-
mutationKeyTypeName
|
|
502
|
-
});
|
|
503
|
-
return /* @__PURE__ */ jsx(File.Source, {
|
|
504
|
-
name,
|
|
505
|
-
isExportable: true,
|
|
506
|
-
isIndexable: true,
|
|
507
|
-
children: /* @__PURE__ */ jsx(Function$1, {
|
|
508
|
-
name,
|
|
509
|
-
export: true,
|
|
510
|
-
params: params.toConstructor(),
|
|
511
|
-
JSDoc: { comments: getComments(operation) },
|
|
512
|
-
children: `
|
|
513
|
-
const { mutation: mutationOptions, client: config = {}, shouldFetch = true } = options ?? {}
|
|
514
|
-
const mutationKey = ${mutationKeyName}(${mutationKeyParams.toCall()})
|
|
515
|
-
|
|
516
|
-
return useSWRMutation<${generics.join(", ")}>(
|
|
517
|
-
shouldFetch ? mutationKey : null,
|
|
518
|
-
async (_url${typeSchemas.request?.name ? ", { arg: data }" : ""}) => {
|
|
519
|
-
return ${clientName}(${clientParams.toCall()})
|
|
520
|
-
},
|
|
521
|
-
mutationOptions
|
|
522
|
-
)
|
|
523
|
-
`
|
|
524
|
-
})
|
|
525
|
-
});
|
|
526
|
-
}
|
|
527
|
-
//#endregion
|
|
528
|
-
//#region src/components/QueryOptions.tsx
|
|
529
|
-
function getParams$1({ paramsType, paramsCasing, pathParamsType, typeSchemas }) {
|
|
530
|
-
if (paramsType === "object") {
|
|
531
|
-
const pathParams = getPathParams(typeSchemas.pathParams, {
|
|
532
|
-
typed: true,
|
|
533
|
-
casing: paramsCasing
|
|
534
|
-
});
|
|
535
|
-
return FunctionParams.factory({
|
|
536
|
-
data: {
|
|
537
|
-
mode: "object",
|
|
538
|
-
children: {
|
|
539
|
-
...pathParams,
|
|
540
|
-
data: typeSchemas.request?.name ? {
|
|
541
|
-
type: typeSchemas.request?.name,
|
|
542
|
-
optional: isOptional(typeSchemas.request?.schema)
|
|
543
|
-
} : void 0,
|
|
544
|
-
params: typeSchemas.queryParams?.name ? {
|
|
545
|
-
type: typeSchemas.queryParams?.name,
|
|
546
|
-
optional: isOptional(typeSchemas.queryParams?.schema)
|
|
547
|
-
} : void 0,
|
|
548
|
-
headers: typeSchemas.headerParams?.name ? {
|
|
549
|
-
type: typeSchemas.headerParams?.name,
|
|
550
|
-
optional: isOptional(typeSchemas.headerParams?.schema)
|
|
551
|
-
} : void 0
|
|
552
|
-
}
|
|
553
|
-
},
|
|
554
|
-
config: {
|
|
555
|
-
type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }",
|
|
556
|
-
default: "{}"
|
|
557
|
-
}
|
|
558
|
-
});
|
|
559
|
-
}
|
|
560
|
-
return FunctionParams.factory({
|
|
561
|
-
pathParams: typeSchemas.pathParams?.name ? {
|
|
562
|
-
mode: pathParamsType === "object" ? "object" : "inlineSpread",
|
|
563
|
-
children: getPathParams(typeSchemas.pathParams, {
|
|
564
|
-
typed: true,
|
|
565
|
-
casing: paramsCasing
|
|
566
|
-
}),
|
|
567
|
-
default: getDefaultValue(typeSchemas.pathParams?.schema)
|
|
568
|
-
} : void 0,
|
|
569
|
-
data: typeSchemas.request?.name ? {
|
|
570
|
-
type: typeSchemas.request?.name,
|
|
571
|
-
optional: isOptional(typeSchemas.request?.schema)
|
|
572
|
-
} : void 0,
|
|
573
|
-
params: typeSchemas.queryParams?.name ? {
|
|
574
|
-
type: typeSchemas.queryParams?.name,
|
|
575
|
-
optional: isOptional(typeSchemas.queryParams?.schema)
|
|
576
|
-
} : void 0,
|
|
577
|
-
headers: typeSchemas.headerParams?.name ? {
|
|
578
|
-
type: typeSchemas.headerParams?.name,
|
|
579
|
-
optional: isOptional(typeSchemas.headerParams?.schema)
|
|
580
|
-
} : void 0,
|
|
581
|
-
config: {
|
|
582
|
-
type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }",
|
|
583
|
-
default: "{}"
|
|
584
|
-
}
|
|
585
|
-
});
|
|
586
|
-
}
|
|
587
|
-
__name(getParams$1, "getParams");
|
|
588
|
-
function QueryOptions({ name, clientName, typeSchemas, paramsCasing, paramsType, pathParamsType }) {
|
|
589
|
-
const params = getParams$1({
|
|
590
|
-
paramsType,
|
|
591
|
-
paramsCasing,
|
|
592
|
-
pathParamsType,
|
|
593
|
-
typeSchemas
|
|
594
|
-
});
|
|
595
|
-
const clientParams = ClientLegacy.getParams({
|
|
596
|
-
paramsCasing,
|
|
597
|
-
paramsType,
|
|
598
|
-
typeSchemas,
|
|
599
|
-
pathParamsType,
|
|
600
|
-
isConfigurable: true
|
|
601
|
-
});
|
|
602
|
-
return /* @__PURE__ */ jsx(File.Source, {
|
|
603
|
-
name,
|
|
604
|
-
isExportable: true,
|
|
605
|
-
isIndexable: true,
|
|
606
|
-
children: /* @__PURE__ */ jsx(Function$1, {
|
|
607
|
-
name,
|
|
608
|
-
export: true,
|
|
609
|
-
params: params.toConstructor(),
|
|
610
|
-
children: `
|
|
611
|
-
return {
|
|
612
|
-
fetcher: async () => {
|
|
613
|
-
return ${clientName}(${clientParams.toCall()})
|
|
614
|
-
},
|
|
615
|
-
}
|
|
616
|
-
`
|
|
617
|
-
})
|
|
618
|
-
});
|
|
619
|
-
}
|
|
620
|
-
QueryOptions.getParams = getParams$1;
|
|
621
|
-
//#endregion
|
|
622
|
-
//#region src/components/Query.tsx
|
|
623
|
-
function getParams({ paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas }) {
|
|
624
|
-
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
625
|
-
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
626
|
-
if (paramsType === "object") {
|
|
627
|
-
const children = {
|
|
628
|
-
...getPathParams(typeSchemas.pathParams, {
|
|
629
|
-
typed: true,
|
|
630
|
-
casing: paramsCasing
|
|
631
|
-
}),
|
|
632
|
-
data: typeSchemas.request?.name ? {
|
|
633
|
-
type: typeSchemas.request?.name,
|
|
634
|
-
optional: isOptional(typeSchemas.request?.schema)
|
|
635
|
-
} : void 0,
|
|
636
|
-
params: typeSchemas.queryParams?.name ? {
|
|
637
|
-
type: typeSchemas.queryParams?.name,
|
|
638
|
-
optional: isOptional(typeSchemas.queryParams?.schema)
|
|
639
|
-
} : void 0,
|
|
640
|
-
headers: typeSchemas.headerParams?.name ? {
|
|
641
|
-
type: typeSchemas.headerParams?.name,
|
|
642
|
-
optional: isOptional(typeSchemas.headerParams?.schema)
|
|
643
|
-
} : void 0
|
|
644
|
-
};
|
|
645
|
-
const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional);
|
|
646
|
-
return FunctionParams.factory({
|
|
647
|
-
data: {
|
|
648
|
-
mode: "object",
|
|
649
|
-
children,
|
|
650
|
-
default: allChildrenAreOptional ? "{}" : void 0
|
|
651
|
-
},
|
|
652
|
-
options: {
|
|
653
|
-
type: `
|
|
654
|
-
{
|
|
655
|
-
query?: Parameters<typeof useSWR<${[TData, TError].join(", ")}>>[2],
|
|
656
|
-
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"},
|
|
657
|
-
shouldFetch?: boolean,
|
|
658
|
-
immutable?: boolean
|
|
659
|
-
}
|
|
660
|
-
`,
|
|
661
|
-
default: "{}"
|
|
662
|
-
}
|
|
663
|
-
});
|
|
664
|
-
}
|
|
665
|
-
return FunctionParams.factory({
|
|
666
|
-
pathParams: typeSchemas.pathParams?.name ? {
|
|
667
|
-
mode: pathParamsType === "object" ? "object" : "inlineSpread",
|
|
668
|
-
children: getPathParams(typeSchemas.pathParams, {
|
|
669
|
-
typed: true,
|
|
670
|
-
casing: paramsCasing
|
|
671
|
-
}),
|
|
672
|
-
default: getDefaultValue(typeSchemas.pathParams?.schema)
|
|
673
|
-
} : void 0,
|
|
674
|
-
data: typeSchemas.request?.name ? {
|
|
675
|
-
type: typeSchemas.request?.name,
|
|
676
|
-
optional: isOptional(typeSchemas.request?.schema)
|
|
677
|
-
} : void 0,
|
|
678
|
-
params: typeSchemas.queryParams?.name ? {
|
|
679
|
-
type: typeSchemas.queryParams?.name,
|
|
680
|
-
optional: isOptional(typeSchemas.queryParams?.schema)
|
|
681
|
-
} : void 0,
|
|
682
|
-
headers: typeSchemas.headerParams?.name ? {
|
|
683
|
-
type: typeSchemas.headerParams?.name,
|
|
684
|
-
optional: isOptional(typeSchemas.headerParams?.schema)
|
|
685
|
-
} : void 0,
|
|
686
|
-
options: {
|
|
687
|
-
type: `
|
|
688
|
-
{
|
|
689
|
-
query?: Parameters<typeof useSWR<${[TData, TError].join(", ")}>>[2],
|
|
690
|
-
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"},
|
|
691
|
-
shouldFetch?: boolean,
|
|
692
|
-
immutable?: boolean
|
|
693
|
-
}
|
|
694
|
-
`,
|
|
695
|
-
default: "{}"
|
|
696
|
-
}
|
|
697
|
-
});
|
|
698
|
-
}
|
|
699
|
-
function Query({ name, typeSchemas, queryKeyName, queryKeyTypeName, queryOptionsName, operation, dataReturnType, paramsType, paramsCasing, pathParamsType }) {
|
|
700
|
-
const generics = [
|
|
701
|
-
dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`,
|
|
702
|
-
`ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`,
|
|
703
|
-
`${queryKeyTypeName} | null`
|
|
704
|
-
];
|
|
705
|
-
const queryKeyParams = QueryKey.getParams({
|
|
706
|
-
pathParamsType,
|
|
707
|
-
typeSchemas,
|
|
708
|
-
paramsCasing
|
|
709
|
-
});
|
|
710
|
-
const params = getParams({
|
|
711
|
-
paramsCasing,
|
|
712
|
-
paramsType,
|
|
713
|
-
pathParamsType,
|
|
714
|
-
dataReturnType,
|
|
715
|
-
typeSchemas
|
|
716
|
-
});
|
|
717
|
-
const queryOptionsParams = QueryOptions.getParams({
|
|
718
|
-
paramsCasing,
|
|
719
|
-
paramsType,
|
|
720
|
-
pathParamsType,
|
|
721
|
-
typeSchemas
|
|
722
|
-
});
|
|
723
|
-
return /* @__PURE__ */ jsx(File.Source, {
|
|
724
|
-
name,
|
|
725
|
-
isExportable: true,
|
|
726
|
-
isIndexable: true,
|
|
727
|
-
children: /* @__PURE__ */ jsx(Function$1, {
|
|
728
|
-
name,
|
|
729
|
-
export: true,
|
|
730
|
-
params: params.toConstructor(),
|
|
731
|
-
JSDoc: { comments: getComments(operation) },
|
|
732
|
-
children: `
|
|
733
|
-
const { query: queryOptions, client: config = {}, shouldFetch = true, immutable } = options ?? {}
|
|
734
|
-
|
|
735
|
-
const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
|
|
736
|
-
|
|
737
|
-
return useSWR<${generics.join(", ")}>(
|
|
738
|
-
shouldFetch ? queryKey : null,
|
|
739
|
-
{
|
|
740
|
-
...${queryOptionsName}(${queryOptionsParams.toCall()}),
|
|
741
|
-
...(immutable ? {
|
|
742
|
-
revalidateIfStale: false,
|
|
743
|
-
revalidateOnFocus: false,
|
|
744
|
-
revalidateOnReconnect: false
|
|
745
|
-
} : { }),
|
|
746
|
-
...queryOptions
|
|
747
|
-
}
|
|
748
|
-
)
|
|
749
|
-
`
|
|
750
|
-
})
|
|
751
|
-
});
|
|
752
|
-
}
|
|
753
|
-
//#endregion
|
|
754
|
-
export { MutationKey as a, QueryKey as i, QueryOptions as n, camelCase as o, Mutation as r, pascalCase as s, Query as t };
|
|
755
|
-
|
|
756
|
-
//# sourceMappingURL=components-DaCTPplv.js.map
|