sera-2 1.26.3__py3-none-any.whl → 1.26.5__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/make/make_typescript_model.py +4 -858
- sera/make/ts_frontend/make_class_schema.py +0 -1
- sera/make/ts_frontend/make_draft_model.py +811 -0
- sera/make/ts_frontend/make_query.py +33 -15
- sera/models/_datatype.py +16 -0
- sera/models/_parse.py +9 -1
- {sera_2-1.26.3.dist-info → sera_2-1.26.5.dist-info}/METADATA +3 -3
- {sera_2-1.26.3.dist-info → sera_2-1.26.5.dist-info}/RECORD +9 -8
- {sera_2-1.26.3.dist-info → sera_2-1.26.5.dist-info}/WHEEL +1 -1
@@ -96,29 +96,47 @@ def make_query(schema: Schema, cls: Class, pkg: Package):
|
|
96
96
|
for dep in tstype.deps:
|
97
97
|
program.import_(dep, is_import_attr=True)
|
98
98
|
|
99
|
+
query_ops = []
|
100
|
+
|
99
101
|
if tstype.type == "string":
|
100
|
-
|
101
|
-
elif tstype.type
|
102
|
-
|
102
|
+
query_ops.append(('"fuzzy"', tstype.type))
|
103
|
+
elif tstype.type == "number":
|
104
|
+
if (
|
105
|
+
isinstance(prop, DataProperty)
|
106
|
+
and prop.db is not None
|
107
|
+
and prop.db.is_primary_key
|
108
|
+
) or (isinstance(prop, ObjectProperty) and prop.target.db is not None):
|
109
|
+
# primary key or foreign key, we only support a limited set of operations
|
110
|
+
query_ops.append(('"eq" | "ne"', tstype.type))
|
111
|
+
else:
|
112
|
+
query_ops.append(
|
113
|
+
('"eq" | "ne" | "lt" | "lte" | "gt" | "gte"', tstype.type)
|
114
|
+
)
|
115
|
+
query_ops.append(('"bti"', "[number, number]"))
|
103
116
|
elif tstype.is_enum_type():
|
104
|
-
|
117
|
+
query_ops.append(('"eq" | "ne"', tstype.type))
|
118
|
+
elif tstype.type == "Date":
|
119
|
+
# for date type, we use iso string as the value
|
120
|
+
query_ops.append(('"lte" | "gte"', "string"))
|
121
|
+
query_ops.append(('"bti"', "[string, string]"))
|
105
122
|
else:
|
106
123
|
raise NotImplementedError(tstype.type)
|
107
124
|
|
108
|
-
if tstype.type == "Date":
|
109
|
-
# for date type, we use timestamp (number) for comparison
|
110
|
-
value = "number"
|
111
|
-
else:
|
112
|
-
value = tstype.type
|
113
|
-
|
114
125
|
query_condition_args.append(
|
115
126
|
(
|
116
127
|
expr.ExprIdent(tspropname + "?"),
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
128
|
+
expr.ExprRawTypescript(
|
129
|
+
" | ".join(
|
130
|
+
[
|
131
|
+
PredefinedFn.dict(
|
132
|
+
[
|
133
|
+
(expr.ExprIdent("op"), expr.ExprIdent(op)),
|
134
|
+
(expr.ExprIdent("value"), expr.ExprIdent(value)),
|
135
|
+
]
|
136
|
+
).to_typescript()
|
137
|
+
for op, value in query_ops
|
138
|
+
]
|
139
|
+
)
|
122
140
|
),
|
123
141
|
)
|
124
142
|
)
|
sera/models/_datatype.py
CHANGED
@@ -287,6 +287,22 @@ predefined_datatypes = {
|
|
287
287
|
tstype=TsTypeWithDep(type="string", spectype="dict"),
|
288
288
|
is_list=False,
|
289
289
|
),
|
290
|
+
"str2str": DataType(
|
291
|
+
pytype=PyTypeWithDep(type="dict[str, str]"),
|
292
|
+
sqltype=SQLTypeWithDep(
|
293
|
+
type="JSON", mapped_pytype="dict[str, str]", deps=["sqlalchemy.JSON"]
|
294
|
+
),
|
295
|
+
tstype=TsTypeWithDep(type="Record<string, string>", spectype="str2str"),
|
296
|
+
is_list=False,
|
297
|
+
),
|
298
|
+
"str2int": DataType(
|
299
|
+
pytype=PyTypeWithDep(type="dict[str, int]"),
|
300
|
+
sqltype=SQLTypeWithDep(
|
301
|
+
type="JSON", mapped_pytype="dict[str, int]", deps=["sqlalchemy.JSON"]
|
302
|
+
),
|
303
|
+
tstype=TsTypeWithDep(type="Record<string, number>", spectype="str2int"),
|
304
|
+
is_list=False,
|
305
|
+
),
|
290
306
|
}
|
291
307
|
|
292
308
|
predefined_py_datatypes = {"bytes": PyTypeWithDep(type="bytes")}
|
sera/models/_parse.py
CHANGED
@@ -275,6 +275,14 @@ def _parse_datatype(schema: Schema, datatype: dict | str) -> DataType:
|
|
275
275
|
if isinstance(datatype, dict):
|
276
276
|
is_list = datatype.get("is_list", False)
|
277
277
|
|
278
|
+
# Parse Python type and argument if present
|
279
|
+
if datatype["pytype"] in predefined_py_datatypes:
|
280
|
+
py_type = predefined_py_datatypes[datatype["pytype"]]
|
281
|
+
else:
|
282
|
+
py_type = PyTypeWithDep(
|
283
|
+
type=datatype["pytype"]["type"], deps=datatype["pytype"].get("deps", [])
|
284
|
+
)
|
285
|
+
|
278
286
|
# Parse SQL type and argument if present
|
279
287
|
m = re.match(r"^([a-zA-Z0-9_]+)(\([^)]+\))?$", datatype["sqltype"])
|
280
288
|
if m is not None:
|
@@ -291,7 +299,7 @@ def _parse_datatype(schema: Schema, datatype: dict | str) -> DataType:
|
|
291
299
|
raise ValueError(f"Invalid SQL type format: {datatype['sqltype']}")
|
292
300
|
|
293
301
|
return DataType(
|
294
|
-
pytype=
|
302
|
+
pytype=py_type,
|
295
303
|
sqltype=sql_type,
|
296
304
|
tstype=predefined_ts_datatypes[datatype["tstype"]],
|
297
305
|
is_list=is_list,
|
@@ -1,14 +1,14 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: sera-2
|
3
|
-
Version: 1.26.
|
3
|
+
Version: 1.26.5
|
4
4
|
Summary:
|
5
|
-
Home-page: https://github.com/binh-vu/sera
|
6
5
|
Author: Binh Vu
|
7
6
|
Author-email: bvu687@gmail.com
|
8
7
|
Requires-Python: >=3.12,<4.0
|
9
8
|
Classifier: Programming Language :: Python :: 3
|
10
9
|
Classifier: Programming Language :: Python :: 3.12
|
11
10
|
Classifier: Programming Language :: Python :: 3.13
|
11
|
+
Classifier: Programming Language :: Python :: 3.14
|
12
12
|
Requires-Dist: black (==25.1.0)
|
13
13
|
Requires-Dist: codegen-2 (>=2.15.1,<3.0.0)
|
14
14
|
Requires-Dist: graph-wrapper (>=1.7.3,<2.0.0)
|
@@ -26,13 +26,14 @@ sera/make/make_app.py,sha256=dTzpJRPGoCojCdJr1TAzwbaquctwwitrGPxkRm9skpo,6033
|
|
26
26
|
sera/make/make_python_api.py,sha256=sfaYnX6Vwj0xWPpvpWbBhq8GyNHgNkvwlyZr7NDCO0k,24770
|
27
27
|
sera/make/make_python_model.py,sha256=cW3RGVttuZWLVWrEg-NppSknWoTKCRE2mar9yyhj-gU,72545
|
28
28
|
sera/make/make_python_services.py,sha256=SvdU--QF23FN_d-Ao07CeXIK9d5eL_-mdXYwXx69dRE,2102
|
29
|
-
sera/make/make_typescript_model.py,sha256=
|
29
|
+
sera/make/make_typescript_model.py,sha256=bhvYbQKST1DT0pnkNOpwcmsaeVnUcNfVvHxUq2LAoo4,17604
|
30
30
|
sera/make/py_backend/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
31
31
|
sera/make/py_backend/misc.py,sha256=lZNkrniR2OZiyK4rei1Yl_mRYBR_QzOpqVO_gMWbJD4,487
|
32
32
|
sera/make/ts_frontend/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
33
|
-
sera/make/ts_frontend/make_class_schema.py,sha256=
|
33
|
+
sera/make/ts_frontend/make_class_schema.py,sha256=JrUNBl5yJSbVFrdGcuC7sG0A-HhmXl24VJWCTVkDh8I,14458
|
34
|
+
sera/make/ts_frontend/make_draft_model.py,sha256=LY1HP6BuEmtxEevqAWMe-GJyTbK-yDIsUjLjZdd-0Rg,32570
|
34
35
|
sera/make/ts_frontend/make_enums.py,sha256=3U6Dt5Y4DM6D_ZiitcVHXtNQyA9cTE046WCDQCDOvSU,2596
|
35
|
-
sera/make/ts_frontend/make_query.py,sha256=
|
36
|
+
sera/make/ts_frontend/make_query.py,sha256=ZpNhVEQn59xk16kMmM6HcwKy_9WpvdeFx0h1xCoCbeA,5703
|
36
37
|
sera/make/ts_frontend/misc.py,sha256=A54nMg4dsn1AC_6T1tFRW3rZAJ71d7SHEMrFOdsI3jo,1011
|
37
38
|
sera/misc/__init__.py,sha256=ee7OODdWPKP8pCDxsfg1EOdxxKFMJCoNMljgV0NCxBw,767
|
38
39
|
sera/misc/_formatter.py,sha256=aCGYL08l8f3aLODHxSocxBBwkRYEo3K1QzCDEn3suj0,1685
|
@@ -41,15 +42,15 @@ sera/models/__init__.py,sha256=ZCnwzgUXhmHEcx5a7nYLopsBXJmSnfSkjt4kUH_vPnM,833
|
|
41
42
|
sera/models/_class.py,sha256=495nP6j4pZIX1j0ZElUHNxe9doUX7vzSIwVrp_lAOHE,2922
|
42
43
|
sera/models/_collection.py,sha256=5VsjmPMlZW-fYvcoYWOKD7Ch34zBYe4EPsjAn6bX7BY,2962
|
43
44
|
sera/models/_constraints.py,sha256=SwUkvV8sESfuO3En6keA_r8GxKiarXYxMb5biml63lU,2021
|
44
|
-
sera/models/_datatype.py,sha256=
|
45
|
+
sera/models/_datatype.py,sha256=0tut54rLErfzx0--S4Plf_YPsu0jKiFSSXHY1acOgU8,10921
|
45
46
|
sera/models/_default.py,sha256=ABggW6qdPR4ZDqIPJdJ0GCGQ-7kfsfZmQ_DchgZEa-I,137
|
46
47
|
sera/models/_enum.py,sha256=FRtEfto2httDB308W8OAuHh2LSazV3v16DHixlz1IZA,2088
|
47
48
|
sera/models/_module.py,sha256=0jWfzb5iMF4IazeOKd_m9hWe7-xIsz7xlWF6mbdnHxw,5394
|
48
49
|
sera/models/_multi_lingual_string.py,sha256=JETN6k00VH4wrA4w5vAHMEJV8fp3SY9bJebskFTjQLA,1186
|
49
|
-
sera/models/_parse.py,sha256=
|
50
|
+
sera/models/_parse.py,sha256=ft5RbsBqkxxKcMOU6Bn_70ai0Lpo4FK2Shdmt4BjX-Q,13498
|
50
51
|
sera/models/_property.py,sha256=Qo23KZl5OQNbuceygicgC3_Yv5ve1KxiFiMoWq6Ljj0,7758
|
51
52
|
sera/models/_schema.py,sha256=VxJEiqgVvbXgcSUK4UW6JnRcggk4nsooVSE6MyXmfNY,1636
|
52
53
|
sera/typing.py,sha256=7S6Ah-Yfcl8a0xAJ4lxEcguq3rYVM7SBeOiuxyJhC04,1089
|
53
|
-
sera_2-1.26.
|
54
|
-
sera_2-1.26.
|
55
|
-
sera_2-1.26.
|
54
|
+
sera_2-1.26.5.dist-info/METADATA,sha256=5gvMEmoiQVFWW9BlLdaDy9YP-gMSAl8DwL02QYGaSI0,987
|
55
|
+
sera_2-1.26.5.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
56
|
+
sera_2-1.26.5.dist-info/RECORD,,
|