/
pass.ts
171 lines (151 loc) · 3.96 KB
/
pass.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import { Construct } from 'constructs';
import { StateType } from './private/state-type';
import { renderJsonPath, State } from './state';
import { Chain } from '../chain';
import { FieldUtils } from '../fields';
import { IChainable, INextable } from '../types';
/**
* 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);
}
/**
*
* @param value result of the Pass operation
*/
protected constructor(public readonly value: any) {
}
}
/**
* Properties for defining a Pass state
*/
export interface PassProps {
/**
* Optional name for this state
*
* @default - The construct ID will be used as state name
*/
readonly stateName?: string;
/**
* An optional description for this state
*
* @default No comment
*/
readonly comment?: string;
/**
* JSONPath expression to select part of the state to be the input to this state.
*
* May also be the special value JsonPath.DISCARD, which will cause the effective
* input to be the empty object {}.
*
* @default $
*/
readonly inputPath?: string;
/**
* JSONPath expression to select part of the state to be the output to this state.
*
* May also be the special value JsonPath.DISCARD, which will cause the effective
* output to be the empty object {}.
*
* @default $
*/
readonly outputPath?: string;
/**
* JSONPath expression to indicate where to inject the state's output
*
* May also be the special value JsonPath.DISCARD, which will cause the state's
* input to become its output.
*
* @default $
*/
readonly resultPath?: string;
/**
* If given, treat as the result of this operation
*
* Can be used to inject or replace the current execution state.
*
* @default No injected result
*/
readonly result?: Result;
/**
* Parameters pass a collection of key-value pairs, either static values or JSONPath expressions that select from the input.
*
* @see
* https://docs.aws.amazon.com/step-functions/latest/dg/input-output-inputpath-params.html#input-output-parameters
*
* @default No parameters
*/
readonly parameters?: { [name: string]: any };
}
/**
* Define a Pass in the state machine
*
* A Pass state can be used to transform the current execution's state.
*/
export class Pass extends State implements INextable {
public readonly endStates: INextable[];
private readonly result?: Result;
constructor(scope: Construct, id: string, props: PassProps = {}) {
super(scope, id, props);
this.result = props.result;
this.endStates = [this];
}
/**
* Continue normal execution with the given state
*/
public next(next: IChainable): Chain {
super.makeNext(next.startState);
return Chain.sequence(this, next);
}
/**
* Return the Amazon States Language object for this state
*/
public toStateJson(): object {
return {
Type: StateType.PASS,
Comment: this.comment,
Result: this.result?.value,
ResultPath: renderJsonPath(this.resultPath),
...this.renderInputOutput(),
...this.renderParameters(),
...this.renderNextEnd(),
};
}
/**
* Render Parameters in ASL JSON format
*/
private renderParameters(): any {
return FieldUtils.renderObject({
Parameters: this.parameters,
});
}
}