cddl2py 0.0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +136 -0
- package/bin/cddl2py.js +0 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +246 -30
- package/package.json +12 -8
- package/.release-it.ts +0 -11
- package/src/cli.ts +0 -42
- package/src/constants.ts +0 -32
- package/src/index.ts +0 -658
- package/src/utils.ts +0 -12
- package/tests/__snapshots__/complex_types.test.ts.snap +0 -81
- package/tests/__snapshots__/group_choice.test.ts.snap +0 -127
- package/tests/__snapshots__/literals.test.ts.snap +0 -15
- package/tests/__snapshots__/mixin_union.test.ts.snap +0 -65
- package/tests/__snapshots__/mod.test.ts.snap +0 -145
- package/tests/__snapshots__/named_group_choice.test.ts.snap +0 -37
- package/tests/__snapshots__/transform.test.ts.snap +0 -137
- package/tests/__snapshots__/webdriver_local.test.ts.snap +0 -921
- package/tests/__snapshots__/webdriver_remote.test.ts.snap +0 -1249
- package/tests/complex_types.test.ts +0 -92
- package/tests/group_choice.test.ts +0 -88
- package/tests/literals.test.ts +0 -63
- package/tests/mixin_union.test.ts +0 -80
- package/tests/mod.test.ts +0 -106
- package/tests/named_group_choice.test.ts +0 -82
- package/tests/transform.test.ts +0 -149
- package/tests/transform_edge_cases.test.ts +0 -265
- package/tests/unknown.test.ts +0 -72
- package/tests/webdriver_local.test.ts +0 -64
- package/tests/webdriver_remote.test.ts +0 -64
- package/tsconfig.json +0 -11
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
-
|
|
3
|
-
exports[`complex types conversion > should include all types in the union (Pydantic) 1`] = `
|
|
4
|
-
"# compiled with https://www.npmjs.com/package/cddl2py v0.1.0
|
|
5
|
-
|
|
6
|
-
from __future__ import annotations
|
|
7
|
-
|
|
8
|
-
from typing import Literal, Union
|
|
9
|
-
from pydantic import BaseModel
|
|
10
|
-
|
|
11
|
-
LocalValue = Union[ArrayLocalValue, DateLocalValue, MapLocalValue, ObjectLocalValue, RegExpLocalValue, SetLocalValue]
|
|
12
|
-
|
|
13
|
-
class ArrayLocalValue(BaseModel):
|
|
14
|
-
type: Literal["array"]
|
|
15
|
-
value: ListLocalValue
|
|
16
|
-
|
|
17
|
-
class DateLocalValue(BaseModel):
|
|
18
|
-
type: Literal["date"]
|
|
19
|
-
value: str
|
|
20
|
-
|
|
21
|
-
class MapLocalValue(BaseModel):
|
|
22
|
-
type: Literal["map"]
|
|
23
|
-
value: MappingLocalValue
|
|
24
|
-
|
|
25
|
-
class ObjectLocalValue(BaseModel):
|
|
26
|
-
type: Literal["object"]
|
|
27
|
-
value: MappingLocalValue
|
|
28
|
-
|
|
29
|
-
class RegExpLocalValue(BaseModel):
|
|
30
|
-
type: Literal["regexp"]
|
|
31
|
-
value: str
|
|
32
|
-
|
|
33
|
-
class SetLocalValue(BaseModel):
|
|
34
|
-
type: Literal["set"]
|
|
35
|
-
value: ListLocalValue
|
|
36
|
-
|
|
37
|
-
MappingLocalValue = list[Union[LocalValue, str]]
|
|
38
|
-
|
|
39
|
-
ListLocalValue = list[LocalValue]
|
|
40
|
-
"
|
|
41
|
-
`;
|
|
42
|
-
|
|
43
|
-
exports[`complex types conversion > should include all types in the union (TypedDict) 1`] = `
|
|
44
|
-
"# compiled with https://www.npmjs.com/package/cddl2py v0.1.0
|
|
45
|
-
|
|
46
|
-
from __future__ import annotations
|
|
47
|
-
|
|
48
|
-
from typing import Literal, Union
|
|
49
|
-
from typing_extensions import TypedDict
|
|
50
|
-
|
|
51
|
-
LocalValue = Union[ArrayLocalValue, DateLocalValue, MapLocalValue, ObjectLocalValue, RegExpLocalValue, SetLocalValue]
|
|
52
|
-
|
|
53
|
-
class ArrayLocalValue(TypedDict):
|
|
54
|
-
type: Literal["array"]
|
|
55
|
-
value: ListLocalValue
|
|
56
|
-
|
|
57
|
-
class DateLocalValue(TypedDict):
|
|
58
|
-
type: Literal["date"]
|
|
59
|
-
value: str
|
|
60
|
-
|
|
61
|
-
class MapLocalValue(TypedDict):
|
|
62
|
-
type: Literal["map"]
|
|
63
|
-
value: MappingLocalValue
|
|
64
|
-
|
|
65
|
-
class ObjectLocalValue(TypedDict):
|
|
66
|
-
type: Literal["object"]
|
|
67
|
-
value: MappingLocalValue
|
|
68
|
-
|
|
69
|
-
class RegExpLocalValue(TypedDict):
|
|
70
|
-
type: Literal["regexp"]
|
|
71
|
-
value: str
|
|
72
|
-
|
|
73
|
-
class SetLocalValue(TypedDict):
|
|
74
|
-
type: Literal["set"]
|
|
75
|
-
value: ListLocalValue
|
|
76
|
-
|
|
77
|
-
MappingLocalValue = list[Union[LocalValue, str]]
|
|
78
|
-
|
|
79
|
-
ListLocalValue = list[LocalValue]
|
|
80
|
-
"
|
|
81
|
-
`;
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
-
|
|
3
|
-
exports[`group choice conversion > should generate a union type for multiple group choices (Pydantic) 1`] = `
|
|
4
|
-
"# compiled with https://www.npmjs.com/package/cddl2py v0.1.0
|
|
5
|
-
|
|
6
|
-
from __future__ import annotations
|
|
7
|
-
|
|
8
|
-
from typing import Any, Literal, Tuple, Union
|
|
9
|
-
from pydantic import BaseModel
|
|
10
|
-
|
|
11
|
-
Extensible = dict[str, Any]
|
|
12
|
-
|
|
13
|
-
ProxyConfiguration = Union[AutodetectProxyConfiguration, DirectProxyConfiguration, ManualProxyConfiguration]
|
|
14
|
-
|
|
15
|
-
class AutodetectProxyConfiguration(Extensible):
|
|
16
|
-
proxy_type: Literal["autodetect"]
|
|
17
|
-
|
|
18
|
-
class DirectProxyConfiguration(Extensible):
|
|
19
|
-
proxy_type: Literal["direct"]
|
|
20
|
-
|
|
21
|
-
class ManualProxyConfiguration(Extensible):
|
|
22
|
-
proxy_type: Literal["manual"]
|
|
23
|
-
|
|
24
|
-
SimpleGroupChoice = Union[Int, str]
|
|
25
|
-
|
|
26
|
-
class NestedGroupChoice(BaseModel):
|
|
27
|
-
pass
|
|
28
|
-
|
|
29
|
-
SequenceGroupChoice = Union[Tuple[int, str], float]
|
|
30
|
-
|
|
31
|
-
class _MapGroupChoiceVariant0(BaseModel):
|
|
32
|
-
a: Literal[1]
|
|
33
|
-
|
|
34
|
-
class _MapGroupChoiceVariant1(BaseModel):
|
|
35
|
-
b: Literal[2]
|
|
36
|
-
|
|
37
|
-
MapGroupChoice = Union[_MapGroupChoiceVariant0, _MapGroupChoiceVariant1]
|
|
38
|
-
|
|
39
|
-
TypeChoiceInsideGroup = Union[int, str]
|
|
40
|
-
|
|
41
|
-
ArrayGroupChoice = list[Union[Int, str]]
|
|
42
|
-
|
|
43
|
-
class MapWithBareGroup(BaseModel):
|
|
44
|
-
pass
|
|
45
|
-
|
|
46
|
-
class MapWithParensGroup(BaseModel):
|
|
47
|
-
pass
|
|
48
|
-
|
|
49
|
-
class MapGroupWrap(BaseModel):
|
|
50
|
-
pass
|
|
51
|
-
|
|
52
|
-
class PropChoiceNoOp(BaseModel):
|
|
53
|
-
a: Union[int, float]
|
|
54
|
-
b: str
|
|
55
|
-
|
|
56
|
-
NestedChoiceRef = Union[int, str]
|
|
57
|
-
|
|
58
|
-
class MapNoComma(BaseModel):
|
|
59
|
-
a: int
|
|
60
|
-
b: str
|
|
61
|
-
|
|
62
|
-
GroupChoiceMulti = Union[dict[str, Any], dict[str, Any], dict[str, Any]]
|
|
63
|
-
"
|
|
64
|
-
`;
|
|
65
|
-
|
|
66
|
-
exports[`group choice conversion > should generate a union type for multiple group choices (TypedDict) 1`] = `
|
|
67
|
-
"# compiled with https://www.npmjs.com/package/cddl2py v0.1.0
|
|
68
|
-
|
|
69
|
-
from __future__ import annotations
|
|
70
|
-
|
|
71
|
-
from typing import Any, Literal, Tuple, Union
|
|
72
|
-
from typing_extensions import TypedDict
|
|
73
|
-
|
|
74
|
-
Extensible = dict[str, Any]
|
|
75
|
-
|
|
76
|
-
ProxyConfiguration = Union[AutodetectProxyConfiguration, DirectProxyConfiguration, ManualProxyConfiguration]
|
|
77
|
-
|
|
78
|
-
class AutodetectProxyConfiguration(Extensible):
|
|
79
|
-
proxy_type: Literal["autodetect"]
|
|
80
|
-
|
|
81
|
-
class DirectProxyConfiguration(Extensible):
|
|
82
|
-
proxy_type: Literal["direct"]
|
|
83
|
-
|
|
84
|
-
class ManualProxyConfiguration(Extensible):
|
|
85
|
-
proxy_type: Literal["manual"]
|
|
86
|
-
|
|
87
|
-
SimpleGroupChoice = Union[Int, str]
|
|
88
|
-
|
|
89
|
-
class NestedGroupChoice(TypedDict):
|
|
90
|
-
pass
|
|
91
|
-
|
|
92
|
-
SequenceGroupChoice = Union[Tuple[int, str], float]
|
|
93
|
-
|
|
94
|
-
class _MapGroupChoiceVariant0(TypedDict):
|
|
95
|
-
a: Literal[1]
|
|
96
|
-
|
|
97
|
-
class _MapGroupChoiceVariant1(TypedDict):
|
|
98
|
-
b: Literal[2]
|
|
99
|
-
|
|
100
|
-
MapGroupChoice = Union[_MapGroupChoiceVariant0, _MapGroupChoiceVariant1]
|
|
101
|
-
|
|
102
|
-
TypeChoiceInsideGroup = Union[int, str]
|
|
103
|
-
|
|
104
|
-
ArrayGroupChoice = list[Union[Int, str]]
|
|
105
|
-
|
|
106
|
-
class MapWithBareGroup(TypedDict):
|
|
107
|
-
pass
|
|
108
|
-
|
|
109
|
-
class MapWithParensGroup(TypedDict):
|
|
110
|
-
pass
|
|
111
|
-
|
|
112
|
-
class MapGroupWrap(TypedDict):
|
|
113
|
-
pass
|
|
114
|
-
|
|
115
|
-
class PropChoiceNoOp(TypedDict):
|
|
116
|
-
a: Union[int, float]
|
|
117
|
-
b: str
|
|
118
|
-
|
|
119
|
-
NestedChoiceRef = Union[int, str]
|
|
120
|
-
|
|
121
|
-
class MapNoComma(TypedDict):
|
|
122
|
-
a: int
|
|
123
|
-
b: str
|
|
124
|
-
|
|
125
|
-
GroupChoiceMulti = Union[dict[str, Any], dict[str, Any], dict[str, Any]]
|
|
126
|
-
"
|
|
127
|
-
`;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
-
|
|
3
|
-
exports[`literals > should support bigint and null literals 1`] = `
|
|
4
|
-
"# compiled with https://www.npmjs.com/package/cddl2py v0.1.0
|
|
5
|
-
|
|
6
|
-
from __future__ import annotations
|
|
7
|
-
|
|
8
|
-
from typing import Literal
|
|
9
|
-
from typing_extensions import TypedDict
|
|
10
|
-
|
|
11
|
-
class LiteralTest(TypedDict):
|
|
12
|
-
big_int: Literal[9007199254740996]
|
|
13
|
-
null_val: None
|
|
14
|
-
"
|
|
15
|
-
`;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
-
|
|
3
|
-
exports[`mixin and union conversion > should generate union type aliases for mixin choices (Pydantic) 1`] = `
|
|
4
|
-
"# compiled with https://www.npmjs.com/package/cddl2py v0.1.0
|
|
5
|
-
|
|
6
|
-
from __future__ import annotations
|
|
7
|
-
|
|
8
|
-
from typing import Union
|
|
9
|
-
from pydantic import BaseModel
|
|
10
|
-
|
|
11
|
-
class Mixins(MixinA, MixinB):
|
|
12
|
-
pass
|
|
13
|
-
|
|
14
|
-
class MixinA(BaseModel):
|
|
15
|
-
a: int
|
|
16
|
-
|
|
17
|
-
class MixinB(BaseModel):
|
|
18
|
-
b: str
|
|
19
|
-
|
|
20
|
-
UnionMixin = Union[MixinA, MixinB]
|
|
21
|
-
|
|
22
|
-
class _ComplexMixinsFields(BaseModel):
|
|
23
|
-
c: bool
|
|
24
|
-
|
|
25
|
-
class _ComplexMixinsVariant0(_ComplexMixinsFields, MixinA):
|
|
26
|
-
pass
|
|
27
|
-
|
|
28
|
-
class _ComplexMixinsVariant1(_ComplexMixinsFields, MixinB):
|
|
29
|
-
pass
|
|
30
|
-
|
|
31
|
-
ComplexMixins = Union[_ComplexMixinsVariant0, _ComplexMixinsVariant1]
|
|
32
|
-
"
|
|
33
|
-
`;
|
|
34
|
-
|
|
35
|
-
exports[`mixin and union conversion > should generate union type aliases for mixin choices (TypedDict) 1`] = `
|
|
36
|
-
"# compiled with https://www.npmjs.com/package/cddl2py v0.1.0
|
|
37
|
-
|
|
38
|
-
from __future__ import annotations
|
|
39
|
-
|
|
40
|
-
from typing import Union
|
|
41
|
-
from typing_extensions import TypedDict
|
|
42
|
-
|
|
43
|
-
class Mixins(MixinA, MixinB):
|
|
44
|
-
pass
|
|
45
|
-
|
|
46
|
-
class MixinA(TypedDict):
|
|
47
|
-
a: int
|
|
48
|
-
|
|
49
|
-
class MixinB(TypedDict):
|
|
50
|
-
b: str
|
|
51
|
-
|
|
52
|
-
UnionMixin = Union[MixinA, MixinB]
|
|
53
|
-
|
|
54
|
-
class _ComplexMixinsFields(TypedDict):
|
|
55
|
-
c: bool
|
|
56
|
-
|
|
57
|
-
class _ComplexMixinsVariant0(_ComplexMixinsFields, MixinA):
|
|
58
|
-
pass
|
|
59
|
-
|
|
60
|
-
class _ComplexMixinsVariant1(_ComplexMixinsFields, MixinB):
|
|
61
|
-
pass
|
|
62
|
-
|
|
63
|
-
ComplexMixins = Union[_ComplexMixinsVariant0, _ComplexMixinsVariant1]
|
|
64
|
-
"
|
|
65
|
-
`;
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
-
|
|
3
|
-
exports[`cddl2py CLI > should generate correct pydantic types for test.cddl 1`] = `
|
|
4
|
-
[
|
|
5
|
-
[
|
|
6
|
-
"# compiled with https://www.npmjs.com/package/cddl2py v0.1.0
|
|
7
|
-
|
|
8
|
-
from __future__ import annotations
|
|
9
|
-
|
|
10
|
-
from typing import Any, Literal, Optional, Union
|
|
11
|
-
from pydantic import BaseModel, Field
|
|
12
|
-
|
|
13
|
-
Message = Union[CommandResponse, ErrorResponse, Event]
|
|
14
|
-
|
|
15
|
-
class ErrorResponse(Extensible):
|
|
16
|
-
id: Optional[Union[JsUint, None]] = None
|
|
17
|
-
error: ErrorCode
|
|
18
|
-
message: str
|
|
19
|
-
stacktrace: Optional[str] = None
|
|
20
|
-
|
|
21
|
-
ResultData = Union[BrowsingContextResult, EmptyResult, NetworkResult, ScriptResult, SessionResult]
|
|
22
|
-
|
|
23
|
-
ErrorCode = Union[Literal["invalid argument"], Literal["invalid session id"], Literal["no such alert"], Literal["no such frame"], Literal["no such handle"], Literal["no such node"], Literal["no such script"], Literal["session not created"], Literal["unknown command"], Literal["unknown error"], Literal["unsupported operation"]]
|
|
24
|
-
|
|
25
|
-
JsInt = int
|
|
26
|
-
|
|
27
|
-
JsUint = int
|
|
28
|
-
|
|
29
|
-
Handle = str
|
|
30
|
-
|
|
31
|
-
SharedId = str
|
|
32
|
-
|
|
33
|
-
class UndefinedValue(BaseModel):
|
|
34
|
-
type: Literal["undefined"]
|
|
35
|
-
|
|
36
|
-
class NullValue(BaseModel):
|
|
37
|
-
type: None
|
|
38
|
-
|
|
39
|
-
class StringValue(BaseModel):
|
|
40
|
-
type: Literal["string"]
|
|
41
|
-
value: str
|
|
42
|
-
|
|
43
|
-
SpecialNumber = Union[Literal["NaN"], Literal["-0"], Literal["Infinity"], Literal["-Infinity"]]
|
|
44
|
-
|
|
45
|
-
class NumberValue(BaseModel):
|
|
46
|
-
type: Literal["number"]
|
|
47
|
-
value: Union[Number, SpecialNumber]
|
|
48
|
-
|
|
49
|
-
class SessionCapabilitiesRequest(BaseModel):
|
|
50
|
-
always_match: Optional[SessionCapabilityRequest] = None
|
|
51
|
-
first_match: Optional[list[SessionCapabilityRequest]] = None
|
|
52
|
-
nested: dict[str, Any]
|
|
53
|
-
|
|
54
|
-
class SomeGroup(BaseModel):
|
|
55
|
-
optional: Optional[str] = None # this is not leading
|
|
56
|
-
orientation: Optional[Union[Literal["portrait"], Literal["landscape"]]] = Field(default="portrait")
|
|
57
|
-
scale: Optional[int] = None
|
|
58
|
-
shrink_to_fit: Optional[bool] = None
|
|
59
|
-
shrink_to_fit_p: Optional[bool] = Field(default=True)
|
|
60
|
-
bottom: Optional[float] = Field(default=1) # this is the pageRanges param
|
|
61
|
-
page_ranges: Optional[list[Union[JsUint, str]]] = None
|
|
62
|
-
foo: Optional[str] = None
|
|
63
|
-
pointer_type: Optional[InputPointerType] = None
|
|
64
|
-
|
|
65
|
-
ScriptListLocalValue = list[ScriptLocalValue]
|
|
66
|
-
|
|
67
|
-
ScriptMappingLocalValue = list[Union[ScriptLocalValue, str]]
|
|
68
|
-
|
|
69
|
-
Extensible = dict[str, Any]
|
|
70
|
-
",
|
|
71
|
-
],
|
|
72
|
-
]
|
|
73
|
-
`;
|
|
74
|
-
|
|
75
|
-
exports[`cddl2py CLI > should generate correct types for test.cddl 1`] = `
|
|
76
|
-
[
|
|
77
|
-
[
|
|
78
|
-
"# compiled with https://www.npmjs.com/package/cddl2py v0.1.0
|
|
79
|
-
|
|
80
|
-
from __future__ import annotations
|
|
81
|
-
|
|
82
|
-
from typing import Any, Literal, Union
|
|
83
|
-
from typing_extensions import NotRequired, TypedDict
|
|
84
|
-
|
|
85
|
-
Message = Union[CommandResponse, ErrorResponse, Event]
|
|
86
|
-
|
|
87
|
-
class ErrorResponse(Extensible):
|
|
88
|
-
id: NotRequired[Union[JsUint, None]]
|
|
89
|
-
error: ErrorCode
|
|
90
|
-
message: str
|
|
91
|
-
stacktrace: NotRequired[str]
|
|
92
|
-
|
|
93
|
-
ResultData = Union[BrowsingContextResult, EmptyResult, NetworkResult, ScriptResult, SessionResult]
|
|
94
|
-
|
|
95
|
-
ErrorCode = Union[Literal["invalid argument"], Literal["invalid session id"], Literal["no such alert"], Literal["no such frame"], Literal["no such handle"], Literal["no such node"], Literal["no such script"], Literal["session not created"], Literal["unknown command"], Literal["unknown error"], Literal["unsupported operation"]]
|
|
96
|
-
|
|
97
|
-
JsInt = int
|
|
98
|
-
|
|
99
|
-
JsUint = int
|
|
100
|
-
|
|
101
|
-
Handle = str
|
|
102
|
-
|
|
103
|
-
SharedId = str
|
|
104
|
-
|
|
105
|
-
class UndefinedValue(TypedDict):
|
|
106
|
-
type: Literal["undefined"]
|
|
107
|
-
|
|
108
|
-
class NullValue(TypedDict):
|
|
109
|
-
type: None
|
|
110
|
-
|
|
111
|
-
class StringValue(TypedDict):
|
|
112
|
-
type: Literal["string"]
|
|
113
|
-
value: str
|
|
114
|
-
|
|
115
|
-
SpecialNumber = Union[Literal["NaN"], Literal["-0"], Literal["Infinity"], Literal["-Infinity"]]
|
|
116
|
-
|
|
117
|
-
class NumberValue(TypedDict):
|
|
118
|
-
type: Literal["number"]
|
|
119
|
-
value: Union[Number, SpecialNumber]
|
|
120
|
-
|
|
121
|
-
class SessionCapabilitiesRequest(TypedDict):
|
|
122
|
-
always_match: NotRequired[SessionCapabilityRequest]
|
|
123
|
-
first_match: NotRequired[list[SessionCapabilityRequest]]
|
|
124
|
-
nested: dict[str, Any]
|
|
125
|
-
|
|
126
|
-
class SomeGroup(TypedDict):
|
|
127
|
-
optional: NotRequired[str] # this is not leading
|
|
128
|
-
orientation: NotRequired[Union[Literal["portrait"], Literal["landscape"]]]
|
|
129
|
-
scale: NotRequired[int]
|
|
130
|
-
shrink_to_fit: NotRequired[bool]
|
|
131
|
-
shrink_to_fit_p: NotRequired[bool]
|
|
132
|
-
bottom: NotRequired[float] # this is the pageRanges param
|
|
133
|
-
page_ranges: NotRequired[list[Union[JsUint, str]]]
|
|
134
|
-
foo: NotRequired[str]
|
|
135
|
-
pointer_type: NotRequired[InputPointerType]
|
|
136
|
-
|
|
137
|
-
ScriptListLocalValue = list[ScriptLocalValue]
|
|
138
|
-
|
|
139
|
-
ScriptMappingLocalValue = list[Union[ScriptLocalValue, str]]
|
|
140
|
-
|
|
141
|
-
Extensible = dict[str, Any]
|
|
142
|
-
",
|
|
143
|
-
],
|
|
144
|
-
]
|
|
145
|
-
`;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
-
|
|
3
|
-
exports[`named group choice > should generate a union type alias for named group references (Pydantic) 1`] = `
|
|
4
|
-
"# compiled with https://www.npmjs.com/package/cddl2py v0.1.0
|
|
5
|
-
|
|
6
|
-
from __future__ import annotations
|
|
7
|
-
|
|
8
|
-
from typing import Union
|
|
9
|
-
from pydantic import BaseModel
|
|
10
|
-
|
|
11
|
-
Choice = Union[OptionA, OptionB]
|
|
12
|
-
|
|
13
|
-
class OptionA(BaseModel):
|
|
14
|
-
a: int
|
|
15
|
-
|
|
16
|
-
class OptionB(BaseModel):
|
|
17
|
-
b: str
|
|
18
|
-
"
|
|
19
|
-
`;
|
|
20
|
-
|
|
21
|
-
exports[`named group choice > should generate a union type alias for named group references (TypedDict) 1`] = `
|
|
22
|
-
"# compiled with https://www.npmjs.com/package/cddl2py v0.1.0
|
|
23
|
-
|
|
24
|
-
from __future__ import annotations
|
|
25
|
-
|
|
26
|
-
from typing import Union
|
|
27
|
-
from typing_extensions import TypedDict
|
|
28
|
-
|
|
29
|
-
Choice = Union[OptionA, OptionB]
|
|
30
|
-
|
|
31
|
-
class OptionA(TypedDict):
|
|
32
|
-
a: int
|
|
33
|
-
|
|
34
|
-
class OptionB(TypedDict):
|
|
35
|
-
b: str
|
|
36
|
-
"
|
|
37
|
-
`;
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
-
|
|
3
|
-
exports[`transform > snapshot tests with parsed CDDL > should transform test.cddl Pydantic correctly 1`] = `
|
|
4
|
-
"# compiled with https://www.npmjs.com/package/cddl2py v0.0.0
|
|
5
|
-
|
|
6
|
-
from __future__ import annotations
|
|
7
|
-
|
|
8
|
-
from typing import Any, Literal, Optional, Union
|
|
9
|
-
from pydantic import BaseModel, Field
|
|
10
|
-
|
|
11
|
-
Message = Union[CommandResponse, ErrorResponse, Event]
|
|
12
|
-
|
|
13
|
-
class ErrorResponse(Extensible):
|
|
14
|
-
id: Optional[Union[JsUint, None]] = None
|
|
15
|
-
error: ErrorCode
|
|
16
|
-
message: str
|
|
17
|
-
stacktrace: Optional[str] = None
|
|
18
|
-
|
|
19
|
-
ResultData = Union[BrowsingContextResult, EmptyResult, NetworkResult, ScriptResult, SessionResult]
|
|
20
|
-
|
|
21
|
-
ErrorCode = Union[Literal["invalid argument"], Literal["invalid session id"], Literal["no such alert"], Literal["no such frame"], Literal["no such handle"], Literal["no such node"], Literal["no such script"], Literal["session not created"], Literal["unknown command"], Literal["unknown error"], Literal["unsupported operation"]]
|
|
22
|
-
|
|
23
|
-
JsInt = int
|
|
24
|
-
|
|
25
|
-
JsUint = int
|
|
26
|
-
|
|
27
|
-
Handle = str
|
|
28
|
-
|
|
29
|
-
SharedId = str
|
|
30
|
-
|
|
31
|
-
class UndefinedValue(BaseModel):
|
|
32
|
-
type: Literal["undefined"]
|
|
33
|
-
|
|
34
|
-
class NullValue(BaseModel):
|
|
35
|
-
type: None
|
|
36
|
-
|
|
37
|
-
class StringValue(BaseModel):
|
|
38
|
-
type: Literal["string"]
|
|
39
|
-
value: str
|
|
40
|
-
|
|
41
|
-
SpecialNumber = Union[Literal["NaN"], Literal["-0"], Literal["Infinity"], Literal["-Infinity"]]
|
|
42
|
-
|
|
43
|
-
class NumberValue(BaseModel):
|
|
44
|
-
type: Literal["number"]
|
|
45
|
-
value: Union[Number, SpecialNumber]
|
|
46
|
-
|
|
47
|
-
class SessionCapabilitiesRequest(BaseModel):
|
|
48
|
-
always_match: Optional[SessionCapabilityRequest] = None
|
|
49
|
-
first_match: Optional[list[SessionCapabilityRequest]] = None
|
|
50
|
-
nested: dict[str, Any]
|
|
51
|
-
|
|
52
|
-
class SomeGroup(BaseModel):
|
|
53
|
-
optional: Optional[str] = None # this is not leading
|
|
54
|
-
orientation: Optional[Union[Literal["portrait"], Literal["landscape"]]] = Field(default="portrait")
|
|
55
|
-
scale: Optional[int] = None
|
|
56
|
-
shrink_to_fit: Optional[bool] = None
|
|
57
|
-
shrink_to_fit_p: Optional[bool] = Field(default=True)
|
|
58
|
-
bottom: Optional[float] = Field(default=1) # this is the pageRanges param
|
|
59
|
-
page_ranges: Optional[list[Union[JsUint, str]]] = None
|
|
60
|
-
foo: Optional[str] = None
|
|
61
|
-
pointer_type: Optional[InputPointerType] = None
|
|
62
|
-
|
|
63
|
-
ScriptListLocalValue = list[ScriptLocalValue]
|
|
64
|
-
|
|
65
|
-
ScriptMappingLocalValue = list[Union[ScriptLocalValue, str]]
|
|
66
|
-
|
|
67
|
-
Extensible = dict[str, Any]
|
|
68
|
-
"
|
|
69
|
-
`;
|
|
70
|
-
|
|
71
|
-
exports[`transform > snapshot tests with parsed CDDL > should transform test.cddl TypedDict correctly 1`] = `
|
|
72
|
-
"# compiled with https://www.npmjs.com/package/cddl2py v0.0.0
|
|
73
|
-
|
|
74
|
-
from __future__ import annotations
|
|
75
|
-
|
|
76
|
-
from typing import Any, Literal, Union
|
|
77
|
-
from typing_extensions import NotRequired, TypedDict
|
|
78
|
-
|
|
79
|
-
Message = Union[CommandResponse, ErrorResponse, Event]
|
|
80
|
-
|
|
81
|
-
class ErrorResponse(Extensible):
|
|
82
|
-
id: NotRequired[Union[JsUint, None]]
|
|
83
|
-
error: ErrorCode
|
|
84
|
-
message: str
|
|
85
|
-
stacktrace: NotRequired[str]
|
|
86
|
-
|
|
87
|
-
ResultData = Union[BrowsingContextResult, EmptyResult, NetworkResult, ScriptResult, SessionResult]
|
|
88
|
-
|
|
89
|
-
ErrorCode = Union[Literal["invalid argument"], Literal["invalid session id"], Literal["no such alert"], Literal["no such frame"], Literal["no such handle"], Literal["no such node"], Literal["no such script"], Literal["session not created"], Literal["unknown command"], Literal["unknown error"], Literal["unsupported operation"]]
|
|
90
|
-
|
|
91
|
-
JsInt = int
|
|
92
|
-
|
|
93
|
-
JsUint = int
|
|
94
|
-
|
|
95
|
-
Handle = str
|
|
96
|
-
|
|
97
|
-
SharedId = str
|
|
98
|
-
|
|
99
|
-
class UndefinedValue(TypedDict):
|
|
100
|
-
type: Literal["undefined"]
|
|
101
|
-
|
|
102
|
-
class NullValue(TypedDict):
|
|
103
|
-
type: None
|
|
104
|
-
|
|
105
|
-
class StringValue(TypedDict):
|
|
106
|
-
type: Literal["string"]
|
|
107
|
-
value: str
|
|
108
|
-
|
|
109
|
-
SpecialNumber = Union[Literal["NaN"], Literal["-0"], Literal["Infinity"], Literal["-Infinity"]]
|
|
110
|
-
|
|
111
|
-
class NumberValue(TypedDict):
|
|
112
|
-
type: Literal["number"]
|
|
113
|
-
value: Union[Number, SpecialNumber]
|
|
114
|
-
|
|
115
|
-
class SessionCapabilitiesRequest(TypedDict):
|
|
116
|
-
always_match: NotRequired[SessionCapabilityRequest]
|
|
117
|
-
first_match: NotRequired[list[SessionCapabilityRequest]]
|
|
118
|
-
nested: dict[str, Any]
|
|
119
|
-
|
|
120
|
-
class SomeGroup(TypedDict):
|
|
121
|
-
optional: NotRequired[str] # this is not leading
|
|
122
|
-
orientation: NotRequired[Union[Literal["portrait"], Literal["landscape"]]]
|
|
123
|
-
scale: NotRequired[int]
|
|
124
|
-
shrink_to_fit: NotRequired[bool]
|
|
125
|
-
shrink_to_fit_p: NotRequired[bool]
|
|
126
|
-
bottom: NotRequired[float] # this is the pageRanges param
|
|
127
|
-
page_ranges: NotRequired[list[Union[JsUint, str]]]
|
|
128
|
-
foo: NotRequired[str]
|
|
129
|
-
pointer_type: NotRequired[InputPointerType]
|
|
130
|
-
|
|
131
|
-
ScriptListLocalValue = list[ScriptLocalValue]
|
|
132
|
-
|
|
133
|
-
ScriptMappingLocalValue = list[Union[ScriptLocalValue, str]]
|
|
134
|
-
|
|
135
|
-
Extensible = dict[str, Any]
|
|
136
|
-
"
|
|
137
|
-
`;
|