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

@openactive/data-model-validator

v2.0.83

Published

A library to allow a developer to validate a JSON document against the OpenActive Modelling Opportunity Specification

Downloads

400

Readme

OpenActive Data Model Validator

The OpenActive data model validator library.

Tests Known Vulnerabilities

Introduction

This library allows developers to validate JSON models to the latest OpenActive Modelling Opportunity Data specification.

Using in your application

This library can be used in your own application, perhaps as part of your CI pipeline.

Install

$ npm install @openactive/data-model-validator

Usage

const { validate } = require('@openactive/data-model-validator');

const data = {
  '@context': 'https://openactive.io/',
  '@type': 'Event',
  name: 'Tai chi Class',
  url: 'http://www.example.org/events/1',
  startDate: '2017-03-22T20:00:00',
  activity: 'Tai Chi',
  location: {
    '@type': 'Place',
    name: 'ExampleCo Gym',
    address: {
      '@type': 'PostalAddress',
      streetAddress: '1 High Street',
      addressLocality: 'Bristol',
      postalCode: 'BS1 4SD'
    }
  }
};

// Check whether the JSON conforms to the Event model
const result = await validate(data);

// Returns:
// [{category: 'conformance', type: 'missing_required_field', message: 'Required field is missing.', value: undefined, severity: 'failure', path: '$.context' }, ... ]

Options

The validate method optionally accepts options for validation:

loadRemoteJson

Default: false

Whether to load remote JSON documents. For example, remote @context definitions or activity list definitions.

e.g.

const { validate } = require('@openactive/data-model-validator');

const data = {
// ...
};

const options = {
loadRemoteJson: true
};

const result = await validate(data, options);

remoteJsonCachePath

Default: null

Used in conjunction with loadRemoteJson. If set, allows the JSON loader to cache requests.

e.g.

const { validate } = require('@openactive/data-model-validator');

const data = {
// ...
};

const options = {
loadRemoteJson: true,
remoteJsonCachePath: '/tmp'
};

const result = await validate(data, options);

remoteJsonCacheTimeToLive

Default: 3600

Used in conjunction with loadRemoteJson and remoteJsonCachePath. It sets the number of seconds that the JSON loader should cache requests for.

e.g.

const { validate } = require('@openactive/data-model-validator');

const data = {
// ...
};

const options = {
  loadRemoteJson: true,
  remoteJsonCachePath: '/tmp',
  remoteJsonCacheTimeToLive: 3600
};

const result = await validate(data, options);

rpdeItemLimit

A limit of the number of RPDE "updated" data items to validate. It is helpful to limit the number of items validated for performance reasons.

e.g.

const { validate } = require('@openactive/data-model-validator');

const feed = {
// ...
};

const options = {
  rpdeItemLimit: 10
};

const result = await validate(feed, options);

type

The validator will detect the type of the model being validated from the @type property. You can override this by providing a type option.

e.g.

const { validate } = require('@openactive/data-model-validator');

const model = {
  type: 'CustomAction'
  // ...
};

const options = {
  type: 'Action'
};

const result = await validate(model, options);

version

The version of the specification to validate against. If not provided, this will validate against the latest specification.

e.g.

const { validate } = require('@openactive/data-model-validator');

const model = {
  type: 'CustomAction'
  // ...
};

const options = {
  version: '2.0'
};

const result = await validate(model, options);
}

validationMode

Provides context as to how the data under validation is expected to be used and therefore some validation rules may or may not apply. For example, OrderQuotes only have a customer attribute in the C2 phase and beyond of booking (so not in C1Request or C1Response nor any more generic published open data usage).

e.g. To only apply rules that are suitable for data used in a booking flow phase like C2Request:

const { validate, ValidationMode } = require('@openactive/data-model-validator');

const model = {
  type: 'CustomAction'
  // ...
};

const options = {
  validationMode: 'C2Request'
  // ...
};

const result = validate(model, options);

Development

Getting started

$ git clone [email protected]:openactive/data-model-validator.git
$ cd data-model-validator
$ npm install

Running tests

This project uses Jasmine for its tests. All spec files are located alongside the files that they target.

To run tests locally, run:

$ npm test

The test run will also include a run of eslint and TypeScript. To run the tests without these, use:

$ npm run run-tests

Contributing

Read the Contributing Guide for information on how to write your own rules.