sfn-diagram 1.2.0 → 1.3.0
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/README.md +79 -3
- package/dist/cfn.d.cts +39 -0
- package/dist/cfn.d.ts +39 -0
- package/dist/cli.js +915 -25
- package/dist/index.cjs +184 -8
- package/dist/index.d.cts +55 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.js +184 -8
- package/dist/png.cjs +171 -3
- package/dist/png.d.cts +46 -0
- package/dist/png.d.ts +46 -0
- package/dist/png.js +171 -3
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -11,8 +11,8 @@ Generate beautiful, interactive diagrams from AWS Step Functions ASL (Amazon Sta
|
|
|
11
11
|
**▶ [Try it in the live playground](https://yusufaf.github.io/sfn-diagram/)** — paste any ASL definition and preview the diagram instantly, no install required.
|
|
12
12
|
|
|
13
13
|
<picture>
|
|
14
|
-
<source media="(prefers-color-scheme: dark)" srcset="
|
|
15
|
-
<img src="
|
|
14
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/images/parallel-dark.svg">
|
|
15
|
+
<img src="docs/images/parallel-light.svg" alt="Example diagram of a Parallel state Step Functions workflow generated by sfn-diagram" width="410">
|
|
16
16
|
</picture>
|
|
17
17
|
|
|
18
18
|
## Table of Contents
|
|
@@ -103,6 +103,7 @@ In short: reach for the AWS Console visualizer to eyeball a state machine you al
|
|
|
103
103
|
- **Multiple Output Formats**: SVG (D3.js), Mermaid syntax, and PNG
|
|
104
104
|
- **Automatic Layout**: Smart graph positioning using Dagre layout engine
|
|
105
105
|
- **Full ASL Support**: All state types (Pass, Task, Choice, Wait, Succeed, Fail, Parallel, Map), both JSONPath and JSONata query languages, plus `Catch`/`Retry` rendering
|
|
106
|
+
- **Modern ASL**: Variables (`Assign`) shown per state, and Distributed Map rendered distinctly from an inline Map — including its `MaxConcurrency`, `ItemReader` source, and `ResultWriter` sink
|
|
106
107
|
- **Visual Diffing**: Compare two definitions and highlight added / modified / removed states — drives the PR-preview GitHub Action
|
|
107
108
|
- **Execution Overlays**: Paint a real execution's history onto the diagram — succeeded/failed/caught/not-reached states, the taken path, and per-state duration & retry counts
|
|
108
109
|
- **Customizable Themes**: AWS light/dark themes plus custom theme support
|
|
@@ -158,7 +159,51 @@ npx sfn-diagram state.asl.json --format mermaid > diagram.mmd
|
|
|
158
159
|
cat state.asl.json | npx sfn-diagram - --format svg
|
|
159
160
|
```
|
|
160
161
|
|
|
161
|
-
|
|
162
|
+
| Flag | Description |
|
|
163
|
+
|---|---|
|
|
164
|
+
| `--format <svg\|mermaid\|png\|html>` | Output format (default: `svg`) |
|
|
165
|
+
| `-o`, `--output <path>` | Output file (required for `png`; stdout otherwise) |
|
|
166
|
+
| `--theme <light\|dark>` | Color theme for SVG/PNG/HTML (default: `light`) |
|
|
167
|
+
| `--layout <TB\|LR\|RL\|BT>` | Graph direction (default: `TB`) |
|
|
168
|
+
| `--hide-catch` | Drop error-handler (`Catch`) branches |
|
|
169
|
+
| `--hide-variables` | Drop the `$var` annotations for ASL `Assign` blocks |
|
|
170
|
+
| `--show-icons` | Draw [AWS service icons](#aws-service-icons) on Task states |
|
|
171
|
+
| `--icon-position <left\|top\|right>` | Icon placement relative to the label (default: `left`) |
|
|
172
|
+
| `--icon-size <pixels>` | Icon size in pixels (default: `24`) |
|
|
173
|
+
| `--diff <baseline>` | Compare the input (head) against a baseline definition |
|
|
174
|
+
| `--execution <history.json>` | Overlay a `GetExecutionHistory` result on the diagram |
|
|
175
|
+
| `--resolve-cfn` | Treat the input as a CloudFormation/SAM/CDK template |
|
|
176
|
+
| `--resource <logicalId>` | State machine to extract when the template has several |
|
|
177
|
+
| `-h`, `--help` / `-v`, `--version` | Show help / version and exit |
|
|
178
|
+
|
|
179
|
+
### Diff and execution overlays from the CLI
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
# Highlight what changed between two revisions of a definition
|
|
183
|
+
npx sfn-diagram head.asl.json --diff base.asl.json -o diff.svg
|
|
184
|
+
npx sfn-diagram head.asl.json --diff base.asl.json --format mermaid > diff.mmd
|
|
185
|
+
|
|
186
|
+
# Colour a diagram by what actually happened in a run
|
|
187
|
+
aws stepfunctions get-execution-history --execution-arn "$ARN" > history.json
|
|
188
|
+
npx sfn-diagram state.asl.json --execution history.json -o run.svg
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Both flags support `--format svg` and `--format mermaid` only, and cannot be combined
|
|
192
|
+
with each other. The change/status summary is written to **stderr**, so the diagram on
|
|
193
|
+
stdout still pipes cleanly:
|
|
194
|
+
|
|
195
|
+
```
|
|
196
|
+
Diff summary:
|
|
197
|
+
Added: NewStep
|
|
198
|
+
Modified: StepB
|
|
199
|
+
Removed: StepC
|
|
200
|
+
Unchanged: 1
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
`--execution` accepts either a full `GetExecutionHistory` response (`{"events": [...]}`)
|
|
204
|
+
or a bare events array. See [generateDiff](#generatemermaiddiffparams--generatediffparams)
|
|
205
|
+
and [generateExecution](#generateexecutionparams--generatemermaidexecutionparams) for the
|
|
206
|
+
programmatic equivalents.
|
|
162
207
|
|
|
163
208
|
CloudFormation/SAM/CDK templates work as input too — see [Extracting ASL from a CDK/CloudFormation template](#extracting-asl-from-a-cdkcloudformation-template).
|
|
164
209
|
|
|
@@ -243,6 +288,7 @@ const result = generateSvg({
|
|
|
243
288
|
padding: 20, // Diagram padding
|
|
244
289
|
edgeStyle: 'curved', // 'curved', 'straight', 'orthogonal'
|
|
245
290
|
showStateTypes: false, // Display state types on nodes
|
|
291
|
+
showVariables: true, // Annotate nodes with the variables they Assign
|
|
246
292
|
includeComments: true, // Use state comments as labels
|
|
247
293
|
customColors: {} // Override colors for specific states
|
|
248
294
|
});
|
|
@@ -576,6 +622,36 @@ Big, branchy state machines are hard to read as a static image. A few options he
|
|
|
576
622
|
- **`--layout LR`** (or `layout: 'LR'`) — the default `TB` layout makes catch-heavy
|
|
577
623
|
or deeply branching machines extremely tall; `LR` reads better for wide graphs.
|
|
578
624
|
|
|
625
|
+
### Variables and Distributed Map
|
|
626
|
+
|
|
627
|
+
Two pieces of modern ASL are rendered explicitly, because both are otherwise
|
|
628
|
+
invisible in a diagram.
|
|
629
|
+
|
|
630
|
+
**Variables (`Assign`).** A state that assigns variables is annotated with their
|
|
631
|
+
names beneath its label — `$orderId, $total`. The list caps at three names, then
|
|
632
|
+
collapses to `+N more`, so a state assigning many variables cannot blow out the
|
|
633
|
+
node width. Disable with `showVariables: false`.
|
|
634
|
+
|
|
635
|
+
```typescript
|
|
636
|
+
const { svg } = generateSvg({ aslDefinition: asl, showVariables: false });
|
|
637
|
+
```
|
|
638
|
+
|
|
639
|
+
**Distributed Map.** A Map whose `ItemProcessor` declares
|
|
640
|
+
`ProcessorConfig.Mode: 'DISTRIBUTED'` runs a child execution per batch rather than
|
|
641
|
+
iterating inline, so it is labelled `Distributed` in the container header instead
|
|
642
|
+
of rendering identically to an inline Map. `MaxConcurrency` is shown alongside it
|
|
643
|
+
when set.
|
|
644
|
+
|
|
645
|
+
Its `ItemReader` (dataset source — S3 or Athena) and `ResultWriter` (result sink)
|
|
646
|
+
each become a satellite node beside the container, wired in and out of the Map.
|
|
647
|
+
With `showIcons: true` they pick up the appropriate AWS service icon, resolved
|
|
648
|
+
from the ARN the same way Task states are.
|
|
649
|
+
|
|
650
|
+
```
|
|
651
|
+
ItemReader (s3) ──▶ ProcessItems ──▶ ResultWriter (s3)
|
|
652
|
+
Distributed · max 100
|
|
653
|
+
```
|
|
654
|
+
|
|
579
655
|
### AWS Service Icons
|
|
580
656
|
|
|
581
657
|
Display AWS service icons on Task state nodes to improve diagram readability and quickly identify which AWS services are being used.
|
package/dist/cfn.d.cts
CHANGED
|
@@ -23,8 +23,33 @@ interface ChoiceRule {
|
|
|
23
23
|
Variable?: string;
|
|
24
24
|
[key: string]: any;
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* A Map state's `ProcessorConfig`, which selects between the inline and
|
|
28
|
+
* distributed execution modes. `Mode: 'DISTRIBUTED'` marks a Distributed Map —
|
|
29
|
+
* a separate child execution per batch, with its own concurrency and failure
|
|
30
|
+
* tolerance semantics.
|
|
31
|
+
*/
|
|
32
|
+
interface ProcessorConfig {
|
|
33
|
+
ExecutionType?: "EXPRESS" | "STANDARD";
|
|
34
|
+
Mode?: "DISTRIBUTED" | "INLINE";
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A Distributed Map `ItemReader` (dataset source) or `ResultWriter` (result sink).
|
|
38
|
+
* Both point at an AWS resource — typically S3, or Athena for `ItemReader` — via
|
|
39
|
+
* the same `Resource` ARN shape used by Task states.
|
|
40
|
+
*/
|
|
41
|
+
interface ItemIo {
|
|
42
|
+
Parameters?: Record<string, any>;
|
|
43
|
+
ReaderConfig?: {
|
|
44
|
+
InputType?: string;
|
|
45
|
+
MaxItems?: number;
|
|
46
|
+
};
|
|
47
|
+
Resource?: string;
|
|
48
|
+
WriterConfig?: Record<string, any>;
|
|
49
|
+
}
|
|
26
50
|
/** A single state within an ASL definition, covering fields for every state type. */
|
|
27
51
|
interface AslState {
|
|
52
|
+
Arguments?: Record<string, any>;
|
|
28
53
|
Assign?: Record<string, any>;
|
|
29
54
|
Branches?: AslDefinition[];
|
|
30
55
|
Catch?: CatchBlock[];
|
|
@@ -34,8 +59,13 @@ interface AslState {
|
|
|
34
59
|
Default?: string;
|
|
35
60
|
End?: boolean;
|
|
36
61
|
Error?: string;
|
|
62
|
+
ItemBatcher?: Record<string, any>;
|
|
37
63
|
ItemProcessor?: AslDefinition;
|
|
64
|
+
ItemReader?: ItemIo;
|
|
65
|
+
ItemSelector?: Record<string, any>;
|
|
38
66
|
Iterator?: AslDefinition;
|
|
67
|
+
Label?: string;
|
|
68
|
+
MaxConcurrency?: number | string;
|
|
39
69
|
Next?: string;
|
|
40
70
|
Output?: any;
|
|
41
71
|
Parameters?: Record<string, any>;
|
|
@@ -43,16 +73,25 @@ interface AslState {
|
|
|
43
73
|
Resource?: string;
|
|
44
74
|
Result?: any;
|
|
45
75
|
ResultPath?: string;
|
|
76
|
+
ResultWriter?: ItemIo;
|
|
46
77
|
Retry?: RetryBlock[];
|
|
47
78
|
Seconds?: number | string;
|
|
48
79
|
SecondsPath?: string;
|
|
49
80
|
Timestamp?: string;
|
|
50
81
|
TimestampPath?: string;
|
|
82
|
+
ToleratedFailureCount?: number;
|
|
83
|
+
ToleratedFailurePercentage?: number;
|
|
51
84
|
Type: StateType;
|
|
52
85
|
}
|
|
53
86
|
/** A complete Amazon States Language state machine definition. */
|
|
54
87
|
interface AslDefinition {
|
|
55
88
|
Comment?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Map-specific, and only valid on an `ItemProcessor` sub-definition rather
|
|
91
|
+
* than on the Map state itself — this is where the ASL spec places it.
|
|
92
|
+
* Selects inline vs distributed execution.
|
|
93
|
+
*/
|
|
94
|
+
ProcessorConfig?: ProcessorConfig;
|
|
56
95
|
QueryLanguage?: "JSONata" | "JSONPath";
|
|
57
96
|
StartAt: string;
|
|
58
97
|
States: Record<string, AslState>;
|
package/dist/cfn.d.ts
CHANGED
|
@@ -23,8 +23,33 @@ interface ChoiceRule {
|
|
|
23
23
|
Variable?: string;
|
|
24
24
|
[key: string]: any;
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* A Map state's `ProcessorConfig`, which selects between the inline and
|
|
28
|
+
* distributed execution modes. `Mode: 'DISTRIBUTED'` marks a Distributed Map —
|
|
29
|
+
* a separate child execution per batch, with its own concurrency and failure
|
|
30
|
+
* tolerance semantics.
|
|
31
|
+
*/
|
|
32
|
+
interface ProcessorConfig {
|
|
33
|
+
ExecutionType?: "EXPRESS" | "STANDARD";
|
|
34
|
+
Mode?: "DISTRIBUTED" | "INLINE";
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A Distributed Map `ItemReader` (dataset source) or `ResultWriter` (result sink).
|
|
38
|
+
* Both point at an AWS resource — typically S3, or Athena for `ItemReader` — via
|
|
39
|
+
* the same `Resource` ARN shape used by Task states.
|
|
40
|
+
*/
|
|
41
|
+
interface ItemIo {
|
|
42
|
+
Parameters?: Record<string, any>;
|
|
43
|
+
ReaderConfig?: {
|
|
44
|
+
InputType?: string;
|
|
45
|
+
MaxItems?: number;
|
|
46
|
+
};
|
|
47
|
+
Resource?: string;
|
|
48
|
+
WriterConfig?: Record<string, any>;
|
|
49
|
+
}
|
|
26
50
|
/** A single state within an ASL definition, covering fields for every state type. */
|
|
27
51
|
interface AslState {
|
|
52
|
+
Arguments?: Record<string, any>;
|
|
28
53
|
Assign?: Record<string, any>;
|
|
29
54
|
Branches?: AslDefinition[];
|
|
30
55
|
Catch?: CatchBlock[];
|
|
@@ -34,8 +59,13 @@ interface AslState {
|
|
|
34
59
|
Default?: string;
|
|
35
60
|
End?: boolean;
|
|
36
61
|
Error?: string;
|
|
62
|
+
ItemBatcher?: Record<string, any>;
|
|
37
63
|
ItemProcessor?: AslDefinition;
|
|
64
|
+
ItemReader?: ItemIo;
|
|
65
|
+
ItemSelector?: Record<string, any>;
|
|
38
66
|
Iterator?: AslDefinition;
|
|
67
|
+
Label?: string;
|
|
68
|
+
MaxConcurrency?: number | string;
|
|
39
69
|
Next?: string;
|
|
40
70
|
Output?: any;
|
|
41
71
|
Parameters?: Record<string, any>;
|
|
@@ -43,16 +73,25 @@ interface AslState {
|
|
|
43
73
|
Resource?: string;
|
|
44
74
|
Result?: any;
|
|
45
75
|
ResultPath?: string;
|
|
76
|
+
ResultWriter?: ItemIo;
|
|
46
77
|
Retry?: RetryBlock[];
|
|
47
78
|
Seconds?: number | string;
|
|
48
79
|
SecondsPath?: string;
|
|
49
80
|
Timestamp?: string;
|
|
50
81
|
TimestampPath?: string;
|
|
82
|
+
ToleratedFailureCount?: number;
|
|
83
|
+
ToleratedFailurePercentage?: number;
|
|
51
84
|
Type: StateType;
|
|
52
85
|
}
|
|
53
86
|
/** A complete Amazon States Language state machine definition. */
|
|
54
87
|
interface AslDefinition {
|
|
55
88
|
Comment?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Map-specific, and only valid on an `ItemProcessor` sub-definition rather
|
|
91
|
+
* than on the Map state itself — this is where the ASL spec places it.
|
|
92
|
+
* Selects inline vs distributed execution.
|
|
93
|
+
*/
|
|
94
|
+
ProcessorConfig?: ProcessorConfig;
|
|
56
95
|
QueryLanguage?: "JSONata" | "JSONPath";
|
|
57
96
|
StartAt: string;
|
|
58
97
|
States: Record<string, AslState>;
|