diff --git a/CHANGELOG.md b/CHANGELOG.md index 3daeae109..6dfc4e915 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,3 @@ - Enhance firstore triggers (#1358). - Allow parametrized string type in ServiceAccount fields in Functions and trigger configs (#1309) +- Adds support for region params (#1353). diff --git a/src/v1/function-builder.ts b/src/v1/function-builder.ts index 1812e3318..e70f26166 100644 --- a/src/v1/function-builder.ts +++ b/src/v1/function-builder.ts @@ -58,7 +58,10 @@ function assertRuntimeOptionsValid(runtimeOptions: RuntimeOptions): boolean { `The only valid memory allocation values are: ${VALID_MEMORY_OPTIONS.join(", ")}` ); } - if (runtimeOptions.timeoutSeconds > MAX_TIMEOUT_SECONDS || runtimeOptions.timeoutSeconds < 0) { + if ( + typeof runtimeOptions.timeoutSeconds === "number" && + (runtimeOptions.timeoutSeconds > MAX_TIMEOUT_SECONDS || runtimeOptions.timeoutSeconds < 0) + ) { throw new Error(`TimeoutSeconds must be between 0 and ${MAX_TIMEOUT_SECONDS}`); } @@ -236,7 +239,7 @@ function validateFailurePolicy(policy: any) { * @param regions list of regions. * @throws { Error } Regions must be in list of supported regions. */ -function assertRegionsAreValid(regions: string[]): boolean { +function assertRegionsAreValid(regions: (string | Expression | ResetValue)[]): boolean { if (!regions.length) { throw new Error("You must specify at least one region"); } @@ -252,7 +255,7 @@ function assertRegionsAreValid(regions: string[]): boolean { * functions.region('us-east1', 'us-central1') */ export function region( - ...regions: Array<(typeof SUPPORTED_REGIONS)[number] | string> + ...regions: Array<(typeof SUPPORTED_REGIONS)[number] | string | Expression | ResetValue> ): FunctionBuilder { if (assertRegionsAreValid(regions)) { return new FunctionBuilder({ regions }); @@ -294,7 +297,9 @@ export class FunctionBuilder { * @example * functions.region('us-east1', 'us-central1') */ - region(...regions: Array<(typeof SUPPORTED_REGIONS)[number] | string>): FunctionBuilder { + region( + ...regions: Array<(typeof SUPPORTED_REGIONS)[number] | string | Expression | ResetValue> + ): FunctionBuilder { if (assertRegionsAreValid(regions)) { this.options.regions = regions; return this; diff --git a/src/v1/function-configuration.ts b/src/v1/function-configuration.ts index 477646fe5..0527572ee 100644 --- a/src/v1/function-configuration.ts +++ b/src/v1/function-configuration.ts @@ -270,7 +270,7 @@ export interface DeploymentOptions extends RuntimeOptions { /** * Regions where function should be deployed. */ - regions?: Array<(typeof SUPPORTED_REGIONS)[number] | string>; + regions?: Array<(typeof SUPPORTED_REGIONS)[number] | string | Expression | ResetValue>; /** * Schedule for the scheduled function. */ diff --git a/src/v2/options.ts b/src/v2/options.ts index f489588e1..6d31dfda1 100644 --- a/src/v2/options.ts +++ b/src/v2/options.ts @@ -102,7 +102,7 @@ export interface GlobalOptions { /** * Region where functions should be deployed. */ - region?: SupportedRegion | string; + region?: SupportedRegion | string | Expression | ResetValue; /** * Amount of memory to allocate to a function. @@ -252,7 +252,7 @@ export interface EventHandlerOptions extends Omit | null; - region?: string; + region?: string | Expression | ResetValue; /** The service account that EventArc should use to invoke this function. Requires the P4SA to have ActAs permission on this service account. */ serviceAccount?: string | Expression | ResetValue; diff --git a/src/v2/providers/alerts/alerts.ts b/src/v2/providers/alerts/alerts.ts index cfb3f64e3..050721f54 100644 --- a/src/v2/providers/alerts/alerts.ts +++ b/src/v2/providers/alerts/alerts.ts @@ -94,7 +94,7 @@ export interface FirebaseAlertOptions extends options.EventHandlerOptions { /** * Region where functions should be deployed. */ - region?: options.SupportedRegion | string; + region?: options.SupportedRegion | string | Expression | ResetValue; /** * Amount of memory to allocate to a function. diff --git a/src/v2/providers/alerts/appDistribution.ts b/src/v2/providers/alerts/appDistribution.ts index 7fb5833a1..239233d73 100644 --- a/src/v2/providers/alerts/appDistribution.ts +++ b/src/v2/providers/alerts/appDistribution.ts @@ -105,7 +105,7 @@ export interface AppDistributionOptions extends options.EventHandlerOptions { /** * Region where functions should be deployed. */ - region?: options.SupportedRegion | string; + region?: options.SupportedRegion | string | Expression | ResetValue; /** * Amount of memory to allocate to a function. diff --git a/src/v2/providers/alerts/crashlytics.ts b/src/v2/providers/alerts/crashlytics.ts index ea0566c13..0e9cb7d8d 100644 --- a/src/v2/providers/alerts/crashlytics.ts +++ b/src/v2/providers/alerts/crashlytics.ts @@ -185,7 +185,7 @@ export interface CrashlyticsOptions extends options.EventHandlerOptions { /** * Region where functions should be deployed. */ - region?: options.SupportedRegion | string; + region?: options.SupportedRegion | string | Expression | ResetValue; /** * Amount of memory to allocate to a function. diff --git a/src/v2/providers/database.ts b/src/v2/providers/database.ts index dbf7dbdb6..c3318855c 100644 --- a/src/v2/providers/database.ts +++ b/src/v2/providers/database.ts @@ -106,7 +106,7 @@ export interface ReferenceOptions extends options.E /** * Region where functions should be deployed. */ - region?: options.SupportedRegion | string; + region?: options.SupportedRegion | string | Expression | ResetValue; /** * Amount of memory to allocate to a function. diff --git a/src/v2/providers/eventarc.ts b/src/v2/providers/eventarc.ts index 3d1a696cb..6d980e2f9 100644 --- a/src/v2/providers/eventarc.ts +++ b/src/v2/providers/eventarc.ts @@ -70,7 +70,7 @@ export interface EventarcTriggerOptions extends options.EventHandlerOptions { /** * Region where functions should be deployed. */ - region?: options.SupportedRegion | string; + region?: options.SupportedRegion | string | Expression | ResetValue; /** * Amount of memory to allocate to a function. diff --git a/src/v2/providers/https.ts b/src/v2/providers/https.ts index 80def4273..461c632f2 100644 --- a/src/v2/providers/https.ts +++ b/src/v2/providers/https.ts @@ -56,7 +56,12 @@ export interface HttpsOptions extends Omit { omit?: boolean | Expression; /** HTTP functions can override global options and can specify multiple regions to deploy to. */ - region?: SupportedRegion | string | Array; + region?: + | SupportedRegion + | string + | Array + | Expression + | ResetValue; /** If true, allows CORS on requests to this function. * If this is a `string` or `RegExp`, allows requests from domains that match the provided value. diff --git a/src/v2/providers/identity.ts b/src/v2/providers/identity.ts index 7e8e5d5aa..3a0b1b7fc 100644 --- a/src/v2/providers/identity.ts +++ b/src/v2/providers/identity.ts @@ -72,7 +72,7 @@ export interface BlockingOptions { /** * Region where functions should be deployed. */ - region?: options.SupportedRegion | string; + region?: options.SupportedRegion | string | Expression | ResetValue; /** * Amount of memory to allocate to a function. diff --git a/src/v2/providers/pubsub.ts b/src/v2/providers/pubsub.ts index e95eca7b6..19e368d41 100644 --- a/src/v2/providers/pubsub.ts +++ b/src/v2/providers/pubsub.ts @@ -163,7 +163,7 @@ export interface PubSubOptions extends options.EventHandlerOptions { /** * Region where functions should be deployed. */ - region?: options.SupportedRegion | string; + region?: options.SupportedRegion | string | Expression | ResetValue; /** * Amount of memory to allocate to a function. diff --git a/src/v2/providers/storage.ts b/src/v2/providers/storage.ts index 248eb1869..451a257b5 100644 --- a/src/v2/providers/storage.ts +++ b/src/v2/providers/storage.ts @@ -211,7 +211,7 @@ export interface StorageOptions extends options.EventHandlerOptions { /** * Region where functions should be deployed. */ - region?: options.SupportedRegion | string; + region?: options.SupportedRegion | string | Expression | ResetValue; /** * Amount of memory to allocate to a function. diff --git a/src/v2/providers/tasks.ts b/src/v2/providers/tasks.ts index 442c92178..304dd907f 100644 --- a/src/v2/providers/tasks.ts +++ b/src/v2/providers/tasks.ts @@ -68,7 +68,7 @@ export interface TaskQueueOptions extends options.EventHandlerOptions { /** * Region where functions should be deployed. */ - region?: options.SupportedRegion | string; + region?: options.SupportedRegion | string | Expression | ResetValue; /** * Amount of memory to allocate to a function.