@@ -34,6 +34,24 @@ import { expr } from "../../params";
3434
3535export { DataSnapshot } ;
3636
37+ /** Handler used by {@link RefBuilder.onWrite}. */
38+ export type OnWriteHandler < Ref extends string = string > = (
39+ change : Change < DataSnapshot > ,
40+ context : EventContext < ParamsOf < Ref > >
41+ ) => PromiseLike < any > | any ;
42+
43+ /** Handler used by {@link RefBuilder.onUpdate}. */
44+ export type OnUpdateHandler < Ref extends string = string > = OnWriteHandler < Ref > ;
45+
46+ /** Handler used by {@link RefBuilder.onCreate}. */
47+ export type OnCreateHandler < Ref extends string = string > = (
48+ snapshot : DataSnapshot ,
49+ context : EventContext < ParamsOf < Ref > >
50+ ) => PromiseLike < any > | any ;
51+
52+ /** Handler used by {@link RefBuilder.onDelete}. */
53+ export type OnDeleteHandler < Ref extends string = string > = OnCreateHandler < Ref > ;
54+
3755/** @internal */
3856export const provider = "google.firebase.database" ;
3957/** @internal */
@@ -182,12 +200,7 @@ export class RefBuilder<Ref extends string> {
182200 * write occurs.
183201 * @returns A function that you can export and deploy.
184202 */
185- onWrite (
186- handler : (
187- change : Change < DataSnapshot > ,
188- context : EventContext < ParamsOf < Ref > >
189- ) => PromiseLike < any > | any
190- ) : CloudFunction < Change < DataSnapshot > > {
203+ onWrite ( handler : OnWriteHandler < Ref > ) : CloudFunction < Change < DataSnapshot > > {
191204 return this . onOperation ( handler , "ref.write" , this . changeConstructor ) ;
192205 }
193206
@@ -199,12 +212,7 @@ export class RefBuilder<Ref extends string> {
199212 * write occurs.
200213 * @returns A function which you can export and deploy.
201214 */
202- onUpdate (
203- handler : (
204- change : Change < DataSnapshot > ,
205- context : EventContext < ParamsOf < Ref > >
206- ) => PromiseLike < any > | any
207- ) : CloudFunction < Change < DataSnapshot > > {
215+ onUpdate ( handler : OnUpdateHandler < Ref > ) : CloudFunction < Change < DataSnapshot > > {
208216 return this . onOperation ( handler , "ref.update" , this . changeConstructor ) ;
209217 }
210218
@@ -216,12 +224,7 @@ export class RefBuilder<Ref extends string> {
216224 * Firebase Realtime Database.
217225 * @returns A function that you can export and deploy.
218226 */
219- onCreate (
220- handler : (
221- snapshot : DataSnapshot ,
222- context : EventContext < ParamsOf < Ref > >
223- ) => PromiseLike < any > | any
224- ) : CloudFunction < DataSnapshot > {
227+ onCreate ( handler : OnCreateHandler < Ref > ) : CloudFunction < DataSnapshot > {
225228 const dataConstructor = ( raw : LegacyEvent ) => {
226229 const [ dbInstance , path ] = extractInstanceAndPath (
227230 raw . context . resource . name ,
@@ -240,12 +243,7 @@ export class RefBuilder<Ref extends string> {
240243 * Firebase Realtime Database.
241244 * @returns A function that you can export and deploy.
242245 */
243- onDelete (
244- handler : (
245- snapshot : DataSnapshot ,
246- context : EventContext < ParamsOf < Ref > >
247- ) => PromiseLike < any > | any
248- ) : CloudFunction < DataSnapshot > {
246+ onDelete ( handler : OnDeleteHandler < Ref > ) : CloudFunction < DataSnapshot > {
249247 const dataConstructor = ( raw : LegacyEvent ) => {
250248 const [ dbInstance , path ] = extractInstanceAndPath (
251249 raw . context . resource . name ,
0 commit comments