Skip to content

Commit

Permalink
Merge pull request #54 from polywrap/nerfzael-features-and-fixes
Browse files Browse the repository at this point in the history
JS wraps with shims, aliasing urls and readme updates
  • Loading branch information
nerfZael authored Sep 18, 2023
2 parents bfaa3ad + bf873b2 commit f4be08d
Show file tree
Hide file tree
Showing 20 changed files with 2,879 additions and 113 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

60 changes: 3 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,63 +20,9 @@ Then, to install `pwr`, run:
```bash
pwrup
```
## Script WRAPS (JS and Python)
{lang} = js | py

### REPL
`pwr {lang} repl`
Runs a REPL where you can type scripts.

`pwr {lang} repl -f {name_of_file}`
Runs the repl over a file.
It will read and execute the file first (and create it if it doesn't exist).
It will also store all CLI commands you type inside of it (after evaluating them).
Press enter in the CLI to re-run the whole file (useful if you want to code in the file instead of the CLI).

`pwr {lang} repl -f {name_of_file} -w`
It will read and execute the file first (and create it if it doesn't exist).
Then it will execute the file every time you save it.
It will not listen to CLI input if you use this option ("-w").

### New
`pwr {lang} new -f {name_of_file}`
Creates a new file of the specified name for the script wrap.
It uses a template for that language.

### Build
`pwr {lang} build -f {name_of_file}`
Builds the target script file.

### Deploy
`pwr deploy`
Deploys the build directory.

`pwr {lang} deploy`
Deploys the build directory. (Same as `pwr deploy`)

`pwr {lang} deploy -f {name_of_file}`
Builds and then deploys the script file.

## TODO: Examples PWR app usage:
Input: `pwr wrap://ens/wrap-echo.eth Hello world!`
Output: `Hello world!`

Input: `pwr ens/wrap-echo.eth Hello world!`
Output: `Hello world!`

Input: `pwr wrap-echo.eth Hello world!`
Output: `Hello world!`

Input: `pwr wrap://ipfs/QmebzauKAXoYbywLAYdBvKyPhWsDoHfkUC4wffWvjighKT Hello world!`
Output: `Hello world!`

Input: `pwr ipfs/QmebzauKAXoYbywLAYdBvKyPhWsDoHfkUC4wffWvjighKT Hello world!`
Output: `Hello world!`

Input: `pwr ipfs://QmebzauKAXoYbywLAYdBvKyPhWsDoHfkUC4wffWvjighKT Hello world!`
Output: `Hello world!`

Input: `pwr QmebzauKAXoYbywLAYdBvKyPhWsDoHfkUC4wffWvjighKT Hello world!`
Output: `Hello world!`
[Example PWR Usage](./docs/pwr-usage.md)

[Example PWR Apps](./docs/pwr-apps.md)

[Script WRAPS Guide](./docs/script-wraps.md)
7 changes: 7 additions & 0 deletions docs/pwr-apps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# PWR App Examples

- [Simple PWR App](../examples/simple-pwr-app/README.md)
- [Simple Storage App](../examples/simple-storage-app/README.md)
- [HTTP Server App](../examples/http-server-app/README.md)
- [Advanced HTTP Server App](../examples/app-with-ui/README.md)
- [PWR App with UI](../examples/app-with-ui/README.md)
57 changes: 57 additions & 0 deletions docs/pwr-usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Example PWR CLI usage:

## Migration
After running `pwrup`, you have to run `pwr migrate` to migrate your configuration to the latest version.

## Running pwr apps

### From wrapscan.io
To run a pwr app from wrapscan.io, run:
```bash
pwr wrapscan.io/pwr/say-hello
```

### From wrappers.dev
To run a pwr app from wrappers.dev, run:
```bash
pwr @pwr/say-hello
```
```bash
pwr https/wrappers.dev/u/pwr/say-hello
```

### Local directory
To run a pwr app from a local directory (e.g. `./build`), run:
```bash
pwr ./build
```
```bash
pwr fs/build
```

### From IPFS
To run a pwr app from IPFS, run:
```bash
pwr ipfs/Qm...
```
```bash
pwr Qm...
```
```bash
pwr ipfs://Qm...
```

### From ENS
To run a pwr app from ENS, run:
```bash
pwr ens/say-hello.eth
```
```bash
pwr say-hello.eth
```

## Passing arguments to pwr apps
To pass arguments to a pwr app add them after the WRAP URI, e.g.:
```bash
pwr ./build arg1 arg2
```
36 changes: 36 additions & 0 deletions docs/script-wraps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Script WRAPS (JS and Python)
{lang} = js | py

### REPL
`pwr {lang} repl`
Runs a REPL where you can type scripts.

`pwr {lang} repl -f {name_of_file}`
Runs the repl over a file.
It will read and execute the file first (and create it if it doesn't exist).
It will also store all CLI commands you type inside of it (after evaluating them).
Press enter in the CLI to re-run the whole file (useful if you want to code in the file instead of the CLI).

`pwr {lang} repl -f {name_of_file} -w`
It will read and execute the file first (and create it if it doesn't exist).
Then it will execute the file every time you save it.
It will not listen to CLI input if you use this option ("-w").

### New
`pwr {lang} new -f {name_of_file}`
Creates a new file of the specified name for the script wrap.
It uses a template for that language.

### Build
`pwr {lang} build -f {name_of_file}`
Builds the target script file.

### Deploy
`pwr deploy`
Deploys the build directory.

`pwr {lang} deploy`
Deploys the build directory. (Same as `pwr deploy`)

`pwr {lang} deploy -f {name_of_file}`
Builds and then deploys the script file.
32 changes: 17 additions & 15 deletions packages/plugins/http-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,25 +133,27 @@ async fn handle_request(
let body: Option<Vec<u8>> =
body::to_bytes(body).await.map(|x| x.to_vec()).ok();

let request = crate::types::Request {
headers: headers.into_iter().map(|(k, v)| KeyValuePair {
key: k.map(|x| x.to_string()).unwrap_or("".to_string()),
value: v.to_str().unwrap().to_string(),
}).collect(),
params: path_params.into_iter().map(|(k, v)| KeyValuePair {
key: k,
value: v,
}).collect(),
query: query_params.into_iter().map(|(k, v)| KeyValuePair {
key: k,
value: v,
}).collect(),
body: body.map(|x| ByteBuf::from(x))
};

let result = deps.invoker.invoke_raw(
&uri,
&method,
Some(&to_vec(&RequestArgs {
request: crate::types::Request {
headers: headers.into_iter().map(|(k, v)| KeyValuePair {
key: k.map(|x| x.to_string()).unwrap_or("".to_string()),
value: v.to_str().unwrap().to_string(),
}).collect(),
params: path_params.into_iter().map(|(k, v)| KeyValuePair {
key: k,
value: v,
}).collect(),
query: query_params.into_iter().map(|(k, v)| KeyValuePair {
key: k,
value: v,
}).collect(),
body: body.map(|x| ByteBuf::from(x))
}
request
}).unwrap()),
None,
).unwrap();
Expand Down
4 changes: 3 additions & 1 deletion packages/pwr/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,11 @@ fn parse_uri(uri: &String) -> Result<Uri, StringError> {
Uri::try_from(format!("wrap://ipfs/{}", &uri["ipfs://".len()..uri.len()])).map_err_str()?
} else if uri.starts_with('.') || uri.starts_with('/') {
Uri::try_from(format!("wrap://file/{}", uri)).map_err_str()?
} else if uri.starts_with("@") {
Uri::try_from(format!("wrap://https/http.wrappers.dev/u/{}", &uri[1..uri.len()])).map_err_str()?
} else if !uri.contains('/') {
Uri::try_from(format!("wrap://pwr/{}", uri)).map_err_str()?
} else {
} else {
Uri::try_from(uri.clone()).map_err_str()?
};

Expand Down
Loading

0 comments on commit f4be08d

Please sign in to comment.