0.5.5 • Published 2 years ago

simplyfire v0.5.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

simplyfire

A lightweight firestore api for firebase cloud functions & Angular.

npm.io 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.
0.5.5

2 years ago

0.3.17

2 years ago

0.3.16

2 years ago

0.3.15

2 years ago

0.3.14

2 years ago

0.5.4-beta.0

2 years ago

0.5.3-beta.0

2 years ago

0.5.3-beta.1

2 years ago

0.5.4

2 years ago

0.5.3

2 years ago

0.5.0

2 years ago

0.5.2

2 years ago

0.5.1

2 years ago

0.4.2-beta.0

2 years ago

0.3.13

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.12

2 years ago

0.3.11

2 years ago

0.3.10

3 years ago

0.3.9

3 years ago

0.3.8

3 years ago

0.3.7

3 years ago

0.3.6

3 years ago

0.3.5

3 years ago

0.3.0

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.3.4

3 years ago

0.3.3

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago