| Crates.io | oxirs-wasm |
| lib.rs | oxirs-wasm |
| version | 0.1.0 |
| created_at | 2025-12-26 14:47:57.403021+00 |
| updated_at | 2026-01-20 21:04:24.146659+00 |
| description | WebAssembly bindings for OxiRS - Run RDF/SPARQL in the browser |
| homepage | https://github.com/cool-japan/oxirs |
| repository | https://github.com/cool-japan/oxirs |
| max_upload_size | |
| id | 2005809 |
| size | 78,491 |
WebAssembly bindings for OxiRS - Run RDF/SPARQL in the browser
Lightweight RDF and SPARQL implementation compiled to WebAssembly for browser, Node.js, and edge deployment.
npm install oxirs-wasm
[dependencies]
oxirs-wasm = "0.1"
import { initialize, createStore } from 'oxirs-wasm';
// Initialize WASM module
await initialize();
// Create RDF store
const store = await createStore();
// Load Turtle data
const turtle = `
@prefix : <http://example.org/> .
:alice :knows :bob .
:bob :name "Bob" .
`;
const count = await store.loadTurtle(turtle);
console.log(`Loaded ${count} triples`);
// Execute SPARQL query
const results = await store.query(`
SELECT ?person ?name WHERE {
?person :name ?name .
}
`);
console.log(results);
// [{ person: "http://example.org/bob", name: "\"Bob\"" }]
// ASK query
const exists = await store.ask(`
ASK { :alice :knows :bob }
`);
console.log('Alice knows Bob:', exists); // true
// Export to N-Triples
const ntriples = store.toNTriples();
console.log(ntriples);
<!DOCTYPE html>
<html>
<head>
<title>RDF in Browser</title>
</head>
<body>
<script type="module">
import { initialize, createStore } from './pkg/oxirs_wasm.js';
async function run() {
await initialize();
const store = await createStore();
await store.loadTurtle(`
@prefix : <http://example.org/> .
:alice :knows :bob .
`);
const results = await store.query(
'SELECT ?s ?o WHERE { ?s :knows ?o }'
);
console.log('Results:', results);
}
run();
</script>
</body>
</html>
# Install wasm-pack
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
# Build WASM package
cd platforms/oxirs-wasm
wasm-pack build --target web --release
# The output will be in pkg/
# - oxirs_wasm.js (ES module)
# - oxirs_wasm_bg.wasm (binary)
# - oxirs_wasm.d.ts (TypeScript types)
class OxiRSStore {
constructor();
// Load RDF data
loadTurtle(turtle: string): Promise<number>;
loadNTriples(ntriples: string): Promise<number>;
// Triple operations
insert(subject: string, predicate: string, object: string): boolean;
delete(subject: string, predicate: string, object: string): boolean;
contains(subject: string, predicate: string, object: string): boolean;
size(): number;
clear(): void;
// SPARQL queries
query(sparql: string): Promise<QueryResult[]>;
ask(sparql: string): Promise<boolean>;
construct(sparql: string): Promise<Triple[]>;
// Export
toTurtle(): string;
toNTriples(): string;
// Indexes
subjects(): string[];
predicates(): string[];
objects(): string[];
// Namespaces
addPrefix(prefix: string, uri: string): void;
}
<script type="module">
import init, { createStore } from './pkg/oxirs_wasm.js';
await init();
const store = await createStore();
</script>
const { initialize, createStore } = require('oxirs-wasm');
(async () => {
await initialize();
const store = await createStore();
// ...
})();
import { initialize, createStore } from 'oxirs-wasm';
export default {
async fetch(request: Request): Promise<Response> {
await initialize();
const store = await createStore();
// Process RDF data
const { rdf, sparql } = await request.json();
await store.loadTurtle(rdf);
const results = await store.query(sparql);
return new Response(JSON.stringify(results));
}
};
import { initialize, createStore } from 'https://esm.sh/oxirs-wasm';
Deno.serve(async (req) => {
await initialize();
const store = await createStore();
// ...
});
Current implementation focuses on core functionality:
For full SPARQL support, use the server-side oxirs-fuseki crate.
wasm-bindgen - JavaScript interopjs-sys - JavaScript standard library bindingsweb-sys - Web APIs (console, performance)getrandom - Random number generation (js feature)Licensed under either of Apache License, Version 2.0 or MIT license at your option.