2222
2323import { Request , Response } from 'express' ;
2424import * as _ from 'lodash' ;
25- import { DeploymentOptions , Schedule } from './function-configuration' ;
25+ import {
26+ DEFAULT_FAILURE_POLICY ,
27+ DeploymentOptions ,
28+ FailurePolicy ,
29+ MEMORY_LOOKUP ,
30+ Schedule ,
31+ } from './function-configuration' ;
2632export { Request , Response } ;
2733
2834/** @hidden */
@@ -202,6 +208,7 @@ export namespace Change {
202208 if ( json . fieldMask ) {
203209 before = applyFieldMask ( before , json . after , json . fieldMask ) ;
204210 }
211+
205212 return Change . fromObjects (
206213 customizer ( before || { } ) ,
207214 customizer ( json . after || { } )
@@ -216,14 +223,16 @@ export namespace Change {
216223 ) {
217224 const before = _ . assign ( { } , after ) ;
218225 const masks = fieldMask . split ( ',' ) ;
219- _ . forEach ( masks , ( mask ) => {
226+
227+ masks . forEach ( ( mask ) => {
220228 const val = _ . get ( sparseBefore , mask ) ;
221229 if ( typeof val === 'undefined' ) {
222230 _ . unset ( before , mask ) ;
223231 } else {
224232 _ . set ( before , mask , val ) ;
225233 }
226234 } ) ;
235+
227236 return before ;
228237 }
229238}
@@ -253,6 +262,7 @@ export interface TriggerAnnotated {
253262 resource : string ;
254263 service : string ;
255264 } ;
265+ failurePolicy ?: FailurePolicy ;
256266 httpsTrigger ?: { } ;
257267 labels ?: { [ key : string ] : string } ;
258268 regions ?: string [ ] ;
@@ -312,6 +322,40 @@ export interface MakeCloudFunctionArgs<EventData> {
312322 triggerResource : ( ) => string ;
313323}
314324
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+
315359/** @hidden */
316360export function makeCloudFunction < EventData > ( {
317361 after = ( ) => { } ,
@@ -463,28 +507,3 @@ function _detectAuthType(event: Event) {
463507 }
464508 return 'UNAUTHENTICATED' ;
465509}
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