Skip to content

Commit ad08cc7

Browse files
committed
Implement input data parsing in debugger
1 parent 5fd13d1 commit ad08cc7

File tree

2 files changed

+36
-26
lines changed

2 files changed

+36
-26
lines changed

rust/cubesql/cubesql/egraph-debug-template/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"elkjs": "^0.9.1",
77
"react": "18.1.0",
88
"react-dom": "18.1.0",
9-
"reactflow": "^11.10.3"
9+
"reactflow": "^11.10.3",
10+
"zod": "3.23.8"
1011
},
1112
"scripts": {
1213
"start": "GENERATE_SOURCEMAP=false && react-scripts start",

rust/cubesql/cubesql/egraph-debug-template/src/index.tsx

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,41 +18,50 @@ import type {
1818
NodeProps,
1919
} from 'reactflow';
2020
import 'reactflow/dist/style.css';
21+
import { z } from 'zod';
2122

2223
import 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

4858
type NodeData = {
4959
label: string;
5060
};
5161
type Node = ReactFlowNode<NodeData>;
5262
type 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
5867
const totalIterations = states.length - 1;

0 commit comments

Comments
 (0)