-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathindex.ts
More file actions
70 lines (57 loc) · 1.72 KB
/
index.ts
File metadata and controls
70 lines (57 loc) · 1.72 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import {Nullable} from "../../../typings/common";
import {
Decoder,
DecodeResult,
FilteredLogEventMap,
LogEventCount,
Metadata,
} from "../../../typings/decoders";
class PlainTextDecoder implements Decoder {
#logs: string[];
constructor (dataArray: Uint8Array) {
const textDecoder = new TextDecoder();
this.#logs = textDecoder.decode(dataArray).split(/\r\n|\r|\n/);
}
static async create (dataArray: Uint8Array) {
return Promise.resolve(new PlainTextDecoder(dataArray));
}
getEstimatedNumEvents (): number {
return this.#logs.length;
}
// eslint-disable-next-line class-methods-use-this
getFilteredLogEventMap (): FilteredLogEventMap {
return null;
}
// eslint-disable-next-line class-methods-use-this
getMetadata (): Metadata {
return {};
}
// eslint-disable-next-line class-methods-use-this
setLogLevelFilter (): boolean {
return false;
}
build (): LogEventCount {
return {
numValidEvents: this.#logs.length,
numInvalidEvents: 0,
};
}
// eslint-disable-next-line class-methods-use-this
setFormatterOptions (): boolean {
return false;
}
decodeRange (beginIdx: number, endIdx: number): Nullable<DecodeResult[]> {
return this.#logs.slice(beginIdx, endIdx).map((log, i) => ({
logEventNum: beginIdx + i,
logLevel: 0,
message: `${log}\n`,
timestamp: BigInt(0),
utcOffset: BigInt(0),
}));
}
// eslint-disable-next-line class-methods-use-this
findNearestLogEventByTimestamp (): Nullable<number> {
return null;
}
}
export default PlainTextDecoder;