feat(graph/export): implement export() and toJSON() methods on TaskGraph

This commit is contained in:
2026-04-27 11:49:11 +00:00
parent 9ad0ec902c
commit 34e227464c
3 changed files with 222 additions and 8 deletions

View File

@@ -130,4 +130,33 @@ export class TaskGraph {
graph._graph.import(data);
return graph;
}
// ---------------------------------------------------------------------------
// Export methods
// ---------------------------------------------------------------------------
/**
* Export the graph as a serialized object in graphology native JSON format.
*
* The returned object conforms to the `TaskGraphSerialized` schema and
* includes all node attributes (name, scope, risk, etc.) and edge attributes
* (including `qualityRetention`).
*
* The output can be passed to `TaskGraph.fromJSON()` for a round-trip.
*
* @returns A `TaskGraphSerialized` object representing this graph
*/
export(): TaskGraphSerialized {
return this._graph.export() as TaskGraphSerialized;
}
/**
* Alias for `export()`. Enables `JSON.stringify(graph)` to produce
* the serialized graph representation automatically.
*
* @returns A `TaskGraphSerialized` object representing this graph
*/
toJSON(): TaskGraphSerialized {
return this.export();
}
}