Skip to content

Commit

Permalink
Fix WASM enums
Browse files Browse the repository at this point in the history
  • Loading branch information
tinrab committed Aug 23, 2024
1 parent 0d47e94 commit c1cf119
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 41 deletions.
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bomboni"
version = "0.1.59"
version = "0.1.60"
authors = ["Tin Rabzelj <tin@flinect.com>"]
description = "Utility Library for Rust"
repository = "https://github.com/tinrab/bomboni"
Expand Down Expand Up @@ -51,11 +51,11 @@ fs = ["dep:bomboni_fs"]
postgres = ["bomboni_common/postgres", "bomboni_request/postgres"]

[dependencies]
bomboni_common = { path = "bomboni_common", version = "0.1.59" }
bomboni_common = { path = "bomboni_common", version = "0.1.60" }

bomboni_prost = { path = "bomboni_prost", version = "0.1.59", default-features = false, optional = true }
bomboni_proto = { path = "bomboni_proto", version = "0.1.59", default-features = false, optional = true }
bomboni_request = { path = "bomboni_request", version = "0.1.59", default-features = false, optional = true }
bomboni_template = { path = "bomboni_template", version = "0.1.59", default-features = false, optional = true }
bomboni_wasm = { path = "bomboni_wasm", version = "0.1.59", default-features = false, optional = true }
bomboni_fs = { path = "bomboni_fs", version = "0.1.59", default-features = false, optional = true }
bomboni_prost = { path = "bomboni_prost", version = "0.1.60", default-features = false, optional = true }
bomboni_proto = { path = "bomboni_proto", version = "0.1.60", default-features = false, optional = true }
bomboni_request = { path = "bomboni_request", version = "0.1.60", default-features = false, optional = true }
bomboni_template = { path = "bomboni_template", version = "0.1.60", default-features = false, optional = true }
bomboni_wasm = { path = "bomboni_wasm", version = "0.1.60", default-features = false, optional = true }
bomboni_fs = { path = "bomboni_fs", version = "0.1.60", default-features = false, optional = true }
4 changes: 2 additions & 2 deletions bomboni_common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bomboni_common"
version = "0.1.59"
version = "0.1.60"
authors = ["Tin Rabzelj <tin@flinect.com>"]
description = "Common things for Bomboni library."
repository = "https://github.com/tinrab/bomboni"
Expand All @@ -27,7 +27,7 @@ js = []
postgres = ["dep:postgres-types", "dep:bytes"]

[dependencies]
bomboni_wasm = { path = "../bomboni_wasm", version = "0.1.59", features = [
bomboni_wasm = { path = "../bomboni_wasm", version = "0.1.60", features = [
"derive",
], optional = true }

Expand Down
2 changes: 1 addition & 1 deletion bomboni_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bomboni_core"
version = "0.1.59"
version = "0.1.60"
authors = ["Tin Rabzelj <tin@flinect.com>"]
description = "Internal part of Bomboni library."
repository = "https://github.com/tinrab/bomboni"
Expand Down
2 changes: 1 addition & 1 deletion bomboni_fs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bomboni_fs"
version = "0.1.59"
version = "0.1.60"
authors = ["Tin Rabzelj <tin@flinect.com>"]
description = "Utilites for working with the file system. Part of Bomboni library."
repository = "https://github.com/tinrab/bomboni"
Expand Down
4 changes: 2 additions & 2 deletions bomboni_prost/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bomboni_prost"
version = "0.1.59"
version = "0.1.60"
authors = ["Tin Rabzelj <tin@flinect.com>"]
description = "Utilities for working with prost. Part of Bomboni library."
repository = "https://github.com/tinrab/bomboni"
Expand All @@ -14,7 +14,7 @@ name = "bomboni_prost"
path = "src/lib.rs"

[dependencies]
bomboni_core = { path = "../bomboni_core", version = "0.1.59" }
bomboni_core = { path = "../bomboni_core", version = "0.1.60" }

prost = "0.13.1"
prost-types = "0.13.1"
Expand Down
8 changes: 4 additions & 4 deletions bomboni_proto/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bomboni_proto"
version = "0.1.59"
version = "0.1.60"
authors = ["Tin Rabzelj <tin@flinect.com>"]
description = "Utilities for working with Protobuf/gRPC. Part of Bomboni library."
repository = "https://github.com/tinrab/bomboni"
Expand Down Expand Up @@ -30,7 +30,7 @@ js = ["bomboni_common/js"]
[dependencies]
bomboni_common = { path = "../bomboni_common", features = [
"serde",
], version = "0.1.59" }
], version = "0.1.60" }

thiserror = "1.0.63"
time = { version = "0.3.36", features = ["serde", "formatting", "parsing"] }
Expand All @@ -44,7 +44,7 @@ http = { version = "1.1.0", optional = true }
chrono = { version = "0.4.38", optional = true }

[target.'cfg(all(target_family = "wasm", not(any(target_os = "emscripten", target_os = "wasi"))))'.dependencies]
bomboni_wasm = { path = "../bomboni_wasm", version = "0.1.59", optional = true }
bomboni_wasm = { path = "../bomboni_wasm", version = "0.1.60", optional = true }

wasm-bindgen = { version = "0.2.92", optional = true }
js-sys = { version = "0.3.69", optional = true }
Expand All @@ -54,5 +54,5 @@ serde-wasm-bindgen = { version = "0.6.5", optional = true }
serde_json = "1.0.120"

[build-dependencies]
bomboni_prost = { path = "../bomboni_prost", version = "0.1.59" }
bomboni_prost = { path = "../bomboni_prost", version = "0.1.60" }
prost-build = "0.13.1"
10 changes: 5 additions & 5 deletions bomboni_request/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bomboni_request"
version = "0.1.59"
version = "0.1.60"
authors = ["Tin Rabzelj <tin@flinect.com>"]
description = "Utilities for working with API requests. Part of Bomboni library."
repository = "https://github.com/tinrab/bomboni"
Expand Down Expand Up @@ -29,10 +29,10 @@ wasm = [
postgres = ["dep:postgres-types", "dep:bytes"]

[dependencies]
bomboni_common = { path = "../bomboni_common", version = "0.1.59" }
bomboni_proto = { path = "../bomboni_proto", version = "0.1.59" }
bomboni_request_derive = { path = "../bomboni_request_derive", version = "0.1.59" }
bomboni_wasm = { path = "../bomboni_wasm", version = "0.1.59", features = [
bomboni_common = { path = "../bomboni_common", version = "0.1.60" }
bomboni_proto = { path = "../bomboni_proto", version = "0.1.60" }
bomboni_request_derive = { path = "../bomboni_request_derive", version = "0.1.60" }
bomboni_wasm = { path = "../bomboni_wasm", version = "0.1.60", features = [
"derive",
], optional = true }

Expand Down
4 changes: 2 additions & 2 deletions bomboni_request_derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bomboni_request_derive"
version = "0.1.59"
version = "0.1.60"
authors = ["Tin Rabzelj <tin@flinect.com>"]
description = "Internal request derive macros for Bomboni library."
repository = "https://github.com/tinrab/bomboni"
Expand All @@ -15,7 +15,7 @@ path = "src/lib.rs"
proc-macro = true

[dependencies]
bomboni_core = { path = "../bomboni_core", version = "0.1.59" }
bomboni_core = { path = "../bomboni_core", version = "0.1.60" }

proc-macro2 = { version = "1.0.86", features = ["proc-macro"] }
syn = "2.0.72"
Expand Down
6 changes: 3 additions & 3 deletions bomboni_template/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bomboni_template"
version = "0.1.59"
version = "0.1.60"
authors = ["Tin Rabzelj <tin@flinect.com>"]
description = "Utilities for working Handlebars templates. Part of Bomboni library."
repository = "https://github.com/tinrab/bomboni"
Expand All @@ -18,8 +18,8 @@ default = ["testing"]
testing = []

[dependencies]
bomboni_common = { path = "../bomboni_common", version = "0.1.59" }
bomboni_proto = { version = "0.1.59", path = "../bomboni_proto" }
bomboni_common = { path = "../bomboni_common", version = "0.1.60" }
bomboni_proto = { version = "0.1.60", path = "../bomboni_proto" }

thiserror = "1.0.63"
handlebars = "6.0.0"
Expand Down
6 changes: 3 additions & 3 deletions bomboni_wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bomboni_wasm"
version = "0.1.59"
version = "0.1.60"
authors = ["Tin Rabzelj <tin@flinect.com>"]
description = "Utilities for working with WASM. Part of Bomboni library."
repository = "https://github.com/tinrab/bomboni"
Expand All @@ -18,8 +18,8 @@ derive = ["dep:bomboni_wasm_derive"]
js = ["bomboni_wasm_core/js"]

[dependencies]
bomboni_wasm_core = { path = "../bomboni_wasm_core", version = "0.1.59" }
bomboni_wasm_derive = { path = "../bomboni_wasm_derive", version = "0.1.59", optional = true }
bomboni_wasm_core = { path = "../bomboni_wasm_core", version = "0.1.60" }
bomboni_wasm_derive = { path = "../bomboni_wasm_derive", version = "0.1.60", optional = true }

serde = "1.0.204"
wasm-bindgen = "0.2.92"
Expand Down
4 changes: 2 additions & 2 deletions bomboni_wasm_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bomboni_wasm_core"
version = "0.1.59"
version = "0.1.60"
authors = ["Tin Rabzelj <tin@flinect.com>"]
description = "Internal WASM part of Bomboni library."
repository = "https://github.com/tinrab/bomboni"
Expand All @@ -17,7 +17,7 @@ path = "src/lib.rs"
js = []

[dependencies]
bomboni_core = { path = "../bomboni_core", version = "0.1.59" }
bomboni_core = { path = "../bomboni_core", version = "0.1.60" }

proc-macro2 = { version = "1.0.86", features = ["proc-macro"] }
syn = "2.0.72"
Expand Down
6 changes: 3 additions & 3 deletions bomboni_wasm_derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bomboni_wasm_derive"
version = "0.1.59"
version = "0.1.60"
authors = ["Tin Rabzelj <tin@flinect.com>"]
description = "Internal WASM derive macros for Bomboni library."
repository = "https://github.com/tinrab/bomboni"
Expand All @@ -15,8 +15,8 @@ path = "src/lib.rs"
proc-macro = true

[dependencies]
bomboni_core = { path = "../bomboni_core", version = "0.1.59" }
bomboni_wasm_core = { path = "../bomboni_wasm_core", version = "0.1.59" }
bomboni_core = { path = "../bomboni_core", version = "0.1.60" }
bomboni_wasm_core = { path = "../bomboni_wasm_core", version = "0.1.60" }

proc-macro2 = { version = "1.0.86", features = ["proc-macro"] }
syn = "2.0.72"
Expand Down
24 changes: 19 additions & 5 deletions bomboni_wasm_derive/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//!
//! [1]: https://github.com/madonoharu/tsify
use std::collections::BTreeSet;
use std::collections::{BTreeMap, BTreeSet};

use bomboni_core::string::{str_to_case, Case};
use bomboni_wasm_core::{
Expand Down Expand Up @@ -436,7 +436,8 @@ fn derive_enum_value(options: &WasmOptions) -> syn::Result<TokenStream> {
let ts_decl = TsDeclParser::new(options).parse();
let ts_decl_name = ts_decl.name();

let mut variants = String::new();
// let mut variants = String::new();
let mut variants = BTreeMap::new();
if let TsDecl::Enum(ts_enum) = &ts_decl {
let mut unique_member_names = BTreeSet::new();
for member in &ts_enum.members {
Expand All @@ -451,13 +452,26 @@ fn derive_enum_value(options: &WasmOptions) -> syn::Result<TokenStream> {
));
}

variants.push_str(&format!("{member_name}: {member_type_value},\n"));
variants.push_str(&format!("{member_type_value}: \"{member_name}\",\n"));
variants.insert(member_name.clone(), member_type_value.clone());
variants.insert(member_type_value, format!("\"{member_name}\""));
}
}

let usage = expand_usage(options);
let js_literal = format!("export const {ts_decl_name} = Object.freeze({{\n {variants}}});");
let js_literal = format!(
"export const {} = Object.freeze({{\n {}}});",
ts_decl_name,
variants
.into_iter()
.map(|(k, v)| { format!("{k}: {v}") })
.fold(String::new(), |acc, row| {
if acc.is_empty() {
row.to_string()
} else {
format!("{acc},\n{row}")
}
})
);
let impls = derive_serde_wasm(options);
Ok(quote! {
#[automatically_derived]
Expand Down

0 comments on commit c1cf119

Please sign in to comment.