/firebless

Firebless allows you to create repositories from Firestore collections

Primary LanguageTypeScriptMIT LicenseMIT

Firebless

Build Status Npm Coverage Maintainability Vulnerabilities License

Firebless allows you to create repositories from Firestore collections. It providing basic methods such as detail, list, create, update, delete and more.

Install

npm i firebless

Basic usage

import { defaultFirestoreRepository, initFirestore } from 'firebless';

const db = initFirestore({/* todo */}); // or use custom instance

interface User {
  id?: string;
  name: string;
}
const userRepository = defaultFirestoreRepository.bind<User>(db.collection('users'));
// userRepository.detailById('123')
// userRepository.list({ name: 'Test' })
// ...

Custom repository

import { defaultFirestoreRepository, initFirestore } from 'firebless';

const db = initFirestore({/* todo */}); // or use custom instance

interface User {
  id?: string;
  name: string;
}
const userRepository = (defaultRepo => {
    const list = () => {
        // custom logic
        return defaultRepo.list({}, defaultRepo.getCollection().orderBy('name', 'asc'));
    };
    return {
        ...defaultRepo,
        list,
    };
})(defaultFirestoreRepository.bind<User>(db.collection('users')));

Examples

Debug

You need to set the NODE_DEBUG variable to the firebless.

Testing

npm t

npm run test:coverage

License

This project is licensed under MIT.