Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bluespark

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bluespark

> Firestore library for TypeScript using io-ts

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by50%
Maintainers
1
Weekly downloads
 
Created
Source

𝘉𝘭𝘶𝘦𝘚𝘱𝘢𝘳𝘬

Firestore library for TypeScript using io-ts

Installation

yarn add firebase bluespark

Usage

import firebase from 'firebase'
import { Blue, Spark } from 'bluespark'

const app = firebase.initializeApp({
    apiKey: '### FIREBASE API KEY ###',
    authDomain: '### FIREBASE AUTH DOMAIN ###',
    projectId: '### CLOUD FIRESTORE PROJECT ID ###',
})

const db = app.firestore()

// Schema

type IPost = {
    id: number
    date: Dayjs | Blue.FieldValue
    text: string
    tags: string[]
    user: Blue.DocReference
}

const Post = Spark<IPost>('posts', {
    // automatically convert `Dayjs` object to `Date` on write
    encoder: deepConvert<dayjs.Dayjs, Date>(dayjs.isDayjs, a => a.toDate()),

    // automatically convert `Timestamp` to `Dayjs` on read
    decoder: deepConvert<Blue.Timestamp, dayjs.Dayjs>(isTimestamp, a =>
        dayjs(a.toDate()),
    ),
})

// equivalent to `db.collection('posts')`
const postCl = Post.collectionWithin(db)

get

const postRef = postCl.doc('doc-path')

const post = await Post.ref(postRef).get()
/* {
    id: number
    date: Dayjs
    text: string
    tags: string[]
    user: Blue.DocReference
} */

// from snapshot
const post = await postRef.get().then(Post.snap)

set, setMerge, update

const postRef = postCl.doc('doc-path')

await Post.ref(postRef).set({
    id: 17,
    date: dayjs(),
    text: 'text',
    tags: ['a', 'b'],
})

FAQs

Package last updated on 09 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc