-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add some WASM APIs - Provide metadata info in `ls` - Expose `base_history_on` function - Expose `load` function * Fix type error * Fix tests * Replace hardcoded `3.0.0` version with loaded version Co-authored-by: appcypher <[email protected]> * Use `wasm-pack build --target web` * Implement and use `From<UnixFsNodeKind> for String` * Fix TryInto<JsValue> for JsMetadata * Add `type: module` and `main: wasm_wnfs.js` entries Co-authored-by: appcypher <[email protected]>
- Loading branch information
Showing
6 changed files
with
117 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use crate::fs::JsResult; | ||
use crate::value; | ||
use js_sys::{Object, Reflect}; | ||
use wasm_bindgen::JsValue; | ||
use wnfs::{Metadata, UnixFsMetadata}; | ||
|
||
pub(crate) struct JsMetadata<'a>(pub(crate) &'a Metadata); | ||
|
||
impl TryInto<JsValue> for JsMetadata<'_> { | ||
type Error = js_sys::Error; | ||
|
||
fn try_into(self) -> JsResult<JsValue> { | ||
let metadata = Object::new(); | ||
let unix_meta = unix_fs_to_js_value(&self.0.unix_fs)?; | ||
let version = value!(self.0.version.to_string()); | ||
|
||
Reflect::set(&metadata, &value!("unixMeta"), &unix_meta)?; | ||
Reflect::set(&metadata, &value!("version"), &version)?; | ||
|
||
Ok(value!(metadata)) | ||
} | ||
} | ||
|
||
fn unix_fs_to_js_value(unix_fs: &UnixFsMetadata) -> JsResult<JsValue> { | ||
let obj = Object::new(); | ||
let kind = value!(String::from(&unix_fs.kind)); | ||
|
||
Reflect::set(&obj, &value!("created"), &value!(unix_fs.created))?; | ||
Reflect::set(&obj, &value!("modified"), &value!(unix_fs.modified))?; | ||
Reflect::set(&obj, &value!("mode"), &value!(unix_fs.mode.clone() as u32))?; | ||
Reflect::set(&obj, &value!("kind"), &kind)?; | ||
|
||
Ok(value!(obj)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
mod blockstore; | ||
mod metadata; | ||
mod public; | ||
mod types; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters