ryan-mars / stochastic

TypeScript framework for building event-driven services. Easily go from Event Storming → Code.
MIT License
6 stars 1 forks source link

feat: consolidate event and shape. rename type to shape. #39

Closed sam-goodwin closed 3 years ago

sam-goodwin commented 3 years ago

Closes #35 Closes #34

This change consolidates the definition of Shapes and DomainEvents.

  1. Shapes and DomainEvents are declared almost identically.
export class FlightSchedule extends Shape("ScheduledFlightAdded", {
  flightNo: string(),
  aircraftType: string(),
  origin: string(),
  destination: string(),
  days: map(string(), object({ scheduledDeparture: date(), scheduledArrival: date() })),
}) {}

export class ScheduledFlightAdded extends DomainEvent("ScheduledFlightAdded", {
  flightNo: string(),
  add: object({
    day: string(),
    scheduledDeparture: date(),
    scheduledArrival: date(),
  }),
}) {}

Except that DomainEvent has kind: "DomainEvent" and is a first-class Component.

  1. de-coupled the DomainEventEnvelope from the DomainEvent itself.
const flightCreated = new DomainEventEnvelope({
    id: "1sC26Tx3VUi42mghcNopBYsRxD9",
    time: new Date("2021-05-07T04:34:35.302Z"),
    source: "FlightScheduleAggregate",
    source_id: "PA576",
    payload: new FlightCreatedEvent({
      flightNo: "PA576",
      aircraftType: "B787-9",
      origin: "SFO",
      destination: "MIA",
    }),
  });