@informath/nominatim
Advanced tools
Comparing version 5.5.0 to 6.0.0
@@ -1,34 +0,46 @@ | ||
const fetch = require('node-fetch'), // Forgot the "Usage Policy" part... NotLikeThis | ||
TQueue = require('tqueue'); | ||
const fetch = require('node-fetch'); // Forgot the "Usage Policy" part... NotLikeThis | ||
const Db = require('informa-db.js'); | ||
const { Db } = require('informa-db.js'); | ||
const queue = new TQueue({delay: 1000}); | ||
const queue = []; | ||
const cache = new Db('cache.json'); | ||
const baseUrl = 'https://nominatim.openstreetmap.org/'; | ||
queue.on('pop', async (item) => { | ||
cache[url] = await (await fetch(item.url)).json(); | ||
item.fn(cache[url]); | ||
const NominatimNoAuth = new Proxy({}, { | ||
get(obj, prop) { | ||
return (prop == 'default' ? { | ||
addressdetails: 1, | ||
limit: 10, | ||
format: 'json' | ||
} : (options, overwriteDefault) => new Promise((res) => { | ||
const url = `${baseUrl}${prop}?${ | ||
Object.entries({ ...(overwriteDefault ? {} : Nominatim.default), ...options }) | ||
.map(([i, v]) => `${i}=${v}`) | ||
.join('&') | ||
}`; | ||
if (url in cache) res(cache[url]); | ||
queue.push({ | ||
url, | ||
fn: res, | ||
uA: this.userAgent, | ||
}) | ||
})) | ||
} | ||
}); | ||
const Nominatim = new Proxy({}, { | ||
get: (obj, prop) => (prop == 'default' ? { | ||
addressdetails: 1, | ||
limit: 10, | ||
format: 'json' | ||
} : (options, overwriteDefault) => new Promise((res) => { | ||
const url = `${baseUrl}${prop}?${ | ||
Object.entries({ ...(overwriteDefault ? {} : Nominatim.default), ...options }) | ||
.map(([i, v]) => `${i}=${v}`) | ||
.join('&') | ||
}`; | ||
if (url in cache) res(cache[url]); | ||
queue.push({ | ||
url, | ||
fn: res, | ||
}) | ||
})) | ||
}); | ||
class Nominatim extends NominatimNoAuth { | ||
constructor(userAgent) { | ||
if (!userAgent) throw new Error(''); | ||
this.userAgent = `"${userAgent}" Cached 1sDelay ShouldBeCompliant`; | ||
setInterval(async () => { | ||
const item = queue.shift(); | ||
if (item) { | ||
cache[url] = await (await fetch(item.url)).json(); | ||
item.fn(cache[url]); | ||
} | ||
}, 1000); | ||
} | ||
} | ||
module.exports = Nominatim; |
@@ -5,3 +5,3 @@ { | ||
"description": "Completely rewritten version of David Howell's Nominatim", | ||
"version": "5.5.0", | ||
"version": "6.0.0", | ||
"repository": { | ||
@@ -13,7 +13,5 @@ "type": "git", | ||
"dependencies": { | ||
"node-fetch": "^2.6.1", | ||
"tqueue": "^0.1.0" | ||
}, | ||
"devDependencies": {}, | ||
"optionalDependencies": {} | ||
"informa-db.js": "^5.5.0", | ||
"node-fetch": "^2.6.1" | ||
} | ||
} |
3021
51
5
+ Addedinforma-db.js@^5.5.0
+ Addedinforma-db.js@5.5.0(transitive)
- Removedtqueue@^0.1.0
- Removedtqueue@0.1.0(transitive)