@kubb/plugin-swr 5.1.2 → 5.1.4
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 +32 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +32 -15
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -228,6 +228,9 @@ function getPrimarySuccessResponse(node) {
|
|
|
228
228
|
function resolveErrorNames(node, resolver) {
|
|
229
229
|
return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode));
|
|
230
230
|
}
|
|
231
|
+
function resolveSuccessNames(node, resolver) {
|
|
232
|
+
return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode));
|
|
233
|
+
}
|
|
231
234
|
function resolveStatusCodeNames(node, resolver) {
|
|
232
235
|
return node.responses.map((response) => resolver.response.status(node, response.statusCode));
|
|
233
236
|
}
|
|
@@ -418,34 +421,44 @@ function resolveContractClient(options) {
|
|
|
418
421
|
* Resolves the contract client `<op>` a consumer (query hook, MCP handler) imports, by looking up
|
|
419
422
|
* the registered contract client plugin's resolver and output. Works for any contract client plugin
|
|
420
423
|
* (plugin-fetch or plugin-axios). Returns `null` when no contract plugin is in play (the inline
|
|
421
|
-
* path)
|
|
422
|
-
*
|
|
424
|
+
* path), or when the client plugin's `exclude` / `include` leaves this operation out, since it then
|
|
425
|
+
* emits no `<op>` to import. The plugin injects `.kubb/client.ts` at the global output root, the
|
|
426
|
+
* same path consumers read `RequestConfig` / `ResponseErrorConfig` from.
|
|
423
427
|
*
|
|
424
428
|
* The result is cached in the current node's `cache` (`ctx.cache`) under the client plugin's name,
|
|
425
429
|
* so several dependents reading the same client plugin for one operation in a single pass
|
|
426
430
|
* (react-query's query/mutation/infinite generators, vue-query, swr, the MCP handler, ...) share
|
|
427
431
|
* one computed result instead of each re-deriving the name and path.
|
|
428
432
|
*
|
|
429
|
-
* `returnType`
|
|
430
|
-
*
|
|
433
|
+
* `returnType`, `output`, and `group` are the client plugin's options for this operation, after its
|
|
434
|
+
* `override` entries, the same resolution its own generator sees. A dependent's generated call body
|
|
435
|
+
* and import path therefore match the `<op>` actually emitted, even when an `override` changes it.
|
|
431
436
|
*/
|
|
432
437
|
function resolveClientOperation(options) {
|
|
433
438
|
const { clientPlugin, driver, node, root, output, cache } = options;
|
|
434
439
|
if (!clientPlugin) return null;
|
|
435
440
|
return cache.ensureItem(`${clientPlugin.pluginName}:clientOperation`, () => {
|
|
436
441
|
const resolver = driver.getResolver(clientPlugin.pluginName);
|
|
437
|
-
const
|
|
442
|
+
const pluginOptions = driver.getPlugin(clientPlugin.pluginName)?.options ?? {};
|
|
443
|
+
const { exclude, include, override } = pluginOptions;
|
|
444
|
+
const operationOptions = Boolean(exclude?.length || include?.length || override?.length) && resolver.default ? resolver.default.options(node, {
|
|
445
|
+
options: pluginOptions,
|
|
446
|
+
exclude,
|
|
447
|
+
include,
|
|
448
|
+
override
|
|
449
|
+
}) : pluginOptions;
|
|
450
|
+
if (!operationOptions) return null;
|
|
438
451
|
const file = resolver.file({
|
|
439
452
|
...operationFileEntry(node, node.operationId),
|
|
440
453
|
root,
|
|
441
|
-
output:
|
|
442
|
-
group:
|
|
454
|
+
output: operationOptions.output ?? output,
|
|
455
|
+
group: operationOptions.group ?? void 0
|
|
443
456
|
});
|
|
444
457
|
return {
|
|
445
458
|
name: resolver.name(node.operationId),
|
|
446
459
|
path: file.path,
|
|
447
460
|
clientPath: node_path.default.resolve(root, ".kubb/client.ts"),
|
|
448
|
-
returnType:
|
|
461
|
+
returnType: operationOptions.returnType ?? "full"
|
|
449
462
|
};
|
|
450
463
|
});
|
|
451
464
|
}
|
|
@@ -601,11 +614,11 @@ function resolveMutationConfig(mutation, options) {
|
|
|
601
614
|
}
|
|
602
615
|
/**
|
|
603
616
|
* Classifies an operation as a query or a mutation from the resolved `query` / `mutation` method lists.
|
|
604
|
-
*
|
|
605
|
-
*
|
|
617
|
+
* Disabled query and mutation configs do not claim operations, and a method already claimed by an
|
|
618
|
+
* enabled query config never counts as a mutation.
|
|
606
619
|
*/
|
|
607
620
|
function classifyOperation(node, { query, mutation }) {
|
|
608
|
-
const isQuery =
|
|
621
|
+
const isQuery = !!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase());
|
|
609
622
|
const queryMethods = new Set(query ? query.methods : []);
|
|
610
623
|
return {
|
|
611
624
|
isQuery,
|
|
@@ -763,7 +776,8 @@ const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "decla
|
|
|
763
776
|
const callPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
764
777
|
function buildMutationParamsNode(node, options) {
|
|
765
778
|
const { mutationKeyTypeName, mutationArgTypeName, resolver } = options;
|
|
766
|
-
const
|
|
779
|
+
const successNames = resolveSuccessNames(node, resolver);
|
|
780
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
|
|
767
781
|
const errorNames = resolveErrorNames(node, resolver);
|
|
768
782
|
const TData = responseName;
|
|
769
783
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -778,7 +792,8 @@ function buildMutationParamsNode(node, options) {
|
|
|
778
792
|
})] });
|
|
779
793
|
}
|
|
780
794
|
function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, mutationArgTypeName, node, tsResolver, returnType = "full" }) {
|
|
781
|
-
const
|
|
795
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
796
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
782
797
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
783
798
|
const TData = responseName;
|
|
784
799
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -862,7 +877,8 @@ const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "decla
|
|
|
862
877
|
const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
863
878
|
function buildQueryParamsNode(node, options) {
|
|
864
879
|
const { resolver } = options;
|
|
865
|
-
const
|
|
880
|
+
const successNames = resolveSuccessNames(node, resolver);
|
|
881
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
|
|
866
882
|
const errorNames = resolveErrorNames(node, resolver);
|
|
867
883
|
const TData = responseName;
|
|
868
884
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -880,7 +896,8 @@ function buildQueryParamsNode(node, options) {
|
|
|
880
896
|
return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [groupedParam, optionsParam].filter((param) => param !== null) });
|
|
881
897
|
}
|
|
882
898
|
function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver }) {
|
|
883
|
-
const
|
|
899
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
900
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
884
901
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
885
902
|
const generics = [
|
|
886
903
|
responseName,
|