Skip to content

Strong typing in MIAMCoreUtils#312

Merged
makrsmark merged 4 commits intoairframesio:masterfrom
makrsmark:feature/miam-typing
Feb 1, 2026
Merged

Strong typing in MIAMCoreUtils#312
makrsmark merged 4 commits intoairframesio:masterfrom
makrsmark:feature/miam-typing

Conversation

@makrsmark
Copy link
Collaborator

@makrsmark makrsmark commented Jan 31, 2026

Summary by CodeRabbit

  • Refactor

    • Unified and version-aware parsing model to handle protocol variants more consistently.
  • Bug Fixes

    • Stronger runtime validation and clearer error responses for invalid inputs; standardized checksum and compression handling; preserved legacy padding behavior where needed.
  • Tests

    • Made tests tolerant to missing decoded payloads to avoid spurious failures.
  • Chores

    • Minor CLI/type cleanup with no user-facing behavior change.

✏️ Tip: You can customize this high-level summary in your review settings.

@makrsmark makrsmark requested a review from andermatt64 January 31, 2026 02:12
@coderabbitai
Copy link

coderabbitai bot commented Jan 31, 2026

Walkthrough

Introduces exported MIAMVersion and unified MIAMCoreApp; converts loose tables/handlers into strongly-typed, versioned Records; adds runtime guards; changes Pdu.version to MIAMVersion; makes parsing and core PDU handling version-aware; replaces undefined handlers with explicit handlers; updates InflateRaw and CRC mappings.

Changes

Cohort / File(s) Summary
Core MIAM module
lib/utils/miam.ts
Adds exported MIAMVersion and unified MIAMCoreApp; changes Pdu.version: numberMIAMVersion; converts AppTypeToAppIdLenTable, FidHandlerTable, VersionPduHandlerTable, and CRC mapping to strongly-typed, versioned Record<MIAMVersion, ...> structures; introduces runtime guards (isMIAMVersion, isMIAMFid, isMIAMCoreApp, isMIAMCorePdu); refactors parse flow and corePduDataHandler to be version-aware; changes pduData to `Buffer
Tests — defensive assertions
lib/utils/miam.test.ts
Makes tests tolerant to missing decode results and missing acars/non_acars by introducing assert-and-return guard patterns before accessing nested fields.
CLI small typing tweaks
lib/bin/acars-decoder-test.ts, lib/bin/acars-decoder.ts
Removed explicit TypeScript any annotation from forEach callbacks (no behavioral change).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client as "Client / Input"
  participant Parser as "MIAM Parser\n(lib/utils/miam.ts)"
  participant VersionHandlers as "VersionPduHandlerTable\n(versioned handlers)"
  participant CoreData as "corePduDataHandler"
  participant FidHandlers as "FidHandlerTable"
  participant Zlib as "InflateRaw"
  participant CRC as "CRC Validator"

  Client->>Parser: submit raw packet
  Parser->>Parser: isMIAMVersion / isMIAMFid guards
  Parser->>VersionHandlers: dispatch by MIAMVersion & PDU type
  VersionHandlers->>CoreData: route Data PDU -> corePduDataHandler(version, hdr, body)
  CoreData->>FidHandlers: determine FID and call handler
  FidHandlers->>Zlib: if compressed -> InflateRaw.inflate
  FidHandlers->>CRC: compute/check CRC via versioned CRC function
  FidHandlers-->>Parser: return PduDecodingResult
  Parser-->>Client: return decoded result
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 I hopped through enums, tidy and bright,
Guards at the gates to keep bytes polite.
V1 and V2 now share one song,
Handlers mapped and errors gone.
A little hop, the code feels light! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main objective of the pull request, which is to introduce strong typing throughout the MIAMCoreUtils module by converting loose/any types to specific enums and typed Record structures.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@lib/utils/miam.ts`:
- Around line 484-496: Fix the typo in the MIAMVersion.V2 AlohaReply error
message inside the VersionPduHandlerTable: locate the MIAMVersion.V2 entry and
update the error string returned by the MIAMCorePdu.AlohaReply handler
(currently contains "Aloha eply PDU not implemented") to the correct text "v2
AlohaReply PDU not implemented" so it matches the other version messages and the
MIAMCorePdu.AlohaReply identifier.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
lib/utils/miam.ts (1)

5-90: ⚠️ Potential issue | 🟠 Major

Export types used by the public API return type.

MIAMCoreUtils.parse() is a public method (line 319) that returns PduDecodingResult, which depends on non-exported types including Pdu, PduACARSData, PduNonACARSData, PduDecodingSuccess, PduDecodingFailure, and MIAMVersion. With declaration emit enabled in tsconfig.json, this generates "private name" errors in the .d.ts files and makes the public types unusable. Export these types or change the public signature to use only exported types.

🔧 Proposed fix
-enum MIAMVersion {
+export enum MIAMVersion {
   V1 = 1,
   V2 = 2,
 }
@@
-interface PduACARSData {
+export interface PduACARSData {
   tail?: string,
   label: string,
   sublabel?: string,
   mfi?: string,
   text?: string,
 }
 
-interface PduNonACARSData {
+export interface PduNonACARSData {
   appId?: string,
   text?: string,
 }
 
-interface Pdu {
+export interface Pdu {
   version: MIAMVersion,
   crc: number,
   crcOk: boolean,
   complete: boolean,
@@
-interface PduDecodingSuccess {
+export interface PduDecodingSuccess {
   decoded: true;
   message: {
     data: Pdu;
   };
 }
 
-interface PduDecodingFailure {
+export interface PduDecodingFailure {
   decoded: false;
   error: string;
 }
 
-type PduDecodingResult = PduDecodingSuccess | PduDecodingFailure;
+export type PduDecodingResult = PduDecodingSuccess | PduDecodingFailure;

Copy link
Contributor

@kevinelliott kevinelliott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really good @makrsmark

remove unecessary any
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
lib/utils/miam.ts (1)

5-105: ⚠️ Potential issue | 🟠 Major

Export types used by public members (or make those members private).

MIAMCoreUtils is exported with public static members (AppTypeToAppIdLenTable, FidHandlerTable, and parse()) that reference non-exported types (MIAMVersion, MIAMCoreApp, MIAMFid, and PduDecodingResult). Since tsconfig.json has "declaration": true enabled, this will trigger TS4023 ("has or is using private name") errors during the build.

Export the referenced enums and types, or make the public members private.

✅ Example fix (export types)
-enum MIAMVersion {
+export enum MIAMVersion {
   V1 = 1,
   V2 = 2,
 }
 
-enum MIAMFid {
+export enum MIAMFid {
   SingleTransfer = 'T',
   FileTransferRequest = 'F',
   FileTransferAccept = 'K',
   FileSegment = 'S',
   FileTransferAbort = 'A',
   XOFFIndication = 'Y',
   XONIndication = 'X',
 }
 
-enum MIAMCorePdu {
+export enum MIAMCorePdu {
   Data = 0,
   Ack = 1,
   Aloha = 2,
   AlohaReply = 3,
 }
 
-enum MIAMCoreApp {
+export enum MIAMCoreApp {
   ACARS2Char = 0x0,
   ACARS4Char = 0x1,
   ACARS6Char = 0x2,
   NonACARS6Char = 0x3,
 }
 
-interface Pdu {
+export interface Pdu {
   version: MIAMVersion,
   crc: number,
   crcOk: boolean,
   complete: boolean,
   compression: number,
   encoding: number,
   msgNum: number,
   ackOptions: number,
   acars?: PduACARSData,
   non_acars?: PduNonACARSData,
 }
 
-type PduDecodingResult = PduDecodingSuccess | PduDecodingFailure;
+export type PduDecodingResult = PduDecodingSuccess | PduDecodingFailure;

@makrsmark makrsmark merged commit d345c7d into airframesio:master Feb 1, 2026
6 checks passed
@makrsmark makrsmark deleted the feature/miam-typing branch February 1, 2026 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants