Skip to main content Link Search Menu Expand Document (external link)

EventLog overview

Added in v1.0.0


Table of contents


client

makeClient

Signature

export declare const makeClient: <Groups extends EventGroup.Any>(
  schema: EventLogSchema<Groups>
) => Effect.Effect<
  <Tag extends Event.Tag<EventGroup.Events<Groups>>>(
    event: Tag,
    payload: Event.PayloadWithTag<EventGroup.Events<Groups>, Tag>
  ) => Effect.Effect<
    Event.SuccessWithTag<EventGroup.Events<Groups>, Tag>,
    Event.ErrorWithTag<EventGroup.Events<Groups>, Tag> | EventJournalError
  >,
  never,
  EventLog
>

Added in v1.0.0

compaction

groupCompaction

Signature

export declare const groupCompaction: <Events extends Event.Any, R>(
  group: EventGroup<Events>,
  effect: (options: {
    readonly primaryKey: string
    readonly entries: Array<Entry>
    readonly events: Array<Event.TaggedPayload<Events>>
    readonly write: <Tag extends Event.Tag<Events>>(
      tag: Tag,
      payload: Event.PayloadWithTag<Events, Tag>
    ) => Effect.Effect<void>
  }) => Effect.Effect<void, never, R>
) => Layer.Layer<never, never, EventLog | R | Event.Context<Events>>

Added in v1.0.0

handlers

Handlers (interface)

Represents a handled EventGroup.

Signature

export interface Handlers<R, Events extends Event.Any = never> extends Pipeable {
  readonly [HandlersTypeId]: {
    _Endpoints: Covariant<Events>
  }
  readonly group: EventGroup.AnyWithProps
  readonly handlers: Record.ReadonlyRecord<string, Handlers.Item<R>>
  readonly context: Context.Context<any>

  /**
   * Add the implementation for an `Event` to a `Handlers` group.
   */
  handle<Tag extends Events["tag"], R1>(
    name: Tag,
    handler: (options: {
      readonly payload: Event.PayloadWithTag<Events, Tag>
      readonly entry: Entry
      readonly conflicts: Array<{
        readonly entry: Entry
        readonly payload: Event.PayloadWithTag<Events, Tag>
      }>
    }) => Effect.Effect<Event.SuccessWithTag<Events, Tag>, Event.ErrorWithTag<Events, Tag>, R1>
  ): Handlers<R | R1, Event.ExcludeTag<Events, Tag>>
}

Added in v1.0.0

Handlers (namespace)

Added in v1.0.0

Any (interface)

Signature

export interface Any {
  readonly [HandlersTypeId]: any
}

Added in v1.0.0

Context (type alias)

Signature

export type Context<A> =
  A extends Handlers<infer _R, infer _Events>
    ? _R | Event.Context<_Events>
    : A extends Effect.Effect<Handlers<infer _R, infer _Events>, infer _EX, infer _RX>
      ? _R | _RX | Event.Context<_Events>
      : never

Added in v1.0.0

Error (type alias)

Signature

export type Error<A> = A extends Effect.Effect<Handlers<infer _R, infer _Events>, infer _EX, infer _RX> ? _EX : never

Added in v1.0.0

Item (type alias)

Signature

export type Item<R> = {
  readonly event: Event.AnyWithProps
  readonly context: Context.Context<any>
  readonly handler: (options: {
    readonly payload: any
    readonly entry: Entry
    readonly conflicts: Array<{
      readonly entry: Entry
      readonly payload: any
    }>
  }) => Effect.Effect<any, R>
}

Added in v1.0.0

ValidateReturn (type alias)

Signature

export type ValidateReturn<A> = A extends
  | Handlers<infer _R, infer _Events>
  | Effect.Effect<Handlers<infer _R, infer _Events>, infer _EX, infer _RX>
  ? [_Events] extends [never]
    ? A
    : `Event not handled: ${Event.Tag<_Events>}`
  : `Must return the implemented handlers`

Added in v1.0.0

HandlersTypeId

Signature

export declare const HandlersTypeId: typeof HandlersTypeId

Added in v1.0.0

HandlersTypeId (type alias)

Signature

export type HandlersTypeId = typeof HandlersTypeId

Added in v1.0.0

group

Signature

export declare const group: <Events extends Event.Any, Return>(
  group: EventGroup<Events>,
  f: (handlers: Handlers<never, Events>) => Handlers.ValidateReturn<Return>
) => Layer.Layer<Event.ToService<Events>, Handlers.Error<Return>, Exclude<Handlers.Context<Return>, Scope>>

Added in v1.0.0

layers

Registry (class)

Signature

export declare class Registry

Added in v1.0.0

layer

Signature

export declare const layer: <Groups extends EventGroup.Any>(
  _schema: EventLogSchema<Groups>
) => Layer.Layer<EventLog, never, EventGroup.ToService<Groups> | EventJournal | Identity>

Added in v1.0.0

layerEventLog

Signature

export declare const layerEventLog: Layer.Layer<EventLog, never, Identity | EventJournal>

Added in v1.0.0

reactivity

groupReactivity

Signature

export declare const groupReactivity: <Events extends Event.Any>(
  group: EventGroup<Events>,
  keys: { readonly [Tag in Event.Tag<Events>]?: ReadonlyArray<string> } | ReadonlyArray<string>
) => Layer.Layer<never, never, EventLog>

Added in v1.0.0

schema

EventLogSchema (interface)

Signature

export interface EventLogSchema<Groups extends EventGroup.Any> {
  new (_: never): {}
  readonly [SchemaTypeId]: SchemaTypeId
  readonly groups: ReadonlyArray<Groups>
}

Added in v1.0.0

SchemaTypeId

Signature

export declare const SchemaTypeId: typeof SchemaTypeId

Added in v1.0.0

SchemaTypeId (type alias)

Signature

export type SchemaTypeId = typeof SchemaTypeId

Added in v1.0.0

isEventLogSchema

Signature

export declare const isEventLogSchema: (u: unknown) => u is EventLogSchema<any>

Added in v1.0.0

schema

Signature

export declare const schema: <Groups extends ReadonlyArray<EventGroup.Any>>(
  ...groups: Groups
) => EventLogSchema<Groups[number]>

Added in v1.0.0

tags

EventLog (class)

Signature

export declare class EventLog

Added in v1.0.0

Identity (class)

Signature

export declare class Identity

Added in v1.0.0