-
Notifications
You must be signed in to change notification settings - Fork 0
dBrowser Profiles API
Jared Rice Sr edited this page Jun 30, 2018
·
3 revisions
dBrowser's API was created for creating, reading and writing dPack Vaults
to the dWeb, seen by dBrowser as User Profile Vaults
.
- represents a user (identity),
- broadcasts information (bookmarks, posts, etc), and
- and follows other profiles (social relationships).
var dBrowserProfilesAPI = require('@dbrowser/api')
// create a ddb instance
var ddb = await dBrowserProfilesAPI.open(injestPathOrName[, mainUserVault]) // mainUserVault is a DPackVault instance
// management
// =
await ddb.close(destroy: Boolean) // close ddb instance, optionally delete its data
await ddb.addVault(vault) // add vault to the ddb
await ddb.addVaults(vaults) // add vaults to the ddb
await ddb.removeVault(vault) // remove vault from the ddb
ddb.listVaults() // list vaults in the ddb
await ddb.pruneUnfollowedVaults(mainUserVault) // remove vaults from the ddb that aren't followed by mainUserVault
// profile data
// =
await ddb.getProfile(vault) // => {name:, bio:, avatar:}
await ddb.setProfile(vault, {name:, bio:})
// social relationships
// =
await ddb.follow(vault, targetUser, targetUserName?)
await ddb.unfollow(vault, targetUser)
ddb.getFollowersQuery(vault) // get InjestQuery for followers
await ddb.listFollowers(vault) // list users in ddb that follow the user
await ddb.countFollowers(vault) // count users in ddb that follow the user
await ddb.listFriends(vault) // list users in ddb that mutually follow the user
await ddb.countFriends(vault) // count users in ddb that mutually follow the user
await ddb.isFollowing(vaultA, vaultB) // => true
await ddb.isFriendsWith(vaultA, vaultB) // => true
// bookmarks
// =
await ddb.bookmark(vault, href, {
title: string
})
await ddb.unbookmark(vault, href)
ddb.getBookmarksQuery({
tag: string | Array<string>,
author: url | DPackVault | Array<url | DPackVault>,
offset: number,
limit: number,
reverse: boolean
})
await ddb.listBookmarks({
// all opts from getBookmarksQuery, plus:
fetchAuthor: boolean
})
await ddb.getBookmark(vault, href)
await ddb.isBookmarked(vault, href)
// internal pinned bookmarks index
await ddb.setBookmarkPinned(href, pinned)
await ddb.listPinnedBookmarks(vault)
// list / count tags
await ddb.listBookmarkTags() // emits an array of strings
await ddb.countBookmarkTags() // emits an object of {[tag]: number}
// publishing vaults
// =
await ddb.publishVault(userVault, targetVault)
await ddb.publishVault(userVault, {
url: string,
title: string,
description: string,
type: string | Array<string>
})
await ddb.unpublishVault(userVault, targetVault)
await ddb.unpublishVault(userVault, targetVaultUrl)
// get InjestQuery for vaults
await ddb.getPublishedVaultsQuery({
author: url | DPackVault, (who published the vault)
vault: url | DPackVault, (which vault to list the publishings for)
after: timestamp,
before: timestamp,
offset: number,
limit: number,
reverse: boolean
})
// get vault records
await ddb.listPublishedVaults({
// all opts from getPublishedVaultsQuery, plus:
fetchAuthor: boolean,
countVotes: boolean
})
await ddb.countPublishedVaults({
// all opts from getPublishedVaultsQuery
})
await ddb.getPublishedVault(recordUrl)
// posting to the feed
// =
await ddb.post(userVault, {
text: 'Hello, world!',
})
// posting a reply
await ddb.post(userVault, {
text: 'Hello, world!',
threadParent: parent._url, // url of message replying to
threadRoot: top._url // url of topmost ancestor message - defaults to threadParent's value
})
// reading the feed
// =
// get InjestQuery for posts
ddb.getPostsQuery({
author?: url | DPackVault,
rootPostsOnly: boolean, filter out posts in the feed that are replies
after: timestamp,
before: timestamp,
offset: number,
limit: number,
reverse: boolean
})
// get post records
await ddb.listPosts({
// all opts from getPostsQuery, plus:
fetchAuthor: boolean,
fetchReplies: boolean,
countVotes: boolean
})
await ddb.countPosts(/* same opts for getPostsQuery */)
await ddb.getPost(url)
// votes
// =
await ddb.vote (userVault, {
vote: number (-1, 0, or 1),
subject: string (a url),
subjectType: string (ie 'dsite')
})
ddb.getVotesForQuery(subject)
ddb.getVotesBySubjectTypeQuery(type, {after, before, offset, limit, reverse})
ddb.getVotesByAuthorQuery(author, {after, before, offset, limit, reverse})
await ddb.listVotesFor(subject)
await ddb.listVotesBySubjectType(type, {
// all opts from getVotesBySubjectTypeQuery, plus:
fetchAuthor: boolean
})
await ddb.listVotesByAuthor(/* same opts for getVotesByAuthorQuery */)
// this returns {up: number, down: number, value: number, upVoters: array of urls, currentUsersVote: number}
async ddb.countVotesFor(subject)