parsec-cloud icon indicating copy to clipboard operation
parsec-cloud copied to clipboard

Rewrite the protocol json file to respect the `protocol scheme`

Open FirelightFlagboy opened this issue 3 years ago • 0 comments

The protocol scheme

type ProtocolScheme = {
    label: string,
    major_versions: number[],
    req: {
        cmd: string,
        unit?: string
        other_fields: Field[]
    }[],
    reps: {
        status: string,
        other_fields: Field[]
    }[]
    nested_types?: {
        label: string,
        discriminant_field: string,
        variants: {
            name: string,
            discriminant_value: string,
            fields: Field[]
        }[]
    }[]
}[]

type Field = {
    name: string,
    type: string,
    introduced_in?: MajorMinorString
}

type MajorMinorString = `${Major}.${Minor}`
type Major = number
type Minor = number

Example protocol scheme

[
    {
        "label": "FooBar",
        "major_versions": [
            1,
            2,
        ],
        "req": {
            "cmd": "foo_bar",
            "other_fields": [
                {
                    "name": "human_handle",
                    "type": "Option<HumanHandle>",
                    "introduced_in": "1.1",
                },
            ],
        },
        "reps": [
            {
                "status": "ok",
                "other_fields": []
            }
        ]
    },
    {
        "label": "FooBar",
        "major_versions": [
            3
        ],
        "req": {
            "cmd": "foo_bar",
            "other_fields": [
                {
                    "name": "human_handle",
                    "type": "HumanHandle",
                },
            ],
        },
        "reps": [
            {
                "status": "ok",
                "other_fields": []
            },
            {
                "status": "error",
                "other_fields": [
                    {
                        "name": "reason",
                        "type": "String"
                    }
                ]
            }
        ]
    },
]

From the example above, we have the field human_handle that is present on versions >=1.1 (including 2.*)

FirelightFlagboy avatar Sep 14 '22 07:09 FirelightFlagboy