musicbrainz-api 0.10.3 → 0.11.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.
@@ -1,689 +0,0 @@
1
- import DateTimeFormat = Intl.DateTimeFormat;
2
- import { IFormData } from './musicbrainz-api';
3
-
4
- export interface IPeriod {
5
- 'begin': string;
6
- 'ended': boolean;
7
- 'end': string;
8
- }
9
-
10
- export interface IEntity {
11
- id: string;
12
- }
13
-
14
- export interface IArea extends IEntity {
15
- 'iso-3166-1-codes': string[];
16
- name: string;
17
- 'sort-name': string;
18
- disambiguation: string;
19
- }
20
-
21
- export interface IAlias extends IEntity {
22
- name: string;
23
- 'sort-name': string;
24
- ended: boolean;
25
- 'type-id': string;
26
- type: string;
27
- locale: string;
28
- primary: string;
29
- begin: string;
30
- end: string;
31
- }
32
-
33
- export interface IMatch {
34
- score: number; // ToDo: provide feedback: should be a number
35
- }
36
-
37
- export interface IArtist extends IEntity {
38
- name: string;
39
- disambiguation: string;
40
- 'sort-name': string;
41
- 'type-id'?: string;
42
- 'gender-id'?;
43
- 'life-span'?: IPeriod;
44
- country?: string;
45
- ipis?: any[]; // ToDo
46
- isnis?: string[];
47
- aliases?: IAlias[];
48
- gender?: string;
49
- type?: string;
50
- area?: IArea;
51
- begin_area?: IArea;
52
- end_area?: IArea;
53
- relations?: IRelation[];
54
- /**
55
- * Only defined if 'releases' are includes
56
- */
57
- releases?: IRelease[];
58
- 'release-groups'?: IReleaseGroup[];
59
- }
60
-
61
- export interface IArtistCredit {
62
- artist: IArtist;
63
- joinphrase: string;
64
- name: string;
65
- }
66
-
67
- export interface ICollection extends IEntity {
68
- type: string;
69
- name: string;
70
- 'type-id': string;
71
- 'recording-count': number;
72
- editor: string;
73
- 'entity-type': string;
74
- }
75
-
76
- export interface IEvent extends IEntity {
77
- cancelled: boolean;
78
- type: string;
79
- 'life-span': IPeriod;
80
- disambiguation: string;
81
- 'type-id': string;
82
- time: string;
83
- setlist: string;
84
- name: string;
85
- }
86
-
87
- export interface IInstrument extends IEntity {
88
- disambiguation: string;
89
- name: string;
90
- 'type-id': string;
91
- type: string;
92
- description: string;
93
- }
94
-
95
- export type ReleaseQuality = 'normal'; // ToDo
96
-
97
- export interface IRelease extends IEntity {
98
- title: string;
99
- 'text-representation': { 'language': string, 'script': string },
100
- disambiguation: string;
101
- asin: string,
102
- 'status-id': string;
103
- packaging?: string;
104
- status: string;
105
- 'packaging-id'?: string;
106
- 'release-events'?: IReleaseEvent[];
107
- date: string;
108
- media: IMedium[];
109
- 'cover-art-archive': ICoverArtArchive;
110
- country: string;
111
- quality: string; // type ReleaseQuality doesnt work here
112
- barcode: string;
113
- relations?: IRelation[];
114
- 'artist-credit'?: IArtistCredit[]; // Include 'artist-credits '
115
- 'release-group'?: IReleaseGroup; // Include: 'release-groups'
116
- }
117
-
118
- export interface IReleaseEvent {
119
- area?: IArea;
120
- date?: string;
121
- }
122
-
123
- export type MediaFormatType = 'Digital Media'; // ToDo
124
-
125
- export interface IRecording extends IEntity {
126
- video: boolean;
127
- length: number;
128
- title: string;
129
- disambiguation: string;
130
- isrcs?: string[];
131
- releases?: IRelease[];
132
- relations?: IRelation[];
133
- 'artist-credit'?: IArtistCredit[];
134
- aliases?: IAlias[];
135
- }
136
-
137
- export interface ITrack extends IEntity{
138
- position: number;
139
- recording: IRecording;
140
- 'number': string; // in JSON, this is a string field
141
- length: number;
142
- title: string;
143
- 'artist-credit'?: IArtistCredit[];
144
- }
145
-
146
- export interface IMedium {
147
- title: string;
148
- format?: string; // optional, type dosent work
149
- 'format-id': string;
150
- tracks: ITrack[];
151
- 'track-count': number;
152
- 'track-offset': number;
153
- position: number;
154
- }
155
-
156
- export interface ICoverArtArchive {
157
- count: number;
158
- front: boolean;
159
- darkened: boolean;
160
- artwork: boolean;
161
- back: boolean;
162
- }
163
-
164
- export interface IReleaseGroup extends IEntity {
165
- count: number;
166
- disambiguation?: string;
167
- title: string;
168
- 'secondary-types': string[];
169
- 'first-release-date': string;
170
- 'primary-type': string;
171
- 'primary-type-id'?: string,
172
- 'secondary-type-ids'?: string[],
173
- 'sort-name': string;
174
- 'artist-credit': { artist: IArtist, name: string, joinphrase: string }[];
175
- releases?: IRelease[]; // include 'releases'
176
- }
177
-
178
- export interface IArtistMatch extends IArtist, IMatch {
179
- }
180
-
181
- export interface IReleaseGroupMatch extends IReleaseGroup, IMatch {
182
- }
183
-
184
- export interface IReleaseMatch extends IRelease, IMatch {
185
- }
186
-
187
- export interface IAreaMatch extends IArea, IMatch {
188
- }
189
-
190
- export interface ISearchResult {
191
- created: DateTimeFormat;
192
- count: number;
193
- offset: number;
194
- }
195
-
196
- export interface IArtistList extends ISearchResult {
197
- artists: IArtistMatch[];
198
- }
199
-
200
- export interface IAreaList extends ISearchResult {
201
- areas: IAreaMatch[];
202
- }
203
-
204
- export interface IReleaseList extends ISearchResult {
205
- releases: IReleaseMatch[];
206
- }
207
-
208
- export interface IReleaseGroupList extends ISearchResult {
209
- 'release-groups': IReleaseGroupMatch[];
210
- }
211
-
212
- export interface IUrlList extends ISearchResult {
213
- urls: IUrlMatch[];
214
- }
215
-
216
- export type RelationDirection = 'backward' | 'forward';
217
-
218
- export interface IRelation {
219
- 'attribute-ids':any;
220
- direction: RelationDirection;
221
- 'target-credit': string;
222
- end: null | unknown;
223
- 'source-credit': string;
224
- ended: boolean;
225
- 'attribute-values': unknown;
226
- attributes?: any[];
227
- type: string;
228
- begin?: null | unknown;
229
- 'target-type'?: 'url';
230
- 'type-id': string;
231
- url?: IUrl;
232
- release?: IRelease;
233
- }
234
-
235
- export interface IRelationList {
236
- relations: IRelation[];
237
- }
238
-
239
- export interface IWork extends IEntity {
240
- title: string;
241
- }
242
-
243
- export interface ILabel extends IEntity {
244
- name: string;
245
- }
246
-
247
- export interface IPlace extends IEntity {
248
- name: string;
249
- }
250
-
251
- export interface IUrl extends IEntity {
252
- id: string,
253
- resource: string,
254
- 'relation-list'?: IRelationList[];
255
- }
256
-
257
- export interface IUrlMatch extends IMatch, IUrl {
258
- }
259
-
260
- export interface IUrlSearchResult extends ISearchResult {
261
- urls?: IUrlMatch[];
262
- }
263
-
264
- export interface IIsrcSearchResult extends ISearchResult {
265
- 'isrc': string;
266
- 'recordings': IRecording[];
267
- }
268
-
269
- export interface IExernalIds {
270
- [type: string]: string;
271
- }
272
-
273
- export interface IReleaseSearchResult extends ISearchResult {
274
- releases: IRelease[];
275
- }
276
-
277
- /**
278
- * https://musicbrainz.org/doc/Development/XML_Web_Service/Version_2#Subqueries
279
- */
280
- export type EntityType = 'area' |
281
- 'artist' |
282
- 'collection' |
283
- 'event' |
284
- 'instrument' |
285
- 'label' |
286
- 'place' |
287
- 'recording' |
288
- 'release' |
289
- 'release-group' |
290
- 'series' |
291
- 'work' |
292
- 'url';
293
-
294
- export type Relationships = 'area-rels' |
295
- 'artist-rels' |
296
- 'event-rels' |
297
- 'instrument-rels' |
298
- 'label-rels' |
299
- 'place-rels' |
300
- 'recording-rels' |
301
- 'release-rels' |
302
- 'release-group-rels' |
303
- 'series-rels' |
304
- 'url-rels' |
305
- 'work-rels';
306
-
307
- export enum LinkType {
308
- license = 302,
309
- production = 256,
310
- samples_IMDb_entry = 258,
311
- get_the_music = 257,
312
- purchase_for_download = 254,
313
- download_for_free = 255,
314
- stream_for_free = 268,
315
- crowdfunding_page = 905,
316
- other_databases = 306,
317
- Allmusic = 285
318
- }
319
-
320
- /**
321
- * https://wiki.musicbrainz.org/Development/XML_Web_Service/Version_2/Search#Artist
322
- */
323
- export interface IPagination {
324
- /**
325
- * Return search results starting at a given offset. Used for paging through more than one page of results.
326
- */
327
- offset?: number;
328
- /**
329
- * 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.
330
- */
331
- limit?: number;
332
- }
333
-
334
- /**
335
- * https://wiki.musicbrainz.org/Development/XML_Web_Service/Version_2/Search#Artist
336
- */
337
- export interface ISearchQuery<I extends string> extends IPagination {
338
- /**
339
- * Lucene search query, this is mandatory
340
- */
341
- query?: string | IFormData,
342
- inc?: I[]
343
- }
344
-
345
- /**
346
- * https://musicbrainz.org/doc/MusicBrainz_API#Browse
347
- * /ws/2/area collection
348
- */
349
- export interface ILinkedEntitiesArea {
350
- collection?: string;
351
- }
352
-
353
- /**
354
- * https://musicbrainz.org/doc/MusicBrainz_API#Browse
355
- * /ws/2/artist area, collection, recording, release, release-group, work
356
- */
357
- export interface ILinkedEntitiesArtist {
358
- area?: string;
359
- collection?: string;
360
- recording?: string;
361
- release?: string;
362
- 'release-group'?: string;
363
- work?: string;
364
- }
365
-
366
- /**
367
- * https://musicbrainz.org/doc/MusicBrainz_API#Browse
368
- * /ws/2/collection area, artist, editor, event, label, place, recording, release, release-group, work
369
- */
370
- export interface ILinkedEntitiesCollection {
371
- area?: string;
372
- artist?: string;
373
- editor?: string;
374
- event?: string;
375
- label?: string;
376
- place?: string;
377
- recording?: string;
378
- release?: string;
379
- 'release-group'?: string;
380
- work?: string;
381
- }
382
-
383
- /**
384
- * https://musicbrainz.org/doc/MusicBrainz_API#Subqueries
385
- * /ws/2/event area, artist, collection, place
386
- */
387
- export interface ILinkedEntitiesEvent {
388
- area?: string;
389
- artist?: string;
390
- collection?: string;
391
- place?: string;
392
- }
393
-
394
- /**
395
- * https://musicbrainz.org/doc/MusicBrainz_API#Subqueries
396
- * /ws/2/instrument collection
397
- */
398
- export interface ILinkedEntitiesInstrument {
399
- collection?: string;
400
- }
401
-
402
- /**
403
- * https://musicbrainz.org/doc/MusicBrainz_API#Subqueries
404
- * /ws/2/label area, collection, release
405
- */
406
- export interface ILinkedEntitiesLabel {
407
- area?: string;
408
- collection?: string;
409
- release?: string;
410
- }
411
-
412
- /**
413
- * https://musicbrainz.org/doc/MusicBrainz_API#Subqueries
414
- * /ws/2/place area, collection
415
- */
416
- export interface IBrowseArgumentPlace {
417
- area?: string;
418
- collection?: string;
419
- }
420
-
421
- /**
422
- * https://musicbrainz.org/doc/MusicBrainz_API#Subqueries
423
- * /ws/2/recording artist, collection, release, work
424
- */
425
- export interface ILinkedEntitiesRecording {
426
- area?: string;
427
- collection?: string;
428
- release?: string;
429
- work?: string;
430
- }
431
-
432
- /**
433
- * https://musicbrainz.org/doc/MusicBrainz_API#Subqueries
434
- * /ws/2/release area, artist, collection, label, track, track_artist, recording, release-group
435
- */
436
- export interface ILinkedEntitiesRelease {
437
- area?: string;
438
- artist?: string;
439
- collection?: string;
440
- label?: string;
441
- track?: string;
442
- track_artist?: string;
443
- recording?: string;
444
- 'release-group'?: string;
445
- }
446
-
447
- /**
448
- * https://musicbrainz.org/doc/MusicBrainz_API#Subqueries
449
- * /ws/2/release-group artist, collection, release
450
- */
451
- export interface ILinkedEntitiesReleaseGroup {
452
- artist?: string;
453
- collection?: string;
454
- release?: string;
455
- }
456
-
457
- /**
458
- * https://musicbrainz.org/doc/MusicBrainz_API#Subqueries
459
- * /ws/2/series collection
460
- */
461
- export interface ILinkedEntitiesSeries {
462
- collection?: string;
463
- }
464
-
465
- /**
466
- * https://musicbrainz.org/doc/MusicBrainz_API#Browse
467
- * /ws/2/work artist, collection
468
- */
469
- export interface ILinkedEntitiesWork {
470
- artist?: string;
471
- collection?: string;
472
- }
473
-
474
- /**
475
- * https://musicbrainz.org/doc/MusicBrainz_API#Browse
476
- * /ws/2/url resource
477
- */
478
- export interface ILinkedEntitiesUrl {
479
- resource?: string;
480
- }
481
-
482
- /**
483
- * Browse artist query <entity>: <MBID>
484
- * https://wiki.musicbrainz.org/MusicBrainz_API#Linked_entities
485
- */
486
- export interface IBrowseAreasQuery extends IPagination {
487
- collection?: string;
488
- }
489
-
490
- /**
491
- * Browse artist query <entity>: <MBID>
492
- * https://wiki.musicbrainz.org/MusicBrainz_API#Linked_entities
493
- */
494
- export interface IBrowseArtistsQuery extends IPagination {
495
- area?: string;
496
- collection?: string;
497
- recording?: string;
498
- release?: string;
499
- 'release-group'?: string;
500
- work?: string;
501
- }
502
-
503
- /**
504
- * Browse collection query <entity>: <MBID>
505
- * https://wiki.musicbrainz.org/MusicBrainz_API#Linked_entities
506
- */
507
- export interface IBrowseCollectionsQuery extends IPagination {
508
- area?: string;
509
- artist?: string;
510
- editor?: string;
511
- event?: string;
512
- label?: string;
513
- place?: string;
514
- recording?: string;
515
- release?: string;
516
- 'release-group'?: string;
517
- work?: string;
518
- }
519
-
520
- /**
521
- * Browse events query <entity>: <MBID>
522
- * https://wiki.musicbrainz.org/MusicBrainz_API#Linked_entities
523
- */
524
- export interface IBrowseEventsQuery extends IPagination {
525
- area?: string;
526
- artist?: string;
527
- collection?: string;
528
- place?: string;
529
- }
530
-
531
- /**
532
- * Browse instruments query <entity>: <MBID>
533
- * https://wiki.musicbrainz.org/MusicBrainz_API#Linked_entities
534
- */
535
- export interface IBrowseInstrumentsQuery extends IPagination {
536
- collection?: string;
537
- }
538
-
539
- /**
540
- * Browse labels query <entity>: <MBID>
541
- * https://wiki.musicbrainz.org/MusicBrainz_API#Linked_entities
542
- */
543
- export interface IBrowseLabelsQuery extends IPagination {
544
- area?: string;
545
- collection?: string;
546
- release?: string;
547
- }
548
-
549
- /**
550
- * Browse places query <entity>: <MBID>
551
- * https://wiki.musicbrainz.org/MusicBrainz_API#Linked_entities
552
- */
553
- export interface IBrowsePlacesQuery extends IPagination {
554
- area?: string;
555
- collection?: string;
556
- }
557
- /**
558
- * Browse recordings query <entity>: <MBID>
559
- * https://wiki.musicbrainz.org/MusicBrainz_API#Linked_entities
560
- */
561
- export interface IBrowseRecordingsQuery extends IPagination {
562
- artist?: string;
563
- collection?: string;
564
- release?: string;
565
- work?: string;
566
- }
567
-
568
- /**
569
- * Browse releases query <entity>: <MBID>
570
- * https://wiki.musicbrainz.org/MusicBrainz_API#Linked_entities
571
- */
572
- export interface IBrowseReleasesQuery extends IPagination {
573
- area?: string;
574
- artist?: string;
575
- editor?: string;
576
- event?: string;
577
- label?: string;
578
- place?: string;
579
- recording?: string;
580
- release?: string;
581
- 'release-group'?: string;
582
- work?: string;
583
- }
584
-
585
- /**
586
- * Browse release-groups query <entity>: <MBID>
587
- */
588
- export interface IReleaseGroupsQuery extends IPagination {
589
- artist?: string;
590
- collection?: string;
591
- release?: string;
592
- }
593
-
594
- /**
595
- * Browse release query <entity>: <MBID>
596
- * https://wiki.musicbrainz.org/MusicBrainz_API#Linked_entities
597
- */
598
- export interface IBrowseSeriesQuery extends IPagination {
599
- collection?: string;
600
- }
601
-
602
- /**
603
- * Browse urls query <entity>: <MBID>
604
- * https://wiki.musicbrainz.org/MusicBrainz_API#Linked_entities
605
- */
606
- export interface IBrowseUrlsQuery extends IPagination {
607
- resource?: string;
608
- }
609
-
610
- /**
611
- * Browse works query <entity>: <MBID>
612
- * https://wiki.musicbrainz.org/MusicBrainz_API#Linked_entities
613
- */
614
- export interface IBrowseWorksQuery extends IPagination {
615
- artist?: string;
616
- collection?: string;
617
- }
618
-
619
- export interface IBrowseAreasResult {
620
- area: IArea;
621
- 'area-count': number;
622
- 'area-offset': number;
623
- }
624
-
625
- export interface IBrowseArtistsResult {
626
- artists: IArtist[];
627
- 'artist-count': number;
628
- 'artist-offset': number;
629
- }
630
-
631
- export interface IBrowseCollectionsResult {
632
- collections: ICollection[];
633
- 'collection-count': number;
634
- 'collection-offset': number;
635
- }
636
-
637
- export interface IBrowseEventsResult {
638
- events: IEvent[];
639
- 'event-count': number;
640
- 'event-offset': number;
641
- }
642
-
643
- export interface IBrowseInstrumentsResult {
644
- instruments: IInstrument[];
645
- 'instrument-count': number;
646
- 'instrument-offset': number;
647
- }
648
-
649
- export interface IBrowseLabelsResult {
650
- label: ILabel[];
651
- 'label-count': number;
652
- 'label-offset': number;
653
- }
654
-
655
- export interface IBrowsePlacesResult {
656
- place: IPlace[];
657
- 'place-count': number;
658
- 'place-offset': number;
659
- }
660
-
661
- export interface IBrowseRecordingsResult {
662
- recording: IRecording[];
663
- 'recording-count': number;
664
- 'recording-offset': number;
665
- }
666
-
667
- export interface IBrowseReleasesResult {
668
- releases: IRelease[];
669
- 'release-count': number;
670
- 'release-offset': number;
671
- }
672
-
673
- export interface IBrowseReleaseGroupsResult {
674
- 'release-groups': IReleaseGroup[];
675
- 'release-group-count': number;
676
- 'release-group-offset': number;
677
- }
678
-
679
- export interface IBrowseSeriesResult {
680
- series: IReleaseGroupsQuery[];
681
- 'series-count': number;
682
- 'series-offset': number;
683
- }
684
-
685
- export interface IBrowseWorksResult {
686
- works: IReleaseGroupsQuery[];
687
- 'work-count': number;
688
- 'work-offset': number;
689
- }
@@ -1,34 +0,0 @@
1
- import * as Debug from 'debug';
2
-
3
- const debug = Debug('musicbrainz-api:rate-limiter');
4
-
5
- export class RateLimiter {
6
-
7
- public static sleep(ms): Promise<void> {
8
- return new Promise(resolve => setTimeout(resolve, ms));
9
- }
10
-
11
- public queue: number[] = [];
12
- private readonly period: number;
13
-
14
- public constructor(period: number, private maxCalls: number) {
15
- this.period = 1000 * period;
16
- }
17
-
18
- public async limit(): Promise<void> {
19
- let now = new Date().getTime();
20
- const t0 = now - (this.period);
21
- while (this.queue.length > 0 && this.queue[0] < t0) {
22
- this.queue.shift();
23
- }
24
- if (this.queue.length >= this.maxCalls) {
25
- const delay = this.queue[0] + this.period - now;
26
- debug(`Client side rate limiter activated: cool down for ${delay / 1000} s...`);
27
- return RateLimiter.sleep(delay);
28
- }
29
- now = new Date().getTime();
30
- this.queue.push(now);
31
- // const ratePerSec = 1000 * this.queue.length / (now - this.queue[0]);
32
- }
33
-
34
- }