dto.rs (67749B)
1 use dto_bindgen_core::{ 2 DescribeCtx, Dto, EnumDef, EnumRepr, FieldDef, FieldPresence, GenericParam, IdentName, IntRepr, 3 RootDescriptor, RustTypeId, SourceSpan, StructDef, TargetFieldNames, TypeDef, TypeRef, 4 VariantDef, VariantShape, WireFieldNames, 5 }; 6 use radroots_core::RadrootsCoreDiscountValue; 7 8 use crate::{ 9 RadrootsNostrEvent, RadrootsNostrEventPtr, RadrootsNostrEventRef, 10 account::RadrootsAccountClaim, 11 app_data::RadrootsAppData, 12 comment::RadrootsComment, 13 coop::{RadrootsCoop, RadrootsCoopLocation, RadrootsCoopRef}, 14 document::{RadrootsDocument, RadrootsDocumentSubject}, 15 farm::{ 16 RadrootsFarm, RadrootsFarmLocation, RadrootsFarmRef, RadrootsGcsLocation, 17 RadrootsGeoJsonPoint, RadrootsGeoJsonPolygon, 18 }, 19 follow::{RadrootsFollow, RadrootsFollowProfile}, 20 geochat::RadrootsGeoChat, 21 gift_wrap::{RadrootsGiftWrap, RadrootsGiftWrapRecipient}, 22 ids::{ 23 RadrootsDTag, RadrootsEventId, RadrootsInventoryBinId, RadrootsListingAddress, 24 RadrootsOrderId, RadrootsOrderQuoteId, RadrootsOrderRevisionId, RadrootsPublicKey, 25 }, 26 job::{JobFeedbackStatus, JobInputType, JobPaymentRequest}, 27 job_feedback::RadrootsJobFeedback, 28 job_request::{RadrootsJobInput, RadrootsJobParam, RadrootsJobRequest}, 29 job_result::RadrootsJobResult, 30 list::{RadrootsList, RadrootsListEntry}, 31 list_set::RadrootsListSet, 32 listing::{ 33 RadrootsListing, RadrootsListingAvailability, RadrootsListingBin, 34 RadrootsListingDeliveryMethod, RadrootsListingImage, RadrootsListingImageSize, 35 RadrootsListingLocation, RadrootsListingProduct, RadrootsListingStatus, 36 }, 37 message::{RadrootsMessage, RadrootsMessageRecipient}, 38 message_file::{RadrootsMessageFile, RadrootsMessageFileDimensions}, 39 order::{ 40 RadrootsCommercialDomain, RadrootsListingParseError, RadrootsOrderCancellation, 41 RadrootsOrderDecision, RadrootsOrderDecisionOutcome, RadrootsOrderEventType, 42 RadrootsOrderInventoryCommitment, RadrootsOrderRequest, RadrootsOrderRevisionDecision, 43 RadrootsOrderRevisionOutcome, RadrootsOrderRevisionProposal, 44 }, 45 order_economics::{ 46 RadrootsOrderEconomicActor, RadrootsOrderEconomicEffect, RadrootsOrderEconomicItem, 47 RadrootsOrderEconomicLine, RadrootsOrderEconomicLineKind, RadrootsOrderEconomicTotals, 48 RadrootsOrderEconomics, RadrootsOrderItem, RadrootsOrderPricingBasis, 49 }, 50 plot::{RadrootsPlot, RadrootsPlotLocation, RadrootsPlotRef}, 51 post::RadrootsPost, 52 profile::{RadrootsProfile, RadrootsProfileType}, 53 reaction::RadrootsReaction, 54 relay_document::RadrootsRelayDocument, 55 resource_area::{RadrootsResourceArea, RadrootsResourceAreaLocation, RadrootsResourceAreaRef}, 56 resource_cap::{RadrootsResourceHarvestCap, RadrootsResourceHarvestProduct}, 57 seal::RadrootsSeal, 58 trade_validation::{ 59 RadrootsTradeValidationListingError, RadrootsTradeValidationListingRequest, 60 RadrootsTradeValidationListingResult, 61 }, 62 }; 63 64 pub fn dto_roots() -> Vec<RootDescriptor> { 65 vec![ 66 RootDescriptor::new::<JobFeedbackStatus>(), 67 RootDescriptor::new::<JobInputType>(), 68 RootDescriptor::new::<JobPaymentRequest>(), 69 RootDescriptor::new::<RadrootsAccountClaim>(), 70 RootDescriptor::new::<RadrootsOrderEnvelopeDto>(), 71 RootDescriptor::new::<RadrootsAppData>(), 72 RootDescriptor::new::<RadrootsComment>(), 73 RootDescriptor::new::<RadrootsCoop>(), 74 RootDescriptor::new::<RadrootsCoopLocation>(), 75 RootDescriptor::new::<RadrootsCoopRef>(), 76 RootDescriptor::new::<RadrootsDocument>(), 77 RootDescriptor::new::<RadrootsDocumentSubject>(), 78 RootDescriptor::new::<RadrootsFarm>(), 79 RootDescriptor::new::<RadrootsFarmLocation>(), 80 RootDescriptor::new::<RadrootsFarmRef>(), 81 RootDescriptor::new::<RadrootsFollow>(), 82 RootDescriptor::new::<RadrootsFollowProfile>(), 83 RootDescriptor::new::<RadrootsGcsLocation>(), 84 RootDescriptor::new::<RadrootsGeoChat>(), 85 RootDescriptor::new::<RadrootsGeoJsonPoint>(), 86 RootDescriptor::new::<RadrootsGeoJsonPolygon>(), 87 RootDescriptor::new::<RadrootsGiftWrap>(), 88 RootDescriptor::new::<RadrootsGiftWrapRecipient>(), 89 RootDescriptor::new::<RadrootsJobFeedback>(), 90 RootDescriptor::new::<RadrootsJobInput>(), 91 RootDescriptor::new::<RadrootsJobParam>(), 92 RootDescriptor::new::<RadrootsJobRequest>(), 93 RootDescriptor::new::<RadrootsJobResult>(), 94 RootDescriptor::new::<RadrootsList>(), 95 RootDescriptor::new::<RadrootsListEntry>(), 96 RootDescriptor::new::<RadrootsListSet>(), 97 RootDescriptor::new::<RadrootsListing>(), 98 RootDescriptor::new::<RadrootsListingAvailability>(), 99 RootDescriptor::new::<RadrootsListingBin>(), 100 RootDescriptor::new::<RadrootsListingDeliveryMethod>(), 101 RootDescriptor::new::<RadrootsNostrEvent>(), 102 RootDescriptor::new::<RadrootsNostrEventRef>(), 103 RootDescriptor::new::<RadrootsNostrEventPtr>(), 104 RootDescriptor::new::<RadrootsListingLocation>(), 105 RootDescriptor::new::<RadrootsListingProduct>(), 106 RootDescriptor::new::<RadrootsListingStatus>(), 107 RootDescriptor::new::<RadrootsListingImage>(), 108 RootDescriptor::new::<RadrootsMessage>(), 109 RootDescriptor::new::<RadrootsMessageFile>(), 110 RootDescriptor::new::<RadrootsMessageFileDimensions>(), 111 RootDescriptor::new::<RadrootsMessageRecipient>(), 112 RootDescriptor::new::<RadrootsPlot>(), 113 RootDescriptor::new::<RadrootsPlotLocation>(), 114 RootDescriptor::new::<RadrootsPlotRef>(), 115 RootDescriptor::new::<RadrootsPost>(), 116 RootDescriptor::new::<RadrootsProfile>(), 117 RootDescriptor::new::<RadrootsProfileType>(), 118 RootDescriptor::new::<RadrootsReaction>(), 119 RootDescriptor::new::<RadrootsRelayDocument>(), 120 RootDescriptor::new::<RadrootsResourceArea>(), 121 RootDescriptor::new::<RadrootsResourceAreaLocation>(), 122 RootDescriptor::new::<RadrootsResourceAreaRef>(), 123 RootDescriptor::new::<RadrootsResourceHarvestCap>(), 124 RootDescriptor::new::<RadrootsResourceHarvestProduct>(), 125 RootDescriptor::new::<RadrootsSeal>(), 126 RootDescriptor::new::<RadrootsListingAnswerDto>(), 127 RootDescriptor::new::<RadrootsListingDiscountDecisionDto>(), 128 RootDescriptor::new::<RadrootsListingDiscountOfferDto>(), 129 RootDescriptor::new::<RadrootsListingDiscountRequestDto>(), 130 RootDescriptor::new::<RadrootsCommercialDomain>(), 131 RootDescriptor::new::<RadrootsOrderEconomicActor>(), 132 RootDescriptor::new::<RadrootsOrderEconomicEffect>(), 133 RootDescriptor::new::<RadrootsOrderEconomicLineKind>(), 134 RootDescriptor::new::<RadrootsCommercialEnvelopeDto>(), 135 RootDescriptor::new::<RadrootsOrderInventoryCommitment>(), 136 RootDescriptor::new::<RadrootsListingCancelDto>(), 137 RootDescriptor::new::<RadrootsListingParseError>(), 138 RootDescriptor::new::<RadrootsTradeValidationListingRequest>(), 139 RootDescriptor::new::<RadrootsTradeValidationListingResult>(), 140 RootDescriptor::new::<RadrootsTradeValidationListingError>(), 141 RootDescriptor::new::<RadrootsCommercialMessagePayloadDto>(), 142 RootDescriptor::new::<RadrootsCommercialMessageTypeDto>(), 143 RootDescriptor::new::<RadrootsOrderCancellation>(), 144 RootDescriptor::new::<RadrootsOrderChangeDto>(), 145 RootDescriptor::new::<RadrootsOrderDecisionOutcome>(), 146 RootDescriptor::new::<RadrootsOrderDecision>(), 147 RootDescriptor::new::<RadrootsOrderEconomicItem>(), 148 RootDescriptor::new::<RadrootsOrderEconomicLine>(), 149 RootDescriptor::new::<RadrootsOrderEconomicTotals>(), 150 RootDescriptor::new::<RadrootsOrderEconomics>(), 151 RootDescriptor::new::<RadrootsOrderItem>(), 152 RootDescriptor::new::<RadrootsOrderRequest>(), 153 RootDescriptor::new::<RadrootsOrderResponseDto>(), 154 RootDescriptor::new::<RadrootsOrderRevisionDto>(), 155 RootDescriptor::new::<RadrootsOrderRevisionOutcome>(), 156 RootDescriptor::new::<RadrootsOrderRevisionDecision>(), 157 RootDescriptor::new::<RadrootsOrderRevisionProposal>(), 158 RootDescriptor::new::<RadrootsOrderRevisionResponseDto>(), 159 RootDescriptor::new::<RadrootsOrderStatusDto>(), 160 RootDescriptor::new::<RadrootsOrderPricingBasis>(), 161 RootDescriptor::new::<RadrootsListingQuestionDto>(), 162 RootDescriptor::new::<RadrootsCommercialTransportLaneDto>(), 163 ] 164 } 165 166 pub struct RadrootsOrderEnvelopeDto; 167 pub struct RadrootsListingAnswerDto; 168 pub struct RadrootsListingDiscountDecisionDto; 169 pub struct RadrootsListingDiscountOfferDto; 170 pub struct RadrootsListingDiscountRequestDto; 171 pub struct RadrootsCommercialEnvelopeDto; 172 pub struct RadrootsListingCancelDto; 173 pub struct RadrootsCommercialMessagePayloadDto; 174 pub struct RadrootsCommercialMessageTypeDto; 175 pub struct RadrootsOrderChangeDto; 176 pub struct RadrootsOrderResponseDto; 177 pub struct RadrootsOrderRevisionDto; 178 pub struct RadrootsOrderRevisionResponseDto; 179 pub struct RadrootsOrderStatusDto; 180 pub struct RadrootsListingQuestionDto; 181 pub struct RadrootsCommercialTransportLaneDto; 182 183 macro_rules! string_dto { 184 ($($ty:ty),+ $(,)?) => { 185 $( 186 impl Dto for $ty { 187 fn describe(_ctx: &mut DescribeCtx) -> TypeRef { 188 TypeRef::String 189 } 190 } 191 )+ 192 }; 193 } 194 195 string_dto!( 196 RadrootsDTag, 197 RadrootsEventId, 198 RadrootsInventoryBinId, 199 RadrootsListingAddress, 200 RadrootsOrderId, 201 RadrootsOrderQuoteId, 202 RadrootsOrderRevisionId, 203 RadrootsPublicKey, 204 ); 205 206 impl Dto for RadrootsNostrEvent { 207 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 208 let def = StructDef::new( 209 "RadrootsNostrEvent", 210 "RadrootsNostrEvent", 211 span("crates/events/src/lib.rs", 52), 212 ) 213 .with_field(field( 214 "id", 215 "id", 216 String::describe(ctx), 217 "crates/events/src/lib.rs", 218 53, 219 )) 220 .with_field(field( 221 "author", 222 "author", 223 String::describe(ctx), 224 "crates/events/src/lib.rs", 225 54, 226 )) 227 .with_field(field( 228 "created_at", 229 "created_at", 230 u32::describe(ctx), 231 "crates/events/src/lib.rs", 232 55, 233 )) 234 .with_field(field( 235 "kind", 236 "kind", 237 u32::describe(ctx), 238 "crates/events/src/lib.rs", 239 56, 240 )) 241 .with_field(field( 242 "tags", 243 "tags", 244 <Vec<Vec<String>> as Dto>::describe(ctx), 245 "crates/events/src/lib.rs", 246 57, 247 )) 248 .with_field(field( 249 "content", 250 "content", 251 String::describe(ctx), 252 "crates/events/src/lib.rs", 253 58, 254 )) 255 .with_field(field( 256 "sig", 257 "sig", 258 String::describe(ctx), 259 "crates/events/src/lib.rs", 260 59, 261 )); 262 register(ctx, "RadrootsNostrEvent", TypeDef::Struct(def)) 263 } 264 } 265 266 impl Dto for RadrootsNostrEventRef { 267 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 268 let def = StructDef::new( 269 "RadrootsNostrEventRef", 270 "RadrootsNostrEventRef", 271 span("crates/events/src/lib.rs", 64), 272 ) 273 .with_field(field( 274 "id", 275 "id", 276 String::describe(ctx), 277 "crates/events/src/lib.rs", 278 65, 279 )) 280 .with_field(field( 281 "author", 282 "author", 283 String::describe(ctx), 284 "crates/events/src/lib.rs", 285 66, 286 )) 287 .with_field(field( 288 "kind", 289 "kind", 290 u32::describe(ctx), 291 "crates/events/src/lib.rs", 292 67, 293 )) 294 .with_field(optional_nullable_field( 295 "d_tag", 296 "d_tag", 297 <Option<String> as Dto>::describe(ctx), 298 "crates/events/src/lib.rs", 299 68, 300 )) 301 .with_field(optional_nullable_field( 302 "relays", 303 "relays", 304 <Option<Vec<String>> as Dto>::describe(ctx), 305 "crates/events/src/lib.rs", 306 69, 307 )); 308 register(ctx, "RadrootsNostrEventRef", TypeDef::Struct(def)) 309 } 310 } 311 312 impl Dto for RadrootsNostrEventPtr { 313 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 314 let def = StructDef::new( 315 "RadrootsNostrEventPtr", 316 "RadrootsNostrEventPtr", 317 span("crates/events/src/lib.rs", 74), 318 ) 319 .with_field(field( 320 "id", 321 "id", 322 String::describe(ctx), 323 "crates/events/src/lib.rs", 324 75, 325 )) 326 .with_field(optional_nullable_field( 327 "relays", 328 "relays", 329 <Option<String> as Dto>::describe(ctx), 330 "crates/events/src/lib.rs", 331 76, 332 )); 333 register(ctx, "RadrootsNostrEventPtr", TypeDef::Struct(def)) 334 } 335 } 336 337 impl Dto for RadrootsListingProduct { 338 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 339 let def = StructDef::new( 340 "RadrootsListingProduct", 341 "RadrootsListingProduct", 342 span("crates/events/src/listing.rs", 81), 343 ) 344 .with_field(field( 345 "key", 346 "key", 347 String::describe(ctx), 348 "crates/events/src/listing.rs", 349 82, 350 )) 351 .with_field(field( 352 "title", 353 "title", 354 String::describe(ctx), 355 "crates/events/src/listing.rs", 356 83, 357 )) 358 .with_field(field( 359 "category", 360 "category", 361 String::describe(ctx), 362 "crates/events/src/listing.rs", 363 84, 364 )) 365 .with_field(optional_nullable_field( 366 "summary", 367 "summary", 368 <Option<String> as Dto>::describe(ctx), 369 "crates/events/src/listing.rs", 370 85, 371 )) 372 .with_field(optional_nullable_field( 373 "process", 374 "process", 375 <Option<String> as Dto>::describe(ctx), 376 "crates/events/src/listing.rs", 377 86, 378 )) 379 .with_field(optional_nullable_field( 380 "lot", 381 "lot", 382 <Option<String> as Dto>::describe(ctx), 383 "crates/events/src/listing.rs", 384 87, 385 )) 386 .with_field(optional_nullable_field( 387 "location", 388 "location", 389 <Option<String> as Dto>::describe(ctx), 390 "crates/events/src/listing.rs", 391 88, 392 )) 393 .with_field(optional_nullable_field( 394 "profile", 395 "profile", 396 <Option<String> as Dto>::describe(ctx), 397 "crates/events/src/listing.rs", 398 89, 399 )) 400 .with_field(optional_nullable_field( 401 "year", 402 "year", 403 <Option<String> as Dto>::describe(ctx), 404 "crates/events/src/listing.rs", 405 90, 406 )); 407 register(ctx, "RadrootsListingProduct", TypeDef::Struct(def)) 408 } 409 } 410 411 impl Dto for RadrootsListingBin { 412 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 413 let def = StructDef::new( 414 "RadrootsListingBin", 415 "RadrootsListingBin", 416 span("crates/events/src/listing.rs", 101), 417 ) 418 .with_field(field( 419 "bin_id", 420 "bin_id", 421 RadrootsInventoryBinId::describe(ctx), 422 "crates/events/src/listing.rs", 423 102, 424 )) 425 .with_field(field( 426 "quantity", 427 "quantity", 428 radroots_core::RadrootsCoreQuantity::describe(ctx), 429 "crates/events/src/listing.rs", 430 103, 431 )) 432 .with_field(field( 433 "price_per_canonical_unit", 434 "price_per_canonical_unit", 435 radroots_core::RadrootsCoreQuantityPrice::describe(ctx), 436 "crates/events/src/listing.rs", 437 104, 438 )) 439 .with_field(optional_nullable_field( 440 "display_amount", 441 "display_amount", 442 TypeRef::option(core_decimal(ctx)), 443 "crates/events/src/listing.rs", 444 105, 445 )) 446 .with_field(optional_nullable_field( 447 "display_unit", 448 "display_unit", 449 <Option<radroots_core::RadrootsCoreUnit> as Dto>::describe(ctx), 450 "crates/events/src/listing.rs", 451 106, 452 )) 453 .with_field(optional_nullable_field( 454 "display_label", 455 "display_label", 456 <Option<String> as Dto>::describe(ctx), 457 "crates/events/src/listing.rs", 458 107, 459 )) 460 .with_field(optional_nullable_field( 461 "display_price", 462 "display_price", 463 <Option<radroots_core::RadrootsCoreMoney> as Dto>::describe(ctx), 464 "crates/events/src/listing.rs", 465 108, 466 )) 467 .with_field(optional_nullable_field( 468 "display_price_unit", 469 "display_price_unit", 470 <Option<radroots_core::RadrootsCoreUnit> as Dto>::describe(ctx), 471 "crates/events/src/listing.rs", 472 109, 473 )); 474 register(ctx, "RadrootsListingBin", TypeDef::Struct(def)) 475 } 476 } 477 478 impl Dto for RadrootsListingImageSize { 479 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 480 let def = StructDef::new( 481 "RadrootsListingImageSize", 482 "RadrootsListingImageSize", 483 span("crates/events/src/listing.rs", 133), 484 ) 485 .with_field(field( 486 "w", 487 "w", 488 u32::describe(ctx), 489 "crates/events/src/listing.rs", 490 134, 491 )) 492 .with_field(field( 493 "h", 494 "h", 495 u32::describe(ctx), 496 "crates/events/src/listing.rs", 497 135, 498 )); 499 register(ctx, "RadrootsListingImageSize", TypeDef::Struct(def)) 500 } 501 } 502 503 impl Dto for RadrootsListingImage { 504 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 505 let size = RadrootsListingImageSize::describe(ctx); 506 let def = StructDef::new( 507 "RadrootsListingImage", 508 "RadrootsListingImage", 509 span("crates/events/src/listing.rs", 126), 510 ) 511 .with_field(field( 512 "url", 513 "url", 514 String::describe(ctx), 515 "crates/events/src/listing.rs", 516 127, 517 )) 518 .with_field(optional_nullable_field( 519 "size", 520 "size", 521 TypeRef::option(size), 522 "crates/events/src/listing.rs", 523 128, 524 )); 525 register(ctx, "RadrootsListingImage", TypeDef::Struct(def)) 526 } 527 } 528 529 impl Dto for RadrootsListingAvailability { 530 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 531 let def = EnumDef::new( 532 "RadrootsListingAvailability", 533 "RadrootsListingAvailability", 534 EnumRepr::Adjacent { 535 tag: "kind".to_owned(), 536 content: "amount".to_owned(), 537 }, 538 span("crates/events/src/listing.rs", 20), 539 ) 540 .with_variant(VariantDef::new( 541 "Window", 542 "window", 543 VariantShape::Struct(vec![ 544 optional_nullable_field( 545 "start", 546 "start", 547 <Option<u64> as Dto>::describe(ctx), 548 "crates/events/src/listing.rs", 549 21, 550 ) 551 .with_int_repr(IntRepr::JsonNumberUnsafe), 552 optional_nullable_field( 553 "end", 554 "end", 555 <Option<u64> as Dto>::describe(ctx), 556 "crates/events/src/listing.rs", 557 22, 558 ) 559 .with_int_repr(IntRepr::JsonNumberUnsafe), 560 ]), 561 span("crates/events/src/listing.rs", 21), 562 )) 563 .with_variant(VariantDef::new( 564 "Status", 565 "status", 566 VariantShape::Struct(vec![field( 567 "status", 568 "status", 569 RadrootsListingStatus::describe(ctx), 570 "crates/events/src/listing.rs", 571 24, 572 )]), 573 span("crates/events/src/listing.rs", 24), 574 )); 575 register(ctx, "RadrootsListingAvailability", TypeDef::Enum(def)) 576 } 577 } 578 579 impl Dto for RadrootsListingStatus { 580 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 581 let def = EnumDef::new( 582 "RadrootsListingStatus", 583 "RadrootsListingStatus", 584 EnumRepr::Adjacent { 585 tag: "kind".to_owned(), 586 content: "amount".to_owned(), 587 }, 588 span("crates/events/src/listing.rs", 36), 589 ) 590 .with_variant(VariantDef::new( 591 "Active", 592 "active", 593 VariantShape::Unit, 594 span("crates/events/src/listing.rs", 37), 595 )) 596 .with_variant(VariantDef::new( 597 "Sold", 598 "sold", 599 VariantShape::Unit, 600 span("crates/events/src/listing.rs", 38), 601 )) 602 .with_variant(VariantDef::new( 603 "Other", 604 "other", 605 VariantShape::Struct(vec![field( 606 "value", 607 "value", 608 String::describe(ctx), 609 "crates/events/src/listing.rs", 610 39, 611 )]), 612 span("crates/events/src/listing.rs", 39), 613 )); 614 register(ctx, "RadrootsListingStatus", TypeDef::Enum(def)) 615 } 616 } 617 618 impl Dto for RadrootsListingDeliveryMethod { 619 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 620 let def = EnumDef::new( 621 "RadrootsListingDeliveryMethod", 622 "RadrootsListingDeliveryMethod", 623 EnumRepr::Adjacent { 624 tag: "kind".to_owned(), 625 content: "amount".to_owned(), 626 }, 627 span("crates/events/src/listing.rs", 48), 628 ) 629 .with_variant(VariantDef::new( 630 "Pickup", 631 "pickup", 632 VariantShape::Unit, 633 span("crates/events/src/listing.rs", 49), 634 )) 635 .with_variant(VariantDef::new( 636 "LocalDelivery", 637 "local_delivery", 638 VariantShape::Unit, 639 span("crates/events/src/listing.rs", 50), 640 )) 641 .with_variant(VariantDef::new( 642 "Shipping", 643 "shipping", 644 VariantShape::Unit, 645 span("crates/events/src/listing.rs", 51), 646 )) 647 .with_variant(VariantDef::new( 648 "Other", 649 "other", 650 VariantShape::Struct(vec![field( 651 "method", 652 "method", 653 String::describe(ctx), 654 "crates/events/src/listing.rs", 655 52, 656 )]), 657 span("crates/events/src/listing.rs", 52), 658 )); 659 register(ctx, "RadrootsListingDeliveryMethod", TypeDef::Enum(def)) 660 } 661 } 662 663 impl Dto for RadrootsListing { 664 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 665 let def = StructDef::new( 666 "RadrootsListing", 667 "RadrootsListing", 668 span("crates/events/src/listing.rs", 57), 669 ) 670 .with_field(field( 671 "d_tag", 672 "d_tag", 673 RadrootsDTag::describe(ctx), 674 "crates/events/src/listing.rs", 675 58, 676 )) 677 .with_field( 678 optional_nullable_field( 679 "published_at", 680 "published_at", 681 <Option<u64> as Dto>::describe(ctx), 682 "crates/events/src/listing.rs", 683 63, 684 ) 685 .with_presence(FieldPresence::optional_nullable_skip_if_none()) 686 .with_int_repr(IntRepr::JsonNumberUnsafe), 687 ) 688 .with_field(field( 689 "farm", 690 "farm", 691 RadrootsFarmRef::describe(ctx), 692 "crates/events/src/listing.rs", 693 68, 694 )) 695 .with_field(field( 696 "product", 697 "product", 698 RadrootsListingProduct::describe(ctx), 699 "crates/events/src/listing.rs", 700 69, 701 )) 702 .with_field(field( 703 "primary_bin_id", 704 "primary_bin_id", 705 RadrootsInventoryBinId::describe(ctx), 706 "crates/events/src/listing.rs", 707 70, 708 )) 709 .with_field(field( 710 "bins", 711 "bins", 712 <Vec<RadrootsListingBin> as Dto>::describe(ctx), 713 "crates/events/src/listing.rs", 714 71, 715 )) 716 .with_field(optional_nullable_field( 717 "resource_area", 718 "resource_area", 719 <Option<RadrootsResourceAreaRef> as Dto>::describe(ctx), 720 "crates/events/src/listing.rs", 721 72, 722 )) 723 .with_field(optional_nullable_field( 724 "plot", 725 "plot", 726 <Option<RadrootsPlotRef> as Dto>::describe(ctx), 727 "crates/events/src/listing.rs", 728 73, 729 )) 730 .with_field(optional_nullable_field( 731 "discounts", 732 "discounts", 733 <Option<Vec<radroots_core::RadrootsCoreDiscount>> as Dto>::describe(ctx), 734 "crates/events/src/listing.rs", 735 74, 736 )) 737 .with_field(optional_nullable_field( 738 "inventory_available", 739 "inventory_available", 740 TypeRef::option(core_decimal(ctx)), 741 "crates/events/src/listing.rs", 742 75, 743 )) 744 .with_field(optional_nullable_field( 745 "availability", 746 "availability", 747 <Option<RadrootsListingAvailability> as Dto>::describe(ctx), 748 "crates/events/src/listing.rs", 749 76, 750 )) 751 .with_field(optional_nullable_field( 752 "delivery_method", 753 "delivery_method", 754 <Option<RadrootsListingDeliveryMethod> as Dto>::describe(ctx), 755 "crates/events/src/listing.rs", 756 77, 757 )) 758 .with_field(optional_nullable_field( 759 "location", 760 "location", 761 <Option<RadrootsListingLocation> as Dto>::describe(ctx), 762 "crates/events/src/listing.rs", 763 78, 764 )) 765 .with_field(optional_nullable_field( 766 "images", 767 "images", 768 <Option<Vec<RadrootsListingImage>> as Dto>::describe(ctx), 769 "crates/events/src/listing.rs", 770 79, 771 )); 772 register(ctx, "RadrootsListing", TypeDef::Struct(def)) 773 } 774 } 775 776 impl Dto for RadrootsResourceHarvestCap { 777 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 778 let def = StructDef::new( 779 "RadrootsResourceHarvestCap", 780 "RadrootsResourceHarvestCap", 781 span("crates/events/src/resource_cap.rs", 20), 782 ) 783 .with_field(field( 784 "d_tag", 785 "d_tag", 786 String::describe(ctx), 787 "crates/events/src/resource_cap.rs", 788 21, 789 )) 790 .with_field(field( 791 "resource_area", 792 "resource_area", 793 RadrootsResourceAreaRef::describe(ctx), 794 "crates/events/src/resource_cap.rs", 795 22, 796 )) 797 .with_field(field( 798 "product", 799 "product", 800 RadrootsResourceHarvestProduct::describe(ctx), 801 "crates/events/src/resource_cap.rs", 802 23, 803 )) 804 .with_field( 805 field( 806 "start", 807 "start", 808 u64::describe(ctx), 809 "crates/events/src/resource_cap.rs", 810 24, 811 ) 812 .with_int_repr(IntRepr::NonJsonBigint), 813 ) 814 .with_field( 815 field( 816 "end", 817 "end", 818 u64::describe(ctx), 819 "crates/events/src/resource_cap.rs", 820 25, 821 ) 822 .with_int_repr(IntRepr::NonJsonBigint), 823 ) 824 .with_field(field( 825 "cap_quantity", 826 "cap_quantity", 827 radroots_core::RadrootsCoreQuantity::describe(ctx), 828 "crates/events/src/resource_cap.rs", 829 26, 830 )) 831 .with_field(optional_nullable_field( 832 "display_amount", 833 "display_amount", 834 TypeRef::option(core_decimal(ctx)), 835 "crates/events/src/resource_cap.rs", 836 27, 837 )) 838 .with_field(optional_nullable_field( 839 "display_unit", 840 "display_unit", 841 <Option<radroots_core::RadrootsCoreUnit> as Dto>::describe(ctx), 842 "crates/events/src/resource_cap.rs", 843 28, 844 )) 845 .with_field(optional_nullable_field( 846 "display_label", 847 "display_label", 848 <Option<String> as Dto>::describe(ctx), 849 "crates/events/src/resource_cap.rs", 850 29, 851 )) 852 .with_field(optional_nullable_field( 853 "tags", 854 "tags", 855 <Option<Vec<String>> as Dto>::describe(ctx), 856 "crates/events/src/resource_cap.rs", 857 30, 858 )); 859 register(ctx, "RadrootsResourceHarvestCap", TypeDef::Struct(def)) 860 } 861 } 862 863 impl Dto for RadrootsComment { 864 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 865 let event_ref = RadrootsNostrEventRef::describe(ctx); 866 let def = StructDef::new( 867 "RadrootsComment", 868 "RadrootsComment", 869 span("crates/events/src/comment.rs", 8), 870 ) 871 .with_field(field( 872 "root", 873 "root", 874 event_ref, 875 "crates/events/src/comment.rs", 876 9, 877 )) 878 .with_field(field( 879 "parent", 880 "parent", 881 RadrootsNostrEventRef::describe(ctx), 882 "crates/events/src/comment.rs", 883 10, 884 )) 885 .with_field(field( 886 "content", 887 "content", 888 String::describe(ctx), 889 "crates/events/src/comment.rs", 890 11, 891 )); 892 register(ctx, "RadrootsComment", TypeDef::Struct(def)) 893 } 894 } 895 896 impl Dto for RadrootsReaction { 897 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 898 let def = StructDef::new( 899 "RadrootsReaction", 900 "RadrootsReaction", 901 span("crates/events/src/reaction.rs", 8), 902 ) 903 .with_field(field( 904 "root", 905 "root", 906 RadrootsNostrEventRef::describe(ctx), 907 "crates/events/src/reaction.rs", 908 9, 909 )) 910 .with_field(field( 911 "content", 912 "content", 913 String::describe(ctx), 914 "crates/events/src/reaction.rs", 915 10, 916 )); 917 register(ctx, "RadrootsReaction", TypeDef::Struct(def)) 918 } 919 } 920 921 impl Dto for RadrootsPost { 922 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 923 let def = StructDef::new( 924 "RadrootsPost", 925 "RadrootsPost", 926 span("crates/events/src/post.rs", 11), 927 ) 928 .with_field(field( 929 "content", 930 "content", 931 String::describe(ctx), 932 "crates/events/src/post.rs", 933 12, 934 )); 935 register(ctx, "RadrootsPost", TypeDef::Struct(def)) 936 } 937 } 938 939 impl Dto for RadrootsListingParseError { 940 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 941 let def = EnumDef::new( 942 "RadrootsListingParseError", 943 "RadrootsListingParseError", 944 EnumRepr::External, 945 span("crates/events/src/order.rs", 26), 946 ) 947 .with_variant(VariantDef::new( 948 "InvalidKind", 949 "InvalidKind", 950 VariantShape::Newtype(u32::describe(ctx)), 951 span("crates/events/src/order.rs", 27), 952 )) 953 .with_variant(VariantDef::new( 954 "MissingTag", 955 "MissingTag", 956 VariantShape::Newtype(String::describe(ctx)), 957 span("crates/events/src/order.rs", 28), 958 )) 959 .with_variant(VariantDef::new( 960 "InvalidTag", 961 "InvalidTag", 962 VariantShape::Newtype(String::describe(ctx)), 963 span("crates/events/src/order.rs", 29), 964 )) 965 .with_variant(VariantDef::new( 966 "InvalidNumber", 967 "InvalidNumber", 968 VariantShape::Newtype(String::describe(ctx)), 969 span("crates/events/src/order.rs", 30), 970 )) 971 .with_variant(VariantDef::new( 972 "InvalidUnit", 973 "InvalidUnit", 974 VariantShape::Unit, 975 span("crates/events/src/order.rs", 31), 976 )) 977 .with_variant(VariantDef::new( 978 "InvalidCurrency", 979 "InvalidCurrency", 980 VariantShape::Unit, 981 span("crates/events/src/order.rs", 32), 982 )) 983 .with_variant(VariantDef::new( 984 "InvalidJson", 985 "InvalidJson", 986 VariantShape::Newtype(String::describe(ctx)), 987 span("crates/events/src/order.rs", 33), 988 )) 989 .with_variant(VariantDef::new( 990 "InvalidDiscount", 991 "InvalidDiscount", 992 VariantShape::Newtype(String::describe(ctx)), 993 span("crates/events/src/order.rs", 34), 994 )); 995 register(ctx, "RadrootsListingParseError", TypeDef::Enum(def)) 996 } 997 } 998 999 impl Dto for RadrootsTradeValidationListingError { 1000 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 1001 let parse_error = RadrootsListingParseError::describe(ctx); 1002 let def = EnumDef::new( 1003 "RadrootsTradeValidationListingError", 1004 "RadrootsTradeListingValidationError", 1005 EnumRepr::Adjacent { 1006 tag: "kind".to_owned(), 1007 content: "amount".to_owned(), 1008 }, 1009 span("crates/events/src/trade_validation.rs", 14), 1010 ) 1011 .with_variant(VariantDef::new( 1012 "InvalidKind", 1013 "invalid_kind", 1014 VariantShape::Struct(vec![field( 1015 "kind", 1016 "kind", 1017 u32::describe(ctx), 1018 "crates/events/src/trade_validation.rs", 1019 15, 1020 )]), 1021 span("crates/events/src/trade_validation.rs", 15), 1022 )) 1023 .with_variant(unit_variant( 1024 "MissingListingId", 1025 "missing_listing_id", 1026 "crates/events/src/trade_validation.rs", 1027 16, 1028 )) 1029 .with_variant(VariantDef::new( 1030 "ListingEventNotFound", 1031 "listing_event_not_found", 1032 VariantShape::Struct(vec![field( 1033 "listing_addr", 1034 "listing_addr", 1035 String::describe(ctx), 1036 "crates/events/src/trade_validation.rs", 1037 17, 1038 )]), 1039 span("crates/events/src/trade_validation.rs", 17), 1040 )) 1041 .with_variant(VariantDef::new( 1042 "ListingEventFetchFailed", 1043 "listing_event_fetch_failed", 1044 VariantShape::Struct(vec![field( 1045 "listing_addr", 1046 "listing_addr", 1047 String::describe(ctx), 1048 "crates/events/src/trade_validation.rs", 1049 18, 1050 )]), 1051 span("crates/events/src/trade_validation.rs", 18), 1052 )) 1053 .with_variant(VariantDef::new( 1054 "ParseError", 1055 "parse_error", 1056 VariantShape::Struct(vec![field( 1057 "error", 1058 "error", 1059 parse_error, 1060 "crates/events/src/trade_validation.rs", 1061 19, 1062 )]), 1063 span("crates/events/src/trade_validation.rs", 19), 1064 )) 1065 .with_variant(unit_variant( 1066 "InvalidSeller", 1067 "invalid_seller", 1068 "crates/events/src/trade_validation.rs", 1069 20, 1070 )) 1071 .with_variant(unit_variant( 1072 "MissingFarmProfile", 1073 "missing_farm_profile", 1074 "crates/events/src/trade_validation.rs", 1075 21, 1076 )) 1077 .with_variant(unit_variant( 1078 "MissingFarmRecord", 1079 "missing_farm_record", 1080 "crates/events/src/trade_validation.rs", 1081 22, 1082 )) 1083 .with_variant(unit_variant( 1084 "MissingTitle", 1085 "missing_title", 1086 "crates/events/src/trade_validation.rs", 1087 23, 1088 )) 1089 .with_variant(unit_variant( 1090 "MissingDescription", 1091 "missing_description", 1092 "crates/events/src/trade_validation.rs", 1093 24, 1094 )) 1095 .with_variant(unit_variant( 1096 "MissingProductType", 1097 "missing_product_type", 1098 "crates/events/src/trade_validation.rs", 1099 25, 1100 )) 1101 .with_variant(unit_variant( 1102 "MissingBins", 1103 "missing_bins", 1104 "crates/events/src/trade_validation.rs", 1105 26, 1106 )) 1107 .with_variant(unit_variant( 1108 "MissingPrimaryBin", 1109 "missing_primary_bin", 1110 "crates/events/src/trade_validation.rs", 1111 27, 1112 )) 1113 .with_variant(unit_variant( 1114 "InvalidBin", 1115 "invalid_bin", 1116 "crates/events/src/trade_validation.rs", 1117 28, 1118 )) 1119 .with_variant(unit_variant( 1120 "MissingPrice", 1121 "missing_price", 1122 "crates/events/src/trade_validation.rs", 1123 29, 1124 )) 1125 .with_variant(unit_variant( 1126 "InvalidPrice", 1127 "invalid_price", 1128 "crates/events/src/trade_validation.rs", 1129 30, 1130 )) 1131 .with_variant(unit_variant( 1132 "MissingInventory", 1133 "missing_inventory", 1134 "crates/events/src/trade_validation.rs", 1135 31, 1136 )) 1137 .with_variant(unit_variant( 1138 "InvalidInventory", 1139 "invalid_inventory", 1140 "crates/events/src/trade_validation.rs", 1141 32, 1142 )) 1143 .with_variant(unit_variant( 1144 "MissingAvailability", 1145 "missing_availability", 1146 "crates/events/src/trade_validation.rs", 1147 33, 1148 )) 1149 .with_variant(unit_variant( 1150 "MissingLocation", 1151 "missing_location", 1152 "crates/events/src/trade_validation.rs", 1153 34, 1154 )) 1155 .with_variant(unit_variant( 1156 "MissingDeliveryMethod", 1157 "missing_delivery_method", 1158 "crates/events/src/trade_validation.rs", 1159 35, 1160 )); 1161 register( 1162 ctx, 1163 "RadrootsTradeValidationListingError", 1164 TypeDef::Enum(def), 1165 ) 1166 } 1167 } 1168 1169 impl Dto for RadrootsOrderEconomicItem { 1170 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 1171 let def = StructDef::new( 1172 "RadrootsOrderEconomicItem", 1173 "RadrootsOrderEconomicItem", 1174 span("crates/events/src/order_economics.rs", 70), 1175 ) 1176 .with_field(field( 1177 "bin_id", 1178 "bin_id", 1179 RadrootsInventoryBinId::describe(ctx), 1180 "crates/events/src/order_economics.rs", 1181 71, 1182 )) 1183 .with_field(field( 1184 "bin_count", 1185 "bin_count", 1186 u32::describe(ctx), 1187 "crates/events/src/order_economics.rs", 1188 72, 1189 )) 1190 .with_field(field( 1191 "quantity_amount", 1192 "quantity_amount", 1193 core_decimal(ctx), 1194 "crates/events/src/order_economics.rs", 1195 73, 1196 )) 1197 .with_field(field( 1198 "quantity_unit", 1199 "quantity_unit", 1200 radroots_core::RadrootsCoreUnit::describe(ctx), 1201 "crates/events/src/order_economics.rs", 1202 74, 1203 )) 1204 .with_field(field( 1205 "unit_price_amount", 1206 "unit_price_amount", 1207 core_decimal(ctx), 1208 "crates/events/src/order_economics.rs", 1209 75, 1210 )) 1211 .with_field(field( 1212 "unit_price_currency", 1213 "unit_price_currency", 1214 core_currency(ctx), 1215 "crates/events/src/order_economics.rs", 1216 76, 1217 )) 1218 .with_field(field( 1219 "line_subtotal", 1220 "line_subtotal", 1221 radroots_core::RadrootsCoreMoney::describe(ctx), 1222 "crates/events/src/order_economics.rs", 1223 77, 1224 )); 1225 register(ctx, "RadrootsOrderEconomicItem", TypeDef::Struct(def)) 1226 } 1227 } 1228 1229 impl Dto for RadrootsOrderEconomics { 1230 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 1231 let def = StructDef::new( 1232 "RadrootsOrderEconomics", 1233 "RadrootsOrderEconomics", 1234 span("crates/events/src/order_economics.rs", 119), 1235 ) 1236 .with_field(field( 1237 "quote_id", 1238 "quote_id", 1239 RadrootsOrderQuoteId::describe(ctx), 1240 "crates/events/src/order_economics.rs", 1241 120, 1242 )) 1243 .with_field(field( 1244 "quote_version", 1245 "quote_version", 1246 u32::describe(ctx), 1247 "crates/events/src/order_economics.rs", 1248 121, 1249 )) 1250 .with_field(field( 1251 "pricing_basis", 1252 "pricing_basis", 1253 RadrootsOrderPricingBasis::describe(ctx), 1254 "crates/events/src/order_economics.rs", 1255 122, 1256 )) 1257 .with_field(field( 1258 "currency", 1259 "currency", 1260 core_currency(ctx), 1261 "crates/events/src/order_economics.rs", 1262 123, 1263 )) 1264 .with_field(field( 1265 "items", 1266 "items", 1267 <Vec<RadrootsOrderEconomicItem> as Dto>::describe(ctx), 1268 "crates/events/src/order_economics.rs", 1269 124, 1270 )) 1271 .with_field(field( 1272 "discounts", 1273 "discounts", 1274 <Vec<RadrootsOrderEconomicLine> as Dto>::describe(ctx), 1275 "crates/events/src/order_economics.rs", 1276 125, 1277 )) 1278 .with_field(field( 1279 "adjustments", 1280 "adjustments", 1281 <Vec<RadrootsOrderEconomicLine> as Dto>::describe(ctx), 1282 "crates/events/src/order_economics.rs", 1283 126, 1284 )) 1285 .with_field(field( 1286 "subtotal", 1287 "subtotal", 1288 radroots_core::RadrootsCoreMoney::describe(ctx), 1289 "crates/events/src/order_economics.rs", 1290 127, 1291 )) 1292 .with_field(field( 1293 "discount_total", 1294 "discount_total", 1295 radroots_core::RadrootsCoreMoney::describe(ctx), 1296 "crates/events/src/order_economics.rs", 1297 128, 1298 )) 1299 .with_field(field( 1300 "adjustment_total", 1301 "adjustment_total", 1302 radroots_core::RadrootsCoreMoney::describe(ctx), 1303 "crates/events/src/order_economics.rs", 1304 129, 1305 )) 1306 .with_field(field( 1307 "total", 1308 "total", 1309 radroots_core::RadrootsCoreMoney::describe(ctx), 1310 "crates/events/src/order_economics.rs", 1311 130, 1312 )); 1313 register(ctx, "RadrootsOrderEconomics", TypeDef::Struct(def)) 1314 } 1315 } 1316 1317 impl Dto for RadrootsOrderRevisionOutcome { 1318 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 1319 let def = EnumDef::new( 1320 "RadrootsOrderRevisionOutcome", 1321 "RadrootsOrderRevisionDecision", 1322 EnumRepr::Internal { 1323 tag: "decision".to_owned(), 1324 }, 1325 span("crates/events/src/order.rs", 221), 1326 ) 1327 .with_variant(VariantDef::new( 1328 "Accepted", 1329 "accepted", 1330 VariantShape::Unit, 1331 span("crates/events/src/order.rs", 222), 1332 )) 1333 .with_variant(VariantDef::new( 1334 "Declined", 1335 "declined", 1336 VariantShape::Struct(vec![field( 1337 "reason", 1338 "reason", 1339 String::describe(ctx), 1340 "crates/events/src/order.rs", 1341 223, 1342 )]), 1343 span("crates/events/src/order.rs", 223), 1344 )); 1345 register(ctx, "RadrootsOrderRevisionOutcome", TypeDef::Enum(def)) 1346 } 1347 } 1348 1349 impl Dto for RadrootsOrderEnvelopeDto { 1350 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 1351 let def = StructDef { 1352 generics: vec![GenericParam::new("T")], 1353 ..StructDef::new( 1354 "RadrootsOrderEnvelopeDto", 1355 "RadrootsOrderEnvelope", 1356 span("crates/events/src/order.rs", 408), 1357 ) 1358 } 1359 .with_field(field( 1360 "version", 1361 "version", 1362 u16::describe(ctx), 1363 "crates/events/src/order.rs", 1364 409, 1365 )) 1366 .with_field(field( 1367 "domain", 1368 "domain", 1369 RadrootsCommercialDomain::describe(ctx), 1370 "crates/events/src/order.rs", 1371 410, 1372 )) 1373 .with_field(field( 1374 "message_type", 1375 "type", 1376 RadrootsOrderEventType::describe(ctx), 1377 "crates/events/src/order.rs", 1378 412, 1379 )) 1380 .with_field(field( 1381 "order_id", 1382 "order_id", 1383 String::describe(ctx), 1384 "crates/events/src/order.rs", 1385 413, 1386 )) 1387 .with_field(field( 1388 "listing_addr", 1389 "listing_addr", 1390 String::describe(ctx), 1391 "crates/events/src/order.rs", 1392 414, 1393 )) 1394 .with_field(field( 1395 "payload", 1396 "payload", 1397 TypeRef::GenericParam("T".to_owned()), 1398 "crates/events/src/order.rs", 1399 415, 1400 )); 1401 register(ctx, "RadrootsOrderEnvelopeDto", TypeDef::Struct(def)) 1402 } 1403 } 1404 1405 impl Dto for RadrootsCommercialEnvelopeDto { 1406 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 1407 let def = StructDef { 1408 generics: vec![GenericParam::new("T")], 1409 ..StructDef::new( 1410 "RadrootsCommercialEnvelopeDto", 1411 "RadrootsCommercialEnvelope", 1412 span("crates/events/src/order.rs", 408), 1413 ) 1414 } 1415 .with_field(field( 1416 "version", 1417 "version", 1418 u16::describe(ctx), 1419 "crates/events/src/order.rs", 1420 409, 1421 )) 1422 .with_field(field( 1423 "domain", 1424 "domain", 1425 RadrootsCommercialDomain::describe(ctx), 1426 "crates/events/src/order.rs", 1427 410, 1428 )) 1429 .with_field(field( 1430 "message_type", 1431 "type", 1432 RadrootsCommercialMessageTypeDto::describe(ctx), 1433 "crates/events/src/order.rs", 1434 412, 1435 )) 1436 .with_field(optional_nullable_field( 1437 "order_id", 1438 "order_id", 1439 <Option<String> as Dto>::describe(ctx), 1440 "crates/events/src/order.rs", 1441 413, 1442 )) 1443 .with_field(field( 1444 "listing_addr", 1445 "listing_addr", 1446 String::describe(ctx), 1447 "crates/events/src/order.rs", 1448 414, 1449 )) 1450 .with_field(field( 1451 "payload", 1452 "payload", 1453 TypeRef::GenericParam("T".to_owned()), 1454 "crates/events/src/order.rs", 1455 415, 1456 )); 1457 register(ctx, "RadrootsCommercialEnvelopeDto", TypeDef::Struct(def)) 1458 } 1459 } 1460 1461 impl Dto for RadrootsCommercialMessageTypeDto { 1462 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 1463 let def = EnumDef::new( 1464 "RadrootsCommercialMessageTypeDto", 1465 "RadrootsCommercialMessageType", 1466 EnumRepr::External, 1467 span("crates/events/src/order.rs", 408), 1468 ) 1469 .with_variant(unit_variant( 1470 "ListingValidateRequest", 1471 "listing_validate_request", 1472 "crates/events/src/order.rs", 1473 408, 1474 )) 1475 .with_variant(unit_variant( 1476 "ListingValidateResult", 1477 "listing_validate_result", 1478 "crates/events/src/order.rs", 1479 408, 1480 )) 1481 .with_variant(unit_variant( 1482 "OrderRequest", 1483 "order_request", 1484 "crates/events/src/order.rs", 1485 408, 1486 )) 1487 .with_variant(unit_variant( 1488 "OrderResponse", 1489 "order_response", 1490 "crates/events/src/order.rs", 1491 408, 1492 )) 1493 .with_variant(unit_variant( 1494 "OrderRevision", 1495 "order_revision", 1496 "crates/events/src/order.rs", 1497 408, 1498 )) 1499 .with_variant(unit_variant( 1500 "OrderRevisionAccept", 1501 "order_revision_accept", 1502 "crates/events/src/order.rs", 1503 408, 1504 )) 1505 .with_variant(unit_variant( 1506 "OrderRevisionDecline", 1507 "order_revision_decline", 1508 "crates/events/src/order.rs", 1509 408, 1510 )) 1511 .with_variant(unit_variant( 1512 "Question", 1513 "question", 1514 "crates/events/src/order.rs", 1515 408, 1516 )) 1517 .with_variant(unit_variant( 1518 "Answer", 1519 "answer", 1520 "crates/events/src/order.rs", 1521 408, 1522 )) 1523 .with_variant(unit_variant( 1524 "DiscountRequest", 1525 "discount_request", 1526 "crates/events/src/order.rs", 1527 408, 1528 )) 1529 .with_variant(unit_variant( 1530 "DiscountOffer", 1531 "discount_offer", 1532 "crates/events/src/order.rs", 1533 408, 1534 )) 1535 .with_variant(unit_variant( 1536 "DiscountAccept", 1537 "discount_accept", 1538 "crates/events/src/order.rs", 1539 408, 1540 )) 1541 .with_variant(unit_variant( 1542 "DiscountDecline", 1543 "discount_decline", 1544 "crates/events/src/order.rs", 1545 408, 1546 )) 1547 .with_variant(unit_variant( 1548 "Cancel", 1549 "cancel", 1550 "crates/events/src/order.rs", 1551 408, 1552 )); 1553 register(ctx, "RadrootsCommercialMessageTypeDto", TypeDef::Enum(def)) 1554 } 1555 } 1556 1557 impl Dto for RadrootsCommercialTransportLaneDto { 1558 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 1559 let def = EnumDef::new( 1560 "RadrootsCommercialTransportLaneDto", 1561 "RadrootsCommercialTransportLane", 1562 EnumRepr::External, 1563 span("crates/events/src/order.rs", 408), 1564 ) 1565 .with_variant(unit_variant( 1566 "Service", 1567 "service", 1568 "crates/events/src/order.rs", 1569 408, 1570 )) 1571 .with_variant(unit_variant( 1572 "Public", 1573 "public", 1574 "crates/events/src/order.rs", 1575 408, 1576 )); 1577 register(ctx, "RadrootsCommercialTransportLaneDto", TypeDef::Enum(def)) 1578 } 1579 } 1580 1581 impl Dto for RadrootsOrderStatusDto { 1582 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 1583 let def = EnumDef::new( 1584 "RadrootsOrderStatusDto", 1585 "RadrootsOrderStatus", 1586 EnumRepr::External, 1587 span("crates/events/src/order.rs", 408), 1588 ) 1589 .with_variant(unit_variant( 1590 "Draft", 1591 "draft", 1592 "crates/events/src/order.rs", 1593 408, 1594 )) 1595 .with_variant(unit_variant( 1596 "Validated", 1597 "validated", 1598 "crates/events/src/order.rs", 1599 408, 1600 )) 1601 .with_variant(unit_variant( 1602 "Requested", 1603 "requested", 1604 "crates/events/src/order.rs", 1605 408, 1606 )) 1607 .with_variant(unit_variant( 1608 "Questioned", 1609 "questioned", 1610 "crates/events/src/order.rs", 1611 408, 1612 )) 1613 .with_variant(unit_variant( 1614 "Revised", 1615 "revised", 1616 "crates/events/src/order.rs", 1617 408, 1618 )) 1619 .with_variant(unit_variant( 1620 "Accepted", 1621 "accepted", 1622 "crates/events/src/order.rs", 1623 408, 1624 )) 1625 .with_variant(unit_variant( 1626 "Declined", 1627 "declined", 1628 "crates/events/src/order.rs", 1629 408, 1630 )) 1631 .with_variant(unit_variant( 1632 "Cancelled", 1633 "cancelled", 1634 "crates/events/src/order.rs", 1635 408, 1636 )); 1637 register(ctx, "RadrootsOrderStatusDto", TypeDef::Enum(def)) 1638 } 1639 } 1640 1641 impl Dto for RadrootsListingQuestionDto { 1642 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 1643 let def = StructDef::new( 1644 "RadrootsListingQuestionDto", 1645 "RadrootsListingQuestion", 1646 span("crates/events/src/order.rs", 408), 1647 ) 1648 .with_field(field( 1649 "question_id", 1650 "question_id", 1651 String::describe(ctx), 1652 "crates/events/src/order.rs", 1653 408, 1654 )); 1655 register(ctx, "RadrootsListingQuestionDto", TypeDef::Struct(def)) 1656 } 1657 } 1658 1659 impl Dto for RadrootsListingAnswerDto { 1660 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 1661 let def = StructDef::new( 1662 "RadrootsListingAnswerDto", 1663 "RadrootsListingAnswer", 1664 span("crates/events/src/order.rs", 408), 1665 ) 1666 .with_field(field( 1667 "question_id", 1668 "question_id", 1669 String::describe(ctx), 1670 "crates/events/src/order.rs", 1671 408, 1672 )); 1673 register(ctx, "RadrootsListingAnswerDto", TypeDef::Struct(def)) 1674 } 1675 } 1676 1677 impl Dto for RadrootsListingDiscountRequestDto { 1678 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 1679 let def = StructDef::new( 1680 "RadrootsListingDiscountRequestDto", 1681 "RadrootsListingDiscountRequest", 1682 span("crates/events/src/order.rs", 408), 1683 ) 1684 .with_field(field( 1685 "discount_id", 1686 "discount_id", 1687 String::describe(ctx), 1688 "crates/events/src/order.rs", 1689 408, 1690 )) 1691 .with_field(field( 1692 "value", 1693 "value", 1694 RadrootsCoreDiscountValue::describe(ctx), 1695 "crates/events/src/order.rs", 1696 408, 1697 )); 1698 register(ctx, "RadrootsListingDiscountRequestDto", TypeDef::Struct(def)) 1699 } 1700 } 1701 1702 impl Dto for RadrootsListingDiscountOfferDto { 1703 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 1704 let def = StructDef::new( 1705 "RadrootsListingDiscountOfferDto", 1706 "RadrootsListingDiscountOffer", 1707 span("crates/events/src/order.rs", 408), 1708 ) 1709 .with_field(field( 1710 "discount_id", 1711 "discount_id", 1712 String::describe(ctx), 1713 "crates/events/src/order.rs", 1714 408, 1715 )) 1716 .with_field(field( 1717 "value", 1718 "value", 1719 RadrootsCoreDiscountValue::describe(ctx), 1720 "crates/events/src/order.rs", 1721 408, 1722 )); 1723 register(ctx, "RadrootsListingDiscountOfferDto", TypeDef::Struct(def)) 1724 } 1725 } 1726 1727 impl Dto for RadrootsListingDiscountDecisionDto { 1728 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 1729 let def = EnumDef::new( 1730 "RadrootsListingDiscountDecisionDto", 1731 "RadrootsListingDiscountDecision", 1732 EnumRepr::Adjacent { 1733 tag: "kind".to_owned(), 1734 content: "amount".to_owned(), 1735 }, 1736 span("crates/events/src/order.rs", 408), 1737 ) 1738 .with_variant(VariantDef::new( 1739 "Accept", 1740 "accept", 1741 VariantShape::Struct(vec![field( 1742 "value", 1743 "value", 1744 RadrootsCoreDiscountValue::describe(ctx), 1745 "crates/events/src/order.rs", 1746 408, 1747 )]), 1748 span("crates/events/src/order.rs", 408), 1749 )) 1750 .with_variant(VariantDef::new( 1751 "Decline", 1752 "decline", 1753 VariantShape::Struct(vec![optional_nullable_field( 1754 "reason", 1755 "reason", 1756 <Option<String> as Dto>::describe(ctx), 1757 "crates/events/src/order.rs", 1758 408, 1759 )]), 1760 span("crates/events/src/order.rs", 408), 1761 )); 1762 register(ctx, "RadrootsListingDiscountDecisionDto", TypeDef::Enum(def)) 1763 } 1764 } 1765 1766 impl Dto for RadrootsListingCancelDto { 1767 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 1768 let def = StructDef::new( 1769 "RadrootsListingCancelDto", 1770 "RadrootsListingCancel", 1771 span("crates/events/src/order.rs", 408), 1772 ) 1773 .with_field(optional_nullable_field( 1774 "reason", 1775 "reason", 1776 <Option<String> as Dto>::describe(ctx), 1777 "crates/events/src/order.rs", 1778 408, 1779 )); 1780 register(ctx, "RadrootsListingCancelDto", TypeDef::Struct(def)) 1781 } 1782 } 1783 1784 impl Dto for RadrootsOrderResponseDto { 1785 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 1786 accepted_reason_struct( 1787 ctx, 1788 "RadrootsOrderResponseDto", 1789 "RadrootsOrderResponse", 1790 ) 1791 } 1792 } 1793 1794 impl Dto for RadrootsOrderRevisionResponseDto { 1795 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 1796 accepted_reason_struct( 1797 ctx, 1798 "RadrootsOrderRevisionResponseDto", 1799 "RadrootsOrderRevisionResponse", 1800 ) 1801 } 1802 } 1803 1804 impl Dto for RadrootsOrderRevisionDto { 1805 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 1806 let def = StructDef::new( 1807 "RadrootsOrderRevisionDto", 1808 "RadrootsOrderRevision", 1809 span("crates/events/src/order.rs", 408), 1810 ) 1811 .with_field(field( 1812 "revision_id", 1813 "revision_id", 1814 String::describe(ctx), 1815 "crates/events/src/order.rs", 1816 408, 1817 )) 1818 .with_field(field( 1819 "changes", 1820 "changes", 1821 <Vec<RadrootsOrderChangeDto> as Dto>::describe(ctx), 1822 "crates/events/src/order.rs", 1823 408, 1824 )); 1825 register(ctx, "RadrootsOrderRevisionDto", TypeDef::Struct(def)) 1826 } 1827 } 1828 1829 impl Dto for RadrootsOrderChangeDto { 1830 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 1831 let def = EnumDef::new( 1832 "RadrootsOrderChangeDto", 1833 "RadrootsOrderChange", 1834 EnumRepr::Adjacent { 1835 tag: "kind".to_owned(), 1836 content: "amount".to_owned(), 1837 }, 1838 span("crates/events/src/order.rs", 408), 1839 ) 1840 .with_variant(VariantDef::new( 1841 "BinCount", 1842 "bin_count", 1843 VariantShape::Struct(vec![ 1844 field( 1845 "item_index", 1846 "item_index", 1847 u32::describe(ctx), 1848 "crates/events/src/order.rs", 1849 408, 1850 ), 1851 field( 1852 "bin_count", 1853 "bin_count", 1854 u32::describe(ctx), 1855 "crates/events/src/order.rs", 1856 408, 1857 ), 1858 ]), 1859 span("crates/events/src/order.rs", 408), 1860 )) 1861 .with_variant(VariantDef::new( 1862 "ItemAdd", 1863 "item_add", 1864 VariantShape::Struct(vec![field( 1865 "item", 1866 "item", 1867 RadrootsOrderItem::describe(ctx), 1868 "crates/events/src/order.rs", 1869 408, 1870 )]), 1871 span("crates/events/src/order.rs", 408), 1872 )) 1873 .with_variant(VariantDef::new( 1874 "ItemRemove", 1875 "item_remove", 1876 VariantShape::Struct(vec![field( 1877 "item_index", 1878 "item_index", 1879 u32::describe(ctx), 1880 "crates/events/src/order.rs", 1881 408, 1882 )]), 1883 span("crates/events/src/order.rs", 408), 1884 )); 1885 register(ctx, "RadrootsOrderChangeDto", TypeDef::Enum(def)) 1886 } 1887 } 1888 1889 impl Dto for RadrootsCommercialMessagePayloadDto { 1890 fn describe(ctx: &mut DescribeCtx) -> TypeRef { 1891 let def = EnumDef::new( 1892 "RadrootsCommercialMessagePayloadDto", 1893 "RadrootsCommercialMessagePayload", 1894 EnumRepr::Adjacent { 1895 tag: "kind".to_owned(), 1896 content: "amount".to_owned(), 1897 }, 1898 span("crates/events/src/order.rs", 408), 1899 ) 1900 .with_variant(newtype_variant( 1901 "ListingValidateRequest", 1902 "listing_validate_request", 1903 RadrootsTradeValidationListingRequest::describe(ctx), 1904 )) 1905 .with_variant(newtype_variant( 1906 "ListingValidateResult", 1907 "listing_validate_result", 1908 RadrootsTradeValidationListingResult::describe(ctx), 1909 )) 1910 .with_variant(newtype_variant( 1911 "TradeOrderRequested", 1912 "trade_order_requested", 1913 RadrootsOrderRequest::describe(ctx), 1914 )) 1915 .with_variant(newtype_variant( 1916 "OrderResponse", 1917 "order_response", 1918 RadrootsOrderResponseDto::describe(ctx), 1919 )) 1920 .with_variant(newtype_variant( 1921 "OrderRevision", 1922 "order_revision", 1923 RadrootsOrderRevisionDto::describe(ctx), 1924 )) 1925 .with_variant(newtype_variant( 1926 "OrderRevisionAccept", 1927 "order_revision_accept", 1928 RadrootsOrderRevisionResponseDto::describe(ctx), 1929 )) 1930 .with_variant(newtype_variant( 1931 "OrderRevisionDecline", 1932 "order_revision_decline", 1933 RadrootsOrderRevisionResponseDto::describe(ctx), 1934 )) 1935 .with_variant(newtype_variant( 1936 "Question", 1937 "question", 1938 RadrootsListingQuestionDto::describe(ctx), 1939 )) 1940 .with_variant(newtype_variant( 1941 "Answer", 1942 "answer", 1943 RadrootsListingAnswerDto::describe(ctx), 1944 )) 1945 .with_variant(newtype_variant( 1946 "DiscountRequest", 1947 "discount_request", 1948 RadrootsListingDiscountRequestDto::describe(ctx), 1949 )) 1950 .with_variant(newtype_variant( 1951 "DiscountOffer", 1952 "discount_offer", 1953 RadrootsListingDiscountOfferDto::describe(ctx), 1954 )) 1955 .with_variant(newtype_variant( 1956 "DiscountAccept", 1957 "discount_accept", 1958 RadrootsListingDiscountDecisionDto::describe(ctx), 1959 )) 1960 .with_variant(newtype_variant( 1961 "DiscountDecline", 1962 "discount_decline", 1963 RadrootsListingDiscountDecisionDto::describe(ctx), 1964 )) 1965 .with_variant(newtype_variant( 1966 "Cancel", 1967 "cancel", 1968 RadrootsListingCancelDto::describe(ctx), 1969 )); 1970 register(ctx, "RadrootsCommercialMessagePayloadDto", TypeDef::Enum(def)) 1971 } 1972 } 1973 1974 fn register(ctx: &mut DescribeCtx, rust_ident: &str, type_def: TypeDef) -> TypeRef { 1975 ctx.register_type(RustTypeId::new("radroots_events", rust_ident), type_def) 1976 } 1977 1978 fn core_decimal(ctx: &mut DescribeCtx) -> TypeRef { 1979 external_core_alias(ctx, "RadrootsCoreDecimal") 1980 } 1981 1982 fn core_currency(ctx: &mut DescribeCtx) -> TypeRef { 1983 external_core_alias(ctx, "RadrootsCoreCurrency") 1984 } 1985 1986 fn external_core_alias(ctx: &mut DescribeCtx, rust_ident: &str) -> TypeRef { 1987 ctx.register_type( 1988 RustTypeId::new("radroots_core", rust_ident), 1989 TypeDef::Struct(StructDef::new( 1990 rust_ident, 1991 rust_ident, 1992 span("crates/core/src/dto.rs", 1), 1993 )), 1994 ) 1995 } 1996 1997 fn accepted_reason_struct(ctx: &mut DescribeCtx, rust_ident: &str, export_name: &str) -> TypeRef { 1998 let def = StructDef::new( 1999 rust_ident, 2000 export_name, 2001 span("crates/events/src/order.rs", 408), 2002 ) 2003 .with_field(field( 2004 "accepted", 2005 "accepted", 2006 bool::describe(ctx), 2007 "crates/events/src/order.rs", 2008 408, 2009 )) 2010 .with_field(optional_nullable_field( 2011 "reason", 2012 "reason", 2013 <Option<String> as Dto>::describe(ctx), 2014 "crates/events/src/order.rs", 2015 408, 2016 )); 2017 register(ctx, rust_ident, TypeDef::Struct(def)) 2018 } 2019 2020 fn unit_variant(rust_name: &str, wire_name: &str, file: &str, line: u32) -> VariantDef { 2021 VariantDef::new(rust_name, wire_name, VariantShape::Unit, span(file, line)) 2022 } 2023 2024 fn newtype_variant(rust_name: &str, wire_name: &str, ty: TypeRef) -> VariantDef { 2025 VariantDef::new( 2026 rust_name, 2027 wire_name, 2028 VariantShape::Newtype(ty), 2029 span("crates/events/src/order.rs", 408), 2030 ) 2031 } 2032 2033 fn optional_nullable_field( 2034 rust_name: &str, 2035 wire_name: &str, 2036 ty: TypeRef, 2037 file: &str, 2038 line: u32, 2039 ) -> FieldDef { 2040 field(rust_name, wire_name, ty, file, line).with_presence(FieldPresence::optional_nullable()) 2041 } 2042 2043 fn field(rust_name: &str, wire_name: &str, ty: TypeRef, file: &str, line: u32) -> FieldDef { 2044 FieldDef::new( 2045 IdentName::new(rust_name), 2046 WireFieldNames::same(wire_name), 2047 TargetFieldNames::new(wire_name, rust_name), 2048 ty, 2049 span(file, line), 2050 ) 2051 } 2052 2053 fn span(file: &str, line: u32) -> SourceSpan { 2054 SourceSpan::new(file, line, 1) 2055 } 2056 2057 #[cfg(test)] 2058 mod tests { 2059 use dto_bindgen_core::{TypeDef, build_registry}; 2060 2061 use super::dto_roots; 2062 2063 #[test] 2064 fn event_descriptor_roots_build_registry() { 2065 let registry = build_registry(dto_roots()); 2066 2067 assert!(!registry.has_errors()); 2068 assert_eq!(registry.roots.len(), dto_roots().len()); 2069 assert!(registry.types_by_id.values().any( 2070 |def| matches!(def, TypeDef::Struct(def) if def.export_name == "RadrootsNostrEvent") 2071 )); 2072 assert!( 2073 registry 2074 .types_by_id 2075 .values() 2076 .any(|def| matches!(def, TypeDef::Struct(def) if def.export_name == "RadrootsListingImageSize")) 2077 ); 2078 } 2079 2080 #[test] 2081 fn option_fields_are_optional_nullable() { 2082 let registry = build_registry(dto_roots()); 2083 2084 let product = registry 2085 .types_by_id 2086 .values() 2087 .find_map(|def| match def { 2088 TypeDef::Struct(def) if def.export_name == "RadrootsListingProduct" => Some(def), 2089 _ => None, 2090 }) 2091 .expect("listing product descriptor exists"); 2092 let summary = product 2093 .fields 2094 .iter() 2095 .find(|field| field.rust_name.as_str() == "summary") 2096 .expect("summary field exists"); 2097 assert!(!summary.presence.required_on_deserialize); 2098 assert!(summary.presence.nullable); 2099 2100 let event_ref = registry 2101 .types_by_id 2102 .values() 2103 .find_map(|def| match def { 2104 TypeDef::Struct(def) if def.export_name == "RadrootsNostrEventRef" => Some(def), 2105 _ => None, 2106 }) 2107 .expect("event ref descriptor exists"); 2108 let d_tag = event_ref 2109 .fields 2110 .iter() 2111 .find(|field| field.rust_name.as_str() == "d_tag") 2112 .expect("d_tag field exists"); 2113 assert!(!d_tag.presence.required_on_deserialize); 2114 assert!(d_tag.presence.nullable); 2115 } 2116 }