sera-2 1.21.2__py3-none-any.whl → 1.24.1__py3-none-any.whl
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.
- sera/libs/api_helper.py +1 -100
- sera/libs/api_test_helper.py +1 -1
- sera/libs/base_service.py +168 -80
- sera/libs/search_helper.py +359 -0
- sera/make/make_app.py +4 -5
- sera/make/make_python_api.py +65 -113
- sera/make/make_python_model.py +184 -17
- sera/make/make_python_services.py +3 -2
- sera/make/make_typescript_model.py +17 -337
- sera/make/ts_frontend/__init__.py +0 -0
- sera/make/ts_frontend/make_class_schema.py +369 -0
- sera/make/ts_frontend/make_enums.py +104 -0
- sera/make/ts_frontend/misc.py +38 -0
- sera/misc/__init__.py +2 -0
- sera/misc/_utils.py +17 -2
- sera/models/_class.py +2 -2
- sera/models/_collection.py +15 -11
- sera/models/_constraints.py +1 -1
- sera/models/_datatype.py +8 -29
- sera/models/_enum.py +3 -2
- sera/models/_module.py +7 -0
- sera/models/_parse.py +5 -1
- {sera_2-1.21.2.dist-info → sera_2-1.24.1.dist-info}/METADATA +2 -2
- {sera_2-1.21.2.dist-info → sera_2-1.24.1.dist-info}/RECORD +25 -20
- {sera_2-1.21.2.dist-info → sera_2-1.24.1.dist-info}/WHEEL +0 -0
sera/models/_datatype.py
CHANGED
@@ -2,12 +2,10 @@ from __future__ import annotations
|
|
2
2
|
|
3
3
|
import datetime
|
4
4
|
from dataclasses import dataclass, field
|
5
|
-
from typing import
|
5
|
+
from typing import Literal
|
6
6
|
|
7
7
|
from codegen.models import expr
|
8
8
|
|
9
|
-
from sera.misc import identity
|
10
|
-
|
11
9
|
PyDataType = Literal["str", "int", "datetime", "float", "bool", "bytes", "dict"]
|
12
10
|
TypescriptDataType = Literal["string", "number", "boolean"]
|
13
11
|
SQLAlchemyDataType = Literal[
|
@@ -69,30 +67,8 @@ class PyTypeWithDep:
|
|
69
67
|
"""Clone the type with the same dependencies."""
|
70
68
|
return PyTypeWithDep(type=self.type, deps=list(self.deps))
|
71
69
|
|
72
|
-
def
|
73
|
-
|
74
|
-
return ("identity", "sera.misc.identity")
|
75
|
-
if self.type == "int":
|
76
|
-
return ("TypeConversion.to_int", "sera.libs.api_helper.TypeConversion")
|
77
|
-
if self.type == "float":
|
78
|
-
return ("TypeConversion.to_float", "sera.libs.api_helper.TypeConversion")
|
79
|
-
if self.type == "bool":
|
80
|
-
return ("TypeConversion.to_bool", "sera.libs.api_helper.TypeConversion")
|
81
|
-
if any(
|
82
|
-
dep.find(".models.enums.") != -1 and dep.endswith(self.type)
|
83
|
-
for dep in self.deps
|
84
|
-
):
|
85
|
-
# This is an enum type, we directly use the enum constructor as the conversion function
|
86
|
-
return (
|
87
|
-
self.type,
|
88
|
-
[
|
89
|
-
dep
|
90
|
-
for dep in self.deps
|
91
|
-
if dep.find(".models.enums.") != -1 and dep.endswith(self.type)
|
92
|
-
][0],
|
93
|
-
)
|
94
|
-
else:
|
95
|
-
raise NotImplementedError()
|
70
|
+
def is_enum_type(self) -> bool:
|
71
|
+
return any(x.find(".models.enums.") != -1 for x in self.deps)
|
96
72
|
|
97
73
|
|
98
74
|
@dataclass
|
@@ -153,7 +129,7 @@ class TsTypeWithDep:
|
|
153
129
|
return value
|
154
130
|
if self.type == "Date":
|
155
131
|
return expr.ExprRawTypescript(f"new Date({value.to_typescript()})")
|
156
|
-
if
|
132
|
+
if self.is_enum_type():
|
157
133
|
# enum type, we don't need to do anything as we use strings for enums
|
158
134
|
return value
|
159
135
|
raise ValueError(f"Unknown type: {self.type}")
|
@@ -174,11 +150,14 @@ class TsTypeWithDep:
|
|
174
150
|
return expr.ExprRawTypescript(f"{value.to_typescript()}.toISOString()")
|
175
151
|
if self.type == "Date | undefined":
|
176
152
|
return expr.ExprRawTypescript(f"{value.to_typescript()}?.toISOString()")
|
177
|
-
if
|
153
|
+
if self.is_enum_type():
|
178
154
|
# enum type, we don't need to do anything as we use strings for enums
|
179
155
|
return value
|
180
156
|
raise ValueError(f"Unknown type: {self.type}")
|
181
157
|
|
158
|
+
def is_enum_type(self) -> bool:
|
159
|
+
return any(x.startswith("@.models.enums.") for x in self.deps)
|
160
|
+
|
182
161
|
|
183
162
|
@dataclass
|
184
163
|
class SQLTypeWithDep:
|
sera/models/_enum.py
CHANGED
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
3
3
|
from collections import Counter
|
4
4
|
from dataclasses import dataclass
|
5
5
|
|
6
|
-
from sera.misc import to_snake_case
|
6
|
+
from sera.misc import to_kebab_case, to_snake_case
|
7
7
|
from sera.models._multi_lingual_string import MultiLingualString
|
8
8
|
|
9
9
|
|
@@ -11,6 +11,7 @@ from sera.models._multi_lingual_string import MultiLingualString
|
|
11
11
|
class EnumValue:
|
12
12
|
name: str
|
13
13
|
value: str | int
|
14
|
+
label: MultiLingualString
|
14
15
|
description: MultiLingualString
|
15
16
|
|
16
17
|
|
@@ -44,7 +45,7 @@ class Enum:
|
|
44
45
|
|
45
46
|
def get_tsmodule_name(self) -> str:
|
46
47
|
"""Get the typescript module name of this enum as if there is a typescript module created to store this enum only."""
|
47
|
-
return self.name
|
48
|
+
return self.name
|
48
49
|
|
49
50
|
def is_str_enum(self) -> bool:
|
50
51
|
"""Check if this enum is a string enum."""
|
sera/models/_module.py
CHANGED
@@ -39,6 +39,13 @@ class Package:
|
|
39
39
|
"""Create a module in this package"""
|
40
40
|
return Module(self, name, self.language)
|
41
41
|
|
42
|
+
def parent(self) -> Package:
|
43
|
+
"""Get the parent package"""
|
44
|
+
assert self.path.count(".") > 0, "Cannot get parent of top-level package"
|
45
|
+
return Package(
|
46
|
+
self.app, self.path.rsplit(".", 1)[0], self.dir.parent, self.language
|
47
|
+
)
|
48
|
+
|
42
49
|
|
43
50
|
@dataclass
|
44
51
|
class Module:
|
sera/models/_parse.py
CHANGED
@@ -91,13 +91,17 @@ def _parse_enum(schema: Schema, enum_name: str, enum: dict) -> Enum:
|
|
91
91
|
for k, v in enum.items():
|
92
92
|
if isinstance(v, (str, int)):
|
93
93
|
values[k] = EnumValue(
|
94
|
-
name=k,
|
94
|
+
name=k,
|
95
|
+
value=v,
|
96
|
+
label=MultiLingualString.en(""),
|
97
|
+
description=MultiLingualString.en(""),
|
95
98
|
)
|
96
99
|
else:
|
97
100
|
try:
|
98
101
|
values[k] = EnumValue(
|
99
102
|
name=k,
|
100
103
|
value=v["value"],
|
104
|
+
label=_parse_multi_lingual_string(v.get("label", "")),
|
101
105
|
description=_parse_multi_lingual_string(v.get("desc", "")),
|
102
106
|
)
|
103
107
|
except KeyError as e:
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: sera-2
|
3
|
-
Version: 1.
|
3
|
+
Version: 1.24.1
|
4
4
|
Summary:
|
5
5
|
Author: Binh Vu
|
6
6
|
Author-email: bvu687@gmail.com
|
@@ -9,7 +9,7 @@ Classifier: Programming Language :: Python :: 3
|
|
9
9
|
Classifier: Programming Language :: Python :: 3.12
|
10
10
|
Classifier: Programming Language :: Python :: 3.13
|
11
11
|
Requires-Dist: black (==25.1.0)
|
12
|
-
Requires-Dist: codegen-2 (>=2.
|
12
|
+
Requires-Dist: codegen-2 (>=2.14.0,<3.0.0)
|
13
13
|
Requires-Dist: graph-wrapper (>=1.7.3,<2.0.0)
|
14
14
|
Requires-Dist: isort (==6.0.1)
|
15
15
|
Requires-Dist: litestar (>=2.15.1,<3.0.0)
|
@@ -4,10 +4,10 @@ sera/exports/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
4
|
sera/exports/schema.py,sha256=wEBUrDOyuCoCJC8X4RlmoWpeqSugaboG-9Q1UQ8HEzk,7824
|
5
5
|
sera/exports/test.py,sha256=jK1EJmLGiy7eREpnY_68IIVRH43uH8S_u5Z7STPbXOM,2002
|
6
6
|
sera/libs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
|
-
sera/libs/api_helper.py,sha256=
|
8
|
-
sera/libs/api_test_helper.py,sha256=
|
7
|
+
sera/libs/api_helper.py,sha256=SkdgZkoYlX6HCyD_D6EiBvE0dWH0QW40xh4opIy737M,3237
|
8
|
+
sera/libs/api_test_helper.py,sha256=SVGhl9UXPyCOw3IRK2znV6_c5tl1lTYYsb9qXJnJHoE,1344
|
9
9
|
sera/libs/base_orm.py,sha256=5hOH_diUeaABm3cpE2-9u50VRqG1QW2osPQnvVHIhIA,3365
|
10
|
-
sera/libs/base_service.py,sha256=
|
10
|
+
sera/libs/base_service.py,sha256=wJ1x0xrxjczRU6Y43EjQb7RlkZ0tAY58tFayDXWBzLs,10773
|
11
11
|
sera/libs/directed_computing_graph/__init__.py,sha256=xiF5_I1y9HtQ-cyq02iwkRYgEZvxBB8YIvysCHCLBco,1290
|
12
12
|
sera/libs/directed_computing_graph/_dcg.py,sha256=nQf9MhnTkFU2-dxhv_PFThz9L61Nn8cvYIOoMq0OVb8,15352
|
13
13
|
sera/libs/directed_computing_graph/_edge.py,sha256=iBq6cpLWWyuD99QWTHVEh8naWUJrR4WJJuq5iuCrwHo,1026
|
@@ -19,29 +19,34 @@ sera/libs/directed_computing_graph/_type_conversion.py,sha256=_XGvDidOJVmHS4gqdP
|
|
19
19
|
sera/libs/middlewares/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
20
20
|
sera/libs/middlewares/auth.py,sha256=r6aix1ZBwxMd1Jv5hMCTB8a_gFOJQ6egvxIrf3DWEOs,2323
|
21
21
|
sera/libs/middlewares/uscp.py,sha256=DRy99nmS3qS5HLjRMIGP0oNUtQIci_a4hL5xQh-lXNY,2322
|
22
|
+
sera/libs/search_helper.py,sha256=G7wig3K-mT0xWtn1lkG_YffZq8SzlBkot3H42HUz1sw,13675
|
22
23
|
sera/make/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
23
24
|
sera/make/__main__.py,sha256=HRfOR53p351h6KblVvYm3DLhDIfEtk6R0kjl78_S_S8,1453
|
24
|
-
sera/make/make_app.py,sha256=
|
25
|
-
sera/make/make_python_api.py,sha256=
|
26
|
-
sera/make/make_python_model.py,sha256=
|
27
|
-
sera/make/make_python_services.py,sha256=
|
28
|
-
sera/make/make_typescript_model.py,sha256=
|
29
|
-
sera/
|
25
|
+
sera/make/make_app.py,sha256=dTzpJRPGoCojCdJr1TAzwbaquctwwitrGPxkRm9skpo,6033
|
26
|
+
sera/make/make_python_api.py,sha256=sfaYnX6Vwj0xWPpvpWbBhq8GyNHgNkvwlyZr7NDCO0k,24770
|
27
|
+
sera/make/make_python_model.py,sha256=YHtZtHWN9X6s8IFiG-5w8sZSbsVWhU_sHtqVrkZkfgA,69686
|
28
|
+
sera/make/make_python_services.py,sha256=SvdU--QF23FN_d-Ao07CeXIK9d5eL_-mdXYwXx69dRE,2102
|
29
|
+
sera/make/make_typescript_model.py,sha256=Ax6xVrZ-x3xaKCsv6X4NKLdaMsAOau_GDrZK1TJ8NL8,57543
|
30
|
+
sera/make/ts_frontend/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
31
|
+
sera/make/ts_frontend/make_class_schema.py,sha256=FHTNQOJl-Zz6CHRT6J2GOZxpIeyMDqMRNTK9XUiM578,14489
|
32
|
+
sera/make/ts_frontend/make_enums.py,sha256=7FILT_RO5ZCByMlYorr3OaOqFGnVtG1y6jFJqFpk_XM,3110
|
33
|
+
sera/make/ts_frontend/misc.py,sha256=R96Tm4Sz05YPVk-gJ8vGW_GbMoUM7sLStar1LVnEn-I,1138
|
34
|
+
sera/misc/__init__.py,sha256=ee7OODdWPKP8pCDxsfg1EOdxxKFMJCoNMljgV0NCxBw,767
|
30
35
|
sera/misc/_formatter.py,sha256=aCGYL08l8f3aLODHxSocxBBwkRYEo3K1QzCDEn3suj0,1685
|
31
|
-
sera/misc/_utils.py,sha256=
|
36
|
+
sera/misc/_utils.py,sha256=_zWGjihxTEo3N1gzdxxB5CPCBBHxsviKWhQSCEonzVQ,13420
|
32
37
|
sera/models/__init__.py,sha256=vJC5Kzo_N7wd16ocNPy1VvAZDGNiWeiAhWJ4ihATKvA,780
|
33
|
-
sera/models/_class.py,sha256=
|
34
|
-
sera/models/_collection.py,sha256=
|
35
|
-
sera/models/_constraints.py,sha256=
|
36
|
-
sera/models/_datatype.py,sha256=
|
38
|
+
sera/models/_class.py,sha256=_jLbewobv0Q6KLNd_jH-Z8vnDfwkRBbhdJbRDtKyE6g,2865
|
39
|
+
sera/models/_collection.py,sha256=72ZBdVa3UE8UyghJ8V-BPimO0f68zFRJvXdzfNaKDMo,2874
|
40
|
+
sera/models/_constraints.py,sha256=SwUkvV8sESfuO3En6keA_r8GxKiarXYxMb5biml63lU,2021
|
41
|
+
sera/models/_datatype.py,sha256=OlCnQlEpB4w9doz0hPhaZk5d4sF664CdGznSBvx0X9g,10293
|
37
42
|
sera/models/_default.py,sha256=ABggW6qdPR4ZDqIPJdJ0GCGQ-7kfsfZmQ_DchgZEa-I,137
|
38
|
-
sera/models/_enum.py,sha256=
|
39
|
-
sera/models/_module.py,sha256=
|
43
|
+
sera/models/_enum.py,sha256=FRtEfto2httDB308W8OAuHh2LSazV3v16DHixlz1IZA,2088
|
44
|
+
sera/models/_module.py,sha256=r9_3nEbLaZKO-jvbZuFYy9DkM6E9jY8hBsBhQBULpVU,5428
|
40
45
|
sera/models/_multi_lingual_string.py,sha256=JETN6k00VH4wrA4w5vAHMEJV8fp3SY9bJebskFTjQLA,1186
|
41
|
-
sera/models/_parse.py,sha256=
|
46
|
+
sera/models/_parse.py,sha256=GL1a5HAlH4S389AyioLjz_9QFpH2rDTMOfXYXFC3fB4,12806
|
42
47
|
sera/models/_property.py,sha256=9yMDxrmbyuF6-29lQjiq163Xzwbk75TlmGBpu0NLpkI,7485
|
43
48
|
sera/models/_schema.py,sha256=VxJEiqgVvbXgcSUK4UW6JnRcggk4nsooVSE6MyXmfNY,1636
|
44
49
|
sera/typing.py,sha256=m4rir-fB6Cgcm7_ZSXXcNdla2LJgq96WXxtTTrDaJno,1058
|
45
|
-
sera_2-1.
|
46
|
-
sera_2-1.
|
47
|
-
sera_2-1.
|
50
|
+
sera_2-1.24.1.dist-info/METADATA,sha256=1DHbHN_a6VlNhVu8xrWJNig7IZCE2WzGvsRLGPnstGM,936
|
51
|
+
sera_2-1.24.1.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
52
|
+
sera_2-1.24.1.dist-info/RECORD,,
|
File without changes
|