vlt / docs

  • PricingBenchmarks (opens in new window)Community (opens in new window)Feedback
  • Overview
    • Overview
    • cache-entry
    • index
    • Reference
    • registry-error
    • store-root
  • Classes
  • CacheEntry
  • Type Aliases
  • CacheEntryOptions
  • JSONObj
  1. Client
  2. /
  3. API Reference
  4. /
  5. @vltpkg/registry-client
  6. /
  7. cache-entry

cache-entry

Classes

CacheEntry

Defined in: src/registry-client/src/cache-entry.ts:127

Constructors

new CacheEntry()
TypeScript
new CacheEntry(
   statusCode, 
   headers, 
   __namedParameters): CacheEntry

Defined in: src/registry-client/src/cache-entry.ts:150

Parameters
ParameterType
statusCodenumber
headersUint8Array<ArrayBufferLike>[]
__namedParametersCacheEntryOptions
Returns

CacheEntry

Accessors

_body
Get Signature
TypeScript
get _body(): Uint8Array

Defined in: src/registry-client/src/cache-entry.ts:379

Returns the body as a single Uint8Array, concatenating parts if needed.

Returns

Uint8Array

body
Get Signature
TypeScript
get body(): Uint8Array<ArrayBufferLike> | Record<string, any>

Defined in: src/registry-client/src/cache-entry.ts:539

Returns

Uint8Array<ArrayBufferLike> | Record<string, any>

cacheControl
Get Signature
TypeScript
get cacheControl(): CacheControl

Defined in: src/registry-client/src/cache-entry.ts:265

Returns

CacheControl

contentType
Get Signature
TypeScript
get contentType(): string

Defined in: src/registry-client/src/cache-entry.ts:288

Returns

string

date
Get Signature
TypeScript
get date(): undefined | Date

Defined in: src/registry-client/src/cache-entry.ts:246

Returns

undefined | Date

digest
Get Signature
TypeScript
get digest(): undefined | `sha512-${string}`

Defined in: src/registry-client/src/cache-entry.ts:479

The sha-512 member of an RFC 9530 Repr-Digest (or Content-Digest) response header, as an SRI string. A registry that serves packuments without dist.integrity labels each tarball this way instead.

Returns

undefined | `sha512-${string}`

fromCache
Get Signature
TypeScript
get fromCache(): boolean

Defined in: src/registry-client/src/cache-entry.ts:343

True when this entry was decoded from the on-disk cache.

Returns

boolean

headers
Get Signature
TypeScript
get headers(): Uint8Array<ArrayBufferLike>[]

Defined in: src/registry-client/src/cache-entry.ts:372

Returns

Uint8Array<ArrayBufferLike>[]

headSize
Get Signature
TypeScript
get headSize(): undefined | number

Defined in: src/registry-client/src/cache-entry.ts:351

Byte length of the encoded head (4-byte length prefix + status + headers). Set when decoded from cache or after encodeHead().

Returns

undefined | number

integrity
Get Signature
TypeScript
get integrity(): undefined | `sha512-${string}`

Defined in: src/registry-client/src/cache-entry.ts:470

Returns

undefined | `sha512-${string}`

Set Signature
TypeScript
set integrity(i): void

Defined in: src/registry-client/src/cache-entry.ts:464

Parameters
ParameterType
iundefined | `sha512-${string}`
Returns

void

integrityActual
Get Signature
TypeScript
get integrityActual(): `sha512-${string}`

Defined in: src/registry-client/src/cache-entry.ts:450

Returns

`sha512-${string}`

Set Signature
TypeScript
set integrityActual(i): void

Defined in: src/registry-client/src/cache-entry.ts:459

Parameters
ParameterType
i`sha512-${string}`
Returns

void

isGzip
Get Signature
TypeScript
get isGzip(): boolean

Defined in: src/registry-client/src/cache-entry.ts:561

Returns

boolean

isJSON
Get Signature
TypeScript
get isJSON(): boolean

Defined in: src/registry-client/src/cache-entry.ts:544

Returns

boolean

maxAge
Get Signature
TypeScript
get maxAge(): number

Defined in: src/registry-client/src/cache-entry.ts:254

Returns

number

ok
Get Signature
TypeScript
get ok(): boolean

Defined in: src/registry-client/src/cache-entry.ts:369

True when the registry answered with a 2xx.

RegistryClient.request() resolves for every status, so this is how code holding a real CacheEntry asks "did it work?".

Note this is the strict form. Use it only where a genuine CacheEntry is guaranteed; assertOk uses the loose range check because it is also handed duck-typed responses.

Returns

boolean

staleWhileRevalidate
Get Signature
TypeScript
get staleWhileRevalidate(): boolean

Defined in: src/registry-client/src/cache-entry.ts:273

Returns

boolean

statusCode
Get Signature
TypeScript
get statusCode(): number

Defined in: src/registry-client/src/cache-entry.ts:355

Returns

number

valid
Get Signature
TypeScript
get valid(): boolean

Defined in: src/registry-client/src/cache-entry.ts:300

Returns

boolean

Methods

[kCustomInspect]()
TypeScript
kCustomInspect: string

Defined in: src/registry-client/src/cache-entry.ts:237

Parameters
ParameterType
depthnumber
optionsInspectOptions
Returns

string

addBody()
TypeScript
addBody(b): void

Defined in: src/registry-client/src/cache-entry.ts:328

Add contents to the entry body.

Parameters
ParameterType
bUint8Array
Returns

void

buffer()
TypeScript
buffer(): Buffer

Defined in: src/registry-client/src/cache-entry.ts:529

Return the body of the entry as a Buffer

Returns

Buffer

checkDigest()
TypeScript
checkDigest(required, context): `sha512-${string}`

Defined in: src/registry-client/src/cache-entry.ts:432

Check the body against the RFC 9530 digest the server sent with it, for a response that had no expected integrity. A registry that omits dist.integrity labels every tarball, so a missing digest fails when required. Like checkIntegrity, only for an actual http response: cached bodies are un-gzipped in place.

Will throw on a mismatch. Returns the hash of the body.

Parameters
ParameterType
requiredboolean
contextErrorCauseOptions
Returns

`sha512-${string}`

checkIntegrity()
TypeScript
checkIntegrity(context): this is CacheEntry & { integrity: `sha512-${string}` }

Defined in: src/registry-client/src/cache-entry.ts:407

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 cache entries not exploded into the global store 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.

Parameters
ParameterType
contextErrorCauseOptions
Returns

this is CacheEntry & { integrity: `sha512-${string}` }

deleteHeader()
TypeScript
deleteHeader(h): void

Defined in: src/registry-client/src/cache-entry.ts:515

Remove a header, if present

Parameters
ParameterType
hstring
Returns

void

encode()
TypeScript
encode(): Buffer

Defined in: src/registry-client/src/cache-entry.ts:790

Encode the entry as a single Buffer for writing to the cache

Returns

Buffer

encodeHead()
TypeScript
encodeHead(): Buffer

Defined in: src/registry-client/src/cache-entry.ts:755

Encode status + headers (no body) as they appear at the start of an on-disk cache file.

Returns

Buffer

getHeader()
TypeScript
getHeader(h): undefined | Uint8Array<ArrayBufferLike>

Defined in: src/registry-client/src/cache-entry.ts:491

Give it a key, and it'll return the buffer of that header value

Parameters
ParameterType
hstring
Returns

undefined | Uint8Array<ArrayBufferLike>

getHeaderString()
TypeScript
getHeaderString(h): undefined | string

Defined in: src/registry-client/src/cache-entry.ts:498

Give it a key, and it'll return the decoded string of that header value

Parameters
ParameterType
hstring
Returns

undefined | string

json()
TypeScript
json(): JSONObj

Defined in: src/registry-client/src/cache-entry.ts:633

Parse the entry body as JSON and return the result

Returns

JSONObj

setHeader()
TypeScript
setHeader(h, value): void

Defined in: src/registry-client/src/cache-entry.ts:508

Set a header to a specific value

Parameters
ParameterType
hstring
valuestring | Uint8Array<ArrayBufferLike>
Returns

void

text()
TypeScript
text(): string

Defined in: src/registry-client/src/cache-entry.ts:625

Return the body of the entry as utf8 text Automatically unzips if the content is gzip encoded

Returns

string

toJSON()
TypeScript
toJSON(): object

Defined in: src/registry-client/src/cache-entry.ts:197

Returns

object

unzip()
TypeScript
unzip(): boolean

Defined in: src/registry-client/src/cache-entry.ts:582

Un-gzip encode the body. Returns true if it was previously gzip (so something was done), otherwise returns false.

Returns

boolean

decode()
TypeScript
static decode(buffer, options): CacheEntry

Defined in: src/registry-client/src/cache-entry.ts:696

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.

Parameters
ParameterType
bufferUint8Array
optionsCacheEntryOptions
Returns

CacheEntry

decodeHead()
TypeScript
static decodeHead(buffer): CacheEntry

Defined in: src/registry-client/src/cache-entry.ts:678

Decode only the status/headers from an encoded cache buffer. The body is not read; headSize records how many bytes the head occupies so a later encodeHead() can be patched in place.

Parameters
ParameterType
bufferUint8Array
Returns

CacheEntry

isGzipEntry()
TypeScript
static isGzipEntry(buffer): boolean

Defined in: src/registry-client/src/cache-entry.ts:733

Parameters
ParameterType
bufferUint8Array
Returns

boolean

isTarballEntry()
TypeScript
static isTarballEntry(buffer): boolean

Defined in: src/registry-client/src/cache-entry.ts:744

Head-only check for a 200 non-JSON body with an integrity header, i.e. a tarball the global store can be built from.

Parameters
ParameterType
bufferUint8Array
Returns

boolean

Type Aliases

CacheEntryOptions

TypeScript
type CacheEntryOptions = object;

Defined in: src/registry-client/src/cache-entry.ts:77

Type declaration

NameTypeDescription
body?Uint8ArrayAn optional body to use. Adopted as-is (no copy). The caller must not mutate or reuse it. Used when decoding a cache entry from a buffer. Do not call addBody after providing this. Worker-thread transfers must copy or structuredClone first so the cache ArrayBuffer is not detached.
contentLength?numberAn optional content length of the body to use, if undefined the content-length header will be used.
integrity?IntegrityThe expected integrity value for this response body
stale-while-revalidate-factor?numberIf 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.
trustIntegrity?booleanWhether 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.

JSONObj

TypeScript
type JSONObj = Record<string, JSONField>;

Defined in: src/registry-client/src/cache-entry.ts:36


Previous@vltpkg/registry-clientNextindex

On this page

  • Classes
  • CacheEntry
  • Type Aliases
  • CacheEntryOptions
  • JSONObj

Deploy your package on vlt.io

Publish scoped and private packages, manage organizations and access, and give every developer and CI environment a consistent source for public and private JavaScript dependencies.

Publish now