Class: Fetcher

Fetcher()

Fetcher The Fetcher object is a helper object for a quadstore which turns it from an offline store to an online store. The fetcher deals with loading data files rom the web, figuring how to parse them. It will also refresh, remove, the data and put back the fata to the web.

Constructor

new Fetcher()

Source:

Methods

(static) offlineOverride(uri) → {string}

Parameters:
Name Type Description
uri string
Source:
Returns:
Type
string

(static) setCredentials(requestedURI, options)

Decide on credentials using old XXHR api or new fetch() one
Parameters:
Name Type Description
requestedURI string
options Object
Source:
Returns:

(static) unsupportedProtocol(uri) → {boolean}

Tests whether the uri's protocol is supported by the Fetcher.
Parameters:
Name Type Description
uri string
Source:
Returns:
Type
boolean

addStatus(req, statusMessage)

Records a status message (as a literal node) by appending it to the request's metadata status collection.
Parameters:
Name Type Description
req BlankNode
statusMessage string
Source:

createContainer(parentURI, folderNameopt, dataopt) → {Promise.<Response>}

Parameters:
Name Type Attributes Description
parentURI string URI of parent container
folderName string <optional>
Optional folder name (slug)
data string <optional>
Optional folder metadata
Source:
Returns:
Type
Promise.<Response>

(async) createIfNotExists(doc) → {Promise}

Create an empty resource if it really does not exist Be absolutely sure something does not exist before creating a new empty file as otherwise existing could be deleted.
Parameters:
Name Type Description
doc NamedNode The resource
Source:
Returns:
Type
Promise

delete(uri, optionsopt) → {Promise.<Response>}

Parameters:
Name Type Attributes Description
uri string
options Object <optional>
Source:
Returns:
Type
Promise.<Response>

failFetch(options, errorMessage, statusCode, response) → {Promise.<Object>}

Records errors in the system on failure: - Adds an entry to the request status collection - Adds an error triple with the fail message to the metadata - Fires the 'fail' callback - Rejects with an error result object, which has a response object if any
Parameters:
Name Type Description
options Object
errorMessage string
statusCode number
response Response // when an fetch() error
Source:
Returns:
Type
Promise.<Object>

fetchUri(docuri, options) → {Promise.<Object>}

(The promise chain ends in either a `failFetch()` or a `doneFetch()`)
Parameters:
Name Type Description
docuri string
options Object
Source:
Returns:
fetch() result or an { error, status } object
Type
Promise.<Object>

getHeader(doc, header) → {Array|undefined}

Looks up response header.
Parameters:
Name Type Description
doc
header
Source:
Returns:
a list of header values found in a stored HTTP response, or [] if response was found but no header found, or undefined if no response is available. Looks for { [] link:requestedURI ?uri; link:response [ httph:header-name ?value ] }
Type
Array | undefined

guessContentType(uri) → {string}

Parameters:
Name Type Description
uri string
Source:
Returns:
Type
string

handleError(response, docuri, options) → {Promise}

Called when there's a network error in fetch(), or a response with status of 0.
Parameters:
Name Type Description
response Response | Error
docuri string
options Object
Source:
Returns:
Type
Promise

handleResponse(response, docuri, options)

Handle fetch() response
Parameters:
Name Type Description
response Response fetch() response object
docuri string
options Object
Source:

handlerForContentType(contentType) → {Handler|null}

Parameters:
Name Type Description
contentType string
Source:
Returns:
Type
Handler | null

initFetchOptions(uri, options) → {Object}

Parameters:
Name Type Description
uri string
options Object
Source:
Returns:
Type
Object

isCrossSite(uri) → {boolean}

Tests whether a request is being made to a cross-site URI (for purposes of retrying with a proxy)
Parameters:
Name Type Description
uri string
Source:
Returns:
Type
boolean

load(uri, options=opt) → {Promise.<Result>}

Promise-based load function Loads a web resource or resources into the store. A resource may be given as NamedNode object, or as a plain URI. an arrsy of resources will be given, in which they will be fetched in parallel. By default, the HTTP headers are recorded also, in the same store, in a separate graph. This allows code like editable() for example to test things about the resource.
Parameters:
Name Type Attributes Default Description
uri Array.<NamedNode> | Array.<string> | NamedNode | string
options= <optional>
{Object}
options.fetch function <optional>
options.referringTerm NamedNode <optional>
Referring term, the resource which referred to this (for tracking bad links)
options.contentType string <optional>
Provided content type (for writes)
options.forceContentType string <optional>
Override the incoming header to force the data to be treated as this content-type (for reads)
options.force boolean <optional>
Load the data even if loaded before. Also sets the `Cache-Control:` header to `no-cache`
options.baseURI Node | string <optional>
docuri Original uri to preserve through proxying etc (`xhr.original`).
options.proxyUsed boolean <optional>
Whether this request is a retry via a proxy (generally done from an error handler)
options.withCredentials boolean <optional>
flag for XHR/CORS etc
options.clearPreviousData boolean <optional>
Before we parse new data, clear old, but only on status 200 responses
options.noMeta boolean <optional>
Prevents the addition of various metadata triples (about the fetch request) to the store
options.noRDFa boolean <optional>
Source:
Returns:
Type
Promise.<Result>

lookUpThing(term, rterm) → {Promise}

Looks up something. Looks up all the URIs a things has.
Parameters:
Name Type Description
term NamedNode canonical term for the thing whose URI is to be dereferenced
rterm NamedNode the resource which referred to this (for tracking bad links)
Source:
Returns:
Type
Promise

normalizedContentType(options, headers) → {string}

Parameters:
Name Type Description
options Object
headers Headers
Source:
Returns:
Type
string

nowKnownAs()

Note two nodes are now smushed If only one was flagged as looked up, then the new node is looked up again, which will make sure all the URIs are dereferenced
Source:

nowOrWhenFetched()

Asks for a doc to be loaded if necessary then calls back Calling methods: nowOrWhenFetched (uri, userCallback) nowOrWhenFetched (uri, options, userCallback) nowOrWhenFetched (uri, referringTerm, userCallback, options) <-- old nowOrWhenFetched (uri, referringTerm, userCallback) <-- old Options include: referringTerm The document in which this link was found. this is valuable when finding the source of bad URIs force boolean. Never mind whether you have tried before, load this from scratch. forceContentType Override the incoming header to force the data to be treated as this content-type. Callback function takes: ok True if the fetch worked, and got a 200 response. False if any error happened errmessage Text error message if not OK. response The fetch Response object (was: XHR) if there was was one includes response.status as the HTTP status if any.
Source:

pendingFetchPromise(uri, originalUri, options) → {Promise.<Result>}

Parameters:
Name Type Description
uri string
originalUri string
options Object
Source:
Returns:
Type
Promise.<Result>

putBack(uri, options=opt) → {Promise}

Writes back to the web what we have in the store for this uri
Parameters:
Name Type Attributes Description
uri Node | string
options= <optional>
Source:
Returns:
Type
Promise

redirectToProxy(newURI, options) → {Promise.<Response>}

Sends a new request to the specified uri. (Extracted from `onerrorFactory()`)
Parameters:
Name Type Description
newURI string
options Object
Source:
Returns:
Type
Promise.<Response>

saveRequestMetadata(docuri, options)

Parameters:
Name Type Description
docuri
options
Source:

webOperation(method, uri, options) → {Promise.<Response>}

A generic web opeation, at the fetch() level. does not invole the quadstore. Returns promise of Response If data is returned, copies it to response.responseText before returning
Parameters:
Name Type Description
method
uri or NamedNode
options
Source:
Returns:
Type
Promise.<Response>