From 06fcd0db02bef7e1c6235940ca8443aaf0a7c1cf Mon Sep 17 00:00:00 2001 From: Atanas Atanasov Date: Tue, 31 Oct 2023 09:07:36 +0200 Subject: [PATCH] Usage and typings updates (#28) --- .codebeatsettings | 28 + .env.example | 1 + .github/workflows/build.yml | 9 +- .gitignore | 1 + .npmignore | 4 + demo/index.js | 86 +++ package.json | 7 +- src/album.ts | 103 +-- src/api-request.ts | 104 +-- src/artist.ts | 155 ++-- src/auth.ts | 40 +- src/chart.ts | 41 +- src/geo.ts | 37 +- src/index.ts | 23 +- src/library.ts | 23 +- src/tag.ts | 78 +- src/track.ts | 174 ++--- src/types.ts | 1442 +++++++++++++++++++++++++++++++++++ src/user.ts | 166 ++-- tsconfig.json | 14 +- yarn.lock | 5 + 21 files changed, 1993 insertions(+), 548 deletions(-) create mode 100644 .codebeatsettings create mode 100644 .env.example create mode 100644 demo/index.js create mode 100644 src/types.ts diff --git a/.codebeatsettings b/.codebeatsettings new file mode 100644 index 0000000..8a42768 --- /dev/null +++ b/.codebeatsettings @@ -0,0 +1,28 @@ +{ + "TYPESCRIPT": { + "ABC": [ + 30, + 60, + 120, + 180 + ], + "LOC": [ + 75, + 120, + 180, + 240 + ], + "TOTAL_LOC": [ + 600, + 750, + 960, + 1350 + ], + "BLOCK_NESTING": [ + 9, + 12, + 15, + 18 + ] + } +} diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..eda8a49 --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +LAST_FM_API_KEY="" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d529105..d6f035c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,5 +16,10 @@ jobs: uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - - run: yarn - - run: yarn build + - name: Build + run: | + yarn + yarn build + yarn demo + env: + LAST_FM_API_KEY: ${{ secrets.LAST_FM_API_KEY }} diff --git a/.gitignore b/.gitignore index fc73a81..2ba934c 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,5 @@ ehthumbs.db Thumbs.db # Project specific +.env /dist diff --git a/.npmignore b/.npmignore index c730ff1..e66b832 100644 --- a/.npmignore +++ b/.npmignore @@ -21,6 +21,9 @@ Thumbs.db .github _config.yml _.config.yml +.codebeatsettings +.env +.env.example .editorconfig .gitattributes .gitignore @@ -37,3 +40,4 @@ tslint.json yarn.lock !dist +demo diff --git a/demo/index.js b/demo/index.js new file mode 100644 index 0000000..914d075 --- /dev/null +++ b/demo/index.js @@ -0,0 +1,86 @@ +// @ts-nocheck + +import { config } from 'dotenv'; + +import { + LastFMGeo, + LastFMTag, + LastFMUser, + LastFMAlbum, + LastFMChart, + LastFMTrack, + LastFMArtist, + LastFMLibrary +} from '../dist/index.js'; + +config(); + +const API_KEY = process.env.LAST_FM_API_KEY; + +const geo = new LastFMGeo(API_KEY); +const tag = new LastFMTag(API_KEY); +const user = new LastFMUser(API_KEY); +const album = new LastFMAlbum(API_KEY); +const chart = new LastFMChart(API_KEY); +const track = new LastFMTrack(API_KEY); +const artist = new LastFMArtist(API_KEY); +const library = new LastFMLibrary(API_KEY); + +const print = r => console.log(JSON.stringify(r, null, 2)); + +geo.getTopArtists({ country: 'Bulgaria', limit: 2 }).then(print); +geo.getTopTracks({ country: 'Bulgaria', limit: 2 }).then(print); + +tag.getInfo({ tag: 'techno', limit: 2 }).then(print); +tag.getSimilar({ tag: 'techno', limit: 2 }).then(print); +tag.getTopAlbums({ tag: 'techno', limit: 2 }).then(print); +tag.getTopArtists({ tag: 'techno', limit: 2 }).then(print); +tag.getTopTags().then(print); +tag.getTopTracks({ tag: 'techno', limit: 2 }).then(print); +tag.getWeeklyChartList({ tag: 'techno' }).then(print); + +user.getFriends({ user: 'scriptex', limit: 2 }).then(print); +user.getInfo({ user: 'scriptex' }).then(print); +user.getLovedTracks({ user: 'scriptex', limit: 2 }).then(print); +user.getPersonalTags({ user: 'scriptex', taggingtype: 'album', tag: 'techno', limit: 2 }).then(print); +user.getPersonalTags({ user: 'scriptex', taggingtype: 'artist', tag: 'techno', limit: 2 }).then(print); +user.getPersonalTags({ user: 'scriptex', taggingtype: 'track', tag: 'techno', limit: 2 }).then(print); +user.getRecentTracks({ user: 'scriptex', limit: 2 }).then(print); +user.getTopAlbums({ user: 'scriptex', limit: 2 }).then(print); +user.getTopArtists({ user: 'scriptex', limit: 2 }).then(print); +user.getTopTags({ user: 'scriptex', limit: 2 }).then(print); +user.getTopTracks({ user: 'scriptex', limit: 2 }).then(print); +user.getWeeklyAlbumChart({ user: 'scriptex', limit: 2 }).then(print); +user.getWeeklyArtistChart({ user: 'scriptex', limit: 2 }).then(print); +user.getWeeklyChartList({ user: 'scriptex' }).then(print); +user.getWeeklyTrackChart({ user: 'scriptex' }).then(print); + +album.getInfo({ album: 'The Fat of The Land', artist: 'The Prodigy' }).then(print); +//NOSONAR +// album.getTags({ album: 'The Fat of The Land', artist: 'The Prodigy' }).then(print); +album.getTopTags({ album: 'The Fat of The Land', artist: 'The Prodigy' }).then(print); +album.search({ album: 'The Fat of The Land', artist: 'The Prodigy' }).then(print); + +chart.getTopArtists({ limit: 2 }).then(print); +chart.getTopTags({ limit: 2 }).then(print); +chart.getTopTracks({ limit: 2 }).then(print); + +track.getCorrection({ track: 'Firestarter', artist: 'The Prodigy' }).then(print); +track.getInfo({ track: 'Firestarter', artist: 'The Prodigy' }).then(print); +track.getSimilar({ track: 'Firestarter', artist: 'The Prodigy', limit: 2 }).then(print); +//NOSONAR +// track.getTags({ track: 'Firestarter', artist: 'The Prodigy', limit: 2 }).then(print); +track.getTopTags({ track: 'Firestarter', artist: 'The Prodigy', limit: 2 }).then(print); +track.search({ track: 'Firestarter', artist: 'The Prodigy', limit: 2 }).then(print); + +artist.getCorrection({ artist: 'The Prodigy' }).then(print); +artist.getInfo({ artist: 'The Prodigy' }).then(print); +artist.getSimilar({ artist: 'The Prodigy', limit: 2 }).then(print); +//NOSONAR +// artist.getTags({ artist: 'The Prodigy' }).then(print); +artist.getTopAlbums({ artist: 'The Prodigy', limit: 2 }).then(print); +artist.getTopTags({ artist: 'The Prodigy' }).then(print); +artist.getTopTracks({ artist: 'The Prodigy', limit: 2 }).then(print); +artist.search({ artist: 'The Prodigy', limit: 2 }).then(print); + +library.getArtists({ user: 'scriptex', limit: 2 }).then(print); diff --git a/package.json b/package.json index b2c707c..53ed5eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lastfm-ts-api", - "version": "1.0.2", + "version": "2.0.0", "description": "An API client for the Last.FM API written in TypeScript", "keywords": [ "Last.FM", @@ -17,6 +17,7 @@ "author": "Atanas Atanasov (https://atanas.info)", "funding": "https://github.com/sponsors/scriptex", "main": "dist/index.js", + "type": "module", "types": "dist/index.d.ts", "repository": { "type": "git", @@ -24,11 +25,13 @@ }, "scripts": { "watch": "tsc -w", - "build": "tsc" + "build": "tsc", + "demo": "node demo/index.js" }, "dependencies": {}, "devDependencies": { "@types/node": "20.8.9", + "dotenv": "16.3.1", "tslib": "2.6.2", "typescript": "5.2.2" } diff --git a/src/album.ts b/src/album.ts index 9cac6e3..5cf71ce 100644 --- a/src/album.ts +++ b/src/album.ts @@ -1,60 +1,21 @@ -import { LastFM } from './base'; -import { LastFMParam, LastFMApiRequest, LastFMRequestParams, LastFMUnknownFunction } from './api-request'; - -export interface LastFMAlbumParams { - readonly album: string; - readonly artist: string; -} - -export interface LastFMAlbumOptionalParams { - readonly mbid?: string; - readonly autocorrect?: 0 | 1; -} - -export interface LastFMAlbumAddTagsParams extends LastFMRequestParams, LastFMAlbumParams { - readonly tags: string | string[]; -} - -export interface LastFMAlbumGetInfoParams - extends LastFMRequestParams<0 | 1 | void>, - LastFMAlbumParams, - LastFMAlbumOptionalParams { - readonly lang?: string; - readonly username?: string; -} - -export interface LastFMAlbumGetTagsParams - extends LastFMRequestParams<0 | 1 | void>, - LastFMAlbumParams, - LastFMAlbumOptionalParams { - readonly user?: string; -} - -export interface LastFMAlbumGetTopTagsParams - extends LastFMRequestParams<0 | 1 | void>, - LastFMAlbumParams, - LastFMAlbumOptionalParams {} - -export interface LastFMAlbumRemoveLastFMTagParams extends LastFMRequestParams, LastFMAlbumParams { - readonly tag: string; -} - -export interface LastFMAlbumSearchParams extends LastFMRequestParams { - readonly page?: number; - readonly album: string; - readonly limit?: number; -} +import { LastFM } from './base.js'; +import { LastFMApiRequest } from './api-request.js'; +import { + LastFMUnknownFunction, + LastFMAlbumSearchParams, + LastFMAlbumAddTagsParams, + LastFMAlbumGetInfoParams, + LastFMAlbumGetTagsParams, + LastFMAlbumSearchResponse, + LastFMAlbumGetInfoResponse, + LastFMAlbumGetTagsResponse, + LastFMAlbumGetTopTagsParams, + LastFMAlbumRemoveLastFMTagParams +} from './types.js'; export class LastFMAlbum extends LastFM { - constructor(apiKey: string, secret?: string, sessionKey?: string) { - super(apiKey, secret, sessionKey); - } - - public addTags( - params: LastFMAlbumAddTagsParams, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + public addTags(params: LastFMAlbumAddTagsParams, callback?: LastFMUnknownFunction): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -67,9 +28,9 @@ export class LastFMAlbum extends LastFM { public getInfo( params: LastFMAlbumGetInfoParams, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -80,9 +41,9 @@ export class LastFMAlbum extends LastFM { public getTags( params: LastFMAlbumGetTagsParams, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -93,9 +54,9 @@ export class LastFMAlbum extends LastFM { public getTopTags( params: LastFMAlbumGetTopTagsParams, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -104,11 +65,8 @@ export class LastFMAlbum extends LastFM { .send(callback); } - public removeTag( - params: LastFMAlbumRemoveLastFMTagParams, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + public removeTag(params: LastFMAlbumRemoveLastFMTagParams, callback?: LastFMUnknownFunction): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -119,8 +77,11 @@ export class LastFMAlbum extends LastFM { .send('POST', callback); } - public search(params: LastFMAlbumSearchParams, callback: LastFMUnknownFunction): Promise | void { - return new LastFMApiRequest() + public search( + params: LastFMAlbumSearchParams, + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, diff --git a/src/api-request.ts b/src/api-request.ts index 2040d9c..56e5d05 100644 --- a/src/api-request.ts +++ b/src/api-request.ts @@ -1,20 +1,17 @@ -import { createHash } from 'crypto'; -import { parse, stringify } from 'querystring'; -import { request, RequestOptions } from 'https'; +import { createHash } from 'node:crypto'; +import { parse, stringify } from 'node:querystring'; +import { request, RequestOptions } from 'node:https'; -export type LastFMUnknownFunction = (...args: unknown[]) => unknown; -export type LastFMParam = string | string[]; -export type LastFMParams = Record; -export type LastFMRequestParams = Record; +import { LastFMParams, LastFMUnknownFunction } from './types.js'; -export class LastFMApiRequest { +export class LastFMApiRequest { private params: Map = new Map(); constructor() { this.params.set('format', 'json'); } - public set(params: LastFMParams): LastFMApiRequest { + public set

(params: LastFMParams): this { Object.entries(params).forEach(([key, value]) => { if (typeof value !== 'undefined') { this.params.set(key, value); @@ -24,7 +21,7 @@ export class LastFMApiRequest { return this; } - public sign(secret?: string): LastFMApiRequest { + public sign(secret?: string): this { const paramsObj: LastFMParams = this.setParams(); const paramsObjParsed = parse(stringify(paramsObj)); @@ -59,19 +56,10 @@ export class LastFMApiRequest { return this; } - public send( - method?: string | LastFMUnknownFunction, - callback?: LastFMUnknownFunction - ): void | Promise { - callback = - callback === undefined - ? typeof method === 'function' - ? method - : undefined - : typeof callback === 'function' - ? callback - : undefined; - method = typeof method === 'string' ? method : undefined; + public send(method?: string | LastFMUnknownFunction, callback?: LastFMUnknownFunction): Promise { + callback = this.getCallback(method, callback); + + method = this.getMethod(method); if (this.params.has('callback')) { this.params.delete('callback'); @@ -79,23 +67,9 @@ export class LastFMApiRequest { const paramsObj: LastFMParams = this.setParams(); const paramsStr = stringify(paramsObj); + const options = this.getOptions(method, paramsStr); - const options: RequestOptions = { - hostname: 'ws.audioscrobbler.com', - path: '/2.0' - }; - - if (method === 'POST') { - options.method = 'POST'; - options.headers = { - 'Content-Length': Buffer.byteLength(paramsStr), - 'Content-Type': 'application/x-www-form-urlencoded' - }; - } else { - options.path += `?${paramsStr}`; - } - - const LastFMapiRequest = new Promise((resolve, reject) => { + const LastFMapiRequest = new Promise((resolve, reject) => { const httpRequest = request(options, httpResponse => { let data = ''; @@ -112,29 +86,27 @@ export class LastFMApiRequest { } httpRequest.end(); - }).then(apiResponse => { + }).then((response: string) => { let data; try { - data = JSON.parse(apiResponse as string); + data = JSON.parse(response); } catch (err) { - throw new Error('Unable to parse API response to JSON'); + throw new Error(`lastfm-ts-api: Unable to parse LastFM API response to JSON. API response is ${err}`); } - if (data.error) { - throw new Error(data.message); + if (data?.error) { + throw new Error(`lastfm-ts-api: ${data?.message ?? 'LastFM API returned an error.'}`); } return data; }); if (callback && typeof callback === 'function') { - LastFMapiRequest.then( + return LastFMapiRequest.then( data => callback!(null, data), err => callback!(err, null) - ); - - return undefined; + ) as typeof LastFMapiRequest; } return LastFMapiRequest; @@ -151,6 +123,42 @@ export class LastFMApiRequest { return result; } + + private getCallback( + method?: string | LastFMUnknownFunction, + callback?: LastFMUnknownFunction + ): LastFMUnknownFunction | undefined { + return callback === undefined + ? typeof method === 'function' + ? method + : undefined + : typeof callback === 'function' + ? callback + : undefined; + } + + private getMethod(method?: string | LastFMUnknownFunction): string | LastFMUnknownFunction | undefined { + return typeof method === 'string' ? method : undefined; + } + + private getOptions(method: string | LastFMUnknownFunction | undefined, params: string): RequestOptions { + const options: RequestOptions = { + hostname: 'ws.audioscrobbler.com', + path: '/2.0' + }; + + if (method === 'POST') { + options.method = 'POST'; + options.headers = { + 'Content-Length': Buffer.byteLength(params), + 'Content-Type': 'application/x-www-form-urlencoded' + }; + } else { + options.path += `?${params}`; + } + + return options; + } } export default LastFMApiRequest; diff --git a/src/artist.ts b/src/artist.ts index c37c9d2..76e6ca7 100644 --- a/src/artist.ts +++ b/src/artist.ts @@ -1,79 +1,30 @@ -import { LastFM } from './base'; -import { LastFMParam, LastFMApiRequest, LastFMRequestParams, LastFMUnknownFunction } from './api-request'; - -export interface LastFMArtistParams extends LastFMRequestParams { - readonly artist: string; -} - -export interface LastFMArtistAddTagsParams extends LastFMRequestParams, LastFMArtistParams { - readonly tags: string | string[]; -} - -export interface LastFMArtistGetInfoParams extends LastFMRequestParams<0 | 1 | void> { - readonly lang?: string; - readonly mbid?: string; - readonly artist: string; - readonly username?: string; - readonly autocorrect?: 0 | 1; -} - -export interface LastFMArtistGetSimilarParams extends LastFMRequestParams<0 | 1 | void | number> { - readonly mbid?: string; - readonly limit?: number; - readonly artist: string; - readonly autocorrect?: 0 | 1; -} - -export interface LastFMArtistGetTagsParams extends LastFMRequestParams<0 | 1 | void> { - readonly mbid?: string; - readonly user?: string; - readonly artist: string; - readonly autocorrect?: 0 | 1; -} - -export interface LastFMArtistGetTopAlbumsParams extends LastFMRequestParams<0 | 1 | void | number> { - readonly mbid?: string; - readonly page?: number; - readonly limit?: number; - readonly artist: string; - readonly autocorrect?: 0 | 1; -} - -export interface LastFMArtistGetTopTagsParams extends LastFMRequestParams<0 | 1 | void> { - readonly mbid?: string; - readonly artist: string; - readonly autocorrect?: 0 | 1; -} - -export interface LastFMArtistGetTopTracksParams extends LastFMRequestParams<0 | 1 | void | number> { - readonly mbid?: string; - readonly page?: number; - readonly limit?: number; - readonly artist: string; - readonly autocorrect?: 0 | 1; -} - -export interface LastFMArtistRemoveLastFMTagParams extends LastFMRequestParams { - readonly tag: string; - readonly artist: string; -} - -export interface LastFMArtistSearchParams extends LastFMRequestParams { - readonly page?: number; - readonly limit?: number; - readonly artist: string; -} +import LastFMApiRequest from './api-request.js'; +import { LastFM } from './base.js'; +import { + LastFMArtistParams, + LastFMUnknownFunction, + LastFMArtistSearchParams, + LastFMArtistAddTagsParams, + LastFMArtistGetInfoParams, + LastFMArtistGetTagsParams, + LastFMArtistSearchResponse, + LastFMArtistGetInfoResponse, + LastFMArtistGetTagsResponse, + LastFMArtistGetSimilarParams, + LastFMArtistGetTopTagsParams, + LastFMArtistGetSimilarResponse, + LastFMArtistGetTopAlbumsParams, + LastFMArtistGetTopTagsResponse, + LastFMArtistGetTopTracksParams, + LastFMArtistGetTopAlbumsResponse, + LastFMArtistGetTopTracksResponse, + LastFMArtistGetCorrectionResponse, + LastFMArtistRemoveLastFMTagParams +} from './types.js'; export class LastFMArtist extends LastFM { - constructor(apiKey: string, secret?: string, sessionKey?: string) { - super(apiKey, secret, sessionKey); - } - - public addTags( - params: LastFMArtistAddTagsParams, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + public addTags(params: LastFMArtistAddTagsParams, callback?: LastFMUnknownFunction): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -86,9 +37,9 @@ export class LastFMArtist extends LastFM { public getCorrection( params: LastFMArtistParams, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -99,9 +50,9 @@ export class LastFMArtist extends LastFM { public getInfo( params: LastFMArtistGetInfoParams, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -112,9 +63,9 @@ export class LastFMArtist extends LastFM { public getSimilar( params: LastFMArtistGetSimilarParams, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -125,9 +76,9 @@ export class LastFMArtist extends LastFM { public getTags( params: LastFMArtistGetTagsParams, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -138,9 +89,9 @@ export class LastFMArtist extends LastFM { public getTopAlbums( params: LastFMArtistGetTopAlbumsParams, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -151,9 +102,9 @@ export class LastFMArtist extends LastFM { public getTopTags( params: LastFMArtistGetTopTagsParams, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -164,9 +115,9 @@ export class LastFMArtist extends LastFM { public getTopTracks( params: LastFMArtistGetTopTracksParams, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -175,11 +126,8 @@ export class LastFMArtist extends LastFM { .send(callback); } - public removeTag( - params: LastFMArtistRemoveLastFMTagParams, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + public removeTag(params: LastFMArtistRemoveLastFMTagParams, callback?: LastFMUnknownFunction): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -190,8 +138,11 @@ export class LastFMArtist extends LastFM { .send('POST', callback); } - public search(params: LastFMArtistSearchParams, callback: LastFMUnknownFunction): Promise | void { - return new LastFMApiRequest() + public search( + params: LastFMArtistSearchParams, + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, diff --git a/src/auth.ts b/src/auth.ts index 49e9998..299c6bc 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -1,25 +1,19 @@ -import { LastFM } from './base'; -import { LastFMParam, LastFMApiRequest, LastFMRequestParams, LastFMUnknownFunction } from './api-request'; - -export interface LastFMAuthGetMobileSessionParams extends LastFMRequestParams { - readonly username: string; - readonly password: string; -} - -export interface LastFMAuthGetSessionParams extends LastFMRequestParams { - readonly token: string; -} +import { LastFM } from './base.js'; +import { LastFMApiRequest } from './api-request.js'; +import { + LastFMUnknownFunction, + LastFMAuthSessionResponse, + LastFMAuthGetSessionParams, + LastFMAuthGetTokenResponse, + LastFMAuthGetMobileSessionParams +} from './types.js'; export class LastFMAuth extends LastFM { - constructor(apiKey: string, secret?: string, sessionKey?: string) { - super(apiKey, secret, sessionKey); - } - public getMobileSession( params: LastFMAuthGetMobileSessionParams, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -31,9 +25,9 @@ export class LastFMAuth extends LastFM { public getSession( params: LastFMAuthGetSessionParams, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -43,8 +37,8 @@ export class LastFMAuth extends LastFM { .send(callback); } - public getToken(callback: LastFMUnknownFunction): Promise | void { - return new LastFMApiRequest() + public getToken(callback?: LastFMUnknownFunction): Promise { + return new LastFMApiRequest() .set({ api_key: this.apiKey, method: 'auth.getToken' diff --git a/src/chart.ts b/src/chart.ts index 1cd19e1..96d9b36 100644 --- a/src/chart.ts +++ b/src/chart.ts @@ -1,18 +1,19 @@ -import { LastFM } from './base'; -import { LastFMApiRequest, LastFMRequestParams, LastFMUnknownFunction } from './api-request'; - -export interface LastFMChartParams extends LastFMRequestParams { - readonly page?: number; - readonly limit?: number; -} +import { LastFM } from './base.js'; +import { LastFMApiRequest } from './api-request.js'; +import { + LastFMChartParams, + LastFMUnknownFunction, + LastFMChartGetTopTagsResponse, + LastFMChartGetTopTracksResponse, + LastFMChartGetTopArtistsResponse +} from './types.js'; export class LastFMChart extends LastFM { - constructor(apiKey: string, secret?: string, sessionKey?: string) { - super(apiKey, secret, sessionKey); - } - - public getTopArtists(params: LastFMChartParams, callback: LastFMUnknownFunction): Promise | void { - return new LastFMApiRequest() + public getTopArtists( + params: LastFMChartParams, + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -21,8 +22,11 @@ export class LastFMChart extends LastFM { .send(callback); } - public getTopTags(params: LastFMChartParams, callback: LastFMUnknownFunction): Promise | void { - return new LastFMApiRequest() + public getTopTags( + params: LastFMChartParams, + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -31,8 +35,11 @@ export class LastFMChart extends LastFM { .send(callback); } - public getTopTracks(params: LastFMChartParams, callback: LastFMUnknownFunction): Promise | void { - return new LastFMApiRequest() + public getTopTracks( + params: LastFMChartParams, + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, diff --git a/src/geo.ts b/src/geo.ts index 2ae9ff0..ae15bed 100644 --- a/src/geo.ts +++ b/src/geo.ts @@ -1,26 +1,19 @@ -import { LastFM } from './base'; -import { LastFMApiRequest, LastFMRequestParams, LastFMUnknownFunction } from './api-request'; - -export interface LastFMGeoGetTopArtistsParams extends LastFMRequestParams { - readonly page?: number; - readonly limit?: number; - readonly country: string; -} - -export interface LastFMGeoGetTopTracksParams extends LastFMGeoGetTopArtistsParams { - readonly location?: string; -} +import { LastFM } from './base.js'; +import { LastFMApiRequest } from './api-request.js'; +import { + LastFMUnknownFunction, + LastFMGeoGetTopTracksParams, + LastFMGeoGetTopArtistsParams, + LastFMGeoGetTopTracksResponse, + LastFMGeoGetTopArtistsResponse +} from './types.js'; export class LastFMGeo extends LastFM { - constructor(apiKey: string, secret?: string, sessionKey?: string) { - super(apiKey, secret, sessionKey); - } - public getTopArtists( params: LastFMGeoGetTopArtistsParams, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -31,9 +24,9 @@ export class LastFMGeo extends LastFM { public getTopTracks( params: LastFMGeoGetTopTracksParams, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, diff --git a/src/index.ts b/src/index.ts index d8a84c5..930beed 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,12 @@ -export * from './album'; -export * from './api-request'; -export * from './artist'; -export * from './auth'; -export * from './base'; -export * from './chart'; -export * from './geo'; -export * from './library'; -export * from './tag'; -export * from './track'; -export * from './user'; +export * from './album.js'; +export * from './api-request.js'; +export * from './artist.js'; +export * from './auth.js'; +export * from './base.js'; +export * from './chart.js'; +export * from './geo.js'; +export * from './library.js'; +export * from './tag.js'; +export * from './track.js'; +export * from './types.js'; +export * from './user.js'; diff --git a/src/library.ts b/src/library.ts index ba87603..7d20cc9 100644 --- a/src/library.ts +++ b/src/library.ts @@ -1,22 +1,13 @@ -import { LastFM } from './base'; -import { LastFMApiRequest, LastFMRequestParams, LastFMUnknownFunction } from './api-request'; - -export interface LastFMLibraryGetArtists extends LastFMRequestParams { - readonly user: string; - readonly page?: number; - readonly limit?: number; -} +import { LastFM } from './base.js'; +import { LastFMApiRequest } from './api-request.js'; +import { LastFMUnknownFunction, LastFMLibraryGetArtistsParams, LastFMLibraryGetArtistsResponse } from './types.js'; export class LastFMLibrary extends LastFM { - constructor(apiKey: string, secret?: string, sessionKey?: string) { - super(apiKey, secret, sessionKey); - } - public getArtists( - params: LastFMLibraryGetArtists, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + params: LastFMLibraryGetArtistsParams, + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, diff --git a/src/tag.ts b/src/tag.ts index 55d179e..1dce645 100644 --- a/src/tag.ts +++ b/src/tag.ts @@ -1,28 +1,25 @@ -import { LastFM } from './base'; -import { LastFMApiRequest, LastFMRequestParams, LastFMUnknownFunction } from './api-request'; - -export interface LastFMTagParams extends LastFMRequestParams { - readonly tag: string; -} - -export interface LastFMTagOptionalParams { - readonly page?: number; - readonly limit?: number; -} - -export interface LastFMTagGetInfoParams extends LastFMRequestParams, LastFMTagParams { - readonly lang?: string; -} - -export interface LastFMTagGetTop extends LastFMRequestParams, LastFMTagParams, LastFMTagOptionalParams {} +import { LastFM } from './base.js'; +import { LastFMApiRequest } from './api-request.js'; +import { + LastFMTagParams, + LastFMTagGetTopParams, + LastFMUnknownFunction, + LastFMTagGetInfoParams, + LastFMTagGetInfoResponse, + LastFMTagGetSimilarResponse, + LastFMTagGetTopTagsResponse, + LastFMTagGetTopAlbumsResponse, + LastFMTagGetTopTracksResponse, + LastFMTagGetTopArtistsResponse, + LastFMTagGetWeeklyChartListResponse +} from './types.js'; export class LastFMTag extends LastFM { - constructor(apiKey: string, secret?: string, sessionKey?: string) { - super(apiKey, secret, sessionKey); - } - - public getInfo(params: LastFMTagGetInfoParams, callback: LastFMUnknownFunction): Promise | void { - return new LastFMApiRequest() + public getInfo( + params: LastFMTagGetInfoParams, + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -31,8 +28,8 @@ export class LastFMTag extends LastFM { .send(callback); } - public getSimilar(params: LastFMTagParams, callback: LastFMUnknownFunction): Promise | void { - return new LastFMApiRequest() + public getSimilar(params: LastFMTagParams, callback?: LastFMUnknownFunction): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -41,8 +38,11 @@ export class LastFMTag extends LastFM { .send(callback); } - public getTopAlbums(params: LastFMTagGetTop, callback: LastFMUnknownFunction): Promise | void { - return new LastFMApiRequest() + public getTopAlbums( + params: LastFMTagGetTopParams, + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -51,8 +51,11 @@ export class LastFMTag extends LastFM { .send(callback); } - public getTopArtists(params: LastFMTagGetTop, callback: LastFMUnknownFunction): Promise | void { - return new LastFMApiRequest() + public getTopArtists( + params: LastFMTagGetTopParams, + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -61,8 +64,8 @@ export class LastFMTag extends LastFM { .send(callback); } - public getTopTags(callback: LastFMUnknownFunction): Promise | void { - return new LastFMApiRequest() + public getTopTags(callback?: LastFMUnknownFunction): Promise { + return new LastFMApiRequest() .set({ api_key: this.apiKey, method: 'tag.getTopTags' @@ -70,8 +73,11 @@ export class LastFMTag extends LastFM { .send(callback); } - public getTopTracks(params: LastFMTagGetTop, callback: LastFMUnknownFunction): Promise | void { - return new LastFMApiRequest() + public getTopTracks( + params: LastFMTagGetTopParams, + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -82,9 +88,9 @@ export class LastFMTag extends LastFM { public getWeeklyChartList( params: LastFMTagParams, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, diff --git a/src/track.ts b/src/track.ts index e847d12..b0f89ae 100644 --- a/src/track.ts +++ b/src/track.ts @@ -1,73 +1,30 @@ -import { LastFM } from './base'; -import { LastFMApiRequest, LastFMRequestParams, LastFMUnknownFunction } from './api-request'; - -export interface LastFMTrackParams extends LastFMRequestParams { - readonly track: string; - readonly artist: string; -} - -export interface LastFMTrackOptionalParams { - readonly mbid?: string; - readonly autocorrect?: 0 | 1; -} - -export interface LastFMTrackAddTags extends LastFMTrackParams { - readonly tags: string | string[]; -} - -export interface LastFMTrackGetInfo extends LastFMTrackParams, LastFMTrackOptionalParams { - readonly username?: string; -} - -export interface LastFMTrackGetSimilar extends LastFMTrackParams, LastFMTrackOptionalParams { - readonly limit?: number; -} - -export interface LastFMTrackGetTags extends LastFMTrackParams, LastFMTrackOptionalParams { - readonly user?: string; -} - -export interface LastFMTrackGetTopTags extends LastFMTrackParams, LastFMTrackOptionalParams {} - -export interface LastFMTrackRemoveTag extends LastFMTrackParams { - readonly tag: string; -} - -export interface LastFMTrackScrobble extends LastFMTrackParams { - readonly timestamp?: number; - readonly mbid?: string; - readonly album?: string; - readonly context?: string; - readonly streamId?: string; - readonly duration?: number; - readonly chosenByUser?: 0 | 1; - readonly trackNumber?: number; - readonly albumArtist?: string; -} - -export interface LastFMTrackSearch extends LastFMRequestParams { - readonly page?: number; - readonly limit?: number; - readonly track: string; - readonly artist?: string; -} - -export interface LastFMTrackUpdateNowPlaying extends LastFMTrackParams { - readonly mbid?: string; - readonly album?: string; - readonly context?: string; - readonly duration?: number; - readonly trackNumber?: number; - readonly albumArtist?: string; -} +import { LastFM } from './base.js'; +import { LastFMApiRequest } from './api-request.js'; +import { + LastFMTrackParams, + LastFMUnknownFunction, + LastFMTrackSearchParams, + LastFMTrackAddTagsParams, + LastFMTrackGetInfoParams, + LastFMTrackGetTagsParams, + LastFMTrackScrobbleParams, + LastFMTrackSearchResponse, + LastFMTrackGetInfoResponse, + LastFMTrackGetTagsResponse, + LastFMTrackRemoveTagParams, + LastFMTrackGetSimilarParams, + LastFMTrackGetTopTagsParams, + LastFMTrackScroblleResponse, + LastFMTrackGetSimilarResponse, + LastFMTrackGetTopTagsResponse, + LastFMUpdateNowPlayingResponse, + LastFMTrackGetCorrectionResponse, + LastFMTrackUpdateNowPlayingParams +} from './types.js'; export class LastFMTrack extends LastFM { - constructor(apiKey: string, secret?: string, sessionKey?: string) { - super(apiKey, secret, sessionKey); - } - - public addTags(params: LastFMTrackAddTags, callback: LastFMUnknownFunction): Promise | void { - return new LastFMApiRequest() + public addTags(params: LastFMTrackAddTagsParams, callback?: LastFMUnknownFunction): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -78,8 +35,11 @@ export class LastFMTrack extends LastFM { .send('POST', callback); } - public getCorrection(params: LastFMTrackParams, callback: LastFMUnknownFunction): Promise | void { - return new LastFMApiRequest() + public getCorrection( + params: LastFMTrackParams, + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -88,8 +48,11 @@ export class LastFMTrack extends LastFM { .send(callback); } - public getInfo(params: LastFMTrackGetInfo, callback: LastFMUnknownFunction): Promise | void { - return new LastFMApiRequest() + public getInfo( + params: LastFMTrackGetInfoParams, + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -99,10 +62,10 @@ export class LastFMTrack extends LastFM { } public getSimilar( - params: LastFMTrackGetSimilar, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + params: LastFMTrackGetSimilarParams, + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -111,8 +74,11 @@ export class LastFMTrack extends LastFM { .send(callback); } - public getTags(params: LastFMTrackGetTags, callback: LastFMUnknownFunction): Promise | void { - return new LastFMApiRequest() + public getTags( + params: LastFMTrackGetTagsParams, + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -122,10 +88,10 @@ export class LastFMTrack extends LastFM { } public getTopTags( - params: LastFMTrackGetTopTags, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + params: LastFMTrackGetTopTagsParams, + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -134,8 +100,8 @@ export class LastFMTrack extends LastFM { .send(callback); } - public love(params: LastFMTrackParams, callback: LastFMUnknownFunction): Promise | void { - return new LastFMApiRequest() + public love(params: LastFMTrackParams, callback?: LastFMUnknownFunction): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -146,8 +112,8 @@ export class LastFMTrack extends LastFM { .send('POST', callback); } - public removeTag(params: LastFMTrackRemoveTag, callback: LastFMUnknownFunction): Promise | void { - return new LastFMApiRequest() + public removeTag(params: LastFMTrackRemoveTagParams, callback?: LastFMUnknownFunction): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -158,8 +124,11 @@ export class LastFMTrack extends LastFM { .send('POST', callback); } - public scrobble(params: LastFMTrackScrobble, callback: LastFMUnknownFunction): Promise | void { - return new LastFMApiRequest() + public scrobble( + params: LastFMTrackScrobbleParams, + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -171,12 +140,12 @@ export class LastFMTrack extends LastFM { } public scrobbleMany( - paramsArr: LastFMTrackScrobble[], - callback: LastFMUnknownFunction - ): Promise | void { - const params: any = {}; + paramsArr: LastFMTrackScrobbleParams[], + callback?: LastFMUnknownFunction + ): Promise { + const params: LastFMTrackScrobbleParams = {} as LastFMTrackScrobbleParams; - paramsArr.forEach((paramsObj: LastFMTrackScrobble, i: number) => + paramsArr.forEach((paramsObj: LastFMTrackScrobbleParams, i: number) => Object.entries(paramsObj).forEach( ([name, value]: [name: string, value: string | string[] | number | void]) => (params[`${name}[${i}]`] = value) @@ -186,8 +155,11 @@ export class LastFMTrack extends LastFM { return this.scrobble(params, callback); } - public search(params: LastFMTrackSearch, callback: LastFMUnknownFunction): Promise | void { - return new LastFMApiRequest() + public search( + params: LastFMTrackSearchParams, + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -196,8 +168,8 @@ export class LastFMTrack extends LastFM { .send(callback); } - public unlove(params: LastFMTrackParams, callback: LastFMUnknownFunction): Promise | void { - return new LastFMApiRequest() + public unlove(params: LastFMTrackParams, callback?: LastFMUnknownFunction): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -209,10 +181,10 @@ export class LastFMTrack extends LastFM { } public updateNowPlaying( - params: LastFMTrackUpdateNowPlaying, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + params: LastFMTrackUpdateNowPlayingParams, + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 0000000..73634de --- /dev/null +++ b/src/types.ts @@ -0,0 +1,1442 @@ +export type LastFMParam = string | string[]; +export type LastFMParams = Record; +export type LastFMVoidOrNumber = void | number; +export type LastFMBooleanNumber = 0 | 1; +export type LastFMUnknownFunction = (...args: unknown[]) => unknown; +export type LastFMRequestParams = Record; +export type LastFMBooleanNumberOrVoid = LastFMBooleanNumber | void; + +export type LastFMAlbumParams = Readonly<{ + album: string; + artist: string; +}>; + +export type LastFMAlbumOptionalParams = Readonly<{ + mbid?: string; + autocorrect?: LastFMBooleanNumber; +}>; + +export type LastFMAlbumAddTagsParams = LastFMRequestParams & + LastFMAlbumParams & + Readonly<{ + tags: string | string[]; + }>; + +export type LastFMAlbumGetInfoParams = LastFMRequestParams & + LastFMAlbumParams & + LastFMAlbumOptionalParams & + Readonly<{ + lang?: string; + username?: string; + }>; + +export type LastFMAlbumGetTagsParams = LastFMRequestParams & + LastFMAlbumParams & + LastFMAlbumOptionalParams & + Readonly<{ + user?: string; + }>; + +export type LastFMAlbumGetTopTagsParams = LastFMRequestParams & + LastFMAlbumParams & + LastFMAlbumOptionalParams; + +export type LastFMAlbumRemoveLastFMTagParams = LastFMRequestParams & + LastFMAlbumParams & + Readonly<{ + tag: string; + }>; + +export type LastFMAlbumSearchParams = LastFMRequestParams & + Readonly<{ + page?: number; + album: string; + limit?: number; + }>; + +export type LastFMAlbumGetInfoResponse = Readonly<{ + album: { + artist: string; + mbid: string; + tags: { + tag: Array<{ + url: string; + name: string; + }>; + }; + playcount: string; + image: Array<{ + size: string; + '#text': string; + }>; + tracks: { + track: Array<{ + streamable: { + fulltrack: string; + '#text': string; + }; + duration: number; + url: string; + name: string; + '@attr': { + rank: number; + }; + artist: { + url: string; + name: string; + mbid: string; + }; + }>; + }; + url: string; + name: string; + listeners: string; + wiki: { + published: string; + summary: string; + }; + }; +}>; + +export type LastFMAlbumGetTagsResponse = Readonly<{ + tags: { + tag: Array<{ + name: string; + url: string; + }>; + }; +}>; + +export type LastFMAlbumSearchResponse = Readonly<{ + results: { + 'opensearch:Query': { + '#text': string; + role: string; + searchTerms: string; + startPage: string; + }; + 'opensearch:totalResults': string; + 'opensearch:startIndex': string; + 'opensearch:itemsPerPage': string; + albummatches: { + album: Array<{ + name: string; + artist: string; + url: string; + image: Array<{ + '#text': string; + size: string; + }>; + streamable: LastFMBooleanNumber; + mbid: string; + }>; + }; + '@attr': { + for: string; + }; + }; +}>; + +export type LastFMArtistParams = LastFMRequestParams & + Readonly<{ + artist: string; + }>; + +export type LastFMArtistAddTagsParams = LastFMRequestParams & + LastFMArtistParams & + Readonly<{ + tags: string | string[]; + }>; + +export type LastFMArtistGetInfoParams = LastFMRequestParams & + Readonly<{ + lang?: string; + mbid?: string; + artist: string; + username?: string; + autocorrect?: 0 | 1; + }>; + +export type LastFMArtistGetSimilarParams = LastFMRequestParams & + Readonly<{ + mbid?: string; + limit?: number; + artist: string; + autocorrect?: 0 | 1; + }>; + +export type LastFMArtistGetTagsParams = LastFMRequestParams & + Readonly<{ + mbid?: string; + user?: string; + artist: string; + autocorrect?: 0 | 1; + }>; + +export type LastFMArtistGetTopAlbumsParams = LastFMRequestParams & + Readonly<{ + mbid?: string; + page?: number; + limit?: number; + artist: string; + autocorrect?: 0 | 1; + }>; + +export type LastFMArtistGetTopTagsParams = LastFMRequestParams & + Readonly<{ + mbid?: string; + artist: string; + autocorrect?: 0 | 1; + }>; + +export type LastFMArtistGetTopTracksParams = LastFMRequestParams & + Readonly<{ + mbid?: string; + page?: number; + limit?: number; + artist: string; + autocorrect?: 0 | 1; + }>; + +export type LastFMArtistRemoveLastFMTagParams = LastFMRequestParams & + Readonly<{ + tag: string; + artist: string; + }>; + +export type LastFMArtistSearchParams = LastFMRequestParams & + Readonly<{ + page?: number; + limit?: number; + artist: string; + }>; + +export type LastFMArtistGetCorrectionResponse = Readonly<{ + corrections: { + correction: { + artist: { + name: string; + mbid: string; + url: string; + }; + '@attr': { + index: string; + }; + }; + }; +}>; + +export type LastFMArtistGetInfoResponse = Readonly<{ + artist: { + name: string; + mbid: string; + url: string; + image: Array<{ + '#text': string; + size: string; + }>; + streamable: LastFMBooleanNumber; + ontour: LastFMBooleanNumber; + stats: { + listeners: string; + playcount: string; + }; + similar: { + artist: Array<{ + name: string; + url: string; + image: Array<{ + '#text': string; + size: string; + }>; + }>; + }; + tags: { + tag: Array<{ + name: string; + url: string; + }>; + }; + bio: { + links: { + link: { + '#text': string; + rel: string; + href: string; + }; + }; + published: string; + summary: string; + content: string; + }; + }; +}>; + +export type LastFMArtistGetSimilarResponse = Readonly<{ + similarartists: { + artist: Array<{ + name: string; + mbid: string; + match: LastFMBooleanNumber; + url: string; + image: Array<{ + '#text': string; + size: string; + }>; + streamable: LastFMBooleanNumber; + }>; + '@attr': { + artist: string; + }; + }; +}>; + +export type LastFMArtistGetTagsResponse = Readonly<{ + tags: { + tag: Array<{ + name: string; + url: string; + }>; + '@attr': { + artist: string; + }; + }; +}>; + +export type LastFMArtistGetTopAlbumsResponse = Readonly<{ + topalbums: { + album: Array<{ + name: string; + playcount: number; + mbid: string; + url: string; + artist: { + name: string; + mbid: string; + url: string; + }; + image: Array<{ + '#text': string; + size: string; + }>; + }>; + '@attr': { + artist: string; + page: string; + perPage: string; + totalPages: string; + total: string; + }; + }; +}>; + +export type LastFMArtistGetTopTagsResponse = Readonly<{ + toptags: { + tag: Array<{ + count: number; + name: string; + url: string; + }>; + '@attr': { + artist: string; + }; + }; +}>; + +export type LastFMArtistGetTopTracksResponse = Readonly<{ + toptracks: { + track: Array<{ + name: string; + playcount: string; + listeners: string; + mbid: string; + url: string; + streamable: LastFMBooleanNumber; + artist: { + name: string; + mbid: string; + url: string; + }; + image: Array<{ + '#text': string; + size: string; + }>; + '@attr': { + rank: string; + }; + }>; + '@attr': { + artist: string; + page: string; + perPage: string; + totalPages: string; + total: string; + }; + }; +}>; + +export type LastFMArtistSearchResponse = Readonly<{ + results: { + 'opensearch:Query': { + '#text': string; + role: string; + searchTerms: string; + startPage: string; + }; + 'opensearch:totalResults': string; + 'opensearch:startIndex': string; + 'opensearch:itemsPerPage': string; + artistmatches: { + artist: Array<{ + name: string; + listeners: string; + mbid: string; + url: string; + streamable: LastFMBooleanNumber; + image: Array<{ + '#text': string; + size: string; + }>; + }>; + }; + '@attr': { + for: string; + }; + }; +}>; + +export type LastFMAuthGetMobileSessionParams = LastFMRequestParams & + Readonly<{ + username: string; + password: string; + }>; + +export type LastFMAuthGetSessionParams = LastFMRequestParams & + Readonly<{ + token: string; + }>; + +export type LastFMAuthSessionResponse = Readonly<{ + session: { + name: string; + key: string; + subscriber: LastFMBooleanNumber; + }; +}>; + +export type LastFMAuthGetTokenResponse = Readonly<{ + token: string; +}>; + +export type LastFMChartParams = LastFMRequestParams & + Readonly<{ + page?: number; + limit?: number; + }>; + +export type LastFMChartGetTopArtistsResponse = Readonly<{ + artists: { + artist: Array<{ + name: string; + playcount: string; + listeners: string; + mbid: string; + url: string; + streamable: LastFMBooleanNumber; + image: Array<{ + '#text': string; + size: string; + }>; + }>; + '@attr': { + page: string; + perPage: string; + totalPages: string; + total: string; + }; + }; +}>; + +export type LastFMChartGetTopTagsResponse = Readonly<{ + tags: { + tag: Array<{ + name: string; + url: string; + reach: string; + taggings: string; + streamable: LastFMBooleanNumber; + wiki: { + published?: string; + summary?: string; + }; + }>; + '@attr': { + page: string; + perPage: string; + totalPages: string; + total: string; + }; + }; +}>; + +export type LastFMChartGetTopTracksResponse = Readonly<{ + tracks: { + track: Array<{ + name: string; + duration: string; + playcount: string; + listeners: string; + mbid: string; + url: string; + streamable: { + '#text': string; + fulltrack: string; + }; + artist: { + name: string; + mbid: string; + url: string; + }; + image: Array<{ + '#text': string; + size: string; + }>; + }>; + '@attr': { + page: string; + perPage: string; + totalPages: string; + total: string; + }; + }; +}>; + +export type LastFMGeoGetTopArtistsParams = LastFMRequestParams & + Readonly<{ + page?: number; + limit?: number; + country: string; + }>; + +export type LastFMGeoGetTopTracksParams = LastFMGeoGetTopArtistsParams & + Readonly<{ + location?: string; + }>; + +export type LastFMGeoGetTopArtistsResponse = Readonly<{ + topartists: { + artist: Array<{ + name: string; + listeners: string; + mbid: string; + url: string; + streamable: LastFMBooleanNumber; + image: Array<{ + '#text': string; + size: string; + }>; + }>; + '@attr': { + country: string; + page: string; + perPage: string; + totalPages: string; + total: string; + }; + }; +}>; + +export type LastFMGeoGetTopTracksResponse = Readonly<{ + tracks: { + track: Array<{ + name: string; + duration: string; + listeners: string; + mbid: string; + url: string; + streamable: { + '#text': string; + fulltrack: string; + }; + artist: { + name: string; + mbid: string; + url: string; + }; + image: Array<{ + '#text': string; + size: string; + }>; + '@attr': { + rank: string; + }; + }>; + '@attr': { + country: string; + page: string; + perPage: string; + totalPages: string; + total: string; + }; + }; +}>; + +export type LastFMLibraryGetArtistsParams = LastFMRequestParams & + Readonly<{ + user: string; + page?: number; + limit?: number; + }>; + +export type LastFMLibraryGetArtistsResponse = Readonly<{ + artists: { + artist: Array<{ + tagcount: string; + image: Array<{ + '#text': string; + size: string; + }>; + mbid: string; + url: string; + playcount: string; + name: string; + streamable: LastFMBooleanNumber; + }>; + '@attr': { + user: string; + totalPages: string; + page: string; + perPage: string; + total: string; + }; + }; +}>; + +export type LastFMTagParams = LastFMRequestParams & + Readonly<{ + tag: string; + }>; + +export type LastFMTagOptionalParams = Readonly<{ + page?: number; + limit?: number; +}>; + +export type LastFMTagGetInfoParams = LastFMRequestParams & + LastFMTagParams & + Readonly<{ + lang?: string; + }>; + +export type LastFMTagGetTopParams = LastFMRequestParams & LastFMTagParams & LastFMTagOptionalParams; + +export type LastFMTagGetInfoResponse = Readonly<{ + tag: { + name: string; + total: number; + reach: number; + wiki: { + summary: string; + content: string; + }; + }; +}>; + +export type LastFMTagGetSimilarResponse = Readonly<{ + similartags: { + tag: Array<{ + url: string; + name: string; + }>; + '@attr': { + tag: string; + }; + }; +}>; + +export type LastFMTagGetTopAlbumsResponse = Readonly<{ + albums: { + album: Array<{ + name: string; + mbid: string; + url: string; + artist: { + name: string; + mbid: string; + url: string; + }; + image: Array<{ + '#text': string; + size: string; + }>; + '@attr': { + rank: string; + }; + }>; + '@attr': { + tag: string; + page: string; + perPage: string; + totalPages: string; + total: string; + }; + }; +}>; + +export type LastFMTagGetTopArtistsResponse = Readonly<{ + topartists: { + artist: Array<{ + name: string; + mbid: string; + url: string; + streamable: LastFMBooleanNumber; + image: Array<{ + '#text': string; + size: string; + }>; + '@attr': { + rank: string; + }; + }>; + '@attr': { + tag: string; + page: string; + perPage: string; + totalPages: string; + total: string; + }; + }; +}>; + +export type LastFMTagGetTopTagsResponse = Readonly<{ + toptags: { + '@attr': { + offset: number; + num_res: number; + total: number; + }; + tag: Array<{ + name: string; + count: number; + reach: number; + }>; + }; +}>; + +export type LastFMTagGetTopTracksResponse = Readonly<{ + tracks: { + track: Array<{ + name: string; + duration: string; + mbid: string; + url: string; + streamable: { + '#text': string; + fulltrack: string; + }; + artist: { + name: string; + mbid: string; + url: string; + }; + image: Array<{ + '#text': string; + size: string; + }>; + '@attr': { + rank: string; + }; + }>; + '@attr': { + tag: string; + page: string; + perPage: string; + totalPages: string; + total: string; + }; + }; +}>; + +export type LastFMTagGetWeeklyChartListResponse = Readonly<{ + weeklychartlist: { + chart: Array<{ + '#text': string; + from: string; + to: string; + }>; + '@attr': { + tag: string; + }; + }; +}>; + +export type LastFMTrackParams = LastFMRequestParams & + Readonly<{ + track: string; + artist: string; + }>; + +export type LastFMTrackOptionalParams = Readonly<{ + mbid?: string; + autocorrect?: 0 | 1; +}>; + +export type LastFMTrackAddTagsParams = LastFMTrackParams & + Readonly<{ + tags: string | string[]; + }>; + +export type LastFMTrackGetInfoParams = LastFMTrackParams & + LastFMTrackOptionalParams & + Readonly<{ + username?: string; + }>; + +export type LastFMTrackGetSimilarParams = LastFMTrackParams & + LastFMTrackOptionalParams & + Readonly<{ + limit?: number; + }>; + +export type LastFMTrackGetTagsParams = LastFMTrackParams & + LastFMTrackOptionalParams & + Readonly<{ + user?: string; + }>; + +export type LastFMTrackGetTopTagsParams = LastFMTrackParams & LastFMTrackOptionalParams; + +export type LastFMTrackRemoveTagParams = LastFMTrackParams & + Readonly<{ + tag: string; + }>; + +export type LastFMTrackScrobbleParams = LastFMTrackParams & + Readonly<{ + timestamp: number; + album?: string; + context?: string; + streamId?: string; + chosenByUser?: 0 | 1; + trackNumber?: number; + mbid?: string; + albumArtist?: string; + duration?: number; + }>; + +export type LastFMTrackSearchParams = LastFMRequestParams & + Readonly<{ + page?: number; + limit?: number; + track: string; + artist?: string; + }>; + +export type LastFMTrackUpdateNowPlayingParams = LastFMTrackParams & + Readonly<{ + mbid?: string; + album?: string; + context?: string; + duration?: number; + trackNumber?: number; + albumArtist?: string; + }>; + +export type LastFMTrackGetCorrectionResponse = Readonly<{ + corrections: { + correction: { + track: { + name: string; + url: string; + artist: { + name: string; + mbid: string; + url: string; + }; + }; + '@attr': { + index: string; + artistcorrected: LastFMBooleanNumber; + trackcorrected: LastFMBooleanNumber; + }; + }; + }; +}>; + +export type LastFMTrackGetInfoResponse = Readonly<{ + track: { + name: string; + mbid: string; + url: string; + duration: string; + streamable: { + '#text': string; + fulltrack: string; + }; + listeners: string; + playcount: string; + artist: { + name: string; + mbid: string; + url: string; + }; + album: { + artist: string; + title: string; + mbid: string; + url: string; + image: Array<{ + size: string; + '#text': string; + }>; + '@attr': { + position: string; + }; + }; + toptags: { + tag: Array<{ + name: string; + url: string; + }>; + }; + wiki: { + published: string; + summary: string; + content: string; + }; + }; +}>; + +export type LastFMTrackGetSimilarResponse = Readonly<{ + similartracks: { + track: Array<{ + name: string; + playcount: number; + mbid: string; + match: string; + url: string; + streamable: { + '#text': string; + fulltrack: string; + }; + duration: number; + artist: { + name: string; + mbid: string; + url: string; + }; + image: Array<{ + size: string; + '#text': string; + }>; + }>; + '@attr': { + artist: string; + }; + }; +}>; + +export type LastFMTrackGetTagsResponse = Readonly<{ + tags: { + tag: Array<{ + name: string; + url: string; + }>; + '@attr': { + artist: string; + track: string; + }; + }; +}>; + +export type LastFMTrackGetTopTagsResponse = Readonly<{ + toptags: { + tag: Array<{ + count: number; + name: string; + url: string; + }>; + '@attr': { + artist: string; + track: string; + }; + }; +}>; + +// This might not be the correct shape of the response +export type LastFMTrackScroblleResponse = Readonly<{ + scrobbles: { + scrobble: Array<{ + track: { + corrected: LastFMBooleanNumber; + '#text': string; + }; + artist: { + corrected: LastFMBooleanNumber; + '#text': string; + }; + album: { + corrected: LastFMBooleanNumber; + '#text': string; + }; + albumArtist: { + corrected: LastFMBooleanNumber; + '#text': string; + }; + timestamp: number; + ignoredMessage: { + code: number; + '#text': string; + }; + }>; + '@attr': { + accepted: number; + ignored: number; + }; + }; +}>; + +export type LastFMTrackSearchResponse = Readonly<{ + results: { + 'opensearch:Query': { + '#text': string; + role: string; + startPage: string; + }; + 'opensearch:totalResults': string; + 'opensearch:startIndex': string; + 'opensearch:itemsPerPage': string; + trackmatches: { + track: Array<{ + name: string; + artist: string; + url: string; + streamable: LastFMBooleanNumber; + listeners: string; + image: Array<{ + size: string; + '#text': string; + }>; + mbid: string; + }>; + }; + '@attr': { + for: string; + }; + }; +}>; + +// This might not be the correct shape of the response +export type LastFMUpdateNowPlayingResponse = Readonly<{ + nowplaying: { + track: { + corrected: LastFMBooleanNumber; + '#text': string; + }; + artist: { + corrected: LastFMBooleanNumber; + '#text': string; + }; + album: { + corrected: LastFMBooleanNumber; + '#text': string; + }; + albumArtist: { + corrected: LastFMBooleanNumber; + '#text': string; + }; + ignoredMessage: { + code: number; + '#text': string; + }; + }; +}>; + +export type LastFMUserParams = LastFMRequestParams & + Readonly<{ + user: string; + }>; + +export type LastFMUserOptionalParams = Readonly<{ + page?: number; + limit?: number; +}>; + +export type LastFMUserGetFriendsParams = LastFMUserParams & + LastFMUserOptionalParams & + Readonly<{ + recenttracks?: boolean; + }>; + +export type LastFMUserGetLovedTracksParams = LastFMUserParams & LastFMUserOptionalParams; + +export type LastFMUserGetPersonalTagsParams = LastFMUserParams & + LastFMUserOptionalParams & + Readonly<{ + tag: string; + taggingtype: 'artist' | 'album' | 'track'; + }>; + +export type LastFMUserGetRecentTracksParams = LastFMUserParams & + LastFMUserOptionalParams & + Readonly<{ + to?: string; + from?: string; + extended?: 0 | 1; + }>; + +export type LastFMUserGetTopParams = LastFMUserParams & + LastFMUserOptionalParams & + Readonly<{ + period?: 'overall' | '7day' | '1month' | '3month' | '6month' | '12month'; + }>; + +export type LastFMUserGetTopTagsParams = LastFMRequestParams & + Readonly<{ + user: string; + limit?: number; + }>; + +export type LastFMUserGetWeeklyParams = LastFMRequestParams & + Readonly<{ + to?: string; + user: string; + from?: string; + }>; + +export type LastFMUserGetFriendsResponse = Readonly<{ + friends: { + '@attr': { + user: string; + totalPages: string; + page: string; + perPage: string; + total: string; + }; + user: Array<{ + name: string; + url: string; + country: string; + playlists: string; + playcount: string; + image: Array<{ + '#text': string; + size: string; + }>; + registered: { + unixtime: string; + '#text': string; + }; + realname: string; + subscriber: LastFMBooleanNumber; + bootstrap: LastFMBooleanNumber; + type: string; + }>; + }; +}>; + +export type LastFMUserGetInfoResponse = Readonly<{ + user: { + name: string; + age: string; + subscriber: LastFMBooleanNumber; + realname: string; + bootstrap: LastFMBooleanNumber; + playcount: string; + artist_count: string; + playlists: string; + track_count: string; + album_count: string; + image: Array<{ + '#text': string; + size: string; + }>; + registered: { + unixtime: string; + '#text': number; + }; + country: string; + gender: string; + url: string; + type: string; + }; +}>; + +export type LastFMUserGetLovedTracksResponse = Readonly<{ + lovedtracks: { + track: Array<{ + artist: { + url: string; + name: string; + mbid: string; + }; + date: { + uts: string; + '#text': string; + }; + mbid: string; + url: string; + name: string; + image: Array<{ + '#text': string; + size: string; + }>; + streamable: { + fulltrack: string; + '#text': string; + }; + }>; + '@attr': { + user: string; + totalPages: string; + page: string; + perPage: string; + total: string; + }; + }; +}>; + +export type LastFMUserGetPersonalTagsResponse = Readonly<{ + taggings: { + artists: { + artist: Array<{ + name: string; + mbid: string; + url: string; + streamable: LastFMBooleanNumber; + image: Array<{ + '#text': string; + size: string; + }>; + }>; + }; + '@attr': { + user: string; + tag: string; + page: string; + perPage: string; + totalPages: string; + total: string; + }; + }; +}>; + +export type LastFMUserGetRecentTracksResponse = Readonly<{ + recenttracks: { + track: Array<{ + artist: { + mbid: string; + '#text': string; + }; + streamable: LastFMBooleanNumber; + image: Array<{ + '#text': string; + size: string; + }>; + mbid: string; + album: { + mbid: string; + '#text': string; + }; + name: string; + url: string; + date: { + uts: string; + '#text': string; + }; + }>; + '@attr': { + user: string; + totalPages: string; + page: string; + perPage: string; + total: string; + }; + }; +}>; + +export type LastFMUserGetTopAlbumsResponse = Readonly<{ + topalbums: { + album: Array<{ + artist: { + url: string; + name: string; + mbid: string; + }; + image: Array<{ + '#text': string; + size: string; + }>; + mbid: string; + url: string; + playcount: string; + '@attr': { + rank: string; + }; + name: string; + }>; + '@attr': { + user: string; + totalPages: string; + page: string; + perPage: string; + total: string; + }; + }; +}>; + +export type LastFMUserGetTopArtistsResponse = Readonly<{ + topartists: { + artist: Array<{ + streamable: LastFMBooleanNumber; + image: Array<{ + '#text': string; + size: string; + }>; + mbid: string; + url: string; + playcount: string; + '@attr': { + rank: string; + }; + name: string; + }>; + '@attr': { + user: string; + totalPages: string; + page: string; + perPage: string; + total: string; + }; + }; +}>; + +export type LastFMUserGetTopTagsResponse = Readonly<{ + toptags: { + tag: Array<{ + name: string; + count: string; + url: string; + }>; + '@attr': { + user: string; + }; + }; +}>; + +export type LastFMUserGetTopTracksResponse = Readonly<{ + toptracks: { + track: Array<{ + streamable: { + fulltrack: string; + '#text': string; + }; + mbid: string; + name: string; + image: Array<{ + '#text': string; + size: string; + }>; + artist: { + url: string; + name: string; + mbid: string; + }; + url: string; + duration: string; + '@attr': { + rank: string; + }; + playcount: string; + }>; + '@attr': { + user: string; + totalPages: string; + page: string; + perPage: string; + total: string; + }; + }; +}>; + +export type LastFMUserGetWeeklyAlbumChartResponse = Readonly<{ + weeklyalbumchart: { + album: Array<{ + artist: { + mbid: string; + '#text': string; + }; + mbid: string; + url: string; + name: string; + '@attr': { + rank: string; + }; + playcount: string; + }>; + '@attr': { + from: string; + user: string; + to: string; + }; + }; +}>; + +export type LastFMUserGetWeeklyArtistChartResponse = Readonly<{ + weeklyartistchart: { + artist: Array<{ + mbid: string; + url: string; + name: string; + '@attr': { + rank: string; + }; + playcount: string; + }>; + '@attr': { + from: string; + user: string; + to: string; + }; + }; +}>; + +export type LastFMUserGetWeeklyChartListResponse = Readonly<{ + weeklychartlist: { + chart: Array<{ + '#text': string; + from: string; + to: string; + }>; + '@attr': { + user: string; + }; + }; +}>; + +export type LastFMUserGetWeeklyTrackChartResponse = Readonly<{ + weeklytrackchart: { + track: Array<{ + artist: { + mbid: string; + '#text': string; + }; + image: Array<{ + '#text': string; + size: string; + }>; + mbid: string; + url: string; + name: string; + '@attr': { + rank: string; + }; + playcount: string; + }>; + '@attr': { + from: string; + user: string; + to: string; + }; + }; +}>; diff --git a/src/user.ts b/src/user.ts index e069a8a..d1245e7 100644 --- a/src/user.ts +++ b/src/user.ts @@ -1,54 +1,36 @@ -import { LastFM } from './base'; -import { LastFMParam, LastFMApiRequest, LastFMRequestParams, LastFMUnknownFunction } from './api-request'; - -export interface LastFMUserParams extends LastFMRequestParams { - readonly user: string; -} - -export interface LastFMUserOptionalParams { - readonly page?: number; - readonly limit?: number; -} - -export interface LastFMUserGetFriends extends LastFMUserParams, LastFMUserOptionalParams { - readonly recenttracks?: boolean; -} - -export interface LastFMUserGetLovedTracks extends LastFMUserParams, LastFMUserOptionalParams {} - -export interface LastFMUserGetPersonalTags extends LastFMUserParams, LastFMUserOptionalParams { - readonly tag?: string; - readonly taggingtype: 'artist' | 'album' | 'track'; -} - -export interface LastFMUserGetRecentTracks extends LastFMUserParams, LastFMUserOptionalParams { - readonly to?: string; - readonly from?: string; - readonly extended: 0 | 1; -} - -export interface LastFMUserGetTop extends LastFMUserParams, LastFMUserOptionalParams { - readonly period?: 'overall' | '7day' | '1month' | '3month' | '6month' | '12month'; -} - -export interface LastFMUserGetTopTags extends LastFMRequestParams { - readonly user: string; - readonly limit?: number; -} - -export interface LastFMUserGetWeekly extends LastFMRequestParams { - readonly to?: string; - readonly user: string; - readonly from?: string; -} +import { LastFM } from './base.js'; +import { LastFMApiRequest } from './api-request.js'; +import { + LastFMUserParams, + LastFMUnknownFunction, + LastFMUserGetTopParams, + LastFMUserGetInfoResponse, + LastFMUserGetWeeklyParams, + LastFMUserGetFriendsParams, + LastFMUserGetTopTagsParams, + LastFMUserGetFriendsResponse, + LastFMUserGetTopTagsResponse, + LastFMUserGetLovedTracksParams, + LastFMUserGetTopAlbumsResponse, + LastFMUserGetTopTracksResponse, + LastFMUserGetPersonalTagsParams, + LastFMUserGetRecentTracksParams, + LastFMUserGetTopArtistsResponse, + LastFMUserGetLovedTracksResponse, + LastFMUserGetPersonalTagsResponse, + LastFMUserGetRecentTracksResponse, + LastFMUserGetWeeklyChartListResponse, + LastFMUserGetWeeklyAlbumChartResponse, + LastFMUserGetWeeklyTrackChartResponse, + LastFMUserGetWeeklyArtistChartResponse +} from './types.js'; export class LastFMUser extends LastFM { - constructor(apiKey: string, secret?: string, sessionKey?: string) { - super(apiKey, secret, sessionKey); - } - - public getFriends(params: LastFMUserGetFriends, callback: LastFMUnknownFunction): Promise | void { - return new LastFMApiRequest() + public getFriends( + params: LastFMUserGetFriendsParams, + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -57,8 +39,8 @@ export class LastFMUser extends LastFM { .send(callback); } - public getInfo(params: LastFMUserParams, callback: LastFMUnknownFunction): Promise | void { - return new LastFMApiRequest() + public getInfo(params: LastFMUserParams, callback?: LastFMUnknownFunction): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -68,10 +50,10 @@ export class LastFMUser extends LastFM { } public getLovedTracks( - params: LastFMUserGetLovedTracks, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + params: LastFMUserGetLovedTracksParams, + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -81,10 +63,10 @@ export class LastFMUser extends LastFM { } public getPersonalTags( - params: LastFMUserGetPersonalTags, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + params: LastFMUserGetPersonalTagsParams, + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -94,10 +76,10 @@ export class LastFMUser extends LastFM { } public getRecentTracks( - params: LastFMUserGetRecentTracks, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + params: LastFMUserGetRecentTracksParams, + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -106,8 +88,11 @@ export class LastFMUser extends LastFM { .send(callback); } - public getTopAlbums(params: LastFMUserGetTop, callback: LastFMUnknownFunction): Promise | void { - return new LastFMApiRequest() + public getTopAlbums( + params: LastFMUserGetTopParams, + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -116,8 +101,11 @@ export class LastFMUser extends LastFM { .send(callback); } - public getTopArtists(params: LastFMUserGetTop, callback: LastFMUnknownFunction): Promise | void { - return new LastFMApiRequest() + public getTopArtists( + params: LastFMUserGetTopParams, + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -126,8 +114,11 @@ export class LastFMUser extends LastFM { .send(callback); } - public getTopTags(params: LastFMUserGetTopTags, callback: LastFMUnknownFunction): Promise | void { - return new LastFMApiRequest() + public getTopTags( + params: LastFMUserGetTopTagsParams, + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -136,8 +127,11 @@ export class LastFMUser extends LastFM { .send(callback); } - public getTopTracks(params: LastFMUserGetTop, callback: LastFMUnknownFunction): Promise | void { - return new LastFMApiRequest() + public getTopTracks( + params: LastFMUserGetTopParams, + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -147,10 +141,10 @@ export class LastFMUser extends LastFM { } public getWeeklyAlbumChart( - params: LastFMUserGetWeekly, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + params: LastFMUserGetWeeklyParams, + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -160,10 +154,10 @@ export class LastFMUser extends LastFM { } public getWeeklyArtistChart( - params: LastFMUserGetWeekly, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + params: LastFMUserGetWeeklyParams, + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -174,9 +168,9 @@ export class LastFMUser extends LastFM { public getWeeklyChartList( params: LastFMUserParams, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, @@ -186,10 +180,10 @@ export class LastFMUser extends LastFM { } public getWeeklyTrackChart( - params: LastFMUserGetWeekly, - callback: LastFMUnknownFunction - ): Promise | void { - return new LastFMApiRequest() + params: LastFMUserGetWeeklyParams, + callback?: LastFMUnknownFunction + ): Promise { + return new LastFMApiRequest() .set(params) .set({ api_key: this.apiKey, diff --git a/tsconfig.json b/tsconfig.json index d5a6513..b7098ff 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,20 +1,12 @@ { "compilerOptions": { - "allowJs": false, - "allowSyntheticDefaultImports": true, "alwaysStrict": true, "baseUrl": "./", "checkJs": false, "declaration": true, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "forceConsistentCasingInFileNames": true, - "importHelpers": false, - "isolatedModules": true, - "jsx": "react", - "lib": ["DOM", "ESNext"], - "module": "ESNext", - "moduleResolution": "Node", + "lib": ["ESNext"], + "module": "NodeNext", + "moduleResolution": "NodeNext", "noEmit": false, "noEmitHelpers": false, "noEmitOnError": true, diff --git a/yarn.lock b/yarn.lock index 15dc288..8ed1d23 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9,6 +9,11 @@ dependencies: undici-types "~5.26.4" +dotenv@16.3.1: + version "16.3.1" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.1.tgz#369034de7d7e5b120972693352a3bf112172cc3e" + integrity sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ== + tslib@2.6.2: version "2.6.2" resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.2.tgz#703ac29425e7b37cd6fd456e92404d46d1f3e4ae"