Skip to content

Commit 943e515

Browse files
chore: upgrade Cognite SDK in viewer to v10 (#5025)
* chore: upgrade SDK to v10 in viewer * chore: bump viewer version
1 parent e42cbd6 commit 943e515

File tree

18 files changed

+129
-57
lines changed

18 files changed

+129
-57
lines changed

viewer/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cognite/reveal",
3-
"version": "4.23.4",
3+
"version": "4.24.0",
44
"description": "WebGL based 3D viewer for CAD and point clouds processed in Cognite Data Fusion.",
55
"homepage": "https://github.com/cognitedata/reveal/tree/master/viewer",
66
"repository": {
@@ -81,7 +81,7 @@
8181
},
8282
"devDependencies": {
8383
"@azure/msal-browser": "^3.13.0",
84-
"@cognite/sdk": "^9.12.0",
84+
"@cognite/sdk": "^10.0.0",
8585
"@microsoft/api-extractor": "^7.43.1",
8686
"@types/dat.gui": "^0.7.13",
8787
"@types/gl": "^6.0.5",
@@ -145,7 +145,7 @@
145145
"workerize-loader": "^2.0.2"
146146
},
147147
"peerDependencies": {
148-
"@cognite/sdk": "^7.16.0 || ^8.0.0",
148+
"@cognite/sdk": "^10.0.0",
149149
"three": "0.174.0"
150150
},
151151
"glslify": {

viewer/packages/360-images/src/annotation/ImageAnnotationObject.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright 2023 Cognite AS
33
*/
44

5-
import { AnnotationsCogniteAnnotationTypesImagesAssetLink, AnnotationsObjectDetection } from '@cognite/sdk';
5+
import { AnnotationsObjectDetection, AnnotationsTypesImagesAssetLink } from '@cognite/sdk';
66
import { CoreDmImage360Annotation, DataSourceType, Image360FileDescriptor } from '@reveal/data-providers';
77

88
import { Color, Matrix4, Vector3, Mesh, MeshBasicMaterial, DoubleSide, Object3D, Group, Raycaster } from 'three';
@@ -82,7 +82,7 @@ export class ImageAnnotationObject<T extends DataSourceType> implements Image360
8282
}
8383

8484
private static createAssetLinkAnnotationData(
85-
assetLink: AnnotationsCogniteAnnotationTypesImagesAssetLink
85+
assetLink: AnnotationsTypesImagesAssetLink
8686
): ImageAnnotationObjectGeometryData | undefined {
8787
const objectRegion = assetLink.objectRegion;
8888
if (objectRegion === undefined) {

viewer/packages/360-images/src/annotation/typeGuards.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
*/
44
import {
55
AnnotationData,
6-
AnnotationsCogniteAnnotationTypesImagesAssetLink,
76
AnnotationsObjectDetection,
7+
AnnotationsTypesImagesAssetLink,
88
AnnotationType
99
} from '@cognite/sdk';
1010
import { DataSourceType, DMDataSourceType } from '@reveal/data-providers';
@@ -33,7 +33,7 @@ export function isAnnotationsObjectDetection(
3333
export function isAnnotationAssetLink(
3434
annotationType: AnnotationType,
3535
annotation: AnnotationData
36-
): annotation is AnnotationsCogniteAnnotationTypesImagesAssetLink {
37-
const link = annotation as AnnotationsCogniteAnnotationTypesImagesAssetLink;
36+
): annotation is AnnotationsTypesImagesAssetLink {
37+
const link = annotation as AnnotationsTypesImagesAssetLink;
3838
return annotationType === 'images.AssetLink' && link.text !== undefined && link.textRegion !== undefined;
3939
}

viewer/packages/cad-styling/src/AssetNodeCollection.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { AssetMapping3D, CogniteClient } from '@cognite/sdk';
1616

1717
import cloneDeep from 'lodash/cloneDeep';
1818
import { CdfModelNodeCollectionDataProvider } from './CdfModelNodeCollectionDataProvider';
19+
import { isCdfAssetMapping } from '@reveal/utilities';
1920

2021
/**
2122
* Represents a set of nodes associated with an [asset in Cognite Fusion]{@link https://docs.cognite.com/api/v1/#tag/Assets}
@@ -59,7 +60,10 @@ export class AssetNodeCollection extends NodeCollection {
5960
this._fetchResultHelper.interrupt();
6061
}
6162
const fetchResultHelper = new PopulateIndexSetFromPagedResponseHelper<AssetMapping3D>(
62-
assetMappings => assetMappings.map(mapping => new NumericRange(mapping.treeIndex, mapping.subtreeSize)),
63+
assetMappings =>
64+
assetMappings
65+
.filter(isCdfAssetMapping)
66+
.map(mapping => new NumericRange(mapping.treeIndex, mapping.subtreeSize)),
6367
mappings => this.fetchBoundingBoxesForAssetMappings(mappings),
6468
() => this.notifyChanged()
6569
);

viewer/packages/data-providers/src/image-360-data-providers/Cdf360ImageAnnotationProvider.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import {
99
CogniteClient,
1010
IdEither,
1111
CogniteInternalId,
12-
AnnotationsCogniteAnnotationTypesImagesAssetLink,
1312
AnnotationFilterProps,
1413
AnnotationsAssetRef,
1514
InternalId,
16-
ExternalId
15+
ExternalId,
16+
AnnotationsTypesImagesAssetLink
1717
} from '@cognite/sdk';
1818
import {
1919
Image360AnnotationFilterDelegate,
@@ -77,7 +77,7 @@ export class Cdf360ImageAnnotationProvider implements Image360AnnotationProvider
7777
const annotations = await revision.getAnnotations();
7878

7979
return annotations.filter(a => {
80-
const assetLink = a.annotation.data as AnnotationsCogniteAnnotationTypesImagesAssetLink;
80+
const assetLink = a.annotation.data as AnnotationsTypesImagesAssetLink;
8181
return assetLink.assetRef !== undefined && matchesAssetRef(assetLink, asset);
8282
});
8383
}
@@ -208,7 +208,7 @@ export class Cdf360ImageAnnotationProvider implements Image360AnnotationProvider
208208
}
209209
}
210210

211-
function matchesAssetRef(assetLink: AnnotationsCogniteAnnotationTypesImagesAssetLink, matchRef: IdEither): boolean {
211+
function matchesAssetRef(assetLink: AnnotationsTypesImagesAssetLink, matchRef: IdEither): boolean {
212212
return (
213213
((matchRef as InternalId).id !== undefined && assetLink.assetRef.id === (matchRef as InternalId).id) ||
214214
((matchRef as ExternalId).externalId !== undefined &&

viewer/packages/data-providers/src/image-360-data-providers/Cdf360ImageFileProvider.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import zipWith from 'lodash/zipWith';
55
import { Image360Face, Image360FileDescriptor, Image360FileProvider } from '../types';
66
import { CdfImageFileProvider } from './CdfImageFileProvider';
7-
import { CogniteClient, InternalId } from '@cognite/sdk/dist/src';
7+
import { CogniteClient, InternalId } from '@cognite/sdk';
88

99
export class Cdf360ImageFileProvider implements Image360FileProvider {
1010
private readonly _imageFileProvider: CdfImageFileProvider;

viewer/packages/data-providers/src/image-360-data-providers/CoreDm360ImageAnnotationProvider.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
} from '@reveal/360-images';
1818
import { isSameImage360RevisionId } from './shared';
1919
import { fetchCoreDm360AnnotationsForRevision } from './cdm/fetchCoreDm360AnnotationsForRevision';
20-
import { CogniteClient } from '@cognite/sdk/dist/src';
20+
import { CogniteClient } from '@cognite/sdk';
2121
import { fetchAnnotationsForInstance, Image360AnnotationsForInstanceResult } from './cdm/fetchAnnotationsForInstance';
2222
import { fetchCoreDm360AnnotationsForCollection } from './cdm/fetchCoreDm360AnnotationsForCollection';
2323
import { DMInstanceKey, dmInstanceRefToKey } from '@reveal/utilities';

viewer/packages/data-providers/src/image-360-data-providers/shared.ts

+3-10
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33
*/
44
import { Image360RevisionId, ImageAssetLinkAnnotationInfo } from '../types';
55
import { DataSourceType } from '../DataSourceType';
6-
import {
7-
AnnotationData,
8-
AnnotationModel,
9-
AnnotationsCogniteAnnotationTypesImagesAssetLink,
10-
Metadata
11-
} from '@cognite/sdk';
6+
import { AnnotationData, AnnotationModel, AnnotationsTypesImagesAssetLink, Metadata } from '@cognite/sdk';
127
import {
138
Image360DataModelIdentifier,
149
Image360LegacyDataModelIdentifier
@@ -69,9 +64,7 @@ export function isImageAssetLinkAnnotation(annotation: AnnotationModel): annotat
6964
return isAssetLinkAnnotationData(annotation.data);
7065
}
7166

72-
function isAssetLinkAnnotationData(
73-
annotationData: AnnotationData
74-
): annotationData is AnnotationsCogniteAnnotationTypesImagesAssetLink {
75-
const data = annotationData as AnnotationsCogniteAnnotationTypesImagesAssetLink;
67+
function isAssetLinkAnnotationData(annotationData: AnnotationData): annotationData is AnnotationsTypesImagesAssetLink {
68+
const data = annotationData as AnnotationsTypesImagesAssetLink;
7669
return data.text !== undefined && data.textRegion !== undefined && data.assetRef !== undefined;
7770
}

viewer/packages/data-providers/src/pointcloud-stylable-object-providers/CdfPointCloudStylableObjectProvider.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
CogniteClient,
77
AnnotationData,
88
AnnotationsBoundingVolume,
9-
AnnotationsCogniteAnnotationTypesPrimitivesGeometry3DGeometry as AnnotationsGeometry
9+
AnnotationsTypesPrimitivesGeometry3DGeometry as AnnotationsGeometry
1010
} from '@cognite/sdk';
1111
import { IShape, Box, Cylinder } from '@reveal/utilities';
1212
import assert from 'assert';

viewer/packages/data-providers/src/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* Copyright 2021 Cognite AS
33
*/
4-
import { AnnotationModel, AnnotationsCogniteAnnotationTypesImagesAssetLink, IdEither } from '@cognite/sdk';
4+
import { AnnotationModel, AnnotationsTypesImagesAssetLink, IdEither } from '@cognite/sdk';
55
import * as THREE from 'three';
66
import { ClassicDataSourceType, DataSourceType, DMDataSourceType } from './DataSourceType';
77
import {
@@ -103,7 +103,7 @@ export type ImageAssetLinkAnnotationInfo = Omit<AnnotationModel, 'data'> & {
103103
/**
104104
* The data associated with the image asset link
105105
*/
106-
data: AnnotationsCogniteAnnotationTypesImagesAssetLink;
106+
data: AnnotationsTypesImagesAssetLink;
107107
};
108108

109109
export type Historical360ImageSet<T extends DataSourceType> = Image360RevisionDescriptor<T> & {

viewer/packages/data-providers/src/utilities/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright 2024 Cognite AS
33
*/
44

5-
import { TableExpressionEqualsFilterV3 } from '@cognite/sdk/dist/src';
5+
import { TableExpressionEqualsFilterV3 } from '@cognite/sdk';
66
import { PointCloudObject, PointCloudObjectMetadata } from '../pointcloud-stylable-object-providers/types';
77
import { StylableObject } from '../pointcloud-stylable-object-providers/StylableObject';
88
import { ClassicDataSourceType, DMDataSourceType, DataSourceType } from '../DataSourceType';

viewer/packages/utilities/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export { createUint8View } from './src/createUint8View';
8787
export * from './src/workers/workerize-transferable';
8888

8989
export * from './src/fdm';
90+
export * from './src/assetMappings';
9091

9192
export * from './src/shapes';
9293
export * from './src/linalg';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/*!
2+
* Copyright 2025 Cognite AS
3+
*/
4+
export { isCdfAssetMapping } from './isCdfAssetMapping';
5+
export { CdfAssetMapping } from './types';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*!
2+
* Copyright 2025 Cognite AS
3+
*/
4+
import { isCdfAssetMapping } from './isCdfAssetMapping';
5+
6+
describe(isCdfAssetMapping.name, () => {
7+
test('correctly recognizes a CDF asset mapping', () => {
8+
expect(
9+
isCdfAssetMapping({
10+
assetId: 123,
11+
nodeId: 345,
12+
treeIndex: 3,
13+
subtreeSize: 2
14+
})
15+
).toBe(true);
16+
});
17+
18+
test('correctly recognizes that an incomplete mapping is not a CDF asset mapping', () => {
19+
expect(
20+
isCdfAssetMapping({
21+
assetId: 123,
22+
nodeId: 234
23+
})
24+
).toBe(false);
25+
});
26+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*!
2+
* Copyright 2025 Cognite AS
3+
*/
4+
import { AssetMapping3D } from '@cognite/sdk';
5+
import { CdfAssetMapping } from './types';
6+
7+
/**
8+
* Type guard checking whether the asset mapping contains treeIndex and subtreeSize
9+
*/
10+
export function isCdfAssetMapping(assetMapping: AssetMapping3D): assetMapping is CdfAssetMapping {
11+
return assetMapping.treeIndex !== undefined && assetMapping.subtreeSize !== undefined;
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*!
2+
* Copyright 2025 Cognite AS
3+
*/
4+
import { CogniteInternalId, UnitDMSUniqueIdentifier } from '@cognite/sdk';
5+
6+
/**
7+
* A CAD asset mapping that is guaranteed to contain treeIndex and subtreeSize. The only CAD asset
8+
* mappings that don't satisfy this rule are from very old CAD models (about pre-2023).
9+
*/
10+
export type CdfAssetMapping = {
11+
/**
12+
* Tree index of the mapped node
13+
*/
14+
treeIndex: number;
15+
/**
16+
* Size of the subtree with the mapped node as root
17+
*/
18+
subtreeSize: number;
19+
/**
20+
* The node id of the mapped node
21+
*/
22+
nodeId: CogniteInternalId;
23+
/**
24+
* The id of the asset mapped to the node
25+
*/
26+
assetId: CogniteInternalId;
27+
/**
28+
* The ID of the associated Cognite Asset instance from Core Data Model.
29+
*/
30+
assetInstanceId?: UnitDMSUniqueIdentifier;
31+
};

viewer/reveal.api.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
import { AnnotationModel } from '@cognite/sdk';
88
import { AnnotationsAssetRef } from '@cognite/sdk';
9-
import { AnnotationsCogniteAnnotationTypesImagesAssetLink } from '@cognite/sdk';
109
import { AnnotationStatus } from '@cognite/sdk';
10+
import { AnnotationsTypesImagesAssetLink } from '@cognite/sdk';
1111
import { Box3 } from 'three';
1212
import { Camera } from 'three';
1313
import { CogniteClient } from '@cognite/sdk';
@@ -1390,7 +1390,7 @@ export type Image360WithCollection<T extends DataSourceType = ClassicDataSourceT
13901390

13911391
// @public
13921392
export type ImageAssetLinkAnnotationInfo = Omit<AnnotationModel, 'data'> & {
1393-
data: AnnotationsCogniteAnnotationTypesImagesAssetLink;
1393+
data: AnnotationsTypesImagesAssetLink;
13941394
};
13951395

13961396
// @public (undocumented)

0 commit comments

Comments
 (0)