diff --git a/index.js b/index.js index 1a1557a5..2ad93bea 100644 --- a/index.js +++ b/index.js @@ -27,25 +27,18 @@ const validateLocation = (loc, name = 'location') => { } }; -const loadEnrichedStationData = (profile) => new Promise((resolve, reject) => { - import('db-hafas-stations').then(m => { - const items = {}; - m.default.full() - .on('data', (station) => { - items[station.id] = station; - items[station.name] = station; - }) - .once('end', () => { - if (profile.DEBUG) { - console.log('Loaded station index.'); - } - resolve(items); - }) - .once('error', (err) => { - reject(err); - }); - }); -}); +const loadEnrichedStationData = async (profile) => { + const dbHafasStations = await import('db-hafas-stations'); + const items = {}; + for await (const station of dbHafasStations.readFullStations()) { + items[station.id] = station; + items[station.name] = station; + } + if (profile.DEBUG) { + console.log('Loaded station index.'); + } + return items; +}; const applyEnrichedStationData = async (ctx, shouldLoadEnrichedStationData) => { const {profile, common} = ctx; diff --git a/package-lock.json b/package-lock.json index ef2bbac7..71b3881d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,17 +1,17 @@ { "name": "db-vendo-client", - "version": "6.6.2", + "version": "6.7.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "db-vendo-client", - "version": "6.6.2", + "version": "6.7.0", "license": "ISC", "dependencies": { "content-type": "^1.0.5", "cross-fetch": "^4.1.0", - "db-hafas-stations": "^1.1.0", + "db-hafas-stations": "2.0.0", "gps-distance": "0.0.4", "https-proxy-agent": "^7.0.6", "luxon": "^3.5.0", @@ -3447,14 +3447,15 @@ } }, "node_modules/db-hafas-stations": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/db-hafas-stations/-/db-hafas-stations-1.1.0.tgz", - "integrity": "sha512-o6NhX3YExhdxd8IA1cfWf1px5nJTym/2hXcnnINgXjSCBmD4ujv/pCUcXZcj8ucozhk5koR2SBgdKhWJpM39pw==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/db-hafas-stations/-/db-hafas-stations-2.0.0.tgz", + "integrity": "sha512-GjcqpZhs+HeOvc2dnAJs2Uy3/b8zRNlvTfLCvqFe9J2JYOlQVyuYCjjdsPBTOmJol42sPToPs71wr03kTMVJDw==", "dependencies": { - "ndjson": "^2.0.0" + "ndjson": "^2.0.0", + "qs": "^6.14.0" }, "engines": { - "node": ">=14" + "node": ">=18" } }, "node_modules/db-rest": { diff --git a/package.json b/package.json index 2cda776e..44e7165c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "db-vendo-client", "description": "Client for bahn.de public transport APIs.", - "version": "6.6.2", + "version": "6.7.0", "type": "module", "main": "index.js", "files": [ @@ -60,7 +60,7 @@ "dependencies": { "content-type": "^1.0.5", "cross-fetch": "^4.1.0", - "db-hafas-stations": "^1.1.0", + "db-hafas-stations": "2.0.0", "gps-distance": "0.0.4", "https-proxy-agent": "^7.0.6", "luxon": "^3.5.0", diff --git a/parse/location.js b/parse/location.js index 66d8d702..cbb0da23 100644 --- a/parse/location.js +++ b/parse/location.js @@ -78,6 +78,14 @@ const enrichStation = (ctx, stop, locations) => { ...stop, }; delete stop.lines; + delete stop.facilities; + delete stop.reisezentrumOpeningHours; + if (stop.station) { + stop.station = {...stop.station}; + delete stop.station.lines; + delete stop.station.facilities; + delete stop.station.reisezentrumOpeningHours; + } } return stop; };