()
| 231 | * Sorted most recently opened first. |
| 232 | */ |
| 233 | export async function readKnownVaultsFromConfig(): Promise<KnownVault[]> { |
| 234 | const parsed = await readConfigFile() |
| 235 | const seen = new Set<string>() |
| 236 | const out: KnownVault[] = [] |
| 237 | |
| 238 | const rawList = Array.isArray(parsed?.localVaults) ? parsed.localVaults : [] |
| 239 | for (const entry of rawList) { |
| 240 | if (!entry || typeof entry !== 'object') continue |
| 241 | const { root, name, lastOpenedAt } = entry as Record<string, unknown> |
| 242 | if (typeof root !== 'string' || !root.trim()) continue |
| 243 | const resolved = path.resolve(root) |
| 244 | if (seen.has(resolved)) continue |
| 245 | seen.add(resolved) |
| 246 | out.push({ |
| 247 | root: resolved, |
| 248 | name: typeof name === 'string' && name.trim() ? name : path.basename(resolved), |
| 249 | lastOpenedAt: typeof lastOpenedAt === 'number' ? lastOpenedAt : null |
| 250 | }) |
| 251 | } |
| 252 | |
| 253 | const active = typeof parsed?.vaultRoot === 'string' ? parsed.vaultRoot.trim() : '' |
| 254 | if (active && !seen.has(path.resolve(active))) { |
| 255 | const resolved = path.resolve(active) |
| 256 | out.push({ root: resolved, name: path.basename(resolved), lastOpenedAt: null }) |
| 257 | } |
| 258 | |
| 259 | out.sort((a, b) => (b.lastOpenedAt ?? 0) - (a.lastOpenedAt ?? 0)) |
| 260 | return out |
| 261 | } |
| 262 | |
| 263 | function expandHome(target: string): string { |
| 264 | if (target === '~') return os.homedir() |
no test coverage detected