Skip to content

EventLogServerUnencrypted

Plaintext server implementation for the event-log remote protocol.

This module accepts unencrypted event batches from remote clients, runs the registered event handlers, stores journal entries, and streams backlog plus live changes through the shared EventLogServer RPC protocol. It is intended for trusted deployments, local development, and tests where event data does not need a server-side encryption layer. The module also provides the services and layers needed to authorize requests, map stores, persist entries, and install the plaintext server.

16 exports Added in v4.0.0 Source

Compaction

Runs the registered compactors over a backlog of remote entries.

When to use

Use to reduce stored remote entries before replaying them to an unencrypted event-log client.

Details

Contiguous entries handled by the same compactor may be replaced with compacted entries when the replacement count can be mapped back to increasing remote sequence numbers; otherwise the original entries are kept.

Signature

declare const compactBacklog: (...args: [options: {
  readonly compactors: ReadonlyMap<string, RegisteredCompactor>;
  readonly remoteEntries: readonly Array<RemoteEntry>;
}]) => Effect<readonly Array<RemoteEntry>, never, never>

Constructors

make

Added in v4.0.0 Source

Creates the EventLogServerUnencrypted service from the configured storage and registered event handlers.

When to use

Use when you need the unencrypted event-log server service from provided Storage and an event-log Registry.

Details

The constructed service exposes makeWrite, which builds a typed server-side write function from an EventLogSchema. Each write encodes the payload with the event schema, runs the registered handler, and persists the generated entry inside Storage.withTransaction.

Gotchas

The write function dies if the requested event tag is not present in the schema passed to makeWrite; it does not report that case as a typed failure.

See

  • makeWrite for the accessor that retrieves the typed server-side write function from the service environment
  • layerServer for the layer form that provides this service together with an event-log Registry

Signature

declare const make: Effect<
  {
    readonly makeWrite: <Groups extends Any>(
      schema: EventLogSchema<Groups>,
    ) => <
      Tag extends string,
      Event extends Any = Extract<
        Events<Groups>,
        {
          readonly tag: Tag;
        }
      >,
    >(options: {
      readonly event: Tag;
      readonly payload: Type<PayloadSchema<Event>>;
      readonly storeId: StoreId;
    }) => Effect<Type<SuccessSchema<Event>>, EventLogServerStoreError | Type<ErrorSchema<Event>>>;
  },
  never,
  Registry | Storage
>;

Creates an in-memory unencrypted server Storage.

Details

The implementation keeps per-store journals and session authentication bindings in memory, publishes live changes, and serializes transactions with a semaphore.

Signature

declare const makeStorageMemory: Effect.Effect<Storage["Service"], never, Scope.Scope>;

makeWrite

Added in v4.0.0 Source

Creates a typed server-side write function for events in the supplied EventLogSchema.

Signature

declare function makeWrite<Groups extends Any>(
  schema: EventLogSchema<Groups>,
): Effect<
  <
    Tag extends string,
    Event extends Any = Extract<
      Events<Groups>,
      {
        readonly tag: Tag;
      }
    >,
  >(options: {
    readonly event: Tag;
    readonly payload: Type<PayloadSchema<Event>>;
    readonly storeId: StoreId;
  }) => Effect<Type<SuccessSchema<Event>>, EventLogServerStoreError | Type<ErrorSchema<Event>>>,
  never,
  EventLogServerUnencrypted
>;

Errors

Error raised when unencrypted server authorization rejects an identity or store operation.

Signature

declare class EventLogServerAuthError extends YieldableError<this> & {
  readonly _tag: "EventLogServerAuthError";
} & Readonly<{
  readonly message?: string;
  readonly publicKey: string;
  readonly reason: "Forbidden" | "Unauthorized";
  readonly storeId?: StoreId;
}> {
  constructor(args: {
    readonly message?: string;
    readonly publicKey: string;
    readonly reason: "Forbidden" | "Unauthorized";
    readonly storeId?: StoreId;
  });
}

Error raised by unencrypted server storage and store mapping operations.

Signature

declare class EventLogServerStoreError extends YieldableError<this> & {
  readonly _tag: "EventLogServerStoreError";
} & Readonly<{
  readonly message?: string;
  readonly publicKey?: string;
  readonly reason: "NotFound" | "PersistenceFailure";
  readonly storeId?: StoreId;
}> {
  constructor(args: {
    readonly message?: string;
    readonly publicKey?: string;
    readonly reason: "NotFound" | "PersistenceFailure";
    readonly storeId?: StoreId;
  });
}

Layers

layer

Added in v4.0.0 Source

Builds a full unencrypted event-log RPC server for the supplied schema and event-group handler layer.

When to use

Use when you need the full unencrypted event-log RPC server layer with storage, authorization, RPC protocol, and event-group handler dependencies supplied externally.

Details

The layer installs EventLogRemoteRpcs, wires layerRpcHandlers, registers the supplied event-group handler layer, and provides layerServer, leaving only the required infrastructure services in the environment.

Gotchas

Entries are persisted and streamed in plaintext. Protect the backing Storage with the surrounding infrastructure, and use durable storage that preserves session authentication bindings when the server must survive restarts.

See

  • layerNoRpcServer for installing the same unencrypted handlers when an RpcServer.Protocol is provided elsewhere
  • layerRpcHandlers for wiring the unencrypted RPC handlers directly
  • layerServer for constructing the server service and event-log registry without RPC handlers

Signature

declare function layer<Groups extends Any, E, R>(
  _schema: EventLogSchema<Groups>,
  layer: Layer<ToService<Groups>, E, R>,
): Layer<
  never,
  E,
  | Protocol
  | Storage
  | StoreMapping
  | EventLogServerAuthorization
  | Exclude<R, Registry | EventLogServerUnencrypted>
>;

Builds the unencrypted event-log server handlers without installing an RpcServer.Protocol implementation.

Signature

declare function layerNoRpcServer<Groups extends Any, E, R>(
  _schema: EventLogSchema<Groups>,
  layer: Layer<ToService<Groups>, E, R>,
): Layer<
  | EventLogAuthentication
  | Handler<"EventLog.Hello">
  | Handler<"EventLog.Authenticate">
  | Handler<"EventLog.WriteChunked">
  | Handler<"EventLog.WriteSingle">
  | Handler<"EventLog.Changes">,
  E,
  | Storage
  | StoreMapping
  | EventLogServerAuthorization
  | Exclude<R, Registry | EventLogServerUnencrypted>
>;

Provides RPC handlers for the unencrypted event-log server.

Details

Incoming plaintext entries are authorized, mapped to a server store, checked for conflicts, run through registered handlers, and persisted; change streams include compacted backlog entries when compactors are registered.

Signature

declare const layerRpcHandlers: Layer.Layer<
  Rpc.ToHandler<RpcGroup.Rpcs<typeof EventLogRemoteRpcs>> | EventLogAuthentication,
  never,
  Storage | StoreMapping | EventLogServerAuthorization | EventLog.Registry
>;

layerServer

Added in v4.0.0 Source

Provides EventLogServerUnencrypted and an event-log Registry using the configured unencrypted server Storage.

When to use

Use to provide the unencrypted event-log server service together with the registry needed by event handlers.

Signature

declare const layerServer: Layer.Layer<
  EventLogServerUnencrypted | EventLog.Registry,
  never,
  Storage
>;

Provides unencrypted server Storage using the in-memory implementation.

Signature

declare const layerStorageMemory: Layer.Layer<Storage>;

Provides a StoreMapping that accepts only one configured store id and fails all other store ids as not found.

Signature

declare function layerStoreMappingStatic(options: {
  readonly storeId: StoreId;
}): Layer<StoreMapping>;

Services

Service that validates unencrypted event-log server write access, read access, and identities.

When to use

Use to provide authorization checks for plaintext event-log writes, reads, and identity authentication.

Signature

declare class EventLogServerAuthorization extends Shape<"effect/eventlog/EventLogServerUnencrypted/EventLogServerAuthorization", {
  readonly authorizeIdentity: (options: {
    readonly publicKey: string;
  }) => Effect<void, EventLogServerAuthError>;
  readonly authorizeRead: (options: {
    readonly publicKey: string;
    readonly storeId: StoreId;
  }) => Effect<void, EventLogServerAuthError>;
  readonly authorizeWrite: (options: {
    readonly entries: readonly Array<Entry>;
    readonly publicKey: string;
    readonly storeId: StoreId;
  }) => Effect<void, EventLogServerAuthError>;
}, this> {
  constructor(_: never);
}

Service that writes plaintext event-log entries directly to unencrypted storage through registered event handlers.

When to use

Use to access or provide the server service that handles plaintext event-log writes.

Signature

declare class EventLogServerUnencrypted extends Shape<
  "effect/eventlog/EventLogServerUnencrypted",
  {
    readonly makeWrite: <Groups extends Any>(
      schema: EventLogSchema<Groups>,
    ) => <
      Tag extends string,
      Event extends Any = Extract<
        Events<Groups>,
        {
          readonly tag: Tag;
        }
      >,
    >(options: {
      readonly event: Tag;
      readonly payload: Type<PayloadSchema<Event>>;
      readonly storeId: StoreId;
    }) => Effect<Type<SuccessSchema<Event>>, EventLogServerStoreError | Type<ErrorSchema<Event>>>;
  },
  this
> {
  constructor(_: never);
}

Storage

Added in v4.0.0 Source

Defines the backing store service used by the unencrypted event-log server.

When to use

Use to provide durable event-log persistence for an unencrypted event-log server layer.

Details

It provides the server remote id, stores session authentication bindings, allocates remote sequence numbers, persists entries, streams changes, and exposes a transaction boundary.

Signature

declare class Storage extends Shape<"effect/eventlog/EventLogServerUnencrypted/Storage", {
  readonly changes: (options: {
    readonly compactors: ReadonlyMap<string, RegisteredCompactor>;
    readonly startSequence: number;
    readonly storeId: StoreId;
  }) => Stream<RemoteEntry>;
  readonly entriesAfter: (storeId: StoreId, entry: Entry) => Effect<Array<Entry>>;
  readonly getId: Effect<RemoteId>;
  readonly getOrCreateSessionAuthBinding: (publicKey: string, signingPublicKey: Uint8Array<ArrayBuffer>) => Effect<Uint8Array<ArrayBuffer>>;
  readonly withTransaction: <A, E, R>(effect: Effect<A, E, R>) => Effect<A, E, R>;
  readonly write: (storeId: StoreId, entries: readonly Array<Entry>) => Effect<readonly Array<RemoteEntry>>;
}, this> {
  constructor(_: never);
}

StoreMapping

Added in v4.0.0 Source

Service that resolves client-requested store ids to server store ids and checks whether a store exists.

When to use

Use to map client-visible store identifiers to server storage identifiers before authorizing or serving unencrypted event-log requests.

Signature

declare class StoreMapping extends Shape<
  "effect/eventlog/EventLogServerUnencrypted/StoreMapping",
  {
    readonly hasStore: (options: {
      readonly publicKey: string;
      readonly storeId: StoreId;
    }) => Effect<boolean, EventLogServerStoreError>;
    readonly resolve: (options: {
      readonly publicKey: string;
      readonly storeId: StoreId;
    }) => Effect<StoreId, EventLogServerStoreError>;
  },
  this
> {
  constructor(_: never);
}