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

shacl-engine

v1.0.1

Published

A fast RDF/JS SHACL engine

Downloads

6,998

Readme

shacl-engine

build status npm version

A fast SHACL engine for data provided as RDF/JS objects.

Features

SHACL consists of multiple modules. Here is an overview of the features this library implements and planned features:

Install

npm install --save shacl-engine

Usage

Validator

The Validator class can be imported from the main package:

import { Validator } from 'shacl-engine'

Or from the class file:

import Validator from 'shacl-engine/Validator.js'

The constructor must be called with the shapes as an RDF/JS DatasetCore object. The second argument is an object for various options:

  • coverage: Boolean flag to enable collecting covered quads. (optional) If coverage is enabled, debug, details, and trace are also enabled.
  • debug: Generate debug results for successful validations. (optional)
  • details: Generate nested result details. (optional)
  • factory: A RDF/JS DataFactory, which is used to generate the report (required).
  • trace: Generate results for path traversing. (optional)

The validations can be executed with the .validate(data, shapes) method. The data must have the following structure:

  • dataset: An RDF/JS DatasetCore object that contains the quads. (required)
  • terms: An iterable object of RDF/JS Terms that will be used as initial focus nodes. (optional)

The shapes object is optional, but if given must have the following structure:

  • terms: An iterable object of RDF/JS Terms that refers to the initial set of shapes. (optional) This doesn't limit the nested shapes.

Example

The following example reads the shapes and data from the list coverage test, creates a Validator instance, and runs the validation:

import rdfDataModel from '@rdfjs/data-model'
import rdfDataset from '@rdfjs/dataset'
import toNT from '@rdfjs/to-ntriples'
import fromFile from 'rdf-utils-fs/fromFile.js'
import Validator from 'shacl-engine/Validator.js'

async function main () {
  // read the shape and data from the list coverage test
  const filename = new URL('../test/assets/coverage/list.ttl', import.meta.url)
  const dataset = rdfDataset.dataset()

  for await (const quad of fromFile(filename.pathname)) {
    dataset.add(quad)
  }

  // create a validator instance for the shapes in the given dataset
  const validator = new Validator(dataset, { factory: rdfDataModel })

  // run the validation process
  const report = await validator.validate({ dataset })

  // check if the data conforms to the given shape
  console.log(`conforms: ${report.conforms}`)
}

main()

See the examples folders for more examples.

SPARQL Support

The Validator comes with the core SHACL validations out-of-the-box. Additional validations must be added for SPARQL support. The validations can be imported from shacl-engine/sparql.js as shown below:

import rdfDataModel from '@rdfjs/data-model'
import { validations as sparqlValidations } from 'shacl-engine/sparql.js'

const validator = new Validator(dataset, {
  factory: rdfDataModel,
  validations: sparqlValidations
})