A plain JavaScript validator for AT Protocol lexicon schemas

feat: add defineLexicon helper for typesafe lexicon authoring

Adds a simple identity function that enables autocomplete and type
checking when writing lexicon definitions in TypeScript or JavaScript
with JSDoc.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

+38 -2
+11
CHANGELOG.md
··· 1 + # Changelog 2 + 3 + ## 0.2.0 4 + 5 + ### Added 6 + 7 + - `defineLexicon` helper function for typesafe lexicon authoring with autocomplete support in TypeScript and JavaScript (with JSDoc) 8 + 9 + ## 0.1.2 10 + 11 + - Initial public release
+1
lexicon.d.ts
··· 142 142 path: string; 143 143 message: string; 144 144 }; 145 + export function defineLexicon<T extends Lexicon>(lex: T): T; 145 146 export type LexiconFormat = "datetime" | "uri" | "at-uri" | "did" | "handle" | "at-identifier" | "nsid" | "cid" | "language" | "tid" | "record-key"; 146 147 export type LexiconStringSchema = { 147 148 type: "string";
+24
lexicon.js
··· 1782 1782 // Validate against the record's object schema 1783 1783 return validateObjectData(record, mainDef.record, '', ctx); 1784 1784 } 1785 + 1786 + /** 1787 + * Identity function that provides type checking and autocomplete for lexicon definitions. 1788 + * @template {Lexicon} T 1789 + * @param {T} lex - The lexicon definition 1790 + * @returns {T} The same lexicon, unchanged 1791 + * @example 1792 + * const myLexicon = defineLexicon({ 1793 + * lexicon: 1, 1794 + * id: 'com.example.myRecord', 1795 + * defs: { 1796 + * main: { 1797 + * type: 'record', 1798 + * record: { 1799 + * type: 'object', 1800 + * properties: { 1801 + * name: { type: 'string' }, 1802 + * }, 1803 + * }, 1804 + * }, 1805 + * }, 1806 + * }); 1807 + */ 1808 + export const defineLexicon = (lex) => lex;
+1 -1
lexicon.test.js
··· 1 1 import { describe, test, expect } from 'vitest'; 2 - import { validateLexicons, validateRecord } from './lexicon.js'; 2 + import { defineLexicon, validateLexicons, validateRecord } from './lexicon.js'; 3 3 import { atprotoValidateLexicons, atprotoValidateRecord } from './test/atproto-oracle.js'; 4 4 5 5 // Schema inputs
+1 -1
package.json
··· 1 1 { 2 2 "name": "@bigmoves/lexicon", 3 - "version": "0.1.2", 3 + "version": "0.2.0", 4 4 "license": "MIT", 5 5 "type": "module", 6 6 "exports": "./lexicon.js",