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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@shexjs/shape-path-query

v1.0.0-alpha.33

Published

ShapePath query interface for ShEx.js

Downloads

480

Readme

@shexjs/shape-path-query

npm version CI

Query RDF data by pointing at schema elements: a ShapePath expression selects constraints in a ShEx schema (shape-path-core), and shapePathQuery answers with the terms those constraints matched when the data validated — XPath for the schema, results from the graph.

Install

npm install @shexjs/shape-path-query

Quick start

const Fs = require("fs");
const Path = require("path");
const {Store, Parser} = require("n3");
const Sp = require("shape-path-core");
const {ctor: RdfJsDb} = require("@shexjs/neighborhood-rdfjs");
const {shapePathQuery} = require("@shexjs/shape-path-query");

// the Issue example that ships with shape-path-core
const schema = JSON.parse(Fs.readFileSync(Path.join(Sp.examples, "issue/Issue.json"), "utf8"));
const turtle = Fs.readFileSync(Path.join(Sp.examples, "issue/Issue2.ttl"), "utf8");

// 1. a ShapePath picks schema elements: the <p:href> constraint in <#DiscItem>
const yy = {base: new URL("http://project.example/schema"), prefixes: {}};
const pathExpr = new Sp.Parser.ShapePathParser(yy).parse(
  "@<http://project.example/schema#DiscItem>~<http://project.example/ns#href>"
);
const nodeSet = pathExpr.evalPathExpr([schema], new Sp.Ast.EvalContext(schema));

// 2. validate, and answer with what those elements matched in the data
const graph = new Store(new Parser({baseIRI: "http://project.example/"}).parse(turtle));
shapePathQuery(schema, nodeSet, RdfJsDb(graph),
  [{node: "http://instance.example/project1/Issue2",
    shape: "http://project.example/schema#Issue"}]
).then(terms => console.log(terms));
[ 'http://instance.example/project1/img1.jpg' ]

shapePathQuery(schema, nodeSet, db, shapeMap) → Promise<terms[]>

  • schema — a ShExJ schema (@types/shexj shaped);
  • nodeSet — schema elements selected by evalPathExpr (they are annotated in place with ShExMap variable bindings — that's the mechanism: the ShapePath aims the query, ShExMap captures the matches);
  • db — a @shexjs/neighborhood-api implementation, e.g. @shexjs/neighborhood-rdfjs over your graph;
  • shapeMap — which node/shape pairs to validate (a parsed shape map).

Returns the data terms the selected schema elements matched, one entry per binding; throws if the shape map doesn't validate.

From the command line

spquery.js takes a ShapePath (,-separated for a union), a schema, -d data and -m shape map:

./bin/spquery.js \
  '@<http://project.example/schema#DiscItem>~<http://project.example/ns#href>,@<http://project.example/schema#Issue>~<http://project.example/ns#spec>/valueExpr/shapeExprs~<http://project.example/ns#href>' \
  node_modules/shape-path-core/examples/issue/Issue.json \
  -d node_modules/shape-path-core/examples/issue/Issue2.ttl \
  -m '<http://instance.example/project1/Issue2>@<http://project.example/schema#Issue>'
[
  "http://instance.example/project1/img1.jpg",
  "http://instance.example/project1/spec3"
]

(or npm run toy from this directory).


@shexjs/shape-path-query is one of the shex.js packages; installing shex pulls in the whole suite, and its README maps them.