@jiway/firestorm-core - v1.1.1
    Preparing search index...

    Class CollectionCrudRepository<T_model>

    Repository with a basic CRUD implementation.

    Type Parameters

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    firestorm: Firestorm

    Instance of firestORM this repository uses to reach the DB

    path: Path

    Path of the repository

    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 firestore(): Firestore

      Instance of firestore this repository uses to reach the DB

      Returns Firestore

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

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

    • Converts a snapshot to a model

      Parameters

      • documentSnapshot: DocumentSnapshot

        Document snapshot in firestore

      Returns T_model

      Converts a document snapshot to a model

    • Gets all the items of a collection

      Parameters

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

        Optional params for querying linked documents.

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

        Optional params for querying linked documents.

      Returns Promise<T_model | null>

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

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

      Parameters

      • id: string

        Id for which you want a document ref

      Returns DocumentReference

      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

      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

      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

    • Parameters

      • optimization: RandomAlgorithm = "quality"

        Picks the randomness selection method.

      Returns Promise<T_model | null>

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

    • Returns Promise<T_model | null>

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

    • Parameters

      • randomIndex: number

        A precomputed random value

      Returns Promise<T_model | null>

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

      It's only available for testing purposes.

    • Returns Promise<T_model | null>

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

    • Build a path to a new ressource using the information of the repository and a way to locate the other resource

      Parameters

      • location: PathLike

        Location of the other resource relative to this.

      Returns Path

    • Runs a tansaction on the transaction function provided

      Parameters

      • transactionFnc: TransactionFnc

        Operations to do durring the transaction

      • Optionaloptions: TransactionOptions

        Transaction options

      Returns Promise<void>

    • Modifies an item in the database.

      Parameters

      Returns Promise<void>

      A promise resolved when the item has been updated.