@hahnpro/hpc-api 5.0.0 → 5.2.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.
@@ -12,10 +12,10 @@ export interface AssetType {
12
12
  typeSchema: any;
13
13
  uiSchema: any;
14
14
  actions?: string[];
15
- createdAt?: string;
16
- updatedAt?: string;
17
15
  author?: string;
18
16
  revision?: number;
17
+ createdAt?: string;
18
+ updatedAt?: string;
19
19
  deletedAt?: string;
20
20
  }
21
21
  export type AssetTypeRevision = AssetType & {
@@ -40,6 +40,8 @@ export interface Asset {
40
40
  actions?: string[];
41
41
  author?: string;
42
42
  revision?: number;
43
+ createdAt?: string;
44
+ updatedAt?: string;
43
45
  deletedAt?: string;
44
46
  }
45
47
  export type AssetRevision = Asset & {
@@ -13,11 +13,12 @@ export interface RequestParameter {
13
13
  populate?: string;
14
14
  sort?: string;
15
15
  }
16
- export interface Filter {
17
- tags?: string[];
18
- type?: string;
19
- parent?: string;
16
+ interface TimePeriod {
17
+ from: Date;
18
+ to: Date;
20
19
  }
20
+ export declare function instanceOfTimePeriod(object: any): object is TimePeriod;
21
+ export type Filter = Record<string, string | string[] | TimePeriod>;
21
22
  export interface DataInterface<T> {
22
23
  addOne(dto: any): Promise<T>;
23
24
  addMany(dto: any[]): Promise<T[]>;
@@ -27,3 +28,4 @@ export interface DataInterface<T> {
27
28
  updateOne(id: string, dto: any): Promise<T>;
28
29
  deleteOne(id: string): Promise<any>;
29
30
  }
31
+ export {};
@@ -1,2 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.instanceOfTimePeriod = void 0;
4
+ function instanceOfTimePeriod(object) {
5
+ return 'from' in object && 'to' in object;
6
+ }
7
+ exports.instanceOfTimePeriod = instanceOfTimePeriod;
@@ -5,6 +5,15 @@ export declare class DataService<T> extends APIBase implements DataInterface<T>
5
5
  addMany(dto: any[]): Promise<T[]>;
6
6
  getOne(id: string, options?: any): Promise<T>;
7
7
  getMany(params?: RequestParameter): Promise<Paginated<T[]>>;
8
+ /**
9
+ * Filters the elements by the passed properties. The object with these properties has to be of the form:
10
+ * {
11
+ * propertyName: string | string[] | { from: Date, to: Date },
12
+ * ...
13
+ * }.
14
+ * @param filter The Object with the properties to filter by.
15
+ * @param params Other request parameters.
16
+ */
8
17
  getManyFiltered(filter: Filter, params?: RequestParameter): Promise<Paginated<T[]>>;
9
18
  updateOne(id: string, dto: any): Promise<T>;
10
19
  deleteOne(id: string, force?: boolean): Promise<any>;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DataService = void 0;
4
4
  const api_base_1 = require("./api-base");
5
+ const data_interface_1 = require("./data.interface");
5
6
  class DataService extends api_base_1.APIBase {
6
7
  addOne(dto) {
7
8
  return this.httpClient.post(this.basePath, dto);
@@ -29,16 +30,17 @@ class DataService extends api_base_1.APIBase {
29
30
  return this.httpClient.delete(`${this.basePath}/${id}`, { params: { force } });
30
31
  }
31
32
  getFilterString(filter) {
32
- const { parent, tags, type } = filter;
33
33
  const filters = [];
34
- if (tags) {
35
- filters.push('tags=@' + tags.join());
36
- }
37
- if (type) {
38
- filters.push('type==' + type);
39
- }
40
- if (parent) {
41
- filters.push('parent==' + parent);
34
+ for (const [key, value] of Object.entries(filter)) {
35
+ if ((0, data_interface_1.instanceOfTimePeriod)(value)) {
36
+ filters.push(`${key}>=${value.from.toISOString()};${key}<=${value.to.toISOString()}`);
37
+ }
38
+ else if (Array.isArray(value)) {
39
+ filters.push(`${key}=@${value.join(',')}`);
40
+ }
41
+ else {
42
+ filters.push(`${key}==${value}`);
43
+ }
42
44
  }
43
45
  return filters.join(';');
44
46
  }
@@ -27,102 +27,90 @@ class MockAPI {
27
27
  const assetTypes = assets
28
28
  .map((v) => v.type)
29
29
  .map((v) => {
30
+ var _a, _b;
30
31
  return typeof v === 'string'
31
32
  ? v
32
- : {
33
- name: v.name,
34
- id: v.id,
35
- readPermissions: [],
36
- readWritePermissions: [],
37
- typeSchema: {},
38
- uiSchema: {},
39
- };
40
- });
41
- const assets1 = assets.map((v, index) => (Object.assign(Object.assign({}, v), { readPermissions: [], readWritePermissions: [], type: assetTypes[index] })));
42
- const assetRevisions1 = assetRevisions.map((v, index) => (Object.assign(Object.assign({}, v), { readPermissions: [], readWritePermissions: [], type: assetTypes[index] })));
33
+ : Object.assign(Object.assign({}, v), { readPermissions: v.readPermissions || [], readWritePermissions: v.readWritePermissions || [], typeSchema: (_a = v.typeSchema) !== null && _a !== void 0 ? _a : {}, uiSchema: (_b = v.uiSchema) !== null && _b !== void 0 ? _b : {} });
34
+ });
35
+ const assets1 = assets.map((v, index) => {
36
+ var _a, _b;
37
+ return (Object.assign(Object.assign({}, v), { readPermissions: (_a = v.readPermissions) !== null && _a !== void 0 ? _a : [], readWritePermissions: (_b = v.readWritePermissions) !== null && _b !== void 0 ? _b : [], type: assetTypes[index] }));
38
+ });
39
+ const assetRevisions1 = assetRevisions.map((v, index) => {
40
+ var _a, _b;
41
+ return (Object.assign(Object.assign({}, v), { readPermissions: (_a = v.readPermissions) !== null && _a !== void 0 ? _a : [], readWritePermissions: (_b = v.readWritePermissions) !== null && _b !== void 0 ? _b : [], type: assetTypes[index] }));
42
+ });
43
43
  const contents1 = contents.map((v) => {
44
+ var _a, _b, _c, _d, _e;
45
+ return (Object.assign(Object.assign({}, v), { readPermissions: (_a = v.readPermissions) !== null && _a !== void 0 ? _a : [], readWritePermissions: (_b = v.readWritePermissions) !== null && _b !== void 0 ? _b : [], size: (_c = v.size) !== null && _c !== void 0 ? _c : 0, fileId: (_d = v.fileId) !== null && _d !== void 0 ? _d : '', mimetype: (_e = v.mimetype) !== null && _e !== void 0 ? _e : '' }));
46
+ });
47
+ const contentData = contents.map((v) => (v.data ? v.data : (0, fs_1.readFileSync)((0, path_1.join)(v.filePath, v.filename))));
48
+ const secrets1 = secrets.map((v) => {
49
+ var _a, _b;
50
+ return (Object.assign(Object.assign({}, v), { readPermissions: (_a = v.readPermissions) !== null && _a !== void 0 ? _a : [], readWritePermissions: (_b = v.readWritePermissions) !== null && _b !== void 0 ? _b : [] }));
51
+ });
52
+ const timeSeries1 = timeSeries.map((v) => {
53
+ var _a, _b, _c, _d, _e, _f;
54
+ return (Object.assign(Object.assign({}, v), { description: (_a = v.description) !== null && _a !== void 0 ? _a : '', readPermissions: (_b = v.readPermissions) !== null && _b !== void 0 ? _b : [], readWritePermissions: (_c = v.readWritePermissions) !== null && _c !== void 0 ? _c : [], maxBucketTimeRange: (_d = v.maxBucketTimeRange) !== null && _d !== void 0 ? _d : 0, maxDate: v.maxDate, minDate: v.minDate, autoDelData: (_e = v.autoDelData) !== null && _e !== void 0 ? _e : new Date(), autoDelBucket: (_f = v.autoDelBucket) !== null && _f !== void 0 ? _f : new Date() }));
55
+ });
56
+ const timeSeriesValues = timeSeries.map((v) => v.values);
57
+ const endpoint1 = endpoints.map((v) => {
58
+ var _a, _b;
59
+ return (Object.assign(Object.assign({}, v), { status: v.status, config: v.config, notificationCheckInterval: v.notificationCheckInterval, notificationPauseInterval: v.notificationPauseInterval, nbOfNotificationsBetweenPauseInterval: v.nbOfNotificationsBetweenPauseInterval, readPermissions: (_a = v.readPermissions) !== null && _a !== void 0 ? _a : [], readWritePermissions: (_b = v.readWritePermissions) !== null && _b !== void 0 ? _b : [] }));
60
+ });
61
+ const tasks1 = tasks.map((v) => {
62
+ var _a, _b, _c;
63
+ return (Object.assign(Object.assign({}, v), { id: v.id, readPermissions: (_a = v.readPermissions) !== null && _a !== void 0 ? _a : [], readWritePermissions: (_b = v.readWritePermissions) !== null && _b !== void 0 ? _b : [], subTasks: (_c = v.subTasks) !== null && _c !== void 0 ? _c : [] }));
64
+ });
65
+ const events1 = events.map((v) => {
66
+ var _a, _b;
67
+ return (Object.assign(Object.assign({}, v), { readPermissions: (_a = v.readPermissions) !== null && _a !== void 0 ? _a : [], readWritePermissions: (_b = v.readWritePermissions) !== null && _b !== void 0 ? _b : [], cause: v.cause, level: v.level }));
68
+ });
69
+ const diagrams1 = diagrams.map((v) => {
44
70
  var _a;
45
- return (Object.assign(Object.assign({}, v), { readPermissions: [], readWritePermissions: [], size: 0, fileId: '', mimetype: (_a = v.mimetype) !== null && _a !== void 0 ? _a : '' }));
46
- });
47
- const contentData = contents.map((v) => {
48
- return v.data ? v.data : (0, fs_1.readFileSync)((0, path_1.join)(v.filePath, v.filename));
49
- });
50
- const secrets1 = secrets.map((v) => (Object.assign(Object.assign({}, v), { readPermissions: [], readWritePermissions: [] })));
51
- const timeSeries1 = timeSeries.map((value) => ({
52
- id: value.id,
53
- name: value.name,
54
- description: '',
55
- readPermissions: [],
56
- readWritePermissions: [],
57
- assetRef: value.assetRef,
58
- assetRef$name: value.assetRef$name,
59
- assetTsId: value.assetTsId,
60
- minDate: value.minDate,
61
- maxBucketTimeRange: 0,
62
- tsRef: value.tsRef,
63
- autoDelData: new Date(),
64
- autoDelBucket: new Date(),
65
- }));
66
- const endpoint1 = endpoints.map((value) => ({
67
- id: value.id,
68
- name: value.name,
69
- description: value.description,
70
- status: value.status,
71
- config: value.config,
72
- notificationCheckInterval: value.notificationCheckInterval,
73
- notificationPauseInterval: value.notificationPauseInterval,
74
- nbOfNotificationsBetweenPauseInterval: value.nbOfNotificationsBetweenPauseInterval,
75
- readPermissions: [],
76
- readWritePermissions: [],
77
- }));
78
- const tasks1 = tasks.map((v) => ({
79
- id: v.id,
80
- name: v.name,
81
- readPermissions: [],
82
- readWritePermissions: [],
83
- assetRef: v.assetRef,
84
- subTasks: [],
85
- assignedTo: v.assignedTo,
86
- status: v.status,
87
- acceptedBy: v.acceptedBy,
88
- }));
89
- const events1 = events.map((v) => ({
90
- id: v.id,
91
- name: v.name,
92
- readPermissions: [],
93
- readWritePermissions: [],
94
- assetRef: v.assetRef,
95
- assetRef$name: v.assetRef$name,
96
- alertRef: v.alertRef,
97
- tsRef: v.tsRef,
98
- tags: v.tags,
99
- cause: v.cause,
100
- level: v.level,
101
- group: v.group,
102
- createdAt: v.createdAt,
103
- }));
104
- const timeseriesValues = timeSeries.map((v) => v.values);
105
- const diagrams1 = diagrams.map((v) => (Object.assign(Object.assign({}, v), { json: '', author: 'nobody' })));
106
- const flows1 = flows.map((v) => (Object.assign(Object.assign({}, v), { readPermissions: [], readWritePermissions: [], diagram: diagrams.find((v1) => v1.flow === v.id).id, name: `flow-${v.id}`, deployments: [] })));
107
- const flowRevisions1 = flowRevisions.map((v) => (Object.assign(Object.assign({}, v), { readPermissions: [], readWritePermissions: [], diagram: diagrams.find((v1) => v1.flow === v.originalId).id, name: `flow-${v.id}`, deployments: [] })));
71
+ return (Object.assign(Object.assign({}, v), { json: (_a = v.json) !== null && _a !== void 0 ? _a : '', author: 'nobody' }));
72
+ });
73
+ const flows1 = flows.map((v) => {
74
+ var _a, _b, _c;
75
+ return (Object.assign(Object.assign({}, v), { readPermissions: (_a = v.readPermissions) !== null && _a !== void 0 ? _a : [], readWritePermissions: (_b = v.readWritePermissions) !== null && _b !== void 0 ? _b : [], diagram: diagrams.find((v1) => v1.flow === v.id).id, name: `flow-${v.id}`, deployments: (_c = v.deployments) !== null && _c !== void 0 ? _c : [] }));
76
+ });
77
+ const flowRevisions1 = flowRevisions.map((v) => {
78
+ var _a, _b, _c;
79
+ return (Object.assign(Object.assign({}, v), { readPermissions: (_a = v.readPermissions) !== null && _a !== void 0 ? _a : [], readWritePermissions: (_b = v.readWritePermissions) !== null && _b !== void 0 ? _b : [], diagram: diagrams.find((v1) => v1.flow === v.originalId).id, name: `flow-${v.id}`, deployments: (_c = v.deployments) !== null && _c !== void 0 ? _c : [] }));
80
+ });
108
81
  const deployments1 = deployments.map((v) => {
109
- var _a;
110
- return (Object.assign(Object.assign({}, v), { readPermissions: [], readWritePermissions: [], diagram: (_a = v.diagram) !== null && _a !== void 0 ? _a : '', artifact: null, flowModel: { connections: [], elements: [] }, desiredStatus: 'running', actualStatus: 'generating queued', target: 'executor', name: `deployment-${v.id}` }));
82
+ var _a, _b, _c, _d, _e;
83
+ return (Object.assign(Object.assign({}, v), { readPermissions: (_a = v.readPermissions) !== null && _a !== void 0 ? _a : [], readWritePermissions: (_b = v.readWritePermissions) !== null && _b !== void 0 ? _b : [], diagram: (_c = v.diagram) !== null && _c !== void 0 ? _c : '', artifact: (_d = v.artifact) !== null && _d !== void 0 ? _d : null, flowModel: (_e = v.flowModel) !== null && _e !== void 0 ? _e : { connections: [], elements: [] }, desiredStatus: 'running', actualStatus: 'generating queued', target: 'executor', name: `deployment-${v.id}` }));
84
+ });
85
+ const functions1 = functions.map((v) => {
86
+ var _a, _b;
87
+ return (Object.assign(Object.assign({}, v), { category: 'task', readPermissions: (_a = v.readPermissions) !== null && _a !== void 0 ? _a : [], readWritePermissions: (_b = v.readWritePermissions) !== null && _b !== void 0 ? _b : [], author: 'nobody' }));
88
+ });
89
+ const functionRevisions1 = functionRevisions.map((v) => {
90
+ var _a, _b;
91
+ return (Object.assign(Object.assign({}, v), { category: 'task', readPermissions: (_a = v.readPermissions) !== null && _a !== void 0 ? _a : [], readWritePermissions: (_b = v.readWritePermissions) !== null && _b !== void 0 ? _b : [], author: 'nobody' }));
111
92
  });
112
- const functions1 = functions.map((v) => (Object.assign(Object.assign({}, v), { category: 'task', readPermissions: [], readWritePermissions: [], author: 'nobody' })));
113
- const functionRevisions1 = functionRevisions.map((v) => (Object.assign(Object.assign({}, v), { category: 'task', readPermissions: [], readWritePermissions: [], author: 'nobody' })));
114
93
  const modules1 = modules.map((v, index) => {
115
- var _a;
116
- return (Object.assign(Object.assign({}, v), { artifacts: (_a = modules[index].artifacts.map((art) => (Object.assign(Object.assign({}, art), { version: '0.0.0', id: (0, crypto_1.randomUUID)(), mimetype: '', size: 0, createdAt: '' + Date.now() })))) !== null && _a !== void 0 ? _a : [], author: 'nobody', functions: [], readPermissions: [], readWritePermissions: [] }));
94
+ var _a, _b, _c, _d;
95
+ return (Object.assign(Object.assign({}, v), { artifacts: (_a = modules[index].artifacts.map((art) => (Object.assign(Object.assign({}, art), { version: '0.0.0', id: (0, crypto_1.randomUUID)(), mimetype: '', size: 0, createdAt: '' + Date.now() })))) !== null && _a !== void 0 ? _a : [], author: 'nobody', functions: (_b = v.functions) !== null && _b !== void 0 ? _b : [], readPermissions: (_c = v.readPermissions) !== null && _c !== void 0 ? _c : [], readWritePermissions: (_d = v.readWritePermissions) !== null && _d !== void 0 ? _d : [] }));
96
+ });
97
+ const labels1 = labels.map((v) => {
98
+ var _a, _b, _c, _d;
99
+ return (Object.assign(Object.assign({}, v), { color: (_a = v.color) !== null && _a !== void 0 ? _a : '', description: (_b = v.description) !== null && _b !== void 0 ? _b : '', readPermissions: (_c = v.readPermissions) !== null && _c !== void 0 ? _c : [], readWritePermissions: (_d = v.readWritePermissions) !== null && _d !== void 0 ? _d : [] }));
100
+ });
101
+ const vaultSecrets1 = vault.map((v) => {
102
+ var _a, _b;
103
+ return (Object.assign(Object.assign({}, v), { readPermissions: (_a = v.readPermissions) !== null && _a !== void 0 ? _a : [], readWritePermissions: (_b = v.readWritePermissions) !== null && _b !== void 0 ? _b : [] }));
104
+ });
105
+ const notifications1 = notifications.map((v) => {
106
+ var _a, _b, _c;
107
+ return (Object.assign(Object.assign({}, v), { link: (_a = v.link) !== null && _a !== void 0 ? _a : '', description: (_b = v.description) !== null && _b !== void 0 ? _b : '', read: (_c = v.read) !== null && _c !== void 0 ? _c : false }));
117
108
  });
118
- const labels1 = labels.map((label) => (Object.assign(Object.assign({}, label), { color: '', description: '', readPermissions: [], readWritePermissions: [] })));
119
- const vaultSecrets1 = vault.map((v) => (Object.assign(Object.assign({}, v), { readPermissions: [], readWritePermissions: [] })));
120
- const notifications1 = notifications.map((n) => (Object.assign(Object.assign({}, n), { link: '', description: '', read: false })));
121
109
  this.assets = new asset_mock_service_1.AssetMockService(this, assets1, assetRevisions1);
122
110
  this.contents = new content_mock_service_1.ContentMockService(contents1, contentData);
123
111
  this.endpoints = new endpoint_mock_service_1.EndpointMockService(endpoint1);
124
112
  this.secrets = new secret_mock_service_1.SecretMockService(secrets1);
125
- this.timeSeries = new timeseries_mock_service_1.TimeseriesMockService(timeSeries1, timeseriesValues);
113
+ this.timeSeries = new timeseries_mock_service_1.TimeseriesMockService(timeSeries1, timeSeriesValues);
126
114
  this.tasks = new task_mock_service_1.TaskMockService(tasks1);
127
115
  this.events = new events_mock_service_1.EventsMockService(events1);
128
116
  this.users = new user_mock_service_1.UserMockService(users);
@@ -8,9 +8,19 @@ export declare class DataMockService<T> extends DataService<T> implements APIBas
8
8
  addOne(dto: any): Promise<T>;
9
9
  deleteOne(id: string): Promise<any>;
10
10
  getMany(params?: RequestParameter): Promise<Paginated<T[]>>;
11
+ /**
12
+ * Filters the elements by the passed properties. The object with these properties has to be of the form:
13
+ * {
14
+ * propertyName: string | string[] | { from: Date, to: Date },
15
+ * ...
16
+ * }.
17
+ * @param filter The Object with the properties to filter by.
18
+ * @param params Other request parameters.
19
+ */
11
20
  getManyFiltered(filter: Filter, params?: RequestParameter): Promise<Paginated<T[]>>;
12
21
  getOne(id: string, options?: Record<string, any> & {
13
22
  idKey?: string;
14
23
  }): Promise<T>;
15
24
  updateOne(id: string, dto: any): Promise<T>;
25
+ private sortData;
16
26
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DataMockService = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const data_interface_1 = require("../data.interface");
5
6
  const data_service_1 = require("../data.service");
6
7
  class DataMockService extends data_service_1.DataService {
7
8
  constructor() {
@@ -25,21 +26,41 @@ class DataMockService extends data_service_1.DataService {
25
26
  return Promise.resolve(obj);
26
27
  }
27
28
  getMany(params) {
29
+ var _a;
28
30
  const data = this.data;
31
+ if (params === null || params === void 0 ? void 0 : params.sort) {
32
+ this.sortData(data, params.sort);
33
+ }
29
34
  const page = {
30
35
  docs: data,
31
- limit: params && params.limit ? params.limit : Number.MAX_SAFE_INTEGER,
36
+ limit: (_a = params === null || params === void 0 ? void 0 : params.limit) !== null && _a !== void 0 ? _a : Number.MAX_SAFE_INTEGER,
32
37
  total: data.length,
33
38
  };
34
39
  return Promise.resolve(page);
35
40
  }
36
41
  getManyFiltered(filter, params = {}) {
42
+ var _a;
37
43
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
38
44
  const paginated = yield this.getMany(params);
39
- const newData = paginated.docs.filter((v) => { var _a; return filter.parent === v.parent || ((_a = filter.tags) === null || _a === void 0 ? void 0 : _a.some((tag) => { var _a; return (_a = v.tags) === null || _a === void 0 ? void 0 : _a.contains(tag); })) || filter.type === v.tag; });
45
+ const newData = paginated.docs.filter((doc) => Object.entries(filter).every(([filterKey, filterValue]) => {
46
+ const docValue = doc[filterKey];
47
+ if (!docValue) {
48
+ return false;
49
+ }
50
+ return ((typeof docValue === 'object' && (filterValue === docValue.name || filterValue === docValue.id)) ||
51
+ (typeof filterValue === 'object' &&
52
+ (0, data_interface_1.instanceOfTimePeriod)(filterValue) &&
53
+ new Date(docValue) >= filterValue.from &&
54
+ new Date(docValue) <= filterValue.to) ||
55
+ (docValue instanceof Date && filterValue === docValue.toISOString()) ||
56
+ (Array.isArray(filterValue) && Array.isArray(docValue) && filterValue.some((fv) => docValue.includes(fv))) ||
57
+ (Array.isArray(filterValue) && filterValue.includes(docValue)) ||
58
+ (Array.isArray(docValue) && docValue.includes(filterValue)) ||
59
+ docValue === filterValue);
60
+ }));
40
61
  const page = {
41
62
  docs: newData,
42
- limit: paginated.limit || Number.MAX_SAFE_INTEGER,
63
+ limit: (_a = paginated.limit) !== null && _a !== void 0 ? _a : Number.MAX_SAFE_INTEGER,
43
64
  total: newData.length,
44
65
  };
45
66
  return Promise.resolve(page);
@@ -57,5 +78,19 @@ class DataMockService extends data_service_1.DataService {
57
78
  return Promise.resolve(t);
58
79
  });
59
80
  }
81
+ sortData(data, sort) {
82
+ const descending = sort.startsWith('-');
83
+ const sortString = descending ? sort.substring(1) : sort;
84
+ const compareFn = (a, b) => {
85
+ let aValue = a[sortString];
86
+ let bValue = b[sortString];
87
+ if (['updatedAt', 'createdAt', 'deletedAt'].includes(sortString)) {
88
+ aValue = new Date(a[sortString]).valueOf();
89
+ bValue = new Date(b[sortString]).valueOf();
90
+ }
91
+ return descending ? bValue - aValue : aValue - bValue;
92
+ };
93
+ data.sort(compareFn);
94
+ }
60
95
  }
61
96
  exports.DataMockService = DataMockService;
@@ -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>;
@@ -45,6 +45,7 @@ class TimeseriesMockService extends BaseService {
45
45
  description: '',
46
46
  maxBucketTimeRange: 0,
47
47
  minDate: undefined,
48
+ maxDate: undefined,
48
49
  name,
49
50
  readPermissions,
50
51
  readWritePermissions,
@@ -56,6 +57,41 @@ class TimeseriesMockService extends BaseService {
56
57
  ts.data = ts.data ? [...ts.data, ...data] : data;
57
58
  return Promise.resolve(ts);
58
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
+ }
59
95
  addValue(id, value) {
60
96
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
61
97
  const ts = yield this.getOne(id, {});
@@ -7,6 +7,7 @@ export interface TimeSeries {
7
7
  assetRef?: string;
8
8
  assetRef$name?: string;
9
9
  assetTsId?: string;
10
+ maxDate: Date;
10
11
  minDate: Date;
11
12
  metrics?: string[];
12
13
  maxBucketTimeRange: number;
@@ -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.0.0",
3
+ "version": "5.2.0",
4
4
  "description": "Module for easy access to the HahnPRO API",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -24,17 +24,17 @@
24
24
  "access": "public"
25
25
  },
26
26
  "dependencies": {
27
- "axios": "~1.6.0",
27
+ "axios": "~1.6.2",
28
28
  "eventsource": "^2.0.2",
29
29
  "form-data": "^4.0.0",
30
- "jose": "^5.0.1",
30
+ "jose": "^5.1.1",
31
31
  "jwt-decode": "^4.0.0",
32
32
  "p-queue": "^6.6.2",
33
33
  "ts-mixer": "^6.0.3",
34
34
  "uuid": "^9.0.1"
35
35
  },
36
36
  "devDependencies": {
37
- "@types/eventsource": "1.1.14",
37
+ "@types/eventsource": "1.1.15",
38
38
  "axios-mock-adapter": "^1.22.0"
39
39
  },
40
40
  "engines": {