Factories for cobox log messages validated with JSON schemas and encoded with Protocol Buffers
Kieran Gibb 40f5071898
Merge branch 'development'
2 years ago
definitions match a minimum of 272 characters 2 years ago
encoders add name to replicate/unreplicate command schema 2 years ago
schemas add name to replicate/unreplicate command schema 2 years ago
test Merge branch 'development' 2 years ago
LICENSE add a readme 2 years ago
README.md correct README 2 years ago
compile.js log when all schemas are compiled 2 years ago
index.js export definitions 2 years ago
package.json 1.0.1-alpha 2 years ago
util.js ensure author is a hex str 2 years ago

README.md

cobox-schemas

This module exports a set of object factories for use with a hypercore. Factories build payloads for a cobox-log using JSON schemas for validation and Protocol Buffers for encoding.

This module also exports all currently used message schemas in CoBox as raw validators and encoders.

In order to use the protocol-buffers message encoders, you’ll need to pre-compile them.

npm run compile
const Factory = require('../')
const author = 'a94fd23d17443e336b798642db689492344c9a35dc37d93e529acd4a432c64c3'
const { PeerAbout, GroupAbout } = Factory(author)

// Lets build a new peer/about message with a name...
PeerAbout({ name: 'magpie' }, (err, payload) => {
  // The returned protocol buffer is an encoded message which when decoded takes the following format
  // {
  //   timestamp: 1580748966968,
  //   author: 'a94fd23d17443e336b798642db689492344c9a35dc37d93e529acd4a432c64c3',
  //   content: {
  //     type: 'peer/about',
  //     name: 'magpie'
  //   }
  // }

  // Now lets do the same for the name of a group...
  GroupAbout({ name: 'Magma Collective' }, (err, payload) => {
  // {
  //   timestamp: 1580748966968,
  //   author: 'a94fd23d17443e336b798642db689492344c9a35dc37d93e529acd4a432c64c3',
  //   content: {
  //     type: 'group/about',
  //     name: 'Magma Collective'
  //   }
  // }
  })
})