Event
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.
Constructors
Signature
declare function addError<A extends Any, Error2 extends Top>(
event: A,
error: Error2,
): AddError<A, Error2>;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 function make<
Tag extends string,
Payload extends Top = Void,
Success extends Top = Void,
Error extends Top = Never,
>(options: {
readonly error?: Error;
readonly payload?: Payload;
readonly primaryKey: (payload: Type<Payload>) => string;
readonly success?: Success;
readonly tag: Tag;
}): Event<Tag, Payload, Success, Error>;Guards
Models
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
interface Any {
readonly "~effect/eventlog/Event": "~effect/eventlog/Event";
readonly error: Top;
readonly payload: Top;
readonly payloadMsgPack: schema<Top>;
readonly primaryKey: (payload: any) => string;
readonly success: Top;
readonly tag: string;
}AnyWithProps interface
Type-erased event definition with its runtime properties available structurally.
Signature
interface AnyWithProps extends Any {}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
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 "~effect/eventlog/Event": "~effect/eventlog/Event";
readonly error: Error;
readonly payload: Payload;
readonly payloadMsgPack: schema<Payload>;
readonly primaryKey: (payload: Type<Payload>) => string;
readonly success: Success;
readonly tag: Tag;
}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
interface EventHandler<in out Tag extends string> {
readonly _: typeof _;
readonly tag: Tag;
}Type IDs
Runtime type identifier used to mark event log event definitions.
Signature
declare const TypeId: "~effect/eventlog/Event";Unique type identifier used to mark event log event definitions.
Signature
type TypeId = "~effect/eventlog/Event";Utility Types
Returns an event definition type whose error schema also includes the provided error schema.
Signature
type AddError<A extends Any, Error extends Schema.Top> =
A extends Event<infer _Tag, infer _Payload, infer _Success, infer _Error>
? Event<_Tag, _Payload, _Success, _Error | Error>
: never;Decoded error value type for an event definition.
Signature
type Error<A extends Any> = Schema.Schema.Type<ErrorSchema<A>>;ErrorSchema type
Extracts the error schema from an event definition.
Signature
type ErrorSchema<A extends Any> =
A extends Event<infer _Tag, infer _Payload, infer _Success, infer _Error> ? _Error : never;ErrorWithTag type
Decoded error value type for the event in a union with the specified tag.
Signature
type ErrorWithTag<Events extends Any, Tag extends string> = Error<WithTag<Events, Tag>>;ExcludeTag type
Removes event definitions with the specified tag from an event union.
Signature
type ExcludeTag<Events extends Any, Tag extends string> = Exclude<
Events,
{
readonly tag: Tag;
}
>;Decoded payload value type for an event definition.
Signature
type Payload<A extends Any> = Schema.Schema.Type<PayloadSchema<A>>;PayloadSchema type
Extracts the payload schema from an event definition.
Signature
type PayloadSchema<A extends Any> =
A extends Event<infer _Tag, infer _Payload, infer _Success, infer _Error> ? _Payload : never;PayloadSchemaWithTag type
Extracts the payload schema for the event in a union with the specified tag.
Signature
type PayloadSchemaWithTag<A extends Any, Tag extends string> =
A extends Event<Tag, infer _Payload, infer _Success, infer _Error> ? _Payload : never;PayloadWithTag type
Decoded payload value type for the event in a union with the specified tag.
Signature
type PayloadWithTag<Events extends Any, Tag extends string> = Payload<WithTag<Events, Tag>>;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"]
: never;ServicesClient type
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"]
: never;ServicesClientWithTag type
Client-side schema services required for the event in a union with the specified tag.
Signature
type ServicesClientWithTag<Events extends Any, Tag extends string> = ServicesClient<
WithTag<Events, Tag>
>;ServicesServer type
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"]
: never;Decoded success value type for an event definition.
Signature
type Success<A extends Any> = Schema.Schema.Type<SuccessSchema<A>>;SuccessSchema type
Extracts the success schema from an event definition.
Signature
type SuccessSchema<A extends Any> =
A extends Event<infer _Tag, infer _Payload, infer _Success, infer _Error> ? _Success : never;SuccessWithTag type
Decoded success value type for the event in a union with the specified tag.
Signature
type SuccessWithTag<Events extends Any, Tag extends string> = Success<WithTag<Events, Tag>>;Extracts the tag string from an event definition.
Signature
type Tag<A> =
A extends Event<infer _Tag, infer _Payload, infer _Success, infer _Error> ? _Tag : never;TaggedPayload type
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 extends Any> =
A extends Event<infer _Tag, infer _Payload, infer _Success, infer _Error>
? {
readonly _tag: _Tag;
readonly payload: Schema.Schema.Type<_Payload>;
}
: never;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>
: never;Extracts the event definition with the specified tag from an event union.
Signature
type WithTag<Events extends Any, Tag extends string> = Extract<
Events,
{
readonly tag: Tag;
}
>;
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.