gpt4 book ai didi

node.js - Firestore 触发的云功能参数的类型?

转载 作者:行者123 更新时间:2023-12-05 00:45:30 26 4
gpt4 key购买 nike

以下是 Firestore 云功能的可用触发器:

https://firebase.google.com/docs/firestore/extend-with-functions

onCreate

functions.firestore
.document('my-collection/{doc-id}')
.onCreate((snap, context) => { /* ... */ });

onDelete

functions.firestore
.document('my-collection/{doc-id}')
.onDelete((snap, context) => { /* ... */ });

onUpdate

functions.firestore
.document('my-collection/{doc-id}')
.onUpdate((change, context) => { /* ... */ });

onWrite

functions.firestore
.document('my-collection/{doc-id}')
.onWrite((change, context) => { /* ... */ });

我正在将我的项目转换为 Typescript。我应该为参数 change contextsnap 使用什么类型?

最佳答案

以下是类型:

onCreate:

snapshot: FirebaseFirestore.QueryDocumentSnapshot
context: functions.EventContext

onDelete:

snapshot: FirebaseFirestore.QueryDocumentSnapshot
context: functions.EventContext

onUpdate:

change: functions.Change<FirebaseFirestore.QueryDocumentSnapshot>
context: functions.EventContext

onWrite:

change: functions.Change<FirebaseFirestore.DocumentSnapshot>
context: functions.EventContext

更多详情 herehere在文档中。


如果你使用 Typescript,你会像这样导入/使用:

import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'
...

export const fnSomeCollectionTriggerOnUpdate =
functions.firestore.document('somecollection/{docId}')
.onUpdate(async (change: functions.Change<admin.firestore.QueryDocumentSnapshot>,
context: functions.EventContext) => {
...
}

关于node.js - Firestore 触发的云功能参数的类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63449156/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com