Skip to content

Commit 316859d

Browse files
authored
Merge pull request #70 from nibble-4bits/feature/no-validate-option
Feature/no validate option
2 parents d2d3dd9 + 71e712f commit 316859d

File tree

10 files changed

+92
-16
lines changed

10 files changed

+92
-16
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ The constructor takes the following parameters:
103103
- `validationOptions?`: An object that specifies how the definition should be validated.
104104
- `checkPaths`: If set to `false`, won't validate JSONPaths.
105105
- `checkArn`: If set to `false`, won't validate ARN syntax in `Task` states.
106+
- `noValidate`: If set to `true`, will skip validation of the definition entirely.
107+
> NOTE: Use this option at your own risk, there are no guarantees when passing an invalid/non-standard definition to the state machine. Running it might result in undefined behavior.
106108
- `awsConfig?`: An object that specifies the [AWS region and credentials](/docs/feature-support.md#providing-aws-credentials-and-region-to-execute-lambda-functions-specified-in-task-states) to use when invoking a Lambda function in a `Task` state. If not set, the AWS config will be resolved based on the [credentials provider chain](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html) of the AWS SDK for JavaScript V3. You don't need to use this option if you have a [shared config/credentials file](https://docs.aws.amazon.com/sdkref/latest/guide/file-format.html) (for example, if you have the [AWS CLI](https://aws.amazon.com/cli/) installed) or if you use a local override for all of your `Task` states.
107109
- `region`: The AWS region where the Lambda functions are created.
108110
- `credentials`: An object that specifies which type of credentials to use.

__tests__/StateMachine.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,31 @@ describe('State Machine', () => {
8484
new StateMachine(stateMachineDefinition, stateMachineOptions);
8585
}).not.toThrow();
8686
});
87+
88+
test('should not throw if definition validation is completely turned off when creating instance', async () => {
89+
const stateMachineDefinition: StateMachineDefinition = {
90+
StartAt: 'FirstState',
91+
States: {
92+
FirstState: {
93+
Type: 'Pass',
94+
InputPath: 'invalidPath',
95+
ResultPath: 'invalidPath',
96+
OutputPath: 'invalidPath',
97+
End: true,
98+
},
99+
UnreachableState: {
100+
// @ts-expect-error Invalid state type
101+
Type: 'InvalidType',
102+
},
103+
},
104+
InvalidTopLevelField: {},
105+
};
106+
const stateMachineOptions = { validationOptions: { noValidate: true } };
107+
108+
expect(() => {
109+
new StateMachine(stateMachineDefinition, stateMachineOptions);
110+
}).not.toThrow();
111+
});
87112
});
88113

89114
describe('run()', () => {

examples/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ Here you can find some useful examples demonstrating specific usages of AWS Loca
99
- [check-for-execution-failure](./check-for-execution-failure.js): Check if execution failed and catch error.
1010
- [check-for-execution-timeout](./check-for-execution-timeout.js): Check if execution timed out because the execution ran longer than the seconds specified in the `TimeoutSeconds` field and catch error.
1111
- [custom-context-object](./custom-context-object.js): Pass a mock Context Object to the execution.
12-
- [disable-state-machine-validation](./disable-state-machine-validation.js): Disable ARN and/or JSONPath validations when instantiating a new `StateMachine` object.
12+
- [disable-arn-validation](./disable-arn-validation.js): Disable ARN validation when instantiating a new `StateMachine` object.
13+
- [disable-jsonpath-validation](./disable-jsonpath-validation.js): Disable JSONPath validation when instantiating a new `StateMachine` object.
14+
- [disable-state-machine-validation](./disable-state-machine-validation.js): Completely disable validation of the state machine definition when instantiating a new `StateMachine` object.
1315
- [execution-event-logs](./execution-event-logs.js): Pulling the log of events produced by an execution as it runs and printing them.
1416
- [task-state-local-override](./task-state-local-override.js): Override the default action for a `Task` state, so that instead of invoking the Lambda specified in the `Resource` field, it runs a local function. This allows running state machines completely locally.
1517
- [wait-state-local-override](./wait-state-local-override.js): Override the wait duration of a `Wait` state so that instead of waiting the duration specified in the `Seconds`, `Timestamp`, `SecondsPath`, `TimestampPath` fields, it waits for a specified number of milliseconds.

examples/disable-arn-validation.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { StateMachine } from 'aws-local-stepfunctions';
2+
3+
const machineDefinition = {
4+
Comment: 'A simple minimal example of the States language',
5+
StartAt: 'Hello World',
6+
States: {
7+
'Hello World': {
8+
Type: 'Task',
9+
InputPath: '$.data',
10+
Resource: 'invalid arn syntax',
11+
End: true,
12+
},
13+
},
14+
};
15+
16+
// Construct a new state machine with the given definition and don't validate ARNs
17+
const stateMachine = new StateMachine(machineDefinition, {
18+
validationOptions: {
19+
checkArn: false,
20+
},
21+
});
22+
23+
// The following log is printed because no error was thrown by the constructor
24+
console.log('No error was thrown!');
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { StateMachine } from 'aws-local-stepfunctions';
2+
3+
const machineDefinition = {
4+
Comment: 'A simple minimal example of the States language',
5+
StartAt: 'Hello World',
6+
States: {
7+
'Hello World': {
8+
Type: 'Task',
9+
InputPath: 'invalid JSONPath syntax',
10+
Resource: 'arn:aws:lambda:us-east-1:123456789012:function:AddNumbers',
11+
End: true,
12+
},
13+
},
14+
};
15+
16+
// Construct a new state machine with the given definition and don't validate JSONPaths
17+
const stateMachine = new StateMachine(machineDefinition, {
18+
validationOptions: {
19+
checkPaths: false,
20+
},
21+
});
22+
23+
// The following log is printed because no error was thrown by the constructor
24+
console.log('No error was thrown!');

examples/disable-state-machine-validation.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,23 @@ const machineDefinition = {
66
States: {
77
'Hello World': {
88
Type: 'Task',
9-
InputPath: 'invalid JSONPath syntax',
10-
Resource: 'invalid arn syntax',
9+
Resource: 'arn:aws:lambda:us-east-1:123456789012:function:AddNumbers',
1110
End: true,
1211
},
12+
UnreachableState: {
13+
Type: 'Succeed',
14+
},
15+
InvalidStateType: {
16+
Type: 'SomeNewType',
17+
},
1318
},
19+
InvalidTopLevelField: {},
1420
};
1521

16-
// Construct a new state machine with the given definition and don't validate ARNs nor JSONPaths
22+
// Construct a new state machine with the given definition and don't validate it at all
1723
const stateMachine = new StateMachine(machineDefinition, {
1824
validationOptions: {
19-
checkArn: false,
20-
checkPaths: false,
25+
noValidate: true,
2126
},
2227
});
2328

src/stateMachine/StateMachine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class StateMachine {
2929
* These options also apply to state machines defined in the `Iterator` field of `Map` states and in the `Branches` field of `Parallel` states.
3030
*/
3131
constructor(definition: StateMachineDefinition, stateMachineOptions?: StateMachineOptions) {
32-
if (!stateMachineOptions?.validationOptions?._noValidate) {
32+
if (!stateMachineOptions?.validationOptions?.noValidate) {
3333
const { isValid, errorsText } = aslValidator(definition, {
3434
checkArn: true,
3535
checkPaths: true,

src/stateMachine/stateActions/MapStateAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class MapStateAction extends BaseStateAction<MapState> {
8989

9090
const iteratorStateMachine = new StateMachine(state.Iterator, {
9191
...options.stateMachineOptions,
92-
validationOptions: { _noValidate: true },
92+
validationOptions: { noValidate: true },
9393
});
9494
const limit = pLimit(state.MaxConcurrency || DEFAULT_MAX_CONCURRENCY);
9595
const processedItemsPromise = items.map((item, i) =>

src/stateMachine/stateActions/ParallelStateAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ParallelStateAction extends BaseStateAction<ParallelState> {
4343
): Promise<JSONValue> {
4444
const stateMachine = new StateMachine(branch, {
4545
...options.stateMachineOptions,
46-
validationOptions: { _noValidate: true },
46+
validationOptions: { noValidate: true },
4747
});
4848
const execution = stateMachine.run(input, options.runOptions);
4949

src/typings/StateMachineImplementation.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,9 @@ interface Overrides {
1818
}
1919

2020
export interface ValidationOptions {
21+
readonly noValidate?: boolean;
2122
readonly checkPaths?: boolean;
2223
readonly checkArn?: boolean;
23-
/**
24-
* @internal DO NOT USE.
25-
*
26-
* This property is meant for internal use only.
27-
* There are no guarantees regarding future changes made to this property.
28-
*/
29-
readonly _noValidate?: boolean;
3024
}
3125

3226
export interface AWSConfig {

0 commit comments

Comments
 (0)