@lafken/state-machine 0.10.1
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/LICENCE +21 -0
- package/README.md +383 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +18 -0
- package/lib/main/index.d.ts +2 -0
- package/lib/main/index.js +18 -0
- package/lib/main/param/index.d.ts +2 -0
- package/lib/main/param/index.js +18 -0
- package/lib/main/param/param.d.ts +105 -0
- package/lib/main/param/param.js +115 -0
- package/lib/main/param/param.types.d.ts +77 -0
- package/lib/main/param/param.types.js +2 -0
- package/lib/main/state-machine/index.d.ts +2 -0
- package/lib/main/state-machine/index.js +18 -0
- package/lib/main/state-machine/state-machine.d.ts +113 -0
- package/lib/main/state-machine/state-machine.js +133 -0
- package/lib/main/state-machine/state-machine.types.d.ts +977 -0
- package/lib/main/state-machine/state-machine.types.js +7 -0
- package/lib/resolver/index.d.ts +1 -0
- package/lib/resolver/index.js +17 -0
- package/lib/resolver/resolver.d.ts +6 -0
- package/lib/resolver/resolver.js +28 -0
- package/lib/resolver/state-machine/schema/schema.d.ts +34 -0
- package/lib/resolver/state-machine/schema/schema.js +431 -0
- package/lib/resolver/state-machine/schema/schema.types.d.ts +149 -0
- package/lib/resolver/state-machine/schema/schema.types.js +2 -0
- package/lib/resolver/state-machine/schema/schema.utils.d.ts +15 -0
- package/lib/resolver/state-machine/schema/schema.utils.js +53 -0
- package/lib/resolver/state-machine/state-machine.d.ts +19 -0
- package/lib/resolver/state-machine/state-machine.js +96 -0
- package/lib/resolver/state-machine/state-machine.types.d.ts +7 -0
- package/lib/resolver/state-machine/state-machine.types.js +2 -0
- package/package.json +87 -0
|
@@ -0,0 +1,977 @@
|
|
|
1
|
+
import type { BucketNames, ClassResource, LambdaMetadata, LambdaProps, ResourceMetadata, ResourceOutputType, ResourceProps, ServicesValues, StateMachineNames } from '@lafken/common';
|
|
2
|
+
import type { JsonAtaString } from '../param';
|
|
3
|
+
export declare enum StateMachineReflectKeys {
|
|
4
|
+
nested = "state_machine:nested"
|
|
5
|
+
}
|
|
6
|
+
export type DefaultMethod = (...args: any) => any;
|
|
7
|
+
export type ProcessorExecutionType = 'STANDARD' | 'EXPRESS';
|
|
8
|
+
export type ProcessorMode = 'INLINE' | 'DISTRIBUTED';
|
|
9
|
+
export type CsvDelimiter = 'COMMA' | 'PIPE' | 'SEMICOLON' | 'SPACE' | 'TAB';
|
|
10
|
+
export type HeaderLocation = 'FIRST_ROW' | 'GIVEN';
|
|
11
|
+
export type ResultOutputType = 'JSON' | 'JSONL';
|
|
12
|
+
export type ResultTransformation = 'NONE' | 'COMPACT' | 'FLATTEN';
|
|
13
|
+
export type IntegrationMode = 'sync' | 'async' | 'token';
|
|
14
|
+
type ObjectOrJsonAta = Record<string, any> | JsonAtaString;
|
|
15
|
+
/**
|
|
16
|
+
* Attributes that can be exported from a Step Functions state machine resource.
|
|
17
|
+
*
|
|
18
|
+
* Based on Terraform `aws_sfn_state_machine` attribute reference:
|
|
19
|
+
* - `arn`: The ARN of the state machine.
|
|
20
|
+
* - `id`: The ARN of the state machine.
|
|
21
|
+
* - `stateMachineVersionArn`: The ARN of the state machine version.
|
|
22
|
+
*/
|
|
23
|
+
export type StateMachineOutputAttributes = 'id' | 'arn' | 'stateMachineVersionArn';
|
|
24
|
+
export interface StateMachineBaseProps<T> {
|
|
25
|
+
/**
|
|
26
|
+
* Initial state of the state machine.
|
|
27
|
+
*
|
|
28
|
+
* Specifies which task or state the state machine should start executing first.
|
|
29
|
+
* This defines the entry point of the workflow.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* {
|
|
33
|
+
* startAt: 'lambda_name',
|
|
34
|
+
* }
|
|
35
|
+
* @example
|
|
36
|
+
* {
|
|
37
|
+
* startAt: {
|
|
38
|
+
* type: 'wait',
|
|
39
|
+
* seconds: 3,
|
|
40
|
+
* next: {
|
|
41
|
+
* type: 'succeed'
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
44
|
+
* }
|
|
45
|
+
*/
|
|
46
|
+
startAt: InitialStateType<T>;
|
|
47
|
+
/**
|
|
48
|
+
* Resource minify
|
|
49
|
+
*
|
|
50
|
+
* Specifies whether the code should be minified when the resource is processed
|
|
51
|
+
*
|
|
52
|
+
* @default true
|
|
53
|
+
*/
|
|
54
|
+
minify?: boolean;
|
|
55
|
+
}
|
|
56
|
+
interface StateMachineProps<T> extends StateMachineBaseProps<T> {
|
|
57
|
+
/**
|
|
58
|
+
* Execution type of the state machine.
|
|
59
|
+
*
|
|
60
|
+
* Specifies whether the state machine should be created as a standard
|
|
61
|
+
* or express state machine.
|
|
62
|
+
*/
|
|
63
|
+
executionType?: ProcessorExecutionType;
|
|
64
|
+
/**
|
|
65
|
+
* State machine services.
|
|
66
|
+
*
|
|
67
|
+
* Defines which AWS services the state machine is allowed to access.
|
|
68
|
+
* Internally, a role is created with the specified service permissions,
|
|
69
|
+
* granting the state machine the ability to interact with those resources.
|
|
70
|
+
*
|
|
71
|
+
* These permissions are merged with the base permissions automatically
|
|
72
|
+
* granted to the state machine (e.g., `cloudwatch`, `lambda`).
|
|
73
|
+
*
|
|
74
|
+
* Can be provided as:
|
|
75
|
+
* - A static array of service names or permission objects.
|
|
76
|
+
* - A callback function that receives `getResourceValue` and `getSSMValue`
|
|
77
|
+
* helpers, allowing dynamic resolution of cross-resource references.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* {
|
|
81
|
+
* services: ['sqs', 'dynamodb']
|
|
82
|
+
* }
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* {
|
|
86
|
+
* services: ({ getResourceValue }) => [
|
|
87
|
+
* {
|
|
88
|
+
* type: 'sqs',
|
|
89
|
+
* permissions: ['GetQueueUrl', 'ReceiveMessage'],
|
|
90
|
+
* resources: [getResourceValue('queue::test', 'id')],
|
|
91
|
+
* },
|
|
92
|
+
* ]
|
|
93
|
+
* }
|
|
94
|
+
*/
|
|
95
|
+
services?: ServicesValues;
|
|
96
|
+
/**
|
|
97
|
+
* Logging configuration for the state machine.
|
|
98
|
+
*
|
|
99
|
+
* Enables CloudWatch Logs for the state machine execution,
|
|
100
|
+
* allowing you to monitor and debug workflow runs.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* {
|
|
104
|
+
* loggingConfiguration: {
|
|
105
|
+
* logGroupName: '/aws/states/my-state-machine',
|
|
106
|
+
* level: 'all',
|
|
107
|
+
* includeExecutionData: true,
|
|
108
|
+
* retentionInDays: 30,
|
|
109
|
+
* }
|
|
110
|
+
* }
|
|
111
|
+
*/
|
|
112
|
+
loggingConfiguration?: {
|
|
113
|
+
/**
|
|
114
|
+
* CloudWatch Log Group name.
|
|
115
|
+
*
|
|
116
|
+
* Defines the name of the CloudWatch Log Group where the
|
|
117
|
+
* state machine execution logs will be sent.
|
|
118
|
+
*
|
|
119
|
+
* @example '/aws/states/my-state-machine'
|
|
120
|
+
*/
|
|
121
|
+
logGroupName: string;
|
|
122
|
+
/**
|
|
123
|
+
* Log level.
|
|
124
|
+
*
|
|
125
|
+
* Controls the verbosity of execution logs sent to CloudWatch.
|
|
126
|
+
* - `'all'`: Logs all execution events.
|
|
127
|
+
* - `'error'`: Logs only error events.
|
|
128
|
+
* - `'fatal'`: Logs only fatal events.
|
|
129
|
+
* - `'off'`: Disables logging.
|
|
130
|
+
*
|
|
131
|
+
* @default 'off'
|
|
132
|
+
*/
|
|
133
|
+
level?: 'all' | 'error' | 'fatal' | 'off';
|
|
134
|
+
/**
|
|
135
|
+
* Include execution data.
|
|
136
|
+
*
|
|
137
|
+
* When enabled, the input and output data of each state
|
|
138
|
+
* is included in the execution logs.
|
|
139
|
+
*
|
|
140
|
+
* @default false
|
|
141
|
+
*/
|
|
142
|
+
includeExecutionData?: boolean;
|
|
143
|
+
/**
|
|
144
|
+
* Log retention period in days.
|
|
145
|
+
*
|
|
146
|
+
* Specifies the number of days to retain the execution logs
|
|
147
|
+
* in the CloudWatch Log Group before they are automatically deleted.
|
|
148
|
+
*/
|
|
149
|
+
retentionInDays?: number;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Enable AWS X-Ray tracing.
|
|
153
|
+
*
|
|
154
|
+
* When enabled, AWS X-Ray tracing is activated for the state machine,
|
|
155
|
+
* allowing you to trace and analyze execution requests across
|
|
156
|
+
* the services invoked during the workflow.
|
|
157
|
+
*
|
|
158
|
+
* @default false
|
|
159
|
+
*/
|
|
160
|
+
enableTrace?: boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Defines which Step Functions state machine attributes should be exported.
|
|
163
|
+
*
|
|
164
|
+
* Supported attributes are based on Terraform `aws_sfn_state_machine`
|
|
165
|
+
* attribute reference:
|
|
166
|
+
* - `arn`: The ARN of the state machine.
|
|
167
|
+
* - `id`: The ARN of the state machine.
|
|
168
|
+
* - `stateMachineVersionArn`: The ARN of the state machine version.
|
|
169
|
+
*
|
|
170
|
+
* Each selected attribute can be exported through SSM Parameter Store (`type: 'ssm'`)
|
|
171
|
+
* or Terraform outputs (`type: 'output'`).
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* {
|
|
175
|
+
* outputs: [
|
|
176
|
+
* { type: 'ssm', name: '/my-app/state-machine-arn', value: 'arn' },
|
|
177
|
+
* { type: 'output', name: 'state_machine_version_arn', value: 'stateMachineVersionArn' }
|
|
178
|
+
* ]
|
|
179
|
+
* }
|
|
180
|
+
*/
|
|
181
|
+
outputs?: ResourceOutputType<StateMachineOutputAttributes>;
|
|
182
|
+
}
|
|
183
|
+
interface WaitStateBase<T> {
|
|
184
|
+
/**
|
|
185
|
+
* State type: Wait.
|
|
186
|
+
*
|
|
187
|
+
* Specifies that this state is a `Wait` state, which pauses the execution
|
|
188
|
+
* of the state machine for a defined duration before moving to the next state.
|
|
189
|
+
*/
|
|
190
|
+
type: 'wait';
|
|
191
|
+
/**
|
|
192
|
+
* Next state to execute.
|
|
193
|
+
*
|
|
194
|
+
* Specifies the next task or state that the state machine should
|
|
195
|
+
* execute after completing the current state.
|
|
196
|
+
* @example
|
|
197
|
+
* {
|
|
198
|
+
* next: 'lambda_name',
|
|
199
|
+
* }
|
|
200
|
+
* @example
|
|
201
|
+
* {
|
|
202
|
+
* next: {
|
|
203
|
+
* type: 'wait',
|
|
204
|
+
* seconds: 3,
|
|
205
|
+
* next: {
|
|
206
|
+
* type: 'succeed'
|
|
207
|
+
* }
|
|
208
|
+
* }
|
|
209
|
+
* }
|
|
210
|
+
*/
|
|
211
|
+
next: StateTypes<T>;
|
|
212
|
+
/**
|
|
213
|
+
* Assign values to the state context.
|
|
214
|
+
*
|
|
215
|
+
* Specifies a mapping of key-value pairs to add or update in the
|
|
216
|
+
* state machine's context when this state executes.
|
|
217
|
+
* Useful for passing data between states or enriching the context.
|
|
218
|
+
*/
|
|
219
|
+
assign?: Record<string, any>;
|
|
220
|
+
}
|
|
221
|
+
interface WaitStateSeconds<T> extends WaitStateBase<T> {
|
|
222
|
+
/**
|
|
223
|
+
* Wait duration in seconds.
|
|
224
|
+
*
|
|
225
|
+
* Specifies the number of seconds that the state machine should pause
|
|
226
|
+
* when executing a `Wait` state. The value can be provided as:
|
|
227
|
+
* - A number representing seconds.
|
|
228
|
+
* - A JSONata expression to compute the duration dynamically based on the context.
|
|
229
|
+
* @example
|
|
230
|
+
* {
|
|
231
|
+
* seconds: 10,
|
|
232
|
+
* }
|
|
233
|
+
* @example
|
|
234
|
+
* {
|
|
235
|
+
* seconds: '{% $states.input.seconds %}'
|
|
236
|
+
* }
|
|
237
|
+
*/
|
|
238
|
+
seconds: number | JsonAtaString;
|
|
239
|
+
timestamp?: never;
|
|
240
|
+
}
|
|
241
|
+
interface WaitStateTimestamp<T> extends WaitStateBase<T> {
|
|
242
|
+
/**
|
|
243
|
+
* Wait until a specific timestamp.
|
|
244
|
+
*
|
|
245
|
+
* Specifies the date and time at which the state machine should
|
|
246
|
+
* resume execution in a `Wait` state. The value can be provided as:
|
|
247
|
+
* - A string representing a timestamp (ISO 8601 format).
|
|
248
|
+
* - A JSONata expression to compute the timestamp dynamically based on the context.
|
|
249
|
+
* @example
|
|
250
|
+
* {
|
|
251
|
+
* timestamp: '2025-01-01T00:00',
|
|
252
|
+
* }
|
|
253
|
+
* @example
|
|
254
|
+
* {
|
|
255
|
+
* timestamp: '{% $states.input.timestamp %}'
|
|
256
|
+
* }
|
|
257
|
+
*/
|
|
258
|
+
timestamp: string;
|
|
259
|
+
seconds?: never;
|
|
260
|
+
}
|
|
261
|
+
interface ChoiceCondition<T> {
|
|
262
|
+
/**
|
|
263
|
+
* Conditional expression for state transitions.
|
|
264
|
+
*
|
|
265
|
+
* Specifies a JSONata expression that determines which state
|
|
266
|
+
* should be executed next based on the current context or input.
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* {
|
|
270
|
+
* condition: '{'$state.input.value = 1'}'
|
|
271
|
+
* }
|
|
272
|
+
*
|
|
273
|
+
*/
|
|
274
|
+
condition: JsonAtaString;
|
|
275
|
+
/**
|
|
276
|
+
* Next state to execute.
|
|
277
|
+
*
|
|
278
|
+
* Specifies the next task or state that the state machine should
|
|
279
|
+
* execute after completing the current state.
|
|
280
|
+
* @example
|
|
281
|
+
* {
|
|
282
|
+
* next: 'lambda_name',
|
|
283
|
+
* }
|
|
284
|
+
* @example
|
|
285
|
+
* {
|
|
286
|
+
* next: {
|
|
287
|
+
* type: 'wait',
|
|
288
|
+
* seconds: 3,
|
|
289
|
+
* next: {
|
|
290
|
+
* type: 'succeed'
|
|
291
|
+
* }
|
|
292
|
+
* }
|
|
293
|
+
* }
|
|
294
|
+
*/
|
|
295
|
+
next: StateTypes<T>;
|
|
296
|
+
}
|
|
297
|
+
export interface ChoiceState<T> {
|
|
298
|
+
/**
|
|
299
|
+
* State type: Choice.
|
|
300
|
+
*
|
|
301
|
+
* Specifies that this state is a `Choice` state, which allows
|
|
302
|
+
* conditional branching based on evaluated expressions.
|
|
303
|
+
*/
|
|
304
|
+
type: 'choice';
|
|
305
|
+
/**
|
|
306
|
+
* Choice conditions.
|
|
307
|
+
*
|
|
308
|
+
* Specifies an array of conditions that determine the next state
|
|
309
|
+
* to execute based on the current context or input.
|
|
310
|
+
*
|
|
311
|
+
* Each condition is evaluated in order, and the first one that
|
|
312
|
+
* matches will define the next state.
|
|
313
|
+
*
|
|
314
|
+
* @example
|
|
315
|
+
* {
|
|
316
|
+
* choices: [
|
|
317
|
+
* {
|
|
318
|
+
* condition: '{% $states.input.value = 1 %}',
|
|
319
|
+
* next: 'lambda_state'
|
|
320
|
+
* },
|
|
321
|
+
* // ...
|
|
322
|
+
* ]
|
|
323
|
+
* }
|
|
324
|
+
*/
|
|
325
|
+
choices: ChoiceCondition<T>[];
|
|
326
|
+
/**
|
|
327
|
+
* Default state.
|
|
328
|
+
*
|
|
329
|
+
* Specifies the state to transition to if none of the `choices`
|
|
330
|
+
* conditions match during the evaluation.
|
|
331
|
+
*
|
|
332
|
+
* @example
|
|
333
|
+
* {
|
|
334
|
+
* default: {
|
|
335
|
+
* type: 'pass',
|
|
336
|
+
* next: 'lambda_state'
|
|
337
|
+
* }
|
|
338
|
+
* }
|
|
339
|
+
*/
|
|
340
|
+
default?: StateTypes<T>;
|
|
341
|
+
}
|
|
342
|
+
interface ParallelState<T> extends CatchAndRetry<T> {
|
|
343
|
+
/**
|
|
344
|
+
* State type: Parallel.
|
|
345
|
+
*
|
|
346
|
+
* Specifies that this state is a `Parallel` state, which allows
|
|
347
|
+
* multiple branches of execution to run simultaneously.
|
|
348
|
+
*/
|
|
349
|
+
type: 'parallel';
|
|
350
|
+
/**
|
|
351
|
+
* Parallel branches.
|
|
352
|
+
*
|
|
353
|
+
* Specifies the different branches that will be executed in parallel
|
|
354
|
+
* within a `Parallel` state. Each branch must be a class decorated
|
|
355
|
+
* with `@NestedStateMachine`.
|
|
356
|
+
*
|
|
357
|
+
* @example
|
|
358
|
+
* {
|
|
359
|
+
* // is a collection of @NestedStateMachine decorated class
|
|
360
|
+
* branches: [Branch1, Branch2]
|
|
361
|
+
* }
|
|
362
|
+
*/
|
|
363
|
+
branches: ClassResource[];
|
|
364
|
+
/**
|
|
365
|
+
* Branch input arguments.
|
|
366
|
+
*
|
|
367
|
+
* Specifies the input data that will be passed to each branch
|
|
368
|
+
* in a `Parallel` state. This can be provided as:
|
|
369
|
+
* - A class decorated with `@Payload`.
|
|
370
|
+
* - A plain object containing key-value pairs.
|
|
371
|
+
*/
|
|
372
|
+
arguments?: ClassResource | Record<string, any>;
|
|
373
|
+
/**
|
|
374
|
+
* Assign values to the state context.
|
|
375
|
+
*
|
|
376
|
+
* Specifies a mapping of key-value pairs to add or update in the
|
|
377
|
+
* state machine's context when this state executes.
|
|
378
|
+
* Useful for passing data between states or enriching the context.
|
|
379
|
+
*/
|
|
380
|
+
assign?: Record<string, any>;
|
|
381
|
+
/**
|
|
382
|
+
* State output transformation.
|
|
383
|
+
*
|
|
384
|
+
* Allows modifying the output of the state before passing it
|
|
385
|
+
* to the next state. The output can be provided as:
|
|
386
|
+
* - An object to directly shape the output.
|
|
387
|
+
* - A JSONata string expression to compute the output dynamically based on the context.
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* {
|
|
391
|
+
* output: '{% $states.result %}'
|
|
392
|
+
* }
|
|
393
|
+
*
|
|
394
|
+
* @example
|
|
395
|
+
* {
|
|
396
|
+
* output: {
|
|
397
|
+
* foo: 1,
|
|
398
|
+
* bar: '{% $states.result %}'
|
|
399
|
+
* }
|
|
400
|
+
* }
|
|
401
|
+
*/
|
|
402
|
+
output?: ObjectOrJsonAta;
|
|
403
|
+
/**
|
|
404
|
+
* End state indicator.
|
|
405
|
+
*
|
|
406
|
+
* Specifies whether this state is a terminal state, meaning
|
|
407
|
+
* the state machine execution will stop after completing this state.
|
|
408
|
+
*/
|
|
409
|
+
end?: boolean;
|
|
410
|
+
/**
|
|
411
|
+
* Next state to execute.
|
|
412
|
+
*
|
|
413
|
+
* Specifies the next task or state that the state machine should
|
|
414
|
+
* execute after completing the current state.
|
|
415
|
+
* @example
|
|
416
|
+
* {
|
|
417
|
+
* next: 'lambda_name',
|
|
418
|
+
* }
|
|
419
|
+
* @example
|
|
420
|
+
* {
|
|
421
|
+
* next: {
|
|
422
|
+
* type: 'wait',
|
|
423
|
+
* seconds: 3,
|
|
424
|
+
* next: {
|
|
425
|
+
* type: 'succeed'
|
|
426
|
+
* }
|
|
427
|
+
* }
|
|
428
|
+
* }
|
|
429
|
+
*/
|
|
430
|
+
next?: StateTypes<T>;
|
|
431
|
+
}
|
|
432
|
+
interface FailState {
|
|
433
|
+
type: 'fail';
|
|
434
|
+
/**
|
|
435
|
+
* Description about error cause, you can use an jsonata expression
|
|
436
|
+
* @example
|
|
437
|
+
* {
|
|
438
|
+
* cause: 'An cause'
|
|
439
|
+
* }
|
|
440
|
+
*
|
|
441
|
+
* @example
|
|
442
|
+
* {
|
|
443
|
+
* cause: '{% $state.result.cause %}'
|
|
444
|
+
* }
|
|
445
|
+
*/
|
|
446
|
+
cause?: string;
|
|
447
|
+
/**
|
|
448
|
+
* Error name, you can use an jsonata expression
|
|
449
|
+
*
|
|
450
|
+
* @example
|
|
451
|
+
* {
|
|
452
|
+
* error: 'An error'
|
|
453
|
+
* }
|
|
454
|
+
*
|
|
455
|
+
* @example
|
|
456
|
+
* {
|
|
457
|
+
* error: '{% $state.result.error %}'
|
|
458
|
+
* }
|
|
459
|
+
*/
|
|
460
|
+
error?: string;
|
|
461
|
+
}
|
|
462
|
+
interface SucceedState {
|
|
463
|
+
type: 'succeed';
|
|
464
|
+
/**
|
|
465
|
+
* State output transformation.
|
|
466
|
+
*
|
|
467
|
+
* Allows modifying the output of the state before passing it
|
|
468
|
+
* to the next state. The output can be provided as:
|
|
469
|
+
* - An object to directly shape the output.
|
|
470
|
+
* - A JSONata string expression to compute the output dynamically based on the context.
|
|
471
|
+
* @example
|
|
472
|
+
* {
|
|
473
|
+
* output: '{% $states.result %}'
|
|
474
|
+
* }
|
|
475
|
+
*
|
|
476
|
+
* @example
|
|
477
|
+
* {
|
|
478
|
+
* output: {
|
|
479
|
+
* foo: 1,
|
|
480
|
+
* bar: '{% $states.result %}'
|
|
481
|
+
* }
|
|
482
|
+
* }
|
|
483
|
+
*/
|
|
484
|
+
output?: ObjectOrJsonAta;
|
|
485
|
+
}
|
|
486
|
+
interface PassState<T> {
|
|
487
|
+
type: 'pass';
|
|
488
|
+
/**
|
|
489
|
+
* Next state to execute.
|
|
490
|
+
*
|
|
491
|
+
* Specifies the next task or state that the state machine should
|
|
492
|
+
* execute after completing the current state.
|
|
493
|
+
* @example
|
|
494
|
+
* {
|
|
495
|
+
* next: 'lambda_name',
|
|
496
|
+
* }
|
|
497
|
+
* @example
|
|
498
|
+
* {
|
|
499
|
+
* next: {
|
|
500
|
+
* type: 'wait',
|
|
501
|
+
* seconds: 3,
|
|
502
|
+
* next: {
|
|
503
|
+
* type: 'succeed'
|
|
504
|
+
* }
|
|
505
|
+
* }
|
|
506
|
+
* }
|
|
507
|
+
*/
|
|
508
|
+
next?: StateTypes<T>;
|
|
509
|
+
/**
|
|
510
|
+
* End state indicator.
|
|
511
|
+
*
|
|
512
|
+
* Specifies whether this state is a terminal state, meaning
|
|
513
|
+
* the state machine execution will stop after completing this state.
|
|
514
|
+
*/
|
|
515
|
+
end?: boolean;
|
|
516
|
+
/**
|
|
517
|
+
* State output transformation.
|
|
518
|
+
*
|
|
519
|
+
* Allows modifying the output of the state before passing it
|
|
520
|
+
* to the next state. The output can be provided as:
|
|
521
|
+
* - An object to directly shape the output.
|
|
522
|
+
* - A JSONata string expression to compute the output dynamically based on the context.
|
|
523
|
+
* @example
|
|
524
|
+
* {
|
|
525
|
+
* output: '{% $states.result %}'
|
|
526
|
+
* }
|
|
527
|
+
*
|
|
528
|
+
* @example
|
|
529
|
+
* {
|
|
530
|
+
* output: {
|
|
531
|
+
* foo: 1,
|
|
532
|
+
* bar: '{% $states.result %}'
|
|
533
|
+
* }
|
|
534
|
+
* }
|
|
535
|
+
*/
|
|
536
|
+
output?: ObjectOrJsonAta;
|
|
537
|
+
/**
|
|
538
|
+
* Assign values to the state context.
|
|
539
|
+
*
|
|
540
|
+
* Specifies a mapping of key-value pairs to add or update in the
|
|
541
|
+
* state machine's context when this state executes.
|
|
542
|
+
* Useful for passing data between states or enriching the context.
|
|
543
|
+
*/
|
|
544
|
+
assign?: Record<string, any>;
|
|
545
|
+
}
|
|
546
|
+
export interface MapStateBase<T> extends CatchAndRetry<T> {
|
|
547
|
+
/**
|
|
548
|
+
* State type: Map.
|
|
549
|
+
*
|
|
550
|
+
* Specifies that this state is a `Map` state, which iterates
|
|
551
|
+
* over a collection of items and executes a set of states for
|
|
552
|
+
* each item individually.
|
|
553
|
+
*/
|
|
554
|
+
type: 'map';
|
|
555
|
+
/**
|
|
556
|
+
* Iterator states.
|
|
557
|
+
*
|
|
558
|
+
* Specifies the set of states that will be executed for each item
|
|
559
|
+
* in the collection within a `Map` state. This should be provided
|
|
560
|
+
* as a class decorated with `@NestedStateMachine`.
|
|
561
|
+
*
|
|
562
|
+
* @example
|
|
563
|
+
* {
|
|
564
|
+
* // is a @NestedStateMachine decorated class
|
|
565
|
+
* states: MapClass
|
|
566
|
+
* }
|
|
567
|
+
*/
|
|
568
|
+
states: ClassResource;
|
|
569
|
+
/**
|
|
570
|
+
* Items to iterate.
|
|
571
|
+
*
|
|
572
|
+
* Specifies the collection of elements that the `Map` state
|
|
573
|
+
* will iterate over. This can be provided as:
|
|
574
|
+
* - A static array of items.
|
|
575
|
+
* - A JSONata expression that dynamically computes the items based on the context.
|
|
576
|
+
* @example
|
|
577
|
+
* {
|
|
578
|
+
* items: [1, 2, 3, 4]
|
|
579
|
+
* }
|
|
580
|
+
*
|
|
581
|
+
* @example
|
|
582
|
+
* {
|
|
583
|
+
* items: '{ $states.input.list }'
|
|
584
|
+
* }
|
|
585
|
+
*/
|
|
586
|
+
items?: any[] | JsonAtaString;
|
|
587
|
+
/**
|
|
588
|
+
* Next state to execute.
|
|
589
|
+
*
|
|
590
|
+
* Specifies the next task or state that the state machine should
|
|
591
|
+
* execute after completing the current state.
|
|
592
|
+
* @example
|
|
593
|
+
* {
|
|
594
|
+
* next: 'lambda_name',
|
|
595
|
+
* }
|
|
596
|
+
* @example
|
|
597
|
+
* {
|
|
598
|
+
* next: {
|
|
599
|
+
* type: 'wait',
|
|
600
|
+
* seconds: 3,
|
|
601
|
+
* next: {
|
|
602
|
+
* type: 'succeed'
|
|
603
|
+
* }
|
|
604
|
+
* }
|
|
605
|
+
* }
|
|
606
|
+
*/
|
|
607
|
+
next?: StateTypes<T>;
|
|
608
|
+
/**
|
|
609
|
+
* Maximum concurrency.
|
|
610
|
+
*
|
|
611
|
+
* Specifies the maximum number of items that the `Map` state
|
|
612
|
+
* will process in parallel at the same time.
|
|
613
|
+
*/
|
|
614
|
+
maxCurrency?: number;
|
|
615
|
+
/**
|
|
616
|
+
* Item selector.
|
|
617
|
+
*
|
|
618
|
+
* Allows transforming or selecting specific parts of each item
|
|
619
|
+
* before it is processed by the `Map` state. The selector can be provided as:
|
|
620
|
+
* - A static object defining the fields to pick or transform.
|
|
621
|
+
* - A JSONata expression to compute or reshape the item dynamically.
|
|
622
|
+
* @example
|
|
623
|
+
* {
|
|
624
|
+
* itemSelector: {
|
|
625
|
+
* item: '{% $state.input.item %}'
|
|
626
|
+
* }
|
|
627
|
+
* }
|
|
628
|
+
* @example
|
|
629
|
+
* {
|
|
630
|
+
* itemSelector: '{% { $state.input.list.[product] } %}'
|
|
631
|
+
* }
|
|
632
|
+
*/
|
|
633
|
+
itemSelector?: ObjectOrJsonAta;
|
|
634
|
+
/**
|
|
635
|
+
* Assign values to the state context.
|
|
636
|
+
*
|
|
637
|
+
* Specifies a mapping of key-value pairs to add or update in the
|
|
638
|
+
* state machine's context when this state executes.
|
|
639
|
+
* Useful for passing data between states or enriching the context.
|
|
640
|
+
*/
|
|
641
|
+
assign?: Record<string, any>;
|
|
642
|
+
/**
|
|
643
|
+
* State output transformation.
|
|
644
|
+
*
|
|
645
|
+
* Allows modifying the output of the state before passing it
|
|
646
|
+
* to the next state. The output can be provided as:
|
|
647
|
+
* - An object to directly shape the output.
|
|
648
|
+
* - A JSONata string expression to compute the output dynamically based on the context.
|
|
649
|
+
* @example
|
|
650
|
+
* {
|
|
651
|
+
* output: '{% $states.result %}'
|
|
652
|
+
* }
|
|
653
|
+
*
|
|
654
|
+
* @example
|
|
655
|
+
* {
|
|
656
|
+
* output: {
|
|
657
|
+
* foo: 1,
|
|
658
|
+
* bar: '{% $states.result %}'
|
|
659
|
+
* }
|
|
660
|
+
* }
|
|
661
|
+
*/
|
|
662
|
+
output?: ObjectOrJsonAta;
|
|
663
|
+
/**
|
|
664
|
+
* Specifies the maximum percentage of items in the distributed map
|
|
665
|
+
* that are allowed to fail before the entire operation is considered unsuccessful.
|
|
666
|
+
*
|
|
667
|
+
*/
|
|
668
|
+
toleratedFailurePercentage?: number;
|
|
669
|
+
/**
|
|
670
|
+
* Specifies the maximum number of items that can fail during the
|
|
671
|
+
* distributed map execution before the entire operation is considered unsuccessful.
|
|
672
|
+
*/
|
|
673
|
+
toleratedFailureCount?: number;
|
|
674
|
+
/**
|
|
675
|
+
* End state indicator.
|
|
676
|
+
*
|
|
677
|
+
* Specifies whether this state is a terminal state, meaning
|
|
678
|
+
* the state machine execution will stop after completing this state.
|
|
679
|
+
*/
|
|
680
|
+
end?: boolean;
|
|
681
|
+
}
|
|
682
|
+
interface MapInline<T> extends MapStateBase<T> {
|
|
683
|
+
/**
|
|
684
|
+
* Execution mode.
|
|
685
|
+
*
|
|
686
|
+
* Specifies that the `Map` state will execute in `inline` mode,
|
|
687
|
+
* meaning all iterations are executed within the same state machine
|
|
688
|
+
* execution rather than spawning separate executions.
|
|
689
|
+
*/
|
|
690
|
+
mode: 'inline';
|
|
691
|
+
}
|
|
692
|
+
interface MapReaderItemBase {
|
|
693
|
+
bucket: BucketNames;
|
|
694
|
+
key: string;
|
|
695
|
+
maxItems?: number;
|
|
696
|
+
}
|
|
697
|
+
interface MapReaderJSONItem extends MapReaderItemBase {
|
|
698
|
+
source: 'json' | 'jsonl' | 'manifest';
|
|
699
|
+
}
|
|
700
|
+
interface MapReaderCSVItem extends MapReaderItemBase {
|
|
701
|
+
source: 'csv';
|
|
702
|
+
headers: {
|
|
703
|
+
location: HeaderLocation;
|
|
704
|
+
titles?: string[];
|
|
705
|
+
};
|
|
706
|
+
delimiter?: CsvDelimiter;
|
|
707
|
+
}
|
|
708
|
+
interface MapWriteResult {
|
|
709
|
+
bucket: BucketNames;
|
|
710
|
+
prefix?: string;
|
|
711
|
+
config?: {
|
|
712
|
+
outputType: 'JSON' | 'JSONL';
|
|
713
|
+
transformation?: 'NONE' | 'COMPACT' | 'FLATTEN';
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
export interface MapDistributed<T> extends MapStateBase<T> {
|
|
717
|
+
/**
|
|
718
|
+
* Execution mode.
|
|
719
|
+
*
|
|
720
|
+
* Specifies that the `Map` state will execute in `distributed` mode,
|
|
721
|
+
* meaning each iteration can be executed as a separate state machine
|
|
722
|
+
* execution, allowing for higher scalability and parallelism.
|
|
723
|
+
*/
|
|
724
|
+
mode: 'distributed';
|
|
725
|
+
/**
|
|
726
|
+
* Map execution type.
|
|
727
|
+
*
|
|
728
|
+
* Specifies the type of execution for the `Map` state, determining
|
|
729
|
+
* how iterations are processed:
|
|
730
|
+
* - `standard`: Iterations run within the standard execution mode,
|
|
731
|
+
* which guarantees exactly-once processing and supports long-running workflows.
|
|
732
|
+
* - `express`: Iterations run in express execution mode, optimized for
|
|
733
|
+
* high-throughput, short-duration workflows.
|
|
734
|
+
*/
|
|
735
|
+
executionType?: 'standard' | 'express';
|
|
736
|
+
/**
|
|
737
|
+
* Map item reader.
|
|
738
|
+
*
|
|
739
|
+
* Specifies the source or format of the items to be processed by
|
|
740
|
+
* the `Map` state.
|
|
741
|
+
*
|
|
742
|
+
* @example
|
|
743
|
+
* {
|
|
744
|
+
* itemReader: {
|
|
745
|
+
* source: 'json',
|
|
746
|
+
* bucket: 'bucket_name',
|
|
747
|
+
* key: 'object.json'
|
|
748
|
+
* }
|
|
749
|
+
* }
|
|
750
|
+
*/
|
|
751
|
+
itemReader?: MapReaderJSONItem | MapReaderCSVItem;
|
|
752
|
+
/**
|
|
753
|
+
* Map result writer.
|
|
754
|
+
*
|
|
755
|
+
* Specifies how the results of each iteration in the `Map` state
|
|
756
|
+
* will be written or aggregated. The `resultWriter` can be used
|
|
757
|
+
* to control the structure and destination of the output for all items.
|
|
758
|
+
*
|
|
759
|
+
* @example
|
|
760
|
+
* {
|
|
761
|
+
* resultWriter: {
|
|
762
|
+
* bucket: 'bucketName',
|
|
763
|
+
* prefix: 'result,
|
|
764
|
+
* config: {
|
|
765
|
+
* outputType: 'JSON'
|
|
766
|
+
* }
|
|
767
|
+
* }
|
|
768
|
+
* }
|
|
769
|
+
*/
|
|
770
|
+
resultWriter?: MapWriteResult;
|
|
771
|
+
/**
|
|
772
|
+
* Max Items Per Batch
|
|
773
|
+
*
|
|
774
|
+
* Defines the maximum number of items to be processed per batch in a Map state execution.
|
|
775
|
+
*/
|
|
776
|
+
maxItemsPerBatch?: number;
|
|
777
|
+
}
|
|
778
|
+
type MapState<T> = MapInline<T> | MapDistributed<T>;
|
|
779
|
+
export type ErrorType = 'States.ALL' | 'States.HeartbeatTimeout' | 'States.Timeout' | 'States.TaskFailed' | 'States.Permissions' | 'States.ResultPathMatchFailure' | 'States.ParameterPathFailure' | 'States.QueryEvaluationError' | 'States.BranchFailed' | 'States.NoChoiceMatched' | 'States.IntrinsicFailure' | 'States.ExceedToleratedFailureThreshold' | 'States.ItemReaderFailed' | 'States.ResultWriterFailed' | (string & {});
|
|
780
|
+
interface StateRetry {
|
|
781
|
+
errorEquals: ErrorType[];
|
|
782
|
+
intervalSeconds?: number;
|
|
783
|
+
maxAttempt?: number;
|
|
784
|
+
backoffRate?: number;
|
|
785
|
+
maxDelaySeconds?: number;
|
|
786
|
+
jitterStrategy?: 'FULL' | 'NONE';
|
|
787
|
+
}
|
|
788
|
+
interface StateCatch<T> {
|
|
789
|
+
/**
|
|
790
|
+
* Error types to catch or retry.
|
|
791
|
+
*
|
|
792
|
+
* Specifies the list of error names that this `Catch` or `Retry`
|
|
793
|
+
* configuration should handle. Only the errors included in this array
|
|
794
|
+
* will trigger the catch or retry behavior.
|
|
795
|
+
*/
|
|
796
|
+
errorEquals: ErrorType[];
|
|
797
|
+
/**
|
|
798
|
+
* Next state to execute.
|
|
799
|
+
*
|
|
800
|
+
* Specifies the next task or state that the state machine should
|
|
801
|
+
* execute after completing the current state.
|
|
802
|
+
* @example
|
|
803
|
+
* {
|
|
804
|
+
* next: 'lambda_name',
|
|
805
|
+
* }
|
|
806
|
+
* @example
|
|
807
|
+
* {
|
|
808
|
+
* next: {
|
|
809
|
+
* type: 'wait',
|
|
810
|
+
* seconds: 3,
|
|
811
|
+
* next: {
|
|
812
|
+
* type: 'succeed'
|
|
813
|
+
* }
|
|
814
|
+
* }
|
|
815
|
+
* }
|
|
816
|
+
*/
|
|
817
|
+
next: T | PassState<T> | SucceedState | FailState;
|
|
818
|
+
}
|
|
819
|
+
export interface CatchAndRetry<T> {
|
|
820
|
+
/**
|
|
821
|
+
* Retry configuration.
|
|
822
|
+
*
|
|
823
|
+
* Specifies the retry behavior for this state in case of failure.
|
|
824
|
+
* The `retry` property allows defining how many times to retry,
|
|
825
|
+
* the interval between retries, and the backoff strategy.
|
|
826
|
+
*/
|
|
827
|
+
retry?: StateRetry[];
|
|
828
|
+
/**
|
|
829
|
+
* Catch configuration.
|
|
830
|
+
*
|
|
831
|
+
* Specifies how errors should be handled for this state. The `catch`
|
|
832
|
+
* property defines one or more handlers that will be invoked if the
|
|
833
|
+
* state fails with a matching error.
|
|
834
|
+
*/
|
|
835
|
+
catch?: StateCatch<T>[];
|
|
836
|
+
}
|
|
837
|
+
export type InitialStateType<T> = T | WaitStateTimestamp<T> | WaitStateSeconds<T> | ChoiceState<T> | ParallelState<T> | MapState<T>;
|
|
838
|
+
export type StateTypes<T> = PassState<T> | FailState | SucceedState | InitialStateType<T>;
|
|
839
|
+
export type RetryCatchTypes<T> = LambdaStateMetadata | ParallelState<T> | MapState<T>;
|
|
840
|
+
export interface StateProps<T> extends CatchAndRetry<T> {
|
|
841
|
+
/**
|
|
842
|
+
* End state indicator.
|
|
843
|
+
*
|
|
844
|
+
* Specifies whether this state is a terminal state, meaning
|
|
845
|
+
* the state machine execution will stop after completing this state.
|
|
846
|
+
*/
|
|
847
|
+
end?: boolean;
|
|
848
|
+
/**
|
|
849
|
+
* Next state to execute.
|
|
850
|
+
*
|
|
851
|
+
* Specifies the next task or state that the state machine should
|
|
852
|
+
* execute after completing the current state.
|
|
853
|
+
* @example
|
|
854
|
+
* {
|
|
855
|
+
* next: 'lambda_name',
|
|
856
|
+
* }
|
|
857
|
+
* @example
|
|
858
|
+
* {
|
|
859
|
+
* next: {
|
|
860
|
+
* type: 'wait',
|
|
861
|
+
* seconds: 3,
|
|
862
|
+
* next: {
|
|
863
|
+
* type: 'succeed'
|
|
864
|
+
* }
|
|
865
|
+
* }
|
|
866
|
+
* }
|
|
867
|
+
*/
|
|
868
|
+
next?: StateTypes<T>;
|
|
869
|
+
/**
|
|
870
|
+
* State output transformation.
|
|
871
|
+
*
|
|
872
|
+
* Allows modifying the output of the state before passing it
|
|
873
|
+
* to the next state. The output can be provided as:
|
|
874
|
+
* - An object to directly shape the output.
|
|
875
|
+
* - A JSONata string expression to compute the output dynamically based on the context.
|
|
876
|
+
* @example
|
|
877
|
+
* {
|
|
878
|
+
* output: '{% $states.result %}'
|
|
879
|
+
* }
|
|
880
|
+
*
|
|
881
|
+
* @example
|
|
882
|
+
* {
|
|
883
|
+
* output: {
|
|
884
|
+
* foo: 1,
|
|
885
|
+
* bar: '{% $states.result %}'
|
|
886
|
+
* }
|
|
887
|
+
* }
|
|
888
|
+
*/
|
|
889
|
+
output?: ObjectOrJsonAta;
|
|
890
|
+
/**
|
|
891
|
+
* Assign values to the state context.
|
|
892
|
+
*
|
|
893
|
+
* Specifies a mapping of key-value pairs to add or update in the
|
|
894
|
+
* state machine's context when this state executes.
|
|
895
|
+
* Useful for passing data between states or enriching the context.
|
|
896
|
+
*/
|
|
897
|
+
assign?: Record<string, any>;
|
|
898
|
+
}
|
|
899
|
+
export interface LambdaStateProps<T = {}> extends StateProps<keyof T> {
|
|
900
|
+
/**
|
|
901
|
+
* Lambda configuration.
|
|
902
|
+
*
|
|
903
|
+
* Specifies the properties of a Lambda function to be invoked
|
|
904
|
+
* by this state.
|
|
905
|
+
*/
|
|
906
|
+
lambda?: Partial<LambdaProps>;
|
|
907
|
+
integrationResource?: never;
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* Configuration for an AWS service integration state.
|
|
911
|
+
*
|
|
912
|
+
* Defines a state that directly integrates with an AWS service
|
|
913
|
+
* instead of invoking a Lambda function. This allows the state machine
|
|
914
|
+
* to call AWS APIs natively without intermediate compute.
|
|
915
|
+
*
|
|
916
|
+
* @see {@link https://docs.aws.amazon.com/step-functions/latest/dg/connect-to-resource.html | AWS Step Functions Service Integrations}
|
|
917
|
+
*
|
|
918
|
+
* @typeParam T - The class type used to infer available state names for transitions.
|
|
919
|
+
*
|
|
920
|
+
* @example
|
|
921
|
+
* ```ts
|
|
922
|
+
* @State({
|
|
923
|
+
* integrationService: 'dynamodb',
|
|
924
|
+
* action: 'putItem',
|
|
925
|
+
* mode: 'sync',
|
|
926
|
+
* end: true,
|
|
927
|
+
* })
|
|
928
|
+
* putItem() {}
|
|
929
|
+
* ```
|
|
930
|
+
*/
|
|
931
|
+
export interface IntegrationStateProps<T = {}> extends StateProps<keyof T> {
|
|
932
|
+
/**
|
|
933
|
+
* AWS service integration resource identifier.
|
|
934
|
+
*
|
|
935
|
+
* Specifies the ARN pattern used to integrate with an AWS service directly
|
|
936
|
+
* from the state machine. The value can follow one of these formats:
|
|
937
|
+
* - `arn:aws:states:::aws-sdk:<service>:<action>` — For AWS SDK integrations.
|
|
938
|
+
* - A full ARN (`arn:aws:states:::...`) — For optimized service integrations.
|
|
939
|
+
*
|
|
940
|
+
* @see {@link https://docs.aws.amazon.com/step-functions/latest/dg/integrate-services.html | Integrating Services with Step Functions}
|
|
941
|
+
*
|
|
942
|
+
* @example
|
|
943
|
+
* ```ts
|
|
944
|
+
* {
|
|
945
|
+
* integrationResource: 'arn:aws:states:::aws-sdk:dynamodb:putItem',
|
|
946
|
+
* }
|
|
947
|
+
* ```
|
|
948
|
+
*
|
|
949
|
+
* @example
|
|
950
|
+
* ```ts
|
|
951
|
+
* {
|
|
952
|
+
* integrationResource: 'arn:aws:states:::sqs:sendMessage',
|
|
953
|
+
* }
|
|
954
|
+
* ```
|
|
955
|
+
*/
|
|
956
|
+
integrationResource: string;
|
|
957
|
+
}
|
|
958
|
+
export type HandlerStateProps<T = {}> = LambdaStateProps<T> | IntegrationStateProps<T>;
|
|
959
|
+
export type LambdaStateMetadata<T = {}> = (LambdaStateProps<T> & LambdaMetadata) | (IntegrationStateProps<T> & Omit<LambdaMetadata, 'lambda'>);
|
|
960
|
+
export interface StateMachineResourceProps<T> extends StateMachineProps<T> {
|
|
961
|
+
/**
|
|
962
|
+
* State Machine name.
|
|
963
|
+
*
|
|
964
|
+
* Specifies the name of the state machine. If not provided, a default
|
|
965
|
+
* name based on the class or resource will be used.
|
|
966
|
+
*/
|
|
967
|
+
name?: StateMachineNames;
|
|
968
|
+
}
|
|
969
|
+
export interface StateMachineResourceMetadata extends Omit<StateMachineProps<any>, 'minify'>, ResourceMetadata {
|
|
970
|
+
startAt: InitialStateType<string>;
|
|
971
|
+
}
|
|
972
|
+
export interface NestedStateMachineResourceProps<T> extends StateMachineBaseProps<T>, ResourceProps {
|
|
973
|
+
}
|
|
974
|
+
export interface NestedStateMachineResourceMetadata extends Omit<StateMachineBaseProps<any>, 'minify'>, ResourceMetadata {
|
|
975
|
+
startAt: InitialStateType<string>;
|
|
976
|
+
}
|
|
977
|
+
export {};
|