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.
This commit is contained in:
Tiara Rodney 2026-03-13 23:29:09 +01:00
parent c297bb4499
commit e6b7f02166
No known key found for this signature in database
GPG key ID: 5CD8EC1D46106723

View file

@ -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();