| 223 | /// console.log(credits_mappings === expected_mappings); // Output should be "true" |
| 224 | #[wasm_bindgen(js_name = "getMappings")] |
| 225 | pub fn get_mappings(&self) -> Result<Array, String> { |
| 226 | let mappings = Array::new(); |
| 227 | |
| 228 | // Set the mapping name and key/value names & types |
| 229 | self.0.mappings().iter().try_for_each(|(name, mapping)| { |
| 230 | let mapping_object = Object::new(); |
| 231 | Reflect::set(&mapping_object, &"name".into(), &name.to_string().into()) |
| 232 | .map_err(|_| "Failed to set property")?; |
| 233 | Reflect::set(&mapping_object, &"key_type".into(), &mapping.key().plaintext_type().to_string().into()) |
| 234 | .map_err(|_| "Failed to set property")?; |
| 235 | Reflect::set(&mapping_object, &"value_type".into(), &mapping.value().plaintext_type().to_string().into()) |
| 236 | .map_err(|_| "Failed to set property")?; |
| 237 | mappings.push(&mapping_object); |
| 238 | Ok::<(), String>(()) |
| 239 | })?; |
| 240 | Ok(mappings) |
| 241 | } |
| 242 | |
| 243 | // Get the value of a plaintext input as a javascript object (this function is not part of the |
| 244 | // public API) |