@g3nomaly/analyze 0.0.0-stage → 0.1.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/LICENSE +95 -0
- package/README.md +71 -2
- package/dist/THIRD_PARTY_LICENSES.txt +1904 -0
- package/dist/api/bundle-builder.d.ts +75 -0
- package/dist/api/bundle-cache.d.ts +70 -0
- package/dist/api/bundle-loader.d.ts +58 -0
- package/dist/api/create-docs.d.ts +72 -0
- package/dist/api/embedding.d.ts +32 -0
- package/dist/api/errors.d.ts +28 -0
- package/dist/api/list.d.ts +106 -0
- package/dist/api/options.d.ts +78 -0
- package/dist/api/refs.d.ts +133 -0
- package/dist/api/scan.d.ts +44 -0
- package/dist/api/search.d.ts +126 -0
- package/dist/api/services.d.ts +7 -0
- package/dist/api/show.d.ts +104 -0
- package/dist/api/site-reader.d.ts +11 -0
- package/dist/api/site-writer.d.ts +20 -0
- package/dist/api/source.d.ts +46 -0
- package/dist/api/target.d.ts +10 -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 +8885 -0
- package/dist/embeddings/abbreviations.d.ts +7 -0
- package/dist/embeddings/index-builder.d.ts +10 -0
- package/dist/embeddings/index.d.ts +10 -0
- package/dist/embeddings/model.d.ts +113 -0
- package/dist/embeddings/searcher.d.ts +67 -0
- package/dist/embeddings/vectors.d.ts +75 -0
- package/dist/embeddings/words.d.ts +42 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +8329 -0
- package/dist/model/index.d.ts +560 -0
- package/dist/model/registry.d.ts +494 -0
- package/dist/query/graph.d.ts +66 -0
- package/dist/query/index.d.ts +4 -0
- package/dist/query/name-search.d.ts +47 -0
- package/dist/query/semantic.d.ts +30 -0
- package/dist/query/text.d.ts +22 -0
- package/dist/retrieval/describe.d.ts +26 -0
- package/dist/retrieval/filter.d.ts +17 -0
- package/dist/retrieval/index.d.ts +7 -0
- package/dist/retrieval/markdown.d.ts +16 -0
- package/dist/retrieval/report.d.ts +214 -0
- package/dist/retrieval/resolve.d.ts +27 -0
- package/dist/retrieval/retriever.d.ts +94 -0
- package/dist/retrieval/summary.d.ts +24 -0
- package/dist/scanner/code/doc/clean.d.ts +10 -0
- package/dist/scanner/code/doc/index.d.ts +6 -0
- package/dist/scanner/code/doc/markdown.d.ts +3 -0
- package/dist/scanner/code/doc/python.d.ts +3 -0
- package/dist/scanner/code/doc/tagged.d.ts +10 -0
- package/dist/scanner/code/doc/types.d.ts +22 -0
- package/dist/scanner/code/doc/xml.d.ts +3 -0
- package/dist/scanner/code/example.d.ts +36 -0
- package/dist/scanner/code/extract.d.ts +78 -0
- package/dist/scanner/code/grammar.d.ts +29 -0
- package/dist/scanner/code/language.d.ts +149 -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 +19 -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 +17 -0
- package/dist/scanner/code/planner.d.ts +71 -0
- package/dist/scanner/code/symbols.d.ts +68 -0
- package/dist/scanner/code/types.d.ts +93 -0
- package/dist/scanner/content.d.ts +38 -0
- package/dist/scanner/decisions/parse.d.ts +28 -0
- package/dist/scanner/decisions/planner.d.ts +30 -0
- package/dist/scanner/docs.d.ts +52 -0
- package/dist/scanner/files.d.ts +60 -0
- package/dist/scanner/glossary/parse.d.ts +30 -0
- package/dist/scanner/glossary/planner.d.ts +42 -0
- package/dist/scanner/glossary/terms.d.ts +86 -0
- package/dist/scanner/graph/builder.d.ts +55 -0
- package/dist/scanner/highlight.d.ts +31 -0
- package/dist/scanner/index.d.ts +40 -0
- package/dist/scanner/markdown/frontmatter.d.ts +9 -0
- package/dist/scanner/markdown/links.d.ts +50 -0
- package/dist/scanner/markdown/outline.d.ts +27 -0
- package/dist/scanner/markdown/renderer.d.ts +44 -0
- package/dist/scanner/openapi/planner.d.ts +84 -0
- package/dist/scanner/reporter.d.ts +7 -0
- package/dist/scanner/scanner.d.ts +52 -0
- package/dist/scanner/schema/definitions.d.ts +69 -0
- package/dist/scanner/schema/describe.d.ts +79 -0
- package/dist/scanner/schema/planner.d.ts +46 -0
- package/dist/scanner/schema/registry.d.ts +61 -0
- package/dist/scanner/skills/classify.d.ts +20 -0
- package/dist/scanner/skills/layout.d.ts +28 -0
- package/dist/scanner/skills/planner.d.ts +46 -0
- package/dist/scanner/specs.d.ts +50 -0
- package/dist/scanner/sql/catalog.d.ts +84 -0
- package/dist/scanner/sql/cursor.d.ts +107 -0
- package/dist/scanner/sql/database.d.ts +48 -0
- package/dist/scanner/sql/parse.d.ts +87 -0
- package/dist/scanner/sql/planner.d.ts +65 -0
- package/dist/scanner/sql/query.d.ts +60 -0
- package/dist/scanner/sql/registry.d.ts +49 -0
- package/dist/scanner/sql/source.d.ts +9 -0
- package/dist/scanner/sql/statements.d.ts +36 -0
- package/dist/scanner/sql/tokens.d.ts +38 -0
- package/dist/scanner/tasks/layout.d.ts +40 -0
- package/dist/scanner/tasks/planner.d.ts +75 -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,87 @@
|
|
|
1
|
+
/** What a `REFERENCES` clause states. */
|
|
2
|
+
export interface ParsedReference {
|
|
3
|
+
/** Name of the referenced table. */
|
|
4
|
+
readonly table: string;
|
|
5
|
+
/** Referenced columns. Empty when the clause names none, which means the primary key. */
|
|
6
|
+
readonly columns: readonly string[];
|
|
7
|
+
/** Action in capitals, or `''`. */
|
|
8
|
+
readonly onDelete: string;
|
|
9
|
+
readonly onUpdate: string;
|
|
10
|
+
}
|
|
11
|
+
/** A foreign key of a table, from a column or from a table constraint. */
|
|
12
|
+
export interface ParsedForeignKey extends ParsedReference {
|
|
13
|
+
/** Name of the constraint, or `''`. */
|
|
14
|
+
readonly name: string;
|
|
15
|
+
/** Columns of the table that hold the key. */
|
|
16
|
+
readonly sourceColumns: readonly string[];
|
|
17
|
+
}
|
|
18
|
+
/** One column of a table as its statement writes it. */
|
|
19
|
+
export interface ParsedColumn {
|
|
20
|
+
readonly name: string;
|
|
21
|
+
/** Declared type as written, with single spaces. `''` for a column without one. */
|
|
22
|
+
readonly type: string;
|
|
23
|
+
/** True when the column is declared `NOT NULL`. */
|
|
24
|
+
readonly notNull: boolean;
|
|
25
|
+
/** Default value as written, or `null`. */
|
|
26
|
+
readonly defaultValue: string | null;
|
|
27
|
+
/** Other constraints of the column as written, such as `UNIQUE`, `CHECK (n > 0)` or `COLLATE NOCASE`. */
|
|
28
|
+
readonly constraints: readonly string[];
|
|
29
|
+
/** Markdown from the comment behind or above the column. */
|
|
30
|
+
readonly description: string;
|
|
31
|
+
}
|
|
32
|
+
/** An index of a table, from a `CREATE INDEX` statement. */
|
|
33
|
+
export interface ParsedIndex {
|
|
34
|
+
readonly name: string;
|
|
35
|
+
/** Indexed columns or expressions as written. */
|
|
36
|
+
readonly columns: readonly string[];
|
|
37
|
+
readonly unique: boolean;
|
|
38
|
+
}
|
|
39
|
+
/** One table of a schema. */
|
|
40
|
+
export interface ParsedTable {
|
|
41
|
+
readonly name: string;
|
|
42
|
+
/** 1-based line of the statement. */
|
|
43
|
+
readonly line: number;
|
|
44
|
+
/** Markdown from the comment above the statement. */
|
|
45
|
+
readonly description: string;
|
|
46
|
+
readonly columns: readonly ParsedColumn[];
|
|
47
|
+
/** Columns of the primary key, in key order. */
|
|
48
|
+
readonly primaryKey: readonly string[];
|
|
49
|
+
readonly foreignKeys: readonly ParsedForeignKey[];
|
|
50
|
+
/** Table constraints that are no key, as written. */
|
|
51
|
+
readonly constraints: readonly string[];
|
|
52
|
+
/** `WITHOUT ROWID`, `STRICT`, `VIRTUAL`, `TEMPORARY`. */
|
|
53
|
+
readonly options: readonly string[];
|
|
54
|
+
readonly indexes: readonly ParsedIndex[];
|
|
55
|
+
}
|
|
56
|
+
/** A view or a trigger of a schema. */
|
|
57
|
+
export interface ParsedObject {
|
|
58
|
+
readonly kind: 'view' | 'trigger';
|
|
59
|
+
readonly name: string;
|
|
60
|
+
/** The table a trigger fires on. `''` for a view. */
|
|
61
|
+
readonly table: string;
|
|
62
|
+
readonly line: number;
|
|
63
|
+
readonly description: string;
|
|
64
|
+
/** The statement as written, without the closing semicolon. */
|
|
65
|
+
readonly sql: string;
|
|
66
|
+
}
|
|
67
|
+
/** What a schema file declares, from `parseSqlSchema`. */
|
|
68
|
+
export interface ParsedSchema {
|
|
69
|
+
/** Markdown from the comments that open the file. */
|
|
70
|
+
readonly intro: string;
|
|
71
|
+
readonly tables: readonly ParsedTable[];
|
|
72
|
+
readonly objects: readonly ParsedObject[];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Reads the tables, indexes, views and triggers of a SQLite schema file.
|
|
76
|
+
* Statements of any other kind, and statements that cannot be read, are
|
|
77
|
+
* skipped. The SQL is read as text and never run.
|
|
78
|
+
*
|
|
79
|
+
* A comment directly above a statement describes its table, view or trigger.
|
|
80
|
+
* A comment behind a column on the same line, or directly above it, describes
|
|
81
|
+
* the column. The comments that open the file, apart from the first
|
|
82
|
+
* statement, are the introduction.
|
|
83
|
+
*
|
|
84
|
+
* @param source - Text of the file.
|
|
85
|
+
* @returns What the file declares, in file order.
|
|
86
|
+
*/
|
|
87
|
+
export declare function parseSqlSchema(source: string): ParsedSchema;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { NodeRef } from '../../model';
|
|
2
|
+
import type { SourceFile } from '../code/planner';
|
|
3
|
+
import type { GraphBuilder } from '../graph/builder';
|
|
4
|
+
import type { CodeHighlighter } from '../highlight';
|
|
5
|
+
import type { ProseResolvers } from '../markdown/links';
|
|
6
|
+
import type { MarkdownRenderer } from '../markdown/renderer';
|
|
7
|
+
import { type Reporter } from '../reporter';
|
|
8
|
+
import { type ParsedSchema } from './parse';
|
|
9
|
+
import type { TableRegistry } from './registry';
|
|
10
|
+
/**
|
|
11
|
+
* Adds SQL schema files to the graph: one `database` node per file, one
|
|
12
|
+
* `table` node per table and one `field` node per column. A foreign key
|
|
13
|
+
* becomes a `references` edge from its table to the table it points at.
|
|
14
|
+
*
|
|
15
|
+
* `DatabasePlanner` calls `add` for every schema file of the repository, and
|
|
16
|
+
* `CodePlanner` calls `plan` for a `.sql` file that belongs to a skill.
|
|
17
|
+
* `RepositoryScanner` creates one per scan with the `TableRegistry` it shares
|
|
18
|
+
* with the `CatalogPlanner`; `DatabasePlanner` shows the wiring.
|
|
19
|
+
*/
|
|
20
|
+
export declare class SqlPlanner {
|
|
21
|
+
private readonly graph;
|
|
22
|
+
private readonly markdown;
|
|
23
|
+
private readonly highlighter;
|
|
24
|
+
private readonly resolvers;
|
|
25
|
+
private readonly tables;
|
|
26
|
+
private readonly reporter;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a planner.
|
|
29
|
+
*
|
|
30
|
+
* @param markdown - Renders comments.
|
|
31
|
+
* @param highlighter - Highlights the statements of views and triggers.
|
|
32
|
+
* @param resolvers - Links what comments refer to.
|
|
33
|
+
* @param tables - Receives every table with its columns, and finds the targets of foreign keys.
|
|
34
|
+
* @param reporter - Receives files that cannot be read.
|
|
35
|
+
*/
|
|
36
|
+
constructor(graph: GraphBuilder, markdown: MarkdownRenderer, highlighter: CodeHighlighter, resolvers: ProseResolvers, tables: TableRegistry, reporter?: Reporter);
|
|
37
|
+
/**
|
|
38
|
+
* Tells whether a file is SQL: its extension is `.sql`, in any case.
|
|
39
|
+
*/
|
|
40
|
+
handles(path: string): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Reads one SQL file and adds its nodes when it creates a table.
|
|
43
|
+
*
|
|
44
|
+
* @param parent - Gives the folder or skill the file is in. Called only when the file creates a table, so a folder with nothing else in it is not added.
|
|
45
|
+
* @returns The node of the file, or `null` when it creates no table or cannot be read.
|
|
46
|
+
*/
|
|
47
|
+
plan(file: SourceFile, parent: () => NodeRef): Promise<NodeRef | null>;
|
|
48
|
+
/**
|
|
49
|
+
* Adds the nodes of one schema file.
|
|
50
|
+
*
|
|
51
|
+
* @param schema - What the file declares, from `parseSqlSchema`.
|
|
52
|
+
* @param parent - The folder or skill the file is in.
|
|
53
|
+
* @returns The node of the file.
|
|
54
|
+
*/
|
|
55
|
+
add(file: SourceFile, schema: ParsedSchema, parent: NodeRef): NodeRef;
|
|
56
|
+
/**
|
|
57
|
+
* Resolves a foreign key against the tables of the scan, and records the
|
|
58
|
+
* edge to its target.
|
|
59
|
+
*
|
|
60
|
+
* @param from - Node of the table that holds the key.
|
|
61
|
+
* @param path - Display path (`SourceFile.displayPath`) of the file the key is in.
|
|
62
|
+
* @returns The key with its target, and with the primary key of the target as its columns when the statement names none.
|
|
63
|
+
*/
|
|
64
|
+
private foreignKey;
|
|
65
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { QueryEffect, QueryTable } from '../../model';
|
|
2
|
+
/** A column a statement names. */
|
|
3
|
+
export interface ParsedColumnRef {
|
|
4
|
+
/** Name of the table in front of the column, with an alias replaced by its table. `null` for a column without one. */
|
|
5
|
+
readonly table: string | null;
|
|
6
|
+
/** Name of the column. `*` for every column. */
|
|
7
|
+
readonly column: string;
|
|
8
|
+
}
|
|
9
|
+
/** One placeholder of a statement. */
|
|
10
|
+
export interface ParsedParameter {
|
|
11
|
+
/** The placeholder as written: `:map_id`, `@id`, `$id`, `?2`. A plain `?` gets the number SQLite gives it: `?1`. */
|
|
12
|
+
readonly name: string;
|
|
13
|
+
/** The column the placeholder is compared with or stored in, when the statement shows one. */
|
|
14
|
+
readonly column: ParsedColumnRef | null;
|
|
15
|
+
/** True for the row count of a `LIMIT` or an `OFFSET`. */
|
|
16
|
+
readonly count: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** One column of the rows a statement returns. */
|
|
19
|
+
export interface ParsedResultColumn {
|
|
20
|
+
/** Name of the column in the result: its alias, else the column it selects, else the expression as written. `*` and `t.*` stand for every column of a table. */
|
|
21
|
+
readonly name: string;
|
|
22
|
+
/** The expression behind an alias, as written. `''` for a column of a table. */
|
|
23
|
+
readonly expression: string;
|
|
24
|
+
/** The column of a table it selects. `null` for an expression. */
|
|
25
|
+
readonly column: ParsedColumnRef | null;
|
|
26
|
+
}
|
|
27
|
+
/** A table a statement names, and what it does with it. */
|
|
28
|
+
export type ParsedQueryTable = Pick<QueryTable, 'name' | 'access'>;
|
|
29
|
+
/** One entry of a query catalog, as its file writes it. */
|
|
30
|
+
export interface ParsedQuery {
|
|
31
|
+
/** Name from a `-- name:` line above the SQL. `null` when the file has no such line, so the file names the entry. */
|
|
32
|
+
readonly name: string | null;
|
|
33
|
+
/** 1-based line the SQL starts on. */
|
|
34
|
+
readonly line: number;
|
|
35
|
+
readonly effect: QueryEffect;
|
|
36
|
+
/** The keywords that open the statement, in capitals: `SELECT`, `INSERT`, `BEGIN IMMEDIATE`. */
|
|
37
|
+
readonly verb: string;
|
|
38
|
+
/** Markdown from the comments above the SQL. */
|
|
39
|
+
readonly note: string;
|
|
40
|
+
/** The SQL as written, without the closing semicolon. */
|
|
41
|
+
readonly sql: string;
|
|
42
|
+
/** In the order SQLite numbers them, each once. */
|
|
43
|
+
readonly parameters: readonly ParsedParameter[];
|
|
44
|
+
/** In the order they first appear, each once per access. */
|
|
45
|
+
readonly tables: readonly ParsedQueryTable[];
|
|
46
|
+
/** In result order. Empty for a statement that returns no rows. */
|
|
47
|
+
readonly columns: readonly ParsedResultColumn[];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Reads a SQL file of a query catalog: a file of queries and statements that
|
|
51
|
+
* creates no table. The SQL is read as text and never run.
|
|
52
|
+
*
|
|
53
|
+
* A file is one entry, named by the file. A file that names its statements
|
|
54
|
+
* with comment lines such as `-- name: list_bookings` is one entry per name.
|
|
55
|
+
* The comments above the SQL of an entry are its note.
|
|
56
|
+
*
|
|
57
|
+
* @param source - Text of the file.
|
|
58
|
+
* @returns The entries in file order. Empty for a file without a statement.
|
|
59
|
+
*/
|
|
60
|
+
export declare function parseQueryFile(source: string): ParsedQuery[];
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { NodeRef } from '../../model';
|
|
2
|
+
/** A column of a table as the registry knows it. */
|
|
3
|
+
export interface ColumnEntry {
|
|
4
|
+
readonly ref: NodeRef;
|
|
5
|
+
/** Name of the column, as its table writes it. */
|
|
6
|
+
readonly name: string;
|
|
7
|
+
/** Declared type, or `''`. */
|
|
8
|
+
readonly type: string;
|
|
9
|
+
}
|
|
10
|
+
/** A table as the registry knows it. */
|
|
11
|
+
export interface TableEntry {
|
|
12
|
+
readonly ref: NodeRef;
|
|
13
|
+
/** Name of the table, as its statement writes it. */
|
|
14
|
+
readonly name: string;
|
|
15
|
+
/** Display path (`SourceFile.displayPath`) of the file that creates the table. */
|
|
16
|
+
readonly path: string;
|
|
17
|
+
/** Columns of its primary key, in key order. */
|
|
18
|
+
readonly primaryKey: readonly string[];
|
|
19
|
+
/** Its columns, in table order. */
|
|
20
|
+
readonly columns: readonly ColumnEntry[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Finds a column of a table by name. Capitals do not matter, as in SQLite.
|
|
24
|
+
*
|
|
25
|
+
* @returns The column, or `undefined` when the table has none of that name.
|
|
26
|
+
*/
|
|
27
|
+
export declare function columnOf(table: TableEntry, name: string): ColumnEntry | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Finds tables by name across the SQL files of one scan.
|
|
30
|
+
*
|
|
31
|
+
* `SqlPlanner` registers every table when it adds it, and looks tables up
|
|
32
|
+
* when the content of the graph is built. By then every file is read, so a
|
|
33
|
+
* foreign key can point at a table of a later file. `CatalogPlanner` looks
|
|
34
|
+
* up the tables and columns that queries name. Holds the tables by their
|
|
35
|
+
* lowercase name. `RepositoryScanner` creates one per scan and hands it to
|
|
36
|
+
* both planners.
|
|
37
|
+
*/
|
|
38
|
+
export declare class TableRegistry {
|
|
39
|
+
private readonly byName;
|
|
40
|
+
/** Records a table under its name. Capitals of the name do not matter, as in SQLite. */
|
|
41
|
+
register(entry: TableEntry): void;
|
|
42
|
+
/**
|
|
43
|
+
* Finds the table a name in a SQL file means.
|
|
44
|
+
*
|
|
45
|
+
* @param path - Display path of the file the name is in, as in `TableEntry.path`.
|
|
46
|
+
* @returns The table of that name in the same file, else the only table of that name in the scan, else `null`.
|
|
47
|
+
*/
|
|
48
|
+
find(name: string, path: string): TableEntry | null;
|
|
49
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SourceFile } from '../code/planner';
|
|
2
|
+
import type { Reporter } from '../reporter';
|
|
3
|
+
/**
|
|
4
|
+
* Reads the text of a SQL file.
|
|
5
|
+
*
|
|
6
|
+
* @param reporter - Receives a warning when the file cannot be read.
|
|
7
|
+
* @returns The text, or `null` for a file that is too large or cannot be read.
|
|
8
|
+
*/
|
|
9
|
+
export declare function readSqlFile(file: SourceFile, reporter: Reporter): Promise<string | null>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { SqlComment, SqlToken } from './tokens';
|
|
2
|
+
/**
|
|
3
|
+
* Turns comments into markdown.
|
|
4
|
+
*
|
|
5
|
+
* @param comments - Comments in file order.
|
|
6
|
+
* @returns Their text without ruler lines and shared indentation. Comments that are apart become paragraphs.
|
|
7
|
+
*/
|
|
8
|
+
export declare function markdownOf(comments: readonly SqlComment[]): string;
|
|
9
|
+
/**
|
|
10
|
+
* Finds the comments that describe what starts on a line: the comments on
|
|
11
|
+
* lines of their own directly above it, without a blank line between.
|
|
12
|
+
*
|
|
13
|
+
* @param comments - Every comment of the file, in file order.
|
|
14
|
+
* @param line - 1-based line the described statement or column starts on.
|
|
15
|
+
* @returns The comments, in file order.
|
|
16
|
+
*/
|
|
17
|
+
export declare function commentsAbove(comments: readonly SqlComment[], line: number): SqlComment[];
|
|
18
|
+
/** One statement of a file, with its tokens. */
|
|
19
|
+
export interface Statement {
|
|
20
|
+
readonly tokens: readonly SqlToken[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Splits the tokens of a file into statements at the semicolons. The
|
|
24
|
+
* semicolons inside the body of a trigger do not end its statement.
|
|
25
|
+
*
|
|
26
|
+
* @param tokens - Every token of the file.
|
|
27
|
+
* @returns The statements, each without its closing semicolon.
|
|
28
|
+
*/
|
|
29
|
+
export declare function statementsOf(tokens: readonly SqlToken[]): Statement[];
|
|
30
|
+
/**
|
|
31
|
+
* Reads a statement back as written.
|
|
32
|
+
*
|
|
33
|
+
* @param source - Text of the whole file.
|
|
34
|
+
* @returns The statement with its line breaks, without the closing semicolon.
|
|
35
|
+
*/
|
|
36
|
+
export declare function sqlOf(source: string, first: SqlToken, last: SqlToken): string;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** What a token of a SQL text is. A `name` is a quoted identifier. */
|
|
2
|
+
export type SqlTokenKind = 'word' | 'name' | 'string' | 'number' | 'symbol';
|
|
3
|
+
/** One token of a SQL text. Comments are no tokens. */
|
|
4
|
+
export interface SqlToken {
|
|
5
|
+
readonly kind: SqlTokenKind;
|
|
6
|
+
/** The token without quotes and escapes. For a word, a number or a symbol: the token as written. */
|
|
7
|
+
readonly value: string;
|
|
8
|
+
/** 1-based line the token starts on. */
|
|
9
|
+
readonly line: number;
|
|
10
|
+
/** 1-based line the token ends on. */
|
|
11
|
+
readonly endLine: number;
|
|
12
|
+
/** Offset of the first character in the text. */
|
|
13
|
+
readonly start: number;
|
|
14
|
+
/** Offset behind the last character. */
|
|
15
|
+
readonly end: number;
|
|
16
|
+
}
|
|
17
|
+
/** One comment of a SQL text. */
|
|
18
|
+
export interface SqlComment {
|
|
19
|
+
/** The comment without its markers, one entry per line. */
|
|
20
|
+
readonly lines: readonly string[];
|
|
21
|
+
/** 1-based line the comment starts on. */
|
|
22
|
+
readonly line: number;
|
|
23
|
+
/** 1-based line the comment ends on. */
|
|
24
|
+
readonly endLine: number;
|
|
25
|
+
/** True when no token is in front of the comment on its line. */
|
|
26
|
+
readonly alone: boolean;
|
|
27
|
+
}
|
|
28
|
+
/** The tokens and the comments of a SQL text, from `tokenizeSql`. */
|
|
29
|
+
export interface SqlTokens {
|
|
30
|
+
readonly tokens: readonly SqlToken[];
|
|
31
|
+
readonly comments: readonly SqlComment[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Splits a SQL text into tokens and comments.
|
|
35
|
+
*
|
|
36
|
+
* @returns The tokens in text order, and the comments apart from them. Text that is no SQL becomes symbol tokens, so the function never fails.
|
|
37
|
+
*/
|
|
38
|
+
export declare function tokenizeSql(source: string): SqlTokens;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Folder of a phase that holds its task files. */
|
|
2
|
+
export declare const TASKS_DIR = "tasks";
|
|
3
|
+
/** Folder of a plan that holds its decision files. */
|
|
4
|
+
export declare const DECISIONS_DIR = "decisions";
|
|
5
|
+
/** File at the root of the tree that holds its terms. */
|
|
6
|
+
export declare const VOCABULARY_FILE = "vocabulary.md";
|
|
7
|
+
/** A phase of the tree as its files lay it out. */
|
|
8
|
+
export interface PhaseFiles {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
/** Tree-relative path of `<plan>/<phase>/<phase>.md`. */
|
|
11
|
+
readonly file: string;
|
|
12
|
+
/** Tree-relative paths of the task files, sorted by name. */
|
|
13
|
+
readonly tasks: readonly string[];
|
|
14
|
+
}
|
|
15
|
+
/** A plan of the tree as its files lay it out. */
|
|
16
|
+
export interface PlanFiles {
|
|
17
|
+
readonly name: string;
|
|
18
|
+
/** Tree-relative path of `<plan>/<plan>.md`. */
|
|
19
|
+
readonly file: string;
|
|
20
|
+
/** Sorted by folder name, which is the order task-manager queues them in. */
|
|
21
|
+
readonly phases: readonly PhaseFiles[];
|
|
22
|
+
/** Tree-relative paths of the decision files, sorted by name. */
|
|
23
|
+
readonly decisions: readonly string[];
|
|
24
|
+
}
|
|
25
|
+
/** The task tree as its files lay it out. */
|
|
26
|
+
export interface TreeFiles {
|
|
27
|
+
readonly plans: readonly PlanFiles[];
|
|
28
|
+
/** Tree-relative path of the vocabulary, or `null` when the tree has none. */
|
|
29
|
+
readonly vocabulary: string | null;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Sorts the files of a task tree into plans, phases, tasks and decisions by
|
|
33
|
+
* where they are: `<plan>/<plan>.md`, `<plan>/<phase>/<phase>.md`,
|
|
34
|
+
* `<plan>/<phase>/tasks/<id>.md` and `<plan>/decisions/<id>.md`. Index files
|
|
35
|
+
* and any other file are left out, since task-manager derives them.
|
|
36
|
+
*
|
|
37
|
+
* @param files - Paths relative to the root of the tree, in POSIX form.
|
|
38
|
+
* @returns The plans in folder order, each with its phases and decisions.
|
|
39
|
+
*/
|
|
40
|
+
export declare function layoutTree(files: readonly string[]): TreeFiles;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { NodeRef } from '../../model';
|
|
2
|
+
import type { FileRenderer } from '../content';
|
|
3
|
+
import type { Source } from '../files';
|
|
4
|
+
import type { GlossaryPlanner } from '../glossary/planner';
|
|
5
|
+
import type { GraphBuilder } from '../graph/builder';
|
|
6
|
+
import type { ProseResolvers } from '../markdown/links';
|
|
7
|
+
import type { MarkdownRenderer } from '../markdown/renderer';
|
|
8
|
+
import type { Reporter } from '../reporter';
|
|
9
|
+
/** The task tree of one scan: the files below its directory, with paths relative to the scanned root. */
|
|
10
|
+
export interface TaskTreeSource extends Source {
|
|
11
|
+
/** Root-relative POSIX path of the tree, such as `docs/task-manager`. */
|
|
12
|
+
readonly dir: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Adds the tasks section to the graph from a task-manager tree: one `plan`
|
|
16
|
+
* page per plan, one `phase` page per phase, one `task` entry per task file,
|
|
17
|
+
* a `decisions` page per plan with decision files, and the `vocabulary.md`
|
|
18
|
+
* of the tree as a glossary. Created by `RepositoryScanner` for every scan.
|
|
19
|
+
*
|
|
20
|
+
* What a plan, a phase or a task links to or names in inline code becomes a
|
|
21
|
+
* `names` edge, and every `depends_on` a `depends` edge. A file whose
|
|
22
|
+
* frontmatter fails its schema is reported and shown as a plain document.
|
|
23
|
+
*
|
|
24
|
+
* Holds the graph, the file renderer, the markdown renderer, the prose
|
|
25
|
+
* resolvers, the `GlossaryPlanner` for the vocabulary and the reporter for
|
|
26
|
+
* warnings.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* await new TaskPlanner(graph, files, markdown, resolvers, glossaries, reporter).plan(sections.tasks, input.tasks);
|
|
30
|
+
*/
|
|
31
|
+
export declare class TaskPlanner {
|
|
32
|
+
private readonly graph;
|
|
33
|
+
private readonly files;
|
|
34
|
+
private readonly markdown;
|
|
35
|
+
private readonly resolvers;
|
|
36
|
+
private readonly glossaries;
|
|
37
|
+
private readonly reporter;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a planner.
|
|
40
|
+
*
|
|
41
|
+
* @param reporter - Receives a warning for every file that fails its schema and every `depends_on` that names nothing.
|
|
42
|
+
*/
|
|
43
|
+
constructor(graph: GraphBuilder, files: FileRenderer, markdown: MarkdownRenderer, resolvers: ProseResolvers, glossaries: GlossaryPlanner, reporter: Reporter);
|
|
44
|
+
/**
|
|
45
|
+
* Adds every plan of the trees, with its phases, tasks and decisions.
|
|
46
|
+
*
|
|
47
|
+
* @param section - Node of the tasks section.
|
|
48
|
+
* @param trees - The task trees of the scan. Usually one, or none when the repository keeps no tasks.
|
|
49
|
+
*/
|
|
50
|
+
plan(section: NodeRef, trees: readonly TaskTreeSource[]): Promise<void>;
|
|
51
|
+
/** Adds one plan with its phases and decisions. */
|
|
52
|
+
private planPlan;
|
|
53
|
+
/** Adds one phase with its tasks. */
|
|
54
|
+
private planPhase;
|
|
55
|
+
/** Adds the decision log of a plan: one `decisions` page for its folder and one `decision` entry per file. */
|
|
56
|
+
private planDecisions;
|
|
57
|
+
/**
|
|
58
|
+
* Renders the page of a plan or a phase whose frontmatter passed its schema.
|
|
59
|
+
*
|
|
60
|
+
* @returns The content of the node: the rendered file, its title and summary, and where it stands.
|
|
61
|
+
*/
|
|
62
|
+
private renderTracked;
|
|
63
|
+
/** Adds a tree file whose frontmatter failed its schema as a plain document. */
|
|
64
|
+
private planDocument;
|
|
65
|
+
/**
|
|
66
|
+
* Checks the frontmatter of a file against its schema, and reports the file when it fails.
|
|
67
|
+
*
|
|
68
|
+
* @returns The parsed frontmatter, or `null` when it failed.
|
|
69
|
+
*/
|
|
70
|
+
private parse;
|
|
71
|
+
/** Reads a file of the tree and splits off its frontmatter. */
|
|
72
|
+
private read;
|
|
73
|
+
/** The paths of a tree file as the planners of the docs section take them. */
|
|
74
|
+
private docFile;
|
|
75
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** Frontmatter of a plan file, `<plan>/<plan>.md`. Fields the site does not show are let through unread. */
|
|
3
|
+
export declare const PlanFrontmatterSchema: z.ZodObject<{
|
|
4
|
+
name: z.ZodString;
|
|
5
|
+
title: z.ZodString;
|
|
6
|
+
priority: z.ZodEnum<{
|
|
7
|
+
critical: "critical";
|
|
8
|
+
high: "high";
|
|
9
|
+
low: "low";
|
|
10
|
+
medium: "medium";
|
|
11
|
+
}>;
|
|
12
|
+
depends_on: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
13
|
+
summary: z.ZodString;
|
|
14
|
+
status: z.ZodEnum<{
|
|
15
|
+
blocked: "blocked";
|
|
16
|
+
completed: "completed";
|
|
17
|
+
"in-progress": "in-progress";
|
|
18
|
+
"in-review": "in-review";
|
|
19
|
+
open: "open";
|
|
20
|
+
}>;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
/** Parsed frontmatter of a plan file. */
|
|
23
|
+
export type PlanFrontmatter = z.infer<typeof PlanFrontmatterSchema>;
|
|
24
|
+
/** Frontmatter of a phase file, `<plan>/<phase>/<phase>.md`. task-manager spells the parallel flag `parrallel`. */
|
|
25
|
+
export declare const PhaseFrontmatterSchema: z.ZodObject<{
|
|
26
|
+
name: z.ZodString;
|
|
27
|
+
title: z.ZodString;
|
|
28
|
+
priority: z.ZodEnum<{
|
|
29
|
+
critical: "critical";
|
|
30
|
+
high: "high";
|
|
31
|
+
low: "low";
|
|
32
|
+
medium: "medium";
|
|
33
|
+
}>;
|
|
34
|
+
depends_on: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
35
|
+
summary: z.ZodString;
|
|
36
|
+
status: z.ZodEnum<{
|
|
37
|
+
blocked: "blocked";
|
|
38
|
+
completed: "completed";
|
|
39
|
+
"in-progress": "in-progress";
|
|
40
|
+
"in-review": "in-review";
|
|
41
|
+
open: "open";
|
|
42
|
+
}>;
|
|
43
|
+
parrallel: z.ZodOptional<z.ZodBoolean>;
|
|
44
|
+
parallel: z.ZodOptional<z.ZodBoolean>;
|
|
45
|
+
}, z.core.$strip>;
|
|
46
|
+
/** Parsed frontmatter of a phase file. */
|
|
47
|
+
export type PhaseFrontmatter = z.infer<typeof PhaseFrontmatterSchema>;
|
|
48
|
+
/** Frontmatter of a task file, `<plan>/<phase>/tasks/<id>.md`. */
|
|
49
|
+
export declare const TaskFrontmatterSchema: z.ZodObject<{
|
|
50
|
+
id: z.ZodString;
|
|
51
|
+
title: z.ZodString;
|
|
52
|
+
package: z.ZodString;
|
|
53
|
+
priority: z.ZodEnum<{
|
|
54
|
+
critical: "critical";
|
|
55
|
+
high: "high";
|
|
56
|
+
low: "low";
|
|
57
|
+
medium: "medium";
|
|
58
|
+
}>;
|
|
59
|
+
depends_on: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
60
|
+
summary: z.ZodString;
|
|
61
|
+
complexity: z.ZodOptional<z.ZodNumber>;
|
|
62
|
+
status: z.ZodEnum<{
|
|
63
|
+
blocked: "blocked";
|
|
64
|
+
completed: "completed";
|
|
65
|
+
"in-progress": "in-progress";
|
|
66
|
+
"in-review": "in-review";
|
|
67
|
+
open: "open";
|
|
68
|
+
}>;
|
|
69
|
+
}, z.core.$strip>;
|
|
70
|
+
/** Parsed frontmatter of a task file. */
|
|
71
|
+
export type TaskFrontmatter = z.infer<typeof TaskFrontmatterSchema>;
|
|
72
|
+
/** Frontmatter of a decision file in a plan's `decisions/` folder. */
|
|
73
|
+
export declare const DecisionFrontmatterSchema: z.ZodObject<{
|
|
74
|
+
id: z.ZodString;
|
|
75
|
+
title: z.ZodString;
|
|
76
|
+
status: z.ZodString;
|
|
77
|
+
date: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodDate, z.ZodTransform<string, Date>>]>>;
|
|
78
|
+
supersedes: z.ZodOptional<z.ZodString>;
|
|
79
|
+
}, z.core.$strip>;
|
|
80
|
+
/** Parsed frontmatter of a decision file. */
|
|
81
|
+
export type DecisionFrontmatter = z.infer<typeof DecisionFrontmatterSchema>;
|
|
82
|
+
/**
|
|
83
|
+
* Describes why a frontmatter block failed its schema, for a warning.
|
|
84
|
+
*
|
|
85
|
+
* @param error - The error of a failed `safeParse`.
|
|
86
|
+
* @returns The issues joined, such as `status: Invalid option; summary: Required`.
|
|
87
|
+
*/
|
|
88
|
+
export declare function describeIssues(error: z.ZodError): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Turns a text into a lowercase, hyphen-separated identifier that is safe in a URL path segment, or `untitled`. */
|
|
2
|
+
export declare function slugify(value: string): string;
|
|
3
|
+
/** Returns `base`, or `base-2`, `base-3`… when `base` is already in `taken`, and adds the result to `taken`. */
|
|
4
|
+
export declare function uniqueId(base: string, taken: Set<string>, separator?: string): string;
|
|
5
|
+
/** Removes the indentation shared by every non-blank line. */
|
|
6
|
+
export declare function dedent(text: string): string;
|
|
7
|
+
/** Dedents and drops leading and trailing blank lines. */
|
|
8
|
+
export declare function trimBlock(text: string): string;
|
|
9
|
+
/** Escapes `&`, `<`, `>` and `"` for HTML text and attribute values. */
|
|
10
|
+
export declare function escapeHtml(value: string): string;
|
|
11
|
+
/** Converts a name in any case to camelCase, such as `user_id` to `userId`. */
|
|
12
|
+
export declare function toCamelCase(name: string): string;
|
|
13
|
+
/** Converts a name in any case to snake_case, such as `userId` to `user_id`. */
|
|
14
|
+
export declare function toSnakeCase(name: string): string;
|