Type-safe Firestore triggers
npm install typed-ffType-safe Firestore Triggers using typesaurus.
``sh`typed-ff depends on typesaurus
yarn add typed-ff typesaurus
`ts
import { onCreate, onDelete, onUpdate, onWrite } from "typed-ff"
import { collection } from "typesaurus"
type User = { name: string }
const users = collection
export const onCreateUser = onCreate(users, (doc, context) => {
doc // => Doc
})
export const onDeleteUser = onDelete(users, (doc, context) => {
doc // => Doc
})
export const onUpdateUser = onUpdate(users, ({ before, after }, context) => {
before // => Doc
after // => Doc
})
export const onWriteUser = onWrite(users, ({ before, after }, context) => {
before // => Doc
after // => Doc
})
`
`ts
import { onCreate } from "typed-ff"
import { collection, ref } from "typesaurus"
type User = { name: string }
const users = collection
const yuiki = ref(users, "yuiki")
export const onCreateUser = onCreate(yuiki, (doc, context) => {
doc // => Doc
})
`
`ts
import { onCreate } from "typed-ff"
import { collection, ref, subcollection } from "typesaurus"
type User = { name: string }
type Post = { text: string }
const users = collection
const posts = subcollection
// You should specify "{parentId}" to use a wildcard and avoid "{id}"
export const onCreateUser = onCreate(posts("{userId}"), (doc, context) => {
doc // => Doc
})
``
- [ ] Add documents
- [ ] Add tests