Skip to content

Commit 14a7531

Browse files
Hotfix: Expose import media types through wasm bindings (#595)
Nemo Web was not able to set correct accept headers for resources loaded from e.g. sparql queries since the type of the resource was not exposed through the wasm bindings. This PR changes this. There is a corresponding PR in Nemo Web making use of this.
2 parents 4a99034 + 04a4254 commit 14a7531

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

nemo-wasm/src/lib.rs

+25-4
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ impl NemoError {
6868
}
6969
}
7070

71+
#[wasm_bindgen]
72+
pub struct NemoResource {
73+
accept: String,
74+
url: String,
75+
}
76+
77+
#[wasm_bindgen]
78+
impl NemoResource {
79+
pub fn accept(&self) -> String {
80+
self.accept.clone()
81+
}
82+
83+
pub fn url(&self) -> String {
84+
self.url.clone()
85+
}
86+
}
87+
7188
#[wasm_bindgen]
7289
impl NemoProgram {
7390
#[wasm_bindgen(constructor)]
@@ -95,16 +112,20 @@ impl NemoProgram {
95112
/// just make sure that things validate upon creation, and make sure that problems
96113
/// are detected early.
97114
#[wasm_bindgen(js_name = "getResourcesUsedInImports")]
98-
pub fn resources_used_in_imports(&self) -> Set {
99-
let js_set = Set::new(&JsValue::undefined());
115+
pub fn resources_used_in_imports(&self) -> Vec<NemoResource> {
116+
let mut result: Vec<NemoResource> = vec![];
100117

101118
for directive in self.0.imports() {
119+
let format = directive.file_format().media_type();
102120
if let Some(resource) = directive.attributes().get(&ImportExportAttribute::Resource) {
103-
js_set.add(&JsValue::from(resource.to_string()));
121+
result.push(NemoResource {
122+
accept: format.to_string(),
123+
url: resource.to_string(),
124+
});
104125
}
105126
}
106127

107-
js_set
128+
result
108129
}
109130

110131
// If there are no outputs, marks all predicates as outputs.

0 commit comments

Comments
 (0)