mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-06-19 10:42:33 +03:00
Compare commits
1 commit
6c8f50350b
...
1f49a52184
Author | SHA1 | Date | |
---|---|---|---|
|
1f49a52184 |
20 changed files with 1021 additions and 1476 deletions
7
debug.js
7
debug.js
|
@ -1,7 +0,0 @@
|
||||||
import {createClient} from './index.js';
|
|
||||||
import {profile} from './p/dbnav/index.js';
|
|
||||||
|
|
||||||
const client = createClient(profile, 'hafas-client-debug');
|
|
||||||
|
|
||||||
const journeys = await client.journeys('8000105', '8000261', {results: 1});
|
|
||||||
console.log(journeys);
|
|
35
index.js
35
index.js
|
@ -26,24 +26,23 @@ const validateLocation = (loc, name = 'location') => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadEnrichedStationData = (profile) => new Promise((resolve, reject) => {
|
const loadEnrichedStationData = (profile) => new Promise(async (resolve, reject) => {
|
||||||
import('db-hafas-stations').then(m => {
|
const { default: readStations} = await import('db-hafas-stations');
|
||||||
const items = {};
|
const items = {};
|
||||||
m.default.full()
|
readStations.full()
|
||||||
.on('data', (station) => {
|
.on('data', (station) => {
|
||||||
items[station.id] = station;
|
items[station.id] = station;
|
||||||
items[station.name] = station;
|
items[station.name] = station;
|
||||||
})
|
})
|
||||||
.once('end', () => {
|
.once('end', () => {
|
||||||
if (profile.DEBUG) {
|
if (profile.DEBUG) {
|
||||||
console.log('Loaded station index.');
|
console.log('Loaded station index.');
|
||||||
}
|
}
|
||||||
resolve(items);
|
resolve(items);
|
||||||
})
|
})
|
||||||
.once('error', (err) => {
|
.once('error', (err) => {
|
||||||
reject(err);
|
reject(err);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const applyEnrichedStationData = async (ctx, shouldLoadEnrichedStationData) => {
|
const applyEnrichedStationData = async (ctx, shouldLoadEnrichedStationData) => {
|
||||||
|
|
|
@ -37,7 +37,7 @@ import {formatTravellers} from '../format/travellers.js';
|
||||||
import {formatLoyaltyCard} from '../format/loyalty-cards.js';
|
import {formatLoyaltyCard} from '../format/loyalty-cards.js';
|
||||||
import {formatTransfers} from '../format/transfers.js';
|
import {formatTransfers} from '../format/transfers.js';
|
||||||
|
|
||||||
const DEBUG = (/(^|,)hafas-client(,|$)/).test(typeof process !== 'undefined' ? process.env.DEBUG || '' : '');
|
const DEBUG = (/(^|,)hafas-client(,|$)/).test((typeof process !== 'undefined') ? (process.env.DEBUG || '') : '');
|
||||||
const logRequest = DEBUG
|
const logRequest = DEBUG
|
||||||
? (_, req, reqId) => console.error(String(req.body))
|
? (_, req, reqId) => console.error(String(req.body))
|
||||||
: () => { };
|
: () => { };
|
||||||
|
|
|
@ -7,10 +7,9 @@ const randomBytesHex = (nBytes = 8) => {
|
||||||
const array = new Uint8Array(nBytes);
|
const array = new Uint8Array(nBytes);
|
||||||
crypto.getRandomValues(array);
|
crypto.getRandomValues(array);
|
||||||
return Array.from(array)
|
return Array.from(array)
|
||||||
.map((byte) => byte.toString(16)
|
.map((byte) => byte.toString(16).padStart(2, '0'))
|
||||||
.padStart(2, '0'))
|
.join('');
|
||||||
.join('');
|
};
|
||||||
};
|
|
||||||
|
|
||||||
const checkIfResponseIsOk = (_) => {
|
const checkIfResponseIsOk = (_) => {
|
||||||
const {
|
const {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import dbnavBase from '../dbnav/base.json' with { type: 'json' };
|
import dbnavBase from '../dbnav/base.json' with { type: "json" };
|
||||||
import dbregioguideBase from '../dbregioguide/base.json' with { type: 'json' };
|
import dbregioguideBase from '../dbregioguide/base.json' with { type: "json" };
|
||||||
import {products} from '../../lib/products.js';
|
import {products} from '../../lib/products.js';
|
||||||
|
|
||||||
// journeys()
|
// journeys()
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import baseProfile from './base.json' with { type: 'json' };
|
import baseProfile from './base.json' with { type: "json" };
|
||||||
import {products} from '../../lib/products.js';
|
import {products} from '../../lib/products.js';
|
||||||
import {formatJourneysReq, formatRefreshJourneyReq} from './journeys-req.js';
|
import {formatJourneysReq, formatRefreshJourneyReq} from './journeys-req.js';
|
||||||
import {formatTripReq} from './trip-req.js';
|
import {formatTripReq} from './trip-req.js';
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import baseProfile from './base.json' with { type: 'json' };
|
import baseProfile from './base.json' with { type: "json" };
|
||||||
import {products} from '../../lib/products.js';
|
import {products} from '../../lib/products.js';
|
||||||
import {formatTripReq} from './trip-req.js';
|
import {formatTripReq} from './trip-req.js';
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import baseProfile from './base.json' with { type: 'json' };
|
import baseProfile from './base.json' with { type: "json" };
|
||||||
import {products} from '../../lib/products.js';
|
import {products} from '../../lib/products.js';
|
||||||
import {formatJourneysReq, formatRefreshJourneyReq} from './journeys-req.js';
|
import {formatJourneysReq, formatRefreshJourneyReq} from './journeys-req.js';
|
||||||
import {formatLocationFilter} from './location-filter.js';
|
import {formatLocationFilter} from './location-filter.js';
|
||||||
|
|
2413
package-lock.json
generated
2413
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -68,15 +68,12 @@
|
||||||
"uuid": "^11.0.5"
|
"uuid": "^11.0.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/eslintrc": "^3.2.0",
|
|
||||||
"@eslint/js": "^9.20.0",
|
|
||||||
"@pollyjs/adapter-node-http": "^6.0.5",
|
"@pollyjs/adapter-node-http": "^6.0.5",
|
||||||
"@pollyjs/core": "^6.0.5",
|
"@pollyjs/core": "^6.0.5",
|
||||||
"@pollyjs/persister-fs": "^6.0.5",
|
"@pollyjs/persister-fs": "^6.0.5",
|
||||||
"@stylistic/eslint-plugin": "^3.1.0",
|
"@stylistic/eslint-plugin": "^3.1.0",
|
||||||
"db-rest": "github:derhuerst/db-rest",
|
"db-rest": "github:derhuerst/db-rest",
|
||||||
"eslint": "^9.20.1",
|
"eslint": "^9.20.1",
|
||||||
"globals": "^15.15.0",
|
|
||||||
"hafas-rest-api": "^5.1.3",
|
"hafas-rest-api": "^5.1.3",
|
||||||
"is-coordinates": "^2.0.2",
|
"is-coordinates": "^2.0.2",
|
||||||
"is-roughly-equal": "^0.1.0",
|
"is-roughly-equal": "^0.1.0",
|
||||||
|
|
|
@ -5,7 +5,7 @@ import tap from 'tap';
|
||||||
|
|
||||||
import {createClient} from '../index.js';
|
import {createClient} from '../index.js';
|
||||||
import {profile as rawProfile} from '../p/dbnav/index.js';
|
import {profile as rawProfile} from '../p/dbnav/index.js';
|
||||||
import res from './fixtures/dbnav-departures.json' with { type: 'json' };
|
import res from './fixtures/dbnav-departures.json' with { type: "json" };
|
||||||
import {dbnavDepartures as expected} from './fixtures/dbnav-departures.js';
|
import {dbnavDepartures as expected} from './fixtures/dbnav-departures.js';
|
||||||
|
|
||||||
const client = createClient(rawProfile, 'public-transport/hafas-client:test', {enrichStations: false});
|
const client = createClient(rawProfile, 'public-transport/hafas-client:test', {enrichStations: false});
|
||||||
|
|
|
@ -5,7 +5,7 @@ import tap from 'tap';
|
||||||
|
|
||||||
import {createClient} from '../index.js';
|
import {createClient} from '../index.js';
|
||||||
import {profile as rawProfile} from '../p/dbnav/index.js';
|
import {profile as rawProfile} from '../p/dbnav/index.js';
|
||||||
import res from './fixtures/dbnav-refresh-journey.json' with { type: 'json' };
|
import res from './fixtures/dbnav-refresh-journey.json' with { type: "json" };
|
||||||
import {dbNavJourney as expected} from './fixtures/dbnav-refresh-journey.js';
|
import {dbNavJourney as expected} from './fixtures/dbnav-refresh-journey.js';
|
||||||
|
|
||||||
const client = createClient(rawProfile, 'public-transport/hafas-client:test', {enrichStations: false});
|
const client = createClient(rawProfile, 'public-transport/hafas-client:test', {enrichStations: false});
|
||||||
|
|
|
@ -5,7 +5,7 @@ import tap from 'tap';
|
||||||
|
|
||||||
import {createClient} from '../index.js';
|
import {createClient} from '../index.js';
|
||||||
import {profile as rawProfile} from '../p/dbnav/index.js';
|
import {profile as rawProfile} from '../p/dbnav/index.js';
|
||||||
import res from './fixtures/dbnav-stop.json' with { type: 'json' };
|
import res from './fixtures/dbnav-stop.json' with { type: "json" };
|
||||||
import {dbnavDepartures as expected} from './fixtures/dbnav-stop.js';
|
import {dbnavDepartures as expected} from './fixtures/dbnav-stop.js';
|
||||||
|
|
||||||
const client = createClient(rawProfile, 'public-transport/hafas-client:test', {enrichStations: false});
|
const client = createClient(rawProfile, 'public-transport/hafas-client:test', {enrichStations: false});
|
||||||
|
|
|
@ -4,7 +4,7 @@ import tap from 'tap';
|
||||||
|
|
||||||
import {createClient} from '../index.js';
|
import {createClient} from '../index.js';
|
||||||
import {profile as rawProfile} from '../p/dbnav/index.js';
|
import {profile as rawProfile} from '../p/dbnav/index.js';
|
||||||
import res from './fixtures/dbnav-trip.json' with { type: 'json' };
|
import res from './fixtures/dbnav-trip.json' with { type: "json" };
|
||||||
import {dbTrip as expected} from './fixtures/dbnav-trip.js';
|
import {dbTrip as expected} from './fixtures/dbnav-trip.js';
|
||||||
|
|
||||||
const client = createClient(rawProfile, 'public-transport/hafas-client:test', {enrichStations: false});
|
const client = createClient(rawProfile, 'public-transport/hafas-client:test', {enrichStations: false});
|
||||||
|
|
|
@ -4,7 +4,7 @@ import tap from 'tap';
|
||||||
|
|
||||||
import {createClient} from '../index.js';
|
import {createClient} from '../index.js';
|
||||||
import {profile as rawProfile} from '../p/dbregioguide/index.js';
|
import {profile as rawProfile} from '../p/dbregioguide/index.js';
|
||||||
import res from './fixtures/dbregioguide-trip.json' with { type: 'json' };
|
import res from './fixtures/dbregioguide-trip.json' with { type: "json" };
|
||||||
import {dbTrip as expected} from './fixtures/dbregioguide-trip.js';
|
import {dbTrip as expected} from './fixtures/dbregioguide-trip.js';
|
||||||
|
|
||||||
const client = createClient(rawProfile, 'public-transport/hafas-client:test', {enrichStations: false});
|
const client = createClient(rawProfile, 'public-transport/hafas-client:test', {enrichStations: false});
|
||||||
|
|
|
@ -4,7 +4,7 @@ import tap from 'tap';
|
||||||
|
|
||||||
import {createClient} from '../index.js';
|
import {createClient} from '../index.js';
|
||||||
import {profile as rawProfile} from '../p/dbweb/index.js';
|
import {profile as rawProfile} from '../p/dbweb/index.js';
|
||||||
import res from './fixtures/dbris-arrivals.json' with { type: 'json' };
|
import res from './fixtures/dbris-arrivals.json' with { type: "json" };
|
||||||
import {dbArrivals as expected} from './fixtures/dbris-arrivals.js';
|
import {dbArrivals as expected} from './fixtures/dbris-arrivals.js';
|
||||||
|
|
||||||
const client = createClient(rawProfile, 'public-transport/hafas-client:test', {enrichStations: false});
|
const client = createClient(rawProfile, 'public-transport/hafas-client:test', {enrichStations: false});
|
||||||
|
|
|
@ -4,7 +4,7 @@ import tap from 'tap';
|
||||||
|
|
||||||
import {createClient} from '../index.js';
|
import {createClient} from '../index.js';
|
||||||
import {profile as rawProfile} from '../p/dbweb/index.js';
|
import {profile as rawProfile} from '../p/dbweb/index.js';
|
||||||
import res from './fixtures/dbweb-departures.json' with { type: 'json' };
|
import res from './fixtures/dbweb-departures.json' with { type: "json" };
|
||||||
import {dbwebDepartures as expected} from './fixtures/dbweb-departures.js';
|
import {dbwebDepartures as expected} from './fixtures/dbweb-departures.js';
|
||||||
|
|
||||||
const client = createClient(rawProfile, 'public-transport/hafas-client:test', {enrichStations: false});
|
const client = createClient(rawProfile, 'public-transport/hafas-client:test', {enrichStations: false});
|
||||||
|
|
|
@ -4,7 +4,7 @@ import tap from 'tap';
|
||||||
|
|
||||||
import {createClient} from '../index.js';
|
import {createClient} from '../index.js';
|
||||||
import {profile as rawProfile} from '../p/dbweb/index.js';
|
import {profile as rawProfile} from '../p/dbweb/index.js';
|
||||||
import res from './fixtures/dbweb-journey.json' with { type: 'json' };
|
import res from './fixtures/dbweb-journey.json' with { type: "json" };
|
||||||
import {dbwebJourney as expected} from './fixtures/dbweb-journey.js';
|
import {dbwebJourney as expected} from './fixtures/dbweb-journey.js';
|
||||||
|
|
||||||
const client = createClient(rawProfile, 'public-transport/hafas-client:test', {enrichStations: false});
|
const client = createClient(rawProfile, 'public-transport/hafas-client:test', {enrichStations: false});
|
||||||
|
|
|
@ -4,7 +4,7 @@ import tap from 'tap';
|
||||||
|
|
||||||
import {createClient} from '../index.js';
|
import {createClient} from '../index.js';
|
||||||
import {profile as rawProfile} from '../p/dbweb/index.js';
|
import {profile as rawProfile} from '../p/dbweb/index.js';
|
||||||
import res from './fixtures/dbweb-refresh-journey.json' with { type: 'json' };
|
import res from './fixtures/dbweb-refresh-journey.json' with { type: "json" };
|
||||||
import {dbJourney as expected} from './fixtures/dbweb-refresh-journey.js';
|
import {dbJourney as expected} from './fixtures/dbweb-refresh-journey.js';
|
||||||
|
|
||||||
const client = createClient(rawProfile, 'public-transport/hafas-client:test', {enrichStations: false});
|
const client = createClient(rawProfile, 'public-transport/hafas-client:test', {enrichStations: false});
|
||||||
|
|
|
@ -4,7 +4,7 @@ import tap from 'tap';
|
||||||
|
|
||||||
import {createClient} from '../index.js';
|
import {createClient} from '../index.js';
|
||||||
import {profile as rawProfile} from '../p/dbweb/index.js';
|
import {profile as rawProfile} from '../p/dbweb/index.js';
|
||||||
import res from './fixtures/dbweb-trip.json' with { type: 'json' };
|
import res from './fixtures/dbweb-trip.json' with { type: "json" };
|
||||||
import {dbwebTrip as expected} from './fixtures/dbweb-trip.js';
|
import {dbwebTrip as expected} from './fixtures/dbweb-trip.js';
|
||||||
|
|
||||||
const client = createClient(rawProfile, 'public-transport/hafas-client:test', {enrichStations: false});
|
const client = createClient(rawProfile, 'public-transport/hafas-client:test', {enrichStations: false});
|
||||||
|
|
Loading…
Add table
Reference in a new issue