-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update CloudEvent types #1089
Update CloudEvent types #1089
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,6 +174,13 @@ export interface CustomerEncryption { | |
keySha256?: string; | ||
} | ||
|
||
interface WithBucket { | ||
/** The name of the bucket containing this object. */ | ||
bucket: string; | ||
} | ||
|
||
export type StorageEvent = CloudEvent<StorageObjectData, WithBucket>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh interesting, I didn't realize that storage also uses custom extension attributes. |
||
|
||
/** @internal */ | ||
export const archivedEvent = 'google.cloud.storage.object.v1.archived'; | ||
/** @internal */ | ||
|
@@ -191,100 +198,100 @@ export interface StorageOptions extends options.EventHandlerOptions { | |
|
||
/** Handle a storage object archived */ | ||
export function onObjectArchived( | ||
handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any> | ||
handler: (event: StorageEvent) => any | Promise<any> | ||
): CloudFunction<StorageObjectData>; | ||
|
||
export function onObjectArchived( | ||
bucket: string, | ||
handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any> | ||
handler: (event: StorageEvent) => any | Promise<any> | ||
): CloudFunction<StorageObjectData>; | ||
|
||
export function onObjectArchived( | ||
opts: StorageOptions, | ||
handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any> | ||
handler: (event: StorageEvent) => any | Promise<any> | ||
): CloudFunction<StorageObjectData>; | ||
|
||
export function onObjectArchived( | ||
buketOrOptsOrHandler: | ||
| string | ||
| StorageOptions | ||
| ((event: CloudEvent<StorageObjectData>) => any | Promise<any>), | ||
handler?: (event: CloudEvent<StorageObjectData>) => any | Promise<any> | ||
| ((event: StorageEvent) => any | Promise<any>), | ||
handler?: (event: StorageEvent) => any | Promise<any> | ||
): CloudFunction<StorageObjectData> { | ||
return onOperation(archivedEvent, buketOrOptsOrHandler, handler); | ||
} | ||
|
||
/** Handle a storage object finalized */ | ||
export function onObjectFinalized( | ||
handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any> | ||
handler: (event: StorageEvent) => any | Promise<any> | ||
): CloudFunction<StorageObjectData>; | ||
|
||
export function onObjectFinalized( | ||
bucket: string, | ||
handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any> | ||
handler: (event: StorageEvent) => any | Promise<any> | ||
): CloudFunction<StorageObjectData>; | ||
|
||
export function onObjectFinalized( | ||
opts: StorageOptions, | ||
handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any> | ||
handler: (event: StorageEvent) => any | Promise<any> | ||
): CloudFunction<StorageObjectData>; | ||
|
||
export function onObjectFinalized( | ||
buketOrOptsOrHandler: | ||
| string | ||
| StorageOptions | ||
| ((event: CloudEvent<StorageObjectData>) => any | Promise<any>), | ||
handler?: (event: CloudEvent<StorageObjectData>) => any | Promise<any> | ||
| ((event: StorageEvent) => any | Promise<any>), | ||
handler?: (event: StorageEvent) => any | Promise<any> | ||
): CloudFunction<StorageObjectData> { | ||
return onOperation(finalizedEvent, buketOrOptsOrHandler, handler); | ||
} | ||
|
||
/** Handle a storage object deleted */ | ||
export function onObjectDeleted( | ||
handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any> | ||
handler: (event: StorageEvent) => any | Promise<any> | ||
): CloudFunction<StorageObjectData>; | ||
|
||
export function onObjectDeleted( | ||
bucket: string, | ||
handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any> | ||
handler: (event: StorageEvent) => any | Promise<any> | ||
): CloudFunction<StorageObjectData>; | ||
|
||
export function onObjectDeleted( | ||
opts: StorageOptions, | ||
handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any> | ||
handler: (event: StorageEvent) => any | Promise<any> | ||
): CloudFunction<StorageObjectData>; | ||
|
||
export function onObjectDeleted( | ||
buketOrOptsOrHandler: | ||
| string | ||
| StorageOptions | ||
| ((event: CloudEvent<StorageObjectData>) => any | Promise<any>), | ||
handler?: (event: CloudEvent<StorageObjectData>) => any | Promise<any> | ||
| ((event: StorageEvent) => any | Promise<any>), | ||
handler?: (event: StorageEvent) => any | Promise<any> | ||
): CloudFunction<StorageObjectData> { | ||
return onOperation(deletedEvent, buketOrOptsOrHandler, handler); | ||
} | ||
|
||
/** Handle a storage object metadata updated */ | ||
export function onObjectMetadataUpdated( | ||
handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any> | ||
handler: (event: StorageEvent) => any | Promise<any> | ||
): CloudFunction<StorageObjectData>; | ||
|
||
export function onObjectMetadataUpdated( | ||
bucket: string, | ||
handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any> | ||
handler: (event: StorageEvent) => any | Promise<any> | ||
): CloudFunction<StorageObjectData>; | ||
|
||
export function onObjectMetadataUpdated( | ||
opts: StorageOptions, | ||
handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any> | ||
handler: (event: StorageEvent) => any | Promise<any> | ||
): CloudFunction<StorageObjectData>; | ||
|
||
export function onObjectMetadataUpdated( | ||
buketOrOptsOrHandler: | ||
| string | ||
| StorageOptions | ||
| ((event: CloudEvent<StorageObjectData>) => any | Promise<any>), | ||
handler?: (event: CloudEvent<StorageObjectData>) => any | Promise<any> | ||
| ((event: StorageEvent) => any | Promise<any>), | ||
handler?: (event: StorageEvent) => any | Promise<any> | ||
): CloudFunction<StorageObjectData> { | ||
return onOperation(metadataUpdatedEvent, buketOrOptsOrHandler, handler); | ||
} | ||
|
@@ -295,12 +302,12 @@ export function onOperation( | |
bucketOrOptsOrHandler: | ||
| string | ||
| StorageOptions | ||
| ((event: CloudEvent<StorageObjectData>) => any | Promise<any>), | ||
handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any> | ||
| ((event: StorageEvent) => any | Promise<any>), | ||
handler: (event: StorageEvent) => any | Promise<any> | ||
): CloudFunction<StorageObjectData> { | ||
if (typeof bucketOrOptsOrHandler === 'function') { | ||
handler = bucketOrOptsOrHandler as ( | ||
event: CloudEvent<StorageObjectData> | ||
event: StorageEvent | ||
) => any | Promise<any>; | ||
bucketOrOptsOrHandler = {}; | ||
} | ||
|
@@ -310,7 +317,7 @@ export function onOperation( | |
); | ||
|
||
const func = (raw: CloudEvent<unknown>) => { | ||
return handler(raw as CloudEvent<StorageObjectData>); | ||
return handler(raw as StorageEvent); | ||
}; | ||
|
||
func.run = handler; | ||
|
@@ -382,7 +389,7 @@ export function getOptsAndBucket( | |
bucket = bucketOrOpts; | ||
opts = {}; | ||
} else { | ||
bucket = bucketOrOpts.bucket || firebaseConfig().storageBucket; | ||
bucket = bucketOrOpts.bucket || firebaseConfig()?.storageBucket; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was the NPE culprit. firebaseConfig() is nullable, so attempting to access |
||
opts = { ...bucketOrOpts }; | ||
delete (opts as any).bucket; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh nice catch, I think I missed this field and meant to add it a while ago 🤦♂️