Skip to content

Commit

Permalink
Fix node build, wnfs script and bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
appcypher committed May 23, 2022
1 parent 7db77df commit 8cb532b
Show file tree
Hide file tree
Showing 11 changed files with 215 additions and 84 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 17 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ A goal of the project is to be easily compiled to WebAssembly to be used in the

Creating a new public directory.

```rs
```rust
use wnfs::{PublicDirectory, Id};
use chrono::Utc;

Expand All @@ -55,7 +55,7 @@ println!("id = {}", dir.get_id());

The in-memory files and directories you create with `wnfs` will need to be sealed and stored somewhere. For that, an object that implements the BlockStore trait like [this one](https://github.com/WebNativeFileSystem/rs-wnfs/blob/8bb0fbb457051295f1ed4a4707dc230c04612658/crates/fs/common/blockstore.rs#L42-L62) can be used.

```rs
```rust
use wnfs::{PublicDirectory, MemoryBlockStore, ipld::Cid};
use chrono::Utc;

Expand All @@ -69,7 +69,7 @@ The WNFS API is immutable, therefore, we need to keep track of the updated root

Each fs operation returns a possibly updated root directory that subsequent changes can be applied on.

```rs
```rust
// ...

let dir = Rc::new(dir);
Expand Down Expand Up @@ -169,9 +169,9 @@ let OpResult { result, .. } = root_dir

</details>

- **The _wnfs_ Helper Script**
- **The _wnfs_ Command**

If you are on a Unix platform, you can optionally install the `wnfs` script.
You can optionally set up the `wnfs` script.

<details>
<summary>Read more</summary>
Expand All @@ -182,7 +182,7 @@ let OpResult { result, .. } = root_dir
sh script/wnfs.sh setup
```

- This lets you run the `wnfs.sh` script with just the `wnfs` command.
- This lets you run the `wnfs.sh` script as a command.

```bash
wnfs help
Expand All @@ -206,20 +206,28 @@ let OpResult { result, .. } = root_dir

- Build the project

Check [REQUIREMENTS](#requirements) on how to set up the `wnfs` command.

```bash
wnfs build --all
```

- You can also build for specific crates

```bash
sh scripts/wnfs.sh build
wnfs build --wasm
```

## Testing the Project

- Run all tests

```bash
sh scripts/wnfs.sh test
wnfs test --all
```

- Show code coverage

```bash
sh scripts/wnfs.sh coverage
wnfs coverage
```
4 changes: 2 additions & 2 deletions crates/fs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wnfs"
version = "0.1.2"
version = "0.1.5"
description = "WebNative filesystem core implementation"
keywords = ["wnfs", "webnative", "ipfs", "decentralisation"]
categories = [
Expand All @@ -10,7 +10,7 @@ categories = [
"wasm",
]
license-file = "../../LICENSE"
readme = "README.md"
readme = "Apache-2.0"
edition = "2021"
repository = "https://github.com/WebNativeFileSystem/rs-wnfs/tree/main/crates/fs"
homepage = "https://fission.codes"
Expand Down
8 changes: 3 additions & 5 deletions crates/fs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
</p>
</div>

<div align="center"><sub>:warning: Work in progress :warning:</sub></div>

##

This crate is a Rust implementation of the primitives for creating and manipulating IPLD graphs that encode WNFS.
Expand All @@ -45,7 +43,7 @@ A goal of the project is to be easily compiled to WebAssembly to be used in the

Creating a new public directory.

```rs
```rust
use wnfs::{PublicDirectory, Id};
use chrono::Utc;

Expand All @@ -55,7 +53,7 @@ println!("id = {}", dir.get_id());

The in-memory files and directories you create with `wnfs` will need to be sealed and stored somewhere. For that, an object that implements the BlockStore trait like [this one](https://github.com/WebNativeFileSystem/rs-wnfs/blob/8bb0fbb457051295f1ed4a4707dc230c04612658/crates/fs/common/blockstore.rs#L42-L62) can be used.

```rs
```rust
use wnfs::{PublicDirectory, MemoryBlockStore, ipld::Cid};
use chrono::Utc;

Expand All @@ -69,7 +67,7 @@ The WNFS API is immutable, therefore, we need to keep track of the updated root

Each fs operation returns a possibly updated root directory that subsequent changes can be applied on.

```rs
```rust
// ...

let dir = Rc::new(dir);
Expand Down
8 changes: 3 additions & 5 deletions crates/wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[package]
name = "wasm-wnfs"
version = "0.1.2"
description = "WebNative filesystem WebAssembly API"
version = "0.1.5"
description = "WebNative Filesystem API (WebAssembly)"
keywords = ["wnfs", "webnative", "ipfs", "decentralisation"]
categories = [
"filesystem",
"cryptography",
"web-programming",
"wasm",
]
license-file = "LICENSE"
license = "Apache-2.0"
readme = "README.md"
edition = "2021"
repository = "https://github.com/WebNativeFileSystem/rs-wnfs/tree/main/crates/wasm"
Expand All @@ -18,8 +18,6 @@ authors = ["The Fission Authors"]

[dependencies]
wnfs = { path = "../fs", version = "0.1.0" }
# serde_json = "1.0"
# serde = { version = "1.0", features = ["derive"] }
wasm-bindgen = { version = "0.2", optional = true, features = ["serde-serialize"] }
wasm-bindgen-futures = { version = "0.4", optional = true }
js-sys = { version = "0.3", optional = true }
Expand Down
24 changes: 13 additions & 11 deletions crates/wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The core of this project is a WebAssembly binary compiled from the [Rust source
## Outline

- [Usage](#usage)
- [Building the Project](#building-the-project)
- [Setting up the project](#setting-up-the-project)
- [Testing the Project](#testing-the-project)
- [Publishing Package](#publishing-package)

Expand Down Expand Up @@ -75,15 +75,21 @@ var { rootDir } = await rootDir.rm(["pictures", "cats"], store);
var { result } = await rootDir.ls(["pictures"], store);
```

## Building the Project
## Setting up the Project

- Install `wasm-pack`

```bash
cargo install wasm-pack
```

- Install playwrigth binaries
- Install dependencies

```bash
yarn
```

- Install playwright binaries

```bash
npx playwright install
Expand All @@ -92,7 +98,7 @@ var { result } = await rootDir.ls(["pictures"], store);
- Build project

```bash
wasm-pack build --target web
wasm-pack build
```

## Testing the Project
Expand All @@ -105,18 +111,14 @@ var { result } = await rootDir.ls(["pictures"], store);

## Publishing Package

- Generate the compilation artifacts in `pkg` directory
- Build the project

```bash
wasm-pack init
wnfs build --wasm
```

- Publish from the `pkg` directory

```bash
cd pkg
```

```bash
npm publish --access=public
wasm-pack publish --nodejs
```
21 changes: 0 additions & 21 deletions crates/wasm/package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
{
"name": "wnfs",
"version": "0.1.1",
"homepage": "https://guide.fission.codes",
"license": "Apache-2.0",
"author": {
"name": "Stephen Akinyemi",
"email": "[email protected]"
},
"keywords": [
"wnfs",
"web",
"webnative",
"filesystem",
"cryptography",
"web-programming",
"wasm"
],
"repository": {
"type": "git",
"url": "https://github.com/WebNativeFileSystem/rs-wnfs/tree/main/crates/wasm"
},
"devDependencies": {
"@playwright/test": "^1.21.1",
"@wasm-tool/wasm-pack-plugin": "^1.6.0",
Expand Down
11 changes: 11 additions & 0 deletions crates/wasm/test-wnfs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { MemoryBlockStore } from "./store.js";
import { PublicDirectory } from "wnfs";

const time = new Date();
const dir = new PublicDirectory(time);
const store = new MemoryBlockStore();

// Create a /pictures/cats directory.
var { rootDir } = await dir.mkdir(["pictures", "cats"], time, store);

console.log("Root Id =", rootDir.getId());
11 changes: 11 additions & 0 deletions crates/wasm/test-wnfs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "test",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"multiformats": "^9.6.5",
"wnfs": "../pkg/"
},
"type": "module"
}
36 changes: 36 additions & 0 deletions crates/wasm/test-wnfs/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { CID } from "multiformats/cid";
import { sha256 } from "multiformats/hashes/sha2";

/** A mock CID. */
const sampleCID = CID.parse(
"bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea"
).bytes;

/**
* An in-memory block store to simulate IPFS.
*
* IPFS is basically a glorified HashMap.
*/
class MemoryBlockStore {
// private store: Map<string, Uint8Array>;

/** Creates a new in-memory block store. */
constructor() {
this.store = new Map();
}

/** Stores an array of bytes in the block store. */
async getBlock(cid) {
const decoded_cid = CID.decode(cid);
return this.store.get(decoded_cid.toString());
}

/** Retrieves an array of bytes from the block store with given CID. */
async putBlock(bytes, code) {
const hash = await sha256.digest(bytes);
const cid = CID.create(1, code, hash);
this.store.set(cid.toString(), bytes);
}
}

export { sampleCID, MemoryBlockStore };
Loading

0 comments on commit 8cb532b

Please sign in to comment.