@hahnpro/hpc-api 2.3.1 → 3.0.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.
@@ -13,34 +13,35 @@ export interface AssetType {
13
13
  actions?: string[];
14
14
  createdAt?: string;
15
15
  updatedAt?: string;
16
+ author?: string;
17
+ revision?: number;
16
18
  }
17
- export interface AssetParent {
19
+ export declare type AssetTypeRevision = AssetType & {
20
+ originalId: string;
21
+ };
22
+ export interface Asset {
18
23
  id?: string;
19
24
  name: string;
20
25
  type: string | AssetType;
26
+ type$name?: string;
21
27
  readPermissions: string[];
22
28
  readWritePermissions: string[];
23
29
  parent?: any | Asset;
30
+ parent$name?: string;
24
31
  ancestors?: string[];
25
32
  tags?: string[];
26
33
  relations?: any[];
27
34
  data?: any;
28
35
  image?: string;
29
- author?: string;
30
- revision?: number;
31
- }
32
- export interface Asset extends AssetParent {
33
- type$name?: string;
34
- parent$name?: string;
35
36
  attachments?: string[];
36
37
  notificationEndpoints?: string[];
37
38
  actions?: string[];
39
+ author?: string;
40
+ revision?: number;
38
41
  }
39
- export interface AssetRevision extends AssetParent {
40
- originalId?: string;
41
- createdAt?: string;
42
- updatedAt?: string;
43
- }
42
+ export declare type AssetRevision = Asset & {
43
+ originalId: string;
44
+ };
44
45
  export interface Attachment {
45
46
  id?: string;
46
47
  filename: string;
@@ -61,4 +62,9 @@ export interface Action {
61
62
  responseType?: string;
62
63
  readPermissions: string[];
63
64
  readWritePermissions: string[];
65
+ author?: string;
66
+ revision?: number;
64
67
  }
68
+ export declare type ActionRevision = Action & {
69
+ originalId: string;
70
+ };
@@ -7,5 +7,7 @@ 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
+ getRevisions(assetId: string): Promise<Paginated<AssetRevision[]>>;
11
+ rollback(assetId: string, revisionId: string): Promise<Asset>;
12
+ deleteRevision(assetId: string, revisionId: string): Promise<any>;
11
13
  }
@@ -17,8 +17,14 @@ 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) {
20
+ getRevisions(assetId) {
21
21
  return this.httpClient.get(`${this.basePath}/${assetId}/revisions`);
22
22
  }
23
+ rollback(assetId, revisionId) {
24
+ return this.httpClient.put(`${this.basePath}/${assetId}/rollback`, { revisionId });
25
+ }
26
+ deleteRevision(assetId, revisionId) {
27
+ return this.httpClient.delete(`${this.basePath}/${assetId}/revisions/${revisionId}`);
28
+ }
23
29
  }
24
30
  exports.AssetService = AssetService;
@@ -1,6 +1,10 @@
1
1
  import { AssetType } from './asset.interface';
2
2
  import { DataService } from './data.service';
3
3
  import { HttpClient } from './http.service';
4
+ import { Paginated } from './data.interface';
4
5
  export declare class AssetTypesService extends DataService<AssetType> {
5
6
  constructor(httpClient: HttpClient);
7
+ getRevisions(id: string): Promise<Paginated<AssetType[]>>;
8
+ rollback(id: string, revisionId: string): Promise<AssetType>;
9
+ deleteRevision(id: string, revisionId: string): Promise<any>;
6
10
  }
@@ -6,5 +6,14 @@ class AssetTypesService extends data_service_1.DataService {
6
6
  constructor(httpClient) {
7
7
  super(httpClient, '/assettypes');
8
8
  }
9
+ getRevisions(id) {
10
+ return this.httpClient.get(`${this.basePath}/${id}/revisions`);
11
+ }
12
+ rollback(id, revisionId) {
13
+ return this.httpClient.put(`${this.basePath}/${id}/rollback`, { revisionId });
14
+ }
15
+ deleteRevision(id, revisionId) {
16
+ return this.httpClient.delete(`${this.basePath}/${id}/revisions/${revisionId}`);
17
+ }
9
18
  }
10
19
  exports.AssetTypesService = AssetTypesService;
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import FormData from 'form-data';
3
4
  import { Content, ReturnType } from './content.interface';
4
5
  import { DataService } from './data.service';
@@ -13,7 +13,7 @@ class ContentService extends data_service_1.DataService {
13
13
  }
14
14
  async download(id, second) {
15
15
  let returnType;
16
- if (typeof second === 'boolean' || !second) {
16
+ if (typeof second === 'boolean' || second == null) {
17
17
  returnType = second ? content_interface_1.ReturnType.ARRAYBUFFER : content_interface_1.ReturnType.BLOB;
18
18
  }
19
19
  else {
@@ -4,8 +4,6 @@ export interface FlowFunctionDto {
4
4
  readPermissions: string[];
5
5
  readWritePermissions: string[];
6
6
  author: string;
7
- current: string;
8
- history: string[] | HistoryEntry[];
9
7
  name?: string;
10
8
  description?: string;
11
9
  icon?: string;
@@ -17,12 +15,12 @@ export interface FlowFunctionDto {
17
15
  tags?: string[];
18
16
  createdAt?: string;
19
17
  updatedAt?: string;
18
+ revision?: string;
20
19
  }
21
- export interface HistoryEntry {
22
- author: string;
23
- createdAt: string;
20
+ export declare type FlowFunctionRevision = FlowFunctionDto & {
24
21
  id: string;
25
- }
22
+ originalId: string;
23
+ };
26
24
  interface Stream {
27
25
  name: string;
28
26
  }
@@ -1,9 +1,11 @@
1
1
  import { DataService } from './data.service';
2
2
  import { FlowFunctionDto } from './flow-function.interface';
3
3
  import { HttpClient } from './http.service';
4
+ import { Paginated } from './data.interface';
4
5
  export declare class FlowFunctionService extends DataService<FlowFunctionDto> {
5
6
  constructor(httpClient: HttpClient);
6
7
  addMany(dto: any[]): Promise<FlowFunctionDto[]>;
7
- getOneWithHistory(fqn: string): Promise<FlowFunctionDto>;
8
- rollback(fqn: string, historyId: string): Promise<FlowFunctionDto>;
8
+ getRevisions(fqn: string): Promise<Paginated<FlowFunctionDto[]>>;
9
+ rollback(fqn: string, revisionId: string): Promise<FlowFunctionDto>;
10
+ deleteRevision(fqn: string, revisionId: string): Promise<any>;
9
11
  }
@@ -10,11 +10,14 @@ class FlowFunctionService extends data_service_1.DataService {
10
10
  const reqs = dto.map((v) => this.addOne(v));
11
11
  return Promise.all(reqs);
12
12
  }
13
- getOneWithHistory(fqn) {
14
- return this.httpClient.get(`${this.basePath}/${fqn}/history`);
13
+ getRevisions(fqn) {
14
+ return this.httpClient.get(`${this.basePath}/${fqn}/revisions`);
15
15
  }
16
- rollback(fqn, historyId) {
17
- return this.httpClient.put(`${this.basePath}/${fqn}/rollback/${historyId}`, {});
16
+ rollback(fqn, revisionId) {
17
+ return this.httpClient.put(`${this.basePath}/${fqn}/rollback`, { revisionId });
18
+ }
19
+ deleteRevision(fqn, revisionId) {
20
+ return this.httpClient.delete(`${this.basePath}/${fqn}/revisions/${revisionId}`);
18
21
  }
19
22
  }
20
23
  exports.FlowFunctionService = FlowFunctionService;
@@ -7,6 +7,9 @@ export interface FlowDto extends Resource {
7
7
  dashboard?: DashboardItem[];
8
8
  propertiesSchema?: JsonSchemaForm;
9
9
  }
10
+ export declare type FlowRevision = FlowDto & {
11
+ originalId: string;
12
+ };
10
13
  export interface DashboardItem {
11
14
  id: string;
12
15
  cols: number;
@@ -9,6 +9,9 @@ export declare class FlowService extends DataService<FlowDto> {
9
9
  getMany(params?: RequestParameter): Promise<Paginated<FlowDto[]>>;
10
10
  getOne(id: string, options?: any): Promise<FlowDto>;
11
11
  getFlowWithDiagram(diagramId: string): Promise<FlowDto>;
12
- getRevisions(id: string): Promise<FlowDiagram[]>;
12
+ getDiagramRevisions(id: string): Promise<FlowDiagram[]>;
13
13
  isDeploymentOnLatestDiagramVersion(depl: FlowDeployment): Promise<boolean>;
14
+ getRevisions(id: string): Promise<Paginated<FlowDto[]>>;
15
+ rollback(id: string, revisionId: string): Promise<FlowDto>;
16
+ deleteRevision(id: string, revisionId: string): Promise<any>;
14
17
  }
@@ -21,14 +21,23 @@ class FlowService extends data_service_1.DataService {
21
21
  getFlowWithDiagram(diagramId) {
22
22
  return this.httpClient.get(`${this.basePath}/diagram/${diagramId}`);
23
23
  }
24
- getRevisions(id) {
24
+ getDiagramRevisions(id) {
25
25
  return this.httpClient.get(`${this.basePath}/${id}/revisions`);
26
26
  }
27
27
  async isDeploymentOnLatestDiagramVersion(depl) {
28
28
  const flowId = typeof depl.flow === 'string' ? depl.flow : depl.flow.id;
29
29
  const diagramId = typeof depl.diagram === 'string' ? depl.diagram : depl.diagram.id;
30
- const revisions = await this.getRevisions(flowId);
30
+ const revisions = await this.getDiagramRevisions(flowId);
31
31
  return revisions.reverse()[0].id === diagramId;
32
32
  }
33
+ getRevisions(id) {
34
+ return this.httpClient.get(`${this.basePath}/${id}/revisions`);
35
+ }
36
+ rollback(id, revisionId) {
37
+ return this.httpClient.put(`${this.basePath}/${id}/rollback`, { revisionId });
38
+ }
39
+ deleteRevision(id, revisionId) {
40
+ return this.httpClient.delete(`${this.basePath}/${id}/revisions/${revisionId}`);
41
+ }
33
42
  }
34
43
  exports.FlowService = FlowService;
@@ -19,9 +19,9 @@ import { FlowDeploymentService } from '../flow-deployment.service';
19
19
  import { FlowFunctionService } from '../flow-function.service';
20
20
  import { FlowModuleService } from '../flow-module.service';
21
21
  import { FlowService } from '../flow.service';
22
- import { FlowDiagram, FlowDto } from '../flow.interface';
22
+ import { FlowDiagram, FlowDto, FlowRevision } from '../flow.interface';
23
23
  import { FlowDeployment } from '../flow-deployment.interface';
24
- import { FlowFunctionDto } from '../flow-function.interface';
24
+ import { FlowFunctionDto, FlowFunctionRevision } from '../flow-function.interface';
25
25
  import { FlowModule } from '../flow-module.interface';
26
26
  import { Artifact } from '../storage.interface';
27
27
  export declare class MockAPI implements API {
@@ -51,7 +51,7 @@ export declare class MockAPI implements API {
51
51
  userManager: UserMockService;
52
52
  constructor(initData: {
53
53
  assets?: AssetInit[];
54
- revisions?: AssetRevisionInit[];
54
+ assetRevisions?: AssetRevisionInit[];
55
55
  contents?: ContentInit[];
56
56
  endpoints?: EndpointInit[];
57
57
  secrets?: SecretInit[];
@@ -60,8 +60,10 @@ export declare class MockAPI implements API {
60
60
  events?: EventInit[];
61
61
  users?: UserInit;
62
62
  flows?: FlowInit[];
63
+ flowRevisions?: FlowRevisionInit[];
63
64
  deployments?: FlowDeploymentInit[];
64
65
  functions?: FlowFunctionInit[];
66
+ functionRevisions?: FlowFunctionRevisionInit[];
65
67
  modules?: FlowModuleInit[];
66
68
  diagrams?: FlowDiagramInit[];
67
69
  });
@@ -74,7 +76,7 @@ export declare type Replace<T, K extends keyof T, TReplace> = Identity<Pick<T, E
74
76
  [P in K]: TReplace;
75
77
  }>;
76
78
  export declare type AssetInit = Replace<AtLeast<Asset, 'id' | 'name' | 'type'>, 'type', AssetTypeInit | string>;
77
- export declare type AssetRevisionInit = Replace<AtLeast<AssetRevision, 'id' | 'name' | 'type'>, 'type', AssetTypeInit | string>;
79
+ export declare type AssetRevisionInit = Replace<AtLeast<AssetRevision, 'id' | 'name' | 'type' | 'originalId'>, 'type', AssetTypeInit | string>;
78
80
  export declare type AssetTypeInit = AtLeast<AssetType, 'id' | 'name'>;
79
81
  export declare type ContentInit = Identity<AtLeast<Content, 'id' | 'filename'> & {
80
82
  filePath?: string;
@@ -88,10 +90,10 @@ export declare type TimeSeriesInit = Identity<AtLeast<TimeSeries, 'id' | 'name'>
88
90
  export declare type TaskInit = AtLeast<Task, 'name' | 'assignedTo'>;
89
91
  export declare type EventInit = AtLeast<Event, 'name'>;
90
92
  export declare type FlowInit = AtLeast<FlowDto, 'id'>;
93
+ export declare type FlowRevisionInit = AtLeast<FlowRevision, 'id' | 'originalId'>;
91
94
  export declare type FlowDeploymentInit = AtLeast<FlowDeployment, 'id' | 'flow'>;
92
- export declare type FlowFunctionInit = AtLeast<Identity<FlowFunctionDto & {
93
- id: string;
94
- }>, 'fqn' | 'id'>;
95
+ export declare type FlowFunctionInit = AtLeast<FlowFunctionDto, 'fqn'>;
96
+ export declare type FlowFunctionRevisionInit = AtLeast<FlowFunctionRevision, 'fqn' | 'id' | 'originalId'>;
95
97
  export declare type FlowModuleInit = Replace<AtLeast<FlowModule, 'name'>, 'artifacts', ArtifactInit[]>;
96
98
  export declare type ArtifactInit = AtLeast<Artifact & {
97
99
  path: string;
@@ -21,7 +21,7 @@ class MockAPI {
21
21
  this.httpClient = null;
22
22
  this.proxy = null;
23
23
  this.siDrive = null;
24
- const { assets = [], revisions = [], contents = [], endpoints = [], secrets = [], timeSeries = [], tasks = [], events = [], users, flows = [], deployments = [], functions = [], modules = [], diagrams = [], } = initData;
24
+ const { assets = [], assetRevisions = [], contents = [], endpoints = [], secrets = [], timeSeries = [], tasks = [], events = [], users, flows = [], flowRevisions = [], deployments = [], functions = [], functionRevisions = [], modules = [], diagrams = [], } = initData;
25
25
  const assetTypes = assets
26
26
  .map((v) => v.type)
27
27
  .map((v) => {
@@ -37,7 +37,7 @@ class MockAPI {
37
37
  };
38
38
  });
39
39
  const assets1 = assets.map((v, index) => (Object.assign(Object.assign({}, v), { readPermissions: [], readWritePermissions: [], type: assetTypes[index] })));
40
- const revisions1 = revisions.map((v, index) => (Object.assign(Object.assign({}, v), { readPermissions: [], readWritePermissions: [], type: assetTypes[index] })));
40
+ const assetRevisions1 = assetRevisions.map((v, index) => (Object.assign(Object.assign({}, v), { readPermissions: [], readWritePermissions: [], type: assetTypes[index] })));
41
41
  const contents1 = contents.map((v) => (Object.assign(Object.assign({}, v), { readPermissions: [], readWritePermissions: [], size: 0, fileId: '', mimetype: v.mimetype || '' })));
42
42
  const contentData = contents.map((v) => {
43
43
  return v.data ? v.data : (0, fs_1.readFileSync)((0, path_1.join)(v.filePath, v.filename));
@@ -98,30 +98,18 @@ class MockAPI {
98
98
  const timeseriesValues = timeSeries.map((v) => v.values);
99
99
  const diagrams1 = diagrams.map((v) => (Object.assign(Object.assign({}, v), { json: '', author: 'nobody' })));
100
100
  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: [] })));
101
+ 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: [] })));
101
102
  const deployments1 = deployments.map((v) => {
102
103
  var _a;
103
104
  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}` }));
104
105
  });
105
- const functions1 = functions.map((v) => {
106
- var _a;
107
- return (Object.assign(Object.assign({}, v), { category: 'task', readPermissions: [], readWritePermissions: [], author: 'nobody', current: v.id, history: [v.id, ...((_a = v === null || v === void 0 ? void 0 : v.history) !== null && _a !== void 0 ? _a : [])] }));
108
- });
109
- const historyMap = new Map();
110
- functions1.forEach((func) => {
111
- func.history.forEach((hist) => {
112
- if (historyMap.has(func.fqn)) {
113
- historyMap.get(func.fqn).push(functions1.find((v) => v.id === hist));
114
- }
115
- else {
116
- historyMap.set(func.fqn, [functions1.find((v) => v.id === hist)]);
117
- }
118
- });
119
- });
106
+ const functions1 = functions.map((v) => (Object.assign(Object.assign({}, v), { category: 'task', readPermissions: [], readWritePermissions: [], author: 'nobody' })));
107
+ const functionRevisions1 = functionRevisions.map((v) => (Object.assign(Object.assign({}, v), { category: 'task', readPermissions: [], readWritePermissions: [], author: 'nobody' })));
120
108
  const modules1 = modules.map((v, index) => {
121
109
  var _a;
122
110
  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: [] }));
123
111
  });
124
- this.assets = new asset_mock_service_1.AssetMockService(this, assets1, revisions1);
112
+ this.assets = new asset_mock_service_1.AssetMockService(this, assets1, assetRevisions1);
125
113
  this.contents = new content_mock_service_1.ContentMockService(contents1, contentData);
126
114
  this.endpoints = new endpoint_mock_service_1.EndpointMockService(endpoint1);
127
115
  this.secrets = new secret_mock_service_1.SecretMockService(secrets1);
@@ -129,9 +117,9 @@ class MockAPI {
129
117
  this.tasks = new task_mock_service_1.TaskMockService(tasks1);
130
118
  this.events = new events_mock_service_1.EventsMockService(events1);
131
119
  this.users = new user_mock_service_1.UserMockService(users);
132
- this.flows = new flow_mock_service_1.FlowMockService(flows1, diagrams1);
120
+ this.flows = new flow_mock_service_1.FlowMockService(flows1, diagrams1, flowRevisions1);
133
121
  this.flowDeployments = new flow_deployment_mock_service_1.FlowDeploymentMockService(deployments1, this);
134
- this.flowFunctions = new flow_functions_mock_service_1.FlowFunctionsMockService(functions1, historyMap);
122
+ this.flowFunctions = new flow_functions_mock_service_1.FlowFunctionsMockService(functions1, functionRevisions1);
135
123
  this.flowModules = new flow_modules_mock_service_1.FlowModulesMockService(modules1);
136
124
  this.assetManager = this.assets;
137
125
  this.contentManager = this.contents;
@@ -8,7 +8,12 @@ export declare class AssetMockService extends DataMockService<Asset> implements
8
8
  private api;
9
9
  private revisions;
10
10
  constructor(api: MockAPI, assets: Asset[], revisions: AssetRevision[]);
11
+ addOne(dto: Asset): Promise<Asset>;
12
+ deleteOne(assetId: string): Promise<any>;
13
+ updateOne(assetId: string, dto: Asset): Promise<Asset>;
11
14
  addAttachment(id: string, form: FormData): Promise<Asset>;
12
15
  getChildren(assetId: string, params?: RequestParameter): Promise<Paginated<Asset[]>>;
13
- findRevisions(assetId: string): Promise<Paginated<AssetRevision[]>>;
16
+ getRevisions(assetId: string): Promise<Paginated<AssetRevision[]>>;
17
+ rollback(assetId: string, revisionId: string): Promise<Asset>;
18
+ deleteRevision(assetId: string, revisionId: string): Promise<any>;
14
19
  }
@@ -2,13 +2,32 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AssetMockService = void 0;
4
4
  const data_mock_service_1 = require("./data.mock.service");
5
+ const crypto_1 = require("crypto");
5
6
  class AssetMockService extends data_mock_service_1.DataMockService {
6
7
  constructor(api, assets, revisions) {
7
8
  super();
8
9
  this.api = api;
9
- this.revisions = [];
10
- this.data = assets;
11
10
  this.revisions = revisions;
11
+ this.data = assets;
12
+ }
13
+ addOne(dto) {
14
+ const id = (0, crypto_1.randomUUID)();
15
+ this.revisions.push(Object.assign(Object.assign({}, dto), { originalId: dto.id }));
16
+ return super.addOne(dto);
17
+ }
18
+ deleteOne(assetId) {
19
+ this.revisions
20
+ .filter((revision) => revision.originalId === assetId)
21
+ .forEach((revision) => {
22
+ const index = this.revisions.indexOf(revision);
23
+ this.revisions.splice(index, 1);
24
+ });
25
+ return super.deleteOne(assetId);
26
+ }
27
+ async updateOne(assetId, dto) {
28
+ await super.deleteOne(assetId);
29
+ const asset = await this.addOne(dto);
30
+ return Promise.resolve(asset);
12
31
  }
13
32
  async addAttachment(id, form) {
14
33
  const asset = this.data.find((v) => v.id === id);
@@ -19,14 +38,23 @@ class AssetMockService extends data_mock_service_1.DataMockService {
19
38
  getChildren(assetId, params = {}) {
20
39
  return this.getManyFiltered({ parent: assetId }, params);
21
40
  }
22
- findRevisions(assetId) {
23
- const newData = this.revisions.filter((revision) => revision.originalId === assetId);
41
+ getRevisions(assetId) {
42
+ const revisions = this.revisions.filter((revision) => revision.originalId === assetId);
24
43
  const page = {
25
- docs: newData,
44
+ docs: revisions,
26
45
  limit: Number.MAX_SAFE_INTEGER,
27
- total: newData.length,
46
+ total: revisions.length,
28
47
  };
29
48
  return Promise.resolve(page);
30
49
  }
50
+ rollback(assetId, revisionId) {
51
+ const asset = this.revisions.find((revision) => revision.id === revisionId);
52
+ return Promise.resolve(asset);
53
+ }
54
+ deleteRevision(assetId, revisionId) {
55
+ const index = this.revisions.findIndex((revision) => revision.id === revisionId);
56
+ this.revisions.splice(index, 1);
57
+ return Promise.resolve(revisionId);
58
+ }
31
59
  }
32
60
  exports.AssetMockService = AssetMockService;
@@ -1,6 +1,14 @@
1
- import { AssetType } from '../asset.interface';
1
+ import { AssetType, AssetTypeRevision } from '../asset.interface';
2
2
  import { AssetTypesService } from '../assettypes.service';
3
3
  import { DataMockService } from './data.mock.service';
4
+ import { Paginated } from '../data.interface';
4
5
  export declare class AssetTypesMockService extends DataMockService<AssetType> implements AssetTypesService {
5
- constructor(assetTypes: AssetType[]);
6
+ private revisions;
7
+ constructor(assetTypes: AssetType[], revisions: AssetTypeRevision[]);
8
+ addOne(dto: AssetType): Promise<AssetType>;
9
+ deleteOne(id: string): Promise<any>;
10
+ updateOne(id: string, dto: AssetType): Promise<AssetType>;
11
+ getRevisions(id: string): Promise<Paginated<AssetTypeRevision[]>>;
12
+ rollback(id: string, revisionId: string): Promise<AssetType>;
13
+ deleteRevision(assetId: string, revisionId: string): Promise<any>;
6
14
  }
@@ -2,10 +2,49 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AssetTypesMockService = void 0;
4
4
  const data_mock_service_1 = require("./data.mock.service");
5
+ const crypto_1 = require("crypto");
5
6
  class AssetTypesMockService extends data_mock_service_1.DataMockService {
6
- constructor(assetTypes) {
7
+ constructor(assetTypes, revisions) {
7
8
  super();
9
+ this.revisions = revisions;
8
10
  this.data = assetTypes;
9
11
  }
12
+ addOne(dto) {
13
+ const id = (0, crypto_1.randomUUID)();
14
+ this.revisions.push(Object.assign(Object.assign({}, dto), { id, originalId: dto.id }));
15
+ return super.addOne(dto);
16
+ }
17
+ deleteOne(id) {
18
+ this.revisions
19
+ .filter((revision) => revision.originalId === id)
20
+ .forEach((revision) => {
21
+ const index = this.revisions.indexOf(revision);
22
+ this.revisions.splice(index, 1);
23
+ });
24
+ return super.deleteOne(id);
25
+ }
26
+ async updateOne(id, dto) {
27
+ await super.deleteOne(id);
28
+ const assetType = await this.addOne(dto);
29
+ return Promise.resolve(assetType);
30
+ }
31
+ getRevisions(id) {
32
+ const revisions = this.revisions.filter((revision) => revision.originalId === id);
33
+ const page = {
34
+ docs: revisions,
35
+ limit: Number.MAX_SAFE_INTEGER,
36
+ total: revisions.length,
37
+ };
38
+ return Promise.resolve(page);
39
+ }
40
+ rollback(id, revisionId) {
41
+ const assetType = this.revisions.find((revision) => revision.id === revisionId);
42
+ return Promise.resolve(assetType);
43
+ }
44
+ deleteRevision(assetId, revisionId) {
45
+ const index = this.revisions.findIndex((revision) => revision.id === revisionId);
46
+ this.revisions.splice(index, 1);
47
+ return Promise.resolve(revisionId);
48
+ }
10
49
  }
11
50
  exports.AssetTypesMockService = AssetTypesMockService;
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import FormData from 'form-data';
3
4
  import { Readable } from 'stream';
4
5
  import { Content, ReturnType } from '../content.interface';
@@ -15,7 +15,7 @@ class ContentMockService extends data_mock_service_1.DataMockService {
15
15
  }
16
16
  download(id, second) {
17
17
  let returnType;
18
- if (typeof second === 'boolean' || !second) {
18
+ if (typeof second === 'boolean' || second == null) {
19
19
  returnType = second ? content_interface_1.ReturnType.ARRAYBUFFER : content_interface_1.ReturnType.BLOB;
20
20
  }
21
21
  else {
@@ -1,14 +1,16 @@
1
1
  import { DataMockService } from './data.mock.service';
2
- import { FlowFunctionDto } from '../flow-function.interface';
2
+ import { FlowFunctionDto, FlowFunctionRevision } from '../flow-function.interface';
3
3
  import { FlowFunctionService } from '../flow-function.service';
4
+ import { Paginated } from '../data.interface';
4
5
  export declare class FlowFunctionsMockService extends DataMockService<FlowFunctionDto> implements FlowFunctionService {
5
- private history;
6
- constructor(functions: FlowFunctionDto[], history: Map<string, Array<FlowFunctionDto & {
7
- id: string;
8
- }>>);
9
- getOneWithHistory(fqn: string): Promise<FlowFunctionDto>;
10
- rollback(fqn: string, historyId: string): Promise<FlowFunctionDto>;
6
+ private revisions;
7
+ constructor(functions: FlowFunctionDto[], revisions: FlowFunctionRevision[]);
8
+ addOne(dto: FlowFunctionDto): Promise<FlowFunctionDto>;
9
+ deleteOne(fqn: string): Promise<any>;
10
+ updateOne(fqn: string, dto: FlowFunctionDto): Promise<FlowFunctionDto>;
11
11
  getOne(fqn: string, options?: any): Promise<FlowFunctionDto>;
12
12
  private getOneById;
13
- updateOne(fqn: string, dto: FlowFunctionDto): Promise<FlowFunctionDto>;
13
+ getRevisions(fqn: string): Promise<Paginated<FlowFunctionRevision[]>>;
14
+ rollback(fqn: string, revisionId: string): Promise<FlowFunctionDto>;
15
+ deleteRevision(fqn: string, revisionId: string): Promise<any>;
14
16
  }
@@ -4,24 +4,32 @@ exports.FlowFunctionsMockService = void 0;
4
4
  const data_mock_service_1 = require("./data.mock.service");
5
5
  const crypto_1 = require("crypto");
6
6
  class FlowFunctionsMockService extends data_mock_service_1.DataMockService {
7
- constructor(functions, history) {
7
+ constructor(functions, revisions) {
8
8
  super();
9
- this.history = history;
9
+ this.revisions = revisions;
10
10
  this.data = functions;
11
11
  }
12
- async getOneWithHistory(fqn) {
13
- const func = await this.getOne(fqn);
14
- return Promise.resolve(Object.assign(Object.assign({}, func), { history: await Promise.all(func.history.map(async (v) => {
15
- const func1 = (await this.getOneById(v));
16
- return { author: func1.author, createdAt: '', id: func1.id };
17
- })) }));
12
+ addOne(dto) {
13
+ const id = (0, crypto_1.randomUUID)();
14
+ this.revisions.push(Object.assign(Object.assign({}, dto), { id, originalId: dto.fqn }));
15
+ return super.addOne(dto);
16
+ }
17
+ deleteOne(fqn) {
18
+ const index = this.data.findIndex((v) => v.fqn === fqn);
19
+ this.data.splice(index, 1);
20
+ this.revisions
21
+ .filter((revision) => revision.originalId === fqn)
22
+ .forEach((revision) => {
23
+ const index = this.revisions.indexOf(revision);
24
+ this.revisions.splice(index, 1);
25
+ });
26
+ return Promise.resolve(undefined);
18
27
  }
19
- rollback(fqn, historyId) {
20
- const hist = this.history.get(fqn).find((v) => v.id === historyId);
28
+ async updateOne(fqn, dto) {
21
29
  const index = this.data.findIndex((v) => v.fqn === fqn);
22
- hist.current = hist.id;
23
- this.data[index] = hist;
24
- return Promise.resolve(hist);
30
+ this.data.splice(index, 1);
31
+ const flowFunction = await this.addOne(dto);
32
+ return Promise.resolve(flowFunction);
25
33
  }
26
34
  getOne(fqn, options) {
27
35
  const t = this.data.find((v) => v.fqn === fqn);
@@ -30,12 +38,23 @@ class FlowFunctionsMockService extends data_mock_service_1.DataMockService {
30
38
  async getOneById(id) {
31
39
  return this.data.find((v) => v.id === id);
32
40
  }
33
- async updateOne(fqn, dto) {
34
- const id = (0, crypto_1.randomUUID)();
35
- const exDto = Object.assign(Object.assign({}, dto), { id, current: id });
36
- exDto.history.push(id);
37
- this.history.get(fqn).push(exDto);
38
- return exDto;
41
+ getRevisions(fqn) {
42
+ const revisions = this.revisions.filter((revision) => revision.originalId === fqn);
43
+ const page = {
44
+ docs: revisions,
45
+ limit: Number.MAX_SAFE_INTEGER,
46
+ total: revisions.length,
47
+ };
48
+ return Promise.resolve(page);
49
+ }
50
+ rollback(fqn, revisionId) {
51
+ const assetType = this.revisions.find((revision) => revision.id === revisionId);
52
+ return Promise.resolve(assetType);
53
+ }
54
+ deleteRevision(fqn, revisionId) {
55
+ const index = this.revisions.findIndex((revision) => revision.id === revisionId);
56
+ this.revisions.splice(index, 1);
57
+ return Promise.resolve(revisionId);
39
58
  }
40
59
  }
41
60
  exports.FlowFunctionsMockService = FlowFunctionsMockService;
@@ -1,13 +1,20 @@
1
1
  import { DataMockService } from './data.mock.service';
2
- import { FlowDiagram, FlowDto } from '../flow.interface';
2
+ import { FlowDiagram, FlowDto, FlowRevision } from '../flow.interface';
3
3
  import { FlowService } from '../flow.service';
4
4
  import { Paginated, RequestParameter } from '../data.interface';
5
5
  import { FlowDeployment } from '../flow-deployment.interface';
6
6
  export declare class FlowMockService extends DataMockService<FlowDto> implements FlowService {
7
7
  private diagrams;
8
- constructor(flows: FlowDto[], diagrams: FlowDiagram[]);
8
+ private revisions;
9
+ constructor(flows: FlowDto[], diagrams: FlowDiagram[], revisions: FlowRevision[]);
10
+ addOne(dto: FlowDto): Promise<FlowDto>;
11
+ deleteOne(id: string): Promise<any>;
12
+ updateOne(id: string, dto: FlowDto): Promise<FlowDto>;
9
13
  isDeploymentOnLatestDiagramVersion(depl: FlowDeployment): Promise<boolean>;
10
- getRevisions(id: string): Promise<FlowDiagram[]>;
14
+ getDiagramRevisions(id: string): Promise<FlowDiagram[]>;
11
15
  getFlowWithDiagram(diagramId: string): Promise<FlowDto>;
12
16
  getMany(params?: RequestParameter): Promise<Paginated<FlowDto[]>>;
17
+ getRevisions(id: string): Promise<Paginated<FlowRevision[]>>;
18
+ rollback(id: string, revisionId: string): Promise<FlowDto>;
19
+ deleteRevision(id: string, revisionId: string): Promise<any>;
13
20
  }
@@ -2,19 +2,40 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FlowMockService = void 0;
4
4
  const data_mock_service_1 = require("./data.mock.service");
5
+ const crypto_1 = require("crypto");
5
6
  class FlowMockService extends data_mock_service_1.DataMockService {
6
- constructor(flows, diagrams) {
7
+ constructor(flows, diagrams, revisions) {
7
8
  super();
8
9
  this.diagrams = diagrams;
10
+ this.revisions = revisions;
9
11
  this.data = flows;
10
12
  }
13
+ addOne(dto) {
14
+ const id = (0, crypto_1.randomUUID)();
15
+ this.revisions.push(Object.assign(Object.assign({}, dto), { id, originalId: dto.id }));
16
+ return super.addOne(dto);
17
+ }
18
+ deleteOne(id) {
19
+ this.revisions
20
+ .filter((revision) => revision.originalId === id)
21
+ .forEach((revision) => {
22
+ const index = this.revisions.indexOf(revision);
23
+ this.revisions.splice(index, 1);
24
+ });
25
+ return super.deleteOne(id);
26
+ }
27
+ async updateOne(id, dto) {
28
+ await super.deleteOne(id);
29
+ const flow = await this.addOne(dto);
30
+ return Promise.resolve(flow);
31
+ }
11
32
  async isDeploymentOnLatestDiagramVersion(depl) {
12
33
  const flowId = typeof depl.flow === 'string' ? depl.flow : depl.flow.id;
13
34
  const diagramId = typeof depl.diagram === 'string' ? depl.diagram : depl.diagram.id;
14
- const revisions = await this.getRevisions(flowId);
35
+ const revisions = await this.getDiagramRevisions(flowId);
15
36
  return revisions.reverse()[0].id === diagramId;
16
37
  }
17
- getRevisions(id) {
38
+ getDiagramRevisions(id) {
18
39
  return Promise.resolve(this.diagrams.filter((v) => v.flow === id));
19
40
  }
20
41
  getFlowWithDiagram(diagramId) {
@@ -28,5 +49,23 @@ class FlowMockService extends data_mock_service_1.DataMockService {
28
49
  limit: 0,
29
50
  };
30
51
  }
52
+ getRevisions(id) {
53
+ const revisions = this.revisions.filter((revision) => revision.originalId === id);
54
+ const page = {
55
+ docs: revisions,
56
+ limit: Number.MAX_SAFE_INTEGER,
57
+ total: revisions.length,
58
+ };
59
+ return Promise.resolve(page);
60
+ }
61
+ rollback(id, revisionId) {
62
+ const flow = this.revisions.find((revision) => revision.id === revisionId);
63
+ return Promise.resolve(flow);
64
+ }
65
+ deleteRevision(id, revisionId) {
66
+ const index = this.revisions.findIndex((revision) => revision.id === revisionId);
67
+ this.revisions.splice(index, 1);
68
+ return Promise.resolve(revisionId);
69
+ }
31
70
  }
32
71
  exports.FlowMockService = FlowMockService;
@@ -15,4 +15,5 @@ export interface Resource {
15
15
  createdAt?: string | Date;
16
16
  updatedAt?: string | Date;
17
17
  deleteddAt?: string | Date;
18
+ revision?: string;
18
19
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hahnpro/hpc-api",
3
- "version": "2.3.1",
3
+ "version": "3.0.0",
4
4
  "description": "Module for easy access to the HahnPRO API",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -24,8 +24,8 @@
24
24
  "access": "public"
25
25
  },
26
26
  "dependencies": {
27
- "axios": "~0.26.1",
28
- "eventsource": "^2.0.1",
27
+ "axios": "~0.27.2",
28
+ "eventsource": "^2.0.2",
29
29
  "form-data": "^4.0.0",
30
30
  "jwt-decode": "^3.1.2",
31
31
  "p-queue": "^6.6.2"