/** * A decoded protocol event, discriminated on `kind`. * * The union collapses the two-layer Engine.IO/Socket.IO wire format into the handful of events the log client actually reacts to: the Engine.IO handshake (`open`) and * heartbeat (`ping`/`pong`), and the Socket.IO namespace lifecycle (`namespaceConnect`/`namespaceError`) and payload delivery (`message`). Any unrecognized string * frame the codec does not model - an empty frame, an unknown Engine.IO digit, or an unhandled Socket.IO packet type - decodes to `unknown` carrying the original text, * so a consumer can log it without the codec having to model every Engine.IO/Socket.IO packet type that the log stream never exercises. * * @category Log Client */ export type ProtocolEvent = { readonly kind: "message"; readonly event: string; readonly namespace: string; readonly payload: unknown; } | { readonly kind: "namespaceConnect"; readonly namespace: string; } | { readonly kind: "namespaceError"; readonly namespace: string; readonly reason: unknown; } | { readonly kind: "open"; readonly pingInterval: number; readonly pingTimeout: number; } | { readonly kind: "ping"; } | { readonly kind: "pong"; } | { readonly kind: "unknown"; readonly raw: string; }; /** * An outbound protocol event to serialize, discriminated on `kind`. * * The OutboundEvent union models three frame shapes: a namespace connect (`connect`), a namespace event with a JSON payload (`event` - this is how `tail-log` is * requested), and a heartbeat pong (`pong`). A fourth outbound frame, the namespace DISCONNECT, is hand-assembled separately (see {@link LOG_NAMESPACE_PATH}) because its * fixed, argument-free shape needs no serialization through this codec. Modeling the outbound set as its own narrow union keeps {@link encodeFrame} total over exactly * what it models, rather than re-using the wider inbound {@link ProtocolEvent} and leaving unserializable arms. * * @category Log Client */ export type OutboundEvent = { readonly args: unknown; readonly event: string; readonly kind: "event"; readonly namespace: string; } | { readonly kind: "connect"; readonly namespace: string; } | { readonly kind: "pong"; }; /** * Serialize an outbound protocol event to its Engine.IO/Socket.IO wire text. * * Always emits EIO4-shaped frames: a namespace connect is `40`, an event is `42[event,args]`, and a pong is the bare Engine.IO `"3"`. The event * payload is `JSON.stringify`d as the `[eventName, args]` array the Socket.IO EVENT format requires. * * @param event - The outbound event to serialize. See {@link OutboundEvent}. * * @returns The wire text to send as a single WebSocket message. * * @category Log Client */ export declare function encodeFrame(event: OutboundEvent): string; /** * Decode a single inbound WebSocket frame into a {@link ProtocolEvent}. * * The decoder peels the leading Engine.IO packet-type digit and dispatches: `0` is the handshake open (whose JSON carries the ping interval/timeout), `2`/`3` are the * heartbeat, and `4` is a message whose remaining text is a Socket.IO packet decoded by the inner namespace/event parser. Its input is typed `string` - the composing * socket drops binary frames before they reach the decoder - so any unrecognized STRING frame (an empty frame, an unknown Engine.IO digit, or an unhandled Socket.IO * packet type) decodes to `unknown` carrying the original text. * * @param frame - The raw WebSocket message text. * * @returns The decoded protocol event. * * @category Log Client */ export declare function decodeFrame(frame: string): ProtocolEvent; /** * The Socket.IO namespace, with its leading slash, that the log stream is served on. The wire format addresses namespaces with a leading slash (`/log`), whereas the * `LOG_NAMESPACE` setting holds the bare name (`log`). This constant supplies the slash-prefixed namespace token used to hand-assemble the raw Socket.IO disconnect frame * (`"41/log,"`), where {@link encodeFrame} is bypassed. It must NOT be passed to `encodeFrame`: that codec's connect and event arms take the bare `LOG_NAMESPACE` and * derive the leading slash themselves, so handing them `LOG_NAMESPACE_PATH` would prepend a second slash and emit a malformed `"//log,"` prefix. * * @category Log Client */ export declare const LOG_NAMESPACE_PATH: string; //# sourceMappingURL=frame.d.ts.map