Skip to content

Commit

Permalink
Fix wasm apis
Browse files Browse the repository at this point in the history
  • Loading branch information
appcypher committed Aug 25, 2022
1 parent b2eb6c2 commit e3f9a1e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
36 changes: 29 additions & 7 deletions crates/wasm/fs/private/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ impl PrivateDirectory {
pub fn get_node(
&self,
path_segments: &Array,
search_latest: bool,
hamt: PrivateForest,
store: BlockStore,
) -> JsResult<Promise> {
Expand All @@ -80,7 +81,7 @@ impl PrivateDirectory {
hamt,
result,
} = directory
.get_node(&path_segments, hamt.0, &store)
.get_node(&path_segments, search_latest, hamt.0, &store)
.await
.map_err(error("Cannot get node"))?;

Expand All @@ -97,6 +98,7 @@ impl PrivateDirectory {
pub fn lookup_node(
&self,
path_segment: &str,
search_latest: bool,
hamt: PrivateForest,
store: BlockStore,
) -> JsResult<Promise> {
Expand All @@ -106,7 +108,7 @@ impl PrivateDirectory {

Ok(future_to_promise(async move {
let found_node = directory
.lookup_node(&path_segment, &hamt.0, &store)
.lookup_node(&path_segment, search_latest, &hamt.0, &store)
.await
.map_err(error("Cannot lookup node"))?;

Expand All @@ -118,6 +120,7 @@ impl PrivateDirectory {
pub fn read(
&self,
path_segments: &Array,
search_latest: bool,
hamt: PrivateForest,
store: BlockStore,
) -> JsResult<Promise> {
Expand All @@ -131,7 +134,7 @@ impl PrivateDirectory {
hamt,
result,
} = directory
.read(&path_segments, hamt.0, &store)
.read(&path_segments, search_latest, hamt.0, &store)
.await
.map_err(error("Cannot read from directory"))?;

Expand All @@ -147,6 +150,7 @@ impl PrivateDirectory {
pub fn ls(
&self,
path_segments: &Array,
search_latest: bool,
hamt: PrivateForest,
store: BlockStore,
) -> JsResult<Promise> {
Expand All @@ -160,7 +164,7 @@ impl PrivateDirectory {
hamt,
result,
} = directory
.ls(&path_segments, hamt.0, &store)
.ls(&path_segments, search_latest, hamt.0, &store)
.await
.map_err(error("Cannot list directory children"))?;

Expand All @@ -177,6 +181,7 @@ impl PrivateDirectory {
pub fn rm(
&self,
path_segments: &Array,
search_latest: bool,
hamt: PrivateForest,
store: BlockStore,
mut rng: Rng,
Expand All @@ -191,7 +196,7 @@ impl PrivateDirectory {
hamt,
result: node,
} = directory
.rm(&path_segments, hamt.0, &mut store, &mut rng)
.rm(&path_segments, search_latest, hamt.0, &mut store, &mut rng)
.await
.map_err(error("Cannot remove from directory"))?;

Expand All @@ -207,6 +212,7 @@ impl PrivateDirectory {
pub fn write(
&self,
path_segments: &Array,
search_latest: bool,
content: Vec<u8>,
time: &Date,
hamt: PrivateForest,
Expand All @@ -220,7 +226,15 @@ impl PrivateDirectory {

Ok(future_to_promise(async move {
let WnfsPrivateOpResult { root_dir, hamt, .. } = directory
.write(&path_segments, time, content, hamt.0, &mut store, &mut rng)
.write(
&path_segments,
search_latest,
time,
content,
hamt.0,
&mut store,
&mut rng,
)
.await
.map_err(error("Cannot write to directory"))?;

Expand All @@ -238,6 +252,7 @@ impl PrivateDirectory {
pub fn mkdir(
&self,
path_segments: &Array,
search_latest: bool,
time: &Date,
hamt: PrivateForest,
store: BlockStore,
Expand All @@ -250,7 +265,14 @@ impl PrivateDirectory {

Ok(future_to_promise(async move {
let WnfsPrivateOpResult { root_dir, hamt, .. } = directory
.mkdir(&path_segments, time, hamt.0, &mut store, &mut rng)
.mkdir(
&path_segments,
search_latest,
time,
hamt.0,
&mut store,
&mut rng,
)
.await
.map_err(error("Cannot create directory: {e}"))?;

Expand Down
21 changes: 13 additions & 8 deletions crates/wasm/tests/private.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ test.describe("PrivateDirectory", () => {
new Date()
);

var { rootDir, hamt } = await root.write(["text.txt"], new Uint8Array([1, 2, 3, 4, 5]), new Date(), initialHamt, store, rng);
var { rootDir, hamt } = await root.write(["text.txt"], true, new Uint8Array([1, 2, 3, 4, 5]), new Date(), initialHamt, store, rng);

return await rootDir.lookupNode("text.txt", hamt, store);
return await rootDir.lookupNode("text.txt", true, hamt, store);
});

expect(result).toBeDefined();
Expand All @@ -53,7 +53,7 @@ test.describe("PrivateDirectory", () => {
new Date()
);

return await root.lookupNode("Unknown", initialHamt, store);
return await root.lookupNode("Unknown", true, initialHamt, store);
});

expect(result).toBe(undefined);
Expand All @@ -76,10 +76,11 @@ test.describe("PrivateDirectory", () => {
new Date()
);

var { rootDir, hamt } = await root.mkdir(["pictures", "cats"], new Date(), initialHamt, store, rng);
var { rootDir, hamt } = await root.mkdir(["pictures", "cats"], true, new Date(), initialHamt, store, rng);

var { rootDir, hamt } = await rootDir.write(
["pictures", "cats", "tabby.png"],
true,
new Uint8Array([1, 2, 3, 4, 5]),
new Date(),
hamt,
Expand All @@ -89,6 +90,7 @@ test.describe("PrivateDirectory", () => {

var { rootDir } = await rootDir.getNode(
["pictures", "cats", "tabby.png"],
true,
hamt,
store
);
Expand Down Expand Up @@ -116,18 +118,19 @@ test.describe("PrivateDirectory", () => {
new Date()
);

var { rootDir, hamt } = await root.mkdir(["pictures", "dogs"], new Date(), initialHamt, store, rng);
var { rootDir, hamt } = await root.mkdir(["pictures", "dogs"], true, new Date(), initialHamt, store, rng);

var { rootDir, hamt } = await rootDir.write(
["pictures", "cats", "tabby.png"],
true,
new Uint8Array([1, 2, 3, 4, 5]),
new Date(),
hamt,
store,
rng,
);

var { result } = await rootDir.ls(["pictures"], hamt, store);
var { result } = await rootDir.ls(["pictures"], true, hamt, store);

return result;
});
Expand Down Expand Up @@ -156,6 +159,7 @@ test.describe("PrivateDirectory", () => {

var { rootDir, hamt } = await root.write(
["pictures", "dogs", "billie.jpeg"],
true,
new Uint8Array([1, 2, 3, 4, 5]),
new Date(),
initialHamt,
Expand All @@ -165,14 +169,15 @@ test.describe("PrivateDirectory", () => {

var { rootDir, hamt } = await rootDir.write(
["pictures", "cats", "tabby.png"],
true,
new Uint8Array([1, 2, 3, 4, 5]),
new Date(),
hamt,
store,
rng,
);
var { rootDir, hamt } = await rootDir.rm(["pictures", "cats"], hamt, store, rng);
var { result } = await rootDir.ls(["pictures"], hamt, store);
var { rootDir, hamt } = await rootDir.rm(["pictures", "cats"], true, hamt, store, rng);
var { result } = await rootDir.ls(["pictures"], true, hamt, store);

return result;
});
Expand Down

0 comments on commit e3f9a1e

Please sign in to comment.