Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/coturiv/simplyfire
A lightweight firestore wrapper for the firebase cloud functions & Angular apps.
https://github.com/coturiv/simplyfire
angular firebase firestore
Last synced: about 13 hours ago
JSON representation
A lightweight firestore wrapper for the firebase cloud functions & Angular apps.
- Host: GitHub
- URL: https://github.com/coturiv/simplyfire
- Owner: coturiv
- License: mit
- Created: 2021-08-21T01:41:40.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-10-22T18:38:15.000Z (about 2 years ago)
- Last Synced: 2024-10-13T01:20:04.152Z (about 1 month ago)
- Topics: angular, firebase, firestore
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/simplyfire
- Size: 1.18 MB
- Stars: 4
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# simplyfire
A lightweight firestore api for firebase cloud functions & Angular.
![](https://github.com/coturiv/simplyfire/workflows/Build/badge.svg)
[![npm version](https://img.shields.io/npm/v/simplyfire.svg)](https://www.npmjs.com/package/simplyfire)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/59e264bce65b40e2b019edcdee9509f2)](https://www.codacy.com/gh/coturiv/simplyfire/dashboard?utm_source=github.com&utm_medium=referral&utm_content=coturiv/simplyfire&utm_campaign=Badge_Grade)## Installation
To use the library, install it via `npm` or `yarn`:
```bash
# 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
| API | DESCRIPTION |
| ------ | ------ |
| `collection(collection: string, qb?: QueryBuilder, maxAge?: number): Promise` | Get documents from the firestore. |
| `collectionGroup(collectionId: string, qb?: QueryBuilder, maxAge?: number): Promise` | Get documents from the firestore(collectionGroup). |
| `collectionSnapshotChanges(collection: string, qb?: QueryBuilder, events?: DocumentChangeType[]): Observable` | Get documents from the firestore (*Client only*). |
| `collectionValueChanges(collection: string, qb?: QueryBuilder): Observable` | Get documents from the firestore (*Client only*). |
| `doc(docPath: string, maxAge?: number): Promise` | Get a document data from the firstore. |
| `docValueChanges(docPath: string): Observable` | Get a document data from the firstore (*Client only*). |
| `upsert(collection: string, data: { id?: string; [key: string]: any }, opts?: SetOptions): Promise` | 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` | Update a document. (The `path` must includes document `id`.) |
| `delete(docPath: string): Promise` | Delete a document. |
| `bulkUpsert(collection: string, docs: DocumentData[], opts?: SetOptions): Promise` | Upsert bulk documents. (`batch` writes) |
| `bulkDelete(collection: string, qb?: QueryBuilder): Promise` | Delete bulk documents. (`batch` deletes) |
| `increment(n?: number): FieldValue` | Firestore Increment. |
| `get batch(): WriteBatch` | Getter of Firestore batch. |
| `get serverTimestamp(): FieldValue` | Getter of Firestore timestamp. |