import { HasMapStore } from "../map"; import { QuerySharedContext } from "./context"; export type QueryOptions = { readonly cacheMaxAge: number; readonly fetchingInterval: number; readonly disableCache: boolean; }; export declare const defaultOptions: QueryOptions; export type QueryError = { status: number; statusText: string; message: string; data?: E; }; export type QueryResponse = { data: T; staled: boolean; local: boolean; timestamp: number; }; export interface IObservableQuery { isObserved: boolean; isStarted: boolean; response?: Readonly>; error?: Readonly>; isFetching: boolean; fetch(): Generator | Promise; waitResponse(): Promise> | undefined>; waitFreshResponse(): Promise> | undefined>; } /** * Base of the observable query classes. * This recommends to use the fetch to query the response. */ export declare abstract class ObservableQuery implements IObservableQuery { protected readonly sharedContext: QuerySharedContext; protected static suspectedResponseDatasWithInvalidValue: string[]; protected static guessResponseTruncated(headers: any, data: string): boolean; protected readonly options: QueryOptions; private _response?; protected _isFetching: boolean; private _error?; private _isStarted; private stateQueue; private pendingOnStart; private readonly queryCanceler; private observedCount; private intervalId; protected baseURL: string; protected _url: string; protected constructor(sharedContext: QuerySharedContext, baseURL: string, url: string, options?: Partial); private becomeObserved; private becomeUnobserved; get isObserved(): boolean; private start; private stop; get isStarted(): boolean; private readonly intervalFetch; private postStart; protected onStart(): void | Promise; protected onStop(): void; protected canFetch(): boolean; get isFetching(): boolean; fetch(): Generator; get response(): Readonly> | undefined; get error(): Readonly> | undefined; protected loadStabledResponse(): Promise; protected setResponse(response: Readonly>): void; protected setError(error: QueryError | undefined): void; protected onReceiveResponse(_: Readonly>): void; private cancel; get url(): string; protected setUrl(url: string): void; /** * Wait the response and return the response without considering it is staled or fresh. */ waitResponse(): Promise> | undefined>; /** * Wait the response and return the response until it is fetched. */ waitFreshResponse(): Promise> | undefined>; protected getCacheKey(): string; protected fetchResponse(abortController: AbortController): Promise<{ headers: any; data: T; }>; /** * Used for saving the last response to disk. * This should not make observable state changes. * @param response * @protected */ protected saveResponse(response: Readonly>): Promise; } export declare class ObservableQueryMap extends HasMapStore> { constructor(creater: (key: string) => ObservableQuery); }