import { IMFDao, IMFLocation, IMFGetOneOptions, IMFGetListOptions, IMFSaveOptions, IMFFile, IMFUpdateOptions, IMFDeleteOptions } from '@modelata/fire/lib/node'; import { DocumentReference, DocumentSnapshot, CollectionReference } from '@google-cloud/firestore'; import { Bucket } from '@google-cloud/storage'; import 'reflect-metadata'; import { MFModel } from './mf-model'; import { MFDeleteMode } from '@modelata/fire/lib/angular/enums/mf-delete-mode.enum'; /** * @inheritdoc */ export declare abstract class MFDao> implements IMFDao { protected db: FirebaseFirestore.Firestore; protected storage?: Bucket; /** * @inheritdoc */ readonly mustachePath: string; /** * soft or hard (default: hard) */ readonly deletionMode: MFDeleteMode; /** * Must be called with super() * * @param db The databse to use to store data * @param storage The bucket where files will be stored */ constructor(db: FirebaseFirestore.Firestore, storage?: Bucket); /** * @inheritdoc * * @param data * @param location */ abstract getNewModel(data?: Partial, location?: Partial): M; /** * @inheritdoc * * @param idOrLocation * @param options */ get(idOrLocation: string | IMFLocation, options?: IMFGetOneOptions): Promise; /** * @inheritdoc * * @param reference * @param options */ getByReference(reference: DocumentReference, options?: IMFGetOneOptions): Promise; /** * @inheritdoc * * @param path * @param options */ getByPath(path: string, options?: IMFGetOneOptions): Promise; /** * @inheritdoc * * @param idOrLocation */ getReference(idOrLocation: string | Partial): DocumentReference | CollectionReference; /** * @inheritdoc * * @param location * @param options */ getList(location?: Omit, options?: IMFGetListOptions): Promise; /** * @inheritdoc * * @param data * @param idOrLocation * @param options */ create(data: M, idOrLocation?: string | Partial, options?: IMFSaveOptions): Promise; /** * @inheritdoc * * @param data * @param idOrLocationOrModel * @param options */ update(data: Partial, idOrLocationOrModel?: string | IMFLocation | M, options?: IMFUpdateOptions): Promise>; /** * @inheritdoc * * @param idLocationOrModel * @param options */ delete(idLocationOrModel: string | IMFLocation | M, options?: IMFDeleteOptions): Promise; /** * Delete a model by its reference * * @param reference Document reference */ deleteByReference(reference: DocumentReference): Promise; /** * @inheritdoc * * @param snapshot */ getModelFromSnapshot(snapshot: DocumentSnapshot): M; /** * @inheritdoc * * @param idOrLocation * @param options */ getSnapshot(idOrLocation: string | IMFLocation, options?: IMFGetOneOptions): Promise; /** * @inheritdoc * * @param model * @param idOrLocation */ beforeSave(model: Partial, idOrLocation?: string | Partial): Promise>; /** * Save files from declared file properties and returns the model with storage informations and location with new document id * * @param model the model for which files must be stored * @param location location of the model * @returns Promise of an object containing the model with storage informations and location with new document id */ private saveFiles; /** * @inheritdoc * * @param fileObject * @param location */ saveFile(fileObject: IMFFile, location: string | IMFLocation): Promise; /** * Delete files from declared file properties and returns the model * * @param model the model for which files must be deleted * @param options override delete on delete default option * @returns Promise of the model */ private deleteFiles; /** * @inheritdoc * * @param fileObject */ deleteFile(fileObject: IMFFile): Promise; /** * Check if the model or reference is compatible with this DAO based on its path * * @param modelOrReference Model or reference to chheck */ isCompatible(modelOrReference: M | DocumentReference | CollectionReference): boolean; /** * Returns a function consuming an options object and displaying a warning if some options are not available in nodejs context * * @param methodName The name of the method where this method was called */ private warnOnUnusedOptions; /** * Get the first offset snapshot available (startAt > startAfter > endAt > endBefore) * * @param offsetOption The offset option value used here * @param options get one options to apply */ private getOffsetSnapshot; /** * Get a reference from a compatible path * * @param path The path for which get a reference * @return a CollectionReference or a documentReference depending on the path param */ getReferenceFromPath(path: string): DocumentReference | CollectionReference; /** * Returns array of file properties names for the partial model consumed or if missing, for the model appliable to this dao * * @param model Some partial or full model */ private getFileProperties; /** * Delete collection and all subcollections * * @param collection collection to delete * @param deletetionMode */ private deleteSubCollection; }