Git Product home page Git Product logo

dat-nexus-api's Introduction

Dat Nexus API

An API for reading and writing-to profile archives in the Dat Nexus App. A "Profile Site" is a dat-site which

  1. represents a user (identity),
  2. broadcasts information (media feed), and
  3. and follows other profiles (social relationships).

Nexus Profile Sites are used to identify users and create social feeds.

var NexusAPI = require('dat-nexus-api')

// create a db instance
var db = await NexusAPI.open(/* cache session */)
var db = await NexusAPI.open(mainUserArchive) // mainUserArchive is a DatArchive instance

// profile data
// =

await db.getProfile() // => {name:, bio:, avatar:}
await db.setProfile({name:, bio:, avatar:})

// management
// =

await db.close(destroy: Boolean) // close db instance, optionally delete its data

await db.addArchive(archive) // add archive to the db
await db.addArchives(archives) // add archives to the db
await db.removeArchive(archive) // remove archive from the db
db.listArchives() // list archives in the db
await db.pruneUnfollowedArchives(mainUserArchive) // remove archives from the db that arent followed by mainUserArchive

// social relationships
// =

await db.follow(userArchive, targetUser, targetUserName?)
await db.unfollow(userArchive, targetUser)

db.getFollowersQuery(userArchive) // get InjestRecordSet for a followers query
await db.listFollowers(userArchive) // list users in db that follow the user
await db.countFollowers(userArchive) // count users in db that follow the user
await db.listFriends(userArchive) // list users in db that mutually follow the user
await db.countFriends(userArchive) // count users in db that mutually follow the user

await db.isFollowing(archiveA, archiveB) // => true
await db.isFriendsWith(archiveA, archiveB) // => true

// posting to the feed
// =

await db.broadcast(userArchive, {
  text: 'Hello, world!',
})

// posting a reply
await db.broadcast(userArchive, {
  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 InjestRecordSet for a broadcasts query
db.getBroadcastsQuery({
  author: url | DatArchive,
  after: timestamp,
  before: timestamp,
  offset: number,
  limit: number,
  reverse: boolean
})

// get broadcast records
await db.listBroadcasts({
  // all opts from getBroadcastsQuery, plus:
  fetchAuthor: boolean,
  fetchReplies: boolean,
  countVotes: boolean
})

await db.countBroadcasts(/* same opts for getBroadcastsQuery */)
await db.getBroadcast(url)

// votes
// =

await db.vote (userArchive, {vote, subject})
// vote should be -1, 0, or 1
// subject should be a dat url

db.getVotesQuery(subject)
await db.listVotes(subject)

// this returns {up: number, down: number, value: number, upVoters: array of urls, currentUsersVote: number}
async db.countVotes(subject)

dat-nexus-api's People

Contributors

pfrazee avatar taravancil avatar

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.