0.8.1 • Published 4 years ago

fire-entity v0.8.1

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

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});

// Retrieving all documents from a collection
entityStore.selectAll('collectionPath').then(entities => console.log(entities));

// Retrieving a subset of documents from a collection
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});

// Listening for changes to all documents from a collection
entityStore.listenAll('collectionPath').subscribe(entities => console.log(entities));

// Listening for changes to a subset of documents from a collection
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

0.8.1

4 years ago

0.8.0

4 years ago

0.7.2

4 years ago

0.7.1

4 years ago

0.7.0

4 years ago

0.6.0

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.1

5 years ago