dto.rs (16234B)
1 use dto_bindgen_core::{ 2 BackendId, DescribeCtx, Dto, EnumDef, EnumRepr, FieldDef, IdentName, RootDescriptor, 3 RustTypeId, SourceSpan, TargetFieldNames, TargetOverride, TypeDef, TypeRef, VariantDef, 4 VariantShape, WireFieldNames, 5 }; 6 use radroots_trade::listing::model::RadrootsTradeListingTotal; 7 8 pub fn dto_roots() -> Vec<RootDescriptor> { 9 let mut roots = radroots_trade::dto::dto_roots() 10 .into_iter() 11 .collect::<Vec<_>>(); 12 roots.extend([ 13 RootDescriptor::new::<RadrootsTradeFacetCount>(), 14 RootDescriptor::new::<RadrootsTradeListingBackofficeOverlay>(), 15 RootDescriptor::new::<RadrootsTradeListingBackofficeQuery>(), 16 RootDescriptor::new::<RadrootsTradeListingBackofficeView>(), 17 RootDescriptor::new::<RadrootsTradeListingBinProjection>(), 18 RootDescriptor::new::<RadrootsTradeListingFacets>(), 19 RootDescriptor::new::<RadrootsTradeListingMarketStatus>(), 20 RootDescriptor::new::<RadrootsTradeListingProjection>(), 21 RootDescriptor::new::<RadrootsTradeListingQuery>(), 22 RootDescriptor::new::<RadrootsTradeListingSort>(), 23 RootDescriptor::new::<RadrootsTradeListingSortField>(), 24 RootDescriptor::new::<RadrootsTradeMarketplaceListingSummary>(), 25 RootDescriptor::new::<RadrootsTradeMarketplaceOrderSummary>(), 26 RootDescriptor::new::<RadrootsTradeModerationFlag>(), 27 RootDescriptor::new::<RadrootsTradeModerationSeverity>(), 28 RootDescriptor::new::<RadrootsTradeModerationStatus>(), 29 RootDescriptor::new::<RadrootsTradeOrderBackofficeOverlay>(), 30 RootDescriptor::new::<RadrootsTradeOrderBackofficeQuery>(), 31 RootDescriptor::new::<RadrootsTradeOrderBackofficeView>(), 32 RootDescriptor::new::<RadrootsTradeOrderFacets>(), 33 RootDescriptor::new::<RadrootsTradeOrderQuery>(), 34 RootDescriptor::new::<RadrootsTradeOrderSort>(), 35 RootDescriptor::new::<RadrootsTradeOrderSortField>(), 36 RootDescriptor::new::<RadrootsTradeOrderWorkflowMessage>(), 37 RootDescriptor::new::<RadrootsTradeOrderWorkflowProjection>(), 38 RootDescriptor::new::<RadrootsTradeReviewPriority>(), 39 RootDescriptor::new::<RadrootsTradeReviewQueueEntry>(), 40 RootDescriptor::new::<RadrootsTradeReviewStatus>(), 41 RootDescriptor::new::<RadrootsTradeSortDirection>(), 42 ]); 43 roots 44 } 45 46 macro_rules! imported_ts_type { 47 ($ty:ident, $target:literal) => { 48 pub struct $ty; 49 50 impl Dto for $ty { 51 fn describe(_ctx: &mut DescribeCtx) -> TypeRef { 52 TypeRef::Override(TargetOverride::new(BackendId::TypeScript, $target)) 53 } 54 } 55 }; 56 } 57 58 imported_ts_type!(RadrootsCoreDecimalImport, "RadrootsCoreDecimal"); 59 imported_ts_type!(RadrootsCoreDiscountImport, "RadrootsCoreDiscount"); 60 imported_ts_type!(RadrootsCoreDiscountValueImport, "RadrootsCoreDiscountValue"); 61 imported_ts_type!(RadrootsCoreMoneyImport, "RadrootsCoreMoney"); 62 imported_ts_type!(RadrootsCoreQuantityImport, "RadrootsCoreQuantity"); 63 imported_ts_type!(RadrootsCoreQuantityPriceImport, "RadrootsCoreQuantityPrice"); 64 imported_ts_type!(RadrootsCoreUnitImport, "RadrootsCoreUnit"); 65 imported_ts_type!(RadrootsFarmRefImport, "RadrootsFarmRef"); 66 imported_ts_type!(RadrootsListingImport, "RadrootsListing"); 67 imported_ts_type!( 68 RadrootsListingAvailabilityImport, 69 "RadrootsListingAvailability" 70 ); 71 imported_ts_type!(RadrootsListingBinImport, "RadrootsListingBin"); 72 imported_ts_type!( 73 RadrootsListingDeliveryMethodImport, 74 "RadrootsListingDeliveryMethod" 75 ); 76 imported_ts_type!(RadrootsListingImageImport, "RadrootsListingImage"); 77 imported_ts_type!(RadrootsListingLocationImport, "RadrootsListingLocation"); 78 imported_ts_type!(RadrootsListingProductImport, "RadrootsListingProduct"); 79 imported_ts_type!(RadrootsNostrEventPtrImport, "RadrootsNostrEventPtr"); 80 imported_ts_type!(RadrootsPlotRefImport, "RadrootsPlotRef"); 81 imported_ts_type!(RadrootsResourceAreaRefImport, "RadrootsResourceAreaRef"); 82 imported_ts_type!( 83 RadrootsTradeMessagePayloadImport, 84 "RadrootsTradeMessagePayload" 85 ); 86 imported_ts_type!(RadrootsTradeMessageTypeImport, "RadrootsTradeMessageType"); 87 imported_ts_type!( 88 RadrootsTradeOrderEconomicLineImport, 89 "RadrootsTradeOrderEconomicLine" 90 ); 91 imported_ts_type!(RadrootsTradeOrderItemImport, "RadrootsTradeOrderItem"); 92 imported_ts_type!(RadrootsTradeOrderStatusImport, "RadrootsTradeOrderStatus"); 93 94 #[derive(dto_bindgen::Dto)] 95 pub struct RadrootsTradeFacetCount { 96 pub key: String, 97 pub count: u32, 98 } 99 100 #[derive(dto_bindgen::Dto)] 101 pub struct RadrootsTradeListingBackofficeOverlay { 102 pub listing_addr: String, 103 pub review_queue: Option<RadrootsTradeReviewQueueEntry>, 104 pub moderation_flags: Vec<RadrootsTradeModerationFlag>, 105 } 106 107 #[derive(dto_bindgen::Dto)] 108 pub struct RadrootsTradeListingBackofficeQuery { 109 pub listing: RadrootsTradeListingQuery, 110 pub requires_review: Option<bool>, 111 pub has_open_moderation_flags: Option<bool>, 112 } 113 114 #[derive(dto_bindgen::Dto)] 115 pub struct RadrootsTradeListingBackofficeView { 116 pub listing: RadrootsTradeListingProjection, 117 pub marketplace: Option<RadrootsTradeMarketplaceListingSummary>, 118 pub overlay: Option<RadrootsTradeListingBackofficeOverlay>, 119 pub requires_review: bool, 120 pub open_moderation_flag_count: u32, 121 } 122 123 #[derive(dto_bindgen::Dto)] 124 pub struct RadrootsTradeListingBinProjection { 125 pub bin: RadrootsListingBinImport, 126 pub one_bin_total: RadrootsTradeListingTotal, 127 } 128 129 #[derive(dto_bindgen::Dto)] 130 pub struct RadrootsTradeListingFacets { 131 pub seller_pubkeys: Vec<RadrootsTradeFacetCount>, 132 pub farm_pubkeys: Vec<RadrootsTradeFacetCount>, 133 pub farm_ids: Vec<RadrootsTradeFacetCount>, 134 pub product_keys: Vec<RadrootsTradeFacetCount>, 135 pub product_categories: Vec<RadrootsTradeFacetCount>, 136 pub listing_statuses: Vec<RadrootsTradeFacetCount>, 137 } 138 139 pub enum RadrootsTradeListingMarketStatus { 140 Unknown, 141 Window, 142 Active, 143 Sold, 144 Other { value: String }, 145 } 146 147 impl Dto for RadrootsTradeListingMarketStatus { 148 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 149 let def = EnumDef::new( 150 "RadrootsTradeListingMarketStatus", 151 "RadrootsTradeListingMarketStatus", 152 EnumRepr::External, 153 span("crates/trade_bindings/src/dto.rs", 140), 154 ) 155 .with_variant(unit_variant( 156 "Unknown", 157 "unknown", 158 "crates/trade_bindings/src/dto.rs", 159 141, 160 )) 161 .with_variant(unit_variant( 162 "Window", 163 "window", 164 "crates/trade_bindings/src/dto.rs", 165 142, 166 )) 167 .with_variant(unit_variant( 168 "Active", 169 "active", 170 "crates/trade_bindings/src/dto.rs", 171 143, 172 )) 173 .with_variant(unit_variant( 174 "Sold", 175 "sold", 176 "crates/trade_bindings/src/dto.rs", 177 144, 178 )) 179 .with_variant(VariantDef::new( 180 "Other", 181 "other", 182 VariantShape::Struct(vec![field( 183 "value", 184 "value", 185 String::describe(ctx), 186 "crates/trade_bindings/src/dto.rs", 187 145, 188 )]), 189 span("crates/trade_bindings/src/dto.rs", 145), 190 )); 191 register(ctx, "RadrootsTradeListingMarketStatus", TypeDef::Enum(def)) 192 } 193 } 194 195 #[derive(dto_bindgen::Dto)] 196 pub struct RadrootsTradeListingProjection { 197 pub listing_addr: String, 198 pub seller_pubkey: String, 199 pub listing_id: String, 200 pub farm: RadrootsFarmRefImport, 201 pub product: RadrootsListingProductImport, 202 pub primary_bin_id: String, 203 pub bins: Vec<RadrootsTradeListingBinProjection>, 204 pub resource_area: Option<RadrootsResourceAreaRefImport>, 205 pub plot: Option<RadrootsPlotRefImport>, 206 pub discounts: Option<Vec<RadrootsCoreDiscountImport>>, 207 pub inventory_available: Option<RadrootsCoreDecimalImport>, 208 pub availability: Option<RadrootsListingAvailabilityImport>, 209 pub delivery_method: Option<RadrootsListingDeliveryMethodImport>, 210 pub location: Option<RadrootsListingLocationImport>, 211 pub images: Option<Vec<RadrootsListingImageImport>>, 212 pub order_count: u32, 213 pub open_order_count: u32, 214 pub terminal_order_count: u32, 215 } 216 217 #[derive(dto_bindgen::Dto)] 218 pub struct RadrootsTradeListingQuery { 219 pub seller_pubkey: Option<String>, 220 pub farm_pubkey: Option<String>, 221 pub farm_id: Option<String>, 222 pub product_key: Option<String>, 223 pub product_category: Option<String>, 224 pub listing_status: Option<RadrootsTradeListingMarketStatus>, 225 } 226 227 #[derive(dto_bindgen::Dto)] 228 pub struct RadrootsTradeListingSort { 229 pub field: RadrootsTradeListingSortField, 230 pub direction: RadrootsTradeSortDirection, 231 } 232 233 #[derive(dto_bindgen::Dto)] 234 pub enum RadrootsTradeListingSortField { 235 #[serde(rename = "listing_addr")] 236 ListingAddr, 237 #[serde(rename = "product_title")] 238 ProductTitle, 239 #[serde(rename = "product_category")] 240 ProductCategory, 241 #[serde(rename = "seller_pubkey")] 242 SellerPubkey, 243 #[serde(rename = "inventory_available")] 244 InventoryAvailable, 245 #[serde(rename = "open_order_count")] 246 OpenOrderCount, 247 #[serde(rename = "total_order_count")] 248 TotalOrderCount, 249 } 250 251 #[derive(dto_bindgen::Dto)] 252 pub struct RadrootsTradeMarketplaceListingSummary { 253 pub listing_addr: String, 254 pub seller_pubkey: String, 255 pub farm_pubkey: String, 256 pub farm_id: String, 257 pub product_key: String, 258 pub product_title: String, 259 pub product_category: String, 260 pub product_summary: Option<String>, 261 pub listing_status: RadrootsTradeListingMarketStatus, 262 pub location_primary: Option<String>, 263 pub inventory_available: Option<RadrootsCoreDecimalImport>, 264 pub primary_bin_id: String, 265 pub primary_bin_label: Option<String>, 266 pub primary_bin_total: RadrootsTradeListingTotal, 267 pub order_count: u32, 268 pub open_order_count: u32, 269 pub terminal_order_count: u32, 270 } 271 272 #[derive(dto_bindgen::Dto)] 273 pub struct RadrootsTradeMarketplaceOrderSummary { 274 pub order_id: String, 275 pub listing_addr: String, 276 pub buyer_pubkey: String, 277 pub seller_pubkey: String, 278 pub status: RadrootsTradeOrderStatusImport, 279 pub last_message_type: RadrootsTradeMessageTypeImport, 280 pub item_count: u32, 281 pub total_bin_count: u32, 282 pub has_requested_discounts: bool, 283 pub last_reason: Option<String>, 284 } 285 286 #[derive(dto_bindgen::Dto)] 287 pub struct RadrootsTradeModerationFlag { 288 pub code: String, 289 pub severity: RadrootsTradeModerationSeverity, 290 pub status: RadrootsTradeModerationStatus, 291 pub source: Option<String>, 292 pub reason: Option<String>, 293 } 294 295 #[derive(dto_bindgen::Dto)] 296 pub enum RadrootsTradeModerationSeverity { 297 #[serde(rename = "notice")] 298 Notice, 299 #[serde(rename = "warning")] 300 Warning, 301 #[serde(rename = "block")] 302 Block, 303 } 304 305 #[derive(dto_bindgen::Dto)] 306 pub enum RadrootsTradeModerationStatus { 307 #[serde(rename = "open")] 308 Open, 309 #[serde(rename = "snoozed")] 310 Snoozed, 311 #[serde(rename = "resolved")] 312 Resolved, 313 } 314 315 #[derive(dto_bindgen::Dto)] 316 pub struct RadrootsTradeOrderBackofficeOverlay { 317 pub order_id: String, 318 pub review_queue: Option<RadrootsTradeReviewQueueEntry>, 319 pub moderation_flags: Vec<RadrootsTradeModerationFlag>, 320 } 321 322 #[derive(dto_bindgen::Dto)] 323 pub struct RadrootsTradeOrderBackofficeQuery { 324 pub order: RadrootsTradeOrderQuery, 325 pub requires_review: Option<bool>, 326 pub has_open_moderation_flags: Option<bool>, 327 } 328 329 #[derive(dto_bindgen::Dto)] 330 pub struct RadrootsTradeOrderBackofficeView { 331 pub order: RadrootsTradeOrderWorkflowProjection, 332 pub marketplace: RadrootsTradeMarketplaceOrderSummary, 333 pub overlay: Option<RadrootsTradeOrderBackofficeOverlay>, 334 pub requires_review: bool, 335 pub open_moderation_flag_count: u32, 336 } 337 338 #[derive(dto_bindgen::Dto)] 339 pub struct RadrootsTradeOrderFacets { 340 pub buyer_pubkeys: Vec<RadrootsTradeFacetCount>, 341 pub seller_pubkeys: Vec<RadrootsTradeFacetCount>, 342 pub listing_addrs: Vec<RadrootsTradeFacetCount>, 343 pub statuses: Vec<RadrootsTradeFacetCount>, 344 } 345 346 #[derive(dto_bindgen::Dto)] 347 pub struct RadrootsTradeOrderQuery { 348 pub listing_addr: Option<String>, 349 pub buyer_pubkey: Option<String>, 350 pub seller_pubkey: Option<String>, 351 pub status: Option<RadrootsTradeOrderStatusImport>, 352 } 353 354 #[derive(dto_bindgen::Dto)] 355 pub struct RadrootsTradeOrderSort { 356 pub field: RadrootsTradeOrderSortField, 357 pub direction: RadrootsTradeSortDirection, 358 } 359 360 #[derive(dto_bindgen::Dto)] 361 pub enum RadrootsTradeOrderSortField { 362 #[serde(rename = "order_id")] 363 OrderId, 364 #[serde(rename = "listing_addr")] 365 ListingAddr, 366 #[serde(rename = "buyer_pubkey")] 367 BuyerPubkey, 368 #[serde(rename = "seller_pubkey")] 369 SellerPubkey, 370 #[serde(rename = "status")] 371 Status, 372 #[serde(rename = "last_message_type")] 373 LastMessageType, 374 #[serde(rename = "total_bin_count")] 375 TotalBinCount, 376 } 377 378 #[derive(dto_bindgen::Dto)] 379 pub struct RadrootsTradeOrderWorkflowMessage { 380 pub event_id: String, 381 pub actor_pubkey: String, 382 pub counterparty_pubkey: String, 383 pub listing_addr: String, 384 pub order_id: Option<String>, 385 pub listing_event: Option<RadrootsNostrEventPtrImport>, 386 pub root_event_id: Option<String>, 387 pub prev_event_id: Option<String>, 388 pub payload: RadrootsTradeMessagePayloadImport, 389 } 390 391 #[derive(dto_bindgen::Dto)] 392 pub struct RadrootsTradeOrderWorkflowProjection { 393 pub order_id: String, 394 pub listing_addr: String, 395 pub buyer_pubkey: String, 396 pub seller_pubkey: String, 397 pub items: Vec<RadrootsTradeOrderItemImport>, 398 pub requested_discounts: Option<Vec<RadrootsTradeOrderEconomicLineImport>>, 399 pub status: RadrootsTradeOrderStatusImport, 400 pub listing_snapshot: Option<RadrootsNostrEventPtrImport>, 401 pub root_event_id: String, 402 pub last_event_id: String, 403 pub last_discount_request: Option<RadrootsCoreDiscountValueImport>, 404 pub last_discount_offer: Option<RadrootsCoreDiscountValueImport>, 405 pub accepted_discount: Option<RadrootsCoreDiscountValueImport>, 406 pub last_reason: Option<String>, 407 pub last_discount_decline_reason: Option<String>, 408 pub question_count: u32, 409 pub answer_count: u32, 410 pub revision_count: u32, 411 pub discount_request_count: u32, 412 pub discount_offer_count: u32, 413 pub discount_accept_count: u32, 414 pub discount_decline_count: u32, 415 pub cancellation_count: u32, 416 pub last_message_type: RadrootsTradeMessageTypeImport, 417 pub last_actor_pubkey: String, 418 } 419 420 #[derive(dto_bindgen::Dto)] 421 pub enum RadrootsTradeReviewPriority { 422 #[serde(rename = "low")] 423 Low, 424 #[serde(rename = "normal")] 425 Normal, 426 #[serde(rename = "high")] 427 High, 428 #[serde(rename = "critical")] 429 Critical, 430 } 431 432 #[derive(dto_bindgen::Dto)] 433 pub struct RadrootsTradeReviewQueueEntry { 434 pub queue: String, 435 pub priority: RadrootsTradeReviewPriority, 436 pub status: RadrootsTradeReviewStatus, 437 pub assigned_operator: Option<String>, 438 pub reason: Option<String>, 439 } 440 441 #[derive(dto_bindgen::Dto)] 442 pub enum RadrootsTradeReviewStatus { 443 #[serde(rename = "queued")] 444 Queued, 445 #[serde(rename = "in_progress")] 446 InProgress, 447 #[serde(rename = "blocked")] 448 Blocked, 449 #[serde(rename = "resolved")] 450 Resolved, 451 } 452 453 #[derive(dto_bindgen::Dto)] 454 pub enum RadrootsTradeSortDirection { 455 #[serde(rename = "asc")] 456 Asc, 457 #[serde(rename = "desc")] 458 Desc, 459 } 460 461 fn register(ctx: &mut DescribeCtx, rust_ident: &str, type_def: TypeDef) -> TypeRef { 462 ctx.register_type( 463 RustTypeId::new("radroots_trade_bindings", rust_ident), 464 type_def, 465 ) 466 } 467 468 fn unit_variant(rust_name: &str, wire_name: &str, file: &str, line: u32) -> VariantDef { 469 VariantDef::new(rust_name, wire_name, VariantShape::Unit, span(file, line)) 470 } 471 472 fn field(rust_name: &str, wire_name: &str, ty: TypeRef, file: &str, line: u32) -> FieldDef { 473 FieldDef::new( 474 IdentName::new(rust_name), 475 WireFieldNames::same(wire_name), 476 TargetFieldNames::new(wire_name, rust_name), 477 ty, 478 span(file, line), 479 ) 480 } 481 482 fn span(file: &str, line: u32) -> SourceSpan { 483 SourceSpan::new(file, line, 1) 484 }