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,138 @@
|
|
|
1
|
+
from collections.abc import Iterable, Sequence
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
from cognite_toolkit._cdf_tk.client.cdf_client import CDFResourceAPI, PagedResponse, ResponseItems
|
|
5
|
+
from cognite_toolkit._cdf_tk.client.cdf_client.api import Endpoint
|
|
6
|
+
from cognite_toolkit._cdf_tk.client.http_client import HTTPClient, ItemsSuccessResponse2, SuccessResponse2
|
|
7
|
+
from cognite_toolkit._cdf_tk.client.resource_classes.identifiers import WorkflowVersionId
|
|
8
|
+
from cognite_toolkit._cdf_tk.client.resource_classes.workflow_version import (
|
|
9
|
+
WorkflowVersionRequest,
|
|
10
|
+
WorkflowVersionResponse,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class WorkflowVersionsAPI(CDFResourceAPI[WorkflowVersionId, WorkflowVersionRequest, WorkflowVersionResponse]):
|
|
15
|
+
def __init__(self, http_client: HTTPClient) -> None:
|
|
16
|
+
super().__init__(
|
|
17
|
+
http_client=http_client,
|
|
18
|
+
method_endpoint_map={
|
|
19
|
+
"upsert": Endpoint(method="POST", path="/workflows/versions", item_limit=1),
|
|
20
|
+
"retrieve": Endpoint(
|
|
21
|
+
method="GET", path="/workflow/{workflowExternalId}/versions/{version}", item_limit=1
|
|
22
|
+
),
|
|
23
|
+
"delete": Endpoint(method="POST", path="/workflows/versions/delete", item_limit=100),
|
|
24
|
+
"list": Endpoint(method="POST", path="/workflows/versions/list", item_limit=1000),
|
|
25
|
+
},
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
def _validate_page_response(
|
|
29
|
+
self, response: SuccessResponse2 | ItemsSuccessResponse2
|
|
30
|
+
) -> PagedResponse[WorkflowVersionResponse]:
|
|
31
|
+
return PagedResponse[WorkflowVersionResponse].model_validate_json(response.body)
|
|
32
|
+
|
|
33
|
+
def _reference_response(self, response: SuccessResponse2) -> ResponseItems[WorkflowVersionId]:
|
|
34
|
+
return ResponseItems[WorkflowVersionId].model_validate_json(response.body)
|
|
35
|
+
|
|
36
|
+
def create(self, items: Sequence[WorkflowVersionRequest]) -> list[WorkflowVersionResponse]:
|
|
37
|
+
"""Create or update workflow versions in CDF.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
items: List of WorkflowVersionRequest objects to create or update.
|
|
41
|
+
Returns:
|
|
42
|
+
List of created/updated WorkflowVersionResponse objects.
|
|
43
|
+
"""
|
|
44
|
+
return self._request_item_response(items, "upsert")
|
|
45
|
+
|
|
46
|
+
# This is a duplicate of the create method, included to standardize the API interface.
|
|
47
|
+
def update(self, items: Sequence[WorkflowVersionRequest]) -> list[WorkflowVersionResponse]:
|
|
48
|
+
"""Create or update workflow versions in CDF.
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
items: List of WorkflowVersionRequest objects to create or update.
|
|
52
|
+
Returns:
|
|
53
|
+
List of created/updated WorkflowVersionResponse objects.
|
|
54
|
+
"""
|
|
55
|
+
return self.create(items)
|
|
56
|
+
|
|
57
|
+
def retrieve(self, items: Sequence[WorkflowVersionId]) -> list[WorkflowVersionResponse]:
|
|
58
|
+
"""Retrieve workflow versions from CDF.
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
items: List of WorkflowVersionId objects to retrieve.
|
|
62
|
+
Returns:
|
|
63
|
+
List of retrieved WorkflowVersionResponse objects.
|
|
64
|
+
"""
|
|
65
|
+
result: list[WorkflowVersionResponse] = []
|
|
66
|
+
for item in items:
|
|
67
|
+
endpoint = f"/workflows/{item.workflow_external_id}/versions/{item.version}"
|
|
68
|
+
retrieved = self._request_item_response([item], "retrieve", endpoint=endpoint)
|
|
69
|
+
result.extend(retrieved)
|
|
70
|
+
return result
|
|
71
|
+
|
|
72
|
+
def delete(self, items: Sequence[WorkflowVersionId]) -> None:
|
|
73
|
+
"""Delete workflow versions from CDF.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
items: List of WorkflowVersionId objects to delete.
|
|
77
|
+
"""
|
|
78
|
+
self._request_no_response(items, "delete")
|
|
79
|
+
|
|
80
|
+
def paginate(
|
|
81
|
+
self,
|
|
82
|
+
workflow_external_id: str | None = None,
|
|
83
|
+
limit: int = 100,
|
|
84
|
+
cursor: str | None = None,
|
|
85
|
+
) -> PagedResponse[WorkflowVersionResponse]:
|
|
86
|
+
"""Iterate over all workflow versions in CDF.
|
|
87
|
+
|
|
88
|
+
Args:
|
|
89
|
+
workflow_external_id: Filter by workflow external ID.
|
|
90
|
+
limit: Maximum number of items to return.
|
|
91
|
+
cursor: Cursor for pagination.
|
|
92
|
+
|
|
93
|
+
Returns:
|
|
94
|
+
PagedResponse of WorkflowVersionResponse objects.
|
|
95
|
+
"""
|
|
96
|
+
body: dict[str, Any] = {}
|
|
97
|
+
if workflow_external_id:
|
|
98
|
+
body["workflowExternalId"] = workflow_external_id
|
|
99
|
+
|
|
100
|
+
return self._paginate(
|
|
101
|
+
cursor=cursor,
|
|
102
|
+
limit=limit,
|
|
103
|
+
body=body,
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
def iterate(
|
|
107
|
+
self,
|
|
108
|
+
workflow_external_id: str | None = None,
|
|
109
|
+
limit: int = 100,
|
|
110
|
+
) -> Iterable[list[WorkflowVersionResponse]]:
|
|
111
|
+
"""Iterate over all workflow versions in CDF.
|
|
112
|
+
|
|
113
|
+
Args:
|
|
114
|
+
workflow_external_id: Filter by workflow external ID.
|
|
115
|
+
limit: Maximum number of items to return per page.
|
|
116
|
+
|
|
117
|
+
Returns:
|
|
118
|
+
Iterable of lists of WorkflowVersionResponse objects.
|
|
119
|
+
"""
|
|
120
|
+
body: dict[str, Any] = {}
|
|
121
|
+
if workflow_external_id:
|
|
122
|
+
body["workflowExternalId"] = workflow_external_id
|
|
123
|
+
|
|
124
|
+
return self._iterate(
|
|
125
|
+
limit=limit,
|
|
126
|
+
body=body,
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
def list(
|
|
130
|
+
self,
|
|
131
|
+
limit: int | None = 100,
|
|
132
|
+
) -> list[WorkflowVersionResponse]:
|
|
133
|
+
"""List all workflow versions in CDF.
|
|
134
|
+
|
|
135
|
+
Returns:
|
|
136
|
+
List of WorkflowVersionResponse objects.
|
|
137
|
+
"""
|
|
138
|
+
return self._list(limit=limit)
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
from collections.abc import Iterable, Sequence
|
|
2
|
+
|
|
3
|
+
from cognite_toolkit._cdf_tk.client.cdf_client import CDFResourceAPI, PagedResponse, ResponseItems
|
|
4
|
+
from cognite_toolkit._cdf_tk.client.cdf_client.api import Endpoint
|
|
5
|
+
from cognite_toolkit._cdf_tk.client.http_client import HTTPClient, ItemsSuccessResponse2, SuccessResponse2
|
|
6
|
+
from cognite_toolkit._cdf_tk.client.resource_classes.identifiers import ExternalId
|
|
7
|
+
from cognite_toolkit._cdf_tk.client.resource_classes.workflow import WorkflowRequest, WorkflowResponse
|
|
8
|
+
|
|
9
|
+
from .workflow_triggers import WorkflowTriggersAPI
|
|
10
|
+
from .workflow_versions import WorkflowVersionsAPI
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class WorkflowsAPI(CDFResourceAPI[ExternalId, WorkflowRequest, WorkflowResponse]):
|
|
14
|
+
def __init__(self, http_client: HTTPClient) -> None:
|
|
15
|
+
super().__init__(
|
|
16
|
+
http_client=http_client,
|
|
17
|
+
method_endpoint_map={
|
|
18
|
+
"upsert": Endpoint(method="POST", path="/workflows", item_limit=1),
|
|
19
|
+
"retrieve": Endpoint(method="GET", path="/workflows/{workflowExternalId}", item_limit=1),
|
|
20
|
+
"delete": Endpoint(method="POST", path="/workflows/delete", item_limit=100),
|
|
21
|
+
"list": Endpoint(method="GET", path="/workflows", item_limit=100),
|
|
22
|
+
},
|
|
23
|
+
)
|
|
24
|
+
self.versions = WorkflowVersionsAPI(http_client)
|
|
25
|
+
self.triggers = WorkflowTriggersAPI(http_client)
|
|
26
|
+
|
|
27
|
+
def _validate_page_response(
|
|
28
|
+
self, response: SuccessResponse2 | ItemsSuccessResponse2
|
|
29
|
+
) -> PagedResponse[WorkflowResponse]:
|
|
30
|
+
return PagedResponse[WorkflowResponse].model_validate_json(response.body)
|
|
31
|
+
|
|
32
|
+
def _reference_response(self, response: SuccessResponse2) -> ResponseItems[ExternalId]:
|
|
33
|
+
return ResponseItems[ExternalId].model_validate_json(response.body)
|
|
34
|
+
|
|
35
|
+
def create(self, items: Sequence[WorkflowRequest]) -> list[WorkflowResponse]:
|
|
36
|
+
"""Create or update workflows in CDF.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
items: List of WorkflowRequest objects to create or update.
|
|
40
|
+
Returns:
|
|
41
|
+
List of created/updated WorkflowResponse objects.
|
|
42
|
+
"""
|
|
43
|
+
return self._request_item_response(items, "upsert")
|
|
44
|
+
|
|
45
|
+
# This is a duplicate of the create method, included to standardize the API interface.
|
|
46
|
+
def update(self, items: Sequence[WorkflowRequest]) -> list[WorkflowResponse]:
|
|
47
|
+
"""Create or update workflows in CDF.
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
items: List of WorkflowRequest objects to create or update.
|
|
51
|
+
Returns:
|
|
52
|
+
List of created/updated WorkflowResponse objects.
|
|
53
|
+
"""
|
|
54
|
+
return self.create(items)
|
|
55
|
+
|
|
56
|
+
def retrieve(self, items: Sequence[ExternalId]) -> list[WorkflowResponse]:
|
|
57
|
+
"""Retrieve a workflow from CDF by external ID.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
items: List of ExternalId objects to retrieve.
|
|
61
|
+
|
|
62
|
+
Returns:
|
|
63
|
+
The retrieved WorkflowResponse object, or None if not found.
|
|
64
|
+
"""
|
|
65
|
+
result: list[WorkflowResponse] = []
|
|
66
|
+
for item in items:
|
|
67
|
+
endpoint = f"/workflows/{item.external_id}"
|
|
68
|
+
retrieved = self._request_item_response([item], "retrieve", endpoint=endpoint)
|
|
69
|
+
result.extend(retrieved)
|
|
70
|
+
return result
|
|
71
|
+
|
|
72
|
+
def delete(self, items: Sequence[ExternalId]) -> None:
|
|
73
|
+
"""Delete workflows from CDF.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
items: List of ExternalId objects to delete.
|
|
77
|
+
"""
|
|
78
|
+
self._request_no_response(items, "delete")
|
|
79
|
+
|
|
80
|
+
def paginate(
|
|
81
|
+
self,
|
|
82
|
+
limit: int = 100,
|
|
83
|
+
cursor: str | None = None,
|
|
84
|
+
) -> PagedResponse[WorkflowResponse]:
|
|
85
|
+
"""Iterate over all workflows in CDF.
|
|
86
|
+
|
|
87
|
+
Args:
|
|
88
|
+
limit: Maximum number of items to return.
|
|
89
|
+
cursor: Cursor for pagination.
|
|
90
|
+
|
|
91
|
+
Returns:
|
|
92
|
+
PagedResponse of WorkflowResponse objects.
|
|
93
|
+
"""
|
|
94
|
+
return self._paginate(cursor=cursor, limit=limit)
|
|
95
|
+
|
|
96
|
+
def iterate(
|
|
97
|
+
self,
|
|
98
|
+
limit: int = 100,
|
|
99
|
+
) -> Iterable[list[WorkflowResponse]]:
|
|
100
|
+
"""Iterate over all workflows in CDF.
|
|
101
|
+
|
|
102
|
+
Args:
|
|
103
|
+
limit: Maximum number of items to return per page.
|
|
104
|
+
|
|
105
|
+
Returns:
|
|
106
|
+
Iterable of lists of WorkflowResponse objects.
|
|
107
|
+
"""
|
|
108
|
+
return self._iterate(limit=limit)
|
|
109
|
+
|
|
110
|
+
def list(
|
|
111
|
+
self,
|
|
112
|
+
limit: int | None = 100,
|
|
113
|
+
) -> list[WorkflowResponse]:
|
|
114
|
+
"""List all workflows in CDF.
|
|
115
|
+
|
|
116
|
+
Returns:
|
|
117
|
+
List of WorkflowResponse objects.
|
|
118
|
+
"""
|
|
119
|
+
return self._list(limit=limit)
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
"""Base classes for resource clients.
|
|
2
|
+
|
|
3
|
+
This module provides the base infrastructure for resource-specific clients
|
|
4
|
+
that handle CRUD operations for CDF Data Modeling API resources.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from abc import ABC, abstractmethod
|
|
8
|
+
from collections import defaultdict
|
|
9
|
+
from collections.abc import Callable, Iterable, Sequence
|
|
10
|
+
from dataclasses import dataclass
|
|
11
|
+
from functools import partial
|
|
12
|
+
from typing import Any, Generic, Literal, TypeAlias
|
|
13
|
+
|
|
14
|
+
from pydantic import JsonValue
|
|
15
|
+
|
|
16
|
+
from cognite_toolkit._cdf_tk.client._resource_base import (
|
|
17
|
+
RequestItem,
|
|
18
|
+
T_Identifier,
|
|
19
|
+
T_RequestResource,
|
|
20
|
+
T_ResponseResource,
|
|
21
|
+
UpdatableRequestResource,
|
|
22
|
+
)
|
|
23
|
+
from cognite_toolkit._cdf_tk.client.http_client import (
|
|
24
|
+
HTTPClient,
|
|
25
|
+
ItemsRequest2,
|
|
26
|
+
ItemsSuccessResponse2,
|
|
27
|
+
RequestMessage2,
|
|
28
|
+
SuccessResponse2,
|
|
29
|
+
)
|
|
30
|
+
from cognite_toolkit._cdf_tk.utils.collection import chunker_sequence
|
|
31
|
+
|
|
32
|
+
from .responses import PagedResponse
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass(frozen=True)
|
|
36
|
+
class Endpoint:
|
|
37
|
+
method: Literal["GET", "POST", "PUT", "PATCH", "DELETE"]
|
|
38
|
+
path: str
|
|
39
|
+
item_limit: int
|
|
40
|
+
concurrency_max_workers: int = 1
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
APIMethod: TypeAlias = Literal["create", "retrieve", "update", "delete", "list", "upsert"]
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class CDFResourceAPI(Generic[T_Identifier, T_RequestResource, T_ResponseResource], ABC):
|
|
47
|
+
"""Generic resource API for CDF APIs
|
|
48
|
+
|
|
49
|
+
This class provides the logic for working with CDF resources,
|
|
50
|
+
including creating, retrieving, deleting, and listing resources.
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
def __init__(
|
|
54
|
+
self, http_client: HTTPClient, method_endpoint_map: dict[APIMethod, Endpoint], disable_gzip: bool = False
|
|
55
|
+
) -> None:
|
|
56
|
+
"""Initialize the resource API.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
http_client: The HTTP client to use for API requests.
|
|
60
|
+
method_endpoint_map: A mapping of endpoint suffixes to their properties.
|
|
61
|
+
disable_gzip: Whether to disable gzip compression for requests. Defaults to False.
|
|
62
|
+
This is only used by the robotics API. If that API is dropped, this parameter can be removed.
|
|
63
|
+
"""
|
|
64
|
+
self._http_client = http_client
|
|
65
|
+
self._method_endpoint_map = method_endpoint_map
|
|
66
|
+
self._disable_gzip = disable_gzip
|
|
67
|
+
|
|
68
|
+
@classmethod
|
|
69
|
+
def _serialize_items(cls, items: Sequence[RequestItem]) -> list[dict[str, JsonValue]]:
|
|
70
|
+
"""Serialize reference objects to JSON-compatible dicts."""
|
|
71
|
+
return [item.dump() for item in items]
|
|
72
|
+
|
|
73
|
+
@classmethod
|
|
74
|
+
def _serialize_updates(
|
|
75
|
+
cls, items: Sequence[UpdatableRequestResource], mode: Literal["patch", "replace"]
|
|
76
|
+
) -> list[dict[str, JsonValue]]:
|
|
77
|
+
"""Serialize updateable objects to JSON-compatible dicts."""
|
|
78
|
+
return [item.as_update(mode=mode) for item in items]
|
|
79
|
+
|
|
80
|
+
@abstractmethod
|
|
81
|
+
def _validate_page_response(
|
|
82
|
+
self, response: SuccessResponse2 | ItemsSuccessResponse2
|
|
83
|
+
) -> PagedResponse[T_ResponseResource]:
|
|
84
|
+
"""Parse a single item response."""
|
|
85
|
+
raise NotImplementedError()
|
|
86
|
+
|
|
87
|
+
def _make_url(self, path: str = "") -> str:
|
|
88
|
+
"""Create the full URL for this resource endpoint."""
|
|
89
|
+
return self._http_client.config.create_api_url(path)
|
|
90
|
+
|
|
91
|
+
def _update(
|
|
92
|
+
self, items: Sequence[UpdatableRequestResource], mode: Literal["patch", "replace"]
|
|
93
|
+
) -> list[T_ResponseResource]:
|
|
94
|
+
"""Update resources in chunks."""
|
|
95
|
+
response_items: list[T_ResponseResource] = []
|
|
96
|
+
for response in self._chunk_requests(
|
|
97
|
+
items, "update", serialization=partial(self._serialize_updates, mode=mode)
|
|
98
|
+
):
|
|
99
|
+
response_items.extend(self._validate_page_response(response).items)
|
|
100
|
+
return response_items
|
|
101
|
+
|
|
102
|
+
def _request_item_response(
|
|
103
|
+
self,
|
|
104
|
+
items: Sequence[RequestItem],
|
|
105
|
+
method: APIMethod,
|
|
106
|
+
params: dict[str, Any] | None = None,
|
|
107
|
+
extra_body: dict[str, Any] | None = None,
|
|
108
|
+
endpoint: str | None = None,
|
|
109
|
+
) -> list[T_ResponseResource]:
|
|
110
|
+
response_items: list[T_ResponseResource] = []
|
|
111
|
+
for response in self._chunk_requests(items, method, self._serialize_items, params, extra_body, endpoint):
|
|
112
|
+
response_items.extend(self._validate_page_response(response).items)
|
|
113
|
+
return response_items
|
|
114
|
+
|
|
115
|
+
def _request_no_response(
|
|
116
|
+
self,
|
|
117
|
+
items: Sequence[RequestItem],
|
|
118
|
+
method: APIMethod,
|
|
119
|
+
params: dict[str, Any] | None = None,
|
|
120
|
+
extra_body: dict[str, Any] | None = None,
|
|
121
|
+
endpoint: str | None = None,
|
|
122
|
+
) -> None:
|
|
123
|
+
list(self._chunk_requests(items, method, self._serialize_items, params, extra_body, endpoint))
|
|
124
|
+
return None
|
|
125
|
+
|
|
126
|
+
def _chunk_requests(
|
|
127
|
+
self,
|
|
128
|
+
items: Sequence[RequestItem],
|
|
129
|
+
method: APIMethod,
|
|
130
|
+
serialization: Callable[[Sequence[RequestItem]], list[dict[str, JsonValue]]],
|
|
131
|
+
params: dict[str, Any] | None = None,
|
|
132
|
+
extra_body: dict[str, Any] | None = None,
|
|
133
|
+
endpoint_path: str | None = None,
|
|
134
|
+
) -> Iterable[SuccessResponse2]:
|
|
135
|
+
"""Send requests in chunks and yield responses.
|
|
136
|
+
|
|
137
|
+
Args:
|
|
138
|
+
items: The items to process.
|
|
139
|
+
method: The API method to use. This is used ot look the up the endpoint.
|
|
140
|
+
serialization: A function to serialize the items to JSON-compatible dicts.
|
|
141
|
+
params: Optional query parameters for the request.
|
|
142
|
+
extra_body: Optional extra body content to include in the request.
|
|
143
|
+
endpoint_path: Optional override for the endpoint path.
|
|
144
|
+
|
|
145
|
+
Yields:
|
|
146
|
+
The successful responses from the API.
|
|
147
|
+
"""
|
|
148
|
+
# Filter out None
|
|
149
|
+
request_params = self._filter_out_none_values(params)
|
|
150
|
+
endpoint = self._method_endpoint_map[method]
|
|
151
|
+
|
|
152
|
+
for chunk in chunker_sequence(items, endpoint.item_limit):
|
|
153
|
+
request = RequestMessage2(
|
|
154
|
+
endpoint_url=f"{self._make_url(endpoint_path or endpoint.path)}",
|
|
155
|
+
method=endpoint.method,
|
|
156
|
+
body_content={"items": serialization(chunk), **(extra_body or {})}, # type: ignore[dict-item]
|
|
157
|
+
parameters=request_params,
|
|
158
|
+
disable_gzip=self._disable_gzip,
|
|
159
|
+
)
|
|
160
|
+
response = self._http_client.request_single_retries(request)
|
|
161
|
+
yield response.get_success_or_raise()
|
|
162
|
+
|
|
163
|
+
def _request_item_split_retries(
|
|
164
|
+
self,
|
|
165
|
+
items: Sequence[RequestItem],
|
|
166
|
+
method: APIMethod,
|
|
167
|
+
params: dict[str, Any] | None = None,
|
|
168
|
+
extra_body: dict[str, Any] | None = None,
|
|
169
|
+
) -> list[T_ResponseResource]:
|
|
170
|
+
"""Request items with retries, splitting on failures.
|
|
171
|
+
|
|
172
|
+
This method handles large batches of items by chunking them according to the endpoint's item limit.
|
|
173
|
+
If a single item fails, it splits the request into individual item requests to isolate the failure.
|
|
174
|
+
|
|
175
|
+
Args:
|
|
176
|
+
items: Sequence of items to request.
|
|
177
|
+
method: API method to use for the request.
|
|
178
|
+
params: Optional query parameters for the request.
|
|
179
|
+
extra_body: Optional additional body fields for the request.
|
|
180
|
+
Returns:
|
|
181
|
+
List of response items.
|
|
182
|
+
"""
|
|
183
|
+
response_items: list[T_ResponseResource] = []
|
|
184
|
+
for response in self._chunk_requests_items_split_retries(items, method, params, extra_body):
|
|
185
|
+
response_items.extend(self._validate_page_response(response).items)
|
|
186
|
+
return response_items
|
|
187
|
+
|
|
188
|
+
def _request_item_split_retries_no_response(
|
|
189
|
+
self,
|
|
190
|
+
items: Sequence[RequestItem],
|
|
191
|
+
method: APIMethod,
|
|
192
|
+
params: dict[str, Any] | None = None,
|
|
193
|
+
extra_body: dict[str, Any] | None = None,
|
|
194
|
+
) -> None:
|
|
195
|
+
"""Request items with retries, splitting on failures, without returning any response.
|
|
196
|
+
|
|
197
|
+
This method handles large batches of items by chunking them according to the endpoint's item limit.
|
|
198
|
+
If a single item fails, it splits the request into individual item requests to isolate the failure.
|
|
199
|
+
|
|
200
|
+
Args:
|
|
201
|
+
items: Sequence of items to request.
|
|
202
|
+
method: API method to use for the request.
|
|
203
|
+
params: Optional query parameters for the request.
|
|
204
|
+
extra_body: Optional additional body fields for the request.
|
|
205
|
+
"""
|
|
206
|
+
list(self._chunk_requests_items_split_retries(items, method, params, extra_body))
|
|
207
|
+
return None
|
|
208
|
+
|
|
209
|
+
def _chunk_requests_items_split_retries(
|
|
210
|
+
self,
|
|
211
|
+
items: Sequence[RequestItem],
|
|
212
|
+
method: APIMethod,
|
|
213
|
+
params: dict[str, Any] | None = None,
|
|
214
|
+
extra_body: dict[str, Any] | None = None,
|
|
215
|
+
) -> Iterable[ItemsSuccessResponse2]:
|
|
216
|
+
"""Request items with retries and splitting on failures.
|
|
217
|
+
|
|
218
|
+
This method handles large batches of items by chunking them according to the endpoint's item limit.
|
|
219
|
+
If a single item fails, it splits the request into individual item requests to isolate the failure.
|
|
220
|
+
|
|
221
|
+
This can be useful to create ignore unknown IDs behavior when retrieving items for API endpoints that
|
|
222
|
+
do not support it natively.
|
|
223
|
+
|
|
224
|
+
Args:
|
|
225
|
+
items: Sequence of items to request.
|
|
226
|
+
method: API method to use for the request.
|
|
227
|
+
params: Optional query parameters for the request.
|
|
228
|
+
extra_body: Optional additional body fields for the request.
|
|
229
|
+
Yields
|
|
230
|
+
SuccessResponse2: Successful responses from the API. All failed items are skipped.
|
|
231
|
+
|
|
232
|
+
"""
|
|
233
|
+
# Filter out None
|
|
234
|
+
request_params = self._filter_out_none_values(params)
|
|
235
|
+
endpoint = self._method_endpoint_map[method]
|
|
236
|
+
|
|
237
|
+
for chunk in chunker_sequence(items, endpoint.item_limit):
|
|
238
|
+
request = ItemsRequest2(
|
|
239
|
+
endpoint_url=f"{self._make_url(endpoint.path)}",
|
|
240
|
+
method=endpoint.method,
|
|
241
|
+
parameters=request_params,
|
|
242
|
+
items=chunk,
|
|
243
|
+
extra_body_fields=extra_body,
|
|
244
|
+
disable_gzip=self._disable_gzip,
|
|
245
|
+
)
|
|
246
|
+
responses = self._http_client.request_items_retries(request)
|
|
247
|
+
for response in responses:
|
|
248
|
+
if isinstance(response, ItemsSuccessResponse2):
|
|
249
|
+
yield response
|
|
250
|
+
|
|
251
|
+
@classmethod
|
|
252
|
+
def _filter_out_none_values(cls, params: dict[str, Any] | None) -> dict[str, Any] | None:
|
|
253
|
+
request_params: dict[str, Any] | None = None
|
|
254
|
+
if params:
|
|
255
|
+
request_params = {k: v for k, v in params.items() if v is not None}
|
|
256
|
+
return request_params
|
|
257
|
+
|
|
258
|
+
@classmethod
|
|
259
|
+
def _group_items_by_text_field(
|
|
260
|
+
cls, items: Sequence[RequestItem], *field_names: str
|
|
261
|
+
) -> dict[tuple[str, ...], list[RequestItem]]:
|
|
262
|
+
"""Group items by a text field."""
|
|
263
|
+
grouped_items: dict[tuple[str, ...], list[RequestItem]] = defaultdict(list)
|
|
264
|
+
for item in items:
|
|
265
|
+
key = tuple(str(getattr(item, field_name)) for field_name in field_names)
|
|
266
|
+
grouped_items[key].append(item)
|
|
267
|
+
return grouped_items
|
|
268
|
+
|
|
269
|
+
def _paginate(
|
|
270
|
+
self,
|
|
271
|
+
limit: int,
|
|
272
|
+
cursor: str | None = None,
|
|
273
|
+
params: dict[str, Any] | None = None,
|
|
274
|
+
body: dict[str, Any] | None = None,
|
|
275
|
+
endpoint_path: str | None = None,
|
|
276
|
+
) -> PagedResponse[T_ResponseResource]:
|
|
277
|
+
"""Fetch a single page of resources.
|
|
278
|
+
|
|
279
|
+
Args:
|
|
280
|
+
params: Query parameters for the request. Supported parameters depend on
|
|
281
|
+
the resource type but typically include:
|
|
282
|
+
- cursor: Cursor for pagination
|
|
283
|
+
- limit: Maximum number of items (defaults to list limit)
|
|
284
|
+
- space: Filter by space
|
|
285
|
+
- includeGlobal: Whether to include global resources
|
|
286
|
+
body : Body content for the request, if applicable.
|
|
287
|
+
limit: Maximum number of items to return in the page.
|
|
288
|
+
cursor: Cursor for pagination.
|
|
289
|
+
limit: Maximum number of items to return in the page.
|
|
290
|
+
cursor: Cursor for pagination.
|
|
291
|
+
|
|
292
|
+
Returns:
|
|
293
|
+
A Page containing the items and the cursor for the next page.
|
|
294
|
+
"""
|
|
295
|
+
endpoint = self._method_endpoint_map["list"]
|
|
296
|
+
if not (0 < limit <= endpoint.item_limit):
|
|
297
|
+
raise ValueError(f"Limit must be between 1 and {endpoint.item_limit}, got {limit}.")
|
|
298
|
+
|
|
299
|
+
request_params = self._filter_out_none_values(params) or {}
|
|
300
|
+
body = self._filter_out_none_values(body) or {}
|
|
301
|
+
if endpoint.method == "GET":
|
|
302
|
+
request_params["limit"] = limit
|
|
303
|
+
if cursor is not None:
|
|
304
|
+
request_params["cursor"] = cursor
|
|
305
|
+
elif endpoint.method in {"POST", "PUT", "PATCH"}:
|
|
306
|
+
body["limit"] = limit
|
|
307
|
+
if cursor is not None:
|
|
308
|
+
body["cursor"] = cursor
|
|
309
|
+
else:
|
|
310
|
+
raise NotImplementedError(f"Unsupported method {endpoint.method} for pagination.")
|
|
311
|
+
|
|
312
|
+
request = RequestMessage2(
|
|
313
|
+
endpoint_url=self._make_url(endpoint_path or endpoint.path),
|
|
314
|
+
method=endpoint.method,
|
|
315
|
+
parameters=request_params,
|
|
316
|
+
body_content=body,
|
|
317
|
+
disable_gzip=self._disable_gzip,
|
|
318
|
+
)
|
|
319
|
+
result = self._http_client.request_single_retries(request)
|
|
320
|
+
response = result.get_success_or_raise()
|
|
321
|
+
return self._validate_page_response(response)
|
|
322
|
+
|
|
323
|
+
def _iterate(
|
|
324
|
+
self,
|
|
325
|
+
limit: int | None = None,
|
|
326
|
+
cursor: str | None = None,
|
|
327
|
+
params: dict[str, Any] | None = None,
|
|
328
|
+
body: dict[str, Any] | None = None,
|
|
329
|
+
endpoint_path: str | None = None,
|
|
330
|
+
) -> Iterable[list[T_ResponseResource]]:
|
|
331
|
+
"""Iterate over all resources, handling pagination automatically."""
|
|
332
|
+
next_cursor = cursor
|
|
333
|
+
total = 0
|
|
334
|
+
endpoint = self._method_endpoint_map["list"]
|
|
335
|
+
while True:
|
|
336
|
+
page_limit = endpoint.item_limit if limit is None else min(limit - total, endpoint.item_limit)
|
|
337
|
+
page = self._paginate(
|
|
338
|
+
limit=page_limit, cursor=next_cursor, params=params, body=body, endpoint_path=endpoint_path
|
|
339
|
+
)
|
|
340
|
+
yield page.items
|
|
341
|
+
total += len(page.items)
|
|
342
|
+
if page.next_cursor is None or (limit is not None and total >= limit):
|
|
343
|
+
break
|
|
344
|
+
next_cursor = page.next_cursor
|
|
345
|
+
|
|
346
|
+
def _list(
|
|
347
|
+
self,
|
|
348
|
+
limit: int | None = None,
|
|
349
|
+
params: dict[str, Any] | None = None,
|
|
350
|
+
endpoint_path: str | None = None,
|
|
351
|
+
body: dict[str, Any] | None = None,
|
|
352
|
+
) -> list[T_ResponseResource]:
|
|
353
|
+
"""List all resources, handling pagination automatically."""
|
|
354
|
+
return [
|
|
355
|
+
item
|
|
356
|
+
for batch in self._iterate(limit=limit, params=params, endpoint_path=endpoint_path, body=body)
|
|
357
|
+
for item in batch
|
|
358
|
+
]
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from typing import Generic, TypeVar
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel, Field, JsonValue
|
|
4
|
+
|
|
5
|
+
from cognite_toolkit._cdf_tk.client.resource_classes.graphql_data_model import GraphQLDataModelResponse
|
|
6
|
+
|
|
7
|
+
T = TypeVar("T", bound=BaseModel)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ResponseItems(BaseModel, Generic[T]):
|
|
11
|
+
"""A page of reference items from a paginated API response.
|
|
12
|
+
|
|
13
|
+
Attributes:
|
|
14
|
+
items: The list of reference items in this page.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
items: list[T]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class PagedResponse(BaseModel, Generic[T]):
|
|
21
|
+
items: list[T]
|
|
22
|
+
next_cursor: str | None = Field(None, alias="nextCursor")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class QueryResponse(BaseModel, Generic[T]):
|
|
26
|
+
items: dict[str, list[T]]
|
|
27
|
+
typing: dict[str, JsonValue] | None = None
|
|
28
|
+
next_cursor: dict[str, str] = Field(alias="nextCursor")
|
|
29
|
+
debug: dict[str, JsonValue] | None = None
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class GraphQLResponse(BaseModel):
|
|
33
|
+
data: GraphQLDataModelResponse
|
|
34
|
+
errors: list[dict[str, JsonValue]] | None = None
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class GraphQLUpsertResponse(BaseModel):
|
|
38
|
+
upsert_graph_ql_dml_version: GraphQLResponse = Field(alias="upsertGraphQlDmlVersion")
|