musicbrainz-api 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/$CACHE_FILE$ +6 -0
- package/.idea/$PRODUCT_WORKSPACE_FILE$ +19 -0
- package/.idea/checkstyle-idea.xml +16 -0
- package/.idea/codeStyles/Project.xml +38 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/shelf/Uncommitted_changes_before_Update_at_6-1-2022_11_38_[Default_Changelist]/shelved.patch +58 -0
- package/.idea/shelf/Uncommitted_changes_before_Update_at_6-1-2022_11_38__Default_Changelist_.xml +4 -0
- package/.idea/shelf/Uncommitted_changes_before_rebase_[Default_Changelist]/shelved.patch +738 -0
- package/.idea/shelf/Uncommitted_changes_before_rebase_[Default_Changelist]1/shelved.patch +0 -0
- package/.idea/shelf/Uncommitted_changes_before_rebase__Default_Changelist_.xml +4 -0
- package/.idea/vcs.xml +6 -0
- package/.idea/workspace.xml +700 -0
- package/README.md +284 -285
- package/etc/config.js +32 -0
- package/lib/digest-auth.d.ts +21 -21
- package/lib/digest-auth.js +87 -86
- package/lib/musicbrainz-api.d.ts +157 -139
- package/lib/musicbrainz-api.js +387 -369
- package/lib/musicbrainz.types.d.ts +253 -257
- package/lib/musicbrainz.types.js +16 -15
- package/lib/rate-limiter.d.ts +8 -8
- package/lib/rate-limiter.js +31 -30
- package/lib/xml/xml-isrc-list.d.ts +17 -17
- package/lib/xml/xml-isrc-list.js +22 -21
- package/lib/xml/xml-isrc.d.ts +10 -10
- package/lib/xml/xml-isrc.js +17 -16
- package/lib/xml/xml-metadata.d.ts +6 -6
- package/lib/xml/xml-metadata.js +29 -28
- package/lib/xml/xml-recording.d.ts +24 -24
- package/lib/xml/xml-recording.js +20 -19
- package/package.json +98 -81
- package/yarn-error.log +3608 -0
- package/.travis.yml +0 -24
- package/lib/xml/xml-isrc-list.js.map +0 -1
- package/lib/xml/xml-isrc.js.map +0 -1
- package/lib/xml/xml-metadata.js.map +0 -1
- package/lib/xml/xml-recording.js.map +0 -1
- package/tsconfig.json +0 -9
- package/tslint.json +0 -26
|
@@ -1,257 +1,253 @@
|
|
|
1
|
-
import DateTimeFormat = Intl.DateTimeFormat;
|
|
2
|
-
export interface IPeriod {
|
|
3
|
-
'begin': string;
|
|
4
|
-
'ended': boolean;
|
|
5
|
-
'end': string;
|
|
6
|
-
}
|
|
7
|
-
export interface IArea {
|
|
8
|
-
id: string;
|
|
9
|
-
'iso-3166-1-codes': string;
|
|
10
|
-
name: string;
|
|
11
|
-
'sort-name': string;
|
|
12
|
-
disambiguation: string;
|
|
13
|
-
}
|
|
14
|
-
export interface IAlias {
|
|
15
|
-
name: string;
|
|
16
|
-
'sort-name': string;
|
|
17
|
-
ended: boolean;
|
|
18
|
-
'type-id': string;
|
|
19
|
-
type: string;
|
|
20
|
-
locale: string;
|
|
21
|
-
primary: string;
|
|
22
|
-
begin: string;
|
|
23
|
-
end: string;
|
|
24
|
-
}
|
|
25
|
-
export interface IMatch {
|
|
26
|
-
score: number;
|
|
27
|
-
}
|
|
28
|
-
export interface IArtist {
|
|
29
|
-
id: string;
|
|
30
|
-
name: string;
|
|
31
|
-
disambiguation: string;
|
|
32
|
-
'sort-name': string;
|
|
33
|
-
'type-id'?: string;
|
|
34
|
-
'gender-id'?: any;
|
|
35
|
-
'life-span'?: IPeriod;
|
|
36
|
-
country?: string;
|
|
37
|
-
ipis?: any[];
|
|
38
|
-
isnis?: string[];
|
|
39
|
-
aliases?: IAlias[];
|
|
40
|
-
gender?: null;
|
|
41
|
-
type?: string;
|
|
42
|
-
area?: IArea;
|
|
43
|
-
begin_area?: IArea;
|
|
44
|
-
end_area?: IArea;
|
|
45
|
-
relations?: IRelation[];
|
|
46
|
-
/**
|
|
47
|
-
* Only defined if 'releases' are includes
|
|
48
|
-
*/
|
|
49
|
-
releases?: IRelease[];
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
export
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
'
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
'
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
'
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
'
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
export interface
|
|
140
|
-
}
|
|
141
|
-
export interface
|
|
142
|
-
}
|
|
143
|
-
export interface
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
export interface
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
'
|
|
170
|
-
|
|
171
|
-
'
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
'
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
export interface
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
export interface
|
|
192
|
-
id: string;
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
export interface
|
|
196
|
-
id: string;
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
export interface
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
*
|
|
242
|
-
*/
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
* Lucene search query, this is mandatory
|
|
255
|
-
*/
|
|
256
|
-
query: string;
|
|
257
|
-
}
|
|
1
|
+
import DateTimeFormat = Intl.DateTimeFormat;
|
|
2
|
+
export interface IPeriod {
|
|
3
|
+
'begin': string;
|
|
4
|
+
'ended': boolean;
|
|
5
|
+
'end': string;
|
|
6
|
+
}
|
|
7
|
+
export interface IArea {
|
|
8
|
+
id: string;
|
|
9
|
+
'iso-3166-1-codes': string[];
|
|
10
|
+
name: string;
|
|
11
|
+
'sort-name': string;
|
|
12
|
+
disambiguation: string;
|
|
13
|
+
}
|
|
14
|
+
export interface IAlias {
|
|
15
|
+
name: string;
|
|
16
|
+
'sort-name': string;
|
|
17
|
+
ended: boolean;
|
|
18
|
+
'type-id': string;
|
|
19
|
+
type: string;
|
|
20
|
+
locale: string;
|
|
21
|
+
primary: string;
|
|
22
|
+
begin: string;
|
|
23
|
+
end: string;
|
|
24
|
+
}
|
|
25
|
+
export interface IMatch {
|
|
26
|
+
score: number;
|
|
27
|
+
}
|
|
28
|
+
export interface IArtist {
|
|
29
|
+
id: string;
|
|
30
|
+
name: string;
|
|
31
|
+
disambiguation: string;
|
|
32
|
+
'sort-name': string;
|
|
33
|
+
'type-id'?: string;
|
|
34
|
+
'gender-id'?: any;
|
|
35
|
+
'life-span'?: IPeriod;
|
|
36
|
+
country?: string;
|
|
37
|
+
ipis?: any[];
|
|
38
|
+
isnis?: string[];
|
|
39
|
+
aliases?: IAlias[];
|
|
40
|
+
gender?: null;
|
|
41
|
+
type?: string;
|
|
42
|
+
area?: IArea;
|
|
43
|
+
begin_area?: IArea;
|
|
44
|
+
end_area?: IArea;
|
|
45
|
+
relations?: IRelation[];
|
|
46
|
+
/**
|
|
47
|
+
* Only defined if 'releases' are includes
|
|
48
|
+
*/
|
|
49
|
+
releases?: IRelease[];
|
|
50
|
+
'release-groups'?: IReleaseGroup[];
|
|
51
|
+
}
|
|
52
|
+
export interface IArtistCredit {
|
|
53
|
+
artist: IArtist;
|
|
54
|
+
joinphrase: string;
|
|
55
|
+
name: string;
|
|
56
|
+
}
|
|
57
|
+
export declare type ReleaseQuality = 'normal';
|
|
58
|
+
export interface IRelease {
|
|
59
|
+
id: string;
|
|
60
|
+
title: string;
|
|
61
|
+
'text-representation': {
|
|
62
|
+
'language': string;
|
|
63
|
+
'script': string;
|
|
64
|
+
};
|
|
65
|
+
disambiguation: string;
|
|
66
|
+
asin: string;
|
|
67
|
+
'status-id': string;
|
|
68
|
+
packaging?: string;
|
|
69
|
+
status: string;
|
|
70
|
+
'packaging-id'?: string;
|
|
71
|
+
'release-events'?: IReleaseEvent[];
|
|
72
|
+
date: string;
|
|
73
|
+
media: IMedium[];
|
|
74
|
+
'cover-art-archive': ICoverArtArchive;
|
|
75
|
+
country: string;
|
|
76
|
+
quality: string;
|
|
77
|
+
barcode: string;
|
|
78
|
+
relations?: IRelation[];
|
|
79
|
+
'artist-credit'?: IArtistCredit[];
|
|
80
|
+
'release-group'?: IReleaseGroup;
|
|
81
|
+
}
|
|
82
|
+
export interface IReleaseEvent {
|
|
83
|
+
area?: IArea;
|
|
84
|
+
date?: string;
|
|
85
|
+
}
|
|
86
|
+
export declare type MediaFormatType = 'Digital Media';
|
|
87
|
+
export interface IRecording {
|
|
88
|
+
id: string;
|
|
89
|
+
video: boolean;
|
|
90
|
+
length: number;
|
|
91
|
+
title: string;
|
|
92
|
+
disambiguation: string;
|
|
93
|
+
isrcs?: string[];
|
|
94
|
+
releases?: IRelease;
|
|
95
|
+
relations?: IRelation[];
|
|
96
|
+
'artist-credit'?: IArtistCredit[];
|
|
97
|
+
aliases?: IAlias[];
|
|
98
|
+
}
|
|
99
|
+
export interface ITrack {
|
|
100
|
+
id: string;
|
|
101
|
+
position: number;
|
|
102
|
+
recording: IRecording;
|
|
103
|
+
number: string;
|
|
104
|
+
length: number;
|
|
105
|
+
title: string;
|
|
106
|
+
'artist-credit'?: IArtistCredit[];
|
|
107
|
+
}
|
|
108
|
+
export interface IMedium {
|
|
109
|
+
title: string;
|
|
110
|
+
format?: string;
|
|
111
|
+
'format-id': string;
|
|
112
|
+
'tracks': ITrack[];
|
|
113
|
+
'track-count': number;
|
|
114
|
+
'track-offset': number;
|
|
115
|
+
'position': number;
|
|
116
|
+
}
|
|
117
|
+
export interface ICoverArtArchive {
|
|
118
|
+
count: number;
|
|
119
|
+
front: boolean;
|
|
120
|
+
darkened: boolean;
|
|
121
|
+
artwork: boolean;
|
|
122
|
+
back: boolean;
|
|
123
|
+
}
|
|
124
|
+
export interface IReleaseGroup {
|
|
125
|
+
id: string;
|
|
126
|
+
count: number;
|
|
127
|
+
title: string;
|
|
128
|
+
'primary-type': string;
|
|
129
|
+
'sort-name': string;
|
|
130
|
+
'artist-credit': [{
|
|
131
|
+
artist: IArtist;
|
|
132
|
+
}];
|
|
133
|
+
releases?: IRelease[];
|
|
134
|
+
}
|
|
135
|
+
export interface IArtistMatch extends IArtist, IMatch {
|
|
136
|
+
}
|
|
137
|
+
export interface IReleaseGroupMatch extends IReleaseGroup, IMatch {
|
|
138
|
+
}
|
|
139
|
+
export interface IReleaseMatch extends IRelease, IMatch {
|
|
140
|
+
}
|
|
141
|
+
export interface IAreaMatch extends IArea, IMatch {
|
|
142
|
+
}
|
|
143
|
+
export interface ISearchResult {
|
|
144
|
+
created: DateTimeFormat;
|
|
145
|
+
count: number;
|
|
146
|
+
offset: number;
|
|
147
|
+
}
|
|
148
|
+
export interface IArtistList extends ISearchResult {
|
|
149
|
+
artists: IArtistMatch[];
|
|
150
|
+
}
|
|
151
|
+
export interface IAreaList extends ISearchResult {
|
|
152
|
+
areas: IAreaMatch[];
|
|
153
|
+
}
|
|
154
|
+
export interface IReleaseList extends ISearchResult {
|
|
155
|
+
releases: IReleaseMatch[];
|
|
156
|
+
}
|
|
157
|
+
export interface IReleaseGroupList extends ISearchResult {
|
|
158
|
+
'release-groups': IReleaseGroupMatch[];
|
|
159
|
+
}
|
|
160
|
+
export interface IUrlList extends ISearchResult {
|
|
161
|
+
urls: IUrlMatch[];
|
|
162
|
+
}
|
|
163
|
+
export declare type RelationDirection = 'backward' | 'forward';
|
|
164
|
+
export interface IRelation {
|
|
165
|
+
'attribute-ids': {};
|
|
166
|
+
direction: RelationDirection;
|
|
167
|
+
'target-credit': string;
|
|
168
|
+
end: null | object;
|
|
169
|
+
'source-credit': string;
|
|
170
|
+
ended: boolean;
|
|
171
|
+
'attribute-values': object;
|
|
172
|
+
attributes?: any[];
|
|
173
|
+
type: string;
|
|
174
|
+
begin?: null | object;
|
|
175
|
+
'target-type'?: 'url';
|
|
176
|
+
'type-id': string;
|
|
177
|
+
url?: IURL;
|
|
178
|
+
release?: IRelease;
|
|
179
|
+
}
|
|
180
|
+
export interface IURL {
|
|
181
|
+
id: string;
|
|
182
|
+
resource: string;
|
|
183
|
+
}
|
|
184
|
+
export interface IRelationList {
|
|
185
|
+
relations: IRelation[];
|
|
186
|
+
}
|
|
187
|
+
export interface IWork {
|
|
188
|
+
id: string;
|
|
189
|
+
title: string;
|
|
190
|
+
}
|
|
191
|
+
export interface ILabel {
|
|
192
|
+
id: string;
|
|
193
|
+
name: string;
|
|
194
|
+
}
|
|
195
|
+
export interface IUrl {
|
|
196
|
+
id: string;
|
|
197
|
+
resource: string;
|
|
198
|
+
'relation-list': IRelationList[];
|
|
199
|
+
}
|
|
200
|
+
export interface IUrlMatch extends IMatch, IUrl {
|
|
201
|
+
}
|
|
202
|
+
export interface IUrlSearchResult extends ISearchResult {
|
|
203
|
+
urls?: IUrlMatch[];
|
|
204
|
+
}
|
|
205
|
+
export interface IIsrcSearchResult {
|
|
206
|
+
'isrc': string;
|
|
207
|
+
'recordings': IRecording[];
|
|
208
|
+
}
|
|
209
|
+
export interface IExernalIds {
|
|
210
|
+
[type: string]: string;
|
|
211
|
+
}
|
|
212
|
+
export interface IReleaseSearchResult extends ISearchResult {
|
|
213
|
+
releases: IRelease[];
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* https://musicbrainz.org/doc/Development/XML_Web_Service/Version_2#Subqueries
|
|
217
|
+
*/
|
|
218
|
+
export declare type EntityType = 'area' | 'artist' | 'collection' | 'event' | 'instrument' | 'label' | 'place' | 'recording' | 'release' | 'release-group' | 'series' | 'work' | 'url';
|
|
219
|
+
export declare type Relationships = 'area-rels' | 'artist-rels' | 'event-rels' | 'instrument-rels' | 'label-rels' | 'place-rels' | 'recording-rels' | 'release-rels' | 'release-group-rels' | 'series-rels' | 'url-rels' | 'work-rels';
|
|
220
|
+
export declare enum LinkType {
|
|
221
|
+
license = 302,
|
|
222
|
+
production = 256,
|
|
223
|
+
samples_IMDb_entry = 258,
|
|
224
|
+
get_the_music = 257,
|
|
225
|
+
purchase_for_download = 254,
|
|
226
|
+
download_for_free = 255,
|
|
227
|
+
stream_for_free = 268,
|
|
228
|
+
crowdfunding_page = 905,
|
|
229
|
+
other_databases = 306,
|
|
230
|
+
Allmusic = 285
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* https://wiki.musicbrainz.org/Development/XML_Web_Service/Version_2/Search#Artist
|
|
234
|
+
*/
|
|
235
|
+
export interface IPagination {
|
|
236
|
+
/**
|
|
237
|
+
* Return search results starting at a given offset. Used for paging through more than one page of results.
|
|
238
|
+
*/
|
|
239
|
+
offset?: number;
|
|
240
|
+
/**
|
|
241
|
+
* An integer value defining how many entries should be returned. Only values between 1 and 100 (both inclusive) are allowed. If not given, this defaults to 25.
|
|
242
|
+
*/
|
|
243
|
+
limit?: number;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* https://wiki.musicbrainz.org/Development/XML_Web_Service/Version_2/Search#Artist
|
|
247
|
+
*/
|
|
248
|
+
export interface ISearchQuery extends IPagination {
|
|
249
|
+
/**
|
|
250
|
+
* Lucene search query, this is mandatory
|
|
251
|
+
*/
|
|
252
|
+
query: string;
|
|
253
|
+
}
|
package/lib/musicbrainz.types.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
LinkType[LinkType["
|
|
7
|
-
LinkType[LinkType["
|
|
8
|
-
LinkType[LinkType["
|
|
9
|
-
LinkType[LinkType["
|
|
10
|
-
LinkType[LinkType["
|
|
11
|
-
LinkType[LinkType["
|
|
12
|
-
LinkType[LinkType["
|
|
13
|
-
LinkType[LinkType["
|
|
14
|
-
LinkType[LinkType["
|
|
15
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LinkType = void 0;
|
|
4
|
+
var LinkType;
|
|
5
|
+
(function (LinkType) {
|
|
6
|
+
LinkType[LinkType["license"] = 302] = "license";
|
|
7
|
+
LinkType[LinkType["production"] = 256] = "production";
|
|
8
|
+
LinkType[LinkType["samples_IMDb_entry"] = 258] = "samples_IMDb_entry";
|
|
9
|
+
LinkType[LinkType["get_the_music"] = 257] = "get_the_music";
|
|
10
|
+
LinkType[LinkType["purchase_for_download"] = 254] = "purchase_for_download";
|
|
11
|
+
LinkType[LinkType["download_for_free"] = 255] = "download_for_free";
|
|
12
|
+
LinkType[LinkType["stream_for_free"] = 268] = "stream_for_free";
|
|
13
|
+
LinkType[LinkType["crowdfunding_page"] = 905] = "crowdfunding_page";
|
|
14
|
+
LinkType[LinkType["other_databases"] = 306] = "other_databases";
|
|
15
|
+
LinkType[LinkType["Allmusic"] = 285] = "Allmusic";
|
|
16
|
+
})(LinkType = exports.LinkType || (exports.LinkType = {}));
|
|
16
17
|
//# sourceMappingURL=musicbrainz.types.js.map
|
package/lib/rate-limiter.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export declare class RateLimiter {
|
|
2
|
-
private maxCalls;
|
|
3
|
-
static sleep(ms: any): Promise<void>;
|
|
4
|
-
queue: number[];
|
|
5
|
-
private readonly period;
|
|
6
|
-
constructor(period: number, maxCalls: number);
|
|
7
|
-
limit(): Promise<void>;
|
|
8
|
-
}
|
|
1
|
+
export declare class RateLimiter {
|
|
2
|
+
private maxCalls;
|
|
3
|
+
static sleep(ms: any): Promise<void>;
|
|
4
|
+
queue: number[];
|
|
5
|
+
private readonly period;
|
|
6
|
+
constructor(period: number, maxCalls: number);
|
|
7
|
+
limit(): Promise<void>;
|
|
8
|
+
}
|
package/lib/rate-limiter.js
CHANGED
|
@@ -1,31 +1,32 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
this.
|
|
9
|
-
this.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RateLimiter = void 0;
|
|
4
|
+
const Debug = require("debug");
|
|
5
|
+
const debug = Debug('musicbrainz-api:rate-limiter');
|
|
6
|
+
class RateLimiter {
|
|
7
|
+
constructor(period, maxCalls) {
|
|
8
|
+
this.maxCalls = maxCalls;
|
|
9
|
+
this.queue = [];
|
|
10
|
+
this.period = 1000 * period;
|
|
11
|
+
}
|
|
12
|
+
static sleep(ms) {
|
|
13
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
14
|
+
}
|
|
15
|
+
async limit() {
|
|
16
|
+
let now = new Date().getTime();
|
|
17
|
+
const t0 = now - (this.period);
|
|
18
|
+
while (this.queue.length > 0 && this.queue[0] < t0) {
|
|
19
|
+
this.queue.shift();
|
|
20
|
+
}
|
|
21
|
+
if (this.queue.length >= this.maxCalls) {
|
|
22
|
+
const delay = this.queue[0] + this.period - now;
|
|
23
|
+
debug(`Client side rate limiter activated: cool down for ${delay / 1000} s...`);
|
|
24
|
+
return RateLimiter.sleep(delay);
|
|
25
|
+
}
|
|
26
|
+
now = new Date().getTime();
|
|
27
|
+
this.queue.push(now);
|
|
28
|
+
// const ratePerSec = 1000 * this.queue.length / (now - this.queue[0]);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.RateLimiter = RateLimiter;
|
|
31
32
|
//# sourceMappingURL=rate-limiter.js.map
|