diff --git a/package.json b/package.json index a751135..c9a9b4d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "asl-puml", - "version": "0.20.0", + "version": "0.21.0", "description": "Generates a plant uml file from a valid JSON ASL file", "main": "./dist/index.js", "bin": { diff --git a/src/__tests__/pumls/aws-example-dynamodb-semaphore.asl.puml b/src/__tests__/pumls/aws-example-dynamodb-semaphore.asl.puml index d5c5b55..c67bbf5 100644 --- a/src/__tests__/pumls/aws-example-dynamodb-semaphore.asl.puml +++ b/src/__tests__/pumls/aws-example-dynamodb-semaphore.asl.puml @@ -21,15 +21,6 @@ skinparam state { FontColor<> automatic BackgroundColor<> #orange } -state "Do Work" as state2<> { -state "Branch 1" as state2_1 { -state "Here" as state11<> -state "You" as state12<> -state "Do" as state13<> -state "Work" as state14<> -state "Run Lambda Function With \nControlled Concurrency" as state15<> -} -} state "Get Lock" as state1<> { state "Branch 1" as state1_1 { state "Acquire Lock" as state5<> @@ -45,6 +36,15 @@ state "Continue Because Lock Was \nAlready Acquired" as state9<> state "Wait to Get Lock" as state10<> } } +state "Do Work" as state2<> { +state "Branch 1" as state2_1 { +state "Here" as state11<> +state "You" as state12<> +state "Do" as state13<> +state "Work" as state14<> +state "Run Lambda Function With \nControlled Concurrency" as state15<> +} +} state "Release Lock" as state3<> state "Success State" as state4<> [*] --> state1 diff --git a/src/__tests__/pumls/aws-example-execute_athena_query.asl.puml b/src/__tests__/pumls/aws-example-execute_athena_query.asl.puml index 94606cd..573bc8c 100644 --- a/src/__tests__/pumls/aws-example-execute_athena_query.asl.puml +++ b/src/__tests__/pumls/aws-example-execute_athena_query.asl.puml @@ -18,14 +18,14 @@ skinparam state { } state "confirm_service_name" as state1<> state "default_service_name" as state2<> -state "get_athena_execution_status" as state7<> -state "get_athena_query" as state4<> -state "get_query_results" as state9<> state "handle_input" as state3<> -state "is_query_finished" as state8<> -state "prepare_output_success" as state10<> +state "get_athena_query" as state4<> state "start_athena_query" as state5<> state "wait_to_query" as state6<> +state "get_athena_execution_status" as state7<> +state "is_query_finished" as state8<> +state "get_query_results" as state9<> +state "prepare_output_success" as state10<> [*] --> state1 state1 --> state3 state1 --> state2 diff --git a/src/__tests__/pumls/aws-example-ship-order-deadpath.asl.puml b/src/__tests__/pumls/aws-example-ship-order-deadpath.asl.puml index b87d971..04fc650 100644 --- a/src/__tests__/pumls/aws-example-ship-order-deadpath.asl.puml +++ b/src/__tests__/pumls/aws-example-ship-order-deadpath.asl.puml @@ -33,15 +33,10 @@ skinparam state { FontColor<> gray BackgroundColor<> #whitesmoke } -state "Do Fraud Check" as state3<> +state "Initial: Validate Input" as state1<> state "Initial: Get Customer Status" as state2<> -state "Initial: Notify Fraudulent \nCustomer" as state10<>: <:warning:><:warning:><:white_check_mark:> -state "Initial: Notify Invalid Input" as state13<> +state "Do Fraud Check" as state3<> state "Initial: Notify New Order" as state4<> -state "Initial: Validate Input" as state1<> -state "Order Shipped Successfully" as state12<> -state "Order Shipping Failed" as state11<> -state "Reserve: Notify Products \nReserved" as state6<> state "Reserve: Products" as state5<> { state "Reserve: Product" as state14<> state "Choice" as state15<> @@ -49,9 +44,14 @@ state "Successful" as state16<> state "Reserve: Notify Delayed" as state17<> state "Wait for availability" as state18<> } -state "Ship: Notify Packaging and \nShipping Failed" as state9<> -state "Ship: Notify Successful \nShipping" as state8<> +state "Reserve: Notify Products \nReserved" as state6<> state "Ship: Packaging and Shipping" as state7<> +state "Ship: Notify Successful \nShipping" as state8<> +state "Ship: Notify Packaging and \nShipping Failed" as state9<> +state "Initial: Notify Fraudulent \nCustomer" as state10<>: <:warning:><:warning:><:white_check_mark:> +state "Order Shipping Failed" as state11<> +state "Order Shipped Successfully" as state12<> +state "Initial: Notify Invalid Input" as state13<> [*] --> state1 state1 -[#lightgray]-> state13 state1 --> state2 diff --git a/src/__tests__/pumls/aws-example-ship-order.asl.puml b/src/__tests__/pumls/aws-example-ship-order.asl.puml index 062db68..87ef399 100644 --- a/src/__tests__/pumls/aws-example-ship-order.asl.puml +++ b/src/__tests__/pumls/aws-example-ship-order.asl.puml @@ -47,15 +47,10 @@ skinparam state { FontColor<> gray BackgroundColor<> #whitesmoke } -state "Do Fraud Check" as state3<> +state "Initial: Validate Input" as state1<> state "Initial: Get Customer Status" as state2<> -state "Initial: Notify Fraudulent \nCustomer" as state10<> -state "Initial: Notify Invalid Input" as state13<> +state "Do Fraud Check" as state3<> state "Initial: Notify New Order" as state4<> -state "Initial: Validate Input" as state1<> -state "Order Shipped Successfully" as state12<> -state "Order Shipping Failed" as state11<> -state "Reserve: Notify Products \nReserved" as state6<> state "Reserve: Products" as state5<> { state "Reserve: Product" as state14<> state "Choice" as state15<> @@ -63,9 +58,14 @@ state "Successful" as state16<> state "Reserve: Notify Delayed" as state17<> state "Wait for availability" as state18<> } -state "Ship: Notify Packaging and \nShipping Failed" as state9<> -state "Ship: Notify Successful \nShipping" as state8<> +state "Reserve: Notify Products \nReserved" as state6<> state "Ship: Packaging and Shipping" as state7<> +state "Ship: Notify Successful \nShipping" as state8<> +state "Ship: Notify Packaging and \nShipping Failed" as state9<> +state "Initial: Notify Fraudulent \nCustomer" as state10<> +state "Order Shipping Failed" as state11<> +state "Order Shipped Successfully" as state12<> +state "Initial: Notify Invalid Input" as state13<> [*] --> state1 state1 -[#lightgray]-> state13 state1 --> state2 diff --git a/src/__tests__/pumls/aws-example-test-result-recorder.asl.puml b/src/__tests__/pumls/aws-example-test-result-recorder.asl.puml index 93f75a9..e8c0d44 100644 --- a/src/__tests__/pumls/aws-example-test-result-recorder.asl.puml +++ b/src/__tests__/pumls/aws-example-test-result-recorder.asl.puml @@ -16,14 +16,14 @@ skinparam state { FontColor<> automatic BackgroundColor<> #orange } -state "ClearResults" as state7<> -state "ConfirmRequiredData" as state2<> state "HandleInput" as state1<> -state "InvalidInput" as state8<> +state "ConfirmRequiredData" as state2<> +state "WasSuccessOrFailure" as state3<> state "RecordTestRun-DurationMetric" as state4<> -state "RecordTestRun-DynamoDB" as state6<> state "RecordTestRun-StatusMetric" as state5<> -state "WasSuccessOrFailure" as state3<> +state "RecordTestRun-DynamoDB" as state6<> +state "ClearResults" as state7<> +state "InvalidInput" as state8<> [*] --> state1 state1 --> state2 state2 --> state3 diff --git a/src/__tests__/pumls/demo.asl.puml b/src/__tests__/pumls/demo.asl.puml index b2bae33..b7899d6 100644 --- a/src/__tests__/pumls/demo.asl.puml +++ b/src/__tests__/pumls/demo.asl.puml @@ -22,17 +22,17 @@ state "FulfillAsk" as state5<> state "FulfillFundAccount" as state6<> } state "Dispatch by type of item" as state1<> -state "Error" as state8<> -state "MarkOrderAsFulfilled" as state7<> -state "PrepareFulfillAskRequest" as state3<> state "PrepareFulfillWidgetRequest" as state2<> +state "PrepareFulfillAskRequest" as state3<> +state "MarkOrderAsFulfilled" as state7<> +state "Error" as state8<> +state "PublishOrderComplete" as state9<> state "PublishCompensate" as state10<> note left order will be canceled, payments refunded, and inventory released end note -state "PublishOrderComplete" as state9<> [*] --> state1 state1 --> state2 note on link diff --git a/src/__tests__/pumls/nested_maps.asl.puml b/src/__tests__/pumls/nested_maps.asl.puml index a04f4fc..a70997c 100644 --- a/src/__tests__/pumls/nested_maps.asl.puml +++ b/src/__tests__/pumls/nested_maps.asl.puml @@ -12,12 +12,12 @@ skinparam state { FontColor<> automatic BackgroundColor<> #orange } -state "Final State" as state2<> state "Map" as state1<> { state "Map2" as state3<> { state "Wait 20s" as state4<> } } +state "Final State" as state2<> [*] --> state1 state1 --> state2 state2 --> [*] diff --git a/src/__tests__/pumls/parallel.asl.puml b/src/__tests__/pumls/parallel.asl.puml index 6d2915e..f97a67e 100644 --- a/src/__tests__/pumls/parallel.asl.puml +++ b/src/__tests__/pumls/parallel.asl.puml @@ -15,7 +15,6 @@ skinparam state { FontColor<> automatic BackgroundColor<> #orange } -state "Final State" as state2<> state "Parallel" as state1<> { state "Branch 1" as state1_1 { state "Wait 20s" as state3<> @@ -25,6 +24,7 @@ state "Pass" as state4<> state "Wait 10s" as state5<> } } +state "Final State" as state2<> [*] --> state1 state1 --> state2 state1 -[bold,#orange]-> state2 diff --git a/src/__tests__/pumls/parallel_in_map.asl.puml b/src/__tests__/pumls/parallel_in_map.asl.puml index ca481ef..c093539 100644 --- a/src/__tests__/pumls/parallel_in_map.asl.puml +++ b/src/__tests__/pumls/parallel_in_map.asl.puml @@ -17,8 +17,6 @@ skinparam state { FontColor<> automatic BackgroundColor<> #orange } -state "Error" as state2<> -state "Final State" as state3<> state "Map" as state1<> { state "Parallel" as state4<> { state "Branch 1" as state4_1 { @@ -29,6 +27,8 @@ state "Wait 30s" as state6<> } } } +state "Error" as state2<> +state "Final State" as state3<> [*] --> state1 state1 --> state3 state1 -[#pink]-> state2 diff --git a/src/lib/decls.ts b/src/lib/decls.ts index df86506..b8bbc90 100644 --- a/src/lib/decls.ts +++ b/src/lib/decls.ts @@ -153,7 +153,11 @@ export const decls: PumlBuilder = (_definition, state_map, config: Config) => { } }); - const sorted = Array.from(state_map.keys()).sort(); + const sorted = Array.from(state_map.keys()).sort((a, b) => { + const stateA = state_map.get(a) as StateHints; + const stateB = state_map.get(b) as StateHints; + return stateA.id - stateB.id; + }); // emit containers first sorted .filter((key) => (state_map.get(key) as StateHints).parent === null)