// at-uri helpers: at://// import { parseResourceUri } from "@atcute/lexicons/syntax"; import { recordKeyOf, type Rkey } from "$lib/api/syntax"; const legacyAuthority = (uri: string): string => { const rest = uri.startsWith("at://") ? uri.slice(5) : uri; const slash = rest.indexOf("/"); return slash === -1 ? rest : rest.slice(0, slash); }; export const didFromUri = (uri: string): string => { try { return parseResourceUri(uri).repo; } catch { return legacyAuthority(uri); } }; // on a knot the uri names the repo, and x-tngl-editor is whoever wrote the latest version export const authorDidOf = (record: { uri: string; value?: unknown }): string => { const editor = (record.value as Record | undefined)?.["x-tngl-editor"]; return typeof editor === "string" ? editor : didFromUri(record.uri); }; export const rkeyFromUri = (uri: string): Rkey => { const fallback = uri.slice(uri.lastIndexOf("/") + 1); try { return recordKeyOf(parseResourceUri(uri).rkey ?? fallback); } catch { return recordKeyOf(fallback); } };