export type AccessorQueryResultFetchMore = () => Promise< AccessorQueryResult >; export type AccessorQueryResultClear = () => void; export type AccessorQueryResultInvalidate = () => void; export type AccessorQueryCacheStoreSet = { (store: T): void; }; export type AccessorQueryCacheStore = { dataAccess: { set: (store: AccessorQueryCacheStoreSet) => any; query: Map< string, | { cacheTimeToRefresh: number; promise: null | Promise>; } | Error >; suspense: Map AccessorQueryResultCacheSetResult>; }; }; type AccessorQueryConfigurationCacheSet< TCache, TQueryRequest, TQueryResponse, TData, > = (args: { cache: () => TCache; cacheId: string; args: TQueryRequest; request: ( args: TQueryRequest, ) => Promise>; response: { status: number; data: TQueryResponse }; }) => { data: TData }; type AccessorQueryConfigurationCacheGet = (args: { cache: () => TCache; cacheId: string; args: TQueryRequest; request: ( args: TQueryRequest, ) => Promise>; }) => AccessorQueryResultCacheSetResult | null; type AccessorQueryConfigurationCacheClear = (args: { cacheId: string; args: TQueryRequest; set: (store: AccessorQueryCacheStoreSet) => any; }) => void; export type AccessorQueryConfiguration< TCache, TQueryRequest, TQueryResponse, TData, > = { debug?: boolean; cache: { duration: number; isPrimableFromCache: boolean; id: (args: { args: TQueryRequest }) => string; invalidate?: { auto?: { enable: boolean; interval?: number } }; set: AccessorQueryConfigurationCacheSet< TCache, TQueryRequest, TQueryResponse, TData >; get: AccessorQueryConfigurationCacheGet; clear: AccessorQueryConfigurationCacheClear; }; constraints?: { enforce?: boolean; maxDelay?: number; }; query: ( args: TQueryRequest, ) => Promise>; }; export type AccessorQueryContext = { queryName: string; requestQueryPromise: ( getCacheStore: () => TCache, args: TQueryRequest, ) => Promise>; suspenseRequestQuery: ({ getCacheStore, onDone, args, }: { getCacheStore: () => TCache; onDone?: () => void; args: TQueryRequest; }) => () => AccessorQueryResultCacheSetResult; }; export type AccessorQueryResultCacheSetResult = { data: null | TData; fetchMore?: null | AccessorQueryResultFetchMore; }; export type AccessorQueryResult = { // Data from the accessor request. data: null | TData; // Prepopulated `request` for additional data from a `query`. fetchMore?: null | AccessorQueryResultFetchMore; // PrePopulated `clear` to remove a reqeust from the cache. // You might be looking for `invalidate`. clear: AccessorQueryResultClear; // PrePopulated `clear` **and** will invoke the accessor request again. invalidate: AccessorQueryResultInvalidate; }; export type AccessorQueryRequestResponse = { status: number; data?: null | T; error?: string; }; export class ErrorTimedOut extends Error { constructor(queryName: string, cacheId: string) { super(`Data accessor '${queryName}' with id '${cacheId}' timed out.`); } }