Skip to content

Commit

Permalink
fix: bindgen nested types init generation (#2580)
Browse files Browse the repository at this point in the history
* fix: bindgen nested types init generation

* bump: cainome-0.4.6

* fix: fix tests

---------

Co-authored-by: glihm <dev@glihm.net>
  • Loading branch information
MartianGreed and glihm authored Oct 29, 2024
1 parent 6f845a7 commit 8a9dc0c
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 51 deletions.
101 changes: 62 additions & 39 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ inherits = "release"
lto = "fat"

[workspace.dependencies]
cainome = { git = "https://github.com/cartridge-gg/cainome", tag = "v0.4.1", features = [ "abigen-rs" ] }
cainome = { git = "https://github.com/cartridge-gg/cainome", tag = "v0.4.6", features = [ "abigen-rs" ] }
dojo-utils = { path = "crates/dojo-utils" }

# metrics
Expand Down Expand Up @@ -216,7 +216,7 @@ warp = "0.3"

# gRPC
prost = "0.12"
tonic = { version = "0.11", features = [ "tls", "tls-roots", "gzip" ] }
tonic = { version = "0.11", features = [ "gzip", "tls", "tls-roots" ] }
tonic-build = "0.11"
tonic-reflection = "0.11"
tonic-web = "0.11"
Expand Down
1 change: 1 addition & 0 deletions crates/dojo-bindgen/src/plugins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl fmt::Display for BuiltinPlugins {
}
}

#[derive(Debug)]
pub struct Buffer(Vec<String>);
impl Buffer {
pub fn new() -> Self {
Expand Down
4 changes: 2 additions & 2 deletions crates/dojo-bindgen/src/plugins/typescript/generator/erc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ const ERC_TORII_TYPES: &str = "\n\t\tERC__Balance: ERC__Balance,\n\t\tERC__Token
ERC__Token,\n\t\tERC__Transfer: ERC__Transfer,";
const ERC_TORII_INIT: &str = "
\t\tERC__Balance: {
\t\t\tfieldorder: ['balance', 'type', 'tokenmetadata'],
\t\t\tfieldOrder: ['balance', 'type', 'tokenmetadata'],
\t\t\tbalance: '',
\t\t\ttype: 'ERC20',
\t\t\ttokenMetadata: {
\t\t\t\tfieldorder: ['name', 'symbol', 'tokenId', 'decimals', 'contractAddress'],
\t\t\t\tfieldOrder: ['name', 'symbol', 'tokenId', 'decimals', 'contractAddress'],
\t\t\t\tname: '',
\t\t\t\tsymbol: '',
\t\t\t\ttokenId: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl TsFunctionGenerator {
}

fn setup_function_wrapper_start(&self, buffer: &mut Buffer) -> usize {
let fn_wrapper = "export async function setupWorld(provider: DojoProvider) {{\n";
let fn_wrapper = "export async function setupWorld(provider: DojoProvider) {\n";

if !buffer.has(fn_wrapper) {
buffer.push(fn_wrapper.to_owned());
Expand Down
5 changes: 3 additions & 2 deletions crates/dojo-bindgen/src/plugins/typescript/generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,14 @@ impl From<&Composite> for JsDefaultValue {
JsDefaultValue(format!("{}.{}", value.type_name(), value.inners[0].name))
}
cainome::parser::tokens::CompositeType::Struct => JsDefaultValue(format!(
"{{ {} }}",
"{{ fieldOrder: [{}], {} }}",
value.inners.iter().map(|i| format!("'{}'", i.name)).collect::<Vec<_>>().join(", "),
value
.inners
.iter()
.map(|i| format!("{}: {},", i.name, JsDefaultValue::from(&i.token)))
.collect::<Vec<_>>()
.join("\n")
.join(" ")
)),
_ => JsDefaultValue::from(value.type_name().as_str()),
}
Expand Down
Loading

0 comments on commit 8a9dc0c

Please sign in to comment.