You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
ldo-compact-fork/packages/schema-converter-shex
Jackson Morgan 67db1eaf28 Refactored jsonld context builder to handle scoped context. 11 months ago
..
src Refactored jsonld context builder to handle scoped context. 11 months ago
test Refactored jsonld context builder to handle scoped context. 11 months ago
.eslintrc Added schema-converter-shex 2 years ago
LICENSE.txt Update Readmes 2 years ago
README.md Update Readmes 2 years ago
jest.config.js added jsonld-dataset-proxy 2 years ago
package.json v0.0.1-alpha.24 2 years ago
tsconfig.build.json Added schema-converter-shex 2 years ago

README.md

ShexJ 2 Type and Context

Turn ShexJ into typescript typings and JSON-LD context.

Installation

npm i @ldo/schema-converter-shex

API

See the full API docs.

Usage

import { Schema } from "shexj";
import shexjToTypeAndContext from "@ldo/schema-converter-shex";

async function run() {
  /**
   * Sample ShexJ. Equivalent to:
   *
   * <EmployeeShape> {                # An <EmployeeShape> has:
   *   foaf:givenName  xsd:string+,   # at least one givenName.
   *   foaf:familyName xsd:string,    # one familyName.
   *   foaf:phone      IRI*,          # any number of phone numbers.
   *   foaf:mbox       IRI            # one FOAF mbox.
   * }
   */
  const sampleShexj: Schema = {
    type: "Schema",
    shapes: [
      {
        type: "Shape",
        id: "http://shex.io/webapps/shex.js/doc/EmployeeShape",
        expression: {
          type: "EachOf",
          expressions: [
            {
              type: "TripleConstraint",
              predicate: "http://xmlns.com/foaf/0.1/givenName",
              valueExpr: {
                type: "NodeConstraint",
                datatype: "http://www.w3.org/2001/XMLSchema#string",
              },
              min: 1,
              max: -1,
            },
            {
              type: "TripleConstraint",
              predicate: "http://xmlns.com/foaf/0.1/familyName",
              valueExpr: {
                type: "NodeConstraint",
                datatype: "http://www.w3.org/2001/XMLSchema#string",
              },
            },
            {
              type: "TripleConstraint",
              predicate: "http://xmlns.com/foaf/0.1/phone",
              valueExpr: {
                type: "NodeConstraint",
                nodeKind: "iri",
              },
              min: 0,
              max: -1,
            },
            {
              type: "TripleConstraint",
              predicate: "http://xmlns.com/foaf/0.1/mbox",
              valueExpr: {
                type: "NodeConstraint",
                nodeKind: "iri",
              },
            },
          ],
        },
      },
    ],
    "@context": "http://www.w3.org/ns/shex.jsonld",
  };

  const [typings, context] = await shexjToTypeAndContext(sampleShexj);

  /*
  Logs:
  declare namespace  {
    interface EmployeeShape {
        givenName: string[];
        familyName: string;
        phone?: string[];
        mbox: string;
    }

  }
  */
  console.log(typings.typingsString);
  /*
  Logs:
  {
    givenName: {
      '@id': 'http://xmlns.com/foaf/0.1/givenName',
      '@type': 'http://www.w3.org/2001/XMLSchema#string',
      '@container': '@set'
    },
    familyName: {
      '@id': 'http://xmlns.com/foaf/0.1/familyName',
      '@type': 'http://www.w3.org/2001/XMLSchema#string'
    },
    phone: { '@id': 'http://xmlns.com/foaf/0.1/phone', '@container': '@set' },
    mbox: { '@id': 'http://xmlns.com/foaf/0.1/mbox' }
  }
  */
  console.log(context);
}
run();

Sponsorship

This project was made possible by a grant from NGI Zero Entrust via nlnet. Learn more on the NLnet project page.

nlnet foundation logo NGI Zero Entrust Logo

Liscense

MIT