lib

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

commit cecaf705e888815821007710503389c2fe357883
parent 2b2e8ee930ae5ec78f2bc960e2b099926ccac6b4
Author: triesap <tyson@radroots.org>
Date:   Sat, 27 Jun 2026 10:25:27 +0000

bindings: align dto source-root generation

- pin dto_bindgen to the pushed source-root closeout revision
- update SDK registry helpers for three-part Rust type identities
- regenerate events and trade TypeScript bindings from source roots
- keep trade overlay order DTOs local to the SDK package surface

Diffstat:
Mcrates/trade_bindings/src/dto.rs | 191+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
Mcrates/trade_bindings/src/lib.rs | 8++++----
Mtools/sdk_xtask_import/src/dto_render.rs | 34++++++++++++++++------------------
Mtools/sdk_xtask_import/src/dto_roots.rs | 51+++++++++++++++++++++++++--------------------------
4 files changed, 222 insertions(+), 62 deletions(-)

diff --git a/crates/trade_bindings/src/dto.rs b/crates/trade_bindings/src/dto.rs @@ -10,6 +10,9 @@ pub fn dto_roots() -> Vec<RootDescriptor> { .into_iter() .collect::<Vec<_>>(); roots.extend([ + RootDescriptor::new::<RadrootsCommercialMessagePayload>(), + RootDescriptor::new::<RadrootsCommercialMessageType>(), + RootDescriptor::new::<RadrootsOrderStatus>(), RootDescriptor::new::<RadrootsTradeFacetCount>(), RootDescriptor::new::<RadrootsTradeListingBackofficeOverlay>(), RootDescriptor::new::<RadrootsTradeListingBackofficeQuery>(), @@ -82,17 +85,158 @@ imported_ts_type!(RadrootsListingProductImport, "RadrootsListingProduct"); imported_ts_type!(RadrootsNostrEventPtrImport, "RadrootsNostrEventPtr"); imported_ts_type!(RadrootsPlotRefImport, "RadrootsPlotRef"); imported_ts_type!(RadrootsResourceAreaRefImport, "RadrootsResourceAreaRef"); +imported_ts_type!(RadrootsOrderCancellationImport, "RadrootsOrderCancellation"); +imported_ts_type!(RadrootsOrderDecisionImport, "RadrootsOrderDecision"); +imported_ts_type!(RadrootsOrderEconomicLineImport, "RadrootsOrderEconomicLine"); +imported_ts_type!(RadrootsOrderItemImport, "RadrootsOrderItem"); +imported_ts_type!(RadrootsOrderRequestImport, "RadrootsOrderRequest"); imported_ts_type!( - RadrootsCommercialMessagePayloadImport, - "RadrootsCommercialMessagePayload" + RadrootsOrderRevisionDecisionImport, + "RadrootsOrderRevisionDecision" ); imported_ts_type!( - RadrootsCommercialMessageTypeImport, - "RadrootsCommercialMessageType" + RadrootsOrderRevisionProposalImport, + "RadrootsOrderRevisionProposal" +); +imported_ts_type!( + RadrootsTradeListingValidateRequestImport, + "RadrootsTradeListingValidateRequest" +); +imported_ts_type!( + RadrootsTradeListingValidateResultImport, + "RadrootsTradeListingValidateResult" ); -imported_ts_type!(RadrootsOrderEconomicLineImport, "RadrootsOrderEconomicLine"); -imported_ts_type!(RadrootsOrderItemImport, "RadrootsOrderItem"); -imported_ts_type!(RadrootsOrderStatusImport, "RadrootsOrderStatus"); + +pub enum RadrootsCommercialMessagePayload { + ListingValidateRequest, + ListingValidateResult, + TradeOrderRequested, + OrderDecision, + OrderRevisionProposal, + OrderRevisionDecisionAccepted, + OrderRevisionDecisionDeclined, + Cancel, +} + +impl Dto for RadrootsCommercialMessagePayload { + fn describe(ctx: &mut DescribeCtx) -> TypeRef { + let def = EnumDef::new( + "RadrootsCommercialMessagePayload", + "RadrootsCommercialMessagePayload", + EnumRepr::External, + span("crates/trade_bindings/src/dto.rs", 97), + ) + .with_variant(payload_variant( + "ListingValidateRequest", + "listing_validate_request", + RadrootsTradeListingValidateRequestImport::describe(ctx), + "crates/trade_bindings/src/dto.rs", + 99, + )) + .with_variant(payload_variant( + "ListingValidateResult", + "listing_validate_result", + RadrootsTradeListingValidateResultImport::describe(ctx), + "crates/trade_bindings/src/dto.rs", + 100, + )) + .with_variant(payload_variant( + "TradeOrderRequested", + "trade_order_requested", + RadrootsOrderRequestImport::describe(ctx), + "crates/trade_bindings/src/dto.rs", + 101, + )) + .with_variant(payload_variant( + "OrderDecision", + "order_response", + RadrootsOrderDecisionImport::describe(ctx), + "crates/trade_bindings/src/dto.rs", + 102, + )) + .with_variant(payload_variant( + "OrderRevisionProposal", + "order_revision", + RadrootsOrderRevisionProposalImport::describe(ctx), + "crates/trade_bindings/src/dto.rs", + 103, + )) + .with_variant(payload_variant( + "OrderRevisionDecisionAccepted", + "order_revision_accept", + RadrootsOrderRevisionDecisionImport::describe(ctx), + "crates/trade_bindings/src/dto.rs", + 104, + )) + .with_variant(payload_variant( + "OrderRevisionDecisionDeclined", + "order_revision_decline", + RadrootsOrderRevisionDecisionImport::describe(ctx), + "crates/trade_bindings/src/dto.rs", + 105, + )) + .with_variant(payload_variant( + "Cancel", + "cancel", + RadrootsOrderCancellationImport::describe(ctx), + "crates/trade_bindings/src/dto.rs", + 106, + )); + register(ctx, "RadrootsCommercialMessagePayload", TypeDef::Enum(def)) + } +} + +#[derive(dto_bindgen::Dto)] +pub enum RadrootsCommercialMessageType { + #[serde(rename = "listing_validate_request")] + ListingValidateRequest, + #[serde(rename = "listing_validate_result")] + ListingValidateResult, + #[serde(rename = "order_request")] + OrderRequest, + #[serde(rename = "order_response")] + OrderResponse, + #[serde(rename = "order_revision")] + OrderRevision, + #[serde(rename = "order_revision_accept")] + OrderRevisionAccept, + #[serde(rename = "order_revision_decline")] + OrderRevisionDecline, + #[serde(rename = "question")] + Question, + #[serde(rename = "answer")] + Answer, + #[serde(rename = "discount_request")] + DiscountRequest, + #[serde(rename = "discount_offer")] + DiscountOffer, + #[serde(rename = "discount_accept")] + DiscountAccept, + #[serde(rename = "discount_decline")] + DiscountDecline, + #[serde(rename = "cancel")] + Cancel, +} + +#[derive(dto_bindgen::Dto)] +pub enum RadrootsOrderStatus { + #[serde(rename = "draft")] + Draft, + #[serde(rename = "validated")] + Validated, + #[serde(rename = "requested")] + Requested, + #[serde(rename = "questioned")] + Questioned, + #[serde(rename = "revised")] + Revised, + #[serde(rename = "accepted")] + Accepted, + #[serde(rename = "declined")] + Declined, + #[serde(rename = "cancelled")] + Cancelled, +} #[derive(dto_bindgen::Dto)] pub struct RadrootsTradeFacetCount { @@ -278,8 +422,8 @@ pub struct RadrootsTradeMarketplaceOrderSummary { pub listing_addr: String, pub buyer_pubkey: String, pub seller_pubkey: String, - pub status: RadrootsOrderStatusImport, - pub last_message_type: RadrootsCommercialMessageTypeImport, + pub status: RadrootsOrderStatus, + pub last_message_type: RadrootsCommercialMessageType, pub item_count: u32, pub total_bin_count: u32, pub has_requested_discounts: bool, @@ -351,7 +495,7 @@ pub struct RadrootsTradeOrderQuery { pub listing_addr: Option<String>, pub buyer_pubkey: Option<String>, pub seller_pubkey: Option<String>, - pub status: Option<RadrootsOrderStatusImport>, + pub status: Option<RadrootsOrderStatus>, } #[derive(dto_bindgen::Dto)] @@ -388,7 +532,7 @@ pub struct RadrootsTradeOrderWorkflowMessage { pub listing_event: Option<RadrootsNostrEventPtrImport>, pub root_event_id: Option<String>, pub prev_event_id: Option<String>, - pub payload: RadrootsCommercialMessagePayloadImport, + pub payload: RadrootsCommercialMessagePayload, } #[derive(dto_bindgen::Dto)] @@ -399,7 +543,7 @@ pub struct RadrootsTradeOrderWorkflowProjection { pub seller_pubkey: String, pub items: Vec<RadrootsOrderItemImport>, pub requested_discounts: Option<Vec<RadrootsOrderEconomicLineImport>>, - pub status: RadrootsOrderStatusImport, + pub status: RadrootsOrderStatus, pub listing_snapshot: Option<RadrootsNostrEventPtrImport>, pub root_event_id: String, pub last_event_id: String, @@ -416,7 +560,7 @@ pub struct RadrootsTradeOrderWorkflowProjection { pub discount_accept_count: u32, pub discount_decline_count: u32, pub cancellation_count: u32, - pub last_message_type: RadrootsCommercialMessageTypeImport, + pub last_message_type: RadrootsCommercialMessageType, pub last_actor_pubkey: String, } @@ -463,7 +607,11 @@ pub enum RadrootsTradeSortDirection { fn register(ctx: &mut DescribeCtx, rust_ident: &str, type_def: TypeDef) -> TypeRef { ctx.register_type( - RustTypeId::new("radroots_trade_bindings", rust_ident), + RustTypeId::new( + "radroots_trade_bindings", + "radroots_trade_bindings", + rust_ident, + ), type_def, ) } @@ -472,6 +620,21 @@ fn unit_variant(rust_name: &str, wire_name: &str, file: &str, line: u32) -> Vari VariantDef::new(rust_name, wire_name, VariantShape::Unit, span(file, line)) } +fn payload_variant( + rust_name: &str, + wire_name: &str, + ty: TypeRef, + file: &str, + line: u32, +) -> VariantDef { + VariantDef::new( + rust_name, + wire_name, + VariantShape::Newtype(ty), + span(file, line), + ) +} + fn field(rust_name: &str, wire_name: &str, ty: TypeRef, file: &str, line: u32) -> FieldDef { FieldDef::new( IdentName::new(rust_name), diff --git a/crates/trade_bindings/src/lib.rs b/crates/trade_bindings/src/lib.rs @@ -54,7 +54,8 @@ pub const TRADE_TYPE_INVENTORY: &[TradeTypeInventoryEntry] = &[ source_root("RadrootsTradeListingTotal"), local_shape("RadrootsTradeMarketplaceListingSummary"), local_shape("RadrootsTradeMarketplaceOrderSummary"), - event_import("RadrootsCommercialMessageType"), + local_shape("RadrootsCommercialMessagePayload"), + local_shape("RadrootsCommercialMessageType"), local_shape("RadrootsTradeModerationFlag"), local_shape("RadrootsTradeModerationSeverity"), local_shape("RadrootsTradeModerationStatus"), @@ -65,7 +66,7 @@ pub const TRADE_TYPE_INVENTORY: &[TradeTypeInventoryEntry] = &[ local_shape("RadrootsTradeOrderQuery"), local_shape("RadrootsTradeOrderSort"), local_shape("RadrootsTradeOrderSortField"), - event_import("RadrootsOrderStatus"), + local_shape("RadrootsOrderStatus"), local_shape("RadrootsTradeOrderWorkflowMessage"), local_shape("RadrootsTradeOrderWorkflowProjection"), local_shape("RadrootsTradeReviewPriority"), @@ -200,6 +201,7 @@ mod tests { "RadrootsTradeListingTotal", "RadrootsTradeMarketplaceListingSummary", "RadrootsTradeMarketplaceOrderSummary", + "RadrootsCommercialMessagePayload", "RadrootsCommercialMessageType", "RadrootsTradeModerationFlag", "RadrootsTradeModerationSeverity", @@ -233,8 +235,6 @@ mod tests { "RadrootsListingProduct", "RadrootsListingPublicLocation", "RadrootsListingStatus", - "RadrootsCommercialMessageType", - "RadrootsOrderStatus", ] { assert_eq!( disposition(export_name), diff --git a/tools/sdk_xtask_import/src/dto_render.rs b/tools/sdk_xtask_import/src/dto_render.rs @@ -487,15 +487,13 @@ fn render_primitive( if primitive.requires_explicit_integer_policy() { return match int_repr { Some(IntRepr::JsonString) => Ok("string".to_owned()), - Some(IntRepr::JsonNumberUnsafe) => Ok("number".to_owned()), - Some(IntRepr::NonJsonBigint) => Ok("bigint".to_owned()), + Some(IntRepr::JsonNumber) => Ok("number".to_owned()), None => match options.config.numeric.large_int_policy { LargeIntPolicy::RequireExplicit => { Err("large integer field requires explicit numeric policy".to_owned()) } LargeIntPolicy::JsonString => Ok("string".to_owned()), - LargeIntPolicy::JsonNumberUnsafe => Ok("number".to_owned()), - LargeIntPolicy::NonJsonBigint => Ok("bigint".to_owned()), + LargeIntPolicy::JsonNumber => Ok("number".to_owned()), }, }; } @@ -642,7 +640,7 @@ mod tests { fn renders_synthetic_registry_as_package_level_types() { let mut registry = Registry::new(); let external_id = registry.register_type( - RustTypeId::new("external", "ExternalThing"), + RustTypeId::new("external", "external", "ExternalThing"), TypeDef::Struct(StructDef::new("ExternalThing", "ExternalThing", span())), ); let envelope = TypeDef::Struct(StructDef { @@ -653,7 +651,7 @@ mod tests { TypeRef::GenericParam("T".to_owned()), )) }); - registry.register_type(RustTypeId::new("sdk", "Envelope"), envelope); + registry.register_type(RustTypeId::new("sdk", "sdk", "Envelope"), envelope); let thing = TypeDef::Struct( StructDef::new("SyntheticThing", "SyntheticThing", span()) .with_field(field("external", "external", TypeRef::Named(external_id))) @@ -680,7 +678,7 @@ mod tests { )), )), ); - registry.register_type(RustTypeId::new("sdk", "SyntheticThing"), thing); + registry.register_type(RustTypeId::new("sdk", "sdk", "SyntheticThing"), thing); let mode = TypeDef::Enum( EnumDef::new("SyntheticMode", "SyntheticMode", EnumRepr::External, span()) .with_variant(VariantDef::new( @@ -691,7 +689,7 @@ mod tests { )) .with_variant(VariantDef::new("Done", "done", VariantShape::Unit, span())), ); - registry.register_type(RustTypeId::new("sdk", "SyntheticMode"), mode); + registry.register_type(RustTypeId::new("sdk", "sdk", "SyntheticMode"), mode); let event = TypeDef::Enum( EnumDef::new( "SyntheticEvent", @@ -718,7 +716,7 @@ mod tests { span(), )), ); - registry.register_type(RustTypeId::new("sdk", "SyntheticEvent"), event); + registry.register_type(RustTypeId::new("sdk", "sdk", "SyntheticEvent"), event); let rendered = render_registry_types( &registry, @@ -744,7 +742,7 @@ mod tests { fn imports_typescript_overrides_when_configured() { let mut registry = Registry::new(); registry.register_type( - RustTypeId::new("sdk", "SyntheticThing"), + RustTypeId::new("sdk", "sdk", "SyntheticThing"), TypeDef::Struct( StructDef::new("SyntheticThing", "SyntheticThing", span()).with_field(field( "external", @@ -778,7 +776,7 @@ mod tests { fn renders_untagged_object_unions() { let mut registry = Registry::new(); registry.register_type( - RustTypeId::new("sdk", "Query"), + RustTypeId::new("sdk", "sdk", "Query"), TypeDef::Enum( EnumDef::new("Query", "Query", EnumRepr::Untagged, span()) .with_variant(VariantDef::new( @@ -809,7 +807,7 @@ mod tests { fn renders_untagged_newtype_aliases() { let mut registry = Registry::new(); registry.register_type( - RustTypeId::new("sdk", "FindOneResolve"), + RustTypeId::new("sdk", "sdk", "FindOneResolve"), TypeDef::Enum( EnumDef::new( "FindOneResolve", @@ -842,7 +840,7 @@ mod tests { fn rejects_untagged_unit_variants() { let mut registry = Registry::new(); registry.register_type( - RustTypeId::new("sdk", "MaybeReady"), + RustTypeId::new("sdk", "sdk", "MaybeReady"), TypeDef::Enum( EnumDef::new("MaybeReady", "MaybeReady", EnumRepr::Untagged, span()).with_variant( VariantDef::new("Ready", "ready", VariantShape::Unit, span()), @@ -863,7 +861,7 @@ mod tests { fn requires_explicit_large_integer_policy() { let mut registry = Registry::new(); registry.register_type( - RustTypeId::new("sdk", "Counter"), + RustTypeId::new("sdk", "sdk", "Counter"), TypeDef::Struct( StructDef::new("Counter", "Counter", span()).with_field(field( "value", @@ -886,16 +884,16 @@ mod tests { fn propagates_integer_policy_through_transparent_containers_only() { let mut registry = Registry::new(); let counter_id = registry.register_type( - RustTypeId::new("sdk", "Counter"), + RustTypeId::new("sdk", "sdk", "Counter"), TypeDef::Struct( StructDef::new("Counter", "Counter", span()).with_field( field("value", "value", TypeRef::Primitive(Primitive::U64)) - .with_int_repr(IntRepr::JsonNumberUnsafe), + .with_int_repr(IntRepr::JsonNumber), ), ), ); registry.register_type( - RustTypeId::new("sdk", "TransparentCounters"), + RustTypeId::new("sdk", "sdk", "TransparentCounters"), TypeDef::Struct( StructDef::new("TransparentCounters", "TransparentCounters", span()) .with_field( @@ -954,7 +952,7 @@ mod tests { fn renders_external_data_enums() { let mut registry = Registry::new(); registry.register_type( - RustTypeId::new("sdk", "ParseError"), + RustTypeId::new("sdk", "sdk", "ParseError"), TypeDef::Enum( EnumDef::new("ParseError", "ParseError", EnumRepr::External, span()) .with_variant(VariantDef::new( diff --git a/tools/sdk_xtask_import/src/dto_roots.rs b/tools/sdk_xtask_import/src/dto_roots.rs @@ -1,4 +1,4 @@ -use dto_bindgen_core::{Registry, RootDescriptor, RustTypeId, TypeId, build_registry}; +use dto_bindgen_core::{Registry, RootDescriptor, TypeDef, TypeId, build_registry}; use crate::dto_render::{DtoRegistryRenderOptions, DtoTypesModule, render_registry_types}; @@ -235,9 +235,13 @@ fn core_import_options( fn core_type_id(registry: &Registry, rust_ident: &str) -> Option<TypeId> { registry - .rust_id_to_type_id - .get(&RustTypeId::new("radroots_core", rust_ident)) - .copied() + .types_by_id + .iter() + .find_map(|(type_id, type_def)| match type_def { + TypeDef::Struct(def) if def.export_name == rust_ident => Some(*type_id), + TypeDef::Enum(def) if def.export_name == rust_ident => Some(*type_id), + _ => None, + }) } fn trade_import_options(mut options: DtoRegistryRenderOptions) -> DtoRegistryRenderOptions { @@ -266,13 +270,17 @@ fn trade_import_options(mut options: DtoRegistryRenderOptions) -> DtoRegistryRen "RadrootsListingPublicLocation", "RadrootsListingStatus", "RadrootsNostrEventPtr", + "RadrootsOrderCancellation", + "RadrootsOrderDecision", "RadrootsPlotRef", "RadrootsResourceAreaRef", - "RadrootsCommercialMessagePayload", - "RadrootsCommercialMessageType", "RadrootsOrderEconomicLine", "RadrootsOrderItem", - "RadrootsOrderStatus", + "RadrootsOrderRequest", + "RadrootsOrderRevisionDecision", + "RadrootsOrderRevisionProposal", + "RadrootsTradeListingValidateRequest", + "RadrootsTradeListingValidateResult", ] { options = options.with_external_override(export_name, export_name, "@radroots/events-bindings"); @@ -373,10 +381,6 @@ mod tests { "RadrootsAppData", "RadrootsComment", "RadrootsCommercialDomain", - "RadrootsCommercialEnvelope", - "RadrootsCommercialMessagePayload", - "RadrootsCommercialMessageType", - "RadrootsCommercialTransportLane", "RadrootsCoop", "RadrootsCoopLocation", "RadrootsCoopRef", @@ -404,7 +408,6 @@ mod tests { "RadrootsListing", "RadrootsListingAvailability", "RadrootsListingBin", - "RadrootsListingCancel", "RadrootsListingDeliveryMethod", "RadrootsListingImage", "RadrootsListingImageSize", @@ -420,14 +423,9 @@ mod tests { "RadrootsNostrEvent", "RadrootsNostrEventPtr", "RadrootsNostrEventRef", - "RadrootsOrderAnswer", "RadrootsOrderCancellation", - "RadrootsOrderChange", "RadrootsOrderDecision", "RadrootsOrderDecisionOutcome", - "RadrootsOrderDiscountDecision", - "RadrootsOrderDiscountOffer", - "RadrootsOrderDiscountRequest", "RadrootsOrderEconomicActor", "RadrootsOrderEconomicEffect", "RadrootsOrderEconomicItem", @@ -435,20 +433,14 @@ mod tests { "RadrootsOrderEconomicLineKind", "RadrootsOrderEconomicTotals", "RadrootsOrderEconomics", - "RadrootsOrderEnvelope", "RadrootsOrderEventType", "RadrootsOrderInventoryCommitment", "RadrootsOrderItem", "RadrootsOrderPricingBasis", - "RadrootsOrderQuestion", "RadrootsOrderRequest", - "RadrootsOrderResponse", - "RadrootsOrderRevision", "RadrootsOrderRevisionDecision", "RadrootsOrderRevisionOutcome", "RadrootsOrderRevisionProposal", - "RadrootsOrderRevisionResponse", - "RadrootsOrderStatus", "RadrootsPlot", "RadrootsPlotLocation", "RadrootsPlotRef", @@ -463,9 +455,15 @@ mod tests { "RadrootsResourceHarvestCap", "RadrootsResourceHarvestProduct", "RadrootsSeal", + "RadrootsSocialFarmAnchor", + "RadrootsSocialLocation", + "RadrootsSocialMediaDimensions", + "RadrootsSocialMediaMetadata", + "RadrootsSocialMediaThumbnail", + "RadrootsSocialTarget", "RadrootsTradeListingValidateRequest", "RadrootsTradeListingValidateResult", - "RadrootsTradeListingValidationError", + "RadrootsTradeValidationListingError", ]; const EVENTS_INDEXED_TYPE_INVENTORY: &[&str] = &[ "RadrootsEventsIndexedShardId", @@ -476,6 +474,9 @@ mod tests { "RadrootsEventsIndexedIndexCheckpoint", ]; const TRADE_TYPE_INVENTORY: &[&str] = &[ + "RadrootsCommercialMessagePayload", + "RadrootsCommercialMessageType", + "RadrootsOrderStatus", "RadrootsTradeFacetCount", "RadrootsTradeListing", "RadrootsTradeListingBackofficeOverlay", @@ -643,8 +644,6 @@ mod tests { for duplicate in [ "export type RadrootsListing = ", "export type RadrootsFarmRef = ", - "export type RadrootsCommercialMessageType = ", - "export type RadrootsOrderStatus = ", ] { assert!(!TRADE_BINDINGS_TYPES_TS.contains(duplicate)); }