Giter Club home page Giter Club logo

ssb-thread-schema's Introduction

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

ssb-thread-schema's People

Contributors

mixmix avatar christianbundy avatar arj03 avatar ahdinosaur avatar dependabot[bot] avatar

Stargazers

nichoth avatar Piet Geursen avatar Powersource avatar Andrew Chou avatar

Watchers

Charles E. Lehner avatar Henry avatar Jan Winkelmann avatar Dominic Tarr avatar  avatar James Cloos avatar Gordon Martin avatar peg avatar Kieran avatar  avatar  avatar

ssb-thread-schema's Issues

Re-add isNestedReply?

Hi @mixmix !

I noticed that isNestedReply() was yanked from the API and I read the note(s) about it in the readme and such, but I was wondering: would you be open to re-adding it? ๐Ÿ™ƒ

Reasoning: I understand that Patchwork's implementation doesn't match the spec, but I think the JSON schema is sufficiently general to support both the spec as you wrote it and the Patchwork implementation (which I'm using in Oasis). I'd like to avoid requiring() the file directly because I want to make sure it's covered by semver (and was confused at why Oasis started breaking after a patch version bump).

Happy to put together a quick PR if you're open to it. ๐ŸŒŸ

SSBC ownership

On the call you asked me to remind you to move this to the SSBC org, so I'm making an issue for that. I'll link this in my SSB post. Thanks again! ๐ŸŽ‰

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.