@kubb/plugin-react-query 5.0.0-beta.76 → 5.0.0-beta.79
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/index.cjs +74 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +74 -32
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -91,7 +91,7 @@ function toFilePath(name, caseLast = camelCase) {
|
|
|
91
91
|
* JavaScript and Java reserved words.
|
|
92
92
|
* @link https://github.com/jonschlinkert/reserved/blob/master/index.js
|
|
93
93
|
*/
|
|
94
|
-
const reservedWords = new Set([
|
|
94
|
+
const reservedWords = /* @__PURE__ */ new Set([
|
|
95
95
|
"abstract",
|
|
96
96
|
"arguments",
|
|
97
97
|
"boolean",
|
|
@@ -320,6 +320,23 @@ function caseParams(params, casing) {
|
|
|
320
320
|
caseParamsCache.set(params, result);
|
|
321
321
|
return result;
|
|
322
322
|
}
|
|
323
|
+
/**
|
|
324
|
+
* Drops parameters that collapse to the same property identity once camelCased, keeping the first.
|
|
325
|
+
*
|
|
326
|
+
* Some specs declare the same parameter twice under different casings (for example AWS S3 lists both
|
|
327
|
+
* `max-uploads` and `MaxUploads`). Both resolve to one output property, so emitting both would yield
|
|
328
|
+
* an object type with a duplicate member, which TypeScript rejects. De-duplicate by the camelCased
|
|
329
|
+
* identity so the resulting group is collision-free regardless of the names each caller carries.
|
|
330
|
+
*/
|
|
331
|
+
function dedupeByCasedName(params) {
|
|
332
|
+
const seen = /* @__PURE__ */ new Set();
|
|
333
|
+
return params.filter((param) => {
|
|
334
|
+
const key = camelCase(param.name);
|
|
335
|
+
if (seen.has(key)) return false;
|
|
336
|
+
seen.add(key);
|
|
337
|
+
return true;
|
|
338
|
+
});
|
|
339
|
+
}
|
|
323
340
|
//#endregion
|
|
324
341
|
//#region ../../internals/shared/src/operation.ts
|
|
325
342
|
/**
|
|
@@ -358,11 +375,27 @@ function getContentTypeInfo(node) {
|
|
|
358
375
|
hasFormData: contentTypes.some((ct) => ct === "multipart/form-data")
|
|
359
376
|
};
|
|
360
377
|
}
|
|
378
|
+
/**
|
|
379
|
+
* The request-body counterpart for the primary success response: the content types it documents and
|
|
380
|
+
* whether several are present, so the client can let a caller pick which one to accept.
|
|
381
|
+
*/
|
|
382
|
+
function getResponseContentTypeInfo(node) {
|
|
383
|
+
const contentTypes = getPrimarySuccessResponse(node)?.content?.map((e) => e.contentType) ?? [];
|
|
384
|
+
const isMultipleContentTypes = contentTypes.length > 1;
|
|
385
|
+
return {
|
|
386
|
+
contentTypes,
|
|
387
|
+
isMultipleContentTypes,
|
|
388
|
+
contentTypeUnion: isMultipleContentTypes ? contentTypes.map((ct) => JSON.stringify(ct)).join(" | ") : "",
|
|
389
|
+
defaultContentType: contentTypes[0] ?? "application/json",
|
|
390
|
+
hasFormData: contentTypes.some((ct) => ct === "multipart/form-data")
|
|
391
|
+
};
|
|
392
|
+
}
|
|
361
393
|
function buildRequestConfigType(node) {
|
|
362
|
-
const
|
|
394
|
+
const request = getContentTypeInfo(node);
|
|
395
|
+
const response = getResponseContentTypeInfo(node);
|
|
363
396
|
const configType = `Partial<Omit<RequestConfig, 'path' | 'query' | 'body' | 'headers' | 'url'>>`;
|
|
364
|
-
const
|
|
365
|
-
return
|
|
397
|
+
const members = [request.isMultipleContentTypes ? `request?: ${request.contentTypeUnion}` : null, response.isMultipleContentTypes ? `response?: ${response.contentTypeUnion}` : null].filter(Boolean);
|
|
398
|
+
return members.length ? `${configType} & { contentType?: { ${members.join("; ")} } }` : configType;
|
|
366
399
|
}
|
|
367
400
|
/**
|
|
368
401
|
* Builds the `client?:` option type shared by the generated query hooks (`useQuery`,
|
|
@@ -424,10 +457,10 @@ function buildOperationComments(node, options = {}) {
|
|
|
424
457
|
function getOperationParameters(node, options = {}) {
|
|
425
458
|
const params = caseParams(node.parameters, options.paramsCasing === "original" ? void 0 : "camelcase");
|
|
426
459
|
return {
|
|
427
|
-
path: params.filter((param) => param.in === "path"),
|
|
428
|
-
query: params.filter((param) => param.in === "query"),
|
|
429
|
-
header: params.filter((param) => param.in === "header"),
|
|
430
|
-
cookie: params.filter((param) => param.in === "cookie")
|
|
460
|
+
path: dedupeByCasedName(params.filter((param) => param.in === "path")),
|
|
461
|
+
query: dedupeByCasedName(params.filter((param) => param.in === "query")),
|
|
462
|
+
header: dedupeByCasedName(params.filter((param) => param.in === "header")),
|
|
463
|
+
cookie: dedupeByCasedName(params.filter((param) => param.in === "cookie"))
|
|
431
464
|
};
|
|
432
465
|
}
|
|
433
466
|
function getStatusCodeNumber(statusCode) {
|
|
@@ -442,6 +475,15 @@ function isErrorStatusCode(statusCode) {
|
|
|
442
475
|
const code = getStatusCodeNumber(statusCode);
|
|
443
476
|
return code !== null && code >= 400;
|
|
444
477
|
}
|
|
478
|
+
function getSuccessResponses(responses) {
|
|
479
|
+
return responses.filter((response) => isSuccessStatusCode(response.statusCode));
|
|
480
|
+
}
|
|
481
|
+
function getOperationSuccessResponses(node) {
|
|
482
|
+
return getSuccessResponses(node.responses);
|
|
483
|
+
}
|
|
484
|
+
function getPrimarySuccessResponse(node) {
|
|
485
|
+
return getOperationSuccessResponses(node)[0] ?? null;
|
|
486
|
+
}
|
|
445
487
|
function resolveErrorNames(node, resolver) {
|
|
446
488
|
return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
|
|
447
489
|
}
|
|
@@ -515,14 +557,14 @@ function createGroupConfig(group) {
|
|
|
515
557
|
};
|
|
516
558
|
}
|
|
517
559
|
//#endregion
|
|
518
|
-
//#region ../../internals/client/src/builders/
|
|
560
|
+
//#region ../../internals/client/src/builders/validatorOptions.ts
|
|
519
561
|
/**
|
|
520
|
-
* Returns `true` when any direction of the
|
|
562
|
+
* Returns `true` when any direction of the validator uses zod (used for dependency checks).
|
|
521
563
|
*/
|
|
522
|
-
function
|
|
523
|
-
if (!
|
|
524
|
-
if (
|
|
525
|
-
return Boolean(
|
|
564
|
+
function isValidatorEnabled(validator) {
|
|
565
|
+
if (!validator) return false;
|
|
566
|
+
if (validator === "zod") return true;
|
|
567
|
+
return Boolean(validator.request || validator.response);
|
|
526
568
|
}
|
|
527
569
|
//#endregion
|
|
528
570
|
//#region ../../internals/client/src/resolveClient.ts
|
|
@@ -1770,7 +1812,7 @@ const infiniteQueryGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1770
1812
|
operation(node, ctx) {
|
|
1771
1813
|
if (!_kubb_core.ast.isHttpOperationNode(node)) return null;
|
|
1772
1814
|
const { config, driver, resolver, root } = ctx;
|
|
1773
|
-
const { output, query, mutation, infinite,
|
|
1815
|
+
const { output, query, mutation, infinite, validator, client, group, customOptions } = ctx.options;
|
|
1774
1816
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
1775
1817
|
if (!pluginTs) return null;
|
|
1776
1818
|
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
@@ -1820,14 +1862,14 @@ const infiniteQueryGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1820
1862
|
includeParams: false
|
|
1821
1863
|
})
|
|
1822
1864
|
].filter((name) => Boolean(name));
|
|
1823
|
-
const pluginZod =
|
|
1865
|
+
const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(_kubb_plugin_zod.pluginZodName) : null;
|
|
1824
1866
|
const zodResolver = pluginZod ? driver.getResolver(_kubb_plugin_zod.pluginZodName) : null;
|
|
1825
1867
|
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
1826
1868
|
root,
|
|
1827
1869
|
output: pluginZod?.options?.output ?? output,
|
|
1828
1870
|
group: pluginZod?.options?.group ?? void 0
|
|
1829
1871
|
}) : null;
|
|
1830
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver,
|
|
1872
|
+
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver, validator);
|
|
1831
1873
|
const calledClientName = contractOp.name;
|
|
1832
1874
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
|
|
1833
1875
|
baseName: meta.file.baseName,
|
|
@@ -1946,7 +1988,7 @@ const mutationGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1946
1988
|
operation(node, ctx) {
|
|
1947
1989
|
if (!_kubb_core.ast.isHttpOperationNode(node)) return null;
|
|
1948
1990
|
const { config, driver, resolver, root } = ctx;
|
|
1949
|
-
const { output, query, mutation,
|
|
1991
|
+
const { output, query, mutation, validator, client, group, customOptions } = ctx.options;
|
|
1950
1992
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
1951
1993
|
if (!pluginTs) return null;
|
|
1952
1994
|
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
@@ -1982,14 +2024,14 @@ const mutationGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1982
2024
|
order: "body-response-first",
|
|
1983
2025
|
includeParams: false
|
|
1984
2026
|
})].filter((name) => Boolean(name));
|
|
1985
|
-
const pluginZod =
|
|
2027
|
+
const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(_kubb_plugin_zod.pluginZodName) : null;
|
|
1986
2028
|
const zodResolver = pluginZod ? driver.getResolver(_kubb_plugin_zod.pluginZodName) : null;
|
|
1987
2029
|
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
1988
2030
|
root,
|
|
1989
2031
|
output: pluginZod?.options?.output ?? output,
|
|
1990
2032
|
group: pluginZod?.options?.group ?? void 0
|
|
1991
2033
|
}) : null;
|
|
1992
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver,
|
|
2034
|
+
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver, validator);
|
|
1993
2035
|
const calledClientName = contractOp.name;
|
|
1994
2036
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
|
|
1995
2037
|
baseName: meta.file.baseName,
|
|
@@ -2095,7 +2137,7 @@ const queryGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
2095
2137
|
operation(node, ctx) {
|
|
2096
2138
|
if (!_kubb_core.ast.isHttpOperationNode(node)) return null;
|
|
2097
2139
|
const { config, driver, resolver, root } = ctx;
|
|
2098
|
-
const { output, query, mutation,
|
|
2140
|
+
const { output, query, mutation, validator, client, group, customOptions } = ctx.options;
|
|
2099
2141
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
2100
2142
|
if (!pluginTs) return null;
|
|
2101
2143
|
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
@@ -2133,14 +2175,14 @@ const queryGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
2133
2175
|
order: "body-response-first",
|
|
2134
2176
|
includeParams: false
|
|
2135
2177
|
})].filter((name) => Boolean(name));
|
|
2136
|
-
const pluginZod =
|
|
2178
|
+
const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(_kubb_plugin_zod.pluginZodName) : null;
|
|
2137
2179
|
const zodResolver = pluginZod ? driver.getResolver(_kubb_plugin_zod.pluginZodName) : null;
|
|
2138
2180
|
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
2139
2181
|
root,
|
|
2140
2182
|
output: pluginZod?.options?.output ?? output,
|
|
2141
2183
|
group: pluginZod?.options?.group ?? void 0
|
|
2142
2184
|
}) : null;
|
|
2143
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver,
|
|
2185
|
+
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver, validator);
|
|
2144
2186
|
const calledClientName = contractOp.name;
|
|
2145
2187
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
|
|
2146
2188
|
baseName: meta.file.baseName,
|
|
@@ -2250,7 +2292,7 @@ const suspenseInfiniteQueryGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
2250
2292
|
operation(node, ctx) {
|
|
2251
2293
|
if (!_kubb_core.ast.isHttpOperationNode(node)) return null;
|
|
2252
2294
|
const { config, driver, resolver, root } = ctx;
|
|
2253
|
-
const { output, query, mutation, infinite, suspense,
|
|
2295
|
+
const { output, query, mutation, infinite, suspense, validator, client, group, customOptions } = ctx.options;
|
|
2254
2296
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
2255
2297
|
if (!pluginTs) return null;
|
|
2256
2298
|
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
@@ -2300,14 +2342,14 @@ const suspenseInfiniteQueryGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
2300
2342
|
includeParams: false
|
|
2301
2343
|
})
|
|
2302
2344
|
].filter((name) => Boolean(name));
|
|
2303
|
-
const pluginZod =
|
|
2345
|
+
const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(_kubb_plugin_zod.pluginZodName) : null;
|
|
2304
2346
|
const zodResolver = pluginZod ? driver.getResolver(_kubb_plugin_zod.pluginZodName) : null;
|
|
2305
2347
|
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
2306
2348
|
root,
|
|
2307
2349
|
output: pluginZod?.options?.output ?? output,
|
|
2308
2350
|
group: pluginZod?.options?.group ?? void 0
|
|
2309
2351
|
}) : null;
|
|
2310
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver,
|
|
2352
|
+
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver, validator);
|
|
2311
2353
|
const calledClientName = contractOp.name;
|
|
2312
2354
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
|
|
2313
2355
|
baseName: meta.file.baseName,
|
|
@@ -2427,7 +2469,7 @@ const suspenseQueryGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
2427
2469
|
operation(node, ctx) {
|
|
2428
2470
|
if (!_kubb_core.ast.isHttpOperationNode(node)) return null;
|
|
2429
2471
|
const { config, driver, resolver, root } = ctx;
|
|
2430
|
-
const { output, query, mutation, suspense,
|
|
2472
|
+
const { output, query, mutation, suspense, validator, client, group, customOptions } = ctx.options;
|
|
2431
2473
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
2432
2474
|
if (!pluginTs) return null;
|
|
2433
2475
|
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
@@ -2465,14 +2507,14 @@ const suspenseQueryGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
2465
2507
|
order: "body-response-first",
|
|
2466
2508
|
includeParams: false
|
|
2467
2509
|
})].filter((name) => Boolean(name));
|
|
2468
|
-
const pluginZod =
|
|
2510
|
+
const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(_kubb_plugin_zod.pluginZodName) : null;
|
|
2469
2511
|
const zodResolver = pluginZod ? driver.getResolver(_kubb_plugin_zod.pluginZodName) : null;
|
|
2470
2512
|
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
2471
2513
|
root,
|
|
2472
2514
|
output: pluginZod?.options?.output ?? output,
|
|
2473
2515
|
group: pluginZod?.options?.group ?? void 0
|
|
2474
2516
|
}) : null;
|
|
2475
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver,
|
|
2517
|
+
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver, validator);
|
|
2476
2518
|
const calledClientName = contractOp.name;
|
|
2477
2519
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
|
|
2478
2520
|
baseName: meta.file.baseName,
|
|
@@ -2719,7 +2761,7 @@ const pluginReactQuery = (0, _kubb_core.definePlugin)((options) => {
|
|
|
2719
2761
|
const { output = {
|
|
2720
2762
|
path: "hooks",
|
|
2721
2763
|
barrel: { type: "named" }
|
|
2722
|
-
}, group, exclude = [], include, override = [],
|
|
2764
|
+
}, group, exclude = [], include, override = [], validator = false, suspense = {}, infinite = false, mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, customOptions, client, resolver: userResolver, macros: userMacros } = options;
|
|
2723
2765
|
const selectedGenerators = [
|
|
2724
2766
|
queryGenerator,
|
|
2725
2767
|
suspenseQueryGenerator,
|
|
@@ -2733,7 +2775,7 @@ const pluginReactQuery = (0, _kubb_core.definePlugin)((options) => {
|
|
|
2733
2775
|
return {
|
|
2734
2776
|
name: pluginReactQueryName,
|
|
2735
2777
|
options,
|
|
2736
|
-
dependencies: [_kubb_plugin_ts.pluginTsName,
|
|
2778
|
+
dependencies: [_kubb_plugin_ts.pluginTsName, isValidatorEnabled(validator) ? _kubb_plugin_zod.pluginZodName : void 0].filter((dependency) => Boolean(dependency)),
|
|
2737
2779
|
hooks: { "kubb:plugin:setup"(ctx) {
|
|
2738
2780
|
const resolver = userResolver ? {
|
|
2739
2781
|
...resolverReactQuery,
|
|
@@ -2781,7 +2823,7 @@ const pluginReactQuery = (0, _kubb_core.definePlugin)((options) => {
|
|
|
2781
2823
|
name: "useCustomHookOptions",
|
|
2782
2824
|
...customOptions
|
|
2783
2825
|
} : null,
|
|
2784
|
-
|
|
2826
|
+
validator,
|
|
2785
2827
|
group: groupConfig,
|
|
2786
2828
|
exclude,
|
|
2787
2829
|
include,
|