https://github.com/kessler/firebase-events
https://github.com/kessler/firebase-events
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/kessler/firebase-events
- Owner: kessler
- Created: 2024-02-16T13:22:13.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-16T16:59:54.000Z (about 1 year ago)
- Last Synced: 2025-03-08T08:12:40.035Z (about 2 months ago)
- Language: JavaScript
- Size: 22.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# firebase-events
A simple library to send events to firestore database
## general usage
```js
const { open } = require('@kessler/firebase-events')
const { onRequest } = require('firebase-functions/v2/https')
const logger = require('firebase-functions/logger')exports.helloWorld = onRequest((req, res) => {
const { newEvent, updateEvent } = await open('events')
const startEvent = newEvent('start', { functionName: 'helloWorld', type: 'start'})logger.info('Hello logs!', { structuredData: true })
updateEvent(startEvent, { type: 'end' })
})```
## timer
```js
const { open } = require('@kessler/firebase-events')
const { onRequest } = require('firebase-functions/v2/https')
const logger = require('firebase-functions/logger')exports.helloWorld = onRequest(async (req, res) => {
const { timer } = await open()
const timerEvent = timer('function_duration', { fnName: 'helloWorld2' })
logger.info('Hello logs!', { structuredData: true })
await timerEvent.send()
})```
1. enable firestore database in your firebase project
2. npm install @kessler/firebase-events
3. update your function code
4. deploy your function