diff --git a/CHANGELOG.md b/CHANGELOG.md index e69de29bb..0062ea300 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -0,0 +1 @@ +Correct the function BooleanExpression#then to BooleanExpression#thenElse (#1268) diff --git a/spec/fixtures/sources/commonjs-params/index.js b/spec/fixtures/sources/commonjs-params/index.js index 5f982fcaa..2418d32a9 100644 --- a/spec/fixtures/sources/commonjs-params/index.js +++ b/spec/fixtures/sources/commonjs-params/index.js @@ -4,10 +4,10 @@ const params = require("../../../../src/params"); params.defineString("BORING"); const foo = params.defineString("FOO", { input: { text: { validationRegex: "w+" } } }); -const bar = params.defineString("BAR", { default: foo , label: "asdf" }); +const bar = params.defineString("BAR", { default: foo, label: "asdf" }); params.defineString("BAZ", { input: { select: { options: [{ value: "a" }, { value: "b" }] } } }); -params.defineInt("AN_INT", { default: bar.equals("qux").then(0, 1) }); +params.defineInt("AN_INT", { default: bar.equals("qux").thenElse(0, 1) }); params.defineInt("ANOTHER_INT", { input: { select: { diff --git a/spec/params/params.spec.ts b/spec/params/params.spec.ts index 9148d5483..fad4f00b5 100644 --- a/spec/params/params.spec.ts +++ b/spec/params/params.spec.ts @@ -5,7 +5,7 @@ describe("Params spec extraction", () => { it("converts Expressions in the param default to strings", () => { const bar = params.defineInt("BAR"); expect( - params.defineString("FOO", { default: bar.notEquals(22).then("asdf", "jkl;") }).toSpec() + params.defineString("FOO", { default: bar.notEquals(22).thenElse("asdf", "jkl;") }).toSpec() .default ).to.equal(`{{ params.BAR != 22 ? "asdf" : "jkl;" }}`); }); @@ -174,13 +174,13 @@ describe("Params value extraction", () => { it("can select the output of a ternary expression based on the comparison", () => { const trueExpr = params.defineString("A_STRING").equals(params.defineString("SAME_STRING")); - expect(trueExpr.then(1, 0).value()).to.equal(1); + expect(trueExpr.thenElse(1, 0).value()).to.equal(1); const falseExpr = params.defineInt("AN_INT").equals(params.defineInt("DIFF_INT")); - expect(falseExpr.then(1, 0).value()).to.equal(0); + expect(falseExpr.thenElse(1, 0).value()).to.equal(0); const twentytwo = params.defineInt("DIFF_INT"); - expect(trueExpr.then(twentytwo, 0).value()).to.equal(22); - expect(falseExpr.then(1, twentytwo).value()).to.equal(22); + expect(trueExpr.thenElse(twentytwo, 0).value()).to.equal(22); + expect(falseExpr.thenElse(1, twentytwo).value()).to.equal(22); }); }); @@ -280,13 +280,15 @@ describe("Params as CEL", () => { expect( booleanExpr.then(params.defineString("FOO"), params.defineString("BAR")).toCEL() ).to.equal("{{ params.BOOL ? params.FOO : params.BAR }}"); - expect(cmpExpr.then("asdf", "jkl;").toCEL()).to.equal( + expect(cmpExpr.thenElse("asdf", "jkl;").toCEL()).to.equal( '{{ params.A != params.B ? "asdf" : "jkl;" }}' ); - expect(cmpExpr.then(-11, 22).toCEL()).to.equal("{{ params.A != params.B ? -11 : 22 }}"); - expect(cmpExpr.then(false, true).toCEL()).to.equal("{{ params.A != params.B ? false : true }}"); - expect(cmpExpr.then(params.defineString("FOO"), params.defineString("BAR")).toCEL()).to.equal( - "{{ params.A != params.B ? params.FOO : params.BAR }}" + expect(cmpExpr.thenElse(-11, 22).toCEL()).to.equal("{{ params.A != params.B ? -11 : 22 }}"); + expect(cmpExpr.thenElse(false, true).toCEL()).to.equal( + "{{ params.A != params.B ? false : true }}" ); + expect( + cmpExpr.thenElse(params.defineString("FOO"), params.defineString("BAR")).toCEL() + ).to.equal("{{ params.A != params.B ? params.FOO : params.BAR }}"); }); }); diff --git a/spec/runtime/manifest.spec.ts b/spec/runtime/manifest.spec.ts index e124f6190..22c5f8af1 100644 --- a/spec/runtime/manifest.spec.ts +++ b/spec/runtime/manifest.spec.ts @@ -127,14 +127,14 @@ describe("stackToWire", () => { labels: {}, httpsTrigger: {}, concurrency: intParam, - maxInstances: intParam.equals(24).then(-1, 1), + maxInstances: intParam.equals(24).thenElse(-1, 1), }, v2schedule: { platform: "gcfv2", entryPoint: "v2callable", labels: {}, scheduleTrigger: { - schedule: stringParam.equals("America/Mexico_City").then("mexico", "usa"), + schedule: stringParam.equals("America/Mexico_City").thenElse("mexico", "usa"), timeZone: stringParam, }, }, diff --git a/src/params/types.ts b/src/params/types.ts index fccdcbf86..7dd9b99bc 100644 --- a/src/params/types.ts +++ b/src/params/types.ts @@ -145,7 +145,7 @@ export class CompareExpression< } /** Returns a TernaryExpression which can resolve to one of two values, based on the resolution of this comparison. */ - then( + thenElse( ifTrue: retT | Expression, ifFalse: retT | Expression ) {