slices-lexicon 0.1.2

AT Protocol lexicon validation library for Slices
Documentation

slices-lexicon

AT Protocol lexicon validation library for Rust, compiled to WebAssembly.

Features

  • 🚀 Fast lexicon validation written in Rust
  • 🌐 WebAssembly support for browser and Node.js environments
  • 📦 Zero JavaScript dependencies
  • 🔒 Type-safe validation with comprehensive error messages
  • ✅ Full AT Protocol lexicon specification support

Installation

[dependencies]
slices-lexicon = "0.1"

Usage

In Rust

use slices_lexicon::{LexiconValidator, ValidationError};
use serde_json::json;

let lexicons = vec![
    json!({
        "id": "com.example.post",
        "defs": {
            "main": {
                "type": "record",
                "record": {
                    "type": "object",
                    "properties": {
                        "text": { "type": "string" }
                    }
                }
            }
        }
    })
];

let validator = LexiconValidator::new(lexicons)?;
let record = json!({ "text": "Hello, world!" });

validator.validate_record("com.example.post", &record)?;

As WebAssembly

Build with wasm-pack:

wasm-pack build --target web

Then use in JavaScript/TypeScript:

import init, { WasmLexiconValidator } from './pkg/slices_lexicon.js';

await init();

const validator = new WasmLexiconValidator(JSON.stringify(lexicons));
validator.validate_record("com.example.post", JSON.stringify(record));

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 datetime
  • uri - Generic URI
  • at-uri - AT Protocol URI
  • did - Decentralized Identifier
  • handle - AT Protocol handle
  • at-identifier - DID or handle
  • nsid - Name Spaced Identifier
  • cid - Content Identifier
  • language - BCP47 language tag
  • tid - Timestamp-based Identifier
  • record-key - Record key format

License

MIT