UNPKG

@intuitionrobotics/db-api-generator

Version:
46 lines (45 loc) 2.81 kB
import { ApiTypeBinder, BaseHttpRequest, ErrorResponse, QueryParams } from "@intuitionrobotics/thunderstorm"; import { ApiBinder_DBCreate, ApiBinder_DBDelete, ApiBinder_DBQuery, ApiBinder_DBUniuqe, GenericApiDef } from "../index"; import { Clause_Where, DB_Object } from "@intuitionrobotics/firebase"; import { ThunderDispatcher } from "@intuitionrobotics/thunderstorm/frontend"; import { Module, PartialProperties } from "@intuitionrobotics/ts-common"; export type BaseApiConfig = { relativeUrl: string; key: string; }; export declare abstract class BaseDB_ApiGeneratorCaller<DBType extends DB_Object, UType extends PartialProperties<DBType, "_id"> = PartialProperties<DBType, "_id">> extends Module<BaseApiConfig> { private readonly errorHandler; private defaultDispatcher?; constructor(config: BaseApiConfig, moduleName: string); setDefaultDispatcher(defaultDispatcher: ThunderDispatcher<any, string>): void; protected createRequest<Binder extends ApiTypeBinder<U, R, B, P, any>, U extends string = Binder["url"], R = Binder["response"], B = Binder["body"], P extends QueryParams = Binder["queryParams"]>(apiDef: GenericApiDef): BaseHttpRequest<Binder>; getRequestKey(apiDef: GenericApiDef): string; protected timeoutHandler(apiDef: GenericApiDef): number | void; protected onError(request: BaseHttpRequest<any>, resError?: ErrorResponse<any>): boolean; private getCreateRequest; create(toCreate: UType): BaseHttpRequest<ApiBinder_DBCreate<DBType>>; createSync(toCreate: UType): Promise<ApiBinder_DBCreate<DBType>["response"]>; private getUpdateRequest; update: (toUpdate: DBType) => BaseHttpRequest<ApiBinder_DBCreate<DBType>>; updateSync: (toUpdate: DBType) => Promise<ApiBinder_DBCreate<DBType>["response"]>; private getQueryBody; query: (query?: Clause_Where<DBType>) => BaseHttpRequest<ApiBinder_DBQuery<DBType>>; querySync: (query?: Clause_Where<DBType>) => Promise<ApiBinder_DBQuery<DBType>["response"]>; private getUniqueRequest; unique: (_id: string) => BaseHttpRequest<ApiBinder_DBUniuqe<DBType>>; uniqueSync: (_id: string) => Promise<ApiBinder_DBUniuqe<DBType>["response"]>; private getDeleteRequest; delete: (_id: string) => BaseHttpRequest<ApiBinder_DBDelete<DBType>>; deleteSync: (_id: string) => Promise<ApiBinder_DBDelete<DBType>["response"]>; private ids; private items; getItems(): DBType[]; get(id: string): DBType | undefined; protected onEntryCreated(item: DBType): Promise<void>; private dispatch; protected onEntryDeleted(item: DBType): Promise<void>; protected onEntryUpdated(item: DBType): Promise<void>; protected onGotUnique(item: DBType): Promise<void>; protected onQueryReturned(items: DBType[]): Promise<void>; private upsertId; }