update deps
This commit is contained in:
parent
72f6cf2485
commit
c33cc04f9f
3 changed files with 38 additions and 19 deletions
|
@ -21,7 +21,7 @@ const route = (req, res, next) => {
|
||||||
stream.removeListener('data', onStation)
|
stream.removeListener('data', onStation)
|
||||||
|
|
||||||
res.json(station)
|
res.json(station)
|
||||||
next()
|
next('/station/:id')
|
||||||
}
|
}
|
||||||
stream.on('data', onStation)
|
stream.on('data', onStation)
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const autocomplete = require('db-stations-autocomplete')
|
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 parse = require('cli-native').to
|
||||||
const createFilter = require('db-stations/create-filter')
|
const createFilter = require('db-stations/create-filter')
|
||||||
const filterStream = require('stream-filter')
|
|
||||||
const ndjson = require('ndjson')
|
const ndjson = require('ndjson')
|
||||||
|
|
||||||
|
const hasProp = (o, k) => Object.prototype.hasOwnProperty.call(o, k)
|
||||||
|
|
||||||
const err400 = (msg) => {
|
const err400 = (msg) => {
|
||||||
const err = new Error(msg)
|
const err = new Error(msg)
|
||||||
err.statusCode = 400
|
err.statusCode = 400
|
||||||
|
@ -14,10 +15,21 @@ const err400 = (msg) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const complete = (req, res, next) => {
|
const complete = (req, res, next) => {
|
||||||
const fuzzy = req.query.fuzzy === 'true'
|
const limit = req.query.results && parseInt(req.query.results) || 3
|
||||||
const completion = req.query.completion !== 'false'
|
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()
|
next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,17 +39,25 @@ const filter = (req, res, next) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const selector = Object.create(null)
|
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)
|
const filter = createFilter(selector)
|
||||||
|
|
||||||
stations.full()
|
res.type('application/x-ndjson')
|
||||||
.on('error', next)
|
const out = ndjson.stringify()
|
||||||
.pipe(filterStream.obj(filter))
|
out
|
||||||
.on('error', next)
|
.once('error', next)
|
||||||
.pipe(ndjson.stringify())
|
|
||||||
.on('error', next)
|
|
||||||
.pipe(res)
|
.pipe(res)
|
||||||
.once('finish', () => next())
|
.once('finish', () => next())
|
||||||
|
|
||||||
|
for (let station of allStations) {
|
||||||
|
if (filter(station)) out.write(station)
|
||||||
|
}
|
||||||
|
out.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
const route = (req, res, next) => {
|
const route = (req, res, next) => {
|
||||||
|
|
11
package.json
11
package.json
|
@ -28,13 +28,12 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cli-native": "^1.0.0",
|
"cli-native": "^1.0.0",
|
||||||
"db-hafas": "^2.0.0-alpha.2",
|
"db-hafas": "^2.1.0",
|
||||||
"db-stations": "^1.24.0",
|
"db-stations": "^2.2.0",
|
||||||
"db-stations-autocomplete": "^1.0.0",
|
"db-stations-autocomplete": "^2.0.1",
|
||||||
"hafas-rest-api": "0.1.0-alpha.10",
|
"hafas-rest-api": "^0.3.3",
|
||||||
"hsts": "^2.1.0",
|
"hsts": "^2.1.0",
|
||||||
"ndjson": "^1.5.0",
|
"ndjson": "^1.5.0"
|
||||||
"stream-filter": "^2.1.0"
|
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node index.js"
|
"start": "node index.js"
|
||||||
|
|
Loading…
Reference in a new issue