+18
-6
crates/atproto-lexicon/README.md
+18
-6
crates/atproto-lexicon/README.md
···
41
41
#[tokio::main]
42
42
async fn main() -> anyhow::Result<()> {
43
43
let http_client = reqwest::Client::new();
44
-
let dns_resolver = HickoryDnsResolver::create_resolver(vec![]);
44
+
let dns_resolver = HickoryDnsResolver::create_resolver(&[]);
45
45
46
46
let resolver = DefaultLexiconResolver::new(http_client, dns_resolver);
47
47
···
60
60
61
61
#[tokio::main]
62
62
async fn main() -> anyhow::Result<()> {
63
-
// ... setup resolver as above ...
63
+
let http_client = reqwest::Client::new();
64
+
let dns_resolver = HickoryDnsResolver::create_resolver(&[]);
65
+
let resolver = DefaultLexiconResolver::new(http_client, dns_resolver);
64
66
65
67
let config = RecursiveResolverConfig {
66
68
max_depth: 5, // Maximum recursion depth
···
96
98
let parts = parse_nsid("app.bsky.feed.post#reply", None)?;
97
99
assert_eq!(parts.parts, vec!["app", "bsky", "feed", "post"]);
98
100
assert_eq!(parts.fragment, Some("reply".to_string()));
101
+
102
+
// Convert parsed NSID back to string using Display trait
103
+
println!("Parsed NSID: {}", parts); // Outputs: app.bsky.feed.post#reply
99
104
100
105
// Convert NSID to DNS name for resolution
101
106
let dns_name = nsid_to_dns_name("app.bsky.feed.post")?;
···
169
174
170
175
## Module Structure
171
176
177
+
- **`errors`**: Structured error types for all lexicon operations
172
178
- **`resolve`**: Core lexicon resolution implementation following AT Protocol specification
173
179
- **`resolve_recursive`**: Recursive resolution with dependency tracking and cycle detection
174
180
- **`validation`**: NSID validation, parsing, and helper functions
···
179
185
Represents a parsed NSID with its component parts and optional fragment:
180
186
- `parts`: Vector of NSID components (e.g., `["app", "bsky", "feed", "post"]`)
181
187
- `fragment`: Optional fragment identifier (e.g., `"reply"` for `#reply`)
188
+
189
+
Implements `Display` trait for converting back to string format.
182
190
183
191
### `RecursiveResolverConfig`
184
192
Configuration for recursive resolution:
···
201
209
202
210
## Error Handling
203
211
204
-
The library uses structured error types for different failure modes:
205
-
- `ValidationError`: NSID format validation errors
206
-
- `ResolveError`: DNS resolution and DID resolution errors
207
-
- Network and XRPC errors are wrapped in `anyhow::Error`
212
+
The library uses structured error types following the project convention `error-atproto-lexicon-<domain>-<number>`:
213
+
214
+
- **`LexiconResolveError`**: Resolution errors (no DIDs found, invalid DID format, PDS errors)
215
+
- **`LexiconValidationError`**: NSID format and validation errors
216
+
- **`LexiconSchemaError`**: Schema structure and parsing errors
217
+
- **`LexiconRecursiveError`**: Errors specific to recursive resolution
218
+
219
+
All errors implement the `Error` trait and provide detailed context about failures.
208
220
209
221
## Dependencies
210
222
+38
crates/atproto-lexicon/src/lib.rs
+38
crates/atproto-lexicon/src/lib.rs
···
2
2
//!
3
3
//! This library provides functionality for resolving and validating AT Protocol lexicons,
4
4
//! which define the schema and structure of AT Protocol data.
5
+
//!
6
+
//! ## Overview
7
+
//!
8
+
//! Lexicons in AT Protocol serve as schema definitions that describe the structure
9
+
//! and types of data that can be stored and transmitted. This library implements
10
+
//! the full lexicon resolution chain as specified by the AT Protocol:
11
+
//!
12
+
//! 1. Convert NSID to DNS name with `_lexicon` prefix
13
+
//! 2. Perform DNS TXT lookup to get the authoritative DID
14
+
//! 3. Resolve the DID to get the DID document
15
+
//! 4. Extract PDS endpoint from the DID document
16
+
//! 5. Make XRPC call to fetch the lexicon schema
17
+
//!
18
+
//! ## Modules
19
+
//!
20
+
//! - [`errors`]: Structured error types for all lexicon operations
21
+
//! - [`resolve`]: Core lexicon resolution implementation
22
+
//! - [`resolve_recursive`]: Recursive resolution with dependency tracking
23
+
//! - [`validation`]: NSID validation, parsing, and helper functions
24
+
//!
25
+
//! ## Example Usage
26
+
//!
27
+
//! ```no_run
28
+
//! # use anyhow::Result;
29
+
//! # #[tokio::main]
30
+
//! # async fn main() -> Result<()> {
31
+
//! use atproto_lexicon::resolve::{DefaultLexiconResolver, LexiconResolver};
32
+
//! use atproto_identity::resolve::HickoryDnsResolver;
33
+
//!
34
+
//! let http_client = reqwest::Client::new();
35
+
//! let dns_resolver = HickoryDnsResolver::create_resolver(&[]);
36
+
//! let resolver = DefaultLexiconResolver::new(http_client, dns_resolver);
37
+
//!
38
+
//! // Resolve a lexicon
39
+
//! let lexicon = resolver.resolve("app.bsky.feed.post").await?;
40
+
//! # Ok(())
41
+
//! # }
42
+
//! ```
5
43
6
44
#![forbid(unsafe_code)]
7
45
#![warn(missing_docs)]