wpilog-parser 3.0.0 → 3.1.1

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 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
- //#region src/byte-offset.ts
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
- //#endregion
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
- //#endregion
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
- //#endregion
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");
@@ -210,35 +207,14 @@ function readTimestamp(view, offset, length) {
210
207
  switch (length) {
211
208
  case 1: return BigInt(view.getUint8(offset));
212
209
  case 2: return BigInt(view.getUint16(offset, true));
213
- case 3: {
214
- const b0 = BigInt(view.getUint8(offset));
215
- const b1 = BigInt(view.getUint8(offset + 1));
216
- return BigInt(view.getUint8(offset + 2)) << 16n | b1 << 8n | b0;
217
- }
210
+ case 3: return BigInt(view.getUint16(offset, true) + view.getUint8(offset + 2) * 2 ** 16);
218
211
  case 4: return BigInt(view.getUint32(offset, true));
219
- case 5: {
220
- const b0 = BigInt(view.getUint8(offset));
221
- const b1 = BigInt(view.getUint8(offset + 1));
222
- const b2 = BigInt(view.getUint8(offset + 2));
223
- const b3 = BigInt(view.getUint8(offset + 3));
224
- return BigInt(view.getUint8(offset + 4)) << 32n | b3 << 24n | b2 << 16n | b1 << 8n | b0;
225
- }
226
- case 6: {
227
- const b0 = BigInt(view.getUint8(offset));
228
- const b1 = BigInt(view.getUint8(offset + 1));
229
- const b2 = BigInt(view.getUint8(offset + 2));
230
- const b3 = BigInt(view.getUint8(offset + 3));
231
- const b4 = BigInt(view.getUint8(offset + 4));
232
- return BigInt(view.getUint8(offset + 5)) << 40n | b4 << 32n | b3 << 24n | b2 << 16n | b1 << 8n | b0;
233
- }
212
+ case 5: return BigInt(view.getUint32(offset, true) + view.getUint8(offset + 4) * 2 ** 32);
213
+ case 6: return BigInt(view.getUint32(offset, true) + view.getUint16(offset + 4, true) * 2 ** 32);
234
214
  case 7: {
235
- const b0 = BigInt(view.getUint8(offset));
236
- const b1 = BigInt(view.getUint8(offset + 1));
237
- const b2 = BigInt(view.getUint8(offset + 2));
238
- const b3 = BigInt(view.getUint8(offset + 3));
239
- const b4 = BigInt(view.getUint8(offset + 4));
240
- const b5 = BigInt(view.getUint8(offset + 5));
241
- return BigInt(view.getUint8(offset + 6)) << 48n | b5 << 40n | b4 << 32n | b3 << 24n | b2 << 16n | b1 << 8n | b0;
215
+ const low = view.getUint32(offset, true);
216
+ const high = view.getUint16(offset + 4, true) + view.getUint8(offset + 6) * 2 ** 16;
217
+ return BigInt(high) << 32n | BigInt(low);
242
218
  }
243
219
  case 8: return view.getBigUint64(offset, true);
244
220
  default: throw new RangeError(`Invalid timestamp length ${length}`);
@@ -341,8 +317,7 @@ function* readRecords(input) {
341
317
  };
342
318
  }
343
319
  }
344
- //#endregion
345
- //#region src/struct/types.ts
320
+ // src/struct/types.ts
346
321
  const KnownStructTypeName = {
347
322
  Boolean: "bool",
348
323
  Character: "char",
@@ -361,8 +336,7 @@ const KnownStructTypeName = {
361
336
  /** Equivalent to {@link (KnownStructTypeName:variable).Float64} */
362
337
  Double: "double"
363
338
  };
364
- //#endregion
365
- //#region src/struct/struct-dependency-graph.ts
339
+ // src/struct/struct-dependency-graph.ts
366
340
  const EMPTY_SET = /* @__PURE__ */ new Set();
367
341
  var StructDependencyGraph = class {
368
342
  allDependencies = new Map(Object.values(KnownStructTypeName).map((type) => [type, EMPTY_SET]));
@@ -406,8 +380,7 @@ var StructDependencyGraph = class {
406
380
  return result;
407
381
  }
408
382
  };
409
- //#endregion
410
- //#region src/struct/struct-decode-queue.ts
383
+ // src/struct/struct-decode-queue.ts
411
384
  var StructDecodeQueue = class {
412
385
  graph = new StructDependencyGraph();
413
386
  queuedRecords = /* @__PURE__ */ new Map();
@@ -434,8 +407,7 @@ var StructDecodeQueue = class {
434
407
  }
435
408
  }
436
409
  };
437
- //#endregion
438
- //#region src/struct/bit-field.ts
410
+ // src/struct/bit-field.ts
439
411
  var BitFieldTracker = class {
440
412
  storageByteLength = 0;
441
413
  bitShift = 0;
@@ -488,8 +460,7 @@ function isSignedInteger(type) {
488
460
  default: return false;
489
461
  }
490
462
  }
491
- //#endregion
492
- //#region src/struct/compile-struct.ts
463
+ // src/struct/compile-struct.ts
493
464
  const READERS = {
494
465
  bool: {
495
466
  method: "getUint8",
@@ -632,8 +603,7 @@ function compileStruct(registry, name) {
632
603
  ${sources.join("\n")}
633
604
  return ${root};`)(new TextDecoder());
634
605
  }
635
- //#endregion
636
- //#region src/struct/lexer.ts
606
+ // src/struct/lexer.ts
637
607
  const Comma = createToken({
638
608
  name: "Comma",
639
609
  pattern: ","
@@ -697,8 +667,7 @@ const allTokens = [
697
667
  Identifier
698
668
  ];
699
669
  const lexer = new Lexer(allTokens);
700
- //#endregion
701
- //#region src/struct/parser.ts
670
+ // src/struct/parser.ts
702
671
  var StructParser = class extends CstParser {
703
672
  structSpecification = this.RULE("structSpecification", () => {
704
673
  this.MANY_SEP({
@@ -762,8 +731,7 @@ var StructParser = class extends CstParser {
762
731
  const parser = new StructParser();
763
732
  parser.getBaseCstVisitorConstructor();
764
733
  const BaseStructVisitorWithDefaults = parser.getBaseCstVisitorConstructorWithDefaults();
765
- //#endregion
766
- //#region src/struct/struct-ast-visitor.ts
734
+ // src/struct/struct-ast-visitor.ts
767
735
  var StructAstVisitor = class extends BaseStructVisitorWithDefaults {
768
736
  constructor() {
769
737
  super();
@@ -860,8 +828,7 @@ var StructAstVisitor = class extends BaseStructVisitorWithDefaults {
860
828
  return Number(value.image);
861
829
  }
862
830
  };
863
- //#endregion
864
- //#region src/struct/parse-struct.ts
831
+ // src/struct/parse-struct.ts
865
832
  const structAstVisitor = new StructAstVisitor();
866
833
  const cache = /* @__PURE__ */ new Map();
867
834
  /** Parse a WPILib struct specification string into declarations. */
@@ -877,8 +844,7 @@ function parseStructSpecification(declaration) {
877
844
  cache.set(declaration, created);
878
845
  return created;
879
846
  }
880
- //#endregion
881
- //#region src/struct/struct-registry.ts
847
+ // src/struct/struct-registry.ts
882
848
  var StructRegistry = class StructRegistry {
883
849
  static TEXT_DECODER = new TextDecoder("utf-8");
884
850
  definitions = /* @__PURE__ */ new Map();
@@ -1198,8 +1164,7 @@ var StructRegistry = class StructRegistry {
1198
1164
  return byteLengthForOne;
1199
1165
  }
1200
1166
  };
1201
- //#endregion
1202
- //#region src/decode-records.ts
1167
+ // src/decode-records.ts
1203
1168
  const TEXT_DECODER = new TextDecoder();
1204
1169
  const STRUCT_PREFIX = "struct:";
1205
1170
  const STRUCT_ARRAY_SUFFIX = "[]";
@@ -1496,8 +1461,7 @@ function decodeNonScalarPayload(raw, entryType, name, metadata, view, structRegi
1496
1461
  };
1497
1462
  }
1498
1463
  }
1499
- //#endregion
1500
- //#region src/catalog.ts
1464
+ // src/catalog.ts
1501
1465
  /**
1502
1466
  * Collect all entry definitions from a WPILOG record stream.
1503
1467
  *
@@ -1525,5 +1489,4 @@ function* catalogEntries(records) {
1525
1489
  }
1526
1490
  }
1527
1491
  }
1528
- //#endregion
1529
1492
  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-AwcdBV3I.mjs";
2
+ import { o as readRecords, t as catalogEntries, u as diagnostics } from "./catalog-BmNQKX4c.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
- //#region package.json
9
- var version = "3.0.0";
10
- //#endregion
11
- //#region src/cli/catalog.ts
9
+ // package.json
10
+ var version = "3.1.1";
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
- //#endregion
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-AwcdBV3I.mjs";
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-BmNQKX4c.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wpilog-parser",
3
- "version": "3.0.0",
3
+ "version": "3.1.1",
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.14.0",
69
+ "packageManager": "pnpm@12.15.0",
69
70
  "tsdocMetadata": "./dist/tsdoc-metadata.json"
70
71
  }