/** * Wire format for records written to `current-N.jsonl` and sealed segment files. * * One JSON object per line, terminated by `\n`. Producer encodes; consumer * decodes. Two categories of frame appear on the wire: * * 1. **Data frames** — a user record that `Producer.send()` published, with a * broker-assigned offset and a producer-stamped timestamp. * 2. **Sentinel frames** — `_seal` and `_open` markers the producer writes at * generation boundaries. These bracket a `current-N.jsonl` so a consumer * streaming the bytes can tell when a generation closes without having to * consult `.index.jsonl` first. The authoritative linearization is still * `.index.jsonl`; the sentinels are defensive in-band markers. `_commit` * and `_abort` end a multi-block batch (ADR-0030). * * The sentinel keys (`_seal`, `_open`) are reserved — user records cannot * publish a top-level `_seal` or `_open` key (the producer rejects with * `ReservedFieldError`). * * Offset wire convention: offsets are conceptually unbounded counters and are * typed `bigint` in TypeScript. On the JSON wire they are encoded as decimal * strings — `JSON.stringify` of a BigInt throws, and serialising as a number * would lose precision past 2^53. Decoders parse the string back to `BigInt`. */ /** What a caller publishes via `Producer.send()`. */ export type UserRecord = { /** Caller-supplied identifier; opaque to the broker. */ readonly id: string; /** * Opaque record body. The broker treats it as a UTF-8 string and round-trips * it through JSON. Binary payloads should be base64-encoded by the caller. */ readonly body: string; }; /** A user record as it appears on the wire — with broker-assigned offset and timestamp. */ export type DataFrame = { readonly offset: bigint; readonly id: string; readonly body: string; /** Producer-stamped ISO 8601 timestamp. */ readonly ts: string; /** Batch id, on every frame written by `openBatch` or `sendBatch` (ADR-0030). */ readonly b?: string; /** Marks the first frame of a multi-block batch, which readers hold until its `_commit`. */ readonly bm?: true; }; /** * `_seal` sentinel — written by the producer as the last byte sequence of a * `current-N.jsonl` before opening `current-(N+1).jsonl`. Consumers crossing * this frame know the generation is closed. */ export type SealFrame = { readonly _seal: true; readonly gen: number; readonly end_offset: bigint; readonly at: string; /** Set when the generation holds a multi-block batch or a stale seal, so the compactor rewrites its archive (ADR-0030). */ readonly has_batch_markers?: true; }; /** * `_open` sentinel — the first frame written to a freshly created * `current-(N+1).jsonl`. Consumers seeing this frame at byte 0 know they have * correctly arrived at the new generation. */ export type OpenFrame = { readonly _open: true; readonly gen: number; readonly start_offset: bigint; readonly at: string; }; /** `_commit` sentinel — ends the last block of a multi-block batch (ADR-0030). */ export type CommitFrame = { readonly _commit: true; readonly gen: number; readonly batch: string; readonly first_offset: bigint; readonly last_offset: bigint; readonly count: number; }; /** `_abort` sentinel — written after a multi-block batch that will never commit (ADR-0030). */ export type AbortFrame = { readonly _abort: true; readonly gen: number; readonly batch: string; readonly first_offset: bigint; readonly last_offset: bigint; }; export type BatchMarkerFrame = CommitFrame | AbortFrame; export type Frame = DataFrame | SealFrame | OpenFrame | BatchMarkerFrame; /** Thrown by the producer when a caller's `UserRecord` collides with a reserved field. */ export declare class ReservedFieldError extends Error { readonly field: string; constructor(field: string); } /** Thrown by the consumer when a frame line fails to parse or is structurally invalid. */ export declare class PoisonFrameError extends Error { readonly rawLine: string; readonly byteOffset: number; readonly cause: unknown; constructor(rawLine: string, byteOffset: number, cause: unknown); } /** * Encode a frame as a single JSON line. BigInt offsets are stringified as * decimal digits (see file header for the convention). No trailing newline — * the caller joins frames with `\n`. */ export declare function encodeFrame(frame: Frame): string; /** * Decode a single JSON line into a typed `Frame`. Throws `PoisonFrameError` * if the line does not parse as JSON, or parses but does not match any frame * shape. The consumer catches `PoisonFrameError`, writes the raw bytes to * `.dead-letter/gen-NNNNNN-byte-BBBBBBBBBB.bin`, and skips past. */ export declare function decodeFrame(line: string, byteOffset: number): Frame; export declare function isDataFrame(frame: Frame): frame is DataFrame; export declare function isSealFrame(frame: Frame): frame is SealFrame; export declare function isOpenFrame(frame: Frame): frame is OpenFrame; export declare function isCommitFrame(frame: Frame): frame is CommitFrame; export declare function isAbortFrame(frame: Frame): frame is AbortFrame; /** * Validate a caller-supplied `UserRecord` for reserved-field collisions. Called * by `Producer.send()` before enqueueing. Returns the record unchanged on pass. */ export declare function assertNoReservedFields(record: UserRecord): UserRecord; //# sourceMappingURL=frame.d.ts.map