private/ConvertTo-SfMetadataComponent.ps1

function ConvertTo-SfMetadataComponent {

    <#
        .SYNOPSIS
        Parses a single 'Type:Name' (or bare 'Name') string into a structured MetadataComponent entry.

        .DESCRIPTION
        Splits a component string in 'Type:Name' notation into a PSCustomObject with
        Type, Name, and Key properties. If ComponentName has no colon, DefaultComponentType
        is used as Type and ComponentName as Name - i.e. treated as if DefaultComponentType
        had been prepended with a colon. If ComponentName has no colon and DefaultComponentType
        is not supplied, this is a format error (see below).

        On any format error - more than one colon, or an empty Type or Name after
        splitting - $null is returned instead of a terminating error.

        .OUTPUTS
        [PSCustomObject] with properties Type, Name, Key. $null on format error.
    #>


    [CmdletBinding()]
    param (
        # The raw component string to parse, e.g. 'CustomObject:Account' or bare 'Account'.
        [Parameter(Mandatory, Position = 0)]
        [ValidateNotNullOrEmpty()]
        [string] $ComponentName,

        # Type assumed when $ComponentName has no colon. Must be called by name.
        [Parameter()]
        [string] $DefaultComponentType
    )

    $ErrorActionPreference = 'Stop'
    [bool] $IsDebug   = $DebugPreference   -ne 'SilentlyContinue'
    [bool] $IsVerbose = $VerbosePreference -ne 'SilentlyContinue'

    [string] $EffectiveEntry = $ComponentName

    if (-not [string]::IsNullOrEmpty($DefaultComponentType) -and -not $ComponentName.Contains(':')) {
        $EffectiveEntry = "${DefaultComponentType}:${ComponentName}"
    }

    [array] $Parts = $EffectiveEntry -split ':'

    if ($Parts.Count -ne 2 -or [string]::IsNullOrEmpty($Parts[0]) -or [string]::IsNullOrEmpty($Parts[1])) {
        Write-Warning "Invalid component name '$ComponentName'. Expected format 'Type:Name' with exactly one colon and non-empty Type/Name."
        return $null
    }

    [string] $Type = $Parts[0]
    [string] $Name = $Parts[1]

    return [PSCustomObject]@{
        Type = $Type
        Name = $Name
        Key  = "${Type}:${Name}"
    }
}