20
20
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
// SOFTWARE.
22
22
23
+ import * as logger from "../logger" ;
24
+
23
25
/*
24
26
* A CEL expression which can be evaluated during function deployment, and
25
27
* resolved to a value of the generic type parameter: i.e, you can pass
28
30
export abstract class Expression < T extends string | number | boolean | string [ ] > {
29
31
/** Returns the Expression's runtime value, based on the CLI's resolution of params. */
30
32
value ( ) : T {
33
+ if ( process . env . FUNCTIONS_CONTROL_API === "true" ) {
34
+ logger . warn (
35
+ `${ this . toString ( ) } .value() invoked during function deployment, instead of during runtime.`
36
+ ) ;
37
+ logger . warn (
38
+ `This is usually a mistake. In configs, use Params directly without calling .value().`
39
+ ) ;
40
+ logger . warn ( `example: { memory: memoryParam } not { memory: memoryParam.value() }` ) ;
41
+ }
42
+ return this . runtimeValue ( ) ;
43
+ }
44
+
45
+ /** @internal */
46
+ runtimeValue ( ) : T {
31
47
throw new Error ( "Not implemented" ) ;
32
48
}
33
49
@@ -47,7 +63,7 @@ function quoteIfString<T extends string | number | boolean | string[]>(literal:
47
63
}
48
64
49
65
function valueOf < T extends string | number | boolean | string [ ] > ( arg : T | Expression < T > ) : T {
50
- return arg instanceof Expression ? arg . value ( ) : arg ;
66
+ return arg instanceof Expression ? arg . runtimeValue ( ) : arg ;
51
67
}
52
68
function refOf < T extends string | number | boolean | string [ ] > ( arg : T | Expression < T > ) : string {
53
69
return arg instanceof Expression ? arg . toString ( ) : quoteIfString ( arg ) . toString ( ) ;
@@ -69,9 +85,9 @@ export class TernaryExpression<
69
85
this . ifFalse = ifFalse ;
70
86
}
71
87
72
- /** Returns the Expression's runtime value, based on the CLI's resolution of params. */
73
- value ( ) : T {
74
- return this . test . value ( ) ? valueOf ( this . ifTrue ) : valueOf ( this . ifFalse ) ;
88
+ /** @internal */
89
+ runtimeValue ( ) : T {
90
+ return this . test . runtimeValue ( ) ? valueOf ( this . ifTrue ) : valueOf ( this . ifFalse ) ;
75
91
}
76
92
77
93
toString ( ) {
@@ -101,9 +117,9 @@ export class CompareExpression<
101
117
this . rhs = rhs ;
102
118
}
103
119
104
- /** Returns the Expression's runtime value, based on the CLI's resolution of params. */
105
- value ( ) : boolean {
106
- const left = this . lhs . value ( ) ;
120
+ /** @internal */
121
+ runtimeValue ( ) : boolean {
122
+ const left = this . lhs . runtimeValue ( ) ;
107
123
const right = valueOf ( this . rhs ) ;
108
124
switch ( this . cmp ) {
109
125
case "==" :
@@ -239,8 +255,8 @@ export abstract class Param<T extends string | number | boolean | string[]> exte
239
255
super ( ) ;
240
256
}
241
257
242
- /** Returns the Expression's runtime value, based on the CLI's resolution of params. */
243
- value ( ) : T {
258
+ /** @internal */
259
+ runtimeValue ( ) : T {
244
260
throw new Error ( "Not implemented" ) ;
245
261
}
246
262
@@ -321,8 +337,8 @@ export class SecretParam {
321
337
this . name = name ;
322
338
}
323
339
324
- /** Returns the Expression's runtime value, based on the latest version of the Secret in Cloud Secret Manager */
325
- value ( ) : string {
340
+ /** @internal */
341
+ runtimeValue ( ) : string {
326
342
return process . env [ this . name ] || "" ;
327
343
}
328
344
@@ -340,7 +356,8 @@ export class SecretParam {
340
356
* if present, or prompted for by the CLI if missing.
341
357
*/
342
358
export class StringParam extends Param < string > {
343
- value ( ) : string {
359
+ /** @internal */
360
+ runtimeValue ( ) : string {
344
361
return process . env [ this . name ] || "" ;
345
362
}
346
363
}
@@ -357,7 +374,8 @@ export class InternalExpression extends Param<string> {
357
374
super ( name ) ;
358
375
}
359
376
360
- value ( ) : string {
377
+ /** @internal */
378
+ runtimeValue ( ) : string {
361
379
return this . getter ( process . env ) || "" ;
362
380
}
363
381
@@ -373,7 +391,8 @@ export class InternalExpression extends Param<string> {
373
391
export class IntParam extends Param < number > {
374
392
static type : ParamValueType = "int" ;
375
393
376
- value ( ) : number {
394
+ /** @internal */
395
+ runtimeValue ( ) : number {
377
396
return parseInt ( process . env [ this . name ] || "0" , 10 ) || 0 ;
378
397
}
379
398
}
@@ -385,7 +404,8 @@ export class IntParam extends Param<number> {
385
404
export class FloatParam extends Param < number > {
386
405
static type : ParamValueType = "float" ;
387
406
388
- value ( ) : number {
407
+ /** @internal */
408
+ runtimeValue ( ) : number {
389
409
return parseFloat ( process . env [ this . name ] || "0" ) || 0 ;
390
410
}
391
411
}
@@ -397,8 +417,8 @@ export class FloatParam extends Param<number> {
397
417
export class BooleanParam extends Param < boolean > {
398
418
static type : ParamValueType = "boolean" ;
399
419
400
- /** Returns the Expression's runtime value, based on the CLI's resolution of params. */
401
- value ( ) : boolean {
420
+ /** @internal */
421
+ runtimeValue ( ) : boolean {
402
422
return ! ! process . env [ this . name ] && process . env [ this . name ] === "true" ;
403
423
}
404
424
@@ -411,8 +431,8 @@ export class BooleanParam extends Param<boolean> {
411
431
export class ListParam extends Param < string [ ] > {
412
432
static type : ParamValueType = "list" ;
413
433
414
- /** Returns the Expression's runtime value, based on the CLI's resolution of params. */
415
- value ( ) : string [ ] {
434
+ /** @internal */
435
+ runtimeValue ( ) : string [ ] {
416
436
throw new Error ( "Not implemented" ) ;
417
437
}
418
438
0 commit comments