SSB Messages
Message-processing tools for secure-scuttlebutt
var mlib =
indexLinks
indexLinks(msg: Object, [opts: Options], each: Function(link: Object, rel: String))
where Options = { rel: String, msg: Bool/String, feed: Bool/String, ext: Bool/String }
Traverses a message and runs the each
function on all found links. All opts
fields are optional. Opts
may also be a string, in which case it is the rel attribute
// assume %msgid and @feedid a well-formedvar msg = foo: link: '%msgid' bar: link: '@feedid' { console }mlib// => foo %msgid// => bar @feedidmlib// => foo %msgidmlib// => foo %msgidmlib// => bar @feedidmlib// => bar @feedid
links (or asLinks)
links(obj: Any, [requiredAttr: String])
Helper to get links from a message in a regular array form.
var msg = foo: link: '%msgid' bar: link: '@feedid' mliblinksmsgfoo // => [{ link: '%msgid' }]mliblinksmsgbar // => [{ link: '@feedid' }]mliblinksmsgbar 'feed' // => [{ link: '@feedid' }]mliblinksmsgbar 'msg' // => []mliblinksmsgbaz // => []
link (or asLink)
link(obj: Any, [requiredAttr: String])
Helper to get a link from a message in a regular object form. If an array is found, will use the first element.
var msg = foo: link: '%msgid' bar: link: '@feedid' mliblinkmsgfoo // => { link: '%msgid' }mliblinkmsgbar // => { link: '@feedid' }mliblinkmsgbar 'feed' // => { link: '@feedid' }mliblinkmsgbar 'msg' // => nullmliblinkmsgbaz // => null
isLink
isLink(obj: Any, [requiredAttr: String])
Predicate to test whether an object is a well-formed link. Returns false if given an array.
var msg = foo: link: '%msgid' bar: link: '@feedid' mlib // => truemlib // => truemlib // => truemlib // => falsemlib // => false
linksTo
linksTo(a: Message, b: Message)
Get link objects pointing from a
to b
.
mlib // => [{ link: '%msgB-id' }]
relationsTo
relationsTo(a: Message, b: Message)
Get relations of links pointing from a
to b
.
mlib // => ['fooRelation']