Something went wrong. Try again.
Monorepo for Tangled tangled.org
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334// at-uri helpers: at://<authority>/<collection>/<rkey>
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 versionexport const authorDidOf = (record: { uri: string; value?: unknown }): string => { const editor = (record.value as Record<string, unknown> | 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); }};