@@ -64,7 +64,7 @@ export interface RawFirestoreData {
6464}
6565
6666/** @internal */
67- export interface RawFirestoreEvent extends CloudEvent < Uint8Array | RawFirestoreData > {
67+ export interface RawFirestoreEvent extends CloudEvent < Uint8Array | RawFirestoreData | undefined > {
6868 location : string ;
6969 project : string ;
7070 database : string ;
@@ -119,9 +119,9 @@ export interface DocumentOptions<Document extends string = string> extends Event
119119export function onDocumentWritten < Document extends string > (
120120 document : Document ,
121121 handler : (
122- event : FirestoreEvent < Change < DocumentSnapshot > , ParamsOf < Document > >
122+ event : FirestoreEvent < Change < DocumentSnapshot > | undefined , ParamsOf < Document > >
123123 ) => any | Promise < any >
124- ) : CloudFunction < FirestoreEvent < Change < DocumentSnapshot > , ParamsOf < Document > > > ;
124+ ) : CloudFunction < FirestoreEvent < Change < DocumentSnapshot > | undefined , ParamsOf < Document > > > ;
125125
126126/**
127127 * Event handler which triggers when a document is created, updated, or deleted in Firestore.
@@ -132,9 +132,9 @@ export function onDocumentWritten<Document extends string>(
132132export function onDocumentWritten < Document extends string > (
133133 opts : DocumentOptions < Document > ,
134134 handler : (
135- event : FirestoreEvent < Change < DocumentSnapshot > , ParamsOf < Document > >
135+ event : FirestoreEvent < Change < DocumentSnapshot > | undefined , ParamsOf < Document > >
136136 ) => any | Promise < any >
137- ) : CloudFunction < FirestoreEvent < Change < DocumentSnapshot > , ParamsOf < Document > > > ;
137+ ) : CloudFunction < FirestoreEvent < Change < DocumentSnapshot > | undefined , ParamsOf < Document > > > ;
138138
139139/**
140140 * Event handler which triggers when a document is created, updated, or deleted in Firestore.
@@ -145,9 +145,9 @@ export function onDocumentWritten<Document extends string>(
145145export function onDocumentWritten < Document extends string > (
146146 documentOrOpts : Document | DocumentOptions < Document > ,
147147 handler : (
148- event : FirestoreEvent < Change < DocumentSnapshot > , ParamsOf < Document > >
148+ event : FirestoreEvent < Change < DocumentSnapshot > | undefined , ParamsOf < Document > >
149149 ) => any | Promise < any >
150- ) : CloudFunction < FirestoreEvent < Change < DocumentSnapshot > , ParamsOf < Document > > > {
150+ ) : CloudFunction < FirestoreEvent < Change < DocumentSnapshot > | undefined , ParamsOf < Document > > > {
151151 return onChangedOperation ( writtenEventType , documentOrOpts , handler ) ;
152152}
153153
@@ -159,8 +159,10 @@ export function onDocumentWritten<Document extends string>(
159159 */
160160export function onDocumentCreated < Document extends string > (
161161 document : Document ,
162- handler : ( event : FirestoreEvent < QueryDocumentSnapshot , ParamsOf < Document > > ) => any | Promise < any >
163- ) : CloudFunction < FirestoreEvent < QueryDocumentSnapshot , ParamsOf < Document > > > ;
162+ handler : (
163+ event : FirestoreEvent < QueryDocumentSnapshot | undefined , ParamsOf < Document > >
164+ ) => any | Promise < any >
165+ ) : CloudFunction < FirestoreEvent < QueryDocumentSnapshot | undefined , ParamsOf < Document > > > ;
164166
165167/**
166168 * Event handler which triggers when a document is created in Firestore.
@@ -170,8 +172,10 @@ export function onDocumentCreated<Document extends string>(
170172 */
171173export function onDocumentCreated < Document extends string > (
172174 opts : DocumentOptions < Document > ,
173- handler : ( event : FirestoreEvent < QueryDocumentSnapshot , ParamsOf < Document > > ) => any | Promise < any >
174- ) : CloudFunction < FirestoreEvent < QueryDocumentSnapshot , ParamsOf < Document > > > ;
175+ handler : (
176+ event : FirestoreEvent < QueryDocumentSnapshot | undefined , ParamsOf < Document > >
177+ ) => any | Promise < any >
178+ ) : CloudFunction < FirestoreEvent < QueryDocumentSnapshot | undefined , ParamsOf < Document > > > ;
175179
176180/**
177181 * Event handler which triggers when a document is created in Firestore.
@@ -181,8 +185,10 @@ export function onDocumentCreated<Document extends string>(
181185 */
182186export function onDocumentCreated < Document extends string > (
183187 documentOrOpts : Document | DocumentOptions < Document > ,
184- handler : ( event : FirestoreEvent < QueryDocumentSnapshot , ParamsOf < Document > > ) => any | Promise < any >
185- ) : CloudFunction < FirestoreEvent < QueryDocumentSnapshot , ParamsOf < Document > > > {
188+ handler : (
189+ event : FirestoreEvent < QueryDocumentSnapshot | undefined , ParamsOf < Document > >
190+ ) => any | Promise < any >
191+ ) : CloudFunction < FirestoreEvent < QueryDocumentSnapshot | undefined , ParamsOf < Document > > > {
186192 return onOperation ( createdEventType , documentOrOpts , handler ) ;
187193}
188194
@@ -195,9 +201,9 @@ export function onDocumentCreated<Document extends string>(
195201export function onDocumentUpdated < Document extends string > (
196202 document : Document ,
197203 handler : (
198- event : FirestoreEvent < Change < QueryDocumentSnapshot > , ParamsOf < Document > >
204+ event : FirestoreEvent < Change < QueryDocumentSnapshot > | undefined , ParamsOf < Document > >
199205 ) => any | Promise < any >
200- ) : CloudFunction < FirestoreEvent < Change < QueryDocumentSnapshot > , ParamsOf < Document > > > ;
206+ ) : CloudFunction < FirestoreEvent < Change < QueryDocumentSnapshot > | undefined , ParamsOf < Document > > > ;
201207/**
202208 * Event handler which triggers when a document is updated in Firestore.
203209 *
@@ -207,9 +213,9 @@ export function onDocumentUpdated<Document extends string>(
207213export function onDocumentUpdated < Document extends string > (
208214 opts : DocumentOptions < Document > ,
209215 handler : (
210- event : FirestoreEvent < Change < QueryDocumentSnapshot > , ParamsOf < Document > >
216+ event : FirestoreEvent < Change < QueryDocumentSnapshot > | undefined , ParamsOf < Document > >
211217 ) => any | Promise < any >
212- ) : CloudFunction < FirestoreEvent < Change < QueryDocumentSnapshot > , ParamsOf < Document > > > ;
218+ ) : CloudFunction < FirestoreEvent < Change < QueryDocumentSnapshot > | undefined , ParamsOf < Document > > > ;
213219
214220/**
215221 * Event handler which triggers when a document is updated in Firestore.
@@ -220,9 +226,9 @@ export function onDocumentUpdated<Document extends string>(
220226export function onDocumentUpdated < Document extends string > (
221227 documentOrOpts : Document | DocumentOptions < Document > ,
222228 handler : (
223- event : FirestoreEvent < Change < QueryDocumentSnapshot > , ParamsOf < Document > >
229+ event : FirestoreEvent < Change < QueryDocumentSnapshot > | undefined , ParamsOf < Document > >
224230 ) => any | Promise < any >
225- ) : CloudFunction < FirestoreEvent < Change < QueryDocumentSnapshot > , ParamsOf < Document > > > {
231+ ) : CloudFunction < FirestoreEvent < Change < QueryDocumentSnapshot > | undefined , ParamsOf < Document > > > {
226232 return onChangedOperation ( updatedEventType , documentOrOpts , handler ) ;
227233}
228234
@@ -234,8 +240,10 @@ export function onDocumentUpdated<Document extends string>(
234240 */
235241export function onDocumentDeleted < Document extends string > (
236242 document : Document ,
237- handler : ( event : FirestoreEvent < QueryDocumentSnapshot , ParamsOf < Document > > ) => any | Promise < any >
238- ) : CloudFunction < FirestoreEvent < QueryDocumentSnapshot , ParamsOf < Document > > > ;
243+ handler : (
244+ event : FirestoreEvent < QueryDocumentSnapshot | undefined , ParamsOf < Document > >
245+ ) => any | Promise < any >
246+ ) : CloudFunction < FirestoreEvent < QueryDocumentSnapshot | undefined , ParamsOf < Document > > > ;
239247
240248/**
241249 * Event handler which triggers when a document is deleted in Firestore.
@@ -245,8 +253,10 @@ export function onDocumentDeleted<Document extends string>(
245253 */
246254export function onDocumentDeleted < Document extends string > (
247255 opts : DocumentOptions < Document > ,
248- handler : ( event : FirestoreEvent < QueryDocumentSnapshot , ParamsOf < Document > > ) => any | Promise < any >
249- ) : CloudFunction < FirestoreEvent < QueryDocumentSnapshot , ParamsOf < Document > > > ;
256+ handler : (
257+ event : FirestoreEvent < QueryDocumentSnapshot | undefined , ParamsOf < Document > >
258+ ) => any | Promise < any >
259+ ) : CloudFunction < FirestoreEvent < QueryDocumentSnapshot | undefined , ParamsOf < Document > > > ;
250260
251261/**
252262 * Event handler which triggers when a document is deleted in Firestore.
@@ -256,8 +266,10 @@ export function onDocumentDeleted<Document extends string>(
256266 */
257267export function onDocumentDeleted < Document extends string > (
258268 documentOrOpts : Document | DocumentOptions < Document > ,
259- handler : ( event : FirestoreEvent < QueryDocumentSnapshot , ParamsOf < Document > > ) => any | Promise < any >
260- ) : CloudFunction < FirestoreEvent < QueryDocumentSnapshot , ParamsOf < Document > > > {
269+ handler : (
270+ event : FirestoreEvent < QueryDocumentSnapshot | undefined , ParamsOf < Document > >
271+ ) => any | Promise < any >
272+ ) : CloudFunction < FirestoreEvent < QueryDocumentSnapshot | undefined , ParamsOf < Document > > > {
261273 return onOperation ( deletedEventType , documentOrOpts , handler ) ;
262274}
263275
@@ -345,20 +357,17 @@ export function makeFirestoreEvent<Params>(
345357 eventType : string ,
346358 event : RawFirestoreEvent ,
347359 params : Params
348- ) : FirestoreEvent < QueryDocumentSnapshot , Params > {
360+ ) : FirestoreEvent < QueryDocumentSnapshot | undefined , Params > {
349361 const data = event . data
350362 ? eventType === createdEventType
351363 ? createSnapshot ( event )
352364 : createBeforeSnapshot ( event )
353365 : undefined ;
354- const firestoreEvent : FirestoreEvent < QueryDocumentSnapshot , Params > = {
366+ const firestoreEvent : FirestoreEvent < QueryDocumentSnapshot | undefined , Params > = {
355367 ...event ,
356368 params,
357369 data,
358370 } ;
359- if ( firestoreEvent . data === undefined ) {
360- delete ( firestoreEvent as any ) . data ;
361- }
362371 delete ( firestoreEvent as any ) . datacontenttype ;
363372 delete ( firestoreEvent as any ) . dataschema ;
364373 return firestoreEvent ;
@@ -368,18 +377,15 @@ export function makeFirestoreEvent<Params>(
368377export function makeChangedFirestoreEvent < Params > (
369378 event : RawFirestoreEvent ,
370379 params : Params
371- ) : FirestoreEvent < Change < QueryDocumentSnapshot > , Params > {
380+ ) : FirestoreEvent < Change < QueryDocumentSnapshot > | undefined , Params > {
372381 const data = event . data
373382 ? Change . fromObjects ( createBeforeSnapshot ( event ) , createSnapshot ( event ) )
374383 : undefined ;
375- const firestoreEvent : FirestoreEvent < Change < QueryDocumentSnapshot > , Params > = {
384+ const firestoreEvent : FirestoreEvent < Change < QueryDocumentSnapshot > | undefined , Params > = {
376385 ...event ,
377386 params,
378387 data,
379388 } ;
380- if ( firestoreEvent . data === undefined ) {
381- delete ( firestoreEvent as any ) . data ;
382- }
383389 delete ( firestoreEvent as any ) . datacontenttype ;
384390 delete ( firestoreEvent as any ) . dataschema ;
385391 return firestoreEvent ;
0 commit comments