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

d-pac.plugins-spec

v0.4.1

Published

D-pac plugin specification

Downloads

4

Readme

d-pac.plugins-spec v0.4

Npm package Build Status Dependency Status

This module formally defines the plugins specification for d-pac. It uses json-schema to describe the mandatory plugin declaration and the data it accepts.

Plugin manifest

A d-pac plugin must declare an object in its package.json which adheres to schemas/pluginmanifest.json To verify your plugin fullfils all requirements:

var spec = require('d-pac.plugins-spec');
var pkg = require('./package.json'); // retrieve your plugin's package manifest

var result = spec.validatePluginmanifest(pkg);
console.log(result.isValid);

Plugin API

A d-pac plugin must expose a method conform to its type declaration in the manifest. ATM a single type is accepted: select.

Example:

module.exports.select = function select(selectionpayload){
    //do your stuff
};

This method should accept exactly one parameter which adheres to schemas/selectionpayload.json A plugin is allowed to override the payload schema in case it requires/ignores any of the fields.

References:

Module API

Schemas

This module exposes a mapping of schema declarations to schema names as schemas:

var spec = require('d-pac.plugins-spec');
console.log(Object.keys(spec.schemas));
#output
[ 'pluginmanifest',
  'assessment',
  'comparison',
  'representation',
  'selectionpayload' ]

Default Validators

It also exposes validators for each of the schemas:

console.log(Object.keys(spec));
#output
[ 'validatePluginmanifest',
  'validateAssessment',
  'validateComparison',
  'validateRepresentation',
  'validateSelectionpayload',
  'schemas',
  'createValidator',
  'VERSION' ]

Usage:

validate<SchemaType>(data) : Object

var result = spec.validateComparison(comparison);

The result is an object with isValid: Boolean and in case the data's not valid an errors array with all errors.

Custom Validators

You can create validators of your own, either based on one of the d-pac schemas, or completely new.

//new schema
var validator = subject.createValidator( {
	"$schema": "http://json-schema.org/draft-04/schema#",
	"title": "Test createValidator",
	"type": "object",
	"properties": {
	  "foo": {
	    "type": "number",
	    "required": true
	  }
	}
} );
console.log(validator( { foo: "foo" } ).isValid); //outputs: false
console.log(validator( { foo: 9 } ).isValid); //outputs: true
//based on existing
var validator = subject.createValidator( "selectionpayload", {
	"selectionpayload": {
	  "properties": {
	    "assessment": {
	      "required": true
	    }
	  }
	},
	"comparison": {
	  "properties": {
	    "updatedAt": {
	      "required": true
	    }
	  }
	}
} );

The above example creates a validator based on schemas/selectionpayload.json by passing the "selectionpayload" as a first argument. You can override the rules of the original schema, by passing extra rules as objects mapped to the schema names. E.g. the assessment property of selectionpayload is made mandatory in the above example.

Since the selectionpayload schema references several other schemas, you can override these too. E.g. all comparison objects passed to selectionpayload.comparisons are required to have a updatedAt property.

The structure of the overriding object must be exactly the same as that of the base schema, i.e. make sure you adhere to it strictly.

Plugin declaration retrieval from package manifests

You can use getPlugins to retrieve plugin declarations from package manifests:

var plugins = subject.getPlugins({
  "d-pac": [
    {
      "name": "test",
      "description": "test",
      "type": "select"
    }
  ],
  dependencies: {
    'd-pac.plugins-spec': '^0.4.0'
  }
});

To allow backwards compatibility to plugins that do not declare a dependency on this module, pass an options object with allowIndependents:true:

var plugins = subject.getPlugins({
  "d-pac": [
    {
      "name": "test",
      "description": "test",
      "type": "select"
    }
  ]
}, {
  allowIndependents: true
);