Skip to content

Commit 06fcd0d

Browse files
authored
Usage and typings updates (#28)
1 parent 5deb751 commit 06fcd0d

File tree

21 files changed

+1993
-548
lines changed

21 files changed

+1993
-548
lines changed

.codebeatsettings

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"TYPESCRIPT": {
3+
"ABC": [
4+
30,
5+
60,
6+
120,
7+
180
8+
],
9+
"LOC": [
10+
75,
11+
120,
12+
180,
13+
240
14+
],
15+
"TOTAL_LOC": [
16+
600,
17+
750,
18+
960,
19+
1350
20+
],
21+
"BLOCK_NESTING": [
22+
9,
23+
12,
24+
15,
25+
18
26+
]
27+
}
28+
}

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
LAST_FM_API_KEY=""

.github/workflows/build.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,10 @@ jobs:
1616
uses: actions/setup-node@v4
1717
with:
1818
node-version: ${{ matrix.node-version }}
19-
- run: yarn
20-
- run: yarn build
19+
- name: Build
20+
run: |
21+
yarn
22+
yarn build
23+
yarn demo
24+
env:
25+
LAST_FM_API_KEY: ${{ secrets.LAST_FM_API_KEY }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ ehthumbs.db
1818
Thumbs.db
1919

2020
# Project specific
21+
.env
2122
/dist

.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ Thumbs.db
2121
.github
2222
_config.yml
2323
_.config.yml
24+
.codebeatsettings
25+
.env
26+
.env.example
2427
.editorconfig
2528
.gitattributes
2629
.gitignore
@@ -37,3 +40,4 @@ tslint.json
3740
yarn.lock
3841

3942
!dist
43+
demo

demo/index.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// @ts-nocheck
2+
3+
import { config } from 'dotenv';
4+
5+
import {
6+
LastFMGeo,
7+
LastFMTag,
8+
LastFMUser,
9+
LastFMAlbum,
10+
LastFMChart,
11+
LastFMTrack,
12+
LastFMArtist,
13+
LastFMLibrary
14+
} from '../dist/index.js';
15+
16+
config();
17+
18+
const API_KEY = process.env.LAST_FM_API_KEY;
19+
20+
const geo = new LastFMGeo(API_KEY);
21+
const tag = new LastFMTag(API_KEY);
22+
const user = new LastFMUser(API_KEY);
23+
const album = new LastFMAlbum(API_KEY);
24+
const chart = new LastFMChart(API_KEY);
25+
const track = new LastFMTrack(API_KEY);
26+
const artist = new LastFMArtist(API_KEY);
27+
const library = new LastFMLibrary(API_KEY);
28+
29+
const print = r => console.log(JSON.stringify(r, null, 2));
30+
31+
geo.getTopArtists({ country: 'Bulgaria', limit: 2 }).then(print);
32+
geo.getTopTracks({ country: 'Bulgaria', limit: 2 }).then(print);
33+
34+
tag.getInfo({ tag: 'techno', limit: 2 }).then(print);
35+
tag.getSimilar({ tag: 'techno', limit: 2 }).then(print);
36+
tag.getTopAlbums({ tag: 'techno', limit: 2 }).then(print);
37+
tag.getTopArtists({ tag: 'techno', limit: 2 }).then(print);
38+
tag.getTopTags().then(print);
39+
tag.getTopTracks({ tag: 'techno', limit: 2 }).then(print);
40+
tag.getWeeklyChartList({ tag: 'techno' }).then(print);
41+
42+
user.getFriends({ user: 'scriptex', limit: 2 }).then(print);
43+
user.getInfo({ user: 'scriptex' }).then(print);
44+
user.getLovedTracks({ user: 'scriptex', limit: 2 }).then(print);
45+
user.getPersonalTags({ user: 'scriptex', taggingtype: 'album', tag: 'techno', limit: 2 }).then(print);
46+
user.getPersonalTags({ user: 'scriptex', taggingtype: 'artist', tag: 'techno', limit: 2 }).then(print);
47+
user.getPersonalTags({ user: 'scriptex', taggingtype: 'track', tag: 'techno', limit: 2 }).then(print);
48+
user.getRecentTracks({ user: 'scriptex', limit: 2 }).then(print);
49+
user.getTopAlbums({ user: 'scriptex', limit: 2 }).then(print);
50+
user.getTopArtists({ user: 'scriptex', limit: 2 }).then(print);
51+
user.getTopTags({ user: 'scriptex', limit: 2 }).then(print);
52+
user.getTopTracks({ user: 'scriptex', limit: 2 }).then(print);
53+
user.getWeeklyAlbumChart({ user: 'scriptex', limit: 2 }).then(print);
54+
user.getWeeklyArtistChart({ user: 'scriptex', limit: 2 }).then(print);
55+
user.getWeeklyChartList({ user: 'scriptex' }).then(print);
56+
user.getWeeklyTrackChart({ user: 'scriptex' }).then(print);
57+
58+
album.getInfo({ album: 'The Fat of The Land', artist: 'The Prodigy' }).then(print);
59+
//NOSONAR
60+
// album.getTags({ album: 'The Fat of The Land', artist: 'The Prodigy' }).then(print);
61+
album.getTopTags({ album: 'The Fat of The Land', artist: 'The Prodigy' }).then(print);
62+
album.search({ album: 'The Fat of The Land', artist: 'The Prodigy' }).then(print);
63+
64+
chart.getTopArtists({ limit: 2 }).then(print);
65+
chart.getTopTags({ limit: 2 }).then(print);
66+
chart.getTopTracks({ limit: 2 }).then(print);
67+
68+
track.getCorrection({ track: 'Firestarter', artist: 'The Prodigy' }).then(print);
69+
track.getInfo({ track: 'Firestarter', artist: 'The Prodigy' }).then(print);
70+
track.getSimilar({ track: 'Firestarter', artist: 'The Prodigy', limit: 2 }).then(print);
71+
//NOSONAR
72+
// track.getTags({ track: 'Firestarter', artist: 'The Prodigy', limit: 2 }).then(print);
73+
track.getTopTags({ track: 'Firestarter', artist: 'The Prodigy', limit: 2 }).then(print);
74+
track.search({ track: 'Firestarter', artist: 'The Prodigy', limit: 2 }).then(print);
75+
76+
artist.getCorrection({ artist: 'The Prodigy' }).then(print);
77+
artist.getInfo({ artist: 'The Prodigy' }).then(print);
78+
artist.getSimilar({ artist: 'The Prodigy', limit: 2 }).then(print);
79+
//NOSONAR
80+
// artist.getTags({ artist: 'The Prodigy' }).then(print);
81+
artist.getTopAlbums({ artist: 'The Prodigy', limit: 2 }).then(print);
82+
artist.getTopTags({ artist: 'The Prodigy' }).then(print);
83+
artist.getTopTracks({ artist: 'The Prodigy', limit: 2 }).then(print);
84+
artist.search({ artist: 'The Prodigy', limit: 2 }).then(print);
85+
86+
library.getArtists({ user: 'scriptex', limit: 2 }).then(print);

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lastfm-ts-api",
3-
"version": "1.0.2",
3+
"version": "2.0.0",
44
"description": "An API client for the Last.FM API written in TypeScript",
55
"keywords": [
66
"Last.FM",
@@ -17,18 +17,21 @@
1717
"author": "Atanas Atanasov <[email protected]> (https://atanas.info)",
1818
"funding": "https://github.com/sponsors/scriptex",
1919
"main": "dist/index.js",
20+
"type": "module",
2021
"types": "dist/index.d.ts",
2122
"repository": {
2223
"type": "git",
2324
"url": "github:scriptex/lastfm-ts-api"
2425
},
2526
"scripts": {
2627
"watch": "tsc -w",
27-
"build": "tsc"
28+
"build": "tsc",
29+
"demo": "node demo/index.js"
2830
},
2931
"dependencies": {},
3032
"devDependencies": {
3133
"@types/node": "20.8.9",
34+
"dotenv": "16.3.1",
3235
"tslib": "2.6.2",
3336
"typescript": "5.2.2"
3437
}

src/album.ts

Lines changed: 32 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,21 @@
1-
import { LastFM } from './base';
2-
import { LastFMParam, LastFMApiRequest, LastFMRequestParams, LastFMUnknownFunction } from './api-request';
3-
4-
export interface LastFMAlbumParams {
5-
readonly album: string;
6-
readonly artist: string;
7-
}
8-
9-
export interface LastFMAlbumOptionalParams {
10-
readonly mbid?: string;
11-
readonly autocorrect?: 0 | 1;
12-
}
13-
14-
export interface LastFMAlbumAddTagsParams extends LastFMRequestParams<LastFMParam>, LastFMAlbumParams {
15-
readonly tags: string | string[];
16-
}
17-
18-
export interface LastFMAlbumGetInfoParams
19-
extends LastFMRequestParams<0 | 1 | void>,
20-
LastFMAlbumParams,
21-
LastFMAlbumOptionalParams {
22-
readonly lang?: string;
23-
readonly username?: string;
24-
}
25-
26-
export interface LastFMAlbumGetTagsParams
27-
extends LastFMRequestParams<0 | 1 | void>,
28-
LastFMAlbumParams,
29-
LastFMAlbumOptionalParams {
30-
readonly user?: string;
31-
}
32-
33-
export interface LastFMAlbumGetTopTagsParams
34-
extends LastFMRequestParams<0 | 1 | void>,
35-
LastFMAlbumParams,
36-
LastFMAlbumOptionalParams {}
37-
38-
export interface LastFMAlbumRemoveLastFMTagParams extends LastFMRequestParams<LastFMParam>, LastFMAlbumParams {
39-
readonly tag: string;
40-
}
41-
42-
export interface LastFMAlbumSearchParams extends LastFMRequestParams<number | void> {
43-
readonly page?: number;
44-
readonly album: string;
45-
readonly limit?: number;
46-
}
1+
import { LastFM } from './base.js';
2+
import { LastFMApiRequest } from './api-request.js';
3+
import {
4+
LastFMUnknownFunction,
5+
LastFMAlbumSearchParams,
6+
LastFMAlbumAddTagsParams,
7+
LastFMAlbumGetInfoParams,
8+
LastFMAlbumGetTagsParams,
9+
LastFMAlbumSearchResponse,
10+
LastFMAlbumGetInfoResponse,
11+
LastFMAlbumGetTagsResponse,
12+
LastFMAlbumGetTopTagsParams,
13+
LastFMAlbumRemoveLastFMTagParams
14+
} from './types.js';
4715

4816
export class LastFMAlbum extends LastFM {
49-
constructor(apiKey: string, secret?: string, sessionKey?: string) {
50-
super(apiKey, secret, sessionKey);
51-
}
52-
53-
public addTags(
54-
params: LastFMAlbumAddTagsParams,
55-
callback: LastFMUnknownFunction
56-
): Promise<LastFMApiRequest> | void {
57-
return new LastFMApiRequest()
17+
public addTags(params: LastFMAlbumAddTagsParams, callback?: LastFMUnknownFunction): Promise<void> {
18+
return new LastFMApiRequest<void>()
5819
.set(params)
5920
.set({
6021
api_key: this.apiKey,
@@ -67,9 +28,9 @@ export class LastFMAlbum extends LastFM {
6728

6829
public getInfo(
6930
params: LastFMAlbumGetInfoParams,
70-
callback: LastFMUnknownFunction
71-
): Promise<LastFMApiRequest> | void {
72-
return new LastFMApiRequest()
31+
callback?: LastFMUnknownFunction
32+
): Promise<LastFMAlbumGetInfoResponse> {
33+
return new LastFMApiRequest<LastFMAlbumGetInfoResponse>()
7334
.set(params)
7435
.set({
7536
api_key: this.apiKey,
@@ -80,9 +41,9 @@ export class LastFMAlbum extends LastFM {
8041

8142
public getTags(
8243
params: LastFMAlbumGetTagsParams,
83-
callback: LastFMUnknownFunction
84-
): Promise<LastFMApiRequest> | void {
85-
return new LastFMApiRequest()
44+
callback?: LastFMUnknownFunction
45+
): Promise<LastFMAlbumGetTagsResponse> {
46+
return new LastFMApiRequest<LastFMAlbumGetTagsResponse>()
8647
.set(params)
8748
.set({
8849
api_key: this.apiKey,
@@ -93,9 +54,9 @@ export class LastFMAlbum extends LastFM {
9354

9455
public getTopTags(
9556
params: LastFMAlbumGetTopTagsParams,
96-
callback: LastFMUnknownFunction
97-
): Promise<LastFMApiRequest> | void {
98-
return new LastFMApiRequest()
57+
callback?: LastFMUnknownFunction
58+
): Promise<LastFMAlbumGetTagsResponse> {
59+
return new LastFMApiRequest<LastFMAlbumGetTagsResponse>()
9960
.set(params)
10061
.set({
10162
api_key: this.apiKey,
@@ -104,11 +65,8 @@ export class LastFMAlbum extends LastFM {
10465
.send(callback);
10566
}
10667

107-
public removeTag(
108-
params: LastFMAlbumRemoveLastFMTagParams,
109-
callback: LastFMUnknownFunction
110-
): Promise<LastFMApiRequest> | void {
111-
return new LastFMApiRequest()
68+
public removeTag(params: LastFMAlbumRemoveLastFMTagParams, callback?: LastFMUnknownFunction): Promise<void> {
69+
return new LastFMApiRequest<void>()
11270
.set(params)
11371
.set({
11472
api_key: this.apiKey,
@@ -119,8 +77,11 @@ export class LastFMAlbum extends LastFM {
11977
.send('POST', callback);
12078
}
12179

122-
public search(params: LastFMAlbumSearchParams, callback: LastFMUnknownFunction): Promise<LastFMApiRequest> | void {
123-
return new LastFMApiRequest()
80+
public search(
81+
params: LastFMAlbumSearchParams,
82+
callback?: LastFMUnknownFunction
83+
): Promise<LastFMAlbumSearchResponse> {
84+
return new LastFMApiRequest<LastFMAlbumSearchResponse>()
12485
.set(params)
12586
.set({
12687
api_key: this.apiKey,

0 commit comments

Comments
 (0)