ID3v2 | Remove FrameClassType#141
Conversation
There was a problem hiding this comment.
Pull request overview
This PR removes the FrameClassType enum and the abstract frameClassType getter from the ID3v2 frame hierarchy, replacing runtime frame-type checks with instanceof-based filtering. A new ArrayUtils.ofType(array, Constructor) helper (backed by a TypeReference<T> type) centralizes the pattern, and each concrete frame class now exposes a static filterFrames(frames: Frame[]) method in place of the old bespoke find*/findPreferred methods. Frame is converted from a named to a default export, and the preferred-frame selection logic for comments and unsynchronized lyrics is moved directly into Id3v2Tag. UrlLinkFrame.fromIdentity is also renamed to fromIdentifier.
Changes:
- Remove
FrameClassType/frameClassTypeand theId3v2FrameClassTypepublic export; makeFramea default export. - Add
ArrayUtils.ofType+TypeReference<T>and replace per-classfind*methods withfilterFrames; move comment/lyrics preferred-frame selection intoId3v2Tag. - Update the test suite to use
instanceof/filterFramesand renamefromIdentity→fromIdentifier.
Reviewed changes
Copilot reviewed 45 out of 45 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils.ts | Adds TypeReference<T> and ArrayUtils.ofType filtering helper. |
| src/index.ts | Exports Frame as default (Id3v2Frame); drops Id3v2FrameClassType. |
| src/id3v2/frames/frame.ts | Removes FrameClassType enum and frameClassType getter; Frame becomes default export. |
| src/id3v2/id3v2Tag.ts | Removes getFramesByClassType/getFramesByIdentifier; inlines comment/lyrics preferred logic; uses filterFrames. Has the two behavior regressions noted below and minor style nits. |
| src/id3v2/frames/urlLinkFrame.ts | Renames fromIdentity→fromIdentifier; adds filterFrames with optional identifier. |
| src/id3v2/frames/userUrlLinkFrame.ts | Adds filterFrames; new Frame default import is misordered. |
| src/id3v2/frames/textInformationFrame.ts | Adds filterFrames with optional identifier filtering. |
| src/id3v2/frames/*.ts (attachment, comments, eventTimeCode, genre, musicCdIdentifier, playCount, popularimeter, private, relativeVolume, synchronizedLyrics, termsOfUse, uniqueFileIdentifier, unknown, unsynchronizedLyrics, userTextInformation) | Remove frameClassType getter and find* methods; add filterFrames via ArrayUtils.ofType. |
| test-unit/id3v2/genreFrameTests.ts | Switches to instanceof/filterFrames; clone test asserts on the wrong object. |
| test-unit/id3v2/userUrlLinkFrameTests.ts, userTextInformationFrameTests.ts | Add shared assertFrame helpers and filterFrames_* tests; use default Frame import. |
| test-unit/id3v2/{privateFrameTests, unsynchronizedLyricsFrameTests, uniqueFileIdentifierFrameTests, unknownFrameTests}.ts | Add filterFrames_* tests; contain CI-breaking trailing whitespace. |
| test-unit/id3v2/id3v2TagTests.ts, frameFactoryTests.ts, other frame tests | Replace FrameClassType assertions with assert.instanceOf; add multi-frame lyrics test. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
The ID3v2 frame classes used to implement a FrameClassType enum that enabled checking frames all over the ID3v2 classes. However, it really isn't necessary, not is it all that strong. This PR removed FrameClassType and replaces checks for frame type with
instanceofchecks. Additionally, the Find methods in each frame class has been replaced with FilterFrames methods. These are not 1:1 replacements, but help to easily filter a Frame[] into a XyzFrame[].Testing
New tests are added where necessary, old tests are removed where necessary, broken tests have been fixed.