Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

osm-p2p-server

Package Overview
Dependencies
Maintainers
2
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

osm-p2p-server - npm Package Compare versions

Comparing version 2.0.0-beta2 to 2.0.0-beta3

22

lib/util.js
var contentType = require('content-type')
var randombytes = require('randombytes')
var convert = require('base-convertor')
var JSONStream = require('JSONStream')
var version = require('../package.json').version
/**

@@ -41,2 +44,18 @@ * Converts objects from osm-p2p to objects compatible with the OSM JSON format

var TEMPLATE = {
version: 0.6,
generator: 'osm-p2p v' + version,
elements: []
}
var SEP = ',\n '
function OsmJSONStream (opts) {
var template = Object.assign({}, TEMPLATE, opts)
var openClose = JSON.stringify(template, null, 4).split('"elements": [')
var open = openClose[0] + '"elements": [\n '
var close = '\n ' + openClose[1]
return JSONStream.stringify(open, SEP, close)
}
/**

@@ -78,3 +97,4 @@ * Sort function to sort forks by most recent first, or by version id

isValidContentType: isValidContentType,
cmpFork: cmpFork
cmpFork: cmpFork,
OsmJSONStream: OsmJSONStream
}

14

package.json
{
"name": "osm-p2p-server",
"version": "2.0.0-beta2",
"version": "2.0.0-beta3",
"description": "Peer-to-peer OpenStreetMap API v0.6 Server",

@@ -21,8 +21,12 @@ "main": "index.js",

"author": "substack",
"contributors": [{
"name": "Gregor MacLennan",
"email": "gmaclennan@digital-democracy.org"
}],
"contributors": [
{
"name": "Gregor MacLennan",
"email": "gmaclennan@digital-democracy.org"
}
],
"license": "BSD-2-Clause",
"dependencies": {
"JSONStream": "^1.1.4",
"accepts": "^1.3.3",
"base-convertor": "^1.1.0",

@@ -29,0 +33,0 @@ "collect-stream": "^1.1.1",

@@ -32,5 +32,5 @@ /**

res.setHeader('content-type', 'text/plain')
res.end(id + '\n')
res.end(id)
})
})
}
var qs = require('query-string')
var toOsm = require('obj2osm')
var fromArray = require('from2-array')
var accepts = require('accepts')
var cmpFork = require('../lib/util').cmpFork
var OsmJSONStream = require('../lib/util').OsmJSONStream
module.exports = function (req, res, api, params, next) {
// TODO: Validate bbox
var accept = accepts(req)
var query = qs.parse(qs.extract(req.url))

@@ -32,4 +35,15 @@ var bbox = query.bbox.split(',').map(Number)

var r = fromArray.obj(byType).on('error', next)
var t = toOsm(toOsmOptions).on('error', next)
res.setHeader('content-type', 'text/xml; charset=utf-8')
var t
switch (accept.types(['xml', 'json'])) {
case 'json':
t = OsmJSONStream(toOsmOptions)
res.setHeader('content-type', 'application/json; charset=utf-8')
break
case 'xml':
default:
t = toOsm(toOsmOptions)
res.setHeader('content-type', 'text/xml; charset=utf-8')
break
}
t.on('error', next)
r.pipe(t).pipe(res)

@@ -36,0 +50,0 @@ })

@@ -5,3 +5,3 @@ var test = require('tape')

var concat = require('concat-stream')
var fs = require('fs')
var createServer = require('./test_server.js')

@@ -100,3 +100,3 @@

test('bbox', function (t) {
t.plan(7 + SIZE * 3)
t.plan(8 + SIZE * 3)
var href = base + 'map?bbox=-123,63,-120,66'

@@ -112,2 +112,3 @@ var hq = hyperquest(href)

t.equal(xml.root.children[0].name, 'bounds')
t.deepEqual(xml.root.children[0].attributes, { maxlat: '66', maxlon: '-120', minlat: '63', minlon: '-123' }, 'bounds matches request')
t.ok(orderedTypes(xml.root.children.map(function (c) {

@@ -134,2 +135,33 @@ return c.name

test('bbox json', function (t) {
t.plan(7 + SIZE * 3)
var href = base + 'map?bbox=-123,63,-120,66'
var hq = hyperquest(href, {headers: { 'Accept': 'application/json' }})
hq.once('response', function (res) {
t.equal(res.statusCode, 200)
t.equal(res.headers['content-type'].split(/\s*;\s*/)[0], 'application/json')
})
hq.pipe(concat({ encoding: 'string' }, function (body) {
var json = JSON.parse(body)
t.equal(json.version, 0.6)
t.deepEqual(json.bounds, { maxlat: 66, maxlon: -120, minlat: 63, minlon: -123 }, 'bounds matches request')
t.ok(orderedTypes(json.elements.map(function (c) {
return c.type
})), 'ordered types')
for (var i = 0; i < json.elements.length; i++) {
var c = json.elements[i]
var node = uploaded[c.id]
if (c.type === 'node') {
t.equal(c.changeset, node.changeset)
t.equal(c.lat, node.lat)
t.equal(c.lon, node.lon)
} else if (c.type === 'way') {
t.equal(c.nodes.length, SIZE, 'way')
t.deepEqual(c.nodes, node.refs, 'way refs')
}
}
}))
})
test('bbox.js: teardown server', function (t) {

@@ -136,0 +168,0 @@ server.cleanup()

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc