@g3nomaly/analyze 0.0.0-stage → 0.1.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 (133) hide show
  1. package/LICENSE +95 -0
  2. package/README.md +76 -2
  3. package/dist/THIRD_PARTY_LICENSES.txt +1904 -0
  4. package/dist/api/bundle-builder.d.ts +94 -0
  5. package/dist/api/bundle-cache.d.ts +73 -0
  6. package/dist/api/bundle-loader.d.ts +65 -0
  7. package/dist/api/create-docs.d.ts +91 -0
  8. package/dist/api/embedding.d.ts +41 -0
  9. package/dist/api/errors.d.ts +35 -0
  10. package/dist/api/list.d.ts +106 -0
  11. package/dist/api/options.d.ts +74 -0
  12. package/dist/api/refs.d.ts +136 -0
  13. package/dist/api/scan.d.ts +56 -0
  14. package/dist/api/search.d.ts +132 -0
  15. package/dist/api/services.d.ts +15 -0
  16. package/dist/api/show.d.ts +100 -0
  17. package/dist/api/site-reader.d.ts +19 -0
  18. package/dist/api/site-writer.d.ts +43 -0
  19. package/dist/api/source.d.ts +57 -0
  20. package/dist/api/target.d.ts +12 -0
  21. package/dist/api/template.d.ts +5 -0
  22. package/dist/assets/tree-sitter-c-sharp.wasm +0 -0
  23. package/dist/assets/tree-sitter-c.wasm +0 -0
  24. package/dist/assets/tree-sitter-cpp.wasm +0 -0
  25. package/dist/assets/tree-sitter-go.wasm +0 -0
  26. package/dist/assets/tree-sitter-java.wasm +0 -0
  27. package/dist/assets/tree-sitter-javascript.wasm +0 -0
  28. package/dist/assets/tree-sitter-kotlin.wasm +0 -0
  29. package/dist/assets/tree-sitter-php.wasm +0 -0
  30. package/dist/assets/tree-sitter-python.wasm +0 -0
  31. package/dist/assets/tree-sitter-ruby.wasm +0 -0
  32. package/dist/assets/tree-sitter-rust.wasm +0 -0
  33. package/dist/assets/tree-sitter-scala.wasm +0 -0
  34. package/dist/assets/tree-sitter-tsx.wasm +0 -0
  35. package/dist/assets/tree-sitter-typescript.wasm +0 -0
  36. package/dist/assets/vectors.bin +0 -0
  37. package/dist/assets/vocab.txt +33731 -0
  38. package/dist/cli.js +9317 -0
  39. package/dist/embeddings/abbreviations.d.ts +7 -0
  40. package/dist/embeddings/index-builder.d.ts +12 -0
  41. package/dist/embeddings/index.d.ts +10 -0
  42. package/dist/embeddings/model.d.ts +126 -0
  43. package/dist/embeddings/searcher.d.ts +84 -0
  44. package/dist/embeddings/vectors.d.ts +77 -0
  45. package/dist/embeddings/words.d.ts +46 -0
  46. package/dist/index.d.ts +9 -0
  47. package/dist/index.js +8747 -0
  48. package/dist/model/index.d.ts +788 -0
  49. package/dist/model/registry.d.ts +687 -0
  50. package/dist/query/graph.d.ts +123 -0
  51. package/dist/query/index.d.ts +4 -0
  52. package/dist/query/name-search.d.ts +65 -0
  53. package/dist/query/semantic.d.ts +38 -0
  54. package/dist/query/text.d.ts +22 -0
  55. package/dist/retrieval/describe.d.ts +33 -0
  56. package/dist/retrieval/filter.d.ts +36 -0
  57. package/dist/retrieval/index.d.ts +7 -0
  58. package/dist/retrieval/markdown.d.ts +17 -0
  59. package/dist/retrieval/report.d.ts +291 -0
  60. package/dist/retrieval/resolve.d.ts +31 -0
  61. package/dist/retrieval/retriever.d.ts +105 -0
  62. package/dist/retrieval/summary.d.ts +27 -0
  63. package/dist/scanner/code/doc/clean.d.ts +36 -0
  64. package/dist/scanner/code/doc/index.d.ts +12 -0
  65. package/dist/scanner/code/doc/markdown.d.ts +8 -0
  66. package/dist/scanner/code/doc/python.d.ts +8 -0
  67. package/dist/scanner/code/doc/tagged.d.ts +19 -0
  68. package/dist/scanner/code/doc/types.d.ts +33 -0
  69. package/dist/scanner/code/doc/xml.d.ts +8 -0
  70. package/dist/scanner/code/example.d.ts +57 -0
  71. package/dist/scanner/code/extract.d.ts +113 -0
  72. package/dist/scanner/code/grammar.d.ts +44 -0
  73. package/dist/scanner/code/language.d.ts +183 -0
  74. package/dist/scanner/code/languages/c-family.d.ts +5 -0
  75. package/dist/scanner/code/languages/csharp.d.ts +3 -0
  76. package/dist/scanner/code/languages/ecmascript.d.ts +7 -0
  77. package/dist/scanner/code/languages/go.d.ts +3 -0
  78. package/dist/scanner/code/languages/index.d.ts +33 -0
  79. package/dist/scanner/code/languages/java.d.ts +3 -0
  80. package/dist/scanner/code/languages/kotlin.d.ts +3 -0
  81. package/dist/scanner/code/languages/php.d.ts +3 -0
  82. package/dist/scanner/code/languages/python.d.ts +3 -0
  83. package/dist/scanner/code/languages/ruby.d.ts +3 -0
  84. package/dist/scanner/code/languages/rust.d.ts +3 -0
  85. package/dist/scanner/code/languages/scala.d.ts +3 -0
  86. package/dist/scanner/code/languages/shared.d.ts +36 -0
  87. package/dist/scanner/code/planner.d.ts +107 -0
  88. package/dist/scanner/code/symbols.d.ts +134 -0
  89. package/dist/scanner/code/types.d.ts +126 -0
  90. package/dist/scanner/config.d.ts +42 -0
  91. package/dist/scanner/content.d.ts +73 -0
  92. package/dist/scanner/decisions/parse.d.ts +37 -0
  93. package/dist/scanner/decisions/planner.d.ts +42 -0
  94. package/dist/scanner/docs.d.ts +69 -0
  95. package/dist/scanner/files.d.ts +85 -0
  96. package/dist/scanner/glossary/parse.d.ts +40 -0
  97. package/dist/scanner/glossary/planner.d.ts +49 -0
  98. package/dist/scanner/glossary/terms.d.ts +116 -0
  99. package/dist/scanner/graph/builder.d.ts +114 -0
  100. package/dist/scanner/highlight.d.ts +54 -0
  101. package/dist/scanner/ignore.d.ts +25 -0
  102. package/dist/scanner/index.d.ts +43 -0
  103. package/dist/scanner/markdown/frontmatter.d.ts +24 -0
  104. package/dist/scanner/markdown/links.d.ts +60 -0
  105. package/dist/scanner/markdown/outline.d.ts +35 -0
  106. package/dist/scanner/markdown/renderer.d.ts +63 -0
  107. package/dist/scanner/openapi/planner.d.ts +96 -0
  108. package/dist/scanner/packages.d.ts +28 -0
  109. package/dist/scanner/reporter.d.ts +10 -0
  110. package/dist/scanner/scanner.d.ts +66 -0
  111. package/dist/scanner/schema/definitions.d.ts +79 -0
  112. package/dist/scanner/schema/describe.d.ts +105 -0
  113. package/dist/scanner/schema/planner.d.ts +49 -0
  114. package/dist/scanner/schema/registry.d.ts +68 -0
  115. package/dist/scanner/skills/classify.d.ts +21 -0
  116. package/dist/scanner/skills/layout.d.ts +46 -0
  117. package/dist/scanner/skills/planner.d.ts +61 -0
  118. package/dist/scanner/specs.d.ts +56 -0
  119. package/dist/scanner/sql/catalog.d.ts +98 -0
  120. package/dist/scanner/sql/cursor.d.ts +112 -0
  121. package/dist/scanner/sql/database.d.ts +51 -0
  122. package/dist/scanner/sql/parse.d.ts +122 -0
  123. package/dist/scanner/sql/planner.d.ts +69 -0
  124. package/dist/scanner/sql/query.d.ts +73 -0
  125. package/dist/scanner/sql/registry.d.ts +63 -0
  126. package/dist/scanner/sql/source.d.ts +10 -0
  127. package/dist/scanner/sql/statements.d.ts +42 -0
  128. package/dist/scanner/sql/tokens.d.ts +51 -0
  129. package/dist/scanner/tasks/layout.d.ts +52 -0
  130. package/dist/scanner/tasks/planner.d.ts +130 -0
  131. package/dist/scanner/tasks/schema.d.ts +88 -0
  132. package/dist/scanner/text.d.ts +14 -0
  133. package/package.json +104 -4
@@ -0,0 +1,123 @@
1
+ import { type BundleMeta, type DocsBundle, type Edge, type GraphNode, type NodeType, type NodeRef, type Route, type Section, type SemanticIndex } from '../model';
2
+ /**
3
+ * Tells whether a kind is a row of its entry (`parameter` or `field`) rather than a page or entry of its own.
4
+ *
5
+ * @param kind - Kind of a node, such as `parameter`.
6
+ */
7
+ export declare function isDeclarationKind(kind: NodeType): kind is 'parameter' | 'field';
8
+ /**
9
+ * @brief The bundle as a graph the app can walk: children, routes and edges in both
10
+ * directions. Built once at startup.
11
+ *
12
+ * Holds the bundle's nodes and meta, the semantic index, and lookup tables
13
+ * built from them: child lists, the route of every node, pages by path,
14
+ * entries by `path#hash`, and edges by source and by target. `web/main.tsx`
15
+ * creates it from the embedded bundle and `api/source.ts` from a loaded one.
16
+ * The web app, `retrieval/` and the search functions in `query/` read it.
17
+ *
18
+ * Create one with `new Graph(bundle)`.
19
+ *
20
+ * @property meta - Title, generation time and generator of the bundle.
21
+ * @property semantic - The embedding model and node vectors for search by meaning, when the bundle has them.
22
+ * @property sections - The sections of the bundle, in display order. Some bundles lack `database`, so a walk over every section goes through this list.
23
+ */
24
+ export declare class Graph {
25
+ readonly meta: BundleMeta;
26
+ readonly semantic: SemanticIndex | undefined;
27
+ private readonly nodes;
28
+ private readonly childRefs;
29
+ private readonly routes;
30
+ private readonly pages;
31
+ private readonly anchors;
32
+ private readonly outgoing;
33
+ private readonly incoming;
34
+ readonly sections: readonly {
35
+ readonly slug: Section;
36
+ readonly node: NodeRef;
37
+ }[];
38
+ /**
39
+ * Indexes the nodes and edges of a bundle.
40
+ *
41
+ * @param bundle - Bundle to index, from the embedded data or a loaded file.
42
+ */
43
+ constructor(bundle: DocsBundle);
44
+ /**
45
+ * Returns the node at `ref`, and throws when there is none.
46
+ *
47
+ * @param ref - Index of the node in the bundle.
48
+ */
49
+ node(ref: NodeRef): GraphNode;
50
+ /**
51
+ * Returns the children of a node in display order.
52
+ *
53
+ * @param ref - Index of the parent node.
54
+ */
55
+ children(ref: NodeRef): readonly NodeRef[];
56
+ /**
57
+ * From the section down to the parent of `ref`.
58
+ *
59
+ * @param ref - Index of the node.
60
+ */
61
+ ancestors(ref: NodeRef): NodeRef[];
62
+ /**
63
+ * Returns the route of the page that shows a node, and throws when there is no node at `ref`.
64
+ *
65
+ * @param ref - Index of the node.
66
+ * @returns The route of the page, with the hash of the entry when the node is one.
67
+ */
68
+ route(ref: NodeRef): Route;
69
+ /**
70
+ * The node a location shows: the entry `hash` names on the page at `path`, else that page.
71
+ *
72
+ * @param path - Page path, with or without leading and trailing slashes, such as `code/src/app.ts`.
73
+ * @param hash - Anchor of an entry on that page, such as `symbol:App.run`, without `#`.
74
+ * @returns The node, or `undefined` when the location names none.
75
+ */
76
+ at(path: string, hash?: string): NodeRef | undefined;
77
+ /**
78
+ * Returns the root node of a section, and throws when the bundle lacks it.
79
+ *
80
+ * @param slug - Section slug, such as `code`.
81
+ */
82
+ section(slug: Section): NodeRef;
83
+ /**
84
+ * The section a node is in.
85
+ *
86
+ * @param ref - Index of the node.
87
+ * @returns Index of the section node, or `ref` itself when it is a section.
88
+ */
89
+ sectionOf(ref: NodeRef): NodeRef;
90
+ /**
91
+ * Every node below `ref`, depth first, in display order.
92
+ *
93
+ * @param ref - Index of the node whose descendants are listed.
94
+ */
95
+ descendants(ref: NodeRef): Generator<NodeRef>;
96
+ /**
97
+ * Number of nodes below `ref` whose kind is one of `kinds`.
98
+ *
99
+ * @param ref - Index of the node whose descendants are counted.
100
+ * @param kinds - Kinds to count, such as `table` or `field`.
101
+ */
102
+ count(ref: NodeRef, kinds: ReadonlySet<NodeType>): number;
103
+ /**
104
+ * Returns the edges that start at a node.
105
+ *
106
+ * @param ref - Index of the source node.
107
+ */
108
+ edgesFrom(ref: NodeRef): readonly Edge[];
109
+ /**
110
+ * Returns the edges that end at a node.
111
+ *
112
+ * @param ref - Index of the target node.
113
+ */
114
+ edgesTo(ref: NodeRef): readonly Edge[];
115
+ /**
116
+ * @brief Name of a node as other places refer to it: `Class.method` for a symbol,
117
+ * `Class.method(parameter)` for a parameter, `table.column` for a column,
118
+ * `query(:placeholder)` for a placeholder of a query, the file path for a page.
119
+ *
120
+ * @param ref - Index of the node.
121
+ */
122
+ qualifiedName(ref: NodeRef): string;
123
+ }
@@ -0,0 +1,4 @@
1
+ export { Graph, isDeclarationKind } from './graph';
2
+ export { buildSearchIndex, type SearchEntry, type SearchMatch, search } from './name-search';
3
+ export { embeddingModelName, type MeaningOptions, searchByMeaning, similarNodes } from './semantic';
4
+ export { codeText, firstParagraph, plainText } from './text';
@@ -0,0 +1,65 @@
1
+ import { type NodeRef, type NodeType } from '../model';
2
+ import type { Graph } from './graph';
3
+ /**
4
+ * What search by words knows about one page or entry. Built by `buildSearchIndex`
5
+ * and matched by `search`.
6
+ *
7
+ * @property node - Node the entry is for.
8
+ * @property kind - Kind of that node.
9
+ * @property group - Name of the section the node is in. Results are grouped by it.
10
+ * @property title - Name shown in the results.
11
+ * @property detail - Text shown beside the title, such as a file path.
12
+ * @property haystack - Lowercase text that names the node: its title, the words of its name, the words it replaces.
13
+ * @property place - Lowercase words of `detail`, each with a space in front of it.
14
+ * @property text - Lowercase words that describe the node: its description, its definition, the page.
15
+ * Every word has a space in front of it, so a search can tell the start of a word from its middle.
16
+ * @property member - True for a parameter, field, operation or definition. Such an entry lets a query that keeps
17
+ * to its kind match it; the search box of the site skips it, because the entry of its owner holds its words too.
18
+ */
19
+ export interface SearchEntry {
20
+ readonly node: NodeRef;
21
+ readonly member: boolean;
22
+ readonly kind: NodeType;
23
+ readonly group: string;
24
+ readonly title: string;
25
+ readonly detail: string;
26
+ readonly haystack: string;
27
+ readonly place: string;
28
+ readonly text: string;
29
+ }
30
+ /**
31
+ * One result of a search by words.
32
+ *
33
+ * @property entry - The entry that matched.
34
+ * @property found - `name` when every word of the query is in what names the node. `text` when at least one word is only in what describes it.
35
+ */
36
+ export interface SearchMatch {
37
+ readonly entry: SearchEntry;
38
+ readonly found: 'name' | 'text';
39
+ }
40
+ /**
41
+ * @brief Builds the index for search by words: one entry per file, symbol, glossary term, decision, table,
42
+ * query and task.
43
+ *
44
+ * Folders are not searched. The name and the text of a parameter, field, operation or definition are added to
45
+ * the entry of the nearest ancestor that is none of these, such as its function or its file, so a search for
46
+ * it finds that node. It also gets an entry of its own, marked `member`, for a query that keeps to its kind.
47
+ *
48
+ * @param graph - Graph to index.
49
+ * @returns The entries in display order.
50
+ */
51
+ export declare function buildSearchIndex(graph: Graph): SearchEntry[];
52
+ /**
53
+ * @brief Finds the entries that contain every word of a query.
54
+ *
55
+ * Entries that are named by the words come first: an exact title, then a title
56
+ * that starts with the query, then other names. Entries in a file whose path
57
+ * holds a word follow, then entries that mention a word in their description.
58
+ * A word of the query may be the start of a word of the description.
59
+ *
60
+ * @param index - The index from `buildSearchIndex`.
61
+ * @param query - What the reader typed.
62
+ * @param limit - Most matches to return.
63
+ * @returns The matches, best first.
64
+ */
65
+ export declare function search(index: readonly SearchEntry[], query: string, limit: number): SearchMatch[];
@@ -0,0 +1,38 @@
1
+ import { type SemanticHit } from '../embeddings';
2
+ import { type NodeRef } from '../model';
3
+ import type { Graph } from './graph';
4
+ /**
5
+ * Narrows a search by meaning.
6
+ *
7
+ * @property limit - Most hits to return. Default: the number the search dialog shows.
8
+ * @property accepts - Says which nodes count. Default: every node.
9
+ */
10
+ export interface MeaningOptions {
11
+ readonly limit?: number;
12
+ readonly accepts?: (node: NodeRef) => boolean;
13
+ }
14
+ /**
15
+ * Finds nodes by the meaning of a query, such as the term `Sailing` for the query `ship`.
16
+ *
17
+ * @param graph - Graph to search.
18
+ * @param query - What the reader typed.
19
+ * @param exclude - Nodes that are listed already.
20
+ * @param options - Limit and filter of the search.
21
+ * @returns The closest nodes, best first. Empty for a graph without embeddings.
22
+ */
23
+ export declare function searchByMeaning(graph: Graph, query: string, exclude: ReadonlySet<NodeRef>, options?: MeaningOptions): SemanticHit[];
24
+ /**
25
+ * Finds the nodes whose meaning is closest to that of a node.
26
+ *
27
+ * @param graph - Graph the node is in.
28
+ * @param node - Node to compare with.
29
+ * @returns The closest nodes, best first. Empty for a graph without embeddings.
30
+ */
31
+ export declare function similarNodes(graph: Graph, node: NodeRef): SemanticHit[];
32
+ /**
33
+ * Names the embedding model of a graph.
34
+ *
35
+ * @param graph - Graph to read the model from.
36
+ * @returns The name, or `null` for a graph without embeddings.
37
+ */
38
+ export declare function embeddingModelName(graph: Graph): string | null;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Reduces scanner HTML to the text a reader sees, on one line.
3
+ *
4
+ * @param html - HTML of a description or a page.
5
+ * @returns The text without tags, with whitespace collapsed. Inline tags leave no gap, so `<code>a</code>.` reads `a.`
6
+ */
7
+ export declare function plainText(html: string): string;
8
+ /**
9
+ * Reads source code back out of a highlighted `<pre>` block.
10
+ *
11
+ * @param html - HTML of a signature, an example or a file shown as text.
12
+ * @returns The code with its line breaks, without the highlighting.
13
+ */
14
+ export declare function codeText(html: string): string;
15
+ /**
16
+ * Takes the first paragraph of a description as its summary.
17
+ *
18
+ * @param html - HTML of a description or a page.
19
+ * @param maxLength - Longest summary. A longer paragraph is cut at a word and ends with `...`.
20
+ * @returns The paragraph as plain text, or `''` when the HTML has no paragraph.
21
+ */
22
+ export declare function firstParagraph(html: string, maxLength?: number): string;
@@ -0,0 +1,33 @@
1
+ import { type EdgeKind, type NodeRef } from '../model';
2
+ import { type Graph } from '../query';
3
+ import type { NodeReport, References } from './report';
4
+ /**
5
+ * @brief Which edges of a node to report.
6
+ *
7
+ * @property direction - `in` for links into the node, `out` for links from it, `both` for either.
8
+ * @property kinds - Edge kinds to keep, such as `references`. Empty keeps every kind.
9
+ */
10
+ export interface ReferenceOptions {
11
+ readonly direction: 'in' | 'out' | 'both';
12
+ readonly kinds: readonly EdgeKind[];
13
+ }
14
+ /** The options that keep every edge in both directions. */
15
+ export declare const ALL_REFERENCES: ReferenceOptions;
16
+ /**
17
+ * @brief Lists the edges of a node in both directions. The edges of its parameters
18
+ * and fields count as its own, as on its page.
19
+ *
20
+ * @param graph - Graph the node belongs to.
21
+ * @param node - A page or an entry.
22
+ * @param options - Which edges to keep, by direction and kind.
23
+ * @returns What the node links to and what links to it.
24
+ */
25
+ export declare function referencesOf(graph: Graph, node: NodeRef, options: ReferenceOptions): References;
26
+ /**
27
+ * @brief Builds the full report of a node: everything its page shows, as data.
28
+ *
29
+ * @param graph - Graph the node belongs to.
30
+ * @param node - A page or an entry.
31
+ * @returns The report. Texts are markdown.
32
+ */
33
+ export declare function describeNode(graph: Graph, node: NodeRef): NodeReport;
@@ -0,0 +1,36 @@
1
+ import { type NodeKind, type NodeRef, type Section } from '../model';
2
+ import type { Graph } from '../query';
3
+ /**
4
+ * @brief Which nodes a query looks at. An empty filter accepts every node but the sections.
5
+ *
6
+ * @property kinds - Kinds to match, such as `function` or `field`. Empty matches every kind. A member kind matches its nodes, and the query returns the node each belongs to.
7
+ * @property section - Section the results are in. `null` looks in every section.
8
+ */
9
+ export interface NodeFilter {
10
+ readonly kinds: readonly NodeKind[];
11
+ readonly section: Section | null;
12
+ }
13
+ /** The filter that keeps every node. */
14
+ export declare const NO_FILTER: NodeFilter;
15
+ /**
16
+ * @brief Finds the node a query returns for a matched node: the node itself, or for a parameter, field,
17
+ * operation or definition the nearest ancestor that is none of these, such as the function of a parameter
18
+ * or the file of an operation.
19
+ *
20
+ * @param node - Node that matched, such as a field of a definition.
21
+ * @returns The node to return, such as the OpenAPI file the definition is in.
22
+ */
23
+ export declare function resultOf(graph: Graph, node: NodeRef): NodeRef;
24
+ /**
25
+ * @brief Turns a filter into a test for one node that a query matches against.
26
+ *
27
+ * @returns A function that says whether a node matches. A section never matches. A member node matches by its own kind and by the section of its result.
28
+ */
29
+ export declare function nodeTest(graph: Graph, filter: NodeFilter): (node: NodeRef) => boolean;
30
+ /**
31
+ * @brief Maps matched nodes to the nodes a query returns, each once, in the order first met.
32
+ *
33
+ * @param nodes - Matched nodes, such as the hits of a search.
34
+ * @returns Their results, see `resultOf`.
35
+ */
36
+ export declare function resultsOf(graph: Graph, nodes: readonly NodeRef[]): NodeRef[];
@@ -0,0 +1,7 @@
1
+ export { ALL_REFERENCES, describeNode, type ReferenceOptions, referencesOf } from './describe';
2
+ export { NO_FILTER, type NodeFilter, nodeTest, resultOf, resultsOf } from './filter';
3
+ export { codeBlock, htmlToMarkdown } from './markdown';
4
+ export type { ContentReport, DatabaseObjectReport, DeclarationReport, ForeignKeyReport, NodeReport, NodeSummary, OperationReport, QueryReport, Reference, References, TableReport, TagReport, TaskReport, } from './report';
5
+ export { type Resolution, resolveNode } from './resolve';
6
+ export { Retriever, SEARCH_MODES, type SearchHit, type SearchMode, type SearchOptions } from './retriever';
7
+ export { nodeId, normalizeId, summarize } from './summary';
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @brief Turns scanner HTML back into markdown, for output that is read in a
3
+ * terminal or by a program. Headings, lists, tables and code blocks keep
4
+ * their structure. Links into the site and images are reduced to text.
5
+ *
6
+ * @param html - HTML of a description or a page.
7
+ * @returns Markdown without a trailing line break. `''` for empty HTML.
8
+ */
9
+ export declare function htmlToMarkdown(html: string): string;
10
+ /**
11
+ * @brief Wraps code in a markdown code block that the code itself cannot close.
12
+ *
13
+ * @param code - Source text to wrap.
14
+ * @param language - Display name of its language, such as `TypeScript`, or `null`.
15
+ * @returns The block, or `''` for empty code. The fence is longer than any run of backticks in the code.
16
+ */
17
+ export declare function codeBlock(code: string, language: string | null): string;
@@ -0,0 +1,291 @@
1
+ import type { ApiServer, DocTagKind, EdgeKind, NodeKind, NodeType, PackageRole, QueryEffect, Section, TableIndex, TaskPriority, TaskStatus } from '../model';
2
+ /**
3
+ * @brief What every listing shows of a node.
4
+ *
5
+ * @property id - Route of the node, as in the address of its page: `code/src/app.ts#symbol:App.run`. Every retrieval command takes it where it takes a node.
6
+ * @property kind - Kind of the node, such as `function` or `file`.
7
+ * @property type - Type of the node, such as `method` or `api`, which says what sort of file or symbol it is.
8
+ * @property title - Name as other places refer to it: `App.run`, the title of a page, `3. Use hash routes`.
9
+ * @property note - A short fact that belongs beside the title: the status of a decision, a plan, a phase or a task, the language of a source file, the version of an API, the verb of a query. `''` for other nodes.
10
+ * @property path - Path on disk of the file the node is or is in. For a catalog, the path of its directory. `null` for a section or a folder.
11
+ * @property line - Line of a symbol, a table or a query in its file. `null` for every other node.
12
+ * @property summary - First paragraph of its description, as plain text. A table or a query without a description gets what its SQL states instead: the number of columns and the tables it is connected to, or the tables it reads and writes. `''` for any other node without a description.
13
+ */
14
+ export interface NodeSummary {
15
+ readonly id: string;
16
+ readonly kind: NodeKind;
17
+ readonly type: NodeType;
18
+ readonly title: string;
19
+ readonly note: string;
20
+ readonly path: string | null;
21
+ readonly line: number | null;
22
+ readonly summary: string;
23
+ }
24
+ /**
25
+ * @brief A parameter or a field of a symbol, a parameter of an operation, a property of a definition, a column of a table, or a placeholder or a result column of a query.
26
+ *
27
+ * @property name - Name of the declaration.
28
+ * @property type - Type as text, or `null` when none is written.
29
+ * @property defaultValue - Default value as written, or `null`.
30
+ * @property optional - Whether the declaration may be left out.
31
+ * @property location - Where an operation takes a parameter from: `path`, `query`, `header` or `cookie`. `null` for every other declaration.
32
+ * @property annotations - Further facts about a field, verbatim: annotations in code, constraints of a property or a column, the expression behind a result column.
33
+ * @property column - The table column a placeholder or a result column of a query stands for, as `table.column`. `null` for every other declaration, and when the scan does not have the column.
34
+ * @property description - Markdown.
35
+ */
36
+ export interface DeclarationReport {
37
+ readonly name: string;
38
+ readonly type: string | null;
39
+ readonly defaultValue: string | null;
40
+ readonly optional: boolean;
41
+ readonly location: string | null;
42
+ readonly annotations: readonly string[];
43
+ readonly column: string | null;
44
+ readonly description: string;
45
+ }
46
+ /**
47
+ * @brief One media type of a request body or a response.
48
+ *
49
+ * @property mediaType - Media type, such as `application/json`.
50
+ * @property schema - The schema as a type expression, or `null`.
51
+ */
52
+ export interface ContentReport {
53
+ readonly mediaType: string;
54
+ readonly schema: string | null;
55
+ }
56
+ /**
57
+ * @brief What an operation of an API states beside its parameters.
58
+ *
59
+ * @property method - HTTP method of the operation.
60
+ * @property path - Path template, or the name of a webhook.
61
+ * @property operationId - Id of the operation, as the API document names it.
62
+ * @property tags - Tags of the operation.
63
+ * @property deprecated - Whether the operation is deprecated.
64
+ * @property security - The ways a caller can authenticate.
65
+ * @property requestBody - The request body, or `null`. Holds `required`, the markdown `description` and the `content` media types.
66
+ * @property responses - One entry per response, with its status, markdown `description` and `content` media types.
67
+ */
68
+ export interface OperationReport {
69
+ readonly method: string;
70
+ readonly path: string;
71
+ readonly operationId: string;
72
+ readonly tags: readonly string[];
73
+ readonly deprecated: boolean;
74
+ readonly security: readonly string[];
75
+ readonly requestBody: {
76
+ readonly required: boolean;
77
+ readonly description: string;
78
+ readonly content: readonly ContentReport[];
79
+ } | null;
80
+ readonly responses: readonly {
81
+ readonly status: string;
82
+ readonly description: string;
83
+ readonly content: readonly ContentReport[];
84
+ }[];
85
+ }
86
+ /**
87
+ * @brief A foreign key of a table.
88
+ *
89
+ * @property name - Name of the key.
90
+ * @property columns - Columns of this table in the key.
91
+ * @property table - Name of the referenced table.
92
+ * @property tableId - Id of the referenced table, or `null` when the scan does not have it.
93
+ * @property referencedColumns - Columns of the referenced table.
94
+ * @property onDelete - Action on delete, as the file writes it.
95
+ * @property onUpdate - Action on update, as the file writes it.
96
+ */
97
+ export interface ForeignKeyReport {
98
+ readonly name: string;
99
+ readonly columns: readonly string[];
100
+ readonly table: string;
101
+ readonly tableId: string | null;
102
+ readonly referencedColumns: readonly string[];
103
+ readonly onDelete: string;
104
+ readonly onUpdate: string;
105
+ }
106
+ /**
107
+ * @brief What a table states beside its columns.
108
+ *
109
+ * @property primaryKey - Columns of the primary key.
110
+ * @property foreignKeys - Foreign keys of the table.
111
+ * @property indexes - Indexes of the table.
112
+ * @property constraints - Constraints, as the file writes them.
113
+ * @property options - Table options, as the file writes them.
114
+ */
115
+ export interface TableReport {
116
+ readonly primaryKey: readonly string[];
117
+ readonly foreignKeys: readonly ForeignKeyReport[];
118
+ readonly indexes: readonly TableIndex[];
119
+ readonly constraints: readonly string[];
120
+ readonly options: readonly string[];
121
+ }
122
+ /**
123
+ * @brief A view or a trigger of a database.
124
+ *
125
+ * @property kind - Whether the object is a `view` or a `trigger`.
126
+ * @property name - Name of the object.
127
+ * @property table - The table a trigger fires on. `''` for a view.
128
+ * @property line - Line of the object in its file.
129
+ * @property description - Markdown.
130
+ * @property sql - The SQL of the object, as the file writes it.
131
+ */
132
+ export interface DatabaseObjectReport {
133
+ readonly kind: 'view' | 'trigger';
134
+ readonly name: string;
135
+ readonly table: string;
136
+ readonly line: number;
137
+ readonly description: string;
138
+ readonly sql: string;
139
+ }
140
+ /**
141
+ * @brief What an entry of a query catalog states beside its placeholders and result columns.
142
+ *
143
+ * @property effect - Whether the query reads or changes data.
144
+ * @property verb - The keywords that open the statement, in capitals.
145
+ * @property sql - The SQL as the file writes it.
146
+ * @property tables - The tables the SQL names. Each has its `name`, its `access` (`read` or `write`) and the `tableId` of the table, or `null` when the scan does not have it.
147
+ */
148
+ export interface QueryReport {
149
+ readonly effect: QueryEffect;
150
+ readonly verb: string;
151
+ readonly sql: string;
152
+ readonly tables: readonly {
153
+ readonly name: string;
154
+ readonly access: 'read' | 'write';
155
+ readonly tableId: string | null;
156
+ }[];
157
+ }
158
+ /**
159
+ * @brief A doc comment tag that is not a parameter or a return value, such as `throws`.
160
+ *
161
+ * @property kind - Kind of the tag.
162
+ * @property label - Label to print: the kind, or the original label of an `other` tag.
163
+ * @property subject - What the tag is about, such as the exception type of a `throws` tag, or `null`.
164
+ * @property text - Markdown.
165
+ */
166
+ export interface TagReport {
167
+ readonly kind: DocTagKind;
168
+ readonly label: string;
169
+ readonly subject: string | null;
170
+ readonly text: string;
171
+ }
172
+ /**
173
+ * @brief One edge of the graph, seen from the node a report is about.
174
+ *
175
+ * @property relation - Kind of the edge.
176
+ * @property node - The node at the other end. For a parameter or a field, the symbol that declares it.
177
+ * @property via - Name of the parameter or field the edge starts at, when it does not start at a page or an entry.
178
+ */
179
+ export interface Reference {
180
+ readonly relation: EdgeKind;
181
+ readonly node: NodeSummary;
182
+ readonly via: string | null;
183
+ }
184
+ /**
185
+ * @brief Both directions of the edges of a node.
186
+ *
187
+ * @property linksTo - Edges that start at the node.
188
+ * @property linkedFrom - Edges that end at the node.
189
+ */
190
+ export interface References {
191
+ readonly linksTo: readonly Reference[];
192
+ readonly linkedFrom: readonly Reference[];
193
+ }
194
+ /**
195
+ * @brief Everything the site shows about one node, as data. Texts are markdown.
196
+ *
197
+ * @property section - Section the node is in, or `null`.
198
+ * @property signature - Declaration head of a symbol, or `null`.
199
+ * @property language - Language of a source file or of the file a symbol is in.
200
+ * @property modifiers - Modifiers of a symbol, as the file writes them.
201
+ * @property annotations - Annotations of a symbol, as the file writes them.
202
+ * @property description - Description of a symbol, an operation, a definition or a table, note of a query, definition of a term, text of a decision, frontmatter description of a file.
203
+ * @property body - Content of a file: its markdown, or its text in a code block. The description of an API, the opening comment of a database. `''` for every other node.
204
+ * @property parameters - Parameters of the node, in source order.
205
+ * @property fields - Fields of the node, in source order.
206
+ * @property returns - Return value of a symbol, or `null`. Holds its `type` and its markdown `description`.
207
+ * @property tags - Doc comment tags that are not parameters or return values.
208
+ * @property example - Example of a symbol, or `null`. Holds its `code` and whether it is `documented` or `generated`.
209
+ * @property term - Set for a glossary term: its `group` and the words it `avoid`s.
210
+ * @property decision - Set for a decision: its `number`, `status` and `date`.
211
+ * @property task - Set for a plan, a phase and a task.
212
+ * @property api - Set for an API document: its `version`, `specVersion` and `servers`.
213
+ * @property package - Set for a package: its `name` and `role`, the path of its `manifest`, and its `version` or `null`.
214
+ * @property operation - Set for an operation of an API.
215
+ * @property definition - Set for a schema definition: its `type`, `constraints` and enum `values`, as JSON.
216
+ * @property table - Set for a table.
217
+ * @property objects - Views and triggers of a database. Empty for every other node.
218
+ * @property query - Set for an entry of a query catalog.
219
+ * @property contains - The pages and entries inside the node: files of a folder or a skill, symbols of a file, members of a class, tables of a database, queries of a catalog.
220
+ */
221
+ export interface NodeReport extends NodeSummary, References {
222
+ readonly section: Section | null;
223
+ readonly signature: string | null;
224
+ readonly language: string | null;
225
+ readonly modifiers: readonly string[];
226
+ readonly annotations: readonly string[];
227
+ readonly description: string;
228
+ readonly body: string;
229
+ readonly parameters: readonly DeclarationReport[];
230
+ readonly fields: readonly DeclarationReport[];
231
+ readonly returns: {
232
+ readonly type: string | null;
233
+ readonly description: string;
234
+ } | null;
235
+ readonly tags: readonly TagReport[];
236
+ readonly example: {
237
+ readonly code: string;
238
+ readonly origin: 'documented' | 'generated';
239
+ } | null;
240
+ readonly term: {
241
+ readonly group: string;
242
+ readonly avoid: readonly string[];
243
+ } | null;
244
+ readonly decision: {
245
+ readonly number: string;
246
+ readonly status: string;
247
+ readonly date: string;
248
+ } | null;
249
+ readonly task: TaskReport | null;
250
+ readonly api: {
251
+ readonly version: string;
252
+ readonly specVersion: string;
253
+ readonly servers: readonly ApiServer[];
254
+ } | null;
255
+ readonly package: {
256
+ readonly name: string;
257
+ readonly role: PackageRole;
258
+ readonly manifest: string;
259
+ readonly version: string | null;
260
+ } | null;
261
+ readonly operation: OperationReport | null;
262
+ readonly definition: {
263
+ readonly type: string | null;
264
+ readonly constraints: readonly string[];
265
+ readonly values: readonly string[];
266
+ } | null;
267
+ readonly table: TableReport | null;
268
+ readonly objects: readonly DatabaseObjectReport[];
269
+ readonly query: QueryReport | null;
270
+ readonly contains: readonly NodeSummary[];
271
+ }
272
+ /**
273
+ * @brief Where a plan, a phase or a task of the task tree stands, as `show` reports it.
274
+ *
275
+ * @property id - The id of a task, such as `TASK-006`. `null` for a plan or a phase.
276
+ * @property status - Status of the plan, phase or task.
277
+ * @property priority - Priority of the plan, phase or task.
278
+ * @property dependsOn - Names or ids of what it waits for, as the file writes them.
279
+ * @property package - The package a task changes. `null` for a plan or a phase.
280
+ * @property complexity - From 1 to 5. `null` when a task states none, and for a plan or a phase.
281
+ * @property parallel - Whether the tasks of a phase run side by side. `null` for a plan or a task.
282
+ */
283
+ export interface TaskReport {
284
+ readonly id: string | null;
285
+ readonly status: TaskStatus;
286
+ readonly priority: TaskPriority;
287
+ readonly dependsOn: readonly string[];
288
+ readonly package: string | null;
289
+ readonly complexity: number | null;
290
+ readonly parallel: boolean | null;
291
+ }
@@ -0,0 +1,31 @@
1
+ import { type NodeRef } from '../model';
2
+ import type { Graph } from '../query';
3
+ /**
4
+ * @brief What a reference to a node turned out to name.
5
+ *
6
+ * @property node - The node, when `kind` is `found`.
7
+ * @property candidates - Nodes that fit equally well, when `kind` is `ambiguous`. The caller has to pick one by id.
8
+ */
9
+ export type Resolution = {
10
+ readonly kind: 'found';
11
+ readonly node: NodeRef;
12
+ } | {
13
+ readonly kind: 'ambiguous';
14
+ readonly candidates: readonly NodeRef[];
15
+ } | {
16
+ readonly kind: 'missing';
17
+ };
18
+ /**
19
+ * @brief Finds the node a caller means. The first of these rules that fits any node decides:
20
+ *
21
+ * 1. The text is the id of a node, with or without `#/` in front. An id with the anchor of a heading names its page.
22
+ * 2. The text is the path of a file on disk. The path of a query file names its query.
23
+ * 3. The text is the name of a node, with the same capitals.
24
+ * 4. The text is the name of a node, capitals ignored.
25
+ *
26
+ * @param graph - Graph to search.
27
+ * @param text - An id, a path or a name.
28
+ * @param accepts - Narrows the nodes that count, such as to one kind.
29
+ * @returns The node, the candidates when several fit the deciding rule, or `missing`. A match by name on a parameter, field, operation or definition returns the node it belongs to, see `resultOf`; its id returns the node itself.
30
+ */
31
+ export declare function resolveNode(graph: Graph, text: string, accepts: (node: NodeRef) => boolean): Resolution;