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
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Gives parsers and validators for all known schema versions of ssb-poll messages
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.
{ 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
isPoll
isChooseOnePoll
(also accessible under isPoll.chooseOne
)
isPosition
isChooseOnePosition
(also accessible under isPosition.chooseOne
)
parsePoll
,parsePosition
,getPollErrors
,getPositionErrors
,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: []
}
Returns an object with version string constants useful for publishing messages.
_SCHEMA_VERSION_STRING: 'v1'
How / when should you modify schema and version numbers:
required
in the schema).There are two ways you can use your schema with this module.
To contribute your schema:
./v1/index.js
for an example.sockets = combine([
quire('./v1/'),
quire('./v2/'),
quire('<your-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