Skip to content

Instantly share code, notes, and snippets.

@vmx
Created April 14, 2026 21:06
Show Gist options
  • Select an option

  • Save vmx/4aaeaec4c61fb3b05d423eed0b4dcea4 to your computer and use it in GitHub Desktop.

Select an option

Save vmx/4aaeaec4c61fb3b05d423eed0b4dcea4 to your computer and use it in GitHub Desktop.
Validate an ATProto Lexicon with atcute.
#!/usr/bin/env node
/**
* validate-lexicon.mjs
*
* Validates a local AT Protocol Lexicon JSON file using atcute.
*
* Usage:
* node validate-lexicon.mjs <path-to-lexicon.json>
*
* Install:
* npm install @atcute/lexicon-doc @atcute/lexicons
*/
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { lexiconDoc } from '@atcute/lexicon-doc';
import { ValidationError } from '@atcute/lexicons';
const filePath = process.argv[2];
if (!filePath) {
console.error('Usage: node validate-lexicon.mjs <path-to-lexicon.json>');
process.exit(1);
}
let doc;
try {
doc = JSON.parse(readFileSync(resolve(filePath), 'utf8'));
} catch (err) {
console.error(`Failed to read file: ${err.message}`);
process.exit(1);
}
delete doc.$type
const result = lexiconDoc.try(doc);
if (!result.ok) {
const err = new ValidationError(result._issueTree);
console.error(`Invalid lexicon: ${filePath}`);
for (const issue of err.issues) {
const path = issue.path.length > 0 ? issue.path.join('.') : '(root)';
console.error(` ${path}: ${issue.code}${issue.expected ? ` (expected: ${JSON.stringify(issue.expected)})` : ''}`);
}
process.exit(1);
}
console.log(`Valid lexicon: ${result.value.id}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment