Skip to content

EventLog

19 exports Added in v1.0.0 Source

Client

makeClient

Added in v1.0.0 Source

Signature

declare function makeClient<Groups extends Any>(
  schema: EventLogSchema<Groups>,
): Effect<
  <Tag extends string>(
    event: Tag,
    payload: Type<
      PayloadSchema<
        Extract<
          Events<Groups>,
          {
            readonly tag: Tag;
          }
        >
      >
    >,
  ) => Effect<
    Type<
      SuccessSchema<
        Extract<
          Events<Groups>,
          {
            readonly tag: Tag;
          }
        >
      >
    >,
    | EventJournalError
    | Type<
        ErrorSchema<
          Extract<
            Events<Groups>,
            {
              readonly tag: Tag;
            }
          >
        >
      >
  >,
  never,
  EventLog
>;

Compaction

Signature

declare function groupCompaction<Events extends Any, R>(
  group: EventGroup<Events>,
  effect: (options: {
    readonly entries: Array<Entry>;
    readonly events: Array<TaggedPayload<Events>>;
    readonly primaryKey: string;
    readonly write: <Tag extends string>(
      tag: Tag,
      payload: Type<
        PayloadSchema<
          Extract<
            Events,
            {
              readonly tag: Tag;
            }
          >
        >
      >,
    ) => Effect<void>;
  }) => Effect<void, never, R>,
): Layer<never, never, EventJournal | R | Identity | Context<Events>>;

Handlers

group

Added in v1.0.0 Source

Signature

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

Handlers

Added in v1.0.0 Source

Handlers interface

Added in v1.0.0 Source

Represents a handled EventGroup.

Signature

interface Handlers<R, Events extends Event.Any = never> extends Pipeable {
  readonly [HandlersTypeId]: {
    _Endpoints: Covariant<Events>;
  };
  readonly context: Context<any>;
  readonly group: AnyWithProps;
  readonly handlers: Record.ReadonlyRecord<string, Handlers.Item<R>>;
  handle<Tag extends string, R1>(
    name: Tag,
    handler: (options: {
      readonly conflicts: Array<{
        readonly entry: Entry;
        readonly payload: Type<
          PayloadSchema<
            Extract<
              Events,
              {
                readonly tag: Tag;
              }
            >
          >
        >;
      }>;
      readonly entry: Entry;
      readonly payload: Type<
        PayloadSchema<
          Extract<
            Events,
            {
              readonly tag: Tag;
            }
          >
        >
      >;
    }) => Effect<
      Type<
        SuccessSchema<
          Extract<
            Events,
            {
              readonly tag: Tag;
            }
          >
        >
      >,
      Type<
        ErrorSchema<
          Extract<
            Events,
            {
              readonly tag: Tag;
            }
          >
        >
      >,
      R1
    >,
  ): Handlers<
    R | R1,
    Exclude<
      Events,
      {
        readonly tag: Tag;
      }
    >
  >;
}

Signature

declare const HandlersTypeId: unique symbol;

HandlersTypeId type

Added in v1.0.0 Source

Signature

type HandlersTypeId = typeof HandlersTypeId;

Layers

layer

Added in v1.0.0 Source

Signature

declare function layer<Groups extends Any>(
  _schema: EventLogSchema<Groups>,
): Layer<EventLog, never, EventJournal | Identity | ToService<Groups>>;

Signature

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

Generates a random Identity and stores it in a KeyValueStore.

Signature

declare function layerIdentityKvs(options: {
  readonly key: string;
}): Layer<Identity, any, KeyValueStore>;

Registry

Added in v1.0.0 Source

Signature

declare class Registry extends any {
  constructor();
  static layer: Layer<unknown, never, never>;
}

Reactivity

Signature

declare function groupReactivity<Events extends Any>(group: EventGroup<Events>, keys: readonly Array<string> | { [Tag in string]: readonly Array<string> }): Layer<never, never, EventJournal | Identity>

Schema

EventLogSchema interface

Added in v1.0.0 Source

Signature

interface EventLogSchema<Groups extends EventGroup.Any> {
  constructor(_: never);
  readonly [SchemaTypeId]: typeof SchemaTypeId;
  readonly groups: readonly Array<Groups>;
}

Signature

declare function isEventLogSchema(u: unknown): u is EventLogSchema<any>;

schema

Added in v1.0.0 Source

Signature

declare function schema<Groups extends readonly Array<Any>>(...groups: Groups): EventLogSchema<Groups[number]>

SchemaTypeId

Added in v1.0.0 Source

Signature

declare const SchemaTypeId: unique symbol;

SchemaTypeId type

Added in v1.0.0 Source

Signature

type SchemaTypeId = typeof SchemaTypeId;

Tags

EventLog

Added in v1.0.0 Source

Signature

declare class EventLog extends any {
  constructor();
}

Identity

Added in v1.0.0 Source

Signature

declare class Identity extends any {
  constructor();
  static readonly Schema: Struct<{
    readonly privateKey: Redacted<Uint8ArrayFromBase64>;
    readonly publicKey: String;
  }>;
  static readonly SchemaFromString: never;
  static decodeString(s: string): any;
  static encodeString(identity: any): string;
  static makeRandom(): any;
}