Crate esdl

source ·
Expand description

ESDL

Event-sourcing Schema Definition Language


Schema definition language for defining aggregates, commands, events & custom types.

Heavily inspired by GraphQL syntax, you can describe aggregates which can be used for codegen in different languages.

Install

Due to the wit-bindgen project not having their crates published yet (see https://github.com/bytecodealliance/wit-bindgen/issues/180), esdl is not up to date on crates.io and it’s advised to use the git url as the dependency for now.

esdl = { git = "https://github.com/thalo-rs/esdl", features = ["codegen-rust"] }

Possible features include codegen-rust, codegen-rust-wasm and codegen-typescript.

Code generation

ESDL schemas can be used for code generation.

The Rust crate currently supports code generation for:

Additional languages may be added in the future. Contributions are welcome!

Example

version = "0.1.0"

aggregate BankAccount {
  open_account(initial_balance: Float) -> OpenedAccount
  deposit_funds(amount: Float) -> ReceivedFunds
  withdraw_funds(amount: Float) -> SentFunds
  send_funds(amount: Float, user: User) -> (SentFunds? | ReceivedFunds?)
}

event OpenedAccount {
  initial_balance: Float
}

event SentFunds {
  amount: Float
  user: User?
}

event ReceivedFunds {
  amount: Float
  user: User?
}

type User {
  id: String
  name: String?
}

Scalar Types

ScalarRust TypeTypeScript Type
StringStringstring
Inti32number
Longi64number
Floatf32number
Doublef64number
Boolboolboolean
BytesVec<u8>string

Optional & Required

Types can be marked as optional by adding the ? suffix.

TypeSyntaxExample
RequiredTString
OptionalT?String?

Repeating Types

Types can be repeated by wrapping them in [].

TypeSyntaxExample
SingleTString
Array[T][String]

Remember, we can mark types as optional, even in arrays.

TypeSyntaxExample
Optional Array[T?]?[String?]?
Required Array[T?][String?]
Required Array Items[T]?[String]?
Required Array Items[T][String]

Integrates with Thalo to generate Rust code.

Code generation

For usage with code generation, see [codegen].

Modules

Enums

Functions

Parse and validate an ESDL schema string.