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MAAK,CAAC,EAAM,IAAU,OAAS,EAAW,KAC1C,OAAM,CAAC,EAAO,IAAU,EAAS,OAAO,IAC7C,EAGF,UAAU,UAAY,UACtB,UAAU,kBAAoB,yBAC9B,UAAU,0BAA4B,iBACtC,UAAU,eAAiB,MAC3B,UAAU,eAAiB,MAE3B,OAAO,QAAU","file":"/npm/nominatim-geocoder@0.1.4/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/nominatim-geocoder@0.1.4/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const Query = require('./model/Query')\n\nconst axios = require('axios')\nconst Cache = require('lru')\nconst Queue = require('promise-queue')\n\nconst defaultConcurrency = 1\nconst defaultMaxQueueLength = Infinity\nconst cacheSize = 100000\n\n// Context is shared across different modules\nconst SingletonContext = {\n  queue: new Queue(defaultConcurrency, defaultMaxQueueLength),\n  cache: new Cache(cacheSize),\n}\n\nclass Nominatim {\n  constructor(options, queryOptions) {\n    const defaultOptions = {\n      secure: false, // enables ssl\n      host: 'nominatim.openstreetmap.org',\n      customUrl: undefined, // if you want to host your own nominatim\n      cache: true,\n      delay: 1000, // Delay between requests\n    }\n\n    const queryDefaults = {\n      format: 'json',\n      limit: 3,\n    }\n\n    this.options = Object.assign({}, defaultOptions, options)\n    this.queryDefaults = Object.assign({}, queryDefaults, queryOptions)\n  }\n\n  static setupCache(size) {\n    // Just to be sure the memory will be freed\n    if (SingletonContext.cache) {\n      SingletonContext.cache.clear()\n    }\n\n    SingletonContext.cache = new Cache(size)\n  }\n\n  static setupQueue(concurrency, maxQueueLength) {\n    SingletonContext.queue = new Queue(\n      concurrency || defaultConcurrency,\n      maxQueueLength || defaultMaxQueueLength)\n  }\n\n\n  protocol(options) {\n    return options.secure ? 'https' : 'http'\n  }\n\n  buildUrl(options, slug) {\n    if (options.customUrl) {\n      return options.customUrl + slug\n    }\n\n    return this.protocol(options) + '://' + options.host + slug\n  }\n\n  search(query, options) {\n    // Merge options\n    const opt = Object.assign({}, this.options, options)\n    const url = this.buildUrl(opt, '/search')\n    return this.query(url, query)\n  }\n\n  reverse(query, options) {\n    // Merge options\n    const opt = Object.assign({}, this.options, options)\n    const url = this.buildUrl(opt, '/reverse')\n    return this.query(url, query)\n  }\n\n  query(url, query) {\n    const queryObject = Object.assign(new Query(), this.queryDefaults, query)\n    const cacheHitInformation = { hit: false }\n\n    return SingletonContext.queue.add(() => {\n      const promise = new Promise((resolve, reject) => {\n        let cachedResponse\n        if (cachedResponse = SingletonContext.cache.get(queryObject.hash())) {\n          cacheHitInformation.hit = true\n          resolve(cachedResponse)\n          return\n        }\n\n        axios.get(url, { params: queryObject.plainObject() })\n          .then((response) => {\n            resolve(response.data)\n          })\n          .catch((error) => {\n            SingletonContext.cache.remove(queryObject.hash())\n            reject(error)\n          })\n      })\n\n      const delayedPromise = this.delayPromise(promise, cacheHitInformation)\n\n      // Store promise in cache, resolved promises are self-unwrapping\n      SingletonContext.cache.set(queryObject.hash(), delayedPromise)\n      return delayedPromise\n    })\n  }\n\n  // This method wraps a promise, it waits after a promise is resolved/rejected\n  // and resolves the outer promise when the remaing time after delayBetweenRequests\n  // has passed. Quite a hack...\n  // ToDo: Replace\n  // Note: Rate limiting is subject to the jasmine tests\n  delayPromise(promise, cacheHitInformation) {\n    const start = new Date()\n\n    const handleEndedPromise = (action, responseOrError) => {\n      const end = new Date()\n\n      const timeToWait = this.options.delay - (end - start)\n      const isFromCache = cacheHitInformation.hit\n\n      if (timeToWait > 0 && !isFromCache) {\n        setTimeout(() => action(responseOrError), timeToWait)\n      } else {\n        action(responseOrError) // immediate resolve\n      }\n    }\n\n    return new Promise((resolve, reject) => {\n      promise.then((response, query, test) => {\n        handleEndedPromise(resolve, response)\n      }).catch((error, query) => {\n        handleEndedPromise(reject, error)\n      })\n    })\n  }\n}\n\n// Wrapper for those who prefer callbacks\nclass NominatimCallbackWrapper extends Nominatim {\n  search(query, options, callback) {\n    const promise = super.search(query, options)\n    return this.handlePromise(promise, callback)\n  }\n\n  reverse(query, options, callback) {\n    const promise = super.reverse(query, options)\n    return this.handlePromise(promise, callback)\n  }\n\n  handlePromise(promise, callback) {\n    if (typeof callback === 'function') {\n      return this.wrapPromiseWithCallback(promise, callback)\n    }\n\n    return promise\n  }\n\n  wrapPromiseWithCallback(promise, callback) {\n    return promise\n      .then((data, query) => callback(undefined, data))\n      .catch((error, query) => callback(error, undefined))\n  }\n}\n\nNominatim.Nominatim = Nominatim // hack to have a default and named exports\nNominatim.NominatimCallback = NominatimCallbackWrapper\nNominatim.NominatimSingletonContext = SingletonContext\nNominatim.NominatimCache = Cache\nNominatim.NominatimQueue = Queue\n\nmodule.exports = Nominatim\n"]}