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

EventLogMessage unstable

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

Branded string identifying a logical event-log store.

Signature

type StoreId = string & Brand<StoreIdTypeId>

Protocols

Since v4.0.0

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]);
}
Since v4.0.0

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

Signature

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

ChangesRpc

unstable
Since v4.0.0

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 EncryptedFromSchemaBinary: toCodec<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 UnencryptedFromSchemaBinary: toCodec<NonEmptyArray<typeof RemoteEntry>>;
}
Since v4.0.0

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

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]);
static is(u: unknown): u is EventLogProtocolError;
}
Since v4.0.0

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

Signature

declare class EventLogRemoteRpcs extends {} {
constructor(_: never);
}
Since v4.0.0

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

unstable
Since v4.0.0

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

Signature

declare class HelloRpc extends {} {
constructor(_: never);
}
Since v4.0.0

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]);
}
Since v4.0.0

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

Signature

declare class WriteChunkedRpc extends {} {
constructor(_: never);
}
Since v4.0.0

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

Details

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

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 FromSchemaBinary: toCodec<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 FromSchemaBinary: toCodec<typeof WriteEntriesUnencrypted>;
encoded: Effect<Uint8Array<ArrayBuffer>, SchemaError, never>;
}
Since v4.0.0

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

Signature

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

Schemas

StoreId

unstable
Since v4.0.0

Schema for branded event-log store ids.

Signature

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

Type IDs

Since v4.0.0

Runtime brand identifier for event-log store ids.

Signature

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

StoreIdTypeId

type unstable
Since v4.0.0

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

Signature

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