scuttlebutt-schema

1.2.1 • Public • Published

scuttlebutt-schema

Tools for creating scuttlebutts.

server-tests

browser-support

schema

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

open

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 (err, sb) {
  //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

Readme

Keywords

none

Package Sidebar

Install

npm i scuttlebutt-schema

Weekly Downloads

0

Version

1.2.1

License

MIT

Last publish

Collaborators

  • dominictarr