import type { ErrorCauseOptions } from '@vltpkg/error-cause'; import type { Integrity, JSONField } from '@vltpkg/types'; import ccp from 'cache-control-parser'; import type { InspectOptions } from 'node:util'; export type JSONObj = Record; declare const kCustomInspect: unique symbol; export type CacheEntryOptions = { /** * An optional body to use. * * This is used when decoding a cache entry from a buffer, and the body * is already in a ArrayBuffer we can use. When this option is * provided the `addBody` method should not be used. */ body?: Uint8Array; /** * An optional content length of the body to use, if undefined the * content-length header will be used. */ contentLength?: number; /** * The expected integrity value for this response body */ integrity?: Integrity; /** * Whether to trust the integrity, or calculate the actual value. * * This indicates that we just accept whatever the integrity is as the actual * integrity for saving back to the cache, because it's coming directly from * the registry that we fetched a packument from, and is an initial gzipped * artifact request. */ trustIntegrity?: boolean; /** * If the server does not serve a `stale-while-revalidate` value in the * `cache-control` header, then this multiplier is applied to the `max-age` * or `s-maxage` values. * * By default, this is `60`, so for example a response that is cacheable for * 5 minutes will allow a stale response while revalidating for up to 5 * hours. * * If the server *does* provide a `stale-while-revalidate` value, then that * is always used. * * Set to 0 to prevent any `stale-while-revalidate` behavior unless * explicitly allowed by the server's `cache-control` header. */ 'stale-while-revalidate-factor'?: number; }; export declare class CacheEntry { #private; constructor(statusCode: number, headers: Uint8Array[], { body, integrity, trustIntegrity, 'stale-while-revalidate-factor': staleWhileRevalidateFactor, contentLength, }?: CacheEntryOptions); toJSON(): { [k: string]: string | number | boolean | [string, string][] | Date | ccp.CacheControl | undefined; }; [kCustomInspect](depth: number, options: InspectOptions): string; get date(): Date | undefined; get maxAge(): number; get cacheControl(): ccp.CacheControl; get staleWhileRevalidate(): boolean; get contentType(): string; get valid(): boolean; /** * Add contents to the entry body. */ addBody(b: Uint8Array): void; get statusCode(): number; get headers(): Uint8Array[]; /** * Returns the body as a single Uint8Array, concatenating parts if needed. */ get _body(): Uint8Array; /** * Check that the sri integrity string that was provided to the ctor * matches the body that we actually received. This should only be called * AFTER the entire body has been completely downloaded. * * This method **will throw** if the integrity values do not match. * * Note that this will *usually* not be true if the value is coming out of * the cache, because the cache entries are un-gzipped in place. It should * _only_ be called for artifacts that come from an actual http response. * * Returns true if anything was actually verified. */ checkIntegrity(context?: ErrorCauseOptions): this is CacheEntry & { integrity: Integrity; }; get integrityActual(): Integrity; set integrityActual(i: Integrity); set integrity(i: Integrity | undefined); get integrity(): Integrity | undefined; /** * Give it a key, and it'll return the buffer of that header value */ getHeader(h: string): Uint8Array | undefined; /** * Give it a key, and it'll return the decoded string of that header value */ getHeaderString(h: string): string | undefined; /** * Set a header to a specific value */ setHeader(h: string, value: Uint8Array | string): void; /** * Return the body of the entry as a Buffer */ buffer(): Buffer; get body(): Uint8Array | Record; get isJSON(): boolean; get isGzip(): boolean; /** * Un-gzip encode the body. * Returns true if it was previously gzip (so something was done), otherwise * returns false. */ unzip(): boolean; /** * Return the body of the entry as utf8 text * Automatically unzips if the content is gzip encoded */ text(): string; /** * Parse the entry body as JSON and return the result */ json(): JSONObj; /** * Pass the contents of a @vltpkg/cache.Cache object as a buffer, * and this static method will decode it into a CacheEntry representing * the cached response. */ static decode(buffer: Uint8Array): CacheEntry; static isGzipEntry(buffer: Uint8Array): boolean; /** * Encode the entry as a single Buffer for writing to the cache */ encode(): Buffer; } export {};