How to represent union of tokens with default value?

did:plc:nmc77zslrwafxn75j66mep6o opened this Oct 13, 2025 2 comments
did:plc:nmc77zslrwafxn75j66mep6o opened Oct 13, 2025

Community Lexicon has a lexicon like this (paraphrased):

{
    "lexicon": 1,
    "id": "community.lexicon.calendar.event",
    "defs": {
        "mode": {
            "type": "string",
            "description": "The mode of the event.",
            "default": "community.lexicon.calendar.event#inperson",
            "knownValues": [
                "community.lexicon.calendar.event#hybrid",
                "community.lexicon.calendar.event#inperson",
                "community.lexicon.calendar.event#virtual"
            ]
        },
        "virtual": {
            "type": "token",
            "description": "A virtual event that takes place online."
        },
        "inperson": {
            "type": "token",
            "description": "An in-person event that takes place offline."
        },
        "hybrid": {
            "type": "token",
            "description": "A hybrid event that takes place both online and offline."
        }
    }
}

This maps almost to:

    /** The mode of the event. */
    @closed @inline
    union Mode {
        Hybrid,
        Inperson,
        Virtual,
    }

    /** A virtual event that takes place online. */
    @token
    model Virtual {}

    /** An in-person event that takes place offline. */
    @token
    model Inperson {}

    /** A hybrid event that takes place both online and offline. */
    @token
    model Hybrid {}

But I'm struggling to think of how to represent the default value in typelex.

No activity yet.

cospan · schematic version control on atproto built on AT Protocol