ssb-whakapapa v4.0.0
ssb-whakapapa
An ssb-server plugin for creating, reading, updating relationships between profiles
Example Usage
const Server = require('ssb-server')
const Config = require('ssb-config/inject')
const config = Config({})
const server = Server
.use(require('ssb-master'))
.use(require('ssb-backlinks'))
.use(require('ssb-whakapapa')) // <<<<<<
.call(null, config)
const details = {
child: '%P5r79KsntEGPMp0Zd24bvfDBMtfx1SADMEE7yxBdVVw=.sha256',
parent: '%4BmROhXcW6H4VyATrIj7uOWqHyW5q5jFZpDHo5RofSc=.sha256',
}
const opts = {
relationshipType: 'birth',
recps: [
'@ye+QM09iPcDJD6YvQYjoQc7sLF/IFhmNbEqgdzQo3lQ=.ed25519'
]
}
server.whakapapa.child.create(details, opts, (err, linkId) => {
// ...
})// later:
server.whakapapa.get('%P5r79KsntEGPMp0Zd24bvfDBMtfx1SADMEE7yxBdVVw=.sha256', (err, data) => {
console.log(data)
// => {
// id: '%P5r79KsntEGPMp0Zd24bvfDBMtfx1SADMEE7yxBdVVw=.sha256',
// parentLinks: [
// {
// id: '%4BmROhXcW6H4VyATrIj7uOWqHyW5q5jFZpDHo5RofSc=.sha256',
// linkId: '%W5q4BmROhXcW6H4VyATrIj7uOWqHy5jFZpDHo5RofSc=.sha256',
//
// relationshipType: 'birth',
// legallyAdopted: null // null means it hasnt been set
// tombstone: null
// }
// ],
// childLinks: []
// }
})API
Views: - view.create - view.get - view.update - view.tombstone - view.list
Relationships: - get - child - child.create - child.get - child.update - child.tombstone - child.list - partner - partner.create - partner.get - partner.update - partner.tombstone - partner.list
Links:
view:
server.whakapapa.view.get
Fetch a "view" of whakapapa - this is a minimal record which stores the sdetails needed to construct a particular perspective on a graph of relationships.
e.g. we might want to see all the descendants of a particular ancestor. To do this we store the profileId of that ancestor and the mode of drawing (down!). We might also include preferences about whether to include whangai or adopted descendants for example.
server.whakapapa.view.get(viewId, cb)
viewIdMessageId - the id of the root message of a viewcbfunction - a callback of signature(err, data), wheredatais an Object with properties:nameString - the name of this whakapapa viewdescriptionString - the name of this whakapapa viewrecordCountInteger - number of decendants linked to the focus (starting profile)ignoredProfilesArray - an array of ProfileIds which have been marked to ignore (don't render these please). Returns[]if there are none.focusProfileId - the id of the profile we start frommodeString - the way to draw the graph. (can be'descendants' | 'ancestors')tombstoneObject - date and reasonpermissionString - whether tribe members can'edit | view | submit'this whakapapa record
If any of these are not set, these properties will still be present, but the values will be null
server.whakapapa.view.create
Creates a new message of type whakapapa/view
server.whakapapa.view.create(details, cb)
detailsObject - contains information to start off viewcbfunction - a form(err, viewId)
The expected form of details is :
{
name: String, // required (for create)
description: String,
image: Image,
focus: ProfileId,
recordCount: Integer,
mode: Mode,
permission: String,
tombstone: Tombstone,
ignoredProfiles: { add: [ProfileId] },
importantRelationships: {
[ProfileId]: [ProfileId, ... ] // a way of declaring relationship priorities for specific profiles
},
recps: [GroupId, FeedId, ...]
}Notes:
Modecan be'descendants' | 'ancestors'Permissioncan be'view' | 'edit | submit'Imageis an Object of form{ blob: '&07xxrn0wWbtRx/gp4IF7THPeWZUT1LWt93IVHTbitFE=.sha256', mimeType: 'image/png' }Tombstoneis an Object of form{ reason: String, date: UnixTime }importantRelationshipsexists as a way to resolve some challenges with drawing whakapapa- sometimes because of intermarriage, a person can appear in two places on a graph
- if you only want them drawn once, you can specify who is is most important for a particular profile
- e.g.
{ @tamaId: ['@whangaiDadId', '@birthMumId'] }is a way to express "I would like tama to be drawn closer to their whangai dad in this whakapapa, but secondarily also show a link across the graph to their birth mum".
recpsis a special field which encrypts the view (and all subsequent updates) to a specified set of FeedIds
server.whakapapa.view.update
server.whakapapa.view.update(viewId, details, cb)
viewIdMessageId - the id of the view to updatedetailsObject - same as inview.create, exceptignoredProfilescan also be{ ignoredProfiles: { remove: [ProfileId] } }for updatesrecpsis inherrited from the create message (root), so setting it here does nothing.nameis not required
cbfunction - callback with signature(err)
server.whakapapa.get
Get children and parents of a particular profile.
server.whakapapa.get(ProfileId, cb)
ProfileIdString - the id for a profilecbFunction - a callback of signature(err, data)
data format
{
parentLinks: [
{
id: '%4BmROhXcW6H4VyATrIj7uOWqHyW5q5jFZpDHo5RofSc=.sha256',
linkId: '%47uOWqHyW5q5jFZpDHo5RofBmROhXcW6H4VyATrIjSc=.sha256',
relationshipType: 'birth',
legallyAdopted: null,
tombstone: null
},
{
id: '%r86qOq2KNY3GlifR6UgQaB05ZfXmHlnxxoFlyi9OI0A=.sha256'
linkId: '%W5q5j47uOWqHyFZpDHo5RofBmROhXcW6H4VyATrIjSc=.sha256',
relationshipType: null, // this means relationshipType hasnt been set
legallyAdopted: null,
tombstone: {
date:
}
}
],
childLinks: [
{
id: '%pCt2QB3ZxZEsKIYvxGI9QBmytrUNZfuuRbNk8i0V7ug=.sha256',
linkId: '%yFZpDHo5RoW5q5j47uOWqHfBmROhXcW6H4VyATrIjSc=.sha256',
relationshipType: 'whangai',
legallyAdopted: false,
tombstone: null
}
]
}server.whakapapa.view.tombstone
server.whakapapa.view.tombstone(viewId, opts, cb)
viewIdMessageId - the root key of the whakapapa view recordoptsObject with properties:reasonString (optional) give a reason for why you're tombstoning the recordundoBoolean (optional) set totrueto remove the tombstone
cbfunction - callback with signature(err)
server.whakapapa.view.list
Find all whakapapa/view record, options to narrow that query down.
server.whakapapa.child.lists(opts, cb)
optsObject - see ssb-crut list optscbfunction - callback with signature(err, links), wherelinksis an Array of link records
relationships - child
server.whakapapa.child.create
Creates a new updateable message of type link/profile-profile/child connecting two profiles - a parent and a child.
server.whakapapa.child.create({ child, parent }, opts, cb)
childString a scuttlebutt MessageId pointing to a profile rootparentString a scuttlebutt MessageId pointing to a profile rootoptsObject - describes the values to set on that relationship and who can read it.cbFunction - a callback of signature(err, linkId)wherelinkIdis the id of the relationship which has just been created
opts format
{
relationshipType: ParentType, // optional
legallyAdopted: Boolean // optional
tombstone: TombStone // optional
recps: [ FeedId ] // optional
}MessageIdis scuttlebutt message cypherlink e.g.%4BmROhXcW6H4VyATrIj7uOWqHyW5q5jFZpDHo5RofSc=.sha256ParentTypeis any of'birth' | 'adopted' | 'whangai' | 'unknown'legallyAdoptedshould only be set ifrelationshipTypeis'adopted'or'whangai'Tombstoneis an Object of form{ date: UnixTime, reason: String }and marks a link as deleted.recpsis an Array ofFeedId(e.g.'@ye+QM09iPcDJD6YvQYjoQc7sLF/IFhmNbEqgdzQo3lQ=.ed25519'). If this is provided this relationship will automatically be encrypted so only the mentioned parties will be able to see this. (NOTE - you cannot change this later)
Notes
- If you don't want to add any optional opts, set
optstonullor{} - this is now a wrapper over
whakapapa.link.create
:construction: TODO
- add
GroupIdto recps once we have private-groups released - add some way to validate whakapapa links
- e.g. an approval system so that kaitiaki (custodians) at each end of the relationship can approve the link?
- need to make sure that can't change pointer for child / parent after an "approval" of link
server.whakapapa.child.update
This updates a child relationship (not the child themself).
server.whakapapa.child.update(linkId, opts, cb)
linkIdMessageId - the root key of the relationshipoptsObject - same as inchild.create, except recps is set for you based on what the first message was.cbfunction - callback with signature(err)
:construction: TODO
- needed for tombstoning
server.whakapapa.child.tombstone
server.whakapapa.child.tombstone(linkId, opts, cb)
linkIdMessageId - the root key of the relationshipoptsObject with properties:reasonString (optional) give a reason for why you're tombstoning the recordundoBoolean (optional) set totrueto remove the tombstone
cbfunction - callback with signature(err)
server.whakapapa.child.list
Find all link/profile-profile/child links, options to narrow that query down.
server.whakapapa.child.lists(opts, cb)
optsObject - see ssb-crut list optscbfunction - callback with signature(err, links), wherelinksis an Array of link records
partner methods
Similar to child methods, but details are empty The valid mutations are:
relationshipTypeis any of'partners' | 'married' | 'divorced' | 'unknown'tombstone(same as for child)
server.whakapapa.partner.create
server.whakapapa.partner.get
server.whakapapa.partner.update
server.whakapapa.partner.tombstone
server.whakapapa.partner.list
link methods
server.whakapapa.link.create
A generic link creating method
server.whakapapa.link.create({ type, parent, child }, details, cb)
typeString - the sort of link you want to make. This will become the messagetype, one of:link/profile-profile/childlink/profile-profile/partnerlink/story-profile/contributorlink/story-profile/creatorlink/story-profile/mentionlink/story-artefactlink/story-story
parentMessageId - the id of the "parent" end the linkdetailsObject - a collection of initial transformations for the link. Useful for storing meta-data, and declaringrecps(private recipients). The valid form of this depends on thetypeonly the "child" link currently has any details
cb
server.whakapapa.link.get
server.whakapapa.link.get(id, cb)
idMessageId - the id of the thing you're inspecting for links
server.whakapapa.link.update
A generic link updating method, this figures out what sort of link it is and updates accordingly.
server.whakapapa.link.update(id, details, cb)
idMessageId - the id of the thing you're inspecting for linksdetailsObject - same as#createmethod details (except you can't changerecpshere)cb
server.whakapapa.link.tombstone
server.whakapapa.link.get(id, details, cb)
idMessageId - the id of the thing you're inspecting for linksdetailsObject which accepts optional inputsdetails.reason,details.undo = true
server.whakapapa.link.getLinksOfType
Find all links of type type attached to a particular messaged id.
server.whakapapa.link.getLinksOfType(id, type, cb)
idMessageId - the id of the thing you're inspecting for linkstypeString - the "type" of links you want to surface (e.glink/story-artefact)cb
server.whakapapa.link.list
Find all links of a particular "type", with options to narrow that query down.
server.whakapapa.link.list(type, opts, cb)
typeString - one of the valid link types this module works withoptsObject - see ssb-crut list opts
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago