2023-03-24 19:36:11 +00:00
|
|
|
import { readLines } from './deps.ts';
|
|
|
|
|
2023-03-24 21:08:36 +00:00
|
|
|
import type { InputMessage, OutputMessage } from './types.ts';
|
2023-03-24 19:36:11 +00:00
|
|
|
|
|
|
|
/**
|
2023-03-25 16:38:27 +00:00
|
|
|
* Parse strfy messages from stdin.
|
|
|
|
* strfry may batch multiple messages at once.
|
2023-03-24 19:36:11 +00:00
|
|
|
*/
|
2023-03-25 16:38:27 +00:00
|
|
|
async function* readStdin(): AsyncGenerator<InputMessage> {
|
|
|
|
for await (const line of readLines(Deno.stdin)) {
|
|
|
|
yield JSON.parse(line);
|
|
|
|
}
|
2023-03-24 19:36:11 +00:00
|
|
|
}
|
|
|
|
|
2023-03-24 21:08:36 +00:00
|
|
|
/** Writes the output message to stdout. */
|
|
|
|
function writeStdout(msg: OutputMessage): void {
|
|
|
|
console.log(JSON.stringify(msg));
|
|
|
|
}
|
|
|
|
|
|
|
|
export { readStdin, writeStdout };
|