Skip to content
Effect 4.0 is here. One ecosystem. Zero dependencies.

Event unstable

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 SchemaBinary encoding for journal entries and remote replication.

29 exports Since v4.0.0 Source

Guards

isEvent

unstable
Since v4.0.0

Returns true when a value is an event log event definition.

Signature

declare function isEvent(u: unknown): u is Event<any, any, any, any>

Models

Any

interface unstable
Since v4.0.0

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 payloadSchemaBinary: toCodec<Top>;
readonly primaryKey: (payload: any) => string;
readonly success: Top;
readonly tag: string;
}

AnyWithProps

interface unstable
Since v4.0.0

Type-erased event definition with its runtime properties available structurally.

Signature

interface AnyWithProps extends Any {}

Event

interface unstable
Since v4.0.0

Definition of an event type that can be written to an EventLog.

Details

An event definition contains its tag, primary-key function, payload schema, SchemaBinary payload codec, 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 payloadSchemaBinary: toCodec<Payload>;
readonly primaryKey: (payload: Type<Payload>) => string;
readonly success: Success;
readonly tag: Tag;
}

EventHandler

interface unstable
Since v4.0.0

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;
}

Other

Signature

declare function addError<A extends Any, Error2 extends Top>(event: A, error: Error2): AddError<A, Error2>

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>

Type IDs

TypeId

unstable
Since v4.0.0

Runtime type identifier used to mark event log event definitions.

Signature

declare const TypeId: "~effect/eventlog/Event"

TypeId

type unstable
Since v4.0.0

Unique type identifier used to mark event log event definitions.

Signature

type TypeId = "~effect/eventlog/Event"

Utility Types

AddError

type unstable
Since v4.0.0

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

Error

type unstable
Since v4.0.0

Decoded error value type for an event definition.

Signature

type Error<A extends Any> = Schema.Schema.Type<ErrorSchema<A>>

ErrorSchema

type unstable
Since v4.0.0

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 unstable
Since v4.0.0

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 unstable
Since v4.0.0

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;
}>

Payload

type unstable
Since v4.0.0

Decoded payload value type for an event definition.

Signature

type Payload<A extends Any> = Schema.Schema.Type<PayloadSchema<A>>

PayloadSchema

type unstable
Since v4.0.0

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
Since v4.0.0

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 unstable
Since v4.0.0

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>>

Services

type unstable
Since v4.0.0

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 unstable
Since v4.0.0

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
Since v4.0.0

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 unstable
Since v4.0.0

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

Success

type unstable
Since v4.0.0

Decoded success value type for an event definition.

Signature

type Success<A extends Any> = Schema.Schema.Type<SuccessSchema<A>>

SuccessSchema

type unstable
Since v4.0.0

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 unstable
Since v4.0.0

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>>

Tag

type unstable
Since v4.0.0

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 unstable
Since v4.0.0

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

ToService

type unstable
Since v4.0.0

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

WithTag

type unstable
Since v4.0.0

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;
}>