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