@intentius/chant 0.124.96 → 0.124.98

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 (237) hide show
  1. package/dist/audit/core.d.ts +29 -0
  2. package/dist/audit/core.d.ts.map +1 -1
  3. package/dist/audit/core.js +48 -11
  4. package/dist/audit/identity.d.ts +27 -0
  5. package/dist/audit/identity.d.ts.map +1 -0
  6. package/dist/audit/identity.js +36 -0
  7. package/dist/audit/report-html.d.ts +3 -1
  8. package/dist/audit/report-html.d.ts.map +1 -1
  9. package/dist/audit/report-html.js +1 -1
  10. package/dist/audit/report-model.d.ts +16 -0
  11. package/dist/audit/report-model.d.ts.map +1 -1
  12. package/dist/audit/report-model.js +5 -1
  13. package/dist/change-set-graph.d.ts +3 -1
  14. package/dist/change-set-graph.d.ts.map +1 -1
  15. package/dist/change-set-graph.js +7 -1
  16. package/dist/change-set.d.ts +5 -2
  17. package/dist/change-set.d.ts.map +1 -1
  18. package/dist/change-set.js +6 -3
  19. package/dist/ci-agent.d.ts +17 -0
  20. package/dist/ci-agent.d.ts.map +1 -1
  21. package/dist/ci-agent.js +32 -0
  22. package/dist/ci-comment-allow.d.ts +88 -0
  23. package/dist/ci-comment-allow.d.ts.map +1 -0
  24. package/dist/ci-comment-allow.js +178 -0
  25. package/dist/ci-comment-commands.d.ts +12 -0
  26. package/dist/ci-comment-commands.d.ts.map +1 -1
  27. package/dist/ci-comment-commands.js +22 -0
  28. package/dist/ci-control.d.ts +6 -1
  29. package/dist/ci-control.d.ts.map +1 -1
  30. package/dist/ci-control.js +6 -1
  31. package/dist/ci-product.d.ts +3 -0
  32. package/dist/ci-product.d.ts.map +1 -1
  33. package/dist/ci-product.js +3 -0
  34. package/dist/cli/commands/audit.d.ts +3 -1
  35. package/dist/cli/commands/audit.d.ts.map +1 -1
  36. package/dist/cli/commands/audit.js +23 -6
  37. package/dist/cli/commands/import.d.ts +8 -1
  38. package/dist/cli/commands/import.d.ts.map +1 -1
  39. package/dist/cli/commands/import.js +31 -6
  40. package/dist/cli/handlers/agent.d.ts.map +1 -1
  41. package/dist/cli/handlers/agent.js +12 -2
  42. package/dist/cli/handlers/pr-comment.d.ts +6 -0
  43. package/dist/cli/handlers/pr-comment.d.ts.map +1 -1
  44. package/dist/cli/handlers/pr-comment.js +12 -0
  45. package/dist/cli/handlers/promote.d.ts.map +1 -1
  46. package/dist/cli/handlers/promote.js +53 -6
  47. package/dist/cli/main.d.ts.map +1 -1
  48. package/dist/cli/main.js +29 -6
  49. package/dist/cli/parse-args.d.ts.map +1 -1
  50. package/dist/cli/parse-args.js +23 -0
  51. package/dist/cli/registry.d.ts +8 -0
  52. package/dist/cli/registry.d.ts.map +1 -1
  53. package/dist/cloud-lister/mask.d.ts +30 -1
  54. package/dist/cloud-lister/mask.d.ts.map +1 -1
  55. package/dist/cloud-lister/mask.js +66 -3
  56. package/dist/components/driver.d.ts +8 -1
  57. package/dist/components/driver.d.ts.map +1 -1
  58. package/dist/components/driver.js +1 -0
  59. package/dist/components/product-pipeline.d.ts +23 -1
  60. package/dist/components/product-pipeline.d.ts.map +1 -1
  61. package/dist/components/product-pipeline.js +40 -7
  62. package/dist/components/product-plan.d.ts +20 -0
  63. package/dist/components/product-plan.d.ts.map +1 -1
  64. package/dist/components/product-plan.js +11 -1
  65. package/dist/control/applied.d.ts +8 -1
  66. package/dist/control/applied.d.ts.map +1 -1
  67. package/dist/control/applied.js +18 -2
  68. package/dist/control/dispatch.d.ts +52 -0
  69. package/dist/control/dispatch.d.ts.map +1 -1
  70. package/dist/control/dispatch.js +140 -4
  71. package/dist/control/train.d.ts +198 -0
  72. package/dist/control/train.d.ts.map +1 -0
  73. package/dist/control/train.js +294 -0
  74. package/dist/deep-observation.js +2 -2
  75. package/dist/floor-table.data.d.ts.map +1 -1
  76. package/dist/floor-table.data.js +7 -1
  77. package/dist/graph-detail.d.ts +9 -0
  78. package/dist/graph-detail.d.ts.map +1 -1
  79. package/dist/graph-detail.js +38 -13
  80. package/dist/graph-refs.d.ts +233 -3
  81. package/dist/graph-refs.d.ts.map +1 -1
  82. package/dist/graph-refs.js +106 -15
  83. package/dist/lint/post-synth.d.ts +22 -0
  84. package/dist/lint/post-synth.d.ts.map +1 -1
  85. package/dist/lint/rules/declarable-naming-convention.d.ts +12 -0
  86. package/dist/lint/rules/declarable-naming-convention.d.ts.map +1 -1
  87. package/dist/lint/rules/declarable-naming-convention.js +38 -8
  88. package/dist/lint/rules/imported-source.d.ts +20 -0
  89. package/dist/lint/rules/imported-source.d.ts.map +1 -0
  90. package/dist/lint/rules/imported-source.js +27 -0
  91. package/dist/lint/rules/no-unused-declarable.d.ts.map +1 -1
  92. package/dist/lint/rules/no-unused-declarable.js +3 -0
  93. package/dist/op/gate.d.ts +2 -0
  94. package/dist/op/gate.d.ts.map +1 -1
  95. package/dist/op/gate.js +8 -1
  96. package/dist/pr-forge-reads.d.ts +17 -0
  97. package/dist/pr-forge-reads.d.ts.map +1 -1
  98. package/dist/pr-forge-reads.js +55 -0
  99. package/dist/reconcile.d.ts +9 -0
  100. package/dist/reconcile.d.ts.map +1 -1
  101. package/dist/release-floors.d.ts +9 -1
  102. package/dist/release-floors.d.ts.map +1 -1
  103. package/dist/release-floors.js +10 -2
  104. package/dist/repo-path.d.ts +29 -0
  105. package/dist/repo-path.d.ts.map +1 -0
  106. package/dist/repo-path.js +81 -0
  107. package/dist/sensitive-key.d.ts +23 -0
  108. package/dist/sensitive-key.d.ts.map +1 -1
  109. package/dist/sensitive-key.js +37 -0
  110. package/dist/terraform/hcl2json.d.ts +7 -0
  111. package/dist/terraform/hcl2json.d.ts.map +1 -1
  112. package/dist/terraform/hcl2json.js +7 -0
  113. package/dist/wave-runtime.mjs +352 -345
  114. package/dist/workspace/catalog-edges.d.ts +147 -0
  115. package/dist/workspace/catalog-edges.d.ts.map +1 -0
  116. package/dist/workspace/catalog-edges.js +461 -0
  117. package/dist/workspace/compose-graph.d.ts +73 -3
  118. package/dist/workspace/compose-graph.d.ts.map +1 -1
  119. package/dist/workspace/declaration.d.ts +2 -0
  120. package/dist/workspace/declaration.d.ts.map +1 -1
  121. package/dist/workspace/declaration.js +1 -0
  122. package/dist/workspace/declaration.schema.json +6 -0
  123. package/dist/workspace/discover.d.ts +134 -0
  124. package/dist/workspace/discover.d.ts.map +1 -0
  125. package/dist/workspace/discover.js +372 -0
  126. package/dist/workspace/graph-cli.d.ts +20 -0
  127. package/dist/workspace/graph-cli.d.ts.map +1 -1
  128. package/dist/workspace/graph-cli.js +178 -20
  129. package/dist/workspace/graph.schema.json +195 -2
  130. package/dist/workspace/release-train.d.ts +214 -3
  131. package/dist/workspace/release-train.d.ts.map +1 -1
  132. package/dist/workspace/release-train.js +552 -16
  133. package/dist/workspace/repo-ref.d.ts +14 -0
  134. package/dist/workspace/repo-ref.d.ts.map +1 -1
  135. package/dist/workspace/repo-ref.js +26 -1
  136. package/dist/workspace/workspace-gates.d.ts +24 -0
  137. package/dist/workspace/workspace-gates.d.ts.map +1 -1
  138. package/dist/workspace/workspace-gates.js +29 -5
  139. package/dist/workspace/workspace-ledger.d.ts +31 -5
  140. package/dist/workspace/workspace-ledger.d.ts.map +1 -1
  141. package/dist/workspace/workspace-ledger.js +2 -1
  142. package/dist/workspace/workspace-run.d.ts +14 -0
  143. package/dist/workspace/workspace-run.d.ts.map +1 -1
  144. package/dist/workspace/workspace-run.js +2 -2
  145. package/dist/yaml.d.ts.map +1 -1
  146. package/dist/yaml.js +33 -8
  147. package/package.json +1 -1
  148. package/src/audit/core.test.ts +64 -1
  149. package/src/audit/core.ts +75 -10
  150. package/src/audit/identity.test.ts +31 -0
  151. package/src/audit/identity.ts +43 -0
  152. package/src/audit/report-html.ts +4 -2
  153. package/src/audit/report-model.ts +21 -1
  154. package/src/change-set-graph.test.ts +33 -1
  155. package/src/change-set-graph.ts +7 -1
  156. package/src/change-set.ts +6 -3
  157. package/src/ci-agent.test.ts +32 -0
  158. package/src/ci-agent.ts +42 -0
  159. package/src/ci-comment-allow.test.ts +380 -0
  160. package/src/ci-comment-allow.ts +184 -0
  161. package/src/ci-comment-commands.ts +25 -0
  162. package/src/ci-control.ts +42 -0
  163. package/src/ci-product.ts +3 -0
  164. package/src/cli/commands/audit-parser-notice.test.ts +74 -0
  165. package/src/cli/commands/audit.test.ts +12 -0
  166. package/src/cli/commands/audit.ts +25 -7
  167. package/src/cli/commands/import-layout.test.ts +2 -1
  168. package/src/cli/commands/import.ts +29 -6
  169. package/src/cli/handlers/agent.ts +13 -2
  170. package/src/cli/handlers/pr-before-merge.test.ts +18 -0
  171. package/src/cli/handlers/pr-comment.ts +12 -0
  172. package/src/cli/handlers/promote.test.ts +68 -0
  173. package/src/cli/handlers/promote.ts +52 -6
  174. package/src/cli/main.test.ts +5 -0
  175. package/src/cli/main.ts +29 -6
  176. package/src/cli/parse-args.ts +18 -0
  177. package/src/cli/registry.ts +8 -0
  178. package/src/cloud-lister/kubernetes.k3d.e2e.test.ts +104 -0
  179. package/src/cloud-lister/mask-references.test.ts +132 -0
  180. package/src/cloud-lister/mask.ts +68 -3
  181. package/src/components/driver.ts +9 -1
  182. package/src/components/product-pipeline.ts +57 -7
  183. package/src/components/product-plan.ts +27 -2
  184. package/src/control/applied.ts +33 -3
  185. package/src/control/dispatch.ts +156 -5
  186. package/src/control/train.test.ts +215 -0
  187. package/src/control/train.ts +413 -0
  188. package/src/deep-observation.ts +2 -2
  189. package/src/floor-table.data.ts +7 -1
  190. package/src/graph-detail.ts +37 -12
  191. package/src/graph-refs.test.ts +45 -1
  192. package/src/graph-refs.ts +321 -14
  193. package/src/lint/post-synth.ts +20 -0
  194. package/src/lint/rules/declarable-naming-convention.test.ts +35 -1
  195. package/src/lint/rules/declarable-naming-convention.ts +35 -8
  196. package/src/lint/rules/imported-source.test.ts +22 -0
  197. package/src/lint/rules/imported-source.ts +31 -0
  198. package/src/lint/rules/no-unused-declarable.test.ts +16 -0
  199. package/src/lint/rules/no-unused-declarable.ts +7 -0
  200. package/src/op/gate.ts +10 -2
  201. package/src/pr-forge-reads.ts +62 -0
  202. package/src/reconcile.ts +9 -0
  203. package/src/release-floors.ts +14 -2
  204. package/src/repo-path.test.ts +72 -0
  205. package/src/repo-path.ts +103 -0
  206. package/src/sensitive-key.ts +38 -0
  207. package/src/terraform/hcl2json.ts +8 -0
  208. package/src/workspace/application-set.e2e.test.ts +405 -0
  209. package/src/workspace/catalog-edges.ts +507 -0
  210. package/src/workspace/ci-green-workflow.test.ts +2 -2
  211. package/src/workspace/cluster-join.e2e.test.ts +150 -0
  212. package/src/workspace/compose-graph.ts +74 -5
  213. package/src/workspace/declaration.schema.json +6 -0
  214. package/src/workspace/declaration.ts +3 -0
  215. package/src/workspace/discover.e2e.test.ts +122 -0
  216. package/src/workspace/discover.test.ts +225 -0
  217. package/src/workspace/discover.ts +406 -0
  218. package/src/workspace/drift-reader.test.ts +3 -3
  219. package/src/workspace/external-secret-catalog.e2e.test.ts +98 -0
  220. package/src/workspace/external-secret-catalog.test.ts +142 -0
  221. package/src/workspace/graph-cli.ts +207 -21
  222. package/src/workspace/graph-contract.test.ts +92 -0
  223. package/src/workspace/graph.schema.json +195 -2
  224. package/src/workspace/helm-references.e2e.test.ts +135 -0
  225. package/src/workspace/identity-annotation-catalog.e2e.test.ts +91 -0
  226. package/src/workspace/identity-annotation-catalog.test.ts +139 -0
  227. package/src/workspace/release-train-repos.test.ts +304 -0
  228. package/src/workspace/release-train.test.ts +296 -0
  229. package/src/workspace/release-train.ts +631 -16
  230. package/src/workspace/repo-ref.ts +26 -1
  231. package/src/workspace/runs-on.test.ts +45 -0
  232. package/src/workspace/workspace-gates.ts +48 -5
  233. package/src/workspace/workspace-ledger.ts +28 -5
  234. package/src/workspace/workspace-run.test.ts +1 -1
  235. package/src/workspace/workspace-run.ts +2 -2
  236. package/src/yaml.test.ts +96 -8
  237. package/src/yaml.ts +36 -8
@@ -0,0 +1,147 @@
1
+ /**
2
+ * The reference catalog over a composed workspace graph (#5097, phase 3 of
3
+ * INTENTIUS/behold#1049).
4
+ *
5
+ * Each lexicon's `referenceCatalog` says how its resources name each other.
6
+ * It ran over a live read and over a cloud index (#4522), never over the
7
+ * declared graph `chant workspace graph` composes, so no edge went from one
8
+ * member to another except through links. {@link runCatalogPass} runs
9
+ * `reconstructIndexedEdges` (../graph-refs.ts) over every composed node, and
10
+ * {@link placeCatalogPass} writes what it found into the document:
11
+ *
12
+ * - each edge it draws goes in `edges` with `origin: "derived"`, the `rule`
13
+ * that drew it, its `relation` and `grain: "property"`, and the holder's
14
+ * `member`. A pair the declared graph already joins gets no second edge;
15
+ * - a reference that names no node goes in `dangling`, with its `rule` and
16
+ * the `targetKind` the rule looks for;
17
+ * - a reference that names more than one node draws no edge and goes in
18
+ * `ambiguous` with every candidate;
19
+ * - `catalog` names the lexicons whose catalog ran, the members read, each
20
+ * rule the document names, and per node the arguments it could not read.
21
+ *
22
+ * ## Scopes
23
+ *
24
+ * A Kubernetes name is unique inside its namespace, while a rule from a
25
+ * Kubernetes object to a cloud resource has to reach a node of another
26
+ * member. The pass keeps one scope per node and uses the index's two-level
27
+ * lookup for both: every node sits in the workspace, and a node of a kind its
28
+ * catalog lists in `scopes` also sits in the scope that kind names, its
29
+ * namespace. A holder in a namespace reaches the nodes of that namespace in
30
+ * any member, and every node that has no namespace. A holder with no
31
+ * namespace reaches only nodes with none. One of those kinds whose node names
32
+ * no namespace sits in a scope of its own member, since chant cannot tell
33
+ * where it will be applied, and the objects one member applies together go to
34
+ * one namespace far more often than not.
35
+ *
36
+ * ## Declared nodes the rules are not written against
37
+ *
38
+ * A catalog's `declaredNode` gives the node the rules read, for a lexicon
39
+ * whose declared nodes are not shaped like its rules: terraform's are all
40
+ * `Terraform::Resource`, with their arguments under `body`. An instance node
41
+ * is handed its block node too, since its attrs stay on the block (#5117).
42
+ * The view is read for this pass only; the document's nodes are unchanged.
43
+ *
44
+ * ## Generated nodes and repository paths (#5102)
45
+ *
46
+ * A catalog's `generates` rules make nodes from a node: an ApplicationSet's
47
+ * generators yield Applications. The pass reads each generated node with the
48
+ * others, so the rules join it as they join a declared node of its kind, and
49
+ * draws a derived edge from the holder to it. A node a generator made for a
50
+ * cluster registration it selected gets an edge to that registration under
51
+ * the rule's `cluster` id, and no other rule's edge for that pair. {@link placeCatalogPass} adds
52
+ * it to `nodes` with `generatedBy`, and marks the holder with `expansion`:
53
+ * how many it generated and what it did not expand.
54
+ *
55
+ * A generate rule's `files` reads the files a generated node names, when the
56
+ * caller hands the pass `readFile` (#5094): a generated Application's Helm
57
+ * values files become nodes, with the objects under their `extraObjects`,
58
+ * as they do for an Application written by hand. Each is `<holder
59
+ * id>/<key>`, in the holder's member, with `generatedBy` naming the
60
+ * generated node and `generator: "file"`, and the rules read it with the
61
+ * rest.
62
+ *
63
+ * A catalog's `pathRefs` rules read the paths in a repository a node names.
64
+ * The caller says, through `lookPath`, whether each is in the workspace's
65
+ * repository; one that is not there, or is a file where a directory is
66
+ * named, goes in `dangling`. A path in another repository is not read. On a
67
+ * generated node the entry names the holder as `through` and the cluster
68
+ * registration the node was made for as `cluster`.
69
+ *
70
+ * ## Detail tiers
71
+ *
72
+ * The pass reads every node with its full attributes, whatever `--detail` the
73
+ * document is printed at. At T1 and T0 an edge, a dangling holder and the
74
+ * candidates move to the node they are drawn as ({@link detailIdMap}), and an
75
+ * edge both of whose ends land on one node is dropped, as T1 drops an edge
76
+ * inside a composite.
77
+ *
78
+ * Pure.
79
+ */
80
+ import { type ContainmentPair, type RepoPathRef, type NamedCatalog } from "../graph-refs.js";
81
+ import { type DetailLevel } from "../graph-detail.js";
82
+ import type { CatalogRuleEntry, ComposedAmbiguous, ComposedDangling, ComposedEdge, ComposedNode, NodeExpansion, WorkspaceGraph } from "./compose-graph.js";
83
+ /** The scope every node of a declared workspace graph sits in. */
84
+ export declare const WORKSPACE_SCOPE = "workspace";
85
+ /** What the catalog pass found, on the ids of the nodes it read. */
86
+ export interface CatalogPass {
87
+ edges: ComposedEdge[];
88
+ containment: ContainmentPair[];
89
+ dangling: ComposedDangling[];
90
+ ambiguous: ComposedAmbiguous[];
91
+ /** By node id: arguments left unread because they are not literal. */
92
+ nonLiteral: Record<string, number>;
93
+ /** Every rule of the catalogs, by rule id. */
94
+ rules: Record<string, CatalogRuleEntry>;
95
+ lexicons: string[];
96
+ members: string[];
97
+ /** Nodes a catalog's `sharedNodes` added (#5100), with their ids as the document gives them. */
98
+ shared: ComposedNode[];
99
+ /** The nodes the catalogs' `generates` rules made (#5102), as the pass read them, each with `generatedBy`. */
100
+ generated: ComposedNode[];
101
+ /** By holder id: what a `generates` rule made of it. */
102
+ expansions: Record<string, NodeExpansion>;
103
+ }
104
+ /** The text of a workspace-relative file in the workspace's repository, or undefined when it is not there (#5094). */
105
+ export type ReadFile = (path: string) => string | undefined;
106
+ /** Whether a repository path is in the workspace's repository: what it is there, `missing`, or undefined when the path is in another repository and is not read. */
107
+ export type LookPath = (ref: RepoPathRef) => "dir" | "file" | "missing" | undefined;
108
+ /** Each rule of the catalogs by id. Rules that share an id (one per target kind) share an entry. */
109
+ export declare function catalogRules(catalogs: readonly NamedCatalog[]): Record<string, CatalogRuleEntry>;
110
+ /**
111
+ * Run the catalogs over composed nodes, each read with its full attributes.
112
+ * Rules apply to nodes of their own lexicon; targets can be any node.
113
+ * `members` names the members read, the nodes' own members by default.
114
+ * `lookPath` finds a path rule's paths in the repository; without it no path
115
+ * is read. `readFile` reads a file a generated node names (#5094); without
116
+ * it no such file is read.
117
+ */
118
+ export declare function runCatalogPass(nodes: readonly ComposedNode[], catalogs: readonly NamedCatalog[], members?: readonly string[], lookPath?: LookPath, readFile?: ReadFile): CatalogPass;
119
+ /**
120
+ * Write a pass into the document. `placed` maps an id the pass read to the
121
+ * id of the node the document draws it as at its detail tier; an id it does
122
+ * not hold is kept as it is, except a generated node's, which is drawn where
123
+ * its holder is (a node read from a generated node's file, where that node is). A generated node goes in `nodes` when its holder is drawn
124
+ * as itself, with its attrs as `level` prints them.
125
+ */
126
+ export declare function placeCatalogPass(graph: WorkspaceGraph, pass: CatalogPass, placed?: ReadonlyMap<string, string>, level?: DetailLevel): void;
127
+ /** What a member's declared `runsOn` drew (#5101). */
128
+ export interface RunsOnEdges {
129
+ /** One declared edge from each cluster registration of the member to the node `runsOn` names. */
130
+ edges: ComposedEdge[];
131
+ /** The registrations an edge was drawn from, so their unmatched references are not reported. */
132
+ joined: Set<string>;
133
+ /** A `runsOn` that drew nothing, and why. */
134
+ problems: string[];
135
+ }
136
+ /**
137
+ * The declared mapping from a cluster's registration to the cluster resource
138
+ * (#5101), for a repo whose names do not match: a member's `runsOn`,
139
+ * `<member>/<address>`, names the node the member runs on, by the member that
140
+ * holds it and its address (the node's id without the member, or an
141
+ * `attrs.address`). Each node of the member that its lexicon's
142
+ * `registersCluster` accepts draws one `declared` edge to it. A target that
143
+ * matches no node or several, a member with nothing that registers a cluster,
144
+ * and a target in the member itself are problems that draw no edge.
145
+ */
146
+ export declare function runsOnEdges(nodes: readonly ComposedNode[], runsOn: ReadonlyMap<string, string>, catalogs: readonly NamedCatalog[]): RunsOnEdges;
147
+ //# sourceMappingURL=catalog-edges.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog-edges.d.ts","sourceRoot":"","sources":["../../src/workspace/catalog-edges.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8EG;AAEH,OAAO,EAML,KAAK,eAAe,EAEpB,KAAK,WAAW,EAEhB,KAAK,YAAY,EAClB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,KAAK,EACV,gBAAgB,EAEhB,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,cAAc,EACf,MAAM,iBAAiB,CAAC;AAGzB,kEAAkE;AAClE,eAAO,MAAM,eAAe,cAAc,CAAC;AAE3C,oEAAoE;AACpE,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,WAAW,EAAE,eAAe,EAAE,CAAC;IAC/B,QAAQ,EAAE,gBAAgB,EAAE,CAAC;IAC7B,SAAS,EAAE,iBAAiB,EAAE,CAAC;IAC/B,sEAAsE;IACtE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,8CAA8C;IAC9C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IACxC,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,gGAAgG;IAChG,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,8GAA8G;IAC9G,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B,wDAAwD;IACxD,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CAC3C;AAED,sHAAsH;AACtH,MAAM,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;AAE5D,oKAAoK;AACpK,MAAM,MAAM,QAAQ,GAAG,CAAC,GAAG,EAAE,WAAW,KAAK,KAAK,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC;AAIpF,oGAAoG;AACpG,wBAAgB,YAAY,CAAC,QAAQ,EAAE,SAAS,YAAY,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAyBhG;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,YAAY,EAAE,EAAE,QAAQ,EAAE,SAAS,YAAY,EAAE,EAAE,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,EAAE,QAAQ,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,WAAW,CAiJpL;AAgCD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,GAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAa,EAAE,KAAK,GAAE,WAAe,GAAG,IAAI,CA6ExJ;AAwBD,sDAAsD;AACtD,MAAM,WAAW,WAAW;IAC1B,iGAAiG;IACjG,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,gGAAgG;IAChG,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACpB,6CAA6C;IAC7C,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,YAAY,EAAE,EAAE,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE,SAAS,YAAY,EAAE,GAAG,WAAW,CA4B/I"}
@@ -0,0 +1,461 @@
1
+ /**
2
+ * The reference catalog over a composed workspace graph (#5097, phase 3 of
3
+ * INTENTIUS/behold#1049).
4
+ *
5
+ * Each lexicon's `referenceCatalog` says how its resources name each other.
6
+ * It ran over a live read and over a cloud index (#4522), never over the
7
+ * declared graph `chant workspace graph` composes, so no edge went from one
8
+ * member to another except through links. {@link runCatalogPass} runs
9
+ * `reconstructIndexedEdges` (../graph-refs.ts) over every composed node, and
10
+ * {@link placeCatalogPass} writes what it found into the document:
11
+ *
12
+ * - each edge it draws goes in `edges` with `origin: "derived"`, the `rule`
13
+ * that drew it, its `relation` and `grain: "property"`, and the holder's
14
+ * `member`. A pair the declared graph already joins gets no second edge;
15
+ * - a reference that names no node goes in `dangling`, with its `rule` and
16
+ * the `targetKind` the rule looks for;
17
+ * - a reference that names more than one node draws no edge and goes in
18
+ * `ambiguous` with every candidate;
19
+ * - `catalog` names the lexicons whose catalog ran, the members read, each
20
+ * rule the document names, and per node the arguments it could not read.
21
+ *
22
+ * ## Scopes
23
+ *
24
+ * A Kubernetes name is unique inside its namespace, while a rule from a
25
+ * Kubernetes object to a cloud resource has to reach a node of another
26
+ * member. The pass keeps one scope per node and uses the index's two-level
27
+ * lookup for both: every node sits in the workspace, and a node of a kind its
28
+ * catalog lists in `scopes` also sits in the scope that kind names, its
29
+ * namespace. A holder in a namespace reaches the nodes of that namespace in
30
+ * any member, and every node that has no namespace. A holder with no
31
+ * namespace reaches only nodes with none. One of those kinds whose node names
32
+ * no namespace sits in a scope of its own member, since chant cannot tell
33
+ * where it will be applied, and the objects one member applies together go to
34
+ * one namespace far more often than not.
35
+ *
36
+ * ## Declared nodes the rules are not written against
37
+ *
38
+ * A catalog's `declaredNode` gives the node the rules read, for a lexicon
39
+ * whose declared nodes are not shaped like its rules: terraform's are all
40
+ * `Terraform::Resource`, with their arguments under `body`. An instance node
41
+ * is handed its block node too, since its attrs stay on the block (#5117).
42
+ * The view is read for this pass only; the document's nodes are unchanged.
43
+ *
44
+ * ## Generated nodes and repository paths (#5102)
45
+ *
46
+ * A catalog's `generates` rules make nodes from a node: an ApplicationSet's
47
+ * generators yield Applications. The pass reads each generated node with the
48
+ * others, so the rules join it as they join a declared node of its kind, and
49
+ * draws a derived edge from the holder to it. A node a generator made for a
50
+ * cluster registration it selected gets an edge to that registration under
51
+ * the rule's `cluster` id, and no other rule's edge for that pair. {@link placeCatalogPass} adds
52
+ * it to `nodes` with `generatedBy`, and marks the holder with `expansion`:
53
+ * how many it generated and what it did not expand.
54
+ *
55
+ * A generate rule's `files` reads the files a generated node names, when the
56
+ * caller hands the pass `readFile` (#5094): a generated Application's Helm
57
+ * values files become nodes, with the objects under their `extraObjects`,
58
+ * as they do for an Application written by hand. Each is `<holder
59
+ * id>/<key>`, in the holder's member, with `generatedBy` naming the
60
+ * generated node and `generator: "file"`, and the rules read it with the
61
+ * rest.
62
+ *
63
+ * A catalog's `pathRefs` rules read the paths in a repository a node names.
64
+ * The caller says, through `lookPath`, whether each is in the workspace's
65
+ * repository; one that is not there, or is a file where a directory is
66
+ * named, goes in `dangling`. A path in another repository is not read. On a
67
+ * generated node the entry names the holder as `through` and the cluster
68
+ * registration the node was made for as `cluster`.
69
+ *
70
+ * ## Detail tiers
71
+ *
72
+ * The pass reads every node with its full attributes, whatever `--detail` the
73
+ * document is printed at. At T1 and T0 an edge, a dangling holder and the
74
+ * candidates move to the node they are drawn as ({@link detailIdMap}), and an
75
+ * edge both of whose ends land on one node is dropped, as T1 drops an edge
76
+ * inside a composite.
77
+ *
78
+ * Pure.
79
+ */
80
+ import { containmentGroups, memberRegion, reconstructIndexedEdges, readPath, refRuleId, } from "../graph-refs.js";
81
+ import { nodeAttrsAt } from "../graph-detail.js";
82
+ import { composedId, danglingKey } from "./compose-graph.js";
83
+ /** The scope every node of a declared workspace graph sits in. */
84
+ export const WORKSPACE_SCOPE = "workspace";
85
+ const byString = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
86
+ /** Each rule of the catalogs by id. Rules that share an id (one per target kind) share an entry. */
87
+ export function catalogRules(catalogs) {
88
+ const out = {};
89
+ const add = (id, entry, targetKind) => {
90
+ const prev = out[id];
91
+ const kinds = new Set(prev?.targetKinds ?? []);
92
+ if (targetKind !== undefined)
93
+ kinds.add(targetKind);
94
+ out[id] = { ...entry, ...(prev?.label !== undefined && entry.label === undefined ? { label: prev.label } : {}), targetKinds: [...kinds].sort(byString) };
95
+ };
96
+ for (const { lexicon, catalog } of catalogs) {
97
+ for (const r of catalog.refs) {
98
+ add(refRuleId(lexicon, r.from, r.path), { lexicon, from: r.from, path: r.path, relation: r.relation, ...(r.label ? { label: r.label } : {}) }, r.targetKind ?? r.indexedTargetKind);
99
+ }
100
+ for (const g of catalog.generates ?? []) {
101
+ add(refRuleId(lexicon, g.from, g.path), { lexicon, from: g.from, path: g.path, relation: "reference", ...(g.label ? { label: g.label } : {}) }, g.targetKind);
102
+ if (g.cluster)
103
+ add(refRuleId(lexicon, g.from, g.cluster.path), { lexicon, from: g.from, path: g.cluster.path, relation: "reference", ...(g.cluster.label ? { label: g.cluster.label } : {}) }, g.cluster.targetKind);
104
+ }
105
+ for (const p of catalog.pathRefs ?? []) {
106
+ add(refRuleId(lexicon, p.from, p.path), { lexicon, from: p.from, path: p.path, relation: "reference", ...(p.label ? { label: p.label } : {}) }, undefined);
107
+ }
108
+ for (const t of catalog.tagRefs ?? []) {
109
+ const from = t.from ?? "*";
110
+ add(refRuleId(lexicon, from, `tag:${t.key}`), { lexicon, from, path: `tag:${t.key}`, relation: "reference", ...(t.label ? { label: t.label } : {}) }, t.targetKind);
111
+ }
112
+ }
113
+ return out;
114
+ }
115
+ /**
116
+ * Run the catalogs over composed nodes, each read with its full attributes.
117
+ * Rules apply to nodes of their own lexicon; targets can be any node.
118
+ * `members` names the members read, the nodes' own members by default.
119
+ * `lookPath` finds a path rule's paths in the repository; without it no path
120
+ * is read. `readFile` reads a file a generated node names (#5094); without
121
+ * it no such file is read.
122
+ */
123
+ export function runCatalogPass(nodes, catalogs, members, lookPath, readFile) {
124
+ const byLexicon = new Map(catalogs.map((c) => [c.lexicon, c.catalog]));
125
+ const nonLiteral = {};
126
+ const byId = new Map(nodes.map((n) => [n.id, n]));
127
+ const read = nodes.map((n) => {
128
+ const view = byLexicon.get(n.lexicon)?.declaredNode?.(n, n.instanceOf !== undefined ? byId.get(n.instanceOf) : undefined);
129
+ if (!view)
130
+ return n;
131
+ if (view.nonLiteral > 0)
132
+ nonLiteral[n.id] = view.nonLiteral;
133
+ return { ...n, kind: view.kind, attrs: view.attrs };
134
+ });
135
+ // Generated nodes (#5102), made from the nodes as the rules read them.
136
+ const generated = [];
137
+ const expansions = {};
138
+ const generatedEdges = [];
139
+ // A generated node's cluster registration, when its generator selected one: another rule's edge to it is left out.
140
+ const selectedFor = new Map();
141
+ const withFiles = [];
142
+ for (const holder of read) {
143
+ for (const rule of byLexicon.get(holder.lexicon)?.generates ?? []) {
144
+ if (rule.from !== holder.kind)
145
+ continue;
146
+ const id = refRuleId(holder.lexicon, rule.from, rule.path);
147
+ const made = rule.generate(holder, read);
148
+ let count = 0;
149
+ for (const g of made.nodes) {
150
+ const nodeId = `${holder.id}/${g.key}`;
151
+ if (byId.has(nodeId) || generated.some((n) => n.id === nodeId))
152
+ continue;
153
+ count++;
154
+ const node = {
155
+ id: nodeId,
156
+ kind: g.kind,
157
+ lexicon: holder.lexicon,
158
+ attrs: g.attrs,
159
+ member: holder.member,
160
+ ...(holder.nested !== undefined ? { nested: holder.nested } : {}),
161
+ generatedBy: { node: holder.id, rule: id, generator: g.generator, params: g.params, ...(g.cluster ? { cluster: g.cluster.id } : {}) },
162
+ };
163
+ generated.push(node);
164
+ if (rule.files && readFile)
165
+ withFiles.push({ rule, ruleId: id, holder, node });
166
+ generatedEdges.push({ from: holder.id, to: nodeId, kind: "ref", viaAttr: refViaAttr(rule.path), grain: "property", origin: "derived", rule: id, relation: "reference", member: holder.member });
167
+ if (g.cluster && rule.cluster) {
168
+ const clusterRule = refRuleId(holder.lexicon, rule.from, rule.cluster.path);
169
+ generatedEdges.push({ from: nodeId, to: g.cluster.id, kind: "ref", viaAttr: "generatedBy", grain: "property", origin: "derived", rule: clusterRule, relation: "reference", member: holder.member });
170
+ selectedFor.set(nodeId, g.cluster.id);
171
+ }
172
+ }
173
+ expansions[holder.id] = { rule: id, generated: count, notExpanded: made.notExpanded };
174
+ }
175
+ }
176
+ read.push(...generated);
177
+ // The files a generated node names (#5094): its values files and their objects, one node per file under the holder.
178
+ const fromFiles = [];
179
+ const fileIds = new Set();
180
+ for (const { rule, ruleId, holder, node } of withFiles) {
181
+ for (const f of rule.files(node, readFile, read)) {
182
+ const id = `${holder.id}/${f.key}`;
183
+ if (byId.has(id) || fileIds.has(id))
184
+ continue;
185
+ fileIds.add(id);
186
+ fromFiles.push({
187
+ id,
188
+ kind: f.kind,
189
+ lexicon: f.lexicon,
190
+ attrs: f.attrs,
191
+ member: holder.member,
192
+ ...(holder.nested !== undefined ? { nested: holder.nested } : {}),
193
+ generatedBy: { node: node.id, rule: ruleId, generator: "file", params: {} },
194
+ });
195
+ }
196
+ }
197
+ generated.push(...fromFiles);
198
+ read.push(...fromFiles);
199
+ const member = new Map(read.map((n) => [n.id, n.member]));
200
+ // A kind a catalog scopes is looked up by its own kind alone: the lexicon that wrote the node is not the catalog's (a values file read by the k8s reader is a helm node).
201
+ const scopePath = new Map();
202
+ for (const { catalog } of catalogs)
203
+ for (const r of catalog.scopes ?? [])
204
+ scopePath.set(r.kind, r.path ?? null);
205
+ const scopeOf = (n) => {
206
+ // Every holder also reaches the nodes its own member holds with no other scope (`member`).
207
+ if (!scopePath.has(n.kind))
208
+ return { account: WORKSPACE_SCOPE, member: n.member };
209
+ const path = scopePath.get(n.kind);
210
+ // A kind scoped with no path is held by its member alone, whichever lexicon the member's other nodes are of.
211
+ if (path === null)
212
+ return { account: WORKSPACE_SCOPE, region: memberRegion(n.member), member: n.member };
213
+ const named = readPath(n.attrs, path).find((v) => v !== "");
214
+ return { account: WORKSPACE_SCOPE, region: named !== undefined ? `${n.lexicon}:${named}` : `${n.lexicon}@${n.member}`, member: n.member };
215
+ };
216
+ const scopes = new Map(read.map((n) => [n.id, scopeOf(n)]));
217
+ // Nodes that no member owns (#5100): placed in the member of the first holder, with an edge to each from every holder.
218
+ const shared = [];
219
+ const sharedEdges = [];
220
+ const sharedRules = {};
221
+ const kindOf = new Map(read.map((n) => [n.id, n.kind]));
222
+ for (const { lexicon, catalog } of catalogs) {
223
+ for (const s of catalog.sharedNodes?.(read) ?? []) {
224
+ const holders = [...s.holders].sort((a, b) => byString(a.from, b.from));
225
+ if (holders.length === 0)
226
+ continue;
227
+ const owner = member.get(holders[0].from);
228
+ if (owner === undefined)
229
+ continue;
230
+ const id = composedId(owner, s.id);
231
+ shared.push({ id, kind: s.kind, lexicon, attrs: s.attrs, member: owner });
232
+ member.set(id, owner);
233
+ for (const h of holders) {
234
+ const from = kindOf.get(h.from);
235
+ if (from === undefined || h.from === id)
236
+ continue;
237
+ const rule = refRuleId(lexicon, from, h.via);
238
+ const prev = sharedRules[rule];
239
+ const label = h.label ?? prev?.label;
240
+ sharedRules[rule] = {
241
+ lexicon,
242
+ from,
243
+ path: h.via,
244
+ relation: "reference",
245
+ targetKinds: [...new Set([...(prev?.targetKinds ?? []), s.kind])].sort(byString),
246
+ ...(label ? { label } : {}),
247
+ };
248
+ sharedEdges.push({ from: h.from, to: id, kind: "ref", viaAttr: h.via, grain: "property", origin: "derived", rule, relation: "reference", member: member.get(h.from) });
249
+ }
250
+ }
251
+ }
252
+ const found = reconstructIndexedEdges([...read, ...shared], catalogs, (n) => scopes.get(n.id) ?? { account: WORKSPACE_SCOPE, member: member.get(n.id) });
253
+ const memberOf = (id) => member.get(id);
254
+ return {
255
+ shared,
256
+ edges: [...generatedEdges, ...found.edges.filter((e) => selectedFor.get(e.from) !== e.to).map((e) => ({ ...e, member: memberOf(e.from) })), ...sharedEdges],
257
+ containment: found.containment,
258
+ dangling: [...pathDangling(read, byLexicon, lookPath), ...found.dangling.map((d) => ({
259
+ from: d.from,
260
+ kind: "ref",
261
+ path: d.path,
262
+ value: d.value,
263
+ member: memberOf(d.from),
264
+ rule: d.rule,
265
+ ...(d.targetKind ? { targetKind: d.targetKind } : {}),
266
+ ...(d.through ? { through: d.through } : {}),
267
+ }))],
268
+ ambiguous: found.ambiguous.map((a) => ({ from: a.from, member: memberOf(a.from), rule: a.rule, path: a.path, value: a.value, candidates: a.candidates })),
269
+ nonLiteral,
270
+ rules: { ...catalogRules(catalogs), ...sharedRules },
271
+ lexicons: catalogs.map((c) => c.lexicon).sort(byString),
272
+ members: [...new Set(members ?? read.map((n) => n.member))].sort(byString),
273
+ generated,
274
+ expansions,
275
+ };
276
+ }
277
+ /** A rule path's first step, the `viaAttr` an edge it draws carries, as the pass's own rules do. */
278
+ const refViaAttr = (path) => path.split(/[.[]/)[0] || path;
279
+ /** The repository paths the nodes name that `lookPath` does not find (#5102). */
280
+ function pathDangling(nodes, byLexicon, lookPath) {
281
+ if (!lookPath)
282
+ return [];
283
+ const out = new Map();
284
+ for (const node of nodes) {
285
+ for (const rule of byLexicon.get(node.lexicon)?.pathRefs ?? []) {
286
+ if (rule.from !== node.kind)
287
+ continue;
288
+ const id = refRuleId(node.lexicon, rule.from, rule.path);
289
+ for (const ref of rule.read(node)) {
290
+ const there = lookPath(ref);
291
+ if (there === undefined || there === ref.type)
292
+ continue;
293
+ const by = node.generatedBy;
294
+ out.set(`${node.id}\u0000${id}\u0000${ref.value}`, {
295
+ from: node.id,
296
+ kind: "ref",
297
+ path: rule.path,
298
+ value: ref.value,
299
+ member: node.member,
300
+ rule: id,
301
+ ...(by ? { through: by.node, ...(by.cluster ? { cluster: by.cluster } : {}) } : {}),
302
+ });
303
+ }
304
+ }
305
+ }
306
+ return [...out.values()];
307
+ }
308
+ /**
309
+ * Write a pass into the document. `placed` maps an id the pass read to the
310
+ * id of the node the document draws it as at its detail tier; an id it does
311
+ * not hold is kept as it is, except a generated node's, which is drawn where
312
+ * its holder is (a node read from a generated node's file, where that node is). A generated node goes in `nodes` when its holder is drawn
313
+ * as itself, with its attrs as `level` prints them.
314
+ */
315
+ export function placeCatalogPass(graph, pass, placed = new Map(), level = 3) {
316
+ var _a, _b, _c, _d, _e;
317
+ const holderOf = new Map(pass.generated.map((n) => [n.id, n.generatedBy.node]));
318
+ // A node read from a generated node's file (#5094) has that node as its holder, so the walk goes up to a node the document holds.
319
+ const at = (id, depth = 0) => {
320
+ const holder = holderOf.get(id);
321
+ if (holder === undefined || depth > 4)
322
+ return placed.get(id) ?? id;
323
+ const drawn = at(holder, depth + 1);
324
+ return drawn === holder ? id : drawn;
325
+ };
326
+ addGenerated(graph, pass, at, level);
327
+ if (pass.shared.length > 0) {
328
+ const have = new Set(graph.nodes.map((n) => n.id));
329
+ const added = pass.shared.filter((n) => !have.has(n.id));
330
+ graph.nodes = [...graph.nodes, ...added].sort((a, b) => byString(a.id, b.id));
331
+ for (const n of added) {
332
+ const m = ((_a = graph.groups.byMember)[_b = n.member] ?? (_a[_b] = []));
333
+ m.push(n.id);
334
+ m.sort(byString);
335
+ const l = ((_d = ((_c = graph.groups).byLexicon ?? (_c.byLexicon = {})))[_e = n.lexicon] ?? (_d[_e] = []));
336
+ l.push(n.id);
337
+ l.sort(byString);
338
+ }
339
+ }
340
+ const joined = new Set(graph.edges.map((e) => `${e.from}\u0000${e.to}`));
341
+ const named = new Set();
342
+ const edges = new Map();
343
+ for (const e of pass.edges) {
344
+ const from = at(e.from);
345
+ const to = at(e.to);
346
+ if (from === to || joined.has(`${from}\u0000${to}`))
347
+ continue;
348
+ const key = `${from}\u0000${to}\u0000${e.viaAttr ?? ""}\u0000${e.relation ?? ""}`;
349
+ const prev = edges.get(key);
350
+ if (!prev || byString(e.rule, prev.rule) < 0)
351
+ edges.set(key, { ...e, from, to });
352
+ }
353
+ for (const e of edges.values())
354
+ named.add(e.rule);
355
+ const edgeKey = (e) => `${e.from}\u0000${e.to}\u0000${e.viaAttr ?? ""}`;
356
+ graph.edges = [...graph.edges, ...edges.values()].sort((a, b) => edgeKey(a).localeCompare(edgeKey(b)));
357
+ const dangling = new Map();
358
+ for (const d of graph.dangling ?? [])
359
+ dangling.set(`${danglingKey(d)}\u0000${d.rule ?? ""}\u0000${d.through ?? ""}`, d);
360
+ for (const d of pass.dangling) {
361
+ const moved = { ...d, from: at(d.from), ...(d.through ? { through: at(d.through) } : {}), ...(d.cluster ? { cluster: at(d.cluster) } : {}) };
362
+ dangling.set(`${danglingKey(moved)}\u0000${moved.rule ?? ""}\u0000${moved.through ?? ""}`, moved);
363
+ named.add(d.rule);
364
+ }
365
+ if (dangling.size > 0)
366
+ graph.dangling = [...dangling.values()].sort((a, b) => danglingKey(a).localeCompare(danglingKey(b)) || byString(a.rule ?? "", b.rule ?? "") || byString(a.through ?? "", b.through ?? ""));
367
+ const ambiguous = new Map();
368
+ for (const a of pass.ambiguous) {
369
+ const moved = { ...a, from: at(a.from), candidates: [...new Set(a.candidates.map(at))].sort(byString) };
370
+ ambiguous.set(`${moved.from}\u0000${moved.rule}\u0000${moved.value}`, moved);
371
+ named.add(a.rule);
372
+ }
373
+ const ambiguousKey = (a) => `${a.from}\u0000${a.rule}\u0000${a.value}`;
374
+ if (ambiguous.size > 0)
375
+ graph.ambiguous = [...ambiguous.values()].sort((a, b) => byString(ambiguousKey(a), ambiguousKey(b)));
376
+ // Containment fills the boundary boxes, on the nodes the document draws.
377
+ const pairs = pass.containment
378
+ .map((p) => ({ ...p, child: at(p.child), parent: at(p.parent) }))
379
+ .filter((p) => p.child !== p.parent);
380
+ const byContainer = containmentGroups(pairs);
381
+ if (Object.keys(byContainer).length > 0) {
382
+ const merged = { ...(graph.groups.byContainer ?? {}) };
383
+ for (const [k, v] of Object.entries(byContainer))
384
+ merged[k] = [...new Set([...(merged[k] ?? []), ...v])].sort(byString);
385
+ graph.groups.byContainer = Object.fromEntries(Object.keys(merged).sort(byString).map((k) => [k, merged[k]]));
386
+ }
387
+ const nonLiteral = {};
388
+ for (const [id, n] of Object.entries(pass.nonLiteral))
389
+ nonLiteral[at(id)] = (nonLiteral[at(id)] ?? 0) + n;
390
+ const summary = {
391
+ lexicons: pass.lexicons,
392
+ members: pass.members,
393
+ rules: Object.fromEntries([...named].filter((id) => pass.rules[id]).sort(byString).map((id) => [id, pass.rules[id]])),
394
+ };
395
+ if (Object.keys(nonLiteral).length > 0)
396
+ summary.nonLiteral = Object.fromEntries(Object.keys(nonLiteral).sort(byString).map((k) => [k, nonLiteral[k]]));
397
+ graph.catalog = summary;
398
+ }
399
+ /** The generated nodes whose holder the document draws as itself, and each holder's `expansion` (#5102). */
400
+ function addGenerated(graph, pass, at, level) {
401
+ const byId = new Map(graph.nodes.map((n) => [n.id, n]));
402
+ for (const [holder, expansion] of Object.entries(pass.expansions)) {
403
+ const node = at(holder) === holder ? byId.get(holder) : undefined;
404
+ if (node)
405
+ node.expansion = expansion;
406
+ }
407
+ const added = [];
408
+ for (const n of pass.generated) {
409
+ if (at(n.id) !== n.id || byId.has(n.id))
410
+ continue;
411
+ const by = n.generatedBy;
412
+ added.push({ ...n, attrs: nodeAttrsAt(n.attrs, level), generatedBy: { ...by, ...(by.cluster ? { cluster: at(by.cluster) } : {}) } });
413
+ }
414
+ if (added.length === 0)
415
+ return;
416
+ graph.nodes = [...graph.nodes, ...added].sort((a, b) => a.id.localeCompare(b.id));
417
+ const into = (group, key, id) => (group[key] = [...(group[key] ?? []), id].sort());
418
+ for (const n of added) {
419
+ into(graph.groups.byMember, n.member, n.id);
420
+ if (graph.groups.byLexicon)
421
+ into(graph.groups.byLexicon, n.lexicon, n.id);
422
+ }
423
+ }
424
+ /**
425
+ * The declared mapping from a cluster's registration to the cluster resource
426
+ * (#5101), for a repo whose names do not match: a member's `runsOn`,
427
+ * `<member>/<address>`, names the node the member runs on, by the member that
428
+ * holds it and its address (the node's id without the member, or an
429
+ * `attrs.address`). Each node of the member that its lexicon's
430
+ * `registersCluster` accepts draws one `declared` edge to it. A target that
431
+ * matches no node or several, a member with nothing that registers a cluster,
432
+ * and a target in the member itself are problems that draw no edge.
433
+ */
434
+ export function runsOnEdges(nodes, runsOn, catalogs) {
435
+ const out = { edges: [], joined: new Set(), problems: [] };
436
+ const registers = new Map(catalogs.map((c) => [c.lexicon, c.catalog.registersCluster]));
437
+ for (const [member, target] of [...runsOn].sort((a, b) => byString(a[0], b[0]))) {
438
+ const slash = target.indexOf("/");
439
+ const targetMember = target.slice(0, slash);
440
+ const address = target.slice(slash + 1);
441
+ const matches = nodes.filter((n) => n.member === targetMember && (n.id === `${targetMember}/${address}` || n.id.endsWith(`/${address}`) || n.attrs?.address === address));
442
+ if (matches.length !== 1) {
443
+ out.problems.push(matches.length === 0
444
+ ? `member ${member} runs on ${target}, which matches no node of ${targetMember}; no edge is drawn`
445
+ : `member ${member} runs on ${target}, which matches ${matches.length} nodes (${matches.map((n) => n.id).join(", ")}); no edge is drawn`);
446
+ continue;
447
+ }
448
+ const registrations = nodes.filter((n) => n.member === member && registers.get(n.lexicon)?.(n) === true);
449
+ if (registrations.length === 0) {
450
+ out.problems.push(`member ${member} runs on ${target}, and holds no cluster registration to join to it; no edge is drawn`);
451
+ continue;
452
+ }
453
+ for (const r of registrations) {
454
+ if (r.id === matches[0].id)
455
+ continue;
456
+ out.joined.add(r.id);
457
+ out.edges.push({ from: r.id, to: matches[0].id, kind: "ref", viaAttr: "runsOn", origin: "declared", member });
458
+ }
459
+ }
460
+ return out;
461
+ }