Universal Javascript fetch wrapper for communicating with the Stardog HTTP server.
This framework wraps all the functionality of a client for the Stardog DBMS, and provides access to a full set of functions such as executing SPARQL queries, administrative tasks on Stardog, and the use of the Reasoning API.
All the implementation uses the HTTP protocol, since most of Stardog functionality is available using this protocol. For more information, go to the Stardog's HTTP Programming documentation.
This is a universal library and as such can be used in both the browser and Node.js.
To install stardog.js run:
npm install stardog
To get started, just clone the project. You'll need a local copy of Stardog to be able to run the tests. For more information on starting the Stardog DB service and how it works, go to Stardog's documentation, where you'll find everything you need to get up and running with Stardog.
Go to http://stardog.com, download and install the database and load the data provided in data/
using the script in the repository.
- Start the Stardog server
stardog-admin server start
- Install
stardog.js
dependencies:
npm install
In order to contribute changes, all test cases must pass. With the Stardog server running, execute the following command to run all test cases in test/spec
:
npm test
Fork, clone and develop, write or amend tests, and then open a PR. All PRs go against "master". This project uses prettier on file commit, so don't worry about style as it'll just get rewritten when you commit your changes.
The current version of stardog.js has been tested against version 5.0.0 of Stardog. You are encouraged to use this library if you are using version 5 or greater of Stardog. However, there is very little code that is version specific in stardog.js. It is essentially just a convenience wrapper around fetch
. It is very likely that many of the exposed methods will work on older versions of Stardog, but this has not been tested.
If you are using a really old version of Stardog (<= 3.0.0) you should stick with the legacy version of the library which is version 0.3.1.
All versions of stardog.js prior to v1.0.0 have been discontinued and will not receive updates of any kind. If you are using a legacy version of stardog.js you can find the original documentation here. The most recent legacy version is 0.3.1.
const { Connection, query } = require('stardog');
const conn = new Connection({
username: 'admin',
password: 'admin',
endpoint: 'http://localhost:5820',
});
query.execute(conn, 'myDatabaseName', 'select distinct ?s where { ?s ?p ?o }', {
limit: 10,
offset: 0,
}).then(({ body }) => {
console.log(body.results.bindings);
});
One of the following values:
'application/x-turtle' | 'text/turtle' | 'application/rdf+xml' | 'text/plain' | 'application/x-trig' | 'text/x-nquads' | 'application/trix'
One of the following values:
'text/plain' | 'application/json' | 'text/boolean'
Object with the following values:
- status (
string
) - statusText (
string
) - result (
object | string | boolean | null
) - ok (
boolean
) - headers (
Headers
)
Object with the following values:
- endpoint (
string
) - username (
string
) - password (
string
)
Connection (Class)
Constructed with:
- options (
ConnectionOptions
)
Takes the following params:
- options (
ConnectionOptions
)
Returns void
Returns Headers
Takes the following params:
- resource (
string[]
)
Returns string
Shuts down a Stardog server.
Expects the following parameters:
-
conn (
Connection
) -
params (
object
)
Returns Promise<HTTP.Body>
Creates a new database.
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
databaseOptions (
object
) -
options (
{ files: string[] }
) -
params (
object
)
Returns Promise<HTTP.Body>
Deletes a database.
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
params (
object
)
Returns Promise<HTTP.Body>
Gets an RDF representation of a database. See: https://www.w3.org/TR/sparql11-http-rdf-update/#http-get
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
params (
object
)
Returns Promise<HTTP.Body>
Sets a database offline.
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
params (
object
)
Returns Promise<HTTP.Body>
Sets a database online.
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
params (
object
)
Returns Promise<HTTP.Body>
Optimizes a database.
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
params (
object
)
Returns Promise<HTTP.Body>
Makes a copy of a database.
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
destination (
string
) -
params (
object
)
Returns Promise<HTTP.Body>
Gets a list of all databases on a Stardog server.
Expects the following parameters:
-
conn (
Connection
) -
params (
object
)
Returns Promise<HTTP.Body>
Gets number of triples in a database.
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
params (
object
)
Returns Promise<HTTP.Body>
Clears the contents of a database.
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
transactionId (
string
) -
params (
object
)
Returns Promise<HTTP.Body>
Adds data within a transaction.
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
transactionId (
string
) -
content (
string
) -
options (
TransactionOptions
) -
params (
object
)
Returns Promise<TransactionResponse>
Removes data within a transaction.
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
transactionId (
string
) -
content (
string
) -
options (
TransactionOptions
) -
params (
object
)
Returns Promise<TransactionResponse>
Gets a mapping of the namespaces used in a database.
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
params (
object
)
Returns Promise<HTTP.Body>
Exports the contents of a database.
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
options ({ mimeType:
AcceptMimeTypes
}) -
params (
{ graphUri: string }
)
Returns Promise<HTTP.Body>
Gets set of options on a database.
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
params (
object
)
Returns Promise<HTTP.Body>
Sets options on a database.
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
databaseOptions (
object
) -
params (
object
)
Returns Promise<HTTP.Body>
One of the following values:
'gzip' | 'compress' | 'deflate' | 'identity' | 'br'
TransactionResponse extends HTTP.Body
Object with the following values:
- transactionId (
string
)
Object with the following values:
- contentType (
HTTP.ContentMimeTypes
) - encoding (
Encodings
)
Begins a new transaction.
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
params (
object
)
Returns Promise<TransactionResponse>
Rolls back a transaction, removing the transaction and undoing all changes
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
transactionId (
string
) -
params (
object
)
Returns Promise<TransactionResponse>
Commits a transaction to the database, removing the transaction and making its changes permanent.
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
transactionId (
string
) -
params (
object
)
Returns Promise<TransactionResponse>
Gets the set of integrity constraints on a given database.
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
params (
object
)
Returns Promise<HTTP.Body>
Adds integrity constraints to a given database.
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
icvAxioms (
string
) -
options ({ contentType:
ContentMimeTypes
}) -
params (
object
)
Returns Promise<HTTP.Body>
Removes integrity constraints from a given database.
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
icvAxioms (
string
) -
options ({ contentType:
ContentMimeTypes
}) -
params (
object
)
Returns Promise<HTTP.Body>
Removes all integrity constraints from a given database.
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
params (
object
)
Returns Promise<HTTP.Body>
Converts a set of integrity constraints into an equivalent SPARQL query for a given database.
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
icvAxioms (
string
) -
options ({ contentType:
ContentMimeTypes
}) -
params (
{ graphUri: string }
)
Returns Promise<HTTP.Body>
Checks constraints to see if they are valid
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
constraints (
string
) -
options ({ contentType:
ContentMimeTypes
}) -
params (
{ graphUri: string }
)
Returns Promise<HTTP.Body>
Checks constraints to see if they are valid within a transaction
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
constraints (
string
) -
transactionId (
string
) -
options ({ contentType:
ContentMimeTypes
}) -
params (
{ graphUri: string }
)
Returns Promise<HTTP.Body>
Accepts integrity constraints as RDF and returns the violation explanations, if any, as RDF.
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
constraints (
string
) -
options ({ contentType:
ContentMimeTypes
}) -
params (
{ graphUri: string }
)
Returns Promise<HTTP.Body>
Accepts integrity constraints as RDF and returns the violation explanations, if any, as RDF.
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
constraints (
string
) -
options ({ contentType:
ContentMimeTypes
}) -
params (
{ graphUri: string }
)
Returns Promise<HTTP.Body>
Returns if the database is consistent
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
options (
{ namedGraph: string }
) -
params (
object
)
Returns Promise<HTTP.Body>
Provides an explanation for an inference
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
inference (
string
) -
config (
{ contentType: string }
) -
params (
object
)
Returns Promise<HTTP.Body>
Provides the reason why a database is inconsistent, as reported by db.reasoning.consistency
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
options (
{ namedGraph: string }
) -
params (
object
)
Returns Promise<HTTP.Body>
db.reasoning.explainInferenceInTransaction(conn, database, transactionId, inference, config, params)
Provides an explanation for an inference within a transaction
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
transactionId (
string
) -
inference (
string
) -
config (
TransactionOptions
) -
params (
object
)
Returns Promise<HTTP.Body>
Provides the reason why a database is inconsistent, as reported by db.reasoning.consistency
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
transactionId (
string
) -
options (
{ namedGraph: string }
) -
params (
object
)
Returns Promise<HTTP.Body>
Gets the reasoning schema of the database
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
params (
object
)
Returns Promise<HTTP.Body>
Object with the following values:
- uri (
string
) - property (
string
)
Gets the values for a specific property of a URI individual.
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
config (
PropertyOptions
) -
params (
object
)
Returns Promise<HTTP.Body>
Gets the query plan generated by Stardog for a given SPARQL query.
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
query (
string
) -
params (
object
)
Returns Promise<HTTP.Body>
Executes a query against a database.
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
query (
string
) -
params (
object
)
Returns Promise<HTTP.Body>
Executes a query against a database within a transaction.
Expects the following parameters:
-
conn (
Connection
) -
database (
string
) -
transactionId (
string
) -
query (
string
) -
params (
object
)
Returns Promise<HTTP.Body>
Gets a list of actively running queries.
Expects the following parameters:
- conn (
Connection
)
Returns Promise<HTTP.Body>
Kills an actively running query.
Expects the following parameters:
-
conn (
Connection
) -
queryId (
string
)
Returns Promise<HTTP.Body>
Gets information about an actively running query.
Expects the following parameters:
-
conn (
Connection
) -
queryId (
string
)
Returns Promise<HTTP.Body>
Object with the following values:
- name (
string
) - database (
string
) - query (
string
) - shared (
boolean
)
Stores a query in Stardog, either on the system level or for a given database.
Expects the following parameters:
-
conn (
Connection
) -
config (
StoredQueryOptions
) -
params (
object
)
Returns Promise<HTTP.Body>
Lists all stored queries.
Expects the following parameters:
-
conn (
Connection
) -
params (
object
)
Returns Promise<HTTP.Body>
Removes a given stored query.
Expects the following parameters:
-
conn (
Connection
) -
storedQuery (
string
) -
params (
object
)
Returns Promise<HTTP.Body>
Object with the following values:
- username (
string
) - password (
string
) - superuser (
boolean
)
One of the following values:
'CREATE' | 'DELETE' | 'READ' | 'WRITE' | 'GRANT' | 'REVOKE' | 'EXECUTE'
One of the following values:
'db' | 'user' | 'role' | 'admin' | 'metadata' | 'named-graph' | 'icv-constraints'
Gets a list of users.
Expects the following parameters:
-
conn (
Connection
) -
params (
object
)
Returns Promise<HTTP.Body>
Gets all information for a given user.
Expects the following parameters:
-
conn (
Connection
) -
username (
string
) -
params (
object
)
Returns Promise<HTTP.Body>
Creates a new user.
Expects the following parameters:
-
conn (
Connection
) -
user (
User
) -
params (
object
)
Returns Promise<HTTP.Body>
Changes a user's password.
Expects the following parameters:
-
conn (
Connection
) -
username (
string
) -
password (
string
) -
params (
object
)
Returns Promise<HTTP.Body>
Verifies that a Connection's credentials are valid.
Expects the following parameters:
-
conn (
Connection
) -
params (
object
)
Returns Promise<HTTP.Body>
Verifies that a user is enabled.
Expects the following parameters:
-
conn (
Connection
) -
username (
string
) -
params (
object
)
Returns Promise<HTTP.Body>
Enables/disables a user.
Expects the following parameters:
-
conn (
Connection
) -
username (
string
) -
enabled (
boolean
) -
params (
object
)
Returns Promise<HTTP.Body>
Sets roles for a user.
Expects the following parameters:
-
conn (
Connection
) -
username (
string
) -
roles (
string[]
) -
params (
object
)
Returns Promise<HTTP.Body>
Gets a list of roles assigned to a user.
Expects the following parameters:
-
conn (
Connection
) -
username (
string
) -
params (
object
)
Returns Promise<HTTP.Body>
Creates a new permission for a user over a given resource.
Expects the following parameters:
-
conn (
Connection
) -
username (
string
) -
permission (
Permission
) -
params (
object
)
Returns Promise<HTTP.Body>
Removes a permission for a user over a given resource.
Expects the following parameters:
-
conn (
Connection
) -
username (
string
) -
permission (
Permission
) -
params (
object
)
Returns Promise<HTTP.Body>
Gets a list of permissions assigned to user.
Expects the following parameters:
-
conn (
Connection
) -
username (
string
) -
params (
object
)
Returns Promise<HTTP.Body>
Gets a list of a user's effective permissions.
Expects the following parameters:
-
conn (
Connection
) -
username (
string
) -
params (
object
)
Returns Promise<HTTP.Body>
Specifies whether a user is a superuser.
Expects the following parameters:
-
conn (
Connection
) -
username (
string
) -
params (
object
)
Returns Promise<HTTP.Body>
Deletes a user.
Expects the following parameters:
-
conn (
Connection
) -
username (
string
) -
params (
object
)
Returns Promise<HTTP.Body>
Object with the following values:
- rolename (
string
)
Object with the following values:
- action (
Action
) - resourceType (
ResourceType
) - resources (
string[]
)
Creates a new role.
Expects the following parameters:
-
conn (
Connection
) -
role (
Role
) -
params (
object
)
Returns Promise<HTTP.Body>
Lists all existing roles.
Expects the following parameters:
-
conn (
Connection
) -
params (
object
)
Returns Promise<HTTP.Body>
Deletes an existing role from the system.
Expects the following parameters:
-
conn (
Connection
) -
role (
Role
) -
params (
object
)
Returns Promise<HTTP.Body>
Lists all users that have been assigned a given role.
Expects the following parameters:
-
conn (
Connection
) -
role (
Role
) -
params (
object
)
Returns Promise<HTTP.Body>
Adds a permission over a given resource to a given role.
Expects the following parameters:
-
conn (
Connection
) -
role (
Role
) -
permission (
Permission
) -
params (
object
)
Returns Promise<HTTP.Body>
Removes a permission over a given resource from a given role.
Expects the following parameters:
-
conn (
Connection
) -
role (
Role
) -
permission (
Permission
) -
params (
object
)
Returns Promise<HTTP.Body>
Lists all permissions assigned to a given role.
Expects the following parameters:
-
conn (
Connection
) -
role (
Role
) -
params (
object
)
Returns Promise<HTTP.Body>