@dbml/parse 8.3.1-custom-metadata.1 → 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,16 +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, CustomMetadata, MetadataElement } from '../../types/schemaJson';
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 { 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[];
14
10
  export default class MetadataInterpreter {
15
11
  private declarationNode;
16
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>;
@@ -17,11 +17,10 @@ export default class ProgramInterpreter {
17
17
  private interpretAllSymbols;
18
18
  private interpretUseSymbol;
19
19
  private interpretAllMetadata;
20
- private promoteOverlapKeys;
20
+ private writeBuiltinFields;
21
21
  private attachMetadata;
22
22
  private interpretAllAliases;
23
23
  private validateRecords;
24
24
  private collectPartialRefs;
25
25
  private pushElement;
26
- private recordEmitted;
27
26
  }
@@ -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,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
- 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
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>;
@@ -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,7 +1,8 @@
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, unknown>;
4
+ import { MetadataTargetKind } from './symbol';
5
+ export type CustomMetadata = Record<string, string>;
5
6
  export type Color = `#${string}` | typeof NONE_COLOR;
6
7
  export declare enum AliasKind {
7
8
  Table = "table"
@@ -245,7 +246,7 @@ export interface TableRecord {
245
246
  }
246
247
  export interface MetadataElement {
247
248
  target: {
248
- kind: string;
249
+ kind: MetadataTargetKind;
249
250
  name: string[];
250
251
  };
251
252
  values: CustomMetadata;
@@ -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,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;
@@ -54,7 +54,7 @@ export declare function isTupleOfVariables(value?: SyntaxNode): value is TupleEx
54
54
  export declare function isValidColumnType(type: SyntaxNode): boolean;
55
55
  export type Settings = Record<SettingName | string, AttributeNode[]>;
56
56
  export declare function isValidMetadataValue(value?: SyntaxNode): boolean;
57
- export declare function validateInlineMetadataSetting(name: string, attrs: AttributeNode[], codes: {
57
+ export declare function validateCustomInlineMetadata(name: string, attrs: AttributeNode[], errorCodes: {
58
58
  duplicate: CompileErrorCode;
59
59
  invalidValue: CompileErrorCode;
60
60
  }): CompileError[];
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.1",
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": "152988f537ab87a9d8320bd41b478495c1acbb0c"
53
+ "gitHead": "6ab830c6b2387ff0c3c9cd0e94c52e62e722ca25"
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;