A plain JavaScript validator for AT Protocol lexicon schemas
README.md

lexicon-js #

A plain JavaScript validator for AT Protocol Lexicon schemas.

Install #

npm install @bigmoves/lexicon

Usage #

import { validateLexicons, validateRecord } from '@bigmoves/lexicon'

// Validate a lexicon schema
const lexicon = {
  lexicon: 1,
  id: 'app.example.post',
  defs: {
    main: {
      type: 'record',
      key: 'tid',
      record: {
        type: 'object',
        required: ['text'],
        properties: {
          text: { type: 'string', maxLength: 300 }
        }
      }
    }
  }
}

const schemaError = validateLexicons([lexicon])
// null if valid, error object if invalid

// Validate a record against a lexicon
const record = { text: 'Hello, world!' }
const dataError = validateRecord([lexicon], 'app.example.post', record)
// null if valid, { path, message } if invalid

Testing #

npm test

Spec Compliance #

This implementation follows the AT Protocol specs. See docs/oracle-differences.md for documented differences with @atproto/lexicon.

License #

MIT