Skip to content

Commit

Permalink
Refactor getCandidAdapter method in CandidAdapter class
Browse files Browse the repository at this point in the history
  • Loading branch information
b3hr4d committed Apr 27, 2024
1 parent 5d30e3c commit e597d38
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/classes/adapter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,6 @@ export class CandidAdapter {
throw new Error("Parser module not available")
}

return this.parserModule.did_to_js(candidSource)
return this.parserModule.didToJs(candidSource)
}
}
17 changes: 15 additions & 2 deletions packages/parser/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use candid_parser::{check_prog, IDLProg, TypeEnv};
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
#[wasm_bindgen(js_name = didToJs)]
pub fn did_to_js(prog: String) -> Result<String, String> {
let ast = prog.parse::<IDLProg>().map_err(|e| e.to_string())?;
let mut env = TypeEnv::new();
Expand All @@ -12,7 +12,7 @@ pub fn did_to_js(prog: String) -> Result<String, String> {
Ok(res)
}

#[wasm_bindgen]
#[wasm_bindgen(js_name = didToTs)]
pub fn did_to_ts(prog: String) -> Result<String, String> {
let ast = prog.parse::<IDLProg>().map_err(|e| e.to_string())?;
let mut env = TypeEnv::new();
Expand All @@ -22,3 +22,16 @@ pub fn did_to_ts(prog: String) -> Result<String, String> {

Ok(res)
}

#[wasm_bindgen(js_name = verifyCompatability)]
pub fn verify_compatability(a: String, b: String) -> Result<bool, String> {
let a = candid_parser::utils::CandidSource::Text(&a);
let b = candid_parser::utils::CandidSource::Text(&b);

let res = candid_parser::utils::service_compatible(a, b);

match res {
Ok(_) => Ok(true),
Err(e) => Err(e.to_string()),
}
}

0 comments on commit e597d38

Please sign in to comment.