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

Add JavaScript bindings via Wasm #360

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
df64c92
Add schemars::JsonSchema derives to all types
leighmcculloch Mar 4, 2024
3a547ec
add test
leighmcculloch Mar 4, 2024
ca57d82
remove unused dev dep
leighmcculloch Mar 4, 2024
3146219
silence clippy warning
leighmcculloch Mar 4, 2024
ddb4b4d
regen with new feature and manual impls from willem
leighmcculloch Mar 7, 2024
52bb627
upd
leighmcculloch Mar 7, 2024
5329bbf
fix
leighmcculloch Mar 7, 2024
bea9cec
upd
leighmcculloch Mar 8, 2024
f576c2a
fix overflow
leighmcculloch Mar 8, 2024
7575d7f
add first version of command
leighmcculloch Mar 13, 2024
db6d5a5
ping to draft7
leighmcculloch Mar 13, 2024
ecb4216
upd
leighmcculloch Mar 13, 2024
bbfea62
group new features
leighmcculloch Mar 14, 2024
017f7d6
custom types
leighmcculloch Mar 15, 2024
48714cb
upd
leighmcculloch Mar 15, 2024
9bf4550
feat: add wasm-pack to allow publishing to npm
willemneal Mar 14, 2024
17efe8f
fix: return list of types
willemneal Mar 14, 2024
c52da3d
feat: add to_xdr and from_xdr
willemneal Mar 18, 2024
b10e4be
feat: use serde_json_wasm
willemneal Mar 19, 2024
0a686f1
feat: add titles to enum types for better readability
willemneal Mar 20, 2024
fcf73dd
feat: add build script
willemneal Mar 21, 2024
2d078c1
upd ver
leighmcculloch Apr 9, 2024
716ac7e
Merge branch 'main' into rust-add-schemas
leighmcculloch Apr 9, 2024
daa2ca7
Merge branch 'main' into rust-add-schemas
leighmcculloch Apr 10, 2024
3a12f34
update xdr
leighmcculloch Apr 10, 2024
c1ce799
Merge branch 'rust-add-schemas' into pr/willemneal/351
leighmcculloch Apr 10, 2024
c0cfb75
Few changes see description
leighmcculloch Apr 11, 2024
b0ab96e
web
leighmcculloch Apr 11, 2024
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
Prev Previous commit
Next Next commit
upd
  • Loading branch information
leighmcculloch committed Mar 15, 2024
commit 48714cbff6cc9d3d30a623ed8ca7a9a5f0570d72
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CARGO_HACK_ARGS=--feature-powerset --exclude-features default --group-features b

CARGO_DOC_ARGS?=--open

XDRGEN_VERSION=4ea81a540e25623567badd1f7dd649cc46cf9f21
XDRGEN_VERSION=0a2611a2bc6b6f6bceacb72fe9321b0cb4d8ccd5
# XDRGEN_LOCAL=1
XDRGEN_TYPES_CUSTOM_STR_IMPL_CURR=PublicKey,AccountId,MuxedAccount,MuxedAccountMed25519,SignerKey,SignerKeyEd25519SignedPayload,NodeId,ScAddress,AssetCode,AssetCode4,AssetCode12
XDRGEN_TYPES_CUSTOM_STR_IMPL_NEXT=PublicKey,AccountId,MuxedAccount,MuxedAccountMed25519,SignerKey,SignerKeyEd25519SignedPayload,NodeId,ScAddress,AssetCode,AssetCode4,AssetCode12
Expand Down
130 changes: 56 additions & 74 deletions src/curr/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -967,12 +967,18 @@ impl<T: schemars::JsonSchema, const MAX: u32> schemars::JsonSchema for VecM<T, M
}

fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
mut_array(Vec::<T>::json_schema(gen), |array| {
schemars::schema::ArrayValidation {
max_items: Some(MAX),
..array
}
})
let schema = Vec::<T>::json_schema(gen);
if let schemars::schema::Schema::Object(mut schema) = schema {
if let Some(array) = schema.array.clone() {
schema.array = Some(Box::new(schemars::schema::ArrayValidation {
max_items: Some(MAX),
..*array
}));
}
schema.into()
} else {
schema
}
}
}

Expand Down Expand Up @@ -1422,8 +1428,8 @@ impl<const MAX: u32> schemars::JsonSchema for BytesM<MAX> {
}

fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
let schema_ = String::json_schema(gen);
if let schemars::schema::Schema::Object(mut schema) = schema_ {
let schema = String::json_schema(gen);
if let schemars::schema::Schema::Object(mut schema) = schema {
schema.extensions.insert(
"contentEncoding".to_owned(),
serde_json::Value::String("hex".to_string()),
Expand All @@ -1432,13 +1438,15 @@ impl<const MAX: u32> schemars::JsonSchema for BytesM<MAX> {
"contentMediaType".to_owned(),
serde_json::Value::String("application/binary".to_string()),
);
mut_string(schema.into(), |string| schemars::schema::StringValidation {
let string = *schema.string.unwrap_or_default().clone();
schema.string = Some(Box::new(schemars::schema::StringValidation {
max_length: MAX.checked_mul(2).map(Some).unwrap_or_default(),
min_length: None,
..string
})
}));
schema.into()
} else {
schema_
schema
}
}
}
Expand Down Expand Up @@ -1837,17 +1845,18 @@ impl<const MAX: u32> schemars::JsonSchema for StringM<MAX> {
format!("StringM<{MAX}>")
}

fn is_referenceable() -> bool {
false
}

fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
mut_string(String::json_schema(gen), |string| {
schemars::schema::StringValidation {
let schema = String::json_schema(gen);
if let schemars::schema::Schema::Object(mut schema) = schema {
let string = *schema.string.unwrap_or_default().clone();
schema.string = Some(Box::new(schemars::schema::StringValidation {
max_length: Some(MAX),
..string
}
})
}));
schema.into()
} else {
schema
}
}
}

Expand Down Expand Up @@ -2173,10 +2182,6 @@ impl<T: schemars::JsonSchema + ReadXdr> schemars::JsonSchema for Frame<T> {
format!("Frame<{}>", T::schema_name())
}

fn is_referenceable() -> bool {
false
}

fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
T::json_schema(gen)
}
Expand Down Expand Up @@ -2206,37 +2211,6 @@ where
}
}

#[cfg(feature = "schemars")]
fn mut_array(
schema: schemars::schema::Schema,
f: impl FnOnce(schemars::schema::ArrayValidation) -> schemars::schema::ArrayValidation,
) -> schemars::schema::Schema {
if let schemars::schema::Schema::Object(mut schema) = schema {
if let Some(array) = schema.array.clone() {
schema.array = Some(Box::new(f(*array)));
}
schema.into()
} else {
schema
}
}

#[cfg(feature = "schemars")]
fn mut_string(
schema: schemars::schema::Schema,
f: impl FnOnce(schemars::schema::StringValidation) -> schemars::schema::StringValidation,
) -> schemars::schema::Schema {
if let schemars::schema::Schema::Object(mut schema) = schema {
let string = *schema.string.unwrap_or_default().clone();
let s = f(string);
schema.string = Some(Box::new(s));

schema.into()
} else {
schema
}
}

#[cfg(all(test, feature = "std"))]
mod tests {
use std::io::Cursor;
Expand Down Expand Up @@ -10201,8 +10175,8 @@ impl schemars::JsonSchema for Thresholds {
}

fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
let schema_ = String::json_schema(gen);
if let schemars::schema::Schema::Object(mut schema) = schema_ {
let schema = String::json_schema(gen);
if let schemars::schema::Schema::Object(mut schema) = schema {
schema.extensions.insert(
"contentEncoding".to_owned(),
serde_json::Value::String("hex".to_string()),
Expand All @@ -10211,13 +10185,15 @@ impl schemars::JsonSchema for Thresholds {
"contentMediaType".to_owned(),
serde_json::Value::String("application/binary".to_string()),
);
mut_string(schema.into(), |string| schemars::schema::StringValidation {
let string = *schema.string.unwrap_or_default().clone();
schema.string = Some(Box::new(schemars::schema::StringValidation {
max_length: 4_u32.checked_mul(2).map(Some).unwrap_or_default(),
min_length: 4_u32.checked_mul(2).map(Some).unwrap_or_default(),
..string
})
}));
schema.into()
} else {
schema_
schema
}
}
}
Expand Down Expand Up @@ -41085,8 +41061,8 @@ impl schemars::JsonSchema for Hash {
}

fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
let schema_ = String::json_schema(gen);
if let schemars::schema::Schema::Object(mut schema) = schema_ {
let schema = String::json_schema(gen);
if let schemars::schema::Schema::Object(mut schema) = schema {
schema.extensions.insert(
"contentEncoding".to_owned(),
serde_json::Value::String("hex".to_string()),
Expand All @@ -41095,13 +41071,15 @@ impl schemars::JsonSchema for Hash {
"contentMediaType".to_owned(),
serde_json::Value::String("application/binary".to_string()),
);
mut_string(schema.into(), |string| schemars::schema::StringValidation {
let string = *schema.string.unwrap_or_default().clone();
schema.string = Some(Box::new(schemars::schema::StringValidation {
max_length: 32_u32.checked_mul(2).map(Some).unwrap_or_default(),
min_length: 32_u32.checked_mul(2).map(Some).unwrap_or_default(),
..string
})
}));
schema.into()
} else {
schema_
schema
}
}
}
Expand Down Expand Up @@ -41234,8 +41212,8 @@ impl schemars::JsonSchema for Uint256 {
}

fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
let schema_ = String::json_schema(gen);
if let schemars::schema::Schema::Object(mut schema) = schema_ {
let schema = String::json_schema(gen);
if let schemars::schema::Schema::Object(mut schema) = schema {
schema.extensions.insert(
"contentEncoding".to_owned(),
serde_json::Value::String("hex".to_string()),
Expand All @@ -41244,13 +41222,15 @@ impl schemars::JsonSchema for Uint256 {
"contentMediaType".to_owned(),
serde_json::Value::String("application/binary".to_string()),
);
mut_string(schema.into(), |string| schemars::schema::StringValidation {
let string = *schema.string.unwrap_or_default().clone();
schema.string = Some(Box::new(schemars::schema::StringValidation {
max_length: 32_u32.checked_mul(2).map(Some).unwrap_or_default(),
min_length: 32_u32.checked_mul(2).map(Some).unwrap_or_default(),
..string
})
}));
schema.into()
} else {
schema_
schema
}
}
}
Expand Down Expand Up @@ -42371,8 +42351,8 @@ impl schemars::JsonSchema for SignatureHint {
}

fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
let schema_ = String::json_schema(gen);
if let schemars::schema::Schema::Object(mut schema) = schema_ {
let schema = String::json_schema(gen);
if let schemars::schema::Schema::Object(mut schema) = schema {
schema.extensions.insert(
"contentEncoding".to_owned(),
serde_json::Value::String("hex".to_string()),
Expand All @@ -42381,13 +42361,15 @@ impl schemars::JsonSchema for SignatureHint {
"contentMediaType".to_owned(),
serde_json::Value::String("application/binary".to_string()),
);
mut_string(schema.into(), |string| schemars::schema::StringValidation {
let string = *schema.string.unwrap_or_default().clone();
schema.string = Some(Box::new(schemars::schema::StringValidation {
max_length: 4_u32.checked_mul(2).map(Some).unwrap_or_default(),
min_length: 4_u32.checked_mul(2).map(Some).unwrap_or_default(),
..string
})
}));
schema.into()
} else {
schema_
schema
}
}
}
Expand Down
Loading
Loading