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
|
@@ -10,6 +10,7 @@ var CogniteSdkAdapter = class {
|
|
|
10
10
|
constructor(client) {
|
|
11
11
|
this.client = client;
|
|
12
12
|
}
|
|
13
|
+
client;
|
|
13
14
|
async retrieveDataModels(ids, options) {
|
|
14
15
|
const response = await this.client.dataModels.retrieve(ids, options);
|
|
15
16
|
return {
|
|
@@ -19,6 +20,11 @@ var CogniteSdkAdapter = class {
|
|
|
19
20
|
}))
|
|
20
21
|
};
|
|
21
22
|
}
|
|
23
|
+
async retrieveViews(ids) {
|
|
24
|
+
const cleanIds = ids.map(({ space, externalId, version }) => ({ space, externalId, version }));
|
|
25
|
+
const response = await this.client.views.retrieve(cleanIds);
|
|
26
|
+
return { items: response.items };
|
|
27
|
+
}
|
|
22
28
|
async queryInstances(request) {
|
|
23
29
|
const response = await this.client.instances.query(
|
|
24
30
|
request
|
|
@@ -525,6 +531,7 @@ var QueryValidator = class {
|
|
|
525
531
|
constructor(viewMapper) {
|
|
526
532
|
this.viewMapper = viewMapper;
|
|
527
533
|
}
|
|
534
|
+
viewMapper;
|
|
528
535
|
async validate(options, rootView) {
|
|
529
536
|
const errors = [];
|
|
530
537
|
errors.push(...this.validateOptionsShape(options, rootView));
|
|
@@ -694,6 +701,7 @@ function isEmptyObject(value) {
|
|
|
694
701
|
return value != null && typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0;
|
|
695
702
|
}
|
|
696
703
|
var AggregateValidator = class {
|
|
704
|
+
queryValidator;
|
|
697
705
|
constructor(viewMapper) {
|
|
698
706
|
this.queryValidator = new QueryValidator(viewMapper);
|
|
699
707
|
}
|
|
@@ -901,6 +909,7 @@ var QueryResultValidator = class {
|
|
|
901
909
|
constructor(viewMapper) {
|
|
902
910
|
this.viewMapper = viewMapper;
|
|
903
911
|
}
|
|
912
|
+
viewMapper;
|
|
904
913
|
async parseItems(rootViewExternalId, items, select) {
|
|
905
914
|
const rootView = await this.viewMapper.getView(rootViewExternalId);
|
|
906
915
|
const schema = await this.buildResultSchema(rootView, MAX_DEPENDENCY_DEPTH, select);
|
|
@@ -1062,6 +1071,8 @@ var FilterMapper = class {
|
|
|
1062
1071
|
this.viewMapper = viewMapper;
|
|
1063
1072
|
this.cognite = cognite;
|
|
1064
1073
|
}
|
|
1074
|
+
viewMapper;
|
|
1075
|
+
cognite;
|
|
1065
1076
|
async map(input, rootView) {
|
|
1066
1077
|
const result = [];
|
|
1067
1078
|
const searchQueries = {};
|
|
@@ -1206,6 +1217,9 @@ var AggregateMapper = class {
|
|
|
1206
1217
|
this.filterMapper = new FilterMapper(viewMapper, cognite);
|
|
1207
1218
|
this.validator = new AggregateValidator(viewMapper);
|
|
1208
1219
|
}
|
|
1220
|
+
viewMapper;
|
|
1221
|
+
filterMapper;
|
|
1222
|
+
validator;
|
|
1209
1223
|
async map(options) {
|
|
1210
1224
|
const { viewExternalId, filters, groupBy, aggregate } = options;
|
|
1211
1225
|
const rootView = await this.viewMapper.getView(viewExternalId);
|
|
@@ -1283,8 +1297,9 @@ var CHUNK_SIZE = 100;
|
|
|
1283
1297
|
var DatapointsMapper = class {
|
|
1284
1298
|
constructor(cognite) {
|
|
1285
1299
|
this.cognite = cognite;
|
|
1286
|
-
this.validator = new DatapointsValidator();
|
|
1287
1300
|
}
|
|
1301
|
+
cognite;
|
|
1302
|
+
validator = new DatapointsValidator();
|
|
1288
1303
|
async retrieve(options) {
|
|
1289
1304
|
this.validator.validateRetrieve(options);
|
|
1290
1305
|
const cogniteOptions = this.toCogniteOptions(options);
|
|
@@ -1405,6 +1420,7 @@ var FilesMapper = class {
|
|
|
1405
1420
|
constructor(cognite) {
|
|
1406
1421
|
this.cognite = cognite;
|
|
1407
1422
|
}
|
|
1423
|
+
cognite;
|
|
1408
1424
|
async upload(fileInfo, content) {
|
|
1409
1425
|
const { space, externalId, ...rest } = fileInfo;
|
|
1410
1426
|
const result = await this.cognite.uploadFile(
|
|
@@ -1476,6 +1492,10 @@ var QueryMapper = class {
|
|
|
1476
1492
|
this.sortMapper = new SortMapper();
|
|
1477
1493
|
this.validator = new QueryValidator(viewMapper);
|
|
1478
1494
|
}
|
|
1495
|
+
viewMapper;
|
|
1496
|
+
filterMapper;
|
|
1497
|
+
sortMapper;
|
|
1498
|
+
validator;
|
|
1479
1499
|
async map(options) {
|
|
1480
1500
|
const {
|
|
1481
1501
|
viewExternalId,
|
|
@@ -1627,6 +1647,7 @@ var QueryResultMapper = class {
|
|
|
1627
1647
|
constructor(viewMapper) {
|
|
1628
1648
|
this.viewMapper = viewMapper;
|
|
1629
1649
|
}
|
|
1650
|
+
viewMapper;
|
|
1630
1651
|
async mapNodes(rootNode, queryResult) {
|
|
1631
1652
|
if (!(rootNode in queryResult)) {
|
|
1632
1653
|
throw new Error(`"${rootNode}" is not available in the query result`);
|
|
@@ -1786,8 +1807,10 @@ var UpsertMapper = class {
|
|
|
1786
1807
|
constructor(viewMapper, cognite) {
|
|
1787
1808
|
this.viewMapper = viewMapper;
|
|
1788
1809
|
this.cognite = cognite;
|
|
1789
|
-
this.validator = new UpsertValidator();
|
|
1790
1810
|
}
|
|
1811
|
+
viewMapper;
|
|
1812
|
+
cognite;
|
|
1813
|
+
validator = new UpsertValidator();
|
|
1791
1814
|
async map(options) {
|
|
1792
1815
|
const rootView = await this.viewMapper.getView(options.viewExternalId);
|
|
1793
1816
|
this.validator.validate(options, rootView);
|
|
@@ -1994,8 +2017,10 @@ var ViewMapper = class {
|
|
|
1994
2017
|
constructor(cognite, dataModelId) {
|
|
1995
2018
|
this.cognite = cognite;
|
|
1996
2019
|
this.dataModelId = dataModelId;
|
|
1997
|
-
this.cachePromise = null;
|
|
1998
2020
|
}
|
|
2021
|
+
cognite;
|
|
2022
|
+
dataModelId;
|
|
2023
|
+
cachePromise = null;
|
|
1999
2024
|
async getView(externalId) {
|
|
2000
2025
|
const views = await this.loadViews();
|
|
2001
2026
|
const view = views.get(externalId);
|
|
@@ -2035,25 +2060,60 @@ var ViewMapper = class {
|
|
|
2035
2060
|
for (const view of dm.views ?? []) {
|
|
2036
2061
|
views.set(view.externalId, view);
|
|
2037
2062
|
}
|
|
2063
|
+
await this.loadDependencyViews(views);
|
|
2038
2064
|
return views;
|
|
2039
2065
|
}
|
|
2066
|
+
async loadDependencyViews(views) {
|
|
2067
|
+
const pending = /* @__PURE__ */ new Map();
|
|
2068
|
+
for (const view of views.values()) {
|
|
2069
|
+
for (const property of Object.values(view.properties)) {
|
|
2070
|
+
for (const ref of collectPropertyRefs(property)) {
|
|
2071
|
+
if (!views.has(ref.externalId) && !pending.has(ref.externalId)) {
|
|
2072
|
+
pending.set(ref.externalId, ref);
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
if (pending.size === 0) return;
|
|
2078
|
+
const sizeBefore = views.size;
|
|
2079
|
+
const fetched = await this.cognite.retrieveViews(Array.from(pending.values()));
|
|
2080
|
+
for (const view of fetched.items) {
|
|
2081
|
+
views.set(view.externalId, view);
|
|
2082
|
+
}
|
|
2083
|
+
if (views.size > sizeBefore) {
|
|
2084
|
+
await this.loadDependencyViews(views);
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
2040
2087
|
};
|
|
2088
|
+
function collectPropertyRefs(property) {
|
|
2089
|
+
if (isViewPropertyDefinition(property)) {
|
|
2090
|
+
const source = getDirectRelationSource(property);
|
|
2091
|
+
return source ? [source] : [];
|
|
2092
|
+
}
|
|
2093
|
+
if (isReverseDirectRelation(property)) {
|
|
2094
|
+
return [property.source, property.through.source];
|
|
2095
|
+
}
|
|
2096
|
+
if (isEdgeConnection(property)) {
|
|
2097
|
+
return [property.source];
|
|
2098
|
+
}
|
|
2099
|
+
return [];
|
|
2100
|
+
}
|
|
2041
2101
|
|
|
2042
2102
|
// src/client.ts
|
|
2043
2103
|
var APPLY_ITEM_LIMIT = 1e3;
|
|
2044
2104
|
var IndustrialModelClient = class {
|
|
2105
|
+
cognite;
|
|
2106
|
+
queryMapper;
|
|
2107
|
+
aggregateMapper;
|
|
2108
|
+
upsertMapper;
|
|
2109
|
+
aggregateResultMapper;
|
|
2110
|
+
resultMapper;
|
|
2111
|
+
datapointsMapper;
|
|
2112
|
+
filesMapper;
|
|
2113
|
+
deleteValidator = new DeleteValidator();
|
|
2114
|
+
resultValidator;
|
|
2115
|
+
validateResults;
|
|
2045
2116
|
constructor(client, dataModelId, options = {}) {
|
|
2046
|
-
this.deleteValidator = new DeleteValidator();
|
|
2047
|
-
this.files = {
|
|
2048
|
-
upload: (fileInfo, content) => this.filesMapper.upload(fileInfo, content),
|
|
2049
|
-
getDownloadUrls: (nodeIds) => this.filesMapper.getDownloadUrls(nodeIds)
|
|
2050
|
-
};
|
|
2051
|
-
this.datapoints = {
|
|
2052
|
-
retrieve: (options) => this.datapointsMapper.retrieve(options),
|
|
2053
|
-
latest: (options) => this.datapointsMapper.retrieveLatest(options),
|
|
2054
|
-
insert: (items) => this.datapointsMapper.insert(items),
|
|
2055
|
-
delete: (ranges) => this.datapointsMapper.delete(ranges)
|
|
2056
|
-
};
|
|
2057
2117
|
const cognite = createCogniteAdapter(client);
|
|
2058
2118
|
this.cognite = cognite;
|
|
2059
2119
|
const viewMapper = new ViewMapper(cognite, dataModelId);
|
|
@@ -2079,6 +2139,16 @@ var IndustrialModelClient = class {
|
|
|
2079
2139
|
const execute = (options) => this.upsertInternal(options);
|
|
2080
2140
|
return execute;
|
|
2081
2141
|
}
|
|
2142
|
+
files = {
|
|
2143
|
+
upload: (fileInfo, content) => this.filesMapper.upload(fileInfo, content),
|
|
2144
|
+
getDownloadUrls: (nodeIds) => this.filesMapper.getDownloadUrls(nodeIds)
|
|
2145
|
+
};
|
|
2146
|
+
datapoints = {
|
|
2147
|
+
retrieve: (options) => this.datapointsMapper.retrieve(options),
|
|
2148
|
+
latest: (options) => this.datapointsMapper.retrieveLatest(options),
|
|
2149
|
+
insert: (items) => this.datapointsMapper.insert(items),
|
|
2150
|
+
delete: (ranges) => this.datapointsMapper.delete(ranges)
|
|
2151
|
+
};
|
|
2082
2152
|
async delete(items) {
|
|
2083
2153
|
this.deleteValidator.validateItems(items);
|
|
2084
2154
|
const deleteItems = items.map((item) => ({
|
|
@@ -2186,6 +2256,7 @@ var COGNITE_CORE_DATA_MODEL = {
|
|
|
2186
2256
|
version: "v1"
|
|
2187
2257
|
};
|
|
2188
2258
|
var CogniteCoreClient = class {
|
|
2259
|
+
model;
|
|
2189
2260
|
constructor(client, options = {}) {
|
|
2190
2261
|
this.model = new IndustrialModelClient(client, COGNITE_CORE_DATA_MODEL, options);
|
|
2191
2262
|
}
|