From 04543f0146c6459765b7a35978b162c0bd201ffd Mon Sep 17 00:00:00 2001 From: Jannis R Date: Wed, 21 Dec 2022 14:30:00 +0100 Subject: [PATCH] =?UTF-8?q?db-hafas@6,=20hafas-rest-api@5,=20cached-hafas-?= =?UTF-8?q?client@5=20=F0=9F=92=A5=F0=9F=93=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #22 --- api-docs.js | 24 ++++++++++++------------ api.js | 12 ++++++------ docs/readme.md | 4 ++-- lib/loyalty-cards.js | 3 +-- package.json | 6 +++--- test/util.js | 4 ++-- 6 files changed, 26 insertions(+), 27 deletions(-) diff --git a/api-docs.js b/api-docs.js index 3cdf6c6..5004323 100644 --- a/api-docs.js +++ b/api-docs.js @@ -1,4 +1,4 @@ -import generateApiDocs from 'hafas-rest-api/tools/generate-docs.js' +import {generateApiDocs} from 'hafas-rest-api/tools/generate-docs.js' import {api} from './api.js' const HEAD = `\ @@ -30,22 +30,22 @@ const order = [ const descriptions = { '/locations': `\ -Uses [\`hafasClient.locations()\`](https://github.com/public-transport/hafas-client/blob/5/docs/locations.md) to **find stops/stations, POIs and addresses matching \`query\`**. +Uses [\`hafasClient.locations()\`](https://github.com/public-transport/hafas-client/blob/6/docs/locations.md) to **find stops/stations, POIs and addresses matching \`query\`**. `, '/stops/nearby': `\ -Uses [\`hafasClient.nearby()\`](https://github.com/public-transport/hafas-client/blob/5/docs/nearby.md) to **find stops/stations close to the given geolocation**. +Uses [\`hafasClient.nearby()\`](https://github.com/public-transport/hafas-client/blob/6/docs/nearby.md) to **find stops/stations close to the given geolocation**. `, '/stops/reachable-from': `\ -Uses [\`hafasClient.reachableFrom()\`](https://github.com/public-transport/hafas-client/blob/5/docs/reachable-from.md) to **find stops/stations reachable within a certain time from an address**. +Uses [\`hafasClient.reachableFrom()\`](https://github.com/public-transport/hafas-client/blob/6/docs/reachable-from.md) to **find stops/stations reachable within a certain time from an address**. `, '/stops/:id': `\ -Uses [\`hafasClient.stop()\`](https://github.com/public-transport/hafas-client/blob/5/docs/stop.md) to **find a stop/station by ID**. +Uses [\`hafasClient.stop()\`](https://github.com/public-transport/hafas-client/blob/6/docs/stop.md) to **find a stop/station by ID**. `, '/stops/:id/departures': `\ -Uses [\`hafasClient.departures()\`](https://github.com/public-transport/hafas-client/blob/5/docs/departures.md) to **get departures at a stop/station**. +Uses [\`hafasClient.departures()\`](https://github.com/public-transport/hafas-client/blob/6/docs/departures.md) to **get departures at a stop/station**. `, '/stops/:id/arrivals': `\ -Works like [\`/stops/:id/departures\`](#get-stopsiddepartures), except that it uses [\`hafasClient.arrivals()\`](https://github.com/public-transport/hafas-client/blob/5/docs/arrivals.md) to **arrivals at a stop/station**. +Works like [\`/stops/:id/departures\`](#get-stopsiddepartures), except that it uses [\`hafasClient.arrivals()\`](https://github.com/public-transport/hafas-client/blob/6/docs/arrivals.md) to **arrivals at a stop/station**. `, '/stations': `\ If the \`query\` parameter is used, it will use [\`db-stations-autocomplete@2\`](https://github.com/derhuerst/db-stations-autocomplete/tree/2.2.0) to autocomplete *Deutsche Bahn*-operated stops/stations. Otherwise, it will filter the stops/stations in [\`db-stations@3\`](https://github.com/derhuerst/db-stations/tree/3.0.1). @@ -56,7 +56,7 @@ Instead of receiving a JSON response, you can request [newline-delimited JSON](h Returns a stop/station from [\`db-stations\`](https://npmjs.com/package/db-stations). `, '/journeys': `\ -Uses [\`hafasClient.journeys()\`](https://github.com/public-transport/hafas-client/blob/5/docs/journeys.md) to **find journeys from A (\`from\`) to B (\`to\`)**. +Uses [\`hafasClient.journeys()\`](https://github.com/public-transport/hafas-client/blob/6/docs/journeys.md) to **find journeys from A (\`from\`) to B (\`to\`)**. \`from\` (A), \`to\` (B), and the optional \`via\` must each have one of these formats: @@ -68,20 +68,20 @@ Uses [\`hafasClient.journeys()\`](https://github.com/public-transport/hafas-clie Given a response, you can also fetch more journeys matching the same criteria. Instead of \`from*\`, \`to*\` & \`departure\`/\`arrival\`, pass \`earlierRef\` from the first response as \`earlierThan\` to get journeys "before", or \`laterRef\` as \`laterThan\` to get journeys "after". -Check the [\`hafasClient.journeys()\` docs](https://github.com/public-transport/hafas-client/blob/5/docs/journeys.md) for more details. +Check the [\`hafasClient.journeys()\` docs](https://github.com/public-transport/hafas-client/blob/6/docs/journeys.md) for more details. `, '/journeys/:ref': `\ -Uses [\`hafasClient.refreshJourney()\`](https://github.com/public-transport/hafas-client/blob/5/docs/refresh-journey.md) to **"refresh" a journey, using its \`refreshToken\`**. +Uses [\`hafasClient.refreshJourney()\`](https://github.com/public-transport/hafas-client/blob/6/docs/refresh-journey.md) to **"refresh" a journey, using its \`refreshToken\`**. The journey will be the same (equal \`from\`, \`to\`, \`via\`, date/time & vehicles used), but you can get up-to-date realtime data, like delays & cancellations. `, '/trips/:id': `\ -Uses [\`hafasClient.trip()\`](https://github.com/public-transport/hafas-client/blob/5/docs/trip.md) to **fetch a trip by ID**. +Uses [\`hafasClient.trip()\`](https://github.com/public-transport/hafas-client/blob/6/docs/trip.md) to **fetch a trip by ID**. A trip is a specific vehicle, stopping at a series of stops at specific points in time. Departures, arrivals & journey legs reference trips by their ID. `, '/radar': `\ -Uses [\`hafasClient.radar()\`](https://github.com/public-transport/hafas-client/blob/5/docs/radar.md) to **find all vehicles currently in an area**, as well as their movements. +Uses [\`hafasClient.radar()\`](https://github.com/public-transport/hafas-client/blob/6/docs/radar.md) to **find all vehicles currently in an area**, as well as their movements. `, } diff --git a/api.js b/api.js index ba954b4..30f874a 100644 --- a/api.js +++ b/api.js @@ -5,12 +5,12 @@ const require = createRequire(import.meta.url) import {dirname, join as pathJoin} from 'node:path' import {fileURLToPath} from 'node:url' -import createHafas from 'db-hafas' -import createApi from 'hafas-rest-api' +import {createDbHafas as createHafas} from 'db-hafas' +import {createHafasRestApi} from 'hafas-rest-api' import createHealthCheck from 'hafas-client-health-check' import Redis from 'ioredis' -import withCache from 'cached-hafas-client' -import redisStore from 'cached-hafas-client/stores/redis.js' +import {createCachedHafasClient} from 'cached-hafas-client' +import {createRedisStore} from 'cached-hafas-client/stores/redis.js' import serveStatic from 'serve-static' import {parseBoolean} from 'hafas-rest-api/lib/parse.js' import {loyaltyCardParser} from './lib/loyalty-cards.js' @@ -29,7 +29,7 @@ let healthCheck = createHealthCheck(hafas, berlinHbf) if (process.env.REDIS_URL) { const redis = new Redis(process.env.REDIS_URL || null) - hafas = withCache(hafas, redisStore(redis), { + hafas = createCachedHafasClient(hafas, createRedisStore(redis), { cachePeriods: { locations: 6 * 60 * 60 * 1000, // 6h }, @@ -87,7 +87,7 @@ const config = { modifyRoutes, } -const api = createApi(hafas, config, (api) => { +const api = await createHafasRestApi(hafas, config, (api) => { api.use('/', serveStatic(docsRoot, { extensions: ['html', 'htm'], })) diff --git a/docs/readme.md b/docs/readme.md index d331f8b..a891bd5 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -4,7 +4,7 @@ [![API status](https://badgen.net/uptime-robot/status/m784879516-8a977fa91b975fc3884a9857)](https://stats.uptimerobot.com/57wNLs39M/784879516) -Because it wraps [an API](https://github.com/public-transport/hafas-client/blob/master/readme.md#background) of [Deutsche Bahn](https://de.wikipedia.org/wiki/Deutsche_Bahn), it **includes most of the long-distance and regional traffic, as well as some international trains and local buses**. Essentially, it returns whatever data the [*DB Navigator* app](https://www.bahn.de/p/view/service/mobile/db-navigator.shtml) shows, **including realtime delays and disruptions**. +Because it wraps [an API](https://github.com/public-transport/hafas-client/blob/6/readme.md#background) of [Deutsche Bahn](https://de.wikipedia.org/wiki/Deutsche_Bahn), it **includes most of the long-distance and regional traffic, as well as some international trains and local buses**. Essentially, it returns whatever data the [*DB Navigator* app](https://www.bahn.de/p/view/service/mobile/db-navigator.shtml) shows, **including realtime delays and disruptions**. - [Getting Started](getting-started.md) - [API documentation](api.md) @@ -14,7 +14,7 @@ Because it wraps [an API](https://github.com/public-transport/hafas-client/blob/ ### Realtime Data -This API returns realtime data whenever its upstream, the [API for DB's mobile app](https://github.com/public-transport/hafas-client/blob/33d7d30acf235c54887c6459a15fe581982c6a19/p/db/readme.md), provides it. +This API returns realtime data whenever its upstream, the [API for DB's mobile app](https://github.com/public-transport/hafas-client/blob/6/p/db/readme.md), provides it. ### No API Key diff --git a/lib/loyalty-cards.js b/lib/loyalty-cards.js index 5532a8d..b54c508 100644 --- a/lib/loyalty-cards.js +++ b/lib/loyalty-cards.js @@ -1,5 +1,4 @@ -import _loyaltyCards from 'hafas-client/p/db/loyalty-cards.js' -const {data: cards} = _loyaltyCards +import {data as cards} from 'hafas-client/p/db/loyalty-cards.js' const typesByName = new Map([ // https://github.com/public-transport/hafas-client/blob/68ecd7c5e976dd2f51c5c64a81600e7e181a8996/p/db/loyalty-cards.js#L6-L11 diff --git a/package.json b/package.json index f0916a0..90034a2 100644 --- a/package.json +++ b/package.json @@ -23,14 +23,14 @@ "node": ">=18" }, "dependencies": { - "cached-hafas-client": "^4.0.4", + "cached-hafas-client": "^5.0.1", "cli-native": "^1.0.0", - "db-hafas": "^5.0.2", + "db-hafas": "^6.0.0", "db-stations": "^3.0.0", "db-stations-autocomplete": "^2.2.0", "etag": "^1.8.1", "hafas-client-health-check": "^2.1.1", - "hafas-rest-api": "^3.8.0", + "hafas-rest-api": "^5.1.0", "ioredis": "^5.0.6", "serve-buffer": "^2.0.0", "serve-static": "^1.14.1" diff --git a/test/util.js b/test/util.js index 8916160..89fe7c4 100644 --- a/test/util.js +++ b/test/util.js @@ -1,4 +1,4 @@ -import createApi from 'hafas-rest-api' +import {createHafasRestApi} from 'hafas-rest-api' import getPort from 'get-port' import {createServer} from 'node:http' import {promisify} from 'node:util' @@ -21,7 +21,7 @@ const createTestApi = async (mocks, cfg) => { ...cfg, } - const api = createApi(mockedHafas, cfg, () => {}) + const api = await createHafasRestApi(mockedHafas, cfg, () => {}) const server = createServer(api) const port = await getPort()