wpilog-parser 3.0.0 → 3.1.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 +16 -0
- package/dist/{catalog-AwcdBV3I.mjs → catalog-DstFMwwV.mjs} +16 -32
- package/dist/cli.mjs +14 -10
- package/dist/index.d.mts +0 -12
- package/dist/index.mjs +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -44,6 +44,22 @@ The default output is [TOON](https://toonformat.dev). JSON, JSONL/NDJSON, and CS
|
|
|
44
44
|
npx wpilog-parser catalog ./example.wpilog --json
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
+
`wpilog` includes shell completions via `wpilog complete`:
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
# zsh
|
|
51
|
+
source <(wpilog complete zsh)
|
|
52
|
+
|
|
53
|
+
# bash (requires bash 4+ and bash-completion)
|
|
54
|
+
source <(wpilog complete bash)
|
|
55
|
+
|
|
56
|
+
# fish
|
|
57
|
+
wpilog complete fish > ~/.config/fish/completions/wpilog.fish
|
|
58
|
+
|
|
59
|
+
# PowerShell
|
|
60
|
+
wpilog complete powershell | Out-String | Invoke-Expression
|
|
61
|
+
```
|
|
62
|
+
|
|
47
63
|
## Agent skill
|
|
48
64
|
|
|
49
65
|
This package ships an [Agent Skill](https://agentskills.io) at `skills/analyze-wpilog/SKILL.md` that teaches AI coding agents how to use the library.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineDiagnostics } from "nostics";
|
|
2
2
|
import { CstParser, Lexer, createToken } from "chevrotain";
|
|
3
|
-
|
|
3
|
+
// src/byte-offset.ts
|
|
4
4
|
var ByteOffset = class {
|
|
5
5
|
offset;
|
|
6
6
|
constructor(offset = 0) {
|
|
@@ -26,8 +26,7 @@ var ByteOffset = class {
|
|
|
26
26
|
return this.advance(8);
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
|
-
|
|
30
|
-
//#region src/diagnostics.ts
|
|
29
|
+
// src/diagnostics.ts
|
|
31
30
|
/** Stable codes for errors callers can act on. */
|
|
32
31
|
const diagnostics = defineDiagnostics({ codes: {
|
|
33
32
|
WPILOG_C0001: {
|
|
@@ -95,8 +94,7 @@ const diagnostics = defineDiagnostics({ codes: {
|
|
|
95
94
|
fix: "Register the struct definition before decoding its records."
|
|
96
95
|
}
|
|
97
96
|
} });
|
|
98
|
-
|
|
99
|
-
//#region src/types.ts
|
|
97
|
+
// src/types.ts
|
|
100
98
|
/** Control record types in the WPILOG format. */
|
|
101
99
|
const ControlRecordType = {
|
|
102
100
|
Start: 0,
|
|
@@ -124,8 +122,7 @@ const RecordType = {
|
|
|
124
122
|
function isDataRecord(record) {
|
|
125
123
|
return record.type !== RecordType.Control;
|
|
126
124
|
}
|
|
127
|
-
|
|
128
|
-
//#region src/read-records.ts
|
|
125
|
+
// src/read-records.ts
|
|
129
126
|
const TEXT_ENCODER = new TextEncoder();
|
|
130
127
|
const TEXT_DECODER$1 = new TextDecoder();
|
|
131
128
|
const MAGIC = TEXT_ENCODER.encode("WPILOG");
|
|
@@ -341,8 +338,7 @@ function* readRecords(input) {
|
|
|
341
338
|
};
|
|
342
339
|
}
|
|
343
340
|
}
|
|
344
|
-
|
|
345
|
-
//#region src/struct/types.ts
|
|
341
|
+
// src/struct/types.ts
|
|
346
342
|
const KnownStructTypeName = {
|
|
347
343
|
Boolean: "bool",
|
|
348
344
|
Character: "char",
|
|
@@ -361,8 +357,7 @@ const KnownStructTypeName = {
|
|
|
361
357
|
/** Equivalent to {@link (KnownStructTypeName:variable).Float64} */
|
|
362
358
|
Double: "double"
|
|
363
359
|
};
|
|
364
|
-
|
|
365
|
-
//#region src/struct/struct-dependency-graph.ts
|
|
360
|
+
// src/struct/struct-dependency-graph.ts
|
|
366
361
|
const EMPTY_SET = /* @__PURE__ */ new Set();
|
|
367
362
|
var StructDependencyGraph = class {
|
|
368
363
|
allDependencies = new Map(Object.values(KnownStructTypeName).map((type) => [type, EMPTY_SET]));
|
|
@@ -406,8 +401,7 @@ var StructDependencyGraph = class {
|
|
|
406
401
|
return result;
|
|
407
402
|
}
|
|
408
403
|
};
|
|
409
|
-
|
|
410
|
-
//#region src/struct/struct-decode-queue.ts
|
|
404
|
+
// src/struct/struct-decode-queue.ts
|
|
411
405
|
var StructDecodeQueue = class {
|
|
412
406
|
graph = new StructDependencyGraph();
|
|
413
407
|
queuedRecords = /* @__PURE__ */ new Map();
|
|
@@ -434,8 +428,7 @@ var StructDecodeQueue = class {
|
|
|
434
428
|
}
|
|
435
429
|
}
|
|
436
430
|
};
|
|
437
|
-
|
|
438
|
-
//#region src/struct/bit-field.ts
|
|
431
|
+
// src/struct/bit-field.ts
|
|
439
432
|
var BitFieldTracker = class {
|
|
440
433
|
storageByteLength = 0;
|
|
441
434
|
bitShift = 0;
|
|
@@ -488,8 +481,7 @@ function isSignedInteger(type) {
|
|
|
488
481
|
default: return false;
|
|
489
482
|
}
|
|
490
483
|
}
|
|
491
|
-
|
|
492
|
-
//#region src/struct/compile-struct.ts
|
|
484
|
+
// src/struct/compile-struct.ts
|
|
493
485
|
const READERS = {
|
|
494
486
|
bool: {
|
|
495
487
|
method: "getUint8",
|
|
@@ -632,8 +624,7 @@ function compileStruct(registry, name) {
|
|
|
632
624
|
${sources.join("\n")}
|
|
633
625
|
return ${root};`)(new TextDecoder());
|
|
634
626
|
}
|
|
635
|
-
|
|
636
|
-
//#region src/struct/lexer.ts
|
|
627
|
+
// src/struct/lexer.ts
|
|
637
628
|
const Comma = createToken({
|
|
638
629
|
name: "Comma",
|
|
639
630
|
pattern: ","
|
|
@@ -697,8 +688,7 @@ const allTokens = [
|
|
|
697
688
|
Identifier
|
|
698
689
|
];
|
|
699
690
|
const lexer = new Lexer(allTokens);
|
|
700
|
-
|
|
701
|
-
//#region src/struct/parser.ts
|
|
691
|
+
// src/struct/parser.ts
|
|
702
692
|
var StructParser = class extends CstParser {
|
|
703
693
|
structSpecification = this.RULE("structSpecification", () => {
|
|
704
694
|
this.MANY_SEP({
|
|
@@ -762,8 +752,7 @@ var StructParser = class extends CstParser {
|
|
|
762
752
|
const parser = new StructParser();
|
|
763
753
|
parser.getBaseCstVisitorConstructor();
|
|
764
754
|
const BaseStructVisitorWithDefaults = parser.getBaseCstVisitorConstructorWithDefaults();
|
|
765
|
-
|
|
766
|
-
//#region src/struct/struct-ast-visitor.ts
|
|
755
|
+
// src/struct/struct-ast-visitor.ts
|
|
767
756
|
var StructAstVisitor = class extends BaseStructVisitorWithDefaults {
|
|
768
757
|
constructor() {
|
|
769
758
|
super();
|
|
@@ -860,8 +849,7 @@ var StructAstVisitor = class extends BaseStructVisitorWithDefaults {
|
|
|
860
849
|
return Number(value.image);
|
|
861
850
|
}
|
|
862
851
|
};
|
|
863
|
-
|
|
864
|
-
//#region src/struct/parse-struct.ts
|
|
852
|
+
// src/struct/parse-struct.ts
|
|
865
853
|
const structAstVisitor = new StructAstVisitor();
|
|
866
854
|
const cache = /* @__PURE__ */ new Map();
|
|
867
855
|
/** Parse a WPILib struct specification string into declarations. */
|
|
@@ -877,8 +865,7 @@ function parseStructSpecification(declaration) {
|
|
|
877
865
|
cache.set(declaration, created);
|
|
878
866
|
return created;
|
|
879
867
|
}
|
|
880
|
-
|
|
881
|
-
//#region src/struct/struct-registry.ts
|
|
868
|
+
// src/struct/struct-registry.ts
|
|
882
869
|
var StructRegistry = class StructRegistry {
|
|
883
870
|
static TEXT_DECODER = new TextDecoder("utf-8");
|
|
884
871
|
definitions = /* @__PURE__ */ new Map();
|
|
@@ -1198,8 +1185,7 @@ var StructRegistry = class StructRegistry {
|
|
|
1198
1185
|
return byteLengthForOne;
|
|
1199
1186
|
}
|
|
1200
1187
|
};
|
|
1201
|
-
|
|
1202
|
-
//#region src/decode-records.ts
|
|
1188
|
+
// src/decode-records.ts
|
|
1203
1189
|
const TEXT_DECODER = new TextDecoder();
|
|
1204
1190
|
const STRUCT_PREFIX = "struct:";
|
|
1205
1191
|
const STRUCT_ARRAY_SUFFIX = "[]";
|
|
@@ -1496,8 +1482,7 @@ function decodeNonScalarPayload(raw, entryType, name, metadata, view, structRegi
|
|
|
1496
1482
|
};
|
|
1497
1483
|
}
|
|
1498
1484
|
}
|
|
1499
|
-
|
|
1500
|
-
//#region src/catalog.ts
|
|
1485
|
+
// src/catalog.ts
|
|
1501
1486
|
/**
|
|
1502
1487
|
* Collect all entry definitions from a WPILOG record stream.
|
|
1503
1488
|
*
|
|
@@ -1525,5 +1510,4 @@ function* catalogEntries(records) {
|
|
|
1525
1510
|
}
|
|
1526
1511
|
}
|
|
1527
1512
|
}
|
|
1528
|
-
//#endregion
|
|
1529
1513
|
export { KnownStructTypeName as a, RecordType as c, parseStructSpecification as i, isDataRecord as l, decodeRecords as n, readRecords as o, parseDataLog as r, ControlRecordType as s, catalogEntries as t, diagnostics as u };
|
package/dist/cli.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { o as readRecords, t as catalogEntries, u as diagnostics } from "./catalog-
|
|
2
|
+
import { o as readRecords, t as catalogEntries, u as diagnostics } from "./catalog-DstFMwwV.mjs";
|
|
3
3
|
import { Diagnostic, formatDiagnostic } from "nostics";
|
|
4
|
+
import tab from "@bomb.sh/tab/cac";
|
|
4
5
|
import { cac } from "cac";
|
|
5
6
|
import oscStatus from "osc-status";
|
|
6
7
|
import { readFile } from "node:fs/promises";
|
|
7
8
|
import { encode } from "@toon-format/toon";
|
|
8
|
-
|
|
9
|
-
var version = "3.
|
|
10
|
-
|
|
11
|
-
//#region src/cli/catalog.ts
|
|
9
|
+
// package.json
|
|
10
|
+
var version = "3.1.0";
|
|
11
|
+
// src/cli/catalog.ts
|
|
12
12
|
async function catalogFile(filePath) {
|
|
13
13
|
let bytes;
|
|
14
14
|
try {
|
|
@@ -56,10 +56,9 @@ function formatCatalog(entries, format = "toon") {
|
|
|
56
56
|
].map((value) => escapeCsv(value)).join(","))].join("\n");
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
|
|
60
|
-
//#region src/cli.ts
|
|
59
|
+
// src/cli.ts
|
|
61
60
|
const cli = cac("wpilog");
|
|
62
|
-
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) => {
|
|
61
|
+
cli.command("catalog <file>", "List the entries available in a WPILOG file").option("--json", "Output as JSON").option("--jsonl", "Output as newline-delimited JSON").option("--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) => {
|
|
63
62
|
const format = selectCatalogFormat(options);
|
|
64
63
|
oscStatus.working({
|
|
65
64
|
app: "wpilog",
|
|
@@ -75,12 +74,18 @@ cli.command("catalog <file>", "List the entries available in a WPILOG file").opt
|
|
|
75
74
|
cli.help();
|
|
76
75
|
cli.version(version);
|
|
77
76
|
try {
|
|
77
|
+
await tab(cli);
|
|
78
|
+
const completeCommand = cli.commands.find((command) => command.name === "complete");
|
|
79
|
+
if (completeCommand) {
|
|
80
|
+
completeCommand.description = "Generate shell completion scripts";
|
|
81
|
+
completeCommand.usage("complete <zsh|bash|fish|powershell>").example("source <(wpilog complete zsh)").example("source <(wpilog complete bash)").example("wpilog complete fish > ~/.config/fish/completions/wpilog.fish").example("wpilog complete powershell | Out-String | Invoke-Expression");
|
|
82
|
+
}
|
|
78
83
|
const parsed = cli.parse(process.argv, { run: false });
|
|
79
|
-
await cli.runMatchedCommand();
|
|
80
84
|
if (!cli.matchedCommand && !parsed.options.help && !parsed.options.version) {
|
|
81
85
|
if (parsed.args[0]) throw diagnostics.WPILOG_C0001({ command: parsed.args[0] });
|
|
82
86
|
cli.outputHelp();
|
|
83
87
|
}
|
|
88
|
+
await cli.runMatchedCommand();
|
|
84
89
|
} catch (error) {
|
|
85
90
|
const message = error instanceof Diagnostic ? formatDiagnostic(error) : error instanceof Error ? error.message : String(error);
|
|
86
91
|
console.error(error instanceof Diagnostic ? message : `wpilog: ${message}`);
|
|
@@ -90,5 +95,4 @@ try {
|
|
|
90
95
|
message: "Command failed"
|
|
91
96
|
});
|
|
92
97
|
}
|
|
93
|
-
//#endregion
|
|
94
98
|
export {};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/types.d.ts
|
|
2
1
|
/** The parsed WPILOG file header. */
|
|
3
2
|
type DataLogHeader = {
|
|
4
3
|
version: {
|
|
@@ -127,8 +126,6 @@ type DecodedRecord = {
|
|
|
127
126
|
structName: string;
|
|
128
127
|
payload: StructPayload[];
|
|
129
128
|
})));
|
|
130
|
-
//#endregion
|
|
131
|
-
//#region src/read-records.d.ts
|
|
132
129
|
/** A raw record or control record yielded by {@link readRecords}. */
|
|
133
130
|
type ReadRecord = {
|
|
134
131
|
kind: 'header';
|
|
@@ -152,8 +149,6 @@ type DataLogInput = Uint8Array | ArrayBuffer;
|
|
|
152
149
|
* or an intermediate transformation are not needed.
|
|
153
150
|
*/
|
|
154
151
|
export declare function readRecords(input: DataLogInput): Generator<ReadRecord>;
|
|
155
|
-
//#endregion
|
|
156
|
-
//#region src/decode-records.d.ts
|
|
157
152
|
/** Options for {@link decodeRecords} and {@link parseDataLog}. */
|
|
158
153
|
type DecodeRecordsOptions = {
|
|
159
154
|
/**
|
|
@@ -181,8 +176,6 @@ export declare function decodeRecords(records: Iterable<ReadRecord>, options?: D
|
|
|
181
176
|
* {@link decodeRecords} while preserving the same output and strict-mode behavior.
|
|
182
177
|
*/
|
|
183
178
|
export declare function parseDataLog(input: DataLogInput, options?: DecodeRecordsOptions): Generator<DecodedRecord>;
|
|
184
|
-
//#endregion
|
|
185
|
-
//#region src/catalog.d.ts
|
|
186
179
|
/** An entry definition from the WPILOG catalog. */
|
|
187
180
|
type CatalogEntry = {
|
|
188
181
|
entryId: number;
|
|
@@ -198,8 +191,6 @@ type CatalogEntry = {
|
|
|
198
191
|
* making this much cheaper than full decoding via {@link parseDataLog}.
|
|
199
192
|
*/
|
|
200
193
|
export declare function catalogEntries(records: Iterable<ReadRecord>): Generator<CatalogEntry>;
|
|
201
|
-
//#endregion
|
|
202
|
-
//#region src/struct/types.d.ts
|
|
203
194
|
export declare const KnownStructTypeName: {
|
|
204
195
|
readonly Boolean: 'bool';
|
|
205
196
|
readonly Character: 'char';
|
|
@@ -229,9 +220,6 @@ type StructDeclaration = {
|
|
|
229
220
|
arraySize?: number;
|
|
230
221
|
bitWidth?: number;
|
|
231
222
|
};
|
|
232
|
-
//#endregion
|
|
233
|
-
//#region src/struct/parse-struct.d.ts
|
|
234
223
|
/** Parse a WPILib struct specification string into declarations. */
|
|
235
224
|
export declare function parseStructSpecification(declaration: string): StructDeclaration[];
|
|
236
|
-
//#endregion
|
|
237
225
|
export type { CatalogEntry, ControlRecord, ControlRecordPayload, DataLogHeader, DataLogInput, DataRecord, DecodeRecordsOptions, DecodedRecord, EnumSpecification, FinishControlRecord, RawRecord, ReadRecord, SetMetadataControlRecord, StartControlRecord, StructDeclaration, StructPayload, StructSpecification, StructTypeName };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { s as ControlRecordType, a as KnownStructTypeName, c as RecordType, t as catalogEntries, n as decodeRecords, l as isDataRecord, r as parseDataLog, i as parseStructSpecification, o as readRecords } from "./catalog-
|
|
1
|
+
export { s as ControlRecordType, a as KnownStructTypeName, c as RecordType, t as catalogEntries, n as decodeRecords, l as isDataRecord, r as parseDataLog, i as parseStructSpecification, o as readRecords } from "./catalog-DstFMwwV.mjs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wpilog-parser",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Read WPILib wpilog data log files in TypeScript & JavaScript",
|
|
5
5
|
"homepage": "https://github.com/jonahsnider/wpilog-parser#readme",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"test": "vp test"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
+
"@bomb.sh/tab": "^0.0.22",
|
|
47
48
|
"@toon-format/toon": "^4.1.1",
|
|
48
49
|
"cac": "^7.0.0",
|
|
49
50
|
"chevrotain": "^13.0.0",
|
|
@@ -65,6 +66,6 @@
|
|
|
65
66
|
"version": "26.x"
|
|
66
67
|
}
|
|
67
68
|
},
|
|
68
|
-
"packageManager": "pnpm@12.
|
|
69
|
+
"packageManager": "pnpm@12.15.0",
|
|
69
70
|
"tsdocMetadata": "./dist/tsdoc-metadata.json"
|
|
70
71
|
}
|