firestore-wrapper
TypeScript icon, indicating that this package has built-in type declarations

0.1.8 • Public • Published

Purpose

typescript helps to avoid numerous errors at development time and for sure firebase is one of the most used tools among developers, be it for mobile, web projects and etc.

The biggest problem is that we have to force data types when we access them through the firebase and this can cause numerous errors.

The firestore-wrapper has the purpose of facilitating and speeding up the life of the developer, being necessary to type your database only once.

How to use

1) Describe your database

In some file, describe your database using a typescript, look like this:

export interface Database {
    User: {[user_id: string]: User};
    Locations: {[location_name: string]: Locations};
}

interface User {
    name: string,
    email: string,
    nick: string
}

interface Locations {
    latitude: number;
    longitude: number;
    single: string;
}

2) Initialize your firebase-admin and associate with wapper

import * as firebase from "firebase-admin";
import Credentials from "../Credentials.json";
import { root } from "firestore-wrapper";
import databaseSchema from './database';

const firebaseSdk = firebase.initializeApp({
    credential: firebase.credential.cert(Credentials as firebase.ServiceAccount),
    databaseURL: "https://any-project.firebaseio.com"  
});

const db = root<databaseSchema>(firebaseSdk.firestore() as any);

3) Now, all firestore functions is typing with your database schema

While you access your database, the wrapper indicates if the path is right

Specs

When you retrieve data, he cames with right type

Specs

Even inside transactions, you keep the types

Specs

Package Sidebar

Install

npm i firestore-wrapper

Weekly Downloads

0

Version

0.1.8

License

ISC

Unpacked Size

8.7 kB

Total Files

8

Last publish

Collaborators

  • leonbonetti