use wasm_bindgen::prelude::*;
use crate::manifest::ManifestSource;
fn js_err(e: crate::Error) -> JsError {
JsError::new(&e.to_string())
}
#[wasm_bindgen(js_name = embedManifest)]
pub fn embed_manifest(model: &[u8], store: &[u8]) -> Result<Vec<u8>, JsError> {
crate::embed_manifest(model, &ManifestSource::embedded(store.to_vec())).map_err(js_err)
}
#[wasm_bindgen(js_name = embedManifestRemote)]
pub fn embed_manifest_remote(model: &[u8], uri: &str) -> Result<Vec<u8>, JsError> {
crate::embed_manifest(model, &ManifestSource::remote(uri)).map_err(js_err)
}
#[wasm_bindgen(js_name = embedManifestBoth)]
pub fn embed_manifest_both(model: &[u8], uri: &str, store: &[u8]) -> Result<Vec<u8>, JsError> {
crate::embed_manifest(model, &ManifestSource::both(uri, store.to_vec())).map_err(js_err)
}
#[wasm_bindgen(js_name = readManifest)]
pub fn read_manifest(model: &[u8]) -> Result<Vec<u8>, JsError> {
crate::read_manifest(model).map_err(js_err)
}
#[wasm_bindgen(js_name = readManifestUri)]
pub fn read_manifest_uri(model: &[u8]) -> Result<Option<String>, JsError> {
crate::read_manifest_uri(model).map_err(js_err)
}
#[wasm_bindgen(js_name = removeManifest)]
pub fn remove_manifest(model: &[u8]) -> Result<Vec<u8>, JsError> {
crate::remove_manifest(model).map_err(js_err)
}
#[wasm_bindgen(js_name = detectFormat)]
pub fn detect_format(model: &[u8]) -> Option<String> {
crate::Format::detect(model).map(|f| f.name().to_string())
}
#[wasm_bindgen(js_name = modelType)]
pub fn model_type(model: &[u8]) -> Option<String> {
crate::Format::detect(model).map(|f| f.model_type().as_str().to_string())
}