osm-p2p-server
Advanced tools
Comparing version 2.0.4 to 2.1.0
@@ -89,3 +89,4 @@ var errors = require('../errors') | ||
}) | ||
op.value.timestamp = new Date().toISOString() | ||
return op | ||
} |
@@ -5,2 +5,9 @@ # Change Log | ||
## [2.1.0] | ||
### Added | ||
- Add a timestamp to elements in a changeset upload with creation/modification time (on the server) | ||
### Fixed | ||
- The latest fork should be returned if forks != `true`, and forks with a timestamp should be preferred over forks without a timestamp (legacy elements do not have a timestamp). The fork sort/compare function was incorrect. | ||
## [2.0.4] | ||
@@ -68,2 +75,4 @@ ### Fixed | ||
[2.1.0]: https://github.com/digidem/osm-p2p-server/compare/2.0.4...2.1.0 | ||
[2.0.4]: https://github.com/digidem/osm-p2p-server/compare/2.0.3...2.0.4 | ||
[2.0.3]: https://github.com/digidem/osm-p2p-server/compare/2.0.2...2.0.3 | ||
@@ -70,0 +79,0 @@ [2.0.2]: https://github.com/digidem/osm-p2p-server/compare/2.0.1...2.0.2 |
@@ -66,5 +66,10 @@ var contentType = require('content-type') | ||
if (a.timestamp && b.timestamp) { | ||
return b.timestamp - a.timestamp | ||
if (a.timestamp > b.timestamp) return -1 | ||
if (a.timestamp < b.timestamp) return 1 | ||
return 0 | ||
} | ||
if (a.timestamp) return -1 | ||
if (b.timestamp) return 1 | ||
// Ensure sorting is stable between requests | ||
console.log(a.version, b.version, a.version < b.version) | ||
return a.version < b.version ? -1 : 1 | ||
@@ -71,0 +76,0 @@ } |
{ | ||
"name": "osm-p2p-server", | ||
"version": "2.0.4", | ||
"version": "2.1.0", | ||
"description": "Peer-to-peer OpenStreetMap API v0.6 Server", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,2 +6,3 @@ var test = require('tape') | ||
var concat = require('concat-stream') | ||
var isISODate = require('isostring') | ||
@@ -84,3 +85,48 @@ var createServer = require('./lib/test_server.js') | ||
test('get osmchange doc from upload', function (t) { | ||
t.plan(4) | ||
t.plan(7) | ||
var expected = [ | ||
{ | ||
name: 'node', | ||
attributes: { | ||
changeset: changeId, | ||
id: ids['1'], | ||
version: versions['1'], | ||
lat: '64.5', | ||
lon: '-121.5' | ||
}, | ||
children: [] | ||
}, | ||
{ | ||
name: 'node', | ||
attributes: { | ||
changeset: changeId, | ||
id: ids['2'], | ||
version: versions['2'], | ||
lat: '63.9', | ||
lon: '-120.9' | ||
}, | ||
children: [] | ||
}, | ||
{ | ||
name: 'way', | ||
attributes: { | ||
changeset: changeId, | ||
id: ids['3'], | ||
version: versions['3'] | ||
}, | ||
content: '', | ||
children: [ | ||
{ | ||
name: 'nd', | ||
attributes: { ref: ids['2'] }, | ||
children: [] | ||
}, | ||
{ | ||
name: 'nd', | ||
attributes: { ref: ids['1'] }, | ||
children: [] | ||
} | ||
].sort(cmpref) | ||
} | ||
].sort(cmpch) | ||
var href = base + 'changeset/' + changeId + '/download' | ||
@@ -99,47 +145,7 @@ var hq = hyperquest(href, { | ||
}) | ||
t.deepEqual(xml.root.children[0].children, [ | ||
{ | ||
name: 'node', | ||
attributes: { | ||
changeset: changeId, | ||
id: ids['1'], | ||
version: versions['1'], | ||
lat: '64.5', | ||
lon: '-121.5' | ||
}, | ||
children: [] | ||
}, | ||
{ | ||
name: 'node', | ||
attributes: { | ||
changeset: changeId, | ||
id: ids['2'], | ||
version: versions['2'], | ||
lat: '63.9', | ||
lon: '-120.9' | ||
}, | ||
children: [] | ||
}, | ||
{ | ||
name: 'way', | ||
attributes: { | ||
changeset: changeId, | ||
id: ids['3'], | ||
version: versions['3'] | ||
}, | ||
content: '', | ||
children: [ | ||
{ | ||
name: 'nd', | ||
attributes: { ref: ids['2'] }, | ||
children: [] | ||
}, | ||
{ | ||
name: 'nd', | ||
attributes: { ref: ids['1'] }, | ||
children: [] | ||
} | ||
].sort(cmpref) | ||
} | ||
].sort(cmpch)) | ||
xml.root.children[0].children.forEach(function (c) { | ||
t.true(isISODate(c.attributes.timestamp)) | ||
delete c.attributes.timestamp | ||
}) | ||
t.deepEqual(xml.root.children[0].children, expected) | ||
})) | ||
@@ -237,3 +243,3 @@ }) | ||
test('second changeset upload', function (t) { | ||
t.plan(11) | ||
t.plan(13) | ||
var href = base + 'changeset/' + secondChangeId + '/upload' | ||
@@ -279,2 +285,4 @@ var hq = hyperquest.post(href, { | ||
t.equal(xml.root.name, 'osm') | ||
t.true(isISODate(xml.root.children[0].attributes.timestamp)) | ||
delete xml.root.children[0].attributes.timestamp | ||
t.deepEqual(xml.root.children, [ | ||
@@ -297,2 +305,4 @@ { | ||
t.equal(xml.root.name, 'osm') | ||
t.true(isISODate(xml.root.children[0].attributes.timestamp)) | ||
delete xml.root.children[0].attributes.timestamp | ||
t.deepEqual(xml.root.children, [ | ||
@@ -299,0 +309,0 @@ { |
@@ -6,2 +6,3 @@ var test = require('tape') | ||
var concat = require('concat-stream') | ||
var isISODate = require('isostring') | ||
@@ -88,3 +89,69 @@ var base, server, changeId | ||
test('get osmchange doc from upload', function (t) { | ||
t.plan(4) | ||
t.plan(8) | ||
var expected = [ | ||
{ | ||
name: 'node', | ||
attributes: { | ||
changeset: changeId, | ||
id: ids['-1'], | ||
version: versions['-1'], | ||
lat: '64.5', | ||
lon: '-121.5' | ||
}, | ||
children: [] | ||
}, | ||
{ | ||
name: 'node', | ||
attributes: { | ||
changeset: changeId, | ||
id: ids['-2'], | ||
version: versions['-2'], | ||
lat: '63.9', | ||
lon: '-120.9' | ||
}, | ||
children: [] | ||
}, | ||
{ | ||
name: 'way', | ||
attributes: { | ||
changeset: changeId, | ||
id: ids['-3'], | ||
version: versions['-3'] | ||
}, | ||
content: '', | ||
children: [ | ||
{ | ||
name: 'nd', | ||
attributes: { ref: ids['-2'] }, | ||
children: [] | ||
}, | ||
{ | ||
name: 'nd', | ||
attributes: { ref: ids['-1'] }, | ||
children: [] | ||
} | ||
].sort(cmpref) | ||
}, | ||
{ | ||
name: 'relation', | ||
attributes: { | ||
changeset: changeId, | ||
id: ids['-4'], | ||
version: versions['-4'] | ||
}, | ||
content: '', | ||
children: [ | ||
{ | ||
name: 'member', | ||
attributes: { type: 'way', ref: ids['-3'], role: '' }, | ||
children: [] | ||
}, | ||
{ | ||
name: 'tag', | ||
attributes: { k: 'hello', v: 'world' }, | ||
children: [] | ||
} | ||
] | ||
} | ||
].sort(cmpch) | ||
var href = base + 'changeset/' + changeId + '/download' | ||
@@ -103,68 +170,7 @@ var hq = hyperquest(href, { | ||
}) | ||
t.deepEqual(xml.root.children[0].children, [ | ||
{ | ||
name: 'node', | ||
attributes: { | ||
changeset: changeId, | ||
id: ids['-1'], | ||
version: versions['-1'], | ||
lat: '64.5', | ||
lon: '-121.5' | ||
}, | ||
children: [] | ||
}, | ||
{ | ||
name: 'node', | ||
attributes: { | ||
changeset: changeId, | ||
id: ids['-2'], | ||
version: versions['-2'], | ||
lat: '63.9', | ||
lon: '-120.9' | ||
}, | ||
children: [] | ||
}, | ||
{ | ||
name: 'way', | ||
attributes: { | ||
changeset: changeId, | ||
id: ids['-3'], | ||
version: versions['-3'] | ||
}, | ||
content: '', | ||
children: [ | ||
{ | ||
name: 'nd', | ||
attributes: { ref: ids['-2'] }, | ||
children: [] | ||
}, | ||
{ | ||
name: 'nd', | ||
attributes: { ref: ids['-1'] }, | ||
children: [] | ||
} | ||
].sort(cmpref) | ||
}, | ||
{ | ||
name: 'relation', | ||
attributes: { | ||
changeset: changeId, | ||
id: ids['-4'], | ||
version: versions['-4'] | ||
}, | ||
content: '', | ||
children: [ | ||
{ | ||
name: 'member', | ||
attributes: { type: 'way', ref: ids['-3'], role: '' }, | ||
children: [] | ||
}, | ||
{ | ||
name: 'tag', | ||
attributes: { k: 'hello', v: 'world' }, | ||
children: [] | ||
} | ||
] | ||
} | ||
].sort(cmpch)) | ||
xml.root.children[0].children.forEach(function (c) { | ||
t.true(isISODate(c.attributes.timestamp)) | ||
delete c.attributes.timestamp | ||
}) | ||
t.deepEqual(xml.root.children[0].children, expected) | ||
})) | ||
@@ -262,3 +268,3 @@ }) | ||
test('second changeset upload', function (t) { | ||
t.plan(11) | ||
t.plan(13) | ||
var href = base + 'changeset/' + secondChangeId + '/upload' | ||
@@ -304,2 +310,4 @@ var hq = hyperquest.post(href, { | ||
t.equal(xml.root.name, 'osm') | ||
t.true(isISODate(xml.root.children[0].attributes.timestamp)) | ||
delete xml.root.children[0].attributes.timestamp | ||
t.deepEqual(xml.root.children, [ | ||
@@ -322,2 +330,4 @@ { | ||
t.equal(xml.root.name, 'osm') | ||
t.true(isISODate(xml.root.children[0].attributes.timestamp)) | ||
delete xml.root.children[0].attributes.timestamp | ||
t.deepEqual(xml.root.children, [ | ||
@@ -324,0 +334,0 @@ { |
@@ -6,2 +6,3 @@ var test = require('tape') | ||
var concat = require('concat-stream') | ||
var isISODate = require('isostring') | ||
@@ -84,3 +85,48 @@ var createServer = require('./lib/test_server.js') | ||
test('get osmchange doc from upload', function (t) { | ||
t.plan(4) | ||
t.plan(7) | ||
var expected = [ | ||
{ | ||
name: 'node', | ||
attributes: { | ||
changeset: changeId, | ||
id: ids['-1'], | ||
version: versions['-1'], | ||
lat: '64.5', | ||
lon: '-121.5' | ||
}, | ||
children: [] | ||
}, | ||
{ | ||
name: 'node', | ||
attributes: { | ||
changeset: changeId, | ||
id: ids['-2'], | ||
version: versions['-2'], | ||
lat: '63.9', | ||
lon: '-120.9' | ||
}, | ||
children: [] | ||
}, | ||
{ | ||
name: 'way', | ||
attributes: { | ||
changeset: changeId, | ||
id: ids['-3'], | ||
version: versions['-3'] | ||
}, | ||
content: '', | ||
children: [ | ||
{ | ||
name: 'nd', | ||
attributes: { ref: ids['-2'] }, | ||
children: [] | ||
}, | ||
{ | ||
name: 'nd', | ||
attributes: { ref: ids['-1'] }, | ||
children: [] | ||
} | ||
].sort(cmpref) | ||
} | ||
].sort(cmpch) | ||
var href = base + 'changeset/' + changeId + '/download' | ||
@@ -99,47 +145,7 @@ var hq = hyperquest(href, { | ||
}) | ||
t.deepEqual(xml.root.children[0].children, [ | ||
{ | ||
name: 'node', | ||
attributes: { | ||
changeset: changeId, | ||
id: ids['-1'], | ||
version: versions['-1'], | ||
lat: '64.5', | ||
lon: '-121.5' | ||
}, | ||
children: [] | ||
}, | ||
{ | ||
name: 'node', | ||
attributes: { | ||
changeset: changeId, | ||
id: ids['-2'], | ||
version: versions['-2'], | ||
lat: '63.9', | ||
lon: '-120.9' | ||
}, | ||
children: [] | ||
}, | ||
{ | ||
name: 'way', | ||
attributes: { | ||
changeset: changeId, | ||
id: ids['-3'], | ||
version: versions['-3'] | ||
}, | ||
content: '', | ||
children: [ | ||
{ | ||
name: 'nd', | ||
attributes: { ref: ids['-2'] }, | ||
children: [] | ||
}, | ||
{ | ||
name: 'nd', | ||
attributes: { ref: ids['-1'] }, | ||
children: [] | ||
} | ||
].sort(cmpref) | ||
} | ||
].sort(cmpch)) | ||
xml.root.children[0].children.forEach(function (c) { | ||
t.true(isISODate(c.attributes.timestamp)) | ||
delete c.attributes.timestamp | ||
}) | ||
t.deepEqual(xml.root.children[0].children, expected) | ||
})) | ||
@@ -237,3 +243,3 @@ }) | ||
test('second changeset upload', function (t) { | ||
t.plan(11) | ||
t.plan(13) | ||
var href = base + 'changeset/' + secondChangeId + '/upload' | ||
@@ -279,2 +285,4 @@ var hq = hyperquest.post(href, { | ||
t.equal(xml.root.name, 'osm') | ||
t.true(isISODate(xml.root.children[0].attributes.timestamp)) | ||
delete xml.root.children[0].attributes.timestamp | ||
t.deepEqual(xml.root.children, [ | ||
@@ -297,2 +305,4 @@ { | ||
t.equal(xml.root.name, 'osm') | ||
t.true(isISODate(xml.root.children[0].attributes.timestamp)) | ||
delete xml.root.children[0].attributes.timestamp | ||
t.deepEqual(xml.root.children, [ | ||
@@ -299,0 +309,0 @@ { |
@@ -376,4 +376,2 @@ var test = require('tape') | ||
console.log('data', json.toString()) | ||
// Ensure the way present matches the deleted fork, and the extra node | ||
@@ -398,3 +396,3 @@ // is not returned. | ||
node.changeset = changesetId | ||
node.timestamp = new Date().getTime() | ||
node.timestamp = (new Date()).toISOString() | ||
osm.create(node, function (err, key) { | ||
@@ -424,3 +422,3 @@ if (err) return done(err) | ||
changeset: changesetId, | ||
timestamp: new Date().getTime() | ||
timestamp: (new Date()).toISOString() | ||
}, function (err, key, node) { | ||
@@ -437,3 +435,3 @@ done(err, key, node.key) | ||
changeset: changesetId, | ||
timestamp: new Date().getTime() | ||
timestamp: (new Date()).toISOString() | ||
}, | ||
@@ -440,0 +438,0 @@ { links: [parentId] }, |
@@ -6,2 +6,3 @@ var test = require('tape') | ||
var concat = require('concat-stream') | ||
var isISODate = require('isostring') | ||
@@ -125,3 +126,48 @@ var base | ||
test('history route', function (t) { | ||
t.plan(5) | ||
t.plan(8) | ||
var expected = [ | ||
{ | ||
name: 'node', | ||
attributes: { | ||
changeset: changesets[2], | ||
id: ids.A, | ||
lat: '64.2', | ||
lon: '-121.4', | ||
version: versions.A[2] | ||
}, | ||
children: [ | ||
{ | ||
name: 'tag', | ||
attributes: { | ||
k: 'beep', | ||
v: 'boop' | ||
}, | ||
children: [] | ||
} | ||
], | ||
content: '' | ||
}, | ||
{ | ||
name: 'node', | ||
attributes: { | ||
changeset: changesets[1], | ||
id: ids.A, | ||
lat: '64.3', | ||
lon: '-121.4', | ||
version: versions.A[1] | ||
}, | ||
children: [] | ||
}, | ||
{ | ||
name: 'node', | ||
attributes: { | ||
changeset: changesets[0], | ||
id: ids.A, | ||
lat: '64.5', | ||
lon: '-121.5', | ||
version: versions.A[0] | ||
}, | ||
children: [] | ||
} | ||
] | ||
var hq = hyperquest(base + 'node/' + ids.A + '/history', { | ||
@@ -139,47 +185,7 @@ headers: { 'content-type': 'text/xml' } | ||
t.equal(xml.root.name, 'osm') | ||
t.deepEqual(xml.root.children, [ | ||
{ | ||
name: 'node', | ||
attributes: { | ||
changeset: changesets[2], | ||
id: ids.A, | ||
lat: '64.2', | ||
lon: '-121.4', | ||
version: versions.A[2] | ||
}, | ||
children: [ | ||
{ | ||
name: 'tag', | ||
attributes: { | ||
k: 'beep', | ||
v: 'boop' | ||
}, | ||
children: [] | ||
} | ||
], | ||
content: '' | ||
}, | ||
{ | ||
name: 'node', | ||
attributes: { | ||
changeset: changesets[1], | ||
id: ids.A, | ||
lat: '64.3', | ||
lon: '-121.4', | ||
version: versions.A[1] | ||
}, | ||
children: [] | ||
}, | ||
{ | ||
name: 'node', | ||
attributes: { | ||
changeset: changesets[0], | ||
id: ids.A, | ||
lat: '64.5', | ||
lon: '-121.5', | ||
version: versions.A[0] | ||
}, | ||
children: [] | ||
} | ||
]) | ||
xml.root.children.forEach(function (c) { | ||
t.true(isISODate(c.attributes.timestamp)) | ||
delete c.attributes.timestamp | ||
}) | ||
t.deepEqual(xml.root.children, expected) | ||
})) | ||
@@ -186,0 +192,0 @@ }) |
@@ -36,1 +36,79 @@ var test = require('tape') | ||
}) | ||
test('cmpFork latest first', t => { | ||
var input = [{ | ||
id: 1, | ||
timestamp: '2017-01-14T16:43:38.968Z', | ||
version: 'b' | ||
}, { | ||
id: 2, | ||
timestamp: '2017-01-14T16:43:36.100Z', | ||
version: 'a' | ||
}] | ||
t.equal(input.sort(util.cmpFork)[0].id, 1) | ||
t.end() | ||
}) | ||
test('cmpFork latest last', t => { | ||
var input = [{ | ||
id: 1, | ||
timestamp: '2017-01-14T16:43:36.100Z', | ||
version: 'b' | ||
}, { | ||
id: 2, | ||
timestamp: '2017-01-14T16:43:38.968Z', | ||
version: 'a' | ||
}] | ||
t.equal(input.sort(util.cmpFork)[0].id, 2) | ||
t.end() | ||
}) | ||
test('cmpFork only first has timestamp', t => { | ||
var input = [{ | ||
id: 1, | ||
timestamp: '2017-01-14T16:43:36.100Z', | ||
version: 'b' | ||
}, { | ||
id: 2, | ||
version: 'a' | ||
}] | ||
t.equal(input.sort(util.cmpFork)[0].id, 1) | ||
t.end() | ||
}) | ||
test('cmpFork only second has timestamp', t => { | ||
var input = [{ | ||
id: 1, | ||
version: 'b' | ||
}, { | ||
id: 2, | ||
timestamp: '2017-01-14T16:43:36.100Z', | ||
version: 'a' | ||
}] | ||
t.equal(input.sort(util.cmpFork)[0].id, 2) | ||
t.end() | ||
}) | ||
test('cmpFork no timestamps (use version)', t => { | ||
var input = [{ | ||
id: 1, | ||
version: 'b' | ||
}, { | ||
id: 2, | ||
version: 'a' | ||
}] | ||
t.equal(input.sort(util.cmpFork)[0].id, 2) | ||
t.end() | ||
}) | ||
test('cmpFork no timestamps (use version)', t => { | ||
var input = [{ | ||
id: 2, | ||
version: 'a' | ||
}, { | ||
id: 1, | ||
version: 'b' | ||
}] | ||
t.equal(input.sort(util.cmpFork)[0].id, 2) | ||
t.end() | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
203326
5844