cognite-toolkit 0.7.41__py3-none-any.whl → 0.7.43__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/client/_toolkit_client.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/events.py +20 -2
- cognite_toolkit/_cdf_tk/client/api/timeseries.py +20 -2
- cognite_toolkit/_cdf_tk/client/data_classes/agent.py +6 -9
- cognite_toolkit/_cdf_tk/client/data_classes/asset.py +7 -14
- cognite_toolkit/_cdf_tk/client/data_classes/base.py +2 -2
- cognite_toolkit/_cdf_tk/client/data_classes/data_modeling/__init__.py +148 -0
- cognite_toolkit/_cdf_tk/client/data_classes/data_modeling/_constraints.py +37 -0
- cognite_toolkit/_cdf_tk/client/data_classes/data_modeling/_container.py +50 -0
- cognite_toolkit/_cdf_tk/client/data_classes/data_modeling/_data_model.py +73 -0
- cognite_toolkit/_cdf_tk/client/data_classes/data_modeling/_data_types.py +116 -0
- cognite_toolkit/_cdf_tk/client/data_classes/data_modeling/_indexes.py +26 -0
- cognite_toolkit/_cdf_tk/client/data_classes/data_modeling/_references.py +78 -0
- cognite_toolkit/_cdf_tk/client/data_classes/data_modeling/_space.py +26 -0
- cognite_toolkit/_cdf_tk/client/data_classes/data_modeling/_view.py +143 -0
- cognite_toolkit/_cdf_tk/client/data_classes/data_modeling/_view_property.py +152 -0
- cognite_toolkit/_cdf_tk/client/data_classes/event.py +12 -15
- cognite_toolkit/_cdf_tk/client/data_classes/filemetadata.py +8 -18
- cognite_toolkit/_cdf_tk/client/data_classes/simulator_model.py +50 -0
- cognite_toolkit/_cdf_tk/client/data_classes/timeseries.py +15 -18
- cognite_toolkit/_cdf_tk/client/testing.py +1 -1
- cognite_toolkit/_cdf_tk/commands/_migrate/conversion.py +7 -5
- cognite_toolkit/_cdf_tk/commands/_migrate/data_mapper.py +4 -4
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/auth.py +5 -1
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/classic.py +40 -39
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/relationship.py +2 -2
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/timeseries.py +48 -47
- cognite_toolkit/_cdf_tk/resource_classes/__init__.py +2 -0
- 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/_asset_centric.py +54 -46
- cognite_toolkit/_cdf_tk/utils/useful_types2.py +5 -3
- 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.41.dist-info → cognite_toolkit-0.7.43.dist-info}/METADATA +1 -1
- {cognite_toolkit-0.7.41.dist-info → cognite_toolkit-0.7.43.dist-info}/RECORD +40 -28
- {cognite_toolkit-0.7.41.dist-info → cognite_toolkit-0.7.43.dist-info}/WHEEL +0 -0
- {cognite_toolkit-0.7.41.dist-info → cognite_toolkit-0.7.43.dist-info}/entry_points.txt +0 -0
|
@@ -36,7 +36,7 @@ class ToolAPI:
|
|
|
36
36
|
self.http_client = http_client
|
|
37
37
|
self.three_d = ThreeDAPI(http_client, console)
|
|
38
38
|
self.assets = AssetsAPI(http_client)
|
|
39
|
-
self.
|
|
39
|
+
self.timeseries = TimeSeriesAPI(http_client)
|
|
40
40
|
self.events = EventsAPI(http_client)
|
|
41
41
|
|
|
42
42
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from collections.abc import Sequence
|
|
2
|
-
from typing import Literal
|
|
2
|
+
from typing import Any, Literal
|
|
3
3
|
|
|
4
4
|
from cognite_toolkit._cdf_tk.client.cdf_client import CDFResourceAPI, PagedResponse, ResponseItems
|
|
5
5
|
from cognite_toolkit._cdf_tk.client.cdf_client.api import Endpoint
|
|
@@ -75,15 +75,33 @@ class EventsAPI(CDFResourceAPI[InternalOrExternalId, EventRequest, EventResponse
|
|
|
75
75
|
|
|
76
76
|
def iterate(
|
|
77
77
|
self,
|
|
78
|
+
data_set_external_ids: list[str] | None = None,
|
|
79
|
+
asset_subtree_external_ids: list[str] | None = None,
|
|
78
80
|
limit: int = 100,
|
|
79
81
|
cursor: str | None = None,
|
|
80
82
|
) -> PagedResponse[EventResponse]:
|
|
81
83
|
"""Iterate over all events in CDF.
|
|
82
84
|
|
|
85
|
+
Args:
|
|
86
|
+
data_set_external_ids: Filter by data set external IDs.
|
|
87
|
+
asset_subtree_external_ids: Filter by asset subtree external IDs.
|
|
88
|
+
limit: Maximum number of items to return.
|
|
89
|
+
cursor: Cursor for pagination.
|
|
90
|
+
|
|
83
91
|
Returns:
|
|
84
92
|
PagedResponse of EventResponse objects.
|
|
85
93
|
"""
|
|
86
|
-
|
|
94
|
+
filter_: dict[str, Any] = {}
|
|
95
|
+
if asset_subtree_external_ids:
|
|
96
|
+
filter_["assetSubtreeIds"] = [{"externalId": ext_id} for ext_id in asset_subtree_external_ids]
|
|
97
|
+
if data_set_external_ids:
|
|
98
|
+
filter_["dataSetIds"] = [{"externalId": ds_id} for ds_id in data_set_external_ids]
|
|
99
|
+
|
|
100
|
+
return self._iterate(
|
|
101
|
+
cursor=cursor,
|
|
102
|
+
limit=limit,
|
|
103
|
+
body={"filter": filter_ or None},
|
|
104
|
+
)
|
|
87
105
|
|
|
88
106
|
def list(
|
|
89
107
|
self,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from collections.abc import Sequence
|
|
2
|
-
from typing import Literal
|
|
2
|
+
from typing import Any, Literal
|
|
3
3
|
|
|
4
4
|
from cognite_toolkit._cdf_tk.client.cdf_client import CDFResourceAPI, PagedResponse, ResponseItems
|
|
5
5
|
from cognite_toolkit._cdf_tk.client.cdf_client.api import Endpoint
|
|
@@ -83,15 +83,33 @@ class TimeSeriesAPI(CDFResourceAPI[InternalOrExternalId, TimeSeriesRequest, Time
|
|
|
83
83
|
|
|
84
84
|
def iterate(
|
|
85
85
|
self,
|
|
86
|
+
data_set_external_ids: list[str] | None = None,
|
|
87
|
+
asset_subtree_external_ids: list[str] | None = None,
|
|
86
88
|
limit: int = 100,
|
|
87
89
|
cursor: str | None = None,
|
|
88
90
|
) -> PagedResponse[TimeSeriesResponse]:
|
|
89
91
|
"""Iterate over all time series in CDF.
|
|
90
92
|
|
|
93
|
+
Args:
|
|
94
|
+
data_set_external_ids: Filter by data set external IDs.
|
|
95
|
+
asset_subtree_external_ids: Filter by asset subtree external IDs.
|
|
96
|
+
limit: Maximum number of items to return.
|
|
97
|
+
cursor: Cursor for pagination.
|
|
98
|
+
|
|
91
99
|
Returns:
|
|
92
100
|
PagedResponse of TimeSeriesResponse objects.
|
|
93
101
|
"""
|
|
94
|
-
|
|
102
|
+
filter_: dict[str, Any] = {}
|
|
103
|
+
if asset_subtree_external_ids:
|
|
104
|
+
filter_["assetSubtreeIds"] = [{"externalId": ext_id} for ext_id in asset_subtree_external_ids]
|
|
105
|
+
if data_set_external_ids:
|
|
106
|
+
filter_["dataSetIds"] = [{"externalId": ds_id} for ds_id in data_set_external_ids]
|
|
107
|
+
|
|
108
|
+
return self._iterate(
|
|
109
|
+
cursor=cursor,
|
|
110
|
+
limit=limit,
|
|
111
|
+
body={"filter": filter_ or None},
|
|
112
|
+
)
|
|
95
113
|
|
|
96
114
|
def list(
|
|
97
115
|
self,
|
|
@@ -98,29 +98,26 @@ AgentTool = Annotated[
|
|
|
98
98
|
]
|
|
99
99
|
|
|
100
100
|
|
|
101
|
-
class
|
|
101
|
+
class Agent(BaseModelObject):
|
|
102
102
|
external_id: str
|
|
103
103
|
name: str
|
|
104
104
|
description: str | None = None
|
|
105
105
|
instructions: str | None = None
|
|
106
106
|
model: str = "azure/gpt-4o-mini"
|
|
107
107
|
tools: list[AgentTool] | None = None
|
|
108
|
-
runtime_version: str | None = None
|
|
109
108
|
|
|
110
109
|
def as_id(self) -> ExternalId:
|
|
111
110
|
return ExternalId(external_id=self.external_id)
|
|
112
111
|
|
|
113
112
|
|
|
114
|
-
class
|
|
113
|
+
class AgentRequest(Agent, RequestResource):
|
|
114
|
+
runtime_version: str | None = None
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
class AgentResponse(Agent, ResponseResource[AgentRequest]):
|
|
115
118
|
created_time: int
|
|
116
119
|
last_updated_time: int
|
|
117
120
|
owner_id: str
|
|
118
|
-
external_id: str
|
|
119
|
-
name: str
|
|
120
|
-
description: str | None = None
|
|
121
|
-
instructions: str | None = None
|
|
122
|
-
model: str = "azure/gpt-4o-mini"
|
|
123
|
-
tools: list[AgentTool] | None = None
|
|
124
121
|
runtime_version: str
|
|
125
122
|
|
|
126
123
|
def as_request_resource(self) -> AgentRequest:
|
|
@@ -7,9 +7,7 @@ from cognite_toolkit._cdf_tk.client.data_classes.base import BaseModelObject, Re
|
|
|
7
7
|
from .identifiers import ExternalId
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
class
|
|
11
|
-
container_fields: ClassVar[frozenset[str]] = frozenset({"metadata", "labels"})
|
|
12
|
-
non_nullable_fields: ClassVar[frozenset[str]] = frozenset({"parent_id", "parent_external_id"})
|
|
10
|
+
class Asset(BaseModelObject):
|
|
13
11
|
external_id: str | None = None
|
|
14
12
|
name: str
|
|
15
13
|
parent_id: int | None = None
|
|
@@ -27,28 +25,23 @@ class AssetRequest(RequestUpdateable):
|
|
|
27
25
|
return ExternalId(external_id=self.external_id)
|
|
28
26
|
|
|
29
27
|
|
|
28
|
+
class AssetRequest(Asset, RequestUpdateable):
|
|
29
|
+
container_fields: ClassVar[frozenset[str]] = frozenset({"metadata", "labels"})
|
|
30
|
+
non_nullable_fields: ClassVar[frozenset[str]] = frozenset({"parent_id", "parent_external_id"})
|
|
31
|
+
|
|
32
|
+
|
|
30
33
|
class AssetAggregateItem(BaseModelObject):
|
|
31
34
|
child_count: int
|
|
32
35
|
depth: int
|
|
33
36
|
path: list[dict[Literal["id"], int]]
|
|
34
37
|
|
|
35
38
|
|
|
36
|
-
class AssetResponse(ResponseResource[AssetRequest]):
|
|
39
|
+
class AssetResponse(Asset, ResponseResource[AssetRequest]):
|
|
37
40
|
created_time: int
|
|
38
41
|
last_updated_time: int
|
|
39
42
|
root_id: int
|
|
40
43
|
aggregates: AssetAggregateItem | None = None
|
|
41
44
|
id: int
|
|
42
|
-
external_id: str | None = None
|
|
43
|
-
name: str
|
|
44
|
-
parent_id: int | None = None
|
|
45
|
-
parent_external_id: str | None = None
|
|
46
|
-
description: str | None = None
|
|
47
|
-
metadata: dict[str, str] | None = None
|
|
48
|
-
data_set_id: int | None = None
|
|
49
|
-
source: str | None = None
|
|
50
|
-
labels: list[dict[Literal["externalId"], str]] | None = None
|
|
51
|
-
geo_location: dict[str, JsonValue] | None = None
|
|
52
45
|
|
|
53
46
|
def as_request_resource(self) -> AssetRequest:
|
|
54
47
|
return AssetRequest.model_validate(self.dump(), extra="ignore")
|
|
@@ -18,7 +18,7 @@ class BaseModelObject(BaseModel):
|
|
|
18
18
|
"""Base class for all object. This includes resources and nested objects."""
|
|
19
19
|
|
|
20
20
|
# We allow extra fields to support forward compatibility.
|
|
21
|
-
model_config = ConfigDict(alias_generator=to_camel, extra="allow")
|
|
21
|
+
model_config = ConfigDict(alias_generator=to_camel, extra="allow", populate_by_name=True)
|
|
22
22
|
|
|
23
23
|
def dump(self, camel_case: bool = True) -> dict[str, Any]:
|
|
24
24
|
"""Dump the resource to a dictionary.
|
|
@@ -30,7 +30,7 @@ class BaseModelObject(BaseModel):
|
|
|
30
30
|
@classmethod
|
|
31
31
|
def _load(cls, resource: dict[str, Any]) -> Self:
|
|
32
32
|
"""Load method to match CogniteResource signature."""
|
|
33
|
-
return cls.model_validate(resource)
|
|
33
|
+
return cls.model_validate(resource, by_alias=True)
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
class Identifier(BaseModelObject):
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
from ._constraints import (
|
|
2
|
+
Constraint,
|
|
3
|
+
ConstraintAdapter,
|
|
4
|
+
ConstraintDefinition,
|
|
5
|
+
RequiresConstraintDefinition,
|
|
6
|
+
UniquenessConstraintDefinition,
|
|
7
|
+
)
|
|
8
|
+
from ._container import (
|
|
9
|
+
Container,
|
|
10
|
+
ContainerPropertyDefinition,
|
|
11
|
+
ContainerRequest,
|
|
12
|
+
ContainerResponse,
|
|
13
|
+
)
|
|
14
|
+
from ._data_model import DataModelRequest, DataModelResponse
|
|
15
|
+
from ._data_types import (
|
|
16
|
+
BooleanProperty,
|
|
17
|
+
DataType,
|
|
18
|
+
DataTypeAdapter,
|
|
19
|
+
DateProperty,
|
|
20
|
+
DirectNodeRelation,
|
|
21
|
+
EnumProperty,
|
|
22
|
+
EnumValue,
|
|
23
|
+
FileCDFExternalIdReference,
|
|
24
|
+
Float32Property,
|
|
25
|
+
Float64Property,
|
|
26
|
+
FloatProperty,
|
|
27
|
+
Int32Property,
|
|
28
|
+
Int64Property,
|
|
29
|
+
JSONProperty,
|
|
30
|
+
ListablePropertyTypeDefinition,
|
|
31
|
+
PropertyTypeDefinition,
|
|
32
|
+
SequenceCDFExternalIdReference,
|
|
33
|
+
TextProperty,
|
|
34
|
+
TimeseriesCDFExternalIdReference,
|
|
35
|
+
TimestampProperty,
|
|
36
|
+
Unit,
|
|
37
|
+
)
|
|
38
|
+
from ._indexes import (
|
|
39
|
+
BtreeIndex,
|
|
40
|
+
Index,
|
|
41
|
+
IndexAdapter,
|
|
42
|
+
IndexDefinition,
|
|
43
|
+
InvertedIndex,
|
|
44
|
+
)
|
|
45
|
+
from ._references import (
|
|
46
|
+
ContainerConstraintReference,
|
|
47
|
+
ContainerDirectReference,
|
|
48
|
+
ContainerIndexReference,
|
|
49
|
+
ContainerReference,
|
|
50
|
+
DataModelReference,
|
|
51
|
+
NodeReference,
|
|
52
|
+
SpaceReference,
|
|
53
|
+
ViewDirectReference,
|
|
54
|
+
ViewReference,
|
|
55
|
+
)
|
|
56
|
+
from ._space import Space, SpaceRequest, SpaceResponse
|
|
57
|
+
from ._view import View, ViewRequest, ViewResponse
|
|
58
|
+
from ._view_property import (
|
|
59
|
+
ConnectionPropertyDefinition,
|
|
60
|
+
ConstraintOrIndexState,
|
|
61
|
+
EdgeProperty,
|
|
62
|
+
MultiEdgeProperty,
|
|
63
|
+
MultiReverseDirectRelationPropertyRequest,
|
|
64
|
+
MultiReverseDirectRelationPropertyResponse,
|
|
65
|
+
ReverseDirectRelationProperty,
|
|
66
|
+
SingleEdgeProperty,
|
|
67
|
+
SingleReverseDirectRelationPropertyRequest,
|
|
68
|
+
SingleReverseDirectRelationPropertyResponse,
|
|
69
|
+
ViewCoreProperty,
|
|
70
|
+
ViewCorePropertyRequest,
|
|
71
|
+
ViewCorePropertyResponse,
|
|
72
|
+
ViewPropertyDefinition,
|
|
73
|
+
ViewRequestProperty,
|
|
74
|
+
ViewRequestPropertyAdapter,
|
|
75
|
+
ViewResponseProperty,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
__all__ = [
|
|
79
|
+
"BooleanProperty",
|
|
80
|
+
"BtreeIndex",
|
|
81
|
+
"ConnectionPropertyDefinition",
|
|
82
|
+
"Constraint",
|
|
83
|
+
"ConstraintAdapter",
|
|
84
|
+
"ConstraintDefinition",
|
|
85
|
+
"ConstraintOrIndexState",
|
|
86
|
+
"Container",
|
|
87
|
+
"ContainerConstraintReference",
|
|
88
|
+
"ContainerDirectReference",
|
|
89
|
+
"ContainerIndexReference",
|
|
90
|
+
"ContainerPropertyDefinition",
|
|
91
|
+
"ContainerReference",
|
|
92
|
+
"ContainerRequest",
|
|
93
|
+
"ContainerResponse",
|
|
94
|
+
"DataModelReference",
|
|
95
|
+
"DataModelRequest",
|
|
96
|
+
"DataModelResponse",
|
|
97
|
+
"DataType",
|
|
98
|
+
"DataTypeAdapter",
|
|
99
|
+
"DateProperty",
|
|
100
|
+
"DirectNodeRelation",
|
|
101
|
+
"EdgeProperty",
|
|
102
|
+
"EnumProperty",
|
|
103
|
+
"EnumValue",
|
|
104
|
+
"FileCDFExternalIdReference",
|
|
105
|
+
"Float32Property",
|
|
106
|
+
"Float64Property",
|
|
107
|
+
"FloatProperty",
|
|
108
|
+
"Index",
|
|
109
|
+
"IndexAdapter",
|
|
110
|
+
"IndexDefinition",
|
|
111
|
+
"Int32Property",
|
|
112
|
+
"Int64Property",
|
|
113
|
+
"InvertedIndex",
|
|
114
|
+
"JSONProperty",
|
|
115
|
+
"ListablePropertyTypeDefinition",
|
|
116
|
+
"MultiEdgeProperty",
|
|
117
|
+
"MultiReverseDirectRelationPropertyRequest",
|
|
118
|
+
"MultiReverseDirectRelationPropertyResponse",
|
|
119
|
+
"NodeReference",
|
|
120
|
+
"PropertyTypeDefinition",
|
|
121
|
+
"RequiresConstraintDefinition",
|
|
122
|
+
"ReverseDirectRelationProperty",
|
|
123
|
+
"SequenceCDFExternalIdReference",
|
|
124
|
+
"SingleEdgeProperty",
|
|
125
|
+
"SingleReverseDirectRelationPropertyRequest",
|
|
126
|
+
"SingleReverseDirectRelationPropertyResponse",
|
|
127
|
+
"Space",
|
|
128
|
+
"SpaceReference",
|
|
129
|
+
"SpaceRequest",
|
|
130
|
+
"SpaceResponse",
|
|
131
|
+
"TextProperty",
|
|
132
|
+
"TimeseriesCDFExternalIdReference",
|
|
133
|
+
"TimestampProperty",
|
|
134
|
+
"UniquenessConstraintDefinition",
|
|
135
|
+
"Unit",
|
|
136
|
+
"View",
|
|
137
|
+
"ViewCoreProperty",
|
|
138
|
+
"ViewCorePropertyRequest",
|
|
139
|
+
"ViewCorePropertyResponse",
|
|
140
|
+
"ViewDirectReference",
|
|
141
|
+
"ViewPropertyDefinition",
|
|
142
|
+
"ViewReference",
|
|
143
|
+
"ViewRequest",
|
|
144
|
+
"ViewRequestProperty",
|
|
145
|
+
"ViewRequestPropertyAdapter",
|
|
146
|
+
"ViewResponse",
|
|
147
|
+
"ViewResponseProperty",
|
|
148
|
+
]
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from abc import ABC
|
|
2
|
+
from typing import Annotated, Any, Literal
|
|
3
|
+
|
|
4
|
+
from pydantic import Field, TypeAdapter, field_serializer
|
|
5
|
+
from pydantic_core.core_schema import FieldSerializationInfo
|
|
6
|
+
|
|
7
|
+
from cognite_toolkit._cdf_tk.client.data_classes.base import BaseModelObject
|
|
8
|
+
|
|
9
|
+
from ._references import ContainerReference
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ConstraintDefinition(BaseModelObject, ABC):
|
|
13
|
+
constraint_type: str
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class UniquenessConstraintDefinition(ConstraintDefinition):
|
|
17
|
+
constraint_type: Literal["uniqueness"] = "uniqueness"
|
|
18
|
+
properties: list[str]
|
|
19
|
+
by_space: bool | None = None
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class RequiresConstraintDefinition(ConstraintDefinition):
|
|
23
|
+
constraint_type: Literal["requires"] = "requires"
|
|
24
|
+
require: ContainerReference
|
|
25
|
+
|
|
26
|
+
@field_serializer("require", mode="plain")
|
|
27
|
+
@classmethod
|
|
28
|
+
def serialize_require(cls, require: ContainerReference, info: FieldSerializationInfo) -> dict[str, Any]:
|
|
29
|
+
return {**require.model_dump(**vars(info)), "type": "container"}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
Constraint = Annotated[
|
|
33
|
+
UniquenessConstraintDefinition | RequiresConstraintDefinition,
|
|
34
|
+
Field(discriminator="constraint_type"),
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
ConstraintAdapter: TypeAdapter[Constraint] = TypeAdapter(Constraint)
|
|
@@ -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.data_classes.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.data_classes.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.data_classes.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.data_classes.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)
|