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.
Compaction
compactBacklog
Signature
declare const compactBacklog: (...args: [options: {
readonly compactors: ReadonlyMap<string, RegisteredCompactor>;
readonly remoteEntries: readonly Array<RemoteEntry>;
}]) => Effect<readonly Array<RemoteEntry>, never, never>Constructors
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
makeWritefor the accessor that retrieves the typed server-side write function from the service environmentlayerServerfor the layer form that provides this service together with an event-logRegistry
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
>;makeStorageMemory
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>;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
EventLogServerAuthError
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;
});
}EventLogServerStoreError
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
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
layerNoRpcServerfor installing the same unencrypted handlers when anRpcServer.Protocolis provided elsewherelayerRpcHandlersfor wiring the unencrypted RPC handlers directlylayerServerfor 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>
>;layerNoRpcServer
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>
>;layerRpcHandlers
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
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
>;layerStorageMemory
Provides unencrypted server Storage using the in-memory implementation.
Signature
declare const layerStorageMemory: Layer.Layer<Storage>;layerStoreMappingStatic
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
EventLogServerAuthorization
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);
}EventLogServerUnencrypted
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);
}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
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);
}
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.