There may be cases where the included API data doesn't contain all requested resources (all album artists, labels, images etc).
So far I've only seen missing resources for track artists, which has a completely separate implementation in getTrackArtists which doesn't call getRelatedItems.
In my local files I've even left a note on this function which mentions the possibility of the current issue, but I hadn't addressed it so far:
TODO: Track AC conversion is inconsistent with release AC conversion (which might be in the wrong order since it filters the existing resources instead of mapping the IDs to resources).
Store artistMap as this.artistMap?
In the long term we probably want to properly type the getRelatedItems helper or abandon it if there is no clean way to do it. I like the approach with the artistMap that we do for tracks, maybe a generic this.resourceMap and a suitable helper function is the way to go?
Originally posted by @kellnerd in #182 (comment)
The current implementation which falls back to returning objects with just an id property is not safe: As far as I can see it doesn't matter whether we return the incomplete object or undefined, all callers of getRelatedItems aren't prepared to handle either case.
That's the big downside of the type assertion there, you don't notice such issues until they happen.
There may be cases where the
includedAPI data doesn't contain all requested resources (all album artists, labels, images etc).So far I've only seen missing resources for track artists, which has a completely separate implementation in
getTrackArtistswhich doesn't callgetRelatedItems.In my local files I've even left a note on this function which mentions the possibility of the current issue, but I hadn't addressed it so far:
In the long term we probably want to properly type the
getRelatedItemshelper or abandon it if there is no clean way to do it. I like the approach with theartistMapthat we do for tracks, maybe a genericthis.resourceMapand a suitable helper function is the way to go?Originally posted by @kellnerd in #182 (comment)
The current implementation which falls back to returning objects with just an
idproperty is not safe: As far as I can see it doesn't matter whether we return the incomplete object orundefined, all callers ofgetRelatedItemsaren't prepared to handle either case.That's the big downside of the type assertion there, you don't notice such issues until they happen.