Private/Get-GraphAliasIndex.ps1
|
function Get-GraphAliasIndex { <# .SYNOPSIS Loads and caches the small alias -> canonical command name(s) map. .DESCRIPTION Reads data/graph-command-aliases.json once per session. An alias is not guaranteed to share its canonical command's resource-based shard key, so this tiny, always-loaded map is what lets Get-GraphMapping -Cmdlet resolve an alias to the shard it must load, without loading the full catalog. #> [CmdletBinding()] [OutputType([pscustomobject])] param( [switch]$Force ) if (-not $Force -and $script:GraphAliasCache) { return $script:GraphAliasCache } $paths = Get-GraphCatalogPath $byAlias = [System.Collections.Generic.Dictionary[string, string[]]]::new([System.StringComparer]::OrdinalIgnoreCase) if ($paths.AliasesPath) { Write-Verbose "Loading GraphShell alias index from $($paths.AliasesPath)" $raw = Get-Content -LiteralPath $paths.AliasesPath -Raw $parsed = $raw | ConvertFrom-Json foreach ($property in $parsed.aliases.PSObject.Properties) { $byAlias[$property.Name] = [string[]]$property.Value } } else { Write-Verbose 'GraphShell alias index (graph-command-aliases.json) not found; alias resolution will be skipped.' } $script:GraphAliasCache = [pscustomobject]@{ ByAlias = $byAlias } return $script:GraphAliasCache } |