@barry-rocks/sdk/events
Event types and schemas for Barry’s event feed, plus announce, which
records an event (with a severity and a type) that sessions and people can
read. Use it to report progress or results from a bag.
import { … } from "@barry-rocks/sdk/events";Interfaces
Section titled “Interfaces”AnnounceOptions
Section titled “AnnounceOptions”Properties
Section titled “Properties”Type Aliases
Section titled “Type Aliases”AnnounceResult
Section titled “AnnounceResult”AnnounceResult = {
ok:true;queued:number; } | {ok:false;reason:string; }
Telling subscribers something changed, from whichever process you happen to be.
The realtime bus is an in-memory map of topic -> websocket, so it lives in
exactly one process: whichever one holds the sockets. Almost nothing that
CAUSES a change runs there. barry events emit is a one-shot CLI process,
record_event runs in the engine, launchd jobs shell out to the CLI, and
identity writes run in bags/identities, a different service from the one
holding the websockets.
So there are two halves, and which one applies is decided by who is running: the bus owner publishes to its own sockets, everyone else posts across the process boundary and lets the owner publish. Wiring only the first half is the trap this module exists to avoid — it looks correct, passes an in-process test, and is silent for every change that actually happens in production.
Generalized from bags/events/src/announce.ts, which solved this first for events. Kept as one implementation rather than a copy per topic, because two copies of the in-process/cross-process choice is how one of them silently stops matching the other.
Best-effort throughout: the write that triggered this already succeeded and
clients refetch on their next poll or reconnect, so a delivery failure must
never fail it. Failures are RETURNED, not thrown and not swallowed — a silent
void would make a missing secret or a stopped service look exactly like a
quiet feed.
BarryEvent
Section titled “BarryEvent”BarryEvent =
z.infer<typeofEventSchema>
EventSeverity
Section titled “EventSeverity”EventSeverity =
z.infer<typeofEventSeveritySchema>
EventType
Section titled “EventType”EventType =
z.infer<typeofEventTypeSchema>
InProcessPublisher
Section titled “InProcessPublisher”InProcessPublisher = (
topic,id,kind) =>number
What a bus owner registers so its own writes skip the HTTP round trip.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
topic |
string |
id |
string |
kind |
string |
Returns
Section titled “Returns”number
Variables
Section titled “Variables”CreateEventRequestSchema
Section titled “CreateEventRequestSchema”
constCreateEventRequestSchema:ZodObject<{body:ZodOptional<ZodString>;data:ZodOptional<ZodRecord<ZodString,ZodUnknown>>;metadata:ZodOptional<ZodRecord<ZodString,ZodUnknown>>;sessionId:ZodOptional<ZodString>;severity:ZodOptional<ZodEnum<{error:"error";info:"info";success:"success";warn:"warn"; }>>;source:ZodOptional<ZodString>;title:ZodString;type:ZodEnum<{notification:"notification";progress:"progress";system_alert:"system_alert";task_finished:"task_finished"; }>; },$strict>
EventListResponseSchema
Section titled “EventListResponseSchema”
constEventListResponseSchema:ZodObject<{events:ZodArray<ZodObject<{body:ZodNullable<ZodString>;createdAt:ZodISODateTime;data:ZodRecord<ZodString,ZodUnknown>;deliveredVia:ZodArray<ZodString>;id:ZodString;metadata:ZodRecord<ZodString,ZodUnknown>;readAt:ZodNullable<ZodISODateTime>;sessionId:ZodNullable<ZodString>;severity:ZodEnum<{error:"error";info:"info";success:"success";warn:"warn"; }>;source:ZodString;title:ZodString;type:ZodEnum<{notification:"notification";progress:"progress";system_alert:"system_alert";task_finished:"task_finished"; }>; },$strict>>;nextCursor:ZodNullable<ZodString>; },$strict>
EventResponseSchema
Section titled “EventResponseSchema”
constEventResponseSchema:ZodObject<{event:ZodObject<{body:ZodNullable<ZodString>;createdAt:ZodISODateTime;data:ZodRecord<ZodString,ZodUnknown>;deliveredVia:ZodArray<ZodString>;id:ZodString;metadata:ZodRecord<ZodString,ZodUnknown>;readAt:ZodNullable<ZodISODateTime>;sessionId:ZodNullable<ZodString>;severity:ZodEnum<{error:"error";info:"info";success:"success";warn:"warn"; }>;source:ZodString;title:ZodString;type:ZodEnum<{notification:"notification";progress:"progress";system_alert:"system_alert";task_finished:"task_finished"; }>; },$strict>; },$strict>
EventSchema
Section titled “EventSchema”
constEventSchema:ZodObject<{body:ZodNullable<ZodString>;createdAt:ZodISODateTime;data:ZodRecord<ZodString,ZodUnknown>;deliveredVia:ZodArray<ZodString>;id:ZodString;metadata:ZodRecord<ZodString,ZodUnknown>;readAt:ZodNullable<ZodISODateTime>;sessionId:ZodNullable<ZodString>;severity:ZodEnum<{error:"error";info:"info";success:"success";warn:"warn"; }>;source:ZodString;title:ZodString;type:ZodEnum<{notification:"notification";progress:"progress";system_alert:"system_alert";task_finished:"task_finished"; }>; },$strict>
EventSeveritySchema
Section titled “EventSeveritySchema”
constEventSeveritySchema:ZodEnum<{error:"error";info:"info";success:"success";warn:"warn"; }>
EventTypeSchema
Section titled “EventTypeSchema”
constEventTypeSchema:ZodEnum<{notification:"notification";progress:"progress";system_alert:"system_alert";task_finished:"task_finished"; }>
EventUnreadCountResponseSchema
Section titled “EventUnreadCountResponseSchema”
constEventUnreadCountResponseSchema:ZodObject<{count:ZodInt; },$strict>
Functions
Section titled “Functions”announce()
Section titled “announce()”announce(
options):Promise<AnnounceResult>
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options |
AnnounceOptions |
Returns
Section titled “Returns”Promise<AnnounceResult>
setInProcessPublisher()
Section titled “setInProcessPublisher()”setInProcessPublisher(
publish):void
Set by whichever service owns the sockets, at startup.
A function rather than a constant so the owner can register before its first write without import order deciding the answer, and so a test can exercise both halves.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
publish |
InProcessPublisher | null |
Returns
Section titled “Returns”void