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 1.3.1 to 1.4.0

96

lib/routes.js

@@ -92,41 +92,2 @@ var h = require('./h.js')

get('/api/0.6/:type/:id', function (req, res, osm, m) {
osm.get(m.params.id, function (err, docs) {
if (err) return error(500, res, err)
if (docs.length === 0) return error(404, res, 'not found')
res.setHeader('content-type', 'text/xml')
res.end(h('osm', Object.keys(docs).map(function (key) {
var doc = xtend(docs[key], {
id: m.params.id,
version: key
})
var type = doc.type
delete doc.type
var children = []
Object.keys(doc.tags || {}).forEach(function (key) {
children.push(h('tag/', { k: key, v: doc.tags[key] }))
})
delete doc.tags
if (doc.type === 'way') {
;(doc.refs || []).forEach(function (ref) {
children.push(h('nd/', { ref: ref }))
})
delete docs.refs
}
if (doc.type === 'relation') {
;(doc.members || []).forEach(function (m) {
children.push(h('member/', m))
})
delete doc.members
}
return h(type, doc, children)
})))
})
})
get('/api/0.6/changeset/:id/download', function (req, res, osm, m) {

@@ -191,2 +152,32 @@ osm.getChanges(m.params.id, function (err, ids) {

get('/api/0.6/:type/:id/:version', function (req, res, osm, m) {
osm.log.get(m.params.version, function (err, doc) {
if (err && (/^notfound/.test(err) || err.notFound)) {
return error(404, res, 'not found')
}
if (err) return error(500, res, err)
res.setHeader('content-type', 'text/xml')
res.end(h('osm', [
renderElem(xtend(doc.value.v, {
id: m.params.id,
version: m.params.version
}))
]))
})
})
get('/api/0.6/:type/:id', function (req, res, osm, m) {
osm.get(m.params.id, function (err, docs) {
if (err) return error(500, res, err)
if (docs.length === 0) return error(404, res, 'not found')
res.setHeader('content-type', 'text/xml')
res.end(h('osm', Object.keys(docs).map(function (key) {
renderElem(xtend(docs[key], {
id: m.params.id,
version: key
}))
})))
})
})
put('/api/0.6/changeset/:id/upload', function (req, res, osm, m) {

@@ -324,1 +315,28 @@ var errors = [], results = []

}
function renderElem (doc) {
var type = doc.type
delete doc.type
var children = []
Object.keys(doc.tags || {}).forEach(function (key) {
children.push(h('tag/', { k: key, v: doc.tags[key] }))
})
delete doc.tags
if (doc.type === 'way') {
;(doc.refs || []).forEach(function (ref) {
children.push(h('nd/', { ref: ref }))
})
delete docs.refs
}
if (doc.type === 'relation') {
;(doc.members || []).forEach(function (m) {
children.push(h('member/', m))
})
delete doc.members
}
return h(type, doc, children)
}

@@ -14,5 +14,5 @@ var parsexml = require('xml-parser')

var doc = xtend(ch.attributes, { type: ch.name })
if (doc.id) doc.oldId = doc.id
if (doc.id && Number(doc.id) < 0) {
ids[doc.id] = randombytes(8).toString('hex')
doc.oldId = doc.id
doc.id = ids[doc.oldId]

@@ -19,0 +19,0 @@ }

{
"name": "osm-p2p-server",
"version": "1.3.1",
"version": "1.4.0",
"description": "serve osm http endpoints over a p2p db",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -214,2 +214,99 @@ var test = require('tape')

var secondChangeId
test('create second changeset', function (t) {
t.plan(3)
var href = base + 'changeset/create'
var hq = hyperquest.put(href, {
headers: { 'content-type': 'text/xml' }
})
hq.once('response', function (res) {
t.equal(res.statusCode, 200, 'create 200 ok')
t.equal(res.headers['content-type'], 'text/plain', 'create content type')
})
hq.pipe(concat({ encoding: 'string' }, function (body) {
secondChangeId = body.trim()
t.ok(/^[0-9A-Fa-f]+$/.test(secondChangeId), 'expected changeset id response')
}))
hq.end(`<osm>
<changeset>
<tag k="comment" v="second"/>
</changeset>
</osm>`)
})
test('second changeset upload', function (t) {
t.plan(10)
var href = base + 'changeset/' + secondChangeId + '/upload'
var hq = hyperquest.put(href, {
headers: { 'content-type': 'text/xml' }
})
hq.on('response', function (res) {
t.equal(res.statusCode, 200)
t.equal(res.headers['content-type'], 'text/xml')
})
var oldv, newv
hq.pipe(concat({ encoding: 'string' }, function (body) {
var xml = parsexml(body)
t.equal(xml.root.name, 'diffResult')
t.deepEqual(xml.root.children.map(function (c) {
return c.attributes.old_id
}).sort(), [ids['-1']])
oldv = versions['-1']
newv = xml.root.children[0].attributes.new_version
hyperquest.get(base + 'node/' + ids['-1'] + '/' + newv)
.on('response', function (res) {
t.equal(res.statusCode, 200)
})
.pipe(concat({ encoding: 'string' }, onnew))
hyperquest.get(base + 'node/' + ids['-1'] + '/' + oldv)
.on('response', function (res) {
t.equal(res.statusCode, 200)
})
.pipe(concat({ encoding: 'string' }, onold))
}))
hq.end(`<osmChange version="1.0" generator="acme osm editor">
<modify>
<node id="${ids['-1']}" changeset="${secondChangeId}" lat="111" lon="222"/>
</modify>
</osmChange>`)
function onnew (body) {
var xml = parsexml(body)
t.equal(xml.root.name, 'osm')
t.deepEqual(xml.root.children, [
{
name: 'node',
attributes: {
changeset: secondChangeId,
lat: '111',
lon: '222',
id: ids['-1'],
version: newv
},
content: '',
children: []
}
])
}
function onold (body) {
var xml = parsexml(body)
t.equal(xml.root.name, 'osm')
t.deepEqual(xml.root.children, [
{
name: 'node',
attributes: {
changeset: changeId,
lat: '64.5',
lon: '-121.5',
id: ids['-1'],
version: oldv
},
content: '',
children: []
}
])
}
})
test('teardown changeset upload server', function (t) {

@@ -216,0 +313,0 @@ server.close()

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