From e6b7f021661a1c81949f9f4dd915d30191816916 Mon Sep 17 00:00:00 2001 From: Tiara Rodney Date: Fri, 13 Mar 2026 23:29:09 +0100 Subject: [PATCH] feat(helper/stream): add browser-compatible Writable interface Define Writable interface, ConsoleWritable (console.log), and StderrWritable (console.error) as browser-safe stream abstractions. Export DEFAULT_STREAM backed by StderrWritable to match Python's sys.stderr default. --- src/helper/stream.ts | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/helper/stream.ts b/src/helper/stream.ts index 297e20c..4102cf4 100644 --- a/src/helper/stream.ts +++ b/src/helper/stream.ts @@ -1,2 +1,33 @@ +/** + * Minimal writable stream interface for browser compatibility. + * + * This abstracts over Node.js streams and browser console output, + * providing a common write target for handlers. + */ +export interface Writable { + write(data: string): void; +} -export type MillisecondsSinceUnixEpoch = number; +/** + * A Writable backed by console.log. + */ +export class ConsoleWritable implements Writable { + write(data: string): void { + console.log(data); + } +} + +/** + * A Writable backed by console.error (stderr equivalent). + */ +export class StderrWritable implements Writable { + write(data: string): void { + console.error(data); + } +} + +/** + * Default output stream. Uses console.error to match Python's default + * of writing to sys.stderr. + */ +export const DEFAULT_STREAM: Writable = new StderrWritable();