Class: RDFRepositoryClient

RDFRepositoryClient(repositoryClientConfig)

RDF repository client implementation realizing specific operations.

Constructor

new RDFRepositoryClient(repositoryClientConfig)

Parameters:
Name Type Description
repositoryClientConfig RepositoryClientConfig
Author:
  • Mihail Radkov
  • Svilen Velikov
Source:

Methods

add(payload) → {Promise.<void>}

Saves the provided statement payload in the repository.

The payload will be converted to a quad or a collection of quads in case there are multiple contexts.

After the conversion, the produced quad(s) will be serialized to Turtle or Trig format and send to the repository as payload.

See #addQuads().

Parameters:
Name Type Description
payload AddStatementPayload

holding request parameters

Source:
Throws:

if the payload is not provided or the payload has null subject, predicate and/or object

Type
Error
Returns:

promise that will be resolved if the addition is successful or rejected in case of failure

Type
Promise.<void>

addFile(filePath, contentType, contextopt, baseURIopt) → {Promise.<void>}

Uploads the file specified by the provided file path to the server.

See #upload

Parameters:
Name Type Attributes Description
filePath string

path to a file to be streamed to the server

contentType string

MIME type of the file's content

context string | Array.<string> <optional>

restricts the operation to the given context. Will be encoded as N-Triple if it is not already one

baseURI string <optional>

used to resolve relative URIs in the data

Source:
Returns:

a promise that will be resolved when the file has been successfully consumed by the server

Type
Promise.<void>

addQuads(quads, contextopt, baseURIopt) → {Promise.<void>}

Serializes the provided quads to Turtle format and sends them to the repository as payload.

If any of the quads have a graph, then the text will be serialized to the Trig format which is an extended version of Turtle supporting contexts.

Parameters:
Name Type Attributes Description
quads Array.<Quad>

collection of quads to be sent as Turtle/Trig text

context string | Array.<string> <optional>

restricts the insertion to the given context. Will be encoded as N-Triple if it is not already one

baseURI string <optional>

used to resolve relative URIs in the data

Source:
Returns:

promise that will be resolved if the addition is successful or rejected in case of failure

Type
Promise.<void>

beginTransaction(isolationLevelopt) → {Promise.<TransactionalRepositoryClient>}

Starts a transaction and produces a TransactionalRepositoryClient.

The transactions ID is extracted from the location header and is used as endpoint for the produced TransactionalRepositoryClient.

If no transaction isolation level is provided, the server will use its default isolation level.

Parameters:
Name Type Attributes Description
isolationLevel string <optional>

an optional parameter to specify the transaction's level of isolation; for possible values see TransactionIsolationLevel

Source:
Returns:

transactional client

Type
Promise.<TransactionalRepositoryClient>

deleteAllStatements() → {Promise.<void>}

Deletes all statements in the repository.

Source:
Returns:

promise that will be resolved if the deletion is successful or rejected in case of failure

Type
Promise.<void>

deleteNamespace(prefix) → {Promise.<void>}

Deletes a namespace that corresponds to the given prefix.

For example if rdfs is provided as prefix that would delete the following namespace: http://www.w3.org/2000/01/rdf-schema#

Note: This method should be invoked only with prefixes. Anything else would result in an error from the server.

Parameters:
Name Type Description
prefix string

prefix of the namespace to be deleted

Source:
Throws:

if the prefix parameter is not provided

Type
Error
Returns:

promise that will be resolved if the deletion is successful

Type
Promise.<void>

deleteNamespaces() → {Promise.<void>}

Deletes all namespace declarations in the repository.

Source:
Returns:

promise that will be resolved after successful deletion

Type
Promise.<void>

deleteStatements(subjectopt, predicateopt, objectopt, contextsopt) → {Promise.<void>}

Deletes statements in the repository based on the provided subject, predicate, object and or contexts. Each of them is optional and acts as statements filter which effectively narrows the scope of the deletion.

Providing context or contexts will restricts the operation to one or more specific contexts in the repository.

Provided values will be automatically converted to N-Triples if they are not already encoded as such.

Parameters:
Name Type Attributes Description
subject String <optional>

resource subject

predicate String <optional>

resource predicate

object String <optional>

resource object

contexts Array.<String> | String <optional>

resource or resources context

Source:
Returns:

promise that will be resolved if the deletion is successful or rejected in case of failure

Type
Promise.<void>

download(payload) → {Promise.<WritableStream>}

Fetch rdf data from statements endpoint using provided parameters.

The request is configured so that expected response should be a readable stream.

Provided request params will be automatically converted to N-Triples if they are not already encoded as such.

Parameters:
Name Type Description
payload GetStatementsPayload

is an object holding request params

Source:
Returns:

the client can subscribe to the readable stream events and consume the emitted strings depending on the provided response type as soon as they are available.

Type
Promise.<WritableStream>

get(payload) → {Promise.<(string|Quad)>}

Fetch rdf data from statements endpoint using provided parameters.

Provided values will be automatically converted to N-Triples if they are not already encoded as such.

Parameters:
Name Type Description
payload GetStatementsPayload

is an object holding the request parameters.

Source:
Returns:

resolves with plain string or Quad according to provided response type.

Type
Promise.<(string|Quad)>

getLogger()

Source:

getNamespace(prefix) → {Promise.<NamedNode>}

Retrieves the namespace for the given prefix as NamedNode.

For example if rdfs is provided as prefix that would result in a NamedNode corresponding to following namespace: http://www.w3.org/2000/01/rdf-schema#

Note: This method should be invoked only with prefixes. Anything else would result in an error from the server.

Parameters:
Name Type Description
prefix string

prefix of the namespace to be retrieved

Source:
Throws:

if the prefix parameter is not supplied

Type
Error
Returns:

promise resolving to NamedNode

Type
Promise.<NamedNode>

getNamespaces() → {Promise.<Array.<Namespace>>}

Retrieves all present namespaces as a collection of Namespace.

Source:
Returns:

promise resolving to a collection of Namespace

Type
Promise.<Array.<Namespace>>

getSize(contextopt) → {Promise.<number>}

Retrieves the size of the repository.

Effectively returns how much statements are in the repository.

If one or multiple context are provided, the operation will be restricted upon each of them.

Parameters:
Name Type Attributes Description
context string | Array.<string> <optional>

context or contexts to restrict the size calculation. Will be encoded as N-Triple if it is not already one

Source:
Returns:

a promise resolving to the total number of statements in the repository

Type
Promise.<number>

initServices()

Instantiates dependent services.

Source:

overwrite(readStream, contentType, context, baseURIopt) → {Promise.<void>}

Executes a PUT request against the /statements endpoint. The statements which have to be updated are provided through a readable stream. This method is useful for overriding large set of statements that might be provided as a readable stream e.g. reading from file.

Parameters:
Name Type Attributes Description
readStream ReadableStream
contentType string
context NamedNode | string

restrict the operation. Will be encoded as N-Triple if it is not already one

baseURI string <optional>

optional uri against which any relative URIs found in the data would be resolved.

Source:
Returns:

a promise that will be resolved when the stream has been successfully consumed by the server

Type
Promise.<void>

putFile(filePath, contentType, contextopt, baseURIopt) → {Promise.<void>}

Uploads the file specified by the provided file path to the server overwriting any data in the server's repository.

The overwrite will be restricted if the context parameter is specified.

See #overwrite

Parameters:
Name Type Attributes Description
filePath string

path to a file to be streamed to the server

contentType string

MIME type of the file's content

context string <optional>

restricts the operation to the given context. Will be encoded as N-Triple if it is not already one

baseURI string <optional>

used to resolve relative URIs in the data

Source:
Returns:

a promise that will be resolved when the file has been successfully consumed by the server

Type
Promise.<void>

putQuads(quads, contextopt, baseURIopt) → {Promise.<void>}

Overwrites the repository's data by serializing the provided quads to Turtle format and sending them to the repository as payload.

If any of the quads have a graph, then the text will be serialized to the Trig format which is an extended version of Turtle supporting contexts.

The overwrite will be restricted if the context parameter is specified.

Parameters:
Name Type Attributes Description
quads Array.<Quad>

collection of quads to be sent as Turtle/Trig text

context string | Array.<string> <optional>

restricts the insertion to the given context. Will be encoded as N-Triple if it is not already one

baseURI string <optional>

used to resolve relative URIs in the data

Source:
Returns:

promise that will be resolved if the overwrite is successful or rejected in case of failure

Type
Promise.<void>

query(payload) → {Promise}

Executes request to query a repository.

Only POST request with a valid QueryPayload is supported.

Parameters:
Name Type Description
payload GetQueryPayload

is an object holding request parameters required by the query POST endpoint.

Source:
Throws:

if the payload is misconfigured

Type
Error
Returns:

the client can subscribe to the stream events and consume the emitted strings or Quads depending on the provided response type as soon as they are available.

Type
Promise

saveNamespace(prefix, namespace) → {Promise.<void>}

Creates or updates the namespace for the given prefix.

If the provided prefix or namespace parameter is not a string or NamedNode then the method will throw an error.

Parameters:
Name Type Description
prefix string

prefix of the namespace to be created/updated

namespace string | NamedNode

the namespace to be created/updated

Source:
Throws:

if the prefix or namespace parameter are not provided

Type
Error
Returns:

promise that will be resolved if the create/update request is successful

Type
Promise.<void>

update(payload) → {Promise.<void>}

Executes a request with a sparql query against /statements endpoint to update repository data.

If contentType is set to application/x-www-form-urlencoded then query and request parameters from the payload are encoded as query string and sent as request body.

If contentType is set to application/sparql-update then the query is sent unencoded as request body.

Parameters:
Name Type Description
payload UpdateQueryPayload
Source:
Throws:

if the payload is misconfigured

Type
Error
Returns:

promise that will be resolved if the update is successful or rejected in case of failure

Type
Promise.<void>

upload(readStream, contentType, contextopt, baseURIopt) → {Promise.<void>}

Executes a POST request against the /statements endpoint. The statements which have to be added are provided through a readable stream. This method is useful for library client who wants to upload a big data set into the repository.

Parameters:
Name Type Attributes Description
readStream ReadableStream
contentType string

is one of RDF mime type formats, application/x-rdftransaction' for a transaction document or application/x-www-form-urlencoded

context NamedNode | string <optional>

optional context to restrict the operation. Will be encoded as N-Triple if it is not already one

baseURI string <optional>

optional uri against which any relative URIs found in the data would be resolved.

Source:
Returns:

a promise that will be resolved when the stream has been successfully consumed by the server

Type
Promise.<void>