thalo-rs / esdl

Event-sourcing Schema Definition Language
Apache License 2.0
42 stars 3 forks source link

Implement Serialize, Deserialize on "type" structs generated from ESDL files #1

Closed Shearerbeard closed 2 years ago

Shearerbeard commented 2 years ago

Currently referencing ESDL "types" from ESDL "events" will lead to a build error as the underlying "types" do not implement Serialize/Deserialize and will break the trait derivation for the "event" in question. Example ESDL from my test app lincluded:

aggregate Order {
    order_placed(order_type: String!, line_items: [LineItem!]!, address: Address): OrderPlaced!
    order_status_changed(id: String!, order_status: String!): OrderStatusChanged!
}

event OrderPlaced {
    id: String!
    line_items: [LineItem!]!
    order_type: String!
    order_status: String!
    address: Address
}

event OrderStatusChanged {
    id: String!
    order_status: String!
}

type LineItem {
    item_id: String!
    quantity: Int!
    notes: String
}

type Address {
    address_1: String!
    address_2: String
    city: String!
    state: String!
    zip: String!
}

In this scenario the compiler will puke on the following:

     pub address: std::option::Option<Address>,
     |     ^^^ the trait `Deserialize<'_>` is not implemented for `Address`
     pub line_items: std::vec::Vec<LineItem>,
     |     ^^^ the trait `Deserialize<'_>` is not implemented for `LineItem`
     pub address: std::option::Option<Address>,
     |     ^^^ the trait `Serialize` is not implemented for `Address`
     pub line_items: std::vec::Vec<LineItem>,
     |     ^^^ the trait `Serialize` is not implemented for `LineItem`
tqwewe commented 2 years ago

Hey @Shearerbeard, I haven't been using types yet in my personal project so I seemed to have missed this, but your change it exactly what I would've done.

I really appreciate you going ahead and opening a PR directly! I'll merge it and publish an updated version now.

For commits I use a tool called cocogitto to use the conventional commit standard, so I might have to update the commit messages to keep cocogitto happy.

tqwewe commented 2 years ago

Published fix under version 0.2.1