diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.ec2-task.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.ec2-task.ts index 0fc37744320d0..043a638a2cc95 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.ec2-task.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.ec2-task.ts @@ -33,7 +33,7 @@ taskDefinition.addContainer('TheContainer', { // Build state machine const definition = new sfn.Pass(stack, 'Start', { - result: { SomeKey: 'SomeValue' } + result: sfn.Result.fromObject({ SomeKey: 'SomeValue' }) }).next(new sfn.Task(stack, 'Run', { task: new tasks.RunEcsEc2Task({ cluster, taskDefinition, containerOverrides: [ diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.fargate-task.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.fargate-task.ts index 40de98378b283..575ac379b76ab 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.fargate-task.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.fargate-task.ts @@ -32,7 +32,7 @@ taskDefinition.addContainer('TheContainer', { // Build state machine const definition = new sfn.Pass(stack, 'Start', { - result: { SomeKey: 'SomeValue' } + result: sfn.Result.fromObject({ SomeKey: 'SomeValue' }) }).next(new sfn.Task(stack, 'FargateTask', { task: new tasks.RunEcsFargateTask({ cluster, taskDefinition, assignPublicIp: true, diff --git a/packages/@aws-cdk/aws-stepfunctions/lib/states/pass.ts b/packages/@aws-cdk/aws-stepfunctions/lib/states/pass.ts index 4bb97d4374f39..f8630562d5d5f 100644 --- a/packages/@aws-cdk/aws-stepfunctions/lib/states/pass.ts +++ b/packages/@aws-cdk/aws-stepfunctions/lib/states/pass.ts @@ -1,7 +1,50 @@ import cdk = require('@aws-cdk/cdk'); -import { Chain } from '../chain'; -import { IChainable, INextable } from '../types'; -import { renderJsonPath, State, StateType } from './state'; +import {Chain} from '../chain'; +import {IChainable, INextable} from '../types'; +import {renderJsonPath, State, StateType} from './state'; + +/** + * The result of a Pass operation + */ +export class Result { + /** + * The result of the operation is a string + */ + public static fromString(value: string): Result { + return new Result(value); + } + + /** + * The result of the operation is a number + */ + public static fromNumber(value: number): Result { + return new Result(value); + } + + /** + * The result of the operation is a boolean + */ + public static fromBoolean(value: boolean): Result { + return new Result(value); + } + + /** + * The result of the operation is an object + */ + public static fromObject(value: {[key: string]: any}): Result { + return new Result(value); + } + + /** + * The result of the operation is an array + */ + public static fromArray(value: any[]): Result { + return new Result(value); + } + + protected constructor(public readonly value: any) { + } +} /** * Properties for defining a Pass state @@ -51,7 +94,7 @@ export interface PassProps { * * @default No injected result */ - readonly result?: {[key: string]: any}; + readonly result?: Result; } /** @@ -62,7 +105,7 @@ export interface PassProps { export class Pass extends State implements INextable { public readonly endStates: INextable[]; - private readonly result?: any; + private readonly result?: Result; constructor(scope: cdk.Construct, id: string, props: PassProps = {}) { super(scope, id, props); @@ -86,10 +129,10 @@ export class Pass extends State implements INextable { return { Type: StateType.Pass, Comment: this.comment, - Result: this.result, + Result: this.result ? this.result.value : undefined, ResultPath: renderJsonPath(this.resultPath), ...this.renderInputOutput(), - ...this.renderNextEnd(), + ...this.renderNextEnd() }; } } diff --git a/packages/@aws-cdk/aws-stepfunctions/test/test.pass.ts b/packages/@aws-cdk/aws-stepfunctions/test/test.pass.ts new file mode 100644 index 0000000000000..3c1fc489627b2 --- /dev/null +++ b/packages/@aws-cdk/aws-stepfunctions/test/test.pass.ts @@ -0,0 +1,40 @@ +import { Test } from 'nodeunit'; +import { Result } from "../lib"; + +export = { + 'fromString has proper value'(test: Test) { + const testValue = 'test string'; + const result = Result.fromString(testValue); + test.equal(result.value, testValue); + + test.done(); + }, + 'fromNumber has proper value'(test: Test) { + const testValue = 1; + const result = Result.fromNumber(testValue); + test.equal(result.value, testValue); + + test.done(); + }, + 'fromBoolean has proper value'(test: Test) { + const testValue = false; + const result = Result.fromBoolean(testValue); + test.equal(result.value, testValue); + + test.done(); + }, + 'fromObject has proper value'(test: Test) { + const testValue = {a: 1}; + const result = Result.fromObject(testValue); + test.deepEqual(result.value, testValue); + + test.done(); + }, + 'fromArray has proper value'(test: Test) { + const testValue = [1]; + const result = Result.fromArray(testValue); + test.deepEqual(result.value, testValue); + + test.done(); + }, +};