@dbml/parse 8.3.1-custom-metadata.1 → 8.3.1-custom-metadata.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 +18 -18
- package/dist/dbml-parse.mjs +7517 -7708
- package/dist/src/compiler/index.d.ts +2 -2
- package/dist/src/compiler/queries/container/element.d.ts +2 -2
- package/dist/src/core/global_modules/metadata/attach.d.ts +6 -0
- package/dist/src/core/global_modules/metadata/bind.d.ts +2 -2
- package/dist/src/core/global_modules/metadata/fieldRegistry.d.ts +4 -0
- package/dist/src/core/global_modules/metadata/interpret.d.ts +3 -12
- package/dist/src/core/global_modules/metadata/metadataField.d.ts +17 -0
- package/dist/src/core/global_modules/metadata/resolve.d.ts +10 -3
- package/dist/src/core/global_modules/note/interpret.d.ts +3 -1
- package/dist/src/core/global_modules/program/interpret.d.ts +0 -4
- package/dist/src/core/global_modules/records/utils/constraints/helper.d.ts +4 -17
- package/dist/src/core/global_modules/table/interpret.d.ts +7 -1
- package/dist/src/core/global_modules/tableGroup/interpret.d.ts +3 -1
- package/dist/src/core/global_modules/utils.d.ts +2 -2
- package/dist/src/core/local_modules/metadata/utils.d.ts +7 -0
- package/dist/src/core/local_modules/metadata/validate.d.ts +2 -2
- package/dist/src/core/parser/parser.d.ts +0 -1
- package/dist/src/core/types/errors.d.ts +3 -5
- package/dist/src/core/types/nodes.d.ts +7 -24
- package/dist/src/core/types/schemaJson.d.ts +5 -10
- package/dist/src/core/types/symbol/metadata.d.ts +9 -5
- package/dist/src/core/types/symbol/symbols.d.ts +6 -7
- package/dist/src/core/utils/interpret.d.ts +11 -1
- package/dist/src/core/utils/span.d.ts +2 -2
- package/dist/src/core/utils/validate.d.ts +0 -5
- package/dist/src/index.d.ts +1 -1
- package/package.json +2 -2
- package/dist/src/core/global_modules/metadata/overlap.d.ts +0 -14
|
@@ -30,7 +30,7 @@ export default class Compiler {
|
|
|
30
30
|
validateFile: (filepath: Filepath) => import('../core/types/report').default<void>;
|
|
31
31
|
nodeFullname: (node: SyntaxNode) => import('../core/types/report').default<string[] | undefined> | import('../core/types/report').default<typeof import('..').UNHANDLED>;
|
|
32
32
|
nodeAlias: (node: SyntaxNode) => import('../core/types/report').default<typeof import('..').UNHANDLED> | import('../core/types/report').default<string | undefined>;
|
|
33
|
-
nodeSettings: (node: SyntaxNode) => import('../core/types/report').default<
|
|
33
|
+
nodeSettings: (node: SyntaxNode) => import('../core/types/report').default<import('../core/utils/validate').Settings> | import('../core/types/report').default<typeof import('..').UNHANDLED>;
|
|
34
34
|
canonicalName: (filepath: Filepath, symbol: import('../core/types/symbol').NodeSymbol) => import('../core/types/report').default<import('./queries/canonicalName').CanonicalName | undefined>;
|
|
35
35
|
bindNode: (node: SyntaxNode) => import('../core/types/report').default<typeof import('..').UNHANDLED> | import('../core/types/report').default<void>;
|
|
36
36
|
bindFile: (filepath: Filepath) => import('../core/types/report').default<void>;
|
|
@@ -100,7 +100,7 @@ export default class Compiler {
|
|
|
100
100
|
token: undefined;
|
|
101
101
|
index: undefined;
|
|
102
102
|
};
|
|
103
|
-
element: (filepath: Filepath, offset: number) => Readonly<import('../core/types/nodes').ElementDeclarationNode | import('../core/types/nodes').ProgramNode
|
|
103
|
+
element: (filepath: Filepath, offset: number) => Readonly<import('../core/types/nodes').ElementDeclarationNode | import('../core/types/nodes').ProgramNode>;
|
|
104
104
|
scope: (filepath: Filepath, offset: number) => import('../core/types/symbol').NodeSymbol[] | undefined;
|
|
105
105
|
scopeKind: (filepath: Filepath, offset: number) => import('./types').ScopeKind;
|
|
106
106
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Filepath } from '../../../core/types/filepath';
|
|
2
|
-
import { ElementDeclarationNode,
|
|
2
|
+
import { ElementDeclarationNode, ProgramNode } from '../../../core/types/nodes';
|
|
3
3
|
import { default as Compiler } from '../../index';
|
|
4
|
-
export declare function containerElement(this: Compiler, filepath: Filepath, offset: number): Readonly<ElementDeclarationNode |
|
|
4
|
+
export declare function containerElement(this: Compiler, filepath: Filepath, offset: number): Readonly<ElementDeclarationNode | ProgramNode>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { default as Compiler } from '../../../compiler/index';
|
|
2
|
+
import { Filepath } from '../../types/filepath';
|
|
3
|
+
import { NodeSymbol } from '../../types/symbol';
|
|
4
|
+
import { MetadataFieldRegistry, MetadataTarget } from './metadataField';
|
|
5
|
+
/** Merge every custom-metadata block, reachable from the current program, targeting element to it's `metadata` and other builtin (note/headercolor/...) fields */
|
|
6
|
+
export declare function attachCustomMetadata<T extends MetadataTarget>(compiler: Compiler, targetElement: Partial<T>, targetSymbol: NodeSymbol, fieldsRegistry: MetadataFieldRegistry<T, any>, filepath: Filepath): void;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { default as Compiler } from '../../../compiler';
|
|
2
2
|
import { CompileError } from '../../types';
|
|
3
|
-
import {
|
|
3
|
+
import { ElementDeclarationNode } from '../../types/nodes';
|
|
4
4
|
export default class MetadataBinder {
|
|
5
5
|
private compiler;
|
|
6
6
|
private declarationNode;
|
|
7
|
-
constructor(compiler: Compiler, declarationNode:
|
|
7
|
+
constructor(compiler: Compiler, declarationNode: ElementDeclarationNode);
|
|
8
8
|
bind(): CompileError[];
|
|
9
9
|
private bindTargetElement;
|
|
10
10
|
private bindBody;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { MetadataTargetKind } from '../../types/symbol';
|
|
2
|
+
import { MetadataFieldRegistry, MetadataTarget } from './metadataField';
|
|
3
|
+
export declare const METADATA_FIELDS_BY_KIND: Record<MetadataTargetKind, MetadataFieldRegistry<any, any>>;
|
|
4
|
+
export type { MetadataFieldRegistry, MetadataTarget };
|
|
@@ -1,23 +1,14 @@
|
|
|
1
1
|
import { default as Compiler } from '../../../compiler';
|
|
2
2
|
import { Filepath } from '../../types';
|
|
3
3
|
import { MetadataElementMetadata } from '../../types/symbol/metadata';
|
|
4
|
-
import { SyntaxNode } from '../../types/nodes';
|
|
5
4
|
import { default as Report } from '../../types/report';
|
|
6
|
-
import {
|
|
7
|
-
import { Settings } from '../../utils/validate';
|
|
8
|
-
export declare function extractValue(node?: SyntaxNode): string | number | boolean | Color | undefined;
|
|
9
|
-
export declare const TABLE_BUILTIN_SETTINGS: readonly ["headercolor", "note"];
|
|
10
|
-
export declare const TABLEGROUP_BUILTIN_SETTINGS: readonly ["color", "note"];
|
|
11
|
-
export declare const NOTE_BUILTIN_SETTINGS: readonly ["color"];
|
|
12
|
-
export declare const COLUMN_BUILTIN_SETTINGS: readonly ["pk", "primary key", "unique", "note", "ref", "default", "check", "increment", "not null", "null"];
|
|
13
|
-
export declare function extractInlineMetadata(settingMap: Settings, builtinSettingNames: readonly string[]): CustomMetadata;
|
|
5
|
+
import { MetadataValues } from '../../types/schemaJson';
|
|
14
6
|
export default class MetadataInterpreter {
|
|
15
7
|
private declarationNode;
|
|
16
8
|
private compiler;
|
|
17
9
|
private filepath;
|
|
18
|
-
private
|
|
10
|
+
private values;
|
|
19
11
|
constructor(compiler: Compiler, metadata: MetadataElementMetadata, filepath: Filepath);
|
|
20
|
-
interpret(): Report<
|
|
21
|
-
private interpretTarget;
|
|
12
|
+
interpret(): Report<MetadataValues>;
|
|
22
13
|
private interpretValues;
|
|
23
14
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SyntaxNode } from '../../types/nodes';
|
|
2
|
+
import { Column, Note, Table, TableGroup, TokenPosition } from '../../types/schemaJson';
|
|
3
|
+
import { SettingName } from '../../types';
|
|
4
|
+
export type MetadataTarget = Table | TableGroup | Note | Column;
|
|
5
|
+
/**
|
|
6
|
+
* Specs for builtin metadata (table's note, tablegroup's color, .etc) for different element types. Does 2 things:
|
|
7
|
+
* - `validate`: Validating if the metadata value is syntactically correct
|
|
8
|
+
* - `assign`: Write the metadata value to the element builtin props (e.g. write `table.note` instead of `table.metadata`)
|
|
9
|
+
*/
|
|
10
|
+
export interface MetadataField<T extends MetadataTarget> {
|
|
11
|
+
/** Check if the metadata value is syntactically correct */
|
|
12
|
+
isValidBuiltinFieldValue(node?: SyntaxNode): boolean;
|
|
13
|
+
message: string;
|
|
14
|
+
/** Write the metadata value to the element builtin props (e.g. write to `table.note`) */
|
|
15
|
+
assignBuiltinField(element: Partial<T>, value: string, token: TokenPosition): void;
|
|
16
|
+
}
|
|
17
|
+
export type MetadataFieldRegistry<T extends MetadataTarget, K extends SettingName = SettingName> = Record<K, MetadataField<T>>;
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { default as Compiler } from '../../../compiler/index';
|
|
2
|
-
import {
|
|
3
|
-
import { NodeSymbol } from '../../types/symbol';
|
|
4
|
-
|
|
2
|
+
import { ElementDeclarationNode } from '../../types/nodes';
|
|
3
|
+
import { NodeSymbol, SymbolKind, MetadataTargetKind } from '../../types/symbol';
|
|
4
|
+
type NameWithSymbolKind = {
|
|
5
|
+
name: string;
|
|
6
|
+
symbolKind: SymbolKind;
|
|
7
|
+
};
|
|
8
|
+
/** @internal Exported for testing only. */
|
|
9
|
+
export declare function mapNamePartToSymbolKind(nameParts: string[], targetKind: MetadataTargetKind): NameWithSymbolKind[];
|
|
10
|
+
export declare function resolveMetadataTarget(compiler: Compiler, metadataNode: ElementDeclarationNode): NodeSymbol | undefined;
|
|
11
|
+
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
|
+
import { MetadataFieldRegistry } from '../metadata/metadataField';
|
|
4
5
|
import { default as Report } from '../../types/report';
|
|
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;
|
|
@@ -11,17 +11,13 @@ export default class ProgramInterpreter {
|
|
|
11
11
|
private errors;
|
|
12
12
|
private warnings;
|
|
13
13
|
private db;
|
|
14
|
-
private emittedBySymbol;
|
|
15
14
|
constructor(compiler: Compiler, symbol: ProgramSymbol, filepath: Filepath);
|
|
16
15
|
interpret(): Report<SchemaElement | SchemaElement[] | undefined>;
|
|
17
16
|
private interpretAllSymbols;
|
|
18
17
|
private interpretUseSymbol;
|
|
19
18
|
private interpretAllMetadata;
|
|
20
|
-
private promoteOverlapKeys;
|
|
21
|
-
private attachMetadata;
|
|
22
19
|
private interpretAllAliases;
|
|
23
20
|
private validateRecords;
|
|
24
21
|
private collectPartialRefs;
|
|
25
22
|
private pushElement;
|
|
26
|
-
private recordEmitted;
|
|
27
23
|
}
|
|
@@ -2,25 +2,12 @@ import { default as Compiler } from '../../../../../compiler/index';
|
|
|
2
2
|
import { CompileWarning } from '../../../../types/errors';
|
|
3
3
|
import { RecordValue, TableRecord } from '../../../../types/schemaJson';
|
|
4
4
|
import { ColumnSymbol } from '../../../../types/symbol';
|
|
5
|
-
export interface ColumnInfo {
|
|
6
|
-
name: string;
|
|
7
|
-
pk: boolean;
|
|
8
|
-
unique: boolean;
|
|
9
|
-
increment: boolean;
|
|
10
|
-
notNull: boolean;
|
|
11
|
-
dbdefault?: {
|
|
12
|
-
value: string | number;
|
|
13
|
-
type: string;
|
|
14
|
-
};
|
|
15
|
-
typeName: string;
|
|
16
|
-
}
|
|
17
|
-
export declare function columnInfoFromSymbol(col: ColumnSymbol, compiler: Compiler): ColumnInfo;
|
|
18
5
|
export declare function toKeyedRows(record: TableRecord): Record<string, RecordValue>[];
|
|
19
6
|
export declare function makeTableKey(schema: string | null, table: string): string;
|
|
20
|
-
export declare function extractKeyValueWithDefault(row: Record<string, RecordValue>,
|
|
21
|
-
export declare function hasNullWithoutDefaultInKey(row: Record<string, RecordValue>,
|
|
22
|
-
export declare function isAutoIncrementColumn(column: ColumnInfo): boolean;
|
|
7
|
+
export declare function extractKeyValueWithDefault(compiler: Compiler, row: Record<string, RecordValue>, columns: ColumnSymbol[]): string;
|
|
8
|
+
export declare function hasNullWithoutDefaultInKey(compiler: Compiler, row: Record<string, RecordValue>, columns: ColumnSymbol[]): boolean;
|
|
23
9
|
export declare function formatFullColumnName(schemaName: string | null, tableName: string, columnName: string): string;
|
|
24
10
|
export declare function formatFullColumnNames(schemaName: string | null, tableName: string, columnNames: string[]): string;
|
|
25
|
-
export declare function formatValues(row: Record<string, RecordValue>,
|
|
11
|
+
export declare function formatValues(compiler: Compiler, row: Record<string, RecordValue>, columns: ColumnSymbol[]): string;
|
|
12
|
+
export declare function getDiagnosticAnchorValues(row: Record<string, RecordValue>, columnNames: string[]): RecordValue[];
|
|
26
13
|
export declare function createConstraintWarning(compiler: Compiler, recordValue: RecordValue, message: string): CompileWarning;
|
|
@@ -1,7 +1,9 @@
|
|
|
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';
|
|
6
|
+
import { MetadataFieldRegistry } from '../metadata/metadataField';
|
|
5
7
|
import { Filepath } from '../../types/filepath';
|
|
6
8
|
import { TableSymbol } from '../../types/symbol/symbols';
|
|
7
9
|
export declare class TableInterpreter {
|
|
@@ -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,6 @@ export declare class TableInterpreter {
|
|
|
24
27
|
private interpretIndexes;
|
|
25
28
|
private interpretChecks;
|
|
26
29
|
}
|
|
30
|
+
export declare const RECOGNIZED_COLUMN_SETTINGS: readonly SettingName[];
|
|
31
|
+
export declare const TABLE_METADATA_FIELDS: MetadataFieldRegistry<Table, SettingName.Note | SettingName.HeaderColor>;
|
|
32
|
+
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
|
+
import { MetadataFieldRegistry } from '../metadata/metadataField';
|
|
4
5
|
import { default as Report } from '../../types/report';
|
|
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 { Filepath, 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';
|
|
@@ -16,4 +16,4 @@ export declare function scanNonListNodeForBinding(node?: SyntaxNode): {
|
|
|
16
16
|
export declare function nodeRefereeOfLeftExpression(compiler: Compiler, node: SyntaxNode): NodeSymbol | undefined;
|
|
17
17
|
export declare function getMultiplicities(op: string): [RelationCardinality, RelationCardinality] | undefined;
|
|
18
18
|
export declare function getDefaultSchemaSymbol(compiler: Compiler, globalSymbol: NodeSymbol): NodeSymbol | undefined;
|
|
19
|
-
export declare function
|
|
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[];
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { default as Compiler } from '../../../compiler';
|
|
2
2
|
import { CompileError } from '../../types/errors';
|
|
3
|
-
import {
|
|
3
|
+
import { ElementDeclarationNode } from '../../types/nodes';
|
|
4
4
|
export default class MetadataValidator {
|
|
5
5
|
private compiler;
|
|
6
6
|
private declarationNode;
|
|
7
|
-
constructor(compiler: Compiler, declarationNode:
|
|
7
|
+
constructor(compiler: Compiler, declarationNode: ElementDeclarationNode);
|
|
8
8
|
validate(): CompileError[];
|
|
9
9
|
private validateTargetKind;
|
|
10
10
|
private validateTargetName;
|
|
@@ -32,7 +32,6 @@ export default class Parser {
|
|
|
32
32
|
private synchronizeUseSpecifierList;
|
|
33
33
|
private useSpecifier;
|
|
34
34
|
private synchronizeProgram;
|
|
35
|
-
private metadataDeclaration;
|
|
36
35
|
private elementDeclaration;
|
|
37
36
|
private synchronizeElementDeclarationName;
|
|
38
37
|
private synchronizeElementDeclarationAlias;
|
|
@@ -114,11 +114,9 @@ export declare enum CompileErrorCode {
|
|
|
114
114
|
UNEQUAL_FIELDS_BINARY_REF = 5003,
|
|
115
115
|
CONFLICTING_SETTING = 5004,
|
|
116
116
|
TABLE_REAPPEAR_IN_TABLEGROUP = 5005,
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
DUPLICATE_METADATA_FIELD = 5009,
|
|
121
|
-
METADATA_TARGET_NOT_FOUND = 5010
|
|
117
|
+
INVALID_METADATA_TARGET_KIND = 5006,
|
|
118
|
+
INVALID_METADATA_FIELD = 5007,
|
|
119
|
+
DUPLICATE_METADATA_FIELD = 5008
|
|
122
120
|
}
|
|
123
121
|
export declare class CompileError extends Error {
|
|
124
122
|
code: Readonly<CompileErrorCode>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Filepath } from './filepath';
|
|
2
2
|
import { Internable } from './internable';
|
|
3
3
|
import { ElementKind } from './keywords';
|
|
4
|
-
import { ImportKind,
|
|
4
|
+
import { ImportKind, SymbolKind } from './symbol';
|
|
5
5
|
import { Position } from './position';
|
|
6
6
|
import { SyntaxToken } from './tokens';
|
|
7
7
|
export type SyntaxNodeId = number;
|
|
@@ -36,7 +36,6 @@ export declare class SyntaxNode implements Internable<InternedSyntaxNode> {
|
|
|
36
36
|
export declare enum SyntaxNodeKind {
|
|
37
37
|
PROGRAM = "<program>",
|
|
38
38
|
ELEMENT_DECLARATION = "<element-declaration>",
|
|
39
|
-
METADATA_DECLARATION = "<metadata-declaration>",
|
|
40
39
|
USE_DECLARATION = "<use-declaration>",
|
|
41
40
|
USE_SPECIFIER = "<use-specifier>",
|
|
42
41
|
USE_SPECIFIER_LIST = "<use-specifier-list>",
|
|
@@ -61,17 +60,16 @@ export declare enum SyntaxNodeKind {
|
|
|
61
60
|
WILDCARD = "<wildcard>"
|
|
62
61
|
}
|
|
63
62
|
export declare class ProgramNode extends SyntaxNode {
|
|
64
|
-
body: (UseDeclarationNode | ElementDeclarationNode
|
|
63
|
+
body: (UseDeclarationNode | ElementDeclarationNode)[];
|
|
65
64
|
eof?: SyntaxToken;
|
|
66
65
|
source: string;
|
|
67
66
|
constructor({ body, eof, source, }: {
|
|
68
|
-
body?: (UseDeclarationNode | ElementDeclarationNode
|
|
67
|
+
body?: (UseDeclarationNode | ElementDeclarationNode)[];
|
|
69
68
|
eof?: SyntaxToken;
|
|
70
69
|
source: string;
|
|
71
70
|
}, id: SyntaxNodeId, filepath: Filepath);
|
|
72
71
|
get declarations(): ElementDeclarationNode[];
|
|
73
72
|
get uses(): UseDeclarationNode[];
|
|
74
|
-
get metadata(): MetadataDeclarationNode[];
|
|
75
73
|
}
|
|
76
74
|
export declare class UseDeclarationNode extends SyntaxNode {
|
|
77
75
|
useKeyword?: SyntaxToken;
|
|
@@ -88,13 +86,11 @@ export declare class UseDeclarationNode extends SyntaxNode {
|
|
|
88
86
|
}
|
|
89
87
|
export declare class UseSpecifierNode extends SyntaxNode {
|
|
90
88
|
importKind?: SyntaxToken;
|
|
91
|
-
subKind?: SyntaxToken;
|
|
92
89
|
name?: NormalExpressionNode;
|
|
93
90
|
asKeyword?: SyntaxToken;
|
|
94
91
|
alias?: NormalExpressionNode;
|
|
95
|
-
constructor({ importKind,
|
|
92
|
+
constructor({ importKind, name, asKeyword, alias, }: {
|
|
96
93
|
importKind?: SyntaxToken;
|
|
97
|
-
subKind?: SyntaxToken;
|
|
98
94
|
name?: NormalExpressionNode;
|
|
99
95
|
asKeyword?: SyntaxToken;
|
|
100
96
|
alias?: NormalExpressionNode;
|
|
@@ -112,31 +108,18 @@ export declare class UseSpecifierListNode extends SyntaxNode {
|
|
|
112
108
|
closeBrace?: SyntaxToken;
|
|
113
109
|
}, id: SyntaxNodeId, filepath: Filepath);
|
|
114
110
|
}
|
|
115
|
-
export declare class MetadataDeclarationNode extends SyntaxNode {
|
|
116
|
-
metadataKeyword?: SyntaxToken;
|
|
117
|
-
targetKind?: SyntaxToken;
|
|
118
|
-
targetName?: NormalExpressionNode;
|
|
119
|
-
bodyColon?: SyntaxToken;
|
|
120
|
-
body?: FunctionApplicationNode | BlockExpressionNode;
|
|
121
|
-
constructor({ metadataKeyword, targetKind, targetName, bodyColon, body, }: {
|
|
122
|
-
metadataKeyword?: SyntaxToken;
|
|
123
|
-
targetKind?: SyntaxToken;
|
|
124
|
-
targetName?: NormalExpressionNode;
|
|
125
|
-
bodyColon?: SyntaxToken;
|
|
126
|
-
body?: BlockExpressionNode | FunctionApplicationNode;
|
|
127
|
-
}, id: SyntaxNodeId, filepath: Filepath);
|
|
128
|
-
getTargetKind(): MetadataTargetKind | undefined;
|
|
129
|
-
}
|
|
130
111
|
export declare class ElementDeclarationNode extends SyntaxNode {
|
|
131
112
|
type?: SyntaxToken;
|
|
113
|
+
targetKind?: SyntaxToken;
|
|
132
114
|
name?: NormalExpressionNode;
|
|
133
115
|
as?: SyntaxToken;
|
|
134
116
|
alias?: NormalExpressionNode;
|
|
135
117
|
attributeList?: ListExpressionNode;
|
|
136
118
|
bodyColon?: SyntaxToken;
|
|
137
119
|
body?: FunctionApplicationNode | BlockExpressionNode;
|
|
138
|
-
constructor({ type, name, as, alias, attributeList, bodyColon, body, }: {
|
|
120
|
+
constructor({ type, targetKind, name, as, alias, attributeList, bodyColon, body, }: {
|
|
139
121
|
type?: SyntaxToken;
|
|
122
|
+
targetKind?: SyntaxToken;
|
|
140
123
|
name?: NormalExpressionNode;
|
|
141
124
|
as?: SyntaxToken;
|
|
142
125
|
alias?: NormalExpressionNode;
|
|
@@ -1,7 +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,
|
|
4
|
+
export type CustomMetadata = Record<string, string>;
|
|
5
5
|
export type Color = `#${string}` | typeof NONE_COLOR;
|
|
6
6
|
export declare enum AliasKind {
|
|
7
7
|
Table = "table"
|
|
@@ -243,15 +243,10 @@ export interface TableRecord {
|
|
|
243
243
|
values: RecordValue[][];
|
|
244
244
|
token: TokenPosition;
|
|
245
245
|
}
|
|
246
|
-
export
|
|
247
|
-
|
|
248
|
-
kind: string;
|
|
249
|
-
name: string[];
|
|
250
|
-
};
|
|
251
|
-
values: CustomMetadata;
|
|
252
|
-
valueTokens: Record<string, TokenPosition>;
|
|
246
|
+
export type MetadataValues = Record<string, {
|
|
247
|
+
value: string;
|
|
253
248
|
token: TokenPosition;
|
|
254
|
-
}
|
|
249
|
+
}>;
|
|
255
250
|
export type Project = Record<string, never> | {
|
|
256
251
|
name: string | null;
|
|
257
252
|
tables: Table[];
|
|
@@ -266,4 +261,4 @@ export type Project = Record<string, never> | {
|
|
|
266
261
|
token: TokenPosition;
|
|
267
262
|
[index: string & Omit<any, 'name' | 'tables' | 'refs' | 'enums' | 'tableGroups' | 'note' | 'tablePartials' | 'records'>]: string;
|
|
268
263
|
};
|
|
269
|
-
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
|
-
import { AttributeNode, ElementDeclarationNode,
|
|
3
|
-
import { ColumnSymbol, NodeSymbol, TablePartialSymbol, TableSymbol } from '../symbol';
|
|
2
|
+
import { AttributeNode, ElementDeclarationNode, SyntaxNode } from '../nodes';
|
|
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",
|
|
@@ -27,7 +27,11 @@ export declare abstract class NodeMetadata implements Internable<InternedNodeMet
|
|
|
27
27
|
constructor(declaration: SyntaxNode);
|
|
28
28
|
intern(): InternedNodeMetadata;
|
|
29
29
|
abstract owners(compiler: Compiler): NodeSymbol[];
|
|
30
|
-
|
|
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[];
|
|
31
35
|
}
|
|
32
36
|
export declare class RefMetadata extends NodeMetadata {
|
|
33
37
|
declaration: ElementDeclarationNode | AttributeNode;
|
|
@@ -76,9 +80,9 @@ export declare class RecordsMetadata extends NodeMetadata {
|
|
|
76
80
|
owners(compiler: Compiler): NodeSymbol[];
|
|
77
81
|
}
|
|
78
82
|
export declare class MetadataElementMetadata extends NodeMetadata {
|
|
79
|
-
declaration:
|
|
83
|
+
declaration: ElementDeclarationNode;
|
|
80
84
|
readonly kind = MetadataKind.MetadataElement;
|
|
81
|
-
constructor(declaration:
|
|
85
|
+
constructor(declaration: ElementDeclarationNode);
|
|
82
86
|
target(compiler: Compiler): NodeSymbol | undefined;
|
|
83
87
|
owners(compiler: Compiler): NodeSymbol[];
|
|
84
88
|
}
|
|
@@ -34,17 +34,15 @@ export declare const ImportKind: {
|
|
|
34
34
|
TablePartial: SymbolKind;
|
|
35
35
|
Note: SymbolKind;
|
|
36
36
|
Schema: SymbolKind;
|
|
37
|
-
Metadata: SymbolKind;
|
|
38
37
|
};
|
|
39
38
|
export type ImportKind = (typeof ImportKind)[keyof typeof ImportKind];
|
|
39
|
+
/** Allowed target element types for a Metadata element header */
|
|
40
40
|
export declare enum MetadataTargetKind {
|
|
41
|
-
Table = "
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
Note = "note"
|
|
41
|
+
Table = "Table",
|
|
42
|
+
Column = "Column",
|
|
43
|
+
TableGroup = "TableGroup",
|
|
44
|
+
Note = "Note"
|
|
46
45
|
}
|
|
47
|
-
export declare const ALLOWED_METADATA_TARGET_KINDS: readonly MetadataTargetKind[];
|
|
48
46
|
declare const __nodeSymbolBrand: unique symbol;
|
|
49
47
|
export type NodeSymbolId = number & {
|
|
50
48
|
readonly [__nodeSymbolBrand]: true;
|
|
@@ -160,6 +158,7 @@ export declare class ColumnSymbol extends NodeSymbol {
|
|
|
160
158
|
pk(compiler: Compiler): boolean;
|
|
161
159
|
unique(compiler: Compiler): boolean;
|
|
162
160
|
nullable(compiler: Compiler): boolean | undefined;
|
|
161
|
+
isIncrementSet(compiler: Compiler): boolean;
|
|
163
162
|
increment(compiler: Compiler): boolean;
|
|
164
163
|
default(compiler: Compiler): {
|
|
165
164
|
type: 'number' | 'string' | 'boolean' | 'expression';
|
|
@@ -1,7 +1,9 @@
|
|
|
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): {
|
|
@@ -14,3 +16,11 @@ export declare function processDefaultValue(valueNode?: SyntaxNode): {
|
|
|
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;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ElementDeclarationNode,
|
|
1
|
+
import { ElementDeclarationNode, SyntaxNode } from '../types/nodes';
|
|
2
2
|
import { SyntaxToken } from '../types/tokens';
|
|
3
3
|
export declare function isOffsetWithinSpan(offset: number, nodeOrToken: SyntaxNode | SyntaxToken): boolean;
|
|
4
|
-
export declare function isOffsetWithinElementHeader(offset: number, element: ElementDeclarationNode
|
|
4
|
+
export declare function isOffsetWithinElementHeader(offset: number, element: ElementDeclarationNode): boolean;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { CompileError, CompileErrorCode } from '../types/errors';
|
|
2
1
|
import { AttributeNode, BlockExpressionNode, ElementDeclarationNode, FunctionApplicationNode, FunctionExpressionNode, InfixExpressionNode, ListExpressionNode, LiteralNode, PrefixExpressionNode, PrimaryExpressionNode, ProgramNode, SyntaxNode, TupleExpressionNode, UseDeclarationNode, UseSpecifierNode, VariableNode, WildcardNode } from '../types/nodes';
|
|
3
2
|
import { default as Report } from '../types/report';
|
|
4
3
|
import { SyntaxToken, SyntaxTokenKind } from '../types/tokens';
|
|
@@ -54,10 +53,6 @@ export declare function isTupleOfVariables(value?: SyntaxNode): value is TupleEx
|
|
|
54
53
|
export declare function isValidColumnType(type: SyntaxNode): boolean;
|
|
55
54
|
export type Settings = Record<SettingName | string, AttributeNode[]>;
|
|
56
55
|
export declare function isValidMetadataValue(value?: SyntaxNode): boolean;
|
|
57
|
-
export declare function validateInlineMetadataSetting(name: string, attrs: AttributeNode[], codes: {
|
|
58
|
-
duplicate: CompileErrorCode;
|
|
59
|
-
invalidValue: CompileErrorCode;
|
|
60
|
-
}): CompileError[];
|
|
61
56
|
export declare function aggregateSettingList(settingList?: ListExpressionNode): Report<Settings>;
|
|
62
57
|
export declare function isExpressionAQuotedString(value?: unknown): value is PrimaryExpressionNode & ({
|
|
63
58
|
expression: VariableNode & {
|
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';
|
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.3.1-custom-metadata.
|
|
4
|
+
"version": "8.3.1-custom-metadata.3",
|
|
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": "be8c21d3525b0001b295695af7057e0e9cfae5d1"
|
|
54
54
|
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { MetadataTargetKind } from '../../types/symbol';
|
|
2
|
-
export declare enum OverlapValueKind {
|
|
3
|
-
Note = "note",
|
|
4
|
-
Color = "color",
|
|
5
|
-
HeaderColor = "headercolor"
|
|
6
|
-
}
|
|
7
|
-
export type OverlapInlineField = 'note' | 'color' | 'headerColor';
|
|
8
|
-
export interface OverlapKey {
|
|
9
|
-
metaKey: string;
|
|
10
|
-
field: OverlapInlineField;
|
|
11
|
-
reshape: OverlapValueKind;
|
|
12
|
-
}
|
|
13
|
-
export declare const OVERLAP_KEYS: Partial<Record<MetadataTargetKind, OverlapKey[]>>;
|
|
14
|
-
export declare function findOverlapKey(kind: MetadataTargetKind | undefined, key: string): OverlapKey | undefined;
|