* Whether an active KB document (non-archived/excluded/deleted, in a * non-deleted KB) in the owning workspace references exactly `cloudKey`, matched * on the document's persisted canonical `storageKey`. This is an exact, indexed * lookup — no URL parsing or wildcard matching at read time. It is
(cloudKey: string, workspaceId: string)
| 475 | * owns it (ownership comes from the binding). |
| 476 | */ |
| 477 | async function hasActiveKbDocumentForKey(cloudKey: string, workspaceId: string): Promise<boolean> { |
| 478 | const rows = await db |
| 479 | .select({ id: document.id }) |
| 480 | .from(document) |
| 481 | .innerJoin(knowledgeBase, eq(document.knowledgeBaseId, knowledgeBase.id)) |
| 482 | .where( |
| 483 | and( |
| 484 | eq(knowledgeBase.workspaceId, workspaceId), |
| 485 | eq(document.storageKey, cloudKey), |
| 486 | eq(document.userExcluded, false), |
| 487 | isNull(document.archivedAt), |
| 488 | isNull(document.deletedAt), |
| 489 | isNull(knowledgeBase.deletedAt) |
| 490 | ) |
| 491 | ) |
| 492 | .limit(1) |
| 493 | |
| 494 | return rows.length > 0 |
| 495 | } |
| 496 | |
| 497 | /** |
| 498 | * Verify access to KB files (`kb/<key>`). |
no test coverage detected