import { InferOutput, parse } from "valibot"; import DeserializerError from "../../../errors/DeserializerError.js"; import Edge from "../../../graph/Edge.js"; import Graph, { GraphSchema } from "../../../graph/Graph.js"; import Node from "../../../graph/Node.js"; import { JsonDeserializer } from "./JsonDeserializer.js"; export default class JointJsonDeserializer implements JsonDeserializer>> { deserialize(input: string) : Graph> { const parsed = JSON.parse(input); if(!parsed) throw new DeserializerError("Result of parsing graph structure not found"); let graph: InferOutput; try { graph = parse(GraphSchema, parsed); // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (error: any) { throw new DeserializerError(error.message) } return new Graph(graph.nodes, graph.edges); } }