About
Cool stuff that speed up your work with Cloud Firestore Database.
If you want to contribute just create pull rquest.
Installation and requirements
Currently web sdk only (not yet for Node.js. Expect separate package).
Tested with "firebase": "7.2.0"
(firebase skd should be also installed with npm i -S firebase
)
Compiled with TypeScript 3.6.3
$ npm i -S firebase-firestore-extra
Active augmentations in TypeScript app (when using plain JavaScript it is enough to require('firebase-firestore-extra')
):
import 'firebase-firestore-extra';
import { DocRef } from 'firebase-firestore-extra';
Examples
Some examples (you should be able to figure out everything on your own using typings and firestore documentation)
import { Doc, DocRef, ColRef, Query } from 'firebase-firestore-extra';
import * as firebase from 'firebase';
interface IData = Doc<{name: string, age: number}>
let db = fireStoreDb;
let colRef: ColRef<IData> = db.collection('col') as ColRef<IData>;
let docRef: DocRef<IData> = colRef.doc('docId');
let typedList: IData[] = await colRef.xGet();
let typedObj: IData = await docRef.xGet();
let myObject: IData = {} as any;
let stop = docRef.xWatch(myObject, {otherOptions});
stop();
let myArray: IData = {} as any;
let stop = colRef.xWatch(myArray, {otherOptions});
stop();
colRef.where('name', '==', 'Nejm').limit(10).xWatch(myArray, {otherOptions});
colRef.xWatch(myArray, {
hooks: {
afterAdded: handlerFunc
afterMofified: handlerFunction
afterRemoved: handlerFunction
}
});
Documentation
Just check examples and typings.
For more advanced use cases please check firebase/firestore documentaion and find corresponding options when usign xGet
and xWatch
methods