Skip to content

Commit 5baa31f

Browse files
authored
fix(core): Incorrect arg type on Fn.eachMemberIn (#2958)
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
1 parent 697535d commit 5baa31f

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

Diff for: packages/@aws-cdk/cdk/lib/fn.ts

+10-8
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ export class Fn {
240240
* of strings.
241241
* @returns an FnCondition token
242242
*/
243-
public conditionEachMemberEquals(listOfStrings: string[], value: string): ICfnConditionExpression {
243+
public static conditionEachMemberEquals(listOfStrings: string[], value: string): ICfnConditionExpression {
244244
return new FnEachMemberEquals(listOfStrings, value);
245245
}
246246

@@ -255,7 +255,7 @@ export class Fn {
255255
* strings_to_check parameter.
256256
* @returns an FnCondition token
257257
*/
258-
public conditionEachMemberIn(stringsToCheck: string[], stringsToMatch: string): ICfnConditionExpression {
258+
public static conditionEachMemberIn(stringsToCheck: string[], stringsToMatch: string[]): ICfnConditionExpression {
259259
return new FnEachMemberIn(stringsToCheck, stringsToMatch);
260260
}
261261

@@ -266,7 +266,7 @@ export class Fn {
266266
* Parameters in the AWS CloudFormation User Guide.
267267
* @returns a token represented as a string array
268268
*/
269-
public refAll(parameterType: string): string[] {
269+
public static refAll(parameterType: string): string[] {
270270
return Token.asList(new FnRefAll(parameterType));
271271
}
272272

@@ -280,7 +280,7 @@ export class Fn {
280280
* value.
281281
* @returns a token represented as a string
282282
*/
283-
public valueOf(parameterOrLogicalId: string, attribute: string): string {
283+
public static valueOf(parameterOrLogicalId: string, attribute: string): string {
284284
return new FnValueOf(parameterOrLogicalId, attribute).toString();
285285
}
286286

@@ -294,9 +294,11 @@ export class Fn {
294294
* value. For more information about attributes, see Supported Attributes.
295295
* @returns a token represented as a string array
296296
*/
297-
public valueOfAll(parameterType: string, attribute: string): string[] {
297+
public static valueOfAll(parameterType: string, attribute: string): string[] {
298298
return Token.asList(new FnValueOfAll(parameterType, attribute));
299299
}
300+
301+
private constructor() { }
300302
}
301303

302304
/**
@@ -577,8 +579,8 @@ class FnEachMemberIn extends FnConditionBase {
577579
* @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.
578580
* @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.
579581
*/
580-
constructor(stringsToCheck: any, stringsToMatch: any) {
581-
super('Fn::EachMemberIn', [ [stringsToCheck], stringsToMatch ]);
582+
constructor(stringsToCheck: string[], stringsToMatch: string[]) {
583+
super('Fn::EachMemberIn', [stringsToCheck, stringsToMatch]);
582584
}
583585
}
584586

@@ -685,4 +687,4 @@ class FnJoin implements IResolvable {
685687
const resolvedValues = this.listOfValues.map(context.resolve);
686688
return this._resolvedValues = minimalCloudFormationJoin(this.delimiter, resolvedValues);
687689
}
688-
}
690+
}

Diff for: packages/@aws-cdk/cdk/test/test.fn.ts

+13
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,19 @@ export = nodeunit.testCase({
126126
{ verbose: true }
127127
);
128128
}),
129+
'Fn::EachMemberIn': asyncTest(async (test) => {
130+
const stack = new Stack();
131+
const eachMemberIn = Fn.conditionEachMemberIn(
132+
Fn.valueOfAll('AWS::EC2::Subnet::Id', 'VpcId'),
133+
Fn.refAll('AWS::EC2::VPC::Id')
134+
);
135+
test.deepEqual(stack.resolve(eachMemberIn), {
136+
'Fn::EachMemberIn': [
137+
{ 'Fn::ValueOfAll': ['AWS::EC2::Subnet::Id', 'VpcId'] },
138+
{ 'Fn::RefAll': 'AWS::EC2::VPC::Id'}
139+
]
140+
});
141+
}),
129142
},
130143
});
131144

0 commit comments

Comments
 (0)