From b4b6d52f09fc93a00c10ed8584f1676542a74594 Mon Sep 17 00:00:00 2001 From: Luis De Anda Date: Sat, 16 Sep 2023 15:15:26 -0600 Subject: [PATCH] Add example for `noValidate` option --- examples/README.md | 4 +++- examples/disable-arn-validation.js | 24 ++++++++++++++++++++ examples/disable-jsonpath-validation.js | 24 ++++++++++++++++++++ examples/disable-state-machine-validation.js | 15 ++++++++---- 4 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 examples/disable-arn-validation.js create mode 100644 examples/disable-jsonpath-validation.js diff --git a/examples/README.md b/examples/README.md index 832d34f..da9170c 100644 --- a/examples/README.md +++ b/examples/README.md @@ -9,7 +9,9 @@ Here you can find some useful examples demonstrating specific usages of AWS Loca - [check-for-execution-failure](./check-for-execution-failure.js): Check if execution failed and catch error. - [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. - [custom-context-object](./custom-context-object.js): Pass a mock Context Object to the execution. -- [disable-state-machine-validation](./disable-state-machine-validation.js): Disable ARN and/or JSONPath validations when instantiating a new `StateMachine` object. +- [disable-arn-validation](./disable-arn-validation.js): Disable ARN validation when instantiating a new `StateMachine` object. +- [disable-jsonpath-validation](./disable-jsonpath-validation.js): Disable JSONPath validation when instantiating a new `StateMachine` object. +- [disable-state-machine-validation](./disable-state-machine-validation.js): Completely disable validation of the state machine definition when instantiating a new `StateMachine` object. - [execution-event-logs](./execution-event-logs.js): Pulling the log of events produced by an execution as it runs and printing them. - [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. - [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. diff --git a/examples/disable-arn-validation.js b/examples/disable-arn-validation.js new file mode 100644 index 0000000..2313772 --- /dev/null +++ b/examples/disable-arn-validation.js @@ -0,0 +1,24 @@ +import { StateMachine } from 'aws-local-stepfunctions'; + +const machineDefinition = { + Comment: 'A simple minimal example of the States language', + StartAt: 'Hello World', + States: { + 'Hello World': { + Type: 'Task', + InputPath: '$.data', + Resource: 'invalid arn syntax', + End: true, + }, + }, +}; + +// Construct a new state machine with the given definition and don't validate ARNs +const stateMachine = new StateMachine(machineDefinition, { + validationOptions: { + checkArn: false, + }, +}); + +// The following log is printed because no error was thrown by the constructor +console.log('No error was thrown!'); diff --git a/examples/disable-jsonpath-validation.js b/examples/disable-jsonpath-validation.js new file mode 100644 index 0000000..b781831 --- /dev/null +++ b/examples/disable-jsonpath-validation.js @@ -0,0 +1,24 @@ +import { StateMachine } from 'aws-local-stepfunctions'; + +const machineDefinition = { + Comment: 'A simple minimal example of the States language', + StartAt: 'Hello World', + States: { + 'Hello World': { + Type: 'Task', + InputPath: 'invalid JSONPath syntax', + Resource: 'arn:aws:lambda:us-east-1:123456789012:function:AddNumbers', + End: true, + }, + }, +}; + +// Construct a new state machine with the given definition and don't validate JSONPaths +const stateMachine = new StateMachine(machineDefinition, { + validationOptions: { + checkPaths: false, + }, +}); + +// The following log is printed because no error was thrown by the constructor +console.log('No error was thrown!'); diff --git a/examples/disable-state-machine-validation.js b/examples/disable-state-machine-validation.js index 1cfbd75..51147f8 100644 --- a/examples/disable-state-machine-validation.js +++ b/examples/disable-state-machine-validation.js @@ -6,18 +6,23 @@ const machineDefinition = { States: { 'Hello World': { Type: 'Task', - InputPath: 'invalid JSONPath syntax', - Resource: 'invalid arn syntax', + Resource: 'arn:aws:lambda:us-east-1:123456789012:function:AddNumbers', End: true, }, + UnreachableState: { + Type: 'Succeed', + }, + InvalidStateType: { + Type: 'SomeNewType', + }, }, + InvalidTopLevelField: {}, }; -// Construct a new state machine with the given definition and don't validate ARNs nor JSONPaths +// Construct a new state machine with the given definition and don't validate it at all const stateMachine = new StateMachine(machineDefinition, { validationOptions: { - checkArn: false, - checkPaths: false, + noValidate: true, }, });