Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds region to params #1353

Merged
merged 3 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Adds support for region params.
10 changes: 6 additions & 4 deletions src/v1/function-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<string> | ResetValue)[]): boolean {
if (!regions.length) {
throw new Error("You must specify at least one region");
}
Expand All @@ -249,7 +249,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 @@ -291,7 +291,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 | ResetValue;
Expand Down
2 changes: 1 addition & 1 deletion src/v2/providers/alerts/alerts.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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