Socket
Socket
Sign inDemoInstall

simplyfire

Package Overview
Dependencies
4
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    simplyfire

A lightweight firestore api for firebase cloud functions & Angular.


Version published
Weekly downloads
5
increased by25%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

simplyfire

A lightweight firestore api for firebase cloud functions & Angular.

npm version Codacy Badge

Installation

To use the library, install it via npm or yarn:

# To get the latest stable version in dependencies

$ npm install simplyfire --save

# Or

$ yarn add simplyfire

Usage


// in the firebase cloud functions

import * as admin from 'firebase-admin';
import * as functions from 'firebase-functions';
import { FirestoreCloudService, QueryBuilder } from 'simplyfire';

const fsService = FirestoreCloudService.getInstance(admin);

export const purgeUnusedUsers = functions.pubsub.schedule('every 24 hours').onRun(async () => {
  const qb = new QueryBuilder();
  qb.where('isEmailVerified', '==', false);
  qb.where('lastSignInTime', '<', new Date(Date.now() - 60 * 24 * 60 * 60 * 1000));

  return fsService.bulkDelete('users', qb);
});


// in the client (with Angular)

import { QueryBuilder } from 'simplyfire';
import { FirebaseService } from 'simplyfire/ngx';

@Injectable({
  providedIn: 'root'
})
export class UserService {

    constructor(private firebaseService: FirebaseService) {}

    async getUsers() {
        const qb = new QueryBuilder();
        qb.where('isEmailVerified', '==', true);
        qb.limit(20);

        qb.leftJoin('companyId', 'companies', 'company');
        qb.leftJoin('lastPostId', 'posts', 'post');

        return await this.firebaseService.collection(`users`, qb);
    }
}

Firestore API

APIDESCRIPTION
collection<T>(collection: string, qb?: QueryBuilder, maxAge?: number): Promise<T[]>Get documents from the firestore.
collectionGroup<T>(collectionId: string, qb?: QueryBuilder, maxAge?: number): Promise<T[]>Get documents from the firestore(collectionGroup).
collectionSnapshotChanges<T>(collection: string, qb?: QueryBuilder, events?: DocumentChangeType[]): Observable<T[]>Get documents from the firestore (Client only).
collectionValueChanges<T>(collection: string, qb?: QueryBuilder): Observable<T[]>Get documents from the firestore (Client only).
doc<T = any>(docPath: string, maxAge?: number): Promise<T>Get a document data from the firstore.
docValueChanges<T>(docPath: string): Observable<T>Get a document data from the firstore (Client only).
upsert(collection: string, data: { id?: string; [key: string]: any }, opts?: SetOptions): Promise<string>Insert/or update document. (If data includes id, it's an update operation, otherwise inserts a document)
update(docPath: string, data: { [key: string]: any }): Promise<void>Update a document. (The path must includes document id.)
delete(docPath: string): Promise<void>Delete a document.
bulkUpsert(collection: string, docs: DocumentData[], opts?: SetOptions): Promise<void>Upsert bulk documents. (batch writes)
bulkDelete(collection: string, qb?: QueryBuilder): Promise<number>Delete bulk documents. (batch deletes)
increment(n?: number): FieldValueFirestore Increment.
get batch(): WriteBatchGetter of Firestore batch.
get serverTimestamp(): FieldValueGetter of Firestore timestamp.

Keywords

FAQs

Last updated on 22 Oct 2022

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc