otomato-sdk 1.5.0 → 1.5.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.
@@ -8,20 +8,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { apiServices } from '../services/ApiService.js';
11
- let edgeCounter = 0;
12
- const generatedEdgeIds = new Set();
13
11
  export class Edge {
14
12
  constructor(edge) {
15
- if (edge.id) {
16
- this.id = edge.id;
17
- }
18
- else {
19
- this.id = `e-${++edgeCounter}`;
20
- while (generatedEdgeIds.has(this.id)) {
21
- this.id = `e-${++edgeCounter}`;
22
- }
23
- }
24
- generatedEdgeIds.add(this.id);
13
+ var _a;
14
+ this.id = (_a = edge.id) !== null && _a !== void 0 ? _a : null;
25
15
  this.source = edge.source;
26
16
  this.target = edge.target;
27
17
  }
@@ -35,8 +25,9 @@ export class Edge {
35
25
  static fromJSON(json, nodes) {
36
26
  const source = nodes.find(n => n.getRef() === json.source);
37
27
  const target = nodes.find(n => n.getRef() === json.target);
38
- if (!source || !target)
39
- throw new Error("Edge refer to non existing node");
28
+ if (!source || !target) {
29
+ throw new Error("Edge refers to a non-existing node");
30
+ }
40
31
  return new Edge({
41
32
  id: json.id,
42
33
  source,
@@ -50,10 +41,7 @@ export class Edge {
50
41
  throw new Error('Cannot delete an edge without an ID.');
51
42
  }
52
43
  try {
53
- console.log('trying...');
54
- console.log(this.id);
55
44
  const response = yield apiServices.delete(`/edges/${this.id}`);
56
- console.log(response.status);
57
45
  if (response.status === 204) {
58
46
  return { success: true };
59
47
  }
@@ -66,4 +54,24 @@ export class Edge {
66
54
  }
67
55
  });
68
56
  }
57
+ update() {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ var _a;
60
+ if (!this.id) {
61
+ throw new Error('Cannot update an edge without an ID.');
62
+ }
63
+ try {
64
+ const response = yield apiServices.patch(`/edges/${this.id}`, this.toJSON());
65
+ if (response.status === 200) {
66
+ return { success: true };
67
+ }
68
+ else {
69
+ return { success: false, error: ((_a = response.data) === null || _a === void 0 ? void 0 : _a.error) || 'Unknown error' };
70
+ }
71
+ }
72
+ catch (error) {
73
+ return { success: false, error: error.message || 'Unknown error' };
74
+ }
75
+ });
76
+ }
69
77
  }
@@ -1,10 +1,10 @@
1
1
  import { Node } from './Node.js';
2
2
  export declare class Edge {
3
- id: string;
3
+ id: string | null;
4
4
  source: Node;
5
5
  target: Node;
6
6
  constructor(edge: {
7
- id?: string;
7
+ id?: string | null;
8
8
  source: Node;
9
9
  target: Node;
10
10
  });
@@ -18,4 +18,8 @@ export declare class Edge {
18
18
  success: boolean;
19
19
  error?: string;
20
20
  }>;
21
+ update(): Promise<{
22
+ success: boolean;
23
+ error?: string;
24
+ }>;
21
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "otomato-sdk",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "An SDK for building and managing automations on Otomato",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/types/src/index.d.ts",