Fire Entity
Fire Entity is a JavaScript library for storing and retrieving JSON documents from
Firebase and caching them locally to reduce quota usage.
Installation
Use npm or yarn to install Fire Entity.
npm i -S fire-entity
yarn add fire-entity
Usage
import {Entity, EntityFireStore} from 'fire-entity';
import {firestore} from 'firebase/app';
import 'firebase/firestore';
const entityStore = new EntityFireStore(firestore(), {setOwner: true});
const entity: Entity = {
name: 'Entity A',
type: 'entities',
};
entityStore.insert(entity);
Instantiating an EntityStore, as shown above, is all you need in order to store and retrieve data from Firebase.
Querying entities
import {Entity, EntityFireStore} from 'fire-entity';
import {firestore} from 'firebase/app';
import 'firebase/firestore';
const entityStore = new EntityFireStore(firestore(), {setOwner: true});
entityStore.selectAll('collectionPath').then(entities => console.log(entities));
entityStore.selectWhere(
'collectionPath',
[{prop: 'age', op: '>', val: 20}]
).then(entities => console.log(entities));
Listening for entity changes
import {Entity, EntityFireStore} from 'fire-entity';
import {firestore} from 'firebase/app';
import 'firebase/firestore';
const entityStore = new EntityFireStore(firestore(), {setOwner: true});
entityStore.listenAll('collectionPath').subscribe(entities => console.log(entities));
entityStore.listenWhere(
'collectionPath',
[{prop: 'age', op: '>', val: 20}]
).subscribe(entities => console.log(entities));
Roadmap
[x] implement Firestore backend
[ ] implement local caching via IndexedDB
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
License
MIT