Highly ambitious ATProtocol AppView service and sdks
at main 34 lines 1.2 kB view raw
1// Check if a value is a strong ref 2// Strong refs have both 'uri' and 'cid' fields 3const isStrongRef = (value: unknown): boolean => { 4 if (typeof value !== "object" || value === null) return false; 5 const obj = value as Record<string, unknown>; 6 return typeof obj.uri === "string" && 7 typeof obj.cid === "string" && 8 obj.uri.startsWith("at://"); 9}; 10 11// Extract URI from a strong ref 12export const getStrongRefUri = (value: unknown): string | null => { 13 if (!isStrongRef(value)) return null; 14 const obj = value as Record<string, unknown>; 15 return obj.uri as string; 16}; 17 18// Check if a string value is an AT-URI 19export const isAtUri = (value: unknown): boolean => { 20 return typeof value === "string" && value.startsWith("at://"); 21}; 22 23// Parse AT-URI to extract collection 24// Format: at://did/collection/rkey 25export const parseAtUri = (uri: string): { did: string; collection: string; rkey: string } | null => { 26 if (!uri.startsWith("at://")) return null; 27 const parts = uri.slice(5).split("/"); // Remove "at://" and split 28 if (parts.length !== 3) return null; 29 return { 30 did: parts[0], 31 collection: parts[1], 32 rkey: parts[2], 33 }; 34};