wpilog-parser 3.2.0 → 3.2.2

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
@@ -26,7 +26,7 @@ for (const record of parseDataLog(bytes)) {
26
26
  Use `readRecords()` and `decodeRecords()` separately when you need access to raw records or want to transform the record stream before decoding it. Both approaches produce the same decoded records.
27
27
 
28
28
  Struct schemas are compiled lazily into reusable decoders, and struct payloads are returned as plain objects, including nested structs and arrays of structs.
29
- In environments where Content Security Policy blocks runtime code generation, structs are decoded by the interpreter automatically.
29
+ In environments where Content Security Policy blocks runtime code generation, decoding falls back to a CSP-safe implementation.
30
30
 
31
31
  A summary of the full API is available in [wpilog-parser.api.md](https://github.com/jonahsnider/wpilog-parser/blob/main/packages/wpilog-parser/etc/wpilog-parser.api.md).
32
32
 
@@ -391,6 +391,20 @@ const TEXT_DECODER = new TextDecoder();
391
391
  const STRUCT_PREFIX = "struct:";
392
392
  const STRUCT_ARRAY_SUFFIX = "[]";
393
393
  const STRUCT_SCHEMA_NAME_PREFIX = "/.schema/struct:";
394
+ /**
395
+ * Build a non-struct data record as one flat object literal.
396
+ * Struct records are built inline with the same field order plus `structName`.
397
+ */
398
+ function dataRecord(entryId, timestamp, name, metadata, type, payload) {
399
+ return {
400
+ entryId,
401
+ timestamp,
402
+ name,
403
+ metadata,
404
+ type,
405
+ payload
406
+ };
407
+ }
394
408
  function byteToBoolean(byte) {
395
409
  switch (byte) {
396
410
  case 0: return false;
@@ -417,25 +431,26 @@ var RecordDecoder = class {
417
431
  if (!context) continue;
418
432
  const { entryType, name, metadata } = context;
419
433
  const structName = entryType.slice(7);
420
- const base = {
421
- entryId: raw.entryId,
422
- timestamp: raw.timestamp,
423
- name,
424
- metadata,
425
- structName
426
- };
427
434
  if (entryType.endsWith(STRUCT_ARRAY_SUFFIX)) {
428
435
  const payload = this.structRegistry.decodeArray(structName, raw.payload);
429
436
  if (typeof payload !== "string") this.delayedRecords.push({
430
- ...base,
437
+ entryId: raw.entryId,
438
+ timestamp: raw.timestamp,
439
+ name,
440
+ metadata,
431
441
  type: RecordType.StructArray,
442
+ structName,
432
443
  payload
433
444
  });
434
445
  } else {
435
446
  const payload = this.structRegistry.decode(structName, raw.payload);
436
447
  if (typeof payload !== "string") this.delayedRecords.push({
437
- ...base,
448
+ entryId: raw.entryId,
449
+ timestamp: raw.timestamp,
450
+ name,
451
+ metadata,
438
452
  type: RecordType.Struct,
453
+ structName,
439
454
  payload
440
455
  });
441
456
  }
@@ -477,33 +492,12 @@ var RecordDecoder = class {
477
492
  if (this.options.strict) throw diagnostics.WPILOG_R0006({ entryId });
478
493
  return;
479
494
  }
480
- const base = {
481
- entryId,
482
- timestamp,
483
- name: context.name,
484
- metadata: context.metadata
485
- };
495
+ const { name, metadata } = context;
486
496
  switch (context.entryType) {
487
- case "boolean": return {
488
- ...base,
489
- type: RecordType.Boolean,
490
- payload: byteToBoolean(view.getUint8(payloadOffset))
491
- };
492
- case "int64": return {
493
- ...base,
494
- type: RecordType.Int64,
495
- payload: view.getBigInt64(payloadOffset, true)
496
- };
497
- case "float": return {
498
- ...base,
499
- type: RecordType.Float,
500
- payload: view.getFloat32(payloadOffset, true)
501
- };
502
- case "double": return {
503
- ...base,
504
- type: RecordType.Double,
505
- payload: view.getFloat64(payloadOffset, true)
506
- };
497
+ case "boolean": return dataRecord(entryId, timestamp, name, metadata, RecordType.Boolean, byteToBoolean(view.getUint8(payloadOffset)));
498
+ case "int64": return dataRecord(entryId, timestamp, name, metadata, RecordType.Int64, view.getBigInt64(payloadOffset, true));
499
+ case "float": return dataRecord(entryId, timestamp, name, metadata, RecordType.Float, view.getFloat32(payloadOffset, true));
500
+ case "double": return dataRecord(entryId, timestamp, name, metadata, RecordType.Double, view.getFloat64(payloadOffset, true));
507
501
  }
508
502
  const payload = payloadOffset === 0 && payloadSize === bytes.byteLength ? bytes : bytes.subarray(payloadOffset, payloadOffset + payloadSize);
509
503
  const raw = {
@@ -572,53 +566,28 @@ function* parseDataLog(input, options = { strict: false }) {
572
566
  * Fixed-width scalar types return from {@link RecordDecoder#decodeData} before this function so their payloads can be read directly from the input buffer.
573
567
  */
574
568
  function decodeNonScalarPayload(raw, entryType, name, metadata, view, structRegistry, structDecodeQueue) {
575
- const base = {
576
- entryId: raw.entryId,
577
- timestamp: raw.timestamp,
578
- name,
579
- metadata
580
- };
569
+ const { entryId, timestamp } = raw;
581
570
  switch (entryType) {
582
- case "string": return {
583
- ...base,
584
- type: RecordType.String,
585
- payload: TEXT_DECODER.decode(raw.payload)
586
- };
571
+ case "string": return dataRecord(entryId, timestamp, name, metadata, RecordType.String, TEXT_DECODER.decode(raw.payload));
587
572
  case "boolean[]": {
588
573
  const payload = [];
589
574
  for (let i = 0; i < raw.payload.byteLength; i++) payload.push(byteToBoolean(view.getUint8(i)));
590
- return {
591
- ...base,
592
- type: RecordType.BooleanArray,
593
- payload
594
- };
575
+ return dataRecord(entryId, timestamp, name, metadata, RecordType.BooleanArray, payload);
595
576
  }
596
577
  case "int64[]": {
597
578
  const payload = [];
598
579
  for (let i = 0; i < raw.payload.byteLength; i += 8) payload.push(view.getBigUint64(i, true));
599
- return {
600
- ...base,
601
- type: RecordType.Int64Array,
602
- payload
603
- };
580
+ return dataRecord(entryId, timestamp, name, metadata, RecordType.Int64Array, payload);
604
581
  }
605
582
  case "float[]": {
606
583
  const payload = [];
607
584
  for (let i = 0; i < raw.payload.byteLength; i += 4) payload.push(view.getFloat32(i, true));
608
- return {
609
- ...base,
610
- type: RecordType.FloatArray,
611
- payload
612
- };
585
+ return dataRecord(entryId, timestamp, name, metadata, RecordType.FloatArray, payload);
613
586
  }
614
587
  case "double[]": {
615
588
  const payload = [];
616
589
  for (let i = 0; i < raw.payload.byteLength; i += 8) payload.push(view.getFloat64(i, true));
617
- return {
618
- ...base,
619
- type: RecordType.DoubleArray,
620
- payload
621
- };
590
+ return dataRecord(entryId, timestamp, name, metadata, RecordType.DoubleArray, payload);
622
591
  }
623
592
  case "string[]": {
624
593
  const payload = [];
@@ -632,21 +601,13 @@ function decodeNonScalarPayload(raw, entryType, name, metadata, view, structRegi
632
601
  offset.advance(stringLength);
633
602
  payload.push(string);
634
603
  }
635
- return {
636
- ...base,
637
- type: RecordType.StringArray,
638
- payload
639
- };
604
+ return dataRecord(entryId, timestamp, name, metadata, RecordType.StringArray, payload);
640
605
  }
641
606
  case "structschema": {
642
607
  const structName = name.slice(name.indexOf(STRUCT_SCHEMA_NAME_PREFIX) + 16);
643
608
  const payload = TEXT_DECODER.decode(raw.payload);
644
609
  structRegistry.register(structName, payload);
645
- return {
646
- ...base,
647
- type: RecordType.String,
648
- payload
649
- };
610
+ return dataRecord(entryId, timestamp, name, metadata, RecordType.String, payload);
650
611
  }
651
612
  default:
652
613
  if (entryType.startsWith(STRUCT_PREFIX)) {
@@ -658,7 +619,10 @@ function decodeNonScalarPayload(raw, entryType, name, metadata, view, structRegi
658
619
  return;
659
620
  }
660
621
  return {
661
- ...base,
622
+ entryId,
623
+ timestamp,
624
+ name,
625
+ metadata,
662
626
  type: RecordType.StructArray,
663
627
  structName,
664
628
  payload: decoded
@@ -670,17 +634,16 @@ function decodeNonScalarPayload(raw, entryType, name, metadata, view, structRegi
670
634
  return;
671
635
  }
672
636
  return {
673
- ...base,
637
+ entryId,
638
+ timestamp,
639
+ name,
640
+ metadata,
674
641
  type: RecordType.Struct,
675
642
  structName,
676
643
  payload: decoded
677
644
  };
678
645
  }
679
- return {
680
- ...base,
681
- type: RecordType.Raw,
682
- payload: raw.payload
683
- };
646
+ return dataRecord(entryId, timestamp, name, metadata, RecordType.Raw, new Uint8Array(raw.payload));
684
647
  }
685
648
  }
686
649
  // src/catalog.ts
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { a as readRecords, l as diagnostics, t as catalogEntries } from "./catalog-hof8DZhi.mjs";
2
+ import { a as readRecords, l as diagnostics, t as catalogEntries } from "./catalog-Dz8xPVYl.mjs";
3
3
  import { Diagnostic, formatDiagnostic } from "nostics";
4
4
  import { RootCommand, script } from "@bomb.sh/tab";
5
5
  import { boolean, command, commandsInfo, positional, run } from "@drizzle-team/brocli";
@@ -7,7 +7,7 @@ import oscStatus from "osc-status";
7
7
  import { readFile } from "node:fs/promises";
8
8
  import { encode } from "@toon-format/toon";
9
9
  // package.json
10
- var version = "3.2.0";
10
+ var version = "3.2.2";
11
11
  var description = "Read WPILib wpilog data log files in TypeScript & JavaScript";
12
12
  // src/cli/catalog.ts
13
13
  async function catalogFile(filePath) {
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as readRecords, c as isDataRecord, i as withStructDiagnostics, n as decodeRecords, o as ControlRecordType, r as parseDataLog, s as RecordType, t as catalogEntries } from "./catalog-hof8DZhi.mjs";
1
+ import { a as readRecords, c as isDataRecord, i as withStructDiagnostics, n as decodeRecords, o as ControlRecordType, r as parseDataLog, s as RecordType, t as catalogEntries } from "./catalog-Dz8xPVYl.mjs";
2
2
  import { KnownStructTypeName, parseStructSpecification as parseStructSpecification$1 } from "wpilib-struct";
3
3
  // src/struct/parse-struct.ts
4
4
  /** Parse a WPILib struct specification string into declarations. */
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.60.0"
8
+ "packageVersion": "7.60.1"
9
9
  }
10
10
  ]
11
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wpilog-parser",
3
- "version": "3.2.0",
3
+ "version": "3.2.2",
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",
@@ -35,12 +35,12 @@
35
35
  "@toon-format/toon": "^4.1.1",
36
36
  "nostics": "^1.3.0",
37
37
  "osc-status": "^1.0.0",
38
- "wpilib-struct": "^1.0.0"
38
+ "wpilib-struct": "^1.0.2"
39
39
  },
40
40
  "devDependencies": {
41
- "@microsoft/api-extractor": "7.60.0",
42
- "vite-plus": "1.4.0",
43
- "vitest": "5.0.5"
41
+ "@microsoft/api-extractor": "7.60.1",
42
+ "vite-plus": "1.6.0",
43
+ "vitest": "5.1.0"
44
44
  },
45
45
  "tsdocMetadata": "./dist/tsdoc-metadata.json",
46
46
  "scripts": {