@electric-sql/d2mini
Version:
D2Mini is a minimal implementation of Differential Dataflow for performing in-memory incremental view maintenance.
36 lines • 1.31 kB
JavaScript
import { DifferenceStreamWriter, UnaryOperator, } from '../graph.js';
import { StreamBuilder } from '../d2.js';
/**
* Operator that logs debug information about the stream
*/
export class DebugOperator extends UnaryOperator {
#name;
#indent;
constructor(id, inputA, output, name, indent = false) {
super(id, inputA, output);
this.#name = name;
this.#indent = indent;
}
run() {
for (const message of this.inputMessages()) {
// eslint-disable-next-line no-console
console.log(`debug ${this.#name} data: ${message.toString(this.#indent)}`);
this.output.sendData(message);
}
}
}
/**
* Logs debug information about the stream using console.log
* @param name - The name to prefix debug messages with
* @param indent - Whether to indent the debug output
*/
export function debug(name, indent = false) {
return (stream) => {
const output = new StreamBuilder(stream.graph, new DifferenceStreamWriter());
const operator = new DebugOperator(stream.graph.getNextOperatorId(), stream.connectReader(), output.writer, name, indent);
stream.graph.addOperator(operator);
stream.graph.addStream(output.connectReader());
return output;
};
}
//# sourceMappingURL=debug.js.map