UNPKG

5.19 kBTypeScriptView Raw
1import { Change } from "../../common/change";
2import { ParamsOf } from "../../common/params";
3import { DataSnapshot } from "../../common/providers/database";
4import { CloudFunction, EventContext } from "../cloud-functions";
5import { DeploymentOptions } from "../function-configuration";
6export { DataSnapshot };
7/**
8 * Registers a function that triggers on events from a specific
9 * Firebase Realtime Database instance.
10 *
11 * @remarks
12 * Use this method together with `ref` to specify the instance on which to
13 * watch for database events. For example: `firebase.database.instance('my-app-db-2').ref('/foo/bar')`
14 *
15 * Note that `functions.database.ref` used without `instance` watches the
16 * *default* instance for events.
17 *
18 * @param instance The instance name of the database instance
19 * to watch for write events.
20 * @returns Firebase Realtime Database instance builder interface.
21 */
22export declare function instance(instance: string): InstanceBuilder;
23/**
24 * Registers a function that triggers on Firebase Realtime Database write
25 * events.
26 *
27 * @remarks
28 * This method behaves very similarly to the method of the same name in the
29 * client and Admin Firebase SDKs. Any change to the Database that affects the
30 * data at or below the provided `path` will fire an event in Cloud Functions.
31 *
32 * There are three important differences between listening to a Realtime
33 * Database event in Cloud Functions and using the Realtime Database in the
34 * client and Admin SDKs:
35 *
36 * 1. Cloud Functions allows wildcards in the `path` name. Any `path` component
37 * in curly brackets (`{}`) is a wildcard that matches all strings. The value
38 * that matched a certain invocation of a Cloud Function is returned as part
39 * of the [`EventContext.params`](cloud_functions_eventcontext.html#params object. For
40 * example, `ref("messages/{messageId}")` matches changes at
41 * `/messages/message1` or `/messages/message2`, resulting in
42 * `event.params.messageId` being set to `"message1"` or `"message2"`,
43 * respectively.
44 *
45 * 2. Cloud Functions do not fire an event for data that already existed before
46 * the Cloud Function was deployed.
47 *
48 * 3. Cloud Function events have access to more information, including a
49 * snapshot of the previous event data and information about the user who
50 * triggered the Cloud Function.
51 *
52 * @param path The path within the Database to watch for write events.
53 * @returns Firebase Realtime Database builder interface.
54 */
55export declare function ref<Ref extends string>(path: Ref): RefBuilder<Ref>;
56/**
57 * The Firebase Realtime Database instance builder interface.
58 *
59 * Access via [`database.instance()`](providers_database_.html#instance).
60 */
61export declare class InstanceBuilder {
62 private instance;
63 private options;
64 constructor(instance: string, options: DeploymentOptions);
65 /**
66 * @returns Firebase Realtime Database reference builder interface.
67 */
68 ref<Ref extends string>(path: Ref): RefBuilder<Ref>;
69}
70/**
71 * The Firebase Realtime Database reference builder interface.
72 *
73 * Access via [`functions.database.ref()`](functions.database#.ref).
74 */
75export declare class RefBuilder<Ref extends string> {
76 private triggerResource;
77 private options;
78 constructor(triggerResource: () => string, options: DeploymentOptions);
79 /**
80 * Event handler that fires every time a Firebase Realtime Database write
81 * of any kind (creation, update, or delete) occurs.
82 *
83 * @param handler Event handler that runs every time a Firebase Realtime Database
84 * write occurs.
85 * @returns A function that you can export and deploy.
86 */
87 onWrite(handler: (change: Change<DataSnapshot>, context: EventContext<ParamsOf<Ref>>) => PromiseLike<any> | any): CloudFunction<Change<DataSnapshot>>;
88 /**
89 * Event handler that fires every time data is updated in
90 * Firebase Realtime Database.
91 *
92 * @param handler Event handler which is run every time a Firebase Realtime Database
93 * write occurs.
94 * @returns A function which you can export and deploy.
95 */
96 onUpdate(handler: (change: Change<DataSnapshot>, context: EventContext<ParamsOf<Ref>>) => PromiseLike<any> | any): CloudFunction<Change<DataSnapshot>>;
97 /**
98 * Event handler that fires every time new data is created in
99 * Firebase Realtime Database.
100 *
101 * @param handler Event handler that runs every time new data is created in
102 * Firebase Realtime Database.
103 * @returns A function that you can export and deploy.
104 */
105 onCreate(handler: (snapshot: DataSnapshot, context: EventContext<ParamsOf<Ref>>) => PromiseLike<any> | any): CloudFunction<DataSnapshot>;
106 /**
107 * Event handler that fires every time data is deleted from
108 * Firebase Realtime Database.
109 *
110 * @param handler Event handler that runs every time data is deleted from
111 * Firebase Realtime Database.
112 * @returns A function that you can export and deploy.
113 */
114 onDelete(handler: (snapshot: DataSnapshot, context: EventContext<ParamsOf<Ref>>) => PromiseLike<any> | any): CloudFunction<DataSnapshot>;
115 private onOperation;
116 private changeConstructor;
117}