cognite-toolkit 0.7.39__py3-none-any.whl → 0.7.51__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.
- cognite_toolkit/_cdf_tk/apps/_download_app.py +1 -1
- cognite_toolkit/_cdf_tk/apps/_dump_app.py +1 -1
- cognite_toolkit/_cdf_tk/apps/_migrate_app.py +6 -6
- cognite_toolkit/_cdf_tk/builders/_function.py +81 -9
- cognite_toolkit/_cdf_tk/builders/_raw.py +1 -1
- cognite_toolkit/_cdf_tk/client/_resource_base.py +187 -0
- cognite_toolkit/_cdf_tk/client/_toolkit_client.py +37 -5
- cognite_toolkit/_cdf_tk/client/api/agents.py +107 -0
- cognite_toolkit/_cdf_tk/client/api/annotations.py +129 -0
- cognite_toolkit/_cdf_tk/client/api/assets.py +130 -0
- cognite_toolkit/_cdf_tk/client/api/containers.py +132 -0
- cognite_toolkit/_cdf_tk/client/api/data_models.py +137 -0
- cognite_toolkit/_cdf_tk/client/api/datasets.py +141 -0
- cognite_toolkit/_cdf_tk/client/api/events.py +129 -0
- cognite_toolkit/_cdf_tk/client/api/extraction_pipelines.py +148 -0
- cognite_toolkit/_cdf_tk/client/api/filemetadata.py +176 -0
- cognite_toolkit/_cdf_tk/client/api/function_schedules.py +115 -0
- cognite_toolkit/_cdf_tk/client/api/functions.py +113 -0
- cognite_toolkit/_cdf_tk/client/api/graphql_data_models.py +167 -0
- cognite_toolkit/_cdf_tk/client/api/groups.py +121 -0
- cognite_toolkit/_cdf_tk/client/api/hosted_extractor_destinations.py +131 -0
- cognite_toolkit/_cdf_tk/client/api/hosted_extractor_jobs.py +122 -0
- cognite_toolkit/_cdf_tk/client/api/hosted_extractor_mappings.py +129 -0
- cognite_toolkit/_cdf_tk/client/api/hosted_extractor_sources.py +136 -0
- cognite_toolkit/_cdf_tk/client/api/hosted_extractors.py +23 -0
- cognite_toolkit/_cdf_tk/client/api/infield.py +8 -8
- cognite_toolkit/_cdf_tk/client/api/instances.py +139 -0
- cognite_toolkit/_cdf_tk/client/api/labels.py +125 -0
- cognite_toolkit/_cdf_tk/client/api/legacy/canvas.py +3 -3
- cognite_toolkit/_cdf_tk/client/api/legacy/charts.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/legacy/extended_data_modeling.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/legacy/extended_files.py +2 -2
- cognite_toolkit/_cdf_tk/client/api/legacy/extended_functions.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/legacy/extended_raw.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/legacy/extended_timeseries.py +2 -2
- cognite_toolkit/_cdf_tk/client/api/legacy/location_filters.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/legacy/robotics/capabilities.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/legacy/robotics/data_postprocessing.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/legacy/robotics/frames.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/legacy/robotics/locations.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/legacy/robotics/maps.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/legacy/robotics/robots.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/legacy/search_config.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/location_filters.py +177 -0
- cognite_toolkit/_cdf_tk/client/api/migration.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/project.py +2 -2
- cognite_toolkit/_cdf_tk/client/api/raw.py +204 -0
- cognite_toolkit/_cdf_tk/client/api/relationships.py +133 -0
- cognite_toolkit/_cdf_tk/client/api/robotics.py +19 -0
- cognite_toolkit/_cdf_tk/client/api/robotics_capabilities.py +127 -0
- cognite_toolkit/_cdf_tk/client/api/robotics_data_postprocessing.py +138 -0
- cognite_toolkit/_cdf_tk/client/api/robotics_frames.py +122 -0
- cognite_toolkit/_cdf_tk/client/api/robotics_locations.py +127 -0
- cognite_toolkit/_cdf_tk/client/api/robotics_maps.py +122 -0
- cognite_toolkit/_cdf_tk/client/api/robotics_robots.py +122 -0
- cognite_toolkit/_cdf_tk/client/api/search_config.py +101 -0
- cognite_toolkit/_cdf_tk/client/api/security_categories.py +94 -0
- cognite_toolkit/_cdf_tk/client/api/sequences.py +133 -0
- cognite_toolkit/_cdf_tk/client/api/simulator_models.py +154 -0
- cognite_toolkit/_cdf_tk/client/api/simulators.py +8 -0
- cognite_toolkit/_cdf_tk/client/api/spaces.py +117 -0
- cognite_toolkit/_cdf_tk/client/api/streams.py +65 -57
- cognite_toolkit/_cdf_tk/client/api/three_d.py +300 -283
- cognite_toolkit/_cdf_tk/client/api/timeseries.py +137 -0
- cognite_toolkit/_cdf_tk/client/api/token.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/transformations.py +146 -0
- cognite_toolkit/_cdf_tk/client/api/views.py +139 -0
- cognite_toolkit/_cdf_tk/client/api/workflow_triggers.py +128 -0
- cognite_toolkit/_cdf_tk/client/api/workflow_versions.py +138 -0
- cognite_toolkit/_cdf_tk/client/api/workflows.py +119 -0
- cognite_toolkit/_cdf_tk/client/cdf_client/__init__.py +10 -0
- cognite_toolkit/_cdf_tk/client/cdf_client/api.py +358 -0
- cognite_toolkit/_cdf_tk/client/cdf_client/responses.py +38 -0
- cognite_toolkit/_cdf_tk/{utils → client}/http_client/__init__.py +9 -7
- cognite_toolkit/_cdf_tk/{utils → client}/http_client/_client.py +23 -14
- cognite_toolkit/_cdf_tk/{utils → client}/http_client/_data_classes.py +12 -2
- cognite_toolkit/_cdf_tk/client/http_client/_data_classes2.py +151 -0
- cognite_toolkit/_cdf_tk/client/http_client/_exception.py +13 -0
- cognite_toolkit/_cdf_tk/client/http_client/_item_classes.py +118 -0
- cognite_toolkit/_cdf_tk/client/request_classes/base.py +19 -0
- cognite_toolkit/_cdf_tk/client/request_classes/filters.py +113 -0
- cognite_toolkit/_cdf_tk/client/request_classes/graphql.py +28 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/agent.py +130 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/annotation.py +79 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/apm_config.py +128 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/asset.py +47 -0
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/charts_data.py +1 -1
- cognite_toolkit/_cdf_tk/client/resource_classes/cognite_file.py +53 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/data_modeling/__init__.py +168 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/data_modeling/_constraints.py +37 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/data_modeling/_container.py +50 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/data_modeling/_data_model.py +73 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/data_modeling/_data_types.py +116 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/data_modeling/_indexes.py +26 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/data_modeling/_instance.py +154 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/data_modeling/_references.py +86 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/data_modeling/_space.py +26 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/data_modeling/_view.py +143 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/data_modeling/_view_property.py +152 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/dataset.py +35 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/event.py +40 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/extraction_pipeline.py +59 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/filemetadata.py +52 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/function.py +53 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/function_schedule.py +65 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/graphql_data_model.py +40 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/group/__init__.py +187 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/group/_constants.py +2 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/group/acls.py +653 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/group/capability.py +56 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/group/group.py +63 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/group/scopes.py +166 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/hosted_extractor_destination.py +34 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/hosted_extractor_job.py +134 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/hosted_extractor_mapping.py +72 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/hosted_extractor_source/__init__.py +63 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/hosted_extractor_source/_auth.py +63 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/hosted_extractor_source/_base.py +26 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/hosted_extractor_source/_certificate.py +20 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/hosted_extractor_source/_eventhub.py +31 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/hosted_extractor_source/_kafka.py +53 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/hosted_extractor_source/_mqtt.py +36 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/hosted_extractor_source/_rest.py +49 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/identifiers.py +59 -0
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/infield.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/instance_api.py +35 -1
- cognite_toolkit/_cdf_tk/client/resource_classes/label.py +27 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/legacy/__init__.py +0 -0
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/canvas.py +48 -15
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/charts.py +1 -1
- cognite_toolkit/_cdf_tk/client/resource_classes/location_filter.py +84 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/raw.py +44 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/relationship.py +49 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/resource_view_mapping.py +38 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/robotics/__init__.py +37 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/robotics/_capability.py +53 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/robotics/_common.py +34 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/robotics/_data_post_processing.py +49 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/robotics/_frame.py +46 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/robotics/_location.py +36 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/robotics/_map.py +65 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/robotics/_robot.py +58 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/search_config.py +54 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/securitycategory.py +24 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/sequence.py +45 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/sequence_rows.py +56 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/simulator_model.py +50 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/streamlit_.py +71 -0
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/streams.py +9 -26
- cognite_toolkit/_cdf_tk/client/resource_classes/three_d.py +135 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/timeseries.py +52 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/transformation.py +140 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/workflow.py +27 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/workflow_trigger.py +63 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/workflow_version.py +155 -0
- cognite_toolkit/_cdf_tk/client/testing.py +31 -2
- cognite_toolkit/_cdf_tk/commands/_migrate/command.py +103 -108
- cognite_toolkit/_cdf_tk/commands/_migrate/conversion.py +22 -15
- cognite_toolkit/_cdf_tk/commands/_migrate/creators.py +1 -1
- cognite_toolkit/_cdf_tk/commands/_migrate/data_classes.py +11 -10
- cognite_toolkit/_cdf_tk/commands/_migrate/data_mapper.py +148 -57
- cognite_toolkit/_cdf_tk/commands/_migrate/default_mappings.py +1 -1
- cognite_toolkit/_cdf_tk/commands/_migrate/issues.py +22 -39
- cognite_toolkit/_cdf_tk/commands/_migrate/migration_io.py +29 -27
- cognite_toolkit/_cdf_tk/commands/_profile.py +1 -1
- cognite_toolkit/_cdf_tk/commands/_purge.py +8 -8
- cognite_toolkit/_cdf_tk/commands/_upload.py +1 -1
- cognite_toolkit/_cdf_tk/commands/build_cmd.py +12 -2
- cognite_toolkit/_cdf_tk/commands/build_v2/_module_parser.py +138 -0
- cognite_toolkit/_cdf_tk/commands/build_v2/_modules_parser.py +163 -0
- cognite_toolkit/_cdf_tk/commands/build_v2/build_cmd.py +83 -96
- cognite_toolkit/_cdf_tk/commands/build_v2/{build_input.py → build_parameters.py} +8 -22
- cognite_toolkit/_cdf_tk/commands/build_v2/data_classes/_modules.py +27 -0
- cognite_toolkit/_cdf_tk/commands/build_v2/data_classes/_resource.py +22 -0
- cognite_toolkit/_cdf_tk/commands/dump_resource.py +4 -4
- cognite_toolkit/_cdf_tk/commands/pull.py +97 -2
- cognite_toolkit/_cdf_tk/commands/run.py +1 -1
- cognite_toolkit/_cdf_tk/cruds/__init__.py +16 -6
- cognite_toolkit/_cdf_tk/cruds/_data_cruds.py +9 -5
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/__init__.py +2 -0
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/auth.py +6 -2
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/classic.py +70 -89
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/configuration.py +1 -1
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/datamodel.py +1 -1
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/extraction_pipeline.py +1 -1
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/fieldops.py +14 -7
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/file.py +50 -59
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/function.py +1 -1
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/industrial_tool.py +1 -1
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/location.py +4 -3
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/migration.py +1 -1
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/raw.py +6 -1
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/relationship.py +5 -4
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/robotics.py +1 -1
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/simulators.py +122 -0
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/streams.py +15 -31
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/timeseries.py +42 -47
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/transformation.py +1 -1
- cognite_toolkit/_cdf_tk/data_classes/__init__.py +3 -0
- cognite_toolkit/_cdf_tk/data_classes/_issues.py +36 -0
- cognite_toolkit/_cdf_tk/data_classes/_module_directories.py +2 -1
- cognite_toolkit/_cdf_tk/data_classes/_tracking_info.py +4 -0
- cognite_toolkit/_cdf_tk/feature_flags.py +8 -0
- cognite_toolkit/_cdf_tk/resource_classes/__init__.py +2 -0
- cognite_toolkit/_cdf_tk/resource_classes/capabilities.py +6 -0
- cognite_toolkit/_cdf_tk/resource_classes/search_config.py +1 -1
- cognite_toolkit/_cdf_tk/resource_classes/simulator_model.py +17 -0
- cognite_toolkit/_cdf_tk/resource_classes/workflow_version.py +13 -4
- cognite_toolkit/_cdf_tk/storageio/_applications.py +53 -15
- cognite_toolkit/_cdf_tk/storageio/_asset_centric.py +117 -107
- cognite_toolkit/_cdf_tk/storageio/_base.py +3 -1
- cognite_toolkit/_cdf_tk/storageio/_datapoints.py +7 -7
- cognite_toolkit/_cdf_tk/storageio/_file_content.py +64 -54
- cognite_toolkit/_cdf_tk/storageio/_instances.py +1 -1
- cognite_toolkit/_cdf_tk/storageio/_raw.py +1 -1
- cognite_toolkit/_cdf_tk/storageio/logger.py +162 -0
- cognite_toolkit/_cdf_tk/tk_warnings/__init__.py +2 -0
- cognite_toolkit/_cdf_tk/tk_warnings/fileread.py +20 -0
- cognite_toolkit/_cdf_tk/utils/__init__.py +11 -1
- cognite_toolkit/_cdf_tk/utils/cdf.py +1 -1
- cognite_toolkit/_cdf_tk/utils/interactive_select.py +8 -6
- cognite_toolkit/_cdf_tk/utils/modules.py +7 -0
- cognite_toolkit/_cdf_tk/utils/pip_validator.py +96 -0
- cognite_toolkit/_cdf_tk/utils/useful_types.py +4 -7
- cognite_toolkit/_cdf_tk/utils/useful_types2.py +14 -0
- cognite_toolkit/_repo_files/GitHub/.github/workflows/deploy.yaml +1 -1
- cognite_toolkit/_repo_files/GitHub/.github/workflows/dry-run.yaml +1 -1
- cognite_toolkit/_resources/cdf.toml +1 -1
- cognite_toolkit/_version.py +1 -1
- {cognite_toolkit-0.7.39.dist-info → cognite_toolkit-0.7.51.dist-info}/METADATA +13 -3
- cognite_toolkit-0.7.51.dist-info/RECORD +445 -0
- {cognite_toolkit-0.7.39.dist-info → cognite_toolkit-0.7.51.dist-info}/WHEEL +2 -2
- cognite_toolkit/_cdf_tk/client/data_classes/api_classes.py +0 -30
- cognite_toolkit/_cdf_tk/client/data_classes/base.py +0 -67
- cognite_toolkit/_cdf_tk/client/data_classes/three_d.py +0 -112
- cognite_toolkit/_cdf_tk/commands/build_v2/build_issues.py +0 -27
- cognite_toolkit/_cdf_tk/utils/http_client/_data_classes2.py +0 -247
- cognite_toolkit/_cdf_tk/utils/http_client/_exception.py +0 -4
- cognite_toolkit-0.7.39.dist-info/RECORD +0 -322
- /cognite_toolkit/_cdf_tk/{utils → client}/http_client/_tracker.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → request_classes}/__init__.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes/legacy → resource_classes}/__init__.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/capabilities.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/apm_config_v1.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/extendable_cognite_file.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/extended_filemetadata.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/extended_filemetdata.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/extended_timeseries.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/functions.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/graphql_data_models.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/instances.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/location_filters.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/migration.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/pending_instances_ids.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/project.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/raw.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/robotics.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/search_config.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/sequences.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/streamlit_.py +0 -0
- {cognite_toolkit-0.7.39.dist-info → cognite_toolkit-0.7.51.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
from abc import ABC
|
|
2
|
+
from typing import Literal
|
|
3
|
+
|
|
4
|
+
from pydantic import JsonValue
|
|
5
|
+
|
|
6
|
+
from cognite_toolkit._cdf_tk.client._resource_base import BaseModelObject, RequestResource, ResponseResource
|
|
7
|
+
|
|
8
|
+
from ._constraints import Constraint
|
|
9
|
+
from ._data_types import DataType
|
|
10
|
+
from ._indexes import Index
|
|
11
|
+
from ._references import ContainerReference
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class ContainerPropertyDefinition(BaseModelObject):
|
|
15
|
+
immutable: bool | None = None
|
|
16
|
+
nullable: bool | None = None
|
|
17
|
+
auto_increment: bool | None = None
|
|
18
|
+
default_value: str | int | float | bool | dict[str, JsonValue] | None = None
|
|
19
|
+
description: str | None = None
|
|
20
|
+
name: str | None = None
|
|
21
|
+
type: DataType
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class Container(BaseModelObject, ABC):
|
|
25
|
+
space: str
|
|
26
|
+
external_id: str
|
|
27
|
+
name: str | None = None
|
|
28
|
+
description: str | None = None
|
|
29
|
+
used_for: Literal["node", "edge", "all"] | None = None
|
|
30
|
+
properties: dict[str, ContainerPropertyDefinition]
|
|
31
|
+
constraints: dict[str, Constraint] | None = None
|
|
32
|
+
indexes: dict[str, Index] | None = None
|
|
33
|
+
|
|
34
|
+
def as_id(self) -> ContainerReference:
|
|
35
|
+
return ContainerReference(
|
|
36
|
+
space=self.space,
|
|
37
|
+
external_id=self.external_id,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class ContainerRequest(Container, RequestResource): ...
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class ContainerResponse(Container, ResponseResource[ContainerRequest]):
|
|
45
|
+
created_time: int
|
|
46
|
+
last_updated_time: int
|
|
47
|
+
is_global: bool
|
|
48
|
+
|
|
49
|
+
def as_request_resource(self) -> "ContainerRequest":
|
|
50
|
+
return ContainerRequest.model_validate(self.model_dump(by_alias=True))
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
from abc import ABC
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
from pydantic import field_serializer
|
|
5
|
+
from pydantic_core.core_schema import FieldSerializationInfo
|
|
6
|
+
|
|
7
|
+
from cognite_toolkit._cdf_tk.client._resource_base import BaseModelObject, RequestResource, ResponseResource
|
|
8
|
+
|
|
9
|
+
from ._references import DataModelReference, ViewReference
|
|
10
|
+
from ._view import ViewResponse
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class DataModel(BaseModelObject, ABC):
|
|
14
|
+
"""Cognite Data Model resource.
|
|
15
|
+
|
|
16
|
+
Data models group and structure views into reusable collections.
|
|
17
|
+
A data model contains a set of views where the node types can
|
|
18
|
+
refer to each other with direct relations and edges.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
space: str
|
|
22
|
+
external_id: str
|
|
23
|
+
version: str
|
|
24
|
+
description: str | None = None
|
|
25
|
+
|
|
26
|
+
def as_id(self) -> DataModelReference:
|
|
27
|
+
return DataModelReference(
|
|
28
|
+
space=self.space,
|
|
29
|
+
external_id=self.external_id,
|
|
30
|
+
version=self.version,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class DataModelRequest(DataModel, RequestResource):
|
|
35
|
+
views: list[ViewReference] | None = None
|
|
36
|
+
|
|
37
|
+
@field_serializer("views", mode="plain")
|
|
38
|
+
@classmethod
|
|
39
|
+
def serialize_views(
|
|
40
|
+
cls, views: list[ViewReference] | None, info: FieldSerializationInfo
|
|
41
|
+
) -> list[dict[str, Any]] | None:
|
|
42
|
+
if views is None:
|
|
43
|
+
return None
|
|
44
|
+
return [{**view.model_dump(**vars(info)), "type": "view"} for view in views]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class DataModelResponse(DataModel, ResponseResource[DataModelRequest]):
|
|
48
|
+
views: list[ViewReference] | None = None
|
|
49
|
+
created_time: int
|
|
50
|
+
last_updated_time: int
|
|
51
|
+
is_global: bool
|
|
52
|
+
|
|
53
|
+
def as_request_resource(self) -> DataModelRequest:
|
|
54
|
+
return DataModelRequest.model_validate(self.model_dump(by_alias=True), extra="ignore")
|
|
55
|
+
|
|
56
|
+
@field_serializer("views", mode="plain")
|
|
57
|
+
@classmethod
|
|
58
|
+
def serialize_views(
|
|
59
|
+
cls, views: list[ViewReference] | None, info: FieldSerializationInfo
|
|
60
|
+
) -> list[dict[str, Any]] | None:
|
|
61
|
+
if views is None:
|
|
62
|
+
return None
|
|
63
|
+
return [{**view.model_dump(**vars(info)), "type": "view"} for view in views]
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class DataModelResponseWithViews(DataModel, ResponseResource[DataModelRequest]):
|
|
67
|
+
views: list[ViewResponse] | None = None
|
|
68
|
+
created_time: int
|
|
69
|
+
last_updated_time: int
|
|
70
|
+
is_global: bool
|
|
71
|
+
|
|
72
|
+
def as_request_resource(self) -> DataModelRequest:
|
|
73
|
+
return DataModelRequest.model_validate(self.model_dump(by_alias=True), extra="ignore")
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
from abc import ABC
|
|
2
|
+
from typing import Annotated, Literal
|
|
3
|
+
|
|
4
|
+
from pydantic import Field, TypeAdapter
|
|
5
|
+
|
|
6
|
+
from cognite_toolkit._cdf_tk.client._resource_base import BaseModelObject
|
|
7
|
+
|
|
8
|
+
from ._references import ContainerReference, ViewReference
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class PropertyTypeDefinition(BaseModelObject, ABC):
|
|
12
|
+
type: str
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class ListablePropertyTypeDefinition(PropertyTypeDefinition, ABC):
|
|
16
|
+
list: bool | None = None
|
|
17
|
+
max_list_size: int | None = None
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class TextProperty(ListablePropertyTypeDefinition):
|
|
21
|
+
type: Literal["text"] = "text"
|
|
22
|
+
max_text_size: int | None = None
|
|
23
|
+
collation: str | None = None
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class Unit(BaseModelObject):
|
|
27
|
+
external_id: str
|
|
28
|
+
source_unit: str | None = None
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class FloatProperty(ListablePropertyTypeDefinition, ABC):
|
|
32
|
+
unit: Unit | None = None
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class Float32Property(FloatProperty):
|
|
36
|
+
type: Literal["float32"] = "float32"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class Float64Property(FloatProperty):
|
|
40
|
+
type: Literal["float64"] = "float64"
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class BooleanProperty(ListablePropertyTypeDefinition):
|
|
44
|
+
type: Literal["boolean"] = "boolean"
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class Int32Property(ListablePropertyTypeDefinition):
|
|
48
|
+
type: Literal["int32"] = "int32"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class Int64Property(ListablePropertyTypeDefinition):
|
|
52
|
+
type: Literal["int64"] = "int64"
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class TimestampProperty(ListablePropertyTypeDefinition):
|
|
56
|
+
type: Literal["timestamp"] = "timestamp"
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class DateProperty(ListablePropertyTypeDefinition):
|
|
60
|
+
type: Literal["date"] = "date"
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class JSONProperty(ListablePropertyTypeDefinition):
|
|
64
|
+
type: Literal["json"] = "json"
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class TimeseriesCDFExternalIdReference(ListablePropertyTypeDefinition):
|
|
68
|
+
type: Literal["timeseries"] = "timeseries"
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class FileCDFExternalIdReference(ListablePropertyTypeDefinition):
|
|
72
|
+
type: Literal["file"] = "file"
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class SequenceCDFExternalIdReference(ListablePropertyTypeDefinition):
|
|
76
|
+
type: Literal["sequence"] = "sequence"
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class DirectNodeRelation(ListablePropertyTypeDefinition):
|
|
80
|
+
type: Literal["direct"] = "direct"
|
|
81
|
+
container: ContainerReference | None = None
|
|
82
|
+
# This property is only available in the response object. It will be ignored in the request object.
|
|
83
|
+
# In the request object, use ViewCoreProperty.source instead.
|
|
84
|
+
source: ViewReference | None = Field(None, exclude=True)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class EnumValue(BaseModelObject):
|
|
88
|
+
name: str | None = None
|
|
89
|
+
description: str | None = None
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
class EnumProperty(PropertyTypeDefinition):
|
|
93
|
+
type: Literal["enum"] = "enum"
|
|
94
|
+
unknown_value: str | None = None
|
|
95
|
+
values: dict[str, EnumValue]
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
DataType = Annotated[
|
|
99
|
+
TextProperty
|
|
100
|
+
| Float32Property
|
|
101
|
+
| Float64Property
|
|
102
|
+
| BooleanProperty
|
|
103
|
+
| Int32Property
|
|
104
|
+
| Int64Property
|
|
105
|
+
| TimestampProperty
|
|
106
|
+
| DateProperty
|
|
107
|
+
| JSONProperty
|
|
108
|
+
| TimeseriesCDFExternalIdReference
|
|
109
|
+
| FileCDFExternalIdReference
|
|
110
|
+
| SequenceCDFExternalIdReference
|
|
111
|
+
| EnumProperty
|
|
112
|
+
| DirectNodeRelation,
|
|
113
|
+
Field(discriminator="type"),
|
|
114
|
+
]
|
|
115
|
+
|
|
116
|
+
DataTypeAdapter: TypeAdapter[DataType] = TypeAdapter(DataType)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from abc import ABC
|
|
2
|
+
from typing import Annotated, Literal
|
|
3
|
+
|
|
4
|
+
from pydantic import Field, TypeAdapter
|
|
5
|
+
|
|
6
|
+
from cognite_toolkit._cdf_tk.client._resource_base import BaseModelObject
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class IndexDefinition(BaseModelObject, ABC):
|
|
10
|
+
index_type: str
|
|
11
|
+
properties: list[str]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class BtreeIndex(IndexDefinition):
|
|
15
|
+
index_type: Literal["btree"] = "btree"
|
|
16
|
+
by_space: bool | None = None
|
|
17
|
+
cursorable: bool | None = None
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class InvertedIndex(IndexDefinition):
|
|
21
|
+
index_type: Literal["inverted"] = "inverted"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
Index = Annotated[BtreeIndex | InvertedIndex, Field(discriminator="index_type")]
|
|
25
|
+
|
|
26
|
+
IndexAdapter: TypeAdapter[Index] = TypeAdapter(Index)
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
from abc import ABC
|
|
2
|
+
from typing import Annotated, Any, Generic, Literal, TypeAlias
|
|
3
|
+
|
|
4
|
+
from pydantic import Field, JsonValue, field_serializer, field_validator
|
|
5
|
+
|
|
6
|
+
from cognite_toolkit._cdf_tk.client._resource_base import (
|
|
7
|
+
BaseModelObject,
|
|
8
|
+
RequestResource,
|
|
9
|
+
ResponseResource,
|
|
10
|
+
T_RequestResource,
|
|
11
|
+
)
|
|
12
|
+
from cognite_toolkit._cdf_tk.client.resource_classes.instance_api import TypedEdgeIdentifier, TypedNodeIdentifier
|
|
13
|
+
|
|
14
|
+
from ._references import ContainerReference, NodeReference, ViewReference
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class InstanceDefinition(BaseModelObject, ABC):
|
|
18
|
+
"""Base class for node and edge instances."""
|
|
19
|
+
|
|
20
|
+
instance_type: str # "node" | "edge"
|
|
21
|
+
space: str
|
|
22
|
+
external_id: str
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class InstanceSource(BaseModelObject):
|
|
26
|
+
source: ViewReference | ContainerReference
|
|
27
|
+
properties: dict[str, JsonValue] | None = None
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class InstanceRequestDefinition(InstanceDefinition, RequestResource, ABC):
|
|
31
|
+
existing_version: int | None = None
|
|
32
|
+
sources: list[InstanceSource]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class InstanceResponseDefinition(InstanceDefinition, ResponseResource, Generic[T_RequestResource], ABC):
|
|
36
|
+
version: int
|
|
37
|
+
created_time: int
|
|
38
|
+
last_updated_time: int
|
|
39
|
+
deleted_time: int | None = None
|
|
40
|
+
properties: dict[ViewReference | ContainerReference, dict[str, JsonValue]] | None = None
|
|
41
|
+
|
|
42
|
+
@field_validator("properties", mode="before")
|
|
43
|
+
def parse_reference(cls, value: Any) -> Any:
|
|
44
|
+
if not isinstance(value, dict):
|
|
45
|
+
return value
|
|
46
|
+
parsed: dict[ViewReference | ContainerReference, dict[str, Any]] = {}
|
|
47
|
+
for space, inner_dict in value.items():
|
|
48
|
+
if not isinstance(inner_dict, dict) or not isinstance(space, str):
|
|
49
|
+
raise ValueError(
|
|
50
|
+
f"Invalid properties format expected dict[str, dict[...]], got: dict[{type(space).__name__}, {type(inner_dict).__name__}]"
|
|
51
|
+
)
|
|
52
|
+
for view_or_container_identifier, prop in inner_dict.items():
|
|
53
|
+
if not isinstance(view_or_container_identifier, str):
|
|
54
|
+
raise ValueError(
|
|
55
|
+
"Invalid properties format expected dict[str, dict[str, ...]]], "
|
|
56
|
+
f"got: dict[{type(space).__name__}, "
|
|
57
|
+
f"dict[{type(view_or_container_identifier).__name__}, ...]]"
|
|
58
|
+
)
|
|
59
|
+
source_ref: ViewReference | ContainerReference
|
|
60
|
+
if "/" in view_or_container_identifier:
|
|
61
|
+
external_id, version = view_or_container_identifier.split("/", 1)
|
|
62
|
+
source_ref = ViewReference(space=space, external_id=external_id, version=version)
|
|
63
|
+
else:
|
|
64
|
+
source_ref = ContainerReference(space=space, external_id=view_or_container_identifier)
|
|
65
|
+
parsed[source_ref] = prop
|
|
66
|
+
return parsed
|
|
67
|
+
|
|
68
|
+
@field_serializer("properties", mode="plain")
|
|
69
|
+
def serialize_properties(self, value: dict[ViewReference | ContainerReference, dict[str, Any]] | None) -> Any:
|
|
70
|
+
if value is None:
|
|
71
|
+
return None
|
|
72
|
+
serialized: dict[str, dict[str, Any]] = {}
|
|
73
|
+
for source_ref, props in value.items():
|
|
74
|
+
space = source_ref.space
|
|
75
|
+
if space not in serialized:
|
|
76
|
+
serialized[space] = {}
|
|
77
|
+
if isinstance(source_ref, ViewReference):
|
|
78
|
+
identifier = f"{source_ref.external_id}/{source_ref.version}"
|
|
79
|
+
else:
|
|
80
|
+
identifier = source_ref.external_id
|
|
81
|
+
serialized[space][identifier] = props
|
|
82
|
+
return serialized
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class NodeRequest(InstanceRequestDefinition):
|
|
86
|
+
"""A node request resource."""
|
|
87
|
+
|
|
88
|
+
instance_type: Literal["node"] = "node"
|
|
89
|
+
type: NodeReference | None = None
|
|
90
|
+
|
|
91
|
+
def as_id(self) -> TypedNodeIdentifier:
|
|
92
|
+
return TypedNodeIdentifier(space=self.space, external_id=self.external_id)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class EdgeRequest(InstanceRequestDefinition):
|
|
96
|
+
"""An edge request resource."""
|
|
97
|
+
|
|
98
|
+
instance_type: Literal["edge"] = "edge"
|
|
99
|
+
type: NodeReference
|
|
100
|
+
start_node: NodeReference
|
|
101
|
+
end_node: NodeReference
|
|
102
|
+
|
|
103
|
+
def as_id(self) -> TypedEdgeIdentifier:
|
|
104
|
+
return TypedEdgeIdentifier(space=self.space, external_id=self.external_id)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class NodeResponse(InstanceResponseDefinition[NodeRequest]):
|
|
108
|
+
"""A node response from the API."""
|
|
109
|
+
|
|
110
|
+
instance_type: Literal["node"] = "node"
|
|
111
|
+
type: NodeReference | None = None
|
|
112
|
+
|
|
113
|
+
def as_id(self) -> TypedNodeIdentifier:
|
|
114
|
+
return TypedNodeIdentifier(space=self.space, external_id=self.external_id)
|
|
115
|
+
|
|
116
|
+
def as_request_resource(self) -> NodeRequest:
|
|
117
|
+
dumped = self.dump()
|
|
118
|
+
if self.properties:
|
|
119
|
+
dumped["sources"] = [
|
|
120
|
+
InstanceSource(source=source_ref, properties=props) for source_ref, props in self.properties.items()
|
|
121
|
+
]
|
|
122
|
+
dumped["existingVersion"] = dumped.pop("version", None)
|
|
123
|
+
return NodeRequest.model_validate(dumped, extra="ignore")
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
class EdgeResponse(InstanceResponseDefinition[EdgeRequest]):
|
|
127
|
+
"""An edge response from the API."""
|
|
128
|
+
|
|
129
|
+
instance_type: Literal["edge"] = "edge"
|
|
130
|
+
type: NodeReference
|
|
131
|
+
start_node: NodeReference
|
|
132
|
+
end_node: NodeReference
|
|
133
|
+
|
|
134
|
+
def as_id(self) -> TypedEdgeIdentifier:
|
|
135
|
+
return TypedEdgeIdentifier(space=self.space, external_id=self.external_id)
|
|
136
|
+
|
|
137
|
+
def as_request_resource(self) -> EdgeRequest:
|
|
138
|
+
dumped = self.dump()
|
|
139
|
+
if self.properties:
|
|
140
|
+
dumped["sources"] = [
|
|
141
|
+
InstanceSource(source=source_ref, properties=props) for source_ref, props in self.properties.items()
|
|
142
|
+
]
|
|
143
|
+
dumped["existingVersion"] = dumped.pop("version", None)
|
|
144
|
+
return EdgeRequest.model_validate(dumped, extra="ignore")
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
InstanceRequest: TypeAlias = Annotated[
|
|
148
|
+
NodeRequest | EdgeRequest,
|
|
149
|
+
Field(discriminator="instance_type"),
|
|
150
|
+
]
|
|
151
|
+
InstanceResponse: TypeAlias = Annotated[
|
|
152
|
+
NodeResponse | EdgeResponse,
|
|
153
|
+
Field(discriminator="instance_type"),
|
|
154
|
+
]
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
from typing import Literal
|
|
2
|
+
|
|
3
|
+
from pydantic import Field
|
|
4
|
+
|
|
5
|
+
from cognite_toolkit._cdf_tk.client.resource_classes.identifiers import Identifier
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SpaceReference(Identifier):
|
|
9
|
+
space: str
|
|
10
|
+
|
|
11
|
+
def __str__(self) -> str:
|
|
12
|
+
return self.space
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class ContainerReference(Identifier):
|
|
16
|
+
type: Literal["container"] = Field("container", exclude=True)
|
|
17
|
+
space: str
|
|
18
|
+
external_id: str
|
|
19
|
+
|
|
20
|
+
def __str__(self) -> str:
|
|
21
|
+
return f"{self.space}:{self.external_id}"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class ViewReference(Identifier):
|
|
25
|
+
type: Literal["view"] = Field("view", exclude=True)
|
|
26
|
+
space: str
|
|
27
|
+
external_id: str
|
|
28
|
+
version: str
|
|
29
|
+
|
|
30
|
+
def __str__(self) -> str:
|
|
31
|
+
return f"{self.space}:{self.external_id}(version={self.version})"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class DataModelReference(Identifier):
|
|
35
|
+
space: str
|
|
36
|
+
external_id: str
|
|
37
|
+
version: str
|
|
38
|
+
|
|
39
|
+
def __str__(self) -> str:
|
|
40
|
+
return f"{self.space}:{self.external_id}(version={self.version})"
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class NodeReference(Identifier):
|
|
44
|
+
space: str
|
|
45
|
+
external_id: str
|
|
46
|
+
|
|
47
|
+
def __str__(self) -> str:
|
|
48
|
+
return f"{self.space}:{self.external_id}"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class EdgeReference(Identifier):
|
|
52
|
+
space: str
|
|
53
|
+
external_id: str
|
|
54
|
+
|
|
55
|
+
def __str__(self) -> str:
|
|
56
|
+
return f"{self.space}:{self.external_id}"
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class ContainerDirectReference(Identifier):
|
|
60
|
+
source: ContainerReference
|
|
61
|
+
identifier: str
|
|
62
|
+
|
|
63
|
+
def __str__(self) -> str:
|
|
64
|
+
return f"{self.source!s}.{self.identifier}"
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class ViewDirectReference(Identifier):
|
|
68
|
+
source: ViewReference
|
|
69
|
+
identifier: str
|
|
70
|
+
|
|
71
|
+
def __str__(self) -> str:
|
|
72
|
+
return f"{self.source!s}.{self.identifier}"
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class ContainerIndexReference(ContainerReference):
|
|
76
|
+
identifier: str
|
|
77
|
+
|
|
78
|
+
def __str__(self) -> str:
|
|
79
|
+
return f"{self.space}:{self.external_id}(index={self.identifier})"
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class ContainerConstraintReference(ContainerReference):
|
|
83
|
+
identifier: str
|
|
84
|
+
|
|
85
|
+
def __str__(self) -> str:
|
|
86
|
+
return f"{self.space}:{self.external_id}(constraint={self.identifier})"
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from abc import ABC
|
|
2
|
+
|
|
3
|
+
from cognite_toolkit._cdf_tk.client._resource_base import BaseModelObject, RequestResource, ResponseResource
|
|
4
|
+
|
|
5
|
+
from ._references import SpaceReference
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Space(BaseModelObject, ABC):
|
|
9
|
+
space: str
|
|
10
|
+
name: str | None = None
|
|
11
|
+
description: str | None = None
|
|
12
|
+
|
|
13
|
+
def as_id(self) -> SpaceReference:
|
|
14
|
+
return SpaceReference(space=self.space)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class SpaceRequest(Space, RequestResource): ...
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class SpaceResponse(Space, ResponseResource[SpaceRequest]):
|
|
21
|
+
created_time: int
|
|
22
|
+
last_updated_time: int
|
|
23
|
+
is_global: bool
|
|
24
|
+
|
|
25
|
+
def as_request_resource(self) -> SpaceRequest:
|
|
26
|
+
return SpaceRequest.model_validate(self.model_dump(by_alias=True), extra="ignore")
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
from abc import ABC
|
|
2
|
+
from typing import Any, Literal
|
|
3
|
+
|
|
4
|
+
from pydantic import Field, JsonValue, field_serializer, model_validator
|
|
5
|
+
from pydantic_core.core_schema import FieldSerializationInfo
|
|
6
|
+
|
|
7
|
+
from cognite_toolkit._cdf_tk.client._resource_base import BaseModelObject, RequestResource, ResponseResource
|
|
8
|
+
|
|
9
|
+
from ._data_types import DirectNodeRelation
|
|
10
|
+
from ._references import ContainerReference, ViewReference
|
|
11
|
+
from ._view_property import (
|
|
12
|
+
MultiReverseDirectRelationPropertyResponse,
|
|
13
|
+
SingleReverseDirectRelationPropertyResponse,
|
|
14
|
+
ViewCorePropertyRequest,
|
|
15
|
+
ViewCorePropertyResponse,
|
|
16
|
+
ViewRequestProperty,
|
|
17
|
+
ViewResponseProperty,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class View(BaseModelObject, ABC):
|
|
22
|
+
space: str
|
|
23
|
+
external_id: str
|
|
24
|
+
version: str
|
|
25
|
+
name: str | None = None
|
|
26
|
+
description: str | None = None
|
|
27
|
+
filter: JsonValue | None
|
|
28
|
+
implements: list[ViewReference] | None = None
|
|
29
|
+
|
|
30
|
+
def as_id(self) -> ViewReference:
|
|
31
|
+
return ViewReference(space=self.space, external_id=self.external_id, version=self.version)
|
|
32
|
+
|
|
33
|
+
@model_validator(mode="before")
|
|
34
|
+
def set_connection_type_on_primary_properties(cls, data: dict[str, Any]) -> dict[str, Any]:
|
|
35
|
+
if "properties" not in data:
|
|
36
|
+
return data
|
|
37
|
+
properties = data["properties"]
|
|
38
|
+
if not isinstance(properties, dict):
|
|
39
|
+
return data
|
|
40
|
+
# We assume all properties without connectionType are core properties.
|
|
41
|
+
# The reason we set connectionType is to make it easy for pydantic to discriminate the union.
|
|
42
|
+
# This also leads to better error messages, as if there is a union and pydantic does not know which
|
|
43
|
+
# type to pick it will give errors from all type in the union.
|
|
44
|
+
new_properties: dict[str, Any] = {}
|
|
45
|
+
for prop_id, prop in properties.items():
|
|
46
|
+
if isinstance(prop, dict) and "connectionType" not in prop:
|
|
47
|
+
prop_copy = prop.copy()
|
|
48
|
+
prop_copy["connectionType"] = "primary_property"
|
|
49
|
+
new_properties[prop_id] = prop_copy
|
|
50
|
+
else:
|
|
51
|
+
new_properties[prop_id] = prop
|
|
52
|
+
if new_properties:
|
|
53
|
+
new_data = data.copy()
|
|
54
|
+
new_data["properties"] = new_properties
|
|
55
|
+
return new_data
|
|
56
|
+
|
|
57
|
+
return data
|
|
58
|
+
|
|
59
|
+
@field_serializer("implements", mode="plain")
|
|
60
|
+
@classmethod
|
|
61
|
+
def serialize_implements(
|
|
62
|
+
cls, implements: list[ViewReference] | None, info: FieldSerializationInfo
|
|
63
|
+
) -> list[dict[str, Any]] | None:
|
|
64
|
+
if implements is None:
|
|
65
|
+
return None
|
|
66
|
+
output: list[dict[str, Any]] = []
|
|
67
|
+
for view in implements:
|
|
68
|
+
dumped = view.model_dump(**vars(info))
|
|
69
|
+
dumped["type"] = "view"
|
|
70
|
+
output.append(dumped)
|
|
71
|
+
return output
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class ViewRequest(View, RequestResource):
|
|
75
|
+
properties: dict[str, ViewRequestProperty] = Field(
|
|
76
|
+
description="View with included properties and expected edges, indexed by a unique space-local identifier."
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
@property
|
|
80
|
+
def used_containers(self) -> set[ContainerReference]:
|
|
81
|
+
"""Get all containers referenced by this view."""
|
|
82
|
+
return {prop.container for prop in self.properties.values() if isinstance(prop, ViewCorePropertyRequest)}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class ViewResponse(View, ResponseResource[ViewRequest]):
|
|
86
|
+
properties: dict[str, ViewResponseProperty]
|
|
87
|
+
|
|
88
|
+
created_time: int
|
|
89
|
+
last_updated_time: int
|
|
90
|
+
writable: bool
|
|
91
|
+
queryable: bool
|
|
92
|
+
used_for: Literal["node", "edge", "all"]
|
|
93
|
+
is_global: bool
|
|
94
|
+
mapped_containers: list[ContainerReference]
|
|
95
|
+
|
|
96
|
+
def as_request_resource(self) -> ViewRequest:
|
|
97
|
+
dumped = self.model_dump(by_alias=True, exclude={"properties"})
|
|
98
|
+
properties: dict[str, Any] = {}
|
|
99
|
+
for key, value in self.properties.items():
|
|
100
|
+
if isinstance(value, ViewCorePropertyResponse) and isinstance(value.type, DirectNodeRelation):
|
|
101
|
+
# Special case. In the request the source of DirectNodeRelation is set on the Property object,
|
|
102
|
+
# while in the response it is set on the DirectNodeRelation object.
|
|
103
|
+
request_object = value.as_request().model_dump(by_alias=True)
|
|
104
|
+
request_object["source"] = value.type.source.model_dump(by_alias=True) if value.type.source else None
|
|
105
|
+
properties[key] = request_object
|
|
106
|
+
elif isinstance(
|
|
107
|
+
value,
|
|
108
|
+
ViewCorePropertyResponse
|
|
109
|
+
| SingleReverseDirectRelationPropertyResponse
|
|
110
|
+
| MultiReverseDirectRelationPropertyResponse,
|
|
111
|
+
):
|
|
112
|
+
properties[key] = value.as_request().model_dump(by_alias=True)
|
|
113
|
+
else:
|
|
114
|
+
properties[key] = value.model_dump(by_alias=True)
|
|
115
|
+
|
|
116
|
+
dumped["properties"] = properties
|
|
117
|
+
return ViewRequest.model_validate(dumped, extra="ignore")
|
|
118
|
+
|
|
119
|
+
@field_serializer("mapped_containers", mode="plain")
|
|
120
|
+
@classmethod
|
|
121
|
+
def serialize_mapped_containers(
|
|
122
|
+
cls, mapped_containers: list[ContainerReference], info: FieldSerializationInfo
|
|
123
|
+
) -> list[dict[str, Any]]:
|
|
124
|
+
return [container.model_dump(**vars(info)) | {"type": "container"} for container in mapped_containers]
|
|
125
|
+
|
|
126
|
+
@field_serializer("properties", mode="plain")
|
|
127
|
+
@classmethod
|
|
128
|
+
def serialize_properties_special_handling_direct_relation_with_source(
|
|
129
|
+
cls, properties: dict[str, ViewResponseProperty], info: FieldSerializationInfo
|
|
130
|
+
) -> dict[str, dict[str, Any]]:
|
|
131
|
+
output: dict[str, dict[str, Any]] = {}
|
|
132
|
+
for prop_id, prop in properties.items():
|
|
133
|
+
output[prop_id] = prop.model_dump(**vars(info))
|
|
134
|
+
if (
|
|
135
|
+
isinstance(prop, ViewCorePropertyResponse)
|
|
136
|
+
and isinstance(prop.type, DirectNodeRelation)
|
|
137
|
+
and prop.type.source
|
|
138
|
+
):
|
|
139
|
+
# We manually include the source as this is excluded by default. The reason why this is excluded
|
|
140
|
+
# is that the DirectNodeRelation is used for both request and response, and in the request the source
|
|
141
|
+
# does not exist on the DirectNodeRelation, but on the Property object.
|
|
142
|
+
output[prop_id]["type"]["source"] = prop.type.source.model_dump(**vars(info)) | {"type": "view"}
|
|
143
|
+
return output
|