```python
def swap_keys(names: dict) -> dict:
    """
    Swap keys and values in the given dictionary, keeping only the first key
    for each value in lexicographical order. Exclude entries with empty string as value.
    
    :param names: Dictionary mapping names to codes.
    :return: Dictionary mapping codes to names.
    """
    if not isinstance(names, dict):
        raise ValueError("Input must be a dictionary.")
    
    swapped = {}
    for name, code in names.items():
        if not isinstance(name, str) or not isinstance(code, str):
            raise ValueError("All keys and values must be strings.")
        
        if code == "":
            continue
        
        if code in swapped:
            if name < swapped[code]:
                swapped[code] = name
        else:
            swapped[code] = name
    
    return swapped
```