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

firestore-plus

v1.1.1

Published

Additional firestore functionality

Downloads

14

Readme

Firestore+

npm install --save `firebase-plus`

Firestore+ is an unofficial extension to firebase that adds features such as schema validation, optional deep population (soon), plugins, and more(?)

Warning: This package is experimental and still in alpha testing. It's only currently tested with firebase@^5.8.5

Installation

npm install --save 'firebase-plus'
# or 
yarn add 'firebase-plus'

If you're using schema validation, you might also want to install yup. Using a custom validator is a feature coming soon.

Usage

This package mainly works by wrapping existing firestore components such as DocumentReference.

See the wiki for full(er) documenation.

import firebase from 'firebase/app' // this package also works with firebase-admin
import 'firebase/firestore'

// Import FirestorePlus, the included plugins, and the Schema class
import FirestorePlus, { plugins } from 'firestore-plus'

const fPlus = FirestorePlus(firebase)

// Initialize Schema plugin
const schema = new plugins.Schema(/* options */, { autoValidate : true })

// Add schema plugin to fPlus instance
fPlus.use(schema)
// or
firebase.firestore().plus(schema)

// Do other things with plugins. Ex: Creating a Schema

import * as yup from 'yup' // import yup validator

const userSchemaDefinition = {
    // Basic validation
    fullName : yup.string(),

    // With options
    age : {
        type : yup.number(),
        default : 18,
        required : true
    }
    // Using validator's options if supported (may cause issues)
    picture : yup.string.default('some-default-image.jpg').required(),
}

// Register the schema to a collection
const UserSchema = schema.model('mycollection', userSchemaDefinition)
// or
const UserSchema = firebase.firestore().plus().schema('myCollection', userSchemaDefinition)

A note about the schema plugin

If autoValidate is set to True, the schema will be automatically validated whenever functions that set or retrieve data are called. If the document fails validation, a big obnoxious error will be thrown.

For example:

firebase.firestore().doc(`path/to/doc/${id}`).get().then( snap => snap.data())
firebase.firestore().doc(`path/to/doc/${id}`).set({ /* some data */})
firebase.firestore().doc(`path/to/doc/${id}`).update({ /* some data */})

Validation can also be done manually by calling the schema's validate method directly

try {
    UserSchema.validate({/* some datat */ })
    console.log(":)") // successfully validated
} catch(error){
    console.log(":(") // validation failed
}

TODO Before 1.1.0 release

  • Custom Validator