@dbml/parse 10.4.0-alpha.2 → 10.4.0-alpha.3
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 +26 -26
- package/dist/dbml-parse.mjs +4806 -4642
- package/dist/src/compiler/index.d.ts +19 -0
- package/dist/src/compiler/queries/metadata/isSymbolVisible.d.ts +10 -0
- package/dist/src/compiler/queries/metadata/metadataTargets.d.ts +7 -0
- package/dist/src/compiler/queries/symbol/visibleSymbols.d.ts +7 -0
- package/dist/src/core/global_modules/metadata/utils.d.ts +11 -9
- package/dist/src/core/global_modules/ref/index.d.ts +4 -0
- package/dist/src/core/global_modules/ref/interpret.d.ts +3 -1
- package/dist/src/core/types/schemaJson/types.d.ts +8 -2
- package/dist/src/core/types/symbol/symbols.d.ts +11 -1
- package/dist/src/core/utils/expression.d.ts +1 -0
- package/dist/src/core/utils/interpret.d.ts +2 -2
- package/dist/src/core/utils/validate.d.ts +0 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/services/suggestions/provider.d.ts +1 -1
- package/package.json +2 -2
|
@@ -50,7 +50,26 @@ export default class Compiler {
|
|
|
50
50
|
symbolMetadata: (symbol: import('../core/types/symbol').NodeSymbol) => import('../core/types/symbol').NodeMetadata[];
|
|
51
51
|
symbolAliases: (symbol: import('../core/types/symbol').NodeSymbol) => import('../core/types/report').default<import('../core/types/symbol').AliasSymbol[]>;
|
|
52
52
|
symbolUses: (symbol: import('../core/types/symbol').NodeSymbol) => import('../core/types/report').default<import('../core/types/symbol').UseSymbol[]>;
|
|
53
|
+
/**
|
|
54
|
+
* A global query
|
|
55
|
+
* Return the named refs visible from a program (refs are not imported via `use`).
|
|
56
|
+
*/
|
|
57
|
+
visibleSymbols: (program: import('../core/types/symbol').ProgramSymbol, kind: import('../core/types/symbol').SymbolKind) => import('../core/types/symbol').RefSymbol[];
|
|
58
|
+
/**
|
|
59
|
+
* A global query
|
|
60
|
+
* Whether a symbol is visible from a program
|
|
61
|
+
*/
|
|
62
|
+
isSymbolVisible: (program: import('../core/types/symbol').ProgramSymbol, symbol: import('../core/types/symbol').NodeSymbol) => boolean;
|
|
63
|
+
/**
|
|
64
|
+
* A global query
|
|
65
|
+
* Resolve all candidates that a metadata block can target
|
|
66
|
+
*/
|
|
67
|
+
metadataTargets: (block: import('../core/types/symbol').MetadataElementMetadata) => import('../core/types/symbol').NodeSymbol[];
|
|
53
68
|
fileDependencies: (filepath: Filepath) => Filepath[];
|
|
69
|
+
/**
|
|
70
|
+
* A global query
|
|
71
|
+
* BFS-traverse imports from an entry filepath and return all reachable files. Related: fileDependencies.
|
|
72
|
+
*/
|
|
54
73
|
reachableFiles: (entry?: Filepath | undefined) => Filepath[];
|
|
55
74
|
usableMembers: (symbolOrFilepath: Filepath | import('../core/types/symbol').SchemaSymbol | import('../core/types/symbol').ProgramSymbol) => import('../core/types/report').default<{
|
|
56
75
|
nonSchemaMembers: import('../core/types/symbol').NodeSymbol[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { NodeSymbol, ProgramSymbol } from '../../../core/types/symbol';
|
|
2
|
+
import { default as Compiler } from '../../index';
|
|
3
|
+
/**
|
|
4
|
+
* Whether `symbol` is visible from `program`.
|
|
5
|
+
* - Column: visible when its table is (a column is not a direct schema member)
|
|
6
|
+
* - Ref: refs are not imported via `use`, a ref is visible when it shows up in the program's output,
|
|
7
|
+
* i.e. the program reaches the ref's file and sees both endpoint tables (RefMetadata.owners)
|
|
8
|
+
* - otherwise: the symbol sits in the program's schemas, directly or through `use`
|
|
9
|
+
*/
|
|
10
|
+
export declare function isSymbolVisible(this: Compiler, program: ProgramSymbol, symbol: NodeSymbol): boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { NodeSymbol } from '../../../core/types/symbol';
|
|
2
|
+
import { MetadataElementMetadata } from '../../../core/types/symbol/metadata';
|
|
3
|
+
import { default as Compiler } from '../../index';
|
|
4
|
+
/**
|
|
5
|
+
* Resolve the candidates a Metadata block targets, from its `<target-kind> <name>` header.
|
|
6
|
+
*/
|
|
7
|
+
export declare function metadataTargets(this: Compiler, block: MetadataElementMetadata): NodeSymbol[];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ProgramSymbol, RefSymbol, SymbolKind } from '../../../core/types/symbol';
|
|
2
|
+
import { default as Compiler } from '../../index';
|
|
3
|
+
/**
|
|
4
|
+
* Named refs usable from `program`: refs are not imported via `use`, a named ref is visible
|
|
5
|
+
* wherever it shows up in the output (see isSymbolVisible).
|
|
6
|
+
*/
|
|
7
|
+
export declare function visibleSymbols(this: Compiler, program: ProgramSymbol, kind: SymbolKind): RefSymbol[];
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { default as Compiler } from '../../../compiler/index';
|
|
2
2
|
import { Filepath, SettingName } from '../../types';
|
|
3
|
-
import { Column, Note, Table, TableGroup, TokenPosition } from '../../types/schemaJson';
|
|
4
|
-
import {
|
|
3
|
+
import { Column, CustomMetadataValue, Note, Ref, Table, TableGroup, TokenPosition } from '../../types/schemaJson';
|
|
4
|
+
import { SyntaxNode } from '../../types/nodes';
|
|
5
5
|
import { NodeSymbol, SymbolKind, MetadataTargetKind } from '../../types/symbol';
|
|
6
|
-
export type MetadataTarget = Table | TableGroup | Note | Column;
|
|
6
|
+
export type MetadataTarget = Table | TableGroup | Note | Column | Ref;
|
|
7
7
|
/**
|
|
8
8
|
* Specs for builtin metadata (table's note, tablegroup's color, .etc) for different element types. Does 2 things:
|
|
9
9
|
* - `validate`: Validating if the metadata value is syntactically correct
|
|
@@ -14,16 +14,18 @@ interface MetadataField<T extends MetadataTarget> {
|
|
|
14
14
|
isValidBuiltinFieldValue(node?: SyntaxNode): boolean;
|
|
15
15
|
message: string;
|
|
16
16
|
/** Write the metadata value to the element builtin props (e.g. write to `table.note`) */
|
|
17
|
-
assignBuiltinField(element: Partial<T>, value:
|
|
17
|
+
assignBuiltinField(element: Partial<T>, value: CustomMetadataValue, token: TokenPosition): void;
|
|
18
18
|
}
|
|
19
|
-
export type MetadataFieldRegistry<T extends MetadataTarget, K extends SettingName
|
|
20
|
-
type NameWithSymbolKind = {
|
|
19
|
+
export type MetadataFieldRegistry<T extends MetadataTarget, K extends SettingName> = Record<K, MetadataField<T>>;
|
|
20
|
+
export type NameWithSymbolKind = {
|
|
21
21
|
name: string;
|
|
22
22
|
symbolKind: SymbolKind;
|
|
23
23
|
};
|
|
24
24
|
/** @internal Exported for testing only. */
|
|
25
|
-
export declare function mapNamePartToSymbolKind(nameParts: string[], targetKind: MetadataTargetKind): NameWithSymbolKind[];
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
export declare function mapNamePartToSymbolKind(nameParts: string[], targetKind: Exclude<MetadataTargetKind, MetadataTargetKind.Ref>): NameWithSymbolKind[];
|
|
26
|
+
/**
|
|
27
|
+
* Merge every custom-metadata block applying to the target in the current program (in precedence order) to its `metadata` and other builtin (note/headercolor/...) fields
|
|
28
|
+
* NOTE: Only run during interpret phase
|
|
29
|
+
*/
|
|
28
30
|
export declare function attachCustomMetadata<T extends MetadataTarget>(compiler: Compiler, targetElement: Partial<T>, targetSymbol: NodeSymbol, fieldsRegistry: MetadataFieldRegistry<T, any>, filepath: Filepath): void;
|
|
29
31
|
export {};
|
|
@@ -2,6 +2,10 @@ import { default as Compiler } from '../../../compiler/index';
|
|
|
2
2
|
import { SyntaxNode } from '../../types/nodes';
|
|
3
3
|
import { default as Report } from '../../types/report';
|
|
4
4
|
import { NodeSymbol } from '../../types/symbol';
|
|
5
|
+
import { CompileError } from '../../types';
|
|
5
6
|
import { GlobalModule } from '../types';
|
|
7
|
+
export declare const refUtils: {
|
|
8
|
+
getDuplicateError(name: string, schemaLabel: string, errorNode: SyntaxNode): CompileError;
|
|
9
|
+
};
|
|
6
10
|
export declare const refModule: GlobalModule;
|
|
7
11
|
export declare function nodeRefereeOfRefEndpoint(compiler: Compiler, globalSymbol: NodeSymbol, node: SyntaxNode): Report<NodeSymbol | undefined>;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Ref } from '../../types/schemaJson';
|
|
2
|
-
import { RefMetadata, Filepath } from '../../types';
|
|
2
|
+
import { RefMetadata, SettingName, Filepath } from '../../types';
|
|
3
3
|
import { default as Compiler } from '../../../compiler';
|
|
4
4
|
import { default as Report } from '../../types/report';
|
|
5
|
+
import { MetadataFieldRegistry } from '../metadata/utils';
|
|
6
|
+
export declare const REF_METADATA_FIELDS: MetadataFieldRegistry<Ref, SettingName.Color | SettingName.Note>;
|
|
5
7
|
export declare class RefInterpreter {
|
|
6
8
|
private compiler;
|
|
7
9
|
private metadata;
|
|
@@ -2,7 +2,8 @@ import { NONE_COLOR } from '../../../constants';
|
|
|
2
2
|
import { Filepath } from '../filepath';
|
|
3
3
|
import { Position } from '../position';
|
|
4
4
|
import { RelationshipOp, RelationCardinality } from '../relation';
|
|
5
|
-
export type
|
|
5
|
+
export type CustomMetadataValue = string | Color | number | boolean;
|
|
6
|
+
export type CustomMetadata = Record<string, CustomMetadataValue>;
|
|
6
7
|
export type Color = `#${string}` | typeof NONE_COLOR;
|
|
7
8
|
export declare enum AliasKind {
|
|
8
9
|
Table = "table"
|
|
@@ -164,9 +165,14 @@ export interface Ref {
|
|
|
164
165
|
name: string | null;
|
|
165
166
|
endpoints: RefEndpointPair;
|
|
166
167
|
color?: Color;
|
|
168
|
+
note?: {
|
|
169
|
+
value: string;
|
|
170
|
+
token: TokenPosition;
|
|
171
|
+
};
|
|
167
172
|
onDelete?: string;
|
|
168
173
|
onUpdate?: string;
|
|
169
174
|
inactive?: boolean;
|
|
175
|
+
metadata?: CustomMetadata;
|
|
170
176
|
token: TokenPosition;
|
|
171
177
|
}
|
|
172
178
|
export type RefEndpointPair = [RefEndpoint, RefEndpoint];
|
|
@@ -280,7 +286,7 @@ export interface TableRecord {
|
|
|
280
286
|
token: TokenPosition;
|
|
281
287
|
}
|
|
282
288
|
export type MetadataValues = Record<string, {
|
|
283
|
-
value:
|
|
289
|
+
value: CustomMetadataValue;
|
|
284
290
|
token: TokenPosition;
|
|
285
291
|
}>;
|
|
286
292
|
export type Project = Record<string, never> | {
|
|
@@ -16,6 +16,7 @@ export declare enum SymbolKind {
|
|
|
16
16
|
Enum = "Enum",
|
|
17
17
|
EnumField = "Enum field",
|
|
18
18
|
StickyNote = "Note",
|
|
19
|
+
Ref = "Ref",
|
|
19
20
|
TablePartial = "TablePartial",
|
|
20
21
|
PartialInjection = "PartialInjection",
|
|
21
22
|
DiagramView = "DiagramView",
|
|
@@ -41,7 +42,8 @@ export declare enum MetadataTargetKind {
|
|
|
41
42
|
Table = "Table",
|
|
42
43
|
Column = "Column",
|
|
43
44
|
TableGroup = "TableGroup",
|
|
44
|
-
Note = "Note"
|
|
45
|
+
Note = "Note",
|
|
46
|
+
Ref = "Ref"
|
|
45
47
|
}
|
|
46
48
|
declare const __nodeSymbolBrand: unique symbol;
|
|
47
49
|
export type NodeSymbolId = number & {
|
|
@@ -211,6 +213,14 @@ export declare class NoteSymbol extends NodeSymbol {
|
|
|
211
213
|
get canBeImported(): boolean;
|
|
212
214
|
get originalSymbol(): NodeSymbol;
|
|
213
215
|
}
|
|
216
|
+
export declare class RefSymbol extends NodeSymbol {
|
|
217
|
+
constructor({ declaration, name, }: {
|
|
218
|
+
declaration?: SyntaxNode;
|
|
219
|
+
name?: string;
|
|
220
|
+
}, id: NodeSymbolId, filepath: Filepath);
|
|
221
|
+
get canBeImported(): boolean;
|
|
222
|
+
get originalSymbol(): NodeSymbol;
|
|
223
|
+
}
|
|
214
224
|
export declare class TablePartialSymbol extends NodeSymbol {
|
|
215
225
|
constructor({ declaration, name, }: {
|
|
216
226
|
declaration?: SyntaxNode;
|
|
@@ -23,6 +23,7 @@ export declare function destructureIndexNode(node?: SyntaxNode): {
|
|
|
23
23
|
} | undefined;
|
|
24
24
|
export declare function extractQuotedStringToken(value?: SyntaxNode): string | undefined;
|
|
25
25
|
export declare function extractNumericLiteral(node?: SyntaxNode): number | null;
|
|
26
|
+
export declare function extractBooleanLiteral(node?: SyntaxNode): boolean | null;
|
|
26
27
|
export declare function destructureCallExpression(node?: SyntaxNode): {
|
|
27
28
|
variables: (PrimaryExpressionNode & {
|
|
28
29
|
expression: VariableNode;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { default as Compiler } from '../../compiler';
|
|
2
|
-
import { Color, ColumnType, CustomMetadata, TokenPosition } from '../types/schemaJson';
|
|
2
|
+
import { Color, ColumnType, CustomMetadata, CustomMetadataValue, TokenPosition } from '../types/schemaJson';
|
|
3
3
|
import { SyntaxNode } from '../types/nodes';
|
|
4
4
|
import { default as Report } from '../types/report';
|
|
5
5
|
import { Settings } from './validate';
|
|
@@ -23,4 +23,4 @@ export declare function processColumnType(compiler: Compiler, typeNode: SyntaxNo
|
|
|
23
23
|
* NOTE: This is used during interpret phase, so no need to validate values, just extract them
|
|
24
24
|
*/
|
|
25
25
|
export declare function extractCustomInlineMetadata(settingMap: Settings, builtinSettings: readonly SettingName[]): CustomMetadata;
|
|
26
|
-
export declare function extractMetadataValue(node?: SyntaxNode):
|
|
26
|
+
export declare function extractMetadataValue(node?: SyntaxNode): CustomMetadataValue | undefined;
|
|
@@ -54,7 +54,6 @@ export declare function isTupleOfVariables(value?: SyntaxNode): value is TupleEx
|
|
|
54
54
|
};
|
|
55
55
|
export declare function isValidColumnType(type: SyntaxNode): boolean;
|
|
56
56
|
export type Settings = Record<SettingName | string, AttributeNode[]>;
|
|
57
|
-
export declare function isValidMetadataValue(value?: SyntaxNode): boolean;
|
|
58
57
|
export declare function aggregateSettingList(settingList?: ListExpressionNode): Report<Settings>;
|
|
59
58
|
export declare function isExpressionAQuotedString(value?: unknown): value is PrimaryExpressionNode & ({
|
|
60
59
|
expression: VariableNode & {
|
package/dist/src/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export { CompileError, CompileErrorCode, CompileWarning, CompileInfo, } from './
|
|
|
12
12
|
export type { Diagnostic, DiagnosticQuickFix } from './services/diagnostics/provider';
|
|
13
13
|
export type { Position, } from './core/types';
|
|
14
14
|
export { ScopeKind, splitQualifiedIdentifier, unescapeString, escapeString, formatRecordValue, isValidIdentifier, addDoubleQuoteIfNeeded, normalizeQualifiedName, } from './compiler/index';
|
|
15
|
-
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 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';
|
|
15
|
+
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 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, type CustomMetadataValue, } from './core/types/schemaJson';
|
|
16
16
|
export { type RelationCardinality, type RelationshipOp, getRelationshipOp, getMultiplicities, parseCardinality, makeCardinalityRequired, makeCardinalityOptional, makeRelationshipRequired, isEndpointOneSide, isEndpointManySide, isEndpointOptional, isEndpointRequired, CARDINALITY_ONE, CARDINALITY_MAYBE, CARDINALITY_SOME, CARDINALITY_MANY, } from './core/types/relation';
|
|
17
17
|
export type { DiagramViewSyncOperation, DiagramViewBlock, TextEdit, } from './compiler/queries/transform';
|
|
18
18
|
export { findDiagramViewBlocks } from './compiler/queries/transform';
|
|
@@ -29,4 +29,4 @@ export default class DBMLCompletionItemProvider implements CompletionItemProvide
|
|
|
29
29
|
constructor(compiler: Compiler, options?: DBMLCompletionItemProviderOptions);
|
|
30
30
|
provideCompletionItems(model: TextModel, position: Position): CompletionList;
|
|
31
31
|
}
|
|
32
|
-
export declare const TOP_LEVEL_SUGGESTION_LABELS: ("Table" | "Enum" | "TableGroup" | "TablePartial" | "Note" | "
|
|
32
|
+
export declare const TOP_LEVEL_SUGGESTION_LABELS: ("Table" | "Enum" | "TableGroup" | "TablePartial" | "Note" | "Ref" | "DiagramView" | "Metadata" | "Dep" | "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": "10.4.0-alpha.
|
|
4
|
+
"version": "10.4.0-alpha.3",
|
|
5
5
|
"description": "DBML parser v2",
|
|
6
6
|
"author": "Holistics <dev@holistics.io>",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"engines": {
|
|
52
52
|
"node": ">=18"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "3c5f2624711c16e2b5011f118c62899f41abca7d"
|
|
55
55
|
}
|