Skip to content

Commit

Permalink
refactor: regen v1
Browse files Browse the repository at this point in the history
  • Loading branch information
doctrino committed Aug 15, 2024
1 parent aa674b8 commit 2eabd69
Show file tree
Hide file tree
Showing 73 changed files with 1,133 additions and 182 deletions.
36 changes: 18 additions & 18 deletions examples-pydantic-v1/equipment_unit_pydantic_v1/_api/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
DEFAULT_QUERY_LIMIT = 3
IN_FILTER_LIMIT = 5_000
INSTANCE_QUERY_LIMIT = 1_000
NODE_PROPERTIES = {"externalId", "space"}

Aggregations = Literal["avg", "count", "max", "min", "sum"]

Expand Down Expand Up @@ -139,7 +140,7 @@ def _search(
) -> T_DomainModelList:
properties_input = self._to_input_properties(properties)

sort_input = self._get_sort(sort_by, direction, sort)
sort_input = self._create_sort(sort_by, direction, sort)
nodes = self._client.data_modeling.instances.search(
view=self._view_id,
query=query,
Expand Down Expand Up @@ -263,7 +264,7 @@ def _list(
direction: Literal["ascending", "descending"] = "ascending",
sort: InstanceSort | list[InstanceSort] | None = None,
) -> T_DomainModelList:
sort_input = self._get_sort(sort_by, direction, sort)
sort_input = self._create_sort(sort_by, direction, sort)
nodes = self._client.data_modeling.instances.list(
instance_type="node",
sources=self._view_id,
Expand All @@ -277,37 +278,36 @@ def _list(

return node_list

def _get_sort(
def _create_sort(
self,
sort_by: str | list[str] | None = None,
direction: Literal["ascending", "descending"] = "ascending",
sort: InstanceSort | list[InstanceSort] | None = None,
) -> list[InstanceSort] | None:
sort_input: list[InstanceSort] | None = None
if sort is None and isinstance(sort_by, str):
sort_input = [
InstanceSort(self._view_id.as_property_ref(self._properties_by_field.get(sort_by, sort_by)), direction)
]
sort_input = [self._create_sort_entry(sort_by, direction)]
elif sort is None and isinstance(sort_by, list):
sort_input = [
InstanceSort(
self._view_id.as_property_ref(self._properties_by_field.get(sort_by_, sort_by_)), direction
)
for sort_by_ in sort_by
]
sort_input = [self._create_sort_entry(sort_by_, direction) for sort_by_ in sort_by]
elif sort is not None:
sort_input = sort if isinstance(sort, list) else [sort]
for sort_ in sort_input:
if isinstance(sort_.property, Sequence) and len(sort_.property) == 1:
sort_.property = self._view_id.as_property_ref(
self._properties_by_field.get(sort_.property[0], sort_.property[0])
)
sort_.property = self._create_property_reference(sort_.property[0])
elif isinstance(sort_.property, str):
sort_.property = self._view_id.as_property_ref(
self._properties_by_field.get(sort_.property, sort_.property)
)
sort_.property = self._create_property_reference(sort_.property)
return sort_input

def _create_sort_entry(self, sort_by: str, direction: Literal["ascending", "descending"]) -> InstanceSort:
return InstanceSort(self._create_property_reference(sort_by), direction)

def _create_property_reference(self, property_: str) -> list[str] | tuple[str, ...]:
prop_name = self._properties_by_field.get(property_, property_)
if prop_name in NODE_PROPERTIES:
return ["node", prop_name]
else:
return self._view_id.as_property_ref(prop_name)

def _retrieve_and_set_edge_types(
self,
nodes: T_DomainModelList, # type: ignore[misc]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ def list(
builder.create_name(None),
dm.query.NodeResultSetExpression(
filter=dm.filters.And(filter_, has_data) if filter_ else has_data,
sort=self._get_sort(sort_by, direction, sort), # type: ignore[arg-type]
sort=self._create_sort(sort_by, direction, sort), # type: ignore[arg-type]
),
UnitProcedure,
max_retrieve_limit=limit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
StartEndTimeFields,
StartEndTimeGraphQL,
StartEndTimeList,
StartEndTimeTextFields,
StartEndTimeWrite,
StartEndTimeWriteList,
)
Expand Down Expand Up @@ -126,6 +127,7 @@
"StartEndTimeWriteList",
"StartEndTimeApplyList",
"StartEndTimeFields",
"StartEndTimeTextFields",
"UnitProcedure",
"UnitProcedureGraphQL",
"UnitProcedureWrite",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@
]


EquipmentModuleTextFields = Literal["description", "name", "sensor_value", "type_"]
EquipmentModuleFields = Literal["description", "name", "sensor_value", "type_"]
EquipmentModuleTextFields = Literal["external_id", "description", "name", "sensor_value", "type_"]
EquipmentModuleFields = Literal["external_id", "description", "name", "sensor_value", "type_"]

_EQUIPMENTMODULE_PROPERTIES_BY_FIELD = {
"external_id": "externalId",
"description": "description",
"name": "name",
"sensor_value": "sensor_value",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@
]


StartEndTimeFields = Literal["end_time", "start_time"]
StartEndTimeTextFields = Literal["external_id",]
StartEndTimeFields = Literal["external_id", "end_time", "start_time"]
_STARTENDTIME_PROPERTIES_BY_FIELD = {
"external_id": "externalId",
"end_time": "end_time",
"start_time": "start_time",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@
]


UnitProcedureTextFields = Literal["name", "type_"]
UnitProcedureFields = Literal["name", "type_"]
UnitProcedureTextFields = Literal["external_id", "name", "type_"]
UnitProcedureFields = Literal["external_id", "name", "type_"]

_UNITPROCEDURE_PROPERTIES_BY_FIELD = {
"external_id": "externalId",
"name": "name",
"type_": "type",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@
]


WorkOrderTextFields = Literal["description", "performed_by", "type_"]
WorkOrderFields = Literal["description", "performed_by", "type_"]
WorkOrderTextFields = Literal["external_id", "description", "performed_by", "type_"]
WorkOrderFields = Literal["external_id", "description", "performed_by", "type_"]

_WORKORDER_PROPERTIES_BY_FIELD = {
"external_id": "externalId",
"description": "description",
"performed_by": "performedBy",
"type_": "type",
Expand Down
36 changes: 18 additions & 18 deletions examples-pydantic-v1/omni_multi_pydantic_v1/_api/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
DEFAULT_QUERY_LIMIT = 3
IN_FILTER_LIMIT = 5_000
INSTANCE_QUERY_LIMIT = 1_000
NODE_PROPERTIES = {"externalId", "space"}

Aggregations = Literal["avg", "count", "max", "min", "sum"]

Expand Down Expand Up @@ -139,7 +140,7 @@ def _search(
) -> T_DomainModelList:
properties_input = self._to_input_properties(properties)

sort_input = self._get_sort(sort_by, direction, sort)
sort_input = self._create_sort(sort_by, direction, sort)
nodes = self._client.data_modeling.instances.search(
view=self._view_id,
query=query,
Expand Down Expand Up @@ -263,7 +264,7 @@ def _list(
direction: Literal["ascending", "descending"] = "ascending",
sort: InstanceSort | list[InstanceSort] | None = None,
) -> T_DomainModelList:
sort_input = self._get_sort(sort_by, direction, sort)
sort_input = self._create_sort(sort_by, direction, sort)
nodes = self._client.data_modeling.instances.list(
instance_type="node",
sources=self._view_id,
Expand All @@ -277,37 +278,36 @@ def _list(

return node_list

def _get_sort(
def _create_sort(
self,
sort_by: str | list[str] | None = None,
direction: Literal["ascending", "descending"] = "ascending",
sort: InstanceSort | list[InstanceSort] | None = None,
) -> list[InstanceSort] | None:
sort_input: list[InstanceSort] | None = None
if sort is None and isinstance(sort_by, str):
sort_input = [
InstanceSort(self._view_id.as_property_ref(self._properties_by_field.get(sort_by, sort_by)), direction)
]
sort_input = [self._create_sort_entry(sort_by, direction)]
elif sort is None and isinstance(sort_by, list):
sort_input = [
InstanceSort(
self._view_id.as_property_ref(self._properties_by_field.get(sort_by_, sort_by_)), direction
)
for sort_by_ in sort_by
]
sort_input = [self._create_sort_entry(sort_by_, direction) for sort_by_ in sort_by]
elif sort is not None:
sort_input = sort if isinstance(sort, list) else [sort]
for sort_ in sort_input:
if isinstance(sort_.property, Sequence) and len(sort_.property) == 1:
sort_.property = self._view_id.as_property_ref(
self._properties_by_field.get(sort_.property[0], sort_.property[0])
)
sort_.property = self._create_property_reference(sort_.property[0])
elif isinstance(sort_.property, str):
sort_.property = self._view_id.as_property_ref(
self._properties_by_field.get(sort_.property, sort_.property)
)
sort_.property = self._create_property_reference(sort_.property)
return sort_input

def _create_sort_entry(self, sort_by: str, direction: Literal["ascending", "descending"]) -> InstanceSort:
return InstanceSort(self._create_property_reference(sort_by), direction)

def _create_property_reference(self, property_: str) -> list[str] | tuple[str, ...]:
prop_name = self._properties_by_field.get(property_, property_)
if prop_name in NODE_PROPERTIES:
return ["node", prop_name]
else:
return self._view_id.as_property_ref(prop_name)

def _retrieve_and_set_edge_types(
self,
nodes: T_DomainModelList, # type: ignore[misc]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@
]


Implementation1v1TextFields = Literal["main_value", "value_1", "value_2"]
Implementation1v1Fields = Literal["main_value", "value_1", "value_2"]
Implementation1v1TextFields = Literal["external_id", "main_value", "value_1", "value_2"]
Implementation1v1Fields = Literal["external_id", "main_value", "value_1", "value_2"]

_IMPLEMENTATION1V1_PROPERTIES_BY_FIELD = {
"external_id": "externalId",
"main_value": "mainValue",
"value_1": "value1",
"value_2": "value2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@
]


Implementation1v2TextFields = Literal["main_value", "sub_value", "value_2"]
Implementation1v2Fields = Literal["main_value", "sub_value", "value_2"]
Implementation1v2TextFields = Literal["external_id", "main_value", "sub_value", "value_2"]
Implementation1v2Fields = Literal["external_id", "main_value", "sub_value", "value_2"]

_IMPLEMENTATION1V2_PROPERTIES_BY_FIELD = {
"external_id": "externalId",
"main_value": "mainValue",
"sub_value": "subValue",
"value_2": "value2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@
]


MainInterfaceTextFields = Literal["main_value"]
MainInterfaceFields = Literal["main_value"]
MainInterfaceTextFields = Literal["external_id", "main_value"]
MainInterfaceFields = Literal["external_id", "main_value"]

_MAININTERFACE_PROPERTIES_BY_FIELD = {
"external_id": "externalId",
"main_value": "mainValue",
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@
]


SubInterfaceTextFields = Literal["main_value", "sub_value"]
SubInterfaceFields = Literal["main_value", "sub_value"]
SubInterfaceTextFields = Literal["external_id", "main_value", "sub_value"]
SubInterfaceFields = Literal["external_id", "main_value", "sub_value"]

_SUBINTERFACE_PROPERTIES_BY_FIELD = {
"external_id": "externalId",
"main_value": "mainValue",
"sub_value": "subValue",
}
Expand Down
36 changes: 18 additions & 18 deletions examples-pydantic-v1/omni_pydantic_v1/_api/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
DEFAULT_QUERY_LIMIT = 3
IN_FILTER_LIMIT = 5_000
INSTANCE_QUERY_LIMIT = 1_000
NODE_PROPERTIES = {"externalId", "space"}

Aggregations = Literal["avg", "count", "max", "min", "sum"]

Expand Down Expand Up @@ -139,7 +140,7 @@ def _search(
) -> T_DomainModelList:
properties_input = self._to_input_properties(properties)

sort_input = self._get_sort(sort_by, direction, sort)
sort_input = self._create_sort(sort_by, direction, sort)
nodes = self._client.data_modeling.instances.search(
view=self._view_id,
query=query,
Expand Down Expand Up @@ -263,7 +264,7 @@ def _list(
direction: Literal["ascending", "descending"] = "ascending",
sort: InstanceSort | list[InstanceSort] | None = None,
) -> T_DomainModelList:
sort_input = self._get_sort(sort_by, direction, sort)
sort_input = self._create_sort(sort_by, direction, sort)
nodes = self._client.data_modeling.instances.list(
instance_type="node",
sources=self._view_id,
Expand All @@ -277,37 +278,36 @@ def _list(

return node_list

def _get_sort(
def _create_sort(
self,
sort_by: str | list[str] | None = None,
direction: Literal["ascending", "descending"] = "ascending",
sort: InstanceSort | list[InstanceSort] | None = None,
) -> list[InstanceSort] | None:
sort_input: list[InstanceSort] | None = None
if sort is None and isinstance(sort_by, str):
sort_input = [
InstanceSort(self._view_id.as_property_ref(self._properties_by_field.get(sort_by, sort_by)), direction)
]
sort_input = [self._create_sort_entry(sort_by, direction)]
elif sort is None and isinstance(sort_by, list):
sort_input = [
InstanceSort(
self._view_id.as_property_ref(self._properties_by_field.get(sort_by_, sort_by_)), direction
)
for sort_by_ in sort_by
]
sort_input = [self._create_sort_entry(sort_by_, direction) for sort_by_ in sort_by]
elif sort is not None:
sort_input = sort if isinstance(sort, list) else [sort]
for sort_ in sort_input:
if isinstance(sort_.property, Sequence) and len(sort_.property) == 1:
sort_.property = self._view_id.as_property_ref(
self._properties_by_field.get(sort_.property[0], sort_.property[0])
)
sort_.property = self._create_property_reference(sort_.property[0])
elif isinstance(sort_.property, str):
sort_.property = self._view_id.as_property_ref(
self._properties_by_field.get(sort_.property, sort_.property)
)
sort_.property = self._create_property_reference(sort_.property)
return sort_input

def _create_sort_entry(self, sort_by: str, direction: Literal["ascending", "descending"]) -> InstanceSort:
return InstanceSort(self._create_property_reference(sort_by), direction)

def _create_property_reference(self, property_: str) -> list[str] | tuple[str, ...]:
prop_name = self._properties_by_field.get(property_, property_)
if prop_name in NODE_PROPERTIES:
return ["node", prop_name]
else:
return self._view_id.as_property_ref(prop_name)

def _retrieve_and_set_edge_types(
self,
nodes: T_DomainModelList, # type: ignore[misc]
Expand Down
Loading

0 comments on commit 2eabd69

Please sign in to comment.