Skip to content

Commit

Permalink
Add lookupCollection function
Browse files Browse the repository at this point in the history
  • Loading branch information
Borewit committed Aug 7, 2022
1 parent 6f13b87 commit 25597a7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/musicbrainz-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -292,6 +299,15 @@ export class MusicBrainzApi {
return this.lookupEntity<mb.IArtist, ArtistIncludes>('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<mb.ICollection> {
return this.lookupEntity<mb.ICollection, ArtistIncludes>('collection', collectionId, inc);
}

/**
* Lookup instrument
* @param artistId Instrument MBID
Expand Down
11 changes: 10 additions & 1 deletion src/musicbrainz.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -615,7 +624,7 @@ export interface IBrowseArtistsResult {
}

export interface IBrowseCollectionsResult {
collections: IArtist[];
collections: ICollection[];
'collection-count': number;
'collection-offset': number;
}
Expand Down
6 changes: 6 additions & 0 deletions test/test-musicbrainz-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 25597a7

Please sign in to comment.