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

@shexjs/cli

v1.0.0-alpha.29

Published

Shape Expressions command line interface

Downloads

292

Readme

NPM Version ShapeExpressions Gitter chat https://gitter.im/shapeExpressions/Lobby DOI

@shexjs/cli

Command line tools for ShEx.

validation executable

Validate over HTTP:

./node_modules/.bin/shex-validate \
    -x http://shex.io/examples/IssueSchema \
    -d http://shex.io/examples/Issue1 \
    -s http://shex.io/examples/IssueSchema#IssueShape \
    -n http://shex.io/examples/Issue1#Issue1

That validates node http://shex.io/examples/Issue in http://shex.io/examples/Issue1.ttl against shape http://shex.io/examples/IssueSchema#IssueShape in http://shex.io/examples/Issue.shex. The result is a JSON structure which tells you exactly how the data matched the schema.

{
  "type": "ShapeTest",
  "node": "http://shex.io/examples/Issue1#Issue1",
  "shape": "http://shex.io/examples/IssueSchema#IssueShape",
  "solution": {
    …
  }
}

The '-x' (shex) indicates a ShEx compact syntax file, which is the preferred type on shex.io; -j … examples/IssueSchema.json selects ShExJ and -t … examples/IssueSchema.ttl selects ShExR.

Had we gotten a Failure, we'd know that the document was invalid with respect to the schema. For instance, tru this again changing #Issue1 to #User2 (because that User2 should not conform to IssueShape):

{
  "type": "Failure",
  "node": "http://shex.io/examples/Issue1#User2",
  "shape": "http://shex.io/examples/IssueSchema#IssueShape",
  "errors": [
    {
      "type": "MissingProperty",
      "property": "http://ex.example/ns#state",
      "valueExpr": {
        "type": "NodeConstraint",
        "values": [
          "http://ex.example/ns#unassigned",
          "http://ex.example/ns#assigned"
        ]
      }
    },
    {
      "type": "MissingProperty",
      "property": "http://ex.example/ns#reportedBy",
      "valueExpr": "http://shex.io/examples/IssueSchema#UserShape"
    },
    {
      "type": "MissingProperty",
      "property": "http://ex.example/ns#reportedOn",
      "valueExpr": {
        "type": "NodeConstraint",
        "datatype": "http://www.w3.org/2001/XMLSchema#dateTime"
      }
    }
  ]
}

See the ShExJ primer for a description of ShEx validation and the ShExJ specification for more details about the results format.

Validate local files:

Command line arguments which don't match "^(blob:)?[a-z]+://." (and don't start with 'file:') are assumed to be file paths.

./node_modules/.bin/shex-validate \
    -x ./node_modules/shex-examples/IssueSchema.shex \
    -d ./node_modules/shex-examples/Issue1.ttl \
    -s '#IssueShape' \
    -n '#Issue1'

Note that the -s (--shape) and the -n (--node) are relative to the schema and data locations respectively. This means you don't have to try to construct the entire file: URL.

In the output, we'll see that the response has file: URLs in it:

{
  "type": "ShapeTest",
  "node": "file:///…/examples/Issue1.ttl#Issue1",
  "shape": "file:///…/examples/IssueSchema.shex#IssueShape",
  "solution": {
    …
  }
}

Of course the schema can use http: and the data file: or visa-versa.

Happy validating!

Validation server:

The -S switch specifies a URL at which to run a validation server:

./node_modules/.bin/shex-validate \
    -S http://localhost:1234/validate \
    -x ./node_modules/shex-examples/IssueSchema.shex \
    -d ./node_modules/shex-examples/Issue1.ttl \
    -s '#IssueShape' \
    -n '#Issue1'

The output of this command will direct you to http://localhost:1234/validate. Because you supplied all necessary parameters in the invocation, by default, this server will validate #Issue1 in Issue1.ttl against #IssueShape in IssueSchema.shex. If you play override the node http://localhost:1234/validate?node=%23Issue2 (note that with curl, you must encode the '#' as "%23"), you will see an error because that node has no arcs out in that graph.

POSTing with curl

curl offers a convenient way to construct POST requests. Supposed you wanted a validation server with no default schema or data:

./node_modules/.bin/shex-validate -S http://localhost:1234/validate

You could submit all the parameters as body parameters in a POST:

curl -i http://localhost:1234/validate \
  -F "schema=@./node_modules/shex-examples/IssueSchema.shex" \
  -F "shape=#IssueShape" \
  -F "data=@./node_modules/shex-examples/Issue1.ttl" \
  -F "node=#Issue1"

(prefixing a curl -F value with an '@' reads from the following filename)

you can mix and match between URL search string and body parameters:

curl -i http://localhost:1234/validate?node=%23Issue1 \
  -F "schema=@./node_modules/shex-examples/IssueSchema.shex" \
  -F "shape=#IssueShape" \
  -F "data=@./node_modules/shex-examples/Issue1.ttl"

(Don't forget to escape the '#' as "%23".)

conversion

As with validation (above), you can convert by either executable or library.

conversion executable

ShEx can be represented in the compact syntax

PREFIX ex: <http://ex.example/#>
<IssueShape> {                       # An <IssueShape> has:
    ex:state (ex:unassigned            # state which is
              ex:assigned),            #   unassigned or assigned.
    ex:reportedBy @<UserShape>        # reported by a <UserShape>.
}

or in JSON:

{ "type": "schema", "start": "http://shex.io/examples/IssueSchema#IssueShape",
  "shapes": {
    "http://shex.io/examples/IssueSchema#IssueShape": { "type": "shape",
      "expression": { "type": "eachOf",
        "expressions": [
          { "type": "tripleConstraint", "predicate": "http://ex.example/#state",
            "valueExpr": { "type": "valueClass", "values": [
                "http://ex.example/#unassigned", "http://ex.example/#assigned"
          ] } },
          { "type": "tripleConstraint", "predicate": "http://ex.example/#reportedBy",
            "valueExpr": { "type": "valueClass", "reference": "http://shex.io/examples/UserShape" }
          }
] } } } }

You can convert between them with shex-to-json:

./node_modules/shex/bin/shex-to-json http://shex.io/examples/Issue.shex

and, less elegantly, back with json-to-shex.

materialize

Materialize is used to transform from a source schema to a target schema after validation is done.

The syntax is:

materialize `-t <target schema>`|-h [-j `<JSON Vars File>`] [-r `<RDF root IRI>`]

Materialize reads the output from the validate tool from STDIN and maps it to the specified target schema.

If supplied, a JSON vars file will be referenced to fill in constant values not specified from the source. This is useful in assigning default fields to the target when there is no equivalent value in the source schema and source data.

Here is an example of a simple JSON vars file:

{
  "urn:local:Demographics:constSys": "System",
}

If this vars file content is used, then any time a variable in the target file with value "urn:local:Demographics:constSys" is seen, the value "System will be substituted.

The RDF root IRI specifies the root node from which all nodes in the schema will descend. The default root if none is specified is: tag:[email protected]/2016/root

Here are some examples:

materialize -h
validate -x source_schema.shex -l data.jsonld -s ProblemShape | materialize -t target_schema.shex -j vars.json
cat problem.val | materialize -t target_schema.shex -j vars.json -r http://hl7.org/fhir/shape/problem

Lerna Monorepo

This repo uses lerna to manage multiple NPM packages. These packages are located in packages/*: