industrial-model 0.7.0 → 0.9.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 +181 -0
- package/dist/cli/index.cjs +6797 -0
- package/dist/cli/index.cjs.map +1 -0
- package/dist/cognite-core/index.cjs +349 -20
- package/dist/cognite-core/index.cjs.map +1 -1
- package/dist/cognite-core/index.d.cts +2 -1
- package/dist/cognite-core/index.d.ts +2 -1
- package/dist/cognite-core/index.js +349 -20
- package/dist/cognite-core/index.js.map +1 -1
- package/dist/index.cjs +346 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -3
- package/dist/index.d.ts +8 -3
- package/dist/index.js +346 -20
- package/dist/index.js.map +1 -1
- package/dist/{types-2jjbs2i7.d.cts → types-69DRhgww.d.cts} +95 -19
- package/dist/{types-2jjbs2i7.d.ts → types-69DRhgww.d.ts} +95 -19
- package/package.json +7 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CogniteClient } from '@cognite/sdk';
|
|
2
|
-
import {
|
|
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-69DRhgww.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<{
|
|
@@ -530,6 +530,7 @@ declare class CogniteCoreClient {
|
|
|
530
530
|
aggregate<TView extends CogniteCoreViewExternalId>(viewExternalId: TView): CogniteCoreAggregateExecutor<TView>;
|
|
531
531
|
upsert<TView extends CogniteCoreViewExternalId>(viewExternalId: TView): CogniteCoreUpsertExecutor<TView>;
|
|
532
532
|
delete<TItem extends NodeId>(items: TItem[]): Promise<DeleteResult>;
|
|
533
|
+
get datapoints(): DatapointsExecutor;
|
|
533
534
|
}
|
|
534
535
|
|
|
535
536
|
export { COGNITE_CORE_DATA_MODEL, type Cognite360Image, type Cognite360ImageAnnotation, type Cognite360ImageCollection, type Cognite360ImageModel, type Cognite360ImageStation, type Cognite3DModel, type Cognite3DObject, type Cognite3DRevision, type Cognite3DTransformation, type CogniteActivity, type CogniteAnnotation, type CogniteAsset, type CogniteAssetClass, type CogniteAssetType, type CogniteCADModel, type CogniteCADNode, type CogniteCADRevision, type CogniteCoreAggregateExecutor, CogniteCoreClient, type CogniteCoreModel, type CogniteCoreModelByView, type CogniteCoreQueryExecutor, type CogniteCoreUpsertExecutor, type CogniteCoreViewExternalId, type CogniteCubeMap, type CogniteDescribable, type CogniteDiagramAnnotation, type CogniteEquipment, type CogniteEquipmentType, type CogniteFile, type CogniteFileCategory, type CognitePointCloudModel, type CognitePointCloudRevision, type CognitePointCloudVolume, type CogniteSchedulable, type CogniteSourceSystem, type CogniteSourceable, type CogniteTimeSeries, type CogniteUnit, type CogniteVisualizable };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CogniteClient } from '@cognite/sdk';
|
|
2
|
-
import {
|
|
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-69DRhgww.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<{
|
|
@@ -530,6 +530,7 @@ declare class CogniteCoreClient {
|
|
|
530
530
|
aggregate<TView extends CogniteCoreViewExternalId>(viewExternalId: TView): CogniteCoreAggregateExecutor<TView>;
|
|
531
531
|
upsert<TView extends CogniteCoreViewExternalId>(viewExternalId: TView): CogniteCoreUpsertExecutor<TView>;
|
|
532
532
|
delete<TItem extends NodeId>(items: TItem[]): Promise<DeleteResult>;
|
|
533
|
+
get datapoints(): DatapointsExecutor;
|
|
533
534
|
}
|
|
534
535
|
|
|
535
536
|
export { COGNITE_CORE_DATA_MODEL, type Cognite360Image, type Cognite360ImageAnnotation, type Cognite360ImageCollection, type Cognite360ImageModel, type Cognite360ImageStation, type Cognite3DModel, type Cognite3DObject, type Cognite3DRevision, type Cognite3DTransformation, type CogniteActivity, type CogniteAnnotation, type CogniteAsset, type CogniteAssetClass, type CogniteAssetType, type CogniteCADModel, type CogniteCADNode, type CogniteCADRevision, type CogniteCoreAggregateExecutor, CogniteCoreClient, type CogniteCoreModel, type CogniteCoreModelByView, type CogniteCoreQueryExecutor, type CogniteCoreUpsertExecutor, type CogniteCoreViewExternalId, type CogniteCubeMap, type CogniteDescribable, type CogniteDiagramAnnotation, type CogniteEquipment, type CogniteEquipmentType, type CogniteFile, type CogniteFileCategory, type CognitePointCloudModel, type CognitePointCloudRevision, type CognitePointCloudVolume, type CogniteSchedulable, type CogniteSourceSystem, type CogniteSourceable, type CogniteTimeSeries, type CogniteUnit, type CogniteVisualizable };
|
|
@@ -48,7 +48,92 @@ var CogniteSdkAdapter = class {
|
|
|
48
48
|
items: response.items
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
|
+
async retrieveDatapoints(options) {
|
|
52
|
+
const { items, ...rest } = options;
|
|
53
|
+
const sdkItems = items.map(({ space, externalId, ...itemRest }) => ({
|
|
54
|
+
...itemRest,
|
|
55
|
+
instanceId: { space, externalId }
|
|
56
|
+
}));
|
|
57
|
+
const response = await this.client.datapoints.retrieve({
|
|
58
|
+
...rest,
|
|
59
|
+
items: sdkItems
|
|
60
|
+
});
|
|
61
|
+
return { items: response.map(mapDatapointResult) };
|
|
62
|
+
}
|
|
63
|
+
async retrieveLatestDatapoints(items, options) {
|
|
64
|
+
const sdkItems = items.map(({ space, externalId, before }) => ({
|
|
65
|
+
instanceId: { space, externalId },
|
|
66
|
+
...before !== void 0 ? { before } : {}
|
|
67
|
+
}));
|
|
68
|
+
const response = await this.client.datapoints.retrieveLatest(
|
|
69
|
+
sdkItems,
|
|
70
|
+
options
|
|
71
|
+
);
|
|
72
|
+
return { items: response.map(mapDatapointResult) };
|
|
73
|
+
}
|
|
74
|
+
async insertDatapoints(items) {
|
|
75
|
+
const sdkItems = items.map(({ space, externalId, datapoints }) => ({
|
|
76
|
+
instanceId: { space, externalId },
|
|
77
|
+
datapoints
|
|
78
|
+
}));
|
|
79
|
+
await this.client.datapoints.insert(
|
|
80
|
+
sdkItems
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
async deleteDatapoints(items) {
|
|
84
|
+
const sdkItems = items.map(({ space, externalId, inclusiveBegin, exclusiveEnd }) => ({
|
|
85
|
+
instanceId: { space, externalId },
|
|
86
|
+
inclusiveBegin,
|
|
87
|
+
...exclusiveEnd !== void 0 ? { exclusiveEnd } : {}
|
|
88
|
+
}));
|
|
89
|
+
await this.client.datapoints.delete(
|
|
90
|
+
sdkItems
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
async uploadFile(fileInfo, content) {
|
|
94
|
+
const { instanceId, ...rest } = fileInfo;
|
|
95
|
+
const response = await this.client.files.upload(
|
|
96
|
+
{ ...rest, instanceId },
|
|
97
|
+
content,
|
|
98
|
+
false,
|
|
99
|
+
content !== void 0
|
|
100
|
+
);
|
|
101
|
+
return mapFileResult(response);
|
|
102
|
+
}
|
|
103
|
+
async getFileDownloadUrls(ids) {
|
|
104
|
+
const response = await this.client.files.getDownloadUrls(
|
|
105
|
+
ids
|
|
106
|
+
);
|
|
107
|
+
return response.map((item) => ({
|
|
108
|
+
...item.instanceId !== void 0 ? { instanceId: item.instanceId } : {},
|
|
109
|
+
downloadUrl: item.downloadUrl
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
51
112
|
};
|
|
113
|
+
function mapFileResult(item) {
|
|
114
|
+
return {
|
|
115
|
+
...item.instanceId !== void 0 ? { instanceId: item.instanceId } : {},
|
|
116
|
+
name: item.name,
|
|
117
|
+
uploaded: item.uploaded,
|
|
118
|
+
createdTime: item.createdTime,
|
|
119
|
+
lastUpdatedTime: item.lastUpdatedTime,
|
|
120
|
+
...item.uploadedTime !== void 0 ? { uploadedTime: item.uploadedTime } : {},
|
|
121
|
+
...item.mimeType !== void 0 ? { mimeType: item.mimeType } : {},
|
|
122
|
+
...item.directory !== void 0 ? { directory: item.directory } : {},
|
|
123
|
+
...item.source !== void 0 ? { source: item.source } : {},
|
|
124
|
+
...item.uploadUrl !== void 0 ? { uploadUrl: item.uploadUrl } : {}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function mapDatapointResult(item) {
|
|
128
|
+
return {
|
|
129
|
+
...item.instanceId?.space !== void 0 ? { space: item.instanceId.space } : {},
|
|
130
|
+
...item.instanceId?.externalId !== void 0 ? { externalId: item.instanceId.externalId } : {},
|
|
131
|
+
isString: item.isString ?? false,
|
|
132
|
+
...item.unit !== void 0 ? { unit: item.unit } : {},
|
|
133
|
+
datapoints: item.datapoints ?? [],
|
|
134
|
+
...item.nextCursor !== void 0 ? { nextCursor: item.nextCursor } : {}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
52
137
|
|
|
53
138
|
// src/constants.ts
|
|
54
139
|
var NESTED_SEP = "|";
|
|
@@ -59,6 +144,15 @@ var MAX_DEPENDENCY_DEPTH = 3;
|
|
|
59
144
|
var AGGREGATE_LIMIT = 1e3;
|
|
60
145
|
var MAX_GROUP_BY = 5;
|
|
61
146
|
|
|
147
|
+
// src/utils/array.ts
|
|
148
|
+
function chunks(items, size) {
|
|
149
|
+
const result = [];
|
|
150
|
+
for (let index = 0; index < items.length; index += size) {
|
|
151
|
+
result.push(items.slice(index, index + size));
|
|
152
|
+
}
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
|
|
62
156
|
// src/utils/query.ts
|
|
63
157
|
function mapNodesAndEdges(queryResult, _query) {
|
|
64
158
|
return queryResult.items;
|
|
@@ -715,6 +809,63 @@ ${errors.map((error) => `- ${error}`).join("\n")}`
|
|
|
715
809
|
return [];
|
|
716
810
|
}
|
|
717
811
|
};
|
|
812
|
+
var dateSchema2 = z.date();
|
|
813
|
+
var nodeIdSchema2 = z.object({ space: z.string(), externalId: z.string() }).loose();
|
|
814
|
+
var retrieveOptionsSchema = z.object({
|
|
815
|
+
timeSeries: z.array(nodeIdSchema2),
|
|
816
|
+
start: dateSchema2.optional(),
|
|
817
|
+
end: dateSchema2.optional()
|
|
818
|
+
}).loose();
|
|
819
|
+
var deleteRangeSchema = z.object({
|
|
820
|
+
timeSeries: z.object({ space: z.string(), externalId: z.string() }).loose(),
|
|
821
|
+
start: dateSchema2,
|
|
822
|
+
end: dateSchema2.optional()
|
|
823
|
+
}).loose();
|
|
824
|
+
function formatIssues(error, prefix) {
|
|
825
|
+
return error.issues.map((issue) => {
|
|
826
|
+
const parts = prefix ? [prefix, ...issue.path] : [...issue.path];
|
|
827
|
+
return `${parts.map(String).join(".")}: ${issue.message}`;
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
var DatapointsValidator = class {
|
|
831
|
+
validateRetrieve(options) {
|
|
832
|
+
const result = retrieveOptionsSchema.safeParse(options);
|
|
833
|
+
if (!result.success) {
|
|
834
|
+
const messages = formatIssues(result.error);
|
|
835
|
+
throw new Error(`Invalid datapoints options:
|
|
836
|
+
- ${messages.join("\n- ")}`);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
validateDelete(ranges) {
|
|
840
|
+
const result = z.array(deleteRangeSchema).safeParse(ranges);
|
|
841
|
+
if (!result.success) {
|
|
842
|
+
const messages = formatIssues(result.error, "ranges");
|
|
843
|
+
throw new Error(`Invalid datapoints options:
|
|
844
|
+
- ${messages.join("\n- ")}`);
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
};
|
|
848
|
+
var nodeIdSchema3 = z.object({
|
|
849
|
+
space: z.string().min(1),
|
|
850
|
+
externalId: z.string().min(1)
|
|
851
|
+
}).loose();
|
|
852
|
+
var deleteItemsSchema = z.array(nodeIdSchema3);
|
|
853
|
+
function formatIssues2(error, prefix) {
|
|
854
|
+
return error.issues.map((issue) => {
|
|
855
|
+
const parts = [prefix, ...issue.path];
|
|
856
|
+
return `${parts.map(String).join(".")}: ${issue.message}`;
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
var DeleteValidator = class {
|
|
860
|
+
validateItems(items) {
|
|
861
|
+
const result = deleteItemsSchema.safeParse(items);
|
|
862
|
+
if (!result.success) {
|
|
863
|
+
const messages = formatIssues2(result.error, "items");
|
|
864
|
+
throw new Error(`Invalid delete options:
|
|
865
|
+
- ${messages.join("\n- ")}`);
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
};
|
|
718
869
|
var nodeMetadataSchema = {
|
|
719
870
|
instanceType: z.literal("node").optional(),
|
|
720
871
|
space: z.string(),
|
|
@@ -1118,6 +1269,178 @@ var AggregateResultMapper = class {
|
|
|
1118
1269
|
}
|
|
1119
1270
|
};
|
|
1120
1271
|
|
|
1272
|
+
// src/mappers/datapoints-mapper.ts
|
|
1273
|
+
var CHUNK_SIZE = 100;
|
|
1274
|
+
var DatapointsMapper = class {
|
|
1275
|
+
constructor(cognite) {
|
|
1276
|
+
this.cognite = cognite;
|
|
1277
|
+
this.validator = new DatapointsValidator();
|
|
1278
|
+
}
|
|
1279
|
+
async retrieve(options) {
|
|
1280
|
+
this.validator.validateRetrieve(options);
|
|
1281
|
+
const cogniteOptions = this.toCogniteOptions(options);
|
|
1282
|
+
const allPages = options.limit === -1;
|
|
1283
|
+
if (!allPages) {
|
|
1284
|
+
const result = await this.cognite.retrieveDatapoints(cogniteOptions);
|
|
1285
|
+
return this.mapResult(result.items, cogniteOptions.items, options.aggregate);
|
|
1286
|
+
}
|
|
1287
|
+
const accumulated = /* @__PURE__ */ new Map();
|
|
1288
|
+
const itemByKey = new Map(cogniteOptions.items.map((item) => [this.toKey(item), item]));
|
|
1289
|
+
let currentItems = cogniteOptions.items;
|
|
1290
|
+
while (currentItems.length > 0) {
|
|
1291
|
+
const result = await this.cognite.retrieveDatapoints({
|
|
1292
|
+
...cogniteOptions,
|
|
1293
|
+
items: currentItems
|
|
1294
|
+
});
|
|
1295
|
+
const nextItems = [];
|
|
1296
|
+
for (const resultItem of result.items) {
|
|
1297
|
+
const key = this.toKey(resultItem);
|
|
1298
|
+
let acc = accumulated.get(key);
|
|
1299
|
+
if (!acc) {
|
|
1300
|
+
acc = { ...resultItem, datapoints: [] };
|
|
1301
|
+
accumulated.set(key, acc);
|
|
1302
|
+
}
|
|
1303
|
+
acc.datapoints.push(...resultItem.datapoints);
|
|
1304
|
+
if (resultItem.nextCursor) {
|
|
1305
|
+
acc.nextCursor = resultItem.nextCursor;
|
|
1306
|
+
} else {
|
|
1307
|
+
delete acc.nextCursor;
|
|
1308
|
+
}
|
|
1309
|
+
if (resultItem.nextCursor) {
|
|
1310
|
+
const original = itemByKey.get(key);
|
|
1311
|
+
nextItems.push({
|
|
1312
|
+
...original,
|
|
1313
|
+
space: resultItem.space ?? original?.space ?? "",
|
|
1314
|
+
externalId: resultItem.externalId ?? original?.externalId ?? "",
|
|
1315
|
+
cursor: resultItem.nextCursor
|
|
1316
|
+
});
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
currentItems = nextItems;
|
|
1320
|
+
}
|
|
1321
|
+
return this.mapResult(
|
|
1322
|
+
Array.from(accumulated.values()),
|
|
1323
|
+
cogniteOptions.items,
|
|
1324
|
+
options.aggregate
|
|
1325
|
+
);
|
|
1326
|
+
}
|
|
1327
|
+
async retrieveLatest(options) {
|
|
1328
|
+
const items = options.timeSeries.map(
|
|
1329
|
+
({ space, externalId, before }) => ({
|
|
1330
|
+
space,
|
|
1331
|
+
externalId,
|
|
1332
|
+
...before !== void 0 ? { before } : {}
|
|
1333
|
+
})
|
|
1334
|
+
);
|
|
1335
|
+
const latestOptions = options.ignoreUnknownIds !== void 0 ? { ignoreUnknownIds: options.ignoreUnknownIds } : void 0;
|
|
1336
|
+
const result = await this.cognite.retrieveLatestDatapoints(items, latestOptions);
|
|
1337
|
+
return this.mapResult(result.items, items);
|
|
1338
|
+
}
|
|
1339
|
+
async insert(items) {
|
|
1340
|
+
const cogniteItems = items.map(({ timeSeries, datapoints }) => ({
|
|
1341
|
+
space: timeSeries.space,
|
|
1342
|
+
externalId: timeSeries.externalId,
|
|
1343
|
+
datapoints
|
|
1344
|
+
}));
|
|
1345
|
+
for (const chunk of chunks(cogniteItems, CHUNK_SIZE)) {
|
|
1346
|
+
await this.cognite.insertDatapoints(chunk);
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
async delete(ranges) {
|
|
1350
|
+
this.validator.validateDelete(ranges);
|
|
1351
|
+
const cogniteItems = ranges.map(({ timeSeries, start, end }) => ({
|
|
1352
|
+
space: timeSeries.space,
|
|
1353
|
+
externalId: timeSeries.externalId,
|
|
1354
|
+
inclusiveBegin: start,
|
|
1355
|
+
...end !== void 0 ? { exclusiveEnd: end } : {}
|
|
1356
|
+
}));
|
|
1357
|
+
for (const chunk of chunks(cogniteItems, CHUNK_SIZE)) {
|
|
1358
|
+
await this.cognite.deleteDatapoints(chunk);
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
toKey(item) {
|
|
1362
|
+
return `${item.space ?? ""}:${item.externalId ?? ""}`;
|
|
1363
|
+
}
|
|
1364
|
+
toCogniteOptions(options) {
|
|
1365
|
+
const { timeSeries, aggregate, ...rest } = options;
|
|
1366
|
+
return {
|
|
1367
|
+
...rest,
|
|
1368
|
+
...aggregate !== void 0 ? { aggregates: [aggregate] } : {},
|
|
1369
|
+
items: timeSeries.map(({ space, externalId }) => ({ space, externalId }))
|
|
1370
|
+
};
|
|
1371
|
+
}
|
|
1372
|
+
mapResult(items, requestedItems, aggregate) {
|
|
1373
|
+
const requestedByKey = new Map(requestedItems.map((item) => [this.toKey(item), item]));
|
|
1374
|
+
const mappedItems = items.filter((item) => !item.isString).map((item) => {
|
|
1375
|
+
const requested = requestedByKey.get(this.toKey(item));
|
|
1376
|
+
const datapoints = aggregate !== void 0 ? item.datapoints.map((dp) => ({
|
|
1377
|
+
timestamp: dp.timestamp,
|
|
1378
|
+
value: dp[aggregate] ?? 0
|
|
1379
|
+
})) : item.datapoints;
|
|
1380
|
+
return {
|
|
1381
|
+
timeSeries: {
|
|
1382
|
+
space: item.space ?? requested?.space ?? "",
|
|
1383
|
+
externalId: item.externalId ?? requested?.externalId ?? ""
|
|
1384
|
+
},
|
|
1385
|
+
...item.unit !== void 0 ? { unit: item.unit } : {},
|
|
1386
|
+
datapoints,
|
|
1387
|
+
cursor: item.nextCursor ?? null
|
|
1388
|
+
};
|
|
1389
|
+
});
|
|
1390
|
+
return { items: mappedItems };
|
|
1391
|
+
}
|
|
1392
|
+
};
|
|
1393
|
+
|
|
1394
|
+
// src/mappers/files-mapper.ts
|
|
1395
|
+
var FilesMapper = class {
|
|
1396
|
+
constructor(cognite) {
|
|
1397
|
+
this.cognite = cognite;
|
|
1398
|
+
}
|
|
1399
|
+
async upload(fileInfo, content) {
|
|
1400
|
+
const { space, externalId, ...rest } = fileInfo;
|
|
1401
|
+
const result = await this.cognite.uploadFile(
|
|
1402
|
+
{ instanceId: { space, externalId }, ...rest },
|
|
1403
|
+
content
|
|
1404
|
+
);
|
|
1405
|
+
return this.mapUploadResult(result, { space, externalId });
|
|
1406
|
+
}
|
|
1407
|
+
async getDownloadUrls(nodeIds) {
|
|
1408
|
+
if (nodeIds.length === 0) return [];
|
|
1409
|
+
const ids = nodeIds.map(({ space, externalId }) => ({ instanceId: { space, externalId } }));
|
|
1410
|
+
const result = await this.cognite.getFileDownloadUrls(ids);
|
|
1411
|
+
return result.map(
|
|
1412
|
+
(item, i) => this.mapDownloadUrl(item, nodeIds[i] ?? { space: "", externalId: "" })
|
|
1413
|
+
);
|
|
1414
|
+
}
|
|
1415
|
+
toNodeId(item, fallback) {
|
|
1416
|
+
return {
|
|
1417
|
+
space: item.instanceId?.space ?? fallback.space,
|
|
1418
|
+
externalId: item.instanceId?.externalId ?? fallback.externalId
|
|
1419
|
+
};
|
|
1420
|
+
}
|
|
1421
|
+
mapUploadResult(item, fallback) {
|
|
1422
|
+
const nodeId = this.toNodeId(item, fallback);
|
|
1423
|
+
return {
|
|
1424
|
+
...nodeId,
|
|
1425
|
+
name: item.name,
|
|
1426
|
+
uploaded: item.uploaded,
|
|
1427
|
+
createdTime: item.createdTime,
|
|
1428
|
+
lastUpdatedTime: item.lastUpdatedTime,
|
|
1429
|
+
...item.uploadedTime !== void 0 ? { uploadedTime: item.uploadedTime } : {},
|
|
1430
|
+
...item.mimeType !== void 0 ? { mimeType: item.mimeType } : {},
|
|
1431
|
+
...item.directory !== void 0 ? { directory: item.directory } : {},
|
|
1432
|
+
...item.source !== void 0 ? { source: item.source } : {},
|
|
1433
|
+
...item.uploadUrl !== void 0 ? { uploadUrl: item.uploadUrl } : {}
|
|
1434
|
+
};
|
|
1435
|
+
}
|
|
1436
|
+
mapDownloadUrl(item, fallback) {
|
|
1437
|
+
return {
|
|
1438
|
+
...this.toNodeId(item, fallback),
|
|
1439
|
+
downloadUrl: item.downloadUrl
|
|
1440
|
+
};
|
|
1441
|
+
}
|
|
1442
|
+
};
|
|
1443
|
+
|
|
1121
1444
|
// src/mappers/sort-mapper.ts
|
|
1122
1445
|
var SortMapper = class {
|
|
1123
1446
|
map(sort, rootView) {
|
|
@@ -1674,6 +1997,10 @@ var ViewMapper = class {
|
|
|
1674
1997
|
}
|
|
1675
1998
|
return view;
|
|
1676
1999
|
}
|
|
2000
|
+
async getViews() {
|
|
2001
|
+
const views = await this.loadViews();
|
|
2002
|
+
return Array.from(views.values());
|
|
2003
|
+
}
|
|
1677
2004
|
loadViews() {
|
|
1678
2005
|
if (this.cachePromise == null) {
|
|
1679
2006
|
this.cachePromise = this.fetchViews();
|
|
@@ -1707,6 +2034,17 @@ var ViewMapper = class {
|
|
|
1707
2034
|
var APPLY_ITEM_LIMIT = 1e3;
|
|
1708
2035
|
var IndustrialModelClient = class {
|
|
1709
2036
|
constructor(client, dataModelId, options = {}) {
|
|
2037
|
+
this.deleteValidator = new DeleteValidator();
|
|
2038
|
+
this.files = {
|
|
2039
|
+
upload: (fileInfo, content) => this.filesMapper.upload(fileInfo, content),
|
|
2040
|
+
getDownloadUrls: (nodeIds) => this.filesMapper.getDownloadUrls(nodeIds)
|
|
2041
|
+
};
|
|
2042
|
+
this.datapoints = {
|
|
2043
|
+
retrieve: (options) => this.datapointsMapper.retrieve(options),
|
|
2044
|
+
latest: (options) => this.datapointsMapper.retrieveLatest(options),
|
|
2045
|
+
insert: (items) => this.datapointsMapper.insert(items),
|
|
2046
|
+
delete: (ranges) => this.datapointsMapper.delete(ranges)
|
|
2047
|
+
};
|
|
1710
2048
|
const cognite = createCogniteAdapter(client);
|
|
1711
2049
|
this.cognite = cognite;
|
|
1712
2050
|
const viewMapper = new ViewMapper(cognite, dataModelId);
|
|
@@ -1715,6 +2053,8 @@ var IndustrialModelClient = class {
|
|
|
1715
2053
|
this.upsertMapper = new UpsertMapper(viewMapper, cognite);
|
|
1716
2054
|
this.aggregateResultMapper = new AggregateResultMapper();
|
|
1717
2055
|
this.resultMapper = new QueryResultMapper(viewMapper);
|
|
2056
|
+
this.datapointsMapper = new DatapointsMapper(cognite);
|
|
2057
|
+
this.filesMapper = new FilesMapper(cognite);
|
|
1718
2058
|
this.resultValidator = new QueryResultValidator(viewMapper);
|
|
1719
2059
|
this.validateResults = options.validateResults ?? false;
|
|
1720
2060
|
}
|
|
@@ -1731,14 +2071,12 @@ var IndustrialModelClient = class {
|
|
|
1731
2071
|
return execute;
|
|
1732
2072
|
}
|
|
1733
2073
|
async delete(items) {
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
};
|
|
1741
|
-
});
|
|
2074
|
+
this.deleteValidator.validateItems(items);
|
|
2075
|
+
const deleteItems = items.map((item) => ({
|
|
2076
|
+
instanceType: "node",
|
|
2077
|
+
space: item.space,
|
|
2078
|
+
externalId: item.externalId
|
|
2079
|
+
}));
|
|
1742
2080
|
const response = await this.applyInstancesInChunks({
|
|
1743
2081
|
items: [],
|
|
1744
2082
|
delete: deleteItems
|
|
@@ -1830,18 +2168,6 @@ var IndustrialModelClient = class {
|
|
|
1830
2168
|
return appendNodesAndEdges(result, nestedResults);
|
|
1831
2169
|
}
|
|
1832
2170
|
};
|
|
1833
|
-
function chunks(items, size) {
|
|
1834
|
-
const result = [];
|
|
1835
|
-
for (let index = 0; index < items.length; index += size) {
|
|
1836
|
-
result.push(items.slice(index, index + size));
|
|
1837
|
-
}
|
|
1838
|
-
return result;
|
|
1839
|
-
}
|
|
1840
|
-
function assertNodeId2(value) {
|
|
1841
|
-
if (value == null || typeof value !== "object" || Array.isArray(value) || typeof value.space !== "string" || value.space?.length === 0 || typeof value.externalId !== "string" || value.externalId?.length === 0) {
|
|
1842
|
-
throw new Error("Invalid delete options:\n- items: expected NodeId values");
|
|
1843
|
-
}
|
|
1844
|
-
}
|
|
1845
2171
|
|
|
1846
2172
|
// src/cognite-core/client.ts
|
|
1847
2173
|
var COGNITE_CORE_DATA_MODEL = {
|
|
@@ -1872,6 +2198,9 @@ var CogniteCoreClient = class {
|
|
|
1872
2198
|
delete(items) {
|
|
1873
2199
|
return this.model.delete(items);
|
|
1874
2200
|
}
|
|
2201
|
+
get datapoints() {
|
|
2202
|
+
return this.model.datapoints;
|
|
2203
|
+
}
|
|
1875
2204
|
};
|
|
1876
2205
|
|
|
1877
2206
|
export { COGNITE_CORE_DATA_MODEL, CogniteCoreClient };
|