Class SingleDocumentRepository<T_model>

Repository with a basic CRUD implemention for collections of one named document.

Type Parameters

Hierarchy (View Summary)

Constructors

Properties

documentId: string = ""

Id of the document

firestore: Firestore

Instance of firestore this repository uses to reach the DB

Accessors

  • get collectionPath(): string
  • Gets the path to the collection of this repository

    Returns string

  • get collectionRef(): CollectionReference<DocumentData, DocumentData>
  • Gets a collection reference to the collection of this repository

    Returns CollectionReference<DocumentData, DocumentData>

    Collection ref to this repository

  • get documentBlueprint(): Record<string, PropertyBluePrint>
  • Gets the blueprint for a document built with the type of this repository

    Returns Record<string, PropertyBluePrint>

    ⚠️ Not ready

  • get isOnSubcollection(): boolean
  • Whether or not this repository is a subcollection or not

    Returns boolean

  • get type(): Type<T_model>
  • Gets the type this repository work on

    Returns Type<T_model>

  • get typeMetadata(): FirestormMetadata<T_model>
  • The metadatas corresponding to the type of this repository

    Returns FirestormMetadata<T_model>

  • get typeName(): string
  • Gets the name of the type.

    Returns string

    Don't rely on its result to do stuff, the name will get mangled after compilation.

Methods

  • Check if the document exists in the database

    If you need to use the document later in the process, getAsync is a better fit

    Returns Promise<boolean>

  • Converts a snapshot to a model

    Parameters

    • documentSnapshot: DocumentSnapshot<DocumentData, DocumentData>

      Document snapshot in firestore

    Returns T_model

    Converts a document snapshot to a model

  • Gets the document of this repository

    Returns Promise<null | T_model>

    A promise containing either the item retrieved or null if it doesn't exist

  • Gets a reference to the document corresponding to this id.

    Parameters

    • id: string

      Id for which you want a document ref

    Returns DocumentReference<DocumentData, DocumentData>

    A document ref corresponding to the model

  • Gets a reference to the document corresponding to this model.

    If the model doesn't have any id, it will give you a reference to a new document, generate an id and assign it to the model

    Parameters

    Returns DocumentReference<DocumentData, DocumentData>

    A document ref corresponding to the model

  • Gets a reference to the document corresponding to this model.

    Parameters

    • modelOrId: string | IFirestormModel

      Id or model for which you want a document ref

    Returns DocumentReference<DocumentData, DocumentData>

    A document ref corresponding to the model

  • Gets a document reference for each of the models provided.

    Parameters

    • ids: string[]

      Ids for which you want document refs

    Returns DocumentReference<DocumentData, DocumentData>[]

    A document ref for each of the models provided in the same order

    getDocumentRef For the rules on each individual model/documentRef

  • Gets a document reference for each of the models provided.

    Parameters

    Returns DocumentReference<DocumentData, DocumentData>[]

    A document ref for each of the models provided in the same order

    getDocumentRef For the rules on each individual model/documentRef

  • Gets a document reference for each of the models provided.

    Parameters

    • modelsOrIds: (string | IFirestormModel)[]

      Ids or models for which you want document refs

    Returns DocumentReference<DocumentData, DocumentData>[]

    A document ref for each of the models provided in the same order

  • Builds the path to a document

    Parameters

    • modelOrId: string | IFirestormModel

      Model or id for which you want the Firestore's DB path

    Returns string

  • Runs a tansaction on the transaction function provided

    Parameters

    • transactionFnc: TransactionFnc

      Operations to do durring the transaction

    • Optionaloptions: TransactionOptions

      Transaction options

    Returns Promise<void>

  • Converts a firestORM query to a firestore query

    Parameters

    Returns Query<DocumentData, DocumentData>

    The firestorm query

  • Modifies the item in the database.

    The id, if provided, is ignored in the model and set to this.documentId

    It will fail if the document doesn't exist.

    Parameters

    • model: Partial<T_model>

      Partial or full model to update. It must have an id.

    Returns Promise<void>

    A Promise that resolved when the item has been updated

  • Writes a new item in the databse.

    The id is ignored in the model and set to this.documentId

    Parameters

    Returns Promise<T_model>