Gathering detailed insights and metrics for osm-p2p-db
Gathering detailed insights and metrics for osm-p2p-db
Gathering detailed insights and metrics for osm-p2p-db
Gathering detailed insights and metrics for osm-p2p-db
npm install osm-p2p-db
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
BSD-2-Clause License
237 Stars
208 Commits
20 Forks
8 Watchers
23 Branches
7 Contributors
Updated on Mar 30, 2025
Latest Version
4.4.1
Package Id
osm-p2p-db@4.4.1
Unpacked Size
158.60 kB
Size
30.35 kB
File Count
41
NPM Version
5.6.0
Node Version
8.11.1
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
p2p database for open street map data
npm install osm-p2p-db
1var hyperlog = require('hyperlog') 2 3var level = require('level') 4var db = { 5 log: level('/tmp/osm-p2p/log'), 6 index: level('/tmp/osm-p2p/index') 7} 8var fdstore = require('fd-chunk-store') 9var storefile = '/tmp/osm-p2p/kdb' 10 11var osmdb = require('osm-p2p-db') 12var osm = osmdb({ 13 log: hyperlog(db.log, { valueEncoding: 'json' }), 14 db: db.index, 15 store: fdstore(4096, storefile) 16}) 17 18if (process.argv[2] === 'create') { 19 var value = JSON.parse(process.argv[3]) 20 osm.create(value, function (err, key, node) { 21 if (err) console.error(err) 22 else console.log(key) 23 }) 24} else if (process.argv[2] === 'query') { 25 var q = process.argv.slice(3).map(csplit) 26 osm.query(q, function (err, pts) { 27 if (err) console.error(err) 28 else pts.forEach(function (pt) { 29 console.log(pt) 30 }) 31 }) 32} 33 34function csplit (x) { return x.split(',').map(Number) }
Now we can create a few nodes and search with a bounding box query:
$ mkdir /tmp/osm-p2p
$ node db.js create '{"type":"node","lat":64.6,"lon":-147.8}'
11892499690884077339
$ node db.js create '{"type":"node","lat":64.3,"lon":-148.2}'
1982521011513780909
$ node db.js create '{"type":"node","lat":64.5,"lon":-147.3}'
14062704270722785878
$ node db.js query 64.1,64.6 -148,-147
{ type: 'node',
lat: 64.5,
lon: -147.3,
id: '14062704270722785878',
version: 'e635d07b9fc0a9d048cdd5d9e97a44a19ba3a0b2a51830d1e3e0fadcb80935fc' }
We can make a way
document that refers to a list of node
documents:
$ node db.js create '{"type":"way","refs":
["11892499690884077339","1982521011513780909","14062704270722785878"]}'
14666931246975765366
When we query, any ways
that have one or more nodes within the bounding box
will turn up in the results:
$ node db.js query 64.1,64.6 -148,-147
{ type: 'node',
lat: 64.5,
lon: -147.3,
id: '14062704270722785878',
version: 'e635d07b9fc0a9d048cdd5d9e97a44a19ba3a0b2a51830d1e3e0fadcb80935fc' }
{ type: 'way',
refs: [ '11892499690884077339', '1982521011513780909', '14062704270722785878' ],
id: '14666931246975765366',
version: 'f4fc0045e298ca4f9373fab78dee4f0561b4056dcd7975eb92f21d0a05e0eede' }
node
or way
.1var osmdb = require('osm-p2p-db')
Create a new osm
instance with:
opts.log
- a hyperlog with a valueEncoding of json
opts.db
- a levelup instance to store index dataopts.store
- an abstract-chunk-store instanceYou may optionally pass in a hyperkv instance as opts.kv
, but otherwise
one will be created from the opts.log
and opts.db
.
You may safely delete the index database whenever you like. The index data is automatically regenerated. This is very useful if there are breaking changes to the index code or if the data becomes corrupted. The hyperlog contains the source of truth.
Store a new document from doc
. cb(err, id, node)
fires with the generated
OSM id
and the node
from the underlying hyperlog.
Elements are node
, way
, and relation
. Each element should have a type
property that contains the element type as a string.
doc.lat
and doc.lon
coordinates.doc.refs
.doc.members
.
Each member object has a member.type
of the document pointed at by
member.ref
and optionally a member.role
.Another type of document is a changeset
.
Each element should have a changeset
property that refers to the id of a
changeset
document.
It is recommended to use tags.comment
to store free-form text describing the
changeset.
Replace a document at id
with doc
.
If the document didn't exist previously, it will be created.
The options opts
are passed to the underlying hyperkv instance.
By default, hyperkv will merge the most recent known forks into a single fork.
To add modifications to a fork without merging the changes into other forks,
set opts.links
to an array of only the single key you want to update.
Delete a document at id
.
The options opts
are passed to the underlying hyperkv instance.
cb(err, node)
fires with the underlying node
in the hyperlog.
Atomically insert an array of documents rows
.
Each row
in rows
should have:
row.type
- 'put'
or 'del'
row.key
or row.id
- the id of the document (generated if not specified)row.links
- array of links to ancestor keysrow.value
- for puts, the value to storeGet a document as cb(err, docs)
by its OSM id
.
docs
is an object mapping hyperlog hashes to current document values. If a
document has been deleted, it will only have the properties { id: <osm-id>, version: <osm-version>, deleted: true}
.
Fetch a specific OSM element by its version string. Returns null
if not found,
otherwise the single element.
Query for all nodes, ways, and relations in the query given by the array q
.
Queries are arrays of [[minLat,maxLat],[minLon,maxLon]]
specifying a bounding
box.
cb(err, res)
fires with an array of results res
. Each result is the document
augmented with an id
property and a version
property that is the hash key
from the underlying hyperlog. If a document has been deleted, it will only have
the properties { id: <osm-id>, version: <osm-version>, deleted: true}
.
Optionally:
opts.order
- set to 'type'
to order by type: node, way, relationFetch a list of all OSM ways and relations that refer to the element with ID
id
. For a node, this can be ways or relations. For a way or relation, this can
only be relations.
Objects of the following form are returned:
1{ 2 id: '...', 3 version: '...' 4}
Runs the callback cb
once all of osm
's internal indexes are caught up to the latest data. cb
is called exactly once.
Closes the Level and chunk-store backends associated with the database. cb
is
called upon completion.
Return a readable object stream rstream
of query results contained in the
query q
. Queries are arrays of [[minLat,maxLat],[minLon,maxLon]]
specifying
a bounding box.
Each object in the stream is a document augmented with an id
property and a
version
property that is the hash key from the underlying hyperlog.
Optionally:
opts.order
- set to 'type'
to order by type: node, way, relationGet the list of document version ids in a changeset by a changeset id
changeset
.
If a callback is provided, the version ids are returned as cb(err, versions)
.
Without callback, the versions are provided by the returned readable object
stream rstream
.
Handle errors from the underlying indexes with the 'error'
event.
You can get at the hyperkv instance directly to perform more operations
using osm.kv
.
For example, you can use osm.kv.createReadStream()
to list all the id/value
pairs in the database.
The hyperlog instance is available as the opts.log
property if you need
to get at it directly later.
To use this module in the browser, use level-browserify to provide the
opts.db
instance and idb-chunk-store as the opts.store
. Each of these
is backed by IndexedDB, a native browser storage interface.
If you have two hyperlogs log0
and log1
, pipe them together and back again
to replicate:
var r0 = log0.replicate()
var r1 = log1.replicate()
r0.pipe(r1).pipe(r0)
Insert additional streams as necessary for network transports if the logs live in different processes or machines.
If both logs have made edits to the same IDs, multiple records will appear for
the same ID in the results. To merge these "conflicts" back into a single value,
use osm.put(id, doc, cb)
to store the desired document value.
Read about the internal architecture.
If you would like to support our work, or if you have ideas about how to use and adapt osm-p2p for your own project, then please dive in. Open an issue with a bug report or feature request, or send us a pull request with a bug-fix or new feature.
We need help right now adding tests and fixing edge-cases with osm-p2p-server and increasing compatibility with other OSM tools such as JOSM.
BSD (c) 2016, Digital Democracy.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 1/20 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More