import { ANSI, type Callable, type IMetric, type ITraceableMapper, type ITraceableTuple, type MetricsTraceSupplier, } from "@emprespresso/pengueno"; export class TraceUtil { static withTrace( trace: string, ansi?: Array ): ITraceableMapper>, Trace> { if (ansi) { return (t) => [t.get(), `${ansi.join("")}${trace}${ANSI.RESET}`]; } return (t) => [t.get(), trace]; } static withMetricTrace( metric: IMetric, ): ITraceableMapper>, Trace> { return (t) => [t.get(), metric as Trace]; } static withFunctionTrace( f: F, ): ITraceableMapper>, Trace> { return TraceUtil.withTrace(`fn.${f.name}`); } static withClassTrace( c: C, ): ITraceableMapper>, Trace> { return TraceUtil.withTrace(`class.${c.constructor.name}`); } static promiseify( mapper: ITraceableMapper, ): ITraceableMapper, Promise, Trace> { return (traceablePromise) => traceablePromise .flatMapAsync(async (t) => t.move(await t.get()).map(mapper)) .get(); } }