Skip to content

Commit df35c1b

Browse files
authoredApr 27, 2020
fix: onCreate, onUpdate and onDelete receive a DocumentQuerySnapshopt (#670)
The arguments of Firestore triggers `onCreate`, `onUpdate` and `onDelete` cannot have an undefined data by definition, so we changed the arguments of those handlers to reflect that by using DocumentQuerySnapshot. fixes #659
1 parent 1dde3db commit df35c1b

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed
 

‎src/providers/firestore.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const service = 'firestore.googleapis.com';
4242
export const defaultDatabase = '(default)';
4343
let firestoreInstance: any;
4444
export type DocumentSnapshot = firebase.firestore.DocumentSnapshot;
45+
export type QueryDocumentSnapshot = firebase.firestore.QueryDocumentSnapshot;
4546

4647
/**
4748
* Select the Firestore document to listen to for events.
@@ -204,30 +205,30 @@ export class DocumentBuilder {
204205
/** Respond only to document updates. */
205206
onUpdate(
206207
handler: (
207-
change: Change<DocumentSnapshot>,
208+
change: Change<QueryDocumentSnapshot>,
208209
context: EventContext
209210
) => PromiseLike<any> | any
210-
): CloudFunction<Change<DocumentSnapshot>> {
211+
): CloudFunction<Change<QueryDocumentSnapshot>> {
211212
return this.onOperation(handler, 'document.update', changeConstructor);
212213
}
213214

214215
/** Respond only to document creations. */
215216
onCreate(
216217
handler: (
217-
snapshot: DocumentSnapshot,
218+
snapshot: QueryDocumentSnapshot,
218219
context: EventContext
219220
) => PromiseLike<any> | any
220-
): CloudFunction<DocumentSnapshot> {
221+
): CloudFunction<QueryDocumentSnapshot> {
221222
return this.onOperation(handler, 'document.create', snapshotConstructor);
222223
}
223224

224225
/** Respond only to document deletions. */
225226
onDelete(
226227
handler: (
227-
snapshot: DocumentSnapshot,
228+
snapshot: QueryDocumentSnapshot,
228229
context: EventContext
229230
) => PromiseLike<any> | any
230-
): CloudFunction<DocumentSnapshot> {
231+
): CloudFunction<QueryDocumentSnapshot> {
231232
return this.onOperation(
232233
handler,
233234
'document.delete',

0 commit comments

Comments
 (0)
Please sign in to comment.