1 | import { Change } from "../../common/change";
|
2 | import { ParamsOf } from "../../common/params";
|
3 | import { ResetValue } from "../../common/options";
|
4 | import { DataSnapshot } from "../../common/providers/database";
|
5 | import { CloudEvent, CloudFunction } from "../core";
|
6 | import { Expression } from "../../params";
|
7 | import * as options from "../options";
|
8 | import { SecretParam } from "../../params/types";
|
9 | export { DataSnapshot };
|
10 | /** @hidden */
|
11 | export interface RawRTDBCloudEventData {
|
12 | ["@type"]: "type.googleapis.com/google.events.firebase.database.v1.ReferenceEventData";
|
13 | data: any;
|
14 | delta: any;
|
15 | }
|
16 | /** @hidden */
|
17 | export interface RawRTDBCloudEvent extends CloudEvent<RawRTDBCloudEventData> {
|
18 | firebasedatabasehost: string;
|
19 | instance: string;
|
20 | ref: string;
|
21 | location: string;
|
22 | }
|
23 | /** A CloudEvent that contains a DataSnapshot or a Change<DataSnapshot> */
|
24 | export interface DatabaseEvent<T, Params = Record<string, string>> extends CloudEvent<T> {
|
25 | /** The domain of the database instance */
|
26 | firebaseDatabaseHost: string;
|
27 | /** The instance ID portion of the fully qualified resource name */
|
28 | instance: string;
|
29 | /** The database reference path */
|
30 | ref: string;
|
31 | /** The location of the database */
|
32 | location: string;
|
33 | /**
|
34 | * An object containing the values of the path patterns.
|
35 | * Only named capture groups will be populated - {key}, {key=*}, {key=**}
|
36 | */
|
37 | params: Params;
|
38 | }
|
39 | /** ReferenceOptions extend EventHandlerOptions with provided ref and optional instance */
|
40 | export interface ReferenceOptions<Ref extends string = string> extends options.EventHandlerOptions {
|
41 | /**
|
42 | * Specify the handler to trigger on a database reference(s).
|
43 | * This value can either be a single reference or a pattern.
|
44 | * Examples: '/foo/bar', '/foo/{bar}'
|
45 | */
|
46 | ref: Ref;
|
47 | /**
|
48 | * Specify the handler to trigger on a database instance(s).
|
49 | * If present, this value can either be a single instance or a pattern.
|
50 | * Examples: 'my-instance-1', 'my-instance-*'
|
51 | * Note: The capture syntax cannot be used for 'instance'.
|
52 | */
|
53 | instance?: string;
|
54 | /**
|
55 | * If true, do not deploy or emulate this function.
|
56 | */
|
57 | omit?: boolean | Expression<boolean>;
|
58 | /**
|
59 | * Region where functions should be deployed.
|
60 | */
|
61 | region?: options.SupportedRegion | string | Expression<string> | ResetValue;
|
62 | /**
|
63 | * Amount of memory to allocate to a function.
|
64 | */
|
65 | memory?: options.MemoryOption | Expression<number> | ResetValue;
|
66 | /**
|
67 | * Timeout for the function in seconds, possible values are 0 to 540.
|
68 | * HTTPS functions can specify a higher timeout.
|
69 | *
|
70 | * @remarks
|
71 | * The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
|
72 | * function depends on the type of function: Event handling functions have a
|
73 | * maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
|
74 | * maximum timeout of 3,600s (1 hour). Task queue functions have a maximum
|
75 | * timeout of 1,800s (30 minutes)
|
76 | */
|
77 | timeoutSeconds?: number | Expression<number> | ResetValue;
|
78 | /**
|
79 | * Min number of actual instances to be running at a given time.
|
80 | *
|
81 | * @remarks
|
82 | * Instances will be billed for memory allocation and 10% of CPU allocation
|
83 | * while idle.
|
84 | */
|
85 | minInstances?: number | Expression<number> | ResetValue;
|
86 | /**
|
87 | * Max number of instances to be running in parallel.
|
88 | */
|
89 | maxInstances?: number | Expression<number> | ResetValue;
|
90 | /**
|
91 | * Number of requests a function can serve at once.
|
92 | *
|
93 | * @remarks
|
94 | * Can only be applied to functions running on Cloud Functions v2.
|
95 | * A value of null restores the default concurrency (80 when CPU >= 1, 1 otherwise).
|
96 | * Concurrency cannot be set to any value other than 1 if `cpu` is less than 1.
|
97 | * The maximum value for concurrency is 1,000.
|
98 | */
|
99 | concurrency?: number | Expression<number> | ResetValue;
|
100 | /**
|
101 | * Fractional number of CPUs to allocate to a function.
|
102 | *
|
103 | * @remarks
|
104 | * Defaults to 1 for functions with <= 2GB RAM and increases for larger memory sizes.
|
105 | * This is different from the defaults when using the gcloud utility and is different from
|
106 | * the fixed amount assigned in Google Cloud Functions generation 1.
|
107 | * To revert to the CPU amounts used in gcloud or in Cloud Functions generation 1, set this
|
108 | * to the value "gcf_gen1"
|
109 | */
|
110 | cpu?: number | "gcf_gen1";
|
111 | /**
|
112 | * Connect cloud function to specified VPC connector.
|
113 | */
|
114 | vpcConnector?: string | Expression<string> | ResetValue;
|
115 | /**
|
116 | * Egress settings for VPC connector.
|
117 | */
|
118 | vpcConnectorEgressSettings?: options.VpcEgressSetting | ResetValue;
|
119 | /**
|
120 | * Specific service account for the function to run as.
|
121 | */
|
122 | serviceAccount?: string | Expression<string> | ResetValue;
|
123 | /**
|
124 | * Ingress settings which control where this function can be called from.
|
125 | */
|
126 | ingressSettings?: options.IngressSetting | ResetValue;
|
127 | /**
|
128 | * User labels to set on the function.
|
129 | */
|
130 | labels?: Record<string, string>;
|
131 | secrets?: (string | SecretParam)[];
|
132 | /** Whether failed executions should be delivered again. */
|
133 | retry?: boolean | Expression<boolean> | ResetValue;
|
134 | }
|
135 | /**
|
136 | * Event handler which triggers when data is created, updated, or deleted in Realtime Database.
|
137 | *
|
138 | * @param reference - The database reference path to trigger on.
|
139 | * @param handler - Event handler which is run every time a Realtime Database create, update, or delete occurs.
|
140 | */
|
141 | export declare function onValueWritten<Ref extends string>(ref: Ref, handler: (event: DatabaseEvent<Change<DataSnapshot>, ParamsOf<Ref>>) => any | Promise<any>): CloudFunction<DatabaseEvent<Change<DataSnapshot>, ParamsOf<Ref>>>;
|
142 | /**
|
143 | * Event handler which triggers when data is created, updated, or deleted in Realtime Database.
|
144 | *
|
145 | * @param opts - Options that can be set on an individual event-handling function.
|
146 | * @param handler - Event handler which is run every time a Realtime Database create, update, or delete occurs.
|
147 | */
|
148 | export declare function onValueWritten<Ref extends string>(opts: ReferenceOptions<Ref>, handler: (event: DatabaseEvent<Change<DataSnapshot>, ParamsOf<Ref>>) => any | Promise<any>): CloudFunction<DatabaseEvent<Change<DataSnapshot>, ParamsOf<Ref>>>;
|
149 | /**
|
150 | * Event handler which triggers when data is created in Realtime Database.
|
151 | *
|
152 | * @param reference - The database reference path to trigger on.
|
153 | * @param handler - Event handler which is run every time a Realtime Database create occurs.
|
154 | */
|
155 | export declare function onValueCreated<Ref extends string>(ref: Ref, handler: (event: DatabaseEvent<DataSnapshot, ParamsOf<Ref>>) => any | Promise<any>): CloudFunction<DatabaseEvent<DataSnapshot, ParamsOf<Ref>>>;
|
156 | /**
|
157 | * Event handler which triggers when data is created in Realtime Database.
|
158 | *
|
159 | * @param opts - Options that can be set on an individual event-handling function.
|
160 | * @param handler - Event handler which is run every time a Realtime Database create occurs.
|
161 | */
|
162 | export declare function onValueCreated<Ref extends string>(opts: ReferenceOptions<Ref>, handler: (event: DatabaseEvent<DataSnapshot, ParamsOf<Ref>>) => any | Promise<any>): CloudFunction<DatabaseEvent<DataSnapshot, ParamsOf<Ref>>>;
|
163 | /**
|
164 | * Event handler which triggers when data is updated in Realtime Database.
|
165 | *
|
166 | * @param reference - The database reference path to trigger on.
|
167 | * @param handler - Event handler which is run every time a Realtime Database update occurs.
|
168 | */
|
169 | export declare function onValueUpdated<Ref extends string>(ref: Ref, handler: (event: DatabaseEvent<Change<DataSnapshot>, ParamsOf<Ref>>) => any | Promise<any>): CloudFunction<DatabaseEvent<Change<DataSnapshot>, ParamsOf<Ref>>>;
|
170 | /**
|
171 | * Event handler which triggers when data is updated in Realtime Database.
|
172 | *
|
173 | * @param opts - Options that can be set on an individual event-handling function.
|
174 | * @param handler - Event handler which is run every time a Realtime Database update occurs.
|
175 | */
|
176 | export declare function onValueUpdated<Ref extends string>(opts: ReferenceOptions<Ref>, handler: (event: DatabaseEvent<Change<DataSnapshot>, ParamsOf<Ref>>) => any | Promise<any>): CloudFunction<DatabaseEvent<Change<DataSnapshot>, ParamsOf<Ref>>>;
|
177 | /**
|
178 | * Event handler which triggers when data is deleted in Realtime Database.
|
179 | *
|
180 | * @param reference - The database reference path to trigger on.
|
181 | * @param handler - Event handler which is run every time a Realtime Database deletion occurs.
|
182 | */
|
183 | export declare function onValueDeleted<Ref extends string>(ref: Ref, handler: (event: DatabaseEvent<DataSnapshot, ParamsOf<Ref>>) => any | Promise<any>): CloudFunction<DatabaseEvent<DataSnapshot, ParamsOf<Ref>>>;
|
184 | /**
|
185 | * Event handler which triggers when data is deleted in Realtime Database.
|
186 | *
|
187 | * @param opts - Options that can be set on an individual event-handling function.
|
188 | * @param handler - Event handler which is run every time a Realtime Database deletion occurs.
|
189 | */
|
190 | export declare function onValueDeleted<Ref extends string>(opts: ReferenceOptions<Ref>, handler: (event: DatabaseEvent<DataSnapshot, ParamsOf<Ref>>) => any | Promise<any>): CloudFunction<DatabaseEvent<DataSnapshot, ParamsOf<Ref>>>;
|