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 🙏

© 2024 – Pkg Stats / Ryan Hefner

fastfire

v0.3.28

Published

<div align="center"> <h1>FastFire🔥</h1> <a href="https://www.npmjs.com/package/fastfire"><img src="https://img.shields.io/npm/v/fastfire.svg?style=flat" /></a>

Downloads

5

Readme

$ npm install --save fastfire
or
$ yarn add fastfire

⚠WIP⚠

What is FastFire?

FastFire is the Firestore ORM library for quick and easy development written in TypeScript.

Just define a FastFireDocument class and FastFire will take care of all the hassle of implementing things like storing and retrieving data, mapping to instances, and more.

It also enables more rapid development by implementing business logic within the FastFireDocument class. Yes, this is the Active Record pattern.

FastFire is strongly inspired by ActiveRecord.

(Of course, this is type safe in various situations)

Getting started

Setup FastFire

Setup Firebase config and call FastFire.initialize method with firestore instance.

import firebase from 'firebase';

const firebaseConfig = {
  apiKey: process.env.apiKey,
  authDomain: process.env.authDomain,
  projectId: process.env.projectId,
  storageBucket: process.env.storageBucket,
  messagingSenderId: process.env.messagingSenderId,
  appId: process.env.appId,
};
firebase.initializeApp(firebaseConfig);

FastFire.initialize(firebase.firestore());

Define FastFireDocument

Define a class to treat as a Firebase document and extends FastFireDocument in that class.

@FastFireCollection("User")
class User extends FastFireDocument<User> {
  // You need to write `FastFireField` decorator on the Firestore document field props.
  @FastFireField()
  name!: string
  @FastFireField()
  bio!: string
}

@FastFireCollection("Article")
class Article extends FastFireDocument<Article> {
  @FastFireField()
  title!: string
  @FastFireField()
  body!: string

  // You need to write `FastFireReference` decorator on the Firestore Reference Type document field props.
  @FastFireReference(User)
  author!: User
}

Create a Document

const user = await FastFire.create(User, {
  name: "tockn", // type safe!🔥
  bio: "hello world!" // type safe!🔥
})

Fetch Document

  • By document id
const user = await FastFire.findById(User, "AKDV23DI97CKUQAM")
  • Using query
const users = await FastFire.where(User, "name", "==", "tockn")
                      .where("bio", "==", "hello world!")
                      .limit(1)
                      .get()

Update or Delete Document

const user = await FastFire.findById(User, "AKDV23DI97CKUQAM")

await user.update({ name: "Ohtani-San" })

await user.delete()

Reference Type and Preloading

Create a document with Reference Type field.

const user = await FastFire.findById(User, "AKDV23DI97CKUQAM")

await FastFire.create(Article, {
  title: "big fly!",
  body: "suwatte kuda sai",
  author: user // author is Reference Type field
})

Reference Type field can be preloaded asynchronously by using the preload method.

// preload author field asynchronously.
const articles = await FastFire.preload(Article, ["author"]).where("title", "==", "big fly!").get()

articles.forEach((article) => {
  // Because it is preloaded, you can get the author's name
  console.log(article.author.name) // => tockn
})

Get realtime updates

You can get document updates in realtime.

const user = await FastFire.findById(User, "AKDV23DI97CKUQAM")

user.onChange((updatedUser) => {
  console.log(updatedUser)
})

You can also get changes in query results in real time.

const users = await FastFire.where(User, "name", "==", "tockn").where("bio", "==", "hello world!")

users.onResultChange((updatedUsers) => {
  console.log(updatedUsers)
})

Validation

You can implement validations using the argument of FastFireField decorator.

  • Required Field Validation
@FastFireCollection("User")
class User extends FastFireDocument<User> {
  @FastFireField({ required: true} )
  name!: string
  @FastFireField()
  bio!: string
}

await FastFire.create(User, { bio: "hello" }) // DocumentValidationError: "User" body: name is required.
  • Custom Validation
@FastFireCollection("User")
class User extends FastFireDocument<User> {
  @FastFireField({ validate: User.validateName })
  name!: string
  
  static validateName(name: string): ValidationResult {
    if (name.length > 100) return "name is too long!"
  }
}

await FastFire.create(User, { bio: "hello" }) // DocumentValidationError: "User" name: name is too long!