diff --git a/src/params/types.ts b/src/params/types.ts index 5521b018b..5aafb2e27 100644 --- a/src/params/types.ts +++ b/src/params/types.ts @@ -20,6 +20,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +import * as logger from "../logger"; + /* * A CEL expression which can be evaluated during function deployment, and * resolved to a value of the generic type parameter: i.e, you can pass @@ -28,6 +30,20 @@ export abstract class Expression { /** Returns the Expression's runtime value, based on the CLI's resolution of params. */ value(): T { + if (process.env.FUNCTIONS_CONTROL_API === "true") { + logger.warn( + `${this.toString()}.value() invoked during function deployment, instead of during runtime.` + ); + logger.warn( + `This is usually a mistake. In configs, use Params directly without calling .value().` + ); + logger.warn(`example: { memory: memoryParam } not { memory: memoryParam.value() }`); + } + return this.runtimeValue(); + } + + /** @internal */ + runtimeValue(): T { throw new Error("Not implemented"); } @@ -47,7 +63,7 @@ function quoteIfString(literal: } function valueOf(arg: T | Expression): T { - return arg instanceof Expression ? arg.value() : arg; + return arg instanceof Expression ? arg.runtimeValue() : arg; } function refOf(arg: T | Expression): string { return arg instanceof Expression ? arg.toString() : quoteIfString(arg).toString(); @@ -69,9 +85,9 @@ export class TernaryExpression< this.ifFalse = ifFalse; } - /** Returns the Expression's runtime value, based on the CLI's resolution of params. */ - value(): T { - return this.test.value() ? valueOf(this.ifTrue) : valueOf(this.ifFalse); + /** @internal */ + runtimeValue(): T { + return this.test.runtimeValue() ? valueOf(this.ifTrue) : valueOf(this.ifFalse); } toString() { @@ -101,9 +117,9 @@ export class CompareExpression< this.rhs = rhs; } - /** Returns the Expression's runtime value, based on the CLI's resolution of params. */ - value(): boolean { - const left = this.lhs.value(); + /** @internal */ + runtimeValue(): boolean { + const left = this.lhs.runtimeValue(); const right = valueOf(this.rhs); switch (this.cmp) { case "==": @@ -239,8 +255,8 @@ export abstract class Param exte super(); } - /** Returns the Expression's runtime value, based on the CLI's resolution of params. */ - value(): T { + /** @internal */ + runtimeValue(): T { throw new Error("Not implemented"); } @@ -321,8 +337,8 @@ export class SecretParam { this.name = name; } - /** Returns the Expression's runtime value, based on the latest version of the Secret in Cloud Secret Manager */ - value(): string { + /** @internal */ + runtimeValue(): string { return process.env[this.name] || ""; } @@ -340,7 +356,8 @@ export class SecretParam { * if present, or prompted for by the CLI if missing. */ export class StringParam extends Param { - value(): string { + /** @internal */ + runtimeValue(): string { return process.env[this.name] || ""; } } @@ -357,7 +374,8 @@ export class InternalExpression extends Param { super(name); } - value(): string { + /** @internal */ + runtimeValue(): string { return this.getter(process.env) || ""; } @@ -373,7 +391,8 @@ export class InternalExpression extends Param { export class IntParam extends Param { static type: ParamValueType = "int"; - value(): number { + /** @internal */ + runtimeValue(): number { return parseInt(process.env[this.name] || "0", 10) || 0; } } @@ -385,7 +404,8 @@ export class IntParam extends Param { export class FloatParam extends Param { static type: ParamValueType = "float"; - value(): number { + /** @internal */ + runtimeValue(): number { return parseFloat(process.env[this.name] || "0") || 0; } } @@ -397,8 +417,8 @@ export class FloatParam extends Param { export class BooleanParam extends Param { static type: ParamValueType = "boolean"; - /** Returns the Expression's runtime value, based on the CLI's resolution of params. */ - value(): boolean { + /** @internal */ + runtimeValue(): boolean { return !!process.env[this.name] && process.env[this.name] === "true"; } @@ -411,8 +431,8 @@ export class BooleanParam extends Param { export class ListParam extends Param { static type: ParamValueType = "list"; - /** Returns the Expression's runtime value, based on the CLI's resolution of params. */ - value(): string[] { + /** @internal */ + runtimeValue(): string[] { throw new Error("Not implemented"); }