//#region src/drivers/patchPgProtocol.d.ts /** * Patches pg-protocol at runtime so that DataRow messages are lazy *and* their bytes are * immutable, i.e. so `WireRowData` can retain raw row payloads by reference — no per-cell * strings, no per-row copies, no arena. * * We patch at runtime (instead of shipping a patched pg-protocol) so that installing joist-orm * requires no package-manager patch steps; see JS-ROW-STORE-DESIGN.md "Distribution". Two * prototype methods are replaced, porting brianc/node-postgres#3719 (which may or may not ever * land upstream — this patch is how we run its design in production regardless): * * - `handlePacket` (stable across pg-protocol 1.10-1.15) returns a {@link LazyDataRowMessage} * for DataRow packets and delegates every other message type to the original. * - `parse` replaces the recycled-scratch buffer management: each socket chunk is parsed *in * place*, and only the one message per chunk that straddles a read boundary is reassembled * into a buffer of its own, which is handed to that message and never touched again. Every * message therefore stays valid for as long as it is held (holding one pins the ~64 KiB chunk * it came from) — versus stock pg-protocol, which copies whole chunks into a scratch buffer * and compacts it in place over the bytes earlier messages point into. * * The patch verifies itself by round-tripping synthetic DataRows through a fresh `Parser` — * including a message that straddles chunks, retained across later reads that would clobber it * under the stock buffer management. On any mismatch (i.e. a future pg-protocol internals * rewrite), it un-patches and reports failure so the driver can fall back to classic rows. * * The lazy message's memoized `fields` getter decodes identically to the original for classic * consumers, i.e. pg's own `Result.parseRow(msg.fields)`. */ declare function ensureLazyDataRows(): boolean; /** A drop-in `DataRowMessage` that defers cell decoding; lazy consumers read `bytes`/`offset`. */ declare class LazyDataRowMessage { #private; readonly length: number; /** The row's payload bytes; immutable under our `parse` patch, so safe to retain. */ readonly bytes: Buffer; readonly offset: number; readonly name = "dataRow"; readonly fieldCount: number; constructor(length: number, /** The row's payload bytes; immutable under our `parse` patch, so safe to retain. */ bytes: Buffer, offset: number); /** Lazily materializes the per-cell strings for classic consumers, i.e. pg's `Result.parseRow`. */ get fields(): (string | null)[]; } //#endregion export { LazyDataRowMessage, ensureLazyDataRows }; //# sourceMappingURL=patchPgProtocol.d.mts.map