( documentIds: string[] )
| 17 | * indicate the document is no longer visible and should be skipped. |
| 18 | */ |
| 19 | export async function getDocumentMetadataByIds( |
| 20 | documentIds: string[] |
| 21 | ): Promise<Record<string, DocumentMetadata>> { |
| 22 | if (documentIds.length === 0) { |
| 23 | return {} |
| 24 | } |
| 25 | |
| 26 | const uniqueIds = [...new Set(documentIds)] |
| 27 | const documents = await db |
| 28 | .select({ |
| 29 | id: document.id, |
| 30 | filename: document.filename, |
| 31 | sourceUrl: document.sourceUrl, |
| 32 | }) |
| 33 | .from(document) |
| 34 | .where( |
| 35 | and( |
| 36 | inArray(document.id, uniqueIds), |
| 37 | eq(document.userExcluded, false), |
| 38 | isNull(document.archivedAt), |
| 39 | isNull(document.deletedAt) |
| 40 | ) |
| 41 | ) |
| 42 | |
| 43 | const map: Record<string, DocumentMetadata> = {} |
| 44 | documents.forEach((doc) => { |
| 45 | map[doc.id] = { filename: doc.filename, sourceUrl: doc.sourceUrl ?? null } |
| 46 | }) |
| 47 | |
| 48 | return map |
| 49 | } |
| 50 | |
| 51 | export interface SearchResult { |
| 52 | id: string |
no test coverage detected