Options
All
  • Public
  • Public/Protected
  • All
Menu

Class 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.

Hierarchy

  • Fetcher

Implements

  • CallbackifyInterface

Index

Constructors

constructor

Properties

_fetch

_fetch: Fetch

appNode

appNode: BlankNode

Denoting this session

fetchCallbacks

fetchCallbacks: FetchCallbacks

fetchCallbacks[uri].push(callback)

fetchQueue

fetchQueue: FetchQueue

fireCallbacks

fireCallbacks: Function

Methods added by calling Util.callbackify in the constructor

handlers

handlers: Array<Handler>

lookedUp

lookedUp: BooleanMap

mediatypes

mediatypes: MediatypesMap

nonexistent

nonexistent: BooleanMap

Keep track of explicit 404s -> we can overwrite etc

ns

ns: object

Type declaration

redirectedTo

redirectedTo: Record<string, string>

Redirected from key uri to value uri

requested

requested: RequestedMap

this.requested[uri] states: undefined no record of web access or records reset true has been requested, fetch in progress 'done' received, Ok 401 Not logged in 403 HTTP status unauthorized 404 Resource does not exist. Can be created etc. 'redirected' In attempt to counter CORS problems retried. 'parse_error' Parse error 'unsupported_protocol' URI is not a protocol Fetcher can deal with other strings mean various other errors.

store

timeout

timeout: number

timeouts

timeouts: TimeOutsMap

List of timeouts associated with a requested URL

Static CONTENT_TYPE_BY_EXT

CONTENT_TYPE_BY_EXT: Record<string, string>

Static HANDLERS

HANDLERS: object

Type declaration

  • [handlerName: number]: Handler

Static crossSiteProxyTemplate

crossSiteProxyTemplate: any

Methods

acceptString

  • acceptString(): string

addFetchCallback

  • addFetchCallback(uri: string, callback: UserCallback): void
  • Parameters

    • uri: string
    • callback: UserCallback

    Returns void

addHandler

  • addHandler(handler: Handler): void

addStatus

  • addStatus(req: BlankNode, statusMessage: string): void
  • Records a status message (as a literal node) by appending it to the request's metadata status collection.

    Parameters

    Returns void

addType

cleanupFetchRequest

  • cleanupFetchRequest(originalUri: string, _options: any, timeout: number): void
  • Parameters

    • originalUri: string
    • _options: any

      DEPRECATED

    • timeout: number

    Returns void

createContainer

  • createContainer(parentURI: string, folderName: string, data: string): Promise<Response>
  • Parameters

    • parentURI: string

      URI of parent container

    • folderName: string

      Optional folder name (slug)

    • data: string

      Optional folder metadata

    Returns Promise<Response>

createIfNotExists

  • createIfNotExists(doc: RDFlibNamedNode, contentType?: "text/turtle", data?: string): Promise<ExtendedResponse>
  • 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

    • doc: RDFlibNamedNode

      The resource

    • Default value contentType: "text/turtle" = TurtleContentType
    • Default value data: string = ""

    Returns Promise<ExtendedResponse>

delete

  • delete(uri: string, options?: Options): Promise<ExtendedResponse>
  • Parameters

    • uri: string
    • Optional options: Options

    Returns Promise<ExtendedResponse>

doneFetch

  • doneFetch(options: object & Options, response: ExtendedResponse): Response
  • Parameters

    • options: object & Options
    • response: ExtendedResponse

    Returns Response

failFetch

  • failFetch(options: object & Options, errorMessage: string, statusCode: StatusValues, response?: ExtendedResponse): Promise<FetchError>
  • 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

    • options: object & Options
    • errorMessage: string
    • statusCode: StatusValues
    • Optional response: ExtendedResponse

    Returns Promise<FetchError>

fetchUri

  • fetchUri(docuri: string, options: AutoInitOptions): Promise<ExtendedResponse | FetchError>
  • (The promise chain ends in either a failFetch() or a doneFetch())

    Parameters

    • docuri: string
    • options: AutoInitOptions

    Returns Promise<ExtendedResponse | FetchError>

    fetch() result or an { error, status } object

getHeader

  • getHeader(doc: NamedNode, header: string): undefined | string[]
  • Looks up response header.

    Parameters

    Returns undefined | string[]

    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 ] }

getState

  • getState(docuri: string): any

guessContentType

  • guessContentType(uri: string): ContentType | undefined

handleError

  • handleError(response: ExtendedResponse | Error, docuri: string, options: AutoInitOptions): Promise<ExtendedResponse | FetchError>
  • Called when there's a network error in fetch(), or a response with status of 0.

    Parameters

    • response: ExtendedResponse | Error
    • docuri: string
    • options: AutoInitOptions

    Returns Promise<ExtendedResponse | FetchError>

handleResponse

  • handleResponse(response: ExtendedResponse, docuri: string, options: AutoInitOptions): Promise<FetchError | ExtendedResponse> | ExtendedResponse
  • Handle fetch() response

    Parameters

    • response: ExtendedResponse
    • docuri: string
    • options: AutoInitOptions

    Returns Promise<FetchError | ExtendedResponse> | ExtendedResponse

handlerForContentType

  • handlerForContentType(contentType: string, response: ExtendedResponse): Handler | null
  • Parameters

    • contentType: string
    • response: ExtendedResponse

    Returns Handler | null

initFetchOptions

  • initFetchOptions(uri: string, options: Options): AutoInitOptions
  • Parameters

    • uri: string
    • options: Options

    Returns AutoInitOptions

invalidateCache

  • invalidateCache(iri: string | NamedNode): void

isCrossSite

  • isCrossSite(uri: string): boolean
  • Tests whether a request is being made to a cross-site URI (for purposes of retrying with a proxy)

    Parameters

    • uri: string

    Returns boolean

isPending

  • isPending(docuri: string): boolean

linkData

  • linkData(originalUri: NamedNode, rel: string, uri: string, why: Quad_Graph, reverse?: undefined | false | true): void

load

  • load<T>(uri: T, options?: Options): T extends (string | NamedNode)[] ? Promise<Response>[] : Promise<Response>
  • 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 array 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.

    Type parameters

    Parameters

    • uri: T
    • Default value options: Options = {}

    Returns T extends (string | NamedNode)[] ? Promise<Response>[] : Promise<Response>

lookUpThing

  • Looks up something. Looks up all the URIs a things has.

    Parameters

    • term: Quad_Subject

      canonical term for the thing whose URI is to be dereferenced

    • rterm: Quad_Subject

      the resource which referred to this (for tracking bad links)

    Returns Promise<Response> | Promise<Response>[]

normalizedContentType

  • normalizedContentType(options: AutoInitOptions, headers: Headers): ContentType | string | null

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

    Parameters

    Returns void

nowOrWhenFetched

  • nowOrWhenFetched(uriIn: string | NamedNode, p2?: UserCallback | Options, userCallback?: UserCallback, options?: Options): void
  • 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.

    Parameters

    • uriIn: string | NamedNode
    • Optional p2: UserCallback | Options
    • Optional userCallback: UserCallback
    • Default value options: Options = {}

    Returns void

objectRefresh

parseLinkHeader

pendingFetchPromise

  • pendingFetchPromise(uri: string, originalUri: string, options: AutoInitOptions): Promise<Result>
  • Parameters

    • uri: string
    • originalUri: string
    • options: AutoInitOptions

    Returns Promise<Result>

putBack

  • putBack(uri: NamedNode | string, options?: Options): Promise<Response>
  • Writes back to the web what we have in the store for this uri

    Parameters

    • uri: NamedNode | string
    • Default value options: Options = {}

    Returns Promise<Response>

redirectToProxy

  • redirectToProxy(newURI: string, options: AutoInitOptions): Promise<ExtendedResponse | FetchError>
  • Sends a new request to the specified uri. (Extracted from onerrorFactory())

    Parameters

    • newURI: string
    • options: AutoInitOptions

    Returns Promise<ExtendedResponse | FetchError>

refresh

  • refresh(term: NamedNode, userCallback?: UserCallback): void

refreshIfExpired

  • refreshIfExpired(term: NamedNode, userCallback: UserCallback): void

retract

retryNoCredentials

  • retryNoCredentials(docuri: string, options: any): Promise<Result>
  • Parameters

    • docuri: string
    • options: any

    Returns Promise<Result>

saveErrorResponse

  • saveErrorResponse(response: ExtendedResponse, responseNode: Quad_Subject): Promise<void>

saveRequestMetadata

  • saveRequestMetadata(docuri: string, options: AutoInitOptions): void
  • Parameters

    • docuri: string
    • options: AutoInitOptions

    Returns void

saveResponseMetadata

  • saveResponseMetadata(response: Response, options: object & Options): BlankNode

setRequestTimeout

  • setRequestTimeout(uri: string, options: object & Options): Promise<number | FetchError>
  • Parameters

    • uri: string
    • options: object & Options

    Returns Promise<number | FetchError>

unload

webCopy

  • webCopy(here: string, there: string, contentType: any): Promise<ExtendedResponse>
  • Parameters

    • here: string
    • there: string
    • contentType: any

    Returns Promise<ExtendedResponse>

webOperation

  • webOperation(method: HTTPMethods, uriIn: string | NamedNode, options?: Options): Promise<ExtendedResponse>
  • 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

    • method: HTTPMethods
    • uriIn: string | NamedNode
    • Default value options: Options = {}

    Returns Promise<ExtendedResponse>

Static crossSiteProxy

  • crossSiteProxy(uri: string): undefined | any
  • Parameters

    • uri: string

    Returns undefined | any

Static offlineOverride

  • offlineOverride(uri: string): string

Static proxyIfNecessary

  • proxyIfNecessary(uri: string): any

Static setCredentials

  • setCredentials(requestedURI: string, options?: Options): void
  • Decide on credentials using old XXHR api or new fetch() one

    Parameters

    • requestedURI: string
    • Default value options: Options = {}

    Returns void

Static unsupportedProtocol

  • unsupportedProtocol(uri: string): boolean
  • Tests whether the uri's protocol is supported by the Fetcher.

    Parameters

    • uri: string

    Returns boolean