Skip to content

TypeIDs

Estoria uses a lightweight TypeID implementation to uniquely identify both aggregates and events. A TypeID is a tuple of (string, uuid), where the string is a type name (e.g. “user”, “order”, “product”) and the UUID is a unique identifier for a specific instance of that type. It is largely a convenience for transferring and presenting these two pieces of information as a single value.

import "github.com/go-estoria/estoria/typeid"

id := typeid.NewV4("user")
// or
id := typeid.NewV7("user")
// or
id := typeid.New("user", uuid.Must(uuid.FromString("978e35ad-876f-43df-8e7d-cbcb6dd855f9")))

fmt.Println(id.Type)   // "user"
fmt.Println(id.UUID)   // 978e35ad-876f-43df-8e7d-cbcb6dd855f9
fmt.Println(id.String()) // "user_978e35ad-876f-43df-8e7d-cbcb6dd855f9"

Parsing

typeid.Parse round-trips IDs from paths, query strings, and logs, accepting exactly what ID.String produces:

id, err := typeid.Parse("user_978e35ad-876f-43df-8e7d-cbcb6dd855f9")

The UUID is always the final 36 characters of the string, so type names containing underscores parse unambiguously.

Type Names

Type names must be non-empty and must not begin or end with an underscore. Interior underscores are fine, so snake_case names like funds_deposited work. The same grammar applies to aggregate type names and event type names, validated when an aggregate store is created and when event types are registered.

Note that the Estoria typeid package is not an implementation of Jetify’s TypeID specification. It is simply a struct that holds a type name and a UUID.