wpilog-parser 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -5
- package/dist/catalog-CYDrFwrh.mjs +1071 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +71 -0
- package/dist/index.d.mts +4 -2
- package/dist/index.mjs +1 -1069
- package/package.json +16 -17
- package/skills/analyze-wpilog/SKILL.md +7 -18
package/dist/cli.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { a as readRecords, t as catalogEntries } from "./catalog-CYDrFwrh.mjs";
|
|
3
|
+
import { cac } from "cac";
|
|
4
|
+
import { readFile } from "node:fs/promises";
|
|
5
|
+
import { encode } from "@toon-format/toon";
|
|
6
|
+
//#region package.json
|
|
7
|
+
var version = "2.3.0";
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/cli/catalog.ts
|
|
10
|
+
async function catalogFile(filePath) {
|
|
11
|
+
let bytes;
|
|
12
|
+
try {
|
|
13
|
+
bytes = await readFile(filePath);
|
|
14
|
+
} catch (error) {
|
|
15
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") throw new Error(`File not found: ${"path" in error ? String(error.path) : "unknown path"}`, { cause: error });
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
return Array.from(catalogEntries(readRecords(bytes)));
|
|
19
|
+
}
|
|
20
|
+
function selectCatalogFormat(options) {
|
|
21
|
+
const selected = [
|
|
22
|
+
options.json && "json",
|
|
23
|
+
(options.jsonl || options.ndjson) && "jsonl",
|
|
24
|
+
options.csv && "csv"
|
|
25
|
+
].filter((format) => Boolean(format));
|
|
26
|
+
if (selected.length > 1) throw new TypeError("Output flags cannot be combined");
|
|
27
|
+
return selected[0] ?? "toon";
|
|
28
|
+
}
|
|
29
|
+
function escapeCsv(value) {
|
|
30
|
+
const text = String(value);
|
|
31
|
+
if (/[",\r\n]/.test(text)) return `"${text.replaceAll("\"", "\"\"")}"`;
|
|
32
|
+
return text;
|
|
33
|
+
}
|
|
34
|
+
/** Serialize catalog entries in the selected output format. */
|
|
35
|
+
function formatCatalog(entries, format = "toon") {
|
|
36
|
+
switch (format) {
|
|
37
|
+
case "toon": return encode(entries);
|
|
38
|
+
case "json": return JSON.stringify(entries, null, 2);
|
|
39
|
+
case "jsonl":
|
|
40
|
+
case "ndjson": return entries.map((entry) => JSON.stringify(entry)).join("\n");
|
|
41
|
+
case "csv": return ["entryId,name,type,metadata", ...entries.map((entry) => [
|
|
42
|
+
entry.entryId,
|
|
43
|
+
entry.name,
|
|
44
|
+
entry.type,
|
|
45
|
+
entry.metadata
|
|
46
|
+
].map((value) => escapeCsv(value)).join(","))].join("\n");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/cli.ts
|
|
51
|
+
const cli = cac("wpilog");
|
|
52
|
+
cli.command("catalog <file>", "List the entries available in a WPILOG file").option("--json", "Output as JSON").option("--jsonl, --ndjson", "Output as newline-delimited JSON").option("--csv", "Output as CSV").example("wpilog catalog ./example.wpilog").example("wpilog catalog ./example.wpilog --json").action(async (file, options) => {
|
|
53
|
+
const format = selectCatalogFormat(options);
|
|
54
|
+
const entries = await catalogFile(file);
|
|
55
|
+
console.log(formatCatalog(entries, format));
|
|
56
|
+
});
|
|
57
|
+
cli.help();
|
|
58
|
+
cli.version(version);
|
|
59
|
+
try {
|
|
60
|
+
const parsed = cli.parse(process.argv, { run: true });
|
|
61
|
+
if (!cli.matchedCommand && !parsed.options.help && !parsed.options.version) {
|
|
62
|
+
if (parsed.args[0]) throw new RangeError(`Unknown command \`${parsed.args[0]}\``);
|
|
63
|
+
cli.outputHelp();
|
|
64
|
+
}
|
|
65
|
+
} catch (error) {
|
|
66
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
67
|
+
console.error(`wpilog: ${message}`);
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export {};
|
package/dist/index.d.mts
CHANGED
|
@@ -36,7 +36,8 @@ type SetMetadataControlRecord = {
|
|
|
36
36
|
type ControlRecordPayload = StartControlRecord | FinishControlRecord | SetMetadataControlRecord;
|
|
37
37
|
/** A raw (undecoded) data log record from the binary format. */
|
|
38
38
|
type RawRecord = {
|
|
39
|
-
entryId: number;
|
|
39
|
+
entryId: number;
|
|
40
|
+
/** Timestamp in microseconds. */
|
|
40
41
|
timestamp: bigint;
|
|
41
42
|
payload: Uint8Array;
|
|
42
43
|
};
|
|
@@ -71,7 +72,8 @@ type ControlRecord = Extract<DecodedRecord, {
|
|
|
71
72
|
declare function isDataRecord(record: DecodedRecord): record is DataRecord;
|
|
72
73
|
/** A decoded data log record. */
|
|
73
74
|
type DecodedRecord = {
|
|
74
|
-
entryId: number;
|
|
75
|
+
entryId: number;
|
|
76
|
+
/** Timestamp in microseconds. */
|
|
75
77
|
timestamp: bigint;
|
|
76
78
|
} & ({
|
|
77
79
|
type: RecordType.Control;
|