npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

firebase-orient

v1.0.3

Published

An object oriented firebase and firestore implementation

Downloads

10

Readme

Firebase Orient 1.0.0

Issues Firebase Orient is an object oriented implementation of Google's firebase and firestore database. Bias admission, the firestore models are made to simulate the behaviour of datastore models in python as much as possible.

Getting Started

Install firebase orient - npm install firebase-orient

At the entry of your application, set the firebase config as follows:

import {setUp} from "firebase-orient"

/**
 * @param {object} props                    Properties required to initialize firebase
 * @param {string} props.appID              The ID of your app usually appID.firebaseapp.com
 * @param {string} props.apiKey             Ofcourse firebase won't just let us connect to their servers like hippies
 * @param {bool}   props.google             If you have enabled google login, set this value to true
 */
setUp({
    appID: "<app_id>",
    apiKey: "<messagingSenderId>",
    google: <True | False>
})

Doing this setup means that you wont need to provide a firebase config every time you call the firebase class

The Firebase class

This class allows you to do various user management functions including: - login - registration - manage user session - upload files to firebase storage The class can be imported and initialized as follows:

import Firebase from "firebase-orient"

const firebase = new Firebase()

This can be done without any properties or you can choose to provide a config similar to the one in Getting Started section. An error will be thrown if you didn't setUp the application and fail to provide a config during initialization

Authentication

Firebase allows you to use several authentication methods including; Email and Password, Google, Github, Phone et cetera, et cetera. You can read further about firebase authentication here. This library however supports Google Auth and Email and Password Auth at the moment. You can still implement other authentication systems on your own by accessing the firebase auth variable directly as shown:

firebase.auth.onAuthStateChanged(user => console.log(user))

All authentication function returns a user object which documentation can be found here

However here are the simplified methods supported by this library:

Email and Password Auth

Registration:

firebase.auth_email_register("[email protected]", "Password").then(user => {
    console.log(user)
})

Login:

firebase.auth_email_signin("[email protected]", "Password").then(user => {
    console.log(user)
})

Google Auth

Google auth doesn't separate registration and login so you just:

firebase.auth_google_login().then(user => {
    console.log(user)
})

Authentication State

Often you need to know whether your user is still logged in or not. The function is called immediately with the current user, then incase of a change.

firebase.auth_state(user => {
    if(user){
        console.log(user)
    }else{
        // There's no user logged in, do something about it
    }
})

Storage

You can access firebase storage, upload files, track upload progress and get the download url The upload functions takes the following parameters:

  • path(String) The path to save the file relative to the bucket root including the filename
  • file(FileObject) A javascript binary file object from input of drop or other sources
  • task_id(any) An upload is a task, this will be used to track the progress
  • actions(Object.) All actions are called with the task_id as the first var
    • actions.pause Will be called if the upload is paused
    • actions.complete Will be called with the download link once the upload is done
    • actions.progress Will be called with progress value on progress update
    • actions.error Will be called with the error string if an error occurs

The function returns an upload task you can use to control the download.

const file = document.querySelector("#some-file-input").files[0]
firebase.upload("users/images/random.png", file, "upload1", {
    pause: task_id => {
        console.log("Task paused", task_id)
    },
    complete: (task_id, download_url) => {
        console.log("File upload done", download_url)
    }
})

Actions functions are nullable, you however shouldn't null the on complete functions

The FireStore class

This is an extension of Firestore that IMO makes it feel more database like

To create a model simply do:

import {db} from "firebase-orient"

class User extends db.Model {
    constructor(name, email){
        super({
            name: db.stringField(),
            email: db.stringField(),
            height: db.numberField({default: 5.1}),
            date_registered: db.datetimeField(),
            interests: db.listField(),
            contact: db.objectField(),
        })
        this.name = name
        this.email = email
    }
}

class Session extends db.Model {
    constructor(){
        super({
            user: db.refferenceField(User),
            start: db.datetimeField()
        })
    }
}

NB:

  • You must define fields in a super call in your constructor
  • If a field is not defined then it won't be submitted on put

You can then proceed to use your models as shown:

const user = new User("Some Name", "[email protected]")
user.put()

const session = new Session()
session.user = user
session.start = db.currentTimestamp()

Release Notes:

  • v1.0.1
    • Fixed bugs on model referencing
  • v1.0.2
    • Fixed error on getting models
    • Fixed errors on saving updated models
  • v1.0.3
    • Enforced model name provision to prevent webpack overwrite