@dbml/parse 6.2.0 → 6.3.0-alpha.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/dist/__tests__/examples/compiler/stringUtils.test.d.ts +1 -0
- package/dist/__tests__/examples/interpreter/record/data.test.d.ts +1 -0
- package/dist/__tests__/examples/interpreter/record/fk.test.d.ts +1 -0
- package/dist/__tests__/examples/interpreter/record/increment.test.d.ts +1 -0
- package/dist/__tests__/examples/interpreter/record/multi_records.test.d.ts +1 -0
- package/dist/__tests__/examples/interpreter/record/pk.test.d.ts +1 -0
- package/dist/__tests__/examples/interpreter/record/table_partial.test.d.ts +1 -0
- package/dist/__tests__/examples/interpreter/record/type_compatibility.test.d.ts +1 -0
- package/dist/__tests__/examples/interpreter/record/unique.test.d.ts +1 -0
- package/dist/__tests__/examples/lexer/scientific-notation.test.d.ts +1 -0
- package/dist/__tests__/examples/services/definition/general.test.d.ts +1 -0
- package/dist/__tests__/examples/services/definition/records.test.d.ts +1 -0
- package/dist/__tests__/examples/services/references/general.test.d.ts +1 -0
- package/dist/__tests__/examples/services/references/records.test.d.ts +1 -0
- package/dist/__tests__/examples/services/suggestions/general.test.d.ts +1 -0
- package/dist/__tests__/examples/services/suggestions/suggestions_records.test.d.ts +1 -0
- package/dist/__tests__/examples/validator/records.test.d.ts +1 -0
- package/dist/__tests__/utils/compiler.d.ts +5 -5
- package/dist/__tests__/utils/mocks.d.ts +1 -0
- package/dist/__tests__/utils/testHelpers.d.ts +2 -2
- package/dist/dbml-parse.js +11 -9
- package/dist/dbml-parse.mjs +7889 -3029
- package/dist/src/compiler/index.d.ts +8 -4
- package/dist/src/compiler/queries/parse.d.ts +2 -1
- package/dist/src/compiler/queries/transform/index.d.ts +2 -1
- package/dist/src/compiler/queries/transform/renameTable.d.ts +1 -4
- package/dist/src/compiler/queries/transform/utils.d.ts +22 -0
- package/dist/src/compiler/queries/utils.d.ts +95 -0
- package/dist/src/compiler/types.d.ts +2 -1
- package/dist/src/core/analyzer/analyzer.d.ts +2 -3
- package/dist/src/core/analyzer/binder/binder.d.ts +1 -2
- package/dist/src/core/analyzer/binder/elementBinder/records.d.ts +22 -0
- package/dist/src/core/analyzer/binder/utils.d.ts +2 -1
- package/dist/src/core/analyzer/types.d.ts +2 -1
- package/dist/src/core/analyzer/utils.d.ts +11 -1
- package/dist/src/core/analyzer/validator/elementValidators/records.d.ts +26 -0
- package/dist/src/core/analyzer/validator/utils.d.ts +3 -3
- package/dist/src/core/analyzer/validator/validator.d.ts +1 -2
- package/dist/src/core/errors.d.ts +15 -1
- package/dist/src/core/interpreter/interpreter.d.ts +1 -2
- package/dist/src/core/interpreter/records/index.d.ts +10 -0
- package/dist/src/core/interpreter/records/utils/constraints/fk.d.ts +3 -0
- package/dist/src/core/interpreter/records/utils/constraints/helper.d.ts +10 -0
- package/dist/src/core/interpreter/records/utils/constraints/index.d.ts +3 -0
- package/dist/src/core/interpreter/records/utils/constraints/pk.d.ts +3 -0
- package/dist/src/core/interpreter/records/utils/constraints/unique.d.ts +3 -0
- package/dist/src/core/interpreter/records/utils/data/index.d.ts +2 -0
- package/dist/src/core/interpreter/records/utils/data/sqlTypes.d.ts +19 -0
- package/dist/src/core/interpreter/records/utils/data/values.d.ts +14 -0
- package/dist/src/core/interpreter/records/utils/index.d.ts +2 -0
- package/dist/src/core/interpreter/types.d.ts +39 -2
- package/dist/src/core/interpreter/utils.d.ts +4 -3
- package/dist/src/core/lexer/lexer.d.ts +1 -2
- package/dist/src/core/parser/nodes.d.ts +17 -6
- package/dist/src/core/parser/parser.d.ts +6 -4
- package/dist/src/core/parser/utils.d.ts +3 -3
- package/dist/src/core/report.d.ts +8 -5
- package/dist/src/core/utils.d.ts +0 -1
- package/dist/src/index.d.ts +3 -4
- package/dist/src/services/diagnostics/provider.d.ts +34 -0
- package/dist/src/services/index.d.ts +2 -1
- package/dist/src/services/suggestions/recordRowSnippet.d.ts +3 -0
- package/dist/src/services/suggestions/utils.d.ts +27 -1
- package/dist/src/services/types.d.ts +13 -2
- package/package.json +5 -3
- package/dist/src/core/serialization/serialize.d.ts +0 -4
- /package/dist/__tests__/examples/{services/definition.test.d.ts → binder/records.test.d.ts} +0 -0
- /package/dist/__tests__/examples/{services/references.test.d.ts → compiler/identifierUtils.test.d.ts} +0 -0
- /package/dist/__tests__/examples/{services/suggestions.test.d.ts → compiler/splitQualifiedIdentifier.test.d.ts} +0 -0
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { ProgramNode } from '../core/parser/nodes';
|
|
2
2
|
import { SyntaxToken } from '../core/lexer/tokens';
|
|
3
|
-
import { CompileError } from '../core/errors';
|
|
4
3
|
import { Database } from '../core/interpreter/types';
|
|
5
4
|
import { default as Report } from '../core/report';
|
|
6
|
-
import { DBMLCompletionItemProvider, DBMLDefinitionProvider, DBMLReferencesProvider } from '../services/index';
|
|
5
|
+
import { DBMLCompletionItemProvider, DBMLDefinitionProvider, DBMLReferencesProvider, DBMLDiagnosticsProvider } from '../services/index';
|
|
7
6
|
import { TextEdit, TableNameInput } from './queries/transform';
|
|
7
|
+
import { splitQualifiedIdentifier, unescapeString, escapeString, formatRecordValue, isValidIdentifier, addDoubleQuoteIfNeeded } from './queries/utils';
|
|
8
8
|
export { ScopeKind } from './types';
|
|
9
|
+
export type { TextEdit, TableNameInput };
|
|
10
|
+
export { splitQualifiedIdentifier, unescapeString, escapeString, formatRecordValue, isValidIdentifier, addDoubleQuoteIfNeeded };
|
|
9
11
|
export default class Compiler {
|
|
10
12
|
private source;
|
|
11
13
|
private cache;
|
|
@@ -26,9 +28,10 @@ export default class Compiler {
|
|
|
26
28
|
ast: ProgramNode;
|
|
27
29
|
tokens: SyntaxToken[];
|
|
28
30
|
rawDb?: Database;
|
|
29
|
-
}
|
|
31
|
+
}>;
|
|
30
32
|
ast: () => Readonly<ProgramNode>;
|
|
31
|
-
errors: () => readonly Readonly<CompileError>[];
|
|
33
|
+
errors: () => readonly Readonly<import('..').CompileError>[];
|
|
34
|
+
warnings: () => readonly Readonly<import('../core/errors').CompileWarning>[];
|
|
32
35
|
tokens: () => Readonly<SyntaxToken>[];
|
|
33
36
|
rawDb: () => Readonly<Database> | undefined;
|
|
34
37
|
publicSymbolTable: () => Readonly<import('../core/analyzer/symbol/symbolTable').default>;
|
|
@@ -62,5 +65,6 @@ export default class Compiler {
|
|
|
62
65
|
definitionProvider: DBMLDefinitionProvider;
|
|
63
66
|
referenceProvider: DBMLReferencesProvider;
|
|
64
67
|
autocompletionProvider: DBMLCompletionItemProvider;
|
|
68
|
+
diagnosticsProvider: DBMLDiagnosticsProvider;
|
|
65
69
|
};
|
|
66
70
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { default as Compiler } from '../index';
|
|
2
2
|
import { ProgramNode } from '../../core/parser/nodes';
|
|
3
3
|
import { SyntaxToken } from '../../core/lexer/tokens';
|
|
4
|
-
import { CompileError } from '../../core/errors';
|
|
4
|
+
import { CompileError, CompileWarning } from '../../core/errors';
|
|
5
5
|
import { Database } from '../../core/interpreter/types';
|
|
6
6
|
import { default as SymbolTable } from '../../core/analyzer/symbol/symbolTable';
|
|
7
7
|
export declare function ast(this: Compiler): Readonly<ProgramNode>;
|
|
8
8
|
export declare function errors(this: Compiler): readonly Readonly<CompileError>[];
|
|
9
|
+
export declare function warnings(this: Compiler): readonly Readonly<CompileWarning>[];
|
|
9
10
|
export declare function tokens(this: Compiler): Readonly<SyntaxToken>[];
|
|
10
11
|
export declare function rawDb(this: Compiler): Readonly<Database> | undefined;
|
|
11
12
|
export declare function publicSymbolTable(this: Compiler): Readonly<SymbolTable>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { default as SymbolTable } from '../../../core/analyzer/symbol/symbolTable';
|
|
2
|
+
import { TableSymbol } from '../../../core/analyzer/symbol/symbols';
|
|
3
|
+
export type TableNameInput = string | {
|
|
4
|
+
schema?: string;
|
|
5
|
+
table: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Normalizes a table name input to { schema, table } format.
|
|
9
|
+
* Properly handles quoted identifiers with dots inside.
|
|
10
|
+
*/
|
|
11
|
+
export declare function normalizeTableName(input: TableNameInput): {
|
|
12
|
+
schema: string;
|
|
13
|
+
table: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Looks up a table symbol from the symbol table.
|
|
17
|
+
*/
|
|
18
|
+
export declare function lookupTableSymbol(symbolTable: Readonly<SymbolTable>, schema: string, table: string): TableSymbol | null;
|
|
19
|
+
/**
|
|
20
|
+
* Removes surrounding double quotes from a string if present.
|
|
21
|
+
*/
|
|
22
|
+
export declare function stripQuotes(str: string): string;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if an identifier is valid (can be used without quotes in DBML).
|
|
3
|
+
* Valid identifiers must:
|
|
4
|
+
* - Contain only alphanumeric characters and underscores
|
|
5
|
+
* - Not start with a digit
|
|
6
|
+
*
|
|
7
|
+
* @param name - The identifier to check
|
|
8
|
+
* @returns True if the identifier is valid and doesn't need quotes
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* isValidIdentifier('users') => true
|
|
12
|
+
* isValidIdentifier('user_name') => true
|
|
13
|
+
* isValidIdentifier('user name') => false (contains space)
|
|
14
|
+
* isValidIdentifier('123users') => false (starts with digit)
|
|
15
|
+
*/
|
|
16
|
+
export declare function isValidIdentifier(name: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Adds double quotes around an identifier if needed.
|
|
19
|
+
* Identifiers need quotes if they:
|
|
20
|
+
* - Contain non-alphanumeric characters (except underscore)
|
|
21
|
+
* - Start with a digit
|
|
22
|
+
* - Are empty strings
|
|
23
|
+
*
|
|
24
|
+
* @param identifier - The identifier to potentially quote
|
|
25
|
+
* @returns The identifier with double quotes if needed, otherwise unchanged
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* addDoubleQuoteIfNeeded('users') => 'users'
|
|
29
|
+
* addDoubleQuoteIfNeeded('user name') => '"user name"'
|
|
30
|
+
* addDoubleQuoteIfNeeded('123users') => '"123users"'
|
|
31
|
+
* addDoubleQuoteIfNeeded('user-name') => '"user-name"'
|
|
32
|
+
*/
|
|
33
|
+
export declare function addDoubleQuoteIfNeeded(identifier: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Unescapes a string by processing escape sequences.
|
|
36
|
+
* Handles escaped quotes (\"), common escape sequences, unicode (\uHHHH), and arbitrary escapes.
|
|
37
|
+
*
|
|
38
|
+
* @param str - The string to unescape
|
|
39
|
+
* @returns The unescaped string
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* unescapeString('table\\"name') => 'table"name'
|
|
43
|
+
* unescapeString('line1\\nline2') => 'line1\nline2'
|
|
44
|
+
* unescapeString('\\u0041BC') => 'ABC'
|
|
45
|
+
* unescapeString('\\x') => 'x'
|
|
46
|
+
*/
|
|
47
|
+
export declare function unescapeString(str: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* Escapes a string by adding backslashes before special characters.
|
|
50
|
+
* Handles quotes and other characters that need escaping.
|
|
51
|
+
*
|
|
52
|
+
* @param str - The string to escape
|
|
53
|
+
* @returns The escaped string
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* escapeString('table"name') => 'table\\"name'
|
|
57
|
+
* escapeString('line1\nline2') => 'line1\\nline2'
|
|
58
|
+
*/
|
|
59
|
+
export declare function escapeString(str: string): string;
|
|
60
|
+
/**
|
|
61
|
+
* Formats a record value for DBML output.
|
|
62
|
+
* Handles different data types and converts them to appropriate DBML syntax.
|
|
63
|
+
*
|
|
64
|
+
* @param recordValue - The record value with type information, or a primitive value
|
|
65
|
+
* @returns The formatted string representation for DBML
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* formatRecordValue({ value: 1, type: 'integer' }) => '1'
|
|
69
|
+
* formatRecordValue({ value: 'Alice', type: 'string' }) => "'Alice'"
|
|
70
|
+
* formatRecordValue({ value: true, type: 'bool' }) => 'true'
|
|
71
|
+
* formatRecordValue({ value: null, type: 'string' }) => 'null'
|
|
72
|
+
* formatRecordValue(undefined) => 'null'
|
|
73
|
+
* formatRecordValue(null) => 'null'
|
|
74
|
+
* formatRecordValue('Alice') => "'Alice'"
|
|
75
|
+
* formatRecordValue(42) => '42'
|
|
76
|
+
* formatRecordValue(true) => 'true'
|
|
77
|
+
*/
|
|
78
|
+
export declare function formatRecordValue(recordValue: {
|
|
79
|
+
value: any;
|
|
80
|
+
type: string;
|
|
81
|
+
} | string | number | boolean | null | undefined): string;
|
|
82
|
+
/**
|
|
83
|
+
* Splits a qualified identifier string into its components, handling quoted segments.
|
|
84
|
+
*
|
|
85
|
+
* Examples:
|
|
86
|
+
* - "schema.table" => ["schema", "table"]
|
|
87
|
+
* - '"schema name".table' => ["schema name", "table"]
|
|
88
|
+
* - '"schema.with.dots"."table.with.dots".column' => ["schema.with.dots", "table.with.dots", "column"]
|
|
89
|
+
* - 'schema."table name"."column name"' => ["schema", "table name", "column name"]
|
|
90
|
+
* - 'schema . table' => ["schema", "table"]
|
|
91
|
+
*
|
|
92
|
+
* @param identifier - The qualified identifier string to split
|
|
93
|
+
* @returns Array of unquoted identifier components
|
|
94
|
+
*/
|
|
95
|
+
export declare function splitQualifiedIdentifier(identifier: string): string[];
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { ProgramNode } from '../parser/nodes';
|
|
2
2
|
import { default as Report } from '../report';
|
|
3
|
-
import { CompileError } from '../errors';
|
|
4
3
|
import { NodeSymbolIdGenerator } from './symbol/symbols';
|
|
5
4
|
export default class Analyzer {
|
|
6
5
|
private ast;
|
|
7
6
|
private symbolFactory;
|
|
8
7
|
constructor(ast: ProgramNode, symbolIdGenerator: NodeSymbolIdGenerator);
|
|
9
|
-
analyze(): Report<ProgramNode
|
|
10
|
-
validate(): Report<ProgramNode
|
|
8
|
+
analyze(): Report<ProgramNode>;
|
|
9
|
+
validate(): Report<ProgramNode>;
|
|
11
10
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { CompileError } from '../../errors';
|
|
2
1
|
import { ProgramNode } from '../../parser/nodes';
|
|
3
2
|
import { default as Report } from '../../report';
|
|
4
3
|
import { default as SymbolFactory } from '../symbol/factory';
|
|
@@ -7,5 +6,5 @@ export default class Binder {
|
|
|
7
6
|
private symbolFactory;
|
|
8
7
|
constructor(ast: ProgramNode, symbolFactory: SymbolFactory);
|
|
9
8
|
private resolvePartialInjections;
|
|
10
|
-
resolve(): Report<ProgramNode
|
|
9
|
+
resolve(): Report<ProgramNode>;
|
|
11
10
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SyntaxToken } from '../../../lexer/tokens';
|
|
2
|
+
import { ElementBinder } from '../types';
|
|
3
|
+
import { ElementDeclarationNode, ProgramNode } from '../../../parser/nodes';
|
|
4
|
+
import { CompileError } from '../../../errors';
|
|
5
|
+
import { default as SymbolFactory } from '../../symbol/factory';
|
|
6
|
+
export default class RecordsBinder implements ElementBinder {
|
|
7
|
+
private symbolFactory;
|
|
8
|
+
private declarationNode;
|
|
9
|
+
private ast;
|
|
10
|
+
private boundColumns;
|
|
11
|
+
constructor(declarationNode: ElementDeclarationNode & {
|
|
12
|
+
type: SyntaxToken;
|
|
13
|
+
}, ast: ProgramNode, symbolFactory: SymbolFactory);
|
|
14
|
+
bind(): CompileError[];
|
|
15
|
+
private bindRecordsName;
|
|
16
|
+
private bindTopLevelName;
|
|
17
|
+
private bindInsideTableName;
|
|
18
|
+
private bindBody;
|
|
19
|
+
private bindDataRows;
|
|
20
|
+
private bindDataRow;
|
|
21
|
+
private bindSubElements;
|
|
22
|
+
}
|
|
@@ -12,9 +12,10 @@ import { default as TableGroupBinder } from './elementBinder/tableGroup';
|
|
|
12
12
|
import { default as TablePartialBinder } from './elementBinder/tablePartial';
|
|
13
13
|
import { SymbolKind } from '../symbol/symbolIndex';
|
|
14
14
|
import { CompileError } from '../../errors';
|
|
15
|
+
import { default as RecordsBinder } from './elementBinder/records';
|
|
15
16
|
export declare function pickBinder(element: ElementDeclarationNode & {
|
|
16
17
|
type: SyntaxToken;
|
|
17
|
-
}): typeof ChecksBinder | typeof CustomBinder | typeof EnumBinder | typeof TableBinder | typeof TableGroupBinder | typeof ProjectBinder | typeof RefBinder | typeof NoteBinder | typeof IndexesBinder | typeof TablePartialBinder;
|
|
18
|
+
}): typeof ChecksBinder | typeof CustomBinder | typeof EnumBinder | typeof TableBinder | typeof TableGroupBinder | typeof ProjectBinder | typeof RefBinder | typeof NoteBinder | typeof IndexesBinder | typeof TablePartialBinder | typeof RecordsBinder;
|
|
18
19
|
export declare function scanNonListNodeForBinding(node?: SyntaxNode): {
|
|
19
20
|
variables: (PrimaryExpressionNode & {
|
|
20
21
|
expression: VariableNode;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Option } from '../option';
|
|
2
2
|
import { ElementDeclarationNode, FunctionExpressionNode, InfixExpressionNode, PrimaryExpressionNode, SyntaxNode, VariableNode } from '../parser/nodes';
|
|
3
|
+
import { SyntaxToken } from '../lexer/tokens';
|
|
3
4
|
import { NodeSymbolIndex } from './symbol/symbolIndex';
|
|
4
5
|
import { NodeSymbol } from './symbol/symbols';
|
|
5
|
-
import { SyntaxToken } from '../lexer/tokens';
|
|
6
6
|
import { ElementKind } from './types';
|
|
7
7
|
export declare function getElementKind(node?: ElementDeclarationNode): Option<ElementKind>;
|
|
8
8
|
export declare function destructureMemberAccessExpression(node?: SyntaxNode): Option<SyntaxNode[]>;
|
|
@@ -26,6 +26,8 @@ export declare function extractVarNameFromPrimaryVariable(node?: PrimaryExpressi
|
|
|
26
26
|
expression: VariableNode;
|
|
27
27
|
}): Option<string>;
|
|
28
28
|
export declare function extractQuotedStringToken(value?: SyntaxNode): Option<string>;
|
|
29
|
+
export declare function extractNumericLiteral(node?: SyntaxNode): number | null;
|
|
30
|
+
export declare function extractReferee(node?: SyntaxNode): NodeSymbol | undefined;
|
|
29
31
|
export declare function isBinaryRelationship(value?: SyntaxNode): value is InfixExpressionNode;
|
|
30
32
|
export declare function isEqualTupleOperands(value: InfixExpressionNode): value is InfixExpressionNode;
|
|
31
33
|
export declare function isValidIndexName(value?: SyntaxNode): value is (PrimaryExpressionNode & {
|
|
@@ -38,4 +40,12 @@ export declare function extractIndexName(value: (PrimaryExpressionNode & {
|
|
|
38
40
|
}) | (FunctionExpressionNode & {
|
|
39
41
|
value: SyntaxToken;
|
|
40
42
|
})): string;
|
|
43
|
+
export declare function destructureCallExpression(node?: SyntaxNode): Option<{
|
|
44
|
+
variables: (PrimaryExpressionNode & {
|
|
45
|
+
expression: VariableNode;
|
|
46
|
+
})[];
|
|
47
|
+
args: (PrimaryExpressionNode & {
|
|
48
|
+
expression: VariableNode;
|
|
49
|
+
})[];
|
|
50
|
+
}>;
|
|
41
51
|
export declare function findSymbol(id: NodeSymbolIndex, startElement: ElementDeclarationNode): NodeSymbol | undefined;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { default as SymbolFactory } from '../../symbol/factory';
|
|
2
|
+
import { CompileError } from '../../../errors';
|
|
3
|
+
import { BlockExpressionNode, ElementDeclarationNode, FunctionApplicationNode } from '../../../parser/nodes';
|
|
4
|
+
import { SyntaxToken } from '../../../lexer/tokens';
|
|
5
|
+
import { ElementValidator } from '../types';
|
|
6
|
+
import { default as SymbolTable } from '../../symbol/symbolTable';
|
|
7
|
+
export default class RecordsValidator implements ElementValidator {
|
|
8
|
+
private declarationNode;
|
|
9
|
+
private publicSymbolTable;
|
|
10
|
+
private symbolFactory;
|
|
11
|
+
constructor(declarationNode: ElementDeclarationNode & {
|
|
12
|
+
type: SyntaxToken;
|
|
13
|
+
}, publicSymbolTable: SymbolTable, symbolFactory: SymbolFactory);
|
|
14
|
+
validate(): CompileError[];
|
|
15
|
+
private validateContext;
|
|
16
|
+
private validateName;
|
|
17
|
+
private validateTopLevelName;
|
|
18
|
+
private validateInsideTableName;
|
|
19
|
+
private validateAlias;
|
|
20
|
+
private validateSettingList;
|
|
21
|
+
validateBody(body?: FunctionApplicationNode | BlockExpressionNode): CompileError[];
|
|
22
|
+
private validateDataRows;
|
|
23
|
+
private validateDataRow;
|
|
24
|
+
private isValidRecordValue;
|
|
25
|
+
private validateSubElements;
|
|
26
|
+
}
|
|
@@ -11,12 +11,12 @@ import { default as TableGroupValidator } from './elementValidators/tableGroup';
|
|
|
11
11
|
import { default as SymbolTable } from '../symbol/symbolTable';
|
|
12
12
|
import { default as SymbolFactory } from '../symbol/factory';
|
|
13
13
|
import { default as Report } from '../../report';
|
|
14
|
-
import { CompileError } from '../../errors';
|
|
15
14
|
import { default as TablePartialValidator } from './elementValidators/tablePartial';
|
|
16
15
|
import { default as ChecksValidator } from './elementValidators/checks';
|
|
16
|
+
import { default as RecordsValidator } from './elementValidators/records';
|
|
17
17
|
export declare function pickValidator(element: ElementDeclarationNode & {
|
|
18
18
|
type: SyntaxToken;
|
|
19
|
-
}): typeof CustomValidator | typeof EnumValidator | typeof TableValidator | typeof TableGroupValidator | typeof ProjectValidator | typeof RefValidator | typeof NoteValidator | typeof IndexesValidator | typeof TablePartialValidator | typeof ChecksValidator;
|
|
19
|
+
}): typeof CustomValidator | typeof EnumValidator | typeof TableValidator | typeof TableGroupValidator | typeof ProjectValidator | typeof RefValidator | typeof NoteValidator | typeof IndexesValidator | typeof TablePartialValidator | typeof ChecksValidator | typeof RecordsValidator;
|
|
20
20
|
export declare function isValidName(nameNode: SyntaxNode): boolean;
|
|
21
21
|
export declare function isValidAlias(aliasNode: SyntaxNode): aliasNode is PrimaryExpressionNode & {
|
|
22
22
|
expression: VariableNode;
|
|
@@ -62,4 +62,4 @@ export declare function isTupleOfVariables(value?: SyntaxNode): value is TupleEx
|
|
|
62
62
|
export declare function isValidColumnType(type: SyntaxNode): boolean;
|
|
63
63
|
export declare function aggregateSettingList(settingList?: ListExpressionNode): Report<{
|
|
64
64
|
[index: string]: AttributeNode[];
|
|
65
|
-
}
|
|
65
|
+
}>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { default as Report } from '../../report';
|
|
2
|
-
import { CompileError } from '../../errors';
|
|
3
2
|
import { ProgramNode } from '../../parser/nodes';
|
|
4
3
|
import { default as SymbolFactory } from '../symbol/factory';
|
|
5
4
|
export default class Validator {
|
|
@@ -7,5 +6,5 @@ export default class Validator {
|
|
|
7
6
|
private publicSchemaSymbol;
|
|
8
7
|
private symbolFactory;
|
|
9
8
|
constructor(ast: ProgramNode, symbolFactory: SymbolFactory);
|
|
10
|
-
validate(): Report<ProgramNode
|
|
9
|
+
validate(): Report<ProgramNode>;
|
|
11
10
|
}
|
|
@@ -90,6 +90,11 @@ export declare enum CompileErrorCode {
|
|
|
90
90
|
UNKNOWN_CHECK_SETTING = 3074,
|
|
91
91
|
DUPLICATE_CHECK_SETTING = 3075,
|
|
92
92
|
INVALID_CHECK_SETTING_VALUE = 3076,
|
|
93
|
+
INVALID_RECORDS_CONTEXT = 3077,
|
|
94
|
+
INVALID_RECORDS_NAME = 3078,
|
|
95
|
+
INVALID_RECORDS_FIELD = 3079,
|
|
96
|
+
DUPLICATE_COLUMN_REFERENCES_IN_RECORDS = 3080,
|
|
97
|
+
DUPLICATE_RECORDS_FOR_TABLE = 3081,
|
|
93
98
|
BINDING_ERROR = 4000,
|
|
94
99
|
UNSUPPORTED = 5000,
|
|
95
100
|
CIRCULAR_REF = 5001,
|
|
@@ -101,7 +106,16 @@ export declare enum CompileErrorCode {
|
|
|
101
106
|
export declare class CompileError extends Error {
|
|
102
107
|
code: Readonly<CompileErrorCode>;
|
|
103
108
|
diagnostic: Readonly<string>;
|
|
104
|
-
nodeOrToken: Readonly<SyntaxNode | SyntaxToken
|
|
109
|
+
nodeOrToken: Readonly<SyntaxNode | SyntaxToken>;
|
|
110
|
+
start: Readonly<number>;
|
|
111
|
+
end: Readonly<number>;
|
|
112
|
+
constructor(code: number, message: string, nodeOrToken: SyntaxNode | SyntaxToken);
|
|
113
|
+
toWarning(): CompileWarning;
|
|
114
|
+
}
|
|
115
|
+
export declare class CompileWarning extends Error {
|
|
116
|
+
code: Readonly<CompileErrorCode>;
|
|
117
|
+
diagnostic: Readonly<string>;
|
|
118
|
+
nodeOrToken: Readonly<SyntaxNode | SyntaxToken>;
|
|
105
119
|
start: Readonly<number>;
|
|
106
120
|
end: Readonly<number>;
|
|
107
121
|
constructor(code: number, message: string, nodeOrToken: SyntaxNode | SyntaxToken);
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { ProgramNode } from '../parser/nodes';
|
|
2
|
-
import { CompileError } from '../errors';
|
|
3
2
|
import { Database, InterpreterDatabase } from './types';
|
|
4
3
|
import { default as Report } from '../report';
|
|
5
4
|
export default class Interpreter {
|
|
6
5
|
ast: ProgramNode;
|
|
7
6
|
env: InterpreterDatabase;
|
|
8
7
|
constructor(ast: ProgramNode);
|
|
9
|
-
interpret(): Report<Database
|
|
8
|
+
interpret(): Report<Database>;
|
|
10
9
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ElementDeclarationNode } from '../../parser/nodes';
|
|
2
|
+
import { default as Report } from '../../report';
|
|
3
|
+
import { InterpreterDatabase } from '../types';
|
|
4
|
+
export declare class RecordsInterpreter {
|
|
5
|
+
private env;
|
|
6
|
+
private tableToRecordMap;
|
|
7
|
+
constructor(env: InterpreterDatabase);
|
|
8
|
+
interpret(elements: ElementDeclarationNode[]): Report<void>;
|
|
9
|
+
private validateConstraints;
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RecordValue, Column, TableRecordRow } from '../../../types';
|
|
2
|
+
import { CompileError } from '../../../../errors';
|
|
3
|
+
export declare function extractKeyValueWithDefault(row: Record<string, RecordValue>, columnNames: string[], columns?: (Column | undefined)[]): string;
|
|
4
|
+
export declare function hasNullWithoutDefaultInKey(row: Record<string, RecordValue>, columnNames: string[], columns?: (Column | undefined)[]): boolean;
|
|
5
|
+
export declare function isAutoIncrementColumn(column: Column): boolean;
|
|
6
|
+
export declare function hasNotNullWithDefault(column: Column): boolean;
|
|
7
|
+
export declare function formatFullColumnName(schemaName: string | null, tableName: string, columnName: string): string;
|
|
8
|
+
export declare function formatFullColumnNames(schemaName: string | null, tableName: string, columnNames: string[]): string;
|
|
9
|
+
export declare function formatValues(row: Record<string, RecordValue>, columnNames: string[]): string;
|
|
10
|
+
export declare function createConstraintErrors(row: TableRecordRow, columnNames: string[], message: string): CompileError[];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ColumnSymbol } from '../../../../analyzer/symbol/symbols';
|
|
2
|
+
export type SqlDialect = 'mysql' | 'postgres' | 'mssql' | 'oracle' | 'snowflake';
|
|
3
|
+
export declare function normalizeTypeName(type: string): string;
|
|
4
|
+
export declare function isIntegerType(type: string, dialect?: SqlDialect): boolean;
|
|
5
|
+
export declare function isFloatType(type: string, dialect?: SqlDialect): boolean;
|
|
6
|
+
export declare function isNumericType(type: string, dialect?: SqlDialect): boolean;
|
|
7
|
+
export declare function isBooleanType(type: string, dialect?: SqlDialect): boolean;
|
|
8
|
+
export declare function isStringType(type: string, dialect?: SqlDialect): boolean;
|
|
9
|
+
export declare function isBinaryType(type: string, dialect?: SqlDialect): boolean;
|
|
10
|
+
export declare function isDateTimeType(type: string, dialect?: SqlDialect): boolean;
|
|
11
|
+
export declare function isSerialType(type: string, dialect?: SqlDialect): boolean;
|
|
12
|
+
export declare function getNumericTypeParams(columnSymbol: ColumnSymbol): {
|
|
13
|
+
precision?: number;
|
|
14
|
+
scale?: number;
|
|
15
|
+
};
|
|
16
|
+
export declare function getLengthTypeParam(columnSymbol: ColumnSymbol): {
|
|
17
|
+
length?: number;
|
|
18
|
+
};
|
|
19
|
+
export declare function getRecordValueType(sqlType: string, isEnum: boolean): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FunctionExpressionNode, SyntaxNode } from '../../../../parser/nodes';
|
|
2
|
+
export { extractNumericLiteral } from '../../../../analyzer/utils';
|
|
3
|
+
export declare function isNullish(value: SyntaxNode): boolean;
|
|
4
|
+
export declare function isEmptyStringLiteral(value: SyntaxNode): boolean;
|
|
5
|
+
export declare function isFunctionExpression(value: SyntaxNode): value is FunctionExpressionNode;
|
|
6
|
+
export declare function extractSignedNumber(node: SyntaxNode): number | null;
|
|
7
|
+
export declare function tryExtractNumeric(value: SyntaxNode | number | string | boolean | undefined | null): number | null;
|
|
8
|
+
export declare function tryExtractInteger(value: SyntaxNode | number | string | boolean | undefined | null): number | null;
|
|
9
|
+
export declare const TRUTHY_VALUES: string[];
|
|
10
|
+
export declare const FALSY_VALUES: string[];
|
|
11
|
+
export declare function tryExtractBoolean(value: SyntaxNode | number | string | boolean | undefined | null): boolean | null;
|
|
12
|
+
export declare function tryExtractEnum(value: SyntaxNode | string | undefined | null): string | null;
|
|
13
|
+
export declare function tryExtractString(value: SyntaxNode | string | boolean | number | undefined | null): string | null;
|
|
14
|
+
export declare function tryExtractDateTime(value: SyntaxNode | string | undefined | null): string | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ElementDeclarationNode } from '../parser/nodes';
|
|
1
|
+
import { ElementDeclarationNode, FunctionApplicationNode, SyntaxNode } from '../parser/nodes';
|
|
2
2
|
import { Position } from '../types';
|
|
3
3
|
import { CompileError } from '../errors';
|
|
4
4
|
export interface TokenPosition {
|
|
@@ -24,6 +24,34 @@ export interface InterpreterDatabase {
|
|
|
24
24
|
tablePartials: Map<ElementDeclarationNode, TablePartial>;
|
|
25
25
|
aliases: Alias[];
|
|
26
26
|
project: Map<ElementDeclarationNode, Project>;
|
|
27
|
+
records: Map<Table, TableRecordRow[]>;
|
|
28
|
+
recordsElements: ElementDeclarationNode[];
|
|
29
|
+
cachedMergedTables: Map<Table, Table>;
|
|
30
|
+
source: string;
|
|
31
|
+
}
|
|
32
|
+
export type RecordValueType = 'string' | 'bool' | 'integer' | 'real' | 'date' | 'time' | 'datetime' | string;
|
|
33
|
+
export interface RecordValue {
|
|
34
|
+
value: any;
|
|
35
|
+
type: RecordValueType;
|
|
36
|
+
}
|
|
37
|
+
export interface TableRecordRow {
|
|
38
|
+
values: Record<string, {
|
|
39
|
+
value: any;
|
|
40
|
+
type: RecordValueType;
|
|
41
|
+
node?: SyntaxNode;
|
|
42
|
+
}>;
|
|
43
|
+
node: FunctionApplicationNode;
|
|
44
|
+
columnNodes: Record<string, SyntaxNode>;
|
|
45
|
+
}
|
|
46
|
+
export interface TableRecordsData {
|
|
47
|
+
table: Table;
|
|
48
|
+
rows: TableRecordRow[];
|
|
49
|
+
}
|
|
50
|
+
export interface TableRecord {
|
|
51
|
+
schemaName: string | undefined;
|
|
52
|
+
tableName: string;
|
|
53
|
+
columns: string[];
|
|
54
|
+
values: RecordValue[][];
|
|
27
55
|
}
|
|
28
56
|
export interface Database {
|
|
29
57
|
schemas: [];
|
|
@@ -35,6 +63,7 @@ export interface Database {
|
|
|
35
63
|
aliases: Alias[];
|
|
36
64
|
project: Project;
|
|
37
65
|
tablePartials: TablePartial[];
|
|
66
|
+
records: TableRecord[];
|
|
38
67
|
}
|
|
39
68
|
export interface Table {
|
|
40
69
|
name: string;
|
|
@@ -61,6 +90,14 @@ export interface ColumnType {
|
|
|
61
90
|
schemaName: string | null;
|
|
62
91
|
type_name: string;
|
|
63
92
|
args: string | null;
|
|
93
|
+
numericParams?: {
|
|
94
|
+
precision: number;
|
|
95
|
+
scale: number;
|
|
96
|
+
};
|
|
97
|
+
lengthParam?: {
|
|
98
|
+
length: number;
|
|
99
|
+
};
|
|
100
|
+
isEnum?: boolean;
|
|
64
101
|
}
|
|
65
102
|
export interface Column {
|
|
66
103
|
name: string;
|
|
@@ -193,5 +230,5 @@ export type Project = Record<string, never> | {
|
|
|
193
230
|
token: TokenPosition;
|
|
194
231
|
};
|
|
195
232
|
token: TokenPosition;
|
|
196
|
-
[index: string & Omit<any, 'name' | 'tables' | 'refs' | 'enums' | 'tableGroups' | 'note' | 'tablePartials'>]: string;
|
|
233
|
+
[index: string & Omit<any, 'name' | 'tables' | 'refs' | 'enums' | 'tableGroups' | 'note' | 'tablePartials' | 'records'>]: string;
|
|
197
234
|
};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { ColumnSymbol } from '../analyzer/symbol/symbols';
|
|
2
2
|
import { LiteralNode, PrimaryExpressionNode, SyntaxNode } from '../parser/nodes';
|
|
3
|
-
import { ColumnType, RelationCardinality, Table, TokenPosition } from './types';
|
|
3
|
+
import { ColumnType, RelationCardinality, Table, TokenPosition, InterpreterDatabase, Ref } from './types';
|
|
4
4
|
import { SyntaxTokenKind } from '../lexer/tokens';
|
|
5
5
|
import { default as Report } from '../report';
|
|
6
|
-
import { CompileError } from '../errors';
|
|
7
6
|
export declare function extractNamesFromRefOperand(operand: SyntaxNode, owner?: Table): {
|
|
8
7
|
schemaName: string | null;
|
|
9
8
|
tableName: string;
|
|
@@ -32,4 +31,6 @@ export declare function processDefaultValue(valueNode?: SyntaxNode): {
|
|
|
32
31
|
type: 'string' | 'number' | 'boolean' | 'expression';
|
|
33
32
|
value: string | number;
|
|
34
33
|
} | undefined;
|
|
35
|
-
export declare function processColumnType(typeNode: SyntaxNode): Report<ColumnType
|
|
34
|
+
export declare function processColumnType(typeNode: SyntaxNode, env: InterpreterDatabase): Report<ColumnType>;
|
|
35
|
+
export declare function mergeTableAndPartials(table: Table, env: InterpreterDatabase): Table;
|
|
36
|
+
export declare function extractInlineRefsFromTablePartials(table: Table, env: InterpreterDatabase): Ref[];
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { CompileError } from '../errors';
|
|
2
1
|
import { default as Report } from '../report';
|
|
3
2
|
import { SyntaxToken, SyntaxTokenKind } from './tokens';
|
|
4
3
|
export default class Lexer {
|
|
@@ -15,7 +14,7 @@ export default class Lexer {
|
|
|
15
14
|
match(sequence: string): boolean;
|
|
16
15
|
private addToken;
|
|
17
16
|
private createToken;
|
|
18
|
-
lex(): Report<SyntaxToken[]
|
|
17
|
+
lex(): Report<SyntaxToken[]>;
|
|
19
18
|
scanTokens(): void;
|
|
20
19
|
gatherTrivia(): void;
|
|
21
20
|
gatherInvalid(): void;
|