feat(graph-wasm): cognicode-graph-wasm bindgen shim (PR #3)#23
Open
Rubentxu wants to merge 3 commits into
Open
feat(graph-wasm): cognicode-graph-wasm bindgen shim (PR #3)#23Rubentxu wants to merge 3 commits into
Rubentxu wants to merge 3 commits into
Conversation
Add the wasm-bindgen shim crate to the workspace. This crate exposes PageRank and god_nodes from cognicode-graph-algos to JavaScript via wasm-bindgen. - Added wasm-bindgen 0.2 and serde-wasm-bindgen 0.6 to workspace.dependencies (required for WASM target). - Added cognicode-graph-wasm as workspace member and dependency.
protocol.rs defines the serde-serializable request/response types shared between wasm32 and native targets: - Graph (wraps JsonGraph from cognicode-graph-algos) - PageRankOptions / PageRankOutput - GodNodesOptions / GodNodesOutput / GodNodeEntry The Graph wrapper delegates to the existing JsonGraph adapter in cognicode-graph-algos (single-source rule, ADR-047/048).
lib.rs — thin translation layer that:
- Accepts JsValue from JavaScript (nodes, edges, options)
- Converts to Graph via wasm_bind::graph_from_js
- Calls cognicode_graph_algos::{page_rank, god_nodes}
- Translates usize-indexed results back to node-id keys
- Returns JsValue via wasm_bind::to_value
wasm_bind.rs — JsValue<->Rust conversion (wasm32 only):
- from_value, graph_from_js, to_value, *_from_js helpers
- Uses serde-wasm-bindgen for direct JsValue conversion
tests/wire_format.rs — 9 native tests covering:
- PageRankOutput round-trip (BTreeMap ordering)
- GodNodesOutput round-trip
- Default values for PageRankOptions and GodNodesOptions
- JsonNode label serialization
All wasm32-only deps (wasm-bindgen, serde-wasm-bindgen) are gated
behind target_arch=wasm32 to keep native builds clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Create
cognicode-graph-wasm— a thin wasm-bindgen shim that wrapscognicode-graph-algospure functions (pagerank,god_nodes) for browser consumption.Scope
Files created:
crates/cognicode-graph-wasm/Cargo.tomlcrates/cognicode-graph-wasm/src/lib.rs— 2 wasm-bindgen exportscrates/cognicode-graph-wasm/src/protocol.rs— serde request/response typescrates/cognicode-graph-wasm/src/wasm_bind.rs— JsValue<->Rust translation (wasm32)crates/cognicode-graph-wasm/tests/wire_format.rs— 9 wire format testsFiles modified:
Cargo.toml— added wasm-bindgen 0.2, serde-wasm-bindgen 0.6, cognicode-graph-wasm memberKey Design Decisions
pagerankandgod_nodesare delegates tocognicode_graph_algos::{page_rank, god_nodes}. No algorithm logic in this crate (ADR-047 §1 + ADR-048).JsonGraphadapter fromcognicode-graph-algos(single-source, not a duplicate implementation).wasm-bindgen,serde-wasm-bindgenonly compiled for wasm32 target; native builds stay clean.serdeas unconditional dep: needed by protocol types on both targets (tests + wasm32).Validation
cargo check -p cognicode-graph-wasm(native)cargo test -p cognicode-graph-wasmcargo check --target wasm32-unknown-unknownwasm-pack build --target web --releasecargo fmt --checkcargo clippy -p cognicode-graph-wasm -p cognicode-graph-algoswasm-pack output
PR chain
0795ce0)e203eff)feat/graph-wasm-shimuseGraphAlgorithmshookMerge
Admin bypass — CI workflows removed per user decision in PR #21.