npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

graphdb-js

v1.0.2

Published

This module is a convenient wrapper for [GraphDB](https://www.ontotext.com/products/graphdb/)'s REST API. Large parts are still to be implemented, however, it's already providing key features like SPARQL querying and document uploading.

Downloads

8

Readme

graphdb-js

This module is a convenient wrapper for GraphDB's REST API. Large parts are still to be implemented, however, it's already providing key features like SPARQL querying and document uploading.

Disclaimer

This module was only tested against the API of GraphDB-free version 8.7.2.

Usage

Install this package via npm:

npm i graphdb-js

Initialization

const GraphDB = require('graphdb-js');

let graphdb = new GraphDB({
    hostname: "localhost",
    repository: "test"
});

In theory you can pass on everything according to the http module's configuration, since these parameters are used by this exact module. However, it is recommended to stick to the one's listed, since you might override stuff that's already correctly configured for you, also there's some options that are not directly related to http like the repository field, which is required. For instance if you pass {method: "GET"} you'll override SPARQL query request parameter's, such that they won't work anymore, since they work with POST requests only. Parameters you might actually be required to modify are listed in the table below.

|Parameter |Datatypes |Description | |:--------:|:--------:|:---------------:| |hostname |String |Name of the host | |port |Integer |The port the GraphDB instance listens on | |repository|String |The repository you want to connect to |

Authorization

Non-free versions of GraphDB also support authorization techniques, which might require you, depending on the repository setup, to perform a login.

/* TODO: not possible yet since I did not have any repo to test this on */

Issuing SPARQL Queries

The following was taken from the w3.org SPARQL specification page. Assuming GraphDB follows this specification, every valid SPARQL query should be possible using this client.

SPARQL can be used to express queries across diverse data sources, whether the data is stored natively as RDF or viewed as RDF via middleware. SPARQL contains capabilities for querying required and optional graph patterns along with their conjunctions and disjunctions. SPARQL also supports aggregation, subqueries, negation, creating values by expressions, extensible value testing, and constraining queries by source RDF graph. The results of SPARQL queries can be result sets or RDF graphs.

SELECT Queries

const select = "select * where { ?s ?p ?o . }";

graphdb.Query.query(select, (err, data) => {
    console.log(data);
    console.log(err);
});

UPDATE Queries

const insert = "insert data { <http://purl.org/dc/elements/1.1/title> <http://purl.org/dc/elements/1.1/title> \"Fundamentals of Compiler Construction\" .}"; 

graphdb.Query.query(insert, (err, data) => {
    console.log(data);
    console.log(err);
});

Upload RDF Files

When it comes to uploading files, there are different ways to do that. Either as strings or by URL, in either case, you are free to use any format that is supported by GraphDB.

As String

graphdb.Import.text({
    data: JSON.stringify(require('./test.json')),
}, (err, data) => {
    console.log(data);
    console.log(err);
});

Parameters

You can pass any of the following parameters to the above method call.

{
  "baseURI": "",
  "context": "",
  "data": "{}",
  "forceSerial": true,
  "format": "Application/ld+json",
  "message": "automatically issued import",
  "parserSettings": {
    "failOnUnknownDataTypes": false,
    "failOnUnknownLanguageTags": false,
    "normalizeDataTypeValues": false,
    "normalizeLanguageTags": false,
    "preserveBNodeIds": false,
    "stopOnError": true,
    "verifyDataTypeValues": false,
    "verifyLanguageTags": true,
    "verifyRelativeURIs": true,
    "verifyURISyntax": true
  },
  "replaceGraphs": [],
  "status": "NONE",
  "type": "text",
  "name": "Text Snippet",
  "timestamp": 0
}

By URL

graphdb.Import.url({
    data: "https://raw.githubusercontent.com/julietcetera/graphdb-js/master/__test__/test.json",
}, (err, data) => {
    console.log(data);
    console.log(err);
});

Parameters

You can pass any of the following parameters to the above method call.

{
  "baseURI": "",
  "context": "",
  "data": "https://example.org/samplejsonld.json",
  "forceSerial": true,
  "format": "Application/ld+json",
  "message": "automatically issued import",
  "parserSettings": {
    "failOnUnknownDataTypes": false,
    "failOnUnknownLanguageTags": false,
    "normalizeDataTypeValues": false,
    "normalizeLanguageTags": false,
    "preserveBNodeIds": false,
    "stopOnError": true,
    "verifyDataTypeValues": false,
    "verifyLanguageTags": true,
    "verifyRelativeURIs": true,
    "verifyURISyntax": true
  },
  "replaceGraphs": [],
  "status": "NONE",
  "type": "url",
  "name": "https://example.org/samplejsonld.json",
  "timestamp": 0
}