@vltpkg/registry-client/cache-entry
Classes
CacheEntry
Defined in: src/registry-client/src/cache-entry.ts:111
Constructors
new CacheEntry()
new CacheEntry( statusCode, headers, __namedParameters): CacheEntry
Defined in: src/registry-client/src/cache-entry.ts:132
Parameters
statusCode
number
headers
Uint8Array
<ArrayBufferLike
>[]
__namedParameters
CacheEntryOptions
= {}
Returns
Accessors
_body
Get Signature
get _body(): Uint8Array
Defined in: src/registry-client/src/cache-entry.ts:331
Returns the body as a single Uint8Array, concatenating parts if needed.
Returns
Uint8Array
body
Get Signature
get body(): Uint8Array<ArrayBufferLike> | Record<string, any>
Defined in: src/registry-client/src/cache-entry.ts:435
Returns
Uint8Array
<ArrayBufferLike
> | Record
<string
, any
>
cacheControl
Get Signature
get cacheControl(): CacheControl
Defined in: src/registry-client/src/cache-entry.ts:250
Returns
CacheControl
contentType
Get Signature
get contentType(): string
Defined in: src/registry-client/src/cache-entry.ts:272
Returns
string
date
Get Signature
get date(): undefined | Date
Defined in: src/registry-client/src/cache-entry.ts:231
Returns
undefined
| Date
headers
Get Signature
get headers(): Uint8Array<ArrayBufferLike>[]
Defined in: src/registry-client/src/cache-entry.ts:324
Returns
Uint8Array
<ArrayBufferLike
>[]
integrity
Get Signature
get integrity(): undefined | `sha512-${string}`
Defined in: src/registry-client/src/cache-entry.ts:394
Returns
undefined
| `sha512-${string}`
Set Signature
set integrity(i): void
Defined in: src/registry-client/src/cache-entry.ts:388
Parameters
i
undefined
| `sha512-${string}`
Returns
void
integrityActual
Get Signature
get integrityActual(): `sha512-${string}`
Defined in: src/registry-client/src/cache-entry.ts:374
Returns
`sha512-${string}`
Set Signature
set integrityActual(i): void
Defined in: src/registry-client/src/cache-entry.ts:383
Parameters
i
`sha512-${string}`
Returns
void
isGzip
Get Signature
get isGzip(): boolean
Defined in: src/registry-client/src/cache-entry.ts:455
Returns
boolean
isJSON
Get Signature
get isJSON(): boolean
Defined in: src/registry-client/src/cache-entry.ts:440
Returns
boolean
maxAge
Get Signature
get maxAge(): number
Defined in: src/registry-client/src/cache-entry.ts:239
Returns
number
staleWhileRevalidate
Get Signature
get staleWhileRevalidate(): boolean
Defined in: src/registry-client/src/cache-entry.ts:258
Returns
boolean
statusCode
Get Signature
get statusCode(): number
Defined in: src/registry-client/src/cache-entry.ts:321
Returns
number
valid
Get Signature
get valid(): boolean
Defined in: src/registry-client/src/cache-entry.ts:283
Returns
boolean
Methods
[kCustomInspect]()
kCustomInspect: string
Defined in: src/registry-client/src/cache-entry.ts:222
Parameters
depth
number
options
InspectOptions
Returns
string
addBody()
addBody(b): void
Defined in: src/registry-client/src/cache-entry.ts:307
Add contents to the entry body.
Parameters
b
Uint8Array
Returns
void
buffer()
buffer(): Buffer
Defined in: src/registry-client/src/cache-entry.ts:425
Return the body of the entry as a Buffer
Returns
Buffer
checkIntegrity()
checkIntegrity(context): this is CacheEntry & { integrity: `sha512-${string}` }
Defined in: src/registry-client/src/cache-entry.ts:358
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.
Parameters
context
ErrorCauseOptions
= {}
Returns
this is CacheEntry & { integrity: `sha512-${string}` }
encode()
encode(): Buffer
Defined in: src/registry-client/src/cache-entry.ts:587
Encode the entry as a single Buffer for writing to the cache
Returns
Buffer
getHeader()
getHeader(h): undefined | Uint8Array<ArrayBufferLike>
Defined in: src/registry-client/src/cache-entry.ts:401
Give it a key, and it’ll return the buffer of that header value
Parameters
h
string
Returns
undefined
| Uint8Array
<ArrayBufferLike
>
getHeaderString()
getHeaderString(h): undefined | string
Defined in: src/registry-client/src/cache-entry.ts:408
Give it a key, and it’ll return the decoded string of that header value
Parameters
h
string
Returns
undefined
| string
json()
json(): JSONObj
Defined in: src/registry-client/src/cache-entry.ts:509
Parse the entry body as JSON and return the result
Returns
setHeader()
setHeader(h, value): void
Defined in: src/registry-client/src/cache-entry.ts:418
Set a header to a specific value
Parameters
h
string
value
string
| Uint8Array
<ArrayBufferLike
>
Returns
void
text()
text(): string
Defined in: src/registry-client/src/cache-entry.ts:501
Return the body of the entry as utf8 text Automatically unzips if the content is gzip encoded
Returns
string
toJSON()
toJSON(): object
Defined in: src/registry-client/src/cache-entry.ts:182
Returns
object
unzip()
unzip(): boolean
Defined in: src/registry-client/src/cache-entry.ts:476
Un-gzip encode the body. Returns true if it was previously gzip (so something was done), otherwise returns false.
Returns
boolean
decode()
static decode(buffer): CacheEntry
Defined in: src/registry-client/src/cache-entry.ts:522
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
buffer
Uint8Array
Returns
isGzipEntry()
static isGzipEntry(buffer): boolean
Defined in: src/registry-client/src/cache-entry.ts:577
Parameters
buffer
Uint8Array
Returns
boolean
Type Aliases
CacheEntryOptions
type CacheEntryOptions = object
Defined in: src/registry-client/src/cache-entry.ts:63
Type declaration
body?
optional body: Uint8Array;
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.
contentLength?
optional contentLength: number;
An optional content length of the body to use, if undefined the content-length header will be used.
integrity?
optional integrity: Integrity;
The expected integrity value for this response body
stale-while-revalidate-factor?
optional stale-while-revalidate-factor: number;
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.
trustIntegrity?
optional trustIntegrity: boolean;
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.
JSONObj
type JSONObj = Record<string, JSONField>
Defined in: src/registry-client/src/cache-entry.ts:36