@dbml/parse 10.4.0-alpha.1 → 10.4.0-alpha.10

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.
@@ -3,10 +3,11 @@ import { SyntaxNode, SyntaxNodeIdGenerator } from '../core/types/nodes';
3
3
  import { NodeSymbolIdGenerator, SymbolFactory } from '../core/types/symbol';
4
4
  import { DBMLCodeActionProvider, DBMLCompletionItemProvider, DBMLDefinitionProvider, DBMLDiagnosticsProvider, DBMLReferencesProvider } from '../services/index';
5
5
  import { DbmlProjectLayout } from './projectLayout';
6
- import { addDoubleQuoteIfNeeded, escapeString, formatRecordValue, isValidIdentifier, normalizeQualifiedName, splitQualifiedIdentifier, unescapeString } from './queries/utils';
6
+ import { addDoubleQuoteIfNeeded, escapeString, formatTypedValue, isValidIdentifier, normalizeQualifiedName, splitQualifiedIdentifier, unescapeString, TypedValue } from './queries/utils';
7
7
  export { ScopeKind } from './types';
8
8
  export type { TextEdit } from './queries/transform';
9
- export { addDoubleQuoteIfNeeded, escapeString, formatRecordValue, isValidIdentifier, normalizeQualifiedName, splitQualifiedIdentifier, unescapeString, };
9
+ export { addDoubleQuoteIfNeeded, escapeString, formatTypedValue, isValidIdentifier, normalizeQualifiedName, splitQualifiedIdentifier, unescapeString, };
10
+ export type { TypedValue };
10
11
  export default class Compiler {
11
12
  layout: DbmlProjectLayout;
12
13
  readonly nodeIdGenerator: SyntaxNodeIdGenerator;
@@ -50,26 +51,7 @@ export default class Compiler {
50
51
  symbolMetadata: (symbol: import('../core/types/symbol').NodeSymbol) => import('../core/types/symbol').NodeMetadata[];
51
52
  symbolAliases: (symbol: import('../core/types/symbol').NodeSymbol) => import('../core/types/report').default<import('../core/types/symbol').AliasSymbol[]>;
52
53
  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
54
  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
55
  reachableFiles: (entry?: Filepath | undefined) => Filepath[];
74
56
  usableMembers: (symbolOrFilepath: Filepath | import('../core/types/symbol').SchemaSymbol | import('../core/types/symbol').ProgramSymbol) => import('../core/types/report').default<{
75
57
  nonSchemaMembers: import('../core/types/symbol').NodeSymbol[];
@@ -93,6 +75,9 @@ export default class Compiler {
93
75
  renameTable: (filepath: Filepath, oldName: string | import('..').TableIdentifier, newName: string | import('..').TableIdentifier) => Map<string, string>;
94
76
  updateElementSetting: (filepath: Filepath, target: import('..').ElementIdentifier, settingName: string, value: string | null | undefined) => string;
95
77
  updateElementSettingEdit: (filepath: Filepath, target: import('..').ElementIdentifier, settingName: string, value: string | null | undefined) => import('.').TextEdit[];
78
+ findMetadataBlock: (filepath: Filepath, target: import('..').ElementIdentifier) => import('../core/types/nodes').ElementDeclarationNode | undefined;
79
+ updateElementMetadata: (filepath: Filepath, target: import('..').ElementIdentifier, key: string, value: TypedValue) => string;
80
+ updateElementMetadataEdit: (filepath: Filepath, target: import('..').ElementIdentifier, key: string, value: TypedValue) => import('.').TextEdit[];
96
81
  syncDiagramView: (filepath: Filepath, operations: import('..').DiagramViewSyncOperation[], blocks?: import('..').DiagramViewBlock[] | undefined) => {
97
82
  newDbml: string;
98
83
  edits: import('.').TextEdit[];
@@ -109,7 +94,7 @@ export default class Compiler {
109
94
  source: (filepath: Filepath) => string;
110
95
  ast: (filepath?: Filepath) => Readonly<import('../core/types/nodes').ProgramNode>;
111
96
  errors: (filepath?: Filepath) => readonly Readonly<import('..').CompileError>[];
112
- warnings: (filepath?: Filepath) => readonly Readonly<import('../core/types').CompileWarning>[];
97
+ warnings: (filepath?: Filepath) => readonly Readonly<import('..').CompileWarning>[];
113
98
  tokens: (filepath?: Filepath) => readonly Readonly<import('..').SyntaxToken>[];
114
99
  rawDb: (filepath?: Filepath) => Readonly<import('..').Database> | undefined;
115
100
  publicSymbolTable: (filepath?: Filepath) => readonly Readonly<import('../core/types/symbol').NodeSymbol>[] | undefined;
@@ -130,6 +115,7 @@ export default class Compiler {
130
115
  initMonacoServices(options?: {
131
116
  autocompletion?: {
132
117
  triggerCharacters?: string[];
118
+ fileListDepth?: number;
133
119
  };
134
120
  }): {
135
121
  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;
@@ -1,5 +1,6 @@
1
1
  export { renameTable } from './renameTable';
2
2
  export { updateElementSetting, updateElementSettingEdit } from './updateElementSetting';
3
+ export { findMetadataBlock, updateElementMetadata, updateElementMetadataEdit } from './updateElementMetadata';
3
4
  export { syncDiagramView, findDiagramViewBlocks, type DiagramViewSyncOperation, type DiagramViewBlock, } from './syncDiagramView';
4
5
  export { syncDep, generateDepBlock, type DepSyncOperation, type DepSyncEdge, type DepEndpointRef, } from './syncDep';
5
6
  export { applyTextEdits, type TextEdit } from './applyTextEdits';
@@ -0,0 +1,9 @@
1
+ import { Filepath } from '../../../core/types/filepath';
2
+ import { ElementDeclarationNode } from '../../../core/types/nodes';
3
+ import { default as Compiler } from '../../index';
4
+ import { TextEdit } from './applyTextEdits';
5
+ import { ElementIdentifier } from './types';
6
+ import { TypedValue } from '../utils';
7
+ export declare function findMetadataBlock(this: Compiler, filepath: Filepath, target: ElementIdentifier): ElementDeclarationNode | undefined;
8
+ export declare function updateElementMetadataEdit(this: Compiler, filepath: Filepath, target: ElementIdentifier, key: string, value: TypedValue | null): TextEdit[];
9
+ export declare function updateElementMetadata(this: Compiler, filepath: Filepath, target: ElementIdentifier, key: string, value: TypedValue | null): string;
@@ -70,20 +70,21 @@ export declare function escapeString(str: string): string;
70
70
  * @returns The formatted string representation for DBML
71
71
  *
72
72
  * @example
73
- * formatRecordValue({ value: 1, type: 'integer' }) => '1'
74
- * formatRecordValue({ value: 'Alice', type: 'string' }) => "'Alice'"
75
- * formatRecordValue({ value: true, type: 'bool' }) => 'true'
76
- * formatRecordValue({ value: null, type: 'string' }) => 'null'
77
- * formatRecordValue(undefined) => 'null'
78
- * formatRecordValue(null) => 'null'
79
- * formatRecordValue('Alice') => "'Alice'"
80
- * formatRecordValue(42) => '42'
81
- * formatRecordValue(true) => 'true'
73
+ * formatTypedValue({ value: 1, type: 'integer' }) => '1'
74
+ * formatTypedValue({ value: 'Alice', type: 'string' }) => "'Alice'"
75
+ * formatTypedValue({ value: true, type: 'bool' }) => 'true'
76
+ * formatTypedValue({ value: null, type: 'string' }) => 'null'
77
+ * formatTypedValue(undefined) => 'null'
78
+ * formatTypedValue(null) => 'null'
79
+ * formatTypedValue('Alice') => "'Alice'"
80
+ * formatTypedValue(42) => '42'
81
+ * formatTypedValue(true) => 'true'
82
82
  */
83
- export declare function formatRecordValue(recordValue: {
83
+ export type TypedValue = {
84
84
  value: any;
85
85
  type: string;
86
- } | string | number | boolean | null | undefined): string;
86
+ } | string | number | boolean | null | undefined;
87
+ export declare function formatTypedValue(recordValue: TypedValue): string;
87
88
  /**
88
89
  * Splits a qualified identifier string into its components, handling quoted segments.
89
90
  *
@@ -1,9 +1,9 @@
1
1
  import { default as Compiler } from '../../../compiler/index';
2
2
  import { Filepath, SettingName } from '../../types';
3
- import { Column, Note, Ref, Table, TableGroup, TokenPosition } from '../../types/schemaJson';
4
- import { SyntaxNode } from '../../types/nodes';
3
+ import { Column, 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
8
  * Specs for builtin metadata (table's note, tablegroup's color, .etc) for different element types. Does 2 things:
9
9
  * - `validate`: Validating if the metadata value is syntactically correct
@@ -17,15 +17,13 @@ interface MetadataField<T extends MetadataTarget> {
17
17
  assignBuiltinField(element: Partial<T>, value: string, token: TokenPosition): void;
18
18
  }
19
19
  export type MetadataFieldRegistry<T extends MetadataTarget, K extends SettingName = SettingName> = Record<K, MetadataField<T>>;
20
- export type NameWithSymbolKind = {
20
+ type NameWithSymbolKind = {
21
21
  name: string;
22
22
  symbolKind: SymbolKind;
23
23
  };
24
24
  /** @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
- */
25
+ export declare function mapNamePartToSymbolKind(nameParts: string[], targetKind: MetadataTargetKind): NameWithSymbolKind[];
26
+ export declare function resolveMetadataTarget(compiler: Compiler, metadataNode: ElementDeclarationNode): NodeSymbol | undefined;
27
+ /** Merge every custom-metadata block, reachable from the current program, targeting element to it's `metadata` and other builtin (note/headercolor/...) fields */
30
28
  export declare function attachCustomMetadata<T extends MetadataTarget>(compiler: Compiler, targetElement: Partial<T>, targetSymbol: NodeSymbol, fieldsRegistry: MetadataFieldRegistry<T, any>, filepath: Filepath): void;
31
29
  export {};
@@ -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;
@@ -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;
@@ -164,14 +164,9 @@ export interface Ref {
164
164
  name: string | null;
165
165
  endpoints: RefEndpointPair;
166
166
  color?: Color;
167
- note?: {
168
- value: string;
169
- token: TokenPosition;
170
- };
171
167
  onDelete?: string;
172
168
  onUpdate?: string;
173
169
  inactive?: boolean;
174
- metadata?: CustomMetadata;
175
170
  token: TokenPosition;
176
171
  }
177
172
  export type RefEndpointPair = [RefEndpoint, RefEndpoint];
@@ -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;
@@ -8,9 +8,10 @@ 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
- export { ScopeKind, splitQualifiedIdentifier, unescapeString, escapeString, formatRecordValue, isValidIdentifier, addDoubleQuoteIfNeeded, normalizeQualifiedName, } from './compiler/index';
14
+ export { ScopeKind, splitQualifiedIdentifier, unescapeString, escapeString, formatTypedValue, type TypedValue, isValidIdentifier, addDoubleQuoteIfNeeded, normalizeQualifiedName, } from './compiler/index';
14
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, } 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';
@@ -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-alpha.1",
4
+ "version": "10.4.0-alpha.10",
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": "2abacb40597047ca589b2c18117f57f8fe3978e6"
54
+ "gitHead": "803873f5165a628d3f9050b9dff0173adab072b2"
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[];