UNPKG

@kubb/plugin-vue-query

Version:

Vue Query hooks generator plugin for Kubb, creating type-safe API client hooks from OpenAPI specifications for Vue.js applications.

95 lines (85 loc) 3.79 kB
/** * Generated by Kubb (https://kubb.dev/). * Do not edit manually. */ import fetch from '@kubb/plugin-client/clients/axios' import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios' import type { QueryKey, QueryClient, QueryObserverOptions, UseQueryReturnType } from 'custom-query' import type { MaybeRefOrGetter } from 'vue' import { queryOptions, useQuery } from 'custom-query' import { toValue } from 'vue' export const updatePetWithFormQueryKey = ( petId: MaybeRefOrGetter<UpdatePetWithFormPathParams['petId']>, data?: MaybeRefOrGetter<UpdatePetWithFormMutationRequest>, params?: MaybeRefOrGetter<UpdatePetWithFormQueryParams>, ) => [{ url: '/pet/:petId', params: { petId: petId } }, ...(params ? [params] : []), ...(data ? [data] : [])] as const export type UpdatePetWithFormQueryKey = ReturnType<typeof updatePetWithFormQueryKey> /** * @summary Updates a pet in the store with form data * {@link /pet/:petId} */ export async function updatePetWithForm( petId: UpdatePetWithFormPathParams['petId'], data?: UpdatePetWithFormMutationRequest, params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> & { client?: typeof fetch } = {}, ) { const { client: request = fetch, ...requestConfig } = config const requestData = updatePetWithFormMutationRequest.parse(data) const res = await request<UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>, UpdatePetWithFormMutationRequest>({ method: 'POST', url: `/pet/${petId}`, params, data: requestData, ...requestConfig, }) return updatePetWithFormMutationResponse.parse(res.data) } export function updatePetWithFormQueryOptions( petId: MaybeRefOrGetter<UpdatePetWithFormPathParams['petId']>, data?: MaybeRefOrGetter<UpdatePetWithFormMutationRequest>, params?: MaybeRefOrGetter<UpdatePetWithFormQueryParams>, config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> & { client?: typeof fetch } = {}, ) { const queryKey = updatePetWithFormQueryKey(petId, data, params) return queryOptions<UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>, UpdatePetWithFormMutationResponse, typeof queryKey>({ enabled: !!petId, queryKey, queryFn: async ({ signal }) => { config.signal = signal return updatePetWithForm(toValue(petId), toValue(data), toValue(params), toValue(config)) }, }) } /** * @summary Updates a pet in the store with form data * {@link /pet/:petId} */ export function useUpdatePetWithForm< TData = UpdatePetWithFormMutationResponse, TQueryData = UpdatePetWithFormMutationResponse, TQueryKey extends QueryKey = UpdatePetWithFormQueryKey, >( petId: MaybeRefOrGetter<UpdatePetWithFormPathParams['petId']>, data?: MaybeRefOrGetter<UpdatePetWithFormMutationRequest>, params?: MaybeRefOrGetter<UpdatePetWithFormQueryParams>, options: { query?: Partial<QueryObserverOptions<UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>, TData, TQueryData, TQueryKey>> & { client?: QueryClient } client?: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> & { client?: typeof fetch } } = {}, ) { const { query: { client: queryClient, ...queryOptions } = {}, client: config = {} } = options ?? {} const queryKey = queryOptions?.queryKey ?? updatePetWithFormQueryKey(petId, data, params) const query = useQuery( { ...updatePetWithFormQueryOptions(petId, data, params, config), queryKey, ...queryOptions, } as unknown as QueryObserverOptions, queryClient, ) as UseQueryReturnType<TData, ResponseErrorConfig<UpdatePetWithForm405>> & { queryKey: TQueryKey } query.queryKey = queryKey as TQueryKey return query }