@hahnpro/hpc-api 5.1.0 → 5.2.1

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.
@@ -32,7 +32,7 @@ class DataService extends api_base_1.APIBase {
32
32
  getFilterString(filter) {
33
33
  const filters = [];
34
34
  for (const [key, value] of Object.entries(filter)) {
35
- if ((0, data_interface_1.instanceOfTimePeriod)(value)) {
35
+ if (typeof value === 'object' && (0, data_interface_1.instanceOfTimePeriod)(value)) {
36
36
  filters.push(`${key}>=${value.from.toISOString()};${key}<=${value.to.toISOString()}`);
37
37
  }
38
38
  else if (Array.isArray(value)) {
@@ -23,6 +23,11 @@ export declare class TimeseriesMockService extends BaseService implements TimeSe
23
23
  addAssetTimeSeriesValues(assetId: string, name: string, readPermissions: string[], readWritePermissions: string[], values: {
24
24
  [timestamp: string]: any;
25
25
  }): Promise<TimeSeries>;
26
+ addManyAssetTimeSeriesValues(assetId: string, readPermissions: string[], readWritePermissions: string[], timeSeries: {
27
+ [timeSeriesName: string]: {
28
+ [timestamp: string]: any;
29
+ };
30
+ }): Promise<PromiseSettledResult<TimeSeries>[]>;
26
31
  addValue(id: string, value: {
27
32
  [timestamp: string]: any;
28
33
  }): Promise<void>;
@@ -57,6 +57,41 @@ class TimeseriesMockService extends BaseService {
57
57
  ts.data = ts.data ? [...ts.data, ...data] : data;
58
58
  return Promise.resolve(ts);
59
59
  }
60
+ addManyAssetTimeSeriesValues(assetId, readPermissions, readWritePermissions, timeSeries) {
61
+ const ts = this.data.find((v) => v.assetRef === assetId);
62
+ const psr = [];
63
+ for (const [tsName, values] of Object.entries(timeSeries)) {
64
+ const data = Object.entries(values).map(([timestamp, value]) => {
65
+ if (value !== null && typeof value === 'object') {
66
+ return Object.assign({ timestamp }, value);
67
+ }
68
+ else {
69
+ return { timestamp, value };
70
+ }
71
+ });
72
+ if (!ts) {
73
+ const dto = {
74
+ autoDelBucket: undefined,
75
+ autoDelData: undefined,
76
+ description: '',
77
+ maxBucketTimeRange: 0,
78
+ minDate: undefined,
79
+ maxDate: undefined,
80
+ name: tsName,
81
+ readPermissions,
82
+ readWritePermissions,
83
+ assetRef: assetId,
84
+ data,
85
+ };
86
+ this.addOne(dto).then((v) => psr.push({ status: 'fulfilled', value: v }));
87
+ }
88
+ else {
89
+ ts.data = ts.data ? [...ts.data, ...data] : data;
90
+ psr.push({ status: 'fulfilled', value: ts });
91
+ }
92
+ }
93
+ return Promise.resolve(psr);
94
+ }
60
95
  addValue(id, value) {
61
96
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
62
97
  const ts = yield this.getOne(id, {});
@@ -13,9 +13,52 @@ export declare class TimeSeriesService extends BaseService {
13
13
  addValue(id: string, value: {
14
14
  [timestamp: string]: any;
15
15
  }): Promise<void>;
16
+ /**
17
+ * Adds time series values to an asset by the name of the time series.
18
+ * If the time series does not exist, it is created.
19
+ * @param assetId - The ID of the asset to which the time series values are added.
20
+ * @param name - The name of the time series.
21
+ * @param readPermissions - an array of permissions that allow the user to read the time series.
22
+ * @param readWritePermissions - an array of permissions that allow the user to read and write the time series.
23
+ * @param values - The time series values are specified as an object with the following structure:
24
+ * {
25
+ * [timestamp: string]: any, // The timestamp and value pairs
26
+ * ...
27
+ * }
28
+ * @returns a promise that resolves to the time series that was added.
29
+ */
16
30
  addAssetTimeSeriesValues(assetId: string, name: string, readPermissions: string[], readWritePermissions: string[], values: {
17
31
  [timestamp: string]: any;
18
32
  }): Promise<TimeSeries>;
33
+ /**
34
+ * Adds multiple time series values to an asset by the name of the time series.
35
+ * If the time series does not exist, it is created.
36
+ * If the operation is successful, the value property contains the time series that was added.
37
+ * If the operation fails, the reason property contains the error that caused the operation to fail.
38
+ * @param assetId - The ID of the asset to which the time series values are added.
39
+ * @param readPermissions - an array of permissions that allow the user to read the time series.
40
+ * @param readWritePermissions - an array of permissions that allow the user to read and write the time series.
41
+ * @param timeSeries - The time series values are specified as an object with the following structure:
42
+ * {
43
+ * [timeSeriesName: string]: { // The name of the time series
44
+ * [timestamp: string]: any, // The timestamp and value pairs
45
+ * ...
46
+ * },
47
+ * ...
48
+ * }
49
+ * @returns a promise that resolves to an array of objects containing the results of the operation.
50
+ * Each object has the following structure:
51
+ * {
52
+ * status: "fulfilled" | "rejected",
53
+ * value?: TimeSeries,
54
+ * reason?: Error,
55
+ * }
56
+ */
57
+ addManyAssetTimeSeriesValues(assetId: string, readPermissions: string[], readWritePermissions: string[], timeSeries: {
58
+ [timeSeriesName: string]: {
59
+ [timestamp: string]: any;
60
+ };
61
+ }): Promise<PromiseSettledResult<TimeSeries>[]>;
19
62
  getMostRecentValue(id: string, before?: Date): Promise<TimeSeriesValue>;
20
63
  getValues(id: string, from: number, limit?: number, group?: TS_GROUPS): Promise<TimeSeriesValue[]>;
21
64
  getValuesOfPeriod(id: string, from: number, to: number, group?: TS_GROUPS): Promise<TimeSeriesValue[]>;
@@ -27,6 +27,15 @@ class TimeSeriesService extends BaseService {
27
27
  };
28
28
  return this.httpClient.post(`${this.basePath}/assets/${assetId}`, dto);
29
29
  }
30
+ addManyAssetTimeSeriesValues(assetId, readPermissions, readWritePermissions, timeSeries) {
31
+ const dtos = Object.entries(timeSeries).map(([name, values]) => ({
32
+ name,
33
+ readPermissions,
34
+ readWritePermissions,
35
+ values,
36
+ }));
37
+ return this.httpClient.post(`${this.basePath}/assets/${assetId}/bulk`, dtos);
38
+ }
30
39
  getMostRecentValue(id, before) {
31
40
  const params = before ? { before: before.toISOString() } : {};
32
41
  return this.httpClient.get(`${this.basePath}/${id}/recent`, { params });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hahnpro/hpc-api",
3
- "version": "5.1.0",
3
+ "version": "5.2.1",
4
4
  "description": "Module for easy access to the HahnPRO API",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -27,7 +27,7 @@
27
27
  "axios": "~1.6.2",
28
28
  "eventsource": "^2.0.2",
29
29
  "form-data": "^4.0.0",
30
- "jose": "^5.1.1",
30
+ "jose": "^5.1.2",
31
31
  "jwt-decode": "^4.0.0",
32
32
  "p-queue": "^6.6.2",
33
33
  "ts-mixer": "^6.0.3",