| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
"""Type definitions used for the asynceapi package.""" |
| 5 |
|
| 6 |
from __future__ import annotations |
| 7 |
|
| 8 |
import sys |
| 9 |
from typing import TYPE_CHECKING, Any, Literal |
| 10 |
|
| 11 |
if TYPE_CHECKING: |
| 12 |
from ._constants import EapiCommandFormat |
| 13 |
|
| 14 |
if sys.version_info >= (3, 11): |
| 15 |
from typing import NotRequired, TypedDict |
| 16 |
else: |
| 17 |
from typing_extensions import NotRequired, TypedDict |
| 18 |
|
| 19 |
EapiJsonOutput = dict[str, Any] |
| 20 |
"""Type definition of an eAPI JSON output response.""" |
| 21 |
EapiTextOutput = str |
| 22 |
"""Type definition of an eAPI text output response.""" |
| 23 |
EapiSimpleCommand = str |
| 24 |
"""Type definition of an eAPI simple command. A simple command is the CLI command to run as a string.""" |
| 25 |
|
| 26 |
|
| 27 |
class EapiComplexCommand(TypedDict): |
| 28 |
"""Type definition of an eAPI complex command. A complex command is a dictionary with the CLI command to run with additional parameters.""" |
| 29 |
|
| 30 |
cmd: str |
| 31 |
input: NotRequired[str] |
| 32 |
revision: NotRequired[int] |
| 33 |
|
| 34 |
|
| 35 |
class JsonRpc(TypedDict): |
| 36 |
"""Type definition of a JSON-RPC payload.""" |
| 37 |
|
| 38 |
jsonrpc: Literal["2.0"] |
| 39 |
method: Literal["runCmds"] |
| 40 |
params: JsonRpcParams |
| 41 |
id: NotRequired[int | str] |
| 42 |
|
| 43 |
|
| 44 |
class JsonRpcParams(TypedDict): |
| 45 |
"""Type definition of JSON-RPC parameters.""" |
| 46 |
|
| 47 |
version: NotRequired[int | Literal["latest"]] |
| 48 |
cmds: list[EapiSimpleCommand | EapiComplexCommand] |
| 49 |
format: NotRequired[EapiCommandFormat] |
| 50 |
autoComplete: NotRequired[bool] |
| 51 |
expandAliases: NotRequired[bool] |
| 52 |
timestamps: NotRequired[bool] |
| 53 |
stopOnError: NotRequired[bool] |