import type { Logger } from "@atbb/logger"; /** * Parsed components of an AT Protocol URI. * Format: at://did:plc:xxx/collection.name/rkey */ export interface ParsedAtUri { did: string; collection: string; rkey: string; } /** * Parse an AT Protocol URI into its component parts. * * @param uri - AT-URI like "at://did:plc:abc/space.atbb.post/3lbk7xxx" * @param logger - Optional structured logger for warnings/errors * @returns Parsed components, or null if the URI is invalid */ export function parseAtUri(uri: string, logger?: Logger): ParsedAtUri | null { try { const match = uri.match(/^at:\/\/([^/]+)\/([^/]+)\/(.+)$/); if (!match) { logger?.warn("Invalid AT URI format", { uri }); return null; } const [, did, collection, rkey] = match; return { did, collection, rkey }; } catch (error) { logger?.error("Unexpected error parsing AT URI", { uri, error: error instanceof Error ? error.message : String(error), }); return null; } }