industrial-model 0.1.30__tar.gz → 0.1.31__tar.gz

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.
Files changed (34) hide show
  1. {industrial_model-0.1.30 → industrial_model-0.1.31}/PKG-INFO +1 -1
  2. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/cognite_adapters/query_result_mapper.py +34 -8
  3. {industrial_model-0.1.30 → industrial_model-0.1.31}/pyproject.toml +1 -1
  4. {industrial_model-0.1.30 → industrial_model-0.1.31}/.gitignore +0 -0
  5. {industrial_model-0.1.30 → industrial_model-0.1.31}/README.md +0 -0
  6. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/__init__.py +0 -0
  7. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/cognite_adapters/__init__.py +0 -0
  8. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/cognite_adapters/aggregation_mapper.py +0 -0
  9. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/cognite_adapters/filter_mapper.py +0 -0
  10. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/cognite_adapters/models.py +0 -0
  11. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/cognite_adapters/optimizer.py +0 -0
  12. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/cognite_adapters/query_mapper.py +0 -0
  13. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/cognite_adapters/search_mapper.py +0 -0
  14. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/cognite_adapters/sort_mapper.py +0 -0
  15. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/cognite_adapters/upsert_mapper.py +0 -0
  16. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/cognite_adapters/utils.py +0 -0
  17. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/cognite_adapters/view_mapper.py +0 -0
  18. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/config.py +0 -0
  19. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/constants.py +0 -0
  20. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/engines/__init__.py +0 -0
  21. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/engines/async_engine.py +0 -0
  22. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/engines/engine.py +0 -0
  23. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/models/__init__.py +0 -0
  24. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/models/base.py +0 -0
  25. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/models/entities.py +0 -0
  26. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/models/schemas.py +0 -0
  27. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/py.typed +0 -0
  28. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/queries/__init__.py +0 -0
  29. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/queries/models.py +0 -0
  30. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/queries/params.py +0 -0
  31. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/queries/utils.py +0 -0
  32. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/statements/__init__.py +0 -0
  33. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/statements/expressions.py +0 -0
  34. {industrial_model-0.1.30 → industrial_model-0.1.31}/industrial_model/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: industrial-model
3
- Version: 0.1.30
3
+ Version: 0.1.31
4
4
  Summary: Industrial Model ORM
5
5
  Author-email: Lucas Alves <lucasrosaalves@gmail.com>
6
6
  Classifier: Programming Language :: Python
@@ -10,6 +10,10 @@ from cognite.client.data_classes.data_modeling import (
10
10
  NodeList,
11
11
  View,
12
12
  )
13
+ from cognite.client.data_classes.data_modeling.data_types import (
14
+ ListablePropertyType,
15
+ )
16
+ from cognite.client.data_classes.data_modeling.instances import PropertyValue
13
17
  from cognite.client.data_classes.data_modeling.views import (
14
18
  MultiReverseDirectRelation,
15
19
  SingleReverseDirectRelation,
@@ -112,13 +116,13 @@ class QueryResultMapper:
112
116
  ):
113
117
  continue
114
118
 
115
- element_key: tuple[str, str] = (
116
- (element.get("space", ""), element.get("externalId", ""))
117
- if isinstance(element, dict)
118
- else (node.space, node.external_id)
119
- )
119
+ element_keys = self._get_element_keys(node, element)
120
120
 
121
- node_entries = mapping_nodes.get(element_key)
121
+ node_entries = [
122
+ item
123
+ for element_key in element_keys
124
+ for item in mapping_nodes.get(element_key, [])
125
+ ]
122
126
  if not node_entries:
123
127
  if mapping_key in properties:
124
128
  properties.pop(mapping_key)
@@ -126,7 +130,11 @@ class QueryResultMapper:
126
130
 
127
131
  entry_data = self.nodes_to_dict(node_entries)
128
132
  properties[mapping_key] = entry_data if is_list else entry_data[0]
129
- edge_entries = mapping_edges.get(element_key)
133
+ edge_entries = [
134
+ item
135
+ for element_key in element_keys
136
+ for item in mapping_edges.get(element_key, [])
137
+ ]
130
138
  if edge_entries:
131
139
  edges_mapping[mapping_key] = self._edges_to_model(edge_entries)
132
140
  properties["_edges"] = edges_mapping
@@ -137,6 +145,21 @@ class QueryResultMapper:
137
145
 
138
146
  return dict(result)
139
147
 
148
+ def _get_element_keys(
149
+ self, node: Node, element: PropertyValue | None
150
+ ) -> list[tuple[str, str]]:
151
+ if isinstance(element, dict):
152
+ return [(element.get("space", ""), element.get("externalId", ""))]
153
+
154
+ if isinstance(element, list):
155
+ return [
156
+ (item.get("space", ""), item.get("externalId", ""))
157
+ for item in element
158
+ if isinstance(item, dict)
159
+ ]
160
+
161
+ return [(node.space, node.external_id)]
162
+
140
163
  def _get_property_mappings(
141
164
  self,
142
165
  key: str,
@@ -159,7 +182,10 @@ class QueryResultMapper:
159
182
  self._view_mapper.get_view(property.source.external_id),
160
183
  query_result,
161
184
  )
162
- is_list = False
185
+ is_list = (
186
+ isinstance(property.type, ListablePropertyType)
187
+ and property.type.is_list
188
+ )
163
189
  connection_type = ConnectionTypeEnum.DIRECT_RELATION
164
190
  elif isinstance(property, SingleReverseDirectRelation) and property.source:
165
191
  nodes = self._map_node_property(
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "industrial-model"
3
- version = "0.1.30"
3
+ version = "0.1.31"
4
4
  description = "Industrial Model ORM"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"