archidocs 1.0.0 → 1.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/LICENSE +21 -0
- package/README.md +231 -0
- package/dist/cli/commands.d.ts +543 -0
- package/dist/cli/commands.js +299 -0
- package/dist/cli/format.d.ts +2 -2
- package/dist/cli/format.js +9 -5
- package/dist/cli/init.d.ts +1 -1
- package/dist/cli/init.js +2 -2
- package/dist/cli/main.js +27 -73
- package/dist/core/compare.d.ts +2 -13
- package/dist/core/compare.js +2 -35
- package/dist/core/index.d.ts +3 -6
- package/dist/core/index.js +3 -6
- package/dist/core/query.d.ts +1 -1
- package/dist/core/rules.d.ts +30 -0
- package/dist/core/rules.js +194 -7
- package/dist/core/views/compare.d.ts +12 -0
- package/dist/core/views/compare.js +37 -0
- package/dist/core/{deployment-views.d.ts → views/deployment.d.ts} +4 -5
- package/dist/core/{deployment-views.js → views/deployment.js} +5 -7
- package/dist/core/{dynamic-views.d.ts → views/dynamic.d.ts} +1 -3
- package/dist/core/{dynamic-views.js → views/dynamic.js} +4 -8
- package/dist/core/views/generated.d.ts +18 -0
- package/dist/core/views/generated.js +92 -0
- package/dist/core/views/ids.d.ts +36 -0
- package/dist/core/views/ids.js +51 -0
- package/dist/core/views/index.d.ts +13 -0
- package/dist/core/views/index.js +12 -0
- package/dist/core/views/lens.d.ts +27 -0
- package/dist/core/views/lens.js +112 -0
- package/dist/core/views/model.d.ts +21 -0
- package/dist/core/views/model.js +69 -0
- package/dist/core/views/resolve.d.ts +42 -0
- package/dist/core/views/resolve.js +81 -0
- package/dist/core/{save-as-view.d.ts → views/save-as-view.d.ts} +2 -2
- package/dist/core/{save-as-view.js → views/save-as-view.js} +13 -10
- package/dist/core/{saved-views.d.ts → views/saved.d.ts} +4 -18
- package/dist/core/{saved-views.js → views/saved.js} +8 -103
- package/dist/core/views/types.d.ts +91 -0
- package/dist/core/views/types.js +2 -0
- package/dist/mcp/errors.d.ts +37 -0
- package/dist/mcp/errors.js +35 -0
- package/dist/mcp/index.d.ts +2 -1
- package/dist/mcp/index.js +1 -0
- package/dist/mcp/server.d.ts +1 -2
- package/dist/mcp/server.js +15 -13
- package/dist/mcp/writes.js +2 -1
- package/dist/render/font.d.ts +14 -8
- package/dist/render/font.js +11 -10
- package/dist/render/index.d.ts +1 -0
- package/dist/render/index.js +1 -0
- package/dist/render/layout.d.ts +20 -3
- package/dist/render/layout.js +49 -12
- package/dist/render/png.d.ts +1 -1
- package/dist/render/png.js +5 -5
- package/dist/render/sequence-svg.d.ts +8 -3
- package/dist/render/sequence-svg.js +32 -32
- package/dist/render/sequence.d.ts +1 -1
- package/dist/render/sequence.js +1 -1
- package/dist/render/svg.d.ts +19 -6
- package/dist/render/svg.js +148 -85
- package/dist/render/text.d.ts +6 -4
- package/dist/render/text.js +11 -9
- package/dist/render/tokens.d.ts +53 -0
- package/dist/render/tokens.js +71 -0
- package/dist/schema/adr.js +18 -13
- package/dist/schema/workspace.js +226 -130
- package/dist/viewer/assets/index-BXa5R96a.js +138 -0
- package/dist/viewer/assets/index-YFA-pYjQ.css +1 -0
- package/dist/viewer/assets/{layout.worker-Bg-OaLVN.js → layout.worker-BRHAGJrD.js} +1 -1
- package/dist/viewer/assets/{png-D1zzLB1s.js → png-CAaXWR-k.js} +1 -1
- package/dist/viewer/assets/svg-BPVHfD36.js +2 -0
- package/dist/viewer/index.html +2 -2
- package/guide/SKILL.md +1 -1
- package/guide/topics/bootstrap.md +1 -1
- package/guide/topics/relationships.md +1 -1
- package/package.json +20 -4
- package/schemas/adr.schema.json +18 -15
- package/schemas/model.schema.json +637 -1144
- package/schemas/project.schema.json +8 -4
- package/schemas/workspace.schema.json +39 -20
- package/dist/core/views.d.ts +0 -126
- package/dist/core/views.js +0 -217
- package/dist/viewer/assets/index-BwUCSYuf.js +0 -113
- package/dist/viewer/assets/index-DvKgCpBr.css +0 -1
- package/dist/viewer/assets/svg-Cw4FMsm3.js +0 -2
|
@@ -5,14 +5,17 @@
|
|
|
5
5
|
"properties": {
|
|
6
6
|
"id": {
|
|
7
7
|
"type": "string",
|
|
8
|
-
"pattern": "^[a-z0-9][a-z0-9-]*$"
|
|
8
|
+
"pattern": "^[a-z0-9][a-z0-9-]*$",
|
|
9
|
+
"description": "The Project's id, unique in the Workspace. Other Projects write it as the prefix of a Qualified id, such as `payments:ledger`."
|
|
9
10
|
},
|
|
10
11
|
"name": {
|
|
11
|
-
"type": "string"
|
|
12
|
+
"type": "string",
|
|
13
|
+
"description": "The Project's display name."
|
|
12
14
|
},
|
|
13
15
|
"owner": {
|
|
14
16
|
"type": "string",
|
|
15
|
-
"pattern": "^[a-z0-9][a-z0-9-]*$"
|
|
17
|
+
"pattern": "^[a-z0-9][a-z0-9-]*$",
|
|
18
|
+
"description": "The Team that owns the Project: the id of a Team in `workspace.yaml`. It is the Owner of every Element and Deployment Target in the Project that sets no `owner` of its own."
|
|
16
19
|
}
|
|
17
20
|
},
|
|
18
21
|
"required": [
|
|
@@ -20,5 +23,6 @@
|
|
|
20
23
|
"name",
|
|
21
24
|
"owner"
|
|
22
25
|
],
|
|
23
|
-
"additionalProperties": false
|
|
26
|
+
"additionalProperties": false,
|
|
27
|
+
"description": "`project.yaml`: marks its folder as a Project."
|
|
24
28
|
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
"type": "object",
|
|
5
5
|
"properties": {
|
|
6
6
|
"teams": {
|
|
7
|
+
"description": "The Teams of the Workspace, keyed by id. Every `owner` in every Project names one of these ids.",
|
|
7
8
|
"type": "object",
|
|
8
9
|
"propertyNames": {
|
|
9
10
|
"type": "string",
|
|
@@ -13,39 +14,30 @@
|
|
|
13
14
|
"type": "object",
|
|
14
15
|
"properties": {
|
|
15
16
|
"name": {
|
|
16
|
-
"type": "string"
|
|
17
|
+
"type": "string",
|
|
18
|
+
"description": "The Team's display name."
|
|
17
19
|
},
|
|
18
20
|
"description": {
|
|
21
|
+
"description": "A short description of the Team.",
|
|
19
22
|
"type": "string"
|
|
20
23
|
},
|
|
21
24
|
"links": {
|
|
25
|
+
"description": "Links to pages about the Team.",
|
|
22
26
|
"type": "array",
|
|
23
27
|
"items": {
|
|
24
|
-
"
|
|
25
|
-
"properties": {
|
|
26
|
-
"label": {
|
|
27
|
-
"type": "string"
|
|
28
|
-
},
|
|
29
|
-
"url": {
|
|
30
|
-
"type": "string",
|
|
31
|
-
"format": "uri"
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
"required": [
|
|
35
|
-
"label",
|
|
36
|
-
"url"
|
|
37
|
-
],
|
|
38
|
-
"additionalProperties": false
|
|
28
|
+
"$ref": "#/$defs/Link"
|
|
39
29
|
}
|
|
40
30
|
}
|
|
41
31
|
},
|
|
42
32
|
"required": [
|
|
43
33
|
"name"
|
|
44
34
|
],
|
|
45
|
-
"additionalProperties": false
|
|
35
|
+
"additionalProperties": false,
|
|
36
|
+
"description": "A Team: a group that can own Elements and Deployment Targets. Its key is the Team's id."
|
|
46
37
|
}
|
|
47
38
|
},
|
|
48
39
|
"environments": {
|
|
40
|
+
"description": "The Environments of the Workspace, keyed by id. Every Deployment in every Project names one of these ids.",
|
|
49
41
|
"type": "object",
|
|
50
42
|
"propertyNames": {
|
|
51
43
|
"type": "string",
|
|
@@ -55,18 +47,45 @@
|
|
|
55
47
|
"type": "object",
|
|
56
48
|
"properties": {
|
|
57
49
|
"name": {
|
|
58
|
-
"type": "string"
|
|
50
|
+
"type": "string",
|
|
51
|
+
"description": "The Environment's display name, such as `Production`."
|
|
59
52
|
},
|
|
60
53
|
"description": {
|
|
54
|
+
"description": "A short description of the Environment.",
|
|
61
55
|
"type": "string"
|
|
62
56
|
}
|
|
63
57
|
},
|
|
64
58
|
"required": [
|
|
65
59
|
"name"
|
|
66
60
|
],
|
|
67
|
-
"additionalProperties": false
|
|
61
|
+
"additionalProperties": false,
|
|
62
|
+
"description": "An Environment: a named stage that Services run in, such as prod or staging. Its key is the Environment's id."
|
|
68
63
|
}
|
|
69
64
|
}
|
|
70
65
|
},
|
|
71
|
-
"additionalProperties": false
|
|
66
|
+
"additionalProperties": false,
|
|
67
|
+
"description": "`workspace.yaml`: the Teams and Environments that every Project in the Workspace shares.",
|
|
68
|
+
"$defs": {
|
|
69
|
+
"Link": {
|
|
70
|
+
"type": "object",
|
|
71
|
+
"properties": {
|
|
72
|
+
"label": {
|
|
73
|
+
"type": "string",
|
|
74
|
+
"description": "The text of the link, such as `Runbook`."
|
|
75
|
+
},
|
|
76
|
+
"url": {
|
|
77
|
+
"type": "string",
|
|
78
|
+
"format": "uri",
|
|
79
|
+
"description": "The page the link opens. A full URL, such as `https://wiki.example.com/runbooks/web`."
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"required": [
|
|
83
|
+
"label",
|
|
84
|
+
"url"
|
|
85
|
+
],
|
|
86
|
+
"additionalProperties": false,
|
|
87
|
+
"title": "Link",
|
|
88
|
+
"description": "A link to a page about the thing it is declared on, such as a runbook or a dashboard."
|
|
89
|
+
}
|
|
90
|
+
}
|
|
72
91
|
}
|
package/dist/core/views.d.ts
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import type { CompareMark } from "./compare.ts";
|
|
2
|
-
import type { Bundle, BundleElement, BundleLens, BundleRelationship } from "../schema/bundle.ts";
|
|
3
|
-
/** The most nodes a View may have before `oversized-view` warns. */
|
|
4
|
-
export declare const MAX_VIEW_NODES = 150;
|
|
5
|
-
/** The kinds of Generated structural View, and the Deployment View. */
|
|
6
|
-
export type ViewKind = "c1" | "c2" | "c3" | "deployment";
|
|
7
|
-
/**
|
|
8
|
-
* One node of a resolved View: an Element, drawn as a box or as a container.
|
|
9
|
-
* A Deployment View also has Deployment Targets (`target`), Deployments
|
|
10
|
-
* (`deployment`, id `<service>@<target>`) and the System boxes inside each
|
|
11
|
-
* Target (`system`, id `<system>@<target>`).
|
|
12
|
-
*/
|
|
13
|
-
export interface ViewNode {
|
|
14
|
-
id: string;
|
|
15
|
-
kind: BundleElement["kind"] | "target" | "deployment";
|
|
16
|
-
name: string;
|
|
17
|
-
/** The Element a Deployment or a Target's System box draws, when the node's id is not that Element's. */
|
|
18
|
-
element?: string;
|
|
19
|
-
/** The nearest ancestor that is itself a node of this View, else null. */
|
|
20
|
-
parent: string | null;
|
|
21
|
-
/** True when the Element has children in the Model that this View hides inside it. */
|
|
22
|
-
collapsed: boolean;
|
|
23
|
-
/** True for an External System or Service. */
|
|
24
|
-
external: boolean;
|
|
25
|
-
/** Set on every node of a View with a Lens: whether the Lens hits it, and for an impact Lens its nearest distance. */
|
|
26
|
-
mark?: NodeMark;
|
|
27
|
-
/** Set on every node of a View drawn for Compare (`compareView`). */
|
|
28
|
-
change?: CompareMark;
|
|
29
|
-
}
|
|
30
|
-
/** How a Lens marks a node; a collapsed box is hit when anything inside it is. */
|
|
31
|
-
export interface NodeMark {
|
|
32
|
-
hit: boolean;
|
|
33
|
-
distance?: number;
|
|
34
|
-
/** For an impact Lens: the origin itself, or the side of it the node sits on, at its nearest distance. */
|
|
35
|
-
side?: ImpactSide;
|
|
36
|
-
}
|
|
37
|
-
export type ImpactSide = "origin" | "upstream" | "downstream";
|
|
38
|
-
/** A Saved View's drawing direction. */
|
|
39
|
-
export type ViewDirection = "TB" | "BT" | "LR" | "RL";
|
|
40
|
-
/** An edge between two nodes, with the declared Relationships beneath it. */
|
|
41
|
-
export interface ViewEdge {
|
|
42
|
-
from: string;
|
|
43
|
-
to: string;
|
|
44
|
-
relationships: BundleRelationship[];
|
|
45
|
-
/** Set on every edge of a View with a Lens: whether the Lens lights it. */
|
|
46
|
-
lit?: boolean;
|
|
47
|
-
/** Set on every edge of a View drawn for Compare (`compareView`). */
|
|
48
|
-
change?: CompareMark;
|
|
49
|
-
}
|
|
50
|
-
/** A View resolved to nodes and edges, sorted by id and by `from`, then `to`. */
|
|
51
|
-
export interface ResolvedView {
|
|
52
|
-
id: string;
|
|
53
|
-
kind: ViewKind;
|
|
54
|
-
title: string;
|
|
55
|
-
/** A Saved View's own direction, if it sets one. */
|
|
56
|
-
direction?: ViewDirection;
|
|
57
|
-
/** A Saved View's Lens, if it carries one. */
|
|
58
|
-
lens?: BundleLens;
|
|
59
|
-
nodes: ViewNode[];
|
|
60
|
-
edges: ViewEdge[];
|
|
61
|
-
}
|
|
62
|
-
export interface ResolveOptions {
|
|
63
|
-
/**
|
|
64
|
-
* Systems and Services to open, showing their children; viewer state, not a
|
|
65
|
-
* different View. A box opens only while it is itself shown, so a Service
|
|
66
|
-
* stays shut inside a closed System. C1 opens nothing.
|
|
67
|
-
*/
|
|
68
|
-
expand?: readonly string[];
|
|
69
|
-
/**
|
|
70
|
-
* A Lens over the View, as the viewer holds it: marks nodes and lights
|
|
71
|
-
* edges without changing which nodes the View holds. It replaces a Saved
|
|
72
|
-
* View's own Lens; null clears a Saved View's own Lens.
|
|
73
|
-
*/
|
|
74
|
-
lens?: BundleLens | null;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Resolves a View by id: a Generated View (`c1`, `c2`, `c2/<system>`,
|
|
78
|
-
* `c3/<service>`, only for a Service with Components, or `deployment/<env>`)
|
|
79
|
-
* or a Saved structural or Deployment View (`project:view-id`). Returns
|
|
80
|
-
* undefined for an unknown id.
|
|
81
|
-
*/
|
|
82
|
-
export declare function resolveView(bundle: Bundle, id: string, options?: ResolveOptions): ResolvedView | undefined;
|
|
83
|
-
/**
|
|
84
|
-
* The picked nodes of a View, laid out again on their own: each pick with the
|
|
85
|
-
* containers it sits in, and the edges among them, Lens marks kept.
|
|
86
|
-
*/
|
|
87
|
-
export declare function pickedView(view: ResolvedView, picks: readonly string[]): ResolvedView;
|
|
88
|
-
/** The kinds a View is listed under: a Saved structural View's is its `level`. */
|
|
89
|
-
export type ListedKind = ViewKind | "dynamic";
|
|
90
|
-
/** A View as listed, without its nodes and edges. */
|
|
91
|
-
export interface ViewSummary {
|
|
92
|
-
id: string;
|
|
93
|
-
kind: ListedKind;
|
|
94
|
-
title: string;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Every Generated View, in the order `c1`, `c2`, then `c2/<system>` and
|
|
98
|
-
* `c3/<service>` by id, then `deployment/<env>` by Environment id, then every
|
|
99
|
-
* Saved View by id. `kind` keeps one kind; `element` keeps the Views that
|
|
100
|
-
* show that Element as a node or a Deployment, and the
|
|
101
|
-
* Dynamic Views it takes part in (including as the broker of an event Step).
|
|
102
|
-
*/
|
|
103
|
-
export declare function listViews(bundle: Bundle, filter?: {
|
|
104
|
-
kind?: ListedKind;
|
|
105
|
-
element?: string;
|
|
106
|
-
}): ViewSummary[];
|
|
107
|
-
/** Every Generated View, resolved, in `listViews` order. */
|
|
108
|
-
export declare function generatedViews(bundle: Bundle): ResolvedView[];
|
|
109
|
-
/**
|
|
110
|
-
* Builds a View from the set of Elements it shows: each Relationship's ends
|
|
111
|
-
* are lifted to their nearest shown ancestor-or-self, and the Relationships
|
|
112
|
-
* landing on one pair form one edge. An edge is kept when `keep` accepts the
|
|
113
|
-
* declared Relationship and its ends are two different nodes.
|
|
114
|
-
*/
|
|
115
|
-
export declare function build(model: ModelIndex, head: Pick<ResolvedView, "id" | "kind" | "title">, shown: Set<string>, keep: (r: BundleRelationship) => boolean): ResolvedView;
|
|
116
|
-
/** Lookups over a Bundle's Elements. */
|
|
117
|
-
export declare class ModelIndex {
|
|
118
|
-
readonly elements: BundleElement[];
|
|
119
|
-
readonly relationships: BundleRelationship[];
|
|
120
|
-
readonly byId: Map<string, BundleElement>;
|
|
121
|
-
private readonly childrenOf;
|
|
122
|
-
constructor(bundle: Bundle);
|
|
123
|
-
children(id: string): BundleElement[];
|
|
124
|
-
/** The Element itself, then its parent, and so on up to the top level. Unknown ids yield only themselves. */
|
|
125
|
-
ancestry(id: string): string[];
|
|
126
|
-
}
|
package/dist/core/views.js
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import { resolveDeployment } from "./deployment-views.js";
|
|
2
|
-
import { resolveDynamic, takesPart } from "./dynamic-views.js";
|
|
3
|
-
import { applyLens, resolveSaved } from "./saved-views.js";
|
|
4
|
-
/** The most nodes a View may have before `oversized-view` warns. */
|
|
5
|
-
export const MAX_VIEW_NODES = 150;
|
|
6
|
-
/**
|
|
7
|
-
* Resolves a View by id: a Generated View (`c1`, `c2`, `c2/<system>`,
|
|
8
|
-
* `c3/<service>`, only for a Service with Components, or `deployment/<env>`)
|
|
9
|
-
* or a Saved structural or Deployment View (`project:view-id`). Returns
|
|
10
|
-
* undefined for an unknown id.
|
|
11
|
-
*/
|
|
12
|
-
export function resolveView(bundle, id, options = {}) {
|
|
13
|
-
const view = resolveUnlensed(bundle, id, options);
|
|
14
|
-
if (view && options.lens)
|
|
15
|
-
applyLens(bundle, new ModelIndex(bundle), view, options.lens);
|
|
16
|
-
return view;
|
|
17
|
-
}
|
|
18
|
-
function resolveUnlensed(bundle, id, options) {
|
|
19
|
-
const saved = bundle.views.find((v) => v.id === id);
|
|
20
|
-
if (saved)
|
|
21
|
-
return saved.kind === "structural" ? resolveSaved(bundle, options.lens === undefined ? saved : { ...saved, lens: null }).view : undefined;
|
|
22
|
-
const model = new ModelIndex(bundle);
|
|
23
|
-
if (id === "c1")
|
|
24
|
-
return landscape(model, "c1", "C1 Landscape", []);
|
|
25
|
-
if (id === "c2")
|
|
26
|
-
return landscape(model, "c2", "C2 Landscape", options.expand ?? []);
|
|
27
|
-
const slash = id.indexOf("/");
|
|
28
|
-
if (slash < 0)
|
|
29
|
-
return undefined;
|
|
30
|
-
const scope = id.slice(0, slash);
|
|
31
|
-
if (scope === "deployment") {
|
|
32
|
-
const env = bundle.environments.find((e) => e.id === id.slice(slash + 1));
|
|
33
|
-
return env ? resolveDeployment(bundle, { id, title: `${env.name} (Deployment)` }, env.id) : undefined;
|
|
34
|
-
}
|
|
35
|
-
const focus = model.byId.get(id.slice(slash + 1));
|
|
36
|
-
if (!focus)
|
|
37
|
-
return undefined;
|
|
38
|
-
const expand = options.expand ?? [];
|
|
39
|
-
if (scope === "c2" && focus.kind === "system")
|
|
40
|
-
return focused(model, { id, kind: "c2", title: `${focus.name} (C2)` }, focus, expand);
|
|
41
|
-
if (scope === "c3" && focus.kind === "service" && model.children(focus.id).length > 0)
|
|
42
|
-
return focused(model, { id, kind: "c3", title: `${focus.name} (C3)` }, focus, expand);
|
|
43
|
-
return undefined;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* The picked nodes of a View, laid out again on their own: each pick with the
|
|
47
|
-
* containers it sits in, and the edges among them, Lens marks kept.
|
|
48
|
-
*/
|
|
49
|
-
export function pickedView(view, picks) {
|
|
50
|
-
const parentOf = new Map(view.nodes.map((n) => [n.id, n.parent]));
|
|
51
|
-
const kept = new Set();
|
|
52
|
-
for (const pick of picks)
|
|
53
|
-
for (let at = parentOf.has(pick) ? pick : undefined; at; at = parentOf.get(at))
|
|
54
|
-
kept.add(at);
|
|
55
|
-
return { ...view, nodes: view.nodes.filter((n) => kept.has(n.id)), edges: view.edges.filter((e) => kept.has(e.from) && kept.has(e.to)) };
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Every Generated View, in the order `c1`, `c2`, then `c2/<system>` and
|
|
59
|
-
* `c3/<service>` by id, then `deployment/<env>` by Environment id, then every
|
|
60
|
-
* Saved View by id. `kind` keeps one kind; `element` keeps the Views that
|
|
61
|
-
* show that Element as a node or a Deployment, and the
|
|
62
|
-
* Dynamic Views it takes part in (including as the broker of an event Step).
|
|
63
|
-
*/
|
|
64
|
-
export function listViews(bundle, filter = {}) {
|
|
65
|
-
const ids = generatedViewIds(bundle).filter((id) => filter.kind === undefined || id.split("/")[0] === filter.kind);
|
|
66
|
-
const generated = filter.element === undefined ? ids.map((id) => summarise(id, bundle)) : resolveAll(bundle, ids).filter((v) => shows(v, filter.element));
|
|
67
|
-
const element = filter.element;
|
|
68
|
-
const saved = bundle.views
|
|
69
|
-
.map((v) => ({ v, kind: v.kind === "dynamic" ? "dynamic" : v.level }))
|
|
70
|
-
.filter(({ kind }) => filter.kind === undefined || kind === filter.kind)
|
|
71
|
-
.filter(({ v }) => {
|
|
72
|
-
if (element === undefined)
|
|
73
|
-
return true;
|
|
74
|
-
if (v.kind === "dynamic")
|
|
75
|
-
return takesPart(resolveDynamic(bundle, v).view, element);
|
|
76
|
-
return shows(resolveSaved(bundle, v).view, element);
|
|
77
|
-
})
|
|
78
|
-
.map(({ v, kind }) => ({ id: v.id, kind, title: v.title }));
|
|
79
|
-
return [...generated, ...saved].map(({ id, kind, title }) => ({ id, kind, title }));
|
|
80
|
-
}
|
|
81
|
-
/** Whether a View draws an Element, as a node of its own or as a Deployment of it. */
|
|
82
|
-
const shows = (view, element) => view.nodes.some((n) => n.id === element || (n.kind === "deployment" && n.element === element));
|
|
83
|
-
/** Every Generated View, resolved, in `listViews` order. */
|
|
84
|
-
export function generatedViews(bundle) {
|
|
85
|
-
return resolveAll(bundle, generatedViewIds(bundle));
|
|
86
|
-
}
|
|
87
|
-
/** Resolves each id, skipping any that don't resolve (as when a Workspace with errors declares one id twice). */
|
|
88
|
-
const resolveAll = (bundle, ids) => ids.map((id) => resolveView(bundle, id)).filter((v) => v !== undefined);
|
|
89
|
-
function generatedViewIds(bundle) {
|
|
90
|
-
const parents = new Set(bundle.elements.map((e) => e.parent));
|
|
91
|
-
const ids = (prefix, keep) => [...new Set(bundle.elements.filter(keep).map((e) => `${prefix}/${e.id}`))].sort();
|
|
92
|
-
const deployment = bundle.environments.map((e) => `deployment/${e.id}`).sort();
|
|
93
|
-
return ["c1", "c2", ...ids("c2", (e) => e.kind === "system"), ...ids("c3", (e) => e.kind === "service" && parents.has(e.id)), ...deployment];
|
|
94
|
-
}
|
|
95
|
-
/** A Generated View's id, kind and title without resolving it; `id` must be one `generatedViewIds` gave. */
|
|
96
|
-
function summarise(id, bundle) {
|
|
97
|
-
if (id === "c1")
|
|
98
|
-
return { id, kind: "c1", title: "C1 Landscape" };
|
|
99
|
-
if (id === "c2")
|
|
100
|
-
return { id, kind: "c2", title: "C2 Landscape" };
|
|
101
|
-
if (id.startsWith("deployment/"))
|
|
102
|
-
return { id, kind: "deployment", title: `${bundle.environments.find((e) => `deployment/${e.id}` === id).name} (Deployment)` };
|
|
103
|
-
const [kind, elementId] = [id.slice(0, 2), id.slice(3)];
|
|
104
|
-
return { id, kind, title: `${bundle.elements.find((e) => e.id === elementId).name} (${kind.toUpperCase()})` };
|
|
105
|
-
}
|
|
106
|
-
/** Every top-level Element, each standing for everything beneath it, with the `expand`ed boxes open. */
|
|
107
|
-
function landscape(model, kind, title, expand) {
|
|
108
|
-
const shown = new Set(model.elements.filter((e) => e.parent === null).map((e) => e.id));
|
|
109
|
-
open(model, shown, expand);
|
|
110
|
-
return build(model, { id: kind, kind, title }, shown, () => true);
|
|
111
|
-
}
|
|
112
|
-
/** Adds the children of each `expand`ed System or Service that is shown, repeating so a Service opens once its System has. */
|
|
113
|
-
function open(model, shown, expand) {
|
|
114
|
-
const pending = new Set(expand.filter((id) => ["system", "service"].includes(model.byId.get(id)?.kind ?? "")));
|
|
115
|
-
for (let grew = true; grew;) {
|
|
116
|
-
grew = false;
|
|
117
|
-
for (const id of pending) {
|
|
118
|
-
if (!shown.has(id))
|
|
119
|
-
continue;
|
|
120
|
-
for (const child of model.children(id))
|
|
121
|
-
shown.add(child.id);
|
|
122
|
-
pending.delete(id);
|
|
123
|
-
grew = true;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* One Element opened as a container around its children, plus its direct
|
|
129
|
-
* neighbours: every Element outside it with a Relationship to anything
|
|
130
|
-
* inside it, collapsed to its highest ancestor that does not contain the
|
|
131
|
-
* focus. Only Relationships touching the focus become edges.
|
|
132
|
-
*/
|
|
133
|
-
function focused(model, head, focus, expand) {
|
|
134
|
-
const inside = (id) => model.ancestry(id).includes(focus.id);
|
|
135
|
-
const touches = (r) => inside(r.from) || inside(r.to);
|
|
136
|
-
const shown = new Set([focus.id, ...model.children(focus.id).map((c) => c.id)]);
|
|
137
|
-
for (const r of model.relationships) {
|
|
138
|
-
if (!touches(r))
|
|
139
|
-
continue;
|
|
140
|
-
for (const end of [r.from, r.to]) {
|
|
141
|
-
if (inside(end) || !model.byId.has(end))
|
|
142
|
-
continue;
|
|
143
|
-
const separating = model.ancestry(end).filter((a) => !model.ancestry(focus.id).includes(a));
|
|
144
|
-
shown.add(separating.at(-1));
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
open(model, shown, expand);
|
|
148
|
-
return build(model, head, shown, touches);
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Builds a View from the set of Elements it shows: each Relationship's ends
|
|
152
|
-
* are lifted to their nearest shown ancestor-or-self, and the Relationships
|
|
153
|
-
* landing on one pair form one edge. An edge is kept when `keep` accepts the
|
|
154
|
-
* declared Relationship and its ends are two different nodes.
|
|
155
|
-
*/
|
|
156
|
-
export function build(model, head, shown, keep) {
|
|
157
|
-
const lift = (id) => model.ancestry(id).find((a) => shown.has(a));
|
|
158
|
-
const edges = new Map();
|
|
159
|
-
for (const r of model.relationships) {
|
|
160
|
-
if (!keep(r))
|
|
161
|
-
continue;
|
|
162
|
-
const from = lift(r.from);
|
|
163
|
-
const to = lift(r.to);
|
|
164
|
-
if (from === undefined || to === undefined || from === to)
|
|
165
|
-
continue;
|
|
166
|
-
const key = `${from}\0${to}`;
|
|
167
|
-
const edge = edges.get(key) ?? { from, to, relationships: [] };
|
|
168
|
-
edge.relationships.push(r);
|
|
169
|
-
edges.set(key, edge);
|
|
170
|
-
}
|
|
171
|
-
const nodes = [...shown]
|
|
172
|
-
.map((id) => model.byId.get(id))
|
|
173
|
-
.filter((e) => e !== undefined)
|
|
174
|
-
.map((e) => ({
|
|
175
|
-
id: e.id,
|
|
176
|
-
kind: e.kind,
|
|
177
|
-
name: e.name,
|
|
178
|
-
parent: model.ancestry(e.id).slice(1).find((a) => shown.has(a)) ?? null,
|
|
179
|
-
collapsed: model.children(e.id).some((c) => !shown.has(c.id)),
|
|
180
|
-
external: "external" in e && e.external,
|
|
181
|
-
}))
|
|
182
|
-
.sort((a, b) => cmp(a.id, b.id));
|
|
183
|
-
return { ...head, nodes, edges: [...edges.values()].sort((a, b) => cmp(a.from, b.from) || cmp(a.to, b.to)) };
|
|
184
|
-
}
|
|
185
|
-
/** Lookups over a Bundle's Elements. */
|
|
186
|
-
export class ModelIndex {
|
|
187
|
-
elements;
|
|
188
|
-
relationships;
|
|
189
|
-
byId;
|
|
190
|
-
childrenOf = new Map();
|
|
191
|
-
constructor(bundle) {
|
|
192
|
-
this.elements = bundle.elements;
|
|
193
|
-
this.relationships = bundle.relationships;
|
|
194
|
-
this.byId = new Map(bundle.elements.map((e) => [e.id, e]));
|
|
195
|
-
for (const e of bundle.elements) {
|
|
196
|
-
if (e.parent === null)
|
|
197
|
-
continue;
|
|
198
|
-
const list = this.childrenOf.get(e.parent) ?? [];
|
|
199
|
-
list.push(e);
|
|
200
|
-
this.childrenOf.set(e.parent, list);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
children(id) {
|
|
204
|
-
return this.childrenOf.get(id) ?? [];
|
|
205
|
-
}
|
|
206
|
-
/** The Element itself, then its parent, and so on up to the top level. Unknown ids yield only themselves. */
|
|
207
|
-
ancestry(id) {
|
|
208
|
-
const out = [id];
|
|
209
|
-
const seen = new Set(out);
|
|
210
|
-
for (let p = this.byId.get(id)?.parent; p != null && !seen.has(p) && this.byId.has(p); p = this.byId.get(p)?.parent) {
|
|
211
|
-
out.push(p);
|
|
212
|
-
seen.add(p);
|
|
213
|
-
}
|
|
214
|
-
return out;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
const cmp = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|