OpenGeodeWeb-Microservice 1.2.2__py3-none-any.whl → 1.3.0__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.
@@ -12,6 +12,7 @@ class Data(Base):
12
12
  id: Mapped[str] = mapped_column(
13
13
  String, primary_key=True, default=lambda: str(uuid.uuid4()).replace("-", "")
14
14
  )
15
+ geode_id: Mapped[str] = mapped_column(String, nullable=False)
15
16
  geode_object: Mapped[GeodeObjectType] = mapped_column(String, nullable=False)
16
17
  viewer_object: Mapped[ViewerType] = mapped_column(String, nullable=False)
17
18
  viewer_elements_type: Mapped[ViewerElementsType] = mapped_column(
@@ -23,11 +24,13 @@ class Data(Base):
23
24
 
24
25
  @staticmethod
25
26
  def create(
27
+ geode_id: str,
26
28
  geode_object: GeodeObjectType,
27
29
  viewer_object: ViewerType,
28
30
  viewer_elements_type: ViewerElementsType,
29
31
  ) -> "Data":
30
32
  data_entry = Data(
33
+ geode_id=geode_id,
31
34
  geode_object=geode_object,
32
35
  viewer_object=viewer_object,
33
36
  viewer_elements_type=viewer_elements_type,
@@ -0,0 +1,20 @@
1
+ {
2
+ "type": "object",
3
+ "properties": {
4
+ "code": {
5
+ "type": "integer"
6
+ },
7
+ "name": {
8
+ "type": "string"
9
+ },
10
+ "description": {
11
+ "type": "string"
12
+ }
13
+ },
14
+ "required": [
15
+ "code",
16
+ "name",
17
+ "description"
18
+ ],
19
+ "additionalProperties": false
20
+ }
@@ -1,9 +1,47 @@
1
1
  import os
2
2
  import glob
3
3
  import json
4
+ import dataclasses
5
+ from dataclasses import dataclass
6
+ from typing import Any, Generic, TypeVar
7
+
8
+ from dataclasses_json import DataClassJsonMixin
4
9
 
5
10
  type SchemaDict = dict[str, str]
6
11
 
12
+ ERROR_SCHEMA_PATH = os.path.join(os.path.dirname(__file__), "error.json")
13
+
14
+ ParamsT = TypeVar("ParamsT", bound=DataClassJsonMixin)
15
+ ResponseT = TypeVar("ResponseT", bound=DataClassJsonMixin)
16
+
17
+
18
+ MAX_VALUE_LENGTH = 80
19
+
20
+
21
+ def _format_value(value: Any, max_length: int) -> str:
22
+ if dataclasses.is_dataclass(value) and not isinstance(value, type):
23
+ return format_dataclass(value, max_length)
24
+ text = repr(value)
25
+ if len(text) <= max_length:
26
+ return text
27
+ details = type(value).__name__
28
+ if hasattr(value, "__len__"):
29
+ details += f", len={len(value)}"
30
+ return f"{text[:max_length]}... ({details})"
31
+
32
+
33
+ def format_dataclass(instance: Any, max_length: int = MAX_VALUE_LENGTH) -> str:
34
+ """Like repr(), but every field value longer than max_length is truncated and followed by its type and length."""
35
+ fields = ", ".join(
36
+ f"{field.name}={_format_value(getattr(instance, field.name), max_length)}"
37
+ for field in dataclasses.fields(instance)
38
+ )
39
+ return f"{type(instance).__name__}({fields})"
40
+
41
+
42
+ def print_dataclass(instance: Any) -> None:
43
+ print(format_dataclass(instance), flush=True)
44
+
7
45
 
8
46
  def get_schemas_dict(path: str) -> dict[str, SchemaDict]:
9
47
  schemas_dict: dict[str, SchemaDict] = {}
@@ -13,3 +51,34 @@ def get_schemas_dict(path: str) -> dict[str, SchemaDict]:
13
51
  file_content = json.load(file)
14
52
  schemas_dict[os.path.splitext(filename)[0]] = file_content
15
53
  return schemas_dict
54
+
55
+
56
+ def load_schema(python_file: str) -> dict[str, Any]:
57
+ """Load the JSON route schema sitting next to a generated schema module."""
58
+ json_file = os.path.splitext(python_file)[0] + ".json"
59
+ with open(json_file, "r") as file:
60
+ schema: dict[str, Any] = json.load(file)
61
+ return schema
62
+
63
+
64
+ @dataclass(frozen=True)
65
+ class Route(Generic[ParamsT, ResponseT]):
66
+ """Generated binding between a route schema, its request params and its success response."""
67
+
68
+ schema: dict[str, Any]
69
+ params: type[ParamsT]
70
+ response: type[ResponseT]
71
+
72
+
73
+ @dataclass
74
+ class BinaryResponse(DataClassJsonMixin):
75
+ """Response of a route streaming a file (schema `"response": {"format": "binary"}`) instead of JSON."""
76
+
77
+
78
+ @dataclass
79
+ class ErrorResponse(DataClassJsonMixin):
80
+ """Body of every 4xx/5xx response, matches error.json."""
81
+
82
+ code: int
83
+ name: str
84
+ description: str
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: OpenGeodeWeb-Microservice
3
- Version: 1.2.2
3
+ Version: 1.3.0
4
4
  Summary: Database model and ORM layer for OpenGeodeWeb ecosystem
5
5
  Author-email: Geode-solutions <team-web@geode-solutions.com>
6
6
  Project-URL: Homepage, https://github.com/Geode-solutions/OpenGeodeWeb-Microservice
@@ -13,13 +13,13 @@ Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
14
  Requires-Dist: dataclasses-json==0.6.7
15
15
  Requires-Dist: fastjsonschema==2.21.1
16
- Requires-Dist: greenlet==3.*,>=3.5.5
17
- Requires-Dist: marshmallow==3.*,>=3.26.2
18
- Requires-Dist: mypy-extensions==1.*,>=1.1.0
19
- Requires-Dist: packaging==26.*,>=26.3
16
+ Requires-Dist: greenlet==3.*
17
+ Requires-Dist: marshmallow==3.*
18
+ Requires-Dist: mypy-extensions==1.*
19
+ Requires-Dist: packaging==26.*
20
20
  Requires-Dist: sqlalchemy==2.0.43
21
- Requires-Dist: typing-extensions==4.*,>=4.16.0
22
- Requires-Dist: typing-inspect==0.*,>=0.9.0
21
+ Requires-Dist: typing-extensions==4.*
22
+ Requires-Dist: typing-inspect==0.*
23
23
  Dynamic: license-file
24
24
 
25
25
  <h1 align="center">OpenGeodeWeb-Microservice<sup><i>by Geode-solutions</i></sup></h1>
@@ -1,13 +1,14 @@
1
1
  opengeodeweb_microservice/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ opengeodeweb_microservice/error.json,sha256=Mz0u8RMoDkv-5q2mvzUtuoTCngOSR6eH_ZWJLY330tI,281
2
3
  opengeodeweb_microservice/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- opengeodeweb_microservice/schemas.py,sha256=Zq7p8CkWcOGaSkAOUoucQe_W_INyfZ416l_NU8b8_CA,483
4
+ opengeodeweb_microservice/schemas.py,sha256=W2v5PtJMHhD9TeU4-LMPYlI0j_SUQwaYFiJLVn2lYUk,2641
4
5
  opengeodeweb_microservice/database/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
6
  opengeodeweb_microservice/database/base.py,sha256=mH7f2d_jiyxJSSx9Gk53QBXRa3LiKBsBjkFgvmtH1WA,83
6
7
  opengeodeweb_microservice/database/connection.py,sha256=GZP50_yMAifFnlwKdCXB6iPU-o6Z2Ke984tF8LPM77I,1292
7
- opengeodeweb_microservice/database/data.py,sha256=B9QZaSaFu4z78lPdDnzuWYU_oWy3_VXD3IljdsSOl1k,1584
8
+ opengeodeweb_microservice/database/data.py,sha256=Yttmtl2b8-kjZvTbOUhgvLWZZNv1RQCGHj8Bv0fbw74,1704
8
9
  opengeodeweb_microservice/database/data_types.py,sha256=unPm-prGAG6_bgCgp0vN3h5vvNgxZFytNB_8irJD2gU,1736
9
- opengeodeweb_microservice-1.2.2.dist-info/licenses/LICENSE,sha256=-NzXOhbKabayTVZGCj8Mas4F4U4FIx4BgP4kPN4CpCI,1072
10
- opengeodeweb_microservice-1.2.2.dist-info/METADATA,sha256=Q8sAhN7Y1HEL7KeDdmPirdKQPBTTV3ljpIBTetmFUDI,2341
11
- opengeodeweb_microservice-1.2.2.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
12
- opengeodeweb_microservice-1.2.2.dist-info/top_level.txt,sha256=a7XQPbBy64ZIhR5FQIPlPSJZdfHDYcP2vX9zA6VGFd4,26
13
- opengeodeweb_microservice-1.2.2.dist-info/RECORD,,
10
+ opengeodeweb_microservice-1.3.0.dist-info/licenses/LICENSE,sha256=-NzXOhbKabayTVZGCj8Mas4F4U4FIx4BgP4kPN4CpCI,1072
11
+ opengeodeweb_microservice-1.3.0.dist-info/METADATA,sha256=3sOBwDAcX0_zkt0AMqCgc00_Adn6b4AAVRJRBhR4yGw,2292
12
+ opengeodeweb_microservice-1.3.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
13
+ opengeodeweb_microservice-1.3.0.dist-info/top_level.txt,sha256=a7XQPbBy64ZIhR5FQIPlPSJZdfHDYcP2vX9zA6VGFd4,26
14
+ opengeodeweb_microservice-1.3.0.dist-info/RECORD,,