Class: TransactionalRepositoryClient

TransactionalRepositoryClient(repositoryClientConfig)

Transactional RDF repository client implementation realizing transaction specific operations.

This client won't perform retries to multiple server endpoints due to when a transaction is started all operations must be performed to the server where it was started.

The transaction is active until #commit or #rollback is invoked. After that each sequential request will result in an error.

Constructor

new TransactionalRepositoryClient(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 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>

commit() → {Promise.<void>}

Commits the current transaction by applying any changes that have been sent to the server.

This effectively makes the transaction inactive.

Source:
Returns:

that will be resolved after successful commit

Type
Promise.<void>

decorateServiceRequest(serviceRequest, action)

Updates the http request builder in the provided service request for executing requests in a transaction.

Parameters:
Name Type Description
serviceRequest ServiceRequest

the request to mutate

action string

the transaction action

Source:

deleteData(data) → {Promise.<void>}

Deletes the statements in the provided Turtle or Trig formatted data.

Parameters:
Name Type Description
data string

payload data in Turtle or Trig format

Source:
Throws:

if no data is provided for deleting

Type
Error
Returns:

promise resolving after the data has been deleted successfully

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>

execute()

Source:
Throws:

if the transaction has been committed or rollbacked

Type
Error

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

Fetch rdf data from statements endpoint using provided parameters.

The fetched data depends on the transaction isolation level.

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:

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

Retrieves the size of the repository during the transaction and its isolation level.

Repository size is the amount of statements present.

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

if provided, the size calculation will be restricted. Will be encoded as N-Triple if it is not already one

Source:
Returns:

a promise resolving to the size of the repo

Type
Promise.<number>

initServices()

Instantiates dependent services.

Source:

isActive() → {boolean}

Source:
Returns:

true if the transaction is active or false otherwise

Type
boolean

query(payload) → {Promise}

Executes request to query a repository.

Parameters:
Name Type Description
payload GetQueryPayload

is an object holding request parameters

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

rollback() → {Promise.<void>}

Rollbacks the current transaction reverting any changes in the server.

This effectively makes the transaction inactive.

Source:
Returns:

that will be resolved after successful rollback

Type
Promise.<void>

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

Executes a request with a SPARQL query to update repository data.

Parameters:
Name Type Description
payload UpdateQueryPayload

request object containing the query

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

Streams data to the repository from the provided readable stream.

This method is useful for library client who wants to upload a big data set into the repository during a transaction

Parameters:
Name Type Attributes Description
readStream ReadableStream

stream with the data to be uploaded

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>