-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunique-slog-events.mjs
executable file
·39 lines (29 loc) · 1.01 KB
/
unique-slog-events.mjs
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
#! /usr/bin/env node
import { open } from "node:fs/promises";
import { createInterface } from "node:readline/promises";
const main = async () => {
const [, , slogFilePath] = process.argv;
if (!slogFilePath) throw Error("Missing slog file path");
const slogFileHandler = await open(slogFilePath, "r");
const readStream = slogFileHandler.createReadStream({
autoClose: false,
encoding: "utf-8",
});
const reader = createInterface({
crlfDelay: Infinity,
input: readStream,
});
reader.addListener("close", () => readStream.close());
readStream.addListener("close", () => slogFileHandler.close());
/** @type {Set<string>} */
const uniqueTypes = new Set();
for await (const data of reader) {
/** @type {string} */
const type = JSON.parse(data).type;
if (!type) console.error(`"type" key not present in slog ${data}`);
else uniqueTypes.add(type);
}
reader.close();
return Array.from(uniqueTypes);
};
main().then((slogEvents) => console.log(JSON.stringify(slogEvents)));