Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ya-s-u/typesafe-functions
A library of typescript interfaces that extend existing firebase functions classes, adding type safety and a better autocomplete experience.
https://github.com/ya-s-u/typesafe-functions
firebase firebase-functions firestore typescript
Last synced: about 1 month ago
JSON representation
A library of typescript interfaces that extend existing firebase functions classes, adding type safety and a better autocomplete experience.
- Host: GitHub
- URL: https://github.com/ya-s-u/typesafe-functions
- Owner: ya-s-u
- License: mit
- Created: 2020-12-09T21:37:34.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2020-12-09T22:13:43.000Z (almost 4 years ago)
- Last Synced: 2024-09-28T17:01:47.179Z (about 2 months ago)
- Topics: firebase, firebase-functions, firestore, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/typesafe-functions
- Size: 30.3 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# typesafe-functions
[![npm version](https://badge.fury.io/js/typesafe-functions.svg)](https://badge.fury.io/js/typesafe-functions)
A library of typescript interfaces that extend existing firebase functions classes, adding type safety and a better autocomplete experience.
Depends on [typesafe-node-firestore](https://github.com/mozilla-fxa/typesafe-node-firestore).
## Installation
```shell
yarn add typesafe-functions --dev
```## Usage
You most likely want to import `TypedDocumentBuilder` and define functions document.
```typescript
import * as functions from 'firebase-functions';
import { TypedDocumentBuilder } from 'typesafe-functions';interface Author {
penName: string;
shortBiography: string;
posts: string[];
};interface Params {
authorId: string;
};const document = functions.firestore.document('authors/{authorId}') as TypedDocumentBuilder;
```And trigger your typesafe firestore events.
```typescript
document.onWrite((change, context) => {
console.log(change.before.data()) //=> Author | undefined
console.log(change.after.data()) //=> Author | undefined
console.log(context.params.authorId) //=> string
});document.onChange((change, context) => {
console.log(change.before.data()) //=> Author | undefined
console.log(change.after.data()) //=> Author | undefined
console.log(context.params.authorId) //=> string
});document.onWrite((snapshot, context) => {
console.log(snapshot.data()) //=> Author
console.log(context.params.authorId) //=> string
});document.onDelete((snapshot, context) => {
console.log(snapshot.data()) //=> Author
console.log(context.params.authorId) //=> string
});
```### License
typesafe-functions is [MIT licensed](./LICENSE).