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

@tjbroodryk/firefetch

v1.0.2

Published

Non-observable wrapper to fetch data from firebase

Downloads

7

Readme

FireFetch

A Promise-based Library for fetching data from firebase. Especially useful for when you have firebase queries that depend on the result of other queries, and you dont want to use all of RxJS' might.

Install

npm install -s @tjbroodryk/firefetch

Usage

More documentation can be seen in the docs directory

Import the package

import firefetch from '@tjbroodryk/firefetch'

Initialisation

Can be done in two ways:

import * as firebase from 'firebase';

firebase.initializeApp(config.default)

firefetch.init(firebase)

which uses an exisitng firebase instance

or

firefetch.init({    
    apiKey: <apikey>,
    authDomain: <authdomain>,
    databaseURL: <databaseurl>,
    projectId: <projectid>,
    storageBucket: <storagebucket>,
    messagingSenderId: <messagesenderid>
})

which creates a firebase instance (if none exisits) using the specified config

Base Path

You can specify a base path which gets prepended onto each query

firefetch.base('flamelink/environments/production/content/')

Querying

Basic, array query

firefetch.fetch('blogSlugs/en-US/', true).now().then(res => {
    const resultArray = res.array()
    //do something with result
})

Basic, single query

firefetch.fetch('blogSlugs/en-US/three-trends-transforming-local-marketing-online').now().then(res => {
    const resultObject = res.single()
    //do something with result
})

Query that filters by where methods

firefetch.fetch('blogSlugs/en-US/', true)
    .where(item => item.key() == 'three-trends-transforming-local-marketing-online')
    .where(item => item.val() == '1526560224416')
    .now()
    .then(res => {
        const resArray = res.array()
    })

Query that uses the first queries result for the second query, and then filters the second query using the where method

firefetch.fetch('blogSlugs/en-US/', true)
    .next(item => `blog/en-US/${item.val()}`, true)
    .where(elem => elem.val() != null && elem.val().postStatus == 'publish')
    .now()
    .then(res => {
        const resArray = res.array()
    })

Query utlising all availible methods

firefetch.fetch('blogSlugs/en-US/', true)
    .next(item => `blog/en-US/${item.val()}`, true)
    .where(elem => elem.val() != null && elem.val().postStatus == 'publish')
    .each(item => {
        console.log(`key : ${item.key()}, value : ${item.val()}`)
    })
    .map(item => {
        const val = item.val()
        val.postTitle = val.postTitle.toUpperCase()
        return new ResultValue(item.key(), val)
    })
    .now()
    .then(res => {
        const resArray = res.array()
        //do something
    })

A couple things to note

  • fetch() is allways the first method in the chain.
  • No query is executed until the now() method is called.
  • All other methods such as map(), where(), etc return an instance of AnyQuery which allows you to chain them infinitely.
  • If the result of your query is expected to be an array, use fetch(<path>, true) or next(<path>, true) - the boolean parameter tells the library whether or not to convert the firebase "array" to an actual array. The default for the param is false.
  • Because the now() method returns a promise, you can use async.

Testing

Clone the repo and run:

npm run test

The current tests use an actual firebase rtdb, so the credentials are obviously not uploaded to github.

Testing - TODO

  • Use mock firebase rtdb for unit tests

Authors

  • Tj Broodryk

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details