FetchResponse

@maynoothuniversity/caching-json-databridge~ FetchResponse

A class representing both data returned from a request to a datasource, and its matching metadata.

The metadata consists of name-value pairs, and may include the following:

  • streamName - the passed or generated stream name used for the request as a string.
  • cacheRead - only present if the data in the response was read from a cache. If present, will be a plain object indexed by:
    • path - the path to the file the cache was read from as a string.
    • timestamp - the time the cached data was written to the cache as an ISO8601 string.
  • cacheWrite - only present if the response was written to a cache file. If present, will be a plain object indexed by:
    • path - the file the data was cached to
    • timestamp - the time the data was cached at as an ISO8601 string.

Constructor

Fcnew FetchResponse(request, metaopt)

Parameters:
Name Type Attributes Description
request FetchRequest

A reference to the data fetch request object this response answers.

meta Object <optional>

an object contaning metadata

Throws:

a validation error is thrown if parameter validation fails.

Type
external:validateParams.ValidationError

Methods

FallMeta() → {Object}

A read-only accessor method to get all metadata. A shallow copy is returned.

See:
  • external:validateParams.shallowCopy
Returns:
Type:
Object

FdataPromise(dataPromiseopt) → {Promise}

A read/write accessor for the promise of the data associated with this response.

Parameters:
Name Type Attributes Description
dataPromise Promise <optional>

if present, this function will behave as a setter.

Throws:

a type error is thrown if a parameter is passed and it's not a promise.

Type
TypeError
Returns:
Type:
Promise

Regardless of whether or not a new promise was passed, if there is a current data promise it will be returned, otherwise, undefined will be returned.

Fmeta(metaName, newValopt)

A read/write accessor for individual pieces of metadata associated with this response.

Parameters:
Name Type Attributes Description
metaName string

the name of desired piece of metadata.

newVal * <optional>

if present, will set the value of the requested piece of metadata to this value.

Throws:

a validation error is thrown if parameter validation fails.

Type
external:validateParams.ValidationError
Returns:
  • always returns the current value for a given metadata name, which could be undefined.

Frequest() → {FetchRequest}

A read-only accessor for the request this response is related to.

Returns:
Type:
FetchRequest