@dbml/parse 8.3.0 → 8.4.0-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 +25001 -28
- package/dist/dbml-parse.mjs +20005 -10406
- 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 +15 -0
- package/dist/src/core/global_modules/metadata/resolve.d.ts +4 -0
- 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/validate.d.ts +28 -0
- package/dist/src/core/types/errors.d.ts +6 -1
- package/dist/src/core/types/keywords.d.ts +2 -1
- package/dist/src/core/types/nodes.d.ts +22 -4
- package/dist/src/core/types/schemaJson.d.ts +12 -1
- package/dist/src/core/types/symbol/metadata.d.ts +10 -1
- package/dist/src/core/types/symbol/symbols.d.ts +10 -0
- package/dist/src/core/utils/validate.d.ts +7 -2
- package/package.json +2 -2
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { default as Compiler } from '../../../compiler';
|
|
2
|
+
import { CompileError } from '../../types';
|
|
3
|
+
import { MetadataElementNode } from '../../types/nodes';
|
|
4
|
+
export default class MetadataBinder {
|
|
5
|
+
private compiler;
|
|
6
|
+
private declarationNode;
|
|
7
|
+
constructor(compiler: Compiler, declarationNode: MetadataElementNode);
|
|
8
|
+
bind(): CompileError[];
|
|
9
|
+
private bindTargetElement;
|
|
10
|
+
private bindBody;
|
|
11
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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 { MetadataElement } from '../../types/schemaJson';
|
|
6
|
+
export default class MetadataInterpreter {
|
|
7
|
+
private declarationNode;
|
|
8
|
+
private compiler;
|
|
9
|
+
private filepath;
|
|
10
|
+
private metadata;
|
|
11
|
+
constructor(compiler: Compiler, metadata: MetadataElementMetadata, filepath: Filepath);
|
|
12
|
+
interpret(): Report<MetadataElement>;
|
|
13
|
+
private interpretTarget;
|
|
14
|
+
private interpretValues;
|
|
15
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { default as Compiler } from '../../../compiler/index';
|
|
2
|
+
import { ElementDeclarationNode } from '../../types/nodes';
|
|
3
|
+
import { NodeSymbol } from '../../types/symbol';
|
|
4
|
+
export declare function resolveMetadataTarget(compiler: Compiler, metadataNode: ElementDeclarationNode): NodeSymbol | undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { default as Compiler } from '../../compiler';
|
|
2
|
-
import { RelationCardinality } from '../types';
|
|
2
|
+
import { Filepath, 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 getGlobalSymbol(compiler: Compiler, filepath: Filepath): NodeSymbol | undefined;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { default as Compiler } from '../../../compiler';
|
|
2
|
+
import { CompileError } from '../../types/errors';
|
|
3
|
+
import { ElementDeclarationNode } from '../../types/nodes';
|
|
4
|
+
import { ElementKind, MetadataTargetKind } from '../../types';
|
|
5
|
+
import { SyntaxToken } from '../../types/tokens';
|
|
6
|
+
export declare function isValidMetadataSubKind(metadataNode: ElementDeclarationNode): metadataNode is ElementDeclarationNode & {
|
|
7
|
+
subKind: SyntaxToken & {
|
|
8
|
+
value: MetadataTargetKind;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export default class MetadataValidator {
|
|
12
|
+
private declarationNode;
|
|
13
|
+
private compiler;
|
|
14
|
+
constructor(compiler: Compiler, declarationNode: ElementDeclarationNode & {
|
|
15
|
+
type: {
|
|
16
|
+
value: ElementKind.Metadata;
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
validate(): CompileError[];
|
|
20
|
+
private validateContext;
|
|
21
|
+
private validateSubKind;
|
|
22
|
+
private validateName;
|
|
23
|
+
private validateAlias;
|
|
24
|
+
private validateSettingList;
|
|
25
|
+
private validateBody;
|
|
26
|
+
private validateFields;
|
|
27
|
+
private validateSubElements;
|
|
28
|
+
}
|
|
@@ -113,7 +113,12 @@ 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_CONTEXT = 5006,
|
|
118
|
+
INVALID_METADATA_TARGET_KIND = 5007,
|
|
119
|
+
INVALID_METADATA_FIELD = 5008,
|
|
120
|
+
DUPLICATE_METADATA_FIELD = 5009,
|
|
121
|
+
METADATA_TARGET_NOT_FOUND = 5010
|
|
117
122
|
}
|
|
118
123
|
export declare class CompileError extends Error {
|
|
119
124
|
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",
|
|
@@ -86,11 +86,13 @@ export declare class UseDeclarationNode extends SyntaxNode {
|
|
|
86
86
|
}
|
|
87
87
|
export declare class UseSpecifierNode extends SyntaxNode {
|
|
88
88
|
importKind?: SyntaxToken;
|
|
89
|
+
subKind?: SyntaxToken;
|
|
89
90
|
name?: NormalExpressionNode;
|
|
90
91
|
asKeyword?: SyntaxToken;
|
|
91
92
|
alias?: NormalExpressionNode;
|
|
92
|
-
constructor({ importKind, name, asKeyword, alias, }: {
|
|
93
|
+
constructor({ importKind, subKind, name, asKeyword, alias, }: {
|
|
93
94
|
importKind?: SyntaxToken;
|
|
95
|
+
subKind?: SyntaxToken;
|
|
94
96
|
name?: NormalExpressionNode;
|
|
95
97
|
asKeyword?: SyntaxToken;
|
|
96
98
|
alias?: NormalExpressionNode;
|
|
@@ -110,14 +112,16 @@ export declare class UseSpecifierListNode extends SyntaxNode {
|
|
|
110
112
|
}
|
|
111
113
|
export declare class ElementDeclarationNode extends SyntaxNode {
|
|
112
114
|
type?: SyntaxToken;
|
|
115
|
+
subKind?: SyntaxToken;
|
|
113
116
|
name?: NormalExpressionNode;
|
|
114
117
|
as?: SyntaxToken;
|
|
115
118
|
alias?: NormalExpressionNode;
|
|
116
119
|
attributeList?: ListExpressionNode;
|
|
117
120
|
bodyColon?: SyntaxToken;
|
|
118
121
|
body?: FunctionApplicationNode | BlockExpressionNode;
|
|
119
|
-
constructor({ type, name, as, alias, attributeList, bodyColon, body, }: {
|
|
122
|
+
constructor({ type, subKind, name, as, alias, attributeList, bodyColon, body, }: {
|
|
120
123
|
type?: SyntaxToken;
|
|
124
|
+
subKind?: SyntaxToken;
|
|
121
125
|
name?: NormalExpressionNode;
|
|
122
126
|
as?: SyntaxToken;
|
|
123
127
|
alias?: NormalExpressionNode;
|
|
@@ -125,9 +129,23 @@ export declare class ElementDeclarationNode extends SyntaxNode {
|
|
|
125
129
|
bodyColon?: SyntaxToken;
|
|
126
130
|
body?: BlockExpressionNode | FunctionApplicationNode;
|
|
127
131
|
}, id: SyntaxNodeId, filepath: Filepath);
|
|
128
|
-
isKind(...kinds:
|
|
129
|
-
|
|
132
|
+
isKind<T extends ElementKind>(...kinds: T[]): this is ElementDeclarationNode & {
|
|
133
|
+
type: {
|
|
134
|
+
value: T;
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
getElementKind<T extends ElementKind>(this: ElementDeclarationNode & {
|
|
138
|
+
type: {
|
|
139
|
+
value: T;
|
|
140
|
+
};
|
|
141
|
+
}): T;
|
|
142
|
+
getElementKind(this: ElementDeclarationNode): ElementKind | undefined;
|
|
130
143
|
}
|
|
144
|
+
export type MetadataElementNode = ElementDeclarationNode & {
|
|
145
|
+
type: {
|
|
146
|
+
value: ElementKind.Metadata;
|
|
147
|
+
};
|
|
148
|
+
};
|
|
131
149
|
export declare class IdentifierStreamNode extends SyntaxNode {
|
|
132
150
|
identifiers: SyntaxToken[];
|
|
133
151
|
constructor({ identifiers, }: {
|
|
@@ -66,6 +66,7 @@ export interface Database {
|
|
|
66
66
|
records: TableRecord[];
|
|
67
67
|
externals: DatabaseExternals;
|
|
68
68
|
diagramViews: DiagramView[];
|
|
69
|
+
metadataElements: MetadataElement[];
|
|
69
70
|
token?: TokenPosition;
|
|
70
71
|
}
|
|
71
72
|
export interface MasterDatabase {
|
|
@@ -238,6 +239,16 @@ export interface TableRecord {
|
|
|
238
239
|
values: RecordValue[][];
|
|
239
240
|
token: TokenPosition;
|
|
240
241
|
}
|
|
242
|
+
export interface MetadataElement {
|
|
243
|
+
target: {
|
|
244
|
+
kind: string;
|
|
245
|
+
name: string[];
|
|
246
|
+
};
|
|
247
|
+
values: {
|
|
248
|
+
[key: string]: unknown;
|
|
249
|
+
};
|
|
250
|
+
token: TokenPosition;
|
|
251
|
+
}
|
|
241
252
|
export type Project = Record<string, never> | {
|
|
242
253
|
name: string | null;
|
|
243
254
|
tables: Table[];
|
|
@@ -252,4 +263,4 @@ export type Project = Record<string, never> | {
|
|
|
252
263
|
token: TokenPosition;
|
|
253
264
|
[index: string & Omit<any, 'name' | 'tables' | 'refs' | 'enums' | 'tableGroups' | 'note' | 'tablePartials' | 'records'>]: string;
|
|
254
265
|
};
|
|
255
|
-
export type SchemaElement = Database | Project | Table | Note | Column | ColumnType | Index | Check | InlineRef | Ref | RefEndpoint | Enum | EnumField | TableGroup | TableGroupField | Alias | TablePartial | TablePartialInjection | TableRecord | RecordValue;
|
|
266
|
+
export type SchemaElement = Database | Project | Table | Note | Column | ColumnType | Index | Check | InlineRef | Ref | RefEndpoint | Enum | EnumField | TableGroup | TableGroupField | Alias | TablePartial | TablePartialInjection | TableRecord | RecordValue | MetadataElement;
|
|
@@ -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,7 @@ 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
|
+
reachableOwners(compiler: Compiler, targets: NodeSymbol[]): NodeSymbol[];
|
|
29
31
|
}
|
|
30
32
|
export declare class RefMetadata extends NodeMetadata {
|
|
31
33
|
declaration: ElementDeclarationNode | AttributeNode;
|
|
@@ -73,6 +75,13 @@ export declare class RecordsMetadata extends NodeMetadata {
|
|
|
73
75
|
table(compiler: Compiler): TableSymbol | undefined;
|
|
74
76
|
owners(compiler: Compiler): NodeSymbol[];
|
|
75
77
|
}
|
|
78
|
+
export declare class MetadataElementMetadata extends NodeMetadata {
|
|
79
|
+
declaration: ElementDeclarationNode;
|
|
80
|
+
readonly kind = MetadataKind.MetadataElement;
|
|
81
|
+
constructor(declaration: ElementDeclarationNode);
|
|
82
|
+
target(compiler: Compiler): NodeSymbol | undefined;
|
|
83
|
+
owners(compiler: Compiler): NodeSymbol[];
|
|
84
|
+
}
|
|
76
85
|
export declare class ProjectMetadata extends NodeMetadata {
|
|
77
86
|
readonly kind = MetadataKind.Project;
|
|
78
87
|
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: {
|
|
@@ -33,8 +34,17 @@ export declare const ImportKind: {
|
|
|
33
34
|
TablePartial: SymbolKind;
|
|
34
35
|
Note: SymbolKind;
|
|
35
36
|
Schema: SymbolKind;
|
|
37
|
+
Metadata: SymbolKind;
|
|
36
38
|
};
|
|
37
39
|
export type ImportKind = (typeof ImportKind)[keyof typeof ImportKind];
|
|
40
|
+
export declare enum MetadataTargetKind {
|
|
41
|
+
Table = "table",
|
|
42
|
+
Schema = "schema",
|
|
43
|
+
Column = "column",
|
|
44
|
+
TableGroup = "tablegroup",
|
|
45
|
+
Note = "note"
|
|
46
|
+
}
|
|
47
|
+
export declare const ALLOWED_METADATA_TARGET_KINDS: readonly MetadataTargetKind[];
|
|
38
48
|
declare const __nodeSymbolBrand: unique symbol;
|
|
39
49
|
export type NodeSymbolId = number & {
|
|
40
50
|
readonly [__nodeSymbolBrand]: true;
|
|
@@ -2,7 +2,7 @@ import { AttributeNode, BlockExpressionNode, ElementDeclarationNode, FunctionApp
|
|
|
2
2
|
import { default as Report } from '../types/report';
|
|
3
3
|
import { SyntaxToken, SyntaxTokenKind } from '../types/tokens';
|
|
4
4
|
import { ElementKind, SettingName } from '../types/keywords';
|
|
5
|
-
import { ImportKind } from '../types/symbol';
|
|
5
|
+
import { ImportKind, MetadataTargetKind } from '../types/symbol';
|
|
6
6
|
export declare function isValidName(nameNode: SyntaxNode): boolean;
|
|
7
7
|
export declare function isValidAlias(aliasNode: SyntaxNode): aliasNode is PrimaryExpressionNode & {
|
|
8
8
|
expression: VariableNode;
|
|
@@ -84,7 +84,11 @@ type DotDelimitedIdentifier = PrimaryExpressionNode | (AccessExpression & {
|
|
|
84
84
|
});
|
|
85
85
|
export declare function isAccessExpression(node?: SyntaxNode): node is AccessExpression;
|
|
86
86
|
export declare function isDotDelimitedIdentifier(node?: SyntaxNode): node is DotDelimitedIdentifier;
|
|
87
|
-
export declare function isElementNode(node: SyntaxNode | undefined, kind:
|
|
87
|
+
export declare function isElementNode<T extends ElementKind>(node: SyntaxNode | undefined, kind: T): node is ElementDeclarationNode & {
|
|
88
|
+
type: {
|
|
89
|
+
value: T;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
88
92
|
export declare function isUseDeclaration(node: SyntaxNode): node is UseDeclarationNode;
|
|
89
93
|
export declare function isUseSpecifier(node: SyntaxNode, kind?: ImportKind): node is UseSpecifierNode;
|
|
90
94
|
export declare function isWildcardSpecifier(node: SyntaxNode): node is WildcardNode;
|
|
@@ -101,4 +105,5 @@ export declare function isValidIndexName(value?: SyntaxNode): value is (PrimaryE
|
|
|
101
105
|
}) | FunctionExpressionNode;
|
|
102
106
|
export declare function getRightmostVariable(node: SyntaxNode): SyntaxNode | undefined;
|
|
103
107
|
export declare function isTerminalAccessFragment(node: SyntaxNode): boolean;
|
|
108
|
+
export declare function getElementSubKind(elementKind: ElementKind | undefined, subKindToken?: SyntaxToken): MetadataTargetKind | undefined;
|
|
104
109
|
export {};
|
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
|
+
"version": "8.4.0-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": "732826ecba8655dfd36d8adcb89f81b597e85fd2"
|
|
54
54
|
}
|