An ATProto Lexicon validator for Gleam.
1# Jetstream Validation Example 2 3This example demonstrates using **honk** to validate AT Protocol records from Bluesky's Jetstream firehose in real-time. 4 5## What it does 6 71. Connects to Jetstream using **goose** (WebSocket consumer) 82. Filters for `xyz.statusphere.status` records 93. Validates each record using **honk** 104. Displays validation results with emoji status 11 12## Running the example 13 14```sh 15cd example 16gleam run 17``` 18 19The example will connect to the live Jetstream firehose and display validation results as records are created: 20 21``` 22🦢 Honk + Goose: Jetstream Validation Example 23━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 24 25Connecting to Jetstream... 26Filtering for: xyz.statusphere.status 27Validating records with honk... 28 29✓ VALID | q6gjnaw2blty... | 👍 | 3l4abc123 30✓ VALID | wa7b35aakoll... | 🎉 | 3l4def456 31✗ INVALID | rfov6bpyztcn... | Data: status exceeds maxGraphemes | 3l4ghi789 32✓ UPDATED | eygmaihciaxp... | 😀 | 3l4jkl012 33🗑️ DELETED | ufbl4k27gp6k... | 3l4mno345 34``` 35 36## How it works 37 38### Lexicon Definition 39 40The example defines the `xyz.statusphere.status` lexicon: 41 42```json 43{ 44 "lexicon": 1, 45 "id": "xyz.statusphere.status", 46 "defs": { 47 "main": { 48 "type": "record", 49 "record": { 50 "type": "object", 51 "required": ["status", "createdAt"], 52 "properties": { 53 "status": { 54 "type": "string", 55 "minLength": 1, 56 "maxGraphemes": 1, 57 "maxLength": 32 58 }, 59 "createdAt": { 60 "type": "string", 61 "format": "datetime" 62 } 63 } 64 } 65 } 66 } 67} 68``` 69 70### Validation Flow 71 721. **goose** receives Jetstream events via WebSocket 732. Events are parsed into typed Gleam structures 743. For `create` and `update` operations: 75 - Extract the `record` field (contains the status data) 76 - Pass to `honk.validate_record()` with the lexicon 77 - Display ✓ for valid or ✗ for invalid records 784. For `delete` operations: 79 - Just log the deletion (no record to validate) 80 81### Dependencies 82 83- **honk**: AT Protocol lexicon validator (local path) 84- **goose**: Jetstream WebSocket consumer library 85- **gleam_json**: JSON encoding/decoding 86- **gleam_stdlib**: Standard library 87 88## Code Structure 89 90``` 91example/ 92├── gleam.toml # Dependencies configuration 93├── README.md # This file 94└── src/ 95 └── example.gleam # Main application 96 ├── main() # Entry point 97 ├── handle_event() # Process Jetstream events 98 ├── handle_create/update() # Validate records 99 ├── create_statusphere_lexicon()# Define lexicon 100 └── format_error/extract_status # Display helpers 101``` 102 103## Learn More 104 105- **honk**: https://hexdocs.pm/honk 106- **goose**: https://hexdocs.pm/goose 107- **Jetstream**: https://docs.bsky.app/docs/advanced-guides/jetstream 108- **AT Protocol**: https://atproto.com/