A plain JavaScript validator for AT Protocol lexicon schemas
JavaScript 94.6%
TypeScript 5.4%
16 1 1

Clone this repository

https://tangled.org/chadtmiller.com/lexicon.js https://tangled.org/did:plc:bcgltzqazw5tb6k2g3ttenbj/lexicon.js
git@knot.tangled.wizardry.systems:chadtmiller.com/lexicon.js git@knot.tangled.wizardry.systems:did:plc:bcgltzqazw5tb6k2g3ttenbj/lexicon.js

For self-hosted knots, clone URLs may differ based on your setup.

Download tar.gz
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