honk

Package Version Hex Docs

An AT Protocol Lexicon validator for Gleam.

While Iโ€™ve tried to be as thorough as possible checking the validators against various atproto validation libraries, this may contain bugs. Please report any issues you find.

Installation

gleam add honk@1

Quick Start

Validate a Lexicon Schema

import honk
import gleam/json

pub fn main() {
  let lexicon = json.object([
    #("lexicon", json.int(1)),
    #("id", json.string("xyz.statusphere.status")),
    #("defs", json.object([
      #("main", json.object([
        #("type", json.string("record")),
        #("key", json.string("tid")),
        #("record", json.object([
          #("type", json.string("object")),
          #("required", json.preprocessed_array([
            json.string("status"),
            json.string("createdAt"),
          ])),
          #("properties", json.object([
            #("status", json.object([
              #("type", json.string("string")),
              #("minLength", json.int(1)),
              #("maxGraphemes", json.int(1)),
              #("maxLength", json.int(32)),
            ])),
            #("createdAt", json.object([
              #("type", json.string("string")),
              #("format", json.string("datetime")),
            ])),
          ])),
        ])),
      ])),
    ])),
  ])

  case honk.validate([lexicon]) {
    Ok(_) -> io.println("โœ“ Lexicon is valid")
    Error(err) -> io.println("โœ— Validation failed: " <> err.message)
  }
}

Validate Record Data

import honk
import gleam/json

pub fn validate_status() {
  let lexicons = [my_lexicon] // Your lexicon definitions
  let record_data = json.object([
    #("status", json.string("๐Ÿ‘")),
    #("createdAt", json.string("2025-01-15T12:00:00Z")),
  ])

  case honk.validate_record(lexicons, "xyz.statusphere.status", record_data) {
    Ok(_) -> io.println("โœ“ Record is valid")
    Error(err) -> io.println("โœ— Invalid: " <> err.message)
  }
}

Features

CLI Usage

Validate lexicon files from the command line:

# Validate a single file
gleam run -m honk check ./lexicons/xyz/statusphere/status.json

# Validate all .json files in a directory
gleam run -m honk check ./lexicons/

# Show help
gleam run -m honk help

When validating a directory, all lexicons are loaded together to resolve cross-lexicon references

Testing

gleam test

Documentation

Further documentation can be found at https://hexdocs.pm/honk.

Development

gleam run   # Run the project
gleam test  # Run the tests
gleam build # Build the project

License

Apache 2.0

โœจ Search Document