Skip to content

Commit

Permalink
Adds region to params (#1353)
Browse files Browse the repository at this point in the history
* update region to be a param

* formatter
  • Loading branch information
colerogers committed Apr 13, 2023
1 parent 74471b5 commit d9e379f
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 17 deletions.
1 change: 1 addition & 0 deletions 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).
13 changes: 9 additions & 4 deletions src/v1/function-builder.ts
Expand Up @@ -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}`);
}

Expand Down Expand Up @@ -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<string> | ResetValue)[]): boolean {
if (!regions.length) {
throw new Error("You must specify at least one region");
}
Expand All @@ -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<string> | ResetValue>
): FunctionBuilder {
if (assertRegionsAreValid(regions)) {
return new FunctionBuilder({ regions });
Expand Down Expand Up @@ -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<string> | ResetValue>
): FunctionBuilder {
if (assertRegionsAreValid(regions)) {
this.options.regions = regions;
return this;
Expand Down
2 changes: 1 addition & 1 deletion src/v1/function-configuration.ts
Expand Up @@ -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<string> | ResetValue>;
/**
* Schedule for the scheduled function.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/v2/options.ts
Expand Up @@ -102,7 +102,7 @@ export interface GlobalOptions {
/**
* Region where functions should be deployed.
*/
region?: SupportedRegion | string;
region?: SupportedRegion | string | Expression<string> | ResetValue;

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

/** Region of the EventArc trigger. */
// region?: string | Expression<string> | null;
region?: string;
region?: string | Expression<string> | 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<string> | ResetValue;
Expand Down
2 changes: 1 addition & 1 deletion src/v2/providers/alerts/alerts.ts
Expand Up @@ -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<string> | ResetValue;

/**
* Amount of memory to allocate to a function.
Expand Down
2 changes: 1 addition & 1 deletion src/v2/providers/alerts/appDistribution.ts
Expand Up @@ -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<string> | ResetValue;

/**
* Amount of memory to allocate to a function.
Expand Down
2 changes: 1 addition & 1 deletion src/v2/providers/alerts/crashlytics.ts
Expand Up @@ -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<string> | ResetValue;

/**
* Amount of memory to allocate to a function.
Expand Down
2 changes: 1 addition & 1 deletion src/v2/providers/database.ts
Expand Up @@ -106,7 +106,7 @@ export interface ReferenceOptions<Ref extends string = string> extends options.E
/**
* Region where functions should be deployed.
*/
region?: options.SupportedRegion | string;
region?: options.SupportedRegion | string | Expression<string> | ResetValue;

/**
* Amount of memory to allocate to a function.
Expand Down
2 changes: 1 addition & 1 deletion src/v2/providers/eventarc.ts
Expand Up @@ -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<string> | ResetValue;

/**
* Amount of memory to allocate to a function.
Expand Down
7 changes: 6 additions & 1 deletion src/v2/providers/https.ts
Expand Up @@ -56,7 +56,12 @@ export interface HttpsOptions extends Omit<GlobalOptions, "region"> {
omit?: boolean | Expression<boolean>;

/** HTTP functions can override global options and can specify multiple regions to deploy to. */
region?: SupportedRegion | string | Array<SupportedRegion | string>;
region?:
| SupportedRegion
| string
| Array<SupportedRegion | string>
| Expression<string>
| 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.
Expand Down
2 changes: 1 addition & 1 deletion src/v2/providers/identity.ts
Expand Up @@ -72,7 +72,7 @@ export interface BlockingOptions {
/**
* Region where functions should be deployed.
*/
region?: options.SupportedRegion | string;
region?: options.SupportedRegion | string | Expression<string> | ResetValue;

/**
* Amount of memory to allocate to a function.
Expand Down
2 changes: 1 addition & 1 deletion src/v2/providers/pubsub.ts
Expand Up @@ -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<string> | ResetValue;

/**
* Amount of memory to allocate to a function.
Expand Down
2 changes: 1 addition & 1 deletion src/v2/providers/storage.ts
Expand Up @@ -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<string> | ResetValue;

/**
* Amount of memory to allocate to a function.
Expand Down
2 changes: 1 addition & 1 deletion src/v2/providers/tasks.ts
Expand Up @@ -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<string> | ResetValue;

/**
* Amount of memory to allocate to a function.
Expand Down

0 comments on commit d9e379f

Please sign in to comment.