import IQueryOptions from '../../Interfaces/Query/IProductQueryOptions'; import { IBatchAction } from './BatchUtils'; export interface IDatabaseRef { path: string; data: object | undefined; id: string; exists: boolean; timestamp: number; } export interface ISaveOption { merge?: boolean; _provider?: string; noEvent?: boolean; } export interface IRefObject { path: string; id: string; } export default class DatabaseService { /** * Get one document by it's Id * @param path the collection path of the document * @param id the Id of the document * @param _provider optional override of the default provider * @returns an IDatabaseRef with the state of the document and data if found */ static getDocument: (path: string, id: string, _provider?: string) => Promise; /** * Get one document by its full path * @param path the full path with document id * @param _provider optional override of the default provider * @returns an IDatabaseRef with the state of the document and data if found */ static getDocumentByPath: (path: string, _provider?: string) => Promise; /** * get many documents using a query * @param path the collection path * @param query the query options * @param _provider optional override of the default provider * @returns a list of IDatabaseRef with the state of the document and data if found */ static getDocuments: (path: string, query?: IQueryOptions, _provider?: string) => Promise; /** * Save the document data * @param path the collection path of the document * @param id the document id * @param timestamp the timestamp of the save * @param obj the data object to save * @param options options like merge * @param _provider optional override of the default provider * @returns true if success */ static saveDocument: (path: string, id: string, timestamp: number, obj: any, options?: ISaveOption, _provider?: string) => Promise; /** * Create a new document * @param path the collection path * @param obj the data object to save * @param _provider optional override of the default provider * @returns the new id if success else false */ static addDocument: (path: string, obj: any, _provider?: string, noEvent?: boolean) => Promise; /** * Delete a document * @param path the collection path * @param id the document id * @param _provider optional override of the default provider * @returns true if success */ static deleteDocument: (path: string, id: string, _provider?: string, noEvent?: boolean) => Promise; /** * Delete a document by its full path * @param path full path with document id * @param _provider * @param forceFirebase * @returns true if success */ static deleteDocumentByPath: (path: string, _provider?: string, noEvent?: boolean) => Promise; static processBatch: (batch: IBatchAction[], _provider?: string, noEvent?: boolean) => Promise; /** * Register a call back on data change * @param callback the function to call with the new data * @param path the collection path to watch * @param query the query for the data to be returned */ static registerListener: (callback: (_: IDatabaseRef[]) => void, path: string, query?: IQueryOptions) => string; /** * Remove a listner * * @param id id of the previously created listner */ static unregisterListener: (id: string) => void; /** * concat a path with extra section to be added * @param path the base path * @param extra the extra part to add * @returns the concatened path */ static addToPath: (path: string, extra: string) => string; /** * concat a path with extra section to be added * @param path the base path * @param extra the extra part to add * @returns the concatened path as an object */ static asCollectionObject: (path: string, extra: string) => { path: string; }; /** * Convert full path to document into a reference object * @param fullPath the full path to the document * @returns A reference object used in class */ static pathToReferenceObject: (fullPath: string) => { path: string; id: string; }; /** * get the parent of a path * @param path original path * @returns parent path */ static getPathParent: (path: string) => string; static getIdFromRef: (fullPath: string) => string | undefined; private static getProvider; }