update deps

This commit is contained in:
Jannis R 2018-01-30 12:11:25 +01:00
parent 72f6cf2485
commit c33cc04f9f
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
3 changed files with 38 additions and 19 deletions

View file

@ -21,7 +21,7 @@ const route = (req, res, next) => {
stream.removeListener('data', onStation)
res.json(station)
next()
next('/station/:id')
}
stream.on('data', onStation)

View file

@ -1,12 +1,13 @@
'use strict'
const autocomplete = require('db-stations-autocomplete')
const stations = require('db-stations')
const allStations = require('db-stations/full.json')
const parse = require('cli-native').to
const createFilter = require('db-stations/create-filter')
const filterStream = require('stream-filter')
const ndjson = require('ndjson')
const hasProp = (o, k) => Object.prototype.hasOwnProperty.call(o, k)
const err400 = (msg) => {
const err = new Error(msg)
err.statusCode = 400
@ -14,10 +15,21 @@ const err400 = (msg) => {
}
const complete = (req, res, next) => {
const fuzzy = req.query.fuzzy === 'true'
const completion = req.query.completion !== 'false'
const limit = req.query.results && parseInt(req.query.results) || 3
const fuzzy = parse(req.query.fuzzy) === true
const completion = parse(req.query.completion) !== false
const results = autocomplete(req.query.query, limit, fuzzy, completion)
res.json(autocomplete(req.query.query, fuzzy, completion))
const data = []
for (let result of results) {
// todo: make this more efficient
const station = allStations.find(s => s.id === result.id)
if (!station) continue
data.push(Object.assign(result, station))
}
res.json(data)
next()
}
@ -27,17 +39,25 @@ const filter = (req, res, next) => {
}
const selector = Object.create(null)
for (let prop in req.query) selector[prop] = parse(req.query[prop])
for (let prop in req.query) {
if (prop.slice(0, 12) === 'coordinates.') { // derhuerst/db-rest#2
prop = 'location.' + prop.slice(12)
}
selector[prop] = parse(req.query[prop])
}
const filter = createFilter(selector)
stations.full()
.on('error', next)
.pipe(filterStream.obj(filter))
.on('error', next)
.pipe(ndjson.stringify())
.on('error', next)
res.type('application/x-ndjson')
const out = ndjson.stringify()
out
.once('error', next)
.pipe(res)
.once('finish', () => next())
for (let station of allStations) {
if (filter(station)) out.write(station)
}
out.end()
}
const route = (req, res, next) => {

View file

@ -28,13 +28,12 @@
},
"dependencies": {
"cli-native": "^1.0.0",
"db-hafas": "^2.0.0-alpha.2",
"db-stations": "^1.24.0",
"db-stations-autocomplete": "^1.0.0",
"hafas-rest-api": "0.1.0-alpha.10",
"db-hafas": "^2.1.0",
"db-stations": "^2.2.0",
"db-stations-autocomplete": "^2.0.1",
"hafas-rest-api": "^0.3.3",
"hsts": "^2.1.0",
"ndjson": "^1.5.0",
"stream-filter": "^2.1.0"
"ndjson": "^1.5.0"
},
"scripts": {
"start": "node index.js"