@@ -174,6 +174,13 @@ export interface CustomerEncryption {
174174 keySha256 ?: string ;
175175}
176176
177+ interface WithBucket {
178+ /** The name of the bucket containing this object. */
179+ bucket : string ;
180+ }
181+
182+ export type StorageEvent = CloudEvent < StorageObjectData , WithBucket > ;
183+
177184/** @internal */
178185export const archivedEvent = 'google.cloud.storage.object.v1.archived' ;
179186/** @internal */
@@ -191,100 +198,100 @@ export interface StorageOptions extends options.EventHandlerOptions {
191198
192199/** Handle a storage object archived */
193200export function onObjectArchived (
194- handler : ( event : CloudEvent < StorageObjectData > ) => any | Promise < any >
201+ handler : ( event : StorageEvent ) => any | Promise < any >
195202) : CloudFunction < StorageObjectData > ;
196203
197204export function onObjectArchived (
198205 bucket : string ,
199- handler : ( event : CloudEvent < StorageObjectData > ) => any | Promise < any >
206+ handler : ( event : StorageEvent ) => any | Promise < any >
200207) : CloudFunction < StorageObjectData > ;
201208
202209export function onObjectArchived (
203210 opts : StorageOptions ,
204- handler : ( event : CloudEvent < StorageObjectData > ) => any | Promise < any >
211+ handler : ( event : StorageEvent ) => any | Promise < any >
205212) : CloudFunction < StorageObjectData > ;
206213
207214export function onObjectArchived (
208215 buketOrOptsOrHandler :
209216 | string
210217 | StorageOptions
211- | ( ( event : CloudEvent < StorageObjectData > ) => any | Promise < any > ) ,
212- handler ?: ( event : CloudEvent < StorageObjectData > ) => any | Promise < any >
218+ | ( ( event : StorageEvent ) => any | Promise < any > ) ,
219+ handler ?: ( event : StorageEvent ) => any | Promise < any >
213220) : CloudFunction < StorageObjectData > {
214221 return onOperation ( archivedEvent , buketOrOptsOrHandler , handler ) ;
215222}
216223
217224/** Handle a storage object finalized */
218225export function onObjectFinalized (
219- handler : ( event : CloudEvent < StorageObjectData > ) => any | Promise < any >
226+ handler : ( event : StorageEvent ) => any | Promise < any >
220227) : CloudFunction < StorageObjectData > ;
221228
222229export function onObjectFinalized (
223230 bucket : string ,
224- handler : ( event : CloudEvent < StorageObjectData > ) => any | Promise < any >
231+ handler : ( event : StorageEvent ) => any | Promise < any >
225232) : CloudFunction < StorageObjectData > ;
226233
227234export function onObjectFinalized (
228235 opts : StorageOptions ,
229- handler : ( event : CloudEvent < StorageObjectData > ) => any | Promise < any >
236+ handler : ( event : StorageEvent ) => any | Promise < any >
230237) : CloudFunction < StorageObjectData > ;
231238
232239export function onObjectFinalized (
233240 buketOrOptsOrHandler :
234241 | string
235242 | StorageOptions
236- | ( ( event : CloudEvent < StorageObjectData > ) => any | Promise < any > ) ,
237- handler ?: ( event : CloudEvent < StorageObjectData > ) => any | Promise < any >
243+ | ( ( event : StorageEvent ) => any | Promise < any > ) ,
244+ handler ?: ( event : StorageEvent ) => any | Promise < any >
238245) : CloudFunction < StorageObjectData > {
239246 return onOperation ( finalizedEvent , buketOrOptsOrHandler , handler ) ;
240247}
241248
242249/** Handle a storage object deleted */
243250export function onObjectDeleted (
244- handler : ( event : CloudEvent < StorageObjectData > ) => any | Promise < any >
251+ handler : ( event : StorageEvent ) => any | Promise < any >
245252) : CloudFunction < StorageObjectData > ;
246253
247254export function onObjectDeleted (
248255 bucket : string ,
249- handler : ( event : CloudEvent < StorageObjectData > ) => any | Promise < any >
256+ handler : ( event : StorageEvent ) => any | Promise < any >
250257) : CloudFunction < StorageObjectData > ;
251258
252259export function onObjectDeleted (
253260 opts : StorageOptions ,
254- handler : ( event : CloudEvent < StorageObjectData > ) => any | Promise < any >
261+ handler : ( event : StorageEvent ) => any | Promise < any >
255262) : CloudFunction < StorageObjectData > ;
256263
257264export function onObjectDeleted (
258265 buketOrOptsOrHandler :
259266 | string
260267 | StorageOptions
261- | ( ( event : CloudEvent < StorageObjectData > ) => any | Promise < any > ) ,
262- handler ?: ( event : CloudEvent < StorageObjectData > ) => any | Promise < any >
268+ | ( ( event : StorageEvent ) => any | Promise < any > ) ,
269+ handler ?: ( event : StorageEvent ) => any | Promise < any >
263270) : CloudFunction < StorageObjectData > {
264271 return onOperation ( deletedEvent , buketOrOptsOrHandler , handler ) ;
265272}
266273
267274/** Handle a storage object metadata updated */
268275export function onObjectMetadataUpdated (
269- handler : ( event : CloudEvent < StorageObjectData > ) => any | Promise < any >
276+ handler : ( event : StorageEvent ) => any | Promise < any >
270277) : CloudFunction < StorageObjectData > ;
271278
272279export function onObjectMetadataUpdated (
273280 bucket : string ,
274- handler : ( event : CloudEvent < StorageObjectData > ) => any | Promise < any >
281+ handler : ( event : StorageEvent ) => any | Promise < any >
275282) : CloudFunction < StorageObjectData > ;
276283
277284export function onObjectMetadataUpdated (
278285 opts : StorageOptions ,
279- handler : ( event : CloudEvent < StorageObjectData > ) => any | Promise < any >
286+ handler : ( event : StorageEvent ) => any | Promise < any >
280287) : CloudFunction < StorageObjectData > ;
281288
282289export function onObjectMetadataUpdated (
283290 buketOrOptsOrHandler :
284291 | string
285292 | StorageOptions
286- | ( ( event : CloudEvent < StorageObjectData > ) => any | Promise < any > ) ,
287- handler ?: ( event : CloudEvent < StorageObjectData > ) => any | Promise < any >
293+ | ( ( event : StorageEvent ) => any | Promise < any > ) ,
294+ handler ?: ( event : StorageEvent ) => any | Promise < any >
288295) : CloudFunction < StorageObjectData > {
289296 return onOperation ( metadataUpdatedEvent , buketOrOptsOrHandler , handler ) ;
290297}
@@ -295,12 +302,12 @@ export function onOperation(
295302 bucketOrOptsOrHandler :
296303 | string
297304 | StorageOptions
298- | ( ( event : CloudEvent < StorageObjectData > ) => any | Promise < any > ) ,
299- handler : ( event : CloudEvent < StorageObjectData > ) => any | Promise < any >
305+ | ( ( event : StorageEvent ) => any | Promise < any > ) ,
306+ handler : ( event : StorageEvent ) => any | Promise < any >
300307) : CloudFunction < StorageObjectData > {
301308 if ( typeof bucketOrOptsOrHandler === 'function' ) {
302309 handler = bucketOrOptsOrHandler as (
303- event : CloudEvent < StorageObjectData >
310+ event : StorageEvent
304311 ) => any | Promise < any > ;
305312 bucketOrOptsOrHandler = { } ;
306313 }
@@ -310,7 +317,7 @@ export function onOperation(
310317 ) ;
311318
312319 const func = ( raw : CloudEvent < unknown > ) => {
313- return handler ( raw as CloudEvent < StorageObjectData > ) ;
320+ return handler ( raw as StorageEvent ) ;
314321 } ;
315322
316323 func . run = handler ;
@@ -382,7 +389,7 @@ export function getOptsAndBucket(
382389 bucket = bucketOrOpts ;
383390 opts = { } ;
384391 } else {
385- bucket = bucketOrOpts . bucket || firebaseConfig ( ) . storageBucket ;
392+ bucket = bucketOrOpts . bucket || firebaseConfig ( ) ? .storageBucket ;
386393 opts = { ...bucketOrOpts } ;
387394 delete ( opts as any ) . bucket ;
388395 }
0 commit comments