/
unitsApi.ts
58 lines (51 loc) · 1.52 KB
/
unitsApi.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2023 Cognite AS
import {
BaseResourceAPI,
CDFHttpClient,
ExternalId,
MetadataMap,
} from '@cognite/sdk-core';
import { Unit } from '../../types';
import { UnitSystemsAPI } from './unitSystemsApi';
export class UnitsAPI extends BaseResourceAPI<Unit> {
private unitSystemsApi: UnitSystemsAPI;
constructor(...args: [string, CDFHttpClient, MetadataMap]) {
super(...args);
const [resourcePath, client, metadataMap] = args;
this.unitSystemsApi = new UnitSystemsAPI(
`${resourcePath}/systems`,
client,
metadataMap
);
}
/**
* [List all supported units](https://developer.cognite.com/api#tag/Units/operation/listUnits)
*
* ```js
* const units = await client.units.list();
* ```
*/
public list = async () => {
return this.listEndpoint(this.callListEndpointWithGet);
};
/**
* [Retrieve one or more units](https://developer.cognite.com/api#tag/Units/operation/byIdsUnits)
*
* ```js
* const units = await client.units.retrieve([{ externalId: 'temperature:deg_c' }, { externalId: 'pressure:bar' }]);
* ```
*/
public retrieve = async (ids: ExternalId[]): Promise<Unit[]> => {
return this.retrieveEndpoint(ids);
};
/**
* [List all supported unit systems](List all supported unit systems <https://developer.cognite.com/api#tag/Unit-Systems/operation/listUnitSystems)
*
* ```js
* const units = await client.units.listUnitSystems();
* ```
*/
public listUnitSystems = async () => {
return this.unitSystemsApi.list();
};
}