scuttlebutt-schema

Tools for creating scuttlebutts.

scuttlebutt-schema

Tools for creating scuttlebutts.

var schema = require('scuttlebutt-schema')
var Model  = require('scuttlebutt/model')
var Events = require('scuttlebutt/events')
 
var createScuttlebutt = schema({
  modelfunction () {
    return new Model()
  },
  eventsfunction () {
    neturn new Events()
  }
})
 
//keys are matched on the prefix. 
var model1 = createScuttlebutt('model1')
var model2 = createScuttlebutt('model2')
var events1 = createScuttlebutt('events1')

open loads a scuttlebutt via a stream. given a schema, and a createStream function, open returns a async function that will callback a fully loaded scuttlebutt. the createStream function takes a string, just like schema, and should return a stream to a scuttlebutt instance with the same name, or a file where that scuttlebutt instance is persisted.

var open = require('scuttlebutt-schema').open(schema, createStream)
//now call the function with a name. 
open(name, function (errsb) {
  //sb is now ready to use! 
})

full example

 
var makeOpen = require('scuttlebutt-schema').open
 
var open = makeMake(function (name) {
  //return a scuttlebutt. 
  return new Model()
}, function (name) {
  //return a duplex stream... 
  return http.get('http://whatever.com/replicate/'+name)
})
 
open(name, function (_scuttlebutt) {
  //scuttlebutt is ready! 
})
 
 
## License
 
MIT