lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README

commit 6fc259db62e3fe6555e67b790425ce5a8e3bbbd5
parent 69cc1738440d615f661145f5ff821aec0dbfe4b2
Author: triesap <tyson@radroots.org>
Date:   Sat, 27 Jun 2026 07:59:23 +0000

core: derive dto roots

Diffstat:
MCargo.lock | 12++++++------
MCargo.toml | 4++--
Mcrates/core/Cargo.toml | 4++--
Mcrates/core/src/currency.rs | 2++
Mcrates/core/src/decimal.rs | 2++
Mcrates/core/src/discount.rs | 8++++++++
Mcrates/core/src/dto.rs | 390++++++--------------------------------------------------------------------------
Acrates/core/src/generated/dto_roots.rs | 20++++++++++++++++++++
Mcrates/core/src/money.rs | 2++
Mcrates/core/src/percent.rs | 3+++
Mcrates/core/src/quantity.rs | 3+++
Mcrates/core/src/quantity_price.rs | 4++--
Mcrates/core/src/unit.rs | 16++++++++++++++++
Adto_bindgen.toml | 46++++++++++++++++++++++++++++++++++++++++++++++
14 files changed, 139 insertions(+), 377 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -1502,7 +1502,7 @@ checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" [[package]] name = "dto_bindgen" version = "0.1.0" -source = "git+https://github.com/triesap/dto_bindgen?rev=96ed6c691aacab31860828d25da2e0167b13d92c#96ed6c691aacab31860828d25da2e0167b13d92c" +source = "git+https://github.com/triesap/dto_bindgen?rev=a9e6433b88e95f4424dadd6b5cd7a610aa150dec#a9e6433b88e95f4424dadd6b5cd7a610aa150dec" dependencies = [ "dto_bindgen_backend_python", "dto_bindgen_backend_ts", @@ -1514,7 +1514,7 @@ dependencies = [ [[package]] name = "dto_bindgen_backend_python" version = "0.1.0" -source = "git+https://github.com/triesap/dto_bindgen?rev=96ed6c691aacab31860828d25da2e0167b13d92c#96ed6c691aacab31860828d25da2e0167b13d92c" +source = "git+https://github.com/triesap/dto_bindgen?rev=a9e6433b88e95f4424dadd6b5cd7a610aa150dec#a9e6433b88e95f4424dadd6b5cd7a610aa150dec" dependencies = [ "dto_bindgen_core", ] @@ -1522,7 +1522,7 @@ dependencies = [ [[package]] name = "dto_bindgen_backend_ts" version = "0.1.0" -source = "git+https://github.com/triesap/dto_bindgen?rev=96ed6c691aacab31860828d25da2e0167b13d92c#96ed6c691aacab31860828d25da2e0167b13d92c" +source = "git+https://github.com/triesap/dto_bindgen?rev=a9e6433b88e95f4424dadd6b5cd7a610aa150dec#a9e6433b88e95f4424dadd6b5cd7a610aa150dec" dependencies = [ "dto_bindgen_core", ] @@ -1530,7 +1530,7 @@ dependencies = [ [[package]] name = "dto_bindgen_core" version = "0.1.0" -source = "git+https://github.com/triesap/dto_bindgen?rev=96ed6c691aacab31860828d25da2e0167b13d92c#96ed6c691aacab31860828d25da2e0167b13d92c" +source = "git+https://github.com/triesap/dto_bindgen?rev=a9e6433b88e95f4424dadd6b5cd7a610aa150dec#a9e6433b88e95f4424dadd6b5cd7a610aa150dec" dependencies = [ "proc-macro2", "quote", @@ -1544,7 +1544,7 @@ dependencies = [ [[package]] name = "dto_bindgen_macros" version = "0.1.0" -source = "git+https://github.com/triesap/dto_bindgen?rev=96ed6c691aacab31860828d25da2e0167b13d92c#96ed6c691aacab31860828d25da2e0167b13d92c" +source = "git+https://github.com/triesap/dto_bindgen?rev=a9e6433b88e95f4424dadd6b5cd7a610aa150dec#a9e6433b88e95f4424dadd6b5cd7a610aa150dec" dependencies = [ "proc-macro2", "quote", @@ -4274,7 +4274,7 @@ dependencies = [ name = "radroots_core" version = "0.1.0-alpha.2" dependencies = [ - "dto_bindgen_core", + "dto_bindgen", "rust_decimal", "rust_decimal_macros", "serde", diff --git a/Cargo.toml b/Cargo.toml @@ -58,8 +58,8 @@ homepage = "https://radroots.org" readme = "README" [workspace.dependencies] -dto_bindgen = { git = "https://github.com/triesap/dto_bindgen", rev = "96ed6c691aacab31860828d25da2e0167b13d92c", package = "dto_bindgen" } -dto_bindgen_core = { git = "https://github.com/triesap/dto_bindgen", rev = "96ed6c691aacab31860828d25da2e0167b13d92c", package = "dto_bindgen_core" } +dto_bindgen = { git = "https://github.com/triesap/dto_bindgen", rev = "a9e6433b88e95f4424dadd6b5cd7a610aa150dec", package = "dto_bindgen" } +dto_bindgen_core = { git = "https://github.com/triesap/dto_bindgen", rev = "a9e6433b88e95f4424dadd6b5cd7a610aa150dec", package = "dto_bindgen_core" } radroots_core = { path = "crates/core", version = "0.1.0-alpha.2", default-features = false } radroots_events = { path = "crates/events", version = "0.1.0-alpha.2", default-features = false } radroots_event_store = { path = "crates/event_store", version = "0.1.0-alpha.2", default-features = false } diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml @@ -13,12 +13,12 @@ readme = "README" [features] default = ["std", "serde"] -dto-bindgen = ["std", "serde", "dep:dto_bindgen_core"] +dto-bindgen = ["std", "serde", "dep:dto_bindgen"] std = [] serde = ["dep:serde", "rust_decimal/serde"] [dependencies] -dto_bindgen_core = { workspace = true, optional = true } +dto_bindgen = { workspace = true, optional = true } rust_decimal = { workspace = true, default-features = false } rust_decimal_macros = { workspace = true } serde = { workspace = true, default-features = false, features = [ diff --git a/crates/core/src/currency.rs b/crates/core/src/currency.rs @@ -10,6 +10,8 @@ use std::string::String; #[cfg(feature = "serde")] use serde::{Deserialize, Deserializer, Serialize, Serializer, de::Error as DeError}; +#[cfg_attr(feature = "dto-bindgen", derive(dto_bindgen::Dto))] +#[cfg_attr(feature = "dto-bindgen", dto(as = "string"))] #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct RadrootsCoreCurrency([u8; 3]); diff --git a/crates/core/src/decimal.rs b/crates/core/src/decimal.rs @@ -12,6 +12,8 @@ use alloc::{format, string::ToString}; #[cfg(feature = "serde")] use serde::{Deserialize, Deserializer, Serialize, Serializer, de::Error as DeError}; +#[cfg_attr(feature = "dto-bindgen", derive(dto_bindgen::Dto))] +#[cfg_attr(feature = "dto-bindgen", dto(as = "string"))] #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] pub struct RadrootsCoreDecimal(pub Decimal); diff --git a/crates/core/src/discount.rs b/crates/core/src/discount.rs @@ -4,6 +4,8 @@ use alloc::string::String; use std::string::String; #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "dto-bindgen", derive(dto_bindgen::Dto))] +#[cfg_attr(feature = "dto-bindgen", dto(export))] #[derive(Clone, Debug, PartialEq, Eq)] #[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))] pub enum RadrootsCoreDiscountScope { @@ -12,6 +14,8 @@ pub enum RadrootsCoreDiscountScope { } #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "dto-bindgen", derive(dto_bindgen::Dto))] +#[cfg_attr(feature = "dto-bindgen", dto(export))] #[derive(Clone, Debug, PartialEq, Eq)] #[cfg_attr( feature = "serde", @@ -23,6 +27,8 @@ pub enum RadrootsCoreDiscountThreshold { } #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "dto-bindgen", derive(dto_bindgen::Dto))] +#[cfg_attr(feature = "dto-bindgen", dto(export))] #[derive(Clone, Debug, PartialEq, Eq)] #[cfg_attr( feature = "serde", @@ -34,6 +40,8 @@ pub enum RadrootsCoreDiscountValue { } #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "dto-bindgen", derive(dto_bindgen::Dto))] +#[cfg_attr(feature = "dto-bindgen", dto(export))] #[derive(Clone, Debug, PartialEq, Eq)] #[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))] pub struct RadrootsCoreDiscount { diff --git a/crates/core/src/dto.rs b/crates/core/src/dto.rs @@ -1,376 +1,36 @@ -use dto_bindgen_core::{ - DescribeCtx, Dto, EnumDef, EnumRepr, FieldDef, FieldPresence, IdentName, RootDescriptor, - RustTypeId, SourceSpan, StructDef, TargetFieldNames, TypeDef, TypeRef, VariantDef, - VariantShape, WireFieldNames, -}; +#[path = "generated/dto_roots.rs"] +mod generated_roots; -use crate::{ - RadrootsCoreCurrency, RadrootsCoreDecimal, RadrootsCoreDiscount, RadrootsCoreDiscountScope, - RadrootsCoreDiscountThreshold, RadrootsCoreDiscountValue, RadrootsCoreMoney, - RadrootsCorePercent, RadrootsCoreQuantity, RadrootsCoreQuantityPrice, RadrootsCoreUnit, - RadrootsCoreUnitDimension, -}; - -pub fn dto_roots() -> [RootDescriptor; 10] { - [ - RootDescriptor::new::<RadrootsCoreDiscount>(), - RootDescriptor::new::<RadrootsCoreDiscountScope>(), - RootDescriptor::new::<RadrootsCoreDiscountThreshold>(), - RootDescriptor::new::<RadrootsCoreDiscountValue>(), - RootDescriptor::new::<RadrootsCoreMoney>(), - RootDescriptor::new::<RadrootsCorePercent>(), - RootDescriptor::new::<RadrootsCoreQuantity>(), - RootDescriptor::new::<RadrootsCoreQuantityPrice>(), - RootDescriptor::new::<RadrootsCoreUnit>(), - RootDescriptor::new::<RadrootsCoreUnitDimension>(), - ] -} - -impl Dto for RadrootsCoreCurrency { - fn describe(_ctx: &mut DescribeCtx) -> TypeRef { - TypeRef::String - } -} - -impl Dto for RadrootsCoreDecimal { - fn describe(_ctx: &mut DescribeCtx) -> TypeRef { - TypeRef::String - } -} - -impl Dto for RadrootsCoreUnitDimension { - fn describe(ctx: &mut DescribeCtx) -> TypeRef { - let def = EnumDef::new( - "RadrootsCoreUnitDimension", - "RadrootsCoreUnitDimension", - EnumRepr::External, - span("crates/core/src/unit.rs", 17), - ) - .with_variant(unit_variant( - "Count", - "count", - "crates/core/src/unit.rs", - 18, - )) - .with_variant(unit_variant("Mass", "mass", "crates/core/src/unit.rs", 19)) - .with_variant(unit_variant( - "Volume", - "volume", - "crates/core/src/unit.rs", - 20, - )); - register(ctx, "RadrootsCoreUnitDimension", TypeDef::Enum(def)) - } -} - -impl Dto for RadrootsCoreUnit { - fn describe(ctx: &mut DescribeCtx) -> TypeRef { - let def = EnumDef::new( - "RadrootsCoreUnit", - "RadrootsCoreUnit", - EnumRepr::External, - span("crates/core/src/unit.rs", 24), - ) - .with_variant(unit_variant("Each", "each", "crates/core/src/unit.rs", 25)) - .with_variant(unit_variant("MassKg", "kg", "crates/core/src/unit.rs", 26)) - .with_variant(unit_variant("MassG", "g", "crates/core/src/unit.rs", 27)) - .with_variant(unit_variant("MassOz", "oz", "crates/core/src/unit.rs", 28)) - .with_variant(unit_variant("MassLb", "lb", "crates/core/src/unit.rs", 29)) - .with_variant(unit_variant("VolumeL", "l", "crates/core/src/unit.rs", 30)) - .with_variant(unit_variant( - "VolumeMl", - "ml", - "crates/core/src/unit.rs", - 31, - )); - register(ctx, "RadrootsCoreUnit", TypeDef::Enum(def)) - } -} - -impl Dto for RadrootsCoreMoney { - fn describe(ctx: &mut DescribeCtx) -> TypeRef { - let def = StructDef::new( - "RadrootsCoreMoney", - "RadrootsCoreMoney", - span("crates/core/src/money.rs", 8), - ) - .with_field(field( - "amount", - "amount", - RadrootsCoreDecimal::describe(ctx), - "crates/core/src/money.rs", - 9, - )) - .with_field(field( - "currency", - "currency", - RadrootsCoreCurrency::describe(ctx), - "crates/core/src/money.rs", - 10, - )); - register(ctx, "RadrootsCoreMoney", TypeDef::Struct(def)) - } -} - -impl Dto for RadrootsCorePercent { - fn describe(ctx: &mut DescribeCtx) -> TypeRef { - let def = StructDef::new( - "RadrootsCorePercent", - "RadrootsCorePercent", - span("crates/core/src/percent.rs", 9), - ) - .with_field(field( - "value", - "value", - RadrootsCoreDecimal::describe(ctx), - "crates/core/src/percent.rs", - 10, - )); - register(ctx, "RadrootsCorePercent", TypeDef::Struct(def)) - } -} - -impl Dto for RadrootsCoreQuantity { - fn describe(ctx: &mut DescribeCtx) -> TypeRef { - let unit = RadrootsCoreUnit::describe(ctx); - let def = StructDef::new( - "RadrootsCoreQuantity", - "RadrootsCoreQuantity", - span("crates/core/src/quantity.rs", 13), - ) - .with_field(field( - "amount", - "amount", - RadrootsCoreDecimal::describe(ctx), - "crates/core/src/quantity.rs", - 14, - )) - .with_field(field( - "unit", - "unit", - unit, - "crates/core/src/quantity.rs", - 16, - )) - .with_field( - field( - "label", - "label", - <Option<String> as Dto>::describe(ctx), - "crates/core/src/quantity.rs", - 18, - ) - .with_presence(FieldPresence::optional_nullable_skip_if_none()), - ); - register(ctx, "RadrootsCoreQuantity", TypeDef::Struct(def)) - } -} - -impl Dto for RadrootsCoreQuantityPrice { - fn describe(ctx: &mut DescribeCtx) -> TypeRef { - let amount = RadrootsCoreMoney::describe(ctx); - let quantity = RadrootsCoreQuantity::describe(ctx); - let def = StructDef::new( - "RadrootsCoreQuantityPrice", - "RadrootsCoreQuantityPrice", - span("crates/core/src/quantity_price.rs", 5), - ) - .with_field(field( - "amount", - "amount", - amount, - "crates/core/src/quantity_price.rs", - 7, - )) - .with_field(field( - "quantity", - "quantity", - quantity, - "crates/core/src/quantity_price.rs", - 9, - )); - register(ctx, "RadrootsCoreQuantityPrice", TypeDef::Struct(def)) - } -} - -impl Dto for RadrootsCoreDiscountScope { - fn describe(ctx: &mut DescribeCtx) -> TypeRef { - let def = EnumDef::new( - "RadrootsCoreDiscountScope", - "RadrootsCoreDiscountScope", - EnumRepr::External, - span("crates/core/src/discount.rs", 9), - ) - .with_variant(unit_variant( - "Bin", - "bin", - "crates/core/src/discount.rs", - 10, - )) - .with_variant(unit_variant( - "OrderTotal", - "order_total", - "crates/core/src/discount.rs", - 11, - )); - register(ctx, "RadrootsCoreDiscountScope", TypeDef::Enum(def)) - } -} - -impl Dto for RadrootsCoreDiscountThreshold { - fn describe(ctx: &mut DescribeCtx) -> TypeRef { - let quantity = RadrootsCoreQuantity::describe(ctx); - let def = EnumDef::new( - "RadrootsCoreDiscountThreshold", - "RadrootsCoreDiscountThreshold", - EnumRepr::Adjacent { - tag: "kind".to_owned(), - content: "amount".to_owned(), - }, - span("crates/core/src/discount.rs", 20), - ) - .with_variant(VariantDef::new( - "BinCount", - "bin_count", - VariantShape::Struct(vec![ - field( - "bin_id", - "bin_id", - String::describe(ctx), - "crates/core/src/discount.rs", - 21, - ), - field( - "min", - "min", - u32::describe(ctx), - "crates/core/src/discount.rs", - 21, - ), - ]), - span("crates/core/src/discount.rs", 21), - )) - .with_variant(VariantDef::new( - "OrderQuantity", - "order_quantity", - VariantShape::Struct(vec![field( - "min", - "min", - quantity, - "crates/core/src/discount.rs", - 22, - )]), - span("crates/core/src/discount.rs", 22), - )); - register(ctx, "RadrootsCoreDiscountThreshold", TypeDef::Enum(def)) - } -} - -impl Dto for RadrootsCoreDiscountValue { - fn describe(ctx: &mut DescribeCtx) -> TypeRef { - let money = RadrootsCoreMoney::describe(ctx); - let percent = RadrootsCorePercent::describe(ctx); - let def = EnumDef::new( - "RadrootsCoreDiscountValue", - "RadrootsCoreDiscountValue", - EnumRepr::Adjacent { - tag: "kind".to_owned(), - content: "amount".to_owned(), - }, - span("crates/core/src/discount.rs", 31), - ) - .with_variant(VariantDef::new( - "MoneyPerBin", - "money_per_bin", - VariantShape::Newtype(money), - span("crates/core/src/discount.rs", 32), - )) - .with_variant(VariantDef::new( - "Percent", - "percent", - VariantShape::Newtype(percent), - span("crates/core/src/discount.rs", 33), - )); - register(ctx, "RadrootsCoreDiscountValue", TypeDef::Enum(def)) - } -} - -impl Dto for RadrootsCoreDiscount { - fn describe(ctx: &mut DescribeCtx) -> TypeRef { - let scope = RadrootsCoreDiscountScope::describe(ctx); - let threshold = RadrootsCoreDiscountThreshold::describe(ctx); - let value = RadrootsCoreDiscountValue::describe(ctx); - let def = StructDef::new( - "RadrootsCoreDiscount", - "RadrootsCoreDiscount", - span("crates/core/src/discount.rs", 39), - ) - .with_field(field( - "scope", - "scope", - scope, - "crates/core/src/discount.rs", - 40, - )) - .with_field(field( - "threshold", - "threshold", - threshold, - "crates/core/src/discount.rs", - 41, - )) - .with_field(field( - "value", - "value", - value, - "crates/core/src/discount.rs", - 42, - )); - register(ctx, "RadrootsCoreDiscount", TypeDef::Struct(def)) - } -} - -fn register(ctx: &mut DescribeCtx, rust_ident: &str, type_def: TypeDef) -> TypeRef { - ctx.register_type(RustTypeId::new("radroots_core", rust_ident), type_def) -} - -fn unit_variant(rust_name: &str, wire_name: &str, file: &str, line: u32) -> VariantDef { - VariantDef::new(rust_name, wire_name, VariantShape::Unit, span(file, line)) -} - -fn field(rust_name: &str, wire_name: &str, ty: TypeRef, file: &str, line: u32) -> FieldDef { - FieldDef::new( - IdentName::new(rust_name), - WireFieldNames::same(wire_name), - TargetFieldNames::new(wire_name, rust_name), - ty, - span(file, line), - ) -} - -fn span(file: &str, line: u32) -> SourceSpan { - SourceSpan::new(file, line, 1) -} +pub use generated_roots::dto_bindgen_roots as dto_roots; #[cfg(test)] mod tests { - use dto_bindgen_core::{TypeDef, build_registry}; - use super::dto_roots; #[test] - fn core_descriptor_roots_build_registry() { - let registry = build_registry(dto_roots()); + fn generated_core_roots_build_registry() { + let roots = dto_roots(); + let registry = dto_bindgen::export::build_registry(roots.iter().copied()); assert!(!registry.has_errors()); - assert_eq!(registry.roots.len(), dto_roots().len()); - assert!(registry.types_by_id.values().any( - |def| matches!(def, TypeDef::Struct(def) if def.export_name == "RadrootsCoreMoney") - )); - assert!( - registry.types_by_id.values().any( - |def| matches!(def, TypeDef::Enum(def) if def.export_name == "RadrootsCoreUnit") - ) - ); + assert_eq!(registry.roots.len(), roots.len()); + } + + #[test] + fn generated_core_roots_plan_typescript_bindings() { + let roots = dto_roots(); + let config_path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../..") + .join("dto_bindgen.toml"); + let report = dto_bindgen::export::plan_with_roots( + dto_bindgen::export::ExportOptions::new(config_path), + roots.iter().copied(), + ) + .unwrap(); + + assert!(report.diagnostics.is_empty()); + assert_eq!(report.registry.roots.len(), roots.len()); + assert!(report.files.iter().any(|path| path.ends_with("types.ts"))); + assert!(report.files.iter().any(|path| path.ends_with("index.ts"))); } } diff --git a/crates/core/src/generated/dto_roots.rs b/crates/core/src/generated/dto_roots.rs @@ -0,0 +1,20 @@ +// @generated by dto_bindgen +// Do not edit by hand. + +pub fn dto_bindgen_roots() -> ::std::vec::Vec<::dto_bindgen::export::RootDescriptor> { + ::std::vec![ + ::dto_bindgen::export::RootDescriptor::new::<crate::discount::RadrootsCoreDiscount>(), + ::dto_bindgen::export::RootDescriptor::new::<crate::discount::RadrootsCoreDiscountScope>(), + ::dto_bindgen::export::RootDescriptor::new::<crate::discount::RadrootsCoreDiscountThreshold>( + ), + ::dto_bindgen::export::RootDescriptor::new::<crate::discount::RadrootsCoreDiscountValue>(), + ::dto_bindgen::export::RootDescriptor::new::<crate::money::RadrootsCoreMoney>(), + ::dto_bindgen::export::RootDescriptor::new::<crate::percent::RadrootsCorePercent>(), + ::dto_bindgen::export::RootDescriptor::new::<crate::quantity::RadrootsCoreQuantity>(), + ::dto_bindgen::export::RootDescriptor::new::< + crate::quantity_price::RadrootsCoreQuantityPrice, + >(), + ::dto_bindgen::export::RootDescriptor::new::<crate::unit::RadrootsCoreUnit>(), + ::dto_bindgen::export::RootDescriptor::new::<crate::unit::RadrootsCoreUnitDimension>(), + ] +} diff --git a/crates/core/src/money.rs b/crates/core/src/money.rs @@ -4,6 +4,8 @@ use rust_decimal::RoundingStrategy; use rust_decimal::prelude::ToPrimitive; #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "dto-bindgen", derive(dto_bindgen::Dto))] +#[cfg_attr(feature = "dto-bindgen", dto(export))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct RadrootsCoreMoney { pub amount: crate::RadrootsCoreDecimal, diff --git a/crates/core/src/percent.rs b/crates/core/src/percent.rs @@ -5,9 +5,12 @@ use crate::RadrootsCoreDecimal; use crate::money::RadrootsCoreMoney; #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "dto-bindgen", derive(dto_bindgen::Dto))] +#[cfg_attr(feature = "dto-bindgen", dto(export))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct RadrootsCorePercent { #[cfg_attr(feature = "serde", serde(with = "crate::serde_ext::decimal_str"))] + #[cfg_attr(feature = "dto-bindgen", dto(as = "string"))] pub value: RadrootsCoreDecimal, } diff --git a/crates/core/src/quantity.rs b/crates/core/src/quantity.rs @@ -9,9 +9,12 @@ use alloc::string::String; use std::string::String; #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "dto-bindgen", derive(dto_bindgen::Dto))] +#[cfg_attr(feature = "dto-bindgen", dto(export))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct RadrootsCoreQuantity { #[cfg_attr(feature = "serde", serde(with = "crate::serde_ext::decimal_str"))] + #[cfg_attr(feature = "dto-bindgen", dto(as = "string"))] pub amount: RadrootsCoreDecimal, pub unit: RadrootsCoreUnit, #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))] diff --git a/crates/core/src/quantity_price.rs b/crates/core/src/quantity_price.rs @@ -1,11 +1,11 @@ use crate::{RadrootsCoreDecimal, RadrootsCoreMoney, RadrootsCoreQuantity, RadrootsCoreUnit}; #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "dto-bindgen", derive(dto_bindgen::Dto))] +#[cfg_attr(feature = "dto-bindgen", dto(export))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct RadrootsCoreQuantityPrice { - #[cfg_attr(feature = "serde", serde(alias = "money", alias = "price"))] pub amount: RadrootsCoreMoney, - #[cfg_attr(feature = "serde", serde(alias = "per", alias = "quantity"))] pub quantity: RadrootsCoreQuantity, } diff --git a/crates/core/src/unit.rs b/crates/core/src/unit.rs @@ -13,21 +13,37 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer, de::Error as DeErr use crate::RadrootsCoreDecimal; +#[cfg_attr(feature = "dto-bindgen", derive(dto_bindgen::Dto))] +#[cfg_attr(feature = "dto-bindgen", dto(export))] +#[cfg_attr(feature = "dto-bindgen", dto(as = "string_enum"))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum RadrootsCoreUnitDimension { + #[cfg_attr(feature = "dto-bindgen", dto(rename = "count"))] Count, + #[cfg_attr(feature = "dto-bindgen", dto(rename = "mass"))] Mass, + #[cfg_attr(feature = "dto-bindgen", dto(rename = "volume"))] Volume, } +#[cfg_attr(feature = "dto-bindgen", derive(dto_bindgen::Dto))] +#[cfg_attr(feature = "dto-bindgen", dto(export))] +#[cfg_attr(feature = "dto-bindgen", dto(as = "string_enum"))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum RadrootsCoreUnit { + #[cfg_attr(feature = "dto-bindgen", dto(rename = "each"))] Each, + #[cfg_attr(feature = "dto-bindgen", dto(rename = "kg"))] MassKg, + #[cfg_attr(feature = "dto-bindgen", dto(rename = "g"))] MassG, + #[cfg_attr(feature = "dto-bindgen", dto(rename = "oz"))] MassOz, + #[cfg_attr(feature = "dto-bindgen", dto(rename = "lb"))] MassLb, + #[cfg_attr(feature = "dto-bindgen", dto(rename = "l"))] VolumeL, + #[cfg_attr(feature = "dto-bindgen", dto(rename = "ml"))] VolumeMl, } diff --git a/dto_bindgen.toml b/dto_bindgen.toml @@ -0,0 +1,46 @@ +schema_version = 1 + +[export] +out_dir = "target/dto-bindgen" +emit_docs = false +wire_format = "json" + +[numeric] +large_int_policy = "require_explicit" + +[typescript] +enabled = true +out_dir = "target/dto-bindgen/core-bindings" +wire_contract = "json_exchange" +layout = "bundle" +bundle_file = "types.ts" +emit = "ts" +module_resolution = "bundler" +import_extension = "none" +type_only_imports = true +strict_null_checks_required = true +style = "dto_bindgen" + +[python] +enabled = false + +[[package]] +key = "core" +rust_package = "radroots_core" +rust_crate = "radroots_core" +npm = "@radroots/core-bindings" +out_dir = "target/dto-bindgen/core-bindings" + +[package.root_discovery] +mode = "source_manifest" +source_files = [ + "crates/core/src/currency.rs", + "crates/core/src/decimal.rs", + "crates/core/src/discount.rs", + "crates/core/src/money.rs", + "crates/core/src/percent.rs", + "crates/core/src/quantity.rs", + "crates/core/src/quantity_price.rs", + "crates/core/src/unit.rs", +] +root_module_file = "crates/core/src/generated/dto_roots.rs"