( workspaceId: string, userId: string )
| 322 | // the typed VFS snapshot are built from this single fetch. Returns null when the |
| 323 | // workspace is unavailable or a fetch fails. |
| 324 | async function buildWorkspaceMdData( |
| 325 | workspaceId: string, |
| 326 | userId: string |
| 327 | ): Promise<WorkspaceMdData | null> { |
| 328 | try { |
| 329 | await assertActiveWorkspaceAccess(workspaceId, userId) |
| 330 | const wsRow = await getWorkspaceWithOwner(workspaceId) |
| 331 | if (!wsRow) { |
| 332 | return null |
| 333 | } |
| 334 | |
| 335 | const [ |
| 336 | members, |
| 337 | workflows, |
| 338 | folderRows, |
| 339 | kbs, |
| 340 | tables, |
| 341 | files, |
| 342 | credentials, |
| 343 | customTools, |
| 344 | mcpServerRows, |
| 345 | skillRows, |
| 346 | jobRows, |
| 347 | ] = await Promise.all([ |
| 348 | getUsersWithPermissions(workspaceId), |
| 349 | |
| 350 | db |
| 351 | .select({ |
| 352 | id: workflow.id, |
| 353 | name: workflow.name, |
| 354 | description: workflow.description, |
| 355 | isDeployed: workflow.isDeployed, |
| 356 | lastRunAt: workflow.lastRunAt, |
| 357 | folderId: workflow.folderId, |
| 358 | }) |
| 359 | .from(workflow) |
| 360 | .where(and(eq(workflow.workspaceId, workspaceId), isNull(workflow.archivedAt))), |
| 361 | |
| 362 | db |
| 363 | .select({ |
| 364 | id: workflowFolder.id, |
| 365 | name: workflowFolder.name, |
| 366 | parentId: workflowFolder.parentId, |
| 367 | }) |
| 368 | .from(workflowFolder) |
| 369 | .where(and(eq(workflowFolder.workspaceId, workspaceId), isNull(workflowFolder.archivedAt))), |
| 370 | |
| 371 | db |
| 372 | .select({ |
| 373 | id: knowledgeBase.id, |
| 374 | name: knowledgeBase.name, |
| 375 | description: knowledgeBase.description, |
| 376 | }) |
| 377 | .from(knowledgeBase) |
| 378 | .where(and(eq(knowledgeBase.workspaceId, workspaceId), isNull(knowledgeBase.deletedAt))), |
| 379 | |
| 380 | db |
| 381 | .select({ |
no test coverage detected