@dbml/parse 10.4.0-metadata-ref-type.0 → 10.4.0-metadata-type.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.
Files changed (31) hide show
  1. package/dist/dbml-parse.js +24 -24
  2. package/dist/dbml-parse.mjs +3447 -3499
  3. package/dist/src/compiler/index.d.ts +2 -20
  4. package/dist/src/compiler/projectLayout/layout.d.ts +7 -0
  5. package/dist/src/core/global_modules/metadata/interpret.d.ts +2 -2
  6. package/dist/src/core/global_modules/metadata/registries.d.ts +19 -0
  7. package/dist/src/core/global_modules/metadata/utils.d.ts +24 -19
  8. package/dist/src/core/global_modules/note/interpret.d.ts +1 -3
  9. package/dist/src/core/global_modules/records/utils/data/values.d.ts +1 -2
  10. package/dist/src/core/global_modules/ref/index.d.ts +0 -4
  11. package/dist/src/core/global_modules/ref/interpret.d.ts +1 -3
  12. package/dist/src/core/global_modules/table/interpret.d.ts +1 -4
  13. package/dist/src/core/global_modules/tableGroup/interpret.d.ts +1 -3
  14. package/dist/src/core/local_modules/dep/validate.d.ts +1 -4
  15. package/dist/src/core/local_modules/note/validate.d.ts +0 -2
  16. package/dist/src/core/local_modules/table/validate.d.ts +1 -7
  17. package/dist/src/core/local_modules/tableGroup/validate.d.ts +1 -5
  18. package/dist/src/core/types/errors.d.ts +4 -0
  19. package/dist/src/core/types/filepath.d.ts +3 -1
  20. package/dist/src/core/types/schemaJson/types.d.ts +7 -11
  21. package/dist/src/core/types/symbol/symbols.d.ts +1 -11
  22. package/dist/src/core/utils/expression.d.ts +1 -0
  23. package/dist/src/core/utils/interpret.d.ts +14 -3
  24. package/dist/src/index.d.ts +3 -2
  25. package/dist/src/services/definition/provider.d.ts +1 -0
  26. package/dist/src/services/suggestions/provider.d.ts +3 -1
  27. package/dist/src/services/suggestions/use.d.ts +4 -1
  28. package/package.json +3 -3
  29. package/dist/src/compiler/queries/metadata/isSymbolVisible.d.ts +0 -10
  30. package/dist/src/compiler/queries/metadata/metadataTargets.d.ts +0 -7
  31. package/dist/src/compiler/queries/symbol/visibleSymbols.d.ts +0 -7
@@ -50,26 +50,7 @@ export default class Compiler {
50
50
  symbolMetadata: (symbol: import('../core/types/symbol').NodeSymbol) => import('../core/types/symbol').NodeMetadata[];
51
51
  symbolAliases: (symbol: import('../core/types/symbol').NodeSymbol) => import('../core/types/report').default<import('../core/types/symbol').AliasSymbol[]>;
52
52
  symbolUses: (symbol: import('../core/types/symbol').NodeSymbol) => import('../core/types/report').default<import('../core/types/symbol').UseSymbol[]>;
53
- /**
54
- * A global query
55
- * Return the named refs visible from a program (refs are not imported via `use`).
56
- */
57
- visibleSymbols: (program: import('../core/types/symbol').ProgramSymbol, kind: import('../core/types/symbol').SymbolKind) => import('../core/types/symbol').RefSymbol[];
58
- /**
59
- * A global query
60
- * Whether a symbol is visible from a program
61
- */
62
- isSymbolVisible: (program: import('../core/types/symbol').ProgramSymbol, symbol: import('../core/types/symbol').NodeSymbol) => boolean;
63
- /**
64
- * A global query
65
- * Resolve all candidates that a metadata block can target
66
- */
67
- metadataTargets: (block: import('../core/types/symbol').MetadataElementMetadata) => import('../core/types/symbol').NodeSymbol[];
68
53
  fileDependencies: (filepath: Filepath) => Filepath[];
69
- /**
70
- * A global query
71
- * BFS-traverse imports from an entry filepath and return all reachable files. Related: fileDependencies.
72
- */
73
54
  reachableFiles: (entry?: Filepath | undefined) => Filepath[];
74
55
  usableMembers: (symbolOrFilepath: Filepath | import('../core/types/symbol').SchemaSymbol | import('../core/types/symbol').ProgramSymbol) => import('../core/types/report').default<{
75
56
  nonSchemaMembers: import('../core/types/symbol').NodeSymbol[];
@@ -109,7 +90,7 @@ export default class Compiler {
109
90
  source: (filepath: Filepath) => string;
110
91
  ast: (filepath?: Filepath) => Readonly<import('../core/types/nodes').ProgramNode>;
111
92
  errors: (filepath?: Filepath) => readonly Readonly<import('..').CompileError>[];
112
- warnings: (filepath?: Filepath) => readonly Readonly<import('../core/types').CompileWarning>[];
93
+ warnings: (filepath?: Filepath) => readonly Readonly<import('..').CompileWarning>[];
113
94
  tokens: (filepath?: Filepath) => readonly Readonly<import('..').SyntaxToken>[];
114
95
  rawDb: (filepath?: Filepath) => Readonly<import('..').Database> | undefined;
115
96
  publicSymbolTable: (filepath?: Filepath) => readonly Readonly<import('../core/types/symbol').NodeSymbol>[] | undefined;
@@ -130,6 +111,7 @@ export default class Compiler {
130
111
  initMonacoServices(options?: {
131
112
  autocompletion?: {
132
113
  triggerCharacters?: string[];
114
+ fileListDepth?: number;
133
115
  };
134
116
  }): {
135
117
  definitionProvider: DBMLDefinitionProvider;
@@ -1,6 +1,12 @@
1
1
  import { Filepath } from '../../core/types/filepath';
2
+ export interface FileSpecifierInfo {
3
+ specifier: string;
4
+ label?: string;
5
+ detail?: string;
6
+ }
2
7
  export interface DbmlProjectLayout {
3
8
  resolveFileSpecifier(currentFilepath: Filepath, specifier: string): Filepath | undefined;
9
+ getFileSpecifierInfo(currentFilepath: Filepath, targetFilepath: Filepath): FileSpecifierInfo | undefined;
4
10
  getSource(filePath: Filepath): string | undefined;
5
11
  exists(filePath: Filepath): boolean;
6
12
  isFile(filePath: Filepath): boolean;
@@ -12,6 +18,7 @@ export declare class MemoryProjectLayout implements DbmlProjectLayout {
12
18
  private readonly files;
13
19
  constructor(files?: Map<string, string> | Record<string, string>);
14
20
  resolveFileSpecifier(currentFilepath: Filepath, relativePath: string): Filepath | undefined;
21
+ getFileSpecifierInfo(currentFilepath: Filepath, targetFilepath: Filepath): FileSpecifierInfo | undefined;
15
22
  setSource(filePath: Filepath, content: string): void;
16
23
  getSource(filePath: Filepath): string | undefined;
17
24
  deleteSource(filePath: Filepath): void;
@@ -2,13 +2,13 @@ import { default as Compiler } from '../../../compiler';
2
2
  import { Filepath } from '../../types';
3
3
  import { MetadataElementMetadata } from '../../types/symbol/metadata';
4
4
  import { default as Report } from '../../types/report';
5
- import { MetadataValues } from '../../types/schemaJson';
5
+ import { CustomMetadata } from '../../types/schemaJson';
6
6
  export default class MetadataInterpreter {
7
7
  private declarationNode;
8
8
  private compiler;
9
9
  private filepath;
10
10
  private values;
11
11
  constructor(compiler: Compiler, metadata: MetadataElementMetadata, filepath: Filepath);
12
- interpret(): Report<MetadataValues>;
12
+ interpret(): Report<CustomMetadata>;
13
13
  private interpretValues;
14
14
  }
@@ -0,0 +1,19 @@
1
+ import { SettingName } from '../../types/keywords';
2
+ import { Color, Column, Note, Table, TableGroup } from '../../types/schemaJson';
3
+ import { MetadataTargetKind } from '../../types/symbol';
4
+ import { MetadataFieldRegistry } from './utils';
5
+ export declare const TABLE_METADATA_FIELDS: MetadataFieldRegistry<Table, {
6
+ [SettingName.Note]: string;
7
+ [SettingName.HeaderColor]: Color;
8
+ }>;
9
+ export declare const COLUMN_METADATA_FIELDS: MetadataFieldRegistry<Column, {
10
+ [SettingName.Note]: string;
11
+ }>;
12
+ export declare const TABLEGROUP_METADATA_FIELDS: MetadataFieldRegistry<TableGroup, {
13
+ [SettingName.Note]: string;
14
+ [SettingName.Color]: Color;
15
+ }>;
16
+ export declare const NOTE_METADATA_FIELDS: MetadataFieldRegistry<Note, {
17
+ [SettingName.Color]: Color;
18
+ }>;
19
+ export declare const METADATA_FIELDS_BY_KIND: Record<MetadataTargetKind, MetadataFieldRegistry<any, any>>;
@@ -1,31 +1,36 @@
1
1
  import { default as Compiler } from '../../../compiler/index';
2
2
  import { Filepath, SettingName } from '../../types';
3
- import { Column, CustomMetadataValue, Note, Ref, Table, TableGroup, TokenPosition } from '../../types/schemaJson';
4
- import { SyntaxNode } from '../../types/nodes';
3
+ import { Column, CustomMetadataValue, CustomMetadataValueType, Note, Table, TableGroup, TokenPosition } from '../../types/schemaJson';
4
+ import { ElementDeclarationNode, SyntaxNode } from '../../types/nodes';
5
5
  import { NodeSymbol, SymbolKind, MetadataTargetKind } from '../../types/symbol';
6
- export type MetadataTarget = Table | TableGroup | Note | Column | Ref;
6
+ export type MetadataTarget = Table | TableGroup | Note | Column;
7
7
  /**
8
- * Specs for builtin metadata (table's note, tablegroup's color, .etc) for different element types. Does 2 things:
9
- * - `validate`: Validating if the metadata value is syntactically correct
10
- * - `assign`: Write the metadata value to the element builtin props (e.g. write `table.note` instead of `table.metadata`)
8
+ * Spec for one builtin metadata field (table's note, tablegroup's color, .etc) of an element kind.
9
+ * Used for both the inline settings list and Metadata blocks:
10
+ * - `parse`: Read the field's own value from a source node, `undefined` means the value is invalid
11
+ * - `assign`: Write the parsed value to the element builtin props (e.g. write `table.note` instead of `table.metadata`)
11
12
  */
12
- interface MetadataField<T extends MetadataTarget> {
13
- /** Check if the metadata value is syntactically correct */
14
- isValidBuiltinFieldValue(node?: SyntaxNode): boolean;
13
+ type MetadataField<T, V> = {
14
+ /** Type of the parsed value, reported when the field is read as a metadata entry */
15
+ type: CustomMetadataValueType;
16
+ /** Parse the source node into the field's value, `undefined` if the node is not a valid value for this field */
17
+ parse(node?: SyntaxNode): V | undefined;
15
18
  message: string;
16
- /** Write the metadata value to the element builtin props (e.g. write to `table.note`) */
17
- assignBuiltinField(element: Partial<T>, value: CustomMetadataValue, token: TokenPosition): void;
18
- }
19
- export type MetadataFieldRegistry<T extends MetadataTarget, K extends SettingName> = Record<K, MetadataField<T>>;
20
- export type NameWithSymbolKind = {
19
+ /** Write the parsed value to the element builtin props (e.g. write to `table.note`) */
20
+ assign(element: Partial<T>, value: V, token: TokenPosition): void;
21
+ };
22
+ export type MetadataFieldRegistry<T extends MetadataTarget, R extends {
23
+ [K in SettingName]?: CustomMetadataValue['value'];
24
+ }> = {
25
+ [K in keyof R]: MetadataField<T, R[K]>;
26
+ };
27
+ type NameWithSymbolKind = {
21
28
  name: string;
22
29
  symbolKind: SymbolKind;
23
30
  };
24
31
  /** @internal Exported for testing only. */
25
- export declare function mapNamePartToSymbolKind(nameParts: string[], targetKind: Exclude<MetadataTargetKind, MetadataTargetKind.Ref>): NameWithSymbolKind[];
26
- /**
27
- * Merge every custom-metadata block applying to the target in the current program (in precedence order) to its `metadata` and other builtin (note/headercolor/...) fields
28
- * NOTE: Only run during interpret phase
29
- */
32
+ export declare function mapNamePartToSymbolKind(nameParts: string[], targetKind: MetadataTargetKind): NameWithSymbolKind[];
33
+ export declare function resolveMetadataTarget(compiler: Compiler, metadataNode: ElementDeclarationNode): NodeSymbol | undefined;
34
+ /** Merge every custom-metadata block, reachable from the current program, targeting element to it's `metadata` and other builtin (note/headercolor/...) fields */
30
35
  export declare function attachCustomMetadata<T extends MetadataTarget>(compiler: Compiler, targetElement: Partial<T>, targetSymbol: NodeSymbol, fieldsRegistry: MetadataFieldRegistry<T, any>, filepath: Filepath): void;
31
36
  export {};
@@ -1,9 +1,7 @@
1
1
  import { Note } from '../../types/schemaJson';
2
2
  import { default as Compiler } from '../../../compiler';
3
- import { SettingName, Filepath, NoteSymbol } from '../../types';
3
+ import { Filepath, NoteSymbol } from '../../types';
4
4
  import { default as Report } from '../../types/report';
5
- import { MetadataFieldRegistry } from '../metadata/utils';
6
- export declare const NOTE_METADATA_FIELDS: MetadataFieldRegistry<Note, SettingName.Color>;
7
5
  export declare class StickyNoteInterpreter {
8
6
  private declarationNode;
9
7
  private symbol;
@@ -1,9 +1,8 @@
1
1
  import { FunctionExpressionNode, SyntaxNode } from '../../../../types/nodes';
2
- export { extractNumericLiteral } from '../../../../utils/expression';
2
+ export { extractNumericLiteral, extractSignedNumber } from '../../../../utils/expression';
3
3
  export declare function isNullish(value: SyntaxNode): boolean;
4
4
  export declare function isEmptyStringLiteral(value: SyntaxNode): boolean;
5
5
  export declare function isFunctionExpression(value: SyntaxNode): value is FunctionExpressionNode;
6
- export declare function extractSignedNumber(node: SyntaxNode): number | null;
7
6
  export declare function tryExtractNumeric(value: SyntaxNode | number | string | boolean | undefined | null): number | null;
8
7
  export declare function tryExtractInteger(value: SyntaxNode | number | string | boolean | undefined | null): number | null;
9
8
  export declare const TRUTHY_VALUES: string[];
@@ -2,10 +2,6 @@ import { default as Compiler } from '../../../compiler/index';
2
2
  import { SyntaxNode } from '../../types/nodes';
3
3
  import { default as Report } from '../../types/report';
4
4
  import { NodeSymbol } from '../../types/symbol';
5
- import { CompileError } from '../../types';
6
5
  import { GlobalModule } from '../types';
7
- export declare const refUtils: {
8
- getDuplicateError(name: string, schemaLabel: string, errorNode: SyntaxNode): CompileError;
9
- };
10
6
  export declare const refModule: GlobalModule;
11
7
  export declare function nodeRefereeOfRefEndpoint(compiler: Compiler, globalSymbol: NodeSymbol, node: SyntaxNode): Report<NodeSymbol | undefined>;
@@ -1,9 +1,7 @@
1
1
  import { Ref } from '../../types/schemaJson';
2
- import { RefMetadata, SettingName, Filepath } from '../../types';
2
+ import { RefMetadata, Filepath } from '../../types';
3
3
  import { default as Compiler } from '../../../compiler';
4
4
  import { default as Report } from '../../types/report';
5
- import { MetadataFieldRegistry } from '../metadata/utils';
6
- export declare const REF_METADATA_FIELDS: MetadataFieldRegistry<Ref, SettingName.Color | SettingName.Note>;
7
5
  export declare class RefInterpreter {
8
6
  private compiler;
9
7
  private metadata;
@@ -2,10 +2,9 @@ import { default as Compiler } from '../../../compiler';
2
2
  import { SettingName } from '../../types/keywords';
3
3
  import { ElementDeclarationNode } from '../../types/nodes';
4
4
  import { default as Report } from '../../types/report';
5
- import { Column, Table } from '../../types/schemaJson';
5
+ import { Table } from '../../types/schemaJson';
6
6
  import { Filepath } from '../../types/filepath';
7
7
  import { TableSymbol } from '../../types/symbol/symbols';
8
- import { MetadataFieldRegistry } from '../metadata/utils';
9
8
  export declare class TableInterpreter {
10
9
  private declarationNode;
11
10
  private compiler;
@@ -33,5 +32,3 @@ export declare class TableInterpreter {
33
32
  * TODO: Catch these settings when we support more data types for custom metadata
34
33
  */
35
34
  export declare const RECOGNIZED_COLUMN_SETTINGS: readonly SettingName[];
36
- export declare const TABLE_METADATA_FIELDS: MetadataFieldRegistry<Table, SettingName.Note | SettingName.HeaderColor>;
37
- export declare const COLUMN_METADATA_FIELDS: MetadataFieldRegistry<Column, SettingName.Note>;
@@ -1,9 +1,7 @@
1
1
  import { TableGroup } from '../../types/schemaJson';
2
2
  import { default as Compiler } from '../../../compiler';
3
- import { SettingName, Filepath, TableGroupSymbol } from '../../types';
3
+ import { Filepath, TableGroupSymbol } from '../../types';
4
4
  import { default as Report } from '../../types/report';
5
- import { MetadataFieldRegistry } from '../metadata/utils';
6
- export declare const TABLEGROUP_METADATA_FIELDS: MetadataFieldRegistry<TableGroup, SettingName.Note | SettingName.Color>;
7
5
  export declare class TableGroupInterpreter {
8
6
  private compiler;
9
7
  private symbol;
@@ -1,8 +1,6 @@
1
1
  import { default as Compiler } from '../../../compiler';
2
2
  import { CompileError } from '../../types/errors';
3
- import { BlockExpressionNode, ElementDeclarationNode, FunctionApplicationNode, ListExpressionNode } from '../../types/nodes';
4
- import { default as Report } from '../../types/report';
5
- import { Settings } from '../../utils/validate';
3
+ import { BlockExpressionNode, ElementDeclarationNode, FunctionApplicationNode } from '../../types/nodes';
6
4
  export default class DepValidator {
7
5
  private declarationNode;
8
6
  private compiler;
@@ -16,4 +14,3 @@ export default class DepValidator {
16
14
  validateFields(fields: FunctionApplicationNode[]): CompileError[];
17
15
  private validateSubElements;
18
16
  }
19
- export declare function validateDepSettings(settings: ListExpressionNode): Report<Settings>;
@@ -9,8 +9,6 @@ export default class NoteValidator {
9
9
  private validateContext;
10
10
  private validateName;
11
11
  private validateAlias;
12
- private isStickyNote;
13
- private validateSettingList;
14
12
  validateBody(body?: FunctionApplicationNode | BlockExpressionNode): CompileError[];
15
13
  validateFields(fields: FunctionApplicationNode[]): CompileError[];
16
14
  private validateSubElements;
@@ -1,8 +1,6 @@
1
1
  import { default as Compiler } from '../../../compiler';
2
2
  import { CompileError } from '../../types/errors';
3
- import { ElementDeclarationNode, ExpressionNode, ListExpressionNode } from '../../types/nodes';
4
- import { default as Report } from '../../types/report';
5
- import { Settings } from '../../utils/validate';
3
+ import { ElementDeclarationNode } from '../../types/nodes';
6
4
  export default class TableValidator {
7
5
  private declarationNode;
8
6
  private compiler;
@@ -11,11 +9,7 @@ export default class TableValidator {
11
9
  private validateContext;
12
10
  private validateName;
13
11
  private validateAlias;
14
- private validateSettingList;
15
12
  private validateBody;
16
13
  private validateFields;
17
- private validateFieldSetting;
18
14
  private validateSubElements;
19
15
  }
20
- export declare function validateTableSettings(settingList?: ListExpressionNode): Report<Settings>;
21
- export declare function validateFieldSetting(parts: ExpressionNode[]): Report<Settings>;
@@ -1,8 +1,6 @@
1
1
  import { default as Compiler } from '../../../compiler';
2
2
  import { CompileError } from '../../types/errors';
3
- import { BlockExpressionNode, ElementDeclarationNode, FunctionApplicationNode, ListExpressionNode } from '../../types/nodes';
4
- import { default as Report } from '../../types/report';
5
- import { Settings } from '../../utils/validate';
3
+ import { BlockExpressionNode, ElementDeclarationNode, FunctionApplicationNode } from '../../types/nodes';
6
4
  export default class TableGroupValidator {
7
5
  private declarationNode;
8
6
  private compiler;
@@ -11,9 +9,7 @@ export default class TableGroupValidator {
11
9
  private validateContext;
12
10
  private validateName;
13
11
  private validateAlias;
14
- private validateSettingList;
15
12
  validateBody(body?: FunctionApplicationNode | BlockExpressionNode): CompileError[];
16
13
  validateFields(fields: FunctionApplicationNode[]): CompileError[];
17
14
  private validateSubElements;
18
15
  }
19
- export declare function validateSettingList(settingList?: ListExpressionNode): Report<Settings>;
@@ -112,6 +112,10 @@ export declare enum CompileErrorCode {
112
112
  DUPLICATE_DIAGRAMVIEW_NAME = 3094,
113
113
  INVALID_DIAGRAMVIEW_FIELD = 3095,
114
114
  DUPLICATE_DIAGRAMVIEW_FIELD = 3096,
115
+ DUPLICATE_TABLEGROUP_SETTING = 3097,
116
+ INVALID_TABLEGROUP_SETTING_VALUE = 3098,
117
+ DUPLICATE_DEP_SETTING = 3099,
118
+ INVALID_DEP_SETTING_VALUE = 3100,
115
119
  BINDING_ERROR = 4000,
116
120
  NONEXISTENT_MODULE = 4001,
117
121
  UNSUPPORTED = 5000,
@@ -5,10 +5,12 @@ export type FilepathId = string & {
5
5
  };
6
6
  export declare class Filepath implements Internable<FilepathId> {
7
7
  private readonly protocol?;
8
- private readonly path;
8
+ private readonly root;
9
+ private readonly segments;
9
10
  constructor(absolutePath: string, options?: {
10
11
  protocol?: string;
11
12
  });
13
+ private get path();
12
14
  intern(): FilepathId;
13
15
  static from(absolutePath: string): Filepath;
14
16
  static resolve(fromDir: string, relativePath: string): Filepath;
@@ -2,7 +2,12 @@ import { NONE_COLOR } from '../../../constants';
2
2
  import { Filepath } from '../filepath';
3
3
  import { Position } from '../position';
4
4
  import { RelationshipOp, RelationCardinality } from '../relation';
5
- export type CustomMetadataValue = string | Color | number | boolean;
5
+ export type CustomMetadataValueType = 'string' | 'number' | 'bool' | 'color';
6
+ export interface CustomMetadataValue {
7
+ value: string | number | boolean;
8
+ type: CustomMetadataValueType;
9
+ token: TokenPosition;
10
+ }
6
11
  export type CustomMetadata = Record<string, CustomMetadataValue>;
7
12
  export type Color = `#${string}` | typeof NONE_COLOR;
8
13
  export declare enum AliasKind {
@@ -165,14 +170,9 @@ export interface Ref {
165
170
  name: string | null;
166
171
  endpoints: RefEndpointPair;
167
172
  color?: Color;
168
- note?: {
169
- value: string;
170
- token: TokenPosition;
171
- };
172
173
  onDelete?: string;
173
174
  onUpdate?: string;
174
175
  inactive?: boolean;
175
- metadata?: CustomMetadata;
176
176
  token: TokenPosition;
177
177
  }
178
178
  export type RefEndpointPair = [RefEndpoint, RefEndpoint];
@@ -285,10 +285,6 @@ export interface TableRecord {
285
285
  example?: boolean;
286
286
  token: TokenPosition;
287
287
  }
288
- export type MetadataValues = Record<string, {
289
- value: CustomMetadataValue;
290
- token: TokenPosition;
291
- }>;
292
288
  export type Project = Record<string, never> | {
293
289
  name: string | null;
294
290
  tables: Table[];
@@ -303,4 +299,4 @@ export type Project = Record<string, never> | {
303
299
  token: TokenPosition;
304
300
  [index: string & Omit<any, 'name' | 'tables' | 'refs' | 'enums' | 'tableGroups' | 'note' | 'tablePartials' | 'records'>]: string;
305
301
  };
306
- export type SchemaElement = Database | Project | Table | Note | Column | ColumnType | Index | Check | InlineRef | InlineDep | Ref | RefEndpoint | Dep | DepEdge | DepEndpoint | Enum | EnumField | TableGroup | TableGroupField | Alias | TablePartial | TablePartialInjection | TableRecord | RecordValue | MetadataValues;
302
+ export type SchemaElement = Database | Project | Table | Note | Column | ColumnType | Index | Check | InlineRef | InlineDep | Ref | RefEndpoint | Dep | DepEdge | DepEndpoint | Enum | EnumField | TableGroup | TableGroupField | Alias | TablePartial | TablePartialInjection | TableRecord | RecordValue | CustomMetadata;
@@ -16,7 +16,6 @@ export declare enum SymbolKind {
16
16
  Enum = "Enum",
17
17
  EnumField = "Enum field",
18
18
  StickyNote = "Note",
19
- Ref = "Ref",
20
19
  TablePartial = "TablePartial",
21
20
  PartialInjection = "PartialInjection",
22
21
  DiagramView = "DiagramView",
@@ -42,8 +41,7 @@ export declare enum MetadataTargetKind {
42
41
  Table = "Table",
43
42
  Column = "Column",
44
43
  TableGroup = "TableGroup",
45
- Note = "Note",
46
- Ref = "Ref"
44
+ Note = "Note"
47
45
  }
48
46
  declare const __nodeSymbolBrand: unique symbol;
49
47
  export type NodeSymbolId = number & {
@@ -213,14 +211,6 @@ export declare class NoteSymbol extends NodeSymbol {
213
211
  get canBeImported(): boolean;
214
212
  get originalSymbol(): NodeSymbol;
215
213
  }
216
- export declare class RefSymbol extends NodeSymbol {
217
- constructor({ declaration, name, }: {
218
- declaration?: SyntaxNode;
219
- name?: string;
220
- }, id: NodeSymbolId, filepath: Filepath);
221
- get canBeImported(): boolean;
222
- get originalSymbol(): NodeSymbol;
223
- }
224
214
  export declare class TablePartialSymbol extends NodeSymbol {
225
215
  constructor({ declaration, name, }: {
226
216
  declaration?: SyntaxNode;
@@ -23,6 +23,7 @@ export declare function destructureIndexNode(node?: SyntaxNode): {
23
23
  } | undefined;
24
24
  export declare function extractQuotedStringToken(value?: SyntaxNode): string | undefined;
25
25
  export declare function extractNumericLiteral(node?: SyntaxNode): number | null;
26
+ export declare function extractSignedNumber(node: SyntaxNode): number | null;
26
27
  export declare function extractBooleanLiteral(node?: SyntaxNode): boolean | null;
27
28
  export declare function destructureCallExpression(node?: SyntaxNode): {
28
29
  variables: (PrimaryExpressionNode & {
@@ -4,12 +4,15 @@ import { SyntaxNode } from '../types/nodes';
4
4
  import { default as Report } from '../types/report';
5
5
  import { Settings } from './validate';
6
6
  import { SettingName } from '../types';
7
+ import { MetadataFieldRegistry, MetadataTarget } from '../global_modules/metadata/utils';
7
8
  export declare function getTokenPosition(node: SyntaxNode): TokenPosition;
8
9
  export declare function normalizeNote(content: string): string;
9
10
  export declare function extractElementName(nameNode: SyntaxNode): {
10
11
  schemaName: string[];
11
12
  name: string;
12
13
  };
14
+ export declare function extractNote(node?: SyntaxNode): string | undefined;
15
+ export declare function extractHexColor(node?: SyntaxNode): Color | undefined;
13
16
  export declare function extractColor(node?: SyntaxNode): Color | undefined;
14
17
  export declare function processDefaultValue(valueNode?: SyntaxNode): {
15
18
  type: 'number' | 'string' | 'boolean' | 'expression';
@@ -17,10 +20,18 @@ export declare function processDefaultValue(valueNode?: SyntaxNode): {
17
20
  } | undefined;
18
21
  export declare function processColumnType(compiler: Compiler, typeNode: SyntaxNode): Report<ColumnType>;
19
22
  /**
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).
23
+ * Extract inline custom metadata from an aggregated setting list, excluding the given recognized settings.
24
+ * Used for columns, whose recognized settings (pk, ref, note, .etc) are interpreted by the column symbol rather than field specs.
22
25
  *
23
26
  * NOTE: This is used during interpret phase, so no need to validate values, just extract them
24
27
  */
25
28
  export declare function extractCustomInlineMetadata(settingMap: Settings, builtinSettings: readonly SettingName[]): CustomMetadata;
26
- export declare function extractMetadataValue(node?: SyntaxNode): CustomMetadataValue | undefined;
29
+ /**
30
+ * Interpret an element's aggregated setting list as metadata:
31
+ * - Builtin fields (headercolor and note in `table`, color in `tablegroup`, .etc) are parsed and assigned onto the element by their field spec
32
+ * - Every other key becomes free-form custom metadata on `element.metadata`
33
+ *
34
+ * Invalid values are skipped (reported at validate phase).
35
+ */
36
+ export declare function assignInlineMetadata<T extends MetadataTarget>(element: Partial<T>, settingMap: Settings, registry: MetadataFieldRegistry<T, any>): void;
37
+ export declare function extractMetadataValue(node?: SyntaxNode): Omit<CustomMetadataValue, 'token'> | undefined;
@@ -8,10 +8,11 @@ export { MetadataKind } from './core/types/symbol/metadata';
8
8
  export * from './core/global_modules/records/utils';
9
9
  export * from './core/types/nodes';
10
10
  export { SyntaxToken, SyntaxTokenKind, isTriviaToken, isOp, isOpToken, } from './core/types/tokens';
11
- export { CompileError, CompileErrorCode, } from './core/types/errors';
11
+ export { CompileError, CompileErrorCode, CompileWarning, CompileInfo, } from './core/types/errors';
12
+ export type { Diagnostic, DiagnosticQuickFix } from './services/diagnostics/provider';
12
13
  export type { Position, } from './core/types';
13
14
  export { ScopeKind, splitQualifiedIdentifier, unescapeString, escapeString, formatRecordValue, isValidIdentifier, addDoubleQuoteIfNeeded, normalizeQualifiedName, } from './compiler/index';
14
- 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 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, type CustomMetadataValue, } from './core/types/schemaJson';
15
+ 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 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, type CustomMetadataValue, type CustomMetadataValueType, } from './core/types/schemaJson';
15
16
  export { type RelationCardinality, type RelationshipOp, getRelationshipOp, getMultiplicities, parseCardinality, makeCardinalityRequired, makeCardinalityOptional, makeRelationshipRequired, isEndpointOneSide, isEndpointManySide, isEndpointOptional, isEndpointRequired, CARDINALITY_ONE, CARDINALITY_MAYBE, CARDINALITY_SOME, CARDINALITY_MANY, } from './core/types/relation';
16
17
  export type { DiagramViewSyncOperation, DiagramViewBlock, TextEdit, } from './compiler/queries/transform';
17
18
  export { findDiagramViewBlocks } from './compiler/queries/transform';
@@ -4,4 +4,5 @@ export default class DBMLDefinitionProvider implements DefinitionProvider {
4
4
  private compiler;
5
5
  constructor(compiler: Compiler);
6
6
  provideDefinition(model: TextModel, position: Position): Definition;
7
+ private resolveImportPath;
7
8
  }
@@ -20,11 +20,13 @@ export declare const TABLE_BODY_SUGGESTION_LABELS: ("indexes" | "checks" | "Note
20
20
  export declare const PROJECT_FIELD_SUGGESTION_LABELS: ("Table" | "Enum" | "TableGroup" | "TablePartial" | "Note" | "Ref" | "Dep")[];
21
21
  export interface DBMLCompletionItemProviderOptions {
22
22
  triggerCharacters?: string[];
23
+ fileListDepth?: number;
23
24
  }
24
25
  export default class DBMLCompletionItemProvider implements CompletionItemProvider {
25
26
  private compiler;
26
27
  triggerCharacters: string[];
28
+ fileListDepth: number;
27
29
  constructor(compiler: Compiler, options?: DBMLCompletionItemProviderOptions);
28
30
  provideCompletionItems(model: TextModel, position: Position): CompletionList;
29
31
  }
30
- export declare const TOP_LEVEL_SUGGESTION_LABELS: ("Table" | "Enum" | "TableGroup" | "TablePartial" | "Note" | "Ref" | "DiagramView" | "Metadata" | "Dep" | "Project" | "Records")[];
32
+ export declare const TOP_LEVEL_SUGGESTION_LABELS: ("Table" | "Enum" | "TableGroup" | "TablePartial" | "Note" | "DiagramView" | "Metadata" | "Ref" | "Dep" | "Project" | "Records")[];
@@ -2,4 +2,7 @@ import { default as Compiler } from '../../compiler';
2
2
  import { Filepath } from '../../core/types/filepath';
3
3
  import { SyntaxToken } from '../../core/types/tokens';
4
4
  import { CompletionList, TextModel } from '../types';
5
- export declare function suggestUseCompletion(compiler: Compiler, filepath: Filepath, offset: number, bOcToken: SyntaxToken | undefined, model: TextModel): CompletionList | null;
5
+ export interface SuggestUseCompletionOptions {
6
+ fileListDepth?: number;
7
+ }
8
+ export declare function suggestUseCompletion(compiler: Compiler, filepath: Filepath, offset: number, bOcToken: SyntaxToken | undefined, model: TextModel, options?: SuggestUseCompletionOptions): CompletionList | null;
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": "10.4.0-metadata-ref-type.0",
4
+ "version": "10.4.0-metadata-type.0",
5
5
  "description": "DBML parser v2",
6
6
  "author": "Holistics <dev@holistics.io>",
7
7
  "license": "Apache-2.0",
@@ -25,7 +25,7 @@
25
25
  "dist"
26
26
  ],
27
27
  "scripts": {
28
- "build": "rm -rf ./dist && tsc --noEmit && vite build",
28
+ "build": "rimraf ./dist && tsc --noEmit && vite build",
29
29
  "dev": "vite build --watch",
30
30
  "test": "vitest run",
31
31
  "test:watch": "vitest watch",
@@ -51,5 +51,5 @@
51
51
  "engines": {
52
52
  "node": ">=18"
53
53
  },
54
- "gitHead": "f2806cfb089ae685523e444dd409fd1e4514962b"
54
+ "gitHead": "0346035c1c3c2bb1f8b1e524e43a43ad4cc9bb8e"
55
55
  }
@@ -1,10 +0,0 @@
1
- import { NodeSymbol, ProgramSymbol } from '../../../core/types/symbol';
2
- import { default as Compiler } from '../../index';
3
- /**
4
- * Whether `symbol` is visible from `program`.
5
- * - Column: visible when its table is (a column is not a direct schema member)
6
- * - Ref: refs are not imported via `use`, a ref is visible when it shows up in the program's output,
7
- * i.e. the program reaches the ref's file and sees both endpoint tables (RefMetadata.owners)
8
- * - otherwise: the symbol sits in the program's schemas, directly or through `use`
9
- */
10
- export declare function isSymbolVisible(this: Compiler, program: ProgramSymbol, symbol: NodeSymbol): boolean;
@@ -1,7 +0,0 @@
1
- import { NodeSymbol } from '../../../core/types/symbol';
2
- import { MetadataElementMetadata } from '../../../core/types/symbol/metadata';
3
- import { default as Compiler } from '../../index';
4
- /**
5
- * Resolve the candidates a Metadata block targets, from its `<target-kind> <name>` header.
6
- */
7
- export declare function metadataTargets(this: Compiler, block: MetadataElementMetadata): NodeSymbol[];
@@ -1,7 +0,0 @@
1
- import { ProgramSymbol, RefSymbol, SymbolKind } from '../../../core/types/symbol';
2
- import { default as Compiler } from '../../index';
3
- /**
4
- * Named refs usable from `program`: refs are not imported via `use`, a named ref is visible
5
- * wherever it shows up in the output (see isSymbolVisible).
6
- */
7
- export declare function visibleSymbols(this: Compiler, program: ProgramSymbol, kind: SymbolKind): RefSymbol[];