aws-local-stepfunctions 0.3.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/main.d.ts CHANGED
@@ -1,11 +1,21 @@
1
- declare type StateType = 'Task' | 'Map' | 'Pass' | 'Wait' | 'Choice' | 'Succeed' | 'Fail';
1
+ import { FromCognitoIdentityPoolParameters } from '@aws-sdk/credential-provider-cognito-identity/dist-types/fromCognitoIdentityPool';
2
+ import { Credentials } from '@aws-sdk/types/dist-types/credentials';
3
+
4
+ type StateType = 'Task' | 'Parallel' | 'Map' | 'Pass' | 'Wait' | 'Choice' | 'Succeed' | 'Fail';
2
5
 
3
6
  interface BaseState {
4
7
  Type: StateType;
5
8
  Comment?: string;
6
9
  }
7
10
 
8
- declare type PayloadTemplate = object;
11
+ type JSONPrimitiveValue = null | boolean | number | string;
12
+ type JSONArray = (JSONPrimitiveValue | JSONArray | JSONObject)[];
13
+ type JSONObject = {
14
+ [key: string]: JSONPrimitiveValue | JSONObject | JSONArray;
15
+ };
16
+ type JSONValue = JSONPrimitiveValue | JSONObject | JSONArray;
17
+
18
+ type PayloadTemplate = JSONObject;
9
19
  interface CanHaveInputPath {
10
20
  InputPath?: string | null;
11
21
  }
@@ -22,54 +32,54 @@ interface CanHaveOutputPath {
22
32
  OutputPath?: string | null;
23
33
  }
24
34
 
25
- declare type StringOperatorNames = 'StringEquals' | 'StringLessThan' | 'StringGreaterThan' | 'StringLessThanEquals' | 'StringGreaterThanEquals' | 'StringMatches';
26
- declare type StringPathOperatorNames = 'StringEqualsPath' | 'StringLessThanPath' | 'StringGreaterThanPath' | 'StringLessThanEqualsPath' | 'StringGreaterThanEqualsPath';
27
- declare type NumericOperatorNames = 'NumericEquals' | 'NumericLessThan' | 'NumericGreaterThan' | 'NumericLessThanEquals' | 'NumericGreaterThanEquals';
28
- declare type NumericPathOperatorNames = 'NumericEqualsPath' | 'NumericLessThanPath' | 'NumericGreaterThanPath' | 'NumericLessThanEqualsPath' | 'NumericGreaterThanEqualsPath';
29
- declare type BooleanOperatorNames = 'BooleanEquals';
30
- declare type BooleanPathOperatorNames = 'BooleanEqualsPath';
31
- declare type TimestampOperatorNames = 'TimestampEquals' | 'TimestampLessThan' | 'TimestampGreaterThan' | 'TimestampLessThanEquals' | 'TimestampGreaterThanEquals';
32
- declare type TimestampPathOperatorNames = 'TimestampEqualsPath' | 'TimestampLessThanPath' | 'TimestampGreaterThanPath' | 'TimestampLessThanEqualsPath' | 'TimestampGreaterThanEqualsPath';
33
- declare type TypeTestOperatorNames = 'IsNull' | 'IsPresent' | 'IsNumeric' | 'IsString' | 'IsBoolean' | 'IsTimestamp';
34
- declare type StringComparisonOperator = {
35
+ type StringOperatorNames = 'StringEquals' | 'StringLessThan' | 'StringGreaterThan' | 'StringLessThanEquals' | 'StringGreaterThanEquals' | 'StringMatches';
36
+ type StringPathOperatorNames = 'StringEqualsPath' | 'StringLessThanPath' | 'StringGreaterThanPath' | 'StringLessThanEqualsPath' | 'StringGreaterThanEqualsPath';
37
+ type NumericOperatorNames = 'NumericEquals' | 'NumericLessThan' | 'NumericGreaterThan' | 'NumericLessThanEquals' | 'NumericGreaterThanEquals';
38
+ type NumericPathOperatorNames = 'NumericEqualsPath' | 'NumericLessThanPath' | 'NumericGreaterThanPath' | 'NumericLessThanEqualsPath' | 'NumericGreaterThanEqualsPath';
39
+ type BooleanOperatorNames = 'BooleanEquals';
40
+ type BooleanPathOperatorNames = 'BooleanEqualsPath';
41
+ type TimestampOperatorNames = 'TimestampEquals' | 'TimestampLessThan' | 'TimestampGreaterThan' | 'TimestampLessThanEquals' | 'TimestampGreaterThanEquals';
42
+ type TimestampPathOperatorNames = 'TimestampEqualsPath' | 'TimestampLessThanPath' | 'TimestampGreaterThanPath' | 'TimestampLessThanEqualsPath' | 'TimestampGreaterThanEqualsPath';
43
+ type TypeTestOperatorNames = 'IsNull' | 'IsPresent' | 'IsNumeric' | 'IsString' | 'IsBoolean' | 'IsTimestamp';
44
+ type StringComparisonOperator = {
35
45
  [P in StringOperatorNames]?: string;
36
46
  };
37
- declare type StringPathComparisonOperator = {
47
+ type StringPathComparisonOperator = {
38
48
  [P in StringPathOperatorNames]?: string;
39
49
  };
40
- declare type NumericComparisonOperator = {
50
+ type NumericComparisonOperator = {
41
51
  [P in NumericOperatorNames]?: number;
42
52
  };
43
- declare type NumericPathComparisonOperator = {
53
+ type NumericPathComparisonOperator = {
44
54
  [P in NumericPathOperatorNames]?: string;
45
55
  };
46
- declare type BooleanComparisonOperator = {
56
+ type BooleanComparisonOperator = {
47
57
  [P in BooleanOperatorNames]?: boolean;
48
58
  };
49
- declare type BooleanPathComparisonOperator = {
59
+ type BooleanPathComparisonOperator = {
50
60
  [P in BooleanPathOperatorNames]?: string;
51
61
  };
52
- declare type TimestampComparisonOperator = {
62
+ type TimestampComparisonOperator = {
53
63
  [P in TimestampOperatorNames]?: string;
54
64
  };
55
- declare type TimestampPathComparisonOperator = {
65
+ type TimestampPathComparisonOperator = {
56
66
  [P in TimestampPathOperatorNames]?: string;
57
67
  };
58
- declare type TypeTestComparisonOperator = {
68
+ type TypeTestComparisonOperator = {
59
69
  [P in TypeTestOperatorNames]?: true;
60
70
  };
61
- declare type ComparisonOperator = StringComparisonOperator | StringPathComparisonOperator | NumericComparisonOperator | NumericPathComparisonOperator | BooleanComparisonOperator | BooleanPathComparisonOperator | TimestampComparisonOperator | TimestampPathComparisonOperator | TypeTestComparisonOperator;
62
- declare type BaseDataTestExpression = {
71
+ type ComparisonOperator = StringComparisonOperator | StringPathComparisonOperator | NumericComparisonOperator | NumericPathComparisonOperator | BooleanComparisonOperator | BooleanPathComparisonOperator | TimestampComparisonOperator | TimestampPathComparisonOperator | TypeTestComparisonOperator;
72
+ type BaseDataTestExpression = {
63
73
  Variable: string;
64
74
  };
65
- declare type DataTestExpression = BaseDataTestExpression & ComparisonOperator;
66
- declare type BooleanExpression = {
75
+ type DataTestExpression = BaseDataTestExpression & ComparisonOperator;
76
+ type BooleanExpression = {
67
77
  And?: ChoiceRuleWithoutNext[];
68
78
  Or?: ChoiceRuleWithoutNext[];
69
79
  Not?: ChoiceRuleWithoutNext;
70
80
  };
71
- declare type ChoiceRuleWithoutNext = DataTestExpression | BooleanExpression;
72
- declare type ChoiceRule = (DataTestExpression | BooleanExpression) & {
81
+ type ChoiceRuleWithoutNext = DataTestExpression | BooleanExpression;
82
+ type ChoiceRule = (DataTestExpression | BooleanExpression) & {
73
83
  Next: string;
74
84
  };
75
85
  interface BaseChoiceState extends BaseState, CanHaveInputPath, CanHaveOutputPath {
@@ -77,7 +87,7 @@ interface BaseChoiceState extends BaseState, CanHaveInputPath, CanHaveOutputPath
77
87
  Choices: ChoiceRule[];
78
88
  Default?: string;
79
89
  }
80
- declare type ChoiceState = BaseChoiceState;
90
+ type ChoiceState = BaseChoiceState;
81
91
 
82
92
  interface EndableState extends BaseState {
83
93
  Type: Exclude<StateType, 'Choice' | 'Succeed' | 'Fail'>;
@@ -86,47 +96,69 @@ interface EndableState extends BaseState {
86
96
  interface SucceedOrFailState extends BaseState {
87
97
  Type: Extract<StateType, 'Succeed' | 'Fail'>;
88
98
  }
89
- declare type TerminalState = EndableState | SucceedOrFailState;
99
+ type TerminalState = EndableState | SucceedOrFailState;
90
100
 
91
101
  interface BaseFailState extends BaseState {
92
102
  Type: 'Fail';
93
103
  Cause?: string;
94
104
  Error?: string;
95
105
  }
96
- declare type FailState = TerminalState & BaseFailState;
106
+ type FailState = TerminalState & BaseFailState;
107
+
108
+ type Retrier = {
109
+ ErrorEquals: string[];
110
+ IntervalSeconds?: number;
111
+ MaxAttempts?: number;
112
+ BackoffRate?: number;
113
+ };
114
+ interface RetryableState {
115
+ Retry?: Retrier[];
116
+ }
117
+ type Catcher = {
118
+ ErrorEquals: string[];
119
+ Next: string;
120
+ ResultPath?: string;
121
+ };
122
+ interface CatchableState {
123
+ Catch?: Catcher[];
124
+ }
97
125
 
98
126
  interface NextableState extends BaseState {
99
127
  Type: Exclude<StateType, 'Choice' | 'Succeed' | 'Fail'>;
100
128
  Next: string;
101
129
  }
102
- declare type IntermediateState = NextableState;
130
+ type IntermediateState = NextableState;
103
131
 
104
- interface BaseMapState extends BaseState, CanHaveInputPath, CanHaveParameters, CanHaveResultSelector, CanHaveResultPath, CanHaveOutputPath {
132
+ interface BaseMapState extends BaseState, CanHaveInputPath, CanHaveParameters, CanHaveResultSelector, CanHaveResultPath, CanHaveOutputPath, RetryableState, CatchableState {
105
133
  Type: 'Map';
106
134
  Iterator: Omit<StateMachineDefinition, 'Version' | 'TimeoutSeconds'>;
107
135
  ItemsPath?: string;
108
136
  MaxConcurrency?: number;
109
137
  }
110
- declare type MapState = (IntermediateState | TerminalState) & BaseMapState;
138
+ type MapState = (IntermediateState | TerminalState) & BaseMapState;
111
139
 
112
- declare type JSONValue = null | boolean | number | string | object | JSONValue[];
140
+ interface BaseParallelState extends BaseState, CanHaveInputPath, CanHaveParameters, CanHaveResultSelector, CanHaveResultPath, CanHaveOutputPath, RetryableState, CatchableState {
141
+ Type: 'Parallel';
142
+ Branches: Omit<StateMachineDefinition, 'Version' | 'TimeoutSeconds'>[];
143
+ }
144
+ type ParallelState = (IntermediateState | TerminalState) & BaseParallelState;
113
145
 
114
146
  interface BasePassState extends BaseState, CanHaveInputPath, CanHaveParameters, CanHaveResultPath, CanHaveOutputPath {
115
147
  Type: 'Pass';
116
148
  Result?: JSONValue;
117
149
  }
118
- declare type PassState = (IntermediateState | TerminalState) & BasePassState;
150
+ type PassState = (IntermediateState | TerminalState) & BasePassState;
119
151
 
120
152
  interface BaseSucceedState extends BaseState, CanHaveInputPath, CanHaveOutputPath {
121
153
  Type: 'Succeed';
122
154
  }
123
- declare type SucceedState = TerminalState & BaseSucceedState;
155
+ type SucceedState = TerminalState & BaseSucceedState;
124
156
 
125
- interface BaseTaskState extends BaseState, CanHaveInputPath, CanHaveParameters, CanHaveResultSelector, CanHaveResultPath, CanHaveOutputPath {
157
+ interface BaseTaskState extends BaseState, CanHaveInputPath, CanHaveParameters, CanHaveResultSelector, CanHaveResultPath, CanHaveOutputPath, RetryableState, CatchableState {
126
158
  Type: 'Task';
127
159
  Resource: string;
128
160
  }
129
- declare type TaskState = (IntermediateState | TerminalState) & BaseTaskState;
161
+ type TaskState = (IntermediateState | TerminalState) & BaseTaskState;
130
162
 
131
163
  interface BaseWaitState extends BaseState, CanHaveInputPath, CanHaveOutputPath {
132
164
  Type: 'Wait';
@@ -135,9 +167,9 @@ interface BaseWaitState extends BaseState, CanHaveInputPath, CanHaveOutputPath {
135
167
  SecondsPath?: string;
136
168
  TimestampPath?: string;
137
169
  }
138
- declare type WaitState = (IntermediateState | TerminalState) & BaseWaitState;
170
+ type WaitState = (IntermediateState | TerminalState) & BaseWaitState;
139
171
 
140
- declare type AllStates = TaskState | MapState | PassState | WaitState | ChoiceState | SucceedState | FailState;
172
+ type AllStates = TaskState | ParallelState | MapState | PassState | WaitState | ChoiceState | SucceedState | FailState;
141
173
 
142
174
  interface StateMachineDefinition {
143
175
  States: Record<string, AllStates>;
@@ -147,10 +179,10 @@ interface StateMachineDefinition {
147
179
  TimeoutSeconds?: number;
148
180
  }
149
181
 
150
- declare type TaskStateResourceLocalHandler = {
182
+ type TaskStateResourceLocalHandler = {
151
183
  [taskStateName: string]: (input: JSONValue) => Promise<JSONValue>;
152
184
  };
153
- declare type WaitStateTimeOverride = {
185
+ type WaitStateTimeOverride = {
154
186
  [waitStateName: string]: number;
155
187
  };
156
188
  interface Overrides {
@@ -161,6 +193,17 @@ interface ValidationOptions {
161
193
  readonly checkPaths?: boolean;
162
194
  readonly checkArn?: boolean;
163
195
  }
196
+ interface AWSConfig {
197
+ region: string;
198
+ credentials?: {
199
+ cognitoIdentityPool?: FromCognitoIdentityPoolParameters;
200
+ accessKeys?: Omit<Credentials, 'expiration'>;
201
+ };
202
+ }
203
+ interface StateMachineOptions {
204
+ validationOptions?: ValidationOptions;
205
+ awsConfig?: AWSConfig;
206
+ }
164
207
  interface RunOptions {
165
208
  overrides?: Overrides;
166
209
  noThrowOnAbort?: boolean;
@@ -172,22 +215,20 @@ declare class StateMachine {
172
215
  */
173
216
  private readonly definition;
174
217
  /**
175
- * A map of functions to execute each type of state.
176
- */
177
- private readonly stateExecutors;
178
- /**
179
- * Options to control whether to apply certain validations to the state machine definition.
218
+ * Options to control certain settings of the state machine.
180
219
  */
181
- private readonly validationOptions;
220
+ private readonly stateMachineOptions;
182
221
  /**
183
222
  * Constructs a new state machine.
184
223
  * @param definition The state machine definition defined using the Amazon States Language (https://states-language.net/spec.html).
185
- * @param validationOptions Options to control whether to apply certain validations to the definition.
186
- * These options also apply to state machines defined in the `Iterator` field of `Map` states.
224
+ * @param stateMachineOptions Options to control certain settings of the state machine.
225
+ * These options also apply to state machines defined in the `Iterator` field of `Map` states and in the `Branches` field of `Parallel` states.
187
226
  */
188
- constructor(definition: StateMachineDefinition, validationOptions?: ValidationOptions);
227
+ constructor(definition: StateMachineDefinition, stateMachineOptions?: StateMachineOptions);
189
228
  /**
190
229
  * Executes the state machine, running through the states specified in the definition.
230
+ * If the execution fails, the result will throw an `ExecutionError` explaining why the
231
+ * execution failed.
191
232
  *
192
233
  * By default, if the execution is aborted, the result will throw an `ExecutionAbortedError`. This behavior can be changed by setting
193
234
  * the `noThrowOnAbort` option to `true`, in which case the result will be `null`.
@@ -203,83 +244,22 @@ declare class StateMachine {
203
244
  * Helper method that handles the execution of the machine states and the transitions between them.
204
245
  */
205
246
  private execute;
206
- /**
207
- * Process the current input according to the `InputPath` and `Parameters` fields.
208
- */
209
- private processInput;
210
- /**
211
- * Process the current result according to the `ResultSelector`, `ResultPath` and `OutputPath` fields.
212
- */
213
- private processResult;
214
- /**
215
- * Handler for task states.
216
- *
217
- * Invokes the Lambda function specified in the `Resource` field
218
- * and sets the current result of the state machine to the value returned by the Lambda.
219
- */
220
- private executeTaskState;
221
- /**
222
- * Handler for map states.
223
- *
224
- * Iterates over the current input items or the items of an array specified
225
- * by the `ItemsPath` field, and then processes each item by passing it
226
- * as the input to the state machine specified in the `Iterator` field.
227
- */
228
- private executeMapState;
229
- /**
230
- * Handler for pass states.
231
- *
232
- * If the `Result` field is specified, copies `Result` into the current result.
233
- * Else, copies the current input into the current result.
234
- */
235
- private executePassState;
236
- /**
237
- * Handler for wait states.
238
- *
239
- * Pauses the state machine execution for a certain amount of time
240
- * based on one of the `Seconds`, `Timestamp`, `SecondsPath` or `TimestampPath` fields.
241
- */
242
- private executeWaitState;
243
- /**
244
- * Handler for choice states.
245
- *
246
- * Evaluates each choice rule specified in the `Choices` field.
247
- *
248
- * If one of the rules matches, then the state machine transitions to the
249
- * state specified in the `Next` field for that choice rule.
250
- *
251
- * If no rule matches but the `Default` field is specified,
252
- * then the next state will be the state specified in said field.
253
- *
254
- * If no rule matches and the `Default` field is not specified, throws a
255
- * States.NoChoiceMatched error.
256
- */
257
- private executeChoiceState;
258
- /**
259
- * Handler for succeed states.
260
- *
261
- * Ends the state machine execution successfully.
262
- */
263
- private executeSucceedState;
264
- /**
265
- * Handler for fail states.
266
- *
267
- * Ends the state machine execution and marks it as a failure.
268
- */
269
- private executeFailState;
270
247
  }
271
248
 
272
- declare abstract class CustomError extends Error {
273
- constructor(message?: string);
274
- abstract toString(): string;
249
+ /**
250
+ * Represents the failure of a state machine execution.
251
+ */
252
+ declare class ExecutionError extends Error {
253
+ #private;
254
+ constructor(caughtError: Error);
255
+ get getWrappedError(): Error;
275
256
  }
276
257
 
277
258
  /**
278
259
  * Represents the abortion of a state machine execution.
279
260
  */
280
- declare class ExecutionAbortedError extends CustomError {
261
+ declare class ExecutionAbortedError extends Error {
281
262
  constructor();
282
- toString(): string;
283
263
  }
284
264
 
285
- export { ExecutionAbortedError, StateMachine };
265
+ export { ExecutionAbortedError, ExecutionError, StateMachine };