diff --git a/src/musicbrainz-api.ts b/src/musicbrainz-api.ts index c428664c..3de7ade2 100644 --- a/src/musicbrainz-api.ts +++ b/src/musicbrainz-api.ts @@ -42,6 +42,13 @@ export type RelationsIncludes = | 'url-rels' | 'work-rels'; +export type SubQueryIncludes = + 'discids' // include discids for all media in the releases + | 'media' // include media for all releases, this includes the # of tracks on each medium and its format. + | 'isrcs' // include isrcs for all recordings + | 'artist-credits' // include artists credits for all releases and recordings + | 'various-artists' // include only those releases where the artist appears on one of the tracks, but not in the artist credit for the release itself (this is only valid on a /ws/2/artist?inc=releases request). + export type MiscIncludes = 'aliases' | 'annotation' @@ -292,6 +299,15 @@ export class MusicBrainzApi { return this.lookupEntity('artist', artistId, inc); } + /** + * Lookup collection + * @param collectionId Collection MBID + * @param inc List of additional information to be included about the entity. Any of the entities directly linked to the entity can be included. + */ + public lookupCollection(collectionId: string, inc: ArtistIncludes[] = []): Promise { + return this.lookupEntity('collection', collectionId, inc); + } + /** * Lookup instrument * @param artistId Instrument MBID diff --git a/src/musicbrainz.types.ts b/src/musicbrainz.types.ts index fb5f6c2a..081e3f15 100644 --- a/src/musicbrainz.types.ts +++ b/src/musicbrainz.types.ts @@ -64,6 +64,15 @@ export interface IArtistCredit { name: string; } +export interface ICollection extends IEntity { + type: string; + name: string; + 'type-id': string; + 'recording-count': number; + editor: string; + 'entity-type': string; +} + export interface IEvent extends IEntity { cancelled: boolean; type: string; @@ -615,7 +624,7 @@ export interface IBrowseArtistsResult { } export interface IBrowseCollectionsResult { - collections: IArtist[]; + collections: ICollection[]; 'collection-count': number; 'collection-offset': number; } diff --git a/test/test-musicbrainz-api.ts b/test/test-musicbrainz-api.ts index fdfecaf6..983e32c9 100644 --- a/test/test-musicbrainz-api.ts +++ b/test/test-musicbrainz-api.ts @@ -160,6 +160,12 @@ describe('MusicBrainz-api', function () { assert.strictEqual(artist.name, 'Stromae'); }); + it('collection', async () => { + const collection = await mbApi.lookupCollection(mbid.collection.Ringtone); + assert.strictEqual(collection.id, mbid.collection.Ringtone); + assert.strictEqual(collection.name, 'Ringtone'); + }); + it('instrument', async () => { const instrument = await mbApi.lookupInstrument(mbid.instrument.spanishAcousticGuitar); assert.strictEqual(instrument.id, mbid.instrument.spanishAcousticGuitar);