2.0.6 • Published 5 years ago

scuttle-book v2.0.6

Weekly downloads
6
License
AGPL-3.0
Repository
github
Last release
5 years ago

Scuttle-book

A helper module which covers all your ssb book related needs from fetching book data, creating new book entries, and validating whether a message is of a standard form.

The parts of this modules are :

  • queries / getters
  • publishing helpers

Usage

const Book = require('scuttle-book')
const book = Book(server)   // server is sometimes called sbot

const newBook = {
  title: 'The Dispossessed',
  author: 'Ursula le Guin'
}

book.async.create(newBook, (err, bookMsg) => {
  if (err) // handle error

  book.isBook(bookMsg)
  // => true
})

Constructor API

Book(server, opts)

server is a connection to your scuttlebutt server provided by ssb-client (sometimes called sbot in other docs).

opts (options) an Object with over-ride options for the scuttle-book instance:

Instance API

book.async.create(book, cb)

book - an Object which must at least have title, author. If a book doesn't pass the isBook validator, the callback is called with the errors : cb(errors)

book.async.update(bookId, attributes, cb)

Validates and posts an update to an existing book.

book.async.comment(updateId, latestCommentId, text, cb)

Validates and posts a comment.

latestCommentId is optional, if not provided, it will be calculated.

book.pull.books(opts, hydrate, loadComments)

A stream of all books. If hydrate is passed, all changes to books will also be loaded and the final state of each book returned. Otherwise raw book messages are returned.

FIXME: live instead of updates?

book.pull.comments()

A stream of comments on books

book.pull.updates()

A stream of updates on books. You can filter this yourself to pull out just ratings, or description updates etc).

FIXME: other helpers: shelves, authors, users

book.async.get(key, loadComments, cb)

Gets a reduced state of the 'book as a whole' of the form:

{
  key: MessageId,
  title: String,
  description: String,
  authors: [ String, String, ... ],
  images: [ Image, Image, ... ] // Objects of same form as image property
  series: String, // the name of the series
  seriesNo: String, // the book number

  subjective: { FeedId: {
    review: String,
    rating: String, // e.g. 4
    ratingMax: String, // out of, e.g. 5
    ratingType: String, // text or emoticon
    shelves: [ String, String, .... ],
    genres:  [ String, String, .... ]
    }, ...
  }
}

FIXME:

heads: MessageId, .... , // most recent message(s) in the document/ thread threads: MessageId, ... // all backlinks in causal order

Schemas

See ssb-book-schema

Development

Run the tests with npm test

Some tests require an sbot to be running and currently use your personal identity to read real books. TODO - build a test harness with an in-memory db.

2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago