import { AccessorQueryCacheStore, AccessorQueryConfiguration, AccessorQueryContext, AccessorQueryResult } from './types'; /** * Use a accessor query hook. * * This hook utilizes `React.Suspense`, `React.ErrorBoundary`, and proxies to make data querying easier on the client. * * A "accessor request", which is what this hook is, enables the following: * 1. The client invokes the hook. * 2. The result cache is read to see if the client has already completed this request, if so provide the accessor result. * 3. Otherwise provide the accessor result with a proxy that will "execute" (throw for suspense) the query request when accessed. * 4. The proxy can be invoked by client code. * 5. Trigger suspense to handle executing the query request. Wait until the query request is completed. * 6. The data cache is then set with the query request response. * 7. Suspense will allow rendering to continue again. * 8. The client will invoke the hook again. * 9. Where the request cache is now populated and read. * * A "query request", also known as a "query" to clients, is where our data comes from for the accessor. * The API is a promise but the expectation is that it's data access. So it should **only** retreive data and manage it's data cache. * * A "accessor clear" is provided in the accessor result and will do the following: * 1. Clear the current accessor request cache by calling `configuration.cache.clear`. * * A "accessor invalidate" is provided in the accessor result and will do the following: * 1. Clear the current accessor request cache by calling `configuration.cache.clear` with the accessor request arguments. * 2. Run the accessor request again with the cache now cleared. * * @param.configuration.cache.duration - How long, in milliseconds, the accessor cache should be used for before being invalidated. * @param.configuration.cache.isPrimableFromCache - Determines if the accessor can be primed from the cache of other data accessors. * Once primed the `configuration.cacheDuration` will be respected. * @param.configuration.cache.id - Synchrounous get function used to reference the accessor cache. * @param.configuration.cache.set - Synchrounous set function used to assign the query's response to cache. * @param.configuration.cache.get - Synchrounous get function used to construct the accessor response from cache. * * @param configuration.cache.invalidate.auto.enable - Determine if the accessor should invalidate automatically. * @param configuration.cache.invalidate.auto.interval - How long, in milliseconds, the cache should be invalidated. * * @param.configuration.constraints.enforce - Determine if the accessor should throw when the constraints aren't met. * @param.configuration.constraints.maxDelay - When provided the accessor will be timed. * To see timings you must have `debug` enabled. * If `enforce` is enabled then the accessor will * throw if the accessor can't resolve data within the * `maxDelay`. * * @param.configuration.debug - Turns logging on or off. * @param configuration.query - Asynchrounous get function used to populate the accessor cache. * * @returns (cache: TCache, args: TQueryRequest) => AccessorQueryResult * @param cache - Where to store cache data for data access. * @param args - Arguments to send to the query. * * @example * ``` * // use_get_book.tsx * const accessor = createAccessor({ ... }); * const useGetBook = useQuery(accessor, { ... }); * * // use_get_book_reports.tsx * const accessor = createAccessor({ ... }); * const useGetBookReports = useQuery(accessor, { ... }); * * // BookReports.tsx * const BookReports = ({ id }) => { * const { data: book } = useGetBook({ id }); * const { data: bookReports } = useGetBookReports({ pageId: page.id }); * return <>{bookReports}; * }; * ``` */ export declare const useQuery: (accessor: { configuration: AccessorQueryConfiguration; context: AccessorQueryContext; }, getCacheStore: () => TCache, args: TQueryRequest) => AccessorQueryResult;