Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update wrap-0.1 Branch #15

Merged
merged 47 commits into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
8f0aa00
added wrap-rust bindings dir with helpers and tests
krisbitney Jun 28, 2023
2152e6a
Merge remote-tracking branch 'origin/dev' into kris/wrap-rust
krisbitney Jul 3, 2023
a034d07
Merge remote-tracking branch 'origin/dev' into kris/wrap-rust
krisbitney Jul 3, 2023
1606e13
added mod and entry for wrap-rust bindings
krisbitney Jul 3, 2023
733cbbf
added module type and object type bindings for wrap-rust, excluding s…
krisbitney Jul 3, 2023
7e7ab17
added interface type rust bindings
krisbitney Jul 3, 2023
9ff43e1
added enum and env type rust bindings
krisbitney Jul 3, 2023
84cf799
added import type rust bindings
krisbitney Jul 3, 2023
509735f
added serialization_imports partial to wrap-rust
krisbitney Jul 3, 2023
3c939a4
added wrap-rust templates and updated helpers
krisbitney Jul 5, 2023
81b7255
refactored map/array type detection logic into map_types and array_ty…
krisbitney Jul 5, 2023
f9e8472
updated deployments
krisbitney Jul 5, 2023
3bbaecd
removed partials dir from wrap-rust
krisbitney Jul 5, 2023
b6b7f4a
added wrap-rust deployment
krisbitney Jul 5, 2023
4615e1f
added wrap-rust deployment
krisbitney Jul 5, 2023
8f28be7
fixed wrap-rust dir names
krisbitney Jul 5, 2023
4e056a5
fix for wrap-rust module_rs.rs
krisbitney Jul 5, 2023
73cb189
various small fixes for wrap-rust
krisbitney Jul 5, 2023
47f4f11
added property_deps (untested)
krisbitney Jul 6, 2023
cbfe6ab
fixed typo in module_type/mod.rs template for wrap-rust
krisbitney Jul 6, 2023
1dca256
fixed polywrap_msgpack_rs imports in wrap-rust templates
krisbitney Jul 6, 2023
6b66389
fixed various typos in enum templates for wrap-rust
krisbitney Jul 6, 2023
db3044d
fixed typo in load_wrap_env import for wrap-rust
krisbitney Jul 6, 2023
13d3ce2
update to property_deps function in wrap-rust
krisbitney Jul 7, 2023
d978637
update to property_deps function in wrap-rust
krisbitney Jul 7, 2023
aad2911
replaced polywrap_client dependency with polywrap_msgpack_serde
krisbitney Jul 7, 2023
45df3f5
wrap-rust using updated polywrap_msgpack_serde
krisbitney Jul 10, 2023
d202e2c
wrap-rust using updated polywrap_msgpack_serde
krisbitney Jul 10, 2023
86a688d
wrap-rust using updated polywrap_msgpack_serde
krisbitney Jul 10, 2023
0f27e8e
wrap-rust using updated polywrap_msgpack_serde
krisbitney Jul 10, 2023
6ee89e1
wrap-rust using updated polywrap_msgpack_serde
krisbitney Jul 10, 2023
aad7527
wrap-rust using serde_rename_if_case_mismatch
krisbitney Jul 10, 2023
d5eb75c
wrap-rust using serde_rename_if_case_mismatch
krisbitney Jul 10, 2023
d291ca0
wrap-rust using serde_rename_if_case_mismatch
krisbitney Jul 10, 2023
fe31c57
updated plugin-typescript wrap to use new `wrap-rust` bindgen
krisbitney Jul 10, 2023
4acd393
fixed wrap-rust BigInt init
krisbitney Jul 11, 2023
cca1bdb
fixed wrap-rust "pub mod imported;" inclusion test
krisbitney Jul 11, 2023
ab5083d
reverted plugin-typescript to use rust bindings present in CLI
krisbitney Jul 11, 2023
8839804
updated wrap-rust test cases
krisbitney Jul 11, 2023
0438fa9
Merge remote-tracking branch 'origin/dev' into kris/wrap-rust
krisbitney Jul 12, 2023
500e423
adjusted import abi in wrap-rust polywrap.yaml
krisbitney Jul 12, 2023
82f842a
Merge pull request #5 from polywrap/kris/wrap-rust
krisbitney Jul 12, 2023
0cf9b83
adjusted cd git diff step
krisbitney Jul 12, 2023
abab021
Merge pull request #13 from polywrap/kris/fix-cd
krisbitney Jul 12, 2023
189c46c
Updated rust plugin bindings to use polywrap_msgpack_serde
namesty Jul 12, 2023
23cdbf1
Using serde annotations instead of wrapper types
namesty Jul 13, 2023
c3700a3
Merge pull request #14 from polywrap/namesty/rust-plugins-serde
dOrgJelli Jul 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ jobs:

- name: Check for changes in URI.txt
run: |
git add .
git diff --name-only | grep ^URI.txt$
echo "changed=$?" >> $GITHUB_ENV

- name: Commit files
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add .
git commit -m "Add deployments" -a
if: env.changed == 0

Expand Down Expand Up @@ -101,14 +101,14 @@ jobs:

- name: Check for changes in URI.txt
run: |
git add .
git diff --name-only | grep ^URI.txt$
echo "changed=$?" >> $GITHUB_ENV

- name: Commit files
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add .
git commit -m "Add deployments" -a
if: env.changed == 0

Expand Down
2 changes: 1 addition & 1 deletion implementations/app-typescript/URI.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
wrap://ipfs/QmNhvrKWXkkvLBknymaoGUpAnd7sE17HTmabDCtyLKFrLa
wrap://ipfs/QmekvC2sggWkuJcK5eKvVWeSNLJmmNzMphsbm3ZT6FfofZ
Binary file modified implementations/app-typescript/build/wrap.wasm
Binary file not shown.
3 changes: 3 additions & 0 deletions implementations/app-typescript/src/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ mod to_graphql_type;
mod to_typescript;
mod pretty;

// helpers for helpers
mod util;

pub fn register(handlebars: &mut Handlebars) -> () {
handlebars.register_helper(
"array_has_length",
Expand Down
40 changes: 14 additions & 26 deletions implementations/app-typescript/src/helpers/to_typescript.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use handlebars::handlebars_helper;
use serde_json::value::Value;
use crate::helpers::detect_keyword::_detect_keyword;
use crate::helpers::util::{array_type, map_types};

handlebars_helper!(to_typescript: |value: Value| {
_to_typescript(value.as_str().unwrap(), false)
Expand All @@ -17,11 +18,11 @@ fn _to_typescript(value: &str, undefinable: bool) -> String {
}

if type_val.starts_with("[") {
return to_typescript_array(&type_val, optional);
return to_typescript_array(&type_val, optional).unwrap();
}

if type_val.starts_with("Map<") {
return to_typescript_map(&type_val, optional);
return to_typescript_map(&type_val, optional).unwrap();
}

match type_val.as_str() {
Expand All @@ -42,32 +43,19 @@ fn _to_typescript(value: &str, undefinable: bool) -> String {
}
}

fn to_typescript_array(type_val: &str, optional: bool) -> String {
let mut iter = type_val.char_indices();

let first_bracket = iter.find(|&(_, c)| c == '[').map(|(i, _)| i).unwrap();
let last_bracket = iter.rfind(|&(_, c)| c == ']').map(|(i, _)| i).unwrap();

let inner_type = &type_val[(first_bracket+1)..last_bracket];
let ts_type = _to_typescript(inner_type, false);

apply_optional(&format!("Array<{}>", ts_type), optional)
fn to_typescript_array(value: &str, optional: bool) -> Result<String, String> {
let inner_type = array_type(value)?;
let ts_type = _to_typescript(&inner_type, false);
let ts_array = format!("Array<{}>", ts_type);
Ok(apply_optional(&ts_array, optional))
}

fn to_typescript_map(type_val: &str, optional: bool) -> String {
let open_angle_bracket_idx = type_val.find('<').unwrap();
let close_angle_bracket_idx = type_val.rfind('>').unwrap();

let key_val_types = &type_val[(open_angle_bracket_idx+1)..close_angle_bracket_idx];

let first_comma_idx = key_val_types.find(',').unwrap();
let key_type = key_val_types[..first_comma_idx].trim();
let val_type = key_val_types[(first_comma_idx+1)..].trim();

let ts_key_type = _to_typescript(key_type, false);
let ts_val_type = _to_typescript(val_type, true);

apply_optional(&format!("Map<{}, {}>", ts_key_type, ts_val_type), optional)
fn to_typescript_map(value: &str, optional: bool) -> Result<String, String> {
let (key_type, val_type) = map_types(value)?;
let ts_key_type = _to_typescript(&key_type, false);
let ts_val_type = _to_typescript(&val_type, true);
let ts_map = format!("Map<{}, {}>", ts_key_type, ts_val_type);
Ok(apply_optional(&ts_map, optional))
}

fn apply_optional(type_val: &str, optional: bool) -> String {
Expand Down
38 changes: 38 additions & 0 deletions implementations/app-typescript/src/helpers/util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
pub fn array_type(value: &str) -> Result<String, String> {
let mut iter = value.char_indices();

let first_bracket = match iter.find(|&(_, c)| c == '[').map(|(i, _)| i) {
Some(idx) => idx,
None => return Err(format!("Invalid Array: {}", value)),
};
let last_bracket = match iter.rfind(|&(_, c)| c == ']').map(|(i, _)| i) {
Some(idx) => idx,
None => return Err(format!("Invalid Array: {}", value)),
};

let inner_type = &value[(first_bracket+1)..last_bracket];
Ok(inner_type.to_string())
}

pub fn map_types(value: &str) -> Result<(String, String), String> {
let first_open_bracket_idx = match value.find('<') {
Some(idx) => idx,
None => return Err(format!("Invalid Map: {}", value)),
};
let last_close_bracket_idx = match value.rfind('>') {
Some(idx) => idx,
None => return Err(format!("Invalid Map: {}", value)),
};

let key_val_types = &value[(first_open_bracket_idx + 1)..last_close_bracket_idx];

let first_comma_idx = match key_val_types.find(',') {
Some(idx) => idx,
None => return Err(format!("Invalid Map: {}", value)),
};

let key_type = key_val_types[..first_comma_idx].trim();
let val_type = key_val_types[(first_comma_idx + 1)..].trim();

Ok((key_type.to_string(), val_type.to_string()))
}
2 changes: 1 addition & 1 deletion implementations/plugin-kotlin/URI.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
wrap://ipfs/QmcLWEBAgFaNRzSj7aYxyKNm9bRC172kibLPgd2yob18fW
wrap://ipfs/QmYbzNmcXaFEAuWQP6f9cBiZbcKoLQbwNjKQMDEbATaefq
Binary file modified implementations/plugin-kotlin/build/wrap.wasm
Binary file not shown.
3 changes: 3 additions & 0 deletions implementations/plugin-kotlin/src/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ mod to_kotlin_byte_array;
mod to_package_id;
mod to_upper;

// helpers for helpers
mod util;

pub fn register(handlebars: &mut Handlebars) -> () {
handlebars.register_helper(
"array_has_length",
Expand Down
42 changes: 6 additions & 36 deletions implementations/plugin-kotlin/src/helpers/to_kotlin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use handlebars::handlebars_helper;
use serde_json::value::Value;
use crate::helpers::detect_keyword::_detect_keyword;
use crate::helpers::to_upper::_to_upper;
use crate::helpers::util::{array_type, map_types};

handlebars_helper!(to_kotlin: |value: Value| {
_to_kotlin(value.as_str().unwrap())
Expand Down Expand Up @@ -53,47 +54,16 @@ fn _to_kotlin(value: &str) -> String {
}

fn to_kotlin_array(value: &str, optional: bool) -> Result<String, String> {
let mut iter = value.char_indices();

let first_bracket = match iter.find(|&(_, c)| c == '[').map(|(i, _)| i) {
Some(idx) => idx,
None => return Err(format!("Invalid Array: {}", value)),
};
let last_bracket = match iter.rfind(|&(_, c)| c == ']').map(|(i, _)| i) {
Some(idx) => idx,
None => return Err(format!("Invalid Array: {}", value)),
};

let inner_type = &value[(first_bracket+1)..last_bracket];
let kt_type = _to_kotlin(inner_type);

let inner_type = array_type(value)?;
let kt_type = _to_kotlin(&inner_type);
let kt_array = format!("List<{}>", kt_type);
Ok(apply_optional(&kt_array, optional))
}

fn to_kotlin_map(value: &str, optional: bool) -> Result<String, String> {
let first_open_bracket_idx = match value.find('<') {
Some(idx) => idx,
None => return Err(format!("Invalid Map: {}", value)),
};
let last_close_bracket_idx = match value.rfind('>') {
Some(idx) => idx,
None => return Err(format!("Invalid Map: {}", value)),
};

let key_val_types = &value[(first_open_bracket_idx + 1)..last_close_bracket_idx];

let first_comma_idx = match key_val_types.find(',') {
Some(idx) => idx,
None => return Err(format!("Invalid Map: {}", value)),
};

let key_type = key_val_types[..first_comma_idx].trim();
let val_type = key_val_types[(first_comma_idx+1)..].trim();

let kt_key_type = _to_kotlin(key_type);
let kt_val_type = _to_kotlin(val_type);

let (key_type, val_type) = map_types(value)?;
let kt_key_type = _to_kotlin(&key_type);
let kt_val_type = _to_kotlin(&val_type);
let kt_map = format!("MsgPackMap<{}, {}>", kt_key_type, kt_val_type);
Ok(apply_optional(&kt_map, optional))
}
Expand Down
38 changes: 38 additions & 0 deletions implementations/plugin-kotlin/src/helpers/util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
pub fn array_type(value: &str) -> Result<String, String> {
let mut iter = value.char_indices();

let first_bracket = match iter.find(|&(_, c)| c == '[').map(|(i, _)| i) {
Some(idx) => idx,
None => return Err(format!("Invalid Array: {}", value)),
};
let last_bracket = match iter.rfind(|&(_, c)| c == ']').map(|(i, _)| i) {
Some(idx) => idx,
None => return Err(format!("Invalid Array: {}", value)),
};

let inner_type = &value[(first_bracket+1)..last_bracket];
Ok(inner_type.to_string())
}

pub fn map_types(value: &str) -> Result<(String, String), String> {
let first_open_bracket_idx = match value.find('<') {
Some(idx) => idx,
None => return Err(format!("Invalid Map: {}", value)),
};
let last_close_bracket_idx = match value.rfind('>') {
Some(idx) => idx,
None => return Err(format!("Invalid Map: {}", value)),
};

let key_val_types = &value[(first_open_bracket_idx + 1)..last_close_bracket_idx];

let first_comma_idx = match key_val_types.find(',') {
Some(idx) => idx,
None => return Err(format!("Invalid Map: {}", value)),
};

let key_type = key_val_types[..first_comma_idx].trim();
let val_type = key_val_types[(first_comma_idx + 1)..].trim();

Ok((key_type.to_string(), val_type.to_string()))
}
2 changes: 1 addition & 1 deletion implementations/plugin-python/URI.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
wrap://ipfs/Qmap4wqfZoFbQxZdMUC4z7Y3YdK6NbXixGM939ofEuwLFU
wrap://ipfs/QmV9xedSz6Y4tc1qUSVcrQSF63wfibWhB18oao99mByghK
Binary file modified implementations/plugin-python/build/wrap.wasm
Binary file not shown.
42 changes: 6 additions & 36 deletions implementations/plugin-python/src/helpers/to_python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use handlebars::handlebars_helper;
use serde_json::value::Value;
use crate::helpers::detect_keyword::_detect_keyword;
use crate::helpers::to_upper::_to_upper;
use crate::helpers::util::{array_type, map_types};

handlebars_helper!(to_python: |value: Value| {
_to_python(value.as_str().unwrap())
Expand Down Expand Up @@ -45,47 +46,16 @@ fn _to_python(value: &str) -> String {
}

fn to_python_array(value: &str, optional: bool) -> Result<String, String> {
let mut iter = value.char_indices();

let first_bracket = match iter.find(|&(_, c)| c == '[').map(|(i, _)| i) {
Some(idx) => idx,
None => return Err(format!("Invalid Array: {}", value)),
};
let last_bracket = match iter.rfind(|&(_, c)| c == ']').map(|(i, _)| i) {
Some(idx) => idx,
None => return Err(format!("Invalid Array: {}", value)),
};

let inner_type = &value[(first_bracket+1)..last_bracket];
let py_type = _to_python(inner_type);

let inner_type = array_type(value)?;
let py_type = _to_python(&inner_type);
let py_array = format!("list[{}]", py_type);
Ok(apply_optional(&py_array, optional))
}

fn to_python_map(value: &str, optional: bool) -> Result<String, String> {
let first_open_bracket_idx = match value.find('<') {
Some(idx) => idx,
None => return Err(format!("Invalid Map: {}", value)),
};
let last_close_bracket_idx = match value.rfind('>') {
Some(idx) => idx,
None => return Err(format!("Invalid Map: {}", value)),
};

let key_val_types = &value[(first_open_bracket_idx + 1)..last_close_bracket_idx];

let first_comma_idx = match key_val_types.find(',') {
Some(idx) => idx,
None => return Err(format!("Invalid Map: {}", value)),
};

let key_type = key_val_types[..first_comma_idx].trim();
let val_type = key_val_types[(first_comma_idx+1)..].trim();

let py_key_type = _to_python(key_type);
let py_val_type = _to_python(val_type);

let (key_type, val_type) = map_types(value)?;
let py_key_type = _to_python(&key_type);
let py_val_type = _to_python(&val_type);
let py_map = format!("GenericMap[{}, {}]", py_key_type, py_val_type);
Ok(apply_optional(&py_map, optional))
}
Expand Down
38 changes: 38 additions & 0 deletions implementations/plugin-python/src/helpers/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,41 @@ pub fn remove_at(s: &str, idx: usize) -> String {
format!("{}{}", start, end)
}

pub fn array_type(value: &str) -> Result<String, String> {
let mut iter = value.char_indices();

let first_bracket = match iter.find(|&(_, c)| c == '[').map(|(i, _)| i) {
Some(idx) => idx,
None => return Err(format!("Invalid Array: {}", value)),
};
let last_bracket = match iter.rfind(|&(_, c)| c == ']').map(|(i, _)| i) {
Some(idx) => idx,
None => return Err(format!("Invalid Array: {}", value)),
};

let inner_type = &value[(first_bracket+1)..last_bracket];
Ok(inner_type.to_string())
}

pub fn map_types(value: &str) -> Result<(String, String), String> {
let first_open_bracket_idx = match value.find('<') {
Some(idx) => idx,
None => return Err(format!("Invalid Map: {}", value)),
};
let last_close_bracket_idx = match value.rfind('>') {
Some(idx) => idx,
None => return Err(format!("Invalid Map: {}", value)),
};

let key_val_types = &value[(first_open_bracket_idx + 1)..last_close_bracket_idx];

let first_comma_idx = match key_val_types.find(',') {
Some(idx) => idx,
None => return Err(format!("Invalid Map: {}", value)),
};

let key_type = key_val_types[..first_comma_idx].trim();
let val_type = key_val_types[(first_comma_idx + 1)..].trim();

Ok((key_type.to_string(), val_type.to_string()))
}
2 changes: 1 addition & 1 deletion implementations/plugin-rust/URI.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
wrap://ipfs/QmTC8oqchRJMqNeKtvRdF2pQc6TMLNS9LFiXwefHaUfUF5
wrap://ipfs/QmSYCtTtHMyenvFu7b4J914LTZLPNkyme2Dfa9QLvNWUiV
Binary file modified implementations/plugin-rust/build/wrap.wasm
Binary file not shown.
Loading
Loading