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

bgio-firebase

v0.5.0

Published

🔌 A Firebase database connector for boardgame.io

Downloads

9

Readme

bgio-firebase

NPM Version Test CI Status Coverage Status

🔌 A Firestore database connector for boardgame.io

This package provides a database connector that allows you to use a Firebase Cloud Firestore instance to store boardgame.io metadata and game state.

Installation

npm install --save bgio-firebase

Usage

This example shows one way to use the database connector when running your server on most Google infrastructure. For more details on configuring Firebase on your server, see the Firebase documentation.

const admin = require('firebase-admin');
const { Server } = require('boardgame.io/server');
const { Firestore } = require('bgio-firebase');
const { MyGame } = require('./game');

const database = new Firestore({
  config: {
    credential: admin.credential.applicationDefault(),
    databaseURL: 'https://<MY-PROJECT>.firebaseio.com',
  },
});

const server = Server({
  games: [MyGame],
  db: database,
});

server.run(8000);

Options

The Firestore class can be configured with an options object with the following properties.

app

  • type: string

If you are using multiple Firebase apps on your server, pass in the name of the app the Firestore connector should use.

config

  • type: admin.AppOptions

An options object to pass to the Firebase Admin SDK's initializeApp method. This configures your connection with Firebase. See the Firebase docs for details.

dbPrefix

  • type: string
  • default: 'bgio_'

Prefix for the boardgame.io collections within your Firebase project.

ignoreUndefinedProperties

  • type: boolean
  • default: true

By default, the Firestore instance’s settings method is called internally to avoid errors from undefined values in data from boardgame.io. settings can only be called once, so if you want to call it with your own custom options, you can pass false here to disable the internal call.

useCompositeIndexes

  • type: boolean
  • default: false

This connector tries to be as efficient as possible with minimal set-up, but due to Firestore’s query limitations, it cannot combine a date range query with other queries when listing matches without a composite index. By default, it will fall back to less efficient server-side filtering in these cases, potentially resulting in more database reads than necessary. You may wish to enable composite indexes if you use the boardgame.io Lobby API’s updatedAfter or updatedBefore queries when listing matches. See the Firestore docs for details on managing indexes.

Database structure

collection ID | document ID | contents -------------------------|-------------|------------------- {dbPrefix}metadata | {matchID} | match metadata {dbPrefix}state | {matchID} | game state {dbPrefix}initialState | {matchID} | initial game state {dbPrefix}log | {matchID} | game action logs

Contributing

Bug reports and pull requests are very welcome! I’m not a database expert or a Firebase expert or any kind of expert, so it’s very possible that there could be improvements to how the connector interfaces with Firebase. If you run into any problems or have questions, please open an issue.

Please also note the code of conduct and be kind to each other.

License

The code in this repository is provided under the MIT License.