🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

is-my-ssb-valid

Package Overview
Dependencies
Maintainers
5
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-my-ssb-valid

build scuttlebutt message validators from JSON Schema

latest
Source
npmnpm
Version
1.2.2
Version published
Maintainers
5
Created
Source

is-my-ssb-valid

Build message validators for scuttlebutt using JSON schema. Uses is-my-json-valid under the hood

Example usage

const Validator = require('is-my-ssb-valid')
const profileSchema = require('ssb-profile/spec/profile/schema')

const isProfile = Validator(profileSchema)
const A = {
  //....
}

isProfile(A)
// => true | false

console.log(isProfile.errors)
// => null | [Error]

console.log(isProfile.errorsString)
// => '' | 'data.type is required'  (example)
const pull = require('pull-stream')

pull(
  sbot.messagesByType({ type: 'profile/person', reverse: true }),
  pull.filter(isProfile),
  pull.take(50),
  pull.collect((err, profileUpdates) => {
    // ...
  })
)

API

Validator(schema) => isValid

where:

  • schema Object is a JSON schema
  • extras Array (optional) is an Array of additional custom validation functions.
    • These will be run after the schema-based validation, and are expected to either return true (no problem) or an Error (a problem) was found.
    • any error returned be added to the isValid.errors and isValid.errorsString for you (see below)

isValid(msg) => Boolean

where msg can be any of

  • a full message a "full message" of form { key, value, timestamp }
  • just the value of a message (msg.value)
  • just the content field of a message (msg.value.content)

If the last message tested came back invalid ("false"), then you can also check out the specific errors:

  • isValid.errors will be populated with those errors
  • isValid.errorsString will be populated with a (crudely) flattened version in case you need a String

Keywords

scuttlebutt

FAQs

Package last updated on 01 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts