@equinor/fusion-query
Version:
Reactive data fetching and caching library with observable streams and comprehensive event system
50 lines (49 loc) • 2.31 kB
TypeScript
import { Observable } from 'rxjs';
import type { QueryClient, QueryClientOptions } from './QueryClient';
import type { QueryClientResult } from './types';
type QueryClientJobStatus = 'idle' | 'active' | 'complete' | 'failed' | 'error' | 'canceled';
/**
* Represents a job for the QueryClient that extends an Observable.
* It manages the lifecycle of a query operation.
*/
export declare class QueryClientJob<TType = unknown, TArgs = unknown> extends Observable<QueryClientResult<TType, TArgs>> implements Disposable {
#private;
/**
* Returns the current status of the job.
*/
get status(): QueryClientJobStatus;
get status$(): Observable<QueryClientJobStatus>;
/**
* Returns the transaction identifier for this job.
*/
get transaction(): string;
readonly created: number;
/**
* Indicates whether the query client job is closed.
* A query client job is considered closed if its status is 'complete', 'error', or 'canceled'.
*/
get closed(): boolean;
/**
* Creates an instance of a QueryClientJob.
* @param client The QueryClient instance.
* @param args The arguments to be used for the query.
* @param options Optional settings for the query client job.
*/
constructor(client: QueryClient<TType, TArgs>, args: TArgs, options?: Partial<QueryClientOptions>);
/**
* Completes the job if it's not already closed, marking it as 'complete'.
* This method should be called to gracefully end a job that has finished its task.
* It will also attempt to cancel the job with a completion reason, transitioning its status to 'canceled'
* if it was in an 'active' state but hadn't yet completed.
*/
complete(reason?: string): void;
/**
* Cancels the job with an optional reason, marking its status as 'canceled'.
* This method is used to prematurely end a job that cannot complete its task, either due to an error or a user-defined condition.
* Upon cancellation, a cancellation action is dispatched to notify other parts of the application that the job has been canceled.
* @param reason The reason for the cancellation, which will be included in the cancellation action.
*/
cancel(reason?: string): void;
[Symbol.dispose](): void;
}
export {};