industrial-model 0.11.2 → 0.12.0
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.
- package/README.md +17 -0
- package/dist/calculator/index.cjs +892 -0
- package/dist/calculator/index.cjs.map +1 -0
- package/dist/calculator/index.d.cts +250 -0
- package/dist/calculator/index.d.ts +250 -0
- package/dist/calculator/index.js +879 -0
- package/dist/calculator/index.js.map +1 -0
- package/dist/cli/index.cjs +191 -169
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cognite-core/index.cjs +85 -14
- package/dist/cognite-core/index.cjs.map +1 -1
- package/dist/cognite-core/index.d.cts +1 -1
- package/dist/cognite-core/index.d.ts +1 -1
- package/dist/cognite-core/index.js +85 -14
- package/dist/cognite-core/index.js.map +1 -1
- package/dist/index.cjs +84 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +84 -14
- package/dist/index.js.map +1 -1
- package/dist/{types-69DRhgww.d.cts → types-CFkHwXW6.d.cts} +362 -1
- package/dist/{types-69DRhgww.d.ts → types-CFkHwXW6.d.ts} +362 -1
- package/package.json +18 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CogniteClient } from '@cognite/sdk';
|
|
2
|
-
import { v as IndustrialModel, N as NodeId, c as AggregateOptions, d as AggregateResult, e as AggregateResultItem, B as QuerySelect, x as QueryOptions, y as QueryResult, z as QueryResultItem, G as UpsertOptions, J as UpsertResult, I as IndustrialModelClientOptions, b as DeleteResult, a as DatapointsExecutor } from '../types-
|
|
2
|
+
import { v as IndustrialModel, N as NodeId, c as AggregateOptions, d as AggregateResult, e as AggregateResultItem, B as QuerySelect, x as QueryOptions, y as QueryResult, z as QueryResultItem, G as UpsertOptions, J as UpsertResult, I as IndustrialModelClientOptions, b as DeleteResult, a as DatapointsExecutor } from '../types-CFkHwXW6.cjs';
|
|
3
3
|
|
|
4
4
|
type CogniteCoreViewExternalId = "CogniteDescribable" | "CogniteSourceable" | "CogniteSourceSystem" | "CogniteSchedulable" | "CogniteVisualizable" | "Cognite3DTransformation" | "CogniteCubeMap" | "Cognite3DObject" | "Cognite3DModel" | "CogniteCADModel" | "Cognite3DRevision" | "CognitePointCloudModel" | "Cognite360ImageModel" | "CogniteCADRevision" | "CognitePointCloudRevision" | "Cognite360ImageCollection" | "CogniteCADNode" | "CognitePointCloudVolume" | "Cognite360Image" | "Cognite360ImageStation" | "Cognite360ImageAnnotation" | "CogniteAsset" | "CogniteAssetClass" | "CogniteAssetType" | "CogniteEquipment" | "CogniteEquipmentType" | "CogniteFile" | "CogniteFileCategory" | "CogniteActivity" | "CogniteTimeSeries" | "CogniteAnnotation" | "CogniteDiagramAnnotation" | "CogniteUnit";
|
|
5
5
|
type CogniteDescribable = IndustrialModel<{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CogniteClient } from '@cognite/sdk';
|
|
2
|
-
import { v as IndustrialModel, N as NodeId, c as AggregateOptions, d as AggregateResult, e as AggregateResultItem, B as QuerySelect, x as QueryOptions, y as QueryResult, z as QueryResultItem, G as UpsertOptions, J as UpsertResult, I as IndustrialModelClientOptions, b as DeleteResult, a as DatapointsExecutor } from '../types-
|
|
2
|
+
import { v as IndustrialModel, N as NodeId, c as AggregateOptions, d as AggregateResult, e as AggregateResultItem, B as QuerySelect, x as QueryOptions, y as QueryResult, z as QueryResultItem, G as UpsertOptions, J as UpsertResult, I as IndustrialModelClientOptions, b as DeleteResult, a as DatapointsExecutor } from '../types-CFkHwXW6.js';
|
|
3
3
|
|
|
4
4
|
type CogniteCoreViewExternalId = "CogniteDescribable" | "CogniteSourceable" | "CogniteSourceSystem" | "CogniteSchedulable" | "CogniteVisualizable" | "Cognite3DTransformation" | "CogniteCubeMap" | "Cognite3DObject" | "Cognite3DModel" | "CogniteCADModel" | "Cognite3DRevision" | "CognitePointCloudModel" | "Cognite360ImageModel" | "CogniteCADRevision" | "CognitePointCloudRevision" | "Cognite360ImageCollection" | "CogniteCADNode" | "CognitePointCloudVolume" | "Cognite360Image" | "Cognite360ImageStation" | "Cognite360ImageAnnotation" | "CogniteAsset" | "CogniteAssetClass" | "CogniteAssetType" | "CogniteEquipment" | "CogniteEquipmentType" | "CogniteFile" | "CogniteFileCategory" | "CogniteActivity" | "CogniteTimeSeries" | "CogniteAnnotation" | "CogniteDiagramAnnotation" | "CogniteUnit";
|
|
5
5
|
type CogniteDescribable = IndustrialModel<{
|
|
@@ -8,6 +8,7 @@ var CogniteSdkAdapter = class {
|
|
|
8
8
|
constructor(client) {
|
|
9
9
|
this.client = client;
|
|
10
10
|
}
|
|
11
|
+
client;
|
|
11
12
|
async retrieveDataModels(ids, options) {
|
|
12
13
|
const response = await this.client.dataModels.retrieve(ids, options);
|
|
13
14
|
return {
|
|
@@ -17,6 +18,11 @@ var CogniteSdkAdapter = class {
|
|
|
17
18
|
}))
|
|
18
19
|
};
|
|
19
20
|
}
|
|
21
|
+
async retrieveViews(ids) {
|
|
22
|
+
const cleanIds = ids.map(({ space, externalId, version }) => ({ space, externalId, version }));
|
|
23
|
+
const response = await this.client.views.retrieve(cleanIds);
|
|
24
|
+
return { items: response.items };
|
|
25
|
+
}
|
|
20
26
|
async queryInstances(request) {
|
|
21
27
|
const response = await this.client.instances.query(
|
|
22
28
|
request
|
|
@@ -523,6 +529,7 @@ var QueryValidator = class {
|
|
|
523
529
|
constructor(viewMapper) {
|
|
524
530
|
this.viewMapper = viewMapper;
|
|
525
531
|
}
|
|
532
|
+
viewMapper;
|
|
526
533
|
async validate(options, rootView) {
|
|
527
534
|
const errors = [];
|
|
528
535
|
errors.push(...this.validateOptionsShape(options, rootView));
|
|
@@ -692,6 +699,7 @@ function isEmptyObject(value) {
|
|
|
692
699
|
return value != null && typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0;
|
|
693
700
|
}
|
|
694
701
|
var AggregateValidator = class {
|
|
702
|
+
queryValidator;
|
|
695
703
|
constructor(viewMapper) {
|
|
696
704
|
this.queryValidator = new QueryValidator(viewMapper);
|
|
697
705
|
}
|
|
@@ -899,6 +907,7 @@ var QueryResultValidator = class {
|
|
|
899
907
|
constructor(viewMapper) {
|
|
900
908
|
this.viewMapper = viewMapper;
|
|
901
909
|
}
|
|
910
|
+
viewMapper;
|
|
902
911
|
async parseItems(rootViewExternalId, items, select) {
|
|
903
912
|
const rootView = await this.viewMapper.getView(rootViewExternalId);
|
|
904
913
|
const schema = await this.buildResultSchema(rootView, MAX_DEPENDENCY_DEPTH, select);
|
|
@@ -1060,6 +1069,8 @@ var FilterMapper = class {
|
|
|
1060
1069
|
this.viewMapper = viewMapper;
|
|
1061
1070
|
this.cognite = cognite;
|
|
1062
1071
|
}
|
|
1072
|
+
viewMapper;
|
|
1073
|
+
cognite;
|
|
1063
1074
|
async map(input, rootView) {
|
|
1064
1075
|
const result = [];
|
|
1065
1076
|
const searchQueries = {};
|
|
@@ -1204,6 +1215,9 @@ var AggregateMapper = class {
|
|
|
1204
1215
|
this.filterMapper = new FilterMapper(viewMapper, cognite);
|
|
1205
1216
|
this.validator = new AggregateValidator(viewMapper);
|
|
1206
1217
|
}
|
|
1218
|
+
viewMapper;
|
|
1219
|
+
filterMapper;
|
|
1220
|
+
validator;
|
|
1207
1221
|
async map(options) {
|
|
1208
1222
|
const { viewExternalId, filters, groupBy, aggregate } = options;
|
|
1209
1223
|
const rootView = await this.viewMapper.getView(viewExternalId);
|
|
@@ -1281,8 +1295,9 @@ var CHUNK_SIZE = 100;
|
|
|
1281
1295
|
var DatapointsMapper = class {
|
|
1282
1296
|
constructor(cognite) {
|
|
1283
1297
|
this.cognite = cognite;
|
|
1284
|
-
this.validator = new DatapointsValidator();
|
|
1285
1298
|
}
|
|
1299
|
+
cognite;
|
|
1300
|
+
validator = new DatapointsValidator();
|
|
1286
1301
|
async retrieve(options) {
|
|
1287
1302
|
this.validator.validateRetrieve(options);
|
|
1288
1303
|
const cogniteOptions = this.toCogniteOptions(options);
|
|
@@ -1403,6 +1418,7 @@ var FilesMapper = class {
|
|
|
1403
1418
|
constructor(cognite) {
|
|
1404
1419
|
this.cognite = cognite;
|
|
1405
1420
|
}
|
|
1421
|
+
cognite;
|
|
1406
1422
|
async upload(fileInfo, content) {
|
|
1407
1423
|
const { space, externalId, ...rest } = fileInfo;
|
|
1408
1424
|
const result = await this.cognite.uploadFile(
|
|
@@ -1474,6 +1490,10 @@ var QueryMapper = class {
|
|
|
1474
1490
|
this.sortMapper = new SortMapper();
|
|
1475
1491
|
this.validator = new QueryValidator(viewMapper);
|
|
1476
1492
|
}
|
|
1493
|
+
viewMapper;
|
|
1494
|
+
filterMapper;
|
|
1495
|
+
sortMapper;
|
|
1496
|
+
validator;
|
|
1477
1497
|
async map(options) {
|
|
1478
1498
|
const {
|
|
1479
1499
|
viewExternalId,
|
|
@@ -1625,6 +1645,7 @@ var QueryResultMapper = class {
|
|
|
1625
1645
|
constructor(viewMapper) {
|
|
1626
1646
|
this.viewMapper = viewMapper;
|
|
1627
1647
|
}
|
|
1648
|
+
viewMapper;
|
|
1628
1649
|
async mapNodes(rootNode, queryResult) {
|
|
1629
1650
|
if (!(rootNode in queryResult)) {
|
|
1630
1651
|
throw new Error(`"${rootNode}" is not available in the query result`);
|
|
@@ -1784,8 +1805,10 @@ var UpsertMapper = class {
|
|
|
1784
1805
|
constructor(viewMapper, cognite) {
|
|
1785
1806
|
this.viewMapper = viewMapper;
|
|
1786
1807
|
this.cognite = cognite;
|
|
1787
|
-
this.validator = new UpsertValidator();
|
|
1788
1808
|
}
|
|
1809
|
+
viewMapper;
|
|
1810
|
+
cognite;
|
|
1811
|
+
validator = new UpsertValidator();
|
|
1789
1812
|
async map(options) {
|
|
1790
1813
|
const rootView = await this.viewMapper.getView(options.viewExternalId);
|
|
1791
1814
|
this.validator.validate(options, rootView);
|
|
@@ -1992,8 +2015,10 @@ var ViewMapper = class {
|
|
|
1992
2015
|
constructor(cognite, dataModelId) {
|
|
1993
2016
|
this.cognite = cognite;
|
|
1994
2017
|
this.dataModelId = dataModelId;
|
|
1995
|
-
this.cachePromise = null;
|
|
1996
2018
|
}
|
|
2019
|
+
cognite;
|
|
2020
|
+
dataModelId;
|
|
2021
|
+
cachePromise = null;
|
|
1997
2022
|
async getView(externalId) {
|
|
1998
2023
|
const views = await this.loadViews();
|
|
1999
2024
|
const view = views.get(externalId);
|
|
@@ -2033,25 +2058,60 @@ var ViewMapper = class {
|
|
|
2033
2058
|
for (const view of dm.views ?? []) {
|
|
2034
2059
|
views.set(view.externalId, view);
|
|
2035
2060
|
}
|
|
2061
|
+
await this.loadDependencyViews(views);
|
|
2036
2062
|
return views;
|
|
2037
2063
|
}
|
|
2064
|
+
async loadDependencyViews(views) {
|
|
2065
|
+
const pending = /* @__PURE__ */ new Map();
|
|
2066
|
+
for (const view of views.values()) {
|
|
2067
|
+
for (const property of Object.values(view.properties)) {
|
|
2068
|
+
for (const ref of collectPropertyRefs(property)) {
|
|
2069
|
+
if (!views.has(ref.externalId) && !pending.has(ref.externalId)) {
|
|
2070
|
+
pending.set(ref.externalId, ref);
|
|
2071
|
+
}
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
if (pending.size === 0) return;
|
|
2076
|
+
const sizeBefore = views.size;
|
|
2077
|
+
const fetched = await this.cognite.retrieveViews(Array.from(pending.values()));
|
|
2078
|
+
for (const view of fetched.items) {
|
|
2079
|
+
views.set(view.externalId, view);
|
|
2080
|
+
}
|
|
2081
|
+
if (views.size > sizeBefore) {
|
|
2082
|
+
await this.loadDependencyViews(views);
|
|
2083
|
+
}
|
|
2084
|
+
}
|
|
2038
2085
|
};
|
|
2086
|
+
function collectPropertyRefs(property) {
|
|
2087
|
+
if (isViewPropertyDefinition(property)) {
|
|
2088
|
+
const source = getDirectRelationSource(property);
|
|
2089
|
+
return source ? [source] : [];
|
|
2090
|
+
}
|
|
2091
|
+
if (isReverseDirectRelation(property)) {
|
|
2092
|
+
return [property.source, property.through.source];
|
|
2093
|
+
}
|
|
2094
|
+
if (isEdgeConnection(property)) {
|
|
2095
|
+
return [property.source];
|
|
2096
|
+
}
|
|
2097
|
+
return [];
|
|
2098
|
+
}
|
|
2039
2099
|
|
|
2040
2100
|
// src/client.ts
|
|
2041
2101
|
var APPLY_ITEM_LIMIT = 1e3;
|
|
2042
2102
|
var IndustrialModelClient = class {
|
|
2103
|
+
cognite;
|
|
2104
|
+
queryMapper;
|
|
2105
|
+
aggregateMapper;
|
|
2106
|
+
upsertMapper;
|
|
2107
|
+
aggregateResultMapper;
|
|
2108
|
+
resultMapper;
|
|
2109
|
+
datapointsMapper;
|
|
2110
|
+
filesMapper;
|
|
2111
|
+
deleteValidator = new DeleteValidator();
|
|
2112
|
+
resultValidator;
|
|
2113
|
+
validateResults;
|
|
2043
2114
|
constructor(client, dataModelId, options = {}) {
|
|
2044
|
-
this.deleteValidator = new DeleteValidator();
|
|
2045
|
-
this.files = {
|
|
2046
|
-
upload: (fileInfo, content) => this.filesMapper.upload(fileInfo, content),
|
|
2047
|
-
getDownloadUrls: (nodeIds) => this.filesMapper.getDownloadUrls(nodeIds)
|
|
2048
|
-
};
|
|
2049
|
-
this.datapoints = {
|
|
2050
|
-
retrieve: (options) => this.datapointsMapper.retrieve(options),
|
|
2051
|
-
latest: (options) => this.datapointsMapper.retrieveLatest(options),
|
|
2052
|
-
insert: (items) => this.datapointsMapper.insert(items),
|
|
2053
|
-
delete: (ranges) => this.datapointsMapper.delete(ranges)
|
|
2054
|
-
};
|
|
2055
2115
|
const cognite = createCogniteAdapter(client);
|
|
2056
2116
|
this.cognite = cognite;
|
|
2057
2117
|
const viewMapper = new ViewMapper(cognite, dataModelId);
|
|
@@ -2077,6 +2137,16 @@ var IndustrialModelClient = class {
|
|
|
2077
2137
|
const execute = (options) => this.upsertInternal(options);
|
|
2078
2138
|
return execute;
|
|
2079
2139
|
}
|
|
2140
|
+
files = {
|
|
2141
|
+
upload: (fileInfo, content) => this.filesMapper.upload(fileInfo, content),
|
|
2142
|
+
getDownloadUrls: (nodeIds) => this.filesMapper.getDownloadUrls(nodeIds)
|
|
2143
|
+
};
|
|
2144
|
+
datapoints = {
|
|
2145
|
+
retrieve: (options) => this.datapointsMapper.retrieve(options),
|
|
2146
|
+
latest: (options) => this.datapointsMapper.retrieveLatest(options),
|
|
2147
|
+
insert: (items) => this.datapointsMapper.insert(items),
|
|
2148
|
+
delete: (ranges) => this.datapointsMapper.delete(ranges)
|
|
2149
|
+
};
|
|
2080
2150
|
async delete(items) {
|
|
2081
2151
|
this.deleteValidator.validateItems(items);
|
|
2082
2152
|
const deleteItems = items.map((item) => ({
|
|
@@ -2184,6 +2254,7 @@ var COGNITE_CORE_DATA_MODEL = {
|
|
|
2184
2254
|
version: "v1"
|
|
2185
2255
|
};
|
|
2186
2256
|
var CogniteCoreClient = class {
|
|
2257
|
+
model;
|
|
2187
2258
|
constructor(client, options = {}) {
|
|
2188
2259
|
this.model = new IndustrialModelClient(client, COGNITE_CORE_DATA_MODEL, options);
|
|
2189
2260
|
}
|