import { ClientPerspective, ContentSourceMap, QueryParams, ResponseQueryOptions } from "@sanity/client"; import { EnableLiveModeOptions, QueryStoreState, createQueryStore } from "@sanity/core-loader"; import { ContentSourceMap as ContentSourceMap$1, ResolveStudioUrl, StudioPathLike, StudioUrl } from "@sanity/client/csm"; /** * @public */ type EncodeDataAttributeFunction = { (path: StudioPathLike): string | undefined; scope: (path: StudioPathLike) => EncodeDataAttributeFunction; }; /** * @public */ type WithEncodeDataAttribute = { encodeDataAttribute: EncodeDataAttributeFunction; }; type UseQueryHook = (query: string, params?: QueryParams, options?: UseQueryOptions) => QueryStoreState & WithEncodeDataAttribute; interface QueryResponseInitial { data: QueryResponseResult; sourceMap: ContentSourceMap | undefined; /** * The perspective used to fetch the data, if not provided it'll assume 'published' */ perspective?: ClientPerspective; } interface UseQueryOptions { /** * Initial `data` and `sourceMap`, used with SSR hydration and is required if `ssr: true` * and an optional speed optimization if `ssr: false`. * It's recommended to set `initial` to the return value of `loadQuery()`. * @example * ```ts * const query = `*[_type == "author" && slug.current == $slug][0]` * export const getServerSideProps = async ({params}) => { * const initial = await loadQuery(query, params) * return { props: { params, initial } } * } * export default function Page({params, initial}) { * const {data} = useQuery(query, params, {initial}) * } * ``` */ initial?: QueryResponseInitial; } interface UseQueryOptionsUndefinedInitial { /** * Initial `data` and `sourceMap`, used with SSR hydration and is required if `ssr: true` * and an optional speed optimization if `ssr: false`. * It's recommended to set `initial` to the return value of `loadQuery()`. * @example * ```ts * const query = `*[_type == "author" && slug.current == $slug][0]` * export const getServerSideProps = async ({params}) => { * const initial = await loadQuery(query, params) * return { props: { params, initial } } * } * export default function Page({params, initial}) { * const {data} = useQuery(query, params, {initial}) * } * ``` */ initial?: undefined; } type NonUndefinedGuard = T extends undefined ? never : T; interface UseQueryOptionsDefinedInitial { /** * Initial `data` and `sourceMap`, used with SSR hydration and is required if `ssr: true` * and an optional speed optimization if `ssr: false`. * It's recommended to set `initial` to the return value of `loadQuery()`. * @example * ```ts * const query = `*[_type == "author" && slug.current == $slug][0]` * export const getServerSideProps = async ({params}) => { * const initial = await loadQuery(query, params) * return { props: { params, initial } } * } * export default function Page({params, initial}) { * const {data} = useQuery(query, params, {initial}) * } * ``` */ initial: NonUndefinedGuard>; } type UseLiveModeHook = (options: EnableLiveModeOptions & { /** * Set this option to activate `encodeDataAttribute` on `useQuery` hooks when stega isn't used. */ studioUrl?: StudioUrl | ResolveStudioUrl | undefined; }) => void; interface QueryStore { loadQuery: (query: string, params?: QueryParams, options?: Pick) => Promise>; setServerClient: ReturnType['setServerClient']; useQuery: { (query: string, params?: QueryParams, options?: UseQueryOptionsUndefinedInitial): QueryStoreState & WithEncodeDataAttribute; (query: string, params?: QueryParams, options?: UseQueryOptionsDefinedInitial): Omit, 'data'> & { data: QueryResponseResult; } & WithEncodeDataAttribute; }; useLiveMode: UseLiveModeHook; } export { UseQueryHook as a, UseQueryOptionsUndefinedInitial as c, __reExport as d, UseLiveModeHook as i, EncodeDataAttributeFunction as l, QueryResponseInitial as n, UseQueryOptions as o, QueryStore as r, UseQueryOptionsDefinedInitial as s, NonUndefinedGuard as t, __exportAll as u }; //# sourceMappingURL=types.d.ts.map