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

semval

v0.2.1

Published

Validates JSON instances using Object Constraint Language

Downloads

3

Readme

semval

Demonstrates how NIST 1500 CDF JSON instances can be validated by the use of OCL invariants.

Rationale

There are certain rules that cannot be expressed using a schema language alone.

OCL fills in this gap by providing a simple, implementation format independent language for expressing predicates.

This prototype shows how OCL rules embedded in the NIST 1500 models can be used to validate JSON instances.

Mutual Exclusion (xor)

Mutual exclusivity describes a situation where either X must be true or Y must be true, but never at the same time.

Example

The VRI model contains a class called AdditionalInfo.

The additional info in question can be expressed as text (via StringValue) or as binary data (via FileValue), but not both.

context VoterId inv: self.StringValue.oclIsUndefined() xor self.FileValue.oclIsUndefined()

Implication

There is a common pattern used throughout NIST 1500 CDFs that allows a producer to specify a custom value if an enumeration does not contain a suitable value.

Example

The VRI specification contains a class called ContactMethod. The type of ContactMethod can be specified by its Type attribute. The value of Type may be email, phone or other. If the Type is other, then the actual value is expected in the OtherType attribute.

We need a rule that says that OtherType must be defined when Type = other:

context ContactMethod inv: self.Type = ContactMethodType::other implies not self.OtherType.oclIsUndefined()

Contrariwise, we should have a rule that ensures OtherType is defined only when Type = other:

context ContactMethod inv: not self.OtherType.oclIsUndefined() implies ContactMethodType::other

Acquiring the prototype

This prototype is available via node package manager (NPM).

npm i semval

Using the prototype

This prototype provides a command line interface to test a set of JSON instances against a set of OCL constraints.

Usage:  [options] <instance> <oclRules> [enums]

ocl ruleset runner for json

Options:
  -V, --version   output the version number
  -m, --multiple  instance file contains multiple instances
  -c, --coverage  append coverage report
  -h, --help      output usage information

Creating your own rulesets

Rulesets are specified as JSON in the following format:

[
    {
        name: string;
        errorMessage: string;
        expression: string;
    }
    ...
]

The validator uses the ocl.js engine to validate instances against OCL invariants. Please view its documentation for notes regarding OCL support and usage.

Examples

Take a look at the testData for example instance and rule files.

Testing a set of instances

using the --multiple flag will allow you to test a set of JSON instances in a single file. The file must be in the form of:

{
    "instance_name": object,
    ...
}

How to run (from source)

  1. Install node / npm.
  2. Run npm run build
  3. Run npm run start