<commit_before>
//these are the async functions.
var async = [
  'add',
  'getPublicKey',
  'getLatest'
]

//these are the readable streams.
var readable = [
  'createFeedStream',
  'createHistoryStream',
  'createLogStream',
  'messagesLinkedTo',
  'feedsLinkedTo',
  'feedsLinkedFrom'
]


//connect to server, and expose this api.
module.exports = function (opts) {
  if(!opts.id)
    throw new Error('must provide the local feed id')

  var api = {}
  async.forEach(function (name) {
    api[name] = function () {
      var args = [].slice.call(arguments)
      var cb = args.pop()
      if(!isFunction(cb))
        throw new Error('cb *must* be provided')
      //send request to backend.
    }
  })
  streams.forEach(function (name) {
    api[name] = function () {
      //connect this stream to the backend.
      return stream(name)
    }
  })

}<commit_msg>api that supports source streams and async cbs<commit_after>var Serializer = require('pull-serializer')
var JSONB = require('json-buffer')
var muxrpc = require('muxrpc')
var toPull = require('stream-to-pull-stream')
var pull = require('pull-stream')

function serialize (stream) {
  return Serializer(stream, JSONB)
}


var manifest = {
  async: [
    'add',
    'getPublicKey',
    'getLatest'
  ],

  source: [
    'createFeedStream',
    'createHistoryStream',
    'createLogStream',
    'messagesLinkedTo',
    'feedsLinkedTo',
    'feedsLinkedFrom'
  ]
}

//connect to server, and expose this api.
exports = module.exports = function (ssb, feed) {

  if(!ssb) throw new Error('ssb is required')
  if(!feed) throw new Error('feed is required')


  var api = {}
  for(var key in manifest) {
    manifest[key].forEach(function (name) {
      api[name] = function () {
        console.log('CALL', name)
        var args = [].slice.call(arguments)
        var f = ssb[name].apply(ssb, args)
        if(f)
          return pull(f, function (read) {
            return function (abort, cb) {
              read(abort, function (err, data) {
                console.log('>>>', err, data)
                cb(err, data)
              })
            }
          })
      }
    })
  }

  // initialize the feed to always be with respect to
  // a given id. or would it be better to allow access to multiple feeds?

  api.add = function (type, message, cb) {
    console.log('ADD', type, message)
    feed.add(type, message, cb)
  }

  return api
}

exports.client = function () {
      // muxrpc(remote, local, serialization)
  return muxrpc(manifest, null, serialize) ()
}

exports.server = function (ssb, feed) {
  return muxrpc(null, manifest, serialize) (exports(ssb, feed))
}


{'fraction_non_alphanumeric': 0.1359848484848485, 'fraction_numerical': 0.0, 'mean_word_length': 2.7040673211781208, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4770081', 'n_tokens_mistral': 854, 'n_tokens_neox': 835, 'n_words': 235}