UNPKG

@helia/verified-fetch

Version:

A fetch-like API for obtaining verified & trustless IPFS content on the web

63 lines 2.67 kB
import { TLRU } from './tlru.js'; import type { ServerTimingResult } from './server-timing.js'; import type { RequestFormatShorthand } from '../types.js'; import type { DNSLinkResolveResult, IPNS, IPNSResolveResult, IPNSRoutingEvents, ResolveDNSLinkProgressEvents, ResolveProgressEvents, ResolveResult } from '@helia/ipns'; import type { AbortOptions, ComponentLogger } from '@libp2p/interface'; import type { ProgressOptions } from 'progress-events'; export declare const ipnsCache: TLRU<DNSLinkResolveResult | IPNSResolveResult>; export interface ParseUrlStringInput { urlString: string; ipns: IPNS; logger: ComponentLogger; withServerTiming?: boolean; } export interface ParseUrlStringOptions extends ProgressOptions<ResolveProgressEvents | IPNSRoutingEvents | ResolveDNSLinkProgressEvents>, AbortOptions { } export interface ParsedUrlQuery extends Record<string, string | unknown> { format?: RequestFormatShorthand; download?: boolean; filename?: string; 'dag-scope'?: string; } export interface ParsedUrlStringResults extends ResolveResult { protocol: 'ipfs' | 'ipns'; query: ParsedUrlQuery; /** * The value for the IPFS gateway spec compliant header `X-Ipfs-Path` on the * response. * The value of this header should be the original requested content path, * prior to any path resolution or traversal. * * @see https://specs.ipfs.tech/http-gateways/path-gateway/#x-ipfs-path-response-header */ ipfsPath: string; /** * seconds as a number */ ttl?: number; /** * serverTiming items */ serverTimings: Array<ServerTimingResult<any>>; } interface MatchUrlGroups { protocol: 'ipfs' | 'ipns'; cidOrPeerIdOrDnsLink: string; path?: string; queryString?: string; } export declare function matchURLString(urlString: string): MatchUrlGroups; /** * A function that parses ipfs:// and ipns:// URLs, returning an object with easily recognizable properties. * * After determining the protocol successfully, we process the cidOrPeerIdOrDnsLink: * - If it's ipfs, it parses the CID or throws Error[] * - If it's ipns, it attempts to resolve the PeerId and then the DNSLink. If both fail, Error[] is thrown. * * @todo we need to break out each step of this function (cid parsing, ipns resolving, dnslink resolving) into separate functions and then remove the eslint-disable comment * * @throws {Error[]} */ export declare function parseUrlString({ urlString, ipns, logger, withServerTiming }: ParseUrlStringInput, options?: ParseUrlStringOptions): Promise<ParsedUrlStringResults>; export {}; //# sourceMappingURL=parse-url-string.d.ts.map