g14o
Packages@g14o/events

API Reference

Types and options for @g14o/events.

EventBusOptions

Options for new Event({ … }). Schema-first mode also accepts schema (nested Standard Schema map) for validation and InferEvents — that field lives on the conditional CreateEventConfig, not on EventBusOptions itself.

OptionTypeDescription
hooks?object

Lifecycle hooks for pipeline and error routing.

onListenerError?OnListenerErrorMode | undefined

How listener errors affect other listeners.

Default: "continue"
strategy?object

Listener execution strategy.

Default: parallelStrategy
stream?object

Cross-instance persistence and fan-out backend.

verbose?boolean | VerboseLogger | undefined

Log pipeline steps to the console when true, or pass a duck-typed { info, warn, error } adapter for custom routing. Silent by default.

Default: false

EventBusHooks

OptionTypeDescription
onError?ErrorHandler

Initial onError handler (listener errors).

onPipelineEnd?function

After middleware + listeners complete.

onPipelineFinally?function

After pipeline attempt (success or failure). Skipped on validation failure.

onPipelineStart?function

After validation, before middleware + listeners.

onValidationError?ErrorHandler

Initial onValidationError handler.

EventBus

Typed async-first event bus returned by new Event({ … }). See Server for emit/dispatch and SSE wiring, Listeners for on / once / subscribe, and Namespaces for namespace and channel scoping.

ChannelEmitter

Channel-scoped emitter from event.channel(...names) — same emit API with channels merged into metadata. See Channel for client subscribe and Server for emit.

EventHandlerOptions

Options for handler({ … }).

OptionTypeDescription
authorizeJoin?AuthorizeJoin

Gate SSE channel join/leave before the connection is accepted.

eventobject

Event bus instance to subscribe and replay from.

maxDurationSecs?number

Max SSE connection duration in seconds before the server closes it.

middleware?HandlerMiddleware

Run before subscribe; return a Response to reject the request.

OnOptions

Options for on / once.

OptionTypeDescription
priority?number

Higher runs first among listeners for the same event.

Default: 0
signal?object

Abort to unregister the listener when the signal fires.

SubscribeEventOptions

Options-object form of server event.subscribe / channel.subscribe (channel-scoped form omits channels).

OptionTypeDescription
signal?object

Abort to unsubscribe when the signal fires.

channels?array

Channel names to scope delivery; omit for bus-wide subscribe.

eventsK

Event names to listen for.

once?boolean | undefined

Unsubscribe after the first matching delivery.

onDatafunction

Called for each matching event payload.

priority?number

Higher runs first when multiple subscribers match.

MemoryStreamOptions

OptionTypeDescription
maxLength?number

Max messages retained per channel.

Default: 100

RedisStreamOptions

OptionTypeDescription
channelPrefix?string

Key/channel prefix.

Default: "@g14o:events"
clientRedisStreamClient

Redis client (node-redis or ioredis).

expireAfterSecs?number

Optional TTL applied to stream keys after append.

maxLength?number

Max stream length (MAXLEN ≈).

UpstashStreamOptions

OptionTypeDescription
channelPrefix?string

Key/channel prefix.

Default: "@g14o:events"
expireAfterSecs?number

Optional TTL applied to stream keys after append.

maxLength?number

Max stream length (MAXLEN).

redisobject

Upstash Redis REST client (or compatible).

EventStream

Pluggable stream contract for custom backends (defineStream). See Streams for built-in adapters and Deployment for multi-instance wiring.

EventProviderProps

OptionTypeDescription
api?object

SSE endpoint and fetch credentials.

childrenReactNode
maxReconnectAttempts?number

Max automatic reconnect attempts after disconnect.

ProviderApiConfig

OptionTypeDescription
url?string

SSE subscribe URL (default /api/events).

withCredentials?boolean | undefined

Send cookies on the EventSource request.

UseEventOptions

Client hook options from createEvent().useEvent. The channels option scopes delivery — see Channel.

OptionTypeDescription
channels?array

Channel names to subscribe to (undefined entries are ignored).

enabled?boolean | undefined

When false, skip registering until enabled.

events?array

Event names to receive; omit for all typed events.

onData?function

Called for each matching realtime message.

PipelineLogOptions

Options for createPipelineLog.

OptionTypeDescription
formatEnd?function

Format a pipeline-end log line.

formatStart?function

Format a pipeline-start log line.

maxEntries?number

Max middleware log entries retained in memory.

Package entry points

ImportDescription
@g14o/eventsEvent, handler, strategies, errors, createPipelineLog, defineStream
@g14o/events/clientEventProvider, createEvent, hooks
@g14o/events/memorymemoryStream
@g14o/events/redisredisStream
@g14o/events/upstashupstashStream

On this page