refactor(n2k-discovery): build outbound PGNs with the typed ts-pgns classes - #2911
refactor(n2k-discovery): build outbound PGNs with the typed ts-pgns classes#2911dirkwa wants to merge 1 commit into
Conversation
…lasses
Every nmea2000JsonOut emit constructed its 126208 / 59904 object as an
untyped literal with stringly field names ('Function Code': 'Command').
The generated per-variant classes carry the same runtime shape - match
fields auto-filled, schema priority defaults, camelCase ids - but a
typo or a wrong field is now a compile error checked against the same
database both encoders (canboatjs and canboat) validate against.
Serialized output is unchanged: the command variant encodes
byte-identical through pgnToActisenseSerialFormat before and after.
|
Important Review skippedNo new commits to review since the last review. ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThe discovery interface now uses typed PGN constructors for ISO Requests and NMEA 2000 device configuration commands. Existing validation, scheduling, parameters, destinations, PGNs, and response behavior remain unchanged. ChangesTyped NMEA 2000 PGN construction
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 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 |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/interfaces/n2k-discovery.ts`:
- Around line 11-15: Add `@canboat/ts-pgns` as an explicit production dependency
in the root package manifest and regenerate the lockfile so its resolved version
and integrity metadata are recorded. Keep the existing runtime imports in
n2k-discovery.ts unchanged.
- Around line 1283-1297: Update the PGN 126208 construction around
PGN_126208_NmeaCommandGroupFunction to use typed per-operation target-PGN
descriptors or builders, rather than raw numeric parameter indexes and untyped
values. Define named constants for the target PGN, field indexes, and priority,
enforce valid value types for those fields, and derive numberOfParameters from
the descriptor list instead of hard-coding it.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 82989e88-9310-4e38-a190-e34f631c0faf
📒 Files selected for processing (1)
src/interfaces/n2k-discovery.ts
|
@coderabbitai Thanks — both findings are accurate observations, but I don't think either should be fixed in this PR. Details below. 1. You're right that the root But this is not new in this PR. import { getAllPGNs, getEnumerationName, getEnumerationValue } from '@canboat/ts-pgns'My change adds three more named imports from a module the file already loaded unconditionally. So the risk profile is unchanged, and fixing it means adding a root production dependency plus a lockfile entry — a dependency-policy decision for the maintainers that reaches well past a no-behavior-change refactor, and one that would be better made once for both packages rather than smuggled in here. Happy to open it as a separate PR if the maintainers want it. 2. Typed target-PGN descriptors — correct about the types, but the erasure is upstream and runtime validation already covers it. Confirmed in the published
This PR is a like-for-like swap of hand-built object literals for the typed constructors, with the encoded bytes and priorities verified identical. Broadening it into a descriptor framework would undercut that reviewability. |
|
Tip For best results, initiate chat on the files or code changes.
I agree that the root dependency issue is pre-existing. This PR does not increase its runtime dependency risk because I also agree that a local descriptor layer is not appropriate for this refactor. The type erasure is upstream, and the existing per-field runtime validation protects the variable values. The typed constructors still improve validation for the outbound PGN shape without changing the encoded output. I will withdraw both findings. If maintainers decide to address the undeclared root dependency, it should be a separate dependency-policy change. 🐇 ✓ ✏️ Learnings added
You are interacting with an AI system. |
|
ready for human review |
|
@coderabbitai review |
|
The N2K discovery responder assembled its outbound PGNs (ISO address claim, product/configuration information responses) from hand-rolled field objects; this builds them with @canboat/ts-pgns' typed classes instead — the compiler now checks field names and shapes against the canboat schema, and the discovery code reads as what it sends. No behavior change intended; the emitted records are the same.
Tested: typecheck and the existing discovery tests; discovery responses verified from a staging image against live bus queries.
Summary
@canboat/ts-pgnsclasses.