src/lib/firestore-extended.class.ts
FirestoreExt Class that uses the FirestoreWrapper Simply extend this class and give it an initialized FirebaseApp to use the FireStoreExtended methods.
constructor(firebaseApp: FirebaseApp, defaultDocId: string)
|
|||||||||
Defined in src/lib/firestore-extended.class.ts:9
|
|||||||||
Parameters :
|
Public defaultDocId |
Type : string
|
Default value : 'data'
|
Inherited from
FirestoreExtended
|
Defined in
FirestoreExtended:87
|
The default name given to a subCollection document when no name is given
|
Public add$ | |||||||||||||||||||||||||
add$(data: T, collectionRef: CollectionReference
|
|||||||||||||||||||||||||
Inherited from
FirestoreExtended
|
|||||||||||||||||||||||||
Defined in
FirestoreExtended:259
|
|||||||||||||||||||||||||
Type parameters :
|
|||||||||||||||||||||||||
Add document to firestore and split it up into sub collection.
Parameters :
Returns :
Observable<FireItem<T>>
|
Protected addSimple$ | ||||||||||||||||
addSimple$(data: T, collectionRef: CollectionReference
|
||||||||||||||||
Inherited from
FirestoreExtended
|
||||||||||||||||
Defined in
FirestoreExtended:1172
|
||||||||||||||||
Type parameters :
|
||||||||||||||||
A replacement/extension to the AngularFirestoreCollection.add. Does the same as AngularFirestoreCollection.add but can also add createdDate and modifiedDate and returns the data with the added properties in FirebaseDbItem Used internally
Parameters :
Returns :
Observable<FireItem<T>>
|
Protected batchCommit$ | ||||||
batchCommit$(batch: WriteBatch)
|
||||||
Inherited from
FirestoreExtended
|
||||||
Defined in
FirestoreExtended:1622
|
||||||
Turn a batch into an Observable instead of Promise. For some reason angularfire returns a promise on batch.commit() instead of an observable like for everything else. This method turns it into an observable
Parameters :
Returns :
Observable<void>
|
Public changeDocId$ | |||||||||||||||||||||||||
changeDocId$(docRef: DocumentReference
|
|||||||||||||||||||||||||
Inherited from
FirestoreExtended
|
|||||||||||||||||||||||||
Defined in
FirestoreExtended:470
|
|||||||||||||||||||||||||
Type parameters :
|
|||||||||||||||||||||||||
Firestore doesn't allow you do change the name or move a doc directly so you will have to create a new doc under the new name and then delete the old doc. returns the new doc once the delete is done.
Parameters :
Returns :
Observable<FireItem<T>>
|
cleanExtrasFromData | ||||||||||||||||
cleanExtrasFromData(data: | FireItem, subCollectionWriters?: SubCollectionWriter[], additionalFieldsToRemove?: string[])
|
||||||||||||||||
Inherited from
FirestoreExtended
|
||||||||||||||||
Defined in
FirestoreExtended:898
|
||||||||||||||||
Type parameters :
|
||||||||||||||||
clean FirestoreBaseItem properties from the data. Usually done if you wish to save the data to firestore, since some FirestoreBaseItem properties are of non allowed types. Goes through each level and removes DbItemExtras In case you wish to save the data
Parameters :
Returns :
T
|
Public delete$ | |||||||||||||||
delete$(docRef: DocumentReference, subCollectionQueries: SubCollectionQuery[])
|
|||||||||||||||
Inherited from
FirestoreExtended
|
|||||||||||||||
Defined in
FirestoreExtended:747
|
|||||||||||||||
Delete Document and child documents. Takes a DocumentReference and an optional list of SubCollectionQuery
Parameters :
Returns :
Observable<void>
|
Public deleteCollection$ | ||||||||||||
deleteCollection$(collectionRef: CollectionReference
|
||||||||||||
Inherited from
FirestoreExtended
|
||||||||||||
Defined in
FirestoreExtended:839
|
||||||||||||
Type parameters :
|
||||||||||||
Delete all documents and sub collections as specified in subCollectionQueries. Not very efficient and causes a lot of db reads. If possible use the firebase CLI or the console instead when deleting large collections.
Parameters :
Returns :
Observable<any>
|
Public deleteDocByPath$ | |||||||||||||||
deleteDocByPath$(docPath: string, subCollectionQueries: SubCollectionQuery[])
|
|||||||||||||||
Inherited from
FirestoreExtended
|
|||||||||||||||
Defined in
FirestoreExtended:856
|
|||||||||||||||
Delete firestore document by path Convenience method in case we do not have direct access to the AngularFirestoreDocument reference
Parameters :
Returns :
Observable<any>
|
Public deleteIndexedItemInArray$ | |||||||||||||||||||||||||
deleteIndexedItemInArray$(items: Array<FireItem<T>>, indexToDelete: number, subCollectionQueries: SubCollectionQuery[], useCopy: boolean)
|
|||||||||||||||||||||||||
Inherited from
FirestoreExtended
|
|||||||||||||||||||||||||
Defined in
FirestoreExtended:595
|
|||||||||||||||||||||||||
Type parameters :
|
|||||||||||||||||||||||||
Use when you wish to delete an indexed document and have the remaining documents update their indices to reflect the change.
Parameters :
Returns :
Observable<void>
|
Public deleteIndexedItemsInArray$ | |||||||||||||||||||||||||
deleteIndexedItemsInArray$(items: Array<FireItem<T>>, indicesToDelete: number[], subCollectionQueries: SubCollectionQuery[], useCopy: boolean)
|
|||||||||||||||||||||||||
Inherited from
FirestoreExtended
|
|||||||||||||||||||||||||
Defined in
FirestoreExtended:634
|
|||||||||||||||||||||||||
Type parameters :
|
|||||||||||||||||||||||||
Use when you wish to delete several indexed documents and have the remaining documents update their indices to reflect the change.
Parameters :
Returns :
Observable<void>
|
Public deleteItem$ | |||||||||||||||
deleteItem$(item: FireItem<T>, subCollectionQueries: SubCollectionQuery[])
|
|||||||||||||||
Inherited from
FirestoreExtended
|
|||||||||||||||
Defined in
FirestoreExtended:870
|
|||||||||||||||
Type parameters :
|
|||||||||||||||
Delete document by FirestoreItem A very convenient method to remove a previously fetched document. Requires that the document/Item is previously fetched since the item needs to be a FireItem, i.e. includes firestoreMetadata.
Parameters :
Returns :
Observable<any>
|
Public deleteMultiple$ | |||||||||||||||
deleteMultiple$(docRefs: DocumentReference
|
|||||||||||||||
Inherited from
FirestoreExtended
|
|||||||||||||||
Defined in
FirestoreExtended:799
|
|||||||||||||||
Type parameters :
|
|||||||||||||||
Delete Documents and child documents
Parameters :
Returns :
Observable<any>
|
Public deleteMultipleByPaths$ | ||||||
deleteMultipleByPaths$(docPaths: string[])
|
||||||
Inherited from
FirestoreExtended
|
||||||
Defined in
FirestoreExtended:786
|
||||||
Parameters :
Returns :
Observable<any>
|
Protected deleteMultipleSimple$ | ||||||||
deleteMultipleSimple$(docRefs: DocumentReference[])
|
||||||||
Inherited from
FirestoreExtended
|
||||||||
Defined in
FirestoreExtended:1388
|
||||||||
Delete Documents
Parameters :
Returns :
Observable<void>
|
Protected getBatchFromMoveItemInIndexedDocs | |||||||||||||||||||||||||
getBatchFromMoveItemInIndexedDocs(items: Array<FireItem<T>>, fromIndex: number, toIndex: number, useCopy)
|
|||||||||||||||||||||||||
Inherited from
FirestoreExtended
|
|||||||||||||||||||||||||
Defined in
FirestoreExtended:549
|
|||||||||||||||||||||||||
Type parameters :
|
|||||||||||||||||||||||||
Does the heavy lifting when it comes to updating multiple docs to change their index. Not called directly.
Parameters :
Returns :
WriteBatch
|
Protected getBatchFromTransferItemInIndexedDocs | ||||||||||||||||||||||||||||||||||||
getBatchFromTransferItemInIndexedDocs(previousArray: Array<FireItem<T>>, currentArray: Array<FireItem<T>>, previousIndex: number, currentIndex: number, currentArrayName: string, additionalDataUpdateOnMovedItem?: literal type, isUpdateModifiedDateOnMovedItem, useCopy)
|
||||||||||||||||||||||||||||||||||||
Inherited from
FirestoreExtended
|
||||||||||||||||||||||||||||||||||||
Defined in
FirestoreExtended:1308
|
||||||||||||||||||||||||||||||||||||
Type parameters :
|
||||||||||||||||||||||||||||||||||||
Used mainly for drag and drop scenarios where we drag an item from one list to another and the the docs have an index value and a groupName.
Parameters :
Returns :
WriteBatch
|
Protected getBatchFromUpdateIndexFromListOfDocs | ||||||||||||
getBatchFromUpdateIndexFromListOfDocs(items: Array<FireItem<T>>, batch: WriteBatch)
|
||||||||||||
Inherited from
FirestoreExtended
|
||||||||||||
Defined in
FirestoreExtended:699
|
||||||||||||
Type parameters :
|
||||||||||||
Run this on collections with a fixed order using an index: number attribute; This will update that index with the index in the collectionData, so it should be sorted by index first. Basically needs to be run after a delete
Parameters :
Returns :
WriteBatch
|
Public getDeleteBatch$ | ||||||||||||||||||||
getDeleteBatch$(docRef: DocumentReference, subCollectionQueries: SubCollectionQuery[], batch: WriteBatch)
|
||||||||||||||||||||
Inherited from
FirestoreExtended
|
||||||||||||||||||||
Defined in
FirestoreExtended:770
|
||||||||||||||||||||
Returns WriteBatch that is set to delete Document and child documents of given docRef
Parameters :
Returns :
Observable<WriteBatch>
|
Protected getDeleteMultipleSimpleBatch | ||||||||||||
getDeleteMultipleSimpleBatch(docRefs: DocumentReference[], batch: WriteBatch)
|
||||||||||||
Inherited from
FirestoreExtended
|
||||||||||||
Defined in
FirestoreExtended:1395
|
||||||||||||
Parameters :
Returns :
WriteBatch
|
Protected getDocumentReferencesDeep$ | |||||||||||||||
getDocumentReferencesDeep$(ref: DocumentReference | CollectionReference, subCollectionQueries: SubCollectionQuery[])
|
|||||||||||||||
Inherited from
FirestoreExtended
|
|||||||||||||||
Defined in
FirestoreExtended:1462
|
|||||||||||||||
Returns an Observable containing a list of DocumentReference found under the given docRef using the SubCollectionQuery[] Mainly used to delete a docFs and its sub docs
Parameters :
Returns :
Observable<DocumentReference[]>
|
Protected getDocumentReferencesFromCollectionRef$ | ||||||||||||
getDocumentReferencesFromCollectionRef$(collectionRef: CollectionReference
|
||||||||||||
Inherited from
FirestoreExtended
|
||||||||||||
Defined in
FirestoreExtended:1489
|
||||||||||||
Type parameters :
|
||||||||||||
Parameters :
Returns :
Observable<DocumentReference[]>
|
Protected getDocumentReferencesFromDocRef$ | ||||||||||||
getDocumentReferencesFromDocRef$(docRef: DocumentReference
|
||||||||||||
Inherited from
FirestoreExtended
|
||||||||||||
Defined in
FirestoreExtended:1473
|
||||||||||||
Type parameters :
|
||||||||||||
Parameters :
Returns :
Observable<DocumentReference[]>
|
Protected getDocumentReferencesFromItem | |||||||||||||||
getDocumentReferencesFromItem(item: FireItem<T>, subCollectionQueries: SubCollectionQuery[])
|
|||||||||||||||
Inherited from
FirestoreExtended
|
|||||||||||||||
Defined in
FirestoreExtended:1525
|
|||||||||||||||
Type parameters :
|
|||||||||||||||
Used by deleteDeepByItem$ to get all the AngularFirestoreDocuments to be deleted including child documents using SubCollectionQueries Internal use
Parameters :
Returns :
DocumentReference[]
|
Protected getPathsFromItemDeepRecursiveHelper | ||||||||||||
getPathsFromItemDeepRecursiveHelper(item: T, subCollectionQueries: SubCollectionQuery[])
|
||||||||||||
Inherited from
FirestoreExtended
|
||||||||||||
Defined in
FirestoreExtended:1536
|
||||||||||||
Type parameters :
|
||||||||||||
DO NOT CALL THIS METHOD, its meant as a support method for getDocs$
Parameters :
Returns :
string[]
|
Public listenForCollection$ | |||||||||||||||
listenForCollection$(_query: Query
|
|||||||||||||||
Inherited from
FirestoreExtended
|
|||||||||||||||
Defined in
FirestoreExtended:167
|
|||||||||||||||
Type parameters :
|
|||||||||||||||
Same as AngularFirestoreCollection.snapshotChanges but it adds the properties in FirebaseDbItem. Important to understand this is will trigger for every change/update on any of the documents we are listening to. That means that if any document we are listening to is changed the entire object will be triggered containing the updated data. Example usage. ngFirestoreDeep: RxFirestoreExtended; // RxFirestoreExtended variable restaurantCollectionFs = this.ngFireStore.collection('restaurants'); // AngularFirestoreCollectionRef to restaurants constructor(private ngFireStore: AngularFirestore) { this.ngFirestoreDeep = new RxFirestoreExtended(ngFireStore); // initialize AngularFireStoreDeep with AngularFirestore } listenForRestaurants$(): Observable<RestaurantItem[]> {
return this.ngFirestoreDeep.listenForCollection$ If you do not wish to listen for changes and only care about getting the values once getRestaurants$(): Observable<RestaurantItem[]> {
return this.ngFirestoreDeep.listenForCollection$
Parameters :
Returns :
Observable<Array<FireItem<T>>>
|
Public listenForCollectionRecursively$ | ||||||||||||
listenForCollectionRecursively$(collectionPath: string, collectionKey: string, orderKey?: string)
|
||||||||||||
Inherited from
FirestoreExtended
|
||||||||||||
Defined in
FirestoreExtended:202
|
||||||||||||
Type parameters :
|
||||||||||||
Listens for collections inside collections with the same name to an unlimited depth and returns all of it as an array.
Parameters :
Returns :
Observable<any>
|
Protected listenForCollectionsDeep | ||||||||||||
listenForCollectionsDeep(item: FireItem<T>, subCollectionQueries: SubCollectionQuery[])
|
||||||||||||
Inherited from
FirestoreExtended
|
||||||||||||
Defined in
FirestoreExtended:1039
|
||||||||||||
Type parameters :
|
||||||||||||
Used internally for both listenForDoc and listenForCollection in order to recursively get collections. Please use listenForDoc or listenForCollection.
Parameters :
Returns :
Observable<FireItem[]>
|
Protected listenForCollectionSimple$ | ||||||||
listenForCollectionSimple$(_query: Query
|
||||||||
Inherited from
FirestoreExtended
|
||||||||
Defined in
FirestoreExtended:999
|
||||||||
Type parameters :
|
||||||||
Listens for single collection and returns an array of documents as FireItem
Parameters :
Returns :
Observable<Array<FireItem<T>>>
|
Public listenForDoc$ | ||||||||||||||||||||
listenForDoc$(docRef: DocumentReference
|
||||||||||||||||||||
Inherited from
FirestoreExtended
|
||||||||||||||||||||
Defined in
FirestoreExtended:125
|
||||||||||||||||||||
Type parameters :
|
||||||||||||||||||||
Allows for listening to documents and collections n deep up to the firestore max of 100 levels. Triggers for any change in any document that is listened to. E.x: const subCollectionQueries: SubCollectionQuery[] = [ { name: 'data' }, { name: 'secure' }, { name: 'variants' }, { name: 'images', queryFn: ref => ref.orderBy('index'), collectionWithNames: [ { name: 'secure'} ] }, ];
Wrapper for listenForDocDeepRecursiveHelper$ so that we can cast the return to the correct type All logic is in listenForDocDeepRecursiveHelper$.
Parameters :
Returns :
Observable<FireItem<T>>
|
Protected listenForDocDeepRecursiveHelper$ | ||||||||||||||||
listenForDocDeepRecursiveHelper$(docRef: DocumentReference
|
||||||||||||||||
Inherited from
FirestoreExtended
|
||||||||||||||||
Defined in
FirestoreExtended:1138
|
||||||||||||||||
Type parameters :
|
||||||||||||||||
DO NOT CALL THIS METHOD, meant to be used solely by listenForDocAndSubCollections$
Parameters :
Returns :
Observable<any>
|
Protected listenForDocSimple$ | |||||||||||||||
listenForDocSimple$(docRef: DocumentReference
|
|||||||||||||||
Inherited from
FirestoreExtended
|
|||||||||||||||
Defined in
FirestoreExtended:942
|
|||||||||||||||
Type parameters :
|
|||||||||||||||
Same as AngularFirestoreDocument.snapshotChanges but it adds the properties in FirebaseDbItem and also allows for to choose action to take when document does not exist Important to understand this is will trigger for every change/update on the document we are listening to.
Parameters :
Returns :
Observable<FireItem<T>>
|
Public moveItemInArray$ | |||||||||||||||||||||||||
moveItemInArray$(items: Array<FireItem<T>>, fromIndex: number, toIndex: number, useCopy)
|
|||||||||||||||||||||||||
Inherited from
FirestoreExtended
|
|||||||||||||||||||||||||
Defined in
FirestoreExtended:516
|
|||||||||||||||||||||||||
Type parameters :
|
|||||||||||||||||||||||||
Moved item within the same list so we need to update the index of all items in the list; Use a copy if you dont wish to update the given array, for example when you want to just listen for the change of the db.. The reason to not do this is because it takes some time for the db to update and it looks better if the list updates immediately.
Parameters :
Returns :
Observable<void>
|
Protected removeDataExtrasRecursiveHelper | ||||||||||||||||||||
removeDataExtrasRecursiveHelper(dbItem: T, subCollectionWriters: SubCollectionWriter[], additionalFieldsToRemove: string[])
|
||||||||||||||||||||
Inherited from
FirestoreExtended
|
||||||||||||||||||||
Defined in
FirestoreExtended:1411
|
||||||||||||||||||||
Type parameters :
|
||||||||||||||||||||
Recursive method to clean FirestoreBaseItem properties from the dbItem
Parameters :
Returns :
T
|
Protected splitDataIntoCurrentDocAndSubCollections | ||||||||||||
splitDataIntoCurrentDocAndSubCollections(data: T, subCollectionWriters: SubCollectionWriter[])
|
||||||||||||
Inherited from
FirestoreExtended
|
||||||||||||
Defined in
FirestoreExtended:1581
|
||||||||||||
Type parameters :
|
||||||||||||
DO NOT CALL THIS METHOD, used in addDeep and updateDeep to split the data into currentDoc and subCollections Only goes one sub level deep;
Parameters :
Returns :
CurrentDocSubCollectionSplit
|
Public transferItemInIndexedDocs | ||||||||||||||||||||||||||||||||||||
transferItemInIndexedDocs(previousArray: Array<FireItem<T>>, currentArray: Array<FireItem<T>>, previousIndex: number, currentIndex: number, currentArrayName: string, additionalDataUpdateOnMovedItem?: literal type, isUpdateModifiedDateOnMovedItem, useCopy)
|
||||||||||||||||||||||||||||||||||||
Inherited from
FirestoreExtended
|
||||||||||||||||||||||||||||||||||||
Defined in
FirestoreExtended:715
|
||||||||||||||||||||||||||||||||||||
Type parameters :
|
||||||||||||||||||||||||||||||||||||
Parameters :
Returns :
Observable<void>
|
Public update$ | |||||||||||||||||||||||||
update$(data: UpdateData
|
|||||||||||||||||||||||||
Inherited from
FirestoreExtended
|
|||||||||||||||||||||||||
Defined in
FirestoreExtended:424
|
|||||||||||||||||||||||||
Type parameters :
|
|||||||||||||||||||||||||
Update document and child documents Be careful when updating a document of any kind since we allow partial data there cannot be any type checking prior to update so its possible to introduce spelling mistakes on attributes and so forth
Parameters :
Returns :
Observable<void>
|
Protected updateDeepToBatchHelper | ||||||||||||||||||||||||
updateDeepToBatchHelper(data: UpdateData
|
||||||||||||||||||||||||
Inherited from
FirestoreExtended
|
||||||||||||||||||||||||
Defined in
FirestoreExtended:1251
|
||||||||||||||||||||||||
Type parameters :
|
||||||||||||||||||||||||
DO NOT CALL THIS METHOD, used by update deep
Parameters :
Returns :
WriteBatch
|
Public updateMultiple$ | ||||||||||||||||||||
updateMultiple$(docRefs: DocumentReference[], data: A, isAddModifiedDate: boolean)
|
||||||||||||||||||||
Inherited from
FirestoreExtended
|
||||||||||||||||||||
Defined in
FirestoreExtended:444
|
||||||||||||||||||||
Type parameters :
|
||||||||||||||||||||
Update/ add data to the firestore documents
Parameters :
Returns :
Observable<void>
|
Protected updateSimple$ | ||||||||||||||||
updateSimple$(data: UpdateData
|
||||||||||||||||
Inherited from
FirestoreExtended
|
||||||||||||||||
Defined in
FirestoreExtended:1238
|
||||||||||||||||
Type parameters :
|
||||||||||||||||
Used internally for updates that doesn't affect child documents
Parameters :
Returns :
Observable<void>
|
import {FirebaseApp} from 'firebase/app';
import {FirestoreWrapper} from './firestore-wrapper';
import {FirestoreExtended} from './firestore-extended';
/**
* FirestoreExt Class that uses the FirestoreWrapper
* Simply extend this class and give it an initialized FirebaseApp to use the FireStoreExtended methods.
*/
export class FirestoreExt extends FirestoreExtended {
constructor(firebaseApp: FirebaseApp, defaultDocId: string = 'data') {
super(new FirestoreWrapper(firebaseApp), defaultDocId);
}
}