2222
2323import { Request , Response } from 'express' ;
2424import * as _ from 'lodash' ;
25- import {
26- DEFAULT_FAILURE_POLICY ,
27- DeploymentOptions ,
28- FailurePolicy ,
29- MEMORY_LOOKUP ,
30- Schedule ,
31- } from './function-configuration' ;
25+ import { DeploymentOptions , Schedule } from './function-configuration' ;
3226export { Request , Response } ;
3327
3428/** @hidden */
@@ -208,7 +202,6 @@ export namespace Change {
208202 if ( json . fieldMask ) {
209203 before = applyFieldMask ( before , json . after , json . fieldMask ) ;
210204 }
211-
212205 return Change . fromObjects (
213206 customizer ( before || { } ) ,
214207 customizer ( json . after || { } )
@@ -223,16 +216,14 @@ export namespace Change {
223216 ) {
224217 const before = _ . assign ( { } , after ) ;
225218 const masks = fieldMask . split ( ',' ) ;
226-
227- masks . forEach ( ( mask ) => {
219+ _ . forEach ( masks , ( mask ) => {
228220 const val = _ . get ( sparseBefore , mask ) ;
229221 if ( typeof val === 'undefined' ) {
230222 _ . unset ( before , mask ) ;
231223 } else {
232224 _ . set ( before , mask , val ) ;
233225 }
234226 } ) ;
235-
236227 return before ;
237228 }
238229}
@@ -262,7 +253,6 @@ export interface TriggerAnnotated {
262253 resource : string ;
263254 service : string ;
264255 } ;
265- failurePolicy ?: FailurePolicy ;
266256 httpsTrigger ?: { } ;
267257 labels ?: { [ key : string ] : string } ;
268258 regions ?: string [ ] ;
@@ -322,40 +312,6 @@ export interface MakeCloudFunctionArgs<EventData> {
322312 triggerResource : ( ) => string ;
323313}
324314
325- /** @hidden */
326- export function optionsToTrigger ( {
327- failurePolicy : failurePolicyOrAlias ,
328- memory,
329- regions,
330- schedule,
331- timeoutSeconds,
332- } : DeploymentOptions ) : TriggerAnnotated [ '__trigger' ] {
333- /*
334- * FailurePolicy can be aliased with a boolean value in the public API.
335- * Convert aliases `true` and `false` to a standardized interface.
336- */
337- const failurePolicy : FailurePolicy | undefined =
338- failurePolicyOrAlias === false
339- ? undefined
340- : failurePolicyOrAlias === true
341- ? DEFAULT_FAILURE_POLICY
342- : failurePolicyOrAlias ;
343-
344- const availableMemoryMb : number | undefined =
345- memory === undefined ? undefined : MEMORY_LOOKUP [ memory ] ;
346-
347- const timeout : string | undefined =
348- timeoutSeconds === undefined ? undefined : `${ timeoutSeconds } s` ;
349-
350- return {
351- ...( failurePolicy === undefined ? { } : { failurePolicy } ) ,
352- ...( availableMemoryMb === undefined ? { } : { availableMemoryMb } ) ,
353- ...( regions === undefined ? { } : { regions } ) ,
354- ...( schedule === undefined ? { } : { schedule } ) ,
355- ...( timeout === undefined ? { } : { timeout } ) ,
356- } ;
357- }
358-
359315/** @hidden */
360316export function makeCloudFunction < EventData > ( {
361317 after = ( ) => { } ,
@@ -507,3 +463,28 @@ function _detectAuthType(event: Event) {
507463 }
508464 return 'UNAUTHENTICATED' ;
509465}
466+
467+ /** @hidden */
468+ export function optionsToTrigger ( options : DeploymentOptions ) {
469+ const trigger : any = { } ;
470+ if ( options . regions ) {
471+ trigger . regions = options . regions ;
472+ }
473+ if ( options . timeoutSeconds ) {
474+ trigger . timeout = options . timeoutSeconds . toString ( ) + 's' ;
475+ }
476+ if ( options . memory ) {
477+ const memoryLookup = {
478+ '128MB' : 128 ,
479+ '256MB' : 256 ,
480+ '512MB' : 512 ,
481+ '1GB' : 1024 ,
482+ '2GB' : 2048 ,
483+ } ;
484+ trigger . availableMemoryMb = _ . get ( memoryLookup , options . memory ) ;
485+ }
486+ if ( options . schedule ) {
487+ trigger . schedule = options . schedule ;
488+ }
489+ return trigger ;
490+ }
0 commit comments