/** * Function signature for `fetch`. */ type FetchFn = (url: string, options?: RequestInit) => Promise; /** * Type for query and mutation errors. */ type QueryError = Error & { /** * Additional error information. */ info?: unknown; /** * HTTP status code. */ status?: number; }; /** * Result of optimistic data provider. */ type OptimisticDataProviderResult = { /** * Kind of the result. * - Update: use the `data` field to update the query cache. * - Skip: skip the optimistic update for this query. * - ProceedDefault: proceed with the default optimistic update. */ kind: 'Update' | 'Skip' | 'ProceedDefault'; /** * Data to update the query cache. Only applicable if `kind` is 'Update'. * * If the data is an object with fields updated, it should have a `$optimistic` * field set to `true`. If it's an array and an element object is created or updated, * the element should have a `$optimistic` field set to `true`. */ data?: any; }; /** * Optimistic data provider. * * @param args Arguments. * @param args.queryModel The model of the query. * @param args.queryOperation The operation of the query, `findMany`, `count`, etc. * @param args.queryArgs The arguments of the query. * @param args.currentData The current cache data for the query. * @param args.mutationArgs The arguments of the mutation. */ type OptimisticDataProvider = (args: { queryModel: string; queryOperation: string; queryArgs: any; currentData: any; mutationArgs: any; }) => OptimisticDataProviderResult | Promise; /** * Extra mutation options. */ type ExtraMutationOptions = { /** * Whether to automatically invalidate queries potentially affected by the mutation. Defaults to `true`. */ invalidateQueries?: boolean; /** * Whether to optimistically update queries potentially affected by the mutation. Defaults to `false`. */ optimisticUpdate?: boolean; /** * A callback for computing optimistic update data for each query cache entry. */ optimisticDataProvider?: OptimisticDataProvider; }; /** * Extra query options. */ type ExtraQueryOptions = { /** * Whether to opt-in to optimistic updates for this query. Defaults to `true`. */ optimisticUpdate?: boolean; }; /** * Context type for configuring the hooks. */ type APIContext = { /** * The endpoint to use for the queries. */ endpoint?: string; /** * A custom fetch function for sending the HTTP requests. */ fetch?: FetchFn; /** * If logging is enabled. */ logging?: boolean; }; type QueryKey = [ string, string, string, unknown, { infinite: boolean; optimisticUpdate: boolean; } ]; /** * Computes query key for the given model, operation and query args. * @param model Model name. * @param urlOrOperation Prisma operation (e.g, `findMany`) or request URL. If it's a URL, the last path segment will be used as the operation name. * @param args Prisma query arguments. * @param options Query options, including `infinite` indicating if it's an infinite query (defaults to false), and `optimisticUpdate` indicating if optimistic updates are enabled (defaults to true). * @returns Query key */ declare function getQueryKey(model: string, urlOrOperation: string, args: unknown, options?: { infinite: boolean; optimisticUpdate: boolean; }): QueryKey; export { type APIContext as A, type ExtraMutationOptions as E, type FetchFn as F, type QueryError as Q, type ExtraQueryOptions as a, getQueryKey as g };