2323import * as express from 'express' ;
2424import * as _ from 'lodash' ;
2525
26- import { CloudFunction , EventContext , Schedule } from './cloud-functions' ;
26+ import { CloudFunction , EventContext } from './cloud-functions' ;
27+ import {
28+ DeploymentOptions ,
29+ MAX_TIMEOUT_SECONDS ,
30+ RuntimeOptions ,
31+ SUPPORTED_REGIONS ,
32+ VALID_MEMORY_OPTIONS ,
33+ } from './function-configuration' ;
2734import * as analytics from './providers/analytics' ;
2835import * as auth from './providers/auth' ;
2936import * as crashlytics from './providers/crashlytics' ;
@@ -34,34 +41,6 @@ import * as pubsub from './providers/pubsub';
3441import * as remoteConfig from './providers/remoteConfig' ;
3542import * as storage from './providers/storage' ;
3643
37- /**
38- * List of all regions supported by Cloud Functions.
39- */
40- const SUPPORTED_REGIONS = [
41- 'us-central1' ,
42- 'us-east1' ,
43- 'us-east4' ,
44- 'europe-west1' ,
45- 'europe-west2' ,
46- 'asia-east2' ,
47- 'asia-northeast1' ,
48- ] ;
49-
50- /**
51- * List of available memory options supported by Cloud Functions.
52- */
53- const VALID_MEMORY_OPTS = [ '128MB' , '256MB' , '512MB' , '1GB' , '2GB' ] ;
54-
55- // Adding this memory type here to error on compile for TS users.
56- // Unfortunately I have not found a way to merge this with VALID_MEMORY_OPS
57- // without it being super ugly. But here they are right next to each other at least.
58- type Memory = '128MB' | '256MB' | '512MB' | '1GB' | '2GB' ;
59-
60- /**
61- * Cloud Functions max timeout value.
62- */
63- const MAX_TIMEOUT_SECONDS = 540 ;
64-
6544/**
6645 * Assert that the runtime options passed in are valid.
6746 * @param runtimeOptions object containing memory and timeout information.
@@ -70,10 +49,10 @@ const MAX_TIMEOUT_SECONDS = 540;
7049function assertRuntimeOptionsValid ( runtimeOptions : RuntimeOptions ) : boolean {
7150 if (
7251 runtimeOptions . memory &&
73- ! _ . includes ( VALID_MEMORY_OPTS , runtimeOptions . memory )
52+ ! _ . includes ( VALID_MEMORY_OPTIONS , runtimeOptions . memory )
7453 ) {
7554 throw new Error (
76- `The only valid memory allocation values are: ${ VALID_MEMORY_OPTS . join (
55+ `The only valid memory allocation values are: ${ VALID_MEMORY_OPTIONS . join (
7756 ', '
7857 ) } `
7958 ) ;
@@ -111,7 +90,9 @@ function assertRegionsAreValid(regions: string[]): boolean {
11190 * @param regions One of more region strings.
11291 * For example: `functions.region('us-east1')` or `functions.region('us-east1', 'us-central1')`
11392 */
114- export function region ( ...regions : string [ ] ) : FunctionBuilder {
93+ export function region (
94+ ...regions : Array < typeof SUPPORTED_REGIONS [ number ] >
95+ ) : FunctionBuilder {
11596 if ( assertRegionsAreValid ( regions ) ) {
11697 return new FunctionBuilder ( { regions } ) ;
11798 }
@@ -130,18 +111,6 @@ export function runWith(runtimeOptions: RuntimeOptions): FunctionBuilder {
130111 }
131112}
132113
133- export interface RuntimeOptions {
134- timeoutSeconds ?: number ;
135- memory ?: Memory ;
136- }
137-
138- export interface DeploymentOptions {
139- regions ?: string [ ] ;
140- timeoutSeconds ?: number ;
141- memory ?: Memory ;
142- schedule ?: Schedule ;
143- }
144-
145114export class FunctionBuilder {
146115 constructor ( private options : DeploymentOptions ) { }
147116
@@ -150,7 +119,7 @@ export class FunctionBuilder {
150119 * @param regions One or more region strings.
151120 * For example: `functions.region('us-east1')` or `functions.region('us-east1', 'us-central1')`
152121 */
153- region ( ...regions : string [ ] ) : FunctionBuilder {
122+ region ( ...regions : Array < typeof SUPPORTED_REGIONS [ number ] > ) : FunctionBuilder {
154123 if ( assertRegionsAreValid ( regions ) ) {
155124 this . options . regions = regions ;
156125 return this ;
0 commit comments