// Check if a value is a strong ref // Strong refs have both 'uri' and 'cid' fields const isStrongRef = (value: unknown): boolean => { if (typeof value !== "object" || value === null) return false; const obj = value as Record; return typeof obj.uri === "string" && typeof obj.cid === "string" && obj.uri.startsWith("at://"); }; // Extract URI from a strong ref export const getStrongRefUri = (value: unknown): string | null => { if (!isStrongRef(value)) return null; const obj = value as Record; return obj.uri as string; }; // Check if a string value is an AT-URI export const isAtUri = (value: unknown): boolean => { return typeof value === "string" && value.startsWith("at://"); }; // Parse AT-URI to extract collection // Format: at://did/collection/rkey export const parseAtUri = (uri: string): { did: string; collection: string; rkey: string } | null => { if (!uri.startsWith("at://")) return null; const parts = uri.slice(5).split("/"); // Remove "at://" and split if (parts.length !== 3) return null; return { did: parts[0], collection: parts[1], rkey: parts[2], }; };