Something went wrong. Try again.
a tool for shared writing and social publishing
Something went wrong. Try again.
TypeScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152import { AtUri } from "@atproto/syntax";import { ids } from "lexicons/api/lexicons";
/** * Returns an OR filter string for Supabase queries to match either namespace URI. * Used for querying documents that may be stored under either pub.leaflet.document * or site.standard.document namespaces. */export function documentUriFilter(did: string, rkey: string): string { const standard = AtUri.make(did, ids.SiteStandardDocument, rkey).toString(); const legacy = AtUri.make(did, ids.PubLeafletDocument, rkey).toString(); return `uri.eq.${standard},uri.eq.${legacy}`;}
/** * Returns an OR filter string for Supabase queries to match either namespace URI. * Used for querying publications that may be stored under either pub.leaflet.publication * or site.standard.publication namespaces. */export function publicationUriFilter(did: string, rkey: string): string { const standard = AtUri.make( did, ids.SiteStandardPublication, rkey, ).toString(); const legacy = AtUri.make(did, ids.PubLeafletPublication, rkey).toString(); return `uri.eq.${standard},uri.eq.${legacy}`;}
/** * Returns an OR filter string for Supabase queries to match a publication by name * or by either namespace URI. Used when the rkey might be the publication name. */export function publicationNameOrUriFilter( did: string, nameOrRkey: string,): string { let standard, legacy; if (/^(?!\.$|\.\.$)[A-Za-z0-9._:~-]{1,512}$/.test(nameOrRkey)) { standard = AtUri.make( did, ids.SiteStandardPublication, nameOrRkey, ).toString(); legacy = AtUri.make(did, ids.PubLeafletPublication, nameOrRkey).toString(); } // The name comes straight from the URL path; escape PostgREST's // quoted-value metacharacters so it can't break the filter grammar. const quotedName = `"${nameOrRkey.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`; return `name.eq.${quotedName},uri.eq."${standard}",uri.eq."${legacy}"`;}