ssb-thread-schema
JSON schemas + validators for common thread messages
Last updated a year ago by mixmix .
AGPL-3.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ssb-thread-schema 
SYNC missed versions from official npm registry.

ssb-thread-schema

a module which provides you schemas and validators for messages involved in threads.

Example Usage

var { isRoot, isReply } = require('ssb-thread-schema')

const testMsg = {
  type: 'post',
  text: 'oh choice, finally a less janky way to check our stuff',
  root: '%+fBXl12aV1wpAdD62RMl1WRhwthDMuAuHH4iNWgB7jA=.sha256',
  branch: [
    '%PK5aWmXVYJLcmRQTc/6EQE1ht9T5Kb+wi6NgTReMKXI=.sha256'
  ]
}
// can be the content of a message or the whole thing

isRoot(testMsg)
// => false
isRoot.errors
// => helpful errors

isReply(testMsg)
// => true

API

isRoot(Object) -> Boolean

Object can be a full message from the log, or just the content from the message, the validator will take care of it.

If the test Object fails the validation, errors are attached to the function (i.e. isRoot.errors, see Example Usage)

An optional second argument can be passed to the validator if you want to tell the validator to attach errors to the test Object (this mutates the test Object):

isRoot(Object, { attachErrors: true })

isReply(Object) -> Boolean

same pattern ^

TOTALLY UNSTABLE

These methods are based on experimental schema which need massive review and are going to be totally over-hauled. Do not use them!

If you reeeeaaallly want to, require mehthods out from the files directly yourself.

isNestedReply(Object) -> Boolean

same pattern ^

isFork(Object) -> Boolean

same pattern ^

See also

  • the README in each folder with a little more about each message type
  • the birth of forks / nested replies spec : %+fBXl12aV1wpAdD62RMl1WRhwthDMuAuHH4iNWgB7jA=.sha256
    • note it's turned out this 'spec' is way sloppy - has holes in it, and has been implemented differently in Patchwork

TODO

  • votes (a.k.a. likes)
  • behaviour / flags

Current Tags

  • 1.1.1                                ...           latest (a year ago)

6 Versions

  • 1.1.1                                ...           a year ago
  • 1.0.4                                ...           a year ago
  • 1.0.3                                ...           a year ago
  • 1.0.2                                ...           a year ago
  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           a year ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (3)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |