UNPKG

servido

Version:

Versatile services for React ⚗️

76 lines (75 loc) 4.94 kB
import { Service } from "./service"; import { ServiceDataExecution, ServiceExecution } from "./service-execution"; import { Class, ServiceData } from "./service-types"; export declare class ServiceDataStore { readonly parent?: ServiceDataStore; private readonly children; readonly data: Map<string, Map<string, ServiceDataEntry<any>>>; readonly executions: Map<string, Map<string, ServiceDataExecution | ServiceExecution>>; constructor(parent?: ServiceDataStore); nest(): ServiceDataStore; getEntry(service: Service): ServiceDataEntry<unknown>; protected getEntryFromPath<T>(key: string, id: string): ServiceDataEntry<T> | undefined; has(service: Service): boolean; delete(service: Service): boolean; protected hasPath(key: string, id: string): boolean; getExecution(service: Service): ServiceDataExecution | ServiceExecution | void; protected getExecutionFromPath(key: string, id: string): ServiceDataExecution | ServiceExecution | void; getExecutionPromise(service: Service): Promise<void> | void; protected getExecutionPromiseFromPath(key: string, id: string): Promise<void> | void; /** Sets the current promise of a service. The passed promise can have a `promiseId` defined (extending `ServiceExecution`). If it does not have a `promiseId` defined, * a new promise will be created with a defined `promiseId` symbol. This allows for setting a new promise during the time the current promise is resolved, and still allowing * the promise returned from the `ServiceDataStore.promise` method to be resolved at the time that the most recently set promise is resolved. */ setExecution(service: Service, execution: ServiceDataExecution | ServiceExecution): this; /** Deletes an execution in the specific store (does not delete promises in the parent or in children). If there is a current execution that has not yet been set to done, it will be. */ clearCurrentExecution(service: Service): boolean; protected clearCurrentExecutionFromPath(key: string, id: string): boolean; /** Deletes an execution in the specific store (does not delete promises in the parent or in children). If there is a current execution that has not yet been set to done, it will be. */ deleteExecution(service: Service, execution: ServiceDataExecution | ServiceExecution): boolean; protected deleteExecutionFromPath(key: string, id: string, execution: ServiceDataExecution | ServiceExecution): boolean; /** Set the data of a service. If a exection exist for the data, that will be cleared (unless `doNotDeleteExecution`). */ setEntry(service: Service, entry: ServiceDataEntry, doNotDeleteExecution?: boolean): this; protected setEntryFromPath<T>(key: string, id: string, entry: ServiceDataEntry<T>, doNotDeleteExecution?: boolean): this; promise(): Promise<ServiceDataStoreData>; get(): ServiceDataStoreData; set(d: ServiceDataStoreData): void; resolve(): Promise<void>; findNearest(where: (store: ServiceDataStore) => unknown): ServiceDataStore | undefined; protected getPromises(): Promise<void>[]; protected getMappedPromises(): Map<string, Promise<void>>; protected getExecutions(): Map<string, Map<string, ServiceDataExecution>>; protected assignExecutionsUp({ executions, assign }?: { executions: Map<string, Map<string, ServiceDataExecution>>; assign: (assignExecutions: Map<string, Map<string, ServiceDataExecution>>) => void; }): Map<string, Map<string, ServiceDataExecution>>; protected assignExecutionsDown({ executions, assign }?: { executions: Map<string, Map<string, ServiceDataExecution>>; assign: (assignExecutions: Map<string, Map<string, ServiceDataExecution>>) => void; }): Map<string, Map<string, ServiceDataExecution>>; protected getExecutionsAssigner(): { executions: Map<string, Map<string, ServiceDataExecution>>; assign: (assignExecutions: Map<string, Map<string, ServiceDataExecution>>) => void; }; protected getLocalPromises(): Promise<void>[]; protected getKeys(): [string, string][]; protected getLocalKeys(): [string, string][]; toString(): string; static getKey<T>(keyThunk: string | Service | Class<Service>): string; static getId(service: Service): string; static mapKey: string; static mapRootKey: string; static mergeData(...data: ServiceDataStoreData[]): void; static mergeDataRecords(...data: ServiceDataStoreData["data"][]): Record<string, any>; } interface ServiceDataStoreData extends Pick<ServiceData, "data" | "dataErrors"> { } export interface ServiceDataStoreProps { parent?: ServiceDataStore; /** If the store is static, no service will ever be re-constructed. */ static?: boolean; } export interface ServiceDataEntry<T = any> { data?: T; error?: Error; } export {};