@infrascan/shared-types 0.4.0 → 0.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @infrascan/shared-types
2
2
 
3
+ ## 0.5.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#84](https://github.com/infrascan/infrascan/pull/84) [`437026c`](https://github.com/infrascan/infrascan/commit/437026cc278ec4b380bcaf3a7a675f3762ce3bea) Thanks [@lfarrel6](https://github.com/lfarrel6)! - Bump aws client sdk versions to remove vulnerable dependency
8
+
9
+ ## 0.5.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#82](https://github.com/infrascan/infrascan/pull/82) [`e28a6d9`](https://github.com/infrascan/infrascan/commit/e28a6d91eb36fa83e9a40a667eb39a15b2a45ccb) Thanks [@lfarrel6](https://github.com/lfarrel6)! - Introduce new readable/writable interface for @infrascan/core graph interface to make types nicer to work with. Previously, the graph returned union types to bridge the Graph's internal model of the state with its exposed API for adding children/parents/edges. This resulted in a lot of properties with signatures like `parent?: Node | string`.
14
+
15
+ This has been updated to wrap the Node and Edge types in `Readable` and `Writable` types based on the context they're being used in. This is inspired by the Kysely `Selectable`/`Insertable` pattern. When a Node is `Readable` its edges, parent and children will resolve to other Node objects. When `Writable`, all other Nodes are expected to be referenced using a string type containing their ID.
16
+
17
+ Introduce @infrascan/node-reducer-plugin which reduces graph complexity for dynamicially provisioned infrastructure.
18
+
3
19
  ## 0.4.0
4
20
 
5
21
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infrascan/shared-types",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "Shared types for multiple infrascan packages",
5
5
  "main": "src/index.ts",
6
6
  "scripts": {
@@ -12,7 +12,7 @@
12
12
  "author": "Liam Farrelly <liam@l3f7.dev> (https://whoisli.am/)",
13
13
  "license": "MPL-2.0",
14
14
  "devDependencies": {
15
- "@aws-sdk/types": "3.428.0",
15
+ "@aws-sdk/types": "3.609.0",
16
16
  "eslint-config-custom": "*",
17
17
  "tsconfig": "*",
18
18
  "typescript": "^5.1.6"
package/src/api.ts CHANGED
@@ -1,4 +1,8 @@
1
- import type { AwsCredentialIdentityProvider, RetryStrategy, RetryStrategyV2 } from "@aws-sdk/types";
1
+ import type {
2
+ AwsCredentialIdentityProvider,
3
+ RetryStrategy,
4
+ RetryStrategyV2,
5
+ } from "@aws-sdk/types";
2
6
 
3
7
  import type { SelectedEdge, SelectedNode } from "./graph";
4
8
  import type { BaseEdgeResolver } from "./config";
@@ -73,7 +77,7 @@ export interface Connector {
73
77
  type ClientBuilder<T, P extends Provider> = (
74
78
  credentials: AwsCredentialIdentityProvider,
75
79
  context: ProviderContextMap[P],
76
- retryStrategy?: RetryStrategy | RetryStrategyV2
80
+ retryStrategy?: RetryStrategy | RetryStrategyV2,
77
81
  ) => T;
78
82
 
79
83
  type GetterFn<T, P extends Provider> = (
package/src/config.ts CHANGED
@@ -47,10 +47,8 @@ export type BaseScannerDefinition = {
47
47
  };
48
48
 
49
49
  type AsCommand<S extends string> = `${S}Command`;
50
- export type AvailableCommand<
51
- Serv extends object,
52
- Funcs extends string,
53
- > = AsCommand<Funcs> extends `${infer P}Command` & keyof Serv ? P : never;
50
+ export type AvailableCommand<Serv extends object, Funcs extends string> =
51
+ AsCommand<Funcs> extends `${infer P}Command` & keyof Serv ? P : never;
54
52
 
55
53
  export type StateSelector<
56
54
  ServiceName extends string,
package/src/graph.ts CHANGED
@@ -7,50 +7,83 @@ export interface SelectedNode {
7
7
  parent?: string;
8
8
  type?: string;
9
9
  rawState?: any;
10
- };
10
+ }
11
11
 
12
12
  export interface SelectedEdgeTarget {
13
- name: string,
14
- target: string
13
+ name: string;
14
+ target: string;
15
15
  }
16
16
 
17
17
  export interface SelectedEdge {
18
18
  source: string;
19
19
  target: string;
20
- metadata?: Record<string, unknown>
20
+ metadata?: Record<string, unknown>;
21
+ }
22
+
23
+ // Create Read/Write types inspired by kysely
24
+ export type ElementType<ReadType, WriteType> = {
25
+ readonly _read: ReadType;
26
+ readonly _write: WriteType;
27
+ };
28
+
29
+ export type ElementRecord<K extends keyof any, R, W> = ElementType<
30
+ Record<K, Readable<R>>,
31
+ Record<K, Writable<W>>
32
+ >;
33
+
34
+ export type ReadType<T> = T extends ElementType<infer R, any> ? Readable<R> : T;
35
+ export type Readable<T> = {
36
+ [K in keyof T]: ReadType<T[K]>;
37
+ };
38
+
39
+ export type WriteType<T> = T extends ElementType<any, infer W>
40
+ ? Writable<W>
41
+ : T;
42
+ export type Writable<T> = {
43
+ [K in keyof T]: WriteType<T[K]>;
21
44
  };
22
45
 
23
46
  export interface Node {
24
- id: string,
25
- name: string,
47
+ id: string;
48
+ name: string;
26
49
  metadata: Record<string, unknown>;
27
- service?: string,
28
- type?: string,
29
- parent?: string | Node,
30
- children?: Record<string, Node>,
31
- incomingEdges: Record<string, Edge<Node>>,
32
- outgoingEdges: Record<string, Edge<Node>>,
50
+ service?: string;
51
+ type?: string;
52
+ parent?: ElementType<Node, string>;
53
+ children?: ElementRecord<string, Node, string>;
54
+ incomingEdges: ElementRecord<string, Edge, string>;
55
+ outgoingEdges: ElementRecord<string, Edge, string>;
33
56
  }
34
57
 
35
- export interface Edge<T extends string | Node> {
36
- id: string,
37
- name?: string,
38
- metadata: Record<string, unknown>,
39
- source: T,
40
- target: T
58
+ export interface Edge {
59
+ id: string;
60
+ name?: string;
61
+ metadata: Record<string, unknown>;
62
+ source: ElementType<Node, string>;
63
+ target: ElementType<Node, string>;
41
64
  }
42
65
 
43
66
  export interface Graph {
44
- nodes: Node[],
45
- edges: Edge<Node>[],
46
- addNode: (node: Pick<Node, "id" | "name" | "metadata" | "parent" | "service" | "type">) => void,
47
- addEdge: (edge: Pick<Edge<string>, "name" | "source" | "target" | "metadata">) => void,
48
- addChild: (parent: string, child: string) => void,
49
- getNode: (id: string) => Node | undefined,
50
- mapNodesById: (id: string, mapperFn: (node: Node) => Node[]) => void,
51
- removeEdge: (id: string) => Edge<Node>,
52
- removeNode: (id: string) => Node,
53
- serialize: () => string
54
- };
67
+ nodes: Readable<Node>[];
68
+ edges: Readable<Edge>[];
69
+ addNode: (
70
+ node: Pick<
71
+ Writable<Node>,
72
+ "id" | "name" | "metadata" | "parent" | "service" | "type"
73
+ >,
74
+ ) => void;
75
+ addEdge: (
76
+ edge: Pick<Writable<Edge>, "name" | "source" | "target" | "metadata">,
77
+ ) => void;
78
+ addChild: (parent: string, child: string) => void;
79
+ getNode: (id: string) => Readable<Node> | undefined;
80
+ mapNodesById: (
81
+ id: string,
82
+ mapperFn: (node: Readable<Node>) => Writable<Node>[],
83
+ ) => void;
84
+ removeEdge: (id: string) => Readable<Edge>;
85
+ removeNode: (id: string) => Readable<Node>;
86
+ serialize: () => string;
87
+ }
55
88
 
56
- export type GraphSerializer<T> = (graph: Graph) => T;
89
+ export type GraphSerializer<T> = (graph: Graph) => T;
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from "./api";
2
2
  export * from "./config";
3
3
  export * from "./graph";
4
- export * from "./scan";
5
- export * from "./plugins";
4
+ export * from "./plugins";
5
+ export * from "./scan";
package/src/plugins.ts CHANGED
@@ -2,25 +2,39 @@ import { Graph } from "./graph";
2
2
  import { AwsContext } from "./api";
3
3
 
4
4
  // All supported events to trigger a plugin
5
- export type GraphPluginEvents = "onServiceComplete" | "onRegionComplete" | "onAccountComplete" | "onGraphComplete";
5
+ export type GraphPluginEvents =
6
+ | "onServiceComplete"
7
+ | "onRegionComplete"
8
+ | "onAccountComplete"
9
+ | "onGraphComplete";
6
10
 
7
11
  /**
8
12
  * A plugin which is called everytime a service's nodes have been added to the graph.
9
13
  * Receives the current graph state, the service ID, and the current AWS Context.
10
14
  */
11
- export type OnServiceCompletePlugin = (graph: Graph, service: string, context: AwsContext) => void | Promise<void>;
15
+ export type OnServiceCompletePlugin = (
16
+ graph: Graph,
17
+ service: string,
18
+ context: AwsContext,
19
+ ) => void | Promise<void>;
12
20
 
13
21
  /**
14
22
  * A plugin which is called everytime a region's nodes have been added to the graph.
15
23
  * Receives the current graph state, and the current AWS Context.
16
24
  */
17
- export type OnRegionCompletePlugin = (graph: Graph, context: AwsContext) => void | Promise<void>;
25
+ export type OnRegionCompletePlugin = (
26
+ graph: Graph,
27
+ context: AwsContext,
28
+ ) => void | Promise<void>;
18
29
 
19
30
  /**
20
31
  * A plugin which is called everytime an account's nodes have been added to the graph.
21
32
  * Receives the current graph state, and the current AWS Context.
22
33
  */
23
- export type OnAccountCompletePlugin = (graph: Graph, context: AwsContext) => void | Promise<void>;
34
+ export type OnAccountCompletePlugin = (
35
+ graph: Graph,
36
+ context: AwsContext,
37
+ ) => void | Promise<void>;
24
38
 
25
39
  /**
26
40
  * A plugin which is called when the entire graph has been generated.
@@ -29,14 +43,14 @@ export type OnAccountCompletePlugin = (graph: Graph, context: AwsContext) => voi
29
43
  export type OnGraphCompletePlugin = (graph: Graph) => void | Promise<void>;
30
44
 
31
45
  export type PluginEventHandlerTypes = {
32
- "onServiceComplete": OnServiceCompletePlugin,
33
- "onRegionComplete": OnRegionCompletePlugin,
34
- "onAccountComplete": OnAccountCompletePlugin,
35
- "onGraphComplete": OnGraphCompletePlugin,
46
+ onServiceComplete: OnServiceCompletePlugin;
47
+ onRegionComplete: OnRegionCompletePlugin;
48
+ onAccountComplete: OnAccountCompletePlugin;
49
+ onGraphComplete: OnGraphCompletePlugin;
36
50
  };
37
51
 
38
52
  export interface GraphPlugin<E extends GraphPluginEvents> {
39
- id: string,
40
- event: E,
41
- handler: PluginEventHandlerTypes[E]
42
- }
53
+ id: string;
54
+ event: E;
55
+ handler: PluginEventHandlerTypes[E];
56
+ }
package/tsconfig.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "extends": "tsconfig/base.json",
2
+ "extends": "@infrascan/tsconfig/base.json",
3
3
  "compilerOptions": {
4
4
  "baseUrl": "src",
5
5
  "noEmit": true,