From c9b914e23e770c4e9ee62454b66c427eec76bf93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=91=A8=F0=9F=8F=BC=E2=80=8D=F0=9F=92=BB=20Romain=20M?= =?UTF-8?q?arcadier-Muller?= Date: Thu, 20 Jun 2019 15:06:03 +0200 Subject: [PATCH] fix(core): Incorrect arg type on Fn.eachMemberIn Changed the type of the second argument to `Fn.eachMemberIn` to an array of `string`s, such that it can be used at all. BREAKING CHANGE: All instance methods of `Fn` were made `static`, and the `Fn` constructor was made private. Fixes #2950 --- packages/@aws-cdk/cdk/lib/fn.ts | 18 ++++++++++-------- packages/@aws-cdk/cdk/test/test.fn.ts | 13 +++++++++++++ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/packages/@aws-cdk/cdk/lib/fn.ts b/packages/@aws-cdk/cdk/lib/fn.ts index 41a03d589c5af..c67a143ba875f 100644 --- a/packages/@aws-cdk/cdk/lib/fn.ts +++ b/packages/@aws-cdk/cdk/lib/fn.ts @@ -240,7 +240,7 @@ export class Fn { * of strings. * @returns an FnCondition token */ - public conditionEachMemberEquals(listOfStrings: string[], value: string): ICfnConditionExpression { + public static conditionEachMemberEquals(listOfStrings: string[], value: string): ICfnConditionExpression { return new FnEachMemberEquals(listOfStrings, value); } @@ -255,7 +255,7 @@ export class Fn { * strings_to_check parameter. * @returns an FnCondition token */ - public conditionEachMemberIn(stringsToCheck: string[], stringsToMatch: string): ICfnConditionExpression { + public static conditionEachMemberIn(stringsToCheck: string[], stringsToMatch: string[]): ICfnConditionExpression { return new FnEachMemberIn(stringsToCheck, stringsToMatch); } @@ -266,7 +266,7 @@ export class Fn { * Parameters in the AWS CloudFormation User Guide. * @returns a token represented as a string array */ - public refAll(parameterType: string): string[] { + public static refAll(parameterType: string): string[] { return Token.asList(new FnRefAll(parameterType)); } @@ -280,7 +280,7 @@ export class Fn { * value. * @returns a token represented as a string */ - public valueOf(parameterOrLogicalId: string, attribute: string): string { + public static valueOf(parameterOrLogicalId: string, attribute: string): string { return new FnValueOf(parameterOrLogicalId, attribute).toString(); } @@ -294,9 +294,11 @@ export class Fn { * value. For more information about attributes, see Supported Attributes. * @returns a token represented as a string array */ - public valueOfAll(parameterType: string, attribute: string): string[] { + public static valueOfAll(parameterType: string, attribute: string): string[] { return Token.asList(new FnValueOfAll(parameterType, attribute)); } + + private constructor() { } } /** @@ -577,8 +579,8 @@ class FnEachMemberIn extends FnConditionBase { * @param stringsToCheck A list of strings, such as "A", "B", "C". AWS CloudFormation checks whether each member in the strings_to_check parameter is in the strings_to_match parameter. * @param stringsToMatch A list of strings, such as "A", "B", "C". Each member in the strings_to_match parameter is compared against the members of the strings_to_check parameter. */ - constructor(stringsToCheck: any, stringsToMatch: any) { - super('Fn::EachMemberIn', [ [stringsToCheck], stringsToMatch ]); + constructor(stringsToCheck: string[], stringsToMatch: string[]) { + super('Fn::EachMemberIn', [stringsToCheck, stringsToMatch]); } } @@ -685,4 +687,4 @@ class FnJoin implements IResolvable { const resolvedValues = this.listOfValues.map(context.resolve); return this._resolvedValues = minimalCloudFormationJoin(this.delimiter, resolvedValues); } -} \ No newline at end of file +} diff --git a/packages/@aws-cdk/cdk/test/test.fn.ts b/packages/@aws-cdk/cdk/test/test.fn.ts index bbec8b7acf8ef..3be13b3ad6ea5 100644 --- a/packages/@aws-cdk/cdk/test/test.fn.ts +++ b/packages/@aws-cdk/cdk/test/test.fn.ts @@ -126,6 +126,19 @@ export = nodeunit.testCase({ { verbose: true } ); }), + 'Fn::EachMemberIn': asyncTest(async (test) => { + const stack = new Stack(); + const eachMemberIn = Fn.conditionEachMemberIn( + Fn.valueOfAll('AWS::EC2::Subnet::Id', 'VpcId'), + Fn.refAll('AWS::EC2::VPC::Id') + ); + test.deepEqual(stack.resolve(eachMemberIn), { + 'Fn::EachMemberIn': [ + { 'Fn::ValueOfAll': ['AWS::EC2::Subnet::Id', 'VpcId'] }, + { 'Fn::RefAll': 'AWS::EC2::VPC::Id'} + ] + }); + }), }, });