@@ -18,41 +18,50 @@ import type {
1818 NodeProps ,
1919} from 'reactflow' ;
2020import 'reactflow/dist/style.css' ;
21+ import { z } from 'zod' ;
2122
2223import statesData from './states.json' ;
2324
24- type InputNodeData = {
25- id : string ;
26- label : string ;
27- comboId : string ;
28- } ;
29- type InputEdgeData = {
30- source : string ;
31- target : string ;
32- } ;
33- type InputComboData = {
34- id : string ;
35- label : string ;
36- } ;
37- type StateData = {
38- nodes : Array < InputNodeData > ;
39- removedNodes : Array < InputNodeData > ;
40- edges : Array < InputEdgeData > ;
41- removedEdges : Array < InputEdgeData > ;
42- combos : Array < InputComboData > ;
43- removedCombos : Array < InputComboData > ;
44- appliedRules : Array < string > ;
45- } ;
46- type InputData = Array < StateData > ;
25+ const InputNodeData = z . object ( {
26+ id : z . string ( ) ,
27+ label : z . string ( ) ,
28+ comboId : z . string ( ) ,
29+ } ) ;
30+ type InputNodeData = z . infer < typeof InputNodeData > ;
31+
32+ const InputEdgeData = z . object ( {
33+ source : z . string ( ) ,
34+ target : z . string ( ) ,
35+ } ) ;
36+ type InputEdgeData = z . infer < typeof InputEdgeData > ;
37+
38+ const InputComboData = z . object ( {
39+ id : z . string ( ) ,
40+ label : z . string ( ) ,
41+ } ) ;
42+ type InputComboData = z . infer < typeof InputComboData > ;
43+
44+ const StateData = z . object ( {
45+ nodes : z . array ( InputNodeData ) ,
46+ removedNodes : z . array ( InputNodeData ) ,
47+ edges : z . array ( InputEdgeData ) ,
48+ removedEdges : z . array ( InputEdgeData ) ,
49+ combos : z . array ( InputComboData ) ,
50+ removedCombos : z . array ( InputComboData ) ,
51+ appliedRules : z . array ( z . string ( ) ) ,
52+ } ) ;
53+ type StateData = z . infer < typeof StateData > ;
54+
55+ const InputData = z . array ( StateData ) ;
56+ type InputData = z . infer < typeof InputData > ;
4757
4858type NodeData = {
4959 label : string ;
5060} ;
5161type Node = ReactFlowNode < NodeData > ;
5262type Edge = ReactFlowEdge < null > ;
5363
54- // TODO proper parsing here
55- const states = statesData as InputData ;
64+ const states = InputData . parse ( statesData ) ;
5665
5766// First is initial state
5867const totalIterations = states . length - 1 ;
0 commit comments