22
22
23
23
import { Request , Response } from 'express' ;
24
24
import * 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' ;
32
26
export { Request , Response } ;
33
27
34
28
/** @hidden */
@@ -208,7 +202,6 @@ export namespace Change {
208
202
if ( json . fieldMask ) {
209
203
before = applyFieldMask ( before , json . after , json . fieldMask ) ;
210
204
}
211
-
212
205
return Change . fromObjects (
213
206
customizer ( before || { } ) ,
214
207
customizer ( json . after || { } )
@@ -223,16 +216,14 @@ export namespace Change {
223
216
) {
224
217
const before = _ . assign ( { } , after ) ;
225
218
const masks = fieldMask . split ( ',' ) ;
226
-
227
- masks . forEach ( ( mask ) => {
219
+ _ . forEach ( masks , ( mask ) => {
228
220
const val = _ . get ( sparseBefore , mask ) ;
229
221
if ( typeof val === 'undefined' ) {
230
222
_ . unset ( before , mask ) ;
231
223
} else {
232
224
_ . set ( before , mask , val ) ;
233
225
}
234
226
} ) ;
235
-
236
227
return before ;
237
228
}
238
229
}
@@ -262,7 +253,6 @@ export interface TriggerAnnotated {
262
253
resource : string ;
263
254
service : string ;
264
255
} ;
265
- failurePolicy ?: FailurePolicy ;
266
256
httpsTrigger ?: { } ;
267
257
labels ?: { [ key : string ] : string } ;
268
258
regions ?: string [ ] ;
@@ -322,40 +312,6 @@ export interface MakeCloudFunctionArgs<EventData> {
322
312
triggerResource : ( ) => string ;
323
313
}
324
314
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
-
359
315
/** @hidden */
360
316
export function makeCloudFunction < EventData > ( {
361
317
after = ( ) => { } ,
@@ -507,3 +463,28 @@ function _detectAuthType(event: Event) {
507
463
}
508
464
return 'UNAUTHENTICATED' ;
509
465
}
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