mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-06-19 10:42:33 +03:00
Compare commits
6 commits
1f49a52184
...
6c8f50350b
Author | SHA1 | Date | |
---|---|---|---|
|
6c8f50350b | ||
|
5e502a6f44 | ||
|
406d24a051 | ||
|
1f95ca06c1 | ||
|
c951466597 | ||
|
f1d226e9c8 |
20 changed files with 1473 additions and 1018 deletions
7
debug.js
Normal file
7
debug.js
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
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);
|
7
index.js
7
index.js
|
@ -26,10 +26,10 @@ const validateLocation = (loc, name = 'location') => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadEnrichedStationData = (profile) => new Promise(async (resolve, reject) => {
|
const loadEnrichedStationData = (profile) => new Promise((resolve, reject) => {
|
||||||
const { default: readStations} = await import('db-hafas-stations');
|
import('db-hafas-stations').then(m => {
|
||||||
const items = {};
|
const items = {};
|
||||||
readStations.full()
|
m.default.full()
|
||||||
.on('data', (station) => {
|
.on('data', (station) => {
|
||||||
items[station.id] = station;
|
items[station.id] = station;
|
||||||
items[station.name] = station;
|
items[station.name] = station;
|
||||||
|
@ -44,6 +44,7 @@ const loadEnrichedStationData = (profile) => new Promise(async (resolve, reject)
|
||||||
reject(err);
|
reject(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const applyEnrichedStationData = async (ctx, shouldLoadEnrichedStationData) => {
|
const applyEnrichedStationData = async (ctx, shouldLoadEnrichedStationData) => {
|
||||||
const {profile, common} = ctx;
|
const {profile, common} = ctx;
|
||||||
|
|
|
@ -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,7 +7,8 @@ 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).padStart(2, '0'))
|
.map((byte) => byte.toString(16)
|
||||||
|
.padStart(2, '0'))
|
||||||
.join('');
|
.join('');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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';
|
||||||
|
|
2407
package-lock.json
generated
2407
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -68,12 +68,15 @@
|
||||||
"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