diff --git a/src/v1/providers/analytics.ts b/src/v1/providers/analytics.ts index 0cc0083b9..87042bab8 100644 --- a/src/v1/providers/analytics.ts +++ b/src/v1/providers/analytics.ts @@ -30,6 +30,9 @@ export const provider = "google.analytics"; /** @internal */ export const service = "app-measurement.com"; +/** Handler used by {@link AnalyticsEventBuilder.onLog}. */ +export type OnLogHandler = (event: AnalyticsEvent, context: EventContext) => PromiseLike | any; + /** * Registers a function to handle analytics events. * @@ -75,9 +78,7 @@ export class AnalyticsEventBuilder { * * @returns A function that you can export and deploy. */ - onLog( - handler: (event: AnalyticsEvent, context: EventContext) => PromiseLike | any - ): CloudFunction { + onLog(handler: OnLogHandler): CloudFunction { const dataConstructor = (raw: LegacyEvent) => { return new AnalyticsEvent(raw.data); }; diff --git a/src/v1/providers/auth.ts b/src/v1/providers/auth.ts index e7100b048..cf54cf37f 100644 --- a/src/v1/providers/auth.ts +++ b/src/v1/providers/auth.ts @@ -55,6 +55,32 @@ export type { UserRecord, UserInfo }; export { HttpsError }; +/** Handler used by {@link UserBuilder.onCreate}. */ +export type OnCreateHandler = (user: UserRecord, context: EventContext) => PromiseLike | any; + +/** Handler used by {@link UserBuilder.onDelete}. */ +export type OnDeleteHandler = OnCreateHandler; + +/** Handler used by {@link UserBuilder.beforeCreate}. */ +export type BeforeCreateHandler = ( + user: AuthUserRecord, + context: AuthEventContext +) => MaybeAsync; + +/** Handler used by {@link UserBuilder.beforeSignIn}. */ +export type BeforeSignInHandler = ( + user: AuthUserRecord, + context: AuthEventContext +) => MaybeAsync; + +/** Handler used by {@link UserBuilder.beforeEmail}. */ +export type BeforeEmailHandler = ( + context: AuthEventContext +) => MaybeAsync; + +/** Handler used by {@link UserBuilder.beforeSms}. */ +export type BeforeSmsHandler = (context: AuthEventContext) => MaybeAsync; + /** @internal */ export const provider = "google.firebase.auth"; /** @internal */ @@ -126,9 +152,7 @@ export class UserBuilder { * * @public */ - onCreate( - handler: (user: UserRecord, context: EventContext) => PromiseLike | any - ): CloudFunction { + onCreate(handler: OnCreateHandler): CloudFunction { return this.onOperation(handler, "user.create"); } @@ -139,9 +163,7 @@ export class UserBuilder { * * @public */ - onDelete( - handler: (user: UserRecord, context: EventContext) => PromiseLike | any - ): CloudFunction { + onDelete(handler: OnDeleteHandler): CloudFunction { return this.onOperation(handler, "user.delete"); } @@ -152,12 +174,7 @@ export class UserBuilder { * * @public */ - beforeCreate( - handler: ( - user: AuthUserRecord, - context: AuthEventContext - ) => MaybeAsync - ): BlockingFunction { + beforeCreate(handler: BeforeCreateHandler): BlockingFunction { return this.beforeOperation(handler, "beforeCreate"); } @@ -168,24 +185,15 @@ export class UserBuilder { * * @public */ - beforeSignIn( - handler: ( - user: AuthUserRecord, - context: AuthEventContext - ) => MaybeAsync - ): BlockingFunction { + beforeSignIn(handler: BeforeSignInHandler): BlockingFunction { return this.beforeOperation(handler, "beforeSignIn"); } - beforeEmail( - handler: (context: AuthEventContext) => MaybeAsync - ): BlockingFunction { + beforeEmail(handler: BeforeEmailHandler): BlockingFunction { return this.beforeOperation(handler, "beforeSendEmail"); } - beforeSms( - handler: (context: AuthEventContext) => MaybeAsync - ): BlockingFunction { + beforeSms(handler: BeforeSmsHandler): BlockingFunction { return this.beforeOperation(handler, "beforeSendSms"); } diff --git a/src/v1/providers/database.ts b/src/v1/providers/database.ts index baa4afcb9..007afe641 100644 --- a/src/v1/providers/database.ts +++ b/src/v1/providers/database.ts @@ -34,6 +34,24 @@ import { expr } from "../../params"; export { DataSnapshot }; +/** Handler used by {@link RefBuilder.onWrite}. */ +export type OnWriteHandler = ( + change: Change, + context: EventContext> +) => PromiseLike | any; + +/** Handler used by {@link RefBuilder.onUpdate}. */ +export type OnUpdateHandler = OnWriteHandler; + +/** Handler used by {@link RefBuilder.onCreate}. */ +export type OnCreateHandler = ( + snapshot: DataSnapshot, + context: EventContext> +) => PromiseLike | any; + +/** Handler used by {@link RefBuilder.onDelete}. */ +export type OnDeleteHandler = OnCreateHandler; + /** @internal */ export const provider = "google.firebase.database"; /** @internal */ @@ -182,12 +200,7 @@ export class RefBuilder { * write occurs. * @returns A function that you can export and deploy. */ - onWrite( - handler: ( - change: Change, - context: EventContext> - ) => PromiseLike | any - ): CloudFunction> { + onWrite(handler: OnWriteHandler): CloudFunction> { return this.onOperation(handler, "ref.write", this.changeConstructor); } @@ -199,12 +212,7 @@ export class RefBuilder { * write occurs. * @returns A function which you can export and deploy. */ - onUpdate( - handler: ( - change: Change, - context: EventContext> - ) => PromiseLike | any - ): CloudFunction> { + onUpdate(handler: OnUpdateHandler): CloudFunction> { return this.onOperation(handler, "ref.update", this.changeConstructor); } @@ -216,12 +224,7 @@ export class RefBuilder { * Firebase Realtime Database. * @returns A function that you can export and deploy. */ - onCreate( - handler: ( - snapshot: DataSnapshot, - context: EventContext> - ) => PromiseLike | any - ): CloudFunction { + onCreate(handler: OnCreateHandler): CloudFunction { const dataConstructor = (raw: LegacyEvent) => { const [dbInstance, path] = extractInstanceAndPath( raw.context.resource.name, @@ -240,12 +243,7 @@ export class RefBuilder { * Firebase Realtime Database. * @returns A function that you can export and deploy. */ - onDelete( - handler: ( - snapshot: DataSnapshot, - context: EventContext> - ) => PromiseLike | any - ): CloudFunction { + onDelete(handler: OnDeleteHandler): CloudFunction { const dataConstructor = (raw: LegacyEvent) => { const [dbInstance, path] = extractInstanceAndPath( raw.context.resource.name, diff --git a/src/v1/providers/firestore.ts b/src/v1/providers/firestore.ts index 1d891df09..52153427d 100644 --- a/src/v1/providers/firestore.ts +++ b/src/v1/providers/firestore.ts @@ -44,6 +44,27 @@ export const defaultDatabase = "(default)"; export type DocumentSnapshot = firestore.DocumentSnapshot; export type QueryDocumentSnapshot = firestore.QueryDocumentSnapshot; +/** Handler used by {@link DocumentBuilder.onWrite}. */ +export type OnWriteHandler = ( + change: Change, + context: EventContext> +) => PromiseLike | any; + +/** Handler used by {@link DocumentBuilder.onUpdate}. */ +export type OnUpdateHandler = ( + change: Change, + context: EventContext> +) => PromiseLike | any; + +/** Handler used by {@link DocumentBuilder.onCreate}. */ +export type OnCreateHandler = ( + snapshot: QueryDocumentSnapshot, + context: EventContext> +) => PromiseLike | any; + +/** Handler used by {@link DocumentBuilder.onDelete}. */ +export type OnDeleteHandler = OnCreateHandler; + /** * Select the Firestore document to listen to for events. * @param path Full database path to listen to. This includes the name of @@ -166,42 +187,22 @@ export class DocumentBuilder { } /** Respond to all document writes (creates, updates, or deletes). */ - onWrite( - handler: ( - change: Change, - context: EventContext> - ) => PromiseLike | any - ): CloudFunction> { + onWrite(handler: OnWriteHandler): CloudFunction> { return this.onOperation(handler, "document.write", changeConstructor); } /** Respond only to document updates. */ - onUpdate( - handler: ( - change: Change, - context: EventContext> - ) => PromiseLike | any - ): CloudFunction> { + onUpdate(handler: OnUpdateHandler): CloudFunction> { return this.onOperation(handler, "document.update", changeConstructor); } /** Respond only to document creations. */ - onCreate( - handler: ( - snapshot: QueryDocumentSnapshot, - context: EventContext> - ) => PromiseLike | any - ): CloudFunction { + onCreate(handler: OnCreateHandler): CloudFunction { return this.onOperation(handler, "document.create", snapshotConstructor); } /** Respond only to document deletions. */ - onDelete( - handler: ( - snapshot: QueryDocumentSnapshot, - context: EventContext> - ) => PromiseLike | any - ): CloudFunction { + onDelete(handler: OnDeleteHandler): CloudFunction { return this.onOperation(handler, "document.delete", beforeSnapshotConstructor); } diff --git a/src/v1/providers/https.ts b/src/v1/providers/https.ts index 739c9e001..9dc7ba2b6 100644 --- a/src/v1/providers/https.ts +++ b/src/v1/providers/https.ts @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -import * as express from "express"; +import type * as express from "express"; import { convertIfPresent, convertInvoker } from "../../common/encoding"; import { @@ -40,14 +40,18 @@ import { wrapTraceContext } from "../../v2/trace"; export { HttpsError }; export type { Request, CallableContext, FunctionsErrorCode }; +/** Handler used by {@link onRequest}. */ +export type OnRequestHandler = (req: Request, resp: express.Response) => void | Promise; + +/** Handler used by {@link onCall}. */ +export type OnCallHandler = (data: any, context: CallableContext) => any | Promise; + /** * Handle HTTP requests. * @param handler A function that takes a request and response object, * same signature as an Express app. */ -export function onRequest( - handler: (req: Request, resp: express.Response) => void | Promise -): HttpsFunction { +export function onRequest(handler: OnRequestHandler): HttpsFunction { return _onRequestWithOptions(handler, {}); } @@ -55,15 +59,13 @@ export function onRequest( * Declares a callable method for clients to call using a Firebase SDK. * @param handler A method that takes a data and context and returns a value. */ -export function onCall( - handler: (data: any, context: CallableContext) => any | Promise -): HttpsFunction & Runnable { +export function onCall(handler: OnCallHandler): HttpsFunction & Runnable { return _onCallWithOptions(handler, {}); } /** @internal */ export function _onRequestWithOptions( - handler: (req: Request, resp: express.Response) => void | Promise, + handler: OnRequestHandler, options: DeploymentOptions ): HttpsFunction { // lets us add __endpoint without altering handler: @@ -101,7 +103,7 @@ export function _onRequestWithOptions( /** @internal */ export function _onCallWithOptions( - handler: (data: any, context: CallableContext) => any | Promise, + handler: OnCallHandler, options: DeploymentOptions ): HttpsFunction & Runnable { // fix the length of handler to make the call to handler consistent diff --git a/src/v1/providers/pubsub.ts b/src/v1/providers/pubsub.ts index 21946dea5..f604d5e78 100644 --- a/src/v1/providers/pubsub.ts +++ b/src/v1/providers/pubsub.ts @@ -30,6 +30,12 @@ export const provider = "google.pubsub"; /** @internal */ export const service = "pubsub.googleapis.com"; +/** Handler used by {@link TopicBuilder.onPublish}. */ +export type OnPublishHandler = (message: Message, context: EventContext) => PromiseLike | any; + +/** Handler used by {@link ScheduleBuilder.onRun}. */ +export type OnRunHandler = (context: EventContext) => PromiseLike | any; + /** * Registers a Cloud Function triggered when a Google Cloud Pub/Sub message * is sent to a specified topic. @@ -79,9 +85,7 @@ export class TopicBuilder { * is published. * @returns A function that you can export and deploy. */ - onPublish( - handler: (message: Message, context: EventContext) => PromiseLike | any - ): CloudFunction { + onPublish(handler: OnPublishHandler): CloudFunction { return makeCloudFunction({ handler, provider, @@ -156,7 +160,7 @@ export class ScheduleBuilder { * scheduler job sends a Pub/Sub message. * @returns A function that you can export and deploy. */ - onRun(handler: (context: EventContext) => PromiseLike | any) { + onRun(handler: OnRunHandler) { const cloudFunction = makeCloudFunction({ contextOnlyHandler: handler, provider, diff --git a/src/v1/providers/remoteConfig.ts b/src/v1/providers/remoteConfig.ts index cf67383dc..4ea94cf2b 100644 --- a/src/v1/providers/remoteConfig.ts +++ b/src/v1/providers/remoteConfig.ts @@ -28,6 +28,12 @@ export const provider = "google.firebase.remoteconfig"; /** @internal */ export const service = "firebaseremoteconfig.googleapis.com"; +/** Handler used by {@link onUpdate}. */ +export type OnUpdateHandler = ( + version: TemplateVersion, + context: EventContext +) => PromiseLike | any; + /** * Registers a function that triggers on Firebase Remote Config template * update events. @@ -37,15 +43,13 @@ export const service = "firebaseremoteconfig.googleapis.com"; * * @returns A function that you can export and deploy. */ -export function onUpdate( - handler: (version: TemplateVersion, context: EventContext) => PromiseLike | any -): CloudFunction { +export function onUpdate(handler: OnUpdateHandler): CloudFunction { return _onUpdateWithOptions(handler, {}); } /** @internal */ export function _onUpdateWithOptions( - handler: (version: TemplateVersion, context: EventContext) => PromiseLike | any, + handler: OnUpdateHandler, options: DeploymentOptions ): CloudFunction { const triggerResource = () => { @@ -68,9 +72,7 @@ export class UpdateBuilder { * @param handler A function that takes the updated Remote Config template * version metadata as an argument. */ - onUpdate( - handler: (version: TemplateVersion, context: EventContext) => PromiseLike | any - ): CloudFunction { + onUpdate(handler: OnUpdateHandler): CloudFunction { return makeCloudFunction({ handler, provider, diff --git a/src/v1/providers/storage.ts b/src/v1/providers/storage.ts index a720f62fe..368054697 100644 --- a/src/v1/providers/storage.ts +++ b/src/v1/providers/storage.ts @@ -31,6 +31,21 @@ export const provider = "google.storage"; /** @internal */ export const service = "storage.googleapis.com"; +/** Handler used by {@link ObjectBuilder.onArchive}. */ +export type OnArchiveHandler = ( + object: ObjectMetadata, + context: EventContext +) => PromiseLike | any; + +/** Handler used by {@link ObjectBuilder.onDelete}. */ +export type OnDeleteHandler = OnArchiveHandler; + +/** Handler used by {@link ObjectBuilder.onFinalize}. */ +export type OnFinalizeHandler = OnArchiveHandler; + +/** Handler used by {@link ObjectBuilder.onMetadataUpdate}. */ +export type OnMetadataUpdateHandler = OnArchiveHandler; + /** * Registers a Cloud Function scoped to a specific storage bucket. * @@ -125,9 +140,7 @@ export class ObjectBuilder { * * @returns A function which you can export and deploy. */ - onArchive( - handler: (object: ObjectMetadata, context: EventContext) => PromiseLike | any - ): CloudFunction { + onArchive(handler: OnArchiveHandler): CloudFunction { return this.onOperation(handler, "object.archive"); } @@ -145,9 +158,7 @@ export class ObjectBuilder { * * @returns A function which you can export and deploy. */ - onDelete( - handler: (object: ObjectMetadata, context: EventContext) => PromiseLike | any - ): CloudFunction { + onDelete(handler: OnDeleteHandler): CloudFunction { return this.onOperation(handler, "object.delete"); } @@ -164,9 +175,7 @@ export class ObjectBuilder { * * @returns A function which you can export and deploy. */ - onFinalize( - handler: (object: ObjectMetadata, context: EventContext) => PromiseLike | any - ): CloudFunction { + onFinalize(handler: OnFinalizeHandler): CloudFunction { return this.onOperation(handler, "object.finalize"); } @@ -179,9 +188,7 @@ export class ObjectBuilder { * * @returns A function which you can export and deploy. */ - onMetadataUpdate( - handler: (object: ObjectMetadata, context: EventContext) => PromiseLike | any - ): CloudFunction { + onMetadataUpdate(handler: OnMetadataUpdateHandler): CloudFunction { return this.onOperation(handler, "object.metadataUpdate"); } diff --git a/src/v1/providers/tasks.ts b/src/v1/providers/tasks.ts index 0be9176ab..32c025bda 100644 --- a/src/v1/providers/tasks.ts +++ b/src/v1/providers/tasks.ts @@ -41,6 +41,9 @@ import { DeploymentOptions } from "../function-configuration"; export type { RetryConfig, RateLimits, TaskContext }; +/** Handler used by {@link TaskQueueBuilder.onDispatch}. */ +export type OnDispatchHandler = (data: any, context: TaskContext) => void | Promise; + /** * Options for configuring the task queue to listen to. */ @@ -100,9 +103,7 @@ export class TaskQueueBuilder { * @param handler - A callback to handle task requests. * @returns A function you can export and deploy. */ - onDispatch( - handler: (data: any, context: TaskContext) => void | Promise - ): TaskQueueFunction { + onDispatch(handler: OnDispatchHandler): TaskQueueFunction { // onEnqueueHandler sniffs the function length of the passed-in callback // and the user could have only tried to listen to data. Wrap their handler // in another handler to avoid accidentally triggering the v2 API diff --git a/src/v1/providers/testLab.ts b/src/v1/providers/testLab.ts index 3ae851437..027b4ae20 100644 --- a/src/v1/providers/testLab.ts +++ b/src/v1/providers/testLab.ts @@ -30,6 +30,12 @@ export const SERVICE = "testing.googleapis.com"; /** @internal */ export const TEST_MATRIX_COMPLETE_EVENT_TYPE = "testMatrix.complete"; +/** Handler used by {@link TestMatrixBuilder.onComplete}. */ +export type OnCompleteHandler = ( + testMatrix: TestMatrix, + context: EventContext +) => PromiseLike | any; + /** Handle events related to Test Lab test matrices. */ export function testMatrix() { return _testMatrixWithOpts({}); @@ -51,9 +57,7 @@ export class TestMatrixBuilder { constructor(private triggerResource: () => string, private options: DeploymentOptions) {} /** Handle a TestMatrix that reached a final test state. */ - onComplete( - handler: (testMatrix: TestMatrix, context: EventContext) => PromiseLike | any - ): CloudFunction { + onComplete(handler: OnCompleteHandler): CloudFunction { const dataConstructor = (raw: LegacyEvent) => { return new TestMatrix(raw.data); }; diff --git a/src/v2/providers/ai/index.ts b/src/v2/providers/ai/index.ts index 413beb685..e5068c994 100644 --- a/src/v2/providers/ai/index.ts +++ b/src/v2/providers/ai/index.ts @@ -151,33 +151,29 @@ type MaybeAsync = T | Promise; export type BlockingFunction = HttpsFunction; -export function beforeGenerateContent( - callback: ( - event: AIBlockingEvent - ) => MaybeAsync> -): BlockingFunction; +/** Handler used by {@link beforeGenerateContent}. */ +export type BeforeGenerateContentHandler = ( + event: AIBlockingEvent +) => MaybeAsync>; + +/** Handler used by {@link afterGenerateContent}. */ +export type AfterGenerateContentHandler = ( + event: AIBlockingEvent +) => MaybeAsync>; + +export function beforeGenerateContent(callback: BeforeGenerateContentHandler): BlockingFunction; export function beforeGenerateContent( options: WebhookOptions, - callback: ( - event: AIBlockingEvent - ) => MaybeAsync> + callback: BeforeGenerateContentHandler ): BlockingFunction; export function beforeGenerateContent( - optsOrCb: - | WebhookOptions - | (( - event: AIBlockingEvent - ) => MaybeAsync>), - cb?: ( - event: AIBlockingEvent - ) => MaybeAsync> + optsOrCb: WebhookOptions | BeforeGenerateContentHandler, + cb?: BeforeGenerateContentHandler ): BlockingFunction { let opts: WebhookOptions; - let handler: ( - event: AIBlockingEvent - ) => MaybeAsync>; + let handler: BeforeGenerateContentHandler; if (arguments.length === 1) { opts = {}; @@ -258,33 +254,19 @@ export function beforeGenerateContent( return func as BlockingFunction; } -export function afterGenerateContent( - callback: ( - event: AIBlockingEvent - ) => MaybeAsync> -): BlockingFunction; +export function afterGenerateContent(callback: AfterGenerateContentHandler): BlockingFunction; export function afterGenerateContent( options: WebhookOptions, - callback: ( - event: AIBlockingEvent - ) => MaybeAsync> + callback: AfterGenerateContentHandler ): BlockingFunction; export function afterGenerateContent( - optsOrCb: - | WebhookOptions - | (( - event: AIBlockingEvent - ) => MaybeAsync>), - cb?: ( - event: AIBlockingEvent - ) => MaybeAsync> + optsOrCb: WebhookOptions | AfterGenerateContentHandler, + cb?: AfterGenerateContentHandler ): BlockingFunction { let opts: WebhookOptions; - let handler: ( - event: AIBlockingEvent - ) => MaybeAsync>; + let handler: AfterGenerateContentHandler; if (arguments.length === 1) { opts = {}; diff --git a/src/v2/providers/alerts/alerts.ts b/src/v2/providers/alerts/alerts.ts index 1cfacd706..15c968ca4 100644 --- a/src/v2/providers/alerts/alerts.ts +++ b/src/v2/providers/alerts/alerts.ts @@ -186,6 +186,11 @@ export interface FirebaseAlertOptions extends options.EventHandlerOptions { retry?: boolean | Expression | ResetValue; } +/** Handler used by {@link onAlertPublished}. */ +export type OnAlertPublishedHandler = ( + event: AlertEvent +) => any | Promise; + /** * Declares a function that can handle Firebase Alerts from CloudEvents. * @typeParam T - the type of event.data.payload. @@ -195,7 +200,7 @@ export interface FirebaseAlertOptions extends options.EventHandlerOptions { */ export function onAlertPublished( alertType: AlertType, - handler: (event: AlertEvent) => any | Promise + handler: OnAlertPublishedHandler ): CloudFunction>; /** @@ -206,12 +211,12 @@ export function onAlertPublished( */ export function onAlertPublished( options: FirebaseAlertOptions, - handler: (event: AlertEvent) => any | Promise + handler: OnAlertPublishedHandler ): CloudFunction>; export function onAlertPublished( alertTypeOrOpts: AlertType | FirebaseAlertOptions, - handler: (event: AlertEvent) => any | Promise + handler: OnAlertPublishedHandler ): CloudFunction> { const [opts, alertType, appId] = getOptsAndAlertTypeAndApp(alertTypeOrOpts); diff --git a/src/v2/providers/alerts/appDistribution.ts b/src/v2/providers/alerts/appDistribution.ts index a26c5e108..fca01ae75 100644 --- a/src/v2/providers/alerts/appDistribution.ts +++ b/src/v2/providers/alerts/appDistribution.ts @@ -197,13 +197,23 @@ export interface AppDistributionOptions extends options.EventHandlerOptions { retry?: boolean | Expression | ResetValue; } +/** Handler used by {@link onNewTesterIosDevicePublished}. */ +export type OnNewTesterIosDevicePublishedHandler = ( + event: AppDistributionEvent +) => any | Promise; + +/** Handler used by {@link onInAppFeedbackPublished}. */ +export type OnInAppFeedbackPublishedHandler = ( + event: AppDistributionEvent +) => any | Promise; + /** * Declares a function that can handle adding a new tester iOS device. * @param handler - Event handler which is run every time a new tester iOS device is added. * @returns A function that you can export and deploy. */ export function onNewTesterIosDevicePublished( - handler: (event: AppDistributionEvent) => any | Promise + handler: OnNewTesterIosDevicePublishedHandler ): CloudFunction>; /** @@ -214,7 +224,7 @@ export function onNewTesterIosDevicePublished( */ export function onNewTesterIosDevicePublished( appId: string, - handler: (event: AppDistributionEvent) => any | Promise + handler: OnNewTesterIosDevicePublishedHandler ): CloudFunction>; /** @@ -225,7 +235,7 @@ export function onNewTesterIosDevicePublished( */ export function onNewTesterIosDevicePublished( opts: AppDistributionOptions, - handler: (event: AppDistributionEvent) => any | Promise + handler: OnNewTesterIosDevicePublishedHandler ): CloudFunction>; /** @@ -235,11 +245,8 @@ export function onNewTesterIosDevicePublished( * @returns A function that you can export and deploy. */ export function onNewTesterIosDevicePublished( - appIdOrOptsOrHandler: - | string - | AppDistributionOptions - | ((event: AppDistributionEvent) => any | Promise), - handler?: (event: AppDistributionEvent) => any | Promise + appIdOrOptsOrHandler: string | AppDistributionOptions | OnNewTesterIosDevicePublishedHandler, + handler?: OnNewTesterIosDevicePublishedHandler ): CloudFunction> { if (typeof appIdOrOptsOrHandler === "function") { handler = appIdOrOptsOrHandler as ( @@ -268,7 +275,7 @@ export function onNewTesterIosDevicePublished( * @returns A function that you can export and deploy. */ export function onInAppFeedbackPublished( - handler: (event: AppDistributionEvent) => any | Promise + handler: OnInAppFeedbackPublishedHandler ): CloudFunction>; /** @@ -279,7 +286,7 @@ export function onInAppFeedbackPublished( */ export function onInAppFeedbackPublished( appId: string, - handler: (event: AppDistributionEvent) => any | Promise + handler: OnInAppFeedbackPublishedHandler ): CloudFunction>; /** @@ -290,7 +297,7 @@ export function onInAppFeedbackPublished( */ export function onInAppFeedbackPublished( opts: AppDistributionOptions, - handler: (event: AppDistributionEvent) => any | Promise + handler: OnInAppFeedbackPublishedHandler ): CloudFunction>; /** @@ -300,11 +307,8 @@ export function onInAppFeedbackPublished( * @returns A function that you can export and deploy. */ export function onInAppFeedbackPublished( - appIdOrOptsOrHandler: - | string - | AppDistributionOptions - | ((event: AppDistributionEvent) => any | Promise), - handler?: (event: AppDistributionEvent) => any | Promise + appIdOrOptsOrHandler: string | AppDistributionOptions | OnInAppFeedbackPublishedHandler, + handler?: OnInAppFeedbackPublishedHandler ): CloudFunction> { if (typeof appIdOrOptsOrHandler === "function") { handler = appIdOrOptsOrHandler as ( diff --git a/src/v2/providers/alerts/billing.ts b/src/v2/providers/alerts/billing.ts index 8bdb10d3d..a09df2219 100644 --- a/src/v2/providers/alerts/billing.ts +++ b/src/v2/providers/alerts/billing.ts @@ -71,13 +71,26 @@ export const planUpdateAlert = "billing.planUpdate"; /** @internal */ export const planAutomatedUpdateAlert = "billing.planAutomatedUpdate"; +/** Handler used by {@link onPlanUpdatePublished}. */ +export type OnPlanUpdatePublishedHandler = ( + event: BillingEvent +) => any | Promise; + +/** Handler used by {@link onPlanAutomatedUpdatePublished}. */ +export type OnPlanAutomatedUpdatePublishedHandler = ( + event: BillingEvent +) => any | Promise; + +/** Handler used by internal billing alert operations. */ +export type OnBillingOperationHandler = (event: BillingEvent) => any | Promise; + /** * Declares a function that can handle a billing plan update event. * @param handler - Event handler which is run every time a billing plan is updated. * @returns A function that you can export and deploy. */ export function onPlanUpdatePublished( - handler: (event: BillingEvent) => any | Promise + handler: OnPlanUpdatePublishedHandler ): CloudFunction>; /** @@ -88,7 +101,7 @@ export function onPlanUpdatePublished( */ export function onPlanUpdatePublished( opts: options.EventHandlerOptions, - handler: (event: BillingEvent) => any | Promise + handler: OnPlanUpdatePublishedHandler ): CloudFunction>; /** @@ -98,10 +111,8 @@ export function onPlanUpdatePublished( * @returns A function that you can export and deploy. */ export function onPlanUpdatePublished( - optsOrHandler: - | options.EventHandlerOptions - | ((event: BillingEvent) => any | Promise), - handler?: (event: BillingEvent) => any | Promise + optsOrHandler: options.EventHandlerOptions | OnPlanUpdatePublishedHandler, + handler?: OnPlanUpdatePublishedHandler ): CloudFunction> { return onOperation(planUpdateAlert, optsOrHandler, handler); } @@ -112,7 +123,7 @@ export function onPlanUpdatePublished( * @returns A function that you can export and deploy. */ export function onPlanAutomatedUpdatePublished( - handler: (event: BillingEvent) => any | Promise + handler: OnPlanAutomatedUpdatePublishedHandler ): CloudFunction>; /** @@ -123,7 +134,7 @@ export function onPlanAutomatedUpdatePublished( */ export function onPlanAutomatedUpdatePublished( opts: options.EventHandlerOptions, - handler: (event: BillingEvent) => any | Promise + handler: OnPlanAutomatedUpdatePublishedHandler ): CloudFunction>; /** @@ -133,10 +144,8 @@ export function onPlanAutomatedUpdatePublished( * @returns A function that you can export and deploy. */ export function onPlanAutomatedUpdatePublished( - optsOrHandler: - | options.EventHandlerOptions - | ((event: BillingEvent) => any | Promise), - handler?: (event: BillingEvent) => any | Promise + optsOrHandler: options.EventHandlerOptions | OnPlanAutomatedUpdatePublishedHandler, + handler?: OnPlanAutomatedUpdatePublishedHandler ): CloudFunction> { return onOperation(planAutomatedUpdateAlert, optsOrHandler, handler); } @@ -144,11 +153,11 @@ export function onPlanAutomatedUpdatePublished( /** @internal */ export function onOperation( alertType: string, - optsOrHandler: options.EventHandlerOptions | ((event: BillingEvent) => any | Promise), - handler: (event: BillingEvent) => any | Promise + optsOrHandler: options.EventHandlerOptions | OnBillingOperationHandler, + handler: OnBillingOperationHandler ): CloudFunction> { if (typeof optsOrHandler === "function") { - handler = optsOrHandler as (event: BillingEvent) => any | Promise; + handler = optsOrHandler as OnBillingOperationHandler; optsOrHandler = {}; } diff --git a/src/v2/providers/alerts/crashlytics.ts b/src/v2/providers/alerts/crashlytics.ts index 638b7f18e..aee791f6d 100644 --- a/src/v2/providers/alerts/crashlytics.ts +++ b/src/v2/providers/alerts/crashlytics.ts @@ -277,13 +277,46 @@ export interface CrashlyticsOptions extends options.EventHandlerOptions { retry?: boolean | Expression | ResetValue; } +/** Handler used by {@link onNewFatalIssuePublished}. */ +export type OnNewFatalIssuePublishedHandler = ( + event: CrashlyticsEvent +) => any | Promise; + +/** Handler used by {@link onNewNonfatalIssuePublished}. */ +export type OnNewNonfatalIssuePublishedHandler = ( + event: CrashlyticsEvent +) => any | Promise; + +/** Handler used by {@link onRegressionAlertPublished}. */ +export type OnRegressionAlertPublishedHandler = ( + event: CrashlyticsEvent +) => any | Promise; + +/** Handler used by {@link onStabilityDigestPublished}. */ +export type OnStabilityDigestPublishedHandler = ( + event: CrashlyticsEvent +) => any | Promise; + +/** Handler used by {@link onVelocityAlertPublished}. */ +export type OnVelocityAlertPublishedHandler = ( + event: CrashlyticsEvent +) => any | Promise; + +/** Handler used by {@link onNewAnrIssuePublished}. */ +export type OnNewAnrIssuePublishedHandler = ( + event: CrashlyticsEvent +) => any | Promise; + +/** Handler used by internal Crashlytics alert operations. */ +export type OnCrashlyticsOperationHandler = (event: CrashlyticsEvent) => any | Promise; + /** * Declares a function that can handle a new fatal issue published to Crashlytics. * @param handler - Event handler that is triggered when a new fatal issue is published to Crashlytics. * @returns A function that you can export and deploy. */ export function onNewFatalIssuePublished( - handler: (event: CrashlyticsEvent) => any | Promise + handler: OnNewFatalIssuePublishedHandler ): CloudFunction>; /** @@ -294,7 +327,7 @@ export function onNewFatalIssuePublished( */ export function onNewFatalIssuePublished( appId: string, - handler: (event: CrashlyticsEvent) => any | Promise + handler: OnNewFatalIssuePublishedHandler ): CloudFunction>; /** @@ -305,7 +338,7 @@ export function onNewFatalIssuePublished( */ export function onNewFatalIssuePublished( opts: CrashlyticsOptions, - handler: (event: CrashlyticsEvent) => any | Promise + handler: OnNewFatalIssuePublishedHandler ): CloudFunction>; /** @@ -315,11 +348,8 @@ export function onNewFatalIssuePublished( * @returns A function that you can export and deploy. */ export function onNewFatalIssuePublished( - appIdOrOptsOrHandler: - | string - | CrashlyticsOptions - | ((event: CrashlyticsEvent) => any | Promise), - handler?: (event: CrashlyticsEvent) => any | Promise + appIdOrOptsOrHandler: string | CrashlyticsOptions | OnNewFatalIssuePublishedHandler, + handler?: OnNewFatalIssuePublishedHandler ): CloudFunction> { return onOperation(newFatalIssueAlert, appIdOrOptsOrHandler, handler); } @@ -330,7 +360,7 @@ export function onNewFatalIssuePublished( * @returns A function that you can export and deploy. */ export function onNewNonfatalIssuePublished( - handler: (event: CrashlyticsEvent) => any | Promise + handler: OnNewNonfatalIssuePublishedHandler ): CloudFunction>; /** @@ -341,7 +371,7 @@ export function onNewNonfatalIssuePublished( */ export function onNewNonfatalIssuePublished( appId: string, - handler: (event: CrashlyticsEvent) => any | Promise + handler: OnNewNonfatalIssuePublishedHandler ): CloudFunction>; /** @@ -352,7 +382,7 @@ export function onNewNonfatalIssuePublished( */ export function onNewNonfatalIssuePublished( opts: CrashlyticsOptions, - handler: (event: CrashlyticsEvent) => any | Promise + handler: OnNewNonfatalIssuePublishedHandler ): CloudFunction>; /** @@ -362,11 +392,8 @@ export function onNewNonfatalIssuePublished( * @returns A function that you can export and deploy. */ export function onNewNonfatalIssuePublished( - appIdOrOptsOrHandler: - | string - | CrashlyticsOptions - | ((event: CrashlyticsEvent) => any | Promise), - handler?: (event: CrashlyticsEvent) => any | Promise + appIdOrOptsOrHandler: string | CrashlyticsOptions | OnNewNonfatalIssuePublishedHandler, + handler?: OnNewNonfatalIssuePublishedHandler ): CloudFunction> { return onOperation(newNonfatalIssueAlert, appIdOrOptsOrHandler, handler); } @@ -377,7 +404,7 @@ export function onNewNonfatalIssuePublished( * @returns A function that you can export and deploy. */ export function onRegressionAlertPublished( - handler: (event: CrashlyticsEvent) => any | Promise + handler: OnRegressionAlertPublishedHandler ): CloudFunction>; /** @@ -389,7 +416,7 @@ export function onRegressionAlertPublished( */ export function onRegressionAlertPublished( appId: string, - handler: (event: CrashlyticsEvent) => any | Promise + handler: OnRegressionAlertPublishedHandler ): CloudFunction>; /** @@ -401,7 +428,7 @@ export function onRegressionAlertPublished( */ export function onRegressionAlertPublished( opts: CrashlyticsOptions, - handler: (event: CrashlyticsEvent) => any | Promise + handler: OnRegressionAlertPublishedHandler ): CloudFunction>; /** @@ -411,11 +438,8 @@ export function onRegressionAlertPublished( * @returns A function that you can export and deploy. */ export function onRegressionAlertPublished( - appIdOrOptsOrHandler: - | string - | CrashlyticsOptions - | ((event: CrashlyticsEvent) => any | Promise), - handler?: (event: CrashlyticsEvent) => any | Promise + appIdOrOptsOrHandler: string | CrashlyticsOptions | OnRegressionAlertPublishedHandler, + handler?: OnRegressionAlertPublishedHandler ): CloudFunction> { return onOperation(regressionAlert, appIdOrOptsOrHandler, handler); } @@ -426,7 +450,7 @@ export function onRegressionAlertPublished( * @returns A function that you can export and deploy. */ export function onStabilityDigestPublished( - handler: (event: CrashlyticsEvent) => any | Promise + handler: OnStabilityDigestPublishedHandler ): CloudFunction>; /** @@ -438,7 +462,7 @@ export function onStabilityDigestPublished( */ export function onStabilityDigestPublished( appId: string, - handler: (event: CrashlyticsEvent) => any | Promise + handler: OnStabilityDigestPublishedHandler ): CloudFunction>; /** @@ -450,7 +474,7 @@ export function onStabilityDigestPublished( */ export function onStabilityDigestPublished( opts: CrashlyticsOptions, - handler: (event: CrashlyticsEvent) => any | Promise + handler: OnStabilityDigestPublishedHandler ): CloudFunction>; /** @@ -460,11 +484,8 @@ export function onStabilityDigestPublished( * @returns A function that you can export and deploy. */ export function onStabilityDigestPublished( - appIdOrOptsOrHandler: - | string - | CrashlyticsOptions - | ((event: CrashlyticsEvent) => any | Promise), - handler?: (event: CrashlyticsEvent) => any | Promise + appIdOrOptsOrHandler: string | CrashlyticsOptions | OnStabilityDigestPublishedHandler, + handler?: OnStabilityDigestPublishedHandler ): CloudFunction> { return onOperation(stabilityDigestAlert, appIdOrOptsOrHandler, handler); } @@ -475,7 +496,7 @@ export function onStabilityDigestPublished( * @returns A function that you can export and deploy. */ export function onVelocityAlertPublished( - handler: (event: CrashlyticsEvent) => any | Promise + handler: OnVelocityAlertPublishedHandler ): CloudFunction>; /** @@ -486,7 +507,7 @@ export function onVelocityAlertPublished( */ export function onVelocityAlertPublished( appId: string, - handler: (event: CrashlyticsEvent) => any | Promise + handler: OnVelocityAlertPublishedHandler ): CloudFunction>; /** @@ -497,7 +518,7 @@ export function onVelocityAlertPublished( */ export function onVelocityAlertPublished( opts: CrashlyticsOptions, - handler: (event: CrashlyticsEvent) => any | Promise + handler: OnVelocityAlertPublishedHandler ): CloudFunction>; /** @@ -507,11 +528,8 @@ export function onVelocityAlertPublished( * @returns A function that you can export and deploy. */ export function onVelocityAlertPublished( - appIdOrOptsOrHandler: - | string - | CrashlyticsOptions - | ((event: CrashlyticsEvent) => any | Promise), - handler?: (event: CrashlyticsEvent) => any | Promise + appIdOrOptsOrHandler: string | CrashlyticsOptions | OnVelocityAlertPublishedHandler, + handler?: OnVelocityAlertPublishedHandler ): CloudFunction> { return onOperation(velocityAlert, appIdOrOptsOrHandler, handler); } @@ -522,7 +540,7 @@ export function onVelocityAlertPublished( * @returns A function that you can export and deploy. */ export function onNewAnrIssuePublished( - handler: (event: CrashlyticsEvent) => any | Promise + handler: OnNewAnrIssuePublishedHandler ): CloudFunction>; /** @@ -534,7 +552,7 @@ export function onNewAnrIssuePublished( */ export function onNewAnrIssuePublished( appId: string, - handler: (event: CrashlyticsEvent) => any | Promise + handler: OnNewAnrIssuePublishedHandler ): CloudFunction>; /** @@ -546,7 +564,7 @@ export function onNewAnrIssuePublished( */ export function onNewAnrIssuePublished( opts: CrashlyticsOptions, - handler: (event: CrashlyticsEvent) => any | Promise + handler: OnNewAnrIssuePublishedHandler ): CloudFunction>; /** @@ -556,11 +574,8 @@ export function onNewAnrIssuePublished( * @returns A function that you can export and deploy. */ export function onNewAnrIssuePublished( - appIdOrOptsOrHandler: - | string - | CrashlyticsOptions - | ((event: CrashlyticsEvent) => any | Promise), - handler?: (event: CrashlyticsEvent) => any | Promise + appIdOrOptsOrHandler: string | CrashlyticsOptions | OnNewAnrIssuePublishedHandler, + handler?: OnNewAnrIssuePublishedHandler ): CloudFunction> { return onOperation(newAnrIssueAlert, appIdOrOptsOrHandler, handler); } @@ -568,14 +583,11 @@ export function onNewAnrIssuePublished( /** @internal */ export function onOperation( alertType: string, - appIdOrOptsOrHandler: - | string - | CrashlyticsOptions - | ((event: CrashlyticsEvent) => any | Promise), - handler: (event: CrashlyticsEvent) => any | Promise + appIdOrOptsOrHandler: string | CrashlyticsOptions | OnCrashlyticsOperationHandler, + handler: OnCrashlyticsOperationHandler ): CloudFunction> { if (typeof appIdOrOptsOrHandler === "function") { - handler = appIdOrOptsOrHandler as (event: CrashlyticsEvent) => any | Promise; + handler = appIdOrOptsOrHandler as OnCrashlyticsOperationHandler; appIdOrOptsOrHandler = {}; } diff --git a/src/v2/providers/alerts/performance.ts b/src/v2/providers/alerts/performance.ts index 9ee3f7beb..a1935e9e3 100644 --- a/src/v2/providers/alerts/performance.ts +++ b/src/v2/providers/alerts/performance.ts @@ -82,13 +82,18 @@ export interface PerformanceOptions extends EventHandlerOptions { appId?: string; } +/** Handler used by {@link onThresholdAlertPublished}. */ +export type OnThresholdAlertPublishedHandler = ( + event: PerformanceEvent +) => any | Promise; + /** * Declares a function that can handle receiving performance threshold alerts. * @param handler - Event handler which is run every time a threshold alert is received. * @returns A function that you can export and deploy. */ export function onThresholdAlertPublished( - handler: (event: PerformanceEvent) => any | Promise + handler: OnThresholdAlertPublishedHandler ): CloudFunction>; /** @@ -99,7 +104,7 @@ export function onThresholdAlertPublished( */ export function onThresholdAlertPublished( appId: string, - handler: (event: PerformanceEvent) => any | Promise + handler: OnThresholdAlertPublishedHandler ): CloudFunction>; /** @@ -110,7 +115,7 @@ export function onThresholdAlertPublished( */ export function onThresholdAlertPublished( opts: PerformanceOptions, - handler: (event: PerformanceEvent) => any | Promise + handler: OnThresholdAlertPublishedHandler ): CloudFunction>; /** @@ -120,11 +125,8 @@ export function onThresholdAlertPublished( * @returns A function that you can export and deploy. */ export function onThresholdAlertPublished( - appIdOrOptsOrHandler: - | string - | PerformanceOptions - | ((event: PerformanceEvent) => any | Promise), - handler?: (event: PerformanceEvent) => any | Promise + appIdOrOptsOrHandler: string | PerformanceOptions | OnThresholdAlertPublishedHandler, + handler?: OnThresholdAlertPublishedHandler ): CloudFunction> { if (typeof appIdOrOptsOrHandler === "function") { handler = appIdOrOptsOrHandler as ( diff --git a/src/v2/providers/database.ts b/src/v2/providers/database.ts index 6c5f5e83c..a3311cc3e 100644 --- a/src/v2/providers/database.ts +++ b/src/v2/providers/database.ts @@ -218,6 +218,48 @@ export interface ReferenceOptions extends options.E retry?: boolean | Expression | ResetValue; } +/** Handler used by {@link onValueWritten}. */ +export type OnValueWrittenHandler = ( + event: DatabaseEvent, ParamsOf> +) => any | Promise; + +/** Handler used by {@link onValueWritten} when accessing v1-compatible fields. */ +export type OnValueWrittenHandlerWithContext = ( + event: DatabaseEvent, ParamsOf> & + V1Compat<"change", Change> +) => any | Promise; + +/** Handler used by {@link onValueCreated}. */ +export type OnValueCreatedHandler = ( + event: DatabaseEvent> +) => any | Promise; + +/** Handler used by {@link onValueCreated} when accessing v1-compatible fields. */ +export type OnValueCreatedHandlerWithContext = ( + event: DatabaseEvent> & V1Compat<"snapshot", DataSnapshot> +) => any | Promise; + +/** Handler used by {@link onValueUpdated}. */ +export type OnValueUpdatedHandler = OnValueWrittenHandler; + +/** Handler used by {@link onValueUpdated} when accessing v1-compatible fields. */ +export type OnValueUpdatedHandlerWithContext = + OnValueWrittenHandlerWithContext; + +/** Handler used by {@link onValueDeleted}. */ +export type OnValueDeletedHandler = OnValueCreatedHandler; + +/** Handler used by {@link onValueDeleted} when accessing v1-compatible fields. */ +export type OnValueDeletedHandlerWithContext = + OnValueCreatedHandlerWithContext; + +/** Handler used by internal changed Realtime Database operations. */ +export type OnChangedOperationHandler = + OnValueWrittenHandlerWithContext; + +/** Handler used by internal Realtime Database operations. */ +export type OnOperationHandler = OnValueCreatedHandlerWithContext; + /** * Event handler which triggers when data is created, updated, or deleted in Realtime Database. * @@ -226,10 +268,7 @@ export interface ReferenceOptions extends options.E */ export function onValueWritten( reference: Ref, - handler: ( - event: DatabaseEvent, ParamsOf> & - V1Compat<"change", Change> - ) => any | Promise + handler: OnValueWrittenHandlerWithContext ): CloudFunction, ParamsOf>>; /** @@ -240,7 +279,7 @@ export function onValueWritten( */ export function onValueWritten( reference: Ref, - handler: (event: DatabaseEvent, ParamsOf>) => any | Promise + handler: OnValueWrittenHandler ): CloudFunction, ParamsOf>>; /** @@ -251,10 +290,7 @@ export function onValueWritten( */ export function onValueWritten( opts: ReferenceOptions, - handler: ( - event: DatabaseEvent, ParamsOf> & - V1Compat<"change", Change> - ) => any | Promise + handler: OnValueWrittenHandlerWithContext ): CloudFunction, ParamsOf>>; /** @@ -265,7 +301,7 @@ export function onValueWritten( */ export function onValueWritten( opts: ReferenceOptions, - handler: (event: DatabaseEvent, ParamsOf>) => any | Promise + handler: OnValueWrittenHandler ): CloudFunction, ParamsOf>>; /** @@ -276,10 +312,7 @@ export function onValueWritten( */ export function onValueWritten( referenceOrOpts: Ref | ReferenceOptions, - handler: ( - event: DatabaseEvent, ParamsOf> & - V1Compat<"change", Change> - ) => any | Promise + handler: OnValueWrittenHandlerWithContext ): CloudFunction, ParamsOf>> { return onChangedOperation(writtenEventType, referenceOrOpts, handler); } @@ -292,9 +325,7 @@ export function onValueWritten( */ export function onValueCreated( reference: Ref, - handler: ( - event: DatabaseEvent> & V1Compat<"snapshot", DataSnapshot> - ) => any | Promise + handler: OnValueCreatedHandlerWithContext ): CloudFunction>>; /** @@ -305,7 +336,7 @@ export function onValueCreated( */ export function onValueCreated( reference: Ref, - handler: (event: DatabaseEvent>) => any | Promise + handler: OnValueCreatedHandler ): CloudFunction>>; /** @@ -316,9 +347,7 @@ export function onValueCreated( */ export function onValueCreated( opts: ReferenceOptions, - handler: ( - event: DatabaseEvent> & V1Compat<"snapshot", DataSnapshot> - ) => any | Promise + handler: OnValueCreatedHandlerWithContext ): CloudFunction>>; /** @@ -329,7 +358,7 @@ export function onValueCreated( */ export function onValueCreated( opts: ReferenceOptions, - handler: (event: DatabaseEvent>) => any | Promise + handler: OnValueCreatedHandler ): CloudFunction>>; /** @@ -340,9 +369,7 @@ export function onValueCreated( */ export function onValueCreated( referenceOrOpts: Ref | ReferenceOptions, - handler: ( - event: DatabaseEvent> & V1Compat<"snapshot", DataSnapshot> - ) => any | Promise + handler: OnValueCreatedHandlerWithContext ): CloudFunction>> { return onOperation(createdEventType, referenceOrOpts, handler); } @@ -355,10 +382,7 @@ export function onValueCreated( */ export function onValueUpdated( reference: Ref, - handler: ( - event: DatabaseEvent, ParamsOf> & - V1Compat<"change", Change> - ) => any | Promise + handler: OnValueUpdatedHandlerWithContext ): CloudFunction, ParamsOf>>; /** @@ -369,7 +393,7 @@ export function onValueUpdated( */ export function onValueUpdated( reference: Ref, - handler: (event: DatabaseEvent, ParamsOf>) => any | Promise + handler: OnValueUpdatedHandler ): CloudFunction, ParamsOf>>; /** @@ -380,10 +404,7 @@ export function onValueUpdated( */ export function onValueUpdated( opts: ReferenceOptions, - handler: ( - event: DatabaseEvent, ParamsOf> & - V1Compat<"change", Change> - ) => any | Promise + handler: OnValueUpdatedHandlerWithContext ): CloudFunction, ParamsOf>>; /** @@ -394,7 +415,7 @@ export function onValueUpdated( */ export function onValueUpdated( opts: ReferenceOptions, - handler: (event: DatabaseEvent, ParamsOf>) => any | Promise + handler: OnValueUpdatedHandler ): CloudFunction, ParamsOf>>; /** @@ -405,10 +426,7 @@ export function onValueUpdated( */ export function onValueUpdated( referenceOrOpts: Ref | ReferenceOptions, - handler: ( - event: DatabaseEvent, ParamsOf> & - V1Compat<"change", Change> - ) => any | Promise + handler: OnValueUpdatedHandlerWithContext ): CloudFunction, ParamsOf>> { return onChangedOperation(updatedEventType, referenceOrOpts, handler); } @@ -421,9 +439,7 @@ export function onValueUpdated( */ export function onValueDeleted( reference: Ref, - handler: ( - event: DatabaseEvent> & V1Compat<"snapshot", DataSnapshot> - ) => any | Promise + handler: OnValueDeletedHandlerWithContext ): CloudFunction>>; /** @@ -434,7 +450,7 @@ export function onValueDeleted( */ export function onValueDeleted( reference: Ref, - handler: (event: DatabaseEvent>) => any | Promise + handler: OnValueDeletedHandler ): CloudFunction>>; /** @@ -445,9 +461,7 @@ export function onValueDeleted( */ export function onValueDeleted( opts: ReferenceOptions, - handler: ( - event: DatabaseEvent> & V1Compat<"snapshot", DataSnapshot> - ) => any | Promise + handler: OnValueDeletedHandlerWithContext ): CloudFunction>>; /** @@ -458,7 +472,7 @@ export function onValueDeleted( */ export function onValueDeleted( opts: ReferenceOptions, - handler: (event: DatabaseEvent>) => any | Promise + handler: OnValueDeletedHandler ): CloudFunction>>; /** @@ -469,9 +483,7 @@ export function onValueDeleted( */ export function onValueDeleted( referenceOrOpts: Ref | ReferenceOptions, - handler: ( - event: DatabaseEvent> & V1Compat<"snapshot", DataSnapshot> - ) => any | Promise + handler: OnValueDeletedHandlerWithContext ): CloudFunction>> { // TODO - need to use event.data.delta return onOperation(deletedEventType, referenceOrOpts, handler); @@ -636,7 +648,7 @@ export function makeEndpoint( export function onChangedOperation( eventType: string, referenceOrOpts: Ref | ReferenceOptions, - handler: (event: any) => any | Promise + handler: OnChangedOperationHandler ): CloudFunction, ParamsOf>> { const { path, instance, opts } = getOpts(referenceOrOpts); @@ -671,7 +683,7 @@ export function onChangedOperation( export function onOperation( eventType: string, referenceOrOpts: Ref | ReferenceOptions, - handler: (event: any) => any | Promise + handler: OnOperationHandler ): CloudFunction>> { const { path, instance, opts } = getOpts(referenceOrOpts); diff --git a/src/v2/providers/dataconnect/index.ts b/src/v2/providers/dataconnect/index.ts index 5d88dd2bd..452878f68 100644 --- a/src/v2/providers/dataconnect/index.ts +++ b/src/v2/providers/dataconnect/index.ts @@ -139,6 +139,18 @@ export interface DataConnectEvent> exten authId?: string; } +/** Handler used by {@link onMutationExecuted}. */ +export type OnMutationExecutedHandler< + PathPatternOrOptions extends string | OperationOptions, + Variables = unknown, + ResponseData = unknown +> = ( + event: DataConnectEvent< + MutationEventData, + DataConnectParams + > +) => unknown | Promise; + /** * Event handler that triggers when a mutation is executed in Firebase Data Connect. * @@ -151,9 +163,7 @@ export function onMutationExecuted< ResponseData = unknown >( mutation: Mutation, - handler: ( - event: DataConnectEvent, DataConnectParams> - ) => unknown | Promise + handler: OnMutationExecutedHandler ): CloudFunction< DataConnectEvent, DataConnectParams> >; @@ -170,9 +180,7 @@ export function onMutationExecuted< ResponseData = unknown >( opts: Options, - handler: ( - event: DataConnectEvent, DataConnectParams> - ) => unknown | Promise + handler: OnMutationExecutedHandler ): CloudFunction< DataConnectEvent, DataConnectParams> >; @@ -189,12 +197,7 @@ export function onMutationExecuted< ResponseData = unknown >( mutationOrOpts: PathPatternOrOptions, - handler: ( - event: DataConnectEvent< - MutationEventData, - DataConnectParams - > - ) => unknown | Promise + handler: OnMutationExecutedHandler ): CloudFunction< DataConnectEvent< MutationEventData, diff --git a/src/v2/providers/eventarc.ts b/src/v2/providers/eventarc.ts index f00597bab..36ffaff38 100644 --- a/src/v2/providers/eventarc.ts +++ b/src/v2/providers/eventarc.ts @@ -162,6 +162,9 @@ export interface EventarcTriggerOptions extends options.EventHandlerOptions { retry?: boolean | Expression | ResetValue; } +/** Handler used by {@link onCustomEventPublished}. */ +export type OnCustomEventPublishedHandler = (event: CloudEvent) => any | Promise; + /** Handles an Eventarc event published on the default channel. * @param eventType - Type of the event to trigger on. * @param handler - A function to execute when triggered. @@ -169,7 +172,7 @@ export interface EventarcTriggerOptions extends options.EventHandlerOptions { */ export function onCustomEventPublished( eventType: string, - handler: (event: CloudEvent) => any | Promise + handler: OnCustomEventPublishedHandler ): CloudFunction>; /** Handles an Eventarc event. @@ -179,12 +182,12 @@ export function onCustomEventPublished( */ export function onCustomEventPublished( opts: EventarcTriggerOptions, - handler: (event: CloudEvent) => any | Promise + handler: OnCustomEventPublishedHandler ): CloudFunction>; export function onCustomEventPublished( eventTypeOrOpts: string | EventarcTriggerOptions, - handler: (event: CloudEvent) => any | Promise + handler: OnCustomEventPublishedHandler ): CloudFunction> { let opts: EventarcTriggerOptions; if (typeof eventTypeOrOpts === "string") { diff --git a/src/v2/providers/firestore.ts b/src/v2/providers/firestore.ts index a7b7ffb81..6acd9c05d 100644 --- a/src/v2/providers/firestore.ts +++ b/src/v2/providers/firestore.ts @@ -155,6 +155,94 @@ export interface DocumentOptions extends Event namespace?: string | Expression; } +/** Handler used by {@link onDocumentWritten}. */ +export type OnDocumentWrittenHandler = ( + event: FirestoreEvent | undefined, ParamsOf> +) => any | Promise; + +/** Handler used by {@link onDocumentWritten} when accessing v1-compatible fields. */ +export type OnDocumentWrittenHandlerWithContext = ( + event: FirestoreEvent | undefined, ParamsOf> & + V1Compat<"change", Change> +) => any | Promise; + +/** Handler used by {@link onDocumentWrittenWithAuthContext}. */ +export type OnDocumentWrittenWithAuthContextHandler = ( + event: FirestoreAuthEvent | undefined, ParamsOf> +) => any | Promise; + +/** Handler used by {@link onDocumentWrittenWithAuthContext} when accessing v1-compatible fields. */ +export type OnDocumentWrittenWithAuthContextHandlerWithContext = ( + event: FirestoreAuthEvent | undefined, ParamsOf> & + V1Compat<"change", Change> +) => any | Promise; + +/** Handler used by {@link onDocumentCreated}. */ +export type OnDocumentCreatedHandler = ( + event: FirestoreEvent> +) => any | Promise; + +/** Handler used by {@link onDocumentCreated} when accessing v1-compatible fields. */ +export type OnDocumentCreatedHandlerWithContext = ( + event: FirestoreEvent> & + V1Compat<"snapshot", QueryDocumentSnapshot> +) => any | Promise; + +/** Handler used by {@link onDocumentCreatedWithAuthContext}. */ +export type OnDocumentCreatedWithAuthContextHandler = ( + event: FirestoreAuthEvent> +) => any | Promise; + +/** Handler used by {@link onDocumentCreatedWithAuthContext} when accessing v1-compatible fields. */ +export type OnDocumentCreatedWithAuthContextHandlerWithContext = ( + event: FirestoreAuthEvent> & + V1Compat<"snapshot", QueryDocumentSnapshot> +) => any | Promise; + +/** Handler used by {@link onDocumentUpdated}. */ +export type OnDocumentUpdatedHandler = ( + event: FirestoreEvent | undefined, ParamsOf> +) => any | Promise; + +/** Handler used by {@link onDocumentUpdated} when accessing v1-compatible fields. */ +export type OnDocumentUpdatedHandlerWithContext = ( + event: FirestoreEvent | undefined, ParamsOf> & + V1Compat<"change", Change> +) => any | Promise; + +/** Handler used by {@link onDocumentUpdatedWithAuthContext}. */ +export type OnDocumentUpdatedWithAuthContextHandler = ( + event: FirestoreAuthEvent | undefined, ParamsOf> +) => any | Promise; + +/** Handler used by {@link onDocumentUpdatedWithAuthContext} when accessing v1-compatible fields. */ +export type OnDocumentUpdatedWithAuthContextHandlerWithContext = ( + event: FirestoreAuthEvent | undefined, ParamsOf> & + V1Compat<"change", Change> +) => any | Promise; + +/** Handler used by {@link onDocumentDeleted}. */ +export type OnDocumentDeletedHandler = + OnDocumentCreatedHandler; + +/** Handler used by {@link onDocumentDeleted} when accessing v1-compatible fields. */ +export type OnDocumentDeletedHandlerWithContext = + OnDocumentCreatedHandlerWithContext; + +/** Handler used by {@link onDocumentDeletedWithAuthContext}. */ +export type OnDocumentDeletedWithAuthContextHandler = + OnDocumentCreatedWithAuthContextHandler; + +/** Handler used by {@link onDocumentDeletedWithAuthContext} when accessing v1-compatible fields. */ +export type OnDocumentDeletedWithAuthContextHandlerWithContext = + OnDocumentCreatedWithAuthContextHandlerWithContext; + +/** Handler used by internal Firestore operations. */ +export type OnOperationHandler = (event: Event) => any | Promise; + +/** Handler used by internal changed Firestore operations. */ +export type OnChangedOperationHandler = (event: Event) => any | Promise; + /** * Event handler that triggers when a document is created, updated, or deleted in Firestore. * @@ -163,10 +251,7 @@ export interface DocumentOptions extends Event */ export function onDocumentWritten( document: Document, - handler: ( - event: FirestoreEvent | undefined, ParamsOf> & - V1Compat<"change", Change> - ) => any | Promise + handler: OnDocumentWrittenHandlerWithContext ): CloudFunction | undefined, ParamsOf>>; /** @@ -177,9 +262,7 @@ export function onDocumentWritten( */ export function onDocumentWritten( document: Document, - handler: ( - event: FirestoreEvent | undefined, ParamsOf> - ) => any | Promise + handler: OnDocumentWrittenHandler ): CloudFunction | undefined, ParamsOf>>; /** @@ -190,10 +273,7 @@ export function onDocumentWritten( */ export function onDocumentWritten( opts: DocumentOptions, - handler: ( - event: FirestoreEvent | undefined, ParamsOf> & - V1Compat<"change", Change> - ) => any | Promise + handler: OnDocumentWrittenHandlerWithContext ): CloudFunction | undefined, ParamsOf>>; /** @@ -204,9 +284,7 @@ export function onDocumentWritten( */ export function onDocumentWritten( opts: DocumentOptions, - handler: ( - event: FirestoreEvent | undefined, ParamsOf> - ) => any | Promise + handler: OnDocumentWrittenHandler ): CloudFunction | undefined, ParamsOf>>; /** @@ -217,10 +295,7 @@ export function onDocumentWritten( */ export function onDocumentWritten( documentOrOpts: Document | DocumentOptions, - handler: ( - event: FirestoreEvent | undefined, ParamsOf> & - V1Compat<"change", Change> - ) => any | Promise + handler: OnDocumentWrittenHandlerWithContext ): CloudFunction | undefined, ParamsOf>> { return onChangedOperation(writtenEventType, documentOrOpts, handler); } @@ -234,10 +309,7 @@ export function onDocumentWritten( */ export function onDocumentWrittenWithAuthContext( document: Document, - handler: ( - event: FirestoreAuthEvent | undefined, ParamsOf> & - V1Compat<"change", Change> - ) => any | Promise + handler: OnDocumentWrittenWithAuthContextHandlerWithContext ): CloudFunction | undefined, ParamsOf>>; /** @@ -249,9 +321,7 @@ export function onDocumentWrittenWithAuthContext( */ export function onDocumentWrittenWithAuthContext( document: Document, - handler: ( - event: FirestoreAuthEvent | undefined, ParamsOf> - ) => any | Promise + handler: OnDocumentWrittenWithAuthContextHandler ): CloudFunction | undefined, ParamsOf>>; /** @@ -263,10 +333,7 @@ export function onDocumentWrittenWithAuthContext( */ export function onDocumentWrittenWithAuthContext( opts: DocumentOptions, - handler: ( - event: FirestoreAuthEvent | undefined, ParamsOf> & - V1Compat<"change", Change> - ) => any | Promise + handler: OnDocumentWrittenWithAuthContextHandlerWithContext ): CloudFunction | undefined, ParamsOf>>; /** @@ -278,9 +345,7 @@ export function onDocumentWrittenWithAuthContext( */ export function onDocumentWrittenWithAuthContext( opts: DocumentOptions, - handler: ( - event: FirestoreAuthEvent | undefined, ParamsOf> - ) => any | Promise + handler: OnDocumentWrittenWithAuthContextHandler ): CloudFunction | undefined, ParamsOf>>; /** @@ -292,10 +357,7 @@ export function onDocumentWrittenWithAuthContext( */ export function onDocumentWrittenWithAuthContext( documentOrOpts: Document | DocumentOptions, - handler: ( - event: FirestoreAuthEvent | undefined, ParamsOf> & - V1Compat<"change", Change> - ) => any | Promise + handler: OnDocumentWrittenWithAuthContextHandlerWithContext ): CloudFunction | undefined, ParamsOf>> { return onChangedOperation(writtenEventWithAuthContextType, documentOrOpts, handler); } @@ -308,10 +370,7 @@ export function onDocumentWrittenWithAuthContext( */ export function onDocumentCreated( document: Document, - handler: ( - event: FirestoreEvent> & - V1Compat<"snapshot", QueryDocumentSnapshot> - ) => any | Promise + handler: OnDocumentCreatedHandlerWithContext ): CloudFunction>>; /** @@ -322,9 +381,7 @@ export function onDocumentCreated( */ export function onDocumentCreated( document: Document, - handler: ( - event: FirestoreEvent> - ) => any | Promise + handler: OnDocumentCreatedHandler ): CloudFunction>>; /** @@ -335,10 +392,7 @@ export function onDocumentCreated( */ export function onDocumentCreated( opts: DocumentOptions, - handler: ( - event: FirestoreEvent> & - V1Compat<"snapshot", QueryDocumentSnapshot> - ) => any | Promise + handler: OnDocumentCreatedHandlerWithContext ): CloudFunction>>; /** @@ -349,9 +403,7 @@ export function onDocumentCreated( */ export function onDocumentCreated( opts: DocumentOptions, - handler: ( - event: FirestoreEvent> - ) => any | Promise + handler: OnDocumentCreatedHandler ): CloudFunction>>; /** @@ -362,10 +414,7 @@ export function onDocumentCreated( */ export function onDocumentCreated( documentOrOpts: Document | DocumentOptions, - handler: ( - event: FirestoreEvent> & - V1Compat<"snapshot", QueryDocumentSnapshot> - ) => any | Promise + handler: OnDocumentCreatedHandlerWithContext ): CloudFunction>> { return onOperation(createdEventType, documentOrOpts, handler); } @@ -379,10 +428,7 @@ export function onDocumentCreated( */ export function onDocumentCreatedWithAuthContext( document: Document, - handler: ( - event: FirestoreAuthEvent> & - V1Compat<"snapshot", QueryDocumentSnapshot> - ) => any | Promise + handler: OnDocumentCreatedWithAuthContextHandlerWithContext ): CloudFunction>>; /** @@ -394,9 +440,7 @@ export function onDocumentCreatedWithAuthContext( */ export function onDocumentCreatedWithAuthContext( document: Document, - handler: ( - event: FirestoreAuthEvent> - ) => any | Promise + handler: OnDocumentCreatedWithAuthContextHandler ): CloudFunction>>; /** @@ -408,10 +452,7 @@ export function onDocumentCreatedWithAuthContext( */ export function onDocumentCreatedWithAuthContext( opts: DocumentOptions, - handler: ( - event: FirestoreAuthEvent> & - V1Compat<"snapshot", QueryDocumentSnapshot> - ) => any | Promise + handler: OnDocumentCreatedWithAuthContextHandlerWithContext ): CloudFunction>>; /** @@ -423,9 +464,7 @@ export function onDocumentCreatedWithAuthContext( */ export function onDocumentCreatedWithAuthContext( opts: DocumentOptions, - handler: ( - event: FirestoreAuthEvent> - ) => any | Promise + handler: OnDocumentCreatedWithAuthContextHandler ): CloudFunction>>; /** @@ -436,10 +475,7 @@ export function onDocumentCreatedWithAuthContext( */ export function onDocumentCreatedWithAuthContext( documentOrOpts: Document | DocumentOptions, - handler: ( - event: FirestoreAuthEvent> & - V1Compat<"snapshot", QueryDocumentSnapshot> - ) => any | Promise + handler: OnDocumentCreatedWithAuthContextHandlerWithContext ): CloudFunction>> { return onOperation(createdEventWithAuthContextType, documentOrOpts, handler); } @@ -452,10 +488,7 @@ export function onDocumentCreatedWithAuthContext( */ export function onDocumentUpdated( document: Document, - handler: ( - event: FirestoreEvent | undefined, ParamsOf> & - V1Compat<"change", Change> - ) => any | Promise + handler: OnDocumentUpdatedHandlerWithContext ): CloudFunction | undefined, ParamsOf>>; /** @@ -466,9 +499,7 @@ export function onDocumentUpdated( */ export function onDocumentUpdated( document: Document, - handler: ( - event: FirestoreEvent | undefined, ParamsOf> - ) => any | Promise + handler: OnDocumentUpdatedHandler ): CloudFunction | undefined, ParamsOf>>; /** @@ -479,10 +510,7 @@ export function onDocumentUpdated( */ export function onDocumentUpdated( opts: DocumentOptions, - handler: ( - event: FirestoreEvent | undefined, ParamsOf> & - V1Compat<"change", Change> - ) => any | Promise + handler: OnDocumentUpdatedHandlerWithContext ): CloudFunction | undefined, ParamsOf>>; /** @@ -493,9 +521,7 @@ export function onDocumentUpdated( */ export function onDocumentUpdated( opts: DocumentOptions, - handler: ( - event: FirestoreEvent | undefined, ParamsOf> - ) => any | Promise + handler: OnDocumentUpdatedHandler ): CloudFunction | undefined, ParamsOf>>; /** @@ -506,10 +532,7 @@ export function onDocumentUpdated( */ export function onDocumentUpdated( documentOrOpts: Document | DocumentOptions, - handler: ( - event: FirestoreEvent | undefined, ParamsOf> & - V1Compat<"change", Change> - ) => any | Promise + handler: OnDocumentUpdatedHandlerWithContext ): CloudFunction | undefined, ParamsOf>> { return onChangedOperation(updatedEventType, documentOrOpts, handler); } @@ -523,10 +546,7 @@ export function onDocumentUpdated( */ export function onDocumentUpdatedWithAuthContext( document: Document, - handler: ( - event: FirestoreAuthEvent | undefined, ParamsOf> & - V1Compat<"change", Change> - ) => any | Promise + handler: OnDocumentUpdatedWithAuthContextHandlerWithContext ): CloudFunction | undefined, ParamsOf>>; /** @@ -538,9 +558,7 @@ export function onDocumentUpdatedWithAuthContext( */ export function onDocumentUpdatedWithAuthContext( document: Document, - handler: ( - event: FirestoreAuthEvent | undefined, ParamsOf> - ) => any | Promise + handler: OnDocumentUpdatedWithAuthContextHandler ): CloudFunction | undefined, ParamsOf>>; /** @@ -552,10 +570,7 @@ export function onDocumentUpdatedWithAuthContext( */ export function onDocumentUpdatedWithAuthContext( opts: DocumentOptions, - handler: ( - event: FirestoreAuthEvent | undefined, ParamsOf> & - V1Compat<"change", Change> - ) => any | Promise + handler: OnDocumentUpdatedWithAuthContextHandlerWithContext ): CloudFunction | undefined, ParamsOf>>; /** @@ -567,9 +582,7 @@ export function onDocumentUpdatedWithAuthContext( */ export function onDocumentUpdatedWithAuthContext( opts: DocumentOptions, - handler: ( - event: FirestoreAuthEvent | undefined, ParamsOf> - ) => any | Promise + handler: OnDocumentUpdatedWithAuthContextHandler ): CloudFunction | undefined, ParamsOf>>; /** @@ -580,10 +593,7 @@ export function onDocumentUpdatedWithAuthContext( */ export function onDocumentUpdatedWithAuthContext( documentOrOpts: Document | DocumentOptions, - handler: ( - event: FirestoreAuthEvent | undefined, ParamsOf> & - V1Compat<"change", Change> - ) => any | Promise + handler: OnDocumentUpdatedWithAuthContextHandlerWithContext ): CloudFunction< FirestoreAuthEvent | undefined, ParamsOf> > { @@ -598,10 +608,7 @@ export function onDocumentUpdatedWithAuthContext( */ export function onDocumentDeleted( document: Document, - handler: ( - event: FirestoreEvent> & - V1Compat<"snapshot", QueryDocumentSnapshot> - ) => any | Promise + handler: OnDocumentDeletedHandlerWithContext ): CloudFunction>>; /** @@ -612,9 +619,7 @@ export function onDocumentDeleted( */ export function onDocumentDeleted( document: Document, - handler: ( - event: FirestoreEvent> - ) => any | Promise + handler: OnDocumentDeletedHandler ): CloudFunction>>; /** @@ -625,10 +630,7 @@ export function onDocumentDeleted( */ export function onDocumentDeleted( opts: DocumentOptions, - handler: ( - event: FirestoreEvent> & - V1Compat<"snapshot", QueryDocumentSnapshot> - ) => any | Promise + handler: OnDocumentDeletedHandlerWithContext ): CloudFunction>>; /** @@ -639,9 +641,7 @@ export function onDocumentDeleted( */ export function onDocumentDeleted( opts: DocumentOptions, - handler: ( - event: FirestoreEvent> - ) => any | Promise + handler: OnDocumentDeletedHandler ): CloudFunction>>; /** @@ -652,10 +652,7 @@ export function onDocumentDeleted( */ export function onDocumentDeleted( documentOrOpts: Document | DocumentOptions, - handler: ( - event: FirestoreEvent> & - V1Compat<"snapshot", QueryDocumentSnapshot> - ) => any | Promise + handler: OnDocumentDeletedHandlerWithContext ): CloudFunction>> { return onOperation(deletedEventType, documentOrOpts, handler); } @@ -669,10 +666,7 @@ export function onDocumentDeleted( */ export function onDocumentDeletedWithAuthContext( document: Document, - handler: ( - event: FirestoreAuthEvent> & - V1Compat<"snapshot", QueryDocumentSnapshot> - ) => any | Promise + handler: OnDocumentDeletedWithAuthContextHandlerWithContext ): CloudFunction>>; /** @@ -684,9 +678,7 @@ export function onDocumentDeletedWithAuthContext( */ export function onDocumentDeletedWithAuthContext( document: Document, - handler: ( - event: FirestoreAuthEvent> - ) => any | Promise + handler: OnDocumentDeletedWithAuthContextHandler ): CloudFunction>>; /** @@ -698,10 +690,7 @@ export function onDocumentDeletedWithAuthContext( */ export function onDocumentDeletedWithAuthContext( opts: DocumentOptions, - handler: ( - event: FirestoreAuthEvent> & - V1Compat<"snapshot", QueryDocumentSnapshot> - ) => any | Promise + handler: OnDocumentDeletedWithAuthContextHandlerWithContext ): CloudFunction>>; /** @@ -713,9 +702,7 @@ export function onDocumentDeletedWithAuthContext( */ export function onDocumentDeletedWithAuthContext( opts: DocumentOptions, - handler: ( - event: FirestoreAuthEvent> - ) => any | Promise + handler: OnDocumentDeletedWithAuthContextHandler ): CloudFunction>>; /** @@ -726,10 +713,7 @@ export function onDocumentDeletedWithAuthContext( */ export function onDocumentDeletedWithAuthContext( documentOrOpts: Document | DocumentOptions, - handler: ( - event: FirestoreAuthEvent> & - V1Compat<"snapshot", QueryDocumentSnapshot> - ) => any | Promise + handler: OnDocumentDeletedWithAuthContextHandlerWithContext ): CloudFunction>> { return onOperation(deletedEventWithAuthContextType, documentOrOpts, handler); } @@ -970,35 +954,25 @@ export function getV1Context(event: any) { export function onOperation( eventType: string, documentOrOpts: Document | DocumentOptions, - handler: ( - event: FirestoreEvent> & - V1Compat<"snapshot", QueryDocumentSnapshot> - ) => any | Promise + handler: OnDocumentCreatedHandlerWithContext ): CloudFunction>>; export function onOperation( eventType: string, documentOrOpts: Document | DocumentOptions, - handler: ( - event: FirestoreEvent> - ) => any | Promise + handler: OnDocumentCreatedHandler ): CloudFunction>>; export function onOperation( eventType: string, documentOrOpts: Document | DocumentOptions, - handler: ( - event: FirestoreAuthEvent> & - V1Compat<"snapshot", QueryDocumentSnapshot> - ) => any | Promise + handler: OnDocumentCreatedWithAuthContextHandlerWithContext ): CloudFunction>>; export function onOperation( eventType: string, documentOrOpts: Document | DocumentOptions, - handler: ( - event: FirestoreAuthEvent> - ) => any | Promise + handler: OnDocumentCreatedWithAuthContextHandler ): CloudFunction>>; export function onOperation< @@ -1013,7 +987,7 @@ export function onOperation< >( eventType: string, documentOrOpts: Document | DocumentOptions, - handler: (event: Event) => any | Promise + handler: OnOperationHandler ): CloudFunction { const { document, database, namespace, opts } = getOpts(documentOrOpts); @@ -1045,35 +1019,25 @@ export function onOperation< export function onChangedOperation( eventType: string, documentOrOpts: Document | DocumentOptions, - handler: ( - event: FirestoreEvent | undefined, ParamsOf> & - V1Compat<"change", Change> - ) => any | Promise + handler: OnDocumentUpdatedHandlerWithContext ): CloudFunction | undefined, ParamsOf>>; export function onChangedOperation( eventType: string, documentOrOpts: Document | DocumentOptions, - handler: ( - event: FirestoreEvent | undefined, ParamsOf> - ) => any | Promise + handler: OnDocumentUpdatedHandler ): CloudFunction | undefined, ParamsOf>>; export function onChangedOperation( eventType: string, documentOrOpts: Document | DocumentOptions, - handler: ( - event: FirestoreAuthEvent | undefined, ParamsOf> & - V1Compat<"change", Change> - ) => any | Promise + handler: OnDocumentUpdatedWithAuthContextHandlerWithContext ): CloudFunction | undefined, ParamsOf>>; export function onChangedOperation( eventType: string, documentOrOpts: Document | DocumentOptions, - handler: ( - event: FirestoreAuthEvent | undefined, ParamsOf> - ) => any | Promise + handler: OnDocumentUpdatedWithAuthContextHandler ): CloudFunction | undefined, ParamsOf>>; export function onChangedOperation< @@ -1088,7 +1052,7 @@ export function onChangedOperation< >( eventType: string, documentOrOpts: Document | DocumentOptions, - handler: (event: Event) => any | Promise + handler: OnChangedOperationHandler ): CloudFunction { const { document, database, namespace, opts } = getOpts(documentOrOpts); diff --git a/src/v2/providers/https.ts b/src/v2/providers/https.ts index cfb3cfee3..4fae6a0fe 100644 --- a/src/v2/providers/https.ts +++ b/src/v2/providers/https.ts @@ -286,29 +286,34 @@ export interface CallableFunction extends HttpsFunc ): { stream: AsyncIterable; output: Return }; } +/** Handler used by {@link onRequest}. */ +export type OnRequestHandler = ( + request: Request, + response: express.Response +) => void | Promise; + +/** Handler used by {@link onCall}. */ +export type OnCallHandler, Stream = unknown> = ( + request: CallableRequest, + response?: CallableResponse +) => Return; + /** * Handles HTTPS requests. * @param opts - Options to set on this function * @param handler - A function that takes a {@link https.Request} and response object, same signature as an Express app. * @returns A function that you can export and deploy. */ -export function onRequest( - opts: HttpsOptions, - handler: (request: Request, response: express.Response) => void | Promise -): HttpsFunction; +export function onRequest(opts: HttpsOptions, handler: OnRequestHandler): HttpsFunction; /** * Handles HTTPS requests. * @param handler - A function that takes a {@link https.Request} and response object, same signature as an Express app. * @returns A function that you can export and deploy. */ +export function onRequest(handler: OnRequestHandler): HttpsFunction; export function onRequest( - handler: (request: Request, response: express.Response) => void | Promise -): HttpsFunction; -export function onRequest( - optsOrHandler: - | HttpsOptions - | ((request: Request, response: express.Response) => void | Promise), - handler?: (request: Request, response: express.Response) => void | Promise + optsOrHandler: HttpsOptions | OnRequestHandler, + handler?: OnRequestHandler ): HttpsFunction { let opts: HttpsOptions; if (arguments.length === 1) { @@ -411,7 +416,7 @@ export function onRequest( */ export function onCall, Stream = unknown>( opts: CallableOptions, - handler: (request: CallableRequest, response?: CallableResponse) => Return + handler: OnCallHandler ): CallableFunction ? Return : Promise, Stream>; /** @@ -420,11 +425,11 @@ export function onCall, Stream = unknown>( * @returns A function that you can export and deploy. */ export function onCall, Stream = unknown>( - handler: (request: CallableRequest, response?: CallableResponse) => Return + handler: OnCallHandler ): CallableFunction ? Return : Promise>; export function onCall, Stream = unknown>( - optsOrHandler: CallableOptions | ((request: CallableRequest) => Return), - handler?: (request: CallableRequest, response?: CallableResponse) => Return + optsOrHandler: CallableOptions | OnCallHandler, + handler?: OnCallHandler ): CallableFunction ? Return : Promise> { let opts: CallableOptions; if (arguments.length === 1) { diff --git a/src/v2/providers/identity.ts b/src/v2/providers/identity.ts index 2e46b6779..95e955338 100644 --- a/src/v2/providers/identity.ts +++ b/src/v2/providers/identity.ts @@ -166,13 +166,31 @@ export interface BlockingOptions { secrets?: SupportedSecretParam[]; } +/** Handler used by {@link beforeUserCreated}. */ +export type BeforeUserCreatedHandler = ( + event: AuthBlockingEvent +) => MaybeAsync; + +/** Handler used by {@link beforeUserSignedIn}. */ +export type BeforeUserSignedInHandler = ( + event: AuthBlockingEvent +) => MaybeAsync; + +/** Handler used by {@link beforeEmailSent}. */ +export type BeforeEmailSentHandler = ( + event: AuthBlockingEvent +) => MaybeAsync; + +/** Handler used by {@link beforeSmsSent}. */ +export type BeforeSmsSentHandler = ( + event: AuthBlockingEvent +) => MaybeAsync; + /** * Handles an event that is triggered before a user is created. * @param handler - Event handler which is run every time before a user is created. */ -export function beforeUserCreated( - handler: (event: AuthBlockingEvent) => MaybeAsync -): BlockingFunction; +export function beforeUserCreated(handler: BeforeUserCreatedHandler): BlockingFunction; /** * Handles an event that is triggered before a user is created. @@ -181,7 +199,7 @@ export function beforeUserCreated( */ export function beforeUserCreated( opts: BlockingOptions, - handler: (event: AuthBlockingEvent) => MaybeAsync + handler: BeforeUserCreatedHandler ): BlockingFunction; /** @@ -190,10 +208,8 @@ export function beforeUserCreated( * @param handler? - If defined, an event handler which is run every time before a user is created. */ export function beforeUserCreated( - optsOrHandler: - | BlockingOptions - | ((event: AuthBlockingEvent) => MaybeAsync), - handler?: (event: AuthBlockingEvent) => MaybeAsync + optsOrHandler: BlockingOptions | BeforeUserCreatedHandler, + handler?: BeforeUserCreatedHandler ): BlockingFunction { return beforeOperation("beforeCreate", optsOrHandler, handler); } @@ -202,9 +218,7 @@ export function beforeUserCreated( * Handles an event that is triggered before a user is signed in. * @param handler - Event handler which is run every time before a user is signed in. */ -export function beforeUserSignedIn( - handler: (event: AuthBlockingEvent) => MaybeAsync -): BlockingFunction; +export function beforeUserSignedIn(handler: BeforeUserSignedInHandler): BlockingFunction; /** * Handles an event that is triggered before a user is signed in. @@ -213,7 +227,7 @@ export function beforeUserSignedIn( */ export function beforeUserSignedIn( opts: BlockingOptions, - handler: (event: AuthBlockingEvent) => MaybeAsync + handler: BeforeUserSignedInHandler ): BlockingFunction; /** @@ -222,10 +236,8 @@ export function beforeUserSignedIn( * @param handler - Event handler which is run every time before a user is signed in. */ export function beforeUserSignedIn( - optsOrHandler: - | BlockingOptions - | ((event: AuthBlockingEvent) => MaybeAsync), - handler?: (event: AuthBlockingEvent) => MaybeAsync + optsOrHandler: BlockingOptions | BeforeUserSignedInHandler, + handler?: BeforeUserSignedInHandler ): BlockingFunction { return beforeOperation("beforeSignIn", optsOrHandler, handler); } @@ -234,9 +246,7 @@ export function beforeUserSignedIn( * Handles an event that is triggered before an email is sent to a user. * @param handler - Event handler that is run before an email is sent to a user. */ -export function beforeEmailSent( - handler: (event: AuthBlockingEvent) => MaybeAsync -): BlockingFunction; +export function beforeEmailSent(handler: BeforeEmailSentHandler): BlockingFunction; /** * Handles an event that is triggered before an email is sent to a user. @@ -245,7 +255,7 @@ export function beforeEmailSent( */ export function beforeEmailSent( opts: Omit, - handler: (event: AuthBlockingEvent) => MaybeAsync + handler: BeforeEmailSentHandler ): BlockingFunction; /** @@ -256,8 +266,8 @@ export function beforeEmailSent( export function beforeEmailSent( optsOrHandler: | Omit - | ((event: AuthBlockingEvent) => MaybeAsync), - handler?: (event: AuthBlockingEvent) => MaybeAsync + | BeforeEmailSentHandler, + handler?: BeforeEmailSentHandler ): BlockingFunction { return beforeOperation("beforeSendEmail", optsOrHandler, handler); } @@ -265,9 +275,7 @@ export function beforeEmailSent( * Handles an event that is triggered before an SMS is sent to a user. * @param handler - Event handler that is run before an SMS is sent to a user. */ -export function beforeSmsSent( - handler: (event: AuthBlockingEvent) => MaybeAsync -): BlockingFunction; +export function beforeSmsSent(handler: BeforeSmsSentHandler): BlockingFunction; /** * Handles an event that is triggered before an SMS is sent to a user. @@ -276,7 +284,7 @@ export function beforeSmsSent( */ export function beforeSmsSent( opts: Omit, - handler: (event: AuthBlockingEvent) => MaybeAsync + handler: BeforeSmsSentHandler ): BlockingFunction; /** @@ -287,8 +295,8 @@ export function beforeSmsSent( export function beforeSmsSent( optsOrHandler: | Omit - | ((event: AuthBlockingEvent) => MaybeAsync), - handler?: (event: AuthBlockingEvent) => MaybeAsync + | BeforeSmsSentHandler, + handler?: BeforeSmsSentHandler ): BlockingFunction { return beforeOperation("beforeSendSms", optsOrHandler, handler); } diff --git a/src/v2/providers/pubsub.ts b/src/v2/providers/pubsub.ts index bb151877b..8570fbdaa 100644 --- a/src/v2/providers/pubsub.ts +++ b/src/v2/providers/pubsub.ts @@ -265,6 +265,16 @@ export interface PubSubOptions extends options.EventHandlerOptions { retry?: boolean | Expression | ResetValue; } +/** Handler used by {@link onMessagePublished}. */ +export type OnMessagePublishedHandler = ( + event: CloudEvent> +) => any | Promise; + +/** Handler used by {@link onMessagePublished} when accessing v1-compatible fields. */ +export type OnMessagePublishedHandlerWithContext = ( + event: CloudEvent> & V1Compat<"message", V1PubSubMessage> +) => any | Promise; + /** * Handle a message being published to a Pub/Sub topic. * @param topic - The Pub/Sub topic to watch for message events. @@ -273,9 +283,7 @@ export interface PubSubOptions extends options.EventHandlerOptions { */ export function onMessagePublished( topic: string, - handler: ( - event: CloudEvent> & V1Compat<"message", V1PubSubMessage> - ) => any | Promise + handler: OnMessagePublishedHandlerWithContext ): CloudFunction>>; /** @@ -286,7 +294,7 @@ export function onMessagePublished( */ export function onMessagePublished( topic: string, - handler: (event: CloudEvent>) => any | Promise + handler: OnMessagePublishedHandler ): CloudFunction>>; /** @@ -297,9 +305,7 @@ export function onMessagePublished( */ export function onMessagePublished( options: PubSubOptions, - handler: ( - event: CloudEvent> & V1Compat<"message", V1PubSubMessage> - ) => any | Promise + handler: OnMessagePublishedHandlerWithContext ): CloudFunction>>; /** @@ -310,7 +316,7 @@ export function onMessagePublished( */ export function onMessagePublished( options: PubSubOptions, - handler: (event: CloudEvent>) => any | Promise + handler: OnMessagePublishedHandler ): CloudFunction>>; /** @@ -321,9 +327,7 @@ export function onMessagePublished( */ export function onMessagePublished( topicOrOptions: string | PubSubOptions, - handler: ( - event: CloudEvent> & V1Compat<"message", V1PubSubMessage> - ) => any | Promise + handler: OnMessagePublishedHandlerWithContext ): CloudFunction>> { let topic: string; let opts: options.EventHandlerOptions; diff --git a/src/v2/providers/remoteConfig.ts b/src/v2/providers/remoteConfig.ts index 7f9ffba22..807d62634 100644 --- a/src/v2/providers/remoteConfig.ts +++ b/src/v2/providers/remoteConfig.ts @@ -25,7 +25,7 @@ import { initV2Endpoint, ManifestEndpoint } from "../../runtime/manifest"; import { CloudEvent, CloudFunction } from "../core"; import { EventHandlerOptions, getGlobalOptions, optionsToEndpoint } from "../options"; import { wrapTraceContext } from "../trace"; -import { V1Compat, addV1Compat } from "../compat"; +import { addV1Compat, V1Compat } from "../compat"; /** @internal */ export const eventType = "google.firebase.remoteconfig.remoteConfig.v1.updated"; @@ -88,6 +88,14 @@ export interface ConfigUpdateData { rollbackSource: number; } +/** Handler used by {@link onConfigUpdated}. */ +export type OnConfigUpdatedHandler = (event: CloudEvent) => any | Promise; + +/** Handler used by {@link onConfigUpdated} when accessing v1-compatible fields. */ +export type OnConfigUpdatedHandlerWithContext = ( + event: CloudEvent & V1Compat<"version", ConfigUpdateData> +) => any | Promise; + /** * Event handler which triggers when data is updated in a Remote Config. * @@ -95,9 +103,7 @@ export interface ConfigUpdateData { * @returns A function that you can export and deploy. */ export function onConfigUpdated( - handler: ( - event: CloudEvent & V1Compat<"version", ConfigUpdateData> - ) => any | Promise + handler: OnConfigUpdatedHandlerWithContext ): CloudFunction>; /** @@ -107,7 +113,7 @@ export function onConfigUpdated( * @returns A function that you can export and deploy. */ export function onConfigUpdated( - handler: (event: CloudEvent) => any | Promise + handler: OnConfigUpdatedHandler ): CloudFunction>; /** @@ -119,9 +125,7 @@ export function onConfigUpdated( */ export function onConfigUpdated( opts: EventHandlerOptions, - handler: ( - event: CloudEvent & V1Compat<"version", ConfigUpdateData> - ) => any | Promise + handler: OnConfigUpdatedHandlerWithContext ): CloudFunction>; /** @@ -133,7 +137,7 @@ export function onConfigUpdated( */ export function onConfigUpdated( opts: EventHandlerOptions, - handler: (event: CloudEvent) => any | Promise + handler: OnConfigUpdatedHandler ): CloudFunction>; /** diff --git a/src/v2/providers/scheduler.ts b/src/v2/providers/scheduler.ts index 876ff7194..7604cc573 100644 --- a/src/v2/providers/scheduler.ts +++ b/src/v2/providers/scheduler.ts @@ -128,6 +128,14 @@ export interface ScheduleOptions extends options.GlobalOptions { maxDoublings?: number | Expression | ResetValue; } +/** Handler used by {@link onSchedule}. */ +export type OnScheduleHandler = (event: ScheduledEvent) => void | Promise; + +/** Handler used by {@link onSchedule} when accessing v1-compatible context. */ +export type OnScheduleHandlerWithContext = ( + event: ScheduledEvent & { context: EventContext } +) => void | Promise; + /** * Handler for scheduled functions. Triggered whenever the associated * scheduler job sends a http request. @@ -137,7 +145,7 @@ export interface ScheduleOptions extends options.GlobalOptions { */ export function onSchedule( schedule: string, - handler: (event: ScheduledEvent & { context: EventContext }) => void | Promise + handler: OnScheduleHandlerWithContext ): ScheduleFunction; /** @@ -147,10 +155,7 @@ export function onSchedule( * @param handler - A function to execute when triggered. * @returns A function that you can export and deploy. */ -export function onSchedule( - schedule: string, - handler: (event: ScheduledEvent) => void | Promise -): ScheduleFunction; +export function onSchedule(schedule: string, handler: OnScheduleHandler): ScheduleFunction; /** * Handler for scheduled functions. Triggered whenever the associated @@ -161,7 +166,7 @@ export function onSchedule( */ export function onSchedule( options: ScheduleOptions, - handler: (event: ScheduledEvent & { context: EventContext }) => void | Promise + handler: OnScheduleHandlerWithContext ): ScheduleFunction; /** @@ -171,10 +176,7 @@ export function onSchedule( * @param handler - A function to execute when triggered. * @returns A function that you can export and deploy. */ -export function onSchedule( - options: ScheduleOptions, - handler: (event: ScheduledEvent) => void | Promise -): ScheduleFunction; +export function onSchedule(options: ScheduleOptions, handler: OnScheduleHandler): ScheduleFunction; /** * Handler for scheduled functions. Triggered whenever the associated @@ -185,7 +187,7 @@ export function onSchedule( */ export function onSchedule( args: string | ScheduleOptions, - handler: (event: any) => void | Promise + handler: OnScheduleHandlerWithContext ): ScheduleFunction { const separatedOpts = getOpts(args); @@ -213,7 +215,7 @@ export function onSchedule( }); try { - await handler(event); + await handler(event as ScheduledEvent & { context: EventContext }); res.status(200).send(); } catch (err) { logger.error((err as Error).message); diff --git a/src/v2/providers/storage.ts b/src/v2/providers/storage.ts index 3e705f243..aeb74fed6 100644 --- a/src/v2/providers/storage.ts +++ b/src/v2/providers/storage.ts @@ -304,6 +304,38 @@ export interface StorageOptions extends options.EventHandlerOptions { retry?: boolean | Expression | ResetValue; } +/** Handler used by Cloud Storage event triggers. */ +export type StorageEventHandler = (event: StorageEvent) => any | Promise; + +/** Handler used by Cloud Storage event triggers when accessing v1-compatible fields. */ +export type StorageEventHandlerWithContext = ( + event: StorageEvent & V1Compat<"object", StorageObjectData> +) => any | Promise; + +/** Handler used by {@link onObjectArchived}. */ +export type OnObjectArchivedHandler = StorageEventHandler; + +/** Handler used by {@link onObjectArchived} when accessing v1-compatible fields. */ +export type OnObjectArchivedHandlerWithContext = StorageEventHandlerWithContext; + +/** Handler used by {@link onObjectFinalized}. */ +export type OnObjectFinalizedHandler = StorageEventHandler; + +/** Handler used by {@link onObjectFinalized} when accessing v1-compatible fields. */ +export type OnObjectFinalizedHandlerWithContext = StorageEventHandlerWithContext; + +/** Handler used by {@link onObjectDeleted}. */ +export type OnObjectDeletedHandler = StorageEventHandler; + +/** Handler used by {@link onObjectDeleted} when accessing v1-compatible fields. */ +export type OnObjectDeletedHandlerWithContext = StorageEventHandlerWithContext; + +/** Handler used by {@link onObjectMetadataUpdated}. */ +export type OnObjectMetadataUpdatedHandler = StorageEventHandler; + +/** Handler used by {@link onObjectMetadataUpdated} when accessing v1-compatible fields. */ +export type OnObjectMetadataUpdatedHandlerWithContext = StorageEventHandlerWithContext; + /** * Event handler sent only when a bucket has enabled object versioning. * This event indicates that the live version of an object has become an @@ -313,7 +345,7 @@ export interface StorageOptions extends options.EventHandlerOptions { * @param handler - Event handler which is run every time a Google Cloud Storage archival occurs. */ export function onObjectArchived( - handler: (event: StorageEvent & V1Compat<"object", StorageObjectData>) => any | Promise + handler: OnObjectArchivedHandlerWithContext ): CloudFunction; /** @@ -324,9 +356,7 @@ export function onObjectArchived( * * @param handler - Event handler which is run every time a Google Cloud Storage archival occurs. */ -export function onObjectArchived( - handler: (event: StorageEvent) => any | Promise -): CloudFunction; +export function onObjectArchived(handler: OnObjectArchivedHandler): CloudFunction; /** * Event handler sent only when a bucket has enabled object versioning. @@ -339,7 +369,7 @@ export function onObjectArchived( */ export function onObjectArchived( bucket: string | Expression, - handler: (event: StorageEvent & V1Compat<"object", StorageObjectData>) => any | Promise + handler: OnObjectArchivedHandlerWithContext ): CloudFunction; /** @@ -353,7 +383,7 @@ export function onObjectArchived( */ export function onObjectArchived( bucket: string | Expression, - handler: (event: StorageEvent) => any | Promise + handler: OnObjectArchivedHandler ): CloudFunction; /** @@ -367,7 +397,7 @@ export function onObjectArchived( */ export function onObjectArchived( opts: StorageOptions, - handler: (event: StorageEvent & V1Compat<"object", StorageObjectData>) => any | Promise + handler: OnObjectArchivedHandlerWithContext ): CloudFunction; /** @@ -381,7 +411,7 @@ export function onObjectArchived( */ export function onObjectArchived( opts: StorageOptions, - handler: (event: StorageEvent) => any | Promise + handler: OnObjectArchivedHandler ): CloudFunction; /** @@ -415,7 +445,7 @@ export function onObjectArchived( * @param handler - Event handler which is run every time a Google Cloud Storage object creation occurs. */ export function onObjectFinalized( - handler: (event: StorageEvent & V1Compat<"object", StorageObjectData>) => any | Promise + handler: OnObjectFinalizedHandlerWithContext ): CloudFunction; /** @@ -428,9 +458,7 @@ export function onObjectFinalized( * * @param handler - Event handler which is run every time a Google Cloud Storage object creation occurs. */ -export function onObjectFinalized( - handler: (event: StorageEvent) => any | Promise -): CloudFunction; +export function onObjectFinalized(handler: OnObjectFinalizedHandler): CloudFunction; /** * Event handler which fires every time a Google Cloud Storage object @@ -445,7 +473,7 @@ export function onObjectFinalized( */ export function onObjectFinalized( bucket: string | Expression, - handler: (event: StorageEvent & V1Compat<"object", StorageObjectData>) => any | Promise + handler: OnObjectFinalizedHandlerWithContext ): CloudFunction; /** @@ -461,7 +489,7 @@ export function onObjectFinalized( */ export function onObjectFinalized( bucket: string | Expression, - handler: (event: StorageEvent) => any | Promise + handler: OnObjectFinalizedHandler ): CloudFunction; /** @@ -477,7 +505,7 @@ export function onObjectFinalized( */ export function onObjectFinalized( opts: StorageOptions, - handler: (event: StorageEvent & V1Compat<"object", StorageObjectData>) => any | Promise + handler: OnObjectFinalizedHandlerWithContext ): CloudFunction; /** @@ -493,7 +521,7 @@ export function onObjectFinalized( */ export function onObjectFinalized( opts: StorageOptions, - handler: (event: StorageEvent) => any | Promise + handler: OnObjectFinalizedHandler ): CloudFunction; /** @@ -530,7 +558,7 @@ export function onObjectFinalized( * @param handler - Event handler which is run every time a Google Cloud Storage object deletion occurs. */ export function onObjectDeleted( - handler: (event: StorageEvent & V1Compat<"object", StorageObjectData>) => any | Promise + handler: OnObjectDeletedHandlerWithContext ): CloudFunction; /** @@ -544,9 +572,7 @@ export function onObjectDeleted( * * @param handler - Event handler which is run every time a Google Cloud Storage object deletion occurs. */ -export function onObjectDeleted( - handler: (event: StorageEvent) => any | Promise -): CloudFunction; +export function onObjectDeleted(handler: OnObjectDeletedHandler): CloudFunction; /** * Event handler which fires every time a Google Cloud Storage deletion occurs. @@ -562,7 +588,7 @@ export function onObjectDeleted( */ export function onObjectDeleted( bucket: string | Expression, - handler: (event: StorageEvent & V1Compat<"object", StorageObjectData>) => any | Promise + handler: OnObjectDeletedHandlerWithContext ): CloudFunction; /** @@ -579,7 +605,7 @@ export function onObjectDeleted( */ export function onObjectDeleted( bucket: string | Expression, - handler: (event: StorageEvent) => any | Promise + handler: OnObjectDeletedHandler ): CloudFunction; /** @@ -596,7 +622,7 @@ export function onObjectDeleted( */ export function onObjectDeleted( opts: StorageOptions, - handler: (event: StorageEvent & V1Compat<"object", StorageObjectData>) => any | Promise + handler: OnObjectDeletedHandlerWithContext ): CloudFunction; /** @@ -613,7 +639,7 @@ export function onObjectDeleted( */ export function onObjectDeleted( opts: StorageOptions, - handler: (event: StorageEvent) => any | Promise + handler: OnObjectDeletedHandler ): CloudFunction; /** @@ -647,7 +673,7 @@ export function onObjectDeleted( * @param handler - Event handler which is run every time a Google Cloud Storage object metadata update occurs. */ export function onObjectMetadataUpdated( - handler: (event: StorageEvent & V1Compat<"object", StorageObjectData>) => any | Promise + handler: OnObjectMetadataUpdatedHandlerWithContext ): CloudFunction; /** @@ -658,7 +684,7 @@ export function onObjectMetadataUpdated( * @param handler - Event handler which is run every time a Google Cloud Storage object metadata update occurs. */ export function onObjectMetadataUpdated( - handler: (event: StorageEvent) => any | Promise + handler: OnObjectMetadataUpdatedHandler ): CloudFunction; /** @@ -670,7 +696,7 @@ export function onObjectMetadataUpdated( */ export function onObjectMetadataUpdated( bucket: string | Expression, - handler: (event: StorageEvent & V1Compat<"object", StorageObjectData>) => any | Promise + handler: OnObjectMetadataUpdatedHandlerWithContext ): CloudFunction; /** @@ -682,7 +708,7 @@ export function onObjectMetadataUpdated( */ export function onObjectMetadataUpdated( bucket: string | Expression, - handler: (event: StorageEvent) => any | Promise + handler: OnObjectMetadataUpdatedHandler ): CloudFunction; /** @@ -694,7 +720,7 @@ export function onObjectMetadataUpdated( */ export function onObjectMetadataUpdated( opts: StorageOptions, - handler: (event: StorageEvent & V1Compat<"object", StorageObjectData>) => any | Promise + handler: OnObjectMetadataUpdatedHandlerWithContext ): CloudFunction; /** @@ -706,7 +732,7 @@ export function onObjectMetadataUpdated( */ export function onObjectMetadataUpdated( opts: StorageOptions, - handler: (event: StorageEvent) => any | Promise + handler: OnObjectMetadataUpdatedHandler ): CloudFunction; /** @@ -734,8 +760,8 @@ export function onOperation( | string | Expression | StorageOptions - | ((event: StorageEvent & V1Compat<"object", StorageObjectData>) => any | Promise), - handler: (event: StorageEvent & V1Compat<"object", StorageObjectData>) => any | Promise + | StorageEventHandlerWithContext, + handler: StorageEventHandlerWithContext ): CloudFunction { if (typeof bucketOrOptsOrHandler === "function") { handler = bucketOrOptsOrHandler as (event: any) => any | Promise; diff --git a/src/v2/providers/tasks.ts b/src/v2/providers/tasks.ts index 9bb0cb13f..50fea7168 100644 --- a/src/v2/providers/tasks.ts +++ b/src/v2/providers/tasks.ts @@ -176,6 +176,14 @@ export interface TaskQueueFunction extends HttpsFunction { run(request: Request): void | Promise; } +/** Handler used by {@link onTaskDispatched}. */ +export type OnTaskDispatchedHandler = (request: Request) => void | Promise; + +/** Handler used by {@link onTaskDispatched} when accessing v1-compatible context. */ +export type OnTaskDispatchedHandlerWithContext = ( + request: Request & { context: TaskContext } +) => void | Promise; + /** * Creates a handler for tasks sent to a Google Cloud Tasks queue. * @param handler - A callback to handle task requests. @@ -183,7 +191,7 @@ export interface TaskQueueFunction extends HttpsFunction { * @returns A function you can export and deploy. */ export function onTaskDispatched( - handler: (request: Request & { context: TaskContext }) => void | Promise + handler: OnTaskDispatchedHandlerWithContext ): TaskQueueFunction; /** @@ -193,7 +201,7 @@ export function onTaskDispatched( * @returns A function you can export and deploy. */ export function onTaskDispatched( - handler: (request: Request) => void | Promise + handler: OnTaskDispatchedHandler ): TaskQueueFunction; /** @@ -205,7 +213,7 @@ export function onTaskDispatched( */ export function onTaskDispatched( options: TaskQueueOptions, - handler: (request: Request & { context: TaskContext }) => void | Promise + handler: OnTaskDispatchedHandlerWithContext ): TaskQueueFunction; /** @@ -217,7 +225,7 @@ export function onTaskDispatched( */ export function onTaskDispatched( options: TaskQueueOptions, - handler: (request: Request) => void | Promise + handler: OnTaskDispatchedHandler ): TaskQueueFunction; export function onTaskDispatched( optsOrHandler: TaskQueueOptions | ((request: any) => void | Promise), diff --git a/src/v2/providers/testLab.ts b/src/v2/providers/testLab.ts index 3b4e5a3c1..47815ae4e 100644 --- a/src/v2/providers/testLab.ts +++ b/src/v2/providers/testLab.ts @@ -144,6 +144,11 @@ export interface TestMatrixCompletedData { testMatrixId: string; } +/** Handler used by {@link onTestMatrixCompleted}. */ +export type OnTestMatrixCompletedHandler = ( + event: CloudEvent +) => any | Promise; + /** * Event handler which triggers when a Firebase test matrix completes. * @@ -152,7 +157,7 @@ export interface TestMatrixCompletedData { * @alpha */ export function onTestMatrixCompleted( - handler: (event: CloudEvent) => any | Promise + handler: OnTestMatrixCompletedHandler ): CloudFunction>; /** @@ -165,7 +170,7 @@ export function onTestMatrixCompleted( */ export function onTestMatrixCompleted( opts: EventHandlerOptions, - handler: (event: CloudEvent) => any | Promise + handler: OnTestMatrixCompletedHandler ): CloudFunction>; /** @@ -177,10 +182,8 @@ export function onTestMatrixCompleted( * @alpha */ export function onTestMatrixCompleted( - optsOrHandler: - | EventHandlerOptions - | ((event: CloudEvent) => any | Promise), - handler?: (event: CloudEvent) => any | Promise + optsOrHandler: EventHandlerOptions | OnTestMatrixCompletedHandler, + handler?: OnTestMatrixCompletedHandler ): CloudFunction> { if (typeof optsOrHandler === "function") { handler = optsOrHandler as (event: CloudEvent) => any | Promise;