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

@thing-description-playground/core

v1.4.0

Published

Provides the validation functionality for the Web of Things - Thing Description Playground.

Downloads

24

Readme

@thing-description-playground/CORE

This package provides the main functionality of the Web of Things Playground, i.e., validating given Thing Descriptions. You can find more information about the Thingweb-Playground here.

Limitations:

  • There is limited nested validation. This is due to the JSON Schema specification which doesn't allow infinite references with $ref keywords. Because of this, an enum key in a e.g. #/actions/input/properties/enum will not be necessarily checked. More information can be found here.

License

Licensed under the MIT license, see License.

Script based Thing Description Validation

This is a Node.js based tool.

WARNING: If you see an error like ajv.errors[0].params.allowedValue this very probably means that your TD is not valid at a specific point. Scroll up to see the precise error message.

You can use the functionality of this package by:

  • Install the package with npm npm install @thing-description-playground/core (or clone repo and install the package with npm install)

  • Node.js or Browser

    • Node.js: Require the package and use the validation function
    const tdValidator = require("@thing-description-playground/core").tdValidator
    • Browser: Import the Validators.tdValidator function as a global by adding a script tag to your HTML.
    <script src="./node_modules/@thing-description-playground/core/dist/web-bundle.min.js"></script>

Structure

The index.js file contains the main validation functionality and exports the modules functionalities.
The shared.js file contains additional check functions, which are shared between the core package and the assertions package.

Examples

  • Some example Thing Descriptions are provided in the examples folder. There are :
    • valid: Minimum 4 lights are lit green, no warning message is displayed. They may or may not pass Full Schema Validation
    • warning: At least one light is orange
    • invalid: At least one of the lights is lit red.

These examples cover all the features of the TD spec. If you think that there is a missing feature not represented, write an issue.

  • Additionally there are also example scripts provided (in the example-script folder) to demonstrate the usage of this package. Further examples for its usage can be found in the web and cli packages.

  • Small example for using this package in a Node.js script, to validate an example TD:

const tdValidator = require("@thing-description-playground/core").tdValidator
const fs = require("fs")

const simpleTD = fs.readFileSync("./node_modules/@thing-description-playground/core/examples/tds/valid/simple.json", "utf8")

/**
 * Use console for logging, no options
 */
tdValidator(simpleTD, console.log, {})
.then( result => {
  console.log("OKAY")
  console.log(result)
}, err => {
  console.log("ERROR")
  console.error(err)
})

Validation Report

The core validation report is an object, which contains three objects (as you can see in the example report):

{
    report: {
        json: "passed",
        schema: "passed",
        defaults: "warning",
        jsonld: null,
        additional: "failed"
    },
    details: {
        enumConst: "passed",
        propItems: "warning",
        security: "passed",
        propUniqueness: "passed",
        multiLangConsistency: "failed"
    },
    detailComments: {
        enumConst: "Checking whether a data schema has enum and const at the same time.",
        propItems: "Checking whether a data schema has an object but not properties or array but no items.",
        security: "Check if used Security definitions are properly defined previously.",
        propUniqueness: "Checking whether in one interaction pattern there are duplicate names, e.g. two properties called temp.",
        multiLangConsistency: "Checks whether all titles and descriptions have the same language fields."
    }
}
  • The report object contains the results of the default validation. It is structure with a keyword and the value null, "passed", "warning" or "failed". Where null is used if the test was not executed, which can happen either because it was opted out or a previous check failed. The keywords are:
    • json: Checks if the TD is a valid JSON instance.
    • schema: Checks if the TD is valid according to the JSON Schema constructed from the TD specification.
    • defaults: As schema, but this JSON Schema additionally checks if default behavior is explicitly stated (recommended). The check can be opted out.
    • jsonld: Checks if the TD is a valid JSON-LD instance. This will only work with internet connection (because the @context tags have to be loaded) and can be opted out.
    • additional: Combined indicator of the results of the additional checks that are listed in details.
  • The details object contains the results of the additional checks. The keywords can have the same values as in report.
  • The detailComments explains the meaning of every additional check.

Test Usage

Test Examples are located under examples directory. For examples you need to fill 'typoCount' field that corresponds to the number of typos existing in the TD.
For protocol detection examples you need to fill 'protocolSchemes' field that corresponds to the protocols TD uses.