An experimental TypeSpec syntax for Lexicon

How to represent union of tokens with default value? #6

closed
opened by maxine.puppykitty.racing

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.

seems like this works in 0.4.0

import "@typelex/emitter";

namespace community.lexicon.calendar.event.defs {
    /** The mode of the event. */
    @default(Inperson)
    union Mode {
        Hybrid,
        Inperson,
        Virtual,
        string
    }

    /** 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 {}
}
sign up or login to add to the discussion
Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:nmc77zslrwafxn75j66mep6o/sh.tangled.repo.issue/3m344mgv5km22