Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MFDao<M>

inheritdoc

Type parameters

Hierarchy

Implements

Index

Constructors

constructor

  • new MFDao(db: Firestore, storage?: Bucket): MFDao
  • Must be called with super()

    Parameters

    • db: Firestore

      The databse to use to store data

    • Optional storage: Bucket

      The bucket where files will be stored

    Returns MFDao

Properties

Protected db

db: Firestore

The databse to use to store data

mustachePath

mustachePath: string = Reflect.getMetadata('mustachePath', this.constructor)

Collection path with mustache document ids (e.g. lists/{lists}/items)

Protected Optional storage

storage: Bucket

The bucket where files will be stored

Methods

beforeSave

  • beforeSave(model: Partial<M>, idOrLocation?: string | Partial<IMFLocation>): Promise<Partial<M>>
  • Override this method to execute actions before saving document in database

    Parameters

    • model: Partial<M>

      the document to save

    • Optional idOrLocation: string | Partial<IMFLocation>

      id or location (pathIds) where the document will be saved

    Returns Promise<Partial<M>>

    Promise with the document that will be saved instead of the input one

create

delete

deleteByReference

  • deleteByReference(reference: DocumentReference): Promise<void>
  • Delete a model by its reference

    Parameters

    • reference: DocumentReference

      Document reference

    Returns Promise<void>

deleteFile

  • deleteFile(fileObject: IMFFile): Promise<void>
  • Override this method to delete files from somewhere else than in firestore storage

    Parameters

    • fileObject: IMFFile

      File object containing the file to delete

    Returns Promise<void>

Private deleteFiles

  • Delete files from declared file properties and returns the model

    Parameters

    Returns Promise<M>

    Promise of the model

get

  • Get a model from database from id or location

    Parameters

    • idOrLocation: string | IMFLocation

      id or location of the document in database

    • Optional options: IMFGetOneOptions

      (withSnapshot, completeOnFirst, cacheable)

    Returns Promise<M>

    asynchronous answer with model

getByPath

  • Get a model from database from its path

    Parameters

    • path: string

      String path to the document in database

    • Optional options: IMFGetOneOptions

      (withSnapshot, completeOnFirst, cacheable)

    Returns Promise<M>

    asynchronous answer with model

getByReference

  • getByReference(reference: DocumentReference, options?: IMFGetOneOptions): Promise<M>
  • Get a model from database from its reference

    Parameters

    • reference: DocumentReference

      Document reference

    • Optional options: IMFGetOneOptions

      (withSnapshot, completeOnFirst, cacheable)

    Returns Promise<M>

    asynchronous answer with model

Private getFileProperties

  • getFileProperties(model?: Partial<M>): string[]
  • Returns array of file properties names for the partial model consumed or if missing, for the model appliable to this dao

    Parameters

    • Optional model: Partial<M>

      Some partial or full model

    Returns string[]

getList

  • Get a list of documents in the collection

    Parameters

    • Optional location: Omit<IMFLocation, "id">

      List of path ids

    • Optional options: IMFGetListOptions<M>

      (withSnapshot, completeOnFirst, where, orderBy, limit, offset, cacheable)

    Returns Promise<M[]>

getModelFromSnapshot

  • getModelFromSnapshot(snapshot: DocumentSnapshot): M

Abstract getNewModel

  • getNewModel(data?: Partial<M>, location?: Partial<IMFLocation>): M
  • Get a new instance of model M

    Parameters

    • Optional data: Partial<M>

      Data to inject in this model

    • Optional location: Partial<IMFLocation>

      Location of the model in database

    Returns M

    new model

Private getOffsetSnapshot

  • Get the first offset snapshot available (startAt > startAfter > endAt > endBefore)

    Parameters

    Returns Promise<DocumentSnapshot>

getReference

  • getReference(idOrLocation: string | Partial<IMFLocation>): DocumentReference | CollectionReference
  • inheritdoc

    Parameters

    Returns DocumentReference | CollectionReference

getReferenceFromPath

  • getReferenceFromPath(path: string): DocumentReference | CollectionReference
  • Get a reference from a compatible path

    Parameters

    • path: string

      The path for which get a reference

    Returns DocumentReference | CollectionReference

    a CollectionReference or a documentReference depending on the path param

getSnapshot

  • Get a document snapshot from database from an id or a location

    Parameters

    • idOrLocation: string | IMFLocation

      id or location (pathIds)

    • Optional options: IMFGetOneOptions

      (where, orderBy, limit, offset, cacheable)

    Returns Promise<DocumentSnapshot>

    Async answer with the snapshot

isCompatible

  • isCompatible(modelOrReference: M | DocumentReference | CollectionReference): boolean
  • Check if the model or reference is compatible with this DAO based on its path

    Parameters

    • modelOrReference: M | DocumentReference | CollectionReference

      Model or reference to chheck

    Returns boolean

saveFile

  • Override this method to save files somewhere else than in firestore storage

    Parameters

    • fileObject: IMFFile

      File object containing the file to save

    • location: string | IMFLocation

      id or location (pathIds) of the document containing the file object

    Returns Promise<IMFFile>

    Promise of the file object containing storage informations

Private saveFiles

  • saveFiles(model: Partial<M>, location: IMFLocation): Promise<object>
  • Save files from declared file properties and returns the model with storage informations and location with new document id

    Parameters

    • model: Partial<M>

      the model for which files must be stored

    • location: IMFLocation

      location of the model

    Returns Promise<object>

    Promise of an object containing the model with storage informations and location with new document id

update

Private warnOnUnusedOptions

  • warnOnUnusedOptions(methodName: string): (Anonymous function)
  • Returns a function consuming an options object and displaying a warning if some options are not available in nodejs context

    Parameters

    • methodName: string

      The name of the method where this method was called

    Returns (Anonymous function)

Generated using TypeDoc