Deterministic event bus and message trace library for MoonBit
moon add violetcb/eventraillet payload = @eventrail.record_value([
@eventrail.field("order_id", @eventrail.text_value("A-1001")),
@eventrail.field("amount", @eventrail.int_value(320)),
])
let event = @eventrail.envelope("order.created", payload, timestamp_ms=20260809)moon run cmd/mainmoon fmt --check
moon check
moon check --deny-warn
moon build
moon test
moon test --deny-warn
moon info
moon run cmd/main
moon packagevioletcb/eventrailpub(all) struct BatchDecision {
index : Int
event_id : String
topic : String
decision : RuleDecision
} derive(Eq, Debug)pub(all) struct BatchRouteReport {
name : String
events : Int
routed_events : Int
unmatched_events : Int
deliveries_planned : Int
rows : Array[BatchRouteRow]
} derive(Eq, Debug)pub(all) struct BatchRuleReport {
name : String
checked : Int
accepted : Int
rejected : Int
decisions : Array[BatchDecision]
} derive(Eq, Debug)pub(all) struct BatchValidationReport {
name : String
checked : Int
valid : Int
invalid : Int
issues : Array[BatchValidationIssue]
} derive(Eq, Debug)pub(all) struct Bus {
subscriptions : Array[Subscription]
deliveries : Array[Delivery]
dead_letters : Array[DeadLetter]
} derive(Eq, Debug)fn Bus::dead_letters_for_subscription(self : Bus, subscription_id : StringView) -> Array[DeadLetter]fn Bus::explain(self : Bus, event : Envelope, mode? : DeliveryMode) -> Result[RouteExplanation, EventRailError]fn Bus::publish(self : Bus, event : Envelope, handler : (Subscription, Envelope) -> HandlerResult) -> Result[(Bus, PublishReport), EventRailError]fn Bus::publish_with_mode(self : Bus, event : Envelope, mode : DeliveryMode, handler : (Subscription, Envelope) -> HandlerResult) -> Result[(Bus, PublishReport), EventRailError]fn Bus::route_with_mode(self : Bus, event : Envelope, mode : DeliveryMode) -> Result[Array[Subscription], EventRailError]fn Bus::subscribe(self : Bus, id : StringView, pattern : StringView, priority? : Int, group? : StringView, retry? : RetryPolicy, enabled? : Bool, guards? : ArrayView[EventPredicate]) -> Result[Bus, EventRailError]pub(all) struct BusPlan {
name : String
subscriptions : Array[SubscriptionBlueprint]
} derive(Eq, Debug)fn BusPlan::coverage(self : BusPlan, events : ArrayView[Envelope], mode? : DeliveryMode) -> Result[PlanCoverageReport, EventRailError]pub(all) struct Delivery {
event_id : String
subscription_id : String
topic : String
status : DeliveryStatus
attempt : Int
delay_ms : Int
} derive(Eq, Debug)pub(all) struct DiagnosticEntry {
severity : DiagnosticSeverity
code : String
subject : String
message : String
} derive(Eq, Debug)pub(all) struct DiagnosticReport {
name : String
checked : Int
infos : Int
warnings : Int
errors : Int
entries : Array[DiagnosticEntry]
} derive(Eq, Debug)fn DiagnosticReport::add(self : DiagnosticReport, severity : DiagnosticSeverity, code : StringView, subject : StringView, message : StringView) -> DiagnosticReportfn DiagnosticReport::error(self : DiagnosticReport, code : StringView, subject : StringView, message : StringView) -> DiagnosticReportfn DiagnosticReport::info(self : DiagnosticReport, code : StringView, subject : StringView, message : StringView) -> DiagnosticReportfn DiagnosticReport::warning(self : DiagnosticReport, code : StringView, subject : StringView, message : StringView) -> DiagnosticReportfn EventBatch::apply_retention(self : EventBatch, policy : RetentionPolicy) -> Result[(EventBatch, RetentionReport), EventRailError]fn EventBatch::filter(self : EventBatch, pattern : StringView) -> Result[EventBatch, EventRailError]fn EventBatch::project(self : EventBatch, spec : ProjectionSpec) -> Result[EventProjection, EventRailError]fn EventBatch::publish(self : EventBatch, bus : Bus, handler : (Subscription, Envelope) -> HandlerResult, mode? : DeliveryMode) -> Result[(Bus, BatchPublishReport), EventRailError]fn EventBatch::retention_plan(self : EventBatch, policy : RetentionPolicy) -> Result[RetentionReport, EventRailError]fn EventBatch::route_preview(self : EventBatch, bus : Bus, mode? : DeliveryMode) -> Result[BatchRouteReport, EventRailError]fn EventBatch::snapshot(self : EventBatch, bus : Bus, name? : StringView, timestamp_ms? : Int) -> EventSnapshotpub(all) struct EventPipeline {
name : String
batch : EventBatch
actions : Array[PipelineAction]
} derive(Eq, Debug)pub(all) enum EventPredicate {
TopicMatches(String)
HeaderEquals(String, String)
HeaderExists(String)
PayloadExists(String)
TextEquals(String, String)
TextContains(String, String)
IntAtLeast(String, Int)
IntAtMost(String, Int)
IntBetween(String, Int, Int)
BoolEquals(String, Bool)
AllOf(Array[EventPredicate])
AnyOf(Array[EventPredicate])
Not(EventPredicate)
} derive(Eq, Debug)pub(all) struct EventProjection {
spec : ProjectionSpec
rows : Array[ProjectionRow]
skipped : Int
issues : Array[ProjectionIssue]
} derive(Eq, Debug)fn EventProjection::apply(self : EventProjection, event : Envelope) -> Result[EventProjection, EventRailError]pub(all) struct EventQuery {
name : String
topic : TopicPattern?
headers : Array[HeaderFilter]
predicates : Array[EventPredicate]
min_timestamp_ms : Int?
max_timestamp_ms : Int?
offset : Int
limit : Int
sort : QuerySort
} derive(Eq, Debug)fn EventQuery::apply(self : EventQuery, events : ArrayView[Envelope]) -> Result[QueryResult, EventRailError]fn EventQuery::matches(self : EventQuery, event : Envelope) -> Result[(Bool, String), EventRailError]fn EventQuery::with_time_range(self : EventQuery, min_timestamp_ms? : Int, max_timestamp_ms? : Int) -> EventQueryfn EventQuery::with_topic(self : EventQuery, topic : StringView) -> Result[EventQuery, EventRailError]pub(all) struct EventSchema {
name : String
topic : TopicPattern?
fields : Array[FieldSpec]
} derive(Eq, Debug)pub(all) struct EventSnapshot {
name : String
source : String
timestamp_ms : Int
event_count : Int
delivery_count : Int
dead_letter_count : Int
digests : Array[EventDigest]
topic_counts : Array[TopicCount]
delivery_stats : DeliveryStats
subscription_stats : Array[SnapshotDeliveryRow]
} derive(Eq, Debug)fn EventSnapshot::subscription_stats_for(self : EventSnapshot, subscription_id : StringView) -> DeliveryStats?fn EventTape::apply_retention(self : EventTape, policy : RetentionPolicy) -> Result[(EventTape, RetentionReport), EventRailError]fn EventTape::project(self : EventTape, spec : ProjectionSpec) -> Result[EventProjection, EventRailError]fn EventTape::replay(self : EventTape, bus : Bus, handler : (Subscription, Envelope) -> HandlerResult) -> Result[(Bus, ReplayReport), EventRailError]fn EventTape::retention_plan(self : EventTape, policy : RetentionPolicy) -> Result[RetentionReport, EventRailError]fn EventTape::select(self : EventTape, pattern : StringView) -> Result[Array[Envelope], EventRailError]fn EventTape::snapshot(self : EventTape, bus : Bus, name? : StringView, timestamp_ms? : Int) -> EventSnapshotpub(all) enum EventValue {
VNull
VBool(Bool)
VInt(Int)
VText(String)
VList(Array[EventValue])
VRecord(Array[(String, EventValue)])
} derive(Eq, Debug)fn EventValue::require_path(self : EventValue, path : StringView) -> Result[EventValue, EventRailError]fn Outbox::from_report(self : Outbox, event : Envelope, report : PublishReport, now_ms : Int) -> Outboxpub(all) enum PipelineAction {
PipelineValidate(EventSchema)
PipelineRules(RuleSet)
PipelineRoute(Bus, DeliveryMode)
PipelineProject(ProjectionSpec)
PipelineSnapshot(Bus)
} derive(Eq, Debug)pub(all) struct PipelineRun {
name : String
stages : Array[PipelineStage]
passed : Int
failed : Int
warnings : Int
} derive(Eq, Debug)pub(all) struct PipelineStage {
index : Int
action : PipelineAction
status : PipelineStageStatus
summary : String
lines : Array[String]
} derive(Eq, Debug)pub(all) struct PlanIssue {
severity : PlanSeverity
code : String
message : String
} derive(Eq, Debug)pub(all) struct ProjectionSpec {
name : String
topic : TopicPattern
key_path : String
include_paths : Array[String]
require_key : Bool
} derive(Eq, Debug)fn ProjectionSpec::project_events(self : ProjectionSpec, events : ArrayView[Envelope]) -> Result[EventProjection, EventRailError]pub(all) struct RetentionPolicy {
name : String
topic : TopicPattern?
min_timestamp_ms : Int?
max_timestamp_ms : Int?
max_events : Int
max_events_per_topic : Int
compact_fingerprints : Bool
} derive(Eq, Debug)fn RetentionPolicy::with_compaction(self : RetentionPolicy, compact_fingerprints : Bool) -> RetentionPolicyfn RetentionPolicy::with_limits(self : RetentionPolicy, max_events? : Int, max_events_per_topic? : Int) -> RetentionPolicyfn RetentionPolicy::with_time_range(self : RetentionPolicy, min_timestamp_ms? : Int, max_timestamp_ms? : Int) -> RetentionPolicyfn RetentionPolicy::with_topic(self : RetentionPolicy, topic : StringView) -> Result[RetentionPolicy, EventRailError]pub(all) struct RetentionReport {
policy : String
source : String
scanned : Int
kept : Int
dropped : Int
topic_summaries : Array[RetentionTopicSummary]
decisions : Array[RetentionDecision]
} derive(Eq, Debug)pub(all) struct RouteExplanation {
event_id : String
topic : String
mode : DeliveryMode
selected : Array[String]
probes : Array[RouteProbe]
} derive(Eq, Debug)pub(all) struct SchemaReport {
name : String
valid : Bool
issues : Array[SchemaIssue]
} derive(Eq, Debug)pub(all) struct SnapshotChange {
kind : SnapshotChangeKind
event_id : String
before_fingerprint : String
after_fingerprint : String
} derive(Eq, Debug)pub(all) struct SnapshotDeliveryRow {
subscription_id : String
stats : DeliveryStats
} derive(Eq, Debug)pub(all) struct SnapshotDiff {
left : String
right : String
added : Int
removed : Int
changed : Int
changes : Array[SnapshotChange]
} derive(Eq, Debug)pub(all) struct Subscription {
id : String
pattern : TopicPattern
priority : Int
group : String
order : Int
retry : RetryPolicy
enabled : Bool
guards : Array[EventPredicate]
} derive(Eq, Debug)pub(all) struct SubscriptionBlueprint {
id : String
pattern : String
priority : Int
group : String
retry : RetryPolicy
enabled : Bool
guards : Array[EventPredicate]
} derive(Eq, Debug)pub(all) struct SubscriptionDeliveryStats {
subscription_id : String
stats : DeliveryStats
} derive(Eq, Debug)pub(all) struct TapeWindow {
cursor : EventCursor
entries : Array[TapeEntry]
next_cursor : EventCursor
complete : Bool
} derive(Eq, Debug)pub(all) struct TopicPattern {
raw : String
tokens : Array[TopicToken]
specificity : Int
} derive(Eq, Debug)fn TopicPattern::matches_topic(self : TopicPattern, topic : StringView) -> Result[Bool, EventRailError]fn TopicPattern::report(self : TopicPattern, topic : StringView) -> Result[MatchReport, EventRailError]fn diagnose_batch_schema(name : StringView, batch : EventBatch, schema : EventSchema) -> DiagnosticReportfn envelope(id? : StringView, topic : StringView, payload : EventValue, headers? : ArrayView[Pair], timestamp_ms? : Int, attempt? : Int, trace? : ArrayView[String]) -> Envelopefn event_pipeline(name : StringView, batch : EventBatch, actions? : ArrayView[PipelineAction]) -> EventPipelinefn event_query(name? : StringView, topic? : StringView, headers? : ArrayView[HeaderFilter], predicates? : ArrayView[EventPredicate], min_timestamp_ms? : Int, max_timestamp_ms? : Int, offset? : Int, limit? : Int, sort? : QuerySort) -> Result[EventQuery, EventRailError]fn event_schema(name : StringView, topic? : StringView, fields? : ArrayView[FieldSpec]) -> Result[EventSchema, EventRailError]fn event_snapshot(name : StringView, source : StringView, events : ArrayView[Envelope], bus : Bus, timestamp_ms? : Int) -> EventSnapshotfn package_name() -> Stringfn projection_spec(name : StringView, key_path : StringView, topic? : StringView, include_paths? : ArrayView[String], require_key? : Bool) -> Result[ProjectionSpec, EventRailError]fn retention_policy(name? : StringView, topic? : StringView, min_timestamp_ms? : Int, max_timestamp_ms? : Int, max_events? : Int, max_events_per_topic? : Int, compact_fingerprints? : Bool) -> Result[RetentionPolicy, EventRailError]fn scheduled_event(due_ms : Int, subscription_id : StringView, reason : StringView, event : Envelope) -> ScheduledEventfn subscription(id : StringView, pattern : StringView, priority? : Int, group? : StringView, order? : Int, retry? : RetryPolicy, enabled? : Bool, guards? : ArrayView[EventPredicate]) -> Result[Subscription, EventRailError]fn subscription_blueprint(id : StringView, pattern : StringView, priority? : Int, group? : StringView, retry? : RetryPolicy, enabled? : Bool, guards? : ArrayView[EventPredicate]) -> SubscriptionBlueprintDeterministic event bus and message trace library for MoonBit