You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

firebase-firestore-extra

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

firebase-firestore-extra

Augmentations and typings for firebase/firestore

1.1.1
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source
  • About
  • Installation & requirements
  • Examples
  • Documentation

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') ):

// Mandatory line, even if you are importing something using 'from' syntax
// In case of Angular app put it in main.ts
import 'firebase-firestore-extra';

// Then import required types, even in the same file as above import...
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}>

// configure firebase...
let db = fireStoreDb;

// Of course await inside async function only
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});
// You can deduce other options from typings
// Variable myObject will be synced with database document until stop() called
stop();

let myArray: IData = {} as any;
let stop = colRef.xWatch(myArray, {otherOptions});
// You can deduce other options from typings
// Array myObject will be synced with database documents list until stop() called
stop();

// You can also query with typings
colRef.where('name', '==', 'Nejm').limit(10).xWatch(myArray, {otherOptions});

// Firebase native options objects:
//
// onError handler
// firebase.firestore.GetOptions
// firebase.firestore.SnapshotOptions
// firebase.firestore.SnapshotListenOptions

// The only additional options provided by firestore-extra are hooks:
colRef.xWatch(myArray, {
    hooks: {
        afterAdded: handlerFunc // You can sound alarm if you received new document created later than Date.now()
        afterMofified: handlerFunction
        afterRemoved: handlerFunction
    }
});

// !!
// If handlerFunction will be method of some class remember to use bind

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

Keywords

firebase

FAQs

Package last updated on 18 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts