Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
- Fixes error when last argument to logger methods is `null`. (#716)
- Adds newly available locations `us-west3`, `europe-west6`, `northamerica-northeast1`, and `australia-southeast1`.
- No longer throw errors for unrecognized regions (deploy will error instead).
7 changes: 7 additions & 0 deletions scripts/fetch-regions
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

if [ -z $1 ]; then
echo "Must provide a project id as first argument." && exit 1
fi;

gcloud functions regions list --project $1 --format=json | jq 'map(.locationId)'
30 changes: 0 additions & 30 deletions spec/function-builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,6 @@ describe('FunctionBuilder', () => {
expect(fn.__trigger.timeout).to.deep.equal('90s');
});

it('should fail if valid runtime options but unsupported region are set (reverse order)', () => {
expect(() => {
functions
.runWith({ timeoutSeconds: 90, memory: '256MB' })
.region('unsupported' as any);
}).to.throw(Error, 'region');
});

it('should fail if supported region but invalid runtime options are set (reverse order)', () => {
expect(() => {
functions
Expand Down Expand Up @@ -165,28 +157,6 @@ describe('FunctionBuilder', () => {
}).to.throw(Error, 'TimeoutSeconds');
});

it('should throw an error if user chooses an invalid region', () => {
expect(() => {
return functions.region('unsupported' as any);
}).to.throw(Error, 'region');

expect(() => {
return functions.region('unsupported' as any).runWith({
timeoutSeconds: 500,
} as any);
}).to.throw(Error, 'region');

expect(() => {
return functions.region('unsupported' as any, 'us-east1');
}).to.throw(Error, 'region');

expect(() => {
return functions.region('unsupported' as any, 'us-east1').runWith({
timeoutSeconds: 500,
} as any);
}).to.throw(Error, 'region');
});

it('should throw an error if user chooses no region when using .region()', () => {
expect(() => {
return functions.region();
Expand Down
11 changes: 4 additions & 7 deletions src/function-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ function assertRegionsAreValid(regions: string[]): boolean {
if (!regions.length) {
throw new Error('You must specify at least one region');
}
if (_.difference(regions, SUPPORTED_REGIONS).length) {
throw new Error(
`The only valid regions are: ${SUPPORTED_REGIONS.join(', ')}`
);
}
return true;
}

Expand All @@ -95,7 +90,7 @@ function assertRegionsAreValid(regions: string[]): boolean {
* functions.region('us-east1', 'us-central1')
*/
export function region(
...regions: Array<typeof SUPPORTED_REGIONS[number]>
...regions: Array<typeof SUPPORTED_REGIONS[number] | string>
): FunctionBuilder {
if (assertRegionsAreValid(regions)) {
return new FunctionBuilder({ regions });
Expand Down Expand Up @@ -127,7 +122,9 @@ export class FunctionBuilder {
* @example
* functions.region('us-east1', 'us-central1')
*/
region(...regions: Array<typeof SUPPORTED_REGIONS[number]>): FunctionBuilder {
region(
...regions: Array<typeof SUPPORTED_REGIONS[number] | string>
): FunctionBuilder {
if (assertRegionsAreValid(regions)) {
this.options.regions = regions;
return this;
Expand Down
6 changes: 5 additions & 1 deletion src/function-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ export const SUPPORTED_REGIONS = [
'us-central1',
'us-east1',
'us-east4',
'us-west3',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that GCF supports so many region could we consider changing the invalid region check from an error to a warning? That way we don't have to keep chasing this list.

We can link people to this page from the warning:
https://cloud.google.com/functions/docs/locations

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not actually going to have it error or warn anymore. The supported regions will just be a TypeScript hinting convenience, and in a followup I think we should have the CLI do a live check against the locations API instead.

'europe-west1',
'europe-west2',
'europe-west3',
'europe-west6',
'asia-east2',
'asia-northeast1',
'northamerica-northeast1',
'australia-southeast1',
] as const;

/**
Expand Down Expand Up @@ -70,6 +74,6 @@ export interface RuntimeOptions {
}

export interface DeploymentOptions extends RuntimeOptions {
regions?: Array<typeof SUPPORTED_REGIONS[number]>;
regions?: Array<typeof SUPPORTED_REGIONS[number] | string>;
schedule?: Schedule;
}