UNPKG

w3name

Version:

The JavaScript API client for w3name

1 lines 1.45 kB
{"version":3,"file":"service.cjs","sources":["../src/service.ts"],"sourcesContent":["import { throttledQueue } from 'throttled-queue'\n\nconst RATE_LIMIT_REQUESTS = 30\nconst RATE_LIMIT_PERIOD = 10 * 1000\n\nexport interface PublicService {\n endpoint: URL\n rateLimiter?: RateLimiter\n}\n\n/**\n * RateLimiter returns a promise that resolves when it is safe to send a request\n * that does not exceed the rate limit.\n */\nexport type RateLimiter = () => Promise<void>\n\nfunction createRateLimiter (): RateLimiter {\n const throttle = throttledQueue({ maxPerInterval: RATE_LIMIT_REQUESTS, interval: RATE_LIMIT_PERIOD })\n return async () => await throttle(() => {})\n}\n\n/**\n * W3NameService coordinates access to the W3name API.\n */\nexport default class W3NameService implements PublicService {\n endpoint: URL\n waitForRateLimit: RateLimiter\n\n constructor (\n endpoint: URL = new URL('https://name.web3.storage/'),\n waitForRateLimit: RateLimiter = createRateLimiter()\n ) {\n this.endpoint = endpoint\n this.waitForRateLimit = waitForRateLimit\n }\n}\n"],"names":["endpoint","waitForRateLimit","constructor","URL","throttle","throttledQueue","maxPerInterval","interval","async","createRateLimiter","this"],"mappings":"6DAwBc,MACZA,SACAC,iBAEAC,YACEF,EAAgB,IAAIG,IAAI,8BACxBF,EAdJ,WACE,MAAMG,EAAWC,EAAAA,eAAe,CAAEC,eAfR,GAe6CC,SAd/C,MAexB,OAAOC,eAAkBJ,GAAS,QACpC,CAWoCK,IAEhCC,KAAKV,SAAWA,EAChBU,KAAKT,iBAAmBA,CAC1B"}