Skip to content

EventLogServerUnencrypted.ts

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.

Since v4.0.0



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

Signature

declare const makeWrite: <Groups extends EventGroup.Any>(
schema: EventLog.EventLogSchema<Groups>
) => Effect.Effect<
<
Tag extends EventGroup.Events<Groups>["tag"],
Event extends Event.Any = Event.WithTag<EventGroup.Events<Groups>, Tag>
>(options: {
readonly storeId: StoreId
readonly event: Tag
readonly payload: Event.Payload<Event>
}) => Effect.Effect<Event.Success<Event>, EventLogServerStoreError | Event.Error<Event>>,
never,
EventLogServerUnencrypted
>

Source

Since v4.0.0

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: (options: {
readonly remoteEntries: ReadonlyArray<RemoteEntry>
readonly compactors: ReadonlyMap<string, RegisteredCompactor>
}) => Effect.Effect<ReadonlyArray<EventJournal.RemoteEntry>, never, never>

Source

Since v4.0.0

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.Effect<
{
readonly makeWrite: <Groups extends EventGroup.Any>(
schema: EventLog.EventLogSchema<Groups>
) => <
Tag extends EventGroup.Events<Groups>["tag"],
Event extends Event.Any = Event.WithTag<EventGroup.Events<Groups>, Tag>
>(options: {
readonly storeId: StoreId
readonly event: Tag
readonly payload: Event.Payload<Event>
}) => Effect.Effect<Event.Success<Event>, EventLogServerStoreError | Event.Error<Event>>
},
never,
Storage | EventLog.Registry
>

Source

Since v4.0.0

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

Signature

declare class EventLogServerAuthError

Source

Since v4.0.0

Error raised by unencrypted server storage and store mapping operations.

Signature

declare class EventLogServerStoreError

Source

Since v4.0.0

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 const layer: <Groups extends EventGroup.Any, E, R>(
_schema: EventLog.EventLogSchema<Groups>,
layer: Layer.Layer<EventGroup.ToService<Groups>, E, R>
) => Layer.Layer<
never,
E,
| Exclude<R, EventLogServerUnencrypted | EventLog.Registry>
| EventLogServerAuthorization
| RpcServer.Protocol
| Storage
| StoreMapping
>

Source

Since v4.0.0

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

Signature

declare const layerNoRpcServer: <Groups extends EventGroup.Any, E, R>(
_schema: EventLog.EventLogSchema<Groups>,
layer: Layer.Layer<EventGroup.ToService<Groups>, E, R>
) => Layer.Layer<
Rpc.ToHandler<RpcGroup.Rpcs<typeof EventLogRemoteRpcs>> | EventLogAuthentication,
E,
Exclude<R, EventLogServerUnencrypted | EventLog.Registry> | EventLogServerAuthorization | Storage | StoreMapping
>

Source

Since v4.0.0

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<
| EventLogAuthentication
| Rpc.Handler<"EventLog.Hello">
| Rpc.Handler<"EventLog.Authenticate">
| Rpc.Handler<"EventLog.WriteChunked">
| Rpc.Handler<"EventLog.WriteSingle">
| Rpc.Handler<"EventLog.Changes">,
never,
Storage | StoreMapping | EventLog.Registry | EventLogServerAuthorization
>

Source

Since v4.0.0

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>

Source

Since v4.0.0

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

Source

Since v4.0.0

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

Source

Since v4.0.0

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

Source

Since v4.0.0

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

Source

Since v4.0.0

Provides unencrypted server Storage using the in-memory implementation.

Signature

declare const layerStorageMemory: Layer.Layer<Storage, never, never>

Source

Since v4.0.0

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<
{
readonly getId: Effect.Effect<RemoteId>
readonly getOrCreateSessionAuthBinding: (
publicKey: string,
signingPublicKey: Uint8Array<ArrayBuffer>
) => Effect.Effect<Uint8Array<ArrayBuffer>>
readonly entriesAfter: (storeId: StoreId, entry: Entry) => Effect.Effect<Array<Entry>>
readonly write: (storeId: StoreId, entries: ReadonlyArray<Entry>) => Effect.Effect<ReadonlyArray<RemoteEntry>>
readonly changes: (options: {
readonly storeId: StoreId
readonly startSequence: number
readonly compactors: ReadonlyMap<string, RegisteredCompactor>
}) => Stream.Stream<RemoteEntry>
readonly withTransaction: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
},
never,
Scope.Scope
>

Source

Since v4.0.0

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

Signature

declare const layerStoreMappingStatic: (options: { readonly storeId: StoreId }) => Layer.Layer<StoreMapping>

Source

Since v4.0.0