Skip to content

Commit 5282a08

Browse files
Simon-Pierre Gingrasrix0rrr
authored andcommitted
fix(sfn): Pass support non-object Result types (#2811)
1 parent ad72271 commit 5282a08

File tree

4 files changed

+92
-9
lines changed

4 files changed

+92
-9
lines changed

packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.ec2-task.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ taskDefinition.addContainer('TheContainer', {
3333

3434
// Build state machine
3535
const definition = new sfn.Pass(stack, 'Start', {
36-
result: { SomeKey: 'SomeValue' }
36+
result: sfn.Result.fromObject({ SomeKey: 'SomeValue' })
3737
}).next(new sfn.Task(stack, 'Run', { task: new tasks.RunEcsEc2Task({
3838
cluster, taskDefinition,
3939
containerOverrides: [

packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.fargate-task.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ taskDefinition.addContainer('TheContainer', {
3232

3333
// Build state machine
3434
const definition = new sfn.Pass(stack, 'Start', {
35-
result: { SomeKey: 'SomeValue' }
35+
result: sfn.Result.fromObject({ SomeKey: 'SomeValue' })
3636
}).next(new sfn.Task(stack, 'FargateTask', { task: new tasks.RunEcsFargateTask({
3737
cluster, taskDefinition,
3838
assignPublicIp: true,

packages/@aws-cdk/aws-stepfunctions/lib/states/pass.ts

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,50 @@
11
import cdk = require('@aws-cdk/cdk');
2-
import { Chain } from '../chain';
3-
import { IChainable, INextable } from '../types';
4-
import { renderJsonPath, State, StateType } from './state';
2+
import {Chain} from '../chain';
3+
import {IChainable, INextable} from '../types';
4+
import {renderJsonPath, State, StateType} from './state';
5+
6+
/**
7+
* The result of a Pass operation
8+
*/
9+
export class Result {
10+
/**
11+
* The result of the operation is a string
12+
*/
13+
public static fromString(value: string): Result {
14+
return new Result(value);
15+
}
16+
17+
/**
18+
* The result of the operation is a number
19+
*/
20+
public static fromNumber(value: number): Result {
21+
return new Result(value);
22+
}
23+
24+
/**
25+
* The result of the operation is a boolean
26+
*/
27+
public static fromBoolean(value: boolean): Result {
28+
return new Result(value);
29+
}
30+
31+
/**
32+
* The result of the operation is an object
33+
*/
34+
public static fromObject(value: {[key: string]: any}): Result {
35+
return new Result(value);
36+
}
37+
38+
/**
39+
* The result of the operation is an array
40+
*/
41+
public static fromArray(value: any[]): Result {
42+
return new Result(value);
43+
}
44+
45+
protected constructor(public readonly value: any) {
46+
}
47+
}
548

649
/**
750
* Properties for defining a Pass state
@@ -51,7 +94,7 @@ export interface PassProps {
5194
*
5295
* @default No injected result
5396
*/
54-
readonly result?: {[key: string]: any};
97+
readonly result?: Result;
5598
}
5699

57100
/**
@@ -62,7 +105,7 @@ export interface PassProps {
62105
export class Pass extends State implements INextable {
63106
public readonly endStates: INextable[];
64107

65-
private readonly result?: any;
108+
private readonly result?: Result;
66109

67110
constructor(scope: cdk.Construct, id: string, props: PassProps = {}) {
68111
super(scope, id, props);
@@ -86,10 +129,10 @@ export class Pass extends State implements INextable {
86129
return {
87130
Type: StateType.Pass,
88131
Comment: this.comment,
89-
Result: this.result,
132+
Result: this.result ? this.result.value : undefined,
90133
ResultPath: renderJsonPath(this.resultPath),
91134
...this.renderInputOutput(),
92-
...this.renderNextEnd(),
135+
...this.renderNextEnd()
93136
};
94137
}
95138
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Test } from 'nodeunit';
2+
import { Result } from "../lib";
3+
4+
export = {
5+
'fromString has proper value'(test: Test) {
6+
const testValue = 'test string';
7+
const result = Result.fromString(testValue);
8+
test.equal(result.value, testValue);
9+
10+
test.done();
11+
},
12+
'fromNumber has proper value'(test: Test) {
13+
const testValue = 1;
14+
const result = Result.fromNumber(testValue);
15+
test.equal(result.value, testValue);
16+
17+
test.done();
18+
},
19+
'fromBoolean has proper value'(test: Test) {
20+
const testValue = false;
21+
const result = Result.fromBoolean(testValue);
22+
test.equal(result.value, testValue);
23+
24+
test.done();
25+
},
26+
'fromObject has proper value'(test: Test) {
27+
const testValue = {a: 1};
28+
const result = Result.fromObject(testValue);
29+
test.deepEqual(result.value, testValue);
30+
31+
test.done();
32+
},
33+
'fromArray has proper value'(test: Test) {
34+
const testValue = [1];
35+
const result = Result.fromArray(testValue);
36+
test.deepEqual(result.value, testValue);
37+
38+
test.done();
39+
},
40+
};

0 commit comments

Comments
 (0)