Skip to content

Commit

Permalink
fix(core): Incorrect arg type on Fn.eachMemberIn (#2958)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
RomainMuller authored Jun 20, 2019
1 parent 697535d commit 5baa31f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/@aws-cdk/cdk/lib/fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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));
}

Expand All @@ -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();
}

Expand All @@ -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() { }
}

/**
Expand Down Expand Up @@ -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]);
}
}

Expand Down Expand Up @@ -685,4 +687,4 @@ class FnJoin implements IResolvable {
const resolvedValues = this.listOfValues.map(context.resolve);
return this._resolvedValues = minimalCloudFormationJoin(this.delimiter, resolvedValues);
}
}
}
13 changes: 13 additions & 0 deletions packages/@aws-cdk/cdk/test/test.fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
]
});
}),
},
});

Expand Down

0 comments on commit 5baa31f

Please sign in to comment.