slices-lexicon
Rust implementation of AT Protocol lexicon validation.
Overview
This validation engine can be used in any project that needs AT Protocol lexicon validation. It provides high-performance, spec-compliant validation of AT Protocol lexicon documents and data records. It can also be compiled to WebAssembly for use in JavaScript/TypeScript environments.
Architecture
This package serves as the core validation engine and is typically consumed by higher-level packages:
@slices/lexicon- TypeScript/Deno package with ergonomic APIs@slices/cli- Deno command-line tool for lexicon/appview managementlexicon-intellisense- VS Code extension for lexicon development
Features
- High-performance lexicon validation implemented in Rust
- Comprehensive error reporting with detailed context
- Full AT Protocol lexicon specification compliance
- Support for all lexicon types: records, queries, procedures, subscriptions
- Optional WebAssembly compilation for JavaScript/TypeScript environments
- Zero JavaScript runtime dependencies when using WebAssembly
Direct Usage
Rust Library
Add to your Cargo.toml:
[]
= "0.2"
Basic validation:
use ;
use json;
// Define lexicon documents
let lexicons = vec!;
// Validate lexicon documents
match validate
// Validate a data record against the schema
let record = json!;
validate_record?;
// Validate NSID format
let is_valid = is_valid_nsid;
println!;
WebAssembly
Build the WASM module:
Use in JavaScript environments:
import init from "./pkg/slices_lexicon.js";
await ;
// Validate lexicons
const lexicons = ;
const validator = ;
const errorsJson = validator.;
const errors = JSON.;
if else
validator.; // Clean up WASM resources
JavaScript/TypeScript Usage
If you're using JavaScript or TypeScript, use the higher-level packages instead of consuming this library directly:
- TypeScript/JavaScript: Use
@slices/lexiconfor ergonomic APIs with automatic resource management - VS Code Development: Install the
lexicon-intellisenseextension - CLI Tools: Use the Slices CLI for lexicon management tasks
Supported Types
- Objects with required/optional fields
- Arrays with min/max length constraints
- Strings with format validation (datetime, URI, DID, handle, etc.)
- Integers with range constraints
- Booleans with const values
- Bytes (base64 encoded)
- Unions (open and closed)
- References (local and cross-lexicon)
- CID links
- Tokens (unit types for type discrimination)
- Unknown types
String Formats
datetime- RFC3339/ISO8601 datetimeuri- Generic URIat-uri- AT Protocol URIdid- Decentralized Identifierhandle- AT Protocol handleat-identifier- DID or handlensid- Name Spaced Identifiercid- Content Identifierlanguage- BCP47 language tagtid- Timestamp-based Identifierrecord-key- Record key format
License
MIT