A plain JavaScript validator for AT Protocol lexicon schemas
1# lexicon-js
2
3A plain JavaScript validator for [AT Protocol Lexicon](https://atproto.com/specs/lexicon) schemas.
4
5## Install
6
7```bash
8npm install @bigmoves/lexicon
9```
10
11## Usage
12
13```javascript
14import { validateLexicons, validateRecord } from '@bigmoves/lexicon'
15
16// Validate a lexicon schema
17const lexicon = {
18 lexicon: 1,
19 id: 'app.example.post',
20 defs: {
21 main: {
22 type: 'record',
23 key: 'tid',
24 record: {
25 type: 'object',
26 required: ['text'],
27 properties: {
28 text: { type: 'string', maxLength: 300 }
29 }
30 }
31 }
32 }
33}
34
35const schemaError = validateLexicons([lexicon])
36// null if valid, error object if invalid
37
38// Validate a record against a lexicon
39const record = { text: 'Hello, world!' }
40const dataError = validateRecord([lexicon], 'app.example.post', record)
41// null if valid, { path, message } if invalid
42```
43
44## Testing
45
46```bash
47npm test
48```
49
50## Spec Compliance
51
52This implementation follows the [AT Protocol specs](https://atproto.com/specs/lexicon). See [docs/oracle-differences.md](./docs/oracle-differences.md) for documented differences with @atproto/lexicon.
53
54## License
55
56MIT