@@ -64,7 +64,7 @@ export interface RawFirestoreData {
64
64
}
65
65
66
66
/** @internal */
67
- export interface RawFirestoreEvent extends CloudEvent < Uint8Array | RawFirestoreData > {
67
+ export interface RawFirestoreEvent extends CloudEvent < Uint8Array | RawFirestoreData | undefined > {
68
68
location : string ;
69
69
project : string ;
70
70
database : string ;
@@ -119,9 +119,9 @@ export interface DocumentOptions<Document extends string = string> extends Event
119
119
export function onDocumentWritten < Document extends string > (
120
120
document : Document ,
121
121
handler : (
122
- event : FirestoreEvent < Change < DocumentSnapshot > , ParamsOf < Document > >
122
+ event : FirestoreEvent < Change < DocumentSnapshot > | undefined , ParamsOf < Document > >
123
123
) => any | Promise < any >
124
- ) : CloudFunction < FirestoreEvent < Change < DocumentSnapshot > , ParamsOf < Document > > > ;
124
+ ) : CloudFunction < FirestoreEvent < Change < DocumentSnapshot > | undefined , ParamsOf < Document > > > ;
125
125
126
126
/**
127
127
* Event handler which triggers when a document is created, updated, or deleted in Firestore.
@@ -132,9 +132,9 @@ export function onDocumentWritten<Document extends string>(
132
132
export function onDocumentWritten < Document extends string > (
133
133
opts : DocumentOptions < Document > ,
134
134
handler : (
135
- event : FirestoreEvent < Change < DocumentSnapshot > , ParamsOf < Document > >
135
+ event : FirestoreEvent < Change < DocumentSnapshot > | undefined , ParamsOf < Document > >
136
136
) => any | Promise < any >
137
- ) : CloudFunction < FirestoreEvent < Change < DocumentSnapshot > , ParamsOf < Document > > > ;
137
+ ) : CloudFunction < FirestoreEvent < Change < DocumentSnapshot > | undefined , ParamsOf < Document > > > ;
138
138
139
139
/**
140
140
* Event handler which triggers when a document is created, updated, or deleted in Firestore.
@@ -145,9 +145,9 @@ export function onDocumentWritten<Document extends string>(
145
145
export function onDocumentWritten < Document extends string > (
146
146
documentOrOpts : Document | DocumentOptions < Document > ,
147
147
handler : (
148
- event : FirestoreEvent < Change < DocumentSnapshot > , ParamsOf < Document > >
148
+ event : FirestoreEvent < Change < DocumentSnapshot > | undefined , ParamsOf < Document > >
149
149
) => any | Promise < any >
150
- ) : CloudFunction < FirestoreEvent < Change < DocumentSnapshot > , ParamsOf < Document > > > {
150
+ ) : CloudFunction < FirestoreEvent < Change < DocumentSnapshot > | undefined , ParamsOf < Document > > > {
151
151
return onChangedOperation ( writtenEventType , documentOrOpts , handler ) ;
152
152
}
153
153
@@ -159,8 +159,10 @@ export function onDocumentWritten<Document extends string>(
159
159
*/
160
160
export function onDocumentCreated < Document extends string > (
161
161
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 > > > ;
164
166
165
167
/**
166
168
* Event handler which triggers when a document is created in Firestore.
@@ -170,8 +172,10 @@ export function onDocumentCreated<Document extends string>(
170
172
*/
171
173
export function onDocumentCreated < Document extends string > (
172
174
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 > > > ;
175
179
176
180
/**
177
181
* Event handler which triggers when a document is created in Firestore.
@@ -181,8 +185,10 @@ export function onDocumentCreated<Document extends string>(
181
185
*/
182
186
export function onDocumentCreated < Document extends string > (
183
187
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 > > > {
186
192
return onOperation ( createdEventType , documentOrOpts , handler ) ;
187
193
}
188
194
@@ -195,9 +201,9 @@ export function onDocumentCreated<Document extends string>(
195
201
export function onDocumentUpdated < Document extends string > (
196
202
document : Document ,
197
203
handler : (
198
- event : FirestoreEvent < Change < QueryDocumentSnapshot > , ParamsOf < Document > >
204
+ event : FirestoreEvent < Change < QueryDocumentSnapshot > | undefined , ParamsOf < Document > >
199
205
) => any | Promise < any >
200
- ) : CloudFunction < FirestoreEvent < Change < QueryDocumentSnapshot > , ParamsOf < Document > > > ;
206
+ ) : CloudFunction < FirestoreEvent < Change < QueryDocumentSnapshot > | undefined , ParamsOf < Document > > > ;
201
207
/**
202
208
* Event handler which triggers when a document is updated in Firestore.
203
209
*
@@ -207,9 +213,9 @@ export function onDocumentUpdated<Document extends string>(
207
213
export function onDocumentUpdated < Document extends string > (
208
214
opts : DocumentOptions < Document > ,
209
215
handler : (
210
- event : FirestoreEvent < Change < QueryDocumentSnapshot > , ParamsOf < Document > >
216
+ event : FirestoreEvent < Change < QueryDocumentSnapshot > | undefined , ParamsOf < Document > >
211
217
) => any | Promise < any >
212
- ) : CloudFunction < FirestoreEvent < Change < QueryDocumentSnapshot > , ParamsOf < Document > > > ;
218
+ ) : CloudFunction < FirestoreEvent < Change < QueryDocumentSnapshot > | undefined , ParamsOf < Document > > > ;
213
219
214
220
/**
215
221
* Event handler which triggers when a document is updated in Firestore.
@@ -220,9 +226,9 @@ export function onDocumentUpdated<Document extends string>(
220
226
export function onDocumentUpdated < Document extends string > (
221
227
documentOrOpts : Document | DocumentOptions < Document > ,
222
228
handler : (
223
- event : FirestoreEvent < Change < QueryDocumentSnapshot > , ParamsOf < Document > >
229
+ event : FirestoreEvent < Change < QueryDocumentSnapshot > | undefined , ParamsOf < Document > >
224
230
) => any | Promise < any >
225
- ) : CloudFunction < FirestoreEvent < Change < QueryDocumentSnapshot > , ParamsOf < Document > > > {
231
+ ) : CloudFunction < FirestoreEvent < Change < QueryDocumentSnapshot > | undefined , ParamsOf < Document > > > {
226
232
return onChangedOperation ( updatedEventType , documentOrOpts , handler ) ;
227
233
}
228
234
@@ -234,8 +240,10 @@ export function onDocumentUpdated<Document extends string>(
234
240
*/
235
241
export function onDocumentDeleted < Document extends string > (
236
242
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 > > > ;
239
247
240
248
/**
241
249
* Event handler which triggers when a document is deleted in Firestore.
@@ -245,8 +253,10 @@ export function onDocumentDeleted<Document extends string>(
245
253
*/
246
254
export function onDocumentDeleted < Document extends string > (
247
255
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 > > > ;
250
260
251
261
/**
252
262
* Event handler which triggers when a document is deleted in Firestore.
@@ -256,8 +266,10 @@ export function onDocumentDeleted<Document extends string>(
256
266
*/
257
267
export function onDocumentDeleted < Document extends string > (
258
268
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 > > > {
261
273
return onOperation ( deletedEventType , documentOrOpts , handler ) ;
262
274
}
263
275
@@ -345,20 +357,17 @@ export function makeFirestoreEvent<Params>(
345
357
eventType : string ,
346
358
event : RawFirestoreEvent ,
347
359
params : Params
348
- ) : FirestoreEvent < QueryDocumentSnapshot , Params > {
360
+ ) : FirestoreEvent < QueryDocumentSnapshot | undefined , Params > {
349
361
const data = event . data
350
362
? eventType === createdEventType
351
363
? createSnapshot ( event )
352
364
: createBeforeSnapshot ( event )
353
365
: undefined ;
354
- const firestoreEvent : FirestoreEvent < QueryDocumentSnapshot , Params > = {
366
+ const firestoreEvent : FirestoreEvent < QueryDocumentSnapshot | undefined , Params > = {
355
367
...event ,
356
368
params,
357
369
data,
358
370
} ;
359
- if ( firestoreEvent . data === undefined ) {
360
- delete ( firestoreEvent as any ) . data ;
361
- }
362
371
delete ( firestoreEvent as any ) . datacontenttype ;
363
372
delete ( firestoreEvent as any ) . dataschema ;
364
373
return firestoreEvent ;
@@ -368,18 +377,15 @@ export function makeFirestoreEvent<Params>(
368
377
export function makeChangedFirestoreEvent < Params > (
369
378
event : RawFirestoreEvent ,
370
379
params : Params
371
- ) : FirestoreEvent < Change < QueryDocumentSnapshot > , Params > {
380
+ ) : FirestoreEvent < Change < QueryDocumentSnapshot > | undefined , Params > {
372
381
const data = event . data
373
382
? Change . fromObjects ( createBeforeSnapshot ( event ) , createSnapshot ( event ) )
374
383
: undefined ;
375
- const firestoreEvent : FirestoreEvent < Change < QueryDocumentSnapshot > , Params > = {
384
+ const firestoreEvent : FirestoreEvent < Change < QueryDocumentSnapshot > | undefined , Params > = {
376
385
...event ,
377
386
params,
378
387
data,
379
388
} ;
380
- if ( firestoreEvent . data === undefined ) {
381
- delete ( firestoreEvent as any ) . data ;
382
- }
383
389
delete ( firestoreEvent as any ) . datacontenttype ;
384
390
delete ( firestoreEvent as any ) . dataschema ;
385
391
return firestoreEvent ;
0 commit comments