@ttsc/graph 0.16.5 → 0.16.7

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 (83) hide show
  1. package/README.md +22 -0
  2. package/lib/TtscGraphApplication.js +58 -22
  3. package/lib/TtscGraphApplication.js.map +1 -1
  4. package/lib/model/TtscGraphMemory.js +43 -4
  5. package/lib/model/TtscGraphMemory.js.map +1 -1
  6. package/lib/model/loadGraph.js +17 -17
  7. package/lib/server/accessAliases.js +53 -0
  8. package/lib/server/accessAliases.js.map +1 -0
  9. package/lib/server/createServer.js +1490 -657
  10. package/lib/server/createServer.js.map +1 -1
  11. package/lib/server/instructions.js +81 -21
  12. package/lib/server/instructions.js.map +1 -1
  13. package/lib/server/pathPolicy.js +35 -0
  14. package/lib/server/pathPolicy.js.map +1 -0
  15. package/lib/server/resultGuide.js +16 -0
  16. package/lib/server/resultGuide.js.map +1 -0
  17. package/lib/server/runDetails.js +474 -0
  18. package/lib/server/runDetails.js.map +1 -0
  19. package/lib/server/{runIndex.js → runEntrypoints.js} +92 -28
  20. package/lib/server/runEntrypoints.js.map +1 -0
  21. package/lib/server/runLookup.js +246 -0
  22. package/lib/server/runLookup.js.map +1 -0
  23. package/lib/server/runOverview.js +44 -27
  24. package/lib/server/runOverview.js.map +1 -1
  25. package/lib/server/runTour.js +737 -0
  26. package/lib/server/runTour.js.map +1 -0
  27. package/lib/server/runTrace.js +224 -43
  28. package/lib/server/runTrace.js.map +1 -1
  29. package/lib/structures/ITtscGraphDetails.js +3 -0
  30. package/lib/structures/ITtscGraphDetails.js.map +1 -0
  31. package/lib/structures/ITtscGraphEntrypoints.js +3 -0
  32. package/lib/structures/ITtscGraphEntrypoints.js.map +1 -0
  33. package/lib/structures/{ITtscGraphExpand.js → ITtscGraphEscape.js} +1 -1
  34. package/lib/structures/ITtscGraphEscape.js.map +1 -0
  35. package/lib/structures/ITtscGraphLookup.js +3 -0
  36. package/lib/structures/ITtscGraphLookup.js.map +1 -0
  37. package/lib/structures/{ITtscGraphIndex.js → ITtscGraphNext.js} +1 -1
  38. package/lib/structures/ITtscGraphNext.js.map +1 -0
  39. package/lib/structures/{ITtscGraphQuery.js → ITtscGraphTour.js} +1 -1
  40. package/lib/structures/ITtscGraphTour.js.map +1 -0
  41. package/lib/structures/index.js +6 -3
  42. package/lib/structures/index.js.map +1 -1
  43. package/package.json +2 -2
  44. package/src/TtscGraphApplication.ts +70 -30
  45. package/src/model/TtscGraphMemory.ts +46 -4
  46. package/src/server/accessAliases.ts +55 -0
  47. package/src/server/createServer.ts +4 -7
  48. package/src/server/instructions.ts +81 -21
  49. package/src/server/pathPolicy.ts +43 -0
  50. package/src/server/resultGuide.ts +20 -0
  51. package/src/server/runDetails.ts +553 -0
  52. package/src/server/{runIndex.ts → runEntrypoints.ts} +116 -36
  53. package/src/server/runLookup.ts +284 -0
  54. package/src/server/runOverview.ts +59 -31
  55. package/src/server/runTour.ts +881 -0
  56. package/src/server/runTrace.ts +299 -45
  57. package/src/structures/ITtscGraphApplication.ts +75 -56
  58. package/src/structures/ITtscGraphDecorator.ts +12 -14
  59. package/src/structures/ITtscGraphDetails.ts +197 -0
  60. package/src/structures/ITtscGraphEntrypoints.ts +149 -0
  61. package/src/structures/ITtscGraphEscape.ts +49 -0
  62. package/src/structures/ITtscGraphEvidence.ts +5 -8
  63. package/src/structures/ITtscGraphLookup.ts +82 -0
  64. package/src/structures/ITtscGraphNext.ts +23 -0
  65. package/src/structures/ITtscGraphNode.ts +10 -4
  66. package/src/structures/ITtscGraphOverview.ts +41 -18
  67. package/src/structures/ITtscGraphTour.ts +150 -0
  68. package/src/structures/ITtscGraphTrace.ts +93 -13
  69. package/src/structures/TtscGraphNodeKind.ts +2 -2
  70. package/src/structures/index.ts +6 -3
  71. package/lib/server/runExpand.js +0 -177
  72. package/lib/server/runExpand.js.map +0 -1
  73. package/lib/server/runIndex.js.map +0 -1
  74. package/lib/server/runQuery.js +0 -147
  75. package/lib/server/runQuery.js.map +0 -1
  76. package/lib/structures/ITtscGraphExpand.js.map +0 -1
  77. package/lib/structures/ITtscGraphIndex.js.map +0 -1
  78. package/lib/structures/ITtscGraphQuery.js.map +0 -1
  79. package/src/server/runExpand.ts +0 -186
  80. package/src/server/runQuery.ts +0 -150
  81. package/src/structures/ITtscGraphExpand.ts +0 -85
  82. package/src/structures/ITtscGraphIndex.ts +0 -100
  83. package/src/structures/ITtscGraphQuery.ts +0 -49
@@ -1,5 +1,8 @@
1
1
  import { TtscGraphMemory } from "../model/TtscGraphMemory";
2
+ import { ITtscGraphNode } from "../structures/ITtscGraphNode";
2
3
  import { ITtscGraphOverview } from "../structures/ITtscGraphOverview";
4
+ import { isPublicApiNoisePath, isSupportPath } from "./pathPolicy";
5
+ import { resultGuide, resultNext } from "./resultGuide";
3
6
 
4
7
  /** Edges that express nesting/packaging, not code dependency. */
5
8
  const STRUCTURAL_KINDS = new Set<string>(["contains", "exports", "imports"]);
@@ -13,10 +16,10 @@ const STRUCTURAL_KINDS = new Set<string>(["contains", "exports", "imports"]);
13
16
  */
14
17
  export function runOverview(
15
18
  graph: TtscGraphMemory,
16
- props: ITtscGraphOverview.IProps,
19
+ props: ITtscGraphOverview.IRequest,
17
20
  ): ITtscGraphOverview {
18
21
  const aspect = props.aspect ?? "all";
19
- const want = (a: ITtscGraphOverview.IProps["aspect"]): boolean =>
22
+ const want = (a: ITtscGraphOverview.IRequest["aspect"]): boolean =>
20
23
  aspect === "all" || aspect === a;
21
24
 
22
25
  const byKind: Record<string, number> = {};
@@ -27,6 +30,7 @@ export function runOverview(
27
30
  }
28
31
 
29
32
  const result: ITtscGraphOverview = {
33
+ type: "overview",
30
34
  project: graph.project,
31
35
  counts: {
32
36
  files,
@@ -34,6 +38,13 @@ export function runOverview(
34
38
  edges: graph.edges.length,
35
39
  byKind,
36
40
  },
41
+ next: resultNext(
42
+ "answer",
43
+ "Counts, layers, hotspots, and public API are sufficient for broad orientation.",
44
+ ),
45
+ guide: resultGuide(
46
+ "Use counts, layers, hotspots, and public API as a broad orientation map. Do not expand it into file reads unless the user needs exact source body text.",
47
+ ),
37
48
  };
38
49
  if (want("layers")) result.layers = layers(graph);
39
50
  if (want("hotspots")) result.hotspots = hotspots(graph);
@@ -45,7 +56,13 @@ export function runOverview(
45
56
  function layers(graph: TtscGraphMemory): ITtscGraphOverview.ILayer[] {
46
57
  const byDir = new Map<string, { files: Set<string>; exported: number }>();
47
58
  for (const node of graph.nodes) {
48
- if (node.external || node.kind === "file") continue;
59
+ if (
60
+ node.external ||
61
+ node.ignored ||
62
+ node.kind === "file" ||
63
+ isSupportPath(node.file)
64
+ )
65
+ continue;
49
66
  const dir = dirname(node.file);
50
67
  let entry = byDir.get(dir);
51
68
  if (!entry) {
@@ -62,12 +79,12 @@ function layers(graph: TtscGraphMemory): ITtscGraphOverview.ILayer[] {
62
79
  exported: entry.exported,
63
80
  }))
64
81
  .sort((a, b) => b.files - a.files)
65
- .slice(0, 16);
82
+ .slice(0, 10);
66
83
  }
67
84
 
68
85
  /**
69
86
  * The symbols at the center of the dependency graph, ranked by real fan-in and
70
- * fan-out structural `contains`/`exports`/`imports` edges are excluded so the
87
+ * fan-out. Structural `contains`/`exports`/`imports` edges are excluded so the
71
88
  * ranking reflects code dependency, not nesting.
72
89
  */
73
90
  function hotspots(graph: TtscGraphMemory): ITtscGraphOverview.IHotspot[] {
@@ -78,18 +95,21 @@ function hotspots(graph: TtscGraphMemory): ITtscGraphOverview.IHotspot[] {
78
95
  return n;
79
96
  };
80
97
  return graph.nodes
81
- .filter((node) => !node.external && node.kind !== "file")
98
+ .filter(
99
+ (node) =>
100
+ !node.external &&
101
+ !node.ignored &&
102
+ node.kind !== "file" &&
103
+ !isSupportPath(node.file),
104
+ )
82
105
  .map((node) => ({
83
- id: node.id,
84
- name: node.qualifiedName ?? node.name,
85
- kind: node.kind,
86
- file: node.file,
106
+ ...nodeOf(node),
87
107
  fanIn: real(node.id, "in"),
88
108
  fanOut: real(node.id, "out"),
89
109
  }))
90
110
  .filter((h) => h.fanIn + h.fanOut > 0)
91
111
  .sort((a, b) => b.fanIn + b.fanOut - (a.fanIn + a.fanOut))
92
- .slice(0, 15);
112
+ .slice(0, 10);
93
113
  }
94
114
 
95
115
  /** Declaration kinds that make up a meaningful public API surface. */
@@ -102,12 +122,13 @@ const API_KINDS = new Set<string>([
102
122
  ]);
103
123
 
104
124
  /**
105
- * The exported API surface: the exported symbols a consumer of the project would
106
- * use, ranked by how depended-on each is (real fan-in/out, structural edges
107
- * excluded). Ranking by dependency rather than by which file declares the most
108
- * exports surfaces the load-bearing types (a DataSource, a SelectQueryBuilder)
109
- * instead of whichever file bundles the most type aliases; test, typings, and
110
- * generated files are dropped so they cannot crowd the real surface out.
125
+ * The exported API surface: the exported symbols a consumer of the project
126
+ * would use, ranked by how depended-on each is (real fan-in/out, structural
127
+ * edges excluded). Ranking by dependency rather than by which file declares the
128
+ * most exports surfaces the load-bearing types (a DataSource, a
129
+ * SelectQueryBuilder) instead of whichever file bundles the most type aliases;
130
+ * test, typings, and generated files are dropped so they cannot crowd the real
131
+ * surface out.
111
132
  */
112
133
  function publicApi(graph: TtscGraphMemory): ITtscGraphOverview.IPublicApi[] {
113
134
  const degree = (id: string): number => {
@@ -122,29 +143,22 @@ function publicApi(graph: TtscGraphMemory): ITtscGraphOverview.IPublicApi[] {
122
143
  .exported()
123
144
  .filter((node) => API_KINDS.has(node.kind) && !isNoiseFile(node.file))
124
145
  .map((node) => ({
125
- name: node.qualifiedName ?? node.name,
126
- kind: node.kind,
127
- file: node.file,
146
+ node: nodeOf(node),
128
147
  degree: degree(node.id),
129
148
  }))
130
149
  .sort((a, b) => b.degree - a.degree)
131
- .slice(0, 30)
132
- .map(({ name, kind, file }) => ({ name, kind, file }));
150
+ .slice(0, 15)
151
+ .map((ranked) => ranked.node);
133
152
  }
134
153
 
135
154
  /**
136
155
  * A file whose exports are noise for an architecture overview: a test, a
137
- * dependency's bundled `.d.ts`/typings, or generated output. The conventions are
138
- * universal (a `test`/`spec` path, a `typings` file), so excluding them is not
139
- * framework-specific it keeps the API surface to authored, used code.
156
+ * dependency's bundled `.d.ts`/typings, or generated output. The conventions
157
+ * are universal (a `test`/`spec` path, a `typings` file), so excluding them is
158
+ * not framework-specific; it keeps the API surface to authored, used code.
140
159
  */
141
160
  function isNoiseFile(file: string): boolean {
142
- return (
143
- /(^|\/)(test|tests|__tests__|spec|sample|samples)\//.test(file) ||
144
- /\.(test|spec)\.[cm]?tsx?$/.test(file) ||
145
- /(^|\/|\.)typings\.[cm]?ts$/.test(file) ||
146
- /\.d\.[cm]?ts$/.test(file)
147
- );
161
+ return isPublicApiNoisePath(file);
148
162
  }
149
163
 
150
164
  /** The parent directory of a project-relative path (`.` at the root). */
@@ -152,3 +166,17 @@ function dirname(file: string): string {
152
166
  const slash = file.lastIndexOf("/");
153
167
  return slash >= 0 ? file.slice(0, slash) : ".";
154
168
  }
169
+
170
+ /** Stable symbol coordinate shared by overview facets. */
171
+ function nodeOf(node: ITtscGraphNode): ITtscGraphOverview.INode {
172
+ const out: ITtscGraphOverview.INode = {
173
+ id: node.id,
174
+ name: node.qualifiedName ?? node.name,
175
+ kind: node.kind,
176
+ file: node.file,
177
+ };
178
+ if (node.evidence?.startLine !== undefined) {
179
+ out.line = node.evidence.startLine;
180
+ }
181
+ return out;
182
+ }