import { EdenClient, type EdenClientError as EdenClientError } from '@aydee-app/eden'; import { type CancelOptions, type InfiniteData, type InvalidateOptions, type InvalidateQueryFilters, type MutationOptions, QueryClient, type QueryFilters, type QueryKey, type RefetchOptions, type RefetchQueryFilters, type ResetOptions, type SetDataOptions, type Updater } from '@tanstack/react-query'; import type { AnyElysia } from 'elysia'; import * as React from 'react'; import type { EdenQueryConfig } from './config'; import type { EdenFetchInfiniteQueryOptions } from './integration/hooks/fetch-infinite'; import type { EdenFetchQueryOptions } from './integration/hooks/fetch-query'; import type { EdenMutationKey, EdenQueryKey, EdenQueryType } from './integration/internal/query-key'; /** * @internal */ export type EdenQueryUtils = { /** * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchquery */ fetchQuery: (queryKey: EdenQueryKey, opts?: EdenFetchQueryOptions>) => Promise; /** * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchinfinitequery */ fetchInfiniteQuery: (queryKey: EdenQueryKey, opts?: EdenFetchInfiniteQueryOptions>) => Promise>; /** * @link https://tanstack.com/query/v5/docs/framework/react/guides/prefetching */ prefetchQuery: (queryKey: EdenQueryKey, opts?: EdenFetchQueryOptions>) => Promise; /** * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientprefetchinfinitequery */ prefetchInfiniteQuery: (queryKey: EdenQueryKey, opts?: EdenFetchInfiniteQueryOptions>) => Promise; /** * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientensurequerydata */ ensureQueryData: (queryKey: EdenQueryKey, opts?: EdenFetchQueryOptions>) => Promise; /** * @link https://tanstack.com/query/v5/docs/framework/react/guides/query-invalidation */ invalidateQueries: (queryKey: EdenQueryKey, filters?: InvalidateQueryFilters, options?: InvalidateOptions) => Promise; /** * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientresetqueries */ resetQueries: (queryKey: EdenQueryKey, filters?: QueryFilters, options?: ResetOptions) => Promise; /** * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientrefetchqueries */ refetchQueries: (queryKey: EdenQueryKey, filters?: RefetchQueryFilters, options?: RefetchOptions) => Promise; /** * @link https://tanstack.com/query/v5/docs/framework/react/guides/query-cancellation */ cancelQuery: (queryKey: EdenQueryKey, options?: CancelOptions) => Promise; /** * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata */ setQueryData: (queryKey: EdenQueryKey, updater: Updater, options?: SetDataOptions) => void; /** * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetqueriesdata */ setQueriesData: (queryKey: EdenQueryKey, filters: QueryFilters, updater: Updater, options?: SetDataOptions) => [QueryKey, unknown][]; /** * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata */ getQueryData: (queryKey: EdenQueryKey) => unknown; /** * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientsetquerydata */ setInfiniteQueryData: (queryKey: EdenQueryKey, updater: Updater | undefined, InfiniteData | undefined>, options?: SetDataOptions) => void; /** * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata */ getInfiniteQueryData: (queryKey: EdenQueryKey) => InfiniteData | undefined; /** * @link https://tanstack.com/query/latest/docs/reference/QueryClient/#queryclientsetmutationdefaults */ setMutationDefaults: (mutationKey: EdenMutationKey, options: MutationOptions | ((args: { canonicalMutationFn: (input: unknown) => Promise; }) => MutationOptions)) => void; /** * @link https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientgetmutationdefaults */ getMutationDefaults: (mutationKey: EdenMutationKey) => MutationOptions | undefined; /** * @link https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientismutating */ isMutating: (filters: { mutationKey: EdenMutationKey; }) => number; }; export declare const EdenQueryContext: React.Context; export type SSRState = 'mounted' | 'mounting' | 'prepass' | false; export type EdenContextPropsBase = { /** * The `TRPCClient` */ client: EdenClient; /** * The SSR context when server-side rendering * @default null */ ssrContext?: TSSRContext | null; /** * State of SSR hydration. * - `false` if not using SSR. * - `prepass` when doing a prepass to fetch queries' data * - `mounting` before TRPCProvider has been rendered on the client * - `mounted` when the TRPCProvider has been rendered on the client * @default false */ ssrState?: SSRState; /** * @deprecated pass abortOnUnmount to `createTRPCReact` instead * Abort loading query calls when unmounting a component - usually when navigating to a new page * @default false */ abortOnUnmount?: boolean; }; export type EdenProviderProps = EdenContextProps & { children: React.ReactNode; }; export type EdenProvider = (props: EdenProviderProps) => React.JSX.Element; export type EdenContextProps = EdenContextPropsBase & { /** * The react-query `QueryClient` */ queryClient: QueryClient; }; export type EdenContextState = Required> & EdenQueryUtils; export declare const contextProps: (keyof EdenContextPropsBase)[]; export declare function getQueryType(utilName: string): EdenQueryType; /** * Creates a set of utility functions that can be used to interact with `react-query` * @param options the `TRPCClient` and `QueryClient` to use * @returns a set of utility functions that can be used to interact with `react-query` * @internal */ export declare function createUtilityFunctions(options: EdenContextProps, config?: EdenQueryConfig): EdenQueryUtils; /** * Hack to make sure errors return `status`='error` when doing SSR * @link https://github.com/trpc/trpc/pull/1645 */ export declare function useSSRQueryOptionsIfNeeded(queryKey: EdenQueryKey, options: TOptions, context: EdenContextState): TOptions;