@kubb/plugin-vue-query 5.5.0 → 5.5.1

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 CHANGED
@@ -5,10 +5,6 @@ Object.defineProperties(exports, {
5
5
  //#region \0rolldown/runtime.js
6
6
  var __create = Object.create;
7
7
  var __defProp = Object.defineProperty;
8
- var __name = (target, value) => __defProp(target, "name", {
9
- value,
10
- configurable: true
11
- });
12
8
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
9
  var __getOwnPropNames = Object.getOwnPropertyNames;
14
10
  var __getProtoOf = Object.getPrototypeOf;
@@ -34,24 +30,6 @@ node_path = __toESM(node_path, 1);
34
30
  let _kubb_plugin_ts = require("@kubb/plugin-ts");
35
31
  let kubb_jsx = require("kubb/jsx");
36
32
  let kubb_jsx_jsx_runtime = require("kubb/jsx/jsx-runtime");
37
- //#region ../../internals/shared/src/params.ts
38
- /**
39
- * Drops parameters that share the same name, keeping the first.
40
- *
41
- * A malformed spec can declare the same parameter name twice within one `in` location. Both would
42
- * resolve to the same output property, so emitting both would yield an object type with a duplicate
43
- * member, which TypeScript rejects. This is a defensive guard against that case, not a casing guard:
44
- * parameter names flow through unchanged, so no two distinct names ever collide here anymore.
45
- */
46
- function dedupeParams(params) {
47
- const seen = /* @__PURE__ */ new Set();
48
- return params.filter((param) => {
49
- if (seen.has(param.name)) return false;
50
- seen.add(param.name);
51
- return true;
52
- });
53
- }
54
- //#endregion
55
33
  //#region ../../internals/shared/src/operation.ts
56
34
  /**
57
35
  * Builds the `ResolverFileParams` every operation generator passes to
@@ -121,12 +99,12 @@ function getContentTypeInfo(node) {
121
99
  function getResponseContentTypeInfo(node) {
122
100
  return buildContentTypeInfo(getPrimarySuccessResponse(node)?.content?.map((e) => e.contentType) ?? []);
123
101
  }
102
+ const requestConfigBaseType = `Partial<Omit<RequestConfig, 'path' | 'query' | 'body' | 'headers' | 'url'>>`;
124
103
  function buildRequestConfigType(node) {
125
104
  const request = getContentTypeInfo(node);
126
105
  const response = getResponseContentTypeInfo(node);
127
- const configType = `Partial<Omit<RequestConfig, 'path' | 'query' | 'body' | 'headers' | 'url'>>`;
128
106
  const members = [request.isMultipleContentTypes ? `request?: ${request.contentTypeUnion}` : null, response.isMultipleContentTypes ? `response?: ${response.contentTypeUnion}` : null].filter(Boolean);
129
- return members.length ? `${configType} & { contentType?: { ${members.join("; ")} } }` : configType;
107
+ return members.length ? `${requestConfigBaseType} & { contentType?: { ${members.join("; ")} } }` : requestConfigBaseType;
130
108
  }
131
109
  /**
132
110
  * Builds the `client?:` option type shared by the generated query hooks (`useQuery`,
@@ -135,7 +113,7 @@ function buildRequestConfigType(node) {
135
113
  * content type for.
136
114
  */
137
115
  function buildClientOptionType() {
138
- return `Partial<Omit<RequestConfig, 'path' | 'query' | 'body' | 'headers' | 'url'>>`;
116
+ return requestConfigBaseType;
139
117
  }
140
118
  /**
141
119
  * Which of the grouped request options an operation carries.
@@ -195,11 +173,19 @@ const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
195
173
  function getOperationParameters(node) {
196
174
  const cached = operationParameterGroupsByNode.get(node);
197
175
  if (cached) return cached;
176
+ const group = (location) => {
177
+ const seen = /* @__PURE__ */ new Set();
178
+ return node.parameters.filter((param) => {
179
+ if (param.in !== location || seen.has(param.name)) return false;
180
+ seen.add(param.name);
181
+ return true;
182
+ });
183
+ };
198
184
  const groups = {
199
- path: dedupeParams(node.parameters.filter((param) => param.in === "path")),
200
- query: dedupeParams(node.parameters.filter((param) => param.in === "query")),
201
- header: dedupeParams(node.parameters.filter((param) => param.in === "header")),
202
- cookie: dedupeParams(node.parameters.filter((param) => param.in === "cookie"))
185
+ path: group("path"),
186
+ query: group("query"),
187
+ header: group("header"),
188
+ cookie: group("cookie")
203
189
  };
204
190
  operationParameterGroupsByNode.set(node, groups);
205
191
  return groups;
@@ -359,7 +345,96 @@ var compatibility = {
359
345
  };
360
346
  //#endregion
361
347
  //#region package.json
362
- var version = "5.5.0";
348
+ var version = "5.5.1";
349
+ //#endregion
350
+ //#region ../../internals/tanstack-query/src/components/HookFile.tsx
351
+ /**
352
+ * Resolves what every TanStack hook file shares: its file, the `@kubb/plugin-ts` file and type names, banner and footer.
353
+ */
354
+ function resolveHookFile(node, ctx, options) {
355
+ const { name, output, group, contractOp, keyTypeName, extraTypeNames = [] } = options;
356
+ const { config, root, resolver } = ctx;
357
+ const pluginTs = ctx.requirePlugin(_kubb_plugin_ts.pluginTsName);
358
+ const tsResolver = ctx.driver.getResolver(_kubb_plugin_ts.pluginTsName);
359
+ const file = resolver.file({
360
+ ...operationFileEntry(node, name),
361
+ root,
362
+ output,
363
+ group: group ?? void 0
364
+ });
365
+ const fileTs = resolveDependencyOperationFile({
366
+ cache: ctx.cache,
367
+ node,
368
+ resolver: tsResolver,
369
+ root,
370
+ output: pluginTs.options?.output ?? output,
371
+ group: pluginTs.options?.group
372
+ });
373
+ const importedTypeNames = [
374
+ tsResolver.response.options(node),
375
+ ...extraTypeNames,
376
+ ...resolveOperationTypeNames(node, tsResolver, {
377
+ exclude: keyTypeName ? [keyTypeName] : void 0,
378
+ order: "body-response-first",
379
+ includeParams: false
380
+ })
381
+ ].filter((typeName) => Boolean(typeName));
382
+ const fileMeta = {
383
+ path: file.path,
384
+ baseName: file.baseName
385
+ };
386
+ return {
387
+ file,
388
+ fileTs,
389
+ tsResolver,
390
+ contractOp,
391
+ importedTypeNames,
392
+ banner: resolver.default.banner(ctx.meta, {
393
+ output,
394
+ config,
395
+ file: fileMeta
396
+ }),
397
+ footer: resolver.default.footer(ctx.meta, {
398
+ output,
399
+ config,
400
+ file: fileMeta
401
+ })
402
+ };
403
+ }
404
+ /**
405
+ * The `<File>` shell shared by the TanStack hook generators; renders `children` after the imports.
406
+ */
407
+ function HookFile({ hook, imports, children }) {
408
+ const { file, fileTs, contractOp, importedTypeNames, banner, footer } = hook;
409
+ return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File, {
410
+ baseName: file.baseName,
411
+ path: file.path,
412
+ meta: file.meta,
413
+ banner,
414
+ footer,
415
+ children: [
416
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
417
+ name: [contractOp.name],
418
+ root: file.path,
419
+ path: contractOp.path
420
+ }),
421
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
422
+ name: ["RequestConfig", "ResponseErrorConfig"],
423
+ root: contractOp.clientPathIsFile ? file.path : void 0,
424
+ path: contractOp.clientPath,
425
+ isTypeOnly: true
426
+ }),
427
+ imports,
428
+ fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
429
+ name: Array.from(new Set(importedTypeNames)),
430
+ root: file.path,
431
+ path: fileTs.path,
432
+ isTypeOnly: true
433
+ }),
434
+ children
435
+ ]
436
+ });
437
+ }
363
438
  //#endregion
364
439
  //#region ../../internals/tanstack-query/src/utils.ts
365
440
  /**
@@ -644,11 +719,47 @@ const queryKeyGroupOrder = [
644
719
  "query",
645
720
  "body"
646
721
  ];
722
+ /**
723
+ * Build QueryKey params as the grouped `{ path, query, body }` object (NO headers, NO config),
724
+ * typed from the operation's `Options` minus `url`. The query key transformer reads the
725
+ * grouped `path`/`query`/`body` bindings.
726
+ */
727
+ function buildQueryKeyParams(node, options) {
728
+ const { resolver, memberTypeWrapper } = options;
729
+ const groupedParam = buildGroupedRequestParam(node, {
730
+ resolver,
731
+ keys: queryKeyGroupOrder,
732
+ memberTypeWrapper
733
+ });
734
+ return (0, _kubb_plugin_ts.createFunctionParameters)({ params: groupedParam ? [groupedParam] : [] });
735
+ }
736
+ /**
737
+ * Builds the hook parameter list: the grouped request param (omitted when `withRequest` is `false`) then `options` typed as `optionsType`.
738
+ */
739
+ function buildHookParams(node, options) {
740
+ const { resolver, optionsType, memberTypeWrapper, withRequest = true } = options;
741
+ const optionsParam = (0, _kubb_plugin_ts.createFunctionParameter)({
742
+ name: "options",
743
+ type: optionsType,
744
+ default: "{}"
745
+ });
746
+ const groupedParam = withRequest ? buildGroupedRequestParam(node, {
747
+ resolver,
748
+ memberTypeWrapper
749
+ }) : null;
750
+ return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [groupedParam, optionsParam].filter((param) => param !== null) });
751
+ }
752
+ /**
753
+ * The `TRequest` type argument of a mutation hook: the options type when the operation takes a request, else `undefined`.
754
+ */
755
+ function resolveMutationRequestType(node, resolver) {
756
+ return buildGroupedRequestParam(node, { resolver }) ? resolver.response.options(node) : "undefined";
757
+ }
647
758
  //#endregion
648
759
  //#region ../../internals/tanstack-query/src/components/InfiniteQueryOptions.tsx
649
- const declarationPrinter$7 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
650
- const callPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
651
- function InfiniteQueryOptions$1({ name, clientName, initialPageParam, hasExplicitInitialPageParam, cursorParam, nextParam, previousParam, getNextPageParam, getPreviousPageParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName, returnType = "full" }) {
760
+ const declarationPrinter$5 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
761
+ const callPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
762
+ function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitInitialPageParam, cursorParam, nextParam, previousParam, getNextPageParam, getPreviousPageParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName, returnType = "full" }) {
652
763
  const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver);
653
764
  const { queryParamsTypeName, pageParamType } = resolvePageParamType(node, {
654
765
  resolver: tsResolver,
@@ -661,12 +772,12 @@ function InfiniteQueryOptions$1({ name, clientName, initialPageParam, hasExplici
661
772
  memberTypeWrapper
662
773
  });
663
774
  const queryKeyParamsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: groupedKeyParam ? [groupedKeyParam] : [] });
664
- const queryKeyParamsCall = callPrinter$4.print(queryKeyParamsNode) ?? "";
775
+ const queryKeyParamsCall = callPrinter$3.print(queryKeyParamsNode) ?? "";
665
776
  const paramsNode = buildQueryOptionsParams(node, {
666
777
  resolver: tsResolver,
667
778
  memberTypeWrapper
668
779
  });
669
- const paramsSignature = declarationPrinter$7.print(paramsNode) ?? "";
780
+ const paramsSignature = declarationPrinter$5.print(paramsNode) ?? "";
670
781
  const queryFnBody = buildCallResultBody(buildClientCall(node, {
671
782
  clientName,
672
783
  signal: true,
@@ -721,23 +832,22 @@ return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${que
721
832
  })
722
833
  });
723
834
  }
724
- __name(InfiniteQueryOptions$1, "InfiniteQueryOptions");
725
835
  //#endregion
726
836
  //#region ../../internals/tanstack-query/src/components/MutationKey.tsx
727
- const declarationPrinter$6 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
837
+ const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
728
838
  const mutationKeyTransformer = ({ node }) => {
729
839
  if (!node.path) return [];
730
840
  return [`{ url: '${kubb_kit.Url.toPath(node.path)}' }`];
731
841
  };
732
- function MutationKey({ name, node, transformer }) {
842
+ function MutationKey({ name, node, transformer, typeName }) {
733
843
  const paramsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: [] });
734
- const paramsSignature = declarationPrinter$6.print(paramsNode) ?? "";
844
+ const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
735
845
  const keys = (transformer ?? mutationKeyTransformer)({
736
846
  node,
737
847
  casing: "camelcase",
738
848
  variant: "mutation"
739
849
  });
740
- return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
850
+ return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
741
851
  name,
742
852
  isExportable: true,
743
853
  isIndexable: true,
@@ -748,7 +858,17 @@ function MutationKey({ name, node, transformer }) {
748
858
  singleLine: true,
749
859
  children: `[${keys.join(", ")}] as const`
750
860
  })
751
- });
861
+ }), typeName && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
862
+ name: typeName,
863
+ isExportable: true,
864
+ isIndexable: true,
865
+ isTypeOnly: true,
866
+ children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Type, {
867
+ export: true,
868
+ name: typeName,
869
+ children: `ReturnType<typeof ${name}>`
870
+ })
871
+ })] });
752
872
  }
753
873
  //#endregion
754
874
  //#region ../../internals/tanstack-query/src/resolver.ts
@@ -803,7 +923,9 @@ function createMutationResolver() {
803
923
  }
804
924
  };
805
925
  }
806
- (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
926
+ //#endregion
927
+ //#region ../../internals/tanstack-query/src/components/QueryKey.tsx
928
+ const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
807
929
  const queryKeyTransformer = ({ node, variant }) => {
808
930
  if (!node.path) return [];
809
931
  const { path, query } = getOperationParameters(node);
@@ -816,6 +938,40 @@ const queryKeyTransformer = ({ node, variant }) => {
816
938
  if (node.requestBody?.content?.[0]?.schema) result.push("...(body !== undefined ? [body] : [])");
817
939
  return result;
818
940
  };
941
+ function QueryKey({ name, node, tsResolver, typeName, transformer, variant = "query", memberTypeWrapper, exportType }) {
942
+ const paramsNode = buildQueryKeyParams(node, {
943
+ resolver: tsResolver,
944
+ memberTypeWrapper
945
+ });
946
+ const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
947
+ const keys = (transformer ?? queryKeyTransformer)({
948
+ node,
949
+ casing: "camelcase",
950
+ variant
951
+ });
952
+ return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
953
+ name,
954
+ isExportable: true,
955
+ isIndexable: true,
956
+ children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function.Arrow, {
957
+ name,
958
+ export: true,
959
+ params: paramsSignature,
960
+ singleLine: true,
961
+ children: `[${keys.join(", ")}] as const`
962
+ })
963
+ }), /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
964
+ name: typeName,
965
+ isExportable: exportType,
966
+ isIndexable: exportType,
967
+ isTypeOnly: true,
968
+ children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Type, {
969
+ name: typeName,
970
+ export: exportType,
971
+ children: `ReturnType<typeof ${name}>`
972
+ })
973
+ })] });
974
+ }
819
975
  //#endregion
820
976
  //#region ../../internals/client/src/resolveClient.ts
821
977
  /**
@@ -859,7 +1015,7 @@ const contractPlugins = [
859
1015
  * @example
860
1016
  * ```ts
861
1017
  * resolveClient({ client: undefined, pluginNames: ['plugin-ts'] })
862
- * // { kind: 'error', message: 'No client plugin is registered…' }
1018
+ * // { kind: 'error', code: 'KUBB_MISSING_DEPENDENCY', message: 'No client plugin is registered.', help: 'Add …' }
863
1019
  * ```
864
1020
  */
865
1021
  function resolveClient(options) {
@@ -869,7 +1025,9 @@ function resolveClient(options) {
869
1025
  const pluginName = selectorToPlugin[client];
870
1026
  if (!has(pluginName)) return {
871
1027
  kind: "error",
872
- message: `\`client: '${client}'\` is set but \`@kubb/plugin-${client}\` is not registered in \`plugins\`. Add it, or drop \`client\` to use a different client plugin.`
1028
+ code: kubb_kit.Diagnostics.code.missingDependency,
1029
+ message: `\`client: '${client}'\` is set but \`@kubb/plugin-${client}\` is not registered in \`plugins\`.`,
1030
+ help: `Add \`@kubb/plugin-${client}\` to \`plugins\`, or drop \`client\` to use a different client plugin.`
873
1031
  };
874
1032
  return {
875
1033
  kind: "contract",
@@ -878,7 +1036,9 @@ function resolveClient(options) {
878
1036
  }
879
1037
  if (client !== void 0) return {
880
1038
  kind: "error",
881
- message: `Option \`client\` is ${typeof client === "string" ? `'${client}'` : String(client)}, but it must be one of 'fetch', 'axios', 'client'. Drop \`client\` to use the registered client plugin.`
1039
+ code: kubb_kit.Diagnostics.code.invalidPluginOptions,
1040
+ message: `Option \`client\` is ${typeof client === "string" ? `'${client}'` : String(client)}, but it must be one of 'fetch', 'axios', 'client'.`,
1041
+ help: "Set `client` to one of those values, or drop it to use the registered client plugin."
882
1042
  };
883
1043
  const registered = contractPlugins.filter(has);
884
1044
  if (registered.length === 1) return {
@@ -887,25 +1047,40 @@ function resolveClient(options) {
887
1047
  };
888
1048
  if (registered.length > 1) return {
889
1049
  kind: "error",
890
- message: `Multiple client plugins are registered (${registered.map((name) => `\`@kubb/${name}\``).join(", ")}). Set \`client: 'fetch' | 'axios' | 'client'\` to choose which client the hooks call, or register a single client plugin.`
1050
+ code: kubb_kit.Diagnostics.code.invalidPluginOptions,
1051
+ message: `Multiple client plugins are registered (${registered.map((name) => `\`@kubb/${name}\``).join(", ")}) and \`client\` is not set.`,
1052
+ help: "Set `client: 'fetch' | 'axios' | 'client'` to choose which client the hooks call, or register a single client plugin."
891
1053
  };
892
1054
  return {
893
1055
  kind: "error",
894
- message: "No client plugin is registered. Add `@kubb/plugin-axios`, `@kubb/plugin-fetch`, or `@kubb/plugin-client` to `plugins` so the generated code has an HTTP client to call."
1056
+ code: kubb_kit.Diagnostics.code.missingDependency,
1057
+ message: "No client plugin is registered.",
1058
+ help: "Add `@kubb/plugin-fetch`, `@kubb/plugin-axios`, or `@kubb/plugin-client` to `plugins` so the generated code has an HTTP client to call."
895
1059
  };
896
1060
  }
897
1061
  /**
898
- * Resolves the contract client during a consumer plugin's setup hook. Extracts the plugin names
899
- * from the raw `plugins` config, applies {@link resolveClient}, and throws the diagnostic on a
900
- * misconfiguration so every consumer fails fast with the same message.
1062
+ * Resolves the contract client during a consumer plugin's setup hook.
1063
+ * It extracts the plugin names from the raw `plugins` config and applies {@link resolveClient}.
1064
+ * On a misconfiguration it throws a config diagnostic tagged with `plugin`, so every consumer
1065
+ * fails fast with the same message.
901
1066
  */
902
1067
  function resolveContractClient(options) {
903
- const { client, plugins = [] } = options;
1068
+ const { plugin, client, plugins = [] } = options;
904
1069
  const resolved = resolveClient({
905
1070
  client,
906
1071
  pluginNames: plugins.map((plugin) => plugin.name).filter((name) => Boolean(name))
907
1072
  });
908
- if (resolved.kind === "error") throw new Error(resolved.message);
1073
+ if (resolved.kind === "error") {
1074
+ const { code, message, help } = resolved;
1075
+ throw new kubb_kit.Diagnostics.Error({
1076
+ code,
1077
+ severity: "error",
1078
+ message,
1079
+ help,
1080
+ location: { kind: "config" },
1081
+ plugin
1082
+ });
1083
+ }
909
1084
  return resolved;
910
1085
  }
911
1086
  //#endregion
@@ -969,66 +1144,9 @@ function resolveClientOperation(options) {
969
1144
  });
970
1145
  }
971
1146
  //#endregion
972
- //#region src/utils.ts
973
- /**
974
- * Builds the call to a contract client `<op>` function inside a vue-query composable body. The
975
- * function takes a single grouped options object, so `config` is spread first, then the operation's
976
- * request groups are unwrapped with `toValue()`, then the abort `signal` for queries, with
977
- * `throwOnError: true` pinned last so a caller's config can't flip the query's error semantics.
978
- * Mutations omit the `signal`.
979
- */
980
- function buildVueClientCall(node, options) {
981
- return buildClientCall(node, {
982
- ...options,
983
- unwrapName: (name) => `toValue(${name})`
984
- });
985
- }
986
- //#endregion
987
- //#region src/components/QueryKey.tsx
988
- const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
989
- function buildQueryKeyParamsNode(node, options) {
990
- const groupedParam = buildGroupedRequestParam(node, {
991
- resolver: options.resolver,
992
- keys: queryKeyGroupOrder,
993
- memberTypeWrapper: maybeRefOrGetter
994
- });
995
- return (0, _kubb_plugin_ts.createFunctionParameters)({ params: groupedParam ? [groupedParam] : [] });
996
- }
997
- function QueryKey({ name, node, tsResolver, typeName, transformer, variant = "query" }) {
998
- const paramsNode = buildQueryKeyParamsNode(node, { resolver: tsResolver });
999
- const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
1000
- const keys = (transformer ?? queryKeyTransformer)({
1001
- node,
1002
- casing: "camelcase",
1003
- variant
1004
- });
1005
- return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
1006
- name,
1007
- isExportable: true,
1008
- isIndexable: true,
1009
- children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function.Arrow, {
1010
- name,
1011
- export: true,
1012
- params: paramsSignature,
1013
- singleLine: true,
1014
- children: `[${keys.join(", ")}] as const`
1015
- })
1016
- }), /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
1017
- name: typeName,
1018
- isExportable: true,
1019
- isIndexable: true,
1020
- isTypeOnly: true,
1021
- children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Type, {
1022
- name: typeName,
1023
- export: true,
1024
- children: `ReturnType<typeof ${name}>`
1025
- })
1026
- })] });
1027
- }
1028
- //#endregion
1029
1147
  //#region src/components/QueryOptions.tsx
1030
- const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1031
- const callPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1148
+ const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1149
+ const callPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1032
1150
  function getQueryOptionsParams(node, options) {
1033
1151
  return buildQueryOptionsParams(node, {
1034
1152
  resolver: options.resolver,
@@ -1037,13 +1155,17 @@ function getQueryOptionsParams(node, options) {
1037
1155
  }
1038
1156
  function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, returnType = "full" }) {
1039
1157
  const { TData, TError } = buildResponseTypes(node, tsResolver);
1040
- const queryKeyParamsNode = buildQueryKeyParamsNode(node, { resolver: tsResolver });
1041
- const queryKeyParamsCall = callPrinter$3.print(queryKeyParamsNode) ?? "";
1158
+ const queryKeyParamsNode = buildQueryKeyParams(node, {
1159
+ resolver: tsResolver,
1160
+ memberTypeWrapper: maybeRefOrGetter
1161
+ });
1162
+ const queryKeyParamsCall = callPrinter$2.print(queryKeyParamsNode) ?? "";
1042
1163
  const paramsNode = getQueryOptionsParams(node, { resolver: tsResolver });
1043
- const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
1044
- const queryFnBody = buildCallResultBody(buildVueClientCall(node, {
1164
+ const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
1165
+ const queryFnBody = buildCallResultBody(buildClientCall(node, {
1045
1166
  clientName,
1046
- signal: true
1167
+ signal: true,
1168
+ unwrapName: (name) => `toValue(${name})`
1047
1169
  }), { returnType });
1048
1170
  return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
1049
1171
  name,
@@ -1066,201 +1188,61 @@ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, return
1066
1188
  });
1067
1189
  }
1068
1190
  //#endregion
1069
- //#region src/components/InfiniteQuery.tsx
1070
- const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1071
- const callPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1072
- function buildInfiniteQueryParamsNode(node, options) {
1073
- const { resolver } = options;
1074
- const { TData, TError } = buildResponseTypes(node, resolver);
1075
- const optionsParam = (0, _kubb_plugin_ts.createFunctionParameter)({
1076
- name: "options",
1077
- type: `{
1078
- query?: Partial<UseInfiniteQueryOptions<${[
1079
- TData,
1080
- TError,
1081
- "TQueryData",
1082
- "TQueryKey",
1083
- "TQueryData"
1084
- ].join(", ")}>> & { client?: QueryClient },
1085
- client?: ${buildClientOptionType()}
1086
- }`,
1087
- default: "{}"
1088
- });
1089
- const groupedParam = buildGroupedRequestParam(node, {
1090
- resolver,
1091
- memberTypeWrapper: maybeRefOrGetter
1092
- });
1093
- return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [groupedParam, optionsParam].filter((param) => param !== null) });
1094
- }
1095
- function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver }) {
1191
+ //#region src/components/Query.tsx
1192
+ const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1193
+ const callPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1194
+ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, infinite }) {
1096
1195
  const { TData, TError } = buildResponseTypes(node, tsResolver);
1097
- const returnType = `UseInfiniteQueryReturnType<${["TData", TError].join(", ")}> & { queryKey: TQueryKey }`;
1196
+ const optionsName = infinite ? "UseInfiniteQueryOptions" : "UseQueryOptions";
1197
+ const hookName = infinite ? "useInfiniteQuery" : "useQuery";
1198
+ const returnType = `${infinite ? "UseInfiniteQueryReturnType" : "UseQueryReturnType"}<${["TData", TError].join(", ")}> & { queryKey: TQueryKey }`;
1098
1199
  const generics = [
1099
- `TData = InfiniteData<${TData}>`,
1200
+ infinite ? `TData = InfiniteData<${TData}>` : `TData = ${TData}`,
1100
1201
  `TQueryData = ${TData}`,
1101
1202
  `TQueryKey extends QueryKey = ${queryKeyTypeName}`
1102
1203
  ];
1103
- const queryKeyParamsNode = buildQueryKeyParamsNode(node, { resolver: tsResolver });
1104
- const queryKeyParamsCall = callPrinter$2.print(queryKeyParamsNode) ?? "";
1105
- const queryOptionsParamsNode = getQueryOptionsParams(node, { resolver: tsResolver });
1106
- const queryOptionsParamsCall = callPrinter$2.print(queryOptionsParamsNode) ?? "";
1107
- const paramsNode = buildInfiniteQueryParamsNode(node, { resolver: tsResolver });
1108
- const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
1109
- return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
1110
- name,
1111
- isExportable: true,
1112
- isIndexable: true,
1113
- children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
1114
- name,
1115
- export: true,
1116
- generics: generics.join(", "),
1117
- params: paramsSignature,
1118
- JSDoc: { comments: buildOperationComments(node) },
1119
- children: `
1120
- const { query: queryConfig = {}, client: config = {} } = options ?? {}
1121
- const { client: queryClient, ...resolvedOptions } = queryConfig
1122
- const queryKey = (resolvedOptions && 'queryKey' in resolvedOptions ? toValue(resolvedOptions.queryKey) : undefined) ?? ${queryKeyName}(${queryKeyParamsCall})
1123
-
1124
- const queryResult = useInfiniteQuery({
1125
- ...${queryOptionsName}(${queryOptionsParamsCall}),
1126
- ...resolvedOptions,
1127
- queryKey
1128
- } as unknown as UseInfiniteQueryOptions<${TData}, ${TError}, ${TData}, TQueryKey, ${TData}>, toValue(queryClient)) as ${returnType}
1129
-
1130
- queryResult.queryKey = queryKey as TQueryKey
1131
-
1132
- return queryResult
1133
- `
1134
- })
1135
- });
1136
- }
1137
- //#endregion
1138
- //#region src/components/InfiniteQueryOptions.tsx
1139
- /**
1140
- * The vue-query flavor of the shared `infiniteQueryOptions` component: request groups accept
1141
- * `MaybeRefOrGetter` values, are unwrapped with `toValue(...)` in the client call, and the emitted
1142
- * `TQueryKey` generic is the imported `QueryKey` type instead of `typeof queryKey`.
1143
- */
1144
- function InfiniteQueryOptions(props) {
1145
- return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(InfiniteQueryOptions$1, {
1146
- ...props,
1147
- queryKeyType: "QueryKey",
1148
- memberTypeWrapper: maybeRefOrGetter,
1149
- unwrapName: (name) => `toValue(${name})`
1150
- });
1151
- }
1152
- //#endregion
1153
- //#region src/components/Mutation.tsx
1154
- const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1155
- const callPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1156
- function resolveMutationRequestType(node, resolver) {
1157
- return buildGroupedRequestParam(node, { resolver }) ? resolver.response.options(node) : "undefined";
1158
- }
1159
- function buildMutationParamsNode(node, options) {
1160
- const { resolver } = options;
1161
- const { TData, TError } = buildResponseTypes(node, resolver);
1162
- const TRequest = resolveMutationRequestType(node, resolver);
1163
- return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [(0, _kubb_plugin_ts.createFunctionParameter)({
1164
- name: "options",
1165
- type: `{
1166
- mutation?: MutationObserverOptions<${[
1167
- TData,
1168
- TError,
1169
- TRequest,
1170
- "TContext"
1171
- ].join(", ")}> & { client?: QueryClient },
1172
- client?: ${buildRequestConfigType(node)},
1173
- }`,
1174
- default: "{}"
1175
- })] });
1176
- }
1177
- function Mutation({ name, clientName, node, tsResolver, mutationKeyName, returnType = "full" }) {
1178
- const { TData, TError } = buildResponseTypes(node, tsResolver);
1179
- const groupedParam = buildGroupedRequestParam(node, { resolver: tsResolver });
1180
- const hasMutationParams = groupedParam !== null;
1181
- const groupedParamsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: groupedParam ? [groupedParam] : [] });
1182
- const argBindingStr = hasMutationParams ? callPrinter$1.print(groupedParamsNode) ?? "" : "";
1183
- const TRequest = resolveMutationRequestType(node, tsResolver);
1184
- const mutationFnBody = buildCallResultBody(buildClientCall(node, {
1185
- clientName,
1186
- signal: false,
1187
- unwrapName: (name) => `toValue<${TRequest}['${name}']>(${name})`
1188
- }), { returnType });
1189
- const generics = [
1204
+ const optionsGenerics = infinite ? [
1190
1205
  TData,
1191
1206
  TError,
1192
- TRequest,
1193
- "TContext"
1194
- ].join(", ");
1195
- const paramsNode = buildMutationParamsNode(node, { resolver: tsResolver });
1196
- const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
1197
- return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
1198
- name,
1199
- isExportable: true,
1200
- isIndexable: true,
1201
- children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
1202
- name,
1203
- export: true,
1204
- params: paramsSignature,
1205
- JSDoc: { comments: buildOperationComments(node) },
1206
- generics: ["TContext"],
1207
- children: `
1208
- const { mutation = {}, client: config = {} } = options ?? {}
1209
- const { client: queryClient, ...mutationOptions } = mutation;
1210
- const mutationKey = mutationOptions?.mutationKey ?? ${mutationKeyName}()
1211
-
1212
- return useMutation<${generics}>({
1213
- mutationFn: async(${argBindingStr}) => {
1214
- ${mutationFnBody}
1215
- },
1216
- mutationKey,
1217
- ...mutationOptions
1218
- }, queryClient)
1219
- `
1220
- })
1221
- });
1222
- }
1223
- //#endregion
1224
- //#region src/components/Query.tsx
1225
- const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1226
- const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1227
- function buildQueryParamsNode(node, options) {
1228
- const { resolver } = options;
1229
- const { TData, TError } = buildResponseTypes(node, resolver);
1230
- const optionsParam = (0, _kubb_plugin_ts.createFunctionParameter)({
1231
- name: "options",
1232
- type: `{
1233
- query?: Partial<UseQueryOptions<${[
1234
- TData,
1235
- TError,
1236
- "TData",
1237
- "TQueryData",
1238
- "TQueryKey"
1239
- ].join(", ")}>> & { client?: QueryClient },
1240
- client?: ${buildClientOptionType()}
1241
- }`,
1242
- default: "{}"
1243
- });
1244
- const groupedParam = buildGroupedRequestParam(node, {
1245
- resolver,
1207
+ "TQueryData",
1208
+ "TQueryKey",
1209
+ "TQueryData"
1210
+ ] : [
1211
+ TData,
1212
+ TError,
1213
+ "TData",
1214
+ "TQueryData",
1215
+ "TQueryKey"
1216
+ ];
1217
+ const castGenerics = infinite ? [
1218
+ TData,
1219
+ TError,
1220
+ TData,
1221
+ "TQueryKey",
1222
+ TData
1223
+ ] : [
1224
+ TData,
1225
+ TError,
1226
+ "TData",
1227
+ TData,
1228
+ "TQueryKey"
1229
+ ];
1230
+ const queryKeyParamsNode = buildQueryKeyParams(node, {
1231
+ resolver: tsResolver,
1246
1232
  memberTypeWrapper: maybeRefOrGetter
1247
1233
  });
1248
- return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [groupedParam, optionsParam].filter((param) => param !== null) });
1249
- }
1250
- function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver }) {
1251
- const { TData, TError } = buildResponseTypes(node, tsResolver);
1252
- const returnType = `UseQueryReturnType<${["TData", TError].join(", ")}> & { queryKey: TQueryKey }`;
1253
- const generics = [
1254
- `TData = ${TData}`,
1255
- `TQueryData = ${TData}`,
1256
- `TQueryKey extends QueryKey = ${queryKeyTypeName}`
1257
- ];
1258
- const queryKeyParamsNode = buildQueryKeyParamsNode(node, { resolver: tsResolver });
1259
- const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? "";
1234
+ const queryKeyParamsCall = callPrinter$1.print(queryKeyParamsNode) ?? "";
1260
1235
  const queryOptionsParamsNode = getQueryOptionsParams(node, { resolver: tsResolver });
1261
- const queryOptionsParamsCall = callPrinter.print(queryOptionsParamsNode) ?? "";
1262
- const paramsNode = buildQueryParamsNode(node, { resolver: tsResolver });
1263
- const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
1236
+ const queryOptionsParamsCall = callPrinter$1.print(queryOptionsParamsNode) ?? "";
1237
+ const paramsNode = buildHookParams(node, {
1238
+ resolver: tsResolver,
1239
+ memberTypeWrapper: maybeRefOrGetter,
1240
+ optionsType: `{
1241
+ query?: Partial<${optionsName}<${optionsGenerics.join(", ")}>> & { client?: QueryClient },
1242
+ client?: ${buildClientOptionType()}
1243
+ }`
1244
+ });
1245
+ const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
1264
1246
  return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
1265
1247
  name,
1266
1248
  isExportable: true,
@@ -1276,11 +1258,11 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
1276
1258
  const { client: queryClient, ...resolvedOptions } = queryConfig
1277
1259
  const queryKey = (resolvedOptions && 'queryKey' in resolvedOptions ? toValue(resolvedOptions.queryKey) : undefined) ?? ${queryKeyName}(${queryKeyParamsCall})
1278
1260
 
1279
- const queryResult = useQuery({
1261
+ const queryResult = ${hookName}({
1280
1262
  ...${queryOptionsName}(${queryOptionsParamsCall}),
1281
1263
  ...resolvedOptions,
1282
1264
  queryKey
1283
- } as unknown as UseQueryOptions<${TData}, ${TError}, TData, ${TData}, TQueryKey>, toValue(queryClient)) as ${returnType}
1265
+ } as unknown as ${optionsName}<${castGenerics.join(", ")}>, toValue(queryClient)) as ${returnType}
1284
1266
 
1285
1267
  queryResult.queryKey = queryKey as TQueryKey
1286
1268
 
@@ -1314,14 +1296,12 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
1314
1296
  },
1315
1297
  operation(node, ctx) {
1316
1298
  if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
1317
- const { config, driver, resolver, root } = ctx;
1299
+ const { driver, resolver, root } = ctx;
1318
1300
  const { output, query, infinite, client, group } = ctx.options;
1319
1301
  const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
1320
1302
  if (!infiniteOptions) return null;
1321
1303
  const pageParamsWarning = getDefaultPageParamsWarning(node, infiniteOptions);
1322
1304
  if (pageParamsWarning) ctx.warn(pageParamsWarning);
1323
- const pluginTs = ctx.requirePlugin(_kubb_plugin_ts.pluginTsName);
1324
- const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
1325
1305
  const importPath = query ? query.importPath : "@tanstack/vue-query";
1326
1306
  const contractOp = resolveClientOperation({
1327
1307
  clientPlugin: { pluginName: client.pluginName },
@@ -1336,91 +1316,39 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
1336
1316
  const queryOptionsName = resolver.infiniteQuery.optionsName(node);
1337
1317
  const queryKeyName = resolver.infiniteQuery.keyName(node);
1338
1318
  const queryKeyTypeName = resolver.infiniteQuery.keyTypeName(node);
1339
- const meta = {
1340
- file: resolver.file({
1341
- ...operationFileEntry(node, queryName),
1342
- root,
1343
- output,
1344
- group: group ?? void 0
1345
- }),
1346
- fileTs: resolveDependencyOperationFile({
1347
- cache: ctx.cache,
1348
- node,
1349
- resolver: tsResolver,
1350
- root,
1351
- output: pluginTs.options?.output ?? output,
1352
- group: pluginTs.options?.group
1353
- })
1354
- };
1355
- const { queryParamsTypeName } = resolvePageParamType(node, {
1356
- resolver: tsResolver,
1357
- initialPageParam: infiniteOptions.initialPageParam,
1358
- queryParam: infiniteOptions.queryParam
1319
+ const hook = resolveHookFile(node, ctx, {
1320
+ name: queryName,
1321
+ output,
1322
+ group,
1323
+ contractOp,
1324
+ keyTypeName: queryKeyTypeName,
1325
+ extraTypeNames: [resolvePageParamType(node, {
1326
+ resolver: ctx.driver.getResolver(_kubb_plugin_ts.pluginTsName),
1327
+ initialPageParam: infiniteOptions.initialPageParam,
1328
+ queryParam: infiniteOptions.queryParam
1329
+ }).queryParamsTypeName]
1359
1330
  });
1360
- const importedTypeNames = [
1361
- tsResolver.response.options(node),
1362
- queryParamsTypeName,
1363
- ...resolveOperationTypeNames(node, tsResolver, {
1364
- exclude: [queryKeyTypeName],
1365
- order: "body-response-first",
1366
- includeParams: false
1367
- })
1368
- ].filter((name) => Boolean(name));
1369
- const calledClientName = contractOp.name;
1370
- return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File, {
1371
- baseName: meta.file.baseName,
1372
- path: meta.file.path,
1373
- meta: meta.file.meta,
1374
- banner: resolver.default.banner(ctx.meta, {
1375
- output,
1376
- config,
1377
- file: {
1378
- path: meta.file.path,
1379
- baseName: meta.file.baseName
1380
- }
1381
- }),
1382
- footer: resolver.default.footer(ctx.meta, {
1383
- output,
1384
- config,
1385
- file: {
1386
- path: meta.file.path,
1387
- baseName: meta.file.baseName
1388
- }
1389
- }),
1331
+ const { tsResolver } = hook;
1332
+ return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(HookFile, {
1333
+ hook,
1334
+ imports: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1335
+ name: ["toValue"],
1336
+ path: "vue"
1337
+ }), /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1338
+ name: ["MaybeRefOrGetter"],
1339
+ path: "vue",
1340
+ isTypeOnly: true
1341
+ })] }),
1390
1342
  children: [
1391
- /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1392
- name: [contractOp.name],
1393
- root: meta.file.path,
1394
- path: contractOp.path
1395
- }),
1396
- /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1397
- name: ["RequestConfig", "ResponseErrorConfig"],
1398
- root: contractOp.clientPathIsFile ? meta.file.path : void 0,
1399
- path: contractOp.clientPath,
1400
- isTypeOnly: true
1401
- }),
1402
- /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1403
- name: ["toValue"],
1404
- path: "vue"
1405
- }),
1406
- /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1407
- name: ["MaybeRefOrGetter"],
1408
- path: "vue",
1409
- isTypeOnly: true
1410
- }),
1411
- meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1412
- name: Array.from(new Set(importedTypeNames)),
1413
- root: meta.file.path,
1414
- path: meta.fileTs.path,
1415
- isTypeOnly: true
1416
- }),
1417
1343
  /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(QueryKey, {
1418
1344
  name: queryKeyName,
1419
1345
  typeName: queryKeyTypeName,
1420
1346
  node,
1421
1347
  tsResolver,
1422
1348
  transformer: ctx.options.queryKey,
1423
- variant: "infiniteQuery"
1349
+ variant: "infiniteQuery",
1350
+ memberTypeWrapper: maybeRefOrGetter,
1351
+ exportType: true
1424
1352
  }),
1425
1353
  /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1426
1354
  name: ["InfiniteData"],
@@ -1433,7 +1361,7 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
1433
1361
  }),
1434
1362
  /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(InfiniteQueryOptions, {
1435
1363
  name: queryOptionsName,
1436
- clientName: calledClientName,
1364
+ clientName: contractOp.name,
1437
1365
  queryKeyName,
1438
1366
  node,
1439
1367
  tsResolver,
@@ -1445,7 +1373,10 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
1445
1373
  initialPageParam: infiniteOptions.initialPageParam,
1446
1374
  hasExplicitInitialPageParam: infiniteOptions.hasExplicitInitialPageParam,
1447
1375
  queryParam: infiniteOptions.queryParam,
1448
- returnType: contractOp.returnType
1376
+ returnType: contractOp.returnType,
1377
+ queryKeyType: "QueryKey",
1378
+ memberTypeWrapper: maybeRefOrGetter,
1379
+ unwrapName: (name) => `toValue(${name})`
1449
1380
  }),
1450
1381
  /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1451
1382
  name: ["useInfiniteQuery"],
@@ -1461,21 +1392,87 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
1461
1392
  path: importPath,
1462
1393
  isTypeOnly: true
1463
1394
  }),
1464
- /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(InfiniteQuery, {
1395
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(Query, {
1465
1396
  name: queryName,
1466
1397
  queryOptionsName,
1467
1398
  queryKeyName,
1468
1399
  queryKeyTypeName,
1469
1400
  node,
1470
1401
  tsResolver,
1471
- initialPageParam: infiniteOptions.initialPageParam,
1472
- queryParam: infiniteOptions.queryParam
1402
+ infinite: true
1473
1403
  })
1474
1404
  ]
1475
1405
  });
1476
1406
  }
1477
1407
  });
1478
1408
  //#endregion
1409
+ //#region src/components/Mutation.tsx
1410
+ const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1411
+ const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1412
+ function buildMutationParamsNode(node, options) {
1413
+ const { resolver } = options;
1414
+ const { TData, TError } = buildResponseTypes(node, resolver);
1415
+ return buildHookParams(node, {
1416
+ resolver,
1417
+ withRequest: false,
1418
+ optionsType: `{
1419
+ mutation?: MutationObserverOptions<${[
1420
+ TData,
1421
+ TError,
1422
+ resolveMutationRequestType(node, resolver),
1423
+ "TContext"
1424
+ ].join(", ")}> & { client?: QueryClient },
1425
+ client?: ${buildRequestConfigType(node)},
1426
+ }`
1427
+ });
1428
+ }
1429
+ function Mutation({ name, clientName, node, tsResolver, mutationKeyName, returnType = "full" }) {
1430
+ const { TData, TError } = buildResponseTypes(node, tsResolver);
1431
+ const groupedParam = buildGroupedRequestParam(node, { resolver: tsResolver });
1432
+ const hasMutationParams = groupedParam !== null;
1433
+ const groupedParamsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: groupedParam ? [groupedParam] : [] });
1434
+ const argBindingStr = hasMutationParams ? callPrinter.print(groupedParamsNode) ?? "" : "";
1435
+ const TRequest = resolveMutationRequestType(node, tsResolver);
1436
+ const mutationFnBody = buildCallResultBody(buildClientCall(node, {
1437
+ clientName,
1438
+ signal: false,
1439
+ unwrapName: (name) => `toValue<${TRequest}['${name}']>(${name})`
1440
+ }), { returnType });
1441
+ const generics = [
1442
+ TData,
1443
+ TError,
1444
+ TRequest,
1445
+ "TContext"
1446
+ ].join(", ");
1447
+ const paramsNode = buildMutationParamsNode(node, { resolver: tsResolver });
1448
+ const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
1449
+ return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
1450
+ name,
1451
+ isExportable: true,
1452
+ isIndexable: true,
1453
+ children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
1454
+ name,
1455
+ export: true,
1456
+ params: paramsSignature,
1457
+ JSDoc: { comments: buildOperationComments(node) },
1458
+ generics: ["TContext"],
1459
+ children: `
1460
+ const { mutation = {}, client: config = {} } = options ?? {}
1461
+ const { client: queryClient, ...mutationOptions } = mutation;
1462
+ const mutationKey = mutationOptions?.mutationKey ?? ${mutationKeyName}()
1463
+
1464
+ return useMutation<${generics}>({
1465
+ mutationFn: async(${argBindingStr}) => {
1466
+ ${mutationFnBody}
1467
+ },
1468
+ mutationKey,
1469
+ ...mutationOptions
1470
+ }, queryClient)
1471
+ `
1472
+ })
1473
+ });
1474
+ }
1475
+ //#endregion
1479
1476
  //#region src/generators/mutationGenerator.tsx
1480
1477
  /**
1481
1478
  * Built-in generator for `useMutation` composables. Emits one
@@ -1487,10 +1484,8 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
1487
1484
  renderer: kubb_jsx.jsxRenderer,
1488
1485
  operation(node, ctx) {
1489
1486
  if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
1490
- const { config, driver, resolver, root } = ctx;
1487
+ const { driver, resolver, root } = ctx;
1491
1488
  const { output, query, mutation, client, group, hooks } = ctx.options;
1492
- const pluginTs = ctx.requirePlugin(_kubb_plugin_ts.pluginTsName);
1493
- const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
1494
1489
  const { isMutation } = classifyOperation(node, {
1495
1490
  query,
1496
1491
  mutation
@@ -1507,104 +1502,48 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
1507
1502
  });
1508
1503
  if (!contractOp) return null;
1509
1504
  const mutationHookName = resolver.mutation.name(node);
1510
- const mutationTypeName = resolver.mutation.typeName(node);
1511
1505
  const mutationKeyName = resolver.mutation.keyName(node);
1512
- const meta = {
1513
- file: resolver.file({
1514
- ...operationFileEntry(node, mutationHookName),
1515
- root,
1516
- output,
1517
- group: group ?? void 0
1518
- }),
1519
- fileTs: resolveDependencyOperationFile({
1520
- cache: ctx.cache,
1521
- node,
1522
- resolver: tsResolver,
1523
- root,
1524
- output: pluginTs.options?.output ?? output,
1525
- group: pluginTs.options?.group
1526
- })
1527
- };
1528
- const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
1529
- order: "body-response-first",
1530
- includeParams: false
1531
- })].filter((name) => Boolean(name));
1532
- const calledClientName = contractOp.name;
1506
+ const hook = resolveHookFile(node, ctx, {
1507
+ name: mutationHookName,
1508
+ output,
1509
+ group,
1510
+ contractOp
1511
+ });
1533
1512
  const groups = getRequestGroups(node);
1534
1513
  const hasRequestGroups = groups.path || groups.query || groups.body || groups.headers;
1535
- return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File, {
1536
- baseName: meta.file.baseName,
1537
- path: meta.file.path,
1538
- meta: meta.file.meta,
1539
- banner: resolver.default.banner(ctx.meta, {
1540
- output,
1541
- config,
1542
- file: {
1543
- path: meta.file.path,
1544
- baseName: meta.file.baseName
1545
- }
1546
- }),
1547
- footer: resolver.default.footer(ctx.meta, {
1548
- output,
1549
- config,
1550
- file: {
1551
- path: meta.file.path,
1552
- baseName: meta.file.baseName
1553
- }
1554
- }),
1555
- children: [
1556
- /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1557
- name: [contractOp.name],
1558
- root: meta.file.path,
1559
- path: contractOp.path
1560
- }),
1514
+ return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(HookFile, {
1515
+ hook,
1516
+ imports: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [hasRequestGroups && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1517
+ name: ["toValue"],
1518
+ path: "vue"
1519
+ }), /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1520
+ name: ["MaybeRefOrGetter"],
1521
+ path: "vue",
1522
+ isTypeOnly: true
1523
+ })] }),
1524
+ children: [/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(MutationKey, {
1525
+ name: mutationKeyName,
1526
+ node,
1527
+ transformer: ctx.options.mutationKey
1528
+ }), mutation && hooks && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [
1561
1529
  /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1562
- name: ["RequestConfig", "ResponseErrorConfig"],
1563
- root: contractOp.clientPathIsFile ? meta.file.path : void 0,
1564
- path: contractOp.clientPath,
1565
- isTypeOnly: true
1566
- }),
1567
- hasRequestGroups && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1568
- name: ["toValue"],
1569
- path: "vue"
1530
+ name: ["useMutation"],
1531
+ path: importPath
1570
1532
  }),
1571
1533
  /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1572
- name: ["MaybeRefOrGetter"],
1573
- path: "vue",
1574
- isTypeOnly: true
1575
- }),
1576
- meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1577
- name: Array.from(new Set(importedTypeNames)),
1578
- root: meta.file.path,
1579
- path: meta.fileTs.path,
1534
+ name: ["MutationObserverOptions", "QueryClient"],
1535
+ path: importPath,
1580
1536
  isTypeOnly: true
1581
1537
  }),
1582
- /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(MutationKey, {
1583
- name: mutationKeyName,
1538
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(Mutation, {
1539
+ name: mutationHookName,
1540
+ clientName: contractOp.name,
1584
1541
  node,
1585
- transformer: ctx.options.mutationKey
1586
- }),
1587
- mutation && hooks && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [
1588
- /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1589
- name: ["useMutation"],
1590
- path: importPath
1591
- }),
1592
- /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1593
- name: ["MutationObserverOptions", "QueryClient"],
1594
- path: importPath,
1595
- isTypeOnly: true
1596
- }),
1597
- /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(Mutation, {
1598
- name: mutationHookName,
1599
- clientName: calledClientName,
1600
- typeName: mutationTypeName,
1601
- node,
1602
- tsResolver,
1603
- mutationKeyName,
1604
- returnType: contractOp.returnType
1605
- })
1606
- ] })
1607
- ]
1542
+ tsResolver: hook.tsResolver,
1543
+ mutationKeyName,
1544
+ returnType: contractOp.returnType
1545
+ })
1546
+ ] })]
1608
1547
  });
1609
1548
  }
1610
1549
  });
@@ -1620,10 +1559,8 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
1620
1559
  renderer: kubb_jsx.jsxRenderer,
1621
1560
  operation(node, ctx) {
1622
1561
  if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
1623
- const { config, driver, resolver, root } = ctx;
1562
+ const { driver, resolver, root } = ctx;
1624
1563
  const { output, query, mutation, client, group, hooks } = ctx.options;
1625
- const pluginTs = ctx.requirePlugin(_kubb_plugin_ts.pluginTsName);
1626
- const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
1627
1564
  const { isQuery, isMutation } = classifyOperation(node, {
1628
1565
  query,
1629
1566
  mutation
@@ -1643,82 +1580,34 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
1643
1580
  const queryOptionsName = resolver.query.optionsName(node);
1644
1581
  const queryKeyName = resolver.query.keyName(node);
1645
1582
  const queryKeyTypeName = resolver.query.keyTypeName(node);
1646
- const meta = {
1647
- file: resolver.file({
1648
- ...operationFileEntry(node, queryName),
1649
- root,
1650
- output,
1651
- group: group ?? void 0
1652
- }),
1653
- fileTs: resolveDependencyOperationFile({
1654
- cache: ctx.cache,
1655
- node,
1656
- resolver: tsResolver,
1657
- root,
1658
- output: pluginTs.options?.output ?? output,
1659
- group: pluginTs.options?.group
1660
- })
1661
- };
1662
- const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
1663
- exclude: [queryKeyTypeName],
1664
- order: "body-response-first",
1665
- includeParams: false
1666
- })].filter((name) => Boolean(name));
1667
- const calledClientName = contractOp.name;
1668
- return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File, {
1669
- baseName: meta.file.baseName,
1670
- path: meta.file.path,
1671
- meta: meta.file.meta,
1672
- banner: resolver.default.banner(ctx.meta, {
1673
- output,
1674
- config,
1675
- file: {
1676
- path: meta.file.path,
1677
- baseName: meta.file.baseName
1678
- }
1679
- }),
1680
- footer: resolver.default.footer(ctx.meta, {
1681
- output,
1682
- config,
1683
- file: {
1684
- path: meta.file.path,
1685
- baseName: meta.file.baseName
1686
- }
1687
- }),
1583
+ const hook = resolveHookFile(node, ctx, {
1584
+ name: queryName,
1585
+ output,
1586
+ group,
1587
+ contractOp,
1588
+ keyTypeName: queryKeyTypeName
1589
+ });
1590
+ const { tsResolver } = hook;
1591
+ return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(HookFile, {
1592
+ hook,
1593
+ imports: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1594
+ name: ["toValue"],
1595
+ path: "vue"
1596
+ }), /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1597
+ name: ["MaybeRefOrGetter"],
1598
+ path: "vue",
1599
+ isTypeOnly: true
1600
+ })] }),
1688
1601
  children: [
1689
- /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1690
- name: [contractOp.name],
1691
- root: meta.file.path,
1692
- path: contractOp.path
1693
- }),
1694
- /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1695
- name: ["RequestConfig", "ResponseErrorConfig"],
1696
- root: contractOp.clientPathIsFile ? meta.file.path : void 0,
1697
- path: contractOp.clientPath,
1698
- isTypeOnly: true
1699
- }),
1700
- /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1701
- name: ["toValue"],
1702
- path: "vue"
1703
- }),
1704
- /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1705
- name: ["MaybeRefOrGetter"],
1706
- path: "vue",
1707
- isTypeOnly: true
1708
- }),
1709
- meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1710
- name: Array.from(new Set(importedTypeNames)),
1711
- root: meta.file.path,
1712
- path: meta.fileTs.path,
1713
- isTypeOnly: true
1714
- }),
1715
1602
  /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(QueryKey, {
1716
1603
  name: queryKeyName,
1717
1604
  typeName: queryKeyTypeName,
1718
1605
  node,
1719
1606
  tsResolver,
1720
1607
  transformer: ctx.options.queryKey,
1721
- variant: "query"
1608
+ variant: "query",
1609
+ memberTypeWrapper: maybeRefOrGetter,
1610
+ exportType: true
1722
1611
  }),
1723
1612
  /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1724
1613
  name: ["queryOptions"],
@@ -1726,7 +1615,7 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
1726
1615
  }),
1727
1616
  /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(QueryOptions, {
1728
1617
  name: queryOptionsName,
1729
- clientName: calledClientName,
1618
+ clientName: contractOp.name,
1730
1619
  queryKeyName,
1731
1620
  node,
1732
1621
  tsResolver,
@@ -1842,6 +1731,7 @@ const pluginVueQuery = (0, kubb_kit.defineExtension)({
1842
1731
  return {
1843
1732
  output,
1844
1733
  client: resolveContractClient({
1734
+ plugin: pluginVueQueryName,
1845
1735
  client,
1846
1736
  plugins: (0, kubb_kit.useConfig)().plugins
1847
1737
  }),