开发者社区> 镜像站> NPM> ssb-schema-definitions
ssb-schema-definitions
standardised schema definitions for JSON validation of ssb references
Last updated 5 months ago by mixmix .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ssb-schema-definitions 
SYNC missed versions from official npm registry.

SSB Schema Definitions

Standardised schema definitions for SSB messages when using is-my-json-valid.

Example Usage

const Definitions = require('ssb-schema-definitions')
const Validator = require('is-my-json-valid')

const schema = {
  $schema: 'http://json-schema.org/schema#',
  type: 'object',
  required: ['type', 'tangles'],
  properties: {
    type: {
      type: 'string',
      pattern: '^profile/.*$'
    },
    preferredName: { type: 'string' },
    avatarImage: { $ref: '#/definitions/image' }, // << reference a definition
    tangles: {
      group: { $ref: '#/definitions/tangle/any' },
      profile: { $ref: '#/definitions/tangle/root' }
    },
    recps: { $ref: '#/definitions/recipients/box2' }
  },
  additionalProperties: false,
  definitions: Definitions() // attach the definitions
}

const isValid = Validator(schema)

// isValid(msgContent) => Boolean
// isValid.errors => null | [Errors]

API

Definitions() => Object

The definitions is a getter (function) so that you can pull it and mutate it awithout getting into trouble.

To see what definitions are available check out index.js.

You can also see examples of how to use most of the definitions in the tests/ folder. At time of writing there's good test coverage here for fields:

  • contentWarning
  • image
  • mentions
  • tangle
  • tombstone
  • recps (box1, box2/ envelope)

Current Tags

  • 3.2.1                                ...           latest (5 months ago)

26 Versions

  • 3.2.1                                ...           5 months ago
  • 3.2.0                                ...           5 months ago
  • 3.1.0                                ...           6 months ago
  • 3.0.1                                ...           6 months ago
  • 3.0.0                                ...           6 months ago
  • 2.1.0                                ...           9 months ago
  • 2.0.2                                ...           a year ago
  • 2.0.1                                ...           a year ago
  • 2.0.0                                ...           a year ago
  • 1.3.0                                ...           a year ago
  • 1.2.0                                ...           a year ago
  • 1.1.6                                ...           a year ago
  • 1.1.5                                ...           2 years ago
  • 1.1.3                                ...           2 years ago
  • 1.1.2                                ...           2 years ago
  • 1.1.1                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.9                                ...           2 years ago
  • 1.0.8                                ...           2 years ago
  • 1.0.7                                ...           2 years ago
  • 1.0.6                                ...           2 years ago
  • 1.0.4                                ...           2 years ago
  • 1.0.3                                ...           2 years ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago