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

@dcic/signature-commons-schema

v1.5.17

Published

JSON-Schema validators for signature commons entities

Downloads

43

Readme

Signature Commons Schema

JSON-Schema validators for signature commons entities. Designed to allow one to flexibly validate arbitrary metadata in the signature commons database.

Installation

npm install --save @dcic/signature-commons-schema

Usage

import { validate } from '@dcic/signature-commons-schema'
validate({your_object})

CLI

(
  # Parse and put json on single line
  jq -c '.' << EOF
{
  "your": "json"
}
EOF
  # Run it through the validator (with verbose debugging; otherwise omit DEBUG)
) | DEBUG=signature-commons-schema signature-commons-schema your_validator
# stdout    -- the valid json(s)
# stderr    -- any errors
# exit code -- the number of errors

s

Project Layout

  • core/: Fundamental schemas which define how the schemas should even be used
    • meta.json: JSON-LD style constraints
    • library.json, signature.json, entity.json: Primary signature common primitives, they expose meta as an instance of meta.json
    • examples.json: Schema example tests structure
  • meta/: Meta schemas designed for the respective primary signature common primitive meta fields.
  • src: Validator built with https://github.com/epoberezkin/ajv

Discussion

At the most basic level, a given instance should reference the validation context which it implements.

Given an abstract concept, we can write a validator for it:

{
  "$id": "myimportantconcept.json",
  "$schema": "http://json-schema.org/draft-04/schema#",
  "description": "My important concept",
  "allOf": [
    {
      "$ref": "core/meta.json"
    },
    {
      "type": "object",
      "properties": {
        "my_important_field": {
          "type": "string",
          "description": "My important description"
        }
      },
      "required": [
        "my_important_field"
      ]
    }
  ]
}

Meta here enforces the constraint of the $validator definition, which references the abstract validation. Now we can write any number of instances for our concept.

{
  "$validator": "myimportantconcept.json",
  "my_important_field": "my_important_value"
}

We can validate that this is true by grabbing the $validator file and validating the json itself.

import {validate} from '@dcic/signature-commons-schema/validate'
validate(data)

The $validator here is therefore doubling as semantic meaning, as described in the descriptions, and computational validation. Better yet, this allows us to support self-described objects, which is how we can deal with arbitrary metadata.

{
  "$validator": "core/signature.json",
  "meta": {
    "$validator": "meta/signature/gene.json",
    ...all the gene signature relevant metadata
  },
  "values": {
    "entity": "id",
    "value": "val"
  }
}

meta/signature/gene.json then is capable of defining the specifics of the metadata implementation, potentially as a subset of other metadata.

{
  "$id": "meta/signature/gene.json",
  "allOf": [
    {
      "$ref": "meta/signature/common.json"
    },
    {
      "type": "object",
      "properties": {
        ...gene specific signature properties
      }
    }
  ]
}

This repository has examples and tests which should be re-used to validate that APIs and Databases as part of the signature commons are serving and consuming data which follows this same approach. The actual schemas can be stored and referenced from this repository as they are public, persistent, and versioned.