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

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.
@@ -0,0 +1,11 @@
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>>;
@@ -1,10 +1,12 @@
1
1
  import { default as Compiler } from '../../../compiler';
2
- import { Filepath } from '../../types';
2
+ import { SettingName, 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 { Color, MetadataElement } from '../../types/schemaJson';
7
- export declare function extractValue(node?: SyntaxNode): string | number | boolean | Color | undefined;
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[];
8
10
  export default class MetadataInterpreter {
9
11
  private declarationNode;
10
12
  private compiler;
@@ -1,6 +1,7 @@
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 { FieldAssignMap } from '../metadata/fieldSpec';
4
5
  import { default as Report } from '../../types/report';
5
6
  export declare class StickyNoteInterpreter {
6
7
  private declarationNode;
@@ -15,3 +16,4 @@ export declare class StickyNoteInterpreter {
15
16
  private interpretBody;
16
17
  private interpretNote;
17
18
  }
19
+ export declare const NOTE_FIELD_ASSIGNS: FieldAssignMap<Note, SettingName.Color>;
@@ -11,11 +11,14 @@ export default class ProgramInterpreter {
11
11
  private errors;
12
12
  private warnings;
13
13
  private db;
14
+ private emittedBySymbol;
14
15
  constructor(compiler: Compiler, symbol: ProgramSymbol, filepath: Filepath);
15
16
  interpret(): Report<SchemaElement | SchemaElement[] | undefined>;
16
17
  private interpretAllSymbols;
17
18
  private interpretUseSymbol;
18
19
  private interpretAllMetadata;
20
+ private writeBuiltinFields;
21
+ private attachMetadata;
19
22
  private interpretAllAliases;
20
23
  private validateRecords;
21
24
  private collectPartialRefs;
@@ -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 { FieldAssignMap } from '../metadata/fieldSpec';
5
7
  import { Filepath } from '../../types/filepath';
6
8
  import { TableSymbol } from '../../types/symbol/symbols';
7
9
  export declare class TableInterpreter {
@@ -24,3 +26,5 @@ export declare class TableInterpreter {
24
26
  private interpretIndexes;
25
27
  private interpretChecks;
26
28
  }
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>;
@@ -1,6 +1,7 @@
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 { FieldAssignMap } from '../metadata/fieldSpec';
4
5
  import { default as Report } from '../../types/report';
5
6
  export declare class TableGroupInterpreter {
6
7
  private compiler;
@@ -16,3 +17,4 @@ export declare class TableGroupInterpreter {
16
17
  private interpretFields;
17
18
  private interpretSettingList;
18
19
  }
20
+ export declare const TABLEGROUP_FIELD_ASSIGNS: FieldAssignMap<TableGroup, SettingName.Note | SettingName.Color>;
@@ -1,6 +1,9 @@
1
1
  import { default as Compiler } from '../../../compiler';
2
2
  import { CompileError } from '../../types/errors';
3
+ import { SettingName } from '../../types/keywords';
3
4
  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>;
4
7
  export default class NoteValidator {
5
8
  private compiler;
6
9
  private declarationNode;
@@ -1,8 +1,12 @@
1
1
  import { default as Compiler } from '../../../compiler';
2
2
  import { CompileError } from '../../types/errors';
3
+ import { SettingName } from '../../types/keywords';
3
4
  import { ElementDeclarationNode, ExpressionNode, ListExpressionNode } from '../../types/nodes';
4
5
  import { default as Report } from '../../types/report';
5
6
  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>;
6
10
  export default class TableValidator {
7
11
  private declarationNode;
8
12
  private compiler;
@@ -1,8 +1,11 @@
1
1
  import { default as Compiler } from '../../../compiler';
2
2
  import { CompileError } from '../../types/errors';
3
+ import { SettingName } from '../../types/keywords';
3
4
  import { BlockExpressionNode, ElementDeclarationNode, FunctionApplicationNode, ListExpressionNode } from '../../types/nodes';
4
5
  import { default as Report } from '../../types/report';
5
6
  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>;
6
9
  export default class TableGroupValidator {
7
10
  private declarationNode;
8
11
  private compiler;
@@ -114,12 +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
- 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
+ INVALID_METADATA_TARGET_KIND = 5006,
118
+ INVALID_METADATA_FIELD = 5007,
119
+ DUPLICATE_METADATA_FIELD = 5008
123
120
  }
124
121
  export declare class CompileError extends Error {
125
122
  code: Readonly<CompileErrorCode>;
@@ -13,8 +13,7 @@ export declare enum ElementKind {
13
13
  DiagramViewTables = "tables",
14
14
  DiagramViewNotes = "notes",
15
15
  DiagramViewTableGroups = "tablegroups",
16
- DiagramViewSchemas = "schemas",
17
- Metadata = "metadata"
16
+ DiagramViewSchemas = "schemas"
18
17
  }
19
18
  export declare enum SettingName {
20
19
  Color = "color",
@@ -88,13 +88,11 @@ export declare class UseDeclarationNode extends SyntaxNode {
88
88
  }
89
89
  export declare class UseSpecifierNode extends SyntaxNode {
90
90
  importKind?: SyntaxToken;
91
- subKind?: SyntaxToken;
92
91
  name?: NormalExpressionNode;
93
92
  asKeyword?: SyntaxToken;
94
93
  alias?: NormalExpressionNode;
95
- constructor({ importKind, subKind, name, asKeyword, alias, }: {
94
+ constructor({ importKind, name, asKeyword, alias, }: {
96
95
  importKind?: SyntaxToken;
97
- subKind?: SyntaxToken;
98
96
  name?: NormalExpressionNode;
99
97
  asKeyword?: SyntaxToken;
100
98
  alias?: NormalExpressionNode;
@@ -1,6 +1,8 @@
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
+ export type CustomMetadata = Record<string, string>;
4
6
  export type Color = `#${string}` | typeof NONE_COLOR;
5
7
  export declare enum AliasKind {
6
8
  Table = "table"
@@ -66,7 +68,6 @@ export interface Database {
66
68
  records: TableRecord[];
67
69
  externals: DatabaseExternals;
68
70
  diagramViews: DiagramView[];
69
- metadataElements: MetadataElement[];
70
71
  token?: TokenPosition;
71
72
  }
72
73
  export interface MasterDatabase {
@@ -86,12 +87,14 @@ export interface Table {
86
87
  value: string;
87
88
  token: TokenPosition;
88
89
  };
90
+ metadata?: CustomMetadata;
89
91
  }
90
92
  export interface Note {
91
93
  name: string;
92
94
  content: string;
93
95
  token: TokenPosition;
94
96
  color?: Color;
97
+ metadata?: CustomMetadata;
95
98
  }
96
99
  export interface ColumnType {
97
100
  schemaName: string | null;
@@ -124,6 +127,7 @@ export interface Column {
124
127
  value: string;
125
128
  token: TokenPosition;
126
129
  };
130
+ metadata?: CustomMetadata;
127
131
  }
128
132
  export interface Index {
129
133
  columns: {
@@ -196,6 +200,7 @@ export interface TableGroup {
196
200
  value: string;
197
201
  token: TokenPosition;
198
202
  };
203
+ metadata?: CustomMetadata;
199
204
  }
200
205
  export interface TableGroupField {
201
206
  name: string;
@@ -241,12 +246,11 @@ export interface TableRecord {
241
246
  }
242
247
  export interface MetadataElement {
243
248
  target: {
244
- kind: string;
249
+ kind: MetadataTargetKind;
245
250
  name: string[];
246
251
  };
247
- values: {
248
- [key: string]: unknown;
249
- };
252
+ values: CustomMetadata;
253
+ valueTokens: Record<string, TokenPosition>;
250
254
  token: TokenPosition;
251
255
  }
252
256
  export type Project = Record<string, never> | {
@@ -34,7 +34,6 @@ 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];
40
39
  export declare enum MetadataTargetKind {
@@ -1,16 +1,26 @@
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): {
8
10
  schemaName: string[];
9
11
  name: string;
10
12
  };
11
- export declare function extractColor(node: unknown): Color | undefined;
13
+ export declare function extractColor(node?: SyntaxNode): Color | undefined;
12
14
  export declare function processDefaultValue(valueNode?: SyntaxNode): {
13
15
  type: 'number' | 'string' | 'boolean' | 'expression';
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,3 +1,4 @@
1
+ import { CompileError, CompileErrorCode } from '../types/errors';
1
2
  import { AttributeNode, BlockExpressionNode, ElementDeclarationNode, FunctionApplicationNode, FunctionExpressionNode, InfixExpressionNode, ListExpressionNode, LiteralNode, PrefixExpressionNode, PrimaryExpressionNode, ProgramNode, SyntaxNode, TupleExpressionNode, UseDeclarationNode, UseSpecifierNode, VariableNode, WildcardNode } from '../types/nodes';
2
3
  import { default as Report } from '../types/report';
3
4
  import { SyntaxToken, SyntaxTokenKind } from '../types/tokens';
@@ -24,7 +25,14 @@ export declare function isValidPartialInjection(node?: SyntaxNode): node is Pref
24
25
  };
25
26
  };
26
27
  export declare function isRelationshipOp(op?: string): boolean;
27
- export declare function isValidColor(value?: SyntaxNode): boolean;
28
+ export declare function isValidHexColor(value?: SyntaxNode): value is PrimaryExpressionNode & {
29
+ expression: LiteralNode & {
30
+ literal: {
31
+ kind: SyntaxTokenKind.COLOR_LITERAL;
32
+ };
33
+ };
34
+ };
35
+ export declare function isValidColorOrNone(value?: SyntaxNode): boolean;
28
36
  export declare function isValidDefaultValue(value?: SyntaxNode): boolean;
29
37
  export type SignedNumberExpression = (PrimaryExpressionNode & {
30
38
  expression: LiteralNode & {
@@ -45,6 +53,11 @@ export declare function isTupleOfVariables(value?: SyntaxNode): value is TupleEx
45
53
  };
46
54
  export declare function isValidColumnType(type: SyntaxNode): boolean;
47
55
  export type Settings = Record<SettingName | string, AttributeNode[]>;
56
+ 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[];
48
61
  export declare function aggregateSettingList(settingList?: ListExpressionNode): Report<Settings>;
49
62
  export declare function isExpressionAQuotedString(value?: unknown): value is PrimaryExpressionNode & ({
50
63
  expression: VariableNode & {
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.0",
4
+ "version": "8.3.1-custom-metadata.2",
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": "cca14935200249a97ec9575cbbe16f5d491c4fc4"
53
+ "gitHead": "6ab830c6b2387ff0c3c9cd0e94c52e62e722ca25"
54
54
  }