@g3nomaly/analyze 0.1.0 → 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/README.md +10 -5
- package/dist/api/bundle-builder.d.ts +29 -10
- package/dist/api/bundle-cache.d.ts +7 -4
- package/dist/api/bundle-loader.d.ts +10 -3
- package/dist/api/create-docs.d.ts +33 -14
- package/dist/api/embedding.d.ts +16 -7
- package/dist/api/errors.d.ts +13 -6
- package/dist/api/list.d.ts +20 -20
- package/dist/api/options.d.ts +18 -22
- package/dist/api/refs.d.ts +24 -21
- package/dist/api/scan.d.ts +24 -12
- package/dist/api/search.d.ts +27 -21
- package/dist/api/services.d.ts +9 -1
- package/dist/api/show.d.ts +15 -19
- package/dist/api/site-reader.d.ts +11 -3
- package/dist/api/site-writer.d.ts +30 -7
- package/dist/api/source.d.ts +23 -12
- package/dist/api/target.d.ts +2 -0
- package/dist/cli.js +670 -238
- package/dist/embeddings/index-builder.d.ts +3 -1
- package/dist/embeddings/model.d.ts +26 -13
- package/dist/embeddings/searcher.d.ts +24 -7
- package/dist/embeddings/vectors.d.ts +3 -1
- package/dist/embeddings/words.d.ts +7 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +647 -229
- package/dist/model/index.d.ts +416 -188
- package/dist/model/registry.d.ts +204 -11
- package/dist/query/graph.d.ts +83 -26
- package/dist/query/name-search.d.ts +39 -21
- package/dist/query/semantic.d.ts +11 -3
- package/dist/retrieval/describe.d.ts +11 -4
- package/dist/retrieval/filter.d.ts +27 -8
- package/dist/retrieval/index.d.ts +1 -1
- package/dist/retrieval/markdown.d.ts +3 -2
- package/dist/retrieval/report.d.ts +147 -70
- package/dist/retrieval/resolve.d.ts +11 -7
- package/dist/retrieval/retriever.d.ts +34 -23
- package/dist/retrieval/summary.d.ts +6 -3
- package/dist/scanner/code/doc/clean.d.ts +31 -5
- package/dist/scanner/code/doc/index.d.ts +7 -1
- package/dist/scanner/code/doc/markdown.d.ts +6 -1
- package/dist/scanner/code/doc/python.d.ts +6 -1
- package/dist/scanner/code/doc/tagged.d.ts +13 -4
- package/dist/scanner/code/doc/types.d.ts +16 -5
- package/dist/scanner/code/doc/xml.d.ts +6 -1
- package/dist/scanner/code/example.d.ts +31 -10
- package/dist/scanner/code/extract.d.ts +56 -21
- package/dist/scanner/code/grammar.d.ts +20 -5
- package/dist/scanner/code/language.d.ts +100 -66
- package/dist/scanner/code/languages/index.d.ts +21 -7
- package/dist/scanner/code/languages/shared.d.ts +23 -4
- package/dist/scanner/code/planner.d.ts +50 -14
- package/dist/scanner/code/symbols.d.ts +86 -20
- package/dist/scanner/code/types.d.ts +48 -15
- package/dist/scanner/config.d.ts +42 -0
- package/dist/scanner/content.d.ts +49 -14
- package/dist/scanner/decisions/parse.d.ts +20 -11
- package/dist/scanner/decisions/planner.d.ts +20 -8
- package/dist/scanner/docs.d.ts +36 -19
- package/dist/scanner/files.d.ts +44 -19
- package/dist/scanner/glossary/parse.d.ts +17 -7
- package/dist/scanner/glossary/planner.d.ts +15 -8
- package/dist/scanner/glossary/terms.d.ts +57 -27
- package/dist/scanner/graph/builder.d.ts +80 -21
- package/dist/scanner/highlight.d.ts +32 -9
- package/dist/scanner/ignore.d.ts +25 -0
- package/dist/scanner/index.d.ts +5 -2
- package/dist/scanner/markdown/frontmatter.d.ts +18 -3
- package/dist/scanner/markdown/links.d.ts +19 -9
- package/dist/scanner/markdown/outline.d.ts +13 -5
- package/dist/scanner/markdown/renderer.d.ts +32 -13
- package/dist/scanner/openapi/planner.d.ts +20 -8
- package/dist/scanner/packages.d.ts +28 -0
- package/dist/scanner/reporter.d.ts +5 -2
- package/dist/scanner/scanner.d.ts +21 -7
- package/dist/scanner/schema/definitions.d.ts +18 -8
- package/dist/scanner/schema/describe.d.ts +44 -18
- package/dist/scanner/schema/planner.d.ts +6 -3
- package/dist/scanner/schema/registry.d.ts +23 -16
- package/dist/scanner/skills/classify.d.ts +2 -1
- package/dist/scanner/skills/layout.d.ts +27 -9
- package/dist/scanner/skills/planner.d.ts +19 -4
- package/dist/scanner/specs.d.ts +8 -2
- package/dist/scanner/sql/catalog.d.ts +21 -7
- package/dist/scanner/sql/cursor.d.ts +9 -4
- package/dist/scanner/sql/database.d.ts +6 -3
- package/dist/scanner/sql/parse.d.ts +62 -27
- package/dist/scanner/sql/planner.d.ts +6 -2
- package/dist/scanner/sql/query.d.ts +34 -21
- package/dist/scanner/sql/registry.d.ts +24 -10
- package/dist/scanner/sql/source.d.ts +1 -0
- package/dist/scanner/sql/statements.d.ts +9 -3
- package/dist/scanner/sql/tokens.d.ts +25 -12
- package/dist/scanner/tasks/layout.d.ts +22 -10
- package/dist/scanner/tasks/planner.d.ts +64 -9
- package/package.json +2 -2
package/dist/scanner/specs.d.ts
CHANGED
|
@@ -5,18 +5,20 @@ import { type Reporter } from './reporter';
|
|
|
5
5
|
import { type JsonObject } from './schema/describe';
|
|
6
6
|
import type { JsonSchemaPlanner } from './schema/planner';
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Kind of a spec: a JSON or YAML file that describes data or an API in a
|
|
9
9
|
* standard format: an OpenAPI document or a JSON Schema.
|
|
10
10
|
*/
|
|
11
11
|
export type SpecKind = 'openapi' | 'json-schema';
|
|
12
12
|
/**
|
|
13
13
|
* Tells what kind of spec a parsed file is.
|
|
14
14
|
*
|
|
15
|
+
* @param path - Path of the file, whose name is checked against the schema names.
|
|
16
|
+
* @param document - The parsed file.
|
|
15
17
|
* @returns `openapi` for a document with an `openapi` version 3 and paths, components or webhooks. `json-schema` for a document whose `$schema` names JSON Schema, or that is named like a schema and uses its keywords. `null` for anything else.
|
|
16
18
|
*/
|
|
17
19
|
export declare function specKind(path: string, document: JsonObject): SpecKind | null;
|
|
18
20
|
/**
|
|
19
|
-
* Adds the specs among the JSON and YAML files of a scan to the graph.
|
|
21
|
+
* @brief Adds the specs among the JSON and YAML files of a scan to the graph.
|
|
20
22
|
*
|
|
21
23
|
* Used by `DocPlanner` and `SkillPlanner` for every JSON or YAML file, before
|
|
22
24
|
* they add the file as plain text. The file is parsed once here, and goes to
|
|
@@ -29,6 +31,8 @@ export declare class SpecPlanner {
|
|
|
29
31
|
/**
|
|
30
32
|
* Keeps the planner of each spec kind.
|
|
31
33
|
*
|
|
34
|
+
* @param openapi - Plans OpenAPI documents.
|
|
35
|
+
* @param schemas - Plans JSON Schemas.
|
|
32
36
|
* @param reporter - Receives files that cannot be read.
|
|
33
37
|
*/
|
|
34
38
|
constructor(openapi: OpenApiPlanner, schemas: JsonSchemaPlanner, reporter?: Reporter);
|
|
@@ -37,6 +41,7 @@ export declare class SpecPlanner {
|
|
|
37
41
|
/**
|
|
38
42
|
* Reads one file and adds it when it is a spec.
|
|
39
43
|
*
|
|
44
|
+
* @param file - The file to read, with its root and path.
|
|
40
45
|
* @param parent - Gives the folder or skill the file is in. Called only for a spec, so a folder with nothing else in it is not added.
|
|
41
46
|
* @returns The node of the file, or `null` when the file is no spec or cannot be parsed.
|
|
42
47
|
*/
|
|
@@ -44,6 +49,7 @@ export declare class SpecPlanner {
|
|
|
44
49
|
/**
|
|
45
50
|
* Parses a file.
|
|
46
51
|
*
|
|
52
|
+
* @param file - The file to read, with its root and path.
|
|
47
53
|
* @returns The parsed object, or `null` for a file that is too large, holds no object or is not valid.
|
|
48
54
|
*/
|
|
49
55
|
private read;
|
|
@@ -6,23 +6,32 @@ import type { ProseResolvers } from '../markdown/links';
|
|
|
6
6
|
import type { MarkdownRenderer } from '../markdown/renderer';
|
|
7
7
|
import type { ParsedQuery } from './query';
|
|
8
8
|
import { type TableRegistry } from './registry';
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* One SQL file of a catalog with the entries it holds.
|
|
11
|
+
*
|
|
12
|
+
* @property file - The SQL file, with its root and paths.
|
|
13
|
+
* @property queries - Entries from `parseQueryFile`. Not empty.
|
|
14
|
+
*/
|
|
10
15
|
export interface CatalogFile {
|
|
11
16
|
readonly file: SourceFile;
|
|
12
|
-
/** From `parseQueryFile`. Not empty. */
|
|
13
17
|
readonly queries: readonly ParsedQuery[];
|
|
14
18
|
}
|
|
15
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Where a catalog goes in the tree and what it is called.
|
|
21
|
+
*
|
|
22
|
+
* @property parent - Folder or section the catalog goes in.
|
|
23
|
+
* @property name - Name the catalog is shown under.
|
|
24
|
+
* @property slug - Segment of the route of the catalog, when it is not the name.
|
|
25
|
+
* @property path - Path of the directory of the catalog, as the site shows it.
|
|
26
|
+
*/
|
|
16
27
|
export interface CatalogPlace {
|
|
17
28
|
readonly parent: NodeRef;
|
|
18
29
|
readonly name: string;
|
|
19
|
-
/** Segment of the route of the catalog, when it is not the name. */
|
|
20
30
|
readonly slug?: string;
|
|
21
|
-
/** Path of the directory of the catalog, as the site shows it. */
|
|
22
31
|
readonly path: string;
|
|
23
32
|
}
|
|
24
33
|
/**
|
|
25
|
-
* Adds query catalogs to the graph: one `catalog` node per directory, one
|
|
34
|
+
* @brief Adds query catalogs to the graph: one `catalog` node per directory, one
|
|
26
35
|
* `query` node per entry, one `parameter` node per placeholder and one
|
|
27
36
|
* `field` node per column of the rows an entry returns. A table an entry
|
|
28
37
|
* names becomes a `reads` or a `writes` edge to that table.
|
|
@@ -42,6 +51,7 @@ export declare class CatalogPlanner {
|
|
|
42
51
|
/**
|
|
43
52
|
* Creates a planner.
|
|
44
53
|
*
|
|
54
|
+
* @param graph - Receives the catalog, entry, parameter and field nodes.
|
|
45
55
|
* @param markdown - Renders the notes of entries.
|
|
46
56
|
* @param highlighter - Highlights the SQL of entries.
|
|
47
57
|
* @param resolvers - Links what notes refer to.
|
|
@@ -51,6 +61,7 @@ export declare class CatalogPlanner {
|
|
|
51
61
|
/**
|
|
52
62
|
* Adds one catalog with its entries.
|
|
53
63
|
*
|
|
64
|
+
* @param place - Where the catalog goes in the tree and what it is called.
|
|
54
65
|
* @param files - The SQL files of the catalog, in display order.
|
|
55
66
|
* @returns The node of the catalog.
|
|
56
67
|
*/
|
|
@@ -59,6 +70,8 @@ export declare class CatalogPlanner {
|
|
|
59
70
|
* Adds one entry with its placeholders and its result columns.
|
|
60
71
|
*
|
|
61
72
|
* @param catalog - Node of the catalog.
|
|
73
|
+
* @param file - The SQL file the entry is in.
|
|
74
|
+
* @param query - The entry as parsed.
|
|
62
75
|
* @param anchors - Anchors the catalog uses already. The anchor of the entry is added.
|
|
63
76
|
* @returns The node of the entry.
|
|
64
77
|
*/
|
|
@@ -73,10 +86,11 @@ export declare class CatalogPlanner {
|
|
|
73
86
|
*/
|
|
74
87
|
private columnOf;
|
|
75
88
|
/**
|
|
76
|
-
* Replaces `*` and `t.*` in the result columns of an entry by the columns
|
|
89
|
+
* @brief Replaces `*` and `t.*` in the result columns of an entry by the columns
|
|
77
90
|
* of the tables they stand for. That needs the tables at the time the
|
|
78
91
|
* entry is added, so `DatabasePlanner` adds schema files first.
|
|
79
92
|
*
|
|
93
|
+
* @param query - The entry whose result columns are expanded.
|
|
80
94
|
* @param path - Display path (`SourceFile.displayPath`) of the file of the entry.
|
|
81
95
|
* @returns The result columns, with every star replaced whose tables the scan has. Any other star stays.
|
|
82
96
|
*/
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { SqlToken } from './tokens';
|
|
2
2
|
/**
|
|
3
|
-
* Error for a statement that cannot be read. Thrown by `TokenCursor` and by
|
|
3
|
+
* @brief Error for a statement that cannot be read. Thrown by `TokenCursor` and by
|
|
4
4
|
* the readers of `parse.ts`. `parseSqlSchema` catches it and skips the statement.
|
|
5
5
|
*/
|
|
6
6
|
export declare class SqlSyntaxError extends Error {
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
|
-
* Walks the tokens of one statement. Holds the tokens, the SQL text they come
|
|
9
|
+
* @brief Walks the tokens of one statement. Holds the tokens, the SQL text they come
|
|
10
10
|
* from and the position of the cursor. The functions of `parse.ts` that read a
|
|
11
11
|
* statement, a column or a constraint each take a cursor, read what they know
|
|
12
12
|
* and leave the cursor behind it. `parseSqlSchema` creates one per statement,
|
|
@@ -19,6 +19,7 @@ export declare class TokenCursor {
|
|
|
19
19
|
/**
|
|
20
20
|
* Creates a cursor at the first token.
|
|
21
21
|
*
|
|
22
|
+
* @param tokens - The tokens to walk, in order.
|
|
22
23
|
* @param source - The SQL text the tokens come from, for reading text back as written.
|
|
23
24
|
*/
|
|
24
25
|
constructor(tokens: readonly SqlToken[], source: string);
|
|
@@ -36,6 +37,7 @@ export declare class TokenCursor {
|
|
|
36
37
|
/**
|
|
37
38
|
* Takes the current token.
|
|
38
39
|
*
|
|
40
|
+
* @returns The token the cursor was on.
|
|
39
41
|
* @throws {SqlSyntaxError} At the end of the statement.
|
|
40
42
|
*/
|
|
41
43
|
next(): SqlToken;
|
|
@@ -67,8 +69,7 @@ export declare class TokenCursor {
|
|
|
67
69
|
*/
|
|
68
70
|
acceptSymbol(symbol: string): boolean;
|
|
69
71
|
/**
|
|
70
|
-
* Takes a name: an unquoted word
|
|
71
|
-
* because SQLite reads a string as a name where a name has to be.
|
|
72
|
+
* Takes a name: an unquoted word, a quoted identifier or a string.
|
|
72
73
|
*
|
|
73
74
|
* @returns The name without quotes.
|
|
74
75
|
* @throws {SqlSyntaxError} When the current token cannot be a name.
|
|
@@ -90,11 +91,15 @@ export declare class TokenCursor {
|
|
|
90
91
|
/**
|
|
91
92
|
* Reads SQL back as written, with runs of whitespace as one space.
|
|
92
93
|
*
|
|
94
|
+
* @param from - First token of the text.
|
|
93
95
|
* @param to - Last token of the text. Defaults to the token in front of the cursor.
|
|
94
96
|
*/
|
|
95
97
|
text(from: SqlToken, to?: SqlToken | undefined): string;
|
|
96
98
|
/**
|
|
97
99
|
* Creates a cursor for some of the tokens of the same text.
|
|
100
|
+
*
|
|
101
|
+
* @param tokens - Tokens of part of the statement, from the same text.
|
|
102
|
+
* @returns A cursor at the first of them.
|
|
98
103
|
*/
|
|
99
104
|
over(tokens: readonly SqlToken[]): TokenCursor;
|
|
100
105
|
}
|
|
@@ -5,13 +5,12 @@ import { type Reporter } from '../reporter';
|
|
|
5
5
|
import type { CatalogPlanner } from './catalog';
|
|
6
6
|
import type { SqlPlanner } from './planner';
|
|
7
7
|
/**
|
|
8
|
-
* Builds the database section from the SQL files of a directory tree.
|
|
8
|
+
* @brief Builds the database section from the SQL files of a directory tree.
|
|
9
9
|
*
|
|
10
10
|
* A file that creates a table is a schema and goes to the `SqlPlanner`.
|
|
11
11
|
* Every other SQL file holds queries and statements. The files of one
|
|
12
12
|
* directory form a catalog, which goes to the `CatalogPlanner`. The section
|
|
13
|
-
* starts at the directory the SQL files share
|
|
14
|
-
* through folders that hold nothing else.
|
|
13
|
+
* starts at the directory the SQL files share.
|
|
15
14
|
*
|
|
16
15
|
* `RepositoryScanner` creates one per scan and calls `planTree` once per
|
|
17
16
|
* source directory. The `SqlPlanner` and the `CatalogPlanner` share one
|
|
@@ -36,6 +35,9 @@ export declare class DatabasePlanner {
|
|
|
36
35
|
/**
|
|
37
36
|
* Creates a planner.
|
|
38
37
|
*
|
|
38
|
+
* @param graph - Receives the database section nodes.
|
|
39
|
+
* @param schemas - Plans the schema files.
|
|
40
|
+
* @param catalogs - Plans the query catalogs.
|
|
39
41
|
* @param reporter - Receives files that cannot be read.
|
|
40
42
|
*/
|
|
41
43
|
constructor(graph: GraphBuilder, schemas: SqlPlanner, catalogs: CatalogPlanner, reporter?: Reporter);
|
|
@@ -43,6 +45,7 @@ export declare class DatabasePlanner {
|
|
|
43
45
|
* Adds every SQL file of `source` below `section`.
|
|
44
46
|
*
|
|
45
47
|
* @param section - Node of the database section.
|
|
48
|
+
* @param source - The SQL files to read, with their root and prefix.
|
|
46
49
|
*/
|
|
47
50
|
planTree(section: NodeRef, source: Source): Promise<void>;
|
|
48
51
|
}
|
|
@@ -1,78 +1,113 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* What a `REFERENCES` clause states.
|
|
3
|
+
*
|
|
4
|
+
* @property table - Name of the referenced table.
|
|
5
|
+
* @property columns - Referenced columns. Empty when the clause names none, which means the primary key.
|
|
6
|
+
* @property onDelete - Action in capitals, or `''`.
|
|
7
|
+
* @property onUpdate - Action in capitals, or `''`.
|
|
8
|
+
*/
|
|
2
9
|
export interface ParsedReference {
|
|
3
|
-
/** Name of the referenced table. */
|
|
4
10
|
readonly table: string;
|
|
5
|
-
/** Referenced columns. Empty when the clause names none, which means the primary key. */
|
|
6
11
|
readonly columns: readonly string[];
|
|
7
|
-
/** Action in capitals, or `''`. */
|
|
8
12
|
readonly onDelete: string;
|
|
9
13
|
readonly onUpdate: string;
|
|
10
14
|
}
|
|
11
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* A foreign key of a table, from a column or from a table constraint.
|
|
17
|
+
*
|
|
18
|
+
* @property name - Name of the constraint, or `''`.
|
|
19
|
+
* @property sourceColumns - Columns of the table that hold the key.
|
|
20
|
+
*/
|
|
12
21
|
export interface ParsedForeignKey extends ParsedReference {
|
|
13
|
-
/** Name of the constraint, or `''`. */
|
|
14
22
|
readonly name: string;
|
|
15
|
-
/** Columns of the table that hold the key. */
|
|
16
23
|
readonly sourceColumns: readonly string[];
|
|
17
24
|
}
|
|
18
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* One column of a table as its statement writes it.
|
|
27
|
+
*
|
|
28
|
+
* @property name - Name of the column.
|
|
29
|
+
* @property type - Declared type as written, with single spaces. `''` for a column without one.
|
|
30
|
+
* @property notNull - True when the column is declared `NOT NULL`.
|
|
31
|
+
* @property defaultValue - Default value as written, or `null`.
|
|
32
|
+
* @property constraints - Other constraints of the column as written, such as `UNIQUE`, `CHECK (n > 0)` or `COLLATE NOCASE`.
|
|
33
|
+
* @property description - Markdown from the comment behind or above the column.
|
|
34
|
+
*/
|
|
19
35
|
export interface ParsedColumn {
|
|
20
36
|
readonly name: string;
|
|
21
|
-
/** Declared type as written, with single spaces. `''` for a column without one. */
|
|
22
37
|
readonly type: string;
|
|
23
|
-
/** True when the column is declared `NOT NULL`. */
|
|
24
38
|
readonly notNull: boolean;
|
|
25
|
-
/** Default value as written, or `null`. */
|
|
26
39
|
readonly defaultValue: string | null;
|
|
27
|
-
/** Other constraints of the column as written, such as `UNIQUE`, `CHECK (n > 0)` or `COLLATE NOCASE`. */
|
|
28
40
|
readonly constraints: readonly string[];
|
|
29
|
-
/** Markdown from the comment behind or above the column. */
|
|
30
41
|
readonly description: string;
|
|
31
42
|
}
|
|
32
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* An index of a table, from a `CREATE INDEX` statement.
|
|
45
|
+
*
|
|
46
|
+
* @property name - Name of the index.
|
|
47
|
+
* @property columns - Indexed columns or expressions as written.
|
|
48
|
+
* @property unique - True for a `UNIQUE` index.
|
|
49
|
+
*/
|
|
33
50
|
export interface ParsedIndex {
|
|
34
51
|
readonly name: string;
|
|
35
|
-
/** Indexed columns or expressions as written. */
|
|
36
52
|
readonly columns: readonly string[];
|
|
37
53
|
readonly unique: boolean;
|
|
38
54
|
}
|
|
39
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* One table of a schema.
|
|
57
|
+
*
|
|
58
|
+
* @property name - Name of the table.
|
|
59
|
+
* @property line - 1-based line of the statement.
|
|
60
|
+
* @property description - Markdown from the comment above the statement.
|
|
61
|
+
* @property columns - Columns of the table.
|
|
62
|
+
* @property primaryKey - Columns of the primary key, in key order.
|
|
63
|
+
* @property foreignKeys - Foreign keys of the table.
|
|
64
|
+
* @property constraints - Table constraints that are no key, as written.
|
|
65
|
+
* @property options - `WITHOUT ROWID`, `STRICT`, `VIRTUAL`, `TEMPORARY`.
|
|
66
|
+
* @property indexes - Indexes of the table.
|
|
67
|
+
*/
|
|
40
68
|
export interface ParsedTable {
|
|
41
69
|
readonly name: string;
|
|
42
|
-
/** 1-based line of the statement. */
|
|
43
70
|
readonly line: number;
|
|
44
|
-
/** Markdown from the comment above the statement. */
|
|
45
71
|
readonly description: string;
|
|
46
72
|
readonly columns: readonly ParsedColumn[];
|
|
47
|
-
/** Columns of the primary key, in key order. */
|
|
48
73
|
readonly primaryKey: readonly string[];
|
|
49
74
|
readonly foreignKeys: readonly ParsedForeignKey[];
|
|
50
|
-
/** Table constraints that are no key, as written. */
|
|
51
75
|
readonly constraints: readonly string[];
|
|
52
|
-
/** `WITHOUT ROWID`, `STRICT`, `VIRTUAL`, `TEMPORARY`. */
|
|
53
76
|
readonly options: readonly string[];
|
|
54
77
|
readonly indexes: readonly ParsedIndex[];
|
|
55
78
|
}
|
|
56
|
-
/**
|
|
79
|
+
/**
|
|
80
|
+
* A view or a trigger of a schema.
|
|
81
|
+
*
|
|
82
|
+
* @property kind - `view` or `trigger`.
|
|
83
|
+
* @property name - Name of the view or trigger.
|
|
84
|
+
* @property table - The table a trigger fires on. `''` for a view.
|
|
85
|
+
* @property line - 1-based line of the statement.
|
|
86
|
+
* @property description - Markdown from the comment above the statement.
|
|
87
|
+
* @property sql - The statement as written, without the closing semicolon.
|
|
88
|
+
*/
|
|
57
89
|
export interface ParsedObject {
|
|
58
90
|
readonly kind: 'view' | 'trigger';
|
|
59
91
|
readonly name: string;
|
|
60
|
-
/** The table a trigger fires on. `''` for a view. */
|
|
61
92
|
readonly table: string;
|
|
62
93
|
readonly line: number;
|
|
63
94
|
readonly description: string;
|
|
64
|
-
/** The statement as written, without the closing semicolon. */
|
|
65
95
|
readonly sql: string;
|
|
66
96
|
}
|
|
67
|
-
/**
|
|
97
|
+
/**
|
|
98
|
+
* What a schema file declares, from `parseSqlSchema`.
|
|
99
|
+
*
|
|
100
|
+
* @property intro - Markdown from the comments that open the file.
|
|
101
|
+
* @property tables - Tables the file creates, in file order.
|
|
102
|
+
* @property objects - Views and triggers the file creates, in file order.
|
|
103
|
+
*/
|
|
68
104
|
export interface ParsedSchema {
|
|
69
|
-
/** Markdown from the comments that open the file. */
|
|
70
105
|
readonly intro: string;
|
|
71
106
|
readonly tables: readonly ParsedTable[];
|
|
72
107
|
readonly objects: readonly ParsedObject[];
|
|
73
108
|
}
|
|
74
109
|
/**
|
|
75
|
-
* Reads the tables, indexes, views and triggers of a SQLite schema file.
|
|
110
|
+
* @brief Reads the tables, indexes, views and triggers of a SQLite schema file.
|
|
76
111
|
* Statements of any other kind, and statements that cannot be read, are
|
|
77
112
|
* skipped. The SQL is read as text and never run.
|
|
78
113
|
*
|
|
@@ -8,7 +8,7 @@ import { type Reporter } from '../reporter';
|
|
|
8
8
|
import { type ParsedSchema } from './parse';
|
|
9
9
|
import type { TableRegistry } from './registry';
|
|
10
10
|
/**
|
|
11
|
-
* Adds SQL schema files to the graph: one `database` node per file, one
|
|
11
|
+
* @brief Adds SQL schema files to the graph: one `database` node per file, one
|
|
12
12
|
* `table` node per table and one `field` node per column. A foreign key
|
|
13
13
|
* becomes a `references` edge from its table to the table it points at.
|
|
14
14
|
*
|
|
@@ -27,6 +27,7 @@ export declare class SqlPlanner {
|
|
|
27
27
|
/**
|
|
28
28
|
* Creates a planner.
|
|
29
29
|
*
|
|
30
|
+
* @param graph - Receives the database, table and field nodes.
|
|
30
31
|
* @param markdown - Renders comments.
|
|
31
32
|
* @param highlighter - Highlights the statements of views and triggers.
|
|
32
33
|
* @param resolvers - Links what comments refer to.
|
|
@@ -41,6 +42,7 @@ export declare class SqlPlanner {
|
|
|
41
42
|
/**
|
|
42
43
|
* Reads one SQL file and adds its nodes when it creates a table.
|
|
43
44
|
*
|
|
45
|
+
* @param file - The SQL file to read.
|
|
44
46
|
* @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
47
|
* @returns The node of the file, or `null` when it creates no table or cannot be read.
|
|
46
48
|
*/
|
|
@@ -48,16 +50,18 @@ export declare class SqlPlanner {
|
|
|
48
50
|
/**
|
|
49
51
|
* Adds the nodes of one schema file.
|
|
50
52
|
*
|
|
53
|
+
* @param file - The SQL file to add.
|
|
51
54
|
* @param schema - What the file declares, from `parseSqlSchema`.
|
|
52
55
|
* @param parent - The folder or skill the file is in.
|
|
53
56
|
* @returns The node of the file.
|
|
54
57
|
*/
|
|
55
58
|
add(file: SourceFile, schema: ParsedSchema, parent: NodeRef): NodeRef;
|
|
56
59
|
/**
|
|
57
|
-
* Resolves a foreign key against the tables of the scan, and records the
|
|
60
|
+
* @brief Resolves a foreign key against the tables of the scan, and records the
|
|
58
61
|
* edge to its target.
|
|
59
62
|
*
|
|
60
63
|
* @param from - Node of the table that holds the key.
|
|
64
|
+
* @param key - The foreign key as the statement wrote it.
|
|
61
65
|
* @param path - Display path (`SourceFile.displayPath`) of the file the key is in.
|
|
62
66
|
* @returns The key with its target, and with the primary key of the target as its columns when the statement names none.
|
|
63
67
|
*/
|
|
@@ -1,53 +1,66 @@
|
|
|
1
1
|
import type { QueryEffect, QueryTable } from '../../model';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* A column a statement names.
|
|
4
|
+
*
|
|
5
|
+
* @property table - Name of the table in front of the column, with an alias replaced by its table. `null` for a column without one.
|
|
6
|
+
* @property column - Name of the column. `*` for every column.
|
|
7
|
+
*/
|
|
3
8
|
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
9
|
readonly table: string | null;
|
|
6
|
-
/** Name of the column. `*` for every column. */
|
|
7
10
|
readonly column: string;
|
|
8
11
|
}
|
|
9
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* One placeholder of a statement.
|
|
14
|
+
*
|
|
15
|
+
* @property name - The placeholder as written: `:map_id`, `@id`, `$id`, `?2`. A plain `?` gets the number SQLite gives it: `?1`.
|
|
16
|
+
* @property column - The column the placeholder is compared with or stored in, when the statement shows one.
|
|
17
|
+
* @property count - True for the row count of a `LIMIT` or an `OFFSET`.
|
|
18
|
+
*/
|
|
10
19
|
export interface ParsedParameter {
|
|
11
|
-
/** The placeholder as written: `:map_id`, `@id`, `$id`, `?2`. A plain `?` gets the number SQLite gives it: `?1`. */
|
|
12
20
|
readonly name: string;
|
|
13
|
-
/** The column the placeholder is compared with or stored in, when the statement shows one. */
|
|
14
21
|
readonly column: ParsedColumnRef | null;
|
|
15
|
-
/** True for the row count of a `LIMIT` or an `OFFSET`. */
|
|
16
22
|
readonly count: boolean;
|
|
17
23
|
}
|
|
18
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* One column of the rows a statement returns.
|
|
26
|
+
*
|
|
27
|
+
* @property name - 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.
|
|
28
|
+
* @property expression - The expression behind an alias, as written. `''` for a column of a table.
|
|
29
|
+
* @property column - The column of a table it selects. `null` for an expression.
|
|
30
|
+
*/
|
|
19
31
|
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
32
|
readonly name: string;
|
|
22
|
-
/** The expression behind an alias, as written. `''` for a column of a table. */
|
|
23
33
|
readonly expression: string;
|
|
24
|
-
/** The column of a table it selects. `null` for an expression. */
|
|
25
34
|
readonly column: ParsedColumnRef | null;
|
|
26
35
|
}
|
|
27
36
|
/** A table a statement names, and what it does with it. */
|
|
28
37
|
export type ParsedQueryTable = Pick<QueryTable, 'name' | 'access'>;
|
|
29
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* One entry of a query catalog, as its file writes it.
|
|
40
|
+
*
|
|
41
|
+
* @property name - Name from a `-- name:` line above the SQL. `null` when the file has no such line, so the file names the entry.
|
|
42
|
+
* @property line - 1-based line the SQL starts on.
|
|
43
|
+
* @property effect - Whether the statement reads, writes or only controls.
|
|
44
|
+
* @property verb - The keywords that open the statement, in capitals: `SELECT`, `INSERT`, `BEGIN IMMEDIATE`.
|
|
45
|
+
* @property note - Markdown from the comments above the SQL.
|
|
46
|
+
* @property sql - The SQL as written, without the closing semicolon.
|
|
47
|
+
* @property parameters - Placeholders in the order SQLite numbers them, each once.
|
|
48
|
+
* @property tables - Tables the statement names, in the order they first appear, each once per access.
|
|
49
|
+
* @property columns - Result columns in result order. Empty for a statement that returns no rows.
|
|
50
|
+
*/
|
|
30
51
|
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
52
|
readonly name: string | null;
|
|
33
|
-
/** 1-based line the SQL starts on. */
|
|
34
53
|
readonly line: number;
|
|
35
54
|
readonly effect: QueryEffect;
|
|
36
|
-
/** The keywords that open the statement, in capitals: `SELECT`, `INSERT`, `BEGIN IMMEDIATE`. */
|
|
37
55
|
readonly verb: string;
|
|
38
|
-
/** Markdown from the comments above the SQL. */
|
|
39
56
|
readonly note: string;
|
|
40
|
-
/** The SQL as written, without the closing semicolon. */
|
|
41
57
|
readonly sql: string;
|
|
42
|
-
/** In the order SQLite numbers them, each once. */
|
|
43
58
|
readonly parameters: readonly ParsedParameter[];
|
|
44
|
-
/** In the order they first appear, each once per access. */
|
|
45
59
|
readonly tables: readonly ParsedQueryTable[];
|
|
46
|
-
/** In result order. Empty for a statement that returns no rows. */
|
|
47
60
|
readonly columns: readonly ParsedResultColumn[];
|
|
48
61
|
}
|
|
49
62
|
/**
|
|
50
|
-
* Reads a SQL file of a query catalog: a file of queries and statements that
|
|
63
|
+
* @brief Reads a SQL file of a query catalog: a file of queries and statements that
|
|
51
64
|
* creates no table. The SQL is read as text and never run.
|
|
52
65
|
*
|
|
53
66
|
* A file is one entry, named by the file. A file that names its statements
|
|
@@ -1,32 +1,42 @@
|
|
|
1
1
|
import type { NodeRef } from '../../model';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* A column of a table as the registry knows it.
|
|
4
|
+
*
|
|
5
|
+
* @property ref - Node of the column.
|
|
6
|
+
* @property name - Name of the column, as its table writes it.
|
|
7
|
+
* @property type - Declared type, or `''`.
|
|
8
|
+
*/
|
|
3
9
|
export interface ColumnEntry {
|
|
4
10
|
readonly ref: NodeRef;
|
|
5
|
-
/** Name of the column, as its table writes it. */
|
|
6
11
|
readonly name: string;
|
|
7
|
-
/** Declared type, or `''`. */
|
|
8
12
|
readonly type: string;
|
|
9
13
|
}
|
|
10
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* A table as the registry knows it.
|
|
16
|
+
*
|
|
17
|
+
* @property ref - Node of the table.
|
|
18
|
+
* @property name - Name of the table, as its statement writes it.
|
|
19
|
+
* @property path - Display path (`SourceFile.displayPath`) of the file that creates the table.
|
|
20
|
+
* @property primaryKey - Columns of its primary key, in key order.
|
|
21
|
+
* @property columns - Its columns, in table order.
|
|
22
|
+
*/
|
|
11
23
|
export interface TableEntry {
|
|
12
24
|
readonly ref: NodeRef;
|
|
13
|
-
/** Name of the table, as its statement writes it. */
|
|
14
25
|
readonly name: string;
|
|
15
|
-
/** Display path (`SourceFile.displayPath`) of the file that creates the table. */
|
|
16
26
|
readonly path: string;
|
|
17
|
-
/** Columns of its primary key, in key order. */
|
|
18
27
|
readonly primaryKey: readonly string[];
|
|
19
|
-
/** Its columns, in table order. */
|
|
20
28
|
readonly columns: readonly ColumnEntry[];
|
|
21
29
|
}
|
|
22
30
|
/**
|
|
23
31
|
* Finds a column of a table by name. Capitals do not matter, as in SQLite.
|
|
24
32
|
*
|
|
33
|
+
* @param table - The table to search.
|
|
34
|
+
* @param name - Name of the column, in any case.
|
|
25
35
|
* @returns The column, or `undefined` when the table has none of that name.
|
|
26
36
|
*/
|
|
27
37
|
export declare function columnOf(table: TableEntry, name: string): ColumnEntry | undefined;
|
|
28
38
|
/**
|
|
29
|
-
* Finds tables by name across the SQL files of one scan.
|
|
39
|
+
* @brief Finds tables by name across the SQL files of one scan.
|
|
30
40
|
*
|
|
31
41
|
* `SqlPlanner` registers every table when it adds it, and looks tables up
|
|
32
42
|
* when the content of the graph is built. By then every file is read, so a
|
|
@@ -37,7 +47,11 @@ export declare function columnOf(table: TableEntry, name: string): ColumnEntry |
|
|
|
37
47
|
*/
|
|
38
48
|
export declare class TableRegistry {
|
|
39
49
|
private readonly byName;
|
|
40
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Records a table under its name. Capitals of the name do not matter, as in SQLite.
|
|
52
|
+
*
|
|
53
|
+
* @param entry - The table to record.
|
|
54
|
+
*/
|
|
41
55
|
register(entry: TableEntry): void;
|
|
42
56
|
/**
|
|
43
57
|
* Finds the table a name in a SQL file means.
|
|
@@ -3,6 +3,7 @@ import type { Reporter } from '../reporter';
|
|
|
3
3
|
/**
|
|
4
4
|
* Reads the text of a SQL file.
|
|
5
5
|
*
|
|
6
|
+
* @param file - The SQL file to read, with its root and path.
|
|
6
7
|
* @param reporter - Receives a warning when the file cannot be read.
|
|
7
8
|
* @returns The text, or `null` for a file that is too large or cannot be read.
|
|
8
9
|
*/
|
|
@@ -7,7 +7,7 @@ import type { SqlComment, SqlToken } from './tokens';
|
|
|
7
7
|
*/
|
|
8
8
|
export declare function markdownOf(comments: readonly SqlComment[]): string;
|
|
9
9
|
/**
|
|
10
|
-
* Finds the comments that describe what starts on a line: the comments on
|
|
10
|
+
* @brief Finds the comments that describe what starts on a line: the comments on
|
|
11
11
|
* lines of their own directly above it, without a blank line between.
|
|
12
12
|
*
|
|
13
13
|
* @param comments - Every comment of the file, in file order.
|
|
@@ -15,12 +15,16 @@ export declare function markdownOf(comments: readonly SqlComment[]): string;
|
|
|
15
15
|
* @returns The comments, in file order.
|
|
16
16
|
*/
|
|
17
17
|
export declare function commentsAbove(comments: readonly SqlComment[], line: number): SqlComment[];
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* One statement of a file: the tokens it is made of, without its closing semicolon.
|
|
20
|
+
*
|
|
21
|
+
* @property tokens - Tokens of the statement, in text order.
|
|
22
|
+
*/
|
|
19
23
|
export interface Statement {
|
|
20
24
|
readonly tokens: readonly SqlToken[];
|
|
21
25
|
}
|
|
22
26
|
/**
|
|
23
|
-
* Splits the tokens of a file into statements at the semicolons. The
|
|
27
|
+
* @brief Splits the tokens of a file into statements at the semicolons. The
|
|
24
28
|
* semicolons inside the body of a trigger do not end its statement.
|
|
25
29
|
*
|
|
26
30
|
* @param tokens - Every token of the file.
|
|
@@ -31,6 +35,8 @@ export declare function statementsOf(tokens: readonly SqlToken[]): Statement[];
|
|
|
31
35
|
* Reads a statement back as written.
|
|
32
36
|
*
|
|
33
37
|
* @param source - Text of the whole file.
|
|
38
|
+
* @param first - Token the statement starts with.
|
|
39
|
+
* @param last - Token the statement ends with.
|
|
34
40
|
* @returns The statement with its line breaks, without the closing semicolon.
|
|
35
41
|
*/
|
|
36
42
|
export declare function sqlOf(source: string, first: SqlToken, last: SqlToken): string;
|
|
@@ -1,31 +1,43 @@
|
|
|
1
1
|
/** What a token of a SQL text is. A `name` is a quoted identifier. */
|
|
2
2
|
export type SqlTokenKind = 'word' | 'name' | 'string' | 'number' | 'symbol';
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* One token of a SQL text. Comments are no tokens.
|
|
5
|
+
*
|
|
6
|
+
* @property kind - What the token is.
|
|
7
|
+
* @property value - The token without quotes and escapes. For a word, a number or a symbol: the token as written.
|
|
8
|
+
* @property line - 1-based line the token starts on.
|
|
9
|
+
* @property endLine - 1-based line the token ends on.
|
|
10
|
+
* @property start - Offset of the first character in the text.
|
|
11
|
+
* @property end - Offset behind the last character.
|
|
12
|
+
*/
|
|
4
13
|
export interface SqlToken {
|
|
5
14
|
readonly kind: SqlTokenKind;
|
|
6
|
-
/** The token without quotes and escapes. For a word, a number or a symbol: the token as written. */
|
|
7
15
|
readonly value: string;
|
|
8
|
-
/** 1-based line the token starts on. */
|
|
9
16
|
readonly line: number;
|
|
10
|
-
/** 1-based line the token ends on. */
|
|
11
17
|
readonly endLine: number;
|
|
12
|
-
/** Offset of the first character in the text. */
|
|
13
18
|
readonly start: number;
|
|
14
|
-
/** Offset behind the last character. */
|
|
15
19
|
readonly end: number;
|
|
16
20
|
}
|
|
17
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* One comment of a SQL text.
|
|
23
|
+
*
|
|
24
|
+
* @property lines - The comment without its markers, one entry per line.
|
|
25
|
+
* @property line - 1-based line the comment starts on.
|
|
26
|
+
* @property endLine - 1-based line the comment ends on.
|
|
27
|
+
* @property alone - True when no token is in front of the comment on its line.
|
|
28
|
+
*/
|
|
18
29
|
export interface SqlComment {
|
|
19
|
-
/** The comment without its markers, one entry per line. */
|
|
20
30
|
readonly lines: readonly string[];
|
|
21
|
-
/** 1-based line the comment starts on. */
|
|
22
31
|
readonly line: number;
|
|
23
|
-
/** 1-based line the comment ends on. */
|
|
24
32
|
readonly endLine: number;
|
|
25
|
-
/** True when no token is in front of the comment on its line. */
|
|
26
33
|
readonly alone: boolean;
|
|
27
34
|
}
|
|
28
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* The tokens and the comments of a SQL text, from `tokenizeSql`.
|
|
37
|
+
*
|
|
38
|
+
* @property tokens - Tokens in text order.
|
|
39
|
+
* @property comments - Comments apart from the tokens, in text order.
|
|
40
|
+
*/
|
|
29
41
|
export interface SqlTokens {
|
|
30
42
|
readonly tokens: readonly SqlToken[];
|
|
31
43
|
readonly comments: readonly SqlComment[];
|
|
@@ -33,6 +45,7 @@ export interface SqlTokens {
|
|
|
33
45
|
/**
|
|
34
46
|
* Splits a SQL text into tokens and comments.
|
|
35
47
|
*
|
|
48
|
+
* @param source - The SQL text, as written in the file.
|
|
36
49
|
* @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
50
|
*/
|
|
38
51
|
export declare function tokenizeSql(source: string): SqlTokens;
|