a tool for shared writing and social publishing
1import { AtUri } from "@atproto/syntax"; 2import { ids } from "lexicons/api/lexicons"; 3 4/** 5 * Returns an OR filter string for Supabase queries to match either namespace URI. 6 * Used for querying documents that may be stored under either pub.leaflet.document 7 * or site.standard.document namespaces. 8 */ 9export function documentUriFilter(did: string, rkey: string): string { 10 const standard = AtUri.make(did, ids.SiteStandardDocument, rkey).toString(); 11 const legacy = AtUri.make(did, ids.PubLeafletDocument, rkey).toString(); 12 return `uri.eq.${standard},uri.eq.${legacy}`; 13} 14 15/** 16 * Returns an OR filter string for Supabase queries to match either namespace URI. 17 * Used for querying publications that may be stored under either pub.leaflet.publication 18 * or site.standard.publication namespaces. 19 */ 20export function publicationUriFilter(did: string, rkey: string): string { 21 const standard = AtUri.make( 22 did, 23 ids.SiteStandardPublication, 24 rkey, 25 ).toString(); 26 const legacy = AtUri.make(did, ids.PubLeafletPublication, rkey).toString(); 27 return `uri.eq.${standard},uri.eq.${legacy}`; 28} 29 30/** 31 * Returns an OR filter string for Supabase queries to match a publication by name 32 * or by either namespace URI. Used when the rkey might be the publication name. 33 */ 34export function publicationNameOrUriFilter( 35 did: string, 36 nameOrRkey: string, 37): string { 38 let standard, legacy; 39 if (/^(?!\.$|\.\.S)[A-Za-z0-9._:~-]{1,512}$/.test(nameOrRkey)) { 40 standard = AtUri.make( 41 did, 42 ids.SiteStandardPublication, 43 nameOrRkey, 44 ).toString(); 45 legacy = AtUri.make(did, ids.PubLeafletPublication, nameOrRkey).toString(); 46 } 47 return `name.eq."${nameOrRkey}"",uri.eq."${standard}",uri.eq."${legacy}"`; 48}