@infrascan/shared-types 0.2.4 → 0.3.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @infrascan/shared-types
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#75](https://github.com/infrascan/infrascan/pull/75) [`4634235`](https://github.com/infrascan/infrascan/commit/4634235d61bd6bd817c6fb9e62add778218b69b6) Thanks [@lfarrel6](https://github.com/lfarrel6)! - Add graph model interface to shared types package
8
+
3
9
  ## 0.2.4
4
10
 
5
11
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infrascan/shared-types",
3
- "version": "0.2.4",
3
+ "version": "0.3.0",
4
4
  "description": "Shared types for multiple infrascan packages",
5
5
  "main": "src/index.ts",
6
6
  "scripts": {
package/src/graph.ts CHANGED
@@ -68,3 +68,38 @@ export type EdgeTarget = {
68
68
  name: string;
69
69
  target: string;
70
70
  };
71
+
72
+ export interface Node {
73
+ id: string,
74
+ name: string,
75
+ metadata: Record<string, unknown>;
76
+ service?: string,
77
+ type?: string,
78
+ parent?: string | Node,
79
+ children?: Record<string, Node>,
80
+ incomingEdges: Record<string, Edge<Node>>,
81
+ outgoingEdges: Record<string, Edge<Node>>,
82
+ }
83
+
84
+ export interface Edge<T extends string | Node> {
85
+ id: string,
86
+ name?: string,
87
+ metadata: Record<string, unknown>,
88
+ source: T,
89
+ target: T
90
+ }
91
+
92
+ export interface Graph {
93
+ nodes: Node[],
94
+ edges: Edge<Node>[],
95
+ addNode: (node: Pick<Node, "id" | "name" | "metadata" | "parent" | "service" | "type">) => void,
96
+ addEdge: (edge: Pick<Edge<string>, "name" | "source" | "target" | "metadata">) => void,
97
+ addChild: (parent: string, child: string) => void,
98
+ getNode: (id: string) => Node | undefined,
99
+ mapNodesById: (id: string, mapperFn: (node: Node) => Node[]) => void,
100
+ removeEdge: (id: string) => Edge<Node>,
101
+ removeNode: (id: string) => Node,
102
+ serialize: () => string
103
+ };
104
+
105
+ export type GraphSerializer<T> = (graph: Graph) => T;