Pax8API/Private/Compare-Pax8SpecManifest.ps1

function Compare-Pax8SpecManifest {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory)]
        [object]$LocalManifest,

        [Parameter(Mandatory)]
        [object]$RemoteManifest
    )

    $localByFile = @{}
    foreach ($spec in @($LocalManifest.specs)) {
        $localByFile[[string]$spec.file] = $spec
    }

    $differences = foreach ($remoteSpec in @($RemoteManifest.specs)) {
        $file = [string]$remoteSpec.file
        $localSpec = $localByFile[$file]
        if (-not $localSpec) {
            [pscustomobject]@{
                File = $file
                Status = 'NewRemoteSpec'
                LocalSha256 = $null
                RemoteSha256 = $remoteSpec.sha256
                LocalOperationCount = $null
                RemoteOperationCount = $remoteSpec.operationCount
            }
            continue
        }

        if ($localSpec.sha256 -ne $remoteSpec.sha256 -or [int]$localSpec.operationCount -ne [int]$remoteSpec.operationCount) {
            [pscustomobject]@{
                File = $file
                Status = 'Changed'
                LocalSha256 = $localSpec.sha256
                RemoteSha256 = $remoteSpec.sha256
                LocalOperationCount = [int]$localSpec.operationCount
                RemoteOperationCount = [int]$remoteSpec.operationCount
            }
        }
    }

    $remoteFiles = @($RemoteManifest.specs | ForEach-Object file)
    foreach ($localSpec in @($LocalManifest.specs)) {
        if ($localSpec.file -notin $remoteFiles) {
            [pscustomobject]@{
                File = $localSpec.file
                Status = 'MissingRemoteSpec'
                LocalSha256 = $localSpec.sha256
                RemoteSha256 = $null
                LocalOperationCount = [int]$localSpec.operationCount
                RemoteOperationCount = $null
            }
        }
    }
}