https://github.com/ssbc/ssb-schema-definitions
Standardised schema definitions for ssb message types using is-my-json-valid
https://github.com/ssbc/ssb-schema-definitions
Last synced: about 1 year ago
JSON representation
Standardised schema definitions for ssb message types using is-my-json-valid
- Host: GitHub
- URL: https://github.com/ssbc/ssb-schema-definitions
- Owner: ssbc
- Created: 2018-07-10T21:21:17.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-03-24T12:44:29.000Z (over 4 years ago)
- Last Synced: 2025-06-09T15:53:35.712Z (about 1 year ago)
- Language: JavaScript
- Size: 131 KB
- Stars: 3
- Watchers: 7
- Forks: 1
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SSB Schema Definitions
Standardised schema definitions for SSB messages when using [is-my-json-valid](https://github.com/mafintosh/is-my-json-valid).
## Example Usage
```js
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)