Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Definitions
✓ const Definitions = require('ssb-schema-definitions')
✗ import Definitions from 'ssb-schema-definitions'
Package is CJS-only; no ESM exports. Use require().
Definitions()
✓ const schemaDefs = Definitions()
Definitions is a function that returns the definitions object. Must be called to get definitions.
Schema definitions (via $ref)
✓ { $ref: '#/definitions/image' }
Reference definitions using JSON Schema $ref syntax after attaching Definitions() to schema definitions property.
Shows how to require the package, attach definitions to a schema, and validate an SSB message.
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' },
tangles: {
group: { $ref: '#/definitions/tangle/any' },
profile: { $ref: '#/definitions/tangle/root' }
},
recps: { $ref: '#/definitions/recipients/box2' }
},
additionalProperties: false,
definitions: Definitions()
}
const isValid = Validator(schema)
const msg = { type: 'profile/update', tangles: { group: { root: null, previous: null }, profile: { root: null, previous: null } } }
console.log(isValid(msg)) // true
console.log(isValid.errors) // null
Errors
Common errors & fixes
require('ssb-schema-definitions') returns a function, not an object
Definitions is a factory function that must be called to get the definitions object.
fixCall Definitions() to get the definitions object.
Cannot find module 'is-my-json-valid'
Missing peer dependency is-my-json-valid.
fixnpm install is-my-json-valid
TypeError: Definitions is not a constructor
Trying to use 'new Definitions()' but it's not a class.
fixUse Definitions() without new.
Audit
Dependencies
is-my-json-validoptionalpeer dependency for JSON validation