Gathering detailed insights and metrics for hafas-client-rpc
Gathering detailed insights and metrics for hafas-client-rpc
npm install hafas-client-rpc
Typescript
Module System
Min. Node Version
Node Version
NPM Version
57.3
Supply Chain
77.8
Quality
73.5
Maintenance
100
Vulnerability
96.2
License
JavaScript (100%)
Total Downloads
5,243
Last Day
1
Last Week
4
Last Month
39
Last Year
463
2 Stars
60 Commits
2 Watching
1 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
5.0.1
Package Id
hafas-client-rpc@5.0.1
Unpacked Size
26.55 kB
Size
8.34 kB
File Count
23
NPM Version
9.8.0
Node Version
20.5.1
Publised On
04 Sept 2023
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
33.3%
4
Compared to previous week
Last month
77.3%
39
Compared to previous month
Last year
-41.2%
463
Compared to previous year
10
1
4
Make JSON-RPC calls to hafas-client
via
websocket-pool
.stdin
/stdout
1npm install hafas-client-rpc
Note: This version of hafas-client-rpc
only works with specific versions of hafas-client
. Check peerDependencies
in package.json
for details.
hafas-client-rpc
has multiple transports. Each of them has a client part (which sends commands to make HAFAS calls) and a server (which executes the HAFAS calls).
With this transport, the server part is an actual WebSockets server, and the client connects to it.
1// server.js 2import http from 'http' 3import {createClient as createHafas} from 'hafas-client' 4import {profile as vbbProfile} from 'hafas-client/p/vbb/index.js' 5import exposeHafasClient from 'hafas-client-rpc/ws/server' 6 7const httpServer = http.createServer() 8httpServer.listen(3000) 9 10const hafas = createHafas(vbbProfile, 'my-awesome-program') 11const server = exposeHafasClient(httpServer, hafas)
1// client.js 2import createRoundRobin from '@derhuerst/round-robin-scheduler' 3import createClient from 'hafas-client-rpc/ws/client.js' 4 5const pool = createClient(createRoundRobin, [ 6 'ws://server-address:3000' 7 // pass more addresses here if you want 8], (_, hafas) => { 9 hafas.departures('900000009102') 10 .then(console.log) 11 .catch(console.error) 12}) 13pool.on('error', console.error)
Or using the websocat
command-line WebSocket client:
1echo 'departures 900000009102' | websocat --jsonrpc 'ws://server-address:3000'
stdin
/stdout
transportWith this transport, the client spawns the server as a sub-process and sends commands via stdio.
1// server.js 2import {createClient as createHafas} from 'hafas-client' 3import {profile as vbbProfile} from 'hafas-client/p/vbb/index.js' 4import exposeViaStdio from 'hafas-client-rpc/stdio/server.js' 5 6const hafas = createHafas(vbbProfile, 'my-awesome-program') 7 8exposeViaStdio(hafas, (err) => { 9 console.log('hafas-client-rpc server ready') 10})
Creating a client in Node.js doesn't make sense, because you could just use hafas-client
directly. You would usually write the client in another language. For demonstration purposes, a Node client:
1// client.js 2import createClient from 'hafas-client-rpc/stdio/client.js' 3 4createClient('path/to/stdio/server.js', (_, hafas) => { 5 hafas.departures('900000009102') 6 .then(console.log) 7 .catch(console.error) 8})
Spawn the stdio RPC server as a sub process of your script:
1node $(node -p 'require.resolve("hafas-client-rpc/stdio/simple-server.js")')
Send JSON-RPC 2.0 calls via stdin
:
1{"jsonrpc":"2.0","id":"1","method":"departures","params":["900000009102"]}
On success, you will receive the result via stdout
:
1{"jsonrpc":"2.0","id":"1","result":[{"tripId":"1|32623|3|86|8122018", …}]}
If an error occurs, you will receive it via stderr
:
1{"jsonrpc":"2.0","id":"1","error":{"message":"station ID must be a valid IBNR.","code":0,"data":{}}}
With this transport, both client & server connect to a local TCP socket /tmp/hafas-client-rpc-{version}
.
1// server.js 2import {createClient as createHafas} from 'hafas-client' 3import {profile as vbbProfile} from 'hafas-client/p/vbb/index.js' 4import exposeViaSocket from 'hafas-client-rpc/socket/server.js' 5 6const hafas = createHafas(vbbProfile, 'my-awesome-program') 7 8exposeViaSocket(hafas)
1// client.js 2import createClient from 'hafas-client-rpc/socket/client.js' 3 4createClient((_, hafas) => { 5 hafas.departures('900000009102') 6 .then(console.log) 7 .catch(console.error) 8})
This transport relies on NATS streaming channels. This allows you to have a pool of servers where an individual server can go offline at any time, as the channel will persist all RPC requests until they're taken care of. The transport uses two durable channels (one for RPC requests, the other for responses).
1// server.js 2import {createClient as createHafas} from 'hafas-client' 3import {profile as vbbProfile} from 'hafas-client/p/vbb/index.js' 4import exposeViaNatsStreaming from 'hafas-client-rpc/nats-streaming/server.js' 5 6const hafas = createHafas(vbbProfile, 'hafas-client-rpc WebSockets example') 7exposeViaNatsStreaming(hafas, (err) => { 8 if (err) console.error(err) 9})
1// client.js 2import createClient from 'hafas-client-rpc/nats-streaming/client.js' 3 4const pool = createClient((_, hafas) => { 5 hafas.departures('900000009102') 6 .then(console.log) 7 .catch(console.error) 8})
hafas-client
exposes the used profile as hafasClient.profile
. Because these profiles consist of JavaScript functions, which can't be serialized properly, the hafas-client-rpc
facade does not expose .profile
.hafas-client
– JavaScript client for HAFAS public transport APIs.If you have a question or have difficulties using hafas-client-rpc
, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, refer to the issues page.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no SAST tool detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Score
Last Scanned on 2025-01-06
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More