Event.ts
Event.ts overview
Section titled “Event.ts overview”Typed event definitions for the unstable event-log system.
An Event is the durable contract shared by writers, handlers, journals, and
replicas. It gives an event a stable tag, derives the aggregate or entity
primary key from the decoded payload, and records the schemas used for the
payload, handler result, and handler errors. The payload schema is also used
to derive the MessagePack encoding for journal entries and remote
replication.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”- constructors
- guards
- models
- AddError (type alias)
- Any (interface)
- AnyWithProps (interface)
- Error (type alias)
- ErrorSchema (type alias)
- ErrorWithTag (type alias)
- Event (interface)
- EventHandler (interface)
- ExcludeTag (type alias)
- Payload (type alias)
- PayloadSchema (type alias)
- PayloadSchemaWithTag (type alias)
- PayloadWithTag (type alias)
- Services (type alias)
- ServicesClient (type alias)
- ServicesClientWithTag (type alias)
- ServicesServer (type alias)
- Success (type alias)
- SuccessSchema (type alias)
- SuccessWithTag (type alias)
- Tag (type alias)
- TaggedPayload (type alias)
- ToService (type alias)
- WithTag (type alias)
- type IDs
constructors
Section titled “constructors”addError
Section titled “addError”Adds another error schema to an event definition.
Details
The returned event keeps the same tag, primary key, payload, and success schema while replacing the error schema with a union of the existing and new errors.
Signature
declare const addError: <A extends Any, Error2 extends Schema.Top>(event: A, error: Error2) => AddError<A, Error2>Since v4.0.0
Creates an event log event definition.
Details
If omitted, the payload and success schemas default to Schema.Void, the error
schema defaults to Schema.Never, and the MessagePack payload schema is derived
from the payload schema.
Signature
declare const make: < Tag extends string, Payload extends Schema.Top = Schema.Void, Success extends Schema.Top = Schema.Void, Error extends Schema.Top = Schema.Never>(options: { readonly tag: Tag readonly primaryKey: (payload: Schema.Schema.Type<Payload>) => string readonly payload?: Payload | undefined readonly success?: Success | undefined readonly error?: Error | undefined}) => Event<Tag, Payload, Success, Error>Since v4.0.0
guards
Section titled “guards”isEvent
Section titled “isEvent”Returns true when a value is an event log event definition.
Signature
declare const isEvent: (u: unknown) => u is Event<any, any, any, any>Since v4.0.0
models
Section titled “models”AddError (type alias)
Section titled “AddError (type alias)”Returns an event definition type whose error schema also includes the provided error schema.
Signature
type AddError<A, Error> = A extends Event<infer _Tag, infer _Payload, infer _Success, infer _Error> ? Event<_Tag, _Payload, _Success, _Error | Error> : neverSince v4.0.0
Any (interface)
Section titled “Any (interface)”Type-erased event log event definition.
Details
It preserves the runtime tag, primary-key function, payload schema, success schema, and error schema without retaining the original type parameters.
Signature
export interface Any { readonly [TypeId]: TypeId readonly tag: string readonly primaryKey: (payload: any) => string readonly payload: Schema.Top readonly payloadMsgPack: Msgpack.schema<Schema.Top> readonly success: Schema.Top readonly error: Schema.Top}Since v4.0.0
AnyWithProps (interface)
Section titled “AnyWithProps (interface)”Type-erased event definition with its runtime properties available structurally.
Signature
export interface AnyWithProps extends Any {}Since v4.0.0
Error (type alias)
Section titled “Error (type alias)”Decoded error value type for an event definition.
Signature
type Error<A> = Schema.Schema.Type<ErrorSchema<A>>Since v4.0.0
ErrorSchema (type alias)
Section titled “ErrorSchema (type alias)”Extracts the error schema from an event definition.
Signature
type ErrorSchema<A> = A extends Event<infer _Tag, infer _Payload, infer _Success, infer _Error> ? _Error : neverSince v4.0.0
ErrorWithTag (type alias)
Section titled “ErrorWithTag (type alias)”Decoded error value type for the event in a union with the specified tag.
Signature
type ErrorWithTag<Events, Tag> = Error<WithTag<Events, Tag>>Since v4.0.0
Event (interface)
Section titled “Event (interface)”Definition of an event type that can be written to an EventLog.
Details
An event definition contains its tag, primary-key function, payload schema, MessagePack payload schema, success schema, and error schema.
Signature
export interface Event< out Tag extends string, in out Payload extends Schema.Top = typeof Schema.Void, in out Success extends Schema.Top = typeof Schema.Void, in out Error extends Schema.Top = typeof Schema.Never> { readonly [TypeId]: TypeId readonly tag: Tag readonly primaryKey: (payload: Schema.Schema.Type<Payload>) => string readonly payload: Payload readonly payloadMsgPack: Msgpack.schema<Payload> readonly success: Success readonly error: Error}Since v4.0.0
EventHandler (interface)
Section titled “EventHandler (interface)”Marker service associated with the handler for an event tag.
Details
ToService derives this service from an Event so handler layers can expose
which events they implement.
Signature
export interface EventHandler<in out Tag extends string> { readonly _: unique symbol readonly tag: Tag}Since v4.0.0
ExcludeTag (type alias)
Section titled “ExcludeTag (type alias)”Removes event definitions with the specified tag from an event union.
Signature
type ExcludeTag<Events, Tag> = Exclude<Events, { readonly tag: Tag }>Since v4.0.0
Payload (type alias)
Section titled “Payload (type alias)”Decoded payload value type for an event definition.
Signature
type Payload<A> = Schema.Schema.Type<PayloadSchema<A>>Since v4.0.0
PayloadSchema (type alias)
Section titled “PayloadSchema (type alias)”Extracts the payload schema from an event definition.
Signature
type PayloadSchema<A> = A extends Event<infer _Tag, infer _Payload, infer _Success, infer _Error> ? _Payload : neverSince v4.0.0
PayloadSchemaWithTag (type alias)
Section titled “PayloadSchemaWithTag (type alias)”Extracts the payload schema for the event in a union with the specified tag.
Signature
type PayloadSchemaWithTag<A, Tag> = A extends Event<Tag, infer _Payload, infer _Success, infer _Error> ? _Payload : neverSince v4.0.0
PayloadWithTag (type alias)
Section titled “PayloadWithTag (type alias)”Decoded payload value type for the event in a union with the specified tag.
Signature
type PayloadWithTag<Events, Tag> = Payload<WithTag<Events, Tag>>Since v4.0.0
Services (type alias)
Section titled “Services (type alias)”All schema services required to encode and decode the payload, success, and error schemas for an event definition.
Signature
type Services<A> = A extends Event<infer _Tag, infer _Payload, infer _Success, infer _Error> ? | _Payload["DecodingServices"] | _Success["EncodingServices"] | _Error["EncodingServices"] | _Payload["EncodingServices"] | _Success["DecodingServices"] | _Error["DecodingServices"] : neverSince v4.0.0
ServicesClient (type alias)
Section titled “ServicesClient (type alias)”Schema services required by a client for an event definition.
Details
This includes payload encoding services plus success and error decoding services.
Signature
type ServicesClient<A> = A extends Event<infer _Tag, infer _Payload, infer _Success, infer _Error> ? _Payload["EncodingServices"] | _Success["DecodingServices"] | _Error["DecodingServices"] : neverSince v4.0.0
ServicesClientWithTag (type alias)
Section titled “ServicesClientWithTag (type alias)”Client-side schema services required for the event in a union with the specified tag.
Signature
type ServicesClientWithTag<Events, Tag> = ServicesClient<WithTag<Events, Tag>>Since v4.0.0
ServicesServer (type alias)
Section titled “ServicesServer (type alias)”Schema services required by a server for an event definition.
Details
This includes payload decoding services plus success and error encoding services.
Signature
type ServicesServer<A> = A extends Event<infer _Tag, infer _Payload, infer _Success, infer _Error> ? _Payload["DecodingServices"] | _Success["EncodingServices"] | _Error["EncodingServices"] : neverSince v4.0.0
Success (type alias)
Section titled “Success (type alias)”Decoded success value type for an event definition.
Signature
type Success<A> = Schema.Schema.Type<SuccessSchema<A>>Since v4.0.0
SuccessSchema (type alias)
Section titled “SuccessSchema (type alias)”Extracts the success schema from an event definition.
Signature
type SuccessSchema<A> = A extends Event<infer _Tag, infer _Payload, infer _Success, infer _Error> ? _Success : neverSince v4.0.0
SuccessWithTag (type alias)
Section titled “SuccessWithTag (type alias)”Decoded success value type for the event in a union with the specified tag.
Signature
type SuccessWithTag<Events, Tag> = Success<WithTag<Events, Tag>>Since v4.0.0
Tag (type alias)
Section titled “Tag (type alias)”Extracts the tag string from an event definition.
Signature
type Tag<A> = A extends Event<infer _Tag, infer _Payload, infer _Success, infer _Error> ? _Tag : neverSince v4.0.0
TaggedPayload (type alias)
Section titled “TaggedPayload (type alias)”Tagged payload value for an event definition.
Details
The result contains _tag set to the event tag and payload set to the
decoded payload value.
Signature
type TaggedPayload<A> = A extends Event<infer _Tag, infer _Payload, infer _Success, infer _Error> ? { readonly _tag: _Tag readonly payload: Schema.Schema.Type<_Payload> } : neverSince v4.0.0
ToService (type alias)
Section titled “ToService (type alias)”Derives the handler service marker for an event definition.
Signature
type ToService<A> = A extends Event<infer _Tag, infer _Payload, infer _Success, infer _Error> ? EventHandler<_Tag> : neverSince v4.0.0
WithTag (type alias)
Section titled “WithTag (type alias)”Extracts the event definition with the specified tag from an event union.
Signature
type WithTag<Events, Tag> = Extract<Events, { readonly tag: Tag }>Since v4.0.0
type IDs
Section titled “type IDs”TypeId
Section titled “TypeId”Runtime type identifier used to mark event log event definitions.
Signature
declare const TypeId: "~effect/eventlog/Event"Since v4.0.0
TypeId (type alias)
Section titled “TypeId (type alias)”Unique type identifier used to mark event log event definitions.
Signature
type TypeId = "~effect/eventlog/Event"Since v4.0.0