Strong typing in MIAMCoreUtils#312
Conversation
WalkthroughIntroduces 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
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 | 🟠 MajorExport types used by the public API return type.
MIAMCoreUtils.parse()is a public method (line 319) that returnsPduDecodingResult, which depends on non-exported types includingPdu,PduACARSData,PduNonACARSData,PduDecodingSuccess,PduDecodingFailure, andMIAMVersion. 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;
kevinelliott
left a comment
There was a problem hiding this comment.
This looks really good @makrsmark
There was a problem hiding this comment.
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 | 🟠 MajorExport types used by public members (or make those members private).
MIAMCoreUtilsis exported with public static members (AppTypeToAppIdLenTable,FidHandlerTable, andparse()) that reference non-exported types (MIAMVersion,MIAMCoreApp,MIAMFid, andPduDecodingResult). Sincetsconfig.jsonhas"declaration": trueenabled, 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;
Summary by CodeRabbit
Refactor
Bug Fixes
Tests
Chores
✏️ Tip: You can customize this high-level summary in your review settings.