@dbml/parse 8.3.0 → 8.3.1-custom-metadata.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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 | import('../core/types/nodes').MetadataDeclarationNode>;
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, ProgramNode } from '../../../core/types/nodes';
2
+ import { ElementDeclarationNode, MetadataDeclarationNode, 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 | ProgramNode>;
4
+ export declare function containerElement(this: Compiler, filepath: Filepath, offset: number): Readonly<ElementDeclarationNode | MetadataDeclarationNode | ProgramNode>;
@@ -11,5 +11,6 @@ export declare const enum ScopeKind {
11
11
  TABLEPARTIAL = 9,
12
12
  CHECKS = 10,
13
13
  RECORDS = 11,
14
- DIAGRAMVIEW = 12
14
+ DIAGRAMVIEW = 12,
15
+ METADATA = 13
15
16
  }
@@ -0,0 +1,11 @@
1
+ import { default as Compiler } from '../../../compiler';
2
+ import { CompileError } from '../../types';
3
+ import { MetadataDeclarationNode } from '../../types/nodes';
4
+ export default class MetadataBinder {
5
+ private compiler;
6
+ private declarationNode;
7
+ constructor(compiler: Compiler, declarationNode: MetadataDeclarationNode);
8
+ bind(): CompileError[];
9
+ private bindTargetElement;
10
+ private bindBody;
11
+ }
@@ -0,0 +1,2 @@
1
+ import { GlobalModule } from '../types';
2
+ export declare const metadataModule: GlobalModule;
@@ -0,0 +1,17 @@
1
+ import { default as Compiler } from '../../../compiler';
2
+ import { Filepath } from '../../types';
3
+ import { MetadataElementMetadata } from '../../types/symbol/metadata';
4
+ import { SyntaxNode } from '../../types/nodes';
5
+ import { default as Report } from '../../types/report';
6
+ import { Color, MetadataElement } from '../../types/schemaJson';
7
+ export declare function extractValue(node?: SyntaxNode): string | number | boolean | Color | undefined;
8
+ export default class MetadataInterpreter {
9
+ private declarationNode;
10
+ private compiler;
11
+ private filepath;
12
+ private metadata;
13
+ constructor(compiler: Compiler, metadata: MetadataElementMetadata, filepath: Filepath);
14
+ interpret(): Report<MetadataElement>;
15
+ private interpretTarget;
16
+ private interpretValues;
17
+ }
@@ -0,0 +1,4 @@
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;
@@ -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,2 @@
1
+ import { LocalModule } from '../types';
2
+ export declare const metadataModule: LocalModule;
@@ -0,0 +1,14 @@
1
+ import { default as Compiler } from '../../../compiler';
2
+ import { CompileError } from '../../types/errors';
3
+ import { MetadataDeclarationNode } from '../../types/nodes';
4
+ export default class MetadataValidator {
5
+ private compiler;
6
+ private declarationNode;
7
+ constructor(compiler: Compiler, declarationNode: MetadataDeclarationNode);
8
+ validate(): CompileError[];
9
+ private validateTargetKind;
10
+ private validateTargetName;
11
+ private validateBody;
12
+ private validateFields;
13
+ private validateSubElements;
14
+ }
@@ -32,6 +32,7 @@ export default class Parser {
32
32
  private synchronizeUseSpecifierList;
33
33
  private useSpecifier;
34
34
  private synchronizeProgram;
35
+ private metadataDeclaration;
35
36
  private elementDeclaration;
36
37
  private synchronizeElementDeclarationName;
37
38
  private synchronizeElementDeclarationAlias;
@@ -113,7 +113,13 @@ 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,
122
+ DUPLICATE_METADATA_KEY_ACROSS_BLOCKS = 5011
117
123
  }
118
124
  export declare class CompileError extends Error {
119
125
  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",
@@ -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, SymbolKind } from './symbol';
4
+ import { ImportKind, MetadataTargetKind, SymbolKind } from './symbol';
5
5
  import { Position } from './position';
6
6
  import { SyntaxToken } from './tokens';
7
7
  export type SyntaxNodeId = number;
@@ -36,6 +36,7 @@ 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>",
39
40
  USE_DECLARATION = "<use-declaration>",
40
41
  USE_SPECIFIER = "<use-specifier>",
41
42
  USE_SPECIFIER_LIST = "<use-specifier-list>",
@@ -60,16 +61,17 @@ export declare enum SyntaxNodeKind {
60
61
  WILDCARD = "<wildcard>"
61
62
  }
62
63
  export declare class ProgramNode extends SyntaxNode {
63
- body: (UseDeclarationNode | ElementDeclarationNode)[];
64
+ body: (UseDeclarationNode | ElementDeclarationNode | MetadataDeclarationNode)[];
64
65
  eof?: SyntaxToken;
65
66
  source: string;
66
67
  constructor({ body, eof, source, }: {
67
- body?: (UseDeclarationNode | ElementDeclarationNode)[];
68
+ body?: (UseDeclarationNode | ElementDeclarationNode | MetadataDeclarationNode)[];
68
69
  eof?: SyntaxToken;
69
70
  source: string;
70
71
  }, id: SyntaxNodeId, filepath: Filepath);
71
72
  get declarations(): ElementDeclarationNode[];
72
73
  get uses(): UseDeclarationNode[];
74
+ get metadata(): MetadataDeclarationNode[];
73
75
  }
74
76
  export declare class UseDeclarationNode extends SyntaxNode {
75
77
  useKeyword?: SyntaxToken;
@@ -86,11 +88,13 @@ export declare class UseDeclarationNode extends SyntaxNode {
86
88
  }
87
89
  export declare class UseSpecifierNode extends SyntaxNode {
88
90
  importKind?: SyntaxToken;
91
+ subKind?: SyntaxToken;
89
92
  name?: NormalExpressionNode;
90
93
  asKeyword?: SyntaxToken;
91
94
  alias?: NormalExpressionNode;
92
- constructor({ importKind, name, asKeyword, alias, }: {
95
+ constructor({ importKind, subKind, name, asKeyword, alias, }: {
93
96
  importKind?: SyntaxToken;
97
+ subKind?: SyntaxToken;
94
98
  name?: NormalExpressionNode;
95
99
  asKeyword?: SyntaxToken;
96
100
  alias?: NormalExpressionNode;
@@ -108,6 +112,21 @@ export declare class UseSpecifierListNode extends SyntaxNode {
108
112
  closeBrace?: SyntaxToken;
109
113
  }, id: SyntaxNodeId, filepath: Filepath);
110
114
  }
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
+ }
111
130
  export declare class ElementDeclarationNode extends SyntaxNode {
112
131
  type?: SyntaxToken;
113
132
  name?: NormalExpressionNode;
@@ -125,8 +144,17 @@ export declare class ElementDeclarationNode extends SyntaxNode {
125
144
  bodyColon?: SyntaxToken;
126
145
  body?: BlockExpressionNode | FunctionApplicationNode;
127
146
  }, id: SyntaxNodeId, filepath: Filepath);
128
- isKind(...kinds: ElementKind[]): boolean;
129
- getElementKind(): ElementKind | undefined;
147
+ isKind<T extends ElementKind>(...kinds: T[]): this is ElementDeclarationNode & {
148
+ type: {
149
+ value: T;
150
+ };
151
+ };
152
+ getElementKind<T extends ElementKind>(this: ElementDeclarationNode & {
153
+ type: {
154
+ value: T;
155
+ };
156
+ }): T;
157
+ getElementKind(this: ElementDeclarationNode): ElementKind | undefined;
130
158
  }
131
159
  export declare class IdentifierStreamNode extends SyntaxNode {
132
160
  identifiers: SyntaxToken[];
@@ -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;
@@ -1,5 +1,5 @@
1
1
  import { default as Compiler } from '../../../compiler';
2
- import { AttributeNode, ElementDeclarationNode, SyntaxNode } from '../nodes';
2
+ import { AttributeNode, ElementDeclarationNode, MetadataDeclarationNode, SyntaxNode } from '../nodes';
3
3
  import { ColumnSymbol, NodeSymbol, TablePartialSymbol, TableSymbol } from '../symbol';
4
4
  import { Internable } from '../internable';
5
5
  export declare enum MetadataKind {
@@ -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: MetadataDeclarationNode;
80
+ readonly kind = MetadataKind.MetadataElement;
81
+ constructor(declaration: MetadataDeclarationNode);
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;
@@ -1,4 +1,4 @@
1
- import { ElementDeclarationNode, SyntaxNode } from '../types/nodes';
1
+ import { ElementDeclarationNode, MetadataDeclarationNode, 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): boolean;
4
+ export declare function isOffsetWithinElementHeader(offset: number, element: ElementDeclarationNode | MetadataDeclarationNode): boolean;
@@ -6,6 +6,9 @@ export declare function isAsKeyword(token?: SyntaxToken): token is SyntaxToken &
6
6
  export declare function isUseKeyword(token?: SyntaxToken): token is SyntaxToken & {
7
7
  kind: SyntaxTokenKind.IDENTIFIER;
8
8
  };
9
+ export declare function isMetadataKeyword(token?: SyntaxToken): token is SyntaxToken & {
10
+ kind: SyntaxTokenKind.IDENTIFIER;
11
+ };
9
12
  export declare function isFromKeyword(token?: SyntaxToken): token is SyntaxToken & {
10
13
  kind: SyntaxTokenKind.IDENTIFIER;
11
14
  };
@@ -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: ElementKind): node is ElementDeclarationNode;
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;
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.0",
4
+ "version": "8.3.1-custom-metadata.0",
5
5
  "description": "DBML parser v2",
6
6
  "author": "Holistics <dev@holistics.io>",
7
7
  "license": "Apache-2.0",
@@ -50,5 +50,5 @@
50
50
  "engines": {
51
51
  "node": ">=18"
52
52
  },
53
- "gitHead": "d1c00c334882b0221bd3966a17e098d86611bec2"
53
+ "gitHead": "cca14935200249a97ec9575cbbe16f5d491c4fc4"
54
54
  }