diff --git a/packages/@aws-cdk/aws-stepfunctions/lib/states/pass.ts b/packages/@aws-cdk/aws-stepfunctions/lib/states/pass.ts index c4f0c26684a09..6aafef9a10cdb 100644 --- a/packages/@aws-cdk/aws-stepfunctions/lib/states/pass.ts +++ b/packages/@aws-cdk/aws-stepfunctions/lib/states/pass.ts @@ -1,7 +1,77 @@ 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'; + +export abstract class Result { + public static fromString(value: string): StringResult { + return new StringResult(value); + } + + public static fromNumber(value: number): NumberResult { + return new NumberResult(value); + } + + public static fromBoolean(value: boolean): BooleanResult { + return new BooleanResult(value); + } + + public static fromMap(value: {[key: string]: any}): MapResult { + return new MapResult(value); + } + + public abstract value: any; +} + +export class StringResult extends Result { + public readonly value: string; + + constructor(value: string) { + super(); + + this.value = value; + } +} + +export class NumberResult extends Result { + public readonly value: number; + + constructor(value: number) { + super(); + + this.value = value; + } +} + +export class BooleanResult extends Result { + readonly value: boolean; + + constructor(value: boolean) { + super(); + + this.value = value; + } +} + +export class ArrayResult extends Result { + public readonly value: any[]; + + constructor(value: any[]) { + super(); + + this.value = value; + } +} + +export class MapResult extends Result { + public readonly value: {[key: string]: any}; + + constructor(value: {[key: string]: any}) { + super(); + + this.value = value; + } +} /** * Properties for defining a Pass state @@ -51,7 +121,7 @@ export interface PassProps { * * @default No injected result */ - readonly result?: {[key: string]: any} | string | number | boolean | null | any[]; + readonly result?: Result; } /** @@ -62,7 +132,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,7 +156,7 @@ 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(), 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..a294ed0eba572 --- /dev/null +++ b/packages/@aws-cdk/aws-stepfunctions/test/test.pass.ts @@ -0,0 +1,33 @@ +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(); + }, + 'fromMap has proper value'(test: Test) { + const testValue = {a: 1}; + const result = Result.fromMap(testValue); + test.deepEqual(result.value, testValue); + + test.done(); + }, +};