firebase-definitions
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

Firebase Defintitions

Scheme in firebase (current: firestore only, planned: realtimedatabase and storage) can be preserved formatting json. This libary cache path information in an object and convert the path with inputted id and path completion.

Motivation

Regardless of string input will be easily trouble as increasingly using many times and many files by typo, missing configuration, ordered naming, it often cause many serious problem. This library goals to prevent input string data as possible, enable auto completion, and give handy recognition we have what or how many collection, subcollection or storage path by collection config in one place. No more missing db definitions.

Usage

  // ./exam[e.ts
  import {firebaseScheme} from 'firebase-definitions'

  const collections = {
    users: {
      private: {
        foo: {},
      },
      profiles: {
        posts: {}
      }
    }
  } as const

  export default firebaseScheme(collections)
  // ./usege.ts

  import collections from './example'
  import firebase from 'firebase'

  // as ever we write this like firebase.firestore().collection(`users/${userId}/profiles/${profileId}`)
  // it's easily cause you mistakes like spell miss or forgetting collections.

  firebase.firestore().collection(collections.users())

  firebase.firestore().doc(collections.users(userId).profiles.$id(profile.id))

  // you can write shortly case most deep collction
  firebase.firestore().doc(collections.users(userId).profiles(profile.id).posts(post.id))

  // completion is enabled by users and profiles, you can't miss spells or invalid input unless you have mistake in first configuration.

License

MIT

Package Sidebar

Install

npm i firebase-definitions

Weekly Downloads

8

Version

2.0.1

License

MIT

Unpacked Size

19.3 kB

Total Files

10

Last publish

Collaborators

  • tkow