@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.js CHANGED
@@ -198,6 +198,9 @@ function getPrimarySuccessResponse(node) {
198
198
  function resolveErrorNames(node, resolver) {
199
199
  return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode));
200
200
  }
201
+ function resolveSuccessNames(node, resolver) {
202
+ return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode));
203
+ }
201
204
  function resolveStatusCodeNames(node, resolver) {
202
205
  return node.responses.map((response) => resolver.response.status(node, response.statusCode));
203
206
  }
@@ -388,34 +391,44 @@ function resolveContractClient(options) {
388
391
  * Resolves the contract client `<op>` a consumer (query hook, MCP handler) imports, by looking up
389
392
  * the registered contract client plugin's resolver and output. Works for any contract client plugin
390
393
  * (plugin-fetch or plugin-axios). Returns `null` when no contract plugin is in play (the inline
391
- * path). The plugin injects `.kubb/client.ts` at the global output root, the same path consumers
392
- * read `RequestConfig` / `ResponseErrorConfig` from.
394
+ * path), or when the client plugin's `exclude` / `include` leaves this operation out, since it then
395
+ * emits no `<op>` to import. The plugin injects `.kubb/client.ts` at the global output root, the
396
+ * same path consumers read `RequestConfig` / `ResponseErrorConfig` from.
393
397
  *
394
398
  * The result is cached in the current node's `cache` (`ctx.cache`) under the client plugin's name,
395
399
  * so several dependents reading the same client plugin for one operation in a single pass
396
400
  * (react-query's query/mutation/infinite generators, vue-query, swr, the MCP handler, ...) share
397
401
  * one computed result instead of each re-deriving the name and path.
398
402
  *
399
- * `returnType` mirrors the client plugin's own `returnType` option (`'full'` when unset), so a
400
- * dependent's generated call body can match it instead of assuming the full `RequestResult` shape.
403
+ * `returnType`, `output`, and `group` are the client plugin's options for this operation, after its
404
+ * `override` entries, the same resolution its own generator sees. A dependent's generated call body
405
+ * and import path therefore match the `<op>` actually emitted, even when an `override` changes it.
401
406
  */
402
407
  function resolveClientOperation(options) {
403
408
  const { clientPlugin, driver, node, root, output, cache } = options;
404
409
  if (!clientPlugin) return null;
405
410
  return cache.ensureItem(`${clientPlugin.pluginName}:clientOperation`, () => {
406
411
  const resolver = driver.getResolver(clientPlugin.pluginName);
407
- const plugin = driver.getPlugin(clientPlugin.pluginName);
412
+ const pluginOptions = driver.getPlugin(clientPlugin.pluginName)?.options ?? {};
413
+ const { exclude, include, override } = pluginOptions;
414
+ const operationOptions = Boolean(exclude?.length || include?.length || override?.length) && resolver.default ? resolver.default.options(node, {
415
+ options: pluginOptions,
416
+ exclude,
417
+ include,
418
+ override
419
+ }) : pluginOptions;
420
+ if (!operationOptions) return null;
408
421
  const file = resolver.file({
409
422
  ...operationFileEntry(node, node.operationId),
410
423
  root,
411
- output: plugin?.options?.output ?? output,
412
- group: plugin?.options?.group ?? void 0
424
+ output: operationOptions.output ?? output,
425
+ group: operationOptions.group ?? void 0
413
426
  });
414
427
  return {
415
428
  name: resolver.name(node.operationId),
416
429
  path: file.path,
417
430
  clientPath: path.resolve(root, ".kubb/client.ts"),
418
- returnType: plugin?.options?.returnType ?? "full"
431
+ returnType: operationOptions.returnType ?? "full"
419
432
  };
420
433
  });
421
434
  }
@@ -571,11 +584,11 @@ function resolveMutationConfig(mutation, options) {
571
584
  }
572
585
  /**
573
586
  * Classifies an operation as a query or a mutation from the resolved `query` / `mutation` method lists.
574
- * `query: false` still marks the operation as a query so the query-family generators keep matching it,
575
- * and a method already claimed by `query` never counts as a mutation.
587
+ * Disabled query and mutation configs do not claim operations, and a method already claimed by an
588
+ * enabled query config never counts as a mutation.
576
589
  */
577
590
  function classifyOperation(node, { query, mutation }) {
578
- const isQuery = query === false || !!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase());
591
+ const isQuery = !!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase());
579
592
  const queryMethods = new Set(query ? query.methods : []);
580
593
  return {
581
594
  isQuery,
@@ -733,7 +746,8 @@ const declarationPrinter$2 = functionPrinter({ mode: "declaration" });
733
746
  const callPrinter$1 = functionPrinter({ mode: "call" });
734
747
  function buildMutationParamsNode(node, options) {
735
748
  const { mutationKeyTypeName, mutationArgTypeName, resolver } = options;
736
- const responseName = resolver.response.response(node);
749
+ const successNames = resolveSuccessNames(node, resolver);
750
+ const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
737
751
  const errorNames = resolveErrorNames(node, resolver);
738
752
  const TData = responseName;
739
753
  const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
@@ -748,7 +762,8 @@ function buildMutationParamsNode(node, options) {
748
762
  })] });
749
763
  }
750
764
  function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, mutationArgTypeName, node, tsResolver, returnType = "full" }) {
751
- const responseName = tsResolver.response.response(node);
765
+ const successNames = resolveSuccessNames(node, tsResolver);
766
+ const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
752
767
  const errorNames = resolveErrorNames(node, tsResolver);
753
768
  const TData = responseName;
754
769
  const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
@@ -832,7 +847,8 @@ const declarationPrinter$1 = functionPrinter({ mode: "declaration" });
832
847
  const callPrinter = functionPrinter({ mode: "call" });
833
848
  function buildQueryParamsNode(node, options) {
834
849
  const { resolver } = options;
835
- const responseName = resolver.response.response(node);
850
+ const successNames = resolveSuccessNames(node, resolver);
851
+ const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
836
852
  const errorNames = resolveErrorNames(node, resolver);
837
853
  const TData = responseName;
838
854
  const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
@@ -850,7 +866,8 @@ function buildQueryParamsNode(node, options) {
850
866
  return createFunctionParameters({ params: [groupedParam, optionsParam].filter((param) => param !== null) });
851
867
  }
852
868
  function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver }) {
853
- const responseName = tsResolver.response.response(node);
869
+ const successNames = resolveSuccessNames(node, tsResolver);
870
+ const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
854
871
  const errorNames = resolveErrorNames(node, tsResolver);
855
872
  const generics = [
856
873
  responseName,