archidocs 1.2.0 → 1.3.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.
Files changed (119) hide show
  1. package/README.md +62 -13
  2. package/dist/cli/commands.d.ts +231 -10
  3. package/dist/cli/commands.js +134 -9
  4. package/dist/cli/dev.d.ts +5 -6
  5. package/dist/cli/dev.js +12 -14
  6. package/dist/cli/diff-format.d.ts +1 -5
  7. package/dist/cli/init.d.ts +1 -1
  8. package/dist/cli/init.js +2 -2
  9. package/dist/cli/main.js +2 -329
  10. package/dist/cli/run.d.ts +18 -0
  11. package/dist/cli/run.js +283 -0
  12. package/dist/commands/build.d.ts +51 -0
  13. package/dist/commands/build.js +39 -0
  14. package/dist/commands/check.d.ts +8 -0
  15. package/dist/commands/check.js +5 -0
  16. package/dist/commands/diff.d.ts +29 -0
  17. package/dist/commands/diff.js +25 -0
  18. package/dist/commands/export.d.ts +41 -0
  19. package/dist/commands/export.js +47 -0
  20. package/dist/commands/history.d.ts +18 -0
  21. package/dist/commands/history.js +9 -0
  22. package/dist/commands/index.d.ts +11 -0
  23. package/dist/commands/index.js +11 -0
  24. package/dist/core/compare.d.ts +2 -13
  25. package/dist/core/compare.js +2 -35
  26. package/dist/core/index.d.ts +3 -6
  27. package/dist/core/index.js +3 -6
  28. package/dist/core/load.d.ts +0 -2
  29. package/dist/core/load.js +5 -6
  30. package/dist/core/rules.d.ts +10 -0
  31. package/dist/core/rules.js +186 -7
  32. package/dist/core/views/compare.d.ts +12 -0
  33. package/dist/core/views/compare.js +37 -0
  34. package/dist/core/{deployment-views.d.ts → views/deployment.d.ts} +4 -5
  35. package/dist/core/{deployment-views.js → views/deployment.js} +5 -7
  36. package/dist/core/{dynamic-views.d.ts → views/dynamic.d.ts} +1 -3
  37. package/dist/core/{dynamic-views.js → views/dynamic.js} +4 -8
  38. package/dist/core/views/generated.d.ts +18 -0
  39. package/dist/core/views/generated.js +92 -0
  40. package/dist/core/views/ids.d.ts +36 -0
  41. package/dist/core/views/ids.js +51 -0
  42. package/dist/core/views/index.d.ts +13 -0
  43. package/dist/core/views/index.js +12 -0
  44. package/dist/core/views/lens.d.ts +27 -0
  45. package/dist/core/views/lens.js +112 -0
  46. package/dist/core/views/model.d.ts +21 -0
  47. package/dist/core/views/model.js +69 -0
  48. package/dist/core/views/resolve.d.ts +42 -0
  49. package/dist/core/views/resolve.js +81 -0
  50. package/dist/core/{save-as-view.d.ts → views/save-as-view.d.ts} +2 -2
  51. package/dist/core/{save-as-view.js → views/save-as-view.js} +13 -10
  52. package/dist/core/{saved-views.d.ts → views/saved.d.ts} +4 -18
  53. package/dist/core/{saved-views.js → views/saved.js} +8 -103
  54. package/dist/core/views/types.d.ts +91 -0
  55. package/dist/core/views/types.js +2 -0
  56. package/dist/core/workspace-files.d.ts +13 -0
  57. package/dist/core/workspace-files.js +20 -0
  58. package/dist/git.d.ts +2 -0
  59. package/dist/git.js +14 -4
  60. package/dist/history/git.d.ts +0 -10
  61. package/dist/history/git.js +1 -30
  62. package/dist/history/index.d.ts +15 -31
  63. package/dist/history/index.js +47 -43
  64. package/dist/history/points.d.ts +23 -0
  65. package/dist/history/points.js +28 -0
  66. package/dist/history/site.d.ts +30 -0
  67. package/dist/history/site.js +37 -0
  68. package/dist/mcp/errors.d.ts +37 -0
  69. package/dist/mcp/errors.js +35 -0
  70. package/dist/mcp/history.d.ts +4 -4
  71. package/dist/mcp/history.js +56 -116
  72. package/dist/mcp/index.d.ts +2 -1
  73. package/dist/mcp/index.js +1 -0
  74. package/dist/mcp/server.d.ts +1 -2
  75. package/dist/mcp/server.js +30 -29
  76. package/dist/mcp/site.d.ts +12 -0
  77. package/dist/mcp/site.js +46 -0
  78. package/dist/mcp/source.d.ts +14 -7
  79. package/dist/mcp/source.js +25 -99
  80. package/dist/render/layout.d.ts +20 -3
  81. package/dist/render/layout.js +49 -12
  82. package/dist/render/sequence-svg.d.ts +1 -1
  83. package/dist/render/sequence.d.ts +1 -1
  84. package/dist/render/svg.d.ts +1 -1
  85. package/dist/render/svg.js +4 -4
  86. package/dist/revisions/find.d.ts +64 -0
  87. package/dist/revisions/find.js +85 -0
  88. package/dist/revisions/index.d.ts +57 -0
  89. package/dist/revisions/index.js +24 -0
  90. package/dist/revisions/site.d.ts +82 -0
  91. package/dist/revisions/site.js +157 -0
  92. package/dist/revisions/text.d.ts +8 -0
  93. package/dist/revisions/text.js +17 -0
  94. package/dist/revisions/touching.d.ts +7 -0
  95. package/dist/revisions/touching.js +7 -0
  96. package/dist/schema/adr.js +18 -13
  97. package/dist/schema/workspace.js +226 -130
  98. package/dist/viewer/assets/index-C0lIIm8V.js +138 -0
  99. package/dist/viewer/assets/index-YFA-pYjQ.css +1 -0
  100. package/dist/viewer/assets/{layout.worker-Bg-OaLVN.js → layout.worker-BRHAGJrD.js} +1 -1
  101. package/dist/viewer/assets/{png-BDKIXtm5.js → png-DMwnpRCt.js} +1 -1
  102. package/dist/viewer/assets/{svg-Bulv5YWn.js → svg-DN6lMeZo.js} +2 -2
  103. package/dist/viewer/index.html +2 -2
  104. package/dist/workspace/index.d.ts +37 -0
  105. package/dist/workspace/index.js +52 -0
  106. package/guide/SKILL.md +1 -1
  107. package/guide/topics/bootstrap.md +1 -1
  108. package/guide/topics/relationships.md +1 -1
  109. package/package.json +4 -3
  110. package/schemas/adr.schema.json +18 -15
  111. package/schemas/model.schema.json +637 -1144
  112. package/schemas/project.schema.json +8 -4
  113. package/schemas/workspace.schema.json +39 -20
  114. package/dist/core/views.d.ts +0 -126
  115. package/dist/core/views.js +0 -217
  116. package/dist/viewer/assets/index-DvKgCpBr.css +0 -1
  117. package/dist/viewer/assets/index-gucix3xm.js +0 -113
  118. /package/dist/{history → revisions}/migrate.d.ts +0 -0
  119. /package/dist/{history → revisions}/migrate.js +0 -0
@@ -0,0 +1,42 @@
1
+ import type { Bundle, BundleDynamicView, BundleStructuralView } from "../../schema/bundle.ts";
2
+ import { type DynamicResolution, type ResolvedDynamicView } from "./dynamic.ts";
3
+ import { ModelIndex } from "./model.ts";
4
+ import { type SavedResolution } from "./saved.ts";
5
+ import type { ListedKind, ResolvedView, ResolveOptions, ViewSummary } from "./types.ts";
6
+ /** Any View resolved: a Structural View, or a Dynamic View (`kind: "dynamic"`). */
7
+ export type AnyView = ResolvedView | ResolvedDynamicView;
8
+ /**
9
+ * Resolves any View by its id: a Generated View (`c1`, `c2`, `c2/<system>`,
10
+ * `c3/<service>`, only for a Service with Components, or `deployment/<env>`)
11
+ * or a Saved View (`project:view-id`), structural or dynamic. The two are
12
+ * told apart by `kind`; the options apply to a Structural View only. Returns
13
+ * undefined for an unknown id.
14
+ */
15
+ export declare function resolveView(bundle: Bundle, id: string, options?: ResolveOptions): AnyView | undefined;
16
+ /** Resolves a Structural View by id over an index of its Bundle; undefined for an unknown id or a Dynamic View's. */
17
+ export declare function resolveStructural(bundle: Bundle, model: ModelIndex, id: string, options?: ResolveOptions): ResolvedView | undefined;
18
+ /**
19
+ * Resolves one Saved View's definition with what `check` reports about it: a
20
+ * Structural View's `expand` and `collapse` entries that can't apply and its
21
+ * paths that find nothing, or a Dynamic View's Step problems.
22
+ */
23
+ export declare function checkView(bundle: Bundle, def: BundleStructuralView): SavedResolution;
24
+ export declare function checkView(bundle: Bundle, def: BundleDynamicView): DynamicResolution;
25
+ /**
26
+ * The picked nodes of a View, laid out again on their own: each pick with the
27
+ * containers it sits in, and the edges among them, Lens marks kept.
28
+ */
29
+ export declare function pickedView(view: ResolvedView, picks: readonly string[]): ResolvedView;
30
+ /**
31
+ * Every Generated View, in the order `c1`, `c2`, then `c2/<system>` and
32
+ * `c3/<service>` by id, then `deployment/<env>` by Environment id, then every
33
+ * Saved View by id. `kind` keeps one kind; `element` keeps the Views that
34
+ * show that Element as a node or a Deployment, and the
35
+ * Dynamic Views it takes part in (including as the broker of an event Step).
36
+ */
37
+ export declare function listViews(bundle: Bundle, filter?: {
38
+ kind?: ListedKind;
39
+ element?: string;
40
+ }): ViewSummary[];
41
+ /** Every Generated View, resolved, in `listViews` order. */
42
+ export declare function generatedViews(bundle: Bundle): ResolvedView[];
@@ -0,0 +1,81 @@
1
+ import { resolveDynamic, takesPart } from "./dynamic.js";
2
+ import { generatedViewIds, resolveGenerated, summarise } from "./generated.js";
3
+ import { applyLens } from "./lens.js";
4
+ import { ModelIndex } from "./model.js";
5
+ import { resolveSaved } from "./saved.js";
6
+ /**
7
+ * Resolves any View by its id: a Generated View (`c1`, `c2`, `c2/<system>`,
8
+ * `c3/<service>`, only for a Service with Components, or `deployment/<env>`)
9
+ * or a Saved View (`project:view-id`), structural or dynamic. The two are
10
+ * told apart by `kind`; the options apply to a Structural View only. Returns
11
+ * undefined for an unknown id.
12
+ */
13
+ export function resolveView(bundle, id, options = {}) {
14
+ const saved = bundle.views.find((v) => v.id === id);
15
+ if (saved?.kind === "dynamic")
16
+ return resolveDynamic(bundle, saved).view;
17
+ return resolveStructural(bundle, new ModelIndex(bundle), id, options);
18
+ }
19
+ /** Resolves a Structural View by id over an index of its Bundle; undefined for an unknown id or a Dynamic View's. */
20
+ export function resolveStructural(bundle, model, id, options = {}) {
21
+ const lens = options.lens ?? "own";
22
+ const view = unlensed(bundle, model, id, options.expand ?? [], lens);
23
+ if (view && typeof lens === "object")
24
+ applyLens(bundle, model, view, lens);
25
+ return view;
26
+ }
27
+ /** A Structural View with no Lens, except a Saved View's own when the choice is `"own"`. */
28
+ function unlensed(bundle, model, id, expand, lens) {
29
+ const saved = bundle.views.find((v) => v.id === id);
30
+ if (saved)
31
+ return saved.kind === "structural" ? resolveSaved(bundle, model, lens === "own" ? saved : { ...saved, lens: null }).view : undefined;
32
+ return resolveGenerated(bundle, model, id, expand);
33
+ }
34
+ export function checkView(bundle, def) {
35
+ return def.kind === "dynamic" ? resolveDynamic(bundle, def) : resolveSaved(bundle, new ModelIndex(bundle), def);
36
+ }
37
+ /**
38
+ * The picked nodes of a View, laid out again on their own: each pick with the
39
+ * containers it sits in, and the edges among them, Lens marks kept.
40
+ */
41
+ export function pickedView(view, picks) {
42
+ const parentOf = new Map(view.nodes.map((n) => [n.id, n.parent]));
43
+ const kept = new Set();
44
+ for (const pick of picks)
45
+ for (let at = parentOf.has(pick) ? pick : undefined; at; at = parentOf.get(at))
46
+ kept.add(at);
47
+ return { ...view, nodes: view.nodes.filter((n) => kept.has(n.id)), edges: view.edges.filter((e) => kept.has(e.from) && kept.has(e.to)) };
48
+ }
49
+ /**
50
+ * Every Generated View, in the order `c1`, `c2`, then `c2/<system>` and
51
+ * `c3/<service>` by id, then `deployment/<env>` by Environment id, then every
52
+ * Saved View by id. `kind` keeps one kind; `element` keeps the Views that
53
+ * show that Element as a node or a Deployment, and the
54
+ * Dynamic Views it takes part in (including as the broker of an event Step).
55
+ */
56
+ export function listViews(bundle, filter = {}) {
57
+ const model = new ModelIndex(bundle);
58
+ const ids = generatedViewIds(bundle).filter((id) => filter.kind === undefined || summarise(id, bundle).kind === filter.kind);
59
+ const generated = filter.element === undefined ? ids.map((id) => summarise(id, bundle)) : resolveAll(bundle, model, ids).filter((v) => shows(v, filter.element));
60
+ const element = filter.element;
61
+ const saved = bundle.views
62
+ .map((v) => ({ v, kind: v.kind === "dynamic" ? "dynamic" : v.level }))
63
+ .filter(({ kind }) => filter.kind === undefined || kind === filter.kind)
64
+ .filter(({ v }) => {
65
+ if (element === undefined)
66
+ return true;
67
+ if (v.kind === "dynamic")
68
+ return takesPart(resolveDynamic(bundle, v).view, element);
69
+ return shows(resolveSaved(bundle, model, v).view, element);
70
+ })
71
+ .map(({ v, kind }) => ({ id: v.id, kind, title: v.title }));
72
+ return [...generated, ...saved].map(({ id, kind, title }) => ({ id, kind, title }));
73
+ }
74
+ /** Whether a View draws an Element, as a node of its own or as a Deployment of it. */
75
+ const shows = (view, element) => view.nodes.some((n) => n.id === element || (n.kind === "deployment" && n.element === element));
76
+ /** Every Generated View, resolved, in `listViews` order. */
77
+ export function generatedViews(bundle) {
78
+ return resolveAll(bundle, new ModelIndex(bundle), generatedViewIds(bundle));
79
+ }
80
+ /** Resolves each id, skipping any that don't resolve (as when a Workspace with errors declares one id twice). */
81
+ const resolveAll = (bundle, model, ids) => ids.map((id) => resolveStructural(bundle, model, id)).filter((v) => v !== undefined);
@@ -1,5 +1,5 @@
1
- import type { Bundle, BundleLens } from "../schema/bundle.ts";
2
- import { type ViewDirection } from "./views.ts";
1
+ import type { Bundle, BundleLens } from "../../schema/bundle.ts";
2
+ import type { ViewDirection } from "./types.ts";
3
3
  /** What the viewer shows, as its URL holds it: the View, its open boxes, the Lens, the picks and a turned direction. */
4
4
  export interface Screen {
5
5
  view: string;
@@ -1,6 +1,8 @@
1
1
  import { stringify } from "yaml";
2
- import { resolveSaved } from "./saved-views.js";
3
- import { ModelIndex, pickedView, resolveView } from "./views.js";
2
+ import { parseViewId } from "./ids.js";
3
+ import { ModelIndex } from "./model.js";
4
+ import { pickedView, resolveStructural } from "./resolve.js";
5
+ import { resolveSaved } from "./saved.js";
4
6
  const kindLevel = { person: "c1", system: "c1", service: "c2", component: "c3" };
5
7
  const levelDepth = { c1: 1, c2: 2, c3: 3 };
6
8
  /**
@@ -14,7 +16,8 @@ const levelDepth = { c1: 1, c2: 2, c3: 3 };
14
16
  * A Deployment View is saved whole, over its Environment, its Lens as `lens:`.
15
17
  */
16
18
  export function saveAsView(bundle, screen, target) {
17
- const view = resolveView(bundle, screen.view, { expand: screen.open });
19
+ const model = new ModelIndex(bundle);
20
+ const view = resolveStructural(bundle, model, screen.view, { expand: screen.open });
18
21
  if (!view)
19
22
  throw new Error(`No View ${screen.view} to save.`);
20
23
  const own = bundle.views.find((v) => v.id === screen.view && v.kind === "structural");
@@ -24,7 +27,8 @@ export function saveAsView(bundle, screen, target) {
24
27
  if (view.kind === "deployment" && screen.picks.length > 0)
25
28
  throw new Error("Save as View keeps a whole Deployment View; clear the picks first.");
26
29
  if (view.kind === "deployment" && !own) {
27
- body = { level: "deployment", environment: screen.view.slice("deployment/".length) };
30
+ const ref = parseViewId(screen.view);
31
+ body = { level: "deployment", environment: ref?.form === "deployment" ? ref.environment : "" };
28
32
  }
29
33
  else if (own && screen.picks.length === 0) {
30
34
  body = {
@@ -35,7 +39,6 @@ export function saveAsView(bundle, screen, target) {
35
39
  };
36
40
  }
37
41
  else {
38
- const model = new ModelIndex(bundle);
39
42
  const kept = new Set((screen.picks.length === 0 ? view : pickedView(view, screen.picks)).nodes.map((n) => n.id));
40
43
  const depthOf = (id) => model.ancestry(id).length;
41
44
  const expand = screen.open
@@ -49,11 +52,11 @@ export function saveAsView(bundle, screen, target) {
49
52
  const selector = screen.lens ? lensSelector(screen.lens) : undefined;
50
53
  body = plain;
51
54
  if (selector) {
52
- const reached = nodesOf(bundle, { level, include: [selector] });
55
+ const reached = nodesOf(bundle, model, { level, include: [selector] });
53
56
  const include = [selector, ...ids.filter((id) => !reached.has(id))];
54
- const extra = [...nodesOf(bundle, { level, include, expand })].filter((id) => !kept.has(id)).sort();
57
+ const extra = [...nodesOf(bundle, model, { level, include, expand })].filter((id) => !kept.has(id)).sort();
55
58
  const withLens = { level, include, ...nonEmpty({ exclude: extra, expand }) };
56
- if (sameSet(nodesOf(bundle, withLens), kept))
59
+ if (sameSet(nodesOf(bundle, model, withLens), kept))
57
60
  body = withLens;
58
61
  }
59
62
  }
@@ -91,8 +94,8 @@ function writtenLens(lens) {
91
94
  return { ...lens };
92
95
  }
93
96
  /** The node ids the core engine resolves a definition to. */
94
- function nodesOf(bundle, def) {
95
- const resolved = resolveSaved(bundle, {
97
+ function nodesOf(bundle, model, def) {
98
+ const resolved = resolveSaved(bundle, model, {
96
99
  id: "screen:saved",
97
100
  project: "screen",
98
101
  kind: "structural",
@@ -1,5 +1,6 @@
1
- import type { Bundle, BundleLens, BundleStructuralView } from "../schema/bundle.ts";
2
- import { ModelIndex, type ResolvedView } from "./views.ts";
1
+ import type { Bundle, BundleStructuralView } from "../../schema/bundle.ts";
2
+ import { type ModelIndex } from "./model.ts";
3
+ import type { ResolvedView } from "./types.ts";
3
4
  /** An `expand` or `collapse` entry that can't apply: its id is not a node of the View, or it has no children. */
4
5
  export interface BadExpand {
5
6
  field: "expand" | "collapse";
@@ -30,19 +31,4 @@ export interface SavedResolution {
30
31
  * The Lens marks nodes and lights edges but never changes membership.
31
32
  * A Deployment View is resolved by `savedDeployment` instead.
32
33
  */
33
- export declare function resolveSaved(bundle: Bundle, def: BundleStructuralView): SavedResolution;
34
- /** A Lens in words, for tool text and a picture's key. */
35
- export declare const describeLens: (lens: BundleLens) => string;
36
- /**
37
- * Marks every node and lights every edge for the Lens. An Element the Lens
38
- * reaches marks the node that holds it, or that it holds, at its nearest
39
- * distance. An impact Lens lights an edge carrying the impact one hop
40
- * closer to its origin; a path Lens, an edge carrying a hop of a path; a
41
- * Team Lens, an edge between two hit nodes.
42
- */
43
- export declare function applyLens(bundle: Bundle, model: ModelIndex, view: ResolvedView, lens: BundleLens): {
44
- unresolved?: {
45
- from: string;
46
- to: string;
47
- };
48
- };
34
+ export declare function resolveSaved(bundle: Bundle, model: ModelIndex, def: BundleStructuralView): SavedResolution;
@@ -1,8 +1,9 @@
1
- import { resolveDeployment } from "./deployment-views.js";
2
- import { getImpact } from "./impact.js";
3
- import { pathsBetween } from "./paths.js";
4
- import { lifter } from "./query.js";
5
- import { build, ModelIndex } from "./views.js";
1
+ import { getImpact } from "../impact.js";
2
+ import { pathsBetween } from "../paths.js";
3
+ import { lifter } from "../query.js";
4
+ import { resolveDeployment } from "./deployment.js";
5
+ import { applyLens, nodesOn } from "./lens.js";
6
+ import { build } from "./model.js";
6
7
  const levelOf = { c1: "system", c2: "service", c3: "component" };
7
8
  /**
8
9
  * Resolves a Saved structural View:
@@ -14,8 +15,7 @@ const levelOf = { c1: "system", c2: "service", c3: "component" };
14
15
  * The Lens marks nodes and lights edges but never changes membership.
15
16
  * A Deployment View is resolved by `savedDeployment` instead.
16
17
  */
17
- export function resolveSaved(bundle, def) {
18
- const model = new ModelIndex(bundle);
18
+ export function resolveSaved(bundle, model, def) {
19
19
  if (def.level === "deployment")
20
20
  return savedDeployment(bundle, model, def);
21
21
  const kind = def.level;
@@ -96,7 +96,7 @@ function savedDeployment(bundle, model, def) {
96
96
  return true;
97
97
  return false;
98
98
  };
99
- const view = resolveDeployment(bundle, { id: def.id, title: def.title }, def.environment ?? "", {
99
+ const view = resolveDeployment(bundle, model, { id: def.id, title: def.title }, def.environment ?? "", {
100
100
  keep: (s) => !excluded.has(s),
101
101
  deployed: (d) => (included === undefined || included.has(d.service)) && (def.targets.length === 0 || under(d.target)),
102
102
  });
@@ -109,8 +109,6 @@ function savedDeployment(bundle, model, def) {
109
109
  }
110
110
  return { view, badExpand: [], unresolvedPaths };
111
111
  }
112
- /** A Lens in words, for tool text and a picture's key. */
113
- export const describeLens = (lens) => "impact" in lens ? `impact of ${lens.impact}, ${lens.direction}` : "team" in lens ? `Team ${lens.team}` : `paths from ${lens.path.from} to ${lens.path.to} (${lens.path.paths ?? "shortest"})`;
114
112
  /** The Elements one selector names; unknown ids name none (`unknown-element` reports them). */
115
113
  function selected(bundle, model, s) {
116
114
  if (typeof s === "string")
@@ -148,96 +146,3 @@ function selected(bundle, model, s) {
148
146
  }
149
147
  return { ids };
150
148
  }
151
- const nodesOn = (paths) => new Set(paths.flatMap((p) => p.hops.flatMap((h) => [h.from, h.to])));
152
- /**
153
- * Marks every node and lights every edge for the Lens. An Element the Lens
154
- * reaches marks the node that holds it, or that it holds, at its nearest
155
- * distance. An impact Lens lights an edge carrying the impact one hop
156
- * closer to its origin; a path Lens, an edge carrying a hop of a path; a
157
- * Team Lens, an edge between two hit nodes.
158
- */
159
- export function applyLens(bundle, model, view, lens) {
160
- view.lens = lens;
161
- /** Element ids the Lens reaches, with their distance when it has one. */
162
- const reached = new Map();
163
- /** For an impact Lens, which side of the origin each reached Element is on, at its nearest distance. */
164
- const sides = new Map();
165
- const carried = new Set();
166
- let unresolved;
167
- if ("impact" in lens) {
168
- if (model.byId.has(lens.impact)) {
169
- reached.set(lens.impact, 0);
170
- sides.set(lens.impact, "origin");
171
- const impact = getImpact(bundle, lens.impact, lens.direction);
172
- const rings = [...(impact.upstream ?? []).map((ring) => ["upstream", ring]), ...(impact.downstream ?? []).map((ring) => ["downstream", ring])];
173
- for (const [side, ring] of rings) {
174
- for (const e of ring.elements) {
175
- if (ring.distance < (reached.get(e.id) ?? Infinity)) {
176
- reached.set(e.id, ring.distance);
177
- sides.set(e.id, side);
178
- }
179
- for (const r of e.relationships)
180
- carried.add(r);
181
- }
182
- }
183
- }
184
- }
185
- else if ("team" in lens) {
186
- for (const e of model.elements)
187
- if (e.owner === lens.team)
188
- reached.set(e.id, undefined);
189
- for (const t of bundle.targets)
190
- if (t.owner === lens.team)
191
- reached.set(t.id, undefined);
192
- }
193
- else {
194
- const paths = pathsBetween(bundle, lens.path.from, lens.path.to, lens.path.paths ?? "shortest");
195
- for (const id of nodesOn(paths))
196
- reached.set(id, undefined);
197
- for (const p of paths)
198
- for (const h of p.hops)
199
- for (const r of h.relationships)
200
- carried.add(r);
201
- if (paths.length === 0 && model.byId.has(lens.path.from) && model.byId.has(lens.path.to))
202
- unresolved = { from: lens.path.from, to: lens.path.to };
203
- }
204
- // Each reached Element marks the nearest node holding it; an impact or path Lens also marks the nodes inside it.
205
- // A node stands for its own id, or for the Element it draws: a Deployment View draws one Service as several Deployments.
206
- const standing = new Map();
207
- for (const n of view.nodes)
208
- standing.set(n.element ?? n.id, [...(standing.get(n.element ?? n.id) ?? []), n.id]);
209
- const marks = new Map(view.nodes.map((n) => [n.id, { hit: false }]));
210
- const mark = (node, d, side) => {
211
- const m = marks.get(node);
212
- if (!m)
213
- return;
214
- m.hit = true;
215
- if (d !== undefined && d < (m.distance ?? Infinity)) {
216
- m.distance = d;
217
- if (side !== undefined)
218
- m.side = side;
219
- }
220
- };
221
- for (const [id, d] of reached) {
222
- const holder = model.ancestry(id).find((a) => standing.has(a));
223
- for (const n of holder === undefined ? [] : standing.get(holder))
224
- mark(n, d, sides.get(id));
225
- if (!("team" in lens))
226
- for (const n of view.nodes)
227
- if ((n.element ?? n.id) !== id && model.ancestry(n.element ?? n.id).includes(id))
228
- mark(n.id, d, sides.get(id));
229
- }
230
- for (const n of view.nodes)
231
- n.mark = marks.get(n.id);
232
- const markOf = new Map(view.nodes.map((n) => [n.id, n.mark]));
233
- for (const e of view.edges) {
234
- const [from, to] = [markOf.get(e.from), markOf.get(e.to)];
235
- if ("team" in lens)
236
- e.lit = from.hit && to.hit;
237
- else if ("impact" in lens)
238
- e.lit = e.relationships.some((r) => carried.has(r)) && from.distance !== undefined && to.distance !== undefined && Math.abs(from.distance - to.distance) === 1;
239
- else
240
- e.lit = e.relationships.some((r) => carried.has(r)) && from.hit && to.hit;
241
- }
242
- return unresolved ? { unresolved } : {};
243
- }
@@ -0,0 +1,91 @@
1
+ import type { BundleElement, BundleLens, BundleRelationship } from "../../schema/bundle.ts";
2
+ /** The most nodes a View may have before `oversized-view` warns. */
3
+ export declare const MAX_VIEW_NODES = 150;
4
+ /** The kinds of Structural View: the three levels, and the Deployment View. */
5
+ export type ViewKind = "c1" | "c2" | "c3" | "deployment";
6
+ /** How Compare marks a node or edge of a View between two Bundles. */
7
+ export type CompareMark = "added" | "removed" | "changed" | "unchanged";
8
+ /**
9
+ * One node of a resolved View: an Element, drawn as a box or as a container.
10
+ * A Deployment View also has Deployment Targets (`target`), Deployments
11
+ * (`deployment`, id `<service>@<target>`) and the System boxes inside each
12
+ * Target (`system`, id `<system>@<target>`).
13
+ */
14
+ export interface ViewNode {
15
+ id: string;
16
+ kind: BundleElement["kind"] | "target" | "deployment";
17
+ name: string;
18
+ /** The Element a Deployment or a Target's System box draws, when the node's id is not that Element's. */
19
+ element?: string;
20
+ /** A Deployment's Deployment Target. */
21
+ target?: string;
22
+ /** The nearest ancestor that is itself a node of this View, else null. */
23
+ parent: string | null;
24
+ /** True when the Element has children in the Model that this View hides inside it. */
25
+ collapsed: boolean;
26
+ /** True for an External System or Service. */
27
+ external: boolean;
28
+ /** Set on every node of a View with a Lens: whether the Lens hits it, and for an impact Lens its nearest distance. */
29
+ mark?: NodeMark;
30
+ /** Set on every node of a View drawn for Compare (`compareView`). */
31
+ change?: CompareMark;
32
+ }
33
+ /** How a Lens marks a node; a collapsed box is hit when anything inside it is. */
34
+ export interface NodeMark {
35
+ hit: boolean;
36
+ distance?: number;
37
+ /** For an impact Lens: the origin itself, or the side of it the node sits on, at its nearest distance. */
38
+ side?: ImpactSide;
39
+ }
40
+ export type ImpactSide = "origin" | "upstream" | "downstream";
41
+ /** The way a View draws: top to bottom, bottom to top, left to right or right to left. */
42
+ export type ViewDirection = "TB" | "BT" | "LR" | "RL";
43
+ /** An edge between two nodes, with the declared Relationships beneath it. */
44
+ export interface ViewEdge {
45
+ from: string;
46
+ to: string;
47
+ relationships: BundleRelationship[];
48
+ /** Set on every edge of a View with a Lens: whether the Lens lights it. */
49
+ lit?: boolean;
50
+ /** Set on every edge of a View drawn for Compare (`compareView`). */
51
+ change?: CompareMark;
52
+ }
53
+ /** A Structural View resolved to nodes and edges, sorted by id and by `from`, then `to`. */
54
+ export interface ResolvedView {
55
+ id: string;
56
+ kind: ViewKind;
57
+ title: string;
58
+ /** The way the View draws: a Saved View's own, else `TB` for a Deployment View, else `LR`. */
59
+ direction: ViewDirection;
60
+ /** A Deployment View's Environment. */
61
+ environment?: string;
62
+ /** A Saved View's Lens, if it carries one. */
63
+ lens?: BundleLens;
64
+ nodes: ViewNode[];
65
+ edges: ViewEdge[];
66
+ }
67
+ export interface ResolveOptions {
68
+ /**
69
+ * Systems and Services to open, showing their children; viewer state, not a
70
+ * different View. A box opens only while it is itself shown, so a Service
71
+ * stays shut inside a closed System. C1 opens nothing.
72
+ */
73
+ expand?: readonly string[];
74
+ /**
75
+ * The Lens over the View, which marks nodes and lights edges without
76
+ * changing which nodes the View holds: `"own"` (the default) is a Saved
77
+ * View's own Lens and none on any other View, `"none"` is no Lens, and a
78
+ * given Lens replaces the View's own.
79
+ */
80
+ lens?: LensChoice;
81
+ }
82
+ /** Which Lens a View is resolved with: its own, none, or this one. */
83
+ export type LensChoice = "own" | "none" | BundleLens;
84
+ /** The kinds a View is listed under: a Saved Structural View's is its `level`. */
85
+ export type ListedKind = ViewKind | "dynamic";
86
+ /** A View as listed, without its nodes and edges. */
87
+ export interface ViewSummary {
88
+ id: string;
89
+ kind: ListedKind;
90
+ title: string;
91
+ }
@@ -0,0 +1,2 @@
1
+ /** The most nodes a View may have before `oversized-view` warns. */
2
+ export const MAX_VIEW_NODES = 150;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The one rule for which files make up a Workspace: `load`'s walk, the
3
+ * Checkout's fingerprint and (later) dev's watcher all use it. Pure and
4
+ * browser-safe, so core can use it.
5
+ */
6
+ /** Whether `load` skips a folder or file by its name: hidden ones (`.git`, editor swap files) and `node_modules`. */
7
+ export declare function isSkippedName(name: string): boolean;
8
+ /**
9
+ * Whether a path, relative to the Workspace root and `/` or `\` separated,
10
+ * is a Workspace file: no part of it is skipped, and it is a `.yaml` model
11
+ * file or an `.md` ADR.
12
+ */
13
+ export declare function isWorkspaceFile(path: string): boolean;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * The one rule for which files make up a Workspace: `load`'s walk, the
3
+ * Checkout's fingerprint and (later) dev's watcher all use it. Pure and
4
+ * browser-safe, so core can use it.
5
+ */
6
+ /** Whether `load` skips a folder or file by its name: hidden ones (`.git`, editor swap files) and `node_modules`. */
7
+ export function isSkippedName(name) {
8
+ return name.startsWith(".") || name === "node_modules";
9
+ }
10
+ /**
11
+ * Whether a path, relative to the Workspace root and `/` or `\` separated,
12
+ * is a Workspace file: no part of it is skipped, and it is a `.yaml` model
13
+ * file or an `.md` ADR.
14
+ */
15
+ export function isWorkspaceFile(path) {
16
+ const parts = path.split(/[\\/]/).filter((part) => part !== "");
17
+ if (parts.length === 0 || parts.some(isSkippedName))
18
+ return false;
19
+ return path.endsWith(".yaml") || path.endsWith(".md");
20
+ }
package/dist/git.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ /** Runs git in `cwd` and returns stdout; throws with git's own message on failure. */
2
+ export declare function git(cwd: string, ...args: string[]): Promise<string>;
1
3
  /** HEAD's sha and commit time, so a Bundle built twice at one commit is byte-identical. Both null outside git or before the first commit. */
2
4
  export declare function gitHead(cwd: string): Promise<{
3
5
  commit: string | null;
package/dist/git.js CHANGED
@@ -1,10 +1,21 @@
1
1
  import { execFile } from "node:child_process";
2
2
  import { promisify } from "node:util";
3
+ const exec = promisify(execFile);
4
+ /** Runs git in `cwd` and returns stdout; throws with git's own message on failure. */
5
+ export async function git(cwd, ...args) {
6
+ try {
7
+ const { stdout } = await exec("git", ["-c", "core.quotePath=false", ...args], { cwd, maxBuffer: 1024 * 1024 * 1024, encoding: "utf8" });
8
+ return stdout;
9
+ }
10
+ catch (e) {
11
+ const err = e;
12
+ throw new Error(err.stderr?.trim() || err.message, { cause: e });
13
+ }
14
+ }
3
15
  /** HEAD's sha and commit time, so a Bundle built twice at one commit is byte-identical. Both null outside git or before the first commit. */
4
16
  export async function gitHead(cwd) {
5
17
  try {
6
- const { stdout } = await promisify(execFile)("git", ["log", "-1", "--format=%H %cI"], { cwd });
7
- const [commit, builtAt] = stdout.trim().split(" ");
18
+ const [commit, builtAt] = (await git(cwd, "log", "-1", "--format=%H %cI")).trim().split(" ");
8
19
  return { commit: commit || null, builtAt: builtAt || null };
9
20
  }
10
21
  catch {
@@ -14,8 +25,7 @@ export async function gitHead(cwd) {
14
25
  /** The top folder of the git checkout holding `cwd`, or null outside git. */
15
26
  export async function gitTopLevel(cwd) {
16
27
  try {
17
- const { stdout } = await promisify(execFile)("git", ["rev-parse", "--show-toplevel"], { cwd });
18
- return stdout.trim() || null;
28
+ return (await git(cwd, "rev-parse", "--show-toplevel")).trim() || null;
19
29
  }
20
30
  catch {
21
31
  return null;
@@ -1,6 +1,4 @@
1
1
  import type { FileSystem } from "../core/fs.ts";
2
- /** Runs git in `cwd` and returns stdout; throws with git's own message on failure. */
3
- export declare function git(cwd: string, ...args: string[]): Promise<string>;
4
2
  /**
5
3
  * A read-only FileSystem over the tree of one commit. Paths are absolute
6
4
  * under `repoRoot`, as on disk; files are read with `git show`, so no
@@ -28,12 +26,4 @@ export declare function defaultBranch(repoRoot: string): Promise<string>;
28
26
  export declare function firstParentCommitsTouching(repoRoot: string, branch: string, path: string): Promise<CommitInfo[]>;
29
27
  /** Tag names by the commit they point at. */
30
28
  export declare function tagsByCommit(repoRoot: string): Promise<Map<string, string[]>>;
31
- /** Whether `point` is a date (`YYYY-MM-DD` or a full ISO 8601 time) rather than a ref. */
32
- export declare const isDate: (point: string) => boolean;
33
- /**
34
- * Resolves a point in time to a commit sha: a date to the last first-parent
35
- * default-branch commit at or before it, anything else as a git ref.
36
- * Undefined when there is no such commit.
37
- */
38
- export declare function resolvePoint(repoRoot: string, point: string): Promise<string | undefined>;
39
29
  export declare const joinRepo: (repoRoot: string, rel: string) => string;
@@ -1,18 +1,5 @@
1
- import { execFile } from "node:child_process";
2
1
  import { join, relative, sep } from "node:path";
3
- import { promisify } from "node:util";
4
- const exec = promisify(execFile);
5
- /** Runs git in `cwd` and returns stdout; throws with git's own message on failure. */
6
- export async function git(cwd, ...args) {
7
- try {
8
- const { stdout } = await exec("git", ["-c", "core.quotePath=false", ...args], { cwd, maxBuffer: 1024 * 1024 * 1024, encoding: "utf8" });
9
- return stdout;
10
- }
11
- catch (e) {
12
- const err = e;
13
- throw new Error(err.stderr?.trim() || err.message, { cause: e });
14
- }
15
- }
2
+ import { git } from "../git.js";
16
3
  /**
17
4
  * A read-only FileSystem over the tree of one commit. Paths are absolute
18
5
  * under `repoRoot`, as on disk; files are read with `git show`, so no
@@ -107,20 +94,4 @@ export async function tagsByCommit(repoRoot) {
107
94
  }
108
95
  return map;
109
96
  }
110
- /** Whether `point` is a date (`YYYY-MM-DD` or a full ISO 8601 time) rather than a ref. */
111
- export const isDate = (point) => /^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2}(:\d{2})?(\.\d+)?(Z|[+-]\d{2}:?\d{2})?)?$/.test(point);
112
- /** A bare date means the end of that day (UTC); a time is taken as given. */
113
- const endOf = (date) => (/^\d{4}-\d{2}-\d{2}$/.test(date) ? `${date}T23:59:59Z` : date);
114
- /**
115
- * Resolves a point in time to a commit sha: a date to the last first-parent
116
- * default-branch commit at or before it, anything else as a git ref.
117
- * Undefined when there is no such commit.
118
- */
119
- export async function resolvePoint(repoRoot, point) {
120
- if (isDate(point)) {
121
- const sha = (await git(repoRoot, "rev-list", "-1", "--first-parent", `--before=${endOf(point)}`, await defaultBranch(repoRoot)).catch(() => "")).trim();
122
- return sha || undefined;
123
- }
124
- return (await git(repoRoot, "rev-parse", "--verify", "--quiet", "--end-of-options", `${point}^{commit}`).catch(() => "")).trim() || undefined;
125
- }
126
97
  export const joinRepo = (repoRoot, rel) => (rel === "" ? repoRoot : join(repoRoot, rel));