import { ReactNode } from 'react'; import { default as AbortSignal, AbortSignalProxy } from './AbortSignal'; import { default as ChannelNotifier } from './ChannelNotifier'; import { default as Meta, InferInstance, InferSchema, MetaLike } from './Meta'; import { Constructor } from './utilityTypes'; export type RequestDetails = { name: string; query: Query; disabled: boolean; options: Options | undefined; }; export type ResourceBaseContext = { name: string; query: Query; options: Options | undefined; request: string; revision: string; data: Response; meta: InferSchema; error: Error | undefined; isDisabled: boolean; isIncomplete: boolean; isInitial: boolean; }; export type ResourceContextValue = InferResponse, QueryI extends InferQuery = InferQuery, OptionsI extends InferOptions = InferOptions, MetaTypeI extends InferMetaType = InferMetaType> = ResourceBaseContext & { dataProvider: DataProviderI; isLoading: boolean; isStale: boolean; next: { request: string; revision: string; }; notify: () => Promise<{ request: string; revision: string; }>; }; export type ContextPlugin = (context: ResourceContextValue, props: PluginProps) => ResourceContextValue & PluginTypes; export type UIPlugin = React.ComponentType; children: (context: ResourceContextValue & PluginTypes) => ReactNode; }>; export type Persistence = boolean | 'very'; export interface GetCallback { (error: undefined, done: boolean, result: Response): void; (error: Error, done: boolean, result: undefined): void; } export type ContinuousGet = (callback: GetCallback) => void; export type DataProviderExtend = { context: (plugin: ContextPlugin) => void; ui: (plugin: UIPlugin) => void; }; export default abstract class DataProvider { readonly _inferItem: Item; readonly _inferQuery: Query; readonly _inferOptions: Options; readonly _inferMetaType: MetaType; readonly _inferResponse: Response; readonly _inferContextPluginProps: ContextPluginProps; readonly _inferContextPluginTypes: ContextPluginTypes; readonly _inferUIPluginProps: UIPluginProps; readonly _inferUIPluginTypes: UIPluginTypes; notifier: ChannelNotifier; readonly contextPlugins: ContextPlugin[]; readonly uiPlugins: UIPlugin[]; constructor(); extend(_extend: DataProviderExtend): void; createInstance(): InferInstance | undefined; releaseInstance(_: InferInstance): void; normalizeResource(resource: string): string; subscribe(resource: string, callback: () => void): () => void; notify(resource?: string): void; get(resource: string, query: QueryI, options?: OptionsI, meta?: MetaLike, abortSignal?: AbortSignal): Promise; continuousGet(resource: string, query: QueryI, options: OptionsI | undefined, meta: MetaLike | undefined, callback: GetCallback, abortSignal?: AbortSignal): void; abstract handleGet(resource: string, query: Query, options: Options | undefined, meta: MetaType, abortSignal: AbortSignalProxy): Promise> | Response | ContinuousGet; compareRequests(nextRequestDetails: RequestDetails, prevRequestDetails: RequestDetails): boolean; createEmptyResponse(_requestDetails: RequestDetails): Response; shouldPersist(nextRequestDetails: RequestDetails, prevRequestDetails: RequestDetails, persistent: Persistence, _context: ResourceBaseContext): boolean; compareItemVersions(_item1: Item, _item2: Item): boolean; getItemIdentifier(item: Item): string | undefined; transition(nextContext: ResourceBaseContext, _prevContext: ResourceBaseContext): Response; recycleItems(nextContext: ResourceBaseContext, prevContext: ResourceBaseContext): Response; } export declare const isDataProvider: (dataProvider: unknown) => boolean; export type DataProviderImplementation = Constructor, options: InferOptions | undefined, meta: InferMetaType, abortSignal: AbortSignalProxy): Promise | ContinuousGet>> | InferResponse | ContinuousGet>; }>; export type GenericDataProvider = DataProvider; export type GenericDataProviderImplementation = DataProviderImplementation; export type InferItem = DataProviderI['_inferItem']; export type InferQuery = DataProviderI['_inferQuery']; export type InferOptions = DataProviderI['_inferOptions']; export type InferMetaType = DataProviderI['_inferMetaType']; export type InferResponse = DataProviderI['_inferResponse']; export type InferContextPluginProps = DataProviderI['_inferContextPluginProps']; export type InferContextPluginTypes = DataProviderI['_inferContextPluginTypes']; export type InferUIPluginProps = DataProviderI['_inferUIPluginProps']; export type InferUIPluginTypes = DataProviderI['_inferUIPluginTypes'];