UNPKG

9.03 kBTypeScriptView Raw
1import * as express from "express";
2import { ResetValue } from "../common/options";
3import { Expression } from "../params/types";
4import { EventContext } from "./cloud-functions";
5import { DeploymentOptions, RuntimeOptions, SUPPORTED_REGIONS } from "./function-configuration";
6import * as analytics from "./providers/analytics";
7import * as auth from "./providers/auth";
8import * as database from "./providers/database";
9import * as firestore from "./providers/firestore";
10import * as https from "./providers/https";
11import * as pubsub from "./providers/pubsub";
12import * as remoteConfig from "./providers/remoteConfig";
13import * as storage from "./providers/storage";
14import * as tasks from "./providers/tasks";
15import * as testLab from "./providers/testLab";
16/**
17 * Configure the regions that the function is deployed to.
18 * @param regions One of more region strings.
19 * @example
20 * functions.region('us-east1')
21 * @example
22 * functions.region('us-east1', 'us-central1')
23 */
24export declare function region(...regions: Array<(typeof SUPPORTED_REGIONS)[number] | string | Expression<string> | ResetValue>): FunctionBuilder;
25/**
26 * Configure runtime options for the function.
27 * @param runtimeOptions Object with optional fields:
28 * 1. `memory`: amount of memory to allocate to the function, possible values
29 * are: '128MB', '256MB', '512MB', '1GB', '2GB', '4GB', and '8GB'.
30 * 2. `timeoutSeconds`: timeout for the function in seconds, possible values are
31 * 0 to 540.
32 * 3. `failurePolicy`: failure policy of the function, with boolean `true` being
33 * equivalent to providing an empty retry object.
34 * 4. `vpcConnector`: id of a VPC connector in same project and region.
35 * 5. `vpcConnectorEgressSettings`: when a vpcConnector is set, control which
36 * egress traffic is sent through the vpcConnector.
37 * 6. `serviceAccount`: Specific service account for the function.
38 * 7. `ingressSettings`: ingress settings for the function, which control where a HTTPS
39 * function can be called from.
40 *
41 * Value must not be null.
42 */
43export declare function runWith(runtimeOptions: RuntimeOptions): FunctionBuilder;
44export declare class FunctionBuilder {
45 private options;
46 constructor(options: DeploymentOptions);
47 /**
48 * Configure the regions that the function is deployed to.
49 * @param regions One or more region strings.
50 * @example
51 * functions.region('us-east1')
52 * @example
53 * functions.region('us-east1', 'us-central1')
54 */
55 region(...regions: Array<(typeof SUPPORTED_REGIONS)[number] | string | Expression<string> | ResetValue>): FunctionBuilder;
56 /**
57 * Configure runtime options for the function.
58 * @param runtimeOptions Object with optional fields:
59 * 1. `memory`: amount of memory to allocate to the function, possible values
60 * are: '128MB', '256MB', '512MB', '1GB', '2GB', '4GB', and '8GB'.
61 * 2. `timeoutSeconds`: timeout for the function in seconds, possible values are
62 * 0 to 540.
63 * 3. `failurePolicy`: failure policy of the function, with boolean `true` being
64 * equivalent to providing an empty retry object.
65 * 4. `vpcConnector`: id of a VPC connector in the same project and region
66 * 5. `vpcConnectorEgressSettings`: when a `vpcConnector` is set, control which
67 * egress traffic is sent through the `vpcConnector`.
68 *
69 * Value must not be null.
70 */
71 runWith(runtimeOptions: RuntimeOptions): FunctionBuilder;
72 get https(): {
73 /**
74 * Handle HTTP requests.
75 * @param handler A function that takes a request and response object,
76 * same signature as an Express app.
77 */
78 onRequest: (handler: (req: https.Request, resp: express.Response) => void | Promise<void>) => import("./cloud-functions").HttpsFunction;
79 /**
80 * Declares a callable method for clients to call using a Firebase SDK.
81 * @param handler A method that takes a data and context and returns a value.
82 */
83 onCall: (handler: (data: any, context: https.CallableContext) => any | Promise<any>) => import("./cloud-functions").HttpsFunction & import("./cloud-functions").Runnable<any>;
84 };
85 get tasks(): {
86 /**
87 * Declares a task queue function for clients to call using a Firebase Admin SDK.
88 * @param options Configurations for the task queue function.
89 */
90 /** @hidden */
91 taskQueue: (options?: tasks.TaskQueueOptions) => tasks.TaskQueueBuilder;
92 };
93 get database(): {
94 /**
95 * Selects a database instance that will trigger the function. If omitted,
96 * will pick the default database for your project.
97 * @param instance The Realtime Database instance to use.
98 */
99 instance: (instance: string) => database.InstanceBuilder;
100 /**
101 * Select Firebase Realtime Database Reference to listen to.
102 *
103 * This method behaves very similarly to the method of the same name in
104 * the client and Admin Firebase SDKs. Any change to the Database that
105 * affects the data at or below the provided `path` will fire an event in
106 * Cloud Functions.
107 *
108 * There are three important differences between listening to a Realtime
109 * Database event in Cloud Functions and using the Realtime Database in
110 * the client and Admin SDKs:
111 * 1. Cloud Functions allows wildcards in the `path` name. Any `path`
112 * component in curly brackets (`{}`) is a wildcard that matches all
113 * strings. The value that matched a certain invocation of a Cloud
114 * Function is returned as part of the `context.params` object. For
115 * example, `ref("messages/{messageId}")` matches changes at
116 * `/messages/message1` or `/messages/message2`, resulting in
117 * `context.params.messageId` being set to `"message1"` or
118 * `"message2"`, respectively.
119 * 2. Cloud Functions do not fire an event for data that already existed
120 * before the Cloud Function was deployed.
121 * 3. Cloud Function events have access to more information, including
122 * information about the user who triggered the Cloud Function.
123 * @param ref Path of the database to listen to.
124 */
125 ref: <Ref extends string>(path: Ref) => database.RefBuilder<Ref>;
126 };
127 get firestore(): {
128 /**
129 * Select the Firestore document to listen to for events.
130 * @param path Full database path to listen to. This includes the name of
131 * the collection that the document is a part of. For example, if the
132 * collection is named "users" and the document is named "Ada", then the
133 * path is "/users/Ada".
134 */
135 document: <Path extends string>(path: Path) => firestore.DocumentBuilder<Path>;
136 /** @hidden */
137 namespace: (namespace: string) => firestore.NamespaceBuilder;
138 /** @hidden */
139 database: (database: string) => firestore.DatabaseBuilder;
140 };
141 get analytics(): {
142 /**
143 * Select analytics events to listen to for events.
144 * @param analyticsEventType Name of the analytics event type.
145 */
146 event: (analyticsEventType: string) => analytics.AnalyticsEventBuilder;
147 };
148 get remoteConfig(): {
149 /**
150 * Handle all updates (including rollbacks) that affect a Remote Config
151 * project.
152 * @param handler A function that takes the updated Remote Config template
153 * version metadata as an argument.
154 */
155 onUpdate: (handler: (version: remoteConfig.TemplateVersion, context: EventContext) => PromiseLike<any> | any) => import("./cloud-functions").CloudFunction<remoteConfig.TemplateVersion>;
156 };
157 get storage(): {
158 /**
159 * The optional bucket function allows you to choose which buckets' events
160 * to handle. This step can be bypassed by calling object() directly,
161 * which will use the default Cloud Storage for Firebase bucket.
162 * @param bucket Name of the Google Cloud Storage bucket to listen to.
163 */
164 bucket: (bucket?: string) => storage.BucketBuilder;
165 /**
166 * Handle events related to Cloud Storage objects.
167 */
168 object: () => storage.ObjectBuilder;
169 };
170 get pubsub(): {
171 /**
172 * Select Cloud Pub/Sub topic to listen to.
173 * @param topic Name of Pub/Sub topic, must belong to the same project as
174 * the function.
175 */
176 topic: (topic: string) => pubsub.TopicBuilder;
177 schedule: (schedule: string) => pubsub.ScheduleBuilder;
178 };
179 get auth(): {
180 /**
181 * Handle events related to Firebase authentication users.
182 */
183 user: (userOptions?: auth.UserOptions) => auth.UserBuilder;
184 };
185 get testLab(): {
186 /**
187 * Handle events related to Test Lab test matrices.
188 */
189 testMatrix: () => testLab.TestMatrixBuilder;
190 };
191}