UNPKG

nftstorage.link

Version:

Utilities for working with the NFT.Storage IPFS Edge Gateway

131 lines 5.05 kB
/** * Creates a rate limiter which limits at the same rate as is enforced * server-side, to allow the client to avoid exceeding the requests limit and * being blocked for 30 seconds. * @returns {RateLimiter} */ export function createRateLimiter(): RateLimiter; /** * @typedef { import('./lib/interface.js').RateLimiter } RateLimiter * @typedef { import('./lib/interface.js').Service } Service * @typedef { import('./lib/interface.js').PutOptions} PutOptions * @typedef { import('./lib/interface.js').DeleteOptions} DeleteOptions * @typedef { import('./lib/interface.js').ListOptions} ListOptions * @typedef { import('./lib/interface.js').CacheResult} CacheResult * @typedef { import('./lib/interface.js').CacheDeleteResult} CacheDeleteResult * @typedef { import('./lib/interface.js').CacheEntry} CacheEntry * @typedef { import('./lib/interface.js').AccountInfo} AccountInfo */ /** * @implements Service */ export class PermaCache implements Service { /** * @hidden * @param {string} token * @returns {Record<string, string>} */ static headers(token: string): Record<string, string>; /** * @param {Service} service * @param {string[]} urls * @param {PutOptions} [options] * @returns {Promise<CacheResult[]>} */ static put({ endpoint, token, rateLimiter }: Service, urls: string[], { onPut, maxRetries }?: import("./lib/interface.js").PutOptions | undefined): Promise<CacheResult[]>; /** * @param {Service} service * @param {ListOptions} [options] * @returns {AsyncIterable<CacheEntry>} */ static list({ endpoint, token, rateLimiter }: Service, { sort, order }?: import("./lib/interface.js").ListOptions | undefined): AsyncIterable<CacheEntry>; /** * @param {Service} service * @param {string[]} urls * @param {DeleteOptions} [options] * @returns {Promise<CacheDeleteResult[]>} */ static delete({ endpoint, token, rateLimiter }: Service, urls: string[], { onDelete, maxRetries }?: import("./lib/interface.js").DeleteOptions | undefined): Promise<CacheDeleteResult[]>; /** * @param {Service} service * @return {Promise<AccountInfo>} */ static accountInfo({ endpoint, token, rateLimiter, }: Service): Promise<AccountInfo>; /** * Constructs a client bound to the given `options.token` and * `options.endpoint`. * * @example * ```js * import { PermaCache } from 'nftstorage.link' * const cache = new PermaCache({ token: API_TOKEN }) * ``` * * @param {{token: string, endpoint?:URL, rateLimiter?: RateLimiter}} options */ constructor({ token, endpoint, rateLimiter, }: { token: string; endpoint?: URL; rateLimiter?: RateLimiter; }); /** * Authorization token. * * @readonly */ readonly token: string; /** * Service API endpoint `URL`. * @readonly */ readonly endpoint: URL; /** * @readonly */ readonly rateLimiter: import("./lib/interface.js").RateLimiter; /** * Perma cache URLS into nftstorage.link. * * Returns the corresponding Perma cache entries created. * * @param {string[]} urls * @param {PutOptions} [options] * @returns {Promise<CacheResult[]>} */ put(urls: string[], options?: import("./lib/interface.js").PutOptions | undefined): Promise<CacheResult[]>; /** * List all Perma cached URLs for this account. Use a `for await...of` loop to fetch them all. * @example * Fetch all the urls * ```js * const urls = [] * for await (const item of client.list()) { * urls.push(item) * } * ``` * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of * @param {ListOptions} [options] * @returns {AsyncIterable<CacheEntry>} */ list(options?: import("./lib/interface.js").ListOptions | undefined): AsyncIterable<CacheEntry>; /** * @param {string[]} urls * @param {DeleteOptions} [options] * @returns {Promise<CacheDeleteResult[]>} */ delete(urls: string[], options?: import("./lib/interface.js").DeleteOptions | undefined): Promise<CacheDeleteResult[]>; /** * Fetch info on PermaCache for the user. */ accountInfo(): Promise<import("./lib/interface.js").AccountInfo>; } export type RateLimiter = import('./lib/interface.js').RateLimiter; export type Service = import('./lib/interface.js').Service; export type PutOptions = import('./lib/interface.js').PutOptions; export type DeleteOptions = import('./lib/interface.js').DeleteOptions; export type ListOptions = import('./lib/interface.js').ListOptions; export type CacheResult = import('./lib/interface.js').CacheResult; export type CacheDeleteResult = import('./lib/interface.js').CacheDeleteResult; export type CacheEntry = import('./lib/interface.js').CacheEntry; export type AccountInfo = import('./lib/interface.js').AccountInfo; //# sourceMappingURL=perma-cache.d.ts.map