@amulet-laboratories/astrolabe 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.d.ts ADDED
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Public type surface for @amulet-laboratories/astrolabe.
3
+ *
4
+ * The serialized graph (`AppGraph`) is the durable contract — treat it like an
5
+ * API. `schemaVersion` bumps when its shape changes in a breaking way.
6
+ */
7
+
8
+ /** Canonical node kinds. Adapters map their framework's concepts onto these. */
9
+ export type NodeType =
10
+ | 'entry'
11
+ | 'layout'
12
+ | 'middleware'
13
+ | 'plugin'
14
+ | 'route'
15
+ | 'component'
16
+ | 'lib-component'
17
+ | 'composable'
18
+ | 'store'
19
+ | 'collection'
20
+ | 'server'
21
+ | 'external'
22
+ | 'config'
23
+
24
+ /** Canonical edge kinds — the verbs the graph draws between nodes. */
25
+ export type EdgeKind = 'renders' | 'wraps' | 'guards' | 'uses' | 'queries' | 'fetches' | 'reads'
26
+
27
+ export interface GraphNode {
28
+ id: string
29
+ type: NodeType
30
+ label: string
31
+ /** Repo-relative path, or a shortened package path for library nodes. */
32
+ file?: string
33
+ /** Kind-specific extras: loc, method, props, fields, pkg, group, files, … */
34
+ meta: Record<string, unknown>
35
+ }
36
+
37
+ export interface GraphEdge {
38
+ from: string
39
+ to: string
40
+ kind: EdgeKind
41
+ }
42
+
43
+ export interface Finding {
44
+ id: string
45
+ severity: 'warn' | 'info'
46
+ title: string
47
+ detail: string
48
+ /** Node ids this finding is about. */
49
+ nodes: string[]
50
+ }
51
+
52
+ export interface Dependency {
53
+ name: string
54
+ version: string
55
+ dev: boolean
56
+ }
57
+
58
+ export interface Stack {
59
+ nuxt: string | null
60
+ packageManager: string | null
61
+ node: string | null
62
+ dependencies: Dependency[]
63
+ }
64
+
65
+ /** The shareable project metadata — no absolute-internal or raw-config fields. */
66
+ export interface Project {
67
+ name: string
68
+ description: string
69
+ root: string
70
+ modules: string[]
71
+ stack: Stack
72
+ }
73
+
74
+ export interface Stats {
75
+ files: number
76
+ loc: number
77
+ contentFiles: number
78
+ }
79
+
80
+ /** The serialized graph — what `scan()` resolves to and `renderHtml()` consumes. */
81
+ export interface AppGraph {
82
+ schemaVersion: number
83
+ project: Project
84
+ warnings: string[]
85
+ nodes: GraphNode[]
86
+ edges: GraphEdge[]
87
+ findings: Finding[]
88
+ stats: Stats
89
+ }
90
+
91
+ /** Scan a web app directory into a serialized graph. */
92
+ export function scan(dir: string): Promise<AppGraph>
93
+
94
+ /** Render a scanned graph into the self-contained interactive HTML report. */
95
+ export function renderHtml(graph: AppGraph): string
96
+
97
+ /** The report's views — projections of the one graph. */
98
+ export type ViewName = 'layers' | 'render' | 'data' | 'modules' | 'sitemap' | 'cleanup'
99
+
100
+ /** Render a static SVG of one view — for embedding where JS can't run. */
101
+ export function renderSvg(graph: AppGraph, opts?: { view?: ViewName; group?: boolean }): string
102
+
103
+ export const SCHEMA_VERSION: number
104
+ export const NODE_KINDS: Record<NodeType, { label: string }>
105
+ export const EDGE_KINDS: Record<EdgeKind, string>
106
+
107
+ /** Structural conformance check; returns [] when the graph is well-formed. */
108
+ export function validateGraph(graph: Pick<AppGraph, 'nodes' | 'edges'>): string[]
109
+
110
+ /** The graph builder an adapter writes into before core finalizes it. */
111
+ export class Graph {
112
+ nodes: Map<string, GraphNode>
113
+ edges: Map<string, GraphEdge>
114
+ node(id: string, data: Omit<GraphNode, 'id'> & { meta?: Record<string, unknown> }): GraphNode
115
+ has(id: string): boolean
116
+ edge(from: string, to: string, kind: EdgeKind): void
117
+ serialize(): { nodes: GraphNode[]; edges: GraphEdge[] }
118
+ }
119
+
120
+ /** A framework adapter: recognizes an app and reads it into a canonical graph. */
121
+ export interface Adapter {
122
+ name: string
123
+ detect(dir: string): boolean
124
+ scan(dir: string): Promise<{ project: Project; graph: Graph; warnings: string[] }>
125
+ }
126
+
127
+ export const ADAPTERS: Adapter[]
128
+
129
+ /** The first registered adapter whose `detect()` matches; throws if none do. */
130
+ export function detectAdapter(dir: string): Adapter
131
+
132
+ /** A single node newly flagged (or cleared) by a finding, in a diff. */
133
+ export interface FindingFlag {
134
+ id: string
135
+ title: string
136
+ severity: 'warn' | 'info'
137
+ node: string
138
+ }
139
+
140
+ /** The added/removed sets and stat deltas between two scanned graphs. */
141
+ export interface GraphDiff {
142
+ nodes: { added: GraphNode[]; removed: GraphNode[] }
143
+ edges: { added: GraphEdge[]; removed: GraphEdge[] }
144
+ findings: { added: FindingFlag[]; removed: FindingFlag[] }
145
+ stats: Record<string, number>
146
+ }
147
+
148
+ /** Compare two scanned graphs, base → head. */
149
+ export function diffGraphs(base: AppGraph, head: AppGraph): GraphDiff
150
+
151
+ /** True when nodes, edges and findings are all unchanged. */
152
+ export function isEmptyDiff(diff: GraphDiff): boolean
153
+
154
+ /** A short Markdown summary of a diff — what a PR comment renders. */
155
+ export function formatDiffMarkdown(diff: GraphDiff, opts?: { title?: string }): string
package/src/index.mjs ADDED
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Public API.
3
+ *
4
+ * `scan(dir)` detects which framework the app uses, runs that adapter, and
5
+ * finalizes its graph into the report shape. `renderHtml(graph)` turns that
6
+ * shape into the self-contained interactive page. The canonical schema and the
7
+ * adapter registry are exported for tools that consume the graph or add a
8
+ * framework.
9
+ */
10
+ import { detectAdapter } from './adapters/registry.mjs'
11
+ import { finalize, Graph } from './core/graph.mjs'
12
+ import { SCHEMA_VERSION } from './core/schema.mjs'
13
+
14
+ export { renderHtml } from './core/render.mjs'
15
+ export { renderSvg } from './core/svg.mjs'
16
+ export { Graph }
17
+ export { SCHEMA_VERSION, NODE_KINDS, EDGE_KINDS, validateGraph } from './core/schema.mjs'
18
+ export { ADAPTERS, detectAdapter } from './adapters/registry.mjs'
19
+ export { diffGraphs, isEmptyDiff, formatDiffMarkdown } from './core/diff.mjs'
20
+
21
+ /**
22
+ * Scan a web app at `dir` into a serialized graph:
23
+ * `{ schemaVersion, project, warnings, nodes, edges, findings, stats }`.
24
+ */
25
+ export async function scan(dir) {
26
+ const adapter = detectAdapter(dir)
27
+ const result = await adapter.scan(dir)
28
+ return { schemaVersion: SCHEMA_VERSION, ...finalize(result) }
29
+ }