Skip to content

Commit

Permalink
fix: bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
FC5570 committed Apr 19, 2022
1 parent 0e1465d commit 15b23ef
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/lib/classes/Playlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class Playlist extends Base {
public snapshot_id!: string;

/**
* The playlist's public/private status: true the playlist is public, false the playlist is private, null the playlist status is not relevant.
* The playlist's public/private status: true the playlist is public, false the playlist is private, null if the playlist status is not relevant.
*/
public public!: APIPlaylist['public'];

Expand Down
2 changes: 1 addition & 1 deletion src/lib/classes/Track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class Track extends Base {
public disc_number!: number;

/**
* The disc number (usually 1 unless the album consists of more than one disc).
* The track length in milliseconds.
*/
public duration_ms!: number;

Expand Down
4 changes: 2 additions & 2 deletions src/managers/AlbumsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class AlbumsManager extends BaseManager {
* @param {number} [limit]: The maximum number of items to return. Default: 20. Minimum: 1. Maximum: 50.
* @param {string} [country]: An ISO 3166-1 alpha-2 country code. Supply this parameter to limit the response to one particular geographical market.
* @param {number} [offset]: The index of the first item to return. Default: 0 (the first item). Use with limit to get the next set of items.
* @returns {Promise<Track[]>}: An APIAlbumTrack object containing the tracks in the items property.
* @returns {Promise<Track[]>}: Array of Track objects
*/
public async getTracks(id: string, limit?: number, country?: string, offset?: number): Promise<Track[]> {
limit ??= 20;
Expand All @@ -82,7 +82,7 @@ export class AlbumsManager extends BaseManager {
* @param {string} [country]: An ISO 3166-1 alpha-2 country code. Supply this parameter to limit the response to one particular geographical market.
* @param {number} [limit]: The maximum number of items to return. Default: 20. Minimum: 1. Maximum: 50.
* @param {number} [offset]: The index of the first item to return. Default: 0 (the first item). Use with limit to get the next set of items.
* @returns {Promise<Album[]>} Objects of newly released albums.
* @returns {Promise<Album[]>} Array of Album objects
*/
public async getNewReleases(country?: string, limit?: number, offset?: number): Promise<Album[]> {
limit ??= 20;
Expand Down
4 changes: 2 additions & 2 deletions src/managers/CategoriesManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class CategoriesManager extends BaseManager {
* @param {string} id: The ID of the category.
* @param {string} [country]: An ISO 3166-1 alpha-2 country code. If specified, only the content available in this country will be returned, if not, the country of the current user will be used.
* @param {string} [locale]: The desired language, consisting of an ISO 639-1 language code and an ISO 3166-1 alpha-2 country code, joined by an underscore. For example: es_MX, meaning "Spanish (Mexico)". Provide this parameter if you want the category strings returned in a particular language. If not specified, the default, en_US (American English) will be used.
* @returns {Promise<Category>} The category
* @returns {Promise<Category>} Category object
*/
public async fetch(id: string, country?: string, locale?: string): Promise<Category> {
if (!id) throw new SpotifyTSError('MANAGER_MISSING_ARGUMENT', 'CategoriesManager', 'fetch', 'id');
Expand All @@ -30,7 +30,7 @@ export class CategoriesManager extends BaseManager {
/**
* Fetch several categories.
* @param {FetchSeveralOptions} [options]: The options for fetching categories.
* @returns {Promise<Category[]>} The categories.
* @returns {Promise<Category[]>} Array of Category objects.
*/
public async fetchSeveral(options?: FetchSeveralOptions): Promise<Category[]> {
const { query } = new RequestData({ query: {} });
Expand Down
4 changes: 2 additions & 2 deletions src/managers/EpisodesManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class EpisodesManager extends BaseManager {
* Fetch an episode by its Spotify ID.
* @param {string} id: The Spotify ID of the episode.
* @param {string} country: The ISO 3166-1 alpha-2 country code. This parameter is required due to a bug with the Spotify API not returning a valid response without the country parameter. See more here: https://stackoverflow.com/a/70476680/14950646
* @returns {Promise<Episode>} The fetched episode.
* @returns {Promise<Episode>} Episode object.
*/
public async fetch(id: string, country: string): Promise<Episode> {
if (!id) throw new SpotifyTSError('MANAGER_MISSING_ARGUMENT', 'EpisodesManager', 'fetch', 'id');
Expand All @@ -28,7 +28,7 @@ export class EpisodesManager extends BaseManager {
* Fetch several episodes by their Spotify IDs.
* @param {Array<string>} ids: The Spotify IDs of the episodes.
* @param {string} [country]: An ISO 3166-1 alpha-2 country code, if specified, returns only the content available in this country. If this argument is not specified, the country code of the user account will be used.
* @returns {Promise<Episode[]>} The fetched episodes.
* @returns {Promise<Episode[]>} Array of Episode objects.
*/
public async fetchSeveral(ids: string[], country?: string): Promise<Episode[]> {
if (!ids || !ids?.length) throw new SpotifyTSError('MANAGER_MISSING_ARGUMENT', 'EpisodesManager', 'fetch', 'ids');
Expand Down
4 changes: 4 additions & 0 deletions src/managers/GenresManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export class GeneresManager extends BaseManager {
super(client, 'recommendations/available-genre-seeds');
}

/**
* Retrieve a list of available genres seed parameter values for recommendations.
* @returns {Promise<string[]>} Array of strings
*/
public async fetchAvailableSeeds(): Promise<string[]> {
const { genres } = await super.get();
return genres;
Expand Down
4 changes: 4 additions & 0 deletions src/managers/MarketsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export class MarketsManager extends BaseManager {
super(client, 'markets');
}

/**
* Get a list of markets where Spotify is available.
* @returns {Promise<string[]>} Array of strings
*/
public async fetchAvailable(): Promise<string[]> {
const { markets } = await super.get();
return markets;
Expand Down
2 changes: 1 addition & 1 deletion src/managers/PlaylistsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class PlaylistsManager extends BaseManager {
* Fetch a playlist using its Spotify ID.
* @param {string} id: The Spotify ID of the playlist.
* @param {string} [country]: An ISO 3166-1 alpha-2 country code. If specified, only the content available in this country will be returned, if not, the country of the current user will be used.
* @returns {Promise<Playlist>} The playlist
* @returns {Promise<Playlist>} Playlist object
*/
public async fetch(id: string, country?: string): Promise<Playlist> {
if (!id) throw new SpotifyTSError('MANAGER_MISSING_ARGUMENT', 'PlaylistsManager', 'fetch', 'id');
Expand Down
7 changes: 4 additions & 3 deletions src/managers/SearchManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ export class SearchManager extends BaseManager {
* @param {SearchOptions['limit']} [options.limit]: The maximum number of results to return. Default: 20. Minimum: 1. Maximum: 50.
* @param {SearchOptions['market']} [options.market]: An ISO 3166-1 alpha-2 country code. If provided, only content available in this market will be returned.
* @param {SearchOptions['offset']} [options.offset]: The index of the first result to return. Use with limit to get the next page of search results. Default value 0, maximum 1000.
* @returns {Promise<(Track | Artist | Album | Playlist | Show | Episode)[]>} The search results.
*/
public async search(options: SearchOptions) {
public async search(options: SearchOptions): Promise<(Track | Artist | Album | Playlist | Show | Episode)[]> {
let { query, type, include_external, limit, market, offset } = options;

if (!query) throw new SpotifyTSError('MANAGER_ARGUMENT_MISSING', 'SearchesManager', 'search', 'query');
if (!type) throw new SpotifyTSError('MANAGER_ARGUMENT_MISSING', 'SearchesManager', 'search', 'type');
if (!query) throw new SpotifyTSError('MANAGER_MISSING_ARGUMENT', 'SearchesManager', 'search', 'query');
if (!type) throw new SpotifyTSError('MANAGER_MISSING_ARGUMENT', 'SearchesManager', 'search', 'type');

if (typeof query !== 'string') throw new SpotifyTSError('MANAGER_ARGUMENT_INVALID_TYPE', 'SearchManager', 'search', 'query', 'string');
if (!Array.isArray(type)) throw new SpotifyTSError('MANAGER_ARGUMENT_INVALID_TYPE', 'SearchManager', 'search', 'type', 'SearchOptionsType[]');
Expand Down
7 changes: 4 additions & 3 deletions src/managers/ShowsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class ShowsManager extends BaseManager {
* Get a show by its Spotify ID.
* @param {string} id: The ID of the show.
* @param {string} [country]: An ISO 3166-1 alpha-2 country code. This is required as the Spotify API has a bug due to which a 404 error is returned if no country parameter is specified.
* @returns {Promise<Show>} The show.
* @returns {Promise<Show>} Show object.
*/
public async fetch(id: string, country: string): Promise<Show> {
if (!id) throw new SpotifyTSError('MANAGER_MISSING_ARGUMENT', 'ShowsManager', 'fetch', 'id');
Expand All @@ -28,7 +28,7 @@ export class ShowsManager extends BaseManager {
* Get several shows by their Spotify IDs.
* @param {Array<string>} ids: The IDs of the shows.
* @param {string} [country]: An ISO 3166-1 alpha-2 country code. If specified, only the content available in this country will be returned, if not, the country of the current user will be used.
* @returns {Promise<Show[]>}
* @returns {Promise<Show[]>} Array of Show objects.
*/
public async fetchSeveral(ids: string[], country?: string): Promise<Show[]> {
if (!ids || !ids?.length) throw new SpotifyTSError('MANAGER_MISSING_ARGUMENT', 'ShowsManager', 'fetchSeveral', 'ids');
Expand Down Expand Up @@ -56,8 +56,9 @@ export class ShowsManager extends BaseManager {
* @param {number} [limit]: The maximum number of episodes to return. Default: 20. Minimum: 1. Maximum: 50.
* @param {number} [offset]: The index of the first episode to return. Default: 0 (the first object). Use with limit to get the next set of episodes.
* @param {string} [country]: An ISO 3166-1 alpha-2 country code. If specified, only the content available in this country will be returned, if not, the country of the current user will be used.
* @returns {Promise<Episode[]>} Array of Episode objects.
*/
public async getEpisodes(id: string, limit?: number, offset?: number, country?: string) {
public async getEpisodes(id: string, limit?: number, offset?: number, country?: string): Promise<Episode[]> {
limit ??= 20;
offset ??= 0;

Expand Down
4 changes: 2 additions & 2 deletions src/managers/TracksManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class TracksManager extends BaseManager {
* Fetch a Spotify Track by its ID.
* @param {string} id: The Spotify ID of the track.
* @param {string} [country]: An ISO 3166-1 alpha-2 country code, if specified, returns only the content available in this country. If this argument is not specified, the country code of the user account will be used.
* @returns {Promise<Track>} The fetched track.
* @returns {Promise<Track>} Track object.
*/
public async fetch(id: string, country?: string): Promise<Track> {
if (!id) throw new SpotifyTSError('MANAGER_MISSING_ARGUMENT', 'TracksManager', 'fetch', 'id');
Expand All @@ -28,7 +28,7 @@ export class TracksManager extends BaseManager {
* Fetch multiple Spotify Tracks by their IDs.
* @param {string[]} ids: The Spotify IDs of the tracks.
* @param {string} [country]: An ISO 3166-1 alpha-2 country code, if specified, returns only the content available in this country. If this argument is not specified, the country code of the user account will be used.
* @returns {Promise<Track[]>} The fetched tracks.
* @returns {Promise<Track[]>} Array of fetched tracks
*/
public async fetchSeveral(ids: string[], country?: string): Promise<Track[]> {
if (!ids || !ids.length) throw new SpotifyTSError('MANAGER_MISSING_ARGUMENT', 'TracksManager', 'fetchSeveral', 'ids');
Expand Down

0 comments on commit 15b23ef

Please sign in to comment.