osm-p2p-server
Advanced tools
Comparing version 1.12.3 to 2.0.0-beta
@@ -13,29 +13,28 @@ #!/usr/bin/env node | ||
}) | ||
if (argv.help || argv._[0] === 'help') return usage(0) | ||
var osmdb = require('osm-p2p') | ||
var osm = osmdb(argv.datadir) | ||
var osmrouter = require('../') | ||
var router = osmrouter(osm) | ||
var version = require('../package.json').version | ||
var http = require('http') | ||
var server = http.createServer(function (req, res) { | ||
if (router.handle(req, res)) {} | ||
else if (req.url === '/') { | ||
res.end('osm-p2p-server ' + version + '\n') | ||
} else { | ||
res.statusCode = 404 | ||
res.end('not found\n') | ||
} | ||
}) | ||
server.listen(argv.port, function () { | ||
console.log('http://127.0.0.1:' + server.address().port) | ||
console.log('database location: ' + path.resolve(argv.datadir)) | ||
}) | ||
function usage (code) { | ||
if (argv.help || argv._[0] === 'help') { | ||
var r = fs.createReadStream(path.join(__dirname, 'usage.txt')) | ||
if (code) r.once('end', function () { process.exit(code) }) | ||
r.once('end', function () { process.exit(0) }) | ||
r.pipe(process.stdout) | ||
} else { | ||
var osmdb = require('osm-p2p') | ||
var osm = osmdb(argv.datadir) | ||
var osmrouter = require('../') | ||
var router = osmrouter(osm) | ||
var version = require('../package.json').version | ||
var http = require('http') | ||
var server = http.createServer(function (req, res) { | ||
if (router.handle(req, res)) { | ||
} else if (req.url === '/') { | ||
res.end('osm-p2p-server ' + version + '\n') | ||
} else { | ||
res.statusCode = 404 | ||
res.end('not found\n') | ||
} | ||
}) | ||
server.listen(argv.port, function () { | ||
console.log('http://127.0.0.1:' + server.address().port) | ||
console.log('database location: ' + path.resolve(argv.datadir)) | ||
}) | ||
} |
@@ -5,6 +5,27 @@ # Change Log | ||
## [1.12.3] - 2016-08-18 | ||
## [Unreleased] | ||
### Added | ||
- Add `timestamp` to newly created elements. | ||
- Add `created_at` timestamp to new changesets. | ||
- Use as Expresss.js middleware | ||
### Changed | ||
- **BREAKING** (Possibly): Empty nodes in returned xml are self-closing tags rather than empty e.g. `<node id="1" />` vs `<node id="1"></node>`. This matches OSM Ruby Port, and is likely not breaking but it did break our tests. | ||
- **BREAKING**: Closed changesets now have attribute `created_at` rather than `createdAt` to be consistent with OSM API. Still checks for `createdAt` in legacy dbs. | ||
- **BREAKING**: Only most recent fork is returned on `GET /:type(node|way|relation)/:id`, unless `?forks=true` query param is set. | ||
- **BREAKING**: Only most recent forks are returned on `GET /:type(nodes|ways|relations)\\?:ktype=:ids`, unless `?forks=true` query param is set. | ||
- **BREAKING**: Only most recent forks are returned of elements in `GET /map`, unless `?forks=true` query param is set. | ||
- **BREAKING**: Routes no longer start with `/api/0.6/`, routes are now mounted on `/` | ||
- Error messages should be more consistent | ||
- More robust XML parsing | ||
### Fixed | ||
- double-check membership in reference count calculation of ifUnused delete. | ||
Previously, this could make it impossible to delete some points. | ||
- Always set xml content-encoding to utf-8 (Very important since the default charset is ISO-8859-1 see http://www.w3.org/International/articles/http-charset/index) | ||
- Set headers content-encoding: identity and no-cache for all routes | ||
- Correctly parse `id` for closing a forked changeset. | ||
- `members` and `nodes` are returned before `tags` in Xml. | ||
- Delete operations must have changeset attribute set. | ||
### Removed | ||
[Unreleased]: https://github.com/digidem/osm-p2p-server/compare/1.12.2...HEAD |
@@ -21,4 +21,4 @@ var level = require('level') | ||
var server = http.createServer(function (req, res) { | ||
if (router.handle(req, res)) {} | ||
else { | ||
if (router.handle(req, res)) { | ||
} else { | ||
res.statusCode = 404 | ||
@@ -25,0 +25,0 @@ res.end('not found\n') |
@@ -9,4 +9,4 @@ var osmdb = require('osm-p2p') | ||
var server = http.createServer(function (req, res) { | ||
if (router.handle(req, res)) {} | ||
else { | ||
if (router.handle(req, res)) { | ||
} else { | ||
res.statusCode = 404 | ||
@@ -13,0 +13,0 @@ res.end('not found\n') |
32
index.js
@@ -1,3 +0,7 @@ | ||
var router = require('./lib/routes.js') | ||
var error = require('debug')('osm-p2p-server:error') | ||
var errors = require('./errors') | ||
var router = require('./routes') | ||
var createApi = require('./api') | ||
module.exports = Server | ||
@@ -8,3 +12,3 @@ | ||
var self = this | ||
self.osmdb = osmdb | ||
self.api = createApi(osmdb) | ||
self.router = router | ||
@@ -17,10 +21,30 @@ } | ||
Server.prototype.handle = function (req, res) { | ||
Server.prototype.handle = function (req, res, next) { | ||
var method = req.headers.x_http_method_override || req.method | ||
var m = this.match(method, req.url) | ||
if (m) { | ||
m.fn(req, res, this.osmdb, m) | ||
res.setHeader('content-encoding', 'identity') | ||
res.setHeader('cache-control', 'no-cache') | ||
m.fn(req, res, this.api, m.params, handleError) | ||
return m | ||
} | ||
if (typeof next === 'function') next() | ||
return null | ||
function handleError (err) { | ||
// If used as middleware, fallthrough | ||
if (typeof next === 'function') return next(err) | ||
if (!err) return | ||
if (!err.status || !err.statusCode) { | ||
err = errors(err) | ||
} | ||
if (err.expose && !res.headersSent) { | ||
res.statusCode = err.status | ||
res.setHeader('content-type', 'text/plain') | ||
res.end(err.message + '\n') | ||
} else { | ||
res.end() | ||
} | ||
error(err) | ||
} | ||
} |
@@ -15,4 +15,5 @@ // work-around for bug elsewhere where ways and relations | ||
osm.get(ref, function (err, docs) { | ||
if (err) return next(err) | ||
if (Object.keys(docs).length > 0) nrefs[i] = ref | ||
//else console.log('SKIP', ref) | ||
else console.log('SKIP', ref) | ||
if (--pending === 0) done() | ||
@@ -25,4 +26,5 @@ }) | ||
osm.get(m.ref, function (err, doc) { | ||
if (err) return next(err) | ||
if (Object.keys(doc).length > 0) nmembers[i] = m | ||
//else console.log('SKIP', m.ref) | ||
else console.log('SKIP', m.ref) | ||
if (--pending === 0) done() | ||
@@ -29,0 +31,0 @@ }) |
@@ -10,3 +10,3 @@ module.exports = function h (tag, attr, children) { | ||
var open = '<' + tag.replace(/[\/!]$/,'') | ||
var open = '<' + tag.replace(/[\/!]$/, '') | ||
var kattr = Object.keys(attr) | ||
@@ -18,8 +18,8 @@ if (kattr.length) { | ||
} | ||
if (/\/$/.test(tag)) { // self-closing | ||
return open + '/>' | ||
} else if (/^\?/.test(tag)) { | ||
if (/^\?/.test(tag)) { | ||
return open + '?>' + children.join('') | ||
} else if (/!$/.test(tag)) { | ||
return open + '>' + children.join('') | ||
} else if (!children.length) { // self-closing | ||
return open + '/>' | ||
} else { | ||
@@ -26,0 +26,0 @@ return open + '>' + children.join('') + '</' + tag + '>' |
{ | ||
"name": "osm-p2p-server", | ||
"version": "1.12.3", | ||
"version": "2.0.0-beta", | ||
"description": "serve osm http endpoints over a p2p db", | ||
@@ -16,27 +16,37 @@ "main": "index.js", | ||
"author": "substack", | ||
"license": "BSD", | ||
"license": "BSD-2-Clause", | ||
"dependencies": { | ||
"base-convertor": "^1.1.0", | ||
"body": "^5.1.0", | ||
"collect-stream": "^1.1.1", | ||
"concat-stream": "^1.5.1", | ||
"has": "^1.0.1", | ||
"content-type": "^1.0.2", | ||
"debug": "^2.2.0", | ||
"from2-array": "0.0.4", | ||
"inherits": "^2.0.1", | ||
"minimist": "^1.2.0", | ||
"obj2osm": "^2.0.0", | ||
"once": "^1.3.3", | ||
"osm-p2p-xml": "^1.0.1", | ||
"osm2json": "^2.1.0", | ||
"pumpify": "^1.3.5", | ||
"query-string": "^4.2.2", | ||
"randombytes": "^2.0.2", | ||
"read-only-stream": "^2.0.0", | ||
"readable-stream": "^2.1.4", | ||
"routes": "^2.1.0", | ||
"sax": "^1.2.1", | ||
"statuses": "^1.3.0", | ||
"through2": "^2.0.1", | ||
"xml-parser": "^1.2.1", | ||
"through2-map": "github:gmaclennan/through2-map", | ||
"xtend": "^4.0.1" | ||
}, | ||
"devDependencies": { | ||
"express": "^4.14.0", | ||
"fd-chunk-store": "^2.0.0", | ||
"hyperlog": "^4.10.0", | ||
"hyperquest": "^2.0.0", | ||
"isostring": "0.0.1", | ||
"memdb": "^1.3.1", | ||
"osm-p2p": "^1.4.0", | ||
"osm-p2p-db": "^3.9.1", | ||
"tape": "^4.4.0" | ||
"standard": "^8.0.0", | ||
"tape": "^4.4.0", | ||
"xml-parser": "^1.2.1" | ||
}, | ||
@@ -47,3 +57,4 @@ "directories": { | ||
"scripts": { | ||
"test": "tape test/*.js" | ||
"test": "tape 'test/**/*.js'", | ||
"lint": "standard" | ||
}, | ||
@@ -50,0 +61,0 @@ "repository": { |
167
README.md
@@ -0,15 +1,104 @@ | ||
# osm-p2p-server | ||
[![Build Status](https://img.shields.io/travis/digidem/osm-p2p-server.svg)](https://travis-ci.org/digidem/osm-p2p-server) | ||
[![npm](https://img.shields.io/npm/v/osm-p2p-server.svg?maxAge=2592000)](https://www.npmjs.com/package/osm-p2p-server) | ||
[![npm](https://img.shields.io/npm/v/osm-p2p-server.svg)](https://www.npmjs.com/package/osm-p2p-server) | ||
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?maxAge=2592000)](http://standardjs.com/) | ||
# osm-p2p-server | ||
> Peer-to-peer [OpenStreetMap API v0.6][1] Server | ||
serve [open street map 0.6](http://wiki.openstreetmap.org/wiki/API_v0.6) | ||
api endpoints over a local p2p http server | ||
[1]: http://wiki.openstreetmap.org/wiki/API_v0.6 | ||
This package is available as a library you can use from node.js (or if you are | ||
creative, also the browser) or as a standalone command. | ||
An implementation of the [OpenStreetMap API v0.6][1] for [`osm-p2p-db`](https://www.npmjs.com/package/osm-p2p-db), a peer-to-peer OSM database. It runs on [node.js](https://nodejs.org/) or, if you are creative, also in the browser. Data is stored in a [LevelUP](https://github.com/Level/levelup) database. There is no need to set up a database, everything you need to get started is available as a single package that you can [install from npm](#install). | ||
# api example | ||
`osm-p2p-server` is tested and working with [iD Editor](https://github.com/openstreetmap/iD) - it appears as identical to the standard [OSM API][1]. It should theoretically work in the future with other editors such as [JOSM](https://josm.openstreetmap.de) but `osm-p2p-server` needs to use at least 64-bit ids to avoid collisions, and JOSM currently still uses 32-bit integers for some ids, such as changeset ids and version numbers. | ||
`osm-p2p-server` is designed to run locally on each client. Synchronize data between clients by [replicating the `osm-p2p-db` database](https://github.com/digidem/osm-p2p-db#replication). You can implement replication over wifi, bluetooth or via USB thumb drives (examples coming soon). | ||
This module is for developers who want to build their own OSM tools. For users who want a one-click install of `osm-p2p-server` with iD Editor see [Mapeo Desktop](https://github.com/digidem/mapeo-desktop). | ||
## Table of Contents | ||
- [Install](#install) | ||
- [Usage](#usage) | ||
- [Routes](#routes) | ||
- [API](#api) | ||
- [REST API](#rest-api) | ||
- [Differences to OSM API v0.6](#differences-to-osm-api-v06) | ||
- [Contribute](#contribute) | ||
- [License](#license) | ||
## Install | ||
You will need to first [install node.js](https://nodejs.org/en/) | ||
``` | ||
npm install osm-p2p-server | ||
``` | ||
## Usage | ||
``` | ||
usage: osm-p2p-server {OPTIONS} | ||
-h --help Show this message | ||
-p --port Listen on a port. Default: 5000 | ||
-d --datadir Store data in this directory. Default: ./osm-p2p.db | ||
``` | ||
## Routes | ||
`osm-p2p-server` currently implements the following routes from the [OSM API v0.6][1]: | ||
- [x] `GET /capabilities` | ||
- [x] `GET /map` | ||
- [x] `PUT /changeset/create` | ||
- [x] `POST /changeset/:id/upload` | ||
- [x] `PUT /changeset/:id/close` | ||
- [x] `GET /map` | ||
- [x] `GET /:type(nodes|ways|relations)?:ktype(nodes|ways|relations)=:ids` | ||
- [x] `GET /:type(node|way|relation)/:id` | ||
- [x] `GET /:type(node|way|relation)/:id/:version` | ||
- [x] `GET /:type(node|way|relation)/:id` | ||
- [x] `GET /:type(node|way|relation)/:id/history` | ||
- [ ] `GET /:type(way|relation)/:id/full` | ||
## API | ||
``` js | ||
var osmrouter = require('osm-p2p-server') | ||
``` | ||
### var router = osmrouter(osm) | ||
Create a new OpenStreetMap `router` given an | ||
[`osm-p2p-db`](https://npmjs.com/package/osm-p2p-db) handle `osm`. | ||
### var m = router.handle(req, res) | ||
Match the `req.method` and `req.url` and dispatch `m.fn(m, req, res)` and return | ||
the match object if there is a match, or else `null`. | ||
### var m = router.match(method, url) | ||
Return a match object `m` if `method` and `url` can be handled by the server. | ||
Used internally by `router.handle()`. | ||
The match object for `router.match('GET', '/node/1234')` would be: | ||
```js | ||
{ | ||
params: { | ||
type: 'node', | ||
id: '1234', | ||
}, | ||
splats: [], | ||
route: '/:type(node|way|relation)/:id', | ||
fn: [Function], | ||
next: [Function] | ||
} | ||
``` | ||
### API Example | ||
```js | ||
var osmdb = require('osm-p2p') | ||
@@ -32,47 +121,53 @@ var osm = osmdb('/tmp/osm-p2p') | ||
# usage | ||
### Use as Express middleware | ||
``` | ||
usage: osm-p2p-server {OPTIONS} | ||
```js | ||
var osmdb = require('osm-p2p') | ||
var express = require('express') | ||
-h --help Show this message | ||
-p --port Listen on a port. Default: 5000 | ||
-d --datadir Store data in this directory. Default: ./osm-p2p.db | ||
var osmRouter = require('../') | ||
``` | ||
var app = express() | ||
var osm = osmdb('/tmp/osm-p2p') | ||
# api | ||
app.use('/api/0.6', osmRouter(osm)) | ||
``` js | ||
var osmrouter = require('osm-p2p-server') | ||
app.use(function handleError (err, req, res, next) { | ||
if (!err) return | ||
if (!res.headersSent) { | ||
res.statusCode = err.status || err.statusCode || 500 | ||
res.setHeader('content-type', 'text/plain') | ||
res.end(err.message + '\n') | ||
} else { | ||
next(err) | ||
} | ||
}) | ||
app.listen(5000, function () { | ||
console.log('osm-p2p-server listening on port 5000!') | ||
}) | ||
``` | ||
## var router = osmrouter(osm) | ||
## REST API | ||
Create a new open street maps server `router` given an | ||
[osm-p2p-db](https://npmjs.com/package/osm-p2p-db) handle `osm`. | ||
See the documentation for the [OSM API v0.6][1] - `osm-p2p-server` replicates that API as faithfully as possible. | ||
## var m = router.match(method, url) | ||
## Differences to OSM API v0.6 | ||
Return a match object `m` if `method` and `url` can be handled by the server. | ||
The main differences to the OSM API v0.6 are related to the peer-to-peer architecture of `osm-p2p-server`. Ids are randomly generated, rather than sequential integers. Version ids are hashes rather than integers. For more details read [`osm-p2p-db` Architecture](https://github.com/digidem/osm-p2p-db/blob/master/doc/architecture.markdown). | ||
## var m = router.handle(req, res) | ||
- If two users edit the same version of an entity (node|way|relation) then two versions will exist in the database. `osm-p2p-server` will not return `409: Conflict` if you try to modify or delete an entity which is not the most recent version, it will create a fork instead. Forks can be created if two users edit the same entity whilst disconnected and then later replicate the database. | ||
Match the `req.method` and `req.url` and dispatch `m.fn(m, req, res)` and return | ||
the match object if there is a match. | ||
- By default `osm-p2p-server` will only return the most recent 'fork', to maintain compatibility with tools that do not understand the concept of forked entities. To see all forks, append `?forks=true` to the URL and if multiple forks exist the returned data will include multiple entities with the same `id`, but different `version` ids. | ||
# differences | ||
- In changeset uploads (`/changeset/:id/upload`), the `version` property of each entity in the changeset | ||
can be a comma-separated list of version hashes of the documents that the update will replace. | ||
Use this to merge multiple forks into a single fork. | ||
In changeset uploads (`/api/0.6/changeset/:id/upload`), the `version` property | ||
refers to a comma-separated list of version hashes of the documents that the | ||
update will replace. | ||
## Contributing | ||
# install | ||
If something does not work as it should, please open an [Issue](/issues). [Pull Requests](/pulls) are welcome, please follow [JS Standard Style](http://standardjs.com/). | ||
``` | ||
npm install osm-p2p-server | ||
``` | ||
## License | ||
# license | ||
BSD | ||
[BSD (c) 2016 Digital Democracy](/LICENSE) |
var test = require('tape') | ||
var tmpdir = require('os').tmpdir() | ||
var path = require('path') | ||
var osmrouter = require('../') | ||
var http = require('http') | ||
var osmdb = require('osm-p2p-db') | ||
var parsexml = require('xml-parser') | ||
var memdb = require('memdb') | ||
var hyperlog = require('hyperlog') | ||
var fdstore = require('fd-chunk-store') | ||
var hyperquest = require('hyperquest') | ||
var mkdirp = require('mkdirp') | ||
var concat = require('concat-stream') | ||
var EventEmitter = require('events').EventEmitter | ||
var base, server, changeId | ||
test('setup bbox server', function (t) { | ||
var dir = path.join(tmpdir, 'osm-p2p-server-test-' + Math.random()) | ||
mkdirp.sync(dir) | ||
var createServer = require('./test_server.js') | ||
var db = memdb() | ||
var slowdb = new EventEmitter | ||
slowdb.setMaxListeners(Infinity) | ||
slowdb.db = {} | ||
slowdb.db.get = function (key, opts, cb) { | ||
setTimeout(function () { | ||
db.db.get(key, opts, cb) | ||
}, Math.random() * 100) | ||
} | ||
slowdb.db.put = db.db.put.bind(db.db) | ||
slowdb.db.del = db.db.del.bind(db.db) | ||
slowdb.db.batch = db.db.batch.bind(db.db) | ||
slowdb.db.iterator = db.db.iterator.bind(db.db) | ||
slowdb.get = db.get.bind(db) | ||
slowdb.put = db.put.bind(db) | ||
slowdb.del = db.del.bind(db) | ||
slowdb.batch = db.batch.bind(db) | ||
slowdb.createReadStream = db.createReadStream.bind(db) | ||
slowdb.isOpen = db.isOpen.bind(db) | ||
db.on('open', slowdb.emit.bind(slowdb, 'open')) | ||
var osm = osmdb({ | ||
db: slowdb, | ||
log: hyperlog(memdb(), { valueEncoding: 'json' }), | ||
store: fdstore(4096, path.join(dir, 'kdb')) | ||
}) | ||
var router = osmrouter(osm) | ||
server = http.createServer(function (req, res) { | ||
if (router.handle(req, res)) {} | ||
else { | ||
res.statusCode = 404 | ||
res.end('not found\n') | ||
} | ||
}) | ||
server.listen(0, function () { | ||
var port = server.address().port | ||
base = 'http://localhost:' + port + '/api/0.6/' | ||
test('bbox_order.js: setup server', function (t) { | ||
createServer(function (d) { | ||
base = d.base | ||
server = d.server | ||
t.end() | ||
@@ -78,3 +32,3 @@ }) | ||
})) | ||
hq.end(`<osm><changeset></changeset></osm>`) | ||
hq.end('<osm><changeset></changeset></osm>') | ||
}) | ||
@@ -90,5 +44,5 @@ | ||
type: 'node', | ||
id: 0-i-1, | ||
lat: 64 + i/SIZE, | ||
lon: -121 - i/SIZE, | ||
id: 0 - i - 1, | ||
lat: 64 + i / SIZE, | ||
lon: -121 - i / SIZE, | ||
changeset: changeId | ||
@@ -99,3 +53,3 @@ }) | ||
type: 'way', | ||
id: '${0-i-1}', | ||
id: 0 - i - 1, | ||
changeset: changeId, | ||
@@ -105,4 +59,4 @@ refs: docs.map(function (d, i) { return 0 - (i + 1) }) | ||
var kdocs = {} | ||
docs.forEach(function (doc,i) { | ||
kdocs[0-i-1] = doc | ||
docs.forEach(function (doc, i) { | ||
kdocs[0 - i - 1] = doc | ||
}) | ||
@@ -116,3 +70,3 @@ | ||
t.equal(res.statusCode, 200) | ||
t.equal(res.headers['content-type'].split(/\s*;\s*/)[0], 'text/xml') | ||
t.equal(res.headers['content-type'], 'text/xml; charset=utf-8') | ||
}) | ||
@@ -124,3 +78,3 @@ hq.pipe(concat({ encoding: 'string' }, function (body) { | ||
var id = node.attributes.new_id | ||
uploaded[id] = kdocs[0-i-1] | ||
uploaded[id] = kdocs[0 - i - 1] | ||
uploaded[id].id = id | ||
@@ -151,3 +105,3 @@ if (node.name === 'way') { | ||
test('bbox', function (t) { | ||
t.plan(6 + SIZE*3) | ||
t.plan(6 + SIZE * 3) | ||
var href = base + 'map?bbox=-123,63,-120,66' | ||
@@ -163,3 +117,2 @@ var hq = hyperquest(href) | ||
t.equal(xml.root.children[0].name, 'bounds') | ||
var ui = 0 | ||
for (var i = 1; i < xml.root.children.length; i++) { | ||
@@ -182,5 +135,5 @@ var c = xml.root.children[i] | ||
test('teardown bbox server', function (t) { | ||
server.close() | ||
test('bbox_order.js: teardown server', function (t) { | ||
server.cleanup() | ||
t.end() | ||
}) |
var test = require('tape') | ||
var tmpdir = require('os').tmpdir() | ||
var path = require('path') | ||
var osmrouter = require('../') | ||
var http = require('http') | ||
var osmdb = require('osm-p2p') | ||
var parsexml = require('xml-parser') | ||
@@ -11,18 +6,10 @@ var hyperquest = require('hyperquest') | ||
var createServer = require('./test_server.js') | ||
var base, server, changeId | ||
test('setup bbox server', function (t) { | ||
var osm = osmdb(path.join(tmpdir, 'osm-p2p-server-test-' + Math.random())) | ||
var router = osmrouter(osm) | ||
server = http.createServer(function (req, res) { | ||
if (router.handle(req, res)) {} | ||
else { | ||
res.statusCode = 404 | ||
res.end('not found\n') | ||
} | ||
}) | ||
server.listen(0, function () { | ||
var port = server.address().port | ||
base = 'http://localhost:' + port + '/api/0.6/' | ||
test('bbox.js: setup changeset server', function (t) { | ||
createServer(function (d) { | ||
base = d.base | ||
server = d.server | ||
t.end() | ||
@@ -46,3 +33,3 @@ }) | ||
})) | ||
hq.end(`<osm><changeset></changeset></osm>`) | ||
hq.end('<osm><changeset></changeset></osm>') | ||
}) | ||
@@ -58,5 +45,5 @@ | ||
type: 'node', | ||
id: 0-i-1, | ||
lat: 64 + i/SIZE, | ||
lon: -121 - i/SIZE, | ||
id: 0 - i - 1, | ||
lat: 64 + i / SIZE, | ||
lon: -121 - i / SIZE, | ||
changeset: changeId | ||
@@ -67,3 +54,3 @@ }) | ||
type: 'way', | ||
id: '${0-i-1}', | ||
id: 0 - i - 1, | ||
changeset: changeId, | ||
@@ -73,4 +60,4 @@ refs: docs.map(function (d, i) { return 0 - (i + 1) }) | ||
var kdocs = {} | ||
docs.forEach(function (doc,i) { | ||
kdocs[0-i-1] = doc | ||
docs.forEach(function (doc, i) { | ||
kdocs[0 - i - 1] = doc | ||
}) | ||
@@ -84,3 +71,3 @@ | ||
t.equal(res.statusCode, 200) | ||
t.equal(res.headers['content-type'].split(/\s*;\s*/)[0], 'text/xml') | ||
t.equal(res.headers['content-type'], 'text/xml; charset=utf-8') | ||
}) | ||
@@ -92,3 +79,3 @@ hq.pipe(concat({ encoding: 'string' }, function (body) { | ||
var id = node.attributes.new_id | ||
uploaded[id] = kdocs[0-i-1] | ||
uploaded[id] = kdocs[0 - i - 1] | ||
uploaded[id].id = id | ||
@@ -119,3 +106,3 @@ if (node.name === 'way') { | ||
test('bbox', function (t) { | ||
t.plan(7 + SIZE*3) | ||
t.plan(7 + SIZE * 3) | ||
var href = base + 'map?bbox=-123,63,-120,66' | ||
@@ -135,3 +122,2 @@ var hq = hyperquest(href) | ||
var ui = 0 | ||
for (var i = 1; i < xml.root.children.length; i++) { | ||
@@ -154,4 +140,4 @@ var c = xml.root.children[i] | ||
test('teardown bbox server', function (t) { | ||
server.close() | ||
test('bbox.js: teardown server', function (t) { | ||
server.cleanup() | ||
t.end() | ||
@@ -163,5 +149,5 @@ }) | ||
for (var i = 1; i < types.length; i++) { | ||
if (order[types[i-1]] > order[types[i]]) return false | ||
if (order[types[i - 1]] > order[types[i]]) return false | ||
} | ||
return true | ||
} |
var test = require('tape') | ||
var request = require('http').request | ||
var tmpdir = require('os').tmpdir() | ||
var path = require('path') | ||
var osmrouter = require('../') | ||
var http = require('http') | ||
var osmdb = require('osm-p2p') | ||
var parsexml = require('xml-parser') | ||
@@ -12,15 +6,9 @@ var hyperquest = require('hyperquest') | ||
var createServer = require('./test_server.js') | ||
var port, server | ||
test('setup capabilities', function (t) { | ||
var osm = osmdb(path.join(tmpdir, 'osm-p2p-server-test-' + Math.random())) | ||
var router = osmrouter(osm) | ||
server = http.createServer(function (req, res) { | ||
if (router.handle(req, res)) {} | ||
else { | ||
res.statusCode = 404 | ||
res.end('not found\n') | ||
} | ||
}) | ||
server.listen(0, function () { | ||
test('capabilities.js: setup server', function (t) { | ||
createServer(function (d) { | ||
server = d.server | ||
port = server.address().port | ||
@@ -33,3 +21,3 @@ t.end() | ||
t.plan(1) | ||
hyperquest('http://localhost:' + port + '/api/capabilities') | ||
hyperquest('http://localhost:' + port + '/capabilities') | ||
.pipe(concat({ encoding: 'string' }, function (body) { | ||
@@ -41,5 +29,5 @@ var data = parsexml(body) | ||
test('teardown capabilities', function (t) { | ||
server.close() | ||
test('capabilities.js: teardown server', function (t) { | ||
server.cleanup() | ||
t.end() | ||
}) |
var test = require('tape') | ||
var request = require('http').request | ||
var tmpdir = require('os').tmpdir() | ||
var path = require('path') | ||
var osmrouter = require('../') | ||
var http = require('http') | ||
var osmdb = require('osm-p2p') | ||
var parsexml = require('xml-parser') | ||
var hyperquest = require('hyperquest') | ||
var concat = require('concat-stream') | ||
var parsexml = require('xml-parser') | ||
var createServer = require('./test_server.js') | ||
var base, server, changeId | ||
test('setup', function (t) { | ||
var osm = osmdb(path.join(tmpdir, 'osm-p2p-server-test-' + Math.random())) | ||
var router = osmrouter(osm) | ||
server = http.createServer(function (req, res) { | ||
if (router.handle(req, res)) {} | ||
else { | ||
res.statusCode = 404 | ||
res.end('not found\n') | ||
} | ||
}) | ||
server.listen(0, function () { | ||
var port = server.address().port | ||
base = 'http://localhost:' + port + '/api/0.6/' | ||
test('changeset_delete.js: setup server', function (t) { | ||
createServer(function (d) { | ||
base = d.base | ||
server = d.server | ||
t.end() | ||
@@ -54,5 +39,6 @@ }) | ||
var ids = {}, versions = {} | ||
var ids = {} | ||
var versions = {} | ||
test('add docs', function (t) { | ||
t.plan(4+6) | ||
t.plan(4 + 6) | ||
@@ -65,3 +51,3 @@ var href = base + 'changeset/' + changeId + '/upload' | ||
t.equal(res.statusCode, 200) | ||
t.equal(res.headers['content-type'].split(/\s*;\s*/)[0], 'text/xml') | ||
t.equal(res.headers['content-type'], 'text/xml; charset=utf-8') | ||
}) | ||
@@ -73,3 +59,3 @@ hq.pipe(concat({ encoding: 'string' }, function (body) { | ||
return c.attributes.old_id | ||
}).sort(), ['-1','-2','-3','-4','-5','-6']) | ||
}).sort(), ['-1', '-2', '-3', '-4', '-5', '-6']) | ||
xml.root.children.forEach(function (c) { | ||
@@ -111,8 +97,7 @@ ids[c.attributes.old_id] = c.attributes.new_id | ||
hq.pipe(concat({ encoding: 'string' }, function (body) { | ||
t.equal(body.trim(), | ||
'Node #'+ids['-1']+' is still used by way #'+ids['-4']+'.') | ||
t.true(body.includes('Element #' + ids['-1'] + ' is still used by element #' + ids['-4'] + '.')) | ||
})) | ||
hq.end(`<osmChange version="1.0" generator="acme osm editor"> | ||
<delete> | ||
<node id="${ids['-1']}"/> | ||
<node id="${ids['-1']}" changeset="${changeId}"/> | ||
</delete> | ||
@@ -138,4 +123,4 @@ </osmChange>`) | ||
<delete> | ||
<node id="${ids['-1']}"/> | ||
<way id="${ids['-4']}"></way> | ||
<node id="${ids['-1']}" changeset="${changeId}"/> | ||
<way id="${ids['-4']}" changeset="${changeId}"></way> | ||
</delete> | ||
@@ -161,4 +146,4 @@ </osmChange>`) | ||
<delete if-unused="1"> | ||
<node id="${ids['-3']}"/> | ||
<node id="${ids['-6']}"/> | ||
<node id="${ids['-3']}" changeset="${changeId}"/> | ||
<node id="${ids['-6']}" changeset="${changeId}"/> | ||
</delete> | ||
@@ -196,5 +181,5 @@ </osmChange>`) | ||
test('teardown changeset upload server', function (t) { | ||
server.close() | ||
test('changeset_delete.js: teardown server', function (t) { | ||
server.cleanup() | ||
t.end() | ||
}) |
var test = require('tape') | ||
var request = require('http').request | ||
var tmpdir = require('os').tmpdir() | ||
var path = require('path') | ||
var osmrouter = require('../') | ||
var http = require('http') | ||
var osmdb = require('osm-p2p') | ||
var parsexml = require('xml-parser') | ||
var hyperquest = require('hyperquest') | ||
var concat = require('concat-stream') | ||
var parsexml = require('xml-parser') | ||
var createServer = require('./test_server.js') | ||
var base, server, changeId | ||
test('setup changeset upload server', function (t) { | ||
var osm = osmdb(path.join(tmpdir, 'osm-p2p-server-test-' + Math.random())) | ||
var router = osmrouter(osm) | ||
server = http.createServer(function (req, res) { | ||
if (router.handle(req, res)) {} | ||
else { | ||
res.statusCode = 404 | ||
res.end('not found\n') | ||
} | ||
}) | ||
server.listen(0, function () { | ||
var port = server.address().port | ||
base = 'http://localhost:' + port + '/api/0.6/' | ||
test('changeset_placeholder.js: setup server', function (t) { | ||
createServer(function (d) { | ||
base = d.base | ||
server = d.server | ||
t.end() | ||
@@ -54,3 +39,4 @@ }) | ||
var ids = {}, versions = {} | ||
var ids = {} | ||
var versions = {} | ||
test('add docs to changeset upload', function (t) { | ||
@@ -65,3 +51,3 @@ t.plan(7) | ||
t.equal(res.statusCode, 200) | ||
t.equal(res.headers['content-type'].split(/\s*;\s*/)[0], 'text/xml') | ||
t.equal(res.headers['content-type'], 'text/xml; charset=utf-8') | ||
}) | ||
@@ -73,3 +59,3 @@ hq.pipe(concat({ encoding: 'string' }, function (body) { | ||
return c.attributes.old_id | ||
}).sort(), ['1','2','3']) | ||
}).sort(), ['1', '2', '3']) | ||
xml.root.children.forEach(function (c) { | ||
@@ -119,4 +105,3 @@ ids[c.attributes.old_id] = c.attributes.new_id | ||
}, | ||
children: [], | ||
content: '' | ||
children: [] | ||
}, | ||
@@ -132,4 +117,3 @@ { | ||
}, | ||
children: [], | ||
content: '' | ||
children: [] | ||
}, | ||
@@ -251,3 +235,3 @@ { | ||
t.equal(res.statusCode, 200) | ||
t.equal(res.headers['content-type'].split(/\s*;\s*/)[0], 'text/xml') | ||
t.equal(res.headers['content-type'], 'text/xml; charset=utf-8') | ||
}) | ||
@@ -294,3 +278,2 @@ var oldv, newv | ||
}, | ||
content: '', | ||
children: [] | ||
@@ -313,3 +296,2 @@ } | ||
}, | ||
content: '', | ||
children: [] | ||
@@ -321,4 +303,4 @@ } | ||
test('teardown changeset upload server', function (t) { | ||
server.close() | ||
test('changeset_placeholder.js: setup server', function (t) { | ||
server.cleanup() | ||
t.end() | ||
@@ -325,0 +307,0 @@ }) |
var test = require('tape') | ||
var request = require('http').request | ||
var tmpdir = require('os').tmpdir() | ||
var path = require('path') | ||
var osmrouter = require('../') | ||
var http = require('http') | ||
var osmdb = require('osm-p2p') | ||
var parsexml = require('xml-parser') | ||
var hyperquest = require('hyperquest') | ||
var concat = require('concat-stream') | ||
var parsexml = require('xml-parser') | ||
var base, server, changeId | ||
test('setup changeset upload server', function (t) { | ||
var osm = osmdb(path.join(tmpdir, 'osm-p2p-server-test-' + Math.random())) | ||
var router = osmrouter(osm) | ||
var createServer = require('./test_server.js') | ||
server = http.createServer(function (req, res) { | ||
if (router.handle(req, res)) {} | ||
else { | ||
res.statusCode = 404 | ||
res.end('not found\n') | ||
} | ||
}) | ||
server.listen(0, function () { | ||
var port = server.address().port | ||
base = 'http://localhost:' + port + '/api/0.6/' | ||
test('changeset_upload_relation.js: setup server', function (t) { | ||
createServer(function (d) { | ||
base = d.base | ||
server = d.server | ||
t.end() | ||
@@ -54,3 +39,4 @@ }) | ||
var ids = {}, versions = {} | ||
var ids = {} | ||
var versions = {} | ||
test('add docs to changeset upload', function (t) { | ||
@@ -65,3 +51,3 @@ t.plan(8) | ||
t.equal(res.statusCode, 200) | ||
t.equal(res.headers['content-type'].split(/\s*;\s*/)[0], 'text/xml') | ||
t.equal(res.headers['content-type'], 'text/xml; charset=utf-8') | ||
}) | ||
@@ -73,3 +59,3 @@ hq.pipe(concat({ encoding: 'string' }, function (body) { | ||
return c.attributes.old_id | ||
}).sort(), ['-1','-2','-3','-4']) | ||
}).sort(), ['-1', '-2', '-3', '-4']) | ||
xml.root.children.forEach(function (c) { | ||
@@ -92,3 +78,3 @@ ids[c.attributes.old_id] = c.attributes.new_id | ||
<tag k="hello" v="world" /> | ||
<member type="way" ref="-3" /> | ||
<member type="way" ref="-3" role="" /> | ||
</relation> | ||
@@ -124,4 +110,3 @@ </create> | ||
}, | ||
children: [], | ||
content: '' | ||
children: [] | ||
}, | ||
@@ -137,4 +122,3 @@ { | ||
}, | ||
children: [], | ||
content: '' | ||
children: [] | ||
}, | ||
@@ -173,3 +157,3 @@ { | ||
name: 'member', | ||
attributes: { type: 'way', ref: ids['-3'] }, | ||
attributes: { type: 'way', ref: ids['-3'], role: '' }, | ||
children: [] | ||
@@ -278,3 +262,3 @@ }, | ||
t.equal(res.statusCode, 200) | ||
t.equal(res.headers['content-type'].split(/\s*;\s*/)[0], 'text/xml') | ||
t.equal(res.headers['content-type'], 'text/xml; charset=utf-8') | ||
}) | ||
@@ -321,3 +305,2 @@ var oldv, newv | ||
}, | ||
content: '', | ||
children: [] | ||
@@ -340,3 +323,2 @@ } | ||
}, | ||
content: '', | ||
children: [] | ||
@@ -348,4 +330,4 @@ } | ||
test('teardown changeset upload server', function (t) { | ||
server.close() | ||
test('changeset_upload_relation.js: teardown server', function (t) { | ||
server.cleanup() | ||
t.end() | ||
@@ -359,3 +341,12 @@ }) | ||
function cmpref (a, b) { | ||
if (a.name === 'tag' && b.name !== 'tag') { | ||
return 1 | ||
} | ||
if (a.name !== 'tag' && b.name === 'tag') { | ||
return -1 | ||
} | ||
if (a.name === 'tag' && b.name === 'tag') { | ||
return a.attributes.k < b.attributes.tag ? -1 : 1 | ||
} | ||
return a.attributes.ref < b.attributes.ref ? -1 : 1 | ||
} |
var test = require('tape') | ||
var request = require('http').request | ||
var tmpdir = require('os').tmpdir() | ||
var path = require('path') | ||
var osmrouter = require('../') | ||
var http = require('http') | ||
var osmdb = require('osm-p2p') | ||
var parsexml = require('xml-parser') | ||
var hyperquest = require('hyperquest') | ||
var concat = require('concat-stream') | ||
var parsexml = require('xml-parser') | ||
var createServer = require('./test_server.js') | ||
var base, server, changeId | ||
test('setup changeset upload server', function (t) { | ||
var osm = osmdb(path.join(tmpdir, 'osm-p2p-server-test-' + Math.random())) | ||
var router = osmrouter(osm) | ||
server = http.createServer(function (req, res) { | ||
if (router.handle(req, res)) {} | ||
else { | ||
res.statusCode = 404 | ||
res.end('not found\n') | ||
} | ||
}) | ||
server.listen(0, function () { | ||
var port = server.address().port | ||
base = 'http://localhost:' + port + '/api/0.6/' | ||
test('changeset_upload.js: setup server', function (t) { | ||
createServer(function (d) { | ||
base = d.base | ||
server = d.server | ||
t.end() | ||
@@ -54,3 +39,4 @@ }) | ||
var ids = {}, versions = {} | ||
var ids = {} | ||
var versions = {} | ||
test('add docs to changeset upload', function (t) { | ||
@@ -65,3 +51,3 @@ t.plan(7) | ||
t.equal(res.statusCode, 200) | ||
t.equal(res.headers['content-type'].split(/\s*;\s*/)[0], 'text/xml') | ||
t.equal(res.headers['content-type'], 'text/xml; charset=utf-8') | ||
}) | ||
@@ -73,3 +59,3 @@ hq.pipe(concat({ encoding: 'string' }, function (body) { | ||
return c.attributes.old_id | ||
}).sort(), ['-1','-2','-3']) | ||
}).sort(), ['-1', '-2', '-3']) | ||
xml.root.children.forEach(function (c) { | ||
@@ -119,4 +105,3 @@ ids[c.attributes.old_id] = c.attributes.new_id | ||
}, | ||
children: [], | ||
content: '' | ||
children: [] | ||
}, | ||
@@ -132,4 +117,3 @@ { | ||
}, | ||
children: [], | ||
content: '' | ||
children: [] | ||
}, | ||
@@ -251,3 +235,3 @@ { | ||
t.equal(res.statusCode, 200) | ||
t.equal(res.headers['content-type'].split(/\s*;\s*/)[0], 'text/xml') | ||
t.equal(res.headers['content-type'], 'text/xml; charset=utf-8') | ||
}) | ||
@@ -294,3 +278,2 @@ var oldv, newv | ||
}, | ||
content: '', | ||
children: [] | ||
@@ -313,3 +296,2 @@ } | ||
}, | ||
content: '', | ||
children: [] | ||
@@ -321,4 +303,4 @@ } | ||
test('teardown changeset upload server', function (t) { | ||
server.close() | ||
test('changeset_upload.js: teardown server', function (t) { | ||
server.cleanup() | ||
t.end() | ||
@@ -325,0 +307,0 @@ }) |
var test = require('tape') | ||
var tmpdir = require('os').tmpdir() | ||
var path = require('path') | ||
var osmrouter = require('../') | ||
var http = require('http') | ||
var osmdb = require('osm-p2p') | ||
var parsexml = require('xml-parser') | ||
@@ -11,18 +6,10 @@ var hyperquest = require('hyperquest') | ||
var createServer = require('./test_server.js') | ||
var base, server, changeId | ||
test('setup changeset server', function (t) { | ||
var osm = osmdb(path.join(tmpdir, 'osm-p2p-server-test-' + Math.random())) | ||
var router = osmrouter(osm) | ||
server = http.createServer(function (req, res) { | ||
if (router.handle(req, res)) {} | ||
else { | ||
res.statusCode = 404 | ||
res.end('not found\n') | ||
} | ||
}) | ||
server.listen(0, function () { | ||
var port = server.address().port | ||
base = 'http://localhost:' + port + '/api/0.6/' | ||
test('changeset.js: setup server', function (t) { | ||
createServer(function (d) { | ||
base = d.base | ||
server = d.server | ||
t.end() | ||
@@ -88,3 +75,3 @@ }) | ||
t.ok(/^[0-9A-Fa-f]+$/.test(body.trim())) | ||
uploaded[doc.lon+','+doc.lat] = body.trim() | ||
uploaded[doc.lon + ',' + doc.lat] = body.trim() | ||
})) | ||
@@ -108,3 +95,3 @@ hq.end(`<osm> | ||
t.equal(res.statusCode, 200) | ||
t.equal(res.headers['content-type'].split(/\s*;\s*/)[0], 'text/xml') | ||
t.equal(res.headers['content-type'], 'text/xml; charset=utf-8') | ||
}) | ||
@@ -133,2 +120,5 @@ hq.pipe(concat({ encoding: 'string' }, function (body) { | ||
t.equal(xml.root.children[0].name, 'create') | ||
xml.root.children[0].children.forEach(function (c) { | ||
delete c.attributes.timestamp | ||
}) | ||
t.deepEqual(xml.root.children[0].children.sort(cmpch), [ | ||
@@ -144,4 +134,3 @@ { | ||
}, | ||
children: [], | ||
content: '' | ||
children: [] | ||
}, | ||
@@ -157,4 +146,3 @@ { | ||
}, | ||
children: [], | ||
content: '' | ||
children: [] | ||
} | ||
@@ -165,4 +153,4 @@ ].sort(cmpch)) | ||
test('teardown changeset server', function (t) { | ||
server.close() | ||
test('changeset.js: teardown server', function (t) { | ||
server.cleanup() | ||
t.end() | ||
@@ -169,0 +157,0 @@ }) |
var test = require('tape') | ||
var request = require('http').request | ||
var tmpdir = require('os').tmpdir() | ||
var path = require('path') | ||
var osmrouter = require('../') | ||
var http = require('http') | ||
var osmdb = require('osm-p2p') | ||
var parsexml = require('xml-parser') | ||
var hyperquest = require('hyperquest') | ||
var concat = require('concat-stream') | ||
var parsexml = require('xml-parser') | ||
var base, server, changeId | ||
test('setup', function (t) { | ||
var osm = osmdb(path.join(tmpdir, 'osm-p2p-server-test-' + Math.random())) | ||
var router = osmrouter(osm) | ||
var createServer = require('./test_server.js') | ||
server = http.createServer(function (req, res) { | ||
if (router.handle(req, res)) {} | ||
else { | ||
res.statusCode = 404 | ||
res.end('not found\n') | ||
} | ||
}) | ||
server.listen(0, function () { | ||
var port = server.address().port | ||
base = 'http://localhost:' + port + '/api/0.6/' | ||
test('delete.js: setup server', function (t) { | ||
createServer(function (d) { | ||
base = d.base | ||
server = d.server | ||
t.end() | ||
@@ -54,5 +39,6 @@ }) | ||
var ids = {}, versions = {} | ||
var ids = {} | ||
var versions = {} | ||
test('add docs', function (t) { | ||
t.plan(4+6) | ||
t.plan(4 + 6) | ||
@@ -65,3 +51,3 @@ var href = base + 'changeset/' + changeId + '/upload' | ||
t.equal(res.statusCode, 200) | ||
t.equal(res.headers['content-type'].split(/\s*;\s*/)[0], 'text/xml') | ||
t.equal(res.headers['content-type'], 'text/xml; charset=utf-8') | ||
}) | ||
@@ -73,3 +59,3 @@ hq.pipe(concat({ encoding: 'string' }, function (body) { | ||
return c.attributes.old_id | ||
}).sort(), ['-1','-2','-3','-4','-5','-6']) | ||
}).sort(), ['-1', '-2', '-3', '-4', '-5', '-6']) | ||
xml.root.children.forEach(function (c) { | ||
@@ -114,6 +100,5 @@ ids[c.attributes.old_id] = c.attributes.new_id | ||
hq.pipe(concat({ encoding: 'string' }, function (body) { | ||
t.equal(body.trim(), | ||
'Node #'+ids['-1']+' is still used by way #'+ids['-4']+'.') | ||
t.true(body.includes('Element #' + ids['-1'] + ' is still used by element #' + ids['-4'] + '.')) | ||
})) | ||
hq.end(`<osm><node id="${ids['-1']}"/></osm>`) | ||
hq.end(`<osm><node id="${ids['-1']}" changeset="${changeId}"/></osm>`) | ||
}) | ||
@@ -165,3 +150,3 @@ | ||
})) | ||
hq.end(`<osm><way id="${ids['-4']}"/></osm>`) | ||
hq.end(`<osm><way id="${ids['-4']}" changeset="${changeId}"/></osm>`) | ||
}) | ||
@@ -185,3 +170,3 @@ | ||
})) | ||
hq.end(`<osm><node id="${ids['-1']}"/></osm>`) | ||
hq.end(`<osm><node id="${ids['-1']}" changeset="${changeId}"/></osm>`) | ||
}) | ||
@@ -230,8 +215,8 @@ | ||
}) | ||
hq.end(`<osm><node id="${ids['-2']}"/></osm>`) | ||
hq.end(`<osm><node id="${ids['-2']} changeset="${changeId}""/></osm>`) | ||
}) | ||
test('teardown changeset upload server', function (t) { | ||
server.close() | ||
test('delete.js: teardown server', function (t) { | ||
server.cleanup() | ||
t.end() | ||
}) |
var test = require('tape') | ||
var request = require('http').request | ||
var tmpdir = require('os').tmpdir() | ||
var path = require('path') | ||
var osmrouter = require('../') | ||
var http = require('http') | ||
var osmdb = require('osm-p2p') | ||
var parsexml = require('xml-parser') | ||
var hyperquest = require('hyperquest') | ||
var concat = require('concat-stream') | ||
var parsexml = require('xml-parser') | ||
var base, server, changeId | ||
var base | ||
var server | ||
test('setup history server', function (t) { | ||
var osm = osmdb(path.join(tmpdir, 'osm-p2p-server-test-' + Math.random())) | ||
var router = osmrouter(osm) | ||
var createServer = require('./test_server.js') | ||
server = http.createServer(function (req, res) { | ||
if (router.handle(req, res)) {} | ||
else { | ||
res.statusCode = 404 | ||
res.end('not found\n') | ||
} | ||
}) | ||
server.listen(0, function () { | ||
var port = server.address().port | ||
base = 'http://localhost:' + port + '/api/0.6/' | ||
test('history.js: setup server', function (t) { | ||
createServer(function (d) { | ||
base = d.base | ||
server = d.server | ||
t.end() | ||
@@ -33,3 +19,5 @@ }) | ||
var ids = {}, versions = {}, changesets = [] | ||
var ids = {} | ||
var versions = {} | ||
var changesets = [] | ||
test('create history', function (t) { | ||
@@ -45,4 +33,3 @@ var updates = [ | ||
[ | ||
{ type: 'node', lat: 64.2, lon: -121.4, id: 'A', | ||
tags: { beep: 'boop' } } | ||
{ type: 'node', lat: 64.2, lon: -121.4, id: 'A', tags: { beep: 'boop' } } | ||
], | ||
@@ -54,3 +41,4 @@ [ | ||
t.plan(6 * updates.length) | ||
var exists = {}, versionId = {} | ||
var exists = {} | ||
var versionId = {} | ||
;(function next () { | ||
@@ -64,4 +52,3 @@ if (updates.length === 0) return | ||
t.equal(res.statusCode, 200, 'create 200 ok') | ||
t.equal(res.headers['content-type'].split(/\s*;\s*/)[0], | ||
'text/plain', 'create content type') | ||
t.equal(res.headers['content-type'], 'text/plain', 'create content type') | ||
}) | ||
@@ -83,4 +70,3 @@ hq.pipe(concat({ encoding: 'string' }, function (body) { | ||
t.equal(res.statusCode, 200, 'create 200 ok') | ||
t.equal(res.headers['content-type'].split(/\s*;\s*/)[0], | ||
'text/xml', 'upload content type') | ||
t.equal(res.headers['content-type'], 'text/xml; charset=utf-8', 'upload content type') | ||
}) | ||
@@ -93,3 +79,3 @@ hq.pipe(concat({ encoding: 'string' }, function (body) { | ||
if (/^-\d+/.test(c.attributes.old_id)) { | ||
key = update[-1-Number(c.attributes.old_id)].id | ||
key = update[-1 - Number(c.attributes.old_id)].id | ||
ids[key] = c.attributes.new_id | ||
@@ -117,3 +103,3 @@ versionId[c.attributes.new_id] = key | ||
function createMap (doc, i) { | ||
return `<node id="-${i+1}" | ||
return `<node id="-${i + 1}" | ||
lat="${doc.lat}" | ||
@@ -123,4 +109,4 @@ lon="${doc.lon}" | ||
>${Object.keys(doc.tags || {}).map(function (key) { | ||
return `<tag k="${key}" v="${doc.tags[key]}"/>` | ||
}).join('')} | ||
return `<tag k="${key}" v="${doc.tags[key]}"/>` | ||
}).join('')} | ||
</node>` | ||
@@ -133,4 +119,4 @@ } | ||
>${Object.keys(doc.tags || {}).map(function (key) { | ||
return `<tag k="${key}" v="${doc.tags[key]}"/>` | ||
}).join('')} | ||
return `<tag k="${key}" v="${doc.tags[key]}"/>` | ||
}).join('')} | ||
</node>` | ||
@@ -150,3 +136,3 @@ } | ||
t.equal(res.statusCode, 200) | ||
t.equal(res.headers['content-type'].split(/\s*;\s*/)[0], 'text/xml') | ||
t.equal(res.headers['content-type'], 'text/xml; charset=utf-8') | ||
}) | ||
@@ -187,4 +173,3 @@ hq.pipe(concat({ encoding: 'string' }, function (body) { | ||
}, | ||
children: [], | ||
content: '' | ||
children: [] | ||
}, | ||
@@ -200,4 +185,3 @@ { | ||
}, | ||
children: [], | ||
content: '' | ||
children: [] | ||
} | ||
@@ -208,5 +192,5 @@ ]) | ||
test('teardown changeset server', function (t) { | ||
server.close() | ||
test('history.js: teardown server', function (t) { | ||
server.cleanup() | ||
t.end() | ||
}) |
var test = require('tape') | ||
var request = require('http').request | ||
var tmpdir = require('os').tmpdir() | ||
var path = require('path') | ||
var osmrouter = require('../') | ||
var http = require('http') | ||
var osmdb = require('osm-p2p') | ||
var parsexml = require('xml-parser') | ||
var hyperquest = require('hyperquest') | ||
var concat = require('concat-stream') | ||
var parsexml = require('xml-parser') | ||
var base, server | ||
var base | ||
var server | ||
test('setup malformed-changeset upload server', function (t) { | ||
var osm = osmdb(path.join(tmpdir, 'osm-p2p-server-test-' + Math.random())) | ||
var router = osmrouter(osm) | ||
var createServer = require('./test_server.js') | ||
server = http.createServer(function (req, res) { | ||
if (router.handle(req, res)) {} | ||
else { | ||
res.statusCode = 404 | ||
res.end('not found\n') | ||
} | ||
}) | ||
server.listen(0, function () { | ||
var port = server.address().port | ||
base = 'http://localhost:' + port + '/api/0.6/' | ||
test('malformed_changeset.js: setup server', function (t) { | ||
createServer(function (d) { | ||
base = d.base | ||
server = d.server | ||
t.end() | ||
@@ -52,5 +37,5 @@ }) | ||
test('teardown malformed-changeset upload server', function (t) { | ||
server.close() | ||
test('malformed_changeset.js: teardown server', function (t) { | ||
server.cleanup() | ||
t.end() | ||
}) |
var test = require('tape') | ||
var request = require('http').request | ||
var tmpdir = require('os').tmpdir() | ||
var path = require('path') | ||
var osmrouter = require('../') | ||
var http = require('http') | ||
var osmdb = require('osm-p2p') | ||
var parsexml = require('xml-parser') | ||
var hyperquest = require('hyperquest') | ||
var concat = require('concat-stream') | ||
var parsexml = require('xml-parser') | ||
var base, server, changeId | ||
var base | ||
var server | ||
var changeId | ||
var createServer = require('./test_server.js') | ||
test('setup many-types server', function (t) { | ||
var osm = osmdb(path.join(tmpdir, 'osm-p2p-server-test-' + Math.random())) | ||
var router = osmrouter(osm) | ||
server = http.createServer(function (req, res) { | ||
if (router.handle(req, res)) {} | ||
else { | ||
res.statusCode = 404 | ||
res.end('not found\n') | ||
} | ||
}) | ||
server.listen(0, function () { | ||
var port = server.address().port | ||
base = 'http://localhost:' + port + '/api/0.6/' | ||
test('many_types.js: setup server', function (t) { | ||
createServer(function (d) { | ||
base = d.base | ||
server = d.server | ||
t.end() | ||
@@ -69,5 +55,7 @@ }) | ||
{ id: 'F', type: 'node', lat: 60.6, lon: -122.3, changeset: changeId }, | ||
{ id: 'G', type: 'way', refs: ['A','B','C'], changeset: changeId }, | ||
{ id: 'H', type: 'way', refs: ['D','E'], changeset: changeId }, | ||
{ id: 'I', type: 'relation', | ||
{ id: 'G', type: 'way', refs: ['A', 'B', 'C'], changeset: changeId }, | ||
{ id: 'H', type: 'way', refs: ['D', 'E'], changeset: changeId }, | ||
{ id: 'I', | ||
type: 'relation', | ||
changeset: changeId, | ||
members: [ | ||
@@ -77,4 +65,3 @@ { type: 'node', ref: 'F' }, | ||
{ type: 'way', ref: 'H' } | ||
], | ||
changeset: changeId | ||
] | ||
} | ||
@@ -106,3 +93,3 @@ ] | ||
t.ok(/^[0-9A-Fa-f]+$/.test(body.trim())) | ||
uploaded[doc.lon+','+doc.lat] = body.trim() | ||
uploaded[doc.lon + ',' + doc.lat] = body.trim() | ||
keys[key] = body.trim() | ||
@@ -142,3 +129,3 @@ next() | ||
t.equal(res.statusCode, 200) | ||
t.equal(res.headers['content-type'].split(/\s*;\s*/)[0], 'text/xml') | ||
t.equal(res.headers['content-type'], 'text/xml; charset=utf-8') | ||
}) | ||
@@ -153,3 +140,3 @@ hq.pipe(concat({ encoding: 'string' }, function (body) { | ||
}) | ||
t.deepEqual(xids, [keys.G,keys.H], 'id comparison') | ||
t.deepEqual(xids, [keys.G, keys.H], 'id comparison') | ||
})) | ||
@@ -166,3 +153,3 @@ }) | ||
t.equal(res.statusCode, 200) | ||
t.equal(res.headers['content-type'].split(/\s*;\s*/)[0], 'text/xml') | ||
t.equal(res.headers['content-type'], 'text/xml; charset=utf-8') | ||
}) | ||
@@ -177,5 +164,5 @@ hq.pipe(concat({ encoding: 'string' }, function (body) { | ||
t.deepEqual(members, [ | ||
{ name: 'member', attributes: { type: 'node', ref: keys.F } }, | ||
{ name: 'member', attributes: { type: 'way', ref: keys.G } } , | ||
{ name: 'member', attributes: { type: 'way', ref: keys.H } } | ||
{ name: 'member', attributes: { type: 'node', ref: keys.F, role: '' } }, | ||
{ name: 'member', attributes: { type: 'way', ref: keys.G, role: '' } }, | ||
{ name: 'member', attributes: { type: 'way', ref: keys.H, role: '' } } | ||
], 'relation members') | ||
@@ -196,7 +183,9 @@ })) | ||
t.equal(xml.root.children[0].name, 'create') | ||
xml.root.children[0].children.forEach(function (c) { | ||
delete c.attributes.timestamp | ||
}) | ||
t.deepEqual(chfilter(xml.root.children[0].children).sort(cmpch), [ | ||
{ name: 'node', | ||
attributes: { id: keys.A, changeset: changeId, lat: '64.5', lon: '-121.5' }, | ||
children: [], | ||
content: '' | ||
children: [] | ||
}, | ||
@@ -206,4 +195,3 @@ { | ||
attributes: { id: keys.B, changeset: changeId, lat: '63.9', lon: '-120.9' }, | ||
children: [], | ||
content: '' | ||
children: [] | ||
}, | ||
@@ -213,4 +201,3 @@ { | ||
attributes: { id: keys.C, changeset: changeId, lat: '64.3', lon: '-122.1' }, | ||
children: [], | ||
content: '' | ||
children: [] | ||
}, | ||
@@ -220,4 +207,3 @@ { | ||
attributes: { id: keys.D, changeset: changeId, lat: '65.1', lon: '-120.9' }, | ||
children: [], | ||
content: '' | ||
children: [] | ||
}, | ||
@@ -227,4 +213,3 @@ { | ||
attributes: { id: keys.E, changeset: changeId, lat: '65.3', lon: '-120.8' }, | ||
children: [], | ||
content: '' | ||
children: [] | ||
}, | ||
@@ -234,4 +219,3 @@ { | ||
attributes: { id: keys.F, changeset: changeId, lat: '60.6', lon: '-122.3' }, | ||
children: [], | ||
content: '' | ||
children: [] | ||
}, | ||
@@ -261,8 +245,8 @@ { | ||
children: [ | ||
{ name: 'member', attributes: { type: 'node', ref: keys.F }, children: [] }, | ||
{ name: 'member', attributes: { type: 'way', ref: keys.G }, children: [] }, | ||
{ name: 'member', attributes: { type: 'way', ref: keys.H }, children: [] } | ||
{ name: 'member', attributes: { type: 'node', ref: keys.F, role: '' }, children: [] }, | ||
{ name: 'member', attributes: { type: 'way', ref: keys.G, role: '' }, children: [] }, | ||
{ name: 'member', attributes: { type: 'way', ref: keys.H, role: '' }, children: [] } | ||
], | ||
content: '' | ||
}, | ||
} | ||
].sort(cmpch)) | ||
@@ -272,4 +256,4 @@ })) | ||
test('teardown many-types server', function (t) { | ||
server.close() | ||
test('many_types.js: teardown server', function (t) { | ||
server.cleanup() | ||
t.end() | ||
@@ -276,0 +260,0 @@ }) |
var test = require('tape') | ||
var request = require('http').request | ||
var tmpdir = require('os').tmpdir() | ||
var path = require('path') | ||
var osmrouter = require('../') | ||
var http = require('http') | ||
var osmdb = require('osm-p2p') | ||
var parsexml = require('xml-parser') | ||
var hyperquest = require('hyperquest') | ||
var concat = require('concat-stream') | ||
var parsexml = require('xml-parser') | ||
var base, server, changeId | ||
test('setup multi-fetch server', function (t) { | ||
var osm = osmdb(path.join(tmpdir, 'osm-p2p-server-test-' + Math.random())) | ||
var router = osmrouter(osm) | ||
var createServer = require('./test_server.js') | ||
server = http.createServer(function (req, res) { | ||
if (router.handle(req, res)) {} | ||
else { | ||
res.statusCode = 404 | ||
res.end('not found\n') | ||
} | ||
}) | ||
server.listen(0, function () { | ||
var port = server.address().port | ||
base = 'http://localhost:' + port + '/api/0.6/' | ||
test('multi_fetch.js: setup server', function (t) { | ||
createServer(function (d) { | ||
base = d.base | ||
server = d.server | ||
t.end() | ||
@@ -76,3 +61,3 @@ }) | ||
t.ok(/^[0-9A-Fa-f]+$/.test(body.trim())) | ||
uploaded[doc.lon+','+doc.lat] = body.trim() | ||
uploaded[doc.lon + ',' + doc.lat] = body.trim() | ||
})) | ||
@@ -98,3 +83,3 @@ hq.end(`<osm> | ||
t.equal(res.statusCode, 200) | ||
t.equal(res.headers['content-type'].split(/\s*;\s*/)[0], 'text/xml') | ||
t.equal(res.headers['content-type'], 'text/xml; charset=utf-8') | ||
}) | ||
@@ -113,5 +98,5 @@ hq.pipe(concat({ encoding: 'string' }, function (body) { | ||
test('teardown multi-fetch server', function (t) { | ||
server.close() | ||
test('multi_fetch.js: teardown server', function (t) { | ||
server.cleanup() | ||
t.end() | ||
}) |
var test = require('tape') | ||
var tmpdir = require('os').tmpdir() | ||
var path = require('path') | ||
var osmrouter = require('../') | ||
var http = require('http') | ||
var osmdb = require('osm-p2p') | ||
var parsexml = require('xml-parser') | ||
@@ -11,18 +6,11 @@ var hyperquest = require('hyperquest') | ||
var createServer = require('./test_server.js') | ||
var base, server, changeId, changeId2, osm | ||
test('setup changeset server', function (t) { | ||
osm = osmdb(path.join(tmpdir, 'osm-p2p-server-test-' + Math.random())) | ||
var router = osmrouter(osm) | ||
server = http.createServer(function (req, res) { | ||
if (router.handle(req, res)) { | ||
} else { | ||
res.statusCode = 404 | ||
res.end('not found\n') | ||
} | ||
}) | ||
server.listen(0, function () { | ||
var port = server.address().port | ||
base = 'http://localhost:' + port + '/api/0.6/' | ||
test('split_way_delete.js: setup server', function (t) { | ||
createServer(function (d) { | ||
base = d.base | ||
server = d.server | ||
osm = d.osm | ||
t.end() | ||
@@ -110,3 +98,3 @@ }) | ||
var nodes = xml.root.children.filter(c => c.name === 'node') | ||
.sort((a, b) => Number(b.lat) - Number(a.lat)) | ||
.sort((a, b) => Number(a.attributes.lat) - Number(b.attributes.lat)) | ||
var ways = xml.root.children.filter(c => c.name === 'way') | ||
@@ -187,3 +175,3 @@ t.equal(nodes.length, 5, 'correct number of nodes') | ||
osm.get(ids['-6'], function (err, docs) { | ||
t.error(err, 'doesn\'t throw error') | ||
t.error(err, "doesn't throw error") | ||
t.equal(Object.keys(docs).length, 1, 'no forks created') | ||
@@ -207,3 +195,3 @@ var way = docs[Object.keys(docs)[0]] | ||
var nodes = xml.root.children.filter(c => c.name === 'node') | ||
.sort((a, b) => Number(b.lat) - Number(a.lat)) | ||
.sort((a, b) => Number(a.attributes.lat) - Number(b.attributes.lat)) | ||
var ways = xml.root.children.filter(c => c.name === 'way') | ||
@@ -222,5 +210,5 @@ t.equal(nodes.length, 3, 'correct number of nodes') | ||
test('teardown changeset server', function (t) { | ||
server.close() | ||
test('split_way_delete.js: teardown server', function (t) { | ||
server.cleanup() | ||
t.end() | ||
}) |
Sorry, the diff of this file is not supported yet
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
GitHub dependency
Supply chain riskContains a dependency which resolves to a GitHub URL. Dependencies fetched from GitHub specifiers are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
Misc. License Issues
License(Experimental) A package's licensing information has fine-grained problems.
Found 1 instance in 1 package
161061
79
0
4707
173
4
20
11
1
1
2
+ Addedcontent-type@^1.0.2
+ Addeddebug@^2.2.0
+ Addedfrom2-array@0.0.4
+ Addedinherits@^2.0.1
+ Addedobj2osm@^2.0.0
+ Addedosm2json@^2.1.0
+ Addedpumpify@^1.3.5
+ Addedquery-string@^4.2.2
+ Addedread-only-stream@^2.0.0
+ Addedreadable-stream@^2.1.4
+ Addedstatuses@^1.3.0
+ Addedcontent-type@1.0.5(transitive)
+ Addedduplexify@3.7.1(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedfrom2@2.3.0(transitive)
+ Addedfrom2-array@0.0.4(transitive)
+ Addedobj2osm@2.0.1(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedosm2json@2.2.1(transitive)
+ Addedpump@2.0.1(transitive)
+ Addedpumpify@1.5.1(transitive)
+ Addedquery-string@4.3.4(transitive)
+ Addedread-only-stream@2.0.0(transitive)
+ Addedstatuses@1.5.0(transitive)
+ Addedstream-shift@1.0.3(transitive)
+ Addedstrict-uri-encode@1.1.0(transitive)
- Removedbody@^5.1.0
- Removedconcat-stream@^1.5.1
- Removedhas@^1.0.1
- Removedosm-p2p-xml@^1.0.1
- Removedsax@^1.2.1
- Removedxml-parser@^1.2.1
- Removedbody@5.1.0(transitive)
- Removedbytes@1.0.0(transitive)
- Removedcontinuable-cache@0.3.1(transitive)
- Removederror@7.2.1(transitive)
- Removedhas@1.0.4(transitive)
- Removedosm-p2p-xml@1.0.3(transitive)
- Removedraw-body@1.1.7(transitive)
- Removedsafe-json-parse@1.0.1(transitive)
- Removedstring-template@0.2.1(transitive)
- Removedstring_decoder@0.10.31(transitive)
- Removedxml-parser@1.2.1(transitive)