Private/Get-GraphCmdletShard.ps1

function Get-GraphCmdletShard {
    <#
    .SYNOPSIS
        Loads and caches a single by-cmdlet lite shard.
    .DESCRIPTION
        data/graph-command-by-cmdlet/{ShardKey}.json groups records by a resource-based shard
        key (see Get-GraphResourceShardKey), so Get-GraphMapping -Cmdlet only needs to load the
        one shard that could contain the requested cmdlet instead of the whole ~11 MB catalog.
    #>

    [CmdletBinding()]
    [OutputType([pscustomobject])]
    param(
        [Parameter(Mandatory)]
        [string]$Shard,

        [switch]$Force
    )

    if (-not $script:GraphCmdletShardCache) {
        $script:GraphCmdletShardCache = [System.Collections.Generic.Dictionary[string, object]]::new([System.StringComparer]::OrdinalIgnoreCase)
    }

    if (-not $Force -and $script:GraphCmdletShardCache.ContainsKey($Shard)) {
        return $script:GraphCmdletShardCache[$Shard]
    }

    $paths = Get-GraphCatalogPath
    if (-not $paths.ByCmdletPath) {
        Write-Verbose 'GraphShell could not locate the graph-command-by-cmdlet folder.'
        return $null
    }
    $shardPath = Join-Path $paths.ByCmdletPath "$Shard.json"
    if (-not (Test-Path -LiteralPath $shardPath)) {
        Write-Verbose "GraphShell cmdlet shard not found: $shardPath"
        return $null
    }

    Write-Verbose "Loading GraphShell cmdlet shard '$Shard' from $shardPath"
    $raw = Get-Content -LiteralPath $shardPath -Raw
    $parsed = $raw | ConvertFrom-Json

    $byCommand = [System.Collections.Generic.Dictionary[string, System.Collections.Generic.List[object]]]::new([System.StringComparer]::OrdinalIgnoreCase)
    foreach ($property in $parsed.commands.PSObject.Properties) {
        $byCommand[$property.Name] = [System.Collections.Generic.List[object]]$property.Value
    }

    $shardObject = [pscustomobject]@{ Shard = $Shard; ByCommand = $byCommand }
    $script:GraphCmdletShardCache[$Shard] = $shardObject
    return $shardObject
}