Repository with a basic CRUD implementation.

Type Parameters

Hierarchy (View Summary)

Constructors

Properties

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

  • Creates a new item in the database.

    Not providing an id in the item auto generates an id.

    If an item with the same id is already present it will override it destructively (the entire document will be replaced in database)

    Parameters

    Returns Promise<T_model>

    A promise that resolved when and on the item that has been created.

  • Creates a collection of items in the database. The operation is batched, so either they are all created or none are created.

    It behaves exactly like createAsync on a per model basis.

    Parameters

    • ...models: T_model[]

      Models to create

    Returns Promise<T_model[]>

    A promise that resolves when the items have been created.

  • Delete all the documents in a query.

    This is operation is partially batched, it deletes all the documents present when starting the query but doesn't delete the documents created while the query is running.

    ⚠️ It's meant to be used in backend. Avoid doing this in front-end clients.

    Returns Promise<void>

  • Deletes a document in the database. It doesn't delete its subcollection if any.

    Trying to delete a document that doesn't exist will just silently fail

    Parameters

    • id: string

      Id of the document to delete

    Returns Promise<void>

    A promise that returns when the document has been deleted

  • Deletes a document in the database. It doesn't delete its subcollection if any.

    Trying to delete a document that doesn't exist will just silently fail

    This doesn't typecheck the model. It only types check that you provided an id

    Parameters

    Returns Promise<void>

    A promise that returns when the document has been deleted

  • Deletes multiple documents It doesn't delete its subcollection if any.

    This operation is batched

    Trying to delete a document that doesn't exist silently fails.

    Parameters

    • ids: string[]

      Ids of the document to delete

    Returns Promise<void>

  • Deletes multiple documents It doesn't delete its subcollection if any.

    This operation is batched

    Trying to delete a document that doesn't exist silently fails.

    This doesn't typecheck the model. It only types check that you provided an id

    Parameters

    Returns Promise<void>

  • Check if a document with this id already exists in the database

    Parameters

    • id: string

      Id of the item to check the existency

    Returns Promise<boolean>

    A promise returning true if an item with this id exists in the collection

    findByIdAsync It's doing findById under the hood so it's almost always preferable to use the other. It's just a convenience

  • Gets all the items of a collection

    Parameters

    • Optionalincludes: Partial<Record<keyof T_model, boolean>>

    Returns Promise<T_model[]>

    A promise containing all the items in the collection

  • Tries to find an item by its id in the database

    Parameters

    • id: string

      Id of the item to find

    • Optionalincludes: Partial<Record<keyof T_model, boolean>>

    Returns Promise<null | T_model>

    A promise containing either the item retrieved or null if not found

  • 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 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

  • Gets a random item in the whole collection.

    It relies on the presence of the field "id" in the document so it won't work if that is not the case.

    Returns Promise<null | T_model>

    A random element of the collection or null if no elements.

  • Builds the path to a document

    Parameters

    • modelOrId: string | IFirestormModel

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

    Returns string

  • Queries a collection of items

    Parameters

    Returns Promise<T_model[]>

    A promise on the items that are results of the query

  • 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 an item in the database.

    Parameters

    Returns Promise<void>

    A promise resolved when the item has been updated.