BlueSpark
Firestore library for TypeScript using io-ts
Installation
yarn add firebase bluespark
Usage
import * as firebase from 'firebase'
import * as t from 'io-ts'
import { dayjs, blue, DayjsFromFirestoreTimestamp, FieldValue } from 'bluespark'
firebase.initializeApp({
apiKey: '### FIREBASE API KEY ###',
authDomain: '### FIREBASE AUTH DOMAIN ###',
projectId: '### CLOUD FIRESTORE PROJECT ID ###',
})
const db = firebase.firestore()
const posts = db.collection('posts')
const Post = blue(
t.type({
id: t.number,
date: t.union([DayjsFromFirestoreTimestamp, FieldValue]),
text: t.string,
tags: t.array(t.string),
}),
)
get
const post = await Post(posts.doc('doc-path')).get()
const post = await posts
.doc('doc-path')
.get()
.then(Post.ss)
set, setMerge, update
await Post(posts.doc('doc-path')).set({
id: 17,
date: dayjs(),
text: 'text',
tags: ['a', 'b'],
})