From 80b0d1b51b803b1a8ce63034b752015cef479b5e Mon Sep 17 00:00:00 2001 From: Cole Rogers Date: Fri, 24 Feb 2023 18:07:20 -0500 Subject: [PATCH 1/2] update region to be a param --- CHANGELOG.md | 1 + src/v1/function-builder.ts | 10 ++++++---- src/v1/function-configuration.ts | 2 +- src/v2/options.ts | 4 ++-- src/v2/providers/alerts/alerts.ts | 2 +- src/v2/providers/alerts/appDistribution.ts | 2 +- src/v2/providers/alerts/crashlytics.ts | 2 +- src/v2/providers/database.ts | 2 +- src/v2/providers/eventarc.ts | 2 +- src/v2/providers/https.ts | 7 ++++++- src/v2/providers/identity.ts | 2 +- src/v2/providers/pubsub.ts | 2 +- src/v2/providers/storage.ts | 2 +- src/v2/providers/tasks.ts | 2 +- 14 files changed, 25 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e69de29bb..2e0749901 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -0,0 +1 @@ +- Adds support for region params. diff --git a/src/v1/function-builder.ts b/src/v1/function-builder.ts index c7e5daa3e..3a51c9f6b 100644 --- a/src/v1/function-builder.ts +++ b/src/v1/function-builder.ts @@ -23,7 +23,7 @@ import * as express from "express"; import { ResetValue } from "../common/options"; -import { SecretParam } from "../params/types"; +import { Expression, SecretParam } from "../params/types"; import { EventContext } from "./cloud-functions"; import { DeploymentOptions, @@ -233,7 +233,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"); } @@ -249,7 +249,7 @@ function assertRegionsAreValid(regions: string[]): boolean { * functions.region('us-east1', 'us-central1') */ export function region( - ...regions: Array + ...regions: Array | ResetValue> ): FunctionBuilder { if (assertRegionsAreValid(regions)) { return new FunctionBuilder({ regions }); @@ -291,7 +291,9 @@ export class FunctionBuilder { * @example * functions.region('us-east1', 'us-central1') */ - region(...regions: Array): FunctionBuilder { + region( + ...regions: Array | 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 12165ce53..b7071ca07 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; + regions?: Array | ResetValue>; /** * Schedule for the scheduled function. */ diff --git a/src/v2/options.ts b/src/v2/options.ts index caa0638b8..6c077c9f6 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 | ResetValue; diff --git a/src/v2/providers/alerts/alerts.ts b/src/v2/providers/alerts/alerts.ts index 56a651072..939855d9f 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 499b50c94..b5103e42d 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 e6d6d7527..961eb5098 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 535cfe97c..e84cfae2e 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 42270ffaf..c508a5bef 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 eedd42e01..0daea9c2b 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 ced3ab5ba..8087af750 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 dac95a999..e50ab5e70 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 668538bcb..ac69c9129 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 dc4ced739..7ba215289 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. From 6d296275dacfa97269751f7885d1ea966447e8e4 Mon Sep 17 00:00:00 2001 From: Cole Rogers Date: Thu, 13 Apr 2023 11:25:47 -0700 Subject: [PATCH 2/2] formatter --- src/v1/function-builder.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/v1/function-builder.ts b/src/v1/function-builder.ts index 9a8030b6f..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 (typeof runtimeOptions.timeoutSeconds === "number" && (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}`); }