( workspaces: FrontendWorkspaceMetadata[], extensionMeta: Map<string, ExtensionMetadata> )
| 33 | } |
| 34 | |
| 35 | function enrichAndSort( |
| 36 | workspaces: FrontendWorkspaceMetadata[], |
| 37 | extensionMeta: Map<string, ExtensionMetadata> |
| 38 | ): WorkspaceWithContext[] { |
| 39 | const enriched: WorkspaceWithContext[] = workspaces.map((ws) => { |
| 40 | return { |
| 41 | ...ws, |
| 42 | extensionMetadata: extensionMeta.get(ws.id), |
| 43 | }; |
| 44 | }); |
| 45 | |
| 46 | // Sort by recency (extension metadata > createdAt > name) |
| 47 | const recencyOf = (w: WorkspaceWithContext): number => |
| 48 | w.extensionMetadata?.recency ?? (w.createdAt ? Date.parse(w.createdAt) : 0); |
| 49 | |
| 50 | enriched.sort((a, b) => { |
| 51 | const aRecency = recencyOf(a); |
| 52 | const bRecency = recencyOf(b); |
| 53 | if (aRecency !== bRecency) return bRecency - aRecency; |
| 54 | return a.name.localeCompare(b.name); |
| 55 | }); |
| 56 | |
| 57 | return enriched; |
| 58 | } |
| 59 | |
| 60 | export async function getAllWorkspacesFromFiles(options?: { |
| 61 | timeoutMs?: number; |
no test coverage detected