/** * Copyright (c) TonTech. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ import { useQuery as tanstack_useQuery, useMutation } from '@tanstack/react-query'; import type { DefaultError, MutateFunction, QueryKey, UseMutationOptions, UseMutationResult, UseQueryOptions, UseQueryResult, } from '@tanstack/react-query'; import type { Compute, ExactPartial, UnionStrictOmit } from '@ton/appkit'; export { useMutation }; export type UseMutationParameters = Compute< Omit, context>, 'mutationFn' | 'mutationKey' | 'throwOnError'> >; export type UseMutationReturnType< data = unknown, error = Error, variables = void, context = unknown, mutate = MutateFunction, mutateAsync = MutateFunction, > = Compute< UnionStrictOmit, 'mutate' | 'mutateAsync'> & { mutate: mutate; mutateAsync: mutateAsync; } >; export function useQuery( parameters: UseQueryParameters & { queryKey: QueryKey; }, ): UseQueryReturnType { const result = tanstack_useQuery({ ...parameters, // queryKeyHashFn: hashFn, // for bigint support }) as UseQueryReturnType; result.queryKey = parameters.queryKey; return result; } export type UseQueryParameters< queryFnData = unknown, error = DefaultError, data = queryFnData, queryKey extends QueryKey = QueryKey, > = Compute< ExactPartial, 'initialData'>> & { initialData?: UseQueryOptions['initialData'] | undefined; } >; export type UseQueryReturnType = Compute< UseQueryResult & { queryKey: QueryKey; } >;