Skip to content

Commit 307752c

Browse files
authored
feat: add support for deprecated type syntax (#977)
Signed-off-by: Louis Mandel <[email protected]>
1 parent 27bb0ea commit 307752c

File tree

7 files changed

+250
-6
lines changed

7 files changed

+250
-6
lines changed

pdl-live-react/src/pdl_ast.d.ts

Lines changed: 153 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,21 @@ export type Program =
4242
export type Description = string | null
4343
export type Enum = unknown[]
4444
export type PdlTypeType =
45-
| ("null" | "boolean" | "string" | "number" | "integer" | "array" | "object")
45+
| (
46+
| "null"
47+
| "boolean"
48+
| "string"
49+
| "number"
50+
| "integer"
51+
| "array"
52+
| "object"
53+
| "bool"
54+
| "str"
55+
| "float"
56+
| "int"
57+
| "list"
58+
| "obj"
59+
)
4660
| EnumPdlType
4761
| PdlTypeType[]
4862
| OptionalPdlType
@@ -2889,6 +2903,12 @@ export interface FunctionBlock {
28892903
| "integer"
28902904
| "array"
28912905
| "object"
2906+
| "bool"
2907+
| "str"
2908+
| "float"
2909+
| "int"
2910+
| "list"
2911+
| "obj"
28922912
)
28932913
| EnumPdlType
28942914
| PdlTypeType[]
@@ -2997,6 +3017,12 @@ export interface CallBlock {
29973017
| "integer"
29983018
| "array"
29993019
| "object"
3020+
| "bool"
3021+
| "str"
3022+
| "float"
3023+
| "int"
3024+
| "list"
3025+
| "obj"
30003026
)
30013027
| EnumPdlType
30023028
| PdlTypeType[]
@@ -3083,6 +3109,12 @@ export interface LitellmModelBlock {
30833109
| "integer"
30843110
| "array"
30853111
| "object"
3112+
| "bool"
3113+
| "str"
3114+
| "float"
3115+
| "int"
3116+
| "list"
3117+
| "obj"
30863118
)
30873119
| EnumPdlType
30883120
| PdlTypeType[]
@@ -3170,6 +3202,12 @@ export interface GraniteioModelBlock {
31703202
| "integer"
31713203
| "array"
31723204
| "object"
3205+
| "bool"
3206+
| "str"
3207+
| "float"
3208+
| "int"
3209+
| "list"
3210+
| "obj"
31733211
)
31743212
| EnumPdlType
31753213
| PdlTypeType[]
@@ -3266,6 +3304,12 @@ export interface CodeBlock {
32663304
| "integer"
32673305
| "array"
32683306
| "object"
3307+
| "bool"
3308+
| "str"
3309+
| "float"
3310+
| "int"
3311+
| "list"
3312+
| "obj"
32693313
)
32703314
| EnumPdlType
32713315
| PdlTypeType[]
@@ -3352,6 +3396,12 @@ export interface ArgsBlock {
33523396
| "integer"
33533397
| "array"
33543398
| "object"
3399+
| "bool"
3400+
| "str"
3401+
| "float"
3402+
| "int"
3403+
| "list"
3404+
| "obj"
33553405
)
33563406
| EnumPdlType
33573407
| PdlTypeType[]
@@ -3432,6 +3482,12 @@ export interface GetBlock {
34323482
| "integer"
34333483
| "array"
34343484
| "object"
3485+
| "bool"
3486+
| "str"
3487+
| "float"
3488+
| "int"
3489+
| "list"
3490+
| "obj"
34353491
)
34363492
| EnumPdlType
34373493
| PdlTypeType[]
@@ -3530,6 +3586,12 @@ export interface DataBlock {
35303586
| "integer"
35313587
| "array"
35323588
| "object"
3589+
| "bool"
3590+
| "str"
3591+
| "float"
3592+
| "int"
3593+
| "list"
3594+
| "obj"
35333595
)
35343596
| EnumPdlType
35353597
| PdlTypeType[]
@@ -3618,6 +3680,12 @@ export interface IfBlock {
36183680
| "integer"
36193681
| "array"
36203682
| "object"
3683+
| "bool"
3684+
| "str"
3685+
| "float"
3686+
| "int"
3687+
| "list"
3688+
| "obj"
36213689
)
36223690
| EnumPdlType
36233691
| PdlTypeType[]
@@ -3716,6 +3784,12 @@ export interface MatchBlock {
37163784
| "integer"
37173785
| "array"
37183786
| "object"
3787+
| "bool"
3788+
| "str"
3789+
| "float"
3790+
| "int"
3791+
| "list"
3792+
| "obj"
37193793
)
37203794
| EnumPdlType
37213795
| PdlTypeType[]
@@ -3814,6 +3888,12 @@ export interface RepeatBlock {
38143888
| "integer"
38153889
| "array"
38163890
| "object"
3891+
| "bool"
3892+
| "str"
3893+
| "float"
3894+
| "int"
3895+
| "list"
3896+
| "obj"
38173897
)
38183898
| EnumPdlType
38193899
| PdlTypeType[]
@@ -3899,6 +3979,12 @@ export interface TextBlock {
38993979
| "integer"
39003980
| "array"
39013981
| "object"
3982+
| "bool"
3983+
| "str"
3984+
| "float"
3985+
| "int"
3986+
| "list"
3987+
| "obj"
39023988
)
39033989
| EnumPdlType
39043990
| PdlTypeType[]
@@ -3977,6 +4063,12 @@ export interface LastOfBlock {
39774063
| "integer"
39784064
| "array"
39794065
| "object"
4066+
| "bool"
4067+
| "str"
4068+
| "float"
4069+
| "int"
4070+
| "list"
4071+
| "obj"
39804072
)
39814073
| EnumPdlType
39824074
| PdlTypeType[]
@@ -4055,6 +4147,12 @@ export interface ArrayBlock {
40554147
| "integer"
40564148
| "array"
40574149
| "object"
4150+
| "bool"
4151+
| "str"
4152+
| "float"
4153+
| "int"
4154+
| "list"
4155+
| "obj"
40584156
)
40594157
| EnumPdlType
40604158
| PdlTypeType[]
@@ -4133,6 +4231,12 @@ export interface ObjectBlock {
41334231
| "integer"
41344232
| "array"
41354233
| "object"
4234+
| "bool"
4235+
| "str"
4236+
| "float"
4237+
| "int"
4238+
| "list"
4239+
| "obj"
41364240
)
41374241
| EnumPdlType
41384242
| PdlTypeType[]
@@ -4211,6 +4315,12 @@ export interface MessageBlock {
42114315
| "integer"
42124316
| "array"
42134317
| "object"
4318+
| "bool"
4319+
| "str"
4320+
| "float"
4321+
| "int"
4322+
| "list"
4323+
| "obj"
42144324
)
42154325
| EnumPdlType
42164326
| PdlTypeType[]
@@ -4302,6 +4412,12 @@ export interface ReadBlock {
43024412
| "integer"
43034413
| "array"
43044414
| "object"
4415+
| "bool"
4416+
| "str"
4417+
| "float"
4418+
| "int"
4419+
| "list"
4420+
| "obj"
43054421
)
43064422
| EnumPdlType
43074423
| PdlTypeType[]
@@ -4381,6 +4497,12 @@ export interface IncludeBlock {
43814497
| "integer"
43824498
| "array"
43834499
| "object"
4500+
| "bool"
4501+
| "str"
4502+
| "float"
4503+
| "int"
4504+
| "list"
4505+
| "obj"
43844506
)
43854507
| EnumPdlType
43864508
| PdlTypeType[]
@@ -4460,6 +4582,12 @@ export interface ImportBlock {
44604582
| "integer"
44614583
| "array"
44624584
| "object"
4585+
| "bool"
4586+
| "str"
4587+
| "float"
4588+
| "int"
4589+
| "list"
4590+
| "obj"
44634591
)
44644592
| EnumPdlType
44654593
| PdlTypeType[]
@@ -4538,6 +4666,12 @@ export interface ErrorBlock {
45384666
| "integer"
45394667
| "array"
45404668
| "object"
4669+
| "bool"
4670+
| "str"
4671+
| "float"
4672+
| "int"
4673+
| "list"
4674+
| "obj"
45414675
)
45424676
| EnumPdlType
45434677
| PdlTypeType[]
@@ -4616,6 +4750,12 @@ export interface EmptyBlock {
46164750
| "integer"
46174751
| "array"
46184752
| "object"
4753+
| "bool"
4754+
| "str"
4755+
| "float"
4756+
| "int"
4757+
| "list"
4758+
| "obj"
46194759
)
46204760
| EnumPdlType
46214761
| PdlTypeType[]
@@ -4713,6 +4853,12 @@ export interface PdlParser {
47134853
| "integer"
47144854
| "array"
47154855
| "object"
4856+
| "bool"
4857+
| "str"
4858+
| "float"
4859+
| "int"
4860+
| "list"
4861+
| "obj"
47164862
)
47174863
| EnumPdlType
47184864
| PdlTypeType[]
@@ -4739,6 +4885,12 @@ export interface RegexParser {
47394885
| "integer"
47404886
| "array"
47414887
| "object"
4888+
| "bool"
4889+
| "str"
4890+
| "float"
4891+
| "int"
4892+
| "list"
4893+
| "obj"
47424894
)
47434895
| EnumPdlType
47444896
| PdlTypeType[]

src/pdl/pdl-schema.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9834,7 +9834,13 @@
98349834
"number",
98359835
"integer",
98369836
"array",
9837-
"object"
9837+
"object",
9838+
"bool",
9839+
"str",
9840+
"float",
9841+
"int",
9842+
"list",
9843+
"obj"
98389844
],
98399845
"type": "string"
98409846
},

src/pdl/pdl_ast.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,20 @@ class AnyPattern(Pattern):
154154

155155

156156
BasePdlType: TypeAlias = Literal[
157-
"null", "boolean", "string", "number", "integer", "array", "object"
157+
"null",
158+
"boolean",
159+
"string",
160+
"number",
161+
"integer",
162+
"array",
163+
"object",
164+
# deprecated syntax below
165+
"bool",
166+
"str",
167+
"float",
168+
"int",
169+
"list",
170+
"obj",
158171
]
159172
"""Base types."""
160173

src/pdl/pdl_dumper.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
TextBlock,
5959
)
6060
from .pdl_lazy import PdlLazy
61+
from .pdl_schema_utils import OLD_PDLTYPE_TO_JSONSCHEMA_NAME
6162

6263
yaml.SafeDumper.org_represent_str = yaml.SafeDumper.represent_str # type: ignore
6364

@@ -327,6 +328,20 @@ def type_to_dict(t: PdlTypeType):
327328
d = None
328329
case "null" | "boolean" | "string" | "number" | "integer" | "array" | "object":
329330
d = t
331+
case "bool" | "str" | "float" | "int" | "list" | "obj":
332+
d = OLD_PDLTYPE_TO_JSONSCHEMA_NAME[t]
333+
case "bool":
334+
d = "boolean"
335+
case "str":
336+
d = "string"
337+
case "float":
338+
d = "number"
339+
case "int":
340+
d = "integer"
341+
case "list":
342+
d = "array"
343+
case "obj":
344+
d = "object"
330345
case EnumPdlType():
331346
d = t.model_dump()
332347
case [elem]:

0 commit comments

Comments
 (0)