Skip to content

EventLogMessage

Defines protocol messages for event-log remote clients and servers.

This module is the shared boundary between EventLogRemote clients and event-log servers. It defines store ids, protocol errors, the hello/authenticate session handshake, remote calls for writes and changes, and message formats for encrypted or plaintext journal entries.

18 exports Added in v4.0.0 Source

Middleware

RPC middleware that authenticates event-log requests and provides the client Identity to authenticated handlers.

Signature

declare class EventLogAuthentication extends Shape<"effect/eventlog/EventLogMessage/EventLogAuthentication", RpcMiddleware<Identity, EventLogProtocolError, never>, this> & {
  readonly "~effect/rpc/RpcMiddleware": {
    readonly clientError: never;
    readonly error: typeof EventLogProtocolError;
    readonly provides: Identity;
    readonly requires: never;
  };
} {
  constructor(_: never);
}

Models

StoreId type

Added in v4.0.0 Source

Branded string identifying a logical event-log store.

Signature

type StoreId = string & Brand<StoreIdTypeId>;

Protocols

Authenticate

Added in v4.0.0 Source

Schema for an authentication request containing the client public key, Ed25519 signing public key, signature over the session challenge payload, and algorithm name.

Signature

declare class Authenticate extends {
  readonly algorithm: "Ed25519";
  readonly publicKey: string;
  readonly signature: Uint8Array<ArrayBuffer>;
  readonly signingPublicKey: Uint8Array<ArrayBuffer>;
} {
  constructor(...args: [props: {
    readonly algorithm: "Ed25519";
    readonly publicKey: string;
    readonly signature: Uint8Array<ArrayBuffer>;
    readonly signingPublicKey: Uint8Array<ArrayBuffer>;
  }, options?: MakeOptions]);
}

RPC used to authenticate a remote event-log session after HelloRpc.

Signature

declare class AuthenticateRpc extends ({}) {
  constructor(_: never);
}

ChangesRpc

Added in v4.0.0 Source

RPC used to stream remote event-log changes for a public key and store id starting at a sequence number.

Details

Responses are encoded as either SingleMessage values or ChunkedMessage parts.

Signature

declare class ChangesRpc extends ({}) {
  constructor(_: never);
  static decodeEncrypted: (
    input: Uint8Array<ArrayBuffer>,
    options?: ParseOptions,
  ) => Effect<
    readonly [
      {
        readonly encryptedEntry: Uint8Array<ArrayBuffer>;
        readonly entryId: Uint8Array<ArrayBuffer> & Brand<"effect/eventlog/EventJournal/EntryId">;
        readonly iv: Uint8Array<ArrayBuffer>;
        readonly sequence: number;
      },
      {
        readonly encryptedEntry: Uint8Array<ArrayBuffer>;
        readonly entryId: Uint8Array<ArrayBuffer> & Brand<"effect/eventlog/EventJournal/EntryId">;
        readonly iv: Uint8Array<ArrayBuffer>;
        readonly sequence: number;
      },
    ],
    SchemaError,
    never
  >;
  static decodeUnencrypted: (
    input: Uint8Array<ArrayBuffer>,
    options?: ParseOptions,
  ) => Effect<readonly [RemoteEntry, RemoteEntry], SchemaError, never>;
  static encodeEncrypted: (
    input: readonly [
      {
        readonly encryptedEntry: Uint8Array<ArrayBuffer>;
        readonly entryId: Uint8Array<ArrayBuffer> & Brand<"effect/eventlog/EventJournal/EntryId">;
        readonly iv: Uint8Array<ArrayBuffer>;
        readonly sequence: number;
      },
      {
        readonly encryptedEntry: Uint8Array<ArrayBuffer>;
        readonly entryId: Uint8Array<ArrayBuffer> & Brand<"effect/eventlog/EventJournal/EntryId">;
        readonly iv: Uint8Array<ArrayBuffer>;
        readonly sequence: number;
      },
    ],
    options?: ParseOptions,
  ) => Effect<Uint8Array<ArrayBuffer>, SchemaError, never>;
  static encodeUnencrypted: (
    input: readonly [RemoteEntry, RemoteEntry],
    options?: ParseOptions,
  ) => Effect<Uint8Array<ArrayBuffer>, SchemaError, never>;
  static EncryptedFromMsgpack: schema<
    NonEmptyArray<
      Struct<{
        readonly encryptedEntry: Transferable<
          instanceOf<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>
        >;
        readonly entryId: brand<
          instanceOf<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>,
          "effect/eventlog/EventJournal/EntryId"
        >;
        readonly iv: Transferable<instanceOf<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
        readonly sequence: Natural;
      }>
    >
  >;
  static UnencryptedFromMsgpack: schema<NonEmptyArray<typeof RemoteEntry>>;
}

Represents one part of a large encoded event-log payload.

When to use

Use to divide data into chunks and join to reassemble all chunks with the same id once every part has arrived.

Signature

declare class ChunkedMessage extends {
  readonly _tag: "Chunked";
  readonly data: Uint8Array<ArrayBuffer>;
  readonly id: number;
  readonly part: readonly [number, number];
} {
  constructor(...args: [props: {
    readonly _tag?: "Chunked";
    readonly data: Uint8Array<ArrayBuffer>;
    readonly id: number;
    readonly part: readonly [number, number];
  }, options?: MakeOptions]);
  static chunkSize: number;
  static initialJoinState(): Map<number, {
    bytes: number;
    count: number;
    readonly parts: Array<Uint8Array<ArrayBufferLike>>;
  }>;
  static join(map: Map<number, {
    bytes: number;
    count: number;
    readonly parts: Array<Uint8Array<ArrayBufferLike>>;
  }>, part: ChunkedMessage): Uint8Array<ArrayBuffer> | undefined;
  static split(id: number, data: Uint8Array): readonly [ChunkedMessage, ChunkedMessage];
}

Error returned by event-log remote RPCs.

Details

It records the request tag, optional identity and store information, a protocol error code, and a human-readable message.

Signature

declare class EventLogProtocolError extends {
  readonly _tag: "EventLogProtocolError";
  readonly code: "NotFound" | "Forbidden" | "InvalidRequest" | "Unauthorized" | "InternalServerError";
  readonly message: string;
  readonly publicKey?: string;
  readonly requestTag: string;
  readonly storeId?: string & Brand<"effect/eventlog/EventLog/StoreId">;
} & YieldableError<this> {
  constructor(...args: [props: {
    readonly _tag?: "EventLogProtocolError";
    readonly code: "NotFound" | "Forbidden" | "InvalidRequest" | "Unauthorized" | "InternalServerError";
    readonly message: string;
    readonly publicKey?: string;
    readonly requestTag: string;
    readonly storeId?: string & Brand<"effect/eventlog/EventLog/StoreId">;
  }, options?: MakeOptions]);
}

RPC group containing the event-log remote handshake, authentication, write, and changes endpoints.

Signature

declare class EventLogRemoteRpcs extends ({}) {
  constructor(_: never);
}

Response sent by the remote server during the authentication handshake.

Details

It contains the server remote id and a challenge that must be signed by the client.

Signature

declare class HelloResponse extends {
  readonly challenge: Uint8Array<ArrayBuffer>;
  readonly remoteId: Uint8Array<ArrayBufferLike> & Brand<"effect/eventlog/EventJournal/RemoteId">;
} {
  constructor(...args: [props: {
    readonly challenge: Uint8Array<ArrayBuffer>;
    readonly remoteId: Uint8Array<ArrayBufferLike> & Brand<"effect/eventlog/EventJournal/RemoteId">;
  }, options?: MakeOptions]);
}

HelloRpc

Added in v4.0.0 Source

RPC used to start an event-log remote session and receive a HelloResponse.

Signature

declare class HelloRpc extends ({}) {
  constructor(_: never);
}

Represents an entire encoded event-log payload in one transport frame.

Signature

declare class SingleMessage extends {
  readonly _tag: "Single";
  readonly data: Uint8Array<ArrayBuffer>;
} {
  constructor(...args: [props: {
    readonly _tag?: "Single";
    readonly data: Uint8Array<ArrayBuffer>;
  }, options?: MakeOptions]);
}

RPC used to send one chunk of a large encoded write payload.

Signature

declare class WriteChunkedRpc extends ({}) {
  constructor(_: never);
}

WriteEntries

Added in v4.0.0 Source

Schema for encrypted event-log write payloads sent to a remote store.

Details

It includes the client public key, target store id, AES-GCM initialization vector, and encrypted entries.

Signature

declare class WriteEntries extends {
  readonly encryptedEntries: readonly Array<{
    readonly encryptedEntry: Uint8Array<ArrayBuffer>;
    readonly entryId: Uint8Array<ArrayBuffer> & Brand<"effect/eventlog/EventJournal/EntryId">;
  }>;
  readonly iv: Uint8Array<ArrayBuffer>;
  readonly publicKey: string;
  readonly storeId: string & Brand<"effect/eventlog/EventLog/StoreId">;
} {
  constructor(...args: [props: {
    readonly encryptedEntries: readonly Array<{
      readonly encryptedEntry: Uint8Array<ArrayBuffer>;
      readonly entryId: Uint8Array<ArrayBuffer> & Brand<"effect/eventlog/EventJournal/EntryId">;
    }>;
    readonly iv: Uint8Array<ArrayBuffer>;
    readonly publicKey: string;
    readonly storeId: string & Brand<"effect/eventlog/EventLog/StoreId">;
  }, options?: MakeOptions]);
  static decode: (input: Uint8Array<ArrayBuffer>, options?: ParseOptions) => Effect<WriteEntries, SchemaError, never>;
  static encode: (input: WriteEntries, options?: ParseOptions) => Effect<Uint8Array<ArrayBuffer>, SchemaError, never>;
  static FromMsgpack: schema<typeof WriteEntries>;
  encoded: Effect<Uint8Array<ArrayBuffer>, SchemaError, never>;
}

Schema for plaintext event-log write payloads sent to a remote store.

Signature

declare class WriteEntriesUnencrypted extends {
  readonly entries: readonly Array<Entry>;
  readonly publicKey: string;
  readonly storeId: string & Brand<"effect/eventlog/EventLog/StoreId">;
} {
  constructor(...args: [props: {
    readonly entries: readonly Array<Entry>;
    readonly publicKey: string;
    readonly storeId: string & Brand<"effect/eventlog/EventLog/StoreId">;
  }, options?: MakeOptions]);
  static decode: (input: Uint8Array<ArrayBuffer>, options?: ParseOptions) => Effect<WriteEntriesUnencrypted, SchemaError, never>;
  static encode: (input: WriteEntriesUnencrypted, options?: ParseOptions) => Effect<Uint8Array<ArrayBuffer>, SchemaError, never>;
  static FromMsgpack: schema<typeof WriteEntriesUnencrypted>;
  encoded: Effect<Uint8Array<ArrayBuffer>, SchemaError, never>;
}

RPC used to send an encoded write payload that fits in one message.

Signature

declare class WriteSingleRpc extends ({}) {
  constructor(_: never);
}

Schemas

StoreId

Added in v4.0.0 Source

Schema for branded event-log store ids.

Signature

declare const StoreId: brand<String, "effect/eventlog/EventLog/StoreId">;

Type IDs

Runtime brand identifier for event-log store ids.

Signature

declare const StoreIdTypeId: "effect/eventlog/EventLog/StoreId";

StoreIdTypeId type

Added in v4.0.0 Source

Type-level identifier used to brand event-log store ids.

Signature

type StoreIdTypeId = "effect/eventlog/EventLog/StoreId";