0.1.3 • Published 6 years ago

protocolsio-schemas v0.1.3

Weekly downloads
1
License
GPL-3.0
Repository
github
Last release
6 years ago

Support This Project via Liberapay

protocolsio-schemas

This package is meant to provide a collection of schemas that model all objects available in the Protocols.io v3 api. As well a jsonschema validator object is provided that allows you to validate any instance of a Protocols.io object to check if it is valid according to the schema. All schemas are implemented using JSON-SCHEMA.

View the NPM page here

Index

Installation

npm install --save protocolsio-schemas

Quick Start

import { ProtocolsIOValidator, User } from 'protocolsio-schemas'
let u = {
  "name": "Vladimir Frolov",
  "affiliation": null,
  "username": "vladimir-frolov10",
  "link": null,
  "image": {
    "source": "https://s3.amazonaws.com/pr-journal/djqbjf6.jpg",
    "placeholder": "https://s3.amazonaws.com/pr-journal/djqbjf6.jpg"
  }
}

console.log(ProtocolsIOValidator.validate(u, User))

Available Imports

Import any object from the protocolsio-schema package using its object name.

import {
  User, Image, Reagent,
  Comment, SmallProtocol, Protocol,
  Step, StepComponent, Case,
  StepComponentType1, StepComponentType3, StepComponentType4,
  StepComponentType6, StepComponentType7, StepComponentType8,
  StepComponentType9, StepComponentType13, StepComponentType15,
  StepComponentType17, StepComponentType18, StepComponentType19,
  StepComponentType20, StepComponentType21, StepComponentType22,
  StepComponentType24, StepComponentType25, StepComponentType26,
} from 'protocolsio-schema'

Objects

Note: Under guidance from the Protocols.IO API developer the following fields are currently the only ones that can be confidently said to never be null: id, title, uri, and created_on. Code your checks around this appropriately.

User

propertytypedescription
namestringuser full name
affiliationstring OR nulluser affiliation
usernamestring OR nullusername
linkstring OR nullexternal url.
imageImageuser profile image

Image

propertytypedescription
sourcestring OR nulllink to the image.
placeholderstring OR nulllink to the image placeholder or original image link of placeholder is not exist

Reagent

propertytypedescription
idintegerunique reagent integer identifier.
mol_weightnumbermolarity weight
namestringname of reagent.
linforstringlinear formula
urlstring OR nullexternal url
skustringreagent sku.
vendorUserreagent vendor.

Comment

propertytypedescription
idintegerunique comment integer identifier.
parent_idintegerid of parent comment.
titlestringtitle of comment.
bodystringbody of comment.
created_onintegerunix timestamp. date/time of comment creation.
changed_onintegerunix timestamp. date/time when comment was modified last time.
creatorUsercomment creator.
commentsArray<Comment>comment replies.

Small Protocol

propertytypedescription
idintegerunique protocol integer identifier.
titlestringprotocol title.
imageImageprotocol image.
version_idinteger0...n. Version number of this protocol.
doistring OR nullDOI of this protocol.
uristringunique protocol text identifier.
published_oninteger OR nullunix timestamp. date/time when this protocol was published.

Protocol

propertytypedescription
idintegerunique protocol integer identifier.
titlestringprotocol title.
imageImageprotocol image.
doistringDOI of this protocol.
uristringunique protocol text identifier.
published_oninteger OR nullunix timestamp. date/time when this protocol was published.
created_onintegerunix timestamp. date/time of protocol creation.
creatorUserprotocol creator
publicinteger1 or 0. 1 means that this protocol is public and 0 otherwise.
versionsArray<SmallProtocol>list of versions
version_idinteger0...n. Version number of this protocol.
linkstringLink to this protocol.
number_of_stepsinteger OR nullnumber of steps of this protocol.
authorsArray<User>list of user or empty array
stepsArray<Step>All of the steps in this protocol.
materialsArray<Reagent>Reagents required for this protocol.

Step

propertytypedescription
idintegerunique step integer identifier.
guidstringunique step guid.
previous_idintegerid of previous step.
previous_guidstring OR nullguid of previous step.
modified_onintegerunix timestamp. date/time when step was modified.
componentsStepComponentlist of step components.

Step Component

propertytypedescription
idintegerunique step integer identifier.
guidstringunique step guid.
order_idintegersequence number of component in the list starting from 0.
type_idintegertype of of component, one of step component types.
titlestringname of component.
sourceArray<StepComponentType>variative object of component, can be determine by type_id

Step Component Type

There are LOTS of Step Component Types: Read More Here

Case

propertytypedescription
titlestringtitle of a case.
labelstring OR nulllabel of a case.
step_idinteger OR nulllinked step id.
step_guidstring OR nulllinked step guid.

Object Validation

To validate an object after constructing it you simply need to import the ProtocolsIOValidator object and the associated object schema. Once you have done that you can get a validation object by running the validate() function of the validator.

Following is an example of constructing and validating a Protocols.io User object.

import { ProtocolsIOValidator, User } from 'protocolsio-schemas'
let u = {
  "name": "Vladimir Frolov",
  "affiliation": null,
  "username": "vladimir-frolov10",
  "link": null,
  "image": {
    "source": "https://s3.amazonaws.com/pr-journal/djqbjf6.jpg",
    "placeholder": "https://s3.amazonaws.com/pr-journal/djqbjf6.jpg"
  }
}

console.log(ProtocolsIOValidator.validate(u, User))

Example Validator Output

ValidatorResult {
  instance:
   { name: 'Vladimir Frolov',
     affiliation: null,
     username: 'vladimir-frolov10',
     link: null,
     image:
      { source: 'https://s3.amazonaws.com/pr-journal/djqbjf6.jpg',
        placeholder: 'https://s3.amazonaws.com/pr-journal/djqbjf6.jpg' } },
  schema:
   { id: '/ProtocolsIO/User',
     title: 'User',
     description: 'A Protocols.io User object. http://apidoc.protocols.io/v3/#user-object',
     type: 'object',
     properties:
      { name: [Object],
        affiliation: [Object],
        username: [Object],
        link: [Object],
        image: [Object] },
     required: [ 'name', 'affiliation', 'username', 'link', 'image' ] },
  propertyPath: 'instance',
  errors: [],
  throwError: undefined,
  disableFormat: false }

The ProtocolsIOValidator is an instance of the Validator class from the json schema package. To learn more about what validate returns and how it works please visit the jsonschema documentation

Development

Project Structure

All of the source code is written in ES6 javascript. You will find all ES6 source code under /src. Within that folder you will find a /test and /schemas folder. Schemas contains a JSON-SCHEMA spec for each object. Tests contains a validation script for each object that runs the validate function on several several test objects.

Building Project

After making changes to any of the code in the /src/ folder simply run the following command in the root folder of the project.

npm run build

Running Tests

In the root folder of the project run the following command to run tests.

npm run test
0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.0.9

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago