ssbc/ssb-poll-schema

Name: ssb-poll-schema

Owner: Secure Scuttlebutt Consortium

Description: null

Created: 2018-03-14 00:43:50.0

Updated: 2018-05-11 00:20:26.0

Pushed: 2018-05-11 00:20:24.0

Homepage: null

Size: 211

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Build Status

ssb-poll-schema

Gives parsers and validators for all known schema versions of ssb-poll messages

Motivation

As well as this being a useful module for scuttle polls, it's a spec for how to publish and version schema on ssb.

This module gives you parsers that will return a 'normalised' object, regardless of of the shape of the object to parse. The position and poll objects returned by the parsers are defined in ./schema.

A change in major version of this module means that there is a breaking change to the shape of the 'normalised' object. An example of a breaking change would be that a required property in the schema was removed.

A minor version change could be that a new property was added to a schema but that isn't a required field.

Example
{ isPoll } = require('ssb-poll-schema')

validPoll = {
pe: 'poll',
rsion: 'v1',
tle: 'what is for dinner',
dy: 'this is really important, please let me know',
osesAt: '2018-03-15T03:40:06.222Z',
tails: {
type: 'chooseOne',
choices: ['lasagne', 'avos', 'tacos']



ole.log(isPoll(validPoll)) // => true
API
Validators
Parsers
Parser Errors (useful for debugging)

Returns something shaped like:

:
 { field: 'data.title',
   message: 'is required',
   value: [Object],
   type: 'object',
   schemaPath: [] },
 { field: 'data.details',
   message: 'is required',
   value: [Object],
   type: 'object',
   schemaPath: [] 
 } 
 

Version strings

Returns an object with version string constants useful for publishing messages.


_SCHEMA_VERSION_STRING: 'v1'

Important note for mantainers of this module or if you add your own schema:

How / when should you modify schema and version numbers:

You have an existing schema but it's missing a constraint that must be added. You want existing messages to fail validation if they fail the new constraint.
You have an existing schema but it has a constraint that must be removed. You want existing messages that would have failed validation to be passed by this new schema.
You have an existing schema and want to add a new property that is optional (not required in the schema).
Want to use your schema with this project?

There are two ways you can use your schema with this module.

Make your schema official

To contribute your schema:

sockets = combine([
quire('./v1/'),
quire('./v2/'),
quire('<your-module>') 

Combine these schema with some of your own in another module

This module exports it's depject combinable schema as schema so you could do something like this in your own module:

pollSchema = require('ssb-poll-schema')
combine = require('depject')
{first} = require('depject/apply')

yourSchema = require('./your-schema')

sockets = combine(pollSchema.concat(yourSchema)) 

isPoll = first(sockets.poll.isPoll, 'poll.isPoll')

ole.log(isPoll({})) // => false

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.