WIP! A BB-style forum, on the ATmosphere! We're still working... we'll be back soon when we have something to show off!
node typescript hono htmx atproto
at main 37 lines 1.0 kB view raw
1import type { Logger } from "@atbb/logger"; 2 3/** 4 * Parsed components of an AT Protocol URI. 5 * Format: at://did:plc:xxx/collection.name/rkey 6 */ 7export interface ParsedAtUri { 8 did: string; 9 collection: string; 10 rkey: string; 11} 12 13/** 14 * Parse an AT Protocol URI into its component parts. 15 * 16 * @param uri - AT-URI like "at://did:plc:abc/space.atbb.post/3lbk7xxx" 17 * @param logger - Optional structured logger for warnings/errors 18 * @returns Parsed components, or null if the URI is invalid 19 */ 20export function parseAtUri(uri: string, logger?: Logger): ParsedAtUri | null { 21 try { 22 const match = uri.match(/^at:\/\/([^/]+)\/([^/]+)\/(.+)$/); 23 if (!match) { 24 logger?.warn("Invalid AT URI format", { uri }); 25 return null; 26 } 27 28 const [, did, collection, rkey] = match; 29 return { did, collection, rkey }; 30 } catch (error) { 31 logger?.error("Unexpected error parsing AT URI", { 32 uri, 33 error: error instanceof Error ? error.message : String(error), 34 }); 35 return null; 36 } 37}