Compare commits

..

No commits in common. "b3e0e764e20d09f04df9046e9f7fb18084a3f50f" and "6c2081c14eb622ed7f04fa127f9dc3c5ff76b59a" have entirely different histories.

6 changed files with 263 additions and 268 deletions

View file

@ -27,18 +27,25 @@ const validateLocation = (loc, name = 'location') => {
} }
}; };
const loadEnrichedStationData = async (profile) => { const loadEnrichedStationData = (profile) => new Promise((resolve, reject) => {
const dbHafasStations = await import('db-hafas-stations'); import('db-hafas-stations').then(m => {
const items = {}; const items = {};
for await (const station of dbHafasStations.readFullStations()) { m.default.full()
.on('data', (station) => {
items[station.id] = station; items[station.id] = station;
items[station.name] = station; items[station.name] = station;
} })
.once('end', () => {
if (profile.DEBUG) { if (profile.DEBUG) {
console.log('Loaded station index.'); console.log('Loaded station index.');
} }
return items; resolve(items);
}; })
.once('error', (err) => {
reject(err);
});
});
});
const applyEnrichedStationData = async (ctx, shouldLoadEnrichedStationData) => { const applyEnrichedStationData = async (ctx, shouldLoadEnrichedStationData) => {
const {profile, common} = ctx; const {profile, common} = ctx;

17
package-lock.json generated
View file

@ -1,17 +1,17 @@
{ {
"name": "db-vendo-client", "name": "db-vendo-client",
"version": "6.7.0", "version": "6.6.2",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "db-vendo-client", "name": "db-vendo-client",
"version": "6.7.0", "version": "6.6.2",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"content-type": "^1.0.5", "content-type": "^1.0.5",
"cross-fetch": "^4.1.0", "cross-fetch": "^4.1.0",
"db-hafas-stations": "2.0.0", "db-hafas-stations": "^1.1.0",
"gps-distance": "0.0.4", "gps-distance": "0.0.4",
"https-proxy-agent": "^7.0.6", "https-proxy-agent": "^7.0.6",
"luxon": "^3.5.0", "luxon": "^3.5.0",
@ -3447,15 +3447,14 @@
} }
}, },
"node_modules/db-hafas-stations": { "node_modules/db-hafas-stations": {
"version": "2.0.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/db-hafas-stations/-/db-hafas-stations-2.0.0.tgz", "resolved": "https://registry.npmjs.org/db-hafas-stations/-/db-hafas-stations-1.1.0.tgz",
"integrity": "sha512-GjcqpZhs+HeOvc2dnAJs2Uy3/b8zRNlvTfLCvqFe9J2JYOlQVyuYCjjdsPBTOmJol42sPToPs71wr03kTMVJDw==", "integrity": "sha512-o6NhX3YExhdxd8IA1cfWf1px5nJTym/2hXcnnINgXjSCBmD4ujv/pCUcXZcj8ucozhk5koR2SBgdKhWJpM39pw==",
"dependencies": { "dependencies": {
"ndjson": "^2.0.0", "ndjson": "^2.0.0"
"qs": "^6.14.0"
}, },
"engines": { "engines": {
"node": ">=18" "node": ">=14"
} }
}, },
"node_modules/db-rest": { "node_modules/db-rest": {

View file

@ -1,7 +1,7 @@
{ {
"name": "db-vendo-client", "name": "db-vendo-client",
"description": "Client for bahn.de public transport APIs.", "description": "Client for bahn.de public transport APIs.",
"version": "6.7.0", "version": "6.6.2",
"type": "module", "type": "module",
"main": "index.js", "main": "index.js",
"files": [ "files": [
@ -60,7 +60,7 @@
"dependencies": { "dependencies": {
"content-type": "^1.0.5", "content-type": "^1.0.5",
"cross-fetch": "^4.1.0", "cross-fetch": "^4.1.0",
"db-hafas-stations": "2.0.0", "db-hafas-stations": "^1.1.0",
"gps-distance": "0.0.4", "gps-distance": "0.0.4",
"https-proxy-agent": "^7.0.6", "https-proxy-agent": "^7.0.6",
"luxon": "^3.5.0", "luxon": "^3.5.0",

View file

@ -78,14 +78,6 @@ const enrichStation = (ctx, stop, locations) => {
...stop, ...stop,
}; };
delete stop.lines; 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; return stop;
}; };

View file

@ -99,8 +99,7 @@ const potsdamHbf = '8012666';
const berlinSüdkreuz = '8011113'; const berlinSüdkreuz = '8011113';
const kölnHbf = '8000207'; const kölnHbf = '8000207';
if (!process.env.VCR_OFF) { tap.test('journeys  Berlin Schwedter Str. to München Hbf', async (t) => {
tap.test('journeys  Berlin Schwedter Str. to München Hbf', async (t) => {
const res = await client.journeys(blnSchwedterStr, münchenHbf, { const res = await client.journeys(blnSchwedterStr, münchenHbf, {
results: 4, results: 4,
departure: when, departure: when,
@ -124,9 +123,9 @@ if (!process.env.VCR_OFF) {
} }
} }
t.end(); t.end();
}); });
tap.test('refreshJourney valid tickets', async (t) => { tap.test('refreshJourney valid tickets', async (t) => {
const T_MOCK = 1710831600 * 1000; // 2024-03-19T08:00:00+01:00 const T_MOCK = 1710831600 * 1000; // 2024-03-19T08:00:00+01:00
const when = createWhen(dbProfile.timezone, dbProfile.locale, T_MOCK); const when = createWhen(dbProfile.timezone, dbProfile.locale, T_MOCK);
@ -148,11 +147,11 @@ if (!process.env.VCR_OFF) {
} }
t.end(); t.end();
}); });
// todo: journeys, only one product // todo: journeys, only one product
tap.test('journeys fails with no product', async (t) => { tap.test('journeys fails with no product', async (t) => {
await journeysFailsWithNoProduct({ await journeysFailsWithNoProduct({
test: t, test: t,
fetchJourneys: client.journeys, fetchJourneys: client.journeys,
@ -162,9 +161,9 @@ if (!process.env.VCR_OFF) {
products: dbProfile.products, products: dbProfile.products,
}); });
t.end(); t.end();
}); });
tap.test('Berlin Schwedter Str. to Torfstraße 17', async (t) => { tap.test('Berlin Schwedter Str. to Torfstraße 17', async (t) => {
const torfstr = { const torfstr = {
type: 'location', type: 'location',
address: 'Torfstraße 17', address: 'Torfstraße 17',
@ -184,9 +183,9 @@ if (!process.env.VCR_OFF) {
to: torfstr, to: torfstr,
}); });
t.end(); t.end();
}); });
tap.test('Berlin Schwedter Str. to ATZE Musiktheater', async (t) => { tap.test('Berlin Schwedter Str. to ATZE Musiktheater', async (t) => {
const atze = { const atze = {
type: 'location', type: 'location',
id: '991598902', id: '991598902',
@ -208,9 +207,9 @@ if (!process.env.VCR_OFF) {
to: atze, to: atze,
}); });
t.end(); t.end();
}); });
tap.test('journeys: via works with detour', async (t) => { tap.test('journeys: via works with detour', async (t) => {
// Going from Westhafen to Wedding via Württembergallee without detour // Going from Westhafen to Wedding via Württembergallee without detour
// is currently impossible. We check if the routing engine computes a detour. // is currently impossible. We check if the routing engine computes a detour.
const res = await client.journeys(westhafen, wedding, { const res = await client.journeys(westhafen, wedding, {
@ -227,11 +226,11 @@ if (!process.env.VCR_OFF) {
detourIds: [württembergallee], detourIds: [württembergallee],
}); });
t.end(); t.end();
}); });
// todo: walkingSpeed "Berlin - Charlottenburg, Hallerstraße" -> jungfernheide
// todo: without detour
// todo: walkingSpeed "Berlin - Charlottenburg, Hallerstraße" -> jungfernheide
// todo: without detour
}
// todo: with the DB endpoint, earlierRef/laterRef is missing queries many days in the future // todo: with the DB endpoint, earlierRef/laterRef is missing queries many days in the future
tap.skip('earlier/later journeys, Jungfernheide -> München Hbf', async (t) => { tap.skip('earlier/later journeys, Jungfernheide -> München Hbf', async (t) => {

View file

@ -151,8 +151,7 @@ tap.test('refreshJourney valid tickets', async (t) => {
// todo: journeys, only one product // todo: journeys, only one product
if (!process.env.VCR_OFF) { tap.test('journeys fails with no product', async (t) => {
tap.test('journeys fails with no product', async (t) => {
await journeysFailsWithNoProduct({ await journeysFailsWithNoProduct({
test: t, test: t,
fetchJourneys: client.journeys, fetchJourneys: client.journeys,
@ -162,9 +161,9 @@ if (!process.env.VCR_OFF) {
products: dbProfile.products, products: dbProfile.products,
}); });
t.end(); t.end();
}); });
tap.test('Berlin Schwedter Str. to Torfstraße 17', async (t) => { tap.test('Berlin Schwedter Str. to Torfstraße 17', async (t) => {
const torfstr = { const torfstr = {
type: 'location', type: 'location',
address: 'Torfstraße 17', address: 'Torfstraße 17',
@ -184,9 +183,9 @@ if (!process.env.VCR_OFF) {
to: torfstr, to: torfstr,
}); });
t.end(); t.end();
}); });
tap.test('Berlin Schwedter Str. to ATZE Musiktheater', async (t) => { tap.test('Berlin Schwedter Str. to ATZE Musiktheater', async (t) => {
const atze = { const atze = {
type: 'location', type: 'location',
id: '991598902', id: '991598902',
@ -208,9 +207,9 @@ if (!process.env.VCR_OFF) {
to: atze, to: atze,
}); });
t.end(); t.end();
}); });
tap.test('journeys: via works with detour', async (t) => { tap.test('journeys: via works with detour', async (t) => {
// Going from Westhafen to Wedding via Württembergallee without detour // Going from Westhafen to Wedding via Württembergallee without detour
// is currently impossible. We check if the routing engine computes a detour. // is currently impossible. We check if the routing engine computes a detour.
const res = await client.journeys(westhafen, wedding, { const res = await client.journeys(westhafen, wedding, {
@ -227,14 +226,14 @@ if (!process.env.VCR_OFF) {
detourIds: [württembergallee], detourIds: [württembergallee],
}); });
t.end(); t.end();
}); });
// todo: walkingSpeed "Berlin - Charlottenburg, Hallerstraße" -> jungfernheide // todo: walkingSpeed "Berlin - Charlottenburg, Hallerstraße" -> jungfernheide
// todo: without detour // todo: without detour
// todo: with the DB endpoint, earlierRef/laterRef is missing queries many days in the future // todo: with the DB endpoint, earlierRef/laterRef is missing queries many days in the future
tap.skip('earlier/later journeys, Jungfernheide -> München Hbf', async (t) => { tap.skip('earlier/later journeys, Jungfernheide -> München Hbf', async (t) => {
await testEarlierLaterJourneys({ await testEarlierLaterJourneys({
test: t, test: t,
fetchJourneys: client.journeys, fetchJourneys: client.journeys,
@ -245,9 +244,9 @@ if (!process.env.VCR_OFF) {
}); });
t.end(); t.end();
}); });
if (!process.env.VCR_MODE) { if (!process.env.VCR_MODE) {
tap.test('journeys leg cycle & alternatives', async (t) => { tap.test('journeys leg cycle & alternatives', async (t) => {
await testLegCycleAlternatives({ await testLegCycleAlternatives({
test: t, test: t,
@ -258,9 +257,9 @@ if (!process.env.VCR_OFF) {
}); });
t.end(); t.end();
}); });
} }
tap.test('refreshJourney', async (t) => { tap.test('refreshJourney', async (t) => {
const T_MOCK = 1710831600 * 1000; // 2024-03-19T08:00:00+01:00 const T_MOCK = 1710831600 * 1000; // 2024-03-19T08:00:00+01:00
const when = createWhen(dbProfile.timezone, dbProfile.locale, T_MOCK); const when = createWhen(dbProfile.timezone, dbProfile.locale, T_MOCK);
const validate = createValidate({...cfg, when}); const validate = createValidate({...cfg, when});
@ -275,8 +274,7 @@ if (!process.env.VCR_OFF) {
when, when,
}); });
t.end(); t.end();
}); });
}
/* /*
tap.skip('journeysFromTrip U Mehringdamm to U Naturkundemuseum, reroute to Spittelmarkt.', async (t) => { tap.skip('journeysFromTrip U Mehringdamm to U Naturkundemuseum, reroute to Spittelmarkt.', async (t) => {