music-routes-data 6.0.2 → 6.0.4

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/bin/mrd CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const cli = require('../lib/cli')
4
- const argv = require('minimist')(process.argv.slice(2))
3
+ const cli = require("../lib/cli");
4
+ const argv = require("minimist")(process.argv.slice(2));
5
5
 
6
- cli.argv(argv)
6
+ cli.argv(argv);
package/bin/verify CHANGED
@@ -1,61 +1,94 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const assert = require('assert')
4
- const path = require('path')
5
- const Data = require('../lib/Data')
3
+ const assert = require("assert");
4
+ const path = require("path");
5
+ const Data = require("../lib/Data");
6
6
 
7
- const data = new Data()
7
+ const data = new Data();
8
8
 
9
- const rv = data.read(path.join(__dirname, '/../data'))
9
+ const rv = data.read(path.join(__dirname, "/../data"));
10
10
  if (rv.status === data.StatusEnum.ERROR) {
11
- console.error(rv.message || 'Unknown error')
12
- process.exit(1)
11
+ console.error(rv.message || "Unknown error");
12
+ process.exit(1);
13
13
  }
14
14
 
15
- const dump = {} // local copy of all collections
15
+ const dump = {}; // local copy of all collections
16
16
 
17
- const collections = ['tracks', 'individuals', 'individual_track']
17
+ const collections = ["tracks", "individuals", "individual_track"];
18
18
 
19
19
  collections.forEach(function (collection) {
20
- const rv = data.search({ collection })
21
- assert.ok(rv.status === data.StatusEnum.OK, 'Could not retrieve contents of collection ' + collection)
22
- assert.ok(rv.results.length > 0, 'Collection ' + collection + ' has no entries')
23
- dump[collection] = rv.results
24
- })
20
+ const rv = data.search({ collection });
21
+ assert.ok(
22
+ rv.status === data.StatusEnum.OK,
23
+ "Could not retrieve contents of collection " + collection,
24
+ );
25
+ assert.ok(
26
+ rv.results.length > 0,
27
+ "Collection " + collection + " has no entries",
28
+ );
29
+ dump[collection] = rv.results;
30
+ });
25
31
 
26
32
  const getSet = function (collectionName, options = {}) {
27
- const idName = options.idName || '_id'
28
- const ignoreDuplicates = options.ignoreDuplicates || false
29
- const myArray = dump[collectionName].map((item) => item[idName])
30
- const mySet = new Set(myArray)
33
+ const idName = options.idName || "_id";
34
+ const ignoreDuplicates = options.ignoreDuplicates || false;
35
+ const myArray = dump[collectionName].map((item) => item[idName]);
36
+ const mySet = new Set(myArray);
31
37
  if (!ignoreDuplicates) {
32
- assert.strictEqual(mySet.size, myArray.length, `Duplicate IDs found in ${collectionName} collection`)
38
+ assert.strictEqual(
39
+ mySet.size,
40
+ myArray.length,
41
+ `Duplicate IDs found in ${collectionName} collection`,
42
+ );
33
43
  }
34
- return mySet
35
- }
44
+ return mySet;
45
+ };
36
46
 
37
47
  const compare = function (a, b, nameA, nameB) {
38
- const diff = a.symmetricDifference(b)
39
- assert.strictEqual(diff.size, 0, `The ${nameA} and ${nameB} collections have different IDs: ${Array.from(diff).join(', ')}`)
40
- }
48
+ const diff = a.symmetricDifference(b);
49
+ assert.strictEqual(
50
+ diff.size,
51
+ 0,
52
+ `The ${nameA} and ${nameB} collections have different IDs: ${Array.from(diff).join(", ")}`,
53
+ );
54
+ };
41
55
 
42
- const trackIds = getSet('tracks')
43
- const individualIds = getSet('individuals')
56
+ const trackIds = getSet("tracks");
57
+ const individualIds = getSet("individuals");
44
58
 
45
59
  // All IDs are strings but must not contain colons or slashes because the visualizer
46
60
  // uses IDs as directory names.
47
61
  const validateIds = (idsSet) => {
48
- assert.ok(idsSet.values().every((id) => typeof id === 'string' && !id.includes(':') && !id.includes('/')), 'Invalid ID found')
49
- }
50
- validateIds(trackIds)
51
- validateIds(individualIds)
62
+ assert.ok(
63
+ idsSet
64
+ .values()
65
+ .every(
66
+ (id) =>
67
+ typeof id === "string" && !id.includes(":") && !id.includes("/"),
68
+ ),
69
+ "Invalid ID found",
70
+ );
71
+ };
72
+ validateIds(trackIds);
73
+ validateIds(individualIds);
52
74
 
53
75
  const individualTrackIds = {
54
- individual: getSet('individual_track', { idName: 'individual_id', ignoreDuplicates: true }),
55
- track: getSet('individual_track', { idName: 'track_id', ignoreDuplicates: true })
56
- }
57
- compare(individualTrackIds.individual, individualIds, 'individual_track', 'individual_id')
58
- compare(individualTrackIds.track, trackIds, 'individual_track', 'track_id')
76
+ individual: getSet("individual_track", {
77
+ idName: "individual_id",
78
+ ignoreDuplicates: true,
79
+ }),
80
+ track: getSet("individual_track", {
81
+ idName: "track_id",
82
+ ignoreDuplicates: true,
83
+ }),
84
+ };
85
+ compare(
86
+ individualTrackIds.individual,
87
+ individualIds,
88
+ "individual_track",
89
+ "individual_id",
90
+ );
91
+ compare(individualTrackIds.track, trackIds, "individual_track", "track_id");
59
92
 
60
93
  // TODO: Make sure that there are no duplicate link entries (Elvis on "Love Me Tender" exists twice should be an error)
61
94
  // TODO: Check that all fields that should be strings are strings and all fields that should be arrays of strings are arrays of strings
@@ -258625,5 +258625,191 @@
258625
258625
  "credits": [
258626
258626
  "vocals"
258627
258627
  ]
258628
+ },
258629
+ {
258630
+ "individual_id": "Kev Choice",
258631
+ "track_id": "13533",
258632
+ "credits": [
258633
+ "piano",
258634
+ "keyboards",
258635
+ "synthesizer"
258636
+ ]
258637
+ },
258638
+ {
258639
+ "individual_id": "Dame Drummer",
258640
+ "track_id": "13533",
258641
+ "credits": [
258642
+ "drums"
258643
+ ]
258644
+ },
258645
+ {
258646
+ "individual_id": "Uriah Duffy",
258647
+ "track_id": "13533",
258648
+ "credits": [
258649
+ "bass"
258650
+ ]
258651
+ },
258652
+ {
258653
+ "individual_id": "Andrew Levin",
258654
+ "track_id": "13533",
258655
+ "credits": [
258656
+ "guitar"
258657
+ ]
258658
+ },
258659
+ {
258660
+ "individual_id": "Manny Martinez",
258661
+ "track_id": "13534",
258662
+ "credits": [
258663
+ "lead vocals",
258664
+ "maracas",
258665
+ "backing vocals"
258666
+ ]
258667
+ },
258668
+ {
258669
+ "individual_id": "Louie Romero",
258670
+ "track_id": "13534",
258671
+ "credits": [
258672
+ "timbales",
258673
+ "bongos"
258674
+ ]
258675
+ },
258676
+ {
258677
+ "individual_id": "Marco Diaz",
258678
+ "track_id": "13534",
258679
+ "credits": [
258680
+ "piano",
258681
+ "trumpet"
258682
+ ]
258683
+ },
258684
+ {
258685
+ "individual_id": "Ayla Dávila",
258686
+ "track_id": "13534",
258687
+ "credits": [
258688
+ "bass"
258689
+ ]
258690
+ },
258691
+ {
258692
+ "individual_id": "Ahkeel Mestayer",
258693
+ "track_id": "13534",
258694
+ "credits": [
258695
+ "congas"
258696
+ ]
258697
+ },
258698
+ {
258699
+ "individual_id": "Marty Wehner",
258700
+ "track_id": "13534",
258701
+ "credits": [
258702
+ "trombone"
258703
+ ]
258704
+ },
258705
+ {
258706
+ "individual_id": "Carlos Caro",
258707
+ "track_id": "13534",
258708
+ "credits": [
258709
+ "güiro"
258710
+ ]
258711
+ },
258712
+ {
258713
+ "individual_id": "Juan Perez",
258714
+ "track_id": "13534",
258715
+ "credits": [
258716
+ "backing vocals"
258717
+ ]
258718
+ },
258719
+ {
258720
+ "individual_id": "Don Cherry",
258721
+ "track_id": "13535"
258722
+ },
258723
+ {
258724
+ "individual_id": "Michael Mantler",
258725
+ "track_id": "13535",
258726
+ "credits": [
258727
+ "trumpet"
258728
+ ]
258729
+ },
258730
+ {
258731
+ "individual_id": "Roswell Rudd",
258732
+ "track_id": "13535",
258733
+ "credits": [
258734
+ "trombone"
258735
+ ]
258736
+ },
258737
+ {
258738
+ "individual_id": "Bob Northern",
258739
+ "track_id": "13535"
258740
+ },
258741
+ {
258742
+ "individual_id": "Howard Johnson",
258743
+ "track_id": "13535",
258744
+ "credits": [
258745
+ "tuba"
258746
+ ]
258747
+ },
258748
+ {
258749
+ "individual_id": "Perry Robinson",
258750
+ "track_id": "13535",
258751
+ "credits": [
258752
+ "clarinet"
258753
+ ]
258754
+ },
258755
+ {
258756
+ "individual_id": "Dewey Redman",
258757
+ "track_id": "13535"
258758
+ },
258759
+ {
258760
+ "individual_id": "Gato Barbieri",
258761
+ "track_id": "13535"
258762
+ },
258763
+ {
258764
+ "individual_id": "Carla Bley",
258765
+ "track_id": "13535"
258766
+ },
258767
+ {
258768
+ "individual_id": "Sam Brown (American jazz guitarist)",
258769
+ "track_id": "13535"
258770
+ },
258771
+ {
258772
+ "individual_id": "Charlie Haden",
258773
+ "track_id": "13535",
258774
+ "credits": [
258775
+ "bass"
258776
+ ]
258777
+ },
258778
+ {
258779
+ "individual_id": "Paul Motian",
258780
+ "track_id": "13535",
258781
+ "credits": [
258782
+ "percussion"
258783
+ ]
258784
+ },
258785
+ {
258786
+ "individual_id": "Stephen Pride",
258787
+ "track_id": "13536",
258788
+ "credits": [
258789
+ "guitar",
258790
+ "pedal steel guitar",
258791
+ "lead vocals"
258792
+ ]
258793
+ },
258794
+ {
258795
+ "individual_id": "Conor Thompson",
258796
+ "track_id": "13536",
258797
+ "credits": [
258798
+ "bass"
258799
+ ]
258800
+ },
258801
+ {
258802
+ "individual_id": "Cory Snavely",
258803
+ "track_id": "13536",
258804
+ "credits": [
258805
+ "drums"
258806
+ ]
258807
+ },
258808
+ {
258809
+ "individual_id": "Josh Wirtschafter",
258810
+ "track_id": "13536",
258811
+ "credits": [
258812
+ "violin"
258813
+ ]
258628
258814
  }
258629
258815
  ]
@@ -63190,5 +63190,96 @@
63190
63190
  "ZZ Ward",
63191
63191
  "Zsuzsanna Ward"
63192
63192
  ]
63193
+ },
63194
+ {
63195
+ "_id": "Kev Choice",
63196
+ "names": [
63197
+ "Kev Choice"
63198
+ ]
63199
+ },
63200
+ {
63201
+ "_id": "Dame Drummer",
63202
+ "names": [
63203
+ "Dame Drummer"
63204
+ ]
63205
+ },
63206
+ {
63207
+ "_id": "Manny Martinez",
63208
+ "names": [
63209
+ "Manny Martinez"
63210
+ ]
63211
+ },
63212
+ {
63213
+ "_id": "Louie Romero",
63214
+ "names": [
63215
+ "Louie Romero"
63216
+ ]
63217
+ },
63218
+ {
63219
+ "_id": "Marco Diaz",
63220
+ "names": [
63221
+ "Marco Diaz"
63222
+ ]
63223
+ },
63224
+ {
63225
+ "_id": "Ayla Dávila",
63226
+ "names": [
63227
+ "Ayla Dávila"
63228
+ ]
63229
+ },
63230
+ {
63231
+ "_id": "Ahkeel Mestayer",
63232
+ "names": [
63233
+ "Ahkeel Mestayer"
63234
+ ]
63235
+ },
63236
+ {
63237
+ "_id": "Carlos Caro",
63238
+ "names": [
63239
+ "Carlos Caro"
63240
+ ]
63241
+ },
63242
+ {
63243
+ "_id": "Juan Perez",
63244
+ "names": [
63245
+ "Juan Perez"
63246
+ ]
63247
+ },
63248
+ {
63249
+ "_id": "Michael Mantler",
63250
+ "names": [
63251
+ "Michael Mantler",
63252
+ "Mike Mantler"
63253
+ ]
63254
+ },
63255
+ {
63256
+ "_id": "Roswell Rudd",
63257
+ "names": [
63258
+ "Roswell Rudd"
63259
+ ]
63260
+ },
63261
+ {
63262
+ "_id": "Perry Robinson",
63263
+ "names": [
63264
+ "Perry Robinson"
63265
+ ]
63266
+ },
63267
+ {
63268
+ "_id": "Dewey Redman",
63269
+ "names": [
63270
+ "Dewey Redman"
63271
+ ]
63272
+ },
63273
+ {
63274
+ "_id": "Paul Motian",
63275
+ "names": [
63276
+ "Paul Motian"
63277
+ ]
63278
+ },
63279
+ {
63280
+ "_id": "Josh Wirtschafter",
63281
+ "names": [
63282
+ "Josh Wirtschafter"
63283
+ ]
63193
63284
  }
63194
63285
  ]
package/data/tracks.json CHANGED
@@ -270339,5 +270339,85 @@
270339
270339
  ]
270340
270340
  }
270341
270341
  ]
270342
+ },
270343
+ {
270344
+ "_id": "13533",
270345
+ "names": [
270346
+ "Hero's Theme"
270347
+ ],
270348
+ "artists": [
270349
+ {
270350
+ "names": [
270351
+ "Kev Choice"
270352
+ ]
270353
+ }
270354
+ ],
270355
+ "releases": [
270356
+ {
270357
+ "names": [
270358
+ "88 Steps To Eternity"
270359
+ ]
270360
+ }
270361
+ ]
270362
+ },
270363
+ {
270364
+ "_id": "13534",
270365
+ "names": [
270366
+ "Tú y Yo (I Love You)"
270367
+ ],
270368
+ "artists": [
270369
+ {
270370
+ "names": [
270371
+ "Manny Martinez Y Su Nuevo Azabache"
270372
+ ]
270373
+ }
270374
+ ],
270375
+ "releases": [
270376
+ {
270377
+ "names": [
270378
+ "Evolution"
270379
+ ]
270380
+ }
270381
+ ]
270382
+ },
270383
+ {
270384
+ "_id": "13535",
270385
+ "names": [
270386
+ "Song for Che"
270387
+ ],
270388
+ "artists": [
270389
+ {
270390
+ "names": [
270391
+ "Charlie Haden"
270392
+ ]
270393
+ }
270394
+ ],
270395
+ "releases": [
270396
+ {
270397
+ "names": [
270398
+ "Liberation Music Orchestra"
270399
+ ]
270400
+ }
270401
+ ]
270402
+ },
270403
+ {
270404
+ "_id": "13536",
270405
+ "names": [
270406
+ "It's Nice to Be Needed (But Not Needed too Much)"
270407
+ ],
270408
+ "artists": [
270409
+ {
270410
+ "names": [
270411
+ "Collisionville"
270412
+ ]
270413
+ }
270414
+ ],
270415
+ "releases": [
270416
+ {
270417
+ "names": [
270418
+ "Stones, Keys, Flat Ninths, & Salvage"
270419
+ ]
270420
+ }
270421
+ ]
270342
270422
  }
270343
270423
  ]
package/lib/Data/index.js CHANGED
@@ -1,157 +1,201 @@
1
- const fs = require('fs')
2
- const validateTrack = require('./validate-track')
1
+ const fs = require("fs");
2
+ const validateTrack = require("./validate-track");
3
3
 
4
- function Data (options) {
5
- const data = {}
4
+ function Data() {
5
+ const data = {};
6
6
  const collectionFields = {
7
- tracks: ['names'],
8
- individuals: ['names']
9
- }
7
+ tracks: ["names"],
8
+ individuals: ["names"],
9
+ };
10
10
 
11
11
  const linkCollectionFields = {
12
- individual_track: []
13
- }
12
+ individual_track: [],
13
+ };
14
14
 
15
- this.dataCollections = Object.freeze(Object.keys(collectionFields))
16
- this.linkCollections = Object.freeze(Object.keys(linkCollectionFields))
15
+ this.dataCollections = Object.freeze(Object.keys(collectionFields));
16
+ this.linkCollections = Object.freeze(Object.keys(linkCollectionFields));
17
17
 
18
- const collections = this.dataCollections.concat(this.linkCollections)
18
+ const collections = this.dataCollections.concat(this.linkCollections);
19
19
  collections.forEach(function (value) {
20
- data[value] = []
21
- })
20
+ data[value] = [];
21
+ });
22
22
 
23
23
  const makeReturnValue = function (status, message) {
24
- return { status, message }
25
- }
24
+ return { status, message };
25
+ };
26
26
 
27
- this.StatusEnum = Object.freeze({ OK: 0, ERROR: 1 })
27
+ this.StatusEnum = Object.freeze({ OK: 0, ERROR: 1 });
28
28
 
29
29
  this.search = function (options) {
30
- if (typeof options === 'undefined') {
31
- return makeReturnValue(this.StatusEnum.ERROR, 'options must be specified')
30
+ if (typeof options === "undefined") {
31
+ return makeReturnValue(
32
+ this.StatusEnum.ERROR,
33
+ "options must be specified",
34
+ );
32
35
  }
33
36
 
34
- const collection = options.collection
37
+ const collection = options.collection;
35
38
 
36
- if (typeof collection === 'undefined') {
37
- return makeReturnValue(this.StatusEnum.ERROR, 'collection is a required option.')
39
+ if (typeof collection === "undefined") {
40
+ return makeReturnValue(
41
+ this.StatusEnum.ERROR,
42
+ "collection is a required option.",
43
+ );
38
44
  }
39
45
 
40
46
  if (collections.indexOf(collection) === -1) {
41
- return makeReturnValue(this.StatusEnum.ERROR, 'collection ' + collection + ' does not exist.')
47
+ return makeReturnValue(
48
+ this.StatusEnum.ERROR,
49
+ "collection " + collection + " does not exist.",
50
+ );
42
51
  }
43
52
 
44
53
  // If no filterCallback sent, return everything
45
- const filterCallback = options.filterCallback || function (value) { return true }
46
-
47
- if (typeof filterCallback !== 'function') {
48
- return makeReturnValue(this.StatusEnum.ERROR, 'filterCallback must be a function, got ' + typeof filterCallback)
54
+ const filterCallback =
55
+ options.filterCallback ||
56
+ function () {
57
+ return true;
58
+ };
59
+
60
+ if (typeof filterCallback !== "function") {
61
+ return makeReturnValue(
62
+ this.StatusEnum.ERROR,
63
+ "filterCallback must be a function, got " + typeof filterCallback,
64
+ );
49
65
  }
50
66
 
51
- const results = data[collection].filter(filterCallback)
67
+ const results = data[collection].filter(filterCallback);
52
68
 
53
- const rv = makeReturnValue(this.StatusEnum.OK, '')
54
- rv.results = results
55
- return rv
56
- }
69
+ const rv = makeReturnValue(this.StatusEnum.OK, "");
70
+ rv.results = results;
71
+ return rv;
72
+ };
57
73
 
58
74
  this.create = function (collection, entry) {
59
- const newEntry = {}
60
- let isFieldMissing = false
75
+ const newEntry = {};
76
+ let isFieldMissing = false;
61
77
 
62
78
  if (this.dataCollections.indexOf(collection) === -1) {
63
- return makeReturnValue(this.StatusEnum.ERROR, 'Collection does not exist: ' + collection)
79
+ return makeReturnValue(
80
+ this.StatusEnum.ERROR,
81
+ "Collection does not exist: " + collection,
82
+ );
64
83
  }
65
84
 
66
85
  if (!entry._id) {
67
- entry._id = entry.names?.[0]
86
+ entry._id = entry.names?.[0];
68
87
  }
69
88
 
70
- if (typeof entry._id !== 'string') {
71
- return makeReturnValue(this.StatusEnum.ERROR, '_id must be a string, got ' + typeof entry._id)
89
+ if (typeof entry._id !== "string") {
90
+ return makeReturnValue(
91
+ this.StatusEnum.ERROR,
92
+ "_id must be a string, got " + typeof entry._id,
93
+ );
72
94
  }
73
95
 
74
96
  // Check if _id already exists. It should not.
75
- if (data[collection].filter(function (value) { return value._id === entry._id }).length > 0) {
76
- return makeReturnValue(this.StatusEnum.ERROR, '_id ' + entry._id + ' already exists')
97
+ if (
98
+ data[collection].filter(function (value) {
99
+ return value._id === entry._id;
100
+ }).length > 0
101
+ ) {
102
+ return makeReturnValue(
103
+ this.StatusEnum.ERROR,
104
+ "_id " + entry._id + " already exists",
105
+ );
77
106
  }
78
107
 
79
- newEntry._id = entry._id
108
+ newEntry._id = entry._id;
80
109
 
81
110
  collectionFields[collection].forEach(function (field) {
82
111
  if (!entry[field]) {
83
- isFieldMissing = true
84
- return
112
+ isFieldMissing = true;
113
+ return;
85
114
  }
86
115
 
87
116
  if (!(entry[field] instanceof Array)) {
88
- isFieldMissing = true
89
- return
117
+ isFieldMissing = true;
118
+ return;
90
119
  }
91
120
 
92
121
  // If some element in field array is not a string, reject the entry.
93
- if (entry[field].some(function (value) { return typeof value !== 'string' })) {
94
- isFieldMissing = true
95
- return
122
+ if (
123
+ entry[field].some(function (value) {
124
+ return typeof value !== "string";
125
+ })
126
+ ) {
127
+ isFieldMissing = true;
128
+ return;
96
129
  }
97
130
 
98
- newEntry[field] = entry[field]
99
- })
131
+ newEntry[field] = entry[field];
132
+ });
100
133
 
101
134
  if (isFieldMissing) {
102
- return makeReturnValue(this.StatusEnum.ERROR, 'Required field is missing')
135
+ return makeReturnValue(
136
+ this.StatusEnum.ERROR,
137
+ "Required field is missing",
138
+ );
103
139
  }
104
140
 
105
- if (collection === 'tracks') {
141
+ if (collection === "tracks") {
106
142
  try {
107
- validateTrack(entry)
143
+ validateTrack(entry);
108
144
  } catch (error) {
109
- return makeReturnValue(this.StatusEnum.ERROR, error.message)
145
+ return makeReturnValue(this.StatusEnum.ERROR, error.message);
110
146
  }
111
- newEntry.artists = entry.artists
112
- newEntry.releases = entry.releases
147
+ newEntry.artists = entry.artists;
148
+ newEntry.releases = entry.releases;
113
149
  }
114
150
 
115
- data[collection].push(newEntry)
116
- return makeReturnValue(this.StatusEnum.OK, '')
117
- }
151
+ data[collection].push(newEntry);
152
+ return makeReturnValue(this.StatusEnum.OK, "");
153
+ };
118
154
 
119
155
  this.link = function (collection, entry) {
120
156
  // TODO: error checking for linkage that already exists
121
157
  // TODO: how to handle credits? separate command? handle it here? I guess real challenge is handling from the command line.
122
158
  if (this.linkCollections.indexOf(collection) === -1) {
123
- return makeReturnValue(this.StatusEnum.ERROR, 'Invalid link collection specified')
159
+ return makeReturnValue(
160
+ this.StatusEnum.ERROR,
161
+ "Invalid link collection specified",
162
+ );
124
163
  }
125
- data[collection].push(entry)
126
- return makeReturnValue(this.StatusEnum.OK, '')
127
- }
164
+ data[collection].push(entry);
165
+ return makeReturnValue(this.StatusEnum.OK, "");
166
+ };
128
167
 
129
168
  const fsOp = function (dir, callback) {
130
- if (!dir || typeof dir !== 'string') {
131
- return makeReturnValue(this.StatusEnum.ERROR, 'No directory specified')
169
+ if (!dir || typeof dir !== "string") {
170
+ return makeReturnValue(this.StatusEnum.ERROR, "No directory specified");
132
171
  }
133
172
 
134
173
  try {
135
- collections.forEach(callback)
174
+ collections.forEach(callback);
136
175
  } catch (e) {
137
- return makeReturnValue(this.StatusEnum.ERROR, e.message)
176
+ return makeReturnValue(this.StatusEnum.ERROR, e.message);
138
177
  }
139
- return makeReturnValue(this.StatusEnum.OK, '')
140
- }
178
+ return makeReturnValue(this.StatusEnum.OK, "");
179
+ };
141
180
 
142
181
  this.read = function (dir) {
143
182
  return fsOp.call(this, dir, function (collection) {
144
- data[collection] = JSON.parse(fs.readFileSync(dir + '/' + collection + '.json'))
145
- if (collection === 'tracks') data[collection].forEach(validateTrack)
146
- })
147
- }
183
+ data[collection] = JSON.parse(
184
+ fs.readFileSync(dir + "/" + collection + ".json"),
185
+ );
186
+ if (collection === "tracks") data[collection].forEach(validateTrack);
187
+ });
188
+ };
148
189
 
149
190
  this.write = function (dir) {
150
191
  return fsOp.call(this, dir, function (collection) {
151
- if (collection === 'tracks') data[collection].forEach(validateTrack)
152
- fs.writeFileSync(dir + '/' + collection + '.json', JSON.stringify(data[collection], null, 2))
153
- })
154
- }
192
+ if (collection === "tracks") data[collection].forEach(validateTrack);
193
+ fs.writeFileSync(
194
+ dir + "/" + collection + ".json",
195
+ JSON.stringify(data[collection], null, 2),
196
+ );
197
+ });
198
+ };
155
199
  }
156
200
 
157
- module.exports = Data
201
+ module.exports = Data;
@@ -1,14 +1,22 @@
1
- const assert = require('assert')
1
+ const assert = require("assert");
2
2
 
3
3
  module.exports = function (track) {
4
- for (const field of ['artists', 'releases']) {
5
- const entries = track[field]
6
- assert.ok(Array.isArray(entries) && entries.length > 0,
7
- `Track ${track._id}: ${field} must be a non-empty array`)
4
+ for (const field of ["artists", "releases"]) {
5
+ const entries = track[field];
6
+ assert.ok(
7
+ Array.isArray(entries) && entries.length > 0,
8
+ `Track ${track._id}: ${field} must be a non-empty array`,
9
+ );
8
10
  for (const entry of entries) {
9
- assert.ok(entry && Array.isArray(entry.names) && entry.names.length > 0 &&
10
- Array.from(entry.names).every(name => typeof name === 'string' && name.trim().length > 0),
11
- `Track ${track._id}: each ${field} entry must have a non-empty names array of non-empty strings`)
11
+ assert.ok(
12
+ entry &&
13
+ Array.isArray(entry.names) &&
14
+ entry.names.length > 0 &&
15
+ Array.from(entry.names).every(
16
+ (name) => typeof name === "string" && name.trim().length > 0,
17
+ ),
18
+ `Track ${track._id}: each ${field} entry must have a non-empty names array of non-empty strings`,
19
+ );
12
20
  }
13
21
  }
14
- }
22
+ };
package/lib/cli/add.js CHANGED
@@ -1,11 +1,15 @@
1
1
  module.exports = function (data, collection, names, metadata) {
2
- let entry = { names: [names] }
3
- if (collection === 'tracks') {
2
+ let entry = { names: [names] };
3
+ if (collection === "tracks") {
4
4
  try {
5
- entry = { ...JSON.parse(metadata), names: [names] }
5
+ entry = { ...JSON.parse(metadata), names: [names] };
6
6
  } catch {
7
- return { status: data.StatusEnum.ERROR, message: 'Tracks require JSON metadata containing artists and releases arrays' }
7
+ return {
8
+ status: data.StatusEnum.ERROR,
9
+ message:
10
+ "Tracks require JSON metadata containing artists and releases arrays",
11
+ };
8
12
  }
9
13
  }
10
- return data.create(collection, entry)
11
- }
14
+ return data.create(collection, entry);
15
+ };
package/lib/cli/argv.js CHANGED
@@ -1,71 +1,76 @@
1
- const fs = require('fs')
2
- const path = require('path')
3
- const Data = require('../Data')
4
- const add = require('./add')
5
- const search = require('./search')
6
- const link = require('./link')
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const Data = require("../Data");
4
+ const add = require("./add");
5
+ const search = require("./search");
6
+ const link = require("./link");
7
7
 
8
8
  module.exports = function (argv) {
9
- const that = this
10
- const action = argv._[0]
11
- const args = argv._.splice(1)
12
- let rv = {}
13
- let inputRv
9
+ const that = this;
10
+ const action = argv._[0];
11
+ const args = argv._.splice(1);
12
+ let rv = {};
13
+ let inputRv;
14
14
 
15
- const defaultDir = path.join(__dirname, '../../data')
16
- const outputDir = argv.outputDir || argv.o || defaultDir
17
- const inputDir = argv.inputDir || argv.i || defaultDir
15
+ const defaultDir = path.join(__dirname, "../../data");
16
+ const outputDir = argv.outputDir || argv.o || defaultDir;
17
+ const inputDir = argv.inputDir || argv.i || defaultDir;
18
18
 
19
- const data = new Data()
19
+ const data = new Data();
20
20
 
21
21
  const save = function () {
22
22
  if (rv.status === data.StatusEnum.OK) {
23
23
  if (outputDir) {
24
- data.write(outputDir)
24
+ data.write(outputDir);
25
25
  }
26
26
  }
27
- }
27
+ };
28
28
 
29
29
  const run = function (actionFunction) {
30
- const actionRv = actionFunction.apply(undefined, [data].concat(args))
30
+ const actionRv = actionFunction.apply(undefined, [data].concat(args));
31
31
  if (actionRv.message) {
32
- that.error(actionRv.message)
32
+ that.error(actionRv.message);
33
33
  }
34
- return actionRv
35
- }
34
+ return actionRv;
35
+ };
36
36
 
37
37
  if (inputDir) {
38
- inputRv = data.read(inputDir)
38
+ inputRv = data.read(inputDir);
39
39
  if (inputRv.message) {
40
- this.error(inputRv.message)
40
+ this.error(inputRv.message);
41
41
  }
42
42
  if (inputRv.status === data.StatusEnum.ERROR) {
43
- this.exit(1)
43
+ this.exit(1);
44
44
  }
45
45
  }
46
46
 
47
47
  switch (action) {
48
- case 'add':
49
- rv = run(add)
50
- save()
51
- break
48
+ case "add":
49
+ rv = run(add);
50
+ save();
51
+ break;
52
52
 
53
- case 'link':
54
- rv = run(link)
55
- save()
56
- break
53
+ case "link":
54
+ rv = run(link);
55
+ save();
56
+ break;
57
57
 
58
- case 'search':
59
- rv = run(search)
58
+ case "search":
59
+ rv = run(search);
60
60
  if (rv.status === data.StatusEnum.OK) {
61
- this.dir(rv.results)
61
+ this.dir(rv.results);
62
62
  }
63
- break
63
+ break;
64
64
 
65
65
  default:
66
- this.error(fs.readFileSync(path.join(__dirname, '..', '..', 'doc', 'cli', 'help.txt'), 'utf8'))
67
- rv = { status: data.StatusEnum.ERROR }
66
+ this.error(
67
+ fs.readFileSync(
68
+ path.join(__dirname, "..", "..", "doc", "cli", "help.txt"),
69
+ "utf8",
70
+ ),
71
+ );
72
+ rv = { status: data.StatusEnum.ERROR };
68
73
  }
69
- const code = rv.status === data.StatusEnum.OK ? 0 : 1
70
- this.exit(code)
71
- }
74
+ const code = rv.status === data.StatusEnum.OK ? 0 : 1;
75
+ this.exit(code);
76
+ };
package/lib/cli/index.js CHANGED
@@ -2,5 +2,5 @@ module.exports = {
2
2
  dir: console.dir,
3
3
  exit: process.exit,
4
4
  error: console.error,
5
- argv: require('./argv')
6
- }
5
+ argv: require("./argv"),
6
+ };
package/lib/cli/link.js CHANGED
@@ -1,18 +1,18 @@
1
1
  module.exports = function (data, collection1, id1, collection2, id2) {
2
- let linkCollection = collection1 + '_' + collection2
3
- const field1 = collection1 + '_id'
4
- const field2 = collection2 + '_id'
5
- const link = {}
6
- link[field1] = id1.toString()
7
- link[field2] = id2.toString()
2
+ let linkCollection = collection1 + "_" + collection2;
3
+ const field1 = collection1 + "_id";
4
+ const field2 = collection2 + "_id";
5
+ const link = {};
6
+ link[field1] = id1.toString();
7
+ link[field2] = id2.toString();
8
8
 
9
9
  if (data.linkCollections.indexOf(linkCollection) === -1) {
10
10
  // Allow the individual and track arguments in either order.
11
- linkCollection = collection2 + '_' + collection1
11
+ linkCollection = collection2 + "_" + collection1;
12
12
  if (data.linkCollections.indexOf(linkCollection) === -1) {
13
- const message = `${collection1} and ${collection2} cannot be linked`
14
- return { status: data.StatusEnum.ERROR, message }
13
+ const message = `${collection1} and ${collection2} cannot be linked`;
14
+ return { status: data.StatusEnum.ERROR, message };
15
15
  }
16
16
  }
17
- return data.link(linkCollection, link)
18
- }
17
+ return data.link(linkCollection, link);
18
+ };
package/lib/cli/search.js CHANGED
@@ -1,7 +1,7 @@
1
1
  module.exports = function (data, collection, searchTerm) {
2
2
  const filterCallback = function (value) {
3
- const names = value.names.map(name => name.toLowerCase())
4
- return names.indexOf(searchTerm.toLowerCase()) !== -1
5
- }
6
- return data.search({ collection, filterCallback })
7
- }
3
+ const names = value.names.map((name) => name.toLowerCase());
4
+ return names.indexOf(searchTerm.toLowerCase()) !== -1;
5
+ };
6
+ return data.search({ collection, filterCallback });
7
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "music-routes-data",
3
- "version": "6.0.2",
3
+ "version": "6.0.4",
4
4
  "description": "What musicians played on what tracks",
5
5
  "homepage": "https://github.com/Trott/music-routes-data",
6
6
  "files": [
@@ -11,7 +11,10 @@
11
11
  "README.md"
12
12
  ],
13
13
  "scripts": {
14
- "test": "standard '**/*.js' bin/* && c8 --100 jasmine spec/*.js && bin/verify"
14
+ "lint": "eslint .",
15
+ "format": "prettier --write --ignore-path .gitignore --parser babel \"**/*.js\" \"bin/*\"",
16
+ "format:check": "prettier --check --ignore-path .gitignore --parser babel \"**/*.js\" \"bin/*\"",
17
+ "test": "npm run lint && npm run format:check && c8 --100 jasmine spec/*.js && bin/verify"
15
18
  },
16
19
  "repository": {
17
20
  "type": "git",
@@ -29,12 +32,15 @@
29
32
  "Trott"
30
33
  ],
31
34
  "devDependencies": {
35
+ "@eslint/js": "^10.0.1",
32
36
  "@semantic-release/changelog": "^7.0.0",
33
37
  "@semantic-release/git": "^11.0.1",
34
38
  "c8": "12.0",
39
+ "eslint": "^10.14.0",
40
+ "globals": "^17.14.0",
35
41
  "jasmine": "7.0",
36
- "semantic-release": "^25.0.1",
37
- "standard": "^17.0.0"
42
+ "prettier": "^3.9.10",
43
+ "semantic-release": "^26.0.1"
38
44
  },
39
45
  "dependencies": {
40
46
  "minimist": "^1.2.7"