1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
import {
type Callable,
type ITraceableMapper,
type ITraceableTuple,
LoggerImpl,
LogTrace,
type LogTraceSupplier,
TraceableImpl,
} from "@emprespresso/pengueno";
export class LogTraceable<T> extends TraceableImpl<T, LogTraceSupplier> {
static from<T>(t: T) {
return new LogTraceable(t, LogTrace(LoggerImpl));
}
}
export class TraceUtil {
static withFunctionTrace<F extends Callable, T, Trace>(
f: F,
): ITraceableMapper<
T,
ITraceableTuple<T, Trace>,
Trace
> {
return (t) => [t.item, `[${f.name}]`];
}
static withClassTrace<C extends object, T, Trace>(
c: C,
): ITraceableMapper<
T,
ITraceableTuple<T, Trace>,
Trace
> {
return (t) => [t.item, `[${c.constructor.name}]`];
}
static promiseify<T, U, Trace>(
mapper: ITraceableMapper<T, U, Trace>,
): ITraceableMapper<Promise<T>, Promise<U>, Trace> {
return (traceablePromise) =>
traceablePromise.flatMapAsync(async (t) =>
t.move(await t.item).map(mapper)
).item;
}
}
|