diff --git a/Cargo.toml b/Cargo.toml index 74f8bd1..2d4aebe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bomboni" -version = "0.1.59" +version = "0.1.60" authors = ["Tin Rabzelj "] description = "Utility Library for Rust" repository = "https://github.com/tinrab/bomboni" @@ -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 } diff --git a/bomboni_common/Cargo.toml b/bomboni_common/Cargo.toml index 2d2a5bb..a70cd73 100644 --- a/bomboni_common/Cargo.toml +++ b/bomboni_common/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bomboni_common" -version = "0.1.59" +version = "0.1.60" authors = ["Tin Rabzelj "] description = "Common things for Bomboni library." repository = "https://github.com/tinrab/bomboni" @@ -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 } diff --git a/bomboni_core/Cargo.toml b/bomboni_core/Cargo.toml index 0197a1f..4d90e53 100644 --- a/bomboni_core/Cargo.toml +++ b/bomboni_core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bomboni_core" -version = "0.1.59" +version = "0.1.60" authors = ["Tin Rabzelj "] description = "Internal part of Bomboni library." repository = "https://github.com/tinrab/bomboni" diff --git a/bomboni_fs/Cargo.toml b/bomboni_fs/Cargo.toml index 4b18471..a352e63 100644 --- a/bomboni_fs/Cargo.toml +++ b/bomboni_fs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bomboni_fs" -version = "0.1.59" +version = "0.1.60" authors = ["Tin Rabzelj "] description = "Utilites for working with the file system. Part of Bomboni library." repository = "https://github.com/tinrab/bomboni" diff --git a/bomboni_prost/Cargo.toml b/bomboni_prost/Cargo.toml index 809bc6b..a60fb44 100644 --- a/bomboni_prost/Cargo.toml +++ b/bomboni_prost/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bomboni_prost" -version = "0.1.59" +version = "0.1.60" authors = ["Tin Rabzelj "] description = "Utilities for working with prost. Part of Bomboni library." repository = "https://github.com/tinrab/bomboni" @@ -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" diff --git a/bomboni_proto/Cargo.toml b/bomboni_proto/Cargo.toml index 253f504..cb9747b 100644 --- a/bomboni_proto/Cargo.toml +++ b/bomboni_proto/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bomboni_proto" -version = "0.1.59" +version = "0.1.60" authors = ["Tin Rabzelj "] description = "Utilities for working with Protobuf/gRPC. Part of Bomboni library." repository = "https://github.com/tinrab/bomboni" @@ -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"] } @@ -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 } @@ -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" diff --git a/bomboni_request/Cargo.toml b/bomboni_request/Cargo.toml index 9027f31..40c0c20 100644 --- a/bomboni_request/Cargo.toml +++ b/bomboni_request/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bomboni_request" -version = "0.1.59" +version = "0.1.60" authors = ["Tin Rabzelj "] description = "Utilities for working with API requests. Part of Bomboni library." repository = "https://github.com/tinrab/bomboni" @@ -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 } diff --git a/bomboni_request_derive/Cargo.toml b/bomboni_request_derive/Cargo.toml index bbce29e..9216f70 100644 --- a/bomboni_request_derive/Cargo.toml +++ b/bomboni_request_derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bomboni_request_derive" -version = "0.1.59" +version = "0.1.60" authors = ["Tin Rabzelj "] description = "Internal request derive macros for Bomboni library." repository = "https://github.com/tinrab/bomboni" @@ -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" diff --git a/bomboni_template/Cargo.toml b/bomboni_template/Cargo.toml index f8f81d2..a14165f 100644 --- a/bomboni_template/Cargo.toml +++ b/bomboni_template/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bomboni_template" -version = "0.1.59" +version = "0.1.60" authors = ["Tin Rabzelj "] description = "Utilities for working Handlebars templates. Part of Bomboni library." repository = "https://github.com/tinrab/bomboni" @@ -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" diff --git a/bomboni_wasm/Cargo.toml b/bomboni_wasm/Cargo.toml index a94db18..fa22fa1 100644 --- a/bomboni_wasm/Cargo.toml +++ b/bomboni_wasm/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bomboni_wasm" -version = "0.1.59" +version = "0.1.60" authors = ["Tin Rabzelj "] description = "Utilities for working with WASM. Part of Bomboni library." repository = "https://github.com/tinrab/bomboni" @@ -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" diff --git a/bomboni_wasm_core/Cargo.toml b/bomboni_wasm_core/Cargo.toml index 1187b9d..df91801 100644 --- a/bomboni_wasm_core/Cargo.toml +++ b/bomboni_wasm_core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bomboni_wasm_core" -version = "0.1.59" +version = "0.1.60" authors = ["Tin Rabzelj "] description = "Internal WASM part of Bomboni library." repository = "https://github.com/tinrab/bomboni" @@ -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" diff --git a/bomboni_wasm_derive/Cargo.toml b/bomboni_wasm_derive/Cargo.toml index 730259f..98e1c7f 100644 --- a/bomboni_wasm_derive/Cargo.toml +++ b/bomboni_wasm_derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bomboni_wasm_derive" -version = "0.1.59" +version = "0.1.60" authors = ["Tin Rabzelj "] description = "Internal WASM derive macros for Bomboni library." repository = "https://github.com/tinrab/bomboni" @@ -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" diff --git a/bomboni_wasm_derive/src/wasm.rs b/bomboni_wasm_derive/src/wasm.rs index bfa0338..2253109 100644 --- a/bomboni_wasm_derive/src/wasm.rs +++ b/bomboni_wasm_derive/src/wasm.rs @@ -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::{ @@ -436,7 +436,8 @@ fn derive_enum_value(options: &WasmOptions) -> syn::Result { 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 { @@ -451,13 +452,26 @@ fn derive_enum_value(options: &WasmOptions) -> syn::Result { )); } - 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]