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

@ternwebdesign/firebase-store

v0.2.6

Published

Use the FirebaseStoreService to generate an out-of-the-box CRUD-service on top off the `@angular/fire` collection module.

Downloads

12

Readme

FirebaseStore

Use the FirebaseStoreService to generate an out-of-the-box CRUD-service on top off the @angular/fire collection module.

Installation

npm install @ternwebdesign/firebase-store

This library is dependent on firebase and @Angular/fire libraries.

Use the angular fire quickstart to set up firebase to your angular project.

Usage

First make sure @angular/fire is initialized. Create a new service and extend that service with the FirebaseStoreService. Add the model you want to store in a firebase collection as generic type. Next inject the AngularFirestore into this service. Use this to add a firebase collection to the parent using the this.setCollection() method in the constructor of the service.

import { Injectable } from '@angular/core';
import { FirebaseStoreService } from '@ternwebdesign/firebase-store';
import { Model } from '../models/model.model';
import { AngularFirestore } from '@angular/fire/firestore';

@Injectable({
  providedIn: 'root'
})
export class ModelService extends FirebaseStoreService<Model> {

  constructor(private db: AngularFirestore) {
    super();
    this.setCollection(db.collection<Model>('Model'));
  }
}

What do you get

Get

service.get('ID');

Using this method it is possible to get a specific document from the collection using the specified id. All methods are developed to add the firebase identifier to the id-property of the model. So you can just use model.id to get the id that is used as an argument in this method.

GetAll

service.getAll();

Use the getAll method to get all documents from the collection.

Add

service.add(model: Model);

Adds the new document to the collection. Returns the document including the new id. It is not possible to prefill the id property when adding the model to the collection. Therefore the id property will always be deleted before uploading the model to the collection.

Update

service.update(model: Model);

Updates the model in the firestore collection. Returns the document.

Delete

service.delete(model: Model);

Deletes model from the collection. Returns empty observable.

ConvertItem

protected convertItem(item: any): Model {
    return convertYourItemHere();
}

All items are converted using the convertItem method of the FirebaseStoreService. The only thing this initially does is return the same item, but you are able to overwrite this method in your class using above example. Use this for example to convert strings to dates or any other conversion you need to convert your backend model to something you can use in the frontend.

Using a sub-collection

import { Injectable } from '@angular/core';
import { FirebaseStoreService } from '@ternwebdesign/firebase-store';
import { Model } from '../models/model.model';
import { Parent } from '../models/parent.model';
import { AngularFirestore } from '@angular/fire/firestore';
import { ParentCollectionService } from '../core/parent-collection.service';

@Injectable({
  providedIn: 'root'
})
export class ModelService extends FirebaseStoreService<Model> {

  constructor(private db: AngularFirestore, 
              private parentCollectionService: ParentCollectionService) {
    super();
    this.parentCollectionService.selected()
        .subscribe(selectedId => !!selectedId ?
            this.setCollection(db.doc<Parent>(`Parent/${selectedId}`).collection<Model>('Model')) :
            this.setCollection(null))
  }
}

Getting a sub-collection is slightly more tricky since a sub-collection needs the doc/id of the specific parent. Somehow get the id of the parent collection and use this to get the sub-collection. Above you find an example of how we are getting the sub-collection for a selectedId from the parent collection It is only possible to add one collection to a service.

Extending the service

This service just adds the basic CRUD methods to your service. If you need anything else (query's for example) just use the AngularFirestore in you service to add any method you like on top of the existing methods. If you need a different implementation of a method, just overwrite the parents method and implement your own.