Skip to content

Commit d9e379f

Browse files
authored
Adds region to params (#1353)
* update region to be a param * formatter
1 parent 74471b5 commit d9e379f

14 files changed

+28
-17
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
- Enhance firstore triggers (#1358).
22
- Allow parametrized string type in ServiceAccount fields in Functions and trigger configs (#1309)
3+
- Adds support for region params (#1353).

src/v1/function-builder.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ function assertRuntimeOptionsValid(runtimeOptions: RuntimeOptions): boolean {
5858
`The only valid memory allocation values are: ${VALID_MEMORY_OPTIONS.join(", ")}`
5959
);
6060
}
61-
if (runtimeOptions.timeoutSeconds > MAX_TIMEOUT_SECONDS || runtimeOptions.timeoutSeconds < 0) {
61+
if (
62+
typeof runtimeOptions.timeoutSeconds === "number" &&
63+
(runtimeOptions.timeoutSeconds > MAX_TIMEOUT_SECONDS || runtimeOptions.timeoutSeconds < 0)
64+
) {
6265
throw new Error(`TimeoutSeconds must be between 0 and ${MAX_TIMEOUT_SECONDS}`);
6366
}
6467

@@ -236,7 +239,7 @@ function validateFailurePolicy(policy: any) {
236239
* @param regions list of regions.
237240
* @throws { Error } Regions must be in list of supported regions.
238241
*/
239-
function assertRegionsAreValid(regions: string[]): boolean {
242+
function assertRegionsAreValid(regions: (string | Expression<string> | ResetValue)[]): boolean {
240243
if (!regions.length) {
241244
throw new Error("You must specify at least one region");
242245
}
@@ -252,7 +255,7 @@ function assertRegionsAreValid(regions: string[]): boolean {
252255
* functions.region('us-east1', 'us-central1')
253256
*/
254257
export function region(
255-
...regions: Array<(typeof SUPPORTED_REGIONS)[number] | string>
258+
...regions: Array<(typeof SUPPORTED_REGIONS)[number] | string | Expression<string> | ResetValue>
256259
): FunctionBuilder {
257260
if (assertRegionsAreValid(regions)) {
258261
return new FunctionBuilder({ regions });
@@ -294,7 +297,9 @@ export class FunctionBuilder {
294297
* @example
295298
* functions.region('us-east1', 'us-central1')
296299
*/
297-
region(...regions: Array<(typeof SUPPORTED_REGIONS)[number] | string>): FunctionBuilder {
300+
region(
301+
...regions: Array<(typeof SUPPORTED_REGIONS)[number] | string | Expression<string> | ResetValue>
302+
): FunctionBuilder {
298303
if (assertRegionsAreValid(regions)) {
299304
this.options.regions = regions;
300305
return this;

src/v1/function-configuration.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ export interface DeploymentOptions extends RuntimeOptions {
270270
/**
271271
* Regions where function should be deployed.
272272
*/
273-
regions?: Array<(typeof SUPPORTED_REGIONS)[number] | string>;
273+
regions?: Array<(typeof SUPPORTED_REGIONS)[number] | string | Expression<string> | ResetValue>;
274274
/**
275275
* Schedule for the scheduled function.
276276
*/

src/v2/options.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export interface GlobalOptions {
102102
/**
103103
* Region where functions should be deployed.
104104
*/
105-
region?: SupportedRegion | string;
105+
region?: SupportedRegion | string | Expression<string> | ResetValue;
106106

107107
/**
108108
* Amount of memory to allocate to a function.
@@ -252,7 +252,7 @@ export interface EventHandlerOptions extends Omit<GlobalOptions, "enforceAppChec
252252

253253
/** Region of the EventArc trigger. */
254254
// region?: string | Expression<string> | null;
255-
region?: string;
255+
region?: string | Expression<string> | ResetValue;
256256

257257
/** The service account that EventArc should use to invoke this function. Requires the P4SA to have ActAs permission on this service account. */
258258
serviceAccount?: string | Expression<string> | ResetValue;

src/v2/providers/alerts/alerts.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export interface FirebaseAlertOptions extends options.EventHandlerOptions {
9494
/**
9595
* Region where functions should be deployed.
9696
*/
97-
region?: options.SupportedRegion | string;
97+
region?: options.SupportedRegion | string | Expression<string> | ResetValue;
9898

9999
/**
100100
* Amount of memory to allocate to a function.

src/v2/providers/alerts/appDistribution.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export interface AppDistributionOptions extends options.EventHandlerOptions {
105105
/**
106106
* Region where functions should be deployed.
107107
*/
108-
region?: options.SupportedRegion | string;
108+
region?: options.SupportedRegion | string | Expression<string> | ResetValue;
109109

110110
/**
111111
* Amount of memory to allocate to a function.

src/v2/providers/alerts/crashlytics.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export interface CrashlyticsOptions extends options.EventHandlerOptions {
185185
/**
186186
* Region where functions should be deployed.
187187
*/
188-
region?: options.SupportedRegion | string;
188+
region?: options.SupportedRegion | string | Expression<string> | ResetValue;
189189

190190
/**
191191
* Amount of memory to allocate to a function.

src/v2/providers/database.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export interface ReferenceOptions<Ref extends string = string> extends options.E
106106
/**
107107
* Region where functions should be deployed.
108108
*/
109-
region?: options.SupportedRegion | string;
109+
region?: options.SupportedRegion | string | Expression<string> | ResetValue;
110110

111111
/**
112112
* Amount of memory to allocate to a function.

src/v2/providers/eventarc.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export interface EventarcTriggerOptions extends options.EventHandlerOptions {
7070
/**
7171
* Region where functions should be deployed.
7272
*/
73-
region?: options.SupportedRegion | string;
73+
region?: options.SupportedRegion | string | Expression<string> | ResetValue;
7474

7575
/**
7676
* Amount of memory to allocate to a function.

src/v2/providers/https.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ export interface HttpsOptions extends Omit<GlobalOptions, "region"> {
5656
omit?: boolean | Expression<boolean>;
5757

5858
/** HTTP functions can override global options and can specify multiple regions to deploy to. */
59-
region?: SupportedRegion | string | Array<SupportedRegion | string>;
59+
region?:
60+
| SupportedRegion
61+
| string
62+
| Array<SupportedRegion | string>
63+
| Expression<string>
64+
| ResetValue;
6065

6166
/** If true, allows CORS on requests to this function.
6267
* If this is a `string` or `RegExp`, allows requests from domains that match the provided value.

src/v2/providers/identity.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export interface BlockingOptions {
7272
/**
7373
* Region where functions should be deployed.
7474
*/
75-
region?: options.SupportedRegion | string;
75+
region?: options.SupportedRegion | string | Expression<string> | ResetValue;
7676

7777
/**
7878
* Amount of memory to allocate to a function.

src/v2/providers/pubsub.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export interface PubSubOptions extends options.EventHandlerOptions {
163163
/**
164164
* Region where functions should be deployed.
165165
*/
166-
region?: options.SupportedRegion | string;
166+
region?: options.SupportedRegion | string | Expression<string> | ResetValue;
167167

168168
/**
169169
* Amount of memory to allocate to a function.

src/v2/providers/storage.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export interface StorageOptions extends options.EventHandlerOptions {
211211
/**
212212
* Region where functions should be deployed.
213213
*/
214-
region?: options.SupportedRegion | string;
214+
region?: options.SupportedRegion | string | Expression<string> | ResetValue;
215215

216216
/**
217217
* Amount of memory to allocate to a function.

src/v2/providers/tasks.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export interface TaskQueueOptions extends options.EventHandlerOptions {
6868
/**
6969
* Region where functions should be deployed.
7070
*/
71-
region?: options.SupportedRegion | string;
71+
region?: options.SupportedRegion | string | Expression<string> | ResetValue;
7272

7373
/**
7474
* Amount of memory to allocate to a function.

0 commit comments

Comments
 (0)