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

stardog-js

v0.6.2

Published

Node.js library for communicating with the Stardog HTTP server.

Downloads

19

Readme

stardog-js

Node.js library for communicating with the Stardog HTTP server.

Installation

$ npm i request
$ npm i stardog-js

request is defined as a peer-dependency and thus has to be installed separately.

Testing

Run Stardog HTTP server on http://localhost:5820.

$ npm test

Import

Using CommonJS

Requirements (Node.js >= 8.0.0).

const Stardog = require('stardog-js');

Using ESM

Use --experimental-modules flag and .mjs extension (Node.js >= 8.6.0).

import Stardog from 'stardog-js';

Usage

Create instances

// Create instance with only endpoint (required option)

const stardog = new Stardog({
    endpoint: 'http://localhost:5820'
});

// Create instance with credentials and database name (optional)

const stardog = new Stardog({
    endpoint: 'http://localhost:5820',
    database: 'database',
    auth: {
        user: 'user',
        pass: 'pass'
    }
});

Invoke methods

// Credentials and database are optional,
// this have lower priority than constructor settings

const data = await stardog.query({
    database: 'database',
    auth: {
        user: 'user',
        pass: 'pass'
    },
    query: 'select * where {?s ?p ?o}'
}).catch((err) => {
    return Promise.reject(err);
});

Examples

import Stardog from 'stardog-js';

const stardogAdminDatabase = new Stardog({
    endpoint: 'http://localhost:5820',
    database: 'database',
    auth: {
        user: 'admin',
        pass: 'admin'
    }
});

const stardogAdmin = new Stardog({
    endpoint: 'http://localhost:5820',
    auth: {
        user: 'admin',
        pass: 'admin'
    }
});

const stardog = new Stardog({
    endpoint: 'http://localhost:5820'
});

(async () => {
    const data1 = await stardogAdminDatabase.query({
        query: 'select * where {?s ?p ?o}'
    });

    const data2 = await stardogAdmin.query({
        database: 'database',
        query: 'select * where {?s ?p ?o}'
    });

    const data3 = await stardog.query({
        database: 'database',
        auth: {
            user: 'admin',
            pass: 'admin'
        },
        query: 'select * where {?s ?p ?o}'
    });
})();

API

Databases

createDatabase

Create new database.

stardog.createDatabase({
    database: 'database'
});

dropDatabase

Drop database.

stardog.dropDatabase({
    database: 'database'
});

sizeDatabase

Get size database.

const size = await stardog.sizeDatabase({
    database: 'database'
});

listDatabases

Get list databases.

const databases = await stardog.listDatabases();

existsDatabase

Check exists database.

if (await stardog.existsDatabase({
        database: 'database'
    })) {
    console.log('exists');
}

metaDatabase

Get metadata options for database.

// Returns all metadata options

const meta = await stardog.metaDatabase({
    database: 'database'
});

/*
options: {
    'database.archetypes': '',
    'database.connection.timeout': '',
    'database.name': '',
    'database.namespaces': '',
    'database.online': '',
    'database.time.creation': '',
    'database.time.modification': '',
    'icv.active.graphs': '',
    'icv.consistency.automatic': '',
    'icv.enabled': '',
    'icv.reasoning.enabled': '',
    'index.differential.enable.limit': '',
    'index.differential.merge.limit': '',
    'index.differential.size': '',
    'index.literals.canonical': '',
    'index.named.graphs': '',
    'index.persist': '',
    'index.persist.sync': '',
    'index.size': '',
    'index.statistics.update.automatic': '',
    'index.type': '',
    'preserve.bnode.ids': '',
    'query.all.graphs': '',
    'query.timeout': '',
    'reasoning.approximate': '',
    'reasoning.consistency.automatic': '',
    'reasoning.punning.enabled': '',
    'reasoning.sameas': '',
    'reasoning.schema.graphs': '',
    'reasoning.schema.timeout': '',
    'reasoning.type': '',
    'reasoning.virtual.graph.enabled': '',
    'search.enabled': '',
    'search.reindex.mode': '',
    'spatial.enabled': '',
    'strict.parsing': '',
    'transaction.isolation': '',
    'transaction.logging': ''
}
*/

// Get custom fields

const meta = await stardog.metaDatabase({
    database: 'database',
    fields: [
        'database.online',
        'database.time.creation'
    ]
});

onDatabase

Bring the database online.

stardog.onDatabase({
    database: 'database'
});

offDatabase

Bring the database offline.

stardog.offDatabase({
    database: 'database'
});

copyDatabase

Copy database.

// Bring the database offline

await stardog.offDatabase({
    database: 'from'
});

// Copy database 'from' to database 'to'

await stardog.copyDatabase({
    from: 'from',
    to: 'to'
});

exportDatabase

Export database.

stardog.exportDatabase({
    database: 'database'
});

// Export database with accept

stardog.exportDatabase({
    database: 'database',
    accept: 'application/n-triples'
});

Graphs

dropGraph

Drop named graph.

stardog.dropGraph({
    graph: 'urn:graph'
});

copyGraph

Copy named graph.

stardog.copyGraph({
    from: 'urn:from',
    to: 'urn:to'
});

moveGraph

Move named graph.

stardog.moveGraph({
    from: 'urn:from',
    to: 'urn:to'
});

addGraph

Insert data from source named graph to destination.

stardog.addGraph({
    from: 'urn:from',
    to: 'urn:to'
});

listGraphs

Get list of named graphs.

const graphs = await stardog.listGraphs();

existsGraph

Check exists named graph.

const exists = await stardog.existsGraph({
    graph: 'urn:graph'
});

Queries

query

Execute query.

const data = await stardog.query({
    query: 'select * where {?s ?p ?o}'
});

// Set accept to 'text/boolean', returns true or false

const data = await stardog.query({
    accept: 'text/boolean',
    query: 'ask {<urn:a> <urn:b> <urn:c>}'
});

const data = await stardog.query({
    query: 'construct {?s ?p ?o} where {?s ?p ?o}'
});

// Query to named graph 'tag:stardog:api:context:default'

const data = await stardog.query({
    query: 'select * where {?s ?p ?o}',
    graph: 'tag:stardog:api:context:default',
    offset: 0,
    limit: 1,
    timeout: 1000,
    reasoning: true
});

// Query to two named graphs

const data = await stardog.query({
    query: 'select * where {?s ?p ?o}',
    graph: ['urn:graph', 'urn:graph2']
});

ask

Alias for query with accept text/boolean.

const data = await stardog.ask({
    query: 'ask {<urn:a> <urn:b> <urn:c>}'
});

// Equal query

const data = await stardog.query({
    accept: 'text/boolean',
    query: 'ask {<urn:a> <urn:b> <urn:c>}'
});

update

Execute update query.

stardog.update({
    query: 'insert data {<urn:a> <urn:b> <urn:c>}'
});

stardog.update({
    query: 'delete data {<urn:a> <urn:b> <urn:c>}'
});

// Insert to named graph 'urn:graph'

stardog.update({
    query: 'insert data {<urn:a> <urn:b> <urn:c>}',
    insertGraph: 'urn:graph'
});

// Remove from named graph 'urn:graph'

stardog.update({
    query: 'delete data {<urn:a> <urn:b> <urn:c>}',
    removeGraph: 'urn:graph'
});