@dbml/parse 8.4.0-alpha.1 → 8.4.0-custom-metadata.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/dbml-parse.js +16 -16
- package/dist/dbml-parse.mjs +3847 -3526
- package/dist/src/compiler/types.d.ts +2 -1
- package/dist/src/core/global_modules/metadata/bind.d.ts +11 -0
- package/dist/src/core/global_modules/metadata/index.d.ts +2 -0
- package/dist/src/core/global_modules/metadata/interpret.d.ts +14 -0
- package/dist/src/core/global_modules/metadata/utils.d.ts +29 -0
- package/dist/src/core/global_modules/note/interpret.d.ts +3 -1
- package/dist/src/core/global_modules/table/interpret.d.ts +12 -1
- package/dist/src/core/global_modules/tableGroup/interpret.d.ts +3 -1
- package/dist/src/core/global_modules/utils.d.ts +3 -1
- package/dist/src/core/local_modules/metadata/index.d.ts +2 -0
- package/dist/src/core/local_modules/metadata/utils.d.ts +7 -0
- package/dist/src/core/local_modules/metadata/validate.d.ts +14 -0
- package/dist/src/core/types/errors.d.ts +4 -1
- package/dist/src/core/types/keywords.d.ts +2 -1
- package/dist/src/core/types/nodes.d.ts +14 -3
- package/dist/src/core/types/schemaJson.d.ts +10 -1
- package/dist/src/core/types/symbol/metadata.d.ts +15 -2
- package/dist/src/core/types/symbol/symbols.d.ts +8 -0
- package/dist/src/core/utils/interpret.d.ts +12 -2
- package/dist/src/core/utils/tokens.d.ts +3 -0
- package/dist/src/core/utils/validate.d.ts +14 -2
- package/dist/src/index.d.ts +1 -1
- package/dist/src/services/suggestions/provider.d.ts +19 -0
- package/package.json +2 -2
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { default as Compiler } from '../../../compiler';
|
|
2
|
+
import { CompileError } from '../../types';
|
|
3
|
+
import { ElementDeclarationNode } from '../../types/nodes';
|
|
4
|
+
export default class MetadataBinder {
|
|
5
|
+
private compiler;
|
|
6
|
+
private declarationNode;
|
|
7
|
+
constructor(compiler: Compiler, declarationNode: ElementDeclarationNode);
|
|
8
|
+
bind(): CompileError[];
|
|
9
|
+
private bindTargetElement;
|
|
10
|
+
private bindBody;
|
|
11
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { default as Compiler } from '../../../compiler';
|
|
2
|
+
import { Filepath } from '../../types';
|
|
3
|
+
import { MetadataElementMetadata } from '../../types/symbol/metadata';
|
|
4
|
+
import { default as Report } from '../../types/report';
|
|
5
|
+
import { MetadataValues } from '../../types/schemaJson';
|
|
6
|
+
export default class MetadataInterpreter {
|
|
7
|
+
private declarationNode;
|
|
8
|
+
private compiler;
|
|
9
|
+
private filepath;
|
|
10
|
+
private values;
|
|
11
|
+
constructor(compiler: Compiler, metadata: MetadataElementMetadata, filepath: Filepath);
|
|
12
|
+
interpret(): Report<MetadataValues>;
|
|
13
|
+
private interpretValues;
|
|
14
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { default as Compiler } from '../../../compiler/index';
|
|
2
|
+
import { Filepath, SettingName } from '../../types';
|
|
3
|
+
import { Column, Note, Table, TableGroup, TokenPosition } from '../../types/schemaJson';
|
|
4
|
+
import { ElementDeclarationNode, SyntaxNode } from '../../types/nodes';
|
|
5
|
+
import { NodeSymbol, SymbolKind, MetadataTargetKind } from '../../types/symbol';
|
|
6
|
+
export type MetadataTarget = Table | TableGroup | Note | Column;
|
|
7
|
+
/**
|
|
8
|
+
* Specs for builtin metadata (table's note, tablegroup's color, .etc) for different element types. Does 2 things:
|
|
9
|
+
* - `validate`: Validating if the metadata value is syntactically correct
|
|
10
|
+
* - `assign`: Write the metadata value to the element builtin props (e.g. write `table.note` instead of `table.metadata`)
|
|
11
|
+
*/
|
|
12
|
+
interface MetadataField<T extends MetadataTarget> {
|
|
13
|
+
/** Check if the metadata value is syntactically correct */
|
|
14
|
+
isValidBuiltinFieldValue(node?: SyntaxNode): boolean;
|
|
15
|
+
message: string;
|
|
16
|
+
/** Write the metadata value to the element builtin props (e.g. write to `table.note`) */
|
|
17
|
+
assignBuiltinField(element: Partial<T>, value: string, token: TokenPosition): void;
|
|
18
|
+
}
|
|
19
|
+
export type MetadataFieldRegistry<T extends MetadataTarget, K extends SettingName = SettingName> = Record<K, MetadataField<T>>;
|
|
20
|
+
type NameWithSymbolKind = {
|
|
21
|
+
name: string;
|
|
22
|
+
symbolKind: SymbolKind;
|
|
23
|
+
};
|
|
24
|
+
/** @internal Exported for testing only. */
|
|
25
|
+
export declare function mapNamePartToSymbolKind(nameParts: string[], targetKind: MetadataTargetKind): NameWithSymbolKind[];
|
|
26
|
+
export declare function resolveMetadataTarget(compiler: Compiler, metadataNode: ElementDeclarationNode): NodeSymbol | undefined;
|
|
27
|
+
/** Merge every custom-metadata block, reachable from the current program, targeting element to it's `metadata` and other builtin (note/headercolor/...) fields */
|
|
28
|
+
export declare function attachCustomMetadata<T extends MetadataTarget>(compiler: Compiler, targetElement: Partial<T>, targetSymbol: NodeSymbol, fieldsRegistry: MetadataFieldRegistry<T, any>, filepath: Filepath): void;
|
|
29
|
+
export {};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Note } from '../../types/schemaJson';
|
|
2
2
|
import { default as Compiler } from '../../../compiler';
|
|
3
|
-
import { Filepath, NoteSymbol } from '../../types';
|
|
3
|
+
import { SettingName, Filepath, NoteSymbol } from '../../types';
|
|
4
4
|
import { default as Report } from '../../types/report';
|
|
5
|
+
import { MetadataFieldRegistry } from '../metadata/utils';
|
|
6
|
+
export declare const NOTE_METADATA_FIELDS: MetadataFieldRegistry<Note, SettingName.Color>;
|
|
5
7
|
export declare class StickyNoteInterpreter {
|
|
6
8
|
private declarationNode;
|
|
7
9
|
private symbol;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { default as Compiler } from '../../../compiler';
|
|
2
|
+
import { SettingName } from '../../types/keywords';
|
|
2
3
|
import { ElementDeclarationNode } from '../../types/nodes';
|
|
3
4
|
import { default as Report } from '../../types/report';
|
|
4
|
-
import { Table } from '../../types/schemaJson';
|
|
5
|
+
import { Column, Table } from '../../types/schemaJson';
|
|
5
6
|
import { Filepath } from '../../types/filepath';
|
|
6
7
|
import { TableSymbol } from '../../types/symbol/symbols';
|
|
8
|
+
import { MetadataFieldRegistry } from '../metadata/utils';
|
|
7
9
|
export declare class TableInterpreter {
|
|
8
10
|
private declarationNode;
|
|
9
11
|
private compiler;
|
|
@@ -13,6 +15,7 @@ export declare class TableInterpreter {
|
|
|
13
15
|
private pkColumns;
|
|
14
16
|
constructor(compiler: Compiler, declarationNode: ElementDeclarationNode, symbol: TableSymbol, filepath: Filepath);
|
|
15
17
|
interpret(): Report<Table>;
|
|
18
|
+
private attachTableAndColumnMetadata;
|
|
16
19
|
private interpretName;
|
|
17
20
|
private interpretAlias;
|
|
18
21
|
private interpretSettingList;
|
|
@@ -24,3 +27,11 @@ export declare class TableInterpreter {
|
|
|
24
27
|
private interpretIndexes;
|
|
25
28
|
private interpretChecks;
|
|
26
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Settings that are excluded from custom metadata for inline metadata for Column
|
|
32
|
+
* Different from what we extract from metadata block for Column because some settings value types are not supported yet, mostly boolean keys without values ([pk, not null])
|
|
33
|
+
* TODO: Catch these settings when we support more data types for custom metadata
|
|
34
|
+
*/
|
|
35
|
+
export declare const RECOGNIZED_COLUMN_SETTINGS: readonly SettingName[];
|
|
36
|
+
export declare const TABLE_METADATA_FIELDS: MetadataFieldRegistry<Table, SettingName.Note | SettingName.HeaderColor>;
|
|
37
|
+
export declare const COLUMN_METADATA_FIELDS: MetadataFieldRegistry<Column, SettingName.Note>;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { TableGroup } from '../../types/schemaJson';
|
|
2
2
|
import { default as Compiler } from '../../../compiler';
|
|
3
|
-
import { Filepath, TableGroupSymbol } from '../../types';
|
|
3
|
+
import { SettingName, Filepath, TableGroupSymbol } from '../../types';
|
|
4
4
|
import { default as Report } from '../../types/report';
|
|
5
|
+
import { MetadataFieldRegistry } from '../metadata/utils';
|
|
6
|
+
export declare const TABLEGROUP_METADATA_FIELDS: MetadataFieldRegistry<TableGroup, SettingName.Note | SettingName.Color>;
|
|
5
7
|
export declare class TableGroupInterpreter {
|
|
6
8
|
private compiler;
|
|
7
9
|
private symbol;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { default as Compiler } from '../../compiler';
|
|
2
|
-
import { RelationCardinality } from '../types';
|
|
2
|
+
import { Filepath, ProgramSymbol, RelationCardinality } from '../types';
|
|
3
3
|
import { PrimaryExpressionNode, SyntaxNode, VariableNode } from '../types/nodes';
|
|
4
4
|
import { default as Report } from '../types/report';
|
|
5
5
|
import { NodeSymbol } from '../types/symbol';
|
|
@@ -15,3 +15,5 @@ export declare function scanNonListNodeForBinding(node?: SyntaxNode): {
|
|
|
15
15
|
}[];
|
|
16
16
|
export declare function nodeRefereeOfLeftExpression(compiler: Compiler, node: SyntaxNode): NodeSymbol | undefined;
|
|
17
17
|
export declare function getMultiplicities(op: string): [RelationCardinality, RelationCardinality] | undefined;
|
|
18
|
+
export declare function getDefaultSchemaSymbol(compiler: Compiler, globalSymbol: NodeSymbol): NodeSymbol | undefined;
|
|
19
|
+
export declare function getProgramSymbol(compiler: Compiler, filepath: Filepath): ProgramSymbol | undefined;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CompileError, CompileErrorCode, MetadataTargetKind } from '../../types';
|
|
2
|
+
import { AttributeNode, ElementDeclarationNode } from '../../types/nodes';
|
|
3
|
+
export declare function getMetadataTargetKind(node: ElementDeclarationNode): MetadataTargetKind | undefined;
|
|
4
|
+
export declare function validateCustomInlineMetadata(name: string, attrs: AttributeNode[], errorCodes: {
|
|
5
|
+
duplicate: CompileErrorCode;
|
|
6
|
+
invalidValue: CompileErrorCode;
|
|
7
|
+
}): CompileError[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { default as Compiler } from '../../../compiler';
|
|
2
|
+
import { CompileError } from '../../types/errors';
|
|
3
|
+
import { ElementDeclarationNode } from '../../types/nodes';
|
|
4
|
+
export default class MetadataValidator {
|
|
5
|
+
private compiler;
|
|
6
|
+
private declarationNode;
|
|
7
|
+
constructor(compiler: Compiler, declarationNode: ElementDeclarationNode);
|
|
8
|
+
validate(): CompileError[];
|
|
9
|
+
private validateTargetKind;
|
|
10
|
+
private validateTargetName;
|
|
11
|
+
private validateBody;
|
|
12
|
+
private validateFields;
|
|
13
|
+
private validateSubElements;
|
|
14
|
+
}
|
|
@@ -113,7 +113,10 @@ export declare enum CompileErrorCode {
|
|
|
113
113
|
SAME_ENDPOINT = 5002,
|
|
114
114
|
UNEQUAL_FIELDS_BINARY_REF = 5003,
|
|
115
115
|
CONFLICTING_SETTING = 5004,
|
|
116
|
-
TABLE_REAPPEAR_IN_TABLEGROUP = 5005
|
|
116
|
+
TABLE_REAPPEAR_IN_TABLEGROUP = 5005,
|
|
117
|
+
INVALID_METADATA_TARGET_KIND = 5006,
|
|
118
|
+
INVALID_METADATA_FIELD = 5007,
|
|
119
|
+
DUPLICATE_METADATA_FIELD = 5008
|
|
117
120
|
}
|
|
118
121
|
export declare class CompileError extends Error {
|
|
119
122
|
code: Readonly<CompileErrorCode>;
|
|
@@ -13,7 +13,8 @@ export declare enum ElementKind {
|
|
|
13
13
|
DiagramViewTables = "tables",
|
|
14
14
|
DiagramViewNotes = "notes",
|
|
15
15
|
DiagramViewTableGroups = "tablegroups",
|
|
16
|
-
DiagramViewSchemas = "schemas"
|
|
16
|
+
DiagramViewSchemas = "schemas",
|
|
17
|
+
Metadata = "metadata"
|
|
17
18
|
}
|
|
18
19
|
export declare enum SettingName {
|
|
19
20
|
Color = "color",
|
|
@@ -110,14 +110,16 @@ export declare class UseSpecifierListNode extends SyntaxNode {
|
|
|
110
110
|
}
|
|
111
111
|
export declare class ElementDeclarationNode extends SyntaxNode {
|
|
112
112
|
type?: SyntaxToken;
|
|
113
|
+
targetKind?: SyntaxToken;
|
|
113
114
|
name?: NormalExpressionNode;
|
|
114
115
|
as?: SyntaxToken;
|
|
115
116
|
alias?: NormalExpressionNode;
|
|
116
117
|
attributeList?: ListExpressionNode;
|
|
117
118
|
bodyColon?: SyntaxToken;
|
|
118
119
|
body?: FunctionApplicationNode | BlockExpressionNode;
|
|
119
|
-
constructor({ type, name, as, alias, attributeList, bodyColon, body, }: {
|
|
120
|
+
constructor({ type, targetKind, name, as, alias, attributeList, bodyColon, body, }: {
|
|
120
121
|
type?: SyntaxToken;
|
|
122
|
+
targetKind?: SyntaxToken;
|
|
121
123
|
name?: NormalExpressionNode;
|
|
122
124
|
as?: SyntaxToken;
|
|
123
125
|
alias?: NormalExpressionNode;
|
|
@@ -125,8 +127,17 @@ export declare class ElementDeclarationNode extends SyntaxNode {
|
|
|
125
127
|
bodyColon?: SyntaxToken;
|
|
126
128
|
body?: BlockExpressionNode | FunctionApplicationNode;
|
|
127
129
|
}, id: SyntaxNodeId, filepath: Filepath);
|
|
128
|
-
isKind(...kinds:
|
|
129
|
-
|
|
130
|
+
isKind<T extends ElementKind>(...kinds: T[]): this is ElementDeclarationNode & {
|
|
131
|
+
type: {
|
|
132
|
+
value: T;
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
getElementKind<T extends ElementKind>(this: ElementDeclarationNode & {
|
|
136
|
+
type: {
|
|
137
|
+
value: T;
|
|
138
|
+
};
|
|
139
|
+
}): T;
|
|
140
|
+
getElementKind(this: ElementDeclarationNode): ElementKind | undefined;
|
|
130
141
|
}
|
|
131
142
|
export declare class IdentifierStreamNode extends SyntaxNode {
|
|
132
143
|
identifiers: SyntaxToken[];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { NONE_COLOR } from '../../constants';
|
|
2
2
|
import { Filepath } from './filepath';
|
|
3
3
|
import { Position } from './position';
|
|
4
|
+
export type CustomMetadata = Record<string, string>;
|
|
4
5
|
export type Color = `#${string}` | typeof NONE_COLOR;
|
|
5
6
|
export declare enum AliasKind {
|
|
6
7
|
Table = "table"
|
|
@@ -85,12 +86,14 @@ export interface Table {
|
|
|
85
86
|
value: string;
|
|
86
87
|
token: TokenPosition;
|
|
87
88
|
};
|
|
89
|
+
metadata?: CustomMetadata;
|
|
88
90
|
}
|
|
89
91
|
export interface Note {
|
|
90
92
|
name: string;
|
|
91
93
|
content: string;
|
|
92
94
|
token: TokenPosition;
|
|
93
95
|
color?: Color;
|
|
96
|
+
metadata?: CustomMetadata;
|
|
94
97
|
}
|
|
95
98
|
export interface ColumnType {
|
|
96
99
|
schemaName: string | null;
|
|
@@ -123,6 +126,7 @@ export interface Column {
|
|
|
123
126
|
value: string;
|
|
124
127
|
token: TokenPosition;
|
|
125
128
|
};
|
|
129
|
+
metadata?: CustomMetadata;
|
|
126
130
|
}
|
|
127
131
|
export interface Index {
|
|
128
132
|
columns: {
|
|
@@ -195,6 +199,7 @@ export interface TableGroup {
|
|
|
195
199
|
value: string;
|
|
196
200
|
token: TokenPosition;
|
|
197
201
|
};
|
|
202
|
+
metadata?: CustomMetadata;
|
|
198
203
|
}
|
|
199
204
|
export interface TableGroupField {
|
|
200
205
|
name: string;
|
|
@@ -238,6 +243,10 @@ export interface TableRecord {
|
|
|
238
243
|
values: RecordValue[][];
|
|
239
244
|
token: TokenPosition;
|
|
240
245
|
}
|
|
246
|
+
export type MetadataValues = Record<string, {
|
|
247
|
+
value: string;
|
|
248
|
+
token: TokenPosition;
|
|
249
|
+
}>;
|
|
241
250
|
export type Project = Record<string, never> | {
|
|
242
251
|
name: string | null;
|
|
243
252
|
tables: Table[];
|
|
@@ -252,4 +261,4 @@ export type Project = Record<string, never> | {
|
|
|
252
261
|
token: TokenPosition;
|
|
253
262
|
[index: string & Omit<any, 'name' | 'tables' | 'refs' | 'enums' | 'tableGroups' | 'note' | 'tablePartials' | 'records'>]: string;
|
|
254
263
|
};
|
|
255
|
-
export type SchemaElement = Database | Project | Table | Note | Column | ColumnType | Index | Check | InlineRef | Ref | RefEndpoint | Enum | EnumField | TableGroup | TableGroupField | Alias | TablePartial | TablePartialInjection | TableRecord | RecordValue;
|
|
264
|
+
export type SchemaElement = Database | Project | Table | Note | Column | ColumnType | Index | Check | InlineRef | Ref | RefEndpoint | Enum | EnumField | TableGroup | TableGroupField | Alias | TablePartial | TablePartialInjection | TableRecord | RecordValue | MetadataValues;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { default as Compiler } from '../../../compiler';
|
|
2
2
|
import { AttributeNode, ElementDeclarationNode, SyntaxNode } from '../nodes';
|
|
3
|
-
import { ColumnSymbol, NodeSymbol, TablePartialSymbol, TableSymbol } from '../symbol';
|
|
3
|
+
import { ColumnSymbol, NodeSymbol, ProgramSymbol, TablePartialSymbol, TableSymbol } from '../symbol';
|
|
4
4
|
import { Internable } from '../internable';
|
|
5
5
|
export declare enum MetadataKind {
|
|
6
6
|
Ref = "ref",
|
|
@@ -8,7 +8,8 @@ export declare enum MetadataKind {
|
|
|
8
8
|
TableChecks = "table checks",
|
|
9
9
|
Indexes = "indexes",
|
|
10
10
|
Records = "records",
|
|
11
|
-
Project = "project"
|
|
11
|
+
Project = "project",
|
|
12
|
+
MetadataElement = "metadata element"
|
|
12
13
|
}
|
|
13
14
|
declare const __nodeMetadataBrand: unique symbol;
|
|
14
15
|
export type NodeMetadataId = number & {
|
|
@@ -26,6 +27,11 @@ export declare abstract class NodeMetadata implements Internable<InternedNodeMet
|
|
|
26
27
|
constructor(declaration: SyntaxNode);
|
|
27
28
|
intern(): InternedNodeMetadata;
|
|
28
29
|
abstract owners(compiler: Compiler): NodeSymbol[];
|
|
30
|
+
/** Get programs (source files) that can both
|
|
31
|
+
* - reach this metadata's declaration file and
|
|
32
|
+
* - see all the given target symbols in their nested schema.
|
|
33
|
+
*/
|
|
34
|
+
resolveOwnerPrograms(compiler: Compiler, targets: NodeSymbol[]): ProgramSymbol[];
|
|
29
35
|
}
|
|
30
36
|
export declare class RefMetadata extends NodeMetadata {
|
|
31
37
|
declaration: ElementDeclarationNode | AttributeNode;
|
|
@@ -73,6 +79,13 @@ export declare class RecordsMetadata extends NodeMetadata {
|
|
|
73
79
|
table(compiler: Compiler): TableSymbol | undefined;
|
|
74
80
|
owners(compiler: Compiler): NodeSymbol[];
|
|
75
81
|
}
|
|
82
|
+
export declare class MetadataElementMetadata extends NodeMetadata {
|
|
83
|
+
declaration: ElementDeclarationNode;
|
|
84
|
+
readonly kind = MetadataKind.MetadataElement;
|
|
85
|
+
constructor(declaration: ElementDeclarationNode);
|
|
86
|
+
target(compiler: Compiler): NodeSymbol | undefined;
|
|
87
|
+
owners(compiler: Compiler): NodeSymbol[];
|
|
88
|
+
}
|
|
76
89
|
export declare class ProjectMetadata extends NodeMetadata {
|
|
77
90
|
readonly kind = MetadataKind.Project;
|
|
78
91
|
constructor(declaration: SyntaxNode);
|
|
@@ -24,6 +24,7 @@ export declare enum SymbolKind {
|
|
|
24
24
|
DiagramViewTableGroup = "DiagramView tablegroup",
|
|
25
25
|
DiagramViewNote = "DiagramView note",
|
|
26
26
|
DiagramViewSchema = "DiagramView schema",
|
|
27
|
+
Metadata = "Metadata",
|
|
27
28
|
Program = "Program"
|
|
28
29
|
}
|
|
29
30
|
export declare const ImportKind: {
|
|
@@ -35,6 +36,13 @@ export declare const ImportKind: {
|
|
|
35
36
|
Schema: SymbolKind;
|
|
36
37
|
};
|
|
37
38
|
export type ImportKind = (typeof ImportKind)[keyof typeof ImportKind];
|
|
39
|
+
/** Allowed target element types for a Metadata element header */
|
|
40
|
+
export declare enum MetadataTargetKind {
|
|
41
|
+
Table = "Table",
|
|
42
|
+
Column = "Column",
|
|
43
|
+
TableGroup = "TableGroup",
|
|
44
|
+
Note = "Note"
|
|
45
|
+
}
|
|
38
46
|
declare const __nodeSymbolBrand: unique symbol;
|
|
39
47
|
export type NodeSymbolId = number & {
|
|
40
48
|
readonly [__nodeSymbolBrand]: true;
|
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
import { default as Compiler } from '../../compiler';
|
|
2
|
-
import { Color, ColumnType, TokenPosition } from '../types/schemaJson';
|
|
2
|
+
import { Color, ColumnType, CustomMetadata, TokenPosition } from '../types/schemaJson';
|
|
3
3
|
import { SyntaxNode } from '../types/nodes';
|
|
4
4
|
import { default as Report } from '../types/report';
|
|
5
|
+
import { Settings } from './validate';
|
|
6
|
+
import { SettingName } from '../types';
|
|
5
7
|
export declare function getTokenPosition(node: SyntaxNode): TokenPosition;
|
|
6
8
|
export declare function normalizeNote(content: string): string;
|
|
7
9
|
export declare function extractElementName(nameNode: SyntaxNode): {
|
|
8
10
|
schemaName: string[];
|
|
9
11
|
name: string;
|
|
10
12
|
};
|
|
11
|
-
export declare function extractColor(node
|
|
13
|
+
export declare function extractColor(node?: SyntaxNode): Color | undefined;
|
|
12
14
|
export declare function processDefaultValue(valueNode?: SyntaxNode): {
|
|
13
15
|
type: 'number' | 'string' | 'boolean' | 'expression';
|
|
14
16
|
value: string | number;
|
|
15
17
|
} | undefined;
|
|
16
18
|
export declare function processColumnType(compiler: Compiler, typeNode: SyntaxNode): Report<ColumnType>;
|
|
19
|
+
/**
|
|
20
|
+
* Extract inline custom metadata from an aggregated setting list,
|
|
21
|
+
* excluding keys that are natively attached to the element (headercolor and note in `table`, color in `tablegroup`, .etc).
|
|
22
|
+
*
|
|
23
|
+
* NOTE: This is used during interpret phase, so no need to validate values, just extract them
|
|
24
|
+
*/
|
|
25
|
+
export declare function extractCustomInlineMetadata(settingMap: Settings, builtinSettings: readonly SettingName[]): CustomMetadata;
|
|
26
|
+
export declare function extractMetadataValue(node?: SyntaxNode): string | Color | undefined;
|
|
@@ -6,6 +6,9 @@ export declare function isAsKeyword(token?: SyntaxToken): token is SyntaxToken &
|
|
|
6
6
|
export declare function isUseKeyword(token?: SyntaxToken): token is SyntaxToken & {
|
|
7
7
|
kind: SyntaxTokenKind.IDENTIFIER;
|
|
8
8
|
};
|
|
9
|
+
export declare function isMetadataKeyword(token?: SyntaxToken): token is SyntaxToken & {
|
|
10
|
+
kind: SyntaxTokenKind.IDENTIFIER;
|
|
11
|
+
};
|
|
9
12
|
export declare function isFromKeyword(token?: SyntaxToken): token is SyntaxToken & {
|
|
10
13
|
kind: SyntaxTokenKind.IDENTIFIER;
|
|
11
14
|
};
|
|
@@ -24,7 +24,14 @@ export declare function isValidPartialInjection(node?: SyntaxNode): node is Pref
|
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
26
|
export declare function isRelationshipOp(op?: string): boolean;
|
|
27
|
-
export declare function
|
|
27
|
+
export declare function isValidHexColor(value?: SyntaxNode): value is PrimaryExpressionNode & {
|
|
28
|
+
expression: LiteralNode & {
|
|
29
|
+
literal: {
|
|
30
|
+
kind: SyntaxTokenKind.COLOR_LITERAL;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export declare function isValidColorOrNone(value?: SyntaxNode): boolean;
|
|
28
35
|
export declare function isValidDefaultValue(value?: SyntaxNode): boolean;
|
|
29
36
|
export type SignedNumberExpression = (PrimaryExpressionNode & {
|
|
30
37
|
expression: LiteralNode & {
|
|
@@ -45,6 +52,7 @@ export declare function isTupleOfVariables(value?: SyntaxNode): value is TupleEx
|
|
|
45
52
|
};
|
|
46
53
|
export declare function isValidColumnType(type: SyntaxNode): boolean;
|
|
47
54
|
export type Settings = Record<SettingName | string, AttributeNode[]>;
|
|
55
|
+
export declare function isValidMetadataValue(value?: SyntaxNode): boolean;
|
|
48
56
|
export declare function aggregateSettingList(settingList?: ListExpressionNode): Report<Settings>;
|
|
49
57
|
export declare function isExpressionAQuotedString(value?: unknown): value is PrimaryExpressionNode & ({
|
|
50
58
|
expression: VariableNode & {
|
|
@@ -84,7 +92,11 @@ type DotDelimitedIdentifier = PrimaryExpressionNode | (AccessExpression & {
|
|
|
84
92
|
});
|
|
85
93
|
export declare function isAccessExpression(node?: SyntaxNode): node is AccessExpression;
|
|
86
94
|
export declare function isDotDelimitedIdentifier(node?: SyntaxNode): node is DotDelimitedIdentifier;
|
|
87
|
-
export declare function isElementNode(node: SyntaxNode | undefined, kind:
|
|
95
|
+
export declare function isElementNode<T extends ElementKind>(node: SyntaxNode | undefined, kind: T): node is ElementDeclarationNode & {
|
|
96
|
+
type: {
|
|
97
|
+
value: T;
|
|
98
|
+
};
|
|
99
|
+
};
|
|
88
100
|
export declare function isUseDeclaration(node: SyntaxNode): node is UseDeclarationNode;
|
|
89
101
|
export declare function isUseSpecifier(node: SyntaxNode, kind?: ImportKind): node is UseSpecifierNode;
|
|
90
102
|
export declare function isWildcardSpecifier(node: SyntaxNode): node is WildcardNode;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export { SyntaxToken, SyntaxTokenKind, isTriviaToken, isOp, isOpToken, } from '.
|
|
|
10
10
|
export { CompileError, CompileErrorCode, } from './core/types/errors';
|
|
11
11
|
export type { Position, } from './core/types';
|
|
12
12
|
export { ScopeKind, splitQualifiedIdentifier, unescapeString, escapeString, formatRecordValue, isValidIdentifier, addDoubleQuoteIfNeeded, } from './compiler/index';
|
|
13
|
-
export { type Database, type MasterDatabase, type Table, type Note, type Column, type ColumnType, type Index, type Check, type InlineRef, type Ref, type RefEndpointPair, type RefEndpoint, type RelationCardinality, type Enum, type EnumField, type TableGroup, type TableGroupField, type Alias, type AliasKind, type TablePartial, type TablePartialInjection, type RecordValue, type RecordValueType, type TableRecord, type Project, type SchemaElement, type TokenPosition, type ElementRef, type FilterConfig, type DiagramView, } from './core/types/schemaJson';
|
|
13
|
+
export { type Database, type MasterDatabase, type Table, type Note, type Column, type ColumnType, type Index, type Check, type InlineRef, type Ref, type RefEndpointPair, type RefEndpoint, type RelationCardinality, type Enum, type EnumField, type TableGroup, type TableGroupField, type Alias, type AliasKind, type TablePartial, type TablePartialInjection, type RecordValue, type RecordValueType, type TableRecord, type Project, type SchemaElement, type TokenPosition, type ElementRef, type FilterConfig, type DiagramView, type CustomMetadata, } from './core/types/schemaJson';
|
|
14
14
|
export type { DiagramViewSyncOperation, DiagramViewBlock, TextEdit, } from './compiler/queries/transform';
|
|
15
15
|
export { dbmlLanguageConfig, dbmlMonarchTokensProvider, } from './services/monarch';
|
|
16
16
|
export * from './compiler/projectLayout/layout';
|
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
import { default as Compiler } from '../../compiler';
|
|
2
|
+
import { SettingName } from '../../core/types/keywords';
|
|
2
3
|
import { CompletionItemProvider, CompletionList, Position, TextModel } from '../types';
|
|
4
|
+
export declare const COLUMN_TYPE_SUGGESTION_LABELS: readonly ["integer", "int", "tinyint", "smallint", "mediumint", "bigint", "bit", "bool", "binary", "varbinary", "logical", "char", "nchar", "varchar", "varchar2", "nvarchar", "nvarchar2", "binary_float", "binary_double", "float", "double", "decimal", "dec", "real", "money", "smallmoney", "enum", "tinyblob", "tinytext", "blob", "text", "mediumblob", "mediumtext", "longblob", "longtext", "ntext", "set", "inet6", "uuid", "image", "date", "time", "datetime", "datetime2", "timestamp", "year", "smalldatetime", "datetimeoffset", "XML", "sql_variant", "uniqueidentifier", "CURSOR", "BFILE", "CLOB", "NCLOB", "RAW"];
|
|
5
|
+
export declare const TABLE_SETTING_SUGGESTION_LABELS: readonly [SettingName.HeaderColor, SettingName.Note];
|
|
6
|
+
export declare const TABLE_SETTING_SUGGESTION_TEXT_INSERTS: string[];
|
|
7
|
+
export declare const COLUMN_SUGGESTION_LABELS: (SettingName.Note | SettingName.PK | SettingName.PrimaryKey | SettingName.Unique | SettingName.Ref | SettingName.NotNull | SettingName.Null | SettingName.Increment | SettingName.Default | SettingName.Check)[];
|
|
8
|
+
export declare const COLUMN_SUGGESTION_TEXT_INSERTS: string[];
|
|
9
|
+
export declare const INDEX_SETTING_SUGGESTION_LABELS: (SettingName.Note | SettingName.PK | SettingName.Unique | SettingName.Name | SettingName.Type)[];
|
|
10
|
+
export declare const INDEX_SETTING_SUGGESTION_TEXT_INSERTS: string[];
|
|
11
|
+
export declare const REF_SETTING_SUGGESTION_LABELS: (SettingName.Color | SettingName.Update | SettingName.Delete | SettingName.Inactive)[];
|
|
12
|
+
export declare const REF_SETTING_SUGGESTION_TEXT_INSERTS: string[];
|
|
13
|
+
export declare const ENUM_SETTING_SUGGESTION_LABELS: readonly [SettingName.Note];
|
|
14
|
+
export declare const ENUM_SETTING_SUGGESTION_TEXT_INSERTS: string[];
|
|
15
|
+
export declare const CHECK_SETTING_SUGGESTION_LABELS: readonly [SettingName.Name];
|
|
16
|
+
export declare const CHECK_SETTING_SUGGESTION_TEXT_INSERTS: string[];
|
|
17
|
+
export declare const REF_ACTION_VALUE_SUGGESTIONS: readonly ["cascade", "set default", "set null", "restrict"];
|
|
18
|
+
export declare const INDEX_TYPE_VALUE_SUGGESTIONS: readonly ["btree", "hash"];
|
|
19
|
+
export declare const TABLE_BODY_SUGGESTION_LABELS: ("indexes" | "checks" | "Note" | "Records")[];
|
|
20
|
+
export declare const PROJECT_FIELD_SUGGESTION_LABELS: ("Table" | "Enum" | "TableGroup" | "TablePartial" | "Note" | "Ref")[];
|
|
3
21
|
export interface DBMLCompletionItemProviderOptions {
|
|
4
22
|
triggerCharacters?: string[];
|
|
5
23
|
}
|
|
@@ -9,3 +27,4 @@ export default class DBMLCompletionItemProvider implements CompletionItemProvide
|
|
|
9
27
|
constructor(compiler: Compiler, options?: DBMLCompletionItemProviderOptions);
|
|
10
28
|
provideCompletionItems(model: TextModel, position: Position): CompletionList;
|
|
11
29
|
}
|
|
30
|
+
export declare const TOP_LEVEL_SUGGESTION_LABELS: ("Table" | "Enum" | "TableGroup" | "TablePartial" | "Note" | "DiagramView" | "Metadata" | "Ref" | "Project" | "Records")[];
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@dbml/parse",
|
|
4
|
-
"version": "8.4.0-
|
|
4
|
+
"version": "8.4.0-custom-metadata.0",
|
|
5
5
|
"description": "DBML parser v2",
|
|
6
6
|
"author": "Holistics <dev@holistics.io>",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"engines": {
|
|
51
51
|
"node": ">=18"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "9efcfd5f8e6981432397d7d242ddfe05b01aec09"
|
|
54
54
|
}
|