Private/Get-GraphDetailShard.ps1
|
function Get-GraphDetailShard { <# .SYNOPSIS Loads and caches a single detail shard from data/graph-command-details. .DESCRIPTION Detail shards hold the full official metadata (permissions, OutputType, ApiReferenceLink, CommandAlias) split by the first letter of the cmdlet name. GraphShell only loads the shard(s) it actually needs instead of the whole ~25 MB detail set, and caches each shard after first use. #> [CmdletBinding()] [OutputType([pscustomobject])] param( [Parameter(Mandatory)] [string]$Shard, [switch]$Force ) if (-not $script:GraphDetailShardCache) { $script:GraphDetailShardCache = [System.Collections.Generic.Dictionary[string, object]]::new([System.StringComparer]::OrdinalIgnoreCase) } if (-not $Force -and $script:GraphDetailShardCache.ContainsKey($Shard)) { return $script:GraphDetailShardCache[$Shard] } $paths = Get-GraphCatalogPath if (-not $paths.DetailsPath) { Write-Verbose "GraphShell could not locate the graph-command-details folder." return $null } $shardPath = Join-Path $paths.DetailsPath "$Shard.json" if (-not (Test-Path -LiteralPath $shardPath)) { Write-Verbose "GraphShell detail shard not found: $shardPath" return $null } Write-Verbose "Loading GraphShell detail shard '$Shard' from $shardPath" $raw = Get-Content -LiteralPath $shardPath -Raw $parsed = $raw | ConvertFrom-Json $byId = [System.Collections.Generic.Dictionary[string, object]]::new([System.StringComparer]::OrdinalIgnoreCase) foreach ($record in $parsed.records) { $byId[$record.id] = $record } $shardObject = [pscustomobject]@{ Shard = $Shard Records = $parsed.records ById = $byId } $script:GraphDetailShardCache[$Shard] = $shardObject return $shardObject } |