Skip to content

Commit 8574e45

Browse files
committed
Don't validate state machine when executing a Map or Parallel state
1 parent 6cad3d8 commit 8574e45

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

src/stateMachine/StateMachine.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,16 @@ export class StateMachine {
3535
* These options also apply to state machines defined in the `Iterator` field of `Map` states and in the `Branches` field of `Parallel` states.
3636
*/
3737
constructor(definition: StateMachineDefinition, stateMachineOptions?: StateMachineOptions) {
38-
const { isValid, errorsText } = aslValidator(definition, {
39-
checkArn: true,
40-
checkPaths: true,
41-
...stateMachineOptions?.validationOptions,
42-
});
43-
44-
if (!isValid) {
45-
throw new Error(`State machine definition is invalid, see error(s) below:\n ${errorsText('\n')}`);
38+
if (!stateMachineOptions?.validationOptions?._noValidate) {
39+
const { isValid, errorsText } = aslValidator(definition, {
40+
checkArn: true,
41+
checkPaths: true,
42+
...stateMachineOptions?.validationOptions,
43+
});
44+
45+
if (!isValid) {
46+
throw new Error(`State machine definition is invalid, see error(s) below:\n ${errorsText('\n')}`);
47+
}
4648
}
4749

4850
this.definition = definition;

src/stateMachine/stateActions/MapStateAction.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ class MapStateAction extends BaseStateAction<MapState> {
7171
throw new StatesRuntimeError('Input of Map state must be an array or ItemsPath property must point to an array');
7272
}
7373

74-
const iteratorStateMachine = new StateMachine(state.Iterator, options?.stateMachineOptions);
74+
const iteratorStateMachine = new StateMachine(state.Iterator, {
75+
...options?.stateMachineOptions,
76+
validationOptions: { _noValidate: true },
77+
});
7578
const limit = pLimit(state.MaxConcurrency || DEFAULT_MAX_CONCURRENCY);
7679
const processedItemsPromise = items.map((item, i) =>
7780
limit(() => this.processItem(iteratorStateMachine, item, input, context, i, options))

src/stateMachine/stateActions/ParallelStateAction.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ class ParallelStateAction extends BaseStateAction<ParallelState> {
2727
context: Context,
2828
options: ParallelStateActionOptions | undefined
2929
): Promise<JSONValue> {
30-
const stateMachine = new StateMachine(branch, options?.stateMachineOptions);
30+
const stateMachine = new StateMachine(branch, {
31+
...options?.stateMachineOptions,
32+
validationOptions: { _noValidate: true },
33+
});
3134
const execution = stateMachine.run(input, options?.runOptions);
3235

3336
this.executionAbortFuncs.push(execution.abort);

src/typings/StateMachineImplementation.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ interface Overrides {
1818
export interface ValidationOptions {
1919
readonly checkPaths?: boolean;
2020
readonly checkArn?: boolean;
21+
/**
22+
* @internal DO NOT USE. This property is meant for internal use only.
23+
*/
24+
readonly _noValidate?: boolean;
2125
}
2226

2327
export interface AWSConfig {

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"declaration": true,
66
"noUncheckedIndexedAccess": false,
77
"noUnusedParameters": false,
8-
"resolveJsonModule": true
8+
"resolveJsonModule": true,
9+
"stripInternal": true
910
},
1011
"include": ["src/**/*.ts"],
1112
"exclude": ["node_modules"]

0 commit comments

Comments
 (0)