Skip to content

EventLogServer

Builds server-side handlers for the event-log remote protocol.

Transport modules use these handlers to expose an event journal to remote replicas. The handlers run the hello/authenticate challenge flow, attach the authenticated EventLog.Identity to later requests, accept single or chunked writes, and stream changes back as single or chunked messages.

4 exports Added in v4.0.0 Source

Layers

Provides RPC authentication middleware that reads the authenticated EventLog.Identity from client annotations.

Details

Requests without an identity fail with a forbidden EventLogProtocolError.

Signature

declare const layerAuthMiddleware: Layer.Layer<EventLogAuthentication>;

Creates the shared RPC handlers for the event-log remote protocol.

Details

The layer manages hello challenges, verifies session authentication, reassembles chunked writes, delegates write and change handling to the supplied callbacks, and frames large change payloads into chunks.

Signature

declare function layerRpcHandlers(options: {
  readonly changes: (options: {
    readonly publicKey: string;
    readonly startSequence: number;
    readonly storeId: StoreId;
  }) => Stream<Uint8Array<ArrayBuffer>, unknown>;
  readonly getOrCreateSessionAuthBinding: (
    publicKey: string,
    signingPublicKey: Uint8Array<ArrayBuffer>,
  ) => Effect<Uint8Array<ArrayBuffer>>;
  readonly onWrite: (
    data: Uint8Array<ArrayBuffer>,
    authenticatedPublicKeys: ReadonlySet<string>,
  ) => Effect<void, EventLogProtocolError>;
  readonly remoteId: RemoteId;
}): Layer<
  | EventLogAuthentication
  | Handler<"EventLog.Hello">
  | Handler<"EventLog.Authenticate">
  | Handler<"EventLog.WriteChunked">
  | Handler<"EventLog.WriteSingle">
  | Handler<"EventLog.Changes">
>;

Services

Annotation containing the public keys authenticated on an RPC connection.

Signature

declare class AuthenticatedIdentities extends Shape<
  "effect/eventlog/EventLogServer/AuthenticatedIdentities",
  Set<string>,
  this
> {
  constructor(_: never);
}

Annotation that stores partial ChunkedMessage data while chunked writes are being reassembled.

When to use

Use to keep per-client chunk assembly state while handling chunked event-log writes.

Signature

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