1mod error;
31mod parser;
32mod query;
33mod store;
34
35use wasm_bindgen::prelude::*;
36
37pub use error::WasmError;
38pub use store::OxiRSStore;
39
40#[wasm_bindgen(start)]
42pub fn init() {
43 console_error_panic_hook::set_once();
44}
45
46#[wasm_bindgen]
48#[derive(Debug, Clone)]
49pub struct Triple {
50 subject: String,
51 predicate: String,
52 object: String,
53}
54
55#[wasm_bindgen]
56impl Triple {
57 #[wasm_bindgen(constructor)]
58 pub fn new(subject: &str, predicate: &str, object: &str) -> Self {
59 Self {
60 subject: subject.to_string(),
61 predicate: predicate.to_string(),
62 object: object.to_string(),
63 }
64 }
65
66 #[wasm_bindgen(getter)]
67 pub fn subject(&self) -> String {
68 self.subject.clone()
69 }
70
71 #[wasm_bindgen(getter)]
72 pub fn predicate(&self) -> String {
73 self.predicate.clone()
74 }
75
76 #[wasm_bindgen(getter)]
77 pub fn object(&self) -> String {
78 self.object.clone()
79 }
80}
81
82#[wasm_bindgen]
84pub struct QueryResult {
85 bindings: Vec<JsValue>,
86}
87
88#[wasm_bindgen]
89impl QueryResult {
90 #[wasm_bindgen(getter)]
91 pub fn bindings(&self) -> Vec<JsValue> {
92 self.bindings.clone()
93 }
94
95 #[wasm_bindgen(getter)]
96 pub fn length(&self) -> usize {
97 self.bindings.len()
98 }
99}
100
101#[wasm_bindgen]
103pub fn version() -> String {
104 env!("CARGO_PKG_VERSION").to_string()
105}
106
107#[wasm_bindgen]
109pub fn log(message: &str) {
110 web_sys::console::log_1(&message.into());
111}
112
113#[cfg(test)]
114mod tests {
115 use super::*;
116
117 #[test]
118 fn test_triple() {
119 let triple = Triple::new("http://a", "http://b", "http://c");
120 assert_eq!(triple.subject(), "http://a");
121 assert_eq!(triple.predicate(), "http://b");
122 assert_eq!(triple.object(), "http://c");
123 }
124}