Skip to content
// EFFECT DAYS 2026

MessageLog unstable

The message log: a development and test hook the runtime calls once per update and at every lifecycle step of every instance.

It's off by default. The MessageLog service defaults to a no-op whose enabled flag is false, and the runtime checks the flag before it builds an entry, so an app that doesn't provide a log pays nothing for it. Provide memory for a ring buffer, socket to stream entries to a devtools process, or fanout for several sinks. Production observability goes through Effect's tracer, logger and metrics instead, and slow renders through Renderer.slowPhases.

Entries hold decoded values and references, never copies. They're encoded through the component's Schemas only when they're sent somewhere, as the versioned Wire.

Example Keeping the last 1,000 entries

import { MessageLog } from "effect/ui"
const DevLog = MessageLog.memory({ size: 1_000 })
57 exports Since v4.2.0 Source

Combinators

fanoutAll

unstable
Since v4.2.0

Sends every entry to several logs. Enabled when any of them is.

Details

Two Layers of one service can't compose, so this is how a memory buffer and a socket run together.

Signature

declare const fanoutAll: (logs: ReadonlyArray<MessageLog>) => MessageLog

Constructors

makeEncoded

unstable
Since v4.2.0

Makes a log that encodes entries off the runtime's path. record only queues an entry. A fiber in the current Scope takes everything queued, encodes it as Wire frames, and passes the batch to onBatch.

Details

The runtime calls record on every update, so a sink that sends frames somewhere builds on this rather than encode inside record. A value whose Schema fails to encode is sent as a placeholder, and a warning is logged the first time per component and field. maxEntryBytes caps Models, messages, query results and shared values, as in makeEncoder. A batch whose onBatch dies is dropped, and an error is logged. Entries recorded once the Scope has closed are dropped.

Signature

declare function makeEncoded(onBatch: (batch: readonly Array<WireEntry>) => Effect<void>, options?: {
readonly maxEntryBytes?: number;
}): Effect<MessageLog, never, Scope>

Example Keeping encoded frames in an array

import { MessageLog } from "effect/ui"
import { Effect, Layer } from "effect"
const frames: Array<MessageLog.WireEntry> = []
const FramesLog = Layer.effect(
MessageLog.MessageLog,
MessageLog.makeEncoded((batch) => Effect.sync(() => frames.push(...batch)))
)

makeMemory

unstable
Since v4.2.0

Makes a ring buffer log holding the last size entries (1,000 by default).

Signature

declare function makeMemory(options?: {
readonly size?: number;
}): Memory

noop

unstable
Since v4.2.0

The no-op log: enabled is false and nothing is recorded.

Signature

declare const noop: MessageLog

Layers

fanout

unstable
Since v4.2.0

A Layer that sends entries to every log the given Layers provide.

Details

Registers each mounted browser root with every distinct BrowserHost.Controllables registry the Layers provide, including the one from DevTools.layer. Registries are deduplicated by object identity. Other services are kept; when multiple Layers provide the same service, the later Layer's wins.

Signature

declare function fanout<Layers extends readonly Array<Layer<never, any, any>>>(layers: Layers): Layer<never, Error<Layers[number]>, Services<Layers[number]>>

memory

unstable
Since v4.2.0

One ring buffer shared by every instance, 1,000 entries by default.

Signature

declare function memory(options?: {
readonly size?: number;
}): Layer<never>

socket

unstable
Since v4.2.0

Streams entries to a devtools process over a WebSocket, as newline-free JSON Wire frames, one per message.

Details

Entries are encoded by makeEncoded. The Layer keeps the last buffer frames (1,000 by default), which every new connection receives after its Hello. It also retains older frames needed to reconstruct mounted instances, their current state, and waiting or running commands. Retained command outcomes prevent completed commands from appearing as waiting. Older history may be missing.

Session starts are retained for the lifetime of the layer. An instance releases its retained frames when its Unmounted leaves the buffer. Retained frames precede the buffer in sequence order on each connection. A lost connection is retried with backoff, and one warning is logged. A defect, such as a throwing WebSocket constructor, is logged and not retried.

Signature

declare function socket(url: string, options?: {
readonly buffer?: number;
readonly host?: "server" | "browser" | "test" | "native" | "terminal";
readonly maxEntryBytes?: number;
}): Layer<never, never, WebSocketConstructor>

Models

AwaitedEntry

interface unstable
Since v4.2.0

An entry a Command.afterRefetch run waits for: the query's name and the entry's log key.

Signature

interface AwaitedEntry {
readonly logKey: string;
readonly query: string;
}

Base

interface unstable
Since v4.2.0

Fields every entry has: its number, its time from Clock, the session it belongs to, and the entry it follows from.

Details

An entry without causedBy is a fact: something that reached the tree from outside it. The session starting is one. So is an Update whose message came from a DOM event, a Command's result, a Subscription, a mount or root.send, a QueryChanged, a Layer build, Command run or mount body ending, and a FetchStarted a timer, a host signal or a Command's own work started.

An entry with causedBy is a consequence. The field is the seq of the fact it follows from, however many steps lie between them: a child's Update for a parent's $.send names the fact the parent's update handled, not the parent's entry. The entries of a render name the fact that last made the rendered instance dirty, so when one flush renders what two messages changed, an instance both changed names the later one. CommandInterrupted names the fact whose handling stopped the run, where issued names the entry that started it. When a render stops a mount, MountEnded.causedBy names the fact whose render stopped it, and started names its MountStarted entry. A FetchStarted with trigger "watch" names the fact whose render declared the query's args. A reader's shared onChange Update names the fact that changed the owner's value, and an owner's collects.onChange Update the fact that last changed a report.

The seq it holds may be of an entry a ring buffer has dropped.

Signature

interface Base {
readonly at: number;
readonly causedBy?: number;
readonly seq: number;
readonly session: string;
}

CommandAwaiting

interface unstable
Since v4.2.0

A run issued with Command.afterRefetch succeeded and waits for the refetches its invalidation started, written at its fiber's exit after the batch's fetch entries. entries is the awaited set, which isn't empty: an empty one logs no entry, and CommandEnded has waitEnded: "nothing".

Signature

interface CommandAwaiting extends InstanceBase {
readonly _tag: "CommandAwaiting";
readonly entries: readonly Array<AwaitedEntry>;
readonly issued: Issued;
readonly name: string;
}

CommandDropped

interface unstable
Since v4.2.0

A Command that never ran: dropped by the server, where no Command runs. Only a Command from update is logged; init's are dropped silently, since the client runs them when it adopts.

Signature

interface CommandDropped extends InstanceBase {
readonly _tag: "CommandDropped";
readonly issued: Issued;
readonly name: string;
readonly reason: "server";
}

CommandEnded

interface unstable
Since v4.2.0

A Command run ended with a result.

Details

spanId and traceId are the run's span, undefined when its span never began. They're here because a run that sends no message has no Update entry whose source would carry them.

Signature

interface CommandEnded extends InstanceBase {
readonly _tag: "CommandEnded";
readonly issued: Issued;
readonly name: string;
readonly outstanding?: readonly Array<AwaitedEntry>;
readonly silent: boolean;
readonly spanId: string | undefined;
readonly traceId: string | undefined;
readonly waitEnded?: WaitEnded;
}

CommandInterrupted

interface unstable
Since v4.2.0

A Command run was interrupted and dispatched nothing. reason says what stopped it (see InterruptReason).

Details

It's logged when the run's fiber has exited, which is when h.isRunning stops counting it and a run queued behind it in its group starts: a run whose cleanup is still going has no entry yet. A run that never got a fiber logs it when it's stopped.

Signature

interface CommandInterrupted extends InstanceBase {
readonly _tag: "CommandInterrupted";
readonly issued: Issued;
readonly name: string;
readonly reason: InterruptReason;
readonly spanId: string | undefined;
readonly traceId: string | undefined;
}

CommandStarted

interface unstable
Since v4.2.0

A Command run's fiber started its work, in the run's span.

Details

From here until its end entry the run is running: CommandEnded, CommandInterrupted, or a Failed with its issued. A run with an end entry and no CommandStarted never began: it was stopped while queued in its group or while it waited for its instance's Layer. causedBy names the fact of the step that started it: the one that issued it, the one that freed its group for a queued run, or the Layer build that ended for a run that waited for it.

Signature

interface CommandStarted extends InstanceBase {
readonly _tag: "CommandStarted";
readonly issued: Issued;
readonly name: string;
readonly parentSpanId?: string;
readonly spanId: string;
readonly traceId: string;
}

Entry

type unstable
Since v4.2.0

Any log entry: one about the tree, or one about an instance.

Signature

type Entry = SessionStarted | FetchStarted | InstanceEntry

Failed

interface unstable
Since v4.2.0

An instance failed, with the real Cause and where it happened.

Details

props are the instance's, as of the failure. An instance that fails in init, or whose Layer fails before it mounts, has no Mounted entry, so this is the only entry that says what was there.

A failed root is the instance with no parent: its Failed entry is followed by its Unmounted. When the root fallback given to mount throws, the root logs a second Failed after that, in "fallback".

Signature

interface Failed extends InstanceBase {
readonly _tag: "Failed";
readonly cause: Cause<unknown>;
readonly in: FailedIn;
readonly issued?: Issued;
readonly name: string | undefined;
readonly props: unknown;
readonly update?: {
readonly message: unknown;
readonly source: Source;
};
}

FailedIn

type unstable
Since v4.2.0

Where a failure happened: the code that threw or failed.

Signature

type FailedIn = "init" | "update" | "view" | "event" | "mount" | "command" | "subscription" | "layer" | "fallback" | "onEmit" | "onFailure" | "head" | "send" | "shares" | "shared"

FetchStarted

interface unstable
Since v4.2.0

The query cache started a fetch.

Details

logKey is the entry's args key with every Schema.Redacted argument redacted, so two entries that differ only in a secret share it. restart marks a fetch that replaced an interrupted one, under the same trigger. inWindow marks a fetch of a hydrated entry while the fetch-free window is open. stored: false marks a fetcher call whose result goes to get callers only. empty is true when the entry held no current or previous Success when the fetch started. watcher is the path of the instance whose watch or $.loadMore started the fetch. A caller that joins a fetch in flight logs nothing.

An infinite query logs each page it requests as its own entry: page is the page's index, from 0, and cursor the cursor encoded by the list's cursor Schema, absent for the first page. A query that isn't a list has neither.

Signature

interface FetchStarted extends Base {
readonly _tag: "FetchStarted";
readonly cursor?: Json;
readonly empty: boolean;
readonly inWindow: boolean;
readonly logKey: string;
readonly page?: number;
readonly parentSpanId?: string;
readonly query: string;
readonly restart: boolean;
readonly stored: boolean;
readonly traceId?: string;
readonly trigger: Trigger;
readonly watcher?: string;
}

InstanceBase

interface unstable
Since v4.2.0

Fields every entry about an instance has: its path, its number and its component.

Details

instance tells two instances at one path apart. A path names a place in the tree, and a child can mount there again before the instance that was there has logged Unmounted. The number is unique in the session, and later instances have higher ones.

component is on every entry, so an entry still names its component when the instance's first entry has left a ring buffer. Its Schemas encode the entry's values for the Wire.

Signature

interface InstanceBase extends Base {
readonly component: Any;
readonly excluded?: boolean;
readonly instance: number;
readonly path: string;
}

InstanceEntry

type unstable
Since v4.2.0

Any entry about one instance.

Signature

type InstanceEntry = Waiting | Mounted | Update | PropsChanged | QueryChanged | LayerPending | LayerReady | LayerFailed | Failed | Unmounted | Unplaced | Placed | MountStarted | MountEnded | CommandStarted | CommandAwaiting | CommandEnded | CommandInterrupted | CommandDropped | SendDropped | SubscriptionStarted | SubscriptionStopped

InterruptReason

type unstable
Since v4.2.0

What stopped a Command run, as CommandInterrupted reports it.

Details

  • "interrupt": an update issued Command.interrupt for its group.
  • "switch": an update issued a later run of its switch group.
  • "unmount": its instance was removed, or the app was disposed.
  • "layer": its instance's provided Layer failed before the run could start, or a keyed provide selected again and dropped the runs issued before it.
  • "self": its own work was interrupted, and nothing in the tree asked it to stop.

causedBy names the fact whose handling stopped it, for every reason but "self".

Signature

type InterruptReason = "interrupt" | "switch" | "unmount" | "layer" | "self"

Issued

interface unstable
Since v4.2.0

Which Command run an entry is about: the seq of the entry that issued it (an Update or a Mounted) and its index in that entry's commands.

Signature

interface Issued {
readonly index: number;
readonly seq: number;
}

LayerFailed

interface unstable
Since v4.2.0

A provided Layer failed to build.

Details

redacted is true when the feature slots below got a cause that says a provided Layer failed on the server: for a handled failure on the server, whose cause is the one its handler got, and on a client that adopted that failure. A replay passes the slots that substitute, not cause.

Signature

interface LayerFailed extends InstanceBase {
readonly _tag: "LayerFailed";
readonly cause: Cause<unknown>;
readonly redacted?: boolean;
}

LayerPending

interface unstable
Since v4.2.0

An instance's provided Layer is still building once the instance is created, or once a keyed provide selected again. Its Commands, Subscriptions and mounts, and its descendants', wait for it.

Details

status is what the instance's feature slots record until the Layer settles: Pending at mount, Rebuilding after a keyed provide selected again, and Awaiting for an instance the server rendered with its services that waits for the client's build. A Wire frame without it, from an older log, is Pending.

Signature

interface LayerPending extends InstanceBase {
readonly _tag: "LayerPending";
readonly status: "Pending" | "Rebuilding" | "Awaiting";
}

LayerReady

interface unstable
Since v4.2.0

The Layer an earlier LayerPending waited for is built.

Signature

interface LayerReady extends InstanceBase {
readonly _tag: "LayerReady";
}

Memory

interface unstable
Since v4.2.0

A ring buffer log whose entries can be read back.

Signature

interface Memory extends MessageLog {
readonly entries: () => readonly Array<Entry>;
}

Mounted

interface unstable
Since v4.2.0

An instance mounted: its props, the Model from init (or adopted from the server or from history), its query results, and the Commands init returned.

Details

queries is what the instance starts with: the server's or history's results when it adopted them, and every query empty otherwise. Only a component with queries has it. The first values of its watches come after, as QueryChanged entries.

Signature

interface Mounted extends InstanceBase {
readonly _tag: "Mounted";
readonly adopted: boolean;
readonly boundary?: number;
readonly commands: readonly Array<Command<any, any>>;
readonly events: readonly Array<unknown>;
readonly model: unknown;
readonly props: unknown;
readonly queries?: Results;
}

MountEnded

interface unstable
Since v4.2.0

The mount body returned, its Scope closed first, or the body failed.

Details

A completed body's Scope outlives it. Releasing that Scope when the element goes writes no further entry. New args published to a running mount write no entry either: each mount-sourced Update carries the args its element last rendered with. Hosts that don't run mounts (the server and TestHost) log neither mount starts nor ends.

Signature

interface MountEnded extends InstanceBase {
readonly _tag: "MountEnded";
readonly name: string;
readonly reason: "closed" | "completed" | "failed";
readonly silent: boolean;
readonly started: number;
}

MountStarted

interface unstable
Since v4.2.0

An element's mount body started, with these args: after the commit, or just before it for a mount made with beforeCommit.

Signature

interface MountStarted extends InstanceBase {
readonly _tag: "MountStarted";
readonly args: unknown;
readonly argsSchema: Top;
readonly name: string;
}

Placed

interface unstable
Since v4.2.0

A bound child was placed by its parent's view and drew its nodes: the first time, or after Unplaced.

Signature

interface Placed extends InstanceBase {
readonly _tag: "Placed";
}

PropsChanged

interface unstable
Since v4.2.0

A mounted instance got new props from its parent or root.setProps, without a re-key. Its queries' args can read them, so Story.fromLog applies it to reach the state the instance ended with.

Details

It's logged before the result writes the new props cause. Props equal to the current ones log nothing.

Signature

interface PropsChanged extends InstanceBase {
readonly _tag: "PropsChanged";
readonly props: unknown;
}

QueryChanged

interface unstable
Since v4.2.0

A query's result changed: the runtime wrote what the query last returned at its args. result is opaque. Story.fromLog applies it to reach the results the instance ended with.

Details

A query with onChange logs this entry before the Update of the message it returns, whose source points at it. An onChange that returns undefined logs no Update.

Signature

interface QueryChanged extends InstanceBase {
readonly _tag: "QueryChanged";
readonly name: string;
readonly result: unknown;
}

SendDropped

interface unstable
Since v4.2.0

A $.send that reached no owner: the sender's reads lists the owner as optional, and no instance of it is above the sender. path is the sender's, owner the name of the owner, and issued the sender's Update entry and the send's index in its sends.

Signature

interface SendDropped extends InstanceBase {
readonly _tag: "SendDropped";
readonly issued: Issued;
readonly owner: string;
}

SessionStarted

interface unstable
Since v4.2.0

A mount or a server render started.

Signature

interface SessionStarted extends Base {
readonly _tag: "SessionStarted";
readonly app: string;
}

Source

type unstable
Since v4.2.0

What sent the message an update handled.

Details

DomEvent is a view handler, such as a click. Command is a Command's result, pointing at the entry that issued it and at its span. Subscription is a keyed Subscription, with the name and deps its key was built from (see SubscriptionStarted). Query is a query's onChange, pointing at the QueryChanged entry it saw. Emit is a child's emit, pointing at the child's entry. Failure is a parent's onFailure for a child that failed, pointing at the child's Failed entry. Send is a descendant's $.send to an owner of shared state, pointing at the sender's entry. Shared is a reader's onChange for its owner's shared value: the name the reader's reads lists the owner under, the owner's path, and the owner's entry that last changed the value. Collected is an owner's collects.onChange for a change in its readers' reports. Mount is an onMount result, pointing at its MountStarted entry and carrying the mount's name and the args its element last rendered with. Dispatch is a message sent from outside the tree, such as TestHost's root.send.

Emit, Failure, Send and Shared name the other instance's path as well as its entry, so a ring buffer that has dropped that entry still says where the message came from.

Signature

type Source = {
readonly _tag: "DomEvent";
readonly name: string;
} | {
readonly _tag: "Command";
readonly issued: Issued;
readonly name: string;
readonly spanId: string | undefined;
readonly traceId: string | undefined;
} | {
readonly _tag: "Subscription";
readonly deps: ReadonlyArray<Subscription.Dep> | undefined;
readonly key: string;
readonly name: string;
} | {
readonly _tag: "Query";
readonly name: string;
readonly seq: number;
} | {
readonly _tag: "Emit";
readonly path: string;
readonly seq: number;
} | {
readonly _tag: "Failure";
readonly path: string;
readonly seq: number;
} | {
readonly _tag: "Send";
readonly path: string;
readonly seq: number;
} | {
readonly _tag: "Shared";
readonly name: string;
readonly path: string;
readonly seq: number;
} | {
readonly _tag: "Collected";
} | {
readonly _tag: "Mount";
readonly args: unknown;
readonly argsSchema: Schema.Top;
readonly name: string;
readonly seq: number;
} | {
readonly _tag: "Dispatch";
}

SubscriptionStarted

interface unstable
Since v4.2.0

A Subscription's key started. A query's watch isn't a Subscription here: its fetches are FetchStarted entries and its values QueryChanged.

Details

key is the Subscription's identity, and what its SubscriptionStopped and the Update entries it sends carry too. name and deps are what Subscription.make built the key from: Subscription.make("room", "42", ...) logs name: "room", deps: ["42"] and key: 'room:"42"'. Group and label by name, and never by parsing key. deps is undefined for a Subscription with no deps.

Signature

interface SubscriptionStarted extends InstanceBase {
readonly _tag: "SubscriptionStarted";
readonly deps: readonly Array<Dep> | undefined;
readonly key: string;
readonly name: string;
}

SubscriptionStopped

interface unstable
Since v4.2.0

A Subscription's key stopped. name and deps are those of the SubscriptionStarted entry with the same key.

Signature

interface SubscriptionStopped extends InstanceBase {
readonly _tag: "SubscriptionStopped";
readonly deps: readonly Array<Dep> | undefined;
readonly key: string;
readonly name: string;
}

Unmounted

interface unstable
Since v4.2.0

An instance left the tree: from then on it takes no message, props or query results, and its path is free.

Details

An instance removed with its parent logs its own entry before its parent's. Its Scope closes after, and its Commands log their ends as they exit, which can be later than this entry.

It also ends the instance's Subscriptions and any Layer still pending: neither logs an end entry when its instance goes, so a reader closes them at this entry. Mounts log their own MountEnded, and Command runs their own CommandEnded or CommandInterrupted.

Signature

interface Unmounted extends InstanceBase {
readonly _tag: "Unmounted";
}

Unplaced

interface unstable
Since v4.2.0

A bound child that its parent's view no longer places dropped its nodes, when the flush that unplaced it ended. It stays mounted: it takes messages, props and query results, and its Commands and Subscriptions go on.

Details

An unplaced child runs no view, and the view-scoped children under it unmount with its nodes. A child moved from one place to another in one flush logs nothing. Placed ends the interval.

Signature

interface Unplaced extends InstanceBase {
readonly _tag: "Unplaced";
}

Update

interface unstable
Since v4.2.0

One update call: the message, what sent it, the props and query results it saw, the Model after it, and the Commands, events, load mores, resets and sends it returned.

Details

It holds the instance's whole state, so a replay can start from any Update a ring buffer still has.

Signature

interface Update extends InstanceBase {
readonly _tag: "Update";
readonly boundary?: number;
readonly collected?: readonly Array<unknown>;
readonly commands: readonly Array<Command<any, any>>;
readonly events: readonly Array<unknown>;
readonly lists: readonly Array<ListIssue>;
readonly message: unknown;
readonly model: unknown;
readonly props: unknown;
readonly queries?: Results;
readonly sends: readonly Array<Send>;
readonly shared?: SharedRecord;
readonly source: Source;
readonly viewTransition?: readonly Array<string>;
}

WaitEnded

type unstable
Since v4.2.0

How a Command.afterRefetch wait ended.

Signature

type WaitEnded = "settled" | "nothing" | "budget" | "switch" | "interrupt" | "closed"

Waiting

interface unstable
Since v4.2.0

A hydrating instance is waiting for its provided Layer: it shows the nodes the server rendered, inert, and has no Model of its own yet.

Details

It's the instance's first entry, logged when the instance is created, with the props it was given and the Model and query results the server rendered the path with: the state the instance adopts. Its Layer entries follow. When the Layer is ready, or fails and onFailure handles it, the instance logs Mounted with its live Model, which includes any update a beforeCommit mount made while it waited. An instance removed while it waits logs Unmounted and never Mounted.

Signature

interface Waiting extends InstanceBase {
readonly _tag: "Waiting";
readonly boundary?: number;
readonly model: unknown;
readonly props: unknown;
readonly queries?: Results;
}

Services

MessageLog

unstable
Since v4.2.0

The MessageLog service. It defaults to noop, so it never has to be provided.

Signature

declare const MessageLog: Reference<MessageLog>

MessageLog

interface unstable
Since v4.2.0

The service the runtime records entries to.

Details

record is called synchronously from the runtime and must not throw. The runtime checks enabled before it builds an entry, and assigns seq itself, so every sink numbers entries the same way. It's runtime input only: it's never part of a component's requirements, and app code can't write entries.

Signature

interface MessageLog {
readonly enabled: boolean;
readonly record: (entry: Entry) => void;
}

Wire

Since v4.2.0

Encodes a Command by name, group and args. Args and group fields use the Command's args Schema, replacing every Schema.Redacted with a placeholder. A leaf that fails to encode falls back to structural encoding. An Interrupt has null args.

Signature

declare function encodeCommand(command: Command<any, any>): {
readonly _tag: "Interrupt" | "Effect" | "Stream";
readonly args: Json;
readonly group: string | null;
readonly name: string;
}

Encoder

interface unstable
Since v4.2.0

Turns entries into Wire frames.

Signature

interface Encoder {
readonly encode: (entry: Entry) => WireEntry;
}

encodeSend

unstable
Since v4.2.0

Encodes a $.send as the owner's name and the message. The message goes through the owner's receives Schema the way encodeArgs encodes Command args: redacted, with a structural fallback for what doesn't encode.

Signature

declare function encodeSend(send: Send): {
readonly message: Json;
readonly owner: string;
}
Since v4.2.0

Whether a JSON value from a Wire frame is a Placeholder: an object with one key, "~unserialisable" with a string, "~redacted" with true, or "~truncated" with a number.

Signature

declare function isPlaceholder(value: unknown): value is Placeholder

makeEncoder

unstable
Since v4.2.0

Makes an encoder. onWarning is called once per component and field the first time its Schema fails to encode a value, which is sent as a placeholder instead.

Signature

declare function makeEncoder(options?: {
readonly maxEntryBytes?: number;
readonly onWarning?: (message: string) => void;
}): Encoder

Placeholder

type unstable
Since v4.2.0

A value the encoder sent in place of one it couldn't or mustn't send.

Signature

type Placeholder = {
readonly "~unserialisable": string;
} | {
readonly "~redacted": true;
} | {
readonly "~truncated": number;
}
Since v4.2.0

Returns a schema that encodes Schema.Redacted values as { "~redacted": true } and rejects those placeholders on decode. Returns schema unchanged if it contains no Schema.Redacted.

Signature

declare function redactSchema(schema: Top): Top

structural

unstable
Since v4.2.0

Encodes any value as JSON, best effort, with the Wire's placeholders for what has no JSON form.

Signature

declare function structural(value: unknown, seen: Set<unknown>): Json

Wire

unstable
Since v4.2.0

The versioned, one-way Schema of what a log sends: a Hello once per connection, then entries with their values already encoded.

Details

Models, messages, props and events are encoded through the component's Schemas, and a send's message through its owner's receives. A shared value a reader's Update holds is encoded through the schema of its owner's shares, or structurally without one, and an owner's reports through its collects.schema. Command args and a mount's args are encoded through the definition's args Schema, field by field, and a field that doesn't encode falls back to a structural encoding, best effort: a value with no JSON form becomes { "~unserialisable": "<kind>" }, a Redacted becomes { "~redacted": true }, and a Model or message over maxEntryBytes becomes { "~truncated": bytes }. A Cause is sent as Cause.pretty plus its reasons, best effort. An entry's component is sent as its name.

A Subscription's deps are sent as an array of JSON values, or null for a Subscription with none. They're there to be read: NaN, Infinity and -Infinity are sent as { "~unserialisable": "number" } and -0 as 0. The key beside them still tells those deps apart.

Every Schema.Redacted in props, Models, messages, events, Command and mount args, sends and shared values is sent as the placeholder. Two values have no Schema to mark them, and are sent in clear: a Subscription's key and deps, and the message text of an error in a Cause. Build a Subscription's key from an id that isn't secret, and keep secrets out of error messages.

A reader treats each placeholder (see isPlaceholder) as a leaf whose value is unknown: two placeholders aren't known to be equal, and a value that is one isn't known to have changed.

Signature

declare const Wire: Union<readonly [TaggedStruct<"Hello", {
readonly host: Literals<readonly ["browser", "native", "server", "terminal", "test"]>;
readonly version: Number;
}>, TaggedStruct<"SessionStarted", {
readonly app: String;
readonly at: Number;
readonly causedBy: optionalKey<Number>;
readonly seq: Number;
readonly session: String;
}>, TaggedStruct<"FetchStarted", {
readonly at: Number;
readonly causedBy: optionalKey<Number>;
readonly cursor: optionalKey<Codec<Json, Json, never, never>>;
readonly empty: optionalKey<Boolean>;
readonly inWindow: Boolean;
readonly logKey: String;
readonly page: optionalKey<Number>;
readonly parentSpanId: optionalKey<String>;
readonly query: String;
readonly restart: Boolean;
readonly seq: Number;
readonly session: String;
readonly stored: Boolean;
readonly traceId: optionalKey<String>;
readonly trigger: Literals<readonly ["watch", "get", "prefetch", "visibility", "connectivity", "interval", "invalidation", "loadMore", "reset"]>;
readonly watcher: optionalKey<String>;
}>, TaggedStruct<"Waiting", {
readonly at: Number;
readonly boundary: optionalKey<Number>;
readonly causedBy: optionalKey<Number>;
readonly component: String;
readonly excluded: optionalKey<Boolean>;
readonly instance: Number;
readonly model: Codec<Json, Json, never, never>;
readonly path: String;
readonly props: Codec<Json, Json, never, never>;
readonly queries: optionalKey<Codec<Json, Json, never, never>>;
readonly seq: Number;
readonly session: String;
}>, TaggedStruct<"Mounted", {
readonly adopted: Boolean;
readonly at: Number;
readonly boundary: optionalKey<Number>;
readonly causedBy: optionalKey<Number>;
readonly commands: $Array<Struct<{
readonly _tag: Literals<readonly ["Effect", "Stream", "Interrupt"]>;
readonly args: Codec<Json, Json, never, never>;
readonly group: NullOr<String>;
readonly name: String;
}>>;
readonly component: String;
readonly events: $Array<Codec<Json, Json, never, never>>;
readonly excluded: optionalKey<Boolean>;
readonly instance: Number;
readonly model: Codec<Json, Json, never, never>;
readonly path: String;
readonly props: Codec<Json, Json, never, never>;
readonly queries: optionalKey<Codec<Json, Json, never, never>>;
readonly seq: Number;
readonly session: String;
}>, TaggedStruct<"Update", {
readonly at: Number;
readonly boundary: optionalKey<Number>;
readonly causedBy: optionalKey<Number>;
readonly collected: optionalKey<Codec<Json, Json, never, never>>;
readonly commands: $Array<Struct<{
readonly _tag: Literals<readonly ["Effect", "Stream", "Interrupt"]>;
readonly args: Codec<Json, Json, never, never>;
readonly group: NullOr<String>;
readonly name: String;
}>>;
readonly component: String;
readonly events: $Array<Codec<Json, Json, never, never>>;
readonly excluded: optionalKey<Boolean>;
readonly instance: Number;
readonly lists: $Array<Struct<{
readonly name: String;
readonly op: Literals<readonly ["loadMore", "reset"]>;
}>>;
readonly message: Codec<Json, Json, never, never>;
readonly model: Codec<Json, Json, never, never>;
readonly path: String;
readonly props: Codec<Json, Json, never, never>;
readonly queries: optionalKey<Codec<Json, Json, never, never>>;
readonly sends: $Array<Struct<{
readonly message: Codec<Json, Json, never, never>;
readonly owner: String;
}>>;
readonly seq: Number;
readonly session: String;
readonly shared: optionalKey<Codec<Json, Json, never, never>>;
readonly source: Union<readonly [TaggedStruct<"DomEvent", {
readonly name: String;
}>, TaggedStruct<"Command", {
readonly issued: Struct<{
readonly index: Number;
readonly seq: Number;
}>;
readonly name: String;
readonly spanId: NullOr<String>;
readonly traceId: NullOr<String>;
}>, TaggedStruct<"Subscription", {
deps: NullOr<$Array<Codec<..., ..., ..., ...>>>;
key: String;
name: String;
}>, TaggedStruct<"Query", {
readonly name: String;
readonly seq: Number;
}>, TaggedStruct<"Emit", {
readonly path: String;
readonly seq: Number;
}>, TaggedStruct<"Failure", {
readonly path: String;
readonly seq: Number;
}>, TaggedStruct<"Send", {
readonly path: String;
readonly seq: Number;
}>, TaggedStruct<"Shared", {
readonly name: String;
readonly path: String;
readonly seq: Number;
}>, TaggedStruct<"Collected", {}>, TaggedStruct<"Mount", {
readonly args: Codec<Json, Json, never, never>;
readonly name: String;
readonly seq: Number;
}>, TaggedStruct<"Dispatch", {}>]>;
readonly viewTransition: optionalKey<$Array<String>>;
}>, TaggedStruct<"PropsChanged", {
readonly at: Number;
readonly causedBy: optionalKey<Number>;
readonly component: String;
readonly excluded: optionalKey<Boolean>;
readonly instance: Number;
readonly path: String;
readonly props: Codec<Json, Json, never, never>;
readonly seq: Number;
readonly session: String;
}>, TaggedStruct<"QueryChanged", {
readonly at: Number;
readonly causedBy: optionalKey<Number>;
readonly component: String;
readonly excluded: optionalKey<Boolean>;
readonly instance: Number;
readonly name: String;
readonly path: String;
readonly result: Codec<Json, Json, never, never>;
readonly seq: Number;
readonly session: String;
}>, TaggedStruct<"LayerPending", {
readonly at: Number;
readonly causedBy: optionalKey<Number>;
readonly component: String;
readonly excluded: optionalKey<Boolean>;
readonly instance: Number;
readonly path: String;
readonly seq: Number;
readonly session: String;
readonly status: optionalKey<Literals<readonly ["Pending", "Rebuilding", "Awaiting"]>>;
}>, TaggedStruct<"LayerReady", {
at: Number;
causedBy: optionalKey<Number>;
component: String;
excluded: optionalKey<Boolean>;
instance: Number;
path: String;
seq: Number;
session: String;
}>, TaggedStruct<"LayerFailed", {
readonly at: Number;
readonly cause: Struct<{
readonly pretty: String;
readonly reasons: $Array<Codec<Json, Json, never, never>>;
}>;
readonly causedBy: optionalKey<Number>;
readonly component: String;
readonly excluded: optionalKey<Boolean>;
readonly instance: Number;
readonly path: String;
readonly redacted: optionalKey<Boolean>;
readonly seq: Number;
readonly session: String;
}>, TaggedStruct<"Failed", {
readonly at: Number;
readonly cause: Struct<{
readonly pretty: String;
readonly reasons: $Array<Codec<Json, Json, never, never>>;
}>;
readonly causedBy: optionalKey<Number>;
readonly component: String;
readonly excluded: optionalKey<Boolean>;
readonly in: String;
readonly instance: Number;
readonly issued: optionalKey<Struct<{
readonly index: Number;
readonly seq: Number;
}>>;
readonly name: NullOr<String>;
readonly path: String;
readonly props: Codec<Json, Json, never, never>;
readonly seq: Number;
readonly session: String;
readonly update: optionalKey<Struct<{
readonly message: Codec<Json, Json, never, never>;
readonly source: Union<readonly [TaggedStruct<"DomEvent", {
readonly name: ...;
}>, TaggedStruct<"Command", {
readonly issued: ...;
readonly name: ...;
readonly spanId: ...;
readonly traceId: ...;
}>, TaggedStruct<"Subscription", {
deps: ...;
key: ...;
name: ...;
}>, TaggedStruct<"Query", {
readonly name: ...;
readonly seq: ...;
}>, TaggedStruct<"Emit", {
readonly path: ...;
readonly seq: ...;
}>, TaggedStruct<"Failure", {
readonly path: ...;
readonly seq: ...;
}>, TaggedStruct<"Send", {
readonly path: ...;
readonly seq: ...;
}>, TaggedStruct<"Shared", {
readonly name: ...;
readonly path: ...;
readonly seq: ...;
}>, TaggedStruct<"Collected", {}>, TaggedStruct<"Mount", {
readonly args: ...;
readonly name: ...;
readonly seq: ...;
}>, TaggedStruct<"Dispatch", {}>]>;
}>>;
}>, TaggedStruct<"Unmounted", {
at: Number;
causedBy: optionalKey<Number>;
component: String;
excluded: optionalKey<Boolean>;
instance: Number;
path: String;
seq: Number;
session: String;
}>, TaggedStruct<"Unplaced", {
at: Number;
causedBy: optionalKey<Number>;
component: String;
excluded: optionalKey<Boolean>;
instance: Number;
path: String;
seq: Number;
session: String;
}>, TaggedStruct<"Placed", {
at: Number;
causedBy: optionalKey<Number>;
component: String;
excluded: optionalKey<Boolean>;
instance: Number;
path: String;
seq: Number;
session: String;
}>, TaggedStruct<"MountStarted", {
readonly args: Codec<Json, Json, never, never>;
readonly at: Number;
readonly causedBy: optionalKey<Number>;
readonly component: String;
readonly excluded: optionalKey<Boolean>;
readonly instance: Number;
readonly name: String;
readonly path: String;
readonly seq: Number;
readonly session: String;
}>, TaggedStruct<"MountEnded", {
readonly at: Number;
readonly causedBy: optionalKey<Number>;
readonly component: String;
readonly excluded: optionalKey<Boolean>;
readonly instance: Number;
readonly name: String;
readonly path: String;
readonly reason: Literals<readonly ["completed", "closed", "failed"]>;
readonly seq: Number;
readonly session: String;
readonly silent: Boolean;
readonly started: Number;
}>, TaggedStruct<"CommandStarted", {
readonly at: Number;
readonly causedBy: optionalKey<Number>;
readonly component: String;
readonly excluded: optionalKey<Boolean>;
readonly instance: Number;
readonly issued: Struct<{
readonly index: Number;
readonly seq: Number;
}>;
readonly name: String;
readonly parentSpanId: optionalKey<String>;
readonly path: String;
readonly seq: Number;
readonly session: String;
readonly spanId: String;
readonly traceId: String;
}>, TaggedStruct<"CommandAwaiting", {
readonly at: Number;
readonly causedBy: optionalKey<Number>;
readonly component: String;
readonly entries: $Array<Struct<{
readonly logKey: String;
readonly query: String;
}>>;
readonly excluded: optionalKey<Boolean>;
readonly instance: Number;
readonly issued: Struct<{
readonly index: Number;
readonly seq: Number;
}>;
readonly name: String;
readonly path: String;
readonly seq: Number;
readonly session: String;
}>, TaggedStruct<"CommandEnded", {
readonly at: Number;
readonly causedBy: optionalKey<Number>;
readonly component: String;
readonly excluded: optionalKey<Boolean>;
readonly instance: Number;
readonly issued: Struct<{
readonly index: Number;
readonly seq: Number;
}>;
readonly name: String;
readonly outstanding: optionalKey<$Array<Struct<{
readonly logKey: String;
readonly query: String;
}>>>;
readonly path: String;
readonly seq: Number;
readonly session: String;
readonly silent: Boolean;
readonly spanId: NullOr<String>;
readonly traceId: NullOr<String>;
readonly waitEnded: optionalKey<Literals<readonly ["settled", "nothing", "budget", "switch", "interrupt", "closed"]>>;
}>, TaggedStruct<"CommandInterrupted", {
readonly at: Number;
readonly causedBy: optionalKey<Number>;
readonly component: String;
readonly excluded: optionalKey<Boolean>;
readonly instance: Number;
readonly issued: Struct<{
readonly index: Number;
readonly seq: Number;
}>;
readonly name: String;
readonly path: String;
readonly reason: Literals<readonly ["interrupt", "switch", "unmount", "layer", "self"]>;
readonly seq: Number;
readonly session: String;
readonly spanId: NullOr<String>;
readonly traceId: NullOr<String>;
}>, TaggedStruct<"CommandDropped", {
readonly at: Number;
readonly causedBy: optionalKey<Number>;
readonly component: String;
readonly excluded: optionalKey<Boolean>;
readonly instance: Number;
readonly issued: Struct<{
readonly index: Number;
readonly seq: Number;
}>;
readonly name: String;
readonly path: String;
readonly reason: Literal<"server">;
readonly seq: Number;
readonly session: String;
}>, TaggedStruct<"SendDropped", {
readonly at: Number;
readonly causedBy: optionalKey<Number>;
readonly component: String;
readonly excluded: optionalKey<Boolean>;
readonly instance: Number;
readonly issued: Struct<{
readonly index: Number;
readonly seq: Number;
}>;
readonly owner: String;
readonly path: String;
readonly seq: Number;
readonly session: String;
}>, TaggedStruct<"SubscriptionStarted", {
readonly at: Number;
readonly causedBy: optionalKey<Number>;
readonly component: String;
readonly deps: NullOr<$Array<Codec<Json, Json, never, never>>>;
readonly excluded: optionalKey<Boolean>;
readonly instance: Number;
readonly key: String;
readonly name: String;
readonly path: String;
readonly seq: Number;
readonly session: String;
}>, TaggedStruct<"SubscriptionStopped", {
readonly at: Number;
readonly causedBy: optionalKey<Number>;
readonly component: String;
readonly deps: NullOr<$Array<Codec<Json, Json, never, never>>>;
readonly excluded: optionalKey<Boolean>;
readonly instance: Number;
readonly key: String;
readonly name: String;
readonly path: String;
readonly seq: Number;
readonly session: String;
}>]>

Wire

type unstable
Since v4.2.0

One frame of the Wire.

Signature

type Wire = typeof Wire.Type

WireEntry

type unstable
Since v4.2.0

The Wire's form of an entry, without the Hello frame.

Signature

type WireEntry = Exclude<Wire, {
readonly _tag: "Hello";
}>

WireHost

type unstable
Since v4.2.0

Where a log comes from, as Hello reports it.

Signature

type WireHost = typeof WireHost.Type

wireVersion

unstable
Since v4.2.0

The Wire format's version, sent in every Hello frame.

Signature

declare const wireVersion: 2