Skip to content

Commit 6dda108

Browse files
committed
Add graph-storage crate
1 parent c8161b9 commit 6dda108

21 files changed

Lines changed: 4589 additions & 145 deletions

File tree

Cargo.lock

Lines changed: 97 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ members = [
88
"desktop/platform/mac",
99
"desktop/platform/win",
1010
"document/container",
11+
"document/graph-storage",
1112
"editor",
1213
"frontend/wrapper",
1314
"libraries/dyn-any",
@@ -87,6 +88,7 @@ repeat-nodes = { path = "node-graph/nodes/repeat" }
8788
math-nodes = { path = "node-graph/nodes/math" }
8889
path-bool-nodes = { path = "node-graph/nodes/path-bool" }
8990
graph-craft = { path = "node-graph/graph-craft" }
91+
graph-storage = { path = "document/graph-storage" }
9092
raster-nodes = { path = "node-graph/nodes/raster" }
9193
graphene-std = { path = "node-graph/nodes/gstd" }
9294
interpreted-executor = { path = "node-graph/interpreted-executor" }

document/graph-storage/Cargo.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[package]
2+
name = "graph-storage"
3+
description = "Provides a delta based graph representation used in the Graphite file format"
4+
edition.workspace = true
5+
version.workspace = true
6+
license.workspace = true
7+
authors.workspace = true
8+
9+
[dependencies]
10+
serde = { workspace = true }
11+
serde_json = { workspace = true }
12+
graph-craft = { workspace = true }
13+
graphene-resource = { workspace = true }
14+
core-types = { workspace = true }
15+
blake3 = "1.5"
16+
postcard = { version = "1.0", features = ["use-std"] }
17+
rustc-hash = "2.0"
18+
thiserror = "2.0"
19+
20+
[dev-dependencies]
21+
graph-craft = { workspace = true, features = ["loading"] }
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//! CLI: round-trips a `.graphite` file through `NodeNetwork → Registry → NodeNetwork`.
2+
3+
use std::fs;
4+
use std::path::PathBuf;
5+
use std::process::ExitCode;
6+
7+
use graph_craft::document::NodeNetwork;
8+
use graph_storage::Registry;
9+
10+
fn main() -> ExitCode {
11+
if let Err(error) = run() {
12+
eprintln!("{error}");
13+
return ExitCode::FAILURE;
14+
}
15+
ExitCode::SUCCESS
16+
}
17+
18+
fn run() -> Result<(), String> {
19+
let args: Vec<String> = std::env::args().collect();
20+
let [_, input, output] = args.as_slice() else {
21+
return Err(format!("Usage: {} <input.graphite> <output.graphite>", args.first().map(String::as_str).unwrap_or("round_trip")));
22+
};
23+
24+
let input_path = PathBuf::from(input);
25+
let output_path = PathBuf::from(output);
26+
27+
println!("Loading artwork from: {}", input_path.display());
28+
29+
let json_content = fs::read_to_string(&input_path).map_err(|e| format!("Error reading input: {e}"))?;
30+
let mut doc: serde_json::Value = serde_json::from_str(&json_content).map_err(|e| format!("Error parsing JSON: {e}"))?;
31+
32+
let original_network: NodeNetwork = serde_json::from_value(doc["network_interface"]["network"].clone()).map_err(|e| format!("Error deserializing NodeNetwork: {e}"))?;
33+
println!("Original network: {} nodes", original_network.nodes.len());
34+
35+
// No byte store here: keep the extracted declaration bytes in hand and rebuild the `Declarations`
36+
// map from them so the back-conversion can resolve proto-node identifiers.
37+
let conversion =
38+
Registry::convert_from_runtime(&original_network, &graph_storage::NoMetadata, &Default::default(), graph_storage::PeerId(0)).map_err(|e| format!("Error converting to Registry: {e}"))?;
39+
let declarations = conversion.declarations().map_err(|e| format!("Error rebuilding declarations: {e}"))?;
40+
let registry = conversion.registry;
41+
println!("Registry: {} node instances, {} networks", registry.node_instances.len(), registry.networks.len());
42+
43+
let mut node_ids: Vec<_> = registry.node_instances.keys().copied().collect();
44+
node_ids.sort();
45+
println!("Registry node IDs: {node_ids:?}");
46+
47+
let (converted_network, _entries) = registry.to_runtime_with_metadata(&declarations).map_err(|e| format!("Error converting back to NodeNetwork: {e}"))?;
48+
println!("Converted network: {} nodes", converted_network.nodes.len());
49+
50+
doc["network_interface"]["network"] = serde_json::to_value(&converted_network).map_err(|e| format!("Error serializing converted network: {e}"))?;
51+
let output_json = serde_json::to_string_pretty(&doc).map_err(|e| format!("Error serializing output JSON: {e}"))?;
52+
fs::write(&output_path, output_json).map_err(|e| format!("Error writing output: {e}"))?;
53+
54+
println!("Wrote round-tripped artwork to: {}", output_path.display());
55+
Ok(())
56+
}

0 commit comments

Comments
 (0)