[READ ONLY MIRROR] Spark Social AppView Server github.com/sprksocial/server
atproto deno hono lexicon
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

at 17a4453b336a3693a4e2b55eced2d8a4a0cf1bd5 55 lines 1.6 kB view raw
1import { FilterQuery } from "mongoose"; 2 3// MongoDB query builder for actor matching (DID or handle) 4export const actorFilter = <T>(actor: string): FilterQuery<T> => { 5 if (actor.startsWith("did:")) { 6 return { did: actor } as FilterQuery<T>; 7 } else { 8 return { handle: actor } as FilterQuery<T>; 9 } 10}; 11 12// Filter for documents that are not soft deleted 13export const notSoftDeletedFilter = <T>(): FilterQuery<T> => { 14 return { takedownRef: { $exists: false } } as FilterQuery<T>; 15}; 16 17// Check if a document is soft deleted 18export const softDeleted = ( 19 actorOrRecord: { takedownRef?: string | null }, 20): boolean => { 21 return !!actorOrRecord.takedownRef; 22}; 23 24// Helper for date range queries 25export const dateRangeFilter = <T>( 26 field: string, 27 start?: Date, 28 end?: Date, 29): FilterQuery<T> => { 30 const filter: Record<string, unknown> = {}; 31 if (start || end) { 32 filter[field] = {}; 33 if (start) (filter[field] as Record<string, unknown>).$gte = start; 34 if (end) (filter[field] as Record<string, unknown>).$lte = end; 35 } 36 return filter as FilterQuery<T>; 37}; 38 39// Helper for pagination 40export interface PaginationOptions { 41 limit?: number; 42 skip?: number; 43 sort?: Record<string, 1 | -1>; 44} 45 46// Helper for creating compound filters 47export const andFilter = <T>( 48 ...filters: FilterQuery<T>[] 49): FilterQuery<T> => ({ 50 $and: filters.filter((f) => Object.keys(f).length > 0), 51} as FilterQuery<T>); 52 53export const orFilter = <T>(...filters: FilterQuery<T>[]): FilterQuery<T> => ({ 54 $or: filters.filter((f) => Object.keys(f).length > 0), 55} as FilterQuery<T>);