Skip to content

Commit

Permalink
chore: add explicit returns to meed jsr publish criteria
Browse files Browse the repository at this point in the history
  • Loading branch information
MellKam committed Feb 19, 2024
1 parent ea2a7ed commit 59fbcea
Show file tree
Hide file tree
Showing 19 changed files with 250 additions and 171 deletions.
6 changes: 3 additions & 3 deletions client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ export class SpotifyError extends Error {
super(message, options);
}

get url() {
get url(): string {
return this.response.url;
}

get status() {
get status(): number {
return this.response.status;
}
}
Expand Down Expand Up @@ -142,7 +142,7 @@ export class SpotifyClient implements HTTPClient {
: "https://api.spotify.com/";
}

fetch(path: string, opts: FetchLikeOptions = {}) {
fetch(path: string, opts: FetchLikeOptions = {}): Promise<Response> {
const url = new URL(path, this.baseUrl);
if (opts.query) {
for (const key in opts.query) {
Expand Down
34 changes: 23 additions & 11 deletions endpoints/album/album.endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const getAlbum = async (
client: HTTPClient,
albumId: string,
market?: string,
) => {
): Promise<Album> => {
const res = await client.fetch("/v1/albums/" + albumId, {
query: { market },
});
Expand All @@ -33,7 +33,7 @@ export const getAlbums = async (
client: HTTPClient,
albumIds: string[],
market?: string,
) => {
): Promise<Album[]> => {
const res = await client.fetch("/v1/albums", {
query: { market, ids: albumIds },
});
Expand Down Expand Up @@ -62,7 +62,7 @@ export const getAlbumTracks = async (
client: HTTPClient,
albumId: string,
options?: GetAlbumTrackOpts,
) => {
): Promise<PagingObject<SimplifiedTrack>> => {
const res = await client.fetch(`/v1/albums/${albumId}/tracks`, {
query: options,
});
Expand All @@ -88,7 +88,7 @@ export type GetSavedAlbumsOpts = Prettify<
export const getSavedAlbums = async (
client: HTTPClient,
options?: GetSavedAlbumsOpts,
) => {
): Promise<PagingObject<SavedAlbum>> => {
const res = await client.fetch("/v1/me/albums", { query: options });
return res.json() as Promise<PagingObject<SavedAlbum>>;
};
Expand All @@ -99,7 +99,10 @@ export const getSavedAlbums = async (
* @param client Spotify HTTPClient
* @param albumIds List of the Spotify IDs for the albums. Maximum: 20 IDs
*/
export const saveAlbums = (client: HTTPClient, albumIds: string[]) => {
export const saveAlbums = (
client: HTTPClient,
albumIds: string[],
): Promise<Response> => {
return client.fetch("/v1/me/albums", {
method: "PUT",
query: { ids: albumIds },
Expand All @@ -112,7 +115,10 @@ export const saveAlbums = (client: HTTPClient, albumIds: string[]) => {
* @param client Spotify HTTPClient
* @param albums_id The Spotify ID of the album
*/
export const saveAlbum = (client: HTTPClient, albumId: string) => {
export const saveAlbum = (
client: HTTPClient,
albumId: string,
): Promise<Response> => {
return saveAlbums(client, [albumId]);
};

Expand All @@ -122,7 +128,10 @@ export const saveAlbum = (client: HTTPClient, albumId: string) => {
* @param client Spotify HTTPClient
* @param albumIds List of the Spotify IDs for the albums. Maximum: 20 IDs
*/
export const removeSavedAlbums = (client: HTTPClient, albumIds: string[]) => {
export const removeSavedAlbums = (
client: HTTPClient,
albumIds: string[],
): Promise<Response> => {
return client.fetch("/v1/me/albums", {
method: "DELETE",
query: { ids: albumIds },
Expand All @@ -135,7 +144,10 @@ export const removeSavedAlbums = (client: HTTPClient, albumIds: string[]) => {
* @param client Spotify HTTPClient
* @param albumId The Spotify ID of the album
*/
export const removeSavedAlbum = (client: HTTPClient, albumId: string) => {
export const removeSavedAlbum = (
client: HTTPClient,
albumId: string,
): Promise<Response> => {
return removeSavedAlbums(client, [albumId]);
};

Expand All @@ -148,7 +160,7 @@ export const removeSavedAlbum = (client: HTTPClient, albumId: string) => {
export const checkIfAlbumsSaved = async (
client: HTTPClient,
albumIds: string[],
) => {
): Promise<boolean[]> => {
const res = await client.fetch("/v1/me/albums/contains", {
query: { ids: albumIds },
});
Expand All @@ -164,7 +176,7 @@ export const checkIfAlbumsSaved = async (
export const checkIfAlbumSaved = async (
client: HTTPClient,
albumId: string,
) => {
): Promise<boolean> => {
return (await checkIfAlbumsSaved(client, [albumId]))[0]!;
};

Expand All @@ -188,7 +200,7 @@ export type GetNewReleasesOpts = Prettify<
export const getNewReleases = async (
client: HTTPClient,
options?: GetNewReleasesOpts,
) => {
): Promise<PagingObject<SimplifiedAlbum>> => {
const res = await client.fetch("/v1/browse/new-releases", { query: options });
return ((await res.json()) as { albums: PagingObject<SimplifiedAlbum> })
.albums;
Expand Down
13 changes: 8 additions & 5 deletions endpoints/artist/artist.endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import type { Artist } from "./artist.types.ts";
* @param client Spotify HTTPClient
* @param artistId Spotify artist ID
*/
export const getArtist = async (client: HTTPClient, artistId: string) => {
export const getArtist = async (
client: HTTPClient,
artistId: string,
): Promise<Artist> => {
const res = await client.fetch("/v1/artists/" + artistId);
return res.json() as Promise<Artist>;
};
Expand All @@ -25,7 +28,7 @@ export const getArtist = async (client: HTTPClient, artistId: string) => {
export const getArtists = async (
client: HTTPClient,
artistIds: string[],
) => {
): Promise<Artist[]> => {
const res = await client.fetch("/v1/artists", { query: { ids: artistIds } });
return ((await res.json()) as { artists: Artist[] }).artists;
};
Expand Down Expand Up @@ -55,7 +58,7 @@ export const getArtistAlbums = async (
client: HTTPClient,
artistId: string,
options?: GetArtistAlbumsOpts,
) => {
): Promise<PagingObject<SimplifiedAlbum>> => {
const res = await client.fetch(`/v1/artists/${artistId}/albums`, {
query: options,
});
Expand All @@ -73,7 +76,7 @@ export const getArtistTopTracks = async (
client: HTTPClient,
artistId: string,
market?: string,
) => {
): Promise<Track[]> => {
const res = await client.fetch(`/v1/artists/${artistId}/top-tracks`, {
query: { market },
});
Expand All @@ -90,7 +93,7 @@ export const getArtistTopTracks = async (
export const getArtistRelatedArtists = async (
client: HTTPClient,
artistId: string,
) => {
): Promise<Artist[]> => {
const res = await client.fetch(`/v1/artists/${artistId}/related-artists`);
return ((await res.json()) as { artists: Artist[] }).artists;
};
35 changes: 12 additions & 23 deletions endpoints/audiobook/audiobook.endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { SimplifiedChapter } from "../chapter/chapter.types.ts";
import type { HTTPClient } from "../../client.ts";
import type { Prettify } from "../../shared.ts";
import type { PagingObject, PagingOptions } from "../general.types.ts";
import type { Audiobook, SimplifiedAudiobook } from "./audiobook.types.ts";
import type { Audiobook, SavedAudiobook } from "./audiobook.types.ts";

/**
* Get Spotify catalog information for a single Audiobook.
Expand All @@ -15,7 +15,7 @@ export const getAudiobook = async (
client: HTTPClient,
audiobookId: string,
market?: string,
) => {
): Promise<Audiobook> => {
const res = await client.fetch("/v1/audiobooks/" + audiobookId, {
query: { market },
});
Expand All @@ -33,7 +33,7 @@ export const getAudiobooks = async (
client: HTTPClient,
audiobookIds: string[],
market?: string,
) => {
): Promise<Audiobook[]> => {
const res = await client.fetch("/v1/audiobooks", {
query: { market, ids: audiobookIds },
});
Expand Down Expand Up @@ -62,7 +62,7 @@ export const getAudiobookChapters = async (
client: HTTPClient,
audiobookId: string,
options?: GetAudiobookChapterOpts,
) => {
): Promise<PagingObject<SimplifiedChapter>> => {
const res = await client.fetch(`/v1/audiobooks/${audiobookId}/chapters`, {
query: options,
});
Expand All @@ -88,20 +88,9 @@ export type GetSavedAudiobooksOpts = Prettify<
export const getSavedAudiobooks = async (
client: HTTPClient,
options?: GetSavedAudiobooksOpts,
) => {
): Promise<PagingObject<SavedAudiobook>> => {
const res = await client.fetch("/v1/me/audiobooks", { query: options });
return res.json() as Promise<
PagingObject<{
/**
* The date and time the audiobook was saved Timestamps are returned in ISO 8601 format as Coordinated Universal Time (UTC) with a zero offset: YYYY-MM-DDTHH:MM:SSZ.
*/
added_at: string;
/**
* Information about the audiobook.
*/
audiobook: SimplifiedAudiobook;
}>
>;
return res.json() as Promise<PagingObject<SavedAudiobook>>;
};

/**
Expand All @@ -113,7 +102,7 @@ export const getSavedAudiobooks = async (
export const saveAudiobooks = (
client: HTTPClient,
audiobookIds: string[],
) => {
): Promise<Response> => {
return client.fetch("/v1/me/audiobooks", {
method: "PUT",
query: { ids: audiobookIds },
Expand All @@ -129,7 +118,7 @@ export const saveAudiobooks = (
export const saveAudiobook = (
client: HTTPClient,
audiobookId: string,
) => {
): Promise<Response> => {
return saveAudiobooks(client, [audiobookId]);
};

Expand All @@ -142,7 +131,7 @@ export const saveAudiobook = (
export const removeSavedAudiobooks = (
client: HTTPClient,
audiobookIds: string[],
) => {
): Promise<Response> => {
return client.fetch("/v1/me/audiobooks", {
method: "DELETE",
query: { ids: audiobookIds },
Expand All @@ -158,7 +147,7 @@ export const removeSavedAudiobooks = (
export const removeSavedAudiobook = (
client: HTTPClient,
audiobookId: string,
) => {
): Promise<Response> => {
return removeSavedAudiobooks(client, [audiobookId]);
};

Expand All @@ -171,7 +160,7 @@ export const removeSavedAudiobook = (
export const checkIfAudiobooksSaved = async (
client: HTTPClient,
audiobookIds: string[],
) => {
): Promise<boolean[]> => {
const res = await client.fetch("/v1/me/audiobooks/contains", {
query: { ids: audiobookIds },
});
Expand All @@ -187,6 +176,6 @@ export const checkIfAudiobooksSaved = async (
export const checkIfAudiobookSaved = async (
client: HTTPClient,
audiobookId: string,
) => {
): Promise<boolean> => {
return (await checkIfAudiobooksSaved(client, [audiobookId]))[0]!;
};
11 changes: 11 additions & 0 deletions endpoints/audiobook/audiobook.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,14 @@ export interface Audiobook extends SimplifiedAudiobook {
*/
chapters: PagingObject<SimplifiedChapter>;
}

export type SavedAudiobook = {
/**
* The date and time the audiobook was saved Timestamps are returned in ISO 8601 format as Coordinated Universal Time (UTC) with a zero offset: YYYY-MM-DDTHH:MM:SSZ.
*/
added_at: string;
/**
* Information about the audiobook.
*/
audiobook: SimplifiedAudiobook;
};
4 changes: 2 additions & 2 deletions endpoints/category/category.endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export type GetBrowseCategoriesOpts = {
export const getBrowseCategories = async (
client: HTTPClient,
options?: GetBrowseCategoriesOpts,
) => {
): Promise<PagingObject<Category>> => {
const res = await client.fetch("/v1/browse/categories", {
query: options,
});
Expand Down Expand Up @@ -73,7 +73,7 @@ export const getBrowseCategory = async (
client: HTTPClient,
categoryId: string,
options?: GetBrowseCategoryOpts,
) => {
): Promise<Category> => {
const res = await client.fetch("/v1/browse/categories/" + categoryId, {
query: options,
});
Expand Down
4 changes: 2 additions & 2 deletions endpoints/chapter/chapter.endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const getChapter = async (
client: HTTPClient,
chapterId: string,
market?: string,
) => {
): Promise<Chapter> => {
const res = await client.fetch("/v1/chapters/" + chapterId, {
query: { market },
});
Expand All @@ -27,7 +27,7 @@ export const getChapters = async (
client: HTTPClient,
chapterIds: string[],
market?: string,
) => {
): Promise<Chapter[]> => {
const res = await client.fetch("/v1/chapters", {
query: { market, ids: chapterIds },
});
Expand Down
Loading

0 comments on commit 59fbcea

Please sign in to comment.