@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.
- package/LICENSE +95 -0
- package/README.md +76 -2
- package/dist/THIRD_PARTY_LICENSES.txt +1904 -0
- package/dist/api/bundle-builder.d.ts +94 -0
- package/dist/api/bundle-cache.d.ts +73 -0
- package/dist/api/bundle-loader.d.ts +65 -0
- package/dist/api/create-docs.d.ts +91 -0
- package/dist/api/embedding.d.ts +41 -0
- package/dist/api/errors.d.ts +35 -0
- package/dist/api/list.d.ts +106 -0
- package/dist/api/options.d.ts +74 -0
- package/dist/api/refs.d.ts +136 -0
- package/dist/api/scan.d.ts +56 -0
- package/dist/api/search.d.ts +132 -0
- package/dist/api/services.d.ts +15 -0
- package/dist/api/show.d.ts +100 -0
- package/dist/api/site-reader.d.ts +19 -0
- package/dist/api/site-writer.d.ts +43 -0
- package/dist/api/source.d.ts +57 -0
- package/dist/api/target.d.ts +12 -0
- package/dist/api/template.d.ts +5 -0
- package/dist/assets/tree-sitter-c-sharp.wasm +0 -0
- package/dist/assets/tree-sitter-c.wasm +0 -0
- package/dist/assets/tree-sitter-cpp.wasm +0 -0
- package/dist/assets/tree-sitter-go.wasm +0 -0
- package/dist/assets/tree-sitter-java.wasm +0 -0
- package/dist/assets/tree-sitter-javascript.wasm +0 -0
- package/dist/assets/tree-sitter-kotlin.wasm +0 -0
- package/dist/assets/tree-sitter-php.wasm +0 -0
- package/dist/assets/tree-sitter-python.wasm +0 -0
- package/dist/assets/tree-sitter-ruby.wasm +0 -0
- package/dist/assets/tree-sitter-rust.wasm +0 -0
- package/dist/assets/tree-sitter-scala.wasm +0 -0
- package/dist/assets/tree-sitter-tsx.wasm +0 -0
- package/dist/assets/tree-sitter-typescript.wasm +0 -0
- package/dist/assets/vectors.bin +0 -0
- package/dist/assets/vocab.txt +33731 -0
- package/dist/cli.js +9317 -0
- package/dist/embeddings/abbreviations.d.ts +7 -0
- package/dist/embeddings/index-builder.d.ts +12 -0
- package/dist/embeddings/index.d.ts +10 -0
- package/dist/embeddings/model.d.ts +126 -0
- package/dist/embeddings/searcher.d.ts +84 -0
- package/dist/embeddings/vectors.d.ts +77 -0
- package/dist/embeddings/words.d.ts +46 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +8747 -0
- package/dist/model/index.d.ts +788 -0
- package/dist/model/registry.d.ts +687 -0
- package/dist/query/graph.d.ts +123 -0
- package/dist/query/index.d.ts +4 -0
- package/dist/query/name-search.d.ts +65 -0
- package/dist/query/semantic.d.ts +38 -0
- package/dist/query/text.d.ts +22 -0
- package/dist/retrieval/describe.d.ts +33 -0
- package/dist/retrieval/filter.d.ts +36 -0
- package/dist/retrieval/index.d.ts +7 -0
- package/dist/retrieval/markdown.d.ts +17 -0
- package/dist/retrieval/report.d.ts +291 -0
- package/dist/retrieval/resolve.d.ts +31 -0
- package/dist/retrieval/retriever.d.ts +105 -0
- package/dist/retrieval/summary.d.ts +27 -0
- package/dist/scanner/code/doc/clean.d.ts +36 -0
- package/dist/scanner/code/doc/index.d.ts +12 -0
- package/dist/scanner/code/doc/markdown.d.ts +8 -0
- package/dist/scanner/code/doc/python.d.ts +8 -0
- package/dist/scanner/code/doc/tagged.d.ts +19 -0
- package/dist/scanner/code/doc/types.d.ts +33 -0
- package/dist/scanner/code/doc/xml.d.ts +8 -0
- package/dist/scanner/code/example.d.ts +57 -0
- package/dist/scanner/code/extract.d.ts +113 -0
- package/dist/scanner/code/grammar.d.ts +44 -0
- package/dist/scanner/code/language.d.ts +183 -0
- package/dist/scanner/code/languages/c-family.d.ts +5 -0
- package/dist/scanner/code/languages/csharp.d.ts +3 -0
- package/dist/scanner/code/languages/ecmascript.d.ts +7 -0
- package/dist/scanner/code/languages/go.d.ts +3 -0
- package/dist/scanner/code/languages/index.d.ts +33 -0
- package/dist/scanner/code/languages/java.d.ts +3 -0
- package/dist/scanner/code/languages/kotlin.d.ts +3 -0
- package/dist/scanner/code/languages/php.d.ts +3 -0
- package/dist/scanner/code/languages/python.d.ts +3 -0
- package/dist/scanner/code/languages/ruby.d.ts +3 -0
- package/dist/scanner/code/languages/rust.d.ts +3 -0
- package/dist/scanner/code/languages/scala.d.ts +3 -0
- package/dist/scanner/code/languages/shared.d.ts +36 -0
- package/dist/scanner/code/planner.d.ts +107 -0
- package/dist/scanner/code/symbols.d.ts +134 -0
- package/dist/scanner/code/types.d.ts +126 -0
- package/dist/scanner/config.d.ts +42 -0
- package/dist/scanner/content.d.ts +73 -0
- package/dist/scanner/decisions/parse.d.ts +37 -0
- package/dist/scanner/decisions/planner.d.ts +42 -0
- package/dist/scanner/docs.d.ts +69 -0
- package/dist/scanner/files.d.ts +85 -0
- package/dist/scanner/glossary/parse.d.ts +40 -0
- package/dist/scanner/glossary/planner.d.ts +49 -0
- package/dist/scanner/glossary/terms.d.ts +116 -0
- package/dist/scanner/graph/builder.d.ts +114 -0
- package/dist/scanner/highlight.d.ts +54 -0
- package/dist/scanner/ignore.d.ts +25 -0
- package/dist/scanner/index.d.ts +43 -0
- package/dist/scanner/markdown/frontmatter.d.ts +24 -0
- package/dist/scanner/markdown/links.d.ts +60 -0
- package/dist/scanner/markdown/outline.d.ts +35 -0
- package/dist/scanner/markdown/renderer.d.ts +63 -0
- package/dist/scanner/openapi/planner.d.ts +96 -0
- package/dist/scanner/packages.d.ts +28 -0
- package/dist/scanner/reporter.d.ts +10 -0
- package/dist/scanner/scanner.d.ts +66 -0
- package/dist/scanner/schema/definitions.d.ts +79 -0
- package/dist/scanner/schema/describe.d.ts +105 -0
- package/dist/scanner/schema/planner.d.ts +49 -0
- package/dist/scanner/schema/registry.d.ts +68 -0
- package/dist/scanner/skills/classify.d.ts +21 -0
- package/dist/scanner/skills/layout.d.ts +46 -0
- package/dist/scanner/skills/planner.d.ts +61 -0
- package/dist/scanner/specs.d.ts +56 -0
- package/dist/scanner/sql/catalog.d.ts +98 -0
- package/dist/scanner/sql/cursor.d.ts +112 -0
- package/dist/scanner/sql/database.d.ts +51 -0
- package/dist/scanner/sql/parse.d.ts +122 -0
- package/dist/scanner/sql/planner.d.ts +69 -0
- package/dist/scanner/sql/query.d.ts +73 -0
- package/dist/scanner/sql/registry.d.ts +63 -0
- package/dist/scanner/sql/source.d.ts +10 -0
- package/dist/scanner/sql/statements.d.ts +42 -0
- package/dist/scanner/sql/tokens.d.ts +51 -0
- package/dist/scanner/tasks/layout.d.ts +52 -0
- package/dist/scanner/tasks/planner.d.ts +130 -0
- package/dist/scanner/tasks/schema.d.ts +88 -0
- package/dist/scanner/text.d.ts +14 -0
- package/package.json +104 -4
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { EdgeKind, NodeRef } from '../../model';
|
|
2
|
+
import { type TypeLinker, type TypeScope } from '../code/types';
|
|
3
|
+
import type { TermLinker } from '../glossary/terms';
|
|
4
|
+
import type { GraphBuilder } from '../graph/builder';
|
|
5
|
+
import type { LinkResolver } from './renderer';
|
|
6
|
+
/**
|
|
7
|
+
* @brief The markdown file whose links are resolved.
|
|
8
|
+
*
|
|
9
|
+
* @property node - The node that shows the text. Edges start here.
|
|
10
|
+
* @property root - Absolute directory `path` is relative to.
|
|
11
|
+
* @property path - Path of the file inside `root`.
|
|
12
|
+
* @property prefix - Prefix the bundle puts in front of paths from `root`.
|
|
13
|
+
*/
|
|
14
|
+
export interface LinkOrigin {
|
|
15
|
+
readonly node: NodeRef;
|
|
16
|
+
readonly root: string;
|
|
17
|
+
readonly path: string;
|
|
18
|
+
readonly prefix: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @brief Creates the link resolver for each piece of markdown of a scan. One place
|
|
22
|
+
* decides what prose can link to: files, types, functions and glossary terms.
|
|
23
|
+
*
|
|
24
|
+
* Holds the graph, the type linker and the term linker. Created once per scan
|
|
25
|
+
* by `RepositoryScanner` and passed to every planner that renders markdown.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* const resolvers = new ProseResolvers(graph, linker, new TermLinker(terms, graph));
|
|
29
|
+
*/
|
|
30
|
+
export declare class ProseResolvers {
|
|
31
|
+
private readonly graph;
|
|
32
|
+
private readonly linker;
|
|
33
|
+
private readonly terms;
|
|
34
|
+
/**
|
|
35
|
+
* @brief Creates the resolver factory.
|
|
36
|
+
*
|
|
37
|
+
* @param graph - Receives the edges that resolved references record.
|
|
38
|
+
* @param linker - Links type and function names in inline code.
|
|
39
|
+
* @param terms - Links glossary terms in prose.
|
|
40
|
+
*/
|
|
41
|
+
constructor(graph: GraphBuilder, linker: TypeLinker, terms: TermLinker);
|
|
42
|
+
/**
|
|
43
|
+
* @brief Makes the resolver for markdown that comes from a file: a page, a term, a decision.
|
|
44
|
+
*
|
|
45
|
+
* @param origin - The file the markdown is in.
|
|
46
|
+
* @param relation - Kind of the edge a link to a file, type or function records.
|
|
47
|
+
* @returns A resolver for one render of that text.
|
|
48
|
+
*/
|
|
49
|
+
forFile(origin: LinkOrigin, relation?: EdgeKind): LinkResolver;
|
|
50
|
+
/**
|
|
51
|
+
* @brief Makes the resolver for the description of a symbol, parameter or field. A doc
|
|
52
|
+
* comment has no links to files, so only inline code and terms resolve.
|
|
53
|
+
*
|
|
54
|
+
* @param from - Node the description belongs to.
|
|
55
|
+
* @param path - Path of the source file.
|
|
56
|
+
* @param scope - Decides which declaration a type name in inline code means.
|
|
57
|
+
* @returns A resolver for one render of that description.
|
|
58
|
+
*/
|
|
59
|
+
forDescription(from: NodeRef, path: string, scope: TypeScope): LinkResolver;
|
|
60
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @brief One line of a markdown text.
|
|
3
|
+
*
|
|
4
|
+
* @property text - The line as written, without its line break.
|
|
5
|
+
* @property heading - Depth and plain text of the line when it is an ATX heading such as `## Terms`. `null` otherwise.
|
|
6
|
+
*/
|
|
7
|
+
export interface MarkdownLine {
|
|
8
|
+
readonly text: string;
|
|
9
|
+
readonly heading: {
|
|
10
|
+
readonly depth: number;
|
|
11
|
+
readonly text: string;
|
|
12
|
+
} | null;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @brief Splits markdown into lines and marks the headings. A `#` line inside a
|
|
16
|
+
* fenced code block is code, not a heading.
|
|
17
|
+
*
|
|
18
|
+
* @param markdown - Markdown text without frontmatter.
|
|
19
|
+
* @returns One entry per line, in order.
|
|
20
|
+
*/
|
|
21
|
+
export declare function outlineLines(markdown: string): MarkdownLine[];
|
|
22
|
+
/**
|
|
23
|
+
* @brief Removes inline markdown markers from a short text such as a heading.
|
|
24
|
+
*
|
|
25
|
+
* @param markdown - Inline markdown, for example `**Lane** (_route_)`.
|
|
26
|
+
* @returns The text a reader sees, for example `Lane (route)`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function plainText(markdown: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* @brief Joins lines back into markdown and drops blank lines at both ends.
|
|
31
|
+
*
|
|
32
|
+
* @param lines - Lines to join, in order.
|
|
33
|
+
* @returns The markdown text, with no blank lines at either end.
|
|
34
|
+
*/
|
|
35
|
+
export declare function joinLines(lines: readonly MarkdownLine[]): string;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Heading } from '../../model';
|
|
2
|
+
import type { TermMatch } from '../glossary/terms';
|
|
3
|
+
import type { CodeHighlighter } from '../highlight';
|
|
4
|
+
/**
|
|
5
|
+
* @brief Turns what one document refers to into links inside the site.
|
|
6
|
+
*
|
|
7
|
+
* @property link - In-site href for a relative link, or `null` when it points outside the bundle.
|
|
8
|
+
* @property image - `data:` URI for a relative image, or `null` when it cannot be embedded.
|
|
9
|
+
* @property code - In-site href for inline code that names something in the bundle, such as a class. Optional.
|
|
10
|
+
* @property terms - The glossary terms in one run of prose that should become links. Optional.
|
|
11
|
+
*/
|
|
12
|
+
export interface LinkResolver {
|
|
13
|
+
link(href: string): string | null;
|
|
14
|
+
image(src: string): Promise<string | null>;
|
|
15
|
+
code?(text: string): string | null;
|
|
16
|
+
terms?(text: string): TermMatch[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @brief The HTML of a markdown text, with its headings and title.
|
|
20
|
+
*
|
|
21
|
+
* @property html - The rendered HTML.
|
|
22
|
+
* @property headings - Headings of depth 2 and 3 that have an id, in document order.
|
|
23
|
+
* @property title - Text of the first level-1 heading, or `null` when there is none.
|
|
24
|
+
*/
|
|
25
|
+
export interface RenderedMarkdown {
|
|
26
|
+
readonly html: string;
|
|
27
|
+
readonly headings: Heading[];
|
|
28
|
+
readonly title: string | null;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @brief Markdown to HTML. Raw HTML in the source is dropped, so the output is safe
|
|
32
|
+
* to inject into the generated page. Code blocks are highlighted, and links,
|
|
33
|
+
* images, inline code and glossary terms are resolved through a `LinkResolver`.
|
|
34
|
+
*
|
|
35
|
+
* Holds only the code highlighter. Created once by the constructor of
|
|
36
|
+
* `RepositoryScanner`, and used by `FileRenderer` and the planners in
|
|
37
|
+
* `code/`, `sql/`, `schema/`, `openapi/`, `glossary/`, `decisions/` and `tasks/`.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* const renderer = new MarkdownRenderer(new ShikiHighlighter());
|
|
41
|
+
*/
|
|
42
|
+
export declare class MarkdownRenderer {
|
|
43
|
+
private readonly highlighter;
|
|
44
|
+
/**
|
|
45
|
+
* @brief Creates a renderer that highlights code blocks.
|
|
46
|
+
*
|
|
47
|
+
* @param highlighter - Highlights the code blocks of the markdown.
|
|
48
|
+
*/
|
|
49
|
+
constructor(highlighter: CodeHighlighter);
|
|
50
|
+
/**
|
|
51
|
+
* @brief Renders markdown to HTML.
|
|
52
|
+
*
|
|
53
|
+
* @param resolver - Resolves links, images, inline code and terms. Without one, relative links lose their href and relative images become their alt text.
|
|
54
|
+
* @returns The HTML, the level-2 and level-3 headings, and the text of the first level-1 heading as title.
|
|
55
|
+
*/
|
|
56
|
+
render(markdown: string, resolver?: LinkResolver): Promise<RenderedMarkdown>;
|
|
57
|
+
/**
|
|
58
|
+
* @brief Replaces the content of every `<pre><code>` block with highlighted HTML.
|
|
59
|
+
*
|
|
60
|
+
* @param tree - The hast tree, changed in place.
|
|
61
|
+
*/
|
|
62
|
+
private highlightCode;
|
|
63
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { NodeRef } from '../../model';
|
|
2
|
+
import type { DocFile } from '../docs';
|
|
3
|
+
import type { GraphBuilder } from '../graph/builder';
|
|
4
|
+
import type { ProseResolvers } from '../markdown/links';
|
|
5
|
+
import type { MarkdownRenderer } from '../markdown/renderer';
|
|
6
|
+
import type { DefinitionPlanner } from '../schema/definitions';
|
|
7
|
+
import { type JsonObject } from '../schema/describe';
|
|
8
|
+
import type { DefinitionRegistry } from '../schema/registry';
|
|
9
|
+
/**
|
|
10
|
+
* @brief Adds an OpenAPI document to the graph: one `api` node for the document,
|
|
11
|
+
* one `operation` node per method on a path and per webhook, one `parameter`
|
|
12
|
+
* node per parameter, and one definition per entry of `components.schemas`.
|
|
13
|
+
*
|
|
14
|
+
* Holds the graph, the markdown renderer, the prose resolvers, the shared
|
|
15
|
+
* `DefinitionPlanner` and the `DefinitionRegistry`. Created by
|
|
16
|
+
* `RepositoryScanner` and used by `SpecPlanner` for every JSON or YAML file
|
|
17
|
+
* that is an OpenAPI 3 document.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const registry = new DefinitionRegistry();
|
|
21
|
+
* const definitions = new DefinitionPlanner(graph, markdown, resolvers, registry);
|
|
22
|
+
* const apis = new OpenApiPlanner(graph, markdown, resolvers, definitions, registry);
|
|
23
|
+
*/
|
|
24
|
+
export declare class OpenApiPlanner {
|
|
25
|
+
private readonly graph;
|
|
26
|
+
private readonly markdown;
|
|
27
|
+
private readonly resolvers;
|
|
28
|
+
private readonly definitions;
|
|
29
|
+
private readonly registry;
|
|
30
|
+
/**
|
|
31
|
+
* @brief Creates a planner.
|
|
32
|
+
*
|
|
33
|
+
* @param graph - Receives the API, operation and parameter nodes and their edges.
|
|
34
|
+
* @param markdown - Renders the descriptions.
|
|
35
|
+
* @param resolvers - Links what descriptions refer to.
|
|
36
|
+
* @param definitions - Adds the schema definitions and links type expressions.
|
|
37
|
+
* @param registry - Receives the document, so refs to it from other files resolve.
|
|
38
|
+
*/
|
|
39
|
+
constructor(graph: GraphBuilder, markdown: MarkdownRenderer, resolvers: ProseResolvers, definitions: DefinitionPlanner, registry: DefinitionRegistry);
|
|
40
|
+
/**
|
|
41
|
+
* @brief Adds one OpenAPI document.
|
|
42
|
+
*
|
|
43
|
+
* @param parent - Folder or skill the file is in.
|
|
44
|
+
* @param file - The file: its root, path, display path and prefix.
|
|
45
|
+
* @param document - The parsed file.
|
|
46
|
+
* @returns The node of the document.
|
|
47
|
+
*/
|
|
48
|
+
plan(parent: NodeRef, file: DocFile, document: JsonObject): NodeRef;
|
|
49
|
+
/**
|
|
50
|
+
* @brief Renders the tags a document declares, in document order, each with its description.
|
|
51
|
+
*
|
|
52
|
+
* @param document - The parsed document.
|
|
53
|
+
* @param node - Node of the document.
|
|
54
|
+
* @param file - The file the document is in.
|
|
55
|
+
* @returns The tags, with their descriptions rendered as HTML.
|
|
56
|
+
*/
|
|
57
|
+
private tags;
|
|
58
|
+
/**
|
|
59
|
+
* @brief Adds one operation with its parameters.
|
|
60
|
+
*
|
|
61
|
+
* @param owner - The document the operation is in.
|
|
62
|
+
* @param document - The parsed document, for resolving refs.
|
|
63
|
+
* @param found - The operation as found in the document.
|
|
64
|
+
*/
|
|
65
|
+
private planOperation;
|
|
66
|
+
/**
|
|
67
|
+
* @brief Reads the request body of an operation.
|
|
68
|
+
*
|
|
69
|
+
* @param document - The parsed document, for resolving refs.
|
|
70
|
+
* @param operation - The operation object of the document.
|
|
71
|
+
* @param node - Node of the operation. Schemas of the body become `type` edges from it.
|
|
72
|
+
* @param file - The file the document is in.
|
|
73
|
+
* @returns The body, or `null` for an operation without one.
|
|
74
|
+
*/
|
|
75
|
+
private requestBody;
|
|
76
|
+
/**
|
|
77
|
+
* @brief Reads the responses of an operation.
|
|
78
|
+
*
|
|
79
|
+
* @param document - The parsed document, for resolving refs.
|
|
80
|
+
* @param operation - The operation object of the document.
|
|
81
|
+
* @param file - The file the document is in.
|
|
82
|
+
* @param node - Node of the operation. A schema of a response becomes a `returns` edge from it, or a `throws` edge for an error.
|
|
83
|
+
* @returns The responses in document order.
|
|
84
|
+
*/
|
|
85
|
+
private responses;
|
|
86
|
+
/**
|
|
87
|
+
* @brief Reads the media types of a request body or a response.
|
|
88
|
+
*
|
|
89
|
+
* @param content - The `content` object: media type to media type object.
|
|
90
|
+
* @param node - Node of the operation.
|
|
91
|
+
* @param file - The file the document is in.
|
|
92
|
+
* @param relation - Kind of the edge a schema records from the operation.
|
|
93
|
+
* @returns One entry per media type, in document order.
|
|
94
|
+
*/
|
|
95
|
+
private content;
|
|
96
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { PackageRole } from '../model';
|
|
2
|
+
import type { Source } from './files';
|
|
3
|
+
/**
|
|
4
|
+
* @brief A directory with a package manifest, as `detectPackages` reads it.
|
|
5
|
+
*
|
|
6
|
+
* @property packageName - Name the manifest gives, such as `@g3nomaly/core`, or the directory name when it gives none.
|
|
7
|
+
* @property role - `app`, `library` or `workspace`. A manifest that declares an executable makes an app; otherwise a directory named `apps`/`app` above it makes an app, one named `libs`/`lib` a library, and else the manifest decides.
|
|
8
|
+
* @property manifest - Display path of the manifest that marks the package, such as `packages/core/package.json`.
|
|
9
|
+
* @property version - Version the manifest gives, or `null`.
|
|
10
|
+
* @property description - Description the manifest gives, or `''`.
|
|
11
|
+
*/
|
|
12
|
+
export interface PackageInfo {
|
|
13
|
+
readonly packageName: string;
|
|
14
|
+
readonly role: PackageRole;
|
|
15
|
+
readonly manifest: string;
|
|
16
|
+
readonly version: string | null;
|
|
17
|
+
readonly description: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @brief Finds the packages of a set of sources: every directory below a root with a manifest that one of the readers understands.
|
|
21
|
+
*
|
|
22
|
+
* A directory with several manifests is read by the first reader in `READERS` that understands one. The root
|
|
23
|
+
* directory of a source is left out: it is the repository itself.
|
|
24
|
+
*
|
|
25
|
+
* @param sources - Directories with their files, such as the code sources of a scan.
|
|
26
|
+
* @returns Packages by display path of their directory, such as `packages/core`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function detectPackages(sources: readonly Source[]): Promise<Map<string, PackageInfo>>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @brief Receives problems that should not stop a scan.
|
|
3
|
+
*
|
|
4
|
+
* @property warn - Reports one problem, as one line of plain text.
|
|
5
|
+
*/
|
|
6
|
+
export interface Reporter {
|
|
7
|
+
warn(message: string): void;
|
|
8
|
+
}
|
|
9
|
+
/** A reporter that drops every warning. */
|
|
10
|
+
export declare const silentReporter: Reporter;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type DocsBundle } from '../model';
|
|
2
|
+
import type { Source } from './files';
|
|
3
|
+
import type { CodeHighlighter } from './highlight';
|
|
4
|
+
import { type Reporter } from './reporter';
|
|
5
|
+
import { type TaskTreeSource } from './tasks/planner';
|
|
6
|
+
/**
|
|
7
|
+
* @brief The directories one scan reads. Skills and docs each have their own. The
|
|
8
|
+
* code section and the database section are both read from `code`: source
|
|
9
|
+
* files go to the one, SQL files to the other.
|
|
10
|
+
*
|
|
11
|
+
* @property skills - Directories of the skills section.
|
|
12
|
+
* @property docs - Directories of the docs section.
|
|
13
|
+
* @property code - Directories of the code and database sections.
|
|
14
|
+
* @property tasks - The task-manager trees. Their files are shown in the tasks section, and nowhere else.
|
|
15
|
+
*/
|
|
16
|
+
export interface ScanInput {
|
|
17
|
+
readonly skills: readonly Source[];
|
|
18
|
+
readonly docs: readonly Source[];
|
|
19
|
+
readonly code: readonly Source[];
|
|
20
|
+
readonly tasks: readonly TaskTreeSource[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @brief What a {@link RepositoryScanner} is built with.
|
|
24
|
+
*
|
|
25
|
+
* @property grammarDir - Directory that relative grammar paths resolve against.
|
|
26
|
+
* @property highlighter - Highlights the code blocks of the markdown.
|
|
27
|
+
* @property reporter - Receives problems that do not stop a scan. Defaults to `silentReporter`.
|
|
28
|
+
*/
|
|
29
|
+
export interface ScannerOptions {
|
|
30
|
+
readonly grammarDir: string;
|
|
31
|
+
readonly highlighter: CodeHighlighter;
|
|
32
|
+
readonly reporter?: Reporter;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @brief Turns directories into the graph of a documentation site. Holds the parts
|
|
36
|
+
* that outlive one scan: the language registry, the symbol extractor, the
|
|
37
|
+
* grammar loader and the markdown and file renderers. Each scan builds a fresh
|
|
38
|
+
* graph and wires up every planner for it. Created in `api/services.ts` and
|
|
39
|
+
* run by `BundleBuilder`.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* const scanner = new RepositoryScanner({ grammarDir: import.meta.dir, highlighter: new ShikiHighlighter(), reporter });
|
|
43
|
+
* const { nodes, edges } = await scanner.scan({ skills: [], docs: [repository], code: [repository], tasks: [] });
|
|
44
|
+
*/
|
|
45
|
+
export declare class RepositoryScanner {
|
|
46
|
+
private readonly options;
|
|
47
|
+
private readonly registry;
|
|
48
|
+
private readonly extractor;
|
|
49
|
+
private readonly grammars;
|
|
50
|
+
private readonly markdown;
|
|
51
|
+
private readonly files;
|
|
52
|
+
/**
|
|
53
|
+
* @brief Creates the grammar loader and the renderers the scans share.
|
|
54
|
+
*
|
|
55
|
+
* @param options - Grammar directory, highlighter and optional reporter.
|
|
56
|
+
*/
|
|
57
|
+
constructor(options: ScannerOptions);
|
|
58
|
+
/**
|
|
59
|
+
* @brief Scans the directories of every section into one graph: skills, docs,
|
|
60
|
+
* code, database and tasks, in that order.
|
|
61
|
+
*
|
|
62
|
+
* @param input - The directories of each section.
|
|
63
|
+
* @returns The nodes and edges of the bundle, without its meta and semantic index.
|
|
64
|
+
*/
|
|
65
|
+
scan(input: ScanInput): Promise<Pick<DocsBundle, 'nodes' | 'edges'>>;
|
|
66
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { EdgeKind, LinkedText, NodeRef } from '../../model';
|
|
2
|
+
import type { DocFile } from '../docs';
|
|
3
|
+
import type { GraphBuilder } from '../graph/builder';
|
|
4
|
+
import type { ProseResolvers } from '../markdown/links';
|
|
5
|
+
import type { MarkdownRenderer } from '../markdown/renderer';
|
|
6
|
+
import { type TypeExpression } from './describe';
|
|
7
|
+
import type { DefinitionRegistry } from './registry';
|
|
8
|
+
/**
|
|
9
|
+
* @brief The file a definition is in.
|
|
10
|
+
*
|
|
11
|
+
* @property ref - Node of the file. Definitions become its children.
|
|
12
|
+
* @property file - The file the definitions are in.
|
|
13
|
+
* @property anchors - Anchors already used on the page of the file.
|
|
14
|
+
*/
|
|
15
|
+
export interface DefinitionOwner {
|
|
16
|
+
readonly ref: NodeRef;
|
|
17
|
+
readonly file: DocFile;
|
|
18
|
+
readonly anchors: Set<string>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @brief Adds named JSON Schemas to the graph: one `definition` node per schema and
|
|
22
|
+
* one `field` node per property. A `$ref` in a type becomes a link to the
|
|
23
|
+
* definition it names, and an edge: `type` from a property, `extends` from a
|
|
24
|
+
* definition.
|
|
25
|
+
*
|
|
26
|
+
* Holds the graph, the markdown renderer, the prose resolvers and the
|
|
27
|
+
* definition registry. Created once per scan by `RepositoryScanner`. Used by
|
|
28
|
+
* `JsonSchemaPlanner` for the schemas of a schema file and by
|
|
29
|
+
* `OpenApiPlanner` for `components.schemas` and for the schemas of
|
|
30
|
+
* parameters, request bodies and responses.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* const registry = new DefinitionRegistry();
|
|
34
|
+
* const definitions = new DefinitionPlanner(graph, markdown, resolvers, registry);
|
|
35
|
+
*/
|
|
36
|
+
export declare class DefinitionPlanner {
|
|
37
|
+
private readonly graph;
|
|
38
|
+
private readonly markdown;
|
|
39
|
+
private readonly resolvers;
|
|
40
|
+
private readonly registry;
|
|
41
|
+
/**
|
|
42
|
+
* @brief Creates a planner.
|
|
43
|
+
*
|
|
44
|
+
* @param graph - Receives the definition and field nodes and their edges.
|
|
45
|
+
* @param markdown - Renders the descriptions.
|
|
46
|
+
* @param resolvers - Links what descriptions refer to.
|
|
47
|
+
* @param registry - Receives every definition, and finds the targets of refs.
|
|
48
|
+
*/
|
|
49
|
+
constructor(graph: GraphBuilder, markdown: MarkdownRenderer, resolvers: ProseResolvers, registry: DefinitionRegistry);
|
|
50
|
+
/**
|
|
51
|
+
* @brief Adds one definition with its properties.
|
|
52
|
+
*
|
|
53
|
+
* @param owner - The file the definition is in.
|
|
54
|
+
* @param name - Name of the definition, as the page shows it.
|
|
55
|
+
* @param pointer - JSON pointer of the schema inside its file. Refs to that place link to the definition.
|
|
56
|
+
* @param schema - The schema: an object, or `true` or `false`.
|
|
57
|
+
* @returns The node of the definition.
|
|
58
|
+
*/
|
|
59
|
+
add(owner: DefinitionOwner, name: string, pointer: string, schema: unknown): NodeRef;
|
|
60
|
+
/**
|
|
61
|
+
* @brief Turns a type expression into text with links to the definitions its refs name.
|
|
62
|
+
*
|
|
63
|
+
* @param expression - The type expression, with the spans of its refs.
|
|
64
|
+
* @param from - Node the expression belongs to.
|
|
65
|
+
* @param file - The file the expression is in. A relative ref starts there.
|
|
66
|
+
* @param relation - Kind of the edge each resolved ref records from `from`.
|
|
67
|
+
* @returns The text with a link for every ref the scan can resolve. A resolved ref reads as the name of its target, so a ref to a whole file reads as the title of its schema.
|
|
68
|
+
*/
|
|
69
|
+
linked(expression: TypeExpression, from: NodeRef, file: DocFile, relation: EdgeKind): LinkedText;
|
|
70
|
+
/**
|
|
71
|
+
* @brief Renders a description as HTML.
|
|
72
|
+
*
|
|
73
|
+
* @param markdown - Markdown of the description, or `''`.
|
|
74
|
+
* @param node - Node the description belongs to. Links in it become edges from this node.
|
|
75
|
+
* @param file - The file the description is in. Its root, path and prefix resolve links.
|
|
76
|
+
* @returns HTML, or `''`.
|
|
77
|
+
*/
|
|
78
|
+
html(markdown: string, node: NodeRef, { root, path, prefix }: DocFile): Promise<string>;
|
|
79
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/** A JSON object as parsed from JSON or YAML. */
|
|
2
|
+
export type JsonObject = Readonly<Record<string, unknown>>;
|
|
3
|
+
/**
|
|
4
|
+
* @brief Tells a JSON object from every other value: true for an object that is no
|
|
5
|
+
* array and not `null`.
|
|
6
|
+
*
|
|
7
|
+
* @param value - Any value, as parsed from JSON or YAML.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isJsonObject(value: unknown): value is JsonObject;
|
|
10
|
+
/**
|
|
11
|
+
* @brief A span of a type expression that stands for a `$ref`.
|
|
12
|
+
*
|
|
13
|
+
* @property start - Offset in the type text where the span starts.
|
|
14
|
+
* @property end - Offset in the type text where the span ends.
|
|
15
|
+
* @property ref - The `$ref` as the schema writes it.
|
|
16
|
+
*/
|
|
17
|
+
export interface SchemaRef {
|
|
18
|
+
readonly start: number;
|
|
19
|
+
readonly end: number;
|
|
20
|
+
readonly ref: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @brief What a schema allows, as text: `string[]`, `Cat | Dog`, `"open" | "closed"`.
|
|
24
|
+
*
|
|
25
|
+
* @property text - The type as text.
|
|
26
|
+
* @property refs - The spans of the text that are `$ref`s, in text order, not overlapping.
|
|
27
|
+
*/
|
|
28
|
+
export interface TypeExpression {
|
|
29
|
+
readonly text: string;
|
|
30
|
+
readonly refs: readonly SchemaRef[];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* @brief One property of an object schema. A nested property has a dotted name.
|
|
34
|
+
*
|
|
35
|
+
* @property name - Name of the property, dotted for a nested one: `city`, `address.city`, `items[].sku`.
|
|
36
|
+
* @property type - The type of the property.
|
|
37
|
+
* @property required - True when the parent schema requires the property.
|
|
38
|
+
* @property defaultValue - The default as JSON, or `null`.
|
|
39
|
+
* @property description - Markdown.
|
|
40
|
+
* @property constraints - Keywords that narrow the type, as `keyword: value`.
|
|
41
|
+
*/
|
|
42
|
+
export interface SchemaProperty {
|
|
43
|
+
readonly name: string;
|
|
44
|
+
readonly type: TypeExpression;
|
|
45
|
+
readonly required: boolean;
|
|
46
|
+
readonly defaultValue: string | null;
|
|
47
|
+
readonly description: string;
|
|
48
|
+
readonly constraints: readonly string[];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* @brief What a schema says, in the shape the site shows.
|
|
52
|
+
*
|
|
53
|
+
* @property type - The type of the schema.
|
|
54
|
+
* @property description - Markdown.
|
|
55
|
+
* @property constraints - Keywords that narrow the type, as `keyword: value`.
|
|
56
|
+
* @property values - Values of an `enum` or a `const`, as JSON. Empty when they fit inside `type`.
|
|
57
|
+
* @property deprecated - True when the schema is deprecated.
|
|
58
|
+
* @property properties - Every property, nested ones included, in schema order.
|
|
59
|
+
*/
|
|
60
|
+
export interface SchemaDescription {
|
|
61
|
+
readonly type: TypeExpression;
|
|
62
|
+
readonly description: string;
|
|
63
|
+
readonly constraints: readonly string[];
|
|
64
|
+
readonly values: readonly string[];
|
|
65
|
+
readonly deprecated: boolean;
|
|
66
|
+
readonly properties: readonly SchemaProperty[];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* @brief Reads the last part of a `$ref` as a name.
|
|
70
|
+
*
|
|
71
|
+
* @param ref - A `$ref`, such as `#/$defs/Booking` or `cargo.schema.json`.
|
|
72
|
+
* @returns `Booking` for a ref into a file, the file name for a ref to a whole file.
|
|
73
|
+
*/
|
|
74
|
+
export declare function refName(ref: string): string;
|
|
75
|
+
/**
|
|
76
|
+
* @brief Decodes one segment of a JSON pointer.
|
|
77
|
+
*
|
|
78
|
+
* @param segment - One segment between two `/`, possibly percent-encoded.
|
|
79
|
+
* @returns The key it names: percent escapes decoded, `~1` as `/` and `~0` as `~`.
|
|
80
|
+
*/
|
|
81
|
+
export declare function decodePointerSegment(segment: string): string;
|
|
82
|
+
/**
|
|
83
|
+
* @brief Writes what a schema allows as a type expression.
|
|
84
|
+
*
|
|
85
|
+
* @param schema - A schema: an object, or `true` or `false`.
|
|
86
|
+
* @param depth - Nesting of the schema inside the one that is described.
|
|
87
|
+
* @returns The expression. `any` for a schema that states no type.
|
|
88
|
+
*/
|
|
89
|
+
export declare function typeOf(schema: unknown, depth?: number): TypeExpression;
|
|
90
|
+
/**
|
|
91
|
+
* @brief Describes a JSON Schema in the shape the site shows: a type expression, a
|
|
92
|
+
* description, constraints and a flat list of properties.
|
|
93
|
+
*
|
|
94
|
+
* @param schema - The schema: an object, or `true` or `false`.
|
|
95
|
+
* @returns The description. A value that is no schema is described as `any`.
|
|
96
|
+
*/
|
|
97
|
+
export declare function describeSchema(schema: unknown): SchemaDescription;
|
|
98
|
+
/**
|
|
99
|
+
* @brief Tells whether a schema says anything about a value: true when it has a
|
|
100
|
+
* type, properties, a composition, values or a `$ref`. A file that only
|
|
101
|
+
* holds `$defs` has a root schema that does not.
|
|
102
|
+
*
|
|
103
|
+
* @param schema - The schema to check.
|
|
104
|
+
*/
|
|
105
|
+
export declare function describesValue(schema: JsonObject): boolean;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { NodeRef } from '../../model';
|
|
2
|
+
import type { FileRenderer } from '../content';
|
|
3
|
+
import type { DocFile } from '../docs';
|
|
4
|
+
import type { GraphBuilder } from '../graph/builder';
|
|
5
|
+
import type { ProseResolvers } from '../markdown/links';
|
|
6
|
+
import type { DefinitionPlanner } from './definitions';
|
|
7
|
+
import { type JsonObject } from './describe';
|
|
8
|
+
import type { DefinitionRegistry } from './registry';
|
|
9
|
+
/**
|
|
10
|
+
* @brief Adds a JSON Schema file to the graph: one `schema` node for the file, with
|
|
11
|
+
* its text, and one definition per schema it names. The root schema is a
|
|
12
|
+
* definition when it describes a value.
|
|
13
|
+
*
|
|
14
|
+
* Holds the graph, the file renderer, the prose resolvers, the shared
|
|
15
|
+
* `DefinitionPlanner` and the `DefinitionRegistry`. Created by
|
|
16
|
+
* `RepositoryScanner` and used by `SpecPlanner` for every JSON or YAML file
|
|
17
|
+
* that is a JSON Schema.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const registry = new DefinitionRegistry();
|
|
21
|
+
* const definitions = new DefinitionPlanner(graph, markdown, resolvers, registry);
|
|
22
|
+
* const schemas = new JsonSchemaPlanner(graph, files, resolvers, definitions, registry);
|
|
23
|
+
*/
|
|
24
|
+
export declare class JsonSchemaPlanner {
|
|
25
|
+
private readonly graph;
|
|
26
|
+
private readonly files;
|
|
27
|
+
private readonly resolvers;
|
|
28
|
+
private readonly definitions;
|
|
29
|
+
private readonly registry;
|
|
30
|
+
/**
|
|
31
|
+
* @brief Creates a planner.
|
|
32
|
+
*
|
|
33
|
+
* @param graph - Receives the schema and definition nodes and their edges.
|
|
34
|
+
* @param files - Renders the text of the file.
|
|
35
|
+
* @param resolvers - Links what the file refers to.
|
|
36
|
+
* @param definitions - Adds the definitions the schema names.
|
|
37
|
+
* @param registry - Receives the file and its `$id`, so refs to the file resolve.
|
|
38
|
+
*/
|
|
39
|
+
constructor(graph: GraphBuilder, files: FileRenderer, resolvers: ProseResolvers, definitions: DefinitionPlanner, registry: DefinitionRegistry);
|
|
40
|
+
/**
|
|
41
|
+
* @brief Adds one schema file.
|
|
42
|
+
*
|
|
43
|
+
* @param parent - Folder or skill the file is in.
|
|
44
|
+
* @param file - The file: its root, path, display path and prefix.
|
|
45
|
+
* @param schema - The parsed file.
|
|
46
|
+
* @returns The node of the file.
|
|
47
|
+
*/
|
|
48
|
+
plan(parent: NodeRef, file: DocFile, schema: JsonObject): NodeRef;
|
|
49
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { NodeRef } from '../../model';
|
|
2
|
+
/**
|
|
3
|
+
* @brief Writes a JSON pointer in one spelling, so two spellings of one place compare equal.
|
|
4
|
+
*
|
|
5
|
+
* @param pointer - A pointer, with or without the `#` in front.
|
|
6
|
+
* @returns The pointer with every segment decoded. `''` names the root.
|
|
7
|
+
*/
|
|
8
|
+
export declare function normalizePointer(pointer: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* @brief What a `$ref` points at.
|
|
11
|
+
*
|
|
12
|
+
* @property ref - The node that shows the place.
|
|
13
|
+
* @property name - Name of the node, as a type expression shows it.
|
|
14
|
+
*/
|
|
15
|
+
export interface RefTarget {
|
|
16
|
+
readonly ref: NodeRef;
|
|
17
|
+
readonly name: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @brief Finds the nodes that `$ref`s point at, across the JSON Schema files and
|
|
21
|
+
* OpenAPI documents of one scan.
|
|
22
|
+
*
|
|
23
|
+
* Created once per scan by `RepositoryScanner` and shared by `JsonSchemaPlanner`,
|
|
24
|
+
* `OpenApiPlanner` and `DefinitionPlanner`. The planners register every file and
|
|
25
|
+
* definition when they add it; `DefinitionPlanner` resolves refs when the content
|
|
26
|
+
* of the graph is built. By then every file is read, so a ref can point into a
|
|
27
|
+
* later file.
|
|
28
|
+
*
|
|
29
|
+
* @property places - The node at each `path#pointer` place.
|
|
30
|
+
* @property ids - Path of each schema file by its `$id`.
|
|
31
|
+
* @example
|
|
32
|
+
* const registry = new DefinitionRegistry();
|
|
33
|
+
*/
|
|
34
|
+
export declare class DefinitionRegistry {
|
|
35
|
+
private readonly places;
|
|
36
|
+
private readonly ids;
|
|
37
|
+
/**
|
|
38
|
+
* @brief Records the node that shows a place in a file.
|
|
39
|
+
*
|
|
40
|
+
* @param path - Path of the file, as the site shows it.
|
|
41
|
+
* @param pointer - JSON pointer of the place inside the file. `''` is the whole file.
|
|
42
|
+
* @param target - The node that shows the place, and its name.
|
|
43
|
+
*/
|
|
44
|
+
register(path: string, pointer: string, target: RefTarget): void;
|
|
45
|
+
/**
|
|
46
|
+
* @brief Records the `$id` of a schema file, so a ref by that id finds the file.
|
|
47
|
+
*
|
|
48
|
+
* @param id - The `$id`, an absolute URI.
|
|
49
|
+
* @param path - Path of the file, as the site shows it.
|
|
50
|
+
*/
|
|
51
|
+
registerId(id: string, path: string): void;
|
|
52
|
+
/**
|
|
53
|
+
* @brief Finds the node a `$ref` points at.
|
|
54
|
+
*
|
|
55
|
+
* @param ref - The `$ref` as written: `#/$defs/Cargo`, `cargo.schema.json#/$defs/Cargo`, or the `$id` of a file.
|
|
56
|
+
* @param fromPath - Path of the file the ref is in. A relative ref starts there.
|
|
57
|
+
* @returns The node and its name, or `null` when the ref leaves the scan or names nothing the site shows.
|
|
58
|
+
*/
|
|
59
|
+
resolve(ref: string, fromPath: string): RefTarget | null;
|
|
60
|
+
/**
|
|
61
|
+
* @brief Finds the file a URI names.
|
|
62
|
+
*
|
|
63
|
+
* @param uri - The part of a ref in front of the `#`.
|
|
64
|
+
* @param fromPath - Path of the file the ref is in, as the site shows it.
|
|
65
|
+
* @returns Path of the file: the same file for an empty URI, a registered `$id`, or a relative path. `null` for any other absolute URI.
|
|
66
|
+
*/
|
|
67
|
+
private pathOf;
|
|
68
|
+
}
|