Skip to main content

Crate purrdf_wasm

Crate purrdf_wasm 

Source
Expand description

§purrdf — a wasm32, in-memory RDF 1.2 engine with an idiomatic RDF/JS API

Parcel P10 of the purrdf program (docs/design/PurRDF-PLAN.md). This crate compiles the oxigraph-free, PyO3-free purrdf kernel to wasm32-unknown-unknown and exposes it to JavaScript/TypeScript through the RDF/JS community spec — DataFactory, DatasetCore, and Stream/Sink — packaged for npm/ESM as purrdf.

§Scope (by charter)

  • In-memory only. The oxigraph Store (RocksDB) and crates/logic do not compile to wasm and are deliberately excluded — this is the value-interned IR + the COW MutableDataset, not a persistent quad store.
  • Offline SPARQL. The native, oxigraph-free multiset evaluator (purrdf_sparql_eval) binds to the wasm Dataset (see the query module), so SELECT / ASK / CONSTRUCT / DESCRIBE run client-side with no server. Only the host can provide SERVICE federation; this default browser surface installs no remote source, so SERVICE / LOAD hard-fails here rather than silently returning a partial answer.
  • Separate from the C-ABI (P8). WASM has its own ownership model, packaging, and async I/O; it is not a C-ABI consumer and does not depend on the no_std track.

§The RDF-1.2 wedge

No incumbent RDF/JS library carries RDF-1.2 quoted-triple terms or directional literals. purrdf’s DataFactory accepts a quoted triple anywhere a term is expected (termType: "Quad" as subject/object) and round-trips base direction on literals — the deliberate “overcome, don’t inherit” extension to stock RDF/JS (.goals: SUBSUME, EXTEND, ENHANCE).

§Architecture

The #[wasm_bindgen] surface is a thin shim over purrdf seams that already exist: TermFactory (the DataFactory 1:1 map), DatasetMut/MutableDataset (the mutable DatasetCore), native_codecs (parse/serialize), and the purrdf-events protocol (the Stream/Sink). Mapping logic lives in plain Rust so it unit-tests on the native workspace gate; the wasm-bindgen wrappers are exercised as real wasm under wasm-pack test --node.

Modules§

shacl
SHACL validation → SARIF 2.1.0 for the wasm/JS surface.

Structs§

CompiledJsonLdContext
An immutable JSON-LD 1.1 context compiled once and reusable across datasets.
DataFactory
An RDF/JS DataFactory. Stateless except for the auto-generated blank-node counter (blankNode() with no argument mints a fresh label).
Dataset
An RDF/JS DatasetCore backed by the engine’s COW mutable dataset.
ProjectionLift
Result of lifting a strict carrier package into an in-memory RDF dataset.
ProjectionPackage
A deterministic USTAR projection package and its canonical runtime ledger.
Quad
An RDF/JS Quad — a statement (subject, predicate, object, graph) with termType: "Quad".
QueryEngine
A reusable SPARQL engine that keeps the native plan cache alive across calls.
QueryResult
A typed SPARQL result returned by the raw wasm binding.
SelectResult
A typed SELECT result returned by the raw wasm binding.
SelectRow
One SELECT binding row.
Sink
An RDF/JS Sink — a streaming consumer that interns pushed quads through the purrdf-events protocol and freezes them at finish().
Term
An RDF/JS Term.

Functions§

lift_projection
Lift a strict bidirectional USTAR package into an in-memory RDF dataset.
version
The purrdf engine version (the crate’s SemVer), exposed to JS as version().