@orval/query 8.1.0 → 8.3.0

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.mjs CHANGED
@@ -58,11 +58,6 @@ const vueUnRefParams = (props) => {
58
58
  };
59
59
  const wrapRouteParameters = (route, prepend, append) => route.replaceAll(TEMPLATE_TAG_REGEX, `\${${prepend}$1${append}}`);
60
60
  const makeRouteSafe = (route) => wrapRouteParameters(route, "encodeURIComponent(String(", "))");
61
- const isVue = (client) => OutputClient.VUE_QUERY === client;
62
- const isSolid = (client) => OutputClient.SOLID_QUERY === client;
63
- const isAngular = (client) => OutputClient.ANGULAR_QUERY === client;
64
- const isReact = (client) => OutputClient.REACT_QUERY === client;
65
- const isSvelte = (client) => OutputClient.SVELTE_QUERY === client;
66
61
  const getQueryTypeForFramework = (type) => {
67
62
  switch (type) {
68
63
  case "suspenseQuery": return "query";
@@ -121,14 +116,13 @@ const ANGULAR_HTTP_DEPENDENCIES = [
121
116
  exports: [{
122
117
  name: "takeUntil",
123
118
  values: true
119
+ }, {
120
+ name: "map",
121
+ values: true
124
122
  }],
125
123
  dependency: "rxjs/operators"
126
124
  }
127
125
  ];
128
- const generateQueryRequestFunction = (verbOptions, options, isVue$1, isAngularClient = false) => {
129
- if (isAngularClient || options.context.output.httpClient === OutputHttpClient.ANGULAR) return generateAngularHttpRequestFunction(verbOptions, options);
130
- return options.context.output.httpClient === OutputHttpClient.AXIOS ? generateAxiosRequestFunction(verbOptions, options, isVue$1) : generateRequestFunction(verbOptions, options);
131
- };
132
126
  const generateAngularHttpRequestFunction = ({ headers, queryParams, operationName, response, mutator, body, props, verb, formData, formUrlEncoded, override }, { route, context }) => {
133
127
  const isRequestOptions = override.requestOptions !== false;
134
128
  const isFormData = !override.formData.disabled;
@@ -180,7 +174,7 @@ const generateAngularHttpRequestFunction = ({ headers, queryParams, operationNam
180
174
  if (headers) httpOptions.push("headers: new HttpHeaders(headers)");
181
175
  const optionsStr = httpOptions.length > 0 ? `, { ${httpOptions.join(", ")} }` : "";
182
176
  let httpCall;
183
- const bodyArg = body.definition ? toObjectString([body], "implementation").replace(/,\s*$/, "") : "";
177
+ const bodyArg = isFormData && body.formData ? "formData" : isFormUrlEncoded && body.formUrlEncoded ? "formUrlEncoded" : body.definition ? toObjectString([body], "implementation").replace(/,\s*$/, "") : "";
184
178
  switch (verb) {
185
179
  case "get":
186
180
  case "head":
@@ -193,6 +187,17 @@ const generateAngularHttpRequestFunction = ({ headers, queryParams, operationNam
193
187
  httpCall = `http.${verb}<${dataType}>(url, ${bodyArg || "undefined"}${optionsStr})`;
194
188
  break;
195
189
  }
190
+ const responseType = response.definition.success;
191
+ const isPrimitiveType = [
192
+ "string",
193
+ "number",
194
+ "boolean",
195
+ "void",
196
+ "unknown"
197
+ ].includes(responseType);
198
+ const hasSchema = response.imports.some((imp) => imp.name === responseType);
199
+ const isZodOutput = isObject(context.output.schemas) && context.output.schemas.type === "zod";
200
+ if (override.query.runtimeValidation && isZodOutput && !isPrimitiveType && hasSchema) httpCall = `${httpCall}.pipe(map(data => ${responseType}.parse(data)))`;
196
201
  const additionalParams = [queryProps, hasSignal ? "options?: { signal?: AbortSignal | null }" : ""].filter(Boolean).join(", ");
197
202
  return `${override.query.shouldExportHttpClient ? "export " : ""}const ${operationName} = (
198
203
  http: HttpClient${additionalParams ? `,\n ${additionalParams}` : ""}
@@ -207,10 +212,10 @@ const generateAngularHttpRequestFunction = ({ headers, queryParams, operationNam
207
212
  }
208
213
  `;
209
214
  };
210
- const generateAxiosRequestFunction = ({ headers, queryParams, operationName, response, mutator, body, props: _props, verb, formData, formUrlEncoded, override, paramsSerializer }, { route: _route, context }, isVue$1) => {
215
+ const generateAxiosRequestFunction = ({ headers, queryParams, operationName, response, mutator, body, props: _props, verb, formData, formUrlEncoded, override, paramsSerializer }, { route: _route, context }, isVue) => {
211
216
  let props = _props;
212
217
  let route = _route;
213
- if (isVue$1) props = vueWrapTypeWithMaybeRef(_props);
218
+ if (isVue) props = vueWrapTypeWithMaybeRef(_props);
214
219
  if (context.output.urlEncodeParameters) route = makeRouteSafe(route);
215
220
  const isRequestOptions = override.requestOptions !== false;
216
221
  const isFormData = !override.formData.disabled;
@@ -238,7 +243,7 @@ const generateAxiosRequestFunction = ({ headers, queryParams, operationName, res
238
243
  hasSignal,
239
244
  hasSignalParam,
240
245
  isExactOptionalPropertyTypes,
241
- isVue: isVue$1
246
+ isVue
242
247
  });
243
248
  const bodyDefinition = body.definition.replace("[]", String.raw`\[\]`);
244
249
  const propsImplementation = mutator.bodyTypeName && body.definition ? toObjectString(props, "implementation").replace(new RegExp(String.raw`(\w*):\s?${bodyDefinition}`), `$1: ${mutator.bodyTypeName}<${body.definition}>`) : toObjectString(props, "implementation");
@@ -270,13 +275,13 @@ const generateAxiosRequestFunction = ({ headers, queryParams, operationName, res
270
275
  }
271
276
  }
272
277
  `;
273
- return isVue$1 ? vueRet : ret;
278
+ return isVue ? vueRet : ret;
274
279
  }
275
280
  return `${override.query.shouldExportHttpClient ? "export " : ""}const ${operationName} = (\n ${propsImplementation}\n ${isRequestOptions && mutator.hasSecondArg ? `options${context.output.optionsParamRequired ? "" : "?"}: SecondParameter<typeof ${mutator.name}>,` : ""}${getSignalDefinition({
276
281
  hasSignal,
277
282
  hasSignalParam
278
283
  })}) => {
279
- ${isVue$1 ? vueUnRefParams(props) : ""}
284
+ ${isVue ? vueUnRefParams(props) : ""}
280
285
  ${bodyForm}
281
286
  return ${mutator.name}<${response.definition.success || "unknown"}>(
282
287
  ${mutatorConfig},
@@ -300,7 +305,7 @@ const generateAxiosRequestFunction = ({ headers, queryParams, operationName, res
300
305
  isExactOptionalPropertyTypes,
301
306
  hasSignal,
302
307
  hasSignalParam,
303
- isVue: isVue$1
308
+ isVue
304
309
  });
305
310
  const optionsArgs = generateRequestOptionsArguments({
306
311
  isRequestOptions,
@@ -309,7 +314,7 @@ const generateAxiosRequestFunction = ({ headers, queryParams, operationName, res
309
314
  });
310
315
  const queryProps = toObjectString(props, "implementation");
311
316
  return `${override.query.shouldExportHttpClient ? "export " : ""}const ${operationName} = (\n ${queryProps} ${optionsArgs} ): Promise<AxiosResponse<${response.definition.success || "unknown"}>> => {
312
- ${isVue$1 ? vueUnRefParams(props) : ""}
317
+ ${isVue ? vueUnRefParams(props) : ""}
313
318
  ${bodyForm}
314
319
  return axios${isSyntheticDefaultImportsAllowed ? "" : ".default"}.${verb}(${options});
315
320
  }
@@ -389,11 +394,6 @@ const getMutationRequestArgs = (isRequestOptions, httpClient, mutator) => {
389
394
  if (mutator?.hasSecondArg && httpClient === OutputHttpClient.ANGULAR) return "http";
390
395
  return isRequestOptions ? mutator ? mutator.hasSecondArg ? "requestOptions" : "" : options : "";
391
396
  };
392
- const getHttpFunctionQueryProps = (isVue$1, httpClient, queryProperties, isAngular$1 = false, hasMutator = false) => {
393
- const result = isVue$1 && httpClient === OutputHttpClient.FETCH && queryProperties ? queryProperties.split(",").map((prop) => `unref(${prop})`).join(",") : queryProperties;
394
- if ((isAngular$1 || httpClient === OutputHttpClient.ANGULAR) && !hasMutator) return result ? `http, ${result}` : "http";
395
- return result;
396
- };
397
397
  const getQueryHeader = (params) => {
398
398
  return params.output.httpClient === OutputHttpClient.FETCH ? generateFetchHeader(params) : "";
399
399
  };
@@ -583,7 +583,8 @@ const REACT_QUERY_DEPENDENCIES = [{
583
583
  const getReactQueryDependencies = (hasGlobalMutator, hasParamsSerializerOptions, packageJson, httpClient, hasTagsMutator, override) => {
584
584
  const hasReactQuery = packageJson?.dependencies?.["react-query"] ?? packageJson?.devDependencies?.["react-query"] ?? packageJson?.peerDependencies?.["react-query"];
585
585
  const hasReactQueryV4 = packageJson?.dependencies?.["@tanstack/react-query"] ?? packageJson?.devDependencies?.["@tanstack/react-query"] ?? packageJson?.peerDependencies?.["@tanstack/react-query"];
586
- const useReactQueryV3 = override.query.version === void 0 ? hasReactQuery && !hasReactQueryV4 : override.query.version <= 3;
586
+ const queryVersion = override?.query.version;
587
+ const useReactQueryV3 = queryVersion === void 0 ? hasReactQuery && !hasReactQueryV4 : queryVersion <= 3;
587
588
  return [
588
589
  ...hasGlobalMutator || hasTagsMutator ? REACT_DEPENDENCIES : [],
589
590
  ...!hasGlobalMutator && httpClient === OutputHttpClient.AXIOS ? AXIOS_DEPENDENCIES : [],
@@ -682,36 +683,39 @@ const VUE_QUERY_DEPENDENCIES = [{
682
683
  ],
683
684
  dependency: "vue"
684
685
  }];
685
- const SOLID_QUERY_DEPENDENCIES = [{
686
- exports: [
687
- {
688
- name: "createQuery",
689
- values: true
690
- },
691
- {
692
- name: "createInfiniteQuery",
693
- values: true
694
- },
695
- {
696
- name: "createMutation",
697
- values: true
698
- },
699
- { name: "CreateQueryOptions" },
700
- { name: "CreateInfiniteQueryOptions" },
701
- { name: "CreateMutationOptions" },
702
- { name: "QueryFunction" },
703
- { name: "MutationFunction" },
704
- { name: "CreateQueryResult" },
705
- { name: "CreateInfiniteQueryResult" },
706
- { name: "QueryKey" },
707
- { name: "InfiniteData" },
708
- { name: "CreateMutationResult" },
709
- { name: "DataTag" },
710
- { name: "QueryClient" },
711
- { name: "InvalidateOptions" }
712
- ],
713
- dependency: "@tanstack/solid-query"
714
- }];
686
+ const getSolidQueryImports = (prefix) => {
687
+ const capitalized = prefix === "use" ? "Use" : "Create";
688
+ return [{
689
+ exports: [
690
+ {
691
+ name: `${prefix}Query`,
692
+ values: true
693
+ },
694
+ {
695
+ name: `${prefix}InfiniteQuery`,
696
+ values: true
697
+ },
698
+ {
699
+ name: `${prefix}Mutation`,
700
+ values: true
701
+ },
702
+ { name: `${capitalized}QueryOptions` },
703
+ { name: `${capitalized}InfiniteQueryOptions` },
704
+ { name: `${capitalized}MutationOptions` },
705
+ { name: "QueryFunction" },
706
+ { name: "MutationFunction" },
707
+ { name: `${capitalized}QueryResult` },
708
+ { name: `${capitalized}InfiniteQueryResult` },
709
+ { name: "QueryKey" },
710
+ { name: "InfiniteData" },
711
+ { name: `${capitalized}MutationResult` },
712
+ { name: "DataTag" },
713
+ { name: "QueryClient" },
714
+ { name: "InvalidateOptions" }
715
+ ],
716
+ dependency: "@tanstack/solid-query"
717
+ }];
718
+ };
715
719
  const ANGULAR_QUERY_DEPENDENCIES = [{
716
720
  exports: [
717
721
  {
@@ -778,7 +782,7 @@ const getSolidQueryDependencies = (hasGlobalMutator, hasParamsSerializerOptions,
778
782
  return [
779
783
  ...!hasGlobalMutator && httpClient === OutputHttpClient.AXIOS ? AXIOS_DEPENDENCIES : [],
780
784
  ...hasParamsSerializerOptions ? PARAMS_SERIALIZER_DEPENDENCIES : [],
781
- ...SOLID_QUERY_DEPENDENCIES
785
+ ...getSolidQueryImports(isSolidQueryWithUsePrefix(packageJson) ? "use" : "create")
782
786
  ];
783
787
  };
784
788
  const getAngularQueryDependencies = (hasGlobalMutator, hasParamsSerializerOptions, packageJson, httpClient) => {
@@ -818,6 +822,12 @@ const isQueryV5WithInfiniteQueryOptionsError = (packageJson, queryClient) => {
818
822
  const withoutRc = version.split("-")[0];
819
823
  return compareVersions(withoutRc, "5.80.0");
820
824
  };
825
+ const isSolidQueryWithUsePrefix = (packageJson) => {
826
+ const version = getPackageByQueryClient(packageJson, "solid-query");
827
+ if (!version) return false;
828
+ const withoutRc = version.split("-")[0];
829
+ return compareVersions(withoutRc, "5.71.5");
830
+ };
821
831
  const getPackageByQueryClient = (packageJson, queryClient) => {
822
832
  switch (queryClient) {
823
833
  case "react-query": return packageJson?.dependencies?.["@tanstack/react-query"] ?? packageJson?.devDependencies?.["@tanstack/react-query"] ?? packageJson?.peerDependencies?.["@tanstack/react-query"];
@@ -837,21 +847,20 @@ const QueryType = {
837
847
  SUSPENSE_INFINITE: "suspenseInfiniteQuery"
838
848
  };
839
849
  const INFINITE_QUERY_PROPERTIES = new Set(["getNextPageParam", "getPreviousPageParam"]);
840
- const generateQueryOptions = ({ params, options, type, outputClient }) => {
850
+ const generateQueryOptions = ({ params, options, type, adapter }) => {
841
851
  if (options === false) return "";
842
852
  const queryConfig = isObject(options) ? ` ${stringify(omitBy(options, (_, key) => type !== QueryType.INFINITE && type !== QueryType.SUSPENSE_INFINITE && INFINITE_QUERY_PROPERTIES.has(key)))?.slice(1, -1)}` : "";
843
853
  if (params.length === 0 || isSuspenseQuery(type)) {
844
854
  if (options) return `${queryConfig} ...queryOptions`;
845
855
  return "...queryOptions";
846
856
  }
847
- return `${!isObject(options) || !Object.hasOwn(options, "enabled") ? isVue(outputClient) ? `enabled: computed(() => !!(${params.map(({ name }) => `unref(${name})`).join(" && ")})),` : `enabled: !!(${params.map(({ name }) => name).join(" && ")}),` : ""}${queryConfig} ...queryOptions`;
857
+ return `${adapter ? adapter.generateEnabledOption(params, options) : !isObject(options) || !Object.hasOwn(options, "enabled") ? `enabled: !!(${params.map(({ name }) => name).join(" && ")}),` : ""}${queryConfig} ...queryOptions`;
848
858
  };
849
859
  const isSuspenseQuery = (type) => {
850
860
  return [QueryType.SUSPENSE_INFINITE, QueryType.SUSPENSE_QUERY].includes(type);
851
861
  };
852
- const getQueryOptionsDefinition = ({ operationName, mutator, definitions, type, hasSvelteQueryV4, hasQueryV5, hasQueryV5WithInfiniteQueryOptionsError, queryParams, queryParam, isReturnType, initialData, isAngularClient }) => {
862
+ const getQueryOptionsDefinition = ({ operationName, mutator, definitions, type, prefix, hasQueryV5, hasQueryV5WithInfiniteQueryOptionsError, queryParams, queryParam, isReturnType, initialData }) => {
853
863
  const isMutatorHook = mutator?.isHook;
854
- const prefix = !hasSvelteQueryV4 && !isAngularClient ? "Use" : "Create";
855
864
  const partialOptions = !isReturnType && hasQueryV5;
856
865
  if (type) {
857
866
  const funcReturnType = `Awaited<ReturnType<${isMutatorHook ? `ReturnType<typeof use${pascal(operationName)}Hook>` : `typeof ${operationName}`}>>`;
@@ -867,109 +876,562 @@ const getQueryOptionsDefinition = ({ operationName, mutator, definitions, type,
867
876
  }
868
877
  return `${prefix}MutationOptions<Awaited<ReturnType<${isMutatorHook ? `ReturnType<typeof use${pascal(operationName)}Hook>` : `typeof ${operationName}`}>>, TError,${definitions ? `{${definitions}}` : "void"}, TContext>`;
869
878
  };
870
- const generateQueryArguments = ({ operationName, definitions, mutator, isRequestOptions, type, hasSvelteQueryV4, hasSvelteQueryV6, hasQueryV5, hasQueryV5WithInfiniteQueryOptionsError, queryParams, queryParam, initialData, httpClient, isAngularClient, forQueryOptions = false, forAngularInject = false }) => {
871
- const definition = getQueryOptionsDefinition({
872
- operationName,
873
- mutator,
874
- definitions,
875
- type,
876
- hasSvelteQueryV4,
877
- hasQueryV5,
878
- hasQueryV5WithInfiniteQueryOptionsError,
879
- queryParams,
880
- queryParam,
881
- isReturnType: false,
882
- initialData,
883
- isAngularClient
884
- });
885
- if (!isRequestOptions) return `${type ? "queryOptions" : "mutationOptions"}${initialData === "defined" ? "" : "?"}: ${definition}`;
886
- const requestType = getQueryArgumentsRequestType(httpClient, mutator);
887
- const isQueryRequired = initialData === "defined";
888
- const optionsType = `{ ${type ? "query" : "mutation"}${isQueryRequired ? "" : "?"}:${definition}, ${requestType}}`;
889
- if (forAngularInject) return `options${isQueryRequired ? "" : "?"}: ${optionsType} | (() => ${optionsType})\n`;
890
- return `options${isQueryRequired ? "" : "?"}: ${hasSvelteQueryV6 && !forQueryOptions ? "() => " : ""}${optionsType}\n`;
891
- };
892
879
 
893
880
  //#endregion
894
- //#region src/return-types.ts
895
- const generateQueryReturnType = ({ outputClient, type, isMutatorHook, operationName, hasVueQueryV4, hasSvelteQueryV4, hasQueryV5, hasQueryV5WithDataTagError, isInitialDataDefined }) => {
896
- switch (outputClient) {
897
- case OutputClient.ANGULAR_QUERY:
881
+ //#region src/frameworks/angular.ts
882
+ const createAngularAdapter = ({ hasQueryV5, hasQueryV5WithDataTagError, hasQueryV5WithInfiniteQueryOptionsError }) => {
883
+ const prefix = "Create";
884
+ return {
885
+ outputClient: OutputClient.ANGULAR_QUERY,
886
+ hookPrefix: "inject",
887
+ isAngularHttp: true,
888
+ hasQueryV5,
889
+ hasQueryV5WithDataTagError,
890
+ hasQueryV5WithInfiniteQueryOptionsError,
891
+ getHookPropsDefinitions(props) {
892
+ return toObjectString(props.map((prop) => {
893
+ const getterType = prop.definition.replace(/^(\w+)(\??): (.+)$/, (_match, name, optional, type) => `${name}${optional}: ${type} | (() => ${type.replace(" | undefined", "")}${optional ? " | undefined" : ""})`);
894
+ return {
895
+ ...prop,
896
+ definition: getterType
897
+ };
898
+ }), "definition");
899
+ },
900
+ getHttpFunctionQueryProps(queryProperties, _httpClient, hasMutator) {
901
+ if (!hasMutator) return queryProperties ? `http, ${queryProperties}` : "http";
902
+ return queryProperties;
903
+ },
904
+ getInfiniteQueryHttpProps(props, queryParam, hasMutator) {
905
+ let result = props.map((param) => {
906
+ if (param.type === GetterPropType.NAMED_PATH_PARAMS) return param.destructured;
907
+ return param.name === "params" ? `{...params, '${queryParam}': pageParam || params?.['${queryParam}']}` : param.name;
908
+ }).join(",");
909
+ if (!hasMutator) result = result ? `http, ${result}` : "http";
910
+ return result;
911
+ },
912
+ getHttpFirstParam(mutator) {
913
+ if (!mutator || mutator.hasSecondArg) return "http: HttpClient, ";
914
+ return "";
915
+ },
916
+ getMutationHttpPrefix(mutator) {
917
+ if (!mutator) return "http, ";
918
+ return "";
919
+ },
920
+ getQueryReturnType({ type }) {
898
921
  if (type !== QueryType.INFINITE && type !== QueryType.SUSPENSE_INFINITE) return `CreateQueryResult<TData, TError>`;
899
922
  return `CreateInfiniteQueryResult<TData, TError>`;
900
- case OutputClient.SOLID_QUERY:
901
- if (type !== QueryType.INFINITE && type !== QueryType.SUSPENSE_INFINITE) return `CreateQueryResult<TData, TError> & { queryKey: ${hasQueryV5 ? `DataTag<QueryKey, TData${hasQueryV5WithDataTagError ? ", TError" : ""}>` : "QueryKey"} }`;
902
- return `CreateInfiniteQueryResult<TData, TError> & { queryKey: ${hasQueryV5 ? `DataTag<QueryKey, TData${hasQueryV5WithDataTagError ? ", TError" : ""}>` : "QueryKey"} }`;
903
- case OutputClient.SVELTE_QUERY:
904
- if (!hasSvelteQueryV4) return `Use${pascal(type)}StoreResult<Awaited<ReturnType<${isMutatorHook ? `ReturnType<typeof use${pascal(operationName)}Hook>` : `typeof ${operationName}`}>>, TError, TData, QueryKey> & { queryKey: QueryKey} }`;
905
- return `Create${pascal(type)}Result<TData, TError> & { queryKey: ${hasQueryV5 ? `DataTag<QueryKey, TData${hasQueryV5WithDataTagError ? ", TError" : ""}>` : "QueryKey"} }`;
906
- case OutputClient.VUE_QUERY:
907
- if (!hasVueQueryV4) return ` UseQueryReturnType<TData, TError, Use${pascal(type)}Result<TData, TError>> & { queryKey: QueryKey} }`;
908
- if (type !== QueryType.INFINITE && type !== QueryType.SUSPENSE_INFINITE) return `UseQueryReturnType<TData, TError> & { queryKey: ${hasQueryV5 ? `DataTag<QueryKey, TData${hasQueryV5WithDataTagError ? ", TError" : ""}>` : "QueryKey"} }`;
909
- return `UseInfiniteQueryReturnType<TData, TError> & { queryKey: ${hasQueryV5 ? `DataTag<QueryKey, TData${hasQueryV5WithDataTagError ? ", TError" : ""}>` : "QueryKey"} }`;
910
- default: return ` ${isInitialDataDefined && !isSuspenseQuery(type) ? "Defined" : ""}Use${pascal(type)}Result<TData, TError> & { queryKey: ${hasQueryV5 ? `DataTag<QueryKey, TData${hasQueryV5WithDataTagError ? ", TError" : ""}>` : "QueryKey"} }`;
911
- }
912
- };
913
- const generateMutatorReturnType = ({ outputClient, dataType, variableType }) => {
914
- if (outputClient === OutputClient.ANGULAR_QUERY) return `: CreateMutationResult<
923
+ },
924
+ getMutationReturnType({ dataType, variableType }) {
925
+ return `: CreateMutationResult<
915
926
  Awaited<ReturnType<${dataType}>>,
916
927
  TError,
917
928
  ${variableType},
918
929
  TContext
919
930
  >`;
920
- if (outputClient === OutputClient.REACT_QUERY) return `: UseMutationResult<
931
+ },
932
+ getQueryReturnStatement({ queryResultVarName }) {
933
+ return `return ${queryResultVarName};`;
934
+ },
935
+ shouldAnnotateQueryKey() {
936
+ return false;
937
+ },
938
+ generateQueryInit({ mutator }) {
939
+ if (!mutator || mutator.hasSecondArg) return `const http = inject(HttpClient);`;
940
+ return "";
941
+ },
942
+ generateQueryInvocationArgs({ props, queryOptionsFnName, isRequestOptions, mutator }) {
943
+ return `() => {${props.length > 0 ? `
944
+ // Resolve params if getter function (for signal reactivity)
945
+ ${props.map((p) => `const _${p.name} = typeof ${p.name} === 'function' ? ${p.name}() : ${p.name};`).join("\n ")}` : ""}
946
+ // Resolve options if getter function (for signal reactivity)
947
+ const _options = typeof ${isRequestOptions ? "options" : "queryOptions"} === 'function' ? ${isRequestOptions ? "options" : "queryOptions"}() : ${isRequestOptions ? "options" : "queryOptions"};
948
+ return ${queryOptionsFnName}(${!mutator || mutator.hasSecondArg ? "http" : ""}${props.length > 0 ? `${!mutator || mutator.hasSecondArg ? ", " : ""}${props.map((p) => `_${p.name}`).join(", ")}` : ""}, _options);
949
+ }`;
950
+ },
951
+ getOptionalQueryClientArgument() {
952
+ return "";
953
+ },
954
+ getQueryOptionsDefinitionPrefix() {
955
+ return prefix;
956
+ },
957
+ generateQueryArguments({ operationName, definitions, mutator, isRequestOptions, type, queryParams, queryParam, initialData, httpClient, forQueryOptions = false, hasInvalidation }) {
958
+ const definition = getQueryOptionsDefinition({
959
+ operationName,
960
+ mutator,
961
+ definitions,
962
+ type,
963
+ prefix,
964
+ hasQueryV5,
965
+ hasQueryV5WithInfiniteQueryOptionsError,
966
+ queryParams,
967
+ queryParam,
968
+ isReturnType: false,
969
+ initialData
970
+ });
971
+ if (!isRequestOptions) return `${type ? "queryOptions" : "mutationOptions"}${initialData === "defined" ? "" : "?"}: ${definition}`;
972
+ const requestType = getQueryArgumentsRequestType(httpClient, mutator);
973
+ const isQueryRequired = initialData === "defined";
974
+ const optionsType = `{ ${type ? "query" : "mutation"}${isQueryRequired ? "" : "?"}:${definition}, ${!type && hasInvalidation ? "skipInvalidation?: boolean, " : ""}${requestType}}`;
975
+ if (type !== void 0 && !forQueryOptions) return `options${isQueryRequired ? "" : "?"}: ${optionsType} | (() => ${optionsType})\n`;
976
+ return `options${isQueryRequired ? "" : "?"}: ${optionsType}\n`;
977
+ },
978
+ generateMutationImplementation({ mutationOptionsFnName, hasInvalidation, isRequestOptions }) {
979
+ return `${mutationOptionsFnName}(${hasInvalidation ? `queryClient, ` : ""}${isRequestOptions ? "options" : "mutationOptions"})`;
980
+ },
981
+ supportsMutationInvalidation() {
982
+ return true;
983
+ },
984
+ generateMutationOnSuccess({ operationName, definitions, isRequestOptions, generateInvalidateCall: generateInvalidateCall$1, uniqueInvalidates }) {
985
+ const invalidateCalls = uniqueInvalidates.map((t) => generateInvalidateCall$1(t)).join("\n");
986
+ if (isRequestOptions) return ` const onSuccess = (data: Awaited<ReturnType<typeof ${operationName}>>, variables: ${definitions ? `{${definitions}}` : "void"}, onMutateResult: TContext, context: MutationFunctionContext) => {
987
+ if (!options?.skipInvalidation) {
988
+ ${invalidateCalls}
989
+ }
990
+ mutationOptions?.onSuccess?.(data, variables, onMutateResult, context);
991
+ };`;
992
+ return ` const onSuccess = (data: Awaited<ReturnType<typeof ${operationName}>>, variables: ${definitions ? `{${definitions}}` : "void"}, onMutateResult: TContext, context: MutationFunctionContext) => {
993
+ ${invalidateCalls}
994
+ mutationOptions?.onSuccess?.(data, variables, onMutateResult, context);
995
+ };`;
996
+ },
997
+ generateMutationHookBody({ operationPrefix, mutationOptionsFnName, mutationOptionsVarName, isRequestOptions, mutator, hasInvalidation }) {
998
+ if (!mutator || mutator.hasSecondArg) return ` const http = inject(HttpClient);${hasInvalidation ? "\n const queryClient = inject(QueryClient);" : ""}
999
+ const ${mutationOptionsVarName} = ${mutationOptionsFnName}(http${hasInvalidation ? ", queryClient" : ""}${isRequestOptions ? ", options" : ", mutationOptions"});
1000
+
1001
+ return ${operationPrefix}Mutation(() => ${mutationOptionsVarName});`;
1002
+ return ` const ${mutationOptionsVarName} = ${`${mutationOptionsFnName}(${hasInvalidation ? `queryClient, ` : ""}${isRequestOptions ? "options" : "mutationOptions"})`};
1003
+
1004
+ return ${operationPrefix}Mutation(() => ${mutationOptionsVarName});`;
1005
+ },
1006
+ getQueryType(type) {
1007
+ return getQueryTypeForFramework(type);
1008
+ },
1009
+ generateRequestFunction(verbOptions, options) {
1010
+ return generateAngularHttpRequestFunction(verbOptions, options);
1011
+ }
1012
+ };
1013
+ };
1014
+
1015
+ //#endregion
1016
+ //#region src/frameworks/react.ts
1017
+ const createReactAdapter = ({ hasQueryV5, hasQueryV5WithDataTagError, hasQueryV5WithInfiniteQueryOptionsError }) => ({
1018
+ outputClient: OutputClient.REACT_QUERY,
1019
+ hookPrefix: "use",
1020
+ hasQueryV5,
1021
+ hasQueryV5WithDataTagError,
1022
+ hasQueryV5WithInfiniteQueryOptionsError,
1023
+ getQueryReturnType({ type, isInitialDataDefined }) {
1024
+ return ` ${isInitialDataDefined && !isSuspenseQuery(type) ? "Defined" : ""}Use${pascal(type)}Result<TData, TError> & { queryKey: ${hasQueryV5 ? `DataTag<QueryKey, TData${hasQueryV5WithDataTagError ? ", TError" : ""}>` : "QueryKey"} }`;
1025
+ },
1026
+ getMutationReturnType({ dataType, variableType }) {
1027
+ return `: UseMutationResult<
921
1028
  Awaited<ReturnType<${dataType}>>,
922
1029
  TError,
923
1030
  ${variableType},
924
1031
  TContext
925
1032
  >`;
926
- if (outputClient === OutputClient.SOLID_QUERY) return `: CreateMutationResult<
1033
+ },
1034
+ getQueryReturnStatement({ queryResultVarName, queryOptionsVarName }) {
1035
+ return `return { ...${queryResultVarName}, queryKey: ${queryOptionsVarName}.queryKey };`;
1036
+ },
1037
+ shouldGenerateOverrideTypes() {
1038
+ return hasQueryV5;
1039
+ },
1040
+ generateMutationImplementation({ mutationOptionsFnName, hasInvalidation, isRequestOptions }) {
1041
+ return `${mutationOptionsFnName}(${hasInvalidation ? `queryClient ?? backupQueryClient, ` : ""}${isRequestOptions ? "options" : "mutationOptions"})`;
1042
+ },
1043
+ supportsMutationInvalidation() {
1044
+ return true;
1045
+ },
1046
+ generateMutationOnSuccess({ operationName, definitions, isRequestOptions, generateInvalidateCall: generateInvalidateCall$1, uniqueInvalidates }) {
1047
+ const invalidateCalls = uniqueInvalidates.map((t) => generateInvalidateCall$1(t)).join("\n");
1048
+ if (isRequestOptions) return ` const onSuccess = (data: Awaited<ReturnType<typeof ${operationName}>>, variables: ${definitions ? `{${definitions}}` : "void"}, context: TContext) => {
1049
+ if (!options?.skipInvalidation) {
1050
+ ${invalidateCalls}
1051
+ }
1052
+ mutationOptions?.onSuccess?.(data, variables, context);
1053
+ };`;
1054
+ return ` const onSuccess = (data: Awaited<ReturnType<typeof ${operationName}>>, variables: ${definitions ? `{${definitions}}` : "void"}, context: TContext) => {
1055
+ ${invalidateCalls}
1056
+ mutationOptions?.onSuccess?.(data, variables, context);
1057
+ };`;
1058
+ },
1059
+ generateMutationHookBody({ operationPrefix, mutationImplementation, hasInvalidation, optionalQueryClientArgument }) {
1060
+ return ` ${hasInvalidation ? `const backupQueryClient = useQueryClient();\n ` : ""}return ${operationPrefix}Mutation(${mutationImplementation}${optionalQueryClientArgument ? `, queryClient` : ""});`;
1061
+ },
1062
+ generateRequestFunction(verbOptions, options) {
1063
+ return options.context.output.httpClient === OutputHttpClient.AXIOS ? generateAxiosRequestFunction(verbOptions, options, false) : generateRequestFunction(verbOptions, options);
1064
+ }
1065
+ });
1066
+
1067
+ //#endregion
1068
+ //#region src/frameworks/solid.ts
1069
+ const createSolidAdapter = ({ hasQueryV5, hasQueryV5WithDataTagError, hasQueryV5WithInfiniteQueryOptionsError, hasSolidQueryUsePrefix }) => ({
1070
+ outputClient: OutputClient.SOLID_QUERY,
1071
+ hookPrefix: hasSolidQueryUsePrefix ? "use" : "create",
1072
+ hasQueryV5,
1073
+ hasQueryV5WithDataTagError,
1074
+ hasQueryV5WithInfiniteQueryOptionsError,
1075
+ getQueryOptionsDefinitionPrefix() {
1076
+ return hasSolidQueryUsePrefix ? "Use" : "Create";
1077
+ },
1078
+ getQueryReturnType({ type }) {
1079
+ const prefix = hasSolidQueryUsePrefix ? "Use" : "Create";
1080
+ const queryKeyType = hasQueryV5 ? `DataTag<QueryKey, TData${hasQueryV5WithDataTagError ? ", TError" : ""}>` : "QueryKey";
1081
+ if (type !== QueryType.INFINITE && type !== QueryType.SUSPENSE_INFINITE) return `${prefix}QueryResult<TData, TError> & { queryKey: ${queryKeyType} }`;
1082
+ return `${prefix}InfiniteQueryResult<TData, TError> & { queryKey: ${queryKeyType} }`;
1083
+ },
1084
+ getMutationReturnType({ dataType, variableType }) {
1085
+ return `: ${hasSolidQueryUsePrefix ? "Use" : "Create"}MutationResult<
927
1086
  Awaited<ReturnType<${dataType}>>,
928
1087
  TError,
929
1088
  ${variableType},
930
1089
  TContext
931
1090
  >`;
932
- if (outputClient === OutputClient.SVELTE_QUERY) return `: CreateMutationResult<
1091
+ },
1092
+ getQueryReturnStatement({ queryResultVarName, queryOptionsVarName }) {
1093
+ return `return { ...${queryResultVarName}, queryKey: ${queryOptionsVarName}.queryKey };`;
1094
+ },
1095
+ generateMutationImplementation({ mutationOptionsFnName, isRequestOptions }) {
1096
+ return `${mutationOptionsFnName}(${isRequestOptions ? "options" : "mutationOptions"})`;
1097
+ },
1098
+ supportsMutationInvalidation() {
1099
+ return false;
1100
+ },
1101
+ generateMutationOnSuccess() {
1102
+ return "";
1103
+ },
1104
+ generateMutationHookBody({ operationPrefix, mutationImplementation, optionalQueryClientArgument }) {
1105
+ return ` return ${operationPrefix}Mutation(${mutationImplementation}${optionalQueryClientArgument ? `, queryClient` : ""});`;
1106
+ },
1107
+ generateRequestFunction(verbOptions, options) {
1108
+ return options.context.output.httpClient === OutputHttpClient.AXIOS ? generateAxiosRequestFunction(verbOptions, options, false) : generateRequestFunction(verbOptions, options);
1109
+ }
1110
+ });
1111
+
1112
+ //#endregion
1113
+ //#region src/frameworks/svelte.ts
1114
+ const createSvelteAdapter = ({ hasSvelteQueryV4, hasSvelteQueryV6, hasQueryV5, hasQueryV5WithDataTagError, hasQueryV5WithInfiniteQueryOptionsError }) => {
1115
+ const prefix = hasSvelteQueryV4 ? "Create" : "Use";
1116
+ return {
1117
+ outputClient: OutputClient.SVELTE_QUERY,
1118
+ hookPrefix: hasSvelteQueryV4 ? "create" : "use",
1119
+ hasQueryV5,
1120
+ hasQueryV5WithDataTagError,
1121
+ hasQueryV5WithInfiniteQueryOptionsError,
1122
+ getHookPropsDefinitions(props) {
1123
+ if (hasSvelteQueryV6) return toObjectString(props.map((p) => ({
1124
+ ...p,
1125
+ definition: p.definition.replace(":", ": () => ")
1126
+ })), "definition");
1127
+ return toObjectString(props, "implementation");
1128
+ },
1129
+ getQueryReturnType({ type, isMutatorHook, operationName }) {
1130
+ if (!hasSvelteQueryV4) return `Use${pascal(type)}StoreResult<Awaited<ReturnType<${isMutatorHook ? `ReturnType<typeof use${pascal(operationName)}Hook>` : `typeof ${operationName}`}>>, TError, TData, QueryKey> & { queryKey: QueryKey }`;
1131
+ return `Create${pascal(type)}Result<TData, TError> & { queryKey: ${hasQueryV5 ? `DataTag<QueryKey, TData${hasQueryV5WithDataTagError ? ", TError" : ""}>` : "QueryKey"} }`;
1132
+ },
1133
+ getMutationReturnType({ dataType, variableType }) {
1134
+ return `: CreateMutationResult<
933
1135
  Awaited<ReturnType<${dataType}>>,
934
1136
  TError,
935
1137
  ${variableType},
936
1138
  TContext
937
1139
  >`;
938
- if (outputClient === OutputClient.VUE_QUERY) return `: UseMutationReturnType<
1140
+ },
1141
+ getQueryReturnStatement({ queryResultVarName, queryOptionsVarName }) {
1142
+ if (hasSvelteQueryV6) return `return ${queryResultVarName}`;
1143
+ if (hasSvelteQueryV4) return `${queryResultVarName}.queryKey = ${queryOptionsVarName}.queryKey;
1144
+
1145
+ return ${queryResultVarName};`;
1146
+ return `return { ...${queryResultVarName}, queryKey: ${queryOptionsVarName}.queryKey };`;
1147
+ },
1148
+ generateQueryInit({ queryOptionsFnName, queryProperties, isRequestOptions }) {
1149
+ if (hasSvelteQueryV6) return "";
1150
+ return `const ${isRequestOptions ? "queryOptions" : "options"} = ${queryOptionsFnName}(${queryProperties}${queryProperties ? "," : ""}${isRequestOptions ? "options" : "queryOptions"})`;
1151
+ },
1152
+ generateQueryInvocationArgs({ props, queryOptionsFnName, isRequestOptions, queryOptionsVarName, optionalQueryClientArgument }) {
1153
+ if (hasSvelteQueryV6) return `() => ${queryOptionsFnName}(${toObjectString(props.map((p) => ({
1154
+ ...p,
1155
+ name: p.default || !p.required ? `${p.name}?.()` : `${p.name}()`
1156
+ })), "name")}${isRequestOptions ? "options?.()" : "queryOptions?.()"})`;
1157
+ return `${queryOptionsVarName}${optionalQueryClientArgument ? ", queryClient" : ""}`;
1158
+ },
1159
+ getQueryInvocationSuffix() {
1160
+ return hasSvelteQueryV6 ? `, queryClient` : "";
1161
+ },
1162
+ getOptionalQueryClientArgument(hasInvalidation) {
1163
+ if (hasSvelteQueryV6) return `, queryClient?: () => QueryClient`;
1164
+ if (hasQueryV5 || hasInvalidation) return ", queryClient?: QueryClient";
1165
+ return "";
1166
+ },
1167
+ getQueryOptionsDefinitionPrefix() {
1168
+ return prefix;
1169
+ },
1170
+ generateQueryArguments({ operationName, definitions, mutator, isRequestOptions, type, queryParams, queryParam, initialData, httpClient, forQueryOptions = false, hasInvalidation }) {
1171
+ const definition = getQueryOptionsDefinition({
1172
+ operationName,
1173
+ mutator,
1174
+ definitions,
1175
+ type,
1176
+ prefix,
1177
+ hasQueryV5,
1178
+ hasQueryV5WithInfiniteQueryOptionsError,
1179
+ queryParams,
1180
+ queryParam,
1181
+ isReturnType: false,
1182
+ initialData
1183
+ });
1184
+ if (!isRequestOptions) return `${type ? "queryOptions" : "mutationOptions"}${initialData === "defined" ? "" : "?"}: ${definition}`;
1185
+ const requestType = getQueryArgumentsRequestType(httpClient, mutator);
1186
+ const isQueryRequired = initialData === "defined";
1187
+ const optionsType = `{ ${type ? "query" : "mutation"}${isQueryRequired ? "" : "?"}:${definition}, ${!type && hasInvalidation ? "skipInvalidation?: boolean, " : ""}${requestType}}`;
1188
+ return `options${isQueryRequired ? "" : "?"}: ${hasSvelteQueryV6 && !forQueryOptions ? "() => " : ""}${optionsType}\n`;
1189
+ },
1190
+ generateMutationImplementation({ mutationOptionsFnName, hasInvalidation, isRequestOptions }) {
1191
+ if (hasSvelteQueryV6) return `${mutationOptionsFnName}(${hasInvalidation ? `backupQueryClient, ` : ""}${isRequestOptions ? "options" : "mutationOptions"}?.())`;
1192
+ return `${mutationOptionsFnName}(${hasInvalidation ? `queryClient ?? backupQueryClient, ` : ""}${isRequestOptions ? "options" : "mutationOptions"})`;
1193
+ },
1194
+ supportsMutationInvalidation() {
1195
+ return true;
1196
+ },
1197
+ generateMutationOnSuccess({ operationName, definitions, isRequestOptions, generateInvalidateCall: generateInvalidateCall$1, uniqueInvalidates }) {
1198
+ const invalidateCalls = uniqueInvalidates.map((t) => generateInvalidateCall$1(t)).join("\n");
1199
+ if (hasSvelteQueryV6) {
1200
+ if (isRequestOptions) return ` const onSuccess = (data: Awaited<ReturnType<typeof ${operationName}>>, variables: ${definitions ? `{${definitions}}` : "void"}, onMutateResult: TContext, context: MutationFunctionContext) => {
1201
+ if (!options?.skipInvalidation) {
1202
+ ${invalidateCalls}
1203
+ }
1204
+ mutationOptions?.onSuccess?.(data, variables, onMutateResult, context);
1205
+ };`;
1206
+ return ` const onSuccess = (data: Awaited<ReturnType<typeof ${operationName}>>, variables: ${definitions ? `{${definitions}}` : "void"}, onMutateResult: TContext, context: MutationFunctionContext) => {
1207
+ ${invalidateCalls}
1208
+ mutationOptions?.onSuccess?.(data, variables, onMutateResult, context);
1209
+ };`;
1210
+ }
1211
+ if (isRequestOptions) return ` const onSuccess = (data: Awaited<ReturnType<typeof ${operationName}>>, variables: ${definitions ? `{${definitions}}` : "void"}, context: TContext | undefined) => {
1212
+ if (!options?.skipInvalidation) {
1213
+ ${invalidateCalls}
1214
+ }
1215
+ mutationOptions?.onSuccess?.(data, variables, context);
1216
+ };`;
1217
+ return ` const onSuccess = (data: Awaited<ReturnType<typeof ${operationName}>>, variables: ${definitions ? `{${definitions}}` : "void"}, context: TContext | undefined) => {
1218
+ ${invalidateCalls}
1219
+ mutationOptions?.onSuccess?.(data, variables, context);
1220
+ };`;
1221
+ },
1222
+ generateMutationHookBody({ operationPrefix, mutationImplementation, hasInvalidation, optionalQueryClientArgument }) {
1223
+ if (hasSvelteQueryV6) return ` ${hasInvalidation ? `const backupQueryClient = useQueryClient(${optionalQueryClientArgument ? "queryClient?.()" : ""});\n ` : ""}return ${operationPrefix}Mutation(() => ({ ...${mutationImplementation} })${optionalQueryClientArgument ? `, queryClient` : ""});`;
1224
+ return ` ${hasInvalidation ? `const backupQueryClient = useQueryClient();\n ` : ""}return ${operationPrefix}Mutation(${mutationImplementation});`;
1225
+ },
1226
+ getQueryType(type) {
1227
+ if (hasSvelteQueryV4) return getQueryTypeForFramework(type);
1228
+ return type;
1229
+ },
1230
+ generateRequestFunction(verbOptions, options) {
1231
+ return options.context.output.httpClient === OutputHttpClient.AXIOS ? generateAxiosRequestFunction(verbOptions, options, false) : generateRequestFunction(verbOptions, options);
1232
+ }
1233
+ };
1234
+ };
1235
+
1236
+ //#endregion
1237
+ //#region src/frameworks/vue.ts
1238
+ const createVueAdapter = ({ hasVueQueryV4, hasQueryV5, hasQueryV5WithDataTagError, hasQueryV5WithInfiniteQueryOptionsError }) => ({
1239
+ outputClient: OutputClient.VUE_QUERY,
1240
+ hookPrefix: "use",
1241
+ hasQueryV5,
1242
+ hasQueryV5WithDataTagError,
1243
+ hasQueryV5WithInfiniteQueryOptionsError,
1244
+ transformProps(props) {
1245
+ return vueWrapTypeWithMaybeRef(props);
1246
+ },
1247
+ shouldDestructureNamedPathParams() {
1248
+ return false;
1249
+ },
1250
+ getHttpFunctionQueryProps(queryProperties, httpClient) {
1251
+ if (httpClient === OutputHttpClient.FETCH && queryProperties) return queryProperties.split(",").map((prop) => `unref(${prop})`).join(",");
1252
+ return queryProperties;
1253
+ },
1254
+ getInfiniteQueryHttpProps(props, queryParam) {
1255
+ return props.map((param) => {
1256
+ return param.name === "params" ? `{...unref(params), '${queryParam}': pageParam || unref(params)?.['${queryParam}']}` : param.name;
1257
+ }).join(",");
1258
+ },
1259
+ getQueryReturnType({ type }) {
1260
+ if (!hasVueQueryV4) return ` UseQueryReturnType<TData, TError, Use${pascal(type)}Result<TData, TError>> & { queryKey: QueryKey }`;
1261
+ if (type !== QueryType.INFINITE && type !== QueryType.SUSPENSE_INFINITE) return `UseQueryReturnType<TData, TError> & { queryKey: ${hasQueryV5 ? `DataTag<QueryKey, TData${hasQueryV5WithDataTagError ? ", TError" : ""}>` : "QueryKey"} }`;
1262
+ return `UseInfiniteQueryReturnType<TData, TError> & { queryKey: ${hasQueryV5 ? `DataTag<QueryKey, TData${hasQueryV5WithDataTagError ? ", TError" : ""}>` : "QueryKey"} }`;
1263
+ },
1264
+ getMutationReturnType({ dataType, variableType }) {
1265
+ return `: UseMutationReturnType<
939
1266
  Awaited<ReturnType<${dataType}>>,
940
1267
  TError,
941
1268
  ${variableType},
942
1269
  TContext
943
1270
  >`;
944
- return "";
945
- };
946
- const getQueryFnArguments = ({ hasQueryParam, hasSignal, hasSignalParam = false }) => {
947
- if (!hasQueryParam && !hasSignal) return "";
948
- const signalDestructure = hasSignalParam ? "signal: querySignal" : "signal";
949
- if (hasQueryParam) {
950
- if (hasSignal) return `{ ${signalDestructure}, pageParam }`;
951
- return "{ pageParam }";
952
- }
953
- return `{ ${signalDestructure} }`;
954
- };
955
- const getQueryReturnStatement = ({ outputClient, hasSvelteQueryV4, hasSvelteQueryV6, hasQueryV5, hasQueryV5WithDataTagError, queryResultVarName, queryOptionsVarName }) => {
956
- if (isAngular(outputClient)) return `return ${queryResultVarName};`;
957
- if (isVue(outputClient)) return `${queryResultVarName}.queryKey = unref(${queryOptionsVarName}).queryKey as ${hasQueryV5 ? `DataTag<QueryKey, TData${hasQueryV5WithDataTagError ? ", TError" : ""}>` : "QueryKey"};
1271
+ },
1272
+ getQueryReturnStatement({ queryResultVarName, queryOptionsVarName }) {
1273
+ return `${queryResultVarName}.queryKey = unref(${queryOptionsVarName}).queryKey as ${hasQueryV5 ? `DataTag<QueryKey, TData${hasQueryV5WithDataTagError ? ", TError" : ""}>` : "QueryKey"};
958
1274
 
959
1275
  return ${queryResultVarName};`;
960
- if (hasSvelteQueryV6) return `return ${queryResultVarName}`;
961
- if (hasSvelteQueryV4) return `${queryResultVarName}.queryKey = ${queryOptionsVarName}.queryKey;
1276
+ },
1277
+ getQueryKeyRouteString(route) {
1278
+ return getRouteAsArray(route);
1279
+ },
1280
+ shouldAnnotateQueryKey() {
1281
+ return false;
1282
+ },
1283
+ getUnrefStatements(props) {
1284
+ return vueUnRefParams(props.filter((prop) => prop.type === GetterPropType.NAMED_PATH_PARAMS));
1285
+ },
1286
+ generateEnabledOption(params, options) {
1287
+ if (!isObject(options) || !Object.hasOwn(options, "enabled")) return `enabled: computed(() => !!(${params.map(({ name }) => `unref(${name})`).join(" && ")})),`;
1288
+ return "";
1289
+ },
1290
+ getQueryKeyPrefix() {
1291
+ return hasVueQueryV4 ? "" : "queryOptions?.queryKey ?? ";
1292
+ },
1293
+ generateMutationImplementation({ mutationOptionsFnName, isRequestOptions }) {
1294
+ return `${mutationOptionsFnName}(${isRequestOptions ? "options" : "mutationOptions"})`;
1295
+ },
1296
+ supportsMutationInvalidation() {
1297
+ return false;
1298
+ },
1299
+ generateMutationOnSuccess() {
1300
+ return "";
1301
+ },
1302
+ generateMutationHookBody({ operationPrefix, mutationImplementation, optionalQueryClientArgument }) {
1303
+ return ` return ${operationPrefix}Mutation(${mutationImplementation}${optionalQueryClientArgument ? `, queryClient` : ""});`;
1304
+ },
1305
+ generateRequestFunction(verbOptions, options) {
1306
+ return options.context.output.httpClient === OutputHttpClient.AXIOS ? generateAxiosRequestFunction(verbOptions, options, true) : generateRequestFunction(verbOptions, options);
1307
+ },
1308
+ getQueryPropertyForProp(prop, body) {
1309
+ return prop.type === GetterPropType.BODY ? body.implementation : prop.name;
1310
+ }
1311
+ });
962
1312
 
963
- return ${queryResultVarName};`;
964
- return `return { ...${queryResultVarName}, queryKey: ${queryOptionsVarName}.queryKey };`;
1313
+ //#endregion
1314
+ //#region src/frameworks/index.ts
1315
+ /** Fill in defaults for fields that most adapters leave empty or share a common implementation. */
1316
+ const withDefaults = (adapter) => ({
1317
+ isAngularHttp: false,
1318
+ getHttpFirstParam: () => "",
1319
+ getMutationHttpPrefix: () => "",
1320
+ getUnrefStatements: () => "",
1321
+ getQueryInvocationSuffix: () => "",
1322
+ transformProps: (props) => props,
1323
+ getHttpFunctionQueryProps: (qp) => qp,
1324
+ getQueryType: (type) => type,
1325
+ shouldDestructureNamedPathParams: () => true,
1326
+ shouldAnnotateQueryKey: () => true,
1327
+ shouldGenerateOverrideTypes: () => false,
1328
+ getQueryKeyPrefix: () => "queryOptions?.queryKey ?? ",
1329
+ getQueryOptionsDefinitionPrefix: () => "Use",
1330
+ getHookPropsDefinitions: (props) => toObjectString(props, "implementation"),
1331
+ getQueryKeyRouteString(route, shouldSplitQueryKey) {
1332
+ if (shouldSplitQueryKey) return getRouteAsArray(route);
1333
+ return `\`${route}\``;
1334
+ },
1335
+ generateEnabledOption(params, options) {
1336
+ if (!isObject(options) || !Object.hasOwn(options, "enabled")) return `enabled: !!(${params.map(({ name }) => name).join(" && ")}),`;
1337
+ return "";
1338
+ },
1339
+ getQueryPropertyForProp(prop, body) {
1340
+ if (prop.type === GetterPropType.NAMED_PATH_PARAMS) return prop.destructured;
1341
+ return prop.type === GetterPropType.BODY ? body.implementation : prop.name;
1342
+ },
1343
+ getInfiniteQueryHttpProps(props, queryParam) {
1344
+ return props.map((param) => {
1345
+ if (param.type === GetterPropType.NAMED_PATH_PARAMS) return param.destructured;
1346
+ return param.name === "params" ? `{...params, '${queryParam}': pageParam || params?.['${queryParam}']}` : param.name;
1347
+ }).join(",");
1348
+ },
1349
+ generateQueryInit({ queryOptionsFnName, queryProperties, isRequestOptions }) {
1350
+ return `const ${isRequestOptions ? "queryOptions" : "options"} = ${queryOptionsFnName}(${queryProperties}${queryProperties ? "," : ""}${isRequestOptions ? "options" : "queryOptions"})`;
1351
+ },
1352
+ generateQueryInvocationArgs({ queryOptionsVarName, optionalQueryClientArgument }) {
1353
+ return `${queryOptionsVarName}${optionalQueryClientArgument ? ", queryClient" : ""}`;
1354
+ },
1355
+ getOptionalQueryClientArgument() {
1356
+ return adapter.hasQueryV5 ? ", queryClient?: QueryClient" : "";
1357
+ },
1358
+ generateQueryArguments({ operationName, definitions, mutator, isRequestOptions, type, queryParams, queryParam, initialData, httpClient, hasInvalidation }) {
1359
+ const definition = getQueryOptionsDefinition({
1360
+ operationName,
1361
+ mutator,
1362
+ definitions,
1363
+ type,
1364
+ prefix: adapter.getQueryOptionsDefinitionPrefix?.() ?? "Use",
1365
+ hasQueryV5: adapter.hasQueryV5,
1366
+ hasQueryV5WithInfiniteQueryOptionsError: adapter.hasQueryV5WithInfiniteQueryOptionsError,
1367
+ queryParams,
1368
+ queryParam,
1369
+ isReturnType: false,
1370
+ initialData
1371
+ });
1372
+ if (!isRequestOptions) return `${type ? "queryOptions" : "mutationOptions"}${initialData === "defined" ? "" : "?"}: ${definition}`;
1373
+ const requestType = getQueryArgumentsRequestType(httpClient, mutator);
1374
+ const isQueryRequired = initialData === "defined";
1375
+ const optionsType = `{ ${type ? "query" : "mutation"}${isQueryRequired ? "" : "?"}:${definition}, ${!type && hasInvalidation ? "skipInvalidation?: boolean, " : ""}${requestType}}`;
1376
+ return `options${isQueryRequired ? "" : "?"}: ${optionsType}\n`;
1377
+ },
1378
+ ...adapter
1379
+ });
1380
+ /**
1381
+ * Create a FrameworkAdapter for the given output client, resolving version flags
1382
+ * from the packageJson and query config.
1383
+ */
1384
+ const createFrameworkAdapter = ({ outputClient, packageJson, queryVersion }) => {
1385
+ const clientType = outputClient;
1386
+ const _hasQueryV5 = queryVersion === 5 || isQueryV5(packageJson, clientType);
1387
+ const _hasQueryV5WithDataTagError = queryVersion === 5 || isQueryV5WithDataTagError(packageJson, clientType);
1388
+ const _hasQueryV5WithInfiniteQueryOptionsError = queryVersion === 5 || isQueryV5WithInfiniteQueryOptionsError(packageJson, clientType);
1389
+ switch (outputClient) {
1390
+ case OutputClient.VUE_QUERY: return withDefaults(createVueAdapter({
1391
+ hasVueQueryV4: !isVueQueryV3(packageJson) || queryVersion === 4,
1392
+ hasQueryV5: _hasQueryV5,
1393
+ hasQueryV5WithDataTagError: _hasQueryV5WithDataTagError,
1394
+ hasQueryV5WithInfiniteQueryOptionsError: _hasQueryV5WithInfiniteQueryOptionsError
1395
+ }));
1396
+ case OutputClient.SVELTE_QUERY: return withDefaults(createSvelteAdapter({
1397
+ hasSvelteQueryV4: !isSvelteQueryV3(packageJson) || queryVersion === 4,
1398
+ hasSvelteQueryV6: isSvelteQueryV6(packageJson),
1399
+ hasQueryV5: _hasQueryV5,
1400
+ hasQueryV5WithDataTagError: _hasQueryV5WithDataTagError,
1401
+ hasQueryV5WithInfiniteQueryOptionsError: _hasQueryV5WithInfiniteQueryOptionsError
1402
+ }));
1403
+ case OutputClient.ANGULAR_QUERY: return withDefaults(createAngularAdapter({
1404
+ hasQueryV5: _hasQueryV5,
1405
+ hasQueryV5WithDataTagError: _hasQueryV5WithDataTagError,
1406
+ hasQueryV5WithInfiniteQueryOptionsError: _hasQueryV5WithInfiniteQueryOptionsError
1407
+ }));
1408
+ case OutputClient.SOLID_QUERY: return withDefaults(createSolidAdapter({
1409
+ hasQueryV5: _hasQueryV5,
1410
+ hasQueryV5WithDataTagError: _hasQueryV5WithDataTagError,
1411
+ hasQueryV5WithInfiniteQueryOptionsError: _hasQueryV5WithInfiniteQueryOptionsError,
1412
+ hasSolidQueryUsePrefix: isSolidQueryWithUsePrefix(packageJson)
1413
+ }));
1414
+ default: return withDefaults(createReactAdapter({
1415
+ hasQueryV5: _hasQueryV5,
1416
+ hasQueryV5WithDataTagError: _hasQueryV5WithDataTagError,
1417
+ hasQueryV5WithInfiniteQueryOptionsError: _hasQueryV5WithInfiniteQueryOptionsError
1418
+ }));
1419
+ }
965
1420
  };
966
1421
 
967
1422
  //#endregion
968
1423
  //#region src/mutation-generator.ts
969
- const normalizeTarget = (target) => typeof target === "string" ? { query: target } : target;
1424
+ const normalizeTarget = (target) => isString(target) ? {
1425
+ query: target,
1426
+ invalidateMode: "invalidate"
1427
+ } : {
1428
+ ...target,
1429
+ invalidateMode: target.invalidateMode ?? "invalidate"
1430
+ };
970
1431
  const serializeTarget = (target) => JSON.stringify({
971
1432
  query: target.query,
972
- params: target.params ?? []
1433
+ params: target.params ?? [],
1434
+ invalidateMode: target.invalidateMode
973
1435
  });
974
1436
  const generateVariableRef = (varName) => {
975
1437
  const parts = varName.split(".");
@@ -981,9 +1443,11 @@ const generateParamArgs = (params) => {
981
1443
  return Object.values(params).map((v) => generateVariableRef(v)).join(", ");
982
1444
  };
983
1445
  const generateInvalidateCall = (target) => {
984
- return ` queryClient.invalidateQueries({ queryKey: ${camel(`get-${target.query}-query-key`)}(${target.params ? generateParamArgs(target.params) : ""}) });`;
1446
+ const queryKeyFn = camel(`get-${target.query}-query-key`);
1447
+ const args = target.params ? generateParamArgs(target.params) : "";
1448
+ return ` queryClient.${target.invalidateMode === "reset" ? "resetQueries" : "invalidateQueries"}({ queryKey: ${queryKeyFn}(${args}) });`;
985
1449
  };
986
- const generateMutationHook = async ({ verbOptions, options, outputClient, hasQueryV5, hasQueryV5WithInfiniteQueryOptionsError, hasSvelteQueryV4, hasSvelteQueryV6, isRequestOptions, httpClient, doc, isAngularHttp }) => {
1450
+ const generateMutationHook = async ({ verbOptions, options, isRequestOptions, httpClient, doc, adapter }) => {
987
1451
  const { operationName, body, props, mutator, response, operationId, override } = verbOptions;
988
1452
  const { route, context, output } = options;
989
1453
  const query = override.query;
@@ -998,55 +1462,45 @@ const generateMutationHook = async ({ verbOptions, options, outputClient, hasQue
998
1462
  const properties = props.map(({ name, type }) => type === GetterPropType.BODY ? "data" : name).join(",");
999
1463
  const errorType = getQueryErrorType(operationName, response, httpClient, mutator);
1000
1464
  const dataType = mutator?.isHook ? `ReturnType<typeof use${pascal(operationName)}Hook>` : `typeof ${operationName}`;
1001
- const isAngularClient = isAngular(outputClient);
1002
1465
  const mutationOptionFnReturnType = getQueryOptionsDefinition({
1003
1466
  operationName,
1004
1467
  mutator,
1005
1468
  definitions,
1006
- hasSvelteQueryV4,
1007
- hasQueryV5,
1008
- hasQueryV5WithInfiniteQueryOptionsError,
1009
- isReturnType: true,
1010
- isAngularClient
1469
+ prefix: adapter.getQueryOptionsDefinitionPrefix(),
1470
+ hasQueryV5: adapter.hasQueryV5,
1471
+ hasQueryV5WithInfiniteQueryOptionsError: adapter.hasQueryV5WithInfiniteQueryOptionsError,
1472
+ isReturnType: true
1473
+ });
1474
+ const invalidatesConfig = (query.mutationInvalidates ?? []).filter((rule) => rule.onMutations.includes(operationName)).flatMap((rule) => rule.invalidates).map((t) => normalizeTarget(t));
1475
+ const seenTargets = /* @__PURE__ */ new Set();
1476
+ const uniqueInvalidates = invalidatesConfig.filter((target) => {
1477
+ const key = serializeTarget(target);
1478
+ if (seenTargets.has(key)) return false;
1479
+ seenTargets.add(key);
1480
+ return true;
1011
1481
  });
1012
- const mutationArguments = generateQueryArguments({
1482
+ const hasInvalidation = uniqueInvalidates.length > 0 && adapter.supportsMutationInvalidation();
1483
+ const mutationArguments = adapter.generateQueryArguments({
1013
1484
  operationName,
1014
1485
  definitions,
1015
1486
  mutator,
1016
1487
  isRequestOptions,
1017
- hasSvelteQueryV4,
1018
- hasSvelteQueryV6,
1019
- hasQueryV5,
1020
- hasQueryV5WithInfiniteQueryOptionsError,
1021
1488
  httpClient,
1022
- isAngularClient
1489
+ hasInvalidation
1023
1490
  });
1024
- const mutationArgumentsForOptions = generateQueryArguments({
1491
+ const mutationArgumentsForOptions = adapter.generateQueryArguments({
1025
1492
  operationName,
1026
1493
  definitions,
1027
1494
  mutator,
1028
1495
  isRequestOptions,
1029
- hasSvelteQueryV4,
1030
- hasSvelteQueryV6,
1031
- hasQueryV5,
1032
- hasQueryV5WithInfiniteQueryOptionsError,
1033
1496
  httpClient,
1034
- isAngularClient,
1035
- forQueryOptions: true
1497
+ forQueryOptions: true,
1498
+ hasInvalidation
1036
1499
  });
1037
1500
  const mutationOptionsFnName = camel(mutationOptionsMutator || mutator?.isHook ? `use-${operationName}-mutationOptions` : `get-${operationName}-mutationOptions`);
1038
1501
  const hooksOptionImplementation = getHooksOptionImplementation(isRequestOptions, httpClient, camel(operationName), mutator);
1039
- const invalidatesConfig = (query.mutationInvalidates ?? []).filter((rule) => rule.onMutations.includes(operationName)).flatMap((rule) => rule.invalidates).map((t) => normalizeTarget(t));
1040
- const seenTargets = /* @__PURE__ */ new Set();
1041
- const uniqueInvalidates = invalidatesConfig.filter((target) => {
1042
- const key = serializeTarget(target);
1043
- if (seenTargets.has(key)) return false;
1044
- seenTargets.add(key);
1045
- return true;
1046
- });
1047
- const hasInvalidation = uniqueInvalidates.length > 0 && (isAngularClient || isReact(outputClient) || isSvelte(outputClient));
1048
1502
  const mutationOptionsFn = `export const ${mutationOptionsFnName} = <TError = ${errorType},
1049
- TContext = unknown>(${isAngularHttp && (!mutator || mutator.hasSecondArg) ? "http: HttpClient, " : ""}${hasInvalidation ? "queryClient: QueryClient, " : ""}${mutationArgumentsForOptions}): ${mutationOptionFnReturnType} => {
1503
+ TContext = unknown>(${adapter.getHttpFirstParam(mutator)}${hasInvalidation ? "queryClient: QueryClient, " : ""}${mutationArgumentsForOptions}): ${mutationOptionFnReturnType} => {
1050
1504
 
1051
1505
  ${hooksOptionImplementation}
1052
1506
 
@@ -1056,31 +1510,43 @@ ${hooksOptionImplementation}
1056
1510
  const mutationFn: MutationFunction<Awaited<ReturnType<${dataType}>>, ${definitions ? `{${definitions}}` : "void"}> = (${properties ? "props" : ""}) => {
1057
1511
  ${properties ? `const {${properties}} = props ?? {};` : ""}
1058
1512
 
1059
- return ${operationName}(${isAngularHttp && !mutator ? "http, " : ""}${properties}${properties ? "," : ""}${getMutationRequestArgs(isRequestOptions, httpClient, mutator)})
1513
+ return ${operationName}(${adapter.getMutationHttpPrefix(mutator)}${properties}${properties ? "," : ""}${getMutationRequestArgs(isRequestOptions, httpClient, mutator)})
1060
1514
  }
1061
1515
 
1062
- ${hasInvalidation ? isAngular(outputClient) ? ` const onSuccess = (data: Awaited<ReturnType<typeof ${operationName}>>, variables: ${definitions ? `{${definitions}}` : "void"}, onMutateResult: TContext, context: MutationFunctionContext) => {
1063
- ${uniqueInvalidates.map((t) => generateInvalidateCall(t)).join("\n")}
1064
- mutationOptions?.onSuccess?.(data, variables, onMutateResult, context);
1065
- };` : isReact(outputClient) ? ` const onSuccess = (data: Awaited<ReturnType<typeof ${operationName}>>, variables: ${definitions ? `{${definitions}}` : "void"}, context: TContext) => {
1066
- ${uniqueInvalidates.map((t) => generateInvalidateCall(t)).join("\n")}
1067
- mutationOptions?.onSuccess?.(data, variables, context);
1068
- };` : isSvelte(outputClient) ? hasSvelteQueryV6 ? ` const onSuccess = (data: Awaited<ReturnType<typeof ${operationName}>>, variables: ${definitions ? `{${definitions}}` : "void"}, onMutateResult: TContext, context: MutationFunctionContext) => {
1069
- ${uniqueInvalidates.map((t) => generateInvalidateCall(t)).join("\n")}
1070
- mutationOptions?.onSuccess?.(data, variables, onMutateResult, context);
1071
- };` : ` const onSuccess = (data: Awaited<ReturnType<typeof ${operationName}>>, variables: ${definitions ? `{${definitions}}` : "void"}, context: TContext | undefined) => {
1072
- ${uniqueInvalidates.map((t) => generateInvalidateCall(t)).join("\n")}
1073
- mutationOptions?.onSuccess?.(data, variables, context);
1074
- };` : "" : ""}
1516
+ ${hasInvalidation ? adapter.generateMutationOnSuccess({
1517
+ operationName,
1518
+ definitions,
1519
+ isRequestOptions,
1520
+ generateInvalidateCall,
1521
+ uniqueInvalidates
1522
+ }) : ""}
1075
1523
 
1076
1524
  ${mutationOptionsMutator ? `const customOptions = ${mutationOptionsMutator.name}({...mutationOptions, mutationFn}${mutationOptionsMutator.hasSecondArg ? `, { url: \`${route.replaceAll("/${", "/{")}\` }` : ""}${mutationOptionsMutator.hasThirdArg ? `, { operationId: '${operationId}', operationName: '${operationName}' }` : ""});` : ""}
1077
1525
 
1078
1526
 
1079
- return ${mutationOptionsMutator ? "customOptions" : hasInvalidation ? "{ mutationFn, onSuccess, ...mutationOptions }" : "{ mutationFn, ...mutationOptions }"}}`;
1080
- const operationPrefix = getFrameworkPrefix(hasSvelteQueryV4, isAngular(outputClient), isSolid(outputClient));
1081
- const optionalQueryClientArgument = hasSvelteQueryV6 ? ", queryClient?: () => QueryClient" : (hasQueryV5 || isSvelte(outputClient) && hasInvalidation) && !isAngular(outputClient) ? ", queryClient?: QueryClient" : "";
1082
- const mutationImplementation = `${mutationOptionsFnName}(${hasInvalidation ? `queryClient${isReact(outputClient) || isSvelte(outputClient) && !hasSvelteQueryV6 ? " ?? backupQueryClient" : ""}${hasSvelteQueryV6 ? "?.() ?? backupQueryClient" : ""}, ` : ""}${isRequestOptions ? "options" : "mutationOptions"}${hasSvelteQueryV6 ? "?.()" : ""})`;
1527
+ return ${mutationOptionsMutator ? "customOptions" : hasInvalidation ? "{ ...mutationOptions, mutationFn, onSuccess }" : "{ mutationFn, ...mutationOptions }"}}`;
1528
+ const operationPrefix = adapter.hookPrefix;
1529
+ const optionalQueryClientArgument = adapter.getOptionalQueryClientArgument(hasInvalidation);
1530
+ const mutationImplementation = adapter.generateMutationImplementation({
1531
+ mutationOptionsFnName,
1532
+ hasInvalidation,
1533
+ isRequestOptions
1534
+ });
1083
1535
  const mutationOptionsVarName = camel(`${operationName}-mutation-options`);
1536
+ const mutationReturnType = adapter.getMutationReturnType({
1537
+ dataType,
1538
+ variableType: definitions ? `{${definitions}}` : "void"
1539
+ });
1540
+ const mutationHookBody = adapter.generateMutationHookBody({
1541
+ operationPrefix,
1542
+ mutationOptionsFnName,
1543
+ mutationImplementation,
1544
+ mutationOptionsVarName,
1545
+ isRequestOptions,
1546
+ mutator,
1547
+ hasInvalidation,
1548
+ optionalQueryClientArgument
1549
+ });
1084
1550
  return {
1085
1551
  implementation: `
1086
1552
  ${mutationOptionsFn}
@@ -1090,17 +1556,8 @@ ${mutationOptionsFn}
1090
1556
  export type ${pascal(operationName)}MutationError = ${errorType}
1091
1557
 
1092
1558
  ${doc}export const ${camel(`${operationPrefix}-${operationName}`)} = <TError = ${errorType},
1093
- TContext = unknown>(${mutationArguments} ${optionalQueryClientArgument})${generateMutatorReturnType({
1094
- outputClient,
1095
- dataType,
1096
- variableType: definitions ? `{${definitions}}` : "void"
1097
- })} => {
1098
- ${isAngular(outputClient) ? isAngularHttp && (!mutator || mutator.hasSecondArg) ? ` const http = inject(HttpClient);${hasInvalidation ? "\n const queryClient = inject(QueryClient);" : ""}
1099
- const ${mutationOptionsVarName} = ${mutationOptionsFnName}(http${hasInvalidation ? ", queryClient" : ""}${isRequestOptions ? ", options" : ", mutationOptions"});
1100
-
1101
- return ${operationPrefix}Mutation(() => ${mutationOptionsVarName});` : ` const ${mutationOptionsVarName} = ${mutationImplementation};
1102
-
1103
- return ${operationPrefix}Mutation(() => ${mutationOptionsVarName});` : ` ${(isReact(outputClient) || isSvelte(outputClient)) && hasInvalidation ? "const backupQueryClient = useQueryClient();\n " : ""}return ${operationPrefix}Mutation(${hasSvelteQueryV6 ? `() => ({ ...${mutationImplementation}${optionalQueryClientArgument ? `, queryClient` : ""} })` : isSvelte(outputClient) ? mutationImplementation : `${mutationImplementation}${optionalQueryClientArgument ? `, queryClient` : ""}`});`}
1559
+ TContext = unknown>(${mutationArguments} ${optionalQueryClientArgument})${mutationReturnType} => {
1560
+ ${mutationHookBody}
1104
1561
  }
1105
1562
  `,
1106
1563
  mutators: mutationOptionsMutator ? [mutationOptionsMutator] : void 0
@@ -1109,20 +1566,14 @@ ${isAngular(outputClient) ? isAngularHttp && (!mutator || mutator.hasSecondArg)
1109
1566
 
1110
1567
  //#endregion
1111
1568
  //#region src/query-generator.ts
1112
- /**
1113
- * Get framework-aware prefix for hook names and type definitions
1114
- * @param hasSvelteQueryV4 - Whether using Svelte Query v4
1115
- * @param isAngularClient - Whether using Angular client
1116
- * @param isSolidClient - Whether using Solid Query client
1117
- * @param capitalize - Whether to capitalize the prefix (for type definitions)
1118
- * @returns The appropriate prefix string
1119
- */
1120
- const getFrameworkPrefix = (hasSvelteQueryV4, isAngularClient, isSolidClient, capitalize = false) => {
1121
- let prefix;
1122
- if (hasSvelteQueryV4 || isSolidClient) prefix = "create";
1123
- else if (isAngularClient) prefix = "inject";
1124
- else prefix = "use";
1125
- return capitalize ? prefix.charAt(0).toUpperCase() + prefix.slice(1) : prefix;
1569
+ const getQueryFnArguments = ({ hasQueryParam, hasSignal, hasSignalParam = false }) => {
1570
+ if (!hasQueryParam && !hasSignal) return "";
1571
+ const signalDestructure = hasSignalParam ? "signal: querySignal" : "signal";
1572
+ if (hasQueryParam) {
1573
+ if (hasSignal) return `{ ${signalDestructure}, pageParam }`;
1574
+ return "{ pageParam }";
1575
+ }
1576
+ return `{ ${signalDestructure} }`;
1126
1577
  };
1127
1578
  const generatePrefetch = ({ usePrefetch, type, useQuery, useInfinite, operationName, mutator, doc, queryProps, dataType, errorType, queryArguments, queryOptionsVarName, queryOptionsFnName, queryProperties, isRequestOptions }) => {
1128
1579
  if (!(usePrefetch && (type === QueryType.QUERY || type === QueryType.INFINITE || type === QueryType.SUSPENSE_QUERY && !useQuery || type === QueryType.SUSPENSE_INFINITE && !useInfinite))) return "";
@@ -1145,7 +1596,8 @@ const generatePrefetch = ({ usePrefetch, type, useQuery, useInfinite, operationN
1145
1596
  return queryClient;
1146
1597
  }\n`;
1147
1598
  };
1148
- const generateQueryImplementation = ({ queryOption: { name, queryParam, options, type, queryKeyFnName }, operationName, queryProperties, queryKeyProperties, queryParams, params, props, mutator, queryOptionsMutator, queryKeyMutator, isRequestOptions, response, outputClient, httpClient, isExactOptionalPropertyTypes, hasSignal, route, hasVueQueryV4, hasSvelteQueryV4, hasSvelteQueryV6, hasQueryV5, hasQueryV5WithDataTagError, hasQueryV5WithInfiniteQueryOptionsError, doc, usePrefetch, useQuery, useInfinite, useInvalidate }) => {
1599
+ const generateQueryImplementation = ({ queryOption: { name, queryParam, options, type, queryKeyFnName }, operationName, queryProperties, queryKeyProperties, queryParams, params, props, mutator, queryOptionsMutator, queryKeyMutator, isRequestOptions, response, httpClient, isExactOptionalPropertyTypes, hasSignal, route, doc, usePrefetch, useQuery, useInfinite, useInvalidate, adapter }) => {
1600
+ const { hasQueryV5, hasQueryV5WithDataTagError, hasQueryV5WithInfiniteQueryOptionsError } = adapter;
1149
1601
  const hasSignalParam = props.some((prop) => prop.name === "signal");
1150
1602
  const queryPropDefinitions = toObjectString(props, "definition");
1151
1603
  const definedInitialDataQueryPropsDefinitions = toObjectString(props.map((prop) => {
@@ -1158,105 +1610,66 @@ const generateQueryImplementation = ({ queryOption: { name, queryParam, options,
1158
1610
  };
1159
1611
  }), "definition");
1160
1612
  const queryProps = toObjectString(props, "implementation");
1161
- const angularQueryPropsDefinitions = toObjectString(props.map((prop) => {
1162
- const getterType = prop.definition.replace(/^(\w+)(\??): (.+)$/, (_match, name$1, optional, type$1) => `${name$1}${optional}: ${type$1} | (() => ${type$1.replace(" | undefined", "")}${optional ? " | undefined" : ""})`);
1163
- return {
1164
- ...prop,
1165
- definition: getterType
1166
- };
1167
- }), "definition");
1168
1613
  const hasInfiniteQueryParam = queryParam && queryParams?.schema.name;
1169
- const isAngularHttp = isAngular(outputClient) || httpClient === OutputHttpClient.ANGULAR;
1170
- let httpFunctionProps = queryParam ? props.map((param) => {
1171
- if (param.type === GetterPropType.NAMED_PATH_PARAMS && !isVue(outputClient)) return param.destructured;
1172
- return param.name === "params" ? `{...${isVue(outputClient) ? `unref(params)` : "params"}, '${queryParam}': pageParam || ${isVue(outputClient) ? `unref(params)?.['${queryParam}']` : `params?.['${queryParam}']`}}` : param.name;
1173
- }).join(",") : getHttpFunctionQueryProps(isVue(outputClient), httpClient, queryProperties, isAngularHttp, !!mutator);
1174
- if (queryParam && isAngularHttp && !mutator) httpFunctionProps = httpFunctionProps ? `http, ${httpFunctionProps}` : "http";
1175
- const definedInitialDataReturnType = generateQueryReturnType({
1176
- outputClient,
1614
+ const httpFunctionProps = queryParam ? adapter.getInfiniteQueryHttpProps(props, queryParam, !!mutator) : adapter.getHttpFunctionQueryProps(queryProperties, httpClient, !!mutator);
1615
+ const definedInitialDataReturnType = adapter.getQueryReturnType({
1177
1616
  type,
1178
1617
  isMutatorHook: mutator?.isHook,
1179
1618
  operationName,
1180
- hasVueQueryV4,
1181
- hasSvelteQueryV4,
1182
1619
  hasQueryV5,
1183
1620
  hasQueryV5WithDataTagError,
1184
1621
  isInitialDataDefined: true
1185
1622
  });
1186
- const returnType = generateQueryReturnType({
1187
- outputClient,
1623
+ const returnType = adapter.getQueryReturnType({
1188
1624
  type,
1189
1625
  isMutatorHook: mutator?.isHook,
1190
1626
  operationName,
1191
- hasVueQueryV4,
1192
- hasSvelteQueryV4,
1193
1627
  hasQueryV5,
1194
1628
  hasQueryV5WithDataTagError
1195
1629
  });
1196
1630
  const errorType = getQueryErrorType(operationName, response, httpClient, mutator);
1197
1631
  const dataType = mutator?.isHook ? `ReturnType<typeof use${pascal(operationName)}Hook>` : `typeof ${operationName}`;
1198
- const definedInitialDataQueryArguments = generateQueryArguments({
1632
+ const definedInitialDataQueryArguments = adapter.generateQueryArguments({
1199
1633
  operationName,
1200
1634
  mutator,
1201
1635
  definitions: "",
1202
1636
  isRequestOptions,
1203
1637
  type,
1204
- hasSvelteQueryV4,
1205
- hasSvelteQueryV6,
1206
- hasQueryV5,
1207
- hasQueryV5WithInfiniteQueryOptionsError,
1208
1638
  queryParams,
1209
1639
  queryParam,
1210
1640
  initialData: "defined",
1211
- httpClient,
1212
- isAngularClient: isAngular(outputClient)
1641
+ httpClient
1213
1642
  });
1214
- const undefinedInitialDataQueryArguments = generateQueryArguments({
1643
+ const undefinedInitialDataQueryArguments = adapter.generateQueryArguments({
1215
1644
  operationName,
1216
1645
  definitions: "",
1217
1646
  mutator,
1218
1647
  isRequestOptions,
1219
1648
  type,
1220
- hasSvelteQueryV4,
1221
- hasSvelteQueryV6,
1222
- hasQueryV5,
1223
- hasQueryV5WithInfiniteQueryOptionsError,
1224
1649
  queryParams,
1225
1650
  queryParam,
1226
1651
  initialData: "undefined",
1227
- httpClient,
1228
- isAngularClient: isAngular(outputClient)
1652
+ httpClient
1229
1653
  });
1230
- const queryArguments = generateQueryArguments({
1654
+ const queryArguments = adapter.generateQueryArguments({
1231
1655
  operationName,
1232
1656
  definitions: "",
1233
1657
  mutator,
1234
1658
  isRequestOptions,
1235
1659
  type,
1236
- hasSvelteQueryV4,
1237
- hasSvelteQueryV6,
1238
- hasQueryV5,
1239
- hasQueryV5WithInfiniteQueryOptionsError,
1240
1660
  queryParams,
1241
1661
  queryParam,
1242
- httpClient,
1243
- isAngularClient: isAngular(outputClient),
1244
- forAngularInject: isAngular(outputClient)
1662
+ httpClient
1245
1663
  });
1246
- const queryArgumentsForOptions = generateQueryArguments({
1664
+ const queryArgumentsForOptions = adapter.generateQueryArguments({
1247
1665
  operationName,
1248
1666
  definitions: "",
1249
1667
  mutator,
1250
1668
  isRequestOptions,
1251
1669
  type,
1252
- hasSvelteQueryV4,
1253
- hasSvelteQueryV6,
1254
- hasQueryV5,
1255
- hasQueryV5WithInfiniteQueryOptionsError,
1256
1670
  queryParams,
1257
1671
  queryParam,
1258
1672
  httpClient,
1259
- isAngularClient: isAngular(outputClient),
1260
1673
  forQueryOptions: true
1261
1674
  });
1262
1675
  const queryOptions = getQueryOptions({
@@ -1282,43 +1695,42 @@ const generateQueryImplementation = ({ queryOption: { name, queryParam, options,
1282
1695
  mutator,
1283
1696
  definitions: "",
1284
1697
  type,
1285
- hasSvelteQueryV4,
1698
+ prefix: adapter.getQueryOptionsDefinitionPrefix(),
1286
1699
  hasQueryV5,
1287
1700
  hasQueryV5WithInfiniteQueryOptionsError,
1288
1701
  queryParams,
1289
1702
  queryParam,
1290
- isReturnType: true,
1291
- isAngularClient: isAngular(outputClient)
1703
+ isReturnType: true
1292
1704
  });
1293
1705
  const queryOptionsImp = generateQueryOptions({
1294
1706
  params,
1295
1707
  options,
1296
1708
  type,
1297
- outputClient
1709
+ adapter
1298
1710
  });
1299
1711
  const queryOptionsFnName = camel(queryKeyMutator || queryOptionsMutator || mutator?.isHook ? `use-${name}-queryOptions` : `get-${name}-queryOptions`);
1300
1712
  const queryOptionsVarName = isRequestOptions ? "queryOptions" : "options";
1301
1713
  const queryResultVarName = props.some((prop) => prop.name === "query") ? "_query" : "query";
1302
1714
  const infiniteParam = queryParams && queryParam ? `, ${queryParams.schema.name}['${queryParam}']` : "";
1303
1715
  const TData = hasQueryV5 && (type === QueryType.INFINITE || type === QueryType.SUSPENSE_INFINITE) ? `InfiniteData<Awaited<ReturnType<${dataType}>>${infiniteParam}>` : `Awaited<ReturnType<${dataType}>>`;
1304
- const queryOptionsFn = `export const ${queryOptionsFnName} = <TData = ${TData}, TError = ${errorType}>(${isAngularHttp && (!mutator || mutator.hasSecondArg) ? "http: HttpClient, " : ""}${queryProps} ${queryArgumentsForOptions}) => {
1716
+ const queryOptionsFn = `export const ${queryOptionsFnName} = <TData = ${TData}, TError = ${errorType}>(${adapter.getHttpFirstParam(mutator)}${queryProps} ${queryArgumentsForOptions}) => {
1305
1717
 
1306
1718
  ${hookOptions}
1307
1719
 
1308
- const queryKey = ${queryKeyMutator ? `${queryKeyMutator.name}({ ${queryProperties} }${queryKeyMutator.hasSecondArg ? `, { url: \`${route}\`, queryOptions }` : ""});` : `${hasVueQueryV4 ? "" : "queryOptions?.queryKey ?? "}${queryKeyFnName}(${queryKeyProperties});`}
1720
+ const queryKey = ${queryKeyMutator ? `${queryKeyMutator.name}({ ${queryProperties} }${queryKeyMutator.hasSecondArg ? `, { url: \`${route}\`, queryOptions }` : ""});` : `${adapter.getQueryKeyPrefix()}${queryKeyFnName}(${queryKeyProperties});`}
1309
1721
 
1310
1722
  ${mutator?.isHook ? `const ${operationName} = use${pascal(operationName)}Hook();` : ""}
1311
1723
 
1312
1724
  const queryFn: QueryFunction<Awaited<ReturnType<${mutator?.isHook ? `ReturnType<typeof use${pascal(operationName)}Hook>` : `typeof ${operationName}`}>>${hasQueryV5 && hasInfiniteQueryParam ? `, QueryKey, ${queryParams.schema.name}['${queryParam}']` : ""}> = (${queryFnArguments}) => ${operationName}(${httpFunctionProps}${httpFunctionProps ? ", " : ""}${queryOptions});
1313
1725
 
1314
- ${isVue(outputClient) ? vueUnRefParams(props.filter((prop) => prop.type === GetterPropType.NAMED_PATH_PARAMS)) : ""}
1726
+ ${adapter.getUnrefStatements(props)}
1315
1727
 
1316
1728
  ${queryOptionsMutator ? `const customOptions = ${queryOptionsMutator.name}({...queryOptions, queryKey, queryFn}${queryOptionsMutator.hasSecondArg ? `, { ${queryProperties} }` : ""}${queryOptionsMutator.hasThirdArg ? `, { url: \`${route}\` }` : ""});` : ""}
1317
1729
 
1318
- return ${queryOptionsMutator ? "customOptions" : `{ queryKey, queryFn, ${queryOptionsImp}}`} as ${queryOptionFnReturnType} ${isVue(outputClient) || isAngular(outputClient) ? "" : `& { queryKey: ${hasQueryV5 ? `DataTag<QueryKey, TData${hasQueryV5WithDataTagError ? ", TError" : ""}>` : "QueryKey"} }`}
1730
+ return ${queryOptionsMutator ? "customOptions" : `{ queryKey, queryFn, ${queryOptionsImp}}`} as ${queryOptionFnReturnType} ${adapter.shouldAnnotateQueryKey() ? `& { queryKey: ${hasQueryV5 ? `DataTag<QueryKey, TData${hasQueryV5WithDataTagError ? ", TError" : ""}>` : "QueryKey"} }` : ""}
1319
1731
  }`;
1320
- const operationPrefix = getFrameworkPrefix(hasSvelteQueryV4, isAngular(outputClient), isSolid(outputClient));
1321
- const optionalQueryClientArgument = hasSvelteQueryV6 ? `, queryClient?: () => QueryClient` : hasQueryV5 && !isAngular(outputClient) ? ", queryClient?: QueryClient" : "";
1732
+ const operationPrefix = adapter.hookPrefix;
1733
+ const optionalQueryClientArgument = adapter.getOptionalQueryClientArgument();
1322
1734
  const queryHookName = camel(`${operationPrefix}-${name}`);
1323
1735
  const overrideTypes = `
1324
1736
  export function ${queryHookName}<TData = ${TData}, TError = ${errorType}>(\n ${definedInitialDataQueryPropsDefinitions} ${definedInitialDataQueryArguments} ${optionalQueryClientArgument}\n ): ${definedInitialDataReturnType}
@@ -1343,36 +1755,39 @@ export function ${queryHookName}<TData = ${TData}, TError = ${errorType}>(\n ${q
1343
1755
  });
1344
1756
  const shouldGenerateInvalidate = useInvalidate && (type === QueryType.QUERY || type === QueryType.INFINITE || type === QueryType.SUSPENSE_QUERY && !useQuery || type === QueryType.SUSPENSE_INFINITE && !useInfinite);
1345
1757
  const invalidateFnName = camel(`invalidate-${name}`);
1758
+ const queryInit = adapter.generateQueryInit({
1759
+ queryOptionsFnName,
1760
+ queryProperties,
1761
+ isRequestOptions,
1762
+ mutator
1763
+ });
1764
+ const queryInvocationArgs = adapter.generateQueryInvocationArgs({
1765
+ props,
1766
+ queryOptionsFnName,
1767
+ queryProperties,
1768
+ isRequestOptions,
1769
+ mutator,
1770
+ operationPrefix,
1771
+ type,
1772
+ queryOptionsVarName,
1773
+ optionalQueryClientArgument
1774
+ });
1775
+ const queryInvocationSuffix = adapter.getQueryInvocationSuffix();
1346
1776
  return `
1347
1777
  ${queryOptionsFn}
1348
1778
 
1349
1779
  export type ${pascal(name)}QueryResult = NonNullable<Awaited<ReturnType<${dataType}>>>
1350
1780
  export type ${pascal(name)}QueryError = ${errorType}
1351
1781
 
1352
- ${hasQueryV5 && OutputClient.REACT_QUERY === outputClient ? overrideTypes : ""}
1782
+ ${adapter.shouldGenerateOverrideTypes() ? overrideTypes : ""}
1353
1783
  ${doc}
1354
- export function ${queryHookName}<TData = ${TData}, TError = ${errorType}>(\n ${hasSvelteQueryV6 ? toObjectString(props.map((p) => ({
1355
- ...p,
1356
- definition: p.definition.replace(":", ": () => ")
1357
- })), "definition") : isAngular(outputClient) ? angularQueryPropsDefinitions : queryProps} ${queryArguments} ${optionalQueryClientArgument} \n ): ${returnType} {
1784
+ export function ${queryHookName}<TData = ${TData}, TError = ${errorType}>(\n ${adapter.getHookPropsDefinitions(props)} ${queryArguments} ${optionalQueryClientArgument} \n ): ${returnType} {
1358
1785
 
1359
- ${hasSvelteQueryV6 ? "" : isAngular(outputClient) && (!mutator || mutator.hasSecondArg) ? `const http = inject(HttpClient);` : isAngular(outputClient) ? "" : `const ${queryOptionsVarName} = ${queryOptionsFnName}(${queryProperties}${queryProperties ? "," : ""}${isRequestOptions ? "options" : "queryOptions"})`}
1786
+ ${queryInit}
1360
1787
 
1361
- const ${queryResultVarName} = ${camel(`${operationPrefix}-${isAngular(outputClient) || hasSvelteQueryV4 ? getQueryTypeForFramework(type) : type}`)}(${isAngular(outputClient) ? `() => {${props.length > 0 ? `
1362
- // Resolve params if getter function (for signal reactivity)
1363
- ${props.map((p) => `const _${p.name} = typeof ${p.name} === 'function' ? ${p.name}() : ${p.name};`).join("\n ")}` : ""}
1364
- // Resolve options if getter function (for signal reactivity)
1365
- const _options = typeof ${isRequestOptions ? "options" : "queryOptions"} === 'function' ? ${isRequestOptions ? "options" : "queryOptions"}() : ${isRequestOptions ? "options" : "queryOptions"};
1366
- return ${queryOptionsFnName}(${!mutator || mutator.hasSecondArg ? "http" : ""}${props.length > 0 ? `${!mutator || mutator.hasSecondArg ? ", " : ""}${props.map((p) => `_${p.name}`).join(", ")}` : ""}, _options);
1367
- }` : hasSvelteQueryV6 ? `() => ${queryOptionsFnName}(${toObjectString(props.map((p) => ({
1368
- ...p,
1369
- name: p.default || !p.required ? `${p.name}?.()` : `${p.name}()`
1370
- })), "name")}${isRequestOptions ? "options?.()" : "queryOptions?.()"})` : `${queryOptionsVarName}${!isAngular(outputClient) && optionalQueryClientArgument ? ", queryClient" : ""}`}${hasSvelteQueryV6 ? `, queryClient` : ""}) as ${returnType};
1788
+ const ${queryResultVarName} = ${camel(`${operationPrefix}-${adapter.getQueryType(type)}`)}(${queryInvocationArgs}${queryInvocationSuffix}) as ${returnType};
1371
1789
 
1372
- ${getQueryReturnStatement({
1373
- outputClient,
1374
- hasSvelteQueryV4,
1375
- hasSvelteQueryV6,
1790
+ ${adapter.getQueryReturnStatement({
1376
1791
  hasQueryV5,
1377
1792
  hasQueryV5WithDataTagError,
1378
1793
  queryResultVarName,
@@ -1388,24 +1803,17 @@ ${shouldGenerateInvalidate ? `${doc}export const ${invalidateFnName} = async (\n
1388
1803
  }\n` : ""}
1389
1804
  `;
1390
1805
  };
1391
- const generateQueryHook = async (verbOptions, options, outputClient) => {
1806
+ const generateQueryHook = async (verbOptions, options, outputClient, adapter) => {
1807
+ if (!adapter) throw new Error("FrameworkAdapter is required for generateQueryHook");
1392
1808
  const { queryParams, operationName, body, props: _props, verb, params, override, mutator, response, operationId, summary, deprecated } = verbOptions;
1393
1809
  const { route, override: { operations }, context, output } = options;
1394
- let props = _props;
1395
- if (isVue(outputClient)) props = vueWrapTypeWithMaybeRef(_props);
1810
+ const props = adapter.transformProps(_props);
1396
1811
  const query = override.query;
1397
1812
  const isRequestOptions = override.requestOptions !== false;
1398
1813
  const operationQueryOptions = operations[operationId]?.query;
1399
1814
  const isExactOptionalPropertyTypes = !!context.output.tsconfig?.compilerOptions?.exactOptionalPropertyTypes;
1400
- const queryVersion = query.version;
1401
- const hasVueQueryV4 = OutputClient.VUE_QUERY === outputClient && (!isVueQueryV3(context.output.packageJson) || queryVersion === 4);
1402
- const hasSvelteQueryV4 = OutputClient.SVELTE_QUERY === outputClient && (!isSvelteQueryV3(context.output.packageJson) || queryVersion === 4);
1403
- const hasSvelteQueryV6 = OutputClient.SVELTE_QUERY === outputClient && isSvelteQueryV6(context.output.packageJson);
1404
- const hasQueryV5 = queryVersion === 5 || isQueryV5(context.output.packageJson, outputClient);
1405
- const hasQueryV5WithDataTagError = queryVersion === 5 || isQueryV5WithDataTagError(context.output.packageJson, outputClient);
1406
- const hasQueryV5WithInfiniteQueryOptionsError = queryVersion === 5 || isQueryV5WithInfiniteQueryOptionsError(context.output.packageJson, outputClient);
1815
+ const { hasQueryV5 } = adapter;
1407
1816
  const httpClient = context.output.httpClient;
1408
- const isAngularHttp = isAngular(outputClient) || httpClient === OutputHttpClient.ANGULAR;
1409
1817
  const doc = jsDoc({
1410
1818
  summary,
1411
1819
  deprecated
@@ -1444,12 +1852,10 @@ const generateQueryHook = async (verbOptions, options, outputClient) => {
1444
1852
  tsconfig: context.output.tsconfig
1445
1853
  }) : void 0;
1446
1854
  const queryProperties = props.map((param) => {
1447
- if (param.type === GetterPropType.NAMED_PATH_PARAMS && !isVue(outputClient)) return param.destructured;
1448
- return param.type === GetterPropType.BODY ? body.implementation : param.name;
1855
+ return adapter.getQueryPropertyForProp(param, body);
1449
1856
  }).join(",");
1450
1857
  const queryKeyProperties = props.filter((prop) => prop.type !== GetterPropType.HEADER).map((param) => {
1451
- if (param.type === GetterPropType.NAMED_PATH_PARAMS && !isVue(outputClient)) return param.destructured;
1452
- return param.type === GetterPropType.BODY ? body.implementation : param.name;
1858
+ return adapter.getQueryPropertyForProp(param, body);
1453
1859
  }).join(",");
1454
1860
  const queries = [
1455
1861
  ...query.useInfinite || operationQueryOptions?.useInfinite ? [{
@@ -1490,7 +1896,7 @@ ${queryKeyMutator ? "" : uniqueQueryOptionsByKeys.reduce((acc, queryOption) => {
1490
1896
  ...prop,
1491
1897
  implementation: prop.type === GetterPropType.PARAM || prop.type === GetterPropType.NAMED_PATH_PARAMS ? prop.implementation : makeOptionalParam(prop.implementation)
1492
1898
  })), "implementation");
1493
- const routeString = isVue(outputClient) || override.query.shouldSplitQueryKey ? getRouteAsArray(route) : `\`${route}\``;
1899
+ const routeString = adapter.getQueryKeyRouteString(route, !!override.query.shouldSplitQueryKey);
1494
1900
  const queryKeyIdentifier = override.query.useOperationIdAsQueryKey ? `"${operationName}"` : routeString;
1495
1901
  const queryKeyParams = props.filter((p) => override.query.useOperationIdAsQueryKey ? true : p.type === GetterPropType.QUERY_PARAM).toSorted((a) => a.required ? -1 : 1).map((p) => `...(${p.name} ? [${p.name}] : [])`).join(", ");
1496
1902
  return acc + `
@@ -1519,24 +1925,18 @@ ${override.query.shouldExportQueryKey ? "export " : ""}const ${queryOption.query
1519
1925
  isRequestOptions,
1520
1926
  queryParams,
1521
1927
  response,
1522
- outputClient,
1523
1928
  httpClient,
1524
1929
  isExactOptionalPropertyTypes,
1525
1930
  hasSignal: getHasSignal({ overrideQuerySignal: override.query.signal }),
1526
1931
  queryOptionsMutator,
1527
1932
  queryKeyMutator,
1528
1933
  route,
1529
- hasVueQueryV4,
1530
- hasSvelteQueryV4,
1531
- hasSvelteQueryV6,
1532
- hasQueryV5,
1533
- hasQueryV5WithDataTagError,
1534
- hasQueryV5WithInfiniteQueryOptionsError,
1535
1934
  doc,
1536
1935
  usePrefetch: query.usePrefetch,
1537
1936
  useQuery: query.useQuery,
1538
1937
  useInfinite: query.useInfinite,
1539
- useInvalidate: query.useInvalidate
1938
+ useInvalidate: query.useInvalidate,
1939
+ adapter
1540
1940
  });
1541
1941
  }, "")}
1542
1942
  `;
@@ -1549,15 +1949,10 @@ ${override.query.shouldExportQueryKey ? "export " : ""}const ${queryOption.query
1549
1949
  props
1550
1950
  },
1551
1951
  options,
1552
- outputClient,
1553
- hasQueryV5,
1554
- hasQueryV5WithInfiniteQueryOptionsError,
1555
- hasSvelteQueryV4,
1556
- hasSvelteQueryV6,
1557
1952
  isRequestOptions,
1558
1953
  httpClient,
1559
1954
  doc,
1560
- isAngularHttp
1955
+ adapter
1561
1956
  });
1562
1957
  implementation += mutationResult.implementation;
1563
1958
  mutators = mutationResult.mutators ? [...mutators ?? [], ...mutationResult.mutators] : mutators;
@@ -1578,9 +1973,14 @@ ${getQueryHeader(params)}
1578
1973
  `;
1579
1974
  };
1580
1975
  const generateQuery = async (verbOptions, options, outputClient) => {
1976
+ const adapter = createFrameworkAdapter({
1977
+ outputClient,
1978
+ packageJson: options.context.output.packageJson,
1979
+ queryVersion: verbOptions.override.query.version
1980
+ });
1581
1981
  const imports = generateVerbImports(verbOptions);
1582
- const functionImplementation = generateQueryRequestFunction(verbOptions, options, isVue(outputClient));
1583
- const { implementation: hookImplementation, mutators } = await generateQueryHook(verbOptions, options, outputClient);
1982
+ const functionImplementation = adapter.generateRequestFunction(verbOptions, options);
1983
+ const { implementation: hookImplementation, mutators } = await generateQueryHook(verbOptions, options, outputClient, adapter);
1584
1984
  return {
1585
1985
  implementation: `${functionImplementation}\n\n${hookImplementation}`,
1586
1986
  imports,