@dbml/parse 8.3.1-custom-metadata.2 → 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.
Files changed (32) hide show
  1. package/dist/dbml-parse.js +18 -18
  2. package/dist/dbml-parse.mjs +7937 -8056
  3. package/dist/src/compiler/index.d.ts +2 -2
  4. package/dist/src/compiler/queries/container/element.d.ts +2 -2
  5. package/dist/src/core/global_modules/metadata/attach.d.ts +6 -0
  6. package/dist/src/core/global_modules/metadata/bind.d.ts +2 -2
  7. package/dist/src/core/global_modules/metadata/fieldRegistry.d.ts +4 -0
  8. package/dist/src/core/global_modules/metadata/interpret.d.ts +4 -9
  9. package/dist/src/core/global_modules/metadata/metadataField.d.ts +17 -0
  10. package/dist/src/core/global_modules/metadata/resolve.d.ts +10 -3
  11. package/dist/src/core/global_modules/note/interpret.d.ts +2 -2
  12. package/dist/src/core/global_modules/program/interpret.d.ts +0 -3
  13. package/dist/src/core/global_modules/records/utils/constraints/helper.d.ts +4 -17
  14. package/dist/src/core/global_modules/table/interpret.d.ts +5 -3
  15. package/dist/src/core/global_modules/tableGroup/interpret.d.ts +2 -2
  16. package/dist/src/core/global_modules/utils.d.ts +2 -2
  17. package/dist/src/core/local_modules/metadata/utils.d.ts +7 -0
  18. package/dist/src/core/local_modules/metadata/validate.d.ts +2 -2
  19. package/dist/src/core/local_modules/note/validate.d.ts +0 -3
  20. package/dist/src/core/local_modules/table/validate.d.ts +0 -4
  21. package/dist/src/core/local_modules/tableGroup/validate.d.ts +0 -3
  22. package/dist/src/core/parser/parser.d.ts +0 -1
  23. package/dist/src/core/types/keywords.d.ts +2 -1
  24. package/dist/src/core/types/nodes.d.ts +6 -21
  25. package/dist/src/core/types/schemaJson.d.ts +4 -10
  26. package/dist/src/core/types/symbol/metadata.d.ts +9 -5
  27. package/dist/src/core/types/symbol/symbols.d.ts +6 -6
  28. package/dist/src/core/utils/span.d.ts +2 -2
  29. package/dist/src/core/utils/validate.d.ts +0 -5
  30. package/dist/src/index.d.ts +1 -1
  31. package/package.json +2 -2
  32. package/dist/src/core/global_modules/metadata/fieldSpec.d.ts +0 -11
@@ -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<typeof import('..').UNHANDLED> | import('../core/types/report').default<import('../core/utils/validate').Settings>;
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 | import('../core/types/nodes').MetadataDeclarationNode>;
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, MetadataDeclarationNode, ProgramNode } from '../../../core/types/nodes';
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 | MetadataDeclarationNode | ProgramNode>;
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 { MetadataDeclarationNode } from '../../types/nodes';
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: MetadataDeclarationNode);
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,19 +1,14 @@
1
1
  import { default as Compiler } from '../../../compiler';
2
- import { SettingName, Filepath } from '../../types';
2
+ import { Filepath } from '../../types';
3
3
  import { MetadataElementMetadata } from '../../types/symbol/metadata';
4
4
  import { default as Report } from '../../types/report';
5
- import { MetadataElement } from '../../types/schemaJson';
6
- export declare const TABLE_BUILTIN_SETTINGS: readonly SettingName[];
7
- export declare const TABLEGROUP_BUILTIN_SETTINGS: readonly SettingName[];
8
- export declare const NOTE_BUILTIN_SETTINGS: readonly SettingName[];
9
- export declare const COLUMN_BUILTIN_SETTINGS: readonly SettingName[];
5
+ import { MetadataValues } from '../../types/schemaJson';
10
6
  export default class MetadataInterpreter {
11
7
  private declarationNode;
12
8
  private compiler;
13
9
  private filepath;
14
- private metadata;
10
+ private values;
15
11
  constructor(compiler: Compiler, metadata: MetadataElementMetadata, filepath: Filepath);
16
- interpret(): Report<MetadataElement>;
17
- private interpretTarget;
12
+ interpret(): Report<MetadataValues>;
18
13
  private interpretValues;
19
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 { MetadataDeclarationNode } from '../../types/nodes';
3
- import { NodeSymbol } from '../../types/symbol';
4
- export declare function resolveMetadataTarget(compiler: Compiler, metadataNode: MetadataDeclarationNode): NodeSymbol | undefined;
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,8 +1,9 @@
1
1
  import { Note } from '../../types/schemaJson';
2
2
  import { default as Compiler } from '../../../compiler';
3
3
  import { SettingName, Filepath, NoteSymbol } from '../../types';
4
- import { FieldAssignMap } from '../metadata/fieldSpec';
4
+ import { MetadataFieldRegistry } from '../metadata/metadataField';
5
5
  import { default as Report } from '../../types/report';
6
+ export declare const NOTE_METADATA_FIELDS: MetadataFieldRegistry<Note, SettingName.Color>;
6
7
  export declare class StickyNoteInterpreter {
7
8
  private declarationNode;
8
9
  private symbol;
@@ -16,4 +17,3 @@ export declare class StickyNoteInterpreter {
16
17
  private interpretBody;
17
18
  private interpretNote;
18
19
  }
19
- export declare const NOTE_FIELD_ASSIGNS: FieldAssignMap<Note, SettingName.Color>;
@@ -11,14 +11,11 @@ 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 writeBuiltinFields;
21
- private attachMetadata;
22
19
  private interpretAllAliases;
23
20
  private validateRecords;
24
21
  private collectPartialRefs;
@@ -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>, columnNames: string[], columns?: (ColumnInfo | undefined)[]): string;
21
- export declare function hasNullWithoutDefaultInKey(row: Record<string, RecordValue>, columnNames: string[], columns?: (ColumnInfo | undefined)[]): boolean;
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>, columnNames: string[]): string;
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;
@@ -3,7 +3,7 @@ import { SettingName } from '../../types/keywords';
3
3
  import { ElementDeclarationNode } from '../../types/nodes';
4
4
  import { default as Report } from '../../types/report';
5
5
  import { Column, Table } from '../../types/schemaJson';
6
- import { FieldAssignMap } from '../metadata/fieldSpec';
6
+ import { MetadataFieldRegistry } from '../metadata/metadataField';
7
7
  import { Filepath } from '../../types/filepath';
8
8
  import { TableSymbol } from '../../types/symbol/symbols';
9
9
  export declare class TableInterpreter {
@@ -15,6 +15,7 @@ export declare class TableInterpreter {
15
15
  private pkColumns;
16
16
  constructor(compiler: Compiler, declarationNode: ElementDeclarationNode, symbol: TableSymbol, filepath: Filepath);
17
17
  interpret(): Report<Table>;
18
+ private attachTableAndColumnMetadata;
18
19
  private interpretName;
19
20
  private interpretAlias;
20
21
  private interpretSettingList;
@@ -26,5 +27,6 @@ export declare class TableInterpreter {
26
27
  private interpretIndexes;
27
28
  private interpretChecks;
28
29
  }
29
- export declare const TABLE_FIELD_ASSIGNS: FieldAssignMap<Table, SettingName.Note | SettingName.HeaderColor>;
30
- export declare const COLUMN_FIELD_ASSIGNS: FieldAssignMap<Column, SettingName.Note | SettingName.PK | SettingName.Unique | SettingName.Increment>;
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,8 +1,9 @@
1
1
  import { TableGroup } from '../../types/schemaJson';
2
2
  import { default as Compiler } from '../../../compiler';
3
3
  import { SettingName, Filepath, TableGroupSymbol } from '../../types';
4
- import { FieldAssignMap } from '../metadata/fieldSpec';
4
+ import { MetadataFieldRegistry } from '../metadata/metadataField';
5
5
  import { default as Report } from '../../types/report';
6
+ export declare const TABLEGROUP_METADATA_FIELDS: MetadataFieldRegistry<TableGroup, SettingName.Note | SettingName.Color>;
6
7
  export declare class TableGroupInterpreter {
7
8
  private compiler;
8
9
  private symbol;
@@ -17,4 +18,3 @@ export declare class TableGroupInterpreter {
17
18
  private interpretFields;
18
19
  private interpretSettingList;
19
20
  }
20
- export declare const TABLEGROUP_FIELD_ASSIGNS: FieldAssignMap<TableGroup, SettingName.Note | SettingName.Color>;
@@ -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 getGlobalSymbol(compiler: Compiler, filepath: Filepath): 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[];
@@ -1,10 +1,10 @@
1
1
  import { default as Compiler } from '../../../compiler';
2
2
  import { CompileError } from '../../types/errors';
3
- import { MetadataDeclarationNode } from '../../types/nodes';
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: MetadataDeclarationNode);
7
+ constructor(compiler: Compiler, declarationNode: ElementDeclarationNode);
8
8
  validate(): CompileError[];
9
9
  private validateTargetKind;
10
10
  private validateTargetName;
@@ -1,9 +1,6 @@
1
1
  import { default as Compiler } from '../../../compiler';
2
2
  import { CompileError } from '../../types/errors';
3
- import { SettingName } from '../../types/keywords';
4
3
  import { BlockExpressionNode, ElementDeclarationNode, FunctionApplicationNode } from '../../types/nodes';
5
- import { FieldValidateMap } from '../../global_modules/metadata/fieldSpec';
6
- export declare const NOTE_FIELD_SPECS: FieldValidateMap<SettingName.Color>;
7
4
  export default class NoteValidator {
8
5
  private compiler;
9
6
  private declarationNode;
@@ -1,12 +1,8 @@
1
1
  import { default as Compiler } from '../../../compiler';
2
2
  import { CompileError } from '../../types/errors';
3
- import { SettingName } from '../../types/keywords';
4
3
  import { ElementDeclarationNode, ExpressionNode, ListExpressionNode } from '../../types/nodes';
5
4
  import { default as Report } from '../../types/report';
6
5
  import { Settings } from '../../utils/validate';
7
- import { FieldValidateMap } from '../../global_modules/metadata/fieldSpec';
8
- export declare const TABLE_FIELD_SPECS: FieldValidateMap<SettingName.Note | SettingName.HeaderColor>;
9
- export declare const COLUMN_FIELD_SPECS: FieldValidateMap<SettingName.Note | SettingName.PK | SettingName.Unique | SettingName.Increment>;
10
6
  export default class TableValidator {
11
7
  private declarationNode;
12
8
  private compiler;
@@ -1,11 +1,8 @@
1
1
  import { default as Compiler } from '../../../compiler';
2
2
  import { CompileError } from '../../types/errors';
3
- import { SettingName } from '../../types/keywords';
4
3
  import { BlockExpressionNode, ElementDeclarationNode, FunctionApplicationNode, ListExpressionNode } from '../../types/nodes';
5
4
  import { default as Report } from '../../types/report';
6
5
  import { Settings } from '../../utils/validate';
7
- import { FieldValidateMap } from '../../global_modules/metadata/fieldSpec';
8
- export declare const TABLEGROUP_FIELD_SPECS: FieldValidateMap<SettingName.Note | SettingName.Color>;
9
6
  export default class TableGroupValidator {
10
7
  private declarationNode;
11
8
  private compiler;
@@ -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;
@@ -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",
@@ -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, MetadataTargetKind, SymbolKind } from './symbol';
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 | MetadataDeclarationNode)[];
63
+ body: (UseDeclarationNode | ElementDeclarationNode)[];
65
64
  eof?: SyntaxToken;
66
65
  source: string;
67
66
  constructor({ body, eof, source, }: {
68
- body?: (UseDeclarationNode | ElementDeclarationNode | MetadataDeclarationNode)[];
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;
@@ -110,31 +108,18 @@ export declare class UseSpecifierListNode extends SyntaxNode {
110
108
  closeBrace?: SyntaxToken;
111
109
  }, id: SyntaxNodeId, filepath: Filepath);
112
110
  }
113
- export declare class MetadataDeclarationNode extends SyntaxNode {
114
- metadataKeyword?: SyntaxToken;
115
- targetKind?: SyntaxToken;
116
- targetName?: NormalExpressionNode;
117
- bodyColon?: SyntaxToken;
118
- body?: FunctionApplicationNode | BlockExpressionNode;
119
- constructor({ metadataKeyword, targetKind, targetName, bodyColon, body, }: {
120
- metadataKeyword?: SyntaxToken;
121
- targetKind?: SyntaxToken;
122
- targetName?: NormalExpressionNode;
123
- bodyColon?: SyntaxToken;
124
- body?: BlockExpressionNode | FunctionApplicationNode;
125
- }, id: SyntaxNodeId, filepath: Filepath);
126
- getTargetKind(): MetadataTargetKind | undefined;
127
- }
128
111
  export declare class ElementDeclarationNode extends SyntaxNode {
129
112
  type?: SyntaxToken;
113
+ targetKind?: SyntaxToken;
130
114
  name?: NormalExpressionNode;
131
115
  as?: SyntaxToken;
132
116
  alias?: NormalExpressionNode;
133
117
  attributeList?: ListExpressionNode;
134
118
  bodyColon?: SyntaxToken;
135
119
  body?: FunctionApplicationNode | BlockExpressionNode;
136
- constructor({ type, name, as, alias, attributeList, bodyColon, body, }: {
120
+ constructor({ type, targetKind, name, as, alias, attributeList, bodyColon, body, }: {
137
121
  type?: SyntaxToken;
122
+ targetKind?: SyntaxToken;
138
123
  name?: NormalExpressionNode;
139
124
  as?: SyntaxToken;
140
125
  alias?: NormalExpressionNode;
@@ -1,7 +1,6 @@
1
1
  import { NONE_COLOR } from '../../constants';
2
2
  import { Filepath } from './filepath';
3
3
  import { Position } from './position';
4
- import { MetadataTargetKind } from './symbol';
5
4
  export type CustomMetadata = Record<string, string>;
6
5
  export type Color = `#${string}` | typeof NONE_COLOR;
7
6
  export declare enum AliasKind {
@@ -244,15 +243,10 @@ export interface TableRecord {
244
243
  values: RecordValue[][];
245
244
  token: TokenPosition;
246
245
  }
247
- export interface MetadataElement {
248
- target: {
249
- kind: MetadataTargetKind;
250
- name: string[];
251
- };
252
- values: CustomMetadata;
253
- valueTokens: Record<string, TokenPosition>;
246
+ export type MetadataValues = Record<string, {
247
+ value: string;
254
248
  token: TokenPosition;
255
- }
249
+ }>;
256
250
  export type Project = Record<string, never> | {
257
251
  name: string | null;
258
252
  tables: Table[];
@@ -267,4 +261,4 @@ export type Project = Record<string, never> | {
267
261
  token: TokenPosition;
268
262
  [index: string & Omit<any, 'name' | 'tables' | 'refs' | 'enums' | 'tableGroups' | 'note' | 'tablePartials' | 'records'>]: string;
269
263
  };
270
- export type SchemaElement = Database | Project | Table | Note | Column | ColumnType | Index | Check | InlineRef | Ref | RefEndpoint | Enum | EnumField | TableGroup | TableGroupField | Alias | TablePartial | TablePartialInjection | TableRecord | RecordValue | MetadataElement;
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, MetadataDeclarationNode, SyntaxNode } from '../nodes';
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
- reachableOwners(compiler: Compiler, targets: NodeSymbol[]): 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[];
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: MetadataDeclarationNode;
83
+ declaration: ElementDeclarationNode;
80
84
  readonly kind = MetadataKind.MetadataElement;
81
- constructor(declaration: MetadataDeclarationNode);
85
+ constructor(declaration: ElementDeclarationNode);
82
86
  target(compiler: Compiler): NodeSymbol | undefined;
83
87
  owners(compiler: Compiler): NodeSymbol[];
84
88
  }
@@ -36,14 +36,13 @@ export declare const ImportKind: {
36
36
  Schema: SymbolKind;
37
37
  };
38
38
  export type ImportKind = (typeof ImportKind)[keyof typeof ImportKind];
39
+ /** Allowed target element types for a Metadata element header */
39
40
  export declare enum MetadataTargetKind {
40
- Table = "table",
41
- Schema = "schema",
42
- Column = "column",
43
- TableGroup = "tablegroup",
44
- Note = "note"
41
+ Table = "Table",
42
+ Column = "Column",
43
+ TableGroup = "TableGroup",
44
+ Note = "Note"
45
45
  }
46
- export declare const ALLOWED_METADATA_TARGET_KINDS: readonly MetadataTargetKind[];
47
46
  declare const __nodeSymbolBrand: unique symbol;
48
47
  export type NodeSymbolId = number & {
49
48
  readonly [__nodeSymbolBrand]: true;
@@ -159,6 +158,7 @@ export declare class ColumnSymbol extends NodeSymbol {
159
158
  pk(compiler: Compiler): boolean;
160
159
  unique(compiler: Compiler): boolean;
161
160
  nullable(compiler: Compiler): boolean | undefined;
161
+ isIncrementSet(compiler: Compiler): boolean;
162
162
  increment(compiler: Compiler): boolean;
163
163
  default(compiler: Compiler): {
164
164
  type: 'number' | 'string' | 'boolean' | 'expression';
@@ -1,4 +1,4 @@
1
- import { ElementDeclarationNode, MetadataDeclarationNode, SyntaxNode } from '../types/nodes';
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 | MetadataDeclarationNode): boolean;
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 validateCustomInlineMetadata(name: string, attrs: AttributeNode[], errorCodes: {
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 & {
@@ -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.2",
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": "6ab830c6b2387ff0c3c9cd0e94c52e62e722ca25"
53
+ "gitHead": "be8c21d3525b0001b295695af7057e0e9cfae5d1"
54
54
  }
@@ -1,11 +0,0 @@
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
- export interface FieldValidateSpec {
6
- predicate(valueNode?: SyntaxNode): boolean;
7
- message: string;
8
- }
9
- export type FieldValidateMap<T extends SettingName = SettingName> = Record<T, FieldValidateSpec>;
10
- export type FieldAssign<T extends MetadataTarget> = (element: T, value: string, token: TokenPosition) => void;
11
- export type FieldAssignMap<T extends MetadataTarget = MetadataTarget, P extends SettingName = SettingName> = Record<P, FieldAssign<T>>;