@hahnpro/hpc-api 2.0.0 → 2.1.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.
@@ -14,15 +14,13 @@ export interface AssetType {
14
14
  createdAt?: string;
15
15
  updatedAt?: string;
16
16
  }
17
- export interface Asset {
17
+ export interface AssetParent {
18
18
  id?: string;
19
19
  name: string;
20
20
  type: string | AssetType;
21
- type$name?: string;
22
21
  readPermissions: string[];
23
22
  readWritePermissions: string[];
24
23
  parent?: any | Asset;
25
- parent$name?: string;
26
24
  ancestors?: string[];
27
25
  tags?: string[];
28
26
  relations?: any[];
@@ -30,9 +28,16 @@ export interface Asset {
30
28
  image?: string;
31
29
  author?: string;
32
30
  revision?: number;
31
+ }
32
+ export interface Asset extends AssetParent {
33
+ type$name?: string;
34
+ parent$name?: string;
33
35
  attachments?: string[];
34
36
  notificationEndpoints?: string[];
35
37
  actions?: string[];
38
+ }
39
+ export interface AssetRevision extends AssetParent {
40
+ originalId?: string;
36
41
  createdAt?: string;
37
42
  updatedAt?: string;
38
43
  }
@@ -1,5 +1,5 @@
1
1
  import FormData from 'form-data';
2
- import { Asset } from './asset.interface';
2
+ import { Asset, AssetRevision } from './asset.interface';
3
3
  import { Paginated, RequestParameter } from './data.interface';
4
4
  import { DataService } from './data.service';
5
5
  import { HttpClient } from './http.service';
@@ -7,4 +7,5 @@ export declare class AssetService extends DataService<Asset> {
7
7
  constructor(httpClient: HttpClient);
8
8
  addAttachment: (id: string, form: FormData) => Promise<Asset>;
9
9
  getChildren(assetId: string, params?: RequestParameter): Promise<Paginated<Asset[]>>;
10
+ findRevisions(assetId: string): Promise<Paginated<AssetRevision[]>>;
10
11
  }
@@ -17,5 +17,8 @@ class AssetService extends data_service_1.DataService {
17
17
  getChildren(assetId, params = {}) {
18
18
  return this.getManyFiltered({ parent: assetId }, params);
19
19
  }
20
+ findRevisions(assetId) {
21
+ return this.httpClient.get(`${this.basePath}/${assetId}/revisions`);
22
+ }
20
23
  }
21
24
  exports.AssetService = AssetService;
@@ -1,5 +1,5 @@
1
1
  import { API } from '../api';
2
- import { Asset, AssetType } from '../asset.interface';
2
+ import { Asset, AssetRevision, AssetType } from '../asset.interface';
3
3
  import { Content } from '../content.interface';
4
4
  import { Secret } from '../secret.interface';
5
5
  import { TimeSeries, TimeSeriesValue } from '../timeseries.interface';
@@ -38,6 +38,7 @@ export declare class MockAPI implements API {
38
38
  userManager: UserMockService;
39
39
  constructor(initData: {
40
40
  assets?: AssetInit[];
41
+ revisions: AssetRevisionInit[];
41
42
  contents?: ContentInit[];
42
43
  endpoints?: EndpointInit[];
43
44
  secrets?: SecretInit[];
@@ -55,6 +56,7 @@ export declare type Replace<T, K extends keyof T, TReplace> = Identity<Pick<T, E
55
56
  [P in K]: TReplace;
56
57
  }>;
57
58
  export declare type AssetInit = Replace<AtLeast<Asset, 'id' | 'name' | 'type'>, 'type', AssetTypeInit | string>;
59
+ export declare type AssetRevisionInit = Replace<AtLeast<AssetRevision, 'id' | 'name' | 'type'>, 'type', AssetTypeInit | string>;
58
60
  export declare type AssetTypeInit = AtLeast<AssetType, 'id' | 'name'>;
59
61
  export declare type ContentInit = Identity<AtLeast<Content, 'id' | 'filename'> & {
60
62
  filePath?: string;
@@ -16,7 +16,7 @@ class MockAPI {
16
16
  this.httpClient = null;
17
17
  this.proxy = null;
18
18
  this.siDrive = null;
19
- const { assets = [], contents = [], endpoints = [], secrets = [], timeSeries = [], tasks = [], events = [], users } = initData;
19
+ const { assets = [], revisions = [], contents = [], endpoints = [], secrets = [], timeSeries = [], tasks = [], events = [], users, } = initData;
20
20
  const assetTypes = assets
21
21
  .map((v) => v.type)
22
22
  .map((v) => {
@@ -32,6 +32,7 @@ class MockAPI {
32
32
  };
33
33
  });
34
34
  const assets1 = assets.map((v, index) => (Object.assign(Object.assign({}, v), { readPermissions: [], readWritePermissions: [], type: assetTypes[index] })));
35
+ const revisions1 = revisions.map((v, index) => (Object.assign(Object.assign({}, v), { readPermissions: [], readWritePermissions: [], type: assetTypes[index] })));
35
36
  const contents1 = contents.map((v) => (Object.assign(Object.assign({}, v), { readPermissions: [], readWritePermissions: [], size: 0, fileId: '', mimetype: v.mimetype || '' })));
36
37
  const contentData = contents.map((v) => {
37
38
  return v.data ? v.data : (0, fs_1.readFileSync)((0, path_1.join)(v.filePath, v.filename));
@@ -90,7 +91,7 @@ class MockAPI {
90
91
  group: v.group,
91
92
  }));
92
93
  const timeseriesValues = timeSeries.map((v) => v.values);
93
- this.assets = new asset_mock_service_1.AssetMockService(this, assets1);
94
+ this.assets = new asset_mock_service_1.AssetMockService(this, assets1, revisions1);
94
95
  this.contents = new content_mock_service_1.ContentMockService(contents1, contentData);
95
96
  this.endpoints = new endpoint_mock_service_1.EndpointMockService(endpoint1);
96
97
  this.secrets = new secret_mock_service_1.SecretMockService(secrets1);
@@ -1,12 +1,14 @@
1
1
  import FormData from 'form-data';
2
- import { Asset } from '../asset.interface';
2
+ import { Asset, AssetRevision } from '../asset.interface';
3
3
  import { AssetService } from '../asset.service';
4
4
  import { Paginated, RequestParameter } from '../data.interface';
5
5
  import { MockAPI } from './api.mock';
6
6
  import { DataMockService } from './data.mock.service';
7
7
  export declare class AssetMockService extends DataMockService<Asset> implements AssetService {
8
8
  private api;
9
- constructor(api: MockAPI, assets: Asset[]);
9
+ private revisions;
10
+ constructor(api: MockAPI, assets: Asset[], revisions: AssetRevision[]);
10
11
  addAttachment(id: string, form: FormData): Promise<Asset>;
11
12
  getChildren(assetId: string, params?: RequestParameter): Promise<Paginated<Asset[]>>;
13
+ findRevisions(assetId: string): Promise<Paginated<AssetRevision[]>>;
12
14
  }
@@ -3,10 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AssetMockService = void 0;
4
4
  const data_mock_service_1 = require("./data.mock.service");
5
5
  class AssetMockService extends data_mock_service_1.DataMockService {
6
- constructor(api, assets) {
6
+ constructor(api, assets, revisions) {
7
7
  super();
8
8
  this.api = api;
9
+ this.revisions = [];
9
10
  this.data = assets;
11
+ this.revisions = revisions;
10
12
  }
11
13
  async addAttachment(id, form) {
12
14
  const asset = this.data.find((v) => v.id === id);
@@ -17,5 +19,14 @@ class AssetMockService extends data_mock_service_1.DataMockService {
17
19
  getChildren(assetId, params = {}) {
18
20
  return this.getManyFiltered({ parent: assetId }, params);
19
21
  }
22
+ findRevisions(assetId) {
23
+ const newData = this.revisions.filter((revision) => revision.originalId === assetId);
24
+ const page = {
25
+ docs: newData,
26
+ limit: Number.MAX_SAFE_INTEGER,
27
+ total: newData.length,
28
+ };
29
+ return Promise.resolve(page);
30
+ }
20
31
  }
21
32
  exports.AssetMockService = AssetMockService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hahnpro/hpc-api",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Module for easy access to the HahnPRO API",
5
5
  "license": "MIT",
6
6
  "author": {